/* * terminal.c * $Id: terminal.c,v 1.12 2005/01/28 16:12:46 obi Exp $ * 010729 cb */ #include #include #include #include "terminal.h" char *command_generator(const char *text, int state) { static int n, len; static char *commands[] = { "bindump", "disassemble", "dump", "exit", "explain", "exrequest", "exservice", "fill", "fillcount", "fpr", "fpr.s", "fpr.d", "gpr", "help", "hexdump", "jump", "load", "number", "poke", "prof", "quit", "reset", "run", "runto", "set", "step", "stepbb", "state", "fdump", "trace_trap", "notracetrap", "tracetrap", NULL }; if(!state) { n = 0; len = strlen(text); } for(; commands[n]; n++) { if(!strncmp(text, commands[n], len)) return strdup(commands[n++]); // hier n++, da das n++ oben nicht mehr ausgeführt wird } return NULL; } char *option_generator(const char *text, int state) { static int n, len; static char *options[] = { "intflip", "nointflip", "trace", "notrace", "tracetrap", "notracetrap", "stop_never", "stop_all", "stop_trap", "no_stop_trap", "stop_trap_exit", "no_stop_trap_exit", "stop_trap_open", "no_stop_trap_open", "stop_trap_close", "no_stop_trap_close", "stop_trap_read", "no_stop_trap_read", "stop_trap_write", "no_stop_trap_write", "stop_trap_irq", "no_stop_trap_irq", "stop_jisr", "no_stop_jisr", "stop_rfe", "no_stop_rfe", "stop_warning", "no_stop_warning", "stop_chmod", "no_stop_chmod", "stop_bbend", "no_stop_bbend", "stop_jal","no_stop_jal", "stop_jr31","no_stop_jr31", NULL }; if(!state) { n = 0; len = strlen(text); } for(; options[n]; n++) { if(!strncmp(text, options[n], len)) return strdup(options[n++]); // hier n++, da das n++ oben nicht mehr ausgeführt wird } return NULL; } char **generator_mux(char *text, int start, int end) { char **matches = NULL; // at the beginning: complete command names if(start == 0) { return rl_completion_matches(text, command_generator); } if(!strncmp(rl_line_buffer, "set ", strlen("set "))) { return rl_completion_matches(text, option_generator); } // return matches, fallback to file names if NULL return matches; } char **delete_item(char **list) { int i; free(*list); // delete first item for(i = 0; list[i] != NULL; i++) list[i] = list[i+1]; // shift others return list; } char **filename_filter(char *fname[]) { char **f; int found = 0; // ignore first entry (common prefix) for(f = fname+1; *f; f++) { if(strstr(*f, "obj")) found = 1; } if(found == 0) // there would be nothing left, so we do not delete anything return fname; f = fname+1; while (*f != NULL) { //printf(" filtering %s\n", *f); if(!strstr(*f, "obj")) { //printf(" deleting %s\n", *f); delete_item(f); } else { f++; } } return fname; } void init_readline() { // try this first rl_attempted_completion_function = (CPPFunction *)generator_mux; // filename filter rl_ignore_some_completions_function = (Function *)filename_filter; } char *get_str(char *prompt) { static char *line = NULL; if(line != NULL) { free(line); line = NULL; } line = readline(prompt); if(line && *line) { add_history(line); } if(line == NULL) { // ^D pressed puts("exit"); exit(0); } return line; } char *static_strdup(char *s) { static char *l = NULL; if(l != NULL) { free(l); } l = strdup(s); return l; }