1 | #ifndef GDBMCLASS_H
|
---|
2 | #define GDBMCLASS_H
|
---|
3 |
|
---|
4 | #ifdef __WIN32__
|
---|
5 | #include "autoconf.h"
|
---|
6 | #include "systems.h"
|
---|
7 | #include "gdbmconst.h"
|
---|
8 | #include "gdbm.h"
|
---|
9 |
|
---|
10 | #else
|
---|
11 | #include <gdbm.h>
|
---|
12 | #endif
|
---|
13 |
|
---|
14 | #include "locateinfo.h"
|
---|
15 |
|
---|
16 |
|
---|
17 | class gdbm_info
|
---|
18 | {
|
---|
19 | public:
|
---|
20 | int docnum;
|
---|
21 | int d;
|
---|
22 | text_t t;
|
---|
23 | text_t p;
|
---|
24 | text_t x;
|
---|
25 | text_t c;
|
---|
26 | text_t j;
|
---|
27 | text_t o;
|
---|
28 | text_t a;
|
---|
29 |
|
---|
30 | void clear ();
|
---|
31 | };
|
---|
32 |
|
---|
33 |
|
---|
34 | class gdbmclass
|
---|
35 | {
|
---|
36 | public:
|
---|
37 | gdbmclass() {gdbm_file = NULL; logout = &cerr;};
|
---|
38 | ~gdbmclass() {};
|
---|
39 |
|
---|
40 | // returns 0 on success, -1 on failure
|
---|
41 | int getinfo (text_t key, text_t collection, gdbm_info &info);
|
---|
42 | void setgdbmhome (const text_t &thegdbmhome);
|
---|
43 | void setlogout (ostream *thelogout) {logout = thelogout;}
|
---|
44 | int exists (text_t key, text_t collection);
|
---|
45 |
|
---|
46 | protected:
|
---|
47 | text_t gdbmhome; // top level directory for gdbm files
|
---|
48 | GDBM_FILE gdbm_file;
|
---|
49 | text_t gdbm_open_name;
|
---|
50 | ostream *logout;
|
---|
51 |
|
---|
52 | int open_database (const text_t &collection);
|
---|
53 | void close_database ();
|
---|
54 |
|
---|
55 | int get_infoline (char *str, int len, int pos, char *key, char *value);
|
---|
56 | };
|
---|
57 |
|
---|
58 |
|
---|
59 | // a few useful functions
|
---|
60 |
|
---|
61 | int is_top_level (const text_t &targetdoc);
|
---|
62 | int is_book (const text_t &targetdoc);
|
---|
63 | void get_book_top (const text_t &targetdoc, text_t &book_top);
|
---|
64 | void get_book (const text_t &targetdoc, text_t &book);
|
---|
65 | void get_parent_section (text_t §ion);
|
---|
66 | void get_parent_section (text_t &parentsection, text_t &childsection);
|
---|
67 | int count_dots (text_t::const_iterator first, text_t::const_iterator last);
|
---|
68 | int count_dots (const text_t &targetdoc);
|
---|
69 | int is_section_top (const text_t &targetdoc);
|
---|
70 | void remove_tags (text_t &text);
|
---|
71 |
|
---|
72 | void seperate_parts (const text_t &targetdoc, gdbmclass &gdbm, const text_t &collection,
|
---|
73 | text_t &classification, text_t &booksection);
|
---|
74 | void split_targetdoc (const text_t &targetdoc, text_t &classification,
|
---|
75 | text_t &booksection);
|
---|
76 | void splitstring (const text_t &string, vector<text_t> &array);
|
---|
77 | void get_parents (const text_t &targetdoc, vector<text_t> &parents);
|
---|
78 | void get_siblings (const text_t &classification, const text_t &booksection,
|
---|
79 | gdbmclass &gdbm, const text_t &collection,
|
---|
80 | vector<text_t> &siblings);
|
---|
81 | int are_same_chapter(text_t section1, text_t section2);
|
---|
82 | void get_first_section(const text_t &instring, text_t &returnstring);
|
---|
83 | int is_number (text_t &text);
|
---|
84 | text_t get_section_str(const text_t &str);
|
---|
85 | void alphabetize_string_english (text_t &text);
|
---|
86 | void alphabetize_string_name (text_t &text);
|
---|
87 | char ** string_add (char **array, int *len, char *str);
|
---|
88 | void string_sort (char **array, int len);
|
---|
89 | static int compare_str (const void *e1, const void *e2);
|
---|
90 | void string_free(char **array, int len);
|
---|
91 | #endif
|
---|