diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-05-25 18:42:22 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-05-25 18:42:22 +0300 |
commit | a98d3bcc6bcd42b4a2bc405183c531f4dcccd067 (patch) | |
tree | 7b9525de40146c61ca8be977a187a432325439a4 /src | |
parent | 26a84bc3a797d60998b3ad6c3732c76ebc154f8c (diff) | |
download | grecs-a98d3bcc6bcd42b4a2bc405183c531f4dcccd067.tar.gz grecs-a98d3bcc6bcd42b4a2bc405183c531f4dcccd067.tar.bz2 |
Change GRECS_NODE_.* flag handling.
* src/grecs.h: Rearange GRECS_NODE_FLAG_* constants.
Remove GRECS_NODE_FLAG_NODESCEND, introduce GRECS_NODE_FLAG_DESCEND
instead.
(_GRECS_NODE_MASK_DELIM,_GRECS_NODE_MASK_OUTPUT): New macros.
(grecs_format_node): Returns int.
(grecs_print_node): Likewise.
Diffstat (limited to 'src')
-rw-r--r-- | src/format.c | 18 | ||||
-rw-r--r-- | src/grecs.h | 27 |
2 files changed, 27 insertions, 18 deletions
diff --git a/src/format.c b/src/format.c index 6d87aed..a8f758d 100644 --- a/src/format.c +++ b/src/format.c | |||
@@ -22,6 +22,7 @@ | |||
22 | #include <stdlib.h> | 22 | #include <stdlib.h> |
23 | #include <ctype.h> | 23 | #include <ctype.h> |
24 | #include <string.h> | 24 | #include <string.h> |
25 | #include <errno.h> | ||
25 | #include "wordsplit.h" | 26 | #include "wordsplit.h" |
26 | 27 | ||
27 | const char * | 28 | const char * |
@@ -207,8 +208,8 @@ grecs_format_node_path(struct grecs_node *node, int flags, | |||
207 | grecs_format_node_path(node->up, flags, clos); | 208 | grecs_format_node_path(node->up, flags, clos); |
208 | if (node->type == grecs_node_root) | 209 | if (node->type == grecs_node_root) |
209 | return; | 210 | return; |
210 | if (flags & 0xff) | 211 | if (flags & _GRECS_NODE_MASK_DELIM) |
211 | delim[0] = flags & 0xff; | 212 | delim[0] = flags & _GRECS_NODE_MASK_DELIM; |
212 | clos->fmtfun(delim, clos->data); | 213 | clos->fmtfun(delim, clos->data); |
213 | clos->fmtfun(node->ident, clos->data); | 214 | clos->fmtfun(node->ident, clos->data); |
214 | if (node->type == grecs_node_block && | 215 | if (node->type == grecs_node_block && |
@@ -271,18 +272,21 @@ grecs_format_value(struct grecs_value *val, int flags, | |||
271 | } | 272 | } |
272 | } | 273 | } |
273 | 274 | ||
274 | void | 275 | int |
275 | grecs_format_node(struct grecs_node *node, int flags, | 276 | grecs_format_node(struct grecs_node *node, int flags, |
276 | struct grecs_format_closure *clos) | 277 | struct grecs_format_closure *clos) |
277 | { | 278 | { |
278 | const char *delim_str = NULL; | 279 | const char *delim_str = NULL; |
279 | 280 | ||
280 | if (!flags) | 281 | if (!(flags & _GRECS_NODE_MASK_OUTPUT)) { |
281 | flags = GRECS_NODE_FLAG_DEFAULT; | 282 | errno = EINVAL; |
283 | return 1; | ||
284 | } | ||
285 | |||
282 | switch (node->type) { | 286 | switch (node->type) { |
283 | case grecs_node_root: | 287 | case grecs_node_root: |
284 | case grecs_node_block: | 288 | case grecs_node_block: |
285 | if (!(flags & GRECS_NODE_FLAG_NODESCEND)) { | 289 | if (flags & GRECS_NODE_FLAG_DESCEND) { |
286 | for (node = node->down; node; node = node->next) { | 290 | for (node = node->down; node; node = node->next) { |
287 | grecs_format_node(node, flags, clos); | 291 | grecs_format_node(node, flags, clos); |
288 | if (node->next) | 292 | if (node->next) |
@@ -357,7 +361,7 @@ grecs_print_value(struct grecs_value *val, int flags, FILE *fp) | |||
357 | grecs_format_value(val, flags, &clos); | 361 | grecs_format_value(val, flags, &clos); |
358 | } | 362 | } |
359 | 363 | ||
360 | void | 364 | int |
361 | grecs_print_node(struct grecs_node *node, int flags, FILE *fp) | 365 | grecs_print_node(struct grecs_node *node, int flags, FILE *fp) |
362 | { | 366 | { |
363 | struct grecs_format_closure clos = { file_fmt, fp }; | 367 | struct grecs_format_closure clos = { file_fmt, fp }; |
diff --git a/src/grecs.h b/src/grecs.h index 7be6b21..fd957a8 100644 --- a/src/grecs.h +++ b/src/grecs.h | |||
@@ -308,23 +308,28 @@ void grecs_format_node_path(struct grecs_node *node, int flag, | |||
308 | void grecs_format_value(struct grecs_value *val, int flags, | 308 | void grecs_format_value(struct grecs_value *val, int flags, |
309 | struct grecs_format_closure *fp); | 309 | struct grecs_format_closure *fp); |
310 | 310 | ||
311 | #define GRECS_NODE_FLAG_LOCUS 0x0100 | 311 | #define GRECS_NODE_FLAG_PATH 0x00100 |
312 | #define GRECS_NODE_FLAG_PATH 0x0200 | 312 | #define GRECS_NODE_FLAG_VALUE 0x00200 |
313 | #define GRECS_NODE_FLAG_VALUE 0x0400 | 313 | #define GRECS_NODE_FLAG_DESCEND 0x01000 |
314 | #define GRECS_NODE_FLAG_QUOTE 0x0800 | 314 | #define GRECS_NODE_FLAG_LOCUS 0x02000 |
315 | #define GRECS_NODE_FLAG_NOQUOTE 0x1000 | 315 | #define GRECS_NODE_FLAG_QUOTE 0x04000 |
316 | #define GRECS_NODE_FLAG_QUOTE_HEX 0x2000 | 316 | #define GRECS_NODE_FLAG_NOQUOTE 0x08000 |
317 | #define GRECS_NODE_FLAG_NODESCEND 0x4000 | 317 | #define GRECS_NODE_FLAG_QUOTE_HEX 0x10000 |
318 | |||
319 | #define _GRECS_NODE_MASK_DELIM 0x000ff | ||
320 | #define _GRECS_NODE_MASK_OUTPUT 0x00f00 | ||
321 | |||
318 | #define GRECS_NODE_FLAG_DEFAULT \ | 322 | #define GRECS_NODE_FLAG_DEFAULT \ |
319 | (GRECS_NODE_FLAG_PATH|GRECS_NODE_FLAG_VALUE|GRECS_NODE_FLAG_QUOTE) | 323 | (GRECS_NODE_FLAG_PATH|GRECS_NODE_FLAG_VALUE|\ |
320 | void grecs_format_node(struct grecs_node *node, int flags, | 324 | GRECS_NODE_FLAG_DESCEND|GRECS_NODE_FLAG_QUOTE) |
321 | struct grecs_format_closure *fp); | 325 | int grecs_format_node(struct grecs_node *node, int flags, |
326 | struct grecs_format_closure *fp); | ||
322 | 327 | ||
323 | void grecs_print_locus(grecs_locus_t *locus, FILE *fp); | 328 | void grecs_print_locus(grecs_locus_t *locus, FILE *fp); |
324 | void grecs_print_node_path(struct grecs_node *node, int flag, FILE *fp); | 329 | void grecs_print_node_path(struct grecs_node *node, int flag, FILE *fp); |
325 | void grecs_print_value(struct grecs_value *val, int flags, FILE *fp); | 330 | void grecs_print_value(struct grecs_value *val, int flags, FILE *fp); |
326 | 331 | ||
327 | void grecs_print_node(struct grecs_node *node, int flags, FILE *fp); | 332 | int grecs_print_node(struct grecs_node *node, int flags, FILE *fp); |
328 | 333 | ||
329 | struct grecs_txtacc; | 334 | struct grecs_txtacc; |
330 | void grecs_txtacc_format_value(struct grecs_value *val, int flags, | 335 | void grecs_txtacc_format_value(struct grecs_value *val, int flags, |