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 |
|
---|
48 | void print_usage (char *program_name) {
|
---|
49 | cerr << "usage: " << program_name << " database-name\n\n";
|
---|
50 | }
|
---|
51 |
|
---|
52 |
|
---|
53 | int 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 | #ifdef __WIN32__
|
---|
66 | dbf = gdbm_open (argv[1], block_size, GDBM_READER, 00664, NULL, 0);
|
---|
67 | #else
|
---|
68 | dbf = gdbm_open (argv[1], block_size, GDBM_READER, 00664, NULL);
|
---|
69 | #endif
|
---|
70 | if (dbf == NULL) {
|
---|
71 | cerr << "couldn't create " << argv[1] << "\n";
|
---|
72 | exit (0);
|
---|
73 | }
|
---|
74 |
|
---|
75 | key = gdbm_firstkey (dbf);
|
---|
76 | while (key.dptr != NULL) {
|
---|
77 | cout << "[";
|
---|
78 | for (i = 0; i < key.dsize; i++)
|
---|
79 | cout << key.dptr[i];
|
---|
80 | cout << "]\n";
|
---|
81 | value = gdbm_fetch (dbf, key);
|
---|
82 | for (i = 0; i < value.dsize; i++)
|
---|
83 | cout << value.dptr[i];
|
---|
84 | cout << "\n----------------------------------------------------------------------\n";
|
---|
85 | key = gdbm_nextkey (dbf, key);
|
---|
86 | delete value.dptr;
|
---|
87 | }
|
---|
88 |
|
---|
89 | gdbm_close (dbf);
|
---|
90 | return 0;
|
---|
91 | }
|
---|