aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore29
-rw-r--r--Makefile.am2
-rw-r--r--am/grecs.m421
-rw-r--r--src/.gitignore4
-rw-r--r--src/Makefile.am3
-rw-r--r--src/diag.c73
-rw-r--r--src/format.c117
-rw-r--r--src/grecs-gram.y709
-rw-r--r--src/grecs.h82
-rw-r--r--src/lookup.c272
-rw-r--r--src/tree.c773
-rw-r--r--tests/.gitignore8
-rw-r--r--tests/Makefile.am84
-rw-r--r--tests/atlocal.in10
-rw-r--r--tests/cfhelp.at76
-rw-r--r--tests/format00.at38
-rw-r--r--tests/format01.at38
-rw-r--r--tests/format02.at38
-rw-r--r--tests/gcf1.conf54
-rw-r--r--tests/gcffmt.c67
-rw-r--r--tests/gcfpeek.c76
-rw-r--r--tests/gcfset.c240
-rw-r--r--tests/peek00.at25
-rw-r--r--tests/peek01.at30
-rw-r--r--tests/peek02.at26
-rw-r--r--tests/peek03.at33
-rw-r--r--tests/set.at38
-rw-r--r--tests/testsuite.at54
28 files changed, 2311 insertions, 709 deletions
diff --git a/.gitignore b/.gitignore
index 42c88b2..eec45d2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,25 @@
1gconf-gram.c 1*.a
2gconf-gram.h 2*.o
3gconf-gram.output 3*.tar.*
4gconf-lex.c 4*~
5.deps
6.emacs.desktop
7.emacs.desktop.lock
8.emacsrc
9ABOUT-NLS
10ChangeLog
11INSTALL
12Makefile
13Makefile.in
14TAGS
15aclocal.m4
16autom4te.cache
17build-aux
18config.h
19config.h.in
20config.log
21config.status
22configure
23core
24m4
25stamp-h1
diff --git a/Makefile.am b/Makefile.am
index 1bfdcf4..17f1ff6 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1 +1 @@
SUBDIRS=src SUBDIRS=src @GRECS_TESTDIR@
diff --git a/am/grecs.m4 b/am/grecs.m4
index 47c9867..5fc1819 100644
--- a/am/grecs.m4
+++ b/am/grecs.m4
@@ -51,5 +51,5 @@ AC_DEFUN([_GRECS_SET_OPTIONS],
51 51
52# GRECS_SETUP([OPTIONS],[pp-setup-file]) 52# GRECS_SETUP([dir],[OPTIONS],[pp-setup-file])
53# 53# dir - Directory in the source tree where grecs has been cloned.
54# Options are: 54# OPTIONS are:
55# no-preproc Disable the use of preprocessor. 55# no-preproc Disable the use of preprocessor.
@@ -59,2 +59,3 @@ AC_DEFUN([_GRECS_SET_OPTIONS],
59# control whether the pp-setup file is installed. 59# control whether the pp-setup file is installed.
60# tests Build tests.
60# 61#
@@ -71,3 +72,4 @@ AC_DEFUN([GRECS_SETUP],[
71 72
72 _GRECS_SET_OPTIONS([$1]) 73 AC_SUBST([GRECS_SUBDIR],m4_if([$1],,grecs,$1))
74 _GRECS_SET_OPTIONS([$2])
73 # ********************** 75 # **********************
@@ -106,3 +108,3 @@ AC_DEFUN([GRECS_SETUP],[
106 [PP_SETUP_FILE='pp-setup'], 108 [PP_SETUP_FILE='pp-setup'],
107 [m4_if([$2],,[PP_SETUP_FILE=],[PP_SETUP_FILE='$2'])]) 109 [m4_if([$3],,[PP_SETUP_FILE=],[PP_SETUP_FILE='$3'])])
108 AC_SUBST(PP_SETUP_FILE) 110 AC_SUBST(PP_SETUP_FILE)
@@ -129,3 +131,12 @@ AC_DEFUN([GRECS_SETUP],[
129 fi 131 fi
132 _GRECS_IF_OPTION_SET([tests],
133 [m4_pushdef([TESTDIR],m4_if([$1],,grecs,$1)/tests)
134 AC_CONFIG_TESTDIR(TESTDIR)
135 AC_CONFIG_FILES(TESTDIR/Makefile TESTDIR/atlocal)
136 m4_popdef([TESTDIR])
137 AM_MISSING_PROG([AUTOM4TE], [autom4te])
138 GRECS_TESTDIR=tests
139 ])
130 AC_SUBST([GRECS_INCLUDES]) 140 AC_SUBST([GRECS_INCLUDES])
141 AC_SUBST([GRECS_TESTDIR])
131]) 142])
diff --git a/src/.gitignore b/src/.gitignore
new file mode 100644
index 0000000..7c38320
--- /dev/null
+++ b/src/.gitignore
@@ -0,0 +1,4 @@
1grecs-gram.c
2grecs-gram.h
3grecs-gram.output
4grecs-lex.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 759716b..0c2c444 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -18,2 +18,3 @@ noinst_LIBRARIES=libgrecs.a
18libgrecs_a_SOURCES = \ 18libgrecs_a_SOURCES = \
19 diag.c\
19 format.c\ 20 format.c\
@@ -22,2 +23,3 @@ libgrecs_a_SOURCES = \
22 list.c\ 23 list.c\
24 lookup.c\
23 mem.c\ 25 mem.c\
@@ -26,2 +28,3 @@ libgrecs_a_SOURCES = \
26 text.c\ 28 text.c\
29 tree.c\
27 grecs.h\ 30 grecs.h\
diff --git a/src/diag.c b/src/diag.c
new file mode 100644
index 0000000..fcb8fd2
--- /dev/null
+++ b/src/diag.c
@@ -0,0 +1,73 @@
1/* grecs - Gray's Extensible Configuration System
2 Copyright (C) 2007-2011 Sergey Poznyakoff
3
4 Grecs is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the
6 Free Software Foundation; either version 3 of the License, or (at your
7 option) any later version.
8
9 Grecs is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with Grecs. If not, see <http://www.gnu.org/licenses/>. */
16
17#ifdef HAVE_CONFIG_H
18# include <config.h>
19#endif
20#include <grecs.h>
21#include <stdlib.h>
22#include <stdio.h>
23#include <string.h>
24#include <errno.h>
25
26static void
27default_print_diag(grecs_locus_t *locus, int err, int errcode, const char *msg)
28{
29 if (locus)
30 fprintf(stderr, "%s:%d: ", locus->file, locus->line);
31 if (!err)
32 fprintf(stderr, "warning: ");
33 fprintf(stderr, "%s", msg);
34 if (errcode)
35 fprintf(stderr, ": %s", strerror(errno));
36 fputc('\n', stderr);
37}
38
39void (*grecs_print_diag_fun)(grecs_locus_t *, int, int, const char *msg) =
40 default_print_diag;
41
42void
43grecs_warning(grecs_locus_t *locus, int errcode, const char *fmt, ...)
44{
45 va_list ap;
46 char *buf = NULL;
47 size_t size = 0;
48
49 va_start(ap, fmt);
50 if (grecs_vasprintf(&buf, &size, fmt, ap))
51 grecs_alloc_die();
52 va_end(ap);
53 grecs_print_diag_fun(locus, 0, errcode, buf);
54 free(buf);
55}
56
57void
58grecs_error(grecs_locus_t *locus, int errcode, const char *fmt, ...)
59{
60 va_list ap;
61 char *buf = NULL;
62 size_t size = 0;
63
64 va_start(ap, fmt);
65 if (grecs_vasprintf(&buf, &size, fmt, ap))
66 grecs_alloc_die();
67 va_end(ap);
68 grecs_print_diag_fun(locus, 1, errcode, buf);
69 free(buf);
70 grecs_error_count++;
71}
72
73
diff --git a/src/format.c b/src/format.c
index fc6c8d6..11b405a 100644
--- a/src/format.c
+++ b/src/format.c
@@ -70,3 +70,3 @@ grecs_data_type_string (enum grecs_data_type type)
70static void 70static void
71format_level(FILE *stream, unsigned level) 71format_level(unsigned level, FILE *stream)
72{ 72{
@@ -77,3 +77,3 @@ format_level(FILE *stream, unsigned level)
77void 77void
78grecs_format_docstring(FILE *stream, const char *docstring, unsigned level) 78grecs_format_docstring(const char *docstring, unsigned level, FILE *stream)
79{ 79{
@@ -103,3 +103,3 @@ grecs_format_docstring(FILE *stream, const char *docstring, unsigned level)
103 103
104 format_level(stream, level); 104 format_level(level, stream);
105 fprintf(stream, "# "); 105 fprintf(stream, "# ");
@@ -121,4 +121,4 @@ grecs_format_docstring(FILE *stream, const char *docstring, unsigned level)
121void 121void
122grecs_format_simple_statement(FILE *stream, struct grecs_keyword *kwp, 122grecs_format_simple_statement(struct grecs_keyword *kwp, unsigned level,
123 unsigned level) 123 FILE *stream)
124{ 124{
@@ -127,4 +127,4 @@ grecs_format_simple_statement(FILE *stream, struct grecs_keyword *kwp,
127 if (kwp->docstring) 127 if (kwp->docstring)
128 grecs_format_docstring(stream, kwp->docstring, level); 128 grecs_format_docstring(kwp->docstring, level, stream);
129 format_level(stream, level); 129 format_level(level, stream);
130 130
@@ -153,8 +153,8 @@ grecs_format_simple_statement(FILE *stream, struct grecs_keyword *kwp,
153void 153void
154grecs_format_block_statement(FILE *stream, struct grecs_keyword *kwp, 154grecs_format_block_statement(struct grecs_keyword *kwp, unsigned level,
155 unsigned level) 155 FILE *stream)
156{ 156{
157 if (kwp->docstring) 157 if (kwp->docstring)