summaryrefslogtreecommitdiffabout
path: root/src
Unidiff
Diffstat (limited to 'src') (more/less context) (ignore whitespace changes)
-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-locus.h57
-rw-r--r--src/grecs.hin584
-rw-r--r--src/grecsopt.h58
-rw-r--r--src/json-gram.y4
-rw-r--r--src/json-lex.l3
-rw-r--r--src/json.h99
-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--src/wordsplit.h250
29 files changed, 20 insertions, 1085 deletions
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-locus.h b/src/grecs-locus.h
deleted file mode 100644
index b5573fd..0000000
--- a/src/grecs-locus.h
+++ b/dev/null
@@ -1,57 +0,0 @@
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#define YYLTYPE grecs_locus_t
18
19 #define YYLLOC_DEFAULT(Current, Rhs, N) \
20 do { \
21 if (N) { \
22 (Current).beg = YYRHSLOC(Rhs, 1).beg; \
23 (Current).end = YYRHSLOC(Rhs, N).end; \
24 } else { \
25 (Current).beg = YYRHSLOC(Rhs, 0).end; \
26 (Current).end = (Current).beg; \
27 } \
28 } while (0)
29
30 #define YY_LOCATION_PRINT(File, Loc) do { \
31 if ((Loc).beg.col == 0) \
32 fprintf(File, "%s:%u", \
33 (Loc).beg.file, \
34 (Loc).beg.line); \
35 else if (strcmp((Loc).beg.file, (Loc).end.file))\
36 fprintf(File, "%s:%u.%u-%s:%u.%u", \
37 (Loc).beg.file, \
38 (Loc).beg.line, (Loc).beg.col, \
39 (Loc).end.file, \
40 (Loc).end.line, (Loc).end.col); \
41 else if ((Loc).beg.line != (Loc).end.line) \
42 fprintf(File, "%s:%u.%u-%u.%u", \
43 (Loc).beg.file, \
44 (Loc).beg.line, (Loc).beg.col, \
45 (Loc).end.line, (Loc).end.col); \
46 else if ((Loc).beg.col != (Loc).end.col) \
47 fprintf(File, "%s:%u.%u-%u", \
48 (Loc).beg.file, \
49 (Loc).beg.line, (Loc).beg.col, \
50 (Loc).end.col); \
51 else \
52 fprintf(File, "%s:%u.%u", \
53 (Loc).beg.file, \
54 (Loc).beg.line, \
55 (Loc).beg.col); \
56 } while (0)
57
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/grecsopt.h b/src/grecsopt.h
deleted file mode 100644
index 49c0b53..0000000
--- a/src/grecsopt.h
+++ b/dev/null
@@ -1,58 +0,0 @@
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#ifndef _GRECSOPT_H
18#define _GRECSOPT_H
19
20struct grecs_proginfo {
21 const char *progname;
22 char **subcmd;
23 const char *docstring;
24 const char *args_doc;
25 struct grecs_opthelp *opthelp;
26 size_t optcount;
27 void (*print_help_hook)(FILE *stream);
28 void (*print_version_hook)(FILE *stream);
29 const char *package;
30 const char *version;
31 const char *license;
32 const char *copyright_year;
33 const char *copyright_holder;
34 const char **authors;
35 const char *bug_address;
36 const char *url;
37 const char *epilogue;
38};
39
40struct grecs_opthelp {
41 const char *opt;
42 const char *arg;
43 int is_optional;
44 const char *descr;
45};
46
47#define DESCRCOLUMN 30
48#define RMARGIN 79
49#define GROUPCOLUMN 2
50#define USAGECOLUMN 13
51
52void grecs_print_help(struct grecs_proginfo *pinfo);
53void grecs_print_usage(struct grecs_proginfo *pinfo);
54void grecs_print_version_only(struct grecs_proginfo *pinfo, FILE *stream);
55void grecs_print_version(struct grecs_proginfo *pinfo, FILE *stream);
56
57#endif
58
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/json.h b/src/json.h
deleted file mode 100644
index f8402e7..0000000
--- a/src/json.h
+++ b/dev/null
@@ -1,99 +0,0 @@
1/* This file is part of Grecs.
2 Copyright (C) 2012-2016 Sergey Poznyakoff.
3
4 Grecs is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3, or (at your option)
7 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
15 along with Grecs. If not, see <http://www.gnu.org/licenses/>. */
16
17#include <grecs.h>
18
19enum json_value_type
20{
21 json_null,
22 json_bool,
23 json_number,
24 json_string,
25 json_arr,
26 json_object
27};
28
29struct json_value;
30struct json_array {
31 size_t oc;
32 struct json_value **ov;
33 struct grecs_list *ol;
34};
35
36struct json_value {
37 enum json_value_type type;
38 union {
39 int b; /* json_bool */
40 double n; /* json_number */
41 char *s; /* json_string */
42 struct json_array *a; /* json_arr */
43 struct grecs_symtab *o; /* json_object */
44 } v;
45};
46
47struct json_pair {
48 char *k;
49 struct json_value *v;
50};
51
52extern char const *json_err_diag;
53extern struct grecs_locus json_err_locus;
54extern struct json_value *json_return_obj;
55
56void jsonlex_setup(char const *s, size_t l);
57void jsonlex_diag(const char *s);
58int json_unescape(char c, char *o);
59
60struct json_value *json_value_create(int type);
61struct grecs_symtab *json_assoc_create(void);
62void json_value_free(struct json_value *obj);
63
64struct json_value *json_parse_string(char const *input, size_t len);
65
66struct json_value *json_value_lookup(struct json_value *obj,
67 const char *ident);
68
69
70struct json_format
71{
72 size_t indent;
73 int precision;
74 void (*write) (void *, char const *, size_t);
75 void *data;
76};
77
78void json_format_value(struct json_value *obj, struct json_format *fmt);
79
80struct json_value *json_new_null(void);
81struct json_value *json_new_bool(int b);
82struct json_value *json_new_number(double n);
83struct json_value *json_new_string(char const *str);
84
85struct json_value *json_new_object(void);
86int json_object_set(struct json_value *obj, char const *name,
87 struct json_value *val);
88int json_object_get(struct json_value *obj, char const *name,
89 struct json_value **retval);
90
91struct json_value *json_new_array(void);
92size_t json_array_size(struct json_value *j);
93void json_array_flatten(struct json_value *j);
94int json_array_insert(struct json_value *j, size_t idx, struct json_value *v);
95int json_array_append(struct json_value *j, struct json_value *v);
96int json_array_set(struct json_value *j, size_t idx, struct json_value *v);
97int json_array_get(struct json_value *j, size_t idx,
98 struct json_value **retval);
99
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/src/wordsplit.h b/src/wordsplit.h
deleted file mode 100644
index a7f6dd5..0000000
--- a/src/wordsplit.h
+++ b/dev/null
@@ -1,250 +0,0 @@
1/* wordsplit - a word splitter
2 Copyright (C) 2009-2016 Sergey Poznyakoff
3
4 This program 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 This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
16
17#ifndef __WORDSPLIT_H
18#define __WORDSPLIT_H
19
20#include <stddef.h>
21
22typedef struct wordsplit wordsplit_t;
23
24/* Structure used to direct the splitting. Members marked with [Input]
25 can be defined before calling wordsplit(), those marked with [Output]
26 provide return values when the function returns. If neither mark is
27 used, the member is internal and must not be used by the caller.
28
29 In the comments below, the
30 identifiers in parentheses indicate bits that must be set (or unset, if
31 starting with !) in the ws_flags to initialize or use the given member.
32 If not redefined explicitly, most of them are set to some reasonable
33 default value upon entry to wordsplit(). */
34struct wordsplit
35{
36 size_t ws_wordc; /* [Output] Number of words in ws_wordv. */
37 char **ws_wordv; /* [Output] Array of parsed out words. */
38 size_t ws_offs; /* [Input] (WRDSF_DOOFFS) Number of initial
39 elements in ws_wordv to fill with NULLs. */
40 size_t ws_wordn; /* Number of elements ws_wordv can accomodate. */
41 int ws_flags; /* [Input] Flags passed to wordsplit. */
42 int ws_options; /* [Input] (WRDSF_PATHEXPAND)
43 Additional options. */
44 const char *ws_delim; /* [Input] (WRDSF_DELIM) Word delimiters. */
45 const char *ws_comment; /* [Input] (WRDSF_COMMENT) Comment characters. */
46 const char *ws_escape[2]; /* [Input] (WRDSF_ESCAPE) Characters to be escaped
47 with backslash. */
48 void (*ws_alloc_die) (wordsplit_t *wsp);
49 /* [Input] (WRDSF_ALLOC_DIE) Function called when
50 out of memory. Must not return. */
51 void (*ws_error) (const char *, ...)
52 __attribute__ ((__format__ (__printf__, 1, 2)));
53 /* [Input] (WRDSF_ERROR) Function used for error
54 reporting */
55 void (*ws_debug) (const char *, ...)
56 __attribute__ ((__format__ (__printf__, 1, 2)));
57 /* [Input] (WRDSF_DEBUG) Function used for debug
58 output. */
59 const char **ws_env; /* [Input] (WRDSF_ENV, !WRDSF_NOVAR) Array of
60 environment variables. */
61
62 char **ws_envbuf;
63 size_t ws_envidx;
64 size_t ws_envsiz;
65
66 int (*ws_getvar) (char **ret, const char *var, size_t len, void *clos);
67 /* [Input] (WRDSF_GETVAR, !WRDSF_NOVAR) Looks up
68 the name VAR (LEN bytes long) in the table of
69 variables and if found returns in memory
70 location pointed to by RET the value of that
71 variable. Returns WRDSE_OK (0) on success,
72 and an error code (see WRDSE_* defines below)
73 on error. User-specific errors can be returned
74 by storing the error diagnostic string in RET
75 and returning WRDSE_USERERR.
76 Whatever is stored in RET, it must be allocated
77 using malloc(3). */
78 void *ws_closure; /* [Input] (WRDSF_CLOSURE) Passed as the CLOS
79 argument to ws_getvar and ws_command. */
80 int (*ws_command) (char **ret, const char *cmd, size_t len, char **argv,
81 void *clos);
82 /* [Input] (!WRDSF_NOCMD) Returns in the memory
83 location pointed to by RET the expansion of
84 the command CMD (LEN bytes nong). If WRDSF_ARGV
85 flag is set, ARGV contains CMD split out to
86 words. Otherwise ARGV is NULL.
87
88 See ws_getvar for a discussion of possible
89 return values. */
90
91 const char *ws_input; /* Input string (the S argument to wordsplit. */
92 size_t ws_len; /* Length of ws_input. */
93 size_t ws_endp; /* Points past the last processed byte in
94 ws_input. */
95 int ws_errno; /* [Output] Error code, if an error occurred. */
96 char *ws_usererr; /* Points to textual description of
97 the error, if ws_errno is WRDSE_USERERR. Must
98 be allocated with malloc(3). */
99 struct wordsplit_node *ws_head, *ws_tail;
100 /* Doubly-linked list of parsed out nodes. */
101 int ws_lvl; /* Invocation nesting level. */
102};
103
104/* Initial size for ws_env, if allocated automatically */
105#define WORDSPLIT_ENV_INIT 16
106
107/* Wordsplit flags. */
108/* Append the words found to the array resulting from a previous
109 call. */
110#define WRDSF_APPEND 0x00000001
111/* Insert ws_offs initial NULLs in the array ws_wordv.
112 (These are not counted in the returned ws_wordc.) */
113#define WRDSF_DOOFFS 0x00000002
114/* Don't do command substitution. */
115#define WRDSF_NOCMD 0x00000004
116/* The parameter p resulted from a previous call to
117 wordsplit(), and wordsplit_free() was not called. Reuse the
118 allocated storage. */
119#define WRDSF_REUSE 0x00000008
120/* Print errors */
121#define WRDSF_SHOWERR 0x00000010
122/* Consider it an error if an undefined variable is expanded. */
123#define WRDSF_UNDEF 0x00000020
124/* Don't do variable expansion. */
125#define WRDSF_NOVAR 0x00000040
126/* Abort on ENOMEM error */
127#define WRDSF_ENOMEMABRT 0x00000080
128/* Trim off any leading and trailind whitespace */
129#define WRDSF_WS 0x00000100
130/* Handle single quotes */
131#define WRDSF_SQUOTE 0x00000200
132/* Handle double quotes */
133#define WRDSF_DQUOTE 0x00000400
134/* Handle single and double quotes */
135#define WRDSF_QUOTE (WRDSF_SQUOTE|WRDSF_DQUOTE)
136/* Replace each input sequence of repeated delimiters with a single
137 delimiter */
138#define WRDSF_SQUEEZE_DELIMS 0x00000800
139/* Return delimiters */
140#define WRDSF_RETURN_DELIMS 0x00001000
141/* Treat sed expressions as words */
142#define WRDSF_SED_EXPR 0x00002000
143/* ws_delim field is initialized */
144#define WRDSF_DELIM 0x00004000
145/* ws_comment field is initialized */
146#define WRDSF_COMMENT 0x00008000
147/* ws_alloc_die field is initialized */
148#define WRDSF_ALLOC_DIE 0x00010000
149/* ws_error field is initialized */
150#define WRDSF_ERROR 0x00020000
151/* ws_debug field is initialized */
152#define WRDSF_DEBUG 0x00040000
153/* ws_env field is initialized */
154#define WRDSF_ENV 0x00080000
155/* ws_getvar field is initialized */
156#define WRDSF_GETVAR 0x00100000
157/* enable debugging */
158#define WRDSF_SHOWDBG 0x00200000
159/* Don't split input into words. Useful for side effects. */
160#define WRDSF_NOSPLIT 0x00400000
161/* Keep undefined variables in place, instead of expanding them to
162 empty strings. */
163#define WRDSF_KEEPUNDEF 0x00800000
164/* Warn about undefined variables */
165#define WRDSF_WARNUNDEF 0x01000000
166/* Handle C escapes */
167#define WRDSF_CESCAPES 0x02000000
168/* ws_closure is set */
169#define WRDSF_CLOSURE 0x04000000
170/* ws_env is a Key/Value environment, i.e. the value of a variable is
171 stored in the element that follows its name. */
172#define WRDSF_ENV_KV 0x08000000
173/* ws_escape is set */
174#define WRDSF_ESCAPE 0x10000000
175/* Incremental mode */
176#define WRDSF_INCREMENTAL 0x20000000
177/* Perform pathname and tilde expansion */
178#define WRDSF_PATHEXPAND 0x40000000
179/* ws_options is initialized */
180#define WRDSF_OPTIONS 0x80000000
181
182 #define WRDSF_DEFFLAGS \
183 (WRDSF_NOVAR | WRDSF_NOCMD | \
184 WRDSF_QUOTE | WRDSF_SQUEEZE_DELIMS | WRDSF_CESCAPES)
185
186/* Remove the word that produces empty string after path expansion */
187#define WRDSO_NULLGLOB 0x00000001
188/* Print error message if path expansion produces empty string */
189#define WRDSO_FAILGLOB 0x00000002
190/* Allow a leading period to be matched by metacharacters. */
191#define WRDSO_DOTGLOB 0x00000004
192/* ws_command needs argv parameter */
193#define WRDSO_ARGV 0x00000008
194/* Keep backslash in unrecognized escape sequences in words */
195#define WRDSO_BSKEEP_WORD 0x00000010
196/* Handle octal escapes in words */
197#define WRDSO_OESC_WORD 0x00000020
198/* Handle hex escapes in words */
199#define WRDSO_XESC_WORD 0x00000040
200
201/* Keep backslash in unrecognized escape sequences in quoted strings */
202#define WRDSO_BSKEEP_QUOTE 0x00000100
203/* Handle octal escapes in quoted strings */
204#define WRDSO_OESC_QUOTE 0x00000200
205/* Handle hex escapes in quoted strings */
206#define WRDSO_XESC_QUOTE 0x00000400
207
208#define WRDSO_BSKEEP WRDSO_BSKEEP_WORD
209#define WRDSO_OESC WRDSO_OESC_WORD
210#define WRDSO_XESC WRDSO_XESC_WORD
211
212/* Indices into ws_escape */
213#define WRDSX_WORD 0
214#define WRDSX_QUOTE 1
215
216/* Set escape option F in WS for words (Q==0) or quoted strings (Q==1) */
217#define WRDSO_ESC_SET(ws,q,f) ((ws)->ws_options |= ((f) << 4*(q)))
218/* Test WS for escape option F for words (Q==0) or quoted strings (Q==1) */
219#define WRDSO_ESC_TEST(ws,q,f) ((ws)->ws_options & ((f) << 4*(q)))
220
221#define WRDSE_OK 0
222#define WRDSE_EOF WRDSE_OK
223#define WRDSE_QUOTE 1
224#define WRDSE_NOSPACE 2
225#define WRDSE_USAGE 3
226#define WRDSE_CBRACE 4
227#define WRDSE_UNDEF 5
228#define WRDSE_NOINPUT 6
229#define WRDSE_PAREN 7
230#define WRDSE_GLOBERR 8
231#define WRDSE_USERERR 9
232
233int wordsplit (const char *s, wordsplit_t *ws, int flags);
234int wordsplit_len (const char *s, size_t len, wordsplit_t *ws, int flags);
235void wordsplit_free (wordsplit_t *ws);
236void wordsplit_free_words (wordsplit_t *ws);
237void wordsplit_free_envbuf (wordsplit_t *ws);
238void wordsplit_getwords (wordsplit_t *ws, size_t *wordc, char ***wordv);
239
240int wordsplit_c_unquote_char (int c);
241int wordsplit_c_quote_char (int c);
242size_t wordsplit_c_quoted_length (const char *str, int quote_hex, int *quote);
243void wordsplit_c_quote_copy (char *dst, const char *src, int quote_hex);
244
245void wordsplit_perror (wordsplit_t *ws);
246const char *wordsplit_strerror (wordsplit_t *ws);
247
248void wordsplit_clearerr (wordsplit_t *ws);
249
250#endif

Return to:

Send suggestions and report system problems to the System administrator.