chiark / gitweb /
Imported Debian patch 1.0.0-5
[e16] / src / econfig.h
1 /*
2  * Copyright (C) 2003-2007 Kim Woelders
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to
6  * deal in the Software without restriction, including without limitation the
7  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8  * sell copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies of the Software, its documentation and marketing & publicity
13  * materials, and acknowledgment shall be given in the documentation, materials
14  * and software packages that this Software was used.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  */
23 #ifndef _ECONFIG_H_
24 #define _ECONFIG_H_
25
26 typedef struct {
27    const char         *name;
28    void               *ptr;
29    char                type;
30    long                dflt;
31    void                (*func) (void *item, const char *value);
32 } CfgItem;
33
34 typedef struct {
35    int                 num;
36    const CfgItem      *lst;
37 } CfgItemList;
38
39 #define ITEM_TYPE_BOOL    0
40 #define ITEM_TYPE_INT     1
41 #define ITEM_TYPE_HEX     2
42 #define ITEM_TYPE_STRING  3
43
44 #define CFG_ITEM_BOOL(conf, name, dflt)  { #name, &conf.name, ITEM_TYPE_BOOL, dflt, NULL }
45 #define CFG_ITEM_INT(conf, name, dflt)   { #name, &conf.name, ITEM_TYPE_INT, dflt, NULL }
46 #define CFG_ITEM_HEX(conf, name, dflt)   { #name, &conf.name, ITEM_TYPE_HEX, dflt, NULL }
47 #define CFG_ITEM_STR(conf, name)         { #name, &conf.name, ITEM_TYPE_STRING, 0, NULL }
48
49 #define CFG_FUNC_BOOL(conf, name, dflt, func)  { #name, &conf.name, ITEM_TYPE_BOOL, dflt, func }
50 #define CFG_FUNC_INT(conf, name, dflt, func)   { #name, &conf.name, ITEM_TYPE_INT, dflt, func }
51 #define CFG_FUNC_STR(conf, name, func)         { #name, &conf.name, ITEM_TYPE_STRING, 0, func }
52
53 /* Change to this? */
54 #define CFR_ITEM_BOOL(conf, name, dflt)  { #name, &conf, ITEM_TYPE_BOOL, dflt, NULL }
55
56 const CfgItem      *CfgItemFind(const CfgItem * pcl, int ncl, const char *name);
57 void                CfgItemToString(const CfgItem * ci, char *buf, int len);
58
59 int                 CfgItemListNamedItemSet(const CfgItem * pcl, int ncl,
60                                             const char *item,
61                                             const char *value);
62
63 #endif /* _ECONFIG_H_ */