aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/kconfig/lxdialog/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/kconfig/lxdialog/util.c')
-rw-r--r--scripts/kconfig/lxdialog/util.c134
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 */
271void init_dialog(void) 271void init_dialog(const char *backtitle)
272{
273 dlg.backtitle = backtitle;
274 color_setup(getenv("MENUCONFIG_COLOR"));
275}
276
277void 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
480struct dialog_list *item_cur;
481struct dialog_list item_nil;
482struct dialog_list *item_head;
483
484void 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
496void 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
513void 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
527void item_set_tag(char tag)
528{
529 item_cur->node.tag = tag;
530}
531void item_set_data(void *ptr)
532{
533 item_cur->node.data = ptr;
534}
535
536void item_set_selected(int val)
537{
538 item_cur->node.selected = val;
539}
540
541int item_activate_selected(void)
542{
543 item_foreach()
544 if (item_is_selected())
545 return 1;
546 return 0;
547}
548
549void *item_data(void)
550{
551 return item_cur->node.data;
552}
553
554char item_tag(void)
555{
556 return item_cur->node.tag;
557}
558
559int 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
569void item_set(int n)
570{
571 int i = 0;
572 item_foreach()
573 if (i++ == n)
574 return;
575}
576
577int 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
590const char *item_str(void)
591{
592 return item_cur->node.str;
593}
594
595int item_is_selected(void)
596{
597 return (item_cur->node.selected != 0);
598}
599
600int item_is_tag(char tag)
601{
602 return (item_cur->node.tag == tag);
603}