diff options
Diffstat (limited to 'src/testgdbm.c')
-rw-r--r-- | src/testgdbm.c | 107 |
1 files changed, 89 insertions, 18 deletions
diff --git a/src/testgdbm.c b/src/testgdbm.c index 2ac3826..155c69e 100644 --- a/src/testgdbm.c +++ b/src/testgdbm.c @@ -1,4 +1 @@ -/* testgdbm.c - Driver program to test the database routines and to - help debug gdbm. Uses inside information to show "system" information */ - /* This file is part of GDBM, the GNU data base manager. @@ -41,3 +38,4 @@ const char *progname; /* Program name */ -char *prompt = "testgdbm> "; +#define DEFAULT_PROMPT "gdbmtool> " +char *prompt; @@ -50,2 +48,3 @@ int key_z = 1; /* Keys are nul-terminated strings */ int data_z = 1; /* Data are nul-terminated strings */ +int quiet_option = 0; /* Omit usual welcome banner at startup */ @@ -802,3 +801,73 @@ data_z_handler (struct handler_param *param) } + +struct prompt_exp; + +void +pe_file_name (struct prompt_exp *p) +{ + fwrite (file_name, strlen (file_name), 1, stdout); +} + +struct prompt_exp +{ + int ch; + void (*fun) (struct prompt_exp *); + char *cache; +}; + +struct prompt_exp prompt_exp[] = { + { 'f', pe_file_name }, + { 0 } +}; +static void +expand_char (int c) +{ + struct prompt_exp *p; + + if (c && c != '%') + { + for (p = prompt_exp; p->ch; p++) + { + if (c == p->ch) + { + if (p->cache) + free (p->cache); + return p->fun (p); + } + } + } + putchar ('%'); + putchar (c); +} + +void +outprompt () +{ + char *s; + + for (s = prompt; *s; s++) + { + if (*s == '%') + { + if (!*++s) + { + putchar ('%'); + break; + } + expand_char (*s); + } + else + putchar (*s); + } + + fflush (stdout); +} + +void +prompt_handler (struct handler_param *param) +{ + free (prompt); + prompt = estrdup (param->argv[0]); +} @@ -893,2 +962,5 @@ struct command command_tab[] = { { NULL, NULL, }, N_("print this help list") }, + { S(prompt), 0, + NULL, prompt_handler, NULL, + { N_("text") }, N_("set command prompt") }, { S(quit), 'q', @@ -1023,9 +1095,4 @@ getword (char *s, char **endp) -/* The test program allows one to call all the routines plus the hash function. - The commands are single letter commands. The user is prompted for missing - pieces of information. See the help command (?) for a list of all - commands. */ - -char *parseopt_program_doc = "Test and modify a GDBM database"; -char *parseopt_program_args = N_("FILE"); +char *parseopt_program_doc = N_("examine and/or modify a GDBM database"); +char *parseopt_program_args = N_("DBFILE"); @@ -1036,3 +1103,3 @@ struct gdbm_option optab[] = { { 'l', "no-lock", NULL, N_("disable file locking") }, - { 'm', "no-mmap", NULL, N_("disable file mmap") }, + { 'm', "no-mmap", NULL, N_("do not use mmap") }, { 'n', "newdb", NULL, N_("create database") }, @@ -1040,2 +1107,3 @@ struct gdbm_option optab[] = { { 's', "synchronize", NULL, N_("synchronize to disk after each write") }, + { 'q', "quiet", NULL, N_("don't print initial banner") }, { 0 } @@ -1118,2 +1186,6 @@ main (int argc, char *argv[]) + case 'q': + quiet_option = 1; + break; + default: @@ -1161,5 +1233,7 @@ main (int argc, char *argv[]) /* Welcome message. */ + if (interactive && !quiet_option) + printf (_("\nWelcome to the gdbm tool. Type ? for help.\n\n")); if (interactive) - printf (_("\nWelcome to the gdbm test program. Type ? for help.\n\n")); - + prompt = estrdup (DEFAULT_PROMPT); + memset (¶m, 0, sizeof (param)); @@ -1183,6 +1257,3 @@ main (int argc, char *argv[]) if (interactive) - { - printf ("%s", prompt); - fflush (stdout); - } + outprompt (); |