aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2021-08-27 16:45:34 +0300
committerSergey Poznyakoff <gray@gnu.org>2021-09-03 13:23:50 +0300
commit9e44aa63680fb8b369cfe3bd406de29cd29fb2eb (patch)
tree46f3602d22674bb9a7c814f97b307381450319e1
parent581c71dd40074cc6985cdc8cc9ffe006a4411d0a (diff)
downloadgdbm-9e44aa63680fb8b369cfe3bd406de29cd29fb2eb.tar.gz
gdbm-9e44aa63680fb8b369cfe3bd406de29cd29fb2eb.tar.bz2
Minor change
* src/gdbmshell.c (command_type): Change initializer. (gdbmshell_run): Initialize the .len member.
-rw-r--r--src/gdbmshell.c613
1 files changed, 380 insertions, 233 deletions
diff --git a/src/gdbmshell.c b/src/gdbmshell.c
index 32c9142..a1ba4b2 100644
--- a/src/gdbmshell.c
+++ b/src/gdbmshell.c
@@ -1721,7 +1721,7 @@ struct command
char *name; /* Command name */
size_t len; /* Name length */
int tok;
- int (*begin) (struct command_param *param, struct command_environ *cenv, size_t *);
+ int (*begin) (struct command_param *param, struct command_environ *cenv, size_t *);
int (*handler) (struct command_param *param, struct command_environ *cenv);
void (*end) (void *data);
struct argdef args[NARGS];
@@ -1731,250 +1731,394 @@ struct command
};
static struct command command_tab[] = {
-#define S(s) #s, sizeof (#s) - 1
- { S(count), T_CMD,
- checkdb_begin, count_handler, NULL,
- { { NULL } },
- FALSE,
- REPEAT_NEVER,
- N_("count (number of entries)") },
- { S(delete), T_CMD,
- checkdb_begin, delete_handler, NULL,
- { { N_("KEY"), GDBM_ARG_DATUM, DS_KEY }, { NULL } },
- FALSE,
- REPEAT_NEVER,
- N_("delete a record") },
- { S(export), T_CMD,
- checkdb_begin, export_handler, NULL,
- { { N_("FILE"), GDBM_ARG_STRING },
+ {
+ .name = "count",
+ .doc = N_("count (number of entries)"),
+ .tok = T_CMD,
+ .begin = checkdb_begin,
+ .handler = count_handler,
+ .variadic = FALSE,
+ .repeat = REPEAT_NEVER,
+ },
+ {
+ .name = "delete",
+ .args = {
+ { N_("KEY"), GDBM_ARG_DATUM, DS_KEY },
+ { NULL }
+ },
+ .doc = N_("delete a record"),
+ .tok = T_CMD,
+ .begin = checkdb_begin,
+ .handler = delete_handler,
+ .variadic = FALSE,
+ .repeat = REPEAT_NEVER,
+ },
+ {
+ .name = "export",
+ .args = {
+ { N_("FILE"), GDBM_ARG_STRING },
{ "[truncate]", GDBM_ARG_STRING },
{ "[binary|ascii]", GDBM_ARG_STRING },
- { NULL } },
- FALSE,
- REPEAT_NEVER,
- N_("export") },
- { S(fetch), T_CMD,
- checkdb_begin, fetch_handler, NULL,
- { { N_("KEY"), GDBM_ARG_DATUM, DS_KEY }, { NULL } },
- FALSE,
- REPEAT_NEVER,
- N_("fetch record") },
- { S(import), T_CMD,
- NULL, import_handler, NULL,
- { { N_("FILE"), GDBM_ARG_STRING },
+ { NULL }
+ },
+ .doc = N_("export"),
+ .tok = T_CMD,
+ .begin = checkdb_begin,
+ .handler = export_handler,
+ .variadic = FALSE,
+ .repeat = REPEAT_NEVER,
+ },
+ {
+ .name = "fetch",
+ .args = {
+ { N_("KEY"), GDBM_ARG_DATUM, DS_KEY },
+ { NULL }
+ },
+ .doc = N_("fetch record"),
+ .tok = T_CMD,
+ .begin = checkdb_begin,
+ .handler = fetch_handler,
+ .variadic = FALSE,
+ .repeat = REPEAT_NEVER,
+ },
+ {
+ .name = "import",
+ .args = {
+ { N_("FILE"), GDBM_ARG_STRING },
{ "[replace]", GDBM_ARG_STRING },
{ "[nometa]" , GDBM_ARG_STRING },
- { NULL } },
- FALSE,
- FALSE,
- N_("import") },
- { S(list), T_CMD,
- list_begin, list_handler, NULL,
- { { NULL } },
- FALSE,
- REPEAT_NEVER,
- N_("list") },
- { S(next), T_CMD,
- checkdb_begin, nextkey_handler, NULL,
- { { N_("[KEY]"), GDBM_ARG_DATUM, DS_KEY },
- { NULL } },
- FALSE,
- REPEAT_NOARG,
- N_("continue iteration: get next key and datum") },
- { S(store), T_CMD,
- checkdb_begin, store_handler, NULL,
- { { N_("KEY"), GDBM_ARG_DATUM, DS_KEY },
+ { NULL }
+ },
+ .doc = N_("import"),
+ .tok = T_CMD,
+ .handler = import_handler,
+ .variadic = FALSE,
+ .repeat = REPEAT_NEVER,
+ },
+ {
+ .name = "list",
+ .doc = N_("list"),
+ .tok = T_CMD,
+ .begin = list_begin,
+ .handler = list_handler,
+ .variadic = FALSE,
+ .repeat = REPEAT_NEVER,
+ },
+ {
+ .name = "next",
+ .args = {
+ { N_("[KEY]"), GDBM_ARG_DATUM, DS_KEY },
+ { NULL }
+ },
+ .doc = N_("continue iteration: get next key and datum"),
+ .tok = T_CMD,
+ .begin = checkdb_begin,
+ .handler = nextkey_handler,
+ .variadic = FALSE,
+ .repeat = REPEAT_NOARG,
+ },
+ {
+ .name = "store",
+ .args = {
+ { N_("KEY"), GDBM_ARG_DATUM, DS_KEY },
{ N_("DATA"), GDBM_ARG_DATUM, DS_CONTENT },
- { NULL } },
- FALSE,
- REPEAT_NEVER,
- N_("store") },
- { S(first), T_CMD,
- checkdb_begin, firstkey_handler, NULL,
- { { NULL } },
- FALSE,
- REPEAT_NEVER,
- N_("begin iteration: get first key and datum") },
- { S(reorganize), T_CMD,
- checkdb_begin, reorganize_handler, NULL,
- { { NULL } },
- FALSE,
- REPEAT_NEVER,
- N_("reorganize") },
- { S(recover), T_CMD,
- checkdb_begin, recover_handler, NULL,
- { { "[verbose]", GDBM_ARG_STRING },
+ { NULL }
+ },
+ .doc = N_("store"),
+ .tok = T_CMD,
+ .begin = checkdb_begin,
+ .handler = store_handler,
+ .variadic = FALSE,
+ .repeat = REPEAT_NEVER,
+ },
+ {
+ .name = "first",
+ .doc = N_("begin iteration: get first key and datum"),
+ .tok = T_CMD,
+ .begin = checkdb_begin,
+ .handler = firstkey_handler,
+ .variadic = FALSE,
+ .repeat = REPEAT_NEVER,
+ },
+ {
+ .name = "reorganize",
+ .doc = N_("reorganize"),
+ .tok = T_CMD,
+ .begin = checkdb_begin,
+ .handler = reorganize_handler,
+ .variadic = FALSE,
+ .repeat = REPEAT_NEVER,
+ },
+ {
+ .name = "recover",
+ .args = {
+ { "[verbose]", GDBM_ARG_STRING },
{ "[summary]", GDBM_ARG_STRING },
{ "[backup]", GDBM_ARG_STRING },
{ "[force]", GDBM_ARG_STRING },
{ "[max-failed-keys=N]", GDBM_ARG_STRING },
{ "[max-failed-buckets=N]", GDBM_ARG_STRING },
{ "[max-failures=N]", GDBM_ARG_STRING },
- { NULL } },
- FALSE,
- REPEAT_NEVER,
- N_("recover the database") },
- { S(avail), T_CMD,
- avail_begin, avail_handler, NULL,
- { { NULL } },
- FALSE,
- REPEAT_NEVER,
- N_("print avail list") },
- { S(bucket), T_CMD,
- print_bucket_begin, print_current_bucket_handler, NULL,
- { { N_("NUMBER"), GDBM_ARG_STRING },
- { NULL } },
- FALSE,
- REPEAT_NEVER,
- N_("print a bucket") },
- { S(current), T_CMD,
- print_current_bucket_begin, print_current_bucket_handler, NULL,
- { { NULL } },
- FALSE,
- REPEAT_NEVER,
- N_("print current bucket") },
- { S(dir), T_CMD,
- print_dir_begin, print_dir_handler, NULL,
- { { NULL } },
- FALSE,
- REPEAT_NEVER,
- N_("print hash directory") },
- { S(header), T_CMD,
- print_header_begin , print_header_handler, NULL,
- { { NULL } },
- FALSE,
- REPEAT_NEVER,
- N_("print database file header") },
- { S(hash), T_CMD,
- NULL, hash_handler, NULL,
- { { N_("KEY"), GDBM_ARG_DATUM, DS_KEY },
- { NULL } },
- FALSE,
- REPEAT_NEVER,
- N_("hash value of key") },
- { S(cache), T_CMD,
- print_cache_begin, print_cache_handler, NULL,
- { { NULL } },
- FALSE,
- REPEAT_NEVER,
- N_("print the bucket cache") },
- { S(status), T_CMD,
- NULL, status_handler, NULL,
- { { NULL } },
- FALSE,
- REPEAT_NEVER,
- N_("print current program status") },
- { S(sync), T_CMD,
- checkdb_begin, sync_handler, NULL,
- { { NULL } },
- FALSE,
- REPEAT_NEVER,
- N_("Synchronize the database with disk copy") },
- { S(upgrade), T_CMD,
- checkdb_begin, upgrade_handler, NULL,
- { { NULL } },
- FALSE,
- REPEAT_NEVER,
- N_("Upgrade the database to extended format") },
- { S(downgrade), T_CMD,
- checkdb_begin, downgrade_handler, NULL,
- { { NULL } },
- FALSE,
- REPEAT_NEVER,
- N_("Downgrade the database to standard format") },
- { S(snapshot), T_CMD,
- NULL, snapshot_handler, NULL,
- { { "FILE", GDBM_ARG_STRING },
+ { NULL }
+ },
+ .doc = N_("recover the database"),
+ .tok = T_CMD,
+ .begin = checkdb_begin,
+ .handler = recover_handler,
+ .variadic = FALSE,
+ .repeat = REPEAT_NEVER,
+ },
+ {
+ .name = "avail",
+ .doc = N_("print avail list"),
+ .tok = T_CMD,
+ .begin = avail_begin,
+ .handler = avail_handler,
+ .variadic = FALSE,
+ .repeat = REPEAT_NEVER,
+ },
+ {
+ .name = "bucket",
+ .args = {
+ { N_("NUMBER"), GDBM_ARG_STRING },
+ { NULL }
+ },
+ .doc = N_("print a bucket"),
+ .tok = T_CMD,
+ .begin = print_bucket_begin,
+ .handler = print_current_bucket_handler,
+ .variadic = FALSE,
+ .repeat = REPEAT_NEVER,
+ },
+ {
+ .name = "current",
+ .doc = N_("print current bucket"),
+ .tok = T_CMD,
+ .begin = print_current_bucket_begin,
+ .handler = print_current_bucket_handler,
+ .variadic = FALSE,
+ .repeat = REPEAT_NEVER,
+ },
+ {
+ .name = "dir",
+ .doc = N_("print hash directory"),
+ .tok = T_CMD,
+ .begin = print_dir_begin,
+ .handler = print_dir_handler,
+ .variadic = FALSE,
+ .repeat = REPEAT_NEVER,
+ },
+ {
+ .name = "header",
+ .doc = N_("print database file header"),
+ .tok = T_CMD,
+ .begin = print_header_begin,
+ .handler = print_header_handler,
+ .variadic = FALSE,
+ .repeat = REPEAT_NEVER,
+ },
+ {
+ .name = "hash",
+ .args = {
+ { N_("KEY"), GDBM_ARG_DATUM, DS_KEY },
+ { NULL }
+ },
+ .doc = N_("hash value of key"),
+ .tok = T_CMD,
+ .handler = hash_handler,
+ .variadic = FALSE,
+ .repeat = REPEAT_NEVER,
+ },
+ {
+ .name = "cache",
+ .doc = N_("print the bucket cache"),
+ .tok = T_CMD,
+ .begin = print_cache_begin,
+ .handler = print_cache_handler,
+ .variadic = FALSE,
+ .repeat = REPEAT_NEVER,
+ },
+ {
+ .name = "status",
+ .doc = N_("print current program status"),
+ .tok = T_CMD,
+ .handler = status_handler,
+ .variadic = FALSE,
+ .repeat = REPEAT_NEVER,
+ },
+ {
+ .name = "sync",
+ .doc = N_("Synchronize the database with disk copy"),
+ .tok = T_CMD,
+ .begin = checkdb_begin,
+ .handler = sync_handler,
+ .variadic = FALSE,
+ .repeat = REPEAT_NEVER,
+ },
+ {
+ .name = "upgrade",
+ .doc = N_("Upgrade the database to extended format"),
+ .tok = T_CMD,
+ .begin = checkdb_begin,
+ .handler = upgrade_handler,
+ .variadic = FALSE,
+ .repeat = REPEAT_NEVER,
+ },
+ {
+ .name = "downgrade",
+ .doc = N_("Downgrade the database to standard format"),
+ .tok = T_CMD,
+ .begin = checkdb_begin,
+ .handler = downgrade_handler,
+ .variadic = FALSE,
+ .repeat = REPEAT_NEVER,
+ },
+ {
+ .name = "snapshot",
+ .args = {
{ "FILE", GDBM_ARG_STRING },
- { NULL } },
- FALSE,
- REPEAT_NEVER,
- N_("analyze two database snapshots") },
- { S(version), T_CMD,
- NULL, print_version_handler, NULL,
- { { NULL } },
- FALSE,
- REPEAT_NEVER,
- N_("print version of gdbm") },
- { S(help), T_CMD,
- help_begin, help_handler, NULL,
- { { NULL } },
- FALSE,
- REPEAT_NEVER,
- N_("print this help list") },
- { S(quit), T_CMD,
- NULL, quit_handler, NULL,
- { { NULL } },
- FALSE,
- REPEAT_NEVER,
- N_("quit the program") },
- { S(set), T_SET,
- NULL, NULL, NULL,
- { { "[VAR=VALUE...]" }, { NULL } },
- FALSE,
- REPEAT_NEVER,
- N_("set or list variables") },
- { S(unset), T_UNSET,
- NULL, NULL, NULL,
- { { "VAR..." }, { NULL } },
- FALSE,
- REPEAT_NEVER,
- N_("unset variables") },
- { S(define), T_DEF,
- NULL, NULL, NULL,
- { { "key|content", GDBM_ARG_STRING },
+ { "FILE", GDBM_ARG_STRING },
+ { NULL }
+ },
+ .doc = N_("analyze two database snapshots"),
+ .tok = T_CMD,
+ .handler = snapshot_handler,
+ .variadic = FALSE,
+ .repeat = REPEAT_NEVER,
+ },
+ {
+ .name = "version",
+ .doc = N_("print version of gdbm"),
+ .tok = T_CMD,
+ .handler = print_version_handler,
+ .variadic = FALSE,
+ .repeat = REPEAT_NEVER,
+ },
+ {
+ .name = "help",
+ .doc = N_("print this help list"),
+ .tok = T_CMD,
+ .begin = help_begin,
+ .handler = help_handler,
+ .variadic = FALSE,
+ .repeat = REPEAT_NEVER,
+ },
+ {
+ .name = "quit",
+ .doc = N_("quit the program"),
+ .tok = T_CMD,
+ .handler = quit_handler,
+ .variadic = FALSE,
+ .repeat = REPEAT_NEVER,
+ },
+ {
+ .name = "set",
+ .args = {
+ { "[VAR=VALUE...]" },
+ { NULL }
+ },
+ .doc = N_("set or list variables"),
+ .tok = T_SET,
+ .variadic = FALSE,
+ .repeat = REPEAT_NEVER,
+ },
+ {
+ .name = "unset",
+ .args = {
+ { "VAR..." },
+ { NULL }
+ },
+ .doc = N_("unset variables"),
+ .tok = T_UNSET,
+ .variadic = FALSE,
+ .repeat = REPEAT_NEVER,
+ },
+ {
+ .name = "define",
+ .args = {
+ { "key|content", GDBM_ARG_STRING },
{ "{ FIELD-LIST }", GDBM_ARG_STRING },
- { NULL } },
- FALSE,
- REPEAT_NEVER,
- N_("define datum structure") },
- { S(source), T_CMD,
- NULL, source_handler, NULL,
- { { "FILE", GDBM_ARG_STRING },
- { NULL } },
- FALSE,
- REPEAT_NEVER,
- N_("source command script") },
- { S(close), T_CMD,
- NULL, close_handler, NULL,
- { { NULL } },
- FALSE,
- REPEAT_NEVER,
- N_("close the database") },
- { S(open), T_CMD,
- NULL, open_handler, NULL,
- { { "[FILE]", GDBM_ARG_STRING }, { NULL } },
- FALSE,
- REPEAT_NEVER,
- N_("open new database") },
- { S(history), T_CMD,
- input_history_begin, input_history_handler, NULL,
- { { N_("[FROM]"), GDBM_ARG_STRING },
+ { NULL }
+ },
+ .doc = N_("define datum structure"),
+ .tok = T_DEF,
+ .variadic = FALSE,
+ .repeat = REPEAT_NEVER,
+ },
+ {
+ .name = "source",
+ .args = {
+ { "FILE", GDBM_ARG_STRING },
+ { NULL }
+ },
+ .doc = N_("source command script"),
+ .tok = T_CMD,
+ .handler = source_handler,
+ .variadic = FALSE,
+ .repeat = REPEAT_NEVER,
+ },
+ {
+ .name = "close",
+ .doc = N_("close the database"),
+ .tok = T_CMD,
+ .handler = close_handler,
+ .variadic = FALSE,
+ .repeat = REPEAT_NEVER,
+ },
+ {
+ .name = "open",
+ .args = {
+ { "[FILE]", GDBM_ARG_STRING },
+ { NULL }
+ },
+ .doc = N_("open new database"),
+ .tok = T_CMD,
+ .handler = open_handler,
+ .variadic = FALSE,
+ .repeat = REPEAT_NEVER,
+ },
+ {
+ .name = "history",
+ .args = {
+ { N_("[FROM]"), GDBM_ARG_STRING },
{ N_("[COUNT]"), GDBM_ARG_STRING },
- { NULL } },
- FALSE,
- REPEAT_NEVER,
- N_("show input history") },
- { S(debug), T_CMD,
- NULL, debug_handler, NULL,
- { { NULL } },
- TRUE,
- REPEAT_NEVER,
- N_("query/set debug level") },
- { S(shell), T_SHELL,
- NULL, shell_handler, NULL,
- { { NULL } },
- TRUE,
- REPEAT_NEVER,
- N_("invoke the shell") },
- { S(perror), T_CMD,
- NULL, perror_handler, NULL,
- { { "[CODE]", GDBM_ARG_STRING },
- { NULL } },
- TRUE,
- REPEAT_NEVER,
- N_("describe GDBM error code") },
-#undef S
+ { NULL }
+ },
+ .doc = N_("show input history"),
+ .tok = T_CMD,
+ .begin = input_history_begin,
+ .handler = input_history_handler,
+ .variadic = FALSE,
+ .repeat = REPEAT_NEVER,
+ },
+ {
+ .name = "debug",
+ .doc = N_("query/set debug level"),
+ .tok = T_CMD,
+ .handler = debug_handler,
+ .variadic = TRUE,
+ .repeat = REPEAT_NEVER,
+ },
+ {
+ .name = "shell",
+ .doc = N_("invoke the shell"),
+ .tok = T_SHELL,
+ .handler = shell_handler,
+ .variadic = TRUE,
+ .repeat = REPEAT_NEVER,
+ },
+ {
+ .name = "perror",
+ .args = {
+ { "[CODE]", GDBM_ARG_STRING },
+ { NULL }
+ },
+ .doc = N_("describe GDBM error code"),
+ .tok = T_CMD,
+ .handler = perror_handler,
+ .variadic = FALSE,
+ .repeat = REPEAT_NEVER,
+ },
{ NULL }
};
@@ -2707,8 +2851,11 @@ gdbmshell_run (int (*init) (void *, instream_t *), void *data)
if (!commands_sorted)
{
- qsort (command_tab, ARRAY_SIZE (command_tab) - 1,
- sizeof (command_tab[0]), cmdcmp);
+ /* Initialize .len fields */
+ for (i = 0; command_tab[i].name; i++)
+ command_tab[i].len = strlen (command_tab[i].name);
+ /* Sort the entries by name. */
+ qsort (command_tab, i, sizeof (command_tab[0]), cmdcmp);
commands_sorted = 1;
}

Return to:

Send suggestions and report system problems to the System administrator.