source: main/trunk/greenstone2/common-src/src/gdbmedit/db2txt/db2txt.cpp@ 26650

Last change on this file since 26650 was 26650, checked in by davidb, 11 years ago

Code changed from using WIN32 use to _MSC_VER (the difference being the former is set for any Windows based compiler, whilst the latter is specifically set by a MicroSoft Visual Studio compiler). Up to this point the difference was not important, however to allow for cross-compilation (using mingw under Linux to produce native Windows binaries) the difference is imporant, and needs to be used more carefully

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 2.8 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#ifdef _MSC_VER
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>
38
39#if defined(GSDL_USE_OBJECTSPACE)
40#include <ospace\std\iostream>
41#elif defined(GSDL_USE_IOS_H)
42#include <iostream.h>
43#else
44#include <iostream>
45#endif
46
47// use the standard namespace
48#if !defined (GSDL_NAMESPACE_BROKEN)
49#if defined(GSDL_USE_OBJECTSPACE)
50using namespace ospace::std;
51#else
52using namespace std;
53#endif
54#endif
55
56void print_usage (char *program_name) {
57 cerr << "usage: " << program_name << " database-name" << endl << endl;
58}
59
60
61int main (int argc, char *argv[]) {
62 int block_size = 0, i;
63 GDBM_FILE dbf;
64 datum key, value, nextkey;
65
66 // sanity check
67 if (argc != 2) {
68 print_usage (argv[0]);
69 exit (0);
70 }
71
72 // open the database
73#ifdef _MSC_VER
74 dbf = gdbm_open (argv[1], block_size, GDBM_READER, 00664, NULL, 0);
75#else
76 dbf = gdbm_open (argv[1], block_size, GDBM_READER, 00664, NULL);
77#endif
78 if (dbf == NULL) {
79 cerr << argv[0] << ": couldn't open " << argv[1] << endl;
80 exit (0);
81 }
82
83 key = gdbm_firstkey (dbf);
84 while (key.dptr != NULL) {
85 cout << "[";
86 for (i = 0; i < key.dsize; ++i)
87 cout << key.dptr[i];
88 cout << "]" << endl;
89 value = gdbm_fetch (dbf, key);
90 for (i = 0; i < value.dsize; ++i)
91 cout << value.dptr[i];
92 cout << endl << "----------------------------------------------------------------------" << endl;
93 free(value.dptr);
94
95 /* get next key */
96 nextkey = gdbm_nextkey (dbf, key);
97
98 /* free old key's dptr, otherwise causes memory leak */
99 free(key.dptr);
100
101 /* can now safely copy content of nextkey into key */
102 key = nextkey;
103 }
104
105 gdbm_close (dbf);
106 return 0;
107}
Note: See TracBrowser for help on using the repository browser.