1 /* This file is part of GDBM test suite.
2 Copyright (C) 2011 Free Software Foundation, Inc.
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 2, or (at your option)
9 GDBM is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with GDBM. If not, see <http://www.gnu.org/licenses/>.
22 #include <sys/types.h>
32 main (int argc, char **argv)
34 const char *progname = canonical_progname (argv[0]);
47 if (strcmp (arg, "-h") == 0)
49 printf ("usage: %s [-null] [-delim=CHR] DBFILE\n", progname);
52 else if (strcmp (arg, "-null") == 0)
54 else if (strncmp (arg, "-delim=", 7) == 0)
56 else if (strcmp (arg, "--") == 0)
62 else if (arg[0] == '-')
64 fprintf (stderr, "%s: unknown option %s\n", progname, arg);
73 fprintf (stderr, "%s: wrong arguments\n", progname);
77 /* Check if .pag file exists. Create it if it doesn't, as DBM
78 cannot do it itself. */
80 dbname = malloc (strlen (*argv) + sizeof (PAGSUF));
84 strcat (strcpy (dbname, *argv), PAGSUF);
86 if (access (dbname, F_OK))
88 int fd = creat (dbname, 0644);
91 fprintf (stderr, "%s: ", progname);
101 fprintf (stderr, "dbminit failed\n");
105 while (fgets (buf, sizeof buf, stdin))
108 size_t len = strlen (buf);
110 if (buf[len - 1] != '\n')
112 fprintf (stderr, "%s: %d: line too long\n",
121 for (i = j = 0; i < len; i++)
125 else if (buf[i] == delim)
133 fprintf (stderr, "%s: %d: malformed line\n",
140 key.dsize = j + data_z;
141 data.dptr = buf + i + 1;
142 data.dsize = strlen (data.dptr) + data_z;
143 if (store (key, data) != 0)
145 fprintf (stderr, "%s: %d: item not inserted\n",