ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/include/confparse.h
Revision: 1.7
Committed: Sat Sep 22 14:27:26 2007 UTC (16 years, 7 months ago) by pippijn
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.6: +3 -3 lines
Log Message:
split up ermyth into ermyth-modules, libermyth (currently just ermyth-util) and ermyth-core

File Contents

# Content
1 /**
2 * confparse.h: Data structures for flags to bitmask processing routines.
3 *
4 * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team
5 * Rights to this code are as documented in COPYING.
6 *
7 *
8 * Portions of this file were derived from sources bearing the following license:
9 * Copyright © 2005 William Pitcock, et al.
10 * Rights to this code are as documented in doc/pod/license.pod.
11 *
12 * $Id: confparse.h,v 1.6 2007-09-16 18:54:42 pippijn Exp $
13 */
14
15 #ifndef CONFPARSE_H
16 #define CONFPARSE_H
17
18 #include <util/containers.h>
19 #include <ermyth/callback.h>
20 #include <ermyth/type_traits.h>
21
22 struct config_file_t : zero_initialised
23 {
24 char *cf_filename;
25 config_entry_t *cf_entries;
26 config_file_t *cf_next;
27 };
28
29 struct config_entry_t : zero_initialised
30 {
31 config_file_t *ce_fileptr;
32
33 int ce_varlinenum;
34 char *ce_varname;
35 char *ce_vardata;
36 int ce_vardatanum;
37 int ce_fileposstart;
38 int ce_fileposend;
39
40 int ce_sectlinenum;
41 config_entry_t *ce_entries;
42
43 config_entry_t *ce_prevlevel;
44
45 config_entry_t *ce_next;
46
47 bool valid ()
48 {
49 return ce_vardata != NULL;
50 }
51
52 template<typename T>
53 T vardata ()
54 {
55 return vardata (types::get<T> ());
56 }
57
58 private:
59 char *vardata (types::charptr_type)
60 {
61 return ce_vardata;
62 }
63
64 int vardata (types::int_type)
65 {
66 return ce_vardatanum;
67 }
68 };
69
70 struct Token
71 {
72 char const * const text;
73 int const value;
74 };
75
76 class ConfTable
77 {
78 struct callbacks
79 {
80 functor::callback0<> ready;
81 };
82
83 public: // typedefs
84 unsigned index;
85 typedef indexing_vector<ConfTable> list_type;
86
87 public: // variables
88 char const * const name;
89 int const rehashable;
90 int (*handler) (config_entry_t *);
91 char *str_val;
92 int *int_val;
93
94 static callbacks callback;
95
96 ConfTable (char const * const blockname, int const can_rehash, int (*handlerfunc) (config_entry_t *))
97 : name (blockname), rehashable (can_rehash), handler (handlerfunc), str_val (0), int_val (0)
98 {
99 }
100 };
101
102 E void init_newconf (void);
103 E void conf_cleanup (void);
104 E struct ConfTable *find_top_conf (char const * const name);
105 E struct ConfTable *find_conf_item (char const * const name, ConfTable::list_type &conflist);
106 E void add_top_conf (char const * const name, int (*handler) (config_entry_t *ce));
107 E void add_conf_item (char const * const name, ConfTable::list_type &conflist, int (*handler) (config_entry_t *ce));
108 E void del_top_conf (char const * const name);
109 E void del_conf_item (char const * const name, ConfTable::list_type &conflist);
110 E int subblock_handler (config_entry_t *ce, ConfTable::list_type &entries);
111
112 #endif