ini_file.h 6.97 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
/* ini_file.h */

/* Functions to parse ini files */

/* $Id$ */

/****************************************************************************
 * @format.tab-size 4		(Plain Text/Source Code File Header)			*
 * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
 *																			*
11
 * Copyright 2005 Rob Swindell - http://www.synchro.net/copyright.html		*
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
 *																			*
 * This library is free software; you can redistribute it and/or			*
 * modify it under the terms of the GNU Lesser General Public License		*
 * as published by the Free Software Foundation; either version 2			*
 * of the License, or (at your option) any later version.					*
 * See the GNU Lesser General Public License for more details: lgpl.txt or	*
 * http://www.fsf.org/copyleft/lesser.html									*
 *																			*
 * Anonymous FTP access to the most recent released source is available at	*
 * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net	*
 *																			*
 * Anonymous CVS access to the development source and modification history	*
 * is available at cvs.synchro.net:/cvsroot/sbbs, example:					*
 * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login			*
 *     (just hit return, no password is necessary)							*
 * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src		*
 *																			*
 * For Synchronet coding style and modification guidelines, see				*
 * http://www.synchro.net/source.html										*
 *																			*
 * You are encouraged to submit any modifications (preferably in Unix diff	*
 * format) via e-mail to mods@synchro.net									*
 *																			*
 * Note: If this box doesn't appear square, then you need to fix your tabs.	*
 ****************************************************************************/

#ifndef _INI_FILE_H
#define _INI_FILE_H

#include "genwrap.h"
42
#include "str_list.h"	/* strList_t */
43

44
#define INI_MAX_VALUE_LEN	1024		/* Maximum value length, includes '\0' */
rswindell's avatar
rswindell committed
45
#define ROOT_SECTION		NULL
46

47
48
49
50
51
typedef struct {
	ulong		bit;
	const char*	name;
} ini_bitdesc_t;

52
53
54
typedef struct {
	int			key_len;
	const char* key_prefix;
55
	const char* section_separator;
56
57
58
59
	const char* value_separator;
	const char*	bit_separator;
} ini_style_t;

60
61
62
63
#if defined(__cplusplus)
extern "C" {
#endif

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
70
/* Read all key and value pairs and return as a named string list */
named_string_t**
71
			iniReadNamedStringList(FILE*, const char* section);
72
73

/* These functions read a single key of the specified type */
74
75
char*		iniReadString(FILE*, const char* section, const char* key
					,const char* deflt, char* value);
76
str_list_t	iniReadStringList(FILE*, const char* section, const char* key
77
78
79
80
81
82
83
84
85
86
87
					,const char* sep, const char* deflt);
long		iniReadInteger(FILE*, const char* section, const char* key
					,long deflt);
ushort		iniReadShortInt(FILE*, const char* section, const char* key
					,ushort deflt);
ulong		iniReadIpAddress(FILE*, const char* section, const char* key
					,ulong deflt);
double		iniReadFloat(FILE*, const char* section, const char* key
					,double deflt);
BOOL		iniReadBool(FILE*, const char* section, const char* key
					,BOOL deflt);
88
89
unsigned	iniReadEnum(FILE*, const char* section, const char* key
					,str_list_t names, unsigned deflt);
90
91
ulong		iniReadBitField(FILE*, const char* section, const char* key
					,ini_bitdesc_t* bitdesc, ulong deflt);
92

93
/* Free string list returned from iniRead*List functions */
94
void*		iniFreeStringList(str_list_t list);
95

96
/* Free named string list returned from iniReadNamedStringList */
97
98
void*		iniFreeNamedStringList(named_string_t** list);

rswindell's avatar
rswindell committed
99
100

/* File I/O Functions */
101
char*		iniFileName(char* dest, size_t maxlen, const char* dir, const char* fname);
102
FILE*		iniOpenFile(const char* fname, BOOL create);
103
104
str_list_t	iniReadFile(FILE*);
BOOL		iniWriteFile(FILE*, const str_list_t);
105
BOOL		iniCloseFile(FILE*);
rswindell's avatar
rswindell committed
106

107
/* StringList functions */
108
109
110
str_list_t	iniGetSectionList(str_list_t list, const char* prefix);
size_t		iniGetSectionCount(str_list_t list, const char* prefix);
str_list_t	iniGetKeyList(str_list_t list, const char* section);
111
named_string_t**
112
			iniGetNamedStringList(str_list_t list, const char* section);
113

114
char*		iniGetString(str_list_t, const char* section, const char* key
115
					,const char* deflt, char* value);
116
str_list_t	iniGetStringList(str_list_t, const char* section, const char* key
117
					,const char* sep, const char* deflt);
118
long		iniGetInteger(str_list_t, const char* section, const char* key
119
					,long deflt);
120
ushort		iniGetShortInt(str_list_t, const char* section, const char* key
121
					,ushort deflt);
122
ulong		iniGetIpAddress(str_list_t, const char* section, const char* key
123
					,ulong deflt);
124
double		iniGetFloat(str_list_t, const char* section, const char* key
125
					,double deflt);
126
BOOL		iniGetBool(str_list_t, const char* section, const char* key
127
					,BOOL deflt);
128
129
unsigned	iniGetEnum(str_list_t, const char* section, const char* key
					,str_list_t names, unsigned deflt);
130
ulong		iniGetBitField(str_list_t, const char* section, const char* key
131
132
133
					,ini_bitdesc_t* bitdesc, ulong deflt);


134
char*		iniSetString(str_list_t*, const char* section, const char* key, const char* value
135
					,ini_style_t*);
136
char*		iniSetInteger(str_list_t*, const char* section, const char* key, long value
137
					,ini_style_t*);
138
char*		iniSetShortInt(str_list_t*, const char* section, const char* key, ushort value
139
					,ini_style_t*);
140
char*		iniSetHexInt(str_list_t*, const char* section, const char* key, ulong value
141
					,ini_style_t*);
142
char*		iniSetFloat(str_list_t*, const char* section, const char* key, double value
143
					,ini_style_t*);
144
char*		iniSetIpAddress(str_list_t*, const char* section, const char* key, ulong value
145
					,ini_style_t*);
146
char*		iniSetBool(str_list_t*, const char* section, const char* key, BOOL value
147
					,ini_style_t*);
148
149
char*		iniSetEnum(str_list_t*, const char* section, const char* key, str_list_t names
					,unsigned value, ini_style_t*);
150
151
152
153
char*		iniSetBitField(str_list_t*, const char* section, const char* key, ini_bitdesc_t*, ulong value
					,ini_style_t*);
char*		iniSetStringList(str_list_t*, const char* section, const char* key
					,const char* sep, str_list_t value, ini_style_t*);
rswindell's avatar
rswindell committed
154

155
156
157
size_t		iniAddSection(str_list_t*, const char* section
					,ini_style_t*);

158
159
160
BOOL		iniSectionExists(str_list_t, const char* section);
BOOL		iniKeyExists(str_list_t, const char* section, const char* key);
BOOL		iniValueExists(str_list_t, const char* section, const char* key);
161
BOOL		iniRemoveKey(str_list_t*, const char* section, const char* key);
162
BOOL		iniRemoveValue(str_list_t*, const char* section, const char* key);
rswindell's avatar
rswindell committed
163
BOOL		iniRemoveSection(str_list_t*, const char* section);
rswindell's avatar
rswindell committed
164
BOOL		iniRenameSection(str_list_t*, const char* section, const char* newname);
165

166
167
168
169
170
#if defined(__cplusplus)
}
#endif

#endif	/* Don't add anything after this line */