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
|
-
|
|
!
|
#ifndef IG_INI_FILE_MODULE_AS
#define IG_INI_FILE_MODULE_AS
#module mod_ini
#uselib "kernel32.dll"
#func WritePrivateProfileString "WritePrivateProfileStringA" sptr,sptr,sptr,sptr
#func GetPrivateProfileString "GetPrivateProfileStringA" sptr,sptr,sptr,int,int,sptr
#cfunc GetPrivateProfileInt "GetPrivateProfileIntA" sptr,sptr,int,sptr
#define ctype double_to_str@mod_ini(%1) strf("\"%%.16e\"", %1)
#define null 0
#deffunc ini_setpath str _path
_ini_path = _path
sdim _strbuf, 512
return
#define global ini_put(%1, %2, %3) ini_put_impl %1, %2, str(%3)
#deffunc ini_put_impl str sec, str key, str value
WritePrivateProfileString sec, key, value, _ini_path
return
#define global ini_puts(%1, %2, %3) ini_put_impl %1, %2, "\"" + (%3) + "\""
#define global ini_putd(%1, %2, %3) ini_put_impl %1, %2, double_to_str@mod_ini(%3)
#define global ini_puti ini_put
#deffunc ini_getv_something_impl var dst, int pSec, int pKey, int pDef, int size_, local size
if ( vartype(dst) != 2 ) { sdim dst }
size = limit(size_, 64, 0xFFFF)
*LReTry:
memexpand dst, size
GetPrivateProfileString pSec, pKey, pDef, varptr(dst), size, _ini_path
if ( (stat == size - 1 || stat == size - 2) && size_ <= 0 ) {
size += size + 512 goto *LReTry
}
return
#define global ini_getsv(%1, %2, %3, %4 = "", %5 = 0) ini_getsv_ %1, %2, %3, %4, %5
#deffunc ini_getsv_ var dst, str sec_, str key_, str def_, int size_, local sec, local key, local def
sec = sec_
key = key_
def = def_
ini_getv_something_impl dst, varptr(sec), varptr(key), varptr(def), size_
return
#define global ctype ini_gets(%1, %2, %3 = "", %4 = 0) ini_gets_(%1, %2, %3, %4)
#defcfunc ini_gets_ str sec, str key, str def, int size_
ini_getsv _strbuf, sec, key, def, size_
return _strbuf
#define global ini_getdv(%1, %2, %3, %4 = 0) %1 = ini_getd(%2, %3, %4)
#define global ctype ini_getd(%1, %2, %3 = 0) ini_getd_(%1, %2, %3)
#defcfunc ini_getd_ str sec, str key, double def
ini_getsv _strbuf, sec, key, double_to_str@mod_ini(def), 32 return double(_strbuf)
#define global ini_getiv(%1, %2, %3, %4 = 0) %1 = ini_geti(%2, %3, %4)
#defcfunc ini_geti str sec, str key, int def
return GetPrivateProfileInt( sec, key, def, _ini_path )
#deffunc ini_enumSection array dst_arr, int bufsize
ini_getv_something_impl _strbuf, null, null, null, bufsize
sdim dst_arr, stat
SplitByNull dst_arr, _strbuf, stat
return
#deffunc ini_enumKey array dst_arr, str section_, int bufsize, local section
section = section_
ini_getv_something_impl _strbuf, varptr(section), null, null, bufsize
sdim dst_arr, stat
SplitByNull dst_arr, _strbuf, stat
return
#deffunc SplitByNull@mod_ini array dst, var buf, int maxsize, local idx
idx = 0
sdim dst
repeat
if ( idx >= maxsize ) { break } getstr dst(cnt), buf, idx, , maxsize
idx += strsize + 1
loop
return
#ifdef _DEBUG
#deffunc ini_dbglog local seclist, local sec, local keylist, local key, local stmp
logmes "\n(ini_dbglog): @" + _ini_path
ini_enumSection seclist
foreach seclist : sec = seclist(cnt)
logmes strf("[%s]", sec)
ini_enumKey keylist, sec foreach keylist : key = keylist(cnt)
ini_getsv stmp, sec, key, , 512
logmes ("\t" + key + " = \"" + stmp + "\"")
loop
loop
return
#else
#define global ini_dbglog :
#endif
#deffunc ini_removeSection str sec
WritePrivateProfileString sec, null, null, _ini_path
return
#deffunc ini_removeKey str sec, str key
WritePrivateProfileString sec, key, null, _ini_path
return
#defcfunc ini_exists str sec, str key
return ( ini_geti(sec, key, 0) == 0 && ini_geti(sec, key, 1) == 1 )
#global
#endif
|