00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _SC_CONF_H
00025 #define _SC_CONF_H
00026
00027 #ifdef __cplusplus
00028 extern "C" {
00029 #endif
00030
00031 typedef struct _scconf_entry {
00032 const char *name;
00033 unsigned int type;
00034 unsigned int flags;
00035 void *parm;
00036 void *arg;
00037 } scconf_entry;
00038
00039
00040 #define SCCONF_PRESENT 0x00000001
00041 #define SCCONF_MANDATORY 0x00000002
00042 #define SCCONF_ALLOC 0x00000004
00043 #define SCCONF_ALL_BLOCKS 0x00000008
00044 #define SCCONF_VERBOSE 0x00000010
00045
00046
00047 #define SCCONF_CALLBACK 1
00048 #define SCCONF_BLOCK 2
00049 #define SCCONF_LIST 3
00050
00051 #define SCCONF_BOOLEAN 11
00052 #define SCCONF_INTEGER 12
00053 #define SCCONF_STRING 13
00054
00055 typedef struct _scconf_block scconf_block;
00056
00057 typedef struct _scconf_list {
00058 struct _scconf_list *next;
00059 char *data;
00060 } scconf_list;
00061
00062 #define SCCONF_ITEM_TYPE_COMMENT 0
00063 #define SCCONF_ITEM_TYPE_BLOCK 1
00064 #define SCCONF_ITEM_TYPE_VALUE 2
00065
00066 typedef struct _scconf_item {
00067 struct _scconf_item *next;
00068 int type;
00069 char *key;
00070 union {
00071 char *comment;
00072 scconf_block *block;
00073 scconf_list *list;
00074 } value;
00075 } scconf_item;
00076
00077 struct _scconf_block {
00078 scconf_block *parent;
00079 scconf_list *name;
00080 scconf_item *items;
00081 };
00082
00083 typedef struct {
00084 char *filename;
00085 int debug;
00086 scconf_block *root;
00087 char *errmsg;
00088 } scconf_context;
00089
00090
00091
00092
00093 extern scconf_context *scconf_new(const char *filename);
00094
00095
00096
00097 extern void scconf_free(scconf_context * config);
00098
00099
00100
00101
00102 extern int scconf_parse(scconf_context * config);
00103
00104
00105
00106
00107 extern int scconf_parse_string(scconf_context * config, const char *string);
00108
00109
00110
00111 extern int scconf_parse_entries(const scconf_context * config, const scconf_block * block, scconf_entry * entry);
00112
00113
00114
00115
00116
00117 extern int scconf_write(scconf_context * config, const char *filename);
00118
00119
00120
00121 extern int scconf_write_entries(scconf_context * config, scconf_block * block, scconf_entry * entry);
00122
00123
00124
00125
00126 extern const scconf_block *scconf_find_block(const scconf_context * config, const scconf_block * block, const char *item_name);
00127
00128
00129
00130
00131
00132 extern scconf_block **scconf_find_blocks(const scconf_context * config, const scconf_block * block, const char *item_name, const char *key);
00133
00134
00135
00136 extern const scconf_list *scconf_find_list(const scconf_block * block, const char *option);
00137
00138
00139
00140
00141 extern const char *scconf_get_str(const scconf_block * block, const char *option, const char *def);
00142
00143
00144
00145
00146 extern int scconf_get_int(const scconf_block * block, const char *option, int def);
00147
00148
00149
00150
00151 extern int scconf_get_bool(const scconf_block * block, const char *option, int def);
00152
00153
00154
00155 extern const char *scconf_put_str(scconf_block * block, const char *option, const char *value);
00156
00157
00158
00159 extern int scconf_put_int(scconf_block * block, const char *option, int value);
00160
00161
00162
00163 extern int scconf_put_bool(scconf_block * block, const char *option, int value);
00164
00165
00166
00167
00168 extern scconf_block *scconf_block_add(scconf_context * config, scconf_block * block, const char *key, const scconf_list *name);
00169
00170
00171
00172 extern scconf_block *scconf_block_copy(const scconf_block * src, scconf_block ** dst);
00173
00174
00175
00176 extern void scconf_block_destroy(scconf_block * block);
00177
00178
00179
00180
00181 extern scconf_item *scconf_item_add(scconf_context * config, scconf_block * block, scconf_item * item, int type, const char *key, const void *data);
00182
00183
00184
00185 extern scconf_item *scconf_item_copy(const scconf_item * src, scconf_item ** dst);
00186
00187
00188
00189 extern void scconf_item_destroy(scconf_item * item);
00190
00191
00192
00193 extern scconf_list *scconf_list_add(scconf_list ** list, const char *value);
00194
00195
00196
00197 extern scconf_list *scconf_list_copy(const scconf_list * src, scconf_list ** dst);
00198
00199
00200
00201 extern void scconf_list_destroy(scconf_list * list);
00202
00203
00204
00205 extern int scconf_list_array_length(const scconf_list * list);
00206
00207
00208
00209 extern int scconf_list_strings_length(const scconf_list * list);
00210
00211
00212
00213
00214
00215 extern char *scconf_list_strdup(const scconf_list * list, const char *filler);
00216
00217
00218
00219
00220
00221
00222 extern const char **scconf_list_toarray(const scconf_list * list);
00223
00224 #ifdef __cplusplus
00225 }
00226 #endif
00227 #endif