]> git.webhop.me Git - lcd4linux.git/commitdiff
layout parser simplified with cfg_rename
authormichael <michael@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Thu, 15 Jan 2009 15:18:33 +0000 (15:18 +0000)
committermichael <michael@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Thu, 15 Jan 2009 15:18:33 +0000 (15:18 +0000)
git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@968 3ae390bd-cb1e-0410-b409-cd5a39f66f1f

layout.c

index a33f9532dd31af390df005fe9efdd62a785edcb8..bdfbd0ae3c1b9e78a98114821fa4d2f996e69f5f 100644 (file)
--- a/layout.c
+++ b/layout.c
 #endif
 
 
+/* rename old-style widgets without layer */
+static int layout_migrate(const char *section)
+{
+    char *list, *old, *new;
+    int row, col;
+
+    /* get a list of all keys in this section */
+    list = cfg_list(section);
+
+    /* map to lower char for scanf() */
+    for (old = list; *old != '\0'; old++)
+       *old = tolower(*old);
+
+    old = list;
+    while (old != NULL) {
+
+       char *p;
+       int i, n;
+
+       /* list is delimited by | */
+       while (*old == '|')
+           old++;
+       if ((p = strchr(old, '|')) != NULL)
+           *p = '\0';
+
+       /* row/col widgets w/o layer */
+       i = sscanf(old, "row%d.col%d%n", &row, &col, &n);
+       if (i == 2 && old[n] == '\0') {
+
+           /* prepare new key */
+           /* strlen("Layer:1.")=8 */
+           new = malloc(strlen(old) + 9);
+           strcpy(new, "Layer:1.");
+           strcat(new, old);
+
+           debug("%s: migrating '%s' to '%s'", section, old, new);
+           if (cfg_rename(section, old, new) < 0) {
+               error("WARNING: %s: both keys '%s' and '%s' may not exist!", section, old, new);
+           }
+       }
+
+       /* next field */
+       old = p ? p + 1 : NULL;
+    }
+    free(list);
+    return 0;
+}
+
+
 int layout_init(const char *layout)
 {
     char *section;
@@ -64,6 +113,9 @@ int layout_init(const char *layout)
     strcpy(section, "Layout:");
     strcat(section, layout);
 
+    /* mirate layout to common format */
+    layout_migrate(section);
+
     /* get a list of all keys in this section */
     list = cfg_list(section);
 
@@ -111,17 +163,6 @@ int layout_init(const char *layout)
            }
        }
 
-       /* row/col widgets w/o layer */
-       i = sscanf(l, "row%d.col%d%n", &row, &col, &n);
-       if (i == 2 && l[n] == '\0') {
-           widget = cfg_get(section, l, NULL);
-           if (widget != NULL && *widget != '\0') {
-               /* default is layer 1 if outside layer section */
-               widget_add(widget, WIDGET_TYPE_RC, 1, row - 1, col - 1);
-           }
-           free(widget);
-       }
-
        /* GPO widgets */
        i = sscanf(l, "gpo%d%n", &num, &n);
        if (i == 1 && l[n] == '\0') {