diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-05-05 14:09:48 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-05-05 14:39:29 +0300 |
commit | 6c3f6c1b02dd5f9ac343c713bdae4aa83bafc328 (patch) | |
tree | 49bc8df1cff7157c711c63447c3e272ebc67cd4c /src | |
parent | a60eb4b18345626a84e23784d77ca231812e1dff (diff) | |
download | grecs-6c3f6c1b02dd5f9ac343c713bdae4aa83bafc328.tar.gz grecs-6c3f6c1b02dd5f9ac343c713bdae4aa83bafc328.tar.bz2 |
Improve node formatting. Add version comparasion functions.
* am/grecs.m4 (GRECS_SETUP): New option: shared.
* doc/GRECS_SETUP.3: Document new options.
* doc/grecs_format_locus.3: Update.
* doc/grecs_format_node.3: Document new flags.
* src/.gitignore: Update.
* src/version.c: New file.
* src/Make.am (GRECS_SRC): Add version.c
(EXTRA_DIST): Update.
* src/diag.c (default_print_diag): Flush stdout as per the docs.
* src/format.c (grecs_format_locus): Don't print trailing semicolon.
(grecs_format_value): Handle GRECS_NODE_FLAG_NOQUOTE flag.
(grecs_format_node): Print delimiters when needed.
* src/grecs.h (grecs_version_info): New struct.
(grecs_version, grecs_version_cmp): New protos.
(GRECS_NODE_FLAG_NOQUOTE): New flag.
* tests/gcfver.c: New file.
* tests/vercmp.at: New file.
* tests/.gitignore: Update.
* tests/Makefile.am: Define GRECS_VERCMP_AT in package.m4
(TESTSUITE_AT): Add vercmp.at (conditionally).
(noinst_PROGRAMS): Add gcfver.
* tests/testsuite.at: Conditionally include vercmp.at.
Diffstat (limited to 'src')
-rw-r--r-- | src/.gitignore | 3 | ||||
-rw-r--r-- | src/Make-shared.am | 18 | ||||
-rw-r--r-- | src/Make-static.am (renamed from src/Make-noinst.am) | 0 | ||||
-rw-r--r-- | src/Make.am | 3 | ||||
-rw-r--r-- | src/diag.c | 1 | ||||
-rw-r--r-- | src/format.c | 18 | ||||
-rw-r--r-- | src/grecs.h | 15 | ||||
-rw-r--r-- | src/version.c | 86 |
8 files changed, 136 insertions, 8 deletions
diff --git a/src/.gitignore b/src/.gitignore index bf5d140..9ef1b57 100644 --- a/src/.gitignore +++ b/src/.gitignore | |||
@@ -2,5 +2,6 @@ grecs-gram.c | |||
2 | grecs-gram.h | 2 | grecs-gram.h |
3 | grecs-gram.output | 3 | grecs-gram.output |
4 | grecs-lex.c | 4 | grecs-lex.c |
5 | Make-noinst.in | ||
6 | Make-inst.in | 5 | Make-inst.in |
6 | Make-shared.in | ||
7 | Make-static.in | ||
diff --git a/src/Make-shared.am b/src/Make-shared.am new file mode 100644 index 0000000..bbf25d4 --- /dev/null +++ b/src/Make-shared.am | |||
@@ -0,0 +1,18 @@ | |||
1 | # This file is part of grecs - Gray's Extensible Configuration System | ||
2 | # Copyright (C) 2007, 2009-2011 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 | include Make.am | ||
17 | noinst_LT_LIBRARIES=libgrecs.la | ||
18 | libgrecs_la_SOURCES = $(GRECS_SRC) | ||
diff --git a/src/Make-noinst.am b/src/Make-static.am index bf4f7ce..bf4f7ce 100644 --- a/src/Make-noinst.am +++ b/src/Make-static.am | |||
diff --git a/src/Make.am b/src/Make.am index e655767..fb3b80b 100644 --- a/src/Make.am +++ b/src/Make.am | |||
@@ -27,10 +27,11 @@ GRECS_SRC = \ | |||
27 | text.c\ | 27 | text.c\ |
28 | tree.c\ | 28 | tree.c\ |
29 | grecs.h\ | 29 | grecs.h\ |
30 | version.c\ | ||
30 | wordsplit.c\ | 31 | wordsplit.c\ |
31 | wordsplit.h | 32 | wordsplit.h |
32 | 33 | ||
33 | EXTRA_DIST=grecs-gram.h $(PP_SETUP_FILE) Make.am Make-inst.am Make-noinst.am | 34 | EXTRA_DIST=grecs-gram.h $(PP_SETUP_FILE) Make.am Make-inst.am Make-shared.am Make-static.am |
34 | 35 | ||
35 | INCLUDES = -I$(srcdir) @GRECS_INCLUDES@ | 36 | INCLUDES = -I$(srcdir) @GRECS_INCLUDES@ |
36 | AM_YFLAGS = -dtv | 37 | AM_YFLAGS = -dtv |
@@ -26,6 +26,7 @@ | |||
26 | static void | 26 | static void |
27 | default_print_diag(grecs_locus_t *locus, int err, int errcode, const char *msg) | 27 | default_print_diag(grecs_locus_t *locus, int err, int errcode, const char *msg) |
28 | { | 28 | { |
29 | fflush(stdout); | ||
29 | if (locus) | 30 | if (locus) |
30 | fprintf(stderr, "%s:%d: ", locus->file, locus->line); | 31 | fprintf(stderr, "%s:%d: ", locus->file, locus->line); |
31 | if (!err) | 32 | if (!err) |
diff --git a/src/format.c b/src/format.c index 2c97b72..6e33521 100644 --- a/src/format.c +++ b/src/format.c | |||
@@ -188,7 +188,7 @@ void | |||
188 | grecs_format_locus(grecs_locus_t *locus, FILE *fp) | 188 | grecs_format_locus(grecs_locus_t *locus, FILE *fp) |
189 | { | 189 | { |
190 | if (locus) | 190 | if (locus) |
191 | fprintf(fp, "%s:%d:", locus->file, locus->line); | 191 | fprintf(fp, "%s:%d", locus->file, locus->line); |
192 | } | 192 | } |
193 | 193 | ||
194 | void | 194 | void |
@@ -222,6 +222,8 @@ grecs_format_value(struct grecs_value *val, int flags, FILE *fp) | |||
222 | &need_quote); | 222 | &need_quote); |
223 | if (flags & GRECS_NODE_FLAG_QUOTE) | 223 | if (flags & GRECS_NODE_FLAG_QUOTE) |
224 | need_quote = 1; | 224 | need_quote = 1; |
225 | else if (flags & GRECS_NODE_FLAG_NOQUOTE) | ||
226 | need_quote = 0; | ||
225 | if (need_quote) { | 227 | if (need_quote) { |
226 | char *cbuf = grecs_malloc(clen + 1); | 228 | char *cbuf = grecs_malloc(clen + 1); |
227 | wordsplit_c_quote_copy(cbuf, val->v.string, | 229 | wordsplit_c_quote_copy(cbuf, val->v.string, |
@@ -257,6 +259,8 @@ grecs_format_value(struct grecs_value *val, int flags, FILE *fp) | |||
257 | void | 259 | void |
258 | grecs_format_node(struct grecs_node *node, int flags, FILE *fp) | 260 | grecs_format_node(struct grecs_node *node, int flags, FILE *fp) |
259 | { | 261 | { |
262 | const char *delim_str = NULL; | ||
263 | |||
260 | if (!flags) | 264 | if (!flags) |
261 | flags = GRECS_NODE_FLAG_DEFAULT; | 265 | flags = GRECS_NODE_FLAG_DEFAULT; |
262 | switch (node->type) { | 266 | switch (node->type) { |
@@ -271,15 +275,19 @@ grecs_format_node(struct grecs_node *node, int flags, FILE *fp) | |||
271 | case grecs_node_stmt: | 275 | case grecs_node_stmt: |
272 | if (flags & GRECS_NODE_FLAG_LOCUS) { | 276 | if (flags & GRECS_NODE_FLAG_LOCUS) { |
273 | grecs_format_locus(&node->locus, fp); | 277 | grecs_format_locus(&node->locus, fp); |
274 | fputc(' ', fp); | 278 | delim_str = ": "; |
275 | } | 279 | } |
276 | if (flags & GRECS_NODE_FLAG_PATH) { | 280 | if (flags & GRECS_NODE_FLAG_PATH) { |
281 | if (delim_str) | ||
282 | fprintf(fp, "%s", delim_str); | ||
277 | grecs_format_node_path(node, flags, fp); | 283 | grecs_format_node_path(node, flags, fp); |
278 | fputc(':', fp); | 284 | delim_str = ": "; |
279 | fputc(' ', fp); | ||
280 | } | 285 | } |
281 | if (flags & GRECS_NODE_FLAG_VALUE) | 286 | if (flags & GRECS_NODE_FLAG_VALUE) { |
287 | if (delim_str) | ||
288 | fprintf(fp, "%s", delim_str); | ||
282 | grecs_format_value(&node->value, flags, fp); | 289 | grecs_format_value(&node->value, flags, fp); |
290 | } | ||
283 | } | 291 | } |
284 | } | 292 | } |
285 | 293 | ||
diff --git a/src/grecs.h b/src/grecs.h index c408aa0..b6ac85c 100644 --- a/src/grecs.h +++ b/src/grecs.h | |||
@@ -37,6 +37,15 @@ | |||
37 | # define N_(s) s | 37 | # define N_(s) s |
38 | #endif | 38 | #endif |
39 | 39 | ||
40 | struct grecs_version_info { | ||
41 | const char *package; | ||
42 | const char *version; | ||
43 | int major; | ||
44 | int minor; | ||
45 | int patch; | ||
46 | char *suffix; | ||
47 | }; | ||
48 | |||
40 | typedef struct { | 49 | typedef struct { |
41 | char *file; | 50 | char *file; |
42 | int line; | 51 | int line; |
@@ -149,6 +158,9 @@ struct grecs_sockaddr { | |||
149 | struct sockaddr *sa; | 158 | struct sockaddr *sa; |
150 | }; | 159 | }; |
151 | 160 | ||
161 | void grecs_version(struct grecs_version_info *pv); | ||
162 | int grecs_version_cmp(const char *vstr); | ||
163 | |||
152 | extern void *(*grecs_malloc_fun)(size_t size); | 164 | extern void *(*grecs_malloc_fun)(size_t size); |
153 | extern void *(*grecs_realloc_fun)(void *ptr, size_t size); | 165 | extern void *(*grecs_realloc_fun)(void *ptr, size_t size); |
154 | extern void (*grecs_alloc_die_fun)(void); | 166 | extern void (*grecs_alloc_die_fun)(void); |
@@ -236,7 +248,8 @@ void grecs_format_value(struct grecs_value *val, int flags, FILE *fp); | |||
236 | #define GRECS_NODE_FLAG_PATH 0x0200 | 248 | #define GRECS_NODE_FLAG_PATH 0x0200 |
237 | #define GRECS_NODE_FLAG_VALUE 0x0400 | 249 | #define GRECS_NODE_FLAG_VALUE 0x0400 |
238 | #define GRECS_NODE_FLAG_QUOTE 0x0800 | 250 | #define GRECS_NODE_FLAG_QUOTE 0x0800 |
239 | #define GRECS_NODE_FLAG_QUOTE_HEX 0x1000 | 251 | #define GRECS_NODE_FLAG_NOQUOTE 0x1000 |
252 | #define GRECS_NODE_FLAG_QUOTE_HEX 0x2000 | ||
240 | #define GRECS_NODE_FLAG_DEFAULT \ | 253 | #define GRECS_NODE_FLAG_DEFAULT \ |
241 | (GRECS_NODE_FLAG_PATH|GRECS_NODE_FLAG_VALUE|GRECS_NODE_FLAG_QUOTE) | 254 | (GRECS_NODE_FLAG_PATH|GRECS_NODE_FLAG_VALUE|GRECS_NODE_FLAG_QUOTE) |
242 | void grecs_format_node(struct grecs_node *node, int flags, FILE *fp); | 255 | void grecs_format_node(struct grecs_node *node, int flags, FILE *fp); |
diff --git a/src/version.c b/src/version.c new file mode 100644 index 0000000..d34b8b5 --- /dev/null +++ b/src/version.c | |||
@@ -0,0 +1,86 @@ | |||
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 <string.h> | ||
22 | #include <ctype.h> | ||
23 | |||
24 | void | ||
25 | grecs_version(struct grecs_version_info *pv) | ||
26 | { | ||
27 | char *p; | ||
28 | memset(pv, 0, sizeof(*pv)); | ||
29 | pv->package = PACKAGE_NAME; | ||
30 | pv->version = PACKAGE_VERSION; | ||
31 | pv->major = strtoul(pv->version, &p, 10); | ||
32 | if (*p && *p == '.') { | ||
33 | pv->minor = strtoul(p + 1, &p, 10); | ||
34 | if (*p && *p == '.') { | ||
35 | char *q; | ||
36 | |||
37 | pv->patch = strtoul(p + 1, &q, 10); | ||
38 | if (q == p + 1) | ||
39 | pv->patch = 0; | ||
40 | else | ||
41 | p = q; | ||
42 | } | ||
43 | } | ||
44 | pv->suffix = p; | ||
45 | } | ||
46 | |||
47 | int | ||
48 | grecs_version_cmp(const char *vstr) | ||
49 | { | ||
50 | struct grecs_version_info v; | ||
51 | char *p; | ||
52 | unsigned long n; | ||