aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorSam Ravnborg <sam@mars.ravnborg.org>2005-11-20 17:34:35 -0500
committerSam Ravnborg <sam@mars.ravnborg.org>2005-11-20 17:34:35 -0500
commit59d3cf7a40dfdbb8e86758ade172831c19630050 (patch)
treeeed9b3e8c4c1e15ff25a53d9ad411d441c966fa9 /scripts
parent7c3badf96e0dc8aa89ebf8919653339a5ee8e035 (diff)
kconfig: make lxdialog/menubox.c more readable
Utilising a small macro for print_item made wonders for readability for this file. Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/lxdialog/menubox.c42
1 files changed, 18 insertions, 24 deletions
diff --git a/scripts/lxdialog/menubox.c b/scripts/lxdialog/menubox.c
index 461ee08edc05..d0bf32b34090 100644
--- a/scripts/lxdialog/menubox.c
+++ b/scripts/lxdialog/menubox.c
@@ -64,8 +64,8 @@ static int menu_width;
64/* 64/*
65 * Print menu item 65 * Print menu item
66 */ 66 */
67static void print_item(WINDOW * win, const char *item, int choice, 67static void do_print_item(WINDOW * win, const char *item, int choice,
68 int selected, int hotkey) 68 int selected, int hotkey)
69{ 69{
70 int j; 70 int j;
71 char *menu_item = malloc(menu_width + 1); 71 char *menu_item = malloc(menu_width + 1);
@@ -99,6 +99,12 @@ static void print_item(WINDOW * win, const char *item, int choice,
99 wrefresh(win); 99 wrefresh(win);
100} 100}
101 101
102#define print_item(index, choice, selected) \
103do {\
104 int hotkey = (items[(index) * 2][0] != ':'); \
105 do_print_item(menu, items[(index) * 2 + 1], choice, selected, hotkey); \
106} while (0)
107
102/* 108/*
103 * Print the scroll indicators. 109 * Print the scroll indicators.
104 */ 110 */
@@ -251,9 +257,7 @@ int dialog_menu(const char *title, const char *prompt, int height, int width,
251 257
252 /* Print the menu */ 258 /* Print the menu */
253 for (i = 0; i < max_choice; i++) { 259 for (i = 0; i < max_choice; i++) {
254 print_item(menu, items[(first_item + i) * 2 + 1], i, 260 print_item(first_item + i, i, i == choice);
255 i == choice,
256 (items[(first_item + i) * 2][0] != ':'));
257 } 261 }
258 262
259 wnoutrefresh(menu); 263 wnoutrefresh(menu);
@@ -292,34 +296,27 @@ int dialog_menu(const char *title, const char *prompt, int height, int width,
292 key == '-' || key == '+' || 296 key == '-' || key == '+' ||
293 key == KEY_PPAGE || key == KEY_NPAGE) { 297 key == KEY_PPAGE || key == KEY_NPAGE) {
294 /* Remove highligt of current item */ 298 /* Remove highligt of current item */
295 print_item(menu, items[(scroll + choice) * 2 + 1], 299 print_item(scroll + choice, choice, FALSE);
296 choice, FALSE,
297 (items[(scroll + choice) * 2][0] != ':'));
298 300
299 if (key == KEY_UP || key == '-') { 301 if (key == KEY_UP || key == '-') {
300 if (choice < 2 && scroll) { 302 if (choice < 2 && scroll) {
301 /* Scroll menu down */ 303 /* Scroll menu down */
302 do_scroll(menu, &scroll, -1); 304 do_scroll(menu, &scroll, -1);
303 305
304 print_item(menu, items[scroll * 2 + 1], 0, FALSE, 306 print_item(scroll, 0, FALSE);
305 (items[scroll * 2][0] != ':'));
306 } else 307 } else
307 choice = MAX(choice - 1, 0); 308 choice = MAX(choice - 1, 0);
308 309
309 } else if (key == KEY_DOWN || key == '+') { 310 } else if (key == KEY_DOWN || key == '+') {
310 311 print_item(scroll+choice, choice, FALSE);
311 print_item(menu,
312 items[(scroll + choice) * 2 + 1], choice, FALSE,
313 (items[(scroll + choice) * 2][0] != ':'));
314 312
315 if ((choice > max_choice - 3) && 313 if ((choice > max_choice - 3) &&
316 (scroll + max_choice < item_no)) { 314 (scroll + max_choice < item_no)) {
317 /* Scroll menu up */ 315 /* Scroll menu up */
318 do_scroll(menu, &scroll, 1); 316 do_scroll(menu, &scroll, 1);
319 317
320 print_item(menu, items[(scroll + max_choice - 1) * 2 + 1], 318 print_item(scroll+max_choice - 1,
321 max_choice - 1, FALSE, 319 max_choice - 1, FALSE);
322 (items [(scroll + max_choice - 1) * 2][0] != ':'));
323 } else 320 } else
324 choice = MIN(choice + 1, max_choice - 1); 321 choice = MIN(choice + 1, max_choice - 1);
325 322
@@ -328,8 +325,7 @@ int dialog_menu(const char *title, const char *prompt, int height, int width,
328 for (i = 0; (i < max_choice); i++) { 325 for (i = 0; (i < max_choice); i++) {
329 if (scroll > 0) { 326 if (scroll > 0) {
330 do_scroll(menu, &scroll, -1); 327 do_scroll(menu, &scroll, -1);
331 print_item(menu, items[scroll * 2 + 1], 0, FALSE, 328 print_item(scroll, 0, FALSE);
332 (items[scroll * 2][0] != ':'));
333 } else { 329 } else {
334 if (choice > 0) 330 if (choice > 0)
335 choice--; 331 choice--;
@@ -340,9 +336,8 @@ int dialog_menu(const char *title, const char *prompt, int height, int width,
340 for (i = 0; (i < max_choice); i++) { 336 for (i = 0; (i < max_choice); i++) {
341 if (scroll + max_choice < item_no) { 337 if (scroll + max_choice < item_no) {
342 do_scroll(menu, &scroll, 1); 338 do_scroll(menu, &scroll, 1);
343 print_item(menu, items[(scroll + max_choice - 1) * 2 + 1], 339 print_item(scroll+max_choice-1,
344 max_choice - 1, FALSE, 340 max_choice - 1, FALSE);
345 (items [(scroll + max_choice - 1) * 2][0] != ':'));
346 } else { 341 } else {
347 if (choice + 1 < max_choice) 342 if (choice + 1 < max_choice)
348 choice++; 343 choice++;
@@ -351,8 +346,7 @@ int dialog_menu(const char *title, const char *prompt, int height, int width,
351 } else 346 } else
352 choice = i; 347 choice = i;
353 348
354 print_item(menu, items[(scroll + choice) * 2 + 1], 349 print_item(scroll + choice, choice, TRUE);
355 choice, TRUE, (items[(scroll + choice) * 2][0] != ':'));
356 350
357 print_arrows(dialog, item_no, scroll, 351 print_arrows(dialog, item_no, scroll,
358 box_y, box_x + ITEM_IDENT + 1, menu_height); 352 box_y, box_x + ITEM_IDENT + 1, menu_height);