|
|
1.1 ! root 1: /* ini_file.h */ ! 2: ! 3: /* Functions to parse ini files */ ! 4: ! 5: /* $Id: ini_file.h,v 1.36 2005/10/15 21:47:12 rswindell Exp $ */ ! 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: * * ! 11: * Copyright 2005 Rob Swindell - http://www.synchro.net/copyright.html * ! 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); ! 82: str_list_t iniReadStringList(FILE*, const char* section, const char* key ! 83: ,const char* sep, const char* deflt); ! 84: long iniReadInteger(FILE*, const char* section, const char* key ! 85: ,long deflt); ! 86: ushort iniReadShortInt(FILE*, const char* section, const char* key ! 87: ,ushort deflt); ! 88: ulong iniReadLongInt(FILE*, const char* section, const char* key ! 89: ,ulong deflt); ! 90: ulong iniReadBytes(FILE*, const char* section, const char* key ! 91: ,ulong unit, ulong deflt); ! 92: double iniReadFloat(FILE*, const char* section, const char* key ! 93: ,double deflt); ! 94: BOOL iniReadBool(FILE*, const char* section, const char* key ! 95: ,BOOL deflt); ! 96: time_t iniReadDateTime(FILE*, const char* section, const char* key ! 97: ,time_t deflt); ! 98: unsigned iniReadEnum(FILE*, const char* section, const char* key ! 99: ,str_list_t names, unsigned deflt); ! 100: long iniReadNamedInt(FILE*, const char* section, const char* key ! 101: ,named_long_t*, long deflt); ! 102: double iniReadNamedFloat(FILE*, const char* section, const char* key ! 103: ,named_double_t*, double deflt); ! 104: ulong iniReadBitField(FILE*, const char* section, const char* key ! 105: ,ini_bitdesc_t* bitdesc, ulong deflt); ! 106: #define iniReadLogLevel(f,s,k,d) iniReadEnum(f,s,k,iniLogLevelStringList(),d) ! 107: ! 108: /* Free string list returned from iniRead*List functions */ ! 109: void* iniFreeStringList(str_list_t list); ! 110: ! 111: /* Free named string list returned from iniReadNamedStringList */ ! 112: void* iniFreeNamedStringList(named_string_t** list); ! 113: ! 114: ! 115: /* File I/O Functions */ ! 116: char* iniFileName(char* dest, size_t maxlen, const char* dir, const char* fname); ! 117: FILE* iniOpenFile(const char* fname, BOOL create); ! 118: str_list_t iniReadFile(FILE*); ! 119: BOOL iniWriteFile(FILE*, const str_list_t); ! 120: BOOL iniCloseFile(FILE*); ! 121: ! 122: /* StringList functions */ ! 123: str_list_t iniGetSectionList(str_list_t list, const char* prefix); ! 124: size_t iniGetSectionCount(str_list_t list, const char* prefix); ! 125: str_list_t iniGetKeyList(str_list_t list, const char* section); ! 126: named_string_t** ! 127: iniGetNamedStringList(str_list_t list, const char* section); ! 128: ! 129: char* iniGetString(str_list_t, const char* section, const char* key ! 130: ,const char* deflt, char* value); ! 131: str_list_t iniGetStringList(str_list_t, const char* section, const char* key ! 132: ,const char* sep, const char* deflt); ! 133: long iniGetInteger(str_list_t, const char* section, const char* key ! 134: ,long deflt); ! 135: ushort iniGetShortInt(str_list_t, const char* section, const char* key ! 136: ,ushort deflt); ! 137: ulong iniGetLongInt(str_list_t, const char* section, const char* key ! 138: ,ulong deflt); ! 139: ulong iniGetBytes(str_list_t, const char* section, const char* key ! 140: ,ulong unit, ulong deflt); ! 141: double iniGetFloat(str_list_t, const char* section, const char* key ! 142: ,double deflt); ! 143: BOOL iniGetBool(str_list_t, const char* section, const char* key ! 144: ,BOOL deflt); ! 145: time_t iniGetDateTime(str_list_t, const char* section, const char* key ! 146: ,time_t deflt); ! 147: unsigned iniGetEnum(str_list_t, const char* section, const char* key ! 148: ,str_list_t names, unsigned deflt); ! 149: long iniGetNamedInt(str_list_t, const char* section, const char* key ! 150: ,named_long_t*, long deflt); ! 151: double iniGetNamedFloat(str_list_t, const char* section, const char* key ! 152: ,named_double_t*, double deflt); ! 153: ulong iniGetBitField(str_list_t, const char* section, const char* key ! 154: ,ini_bitdesc_t* bitdesc, ulong deflt); ! 155: #define iniGetLogLevel(l,s,k,d) iniGetEnum(l,s,k,iniLogLevelStringList(),d) ! 156: ! 157: #if !defined(NO_SOCKET_SUPPORT) ! 158: ulong iniReadIpAddress(FILE*, const char* section, const char* key ! 159: ,ulong deflt); ! 160: ulong iniGetIpAddress(str_list_t, const char* section, const char* key ! 161: ,ulong deflt); ! 162: char* iniSetIpAddress(str_list_t*, const char* section, const char* key, ulong value ! 163: ,ini_style_t*); ! 164: int iniGetSocketOptions(str_list_t, const char* section ! 165: ,SOCKET sock, char* error, size_t errlen); ! 166: #endif ! 167: ! 168: void iniSetDefaultStyle(ini_style_t); ! 169: ! 170: char* iniSetString(str_list_t*, const char* section, const char* key, const char* value ! 171: ,ini_style_t*); ! 172: char* iniSetInteger(str_list_t*, const char* section, const char* key, long value ! 173: ,ini_style_t*); ! 174: char* iniSetShortInt(str_list_t*, const char* section, const char* key, ushort value ! 175: ,ini_style_t*); ! 176: char* iniSetLongInt(str_list_t*, const char* section, const char* key, ulong value ! 177: ,ini_style_t*); ! 178: char* iniSetBytes(str_list_t*, const char* section, const char* key, ulong unit, ulong value ! 179: ,ini_style_t*); ! 180: char* iniSetHexInt(str_list_t*, const char* section, const char* key, ulong value ! 181: ,ini_style_t*); ! 182: char* iniSetFloat(str_list_t*, const char* section, const char* key, double value ! 183: ,ini_style_t*); ! 184: char* iniSetBool(str_list_t*, const char* section, const char* key, BOOL value ! 185: ,ini_style_t*); ! 186: char* iniSetDateTime(str_list_t*, const char* section, const char* key, BOOL include_time, time_t ! 187: ,ini_style_t*); ! 188: char* iniSetEnum(str_list_t*, const char* section, const char* key, str_list_t names ! 189: ,unsigned value, ini_style_t*); ! 190: char* iniSetNamedInt(str_list_t*, const char* section, const char* key, named_long_t* ! 191: ,long value, ini_style_t*); ! 192: char* iniSetNamedFloat(str_list_t*, const char* section, const char* key, named_double_t* ! 193: ,double value, ini_style_t*); ! 194: char* iniSetBitField(str_list_t*, const char* section, const char* key, ini_bitdesc_t*, ulong value ! 195: ,ini_style_t*); ! 196: char* iniSetStringList(str_list_t*, const char* section, const char* key ! 197: ,const char* sep, str_list_t value, ini_style_t*); ! 198: #define iniSetLogLevel(l,s,k,v,style) iniSetEnum(l,s,k,iniLogLevelStringList(),v,style) ! 199: ! 200: size_t iniAddSection(str_list_t*, const char* section ! 201: ,ini_style_t*); ! 202: ! 203: size_t iniAppendSection(str_list_t*, const char* section ! 204: ,ini_style_t*); ! 205: ! 206: BOOL iniSectionExists(str_list_t, const char* section); ! 207: BOOL iniKeyExists(str_list_t, const char* section, const char* key); ! 208: BOOL iniValueExists(str_list_t, const char* section, const char* key); ! 209: BOOL iniRemoveKey(str_list_t*, const char* section, const char* key); ! 210: BOOL iniRemoveValue(str_list_t*, const char* section, const char* key); ! 211: BOOL iniRemoveSection(str_list_t*, const char* section); ! 212: BOOL iniRenameSection(str_list_t*, const char* section, const char* newname); ! 213: ! 214: #if defined(__cplusplus) ! 215: } ! 216: #endif ! 217: ! 218: #endif /* Don't add anything after this line */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.