aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/lxdialog/util.c
diff options
context:
space:
mode:
authorSam Ravnborg <sam@mars.ravnborg.org>2005-11-19 13:13:34 -0500
committerSam Ravnborg <sam@mars.ravnborg.org>2005-11-19 13:13:34 -0500
commitb1c5f1c635f4a821f834ed51ccd8a2a1515fffd2 (patch)
tree7325e59c16a2b90fd6f78ab491f7ef48bfd409b9 /scripts/lxdialog/util.c
parentb286e39207237e2f6929959372bf66d9a8d05a82 (diff)
kconfig: Lindent scripts/lxdialog
The lxdialog code was not easy to read. So as first step the code was run through Lindent. Fix-ups will come in next patchset. Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Diffstat (limited to 'scripts/lxdialog/util.c')
-rw-r--r--scripts/lxdialog/util.c467
1 files changed, 229 insertions, 238 deletions
diff --git a/scripts/lxdialog/util.c b/scripts/lxdialog/util.c
index e7bce9be69c3..232b32c4fc38 100644
--- a/scripts/lxdialog/util.c
+++ b/scripts/lxdialog/util.c
@@ -21,7 +21,6 @@
21 21
22#include "dialog.h" 22#include "dialog.h"
23 23
24
25/* use colors by default? */ 24/* use colors by default? */
26bool use_colors = 1; 25bool use_colors = 1;
27 26
@@ -32,326 +31,318 @@ const char *dialog_result;
32/* 31/*
33 * Attribute values, default is for mono display 32 * Attribute values, default is for mono display
34 */ 33 */
35chtype attributes[] = 34chtype attributes[] = {
36{ 35 A_NORMAL, /* screen_attr */
37 A_NORMAL, /* screen_attr */ 36 A_NORMAL, /* shadow_attr */
38 A_NORMAL, /* shadow_attr */ 37 A_NORMAL, /* dialog_attr */
39 A_NORMAL, /* dialog_attr */ 38 A_BOLD, /* title_attr */
40 A_BOLD, /* title_attr */ 39 A_NORMAL, /* border_attr */
41 A_NORMAL, /* border_attr */ 40 A_REVERSE, /* button_active_attr */
42 A_REVERSE, /* button_active_attr */ 41 A_DIM, /* button_inactive_attr */
43 A_DIM, /* button_inactive_attr */ 42 A_REVERSE, /* button_key_active_attr */
44 A_REVERSE, /* button_key_active_attr */ 43 A_BOLD, /* button_key_inactive_attr */
45 A_BOLD, /* button_key_inactive_attr */ 44 A_REVERSE, /* button_label_active_attr */
46 A_REVERSE, /* button_label_active_attr */ 45 A_NORMAL, /* button_label_inactive_attr */
47 A_NORMAL, /* button_label_inactive_attr */ 46 A_NORMAL, /* inputbox_attr */
48 A_NORMAL, /* inputbox_attr */ 47 A_NORMAL, /* inputbox_border_attr */
49 A_NORMAL, /* inputbox_border_attr */ 48 A_NORMAL, /* searchbox_attr */
50 A_NORMAL, /* searchbox_attr */ 49 A_BOLD, /* searchbox_title_attr */
51 A_BOLD, /* searchbox_title_attr */ 50 A_NORMAL, /* searchbox_border_attr */
52 A_NORMAL, /* searchbox_border_attr */ 51 A_BOLD, /* position_indicator_attr */
53 A_BOLD, /* position_indicator_attr */ 52 A_NORMAL, /* menubox_attr */
54 A_NORMAL, /* menubox_attr */ 53 A_NORMAL, /* menubox_border_attr */
55 A_NORMAL, /* menubox_border_attr */ 54 A_NORMAL, /* item_attr */
56 A_NORMAL, /* item_attr */ 55 A_REVERSE, /* item_selected_attr */
57 A_REVERSE, /* item_selected_attr */ 56 A_BOLD, /* tag_attr */
58 A_BOLD, /* tag_attr */ 57 A_REVERSE, /* tag_selected_attr */
59 A_REVERSE, /* tag_selected_attr */ 58 A_BOLD, /* tag_key_attr */
60 A_BOLD, /* tag_key_attr */ 59 A_REVERSE, /* tag_key_selected_attr */
61 A_REVERSE, /* tag_key_selected_attr */ 60 A_BOLD, /* check_attr */
62 A_BOLD, /* check_attr */ 61 A_REVERSE, /* check_selected_attr */
63 A_REVERSE, /* check_selected_attr */ 62 A_BOLD, /* uarrow_attr */
64 A_BOLD, /* uarrow_attr */ 63 A_BOLD /* darrow_attr */
65 A_BOLD /* darrow_attr */
66}; 64};
67 65
68
69#include "colors.h" 66#include "colors.h"
70 67
71/* 68/*
72 * Table of color values 69 * Table of color values
73 */ 70 */
74int color_table[][3] = 71int color_table[][3] = {
75{ 72 {SCREEN_FG, SCREEN_BG, SCREEN_HL},
76 {SCREEN_FG, SCREEN_BG, SCREEN_HL}, 73 {SHADOW_FG, SHADOW_BG, SHADOW_HL},
77 {SHADOW_FG, SHADOW_BG, SHADOW_HL}, 74 {DIALOG_FG, DIALOG_BG, DIALOG_HL},
78 {DIALOG_FG, DIALOG_BG, DIALOG_HL}, 75 {TITLE_FG, TITLE_BG, TITLE_HL},
79 {TITLE_FG, TITLE_BG, TITLE_HL}, 76 {BORDER_FG, BORDER_BG, BORDER_HL},
80 {BORDER_FG, BORDER_BG, BORDER_HL}, 77 {BUTTON_ACTIVE_FG, BUTTON_ACTIVE_BG, BUTTON_ACTIVE_HL},
81 {BUTTON_ACTIVE_FG, BUTTON_ACTIVE_BG, BUTTON_ACTIVE_HL}, 78 {BUTTON_INACTIVE_FG, BUTTON_INACTIVE_BG, BUTTON_INACTIVE_HL},
82 {BUTTON_INACTIVE_FG, BUTTON_INACTIVE_BG, BUTTON_INACTIVE_HL}, 79 {BUTTON_KEY_ACTIVE_FG, BUTTON_KEY_ACTIVE_BG, BUTTON_KEY_ACTIVE_HL},
83 {BUTTON_KEY_ACTIVE_FG, BUTTON_KEY_ACTIVE_BG, BUTTON_KEY_ACTIVE_HL}, 80 {BUTTON_KEY_INACTIVE_FG, BUTTON_KEY_INACTIVE_BG,
84 {BUTTON_KEY_INACTIVE_FG, BUTTON_KEY_INACTIVE_BG, BUTTON_KEY_INACTIVE_HL}, 81 BUTTON_KEY_INACTIVE_HL},
85 {BUTTON_LABEL_ACTIVE_FG, BUTTON_LABEL_ACTIVE_BG, BUTTON_LABEL_ACTIVE_HL}, 82 {BUTTON_LABEL_ACTIVE_FG, BUTTON_LABEL_ACTIVE_BG,
86 {BUTTON_LABEL_INACTIVE_FG, BUTTON_LABEL_INACTIVE_BG, 83 BUTTON_LABEL_ACTIVE_HL},
87 BUTTON_LABEL_INACTIVE_HL}, 84 {BUTTON_LABEL_INACTIVE_FG, BUTTON_LABEL_INACTIVE_BG,
88 {INPUTBOX_FG, INPUTBOX_BG, INPUTBOX_HL}, 85 BUTTON_LABEL_INACTIVE_HL},
89 {INPUTBOX_BORDER_FG, INPUTBOX_BORDER_BG, INPUTBOX_BORDER_HL}, 86 {INPUTBOX_FG, INPUTBOX_BG, INPUTBOX_HL},
90 {SEARCHBOX_FG, SEARCHBOX_BG, SEARCHBOX_HL}, 87 {INPUTBOX_BORDER_FG, INPUTBOX_BORDER_BG, INPUTBOX_BORDER_HL},
91 {SEARCHBOX_TITLE_FG, SEARCHBOX_TITLE_BG, SEARCHBOX_TITLE_HL}, 88 {SEARCHBOX_FG, SEARCHBOX_BG, SEARCHBOX_HL},
92 {SEARCHBOX_BORDER_FG, SEARCHBOX_BORDER_BG, SEARCHBOX_BORDER_HL}, 89 {SEARCHBOX_TITLE_FG, SEARCHBOX_TITLE_BG, SEARCHBOX_TITLE_HL},
93 {POSITION_INDICATOR_FG, POSITION_INDICATOR_BG, POSITION_INDICATOR_HL}, 90 {SEARCHBOX_BORDER_FG, SEARCHBOX_BORDER_BG, SEARCHBOX_BORDER_HL},
94 {MENUBOX_FG, MENUBOX_BG, MENUBOX_HL}, 91 {POSITION_INDICATOR_FG, POSITION_INDICATOR_BG, POSITION_INDICATOR_HL},
95 {MENUBOX_BORDER_FG, MENUBOX_BORDER_BG, MENUBOX_BORDER_HL}, 92 {MENUBOX_FG, MENUBOX_BG, MENUBOX_HL},
96 {ITEM_FG, ITEM_BG, ITEM_HL}, 93 {MENUBOX_BORDER_FG, MENUBOX_BORDER_BG, MENUBOX_BORDER_HL},
97 {ITEM_SELECTED_FG, ITEM_SELECTED_BG, ITEM_SELECTED_HL}, 94 {ITEM_FG, ITEM_BG, ITEM_HL},
98 {TAG_FG, TAG_BG, TAG_HL}, 95 {ITEM_SELECTED_FG, ITEM_SELECTED_BG, ITEM_SELECTED_HL},
99 {TAG_SELECTED_FG, TAG_SELECTED_BG, TAG_SELECTED_HL}, 96 {TAG_FG, TAG_BG, TAG_HL},
100 {TAG_KEY_FG, TAG_KEY_BG, TAG_KEY_HL}, 97 {TAG_SELECTED_FG, TAG_SELECTED_BG, TAG_SELECTED_HL},
101 {TAG_KEY_SELECTED_FG, TAG_KEY_SELECTED_BG, TAG_KEY_SELECTED_HL}, 98 {TAG_KEY_FG, TAG_KEY_BG, TAG_KEY_HL},
102 {CHECK_FG, CHECK_BG, CHECK_HL}, 99 {TAG_KEY_SELECTED_FG, TAG_KEY_SELECTED_BG, TAG_KEY_SELECTED_HL},
103 {CHECK_SELECTED_FG, CHECK_SELECTED_BG, CHECK_SELECTED_HL}, 100 {CHECK_FG, CHECK_BG, CHECK_HL},
104 {UARROW_FG, UARROW_BG, UARROW_HL}, 101 {CHECK_SELECTED_FG, CHECK_SELECTED_BG, CHECK_SELECTED_HL},
105 {DARROW_FG, DARROW_BG, DARROW_HL}, 102 {UARROW_FG, UARROW_BG, UARROW_HL},
103 {DARROW_FG, DARROW_BG, DARROW_HL},
106}; /* color_table */ 104}; /* color_table */
107 105
108/* 106/*
109 * Set window to attribute 'attr' 107 * Set window to attribute 'attr'
110 */ 108 */
111void 109void attr_clear(WINDOW * win, int height, int width, chtype attr)
112attr_clear (WINDOW * win, int height, int width, chtype attr)
113{ 110{
114 int i, j; 111 int i, j;
115 112
116 wattrset (win, attr); 113 wattrset(win, attr);
117 for (i = 0; i < height; i++) { 114 for (i = 0; i < height; i++) {
118 wmove (win, i, 0); 115 wmove(win, i, 0);
119 for (j = 0; j < width; j++) 116 for (j = 0; j < width; j++)
120 waddch (win, ' '); 117 waddch(win, ' ');
121 } 118 }
122 touchwin (win); 119 touchwin(win);
123} 120}
124 121
125void dialog_clear (void) 122void dialog_clear(void)
126{ 123{
127 attr_clear (stdscr, LINES, COLS, screen_attr); 124 attr_clear(stdscr, LINES, COLS, screen_attr);
128 /* Display background title if it exists ... - SLH */ 125 /* Display background title if it exists ... - SLH */
129 if (backtitle != NULL) { 126 if (backtitle != NULL) {
130 int i; 127 int i;
131 128
132 wattrset (stdscr, screen_attr); 129 wattrset(stdscr, screen_attr);
133 mvwaddstr (stdscr, 0, 1, (char *)backtitle); 130 mvwaddstr(stdscr, 0, 1, (char *)backtitle);
134 wmove (stdscr, 1, 1); 131 wmove(stdscr, 1, 1);
135 for (i = 1; i < COLS - 1; i++) 132 for (i = 1; i < COLS - 1; i++)
136 waddch (stdscr, ACS_HLINE); 133 waddch(stdscr, ACS_HLINE);
137 } 134 }
138 wnoutrefresh (stdscr); 135 wnoutrefresh(stdscr);
139} 136}
140 137
141/* 138/*
142 * Do some initialization for dialog 139 * Do some initialization for dialog
143 */ 140 */
144void 141void init_dialog(void)
145init_dialog (void)
146{ 142{
147 initscr (); /* Init curses */ 143 initscr(); /* Init curses */
148 keypad (stdscr, TRUE); 144 keypad(stdscr, TRUE);
149 cbreak (); 145 cbreak();
150 noecho (); 146 noecho();
151 147
148 if (use_colors) /* Set up colors */
149 color_setup();
152 150
153 if (use_colors) /* Set up colors */ 151 dialog_clear();
154 color_setup ();
155
156
157 dialog_clear ();
158} 152}
159 153
160/* 154/*
161 * Setup for color display 155 * Setup for color display
162 */ 156 */
163void 157void color_setup(void)
164color_setup (void)
165{ 158{
166 int i; 159 int i;
167 160
168 if (has_colors ()) { /* Terminal supports color? */ 161 if (has_colors()) { /* Terminal supports color? */
169 start_color (); 162 start_color();
170 163
171 /* Initialize color pairs */ 164 /* Initialize color pairs */
172 for (i = 0; i < ATTRIBUTE_COUNT; i++) 165 for (i = 0; i < ATTRIBUTE_COUNT; i++)
173 init_pair (i + 1, color_table[i][0], color_table[i][1]); 166 init_pair(i + 1, color_table[i][0], color_table[i][1]);
174 167
175 /* Setup color attributes */ 168 /* Setup color attributes */
176 for (i = 0; i < ATTRIBUTE_COUNT; i++) 169 for (i = 0; i < ATTRIBUTE_COUNT; i++)
177 attributes[i] = C_ATTR (color_table[i][2], i + 1); 170 attributes[i] = C_ATTR(color_table[i][2], i + 1);
178 } 171 }
179} 172}
180 173
181/* 174/*
182 * End using dialog functions. 175 * End using dialog functions.
183 */ 176 */
184void 177void end_dialog(void)
185end_dialog (void)
186{ 178{
187 endwin (); 179 endwin();
188} 180}
189 181
190
191/* 182/*
192 * Print a string of text in a window, automatically wrap around to the 183 * Print a string of text in a window, automatically wrap around to the
193 * next line if the string is too long to fit on one line. Newline 184 * next line if the string is too long to fit on one line. Newline
194 * characters '\n' are replaced by spaces. We start on a new line 185 * characters '\n' are replaced by spaces. We start on a new line
195 * if there is no room for at least 4 nonblanks following a double-space. 186 * if there is no room for at least 4 nonblanks following a double-space.
196 */ 187 */
197void 188void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x)
198print_autowrap (WINDOW * win, const char *prompt, int width, int y, int x)
199{ 189{
200 int newl, cur_x, cur_y; 190 int newl, cur_x, cur_y;
201 int i, prompt_len, room, wlen; 191 int i, prompt_len, room, wlen;
202 char tempstr[MAX_LEN + 1], *word, *sp, *sp2; 192 char tempstr[MAX_LEN + 1], *word, *sp, *sp2;
203 193
204 strcpy (tempstr, prompt); 194 strcpy(tempstr, prompt);
205 195
206 prompt_len = strlen(tempstr); 196 prompt_len = strlen(tempstr);
207 197
208 /* 198 /*
209 * Remove newlines 199 * Remove newlines
210 */ 200 */
211 for(i=0; i<prompt_len; i++) { 201 for (i = 0; i < prompt_len; i++) {
212 if(tempstr[i] == '\n') tempstr[i] = ' '; 202 if (tempstr[i] == '\n')
213 } 203 tempstr[i] = ' ';
214 204 }
215 if (prompt_len <= width - x * 2) { /* If prompt is short */ 205
216 wmove (win, y, (width - prompt_len) / 2); 206 if (prompt_len <= width - x * 2) { /* If prompt is short */
217 waddstr (win, tempstr); 207 wmove(win, y, (width - prompt_len) / 2);
218 } else { 208 waddstr(win, tempstr);
219 cur_x = x; 209 } else {
220 cur_y = y;
221 newl = 1;
222 word = tempstr;
223 while (word && *word) {
224 sp = index(word, ' ');
225 if (sp)
226 *sp++ = 0;
227
228 /* Wrap to next line if either the word does not fit,
229 or it is the first word of a new sentence, and it is
230 short, and the next word does not fit. */
231 room = width - cur_x;
232 wlen = strlen(word);
233 if (wlen > room ||
234 (newl && wlen < 4 && sp && wlen+1+strlen(sp) > room
235 && (!(sp2 = index(sp, ' ')) || wlen+1+(sp2-sp) > room))) {
236 cur_y++;
237 cur_x = x; 210 cur_x = x;
238 } 211 cur_y = y;
239 wmove (win, cur_y, cur_x);
240 waddstr (win, word);
241 getyx (win, cur_y, cur_x);
242 cur_x++;
243 if (sp && *sp == ' ') {
244 cur_x++; /* double space */
245 while (*++sp == ' ');
246 newl = 1; 212 newl = 1;
247 } else 213 word = tempstr;
248 newl = 0; 214 while (word && *word) {
249 word = sp; 215 sp = index(word, ' ');
216 if (sp)
217 *sp++ = 0;
218
219 /* Wrap to next line if either the word does not fit,
220 or it is the first word of a new sentence, and it is
221 short, and the next word does not fit. */
222 room = width - cur_x;
223 wlen = strlen(word);
224 if (wlen > room ||
225 (newl && wlen < 4 && sp
226 && wlen + 1 + strlen(sp) > room
227 && (!(sp2 = index(sp, ' '))
228 || wlen + 1 + (sp2 - sp) > room))) {
229 cur_y++;
230 cur_x = x;
231 }
232 wmove(win, cur_y, cur_x);
233 waddstr(win, word);
234 getyx(win, cur_y, cur_x);
235 cur_x++;
236 if (sp && *sp == ' ') {
237 cur_x++; /* double space */
238 while (*++sp == ' ') ;
239 newl = 1;
240 } else
241 newl = 0;
242 word = sp;
243 }
250 } 244 }
251 }
252} 245}
253 246
254/* 247/*
255 * Print a button 248 * Print a button
256 */ 249 */
257void 250void print_button(WINDOW * win, const char *label, int y, int x, int selected)
258print_button (WINDOW * win, const char *label, int y, int x, int selected)
259{ 251{
260 int i, temp; 252 int i, temp;
261 253
262 wmove (win, y, x); 254 wmove(win, y, x);
263 wattrset (win, selected ? button_active_attr : button_inactive_attr); 255 wattrset(win, selected ? button_active_attr : button_inactive_attr);
264 waddstr (win, "<"); 256 waddstr(win, "<");
265 temp = strspn (label, " "); 257 temp = strspn(label, " ");
266 label += temp; 258 label += temp;
267 wattrset (win, selected ? button_label_active_attr 259 wattrset(win, selected ? button_label_active_attr
268 : button_label_inactive_attr); 260 : button_label_inactive_attr);
269 for (i = 0; i < temp; i++) 261 for (i = 0; i < temp; i++)
270 waddch (win, ' '); 262 waddch(win, ' ');
271 wattrset (win, selected ? button_key_active_attr 263 wattrset(win, selected ? button_key_active_attr
272 : button_key_inactive_attr); 264 : button_key_inactive_attr);
273 waddch (win, label[0]); 265 waddch(win, label[0]);
274 wattrset (win, selected ? button_label_active_attr 266 wattrset(win, selected ? button_label_active_attr
275 : button_label_inactive_attr); 267 : button_label_inactive_attr);
276 waddstr (win, (char *)label + 1); 268 waddstr(win, (char *)label + 1);
277 wattrset (win, selected ? button_active_attr : button_inactive_attr); 269 wattrset(win, selected ? button_active_attr : button_inactive_attr);
278 waddstr (win, ">"); 270 waddstr(win, ">");
279 wmove (win, y, x + temp + 1); 271 wmove(win, y, x + temp + 1);
280} 272}
281 273
282/* 274/*
283 * Draw a rectangular box with line drawing characters 275 * Draw a rectangular box with line drawing characters
284 */ 276 */
285void 277void
286draw_box (WINDOW * win, int y, int x, int height, int width, 278draw_box(WINDOW * win, int y, int x, int height, int width,
287 chtype box, chtype border) 279 chtype box, chtype border)
288{ 280{
289 int i, j; 281 int i, j;
290 282
291 wattrset (win, 0); 283 wattrset(win, 0);
292 for (i = 0; i < height; i++) { 284 for (i = 0; i < height; i++) {
293 wmove (win, y + i, x); 285 wmove(win, y + i, x);
294 for (j = 0; j < width; j++) 286 for (j = 0; j < width; j++)
295 if (!i && !j) 287 if (!i && !j)
296 waddch (win, border | ACS_ULCORNER); 288 waddch(win, border | ACS_ULCORNER);
297 else if (i == height - 1 && !j) 289 else if (i == height - 1 && !j)
298 waddch (win, border | ACS_LLCORNER); 290 waddch(win, border | ACS_LLCORNER);
299 else if (!i && j == width - 1) 291 else if (!i && j == width - 1)
300 waddch (win, box | ACS_URCORNER); 292 waddch(win, box | ACS_URCORNER);
301 else if (i == height - 1 && j == width - 1) 293 else if (i == height - 1 && j == width - 1)
302 waddch (win, box | ACS_LRCORNER); 294 waddch(win, box | ACS_LRCORNER);
303 else if (!i) 295 else if (!i)
304 waddch (win, border | ACS_HLINE); 296 waddch(win, border | ACS_HLINE);
305 else if (i == height - 1) 297 else if (i == height - 1)
306 waddch (win, box | ACS_HLINE); 298 waddch(win, box | ACS_HLINE);
307 else if (!j) 299 else if (!j)
308 waddch (win, border | ACS_VLINE); 300 waddch(win, border | ACS_VLINE);
309 else if (j == width - 1) 301 else if (j == width - 1)
310 waddch (win, box | ACS_VLINE); 302 waddch(win, box | ACS_VLINE);
311 else 303 else
312 waddch (win, box | ' '); 304 waddch(win, box | ' ');
313 } 305 }
314} 306}
315 307
316/* 308/*
317 * Draw shadows along the right and bottom edge to give a more 3D look 309 * Draw shadows along the right and bottom edge to give a more 3D look
318 * to the boxes 310 * to the boxes
319 */ 311 */
320void 312void draw_shadow(WINDOW * win, int y, int x, int height, int width)
321draw_shadow (WINDOW * win, int y, int x, int height, int width)
322{ 313{
323 int i; 314 int i;
324 315
325 if (has_colors ()) { /* Whether terminal supports color? */ 316 if (has_colors()) { /* Whether terminal supports color? */
326 wattrset (win, shadow_attr); 317 wattrset(win, shadow_attr);
327 wmove (win, y + height, x + 2); 318 wmove(win, y + height, x + 2);
328 for (i = 0; i < width; i++) 319 for (i = 0; i < width; i++)
329 waddch (win, winch (win) & A_CHARTEXT); 320 waddch(win, winch(win) & A_CHARTEXT);
330 for (i = y + 1; i < y + height + 1; i++) { 321 for (i = y + 1; i < y + height + 1; i++) {
331 wmove (win, i, x + width); 322 wmove(win, i, x + width);
332 waddch (win, winch (win) & A_CHARTEXT); 323 waddch(win, winch(win) & A_CHARTEXT);
333 waddch (win, winch (win) & A_CHARTEXT); 324 waddch(win, winch(win) & A_CHARTEXT);
325 }
326 wnoutrefresh(win);
334 } 327 }
335 wnoutrefresh (win);
336 }
337} 328}
338 329
339/* 330/*
340 * Return the position of the first alphabetic character in a string. 331 * Return the position of the first alphabetic character in a string.
341 */ 332 */
342int 333int first_alpha(const char *string, const char *exempt)
343first_alpha(const char *string, const char *exempt)
344{ 334{
345 int i, in_paren=0, c; 335 int i, in_paren = 0, c;
346 336
347 for (i = 0; i < strlen(string); i++) { 337 for (i = 0; i < strlen(string); i++) {
348 c = tolower(string[i]); 338 c = tolower(string[i]);
349 339
350 if (strchr("<[(", c)) ++in_paren; 340 if (strchr("<[(", c))
351 if (strchr(">])", c) && in_paren > 0) --in_paren; 341 ++in_paren;
342 if (strchr(">])", c) && in_paren > 0)
343 --in_paren;
352 344
353 if ((! in_paren) && isalpha(c) && 345 if ((!in_paren) && isalpha(c) && strchr(exempt, c) == 0)
354 strchr(exempt, c) == 0)
355 return i; 346 return i;
356 } 347 }
357 348