summaryrefslogtreecommitdiffabout
path: root/src
authorSergey Poznyakoff <gray@gnu.org.ua>2011-05-25 15:42:22 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2011-05-25 15:42:22 (GMT)
commita98d3bcc6bcd42b4a2bc405183c531f4dcccd067 (patch) (side-by-side diff)
tree7b9525de40146c61ca8be977a187a432325439a4 /src
parent26a84bc3a797d60998b3ad6c3732c76ebc154f8c (diff)
downloadgrecs-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') (more/less context) (ignore whitespace changes)
-rw-r--r--src/format.c18
-rw-r--r--src/grecs.h27
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 @@
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
+#include <errno.h>
#include "wordsplit.h"
const char *
@@ -207,8 +208,8 @@ grecs_format_node_path(struct grecs_node *node, int flags,
grecs_format_node_path(node->up, flags, clos);
if (node->type == grecs_node_root)
return;
- if (flags & 0xff)
- delim[0] = flags & 0xff;
+ if (flags & _GRECS_NODE_MASK_DELIM)
+ delim[0] = flags & _GRECS_NODE_MASK_DELIM;
clos->fmtfun(delim, clos->data);
clos->fmtfun(node->ident, clos->data);
if (node->type == grecs_node_block &&
@@ -271,18 +272,21 @@ grecs_format_value(struct grecs_value *val, int flags,
}
}
-void
+int
grecs_format_node(struct grecs_node *node, int flags,
struct grecs_format_closure *clos)
{
const char *delim_str = NULL;
- if (!flags)
- flags = GRECS_NODE_FLAG_DEFAULT;
+ if (!(flags & _GRECS_NODE_MASK_OUTPUT)) {
+ errno = EINVAL;
+ return 1;
+ }
+
switch (node->type) {
case grecs_node_root:
case grecs_node_block:
- if (!(flags & GRECS_NODE_FLAG_NODESCEND)) {
+ if (flags & GRECS_NODE_FLAG_DESCEND) {
for (node = node->down; node; node = node->next) {
grecs_format_node(node, flags, clos);
if (node->next)
@@ -357,7 +361,7 @@ grecs_print_value(struct grecs_value *val, int flags, FILE *fp)
grecs_format_value(val, flags, &clos);
}
-void
+int
grecs_print_node(struct grecs_node *node, int flags, FILE *fp)
{
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,
void grecs_format_value(struct grecs_value *val, int flags,
struct grecs_format_closure *fp);
-#define GRECS_NODE_FLAG_LOCUS 0x0100
-#define GRECS_NODE_FLAG_PATH 0x0200
-#define GRECS_NODE_FLAG_VALUE 0x0400
-#define GRECS_NODE_FLAG_QUOTE 0x0800
-#define GRECS_NODE_FLAG_NOQUOTE 0x1000
-#define GRECS_NODE_FLAG_QUOTE_HEX 0x2000
-#define GRECS_NODE_FLAG_NODESCEND 0x4000
+#define GRECS_NODE_FLAG_PATH 0x00100
+#define GRECS_NODE_FLAG_VALUE 0x00200
+#define GRECS_NODE_FLAG_DESCEND 0x01000
+#define GRECS_NODE_FLAG_LOCUS 0x02000
+#define GRECS_NODE_FLAG_QUOTE 0x04000
+#define GRECS_NODE_FLAG_NOQUOTE 0x08000
+#define GRECS_NODE_FLAG_QUOTE_HEX 0x10000
+
+#define _GRECS_NODE_MASK_DELIM 0x000ff
+#define _GRECS_NODE_MASK_OUTPUT 0x00f00
+
#define GRECS_NODE_FLAG_DEFAULT \
- (GRECS_NODE_FLAG_PATH|GRECS_NODE_FLAG_VALUE|GRECS_NODE_FLAG_QUOTE)
-void grecs_format_node(struct grecs_node *node, int flags,
- struct grecs_format_closure *fp);
+ (GRECS_NODE_FLAG_PATH|GRECS_NODE_FLAG_VALUE|\
+ GRECS_NODE_FLAG_DESCEND|GRECS_NODE_FLAG_QUOTE)
+int grecs_format_node(struct grecs_node *node, int flags,
+ struct grecs_format_closure *fp);
void grecs_print_locus(grecs_locus_t *locus, FILE *fp);
void grecs_print_node_path(struct grecs_node *node, int flag, FILE *fp);
void grecs_print_value(struct grecs_value *val, int flags, FILE *fp);
-void grecs_print_node(struct grecs_node *node, int flags, FILE *fp);
+int grecs_print_node(struct grecs_node *node, int flags, FILE *fp);
struct grecs_txtacc;
void grecs_txtacc_format_value(struct grecs_value *val, int flags,

Return to:

Send suggestions and report system problems to the System administrator.