aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2013-05-14 10:16:09 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2013-05-14 10:16:09 +0000
commite0fba6888fc9ee90d27ac03a06844b22bad101be (patch)
tree873f30cd678e3d2bfad4fd5e3ce4a9d878156037 /src
parent10201217d141314a78a7937027bfdbdb7c994a43 (diff)
downloadgdbm-e0fba6888fc9ee90d27ac03a06844b22bad101be.tar.gz
gdbm-e0fba6888fc9ee90d27ac03a06844b22bad101be.tar.bz2
Cleanup.
* src/datconv.c (s_float): Use strtod. (datum_scan_notag, datum_scan_tag): Made static. (dsprint): New function. * src/gdbmtool.c (status_handler): Print ket and content definitions. (slist_new): Bugfix (missing return statement). * src/gdbmtool.h: Add new prototypes. * src/lex.l: Remove unused variables, set option nounput.
Diffstat (limited to 'src')
-rw-r--r--src/datconv.c39
-rw-r--r--src/gdbmtool.c16
-rw-r--r--src/gdbmtool.h15
-rw-r--r--src/lex.l5
4 files changed, 62 insertions, 13 deletions
diff --git a/src/datconv.c b/src/datconv.c
index 6f5e2f5..cf17011 100644
--- a/src/datconv.c
+++ b/src/datconv.c
@@ -128,7 +128,7 @@ s_float (struct xdatum *xd, char *str)
char *p;
errno = 0;
- d = strtof (str, &p);
+ d = strtod (str, &p);
if (errno || *p)
return 1;
xd_store (xd, &d, sizeof (d));
@@ -302,11 +302,11 @@ xd_store (struct xdatum *xd, void *val, size_t size)
xd->dsize = xd->off;
}
-int
+static int
datum_scan_notag (datum *dat, struct dsegm *ds, struct kvpair *kv)
{
struct xdatum xd;
- int i, n;
+ int i;
struct slist *s;
int err = 0;
@@ -377,7 +377,7 @@ datum_scan_notag (datum *dat, struct dsegm *ds, struct kvpair *kv)
return 0;
}
-int
+static int
datum_scan_tag (datum *dat, struct dsegm *ds, struct kvpair *kv)
{
parse_error (&kv->loc, "tagged values are not yet supported");
@@ -389,3 +389,34 @@ datum_scan (datum *dat, struct dsegm *ds, struct kvpair *kv)
{
return (kv->key ? datum_scan_tag : datum_scan_notag) (dat, ds, kv);
}
+
+void
+dsprint (FILE *fp, int what, struct dsegm *ds)
+{
+ static char *dsstr[] = { "key", "content" };
+
+ fprintf (fp, "define %s {\n", dsstr[what]);
+ for (; ds; ds = ds->next)
+ {
+ switch (ds->type)
+ {
+ case FDEF_FLD:
+ fprintf (fp, "\t%s", ds->v.field.type->name);
+ if (ds->v.field.name)
+ fprintf (fp, " %s", ds->v.field.type->name);
+ if (ds->v.field.dim > 1)
+ fprintf (fp, "[%d]", ds->v.field.dim);
+ fprintf (fp, ",\n");
+ break;
+
+ case FDEF_OFF:
+ fprintf (fp, "\toff %d,\n", ds->v.n);
+ break;
+
+ case FDEF_PAD:
+ fprintf (fp, "\tpad %d,\n", ds->v.n);
+ break;
+ }
+ }
+ fprintf (fp, "}\n");
+}
diff --git a/src/gdbmtool.c b/src/gdbmtool.c
index 905c3fb..b9d771b 100644
--- a/src/gdbmtool.c
+++ b/src/gdbmtool.c
@@ -735,17 +735,13 @@ import_handler (struct handler_param *param)
}
}
-static const char *
-boolstr (int val)
-{
- return val ? _("yes") : _("no");
-}
-
/* S - print current program status */
void
status_handler (struct handler_param *param)
{
fprintf (param->fp, _("Database file: %s\n"), file_name);
+ dsprint (param->fp, DS_KEY, dsdef[DS_KEY]);
+ dsprint (param->fp, DS_CONTENT, dsdef[DS_CONTENT]);
}
void
@@ -864,7 +860,7 @@ struct command command_tab[] = {
{ { NULL } }, N_("quit the program") },
{ S(set), T_SET,
NULL, NULL, NULL,
- { { "[var=value...]" }, NULL }, N_("set or list variables") },
+ { { "[var=value...]" }, { NULL } }, N_("set or list variables") },
{ S(define), T_DEF,
NULL, NULL, NULL,
{ { "key|content", ARG_STRING },
@@ -960,6 +956,11 @@ command_lookup (const char *str, struct locus *loc, struct command **pcmd)
/* fall through */
case fcom_ambig:
fprintf (stderr, " %s\n", cmd->name);
+ break;
+
+ case fcom_abort:
+ /* should not happen */
+ abort ();
}
}
}
@@ -1033,6 +1034,7 @@ slist_new (char *s)
struct slist *lp = emalloc (sizeof (*lp));
lp->next = NULL;
lp->str = s;
+ return lp;
}
void
diff --git a/src/gdbmtool.h b/src/gdbmtool.h
index 96e0ba5..3887338 100644
--- a/src/gdbmtool.h
+++ b/src/gdbmtool.h
@@ -22,6 +22,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
+#include <ctype.h>
/* Position in input file */
struct point
@@ -231,4 +232,18 @@ int variable_set (const char *name, int type, void *val);
int variable_get (const char *name, int type, void **val);
void variable_print_all (FILE *fp);
+
+int unescape (int c);
+int escape (int c);
+void begin_def (void);
+void end_def (void);
+
+int yylex (void);
+int yyerror (char *s);
+int yyparse (void);
+
+void datum_format (FILE *fp, datum const *dat, struct dsegm *ds);
+int datum_scan (datum *dat, struct dsegm *ds, struct kvpair *kv);
+void dsprint (FILE *fp, int what, struct dsegm *ds);
+
diff --git a/src/lex.l b/src/lex.l
index fda3002..8596365 100644
--- a/src/lex.l
+++ b/src/lex.l
@@ -131,7 +131,6 @@ findctx (struct stat *st)
int
setsource (const char *name, int intr)
{
- int rc;
struct stat st;
struct context *cp;
FILE *fp;
@@ -190,6 +189,8 @@ setsource (const char *name, int intr)
}
%}
+%option nounput
+
%x STR DEF
WS [ \t][ \t]*
@@ -201,7 +202,7 @@ O [0-7]
%%
^[ \t]*#[ \t]*line[ \t].*\n {
- char *p, *q;
+ char *p;
char *file = NULL;
int line, len;

Return to:

Send suggestions and report system problems to the System administrator.