"SfR Fresh" - the SfR Freeware/Shareware Archive 
As a special service "SfR Fresh" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting with prefixed line numbers.
Alternatively you can here view or download the uninterpreted source code file.
That can be also achieved for any archive member file by clicking within an archive contents listing on the first character of the file(path) respectively on the according byte size field.
1 /*
2 * Brutus header file for a configuration file class.
3 * Copyright (C) 2004 OMC Denmark ApS.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20
21 #ifndef _CONFIG_H_
22 #define _CONFIG_H_
23
24 #include <stdlib.h>
25 #include <string.h>
26 #include <new>
27
28 class Config {
29 public:
30 Config(const char *stack_token)
31 {
32 _fbuf = NULL;
33 _items = NULL;
34 _fsize = 0;
35 _stack = _strdup(stack_token);
36 if (!_stack)
37 throw std::bad_alloc();
38 };
39
40 Config(void)
41 {
42 _fbuf = NULL;
43 _items = NULL;
44 _fsize = 0;
45 _stack = NULL;
46 };
47
48 ~Config()
49 {
50 if (_fbuf)
51 free(_fbuf);
52
53 if (_items)
54 free(_items);
55
56 if (_stack)
57 free(_stack);
58 };
59
60 // Loads the configuration file
61 int load(const char *file);
62
63 // Will cyclically get all the item pairs, starting
64 // at the first, returning false when there are no more.
65 //
66 // *MUST* be called before get_value().
67 //
68 bool get_token_value_pair(const char *token,
69 const char *value);
70
71 // Will return the textual value of the token
72 char *get_value(const char *token);
73
74 private:
75 int _lnum;
76 char *_fbuf;
77 size_t _fsize;
78 char *_stack;
79
80 struct item {
81 char *token;
82 char *value;
83 };
84 struct item *_items;
85
86 // whitespace?
87 bool wspace(char c)
88 {
89 switch (c) {
90 case ' ' :
91 case '\t' :
92 case '\r' :
93 return true;
94 default:
95 return false;
96 }
97 };
98
99 int itemize(void);
100 int point_to_value(char **str, char **val);
101 int get_next_line(char **str);
102 int read_conf(const char *file_name, size_t *size, void **buf);
103 };
104
105 #endif // _CONFIG_H_
106
107 /*
108 * Local variables:
109 * mode: C++
110 * c-basic-offset: 8
111 * tab-width: 8
112 * indent-tabs-mode: nil
113 * End:
114 */