]> mj.ucw.cz Git - libucw.git/blobdiff - lib/shell/config.c
I decided to turn off cf/url-equiv for indexation. however, after the indexer
[libucw.git] / lib / shell / config.c
index ac9cd5325ccec5ac090f7a89fb02a51e9bbdf37e..e00ca8f4f595f8ad944ccbdd8150a88580cb7354 100644 (file)
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <alloca.h>
+
+static struct cfitem *items;
+static byte *flags;
 
 static void
 help(void)
 {
-  die("Usage: config [-C<configfile>] [-S<section>.<option>=<value>] <section> <item>[=<default>] <item2> ... [*]");
+  die("Usage: config [-C<configfile>] [-S<section>.<option>=<value>] <section> [@]<item>[=<default>] <item2> ... [*]");
+}
+
+static byte *
+report(struct cfitem *item, byte *value)
+{
+  if (flags[item-items])
+    printf("CF_%s[${#CF_%s[*]}]='", item->name, item->name);
+  else
+    printf("CF_%s='", item->name);
+  while (*value)
+    {
+      if (*value == '\'')
+       die("Apostrophes are not supported in config of scripts");
+      putchar(*value++);
+    }
+  puts("'");
+  return NULL;
 }
 
 int main(int argc, char **argv)
 {
   int i = 1;
   int start;
-  struct cfitem *items, *c;
-  byte **vars;
+  struct cfitem *c;
 
   log_init("config");
   while (i < argc && argv[i][0] == '-')
@@ -42,7 +62,8 @@ int main(int argc, char **argv)
     help();
   start = i;
   c = items = alloca(sizeof(struct cfitem) * (argc-i+1));
-  vars = alloca(sizeof(byte *) * argc);
+  flags = alloca(argc);
+  bzero(flags, argc);
   c->name = argv[i];
   c->type = CT_SECTION;
   c->var = NULL;
@@ -53,15 +74,20 @@ int main(int argc, char **argv)
        items->type = CT_INCOMPLETE_SECTION;
       else
        {
-         byte *e = strchr(argv[i], '=');
+         char *e = strchr(argv[i], '=');
+         c->name = argv[i];
+         c->type = CT_FUNCTION;
+         c->var = report;
          if (e)
            *e++ = 0;
-         else
-           e = "";
-         c->name = argv[i];
-         c->type = CT_STRING;
-         c->var = &vars[i];
-         *(byte **)c->var = e;
+         if (*c->name == '@')
+           {
+             c->name++;
+             printf("declare -a CF_%s ; CF_%s=()\n", c->name, c->name);
+             flags[c-items] = 1;
+           }
+         if (e)
+           report(c, e);
          c++;
        }
     }
@@ -69,13 +95,5 @@ int main(int argc, char **argv)
   cf_register(items);
   if (cf_getopt(start, argv, CF_SHORT_OPTS, CF_NO_LONG_OPTS, NULL) != -1)
     help();
-
-  c = items+1;
-  while (c->type)
-    {
-      printf("CF_%s=\"%s\"\n", c->name, *(byte **)c->var);
-      c++;
-    }
-
   return 0;
 }