layout parser simplified with cfg_rename

git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@968 3ae390bd-cb1e-0410-b409-cd5a39f66f1f
This commit is contained in:
michael
2009-01-15 15:18:33 +00:00
parent c184195177
commit 91d11df484
+52 -11
View File
@@ -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') {