-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathining.h
More file actions
125 lines (98 loc) · 4.3 KB
/
Copy pathining.h
File metadata and controls
125 lines (98 loc) · 4.3 KB
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
#ifndef INING_H
#define INING_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stddef.h>
/* -----------------------------------------------------------------------
* IniNG - Ini Next Gen (in-memory string-based .ini library)
*
* Format:
* {GroupName} ; optional comment
* [SiteName] ; optional comment
* key = value ; optional comment
* [End]
* {End}
* ----------------------------------------------------------------------- */
/* Opaque handle returned by iningLoad() */
typedef struct IniNG IniNG;
/* -----------------------------------------------------------------------
* Lifecycle
* ----------------------------------------------------------------------- */
/** Load an .ini file into memory. Returns NULL on error. */
IniNG *iningLoad(const char *filename);
/** Parse an in-memory string instead of a file. */
IniNG *iningParse(const char *text);
/** Write the (possibly modified) document back to a file.
* Pass NULL to write back to the file it was loaded from.
* Returns 0 on success, -1 on error. */
int iningSave(IniNG *ini, const char *filename);
/** Return the current document as a heap-allocated string.
* Caller must free(). */
char *iningToString(const IniNG *ini);
/** Free all memory. */
void iningFree(IniNG *ini);
/* -----------------------------------------------------------------------
* Read
* ----------------------------------------------------------------------- */
/** Get a value. Returns NULL if not found.
* The returned pointer is into the internal buffer – do NOT free it.
* It is valid until the next mutating call. */
const char *iningGet(const IniNG *ini,
const char *group,
const char *site,
const char *key);
/** Check whether a group exists. */
int iningHasGroup(const IniNG *ini, const char *group);
/** Check whether a site exists inside a group. */
int iningHasSite(const IniNG *ini, const char *group, const char *site);
/* -----------------------------------------------------------------------
* Write (all modify the in-memory buffer; call iningSave() to persist)
* ----------------------------------------------------------------------- */
/** Set (or add) a key=value inside an existing group/site.
* Returns 0 on success, -1 if group or site not found. */
int iningSet(IniNG *ini,
const char *group,
const char *site,
const char *key,
const char *value);
/** Add a brand-new group.
* Returns 0 on success, -1 if the group already exists. */
int iningAddGroup(IniNG *ini, const char *group, const char *comment);
/** Add a brand-new site inside an existing group.
* Returns 0 on success, -1 if group not found or site already exists. */
int iningAddSite(IniNG *ini,
const char *group,
const char *site,
const char *comment);
/* -----------------------------------------------------------------------
* Delete
* ----------------------------------------------------------------------- */
/** Delete a single key from a site.
* Returns 0 on success, -1 if not found. */
int iningDeleteKey(IniNG *ini,
const char *group,
const char *site,
const char *key);
/** Delete an entire site (and all its keys) from a group.
* Returns 0 on success, -1 if not found. */
int iningDeleteSite(IniNG *ini, const char *group, const char *site);
/** Delete an entire group (and all its sites/keys).
* Returns 0 on success, -1 if not found. */
int iningDeleteGroup(IniNG *ini, const char *group);
/* -----------------------------------------------------------------------
* Iteration helpers
* ----------------------------------------------------------------------- */
/** Fill *names with a NULL-terminated array of group name strings
* taken directly from the buffer (read-only, valid until next mutation).
* *count receives the number of groups.
* Caller must free(*names) but NOT the individual strings.
* Returns 0 on success. */
int iningListGroups(const IniNG *ini, const char ***names, int *count);
/** Same for sites inside a group. */
int iningListSites(const IniNG *ini, const char *group,
const char ***names, int *count);
#ifdef __cplusplus
}
#endif
#endif /* INING_H */