1 /*
2  * file ini_file.h - parsing ini-file into a database
3  *
4  * $Id: ini_file.h,v 1.17 2006/04/11 16:44:00 fzago Exp $
5  *
6  * Program XBLAST
7  * (C) by Oliver Vogel (e-mail: m.vogel@ndh.net)
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published
11  * by the Free Software Foundation; either version 2; or (at your option)
12  * any later version
13  *
14  * This program is distributed in the hope that it will be entertaining,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILTY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
17  * Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write to the Free Software Foundation, Inc.
21  * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23 #ifndef _INI_FILE_H
24 #define _INI_FILE_H
25 
26 /*
27  * type definitions
28  */
29 
30 /* struct for string to int conversions */
31 typedef struct
32 {
33 	const char *key;
34 	int value;
35 } DBToInt;
36 
37 /* struct for string to data conversions */
38 typedef struct
39 {
40 	const char *key;
41 	void *value;
42 } DBToData;
43 
44 /* type of database */
45 typedef enum
46 {
47 	DT_Config,
48 	DT_Level,
49 	DT_Demo,
50 	DT_Central,
51 	NUM_DT
52 } DBType;
53 
54 /* conversion results */
55 typedef enum
56 {
57 	DCR_Okay = 0,
58 	DCR_NoSuchEntry,
59 	DCR_Failure,
60 } DBConversionResult;
61 
62 /* declarations of db elements */
63 typedef struct _db_entry DBEntry;
64 typedef struct _db_section DBSection;
65 typedef struct _db_root DBRoot;
66 
67 /* callback for DB_LoadDir */
68 typedef void (*DBLoadDirFunc) (DBSection *);
69 
70 /*
71  * prototypes
72  */
73 
74 /* databases */
75 extern DBRoot *DB_Create (DBType type, XBAtom atom);
76 extern const DBRoot *DB_Get (DBType type, XBAtom atom);
77 extern XBBool DB_Changed (const DBRoot * db);
78 extern XBAtom DB_Atom (const DBRoot *);
79 extern void DB_SetAtom (DBRoot *, XBAtom);
80 extern void DB_Delete (DBRoot * db);
81 
82 /* sections */
83 extern DBSection *DB_CreateSection (DBRoot * db, XBAtom atom);
84 extern DBSection *DB_GetSection (const DBRoot * db, XBAtom atom);
85 extern XBAtom DB_SectionAtom (const DBSection * section);
86 extern int DB_NumSections (const DBRoot * db);
87 extern XBAtom DB_IndexSection (const DBRoot * db, int index);
88 extern void DB_DeleteAll (DBRoot * db);
89 extern void DB_DeleteSection (DBRoot * db, XBAtom atom);
90 
91 /* entries */
92 extern XBBool DB_CreateEntryString (DBSection * section, XBAtom atom, const char *value);
93 extern XBBool DB_CreateEntryAtom (DBSection * section, XBAtom atom, XBAtom value);
94 extern XBBool DB_CreateEntryInt (DBSection * section, XBAtom atom, int value);
95 extern XBBool DB_CreateEntryColor (DBSection * section, XBAtom atom, XBColor value);
96 extern XBBool DB_CreateEntryBool (DBSection * section, XBAtom atom, XBBool value);
97 extern XBBool DB_CreateEntryTime (DBSection * section, XBAtom atom, time_t value);
98 extern XBBool DB_CreateEntryFloat (DBSection * section, XBAtom atom, double value);
99 extern XBBool DB_CreateEntryGameResult (DBSection * section, XBAtom atom, int score);
100 extern XBBool DB_CreateEntryPlayerRating (DBSection * section, XBAtom atom, int PID, float rating);
101 extern XBBool DB_CreateEntryPos (DBSection * section, XBAtom atom, BMPosition * pValue);
102 extern XBBool DB_ParseEntry (DBSection * db, const char *line);
103 extern XBBool DB_CopyEntry (DBRoot * db, const DBSection * section, XBAtom atom);
104 
105 extern XBBool DB_GetEntryString (const DBSection * section, XBAtom atom, const char **pString);
106 extern XBBool DB_GetEntryAtom (const DBSection * section, XBAtom atom, XBAtom * pAtom);
107 extern XBBool DB_GetEntryInt (const DBSection * section, XBAtom atom, int *pValue);
108 extern XBBool DB_GetEntryColor (const DBSection * section, XBAtom atom, XBColor * pValue);
109 extern XBBool DB_GetEntryBool (const DBSection * section, XBAtom atom, XBBool * pValue);
110 extern XBBool DB_GetEntryTime (const DBSection * section, XBAtom atom, time_t * pValue);
111 extern XBBool DB_GetEntryFloat (const DBSection * section, XBAtom atom, double *pValue);
112 extern XBBool DB_GetEntryPos (const DBSection * section, XBAtom atom, BMPosition * pValue);
113 
114 extern DBConversionResult DB_ConvertEntryInt (const DBSection * section, XBAtom atom, int *pValue,
115 											  const DBToInt * convTable);
116 extern DBConversionResult DB_ConvertEntryData (const DBSection * section, XBAtom atom,
117 											   void **pValue, const DBToData * convTable);
118 extern DBConversionResult DB_ConvertEntryFlags (const DBSection * section, XBAtom atom,
119 												unsigned *pValue, const DBToInt * convTable);
120 
121 extern int DB_NumAllEntries (const DBRoot * db);
122 extern int DB_NumEntries (const DBSection * section);
123 extern XBAtom DB_IndexEntry (const DBSection * section, int index);
124 extern size_t DB_PrintEntry (char *buffer, const DBSection * section, int index);
125 extern char *DB_SectionEntryString (const DBSection * section, XBAtom atom);
126 extern void DB_DeleteEntry (DBSection * section, XBAtom atom);
127 
128 /* conversion */
129 extern const char *DB_IntToString (const DBToInt * table, int value);
130 extern const char *DB_DataToString (const DBToData * table, void *pValue);
131 
132 /* file operations */
133 extern XBBool DB_Store (DBRoot * db);
134 extern XBBool DB_Append (DBRoot * db);
135 extern XBBool DB_Load (DBRoot * db);
136 extern XBBool DB_Dump (const DBRoot * db);
137 extern XBBool DB_LoadDir (DBRoot * db, const char *path, const char *ext, DBType type, XBAtom mtime,
138 						  XBAtom section, DBLoadDirFunc func, XBBool rec);
139 extern int ReadMessageOfTheDay (int m, char *s, int *l);
140 
141 /* clear all data */
142 extern void DB_Finish (void);
143 
144 #endif
145 /*
146  * end of file ini_file.h
147  */
148