ini_file.h 5.21 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 2004 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	iniGetSectionList		(FILE*, const char* prefix);
67
/* Read all key names and return as an allocated string list */
68
str_list_t	iniGetKeyList			(FILE*, const char* section);
69
70
/* Read all key and value pairs and return as a named string list */
named_string_t**
71
			iniGetNamedStringList	(FILE*, const char* section);
72
73

/* These functions read a single key of the specified type */
74
char*		iniGetString	(FILE*, const char* section, const char* key, 
75
							 const char* deflt, char* value);
76
str_list_t	iniGetStringList(FILE*, const char* section, const char* key
77
							,const char* sep, const char* deflt);
78
long		iniGetInteger	(FILE*, const char* section, const char* key, 
79
							 long deflt);
80
ushort		iniGetShortInt	(FILE*, const char* section, const char* key, 
81
							 ushort deflt);
82
ulong		iniGetIpAddress(FILE*, const char* section, const char* key, 
83
							 ulong deflt);
84
double		iniGetFloat	(FILE*, const char* section, const char* key, 
85
							 double deflt);
86
BOOL		iniGetBool		(FILE*, const char* section, const char* key, 
87
							 BOOL deflt);
88
ulong		iniGetBitField	(FILE*, const char* section, const char* key, 
89
							 ini_bitdesc_t* bitdesc, ulong deflt);
90

91
/* Free string list returned from iniGet*List functions */
92
void*		iniFreeStringList(str_list_t list);
93

94
/* Free named string list returned from iniGetNamedStringList */
95
96
void*		iniFreeNamedStringList(named_string_t** list);

rswindell's avatar
rswindell committed
97
98

/* File I/O Functions */
99
100
str_list_t	iniReadFile(FILE*);
BOOL		iniWriteFile(FILE*, const str_list_t);
rswindell's avatar
rswindell committed
101

102
/* StringList functions */
103
104
size_t		iniAddSection(str_list_t*, const char* section
					,ini_style_t*);
105
char*		iniSetString(str_list_t*, const char* section, const char* key, const char* value
106
					,ini_style_t*);
107
char*		iniSetInteger(str_list_t*, const char* section, const char* key, long value
108
					,ini_style_t*);
109
char*		iniSetShortInt(str_list_t*, const char* section, const char* key, ushort value
110
					,ini_style_t*);
111
char*		iniSetHexInt(str_list_t*, const char* section, const char* key, ulong value
112
					,ini_style_t*);
113
char*		iniSetFloat(str_list_t*, const char* section, const char* key, double value
114
					,ini_style_t*);
115
char*		iniSetIpAddress(str_list_t*, const char* section, const char* key, ulong value
116
					,ini_style_t*);
117
char*		iniSetBool(str_list_t*, const char* section, const char* key, BOOL value
118
					,ini_style_t*);
119
120
121
122
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
123

124
125
126
127
BOOL		iniKeyExists(str_list_t*, const char* section, const char* key);
BOOL		iniValueExists(str_list_t*, const char* section, const char* key);
BOOL		iniRemoveKey(str_list_t*, const char* section, const char* key);

128
129
130
131
132
#if defined(__cplusplus)
}
#endif

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