diff options
author | Sam Ravnborg <sam@mars.ravnborg.org> | 2006-07-27 16:10:27 -0400 |
---|---|---|
committer | Sam Ravnborg <sam@neptun.ravnborg.org> | 2006-09-30 05:19:19 -0400 |
commit | 2982de6993e6d9944f2215d7cb9b558b465a0c99 (patch) | |
tree | 3b4765905e7c53e2a03ed599692d2636623e22a5 /scripts/kconfig/lxdialog/util.c | |
parent | 350b5b76384e77bcc58217f00455fdbec5cac594 (diff) |
kconfig/menuconfig: lxdialog is now built-in
lxdialog was previously called as an external program causing screen
to flicker when used. With this patch lxdialog is now built-in.
It is loosly based om previous work by: Petr Baudis <pasky@ucw.cz>
Following is a list of changes:
o Moved build of dialog routings to kconfig Makefile
o menubox + checklist uses a new item list to hold all menu items
o in util.c implmented helper function to deal with item list
o menubox now uses parameters to save scroll state (avoids temp file)
o textbox now get text to be displayed as parameter and not a file
o make sure to properly delete subwin's before main windows
o killed unused files: lxdialog.c msgbox.c
o modified return value for ESC to match direct calling
o in a few places the code has been adjusted to 80 char wide
o in textbox a small refactoring was made to make code remotely readable
o in mconf removed all unused stuff (functions/variables)
Following is a list of know short comings:
a) pressing ESC twice will be interpreted as two ESC presses
b) resize does not work. menuconfig needs to be restarted to be adjusted
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Diffstat (limited to 'scripts/kconfig/lxdialog/util.c')
-rw-r--r-- | scripts/kconfig/lxdialog/util.c | 134 |
1 files changed, 132 insertions, 2 deletions
diff --git a/scripts/kconfig/lxdialog/util.c b/scripts/kconfig/lxdialog/util.c index e73a36df93b4..0b3118df50df 100644 --- a/scripts/kconfig/lxdialog/util.c +++ b/scripts/kconfig/lxdialog/util.c | |||
@@ -268,13 +268,18 @@ void dialog_clear(void) | |||
268 | /* | 268 | /* |
269 | * Do some initialization for dialog | 269 | * Do some initialization for dialog |
270 | */ | 270 | */ |
271 | void init_dialog(void) | 271 | void init_dialog(const char *backtitle) |
272 | { | ||
273 | dlg.backtitle = backtitle; | ||
274 | color_setup(getenv("MENUCONFIG_COLOR")); | ||
275 | } | ||
276 | |||
277 | void reset_dialog(void) | ||
272 | { | 278 | { |
273 | initscr(); /* Init curses */ | 279 | initscr(); /* Init curses */ |
274 | keypad(stdscr, TRUE); | 280 | keypad(stdscr, TRUE); |
275 | cbreak(); | 281 | cbreak(); |
276 | noecho(); | 282 | noecho(); |
277 | color_setup(getenv("MENUCONFIG_COLOR")); | ||
278 | dialog_clear(); | 283 | dialog_clear(); |
279 | } | 284 | } |
280 | 285 | ||
@@ -471,3 +476,128 @@ int first_alpha(const char *string, const char *exempt) | |||
471 | 476 | ||
472 | return 0; | 477 | return 0; |
473 | } | 478 | } |
479 | |||
480 | struct dialog_list *item_cur; | ||
481 | struct dialog_list item_nil; | ||
482 | struct dialog_list *item_head; | ||
483 | |||
484 | void item_reset(void) | ||
485 | { | ||
486 | struct dialog_list *p, *next; | ||
487 | |||
488 | for (p = item_head; p; p = next) { | ||
489 | next = p->next; | ||
490 | free(p); | ||
491 | } | ||
492 | item_head = NULL; | ||
493 | item_cur = &item_nil; | ||
494 | } | ||
495 | |||
496 | void item_make(const char *fmt, ...) | ||
497 | { | ||
498 | va_list ap; | ||
499 | struct dialog_list *p = malloc(sizeof(*p)); | ||
500 | |||
501 | if (item_head) | ||
502 | item_cur->next = p; | ||
503 | else | ||
504 | item_head = p; | ||
505 | item_cur = p; | ||
506 | memset(p, 0, sizeof(*p)); | ||
507 | |||
508 | va_start(ap, fmt); | ||
509 | vsnprintf(item_cur->node.str, sizeof(item_cur->node.str), fmt, ap); | ||
510 | va_end(ap); | ||
511 | } | ||
512 | |||
513 | void item_add_str(const char *fmt, ...) | ||
514 | { | ||
515 | va_list ap; | ||
516 | size_t avail; | ||
517 | |||
518 | avail = sizeof(item_cur->node.str) - strlen(item_cur->node.str); | ||
519 | |||
520 | va_start(ap, fmt); | ||
521 | vsnprintf(item_cur->node.str + strlen(item_cur->node.str), | ||
522 | avail, fmt, ap); | ||
523 | item_cur->node.str[sizeof(item_cur->node.str) - 1] = '\0'; | ||
524 | va_end(ap); | ||
525 | } | ||
526 | |||
527 | void item_set_tag(char tag) | ||
528 | { | ||
529 | item_cur->node.tag = tag; | ||
530 | } | ||
531 | void item_set_data(void *ptr) | ||
532 | { | ||
533 | item_cur->node.data = ptr; | ||
534 | } | ||
535 | |||
536 | void item_set_selected(int val) | ||
537 | { | ||
538 | item_cur->node.selected = val; | ||
539 | } | ||
540 | |||
541 | int item_activate_selected(void) | ||
542 | { | ||
543 | item_foreach() | ||
544 | if (item_is_selected()) | ||
545 | return 1; | ||
546 | return 0; | ||
547 | } | ||
548 | |||
549 | void *item_data(void) | ||
550 | { | ||
551 | return item_cur->node.data; | ||
552 | } | ||
553 | |||
554 | char item_tag(void) | ||
555 | { | ||
556 | return item_cur->node.tag; | ||
557 | } | ||
558 | |||
559 | int item_count(void) | ||
560 | { | ||
561 | int n = 0; | ||
562 | struct dialog_list *p; | ||
563 | |||
564 | for (p = item_head; p; p = p->next) | ||
565 | n++; | ||
566 | return n; | ||
567 | } | ||
568 | |||
569 | void item_set(int n) | ||
570 | { | ||
571 | int i = 0; | ||
572 | item_foreach() | ||
573 | if (i++ == n) | ||
574 | return; | ||
575 | } | ||
576 | |||
577 | int item_n(void) | ||
578 | { | ||
579 | int n = 0; | ||
580 | struct dialog_list *p; | ||
581 | |||
582 | for (p = item_head; p; p = p->next) { | ||
583 | if (p == item_cur) | ||
584 | return n; | ||
585 | n++; | ||
586 | } | ||
587 | return 0; | ||
588 | } | ||
589 | |||
590 | const char *item_str(void) | ||
591 | { | ||
592 | return item_cur->node.str; | ||
593 | } | ||
594 | |||
595 | int item_is_selected(void) | ||
596 | { | ||
597 | return (item_cur->node.selected != 0); | ||
598 | } | ||
599 | |||
600 | int item_is_tag(char tag) | ||
601 | { | ||
602 | return (item_cur->node.tag == tag); | ||
603 | } | ||