18 #define _XOPEN_SOURCE 700
29 #define DFUNCTION "_sion_flags_init_entry"
32 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
38 DPRINTFP((2, DFUNCTION, -1,
"leave\n"));
42 #define DFUNCTION "_sion_flags_create_entry"
53 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
56 _sion_flags_init_entry(new_entry);
58 DPRINTFP((2, DFUNCTION, -1,
"leave\n"));
64 #define DFUNCTION "_sion_flags_destroy_entry"
67 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
74 DPRINTFP((2, DFUNCTION, -1,
"leave\n"));
78 #define DFUNCTION "_sion_flags_iter"
81 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
82 DPRINTFP((2, DFUNCTION, -1,
"leave\n"));
88 #define DFUNCTION "_sion_flags_init_store"
91 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
94 store->current = store->root;
96 DPRINTFP((2, DFUNCTION, -1,
"leave\n"));
100 #define DFUNCTION "_sion_flags_create_store"
111 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
114 _sion_flags_init_store(new_store);
116 DPRINTFP((2, DFUNCTION, -1,
"leave\n"));
122 #define DFUNCTION "_sion_flags_destroy_store"
128 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
130 entry = _sion_flags_iter(*store);
132 while (entry != NULL) {
134 _sion_flags_destroy_entry(&entry);
141 DPRINTFP((2, DFUNCTION, -1,
"leave\n"));
145 #define DFUNCTION "_sion_flags_add_entry"
162 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
165 entry->key = (
char*)malloc(strlen(key) + 1);
166 entry->val = (
char*)malloc(strlen(val) + 1);
168 strcpy(entry->key, key);
169 strcpy(entry->val, val);
170 entry->next = new_entry;
172 DPRINTFP((2, DFUNCTION, -1,
"leave (entry->key = %s, entry->val = %s\n",
173 entry->key, entry->val));
179 #define DFUNCTION "_sion_flags_add"
184 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
188 DPRINTFP((2, DFUNCTION, -1,
"leave\n"));
192 #define DFUNCTION "_sion_flags_get"
197 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
199 for (iter = _sion_flags_iter(store); iter->next != NULL; iter = iter->next) {
200 if (!strcmp(iter->key, key)) {
201 DPRINTFP((2, DFUNCTION, -1,
"leave (key in store)\n"));
206 DPRINTFP((2, DFUNCTION, -1,
"leave (key not in store)\n"));
212 #define DFUNCTION "_sion_flags_update_mask"
217 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
220 store->mask |= _SION_FMODE_ANSI;
222 for (iter = _sion_flags_iter(store); iter->next != NULL; iter = iter->next) {
223 if ((!strcmp(iter->key,
"w")) || (!strcmp(iter->key,
"wb")) ||
224 (!strcmp(iter->key,
"bw"))) {
225 store->mask |= _SION_FMODE_WRITE;
227 else if ((!strcmp(iter->key,
"r")) || (!strcmp(iter->key,
"rb")) ||
228 (!strcmp(iter->key,
"br"))) {
229 store->mask |= _SION_FMODE_READ;
231 else if (!strcmp(iter->key,
"buffered")) {
232 store->mask |= _SION_FMODE_BUFFERED;
234 else if (!strcmp(iter->key,
"buddy")) {
235 store->mask |= _SION_FMODE_BUDDY;
237 else if (!strcmp(iter->key,
"compress")) {
238 store->mask |= _SION_FMODE_COMPRESS;
240 else if (!strcmp(iter->key,
"collective")) {
241 store->mask |= _SION_FMODE_COLLECTIVE;
243 else if ((!strcmp(iter->key,
"collectivemerge")) ||
244 (!strcmp(iter->key,
"cmerge"))) {
245 store->mask |= _SION_FMODE_COLLECTIVE_MERGE;
247 else if (!strcmp(iter->key,
"keyval")) {
248 if ((!strcmp(iter->val,
"default")) || (!strcmp(iter->val,
"inline")) ||
249 (!strcmp(iter->val,
""))) {
250 store->mask |= _SION_FMODE_KEYVAL_INLINE;
252 else if (!strcmp(iter->key,
"meta")) {
253 store->mask |= _SION_FMODE_KEYVAL_META;
255 else if (!strcmp(iter->key,
"hash")) {
256 store->mask |= _SION_FMODE_KEYVAL_HASH;
258 else if (!strcmp(iter->key,
"none")) {
259 store->mask |= _SION_FMODE_KEYVAL_NONE;
261 else if (!strcmp(iter->key,
"unknown")) {
262 store->mask |= _SION_FMODE_KEYVAL_UNKNOWN;
265 else if (!strcmp(iter->key,
"endianness")) {
266 store->mask |= _SION_FMODE_ENDIANNESS_SET;
267 if (!strcmp(iter->val,
"big")) {
268 store->mask |= _SION_FMODE_ENDIANNESS_BIG;
271 else if (!strcmp(iter->key,
"posix")) {
272 store->mask |= _SION_FMODE_POSIX;
273 store->mask ^= store->mask & _SION_FMODE_ANSI;
274 #if defined(_SION_SIONFWD)
275 store->mask ^= store->mask & _SION_FMODE_SIONFWD;
277 #ifdef _SION_IME_NATIVE
278 store->mask ^= store->mask & _SION_FMODE_IME_NATIVE;
281 else if (!strcmp(iter->key,
"ansi")) {
282 store->mask |= _SION_FMODE_ANSI;
283 store->mask ^= store->mask & _SION_FMODE_POSIX;
284 #if defined(_SION_SIONFWD)
285 store->mask ^= store->mask & _SION_FMODE_SIONFWD;
287 #ifdef _SION_IME_NATIVE
288 store->mask ^= store->mask & _SION_FMODE_IME_NATIVE;
291 #if defined(_SION_SIONFWD)
292 else if (!strcmp(iter->key,
"sionfwd")) {
293 store->mask |= _SION_FMODE_SIONFWD;
294 store->mask ^= store->mask & _SION_FMODE_ANSI;
295 store->mask ^= store->mask & _SION_FMODE_POSIX;
296 #ifdef _SION_IME_NATIVE
297 store->mask ^= store->mask & _SION_FMODE_IME_NATIVE;
301 #ifdef _SION_IME_NATIVE
302 else if (!strcmp(iter->key,
"ime")) {
303 store->mask |= _SION_FMODE_IME_NATIVE;
304 store->mask ^= store->mask & _SION_FMODE_ANSI;
305 store->mask ^= store->mask & _SION_FMODE_POSIX;
306 #if defined(_SION_SIONFWD)
307 store->mask ^= store->mask & _SION_FMODE_SIONFWD;
313 DPRINTFP((2, DFUNCTION, -1,
"leave (mask = %llx)\n", store->mask));
319 #define DFUNCTION "_sion_parse_flags"
332 char* saveptr = NULL;
333 const char* delim_tok =
",";
334 const char* delim_kv =
"=";
337 const int len = strlen(flags) + 1;
340 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
344 tmps = (
char*)malloc(len);
345 key = (
char*)malloc(len);
346 val = (
char*)malloc(len);
349 DPRINTF((32, DFUNCTION, -1,
"tmps = '%s'\n", tmps));
350 DPRINTF((32, DFUNCTION, -1,
"delim_tok = '%s'\n", delim_tok));
351 DPRINTF((32, DFUNCTION, -1,
"delim_kv = '%s'\n", delim_kv));
352 pch = strtok_r(tmps, delim_tok, &saveptr);
353 while (pch != NULL) {
354 span = strcspn(pch, delim_kv);
355 strncpy(key, pch, span);
357 if (span < strlen(pch)) {
358 strcpy(val, &pch[span + 1]);
363 DPRINTF((32, DFUNCTION, -1,
"key = '%s' | val = '%s'\n", key, val));
364 _sion_flags_add(store, key, val);
365 pch = strtok_r(NULL, delim_tok, &saveptr);
372 _sion_flags_update_mask(store);
374 DPRINTFP((2, DFUNCTION, -1,
"leave\n"));
_sion_flags_entry * _sion_flags_add_entry(_sion_flags_entry *entry, const char *key, const char *val)
Create a flags entry.
_sion_flags_store * _sion_flags_create_store(void)
Create a flags entry.
_sion_flags_store * _sion_parse_flags(const char *flags)
Parse flags and return a flags store with key value pairs.
_sion_flags_entry * _sion_flags_create_entry(void)
Create a flags entry.