From 07bb413a8f6e3e3d42e317508c9a32826c8b6563 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Thu, 1 Aug 2002 12:46:52 +0000 Subject: [PATCH] o Added new value type CFG_EMPTY_ARRAY, to indicate '[]', useful since we use the arrays to hold a symbolic set of flags. --- lib/config/config.c | 19 +++++++++++++++++++ lib/config/config.h | 1 + 2 files changed, 20 insertions(+) diff --git a/lib/config/config.c b/lib/config/config.c index ada847876..39cfa8793 100644 --- a/lib/config/config.c +++ b/lib/config/config.c @@ -177,6 +177,13 @@ static void _write_value(FILE * fp, struct config_value *v) case CFG_INT: fprintf(fp, "%d", v->v.i); break; + + case CFG_EMPTY_ARRAY: + fprintf(fp, "[]"); + break; + + default: + log_err("Unknown value type"); } } @@ -325,6 +332,16 @@ static struct config_value *_value(struct parser *p) match(TOK_COMMA); } match(TOK_ARRAY_E); + + /* + * Special case an empty array. + */ + if (!h) { + if (!(h = _create_value(p))) + return NULL; + + h->type = CFG_EMPTY_ARRAY; + } } else h = _type(p); @@ -335,6 +352,8 @@ static struct config_value *_type(struct parser *p) { /* [0-9]+ | [0-9]*\.[0-9]* | ".*" */ struct config_value *v = _create_value(p); + if (!v) + return NULL; switch (p->t) { case TOK_INT: diff --git a/lib/config/config.h b/lib/config/config.h index 1f07a312f..c8d70463e 100644 --- a/lib/config/config.h +++ b/lib/config/config.h @@ -13,6 +13,7 @@ enum { CFG_STRING, CFG_FLOAT, CFG_INT, + CFG_EMPTY_ARRAY }; struct config_value {