Annotation of sbbs/src/xpdev/ini_file.h, revision 1.1.1.2

1.1       root        1: /* ini_file.h */
                      2: 
1.1.1.2 ! root        3: /* Functions to parse ini (initialization / configuration) files */
1.1       root        4: 
1.1.1.2 ! root        5: /* $Id: ini_file.h,v 1.44 2011/07/21 10:47:47 rswindell Exp $ */
1.1       root        6: 
                      7: /****************************************************************************
                      8:  * @format.tab-size 4          (Plain Text/Source Code File Header)                    *
                      9:  * @format.use-tabs true       (see http://www.synchro.net/ptsc_hdr.html)              *
                     10:  *                                                                                                                                                     *
1.1.1.2 ! root       11:  * Copyright 2011 Rob Swindell - http://www.synchro.net/copyright.html         *
1.1       root       12:  *                                                                                                                                                     *
                     13:  * This library is free software; you can redistribute it and/or                       *
                     14:  * modify it under the terms of the GNU Lesser General Public License          *
                     15:  * as published by the Free Software Foundation; either version 2                      *
                     16:  * of the License, or (at your option) any later version.                                      *
                     17:  * See the GNU Lesser General Public License for more details: lgpl.txt or     *
                     18:  * http://www.fsf.org/copyleft/lesser.html                                                                     *
                     19:  *                                                                                                                                                     *
                     20:  * Anonymous FTP access to the most recent released source is available at     *
                     21:  * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net     *
                     22:  *                                                                                                                                                     *
                     23:  * Anonymous CVS access to the development source and modification history     *
                     24:  * is available at cvs.synchro.net:/cvsroot/sbbs, example:                                     *
                     25:  * cvs -d :pserver:[email protected]:/cvsroot/sbbs login                       *
                     26:  *     (just hit return, no password is necessary)                                                     *
                     27:  * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src                *
                     28:  *                                                                                                                                                     *
                     29:  * For Synchronet coding style and modification guidelines, see                                *
                     30:  * http://www.synchro.net/source.html                                                                          *
                     31:  *                                                                                                                                                     *
                     32:  * You are encouraged to submit any modifications (preferably in Unix diff     *
                     33:  * format) via e-mail to [email protected]                                                                      *
                     34:  *                                                                                                                                                     *
                     35:  * Note: If this box doesn't appear square, then you need to fix your tabs.    *
                     36:  ****************************************************************************/
                     37: 
                     38: #ifndef _INI_FILE_H
                     39: #define _INI_FILE_H
                     40: 
                     41: #include "genwrap.h"
                     42: #include "str_list.h"  /* strList_t */
                     43: #if !defined(NO_SOCKET_SUPPORT)
                     44:        #include "sockwrap.h"   /* inet_addr, SOCKET */
                     45: #endif
                     46: 
                     47: #define INI_MAX_VALUE_LEN      1024            /* Maximum value length, includes '\0' */
                     48: #define ROOT_SECTION           NULL
                     49: 
                     50: typedef struct {
                     51:        ulong           bit;
                     52:        const char*     name;
                     53: } ini_bitdesc_t;
                     54: 
                     55: typedef struct {
                     56:        int                     key_len;
                     57:        const char* key_prefix;
                     58:        const char* section_separator;
                     59:        const char* value_separator;
                     60:        const char*     bit_separator;
                     61: } ini_style_t;
                     62: 
                     63: #if defined(__cplusplus)
                     64: extern "C" {
                     65: #endif
                     66: 
                     67: /* Read all section names and return as an allocated string list */
                     68: /* Optionally (if prefix!=NULL), returns a subset of section names */
                     69: str_list_t     iniReadSectionList(FILE*, const char* prefix);
                     70: /* Read all key names and return as an allocated string list */
                     71: str_list_t     iniReadKeyList(FILE*, const char* section);
                     72: /* Read all key and value pairs and return as a named string list */
                     73: named_string_t**
                     74:                        iniReadNamedStringList(FILE*, const char* section);
                     75: 
                     76: /* Return the supported Log Levels in a string list - for *LogLevel macros */
                     77: str_list_t     iniLogLevelStringList(void);
                     78: 
                     79: /* These functions read a single key of the specified type */
                     80: char*          iniReadString(FILE*, const char* section, const char* key
                     81:                                        ,const char* deflt, char* value);
1.1.1.2 ! root       82: /* If the key doesn't exist, iniReadExistingString just returns NULL */
        !            83: char*          iniReadExistingString(FILE*, const char* section, const char* key
        !            84:                                        ,const char* deflt, char* value);
1.1       root       85: str_list_t     iniReadStringList(FILE*, const char* section, const char* key
                     86:                                        ,const char* sep, const char* deflt);
                     87: long           iniReadInteger(FILE*, const char* section, const char* key
                     88:                                        ,long deflt);
                     89: ushort         iniReadShortInt(FILE*, const char* section, const char* key
                     90:                                        ,ushort deflt);
                     91: ulong          iniReadLongInt(FILE*, const char* section, const char* key
                     92:                                        ,ulong deflt);
1.1.1.2 ! root       93: int64_t                iniReadBytes(FILE*, const char* section, const char* key
        !            94:                                        ,ulong unit, int64_t deflt);
1.1       root       95: double         iniReadFloat(FILE*, const char* section, const char* key
                     96:                                        ,double deflt);
                     97: BOOL           iniReadBool(FILE*, const char* section, const char* key
                     98:                                        ,BOOL deflt);
                     99: time_t         iniReadDateTime(FILE*, const char* section, const char* key
                    100:                                        ,time_t deflt);
                    101: unsigned       iniReadEnum(FILE*, const char* section, const char* key
                    102:                                        ,str_list_t names, unsigned deflt);
1.1.1.2 ! root      103: unsigned*      iniReadEnumList(FILE*, const char* section, const char* key
        !           104:                                        ,str_list_t names, unsigned* count, const char* sep, const char* deflt);
1.1       root      105: long           iniReadNamedInt(FILE*, const char* section, const char* key
                    106:                                        ,named_long_t*, long deflt);
                    107: double         iniReadNamedFloat(FILE*, const char* section, const char* key
                    108:                                        ,named_double_t*, double deflt);
                    109: ulong          iniReadBitField(FILE*, const char* section, const char* key
                    110:                                        ,ini_bitdesc_t* bitdesc, ulong deflt);
                    111: #define                iniReadLogLevel(f,s,k,d) iniReadEnum(f,s,k,iniLogLevelStringList(),d)
                    112: 
                    113: /* Free string list returned from iniRead*List functions */
                    114: void*          iniFreeStringList(str_list_t list);
                    115: 
                    116: /* Free named string list returned from iniReadNamedStringList */
                    117: void*          iniFreeNamedStringList(named_string_t** list);
                    118: 
                    119: 
                    120: /* File I/O Functions */
                    121: char*          iniFileName(char* dest, size_t maxlen, const char* dir, const char* fname);
                    122: FILE*          iniOpenFile(const char* fname, BOOL create);
                    123: str_list_t     iniReadFile(FILE*);
                    124: BOOL           iniWriteFile(FILE*, const str_list_t);
                    125: BOOL           iniCloseFile(FILE*);
                    126: 
                    127: /* StringList functions */
                    128: str_list_t     iniGetSectionList(str_list_t list, const char* prefix);
                    129: size_t         iniGetSectionCount(str_list_t list, const char* prefix);
                    130: str_list_t     iniGetKeyList(str_list_t list, const char* section);
                    131: named_string_t**
                    132:                        iniGetNamedStringList(str_list_t list, const char* section);
                    133: 
                    134: char*          iniGetString(str_list_t, const char* section, const char* key
1.1.1.2 ! root      135:                                        ,const char* deflt, char* value /* may be NULL */);
        !           136: /* If the key doesn't exist, iniGetExistingString just returns NULL */
        !           137: char*          iniGetExistingString(str_list_t, const char* section, const char* key
        !           138:                                        ,const char* deflt, char* value /* may be NULL */);
1.1       root      139: str_list_t     iniGetStringList(str_list_t, const char* section, const char* key
                    140:                                        ,const char* sep, const char* deflt);
                    141: long           iniGetInteger(str_list_t, const char* section, const char* key
                    142:                                        ,long deflt);
                    143: ushort         iniGetShortInt(str_list_t, const char* section, const char* key
                    144:                                        ,ushort deflt);
                    145: ulong          iniGetLongInt(str_list_t, const char* section, const char* key
                    146:                                        ,ulong deflt);
1.1.1.2 ! root      147: int64_t                iniGetBytes(str_list_t, const char* section, const char* key
        !           148:                                        ,ulong unit, int64_t deflt);
1.1       root      149: double         iniGetFloat(str_list_t, const char* section, const char* key
                    150:                                        ,double deflt);
                    151: BOOL           iniGetBool(str_list_t, const char* section, const char* key
                    152:                                        ,BOOL deflt);
                    153: time_t         iniGetDateTime(str_list_t, const char* section, const char* key
                    154:                                        ,time_t deflt);
                    155: unsigned       iniGetEnum(str_list_t, const char* section, const char* key
                    156:                                        ,str_list_t names, unsigned deflt);
1.1.1.2 ! root      157: unsigned*      iniGetEnumList(str_list_t, const char* section, const char* key
        !           158:                                        ,str_list_t names, unsigned* count, const char* sep, const char* deflt);
1.1       root      159: long           iniGetNamedInt(str_list_t, const char* section, const char* key
                    160:                                        ,named_long_t*, long deflt);
                    161: double         iniGetNamedFloat(str_list_t, const char* section, const char* key
                    162:                                        ,named_double_t*, double deflt);
                    163: ulong          iniGetBitField(str_list_t, const char* section, const char* key
                    164:                                        ,ini_bitdesc_t* bitdesc, ulong deflt);
1.1.1.2 ! root      165: str_list_t     iniGetSection(str_list_t, const char *section);
1.1       root      166: #define                iniGetLogLevel(l,s,k,d) iniGetEnum(l,s,k,iniLogLevelStringList(),d)
                    167: 
                    168: #if !defined(NO_SOCKET_SUPPORT)
                    169: ulong          iniReadIpAddress(FILE*, const char* section, const char* key
                    170:                                        ,ulong deflt);
                    171: ulong          iniGetIpAddress(str_list_t, const char* section, const char* key
                    172:                                        ,ulong deflt);
                    173: char*          iniSetIpAddress(str_list_t*, const char* section, const char* key, ulong value
                    174:                                        ,ini_style_t*);
                    175: int                    iniGetSocketOptions(str_list_t, const char* section
                    176:                                        ,SOCKET sock, char* error, size_t errlen);
                    177: #endif
                    178: 
                    179: void           iniSetDefaultStyle(ini_style_t);
                    180: 
                    181: char*          iniSetString(str_list_t*, const char* section, const char* key, const char* value
                    182:                                        ,ini_style_t*);
                    183: char*          iniSetInteger(str_list_t*, const char* section, const char* key, long value
                    184:                                        ,ini_style_t*);
                    185: char*          iniSetShortInt(str_list_t*, const char* section, const char* key, ushort value
                    186:                                        ,ini_style_t*);
                    187: char*          iniSetLongInt(str_list_t*, const char* section, const char* key, ulong value
                    188:                                        ,ini_style_t*);
1.1.1.2 ! root      189: char*          iniSetBytes(str_list_t*, const char* section, const char* key, ulong unit, int64_t value
1.1       root      190:                                        ,ini_style_t*);
                    191: char*          iniSetHexInt(str_list_t*, const char* section, const char* key, ulong value
                    192:                                        ,ini_style_t*);
                    193: char*          iniSetFloat(str_list_t*, const char* section, const char* key, double value
                    194:                                        ,ini_style_t*);
                    195: char*          iniSetBool(str_list_t*, const char* section, const char* key, BOOL value
                    196:                                        ,ini_style_t*);
                    197: char*          iniSetDateTime(str_list_t*, const char* section, const char* key, BOOL include_time, time_t
                    198:                                        ,ini_style_t*);
                    199: char*          iniSetEnum(str_list_t*, const char* section, const char* key, str_list_t names
                    200:                                        ,unsigned value, ini_style_t*);
1.1.1.2 ! root      201: char*          iniSetEnumList(str_list_t*, const char* section, const char* key 
        !           202:                                        ,const char* sep, str_list_t names, unsigned* values, unsigned count, ini_style_t*);
1.1       root      203: char*          iniSetNamedInt(str_list_t*, const char* section, const char* key, named_long_t*
                    204:                                        ,long value, ini_style_t*);
                    205: char*          iniSetNamedFloat(str_list_t*, const char* section, const char* key, named_double_t*
                    206:                                        ,double value, ini_style_t*);
                    207: char*          iniSetBitField(str_list_t*, const char* section, const char* key, ini_bitdesc_t*, ulong value
                    208:                                        ,ini_style_t*);
                    209: char*          iniSetStringList(str_list_t*, const char* section, const char* key
                    210:                                        ,const char* sep, str_list_t value, ini_style_t*);
                    211: #define                iniSetLogLevel(l,s,k,v,style) iniSetEnum(l,s,k,iniLogLevelStringList(),v,style)
                    212: 
                    213: size_t         iniAddSection(str_list_t*, const char* section
                    214:                                        ,ini_style_t*);
                    215: 
                    216: size_t         iniAppendSection(str_list_t*, const char* section
                    217:                                        ,ini_style_t*);
                    218: 
                    219: BOOL           iniSectionExists(str_list_t, const char* section);
                    220: BOOL           iniKeyExists(str_list_t, const char* section, const char* key);
                    221: BOOL           iniValueExists(str_list_t, const char* section, const char* key);
1.1.1.2 ! root      222: char*          iniPopKey(str_list_t*, const char* section, const char* key, char* value);
1.1       root      223: BOOL           iniRemoveKey(str_list_t*, const char* section, const char* key);
                    224: BOOL           iniRemoveValue(str_list_t*, const char* section, const char* key);
                    225: BOOL           iniRemoveSection(str_list_t*, const char* section);
                    226: BOOL           iniRenameSection(str_list_t*, const char* section, const char* newname);
                    227: 
1.1.1.2 ! root      228: /*
        !           229:  * Too handy to leave internal
        !           230:  */
        !           231: unsigned* parseEnumList(const char* values, const char* sep, str_list_t names, unsigned* count);
        !           232: 
1.1       root      233: #if defined(__cplusplus)
                    234: }
                    235: #endif
                    236: 
                    237: #endif /* Don't add anything after this line */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.