Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+18 -24
+18 -24
scripts/lxdialog/menubox.c
··· 64 64 /* 65 65 * Print menu item 66 66 */ 67 - static void print_item(WINDOW * win, const char *item, int choice, 68 - int selected, int hotkey) 67 + static void do_print_item(WINDOW * win, const char *item, int choice, 68 + int selected, int hotkey) 69 69 { 70 70 int j; 71 71 char *menu_item = malloc(menu_width + 1); ··· 98 98 free(menu_item); 99 99 wrefresh(win); 100 100 } 101 + 102 + #define print_item(index, choice, selected) \ 103 + do {\ 104 + int hotkey = (items[(index) * 2][0] != ':'); \ 105 + do_print_item(menu, items[(index) * 2 + 1], choice, selected, hotkey); \ 106 + } while (0) 101 107 102 108 /* 103 109 * Print the scroll indicators. ··· 257 251 258 252 /* Print the menu */ 259 253 for (i = 0; i < max_choice; i++) { 260 - print_item(menu, items[(first_item + i) * 2 + 1], i, 261 - i == choice, 262 - (items[(first_item + i) * 2][0] != ':')); 254 + print_item(first_item + i, i, i == choice); 263 255 } 264 256 265 257 wnoutrefresh(menu); ··· 296 292 key == '-' || key == '+' || 297 293 key == KEY_PPAGE || key == KEY_NPAGE) { 298 294 /* Remove highligt of current item */ 299 - print_item(menu, items[(scroll + choice) * 2 + 1], 300 - choice, FALSE, 301 - (items[(scroll + choice) * 2][0] != ':')); 295 + print_item(scroll + choice, choice, FALSE); 302 296 303 297 if (key == KEY_UP || key == '-') { 304 298 if (choice < 2 && scroll) { 305 299 /* Scroll menu down */ 306 300 do_scroll(menu, &scroll, -1); 307 301 308 - print_item(menu, items[scroll * 2 + 1], 0, FALSE, 309 - (items[scroll * 2][0] != ':')); 302 + print_item(scroll, 0, FALSE); 310 303 } else 311 304 choice = MAX(choice - 1, 0); 312 305 313 306 } else if (key == KEY_DOWN || key == '+') { 314 - 315 - print_item(menu, 316 - items[(scroll + choice) * 2 + 1], choice, FALSE, 317 - (items[(scroll + choice) * 2][0] != ':')); 307 + print_item(scroll+choice, choice, FALSE); 318 308 319 309 if ((choice > max_choice - 3) && 320 310 (scroll + max_choice < item_no)) { 321 311 /* Scroll menu up */ 322 312 do_scroll(menu, &scroll, 1); 323 313 324 - print_item(menu, items[(scroll + max_choice - 1) * 2 + 1], 325 - max_choice - 1, FALSE, 326 - (items [(scroll + max_choice - 1) * 2][0] != ':')); 314 + print_item(scroll+max_choice - 1, 315 + max_choice - 1, FALSE); 327 316 } else 328 317 choice = MIN(choice + 1, max_choice - 1); 329 318 ··· 325 328 for (i = 0; (i < max_choice); i++) { 326 329 if (scroll > 0) { 327 330 do_scroll(menu, &scroll, -1); 328 - print_item(menu, items[scroll * 2 + 1], 0, FALSE, 329 - (items[scroll * 2][0] != ':')); 331 + print_item(scroll, 0, FALSE); 330 332 } else { 331 333 if (choice > 0) 332 334 choice--; ··· 336 340 for (i = 0; (i < max_choice); i++) { 337 341 if (scroll + max_choice < item_no) { 338 342 do_scroll(menu, &scroll, 1); 339 - print_item(menu, items[(scroll + max_choice - 1) * 2 + 1], 340 - max_choice - 1, FALSE, 341 - (items [(scroll + max_choice - 1) * 2][0] != ':')); 343 + print_item(scroll+max_choice-1, 344 + max_choice - 1, FALSE); 342 345 } else { 343 346 if (choice + 1 < max_choice) 344 347 choice++; ··· 346 351 } else 347 352 choice = i; 348 353 349 - print_item(menu, items[(scroll + choice) * 2 + 1], 350 - choice, TRUE, (items[(scroll + choice) * 2][0] != ':')); 354 + print_item(scroll + choice, choice, TRUE); 351 355 352 356 print_arrows(dialog, item_no, scroll, 353 357 box_y, box_x + ITEM_IDENT + 1, menu_height);