1 /*	inifile.h
2 	Copyright (C) 2007-2019 Dmitry Groshev
3 
4 	This file is part of mtPaint.
5 
6 	mtPaint is free software; you can redistribute it and/or modify
7 	it under the terms of the GNU General Public License as published by
8 	the Free Software Foundation; either version 3 of the License, or
9 	(at your option) any later version.
10 
11 	mtPaint is distributed in the hope that it will be useful,
12 	but WITHOUT ANY WARRANTY; without even the implied warranty of
13 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 	GNU General Public License for more details.
15 
16 	You should have received a copy of the GNU General Public License
17 	along with mtPaint in the file COPYING.
18 */
19 
20 typedef struct {
21 	char *key, *value, *defv;
22 	int sec, chain;
23 	short type, flags;
24 } inislot;
25 
26 typedef struct {
27 	char *sblocks;
28 	inislot *slots;
29 	gint32 *hash;
30 	int count, slen, maxloop;
31 	guint32 hmask, seed[2];
32 } inifile;
33 
34 /* Access macros */
35 
36 #define INI_KEY(P,N)  ((P)->slots[(N)].key)
37 #define INI_VALUE(P,N)  ((P)->slots[(N)].value)
38 #define INI_PARENT(P,N) ((P)->slots[(N)].sec)
39 
40 /* Iterator macros */
41 
42 #define INI_FIRST(P,N) ((int)(P)->slots[(N)].defv)
43 #define INI_NEXT(P,N) ((P)->slots[(N)].chain)
44 
45 /* Core functions */
46 
47 int new_ini(inifile *inip);
48 void forget_ini(inifile *inip);
49 int read_ini(inifile *inip, char *fname, int itype);
50 int write_ini(inifile *inip, char *fname, char *header);
51 
52 int ini_setstr(inifile *inip, int section, char *key, char *value);
53 int ini_setint(inifile *inip, int section, char *key, int value);
54 int ini_setbool(inifile *inip, int section, char *key, int value);
55 int ini_setref(inifile *inip, int section, char *key, int value);
56 
57 char *ini_getstr(inifile *inip, int section, char *key, char *defv);
58 int ini_getint(inifile *inip, int section, char *key, int defv);
59 int ini_getbool(inifile *inip, int section, char *key, int defv);
60 int ini_getref(inifile *inip, int section, char *key, int defv);
61 
62 int ini_setsection(inifile *inip, int section, char *key);
63 int ini_getsection(inifile *inip, int section, char *key);
64 
65 int ini_transient(inifile *inip, int section, char *key);
66 
67 /* File functions */
68 
69 char *slurp_file_l(char *fname, int before, int *len);
70 #define slurp_file(A,B) slurp_file_l((A), (B), NULL)
71 char *get_home_directory(void);
72 char *extend_path(const char *path);
73 
74 /* Helper functions */
75 
76 int str2bool(const char *s);
77 
78 /* Compatibility functions */
79 
80 inifile main_ini;
81 
82 void inifile_init(char *system_ini, char *user_ini);
83 void inifile_quit();
84 
85 char *inifile_get(char *setting, char *defaultValue);
86 int inifile_get_gint32(char *setting, int defaultValue);
87 int inifile_get_gboolean(char *setting, int defaultValue);
88 
89 int inifile_set(char *setting, char *value);
90 int inifile_set_gint32(char *setting, int value);
91 int inifile_set_gboolean(char *setting, int value);
92