14c8945a0SNathan Whitehorn /* 22a3e3873SBaptiste Daroussin * $Id: dialog.c,v 1.230 2013/03/15 09:07:30 tom Exp $ 34c8945a0SNathan Whitehorn * 44c8945a0SNathan Whitehorn * cdialog - Display simple dialog boxes from shell scripts 54c8945a0SNathan Whitehorn * 62a3e3873SBaptiste Daroussin * Copyright 2000-2012,2013 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> 284c8945a0SNathan Whitehorn #include <string.h> 294c8945a0SNathan Whitehorn #include <sys/types.h> 304c8945a0SNathan Whitehorn #include <sys/stat.h> 314c8945a0SNathan Whitehorn 324c8945a0SNathan Whitehorn #ifdef HAVE_SETLOCALE 334c8945a0SNathan Whitehorn #include <locale.h> 344c8945a0SNathan Whitehorn #endif 354c8945a0SNathan Whitehorn 364c8945a0SNathan Whitehorn #define PASSARGS t, av, offset_add 374c8945a0SNathan Whitehorn #define CALLARGS const char *t, char *av[], int *offset_add 384c8945a0SNathan Whitehorn typedef int (callerFn) (CALLARGS); 394c8945a0SNathan Whitehorn 404c8945a0SNathan Whitehorn typedef enum { 414c8945a0SNathan Whitehorn o_unknown = 0 424c8945a0SNathan Whitehorn ,o_allow_close 434c8945a0SNathan Whitehorn ,o_and_widget 444c8945a0SNathan Whitehorn ,o_ascii_lines 454c8945a0SNathan Whitehorn ,o_aspect 464c8945a0SNathan Whitehorn ,o_auto_placement 474c8945a0SNathan Whitehorn ,o_backtitle 484c8945a0SNathan Whitehorn ,o_beep 494c8945a0SNathan Whitehorn ,o_beep_after 504c8945a0SNathan Whitehorn ,o_begin 514c8945a0SNathan Whitehorn ,o_cancel_label 524c8945a0SNathan Whitehorn ,o_checklist 534c8945a0SNathan Whitehorn ,o_clear 544c8945a0SNathan Whitehorn ,o_colors 554c8945a0SNathan Whitehorn ,o_column_separator 564c8945a0SNathan Whitehorn ,o_cr_wrap 574c8945a0SNathan Whitehorn ,o_create_rc 584c8945a0SNathan Whitehorn ,o_date_format 592a3e3873SBaptiste Daroussin ,o_default_button 604c8945a0SNathan Whitehorn ,o_default_item 614c8945a0SNathan Whitehorn ,o_defaultno 624c8945a0SNathan Whitehorn ,o_exit_label 634c8945a0SNathan Whitehorn ,o_extra_button 644c8945a0SNathan Whitehorn ,o_extra_label 654c8945a0SNathan Whitehorn ,o_fixed_font 664c8945a0SNathan Whitehorn ,o_form 674c8945a0SNathan Whitehorn ,o_gauge 684c8945a0SNathan Whitehorn ,o_help 694c8945a0SNathan Whitehorn ,o_help_button 70682c9e0fSNathan Whitehorn ,o_help_file 714c8945a0SNathan Whitehorn ,o_help_label 72682c9e0fSNathan Whitehorn ,o_help_line 734c8945a0SNathan Whitehorn ,o_help_status 744c8945a0SNathan Whitehorn ,o_icon 754c8945a0SNathan Whitehorn ,o_ignore 764c8945a0SNathan Whitehorn ,o_infobox 774c8945a0SNathan Whitehorn ,o_input_fd 784c8945a0SNathan Whitehorn ,o_inputbox 794c8945a0SNathan Whitehorn ,o_inputmenu 804c8945a0SNathan Whitehorn ,o_insecure 814c8945a0SNathan Whitehorn ,o_item_help 824c8945a0SNathan Whitehorn ,o_keep_colors 834c8945a0SNathan Whitehorn ,o_keep_tite 844c8945a0SNathan Whitehorn ,o_keep_window 852a3e3873SBaptiste Daroussin ,o_last_key 864c8945a0SNathan Whitehorn ,o_max_input 874c8945a0SNathan Whitehorn ,o_menu 884c8945a0SNathan Whitehorn ,o_mixedform 894c8945a0SNathan Whitehorn ,o_mixedgauge 904c8945a0SNathan Whitehorn ,o_msgbox 914c8945a0SNathan Whitehorn ,o_no_close 924c8945a0SNathan Whitehorn ,o_no_collapse 934c8945a0SNathan Whitehorn ,o_no_cr_wrap 944c8945a0SNathan Whitehorn ,o_no_kill 954c8945a0SNathan Whitehorn ,o_no_label 964c8945a0SNathan Whitehorn ,o_no_lines 977a1c0d96SNathan Whitehorn ,o_no_mouse 98682c9e0fSNathan Whitehorn ,o_no_nl_expand 994c8945a0SNathan Whitehorn ,o_no_shadow 1004c8945a0SNathan Whitehorn ,o_nocancel 1014c8945a0SNathan Whitehorn ,o_nook 1024c8945a0SNathan Whitehorn ,o_ok_label 1034c8945a0SNathan Whitehorn ,o_output_fd 1044c8945a0SNathan Whitehorn ,o_output_separator 1054c8945a0SNathan Whitehorn ,o_passwordbox 1064c8945a0SNathan Whitehorn ,o_passwordform 1074c8945a0SNathan Whitehorn ,o_pause 1087a1c0d96SNathan Whitehorn ,o_prgbox 1094c8945a0SNathan Whitehorn ,o_print_maxsize 1104c8945a0SNathan Whitehorn ,o_print_size 1114c8945a0SNathan Whitehorn ,o_print_version 1127a1c0d96SNathan Whitehorn ,o_programbox 1134c8945a0SNathan Whitehorn ,o_progressbox 1144c8945a0SNathan Whitehorn ,o_quoted 1154c8945a0SNathan Whitehorn ,o_radiolist 1164c8945a0SNathan Whitehorn ,o_screen_center 1174c8945a0SNathan Whitehorn ,o_scrollbar 1184c8945a0SNathan Whitehorn ,o_separate_output 1194c8945a0SNathan Whitehorn ,o_separate_widget 1204c8945a0SNathan Whitehorn ,o_separator 1214c8945a0SNathan Whitehorn ,o_shadow 1224c8945a0SNathan Whitehorn ,o_single_quoted 1234c8945a0SNathan Whitehorn ,o_size_err 1244c8945a0SNathan Whitehorn ,o_sleep 1254c8945a0SNathan Whitehorn ,o_smooth 1264c8945a0SNathan Whitehorn ,o_stderr 1274c8945a0SNathan Whitehorn ,o_stdout 1284c8945a0SNathan Whitehorn ,o_tab_correct 1294c8945a0SNathan Whitehorn ,o_tab_len 1304c8945a0SNathan Whitehorn ,o_tailbox 1314c8945a0SNathan Whitehorn ,o_tailboxbg 1324c8945a0SNathan Whitehorn ,o_textbox 1334c8945a0SNathan Whitehorn ,o_time_format 1344c8945a0SNathan Whitehorn ,o_timeout 1354c8945a0SNathan Whitehorn ,o_title 1364c8945a0SNathan Whitehorn ,o_trim 1374c8945a0SNathan Whitehorn ,o_under_mouse 138682c9e0fSNathan Whitehorn ,o_version 1394c8945a0SNathan Whitehorn ,o_visit_items 1404c8945a0SNathan Whitehorn ,o_wmclass 1414c8945a0SNathan Whitehorn ,o_yes_label 1424c8945a0SNathan Whitehorn ,o_yesno 1432a3e3873SBaptiste Daroussin #ifdef HAVE_WHIPTAIL 1442a3e3873SBaptiste Daroussin ,o_fullbutton 1452a3e3873SBaptiste Daroussin ,o_topleft 1462a3e3873SBaptiste Daroussin #endif 1472a3e3873SBaptiste Daroussin #ifdef HAVE_XDIALOG 1482a3e3873SBaptiste Daroussin ,o_calendar 1492a3e3873SBaptiste Daroussin ,o_dselect 1502a3e3873SBaptiste Daroussin ,o_editbox 1512a3e3873SBaptiste Daroussin ,o_fselect 1522a3e3873SBaptiste Daroussin ,o_timebox 1532a3e3873SBaptiste Daroussin #endif 1542a3e3873SBaptiste Daroussin #ifdef HAVE_XDIALOG2 1552a3e3873SBaptiste Daroussin ,o_buildlist 1562a3e3873SBaptiste Daroussin ,o_rangebox 1572a3e3873SBaptiste Daroussin ,o_treeview 1582a3e3873SBaptiste Daroussin #endif 1592a3e3873SBaptiste Daroussin #if defined(HAVE_XDIALOG2) || defined(HAVE_WHIPTAIL) 1602a3e3873SBaptiste Daroussin ,o_no_items 1612a3e3873SBaptiste Daroussin ,o_no_tags 1622a3e3873SBaptiste Daroussin #endif 1634c8945a0SNathan Whitehorn #ifdef HAVE_DLG_TRACE 1644c8945a0SNathan Whitehorn ,o_trace 1654c8945a0SNathan Whitehorn #endif 1664c8945a0SNathan Whitehorn } eOptions; 1674c8945a0SNathan Whitehorn 1684c8945a0SNathan Whitehorn /* 1694c8945a0SNathan Whitehorn * The bits in 'pass' are used to decide which options are applicable at 1704c8945a0SNathan Whitehorn * different stages in the program: 1714c8945a0SNathan Whitehorn * 1 flags before widgets 1724c8945a0SNathan Whitehorn * 2 widgets 1734c8945a0SNathan Whitehorn * 4 non-widget options 1744c8945a0SNathan Whitehorn */ 1754c8945a0SNathan Whitehorn typedef struct { 1764c8945a0SNathan Whitehorn const char *name; 1774c8945a0SNathan Whitehorn eOptions code; 1784c8945a0SNathan Whitehorn int pass; /* 1,2,4 or combination */ 1794c8945a0SNathan Whitehorn const char *help; /* NULL to suppress, non-empty to display params */ 1804c8945a0SNathan Whitehorn } Options; 1814c8945a0SNathan Whitehorn 1824c8945a0SNathan Whitehorn typedef struct { 1834c8945a0SNathan Whitehorn eOptions code; 1844c8945a0SNathan Whitehorn int argmin, argmax; 1854c8945a0SNathan Whitehorn callerFn *jumper; 1864c8945a0SNathan Whitehorn } Mode; 1874c8945a0SNathan Whitehorn 1884c8945a0SNathan Whitehorn static bool *dialog_opts; 1894c8945a0SNathan Whitehorn static char **dialog_argv; 1904c8945a0SNathan Whitehorn 1914c8945a0SNathan Whitehorn static bool ignore_unknown = FALSE; 1924c8945a0SNathan Whitehorn 1934c8945a0SNathan Whitehorn static const char *program = "dialog"; 1944c8945a0SNathan Whitehorn 1954c8945a0SNathan Whitehorn /* 1964c8945a0SNathan Whitehorn * The options[] table is organized this way to make it simple to maintain 1974c8945a0SNathan Whitehorn * a sorted list of options for the help-message. 1984c8945a0SNathan Whitehorn */ 1994c8945a0SNathan Whitehorn /* *INDENT-OFF* */ 2004c8945a0SNathan Whitehorn static const Options options[] = { 2014c8945a0SNathan Whitehorn { "allow-close", o_allow_close, 1, NULL }, 2024c8945a0SNathan Whitehorn { "and-widget", o_and_widget, 4, NULL }, 2034c8945a0SNathan Whitehorn { "ascii-lines", o_ascii_lines, 1, "" }, 2044c8945a0SNathan Whitehorn { "aspect", o_aspect, 1, "<ratio>" }, 2054c8945a0SNathan Whitehorn { "auto-placement", o_auto_placement, 1, NULL }, 2064c8945a0SNathan Whitehorn { "backtitle", o_backtitle, 1, "<backtitle>" }, 2072a3e3873SBaptiste Daroussin { "beep", o_beep, 1, "" }, 2082a3e3873SBaptiste Daroussin { "beep-after", o_beep_after, 1, "" }, 2094c8945a0SNathan Whitehorn { "begin", o_begin, 1, "<y> <x>" }, 2104c8945a0SNathan Whitehorn { "cancel-label", o_cancel_label, 1, "<str>" }, 2114c8945a0SNathan Whitehorn { "checklist", o_checklist, 2, "<text> <height> <width> <list height> <tag1> <item1> <status1>..." }, 2124c8945a0SNathan Whitehorn { "clear", o_clear, 1, "" }, 2134c8945a0SNathan Whitehorn { "colors", o_colors, 1, "" }, 2144c8945a0SNathan Whitehorn { "column-separator",o_column_separator, 1, "<str>" }, 2154c8945a0SNathan Whitehorn { "cr-wrap", o_cr_wrap, 1, "" }, 2164c8945a0SNathan Whitehorn { "create-rc", o_create_rc, 1, NULL }, 2174c8945a0SNathan Whitehorn { "date-format", o_date_format, 1, "<str>" }, 2182a3e3873SBaptiste Daroussin { "default-button", o_default_button, 1, "<str>" }, 2194c8945a0SNathan Whitehorn { "default-item", o_default_item, 1, "<str>" }, 2204c8945a0SNathan Whitehorn { "defaultno", o_defaultno, 1, "" }, 2214c8945a0SNathan Whitehorn { "exit-label", o_exit_label, 1, "<str>" }, 2224c8945a0SNathan Whitehorn { "extra-button", o_extra_button, 1, "" }, 2234c8945a0SNathan Whitehorn { "extra-label", o_extra_label, 1, "<str>" }, 2244c8945a0SNathan Whitehorn { "fixed-font", o_fixed_font, 1, NULL }, 2254c8945a0SNathan Whitehorn { "form", o_form, 2, "<text> <height> <width> <form height> <label1> <l_y1> <l_x1> <item1> <i_y1> <i_x1> <flen1> <ilen1>..." }, 2264c8945a0SNathan Whitehorn { "gauge", o_gauge, 2, "<text> <height> <width> [<percent>]" }, 2274c8945a0SNathan Whitehorn { "guage", o_gauge, 2, NULL }, 2284c8945a0SNathan Whitehorn { "help", o_help, 4, "" }, 2294c8945a0SNathan Whitehorn { "help-button", o_help_button, 1, "" }, 2304c8945a0SNathan Whitehorn { "help-label", o_help_label, 1, "<str>" }, 2314c8945a0SNathan Whitehorn { "help-status", o_help_status, 1, "" }, 232682c9e0fSNathan Whitehorn { "hfile", o_help_file, 1, "<str>" }, 233682c9e0fSNathan Whitehorn { "hline", o_help_line, 1, "<str>" }, 2344c8945a0SNathan Whitehorn { "icon", o_icon, 1, NULL }, 2354c8945a0SNathan Whitehorn { "ignore", o_ignore, 1, "" }, 2364c8945a0SNathan Whitehorn { "infobox", o_infobox, 2, "<text> <height> <width>" }, 2374c8945a0SNathan Whitehorn { "input-fd", o_input_fd, 1, "<fd>" }, 2384c8945a0SNathan Whitehorn { "inputbox", o_inputbox, 2, "<text> <height> <width> [<init>]" }, 2394c8945a0SNathan Whitehorn { "inputmenu", o_inputmenu, 2, "<text> <height> <width> <menu height> <tag1> <item1>..." }, 2404c8945a0SNathan Whitehorn { "insecure", o_insecure, 1, "" }, 2414c8945a0SNathan Whitehorn { "item-help", o_item_help, 1, "" }, 2424c8945a0SNathan Whitehorn { "keep-colors", o_keep_colors, 1, NULL }, 2434c8945a0SNathan Whitehorn { "keep-tite", o_keep_tite, 1, "" }, 2444c8945a0SNathan Whitehorn { "keep-window", o_keep_window, 1, "" }, 2452a3e3873SBaptiste Daroussin { "last-key", o_last_key, 1, "" }, 2464c8945a0SNathan Whitehorn { "max-input", o_max_input, 1, "<n>" }, 2474c8945a0SNathan Whitehorn { "menu", o_menu, 2, "<text> <height> <width> <menu height> <tag1> <item1>..." }, 2484c8945a0SNathan Whitehorn { "mixedform", o_mixedform, 2, "<text> <height> <width> <form height> <label1> <l_y1> <l_x1> <item1> <i_y1> <i_x1> <flen1> <ilen1> <itype>..." }, 2494c8945a0SNathan Whitehorn { "mixedgauge", o_mixedgauge, 2, "<text> <height> <width> <percent> <tag1> <item1>..." }, 2504c8945a0SNathan Whitehorn { "msgbox", o_msgbox, 2, "<text> <height> <width>" }, 2514c8945a0SNathan Whitehorn { "no-cancel", o_nocancel, 1, "" }, 2524c8945a0SNathan Whitehorn { "no-close", o_no_close, 1, NULL }, 2534c8945a0SNathan Whitehorn { "no-collapse", o_no_collapse, 1, "" }, 2542a3e3873SBaptiste Daroussin { "no-cr-wrap", o_no_cr_wrap, 1, "" }, 2554c8945a0SNathan Whitehorn { "no-kill", o_no_kill, 1, "" }, 2564c8945a0SNathan Whitehorn { "no-label", o_no_label, 1, "<str>" }, 2574c8945a0SNathan Whitehorn { "no-lines", o_no_lines, 1, "" }, 2587a1c0d96SNathan Whitehorn { "no-mouse", o_no_mouse, 1, "" }, 259682c9e0fSNathan Whitehorn { "no-nl-expand", o_no_nl_expand, 1, "" }, 2604c8945a0SNathan Whitehorn { "no-ok", o_nook, 1, "" }, 2614c8945a0SNathan Whitehorn { "no-shadow", o_no_shadow, 1, "" }, 2624c8945a0SNathan Whitehorn { "nocancel", o_nocancel, 1, NULL }, /* see --no-cancel */ 2634c8945a0SNathan Whitehorn { "nook", o_nook, 1, "" }, /* See no-ok */ 2644c8945a0SNathan Whitehorn { "ok-label", o_ok_label, 1, "<str>" }, 2654c8945a0SNathan Whitehorn { "output-fd", o_output_fd, 1, "<fd>" }, 2664c8945a0SNathan Whitehorn { "output-separator",o_output_separator, 1, "<str>" }, 2674c8945a0SNathan Whitehorn { "passwordbox", o_passwordbox, 2, "<text> <height> <width> [<init>]" }, 2684c8945a0SNathan Whitehorn { "passwordform", o_passwordform, 2, "<text> <height> <width> <form height> <label1> <l_y1> <l_x1> <item1> <i_y1> <i_x1> <flen1> <ilen1>..." }, 2694c8945a0SNathan Whitehorn { "pause", o_pause, 2, "<text> <height> <width> <seconds>" }, 2707a1c0d96SNathan Whitehorn { "prgbox", o_prgbox, 2, "<text> <command> <height> <width>" }, 2714c8945a0SNathan Whitehorn { "print-maxsize", o_print_maxsize, 1, "" }, 2724c8945a0SNathan Whitehorn { "print-size", o_print_size, 1, "" }, 2734c8945a0SNathan Whitehorn { "print-version", o_print_version, 5, "" }, 2747a1c0d96SNathan Whitehorn { "programbox", o_programbox, 2, "<text> <height> <width>" }, 2757a1c0d96SNathan Whitehorn { "progressbox", o_progressbox, 2, "<text> <height> <width>" }, 2764c8945a0SNathan Whitehorn { "quoted", o_quoted, 1, "" }, 2774c8945a0SNathan Whitehorn { "radiolist", o_radiolist, 2, "<text> <height> <width> <list height> <tag1> <item1> <status1>..." }, 2784c8945a0SNathan Whitehorn { "screen-center", o_screen_center, 1, NULL }, 2794c8945a0SNathan Whitehorn { "scrollbar", o_scrollbar, 1, "" }, 2804c8945a0SNathan Whitehorn { "separate-output",o_separate_output, 1, "" }, 2814c8945a0SNathan Whitehorn { "separate-widget",o_separate_widget, 1, "<str>" }, 2824c8945a0SNathan Whitehorn { "separator", o_separator, 1, NULL }, 2834c8945a0SNathan Whitehorn { "shadow", o_shadow, 1, "" }, 2844c8945a0SNathan Whitehorn { "single-quoted", o_single_quoted, 1, "" }, 2854c8945a0SNathan Whitehorn { "size-err", o_size_err, 1, "" }, 2864c8945a0SNathan Whitehorn { "sleep", o_sleep, 1, "<secs>" }, 2874c8945a0SNathan Whitehorn { "smooth", o_smooth, 1, NULL }, 2884c8945a0SNathan Whitehorn { "stderr", o_stderr, 1, "" }, 2894c8945a0SNathan Whitehorn { "stdout", o_stdout, 1, "" }, 2904c8945a0SNathan Whitehorn { "tab-correct", o_tab_correct, 1, "" }, 2914c8945a0SNathan Whitehorn { "tab-len", o_tab_len, 1, "<n>" }, 2924c8945a0SNathan Whitehorn { "tailbox", o_tailbox, 2, "<file> <height> <width>" }, 2934c8945a0SNathan Whitehorn { "tailboxbg", o_tailboxbg, 2, "<file> <height> <width>" }, 2944c8945a0SNathan Whitehorn { "textbox", o_textbox, 2, "<file> <height> <width>" }, 2954c8945a0SNathan Whitehorn { "time-format", o_time_format, 1, "<str>" }, 2964c8945a0SNathan Whitehorn { "timeout", o_timeout, 1, "<secs>" }, 2974c8945a0SNathan Whitehorn { "title", o_title, 1, "<title>" }, 2984c8945a0SNathan Whitehorn { "trim", o_trim, 1, "" }, 2994c8945a0SNathan Whitehorn { "under-mouse", o_under_mouse, 1, NULL }, 300682c9e0fSNathan Whitehorn { "version", o_version, 5, "" }, 3014c8945a0SNathan Whitehorn { "visit-items", o_visit_items, 1, "" }, 3024c8945a0SNathan Whitehorn { "wmclass", o_wmclass, 1, NULL }, 3034c8945a0SNathan Whitehorn { "yes-label", o_yes_label, 1, "<str>" }, 3044c8945a0SNathan Whitehorn { "yesno", o_yesno, 2, "<text> <height> <width>" }, 3052a3e3873SBaptiste Daroussin #ifdef HAVE_WHIPTAIL 3062a3e3873SBaptiste Daroussin { "cancel-button", o_cancel_label, 1, NULL }, 3072a3e3873SBaptiste Daroussin { "fb", o_fullbutton, 1, NULL }, 3082a3e3873SBaptiste Daroussin { "fullbutton", o_fullbutton, 1, NULL }, 3092a3e3873SBaptiste Daroussin { "no-button", o_no_label, 1, NULL }, 3102a3e3873SBaptiste Daroussin { "ok-button", o_ok_label, 1, NULL }, 3112a3e3873SBaptiste Daroussin { "scrolltext", o_scrollbar, 1, NULL }, 3122a3e3873SBaptiste Daroussin { "topleft", o_topleft, 1, NULL }, 3132a3e3873SBaptiste Daroussin { "yes-button", o_yes_label, 1, NULL }, 3142a3e3873SBaptiste Daroussin #endif 3152a3e3873SBaptiste Daroussin #ifdef HAVE_XDIALOG 3162a3e3873SBaptiste Daroussin { "calendar", o_calendar, 2, "<text> <height> <width> <day> <month> <year>" }, 3172a3e3873SBaptiste Daroussin { "dselect", o_dselect, 2, "<directory> <height> <width>" }, 3182a3e3873SBaptiste Daroussin { "editbox", o_editbox, 2, "<file> <height> <width>" }, 3192a3e3873SBaptiste Daroussin { "fselect", o_fselect, 2, "<filepath> <height> <width>" }, 3202a3e3873SBaptiste Daroussin { "timebox", o_timebox, 2, "<text> <height> <width> <hour> <minute> <second>" }, 3212a3e3873SBaptiste Daroussin #endif 3222a3e3873SBaptiste Daroussin #ifdef HAVE_XDIALOG2 3232a3e3873SBaptiste Daroussin { "buildlist", o_buildlist, 2, "<text> <height> <width> <tag1> <item1> <status1>..." }, 3242a3e3873SBaptiste Daroussin { "no-items", o_no_items, 1, "" }, 3252a3e3873SBaptiste Daroussin { "no-tags", o_no_tags, 1, "" }, 3262a3e3873SBaptiste Daroussin { "rangebox", o_rangebox, 2, "<text> <height> <width> <min-value> <max-value> <default-value>" }, 3272a3e3873SBaptiste Daroussin { "treeview", o_treeview, 2, "<text> <height> <width> <list-height> <tag1> <item1> <status1> <depth1>..." }, 3282a3e3873SBaptiste Daroussin #endif 3292a3e3873SBaptiste Daroussin #if defined(HAVE_XDIALOG2) || defined(HAVE_WHIPTAIL) 3302a3e3873SBaptiste Daroussin { "noitem", o_no_items, 1, NULL }, 3312a3e3873SBaptiste Daroussin { "notags", o_no_tags, 1, NULL }, 3322a3e3873SBaptiste Daroussin #endif 3334c8945a0SNathan Whitehorn #ifdef HAVE_DLG_TRACE 3344c8945a0SNathan Whitehorn { "trace", o_trace, 1, "<file>" }, 3354c8945a0SNathan Whitehorn #endif 3364c8945a0SNathan Whitehorn }; 3374c8945a0SNathan Whitehorn /* *INDENT-ON* */ 3384c8945a0SNathan Whitehorn 3394c8945a0SNathan Whitehorn /* 3404c8945a0SNathan Whitehorn * Make an array showing which argv[] entries are options. Use "--" as a 3414c8945a0SNathan Whitehorn * special token to escape the next argument, allowing it to begin with "--". 3424c8945a0SNathan Whitehorn * When we find a "--" argument, also remove it from argv[] and adjust argc. 3434c8945a0SNathan Whitehorn * That appears to be an undocumented feature of the popt library. 3444c8945a0SNathan Whitehorn * 3454c8945a0SNathan Whitehorn * Also, if we see a "--file", expand it into the parameter list by reading the 3464c8945a0SNathan Whitehorn * text from the given file and stripping quotes, treating whitespace outside 3474c8945a0SNathan Whitehorn * quotes as a parameter delimiter. 3484c8945a0SNathan Whitehorn * 3494c8945a0SNathan Whitehorn * Finally, if we see a "--args", dump the current list of arguments to the 3504c8945a0SNathan Whitehorn * standard error. This is used for debugging complex --file combinations. 3514c8945a0SNathan Whitehorn */ 3524c8945a0SNathan Whitehorn static void 3534c8945a0SNathan Whitehorn unescape_argv(int *argcp, char ***argvp) 3544c8945a0SNathan Whitehorn { 3554c8945a0SNathan Whitehorn int j, k; 3564c8945a0SNathan Whitehorn int limit_includes = 20 + *argcp; 3574c8945a0SNathan Whitehorn int count_includes = 0; 3584c8945a0SNathan Whitehorn bool changed = FALSE; 3594c8945a0SNathan Whitehorn bool doalloc = FALSE; 3604c8945a0SNathan Whitehorn char *filename; 3614c8945a0SNathan Whitehorn 3624c8945a0SNathan Whitehorn dialog_opts = dlg_calloc(bool, (size_t) *argcp + 1); 3634c8945a0SNathan Whitehorn assert_ptr(dialog_opts, "unescape_argv"); 3644c8945a0SNathan Whitehorn 3654c8945a0SNathan Whitehorn for (j = 1; j < *argcp; j++) { 3664c8945a0SNathan Whitehorn bool escaped = FALSE; 3674c8945a0SNathan Whitehorn if (!strcmp((*argvp)[j], "--")) { 3684c8945a0SNathan Whitehorn escaped = TRUE; 3697a1c0d96SNathan Whitehorn changed = dlg_eat_argv(argcp, argvp, j, 1); 3704c8945a0SNathan Whitehorn } else if (!strcmp((*argvp)[j], "--args")) { 3714c8945a0SNathan Whitehorn fprintf(stderr, "Showing arguments at arg%d\n", j); 3724c8945a0SNathan Whitehorn for (k = 0; k < *argcp; ++k) { 3734c8945a0SNathan Whitehorn fprintf(stderr, " arg%d:%s\n", k, (*argvp)[k]); 3744c8945a0SNathan Whitehorn } 3757a1c0d96SNathan Whitehorn changed = dlg_eat_argv(argcp, argvp, j, 1); 3764c8945a0SNathan Whitehorn } else if (!strcmp((*argvp)[j], "--file")) { 3774c8945a0SNathan Whitehorn if (++count_includes > limit_includes) 3784c8945a0SNathan Whitehorn dlg_exiterr("Too many --file options"); 3794c8945a0SNathan Whitehorn 3804c8945a0SNathan Whitehorn if ((filename = (*argvp)[j + 1]) != 0) { 3814c8945a0SNathan Whitehorn FILE *fp; 3824c8945a0SNathan Whitehorn char **list; 3834c8945a0SNathan Whitehorn char *blob; 3844c8945a0SNathan Whitehorn int added; 3854c8945a0SNathan Whitehorn size_t bytes_read; 3864c8945a0SNathan Whitehorn size_t length; 3874c8945a0SNathan Whitehorn int n; 3884c8945a0SNathan Whitehorn 3894c8945a0SNathan Whitehorn if (*filename == '&') { 3904c8945a0SNathan Whitehorn fp = fdopen(atoi(filename + sizeof(char)), "r"); 3914c8945a0SNathan Whitehorn } else { 3924c8945a0SNathan Whitehorn fp = fopen(filename, "r"); 3934c8945a0SNathan Whitehorn } 3944c8945a0SNathan Whitehorn 3954c8945a0SNathan Whitehorn if (fp) { 3964c8945a0SNathan Whitehorn blob = NULL; 3974c8945a0SNathan Whitehorn length = 0; 3984c8945a0SNathan Whitehorn do { 3994c8945a0SNathan Whitehorn blob = dlg_realloc(char, length + BUFSIZ + 1, blob); 4004c8945a0SNathan Whitehorn assert_ptr(blob, "unescape_argv"); 4014c8945a0SNathan Whitehorn bytes_read = fread(blob + length, 4024c8945a0SNathan Whitehorn sizeof(char), 4037a1c0d96SNathan Whitehorn (size_t) BUFSIZ, 4044c8945a0SNathan Whitehorn fp); 4054c8945a0SNathan Whitehorn length += bytes_read; 4064c8945a0SNathan Whitehorn if (ferror(fp)) 4074c8945a0SNathan Whitehorn dlg_exiterr("error on filehandle in unescape_argv"); 4084c8945a0SNathan Whitehorn } while (bytes_read == BUFSIZ); 4094c8945a0SNathan Whitehorn fclose(fp); 4104c8945a0SNathan Whitehorn 4114c8945a0SNathan Whitehorn blob[length] = '\0'; 4124c8945a0SNathan Whitehorn 4137a1c0d96SNathan Whitehorn list = dlg_string_to_argv(blob); 4147a1c0d96SNathan Whitehorn if ((added = dlg_count_argv(list)) != 0) { 4154c8945a0SNathan Whitehorn if (added > 2) { 4164c8945a0SNathan Whitehorn size_t need = (size_t) (*argcp + added + 1); 4174c8945a0SNathan Whitehorn if (doalloc) { 4184c8945a0SNathan Whitehorn *argvp = dlg_realloc(char *, need, *argvp); 4194c8945a0SNathan Whitehorn assert_ptr(*argvp, "unescape_argv"); 4204c8945a0SNathan Whitehorn } else { 4214c8945a0SNathan Whitehorn char **newp = dlg_malloc(char *, need); 4224c8945a0SNathan Whitehorn assert_ptr(newp, "unescape_argv"); 4234c8945a0SNathan Whitehorn for (n = 0; n < *argcp; ++n) { 4244c8945a0SNathan Whitehorn newp[n] = (*argvp)[n]; 4254c8945a0SNathan Whitehorn } 4264c8945a0SNathan Whitehorn *argvp = newp; 4274c8945a0SNathan Whitehorn doalloc = TRUE; 4284c8945a0SNathan Whitehorn } 4294c8945a0SNathan Whitehorn dialog_opts = dlg_realloc(bool, need, dialog_opts); 4304c8945a0SNathan Whitehorn assert_ptr(dialog_opts, "unescape_argv"); 4314c8945a0SNathan Whitehorn } 4324c8945a0SNathan Whitehorn for (n = *argcp; n >= j + 2; --n) { 4334c8945a0SNathan Whitehorn (*argvp)[n + added - 2] = (*argvp)[n]; 4344c8945a0SNathan Whitehorn dialog_opts[n + added - 2] = dialog_opts[n]; 4354c8945a0SNathan Whitehorn } 4364c8945a0SNathan Whitehorn for (n = 0; n < added; ++n) { 4374c8945a0SNathan Whitehorn (*argvp)[n + j] = list[n]; 4384c8945a0SNathan Whitehorn dialog_opts[n + j] = FALSE; 4394c8945a0SNathan Whitehorn } 4404c8945a0SNathan Whitehorn *argcp += added - 2; 4414c8945a0SNathan Whitehorn free(list); 4424c8945a0SNathan Whitehorn } 4434c8945a0SNathan Whitehorn } else { 4444c8945a0SNathan Whitehorn dlg_exiterr("Cannot open --file %s", filename); 4454c8945a0SNathan Whitehorn } 4464c8945a0SNathan Whitehorn (*argvp)[*argcp] = 0; 4474c8945a0SNathan Whitehorn ++j; 4484c8945a0SNathan Whitehorn continue; 4494c8945a0SNathan Whitehorn } else { 4504c8945a0SNathan Whitehorn dlg_exiterr("No value given for --file"); 4514c8945a0SNathan Whitehorn } 4524c8945a0SNathan Whitehorn } 4534c8945a0SNathan Whitehorn if (!escaped 4544c8945a0SNathan Whitehorn && (*argvp)[j] != 0 4557a1c0d96SNathan Whitehorn && !strncmp((*argvp)[j], "--", (size_t) 2) 4564c8945a0SNathan Whitehorn && isalpha(UCH((*argvp)[j][2]))) { 4574c8945a0SNathan Whitehorn dialog_opts[j] = TRUE; 4584c8945a0SNathan Whitehorn } 4594c8945a0SNathan Whitehorn } 4604c8945a0SNathan Whitehorn 4614c8945a0SNathan Whitehorn /* if we didn't find any "--" tokens, there's no reason to do the table 4624c8945a0SNathan Whitehorn * lookup in isOption() 4634c8945a0SNathan Whitehorn */ 4644c8945a0SNathan Whitehorn if (!changed) { 4654c8945a0SNathan Whitehorn free(dialog_opts); 4664c8945a0SNathan Whitehorn dialog_opts = 0; 4674c8945a0SNathan Whitehorn } 4684c8945a0SNathan Whitehorn dialog_argv = (*argvp); 4694c8945a0SNathan Whitehorn } 4704c8945a0SNathan Whitehorn 4712a3e3873SBaptiste Daroussin #define OptionChars "\ 4722a3e3873SBaptiste Daroussin 0123456789\ 4732a3e3873SBaptiste Daroussin -\ 4742a3e3873SBaptiste Daroussin abcdefghijklmnopqrstuvwxyz\ 4752a3e3873SBaptiste Daroussin " 4762a3e3873SBaptiste Daroussin 4774c8945a0SNathan Whitehorn /* 4784c8945a0SNathan Whitehorn * Check if the given string from main's argv is an option. 4794c8945a0SNathan Whitehorn */ 4804c8945a0SNathan Whitehorn static bool 4814c8945a0SNathan Whitehorn isOption(const char *arg) 4824c8945a0SNathan Whitehorn { 4834c8945a0SNathan Whitehorn bool result = FALSE; 4844c8945a0SNathan Whitehorn 4854c8945a0SNathan Whitehorn if (arg != 0) { 4864c8945a0SNathan Whitehorn if (dialog_opts != 0) { 4874c8945a0SNathan Whitehorn int n; 4884c8945a0SNathan Whitehorn for (n = 1; dialog_argv[n] != 0; ++n) { 4894c8945a0SNathan Whitehorn if (dialog_argv[n] == arg) { 4904c8945a0SNathan Whitehorn result = dialog_opts[n]; 4914c8945a0SNathan Whitehorn break; 4924c8945a0SNathan Whitehorn } 4934c8945a0SNathan Whitehorn } 4947a1c0d96SNathan Whitehorn } else if (!strncmp(arg, "--", (size_t) 2) && isalpha(UCH(arg[2]))) { 4952a3e3873SBaptiste Daroussin if (strlen(arg) == strspn(arg, OptionChars)) { 4964c8945a0SNathan Whitehorn result = TRUE; 4972a3e3873SBaptiste Daroussin } else { 4982a3e3873SBaptiste Daroussin dlg_exiterr("Invalid option \"%s\"", arg); 4992a3e3873SBaptiste Daroussin } 5004c8945a0SNathan Whitehorn } 5014c8945a0SNathan Whitehorn } 5024c8945a0SNathan Whitehorn return result; 5034c8945a0SNathan Whitehorn } 5044c8945a0SNathan Whitehorn 5054c8945a0SNathan Whitehorn static eOptions 5064c8945a0SNathan Whitehorn lookupOption(const char *name, int pass) 5074c8945a0SNathan Whitehorn { 5084c8945a0SNathan Whitehorn unsigned n; 5092a3e3873SBaptiste Daroussin eOptions result = o_unknown; 5104c8945a0SNathan Whitehorn 5114c8945a0SNathan Whitehorn if (isOption(name)) { 5124c8945a0SNathan Whitehorn name += 2; 5134c8945a0SNathan Whitehorn for (n = 0; n < sizeof(options) / sizeof(options[0]); n++) { 5144c8945a0SNathan Whitehorn if ((pass & options[n].pass) != 0 5154c8945a0SNathan Whitehorn && !strcmp(name, options[n].name)) { 5162a3e3873SBaptiste Daroussin result = options[n].code; 5172a3e3873SBaptiste Daroussin break; 5184c8945a0SNathan Whitehorn } 5194c8945a0SNathan Whitehorn } 5204c8945a0SNathan Whitehorn } 5212a3e3873SBaptiste Daroussin return result; 5224c8945a0SNathan Whitehorn } 5234c8945a0SNathan Whitehorn 5244c8945a0SNathan Whitehorn static void 5254c8945a0SNathan Whitehorn Usage(const char *msg) 5264c8945a0SNathan Whitehorn { 5274c8945a0SNathan Whitehorn dlg_exiterr("Error: %s.\nUse --help to list options.\n\n", msg); 5284c8945a0SNathan Whitehorn } 5294c8945a0SNathan Whitehorn 5304c8945a0SNathan Whitehorn /* 5314c8945a0SNathan Whitehorn * Count arguments, stopping at the end of the argument list, or on any of our 5324c8945a0SNathan Whitehorn * "--" tokens. 5334c8945a0SNathan Whitehorn */ 5344c8945a0SNathan Whitehorn static int 5354c8945a0SNathan Whitehorn arg_rest(char *argv[]) 5364c8945a0SNathan Whitehorn { 5374c8945a0SNathan Whitehorn int i = 1; /* argv[0] points to a "--" token */ 5384c8945a0SNathan Whitehorn 5394c8945a0SNathan Whitehorn while (argv[i] != 0 5404c8945a0SNathan Whitehorn && (!isOption(argv[i]) || lookupOption(argv[i], 7) == o_unknown)) 5414c8945a0SNathan Whitehorn i++; 5424c8945a0SNathan Whitehorn return i; 5434c8945a0SNathan Whitehorn } 5444c8945a0SNathan Whitehorn 5454c8945a0SNathan Whitehorn /* 5464c8945a0SNathan Whitehorn * In MultiWidget this function is needed to count how many tags 5474c8945a0SNathan Whitehorn * a widget (menu, checklist, radiolist) has 5484c8945a0SNathan Whitehorn */ 5494c8945a0SNathan Whitehorn static int 5504c8945a0SNathan Whitehorn howmany_tags(char *argv[], int group) 5514c8945a0SNathan Whitehorn { 5524c8945a0SNathan Whitehorn int result = 0; 5534c8945a0SNathan Whitehorn int have; 5544c8945a0SNathan Whitehorn const char *format = "Expected %d arguments, found only %d"; 5554c8945a0SNathan Whitehorn char temp[80]; 5564c8945a0SNathan Whitehorn 5574c8945a0SNathan Whitehorn while (argv[0] != 0) { 5584c8945a0SNathan Whitehorn if (isOption(argv[0])) 5594c8945a0SNathan Whitehorn break; 5604c8945a0SNathan Whitehorn if ((have = arg_rest(argv)) < group) { 5614c8945a0SNathan Whitehorn sprintf(temp, format, group, have); 5624c8945a0SNathan Whitehorn Usage(temp); 5634c8945a0SNathan Whitehorn } 5644c8945a0SNathan Whitehorn 5654c8945a0SNathan Whitehorn argv += group; 5664c8945a0SNathan Whitehorn result++; 5674c8945a0SNathan Whitehorn } 5684c8945a0SNathan Whitehorn 5694c8945a0SNathan Whitehorn return result; 5704c8945a0SNathan Whitehorn } 5714c8945a0SNathan Whitehorn 5724c8945a0SNathan Whitehorn static int 5734c8945a0SNathan Whitehorn numeric_arg(char **av, int n) 5744c8945a0SNathan Whitehorn { 5752a3e3873SBaptiste Daroussin int result = 0; 5762a3e3873SBaptiste Daroussin 5772a3e3873SBaptiste Daroussin if (n < dlg_count_argv(av)) { 5784c8945a0SNathan Whitehorn char msg[80]; 5792a3e3873SBaptiste Daroussin char *last = 0; 5802a3e3873SBaptiste Daroussin result = (int) strtol(av[n], &last, 10); 5814c8945a0SNathan Whitehorn 5824c8945a0SNathan Whitehorn if (last == 0 || *last != 0) { 5834c8945a0SNathan Whitehorn sprintf(msg, "Expected a number for token %d of %.20s", n, av[0]); 5844c8945a0SNathan Whitehorn Usage(msg); 5854c8945a0SNathan Whitehorn } 5862a3e3873SBaptiste Daroussin } 5874c8945a0SNathan Whitehorn return result; 5884c8945a0SNathan Whitehorn } 5894c8945a0SNathan Whitehorn 5904c8945a0SNathan Whitehorn static char * 5914c8945a0SNathan Whitehorn optional_str(char **av, int n, char *dft) 5924c8945a0SNathan Whitehorn { 5934c8945a0SNathan Whitehorn char *ret = dft; 5944c8945a0SNathan Whitehorn if (arg_rest(av) > n) 5954c8945a0SNathan Whitehorn ret = av[n]; 5964c8945a0SNathan Whitehorn return ret; 5974c8945a0SNathan Whitehorn } 5984c8945a0SNathan Whitehorn 5994c8945a0SNathan Whitehorn #if defined(HAVE_DLG_GAUGE) || defined(HAVE_XDIALOG) 6004c8945a0SNathan Whitehorn static int 6014c8945a0SNathan Whitehorn optional_num(char **av, int n, int dft) 6024c8945a0SNathan Whitehorn { 6034c8945a0SNathan Whitehorn int ret = dft; 6044c8945a0SNathan Whitehorn if (arg_rest(av) > n) 6054c8945a0SNathan Whitehorn ret = numeric_arg(av, n); 6064c8945a0SNathan Whitehorn return ret; 6074c8945a0SNathan Whitehorn } 6084c8945a0SNathan Whitehorn #endif 6094c8945a0SNathan Whitehorn 6104c8945a0SNathan Whitehorn /* 6114c8945a0SNathan Whitehorn * On AIX 4.x, we have to flush the output right away since there is a bug in 6124c8945a0SNathan Whitehorn * the curses package which discards stdout even when we've used newterm to 6134c8945a0SNathan Whitehorn * redirect output to /dev/tty. 6144c8945a0SNathan Whitehorn */ 6154c8945a0SNathan Whitehorn static int 6164c8945a0SNathan Whitehorn show_result(int ret) 6174c8945a0SNathan Whitehorn { 6184c8945a0SNathan Whitehorn bool either = FALSE; 6194c8945a0SNathan Whitehorn 6204c8945a0SNathan Whitehorn switch (ret) { 6214c8945a0SNathan Whitehorn case DLG_EXIT_OK: 6224c8945a0SNathan Whitehorn case DLG_EXIT_EXTRA: 6234c8945a0SNathan Whitehorn case DLG_EXIT_HELP: 6244c8945a0SNathan Whitehorn case DLG_EXIT_ITEM_HELP: 6254c8945a0SNathan Whitehorn if ((dialog_state.output_count > 1) && !dialog_vars.separate_output) { 6264c8945a0SNathan Whitehorn fputs((dialog_state.separate_str 6274c8945a0SNathan Whitehorn ? dialog_state.separate_str 6284c8945a0SNathan Whitehorn : DEFAULT_SEPARATE_STR), 6294c8945a0SNathan Whitehorn dialog_state.output); 6304c8945a0SNathan Whitehorn either = TRUE; 6314c8945a0SNathan Whitehorn } 6327a1c0d96SNathan Whitehorn if (dialog_vars.input_result != 0 6337a1c0d96SNathan Whitehorn && dialog_vars.input_result[0] != '\0') { 6344c8945a0SNathan Whitehorn fputs(dialog_vars.input_result, dialog_state.output); 6354c8945a0SNathan Whitehorn either = TRUE; 6364c8945a0SNathan Whitehorn } 6374c8945a0SNathan Whitehorn if (either) { 6384c8945a0SNathan Whitehorn fflush(dialog_state.output); 6394c8945a0SNathan Whitehorn } 6404c8945a0SNathan Whitehorn break; 6414c8945a0SNathan Whitehorn } 6424c8945a0SNathan Whitehorn return ret; 6434c8945a0SNathan Whitehorn } 6444c8945a0SNathan Whitehorn 6454c8945a0SNathan Whitehorn /* 6464c8945a0SNathan Whitehorn * These are the widget callers. 6474c8945a0SNathan Whitehorn */ 6484c8945a0SNathan Whitehorn 6494c8945a0SNathan Whitehorn static int 6504c8945a0SNathan Whitehorn call_yesno(CALLARGS) 6514c8945a0SNathan Whitehorn { 6524c8945a0SNathan Whitehorn *offset_add = 4; 6534c8945a0SNathan Whitehorn return dialog_yesno(t, 6544c8945a0SNathan Whitehorn av[1], 6554c8945a0SNathan Whitehorn numeric_arg(av, 2), 6564c8945a0SNathan Whitehorn numeric_arg(av, 3)); 6574c8945a0SNathan Whitehorn } 6584c8945a0SNathan Whitehorn 6594c8945a0SNathan Whitehorn static int 6604c8945a0SNathan Whitehorn call_msgbox(CALLARGS) 6614c8945a0SNathan Whitehorn { 6624c8945a0SNathan Whitehorn *offset_add = 4; 6634c8945a0SNathan Whitehorn return dialog_msgbox(t, 6644c8945a0SNathan Whitehorn av[1], 6654c8945a0SNathan Whitehorn numeric_arg(av, 2), 6664c8945a0SNathan Whitehorn numeric_arg(av, 3), 1); 6674c8945a0SNathan Whitehorn } 6684c8945a0SNathan Whitehorn 6694c8945a0SNathan Whitehorn static int 6704c8945a0SNathan Whitehorn call_infobox(CALLARGS) 6714c8945a0SNathan Whitehorn { 6724c8945a0SNathan Whitehorn *offset_add = 4; 6734c8945a0SNathan Whitehorn return dialog_msgbox(t, 6744c8945a0SNathan Whitehorn av[1], 6754c8945a0SNathan Whitehorn numeric_arg(av, 2), 6764c8945a0SNathan Whitehorn numeric_arg(av, 3), 0); 6774c8945a0SNathan Whitehorn } 6784c8945a0SNathan Whitehorn 6794c8945a0SNathan Whitehorn static int 6804c8945a0SNathan Whitehorn call_textbox(CALLARGS) 6814c8945a0SNathan Whitehorn { 6824c8945a0SNathan Whitehorn *offset_add = 4; 6834c8945a0SNathan Whitehorn return dialog_textbox(t, 6844c8945a0SNathan Whitehorn av[1], 6854c8945a0SNathan Whitehorn numeric_arg(av, 2), 6864c8945a0SNathan Whitehorn numeric_arg(av, 3)); 6874c8945a0SNathan Whitehorn } 6884c8945a0SNathan Whitehorn 6894c8945a0SNathan Whitehorn static int 6904c8945a0SNathan Whitehorn call_menu(CALLARGS) 6914c8945a0SNathan Whitehorn { 6924c8945a0SNathan Whitehorn int tags = howmany_tags(av + 5, MENUBOX_TAGS); 6934c8945a0SNathan Whitehorn *offset_add = 5 + tags * MENUBOX_TAGS; 6944c8945a0SNathan Whitehorn 6954c8945a0SNathan Whitehorn return dialog_menu(t, 6964c8945a0SNathan Whitehorn av[1], 6974c8945a0SNathan Whitehorn numeric_arg(av, 2), 6984c8945a0SNathan Whitehorn numeric_arg(av, 3), 6994c8945a0SNathan Whitehorn numeric_arg(av, 4), 7004c8945a0SNathan Whitehorn tags, av + 5); 7014c8945a0SNathan Whitehorn } 7024c8945a0SNathan Whitehorn 7034c8945a0SNathan Whitehorn static int 7044c8945a0SNathan Whitehorn call_inputmenu(CALLARGS) 7054c8945a0SNathan Whitehorn { 7064c8945a0SNathan Whitehorn int tags = howmany_tags(av + 5, MENUBOX_TAGS); 7077a1c0d96SNathan Whitehorn bool free_extra_label = FALSE; 7087a1c0d96SNathan Whitehorn int result; 7094c8945a0SNathan Whitehorn 7104c8945a0SNathan Whitehorn dialog_vars.input_menu = TRUE; 7114c8945a0SNathan Whitehorn 7124c8945a0SNathan Whitehorn if (dialog_vars.max_input == 0) 7134c8945a0SNathan Whitehorn dialog_vars.max_input = MAX_LEN / 2; 7144c8945a0SNathan Whitehorn 7157a1c0d96SNathan Whitehorn if (dialog_vars.extra_label == 0) { 7167a1c0d96SNathan Whitehorn free_extra_label = TRUE; 7177a1c0d96SNathan Whitehorn dialog_vars.extra_label = dlg_strclone(_("Rename")); 7187a1c0d96SNathan Whitehorn } 7194c8945a0SNathan Whitehorn 7204c8945a0SNathan Whitehorn dialog_vars.extra_button = TRUE; 7214c8945a0SNathan Whitehorn 7224c8945a0SNathan Whitehorn *offset_add = 5 + tags * MENUBOX_TAGS; 7237a1c0d96SNathan Whitehorn result = dialog_menu(t, 7244c8945a0SNathan Whitehorn av[1], 7254c8945a0SNathan Whitehorn numeric_arg(av, 2), 7264c8945a0SNathan Whitehorn numeric_arg(av, 3), 7274c8945a0SNathan Whitehorn numeric_arg(av, 4), 7284c8945a0SNathan Whitehorn tags, av + 5); 7297a1c0d96SNathan Whitehorn if (free_extra_label) { 7307a1c0d96SNathan Whitehorn free(dialog_vars.extra_label); 7317a1c0d96SNathan Whitehorn dialog_vars.extra_label = 0; 7327a1c0d96SNathan Whitehorn } 7337a1c0d96SNathan Whitehorn return result; 7344c8945a0SNathan Whitehorn } 7354c8945a0SNathan Whitehorn 7364c8945a0SNathan Whitehorn static int 7374c8945a0SNathan Whitehorn call_checklist(CALLARGS) 7384c8945a0SNathan Whitehorn { 7394c8945a0SNathan Whitehorn int tags = howmany_tags(av + 5, CHECKBOX_TAGS); 7404c8945a0SNathan Whitehorn int code; 7414c8945a0SNathan Whitehorn 7424c8945a0SNathan Whitehorn *offset_add = 5 + tags * CHECKBOX_TAGS; 7434c8945a0SNathan Whitehorn code = dialog_checklist(t, 7444c8945a0SNathan Whitehorn av[1], 7454c8945a0SNathan Whitehorn numeric_arg(av, 2), 7464c8945a0SNathan Whitehorn numeric_arg(av, 3), 7474c8945a0SNathan Whitehorn numeric_arg(av, 4), 7484c8945a0SNathan Whitehorn tags, av + 5, FLAG_CHECK); 7494c8945a0SNathan Whitehorn return code; 7504c8945a0SNathan Whitehorn } 7514c8945a0SNathan Whitehorn 7524c8945a0SNathan Whitehorn static int 7534c8945a0SNathan Whitehorn call_radiolist(CALLARGS) 7544c8945a0SNathan Whitehorn { 7554c8945a0SNathan Whitehorn int tags = howmany_tags(av + 5, CHECKBOX_TAGS); 7564c8945a0SNathan Whitehorn *offset_add = 5 + tags * CHECKBOX_TAGS; 7574c8945a0SNathan Whitehorn return dialog_checklist(t, 7584c8945a0SNathan Whitehorn av[1], 7594c8945a0SNathan Whitehorn numeric_arg(av, 2), 7604c8945a0SNathan Whitehorn numeric_arg(av, 3), 7614c8945a0SNathan Whitehorn numeric_arg(av, 4), 7624c8945a0SNathan Whitehorn tags, av + 5, FLAG_RADIO); 7634c8945a0SNathan Whitehorn } 7644c8945a0SNathan Whitehorn 7654c8945a0SNathan Whitehorn static int 7664c8945a0SNathan Whitehorn call_inputbox(CALLARGS) 7674c8945a0SNathan Whitehorn { 7684c8945a0SNathan Whitehorn *offset_add = arg_rest(av); 7694c8945a0SNathan Whitehorn return dialog_inputbox(t, 7704c8945a0SNathan Whitehorn av[1], 7714c8945a0SNathan Whitehorn numeric_arg(av, 2), 7724c8945a0SNathan Whitehorn numeric_arg(av, 3), 7734c8945a0SNathan Whitehorn optional_str(av, 4, 0), 0); 7744c8945a0SNathan Whitehorn } 7754c8945a0SNathan Whitehorn 7764c8945a0SNathan Whitehorn static int 7774c8945a0SNathan Whitehorn call_passwordbox(CALLARGS) 7784c8945a0SNathan Whitehorn { 7794c8945a0SNathan Whitehorn *offset_add = arg_rest(av); 7804c8945a0SNathan Whitehorn return dialog_inputbox(t, 7814c8945a0SNathan Whitehorn av[1], 7824c8945a0SNathan Whitehorn numeric_arg(av, 2), 7834c8945a0SNathan Whitehorn numeric_arg(av, 3), 7844c8945a0SNathan Whitehorn optional_str(av, 4, 0), 1); 7854c8945a0SNathan Whitehorn } 7864c8945a0SNathan Whitehorn 7874c8945a0SNathan Whitehorn #ifdef HAVE_XDIALOG 7884c8945a0SNathan Whitehorn static int 7894c8945a0SNathan Whitehorn call_calendar(CALLARGS) 7904c8945a0SNathan Whitehorn { 7914c8945a0SNathan Whitehorn *offset_add = arg_rest(av); 7924c8945a0SNathan Whitehorn return dialog_calendar(t, 7934c8945a0SNathan Whitehorn av[1], 7944c8945a0SNathan Whitehorn numeric_arg(av, 2), 7954c8945a0SNathan Whitehorn numeric_arg(av, 3), 7964c8945a0SNathan Whitehorn optional_num(av, 4, -1), 7974c8945a0SNathan Whitehorn optional_num(av, 5, -1), 7984c8945a0SNathan Whitehorn optional_num(av, 6, -1)); 7994c8945a0SNathan Whitehorn } 8004c8945a0SNathan Whitehorn 8014c8945a0SNathan Whitehorn static int 8024c8945a0SNathan Whitehorn call_dselect(CALLARGS) 8034c8945a0SNathan Whitehorn { 8044c8945a0SNathan Whitehorn *offset_add = arg_rest(av); 8054c8945a0SNathan Whitehorn return dialog_dselect(t, 8064c8945a0SNathan Whitehorn av[1], 8074c8945a0SNathan Whitehorn numeric_arg(av, 2), 8084c8945a0SNathan Whitehorn numeric_arg(av, 3)); 8094c8945a0SNathan Whitehorn } 8104c8945a0SNathan Whitehorn 8114c8945a0SNathan Whitehorn static int 8124c8945a0SNathan Whitehorn call_editbox(CALLARGS) 8134c8945a0SNathan Whitehorn { 8144c8945a0SNathan Whitehorn *offset_add = 4; 8154c8945a0SNathan Whitehorn return dialog_editbox(t, 8164c8945a0SNathan Whitehorn av[1], 8174c8945a0SNathan Whitehorn numeric_arg(av, 2), 8184c8945a0SNathan Whitehorn numeric_arg(av, 3)); 8194c8945a0SNathan Whitehorn } 8204c8945a0SNathan Whitehorn 8214c8945a0SNathan Whitehorn static int 8224c8945a0SNathan Whitehorn call_fselect(CALLARGS) 8234c8945a0SNathan Whitehorn { 8244c8945a0SNathan Whitehorn *offset_add = arg_rest(av); 8254c8945a0SNathan Whitehorn return dialog_fselect(t, 8264c8945a0SNathan Whitehorn av[1], 8274c8945a0SNathan Whitehorn numeric_arg(av, 2), 8284c8945a0SNathan Whitehorn numeric_arg(av, 3)); 8294c8945a0SNathan Whitehorn } 8304c8945a0SNathan Whitehorn 8314c8945a0SNathan Whitehorn static int 8324c8945a0SNathan Whitehorn call_timebox(CALLARGS) 8334c8945a0SNathan Whitehorn { 8344c8945a0SNathan Whitehorn *offset_add = arg_rest(av); 8354c8945a0SNathan Whitehorn return dialog_timebox(t, 8364c8945a0SNathan Whitehorn av[1], 8374c8945a0SNathan Whitehorn numeric_arg(av, 2), 8384c8945a0SNathan Whitehorn numeric_arg(av, 3), 8394c8945a0SNathan Whitehorn optional_num(av, 4, -1), 8404c8945a0SNathan Whitehorn optional_num(av, 5, -1), 8414c8945a0SNathan Whitehorn optional_num(av, 6, -1)); 8424c8945a0SNathan Whitehorn } 8434c8945a0SNathan Whitehorn #endif /* HAVE_XDIALOG */ 8444c8945a0SNathan Whitehorn 8452a3e3873SBaptiste Daroussin /* dialog 1.2 widgets */ 8462a3e3873SBaptiste Daroussin #ifdef HAVE_XDIALOG2 8472a3e3873SBaptiste Daroussin 8482a3e3873SBaptiste Daroussin #define DisableNoTags() \ 8492a3e3873SBaptiste Daroussin bool save_no_tags = dialog_vars.no_tags; \ 8502a3e3873SBaptiste Daroussin bool save_no_items = dialog_vars.no_items; \ 8512a3e3873SBaptiste Daroussin dialog_vars.no_tags = TRUE; \ 8522a3e3873SBaptiste Daroussin dialog_vars.no_items = FALSE 8532a3e3873SBaptiste Daroussin 8542a3e3873SBaptiste Daroussin #define RestoreNoTags() \ 8552a3e3873SBaptiste Daroussin dialog_vars.no_tags = save_no_tags; \ 8562a3e3873SBaptiste Daroussin dialog_vars.no_items = save_no_items 8572a3e3873SBaptiste Daroussin 8582a3e3873SBaptiste Daroussin static int 8592a3e3873SBaptiste Daroussin call_buildlist(CALLARGS) 8602a3e3873SBaptiste Daroussin { 8612a3e3873SBaptiste Daroussin int tags = howmany_tags(av + 5, CHECKBOX_TAGS); 8622a3e3873SBaptiste Daroussin int result; 8632a3e3873SBaptiste Daroussin 8642a3e3873SBaptiste Daroussin DisableNoTags(); 8652a3e3873SBaptiste Daroussin 8662a3e3873SBaptiste Daroussin *offset_add = 5 + tags * CHECKBOX_TAGS; 8672a3e3873SBaptiste Daroussin result = dialog_buildlist(t, 8682a3e3873SBaptiste Daroussin av[1], 8692a3e3873SBaptiste Daroussin numeric_arg(av, 2), 8702a3e3873SBaptiste Daroussin numeric_arg(av, 3), 8712a3e3873SBaptiste Daroussin numeric_arg(av, 4), 8722a3e3873SBaptiste Daroussin tags, av + 5, 8732a3e3873SBaptiste Daroussin TRUE); 8742a3e3873SBaptiste Daroussin RestoreNoTags(); 8752a3e3873SBaptiste Daroussin return result; 8762a3e3873SBaptiste Daroussin } 8772a3e3873SBaptiste Daroussin 8782a3e3873SBaptiste Daroussin static int 8792a3e3873SBaptiste Daroussin call_rangebox(CALLARGS) 8802a3e3873SBaptiste Daroussin { 8812a3e3873SBaptiste Daroussin int min_value; 8822a3e3873SBaptiste Daroussin 8832a3e3873SBaptiste Daroussin *offset_add = arg_rest(av); 8842a3e3873SBaptiste Daroussin min_value = numeric_arg(av, 4); 8852a3e3873SBaptiste Daroussin return dialog_rangebox(t, 8862a3e3873SBaptiste Daroussin av[1], 8872a3e3873SBaptiste Daroussin numeric_arg(av, 2), 8882a3e3873SBaptiste Daroussin numeric_arg(av, 3), 8892a3e3873SBaptiste Daroussin min_value, 8902a3e3873SBaptiste Daroussin numeric_arg(av, 5), 8912a3e3873SBaptiste Daroussin (*offset_add > 6) ? numeric_arg(av, 6) : min_value); 8922a3e3873SBaptiste Daroussin } 8932a3e3873SBaptiste Daroussin 8942a3e3873SBaptiste Daroussin static int 8952a3e3873SBaptiste Daroussin call_treeview(CALLARGS) 8962a3e3873SBaptiste Daroussin { 8972a3e3873SBaptiste Daroussin int tags = howmany_tags(av + 5, TREEVIEW_TAGS); 8982a3e3873SBaptiste Daroussin int result; 8992a3e3873SBaptiste Daroussin 9002a3e3873SBaptiste Daroussin DisableNoTags(); 9012a3e3873SBaptiste Daroussin 9022a3e3873SBaptiste Daroussin *offset_add = arg_rest(av); 9032a3e3873SBaptiste Daroussin result = dialog_treeview(t, 9042a3e3873SBaptiste Daroussin av[1], 9052a3e3873SBaptiste Daroussin numeric_arg(av, 2), 9062a3e3873SBaptiste Daroussin numeric_arg(av, 3), 9072a3e3873SBaptiste Daroussin numeric_arg(av, 4), 9082a3e3873SBaptiste Daroussin tags, av + 5, FLAG_RADIO); 9092a3e3873SBaptiste Daroussin RestoreNoTags(); 9102a3e3873SBaptiste Daroussin return result; 9112a3e3873SBaptiste Daroussin } 9122a3e3873SBaptiste Daroussin #endif /* HAVE_XDIALOG */ 9132a3e3873SBaptiste Daroussin 9144c8945a0SNathan Whitehorn #ifdef HAVE_DLG_FORMBOX 9154c8945a0SNathan Whitehorn static int 9164c8945a0SNathan Whitehorn call_form(CALLARGS) 9174c8945a0SNathan Whitehorn { 9184c8945a0SNathan Whitehorn int group = FORMBOX_TAGS; 9194c8945a0SNathan Whitehorn int tags = howmany_tags(av + 5, group); 9204c8945a0SNathan Whitehorn *offset_add = 5 + tags * group; 9214c8945a0SNathan Whitehorn 9224c8945a0SNathan Whitehorn return dialog_form(t, 9234c8945a0SNathan Whitehorn av[1], 9244c8945a0SNathan Whitehorn numeric_arg(av, 2), 9254c8945a0SNathan Whitehorn numeric_arg(av, 3), 9264c8945a0SNathan Whitehorn numeric_arg(av, 4), 9274c8945a0SNathan Whitehorn tags, av + 5); 9284c8945a0SNathan Whitehorn } 9294c8945a0SNathan Whitehorn 9304c8945a0SNathan Whitehorn static int 9314c8945a0SNathan Whitehorn call_password_form(CALLARGS) 9324c8945a0SNathan Whitehorn { 9334c8945a0SNathan Whitehorn unsigned save = dialog_vars.formitem_type; 9344c8945a0SNathan Whitehorn int result; 9354c8945a0SNathan Whitehorn 9364c8945a0SNathan Whitehorn dialog_vars.formitem_type = 1; 9374c8945a0SNathan Whitehorn result = call_form(PASSARGS); 9384c8945a0SNathan Whitehorn dialog_vars.formitem_type = save; 9394c8945a0SNathan Whitehorn 9404c8945a0SNathan Whitehorn return result; 9414c8945a0SNathan Whitehorn } 9424c8945a0SNathan Whitehorn #endif /* HAVE_DLG_FORMBOX */ 9434c8945a0SNathan Whitehorn 9444c8945a0SNathan Whitehorn #ifdef HAVE_DLG_MIXEDFORM 9454c8945a0SNathan Whitehorn static int 9464c8945a0SNathan Whitehorn call_mixed_form(CALLARGS) 9474c8945a0SNathan Whitehorn { 9484c8945a0SNathan Whitehorn int group = MIXEDFORM_TAGS; 9494c8945a0SNathan Whitehorn int tags = howmany_tags(av + 5, group); 9504c8945a0SNathan Whitehorn *offset_add = 5 + tags * group; 9514c8945a0SNathan Whitehorn 9524c8945a0SNathan Whitehorn return dialog_mixedform(t, 9534c8945a0SNathan Whitehorn av[1], 9544c8945a0SNathan Whitehorn numeric_arg(av, 2), 9554c8945a0SNathan Whitehorn numeric_arg(av, 3), 9564c8945a0SNathan Whitehorn numeric_arg(av, 4), 9574c8945a0SNathan Whitehorn tags, av + 5); 9584c8945a0SNathan Whitehorn } 9594c8945a0SNathan Whitehorn #endif /* HAVE_DLG_MIXEDFORM */ 9604c8945a0SNathan Whitehorn 9614c8945a0SNathan Whitehorn #ifdef HAVE_DLG_GAUGE 9624c8945a0SNathan Whitehorn static int 9634c8945a0SNathan Whitehorn call_gauge(CALLARGS) 9644c8945a0SNathan Whitehorn { 9654c8945a0SNathan Whitehorn *offset_add = arg_rest(av); 9664c8945a0SNathan Whitehorn return dialog_gauge(t, 9674c8945a0SNathan Whitehorn av[1], 9684c8945a0SNathan Whitehorn numeric_arg(av, 2), 9694c8945a0SNathan Whitehorn numeric_arg(av, 3), 9704c8945a0SNathan Whitehorn optional_num(av, 4, 0)); 9714c8945a0SNathan Whitehorn } 9724c8945a0SNathan Whitehorn 9734c8945a0SNathan Whitehorn static int 9744c8945a0SNathan Whitehorn call_pause(CALLARGS) 9754c8945a0SNathan Whitehorn { 9764c8945a0SNathan Whitehorn *offset_add = arg_rest(av); 9774c8945a0SNathan Whitehorn return dialog_pause(t, 9784c8945a0SNathan Whitehorn av[1], 9794c8945a0SNathan Whitehorn numeric_arg(av, 2), 9804c8945a0SNathan Whitehorn numeric_arg(av, 3), 9814c8945a0SNathan Whitehorn numeric_arg(av, 4)); 9824c8945a0SNathan Whitehorn } 9834c8945a0SNathan Whitehorn #endif 9844c8945a0SNathan Whitehorn 9854c8945a0SNathan Whitehorn #ifdef HAVE_MIXEDGAUGE 9864c8945a0SNathan Whitehorn static int 9874c8945a0SNathan Whitehorn call_mixed_gauge(CALLARGS) 9884c8945a0SNathan Whitehorn { 9894c8945a0SNathan Whitehorn #define MIXEDGAUGE_BASE 5 9904c8945a0SNathan Whitehorn int tags = howmany_tags(av + MIXEDGAUGE_BASE, MIXEDGAUGE_TAGS); 9914c8945a0SNathan Whitehorn *offset_add = MIXEDGAUGE_BASE + tags * MIXEDGAUGE_TAGS; 9924c8945a0SNathan Whitehorn return dialog_mixedgauge(t, 9934c8945a0SNathan Whitehorn av[1], 9944c8945a0SNathan Whitehorn numeric_arg(av, 2), 9954c8945a0SNathan Whitehorn numeric_arg(av, 3), 9964c8945a0SNathan Whitehorn numeric_arg(av, 4), 9974c8945a0SNathan Whitehorn tags, av + MIXEDGAUGE_BASE); 9984c8945a0SNathan Whitehorn } 9994c8945a0SNathan Whitehorn #endif 10004c8945a0SNathan Whitehorn 1001682c9e0fSNathan Whitehorn #ifdef HAVE_DLG_GAUGE 10027a1c0d96SNathan Whitehorn static int 10037a1c0d96SNathan Whitehorn call_prgbox(CALLARGS) 10047a1c0d96SNathan Whitehorn { 10057a1c0d96SNathan Whitehorn *offset_add = arg_rest(av); 10067a1c0d96SNathan Whitehorn /* the original version does not accept a prompt string, but for 10077a1c0d96SNathan Whitehorn * consistency we allow it. 10087a1c0d96SNathan Whitehorn */ 10097a1c0d96SNathan Whitehorn return ((*offset_add == 5) 10107a1c0d96SNathan Whitehorn ? dialog_prgbox(t, 10117a1c0d96SNathan Whitehorn av[1], 10127a1c0d96SNathan Whitehorn av[2], 10137a1c0d96SNathan Whitehorn numeric_arg(av, 3), 10147a1c0d96SNathan Whitehorn numeric_arg(av, 4), TRUE) 10157a1c0d96SNathan Whitehorn : dialog_prgbox(t, 10167a1c0d96SNathan Whitehorn "", 10177a1c0d96SNathan Whitehorn av[1], 10187a1c0d96SNathan Whitehorn numeric_arg(av, 2), 10197a1c0d96SNathan Whitehorn numeric_arg(av, 3), TRUE)); 10207a1c0d96SNathan Whitehorn } 1021682c9e0fSNathan Whitehorn #endif 10227a1c0d96SNathan Whitehorn 10237a1c0d96SNathan Whitehorn #ifdef HAVE_DLG_GAUGE 10247a1c0d96SNathan Whitehorn static int 10257a1c0d96SNathan Whitehorn call_programbox(CALLARGS) 10267a1c0d96SNathan Whitehorn { 10277a1c0d96SNathan Whitehorn int result; 10287a1c0d96SNathan Whitehorn 10297a1c0d96SNathan Whitehorn *offset_add = arg_rest(av); 10307a1c0d96SNathan Whitehorn /* this function is a compromise between --prgbox and --progressbox. 10317a1c0d96SNathan Whitehorn */ 10327a1c0d96SNathan Whitehorn result = ((*offset_add == 4) 10337a1c0d96SNathan Whitehorn ? dlg_progressbox(t, 10347a1c0d96SNathan Whitehorn av[1], 10357a1c0d96SNathan Whitehorn numeric_arg(av, 2), 10367a1c0d96SNathan Whitehorn numeric_arg(av, 3), 10377a1c0d96SNathan Whitehorn TRUE, 10387a1c0d96SNathan Whitehorn dialog_state.pipe_input) 10397a1c0d96SNathan Whitehorn : dlg_progressbox(t, 10407a1c0d96SNathan Whitehorn "", 10417a1c0d96SNathan Whitehorn numeric_arg(av, 1), 10427a1c0d96SNathan Whitehorn numeric_arg(av, 2), 10437a1c0d96SNathan Whitehorn TRUE, 10447a1c0d96SNathan Whitehorn dialog_state.pipe_input)); 10457a1c0d96SNathan Whitehorn dialog_state.pipe_input = 0; 10467a1c0d96SNathan Whitehorn return result; 10477a1c0d96SNathan Whitehorn } 10487a1c0d96SNathan Whitehorn #endif 10497a1c0d96SNathan Whitehorn 10504c8945a0SNathan Whitehorn #ifdef HAVE_DLG_GAUGE 10514c8945a0SNathan Whitehorn static int 10524c8945a0SNathan Whitehorn call_progressbox(CALLARGS) 10534c8945a0SNathan Whitehorn { 10544c8945a0SNathan Whitehorn *offset_add = arg_rest(av); 10554c8945a0SNathan Whitehorn /* the original version does not accept a prompt string, but for 10564c8945a0SNathan Whitehorn * consistency we allow it. 10574c8945a0SNathan Whitehorn */ 10584c8945a0SNathan Whitehorn return ((*offset_add == 4) 10594c8945a0SNathan Whitehorn ? dialog_progressbox(t, 10604c8945a0SNathan Whitehorn av[1], 10614c8945a0SNathan Whitehorn numeric_arg(av, 2), 10624c8945a0SNathan Whitehorn numeric_arg(av, 3)) 10634c8945a0SNathan Whitehorn : dialog_progressbox(t, 10644c8945a0SNathan Whitehorn "", 10654c8945a0SNathan Whitehorn numeric_arg(av, 1), 10664c8945a0SNathan Whitehorn numeric_arg(av, 2))); 10674c8945a0SNathan Whitehorn } 10684c8945a0SNathan Whitehorn #endif 10694c8945a0SNathan Whitehorn 10704c8945a0SNathan Whitehorn #ifdef HAVE_DLG_TAILBOX 10714c8945a0SNathan Whitehorn static int 10724c8945a0SNathan Whitehorn call_tailbox(CALLARGS) 10734c8945a0SNathan Whitehorn { 10744c8945a0SNathan Whitehorn *offset_add = 4; 10754c8945a0SNathan Whitehorn return dialog_tailbox(t, 10764c8945a0SNathan Whitehorn av[1], 10774c8945a0SNathan Whitehorn numeric_arg(av, 2), 10784c8945a0SNathan Whitehorn numeric_arg(av, 3), 10794c8945a0SNathan Whitehorn FALSE); 10804c8945a0SNathan Whitehorn } 10814c8945a0SNathan Whitehorn 10824c8945a0SNathan Whitehorn static int 10834c8945a0SNathan Whitehorn call_tailboxbg(CALLARGS) 10844c8945a0SNathan Whitehorn { 10854c8945a0SNathan Whitehorn *offset_add = 4; 10864c8945a0SNathan Whitehorn return dialog_tailbox(t, 10874c8945a0SNathan Whitehorn av[1], 10884c8945a0SNathan Whitehorn numeric_arg(av, 2), 10894c8945a0SNathan Whitehorn numeric_arg(av, 3), 10904c8945a0SNathan Whitehorn TRUE); 10914c8945a0SNathan Whitehorn } 10924c8945a0SNathan Whitehorn #endif 10934c8945a0SNathan Whitehorn /* *INDENT-OFF* */ 10944c8945a0SNathan Whitehorn static const Mode modes[] = 10954c8945a0SNathan Whitehorn { 10964c8945a0SNathan Whitehorn {o_yesno, 4, 4, call_yesno}, 10974c8945a0SNathan Whitehorn {o_msgbox, 4, 4, call_msgbox}, 10984c8945a0SNathan Whitehorn {o_infobox, 4, 4, call_infobox}, 10994c8945a0SNathan Whitehorn {o_textbox, 4, 4, call_textbox}, 11004c8945a0SNathan Whitehorn {o_menu, 7, 0, call_menu}, 11014c8945a0SNathan Whitehorn {o_inputmenu, 7, 0, call_inputmenu}, 11024c8945a0SNathan Whitehorn {o_checklist, 8, 0, call_checklist}, 11034c8945a0SNathan Whitehorn {o_radiolist, 8, 0, call_radiolist}, 11044c8945a0SNathan Whitehorn {o_inputbox, 4, 5, call_inputbox}, 11054c8945a0SNathan Whitehorn {o_passwordbox, 4, 5, call_passwordbox}, 11064c8945a0SNathan Whitehorn #ifdef HAVE_DLG_GAUGE 11074c8945a0SNathan Whitehorn {o_gauge, 4, 5, call_gauge}, 11084c8945a0SNathan Whitehorn {o_pause, 5, 5, call_pause}, 11097a1c0d96SNathan Whitehorn {o_prgbox, 4, 5, call_prgbox}, 11107a1c0d96SNathan Whitehorn {o_programbox, 3, 4, call_programbox}, 11114c8945a0SNathan Whitehorn {o_progressbox, 3, 4, call_progressbox}, 11124c8945a0SNathan Whitehorn #endif 11134c8945a0SNathan Whitehorn #ifdef HAVE_DLG_FORMBOX 11144c8945a0SNathan Whitehorn {o_passwordform, 13, 0, call_password_form}, 11154c8945a0SNathan Whitehorn {o_form, 13, 0, call_form}, 11164c8945a0SNathan Whitehorn #endif 11174c8945a0SNathan Whitehorn #ifdef HAVE_MIXEDGAUGE 11184c8945a0SNathan Whitehorn {o_mixedgauge, MIXEDGAUGE_BASE, 0, call_mixed_gauge}, 11194c8945a0SNathan Whitehorn #endif 11204c8945a0SNathan Whitehorn #ifdef HAVE_DLG_MIXEDFORM 11214c8945a0SNathan Whitehorn {o_mixedform, 13, 0, call_mixed_form}, 11224c8945a0SNathan Whitehorn #endif 11234c8945a0SNathan Whitehorn #ifdef HAVE_DLG_TAILBOX 11244c8945a0SNathan Whitehorn {o_tailbox, 4, 4, call_tailbox}, 11254c8945a0SNathan Whitehorn {o_tailboxbg, 4, 4, call_tailboxbg}, 11264c8945a0SNathan Whitehorn #endif 11274c8945a0SNathan Whitehorn #ifdef HAVE_XDIALOG 11282a3e3873SBaptiste Daroussin {o_buildlist, 4, 0, call_buildlist}, 11294c8945a0SNathan Whitehorn {o_calendar, 4, 7, call_calendar}, 11304c8945a0SNathan Whitehorn {o_dselect, 4, 5, call_dselect}, 11314c8945a0SNathan Whitehorn {o_editbox, 4, 4, call_editbox}, 11324c8945a0SNathan Whitehorn {o_fselect, 4, 5, call_fselect}, 11332a3e3873SBaptiste Daroussin {o_rangebox, 5, 7, call_rangebox}, 11344c8945a0SNathan Whitehorn {o_timebox, 4, 7, call_timebox}, 11352a3e3873SBaptiste Daroussin {o_treeview, 4, 0, call_treeview}, 11364c8945a0SNathan Whitehorn #endif 11374c8945a0SNathan Whitehorn }; 11384c8945a0SNathan Whitehorn /* *INDENT-ON* */ 11394c8945a0SNathan Whitehorn 11404c8945a0SNathan Whitehorn static char * 11414c8945a0SNathan Whitehorn optionString(char **argv, int *num) 11424c8945a0SNathan Whitehorn { 11434c8945a0SNathan Whitehorn int next = *num + 1; 11444c8945a0SNathan Whitehorn char *result = argv[next]; 11454c8945a0SNathan Whitehorn if (result == 0) { 11464c8945a0SNathan Whitehorn char temp[80]; 11474c8945a0SNathan Whitehorn sprintf(temp, "Expected a string-parameter for %.20s", argv[*num]); 11484c8945a0SNathan Whitehorn Usage(temp); 11494c8945a0SNathan Whitehorn } 11504c8945a0SNathan Whitehorn *num = next; 11514c8945a0SNathan Whitehorn return result; 11524c8945a0SNathan Whitehorn } 11534c8945a0SNathan Whitehorn 11544c8945a0SNathan Whitehorn static int 11554c8945a0SNathan Whitehorn optionValue(char **argv, int *num) 11564c8945a0SNathan Whitehorn { 11574c8945a0SNathan Whitehorn int next = *num + 1; 11584c8945a0SNathan Whitehorn char *src = argv[next]; 11594c8945a0SNathan Whitehorn char *tmp = 0; 11604c8945a0SNathan Whitehorn int result = 0; 11614c8945a0SNathan Whitehorn 11624c8945a0SNathan Whitehorn if (src != 0) { 11637a1c0d96SNathan Whitehorn result = (int) strtol(src, &tmp, 0); 11644c8945a0SNathan Whitehorn if (tmp == 0 || *tmp != 0) 11654c8945a0SNathan Whitehorn src = 0; 11664c8945a0SNathan Whitehorn } 11674c8945a0SNathan Whitehorn 11684c8945a0SNathan Whitehorn if (src == 0) { 11694c8945a0SNathan Whitehorn char temp[80]; 11704c8945a0SNathan Whitehorn sprintf(temp, "Expected a numeric-parameter for %.20s", argv[*num]); 11714c8945a0SNathan Whitehorn Usage(temp); 11724c8945a0SNathan Whitehorn } 11734c8945a0SNathan Whitehorn *num = next; 11744c8945a0SNathan Whitehorn return result; 11754c8945a0SNathan Whitehorn } 11764c8945a0SNathan Whitehorn 11772a3e3873SBaptiste Daroussin /* Return exit-code for a named button */ 11782a3e3873SBaptiste Daroussin static int 11792a3e3873SBaptiste Daroussin button_code(const char *name) 11802a3e3873SBaptiste Daroussin { 11812a3e3873SBaptiste Daroussin /* *INDENT-OFF* */ 11822a3e3873SBaptiste Daroussin static struct { 11832a3e3873SBaptiste Daroussin const char *name; 11842a3e3873SBaptiste Daroussin int code; 11852a3e3873SBaptiste Daroussin } table[] = { 11862a3e3873SBaptiste Daroussin { "ok", DLG_EXIT_OK }, 11872a3e3873SBaptiste Daroussin { "yes", DLG_EXIT_OK }, 11882a3e3873SBaptiste Daroussin { "cancel", DLG_EXIT_CANCEL }, 11892a3e3873SBaptiste Daroussin { "no", DLG_EXIT_CANCEL }, 11902a3e3873SBaptiste Daroussin { "help", DLG_EXIT_HELP }, 11912a3e3873SBaptiste Daroussin { "extra", DLG_EXIT_EXTRA }, 11922a3e3873SBaptiste Daroussin }; 11932a3e3873SBaptiste Daroussin /* *INDENT-ON* */ 11942a3e3873SBaptiste Daroussin 11952a3e3873SBaptiste Daroussin int code = DLG_EXIT_ERROR; 11962a3e3873SBaptiste Daroussin size_t i; 11972a3e3873SBaptiste Daroussin 11982a3e3873SBaptiste Daroussin for (i = 0; i < (sizeof(table) / sizeof(table[0])); i++) { 11992a3e3873SBaptiste Daroussin if (!dlg_strcmp(name, table[i].name)) { 12002a3e3873SBaptiste Daroussin code = table[i].code; 12012a3e3873SBaptiste Daroussin break; 12022a3e3873SBaptiste Daroussin } 12032a3e3873SBaptiste Daroussin } 12042a3e3873SBaptiste Daroussin 12052a3e3873SBaptiste Daroussin if (code == DLG_EXIT_ERROR) { 12062a3e3873SBaptiste Daroussin char temp[80]; 12072a3e3873SBaptiste Daroussin sprintf(temp, "Button name \"%.20s\" unknown", name); 12082a3e3873SBaptiste Daroussin Usage(temp); 12092a3e3873SBaptiste Daroussin } 12102a3e3873SBaptiste Daroussin 12112a3e3873SBaptiste Daroussin return code; 12122a3e3873SBaptiste Daroussin } 12132a3e3873SBaptiste Daroussin 12144c8945a0SNathan Whitehorn /* 12154c8945a0SNathan Whitehorn * Print parts of a message 12164c8945a0SNathan Whitehorn */ 12174c8945a0SNathan Whitehorn static void 12184c8945a0SNathan Whitehorn PrintList(const char *const *list) 12194c8945a0SNathan Whitehorn { 12204c8945a0SNathan Whitehorn const char *leaf = strrchr(program, '/'); 12214c8945a0SNathan Whitehorn unsigned n = 0; 12224c8945a0SNathan Whitehorn 12234c8945a0SNathan Whitehorn if (leaf != 0) 12244c8945a0SNathan Whitehorn leaf++; 12254c8945a0SNathan Whitehorn else 12264c8945a0SNathan Whitehorn leaf = program; 12274c8945a0SNathan Whitehorn 12284c8945a0SNathan Whitehorn while (*list != 0) { 12294c8945a0SNathan Whitehorn fprintf(dialog_state.output, *list, n ? leaf : dialog_version()); 12304c8945a0SNathan Whitehorn (void) fputc('\n', dialog_state.output); 12314c8945a0SNathan Whitehorn n = 1; 12324c8945a0SNathan Whitehorn list++; 12334c8945a0SNathan Whitehorn } 12344c8945a0SNathan Whitehorn } 12354c8945a0SNathan Whitehorn 12364c8945a0SNathan Whitehorn static const Mode * 12374c8945a0SNathan Whitehorn lookupMode(eOptions code) 12384c8945a0SNathan Whitehorn { 12394c8945a0SNathan Whitehorn const Mode *modePtr = 0; 12404c8945a0SNathan Whitehorn unsigned n; 12414c8945a0SNathan Whitehorn 12424c8945a0SNathan Whitehorn for (n = 0; n < sizeof(modes) / sizeof(modes[0]); n++) { 12434c8945a0SNathan Whitehorn if (modes[n].code == code) { 12444c8945a0SNathan Whitehorn modePtr = &modes[n]; 12454c8945a0SNathan Whitehorn break; 12464c8945a0SNathan Whitehorn } 12474c8945a0SNathan Whitehorn } 12484c8945a0SNathan Whitehorn return modePtr; 12494c8945a0SNathan Whitehorn } 12504c8945a0SNathan Whitehorn 12514c8945a0SNathan Whitehorn static int 12524c8945a0SNathan Whitehorn compare_opts(const void *a, const void *b) 12534c8945a0SNathan Whitehorn { 12544c8945a0SNathan Whitehorn Options *const *p = (Options * const *) a; 12554c8945a0SNathan Whitehorn Options *const *q = (Options * const *) b; 12564c8945a0SNathan Whitehorn return strcmp((*p)->name, (*q)->name); 12574c8945a0SNathan Whitehorn } 12584c8945a0SNathan Whitehorn 12594c8945a0SNathan Whitehorn /* 1260682c9e0fSNathan Whitehorn * Print program's version. 1261682c9e0fSNathan Whitehorn */ 1262682c9e0fSNathan Whitehorn static void 1263682c9e0fSNathan Whitehorn PrintVersion(FILE *fp) 1264682c9e0fSNathan Whitehorn { 1265682c9e0fSNathan Whitehorn fprintf(fp, "Version: %s\n", dialog_version()); 1266682c9e0fSNathan Whitehorn } 1267682c9e0fSNathan Whitehorn 1268682c9e0fSNathan Whitehorn /* 12694c8945a0SNathan Whitehorn * Print program help-message 12704c8945a0SNathan Whitehorn */ 12714c8945a0SNathan Whitehorn static void 12724c8945a0SNathan Whitehorn Help(void) 12734c8945a0SNathan Whitehorn { 12744c8945a0SNathan Whitehorn static const char *const tbl_1[] = 12754c8945a0SNathan Whitehorn { 12764c8945a0SNathan Whitehorn "cdialog (ComeOn Dialog!) version %s", 12772a3e3873SBaptiste Daroussin "Copyright 2000-2012,2013 Thomas E. Dickey", 12784c8945a0SNathan Whitehorn "This is free software; see the source for copying conditions. There is NO", 12794c8945a0SNathan Whitehorn "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.", 12804c8945a0SNathan Whitehorn "", 12814c8945a0SNathan Whitehorn "* Display dialog boxes from shell scripts *", 12824c8945a0SNathan Whitehorn "", 12834c8945a0SNathan Whitehorn "Usage: %s <options> { --and-widget <options> }", 12844c8945a0SNathan Whitehorn "where options are \"common\" options, followed by \"box\" options", 12854c8945a0SNathan Whitehorn "", 12864c8945a0SNathan Whitehorn #ifdef HAVE_RC_FILE 12874c8945a0SNathan Whitehorn "Special options:", 12884c8945a0SNathan Whitehorn " [--create-rc \"file\"]", 12894c8945a0SNathan Whitehorn #endif 12904c8945a0SNathan Whitehorn 0 12914c8945a0SNathan Whitehorn }, *const tbl_3[] = 12924c8945a0SNathan Whitehorn { 12934c8945a0SNathan Whitehorn "", 12944c8945a0SNathan Whitehorn "Auto-size with height and width = 0. Maximize with height and width = -1.", 12954c8945a0SNathan Whitehorn "Global-auto-size if also menu_height/list_height = 0.", 12964c8945a0SNathan Whitehorn 0 12974c8945a0SNathan Whitehorn }; 12987a1c0d96SNathan Whitehorn size_t limit = sizeof(options) / sizeof(options[0]); 12997a1c0d96SNathan Whitehorn size_t j, k; 13004c8945a0SNathan Whitehorn const Options **opts; 13014c8945a0SNathan Whitehorn 1302682c9e0fSNathan Whitehorn end_dialog(); 1303682c9e0fSNathan Whitehorn dialog_state.output = stdout; 1304682c9e0fSNathan Whitehorn 13054c8945a0SNathan Whitehorn opts = dlg_calloc(const Options *, limit); 13064c8945a0SNathan Whitehorn assert_ptr(opts, "Help"); 13074c8945a0SNathan Whitehorn for (j = 0; j < limit; ++j) { 13084c8945a0SNathan Whitehorn opts[j] = &(options[j]); 13094c8945a0SNathan Whitehorn } 13104c8945a0SNathan Whitehorn qsort(opts, limit, sizeof(Options *), compare_opts); 13114c8945a0SNathan Whitehorn 13124c8945a0SNathan Whitehorn PrintList(tbl_1); 13134c8945a0SNathan Whitehorn fprintf(dialog_state.output, "Common options:\n "); 13144c8945a0SNathan Whitehorn for (j = k = 0; j < limit; j++) { 13154c8945a0SNathan Whitehorn if ((opts[j]->pass & 1) 13164c8945a0SNathan Whitehorn && opts[j]->help != 0) { 13177a1c0d96SNathan Whitehorn size_t len = 6 + strlen(opts[j]->name) + strlen(opts[j]->help); 13184c8945a0SNathan Whitehorn k += len; 13194c8945a0SNathan Whitehorn if (k > 75) { 13204c8945a0SNathan Whitehorn fprintf(dialog_state.output, "\n "); 13214c8945a0SNathan Whitehorn k = len; 13224c8945a0SNathan Whitehorn } 13234c8945a0SNathan Whitehorn fprintf(dialog_state.output, " [--%s%s%s]", opts[j]->name, 13244c8945a0SNathan Whitehorn *(opts[j]->help) ? " " : "", opts[j]->help); 13254c8945a0SNathan Whitehorn } 13264c8945a0SNathan Whitehorn } 13274c8945a0SNathan Whitehorn fprintf(dialog_state.output, "\nBox options:\n"); 13284c8945a0SNathan Whitehorn for (j = 0; j < limit; j++) { 13294c8945a0SNathan Whitehorn if ((opts[j]->pass & 2) != 0 13304c8945a0SNathan Whitehorn && opts[j]->help != 0 13314c8945a0SNathan Whitehorn && lookupMode(opts[j]->code)) 13324c8945a0SNathan Whitehorn fprintf(dialog_state.output, " --%-12s %s\n", opts[j]->name, 13334c8945a0SNathan Whitehorn opts[j]->help); 13344c8945a0SNathan Whitehorn } 13354c8945a0SNathan Whitehorn PrintList(tbl_3); 13364c8945a0SNathan Whitehorn 13374c8945a0SNathan Whitehorn free(opts); 13384c8945a0SNathan Whitehorn dlg_exit(DLG_EXIT_OK); 13394c8945a0SNathan Whitehorn } 13404c8945a0SNathan Whitehorn 13412a3e3873SBaptiste Daroussin #ifdef HAVE_DLG_TRACE 13422a3e3873SBaptiste Daroussin /* 13432a3e3873SBaptiste Daroussin * Only the first call to dlg_trace will open a trace file. But each time 13442a3e3873SBaptiste Daroussin * --trace is parsed, we show the whole parameter list as it is at that moment, 13452a3e3873SBaptiste Daroussin * counting discarded parameters. The only way to capture the whole parameter 13462a3e3873SBaptiste Daroussin * list is if --trace is the first option. 13472a3e3873SBaptiste Daroussin */ 13482a3e3873SBaptiste Daroussin static void 13492a3e3873SBaptiste Daroussin process_trace_option(char **argv, int *offset) 13502a3e3873SBaptiste Daroussin { 13512a3e3873SBaptiste Daroussin int j; 13522a3e3873SBaptiste Daroussin 13532a3e3873SBaptiste Daroussin if (dialog_state.trace_output == 0) { 13542a3e3873SBaptiste Daroussin dlg_trace(optionString(argv, offset)); 13552a3e3873SBaptiste Daroussin } else { 13562a3e3873SBaptiste Daroussin dlg_trace_msg("# ignore extra --trace option\n"); 13572a3e3873SBaptiste Daroussin *offset += 1; 13582a3e3873SBaptiste Daroussin } 13592a3e3873SBaptiste Daroussin 13602a3e3873SBaptiste Daroussin dlg_trace_msg("# Parameters:\n"); 13612a3e3873SBaptiste Daroussin for (j = 0; argv[j] != 0; ++j) { 13622a3e3873SBaptiste Daroussin dlg_trace_msg("# argv[%d] = %s\n", j, argv[j]); 13632a3e3873SBaptiste Daroussin } 13642a3e3873SBaptiste Daroussin } 13652a3e3873SBaptiste Daroussin #endif 13662a3e3873SBaptiste Daroussin 13674c8945a0SNathan Whitehorn /* 13684c8945a0SNathan Whitehorn * "Common" options apply to all widgets more/less. Most of the common options 13694c8945a0SNathan Whitehorn * set values in dialog_vars, a few set dialog_state and a couple write to the 13704c8945a0SNathan Whitehorn * output stream. 13714c8945a0SNathan Whitehorn */ 13724c8945a0SNathan Whitehorn static int 13734c8945a0SNathan Whitehorn process_common_options(int argc, char **argv, int offset, bool output) 13744c8945a0SNathan Whitehorn { 13754c8945a0SNathan Whitehorn bool done = FALSE; 13764c8945a0SNathan Whitehorn 13772a3e3873SBaptiste Daroussin dlg_trace_msg("# process_common_options, offset %d\n", offset); 13782a3e3873SBaptiste Daroussin 13794c8945a0SNathan Whitehorn while (offset < argc && !done) { /* Common options */ 13802a3e3873SBaptiste Daroussin dlg_trace_msg("#\targv[%d] = %s\n", offset, argv[offset]); 13814c8945a0SNathan Whitehorn switch (lookupOption(argv[offset], 1)) { 13824c8945a0SNathan Whitehorn case o_title: 13834c8945a0SNathan Whitehorn dialog_vars.title = optionString(argv, &offset); 13844c8945a0SNathan Whitehorn break; 13854c8945a0SNathan Whitehorn case o_backtitle: 13864c8945a0SNathan Whitehorn dialog_vars.backtitle = optionString(argv, &offset); 13874c8945a0SNathan Whitehorn break; 13884c8945a0SNathan Whitehorn case o_separate_widget: 13894c8945a0SNathan Whitehorn dialog_state.separate_str = optionString(argv, &offset); 13904c8945a0SNathan Whitehorn break; 13914c8945a0SNathan Whitehorn case o_separate_output: 13924c8945a0SNathan Whitehorn dialog_vars.separate_output = TRUE; 13934c8945a0SNathan Whitehorn break; 13944c8945a0SNathan Whitehorn case o_colors: 13954c8945a0SNathan Whitehorn dialog_vars.colors = TRUE; 13964c8945a0SNathan Whitehorn break; 13974c8945a0SNathan Whitehorn case o_cr_wrap: 13984c8945a0SNathan Whitehorn dialog_vars.cr_wrap = TRUE; 13994c8945a0SNathan Whitehorn break; 1400682c9e0fSNathan Whitehorn case o_no_nl_expand: 1401682c9e0fSNathan Whitehorn dialog_vars.no_nl_expand = TRUE; 1402682c9e0fSNathan Whitehorn break; 14034c8945a0SNathan Whitehorn case o_no_collapse: 14044c8945a0SNathan Whitehorn dialog_vars.nocollapse = TRUE; 14054c8945a0SNathan Whitehorn break; 14064c8945a0SNathan Whitehorn case o_no_kill: 14074c8945a0SNathan Whitehorn dialog_vars.cant_kill = TRUE; 14084c8945a0SNathan Whitehorn break; 14094c8945a0SNathan Whitehorn case o_nocancel: 14104c8945a0SNathan Whitehorn dialog_vars.nocancel = TRUE; 14114c8945a0SNathan Whitehorn break; 14124c8945a0SNathan Whitehorn case o_nook: 14134c8945a0SNathan Whitehorn dialog_vars.nook = TRUE; 14144c8945a0SNathan Whitehorn break; 14154c8945a0SNathan Whitehorn case o_quoted: 14164c8945a0SNathan Whitehorn dialog_vars.quoted = TRUE; 14174c8945a0SNathan Whitehorn break; 14184c8945a0SNathan Whitehorn case o_single_quoted: 14194c8945a0SNathan Whitehorn dialog_vars.single_quoted = TRUE; 14204c8945a0SNathan Whitehorn break; 14214c8945a0SNathan Whitehorn case o_size_err: 14224c8945a0SNathan Whitehorn dialog_vars.size_err = TRUE; 14234c8945a0SNathan Whitehorn break; 14244c8945a0SNathan Whitehorn case o_beep: 14254c8945a0SNathan Whitehorn dialog_vars.beep_signal = TRUE; 14264c8945a0SNathan Whitehorn break; 14274c8945a0SNathan Whitehorn case o_beep_after: 14284c8945a0SNathan Whitehorn dialog_vars.beep_after_signal = TRUE; 14294c8945a0SNathan Whitehorn break; 14304c8945a0SNathan Whitehorn case o_scrollbar: 14314c8945a0SNathan Whitehorn dialog_state.use_scrollbar = TRUE; 14324c8945a0SNathan Whitehorn break; 14334c8945a0SNathan Whitehorn case o_shadow: 14344c8945a0SNathan Whitehorn dialog_state.use_shadow = TRUE; 14354c8945a0SNathan Whitehorn break; 14364c8945a0SNathan Whitehorn case o_defaultno: 14374c8945a0SNathan Whitehorn dialog_vars.defaultno = TRUE; 14382a3e3873SBaptiste Daroussin dialog_vars.default_button = DLG_EXIT_CANCEL; 14392a3e3873SBaptiste Daroussin break; 14402a3e3873SBaptiste Daroussin case o_default_button: 14412a3e3873SBaptiste Daroussin dialog_vars.default_button = button_code(optionString(argv, &offset)); 14422a3e3873SBaptiste Daroussin dialog_vars.defaultno = dialog_vars.default_button == DLG_EXIT_CANCEL; 14434c8945a0SNathan Whitehorn break; 14444c8945a0SNathan Whitehorn case o_default_item: 14454c8945a0SNathan Whitehorn dialog_vars.default_item = optionString(argv, &offset); 14464c8945a0SNathan Whitehorn break; 14474c8945a0SNathan Whitehorn case o_insecure: 14484c8945a0SNathan Whitehorn dialog_vars.insecure = TRUE; 14494c8945a0SNathan Whitehorn break; 14504c8945a0SNathan Whitehorn case o_item_help: 14514c8945a0SNathan Whitehorn dialog_vars.item_help = TRUE; 14524c8945a0SNathan Whitehorn break; 1453682c9e0fSNathan Whitehorn case o_help_line: 1454682c9e0fSNathan Whitehorn dialog_vars.help_line = optionString(argv, &offset); 1455682c9e0fSNathan Whitehorn break; 1456682c9e0fSNathan Whitehorn case o_help_file: 1457682c9e0fSNathan Whitehorn dialog_vars.help_file = optionString(argv, &offset); 1458682c9e0fSNathan Whitehorn break; 14594c8945a0SNathan Whitehorn case o_help_button: 14604c8945a0SNathan Whitehorn dialog_vars.help_button = TRUE; 14614c8945a0SNathan Whitehorn break; 14624c8945a0SNathan Whitehorn case o_help_status: 14634c8945a0SNathan Whitehorn dialog_vars.help_status = TRUE; 14644c8945a0SNathan Whitehorn break; 14654c8945a0SNathan Whitehorn case o_extra_button: 14664c8945a0SNathan Whitehorn dialog_vars.extra_button = TRUE; 14674c8945a0SNathan Whitehorn break; 14684c8945a0SNathan Whitehorn case o_ignore: 14694c8945a0SNathan Whitehorn ignore_unknown = TRUE; 14704c8945a0SNathan Whitehorn break; 14714c8945a0SNathan Whitehorn case o_keep_window: 14724c8945a0SNathan Whitehorn dialog_vars.keep_window = TRUE; 14734c8945a0SNathan Whitehorn break; 14742a3e3873SBaptiste Daroussin case o_last_key: 14752a3e3873SBaptiste Daroussin dialog_vars.last_key = TRUE; 14762a3e3873SBaptiste Daroussin break; 14774c8945a0SNathan Whitehorn case o_no_shadow: 14784c8945a0SNathan Whitehorn dialog_state.use_shadow = FALSE; 14794c8945a0SNathan Whitehorn break; 14804c8945a0SNathan Whitehorn case o_print_size: 14814c8945a0SNathan Whitehorn dialog_vars.print_siz = TRUE; 14824c8945a0SNathan Whitehorn break; 14834c8945a0SNathan Whitehorn case o_print_maxsize: 14844c8945a0SNathan Whitehorn if (output) { 14854c8945a0SNathan Whitehorn /* 14864c8945a0SNathan Whitehorn * If this is the last option, we do not want any error 14874c8945a0SNathan Whitehorn * messages - just our output. Calling end_dialog() cancels 14884c8945a0SNathan Whitehorn * the refresh() at the end of the program as well. 14894c8945a0SNathan Whitehorn */ 14904c8945a0SNathan Whitehorn if (argv[offset + 1] == 0) { 14914c8945a0SNathan Whitehorn ignore_unknown = TRUE; 14924c8945a0SNathan Whitehorn end_dialog(); 14934c8945a0SNathan Whitehorn } 14944c8945a0SNathan Whitehorn fflush(dialog_state.output); 14954c8945a0SNathan Whitehorn fprintf(dialog_state.output, "MaxSize: %d, %d\n", SLINES, SCOLS); 14964c8945a0SNathan Whitehorn } 14974c8945a0SNathan Whitehorn break; 14984c8945a0SNathan Whitehorn case o_print_version: 14994c8945a0SNathan Whitehorn if (output) { 1500682c9e0fSNathan Whitehorn PrintVersion(dialog_state.output); 15014c8945a0SNathan Whitehorn } 15024c8945a0SNathan Whitehorn break; 15034c8945a0SNathan Whitehorn case o_separator: 15044c8945a0SNathan Whitehorn case o_output_separator: 15054c8945a0SNathan Whitehorn dialog_vars.output_separator = optionString(argv, &offset); 15064c8945a0SNathan Whitehorn break; 15074c8945a0SNathan Whitehorn case o_column_separator: 15084c8945a0SNathan Whitehorn dialog_vars.column_separator = optionString(argv, &offset); 15094c8945a0SNathan Whitehorn break; 15104c8945a0SNathan Whitehorn case o_tab_correct: 15114c8945a0SNathan Whitehorn dialog_vars.tab_correct = TRUE; 15124c8945a0SNathan Whitehorn break; 15134c8945a0SNathan Whitehorn case o_sleep: 15144c8945a0SNathan Whitehorn dialog_vars.sleep_secs = optionValue(argv, &offset); 15154c8945a0SNathan Whitehorn break; 15164c8945a0SNathan Whitehorn case o_timeout: 15174c8945a0SNathan Whitehorn dialog_vars.timeout_secs = optionValue(argv, &offset); 15184c8945a0SNathan Whitehorn break; 15194c8945a0SNathan Whitehorn case o_max_input: 15204c8945a0SNathan Whitehorn dialog_vars.max_input = optionValue(argv, &offset); 15214c8945a0SNathan Whitehorn break; 15224c8945a0SNathan Whitehorn case o_tab_len: 15234c8945a0SNathan Whitehorn dialog_state.tab_len = optionValue(argv, &offset); 15244c8945a0SNathan Whitehorn break; 15254c8945a0SNathan Whitehorn case o_trim: 15264c8945a0SNathan Whitehorn dialog_vars.trim_whitespace = TRUE; 15274c8945a0SNathan Whitehorn break; 15284c8945a0SNathan Whitehorn case o_visit_items: 15294c8945a0SNathan Whitehorn dialog_state.visit_items = TRUE; 15302a3e3873SBaptiste Daroussin dialog_state.visit_cols = 1; 15314c8945a0SNathan Whitehorn break; 15324c8945a0SNathan Whitehorn case o_aspect: 15334c8945a0SNathan Whitehorn dialog_state.aspect_ratio = optionValue(argv, &offset); 15344c8945a0SNathan Whitehorn break; 15354c8945a0SNathan Whitehorn case o_begin: 15364c8945a0SNathan Whitehorn dialog_vars.begin_set = TRUE; 15374c8945a0SNathan Whitehorn dialog_vars.begin_y = optionValue(argv, &offset); 15384c8945a0SNathan Whitehorn dialog_vars.begin_x = optionValue(argv, &offset); 15394c8945a0SNathan Whitehorn break; 15404c8945a0SNathan Whitehorn case o_clear: 15414c8945a0SNathan Whitehorn dialog_vars.dlg_clear_screen = TRUE; 15424c8945a0SNathan Whitehorn break; 15434c8945a0SNathan Whitehorn case o_yes_label: 15444c8945a0SNathan Whitehorn dialog_vars.yes_label = optionString(argv, &offset); 15454c8945a0SNathan Whitehorn break; 15464c8945a0SNathan Whitehorn case o_no_label: 15474c8945a0SNathan Whitehorn dialog_vars.no_label = optionString(argv, &offset); 15484c8945a0SNathan Whitehorn break; 15494c8945a0SNathan Whitehorn case o_ok_label: 15504c8945a0SNathan Whitehorn dialog_vars.ok_label = optionString(argv, &offset); 15514c8945a0SNathan Whitehorn break; 15524c8945a0SNathan Whitehorn case o_cancel_label: 15534c8945a0SNathan Whitehorn dialog_vars.cancel_label = optionString(argv, &offset); 15544c8945a0SNathan Whitehorn break; 15554c8945a0SNathan Whitehorn case o_extra_label: 15564c8945a0SNathan Whitehorn dialog_vars.extra_label = optionString(argv, &offset); 15574c8945a0SNathan Whitehorn break; 15584c8945a0SNathan Whitehorn case o_exit_label: 15594c8945a0SNathan Whitehorn dialog_vars.exit_label = optionString(argv, &offset); 15604c8945a0SNathan Whitehorn break; 15614c8945a0SNathan Whitehorn case o_help_label: 15624c8945a0SNathan Whitehorn dialog_vars.help_label = optionString(argv, &offset); 15634c8945a0SNathan Whitehorn break; 15644c8945a0SNathan Whitehorn case o_date_format: 15654c8945a0SNathan Whitehorn dialog_vars.date_format = optionString(argv, &offset); 15664c8945a0SNathan Whitehorn break; 15674c8945a0SNathan Whitehorn case o_time_format: 15684c8945a0SNathan Whitehorn dialog_vars.time_format = optionString(argv, &offset); 15694c8945a0SNathan Whitehorn break; 15704c8945a0SNathan Whitehorn case o_keep_tite: 15714c8945a0SNathan Whitehorn dialog_vars.keep_tite = TRUE; 15724c8945a0SNathan Whitehorn break; 15734c8945a0SNathan Whitehorn case o_ascii_lines: 15744c8945a0SNathan Whitehorn dialog_vars.ascii_lines = TRUE; 15754c8945a0SNathan Whitehorn dialog_vars.no_lines = FALSE; 15764c8945a0SNathan Whitehorn break; 15774c8945a0SNathan Whitehorn case o_no_lines: 15784c8945a0SNathan Whitehorn dialog_vars.no_lines = TRUE; 15794c8945a0SNathan Whitehorn dialog_vars.ascii_lines = FALSE; 15804c8945a0SNathan Whitehorn break; 15817a1c0d96SNathan Whitehorn case o_no_mouse: 15827a1c0d96SNathan Whitehorn dialog_state.no_mouse = TRUE; 1583682c9e0fSNathan Whitehorn mouse_close(); 15847a1c0d96SNathan Whitehorn break; 15852a3e3873SBaptiste Daroussin #ifdef HAVE_WHIPTAIL 15862a3e3873SBaptiste Daroussin case o_topleft: 15872a3e3873SBaptiste Daroussin dialog_vars.begin_set = TRUE; 15882a3e3873SBaptiste Daroussin dialog_vars.begin_y = 0; 15892a3e3873SBaptiste Daroussin dialog_vars.begin_x = 0; 15902a3e3873SBaptiste Daroussin break; 15914c8945a0SNathan Whitehorn case o_fullbutton: 15924c8945a0SNathan Whitehorn /* ignore */ 15934c8945a0SNathan Whitehorn break; 15942a3e3873SBaptiste Daroussin #endif 15954c8945a0SNathan Whitehorn /* options of Xdialog which we ignore */ 15964c8945a0SNathan Whitehorn case o_icon: 15974c8945a0SNathan Whitehorn case o_wmclass: 15984c8945a0SNathan Whitehorn (void) optionString(argv, &offset); 15994c8945a0SNathan Whitehorn /* FALLTHRU */ 16004c8945a0SNathan Whitehorn case o_allow_close: 16014c8945a0SNathan Whitehorn case o_auto_placement: 16024c8945a0SNathan Whitehorn case o_fixed_font: 16034c8945a0SNathan Whitehorn case o_keep_colors: 16044c8945a0SNathan Whitehorn case o_no_close: 16054c8945a0SNathan Whitehorn case o_no_cr_wrap: 16064c8945a0SNathan Whitehorn case o_screen_center: 16074c8945a0SNathan Whitehorn case o_smooth: 16084c8945a0SNathan Whitehorn case o_under_mouse: 16094c8945a0SNathan Whitehorn break; 16104c8945a0SNathan Whitehorn case o_unknown: 16114c8945a0SNathan Whitehorn if (ignore_unknown) 16124c8945a0SNathan Whitehorn break; 16134c8945a0SNathan Whitehorn /* FALLTHRU */ 16144c8945a0SNathan Whitehorn default: /* no more common options */ 16154c8945a0SNathan Whitehorn done = TRUE; 16164c8945a0SNathan Whitehorn break; 16174c8945a0SNathan Whitehorn #ifdef HAVE_DLG_TRACE 16184c8945a0SNathan Whitehorn case o_trace: 16192a3e3873SBaptiste Daroussin process_trace_option(argv, &offset); 16202a3e3873SBaptiste Daroussin break; 16212a3e3873SBaptiste Daroussin #endif 16222a3e3873SBaptiste Daroussin #if defined(HAVE_XDIALOG2) || defined(HAVE_WHIPTAIL) 16232a3e3873SBaptiste Daroussin case o_no_items: 16242a3e3873SBaptiste Daroussin dialog_vars.no_items = TRUE; 16252a3e3873SBaptiste Daroussin break; 16262a3e3873SBaptiste Daroussin case o_no_tags: 16272a3e3873SBaptiste Daroussin dialog_vars.no_tags = TRUE; 16284c8945a0SNathan Whitehorn break; 16294c8945a0SNathan Whitehorn #endif 16304c8945a0SNathan Whitehorn } 16314c8945a0SNathan Whitehorn if (!done) 16324c8945a0SNathan Whitehorn offset++; 16334c8945a0SNathan Whitehorn } 16344c8945a0SNathan Whitehorn return offset; 16354c8945a0SNathan Whitehorn } 16364c8945a0SNathan Whitehorn 16374c8945a0SNathan Whitehorn /* 16384c8945a0SNathan Whitehorn * Initialize options at the start of a series of common options culminating 16394c8945a0SNathan Whitehorn * in a widget. 16404c8945a0SNathan Whitehorn */ 16414c8945a0SNathan Whitehorn static void 16424c8945a0SNathan Whitehorn init_result(char *buffer) 16434c8945a0SNathan Whitehorn { 16444c8945a0SNathan Whitehorn static bool first = TRUE; 16454c8945a0SNathan Whitehorn static char **special_argv = 0; 16464c8945a0SNathan Whitehorn static int special_argc = 0; 16474c8945a0SNathan Whitehorn 16482a3e3873SBaptiste Daroussin dlg_trace_msg("# init_result\n"); 16492a3e3873SBaptiste Daroussin 16504c8945a0SNathan Whitehorn /* clear everything we do not save for the next widget */ 16514c8945a0SNathan Whitehorn memset(&dialog_vars, 0, sizeof(dialog_vars)); 16524c8945a0SNathan Whitehorn 16534c8945a0SNathan Whitehorn dialog_vars.input_result = buffer; 16544c8945a0SNathan Whitehorn dialog_vars.input_result[0] = '\0'; 16554c8945a0SNathan Whitehorn 16562a3e3873SBaptiste Daroussin dialog_vars.default_button = -1; 16572a3e3873SBaptiste Daroussin 16584c8945a0SNathan Whitehorn /* 16594c8945a0SNathan Whitehorn * The first time this is called, check for common options given by an 16604c8945a0SNathan Whitehorn * environment variable. 16614c8945a0SNathan Whitehorn */ 16624c8945a0SNathan Whitehorn if (first) { 16634c8945a0SNathan Whitehorn char *env = getenv("DIALOGOPTS"); 16644c8945a0SNathan Whitehorn if (env != 0) 16654c8945a0SNathan Whitehorn env = dlg_strclone(env); 16664c8945a0SNathan Whitehorn if (env != 0) { 16677a1c0d96SNathan Whitehorn special_argv = dlg_string_to_argv(env); 16687a1c0d96SNathan Whitehorn special_argc = dlg_count_argv(special_argv); 16694c8945a0SNathan Whitehorn } 16702a3e3873SBaptiste Daroussin first = FALSE; 16714c8945a0SNathan Whitehorn } 16722a3e3873SBaptiste Daroussin 16732a3e3873SBaptiste Daroussin /* 16742a3e3873SBaptiste Daroussin * If we are not checking memory leaks, just do the parse of the 16752a3e3873SBaptiste Daroussin * environment once. 16762a3e3873SBaptiste Daroussin */ 16774c8945a0SNathan Whitehorn if (special_argv != 0) { 16784c8945a0SNathan Whitehorn process_common_options(special_argc, special_argv, 0, FALSE); 16794c8945a0SNathan Whitehorn #ifdef NO_LEAKS 16804c8945a0SNathan Whitehorn free(special_argv[0]); 16814c8945a0SNathan Whitehorn free(special_argv); 16822a3e3873SBaptiste Daroussin special_argv = 0; 16832a3e3873SBaptiste Daroussin special_argc = 0; 16844c8945a0SNathan Whitehorn first = TRUE; 16854c8945a0SNathan Whitehorn #endif 16864c8945a0SNathan Whitehorn } 16874c8945a0SNathan Whitehorn } 16884c8945a0SNathan Whitehorn 16894c8945a0SNathan Whitehorn int 16904c8945a0SNathan Whitehorn main(int argc, char *argv[]) 16914c8945a0SNathan Whitehorn { 16924c8945a0SNathan Whitehorn char temp[256]; 16934c8945a0SNathan Whitehorn bool esc_pressed = FALSE; 16944c8945a0SNathan Whitehorn bool keep_tite = FALSE; 16954c8945a0SNathan Whitehorn int offset = 1; 16964c8945a0SNathan Whitehorn int offset_add; 16974c8945a0SNathan Whitehorn int retval = DLG_EXIT_OK; 16984c8945a0SNathan Whitehorn int j, have; 16994c8945a0SNathan Whitehorn eOptions code; 17004c8945a0SNathan Whitehorn const Mode *modePtr; 17014c8945a0SNathan Whitehorn char my_buffer[MAX_LEN + 1]; 17024c8945a0SNathan Whitehorn 17034c8945a0SNathan Whitehorn memset(&dialog_state, 0, sizeof(dialog_state)); 17044c8945a0SNathan Whitehorn memset(&dialog_vars, 0, sizeof(dialog_vars)); 17054c8945a0SNathan Whitehorn 17064c8945a0SNathan Whitehorn #if defined(ENABLE_NLS) 17074c8945a0SNathan Whitehorn /* initialize locale support */ 17084c8945a0SNathan Whitehorn setlocale(LC_ALL, ""); 17097a1c0d96SNathan Whitehorn bindtextdomain(NLS_TEXTDOMAIN, LOCALEDIR); 17107a1c0d96SNathan Whitehorn textdomain(NLS_TEXTDOMAIN); 17114c8945a0SNathan Whitehorn #elif defined(HAVE_SETLOCALE) 17124c8945a0SNathan Whitehorn (void) setlocale(LC_ALL, ""); 17134c8945a0SNathan Whitehorn #endif 17144c8945a0SNathan Whitehorn 17154c8945a0SNathan Whitehorn unescape_argv(&argc, &argv); 17164c8945a0SNathan Whitehorn program = argv[0]; 17174c8945a0SNathan Whitehorn dialog_state.output = stderr; 17184c8945a0SNathan Whitehorn dialog_state.input = stdin; 17194c8945a0SNathan Whitehorn 17204c8945a0SNathan Whitehorn /* 17214c8945a0SNathan Whitehorn * Look for the last --stdout, --stderr or --output-fd option, and use 17224c8945a0SNathan Whitehorn * that. We can only write to one of them. If --stdout is used, that 17234c8945a0SNathan Whitehorn * can interfere with initializing the curses library, so we want to 17244c8945a0SNathan Whitehorn * know explicitly if it is used. 1725682c9e0fSNathan Whitehorn * 1726682c9e0fSNathan Whitehorn * Also, look for any --version or --help message, processing those 1727682c9e0fSNathan Whitehorn * immediately. 17284c8945a0SNathan Whitehorn */ 17294c8945a0SNathan Whitehorn while (offset < argc) { 17304c8945a0SNathan Whitehorn int base = offset; 17314c8945a0SNathan Whitehorn switch (lookupOption(argv[offset], 7)) { 17324c8945a0SNathan Whitehorn case o_stdout: 17334c8945a0SNathan Whitehorn dialog_state.output = stdout; 17344c8945a0SNathan Whitehorn break; 17354c8945a0SNathan Whitehorn case o_stderr: 17364c8945a0SNathan Whitehorn dialog_state.output = stderr; 17374c8945a0SNathan Whitehorn break; 17384c8945a0SNathan Whitehorn case o_input_fd: 17394c8945a0SNathan Whitehorn if ((j = optionValue(argv, &offset)) < 0 17404c8945a0SNathan Whitehorn || (dialog_state.input = fdopen(j, "r")) == 0) 17414c8945a0SNathan Whitehorn dlg_exiterr("Cannot open input-fd\n"); 17424c8945a0SNathan Whitehorn break; 17434c8945a0SNathan Whitehorn case o_output_fd: 17444c8945a0SNathan Whitehorn if ((j = optionValue(argv, &offset)) < 0 17454c8945a0SNathan Whitehorn || (dialog_state.output = fdopen(j, "w")) == 0) 17464c8945a0SNathan Whitehorn dlg_exiterr("Cannot open output-fd\n"); 17474c8945a0SNathan Whitehorn break; 17484c8945a0SNathan Whitehorn case o_keep_tite: 17494c8945a0SNathan Whitehorn keep_tite = TRUE; 17504c8945a0SNathan Whitehorn break; 1751682c9e0fSNathan Whitehorn case o_version: 1752682c9e0fSNathan Whitehorn dialog_state.output = stdout; 1753682c9e0fSNathan Whitehorn PrintVersion(dialog_state.output); 1754682c9e0fSNathan Whitehorn exit(DLG_EXIT_OK); 1755682c9e0fSNathan Whitehorn break; 1756682c9e0fSNathan Whitehorn case o_help: 1757682c9e0fSNathan Whitehorn Help(); 1758682c9e0fSNathan Whitehorn break; 17592a3e3873SBaptiste Daroussin #ifdef HAVE_DLG_TRACE 17602a3e3873SBaptiste Daroussin case o_trace: 17612a3e3873SBaptiste Daroussin /* 17622a3e3873SBaptiste Daroussin * Process/remove the --trace option if it is the first option. 17632a3e3873SBaptiste Daroussin * Otherwise, process it in more/less expected order as a 17642a3e3873SBaptiste Daroussin * "common" option. 17652a3e3873SBaptiste Daroussin */ 17662a3e3873SBaptiste Daroussin if (base == 1) { 17672a3e3873SBaptiste Daroussin process_trace_option(argv, &offset); 17682a3e3873SBaptiste Daroussin break; 17692a3e3873SBaptiste Daroussin } else { 17702a3e3873SBaptiste Daroussin ++offset; 17712a3e3873SBaptiste Daroussin continue; 17722a3e3873SBaptiste Daroussin } 17732a3e3873SBaptiste Daroussin #endif 17744c8945a0SNathan Whitehorn default: 17754c8945a0SNathan Whitehorn ++offset; 17764c8945a0SNathan Whitehorn continue; 17774c8945a0SNathan Whitehorn } 17782a3e3873SBaptiste Daroussin dlg_trace_msg("# discarding %d parameters starting with argv[%d] (%s)\n", 17792a3e3873SBaptiste Daroussin 1 + offset - base, base, 17802a3e3873SBaptiste Daroussin argv[base]); 17814c8945a0SNathan Whitehorn for (j = base; j < argc; ++j) { 17824c8945a0SNathan Whitehorn dialog_argv[j] = dialog_argv[j + 1 + (offset - base)]; 17834c8945a0SNathan Whitehorn if (dialog_opts != 0) 17844c8945a0SNathan Whitehorn dialog_opts[j] = dialog_opts[j + 1 + (offset - base)]; 17854c8945a0SNathan Whitehorn } 17864c8945a0SNathan Whitehorn argc -= (1 + offset - base); 17874c8945a0SNathan Whitehorn offset = base; 17884c8945a0SNathan Whitehorn } 17894c8945a0SNathan Whitehorn offset = 1; 17904c8945a0SNathan Whitehorn init_result(my_buffer); 17914c8945a0SNathan Whitehorn 1792682c9e0fSNathan Whitehorn /* 1793682c9e0fSNathan Whitehorn * Dialog's output may be redirected (see above). Handle the special 1794682c9e0fSNathan Whitehorn * case of options that only report information without interaction. 1795682c9e0fSNathan Whitehorn */ 1796682c9e0fSNathan Whitehorn if (argc == 2) { 17974c8945a0SNathan Whitehorn switch (lookupOption(argv[1], 7)) { 17984c8945a0SNathan Whitehorn case o_print_maxsize: 17994c8945a0SNathan Whitehorn (void) initscr(); 18004c8945a0SNathan Whitehorn endwin(); 18014c8945a0SNathan Whitehorn fflush(dialog_state.output); 18024c8945a0SNathan Whitehorn fprintf(dialog_state.output, "MaxSize: %d, %d\n", SLINES, SCOLS); 18034c8945a0SNathan Whitehorn break; 18044c8945a0SNathan Whitehorn case o_print_version: 1805682c9e0fSNathan Whitehorn PrintVersion(dialog_state.output); 18064c8945a0SNathan Whitehorn break; 18074c8945a0SNathan Whitehorn case o_clear: 18084c8945a0SNathan Whitehorn initscr(); 18094c8945a0SNathan Whitehorn refresh(); 18104c8945a0SNathan Whitehorn endwin(); 18114c8945a0SNathan Whitehorn break; 18124c8945a0SNathan Whitehorn case o_ignore: 18134c8945a0SNathan Whitehorn break; 18144c8945a0SNathan Whitehorn default: 18154c8945a0SNathan Whitehorn Help(); 18164c8945a0SNathan Whitehorn break; 18174c8945a0SNathan Whitehorn } 18184c8945a0SNathan Whitehorn return DLG_EXIT_OK; 18194c8945a0SNathan Whitehorn } 18204c8945a0SNathan Whitehorn 18214c8945a0SNathan Whitehorn if (argc < 2) { 18224c8945a0SNathan Whitehorn Help(); 18234c8945a0SNathan Whitehorn } 18244c8945a0SNathan Whitehorn #ifdef HAVE_RC_FILE 18254c8945a0SNathan Whitehorn if (lookupOption(argv[1], 7) == o_create_rc) { 18264c8945a0SNathan Whitehorn if (argc != 3) { 18274c8945a0SNathan Whitehorn sprintf(temp, "Expected a filename for %.50s", argv[1]); 18284c8945a0SNathan Whitehorn Usage(temp); 18294c8945a0SNathan Whitehorn } 18304c8945a0SNathan Whitehorn if (dlg_parse_rc() == -1) /* Read the configuration file */ 18314c8945a0SNathan Whitehorn dlg_exiterr("dialog: dlg_parse_rc"); 18324c8945a0SNathan Whitehorn dlg_create_rc(argv[2]); 18334c8945a0SNathan Whitehorn return DLG_EXIT_OK; 18344c8945a0SNathan Whitehorn } 18354c8945a0SNathan Whitehorn #endif 18364c8945a0SNathan Whitehorn 18374c8945a0SNathan Whitehorn dialog_vars.keep_tite = keep_tite; /* init_result() cleared global */ 18384c8945a0SNathan Whitehorn 18394c8945a0SNathan Whitehorn init_dialog(dialog_state.input, dialog_state.output); 18404c8945a0SNathan Whitehorn 18414c8945a0SNathan Whitehorn while (offset < argc && !esc_pressed) { 18424c8945a0SNathan Whitehorn init_result(my_buffer); 18434c8945a0SNathan Whitehorn 18444c8945a0SNathan Whitehorn offset = process_common_options(argc, argv, offset, TRUE); 18454c8945a0SNathan Whitehorn 18464c8945a0SNathan Whitehorn if (argv[offset] == NULL) { 18474c8945a0SNathan Whitehorn if (ignore_unknown) 18484c8945a0SNathan Whitehorn break; 18494c8945a0SNathan Whitehorn Usage("Expected a box option"); 18504c8945a0SNathan Whitehorn } 18514c8945a0SNathan Whitehorn 18524c8945a0SNathan Whitehorn if (lookupOption(argv[offset], 2) != o_checklist 18534c8945a0SNathan Whitehorn && dialog_vars.separate_output) { 18544c8945a0SNathan Whitehorn sprintf(temp, "Expected --checklist, not %.20s", argv[offset]); 18554c8945a0SNathan Whitehorn Usage(temp); 18564c8945a0SNathan Whitehorn } 18574c8945a0SNathan Whitehorn 18584c8945a0SNathan Whitehorn if (dialog_state.aspect_ratio == 0) 18594c8945a0SNathan Whitehorn dialog_state.aspect_ratio = DEFAULT_ASPECT_RATIO; 18604c8945a0SNathan Whitehorn 18614c8945a0SNathan Whitehorn dlg_put_backtitle(); 18624c8945a0SNathan Whitehorn 18634c8945a0SNathan Whitehorn /* use a table to look for the requested mode, to avoid code duplication */ 18644c8945a0SNathan Whitehorn 18654c8945a0SNathan Whitehorn modePtr = 0; 18664c8945a0SNathan Whitehorn if ((code = lookupOption(argv[offset], 2)) != o_unknown) 18674c8945a0SNathan Whitehorn modePtr = lookupMode(code); 18684c8945a0SNathan Whitehorn if (modePtr == 0) { 18694c8945a0SNathan Whitehorn sprintf(temp, "%s option %.20s", 18704c8945a0SNathan Whitehorn lookupOption(argv[offset], 7) != o_unknown 18714c8945a0SNathan Whitehorn ? "Unexpected" 18724c8945a0SNathan Whitehorn : "Unknown", 18734c8945a0SNathan Whitehorn argv[offset]); 18744c8945a0SNathan Whitehorn Usage(temp); 18754c8945a0SNathan Whitehorn } 18764c8945a0SNathan Whitehorn 18774c8945a0SNathan Whitehorn have = arg_rest(&argv[offset]); 18784c8945a0SNathan Whitehorn if (have < modePtr->argmin) { 18794c8945a0SNathan Whitehorn sprintf(temp, "Expected at least %d tokens for %.20s, have %d", 18804c8945a0SNathan Whitehorn modePtr->argmin - 1, argv[offset], 18814c8945a0SNathan Whitehorn have - 1); 18824c8945a0SNathan Whitehorn Usage(temp); 18834c8945a0SNathan Whitehorn } 18844c8945a0SNathan Whitehorn if (modePtr->argmax && have > modePtr->argmax) { 18854c8945a0SNathan Whitehorn sprintf(temp, 18864c8945a0SNathan Whitehorn "Expected no more than %d tokens for %.20s, have %d", 18874c8945a0SNathan Whitehorn modePtr->argmax - 1, argv[offset], 18884c8945a0SNathan Whitehorn have - 1); 18894c8945a0SNathan Whitehorn Usage(temp); 18904c8945a0SNathan Whitehorn } 18914c8945a0SNathan Whitehorn 18924c8945a0SNathan Whitehorn /* 18934c8945a0SNathan Whitehorn * Trim whitespace from non-title option values, e.g., the ones that 18944c8945a0SNathan Whitehorn * will be used as captions or prompts. Do that only for the widget 18954c8945a0SNathan Whitehorn * we are about to process, since the "--trim" option is reset before 18964c8945a0SNathan Whitehorn * accumulating options for each widget. 18974c8945a0SNathan Whitehorn */ 18984c8945a0SNathan Whitehorn for (j = offset + 1; j <= offset + have; j++) { 18994c8945a0SNathan Whitehorn switch (lookupOption(argv[j - 1], 7)) { 19004c8945a0SNathan Whitehorn case o_unknown: 19014c8945a0SNathan Whitehorn case o_title: 19024c8945a0SNathan Whitehorn case o_backtitle: 1903682c9e0fSNathan Whitehorn case o_help_line: 1904682c9e0fSNathan Whitehorn case o_help_file: 19054c8945a0SNathan Whitehorn break; 19064c8945a0SNathan Whitehorn default: 19074c8945a0SNathan Whitehorn if (argv[j] != 0) { 19082a3e3873SBaptiste Daroussin char *argv_j = strdup(argv[j]); 19092a3e3873SBaptiste Daroussin if (argv_j != 0) { 19102a3e3873SBaptiste Daroussin dlg_trim_string(argv_j); 19112a3e3873SBaptiste Daroussin argv[j] = argv_j; 19122a3e3873SBaptiste Daroussin } else { 19132a3e3873SBaptiste Daroussin argv[j] = strdup("?"); 19142a3e3873SBaptiste Daroussin } 19154c8945a0SNathan Whitehorn } 19164c8945a0SNathan Whitehorn break; 19174c8945a0SNathan Whitehorn } 19184c8945a0SNathan Whitehorn } 19194c8945a0SNathan Whitehorn 19204c8945a0SNathan Whitehorn retval = show_result((*(modePtr->jumper)) (dialog_vars.title, 19214c8945a0SNathan Whitehorn argv + offset, 19224c8945a0SNathan Whitehorn &offset_add)); 19232a3e3873SBaptiste Daroussin dlg_trace_msg("# widget returns %d\n", retval); 19244c8945a0SNathan Whitehorn offset += offset_add; 19254c8945a0SNathan Whitehorn 19267a1c0d96SNathan Whitehorn if (dialog_vars.input_result != my_buffer) { 19274c8945a0SNathan Whitehorn free(dialog_vars.input_result); 19287a1c0d96SNathan Whitehorn dialog_vars.input_result = 0; 19297a1c0d96SNathan Whitehorn } 19304c8945a0SNathan Whitehorn 19314c8945a0SNathan Whitehorn if (retval == DLG_EXIT_ESC) { 19324c8945a0SNathan Whitehorn esc_pressed = TRUE; 19334c8945a0SNathan Whitehorn } else { 19344c8945a0SNathan Whitehorn 19354c8945a0SNathan Whitehorn if (dialog_vars.beep_after_signal) 19364c8945a0SNathan Whitehorn (void) beep(); 19374c8945a0SNathan Whitehorn 19384c8945a0SNathan Whitehorn if (dialog_vars.sleep_secs) 19394c8945a0SNathan Whitehorn (void) napms(dialog_vars.sleep_secs * 1000); 19404c8945a0SNathan Whitehorn 19414c8945a0SNathan Whitehorn if (offset < argc) { 19424c8945a0SNathan Whitehorn switch (lookupOption(argv[offset], 7)) { 19434c8945a0SNathan Whitehorn case o_and_widget: 19444c8945a0SNathan Whitehorn offset++; 19454c8945a0SNathan Whitehorn break; 19464c8945a0SNathan Whitehorn case o_unknown: 19474c8945a0SNathan Whitehorn sprintf(temp, "Expected --and-widget, not %.20s", 19484c8945a0SNathan Whitehorn argv[offset]); 19494c8945a0SNathan Whitehorn Usage(temp); 19504c8945a0SNathan Whitehorn break; 19514c8945a0SNathan Whitehorn default: 19524c8945a0SNathan Whitehorn /* if we got a cancel, etc., stop chaining */ 19534c8945a0SNathan Whitehorn if (retval != DLG_EXIT_OK) 19544c8945a0SNathan Whitehorn esc_pressed = TRUE; 19554c8945a0SNathan Whitehorn else 19564c8945a0SNathan Whitehorn dialog_vars.dlg_clear_screen = TRUE; 19574c8945a0SNathan Whitehorn break; 19584c8945a0SNathan Whitehorn } 19594c8945a0SNathan Whitehorn } 19604c8945a0SNathan Whitehorn if (dialog_vars.dlg_clear_screen) 19614c8945a0SNathan Whitehorn dlg_clear(); 19624c8945a0SNathan Whitehorn } 19634c8945a0SNathan Whitehorn } 19644c8945a0SNathan Whitehorn 19654c8945a0SNathan Whitehorn dlg_killall_bg(&retval); 19664c8945a0SNathan Whitehorn if (dialog_state.screen_initialized) { 19674c8945a0SNathan Whitehorn (void) refresh(); 19684c8945a0SNathan Whitehorn end_dialog(); 19694c8945a0SNathan Whitehorn } 19704c8945a0SNathan Whitehorn dlg_exit(retval); 19714c8945a0SNathan Whitehorn } 1972