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/>.
26 main (int argc, char **argv)
28 const char *progname = canonical_progname (argv[0]);
36 int mode = GDBM_WRCREAT;
41 size_t mapped_size_max = 0;
47 if (strcmp (arg, "-h") == 0)
49 printf ("usage: %s [-replace] [-clear] [-blocksize=N] [-null] [-nolock] [-nommap] [-maxmap=N] [-sync] [-delim=CHR] DBFILE\n", progname);
52 else if (strcmp (arg, "-replace") == 0)
53 replace |= GDBM_REPLACE;
54 else if (strcmp (arg, "-clear") == 0)
56 else if (strcmp (arg, "-null") == 0)
58 else if (strcmp (arg, "-nolock") == 0)
60 else if (strcmp (arg, "-nommap") == 0)
62 else if (strcmp (arg, "-sync") == 0)
64 else if (strncmp (arg, "-blocksize=", 11) == 0)
65 block_size = atoi (arg + 11);
66 else if (strncmp (arg, "-maxmap=", 8) == 0)
71 mapped_size_max = strtoul (arg + 8, &p, 10);
75 fprintf (stderr, "%s: ", progname);
82 fprintf (stderr, "%s: bad maxmap\n", progname);
86 else if (strncmp (arg, "-delim=", 7) == 0)
88 else if (strcmp (arg, "--") == 0)
94 else if (arg[0] == '-')
96 fprintf (stderr, "%s: unknown option %s\n", progname, arg);
105 fprintf (stderr, "%s: wrong arguments\n", progname);
110 dbf = gdbm_open (dbname, block_size, mode|flags, 00664, NULL);
113 fprintf (stderr, "gdbm_open failed: %s\n", gdbm_strerror (gdbm_errno));
119 if (gdbm_setopt (dbf, GDBM_SETMAXMAPSIZE, &mapped_size_max,
120 sizeof (mapped_size_max)))
122 fprintf (stderr, "gdbm_setopt failed: %s\n",
123 gdbm_strerror (gdbm_errno));
128 while (fgets (buf, sizeof buf, stdin))
131 size_t len = strlen (buf);
133 if (buf[len - 1] != '\n')
135 fprintf (stderr, "%s: %d: line too long\n",
144 for (i = j = 0; i < len; i++)
148 else if (buf[i] == delim)
156 fprintf (stderr, "%s: %d: malformed line\n",
163 key.dsize = j + data_z;
164 data.dptr = buf + i + 1;
165 data.dsize = strlen (data.dptr) + data_z;
166 if (gdbm_store (dbf, key, data, replace) != 0)
168 fprintf (stderr, "%s: %d: item not inserted\n",