1 | /**********************************************************************
|
---|
2 | *
|
---|
3 | * gdbmclass.h --
|
---|
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 | * $Id: gdbmclass.h 534 1999-09-07 04:57:43Z sjboddie $
|
---|
25 | *
|
---|
26 | *********************************************************************/
|
---|
27 |
|
---|
28 |
|
---|
29 | #ifndef GDBMCLASS_H
|
---|
30 | #define GDBMCLASS_H
|
---|
31 |
|
---|
32 |
|
---|
33 |
|
---|
34 | #ifdef __WIN32__
|
---|
35 | #include "autoconf.h"
|
---|
36 | #include "systems.h"
|
---|
37 | #include "gdbmconst.h"
|
---|
38 | #include "gdbm.h"
|
---|
39 |
|
---|
40 | #else
|
---|
41 | #include <gdbm.h>
|
---|
42 | #endif
|
---|
43 |
|
---|
44 |
|
---|
45 | class gdbm_info {
|
---|
46 | public:
|
---|
47 | int docnum; // 'd'
|
---|
48 | text_t title; // 't'
|
---|
49 | text_t parent; // 'p'
|
---|
50 | text_t classification; // 'x'
|
---|
51 | text_t contents; // 'c'
|
---|
52 | text_t jobnum; // 'j'
|
---|
53 | text_t OID; // 'o'
|
---|
54 | text_t author; // 'a'
|
---|
55 | text_t source; // 's'
|
---|
56 | text_t date; // 'i'
|
---|
57 |
|
---|
58 | void clear ();
|
---|
59 | };
|
---|
60 |
|
---|
61 |
|
---|
62 | class gdbmclass {
|
---|
63 | public:
|
---|
64 | gdbmclass() {gdbmfile = NULL; logout = &cerr;};
|
---|
65 | ~gdbmclass() {};
|
---|
66 |
|
---|
67 | // returns 0 if failed, 1 if opened
|
---|
68 | int opendatabase (const text_t &filename);
|
---|
69 | void closedatabase ();
|
---|
70 |
|
---|
71 | // returns 0 on success, -1 on failure
|
---|
72 | int getinfo (text_t key, gdbm_info &info);
|
---|
73 | void setlogout (ostream *thelogout) {logout = thelogout;}
|
---|
74 | int exists (text_t key);
|
---|
75 |
|
---|
76 | protected:
|
---|
77 | text_t openfile;
|
---|
78 | GDBM_FILE gdbmfile;
|
---|
79 | ostream *logout;
|
---|
80 |
|
---|
81 | int getkeydata (text_t key, text_t &data);
|
---|
82 | int getinfoline (text_t::iterator &here, text_t::iterator end,
|
---|
83 | text_t &key, text_t &value);
|
---|
84 | };
|
---|
85 |
|
---|
86 |
|
---|
87 | // a few useful functions
|
---|
88 |
|
---|
89 | int is_top_level (const text_t &targetdoc);
|
---|
90 | int is_book (const text_t &targetdoc);
|
---|
91 | void get_book_top (const text_t &targetdoc, text_t &book_top);
|
---|
92 | void get_book (const text_t &targetdoc, text_t &book);
|
---|
93 | void get_parent_section (text_t §ion);
|
---|
94 | void get_parent_section (text_t &parentsection, text_t &childsection);
|
---|
95 | int count_dots (text_t::const_iterator first, text_t::const_iterator last);
|
---|
96 | int count_dots (const text_t &targetdoc);
|
---|
97 | int is_section_top (const text_t &targetdoc);
|
---|
98 | void remove_tags (text_t &text);
|
---|
99 |
|
---|
100 | void separate_parts (const text_t &targetdoc, gdbmclass &gdbm,
|
---|
101 | text_t &classification, text_t &booksection);
|
---|
102 | void split_targetdoc (const text_t &targetdoc, text_t &classification,
|
---|
103 | text_t &booksection);
|
---|
104 | void splitstring (const text_t &string, vector<text_t> &array);
|
---|
105 | void get_parents (const text_t &targetdoc, vector<text_t> &parents);
|
---|
106 | void get_siblings (const text_t &classification, const text_t &booksection,
|
---|
107 | gdbmclass &gdbm, vector<text_t> &siblings);
|
---|
108 | int are_same_chapter(text_t section1, text_t section2);
|
---|
109 | void get_first_section(const text_t &instring, text_t &returnstring);
|
---|
110 | int is_number (text_t &text);
|
---|
111 | text_t get_section_str(const text_t &str);
|
---|
112 | void alphabetize_string_english (text_t &text);
|
---|
113 | void alphabetize_string_name (text_t &text);
|
---|
114 | char ** string_add (char **array, int *len, char *str);
|
---|
115 | void string_sort (char **array, int len);
|
---|
116 | void string_free(char **array, int len);
|
---|
117 | text_t format_date (const text_t &date);
|
---|
118 | void format_month (text_t &month);
|
---|
119 | void format_day(text_t &day);
|
---|
120 |
|
---|
121 |
|
---|
122 | #endif
|
---|