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 print_key (FILE *fp, datum key, int delim)
29 for (i = 0; i < key.dsize && key.dptr[i]; i++)
31 if (key.dptr[i] == delim || key.dptr[i] == '\\')
33 fputc (key.dptr[i], fp);
38 main (int argc, char **argv)
40 const char *progname = canonical_progname (argv[0]);
54 if (strcmp (arg, "-h") == 0)
56 printf ("usage: %s [-nolock] [-nommap] [-null] [-delim=CHR] DBFILE KEY [KEY...]\n",
60 else if (strcmp (arg, "-nolock") == 0)
62 else if (strcmp (arg, "-nommap") == 0)
64 else if (strcmp (arg, "-null") == 0)
66 else if (strncmp (arg, "-delim=", 7) == 0)
68 else if (strcmp (arg, "--") == 0)
74 else if (arg[0] == '-')
76 fprintf (stderr, "%s: unknown option %s\n", progname, arg);
85 fprintf (stderr, "%s: wrong arguments\n", progname);
90 dbf = gdbm_open (dbname, 0, GDBM_READER|flags, 00664, NULL);
93 fprintf (stderr, "gdbm_open failed: %s\n", gdbm_strerror (gdbm_errno));
102 key.dsize = strlen (arg) + !!data_z;
104 data = gdbm_fetch (dbf, key);
105 if (data.dptr == NULL)
108 fprintf (stderr, "%s: ", progname);
109 print_key (stderr, key, delim);
110 fprintf (stderr, ": not found\n");
115 print_key (stdout, key, delim);
116 fputc (delim, stdout);
119 fwrite (data.dptr, data.dsize - !!data_z, 1, stdout);
122 fputc ('\n', stdout);