2 * $Id: dialog.c,v 1.289 2022/07/28 21:11:36 tom Exp $
4 * cdialog - Display simple dialog boxes from shell scripts
6 * Copyright 2000-2021,2022 Thomas E. Dickey
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License, version 2.1
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this program; if not, write to
19 * Free Software Foundation, Inc.
20 * 51 Franklin St., Fifth Floor
21 * Boston, MA 02110, USA.
23 * An earlier version of this program lists as authors
24 * Savio Lam (lam836@cs.cuhk.hk)
27 #include <dlg_internals.h>
29 #define USEMAX_ARGS 20
30 #define USEMAX_FILE 50
32 #define PASSARGS t, av, offset_add
33 #define CALLARGS const char *t, char *av[], int *offset_add
34 typedef int (callerFn
) (CALLARGS
);
161 #if defined(HAVE_XDIALOG2) || defined(HAVE_WHIPTAIL)
165 #ifdef HAVE_DLG_TRACE
180 * The bits in 'pass' are used to decide which options are applicable at
181 * different stages in the program:
182 * 1 flags before widgets
184 * 4 non-widget options
189 int vars
; /* 0=none, 1=state, 2=vars */
190 tOptions type
; /* type for bool(true/false), number, string */
192 int pass
; /* 1,2,4 or combination */
193 const char *help
; /* NULL to suppress, non-empty to display params */
202 /* use these macros for simple options in DIALOG_STATE */
203 #define ssF(name) o_##name, 1, tFalse, offsetof(DIALOG_STATE,name)
204 #define ssT(name) o_##name, 1, tTrue, offsetof(DIALOG_STATE,name)
205 #define ssN(name) o_##name, 1, tNumber, offsetof(DIALOG_STATE,name)
206 #define ssS(name) o_##name, 1, tString, offsetof(DIALOG_STATE,name)
208 /* use these macros for simple options in DIALOG_VARS */
209 #define svF(name) o_##name, 2, tFalse, offsetof(DIALOG_VARS,name)
210 #define svT(name) o_##name, 2, tTrue, offsetof(DIALOG_VARS,name)
211 #define svN(name) o_##name, 2, tNumber, offsetof(DIALOG_VARS,name)
212 #define svS(name) o_##name, 2, tString, offsetof(DIALOG_VARS,name)
214 /* use these macros for ignored options */
215 #define xxF(name) o_##name, 0, tFalse, 0
216 #define xxT(name) o_##name, 0, tTrue, 0
217 #define xxN(name) o_##name, 0, tNumber, 0
218 #define xxS(name) o_##name, 0, tString, 0
220 /* use this macro for widget options */
221 #define opW(name) o_##name, 0, 0, 0
223 /* use this macro for other options */
224 #define opO(name) o_##name, 0, 0, 0
226 static int known_opts
= 0;
227 static const char **dialog_opts
;
228 static char **dialog_argv
;
230 static char **special_argv
= 0;
231 static int special_argc
= 0;
233 static bool ignore_unknown
= FALSE
;
235 static const char *program
= "dialog";
238 typedef struct _all_blobs
{
239 struct _all_blobs
*next
;
243 static AllBlobs
*all_blobs
;
247 * The options[] table is organized this way to make it simple to maintain
248 * a sorted list of options for the help-message.
250 * Because Boolean options correspond to "true", --shadow is listed here while
251 * --no-shadow is not. The findOption and optionBool functions handle the
252 * cases where "no" is added or removed from the option name to derive an
256 static const Options options
[] = {
257 { "allow-close", xxT(allow_close
), 1, NULL
},
258 { "and-widget", opO(and_widget
), 4, NULL
},
259 { "ascii-lines", svT(ascii_lines
), 1, "" },
260 { "aspect", ssN(aspect_ratio
), 1, "<ratio>" },
261 { "auto-placement", xxT(auto_placement
), 1, NULL
},
262 { "backtitle", svS(backtitle
), 1, "<backtitle>" },
263 { "beep", svT(beep_signal
), 1, "" },
264 { "beep-after", svT(beep_after_signal
), 1, "" },
265 { "begin", svT(begin_set
), 1, "<y> <x>" },
266 { "cancel-label", svS(cancel_label
), 1, "<str>" },
267 { "checklist", opW(checklist
), 2, "<text> <height> <width> <list height> <tag1> <item1> <status1>..." },
268 { "clear", svT(dlg_clear_screen
), 1, "" },
269 { "colors", svT(colors
), 1, "" },
270 { "column-separator",svS(column_separator
), 1, "<str>" },
271 { "cr-wrap", svT(cr_wrap
), 1, "" },
272 { "create-rc", opO(create_rc
), 1, NULL
},
273 { "cursor-off-label",svT(cursor_off_label
), 1, "" },
274 { "date-format", svS(date_format
), 1, "<str>" },
275 { "default-button", xxS(default_button
), 1, "<str>" },
276 { "default-item", svS(default_item
), 1, "<str>" },
277 { "defaultno", svT(defaultno
), 1, "" },
278 { "erase-on-exit", svT(erase_on_exit
), 1, "" },
279 { "exit-label", svS(exit_label
), 1, "<str>" },
280 { "extra-button", svT(extra_button
), 1, "" },
281 { "extra-label", svS(extra_label
), 1, "<str>" },
282 { "fixed-font", xxT(fixed_font
), 1, NULL
},
283 { "form", opW(form
), 2, "<text> <height> <width> <form height> <label1> <l_y1> <l_x1> <item1> <i_y1> <i_x1> <flen1> <ilen1>..." },
284 { "gauge", opW(gauge
), 2, "<text> <height> <width> [<percent>]" },
285 { "guage", opW(gauge
), 2, NULL
},
286 { "help", opO(help
), 4, "" },
287 { "help-button", svT(help_button
), 1, "" },
288 { "help-label", svS(help_label
), 1, "<str>" },
289 { "help-status", svT(help_status
), 1, "" },
290 { "help-tags", svT(help_tags
), 1, "" },
291 { "hfile", svS(help_file
), 1, "<str>" },
292 { "hline", svS(help_line
), 1, "<str>" },
293 { "icon", xxS(icon
), 1, NULL
},
294 { "ignore", opO(ignore
), 1, "" },
295 { "infobox", opW(infobox
), 2, "<text> <height> <width>" },
296 { "input-fd", opO(input_fd
), 1, "<fd>" },
297 { "inputbox", opW(inputbox
), 2, "<text> <height> <width> [<init>]" },
298 { "inputmenu", opW(inputmenu
), 2, "<text> <height> <width> <menu height> <tag1> <item1>..." },
299 { "insecure", svT(insecure
), 1, "" },
300 { "item-help", svT(item_help
), 1, "" },
301 { "keep-colors", xxT(keep_colors
), 1, NULL
},
302 { "keep-tite", svT(keep_tite
), 1, "" },
303 { "keep-window", svT(keep_window
), 1, "" },
304 { "last-key", svT(last_key
), 1, "" },
305 { "max-input", svN(max_input
), 1, "<n>" },
306 { "menu", opW(menu
), 2, "<text> <height> <width> <menu height> <tag1> <item1>..." },
307 { "mixedform", opW(mixedform
), 2, "<text> <height> <width> <form height> <label1> <l_y1> <l_x1> <item1> <i_y1> <i_x1> <flen1> <ilen1> <itype>..." },
308 { "mixedgauge", opW(mixedgauge
), 2, "<text> <height> <width> <percent> <tag1> <item1>..." },
309 { "msgbox", opW(msgbox
), 2, "<text> <height> <width>" },
310 { "no-cancel", svT(nocancel
), 1, "" },
311 { "no-close", xxT(no_close
), 1, NULL
},
312 { "no-collapse", svT(nocollapse
), 1, "" },
313 { "no-hot-list", svT(no_hot_list
), 1, "" },
314 { "no-kill", svT(cant_kill
), 1, "" },
315 { "no-label", svS(no_label
), 1, "<str>" },
316 { "no-lines", svT(no_lines
), 1, "" },
317 { "no-mouse", ssT(no_mouse
), 1, "" },
318 { "no-nl-expand", svT(no_nl_expand
), 1, "" },
319 { "no-ok", svT(nook
), 1, "" },
320 { "no-shadow", ssF(use_shadow
), 1, "" },
321 { "ok-label", svS(ok_label
), 1, "<str>" },
322 { "output-fd", opO(output_fd
), 1, "<fd>" },
323 { "output-separator",svS(output_separator
), 1, "<str>" },
324 { "passwordbox", opW(passwordbox
), 2, "<text> <height> <width> [<init>]" },
325 { "passwordform", opW(passwordform
), 2, "<text> <height> <width> <form height> <label1> <l_y1> <l_x1> <item1> <i_y1> <i_x1> <flen1> <ilen1>..." },
326 { "pause", opW(pause
), 2, "<text> <height> <width> <seconds>" },
327 { "prgbox", opW(prgbox
), 2, "<text> <command> <height> <width>" },
328 { "print-maxsize", opO(print_maxsize
), 1, "" },
329 { "print-size", svT(print_siz
), 1, "" },
330 { "print-text-only",ssT(text_only
), 5, "<text> <height> <width>" },
331 { "print-text-size",opO(print_text_size
), 5, "<text> <height> <width>" },
332 { "print-version", opO(print_version
), 5, "" },
333 { "programbox", opW(programbox
), 2, "<text> <height> <width>" },
334 { "progressbox", opW(progressbox
), 2, "<text> <height> <width>" },
335 { "quoted", svT(quoted
), 1, "" },
336 { "radiolist", opW(radiolist
), 2, "<text> <height> <width> <list height> <tag1> <item1> <status1>..." },
337 { "screen-center", xxT(screen_center
), 1, NULL
},
338 { "scrollbar", ssT(use_scrollbar
), 1, "" },
339 { "separate-output",svT(separate_output
), 1, "" },
340 { "separate-widget",ssS(separate_str
), 1, "<str>" },
341 { "separator", svS(output_separator
), 1, NULL
},
342 { "single-quoted", svT(single_quoted
), 1, "" },
343 { "size-err", svT(size_err
), 1, "" },
344 { "sleep", svN(sleep_secs
), 1, "<secs>" },
345 { "smooth", xxT(smooth
), 1, NULL
},
346 { "stderr", opO(output_stderr
), 1, "" },
347 { "stdout", opO(output_stdout
), 1, "" },
348 { "tab-correct", svT(tab_correct
), 1, "" },
349 { "tab-len", ssN(tab_len
), 1, "<n>" },
350 { "tailbox", opW(tailbox
), 2, "<file> <height> <width>" },
351 { "tailboxbg", opW(tailboxbg
), 2, "<file> <height> <width>" },
352 { "textbox", opW(textbox
), 2, "<file> <height> <width>" },
353 { "time-format", svS(time_format
), 1, "<str>" },
354 { "timeout", svN(timeout_secs
), 1, "<secs>" },
355 { "title", svS(title
), 1, "<title>" },
356 { "trim", svT(trim_whitespace
), 1, "" },
357 { "under-mouse", xxT(under_mouse
), 1, NULL
},
358 { "version", opO(version
), 5, "" },
359 { "visit-items", ssT(visit_items
), 1, "" },
360 { "wmclass", xxS(wmclass
), 1, NULL
},
361 { "yes-label", svS(yes_label
), 1, "<str>" },
362 { "yesno", opW(yesno
), 2, "<text> <height> <width>" },
364 { "cancel-button", svS(cancel_label
), 1, NULL
},
365 { "fb", xxT(fullbutton
), 1, NULL
},
366 { "fullbutton", xxT(fullbutton
), 1, NULL
},
367 { "no-button", svS(no_label
), 1, NULL
},
368 { "ok-button", svS(ok_label
), 1, NULL
},
369 { "scrolltext", ssT(use_scrollbar
), 1, NULL
},
370 { "topleft", svT(begin_set
), 1, NULL
},
371 { "yes-button", svS(yes_label
), 1, NULL
},
374 { "calendar", opW(calendar
), 2, "<text> <height> <width> <day> <month> <year>" },
375 { "dselect", opW(dselect
), 2, "<directory> <height> <width>" },
376 { "editbox", opW(editbox
), 2, "<file> <height> <width>" },
377 { "fselect", opW(fselect
), 2, "<filepath> <height> <width>" },
378 { "timebox", opW(timebox
), 2, "<text> <height> <width> <hour> <minute> <second>" },
379 { "week-start", svS(week_start
), 1, "<str>" },
380 { "iso-week", svT(iso_week
), 1, NULL
},
383 { "buildlist", opW(buildlist
), 2, "<text> <height> <width> <list-height> <tag1> <item1> <status1>..." },
384 { "no-items", svT(no_items
), 1, "" },
385 { "no-tags", svT(no_tags
), 1, "" },
386 { "rangebox", opW(rangebox
), 2, "<text> <height> <width> <min-value> <max-value> <default-value>" },
387 { "reorder", svT(reorder
), 1, "" },
388 { "treeview", opW(treeview
), 2, "<text> <height> <width> <list-height> <tag1> <item1> <status1> <depth1>..." },
390 #if defined(HAVE_XDIALOG2) || defined(HAVE_WHIPTAIL)
391 { "noitem", svT(no_items
), 1, NULL
},
392 { "notags", svT(no_tags
), 1, NULL
},
394 #ifdef HAVE_DLG_TRACE
395 { "trace", opO(trace
), 1, "<file>" },
402 ignore_leak(void *value
)
404 AllBlobs
*next
= dlg_calloc(AllBlobs
, (size_t) 1);
407 next
->next
= all_blobs
;
415 while (all_blobs
!= 0) {
416 char *blob
= all_blobs
->blob
;
417 AllBlobs
*next
= all_blobs
->next
;
423 if (special_argv
!= 0) {
424 free(special_argv
[0]);
431 #define handle_leaks() /* nothing */
432 #define ignore_leak(n) /* nothing */
435 #define OptionChars "\
438 abcdefghijklmnopqrstuvwxyz\
442 * Check if the given string from main's argv is an option.
445 isOption(const char *arg
)
450 if (dialog_opts
!= 0) {
452 for (n
= 0; dialog_opts
[n
] != 0; ++n
) {
453 if (dialog_opts
[n
] == arg
) {
458 } else if (!strncmp(arg
, "--", (size_t) 2) && isalpha(UCH(arg
[2]))) {
459 if (strlen(arg
) == (strspn
) (arg
, OptionChars
)) {
463 dlg_exiterr(_("Invalid option \"%s\""), arg
);
471 * Make an array showing which argv[] entries are options. Use "--" as a
472 * special token to escape the next argument, allowing it to begin with "--".
473 * When we find a "--" argument, also remove it from argv[] and adjust argc.
474 * That appears to be an undocumented feature of the popt library.
476 * Also, if we see a "--file", expand it into the parameter list by reading the
477 * text from the given file and stripping quotes, treating whitespace outside
478 * quotes as a parameter delimiter.
480 * Finally, if we see a "--args", dump the current list of arguments to the
481 * standard error. This is used for debugging complex --file combinations.
484 unescape_argv(int *argcp
, char ***argvp
)
487 int limit_includes
= 20 + *argcp
;
488 int count_includes
= 0;
489 bool doalloc
= FALSE
;
491 const char **my_argv
= 0;
494 DLG_TRACE(("# unescape_argv\n"));
495 for (k
= 0; k
< 2; ++k
) {
498 if (special_argv
!= 0) {
499 for (j
= 0; special_argv
[j
] != 0; ++j
) {
500 if (!strcmp(special_argv
[j
], "--")) {
502 } else if (isOption(special_argv
[j
])) {
504 my_argv
[my_argc
] = special_argv
[j
];
511 my_argc
+= (*argcp
+ 1);
512 my_argv
= dlg_calloc(const char *, (size_t) my_argc
);
513 assert_ptr(my_argv
, "unescape_argv");
517 for (j
= 1; j
< *argcp
; j
++) {
518 bool escaped
= FALSE
;
519 if (!strcmp((*argvp
)[j
], "--")) {
521 dlg_eat_argv(argcp
, argvp
, j
, 1);
522 } else if (!strcmp((*argvp
)[j
], "--args")) {
523 fprintf(stderr
, _("Showing arguments at arg%d\n"), j
);
524 for (k
= 0; k
< *argcp
; ++k
) {
525 fprintf(stderr
, " arg%d:%s\n", k
, (*argvp
)[k
]);
527 dlg_eat_argv(argcp
, argvp
, j
, 1);
529 } else if (!strcmp((*argvp
)[j
], "--file")) {
530 if (++count_includes
> limit_includes
) {
532 dlg_exiterr(_("Too many --file options"));
535 if ((filename
= (*argvp
)[j
+ 1]) != 0) {
539 if (*filename
== '&') {
540 fp
= fdopen(atoi(filename
+ sizeof(char)), "r");
542 fp
= fopen(filename
, "r");
552 DLG_TRACE(("# opened --file %s ..\n", filename
));
556 blob
= dlg_realloc(char, length
+ BUFSIZ
+ 1, blob
);
557 assert_ptr(blob
, "unescape_argv");
558 bytes_read
= fread(blob
+ length
,
562 length
+= bytes_read
;
565 dlg_exiterr(_("error on filehandle in unescape_argv"));
567 } while (bytes_read
== BUFSIZ
);
573 list
= dlg_string_to_argv(blob
);
574 added
= dlg_count_argv(list
);
576 /* *argcp arguments before the expansion of --file
577 - 2 for the removal of '--file <filepath>'
578 + added for the arguments contained in <filepath>
579 + 1 for the terminating NULL pointer */
580 size_t need
= (size_t) (*argcp
+ added
- 1);
582 *argvp
= dlg_realloc(char *, need
, *argvp
);
583 assert_ptr(*argvp
, "unescape_argv");
585 char **newp
= dlg_malloc(char *, need
);
587 assert_ptr(newp
, "unescape_argv");
588 for (n
= 0; n
< *argcp
; ++n
) {
589 newp
[n
] = (*argvp
)[n
];
591 /* The new array is not NULL-terminated yet. */
595 my_argv
= dlg_realloc(const char *, need
, my_argv
);
596 assert_ptr(my_argv
, "unescape_argv");
598 /* Shift the arguments after '--file <filepath>'
599 right by (added - 2) positions */
600 for (n
= *argcp
- 1; n
>= j
+ 2; --n
) {
601 (*argvp
)[n
+ added
- 2] = (*argvp
)[n
];
603 } else if (added
< 2) {
604 /* 0 or 1 argument read from the included file
605 -> shift the arguments after '--file <filepath>'
606 left by (2 - added) positions */
607 for (n
= j
+ added
; n
+ 2 - added
< *argcp
; ++n
) {
608 (*argvp
)[n
] = (*argvp
)[n
+ 2 - added
];
611 /* Copy the inserted arguments to *argvp */
612 for (n
= 0; n
< added
; ++n
) {
613 (*argvp
)[n
+ j
] = list
[n
];
616 (*argvp
)[*argcp
] = 0; /* Write the NULL terminator */
617 free(list
); /* No-op if 'list' is NULL */
618 /* Force rescan starting from the first inserted argument */
620 DLG_TRACE(("# finished --file\n"));
624 dlg_exiterr(_("Cannot open --file %s"), filename
);
628 dlg_exiterr(_("No value given for --file"));
633 && !strncmp((*argvp
)[j
], "--", (size_t) 2)
634 && isalpha(UCH((*argvp
)[j
][2]))) {
635 my_argv
[my_argc
++] = (*argvp
)[j
];
636 DLG_TRACE(("#\toption argv[%d]=%s\n", j
, (*argvp
)[j
]));
640 my_argv
[my_argc
] = 0;
642 known_opts
= my_argc
;
643 dialog_opts
= my_argv
;
645 DLG_TRACE(("#\t%d options vs %d arguments\n", known_opts
, *argcp
));
646 dialog_argv
= (*argvp
);
649 static const Options
*
650 findOption(const char *name
, int pass
, bool recur
)
652 const Options
*result
= NULL
;
654 if (!strncmp(name
, "--", 2) && isalpha(UCH(name
[2]))) {
657 name
+= 2; /* skip the "--" */
658 for (n
= 0; n
< TableSize(options
); n
++) {
659 if ((pass
& options
[n
].pass
) != 0
660 && !strcmp(name
, options
[n
].name
)) {
661 result
= &options
[n
];
665 if (result
== NULL
&& !recur
) {
666 char *temp
= malloc(8 + strlen(name
));
668 if (!strncmp(name
, "no", 2)) {
669 int skip
= !strncmp(name
, "no-", 3) ? 3 : 2;
670 sprintf(temp
, "--no-%s", name
+ skip
);
671 result
= findOption(temp
, pass
, TRUE
);
672 if (result
== NULL
) {
673 sprintf(temp
, "--%s", name
+ skip
);
674 result
= findOption(temp
, pass
, TRUE
);
677 if (result
== NULL
&& strncmp(name
, "no", 2)) {
678 sprintf(temp
, "--no-%s", name
);
679 result
= findOption(temp
, pass
, TRUE
);
689 lookupOption(const char *name
, int pass
)
691 eOptions result
= o_unknown
;
692 const Options
*data
= findOption(name
, pass
, FALSE
);
700 Usage(const char *msg
)
703 dlg_exiterr(_("%s.\nUse --help to list options.\n\n"), msg
);
707 * Count arguments, stopping at the end of the argument list, or on any of our
711 arg_rest(char *argv
[])
713 int i
= 1; /* argv[0] points to a "--" token */
716 && (!isOption(argv
[i
]) || lookupOption(argv
[i
], 7) == o_unknown
))
722 * In MultiWidget this function is needed to count how many tags
723 * a widget (menu, checklist, radiolist) has
726 howmany_tags(char *argv
[], int group
)
731 while (argv
[0] != 0) {
734 if (isOption(argv
[0]))
736 if ((have
= arg_rest(argv
)) < group
) {
737 const char *format
= _("Expected %d arguments, found only %d");
738 sprintf(temp
, format
, group
, have
);
740 } else if ((have
% group
) != 0) {
741 const char *format
= _("Expected %d arguments, found extra %d");
742 sprintf(temp
, format
, group
, (have
% group
));
747 result
+= (have
/ group
);
754 numeric_arg(char **av
, int n
)
758 if (n
< dlg_count_argv(av
)) {
760 result
= (int) strtol(av
[n
], &last
, 10);
762 if (last
== 0 || *last
!= 0) {
765 sprintf(msg
, _("Expected a number for token %d of %.*s"), n
,
774 optional_str(char **av
, int n
, char *dft
)
777 if (arg_rest(av
) > n
)
782 #if defined(HAVE_DLG_GAUGE) || defined(HAVE_XDIALOG)
784 optional_num(char **av
, int n
, int dft
)
787 if (arg_rest(av
) > n
)
788 ret
= numeric_arg(av
, n
);
794 * On AIX 4.x, we have to flush the output right away since there is a bug in
795 * the curses package which discards stdout even when we've used newterm to
796 * redirect output to /dev/tty.
807 case DLG_EXIT_ITEM_HELP
:
808 if ((dialog_state
.output_count
> 1) && !dialog_vars
.separate_output
) {
809 fputs((dialog_state
.separate_str
810 ? dialog_state
.separate_str
811 : DEFAULT_SEPARATE_STR
),
812 dialog_state
.output
);
815 if (dialog_vars
.input_result
!= 0
816 && dialog_vars
.input_result
[0] != '\0') {
817 fputs(dialog_vars
.input_result
, dialog_state
.output
);
818 DLG_TRACE(("# input_result:\n%s\n", dialog_vars
.input_result
));
822 fflush(dialog_state
.output
);
830 * These are the widget callers.
837 return dialog_yesno(t
,
844 call_msgbox(CALLARGS
)
847 return dialog_msgbox(t
,
850 numeric_arg(av
, 3), 1);
854 call_infobox(CALLARGS
)
857 return dialog_msgbox(t
,
860 numeric_arg(av
, 3), 0);
864 call_textbox(CALLARGS
)
867 return dialog_textbox(t
,
876 int tags
= howmany_tags(av
+ 5, MENUBOX_TAGS
);
877 *offset_add
= 5 + tags
* MENUBOX_TAGS
;
879 return dialog_menu(t
,
888 call_inputmenu(CALLARGS
)
890 int tags
= howmany_tags(av
+ 5, MENUBOX_TAGS
);
891 bool free_extra_label
= FALSE
;
894 dialog_vars
.input_menu
= TRUE
;
896 if (dialog_vars
.extra_label
== 0) {
897 free_extra_label
= TRUE
;
898 dialog_vars
.extra_label
= dlg_strclone(_("Rename"));
901 dialog_vars
.extra_button
= TRUE
;
903 *offset_add
= 5 + tags
* MENUBOX_TAGS
;
904 result
= dialog_menu(t
,
910 if (free_extra_label
) {
911 free(dialog_vars
.extra_label
);
912 dialog_vars
.extra_label
= 0;
918 call_checklist(CALLARGS
)
920 int tags
= howmany_tags(av
+ 5, CHECKBOX_TAGS
);
923 *offset_add
= 5 + tags
* CHECKBOX_TAGS
;
924 code
= dialog_checklist(t
,
929 tags
, av
+ 5, FLAG_CHECK
);
934 call_radiolist(CALLARGS
)
936 int tags
= howmany_tags(av
+ 5, CHECKBOX_TAGS
);
937 *offset_add
= 5 + tags
* CHECKBOX_TAGS
;
938 return dialog_checklist(t
,
943 tags
, av
+ 5, FLAG_RADIO
);
947 call_inputbox(CALLARGS
)
949 *offset_add
= arg_rest(av
);
950 return dialog_inputbox(t
,
954 optional_str(av
, 4, 0), 0);
958 call_passwordbox(CALLARGS
)
960 *offset_add
= arg_rest(av
);
961 return dialog_inputbox(t
,
965 optional_str(av
, 4, 0), 1);
970 call_calendar(CALLARGS
)
972 *offset_add
= arg_rest(av
);
973 return dialog_calendar(t
,
977 optional_num(av
, 4, -1),
978 optional_num(av
, 5, -1),
979 optional_num(av
, 6, -1));
983 call_dselect(CALLARGS
)
985 *offset_add
= arg_rest(av
);
986 return dialog_dselect(t
,
993 call_editbox(CALLARGS
)
996 return dialog_editbox(t
,
1003 call_fselect(CALLARGS
)
1005 *offset_add
= arg_rest(av
);
1006 return dialog_fselect(t
,
1009 numeric_arg(av
, 3));
1013 call_timebox(CALLARGS
)
1015 *offset_add
= arg_rest(av
);
1016 return dialog_timebox(t
,
1020 optional_num(av
, 4, -1),
1021 optional_num(av
, 5, -1),
1022 optional_num(av
, 6, -1));
1024 #endif /* HAVE_XDIALOG */
1026 /* dialog 1.2 widgets */
1027 #ifdef HAVE_XDIALOG2
1029 #define DisableNoTags() \
1030 bool save_no_tags = dialog_vars.no_tags; \
1031 bool save_no_items = dialog_vars.no_items; \
1032 dialog_vars.no_tags = TRUE; \
1033 dialog_vars.no_items = FALSE
1035 #define RestoreNoTags() \
1036 dialog_vars.no_tags = save_no_tags; \
1037 dialog_vars.no_items = save_no_items
1040 call_buildlist(CALLARGS
)
1042 int tags
= howmany_tags(av
+ 5, CHECKBOX_TAGS
);
1047 *offset_add
= 5 + tags
* CHECKBOX_TAGS
;
1048 result
= dialog_buildlist(t
,
1054 dialog_vars
.reorder
);
1060 call_rangebox(CALLARGS
)
1064 *offset_add
= arg_rest(av
);
1065 min_value
= numeric_arg(av
, 4);
1066 return dialog_rangebox(t
,
1072 (*offset_add
> 6) ? numeric_arg(av
, 6) : min_value
);
1076 call_treeview(CALLARGS
)
1078 int tags
= howmany_tags(av
+ 5, TREEVIEW_TAGS
);
1083 *offset_add
= arg_rest(av
);
1084 result
= dialog_treeview(t
,
1089 tags
, av
+ 5, FLAG_RADIO
);
1093 #endif /* HAVE_XDIALOG */
1095 #ifdef HAVE_DLG_FORMBOX
1099 int group
= FORMBOX_TAGS
;
1100 int tags
= howmany_tags(av
+ 5, group
);
1101 *offset_add
= 5 + tags
* group
;
1103 return dialog_form(t
,
1112 call_password_form(CALLARGS
)
1114 unsigned save
= dialog_vars
.formitem_type
;
1117 dialog_vars
.formitem_type
= 1;
1118 result
= call_form(PASSARGS
);
1119 dialog_vars
.formitem_type
= save
;
1123 #endif /* HAVE_DLG_FORMBOX */
1125 #ifdef HAVE_DLG_MIXEDFORM
1127 call_mixed_form(CALLARGS
)
1129 int group
= MIXEDFORM_TAGS
;
1130 int tags
= howmany_tags(av
+ 5, group
);
1131 *offset_add
= 5 + tags
* group
;
1133 return dialog_mixedform(t
,
1140 #endif /* HAVE_DLG_MIXEDFORM */
1142 #ifdef HAVE_DLG_GAUGE
1144 call_gauge(CALLARGS
)
1146 *offset_add
= arg_rest(av
);
1147 return dialog_gauge(t
,
1151 optional_num(av
, 4, 0));
1155 call_pause(CALLARGS
)
1157 *offset_add
= arg_rest(av
);
1158 return dialog_pause(t
,
1162 numeric_arg(av
, 4));
1166 #ifdef HAVE_MIXEDGAUGE
1168 call_mixed_gauge(CALLARGS
)
1170 #define MIXEDGAUGE_BASE 5
1171 int tags
= howmany_tags(av
+ MIXEDGAUGE_BASE
, MIXEDGAUGE_TAGS
);
1172 *offset_add
= MIXEDGAUGE_BASE
+ tags
* MIXEDGAUGE_TAGS
;
1173 return dialog_mixedgauge(t
,
1178 tags
, av
+ MIXEDGAUGE_BASE
);
1182 #ifdef HAVE_DLG_GAUGE
1184 call_prgbox(CALLARGS
)
1186 *offset_add
= arg_rest(av
);
1187 /* the original version does not accept a prompt string, but for
1188 * consistency we allow it.
1190 return ((*offset_add
== 5)
1195 numeric_arg(av
, 4), TRUE
)
1200 numeric_arg(av
, 3), TRUE
));
1204 #ifdef HAVE_DLG_GAUGE
1206 call_programbox(CALLARGS
)
1210 *offset_add
= arg_rest(av
);
1211 /* this function is a compromise between --prgbox and --progressbox.
1213 result
= ((*offset_add
== 4)
1214 ? dlg_progressbox(t
,
1219 dialog_state
.pipe_input
)
1220 : dlg_progressbox(t
,
1225 dialog_state
.pipe_input
));
1226 dialog_state
.pipe_input
= 0;
1231 #ifdef HAVE_DLG_GAUGE
1233 call_progressbox(CALLARGS
)
1235 *offset_add
= arg_rest(av
);
1236 /* the original version does not accept a prompt string, but for
1237 * consistency we allow it.
1239 return ((*offset_add
== 4)
1240 ? dialog_progressbox(t
,
1244 : dialog_progressbox(t
,
1247 numeric_arg(av
, 2)));
1251 #ifdef HAVE_DLG_TAILBOX
1253 call_tailbox(CALLARGS
)
1256 return dialog_tailbox(t
,
1264 call_tailboxbg(CALLARGS
)
1267 return dialog_tailbox(t
,
1275 static const Mode modes
[] =
1277 {o_yesno
, 4, 4, call_yesno
},
1278 {o_msgbox
, 4, 4, call_msgbox
},
1279 {o_infobox
, 4, 4, call_infobox
},
1280 {o_textbox
, 4, 4, call_textbox
},
1281 {o_menu
, 6, 0, call_menu
},
1282 {o_inputmenu
, 6, 0, call_inputmenu
},
1283 {o_checklist
, 7, 0, call_checklist
},
1284 {o_radiolist
, 7, 0, call_radiolist
},
1285 {o_inputbox
, 4, 5, call_inputbox
},
1286 {o_passwordbox
, 4, 5, call_passwordbox
},
1287 #ifdef HAVE_DLG_GAUGE
1288 {o_gauge
, 4, 5, call_gauge
},
1289 {o_pause
, 5, 5, call_pause
},
1290 {o_prgbox
, 4, 5, call_prgbox
},
1291 {o_programbox
, 3, 4, call_programbox
},
1292 {o_progressbox
, 3, 4, call_progressbox
},
1294 #ifdef HAVE_DLG_FORMBOX
1295 {o_passwordform
, 13, 0, call_password_form
},
1296 {o_form
, 13, 0, call_form
},
1298 #ifdef HAVE_MIXEDGAUGE
1299 {o_mixedgauge
, MIXEDGAUGE_BASE
, 0, call_mixed_gauge
},
1301 #ifdef HAVE_DLG_MIXEDFORM
1302 {o_mixedform
, 13, 0, call_mixed_form
},
1304 #ifdef HAVE_DLG_TAILBOX
1305 {o_tailbox
, 4, 4, call_tailbox
},
1306 {o_tailboxbg
, 4, 4, call_tailboxbg
},
1309 {o_calendar
, 4, 7, call_calendar
},
1310 {o_dselect
, 4, 5, call_dselect
},
1311 {o_editbox
, 4, 4, call_editbox
},
1312 {o_fselect
, 4, 5, call_fselect
},
1313 {o_timebox
, 4, 7, call_timebox
},
1315 #ifdef HAVE_XDIALOG2
1316 {o_buildlist
, 4, 0, call_buildlist
},
1317 {o_rangebox
, 5, 7, call_rangebox
},
1318 {o_treeview
, 4, 0, call_treeview
},
1324 optionString(char **argv
, int *num
)
1326 int next
= *num
+ 1;
1327 char *result
= argv
[next
];
1330 sprintf(temp
, ("Expected a string-parameter for %.*s"), USEMAX_ARGS
,
1339 optionValue(char **argv
, int *num
)
1341 int next
= *num
+ 1;
1342 char *src
= argv
[next
];
1347 result
= (int) strtol(src
, &tmp
, 0);
1348 if (tmp
== 0 || *tmp
!= 0)
1354 sprintf(temp
, _("Expected a numeric-parameter for %.*s"),
1355 USEMAX_ARGS
, argv
[*num
]);
1363 * In findOption, we made provision for adding/removing a "no" prefix from
1364 * any boolean option. This function determines the actual true/false result.
1367 optionBool(const char *actual
, const Options
* data
)
1369 bool normal
= (data
->type
== tTrue
) ? TRUE
: FALSE
;
1370 bool result
= !strcmp(actual
+ 2, data
->name
) ? normal
: !normal
;
1371 if (result
!= normal
) {
1372 int want_no
= (strncmp(actual
+ 2, "no", 2) == 0);
1373 int have_no
= (strncmp(data
->name
, "no", 2) == 0);
1374 if (have_no
== want_no
)
1380 /* Return exit-code for a named button */
1382 button_code(const char *name
)
1389 { "ok", DLG_EXIT_OK
},
1390 { "yes", DLG_EXIT_OK
},
1391 { "cancel", DLG_EXIT_CANCEL
},
1392 { "no", DLG_EXIT_CANCEL
},
1393 { "help", DLG_EXIT_HELP
},
1394 { "extra", DLG_EXIT_EXTRA
},
1398 int code
= DLG_EXIT_ERROR
;
1401 for (i
= 0; i
< TableSize(table
); i
++) {
1402 if (!dlg_strcmp(name
, table
[i
].name
)) {
1403 code
= table
[i
].code
;
1408 if (code
== DLG_EXIT_ERROR
) {
1410 sprintf(temp
, _("Button name \"%.*s\" unknown"), USEMAX_ARGS
, name
);
1418 * If this is the last option, we do not want any error messages - just our
1419 * output. Calling end_dialog() cancels the refresh() at the end of the
1423 IgnoreNonScreen(char **argv
, int offset
)
1425 if (argv
[offset
+ 1] == 0) {
1426 ignore_unknown
= TRUE
;
1432 PrintTextOnly(char **argv
, int *offset
, eOptions code
)
1434 /* TODO - handle two optional numeric params */
1440 int next
= arg_rest(argv
+ *offset
);
1442 if (LINES
<= 0 && COLS
<= 0) {
1443 dlg_ttysize(fileno(dialog_state
.input
),
1444 &dialog_state
.screen_height
,
1445 &dialog_state
.screen_width
);
1448 text
= strdup(optionString(argv
, offset
));
1449 IgnoreNonScreen(argv
, *offset
);
1452 next
= MIN(next
, 3);
1453 height
= numeric_arg(argv
, *offset
+ 1);
1455 width
= numeric_arg(argv
, *offset
+ 2);
1456 *offset
+= next
- 1;
1459 dlg_trim_string(text
);
1460 dlg_auto_size(NULL
, text
, &height2
, &width2
, height
, width
);
1464 dialog_state
.text_only
= TRUE
;
1465 dlg_print_autowrap(stdscr
, text
, height2
, width2
);
1466 dialog_state
.text_only
= FALSE
;
1468 case o_print_text_size
:
1469 fprintf(dialog_state
.output
, "%d %d\n",
1470 dialog_state
.text_height
,
1471 dialog_state
.text_width
);
1479 * Print parts of a message
1482 PrintList(const char *const *list
)
1484 const char *leaf
= strrchr(program
, '/');
1492 while (*list
!= 0) {
1493 fprintf(dialog_state
.output
, *list
, n
? leaf
: dialog_version());
1494 (void) fputc('\n', dialog_state
.output
);
1501 lookupMode(eOptions code
)
1503 const Mode
*modePtr
= 0;
1506 for (n
= 0; n
< TableSize(modes
); n
++) {
1507 if (modes
[n
].code
== code
) {
1508 modePtr
= &modes
[n
];
1516 compare_opts(const void *a
, const void *b
)
1518 Options
*const *p
= (Options
* const *) a
;
1519 Options
*const *q
= (Options
* const *) b
;
1520 return strcmp((*p
)->name
, (*q
)->name
);
1524 * Print program's version.
1527 PrintVersion(FILE *fp
)
1529 fprintf(fp
, "Version: %s\n", dialog_version());
1533 * Print program help-message
1538 static const char *const tbl_1
[] =
1540 "cdialog (ComeOn Dialog!) version %s",
1541 "Copyright 2000-2021,2022 Thomas E. Dickey",
1542 "This is free software; see the source for copying conditions. There is NO",
1543 "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.",
1545 "* Display dialog boxes from shell scripts *",
1547 "Usage: %s <options> { --and-widget <options> }",
1548 "where options are \"common\" options, followed by \"box\" options",
1552 " [--create-rc \"file\"]",
1558 "Auto-size with height and width = 0. Maximize with height and width = -1.",
1559 "Global-auto-size if also menu_height/list_height = 0.",
1562 size_t limit
= TableSize(options
);
1564 const Options
**opts
;
1567 dialog_state
.output
= stdout
;
1569 opts
= dlg_calloc(const Options
*, limit
);
1570 assert_ptr(opts
, "Help");
1571 for (j
= 0; j
< limit
; ++j
) {
1572 opts
[j
] = &(options
[j
]);
1574 qsort(opts
, limit
, sizeof(Options
*), compare_opts
);
1577 fprintf(dialog_state
.output
, "Common options:\n ");
1578 for (j
= k
= 0; j
< limit
; j
++) {
1579 if ((opts
[j
]->pass
& 1)
1580 && opts
[j
]->help
!= 0) {
1581 size_t len
= 6 + strlen(opts
[j
]->name
) + strlen(opts
[j
]->help
);
1584 fprintf(dialog_state
.output
, "\n ");
1587 fprintf(dialog_state
.output
, " [--%s%s%s]", opts
[j
]->name
,
1588 *(opts
[j
]->help
) ? " " : "", opts
[j
]->help
);
1591 fprintf(dialog_state
.output
, "\nBox options:\n");
1592 for (j
= 0; j
< limit
; j
++) {
1593 if ((opts
[j
]->pass
& 2) != 0
1594 && opts
[j
]->help
!= 0
1595 && lookupMode(opts
[j
]->code
)) {
1596 fprintf(dialog_state
.output
, " --%-12s %s\n", opts
[j
]->name
,
1604 dlg_exit(DLG_EXIT_OK
);
1607 #ifdef HAVE_DLG_TRACE
1609 * Only the first call to dlg_trace will open a trace file. But each time
1610 * --trace is parsed, we show the whole parameter list as it is at that moment,
1611 * counting discarded parameters. The only way to capture the whole parameter
1612 * list is if --trace is the first option.
1615 process_trace_option(char **argv
, int *offset
)
1619 if (dialog_state
.trace_output
== 0) {
1620 dlg_trace(optionString(argv
, offset
));
1622 DLG_TRACE(("# ignore extra --trace option\n"));
1626 DLG_TRACE(("# Parameters:\n"));
1627 for (j
= 0; argv
[j
] != 0; ++j
) {
1628 DLG_TRACE(("#\targv[%d] = %s\n", j
, argv
[j
]));
1634 * "Common" options apply to all widgets more/less. Most of the common options
1635 * set values in dialog_vars, a few set dialog_state and a couple write to the
1639 process_common_options(int argc
, char **argv
, int offset
, int output
)
1641 const Options
*data
= NULL
;
1644 DLG_TRACE(("# process_common_options, offset %d:%d\n", offset
, argc
));
1646 while (!done
&& offset
< argc
) {
1647 static char empty
[] = "";
1648 eOptions code
= o_unknown
;
1654 DLG_TRACE(("#\targv[%d] = %s\n", offset
, argv
[offset
]));
1655 if ((data
= findOption(argv
[offset
], 1, FALSE
)) == NULL
) {
1660 switch (data
->vars
) {
1665 target
= (char *) &dialog_state
;
1668 target
= (char *) &dialog_vars
;
1672 #define TraceTarget \
1673 ((target == (char *) &dialog_state) \
1676 #define TraceBVal (bval ? "TRUE" : "FALSE")
1677 #define TraceDone(fmt,value) \
1678 DLG_TRACE(("#\t.. set %s.%s = %"fmt"\n", TraceTarget, data->name, value))
1679 #define TraceLate(fmt,value) \
1680 DLG_TRACE(("#\t.. defer setting %s = %"fmt"\n", data->name, value))
1683 switch (data
->type
) {
1688 bval
= optionBool(argv
[offset
], data
);
1689 if (target
!= NULL
) {
1690 *(bool *) (target
+ data
->offset
) = bval
;
1691 TraceDone("s", TraceBVal
);
1693 TraceLate("s", TraceBVal
);
1697 nval
= optionValue(argv
, &offset
);
1698 if (target
!= NULL
) {
1699 *(int *) (void *) (target
+ data
->offset
) = nval
;
1700 TraceDone("d", nval
);
1702 TraceLate("d", nval
);
1706 sval
= optionString(argv
, &offset
);
1707 if (target
!= NULL
) {
1708 *(char **) (void *) (target
+ data
->offset
) = sval
;
1709 TraceDone("s", sval
);
1711 TraceLate("s", sval
);
1718 dialog_vars
.default_button
= DLG_EXIT_CANCEL
;
1720 case o_default_button
:
1721 dialog_vars
.default_button
= button_code(sval
);
1722 dialog_vars
.defaultno
= dialog_vars
.default_button
== DLG_EXIT_CANCEL
;
1725 case o_print_text_size
:
1726 PrintTextOnly(argv
, &offset
, code
);
1728 case o_print_maxsize
:
1730 IgnoreNonScreen(argv
, offset
);
1731 fflush(dialog_state
.output
);
1732 fprintf(dialog_state
.output
, "MaxSize: %d, %d\n", SLINES
, SCOLS
);
1735 case o_print_version
:
1737 PrintVersion(dialog_state
.output
);
1741 dialog_state
.visit_cols
= 1;
1744 #ifdef HAVE_WHIPTAIL
1745 if (!strcmp(argv
[offset
], "--topleft")) {
1746 dialog_vars
.begin_y
= 0;
1747 dialog_vars
.begin_x
= 0;
1751 dialog_vars
.begin_y
= optionValue(argv
, &offset
);
1752 dialog_vars
.begin_x
= optionValue(argv
, &offset
);
1756 dialog_vars
.no_lines
= FALSE
;
1759 dialog_vars
.ascii_lines
= FALSE
;
1765 done
= !ignore_unknown
;
1768 #ifdef HAVE_DLG_TRACE
1770 process_trace_option(argv
, &offset
);
1774 if (dialog_vars
.week_start
== 0) { /* Monday is implied */
1775 static char default_1st
[] = "1";
1776 dialog_vars
.week_start
= default_1st
;
1784 if (dialog_state
.aspect_ratio
== 0)
1785 dialog_state
.aspect_ratio
= DEFAULT_ASPECT_RATIO
;
1791 * Initialize options at the start of a series of common options culminating
1795 init_result(char *buffer
)
1797 static bool first
= TRUE
;
1799 DLG_TRACE(("# init_result\n"));
1801 /* clear everything we do not save for the next widget */
1802 memset(&dialog_vars
, 0, sizeof(dialog_vars
));
1804 dialog_vars
.input_result
= buffer
;
1805 dialog_vars
.input_result
[0] = '\0';
1807 dialog_vars
.default_button
= -1;
1810 * The first time this is called, check for common options given by an
1811 * environment variable.
1814 char *env
= dlg_getenv_str("DIALOGOPTS");
1816 env
= dlg_strclone(env
);
1818 special_argv
= dlg_string_to_argv(env
);
1819 special_argc
= dlg_count_argv(special_argv
);
1824 if (special_argv
!= 0) {
1825 process_common_options(special_argc
, special_argv
, 0, FALSE
);
1830 main(int argc
, char *argv
[])
1833 bool esc_pressed
= FALSE
;
1834 bool keep_tite
= FALSE
;
1838 int retval
= DLG_EXIT_OK
;
1841 char my_buffer
[MAX_LEN
+ 1];
1843 memset(&dialog_state
, 0, sizeof(dialog_state
));
1844 memset(&dialog_vars
, 0, sizeof(dialog_vars
));
1846 #if defined(ENABLE_NLS)
1847 /* initialize locale support */
1848 setlocale(LC_ALL
, "");
1849 bindtextdomain(NLS_TEXTDOMAIN
, LOCALEDIR
);
1850 textdomain(NLS_TEXTDOMAIN
);
1851 #elif defined(HAVE_SETLOCALE)
1852 (void) setlocale(LC_ALL
, "");
1855 init_result(my_buffer
); /* honor $DIALOGOPTS */
1856 unescape_argv(&argc
, &argv
);
1858 dialog_state
.output
= stderr
;
1859 dialog_state
.input
= stdin
;
1862 * Look for the last --stdout, --stderr or --output-fd option, and use
1863 * that. We can only write to one of them. If --stdout is used, that
1864 * can interfere with initializing the curses library, so we want to
1865 * know explicitly if it is used.
1867 * Also, look for any --version or --help message, processing those
1870 while (offset
< argc
) {
1872 switch (lookupOption(argv
[offset
], 7)) {
1873 case o_output_stdout
:
1874 dialog_state
.output
= stdout
;
1876 case o_output_stderr
:
1877 dialog_state
.output
= stderr
;
1880 if ((j
= optionValue(argv
, &offset
)) < 0
1881 || (dialog_state
.input
= fdopen(j
, "r")) == 0) {
1883 dlg_exiterr(_("Cannot open input-fd\n"));
1887 if ((j
= optionValue(argv
, &offset
)) < 0
1888 || (dialog_state
.output
= fdopen(j
, "w")) == 0) {
1890 dlg_exiterr(_("Cannot open output-fd\n"));
1897 dialog_state
.output
= stdout
;
1898 PrintVersion(dialog_state
.output
);
1899 dlg_exit(DLG_EXIT_OK
);
1904 #ifdef HAVE_DLG_TRACE
1907 * Process/remove the --trace option if it is the first option.
1908 * Otherwise, process it in more/less expected order as a
1912 process_trace_option(argv
, &offset
);
1923 DLG_TRACE(("# discarding %d parameters starting with argv[%d] (%s)\n",
1924 1 + offset
- base
, base
,
1926 for (j
= base
; j
< argc
; ++j
) {
1927 dialog_argv
[j
] = dialog_argv
[j
+ 1 + (offset
- base
)];
1929 argc
-= (1 + offset
- base
);
1933 init_result(my_buffer
);
1934 dialog_vars
.keep_tite
|= keep_tite
; /* init_result() cleared global */
1937 * Dialog's output may be redirected (see above). Handle the special
1938 * case of options that only report information without interaction.
1941 switch (lookupOption(argv
[1], 7)) {
1942 case o_print_maxsize
:
1945 fflush(dialog_state
.output
);
1946 fprintf(dialog_state
.output
, "MaxSize: %d, %d\n", SLINES
, SCOLS
);
1948 case o_print_version
:
1949 PrintVersion(dialog_state
.output
);
1951 case o_dlg_clear_screen
:
1954 dlg_keep_tite((dialog_state
.output
== stdout
) ? stderr
: stdout
);
1963 dlg_exit(DLG_EXIT_OK
);
1964 } else if (argc
< 2) {
1968 else if (lookupOption(argv
[1], 7) == o_create_rc
) {
1970 sprintf(temp
, _("Expected a filename for %.*s"), USEMAX_FILE
,
1975 dialog_state
.use_colors
= USE_COLORS
; /* use colors by default? */
1976 dialog_state
.use_shadow
= USE_SHADOW
; /* shadow dialog boxes by default? */
1978 if (dlg_parse_rc() == -1) { /* Read the configuration file */
1980 dlg_exiterr("dialog: dlg_parse_rc");
1982 dlg_create_rc(argv
[2]);
1983 dlg_exit(DLG_EXIT_OK
);
1985 #endif /* HAVE_RC_FILE */
1988 * Handle combinations of common options including --print-text-only
1989 * which can be done before involving curses, in case we can exit
1990 * without initializing curses (and writing to the terminal).
1992 initial
= process_common_options(argc
, argv
, offset
, TRUE
);
1993 if (initial
>= argc
)
1994 dlg_exit(DLG_EXIT_OK
);
1997 init_dialog(dialog_state
.input
, dialog_state
.output
);
1999 while (offset
< argc
&& !esc_pressed
) {
2001 const Mode
*modePtr
;
2003 init_result(my_buffer
);
2004 offset
= process_common_options(argc
, argv
, offset
, offset
> initial
);
2006 if (argv
[offset
] == NULL
) {
2009 Usage(_("Expected a box option"));
2012 if (dialog_vars
.separate_output
) {
2013 switch (lookupOption(argv
[offset
], 2)) {
2014 #ifdef HAVE_XDIALOG2
2022 _("Unexpected widget with --separate-output %.*s"),
2023 USEMAX_ARGS
, argv
[offset
]);
2028 dlg_put_backtitle();
2030 /* use a table to look for the requested mode, to avoid code duplication */
2033 if ((code
= lookupOption(argv
[offset
], 2)) != o_unknown
)
2034 modePtr
= lookupMode(code
);
2037 (lookupOption(argv
[offset
], 7) != o_unknown
2038 ? _("Unexpected option %.*s")
2039 : _("Unknown option %.*s")),
2045 have
= arg_rest(&argv
[offset
]);
2046 if (have
< modePtr
->argmin
) {
2047 sprintf(temp
, _("Expected at least %d tokens for %.*s, have %d"),
2049 modePtr
->argmin
- 1, argv
[offset
],
2053 if (modePtr
->argmax
&& have
> modePtr
->argmax
) {
2055 _("Expected no more than %d tokens for %.*s, have %d"),
2057 modePtr
->argmax
- 1, argv
[offset
],
2063 * Trim whitespace from non-title option values, e.g., the ones that
2064 * will be used as captions or prompts. Do that only for the widget
2065 * we are about to process, since the "--trim" option is reset before
2066 * accumulating options for each widget.
2068 for (j
= offset
+ 1; j
<= offset
+ have
; j
++) {
2069 switch (lookupOption(argv
[j
- 1], 7)) {
2078 char *argv_j
= strdup(argv
[j
]);
2080 dlg_trim_string(argv_j
);
2083 argv
[j
] = strdup("?");
2085 ignore_leak(argv
[j
]);
2091 DLG_TRACE(("# execute %s\n", argv
[offset
]));
2092 retval
= show_result((*(modePtr
->jumper
)) (dialog_vars
.title
,
2095 DLG_TRACE(("# widget returns %d\n", retval
));
2096 offset
+= offset_add
;
2098 if (dialog_vars
.input_result
!= my_buffer
) {
2099 free(dialog_vars
.input_result
);
2100 dialog_vars
.input_result
= 0;
2103 if (retval
== DLG_EXIT_ESC
) {
2107 if (dialog_vars
.beep_after_signal
)
2110 if (dialog_vars
.sleep_secs
)
2111 (void) napms(dialog_vars
.sleep_secs
* 1000);
2113 if (offset
< argc
) {
2114 switch (lookupOption(argv
[offset
], 7)) {
2119 sprintf(temp
, _("Expected --and-widget, not %.*s"),
2120 USEMAX_ARGS
, argv
[offset
]);
2124 /* if we got a cancel, etc., stop chaining */
2125 if (retval
!= DLG_EXIT_OK
)
2128 dialog_vars
.dlg_clear_screen
= TRUE
;
2132 if (dialog_vars
.dlg_clear_screen
)
2137 dlg_killall_bg(&retval
);
2138 if (dialog_state
.screen_initialized
) {