File: ini.h

package info (click to toggle)
unixodbc 2.2.11-16
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 17,332 kB
  • ctags: 12,399
  • sloc: ansic: 116,624; cpp: 29,333; sh: 25,024; makefile: 3,002; lex: 241; yacc: 182; perl: 142; sed: 16; sql: 1
file content (474 lines) | stat: -rw-r--r-- 13,739 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
/**********************************************************************************
 * ini.h
 *
 * Include file for libini.a. Coding? Include this and link against libini.a.
 *
 *
 **************************************************
 * This code was created by Peter Harvey @ CodeByDesign.
 * Released under LGPL 28.JAN.99
 *
 * Contributions from...
 * -----------------------------------------------
 * Peter Harvey		- pharvey@codebydesign.com
 **************************************************/

#ifndef INCLUDED_INI_H
#define INCLUDED_INI_H

/*********[ CONSTANTS AND TYPES ]**************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>

#ifndef TRUE
#define TRUE    1
#endif

#ifndef FALSE
#define FALSE   0
#endif

#define     STDINFILE               ((char*)-1)

#define     INI_NO_DATA             2
#define     INI_SUCCESS             1
#define     INI_ERROR               0

#define     INI_MAX_LINE            1000
#define     INI_MAX_OBJECT_NAME     INI_MAX_LINE
#define     INI_MAX_PROPERTY_NAME   INI_MAX_LINE
#define     INI_MAX_PROPERTY_VALUE  INI_MAX_LINE

#if HAVE_LIMITS_H
#include <limits.h>
#endif

#ifdef PATH_MAX
#define ODBC_FILENAME_MAX         PATH_MAX
#elif MAXPATHLEN
#define ODBC_FILENAME_MAX         MAXPATHLEN
#else
#define ODBC_FILENAME_MAX         FILENAME_MAX
#endif

/********************************************
 * tINIPROPERTY
 *
 * Each property line has Name=Value pair.
 * They are stored in this structure and linked together to provide a list
 * of all properties for a given Object.
 ********************************************/

typedef struct	tINIPROPERTY
{
	struct	tINIPROPERTY	*pNext;
	struct	tINIPROPERTY	*pPrev;

	char	szName[INI_MAX_PROPERTY_NAME+1];
	char	szValue[INI_MAX_PROPERTY_VALUE+1];

} INIPROPERTY, *HINIPROPERTY;

/********************************************
 * tINIOBJECT
 *
 * Each object line has just an object name. This structure
 * stores the object name and its subordinate information.
 * The lines that follow are considered to be properties
 * and are stored in a list of tINIPROPERTY.
 ********************************************/

typedef struct	tINIOBJECT
{
	struct	tINIOBJECT	*pNext;
	struct	tINIOBJECT	*pPrev;

	char	szName[INI_MAX_OBJECT_NAME+1];

    HINIPROPERTY		hFirstProperty;
    HINIPROPERTY		hLastProperty;
	int					nProperties;

} INIOBJECT, *HINIOBJECT;

/********************************************
 * tINI
 *
 * Each INI file contains a list of objects. This
 * structure stores each object in a list of tINIOBJECT.
 ********************************************/

typedef struct     tINI
{
#ifdef __OS2__
    int     iniFileType;			/*  ini file type 0 = text, 1 = binary (OS/2 only) */
#endif
    char    szFileName[ODBC_FILENAME_MAX+1];        /* FULL INI FILE NAME                                                           */
    char    cComment[ 5 ];                          /* COMMENT CHAR MUST BE IN FIRST COLUMN                                         */
    char    cLeftBracket;                           /* BRACKETS DELIMIT THE OBJECT NAME, THE LEFT BRACKET MUST BE IN COLUMN ONE     */
    char    cRightBracket;
    char    cEqual;                                 /* SEPERATES THE PROPERTY NAME FROM ITS VALUE                                   */
	int		bChanged;								/* IF true, THEN THE WHOLE FILE IS OVERWRITTEN UPON iniCommit					*/
	int		bReadOnly;								/* TRUE IF AT LEAST ONE CALL HAS BEEN MADE TO iniAppend() 						*/

	HINIOBJECT		hFirstObject;
	HINIOBJECT		hLastObject;
	HINIOBJECT		hCurObject;
	int				nObjects;

	HINIPROPERTY	hCurProperty;

} INI, *HINI;

/********************************************
 * tINIBOOKMARK
 *
 * Used to store the current Object and Property pointers so
 * that the caller can quickly return to some point in the
 * INI data.
 ********************************************/

typedef struct tINIBOOKMARK
{
	HINI			hIni;
	HINIOBJECT		hCurObject;
    HINIPROPERTY	hCurProperty;

} INIBOOKMARK, *HINIBOOKMARK;

#if defined(__cplusplus)
         extern  "C" {
#endif

/*********[ PRIMARY INTERFACE ]*****************************************************/

/******************************
 * iniOpen
 *
 * 1. make sure file exists
 * 2. allocate memory for HINI
 * 3. initialize HINI
 * 4. load entire file into structured memory
 * 5. set TRUE if you want to create file if non-existing
 ******************************/
#ifdef __OS2__
int iniOpen( HINI *hIni, char *pszFileName, char *cComment, char cLeftBracket, char cRightBracket, char cEqual, int bCreate, int bFileType  );
#else
int iniOpen( HINI *hIni, char *pszFileName, char *cComment, char cLeftBracket, char cRightBracket, char cEqual, int bCreate  );
#endif
/******************************
 * iniAppend
 *
 * 1. append Sections in pszFileName that do not already exist in hIni
 * 2. Makes hIni ReadOnly!
 ******************************/
int iniAppend( HINI hIni, char *pszFileName );

/******************************
 * iniDelete
 *
 * 1. simple removes all objects (and their properties) from the list using iniObjectDelete() in a loop
 ******************************/
int iniDelete( HINI hIni );

/******************************
 * iniClose
 *
 * 1. free memory previously allocated for HINI
 * 2. DO NOT SAVE ANY CHANGES (see iniCommit)
 ******************************/
int iniClose( HINI hIni );

/******************************
 * iniCommit
 *
 * 1. replaces file contents with memory contents (overwrites the file)
 ******************************/
int iniCommit( HINI hIni );

/******************************
 * iniObjectFirst
 *
 ******************************/
int iniObjectFirst( HINI hIni );

/******************************
 * iniObjectLast
 *
 ******************************/
int iniObjectLast( HINI hIni );

/******************************
 * iniObjectNext
 *
 * 1. iniObjects() if no current object name else
 * 2. find and store next object name
 ******************************/
int iniObjectNext( HINI hIni );

/******************************
 * iniObjectSeek
 *
 * 1. find and store object name
 ******************************/
int iniObjectSeek( HINI hIni, char *pszObject );

/******************************
 * iniObjectSeekSure
 *
 * 1. find and store object name
 * 2. ensure that it exists
 ******************************/
int iniObjectSeekSure( HINI hIni, char *pszObject );

/******************************
 * iniObjectEOL
 *
 ******************************/
int iniObjectEOL( HINI hIni );

/******************************
 * iniObject
 *
 * 1. returns the current object name
 ******************************/
int iniObject( HINI hIni, char *pszObject );

/******************************
 * iniObjectDelete
 *
 * 1. deletes current Object
 ******************************/
int iniObjectDelete( HINI hIni );

/******************************
 * iniObjectUpdate
 *
 * 1. update current Object
 ******************************/
int iniObjectUpdate( HINI hIni, char *pszObject );

/******************************
 * iniPropertyObject
 *
 * 1. inserts a new Object
 * 2. becomes current
 ******************************/
int iniObjectInsert( HINI hIni, char *pszObject );

/******************************
 * iniPropertyFirst
 *
 ******************************/
int iniPropertyFirst( HINI hIni );

/******************************
 * iniPropertyLast
 *
 ******************************/
int iniPropertyLast( HINI hIni );

/******************************
 * iniPropertyNext
 *
 * 1. iniProperties() if no current property name else
 * 2. find and store next property name
 ******************************/
int iniPropertyNext( HINI hIni );

/******************************
 * iniPropertySeek
 *
 * 1. set current Object & Property positions where matching parameters
 * 2. any parms which are empty strings (ie pszObject[0]) are ignored
 * 3. it is kinda pointless to pass empty strings for all parms... you will get 1st Property in 1st Object
 ******************************/
int iniPropertySeek( HINI hIni, char *pszObject, char *pszProperty, char *pszValue );

/******************************
 * iniPropertySeekSure
 *
 * 1. same as iniPropertySeek but
 * 2. will ensure that both Object and Property exist
 ******************************/
int iniPropertySeekSure( HINI hIni, char *pszObject, char *pszProperty, char *pszValue );

/******************************
 * iniPropertyEOL
 *
 ******************************/
int iniPropertyEOL( HINI hIni );

/******************************
 * iniProperty
 *
 * 1. returns the current property name
 ******************************/
int iniProperty( HINI hIni, char *pszProperty );

/******************************
 * iniPropertyDelete
 *
 * 1. deletes current Property
 ******************************/
int iniPropertyDelete( HINI hIni );

/******************************
 * iniPropertyUpdate
 *
 * 1. update current Property
 ******************************/
int iniPropertyUpdate( HINI hIni, char *pszProperty, char *pszValue );

/******************************
 * iniPropertyInsert
 *
 * 1. inserts a new Property for current Object
 * 2. becomes current
 ******************************/
int iniPropertyInsert( HINI hIni, char *pszProperty, char *pszValue );

/******************************
 * iniValue
 *
 * 1. returns the value for the current object/property
 ******************************/
int iniValue( HINI hIni, char *pszValue );

/******************************
 * iniGetBookmark
 *
 * 1. Store the current data positions (Object and Property)
 *    into hIniBookmark.
 * 2. Does not allocate memory for hIniBookmark so pass a
 *    pointer to a valid bookmark.
 ******************************/
int iniGetBookmark( HINI hIni, HINIBOOKMARK hIniBookmark );

/******************************
 * iniGotoBookmark
 *
 * 1. Sets the current Object and Property positions to
 *    those stored in IniBookmark.
 * 2. Does not account for the bookmark becoming
 *    invalid ie from the Object or Property being deleted.
 ******************************/
int iniGotoBookmark( INIBOOKMARK IniBookmark );

/******************************
 * iniCursor
 *
 * 1. Returns a copy of the hIni with a new
 *    set of position cursors (current Object and Property).
 * 2. Not safe to use when in the possibility of
 *    deleting data in another cursor on same data.
 * 3. Use when reading data only.
 * 4. Does not allocate memory so hIniCursor should be valid.
 * 5. All calls, other than those for movement, are
 *    global and will affect any other view of the data.
 ******************************/
int iniCursor( HINI hIni, HINI hIniCursor );

/*************************************************************************************/
/*********[ SUPPORT FUNCS ]***********************************************************/
/*************************************************************************************/

/******************************
 * iniElement
 *
 ******************************/
int iniElement( char *pszData, char cSeperator, char cTerminator, int nElement, char *pszElement, int nMaxElement );
int iniElementToEnd( char *pszData, char cSeperator, char cTerminator, int nElement, char *pszElement, int nMaxElement );
int iniElementEOL( char *pszData, char cSeperator, char cTerminator, int nElement, char *pszElement, int nMaxElement );

/******************************
 * iniElementCount
 *
 ******************************/
int iniElementCount( char *pszData, char cSeperator, char cTerminator );

/******************************
 * iniPropertyValue
 *
 * 1. returns the property value for pszProperty in pszValue
 * 2. pszString example;
 *		"PropertyName1=Value1;PropertyName2=Value2;..."
 * 3. cEqual is usually '='
 * 4. cPropertySep is usually ';'
 *
 * This function can be called without calling any other functions in this lib.
 ******************************/
int iniPropertyValue( char *pszString, char *pszProperty, char *pszValue, char cEqual, char cPropertySep );

/******************************
 * iniAllTrim
 *
 * 1. trims blanks, tabs and newlines from start and end of pszString
 *
 * This function can be called without calling any other functions in this lib.
 ******************************/
int iniAllTrim( char *pszString );

/******************************
 * iniToUpper
 *
 * 1. Converts all chars in pszString to upper case.
 *
 * This function can be called without calling any other functions in this lib.
 ******************************/
int iniToUpper( char *pszString );


/******************************
 * _iniObjectRead
 *
 ******************************/
int _iniObjectRead( HINI hIni, char *szLine, char *pszObjectName );

/******************************
 * _iniPropertyRead
 *
 ******************************/
int _iniPropertyRead( HINI hIni, char *szLine, char *pszPropertyName, char *pszPropertyValue );

/******************************
 * _iniDump
 *
 ******************************/
int _iniDump( HINI hIni, FILE *hStream );

/******************************
 * _iniScanUntilObject
 *
 ******************************/
int _iniScanUntilObject( HINI hIni, FILE *hFile, char *pszLine );
int _iniScanUntilNextObject( HINI hIni, FILE *hFile, char *pszLine );

/*
 * Some changes to avoid a 255 file handle limit, thanks MQJoe.
 * Make it conditional as it does have some performance impact esp with LARGE ini files (like what I have :-)
 */

#if defined( HAVE_VSNPRINTF ) && defined( USE_LL_FIO )

FILE *uo_fopen( const char *filename, const char *mode );
int uo_fclose( FILE *stream );
char *uo_fgets( char *szbuffer, int n, FILE *stream );
int uo_fprintf( FILE *stream, const char *fmt, ...);

#else

#define uo_fopen   fopen
#define uo_fclose  fclose
#define uo_fgets   fgets
#define uo_fprintf fprintf

#endif

#if defined(__cplusplus)
         }
#endif

#endif