summaryrefslogtreecommitdiffstats
path: root/contrib/dialog/dialog.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/dialog/dialog.c')
-rw-r--r--contrib/dialog/dialog.c239
1 files changed, 106 insertions, 133 deletions
diff --git a/contrib/dialog/dialog.c b/contrib/dialog/dialog.c
index 3f718b4..13b2a17 100644
--- a/contrib/dialog/dialog.c
+++ b/contrib/dialog/dialog.c
@@ -1,9 +1,9 @@
/*
- * $Id: dialog.c,v 1.177 2010/01/18 09:21:14 tom Exp $
+ * $Id: dialog.c,v 1.186 2011/03/02 09:58:29 tom Exp $
*
* cdialog - Display simple dialog boxes from shell scripts
*
- * Copyright 2000-2008,2010 Thomas E. Dickey
+ * Copyright 2000-2010,2011 Thomas E. Dickey
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License, version 2.1
@@ -95,6 +95,7 @@ typedef enum {
,o_no_kill
,o_no_label
,o_no_lines
+ ,o_no_mouse
,o_no_shadow
,o_nocancel
,o_noitem
@@ -105,9 +106,11 @@ typedef enum {
,o_passwordbox
,o_passwordform
,o_pause
+ ,o_prgbox
,o_print_maxsize
,o_print_size
,o_print_version
+ ,o_programbox
,o_progressbox
,o_quoted
,o_radiolist
@@ -235,6 +238,7 @@ static const Options options[] = {
{ "no-kill", o_no_kill, 1, "" },
{ "no-label", o_no_label, 1, "<str>" },
{ "no-lines", o_no_lines, 1, "" },
+ { "no-mouse", o_no_mouse, 1, "" },
{ "no-ok", o_nook, 1, "" },
{ "no-shadow", o_no_shadow, 1, "" },
{ "nocancel", o_nocancel, 1, NULL }, /* see --no-cancel */
@@ -246,10 +250,12 @@ static const Options options[] = {
{ "passwordbox", o_passwordbox, 2, "<text> <height> <width> [<init>]" },
{ "passwordform", o_passwordform, 2, "<text> <height> <width> <form height> <label1> <l_y1> <l_x1> <item1> <i_y1> <i_x1> <flen1> <ilen1>..." },
{ "pause", o_pause, 2, "<text> <height> <width> <seconds>" },
+ { "prgbox", o_prgbox, 2, "<text> <command> <height> <width>" },
{ "print-maxsize", o_print_maxsize, 1, "" },
{ "print-size", o_print_size, 1, "" },
{ "print-version", o_print_version, 5, "" },
- { "progressbox", o_progressbox, 2, "<height> <width>" },
+ { "programbox", o_programbox, 2, "<text> <height> <width>" },
+ { "progressbox", o_progressbox, 2, "<text> <height> <width>" },
{ "quoted", o_quoted, 1, "" },
{ "radiolist", o_radiolist, 2, "<text> <height> <width> <list height> <tag1> <item1> <status1>..." },
{ "screen-center", o_screen_center, 1, NULL },
@@ -287,109 +293,6 @@ static const Options options[] = {
/* *INDENT-ON* */
/*
- * Convert a string to an argv[], returning a char** index (which must be
- * freed by the caller). The string is modified (replacing gaps between
- * tokens with nulls).
- */
-static char **
-string_to_argv(char *blob)
-{
- size_t n;
- int pass;
- size_t length = strlen(blob);
- char **result = 0;
-
- for (pass = 0; pass < 2; ++pass) {
- bool inparm = FALSE;
- bool quoted = FALSE;
- char *param = blob;
- size_t count = 0;
-
- for (n = 0; n < length; ++n) {
- if (quoted && blob[n] == '"') {
- quoted = FALSE;
- } else if (blob[n] == '"') {
- quoted = TRUE;
- if (!inparm) {
- if (pass)
- result[count] = param;
- ++count;
- inparm = TRUE;
- }
- } else if (blob[n] == '\\') {
- if (quoted && !isspace(UCH(blob[n + 1]))) {
- if (!inparm) {
- if (pass)
- result[count] = param;
- ++count;
- inparm = TRUE;
- }
- if (pass) {
- *param++ = blob[n];
- *param++ = blob[n + 1];
- }
- }
- ++n;
- } else if (!quoted && isspace(UCH(blob[n]))) {
- inparm = FALSE;
- if (pass) {
- *param++ = '\0';
- }
- } else {
- if (!inparm) {
- if (pass)
- result[count] = param;
- ++count;
- inparm = TRUE;
- }
- if (pass) {
- *param++ = blob[n];
- }
- }
- }
-
- if (!pass) {
- if (count) {
- result = dlg_calloc(char *, count + 1);
- assert_ptr(result, "string_to_argv");
- } else {
- break; /* no tokens found */
- }
- } else {
- *param = '\0';
- }
- }
- return result;
-}
-
-/*
- * Count the entries in an argv list.
- */
-static int
-count_argv(char **argv)
-{
- int result = 0;
-
- if (argv != 0) {
- while (argv[result] != 0)
- ++result;
- }
- return result;
-}
-
-static int
-eat_argv(int *argcp, char ***argvp, int start, int count)
-{
- int k;
-
- *argcp -= count;
- for (k = start; k <= *argcp; k++)
- (*argvp)[k] = (*argvp)[k + count];
- (*argvp)[*argcp] = 0;
- return TRUE;
-}
-
-/*
* Make an array showing which argv[] entries are options. Use "--" as a
* special token to escape the next argument, allowing it to begin with "--".
* When we find a "--" argument, also remove it from argv[] and adjust argc.
@@ -419,13 +322,13 @@ unescape_argv(int *argcp, char ***argvp)
bool escaped = FALSE;
if (!strcmp((*argvp)[j], "--")) {
escaped = TRUE;
- changed = eat_argv(argcp, argvp, j, 1);
+ changed = dlg_eat_argv(argcp, argvp, j, 1);
} else if (!strcmp((*argvp)[j], "--args")) {
fprintf(stderr, "Showing arguments at arg%d\n", j);
for (k = 0; k < *argcp; ++k) {
fprintf(stderr, " arg%d:%s\n", k, (*argvp)[k]);
}
- changed = eat_argv(argcp, argvp, j, 1);
+ changed = dlg_eat_argv(argcp, argvp, j, 1);
} else if (!strcmp((*argvp)[j], "--file")) {
if (++count_includes > limit_includes)
dlg_exiterr("Too many --file options");
@@ -453,7 +356,7 @@ unescape_argv(int *argcp, char ***argvp)
assert_ptr(blob, "unescape_argv");
bytes_read = fread(blob + length,
sizeof(char),
- BUFSIZ,
+ (size_t) BUFSIZ,
fp);
length += bytes_read;
if (ferror(fp))
@@ -463,8 +366,8 @@ unescape_argv(int *argcp, char ***argvp)
blob[length] = '\0';
- list = string_to_argv(blob);
- if ((added = count_argv(list)) != 0) {
+ list = dlg_string_to_argv(blob);
+ if ((added = dlg_count_argv(list)) != 0) {
if (added > 2) {
size_t need = (size_t) (*argcp + added + 1);
if (doalloc) {
@@ -505,7 +408,7 @@ unescape_argv(int *argcp, char ***argvp)
}
if (!escaped
&& (*argvp)[j] != 0
- && !strncmp((*argvp)[j], "--", 2)
+ && !strncmp((*argvp)[j], "--", (size_t) 2)
&& isalpha(UCH((*argvp)[j][2]))) {
dialog_opts[j] = TRUE;
}
@@ -538,7 +441,7 @@ isOption(const char *arg)
break;
}
}
- } else if (!strncmp(arg, "--", 2) && isalpha(UCH(arg[2]))) {
+ } else if (!strncmp(arg, "--", (size_t) 2) && isalpha(UCH(arg[2]))) {
result = TRUE;
}
}
@@ -614,7 +517,7 @@ static int
numeric_arg(char **av, int n)
{
char *last = 0;
- int result = strtol(av[n], &last, 10);
+ int result = (int) strtol(av[n], &last, 10);
char msg[80];
if (last == 0 || *last != 0) {
@@ -666,7 +569,8 @@ show_result(int ret)
dialog_state.output);
either = TRUE;
}
- if (dialog_vars.input_result[0] != '\0') {
+ if (dialog_vars.input_result != 0
+ && dialog_vars.input_result[0] != '\0') {
fputs(dialog_vars.input_result, dialog_state.output);
either = TRUE;
}
@@ -740,24 +644,33 @@ static int
call_inputmenu(CALLARGS)
{
int tags = howmany_tags(av + 5, MENUBOX_TAGS);
+ bool free_extra_label = FALSE;
+ int result;
dialog_vars.input_menu = TRUE;
if (dialog_vars.max_input == 0)
dialog_vars.max_input = MAX_LEN / 2;
- if (dialog_vars.extra_label == 0)
- dialog_vars.extra_label = _("Rename");
+ if (dialog_vars.extra_label == 0) {
+ free_extra_label = TRUE;
+ dialog_vars.extra_label = dlg_strclone(_("Rename"));
+ }
dialog_vars.extra_button = TRUE;
*offset_add = 5 + tags * MENUBOX_TAGS;
- return dialog_menu(t,
- av[1],
- numeric_arg(av, 2),
- numeric_arg(av, 3),
- numeric_arg(av, 4),
- tags, av + 5);
+ result = dialog_menu(t,
+ av[1],
+ numeric_arg(av, 2),
+ numeric_arg(av, 3),
+ numeric_arg(av, 4),
+ tags, av + 5);
+ if (free_extra_label) {
+ free(dialog_vars.extra_label);
+ dialog_vars.extra_label = 0;
+ }
+ return result;
}
static int
@@ -959,6 +872,53 @@ call_mixed_gauge(CALLARGS)
}
#endif
+static int
+call_prgbox(CALLARGS)
+{
+ *offset_add = arg_rest(av);
+ /* the original version does not accept a prompt string, but for
+ * consistency we allow it.
+ */
+ return ((*offset_add == 5)
+ ? dialog_prgbox(t,
+ av[1],
+ av[2],
+ numeric_arg(av, 3),
+ numeric_arg(av, 4), TRUE)
+ : dialog_prgbox(t,
+ "",
+ av[1],
+ numeric_arg(av, 2),
+ numeric_arg(av, 3), TRUE));
+}
+
+#ifdef HAVE_DLG_GAUGE
+static int
+call_programbox(CALLARGS)
+{
+ int result;
+
+ *offset_add = arg_rest(av);
+ /* this function is a compromise between --prgbox and --progressbox.
+ */
+ result = ((*offset_add == 4)
+ ? dlg_progressbox(t,
+ av[1],
+ numeric_arg(av, 2),
+ numeric_arg(av, 3),
+ TRUE,
+ dialog_state.pipe_input)
+ : dlg_progressbox(t,
+ "",
+ numeric_arg(av, 1),
+ numeric_arg(av, 2),
+ TRUE,
+ dialog_state.pipe_input));
+ dialog_state.pipe_input = 0;
+ return result;
+}
+#endif
+
#ifdef HAVE_DLG_GAUGE
static int
call_progressbox(CALLARGS)
@@ -1018,6 +978,8 @@ static const Mode modes[] =
#ifdef HAVE_DLG_GAUGE
{o_gauge, 4, 5, call_gauge},
{o_pause, 5, 5, call_pause},
+ {o_prgbox, 4, 5, call_prgbox},
+ {o_programbox, 3, 4, call_programbox},
{o_progressbox, 3, 4, call_progressbox},
#endif
#ifdef HAVE_DLG_FORMBOX
@@ -1067,7 +1029,7 @@ optionValue(char **argv, int *num)
int result = 0;
if (src != 0) {
- result = strtol(src, &tmp, 0);
+ result = (int) strtol(src, &tmp, 0);
if (tmp == 0 || *tmp != 0)
src = 0;
}
@@ -1135,7 +1097,7 @@ Help(void)
static const char *const tbl_1[] =
{
"cdialog (ComeOn Dialog!) version %s",
- "Copyright 2000-2007,2008 Thomas E. Dickey",
+ "Copyright 2000-2008,2011 Thomas E. Dickey",
"This is free software; see the source for copying conditions. There is NO",
"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.",
"",
@@ -1156,8 +1118,8 @@ Help(void)
"Global-auto-size if also menu_height/list_height = 0.",
0
};
- unsigned limit = sizeof(options) / sizeof(options[0]);
- unsigned j, k;
+ size_t limit = sizeof(options) / sizeof(options[0]);
+ size_t j, k;
const Options **opts;
opts = dlg_calloc(const Options *, limit);
@@ -1172,7 +1134,7 @@ Help(void)
for (j = k = 0; j < limit; j++) {
if ((opts[j]->pass & 1)
&& opts[j]->help != 0) {
- unsigned len = 6 + strlen(opts[j]->name) + strlen(opts[j]->help);
+ size_t len = 6 + strlen(opts[j]->name) + strlen(opts[j]->help);
k += len;
if (k > 75) {
fprintf(dialog_state.output, "\n ");
@@ -1204,6 +1166,9 @@ Help(void)
static int
process_common_options(int argc, char **argv, int offset, bool output)
{
+#ifdef HAVE_DLG_TRACE
+ int n;
+#endif
bool done = FALSE;
while (offset < argc && !done) { /* Common options */
@@ -1389,6 +1354,9 @@ process_common_options(int argc, char **argv, int offset, bool output)
dialog_vars.no_lines = TRUE;
dialog_vars.ascii_lines = FALSE;
break;
+ case o_no_mouse:
+ dialog_state.no_mouse = TRUE;
+ break;
case o_noitem:
case o_fullbutton:
/* ignore */
@@ -1418,6 +1386,9 @@ process_common_options(int argc, char **argv, int offset, bool output)
#ifdef HAVE_DLG_TRACE
case o_trace:
dlg_trace(optionString(argv, &offset));
+ for (n = 0; argv[n] != 0; ++n) {
+ dlg_trace_msg("argv[%d] = %s\n", n, argv[n]);
+ }
break;
#endif
}
@@ -1453,8 +1424,8 @@ init_result(char *buffer)
if (env != 0)
env = dlg_strclone(env);
if (env != 0) {
- special_argv = string_to_argv(env);
- special_argc = count_argv(special_argv);
+ special_argv = dlg_string_to_argv(env);
+ special_argc = dlg_count_argv(special_argv);
}
}
if (special_argv != 0) {
@@ -1487,8 +1458,8 @@ main(int argc, char *argv[])
#if defined(ENABLE_NLS)
/* initialize locale support */
setlocale(LC_ALL, "");
- bindtextdomain(PACKAGE, LOCALEDIR);
- textdomain(PACKAGE);
+ bindtextdomain(NLS_TEXTDOMAIN, LOCALEDIR);
+ textdomain(NLS_TEXTDOMAIN);
#elif defined(HAVE_SETLOCALE)
(void) setlocale(LC_ALL, "");
#endif
@@ -1664,8 +1635,10 @@ main(int argc, char *argv[])
&offset_add));
offset += offset_add;
- if (dialog_vars.input_result != my_buffer)
+ if (dialog_vars.input_result != my_buffer) {
free(dialog_vars.input_result);
+ dialog_vars.input_result = 0;
+ }
if (retval == DLG_EXIT_ESC) {
esc_pressed = TRUE;
OpenPOWER on IntegriCloud