void dlg_dump_keys(FILE *fp) { LIST_BINDINGS *p; const char *last = ""; unsigned n; unsigned count = 0; for (p = all_bindings; p != 0; p = p->link) { if (p->win == 0) { ++count; } } if (count != 0) { for (p = all_bindings, n = 0; p != 0; p = p->link) { if (p->win == 0) { if (dlg_strcmp(last, p->name)) { fprintf(fp, "\n# key bindings for %s widgets\n", !strcmp(p->name, "*") ? "all" : p->name); last = p->name; } dump_one_binding(fp, p->name, p->binding); } } } }
static int find_vars(char *name) { int result = -1; unsigned i; for (i = 0; i < VAR_COUNT; i++) { if (dlg_strcmp(vars[i].name, name) == 0) { result = (int) i; break; } } return result; }
static int find_color(char *name) { int result = -1; int i; int limit = dlg_color_count(); for (i = 0; i < limit; i++) { if (dlg_strcmp(dlg_color_table[i].name, name) == 0) { result = i; break; } } return result; }
/* * Find a user-defined binding, given the curses key code. */ static DLG_KEYS_BINDING * find_binding(char *widget, int curses_key) { LIST_BINDINGS *p; DLG_KEYS_BINDING *result = 0; for (p = all_bindings; p != 0; p = p->link) { if (p->win == 0 && !dlg_strcmp(p->name, widget) && p->binding->curses_key == curses_key) { result = p->binding; break; } } return result; }
/* * Unlike dlg_lookup_key(), this looks for either widget-builtin or rc-file * definitions, depending on whether 'win' is null. */ static int key_is_bound(WINDOW *win, const char *name, int curses_key, int function_key) { LIST_BINDINGS *p; for (p = all_bindings; p != 0; p = p->link) { if (p->win == win && !dlg_strcmp(p->name, name)) { int n; for (n = 0; p->binding[n].is_function_key >= 0; ++n) { if (p->binding[n].curses_key == curses_key && p->binding[n].is_function_key == function_key) { return TRUE; } } } } return FALSE; }
/* * Check if the line begins with a special keyword; if so, return true while * pointing params to its parameters. */ static int begins_with(char *line, const char *keyword, char **params) { int i = skip_whitespace(line, 0); int j = skip_keyword(line, i); if ((j - i) == (int) strlen(keyword)) { char save = line[j]; line[j] = 0; if (!dlg_strcmp(keyword, line + i)) { *params = line + skip_whitespace(line, j + 1); return 1; } line[j] = save; } return 0; }
/* * Built-in bindings have a nonzero "win" member, and the associated binding * table can have more than one entry. We keep those last, since lookups will * find the user-defined bindings first and use those. * * Sort "*" (all-widgets) entries past named widgets, since those are less * specific. */ static int compare_bindings(LIST_BINDINGS * a, LIST_BINDINGS * b) { int result = 0; if (a->win == b->win) { if (!strcmp(a->name, b->name)) { result = a->binding[0].curses_key - b->binding[0].curses_key; } else if (!strcmp(b->name, "*")) { result = -1; } else if (!strcmp(a->name, "*")) { result = 1; } else { result = dlg_strcmp(a->name, b->name); } } else if (b->win) { result = -1; } else { result = 1; } return result; }
/* * Dump bindings for the given window. If it is a null, then this dumps the * initial bindings which were loaded from the rc-file that are used as * overall defaults. */ void dlg_dump_window_keys(FILE *fp, WINDOW *win) { if (fp != 0) { LIST_BINDINGS *p; DLG_KEYS_BINDING *q; const char *last = ""; for (p = all_bindings; p != 0; p = p->link) { if (p->win == win) { if (dlg_strcmp(last, p->name)) { fprintf(fp, "\n# key bindings for %s widgets\n", !strcmp(p->name, WILDNAME) ? "all" : p->name); last = p->name; } for (q = p->binding; q->is_function_key >= 0; ++q) { dump_one_binding(fp, p->name, q); } } } } }
/* * Parse the parameters of the "bindkeys" configuration-file entry. This * expects widget name which may be "*", followed by curses key definition and * then dialog key definition. * * The curses key "should" be one of the names (ignoring case) from * curses_names[], but may also be a single control character (prefix "^" or * "~" depending on whether it is C0 or C1), or an escaped single character. * Binding a printable character with dialog is possible but not useful. * * The dialog key must be one of the names from dialog_names[]. */ int dlg_parse_bindkey(char *params) { char *p = skip_white(params); char *q; bool escaped = FALSE; int modified = 0; int result = FALSE; unsigned xx; char *widget; int is_function = FALSE; int curses_key; int dialog_key; curses_key = -1; dialog_key = -1; widget = p; p = skip_black(p); if (p != widget && *p != '\0') { *p++ = '\0'; q = p; while (*p != '\0' && curses_key < 0) { if (escaped) { escaped = FALSE; curses_key = *p; } else if (*p == '\\') { escaped = TRUE; } else if (modified) { if (*p == '?') { curses_key = ((modified == '^') ? 127 : 255); } else { curses_key = ((modified == '^') ? (*p & 0x1f) : ((*p & 0x1f) | 0x80)); } } else if (*p == '^') { modified = *p; } else if (*p == '~') { modified = *p; } else if (isspace(UCH(*p))) { break; } ++p; } if (!isspace(UCH(*p))) { ; } else { *p++ = '\0'; if (curses_key < 0) { char fprefix[2]; char check[2]; int keynumber; if (sscanf(q, "%[Ff]%d%c", fprefix, &keynumber, check) == 2) { curses_key = KEY_F(keynumber); is_function = TRUE; } else { for (xx = 0; xx < COUNT_CURSES; ++xx) { if (!dlg_strcmp(curses_names[xx].name, q)) { curses_key = curses_names[xx].code; is_function = TRUE; break; } } } } } q = skip_white(p); p = skip_black(q); if (p != q) { for (xx = 0; xx < COUNT_DIALOG; ++xx) { if (!dlg_strcmp(dialog_names[xx].name, q)) { dialog_key = dialog_names[xx].code; break; } } } if (*widget != '\0' && curses_key >= 0 && dialog_key >= 0 && make_binding(widget, curses_key, is_function, dialog_key) != 0) { result = TRUE; } } return result; }
/* * Display a dialog box with a list of options that can be turned on or off * The `flag' parameter is used to select between radiolist and checklist. */ int dialog_checklist(const char *title, const char *cprompt, int height, int width, int list_height, int item_no, char **items, int flag, int separate_output) { int i, j, key2, found, x, y, cur_x, cur_y, box_x, box_y; int key = 0, fkey; int button = 0; int choice = 0; int scrollamt = 0; int max_choice, *status; int use_width, name_width, text_width; int result = DLG_EXIT_UNKNOWN; WINDOW *dialog, *list; char *prompt = strclone(cprompt); const char **buttons = dlg_ok_labels(); tab_correct_str(prompt); if (list_height == 0) { use_width = calc_listw(item_no, items, CHECKBOX_TAGS) + 10; /* calculate height without items (4) */ auto_size(title, prompt, &height, &width, 4, MAX(26, use_width)); calc_listh(&height, &list_height, item_no); } else { auto_size(title, prompt, &height, &width, 4 + list_height, 26); } print_size(height, width); ctl_size(height, width); checkflag = flag; /* Allocate space for storing item on/off status */ status = malloc(sizeof(int) * item_no); assert_ptr(status, "dialog_checklist"); /* Initializes status */ for (i = 0; i < item_no; i++) status[i] = !dlg_strcmp(ItemStatus(i), "on"); max_choice = MIN(list_height, item_no); x = box_x_ordinate(width); y = box_y_ordinate(height); dialog = new_window(height, width, y, x); mouse_setbase(x, y); draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr); draw_bottom_box(dialog); draw_title(dialog, title); wattrset(dialog, dialog_attr); print_autowrap(dialog, prompt, height, width); list_width = width - 6; getyx(dialog, cur_y, cur_x); box_y = cur_y + 1; box_x = (width - list_width) / 2 - 1; /* create new window for the list */ list = sub_window(dialog, list_height, list_width, y + box_y + 1, x + box_x + 1); /* draw a box around the list items */ draw_box(dialog, box_y, box_x, list_height + 2 * MARGIN, list_width + 2 * MARGIN, menubox_border_attr, menubox_attr); text_width = 0; name_width = 0; /* Find length of longest item to center checklist */ for (i = 0; i < item_no; i++) { text_width = MAX(text_width, (int) strlen(ItemText(i))); name_width = MAX(name_width, (int) strlen(ItemName(i))); } /* If the name+text is wider than the list is allowed, then truncate * one or both of them. If the name is no wider than 1/4 of the list, * leave it intact. */ use_width = (list_width - 6); if (text_width + name_width > use_width) { int need = 0.25 * use_width; if (name_width > need) { int want = use_width * ((double) name_width) / (text_width + name_width); name_width = (want > need) ? want : need; } text_width = use_width - name_width; } check_x = (use_width - (text_width + name_width)) / 2; item_x = name_width + check_x + 6; /* Print the list */ for (i = 0; i < max_choice; i++) print_item(list, ItemData(i), status[i], i, i == choice); (void) wnoutrefresh(list); /* register the new window, along with its borders */ mouse_mkbigregion(box_y + 1, box_x, list_height, list_width + 2, KEY_MAX, 1, 1, 1 /* by lines */ ); dlg_draw_arrows(dialog, scrollamt, scrollamt + max_choice < item_no - 1, box_x + check_x + 5, box_y, box_y + list_height + 1); dlg_draw_buttons(dialog, height - 2, 0, buttons, 0, FALSE, width); wtimeout(dialog, WTIMEOUT_VAL); while (result == DLG_EXIT_UNKNOWN) { key = mouse_wgetch(dialog, &fkey); if (fkey && (key >= (M_EVENT + KEY_MAX))) { getyx(dialog, cur_y, cur_x); /* De-highlight current item */ print_item(list, ItemData(scrollamt + choice), status[scrollamt + choice], choice, FALSE); /* Highlight new item */ choice = (key - (M_EVENT + KEY_MAX)); print_item(list, ItemData(scrollamt + choice), status[scrollamt + choice], choice, TRUE); (void) wnoutrefresh(list); (void) wmove(dialog, cur_y, cur_x); key = ' '; /* force the selected item to toggle */ fkey = FALSE; } /* * A space toggles the item status. We handle either a checklist * (any number of items can be selected) or radio list (zero or one * items can be selected). */ if (key == ' ') { getyx(dialog, cur_y, cur_x); if (flag == FLAG_CHECK) { /* checklist? */ status[scrollamt + choice] = !status[scrollamt + choice]; print_item(list, ItemData(scrollamt + choice), status[scrollamt + choice], choice, TRUE); } else { /* radiolist */ if (!status[scrollamt + choice]) { for (i = 0; i < item_no; i++) status[i] = FALSE; status[scrollamt + choice] = TRUE; for (i = 0; i < max_choice; i++) print_item(list, ItemData(scrollamt + i), status[scrollamt + i], i, i == choice); } } (void) wnoutrefresh(list); (void) wmove(dialog, cur_y, cur_x); wrefresh(dialog); continue; /* wait for another key press */ } else if (key == ESC) { result = DLG_EXIT_ESC; continue; } if (!fkey) { fkey = TRUE; switch (key) { case '\n': case '\r': key = KEY_ENTER; break; case '-': key = KEY_UP; break; case '+': key = KEY_DOWN; break; case TAB: key = KEY_RIGHT; break; default: fkey = FALSE; break; } } /* * Check if key pressed matches first character of any item tag in * list. If there is more than one match, we will cycle through * each one as the same key is pressed repeatedly. */ found = FALSE; if (!fkey) { for (j = scrollamt + choice + 1; j < item_no; j++) { if (dlg_match_char(dlg_last_getc(), ItemName(j))) { found = TRUE; i = j - scrollamt; break; } } if (!found) { for (j = 0; j <= scrollamt + choice; j++) { if (dlg_match_char(dlg_last_getc(), ItemName(j))) { found = TRUE; i = j - scrollamt; break; } } } if (found) dlg_flush_getc(); } /* * A single digit (1-9) positions the selection to that line in the * current screen. */ if (!found && (key <= '9') && (key > '0') && (key - '1' < max_choice)) { found = TRUE; i = key - '1'; } if (!found) { if (fkey) { found = TRUE; switch (key) { case KEY_HOME: i = -scrollamt; break; case KEY_LL: case KEY_END: i = item_no - 1 - scrollamt; break; case M_EVENT + KEY_PPAGE: case KEY_PPAGE: if (choice) i = 0; else if (scrollamt != 0) i = -MIN(scrollamt, max_choice); else continue; break; case M_EVENT + KEY_NPAGE: case KEY_NPAGE: i = MIN(choice + max_choice, item_no - scrollamt - 1); break; case KEY_UP: i = choice - 1; if (choice == 0 && scrollamt == 0) continue; break; case KEY_DOWN: i = choice + 1; if (scrollamt + choice >= item_no - 1) continue; break; default: found = FALSE; break; } } } if (found) { if (i != choice) { getyx(dialog, cur_y, cur_x); if (i < 0 || i >= max_choice) { #if defined(NCURSES_VERSION_MAJOR) && NCURSES_VERSION_MAJOR < 5 /* * Using wscrl to assist ncurses scrolling is not needed * in version 5.x */ if (i == -1) { if (list_height > 1) { /* De-highlight current first item */ print_item(list, ItemData(scrollamt), status[scrollamt], 0, FALSE); scrollok(list, TRUE); wscrl(list, -1); scrollok(list, FALSE); } scrollamt--; print_item(list, ItemData(scrollamt), status[scrollamt], 0, TRUE); } else if (i == max_choice) { if (list_height > 1) { /* De-highlight current last item before scrolling up */ print_item(list, ItemData(scrollamt + max_choice - 1), status[scrollamt + max_choice - 1], max_choice - 1, FALSE); scrollok(list, TRUE); wscrl(list, 1); scrollok(list, FALSE); } scrollamt++; print_item(list, ItemData(scrollamt + max_choice - 1), status[scrollamt + max_choice - 1], max_choice - 1, TRUE); } else #endif { if (i < 0) { scrollamt += i; choice = 0; } else { choice = max_choice - 1; scrollamt += (i - max_choice + 1); } for (i = 0; i < max_choice; i++) { print_item(list, ItemData(scrollamt + i), status[scrollamt + i], i, i == choice); } } (void) wnoutrefresh(list); dlg_draw_arrows(dialog, scrollamt, scrollamt + choice < item_no - 1, box_x + check_x + 5, box_y, box_y + list_height + 1); } else { /* De-highlight current item */ print_item(list, ItemData(scrollamt + choice), status[scrollamt + choice], choice, FALSE); /* Highlight new item */ choice = i; print_item(list, ItemData(scrollamt + choice), status[scrollamt + choice], choice, TRUE); (void) wnoutrefresh(list); (void) wmove(dialog, cur_y, cur_x); wrefresh(dialog); } } continue; /* wait for another key press */ } if (fkey) { switch (key) { case KEY_ENTER: result = dlg_ok_buttoncode(button); break; case KEY_BTAB: case KEY_LEFT: button = dlg_prev_button(buttons, button); dlg_draw_buttons(dialog, height - 2, 0, buttons, button, FALSE, width); break; case KEY_RIGHT: button = dlg_next_button(buttons, button); dlg_draw_buttons(dialog, height - 2, 0, buttons, button, FALSE, width); break; default: if (key >= M_EVENT) { if ((key2 = dlg_ok_buttoncode(key - M_EVENT)) >= 0) { result = key2; break; } beep(); } } } else { beep(); } } del_window(dialog); switch (result) { case DLG_EXIT_OK: /* FALLTHRU */ case DLG_EXIT_EXTRA: for (i = 0; i < item_no; i++) { if (status[i]) { if (flag == FLAG_CHECK) { if (separate_output) { dlg_add_result(ItemName(i)); dlg_add_result("\n"); } else { dlg_add_result("\""); dlg_add_result(ItemName(i)); dlg_add_result("\" "); } } else { dlg_add_result(ItemName(i)); } } } break; case DLG_EXIT_HELP: dlg_add_result("HELP "); if (USE_ITEM_HELP(ItemHelp(scrollamt + choice))) { dlg_add_result(ItemHelp(scrollamt + choice)); result = DLG_EXIT_OK; /* this is inconsistent */ } else { dlg_add_result(ItemName(scrollamt + choice)); } break; } mouse_free_regions(); free(status); free(prompt); return result; }
/* * Display a dialog box with a list of options that can be turned on or off * The `flag' parameter is used to select between radiolist and checklist. */ int dialog_checklist(const char *title, const char *cprompt, int height, int width, int list_height, int item_no, char **items, int flag) { int result; int i, j; DIALOG_LISTITEM *listitems; bool separate_output = ((flag == FLAG_CHECK) && (dialog_vars.separate_output)); bool show_status = FALSE; int current = 0; char *help_result; listitems = dlg_calloc(DIALOG_LISTITEM, (size_t) item_no + 1); assert_ptr(listitems, "dialog_checklist"); for (i = j = 0; i < item_no; ++i) { listitems[i].name = items[j++]; listitems[i].text = (dialog_vars.no_items ? dlg_strempty() : items[j++]); listitems[i].state = !dlg_strcmp(items[j++], "on"); listitems[i].help = ((dialog_vars.item_help) ? items[j++] : dlg_strempty()); } dlg_align_columns(&listitems[0].text, (int) sizeof(DIALOG_LISTITEM), item_no); result = dlg_checklist(title, cprompt, height, width, list_height, item_no, listitems, NULL, flag, ¤t); switch (result) { case DLG_EXIT_OK: /* FALLTHRU */ case DLG_EXIT_EXTRA: show_status = TRUE; break; case DLG_EXIT_HELP: dlg_add_help_listitem(&result, &help_result, &listitems[current]); if ((show_status = dialog_vars.help_status)) { if (separate_output) { dlg_add_string(help_result); dlg_add_separator(); } else { dlg_add_quoted(help_result); } } else { dlg_add_string(help_result); } break; } if (show_status) { for (i = 0; i < item_no; i++) { if (listitems[i].state) { if (separate_output) { dlg_add_string(listitems[i].name); dlg_add_separator(); } else { if (dlg_need_separator()) dlg_add_separator(); if (flag == FLAG_CHECK) dlg_add_quoted(listitems[i].name); else dlg_add_string(listitems[i].name); } } } dlg_add_last_key(separate_output); } dlg_free_columns(&listitems[0].text, (int) sizeof(DIALOG_LISTITEM), item_no); free(listitems); return result; }
/* * Parse the configuration file and set up variables */ int dlg_parse_rc(void) { int i; int l = 1; PARSE_LINE parse; char str[MAX_LEN + 1]; char *var; char *value; char *tempptr; int result = 0; FILE *rc_file = 0; char *params; /* * At startup, dialog determines the settings to use as follows: * * a) if the environment variable $DIALOGRC is set, its value determines * the name of the configuration file. * * b) if the file in (a) can't be found, use the file $HOME/.dialogrc * as the configuration file. * * c) if the file in (b) can't be found, try using the GLOBALRC file. * Usually this will be /etc/dialogrc. * * d) if the file in (c) cannot be found, use the compiled-in defaults. */ /* try step (a) */ if ((tempptr = getenv("DIALOGRC")) != NULL) rc_file = fopen(tempptr, "rt"); if (rc_file == NULL) { /* step (a) failed? */ /* try step (b) */ if ((tempptr = getenv("HOME")) != NULL && strlen(tempptr) < MAX_LEN - (sizeof(DIALOGRC) + 3)) { if (tempptr[0] == '\0' || lastch(tempptr) == '/') sprintf(str, "%s%s", tempptr, DIALOGRC); else sprintf(str, "%s/%s", tempptr, DIALOGRC); rc_file = fopen(tempptr = str, "rt"); } } if (rc_file == NULL) { /* step (b) failed? */ /* try step (c) */ strcpy(str, GLOBALRC); if ((rc_file = fopen(tempptr = str, "rt")) == NULL) return 0; /* step (c) failed, use default values */ } DLG_TRACE(("opened rc file \"%s\"\n", tempptr)); /* Scan each line and set variables */ while ((result == 0) && (fgets(str, MAX_LEN, rc_file) != NULL)) { DLG_TRACE(("rc:%s", str)); if (*str == '\0' || lastch(str) != '\n') { /* ignore rest of file if line too long */ fprintf(stderr, "\nParse error: line %d of configuration" " file too long.\n", l); result = -1; /* parse aborted */ break; } lastch(str) = '\0'; if (begins_with(str, "bindkey", ¶ms)) { if (!dlg_parse_bindkey(params)) { fprintf(stderr, "\nParse error: line %d of configuration\n", l); result = -1; } continue; } parse = parse_line(str, &var, &value); /* parse current line */ switch (parse) { case LINE_EMPTY: /* ignore blank lines and comments */ break; case LINE_EQUALS: /* search table for matching config variable name */ if ((i = find_vars(var)) >= 0) { switch (vars[i].type) { case VAL_INT: *((int *) vars[i].var) = atoi(value); break; case VAL_STR: if (!isquote(value[0]) || !isquote(lastch(value)) || strlen(value) < 2) { fprintf(stderr, "\nParse error: string value " "expected at line %d of configuration " "file.\n", l); result = -1; /* parse aborted */ } else { /* remove the (") quotes */ value++; lastch(value) = '\0'; strcpy((char *) vars[i].var, value); } break; case VAL_BOOL: if (!dlg_strcmp(value, "ON")) *((bool *) vars[i].var) = TRUE; else if (!dlg_strcmp(value, "OFF")) *((bool *) vars[i].var) = FALSE; else { fprintf(stderr, "\nParse error: boolean value " "expected at line %d of configuration " "file (found %s).\n", l, value); result = -1; /* parse aborted */ } break; } #ifdef HAVE_COLOR } else if ((i = find_color(var)) >= 0) { int fg = 0; int bg = 0; int hl = 0; if (str_to_attr(value, &fg, &bg, &hl) == -1) { fprintf(stderr, "\nParse error: attribute " "value expected at line %d of configuration " "file.\n", l); result = -1; /* parse aborted */ } else { dlg_color_table[i].fg = fg; dlg_color_table[i].bg = bg; dlg_color_table[i].hilite = hl; } } else { #endif /* HAVE_COLOR */ fprintf(stderr, "\nParse error: unknown variable " "at line %d of configuration file:\n\t%s\n", l, var); result = -1; /* parse aborted */ } break; case LINE_ERROR: fprintf(stderr, "\nParse error: syntax error at line %d of " "configuration file.\n", l); result = -1; /* parse aborted */ break; } l++; /* next line */ } (void) fclose(rc_file); return result; }
/* * Extract the foreground, background and highlight values from an attribute * represented as a string in one of two forms: * * "(foreground,background,highlight)" " "xxxx_color" */ static int str_to_attr(char *str, int *fg, int *bg, int *hl) { int i = 0, get_fg = 1; unsigned j; char tempstr[MAX_LEN + 1], *part; if (str[0] != '(' || lastch(str) != ')') { if ((i = find_color(str)) >= 0) { *fg = dlg_color_table[i].fg; *bg = dlg_color_table[i].bg; *hl = dlg_color_table[i].hilite; return 0; } return -1; /* invalid representation */ } /* remove the parenthesis */ strcpy(tempstr, str + 1); lastch(tempstr) = '\0'; /* get foreground and background */ while (1) { /* skip white space before fg/bg string */ i = skip_whitespace(tempstr, i); if (tempstr[i] == '\0') return -1; /* invalid representation */ part = tempstr + i; /* set 'part' to start of fg/bg string */ /* find end of fg/bg string */ while (!whitespace(tempstr[i]) && tempstr[i] != ',' && tempstr[i] != '\0') i++; if (tempstr[i] == '\0') return -1; /* invalid representation */ else if (whitespace(tempstr[i])) { /* not yet ',' */ tempstr[i++] = '\0'; /* skip white space before ',' */ i = skip_whitespace(tempstr, i); if (tempstr[i] != ',') return -1; /* invalid representation */ } tempstr[i++] = '\0'; /* skip the ',' */ for (j = 0; j < COLOR_COUNT && dlg_strcmp(part, color_names[j].name); j++) ; if (j == COLOR_COUNT) /* invalid color name */ return -1; if (get_fg) { *fg = color_names[j].value; get_fg = 0; /* next we have to get the background */ } else { *bg = color_names[j].value; break; } } /* got foreground and background */ /* get highlight */ /* skip white space before highlight string */ i = skip_whitespace(tempstr, i); if (tempstr[i] == '\0') return -1; /* invalid representation */ part = tempstr + i; /* set 'part' to start of highlight string */ /* trim trailing white space from highlight string */ i = (int) strlen(part) - 1; while (whitespace(part[i]) && i > 0) i--; part[i + 1] = '\0'; if (!dlg_strcmp(part, "ON")) *hl = TRUE; else if (!dlg_strcmp(part, "OFF")) *hl = FALSE; else return -1; /* invalid highlight value */ return 0; }
/* * Display a dialog box with a list of options that can be turned on or off * The `flag' parameter is used to select between radiolist and checklist. */ int dialog_checklist(const char *title, const char *cprompt, int height, int width, int list_height, int item_no, char **items, int flag) { int result; int i; DIALOG_LISTITEM *listitems; bool separate_output = ((flag == FLAG_CHECK) && (dialog_vars.separate_output)); bool show_status = FALSE; int current = 0; listitems = dlg_calloc(DIALOG_LISTITEM, (size_t) item_no + 1); assert_ptr(listitems, "dialog_checklist"); for (i = 0; i < item_no; ++i) { listitems[i].name = ItemName(i); listitems[i].text = ItemText(i); listitems[i].help = ((dialog_vars.item_help) ? ItemHelp(i) : dlg_strempty()); listitems[i].state = !dlg_strcmp(ItemStatus(i), "on"); } dlg_align_columns(&listitems[0].text, (int) sizeof(DIALOG_LISTITEM), item_no); result = dlg_checklist(title, cprompt, height, width, list_height, item_no, listitems, NULL, flag, ¤t); switch (result) { case DLG_EXIT_OK: /* FALLTHRU */ case DLG_EXIT_EXTRA: show_status = TRUE; break; case DLG_EXIT_HELP: dlg_add_result("HELP "); show_status = dialog_vars.help_status; if (USE_ITEM_HELP(listitems[current].help)) { if (show_status) { if (separate_output) { dlg_add_string(listitems[current].help); dlg_add_separator(); } else { dlg_add_quoted(listitems[current].help); } } else { dlg_add_string(listitems[current].help); } result = DLG_EXIT_ITEM_HELP; } else { if (show_status) { if (separate_output) { dlg_add_string(listitems[current].name); dlg_add_separator(); } else { dlg_add_quoted(listitems[current].name); } } else { dlg_add_string(listitems[current].name); } } break; } if (show_status) { for (i = 0; i < item_no; i++) { if (listitems[i].state) { if (separate_output) { dlg_add_string(listitems[i].name); dlg_add_separator(); } else { if (dlg_need_separator()) dlg_add_separator(); dlg_add_string(listitems[i].name); } } } } dlg_free_columns(&listitems[0].text, (int) sizeof(DIALOG_LISTITEM), item_no); free(listitems); return result; }