1
|
/*! \file scol_glib_keyfile.c
|
2
|
* \brief all functions of this API
|
3
|
* \author Stephane Bisaro
|
4
|
*/
|
5
|
/*
|
6
|
This source file is part of Scol
|
7
|
For the latest info, see http://www.scolring.org
|
8
|
|
9
|
Copyright (c) 2010 Stephane Bisaro, aka Iri <iri@irizone.net>
|
10
|
|
11
|
This program is free software; you can redistribute it and/or modify it under
|
12
|
the terms of the GNU Lesser General Public License as published by the Free Software
|
13
|
Foundation; either version 2 of the License, or (at your option) any later
|
14
|
version.
|
15
|
|
16
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
17
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
18
|
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
19
|
|
20
|
You should have received a copy of the GNU Lesser General Public License along with
|
21
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
22
|
Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
23
|
http://www.gnu.org/copyleft/lesser.txt
|
24
|
|
25
|
For others informations, please contact us from http://www.scolring.org/
|
26
|
*/
|
27
|
|
28
|
#include "../include/scol_glib_keyfile.h"
|
29
|
|
30
|
#if ((defined _WIN32) || (defined __WIN32__))
|
31
|
cbmachine ww;
|
32
|
#endif
|
33
|
mmachine mm;
|
34
|
|
35
|
|
36
|
/**
|
37
|
* \brief GKF_VALUE_RAW : I : flag used to load a key file. The raw value associated with key under group.
|
38
|
* The value can be escaped string
|
39
|
*/
|
40
|
int GKF_VALUE_RAW (mmachine m) { return MMpush (m, ITOM (1)); }
|
41
|
/**
|
42
|
* \brief GKF_VALUE_STRING : I : flag used to load a key file. The string value associated with key under group.
|
43
|
* Unlike GKF_VALUE_RAW, any escaped sequence are unescaped
|
44
|
*/
|
45
|
int GKF_VALUE_STRING (mmachine m) { return MMpush (m, ITOM (2)); }
|
46
|
/**
|
47
|
* \brief GKF_VALUE_INTEGER : Not implemented yet
|
48
|
*/
|
49
|
int GKF_VALUE_INTEGER (mmachine m) { return MMpush (m, ITOM (3)); }
|
50
|
/**
|
51
|
* \brief GKF_VALUE_INTEGER64 : Not implemented yet
|
52
|
*/
|
53
|
int GKF_VALUE_INTEGER64 (mmachine m) { return MMpush (m, ITOM (4)); }
|
54
|
/**
|
55
|
* \brief GKF_VALUE_UINTEGER64 : Not implemented yet
|
56
|
*/
|
57
|
int GKF_VALUE_UINTEGER64 (mmachine m) { return MMpush (m, ITOM (5)); }
|
58
|
/**
|
59
|
* \brief GKF_VALUE_DOUBLE : Not implemented yet
|
60
|
*/
|
61
|
int GKF_VALUE_DOUBLE (mmachine m) { return MMpush (m, ITOM (6)); }
|
62
|
/**
|
63
|
* \brief GKF_VALUE_BOOLEAN : Not implemented yet
|
64
|
*/
|
65
|
int GKF_VALUE_BOOLEAN (mmachine m) { return MMpush (m, ITOM (7)); }
|
66
|
|
67
|
|
68
|
/**
|
69
|
* \brief _gkeyFileReadP : read a key file
|
70
|
* fun [P S] [[S [[S S] r1]] r1]
|
71
|
*
|
72
|
* \param P : any file (read reference only)
|
73
|
* \param S : the list seperator, or nil (default ";")
|
74
|
* \return [[S [[S S] r1]] r1] : the list of datas = group names and for each group name, a list of tuple [key value]
|
75
|
*/
|
76
|
int SCOL_gkeyFileReadP (mmachine m)
|
77
|
{
|
78
|
int mfile, msep;
|
79
|
gboolean b;
|
80
|
GKeyFile *ini;
|
81
|
GError *err = NULL;
|
82
|
|
83
|
msep = MTOP (MMpull (m));
|
84
|
mfile = MMpull (m);
|
85
|
if (mfile == NIL)
|
86
|
{
|
87
|
MMpush (m, NIL);
|
88
|
return 0;
|
89
|
}
|
90
|
|
91
|
ini = g_key_file_new ();
|
92
|
if (msep != NIL)
|
93
|
g_key_file_set_list_separator (ini, (MMstart (m, msep))[0]);
|
94
|
b = g_key_file_load_from_file (ini, MMstartstr (m, MTOP (mfile)), G_KEY_FILE_NONE, &err);
|
95
|
if (!b)
|
96
|
{
|
97
|
MMechostr (0, "SCOL_gkeyFileReadP load error : %d .:. %s\n", err->code, err->message);
|
98
|
g_error_free (err);
|
99
|
MMpush (m, NIL);
|
100
|
return 0;
|
101
|
}
|
102
|
g_key_file_free (ini);
|
103
|
return scol_g_key_file_read (ini, m);
|
104
|
}
|
105
|
|
106
|
|
107
|
|
108
|
|
109
|
|
110
|
|
111
|
|
112
|
|
113
|
/* ========================================================================= */
|
114
|
|
115
|
|
116
|
/** \private
|
117
|
* internal function : get groups names
|
118
|
*/
|
119
|
int scol_g_key_file_get_groups (mmachine m, int flag)
|
120
|
{
|
121
|
int mini;
|
122
|
int i = 0;
|
123
|
gsize len = 0;
|
124
|
GKeyFile *ini;
|
125
|
gchar **groups;
|
126
|
|
127
|
mini = MMpull (m);
|
128
|
if (mini == NIL)
|
129
|
{
|
130
|
MMechostr (0, "scol_g_key_file_get_groups error : object is nil\n");
|
131
|
MMpush (m, NIL);
|
132
|
return 0;
|
133
|
}
|
134
|
|
135
|
ini = (GKeyFile*) MMfetch (m, MTOP (mini), OBJGKEYFILE_HANDLE);
|
136
|
groups = g_key_file_get_groups (ini, &len);
|
137
|
if (flag)
|
138
|
MMpush (m, ITOM ((int) len)); /* I */
|
139
|
else
|
140
|
{
|
141
|
for (i = 0; i < (int) len; i++)
|
142
|
Mpushstrbloc (m, groups[i]);
|
143
|
MMpush (m, NIL);
|
144
|
for (i = 0; i < (int) len; i++)
|
145
|
{
|
146
|
MMpush (m, ITOM (2));
|
147
|
MBdeftab (m);
|
148
|
} /* [S r1] */
|
149
|
}
|
150
|
g_strfreev (groups);
|
151
|
return 0;
|
152
|
}
|
153
|
/** \private
|
154
|
* internal function : return a list of the entire content ( [[S [[S S] r1]] r1] )
|
155
|
*/
|
156
|
int scol_g_key_file_read (GKeyFile *ini, mmachine m)
|
157
|
{
|
158
|
int i, j;
|
159
|
gsize ngroups, nkeys;
|
160
|
gchar **groups;
|
161
|
|
162
|
groups = g_key_file_get_groups (ini, &ngroups);
|
163
|
for (i = 0; i < (int) ngroups; i++)
|
164
|
{
|
165
|
gchar **keys;
|
166
|
|
167
|
Mpushstrbloc (m, groups[i]); /* S */
|
168
|
|
169
|
keys = g_key_file_get_keys (ini, groups[i], &nkeys, NULL);
|
170
|
for (j = 0; j < (int) nkeys; j++)
|
171
|
{
|
172
|
gchar *value;
|
173
|
|
174
|
value = g_key_file_get_value (ini, groups[i], keys[j], NULL);
|
175
|
Mpushstrbloc (m, keys[j]);
|
176
|
Mpushstrbloc (m, value);
|
177
|
MMpush (m, ITOM (2));
|
178
|
MBdeftab (m); /* [S S] */
|
179
|
g_free (value);
|
180
|
}
|
181
|
g_strfreev (keys);
|
182
|
MMpush (m, NIL);
|
183
|
for (j = 0; j < (int) nkeys; j++)
|
184
|
{
|
185
|
MMpush (m, ITOM (2));
|
186
|
MBdeftab (m);
|
187
|
} /* [[S S] r1] */
|
188
|
MMpush (m, ITOM (2));
|
189
|
MBdeftab (m); /* [S [[S S] r1]] */
|
190
|
}
|
191
|
g_strfreev (groups);
|
192
|
MMpush (m, NIL);
|
193
|
for (i = 0; i < (int) ngroups; i++)
|
194
|
{
|
195
|
MMpush (m, ITOM (2));
|
196
|
MBdeftab (m);
|
197
|
} /* [[S [[S S] r1]] r1] */
|
198
|
return 0;
|
199
|
}
|
200
|
|
201
|
/** \private
|
202
|
* internal function : load a file or data
|
203
|
*/
|
204
|
int scol_g_key_file_load (mmachine m, int typ)
|
205
|
{
|
206
|
int mchannel, mfile, msep, mflag;
|
207
|
int initab;
|
208
|
gboolean b;
|
209
|
GKeyFileFlags flag = G_KEY_FILE_NONE;
|
210
|
GKeyFile *ini;
|
211
|
GError *err = NULL;
|
212
|
|
213
|
mflag = MTOI (MMpull (m));
|
214
|
msep = MTOP (MMpull (m));
|
215
|
mfile = MMpull (m);
|
216
|
mchannel = MMget (m, 0);
|
217
|
|
218
|
if (mchannel == NIL)
|
219
|
{
|
220
|
MMechostr (0, "scol_g_key_file_load error : channel is nil\n");
|
221
|
MMpush (m, NIL);
|
222
|
return 0;
|
223
|
}
|
224
|
if (mfile == NIL)
|
225
|
{
|
226
|
MMechostr (0, "scol_g_key_file_load error : file is nil\n");
|
227
|
MMpush (m, NIL);
|
228
|
return 0;
|
229
|
}
|
230
|
|
231
|
ini = g_key_file_new ();
|
232
|
if (msep != NIL)
|
233
|
g_key_file_set_list_separator (ini, (MMstart (m, msep))[0]);
|
234
|
|
235
|
if (mflag == 1)
|
236
|
flag = G_KEY_FILE_KEEP_COMMENTS;
|
237
|
else if (mflag == 2)
|
238
|
flag = G_KEY_FILE_KEEP_TRANSLATIONS;
|
239
|
else if (mflag == 3)
|
240
|
flag = G_KEY_FILE_KEEP_TRANSLATIONS|G_KEY_FILE_KEEP_COMMENTS;
|
241
|
|
242
|
if (typ)
|
243
|
b = g_key_file_load_from_data (ini, MMstartstr (m, MTOP (mfile)), MMsizestr (m, MTOP (mfile)), flag, &err);
|
244
|
else
|
245
|
b = g_key_file_load_from_file (ini, MMstartstr (m, MTOP (mfile)), flag, &err);
|
246
|
if ((!b) || (err != NULL))
|
247
|
{
|
248
|
MMechostr (0, "scol_g_key_file_load error : loading is failed -> %s\n", err->message);
|
249
|
g_error_free (err);
|
250
|
MMpush (m, NIL);
|
251
|
return 0;
|
252
|
}
|
253
|
|
254
|
initab = MMmalloc (m, sizeof (ini) + 1, TYPETAB);
|
255
|
if (initab == NIL)
|
256
|
{
|
257
|
MMechostr (0, "scol_g_key_file_load error : not enough memory\n");
|
258
|
MMpull (m);
|
259
|
MMpush (m, NIL);
|
260
|
g_key_file_free (ini);
|
261
|
return 0;
|
262
|
}
|
263
|
MMstore (m, initab, OBJGKEYFILE_HANDLE, (int) ini);
|
264
|
MMpush (m, PTOM (initab));
|
265
|
OBJcreate (m, ObjKeyFile, (int) ini, -1, -1);
|
266
|
return 0;
|
267
|
}
|
268
|
|
269
|
/**
|
270
|
* \brief _gkeyFileLoadP : Loads a key file from any valid file
|
271
|
*
|
272
|
* fun [Chn P S I] ObjKeyFile
|
273
|
*
|
274
|
* \param Chn : the channel
|
275
|
* \param P : any read referenced file
|
276
|
* \param S : the list separator or nil (default ";"). One character only (if more, they are ignored)
|
277
|
* \param I : flag :
|
278
|
* 0 -> No flags, default behaviour
|
279
|
* 1 -> Use this flag if you plan to write the (possibly modified) contents of the key file back to a file;
|
280
|
* otherwise all comments will be lost when the key file is written back.
|
281
|
* 2 -> Use this flag if you plan to write the (possibly modified) contents of the key file back to a file;
|
282
|
* otherwise only the translations for the current language will be written back.
|
283
|
* 3 -> 1 and 2
|
284
|
* \return ObjKeyFile : the new object, or nil if error
|
285
|
*
|
286
|
* Importante note : if you want get/set any localized key, be sure set the flag to 2 (or 3) !
|
287
|
*/
|
288
|
int SCOL_gkeyFileLoadP (mmachine m)
|
289
|
{
|
290
|
return scol_g_key_file_load (m, 0);
|
291
|
}
|
292
|
|
293
|
/**
|
294
|
* \brief _gkeyFileLoadS : Loads a key file from any valid data
|
295
|
*
|
296
|
* fun [Chn P S I] ObjKeyFile
|
297
|
*
|
298
|
* \param Chn : the channel
|
299
|
* \param S : any valid content
|
300
|
* \param S : the list separator or nil (default ";"). One character only (if more, they are ignored)
|
301
|
* \param I : flag :
|
302
|
* 0 -> No flags, default behaviour
|
303
|
* 1 -> Use this flag if you plan to write the (possibly modified) contents of the key file back to a file;
|
304
|
* otherwise all comments will be lost when the key file is written back.
|
305
|
* 2 -> Use this flag if you plan to write the (possibly modified) contents of the key file back to a file;
|
306
|
* otherwise only the translations for the current language will be written back.
|
307
|
* 3 -> 1 and 2
|
308
|
* \return ObjKeyFile : the new object, or nil if error
|
309
|
*/
|
310
|
int SCOL_gkeyFileLoadS (mmachine m)
|
311
|
{
|
312
|
return scol_g_key_file_load (m, 1);
|
313
|
}
|
314
|
|
315
|
|
316
|
/**
|
317
|
* \brief _gkeyFileSave : save a keyfile to a filename
|
318
|
*
|
319
|
* fun [ObjKeyFile W] I
|
320
|
*
|
321
|
* \param ObjKeyFile : a valid object
|
322
|
* \param W : a Scol write referenced filename
|
323
|
* \return I : 0 if success or nil if error (see log message)
|
324
|
*/
|
325
|
int SCOL_gkeyFileSave (mmachine m)
|
326
|
{
|
327
|
int mini, mwfile;
|
328
|
gboolean b;
|
329
|
GKeyFile *ini;
|
330
|
gchar *content, *wfile;
|
331
|
gsize len = 0;
|
332
|
GError *err = NULL;
|
333
|
|
334
|
mwfile = MMpull (m);
|
335
|
mini = MMpull (m);
|
336
|
|
337
|
if ((mini == NIL) || (mwfile == NIL))
|
338
|
{
|
339
|
MMechostr (0, "SCOL_gkeyFileSave error : bad(s) argument(s) !\n");
|
340
|
MMpush (m, NIL);
|
341
|
return 0;
|
342
|
}
|
343
|
|
344
|
ini = (GKeyFile*) MMfetch (m, MTOP (mini), OBJGKEYFILE_HANDLE);
|
345
|
wfile = MMstartstr (m, MTOP (mwfile));
|
346
|
content = g_key_file_to_data (ini, &len, &err);
|
347
|
if ((content == NULL) || (err != NULL))
|
348
|
{
|
349
|
MMechostr (0, "SCOL_gkeyFileSave error : %d -> %s !\n", err->code, err->message);
|
350
|
g_error_free (err);
|
351
|
MMpush (m, NIL);
|
352
|
return 0;
|
353
|
}
|
354
|
b = g_file_set_contents (wfile, content, len, &err);
|
355
|
if ((!b) || (err != NULL))
|
356
|
{
|
357
|
MMechostr (0, "SCOL_gkeyFileSave error : %d -> %s !\n", err->code, err->message);
|
358
|
g_error_free (err);
|
359
|
MMpush (m, NIL);
|
360
|
return 0;
|
361
|
}
|
362
|
g_free (content);
|
363
|
MMpush (m, ITOM (0));
|
364
|
return 0;
|
365
|
}
|
366
|
|
367
|
/**
|
368
|
*\brief _gkeyFileDestroy : Destroys an object
|
369
|
*
|
370
|
* \param ObjKeyFile
|
371
|
* \return I : O or nil if error
|
372
|
*/
|
373
|
int SCOL_gkeyFileDestroy (mmachine m)
|
374
|
{
|
375
|
int mini;
|
376
|
GKeyFile *ini;
|
377
|
|
378
|
mini = MMpull (m);
|
379
|
if (mini == NIL)
|
380
|
{
|
381
|
MMechostr (0, "SCOL_gkeyFileDestroy error : object is nil\n");
|
382
|
MMpush (m, NIL);
|
383
|
return 0;
|
384
|
}
|
385
|
|
386
|
ini = (GKeyFile*) MMfetch (m, MTOP (mini), OBJGKEYFILE_HANDLE);
|
387
|
g_key_file_free (ini);
|
388
|
OBJdelTM (m, ObjKeyFile, mini);
|
389
|
MMpush (m, 0);
|
390
|
|
391
|
return 0;
|
392
|
}
|
393
|
|
394
|
/**
|
395
|
* \brief _gkeyFileGetContent : Returns the content of key file
|
396
|
*
|
397
|
* fun [ObjKeyFile] [S I]
|
398
|
*
|
399
|
* \param ObjKeyFile : any valid object
|
400
|
* \return [S I] : a tuple : the content and its length or nil if error
|
401
|
*/
|
402
|
int SCOL_gkeyFileGetContent (mmachine m)
|
403
|
{
|
404
|
int mini;
|
405
|
gchar *content;
|
406
|
gsize len = 0;
|
407
|
GKeyFile *ini;
|
408
|
|
409
|
mini = MMpull (m);
|
410
|
if (mini == NIL)
|
411
|
{
|
412
|
MMechostr (0, "SCOL_gkeyFileGetContent error : object is nil\n");
|
413
|
MMpush (m, NIL);
|
414
|
return 0;
|
415
|
}
|
416
|
|
417
|
ini = (GKeyFile*) MMfetch (m, MTOP (mini), OBJGKEYFILE_HANDLE);
|
418
|
content = g_key_file_to_data (ini, &len, NULL);
|
419
|
Mpushstrbloc (m, content);
|
420
|
MMpush (m, ITOM ((int) len));
|
421
|
MMpush (m, ITOM (2));
|
422
|
MBdeftab (m);
|
423
|
g_free (content);
|
424
|
return 0;
|
425
|
}
|
426
|
|
427
|
/**
|
428
|
* \brief _gkeyFileGetDatas : Return a list of the content
|
429
|
*
|
430
|
* fun [ObjKeyFile] [[S [[S S] r1]] r1]
|
431
|
*
|
432
|
* \param ObjKeyFile : an object already created
|
433
|
* \return [[S [[S S] r1]] r1] : a list of group names and for each group name, a list of tuple [key value] or nil if error
|
434
|
*/
|
435
|
int SCOL_gkeyFileGetDatas (mmachine m)
|
436
|
{
|
437
|
int mini;
|
438
|
GKeyFile *ini;
|
439
|
|
440
|
mini = MMpull (m);
|
441
|
if (mini == NIL)
|
442
|
{
|
443
|
MMechostr (0, "SCOL_gkeyFileGetDatas error : object is nil\n");
|
444
|
MMpush (m, NIL);
|
445
|
return 0;
|
446
|
}
|
447
|
|
448
|
ini = (GKeyFile*) MMfetch (m, MTOP (mini), OBJGKEYFILE_HANDLE);
|
449
|
return scol_g_key_file_read (ini, m);
|
450
|
}
|
451
|
|
452
|
/**
|
453
|
* \brief _gkeyFileGetGroups : Returns a list of all groups
|
454
|
*
|
455
|
* fun [ObjKeyFile] [S r1]
|
456
|
*
|
457
|
* \param ObjKeyFile : any object already created
|
458
|
* \return [S r1] : this list or nil if error
|
459
|
*/
|
460
|
int SCOL_gkeyFileGetGroups (mmachine m)
|
461
|
{
|
462
|
return scol_g_key_file_get_groups (m, 0);
|
463
|
}
|
464
|
|
465
|
/**
|
466
|
* \brief _gkeyFileGetNbGroups : Returns the number of group
|
467
|
*
|
468
|
* fun [ObjKeyFile] I
|
469
|
*
|
470
|
* \param ObjKeyFile : any object already created
|
471
|
* \return I : this number or nil if error
|
472
|
*/
|
473
|
int SCOL_gkeyFileGetNbGroups (mmachine m)
|
474
|
{
|
475
|
return scol_g_key_file_get_groups (m, 1);
|
476
|
}
|
477
|
|
478
|
/**
|
479
|
* \brief _gkeyFileDataExist : Looks whether the key file has the datas
|
480
|
*
|
481
|
* fun [ObjKeyFile S S] I
|
482
|
*
|
483
|
* \param ObjKeyFile : any object already created
|
484
|
* \param S : a group name or nil
|
485
|
* \param S : a key name or nil
|
486
|
* \return I : the result (see below) or nil if error
|
487
|
*
|
488
|
* If the group name and the key name are not nil, this function searches the key into the group.
|
489
|
* If found, 1 is returned, else 0
|
490
|
* If the group name is nil, this function searches the key into all groups.
|
491
|
* The returned value is the number of this key, 0 if not found.
|
492
|
* If the key name is nil, this function searches the group into the keyfile.
|
493
|
* If found, 1 is returned, else 0.
|
494
|
* If the keyfile is nil or if the group and key names are nil, nil is returned.
|
495
|
*/
|
496
|
int SCOL_gkeyFileDataExist (mmachine m)
|
497
|
{
|
498
|
int mini, mgroup, mkey;
|
499
|
GKeyFile *ini;
|
500
|
gboolean b;
|
501
|
|
502
|
mkey = MMpull (m);
|
503
|
mgroup = MMpull (m);
|
504
|
mini = MMpull (m);
|
505
|
|
506
|
if (mini == NIL)
|
507
|
{
|
508
|
MMechostr (0, "SCOL_gkeyFileDataExist error : object is nil\n");
|
509
|
MMpush (m, NIL);
|
510
|
return 0;
|
511
|
}
|
512
|
|
513
|
if ((mkey == NIL) && (mgroup == NIL))
|
514
|
{
|
515
|
MMechostr (0, "SCOL_gkeyFileDataExist error : group and key are nil\n");
|
516
|
MMpush (m, NIL);
|
517
|
return 0;
|
518
|
}
|
519
|
|
520
|
ini = (GKeyFile*) MMfetch (m, MTOP (mini), OBJGKEYFILE_HANDLE);
|
521
|
|
522
|
if (mkey == NIL) /* search a group only */
|
523
|
{
|
524
|
b = g_key_file_has_group (ini, MMstartstr (m, MTOP (mgroup)));
|
525
|
MMpush (m, ITOM (b));
|
526
|
return 0;
|
527
|
}
|
528
|
|
529
|
if (mgroup == NIL) /* search a key in all groups */
|
530
|
{
|
531
|
gchar ** groups;
|
532
|
gsize len = 0;
|
533
|
int i, r = 0;
|
534
|
|
535
|
groups = g_key_file_get_groups (ini, &len);
|
536
|
for (i = 0; i < len; i++)
|
537
|
{
|
538
|
if (g_key_file_has_key (ini, groups[i], MMstartstr (m, MTOP (mkey)), NULL))
|
539
|
r++;
|
540
|
}
|
541
|
MMpush (m, ITOM (r));
|
542
|
g_strfreev (groups);
|
543
|
return 0;
|
544
|
}
|
545
|
|
546
|
/* search a key in a group */
|
547
|
b = g_key_file_has_key (ini, MMstartstr (m, MTOP (mgroup)), MMstartstr (m, MTOP (mkey)), NULL);
|
548
|
MMpush (m, ITOM (b));
|
549
|
return 0;
|
550
|
}
|
551
|
|
552
|
/**
|
553
|
* \brief _keyFileGetValue : Returns the value for any key in any group
|
554
|
*
|
555
|
* fun [ObjKeyFile S S I] S
|
556
|
*
|
557
|
* \param ObjKeyFile : any valid object
|
558
|
* \param S : any group name
|
559
|
* \param S : any key name
|
560
|
* \param I : flag : GKF_VALUE_RAW, GKF_VALUE_STRING, GKF_VALUE_INTEGER, GKF_VALUE_INTEGER64, GKF_VALUE_UINTEGER64, GKF_VALUE_DOUBLE, GKF_VALUE_BOOLEAN
|
561
|
* GKF_VALUE_RAW and GKF_VALUE_STRING have a difference, others always return a string
|
562
|
* \return S : the value or nil if error or not found
|
563
|
*/
|
564
|
int SCOL_keyFileGetValue (mmachine m)
|
565
|
{
|
566
|
int mini, mgroup, mkey, mflag;
|
567
|
GKeyFile *ini;
|
568
|
gchar *value, *group, *key;
|
569
|
GError *err = NULL;
|
570
|
|
571
|
mflag = MTOI (MMpull (m));
|
572
|
mkey = MMpull (m);
|
573
|
mgroup = MMpull (m);
|
574
|
mini = MMpull (m);
|
575
|
|
576
|
if ((mini == NIL) || (mkey == NIL) || (mgroup == NIL))
|
577
|
{
|
578
|
MMechostr (0, "SCOL_keyFileGetValue error : bad(s) argument(s) !\n");
|
579
|
MMpush (m, NIL);
|
580
|
return 0;
|
581
|
}
|
582
|
|
583
|
ini = (GKeyFile*) MMfetch (m, MTOP (mini), OBJGKEYFILE_HANDLE);
|
584
|
group = MMstartstr (m, MTOP (mgroup));
|
585
|
key = MMstartstr (m, MTOP (mkey));
|
586
|
|
587
|
switch (mflag)
|
588
|
{
|
589
|
case (2) :
|
590
|
value = g_key_file_get_string (ini, group, key, &err);
|
591
|
break;
|
592
|
|
593
|
case (3) :
|
594
|
{
|
595
|
int v;
|
596
|
|
597
|
v = g_key_file_get_integer (ini, group, key, &err);
|
598
|
value = g_malloc (sizeof (gchar) * 64);
|
599
|
snprintf (value, 64, "%d", v);
|
600
|
break;
|
601
|
}
|
602
|
#ifndef GLIB_224
|
603
|
case (4) :
|
604
|
{
|
605
|
gint64 v;
|
606
|
|
607
|
v = g_key_file_get_int64 (ini, group, key, &err);
|
608
|
value = g_malloc (sizeof (gchar) * 64);
|
609
|
snprintf (value, 64, "%" G_GINT64_MODIFIER "x", v);
|
610
|
break;
|
611
|
}
|
612
|
|
613
|
case (5) :
|
614
|
{
|
615
|
guint64 v;
|
616
|
|
617
|
v = g_key_file_get_uint64 (ini, group, key, &err);
|
618
|
value = g_malloc (sizeof (gchar) * 64);
|
619
|
snprintf (value, 64, "%" G_GUINT64_FORMAT "x", v);
|
620
|
break;
|
621
|
}
|
622
|
#endif
|
623
|
case (6) :
|
624
|
{
|
625
|
double v;
|
626
|
|
627
|
v = g_key_file_get_double (ini, group, key, &err);
|
628
|
value = g_malloc (sizeof (gchar) * 64);
|
629
|
snprintf (value, 64, "%f", v);
|
630
|
break;
|
631
|
}
|
632
|
|
633
|
case (7) :
|
634
|
{
|
635
|
gboolean v;
|
636
|
|
637
|
v = g_key_file_get_boolean (ini, group, key, &err);
|
638
|
value = g_malloc (sizeof (gchar) * 64);
|
639
|
snprintf (value, 64, "%d", v);
|
640
|
break;
|
641
|
}
|
642
|
|
643
|
default :
|
644
|
value = g_key_file_get_value (ini, group, key, &err);
|
645
|
|
646
|
}
|
647
|
if ((value == NULL) || (err != NULL))
|
648
|
{
|
649
|
MMechostr (0, "SCOL_keyFileGetValue error : %d -> %s !\n", err->code, err->message);
|
650
|
g_error_free (err);
|
651
|
MMpush (m, NIL);
|
652
|
}
|
653
|
else
|
654
|
{
|
655
|
Mpushstrbloc (m, value);
|
656
|
g_free (value);
|
657
|
}
|
658
|
return 0;
|
659
|
}
|
660
|
|
661
|
/**
|
662
|
* \brief _keyFileGetLocaleValue : Returns the locale value for any key in any group
|
663
|
*
|
664
|
* fun [ObjKeyFile S S S] S
|
665
|
*
|
666
|
* \param ObjKeyFile : any valid object
|
667
|
* \param S : any group name
|
668
|
* \param S : any key name
|
669
|
* \param S : any locale identifier or nil
|
670
|
* \return S : the value or nil if error or not found
|
671
|
*
|
672
|
* If locale is nil or not found, the value of the default key (without localization) will be returned
|
673
|
* When the ObjKeyFile has been created, if the flag is at 0 or 1, the current locale can be used only.
|
674
|
* In this last case, to get a value of an other locale, the flag should have set to 2 or 3.
|
675
|
*/
|
676
|
int SCOL_keyFileGetLocaleValue (mmachine m)
|
677
|
{
|
678
|
int mini, mgroup, mkey, mlang;
|
679
|
GKeyFile *ini;
|
680
|
gchar *value, *group, *key, *lang = NULL;
|
681
|
GError *err = NULL;
|
682
|
|
683
|
mlang = MMpull (m);
|
684
|
mkey = MMpull (m);
|
685
|
mgroup = MMpull (m);
|
686
|
mini = MMpull (m);
|
687
|
|
688
|
if ((mini == NIL) || (mkey == NIL) || (mgroup == NIL))
|
689
|
{
|
690
|
MMechostr (0, "SCOL_keyFileGetLocaleValue error : bad(s) argument(s) !\n");
|
691
|
MMpush (m, NIL);
|
692
|
return 0;
|
693
|
}
|
694
|
|
695
|
ini = (GKeyFile*) MMfetch (m, MTOP (mini), OBJGKEYFILE_HANDLE);
|
696
|
group = MMstartstr (m, MTOP (mgroup));
|
697
|
key = MMstartstr (m, MTOP (mkey));
|
698
|
if (mlang != NIL)
|
699
|
lang = MMstartstr (m, MTOP (mlang));
|
700
|
|
701
|
value = g_key_file_get_locale_string (ini, group, key, lang, &err);
|
702
|
if ((value == NULL) || (err != NULL))
|
703
|
{
|
704
|
MMechostr (0, "SCOL_keyFileGetLocaleValue error : %d -> %s !\n", err->code, err->message);
|
705
|
g_error_free (err);
|
706
|
MMpush (m, NIL);
|
707
|
}
|
708
|
|
709
|
Mpushstrbloc (m, value);
|
710
|
g_free (value);
|
711
|
return 0;
|
712
|
}
|
713
|
|
714
|
/**
|
715
|
* \brief _gkeyFileGetValueList : Returns the values associated with key under group
|
716
|
*
|
717
|
* fun [ObjKeyFile S S] [S r1]
|
718
|
*
|
719
|
* \param ObjKeyFile : any valid object
|
720
|
* \param S : any group name
|
721
|
* \param S : any key name
|
722
|
* \return [S r1] : the value or nil if error or not found
|
723
|
*/
|
724
|
int SCOL_gkeyFileGetValueList (mmachine m)
|
725
|
{
|
726
|
int mini, mgroup, mkey;
|
727
|
int i;
|
728
|
GKeyFile *ini;
|
729
|
gchar *group, *key;
|
730
|
gchar **list;
|
731
|
gsize len = 0;
|
732
|
GError *err = NULL;
|
733
|
|
734
|
mkey = MMpull (m);
|
735
|
mgroup = MMpull (m);
|
736
|
mini = MMpull (m);
|
737
|
|
738
|
if ((mini == NIL) || (mkey == NIL) || (mgroup == NIL))
|
739
|
{
|
740
|
MMechostr (0, "SCOL_gkeyFileGetValueList error : bad(s) argument(s) !\n");
|
741
|
MMpush (m, NIL);
|
742
|
return 0;
|
743
|
}
|
744
|
|
745
|
ini = (GKeyFile*) MMfetch (m, MTOP (mini), OBJGKEYFILE_HANDLE);
|
746
|
group = MMstartstr (m, MTOP (mgroup));
|
747
|
key = MMstartstr (m, MTOP (mkey));
|
748
|
|
749
|
list = g_key_file_get_string_list (ini, group, key, &len, &err);
|
750
|
if ((list == NULL) || (err != NULL))
|
751
|
{
|
752
|
MMechostr (0, "SCOL_gkeyFileGetValueList error : %d -> %s !\n", err->code, err->message);
|
753
|
g_error_free (err);
|
754
|
MMpush (m, NIL);
|
755
|
}
|
756
|
|
757
|
for (i = 0; i < (int) len; i++)
|
758
|
Mpushstrbloc (m, list[i]);
|
759
|
MMpush (m, NIL);
|
760
|
for (i = 0; i < (int) len; i++)
|
761
|
{
|
762
|
MMpush (m, ITOM (2));
|
763
|
MBdeftab (m);
|
764
|
}
|
765
|
g_strfreev (list);
|
766
|
return 0;
|
767
|
}
|
768
|
|
769
|
/**
|
770
|
* \brief _gkeyFileGetValueLocaleList : Returns the locales values associated with key under group
|
771
|
*
|
772
|
* fun [ObjKeyFile S S S] [S r1]
|
773
|
*
|
774
|
* \param ObjKeyFile : any valid object
|
775
|
* \param S : any group name
|
776
|
* \param S : any key name
|
777
|
* \param S : any locale identifier or nil
|
778
|
* \return [S r1] : the value or nil if error or not found
|
779
|
*
|
780
|
* If locale is nil or not found, the values of the default key (without localization) will be returned
|
781
|
* When the ObjKeyFile has been created, if the flag is at 0 or 1, the current locale can be used only.
|
782
|
* In this last case, to get the values of an other locale, the flag should have set to 2 or 3.
|
783
|
*/
|
784
|
int SCOL_gkeyFileGetValueLocaleList (mmachine m)
|
785
|
{
|
786
|
int mini, mgroup, mkey, mlang;
|
787
|
int i;
|
788
|
GKeyFile *ini;
|
789
|
gchar *group, *key, *lang = NULL;
|
790
|
gchar **list;
|
791
|
gsize len = 0;
|
792
|
GError *err = NULL;
|
793
|
|
794
|
mlang = MMpull (m);
|
795
|
mkey = MMpull (m);
|
796
|
mgroup = MMpull (m);
|
797
|
mini = MMpull (m);
|
798
|
|
799
|
if ((mini == NIL) || (mkey == NIL) || (mgroup == NIL))
|
800
|
{
|
801
|
MMechostr (0, "SCOL_gkeyFileGetValueLocaleList error : bad(s) argument(s) !\n");
|
802
|
MMpush (m, NIL);
|
803
|
return 0;
|
804
|
}
|
805
|
|
806
|
ini = (GKeyFile*) MMfetch (m, MTOP (mini), OBJGKEYFILE_HANDLE);
|
807
|
group = MMstartstr (m, MTOP (mgroup));
|
808
|
key = MMstartstr (m, MTOP (mkey));
|
809
|
if (mlang != NIL)
|
810
|
lang = MMstartstr (m, MTOP (mlang));
|
811
|
|
812
|
list = g_key_file_get_locale_string_list (ini, group, key, lang, &len, &err);
|
813
|
if ((list == NULL) || (err != NULL))
|
814
|
{
|
815
|
MMechostr (0, "SCOL_gkeyFileGetValueLocaleList error : %d -> %s !\n", err->code, err->message);
|
816
|
g_error_free (err);
|
817
|
MMpush (m, NIL);
|
818
|
}
|
819
|
|
820
|
for (i = 0; i < (int) len; i++)
|
821
|
Mpushstrbloc (m, list[i]);
|
822
|
MMpush (m, NIL);
|
823
|
for (i = 0; i < (int) len; i++)
|
824
|
{
|
825
|
MMpush (m, ITOM (2));
|
826
|
MBdeftab (m);
|
827
|
}
|
828
|
g_strfreev (list);
|
829
|
return 0;
|
830
|
}
|
831
|
|
832
|
/**
|
833
|
* \brief _gkeyFileGetComment : Return a comment
|
834
|
*
|
835
|
* fun [ObjKeyFile S S] S
|
836
|
*
|
837
|
* \param ObjKeyFile : an object
|
838
|
* \param S : a group name
|
839
|
* \param S : a key name
|
840
|
* \return S : the comment or nil if error or not found
|
841
|
*
|
842
|
* Retrieves a comment above key name from group name. If key is NULL then comment will be read from above group name.
|
843
|
* If both key name and group name are NULL, then comment will be read from above the first group in the file.
|
844
|
*/
|
845
|
int SCOL_gkeyFileGetComment (mmachine m)
|
846
|
{
|
847
|
int mini, mgroup, mkey;
|
848
|
GKeyFile *ini;
|
849
|
gchar *group = NULL, *key = NULL, *comment;
|
850
|
GError *err = NULL;
|
851
|
|
852
|
mkey = MMpull (m);
|
853
|
mgroup = MMpull (m);
|
854
|
mini = MMpull (m);
|
855
|
|
856
|
if (mini == NIL)
|
857
|
{
|
858
|
MMechostr (0, "SCOL_gkeyFileGetComment error : bad(s) argument(s) !\n");
|
859
|
MMpush (m, NIL);
|
860
|
return 0;
|
861
|
}
|
862
|
|
863
|
ini = (GKeyFile*) MMfetch (m, MTOP (mini), OBJGKEYFILE_HANDLE);
|
864
|
if (mgroup != NIL)
|
865
|
group = MMstartstr (m, MTOP (mgroup));
|
866
|
if (mkey != NIL)
|
867
|
key = MMstartstr (m, MTOP (mkey));
|
868
|
|
869
|
comment = g_key_file_get_comment (ini, group, key, &err);
|
870
|
if (err != NULL)
|
871
|
{
|
872
|
MMechostr (0, "SCOL_gkeyFileGetComment error : %d -> %s !\n", err->code, err->message);
|
873
|
g_error_free (err);
|
874
|
MMpush (m, NIL);
|
875
|
}
|
876
|
Mpushstrbloc (m, comment);
|
877
|
g_free (comment);
|
878
|
return 0;
|
879
|
}
|
880
|
|
881
|
/**
|
882
|
* \brief _gkeyFileSetValue : Associates a new value with key under group.
|
883
|
*
|
884
|
* Fun [ObjKeyFile S S S I] ObjKeyFile
|
885
|
* If key cannot be found then it is created. If group cannot be found then it is created.
|
886
|
*
|
887
|
* \param ObjKeyFile : a valid object
|
888
|
* \param S : a group name
|
889
|
* \param S : a key name
|
890
|
* \param S : the new value
|
891
|
* \param I : a flag = GKF_VALUE_RAW or GKF_VALUE_STRING (others flags aren't implemented yet)
|
892
|
* \return ObjKeyFile : the same object or nil if error
|
893
|
*
|
894
|
* If key or group is nil, the command is ignored but a message is written to the log
|
895
|
*/
|
896
|
int SCOL_gkeyFileSetValue (mmachine m)
|
897
|
{
|
898
|
int mini, mgroup, mkey, mvalue, mflag;
|
899
|
GKeyFile *ini;
|
900
|
gchar *group = NULL, *key = NULL, *value = NULL;
|
901
|
|
902
|
mflag = MTOI (MMpull (m));
|
903
|
mvalue = MMpull (m);
|
904
|
mkey = MMpull (m);
|
905
|
mgroup = MMpull (m);
|
906
|
mini = MMpull (m);
|
907
|
|
908
|
if ((mini == NIL) || (mvalue == NIL))
|
909
|
{
|
910
|
MMechostr (0, "SCOL_gkeyFileSetValue error : bad(s) argument(s) !\n");
|
911
|
MMpush (m, NIL);
|
912
|
return 0;
|
913
|
}
|
914
|
|
915
|
ini = (GKeyFile*) MMfetch (m, MTOP (mini), OBJGKEYFILE_HANDLE);
|
916
|
if (mgroup != NIL)
|
917
|
group = MMstartstr (m, MTOP (mgroup));
|
918
|
if (mkey != NIL)
|
919
|
key = MMstartstr (m, MTOP (mkey));
|
920
|
if (mvalue != NIL)
|
921
|
value = MMstartstr (m, MTOP (mvalue));
|
922
|
|
923
|
switch (mflag)
|
924
|
{
|
925
|
case (2) :
|
926
|
g_key_file_set_string (ini, group, key, SCOLUTF8 (value, -1));
|
927
|
break;
|
928
|
|
929
|
default :
|
930
|
g_key_file_set_value (ini, group, key, value);
|
931
|
}
|
932
|
MMpush (m, mini);
|
933
|
return 0;
|
934
|
}
|
935
|
/**
|
936
|
* \brief _gkeyFileSetLocaleValue : Associates a new value with key under group.
|
937
|
*
|
938
|
* Fun [ObjKeyFile S S S I] ObjKeyFile
|
939
|
* If key cannot be found then it is created. If group cannot be found then it is created.
|
940
|
*
|
941
|
* \param ObjKeyFile : a valid object
|
942
|
* \param S : a group name
|
943
|
* \param S : a key name
|
944
|
* \param S : the new value
|
945
|
* \param S : a locale identifier
|
946
|
* \return ObjKeyFile : the same object or nil if error
|
947
|
*
|
948
|
* If key or group is nil, the command is ignored but a message is written to the log
|
949
|
*/
|
950
|
int SCOL_gkeyFileSetLocaleValue (mmachine m)
|
951
|
{
|
952
|
int mini, mgroup, mkey, mvalue, mlocale;
|
953
|
GKeyFile *ini;
|
954
|
gchar *group = NULL, *key = NULL, *value = NULL, *locale = NULL;
|
955
|
|
956
|
mlocale = MMpull (m);
|
957
|
mvalue = MMpull (m);
|
958
|
mkey = MMpull (m);
|
959
|
mgroup = MMpull (m);
|
960
|
mini = MMpull (m);
|
961
|
|
962
|
if ((mini == NIL) || (mvalue == NIL))
|
963
|
{
|
964
|
MMechostr (0, "SCOL_gkeyFileSetLocaleValue error : bad(s) argument(s) !\n");
|
965
|
MMpush (m, NIL);
|
966
|
return 0;
|
967
|
}
|
968
|
|
969
|
ini = (GKeyFile*) MMfetch (m, MTOP (mini), OBJGKEYFILE_HANDLE);
|
970
|
if (mgroup != NIL)
|
971
|
group = MMstartstr (m, MTOP (mgroup));
|
972
|
if (mkey != NIL)
|
973
|
key = MMstartstr (m, MTOP (mkey));
|
974
|
if (mvalue != NIL)
|
975
|
value = SCOLUTF8 (MMstartstr (m, MTOP (mvalue)), -1);
|
976
|
if (mlocale != NIL)
|
977
|
locale = MMstartstr (m, MTOP (mlocale));
|
978
|
|
979
|
g_key_file_set_locale_string (ini, group, key, locale, value);
|
980
|
g_free (value);
|
981
|
MMpush (m, mini);
|
982
|
return 0;
|
983
|
}
|
984
|
|
985
|
/**
|
986
|
* \brief _gkeyFileSetValueList : Associates a list of string for key under group.
|
987
|
*
|
988
|
* fun [ObjKeyFile S S [S r1] ObjKeyFile
|
989
|
* If key cannot be found then it is created. If group cannot be found then it is created.
|
990
|
*
|
991
|
* \param ObjKeyFile : an object
|
992
|
* \param S : a group
|
993
|
* \param S : a key
|
994
|
* \param [S r1] : a list of values
|
995
|
* \return ObjKeyFile : the same object or nil if error
|
996
|
*
|
997
|
* If key or group is nil, the command is ignored but a message is written to the log
|
998
|
*/
|
999
|
int SCOL_gkeyFileSetValueList (mmachine m)
|
1000
|
{
|
1001
|
int mini, mgroup, mkey, mvalues, mtmp;
|
1002
|
int i = 0, size = 0;
|
1003
|
GKeyFile *ini;
|
1004
|
gchar *group = NULL, *key = NULL;
|
1005
|
gchar ** values = NULL;
|
1006
|
|
1007
|
mtmp = MMget (m, 0); /* blurps */
|
1008
|
mvalues = MMpull (m);
|
1009
|
mkey = MMpull (m);
|
1010
|
mgroup = MMpull (m);
|
1011
|
mini = MMpull (m);
|
1012
|
|
1013
|
if ((mini == NIL) || (mvalues == NIL))
|
1014
|
{
|
1015
|
MMechostr (0, "SCOL_gkeyFileSetValueList error : bad(s) argument(s) !\n");
|
1016
|
MMpush (m, NIL);
|
1017
|
return 0;
|
1018
|
}
|
1019
|
|
1020
|
ini = (GKeyFile*) MMfetch (m, MTOP (mini), OBJGKEYFILE_HANDLE);
|
1021
|
if (mgroup != NIL)
|
1022
|
group = MMstartstr (m, MTOP (mgroup));
|
1023
|
if (mkey != NIL)
|
1024
|
key = MMstartstr (m, MTOP (mkey));
|
1025
|
|
1026
|
mvalues = MTOP (mvalues);
|
1027
|
mtmp = MTOP (mtmp);
|
1028
|
|
1029
|
while (mtmp != NIL)
|
1030
|
{
|
1031
|
size++;
|
1032
|
mtmp = MMfetch (m, mtmp, 1)>>1;
|
1033
|
}
|
1034
|
values = g_new0 (gchar *, size+1);
|
1035
|
while (mvalues != NIL)
|
1036
|
{
|
1037
|
values[i] = SCOLUTF8 (MMstartstr (m, MTOP (MMfetch (m, mvalues, 0))), -1);
|
1038
|
i++;
|
1039
|
mvalues = MMfetch (m, mvalues, 1)>>1;
|
1040
|
}
|
1041
|
|
1042
|
g_key_file_set_string_list (ini, group, key, (const gchar** const) values, size);
|
1043
|
MMpush (m, mini);
|
1044
|
g_strfreev (values);
|
1045
|
return 0;
|
1046
|
}
|
1047
|
|
1048
|
/**
|
1049
|
* \brief _gkeyFileSetLocaleValueList : Associates a list of string for key under group.
|
1050
|
*
|
1051
|
* fun [ObjKeyFile S S S [S r1] ObjKeyFile
|
1052
|
* If key cannot be found then it is created. If group cannot be found then it is created.
|
1053
|
*
|
1054
|
* \param ObjKeyFile : an object
|
1055
|
* \param S : a group
|
1056
|
* \param S : a key
|
1057
|
* \param S : a locale identifier
|
1058
|
* \param [S r1] : a list of values
|
1059
|
* \return ObjKeyFile : the same object or nil if error
|
1060
|
*
|
1061
|
* If key or group is nil, the command is ignored but a message is written to the log
|
1062
|
*/
|
1063
|
int SCOL_gkeyFileSetLocaleValueList (mmachine m)
|
1064
|
{
|
1065
|
int mini, mgroup, mkey, mlocale, mvalues, mtmp;
|
1066
|
int i = 0, size = 0;
|
1067
|
GKeyFile *ini;
|
1068
|
gchar *group = NULL, *key = NULL, *locale = NULL;
|
1069
|
gchar ** values = NULL;
|
1070
|
|
1071
|
mtmp = MMget (m, 0); /* blurps */
|
1072
|
mvalues = MMpull (m);
|
1073
|
mlocale = MMpull (m);
|
1074
|
mkey = MMpull (m);
|
1075
|
mgroup = MMpull (m);
|
1076
|
mini = MMpull (m);
|
1077
|
|
1078
|
if ((mini == NIL) || (mvalues == NIL))
|
1079
|
{
|
1080
|
MMechostr (0, "SCOL_gkeyFileSetLocaleValueList error : bad(s) argument(s) !\n");
|
1081
|
MMpush (m, NIL);
|
1082
|
return 0;
|
1083
|
}
|
1084
|
|
1085
|
ini = (GKeyFile*) MMfetch (m, MTOP (mini), OBJGKEYFILE_HANDLE);
|
1086
|
if (mgroup != NIL)
|
1087
|
group = MMstartstr (m, MTOP (mgroup));
|
1088
|
if (mkey != NIL)
|
1089
|
key = MMstartstr (m, MTOP (mkey));
|
1090
|
if (mlocale != NIL)
|
1091
|
locale = MMstartstr (m, MTOP (mlocale));
|
1092
|
|
1093
|
mvalues = MTOP (mvalues);
|
1094
|
mtmp = MTOP (mtmp);
|
1095
|
|
1096
|
while (mtmp != NIL)
|
1097
|
{
|
1098
|
size++;
|
1099
|
mtmp = MMfetch (m, mtmp, 1)>>1;
|
1100
|
}
|
1101
|
values = g_new0 (gchar *, size+1);
|
1102
|
while (mvalues != NIL)
|
1103
|
{
|
1104
|
values[i] = SCOLUTF8 (MMstartstr (m, MTOP (MMfetch (m, mvalues, 0))), -1);
|
1105
|
i++;
|
1106
|
mvalues = MMfetch (m, mvalues, 1)>>1;
|
1107
|
}
|
1108
|
|
1109
|
g_key_file_set_locale_string_list (ini, group, key, locale, (const gchar** const) values, size);
|
1110
|
MMpush (m, mini);
|
1111
|
g_strfreev (values);
|
1112
|
return 0;
|
1113
|
}
|
1114
|
|
1115
|
/**
|
1116
|
* \brief _gkeyFileSetComment : Comments a key, a group or the key file.
|
1117
|
*
|
1118
|
* fun [ObjKeyFile S S S] ObjKeyFile
|
1119
|
*
|
1120
|
* \param ObjKeyFile : an object already created
|
1121
|
* \param S : a group
|
1122
|
* \param S : a key name
|
1123
|
* \param S : a comment
|
1124
|
* \return ObjKeyFile : the same object or nil if error
|
1125
|
*
|
1126
|
* See _gkeyFileGetComment too
|
1127
|
*/
|
1128
|
int SCOL_gkeyFileSetComment (mmachine m)
|
1129
|
{
|
1130
|
int mini, mgroup, mkey, mcomment;
|
1131
|
gboolean b;
|
1132
|
GKeyFile *ini;
|
1133
|
gchar *group = NULL, *key = NULL, *comment = NULL;
|
1134
|
GError *err = NULL;
|
1135
|
|
1136
|
mcomment = MMpull (m);
|
1137
|
mkey = MMpull (m);
|
1138
|
mgroup = MMpull (m);
|
1139
|
mini = MMpull (m);
|
1140
|
|
1141
|
if ((mini == NIL) || (mcomment == NIL))
|
1142
|
{
|
1143
|
MMechostr (0, "SCOL_gkeyFileSetComment error : bad(s) argument(s) !\n");
|
1144
|
MMpush (m, NIL);
|
1145
|
return 0;
|
1146
|
}
|
1147
|
|
1148
|
ini = (GKeyFile*) MMfetch (m, MTOP (mini), OBJGKEYFILE_HANDLE);
|
1149
|
if (mgroup != NIL)
|
1150
|
group = MMstartstr (m, MTOP (mgroup));
|
1151
|
if (mkey != NIL)
|
1152
|
key = MMstartstr (m, MTOP (mkey));
|
1153
|
comment = SCOLUTF8 (MMstartstr (m, MTOP (mcomment)), -1);
|
1154
|
|
1155
|
b = g_key_file_set_comment (ini, group, key, comment, &err);
|
1156
|
if ((!b) || (err != NULL))
|
1157
|
{
|
1158
|
MMechostr (0, "SCOL_gkeyFileSetComment error : %d -> %s !\n", err->code, err->message);
|
1159
|
g_error_free (err);
|
1160
|
MMpush (m, NIL);
|
1161
|
}
|
1162
|
MMpush (m, mini);
|
1163
|
g_free (comment);
|
1164
|
return 0;
|
1165
|
}
|
1166
|
|
1167
|
/**
|
1168
|
* \brief _gkeyFileRemGroup : Removes the specified group from the object.
|
1169
|
*
|
1170
|
* fun [ObjKeyFile S] ObjKeyFile
|
1171
|
*
|
1172
|
* \param ObjKeyFile : an object already created
|
1173
|
* \param S : a group
|
1174
|
* \return ObjKeyFile : the same object or nil if error
|
1175
|
*/
|
1176
|
int SCOL_gkeyFileRemGroup (mmachine m)
|
1177
|
{
|
1178
|
int mini, mgroup;
|
1179
|
gboolean b;
|
1180
|
GKeyFile *ini;
|
1181
|
gchar *group = NULL;
|
1182
|
GError *err = NULL;
|
1183
|
|
1184
|
mgroup = MMpull (m);
|
1185
|
mini = MMpull (m);
|
1186
|
|
1187
|
if ((mini == NIL) || (mgroup == NIL))
|
1188
|
{
|
1189
|
MMechostr (0, "SCOL_gkeyFileRemGroup error : bad(s) argument(s) !\n");
|
1190
|
MMpush (m, NIL);
|
1191
|
return 0;
|
1192
|
}
|
1193
|
|
1194
|
ini = (GKeyFile*) MMfetch (m, MTOP (mini), OBJGKEYFILE_HANDLE);
|
1195
|
group = MMstartstr (m, MTOP (mgroup));
|
1196
|
b = g_key_file_remove_group (ini, group, &err);
|
1197
|
if ((!b) || (err != NULL))
|
1198
|
{
|
1199
|
MMechostr (0, "SCOL_gkeyFileRemGroup error : %d -> %s !\n", err->code, err->message);
|
1200
|
g_error_free (err);
|
1201
|
MMpush (m, NIL);
|
1202
|
}
|
1203
|
MMpush (m, mini);
|
1204
|
return 0;
|
1205
|
}
|
1206
|
|
1207
|
/**
|
1208
|
* \brief _gkeyFileRemKey : Removes the specified key in group from the object.
|
1209
|
*
|
1210
|
* fun [ObjKeyFile S S] ObjKeyFile
|
1211
|
*
|
1212
|
* \param ObjKeyFile : an object already created
|
1213
|
* \param S : a group
|
1214
|
* \param S : a key
|
1215
|
* \return ObjKeyFile : the same object or nil if error
|
1216
|
*/
|
1217
|
int SCOL_gkeyFileRemKey (mmachine m)
|
1218
|
{
|
1219
|
int mini, mgroup, mkey;
|
1220
|
gboolean b;
|
1221
|
GKeyFile *ini;
|
1222
|
gchar *group = NULL, *key = NULL;
|
1223
|
GError *err = NULL;
|
1224
|
|
1225
|
mkey = MMpull (m);
|
1226
|
mgroup = MMpull (m);
|
1227
|
mini = MMpull (m);
|
1228
|
|
1229
|
if ((mini == NIL) || (mgroup == NIL) || (mkey == NIL))
|
1230
|
{
|
1231
|
MMechostr (0, "SCOL_gkeyFileRemKey error : bad(s) argument(s) !\n");
|
1232
|
MMpush (m, NIL);
|
1233
|
return 0;
|
1234
|
}
|
1235
|
|
1236
|
ini = (GKeyFile*) MMfetch (m, MTOP (mini), OBJGKEYFILE_HANDLE);
|
1237
|
group = MMstartstr (m, MTOP (mgroup));
|
1238
|
key = MMstartstr (m, MTOP (mkey));
|
1239
|
b = g_key_file_remove_key (ini, group, key, &err);
|
1240
|
if ((!b) || (err != NULL))
|
1241
|
{
|
1242
|
MMechostr (0, "SCOL_gkeyFileRemKey error : %d -> %s !\n", err->code, err->message);
|
1243
|
g_error_free (err);
|
1244
|
MMpush (m, NIL);
|
1245
|
}
|
1246
|
MMpush (m, mini);
|
1247
|
return 0;
|
1248
|
}
|
1249
|
|
1250
|
/**
|
1251
|
* \brief _gkeyFileRemComment : Removes a comment above key from group.
|
1252
|
*
|
1253
|
* fun [ObjKeyFile S S] ObjKeyFile
|
1254
|
* If key is NULL then comment will be removed above group.
|
1255
|
* If both key and group are NULL, then comment will be removed above the first group in the file.
|
1256
|
*
|
1257
|
* \param ObjKeyFile : an object already created
|
1258
|
* \param S : a group
|
1259
|
* \param S : a key
|
1260
|
* \return ObjKeyFile : the same object or nil if error
|
1261
|
*/
|
1262
|
int SCOL_gkeyFileRemComment (mmachine m)
|
1263
|
{
|
1264
|
int mini, mgroup, mkey;
|
1265
|
gboolean b;
|
1266
|
GKeyFile *ini;
|
1267
|
gchar *group = NULL, *key = NULL;
|
1268
|
GError *err = NULL;
|
1269
|
|
1270
|
mkey = MMpull (m);
|
1271
|
mgroup = MMpull (m);
|
1272
|
mini = MMpull (m);
|
1273
|
|
1274
|
if ((mini == NIL) || (mgroup == NIL) || (mkey == NIL))
|
1275
|
{
|
1276
|
MMechostr (0, "_gkeyFileRemComment error : bad(s) argument(s) !\n");
|
1277
|
MMpush (m, NIL);
|
1278
|
return 0;
|
1279
|
}
|
1280
|
|
1281
|
ini = (GKeyFile*) MMfetch (m, MTOP (mini), OBJGKEYFILE_HANDLE);
|
1282
|
group = MMstartstr (m, MTOP (mgroup));
|
1283
|
key = MMstartstr (m, MTOP (mkey));
|
1284
|
b = g_key_file_remove_comment (ini, group, key, &err);
|
1285
|
if ((!b) || (err != NULL))
|
1286
|
{
|
1287
|
MMechostr (0, "_gkeyFileRemComment error : %d -> %s !\n", err->code, err->message);
|
1288
|
g_error_free (err);
|
1289
|
MMpush (m, NIL);
|
1290
|
}
|
1291
|
MMpush (m, mini);
|
1292
|
return 0;
|
1293
|
}
|
1294
|
|
1295
|
|
1296
|
|
1297
|
|
1298
|
|
1299
|
|
1300
|
|
1301
|
|
1302
|
|
1303
|
/* API d?finitions : */
|
1304
|
|
1305
|
char* gkey_name[GKEYFILE_PKG_NB]=
|
1306
|
{
|
1307
|
"ObjKeyFile",
|
1308
|
|
1309
|
"_gkeyFileReadP",
|
1310
|
|
1311
|
"_gkeyFileLoadS",
|
1312
|
"_gkeyFileLoadP",
|
1313
|
"_gkeyFileSave",
|
1314
|
"_gkeyFileDestroy",
|
1315
|
|
1316
|
"_gkeyFileGetContent",
|
1317
|
"_gkeyFileGetDatas",
|
1318
|
"_gkeyFileGetGroups",
|
1319
|
"_gkeyFileGetNbGroups",
|
1320
|
"_gkeyFileDataExist",
|
1321
|
"_keyFileGetValue",
|
1322
|
"_keyFileGetLocaleValue",
|
1323
|
"_gkeyFileGetValueList",
|
1324
|
"_gkeyFileGetValueLocaleList",
|
1325
|
"_gkeyFileGetComment",
|
1326
|
|
1327
|
"_gkeyFileSetValue",
|
1328
|
"_gkeyFileSetLocaleValue",
|
1329
|
"_gkeyFileSetValueList",
|
1330
|
"_gkeyFileSetLocaleValueList",
|
1331
|
"_gkeyFileSetComment",
|
1332
|
|
1333
|
"_gkeyFileRemGroup",
|
1334
|
"_gkeyFileRemKey",
|
1335
|
"_gkeyFileRemComment",
|
1336
|
|
1337
|
"GKF_VALUE_RAW",
|
1338
|
"GKF_VALUE_STRING",
|
1339
|
"GKF_VALUE_INTEGER",
|
1340
|
"GKF_VALUE_INTEGER64",
|
1341
|
"GKF_VALUE_UINTEGER64",
|
1342
|
"GKF_VALUE_DOUBLE",
|
1343
|
"GKF_VALUE_BOOLEAN"
|
1344
|
|
1345
|
};
|
1346
|
|
1347
|
int (*gkey_fun[GKEYFILE_PKG_NB])(mmachine m)=
|
1348
|
{
|
1349
|
NULL,
|
1350
|
|
1351
|
SCOL_gkeyFileReadP,
|
1352
|
|
1353
|
SCOL_gkeyFileLoadS,
|
1354
|
SCOL_gkeyFileLoadP,
|
1355
|
SCOL_gkeyFileSave,
|
1356
|
SCOL_gkeyFileDestroy,
|
1357
|
|
1358
|
SCOL_gkeyFileGetContent,
|
1359
|
SCOL_gkeyFileGetDatas,
|
1360
|
SCOL_gkeyFileGetGroups,
|
1361
|
SCOL_gkeyFileGetNbGroups,
|
1362
|
SCOL_gkeyFileDataExist,
|
1363
|
SCOL_keyFileGetValue,
|
1364
|
SCOL_keyFileGetLocaleValue,
|
1365
|
SCOL_gkeyFileGetValueList,
|
1366
|
SCOL_gkeyFileGetValueLocaleList,
|
1367
|
SCOL_gkeyFileGetComment,
|
1368
|
|
1369
|
SCOL_gkeyFileSetValue,
|
1370
|
SCOL_gkeyFileSetLocaleValue,
|
1371
|
SCOL_gkeyFileSetValueList,
|
1372
|
SCOL_gkeyFileSetLocaleValueList,
|
1373
|
SCOL_gkeyFileSetComment,
|
1374
|
|
1375
|
SCOL_gkeyFileRemGroup,
|
1376
|
SCOL_gkeyFileRemKey,
|
1377
|
SCOL_gkeyFileRemComment,
|
1378
|
|
1379
|
GKF_VALUE_RAW,
|
1380
|
GKF_VALUE_STRING,
|
1381
|
GKF_VALUE_INTEGER,
|
1382
|
GKF_VALUE_INTEGER64,
|
1383
|
GKF_VALUE_UINTEGER64,
|
1384
|
GKF_VALUE_DOUBLE,
|
1385
|
GKF_VALUE_BOOLEAN
|
1386
|
};
|
1387
|
|
1388
|
int gkey_narg[GKEYFILE_PKG_NB]=
|
1389
|
{
|
1390
|
TYPTYPE,
|
1391
|
|
1392
|
2, /* SCOL_gkeyFileReadP */
|
1393
|
|
1394
|
4, /* SCOL_gkeyFileLoadS */
|
1395
|
4, /* SCOL_gkeyFileLoadP */
|
1396
|
2, /* SCOL_gkeyFileSave */
|
1397
|
1, /* SCOL_gkeyFileDestroy */
|
1398
|
|
1399
|
1, /* SCOL_gkeyFileGetContent */
|
1400
|
1, /* SCOL_gkeyFileGetDatas */
|
1401
|
1, /* SCOL_gkeyFileGetGroups */
|
1402
|
1, /* SCOL_gkeyFileGetNbGroups */
|
1403
|
3, /* SCOL_gkeyFileDataExist */
|
1404
|
4, /* SCOL_keyFileGetValue */
|
1405
|
4, /* SCOL_keyFileGetLocaleValue */
|
1406
|
3, /* SCOL_gkeyFileGetValueList */
|
1407
|
4, /* SCOL_gkeyFileGetValueLocaleList */
|
1408
|
3, /* SCOL_gkeyFileGetComment */
|
1409
|
|
1410
|
5, /* SCOL_gkeyFileSetValue */
|
1411
|
5, /* SCOL_gkeyFileSetLocaleValue */
|
1412
|
4, /* SCOL_gkeyFileSetValueList */
|
1413
|
5, /* SCOL_gkeyFileSetLocaleValueList */
|
1414
|
4, /* SCOL_gkeyFileSetComment */
|
1415
|
|
1416
|
2, /* SCOL_gkeyFileRemGroup */
|
1417
|
3, /* SCOL_gkeyFileRemKey */
|
1418
|
3, /* SCOL_gkeyFileRemComment */
|
1419
|
|
1420
|
0,
|
1421
|
0,
|
1422
|
0,
|
1423
|
0,
|
1424
|
0,
|
1425
|
0,
|
1426
|
0
|
1427
|
};
|
1428
|
|
1429
|
char* gkey_type[GKEYFILE_PKG_NB]=
|
1430
|
{
|
1431
|
NULL,
|
1432
|
|
1433
|
"fun [P S] [[S [[S S] r1]] r1]", /* SCOL_gkeyFileReadP */
|
1434
|
|
1435
|
"fun [Chn S S I] ObjKeyFile", /* SCOL_gkeyFileLoadS */
|
1436
|
"fun [Chn P S I] ObjKeyFile", /* SCOL_gkeyFileLoadP */
|
1437
|
"fun [ObjKeyFile W] I", /* SCOL_gkeyFileSave */
|
1438
|
"fun [ObjKeyFile] I", /* SCOL_gkeyFileDestroy */
|
1439
|
|
1440
|
"fun [ObjKeyFile] [S I]", /* SCOL_gkeyFileGetContent */
|
1441
|
"fun [ObjKeyFile] [[S [[S S] r1]] r1]", /* SCOL_gkeyFileGetDatas */
|
1442
|
"fun [ObjKeyFile] [S r1]", /* SCOL_gkeyFileGetGroups */
|
1443
|
"fun [ObjKeyFile] I", /* SCOL_gkeyFileGetNbGroups */
|
1444
|
"fun [ObjKeyFile S S] I", /* SCOL_gkeyFileDataExist */
|
1445
|
"fun [ObjKeyFile S S I] S", /* SCOL_keyFileGetValue */
|
1446
|
"fun [ObjKeyFile S S S] S", /* SCOL_keyFileGetLocaleValue */
|
1447
|
"fun [ObjKeyFile S S] [S r1]", /* SCOL_gkeyFileGetValueList */
|
1448
|
"fun [ObjKeyFile S S S] [S r1]", /* SCOL_gkeyFileGetValueLocaleList */
|
1449
|
"fun [ObjKeyFile S S] S", /* SCOL_gkeyFileGetComment */
|
1450
|
|
1451
|
"fun [ObjKeyFile S S S I] ObjKeyFile", /* SCOL_gkeyFileSetValue */
|
1452
|
"fun [ObjKeyFile S S S S] ObjKeyFile", /* SCOL_gkeyFileSetLocaleValue */
|
1453
|
"fun [ObjKeyFile S S [S r1]] ObjKeyFile", /* SCOL_gkeyFileSetValueList */
|
1454
|
"fun [ObjKeyFile S S S [S r1]] ObjKeyFile", /* SCOL_gkeyFileSetLocaleValueList */
|
1455
|
"fun [ObjKeyFile S S S] ObjKeyFile", /* SCOL_gkeyFileSetComment */
|
1456
|
|
1457
|
"fun [ObjKeyFile S] ObjKeyFile", /* SCOL_gkeyFileRemGroup */
|
1458
|
"fun [ObjKeyFile S S] ObjKeyFile", /* SCOL_gkeyFileRemKey */
|
1459
|
"fun [ObjKeyFile S S] ObjKeyFile", /* SCOL_gkeyFileRemComment */
|
1460
|
|
1461
|
"fun [] I",
|
1462
|
"fun [] I",
|
1463
|
"fun [] I",
|
1464
|
"fun [] I",
|
1465
|
"fun [] I",
|
1466
|
"fun [] I",
|
1467
|
"fun [] I"
|
1468
|
};
|
1469
|
|
1470
|
|
1471
|
/** \private
|
1472
|
*/
|
1473
|
int ObjKeyFileTypeDestroy (mmachine m, int handsys, int mobj)
|
1474
|
{
|
1475
|
GKeyFile *o;
|
1476
|
MMechostr (MSKDEBUG, "ObjKeyFileTypeDestroy: entering\n");
|
1477
|
|
1478
|
o = (GKeyFile*) MMfetch (m, MTOP (mobj), OBJGKEYFILE_HANDLE);
|
1479
|
if (o == (int) NULL)
|
1480
|
{
|
1481
|
MMechostr (MSKDEBUG, "ObjKeyFileTypeDestroy : object %p already destroyed\n", (void *) o);
|
1482
|
return 0;
|
1483
|
}
|
1484
|
g_key_file_free (o);
|
1485
|
|
1486
|
MMstore (m, MTOP (mobj), OBJGKEYFILE_HANDLE, (int) NULL);
|
1487
|
MMechostr (MSKDEBUG, "ObjKeyFileTypeDestroy : object %p has been destroyed\n", (void *) o);
|
1488
|
|
1489
|
return 0;
|
1490
|
}
|
1491
|
|
1492
|
/** \private
|
1493
|
*/
|
1494
|
int SCOLinitGlibKeyClass (mmachine m)
|
1495
|
{
|
1496
|
int k;
|
1497
|
|
1498
|
MMechostr (0, "SCOLinitGlibKeyClass : entering\n");
|
1499
|
|
1500
|
ObjKeyFile = OBJregister (GKEYFILE_RFL_NB, 1, ObjKeyFileTypeDestroy, "ObjKeyFileType");
|
1501
|
|
1502
|
k = PKhardpak (m, "GkeyEngine", GKEYFILE_PKG_NB, gkey_name, gkey_fun, gkey_narg, gkey_type);
|
1503
|
return k;
|
1504
|
}
|
1505
|
|
1506
|
|
1507
|
/**
|
1508
|
* \private
|
1509
|
* \brief Free the key file library
|
1510
|
* Plateforms supported : MS Windows and GNU / Linux
|
1511
|
*/
|
1512
|
int GkeyRelease ()
|
1513
|
{
|
1514
|
MMechostr (0, "\nG KEY FILE library released !\n");
|
1515
|
return 0;
|
1516
|
}
|
1517
|
|
1518
|
|
1519
|
#if ((defined _WIN32) || (defined __WIN32__))
|
1520
|
# define SCOL_GBASE_PLUGIN_EXPORT __declspec (dllexport)
|
1521
|
#elif ((defined linux) || (defined __linux))
|
1522
|
# define SCOL_GBASE_PLUGIN_EXPORT
|
1523
|
#else
|
1524
|
# error no platform supported
|
1525
|
#endif
|
1526
|
|
1527
|
SCOL_GBASE_PLUGIN_EXPORT int SCOLloadGBASE(mmachine m, cbmachine w)
|
1528
|
{
|
1529
|
ww = w;
|
1530
|
mm = m;
|
1531
|
|
1532
|
SCOLinitplugin(w);
|
1533
|
return SCOLinitGlibKeyClass (m);
|
1534
|
}
|
1535
|
|
1536
|
SCOL_GBASE_PLUGIN_EXPORT int SCOLfreeGBASE()
|
1537
|
{
|
1538
|
GkeyRelease ();
|
1539
|
return 0;
|
1540
|
}
|
1541
|
|