1 /* grecs - Gray's Extensible Configuration System
2 Copyright (C) 2007-2016 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 <stdlib.h>
21 #include <strings.h>
22 #include <errno.h>
23 #include "grecs.h"
24
25 static struct parser_tab {
26 const char *name;
27 grecs_parser_t parser;
28 } parser_tab[] = {
29 { "GRECS", grecs_grecs_parser },
30 { "PATH", grecs_path_parser },
31 #ifdef ENABLE_META1_PARSER
32 { "META1", grecs_meta1_parser },
33 #endif
34 #ifdef ENABLE_BIND_PARSER
35 { "BIND", grecs_bind_parser },
36 #endif
37 #ifdef ENABLE_DHCPD_PARSER
38 { "DHCPD", grecs_dhcpd_parser },
39 { "DHCP", grecs_dhcpd_parser },
40 #endif
41 #ifdef ENABLE_GIT_PARSER
42 { "GIT", grecs_git_parser },
43 #endif
44 { NULL }
45 };
46
47 int
grecs_enumerate_parsers(int (* fun)(const char *,grecs_parser_t,void *),void * data)48 grecs_enumerate_parsers(int (*fun)(const char *, grecs_parser_t, void *),
49 void *data)
50 {
51 struct parser_tab *pt;
52 int rc = 0;
53
54 for (pt = parser_tab; rc == 0 && pt->name; pt++)
55 rc = fun(pt->name, pt->parser, data);
56 return rc;
57 }
58
59 grecs_parser_t
grecs_get_parser_by_type(const char * type)60 grecs_get_parser_by_type(const char *type)
61 {
62 struct parser_tab *pt;
63
64 for (pt = parser_tab; pt->name; pt++) {
65 if (strcasecmp(pt->name, type) == 0)
66 return pt->parser;
67 }
68 return NULL;
69 }
70
71