summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--Makefile.am2
-rw-r--r--am/grecs.m416
-rw-r--r--configure.ac2
-rw-r--r--include/Makefile.am19
-rw-r--r--include/grecs.h40
-rw-r--r--include/grecs/.gitignore1
-rw-r--r--include/grecs/Makefile.am43
-rw-r--r--include/grecs/doc.h32
-rw-r--r--include/grecs/error.h38
-rw-r--r--include/grecs/format.h62
-rw-r--r--include/grecs/json.h (renamed from src/json.h)0
-rw-r--r--include/grecs/lex.h51
-rw-r--r--include/grecs/list.h55
-rw-r--r--include/grecs/locus.h (renamed from src/grecs-locus.h)23
-rw-r--r--include/grecs/mem.h33
-rw-r--r--include/grecs/node.h62
-rw-r--r--include/grecs/opt.h (renamed from src/grecsopt.h)4
-rw-r--r--include/grecs/parser.h53
-rw-r--r--include/grecs/preproc.h46
-rw-r--r--include/grecs/sockaddr.h66
-rw-r--r--include/grecs/symtab.h52
-rw-r--r--include/grecs/table.h98
-rw-r--r--include/grecs/tree.h71
-rw-r--r--include/grecs/txtacc.h36
-rw-r--r--include/grecs/types.h.in24
-rw-r--r--include/grecs/util.h26
-rw-r--r--include/grecs/value.h52
-rw-r--r--include/grecs/version.h40
-rw-r--r--include/wordsplit.h (renamed from src/wordsplit.h)0
-rw-r--r--src/Make-inst.am1
-rw-r--r--src/Make-shared.am6
-rw-r--r--src/Make-static.am1
-rw-r--r--src/Make.am14
-rw-r--r--src/bind-gram.y1
-rw-r--r--src/bind-lex.l1
-rw-r--r--src/cidr.c1
-rw-r--r--src/dhcpd-gram.y1
-rw-r--r--src/dhcpd-lex.l1
-rw-r--r--src/diag.c1
-rw-r--r--src/format.c2
-rw-r--r--src/grecs-gram.y1
-rw-r--r--src/grecs-lex.l1
-rw-r--r--src/grecs.hin584
-rw-r--r--src/json-gram.y4
-rw-r--r--src/json-lex.l3
-rw-r--r--src/jsonfmt.c3
-rw-r--r--src/lookup.c3
-rw-r--r--src/meta1-gram.y1
-rw-r--r--src/meta1-lex.l1
-rw-r--r--src/opthelp.c2
-rw-r--r--src/preproc.c3
-rw-r--r--src/sockaddr.c1
-rw-r--r--src/txtacc.c3
-rw-r--r--src/version.c1
-rw-r--r--tests/gcfenum.c1
-rw-r--r--tests/gcffmt.c1
-rw-r--r--tests/gcfpeek.c1
-rw-r--r--tests/gcfset.c1
-rw-r--r--tests/gcfver.c1
-rw-r--r--tests/json.c3
60 files changed, 1067 insertions, 629 deletions
diff --git a/Makefile.am b/Makefile.am
index e499bb4..3eaa8df 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -17,3 +17,3 @@
17ACLOCAL_AMFLAGS = -I am 17ACLOCAL_AMFLAGS = -I am
18SUBDIRS=. src @GRECS_TESTDIR@ @GRECS_DOCDIR@ 18SUBDIRS=. include src @GRECS_TESTDIR@ @GRECS_DOCDIR@
19EXTRA_DIST=build-aux/yyrename @GRECS_BUILD_AUX@ @GRECS_DISTDOC@ gitid.h 19EXTRA_DIST=build-aux/yyrename @GRECS_BUILD_AUX@ @GRECS_DISTDOC@ gitid.h
diff --git a/am/grecs.m4 b/am/grecs.m4
index 74b7840..60244a1 100644
--- a/am/grecs.m4
+++ b/am/grecs.m4
@@ -204,3 +204,3 @@ AC_DEFUN([GRECS_SETUP],[
204 AC_SUBST([GRECS_README]) 204 AC_SUBST([GRECS_README])
205 AC_SUBST([GRECS_INCLUDES],['-I$(top_srcdir)/]grecsdir[src] [-I$(top_builddir)/]grecsdir[src]') 205 AC_SUBST([GRECS_INCLUDES],['-I$(top_srcdir)/]grecsdir[include] [-I$(top_builddir)/]grecsdir[include]')
206 AC_SUBST([GRECS_HOST_PROJECT_INCLUDES]) 206 AC_SUBST([GRECS_HOST_PROJECT_INCLUDES])
@@ -208,5 +208,6 @@ AC_DEFUN([GRECS_SETUP],[
208 AC_SUBST([GRECS_INCLUDE_DIR],['$(pkgincludedir)']) 208 AC_SUBST([GRECS_INCLUDE_DIR],['$(pkgincludedir)'])
209 209
210 _GRECS_OPTION_SWITCH([install],[ 210 _GRECS_OPTION_SWITCH([install],[
211 LT_INIT 211 LT_INIT
212 GRECS_BUILD_TYPE=install
212 GRECS_LDADD=['$(top_builddir)/]grecsdir[src/libgrecs.la'] 213 GRECS_LDADD=['$(top_builddir)/]grecsdir[src/libgrecs.la']
@@ -220,2 +221,3 @@ AC_DEFUN([GRECS_SETUP],[
220 LT_INIT 221 LT_INIT
222 GRECS_BUILD_TYPE=shared
221 GRECS_LDADD=['$(top_builddir)/]grecsdir[src/libgrecs.la'] 223 GRECS_LDADD=['$(top_builddir)/]grecsdir[src/libgrecs.la']
@@ -226,2 +228,3 @@ AC_DEFUN([GRECS_SETUP],[
226 ],[ 228 ],[
229 GRECS_BUILD_TYPE=static
227 GRECS_LDADD=['$(top_builddir)/]grecsdir[src/libgrecs.a'] 230 GRECS_LDADD=['$(top_builddir)/]grecsdir[src/libgrecs.a']
@@ -232,3 +235,10 @@ AC_DEFUN([GRECS_SETUP],[
232 ]) 235 ])
233 AC_CONFIG_FILES(grecsdir[Makefile] grecsdir[src/grecs.h]:grecsdir[src/grecs.hin]) 236 AM_CONDITIONAL([GRECS_COND_BUILD_INSTALL],[test $GRECS_BUILD_TYPE = install])
237 AM_CONDITIONAL([GRECS_COND_BUILD_SHARED],[test $GRECS_BUILD_TYPE = shared])
238 AM_CONDITIONAL([GRECS_COND_BUILD_STATIC],[test $GRECS_BUILD_TYPE = static])
239
240 AC_CONFIG_FILES(grecsdir[Makefile]
241 grecsdir[include/Makefile]
242 grecsdir[include/grecs/Makefile]
243 grecsdir[include/grecs/types.h]:grecsdir[include/grecs/types.h.in])
234 m4_popdef([grecsdir]) 244 m4_popdef([grecsdir])
diff --git a/configure.ac b/configure.ac
index b923c9b..6ffa55b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -18,3 +18,3 @@ AC_PREREQ(2.63)
18AC_INIT([libgrecs], [1.0], [gray+grecs@gnu.org.ua]) 18AC_INIT([libgrecs], [1.0], [gray+grecs@gnu.org.ua])
19AC_CONFIG_SRCDIR([src/grecs.hin]) 19AC_CONFIG_SRCDIR([src/grecs-gram.y])
20AC_CONFIG_AUX_DIR([build-aux]) 20AC_CONFIG_AUX_DIR([build-aux])
diff --git a/include/Makefile.am b/include/Makefile.am
new file mode 100644
index 0000000..21a51e7
--- a/dev/null
+++ b/include/Makefile.am
@@ -0,0 +1,19 @@
1SUBDIRS = grecs
2GRECS_HDR = grecs.h wordsplit.h
3
4if GRECS_COND_BUILD_INSTALL
5 include_HEADERS = $(GRECS_HDR)
6endif
7
8if GRECS_COND_BUILD_SHARED
9 if GRECS_COND_INSTALLHEADERS
10 grecsincludedir = @GRECS_INCLUDE_DIR@
11 grecsinclude_HEADERS = $(GRECS_HDR)
12 else
13 noinst_HEADERS = $(GRECS_HDR)
14 endif
15endif
16
17if GRECS_COND_BUILD_STATIC
18 noinst_HEADERS = $(GRECS_HDR)
19endif
diff --git a/include/grecs.h b/include/grecs.h
new file mode 100644
index 0000000..eac11d4
--- a/dev/null
+++ b/include/grecs.h
@@ -0,0 +1,40 @@
1/* grecs - Gray's Extensible Configuration System -*- c -*-
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#ifndef _GRECS_H
18#define _GRECS_H
19
20#include <grecs/types.h>
21#include <grecs/version.h>
22#include <grecs/doc.h>
23#include <grecs/error.h>
24#include <grecs/format.h>
25#include <grecs/lex.h>
26#include <grecs/list.h>
27#include <grecs/locus.h>
28#include <grecs/mem.h>
29#include <grecs/node.h>
30#include <grecs/parser.h>
31#include <grecs/preproc.h>
32#include <grecs/sockaddr.h>
33#include <grecs/symtab.h>
34#include <grecs/table.h>
35#include <grecs/tree.h>
36#include <grecs/txtacc.h>
37#include <grecs/util.h>
38#include <grecs/value.h>
39
40#endif
diff --git a/include/grecs/.gitignore b/include/grecs/.gitignore
new file mode 100644
index 0000000..8cb8a05
--- a/dev/null
+++ b/include/grecs/.gitignore
@@ -0,0 +1 @@
types.h
diff --git a/include/grecs/Makefile.am b/include/grecs/Makefile.am
new file mode 100644
index 0000000..c239c1b
--- a/dev/null
+++ b/include/grecs/Makefile.am
@@ -0,0 +1,43 @@
1GRECS_PKG_HDR =\
2 doc.h\
3 error.h\
4 format.h\
5 lex.h\
6 list.h\
7 locus.h\
8 mem.h\
9 node.h\
10 opt.h\
11 parser.h\
12 preproc.h\
13 sockaddr.h\
14 symtab.h\
15 table.h\
16 tree.h\
17 txtacc.h\
18 types.h\
19 util.h\
20 value.h\
21 version.h
22
23if GRECS_COND_JSON
24 GRECS_PKG_HDR += json.h
25endif
26
27if GRECS_COND_BUILD_INSTALL
28 grecsincludedir = @GRECS_INCLUDE_DIR@
29 grecsinclude_HEADERS = $(GRECS_PKG_HDR)
30endif
31
32if GRECS_COND_BUILD_SHARED
33 if GRECS_COND_INSTALLHEADERS
34 grecsincludedir = @GRECS_INCLUDE_DIR@
35 grecsinclude_HEADERS = $(GRECS_PKG_HDR)
36 else
37 noinst_HEADERS = $(GRECS_PKG_HDR)
38 endif
39endif
40
41if GRECS_COND_BUILD_STATIC
42 noinst_HEADERS = $(GRECS_PKG_HDR)
43endif
diff --git a/include/grecs/doc.h b/include/grecs/doc.h
new file mode 100644
index 0000000..b2514fb
--- a/dev/null
+++ b/include/grecs/doc.h
@@ -0,0 +1,32 @@
1/* grecs - Gray's Extensible Configuration System -*- c -*-
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#ifndef _GRECS_DOC_H
18#define _GRECS_DOC_H
19
20#include <stdio.h>
21#include <grecs/table.h>
22
23void grecs_print_docstring(const char *docstring, unsigned level,
24 FILE *stream);
25void grecs_print_simple_statement(struct grecs_keyword *kwp,
26 unsigned level, FILE *stream);
27void grecs_print_block_statement(struct grecs_keyword *kwp,
28 unsigned level, FILE *stream);
29void grecs_print_statement_array(struct grecs_keyword *kwp,
30 unsigned n,
31 unsigned level, FILE *stream);
32#endif
diff --git a/include/grecs/error.h b/include/grecs/error.h
new file mode 100644
index 0000000..8630b8a
--- a/dev/null
+++ b/include/grecs/error.h
@@ -0,0 +1,38 @@
1/* grecs - Gray's Extensible Configuration System -*- c -*-
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#ifndef _GRECS_ERROR_H
18#define _GRECS_ERROR_H
19
20#include <grecs/locus.h>
21
22extern int grecs_log_to_stderr;
23extern void (*grecs_log_setup_hook)(void);
24
25extern void (*grecs_print_diag_fun)(grecs_locus_t const *, int, int,
26 const char*);
27
28void grecs_warning(grecs_locus_t const *locus,
29 int errcode, const char *fmt, ...)
30 __attribute__ ((__format__ (__printf__, 3, 4)));
31void grecs_error(grecs_locus_t const *locus, int errcode,
32 const char *fmt, ...)
33 __attribute__ ((__format__ (__printf__, 3, 4)));
34
35int grecs_asprint_locus(char **locstr, size_t *size,
36 grecs_locus_t const *locus);
37
38#endif
diff --git a/include/grecs/format.h b/include/grecs/format.h
new file mode 100644
index 0000000..7ac8458
--- a/dev/null
+++ b/include/grecs/format.h
@@ -0,0 +1,62 @@
1/* grecs - Gray's Extensible Configuration System -*- c -*-
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#ifndef _GRECS_FORMAT_H
18#define _GRECS_FORMAT_H
19
20#include <grecs/value.h>
21#include <grecs/locus.h>
22#include <grecs/node.h>
23#include <grecs/txtacc.h>
24
25struct grecs_format_closure {
26 int (*fmtfun)(const char *, void *);
27 void *data;
28};
29
30void grecs_format_locus(grecs_locus_t *locus, struct grecs_format_closure *fp);
31void grecs_format_node_path(struct grecs_node *node, int flag,
32 struct grecs_format_closure *fp);
33void grecs_format_value(struct grecs_value *val, int flags,
34 struct grecs_format_closure *fp);
35
36#define GRECS_NODE_FLAG_PATH 0x00100
37#define GRECS_NODE_FLAG_VALUE 0x00200
38#define GRECS_NODE_FLAG_DESCEND 0x01000
39#define GRECS_NODE_FLAG_LOCUS 0x02000
40#define GRECS_NODE_FLAG_QUOTE 0x04000
41#define GRECS_NODE_FLAG_NOQUOTE 0x08000
42#define GRECS_NODE_FLAG_QUOTE_HEX 0x10000
43
44#define _GRECS_NODE_MASK_DELIM 0x000ff
45#define _GRECS_NODE_MASK_OUTPUT 0x00f00
46
47#define GRECS_NODE_FLAG_DEFAULT \
48 (GRECS_NODE_FLAG_PATH|GRECS_NODE_FLAG_VALUE|\
49 GRECS_NODE_FLAG_DESCEND|GRECS_NODE_FLAG_QUOTE)
50int grecs_format_node(struct grecs_node *node, int flags,
51 struct grecs_format_closure *fp);
52
53void grecs_print_locus(grecs_locus_t *locus, FILE *fp);
54void grecs_print_node_path(struct grecs_node *node, int flag, FILE *fp);
55void grecs_print_value(struct grecs_value *val, int flags, FILE *fp);
56
57int grecs_print_node(struct grecs_node *node, int flags, FILE *fp);
58
59void grecs_txtacc_format_value(struct grecs_value *val, int flags,
60 grecs_txtacc_t acc);
61
62#endif
diff --git a/src/json.h b/include/grecs/json.h
index f8402e7..f8402e7 100644
--- a/src/json.h
+++ b/include/grecs/json.h
diff --git a/include/grecs/lex.h b/include/grecs/lex.h
new file mode 100644
index 0000000..fe2365f
--- a/dev/null
+++ b/include/grecs/lex.h
@@ -0,0 +1,51 @@
1/* grecs - Gray's Extensible Configuration System -*- c -*-
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#ifndef _GRECS_LEX_H
18#define _GRECS_LEX_H
19
20int grecs_lex_begin(const char*, int);
21void grecs_lex_end(int err);
22
23char *grecs_install_text(const char *str);
24void grecs_destroy_text(void);
25struct grecs_symtab *grecs_text_table(void);
26
27void grecs_parse_line_directive(char *text, grecs_locus_t *ploc,
28 struct grecs_locus_point *ppoint,
29 size_t *pxlines);
30void grecs_parse_line_directive_cpp(char *text, grecs_locus_t *ploc,
31 struct grecs_locus_point *ppoint,
32 size_t *pxlines);
33
34void grecs_line_acc_create(void);
35void grecs_line_acc_free(void);
36void grecs_line_acc_grow_char(int c);
37void grecs_line_acc_grow_char_unescape(int c);
38void grecs_line_acc_grow(const char *text, size_t len);
39void grecs_line_acc_grow_unescape_last(char *text, size_t len);
40
41void grecs_line_begin(void);
42#define grecs_line_add grecs_line_acc_grow
43char *grecs_line_finish(void);
44
45int grecs_str_is_ipv4(const char *addr);
46int grecs_str_is_num(const char *s);
47int grecs_str_is_ipv6(const char *addr);
48int grecs_str_is_num(const char *s);
49int grecs_str_is_ipaddr(const char *addr);
50
51#endif
diff --git a/include/grecs/list.h b/include/grecs/list.h
new file mode 100644
index 0000000..efccd56
--- a/dev/null
+++ b/include/grecs/list.h
@@ -0,0 +1,55 @@
1/* grecs - Gray's Extensible Configuration System -*- c -*-
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#ifndef _GRECS_LIST_H
18#define _GRECS_LIST_H
19
20typedef struct grecs_list_entry *grecs_list_entry_t;
21typedef struct grecs_list *grecs_list_t;
22
23struct grecs_list_entry {
24 struct grecs_list_entry *next, *prev;
25 void *data;
26};
27
28struct grecs_list {
29 struct grecs_list_entry *head, *tail;
30 size_t count;
31 int (*cmp)(const void *, const void *);
32 void (*free_entry)(void *);
33};
34
35grecs_list_t grecs_list_create(void);
36size_t grecs_list_size(grecs_list_t);
37void grecs_list_append(grecs_list_t, void *);
38void grecs_list_push(grecs_list_t, void *);
39void *grecs_list_pop(grecs_list_t);
40void *grecs_list_locate(grecs_list_t, void *);
41void *grecs_list_index(grecs_list_t, size_t);
42void *grecs_list_remove_tail(grecs_list_t);
43void grecs_list_remove_entry(grecs_list_t, grecs_list_entry_t);
44void grecs_list_clear(grecs_list_t);
45void grecs_list_free(grecs_list_t);
46void grecs_list_add(grecs_list_t, grecs_list_t);
47
48/* FIXME */
49struct grecs_list *_grecs_simple_list_create(int dispose);
50struct grecs_list *grecs_value_list_create(void);
51
52
53
54
55#endif
diff --git a/src/grecs-locus.h b/include/grecs/locus.h
index b5573fd..4ca6d21 100644
--- a/src/grecs-locus.h
+++ b/include/grecs/locus.h
@@ -16,2 +16,24 @@
16 16
17#ifndef _GRECS_LOCUS_H
18#define _GRECS_LOCUS_H
19
20struct grecs_locus_point {
21 char *file;
22 unsigned line;
23 unsigned col;
24};
25
26 #define grecs_locus_point_advance_line(loc) do {\
27 (loc).line++; \
28 (loc).col = 0; \
29 } while (0)
30
31#define GRECS_LOCUS_POINT_EQ(a,b) \
32 ((strcmp((a)->file, (b)->file) == 0) && ((a)->line == (b)->line))
33
34typedef struct grecs_locus {
35 struct grecs_locus_point beg;
36 struct grecs_locus_point end;
37} grecs_locus_t;
38
17#define YYLTYPE grecs_locus_t 39#define YYLTYPE grecs_locus_t
@@ -57 +79,2 @@
57 79
80#endif
diff --git a/include/grecs/mem.h b/include/grecs/mem.h
new file mode 100644
index 0000000..de46b32
--- a/dev/null
+++ b/include/grecs/mem.h
@@ -0,0 +1,33 @@
1/* grecs - Gray's Extensible Configuration System -*- c -*-
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#ifndef _GRECS_MEM_H
18#define _GRECS_MEM_H
19
20extern void *(*grecs_malloc_fun)(size_t size);
21extern void *(*grecs_realloc_fun)(void *ptr, size_t size);
22extern void (*grecs_alloc_die_fun)(void);
23extern void (*grecs_free_fun)(void *ptr);
24
25void *grecs_malloc(size_t size);
26void *grecs_zalloc(size_t size);
27void *grecs_calloc(size_t nmemb, size_t size);
28void *grecs_realloc(void *ptr, size_t size);
29void grecs_alloc_die(void);
30char *grecs_strdup(const char *str);
31void grecs_free(void *ptr);
32
33#endif
diff --git a/include/grecs/node.h b/include/grecs/node.h
new file mode 100644
index 0000000..5bbe9dc
--- a/dev/null
+++ b/include/grecs/node.h
@@ -0,0 +1,62 @@
1/* grecs - Gray's Extensible Configuration System -*- c -*-
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#ifndef _GRECS_NODE_H
18#define _GRECS_NODE_H
19
20#include <grecs/locus.h>
21#include <grecs/symtab.h>
22#include <grecs/value.h>
23
24enum grecs_node_type {
25 grecs_node_root,
26 grecs_node_stmt,
27 grecs_node_block
28};
29
30typedef struct grecs_node {
31 enum grecs_node_type type;
32 grecs_locus_t locus;
33 struct grecs_node *up;
34 struct grecs_node *down;
35 struct grecs_node *next;
36 struct grecs_node *prev;
37 char *ident;
38 grecs_locus_t idloc;
39 union {
40 grecs_value_t *value;
41 grecs_symtab_t texttab;
42 } v;
43} grecs_node_t;
44
45void grecs_node_free(struct grecs_node *node);
46struct grecs_node *grecs_node_create(enum grecs_node_type type,
47 grecs_locus_t *loc);
48struct grecs_node *grecs_node_create_points(enum grecs_node_type type,
49 struct grecs_locus_point beg,
50 struct grecs_locus_point end);
51void grecs_node_bind(struct grecs_node *master, struct grecs_node *node,
52 int dn);
53int grecs_node_eq(struct grecs_node *a, struct grecs_node *b);
54int grecs_node_unlink(struct grecs_node *node);
55
56struct grecs_node *grecs_node_from_path(const char *path, const char *value);
57struct grecs_node *grecs_node_from_path_locus(const char *path,
58 const char *value,
59 grecs_locus_t *locus,
60 grecs_locus_t *vallocus);
61
62#endif
diff --git a/src/grecsopt.h b/include/grecs/opt.h
index 49c0b53..5153033 100644
--- a/src/grecsopt.h
+++ b/include/grecs/opt.h
@@ -16,4 +16,4 @@
16 16
17#ifndef _GRECSOPT_H 17#ifndef _GRECS_OPT_H
18#define _GRECSOPT_H 18#define _GRECS_OPT_H
19 19
diff --git a/include/grecs/parser.h b/include/grecs/parser.h
new file mode 100644
index 0000000..00878f4
--- a/dev/null
+++ b/include/grecs/parser.h
@@ -0,0 +1,53 @@
1/* grecs - Gray's Extensible Configuration System -*- c -*-
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#ifndef _GRECS_PARSER_H
18#define _GRECS_PARSER_H
19
20typedef struct grecs_node *(*grecs_parser_t)(const char *name, int trace);
21
22#define GRECS_TRACE_GRAM 0x01
23#define GRECS_TRACE_LEX 0x02
24
25extern int grecs_trace_flags;
26extern grecs_parser_t grecs_parser_fun;
27extern int grecs_default_port;
28
29extern struct grecs_locus_point grecs_current_locus_point;
30extern grecs_locus_t grecs_locus;
31extern int grecs_adjust_string_locations;
32extern int grecs_error_count;
33
34/* Main entry point */
35struct grecs_node *grecs_parse(const char *name);
36void grecs_gram_trace(int n);
37void grecs_lex_trace(int n);
38
39/* Parsers: */
40struct grecs_node *grecs_grecs_parser(const char *name, int traceflags);
41struct grecs_node *grecs_meta1_parser(const char *name, int traceflags);
42struct grecs_node *grecs_bind_parser(const char *name, int traceflags);
43struct grecs_node *grecs_dhcpd_parser(const char *name, int traceflags);
44struct grecs_node *grecs_git_parser(const char *name, int traceflags);
45struct grecs_node *grecs_path_parser(const char *name, int traceflags);
46
47
48/* Parser database */
49int grecs_enumerate_parsers(int (*fun)(const char *, grecs_parser_t, void *),
50 void *);
51grecs_parser_t grecs_get_parser_by_type(const char *type);
52
53#endif
diff --git a/include/grecs/preproc.h b/include/grecs/preproc.h
new file mode 100644
index 0000000..798e879
--- a/dev/null
+++ b/include/grecs/preproc.h
@@ -0,0 +1,46 @@
1/* grecs - Gray's Extensible Configuration System -*- c -*-
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#ifndef _GRECS_PREPROC_H
18#define _GRECS_PREPROC_H
19
20#include <sys/types.h>
21
22extern const char *grecs_preprocessor;
23
24size_t grecs_preproc_fill_buffer(char *buf, size_t size);
25void grecs_preproc_add_include_dir(char *dir);
26int grecs_preproc_init(const char *name);
27void grecs_preproc_done(void);
28int grecs_preproc_run(const char *config_file, const char *extpp);
29
30#define GRECS_STD_INCLUDE 0x01
31#define GRECS_USR_INCLUDE 0x02
32
33size_t grecs_include_path_count(int flag);
34int grecs_foreach_include_dir(int flag, int (*fun)(int, const char *, void *),
35 void *data);
36
37char *grecs_find_include_file(const char *name, int allow_cwd);
38
39FILE *grecs_preproc_extrn_start(const char *file, pid_t *ppid);
40void grecs_preproc_extrn_shutdown(pid_t pid);
41
42void grecs_include_path_clear(void);
43void grecs_include_path_setup(const char *dir, ...);
44void grecs_include_path_setup_v(char **dirs);
45
46#endif
diff --git a/include/grecs/sockaddr.h b/include/grecs/sockaddr.h
new file mode 100644
index 0000000..c8a3de2
--- a/dev/null
+++ b/include/grecs/sockaddr.h
@@ -0,0 +1,66 @@
1/* grecs - Gray's Extensible Configuration System -*- c -*-
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#ifndef _GRECS_SOCKADDR_H
18#define _GRECS_SOCKADDR_H
19
20struct grecs_sockaddr {
21#if GRECS_SOCKADDR_LIST
22 struct grecs_sockaddr *next;
23#endif
24 int len;
25 struct sockaddr *sa;
26};
27
28#if GRECS_SOCKADDR_LIST
29
30#define GRECS_AH_PASSIVE 0x01
31#define GRECS_HINT_SERVICE 0x02
32#define GRECS_HINT_PORT 0x04
33
34struct grecs_sockaddr_hints {
35 int flags;
36 char *service;
37 unsigned short port;
38};
39
40extern struct grecs_sockaddr_hints *grecs_sockaddr_hints;
41
42struct grecs_sockaddr *grecs_sockaddr_new(size_t s);
43void grecs_sockaddr_free(struct grecs_sockaddr *p);
44
45int grecs_str_to_sockaddr(struct grecs_sockaddr **sap,
46 const char *arg, struct grecs_sockaddr_hints *gh,
47 grecs_locus_t const *locus);
48#endif
49
50#define GRECS_INADDR_BYTES 16
51
52struct grecs_cidr
53{
54 int family;
55 int len;
56 unsigned char address[GRECS_INADDR_BYTES];
57 unsigned char netmask[GRECS_INADDR_BYTES];
58};
59
60int grecs_str_to_cidr(struct grecs_cidr *pcidr, const char *str,
61 grecs_locus_t const *locus);
62
63int grecs_sockaddr_to_cidr(struct grecs_cidr *cidr, const struct sockaddr *sa);
64int grecs_sockadd_cidr_match(struct sockaddr *sa, struct grecs_cidr *cidr);
65
66#endif
diff --git a/include/grecs/symtab.h b/include/grecs/symtab.h
new file mode 100644
index 0000000..a4a7106
--- a/dev/null
+++ b/include/grecs/symtab.h
@@ -0,0 +1,52 @@
1/* grecs - Gray's Extensible Configuration System -*- c -*-
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#ifndef _GRECS_SYMTAB_H
18#define _GRECS_SYMTAB_H
19
20typedef struct grecs_symtab *grecs_symtab_t;
21
22struct grecs_syment {
23 char *name;
24};
25
26typedef int (*grecs_symtab_enumerator_t)(void *sym, void *data);
27
28const char *grecs_symtab_strerror(int rc);
29
30void *grecs_symtab_lookup_or_install(grecs_symtab_t st,
31 void *key, int *install);
32void grecs_symtab_clear(grecs_symtab_t st);
33grecs_symtab_t grecs_symtab_create(size_t elsize,
34 unsigned (*hash_fun)(void *, unsigned long),
35 int (*cmp_fun)(const void *, const void *),
36 int (*copy_fun)(void *, void *),
37 void *(*alloc_fun)(size_t),
38 void (*free_fun)(void *));
39grecs_symtab_t grecs_symtab_create_default(size_t elsize);
40
41void grecs_symtab_free(grecs_symtab_t pst);
42int grecs_symtab_remove(grecs_symtab_t st, void *elt);
43int grecs_symtab_replace(grecs_symtab_t st, void *ent, void **old_ent);
44int grecs_symtab_enumerate(grecs_symtab_t st,
45 grecs_symtab_enumerator_t fun, void *data);
46
47size_t grecs_symtab_count_entries(grecs_symtab_t st);
48
49unsigned grecs_hash_string(const char *name, unsigned long hashsize);
50unsigned grecs_hash_string_ci(const char *name, unsigned long hashsize);
51
52#endif
diff --git a/include/grecs/table.h b/include/grecs/table.h
new file mode 100644
index 0000000..4210c6f
--- a/dev/null
+++ b/include/grecs/table.h
@@ -0,0 +1,98 @@
1/* grecs - Gray's Extensible Configuration System -*- c -*-
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#ifndef _GRECS_TABLE_H
18#define _GRECS_TABLE_H
19
20#include <grecs/node.h>
21
22enum grecs_data_type {
23 grecs_type_void,
24 grecs_type_string,
25 grecs_type_short,
26 grecs_type_ushort,
27 grecs_type_int,
28 grecs_type_uint,
29 grecs_type_long,
30 grecs_type_ulong,
31 grecs_type_size,
32/* grecs_type_off,*/
33 grecs_type_time,
34 grecs_type_bool,
35 grecs_type_ipv4,
36 grecs_type_cidr,
37 grecs_type_host,
38 grecs_type_sockaddr,
39 grecs_type_section,
40 grecs_type_null
41};
42
43#define GRECS_DFLT 0x00
44#define GRECS_AGGR 0x01
45#define GRECS_MULT 0x02
46#define GRECS_INAC 0x04
47#define GRECS_LIST 0x08
48#define GRECS_HIDDEN 0x10
49
50enum grecs_callback_command {
51 grecs_callback_section_begin,
52 grecs_callback_section_end,
53 grecs_callback_set_value
54};
55
56typedef int (*grecs_callback_fn)(
57#if GRECS_TREE_API
58 enum grecs_callback_command cmd,
59 grecs_node_t * /* node */,
60 void * /* varptr */,
61 void * /* cb_data */
62#else
63 enum grecs_callback_command cmd,
64 grecs_locus_t * /* locus */,
65 void * /* varptr */,
66 grecs_value_t * /* value */,
67 void * /* cb_data */
68#endif
69 );
70
71struct grecs_keyword {
72 const char *ident;
73 const char *argname;
74 const char *docstring;
75 enum grecs_data_type type;
76 int flags;
77 void *varptr;
78 size_t offset;
79 grecs_callback_fn callback;
80 void *callback_data;
81 struct grecs_keyword *kwd;
82};
83
84extern int grecs_string_convert(void *target, enum grecs_data_type type,
85 const char *string,
86 grecs_locus_t const *locus);
87extern void grecs_process_ident(struct grecs_keyword *kwp,
88 grecs_value_t *value,
89 void *base,
90 grecs_locus_t *locus);
91
92const char *grecs_data_type_string(enum grecs_data_type type);
93
94int grecs_tree_process(struct grecs_node *node, struct grecs_keyword *kwd);
95int grecs_tree_reduce(struct grecs_node *node, struct grecs_keyword *kwd,
96 int flags);
97
98#endif
diff --git a/include/grecs/tree.h b/include/grecs/tree.h
new file mode 100644
index 0000000..2fb26dd
--- a/dev/null
+++ b/include/grecs/tree.h
@@ -0,0 +1,71 @@
1/* grecs - Gray's Extensible Configuration System -*- c -*-
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#ifndef _GRECS_TREE_H
18#define _GRECS_TREE_H
19
20#include <grecs/node.h>
21
22int grecs_tree_free(struct grecs_node *node);
23void grecs_tree_sort(struct grecs_node *node,
24 int (*compare)(struct grecs_node const *,
25 struct grecs_node const *));
26struct grecs_node *grecs_tree_first_node(struct grecs_node *tree);
27struct grecs_node *grecs_next_node(struct grecs_node *node);
28
29struct grecs_node *grecs_find_node(struct grecs_node *node, const char *path);
30
31enum grecs_tree_recurse_op {
32 grecs_tree_recurse_set,
33 grecs_tree_recurse_pre,
34 grecs_tree_recurse_post
35};
36
37enum grecs_tree_recurse_res {
38 grecs_tree_recurse_ok,
39 grecs_tree_recurse_fail,
40 grecs_tree_recurse_skip,
41 grecs_tree_recurse_stop
42};
43
44typedef enum grecs_tree_recurse_res
45 (*grecs_tree_recursor_t)(enum grecs_tree_recurse_op,
46 struct grecs_node *, void *);
47
48int grecs_tree_recurse(struct grecs_node *node, grecs_tree_recursor_t recfun,
49 void *data);
50int grecs_tree_join(struct grecs_node *dst, struct grecs_node *src);
51
52enum grecs_tree_recurse_res grecs_node_exact_match(
53 enum grecs_tree_recurse_op op,
54 struct grecs_node *node, void *data);
55
56typedef struct grecs_match_buf *grecs_match_buf_t;
57struct grecs_node *grecs_match_first(struct grecs_node *tree,
58 const char *pattern,
59 grecs_match_buf_t *buf);
60struct grecs_node *grecs_match_next(struct grecs_match_buf *buf);
61void grecs_match_buf_free(struct grecs_match_buf *buf);
62grecs_match_buf_t grecs_match_buf_create(int argc, char **argv,
63 struct grecs_value **labelv);
64struct grecs_node *grecs_match_buf_first(struct grecs_match_buf *buf,
65 struct grecs_node *tree);
66struct grecs_node *grecs_match_buf_get_node(grecs_match_buf_t buf);
67size_t grecs_match_buf_get_args(grecs_match_buf_t buf, char ***argv);
68struct grecs_node *grecs_match_buf_get_root(grecs_match_buf_t buf);
69void grecs_match_buf_set_root(grecs_match_buf_t buf, struct grecs_node *root);
70
71#endif
diff --git a/include/grecs/txtacc.h b/include/grecs/txtacc.h
new file mode 100644
index 0000000..d6dc1c4
--- a/dev/null
+++ b/include/grecs/txtacc.h
@@ -0,0 +1,36 @@
1/* grecs - Gray's Extensible Configuration System -*- c -*-
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#ifndef _GRECS_TXTACC_H
18#define _GRECS_TXTACC_H
19
20#define GRECS_TXTACC_BUFSIZE 1024
21typedef struct grecs_txtacc *grecs_txtacc_t;
22
23grecs_txtacc_t grecs_txtacc_create(void);
24void grecs_txtacc_free(grecs_txtacc_t);
25void grecs_txtacc_grow(grecs_txtacc_t, const char *, size_t);
26void grecs_txtacc_grow_string(grecs_txtacc_t, const char *);
27void grecs_txtacc_grow_string_escape(grecs_txtacc_t, const char *);
28 #define grecs_txtacc_grow_char(acc,c) \
29 do { \
30 char __ch = c; \
31 grecs_txtacc_grow(acc,&__ch,1);\
32 } while (0)
33char *grecs_txtacc_finish(grecs_txtacc_t, int);
34void grecs_txtacc_free_string(grecs_txtacc_t, char *);
35
36#endif
diff --git a/include/grecs/types.h.in b/include/grecs/types.h.in
new file mode 100644
index 0000000..b891a05
--- a/dev/null
+++ b/include/grecs/types.h.in
@@ -0,0 +1,24 @@
1#ifndef _GRECS_TYPES_H
2#define _GRECS_TYPES_H
3
4#define GRECS_VERSION_MAJOR 1
5#define GRECS_VERSION_MINOR 0
6
7#define GRECS_TREE_API @GRECS_TREE_API@
8#define GRECS_SOCKADDR_LIST @GRECS_SOCKADDR_LIST@
9
10#if ENABLE_NLS
11# include "gettext.h"
12#else
13# ifndef gettext
14# define gettext(msgid) msgid
15# endif
16#endif
17#ifndef _
18# define _(msgid) gettext(msgid)
19#endif
20#ifndef N_
21# define N_(s) s
22#endif
23
24#endif
diff --git a/include/grecs/util.h b/include/grecs/util.h
new file mode 100644
index 0000000..cf3bee1
--- a/dev/null
+++ b/include/grecs/util.h
@@ -0,0 +1,26 @@
1/* grecs - Gray's Extensible Configuration System -*- c -*-
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#ifndef _GRECS_UTIL_H
18#define _GRECS_UTIL_H
19
20#include <stdarg.h>
21
22ssize_t grecs_getline(char **pbuf, size_t *psize, FILE *fp);
23int grecs_vasprintf(char **pbuf, size_t *psize, const char *fmt, va_list ap);
24int grecs_asprintf(char **pbuf, size_t *psize, const char *fmt, ...);
25
26#endif
diff --git a/include/grecs/value.h b/include/grecs/value.h
new file mode 100644
index 0000000..73f979c
--- a/dev/null
+++ b/include/grecs/value.h
@@ -0,0 +1,52 @@
1/* grecs - Gray's Extensible Configuration System -*- c -*-
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#ifndef _GRECS_VALUE_H
18#define _GRECS_VALUE_H
19
20#include <grecs/locus.h>
21#include <grecs/list.h>
22
23#define GRECS_TYPE_STRING 0
24#define GRECS_TYPE_LIST 1
25#define GRECS_TYPE_ARRAY 2
26
27typedef struct grecs_value {
28 int type;
29 grecs_locus_t locus;
30 union {
31 grecs_list_t list;
32 char *string;
33 struct {
34 size_t c;
35 struct grecs_value **v;
36 } arg;
37 } v;
38} grecs_value_t;
39
40#define GRECS_VALUE_EMPTY_P(val) \
41 (!(val) || \
42 ((val)->type == GRECS_TYPE_STRING && (val)->v.string == NULL))
43
44void grecs_value_free(struct grecs_value *val);
45void grecs_value_free_content(struct grecs_value *val);
46grecs_value_t *grecs_value_ptr_from_static(grecs_value_t *input);
47
48int grecs_value_eq(struct grecs_value *a, struct grecs_value *b);
49int grecs_value_match(struct grecs_value *pat, struct grecs_value *b,
50 int flags);
51
52#endif
diff --git a/include/grecs/version.h b/include/grecs/version.h
new file mode 100644
index 0000000..f37adc6
--- a/dev/null
+++ b/include/grecs/version.h
@@ -0,0 +1,40 @@
1/* grecs - Gray's Extensible Configuration System -*- c -*-
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#ifndef _GRECS_VERSION_H
18#define _GRECS_VERSION_H
19
20struct grecs_version_info {
21 const char *package;
22 const char *version;
23 const char *id;
24 int major;
25 int minor;
26 int patch;
27 char *suffix;
28 char *buffer;
29};
30
31struct grecs_version_info *grecs_version(void);
32int grecs_version_cmp(const char *, const char *, int *);
33int grecs_version_ok(const char *);
34void grecs_version_info_free(struct grecs_version_info *);
35struct grecs_version_info *grecs_version_split(const char *);
36int grecs_version_info_cmp(struct grecs_version_info *,
37 struct grecs_version_info *,
38 int *);
39
40#endif
diff --git a/src/wordsplit.h b/include/wordsplit.h
index a7f6dd5..a7f6dd5 100644
--- a/src/wordsplit.h
+++ b/include/wordsplit.h
diff --git a/src/Make-inst.am b/src/Make-inst.am
index 9dac1ad..a4b6aea 100644
--- a/src/Make-inst.am
+++ b/src/Make-inst.am
@@ -19,3 +19,2 @@ lib_LTLIBRARIES=libgrecs.la
19libgrecs_la_SOURCES = $(GRECS_SRC) 19libgrecs_la_SOURCES = $(GRECS_SRC)
20include_HEADERS = $(GRECS_HDR)
21m4datadir = $(datadir)/aclocal 20m4datadir = $(datadir)/aclocal
diff --git a/src/Make-shared.am b/src/Make-shared.am
index 8ec4a76..9a762a4 100644
--- a/src/Make-shared.am
+++ b/src/Make-shared.am
@@ -19,7 +19 @@ libgrecs_la_SOURCES = $(GRECS_SRC)
19
20if GRECS_COND_INSTALLHEADERS
21 grecsincludedir = @GRECS_INCLUDE_DIR@
22 grecsinclude_HEADERS = $(GRECS_HDR)
23else
24 noinst_HEADERS += $(GRECS_HDR)
25endif
diff --git a/src/Make-static.am b/src/Make-static.am
index 7532562..2688b40 100644
--- a/src/Make-static.am
+++ b/src/Make-static.am
@@ -18,3 +18,2 @@ noinst_LIBRARIES=libgrecs.a
18libgrecs_a_SOURCES = $(GRECS_SRC) 18libgrecs_a_SOURCES = $(GRECS_SRC)
19noinst_HEADERS += $(GRECS_HDR)
20 19
diff --git a/src/Make.am b/src/Make.am
index cfae734..227973e 100644
--- a/src/Make.am
+++ b/src/Make.am
@@ -77,7 +77,2 @@ GRECS_SRC = \
77 77
78GRECS_HDR = grecs.h grecsopt.h wordsplit.h
79if GRECS_COND_JSON
80 GRECS_HDR += json.h
81endif
82
83if GRECS_COND_SOCKADDR_LIST 78if GRECS_COND_SOCKADDR_LIST
@@ -86,7 +81,4 @@ endif
86 81
87noinst_HEADERS = grecs-locus.h
88
89EXTRA_DIST=\ 82EXTRA_DIST=\
90 grecs-gram.h\ 83 grecs-gram.h\
91 grecs.hin\
92 $(GRECS_EXTRA_BIND)\ 84 $(GRECS_EXTRA_BIND)\
@@ -98,4 +90,2 @@ EXTRA_DIST=\
98 90
99BUILT_SOURCES=grecs.h
100
101AM_CPPFLAGS = \ 91AM_CPPFLAGS = \
@@ -114 +104,5 @@ LEXCOMPILE = $(top_srcdir)/@GRECS_SUBDIR@/build-aux/yyrename '$(LEX) $(LFLAGS) $
114YACCCOMPILE = $(top_srcdir)/@GRECS_SUBDIR@/build-aux/yyrename '$(YACC) $(YFLAGS) $(AM_YFLAGS)' 104YACCCOMPILE = $(top_srcdir)/@GRECS_SUBDIR@/build-aux/yyrename '$(YACC) $(YFLAGS) $(AM_YFLAGS)'
105
106
107
108
diff --git a/src/bind-gram.y b/src/bind-gram.y
index 4c8d394..18deb0d 100644
--- a/src/bind-gram.y
+++ b/src/bind-gram.y
@@ -21,3 +21,2 @@
21#include <grecs.h> 21#include <grecs.h>
22#include <grecs-locus.h>
23#include <bind-gram.h> 22#include <bind-gram.h>
diff --git a/src/bind-lex.l b/src/bind-lex.l
index 096d1f2..e0659e7 100644
--- a/src/bind-lex.l
+++ b/src/bind-lex.l
@@ -26,3 +26,2 @@
26#include <grecs.h> 26#include <grecs.h>
27#include <grecs-locus.h>
28#include <bind-gram.h> 27#include <bind-gram.h>
diff --git a/src/cidr.c b/src/cidr.c
index bffa35e..7566fa6 100644
--- a/src/cidr.c
+++ b/src/cidr.c
@@ -24,2 +24,3 @@
24#include <arpa/inet.h> 24#include <arpa/inet.h>
25#include <stdlib.h>
25#include "grecs.h" 26#include "grecs.h"
diff --git a/src/dhcpd-gram.y b/src/dhcpd-gram.y
index 86bfde9..11dd1b2 100644
--- a/src/dhcpd-gram.y
+++ b/src/dhcpd-gram.y
@@ -21,3 +21,2 @@
21#include <grecs.h> 21#include <grecs.h>
22#include <grecs-locus.h>
23#include <dhcpd-gram.h> 22#include <dhcpd-gram.h>
diff --git a/src/dhcpd-lex.l b/src/dhcpd-lex.l
index 490fd72..79c7274 100644
--- a/src/dhcpd-lex.l
+++ b/src/dhcpd-lex.l
@@ -25,3 +25,2 @@
25#include <grecs.h> 25#include <grecs.h>
26#include <grecs-locus.h>
27#include <dhcpd-gram.h> 26#include <dhcpd-gram.h>
diff --git a/src/diag.c b/src/diag.c
index 1424437..bdbb407 100644
--- a/src/diag.c
+++ b/src/diag.c
@@ -20,3 +20,2 @@
20#include <grecs.h> 20#include <grecs.h>
21#include <grecs-locus.h>
22#include <stdlib.h> 21#include <stdlib.h>
diff --git a/src/format.c b/src/format.c
index 89202a0..af87329 100644
--- a/src/format.c
+++ b/src/format.c
@@ -20,2 +20,3 @@
20#include <grecs.h> 20#include <grecs.h>
21#include <wordsplit.h>
21#include <stdio.h> 22#include <stdio.h>
@@ -25,3 +26,2 @@
25#include <errno.h> 26#include <errno.h>
26#include "wordsplit.h"
27 27
diff --git a/src/grecs-gram.y b/src/grecs-gram.y
index 4545c85..05ed2f5 100644
--- a/src/grecs-gram.y
+++ b/src/grecs-gram.y
@@ -21,3 +21,2 @@
21#include <grecs.h> 21#include <grecs.h>
22#include <grecs-locus.h>
23#include <grecs-gram.h> 22#include <grecs-gram.h>
diff --git a/src/grecs-lex.l b/src/grecs-lex.l
index 5223765..113ee88 100644
--- a/src/grecs-lex.l
+++ b/src/grecs-lex.l
@@ -26,3 +26,2 @@
26#include <grecs.h> 26#include <grecs.h>
27#include <grecs-locus.h>
28#include <grecs-gram.h> 27#include <grecs-gram.h>
diff --git a/src/grecs.hin b/src/grecs.hin
deleted file mode 100644
index bfaaa49..0000000
--- a/src/grecs.hin
+++ b/dev/null
@@ -1,584 +0,0 @@
1/* grecs - Gray's Extensible Configuration System -*- c -*-
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#ifndef _GRECS_H
18#define _GRECS_H
19
20#include <sys/types.h>
21#include <unistd.h>
22#include <stdlib.h>
23#include <stdio.h>
24#include <stdarg.h>
25
26#if ENABLE_NLS
27# include "gettext.h"
28#else
29# ifndef gettext
30# define gettext(msgid) msgid
31# endif
32#endif
33#ifndef _
34# define _(msgid) gettext(msgid)
35#endif
36#ifndef N_
37# define N_(s) s
38#endif
39
40#define GRECS_VERSION_MAJOR 1
41#define GRECS_VERSION_MINOR 0
42
43#define GRECS_TREE_API @GRECS_TREE_API@
44#define GRECS_SOCKADDR_LIST @GRECS_SOCKADDR_LIST@
45
46struct grecs_version_info {
47 const char *package;
48 const char *version;
49 const char *id;
50 int major;
51 int minor;
52 int patch;
53 char *suffix;
54 char *buffer;
55};
56
57struct grecs_locus_point {
58 char *file;
59 unsigned line;
60 unsigned col;
61};
62
63 #define grecs_locus_point_advance_line(loc) do {\
64 (loc).line++; \
65 (loc).col = 0; \
66 } while (0)
67
68#define GRECS_LOCUS_POINT_EQ(a,b) \
69 ((strcmp((a)->file, (b)->file) == 0) && ((a)->line == (b)->line))
70
71typedef struct grecs_locus {
72 struct grecs_locus_point beg;
73 struct grecs_locus_point end;
74} grecs_locus_t;
75
76extern grecs_locus_t grecs_locus;
77extern int grecs_adjust_string_locations;
78
79enum grecs_data_type {
80 grecs_type_void,
81 grecs_type_string,
82 grecs_type_short,
83 grecs_type_ushort,
84 grecs_type_int,
85 grecs_type_uint,
86 grecs_type_long,
87 grecs_type_ulong,
88 grecs_type_size,
89/* grecs_type_off,*/
90 grecs_type_time,
91 grecs_type_bool,
92 grecs_type_ipv4,
93 grecs_type_cidr,
94 grecs_type_host,
95 grecs_type_sockaddr,
96 grecs_type_section,
97 grecs_type_null
98};
99
100#define GRECS_DFLT 0x00 /* Default keyword flags */
101#define GRECS_AGGR 0x01 /* Multiple entries aggregate */
102#define GRECS_MULT 0x02 /* Statement can appear multiple times */
103#define GRECS_INAC 0x04 /* Inactive keyword */
104#define GRECS_LIST 0x08 /* Value is a list of declared type */
105#define GRECS_HIDDEN 0x10 /* Hidden keyword: don't display in help output */
106#define GRECS_CONST 0x20 /* For string types: initial value is constant,
107 don't try to free it before assigning new value.
108 This flag is cleared after the first assignment.
109 */
110
111enum grecs_callback_command {
112 grecs_callback_section_begin,
113 grecs_callback_section_end,
114 grecs_callback_set_value
115};
116
117#define GRECS_TYPE_STRING 0
118#define GRECS_TYPE_LIST 1
119#define GRECS_TYPE_ARRAY 2
120
121struct grecs_list_entry {
122 struct grecs_list_entry *next, *prev;
123 void *data;
124};
125
126struct grecs_list {
127 struct grecs_list_entry *head, *tail;
128 size_t count;
129 int (*cmp)(const void *, const void *);
130 void (*free_entry)(void *);
131};
132
133typedef struct grecs_value {
134 int type;
135 grecs_locus_t locus;
136 union {
137 struct grecs_list *list;
138 char *string;
139 struct {
140 size_t c;
141 struct grecs_value **v;
142 } arg;
143 } v;
144} grecs_value_t;
145
146#define GRECS_VALUE_EMPTY_P(val) \
147 (!(val) || \
148 ((val)->type == GRECS_TYPE_STRING && (val)->v.string == NULL))
149
150enum grecs_node_type {
151 grecs_node_root,
152 grecs_node_stmt,
153 grecs_node_block
154};
155
156typedef struct grecs_node {
157 enum grecs_node_type type;
158 grecs_locus_t locus;
159 struct grecs_node *up;
160 struct grecs_node *down;
161 struct grecs_node *next;
162 struct grecs_node *prev;
163 char *ident;
164 grecs_locus_t idloc;
165 union {
166 struct grecs_value *value;
167 struct grecs_symtab *texttab;
168 } v;
169} grecs_node_t;
170
171typedef int (*grecs_callback_fn)(
172#if GRECS_TREE_API
173 enum grecs_callback_command cmd,
174 grecs_node_t * /* node */,
175 void * /* varptr */,
176 void * /* cb_data */
177#else
178 enum grecs_callback_command cmd,
179 grecs_locus_t * /* locus */,
180 void * /* varptr */,
181 grecs_value_t * /* value */,
182 void * /* cb_data */
183#endif
184 );
185
186struct grecs_keyword {
187 const char *ident;
188 const char *argname;
189 const char *docstring;
190 enum grecs_data_type type;
191 int flags;
192 void *varptr;
193 size_t offset;
194 grecs_callback_fn callback;
195 void *callback_data;
196 struct grecs_keyword *kwd;
197};
198
199struct grecs_sockaddr {
200#if GRECS_SOCKADDR_LIST
201 struct grecs_sockaddr *next;
202#endif
203 int len;
204 struct sockaddr *sa;
205};
206
207struct grecs_version_info *grecs_version(void);
208int grecs_version_cmp(const char *vstr1, const char *vstr2, int *pres);
209int grecs_version_ok(const char *vstr);
210void grecs_version_info_free(struct grecs_version_info *pv);
211struct grecs_version_info *grecs_version_split(const char *vstr);
212int grecs_version_info_cmp(struct grecs_version_info *vx,
213 struct grecs_version_info *vy,
214 int *pres);
215
216extern void *(*grecs_malloc_fun)(size_t size);
217extern void *(*grecs_realloc_fun)(void *ptr, size_t size);
218extern void (*grecs_alloc_die_fun)(void);
219extern void (*grecs_free_fun)(void *ptr);
220
221void *grecs_malloc(size_t size);
222void *grecs_zalloc(size_t size);
223void *grecs_calloc(size_t nmemb, size_t size);
224void *grecs_realloc(void *ptr, size_t size);
225void grecs_alloc_die(void);
226char *grecs_strdup(const char *str);
227void grecs_free(void *ptr);
228
229grecs_value_t *grecs_value_ptr_from_static(grecs_value_t *input);
230
231extern void (*grecs_print_diag_fun)(grecs_locus_t const *, int, int, const char*);
232
233void grecs_warning(grecs_locus_t const *locus,
234 int errcode, const char *fmt, ...)
235 __attribute__ ((__format__ (__printf__, 3, 4)));
236void grecs_error(grecs_locus_t const *locus, int errcode,
237 const char *fmt, ...)
238 __attribute__ ((__format__ (__printf__, 3, 4)));
239
240int grecs_asprint_locus(char **locstr, size_t *size,
241 grecs_locus_t const *locus);
242
243
244extern int grecs_trace_flags;
245
246#define GRECS_TRACE_GRAM 0x01
247#define GRECS_TRACE_LEX 0x02
248void grecs_gram_trace(int n);
249void grecs_lex_trace(int n);
250
251void grecs_parse_line_directive(char *text, grecs_locus_t *ploc,
252 struct grecs_locus_point *ppoint,
253 size_t *pxlines);
254void grecs_parse_line_directive_cpp(char *text, grecs_locus_t *ploc,
255 struct grecs_locus_point *ppoint,
256 size_t *pxlines);
257
258
259
260int grecs_lex_begin(const char*, int);
261void grecs_lex_end(int err);
262struct grecs_node *grecs_parse(const char *name);
263
264typedef struct grecs_node *(*grecs_parser_t)(const char *name, int trace);
265
266extern grecs_parser_t grecs_parser_fun;
267
268/* Parsers: */
269struct grecs_node *grecs_grecs_parser(const char *name, int traceflags);
270struct grecs_node *grecs_meta1_parser(const char *name, int traceflags);
271struct grecs_node *grecs_bind_parser(const char *name, int traceflags);
272struct grecs_node *grecs_dhcpd_parser(const char *name, int traceflags);
273struct grecs_node *grecs_git_parser(const char *name, int traceflags);
274struct grecs_node *grecs_path_parser(const char *name, int traceflags);
275
276
277/* Parser database */
278int grecs_enumerate_parsers(int (*fun)(const char *, grecs_parser_t, void *),
279 void *);
280grecs_parser_t grecs_get_parser_by_type(const char *type);
281
282
283struct grecs_list *_grecs_simple_list_create(int dispose);
284struct grecs_list *grecs_value_list_create(void);
285
286void grecs_line_acc_create(void);
287void grecs_line_acc_free(void);
288void grecs_line_acc_grow_char(int c);
289int grecs_line_acc_grow_char_unescape(int c);
290void grecs_line_acc_grow(const char *text, size_t len);
291void grecs_line_acc_grow_unescape_last(char *text, size_t len,
292 grecs_locus_t const *loc);
293
294void grecs_line_begin(void);
295#define grecs_line_add grecs_line_acc_grow
296char *grecs_line_finish(void);
297
298extern int grecs_string_convert(void *target, enum grecs_data_type type,
299 const char *string,
300 grecs_locus_t const *locus);
301extern void grecs_process_ident(struct grecs_keyword *kwp,
302 grecs_value_t *value,
303 void *base,
304 grecs_locus_t *locus);
305
306struct grecs_node *grecs_node_create(enum grecs_node_type type,
307 grecs_locus_t *loc);
308struct grecs_node *grecs_node_create_points(enum grecs_node_type type,
309 struct grecs_locus_point beg,
310 struct grecs_locus_point end);
311void grecs_node_bind(struct grecs_node *master, struct grecs_node *node,
312 int dn);
313int grecs_node_eq(struct grecs_node *a, struct grecs_node *b);
314
315
316extern struct grecs_locus_point grecs_current_locus_point;
317extern int grecs_error_count;
318extern int grecs_default_port;
319
320extern const char *grecs_preprocessor;
321extern int grecs_log_to_stderr;
322extern void (*grecs_log_setup_hook)();
323
324size_t grecs_preproc_fill_buffer(char *buf, size_t size);
325void grecs_preproc_add_include_dir(char *dir);
326int grecs_preproc_init(const char *name);
327void grecs_preproc_done(void);
328int grecs_preproc_run(const char *config_file, const char *extpp);
329
330#define GRECS_STD_INCLUDE 0x01
331#define GRECS_USR_INCLUDE 0x02
332
333size_t grecs_include_path_count(int flag);
334int grecs_foreach_include_dir(int flag, int (*fun)(int, const char *, void *),
335 void *data);
336
337char *grecs_find_include_file(const char *name, int allow_cwd);
338
339FILE *grecs_preproc_extrn_start(const char *file, pid_t *ppid);
340void grecs_preproc_extrn_shutdown(pid_t pid);
341
342char *grecs_install_text(const char *str);
343void grecs_destroy_text(void);
344struct grecs_symtab *grecs_text_table(void);
345
346void grecs_include_path_clear(void);
347void grecs_include_path_setup(const char *dir, ...);
348void grecs_include_path_setup_v(char **dirs);
349
350ssize_t grecs_getline(char **pbuf, size_t *psize, FILE *fp);
351
352const char *grecs_data_type_string(enum grecs_data_type type);
353void grecs_print_docstring(const char *docstring, unsigned level,
354 FILE *stream);
355void grecs_print_simple_statement(struct grecs_keyword *kwp,
356 unsigned level, FILE *stream);
357void grecs_print_block_statement(struct grecs_keyword *kwp,
358 unsigned level, FILE *stream);
359void grecs_print_statement_array(struct grecs_keyword *kwp,
360 unsigned n,
361 unsigned level, FILE *stream);
362
363struct grecs_format_closure
364{
365 int (*fmtfun)(const char *, void *);
366 void *data;
367};
368
369void grecs_format_locus(grecs_locus_t *locus, struct grecs_format_closure *fp);
370void grecs_format_node_path(struct grecs_node *node, int flag,
371 struct grecs_format_closure *fp);
372void grecs_format_value(struct grecs_value *val, int flags,
373 struct grecs_format_closure *fp);
374
375#define GRECS_NODE_FLAG_PATH 0x00100
376#define GRECS_NODE_FLAG_VALUE 0x00200
377#define GRECS_NODE_FLAG_DESCEND 0x01000
378#define GRECS_NODE_FLAG_LOCUS 0x02000
379#define GRECS_NODE_FLAG_QUOTE 0x04000
380#define GRECS_NODE_FLAG_NOQUOTE 0x08000
381#define GRECS_NODE_FLAG_QUOTE_HEX 0x10000
382
383#define _GRECS_NODE_MASK_DELIM 0x000ff
384#define _GRECS_NODE_MASK_OUTPUT 0x00f00
385
386#define GRECS_NODE_FLAG_DEFAULT \
387 (GRECS_NODE_FLAG_PATH|GRECS_NODE_FLAG_VALUE|\
388 GRECS_NODE_FLAG_DESCEND|GRECS_NODE_FLAG_QUOTE)
389int grecs_format_node(struct grecs_node *node, int flags,
390 struct grecs_format_closure *fp);
391
392void grecs_print_locus(grecs_locus_t *locus, FILE *fp);
393void grecs_print_node_path(struct grecs_node *node, int flag, FILE *fp);
394void grecs_print_value(struct grecs_value *val, int flags, FILE *fp);
395
396int grecs_print_node(struct grecs_node *node, int flags, FILE *fp);
397
398struct grecs_txtacc;
399void grecs_txtacc_format_value(struct grecs_value *val, int flags,
400 struct grecs_txtacc *acc);
401
402
403
404struct grecs_list *grecs_list_create(void);
405size_t grecs_list_size(struct grecs_list *lp);
406void grecs_list_append(struct grecs_list *lp, void *val);
407void grecs_list_push(struct grecs_list *lp, void *val);
408void *grecs_list_pop(struct grecs_list *lp);
409void *grecs_list_locate(struct grecs_list *lp, void *data);
410void *grecs_list_index(struct grecs_list *lp, size_t idx);
411void *grecs_list_remove_tail(struct grecs_list *lp);
412void grecs_list_remove_entry(struct grecs_list *lp,
413 struct grecs_list_entry *ent);
414void grecs_list_clear(struct grecs_list *lp);
415void grecs_list_free(struct grecs_list *lp);
416void grecs_list_add(struct grecs_list *dst, struct grecs_list *src);
417int grecs_list_compare(struct grecs_list *a, struct grecs_list *b);
418
419int grecs_vasprintf(char **pbuf, size_t *psize, const char *fmt, va_list ap);
420int grecs_asprintf(char **pbuf, size_t *psize, const char *fmt, ...);
421
422#define GRECS_TXTACC_BUFSIZE 1024
423struct grecs_txtacc *grecs_txtacc_create(void);
424void grecs_txtacc_free(struct grecs_txtacc *acc);
425void grecs_txtacc_grow(struct grecs_txtacc *acc, const char *buf, size_t size);
426void grecs_txtacc_grow_string(struct grecs_txtacc *acc, const char *buf);
427void grecs_txtacc_grow_string_escape(struct grecs_txtacc *acc,
428 const char *buf);
429 #define grecs_txtacc_grow_char(acc,c) \
430 do { \
431 char __ch = c; \
432 grecs_txtacc_grow(acc,&__ch,1);\
433 } while (0)
434char *grecs_txtacc_finish(struct grecs_txtacc *acc, int steal);
435void grecs_txtacc_free_string(struct grecs_txtacc *acc, char *str);
436
437struct grecs_symtab;
438
439struct grecs_syment {
440 char *name;
441};
442
443typedef int (*grecs_symtab_enumerator_t)(void *sym, void *data);
444
445const char *grecs_symtab_strerror(int rc);
446
447void *grecs_symtab_lookup_or_install(struct grecs_symtab *st,
448 void *key, int *install);
449void grecs_symtab_clear(struct grecs_symtab *st);
450struct grecs_symtab *grecs_symtab_create(size_t elsize,
451 unsigned (*hash_fun)(void *, unsigned long),
452 int (*cmp_fun)(const void *, const void *),
453 int (*copy_fun)(void *, void *),
454 void *(*alloc_fun)(size_t),
455 void (*free_fun)(void *));
456struct grecs_symtab *grecs_symtab_create_default(size_t elsize);
457
458void grecs_symtab_free(struct grecs_symtab *pst);
459int grecs_symtab_remove(struct grecs_symtab *st, void *elt);
460int grecs_symtab_replace(struct grecs_symtab *st, void *ent, void **old_ent);
461int grecs_symtab_enumerate(struct grecs_symtab *st,
462 grecs_symtab_enumerator_t fun, void *data);
463
464size_t grecs_symtab_count_entries(struct grecs_symtab *st);
465
466unsigned grecs_hash_string(const char *name, unsigned long hashsize);
467unsigned grecs_hash_string_ci(const char *name, unsigned long hashsize);
468
469
470void grecs_value_free(struct grecs_value *val);
471void grecs_value_free_content(struct grecs_value *val);
472void grecs_node_free(struct grecs_node *node);
473int grecs_node_unlink(struct grecs_node *node);
474int grecs_tree_free(struct grecs_node *node);
475
476enum grecs_tree_recurse_op {
477 grecs_tree_recurse_set,
478 grecs_tree_recurse_pre,
479 grecs_tree_recurse_post
480};
481
482enum grecs_tree_recurse_res {
483 grecs_tree_recurse_ok,
484 grecs_tree_recurse_fail,
485 grecs_tree_recurse_skip,
486 grecs_tree_recurse_stop
487};
488
489typedef enum grecs_tree_recurse_res
490 (*grecs_tree_recursor_t)(enum grecs_tree_recurse_op,
491 struct grecs_node *, void *);
492
493int grecs_tree_recurse(struct grecs_node *node, grecs_tree_recursor_t recfun,
494 void *data);
495int grecs_tree_join(struct grecs_node *dst, struct grecs_node *src);
496
497
498int grecs_tree_process(struct grecs_node *node, struct grecs_keyword *kwd);
499
500typedef struct grecs_match_buf *grecs_match_buf_t;
501struct grecs_node *grecs_match_first(struct grecs_node *tree,
502 const char *pattern,
503 grecs_match_buf_t *buf);
504struct grecs_node *grecs_match_next(struct grecs_match_buf *buf);
505void grecs_match_buf_free(struct grecs_match_buf *buf);
506grecs_match_buf_t grecs_match_buf_create(int argc, char **argv,
507 struct grecs_value **labelv);
508struct grecs_node *grecs_match_buf_first(struct grecs_match_buf *buf,
509 struct grecs_node *tree);
510struct grecs_node *grecs_match_buf_get_node(grecs_match_buf_t buf);
511size_t grecs_match_buf_get_args(grecs_match_buf_t buf, char ***argv);
512struct grecs_node *grecs_match_buf_get_root(grecs_match_buf_t buf);
513void grecs_match_buf_set_root(grecs_match_buf_t buf, struct grecs_node *root);
514
515int grecs_value_eq(struct grecs_value *a, struct grecs_value *b);
516int grecs_value_match(struct grecs_value *pat, struct grecs_value *b,
517 int flags);
518
519enum grecs_tree_recurse_res grecs_node_exact_match(
520 enum grecs_tree_recurse_op op,
521 struct grecs_node *node, void *data);
522
523struct grecs_node *grecs_find_node(struct grecs_node *node, const char *path);
524
525struct grecs_node *grecs_node_from_path(const char *path, const char *value);
526struct grecs_node *grecs_node_from_path_locus(const char *path,
527 const char *value,
528 grecs_locus_t *locus,
529 grecs_locus_t *vallocus);
530int grecs_tree_reduce(struct grecs_node *node, struct grecs_keyword *kwd,
531 int flags);
532
533void grecs_tree_sort(struct grecs_node *node,
534 int (*compare)(struct grecs_node const *,
535 struct grecs_node const *));
536
537struct grecs_node *grecs_tree_first_node(struct grecs_node *tree);
538struct grecs_node *grecs_next_node(struct grecs_node *node);
539
540int grecs_str_is_ipv4(const char *addr);
541int grecs_str_is_num(const char *s);
542int grecs_str_is_ipv6(const char *addr);
543int grecs_str_is_num(const char *s);
544int grecs_str_is_ipaddr(const char *addr);
545
546#if GRECS_SOCKADDR_LIST
547
548#define GRECS_AH_PASSIVE 0x01
549#define GRECS_HINT_SERVICE 0x02
550#define GRECS_HINT_PORT 0x04
551
552struct grecs_sockaddr_hints {
553 int flags;
554 char *service;
555 unsigned short port;
556};
557
558extern struct grecs_sockaddr_hints *grecs_sockaddr_hints;
559
560struct grecs_sockaddr *grecs_sockaddr_new(size_t s);
561void grecs_sockaddr_free(struct grecs_sockaddr *p);
562
563int grecs_str_to_sockaddr(struct grecs_sockaddr **sap,
564 const char *arg, struct grecs_sockaddr_hints *gh,
565 grecs_locus_t const *locus);
566#endif
567
568#define GRECS_INADDR_BYTES 16
569
570struct grecs_cidr
571{
572 int family;
573 int len;
574 unsigned char address[GRECS_INADDR_BYTES];
575 unsigned char netmask[GRECS_INADDR_BYTES];
576};
577
578int grecs_str_to_cidr(struct grecs_cidr *pcidr, const char *str,
579 grecs_locus_t const *locus);
580
581int grecs_sockaddr_to_cidr(struct grecs_cidr *cidr, const struct sockaddr *sa);
582int grecs_sockadd_cidr_match(struct sockaddr *sa, struct grecs_cidr *cidr);
583
584#endif
diff --git a/src/json-gram.y b/src/json-gram.y
index 4d5ae0f..fe8996b 100644
--- a/src/json-gram.y
+++ b/src/json-gram.y
@@ -21,7 +21,7 @@
21#include "grecs.h" 21#include "grecs.h"
22#include <grecs-locus.h>
23#include <string.h> 22#include <string.h>
24#include <errno.h> 23#include <errno.h>
24#include <stdlib.h>
25#include "json-gram.h" 25#include "json-gram.h"
26#include "json.h" 26#include "grecs/json.h"
27 27
diff --git a/src/json-lex.l b/src/json-lex.l
index 1ab6f74..169cf32 100644
--- a/src/json-lex.l
+++ b/src/json-lex.l
@@ -25,5 +25,4 @@
25#include "grecs.h" 25#include "grecs.h"
26#include <grecs-locus.h>
27#include "json-gram.h" 26#include "json-gram.h"
28#include "json.h" 27#include "grecs/json.h"
29 28
diff --git a/src/jsonfmt.c b/src/jsonfmt.c
index dda919b..9ccac37 100644
--- a/src/jsonfmt.c
+++ b/src/jsonfmt.c
@@ -20,4 +20,5 @@
20#include <string.h> 20#include <string.h>
21#include <stdlib.h>
21#include "grecs.h" 22#include "grecs.h"
22#include "json.h" 23#include "grecs/json.h"
23 24
diff --git a/src/lookup.c b/src/lookup.c
index f6c0865..7cb95df 100644
--- a/src/lookup.c
+++ b/src/lookup.c
@@ -25,2 +25,3 @@
25#include <fnmatch.h> 25#include <fnmatch.h>
26#include <stdlib.h>
26 27
@@ -179,3 +180,3 @@ grecs_match_buf_create(int argc, char **argv, struct grecs_value **labelv)
179 j < buf->argc && ISWC(buf->argv[j], '*'); j++) { 180 j < buf->argc && ISWC(buf->argv[j], '*'); j++) {
180 free(buf->argv[j]); 181 free(buf->argv[j]);
181 grecs_value_free_content(buf->labelv[i]); 182 grecs_value_free_content(buf->labelv[i]);
diff --git a/src/meta1-gram.y b/src/meta1-gram.y
index 96ebd3d..3b9ca63 100644
--- a/src/meta1-gram.y
+++ b/src/meta1-gram.y
@@ -23,3 +23,2 @@
23#include "grecs.h" 23#include "grecs.h"
24#include "grecs-locus.h"
25 24
diff --git a/src/meta1-lex.l b/src/meta1-lex.l
index 8050e5b..a5f873b 100644
--- a/src/meta1-lex.l
+++ b/src/meta1-lex.l
@@ -27,3 +27,2 @@
27#include "grecs.h" 27#include "grecs.h"
28#include "grecs-locus.h"
29#include "meta1-gram.h" 28#include "meta1-gram.h"
diff --git a/src/opthelp.c b/src/opthelp.c
index 6428a46..c9b7b46 100644
--- a/src/opthelp.c
+++ b/src/opthelp.c
@@ -23,3 +23,3 @@
23#include "grecs.h" 23#include "grecs.h"
24#include "grecsopt.h" 24#include "grecs/opt.h"
25#include "wordsplit.h" 25#include "wordsplit.h"
diff --git a/src/preproc.c b/src/preproc.c
index cf752f6..4d69602 100644
--- a/src/preproc.c
+++ b/src/preproc.c
@@ -20,2 +20,3 @@
20#include <grecs.h> 20#include <grecs.h>
21#include <wordsplit.h>
21#include <sys/types.h> 22#include <sys/types.h>
@@ -31,4 +32,4 @@
31#include <glob.h> 32#include <glob.h>
33#include <unistd.h>
32 34
33#include <wordsplit.h>
34 35
diff --git a/src/sockaddr.c b/src/sockaddr.c
index d3a969b..8cd790d 100644
--- a/src/sockaddr.c
+++ b/src/sockaddr.c
@@ -30,2 +30,3 @@
30#include <errno.h> 30#include <errno.h>
31#include <stdlib.h>
31#include "grecs.h" 32#include "grecs.h"
diff --git a/src/txtacc.c b/src/txtacc.c
index ee00170..5b9a197 100644
--- a/src/txtacc.c
+++ b/src/txtacc.c
@@ -20,2 +20,3 @@
20#include <string.h> 20#include <string.h>
21#include <stdlib.h>
21#include "grecs.h" 22#include "grecs.h"
@@ -75,3 +76,3 @@ grecs_txtacc_entry_tailor(struct grecs_txtacc_entry *ent)
75 if (ent->size > ent->len) { 76 if (ent->size > ent->len) {
76 char *p = realloc(ent->buf, ent->len); 77 char *p = grecs_realloc(ent->buf, ent->len);
77 if (!p) 78 if (!p)
diff --git a/src/version.c b/src/version.c
index 58ed799..e769e31 100644
--- a/src/version.c
+++ b/src/version.c
@@ -22,2 +22,3 @@
22#include <ctype.h> 22#include <ctype.h>
23#include <stdlib.h>
23#include "gitid.h" 24#include "gitid.h"
diff --git a/tests/gcfenum.c b/tests/gcfenum.c
index 1faa5c7..e36dbac 100644
--- a/tests/gcfenum.c
+++ b/tests/gcfenum.c
@@ -21,2 +21,3 @@
21#include <errno.h> 21#include <errno.h>
22#include <stdlib.h>
22#include "grecs.h" 23#include "grecs.h"
diff --git a/tests/gcffmt.c b/tests/gcffmt.c
index 6bfc53e..8e378f9 100644
--- a/tests/gcffmt.c
+++ b/tests/gcffmt.c
@@ -21,2 +21,3 @@
21#include <errno.h> 21#include <errno.h>
22#include <stdlib.h>
22#include "grecs.h" 23#include "grecs.h"
diff --git a/tests/gcfpeek.c b/tests/gcfpeek.c
index cd7136a..8e71c62 100644
--- a/tests/gcfpeek.c
+++ b/tests/gcfpeek.c
@@ -21,2 +21,3 @@
21#include <errno.h> 21#include <errno.h>
22#include <stdlib.h>
22#include "grecs.h" 23#include "grecs.h"
diff --git a/tests/gcfset.c b/tests/gcfset.c
index ee005a6..f241738 100644
--- a/tests/gcfset.c
+++ b/tests/gcfset.c
@@ -22,2 +22,3 @@
22#include <errno.h> 22#include <errno.h>
23#include <stdlib.h>
23#include "grecs.h" 24#include "grecs.h"
diff --git a/tests/gcfver.c b/tests/gcfver.c
index e0396c1..b5c9bab 100644
--- a/tests/gcfver.c
+++ b/tests/gcfver.c
@@ -19,2 +19,3 @@
19#endif 19#endif
20#include <stdlib.h>
20#include "grecs.h" 21#include "grecs.h"
diff --git a/tests/json.c b/tests/json.c
index fd244b5..0166c1a 100644
--- a/tests/json.c
+++ b/tests/json.c
@@ -24,4 +24,5 @@
24#include <errno.h> 24#include <errno.h>
25#include <stdlib.h>
25#include "grecs.h" 26#include "grecs.h"
26#include "json.h" 27#include "grecs/json.h"
27 28

Return to:

Send suggestions and report system problems to the System administrator.