source: trunk/gsdl/src/db2txt/db2txt.cpp@ 558

Last change on this file since 558 was 535, checked in by sjboddie, 25 years ago

added GPL header

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 2.3 KB
Line 
1/**********************************************************************
2 *
3 * db2txt.cpp --
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
27#ifdef __WIN32__
28#include "autoconf.h"
29#include "systems.h"
30#include "gdbmconst.h"
31#include "gdbm.h"
32
33#else
34#include <gdbm.h>
35#endif
36
37#include "gsdlconf.h"
38#include <stdlib.h>
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
48void print_usage (char *program_name) {
49 cerr << "usage: " << program_name << " database-name\n\n";
50}
51
52
53int main (int argc, char *argv[]) {
54 int block_size = 0, i;
55 GDBM_FILE dbf;
56 datum key, value;
57
58 // sanity check
59 if (argc != 2) {
60 print_usage (argv[0]);
61 exit (0);
62 }
63
64 // open the database
65 dbf = gdbm_open (argv[1], block_size, GDBM_READER, 00664, NULL);
66 if (dbf == NULL) {
67 cerr << "couldn't create " << argv[1] << "\n";
68 exit (0);
69 }
70
71 key = gdbm_firstkey (dbf);
72 while (key.dptr != NULL) {
73 cout << "[";
74 for (i = 0; i < key.dsize; i++)
75 cout << key.dptr[i];
76 cout << "]\n";
77 value = gdbm_fetch (dbf, key);
78 for (i = 0; i < value.dsize; i++)
79 cout << value.dptr[i];
80 cout << "\n----------------------------------------------------------------------\n";
81 key = gdbm_nextkey (dbf, key);
82 delete value.dptr;
83 }
84
85 gdbm_close (dbf);
86 return 0;
87}
Note: See TracBrowser for help on using the repository browser.