Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * util.c |
| 3 | * |
| 4 | * ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk) |
| 5 | * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcap@cfw.com) |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; either version 2 |
| 10 | * of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 | */ |
| 21 | |
| 22 | #include "dialog.h" |
| 23 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | /* use colors by default? */ |
| 25 | bool use_colors = 1; |
| 26 | |
| 27 | const char *backtitle = NULL; |
| 28 | |
| 29 | const char *dialog_result; |
| 30 | |
Sam Ravnborg | dec69da | 2005-11-19 21:56:20 +0100 | [diff] [blame^] | 31 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | * Attribute values, default is for mono display |
| 33 | */ |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 34 | chtype attributes[] = { |
| 35 | A_NORMAL, /* screen_attr */ |
| 36 | A_NORMAL, /* shadow_attr */ |
| 37 | A_NORMAL, /* dialog_attr */ |
| 38 | A_BOLD, /* title_attr */ |
| 39 | A_NORMAL, /* border_attr */ |
| 40 | A_REVERSE, /* button_active_attr */ |
| 41 | A_DIM, /* button_inactive_attr */ |
| 42 | A_REVERSE, /* button_key_active_attr */ |
| 43 | A_BOLD, /* button_key_inactive_attr */ |
| 44 | A_REVERSE, /* button_label_active_attr */ |
| 45 | A_NORMAL, /* button_label_inactive_attr */ |
| 46 | A_NORMAL, /* inputbox_attr */ |
| 47 | A_NORMAL, /* inputbox_border_attr */ |
| 48 | A_NORMAL, /* searchbox_attr */ |
| 49 | A_BOLD, /* searchbox_title_attr */ |
| 50 | A_NORMAL, /* searchbox_border_attr */ |
| 51 | A_BOLD, /* position_indicator_attr */ |
| 52 | A_NORMAL, /* menubox_attr */ |
| 53 | A_NORMAL, /* menubox_border_attr */ |
| 54 | A_NORMAL, /* item_attr */ |
| 55 | A_REVERSE, /* item_selected_attr */ |
| 56 | A_BOLD, /* tag_attr */ |
| 57 | A_REVERSE, /* tag_selected_attr */ |
| 58 | A_BOLD, /* tag_key_attr */ |
| 59 | A_REVERSE, /* tag_key_selected_attr */ |
| 60 | A_BOLD, /* check_attr */ |
| 61 | A_REVERSE, /* check_selected_attr */ |
| 62 | A_BOLD, /* uarrow_attr */ |
| 63 | A_BOLD /* darrow_attr */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | }; |
| 65 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | #include "colors.h" |
| 67 | |
| 68 | /* |
| 69 | * Table of color values |
| 70 | */ |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 71 | int color_table[][3] = { |
| 72 | {SCREEN_FG, SCREEN_BG, SCREEN_HL}, |
| 73 | {SHADOW_FG, SHADOW_BG, SHADOW_HL}, |
| 74 | {DIALOG_FG, DIALOG_BG, DIALOG_HL}, |
| 75 | {TITLE_FG, TITLE_BG, TITLE_HL}, |
| 76 | {BORDER_FG, BORDER_BG, BORDER_HL}, |
| 77 | {BUTTON_ACTIVE_FG, BUTTON_ACTIVE_BG, BUTTON_ACTIVE_HL}, |
| 78 | {BUTTON_INACTIVE_FG, BUTTON_INACTIVE_BG, BUTTON_INACTIVE_HL}, |
| 79 | {BUTTON_KEY_ACTIVE_FG, BUTTON_KEY_ACTIVE_BG, BUTTON_KEY_ACTIVE_HL}, |
| 80 | {BUTTON_KEY_INACTIVE_FG, BUTTON_KEY_INACTIVE_BG, |
| 81 | BUTTON_KEY_INACTIVE_HL}, |
| 82 | {BUTTON_LABEL_ACTIVE_FG, BUTTON_LABEL_ACTIVE_BG, |
| 83 | BUTTON_LABEL_ACTIVE_HL}, |
| 84 | {BUTTON_LABEL_INACTIVE_FG, BUTTON_LABEL_INACTIVE_BG, |
| 85 | BUTTON_LABEL_INACTIVE_HL}, |
| 86 | {INPUTBOX_FG, INPUTBOX_BG, INPUTBOX_HL}, |
| 87 | {INPUTBOX_BORDER_FG, INPUTBOX_BORDER_BG, INPUTBOX_BORDER_HL}, |
| 88 | {SEARCHBOX_FG, SEARCHBOX_BG, SEARCHBOX_HL}, |
| 89 | {SEARCHBOX_TITLE_FG, SEARCHBOX_TITLE_BG, SEARCHBOX_TITLE_HL}, |
| 90 | {SEARCHBOX_BORDER_FG, SEARCHBOX_BORDER_BG, SEARCHBOX_BORDER_HL}, |
| 91 | {POSITION_INDICATOR_FG, POSITION_INDICATOR_BG, POSITION_INDICATOR_HL}, |
| 92 | {MENUBOX_FG, MENUBOX_BG, MENUBOX_HL}, |
| 93 | {MENUBOX_BORDER_FG, MENUBOX_BORDER_BG, MENUBOX_BORDER_HL}, |
| 94 | {ITEM_FG, ITEM_BG, ITEM_HL}, |
| 95 | {ITEM_SELECTED_FG, ITEM_SELECTED_BG, ITEM_SELECTED_HL}, |
| 96 | {TAG_FG, TAG_BG, TAG_HL}, |
| 97 | {TAG_SELECTED_FG, TAG_SELECTED_BG, TAG_SELECTED_HL}, |
| 98 | {TAG_KEY_FG, TAG_KEY_BG, TAG_KEY_HL}, |
| 99 | {TAG_KEY_SELECTED_FG, TAG_KEY_SELECTED_BG, TAG_KEY_SELECTED_HL}, |
| 100 | {CHECK_FG, CHECK_BG, CHECK_HL}, |
| 101 | {CHECK_SELECTED_FG, CHECK_SELECTED_BG, CHECK_SELECTED_HL}, |
| 102 | {UARROW_FG, UARROW_BG, UARROW_HL}, |
| 103 | {DARROW_FG, DARROW_BG, DARROW_HL}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | }; /* color_table */ |
| 105 | |
| 106 | /* |
| 107 | * Set window to attribute 'attr' |
| 108 | */ |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 109 | void attr_clear(WINDOW * win, int height, int width, chtype attr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | { |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 111 | int i, j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 113 | wattrset(win, attr); |
| 114 | for (i = 0; i < height; i++) { |
| 115 | wmove(win, i, 0); |
| 116 | for (j = 0; j < width; j++) |
| 117 | waddch(win, ' '); |
| 118 | } |
| 119 | touchwin(win); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | } |
| 121 | |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 122 | void dialog_clear(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | { |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 124 | attr_clear(stdscr, LINES, COLS, screen_attr); |
| 125 | /* Display background title if it exists ... - SLH */ |
| 126 | if (backtitle != NULL) { |
| 127 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 129 | wattrset(stdscr, screen_attr); |
| 130 | mvwaddstr(stdscr, 0, 1, (char *)backtitle); |
| 131 | wmove(stdscr, 1, 1); |
| 132 | for (i = 1; i < COLS - 1; i++) |
| 133 | waddch(stdscr, ACS_HLINE); |
| 134 | } |
| 135 | wnoutrefresh(stdscr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | /* |
| 139 | * Do some initialization for dialog |
| 140 | */ |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 141 | void init_dialog(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | { |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 143 | initscr(); /* Init curses */ |
| 144 | keypad(stdscr, TRUE); |
| 145 | cbreak(); |
| 146 | noecho(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 148 | if (use_colors) /* Set up colors */ |
| 149 | color_setup(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 151 | dialog_clear(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | /* |
| 155 | * Setup for color display |
| 156 | */ |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 157 | void color_setup(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | { |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 159 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 161 | if (has_colors()) { /* Terminal supports color? */ |
| 162 | start_color(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 164 | /* Initialize color pairs */ |
| 165 | for (i = 0; i < ATTRIBUTE_COUNT; i++) |
| 166 | init_pair(i + 1, color_table[i][0], color_table[i][1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 168 | /* Setup color attributes */ |
| 169 | for (i = 0; i < ATTRIBUTE_COUNT; i++) |
| 170 | attributes[i] = C_ATTR(color_table[i][2], i + 1); |
| 171 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | /* |
| 175 | * End using dialog functions. |
| 176 | */ |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 177 | void end_dialog(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | { |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 179 | endwin(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | /* |
| 183 | * Print a string of text in a window, automatically wrap around to the |
| 184 | * next line if the string is too long to fit on one line. Newline |
| 185 | * characters '\n' are replaced by spaces. We start on a new line |
| 186 | * if there is no room for at least 4 nonblanks following a double-space. |
| 187 | */ |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 188 | void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | { |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 190 | int newl, cur_x, cur_y; |
| 191 | int i, prompt_len, room, wlen; |
| 192 | char tempstr[MAX_LEN + 1], *word, *sp, *sp2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 194 | strcpy(tempstr, prompt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 196 | prompt_len = strlen(tempstr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 198 | /* |
| 199 | * Remove newlines |
| 200 | */ |
| 201 | for (i = 0; i < prompt_len; i++) { |
| 202 | if (tempstr[i] == '\n') |
| 203 | tempstr[i] = ' '; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | } |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 205 | |
| 206 | if (prompt_len <= width - x * 2) { /* If prompt is short */ |
| 207 | wmove(win, y, (width - prompt_len) / 2); |
| 208 | waddstr(win, tempstr); |
| 209 | } else { |
| 210 | cur_x = x; |
| 211 | cur_y = y; |
| 212 | newl = 1; |
| 213 | word = tempstr; |
| 214 | while (word && *word) { |
| 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 | } |
| 244 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | /* |
| 248 | * Print a button |
| 249 | */ |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 250 | void print_button(WINDOW * win, const char *label, int y, int x, int selected) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | { |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 252 | int i, temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 254 | wmove(win, y, x); |
| 255 | wattrset(win, selected ? button_active_attr : button_inactive_attr); |
| 256 | waddstr(win, "<"); |
| 257 | temp = strspn(label, " "); |
| 258 | label += temp; |
| 259 | wattrset(win, selected ? button_label_active_attr |
| 260 | : button_label_inactive_attr); |
| 261 | for (i = 0; i < temp; i++) |
| 262 | waddch(win, ' '); |
| 263 | wattrset(win, selected ? button_key_active_attr |
| 264 | : button_key_inactive_attr); |
| 265 | waddch(win, label[0]); |
| 266 | wattrset(win, selected ? button_label_active_attr |
| 267 | : button_label_inactive_attr); |
| 268 | waddstr(win, (char *)label + 1); |
| 269 | wattrset(win, selected ? button_active_attr : button_inactive_attr); |
| 270 | waddstr(win, ">"); |
| 271 | wmove(win, y, x + temp + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | /* |
| 275 | * Draw a rectangular box with line drawing characters |
| 276 | */ |
| 277 | void |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 278 | draw_box(WINDOW * win, int y, int x, int height, int width, |
| 279 | chtype box, chtype border) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | { |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 281 | int i, j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 283 | wattrset(win, 0); |
| 284 | for (i = 0; i < height; i++) { |
| 285 | wmove(win, y + i, x); |
| 286 | for (j = 0; j < width; j++) |
| 287 | if (!i && !j) |
| 288 | waddch(win, border | ACS_ULCORNER); |
| 289 | else if (i == height - 1 && !j) |
| 290 | waddch(win, border | ACS_LLCORNER); |
| 291 | else if (!i && j == width - 1) |
| 292 | waddch(win, box | ACS_URCORNER); |
| 293 | else if (i == height - 1 && j == width - 1) |
| 294 | waddch(win, box | ACS_LRCORNER); |
| 295 | else if (!i) |
| 296 | waddch(win, border | ACS_HLINE); |
| 297 | else if (i == height - 1) |
| 298 | waddch(win, box | ACS_HLINE); |
| 299 | else if (!j) |
| 300 | waddch(win, border | ACS_VLINE); |
| 301 | else if (j == width - 1) |
| 302 | waddch(win, box | ACS_VLINE); |
| 303 | else |
| 304 | waddch(win, box | ' '); |
| 305 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | /* |
| 309 | * Draw shadows along the right and bottom edge to give a more 3D look |
| 310 | * to the boxes |
| 311 | */ |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 312 | void draw_shadow(WINDOW * win, int y, int x, int height, int width) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | { |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 314 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 316 | if (has_colors()) { /* Whether terminal supports color? */ |
| 317 | wattrset(win, shadow_attr); |
| 318 | wmove(win, y + height, x + 2); |
| 319 | for (i = 0; i < width; i++) |
| 320 | waddch(win, winch(win) & A_CHARTEXT); |
| 321 | for (i = y + 1; i < y + height + 1; i++) { |
| 322 | wmove(win, i, x + width); |
| 323 | waddch(win, winch(win) & A_CHARTEXT); |
| 324 | waddch(win, winch(win) & A_CHARTEXT); |
| 325 | } |
| 326 | wnoutrefresh(win); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | /* |
| 331 | * Return the position of the first alphabetic character in a string. |
| 332 | */ |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 333 | int first_alpha(const char *string, const char *exempt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | { |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 335 | int i, in_paren = 0, c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | |
| 337 | for (i = 0; i < strlen(string); i++) { |
| 338 | c = tolower(string[i]); |
| 339 | |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 340 | if (strchr("<[(", c)) |
| 341 | ++in_paren; |
| 342 | if (strchr(">])", c) && in_paren > 0) |
| 343 | --in_paren; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | |
Sam Ravnborg | b1c5f1c | 2005-11-19 19:13:34 +0100 | [diff] [blame] | 345 | if ((!in_paren) && isalpha(c) && strchr(exempt, c) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | return i; |
| 347 | } |
| 348 | |
| 349 | return 0; |
| 350 | } |