diff options
author | michael <michael@3ae390bd-cb1e-0410-b409-cd5a39f66f1f> | 2009-01-15 15:18:33 +0000 |
---|---|---|
committer | michael <michael@3ae390bd-cb1e-0410-b409-cd5a39f66f1f> | 2009-01-15 15:18:33 +0000 |
commit | 91d11df484b5aad195580d25e8050955334b365d (patch) | |
tree | b302d85c27b0d4ea68fb2bc3dac3249514d8bdcc | |
parent | c184195177c8219d46f687e42234edbc33c0eeb6 (diff) | |
download | lcd4linux-91d11df484b5aad195580d25e8050955334b365d.tar.gz |
layout parser simplified with cfg_rename
git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@968 3ae390bd-cb1e-0410-b409-cd5a39f66f1f
-rw-r--r-- | layout.c | 63 |
1 files changed, 52 insertions, 11 deletions
@@ -49,6 +49,55 @@ #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') { |