From 05c8c4e718cbadd9b72eff863f1e32213cfecf64 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Thu, 19 Feb 2009 17:15:32 +0100 Subject: [PATCH] Config parser: Added a new operation `:reset', which is a shorthand for `:clear' and `:append'. I am not too confident about the name ... does anybody have a better idea? --- ucw/conf-input.c | 2 +- ucw/conf-intr.c | 43 +++++++++++++++++++++++++++++++------------ ucw/conf-test.cf | 2 +- ucw/getopt.h | 2 +- 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/ucw/conf-input.c b/ucw/conf-input.c index 86a092c1..09d21c83 100644 --- a/ucw/conf-input.c +++ b/ucw/conf-input.c @@ -255,7 +255,7 @@ parse_fastbuf(const char *name_fb, struct fastbuf *fb, uns depth) default: op = OP_ALL; }; break; case 'p': op = OP_PREPEND; break; - case 'r': op = OP_REMOVE; break; + case 'r': op = (c[1] && Clocase(c[2]) == 'm') ? OP_REMOVE : OP_RESET; break; case 'e': op = OP_EDIT; break; case 'b': op = OP_BEFORE; break; default: op = OP_SET; break; diff --git a/ucw/conf-intr.c b/ucw/conf-intr.c index dcde639a..deae4505 100644 --- a/ucw/conf-intr.c +++ b/ucw/conf-intr.c @@ -519,6 +519,21 @@ find_item(struct cf_section *curr_sec, const char *name, char **msg, void **ptr) } } +static char * +interpret_add(char *name, struct cf_item *item, int number, char **pars, int *takenp, void *ptr, enum cf_operation op) +{ + switch (item->cls) { + case CC_DYNAMIC: + return interpret_add_dynamic(item, number, pars, takenp, ptr, op); + case CC_LIST: + return interpret_add_list(item, number, pars, takenp, ptr, op); + case CC_BITMAP: + return interpret_add_bitmap(item, number, pars, takenp, ptr, op); + default: + return cf_printf("Operation %s not supported on attribute %s", cf_op_names[op], name); + } +} + char * cf_interpret_line(char *name, enum cf_operation op, int number, char **pars) { @@ -541,18 +556,22 @@ cf_interpret_line(char *name, enum cf_operation op, int number, char **pars) op &= OP_MASK; int taken = 0; // process as many parameters as possible - if (op == OP_CLEAR || op == OP_ALL) - msg = interpret_set_all(item, ptr, op); - else if (op == OP_SET) - msg = interpret_set_item(item, number, pars, &taken, ptr, 1); - else if (item->cls == CC_DYNAMIC) - msg = interpret_add_dynamic(item, number, pars, &taken, ptr, op); - else if (item->cls == CC_LIST) - msg = interpret_add_list(item, number, pars, &taken, ptr, op); - else if (item->cls == CC_BITMAP) - msg = interpret_add_bitmap(item, number, pars, &taken, ptr, op); - else - return cf_printf("Operation %s not supported on attribute %s", cf_op_names[op], name); + switch (op) { + case OP_CLEAR: + case OP_ALL: + msg = interpret_set_all(item, ptr, op); + break; + case OP_SET: + msg = interpret_set_item(item, number, pars, &taken, ptr, 1); + break; + case OP_RESET: + msg = interpret_set_all(item, ptr, OP_CLEAR); + if (!msg) + msg = interpret_add(name, item, number, pars, &taken, ptr, OP_APPEND); + break; + default: + msg = interpret_add(name, item, number, pars, &taken, ptr, op); + } if (msg) return msg; if (taken < number) diff --git a/ucw/conf-test.cf b/ucw/conf-test.cf index 51bacd4a..d533af4c 100644 --- a/ucw/conf-test.cf +++ b/ucw/conf-test.cf @@ -34,7 +34,7 @@ Top { \ unknown.ignored :-) -top.slaves cairns gpua 7 7 -10% +10% +top.slaves:reset cairns gpua 7 7 -10% +10% top.slaves daintree rafc 4 5 -171% top.slaves coogee pum 9 8 top.slaves:prepend {name=bondi; level=\ diff --git a/ucw/getopt.h b/ucw/getopt.h index c9daf24d..5fe66cea 100644 --- a/ucw/getopt.h +++ b/ucw/getopt.h @@ -63,7 +63,7 @@ int cf_set(const char *string); * described in <>. **/ #define CF_OPERATIONS T(CLOSE) T(SET) T(CLEAR) T(ALL) \ - T(APPEND) T(PREPEND) T(REMOVE) T(EDIT) T(AFTER) T(BEFORE) T(COPY) + T(APPEND) T(PREPEND) T(REMOVE) T(EDIT) T(AFTER) T(BEFORE) T(COPY) T(RESET) /* Closing brace finishes previous block. * Basic attributes (static, dynamic, parsed) can be used with SET. * Dynamic arrays can be used with SET, APPEND, PREPEND. -- 2.39.2