~ubuntu-branches/ubuntu/lucid/stfl/lucid

« back to all changes in this revision

Viewing changes to style.c

  • Committer: Bazaar Package Importer
  • Author(s): Nico Golde
  • Date: 2007-08-07 13:06:54 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070807130654-fmvsraotulj0nbri
Tags: 0.15-3
Again added fPIC to CFLAGS. Hopefully all build issues
are fixed now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 *  STFL - The Structured Terminal Forms Language/Library
3
 
 *  Copyright (C) 2006  Clifford Wolf <clifford@clifford.at>
4
 
 *
5
 
 *  This program is free software; you can redistribute it and/or modify
6
 
 *  it under the terms of the GNU General Public License as published by
7
 
 *  the Free Software Foundation; either version 2 of the License, or
8
 
 *  (at your option) any later version.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
 
3
 *  Copyright (C) 2006, 2007  Clifford Wolf <clifford@clifford.at>
 
4
 *
 
5
 *  This library is free software; you can redistribute it and/or
 
6
 *  modify it under the terms of the GNU Lesser General Public
 
7
 *  License as published by the Free Software Foundation; either
 
8
 *  version 3 of the License, or (at your option) any later version.
 
9
 *  
 
10
 *  This library is distributed in the hope that it will be useful,
11
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
 *  Lesser General Public License for more details.
 
14
 *  
 
15
 *  You should have received a copy of the GNU Lesser General Public
 
16
 *  License along with this library; if not, write to the Free Software
 
17
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 
18
 *  MA 02110-1301 USA
18
19
 *
19
20
 *  style.c: Helper functions for text colors and attributes
20
21
 */
23
24
 
24
25
#include <string.h>
25
26
#include <stdlib.h>
 
27
#include <wchar.h>
 
28
 
 
29
static wchar_t *wcssep(wchar_t **stringp, const wchar_t *delim) {
 
30
        register wchar_t *tmp=*stringp;
 
31
        register wchar_t *tmp2=tmp;
 
32
        register const wchar_t *tmp3;
 
33
        if (!*stringp) return 0;
 
34
        for (tmp2=tmp; *tmp2; ++tmp2) {
 
35
                for (tmp3=delim; *tmp3; ++tmp3)
 
36
                        if (*tmp2==*tmp3) {       /* delimiter found */
 
37
                                *tmp2=0;
 
38
                                *stringp=tmp2+1;
 
39
                                return tmp;
 
40
                        }
 
41
        }
 
42
        *stringp=0;
 
43
        return tmp;
 
44
}
 
45
 
26
46
 
27
47
static int stfl_colorpair_begin = -1;
28
48
static int stfl_colorpair_counter = -1;
29
49
 
30
 
void stfl_style(WINDOW *win, const char *style)
 
50
void stfl_style(WINDOW *win, const wchar_t *style)
31
51
{
32
52
        int bg_color = -1, fg_color = -1, attr = A_NORMAL;
33
53
 
34
 
        style += strspn(style, " \t");
 
54
        style += wcsspn(style, L" \t");
35
55
 
36
56
        while (*style)
37
57
        {
38
 
                int field_len = strcspn(style, ",");
39
 
                char field[field_len+1];
40
 
                memcpy(field, style, field_len);
 
58
                int field_len = wcscspn(style, L",");
 
59
                wchar_t field[field_len+1];
 
60
                wmemcpy(field, style, field_len);
41
61
                field[field_len] = 0;
42
62
                style += field_len;
43
63
 
44
 
                if (*style == ',')
 
64
                if (*style == L',')
45
65
                        style++;
46
66
 
47
 
                char *sepp = field;
48
 
                char *key = strsep(&sepp, "=");
49
 
                char *value = strsep(&sepp, "");
 
67
                wchar_t *sepp = field;
 
68
                wchar_t *key = wcssep(&sepp, L"=");
 
69
                wchar_t *value = wcssep(&sepp, L"");
50
70
 
51
71
                if (!key || !value) continue;
52
72
 
53
 
                key += strspn(key, " \t");
54
 
                key = strsep(&key, " \t");
55
 
 
56
 
                value += strspn(value, " \t");
57
 
                value = strsep(&value, " \t");
58
 
 
59
 
                if (!strcmp(key, "bg") || !strcmp(key, "fg"))
 
73
                key += wcsspn(key, L" \t");
 
74
                key = wcssep(&key, L" \t");
 
75
 
 
76
                value += wcsspn(value, L" \t");
 
77
                value = wcssep(&value, L" \t");
 
78
 
 
79
                if (!wcscmp(key, L"bg") || !wcscmp(key, L"fg"))
60
80
                {
61
81
                        int color = -1;
62
 
                        if (!strcmp(value, "black"))
 
82
                        if (!wcscmp(value, L"black"))
63
83
                                color = COLOR_BLACK;
64
84
                        else
65
 
                        if (!strcmp(value, "red"))
 
85
                        if (!wcscmp(value, L"red"))
66
86
                                color = COLOR_RED;
67
87
                        else
68
 
                        if (!strcmp(value, "green"))
 
88
                        if (!wcscmp(value, L"green"))
69
89
                                color = COLOR_GREEN;
70
90
                        else
71
 
                        if (!strcmp(value, "yellow"))
 
91
                        if (!wcscmp(value, L"yellow"))
72
92
                                color = COLOR_YELLOW;
73
93
                        else
74
 
                        if (!strcmp(value, "blue"))
 
94
                        if (!wcscmp(value, L"blue"))
75
95
                                color = COLOR_BLUE;
76
96
                        else
77
 
                        if (!strcmp(value, "magenta"))
 
97
                        if (!wcscmp(value, L"magenta"))
78
98
                                color = COLOR_MAGENTA;
79
99
                        else
80
 
                        if (!strcmp(value, "cyan"))
 
100
                        if (!wcscmp(value, L"cyan"))
81
101
                                color = COLOR_CYAN;
82
102
                        else
83
 
                        if (!strcmp(value, "white"))
 
103
                        if (!wcscmp(value, L"white"))
84
104
                                color = COLOR_WHITE;
85
105
                        else {
86
 
                                fprintf(stderr, "STFL Style Error: Unknown %s color: '%s'\n", key, value);
 
106
                                fprintf(stderr, "STFL Style Error: Unknown %ls color: '%ls'\n", key, value);
87
107
                                abort();
88
108
                        }
89
109
 
90
 
                        if (!strcmp(key, "bg"))
 
110
                        if (!wcscmp(key, L"bg"))
91
111
                                bg_color = color;
92
112
                        else
93
113
                                fg_color = color;
94
114
                }
95
115
                else
96
 
                if (!strcmp(key, "attr"))
 
116
                if (!wcscmp(key, L"attr"))
97
117
                {
98
 
                        if (!strcmp(value, "standout"))
 
118
                        if (!wcscmp(value, L"standout"))
99
119
                                attr |= A_STANDOUT;
100
120
                        else
101
 
                        if (!strcmp(value, "underline"))
 
121
                        if (!wcscmp(value, L"underline"))
102
122
                                attr |= A_UNDERLINE;
103
123
                        else
104
 
                        if (!strcmp(value, "reverse"))
 
124
                        if (!wcscmp(value, L"reverse"))
105
125
                                attr |= A_REVERSE;
106
126
                        else
107
 
                        if (!strcmp(value, "blink"))
 
127
                        if (!wcscmp(value, L"blink"))
108
128
                                attr |= A_BLINK;
109
129
                        else
110
 
                        if (!strcmp(value, "dim"))
 
130
                        if (!wcscmp(value, L"dim"))
111
131
                                attr |= A_DIM;
112
132
                        else
113
 
                        if (!strcmp(value, "bold"))
 
133
                        if (!wcscmp(value, L"bold"))
114
134
                                attr |= A_BOLD;
115
135
                        else
116
 
                        if (!strcmp(value, "protect"))
 
136
                        if (!wcscmp(value, L"protect"))
117
137
                                attr |= A_PROTECT;
118
138
                        else
119
 
                        if (!strcmp(value, "invis"))
 
139
                        if (!wcscmp(value, L"invis"))
120
140
                                attr |= A_INVIS;
121
141
                        else {
122
 
                                fprintf(stderr, "STFL Style Error: Unknown attribute: '%s'\n", value);
 
142
                                fprintf(stderr, "STFL Style Error: Unknown attribute: '%ls'\n", value);
123
143
                                abort();
124
144
                        }
125
145
                }
126
146
                else {
127
 
                        fprintf(stderr, "STFL Style Error: Unknown keyword: '%s'\n", key);
 
147
                        fprintf(stderr, "STFL Style Error: Unknown keyword: '%ls'\n", key);
128
148
                        abort();
129
149
                }
130
150
        }
158
178
 
159
179
void stfl_widget_style(struct stfl_widget *w, struct stfl_form *f, WINDOW *win)
160
180
{
161
 
        const char *style = "";
 
181
        const wchar_t *style = L"";
162
182
 
163
183
        if (f->current_focus_id == w->id)
164
 
                style = stfl_widget_getkv_str(w, "style_focus", "");
 
184
                style = stfl_widget_getkv_str(w, L"style_focus", L"");
165
185
 
166
186
        if (*style == 0)
167
 
                style = stfl_widget_getkv_str(w, "style_normal", "");
 
187
                style = stfl_widget_getkv_str(w, L"style_normal", L"");
168
188
 
169
189
        stfl_style(win, style);
170
190
}