aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am12
-rw-r--r--src/gdbmtool.c102
-rw-r--r--src/gdbmtool.h31
-rw-r--r--src/gram.y7
-rw-r--r--src/input-rl.c235
-rw-r--r--src/input-std.c43
-rw-r--r--src/lex.l134
7 files changed, 483 insertions, 81 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 6a05634..b55deb6 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -81,3 +81,7 @@ bin_PROGRAMS = gdbmtool gdbm_load gdbm_dump
81 81
82gdbmtool_LDADD = ./libgdbmapp.a ./libgdbm.la 82gdbmtool_LDADD = \
83 ./libgdbmapp.a\
84 ./libgdbm.la\
85 @READLINE_LIBS@
86
83gdbmtool_SOURCES = \ 87gdbmtool_SOURCES = \
@@ -91,2 +95,8 @@ gdbmtool_SOURCES = \
91 95
96if GDBM_COND_READLINE
97 gdbmtool_SOURCES += input-rl.c
98else
99 gdbmtool_SOURCES += input-std.c
100endif
101
92AM_YFLAGS = -dtv 102AM_YFLAGS = -dtv
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 ()
325} 325}
326
327
328#define ARG_UNUSED __attribute__ ((__unused__))
329
330#define NARGS 5
331
332struct handler_param
333{
334 int argc;
335 struct gdbmarg **argv;
336 FILE *fp;
337 void *data;
338};
339
340 326
@@ -753,3 +739,3 @@ quit_handler (struct handler_param *param ARG_UNUSED)
753 gdbm_close (gdbm_file); 739 gdbm_close (gdbm_file);
754 740 input_done ();
755 exit (EXIT_OK); 741 exit (EXIT_OK);
@@ -893,2 +879,4 @@ struct argdef
893 879
880#define NARGS 5
881
894struct command 882struct command
@@ -904,3 +892,2 @@ struct command
904}; 892};
905
906 893
@@ -1009,2 +996,9 @@ struct command command_tab[] = {
1009 N_("open new database") }, 996 N_("open new database") },
997#ifdef WITH_READLINE
998 { S(history), T_CMD,
999 input_history_begin, input_history_handler, NULL,
1000 { { N_("[FROM]"), GDBM_ARG_STRING },
1001 { N_("[COUNT]"), GDBM_ARG_STRING },
1002 { NULL } }, N_("show input history") },
1003#endif
1010#undef S 1004#undef S
@@ -1028,2 +1022,35 @@ sort_commands ()
1028 1022
1023/* Generator function for command completion. STATE lets us know whether
1024 to start from scratch; without any state (i.e. STATE == 0), then we
1025 start at the top of the list. */
1026char *
1027command_generator (const char *text, int state)
1028{
1029 const char *name;
1030 static int len;
1031 static struct command *cmd;
1032
1033 /* If this is a new word to complete, initialize now. This includes
1034 saving the length of TEXT for efficiency, and initializing the index
1035 variable to 0. */
1036 if (!state)
1037 {
1038 cmd = command_tab;
1039 len = strlen (text);
1040 }
1041
1042 if (!cmd->name)
1043 return NULL;
1044
1045 /* Return the next name which partially matches from the command list. */
1046 while ((name = cmd->name))
1047 {
1048 cmd++;
1049 if (strncmp (name, text, len) == 0)
1050 return strdup (name);
1051 }
1052
1053 /* If no names matched, then return NULL. */
1054 return NULL;
1055}
1029 1056
@@ -1176,3 +1203,3 @@ gdbmarg_kvpair (struct kvpair *kvp, struct locus *loc)
1176struct slist * 1203struct slist *
1177slist_new (char *s) 1204slist_new_s (char *s)
1178{ 1205{
@@ -1184,2 +1211,17 @@ slist_new (char *s)
1184 1211
1212struct slist *
1213slist_new (char const *s)
1214{
1215 return slist_new_s (estrdup (s));
1216}
1217
1218struct slist *
1219slist_new_l (char const *s, size_t l)
1220{
1221 char *copy = emalloc (l + 1);
1222 memcpy (copy, s, l);
1223 copy[l] = 0;
1224 return slist_new_s (copy);
1225}
1226
1185void 1227void
@@ -1195,2 +1237,17 @@ slist_free (struct slist *lp)
1195} 1237}
1238
1239void
1240slist_insert (struct slist **where, struct slist *what)
1241{
1242 if (*where)
1243 {
1244 while (what->next)
1245 what = what->next;
1246 what->next = (*where)->next;
1247 (*where)->next = what;
1248 }
1249 else
1250 what->next = NULL;
1251 *where = what;
1252}
1196 1253
@@ -1218,3 +1275,2 @@ kvpair_list (struct locus *loc, struct slist *s)
1218 1275
1219
1220static void 1276static void
@@ -1536,2 +1592,3 @@ main (int argc, char *argv[])
1536 int norc = 0; 1592 int norc = 0;
1593 int res;
1537 char *source = "-"; 1594 char *source = "-";
@@ -1547,5 +1604,6 @@ main (int argc, char *argv[])
1547 sort_commands (); 1604 sort_commands ();
1548 1605
1549 /* Initialize variables. */ 1606 /* Initialize variables. */
1550 intr = isatty (0); 1607 intr = isatty (0);
1608 interactive = intr; /* Used early by input_init */
1551 dsdef[DS_KEY] = dsegm_new_field (datadef_lookup ("string"), NULL, 1); 1609 dsdef[DS_KEY] = dsegm_new_field (datadef_lookup ("string"), NULL, 1);
@@ -1556,2 +1614,4 @@ main (int argc, char *argv[])
1556 1614
1615 input_init ();
1616
1557 for (opt = parseopt_first (argc, argv, optab); 1617 for (opt = parseopt_first (argc, argv, optab);
@@ -1642,3 +1702,5 @@ main (int argc, char *argv[])
1642 exit (EXIT_FATAL); 1702 exit (EXIT_FATAL);
1643 return yyparse (); 1703 res = yyparse ();
1704 input_done ();
1705 return res;
1644} 1706}
diff --git a/src/gdbmtool.h b/src/gdbmtool.h
index 84f1409..d0e9aa0 100644
--- a/src/gdbmtool.h
+++ b/src/gdbmtool.h
@@ -26,2 +26,4 @@
26 26
27#define ARG_UNUSED __attribute__ ((__unused__))
28
27/* Position in input file */ 29/* Position in input file */
@@ -96,3 +98,3 @@ void terror (const char *fmt, ...);
96 98
97void print_prompt (void); 99char *make_prompt (void);
98 100
@@ -106,2 +108,13 @@ extern int open_mode;
106#define GDBMTOOL_DEFFILE "junk.gdbm" 108#define GDBMTOOL_DEFFILE "junk.gdbm"
109
110ssize_t input_read (FILE *fp, char *buf, size_t size);
111void input_init (void);
112void input_done (void);
113
114struct handler_param;
115void input_history_handler (struct handler_param *param);
116int input_history_begin (struct handler_param *param, size_t *exp_count);
117
118void print_prompt_at_bol (void);
119char *command_generator (const char *text, int state);
107 120
@@ -114,4 +127,7 @@ struct slist
114 127
115struct slist *slist_new (char *s); 128struct slist *slist_new (char const *s);
129struct slist *slist_new_s (char *s);
130struct slist *slist_new_l (char const *s, size_t l);
116void slist_free (struct slist *); 131void slist_free (struct slist *);
132void slist_insert (struct slist **where, struct slist *what);
117 133
@@ -163,2 +179,10 @@ struct gdbmarglist
163 179
180struct handler_param
181{
182 int argc;
183 struct gdbmarg **argv;
184 FILE *fp;
185 void *data;
186};
187
164void gdbmarglist_init (struct gdbmarglist *, struct gdbmarg *); 188void gdbmarglist_init (struct gdbmarglist *, struct gdbmarg *);
@@ -264 +288,4 @@ int vgetyn (const char *prompt, va_list ap);
264int getyn (const char *prompt, ...); 288int getyn (const char *prompt, ...);
289
290int getnum (int *pnum, char *arg, char **endp);
291int get_screen_lines (void);
diff --git a/src/gram.y b/src/gram.y
index 9a6e3c2..2f6d7c0 100644
--- a/src/gram.y
+++ b/src/gram.y
@@ -170,3 +170,3 @@ slist : string
170 { 170 {
171 $$.head = $$.tail = slist_new ($1); 171 $$.head = $$.tail = slist_new_s ($1);
172 } 172 }
@@ -174,5 +174,4 @@ slist : string
174 { 174 {
175 struct slist *s = slist_new ($3); 175 struct slist *s = slist_new_s ($3);
176 $1.tail->next = s; 176 slist_insert (&$1.tail, s);
177 $1.tail = s;
178 $$ = $1; 177 $$ = $1;
diff --git a/src/input-rl.c b/src/input-rl.c
new file mode 100644
index 0000000..f435ed4
--- /dev/null
+++ b/src/input-rl.c
@@ -0,0 +1,235 @@
1/* This file is part of GDBM, the GNU data base manager.
2 Copyright (C) 2016 Free Software Foundation, Inc.
3
4 GDBM is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3, or (at your option)