-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathpsettings.c
762 lines (653 loc) · 23.3 KB
/
psettings.c
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
/* psettings.c implements an object that encapsulates parser settings,
* including a convenience method that reads settings from an XML
* file.
*
* written nml 2004-08-09
*
*/
#include "firstinclude.h"
#include "psettings.h"
#include "chash.h"
#include "error.h"
#include "str.h"
#include "mlparse_wrap.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
enum type_flags {
TYPE_FLAG_DEFSET = (1 << 0), /* default was set (not inherited) */
TYPE_FLAG_SELF_ID = (1 << 1) /* documents identify themselves */
};
/* structure to represent the parser settings for one mime type */
struct psettings_type {
struct chash *tags; /* hashtable of tags to attrs */
enum psettings_attr def; /* default attr */
enum type_flags flags; /* flags for this type */
};
/* structure to represent all parser settings */
struct psettings {
struct chash *strings; /* hashtable of tag strings */
struct psettings_type *type; /* per-type array */
unsigned int types; /* size of type array */
enum psettings_attr def; /* default settings for unrecognised
* tags */
};
struct psettings *psettings_new(enum psettings_attr def) {
struct psettings *pset = malloc(sizeof(*pset));
if (pset
&& (pset->strings = chash_ptr_new(5, 0.5,
(unsigned int (*)(const void *)) str_hash,
(int (*)(const void *, const void *)) str_cmp))) {
pset->type = NULL;
pset->types = 0;
pset->def = def;
} else if (pset) {
if (pset->strings) {
chash_delete(pset->strings);
}
free(pset);
pset = NULL;
}
return pset;
}
static void freestr(void *userdata, const void *key, void **data) {
free(*data);
}
void psettings_delete(struct psettings *pset) {
unsigned int i;
for (i = 0; i < pset->types; i++) {
chash_delete(pset->type[i].tags);
}
if (pset->type) {
free(pset->type);
}
chash_ptr_ptr_foreach(pset->strings, NULL, freestr);
chash_delete(pset->strings);
free(pset);
}
static enum psettings_ret psettings_expand(struct psettings *pset,
enum mime_types type) {
void *ptr;
unsigned int i;
if ((ptr = realloc(pset->type,
sizeof(*pset->type) * (pset->types * 2 + 1)))) {
i = pset->types;
pset->type = ptr;
pset->types = pset->types * 2 + 1;
for (; i < pset->types; i++) {
if ((pset->type[i].tags = chash_ptr_new(1, 2.0,
(unsigned int (*)(const void *)) str_hash,
(int (*)(const void *, const void *)) str_cmp))) {
pset->type[i].def = pset->def;
pset->type[i].flags = 0;
} else {
/* couldn't initialise hashtable */
pset->types = i;
if (type < 0 || (unsigned int) type >= pset->types) {
return PSETTINGS_ENOMEM;
}
break;
}
}
} else {
return PSETTINGS_ENOMEM;
}
return PSETTINGS_OK;
}
enum psettings_ret psettings_set(struct psettings *pset, enum mime_types type,
const char *tag, enum psettings_attr attr) {
void **ptr_find;
unsigned long int *settings;
char *localtag;
enum psettings_ret ret;
assert(type >= 0);
while ((unsigned int) type >= pset->types) {
if ((ret = psettings_expand(pset, type)) != PSETTINGS_OK) {
return ret;
}
}
assert((unsigned int) type < pset->types);
if (chash_ptr_luint_find(pset->type[type].tags, tag, &settings)
== CHASH_OK) {
/* found an existing entry, modify it */
*settings = attr;
} else {
/* need to insert new entry */
/* find or insert it into the strings table */
if (chash_ptr_ptr_find(pset->strings, tag, &ptr_find) == CHASH_OK) {
localtag = *ptr_find;
} else {
if ((localtag = str_dup(tag))
&& (chash_ptr_ptr_insert(pset->strings, localtag, localtag)
== CHASH_OK)) {
/* succeeded, do nothing */
} else {
if (localtag) {
free(localtag);
}
return PSETTINGS_ENOMEM;
}
}
if (chash_ptr_luint_insert(pset->type[type].tags, localtag, attr)
== CHASH_OK) {
/* succeeded, finish up below */
} else {
return PSETTINGS_ENOMEM;
}
}
/* keep track of whether documents contain an internal identification */
if (attr & PSETTINGS_ATTR_ID) {
pset->type[type].flags |= TYPE_FLAG_SELF_ID;
}
return PSETTINGS_OK;
}
enum psettings_ret psettings_type_default(struct psettings *pset,
enum mime_types type, enum psettings_attr def) {
enum psettings_ret ret;
assert(type >= 0);
while ((unsigned int) type >= pset->types) {
if ((ret = psettings_expand(pset, type)) != PSETTINGS_OK) {
return ret;
}
}
assert((unsigned int) type < pset->types);
pset->type[type].def = def;
pset->type[type].flags |= TYPE_FLAG_DEFSET;
return PSETTINGS_OK;
}
enum psettings_attr psettings_find(struct psettings *pset,
enum mime_types type, const char *tag) {
if (type >= 0 && ((unsigned int) type) < pset->types) {
return psettings_type_find(pset, &pset->type[type], tag);
} else {
return pset->def;
}
}
enum psettings_attr psettings_type_find(struct psettings *pset,
struct psettings_type *type, const char *tag) {
unsigned long int *settings;
assert(type);
if (chash_ptr_luint_find(type->tags, tag, &settings) == CHASH_OK) {
return *settings;
} else {
return pset->def;
}
}
/* get the set of tags for a given mime type */
enum psettings_ret psettings_type_tags(struct psettings *pset,
enum mime_types type, struct psettings_type **ptype) {
if (type >= 0 && ((unsigned int) type) < pset->types) {
*ptype = &pset->type[type];
return PSETTINGS_OK;
} else {
*ptype = NULL;
return PSETTINGS_EEXIST;
}
}
int psettings_self_id(struct psettings *pset, enum mime_types type) {
if (type >= 0 && ((unsigned int) type) < pset->types) {
return pset->type[type].flags & TYPE_FLAG_SELF_ID;
} else {
return 0;
}
}
#define WORDLEN 100
static int parse(struct mlparse_wrap *parser, char *buf, unsigned int *len,
int strip) {
enum mlparse_ret ret;
do {
ret = mlparse_wrap_parse(parser, buf, len, strip);
/* filter out comments and whitespace and cdata sections */
switch (ret) {
case MLPARSE_COMMENT:
/* skip to end of comment */
do {
ret = parse(parser, buf, len, strip);
switch (ret) {
case MLPARSE_WORD:
case MLPARSE_END | MLPARSE_WORD:
case MLPARSE_CONT | MLPARSE_WORD:
break;
case MLPARSE_END | MLPARSE_COMMENT:
break;
case MLPARSE_EOF:
return MLPARSE_EOF;
default:
assert(0);
return MLPARSE_ERR;
};
} while ((ret != (MLPARSE_END | MLPARSE_COMMENT)));
break;
case MLPARSE_WHITESPACE:
break;
case MLPARSE_CDATA:
case MLPARSE_END | MLPARSE_CDATA:
break;
default:
return ret;
};
} while (1);
}
static int psettings_read_tag(struct psettings *pset,
struct mlparse_wrap *parser, enum mime_types type, char *buf, char *tagbuf) {
enum mlparse_ret ret;
unsigned int len;
enum psettings_attr attr = PSETTINGS_ATTR_INDEX,
ex_attr; /* existing attribute */
struct psettings_type *ptype;
/* 'tag' tag can contain name and index attributes only */
/* read name and index tags */
tagbuf[0] = '\0';
while ((ret = parse(parser, buf, &len, 1)) == MLPARSE_PARAM) {
buf[len] = '\0';
if (!str_casecmp(buf, "name")) {
assert(tagbuf[0] == '\0');
if ((ret = parse(parser, tagbuf, &len, 0)) == MLPARSE_PARAMVAL) {
/* got the tag name in tagbuf */
tagbuf[len] = '\0';
str_tolower(tagbuf);
} else {
ERROR("expecting parameter value after name attribute");
return 0;
}
} else if (!str_casecmp(buf, "index")) {
if ((ret = parse(parser, buf, &len, 1)) == MLPARSE_PARAMVAL) {
buf[len] = '\0';
if (!str_casecmp(buf, "true")) {
attr |= PSETTINGS_ATTR_INDEX;
} else if (!str_casecmp(buf, "false")) {
attr &= ~PSETTINGS_ATTR_INDEX;
} else if (!str_casecmp(buf, "binary")) {
attr &= ~PSETTINGS_ATTR_INDEX;
attr |= PSETTINGS_ATTR_CHECKBIN;
} else if (!str_casecmp(buf, "pop")) {
attr &= ~PSETTINGS_ATTR_INDEX;
attr |= PSETTINGS_ATTR_POP;
} else if (!str_casecmp(buf, "noop")) {
attr &= ~PSETTINGS_ATTR_INDEX;
attr |= PSETTINGS_ATTR_NOOP;
} else if (!str_casecmp(buf, "identifier")) {
attr &= ~PSETTINGS_ATTR_INDEX;
attr |= PSETTINGS_ATTR_ID;
} else if (!str_casecmp(buf, "offend")) {
attr &= ~PSETTINGS_ATTR_INDEX;
attr |= PSETTINGS_ATTR_OFF_END;
} else if (!str_casecmp(buf, "title")) {
attr &= ~PSETTINGS_ATTR_INDEX;
attr |= PSETTINGS_ATTR_TITLE;
} else {
ERROR("expected true, false, binary or identifier as "
"value for index attribute");
return 0;
}
} else {
ERROR("expecting parameter value after index attribute");
return 0;
}
} else if (!str_casecmp(buf, "flow")) {
if ((ret = parse(parser, buf, &len, 1)) == MLPARSE_PARAMVAL) {
buf[len] = '\0';
if (!str_casecmp(buf, "true")) {
attr |= PSETTINGS_ATTR_FLOW;
} else if (!str_casecmp(buf, "false")) {
/* do nothing */
} else {
ERROR("expected true or false as value for flow "
"attribute");
return 0;
}
} else {
ERROR("expecting parameter value after flow attribute");
return 0;
}
} else {
ERROR("expected name, index or flow attribute");
return 0;
}
}
/* sanity checks */
if (!tagbuf[0] || ret != MLPARSE_TAG
|| ((buf[len] = '\0'), str_cmp(buf, "/tag"))) {
if (!tagbuf[0]) {
ERROR("name attribute required");
} else {
ERROR("expected '/tag' tag");
}
return 0;
}
/* insert settings for this tag into the table, making sure we don't
* overwrite endtag for this tag if it is set */
if (psettings_type_tags(pset, type, &ptype) == PSETTINGS_OK) {
ex_attr = psettings_type_find(pset, ptype, tagbuf);
attr |= ex_attr & PSETTINGS_ATTR_DOCEND;
if (psettings_set(pset, type, tagbuf, attr) == PSETTINGS_OK) {
/* tag settings created */
return 1;
} else {
ERROR1("couldn't insert tag %s", tagbuf);
return 0;
}
} else {
assert("can't get here" && 0);
return 0;
}
}
static int psettings_read_type(struct psettings *pset,
struct mlparse_wrap *parser, char *buf, char *tagbuf) {
char *endtag = NULL;
enum mime_types type = MIME_TYPE_UNKNOWN_UNKNOWN;
enum psettings_attr def = PSETTINGS_ATTR_INDEX;
enum mlparse_ret ret;
unsigned int len;
/* 'type' tag contains mimetype (required), endtag (optional) and default
* (optional) attributes, followed by a list of 'tag' tags */
while ((ret = parse(parser, buf, &len, 1)) == MLPARSE_PARAM) {
buf[len] = '\0';
if (!str_cmp(buf, "mimetype")) {
if ((ret = parse(parser, buf, &len, 0)) == MLPARSE_PARAMVAL) {
/* save name */
buf[len] = '\0';
str_tolower(buf);
type = mime_type(buf);
} else {
ERROR("expected parameter value for mimetype attribute");
if (endtag) free(endtag);
return 0;
}
} else if (!str_cmp(buf, "endtag")) {
if ((ret = parse(parser, buf, &len, 0)) == MLPARSE_PARAMVAL) {
/* save name */
buf[len] = '\0';
str_tolower(buf);
if (!(endtag = str_dup(buf))) {
ERROR1("no memory to copy '%s' endtag", buf);
if (endtag) free(endtag);
return 0;
}
} else {
ERROR("expected parameter value for mimetype attribute");
if (endtag) free(endtag);
return 0;
}
} else if (!str_cmp(buf, "default")) {
if ((ret = parse(parser, buf, &len, 1)) == MLPARSE_PARAMVAL) {
buf[len] = '\0';
str_tolower(buf);
if (!str_cmp(buf, "true")) {
def = PSETTINGS_ATTR_INDEX;
} else if (!str_cmp(buf, "false")) {
def = 0;
} else {
ERROR1("expected true or false value for default, got '%s'",
buf);
if (endtag) free(endtag);
return 0;
}
} else {
ERROR("expected parameter value for mimetype attribute");
if (endtag) free(endtag);
return 0;
}
} else {
ERROR1("unrecognised attribute '%s' in 'type' tag", buf);
if (endtag) free(endtag);
return 0;
}
}
if (type == MIME_TYPE_UNKNOWN_UNKNOWN) {
ERROR("didn't receive mimetype for 'type' tag");
if (endtag) free(endtag);
return 0;
}
/* insert type and default into psettings */
if (psettings_type_default(pset, type, def) == PSETTINGS_OK) {
/* insert endtag tag if received */
if (endtag) {
/* note that enddoc tag gets DOCEND attribute only */
def = PSETTINGS_ATTR_DOCEND;
if (psettings_set(pset, type, endtag, def) != PSETTINGS_OK) {
ERROR("couldn't set endtag");
free(endtag);
return 0;
}
free(endtag);
}
} else {
ERROR("couldn't insert new mime type");
if (endtag) free(endtag);
return 0;
}
/* process list of 'tag' tags */
while ((ret == MLPARSE_TAG)
&& !str_nncmp(buf, len, "tag", str_len("tag"))) {
if (!psettings_read_tag(pset, parser, type, buf, tagbuf)) {
return 0;
}
ret = parse(parser, buf, &len, 1);
}
if (ret == MLPARSE_TAG && !str_nncmp(buf, len, "/type", str_len("/type"))) {
/* succeeded */
return 1;
} else {
ERROR("unexpected ending of 'type' tag");
return 0;
}
}
struct psettings *psettings_read(FILE *fp, enum psettings_attr def) {
struct psettings *pset;
struct mlparse_wrap *parser;
char buf[WORDLEN + 1];
char tagbuf[WORDLEN + 1];
unsigned int len;
enum mlparse_ret ret;
if ((pset = psettings_new(def))
&& (parser = mlparse_wrap_new_file(WORDLEN, 1024, fp, 1024, 0))) {
/* read initial junk (xml declaration) */
do {
ret = parse(parser, buf, &len, 1);
switch (ret) {
case MLPARSE_TAG:
if (!str_cmp(buf, "?xml")) {
break;
}
/* otherwise fallthrough to error handling */
/* only allow tags, comments whitespace at the start */
default:
mlparse_wrap_delete(parser);
psettings_delete(pset);
return NULL;
}
} while (!((ret == MLPARSE_TAG) && !str_cmp(buf, "?xml")));
/* read initial junk (rest of xml declaration, psettings tag) */
do {
ret = parse(parser, buf, &len, 1);
switch (ret) {
case MLPARSE_PARAM:
case MLPARSE_PARAMVAL:
break;
case MLPARSE_TAG:
if (!str_cmp(buf, "psettings")) {
break;
}
/* otherwise fallthrough to error handling */
/* only allow tags, whitespace at the start */
default:
mlparse_wrap_delete(parser);
psettings_delete(pset);
return NULL;
}
} while (!((ret == MLPARSE_TAG) && !str_cmp(buf, "psettings")));
/* read types */
do {
ret = parse(parser, buf, &len, 1);
switch (ret) {
case MLPARSE_TAG:
buf[len] = '\0';
if (!str_cmp(buf, "type")) {
if (!psettings_read_type(pset, parser, buf, tagbuf)) {
mlparse_wrap_delete(parser);
psettings_delete(pset);
return NULL;
}
break;
} else if (!str_cmp(buf, "/psettings")) {
break;
}
/* otherwise fallthrough to error handling */
/* only allow tags, whitespace at the start */
default:
mlparse_wrap_delete(parser);
psettings_delete(pset);
return NULL;
}
} while (!((ret == MLPARSE_TAG) && !str_cmp(buf, "/psettings")));
/* have read closing junk, now finish file */
do {
ret = parse(parser, buf, &len, 1);
switch (ret) {
case MLPARSE_EOF:
break;
default:
mlparse_wrap_delete(parser);
psettings_delete(pset);
return NULL;
}
} while (ret != MLPARSE_EOF);
mlparse_wrap_delete(parser);
return pset;
} else {
if (pset) {
psettings_delete(pset);
}
return NULL;
}
}
struct tmptag {
char *name;
unsigned int settings;
};
int tmptag_cmp(const void *vone, const void *vtwo) {
const struct tmptag *one = vone,
*two = vtwo;
return str_cmp(one->name, two->name);
}
enum psettings_attr psettings_default(struct psettings *pset) {
return pset->def;
}
enum psettings_ret psettings_write_code(struct psettings *pset, FILE *output) {
unsigned int i;
struct chash_iter *iter;
fprintf(output, "/* code generated by psettings_write_code() to produce a "
"psettings object with \n * default settings */\n\n");
fprintf(output, "#include \"firstinclude.h\"\n");
fprintf(output, "#include <assert.h>\n");
fprintf(output, "#include <stdlib.h>\n\n");
fprintf(output, "#include \"psettings.h\"\n\n");
fprintf(output, "struct psettings *psettings_new_default(enum "
"psettings_attr def) {\n");
fprintf(output, " struct psettings *pset = psettings_new(def);\n");
fprintf(output, " enum psettings_ret ret;\n\n");
fprintf(output, " if (pset) {\n");
/* load index names in object, by iterating over names hashtable. Types
* will have the same numbers as they currently do */
/* iterate over types */
for (i = 0; i < pset->types; i++) {
struct chash *curr = pset->type[i].tags;
struct tmptag *tags = NULL;
if (chash_size(curr) || (pset->type[i].flags & TYPE_FLAG_DEFSET)) {
fprintf(output, " if ((ret = psettings_type_default(pset, "
"%u, %u))\n", i, pset->type[i].def);
fprintf(output, " != PSETTINGS_OK) {\n");
fprintf(output, " psettings_delete(pset);\n");
fprintf(output, " return NULL;\n");
fprintf(output, " }\n");
if ((iter = chash_iter_new(curr))
&& (tags = malloc(sizeof(*tags) * chash_size(curr)))) {
unsigned int j;
const void *key;
unsigned long int *data;
j = 0;
while (chash_iter_ptr_luint_next(iter, &key, &data)
== CHASH_OK) {
assert(j < chash_size(curr));
tags[j].name = (char *) key;
tags[j++].settings = *data;
}
qsort(tags, chash_size(curr), sizeof(*tags), tmptag_cmp);
for (j = 0; j < chash_size(curr); j++) {
fprintf(output, " if ((ret = psettings_set(pset, "
"%u, \"%s\", %u))\n",
i, tags[j].name, tags[j].settings);
fprintf(output, " != PSETTINGS_OK) {\n");
fprintf(output, " psettings_delete(pset);\n");
fprintf(output, " return NULL;\n");
fprintf(output, " }\n");
}
free(tags);
chash_iter_delete(iter);
} else {
if (iter) {
chash_iter_delete(iter);
}
return PSETTINGS_ENOMEM;
}
}
/* otherwise its empty, just ignore it */
}
fprintf(output, " }\n\n");
fprintf(output, " return pset;\n");
fprintf(output, "}\n\n");
fprintf(output, "#ifdef PSETTINGS_DEFAULT_TEST\n\n");
fprintf(output, "int main() {\n");
fprintf(output, " struct psettings *pset "
"= psettings_new_default(PSETTINGS_ATTR_INDEX);\n");
fprintf(output, "\n");
fprintf(output, " psettings_write_code(pset, stdout);\n\n");
fprintf(output, " psettings_delete(pset);\n");
fprintf(output, " return EXIT_SUCCESS;\n\n");
fprintf(output, "}\n\n");
fprintf(output, "#endif\n\n");
return PSETTINGS_OK;
}
#ifdef PSETTINGS_MAIN
int main(int argc, char **argv) {
struct psettings *pset;
FILE *fp,
*outfp;
if (argc > 3) {
fprintf(stderr, "usage: %s [file] [outfile]\n", *argv);
return EXIT_FAILURE;
}
if (argc > 2) {
outfp = fopen(argv[2], "wb");
if (!outfp) {
perror(*argv);
return EXIT_FAILURE;
}
} else {
outfp = stdout;
}
if (argc > 1) {
fp = fopen(argv[1], "rb");
if (!fp) {
perror(*argv);
fclose(outfp);
return EXIT_FAILURE;
}
} else {
fp = stdin;
}
if ((pset = psettings_read(fp, PSETTINGS_ATTR_INDEX))) {
fclose(fp);
psettings_write_code(pset, outfp);
fclose(outfp);
psettings_delete(pset);
return EXIT_SUCCESS;
} else {
fclose(fp);
fclose(outfp);
fprintf(stderr, "failed to create psettings object from stream\n");
return EXIT_FAILURE;
}
}
#endif