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/>.
25 main (int argc, char **argv)
27 const char *progname = canonical_progname (argv[0]);
39 if (strcmp (arg, "-h") == 0)
41 printf ("usage: %s [-nolock] [-nommap] [-delim=CHR] DBFILE\n",
45 else if (strcmp (arg, "-nolock") == 0)
47 else if (strcmp (arg, "-nommap") == 0)
49 else if (strcmp (arg, "-sync") == 0)
51 else if (strncmp (arg, "-delim=", 7) == 0)
53 else if (strcmp (arg, "--") == 0)
59 else if (arg[0] == '-')
61 fprintf (stderr, "%s: unknown option %s\n", progname, arg);
70 fprintf (stderr, "%s: wrong arguments\n", progname);
75 dbf = gdbm_open (dbname, 0, GDBM_READER|flags, 00664, NULL);
78 fprintf (stderr, "gdbm_open failed: %s\n", gdbm_strerror (gdbm_errno));
82 key = gdbm_firstkey (dbf);
86 datum nextkey = gdbm_nextkey (dbf, key);
88 for (i = 0; i < key.dsize && key.dptr[i]; i++)
90 if (key.dptr[i] == delim || key.dptr[i] == '\\')
92 fputc (key.dptr[i], stdout);
95 fputc (delim, stdout);
97 data = gdbm_fetch (dbf, key);
99 if (data.dptr[i-1] == 0)
102 fwrite (data.dptr, i, 1, stdout);
105 fputc ('\n', stdout);