diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-05-08 16:27:01 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-05-08 16:27:01 +0000 |
commit | 6658f41e38fec9e007a0fbd0883e030f6337e28d (patch) | |
tree | d7ecc0b72b23a01a2bfa10e8a7bb184d704269dc /src | |
parent | c0cba983ab0c0bc1de630a200f902189ddddff09 (diff) | |
download | gdbm-6658f41e38fec9e007a0fbd0883e030f6337e28d.tar.gz gdbm-6658f41e38fec9e007a0fbd0883e030f6337e28d.tar.bz2 |
Rename testgdbm to gdbmtool. Improve documentation.
* configure.ac: Fix a typo.
* src/.cvsignore: Add gdbmtool
* src/Makefile.am: Rename testgdbm to gdbmtool. Source
file not renamed because of CVS deficiency.
* src/gdbm_dump.c: Enable NLS.
* src/gdbm_load.c: Likewise.
* src/testgdbm.c: New option -q (--quiet).
New command: prompt.
* doc/Makefile.am (man_MANS): Add new manpages.
* doc/gdbmtool.1: New file.
* doc/gdbm_load.1: New file.
* doc/gdbm_dump.1: New file.
* doc/gdbm.3: Update.
* doc/gdbm.texinfo: Update.
Diffstat (limited to 'src')
-rw-r--r-- | src/.cvsignore | 1 | ||||
-rw-r--r-- | src/Makefile.am | 5 | ||||
-rw-r--r-- | src/gdbm_dump.c | 8 | ||||
-rw-r--r-- | src/gdbm_load.c | 6 | ||||
-rw-r--r-- | src/testgdbm.c | 107 |
5 files changed, 106 insertions, 21 deletions
diff --git a/src/.cvsignore b/src/.cvsignore index 46838d7..70e7a26 100644 --- a/src/.cvsignore +++ b/src/.cvsignore @@ -7,5 +7,6 @@ gdbm.h *.lo libgdbm.la testgdbm +gdbmtool gdbm_dump gdbm_load diff --git a/src/Makefile.am b/src/Makefile.am index 2d7a81a..7b1a2d2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -76,7 +76,8 @@ libgdbmapp_a_SOURCES =\ progname.c # Programs -bin_PROGRAMS = testgdbm gdbm_load gdbm_dump -testgdbm_LDADD = ./libgdbmapp.a ./libgdbm.la +bin_PROGRAMS = gdbmtool gdbm_load gdbm_dump +gdbmtool_LDADD = ./libgdbmapp.a ./libgdbm.la +gdbmtool_SOURCES = testgdbm.c gdbm_load_LDADD = ./libgdbmapp.a ./libgdbm.la gdbm_dump_LDADD = ./libgdbmapp.a ./libgdbm.la diff --git a/src/gdbm_dump.c b/src/gdbm_dump.c index 9120f04..d6318b1 100644 --- a/src/gdbm_dump.c +++ b/src/gdbm_dump.c @@ -22,7 +22,7 @@ char *parseopt_program_doc = "dump a GDBM database to a file"; char *parseopt_program_args = "DB_FILE [FILE]"; struct gdbm_option optab[] = { - { 'H', "format", N_("0|1"), N_("select dump format") }, + { 'H', "format", "binary|ascii|0|1", N_("select dump format") }, { 0 } }; @@ -36,6 +36,12 @@ main (int argc, char **argv) char *dbname, *filename; FILE *fp; +#ifdef HAVE_SETLOCALE + setlocale (LC_ALL, ""); +#endif + bindtextdomain (PACKAGE, LOCALEDIR); + textdomain (PACKAGE); + set_progname (argv[0]); for (opt = parseopt_first (argc, argv, optab); diff --git a/src/gdbm_load.c b/src/gdbm_load.c index deea9ca..7746b1b 100644 --- a/src/gdbm_load.c +++ b/src/gdbm_load.c @@ -73,6 +73,12 @@ main (int argc, char **argv) unsigned long err_line, n; char *end; +#ifdef HAVE_SETLOCALE + setlocale (LC_ALL, ""); +#endif + bindtextdomain (PACKAGE, LOCALEDIR); + textdomain (PACKAGE); + set_progname (argv[0]); for (opt = parseopt_first (argc, argv, optab); diff --git a/src/testgdbm.c b/src/testgdbm.c index 2ac3826..155c69e 100644 --- a/src/testgdbm.c +++ b/src/testgdbm.c @@ -1,6 +1,3 @@ -/* 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. Copyright (C) 1990, 1991, 1993, 2007, 2011, 2013 Free Software Foundation, Inc. @@ -39,7 +36,8 @@ const char *progname; /* Program name */ -char *prompt = "testgdbm> "; +#define DEFAULT_PROMPT "gdbmtool> " +char *prompt; char *file_name = NULL; /* Database file name */ GDBM_FILE gdbm_file = NULL; /* Database to operate upon */ @@ -48,6 +46,7 @@ datum key_data; /* Current key */ datum return_data; /* Current data */ 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 */ #define SIZE_T_MAX ((size_t)-1) @@ -800,7 +799,77 @@ data_z_handler (struct handler_param *param) data_z = !data_z; fprintf (param->fp, _("Zero terminated data: %s\n"), boolstr (data_z)); } + +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]); +} void help_handler (struct handler_param *param); int help_begin (struct handler_param *param, size_t *exp_count); @@ -891,6 +960,9 @@ struct command command_tab[] = { { S(help), '?', help_begin, help_handler, NULL, { NULL, NULL, }, N_("print this help list") }, + { S(prompt), 0, + NULL, prompt_handler, NULL, + { N_("text") }, N_("set command prompt") }, { S(quit), 'q', NULL, quit_handler, NULL, { NULL, NULL, }, N_("quit the program") }, @@ -1021,23 +1093,19 @@ getword (char *s, char **endp) return p; } -/* 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"); struct gdbm_option optab[] = { { 'b', "block-size", N_("SIZE"), N_("set block size") }, { 'c', "cache-size", N_("SIZE"), N_("set cache size") }, { 'g', NULL, "FILE", NULL, PARSEOPT_HIDDEN }, { '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") }, { 'r', "read-only", NULL, N_("open database in read-only mode") }, { 's', "synchronize", NULL, N_("synchronize to disk after each write") }, + { 'q', "quiet", NULL, N_("don't print initial banner") }, { 0 } }; @@ -1116,6 +1184,10 @@ main (int argc, char *argv[]) file_name = optarg; break; + case 'q': + quiet_option = 1; + break; + default: terror (EXIT_USAGE, _("unknown option; try `%s -h' for more info\n"), progname); @@ -1159,9 +1231,11 @@ main (int argc, char *argv[]) signal (SIGPIPE, SIG_IGN); /* 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)); argmax = 0; @@ -1181,10 +1255,7 @@ main (int argc, char *argv[]) input_line++; if (interactive) - { - printf ("%s", prompt); - fflush (stdout); - } + outprompt (); if (fgets (cmdbuf, sizeof cmdbuf, stdin) == NULL) { |