aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/lxdialog/checklist.c
diff options
context:
space:
mode:
authorSam Ravnborg <sam@mars.ravnborg.org>2005-11-19 15:56:20 -0500
committerSam Ravnborg <sam@mars.ravnborg.org>2005-11-19 15:56:20 -0500
commitdec69da856653772d7ee7b2f98dc69da27274a22 (patch)
tree020cf19de028a402a6bfc792caaffeddaf5a3e9b /scripts/lxdialog/checklist.c
parentb1c5f1c635f4a821f834ed51ccd8a2a1515fffd2 (diff)
kconfig: fixup after Lindent
Readability are more important then the 80 coloumn limit, so fold several lines to greatly improve readability. Also keep return type on same line as function definition. Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Diffstat (limited to 'scripts/lxdialog/checklist.c')
-rw-r--r--scripts/lxdialog/checklist.c99
1 files changed, 30 insertions, 69 deletions
diff --git a/scripts/lxdialog/checklist.c b/scripts/lxdialog/checklist.c
index 1857c5378ce8..ae40a2b3b885 100644
--- a/scripts/lxdialog/checklist.c
+++ b/scripts/lxdialog/checklist.c
@@ -28,8 +28,8 @@ static int list_width, check_x, item_x, checkflag;
28/* 28/*
29 * Print list item 29 * Print list item
30 */ 30 */
31static void 31static void print_item(WINDOW * win, const char *item, int status, int choice,
32print_item(WINDOW * win, const char *item, int status, int choice, int selected) 32 int selected)
33{ 33{
34 int i; 34 int i;
35 35
@@ -59,8 +59,7 @@ print_item(WINDOW * win, const char *item, int status, int choice, int selected)
59/* 59/*
60 * Print the scroll indicators. 60 * Print the scroll indicators.
61 */ 61 */
62static void 62static void print_arrows(WINDOW * win, int choice, int item_no, int scroll,
63print_arrows(WINDOW * win, int choice, int item_no, int scroll,
64 int y, int x, int height) 63 int y, int x, int height)
65{ 64{
66 wmove(win, y, x); 65 wmove(win, y, x);
@@ -112,10 +111,9 @@ static void print_buttons(WINDOW * dialog, int height, int width, int selected)
112 * Display a dialog box with a list of options that can be turned on or off 111 * Display a dialog box with a list of options that can be turned on or off
113 * The `flag' parameter is used to select between radiolist and checklist. 112 * The `flag' parameter is used to select between radiolist and checklist.
114 */ 113 */
115int 114int dialog_checklist(const char *title, const char *prompt, int height,
116dialog_checklist(const char *title, const char *prompt, int height, int width, 115 int width, int list_height, int item_no,
117 int list_height, int item_no, const char *const *items, 116 const char *const *items, int flag)
118 int flag)
119{ 117{
120 int i, x, y, box_x, box_y; 118 int i, x, y, box_x, box_y;
121 int key = 0, button = 0, choice = 0, scroll = 0, max_choice, *status; 119 int key = 0, button = 0, choice = 0, scroll = 0, max_choice, *status;
@@ -183,15 +181,14 @@ dialog_checklist(const char *title, const char *prompt, int height, int width,
183 box_x = (width - list_width) / 2 - 1; 181 box_x = (width - list_width) / 2 - 1;
184 182
185 /* create new window for the list */ 183 /* create new window for the list */
186 list = 184 list = subwin(dialog, list_height, list_width, y + box_y + 1,
187 subwin(dialog, list_height, list_width, y + box_y + 1, 185 x + box_x + 1);
188 x + box_x + 1);
189 186
190 keypad(list, TRUE); 187 keypad(list, TRUE);
191 188
192 /* draw a box around the list items */ 189 /* draw a box around the list items */
193 draw_box(dialog, box_y, box_x, list_height + 2, list_width + 2, 190 draw_box(dialog, box_y, box_x, list_height + 2, list_width + 2,
194 menubox_border_attr, menubox_attr); 191 menubox_border_attr, menubox_attr);
195 192
196 /* Find length of longest item in order to center checklist */ 193 /* Find length of longest item in order to center checklist */
197 check_x = 0; 194 check_x = 0;
@@ -238,24 +235,18 @@ dialog_checklist(const char *title, const char *prompt, int height, int width,
238 /* Scroll list down */ 235 /* Scroll list down */
239 if (list_height > 1) { 236 if (list_height > 1) {
240 /* De-highlight current first item */ 237 /* De-highlight current first item */
241 print_item(list, 238 print_item(list, items[scroll * 3 + 1],
242 items[scroll * 3 + 239 status[scroll], 0, FALSE);
243 1],
244 status[scroll], 0,
245 FALSE);
246 scrollok(list, TRUE); 240 scrollok(list, TRUE);
247 wscrl(list, -1); 241 wscrl(list, -1);
248 scrollok(list, FALSE); 242 scrollok(list, FALSE);
249 } 243 }
250 scroll--; 244 scroll--;
251 print_item(list, items[scroll * 3 + 1], 245 print_item(list, items[scroll * 3 + 1], status[scroll], 0, TRUE);
252 status[scroll], 0, TRUE);
253 wnoutrefresh(list); 246 wnoutrefresh(list);
254 247
255 print_arrows(dialog, choice, item_no, 248 print_arrows(dialog, choice, item_no,
256 scroll, box_y, 249 scroll, box_y, box_x + check_x + 5, list_height);
257 box_x + check_x + 5,
258 list_height);
259 250
260 wrefresh(dialog); 251 wrefresh(dialog);
261 252
@@ -269,32 +260,20 @@ dialog_checklist(const char *title, const char *prompt, int height, int width,
269 /* Scroll list up */ 260 /* Scroll list up */
270 if (list_height > 1) { 261 if (list_height > 1) {
271 /* De-highlight current last item before scrolling up */ 262 /* De-highlight current last item before scrolling up */
272 print_item(list, 263 print_item(list, items[(scroll + max_choice - 1) * 3 + 1],
273 items[(scroll + 264 status[scroll + max_choice - 1],
274 max_choice - 265 max_choice - 1, FALSE);
275 1) * 3 + 1],
276 status[scroll +
277 max_choice -
278 1],
279 max_choice - 1,
280 FALSE);
281 scrollok(list, TRUE); 266 scrollok(list, TRUE);
282 wscrl(list, 1); 267 wscrl(list, 1);
283 scrollok(list, FALSE); 268 scrollok(list, FALSE);
284 } 269 }
285 scroll++; 270 scroll++;
286 print_item(list, 271 print_item(list, items[(scroll + max_choice - 1) * 3 + 1],
287 items[(scroll + max_choice - 272 status[scroll + max_choice - 1], max_choice - 1, TRUE);
288 1) * 3 + 1],
289 status[scroll + max_choice -
290 1], max_choice - 1,
291 TRUE);
292 wnoutrefresh(list); 273 wnoutrefresh(list);
293 274
294 print_arrows(dialog, choice, item_no, 275 print_arrows(dialog, choice, item_no,
295 scroll, box_y, 276 scroll, box_y, box_x + check_x + 5, list_height);
296 box_x + check_x + 5,
297 list_height);
298 277
299 wrefresh(dialog); 278 wrefresh(dialog);
300 279
@@ -304,16 +283,12 @@ dialog_checklist(const char *title, const char *prompt, int height, int width,
304 } 283 }
305 if (i != choice) { 284 if (i != choice) {
306 /* De-highlight current item */ 285 /* De-highlight current item */
307 print_item(list, 286 print_item(list, items[(scroll + choice) * 3 + 1],
308 items[(scroll + choice) * 3 + 1], 287 status[scroll + choice], choice, FALSE);
309 status[scroll + choice], choice,
310 FALSE);
311 /* Highlight new item */ 288 /* Highlight new item */
312 choice = i; 289 choice = i;
313 print_item(list, 290 print_item(list, items[(scroll + choice) * 3 + 1],
314 items[(scroll + choice) * 3 + 1], 291 status[scroll + choice], choice, TRUE);
315 status[scroll + choice], choice,
316 TRUE);
317 wnoutrefresh(list); 292 wnoutrefresh(list);
318 wrefresh(dialog); 293 wrefresh(dialog);
319 } 294 }
@@ -342,28 +317,18 @@ dialog_checklist(const char *title, const char *prompt, int height, int width,
342 case '\n': 317 case '\n':
343 if (!button) { 318 if (!button) {
344 if (flag == FLAG_CHECK) { 319 if (flag == FLAG_CHECK) {
345 status[scroll + choice] = 320 status[scroll + choice] = !status[scroll + choice];
346 !status[scroll + choice];
347 wmove(list, choice, check_x); 321 wmove(list, choice, check_x);
348 wattrset(list, check_selected_attr); 322 wattrset(list, check_selected_attr);
349 wprintw(list, "[%c]", 323 wprintw(list, "[%c]", status[scroll + choice] ? 'X' : ' ');
350 status[scroll +
351 choice] ? 'X' : ' ');
352 } else { 324 } else {
353 if (!status[scroll + choice]) { 325 if (!status[scroll + choice]) {
354 for (i = 0; i < item_no; i++) 326 for (i = 0; i < item_no; i++)
355 status[i] = 0; 327 status[i] = 0;
356 status[scroll + choice] = 1; 328 status[scroll + choice] = 1;
357 for (i = 0; i < max_choice; i++) 329 for (i = 0; i < max_choice; i++)
358 print_item(list, 330 print_item(list, items[(scroll + i) * 3 + 1],
359 items[(scroll 331 status[scroll + i], i, i == choice);
360 +
361 i) *
362 3 + 1],
363 status[scroll
364 + i],
365 i,
366 i == choice);
367 } 332 }
368 } 333 }
369 wnoutrefresh(list); 334 wnoutrefresh(list);
@@ -372,19 +337,15 @@ dialog_checklist(const char *title, const char *prompt, int height, int width,
372 for (i = 0; i < item_no; i++) { 337 for (i = 0; i < item_no; i++) {
373 if (status[i]) { 338 if (status[i]) {
374 if (flag == FLAG_CHECK) { 339 if (flag == FLAG_CHECK) {
375 fprintf(stderr, 340 fprintf(stderr, "\"%s\" ", items[i * 3]);
376 "\"%s\" ",
377 items[i * 3]);
378 } else { 341 } else {
379 fprintf(stderr, "%s", 342 fprintf(stderr, "%s", items[i * 3]);
380 items[i * 3]);
381 } 343 }
382 344
383 } 345 }
384 } 346 }
385 } else 347 } else
386 fprintf(stderr, "%s", 348 fprintf(stderr, "%s", items[(scroll + choice) * 3]);
387 items[(scroll + choice) * 3]);
388 delwin(dialog); 349 delwin(dialog);
389 free(status); 350 free(status);
390 return button; 351 return button;