* of the GNU Lesser General Public License.
*/
-#include "ucw/lib.h"
-#include "ucw/conf.h"
-#include "ucw/getopt.h"
-#include "ucw/conf-internal.h"
-#include "ucw/clists.h"
+#include <ucw/lib.h>
+#include <ucw/conf.h>
+#include <ucw/getopt.h>
+#include <ucw/conf-internal.h>
+#include <ucw/clists.h>
#include <string.h>
#include <stdio.h>
static char *
interpret_add_bitmap(struct cf_item *item, int number, char **pars, int *processed, u32 *ptr, enum cf_operation op)
{
+ if (op == OP_PREPEND || op == OP_APPEND)
+ op = OP_SET;
if (op != OP_SET && op != OP_REMOVE)
return cf_printf("Cannot apply operation %s on a bitmap", cf_op_names[op]);
else if (item->type != CT_INT && item->type != CT_LOOKUP)
}
}
+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)
{
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)
break;
case OP_APPEND:
case OP_PREPEND:
- if (item->cls == CC_DYNAMIC)
- msg = interpret_add_dynamic(item, number, pars, &taken, item->ptr, op);
- else if (item->cls == CC_LIST)
- msg = interpret_add_list(item, number, pars, &taken, item->ptr, op);
- else
- return "The attribute does not support append/prepend";
+ switch (item->cls) {
+ case CC_DYNAMIC:
+ msg = interpret_add_dynamic(item, number, pars, &taken, item->ptr, op);
+ break;
+ case CC_LIST:
+ msg = interpret_add_list(item, number, pars, &taken, item->ptr, op);
+ break;
+ case CC_BITMAP:
+ msg = interpret_add_bitmap(item, number, pars, &taken, item->ptr, op);
+ break;
+ default:
+ return "The attribute does not support append/prepend";
+ }
break;
case OP_REMOVE:
if (item->cls == CC_BITMAP)