aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-05-03 17:49:29 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2011-05-03 21:23:21 +0300
commit3d679b3df641f59fb81ca1651799f4e2965ed67e (patch)
tree5a614ee25cff44d015ee9e6f6920e2ba19379bba
parent24ec67c9f6375d34d88e79981ed8abbe15a78169 (diff)
downloadgrecs-3d679b3df641f59fb81ca1651799f4e2965ed67e.tar.gz
grecs-3d679b3df641f59fb81ca1651799f4e2965ed67e.tar.bz2
Switch to the two-layer model. Add testsuite.
The configuration file parser creates a syntax tree. This step does not require any knowledge about which keywords are allowed. The user can then either use that tree directly, or post-process it using parser tables. The latter approach is equivalent to previous versions of grecs.
-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.c121
-rw-r--r--src/grecs-gram.y715
-rw-r--r--src/grecs.h86
-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, 2318 insertions, 716 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
@@ -46,33 +46,35 @@ AC_DEFUN([_GRECS_OPTION_SWITCH],
46# _GRECS_SET_OPTIONS(OPTIONS) 46# _GRECS_SET_OPTIONS(OPTIONS)
47# ---------------------------------- 47# ----------------------------------
48# OPTIONS is a space-separated list of Grecs options. 48# OPTIONS is a space-separated list of Grecs options.
49AC_DEFUN([_GRECS_SET_OPTIONS], 49AC_DEFUN([_GRECS_SET_OPTIONS],
50[m4_foreach_w([_GRECS_Option], [$1], [_GRECS_SET_OPTION(_GRECS_Option)])]) 50[m4_foreach_w([_GRECS_Option], [$1], [_GRECS_SET_OPTION(_GRECS_Option)])])
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.
56# std-pp-setup Install standard pp-setup file. 56# std-pp-setup Install standard pp-setup file.
57# pp-setup-option Add the --with-pp-setup-file option to the 57# pp-setup-option Add the --with-pp-setup-file option to the
58# configuration file. The option allows user to 58# configuration file. The option allows user to
59# control whether the pp-setup file is installed. 59# control whether the pp-setup file is installed.
60# tests Build tests.
60# 61#
61# The pp-setup-file argument supplies the pathname of the preprocessor 62# The pp-setup-file argument supplies the pathname of the preprocessor
62# setup file in the source tree. It is ignored if std-pp-setup option is 63# setup file in the source tree. It is ignored if std-pp-setup option is
63# given. 64# given.
64# 65#
65# If neither std-pp-setup option, nor pp-setup-file argument are supplied, 66# If neither std-pp-setup option, nor pp-setup-file argument are supplied,
66# no preprocessor setup file is installed. 67# no preprocessor setup file is installed.
67 68
68AC_DEFUN([GRECS_SETUP],[ 69AC_DEFUN([GRECS_SETUP],[
69 AC_PROG_YACC 70 AC_PROG_YACC
70 AM_PROG_LEX 71 AM_PROG_LEX
71 72
72 _GRECS_SET_OPTIONS([$1]) 73 AC_SUBST([GRECS_SUBDIR],m4_if([$1],,grecs,$1))
74 _GRECS_SET_OPTIONS([$2])
73 # ********************** 75 # **********************
74 # Preprocessor 76 # Preprocessor
75 # ********************** 77 # **********************
76 _GRECS_IF_OPTION_SET([no-preproc], 78 _GRECS_IF_OPTION_SET([no-preproc],
77 [use_ext_pp=no], 79 [use_ext_pp=no],
78 [AC_ARG_WITH([preprocessor], 80 [AC_ARG_WITH([preprocessor],
@@ -101,13 +103,13 @@ AC_DEFUN([GRECS_SETUP],[
101 AC_PATH_PROG(PPBIN, $DEFAULT_PREPROCESSOR) 103 AC_PATH_PROG(PPBIN, $DEFAULT_PREPROCESSOR)
102 DEFAULT_PREPROCESSOR=$PPBIN 104 DEFAULT_PREPROCESSOR=$PPBIN
103 if test -n "$DEFAULT_PREPROCESSOR"; then 105 if test -n "$DEFAULT_PREPROCESSOR"; then
104 DEFAULT_PREPROCESSOR="$DEFAULT_PREPROCESSOR $PREPROC_OPTIONS" 106 DEFAULT_PREPROCESSOR="$DEFAULT_PREPROCESSOR $PREPROC_OPTIONS"
105 _GRECS_IF_OPTION_SET([std-pp-setup], 107 _GRECS_IF_OPTION_SET([std-pp-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)
109 if test -n "$PP_SETUP_FILE"; then 111 if test -n "$PP_SETUP_FILE"; then
110 _GRECS_IF_OPTION_SET([pp-setup-option], 112 _GRECS_IF_OPTION_SET([pp-setup-option],
111 [AC_ARG_WITH([pp-setup-file], 113 [AC_ARG_WITH([pp-setup-file],
112 AC_HELP_STRING([--with-pp-setup-file], 114 AC_HELP_STRING([--with-pp-setup-file],
113 [install the default pp-setup file]), 115 [install the default pp-setup file]),
@@ -124,8 +126,17 @@ AC_DEFUN([GRECS_SETUP],[
124 fi 126 fi
125 PATH=$save_PATH 127 PATH=$save_PATH
126 DEFAULT_PREPROCESSOR="\\\"$DEFAULT_PREPROCESSOR\\\"" 128 DEFAULT_PREPROCESSOR="\\\"$DEFAULT_PREPROCESSOR\\\""
127 else 129 else
128 DEFAULT_PREPROCESSOR=NULL 130 DEFAULT_PREPROCESSOR=NULL
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
@@ -13,20 +13,23 @@
13# 13#
14# You should have received a copy of the GNU General Public License 14# You should have received a copy of the GNU General Public License
15# along with Grex. If not, see <http://www.gnu.org/licenses/>. 15# along with Grex. If not, see <http://www.gnu.org/licenses/>.
16 16
17noinst_LIBRARIES=libgrecs.a 17noinst_LIBRARIES=libgrecs.a
18libgrecs_a_SOURCES = \ 18libgrecs_a_SOURCES = \
19 diag.c\
19 format.c\ 20 format.c\
20 grecs-gram.y\ 21 grecs-gram.y\
21 grecs-lex.l\ 22 grecs-lex.l\
22 list.c\ 23 list.c\
24 lookup.c\
23 mem.c\ 25 mem.c\
24 preproc.c\ 26 preproc.c\
25 symtab.c\ 27 symtab.c\
26 text.c\ 28 text.c\
29 tree.c\
27 grecs.h\ 30 grecs.h\
28 wordsplit.c\ 31 wordsplit.c\
29 wordsplit.h 32 wordsplit.h
30 33
31EXTRA_DIST=grecs-gram.h $(PP_SETUP_FILE) 34EXTRA_DIST=grecs-gram.h $(PP_SETUP_FILE)
32 35
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{