diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-05-15 18:31:55 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-05-15 18:31:55 +0000 |
commit | 04d75f9797ce3d117e0f8a18f925c096014ed1fa (patch) | |
tree | 3aec2ba937c52b5f12e3bc75703cbb668eb0a17f | |
parent | bd1fd16d2eab21688a1e9b536821eae4970cedfd (diff) | |
download | gdbm-04d75f9797ce3d117e0f8a18f925c096014ed1fa.tar.gz gdbm-04d75f9797ce3d117e0f8a18f925c096014ed1fa.tar.bz2 |
Implement the "quiet" variable.
* src/var.c (vartab) <quiet>: New variable.
(variable_is_true): Return 0 if the value cannot be
retrieved.
* src/gdbmtool.c (optab): New option --file (-f).
(main): Handle the --file option.
Retrieve the "quiet" setting from the variable.
* src/lex.l (context_pop): Clear both point.file
and yylloc.
-rw-r--r-- | ChangeLog | 13 | ||||
-rw-r--r-- | src/gdbmtool.c | 34 | ||||
-rw-r--r-- | src/lex.l | 2 | ||||
-rw-r--r-- | src/var.c | 7 |
4 files changed, 40 insertions, 16 deletions
@@ -1,5 +1,18 @@ 2013-05-15 Sergey Poznyakoff <gray@gnu.org.ua> + Implement the "quiet" variable. + + * src/var.c (vartab) <quiet>: New variable. + (variable_is_true): Return 0 if the value cannot be + retrieved. + * src/gdbmtool.c (optab): New option --file (-f). + (main): Handle the --file option. + Retrieve the "quiet" setting from the variable. + * src/lex.l (context_pop): Clear both point.file + and yylloc. + +2013-05-15 Sergey Poznyakoff <gray@gnu.org.ua> + Add "pager" variable and "unset" command. * src/gdbmtool.c (command_tab) <unset>: New command. diff --git a/src/gdbmtool.c b/src/gdbmtool.c index 93cc175..4acb2a7 100644 --- a/src/gdbmtool.c +++ b/src/gdbmtool.c @@ -36,7 +36,6 @@ char *file_name = NULL; /* Database file name */ GDBM_FILE gdbm_file = NULL; /* Database to operate upon */ datum key_data; /* Current key */ datum return_data; /* Current data */ -int quiet_option = 0; /* Omit the usual welcome banner at startup */ int open_mode; /* Default open mode */ #define SIZE_T_MAX ((size_t)-1) @@ -1072,6 +1071,7 @@ 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") }, + { 'f', "file", N_("FILE"), N_("read commands from FILE") }, { 'g', NULL, "FILE", NULL, PARSEOPT_HIDDEN }, { 'l', "no-lock", NULL, N_("disable file locking") }, { 'm', "no-mmap", NULL, N_("do not use mmap") }, @@ -1486,6 +1486,7 @@ main (int argc, char *argv[]) int opt; int bv; int norc = 0; + char *source = "-"; set_progname (argv[0]); @@ -1497,6 +1498,11 @@ main (int argc, char *argv[]) sort_commands (); + /* Initialize variables. */ + intr = isatty (0); + dsdef[DS_KEY] = dsegm_new_field (datadef_lookup ("string"), NULL, 1); + dsdef[DS_CONTENT] = dsegm_new_field (datadef_lookup ("string"), NULL, 1); + variable_set ("open", VART_STRING, "wrcreat"); variable_set ("pager", VART_STRING, getenv ("PAGER")); @@ -1505,6 +1511,11 @@ main (int argc, char *argv[]) opt = parseopt_next ()) switch (opt) { + case 'f': + source = optarg; + intr = 0; + break; + case 'l': bv = 0; variable_set ("lock", VART_BOOL, &bv); @@ -1545,12 +1556,13 @@ main (int argc, char *argv[]) break; case 'q': - quiet_option = 1; + bv = 1; + variable_set ("quiet", VART_BOOL, &bv); break; default: terror (_("unknown option; try `%s -h' for more info"), - progname); + progname); exit (EXIT_USAGE); } @@ -1566,23 +1578,19 @@ main (int argc, char *argv[]) if (argc == 1) file_name = argv[0]; - /* Initialize variables. */ - intr = isatty (0); - dsdef[DS_KEY] = dsegm_new_field (datadef_lookup ("string"), NULL, 1); - dsdef[DS_CONTENT] = dsegm_new_field (datadef_lookup ("string"), NULL, 1); - signal (SIGPIPE, SIG_IGN); memset (¶m, 0, sizeof (param)); argmax = 0; - /* Welcome message. */ - if (intr && !quiet_option) - printf (_("\nWelcome to the gdbm tool. Type ? for help.\n\n")); - if (!norc) source_rcfile (); - setsource ("-", intr); + /* Welcome message. */ + if (intr && !variable_is_true ("quiet")) + printf (_("\nWelcome to the gdbm tool. Type ? for help.\n\n")); + + if (setsource (source, intr)) + exit (EXIT_FATAL); return yyparse (); } @@ -100,6 +100,8 @@ context_pop () fclose (yyin); yyin = NULL; free (point.file); + point.file = NULL; + memset (&yylloc, 0, sizeof (yylloc)); if (!cp) return 1; @@ -59,6 +59,7 @@ static struct variable vartab[] = { { "mmap", VART_BOOL, VARF_INIT, { num: 1 } }, { "sync", VART_BOOL, VARF_INIT, { num: 0 } }, { "pager", VART_STRING, VARF_DFL }, + { "quiet", VART_BOOL, VARF_DFL }, { NULL } }; @@ -355,7 +356,7 @@ variable_is_true (const char *name) { int n; - if (variable_get (name, VART_BOOL, (void **) &n)) - return 1; - return n; + if (variable_get (name, VART_BOOL, (void **) &n) == VAR_OK) + return n; + return 0; } |