1 :
2 : /* this parses and dumps a conf.c configuration ... */
3 :
4 : #define EX_UTILS_NO_USE_INPUT 1
5 : #define EX_UTILS_NO_USE_LIMIT 1
6 : #define EX_UTILS_NO_USE_OPEN 1
7 : #include "ex_utils.h"
8 :
9 : #include "conf.h"
10 :
11 : #include "mk.h"
12 :
13 : MALLOC_CHECK_DECL();
14 :
15 : int main(int argc, char *argv[])
16 56 : {
17 56 : Vstr_base *out = ex_init(NULL);
18 56 : Vstr_base *s1 = NULL;
19 56 : Conf_parse *conf = conf_parse_make(NULL);
20 56 : Conf_token token[1] = {CONF_TOKEN_INIT};
21 56 : int ret = 0;
22 :
23 56 : if (argc != 2)
24 0 : errx(EXIT_FAILURE, "args");
25 :
26 56 : if (!conf)
27 0 : errx(EXIT_FAILURE, "conf_parse_make()");
28 :
29 56 : s1 = conf->data;
30 56 : if (!vstr_sc_read_len_file(s1, 0, argv[1], 0, 0, NULL))
31 0 : errx(EXIT_FAILURE, "read(%s)", argv[1]);
32 :
33 56 : if (!conf_parse_lex(conf, 1, conf->data->len))
34 : {
35 0 : conf_parse_backtrace(out, argv[1], conf, token);
36 0 : vstr_add_cstr_ptr(out, out->len, "\n");
37 : }
38 : else
39 10448 : while (conf_parse_token(conf, token))
40 : {
41 10364 : const Vstr_sect_node *val = NULL;
42 :
43 10364 : if (token->type > CONF_TOKEN_TYPE_SYMBOL)
44 : {
45 0 : vstr_add_rep_chr(out, out->len, ' ', token->depth_num << 1);
46 0 : vstr_add_fmt(out, out->len, "%u. (%s %d)\n",
47 : token->num, conf_token_name(token),
48 : token->type - CONF_TOKEN_TYPE_SYMBOL);
49 : }
50 10364 : else if (!(val = conf_token_value(token)))
51 : {
52 1916 : vstr_add_rep_chr(out, out->len, ' ', (token->depth_num - 1) << 1);
53 1916 : vstr_add_fmt(out, out->len, "%u. [%s]\n",
54 : token->num, conf_token_name(token));
55 : }
56 : else
57 : {
58 8448 : vstr_add_rep_chr(out, out->len, ' ', token->depth_num << 1);
59 8448 : vstr_add_fmt(out, out->len, "%u. <%s> = ",
60 : token->num, conf_token_name(token));
61 8448 : vstr_add_vstr(out, out->len, s1, val->pos, val->len, 0);
62 8448 : vstr_add_cstr_buf(out, out->len, "\n");
63 : }
64 : }
65 :
66 56 : if (out->conf->malloc_bad)
67 0 : errno = ENOMEM, err(EXIT_FAILURE, "print");
68 :
69 56 : io_put_all(out, STDOUT_FILENO);
70 :
71 56 : conf_parse_free(conf);
72 :
73 56 : ret = ex_exit(out, NULL);
74 :
75 28 : MALLOC_CHECK_EMPTY();
76 :
77 56 : exit (ret);
78 : }
|