14c8945a0SNathan Whitehorn /* 2a96ef450SBaptiste Daroussin * $Id: dialog.c,v 1.281 2021/01/17 16:52:18 tom Exp $ 34c8945a0SNathan Whitehorn * 44c8945a0SNathan Whitehorn * cdialog - Display simple dialog boxes from shell scripts 54c8945a0SNathan Whitehorn * 6a96ef450SBaptiste Daroussin * Copyright 2000-2020,2021 Thomas E. Dickey 74c8945a0SNathan Whitehorn * 84c8945a0SNathan Whitehorn * This program is free software; you can redistribute it and/or modify 94c8945a0SNathan Whitehorn * it under the terms of the GNU Lesser General Public License, version 2.1 104c8945a0SNathan Whitehorn * as published by the Free Software Foundation. 114c8945a0SNathan Whitehorn * 124c8945a0SNathan Whitehorn * This program is distributed in the hope that it will be useful, but 134c8945a0SNathan Whitehorn * WITHOUT ANY WARRANTY; without even the implied warranty of 144c8945a0SNathan Whitehorn * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 154c8945a0SNathan Whitehorn * Lesser General Public License for more details. 164c8945a0SNathan Whitehorn * 174c8945a0SNathan Whitehorn * You should have received a copy of the GNU Lesser General Public 184c8945a0SNathan Whitehorn * License along with this program; if not, write to 194c8945a0SNathan Whitehorn * Free Software Foundation, Inc. 204c8945a0SNathan Whitehorn * 51 Franklin St., Fifth Floor 214c8945a0SNathan Whitehorn * Boston, MA 02110, USA. 224c8945a0SNathan Whitehorn * 234c8945a0SNathan Whitehorn * An earlier version of this program lists as authors 244c8945a0SNathan Whitehorn * Savio Lam (lam836@cs.cuhk.hk) 254c8945a0SNathan Whitehorn */ 264c8945a0SNathan Whitehorn 274c8945a0SNathan Whitehorn #include <dialog.h> 28a96ef450SBaptiste Daroussin 294c8945a0SNathan Whitehorn #include <string.h> 304c8945a0SNathan Whitehorn #include <sys/types.h> 314c8945a0SNathan Whitehorn #include <sys/stat.h> 324c8945a0SNathan Whitehorn 334c8945a0SNathan Whitehorn #ifdef HAVE_SETLOCALE 344c8945a0SNathan Whitehorn #include <locale.h> 354c8945a0SNathan Whitehorn #endif 364c8945a0SNathan Whitehorn 37a96ef450SBaptiste Daroussin #include <dlg_internals.h> 38a96ef450SBaptiste Daroussin 394c8945a0SNathan Whitehorn #define PASSARGS t, av, offset_add 404c8945a0SNathan Whitehorn #define CALLARGS const char *t, char *av[], int *offset_add 414c8945a0SNathan Whitehorn typedef int (callerFn) (CALLARGS); 424c8945a0SNathan Whitehorn 434c8945a0SNathan Whitehorn typedef enum { 444c8945a0SNathan Whitehorn o_unknown = 0 454c8945a0SNathan Whitehorn ,o_allow_close 464c8945a0SNathan Whitehorn ,o_and_widget 474c8945a0SNathan Whitehorn ,o_ascii_lines 48a96ef450SBaptiste Daroussin ,o_aspect_ratio 494c8945a0SNathan Whitehorn ,o_auto_placement 504c8945a0SNathan Whitehorn ,o_backtitle 51a96ef450SBaptiste Daroussin ,o_beep_signal 52a96ef450SBaptiste Daroussin ,o_beep_after_signal 53a96ef450SBaptiste Daroussin ,o_begin_set 544c8945a0SNathan Whitehorn ,o_cancel_label 554c8945a0SNathan Whitehorn ,o_checklist 56a96ef450SBaptiste Daroussin ,o_dlg_clear_screen 574c8945a0SNathan Whitehorn ,o_colors 584c8945a0SNathan Whitehorn ,o_column_separator 594c8945a0SNathan Whitehorn ,o_cr_wrap 604c8945a0SNathan Whitehorn ,o_create_rc 61a96ef450SBaptiste Daroussin ,o_cursor_off_label 624c8945a0SNathan Whitehorn ,o_date_format 632a3e3873SBaptiste Daroussin ,o_default_button 644c8945a0SNathan Whitehorn ,o_default_item 654c8945a0SNathan Whitehorn ,o_defaultno 66a96ef450SBaptiste Daroussin ,o_erase_on_exit 674c8945a0SNathan Whitehorn ,o_exit_label 684c8945a0SNathan Whitehorn ,o_extra_button 694c8945a0SNathan Whitehorn ,o_extra_label 704c8945a0SNathan Whitehorn ,o_fixed_font 714c8945a0SNathan Whitehorn ,o_form 724c8945a0SNathan Whitehorn ,o_gauge 734c8945a0SNathan Whitehorn ,o_help 744c8945a0SNathan Whitehorn ,o_help_button 75682c9e0fSNathan Whitehorn ,o_help_file 764c8945a0SNathan Whitehorn ,o_help_label 77682c9e0fSNathan Whitehorn ,o_help_line 784c8945a0SNathan Whitehorn ,o_help_status 79febdb468SDevin Teske ,o_help_tags 804c8945a0SNathan Whitehorn ,o_icon 814c8945a0SNathan Whitehorn ,o_ignore 824c8945a0SNathan Whitehorn ,o_infobox 834c8945a0SNathan Whitehorn ,o_input_fd 844c8945a0SNathan Whitehorn ,o_inputbox 854c8945a0SNathan Whitehorn ,o_inputmenu 864c8945a0SNathan Whitehorn ,o_insecure 874c8945a0SNathan Whitehorn ,o_item_help 884c8945a0SNathan Whitehorn ,o_keep_colors 894c8945a0SNathan Whitehorn ,o_keep_tite 904c8945a0SNathan Whitehorn ,o_keep_window 912a3e3873SBaptiste Daroussin ,o_last_key 924c8945a0SNathan Whitehorn ,o_max_input 934c8945a0SNathan Whitehorn ,o_menu 944c8945a0SNathan Whitehorn ,o_mixedform 954c8945a0SNathan Whitehorn ,o_mixedgauge 964c8945a0SNathan Whitehorn ,o_msgbox 974c8945a0SNathan Whitehorn ,o_no_close 98a96ef450SBaptiste Daroussin ,o_nocollapse 994c8945a0SNathan Whitehorn ,o_no_cr_wrap 100a96ef450SBaptiste Daroussin ,o_cant_kill 101a96ef450SBaptiste Daroussin ,o_no_hot_list 1024c8945a0SNathan Whitehorn ,o_no_label 1034c8945a0SNathan Whitehorn ,o_no_lines 1047a1c0d96SNathan Whitehorn ,o_no_mouse 105682c9e0fSNathan Whitehorn ,o_no_nl_expand 106a96ef450SBaptiste Daroussin ,o_use_shadow 1074c8945a0SNathan Whitehorn ,o_nocancel 1084c8945a0SNathan Whitehorn ,o_nook 1094c8945a0SNathan Whitehorn ,o_ok_label 1104c8945a0SNathan Whitehorn ,o_output_fd 1114c8945a0SNathan Whitehorn ,o_output_separator 1124c8945a0SNathan Whitehorn ,o_passwordbox 1134c8945a0SNathan Whitehorn ,o_passwordform 1144c8945a0SNathan Whitehorn ,o_pause 1157a1c0d96SNathan Whitehorn ,o_prgbox 1164c8945a0SNathan Whitehorn ,o_print_maxsize 117a96ef450SBaptiste Daroussin ,o_print_siz 118a96ef450SBaptiste Daroussin ,o_text_only 119f4f33ea0SBaptiste Daroussin ,o_print_text_size 1204c8945a0SNathan Whitehorn ,o_print_version 1217a1c0d96SNathan Whitehorn ,o_programbox 1224c8945a0SNathan Whitehorn ,o_progressbox 1234c8945a0SNathan Whitehorn ,o_quoted 1244c8945a0SNathan Whitehorn ,o_radiolist 1254c8945a0SNathan Whitehorn ,o_screen_center 126a96ef450SBaptiste Daroussin ,o_use_scrollbar 1274c8945a0SNathan Whitehorn ,o_separate_output 128a96ef450SBaptiste Daroussin ,o_separate_str 1294c8945a0SNathan Whitehorn ,o_single_quoted 1304c8945a0SNathan Whitehorn ,o_size_err 131a96ef450SBaptiste Daroussin ,o_sleep_secs 1324c8945a0SNathan Whitehorn ,o_smooth 133a96ef450SBaptiste Daroussin ,o_output_stderr 134a96ef450SBaptiste Daroussin ,o_output_stdout 1354c8945a0SNathan Whitehorn ,o_tab_correct 1364c8945a0SNathan Whitehorn ,o_tab_len 1374c8945a0SNathan Whitehorn ,o_tailbox 1384c8945a0SNathan Whitehorn ,o_tailboxbg 1394c8945a0SNathan Whitehorn ,o_textbox 1404c8945a0SNathan Whitehorn ,o_time_format 141a96ef450SBaptiste Daroussin ,o_timeout_secs 1424c8945a0SNathan Whitehorn ,o_title 143a96ef450SBaptiste Daroussin ,o_trim_whitespace 1444c8945a0SNathan Whitehorn ,o_under_mouse 145682c9e0fSNathan Whitehorn ,o_version 1464c8945a0SNathan Whitehorn ,o_visit_items 1474c8945a0SNathan Whitehorn ,o_wmclass 1484c8945a0SNathan Whitehorn ,o_yes_label 1494c8945a0SNathan Whitehorn ,o_yesno 1502a3e3873SBaptiste Daroussin #ifdef HAVE_WHIPTAIL 1512a3e3873SBaptiste Daroussin ,o_fullbutton 1522a3e3873SBaptiste Daroussin ,o_topleft 1532a3e3873SBaptiste Daroussin #endif 1542a3e3873SBaptiste Daroussin #ifdef HAVE_XDIALOG 1552a3e3873SBaptiste Daroussin ,o_calendar 1562a3e3873SBaptiste Daroussin ,o_dselect 1572a3e3873SBaptiste Daroussin ,o_editbox 1582a3e3873SBaptiste Daroussin ,o_fselect 1592a3e3873SBaptiste Daroussin ,o_timebox 160f4f33ea0SBaptiste Daroussin ,o_week_start 1612a3e3873SBaptiste Daroussin #endif 1622a3e3873SBaptiste Daroussin #ifdef HAVE_XDIALOG2 1632a3e3873SBaptiste Daroussin ,o_buildlist 1642a3e3873SBaptiste Daroussin ,o_rangebox 165f4f33ea0SBaptiste Daroussin ,o_reorder 1662a3e3873SBaptiste Daroussin ,o_treeview 1672a3e3873SBaptiste Daroussin #endif 1682a3e3873SBaptiste Daroussin #if defined(HAVE_XDIALOG2) || defined(HAVE_WHIPTAIL) 1692a3e3873SBaptiste Daroussin ,o_no_items 1702a3e3873SBaptiste Daroussin ,o_no_tags 1712a3e3873SBaptiste Daroussin #endif 1724c8945a0SNathan Whitehorn #ifdef HAVE_DLG_TRACE 1734c8945a0SNathan Whitehorn ,o_trace 1744c8945a0SNathan Whitehorn #endif 175f4f33ea0SBaptiste Daroussin ,o_iso_week 1764c8945a0SNathan Whitehorn } eOptions; 1774c8945a0SNathan Whitehorn 178a96ef450SBaptiste Daroussin typedef enum { 179a96ef450SBaptiste Daroussin tUnknown 180a96ef450SBaptiste Daroussin ,tFalse 181a96ef450SBaptiste Daroussin ,tTrue 182a96ef450SBaptiste Daroussin ,tNumber 183a96ef450SBaptiste Daroussin ,tString 184a96ef450SBaptiste Daroussin } tOptions; 185a96ef450SBaptiste Daroussin 1864c8945a0SNathan Whitehorn /* 1874c8945a0SNathan Whitehorn * The bits in 'pass' are used to decide which options are applicable at 1884c8945a0SNathan Whitehorn * different stages in the program: 1894c8945a0SNathan Whitehorn * 1 flags before widgets 1904c8945a0SNathan Whitehorn * 2 widgets 1914c8945a0SNathan Whitehorn * 4 non-widget options 1924c8945a0SNathan Whitehorn */ 1934c8945a0SNathan Whitehorn typedef struct { 1944c8945a0SNathan Whitehorn const char *name; 1954c8945a0SNathan Whitehorn eOptions code; 196a96ef450SBaptiste Daroussin int vars; /* 0=none, 1=state, 2=vars */ 197a96ef450SBaptiste Daroussin tOptions type; /* type for bool(true/false), number, string */ 198a96ef450SBaptiste Daroussin unsigned offset; 1994c8945a0SNathan Whitehorn int pass; /* 1,2,4 or combination */ 2004c8945a0SNathan Whitehorn const char *help; /* NULL to suppress, non-empty to display params */ 2014c8945a0SNathan Whitehorn } Options; 2024c8945a0SNathan Whitehorn 2034c8945a0SNathan Whitehorn typedef struct { 2044c8945a0SNathan Whitehorn eOptions code; 2054c8945a0SNathan Whitehorn int argmin, argmax; 2064c8945a0SNathan Whitehorn callerFn *jumper; 2074c8945a0SNathan Whitehorn } Mode; 2084c8945a0SNathan Whitehorn 209a96ef450SBaptiste Daroussin /* use these macros for simple options in DIALOG_STATE */ 210a96ef450SBaptiste Daroussin #define ssF(name) o_##name, 1, tFalse, offsetof(DIALOG_STATE,name) 211a96ef450SBaptiste Daroussin #define ssT(name) o_##name, 1, tTrue, offsetof(DIALOG_STATE,name) 212a96ef450SBaptiste Daroussin #define ssN(name) o_##name, 1, tNumber, offsetof(DIALOG_STATE,name) 213a96ef450SBaptiste Daroussin #define ssS(name) o_##name, 1, tString, offsetof(DIALOG_STATE,name) 214a96ef450SBaptiste Daroussin 215a96ef450SBaptiste Daroussin /* use these macros for simple options in DIALOG_VARS */ 216a96ef450SBaptiste Daroussin #define svF(name) o_##name, 2, tFalse, offsetof(DIALOG_VARS,name) 217a96ef450SBaptiste Daroussin #define svT(name) o_##name, 2, tTrue, offsetof(DIALOG_VARS,name) 218a96ef450SBaptiste Daroussin #define svN(name) o_##name, 2, tNumber, offsetof(DIALOG_VARS,name) 219a96ef450SBaptiste Daroussin #define svS(name) o_##name, 2, tString, offsetof(DIALOG_VARS,name) 220a96ef450SBaptiste Daroussin 221a96ef450SBaptiste Daroussin /* use these macros for ignored options */ 222a96ef450SBaptiste Daroussin #define xxF(name) o_##name, 0, tFalse, 0 223a96ef450SBaptiste Daroussin #define xxT(name) o_##name, 0, tTrue, 0 224a96ef450SBaptiste Daroussin #define xxN(name) o_##name, 0, tNumber, 0 225a96ef450SBaptiste Daroussin #define xxS(name) o_##name, 0, tString, 0 226a96ef450SBaptiste Daroussin 227a96ef450SBaptiste Daroussin /* use this macro for widget options */ 228a96ef450SBaptiste Daroussin #define opW(name) o_##name, 0, 0, 0 229a96ef450SBaptiste Daroussin 230a96ef450SBaptiste Daroussin /* use this macro for other options */ 231a96ef450SBaptiste Daroussin #define opO(name) o_##name, 0, 0, 0 232a96ef450SBaptiste Daroussin 233f4f33ea0SBaptiste Daroussin static int known_opts = 0; 234f4f33ea0SBaptiste Daroussin static const char **dialog_opts; 2354c8945a0SNathan Whitehorn static char **dialog_argv; 2364c8945a0SNathan Whitehorn 237f4f33ea0SBaptiste Daroussin static char **special_argv = 0; 238f4f33ea0SBaptiste Daroussin static int special_argc = 0; 239f4f33ea0SBaptiste Daroussin 2404c8945a0SNathan Whitehorn static bool ignore_unknown = FALSE; 2414c8945a0SNathan Whitehorn 2424c8945a0SNathan Whitehorn static const char *program = "dialog"; 2434c8945a0SNathan Whitehorn 244f4f33ea0SBaptiste Daroussin #ifdef NO_LEAKS 245f4f33ea0SBaptiste Daroussin typedef struct _all_blobs { 246f4f33ea0SBaptiste Daroussin struct _all_blobs *next; 247f4f33ea0SBaptiste Daroussin void *blob; 248f4f33ea0SBaptiste Daroussin } AllBlobs; 249f4f33ea0SBaptiste Daroussin 250f4f33ea0SBaptiste Daroussin static AllBlobs *all_blobs; 251f4f33ea0SBaptiste Daroussin #endif 252f4f33ea0SBaptiste Daroussin 2534c8945a0SNathan Whitehorn /* 2544c8945a0SNathan Whitehorn * The options[] table is organized this way to make it simple to maintain 2554c8945a0SNathan Whitehorn * a sorted list of options for the help-message. 256a96ef450SBaptiste Daroussin * 257a96ef450SBaptiste Daroussin * Because Boolean options correspond to "true", --shadow is listed here while 258a96ef450SBaptiste Daroussin * --no-shadow is not. The findOption and optionBool functions handle the 259a96ef450SBaptiste Daroussin * cases where "no" is added or removed from the option name to derive an 260a96ef450SBaptiste Daroussin * opposite setting. 2614c8945a0SNathan Whitehorn */ 2624c8945a0SNathan Whitehorn /* *INDENT-OFF* */ 2634c8945a0SNathan Whitehorn static const Options options[] = { 264a96ef450SBaptiste Daroussin { "allow-close", xxT(allow_close), 1, NULL }, 265a96ef450SBaptiste Daroussin { "and-widget", opO(and_widget), 4, NULL }, 266a96ef450SBaptiste Daroussin { "ascii-lines", svT(ascii_lines), 1, "" }, 267a96ef450SBaptiste Daroussin { "aspect", ssN(aspect_ratio), 1, "<ratio>" }, 268a96ef450SBaptiste Daroussin { "auto-placement", xxT(auto_placement), 1, NULL }, 269a96ef450SBaptiste Daroussin { "backtitle", svS(backtitle), 1, "<backtitle>" }, 270a96ef450SBaptiste Daroussin { "beep", svT(beep_signal), 1, "" }, 271a96ef450SBaptiste Daroussin { "beep-after", svT(beep_after_signal), 1, "" }, 272a96ef450SBaptiste Daroussin { "begin", svT(begin_set), 1, "<y> <x>" }, 273a96ef450SBaptiste Daroussin { "cancel-label", svS(cancel_label), 1, "<str>" }, 274a96ef450SBaptiste Daroussin { "checklist", opW(checklist), 2, "<text> <height> <width> <list height> <tag1> <item1> <status1>..." }, 275a96ef450SBaptiste Daroussin { "clear", svT(dlg_clear_screen), 1, "" }, 276a96ef450SBaptiste Daroussin { "colors", svT(colors), 1, "" }, 277a96ef450SBaptiste Daroussin { "column-separator",svS(column_separator), 1, "<str>" }, 278a96ef450SBaptiste Daroussin { "cr-wrap", svT(cr_wrap), 1, "" }, 279a96ef450SBaptiste Daroussin { "create-rc", opO(create_rc), 1, NULL }, 280a96ef450SBaptiste Daroussin { "cursor-off-label",svT(cursor_off_label), 1, "" }, 281a96ef450SBaptiste Daroussin { "date-format", svS(date_format), 1, "<str>" }, 282a96ef450SBaptiste Daroussin { "default-button", xxS(default_button), 1, "<str>" }, 283a96ef450SBaptiste Daroussin { "default-item", svS(default_item), 1, "<str>" }, 284a96ef450SBaptiste Daroussin { "defaultno", svT(defaultno), 1, "" }, 285a96ef450SBaptiste Daroussin { "erase-on-exit", svT(erase_on_exit), 1, "" }, 286a96ef450SBaptiste Daroussin { "exit-label", svS(exit_label), 1, "<str>" }, 287a96ef450SBaptiste Daroussin { "extra-button", svT(extra_button), 1, "" }, 288a96ef450SBaptiste Daroussin { "extra-label", svS(extra_label), 1, "<str>" }, 289a96ef450SBaptiste Daroussin { "fixed-font", xxT(fixed_font), 1, NULL }, 290a96ef450SBaptiste Daroussin { "form", opW(form), 2, "<text> <height> <width> <form height> <label1> <l_y1> <l_x1> <item1> <i_y1> <i_x1> <flen1> <ilen1>..." }, 291a96ef450SBaptiste Daroussin { "gauge", opW(gauge), 2, "<text> <height> <width> [<percent>]" }, 292a96ef450SBaptiste Daroussin { "guage", opW(gauge), 2, NULL }, 293a96ef450SBaptiste Daroussin { "help", opO(help), 4, "" }, 294a96ef450SBaptiste Daroussin { "help-button", svT(help_button), 1, "" }, 295a96ef450SBaptiste Daroussin { "help-label", svS(help_label), 1, "<str>" }, 296a96ef450SBaptiste Daroussin { "help-status", svT(help_status), 1, "" }, 297a96ef450SBaptiste Daroussin { "help-tags", svT(help_tags), 1, "" }, 298a96ef450SBaptiste Daroussin { "hfile", svS(help_file), 1, "<str>" }, 299a96ef450SBaptiste Daroussin { "hline", svS(help_line), 1, "<str>" }, 300a96ef450SBaptiste Daroussin { "icon", xxS(icon), 1, NULL }, 301a96ef450SBaptiste Daroussin { "ignore", opO(ignore), 1, "" }, 302a96ef450SBaptiste Daroussin { "infobox", opW(infobox), 2, "<text> <height> <width>" }, 303a96ef450SBaptiste Daroussin { "input-fd", opO(input_fd), 1, "<fd>" }, 304a96ef450SBaptiste Daroussin { "inputbox", opW(inputbox), 2, "<text> <height> <width> [<init>]" }, 305a96ef450SBaptiste Daroussin { "inputmenu", opW(inputmenu), 2, "<text> <height> <width> <menu height> <tag1> <item1>..." }, 306a96ef450SBaptiste Daroussin { "insecure", svT(insecure), 1, "" }, 307a96ef450SBaptiste Daroussin { "item-help", svT(item_help), 1, "" }, 308a96ef450SBaptiste Daroussin { "keep-colors", xxT(keep_colors), 1, NULL }, 309a96ef450SBaptiste Daroussin { "keep-tite", svT(keep_tite), 1, "" }, 310a96ef450SBaptiste Daroussin { "keep-window", svT(keep_window), 1, "" }, 311a96ef450SBaptiste Daroussin { "last-key", svT(last_key), 1, "" }, 312a96ef450SBaptiste Daroussin { "max-input", svN(max_input), 1, "<n>" }, 313a96ef450SBaptiste Daroussin { "menu", opW(menu), 2, "<text> <height> <width> <menu height> <tag1> <item1>..." }, 314a96ef450SBaptiste Daroussin { "mixedform", opW(mixedform), 2, "<text> <height> <width> <form height> <label1> <l_y1> <l_x1> <item1> <i_y1> <i_x1> <flen1> <ilen1> <itype>..." }, 315a96ef450SBaptiste Daroussin { "mixedgauge", opW(mixedgauge), 2, "<text> <height> <width> <percent> <tag1> <item1>..." }, 316a96ef450SBaptiste Daroussin { "msgbox", opW(msgbox), 2, "<text> <height> <width>" }, 317a96ef450SBaptiste Daroussin { "no-cancel", svT(nocancel), 1, "" }, 318a96ef450SBaptiste Daroussin { "no-close", xxT(no_close), 1, NULL }, 319a96ef450SBaptiste Daroussin { "no-collapse", svT(nocollapse), 1, "" }, 320a96ef450SBaptiste Daroussin { "no-hot-list", svT(no_hot_list), 1, "" }, 321a96ef450SBaptiste Daroussin { "no-kill", svT(cant_kill), 1, "" }, 322a96ef450SBaptiste Daroussin { "no-label", svS(no_label), 1, "<str>" }, 323a96ef450SBaptiste Daroussin { "no-lines", svT(no_lines), 1, "" }, 324a96ef450SBaptiste Daroussin { "no-mouse", ssT(no_mouse), 1, "" }, 325a96ef450SBaptiste Daroussin { "no-nl-expand", svT(no_nl_expand), 1, "" }, 326a96ef450SBaptiste Daroussin { "no-ok", svT(nook), 1, "" }, 327a96ef450SBaptiste Daroussin { "no-shadow", ssF(use_shadow), 1, "" }, 328a96ef450SBaptiste Daroussin { "ok-label", svS(ok_label), 1, "<str>" }, 329a96ef450SBaptiste Daroussin { "output-fd", opO(output_fd), 1, "<fd>" }, 330a96ef450SBaptiste Daroussin { "output-separator",svS(output_separator), 1, "<str>" }, 331a96ef450SBaptiste Daroussin { "passwordbox", opW(passwordbox), 2, "<text> <height> <width> [<init>]" }, 332a96ef450SBaptiste Daroussin { "passwordform", opW(passwordform), 2, "<text> <height> <width> <form height> <label1> <l_y1> <l_x1> <item1> <i_y1> <i_x1> <flen1> <ilen1>..." }, 333a96ef450SBaptiste Daroussin { "pause", opW(pause), 2, "<text> <height> <width> <seconds>" }, 334a96ef450SBaptiste Daroussin { "prgbox", opW(prgbox), 2, "<text> <command> <height> <width>" }, 335a96ef450SBaptiste Daroussin { "print-maxsize", opO(print_maxsize), 1, "" }, 336a96ef450SBaptiste Daroussin { "print-size", svT(print_siz), 1, "" }, 337a96ef450SBaptiste Daroussin { "print-text-only",ssT(text_only), 5, "<text> <height> <width>" }, 338a96ef450SBaptiste Daroussin { "print-text-size",opO(print_text_size), 5, "<text> <height> <width>" }, 339a96ef450SBaptiste Daroussin { "print-version", opO(print_version), 5, "" }, 340a96ef450SBaptiste Daroussin { "programbox", opW(programbox), 2, "<text> <height> <width>" }, 341a96ef450SBaptiste Daroussin { "progressbox", opW(progressbox), 2, "<text> <height> <width>" }, 342a96ef450SBaptiste Daroussin { "quoted", svT(quoted), 1, "" }, 343a96ef450SBaptiste Daroussin { "radiolist", opW(radiolist), 2, "<text> <height> <width> <list height> <tag1> <item1> <status1>..." }, 344a96ef450SBaptiste Daroussin { "screen-center", xxT(screen_center), 1, NULL }, 345a96ef450SBaptiste Daroussin { "scrollbar", ssT(use_scrollbar), 1, "" }, 346a96ef450SBaptiste Daroussin { "separate-output",svT(separate_output), 1, "" }, 347a96ef450SBaptiste Daroussin { "separate-widget",ssS(separate_str), 1, "<str>" }, 348a96ef450SBaptiste Daroussin { "separator", svS(output_separator), 1, NULL }, 349a96ef450SBaptiste Daroussin { "single-quoted", svT(single_quoted), 1, "" }, 350a96ef450SBaptiste Daroussin { "size-err", svT(size_err), 1, "" }, 351a96ef450SBaptiste Daroussin { "sleep", svN(sleep_secs), 1, "<secs>" }, 352a96ef450SBaptiste Daroussin { "smooth", xxT(smooth), 1, NULL }, 353a96ef450SBaptiste Daroussin { "stderr", opO(output_stderr), 1, "" }, 354a96ef450SBaptiste Daroussin { "stdout", opO(output_stdout), 1, "" }, 355a96ef450SBaptiste Daroussin { "tab-correct", svT(tab_correct), 1, "" }, 356a96ef450SBaptiste Daroussin { "tab-len", ssN(tab_len), 1, "<n>" }, 357a96ef450SBaptiste Daroussin { "tailbox", opW(tailbox), 2, "<file> <height> <width>" }, 358a96ef450SBaptiste Daroussin { "tailboxbg", opW(tailboxbg), 2, "<file> <height> <width>" }, 359a96ef450SBaptiste Daroussin { "textbox", opW(textbox), 2, "<file> <height> <width>" }, 360a96ef450SBaptiste Daroussin { "time-format", svS(time_format), 1, "<str>" }, 361a96ef450SBaptiste Daroussin { "timeout", svN(timeout_secs), 1, "<secs>" }, 362a96ef450SBaptiste Daroussin { "title", svS(title), 1, "<title>" }, 363a96ef450SBaptiste Daroussin { "trim", svT(trim_whitespace), 1, "" }, 364a96ef450SBaptiste Daroussin { "under-mouse", xxT(under_mouse), 1, NULL }, 365a96ef450SBaptiste Daroussin { "version", opO(version), 5, "" }, 366a96ef450SBaptiste Daroussin { "visit-items", ssT(visit_items), 1, "" }, 367a96ef450SBaptiste Daroussin { "wmclass", xxS(wmclass), 1, NULL }, 368a96ef450SBaptiste Daroussin { "yes-label", svS(yes_label), 1, "<str>" }, 369a96ef450SBaptiste Daroussin { "yesno", opW(yesno), 2, "<text> <height> <width>" }, 3702a3e3873SBaptiste Daroussin #ifdef HAVE_WHIPTAIL 371a96ef450SBaptiste Daroussin { "cancel-button", svS(cancel_label), 1, NULL }, 372a96ef450SBaptiste Daroussin { "fb", xxT(fullbutton), 1, NULL }, 373a96ef450SBaptiste Daroussin { "fullbutton", xxT(fullbutton), 1, NULL }, 374a96ef450SBaptiste Daroussin { "no-button", svS(no_label), 1, NULL }, 375a96ef450SBaptiste Daroussin { "ok-button", svS(ok_label), 1, NULL }, 376a96ef450SBaptiste Daroussin { "scrolltext", ssT(use_scrollbar), 1, NULL }, 377a96ef450SBaptiste Daroussin { "topleft", svT(begin_set), 1, NULL }, 378a96ef450SBaptiste Daroussin { "yes-button", svS(yes_label), 1, NULL }, 3792a3e3873SBaptiste Daroussin #endif 3802a3e3873SBaptiste Daroussin #ifdef HAVE_XDIALOG 381a96ef450SBaptiste Daroussin { "calendar", opW(calendar), 2, "<text> <height> <width> <day> <month> <year>" }, 382a96ef450SBaptiste Daroussin { "dselect", opW(dselect), 2, "<directory> <height> <width>" }, 383a96ef450SBaptiste Daroussin { "editbox", opW(editbox), 2, "<file> <height> <width>" }, 384a96ef450SBaptiste Daroussin { "fselect", opW(fselect), 2, "<filepath> <height> <width>" }, 385a96ef450SBaptiste Daroussin { "timebox", opW(timebox), 2, "<text> <height> <width> <hour> <minute> <second>" }, 386a96ef450SBaptiste Daroussin { "week-start", svS(week_start), 1, "<str>" }, 387a96ef450SBaptiste Daroussin { "iso-week", svT(iso_week), 1, NULL }, 3882a3e3873SBaptiste Daroussin #endif 3892a3e3873SBaptiste Daroussin #ifdef HAVE_XDIALOG2 390a96ef450SBaptiste Daroussin { "buildlist", opW(buildlist), 2, "<text> <height> <width> <list-height> <tag1> <item1> <status1>..." }, 391a96ef450SBaptiste Daroussin { "no-items", svT(no_items), 1, "" }, 392a96ef450SBaptiste Daroussin { "no-tags", svT(no_tags), 1, "" }, 393a96ef450SBaptiste Daroussin { "rangebox", opW(rangebox), 2, "<text> <height> <width> <min-value> <max-value> <default-value>" }, 394a96ef450SBaptiste Daroussin { "reorder", svT(reorder), 1, "" }, 395a96ef450SBaptiste Daroussin { "treeview", opW(treeview), 2, "<text> <height> <width> <list-height> <tag1> <item1> <status1> <depth1>..." }, 3962a3e3873SBaptiste Daroussin #endif 3972a3e3873SBaptiste Daroussin #if defined(HAVE_XDIALOG2) || defined(HAVE_WHIPTAIL) 398a96ef450SBaptiste Daroussin { "noitem", svT(no_items), 1, NULL }, 399a96ef450SBaptiste Daroussin { "notags", svT(no_tags), 1, NULL }, 4002a3e3873SBaptiste Daroussin #endif 4014c8945a0SNathan Whitehorn #ifdef HAVE_DLG_TRACE 402a96ef450SBaptiste Daroussin { "trace", opO(trace), 1, "<file>" }, 4034c8945a0SNathan Whitehorn #endif 4044c8945a0SNathan Whitehorn }; 4054c8945a0SNathan Whitehorn /* *INDENT-ON* */ 4064c8945a0SNathan Whitehorn 407f4f33ea0SBaptiste Daroussin #ifdef NO_LEAKS 408f4f33ea0SBaptiste Daroussin static void 409f4f33ea0SBaptiste Daroussin ignore_leak(void *value) 410f4f33ea0SBaptiste Daroussin { 411f4f33ea0SBaptiste Daroussin AllBlobs *next = dlg_calloc(AllBlobs, (size_t) 1); 412f4f33ea0SBaptiste Daroussin if (next != 0) { 413f4f33ea0SBaptiste Daroussin next->blob = value; 414f4f33ea0SBaptiste Daroussin next->next = all_blobs; 415f4f33ea0SBaptiste Daroussin all_blobs = next; 416f4f33ea0SBaptiste Daroussin } 417f4f33ea0SBaptiste Daroussin } 418f4f33ea0SBaptiste Daroussin 419f4f33ea0SBaptiste Daroussin static void 420f4f33ea0SBaptiste Daroussin handle_leaks(void) 421f4f33ea0SBaptiste Daroussin { 422f4f33ea0SBaptiste Daroussin while (all_blobs != 0) { 423f4f33ea0SBaptiste Daroussin char *blob = all_blobs->blob; 424f4f33ea0SBaptiste Daroussin AllBlobs *next = all_blobs->next; 425f4f33ea0SBaptiste Daroussin free(blob); 426f4f33ea0SBaptiste Daroussin free(all_blobs); 427f4f33ea0SBaptiste Daroussin all_blobs = next; 428f4f33ea0SBaptiste Daroussin } 429f4f33ea0SBaptiste Daroussin free(dialog_opts); 430f4f33ea0SBaptiste Daroussin if (special_argv != 0) { 431f4f33ea0SBaptiste Daroussin free(special_argv[0]); 432f4f33ea0SBaptiste Daroussin free(special_argv); 433f4f33ea0SBaptiste Daroussin special_argv = 0; 434f4f33ea0SBaptiste Daroussin special_argc = 0; 435f4f33ea0SBaptiste Daroussin } 436f4f33ea0SBaptiste Daroussin } 437f4f33ea0SBaptiste Daroussin #else 438f4f33ea0SBaptiste Daroussin #define handle_leaks() /* nothing */ 439f4f33ea0SBaptiste Daroussin #define ignore_leak(n) /* nothing */ 440f4f33ea0SBaptiste Daroussin #endif 441f4f33ea0SBaptiste Daroussin 442f4f33ea0SBaptiste Daroussin #define OptionChars "\ 443f4f33ea0SBaptiste Daroussin 0123456789\ 444f4f33ea0SBaptiste Daroussin -\ 445f4f33ea0SBaptiste Daroussin abcdefghijklmnopqrstuvwxyz\ 446f4f33ea0SBaptiste Daroussin " 447f4f33ea0SBaptiste Daroussin 448f4f33ea0SBaptiste Daroussin /* 449f4f33ea0SBaptiste Daroussin * Check if the given string from main's argv is an option. 450f4f33ea0SBaptiste Daroussin */ 451f4f33ea0SBaptiste Daroussin static bool 452f4f33ea0SBaptiste Daroussin isOption(const char *arg) 453f4f33ea0SBaptiste Daroussin { 454f4f33ea0SBaptiste Daroussin bool result = FALSE; 455f4f33ea0SBaptiste Daroussin 456f4f33ea0SBaptiste Daroussin if (arg != 0) { 457f4f33ea0SBaptiste Daroussin if (dialog_opts != 0) { 458f4f33ea0SBaptiste Daroussin int n; 459f4f33ea0SBaptiste Daroussin for (n = 0; dialog_opts[n] != 0; ++n) { 460f4f33ea0SBaptiste Daroussin if (dialog_opts[n] == arg) { 461f4f33ea0SBaptiste Daroussin result = TRUE; 462f4f33ea0SBaptiste Daroussin break; 463f4f33ea0SBaptiste Daroussin } 464f4f33ea0SBaptiste Daroussin } 465f4f33ea0SBaptiste Daroussin } else if (!strncmp(arg, "--", (size_t) 2) && isalpha(UCH(arg[2]))) { 466f4f33ea0SBaptiste Daroussin if (strlen(arg) == (strspn) (arg, OptionChars)) { 467f4f33ea0SBaptiste Daroussin result = TRUE; 468f4f33ea0SBaptiste Daroussin } else { 469f4f33ea0SBaptiste Daroussin handle_leaks(); 470f4f33ea0SBaptiste Daroussin dlg_exiterr("Invalid option \"%s\"", arg); 471f4f33ea0SBaptiste Daroussin } 472f4f33ea0SBaptiste Daroussin } 473f4f33ea0SBaptiste Daroussin } 474f4f33ea0SBaptiste Daroussin return result; 475f4f33ea0SBaptiste Daroussin } 476f4f33ea0SBaptiste Daroussin 4774c8945a0SNathan Whitehorn /* 4784c8945a0SNathan Whitehorn * Make an array showing which argv[] entries are options. Use "--" as a 4794c8945a0SNathan Whitehorn * special token to escape the next argument, allowing it to begin with "--". 4804c8945a0SNathan Whitehorn * When we find a "--" argument, also remove it from argv[] and adjust argc. 4814c8945a0SNathan Whitehorn * That appears to be an undocumented feature of the popt library. 4824c8945a0SNathan Whitehorn * 4834c8945a0SNathan Whitehorn * Also, if we see a "--file", expand it into the parameter list by reading the 4844c8945a0SNathan Whitehorn * text from the given file and stripping quotes, treating whitespace outside 4854c8945a0SNathan Whitehorn * quotes as a parameter delimiter. 4864c8945a0SNathan Whitehorn * 4874c8945a0SNathan Whitehorn * Finally, if we see a "--args", dump the current list of arguments to the 4884c8945a0SNathan Whitehorn * standard error. This is used for debugging complex --file combinations. 4894c8945a0SNathan Whitehorn */ 4904c8945a0SNathan Whitehorn static void 4914c8945a0SNathan Whitehorn unescape_argv(int *argcp, char ***argvp) 4924c8945a0SNathan Whitehorn { 4934c8945a0SNathan Whitehorn int j, k; 4944c8945a0SNathan Whitehorn int limit_includes = 20 + *argcp; 4954c8945a0SNathan Whitehorn int count_includes = 0; 4964c8945a0SNathan Whitehorn bool doalloc = FALSE; 4974c8945a0SNathan Whitehorn char *filename; 498f4f33ea0SBaptiste Daroussin const char **my_argv = 0; 499f4f33ea0SBaptiste Daroussin int my_argc; 5004c8945a0SNathan Whitehorn 501f4f33ea0SBaptiste Daroussin DLG_TRACE(("# unescape_argv\n")); 502f4f33ea0SBaptiste Daroussin for (k = 0; k < 2; ++k) { 503f4f33ea0SBaptiste Daroussin 504f4f33ea0SBaptiste Daroussin my_argc = 0; 505f4f33ea0SBaptiste Daroussin if (special_argv != 0) { 506f4f33ea0SBaptiste Daroussin for (j = 0; special_argv[j] != 0; ++j) { 507f4f33ea0SBaptiste Daroussin if (!strcmp(special_argv[j], "--")) { 508f4f33ea0SBaptiste Daroussin break; 509f4f33ea0SBaptiste Daroussin } else if (isOption(special_argv[j])) { 510f4f33ea0SBaptiste Daroussin if (k != 0) 511f4f33ea0SBaptiste Daroussin my_argv[my_argc] = special_argv[j]; 512f4f33ea0SBaptiste Daroussin my_argc++; 513f4f33ea0SBaptiste Daroussin } 514f4f33ea0SBaptiste Daroussin } 515f4f33ea0SBaptiste Daroussin } 516f4f33ea0SBaptiste Daroussin 517f4f33ea0SBaptiste Daroussin if (k == 0) { 518f4f33ea0SBaptiste Daroussin my_argc += (*argcp + 1); 519f4f33ea0SBaptiste Daroussin my_argv = dlg_calloc(const char *, (size_t) my_argc); 520f4f33ea0SBaptiste Daroussin assert_ptr(my_argv, "unescape_argv"); 521f4f33ea0SBaptiste Daroussin } 522f4f33ea0SBaptiste Daroussin } 5234c8945a0SNathan Whitehorn 5244c8945a0SNathan Whitehorn for (j = 1; j < *argcp; j++) { 5254c8945a0SNathan Whitehorn bool escaped = FALSE; 5264c8945a0SNathan Whitehorn if (!strcmp((*argvp)[j], "--")) { 5274c8945a0SNathan Whitehorn escaped = TRUE; 528f4f33ea0SBaptiste Daroussin dlg_eat_argv(argcp, argvp, j, 1); 5294c8945a0SNathan Whitehorn } else if (!strcmp((*argvp)[j], "--args")) { 5304c8945a0SNathan Whitehorn fprintf(stderr, "Showing arguments at arg%d\n", j); 5314c8945a0SNathan Whitehorn for (k = 0; k < *argcp; ++k) { 5324c8945a0SNathan Whitehorn fprintf(stderr, " arg%d:%s\n", k, (*argvp)[k]); 5334c8945a0SNathan Whitehorn } 534f4f33ea0SBaptiste Daroussin dlg_eat_argv(argcp, argvp, j, 1); 535f4f33ea0SBaptiste Daroussin --j; 5364c8945a0SNathan Whitehorn } else if (!strcmp((*argvp)[j], "--file")) { 537f4f33ea0SBaptiste Daroussin if (++count_includes > limit_includes) { 538f4f33ea0SBaptiste Daroussin handle_leaks(); 5394c8945a0SNathan Whitehorn dlg_exiterr("Too many --file options"); 540f4f33ea0SBaptiste Daroussin } 5414c8945a0SNathan Whitehorn 5424c8945a0SNathan Whitehorn if ((filename = (*argvp)[j + 1]) != 0) { 5434c8945a0SNathan Whitehorn FILE *fp; 5444c8945a0SNathan Whitehorn char **list; 5454c8945a0SNathan Whitehorn 5464c8945a0SNathan Whitehorn if (*filename == '&') { 5474c8945a0SNathan Whitehorn fp = fdopen(atoi(filename + sizeof(char)), "r"); 5484c8945a0SNathan Whitehorn } else { 5494c8945a0SNathan Whitehorn fp = fopen(filename, "r"); 5504c8945a0SNathan Whitehorn } 5514c8945a0SNathan Whitehorn 5524c8945a0SNathan Whitehorn if (fp) { 553a96ef450SBaptiste Daroussin char *blob; 554a96ef450SBaptiste Daroussin int added; 555a96ef450SBaptiste Daroussin size_t bytes_read; 556a96ef450SBaptiste Daroussin size_t length; 557a96ef450SBaptiste Daroussin int n; 558a96ef450SBaptiste Daroussin 559f4f33ea0SBaptiste Daroussin DLG_TRACE(("# opened --file %s ..\n", filename)); 5604c8945a0SNathan Whitehorn blob = NULL; 5614c8945a0SNathan Whitehorn length = 0; 5624c8945a0SNathan Whitehorn do { 5634c8945a0SNathan Whitehorn blob = dlg_realloc(char, length + BUFSIZ + 1, blob); 5644c8945a0SNathan Whitehorn assert_ptr(blob, "unescape_argv"); 5654c8945a0SNathan Whitehorn bytes_read = fread(blob + length, 5664c8945a0SNathan Whitehorn sizeof(char), 5677a1c0d96SNathan Whitehorn (size_t) BUFSIZ, 5684c8945a0SNathan Whitehorn fp); 5694c8945a0SNathan Whitehorn length += bytes_read; 570f4f33ea0SBaptiste Daroussin if (ferror(fp)) { 571f4f33ea0SBaptiste Daroussin handle_leaks(); 5724c8945a0SNathan Whitehorn dlg_exiterr("error on filehandle in unescape_argv"); 573f4f33ea0SBaptiste Daroussin } 5744c8945a0SNathan Whitehorn } while (bytes_read == BUFSIZ); 5754c8945a0SNathan Whitehorn fclose(fp); 5764c8945a0SNathan Whitehorn 5774c8945a0SNathan Whitehorn blob[length] = '\0'; 578f4f33ea0SBaptiste Daroussin ignore_leak(blob); 5794c8945a0SNathan Whitehorn 5807a1c0d96SNathan Whitehorn list = dlg_string_to_argv(blob); 581f4f33ea0SBaptiste Daroussin added = dlg_count_argv(list); 5824c8945a0SNathan Whitehorn if (added > 2) { 583f4f33ea0SBaptiste Daroussin /* *argcp arguments before the expansion of --file 584f4f33ea0SBaptiste Daroussin - 2 for the removal of '--file <filepath>' 585f4f33ea0SBaptiste Daroussin + added for the arguments contained in <filepath> 586f4f33ea0SBaptiste Daroussin + 1 for the terminating NULL pointer */ 587f4f33ea0SBaptiste Daroussin size_t need = (size_t) (*argcp + added - 1); 5884c8945a0SNathan Whitehorn if (doalloc) { 5894c8945a0SNathan Whitehorn *argvp = dlg_realloc(char *, need, *argvp); 5904c8945a0SNathan Whitehorn assert_ptr(*argvp, "unescape_argv"); 5914c8945a0SNathan Whitehorn } else { 5924c8945a0SNathan Whitehorn char **newp = dlg_malloc(char *, need); 593f4f33ea0SBaptiste Daroussin ignore_leak(newp); 5944c8945a0SNathan Whitehorn assert_ptr(newp, "unescape_argv"); 5954c8945a0SNathan Whitehorn for (n = 0; n < *argcp; ++n) { 5964c8945a0SNathan Whitehorn newp[n] = (*argvp)[n]; 5974c8945a0SNathan Whitehorn } 598f4f33ea0SBaptiste Daroussin /* The new array is not NULL-terminated yet. */ 5994c8945a0SNathan Whitehorn *argvp = newp; 6004c8945a0SNathan Whitehorn doalloc = TRUE; 6014c8945a0SNathan Whitehorn } 602f4f33ea0SBaptiste Daroussin my_argv = dlg_realloc(const char *, need, my_argv); 603f4f33ea0SBaptiste Daroussin assert_ptr(my_argv, "unescape_argv"); 604f4f33ea0SBaptiste Daroussin 605f4f33ea0SBaptiste Daroussin /* Shift the arguments after '--file <filepath>' 606f4f33ea0SBaptiste Daroussin right by (added - 2) positions */ 607f4f33ea0SBaptiste Daroussin for (n = *argcp - 1; n >= j + 2; --n) { 6084c8945a0SNathan Whitehorn (*argvp)[n + added - 2] = (*argvp)[n]; 6094c8945a0SNathan Whitehorn } 610f4f33ea0SBaptiste Daroussin } else if (added < 2) { 611f4f33ea0SBaptiste Daroussin /* 0 or 1 argument read from the included file 612f4f33ea0SBaptiste Daroussin -> shift the arguments after '--file <filepath>' 613f4f33ea0SBaptiste Daroussin left by (2 - added) positions */ 614f4f33ea0SBaptiste Daroussin for (n = j + added; n + 2 - added < *argcp; ++n) { 615f4f33ea0SBaptiste Daroussin (*argvp)[n] = (*argvp)[n + 2 - added]; 616f4f33ea0SBaptiste Daroussin } 617f4f33ea0SBaptiste Daroussin } 618f4f33ea0SBaptiste Daroussin /* Copy the inserted arguments to *argvp */ 6194c8945a0SNathan Whitehorn for (n = 0; n < added; ++n) { 6204c8945a0SNathan Whitehorn (*argvp)[n + j] = list[n]; 6214c8945a0SNathan Whitehorn } 6224c8945a0SNathan Whitehorn *argcp += added - 2; 623f4f33ea0SBaptiste Daroussin (*argvp)[*argcp] = 0; /* Write the NULL terminator */ 624f4f33ea0SBaptiste Daroussin free(list); /* No-op if 'list' is NULL */ 625f4f33ea0SBaptiste Daroussin /* Force rescan starting from the first inserted argument */ 626f4f33ea0SBaptiste Daroussin --j; 627f4f33ea0SBaptiste Daroussin DLG_TRACE(("# finished --file\n")); 6284c8945a0SNathan Whitehorn continue; 6294c8945a0SNathan Whitehorn } else { 630f4f33ea0SBaptiste Daroussin handle_leaks(); 631f4f33ea0SBaptiste Daroussin dlg_exiterr("Cannot open --file %s", filename); 632f4f33ea0SBaptiste Daroussin } 633f4f33ea0SBaptiste Daroussin } else { 634f4f33ea0SBaptiste Daroussin handle_leaks(); 6354c8945a0SNathan Whitehorn dlg_exiterr("No value given for --file"); 6364c8945a0SNathan Whitehorn } 6374c8945a0SNathan Whitehorn } 6384c8945a0SNathan Whitehorn if (!escaped 6394c8945a0SNathan Whitehorn && (*argvp)[j] != 0 6407a1c0d96SNathan Whitehorn && !strncmp((*argvp)[j], "--", (size_t) 2) 6414c8945a0SNathan Whitehorn && isalpha(UCH((*argvp)[j][2]))) { 642f4f33ea0SBaptiste Daroussin my_argv[my_argc++] = (*argvp)[j]; 643f4f33ea0SBaptiste Daroussin DLG_TRACE(("#\toption argv[%d]=%s\n", j, (*argvp)[j])); 6444c8945a0SNathan Whitehorn } 6454c8945a0SNathan Whitehorn } 6464c8945a0SNathan Whitehorn 647f4f33ea0SBaptiste Daroussin my_argv[my_argc] = 0; 648f4f33ea0SBaptiste Daroussin 649f4f33ea0SBaptiste Daroussin known_opts = my_argc; 650f4f33ea0SBaptiste Daroussin dialog_opts = my_argv; 651f4f33ea0SBaptiste Daroussin 652f4f33ea0SBaptiste Daroussin DLG_TRACE(("#\t%d options vs %d arguments\n", known_opts, *argcp)); 6534c8945a0SNathan Whitehorn dialog_argv = (*argvp); 6544c8945a0SNathan Whitehorn } 6554c8945a0SNathan Whitehorn 656a96ef450SBaptiste Daroussin static const Options * 657a96ef450SBaptiste Daroussin findOption(const char *name, int pass, bool recur) 6584c8945a0SNathan Whitehorn { 659a96ef450SBaptiste Daroussin const Options *result = NULL; 6604c8945a0SNathan Whitehorn 661a96ef450SBaptiste Daroussin if (!strncmp(name, "--", 2) && isalpha(UCH(name[2]))) { 662a96ef450SBaptiste Daroussin unsigned n; 663a96ef450SBaptiste Daroussin 664a96ef450SBaptiste Daroussin name += 2; /* skip the "--" */ 665a96ef450SBaptiste Daroussin for (n = 0; n < TableSize(options); n++) { 6664c8945a0SNathan Whitehorn if ((pass & options[n].pass) != 0 6674c8945a0SNathan Whitehorn && !strcmp(name, options[n].name)) { 668a96ef450SBaptiste Daroussin result = &options[n]; 6692a3e3873SBaptiste Daroussin break; 6704c8945a0SNathan Whitehorn } 6714c8945a0SNathan Whitehorn } 672a96ef450SBaptiste Daroussin if (result == NULL && !recur) { 673a96ef450SBaptiste Daroussin char *temp = malloc(8 + strlen(name)); 674a96ef450SBaptiste Daroussin if (temp != NULL) { 675a96ef450SBaptiste Daroussin if (!strncmp(name, "no", 2)) { 676a96ef450SBaptiste Daroussin int skip = !strncmp(name, "no-", 3) ? 3 : 2; 677a96ef450SBaptiste Daroussin sprintf(temp, "--no-%s", name + skip); 678a96ef450SBaptiste Daroussin result = findOption(temp, pass, TRUE); 679a96ef450SBaptiste Daroussin if (result == NULL) { 680a96ef450SBaptiste Daroussin sprintf(temp, "--%s", name + skip); 681a96ef450SBaptiste Daroussin result = findOption(temp, pass, TRUE); 682a96ef450SBaptiste Daroussin } 683a96ef450SBaptiste Daroussin } 684a96ef450SBaptiste Daroussin if (result == NULL && strncmp(name, "no", 2)) { 685a96ef450SBaptiste Daroussin sprintf(temp, "--no-%s", name); 686a96ef450SBaptiste Daroussin result = findOption(temp, pass, TRUE); 687a96ef450SBaptiste Daroussin } 688a96ef450SBaptiste Daroussin free(temp); 689a96ef450SBaptiste Daroussin } 690a96ef450SBaptiste Daroussin } 691a96ef450SBaptiste Daroussin } 692a96ef450SBaptiste Daroussin return result; 693a96ef450SBaptiste Daroussin } 694a96ef450SBaptiste Daroussin 695a96ef450SBaptiste Daroussin static eOptions 696a96ef450SBaptiste Daroussin lookupOption(const char *name, int pass) 697a96ef450SBaptiste Daroussin { 698a96ef450SBaptiste Daroussin eOptions result = o_unknown; 699a96ef450SBaptiste Daroussin const Options *data = findOption(name, pass, FALSE); 700a96ef450SBaptiste Daroussin if (data != NULL) { 701a96ef450SBaptiste Daroussin result = data->code; 7024c8945a0SNathan Whitehorn } 7032a3e3873SBaptiste Daroussin return result; 7044c8945a0SNathan Whitehorn } 7054c8945a0SNathan Whitehorn 7064c8945a0SNathan Whitehorn static void 7074c8945a0SNathan Whitehorn Usage(const char *msg) 7084c8945a0SNathan Whitehorn { 709f4f33ea0SBaptiste Daroussin handle_leaks(); 710a96ef450SBaptiste Daroussin dlg_exiterr("%s.\nUse --help to list options.\n\n", msg); 7114c8945a0SNathan Whitehorn } 7124c8945a0SNathan Whitehorn 7134c8945a0SNathan Whitehorn /* 7144c8945a0SNathan Whitehorn * Count arguments, stopping at the end of the argument list, or on any of our 7154c8945a0SNathan Whitehorn * "--" tokens. 7164c8945a0SNathan Whitehorn */ 7174c8945a0SNathan Whitehorn static int 7184c8945a0SNathan Whitehorn arg_rest(char *argv[]) 7194c8945a0SNathan Whitehorn { 7204c8945a0SNathan Whitehorn int i = 1; /* argv[0] points to a "--" token */ 7214c8945a0SNathan Whitehorn 7224c8945a0SNathan Whitehorn while (argv[i] != 0 7234c8945a0SNathan Whitehorn && (!isOption(argv[i]) || lookupOption(argv[i], 7) == o_unknown)) 7244c8945a0SNathan Whitehorn i++; 7254c8945a0SNathan Whitehorn return i; 7264c8945a0SNathan Whitehorn } 7274c8945a0SNathan Whitehorn 7284c8945a0SNathan Whitehorn /* 7294c8945a0SNathan Whitehorn * In MultiWidget this function is needed to count how many tags 7304c8945a0SNathan Whitehorn * a widget (menu, checklist, radiolist) has 7314c8945a0SNathan Whitehorn */ 7324c8945a0SNathan Whitehorn static int 7334c8945a0SNathan Whitehorn howmany_tags(char *argv[], int group) 7344c8945a0SNathan Whitehorn { 7354c8945a0SNathan Whitehorn int result = 0; 7364c8945a0SNathan Whitehorn char temp[80]; 7374c8945a0SNathan Whitehorn 7384c8945a0SNathan Whitehorn while (argv[0] != 0) { 739a96ef450SBaptiste Daroussin int have; 740a96ef450SBaptiste Daroussin 7414c8945a0SNathan Whitehorn if (isOption(argv[0])) 7424c8945a0SNathan Whitehorn break; 7434c8945a0SNathan Whitehorn if ((have = arg_rest(argv)) < group) { 744f4f33ea0SBaptiste Daroussin const char *format = _("Expected %d arguments, found only %d"); 7454c8945a0SNathan Whitehorn sprintf(temp, format, group, have); 7464c8945a0SNathan Whitehorn Usage(temp); 747f4f33ea0SBaptiste Daroussin } else if ((have % group) != 0) { 748f4f33ea0SBaptiste Daroussin const char *format = _("Expected %d arguments, found extra %d"); 749f4f33ea0SBaptiste Daroussin sprintf(temp, format, group, (have % group)); 750f4f33ea0SBaptiste Daroussin Usage(temp); 7514c8945a0SNathan Whitehorn } 7524c8945a0SNathan Whitehorn 753f4f33ea0SBaptiste Daroussin argv += have; 754f4f33ea0SBaptiste Daroussin result += (have / group); 7554c8945a0SNathan Whitehorn } 7564c8945a0SNathan Whitehorn 7574c8945a0SNathan Whitehorn return result; 7584c8945a0SNathan Whitehorn } 7594c8945a0SNathan Whitehorn 7604c8945a0SNathan Whitehorn static int 7614c8945a0SNathan Whitehorn numeric_arg(char **av, int n) 7624c8945a0SNathan Whitehorn { 7632a3e3873SBaptiste Daroussin int result = 0; 7642a3e3873SBaptiste Daroussin 7652a3e3873SBaptiste Daroussin if (n < dlg_count_argv(av)) { 7662a3e3873SBaptiste Daroussin char *last = 0; 7672a3e3873SBaptiste Daroussin result = (int) strtol(av[n], &last, 10); 7684c8945a0SNathan Whitehorn 7694c8945a0SNathan Whitehorn if (last == 0 || *last != 0) { 770a96ef450SBaptiste Daroussin char msg[80]; 771a96ef450SBaptiste Daroussin 7724c8945a0SNathan Whitehorn sprintf(msg, "Expected a number for token %d of %.20s", n, av[0]); 7734c8945a0SNathan Whitehorn Usage(msg); 7744c8945a0SNathan Whitehorn } 7752a3e3873SBaptiste Daroussin } 7764c8945a0SNathan Whitehorn return result; 7774c8945a0SNathan Whitehorn } 7784c8945a0SNathan Whitehorn 7794c8945a0SNathan Whitehorn static char * 7804c8945a0SNathan Whitehorn optional_str(char **av, int n, char *dft) 7814c8945a0SNathan Whitehorn { 7824c8945a0SNathan Whitehorn char *ret = dft; 7834c8945a0SNathan Whitehorn if (arg_rest(av) > n) 7844c8945a0SNathan Whitehorn ret = av[n]; 7854c8945a0SNathan Whitehorn return ret; 7864c8945a0SNathan Whitehorn } 7874c8945a0SNathan Whitehorn 7884c8945a0SNathan Whitehorn #if defined(HAVE_DLG_GAUGE) || defined(HAVE_XDIALOG) 7894c8945a0SNathan Whitehorn static int 7904c8945a0SNathan Whitehorn optional_num(char **av, int n, int dft) 7914c8945a0SNathan Whitehorn { 7924c8945a0SNathan Whitehorn int ret = dft; 7934c8945a0SNathan Whitehorn if (arg_rest(av) > n) 7944c8945a0SNathan Whitehorn ret = numeric_arg(av, n); 7954c8945a0SNathan Whitehorn return ret; 7964c8945a0SNathan Whitehorn } 7974c8945a0SNathan Whitehorn #endif 7984c8945a0SNathan Whitehorn 7994c8945a0SNathan Whitehorn /* 8004c8945a0SNathan Whitehorn * On AIX 4.x, we have to flush the output right away since there is a bug in 8014c8945a0SNathan Whitehorn * the curses package which discards stdout even when we've used newterm to 8024c8945a0SNathan Whitehorn * redirect output to /dev/tty. 8034c8945a0SNathan Whitehorn */ 8044c8945a0SNathan Whitehorn static int 8054c8945a0SNathan Whitehorn show_result(int ret) 8064c8945a0SNathan Whitehorn { 8074c8945a0SNathan Whitehorn bool either = FALSE; 8084c8945a0SNathan Whitehorn 8094c8945a0SNathan Whitehorn switch (ret) { 8104c8945a0SNathan Whitehorn case DLG_EXIT_OK: 8114c8945a0SNathan Whitehorn case DLG_EXIT_EXTRA: 8124c8945a0SNathan Whitehorn case DLG_EXIT_HELP: 8134c8945a0SNathan Whitehorn case DLG_EXIT_ITEM_HELP: 8144c8945a0SNathan Whitehorn if ((dialog_state.output_count > 1) && !dialog_vars.separate_output) { 8154c8945a0SNathan Whitehorn fputs((dialog_state.separate_str 8164c8945a0SNathan Whitehorn ? dialog_state.separate_str 8174c8945a0SNathan Whitehorn : DEFAULT_SEPARATE_STR), 8184c8945a0SNathan Whitehorn dialog_state.output); 8194c8945a0SNathan Whitehorn either = TRUE; 8204c8945a0SNathan Whitehorn } 8217a1c0d96SNathan Whitehorn if (dialog_vars.input_result != 0 8227a1c0d96SNathan Whitehorn && dialog_vars.input_result[0] != '\0') { 8234c8945a0SNathan Whitehorn fputs(dialog_vars.input_result, dialog_state.output); 824f4f33ea0SBaptiste Daroussin DLG_TRACE(("# input_result:\n%s\n", dialog_vars.input_result)); 8254c8945a0SNathan Whitehorn either = TRUE; 8264c8945a0SNathan Whitehorn } 8274c8945a0SNathan Whitehorn if (either) { 8284c8945a0SNathan Whitehorn fflush(dialog_state.output); 8294c8945a0SNathan Whitehorn } 8304c8945a0SNathan Whitehorn break; 8314c8945a0SNathan Whitehorn } 8324c8945a0SNathan Whitehorn return ret; 8334c8945a0SNathan Whitehorn } 8344c8945a0SNathan Whitehorn 8354c8945a0SNathan Whitehorn /* 8364c8945a0SNathan Whitehorn * These are the widget callers. 8374c8945a0SNathan Whitehorn */ 8384c8945a0SNathan Whitehorn 8394c8945a0SNathan Whitehorn static int 8404c8945a0SNathan Whitehorn call_yesno(CALLARGS) 8414c8945a0SNathan Whitehorn { 8424c8945a0SNathan Whitehorn *offset_add = 4; 8434c8945a0SNathan Whitehorn return dialog_yesno(t, 8444c8945a0SNathan Whitehorn av[1], 8454c8945a0SNathan Whitehorn numeric_arg(av, 2), 8464c8945a0SNathan Whitehorn numeric_arg(av, 3)); 8474c8945a0SNathan Whitehorn } 8484c8945a0SNathan Whitehorn 8494c8945a0SNathan Whitehorn static int 8504c8945a0SNathan Whitehorn call_msgbox(CALLARGS) 8514c8945a0SNathan Whitehorn { 8524c8945a0SNathan Whitehorn *offset_add = 4; 8534c8945a0SNathan Whitehorn return dialog_msgbox(t, 8544c8945a0SNathan Whitehorn av[1], 8554c8945a0SNathan Whitehorn numeric_arg(av, 2), 8564c8945a0SNathan Whitehorn numeric_arg(av, 3), 1); 8574c8945a0SNathan Whitehorn } 8584c8945a0SNathan Whitehorn 8594c8945a0SNathan Whitehorn static int 8604c8945a0SNathan Whitehorn call_infobox(CALLARGS) 8614c8945a0SNathan Whitehorn { 8624c8945a0SNathan Whitehorn *offset_add = 4; 8634c8945a0SNathan Whitehorn return dialog_msgbox(t, 8644c8945a0SNathan Whitehorn av[1], 8654c8945a0SNathan Whitehorn numeric_arg(av, 2), 8664c8945a0SNathan Whitehorn numeric_arg(av, 3), 0); 8674c8945a0SNathan Whitehorn } 8684c8945a0SNathan Whitehorn 8694c8945a0SNathan Whitehorn static int 8704c8945a0SNathan Whitehorn call_textbox(CALLARGS) 8714c8945a0SNathan Whitehorn { 8724c8945a0SNathan Whitehorn *offset_add = 4; 8734c8945a0SNathan Whitehorn return dialog_textbox(t, 8744c8945a0SNathan Whitehorn av[1], 8754c8945a0SNathan Whitehorn numeric_arg(av, 2), 8764c8945a0SNathan Whitehorn numeric_arg(av, 3)); 8774c8945a0SNathan Whitehorn } 8784c8945a0SNathan Whitehorn 8794c8945a0SNathan Whitehorn static int 8804c8945a0SNathan Whitehorn call_menu(CALLARGS) 8814c8945a0SNathan Whitehorn { 8824c8945a0SNathan Whitehorn int tags = howmany_tags(av + 5, MENUBOX_TAGS); 8834c8945a0SNathan Whitehorn *offset_add = 5 + tags * MENUBOX_TAGS; 8844c8945a0SNathan Whitehorn 8854c8945a0SNathan Whitehorn return dialog_menu(t, 8864c8945a0SNathan Whitehorn av[1], 8874c8945a0SNathan Whitehorn numeric_arg(av, 2), 8884c8945a0SNathan Whitehorn numeric_arg(av, 3), 8894c8945a0SNathan Whitehorn numeric_arg(av, 4), 8904c8945a0SNathan Whitehorn tags, av + 5); 8914c8945a0SNathan Whitehorn } 8924c8945a0SNathan Whitehorn 8934c8945a0SNathan Whitehorn static int 8944c8945a0SNathan Whitehorn call_inputmenu(CALLARGS) 8954c8945a0SNathan Whitehorn { 8964c8945a0SNathan Whitehorn int tags = howmany_tags(av + 5, MENUBOX_TAGS); 8977a1c0d96SNathan Whitehorn bool free_extra_label = FALSE; 8987a1c0d96SNathan Whitehorn int result; 8994c8945a0SNathan Whitehorn 9004c8945a0SNathan Whitehorn dialog_vars.input_menu = TRUE; 9014c8945a0SNathan Whitehorn 9024c8945a0SNathan Whitehorn if (dialog_vars.max_input == 0) 9034c8945a0SNathan Whitehorn dialog_vars.max_input = MAX_LEN / 2; 9044c8945a0SNathan Whitehorn 9057a1c0d96SNathan Whitehorn if (dialog_vars.extra_label == 0) { 9067a1c0d96SNathan Whitehorn free_extra_label = TRUE; 9077a1c0d96SNathan Whitehorn dialog_vars.extra_label = dlg_strclone(_("Rename")); 9087a1c0d96SNathan Whitehorn } 9094c8945a0SNathan Whitehorn 9104c8945a0SNathan Whitehorn dialog_vars.extra_button = TRUE; 9114c8945a0SNathan Whitehorn 9124c8945a0SNathan Whitehorn *offset_add = 5 + tags * MENUBOX_TAGS; 9137a1c0d96SNathan Whitehorn result = dialog_menu(t, 9144c8945a0SNathan Whitehorn av[1], 9154c8945a0SNathan Whitehorn numeric_arg(av, 2), 9164c8945a0SNathan Whitehorn numeric_arg(av, 3), 9174c8945a0SNathan Whitehorn numeric_arg(av, 4), 9184c8945a0SNathan Whitehorn tags, av + 5); 9197a1c0d96SNathan Whitehorn if (free_extra_label) { 9207a1c0d96SNathan Whitehorn free(dialog_vars.extra_label); 9217a1c0d96SNathan Whitehorn dialog_vars.extra_label = 0; 9227a1c0d96SNathan Whitehorn } 9237a1c0d96SNathan Whitehorn return result; 9244c8945a0SNathan Whitehorn } 9254c8945a0SNathan Whitehorn 9264c8945a0SNathan Whitehorn static int 9274c8945a0SNathan Whitehorn call_checklist(CALLARGS) 9284c8945a0SNathan Whitehorn { 9294c8945a0SNathan Whitehorn int tags = howmany_tags(av + 5, CHECKBOX_TAGS); 9304c8945a0SNathan Whitehorn int code; 9314c8945a0SNathan Whitehorn 9324c8945a0SNathan Whitehorn *offset_add = 5 + tags * CHECKBOX_TAGS; 9334c8945a0SNathan Whitehorn code = dialog_checklist(t, 9344c8945a0SNathan Whitehorn av[1], 9354c8945a0SNathan Whitehorn numeric_arg(av, 2), 9364c8945a0SNathan Whitehorn numeric_arg(av, 3), 9374c8945a0SNathan Whitehorn numeric_arg(av, 4), 9384c8945a0SNathan Whitehorn tags, av + 5, FLAG_CHECK); 9394c8945a0SNathan Whitehorn return code; 9404c8945a0SNathan Whitehorn } 9414c8945a0SNathan Whitehorn 9424c8945a0SNathan Whitehorn static int 9434c8945a0SNathan Whitehorn call_radiolist(CALLARGS) 9444c8945a0SNathan Whitehorn { 9454c8945a0SNathan Whitehorn int tags = howmany_tags(av + 5, CHECKBOX_TAGS); 9464c8945a0SNathan Whitehorn *offset_add = 5 + tags * CHECKBOX_TAGS; 9474c8945a0SNathan Whitehorn return dialog_checklist(t, 9484c8945a0SNathan Whitehorn av[1], 9494c8945a0SNathan Whitehorn numeric_arg(av, 2), 9504c8945a0SNathan Whitehorn numeric_arg(av, 3), 9514c8945a0SNathan Whitehorn numeric_arg(av, 4), 9524c8945a0SNathan Whitehorn tags, av + 5, FLAG_RADIO); 9534c8945a0SNathan Whitehorn } 9544c8945a0SNathan Whitehorn 9554c8945a0SNathan Whitehorn static int 9564c8945a0SNathan Whitehorn call_inputbox(CALLARGS) 9574c8945a0SNathan Whitehorn { 9584c8945a0SNathan Whitehorn *offset_add = arg_rest(av); 9594c8945a0SNathan Whitehorn return dialog_inputbox(t, 9604c8945a0SNathan Whitehorn av[1], 9614c8945a0SNathan Whitehorn numeric_arg(av, 2), 9624c8945a0SNathan Whitehorn numeric_arg(av, 3), 9634c8945a0SNathan Whitehorn optional_str(av, 4, 0), 0); 9644c8945a0SNathan Whitehorn } 9654c8945a0SNathan Whitehorn 9664c8945a0SNathan Whitehorn static int 9674c8945a0SNathan Whitehorn call_passwordbox(CALLARGS) 9684c8945a0SNathan Whitehorn { 9694c8945a0SNathan Whitehorn *offset_add = arg_rest(av); 9704c8945a0SNathan Whitehorn return dialog_inputbox(t, 9714c8945a0SNathan Whitehorn av[1], 9724c8945a0SNathan Whitehorn numeric_arg(av, 2), 9734c8945a0SNathan Whitehorn numeric_arg(av, 3), 9744c8945a0SNathan Whitehorn optional_str(av, 4, 0), 1); 9754c8945a0SNathan Whitehorn } 9764c8945a0SNathan Whitehorn 9774c8945a0SNathan Whitehorn #ifdef HAVE_XDIALOG 9784c8945a0SNathan Whitehorn static int 9794c8945a0SNathan Whitehorn call_calendar(CALLARGS) 9804c8945a0SNathan Whitehorn { 9814c8945a0SNathan Whitehorn *offset_add = arg_rest(av); 9824c8945a0SNathan Whitehorn return dialog_calendar(t, 9834c8945a0SNathan Whitehorn av[1], 9844c8945a0SNathan Whitehorn numeric_arg(av, 2), 9854c8945a0SNathan Whitehorn numeric_arg(av, 3), 9864c8945a0SNathan Whitehorn optional_num(av, 4, -1), 9874c8945a0SNathan Whitehorn optional_num(av, 5, -1), 9884c8945a0SNathan Whitehorn optional_num(av, 6, -1)); 9894c8945a0SNathan Whitehorn } 9904c8945a0SNathan Whitehorn 9914c8945a0SNathan Whitehorn static int 9924c8945a0SNathan Whitehorn call_dselect(CALLARGS) 9934c8945a0SNathan Whitehorn { 9944c8945a0SNathan Whitehorn *offset_add = arg_rest(av); 9954c8945a0SNathan Whitehorn return dialog_dselect(t, 9964c8945a0SNathan Whitehorn av[1], 9974c8945a0SNathan Whitehorn numeric_arg(av, 2), 9984c8945a0SNathan Whitehorn numeric_arg(av, 3)); 9994c8945a0SNathan Whitehorn } 10004c8945a0SNathan Whitehorn 10014c8945a0SNathan Whitehorn static int 10024c8945a0SNathan Whitehorn call_editbox(CALLARGS) 10034c8945a0SNathan Whitehorn { 10044c8945a0SNathan Whitehorn *offset_add = 4; 10054c8945a0SNathan Whitehorn return dialog_editbox(t, 10064c8945a0SNathan Whitehorn av[1], 10074c8945a0SNathan Whitehorn numeric_arg(av, 2), 10084c8945a0SNathan Whitehorn numeric_arg(av, 3)); 10094c8945a0SNathan Whitehorn } 10104c8945a0SNathan Whitehorn 10114c8945a0SNathan Whitehorn static int 10124c8945a0SNathan Whitehorn call_fselect(CALLARGS) 10134c8945a0SNathan Whitehorn { 10144c8945a0SNathan Whitehorn *offset_add = arg_rest(av); 10154c8945a0SNathan Whitehorn return dialog_fselect(t, 10164c8945a0SNathan Whitehorn av[1], 10174c8945a0SNathan Whitehorn numeric_arg(av, 2), 10184c8945a0SNathan Whitehorn numeric_arg(av, 3)); 10194c8945a0SNathan Whitehorn } 10204c8945a0SNathan Whitehorn 10214c8945a0SNathan Whitehorn static int 10224c8945a0SNathan Whitehorn call_timebox(CALLARGS) 10234c8945a0SNathan Whitehorn { 10244c8945a0SNathan Whitehorn *offset_add = arg_rest(av); 10254c8945a0SNathan Whitehorn return dialog_timebox(t, 10264c8945a0SNathan Whitehorn av[1], 10274c8945a0SNathan Whitehorn numeric_arg(av, 2), 10284c8945a0SNathan Whitehorn numeric_arg(av, 3), 10294c8945a0SNathan Whitehorn optional_num(av, 4, -1), 10304c8945a0SNathan Whitehorn optional_num(av, 5, -1), 10314c8945a0SNathan Whitehorn optional_num(av, 6, -1)); 10324c8945a0SNathan Whitehorn } 10334c8945a0SNathan Whitehorn #endif /* HAVE_XDIALOG */ 10344c8945a0SNathan Whitehorn 10352a3e3873SBaptiste Daroussin /* dialog 1.2 widgets */ 10362a3e3873SBaptiste Daroussin #ifdef HAVE_XDIALOG2 10372a3e3873SBaptiste Daroussin 10382a3e3873SBaptiste Daroussin #define DisableNoTags() \ 10392a3e3873SBaptiste Daroussin bool save_no_tags = dialog_vars.no_tags; \ 10402a3e3873SBaptiste Daroussin bool save_no_items = dialog_vars.no_items; \ 10412a3e3873SBaptiste Daroussin dialog_vars.no_tags = TRUE; \ 10422a3e3873SBaptiste Daroussin dialog_vars.no_items = FALSE 10432a3e3873SBaptiste Daroussin 10442a3e3873SBaptiste Daroussin #define RestoreNoTags() \ 10452a3e3873SBaptiste Daroussin dialog_vars.no_tags = save_no_tags; \ 10462a3e3873SBaptiste Daroussin dialog_vars.no_items = save_no_items 10472a3e3873SBaptiste Daroussin 10482a3e3873SBaptiste Daroussin static int 10492a3e3873SBaptiste Daroussin call_buildlist(CALLARGS) 10502a3e3873SBaptiste Daroussin { 10512a3e3873SBaptiste Daroussin int tags = howmany_tags(av + 5, CHECKBOX_TAGS); 10522a3e3873SBaptiste Daroussin int result; 10532a3e3873SBaptiste Daroussin 10542a3e3873SBaptiste Daroussin DisableNoTags(); 10552a3e3873SBaptiste Daroussin 10562a3e3873SBaptiste Daroussin *offset_add = 5 + tags * CHECKBOX_TAGS; 10572a3e3873SBaptiste Daroussin result = dialog_buildlist(t, 10582a3e3873SBaptiste Daroussin av[1], 10592a3e3873SBaptiste Daroussin numeric_arg(av, 2), 10602a3e3873SBaptiste Daroussin numeric_arg(av, 3), 10612a3e3873SBaptiste Daroussin numeric_arg(av, 4), 10622a3e3873SBaptiste Daroussin tags, av + 5, 1063f4f33ea0SBaptiste Daroussin dialog_vars.reorder); 10642a3e3873SBaptiste Daroussin RestoreNoTags(); 10652a3e3873SBaptiste Daroussin return result; 10662a3e3873SBaptiste Daroussin } 10672a3e3873SBaptiste Daroussin 10682a3e3873SBaptiste Daroussin static int 10692a3e3873SBaptiste Daroussin call_rangebox(CALLARGS) 10702a3e3873SBaptiste Daroussin { 10712a3e3873SBaptiste Daroussin int min_value; 10722a3e3873SBaptiste Daroussin 10732a3e3873SBaptiste Daroussin *offset_add = arg_rest(av); 10742a3e3873SBaptiste Daroussin min_value = numeric_arg(av, 4); 10752a3e3873SBaptiste Daroussin return dialog_rangebox(t, 10762a3e3873SBaptiste Daroussin av[1], 10772a3e3873SBaptiste Daroussin numeric_arg(av, 2), 10782a3e3873SBaptiste Daroussin numeric_arg(av, 3), 10792a3e3873SBaptiste Daroussin min_value, 10802a3e3873SBaptiste Daroussin numeric_arg(av, 5), 10812a3e3873SBaptiste Daroussin (*offset_add > 6) ? numeric_arg(av, 6) : min_value); 10822a3e3873SBaptiste Daroussin } 10832a3e3873SBaptiste Daroussin 10842a3e3873SBaptiste Daroussin static int 10852a3e3873SBaptiste Daroussin call_treeview(CALLARGS) 10862a3e3873SBaptiste Daroussin { 10872a3e3873SBaptiste Daroussin int tags = howmany_tags(av + 5, TREEVIEW_TAGS); 10882a3e3873SBaptiste Daroussin int result; 10892a3e3873SBaptiste Daroussin 10902a3e3873SBaptiste Daroussin DisableNoTags(); 10912a3e3873SBaptiste Daroussin 10922a3e3873SBaptiste Daroussin *offset_add = arg_rest(av); 10932a3e3873SBaptiste Daroussin result = dialog_treeview(t, 10942a3e3873SBaptiste Daroussin av[1], 10952a3e3873SBaptiste Daroussin numeric_arg(av, 2), 10962a3e3873SBaptiste Daroussin numeric_arg(av, 3), 10972a3e3873SBaptiste Daroussin numeric_arg(av, 4), 10982a3e3873SBaptiste Daroussin tags, av + 5, FLAG_RADIO); 10992a3e3873SBaptiste Daroussin RestoreNoTags(); 11002a3e3873SBaptiste Daroussin return result; 11012a3e3873SBaptiste Daroussin } 11022a3e3873SBaptiste Daroussin #endif /* HAVE_XDIALOG */ 11032a3e3873SBaptiste Daroussin 11044c8945a0SNathan Whitehorn #ifdef HAVE_DLG_FORMBOX 11054c8945a0SNathan Whitehorn static int 11064c8945a0SNathan Whitehorn call_form(CALLARGS) 11074c8945a0SNathan Whitehorn { 11084c8945a0SNathan Whitehorn int group = FORMBOX_TAGS; 11094c8945a0SNathan Whitehorn int tags = howmany_tags(av + 5, group); 11104c8945a0SNathan Whitehorn *offset_add = 5 + tags * group; 11114c8945a0SNathan Whitehorn 11124c8945a0SNathan Whitehorn return dialog_form(t, 11134c8945a0SNathan Whitehorn av[1], 11144c8945a0SNathan Whitehorn numeric_arg(av, 2), 11154c8945a0SNathan Whitehorn numeric_arg(av, 3), 11164c8945a0SNathan Whitehorn numeric_arg(av, 4), 11174c8945a0SNathan Whitehorn tags, av + 5); 11184c8945a0SNathan Whitehorn } 11194c8945a0SNathan Whitehorn 11204c8945a0SNathan Whitehorn static int 11214c8945a0SNathan Whitehorn call_password_form(CALLARGS) 11224c8945a0SNathan Whitehorn { 11234c8945a0SNathan Whitehorn unsigned save = dialog_vars.formitem_type; 11244c8945a0SNathan Whitehorn int result; 11254c8945a0SNathan Whitehorn 11264c8945a0SNathan Whitehorn dialog_vars.formitem_type = 1; 11274c8945a0SNathan Whitehorn result = call_form(PASSARGS); 11284c8945a0SNathan Whitehorn dialog_vars.formitem_type = save; 11294c8945a0SNathan Whitehorn 11304c8945a0SNathan Whitehorn return result; 11314c8945a0SNathan Whitehorn } 11324c8945a0SNathan Whitehorn #endif /* HAVE_DLG_FORMBOX */ 11334c8945a0SNathan Whitehorn 11344c8945a0SNathan Whitehorn #ifdef HAVE_DLG_MIXEDFORM 11354c8945a0SNathan Whitehorn static int 11364c8945a0SNathan Whitehorn call_mixed_form(CALLARGS) 11374c8945a0SNathan Whitehorn { 11384c8945a0SNathan Whitehorn int group = MIXEDFORM_TAGS; 11394c8945a0SNathan Whitehorn int tags = howmany_tags(av + 5, group); 11404c8945a0SNathan Whitehorn *offset_add = 5 + tags * group; 11414c8945a0SNathan Whitehorn 11424c8945a0SNathan Whitehorn return dialog_mixedform(t, 11434c8945a0SNathan Whitehorn av[1], 11444c8945a0SNathan Whitehorn numeric_arg(av, 2), 11454c8945a0SNathan Whitehorn numeric_arg(av, 3), 11464c8945a0SNathan Whitehorn numeric_arg(av, 4), 11474c8945a0SNathan Whitehorn tags, av + 5); 11484c8945a0SNathan Whitehorn } 11494c8945a0SNathan Whitehorn #endif /* HAVE_DLG_MIXEDFORM */ 11504c8945a0SNathan Whitehorn 11514c8945a0SNathan Whitehorn #ifdef HAVE_DLG_GAUGE 11524c8945a0SNathan Whitehorn static int 11534c8945a0SNathan Whitehorn call_gauge(CALLARGS) 11544c8945a0SNathan Whitehorn { 11554c8945a0SNathan Whitehorn *offset_add = arg_rest(av); 11564c8945a0SNathan Whitehorn return dialog_gauge(t, 11574c8945a0SNathan Whitehorn av[1], 11584c8945a0SNathan Whitehorn numeric_arg(av, 2), 11594c8945a0SNathan Whitehorn numeric_arg(av, 3), 11604c8945a0SNathan Whitehorn optional_num(av, 4, 0)); 11614c8945a0SNathan Whitehorn } 11624c8945a0SNathan Whitehorn 11634c8945a0SNathan Whitehorn static int 11644c8945a0SNathan Whitehorn call_pause(CALLARGS) 11654c8945a0SNathan Whitehorn { 11664c8945a0SNathan Whitehorn *offset_add = arg_rest(av); 11674c8945a0SNathan Whitehorn return dialog_pause(t, 11684c8945a0SNathan Whitehorn av[1], 11694c8945a0SNathan Whitehorn numeric_arg(av, 2), 11704c8945a0SNathan Whitehorn numeric_arg(av, 3), 11714c8945a0SNathan Whitehorn numeric_arg(av, 4)); 11724c8945a0SNathan Whitehorn } 11734c8945a0SNathan Whitehorn #endif 11744c8945a0SNathan Whitehorn 11754c8945a0SNathan Whitehorn #ifdef HAVE_MIXEDGAUGE 11764c8945a0SNathan Whitehorn static int 11774c8945a0SNathan Whitehorn call_mixed_gauge(CALLARGS) 11784c8945a0SNathan Whitehorn { 11794c8945a0SNathan Whitehorn #define MIXEDGAUGE_BASE 5 11804c8945a0SNathan Whitehorn int tags = howmany_tags(av + MIXEDGAUGE_BASE, MIXEDGAUGE_TAGS); 11814c8945a0SNathan Whitehorn *offset_add = MIXEDGAUGE_BASE + tags * MIXEDGAUGE_TAGS; 11824c8945a0SNathan Whitehorn return dialog_mixedgauge(t, 11834c8945a0SNathan Whitehorn av[1], 11844c8945a0SNathan Whitehorn numeric_arg(av, 2), 11854c8945a0SNathan Whitehorn numeric_arg(av, 3), 11864c8945a0SNathan Whitehorn numeric_arg(av, 4), 11874c8945a0SNathan Whitehorn tags, av + MIXEDGAUGE_BASE); 11884c8945a0SNathan Whitehorn } 11894c8945a0SNathan Whitehorn #endif 11904c8945a0SNathan Whitehorn 1191682c9e0fSNathan Whitehorn #ifdef HAVE_DLG_GAUGE 11927a1c0d96SNathan Whitehorn static int 11937a1c0d96SNathan Whitehorn call_prgbox(CALLARGS) 11947a1c0d96SNathan Whitehorn { 11957a1c0d96SNathan Whitehorn *offset_add = arg_rest(av); 11967a1c0d96SNathan Whitehorn /* the original version does not accept a prompt string, but for 11977a1c0d96SNathan Whitehorn * consistency we allow it. 11987a1c0d96SNathan Whitehorn */ 11997a1c0d96SNathan Whitehorn return ((*offset_add == 5) 12007a1c0d96SNathan Whitehorn ? dialog_prgbox(t, 12017a1c0d96SNathan Whitehorn av[1], 12027a1c0d96SNathan Whitehorn av[2], 12037a1c0d96SNathan Whitehorn numeric_arg(av, 3), 12047a1c0d96SNathan Whitehorn numeric_arg(av, 4), TRUE) 12057a1c0d96SNathan Whitehorn : dialog_prgbox(t, 12067a1c0d96SNathan Whitehorn "", 12077a1c0d96SNathan Whitehorn av[1], 12087a1c0d96SNathan Whitehorn numeric_arg(av, 2), 12097a1c0d96SNathan Whitehorn numeric_arg(av, 3), TRUE)); 12107a1c0d96SNathan Whitehorn } 1211682c9e0fSNathan Whitehorn #endif 12127a1c0d96SNathan Whitehorn 12137a1c0d96SNathan Whitehorn #ifdef HAVE_DLG_GAUGE 12147a1c0d96SNathan Whitehorn static int 12157a1c0d96SNathan Whitehorn call_programbox(CALLARGS) 12167a1c0d96SNathan Whitehorn { 12177a1c0d96SNathan Whitehorn int result; 12187a1c0d96SNathan Whitehorn 12197a1c0d96SNathan Whitehorn *offset_add = arg_rest(av); 12207a1c0d96SNathan Whitehorn /* this function is a compromise between --prgbox and --progressbox. 12217a1c0d96SNathan Whitehorn */ 12227a1c0d96SNathan Whitehorn result = ((*offset_add == 4) 12237a1c0d96SNathan Whitehorn ? dlg_progressbox(t, 12247a1c0d96SNathan Whitehorn av[1], 12257a1c0d96SNathan Whitehorn numeric_arg(av, 2), 12267a1c0d96SNathan Whitehorn numeric_arg(av, 3), 12277a1c0d96SNathan Whitehorn TRUE, 12287a1c0d96SNathan Whitehorn dialog_state.pipe_input) 12297a1c0d96SNathan Whitehorn : dlg_progressbox(t, 12307a1c0d96SNathan Whitehorn "", 12317a1c0d96SNathan Whitehorn numeric_arg(av, 1), 12327a1c0d96SNathan Whitehorn numeric_arg(av, 2), 12337a1c0d96SNathan Whitehorn TRUE, 12347a1c0d96SNathan Whitehorn dialog_state.pipe_input)); 12357a1c0d96SNathan Whitehorn dialog_state.pipe_input = 0; 12367a1c0d96SNathan Whitehorn return result; 12377a1c0d96SNathan Whitehorn } 12387a1c0d96SNathan Whitehorn #endif 12397a1c0d96SNathan Whitehorn 12404c8945a0SNathan Whitehorn #ifdef HAVE_DLG_GAUGE 12414c8945a0SNathan Whitehorn static int 12424c8945a0SNathan Whitehorn call_progressbox(CALLARGS) 12434c8945a0SNathan Whitehorn { 12444c8945a0SNathan Whitehorn *offset_add = arg_rest(av); 12454c8945a0SNathan Whitehorn /* the original version does not accept a prompt string, but for 12464c8945a0SNathan Whitehorn * consistency we allow it. 12474c8945a0SNathan Whitehorn */ 12484c8945a0SNathan Whitehorn return ((*offset_add == 4) 12494c8945a0SNathan Whitehorn ? dialog_progressbox(t, 12504c8945a0SNathan Whitehorn av[1], 12514c8945a0SNathan Whitehorn numeric_arg(av, 2), 12524c8945a0SNathan Whitehorn numeric_arg(av, 3)) 12534c8945a0SNathan Whitehorn : dialog_progressbox(t, 12544c8945a0SNathan Whitehorn "", 12554c8945a0SNathan Whitehorn numeric_arg(av, 1), 12564c8945a0SNathan Whitehorn numeric_arg(av, 2))); 12574c8945a0SNathan Whitehorn } 12584c8945a0SNathan Whitehorn #endif 12594c8945a0SNathan Whitehorn 12604c8945a0SNathan Whitehorn #ifdef HAVE_DLG_TAILBOX 12614c8945a0SNathan Whitehorn static int 12624c8945a0SNathan Whitehorn call_tailbox(CALLARGS) 12634c8945a0SNathan Whitehorn { 12644c8945a0SNathan Whitehorn *offset_add = 4; 12654c8945a0SNathan Whitehorn return dialog_tailbox(t, 12664c8945a0SNathan Whitehorn av[1], 12674c8945a0SNathan Whitehorn numeric_arg(av, 2), 12684c8945a0SNathan Whitehorn numeric_arg(av, 3), 12694c8945a0SNathan Whitehorn FALSE); 12704c8945a0SNathan Whitehorn } 12714c8945a0SNathan Whitehorn 12724c8945a0SNathan Whitehorn static int 12734c8945a0SNathan Whitehorn call_tailboxbg(CALLARGS) 12744c8945a0SNathan Whitehorn { 12754c8945a0SNathan Whitehorn *offset_add = 4; 12764c8945a0SNathan Whitehorn return dialog_tailbox(t, 12774c8945a0SNathan Whitehorn av[1], 12784c8945a0SNathan Whitehorn numeric_arg(av, 2), 12794c8945a0SNathan Whitehorn numeric_arg(av, 3), 12804c8945a0SNathan Whitehorn TRUE); 12814c8945a0SNathan Whitehorn } 12824c8945a0SNathan Whitehorn #endif 12834c8945a0SNathan Whitehorn /* *INDENT-OFF* */ 12844c8945a0SNathan Whitehorn static const Mode modes[] = 12854c8945a0SNathan Whitehorn { 12864c8945a0SNathan Whitehorn {o_yesno, 4, 4, call_yesno}, 12874c8945a0SNathan Whitehorn {o_msgbox, 4, 4, call_msgbox}, 12884c8945a0SNathan Whitehorn {o_infobox, 4, 4, call_infobox}, 12894c8945a0SNathan Whitehorn {o_textbox, 4, 4, call_textbox}, 1290f4f33ea0SBaptiste Daroussin {o_menu, 6, 0, call_menu}, 1291f4f33ea0SBaptiste Daroussin {o_inputmenu, 6, 0, call_inputmenu}, 1292f4f33ea0SBaptiste Daroussin {o_checklist, 7, 0, call_checklist}, 1293f4f33ea0SBaptiste Daroussin {o_radiolist, 7, 0, call_radiolist}, 12944c8945a0SNathan Whitehorn {o_inputbox, 4, 5, call_inputbox}, 12954c8945a0SNathan Whitehorn {o_passwordbox, 4, 5, call_passwordbox}, 12964c8945a0SNathan Whitehorn #ifdef HAVE_DLG_GAUGE 12974c8945a0SNathan Whitehorn {o_gauge, 4, 5, call_gauge}, 12984c8945a0SNathan Whitehorn {o_pause, 5, 5, call_pause}, 12997a1c0d96SNathan Whitehorn {o_prgbox, 4, 5, call_prgbox}, 13007a1c0d96SNathan Whitehorn {o_programbox, 3, 4, call_programbox}, 13014c8945a0SNathan Whitehorn {o_progressbox, 3, 4, call_progressbox}, 13024c8945a0SNathan Whitehorn #endif 13034c8945a0SNathan Whitehorn #ifdef HAVE_DLG_FORMBOX 13044c8945a0SNathan Whitehorn {o_passwordform, 13, 0, call_password_form}, 13054c8945a0SNathan Whitehorn {o_form, 13, 0, call_form}, 13064c8945a0SNathan Whitehorn #endif 13074c8945a0SNathan Whitehorn #ifdef HAVE_MIXEDGAUGE 13084c8945a0SNathan Whitehorn {o_mixedgauge, MIXEDGAUGE_BASE, 0, call_mixed_gauge}, 13094c8945a0SNathan Whitehorn #endif 13104c8945a0SNathan Whitehorn #ifdef HAVE_DLG_MIXEDFORM 13114c8945a0SNathan Whitehorn {o_mixedform, 13, 0, call_mixed_form}, 13124c8945a0SNathan Whitehorn #endif 13134c8945a0SNathan Whitehorn #ifdef HAVE_DLG_TAILBOX 13144c8945a0SNathan Whitehorn {o_tailbox, 4, 4, call_tailbox}, 13154c8945a0SNathan Whitehorn {o_tailboxbg, 4, 4, call_tailboxbg}, 13164c8945a0SNathan Whitehorn #endif 13174c8945a0SNathan Whitehorn #ifdef HAVE_XDIALOG 13184c8945a0SNathan Whitehorn {o_calendar, 4, 7, call_calendar}, 13194c8945a0SNathan Whitehorn {o_dselect, 4, 5, call_dselect}, 13204c8945a0SNathan Whitehorn {o_editbox, 4, 4, call_editbox}, 13214c8945a0SNathan Whitehorn {o_fselect, 4, 5, call_fselect}, 13224c8945a0SNathan Whitehorn {o_timebox, 4, 7, call_timebox}, 1323f4f33ea0SBaptiste Daroussin #endif 1324f4f33ea0SBaptiste Daroussin #ifdef HAVE_XDIALOG2 1325f4f33ea0SBaptiste Daroussin {o_buildlist, 4, 0, call_buildlist}, 1326f4f33ea0SBaptiste Daroussin {o_rangebox, 5, 7, call_rangebox}, 13272a3e3873SBaptiste Daroussin {o_treeview, 4, 0, call_treeview}, 13284c8945a0SNathan Whitehorn #endif 13294c8945a0SNathan Whitehorn }; 13304c8945a0SNathan Whitehorn /* *INDENT-ON* */ 13314c8945a0SNathan Whitehorn 13324c8945a0SNathan Whitehorn static char * 13334c8945a0SNathan Whitehorn optionString(char **argv, int *num) 13344c8945a0SNathan Whitehorn { 13354c8945a0SNathan Whitehorn int next = *num + 1; 13364c8945a0SNathan Whitehorn char *result = argv[next]; 13374c8945a0SNathan Whitehorn if (result == 0) { 13384c8945a0SNathan Whitehorn char temp[80]; 13394c8945a0SNathan Whitehorn sprintf(temp, "Expected a string-parameter for %.20s", argv[*num]); 13404c8945a0SNathan Whitehorn Usage(temp); 13414c8945a0SNathan Whitehorn } 13424c8945a0SNathan Whitehorn *num = next; 13434c8945a0SNathan Whitehorn return result; 13444c8945a0SNathan Whitehorn } 13454c8945a0SNathan Whitehorn 13464c8945a0SNathan Whitehorn static int 13474c8945a0SNathan Whitehorn optionValue(char **argv, int *num) 13484c8945a0SNathan Whitehorn { 13494c8945a0SNathan Whitehorn int next = *num + 1; 13504c8945a0SNathan Whitehorn char *src = argv[next]; 13514c8945a0SNathan Whitehorn char *tmp = 0; 13524c8945a0SNathan Whitehorn int result = 0; 13534c8945a0SNathan Whitehorn 13544c8945a0SNathan Whitehorn if (src != 0) { 13557a1c0d96SNathan Whitehorn result = (int) strtol(src, &tmp, 0); 13564c8945a0SNathan Whitehorn if (tmp == 0 || *tmp != 0) 13574c8945a0SNathan Whitehorn src = 0; 13584c8945a0SNathan Whitehorn } 13594c8945a0SNathan Whitehorn 13604c8945a0SNathan Whitehorn if (src == 0) { 13614c8945a0SNathan Whitehorn char temp[80]; 13624c8945a0SNathan Whitehorn sprintf(temp, "Expected a numeric-parameter for %.20s", argv[*num]); 13634c8945a0SNathan Whitehorn Usage(temp); 13644c8945a0SNathan Whitehorn } 13654c8945a0SNathan Whitehorn *num = next; 13664c8945a0SNathan Whitehorn return result; 13674c8945a0SNathan Whitehorn } 13684c8945a0SNathan Whitehorn 1369a96ef450SBaptiste Daroussin /* 1370a96ef450SBaptiste Daroussin * In findOption, we made provision for adding/removing a "no" prefix from 1371a96ef450SBaptiste Daroussin * any boolean option. This function determines the actual true/false result. 1372a96ef450SBaptiste Daroussin */ 1373a96ef450SBaptiste Daroussin static bool 1374a96ef450SBaptiste Daroussin optionBool(const char *actual, const Options * data) 1375a96ef450SBaptiste Daroussin { 1376a96ef450SBaptiste Daroussin bool normal = (data->type == tTrue) ? TRUE : FALSE; 1377a96ef450SBaptiste Daroussin bool result = !strcmp(actual + 2, data->name) ? normal : !normal; 1378a96ef450SBaptiste Daroussin if (result != normal) { 1379a96ef450SBaptiste Daroussin int want_no = (strncmp(actual + 2, "no", 2) == 0); 1380a96ef450SBaptiste Daroussin int have_no = (strncmp(data->name, "no", 2) == 0); 1381a96ef450SBaptiste Daroussin if (have_no == want_no) 1382a96ef450SBaptiste Daroussin result = normal; 1383a96ef450SBaptiste Daroussin } 1384a96ef450SBaptiste Daroussin return result; 1385a96ef450SBaptiste Daroussin } 1386a96ef450SBaptiste Daroussin 13872a3e3873SBaptiste Daroussin /* Return exit-code for a named button */ 13882a3e3873SBaptiste Daroussin static int 13892a3e3873SBaptiste Daroussin button_code(const char *name) 13902a3e3873SBaptiste Daroussin { 13912a3e3873SBaptiste Daroussin /* *INDENT-OFF* */ 13922a3e3873SBaptiste Daroussin static struct { 13932a3e3873SBaptiste Daroussin const char *name; 13942a3e3873SBaptiste Daroussin int code; 13952a3e3873SBaptiste Daroussin } table[] = { 13962a3e3873SBaptiste Daroussin { "ok", DLG_EXIT_OK }, 13972a3e3873SBaptiste Daroussin { "yes", DLG_EXIT_OK }, 13982a3e3873SBaptiste Daroussin { "cancel", DLG_EXIT_CANCEL }, 13992a3e3873SBaptiste Daroussin { "no", DLG_EXIT_CANCEL }, 14002a3e3873SBaptiste Daroussin { "help", DLG_EXIT_HELP }, 14012a3e3873SBaptiste Daroussin { "extra", DLG_EXIT_EXTRA }, 14022a3e3873SBaptiste Daroussin }; 14032a3e3873SBaptiste Daroussin /* *INDENT-ON* */ 14042a3e3873SBaptiste Daroussin 14052a3e3873SBaptiste Daroussin int code = DLG_EXIT_ERROR; 14062a3e3873SBaptiste Daroussin size_t i; 14072a3e3873SBaptiste Daroussin 1408a96ef450SBaptiste Daroussin for (i = 0; i < TableSize(table); i++) { 14092a3e3873SBaptiste Daroussin if (!dlg_strcmp(name, table[i].name)) { 14102a3e3873SBaptiste Daroussin code = table[i].code; 14112a3e3873SBaptiste Daroussin break; 14122a3e3873SBaptiste Daroussin } 14132a3e3873SBaptiste Daroussin } 14142a3e3873SBaptiste Daroussin 14152a3e3873SBaptiste Daroussin if (code == DLG_EXIT_ERROR) { 14162a3e3873SBaptiste Daroussin char temp[80]; 14172a3e3873SBaptiste Daroussin sprintf(temp, "Button name \"%.20s\" unknown", name); 14182a3e3873SBaptiste Daroussin Usage(temp); 14192a3e3873SBaptiste Daroussin } 14202a3e3873SBaptiste Daroussin 14212a3e3873SBaptiste Daroussin return code; 14222a3e3873SBaptiste Daroussin } 14232a3e3873SBaptiste Daroussin 14244c8945a0SNathan Whitehorn /* 1425f4f33ea0SBaptiste Daroussin * If this is the last option, we do not want any error messages - just our 1426f4f33ea0SBaptiste Daroussin * output. Calling end_dialog() cancels the refresh() at the end of the 1427f4f33ea0SBaptiste Daroussin * program as well. 1428f4f33ea0SBaptiste Daroussin */ 1429f4f33ea0SBaptiste Daroussin static void 1430f4f33ea0SBaptiste Daroussin IgnoreNonScreen(char **argv, int offset) 1431f4f33ea0SBaptiste Daroussin { 1432f4f33ea0SBaptiste Daroussin if (argv[offset + 1] == 0) { 1433f4f33ea0SBaptiste Daroussin ignore_unknown = TRUE; 1434f4f33ea0SBaptiste Daroussin end_dialog(); 1435f4f33ea0SBaptiste Daroussin } 1436f4f33ea0SBaptiste Daroussin } 1437f4f33ea0SBaptiste Daroussin 1438f4f33ea0SBaptiste Daroussin static void 1439f4f33ea0SBaptiste Daroussin PrintTextOnly(char **argv, int *offset, eOptions code) 1440f4f33ea0SBaptiste Daroussin { 1441f4f33ea0SBaptiste Daroussin /* TODO - handle two optional numeric params */ 1442f4f33ea0SBaptiste Daroussin char *text; 1443f4f33ea0SBaptiste Daroussin int height = 0; 1444f4f33ea0SBaptiste Daroussin int width = 0; 1445f4f33ea0SBaptiste Daroussin int height2 = 0; 1446f4f33ea0SBaptiste Daroussin int width2 = 0; 1447f4f33ea0SBaptiste Daroussin int next = arg_rest(argv + *offset); 1448f4f33ea0SBaptiste Daroussin 1449a96ef450SBaptiste Daroussin if (LINES <= 0 && COLS <= 0) { 1450a96ef450SBaptiste Daroussin dlg_ttysize(fileno(dialog_state.input), 1451a96ef450SBaptiste Daroussin &dialog_state.screen_height, 1452a96ef450SBaptiste Daroussin &dialog_state.screen_width); 1453a96ef450SBaptiste Daroussin } 1454f4f33ea0SBaptiste Daroussin 1455f4f33ea0SBaptiste Daroussin text = strdup(optionString(argv, offset)); 1456f4f33ea0SBaptiste Daroussin IgnoreNonScreen(argv, *offset); 1457f4f33ea0SBaptiste Daroussin 1458f4f33ea0SBaptiste Daroussin if (next >= 1) { 1459f4f33ea0SBaptiste Daroussin next = MIN(next, 3); 1460f4f33ea0SBaptiste Daroussin height = numeric_arg(argv, *offset + 1); 1461f4f33ea0SBaptiste Daroussin if (next >= 2) 1462f4f33ea0SBaptiste Daroussin width = numeric_arg(argv, *offset + 2); 1463f4f33ea0SBaptiste Daroussin *offset += next - 1; 1464f4f33ea0SBaptiste Daroussin } 1465f4f33ea0SBaptiste Daroussin 1466f4f33ea0SBaptiste Daroussin dlg_trim_string(text); 1467f4f33ea0SBaptiste Daroussin dlg_auto_size(NULL, text, &height2, &width2, height, width); 1468f4f33ea0SBaptiste Daroussin 1469f4f33ea0SBaptiste Daroussin switch (code) { 1470a96ef450SBaptiste Daroussin case o_text_only: 1471f4f33ea0SBaptiste Daroussin dialog_state.text_only = TRUE; 1472f4f33ea0SBaptiste Daroussin dlg_print_autowrap(stdscr, text, height2, width2); 1473f4f33ea0SBaptiste Daroussin dialog_state.text_only = FALSE; 1474f4f33ea0SBaptiste Daroussin break; 1475f4f33ea0SBaptiste Daroussin case o_print_text_size: 1476f4f33ea0SBaptiste Daroussin fprintf(dialog_state.output, "%d %d\n", 1477f4f33ea0SBaptiste Daroussin dialog_state.text_height, 1478f4f33ea0SBaptiste Daroussin dialog_state.text_width); 1479f4f33ea0SBaptiste Daroussin break; 1480f4f33ea0SBaptiste Daroussin default: 1481f4f33ea0SBaptiste Daroussin break; 1482f4f33ea0SBaptiste Daroussin } 1483f4f33ea0SBaptiste Daroussin } 1484f4f33ea0SBaptiste Daroussin 1485f4f33ea0SBaptiste Daroussin /* 14864c8945a0SNathan Whitehorn * Print parts of a message 14874c8945a0SNathan Whitehorn */ 14884c8945a0SNathan Whitehorn static void 14894c8945a0SNathan Whitehorn PrintList(const char *const *list) 14904c8945a0SNathan Whitehorn { 14914c8945a0SNathan Whitehorn const char *leaf = strrchr(program, '/'); 14924c8945a0SNathan Whitehorn unsigned n = 0; 14934c8945a0SNathan Whitehorn 14944c8945a0SNathan Whitehorn if (leaf != 0) 14954c8945a0SNathan Whitehorn leaf++; 14964c8945a0SNathan Whitehorn else 14974c8945a0SNathan Whitehorn leaf = program; 14984c8945a0SNathan Whitehorn 14994c8945a0SNathan Whitehorn while (*list != 0) { 15004c8945a0SNathan Whitehorn fprintf(dialog_state.output, *list, n ? leaf : dialog_version()); 15014c8945a0SNathan Whitehorn (void) fputc('\n', dialog_state.output); 15024c8945a0SNathan Whitehorn n = 1; 15034c8945a0SNathan Whitehorn list++; 15044c8945a0SNathan Whitehorn } 15054c8945a0SNathan Whitehorn } 15064c8945a0SNathan Whitehorn 15074c8945a0SNathan Whitehorn static const Mode * 15084c8945a0SNathan Whitehorn lookupMode(eOptions code) 15094c8945a0SNathan Whitehorn { 15104c8945a0SNathan Whitehorn const Mode *modePtr = 0; 15114c8945a0SNathan Whitehorn unsigned n; 15124c8945a0SNathan Whitehorn 1513a96ef450SBaptiste Daroussin for (n = 0; n < TableSize(modes); n++) { 15144c8945a0SNathan Whitehorn if (modes[n].code == code) { 15154c8945a0SNathan Whitehorn modePtr = &modes[n]; 15164c8945a0SNathan Whitehorn break; 15174c8945a0SNathan Whitehorn } 15184c8945a0SNathan Whitehorn } 15194c8945a0SNathan Whitehorn return modePtr; 15204c8945a0SNathan Whitehorn } 15214c8945a0SNathan Whitehorn 15224c8945a0SNathan Whitehorn static int 15234c8945a0SNathan Whitehorn compare_opts(const void *a, const void *b) 15244c8945a0SNathan Whitehorn { 15254c8945a0SNathan Whitehorn Options *const *p = (Options * const *) a; 15264c8945a0SNathan Whitehorn Options *const *q = (Options * const *) b; 15274c8945a0SNathan Whitehorn return strcmp((*p)->name, (*q)->name); 15284c8945a0SNathan Whitehorn } 15294c8945a0SNathan Whitehorn 15304c8945a0SNathan Whitehorn /* 1531682c9e0fSNathan Whitehorn * Print program's version. 1532682c9e0fSNathan Whitehorn */ 1533682c9e0fSNathan Whitehorn static void 1534682c9e0fSNathan Whitehorn PrintVersion(FILE *fp) 1535682c9e0fSNathan Whitehorn { 1536682c9e0fSNathan Whitehorn fprintf(fp, "Version: %s\n", dialog_version()); 1537682c9e0fSNathan Whitehorn } 1538682c9e0fSNathan Whitehorn 1539682c9e0fSNathan Whitehorn /* 15404c8945a0SNathan Whitehorn * Print program help-message 15414c8945a0SNathan Whitehorn */ 15424c8945a0SNathan Whitehorn static void 15434c8945a0SNathan Whitehorn Help(void) 15444c8945a0SNathan Whitehorn { 15454c8945a0SNathan Whitehorn static const char *const tbl_1[] = 15464c8945a0SNathan Whitehorn { 15474c8945a0SNathan Whitehorn "cdialog (ComeOn Dialog!) version %s", 1548a96ef450SBaptiste Daroussin "Copyright 2000-2020,2021 Thomas E. Dickey", 15494c8945a0SNathan Whitehorn "This is free software; see the source for copying conditions. There is NO", 15504c8945a0SNathan Whitehorn "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.", 15514c8945a0SNathan Whitehorn "", 15524c8945a0SNathan Whitehorn "* Display dialog boxes from shell scripts *", 15534c8945a0SNathan Whitehorn "", 15544c8945a0SNathan Whitehorn "Usage: %s <options> { --and-widget <options> }", 15554c8945a0SNathan Whitehorn "where options are \"common\" options, followed by \"box\" options", 15564c8945a0SNathan Whitehorn "", 15574c8945a0SNathan Whitehorn #ifdef HAVE_RC_FILE 15584c8945a0SNathan Whitehorn "Special options:", 15594c8945a0SNathan Whitehorn " [--create-rc \"file\"]", 15604c8945a0SNathan Whitehorn #endif 15614c8945a0SNathan Whitehorn 0 15624c8945a0SNathan Whitehorn }, *const tbl_3[] = 15634c8945a0SNathan Whitehorn { 15644c8945a0SNathan Whitehorn "", 15654c8945a0SNathan Whitehorn "Auto-size with height and width = 0. Maximize with height and width = -1.", 15664c8945a0SNathan Whitehorn "Global-auto-size if also menu_height/list_height = 0.", 15674c8945a0SNathan Whitehorn 0 15684c8945a0SNathan Whitehorn }; 1569a96ef450SBaptiste Daroussin size_t limit = TableSize(options); 15707a1c0d96SNathan Whitehorn size_t j, k; 15714c8945a0SNathan Whitehorn const Options **opts; 15724c8945a0SNathan Whitehorn 1573682c9e0fSNathan Whitehorn end_dialog(); 1574682c9e0fSNathan Whitehorn dialog_state.output = stdout; 1575682c9e0fSNathan Whitehorn 15764c8945a0SNathan Whitehorn opts = dlg_calloc(const Options *, limit); 15774c8945a0SNathan Whitehorn assert_ptr(opts, "Help"); 15784c8945a0SNathan Whitehorn for (j = 0; j < limit; ++j) { 15794c8945a0SNathan Whitehorn opts[j] = &(options[j]); 15804c8945a0SNathan Whitehorn } 15814c8945a0SNathan Whitehorn qsort(opts, limit, sizeof(Options *), compare_opts); 15824c8945a0SNathan Whitehorn 15834c8945a0SNathan Whitehorn PrintList(tbl_1); 15844c8945a0SNathan Whitehorn fprintf(dialog_state.output, "Common options:\n "); 15854c8945a0SNathan Whitehorn for (j = k = 0; j < limit; j++) { 15864c8945a0SNathan Whitehorn if ((opts[j]->pass & 1) 15874c8945a0SNathan Whitehorn && opts[j]->help != 0) { 15887a1c0d96SNathan Whitehorn size_t len = 6 + strlen(opts[j]->name) + strlen(opts[j]->help); 15894c8945a0SNathan Whitehorn k += len; 15904c8945a0SNathan Whitehorn if (k > 75) { 15914c8945a0SNathan Whitehorn fprintf(dialog_state.output, "\n "); 15924c8945a0SNathan Whitehorn k = len; 15934c8945a0SNathan Whitehorn } 15944c8945a0SNathan Whitehorn fprintf(dialog_state.output, " [--%s%s%s]", opts[j]->name, 15954c8945a0SNathan Whitehorn *(opts[j]->help) ? " " : "", opts[j]->help); 15964c8945a0SNathan Whitehorn } 15974c8945a0SNathan Whitehorn } 15984c8945a0SNathan Whitehorn fprintf(dialog_state.output, "\nBox options:\n"); 15994c8945a0SNathan Whitehorn for (j = 0; j < limit; j++) { 16004c8945a0SNathan Whitehorn if ((opts[j]->pass & 2) != 0 16014c8945a0SNathan Whitehorn && opts[j]->help != 0 1602f4f33ea0SBaptiste Daroussin && lookupMode(opts[j]->code)) { 16034c8945a0SNathan Whitehorn fprintf(dialog_state.output, " --%-12s %s\n", opts[j]->name, 16044c8945a0SNathan Whitehorn opts[j]->help); 16054c8945a0SNathan Whitehorn } 1606f4f33ea0SBaptiste Daroussin } 16074c8945a0SNathan Whitehorn PrintList(tbl_3); 16084c8945a0SNathan Whitehorn 16094c8945a0SNathan Whitehorn free(opts); 1610f4f33ea0SBaptiste Daroussin handle_leaks(); 16114c8945a0SNathan Whitehorn dlg_exit(DLG_EXIT_OK); 16124c8945a0SNathan Whitehorn } 16134c8945a0SNathan Whitehorn 16142a3e3873SBaptiste Daroussin #ifdef HAVE_DLG_TRACE 16152a3e3873SBaptiste Daroussin /* 16162a3e3873SBaptiste Daroussin * Only the first call to dlg_trace will open a trace file. But each time 16172a3e3873SBaptiste Daroussin * --trace is parsed, we show the whole parameter list as it is at that moment, 16182a3e3873SBaptiste Daroussin * counting discarded parameters. The only way to capture the whole parameter 16192a3e3873SBaptiste Daroussin * list is if --trace is the first option. 16202a3e3873SBaptiste Daroussin */ 16212a3e3873SBaptiste Daroussin static void 16222a3e3873SBaptiste Daroussin process_trace_option(char **argv, int *offset) 16232a3e3873SBaptiste Daroussin { 16242a3e3873SBaptiste Daroussin int j; 16252a3e3873SBaptiste Daroussin 16262a3e3873SBaptiste Daroussin if (dialog_state.trace_output == 0) { 16272a3e3873SBaptiste Daroussin dlg_trace(optionString(argv, offset)); 16282a3e3873SBaptiste Daroussin } else { 1629f4f33ea0SBaptiste Daroussin DLG_TRACE(("# ignore extra --trace option\n")); 16302a3e3873SBaptiste Daroussin *offset += 1; 16312a3e3873SBaptiste Daroussin } 16322a3e3873SBaptiste Daroussin 1633f4f33ea0SBaptiste Daroussin DLG_TRACE(("# Parameters:\n")); 16342a3e3873SBaptiste Daroussin for (j = 0; argv[j] != 0; ++j) { 1635f4f33ea0SBaptiste Daroussin DLG_TRACE(("#\targv[%d] = %s\n", j, argv[j])); 16362a3e3873SBaptiste Daroussin } 16372a3e3873SBaptiste Daroussin } 16382a3e3873SBaptiste Daroussin #endif 16392a3e3873SBaptiste Daroussin 16404c8945a0SNathan Whitehorn /* 16414c8945a0SNathan Whitehorn * "Common" options apply to all widgets more/less. Most of the common options 16424c8945a0SNathan Whitehorn * set values in dialog_vars, a few set dialog_state and a couple write to the 16434c8945a0SNathan Whitehorn * output stream. 16444c8945a0SNathan Whitehorn */ 16454c8945a0SNathan Whitehorn static int 1646a96ef450SBaptiste Daroussin process_common_options(int argc, char **argv, int offset, int output) 16474c8945a0SNathan Whitehorn { 1648a96ef450SBaptiste Daroussin const Options *data = NULL; 16494c8945a0SNathan Whitehorn bool done = FALSE; 16504c8945a0SNathan Whitehorn 1651a96ef450SBaptiste Daroussin DLG_TRACE(("# process_common_options, offset %d:%d\n", offset, argc)); 16522a3e3873SBaptiste Daroussin 1653a96ef450SBaptiste Daroussin while (!done && offset < argc) { 1654a96ef450SBaptiste Daroussin static char empty[] = ""; 1655a96ef450SBaptiste Daroussin eOptions code = o_unknown; 1656a96ef450SBaptiste Daroussin char *sval = empty; 1657a96ef450SBaptiste Daroussin bool bval; 1658a96ef450SBaptiste Daroussin int nval; 1659a96ef450SBaptiste Daroussin char *target; 1660a96ef450SBaptiste Daroussin 1661f4f33ea0SBaptiste Daroussin DLG_TRACE(("#\targv[%d] = %s\n", offset, argv[offset])); 1662a96ef450SBaptiste Daroussin if ((data = findOption(argv[offset], 1, FALSE)) == NULL) { 1663a96ef450SBaptiste Daroussin done = TRUE; 1664a96ef450SBaptiste Daroussin continue; 1665a96ef450SBaptiste Daroussin } 1666a96ef450SBaptiste Daroussin 1667a96ef450SBaptiste Daroussin switch (data->vars) { 1668a96ef450SBaptiste Daroussin default: 1669a96ef450SBaptiste Daroussin target = NULL; 16704c8945a0SNathan Whitehorn break; 1671a96ef450SBaptiste Daroussin case 1: 1672a96ef450SBaptiste Daroussin target = (char *) &dialog_state; 16734c8945a0SNathan Whitehorn break; 1674a96ef450SBaptiste Daroussin case 2: 1675a96ef450SBaptiste Daroussin target = (char *) &dialog_vars; 16764c8945a0SNathan Whitehorn break; 1677a96ef450SBaptiste Daroussin } 1678a96ef450SBaptiste Daroussin 1679a96ef450SBaptiste Daroussin #define TraceTarget \ 1680a96ef450SBaptiste Daroussin ((target == (char *) &dialog_state) \ 1681a96ef450SBaptiste Daroussin ? "dialog_state" \ 1682a96ef450SBaptiste Daroussin : "dialog_vars") 1683a96ef450SBaptiste Daroussin #define TraceBVal (bval ? "TRUE" : "FALSE") 1684a96ef450SBaptiste Daroussin #define TraceDone(fmt,value) \ 1685a96ef450SBaptiste Daroussin DLG_TRACE(("#\t.. set %s.%s = %"fmt"\n", TraceTarget, data->name, value)) 1686a96ef450SBaptiste Daroussin #define TraceLate(fmt,value) \ 1687a96ef450SBaptiste Daroussin DLG_TRACE(("#\t.. defer setting %s = %"fmt"\n", data->name, value)) 1688a96ef450SBaptiste Daroussin 1689a96ef450SBaptiste Daroussin code = data->code; 1690a96ef450SBaptiste Daroussin switch (data->type) { 1691a96ef450SBaptiste Daroussin default: 16924c8945a0SNathan Whitehorn break; 1693a96ef450SBaptiste Daroussin case tFalse: 1694a96ef450SBaptiste Daroussin case tTrue: 1695a96ef450SBaptiste Daroussin bval = optionBool(argv[offset], data); 1696a96ef450SBaptiste Daroussin if (target != NULL) { 1697a96ef450SBaptiste Daroussin *(bool *) (target + data->offset) = bval; 1698a96ef450SBaptiste Daroussin TraceDone("s", TraceBVal); 1699a96ef450SBaptiste Daroussin } else { 1700a96ef450SBaptiste Daroussin TraceLate("s", TraceBVal); 1701a96ef450SBaptiste Daroussin } 17024c8945a0SNathan Whitehorn break; 1703a96ef450SBaptiste Daroussin case tNumber: 1704a96ef450SBaptiste Daroussin nval = optionValue(argv, &offset); 1705a96ef450SBaptiste Daroussin if (target != NULL) { 1706a96ef450SBaptiste Daroussin *(int *) (void *) (target + data->offset) = nval; 1707a96ef450SBaptiste Daroussin TraceDone("d", nval); 1708a96ef450SBaptiste Daroussin } else { 1709a96ef450SBaptiste Daroussin TraceLate("d", nval); 1710a96ef450SBaptiste Daroussin } 17114c8945a0SNathan Whitehorn break; 1712a96ef450SBaptiste Daroussin case tString: 1713a96ef450SBaptiste Daroussin sval = optionString(argv, &offset); 1714a96ef450SBaptiste Daroussin if (target != NULL) { 1715a96ef450SBaptiste Daroussin *(char **) (void *) (target + data->offset) = sval; 1716a96ef450SBaptiste Daroussin TraceDone("s", sval); 1717a96ef450SBaptiste Daroussin } else { 1718a96ef450SBaptiste Daroussin TraceLate("s", sval); 1719a96ef450SBaptiste Daroussin } 1720682c9e0fSNathan Whitehorn break; 1721a96ef450SBaptiste Daroussin } 1722a96ef450SBaptiste Daroussin 1723a96ef450SBaptiste Daroussin switch (code) { 17244c8945a0SNathan Whitehorn case o_defaultno: 17252a3e3873SBaptiste Daroussin dialog_vars.default_button = DLG_EXIT_CANCEL; 17262a3e3873SBaptiste Daroussin break; 17272a3e3873SBaptiste Daroussin case o_default_button: 1728a96ef450SBaptiste Daroussin dialog_vars.default_button = button_code(sval); 17292a3e3873SBaptiste Daroussin dialog_vars.defaultno = dialog_vars.default_button == DLG_EXIT_CANCEL; 17304c8945a0SNathan Whitehorn break; 1731a96ef450SBaptiste Daroussin case o_text_only: 1732f4f33ea0SBaptiste Daroussin case o_print_text_size: 1733f4f33ea0SBaptiste Daroussin PrintTextOnly(argv, &offset, code); 1734f4f33ea0SBaptiste Daroussin break; 17354c8945a0SNathan Whitehorn case o_print_maxsize: 17364c8945a0SNathan Whitehorn if (output) { 1737f4f33ea0SBaptiste Daroussin IgnoreNonScreen(argv, offset); 17384c8945a0SNathan Whitehorn fflush(dialog_state.output); 17394c8945a0SNathan Whitehorn fprintf(dialog_state.output, "MaxSize: %d, %d\n", SLINES, SCOLS); 17404c8945a0SNathan Whitehorn } 17414c8945a0SNathan Whitehorn break; 17424c8945a0SNathan Whitehorn case o_print_version: 17434c8945a0SNathan Whitehorn if (output) { 1744682c9e0fSNathan Whitehorn PrintVersion(dialog_state.output); 17454c8945a0SNathan Whitehorn } 17464c8945a0SNathan Whitehorn break; 17474c8945a0SNathan Whitehorn case o_visit_items: 17482a3e3873SBaptiste Daroussin dialog_state.visit_cols = 1; 17494c8945a0SNathan Whitehorn break; 1750a96ef450SBaptiste Daroussin case o_begin_set: 1751a96ef450SBaptiste Daroussin #ifdef HAVE_WHIPTAIL 1752a96ef450SBaptiste Daroussin if (!strcmp(argv[offset], "--topleft")) { 1753a96ef450SBaptiste Daroussin dialog_vars.begin_y = 0; 1754a96ef450SBaptiste Daroussin dialog_vars.begin_x = 0; 1755a96ef450SBaptiste Daroussin } else 1756a96ef450SBaptiste Daroussin #endif 1757a96ef450SBaptiste Daroussin { 17584c8945a0SNathan Whitehorn dialog_vars.begin_y = optionValue(argv, &offset); 17594c8945a0SNathan Whitehorn dialog_vars.begin_x = optionValue(argv, &offset); 1760a96ef450SBaptiste Daroussin } 17614c8945a0SNathan Whitehorn break; 17624c8945a0SNathan Whitehorn case o_ascii_lines: 17634c8945a0SNathan Whitehorn dialog_vars.no_lines = FALSE; 17644c8945a0SNathan Whitehorn break; 17654c8945a0SNathan Whitehorn case o_no_lines: 17664c8945a0SNathan Whitehorn dialog_vars.ascii_lines = FALSE; 17674c8945a0SNathan Whitehorn break; 17687a1c0d96SNathan Whitehorn case o_no_mouse: 1769682c9e0fSNathan Whitehorn mouse_close(); 17707a1c0d96SNathan Whitehorn break; 17714c8945a0SNathan Whitehorn case o_unknown: 1772a96ef450SBaptiste Daroussin done = !ignore_unknown; 1773a96ef450SBaptiste Daroussin default: 17744c8945a0SNathan Whitehorn break; 17754c8945a0SNathan Whitehorn #ifdef HAVE_DLG_TRACE 17764c8945a0SNathan Whitehorn case o_trace: 17772a3e3873SBaptiste Daroussin process_trace_option(argv, &offset); 17782a3e3873SBaptiste Daroussin break; 17792a3e3873SBaptiste Daroussin #endif 1780f4f33ea0SBaptiste Daroussin case o_iso_week: 1781f4f33ea0SBaptiste Daroussin if (dialog_vars.week_start == 0) { /* Monday is implied */ 1782f4f33ea0SBaptiste Daroussin static char default_1st[] = "1"; 1783f4f33ea0SBaptiste Daroussin dialog_vars.week_start = default_1st; 1784f4f33ea0SBaptiste Daroussin } 1785f4f33ea0SBaptiste Daroussin break; 17864c8945a0SNathan Whitehorn } 17874c8945a0SNathan Whitehorn if (!done) 17884c8945a0SNathan Whitehorn offset++; 17894c8945a0SNathan Whitehorn } 1790f4f33ea0SBaptiste Daroussin 1791f4f33ea0SBaptiste Daroussin if (dialog_state.aspect_ratio == 0) 1792f4f33ea0SBaptiste Daroussin dialog_state.aspect_ratio = DEFAULT_ASPECT_RATIO; 1793f4f33ea0SBaptiste Daroussin 17944c8945a0SNathan Whitehorn return offset; 17954c8945a0SNathan Whitehorn } 17964c8945a0SNathan Whitehorn 17974c8945a0SNathan Whitehorn /* 17984c8945a0SNathan Whitehorn * Initialize options at the start of a series of common options culminating 17994c8945a0SNathan Whitehorn * in a widget. 18004c8945a0SNathan Whitehorn */ 18014c8945a0SNathan Whitehorn static void 18024c8945a0SNathan Whitehorn init_result(char *buffer) 18034c8945a0SNathan Whitehorn { 18044c8945a0SNathan Whitehorn static bool first = TRUE; 18054c8945a0SNathan Whitehorn 1806f4f33ea0SBaptiste Daroussin DLG_TRACE(("# init_result\n")); 18072a3e3873SBaptiste Daroussin 18084c8945a0SNathan Whitehorn /* clear everything we do not save for the next widget */ 18094c8945a0SNathan Whitehorn memset(&dialog_vars, 0, sizeof(dialog_vars)); 18104c8945a0SNathan Whitehorn 18114c8945a0SNathan Whitehorn dialog_vars.input_result = buffer; 18124c8945a0SNathan Whitehorn dialog_vars.input_result[0] = '\0'; 18134c8945a0SNathan Whitehorn 18142a3e3873SBaptiste Daroussin dialog_vars.default_button = -1; 18152a3e3873SBaptiste Daroussin 18164c8945a0SNathan Whitehorn /* 18174c8945a0SNathan Whitehorn * The first time this is called, check for common options given by an 18184c8945a0SNathan Whitehorn * environment variable. 18194c8945a0SNathan Whitehorn */ 18204c8945a0SNathan Whitehorn if (first) { 1821a96ef450SBaptiste Daroussin char *env = dlg_getenv_str("DIALOGOPTS"); 18224c8945a0SNathan Whitehorn if (env != 0) 18234c8945a0SNathan Whitehorn env = dlg_strclone(env); 18244c8945a0SNathan Whitehorn if (env != 0) { 18257a1c0d96SNathan Whitehorn special_argv = dlg_string_to_argv(env); 18267a1c0d96SNathan Whitehorn special_argc = dlg_count_argv(special_argv); 18274c8945a0SNathan Whitehorn } 18282a3e3873SBaptiste Daroussin first = FALSE; 18294c8945a0SNathan Whitehorn } 18302a3e3873SBaptiste Daroussin 18314c8945a0SNathan Whitehorn if (special_argv != 0) { 18324c8945a0SNathan Whitehorn process_common_options(special_argc, special_argv, 0, FALSE); 18334c8945a0SNathan Whitehorn } 18344c8945a0SNathan Whitehorn } 18354c8945a0SNathan Whitehorn 18364c8945a0SNathan Whitehorn int 18374c8945a0SNathan Whitehorn main(int argc, char *argv[]) 18384c8945a0SNathan Whitehorn { 18394c8945a0SNathan Whitehorn char temp[256]; 18404c8945a0SNathan Whitehorn bool esc_pressed = FALSE; 18414c8945a0SNathan Whitehorn bool keep_tite = FALSE; 1842a96ef450SBaptiste Daroussin int initial = 1; 18434c8945a0SNathan Whitehorn int offset = 1; 1844a96ef450SBaptiste Daroussin int offset_add = 0; 18454c8945a0SNathan Whitehorn int retval = DLG_EXIT_OK; 1846a96ef450SBaptiste Daroussin int j; 18474c8945a0SNathan Whitehorn eOptions code; 18484c8945a0SNathan Whitehorn char my_buffer[MAX_LEN + 1]; 18494c8945a0SNathan Whitehorn 18504c8945a0SNathan Whitehorn memset(&dialog_state, 0, sizeof(dialog_state)); 18514c8945a0SNathan Whitehorn memset(&dialog_vars, 0, sizeof(dialog_vars)); 18524c8945a0SNathan Whitehorn 18534c8945a0SNathan Whitehorn #if defined(ENABLE_NLS) 18544c8945a0SNathan Whitehorn /* initialize locale support */ 18554c8945a0SNathan Whitehorn setlocale(LC_ALL, ""); 18567a1c0d96SNathan Whitehorn bindtextdomain(NLS_TEXTDOMAIN, LOCALEDIR); 18577a1c0d96SNathan Whitehorn textdomain(NLS_TEXTDOMAIN); 18584c8945a0SNathan Whitehorn #elif defined(HAVE_SETLOCALE) 18594c8945a0SNathan Whitehorn (void) setlocale(LC_ALL, ""); 18604c8945a0SNathan Whitehorn #endif 18614c8945a0SNathan Whitehorn 1862f4f33ea0SBaptiste Daroussin init_result(my_buffer); /* honor $DIALOGOPTS */ 18634c8945a0SNathan Whitehorn unescape_argv(&argc, &argv); 18644c8945a0SNathan Whitehorn program = argv[0]; 18654c8945a0SNathan Whitehorn dialog_state.output = stderr; 18664c8945a0SNathan Whitehorn dialog_state.input = stdin; 18674c8945a0SNathan Whitehorn 18684c8945a0SNathan Whitehorn /* 18694c8945a0SNathan Whitehorn * Look for the last --stdout, --stderr or --output-fd option, and use 18704c8945a0SNathan Whitehorn * that. We can only write to one of them. If --stdout is used, that 18714c8945a0SNathan Whitehorn * can interfere with initializing the curses library, so we want to 18724c8945a0SNathan Whitehorn * know explicitly if it is used. 1873682c9e0fSNathan Whitehorn * 1874682c9e0fSNathan Whitehorn * Also, look for any --version or --help message, processing those 1875682c9e0fSNathan Whitehorn * immediately. 18764c8945a0SNathan Whitehorn */ 18774c8945a0SNathan Whitehorn while (offset < argc) { 18784c8945a0SNathan Whitehorn int base = offset; 18794c8945a0SNathan Whitehorn switch (lookupOption(argv[offset], 7)) { 1880a96ef450SBaptiste Daroussin case o_output_stdout: 18814c8945a0SNathan Whitehorn dialog_state.output = stdout; 18824c8945a0SNathan Whitehorn break; 1883a96ef450SBaptiste Daroussin case o_output_stderr: 18844c8945a0SNathan Whitehorn dialog_state.output = stderr; 18854c8945a0SNathan Whitehorn break; 18864c8945a0SNathan Whitehorn case o_input_fd: 18874c8945a0SNathan Whitehorn if ((j = optionValue(argv, &offset)) < 0 1888f4f33ea0SBaptiste Daroussin || (dialog_state.input = fdopen(j, "r")) == 0) { 1889f4f33ea0SBaptiste Daroussin handle_leaks(); 18904c8945a0SNathan Whitehorn dlg_exiterr("Cannot open input-fd\n"); 1891f4f33ea0SBaptiste Daroussin } 18924c8945a0SNathan Whitehorn break; 18934c8945a0SNathan Whitehorn case o_output_fd: 18944c8945a0SNathan Whitehorn if ((j = optionValue(argv, &offset)) < 0 1895f4f33ea0SBaptiste Daroussin || (dialog_state.output = fdopen(j, "w")) == 0) { 1896f4f33ea0SBaptiste Daroussin handle_leaks(); 18974c8945a0SNathan Whitehorn dlg_exiterr("Cannot open output-fd\n"); 1898f4f33ea0SBaptiste Daroussin } 18994c8945a0SNathan Whitehorn break; 19004c8945a0SNathan Whitehorn case o_keep_tite: 19014c8945a0SNathan Whitehorn keep_tite = TRUE; 19024c8945a0SNathan Whitehorn break; 1903682c9e0fSNathan Whitehorn case o_version: 1904682c9e0fSNathan Whitehorn dialog_state.output = stdout; 1905682c9e0fSNathan Whitehorn PrintVersion(dialog_state.output); 1906f4f33ea0SBaptiste Daroussin dlg_exit(DLG_EXIT_OK); 1907682c9e0fSNathan Whitehorn break; 1908682c9e0fSNathan Whitehorn case o_help: 1909682c9e0fSNathan Whitehorn Help(); 1910682c9e0fSNathan Whitehorn break; 19112a3e3873SBaptiste Daroussin #ifdef HAVE_DLG_TRACE 19122a3e3873SBaptiste Daroussin case o_trace: 19132a3e3873SBaptiste Daroussin /* 19142a3e3873SBaptiste Daroussin * Process/remove the --trace option if it is the first option. 19152a3e3873SBaptiste Daroussin * Otherwise, process it in more/less expected order as a 19162a3e3873SBaptiste Daroussin * "common" option. 19172a3e3873SBaptiste Daroussin */ 19182a3e3873SBaptiste Daroussin if (base == 1) { 19192a3e3873SBaptiste Daroussin process_trace_option(argv, &offset); 19202a3e3873SBaptiste Daroussin break; 19212a3e3873SBaptiste Daroussin } else { 19222a3e3873SBaptiste Daroussin ++offset; 19232a3e3873SBaptiste Daroussin continue; 19242a3e3873SBaptiste Daroussin } 19252a3e3873SBaptiste Daroussin #endif 19264c8945a0SNathan Whitehorn default: 19274c8945a0SNathan Whitehorn ++offset; 19284c8945a0SNathan Whitehorn continue; 19294c8945a0SNathan Whitehorn } 1930f4f33ea0SBaptiste Daroussin DLG_TRACE(("# discarding %d parameters starting with argv[%d] (%s)\n", 19312a3e3873SBaptiste Daroussin 1 + offset - base, base, 1932f4f33ea0SBaptiste Daroussin argv[base])); 19334c8945a0SNathan Whitehorn for (j = base; j < argc; ++j) { 19344c8945a0SNathan Whitehorn dialog_argv[j] = dialog_argv[j + 1 + (offset - base)]; 19354c8945a0SNathan Whitehorn } 19364c8945a0SNathan Whitehorn argc -= (1 + offset - base); 19374c8945a0SNathan Whitehorn offset = base; 19384c8945a0SNathan Whitehorn } 19394c8945a0SNathan Whitehorn offset = 1; 19404c8945a0SNathan Whitehorn init_result(my_buffer); 1941a96ef450SBaptiste Daroussin dialog_vars.keep_tite |= keep_tite; /* init_result() cleared global */ 19424c8945a0SNathan Whitehorn 1943682c9e0fSNathan Whitehorn /* 1944682c9e0fSNathan Whitehorn * Dialog's output may be redirected (see above). Handle the special 1945682c9e0fSNathan Whitehorn * case of options that only report information without interaction. 1946682c9e0fSNathan Whitehorn */ 1947682c9e0fSNathan Whitehorn if (argc == 2) { 1948f4f33ea0SBaptiste Daroussin switch (code = lookupOption(argv[1], 7)) { 19494c8945a0SNathan Whitehorn case o_print_maxsize: 19504c8945a0SNathan Whitehorn (void) initscr(); 19514c8945a0SNathan Whitehorn endwin(); 19524c8945a0SNathan Whitehorn fflush(dialog_state.output); 19534c8945a0SNathan Whitehorn fprintf(dialog_state.output, "MaxSize: %d, %d\n", SLINES, SCOLS); 19544c8945a0SNathan Whitehorn break; 19554c8945a0SNathan Whitehorn case o_print_version: 1956682c9e0fSNathan Whitehorn PrintVersion(dialog_state.output); 19574c8945a0SNathan Whitehorn break; 1958a96ef450SBaptiste Daroussin case o_dlg_clear_screen: 19594c8945a0SNathan Whitehorn initscr(); 19604c8945a0SNathan Whitehorn refresh(); 1961a96ef450SBaptiste Daroussin dlg_keep_tite((dialog_state.output == stdout) ? stderr : stdout); 19624c8945a0SNathan Whitehorn endwin(); 19634c8945a0SNathan Whitehorn break; 19644c8945a0SNathan Whitehorn case o_ignore: 19654c8945a0SNathan Whitehorn break; 19664c8945a0SNathan Whitehorn default: 19674c8945a0SNathan Whitehorn Help(); 19684c8945a0SNathan Whitehorn break; 19694c8945a0SNathan Whitehorn } 1970f4f33ea0SBaptiste Daroussin dlg_exit(DLG_EXIT_OK); 1971f4f33ea0SBaptiste Daroussin } else if (argc < 2) { 19724c8945a0SNathan Whitehorn Help(); 19734c8945a0SNathan Whitehorn } 19744c8945a0SNathan Whitehorn #ifdef HAVE_RC_FILE 1975f4f33ea0SBaptiste Daroussin else if (lookupOption(argv[1], 7) == o_create_rc) { 19764c8945a0SNathan Whitehorn if (argc != 3) { 19774c8945a0SNathan Whitehorn sprintf(temp, "Expected a filename for %.50s", argv[1]); 19784c8945a0SNathan Whitehorn Usage(temp); 19794c8945a0SNathan Whitehorn } 1980f4f33ea0SBaptiste Daroussin if (dlg_parse_rc() == -1) { /* Read the configuration file */ 1981f4f33ea0SBaptiste Daroussin handle_leaks(); 19824c8945a0SNathan Whitehorn dlg_exiterr("dialog: dlg_parse_rc"); 1983f4f33ea0SBaptiste Daroussin } 19844c8945a0SNathan Whitehorn dlg_create_rc(argv[2]); 1985f4f33ea0SBaptiste Daroussin dlg_exit(DLG_EXIT_OK); 19864c8945a0SNathan Whitehorn } 19874c8945a0SNathan Whitehorn #endif 1988f4f33ea0SBaptiste Daroussin else { 1989f4f33ea0SBaptiste Daroussin /* 1990f4f33ea0SBaptiste Daroussin * Handle combinations of common options including --print-text-only 1991f4f33ea0SBaptiste Daroussin * which can be done before involving curses, in case we can exit 1992f4f33ea0SBaptiste Daroussin * without initializing curses (and writing to the terminal). 1993f4f33ea0SBaptiste Daroussin */ 1994a96ef450SBaptiste Daroussin initial = process_common_options(argc, argv, offset, TRUE); 1995a96ef450SBaptiste Daroussin if (initial >= argc) 1996f4f33ea0SBaptiste Daroussin dlg_exit(DLG_EXIT_OK); 1997f4f33ea0SBaptiste Daroussin } 19984c8945a0SNathan Whitehorn 19994c8945a0SNathan Whitehorn init_dialog(dialog_state.input, dialog_state.output); 20004c8945a0SNathan Whitehorn 20014c8945a0SNathan Whitehorn while (offset < argc && !esc_pressed) { 2002a96ef450SBaptiste Daroussin int have; 2003a96ef450SBaptiste Daroussin const Mode *modePtr; 2004a96ef450SBaptiste Daroussin 20054c8945a0SNathan Whitehorn init_result(my_buffer); 2006a96ef450SBaptiste Daroussin offset = process_common_options(argc, argv, offset, offset > initial); 20074c8945a0SNathan Whitehorn 20084c8945a0SNathan Whitehorn if (argv[offset] == NULL) { 20094c8945a0SNathan Whitehorn if (ignore_unknown) 20104c8945a0SNathan Whitehorn break; 20114c8945a0SNathan Whitehorn Usage("Expected a box option"); 20124c8945a0SNathan Whitehorn } 20134c8945a0SNathan Whitehorn 2014f4f33ea0SBaptiste Daroussin if (dialog_vars.separate_output) { 2015f4f33ea0SBaptiste Daroussin switch (lookupOption(argv[offset], 2)) { 2016f4f33ea0SBaptiste Daroussin #ifdef HAVE_XDIALOG2 2017f4f33ea0SBaptiste Daroussin case o_buildlist: 2018f4f33ea0SBaptiste Daroussin case o_treeview: 2019f4f33ea0SBaptiste Daroussin #endif 2020f4f33ea0SBaptiste Daroussin case o_checklist: 2021f4f33ea0SBaptiste Daroussin break; 2022f4f33ea0SBaptiste Daroussin default: 2023f4f33ea0SBaptiste Daroussin sprintf(temp, 2024f4f33ea0SBaptiste Daroussin "Unexpected widget with --separate-output %.20s", 2025f4f33ea0SBaptiste Daroussin argv[offset]); 20264c8945a0SNathan Whitehorn Usage(temp); 20274c8945a0SNathan Whitehorn } 2028f4f33ea0SBaptiste Daroussin } 20294c8945a0SNathan Whitehorn 20304c8945a0SNathan Whitehorn dlg_put_backtitle(); 20314c8945a0SNathan Whitehorn 20324c8945a0SNathan Whitehorn /* use a table to look for the requested mode, to avoid code duplication */ 20334c8945a0SNathan Whitehorn 20344c8945a0SNathan Whitehorn modePtr = 0; 20354c8945a0SNathan Whitehorn if ((code = lookupOption(argv[offset], 2)) != o_unknown) 20364c8945a0SNathan Whitehorn modePtr = lookupMode(code); 20374c8945a0SNathan Whitehorn if (modePtr == 0) { 20384c8945a0SNathan Whitehorn sprintf(temp, "%s option %.20s", 20394c8945a0SNathan Whitehorn lookupOption(argv[offset], 7) != o_unknown 20404c8945a0SNathan Whitehorn ? "Unexpected" 20414c8945a0SNathan Whitehorn : "Unknown", 20424c8945a0SNathan Whitehorn argv[offset]); 20434c8945a0SNathan Whitehorn Usage(temp); 20444c8945a0SNathan Whitehorn } 20454c8945a0SNathan Whitehorn 20464c8945a0SNathan Whitehorn have = arg_rest(&argv[offset]); 20474c8945a0SNathan Whitehorn if (have < modePtr->argmin) { 20484c8945a0SNathan Whitehorn sprintf(temp, "Expected at least %d tokens for %.20s, have %d", 20494c8945a0SNathan Whitehorn modePtr->argmin - 1, argv[offset], 20504c8945a0SNathan Whitehorn have - 1); 20514c8945a0SNathan Whitehorn Usage(temp); 20524c8945a0SNathan Whitehorn } 20534c8945a0SNathan Whitehorn if (modePtr->argmax && have > modePtr->argmax) { 20544c8945a0SNathan Whitehorn sprintf(temp, 20554c8945a0SNathan Whitehorn "Expected no more than %d tokens for %.20s, have %d", 20564c8945a0SNathan Whitehorn modePtr->argmax - 1, argv[offset], 20574c8945a0SNathan Whitehorn have - 1); 20584c8945a0SNathan Whitehorn Usage(temp); 20594c8945a0SNathan Whitehorn } 20604c8945a0SNathan Whitehorn 20614c8945a0SNathan Whitehorn /* 20624c8945a0SNathan Whitehorn * Trim whitespace from non-title option values, e.g., the ones that 20634c8945a0SNathan Whitehorn * will be used as captions or prompts. Do that only for the widget 20644c8945a0SNathan Whitehorn * we are about to process, since the "--trim" option is reset before 20654c8945a0SNathan Whitehorn * accumulating options for each widget. 20664c8945a0SNathan Whitehorn */ 20674c8945a0SNathan Whitehorn for (j = offset + 1; j <= offset + have; j++) { 20684c8945a0SNathan Whitehorn switch (lookupOption(argv[j - 1], 7)) { 20694c8945a0SNathan Whitehorn case o_unknown: 20704c8945a0SNathan Whitehorn case o_title: 20714c8945a0SNathan Whitehorn case o_backtitle: 2072682c9e0fSNathan Whitehorn case o_help_line: 2073682c9e0fSNathan Whitehorn case o_help_file: 20744c8945a0SNathan Whitehorn break; 20754c8945a0SNathan Whitehorn default: 20764c8945a0SNathan Whitehorn if (argv[j] != 0) { 20772a3e3873SBaptiste Daroussin char *argv_j = strdup(argv[j]); 20782a3e3873SBaptiste Daroussin if (argv_j != 0) { 20792a3e3873SBaptiste Daroussin dlg_trim_string(argv_j); 20802a3e3873SBaptiste Daroussin argv[j] = argv_j; 20812a3e3873SBaptiste Daroussin } else { 20822a3e3873SBaptiste Daroussin argv[j] = strdup("?"); 20832a3e3873SBaptiste Daroussin } 2084f4f33ea0SBaptiste Daroussin ignore_leak(argv[j]); 20854c8945a0SNathan Whitehorn } 20864c8945a0SNathan Whitehorn break; 20874c8945a0SNathan Whitehorn } 20884c8945a0SNathan Whitehorn } 20894c8945a0SNathan Whitehorn 2090f4f33ea0SBaptiste Daroussin DLG_TRACE(("# execute %s\n", argv[offset])); 20914c8945a0SNathan Whitehorn retval = show_result((*(modePtr->jumper)) (dialog_vars.title, 20924c8945a0SNathan Whitehorn argv + offset, 20934c8945a0SNathan Whitehorn &offset_add)); 2094f4f33ea0SBaptiste Daroussin DLG_TRACE(("# widget returns %d\n", retval)); 20954c8945a0SNathan Whitehorn offset += offset_add; 20964c8945a0SNathan Whitehorn 20977a1c0d96SNathan Whitehorn if (dialog_vars.input_result != my_buffer) { 20984c8945a0SNathan Whitehorn free(dialog_vars.input_result); 20997a1c0d96SNathan Whitehorn dialog_vars.input_result = 0; 21007a1c0d96SNathan Whitehorn } 21014c8945a0SNathan Whitehorn 21024c8945a0SNathan Whitehorn if (retval == DLG_EXIT_ESC) { 21034c8945a0SNathan Whitehorn esc_pressed = TRUE; 21044c8945a0SNathan Whitehorn } else { 21054c8945a0SNathan Whitehorn 21064c8945a0SNathan Whitehorn if (dialog_vars.beep_after_signal) 21074c8945a0SNathan Whitehorn (void) beep(); 21084c8945a0SNathan Whitehorn 21094c8945a0SNathan Whitehorn if (dialog_vars.sleep_secs) 21104c8945a0SNathan Whitehorn (void) napms(dialog_vars.sleep_secs * 1000); 21114c8945a0SNathan Whitehorn 21124c8945a0SNathan Whitehorn if (offset < argc) { 21134c8945a0SNathan Whitehorn switch (lookupOption(argv[offset], 7)) { 21144c8945a0SNathan Whitehorn case o_and_widget: 21154c8945a0SNathan Whitehorn offset++; 21164c8945a0SNathan Whitehorn break; 21174c8945a0SNathan Whitehorn case o_unknown: 21184c8945a0SNathan Whitehorn sprintf(temp, "Expected --and-widget, not %.20s", 21194c8945a0SNathan Whitehorn argv[offset]); 21204c8945a0SNathan Whitehorn Usage(temp); 21214c8945a0SNathan Whitehorn break; 21224c8945a0SNathan Whitehorn default: 21234c8945a0SNathan Whitehorn /* if we got a cancel, etc., stop chaining */ 21244c8945a0SNathan Whitehorn if (retval != DLG_EXIT_OK) 21254c8945a0SNathan Whitehorn esc_pressed = TRUE; 21264c8945a0SNathan Whitehorn else 21274c8945a0SNathan Whitehorn dialog_vars.dlg_clear_screen = TRUE; 21284c8945a0SNathan Whitehorn break; 21294c8945a0SNathan Whitehorn } 21304c8945a0SNathan Whitehorn } 21314c8945a0SNathan Whitehorn if (dialog_vars.dlg_clear_screen) 21324c8945a0SNathan Whitehorn dlg_clear(); 21334c8945a0SNathan Whitehorn } 21344c8945a0SNathan Whitehorn } 21354c8945a0SNathan Whitehorn 21364c8945a0SNathan Whitehorn dlg_killall_bg(&retval); 21374c8945a0SNathan Whitehorn if (dialog_state.screen_initialized) { 21384c8945a0SNathan Whitehorn (void) refresh(); 21394c8945a0SNathan Whitehorn end_dialog(); 21404c8945a0SNathan Whitehorn } 2141f4f33ea0SBaptiste Daroussin handle_leaks(); 21424c8945a0SNathan Whitehorn dlg_exit(retval); 21434c8945a0SNathan Whitehorn } 2144