]> mj.ucw.cz Git - libucw.git/commitdiff
cleanup of new configuration: operation :unset replaced by :remove
authorRobert Spalek <robert@ucw.cz>
Sun, 7 May 2006 18:43:35 +0000 (20:43 +0200)
committerRobert Spalek <robert@ucw.cz>
Sun, 7 May 2006 18:43:35 +0000 (20:43 +0200)
Why to create a new operations?  Also, cleaned up the procedures so that
have unified interface.

lib/conf-input.c
lib/conf-intr.c
lib/conf-test.cf
lib/getopt.h

index 036181dc81c7aaf48d098fa2db52dedcd69e9003..37147a8de336b8eff886f5a1a21354ff92f85980 100644 (file)
@@ -246,7 +246,6 @@ parse_fastbuf(byte *name_fb, struct fastbuf *fb, uns depth)
       *c++ = 0;
       switch (Clocase(*c)) {
        case 's': op = OP_SET; break;
-       case 'u': op = OP_UNSET; break;
        case 'c': op = Clocase(c[1]) == 'l' ? OP_CLEAR: OP_COPY; break;
        case 'a': switch (Clocase(c[1])) {
                    case 'p': op = OP_APPEND; break;
index 5a5f7eaab0e2c0d60b21fb556f957f400549ea06..2d51fd90daca242b7223f0c1b3e0493e6809b48a 100644 (file)
@@ -226,10 +226,10 @@ interpret_add_list(struct cf_item *item, int number, byte **pars, int *processed
 }
 
 static byte *
-interpret_bitmap(struct cf_item *item, int number, byte **pars, int *processed, u32 *ptr, enum cf_operation op)
+interpret_add_bitmap(struct cf_item *item, int number, byte **pars, int *processed, u32 *ptr, enum cf_operation op)
 {
-  if (item->cls != CC_BITMAP)
-    return cf_printf("Expecting a bitmap");
+  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)
     return cf_printf("Type %s cannot be used with bitmaps", cf_type_names[item->type]);
   cf_journal_block(ptr, sizeof(u32));
@@ -289,15 +289,31 @@ interpret_set_item(struct cf_item *item, int number, byte **pars, int *processed
     case CC_BITMAP:
       if (!allow_dynamic)
        return "Bitmaps cannot be used here";
-      return interpret_bitmap(item, number, pars, processed, ptr, OP_SET);
+      return interpret_add_bitmap(item, number, pars, processed, ptr, OP_SET);
     default:
       ASSERT(0);
   }
 }
 
 static byte *
-interpret_clear(struct cf_item *item, void *ptr)
+interpret_set_all(struct cf_item *item, void *ptr, enum cf_operation op)
 {
+  if (item->cls == CC_BITMAP) {
+    cf_journal_block(ptr, sizeof(u32));
+    if (op == OP_CLEAR)
+      * (u32*) ptr = 0;
+    else
+      if (item->type == CT_INT)
+       * (u32*) ptr = ~0u;
+      else {
+       uns nr = -1;
+       while (item->u.lookup[++nr]);
+       * (u32*) ptr = ~0u >> (32-nr);
+      }
+    return NULL;
+  } else if (op != OP_CLEAR)
+    return "The item is not a bitmap";
+
   if (item->cls == CC_LIST) {
     cf_journal_block(ptr, sizeof(clist));
     clist_init(ptr);
@@ -308,31 +324,11 @@ interpret_clear(struct cf_item *item, void *ptr)
   } else if (item->cls == CC_STATIC && item->type == CT_STRING) {
     cf_journal_block(ptr, item->number * sizeof(byte*));
     bzero(ptr, item->number * sizeof(byte*));
-  } else if (item->cls == CC_BITMAP) {
-    cf_journal_block(ptr, sizeof(u32));
-    * (u32*) ptr = 0;
   } else
     return "The item is not a list, dynamic array, bitmap, or string";
   return NULL;
 }
 
-static byte *
-interpret_set_all(struct cf_item *item, void *ptr)
-{
-  if (item->cls == CC_BITMAP) {
-    cf_journal_block(ptr, sizeof(u32));
-    if (item->type == CT_INT)
-      * (u32*) ptr = ~0u;
-    else {
-      uns nr = -1;
-      while (item->u.lookup[++nr]);
-      * (u32*) ptr = ~0u >> (32-nr);
-    }
-    return NULL;
-  } else
-    return "The item is not a bitmap";
-}
-
 static int
 cmp_items(void *i1, void *i2, struct cf_item *item)
 {
@@ -421,8 +417,8 @@ opening_brace(struct cf_item *item, void *ptr, enum cf_operation op)
     cf_init_section(item->name, item->u.sec, stack[level].base_ptr, 1);
     stack[level].list = ptr;
     stack[level].item = item;
-    if (pure_op == OP_UNSET || pure_op == OP_ALL)
-      return "Bitmap operations are not supported for lists";
+    if (pure_op == OP_ALL)
+      return "Operation ALL cannot be applied on lists";
     else if (pure_op < OP_REMOVE) {
       add_to_list(ptr, stack[level].base_ptr, pure_op);
       stack[level].op |= OP_2ND;
@@ -543,18 +539,16 @@ cf_interpret_line(byte *name, enum cf_operation op, int number, byte **pars)
   op &= OP_MASK;
 
   int taken = 0;               // process as many parameters as possible
-  if (op == OP_CLEAR)
-    msg = interpret_clear(item, ptr);
-  else if (op == OP_ALL)
-    msg = interpret_set_all(item, ptr);
+  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 (op == OP_UNSET)
-    msg = interpret_bitmap(item, number, pars, &taken, ptr, OP_UNSET);
   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);
   if (msg)
@@ -591,13 +585,8 @@ cf_write_item(struct cf_item *item, enum cf_operation op, int number, byte **par
       msg = interpret_set_item(item, number, pars, &taken, item->ptr, 1);
       break;
     case OP_CLEAR:
-      msg = interpret_clear(item, item->ptr);
-      break;
-    case OP_UNSET:
-      msg = interpret_bitmap(item, number, pars, &taken, item->ptr, OP_UNSET);
-      break;
     case OP_ALL:
-      msg = interpret_set_all(item, item->ptr);
+      msg = interpret_set_all(item, item->ptr, op);
       break;
     case OP_APPEND:
     case OP_PREPEND:
@@ -606,7 +595,13 @@ cf_write_item(struct cf_item *item, enum cf_operation op, int number, byte **par
       else if (item->cls == CC_LIST)
        msg = interpret_add_list(item, number, pars, &taken, item->ptr, op);
       else
-       return "The attribute class does not support append/prepend";
+       return "The attribute does not support append/prepend";
+      break;
+    case OP_REMOVE:
+      if (item->cls == CC_BITMAP)
+       msg = interpret_add_bitmap(item, number, pars, &taken, item->ptr, op);
+      else
+       return "Only applicable on bitmaps";
       break;
     default:
       return "Unsupported operation";
index 43dbfdaea468ed697b793fe73f5087641792b323..91e6cc3b08b3eefb5bc32000b4f9cf451d646351 100644 (file)
@@ -27,9 +27,9 @@ Top { \
   look:prepend Beta GAMMA
   numbers 11000 65535
   bitmap1 31
-  bitmap1:unset 3 3
+  bitmap1:remove 3 3
   bitmap2:all
-  bitmap2:unset eleven twelve one
+  bitmap2:remove eleven twelve one
 };;;;;;
 
 unknown.ignored :-)
index 042a1b05eaec65407fa563a3a14b6420c33bf152..fee099a259ef05f94b39838282b125a52c0aef83 100644 (file)
@@ -22,7 +22,7 @@ int cf_set(byte *string);
 
 /* Direct access to configuration items: conf-intr.c */
 
-#define CF_OPERATIONS T(CLOSE) T(SET) T(CLEAR) T(UNSET) T(ALL) \
+#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)
   /* Closing brace finishes previous block.
    * Basic attributes (static, dynamic, parsed) can be used with SET.