source: gsdl/trunk/common-src/src/gdbmedit/gdbmdel/gdbmdel.cpp@ 18880

Last change on this file since 18880 was 18880, checked in by oranfry, 15 years ago

being more explicit about included libraries for the sake of newer compilers

  • Property svn:executable set to *
File size: 2.6 KB
Line 
1/**********************************************************************
2 *
3 * gdbmdel -- 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>
38#include <cstring>
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{
60 cerr << "usage: " << program_name << " <database_path> <key>" << endl;
61 cerr << endl;
62}
63
64
65int main (int argc, char *argv[])
66{
67 int block_size = 0;
68 GDBM_FILE dbf;
69 datum key;
70
71 // sanity check
72 if (argc != 3)
73 {
74 print_usage (argv[0]);
75 exit (-1);
76 }
77
78 // open the database
79#ifdef __WIN32__
80 dbf = gdbm_open (argv[1], block_size, GDBM_WRCREAT, 00664, NULL, 1);
81#else
82 dbf = gdbm_open (argv[1], block_size, GDBM_WRCREAT, 00664, NULL);
83#endif
84 if (dbf == NULL)
85 {
86 cerr << "Couldn't open " << argv[1] << endl;
87 exit (-1);
88 }
89
90 key.dsize = strlen(argv[2]);
91 key.dptr = argv[2];
92
93 int status = gdbm_delete (dbf, key);
94
95 // status:
96 // 0 == delete OK
97 // -1 == key does not exist or there was an error
98
99 if (status < 0) {
100 cerr << "Opened database " << argv[1] << endl;
101 cerr << " but couldn't delete: " << argv[2] << endl;
102 }
103
104 gdbm_close (dbf);
105
106 return status;
107}
108
Note: See TracBrowser for help on using the repository browser.