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, 8 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

# User Rev Content
1 pippijn 1.6 /**
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 pippijn 1.3 * Copyright © 2005 William Pitcock, et al.
10 pippijn 1.2 * Rights to this code are as documented in doc/pod/license.pod.
11 pippijn 1.1 *
12 pippijn 1.7 * $Id: confparse.h,v 1.6 2007-09-16 18:54:42 pippijn Exp $
13 pippijn 1.1 */
14    
15     #ifndef CONFPARSE_H
16     #define CONFPARSE_H
17    
18 pippijn 1.7 #include <util/containers.h>
19 pippijn 1.3 #include <ermyth/callback.h>
20 pippijn 1.4 #include <ermyth/type_traits.h>
21 pippijn 1.3
22     struct config_file_t : zero_initialised
23 pippijn 1.1 {
24     char *cf_filename;
25     config_entry_t *cf_entries;
26     config_file_t *cf_next;
27     };
28    
29 pippijn 1.3 struct config_entry_t : zero_initialised
30 pippijn 1.1 {
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 pippijn 1.4
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 pippijn 1.1 };
69    
70     struct Token
71     {
72 pippijn 1.3 char const * const text;
73     int const value;
74 pippijn 1.1 };
75    
76 pippijn 1.4 class ConfTable
77 pippijn 1.1 {
78 pippijn 1.3 struct callbacks
79     {
80     functor::callback0<> ready;
81     };
82    
83 pippijn 1.5 public: // typedefs
84     unsigned index;
85     typedef indexing_vector<ConfTable> list_type;
86    
87     public: // variables
88 pippijn 1.3 char const * const name;
89     int const rehashable;
90 pippijn 1.1 int (*handler) (config_entry_t *);
91     char *str_val;
92     int *int_val;
93 pippijn 1.3
94     static callbacks callback;
95    
96     ConfTable (char const * const blockname, int const can_rehash, int (*handlerfunc) (config_entry_t *))
97 pippijn 1.4 : name (blockname), rehashable (can_rehash), handler (handlerfunc), str_val (0), int_val (0)
98 pippijn 1.3 {
99     }
100 pippijn 1.1 };
101    
102 pippijn 1.4 E void init_newconf (void);
103 pippijn 1.7 E void conf_cleanup (void);
104 pippijn 1.4 E struct ConfTable *find_top_conf (char const * const name);
105 pippijn 1.5 E struct ConfTable *find_conf_item (char const * const name, ConfTable::list_type &conflist);
106 pippijn 1.4 E void add_top_conf (char const * const name, int (*handler) (config_entry_t *ce));
107 pippijn 1.5 E void add_conf_item (char const * const name, ConfTable::list_type &conflist, int (*handler) (config_entry_t *ce));
108 pippijn 1.4 E void del_top_conf (char const * const name);
109 pippijn 1.5 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 pippijn 1.1
112     #endif