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]);
52 if (strcmp (arg, "-h") == 0)
54 printf ("usage: %s [-null] [-delim=CHR] DBFILE KEY [KEY...]\n",
58 else if (strcmp (arg, "-null") == 0)
60 else if (strncmp (arg, "-delim=", 7) == 0)
62 else if (strcmp (arg, "--") == 0)
68 else if (arg[0] == '-')
70 fprintf (stderr, "%s: unknown option %s\n", progname, arg);
79 fprintf (stderr, "%s: wrong arguments\n", progname);
86 fprintf (stderr, "dbminit failed\n");
95 key.dsize = strlen (arg) + !!data_z;
98 if (data.dptr == NULL)
101 fprintf (stderr, "%s: ", progname);
102 print_key (stderr, key, delim);
103 fprintf (stderr, ": not found\n");
108 print_key (stdout, key, delim);
109 fputc (delim, stdout);
112 fwrite (data.dptr, data.dsize - !!data_z, 1, stdout);
114 fputc ('\n', stdout);