|
|
1.1 ! root 1: /* ini_file.h */ ! 2: ! 3: /* Functions to parse ini files */ ! 4: ! 5: /* $Id: ini_file.h,v 1.27 2004/10/22 02:25:23 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 2004 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: ! 44: #define INI_MAX_VALUE_LEN 1024 /* Maximum value length, includes '\0' */ ! 45: #define ROOT_SECTION NULL ! 46: ! 47: typedef struct { ! 48: ulong bit; ! 49: const char* name; ! 50: } ini_bitdesc_t; ! 51: ! 52: typedef struct { ! 53: int key_len; ! 54: const char* key_prefix; ! 55: const char* section_separator; ! 56: const char* value_separator; ! 57: const char* bit_separator; ! 58: } ini_style_t; ! 59: ! 60: #if defined(__cplusplus) ! 61: extern "C" { ! 62: #endif ! 63: ! 64: /* Read all section names and return as an allocated string list */ ! 65: /* Optionally (if prefix!=NULL), returns a subset of section names */ ! 66: str_list_t iniReadSectionList(FILE*, const char* prefix); ! 67: /* Read all key names and return as an allocated string list */ ! 68: str_list_t iniReadKeyList(FILE*, const char* section); ! 69: /* Read all key and value pairs and return as a named string list */ ! 70: named_string_t** ! 71: iniReadNamedStringList (FILE*, const char* section); ! 72: ! 73: /* These functions read a single key of the specified type */ ! 74: char* iniReadString(FILE*, const char* section, const char* key ! 75: ,const char* deflt, char* value); ! 76: str_list_t iniReadStringList(FILE*, const char* section, const char* key ! 77: ,const char* sep, const char* deflt); ! 78: long iniReadInteger(FILE*, const char* section, const char* key ! 79: ,long deflt); ! 80: ushort iniReadShortInt(FILE*, const char* section, const char* key ! 81: ,ushort deflt); ! 82: ulong iniReadIpAddress(FILE*, const char* section, const char* key ! 83: ,ulong deflt); ! 84: double iniReadFloat(FILE*, const char* section, const char* key ! 85: ,double deflt); ! 86: BOOL iniReadBool(FILE*, const char* section, const char* key ! 87: ,BOOL deflt); ! 88: ulong iniReadBitField(FILE*, const char* section, const char* key ! 89: ,ini_bitdesc_t* bitdesc, ulong deflt); ! 90: ! 91: /* Free string list returned from iniRead*List functions */ ! 92: void* iniFreeStringList(str_list_t list); ! 93: ! 94: /* Free named string list returned from iniReadNamedStringList */ ! 95: void* iniFreeNamedStringList(named_string_t** list); ! 96: ! 97: ! 98: /* File I/O Functions */ ! 99: char* iniFileName(char* dest, size_t maxlen, const char* dir, const char* fname); ! 100: FILE* iniOpenFile(const char* fname); ! 101: str_list_t iniReadFile(FILE*); ! 102: BOOL iniWriteFile(FILE*, const str_list_t); ! 103: BOOL iniCloseFile(FILE*); ! 104: ! 105: /* StringList functions */ ! 106: str_list_t iniGetSectionList(str_list_t* list, const char* prefix); ! 107: str_list_t iniGetKeyList(str_list_t* list, const char* section); ! 108: named_string_t** ! 109: iniGetNamedStringList(str_list_t* list, const char* section); ! 110: ! 111: char* iniGetString(str_list_t*, const char* section, const char* key ! 112: ,const char* deflt, char* value); ! 113: str_list_t iniGetStringList(str_list_t*, const char* section, const char* key ! 114: ,const char* sep, const char* deflt); ! 115: long iniGetInteger(str_list_t*, const char* section, const char* key ! 116: ,long deflt); ! 117: ushort iniGetShortInt(str_list_t*, const char* section, const char* key ! 118: ,ushort deflt); ! 119: ulong iniGetIpAddress(str_list_t*, const char* section, const char* key ! 120: ,ulong deflt); ! 121: double iniGetFloat(str_list_t*, const char* section, const char* key ! 122: ,double deflt); ! 123: BOOL iniGetBool(str_list_t*, const char* section, const char* key ! 124: ,BOOL deflt); ! 125: ulong iniGetBitField(str_list_t*, const char* section, const char* key ! 126: ,ini_bitdesc_t* bitdesc, ulong deflt); ! 127: ! 128: ! 129: char* iniSetString(str_list_t*, const char* section, const char* key, const char* value ! 130: ,ini_style_t*); ! 131: char* iniSetInteger(str_list_t*, const char* section, const char* key, long value ! 132: ,ini_style_t*); ! 133: char* iniSetShortInt(str_list_t*, const char* section, const char* key, ushort value ! 134: ,ini_style_t*); ! 135: char* iniSetHexInt(str_list_t*, const char* section, const char* key, ulong value ! 136: ,ini_style_t*); ! 137: char* iniSetFloat(str_list_t*, const char* section, const char* key, double value ! 138: ,ini_style_t*); ! 139: char* iniSetIpAddress(str_list_t*, const char* section, const char* key, ulong value ! 140: ,ini_style_t*); ! 141: char* iniSetBool(str_list_t*, const char* section, const char* key, BOOL value ! 142: ,ini_style_t*); ! 143: char* iniSetBitField(str_list_t*, const char* section, const char* key, ini_bitdesc_t*, ulong value ! 144: ,ini_style_t*); ! 145: char* iniSetStringList(str_list_t*, const char* section, const char* key ! 146: ,const char* sep, str_list_t value, ini_style_t*); ! 147: ! 148: size_t iniAddSection(str_list_t*, const char* section ! 149: ,ini_style_t*); ! 150: ! 151: BOOL iniSectionExists(str_list_t*, const char* section); ! 152: BOOL iniKeyExists(str_list_t*, const char* section, const char* key); ! 153: BOOL iniValueExists(str_list_t*, const char* section, const char* key); ! 154: BOOL iniRemoveKey(str_list_t*, const char* section, const char* key); ! 155: BOOL iniRemoveValue(str_list_t*, const char* section, const char* key); ! 156: BOOL iniRemoveSection(str_list_t*, const char* section); ! 157: BOOL iniRenameSection(str_list_t*, const char* section, const char* newname); ! 158: ! 159: #if defined(__cplusplus) ! 160: } ! 161: #endif ! 162: ! 163: #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.