diff options
Diffstat (limited to 'src/gdbmtool.c')
-rw-r--r-- | src/gdbmtool.c | 102 |
1 files changed, 82 insertions, 20 deletions
diff --git a/src/gdbmtool.c b/src/gdbmtool.c index 65b6740..2d57cbc 100644 --- a/src/gdbmtool.c +++ b/src/gdbmtool.c @@ -325,16 +325,2 @@ get_screen_lines () } - - -#define ARG_UNUSED __attribute__ ((__unused__)) - -#define NARGS 5 - -struct handler_param -{ - int argc; - struct gdbmarg **argv; - FILE *fp; - void *data; -}; - @@ -753,3 +739,3 @@ quit_handler (struct handler_param *param ARG_UNUSED) gdbm_close (gdbm_file); - + input_done (); exit (EXIT_OK); @@ -893,2 +879,4 @@ struct argdef +#define NARGS 5 + struct command @@ -904,3 +892,2 @@ struct command }; - @@ -1009,2 +996,9 @@ struct command command_tab[] = { N_("open new database") }, +#ifdef WITH_READLINE + { S(history), T_CMD, + input_history_begin, input_history_handler, NULL, + { { N_("[FROM]"), GDBM_ARG_STRING }, + { N_("[COUNT]"), GDBM_ARG_STRING }, + { NULL } }, N_("show input history") }, +#endif #undef S @@ -1028,2 +1022,35 @@ sort_commands () +/* Generator function for command completion. STATE lets us know whether + to start from scratch; without any state (i.e. STATE == 0), then we + start at the top of the list. */ +char * +command_generator (const char *text, int state) +{ + const char *name; + static int len; + static struct command *cmd; + + /* If this is a new word to complete, initialize now. This includes + saving the length of TEXT for efficiency, and initializing the index + variable to 0. */ + if (!state) + { + cmd = command_tab; + len = strlen (text); + } + + if (!cmd->name) + return NULL; + + /* Return the next name which partially matches from the command list. */ + while ((name = cmd->name)) + { + cmd++; + if (strncmp (name, text, len) == 0) + return strdup (name); + } + + /* If no names matched, then return NULL. */ + return NULL; +} @@ -1176,3 +1203,3 @@ gdbmarg_kvpair (struct kvpair *kvp, struct locus *loc) struct slist * -slist_new (char *s) +slist_new_s (char *s) { @@ -1184,2 +1211,17 @@ slist_new (char *s) +struct slist * +slist_new (char const *s) +{ + return slist_new_s (estrdup (s)); +} + +struct slist * +slist_new_l (char const *s, size_t l) +{ + char *copy = emalloc (l + 1); + memcpy (copy, s, l); + copy[l] = 0; + return slist_new_s (copy); +} + void @@ -1195,2 +1237,17 @@ slist_free (struct slist *lp) } + +void +slist_insert (struct slist **where, struct slist *what) +{ + if (*where) + { + while (what->next) + what = what->next; + what->next = (*where)->next; + (*where)->next = what; + } + else + what->next = NULL; + *where = what; +} @@ -1218,3 +1275,2 @@ kvpair_list (struct locus *loc, struct slist *s) - static void @@ -1536,2 +1592,3 @@ main (int argc, char *argv[]) int norc = 0; + int res; char *source = "-"; @@ -1547,5 +1604,6 @@ main (int argc, char *argv[]) sort_commands (); - + /* Initialize variables. */ intr = isatty (0); + interactive = intr; /* Used early by input_init */ dsdef[DS_KEY] = dsegm_new_field (datadef_lookup ("string"), NULL, 1); @@ -1556,2 +1614,4 @@ main (int argc, char *argv[]) + input_init (); + for (opt = parseopt_first (argc, argv, optab); @@ -1642,3 +1702,5 @@ main (int argc, char *argv[]) exit (EXIT_FATAL); - return yyparse (); + res = yyparse (); + input_done (); + return res; } |