~siretart/lcd4linux/debian

« back to all changes in this revision

Viewing changes to layout.c

  • Committer: Reinhard Tartler
  • Date: 2011-04-27 17:28:49 UTC
  • mfrom: (0.1.1 upstream)
  • Revision ID: siretart@tauware.de-20110427172849-mj5cj5a0igpcc9fn
New upstream snapshot

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: layout.c 728 2007-01-14 11:14:38Z michael $
2
 
 * $URL: https://ssl.bulix.org/svn/lcd4linux/branches/0.10.1/layout.c $
 
1
/* $Id: layout.c 1057 2009-11-17 01:47:43Z edman007 $
 
2
 * $URL: https://ssl.bulix.org/svn/lcd4linux/trunk/layout.c $
3
3
 *
4
4
 * new layouter framework
5
5
 *
6
 
 * Copyright (C) 2003 Michael Reinelt <reinelt@eunet.at>
 
6
 * Copyright (C) 2003 Michael Reinelt <michael@reinelt.co.at>
7
7
 * Copyright (C) 2004 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net>
8
8
 *
9
9
 * This file is part of LCD4Linux.
49
49
#endif
50
50
 
51
51
 
 
52
/* rename old-style widgets without layer */
 
53
static int layout_migrate(const char *section)
 
54
{
 
55
    char *list, *old, *new;
 
56
    int row, col;
 
57
 
 
58
    /* get a list of all keys in this section */
 
59
    list = cfg_list(section);
 
60
 
 
61
    /* map to lower char for scanf() */
 
62
    for (old = list; *old != '\0'; old++)
 
63
        *old = tolower(*old);
 
64
 
 
65
    old = list;
 
66
    while (old != NULL) {
 
67
 
 
68
        char *p;
 
69
        int i, n;
 
70
 
 
71
        /* list is delimited by | */
 
72
        while (*old == '|')
 
73
            old++;
 
74
        if ((p = strchr(old, '|')) != NULL)
 
75
            *p = '\0';
 
76
 
 
77
        /* row/col widgets w/o layer */
 
78
        i = sscanf(old, "row%d.col%d%n", &row, &col, &n);
 
79
        if (i == 2 && old[n] == '\0') {
 
80
 
 
81
            /* prepare new key */
 
82
            /* strlen("Layer:1.")=8 */
 
83
            new = malloc(strlen(old) + 9);
 
84
            strcpy(new, "Layer:1.");
 
85
            strcat(new, old);
 
86
 
 
87
            debug("%s: migrating '%s' to '%s'", section, old, new);
 
88
            if (cfg_rename(section, old, new) < 0) {
 
89
                error("WARNING: %s: both keys '%s' and '%s' may not exist!", section, old, new);
 
90
            }
 
91
            free(new);
 
92
        }
 
93
 
 
94
        /* next field */
 
95
        old = p ? p + 1 : NULL;
 
96
    }
 
97
    free(list);
 
98
    return 0;
 
99
}
 
100
 
 
101
 
52
102
int layout_init(const char *layout)
53
103
{
54
104
    char *section;
64
114
    strcpy(section, "Layout:");
65
115
    strcat(section, layout);
66
116
 
 
117
    /* mirate layout to common format */
 
118
    layout_migrate(section);
 
119
 
67
120
    /* get a list of all keys in this section */
68
121
    list = cfg_list(section);
69
122
 
111
164
            }
112
165
        }
113
166
 
114
 
        /* row/col widgets w/o layer */
115
 
        i = sscanf(l, "row%d.col%d%n", &row, &col, &n);
116
 
        if (i == 2 && l[n] == '\0') {
117
 
            widget = cfg_get(section, l, NULL);
118
 
            if (widget != NULL && *widget != '\0') {
119
 
                /* default is layer 1 if outside layer section */
120
 
                widget_add(widget, WIDGET_TYPE_RC, 1, row - 1, col - 1);
121
 
            }
122
 
            free(widget);
123
 
        }
124
 
 
125
167
        /* GPO widgets */
126
168
        i = sscanf(l, "gpo%d%n", &num, &n);
127
169
        if (i == 1 && l[n] == '\0') {