2 ** Copyright 1998 - 1999 Double Precision, Inc.
3 ** See COPYING for distribution information.
17 static const char rcsid
[]="$Id: makedatprog.c,v 1.4 1999/12/06 13:22:17 mrsam Exp $";
19 static int addgdbm(char *p
, struct dbobj
*o
)
27 if ( (val
=strchr(p
, '\t')) == 0) val
="";
33 if (dbobj_store(o
, key
, strlen(key
), val
, strlen(val
), "I"))
35 fprintf(stderr
, "Cannot store record for %s - duplicate or out of disk space.\n", key
);
42 static int buildgdbm(FILE *i
, struct dbobj
*o
)
45 size_t bufsize
, buflen
;
57 if (buflen
>= bufsize
)
60 buf
= buf
? realloc(buf
, bufsize
):
69 if (c
== '\n' || c
== EOF
) break;
73 if (c
== EOF
) return (-1);
75 if (strcmp(buf
, ".") == 0) return (0);
76 if (addgdbm(buf
, o
)) return (-1);
80 int main(int argc
, char **argv
)
87 fprintf(stderr
, "Usage: %s textfile tmpfile gdbmfile\n",
91 if (strcmp(argv
[1], "-") == 0)
95 if ((i
=fopen(argv
[1], "r")) == 0)
104 if (dbobj_open(&obj
, argv
[2], "N"))
106 fprintf(stderr
, "Cannot create %s\n", argv
[2]);
110 if (buildgdbm(i
, &obj
))
119 if (rename(argv
[2], argv
[3]))