source: main/trunk/greenstone2/common-src/src/gdbmedit/gdbmget/gdbmget.cpp@ 22039

Last change on this file since 22039 was 22039, checked in by davidb, 14 years ago

Improved error reporting to GDBMedit utils

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 2.6 KB
RevLine 
[12844]1/**********************************************************************
2 *
3 * gdbmget -- retrieve a single value from the GDBM database
4 * Copyright (C) 1999 The New Zealand Digital Library Project
5 *
6 * A component of the Greenstone digital library software
7 * from the New Zealand Digital Library Project at the
8 * University of Waikato, New Zealand.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 *********************************************************************/
25
26#ifdef __WIN32__
27#include "autoconf.h"
28#include "systems.h"
29#include "gdbmconst.h"
30#include "gdbm.h"
31
32#else
33#include <gdbm.h>
34#endif
35
36#include "gsdlconf.h"
37#include <stdlib.h>
[18880]38#include <cstring>
[12844]39
40#if defined(GSDL_USE_OBJECTSPACE)
41#include <ospace\std\iostream>
42#elif defined(GSDL_USE_IOS_H)
43#include <iostream.h>
44#else
45#include <iostream>
46#endif
47
48// use the standard namespace
49#if !defined (GSDL_NAMESPACE_BROKEN)
50#if defined(GSDL_USE_OBJECTSPACE)
51using namespace ospace::std;
52#else
53using namespace std;
54#endif
55#endif
56
57void
58print_usage (char *program_name)
59{
[17091]60 cerr << "usage: " << program_name << " <database_path> <key>" << endl;
61 cerr << endl;
[12844]62}
63
64
[17091]65int main (int argc, char *argv[])
[12844]66{
67 int block_size = 0;
68 GDBM_FILE dbf;
69 datum key, value;
70
71 // sanity check
72 if (argc != 3)
73 {
74 print_usage (argv[0]);
[17091]75 exit (-1);
[12844]76 }
77
78 // open the database
79#ifdef __WIN32__
80 dbf = gdbm_open (argv[1], block_size, GDBM_READER, 00664, NULL, 0);
81#else
82 dbf = gdbm_open (argv[1], block_size, GDBM_READER, 00664, NULL);
83#endif
84 if (dbf == NULL)
85 {
[22039]86 cerr << argv[0] << ": couldn't open " << argv[1] << endl;
[17091]87 exit (-1);
[12844]88 }
89
90 key.dsize = strlen(argv[2]);
91 key.dptr = argv[2];
92 value = gdbm_fetch (dbf, key);
93 if (value.dsize > 0)
94 {
95 for (int i = 0; i < value.dsize; i++)
96 {
97 cout << value.dptr[i];
98 }
[17782]99 cout << endl; // used to be printf("\n");
[15932]100 // ?? free(value.dptri);
[12844]101 }
102 else
103 {
[17782]104 cout << endl; // used to be printf("\n");
[12844]105 }
106
107 gdbm_close (dbf);
108 return 0;
109}
110
Note: See TracBrowser for help on using the repository browser.