aboutsummaryrefslogtreecommitdiff
path: root/tests/gcffmt.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/gcffmt.c')
-rw-r--r--tests/gcffmt.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/gcffmt.c b/tests/gcffmt.c
new file mode 100644
index 0000000..cc67b9a
--- /dev/null
+++ b/tests/gcffmt.c
@@ -0,0 +1,67 @@
1/* grecs - Gray's Extensible Configuration System
2 Copyright (C) 2007-2011 Sergey Poznyakoff
3
4 Grecs is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the
6 Free Software Foundation; either version 3 of the License, or (at your
7 option) any later version.
8
9 Grecs is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with Grecs. If not, see <http://www.gnu.org/licenses/>. */
16
17#ifdef HAVE_CONFIG_H
18# include <config.h>
19#endif
20#include <string.h>
21#include <errno.h>
22#include "grecs.h"
23
24static void
25usage(const char *arg, FILE *fp, int code)
26{
27 fprintf(fp, "usage: %s [-h] [-locus] [-delim=char] file\n", arg);
28 exit(code);
29}
30
31int
32main(int argc, char **argv)
33{
34 char *progname = argv[0];
35 char *file = NULL;
36 struct grecs_node *tree, *node;
37 int flags = 0;
38
39 while (--argc) {
40 char *arg = *++argv;
41 if (strcmp(arg, "-locus") == 0)
42 flags |= GRECS_NODE_FLAG_LOCUS;
43 else if (strncmp(arg, "-delim=", 7) == 0)
44 flags |= arg[7];
45 else if (strcmp(arg, "-h") == 0)
46 usage(progname, stdout, 0);
47 else if (arg[0] == '-')
48 usage(progname, stderr, 1);
49 else if (file)
50 usage(progname, stderr, 1);
51 else
52 file = arg;
53 }
54
55 if (!file || argc)
56 usage(progname, stderr, 1);
57
58 tree = grecs_parse(file);
59 if (!tree)
60 exit(1);
61
62 for (node = tree; node; node = node->next) {
63 grecs_format_node(node, flags, stdout);
64 fputc('\n', stdout);
65 }
66 exit(0);
67}

Return to:

Send suggestions and report system problems to the System administrator.