summaryrefslogtreecommitdiff
path: root/ini.h
blob: 9ac4f0ef159536c13ccecb7a8f99e2e207296de5 (plain)
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
/*

    viDOOM - level editor for DOOM

    Copyright (C) 2000  Ian Cowburn (ianc@noddybox.demon.co.uk)

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

    -------------------------------------------------------------------------

    Routines and common keys used to read an INI file
    Format of INI file:

	    [key]
	    value_key=value

    $Id$

*/

#ifndef _INI_H

#define _INI_H


/* Types for table filling queries
*/
#define INI_INT		0
#define INI_STR		1
#define INI_TOK		2
#define INI_DOUBLE	3


/* Defines the possible values and the corresponding string token for the
   value.
*/
typedef struct
	{
	char		*token;
	int		val;
	} TokenTable;

/* .data is treated as (int *) for INI_INT and INI_TOK.  It is treated as
   (char *) for INI_TOK and (double *) INI_DOUBLE.  Tokens can be NULL for
   non-INI_TOK types.
*/
typedef struct
	{
	int		type;
	char		*key;
	char		*valkey;
	void		*data;
	TokenTable	*tokens;
	} INI_Table;


/* General yes/no token definitions
*/
extern TokenTable       ini_yesno[];

/* Macro for calculating table size
*/
#define INI_TAB_SIZE(x)	(sizeof(x)/sizeof(INI_Table))


/* Note all returns are static
*/
int	INI_ReadInt(char *key,char *value_key);
char 	*INI_ReadStr(char *key,char *value_key);
int 	INI_ReadToken(char *key,char *value_key,TokenTable tokens[]);
double 	INI_ReadDouble(char *key,char *value_key);

void	INI_SaveInt(char *key,char *value_key,int val);
void 	INI_SaveStr(char *key,char *value_key,char *val);
void 	INI_SaveToken(char *key,char *value_key,int val,TokenTable tokens[]);
void 	INI_SaveDouble(char *key,char *value_key,double val);

void	INI_DeleteKey(char *key,char *value_key);

void	INI_Load(char *name);
void	INI_Save(void);

void	INI_GetTable(INI_Table table[],int no);
void	INI_PutTable(INI_Table table[],int no);

/* This automatically takes iyase_dir from [config] and dir from [key]{iyase}
   and adds on the passed filename.  Note that return is static.
*/
char	*INI_FileName(char *key,char *fname);

#endif


/* END OF FILE */