xref: /freebsd/contrib/bsddialog/utility/util_cli.c (revision d4ca001544347e217e2ab023cca88b30637def98)
161ba55bcSBaptiste Daroussin /*-
261ba55bcSBaptiste Daroussin  * SPDX-License-Identifier: BSD-2-Clause
361ba55bcSBaptiste Daroussin  *
461ba55bcSBaptiste Daroussin  * Copyright (c) 2021-2023 Alfonso Sabato Siciliano
561ba55bcSBaptiste Daroussin  *
661ba55bcSBaptiste Daroussin  * Redistribution and use in source and binary forms, with or without
761ba55bcSBaptiste Daroussin  * modification, are permitted provided that the following conditions
861ba55bcSBaptiste Daroussin  * are met:
961ba55bcSBaptiste Daroussin  * 1. Redistributions of source code must retain the above copyright
1061ba55bcSBaptiste Daroussin  *    notice, this list of conditions and the following disclaimer.
1161ba55bcSBaptiste Daroussin  * 2. Redistributions in binary form must reproduce the above copyright
1261ba55bcSBaptiste Daroussin  *    notice, this list of conditions and the following disclaimer in the
1361ba55bcSBaptiste Daroussin  *    documentation and/or other materials provided with the distribution.
1461ba55bcSBaptiste Daroussin  *
1561ba55bcSBaptiste Daroussin  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1661ba55bcSBaptiste Daroussin  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1761ba55bcSBaptiste Daroussin  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1861ba55bcSBaptiste Daroussin  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1961ba55bcSBaptiste Daroussin  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2061ba55bcSBaptiste Daroussin  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2161ba55bcSBaptiste Daroussin  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2261ba55bcSBaptiste Daroussin  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2361ba55bcSBaptiste Daroussin  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2461ba55bcSBaptiste Daroussin  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2561ba55bcSBaptiste Daroussin  * SUCH DAMAGE.
2661ba55bcSBaptiste Daroussin  */
2761ba55bcSBaptiste Daroussin 
2861ba55bcSBaptiste Daroussin #include <sys/ioctl.h>
2961ba55bcSBaptiste Daroussin 
3061ba55bcSBaptiste Daroussin #include <getopt.h>
3161ba55bcSBaptiste Daroussin #include <stdio.h>
3261ba55bcSBaptiste Daroussin #include <stdlib.h>
3361ba55bcSBaptiste Daroussin #include <string.h>
3461ba55bcSBaptiste Daroussin #include <unistd.h>
3561ba55bcSBaptiste Daroussin 
3661ba55bcSBaptiste Daroussin #include <bsddialog.h>
3761ba55bcSBaptiste Daroussin #include <bsddialog_theme.h>
3861ba55bcSBaptiste Daroussin 
3961ba55bcSBaptiste Daroussin #include "util.h"
4061ba55bcSBaptiste Daroussin 
4161ba55bcSBaptiste Daroussin enum OPTS {
4261ba55bcSBaptiste Daroussin 	/* Options */
4361ba55bcSBaptiste Daroussin 	ALTERNATE_SCREEN = '?' + 1,
4461ba55bcSBaptiste Daroussin 	AND_DIALOG,
4561ba55bcSBaptiste Daroussin 	ASCII_LINES,
4661ba55bcSBaptiste Daroussin 	BACKTITLE,
4761ba55bcSBaptiste Daroussin 	BEGIN_X,
4861ba55bcSBaptiste Daroussin 	BEGIN_Y,
4961ba55bcSBaptiste Daroussin 	BIKESHED,
5061ba55bcSBaptiste Daroussin 	CANCEL_EXIT_CODE,
5161ba55bcSBaptiste Daroussin 	CANCEL_LABEL,
5261ba55bcSBaptiste Daroussin 	CLEAR_DIALOG,
5361ba55bcSBaptiste Daroussin 	CLEAR_SCREEN,
5461ba55bcSBaptiste Daroussin 	COLUMNS_PER_ROW,
5561ba55bcSBaptiste Daroussin 	CR_WRAP,
5661ba55bcSBaptiste Daroussin 	DATEBOX_FORMAT,
5761ba55bcSBaptiste Daroussin 	DATE_FORMAT,
5861ba55bcSBaptiste Daroussin 	DEFAULT_BUTTON,
5961ba55bcSBaptiste Daroussin 	DEFAULT_ITEM,
6061ba55bcSBaptiste Daroussin 	DEFAULT_NO,
6161ba55bcSBaptiste Daroussin 	DISABLE_ESC,
6261ba55bcSBaptiste Daroussin 	ERROR_EXIT_CODE,
6361ba55bcSBaptiste Daroussin 	ESC_EXIT_CODE,
6461ba55bcSBaptiste Daroussin 	EXIT_LABEL,
6561ba55bcSBaptiste Daroussin 	EXTRA_BUTTON,
6661ba55bcSBaptiste Daroussin 	EXTRA_EXIT_CODE,
6761ba55bcSBaptiste Daroussin 	EXTRA_LABEL,
6861ba55bcSBaptiste Daroussin 	HELP_BUTTON,
6961ba55bcSBaptiste Daroussin 	HELP_EXIT_CODE,
7061ba55bcSBaptiste Daroussin 	HELP_LABEL,
7161ba55bcSBaptiste Daroussin 	HELP_PRINT_ITEMS,
7261ba55bcSBaptiste Daroussin 	HELP_PRINT_NAME,
7361ba55bcSBaptiste Daroussin 	HFILE,
7461ba55bcSBaptiste Daroussin 	HLINE,
7561ba55bcSBaptiste Daroussin 	HMSG,
7661ba55bcSBaptiste Daroussin 	IGNORE,
7761ba55bcSBaptiste Daroussin 	INSECURE,
7861ba55bcSBaptiste Daroussin 	ITEM_BOTTOM_DESC,
7961ba55bcSBaptiste Daroussin 	ITEM_DEPTH,
8061ba55bcSBaptiste Daroussin 	ITEM_PREFIX,
8161ba55bcSBaptiste Daroussin 	LEFT1_BUTTON,
8261ba55bcSBaptiste Daroussin 	LEFT1_EXIT_CODE,
8361ba55bcSBaptiste Daroussin 	LEFT2_BUTTON,
8461ba55bcSBaptiste Daroussin 	LEFT2_EXIT_CODE,
8561ba55bcSBaptiste Daroussin 	LEFT3_BUTTON,
8661ba55bcSBaptiste Daroussin 	LEFT3_EXIT_CODE,
8761ba55bcSBaptiste Daroussin 	LOAD_THEME,
88*d4ca0015SKyle Evans 	MAX_INPUT_FORM,
8961ba55bcSBaptiste Daroussin 	NO_CANCEL,
9061ba55bcSBaptiste Daroussin 	NO_DESCRIPTIONS,
9161ba55bcSBaptiste Daroussin 	NO_LINES,
9261ba55bcSBaptiste Daroussin 	NO_NAMES,
9361ba55bcSBaptiste Daroussin 	NO_OK,
9461ba55bcSBaptiste Daroussin 	NO_SHADOW,
9561ba55bcSBaptiste Daroussin 	NORMAL_SCREEN,
9661ba55bcSBaptiste Daroussin 	OK_EXIT_CODE,
9761ba55bcSBaptiste Daroussin 	OK_LABEL,
9861ba55bcSBaptiste Daroussin 	OUTPUT_FD,
9961ba55bcSBaptiste Daroussin 	OUTPUT_SEPARATOR,
10061ba55bcSBaptiste Daroussin 	PRINT_MAXSIZE,
10161ba55bcSBaptiste Daroussin 	PRINT_SIZE,
10261ba55bcSBaptiste Daroussin 	PRINT_VERSION,
10361ba55bcSBaptiste Daroussin 	QUOTED,
10461ba55bcSBaptiste Daroussin 	RIGHT1_BUTTON,
10561ba55bcSBaptiste Daroussin 	RIGHT1_EXIT_CODE,
10661ba55bcSBaptiste Daroussin 	RIGHT2_BUTTON,
10761ba55bcSBaptiste Daroussin 	RIGHT2_EXIT_CODE,
10861ba55bcSBaptiste Daroussin 	RIGHT3_BUTTON,
10961ba55bcSBaptiste Daroussin 	RIGHT3_EXIT_CODE,
11061ba55bcSBaptiste Daroussin 	SAVE_THEME,
11161ba55bcSBaptiste Daroussin 	SEPARATE_OUTPUT,
11261ba55bcSBaptiste Daroussin 	SHADOW,
11361ba55bcSBaptiste Daroussin 	SINGLE_QUOTED,
11461ba55bcSBaptiste Daroussin 	SLEEP,
11561ba55bcSBaptiste Daroussin 	STDERR,
11661ba55bcSBaptiste Daroussin 	STDOUT,
11761ba55bcSBaptiste Daroussin 	SWITCH_BUTTONS,
11861ba55bcSBaptiste Daroussin 	TAB_ESCAPE,
11961ba55bcSBaptiste Daroussin 	TAB_LEN,
12061ba55bcSBaptiste Daroussin 	TEXT_ESCAPE,
12161ba55bcSBaptiste Daroussin 	TEXT_UNCHANGED,
12261ba55bcSBaptiste Daroussin 	THEME,
12361ba55bcSBaptiste Daroussin 	TIMEOUT_EXIT_CODE,
12461ba55bcSBaptiste Daroussin 	TIME_FORMAT,
12561ba55bcSBaptiste Daroussin 	TITLE,
12661ba55bcSBaptiste Daroussin 	/* Dialogs */
12761ba55bcSBaptiste Daroussin 	CALENDAR,
12861ba55bcSBaptiste Daroussin 	CHECKLIST,
12961ba55bcSBaptiste Daroussin 	DATEBOX,
13061ba55bcSBaptiste Daroussin 	FORM,
13161ba55bcSBaptiste Daroussin 	GAUGE,
13261ba55bcSBaptiste Daroussin 	INFOBOX,
13361ba55bcSBaptiste Daroussin 	INPUTBOX,
13461ba55bcSBaptiste Daroussin 	MENU,
13561ba55bcSBaptiste Daroussin 	MIXEDFORM,
13661ba55bcSBaptiste Daroussin 	MIXEDGAUGE,
13761ba55bcSBaptiste Daroussin 	MSGBOX,
13861ba55bcSBaptiste Daroussin 	PASSWORDBOX,
13961ba55bcSBaptiste Daroussin 	PASSWORDFORM,
14061ba55bcSBaptiste Daroussin 	PAUSE,
14161ba55bcSBaptiste Daroussin 	RADIOLIST,
14261ba55bcSBaptiste Daroussin 	RANGEBOX,
14361ba55bcSBaptiste Daroussin 	TEXTBOX,
14461ba55bcSBaptiste Daroussin 	TIMEBOX,
14561ba55bcSBaptiste Daroussin 	TREEVIEW,
14661ba55bcSBaptiste Daroussin 	YESNO
14761ba55bcSBaptiste Daroussin };
14861ba55bcSBaptiste Daroussin 
14961ba55bcSBaptiste Daroussin /* options descriptor */
15061ba55bcSBaptiste Daroussin static struct option longopts[] = {
15161ba55bcSBaptiste Daroussin 	/* Options */
15261ba55bcSBaptiste Daroussin 	{"alternate-screen",  no_argument,       NULL, ALTERNATE_SCREEN},
15361ba55bcSBaptiste Daroussin 	{"and-dialog",        no_argument,       NULL, AND_DIALOG},
15461ba55bcSBaptiste Daroussin 	{"and-widget",        no_argument,       NULL, AND_DIALOG},
15561ba55bcSBaptiste Daroussin 	{"ascii-lines",       no_argument,       NULL, ASCII_LINES},
15661ba55bcSBaptiste Daroussin 	{"backtitle",         required_argument, NULL, BACKTITLE},
15761ba55bcSBaptiste Daroussin 	{"begin-x",           required_argument, NULL, BEGIN_X},
15861ba55bcSBaptiste Daroussin 	{"begin-y",           required_argument, NULL, BEGIN_Y},
15961ba55bcSBaptiste Daroussin 	{"bikeshed",          no_argument,       NULL, BIKESHED},
16061ba55bcSBaptiste Daroussin 	{"cancel-exit-code",  required_argument, NULL, CANCEL_EXIT_CODE},
16161ba55bcSBaptiste Daroussin 	{"cancel-label",      required_argument, NULL, CANCEL_LABEL},
16261ba55bcSBaptiste Daroussin 	{"clear",             no_argument,       NULL, CLEAR_SCREEN},
16361ba55bcSBaptiste Daroussin 	{"clear-dialog",      no_argument,       NULL, CLEAR_DIALOG},
16461ba55bcSBaptiste Daroussin 	{"clear-screen",      no_argument,       NULL, CLEAR_SCREEN},
16561ba55bcSBaptiste Daroussin 	{"colors",            no_argument,       NULL, TEXT_ESCAPE},
16661ba55bcSBaptiste Daroussin 	{"columns-per-row",   required_argument, NULL, COLUMNS_PER_ROW},
16761ba55bcSBaptiste Daroussin 	{"cr-wrap",           no_argument,       NULL, CR_WRAP},
16861ba55bcSBaptiste Daroussin 	{"datebox-format",    required_argument, NULL, DATEBOX_FORMAT},
16961ba55bcSBaptiste Daroussin 	{"date-format",       required_argument, NULL, DATE_FORMAT},
17061ba55bcSBaptiste Daroussin 	{"defaultno",         no_argument,       NULL, DEFAULT_NO},
17161ba55bcSBaptiste Daroussin 	{"default-button",    required_argument, NULL, DEFAULT_BUTTON},
17261ba55bcSBaptiste Daroussin 	{"default-item",      required_argument, NULL, DEFAULT_ITEM},
17361ba55bcSBaptiste Daroussin 	{"default-no",        no_argument,       NULL, DEFAULT_NO},
17461ba55bcSBaptiste Daroussin 	{"disable-esc",       no_argument,       NULL, DISABLE_ESC},
17561ba55bcSBaptiste Daroussin 	{"error-exit-code",   required_argument, NULL, ERROR_EXIT_CODE},
17661ba55bcSBaptiste Daroussin 	{"esc-exit-code",     required_argument, NULL, ESC_EXIT_CODE},
17761ba55bcSBaptiste Daroussin 	{"exit-label",        required_argument, NULL, EXIT_LABEL},
17861ba55bcSBaptiste Daroussin 	{"extra-button",      no_argument,       NULL, EXTRA_BUTTON},
17961ba55bcSBaptiste Daroussin 	{"extra-exit-code",   required_argument, NULL, EXTRA_EXIT_CODE},
18061ba55bcSBaptiste Daroussin 	{"extra-label",       required_argument, NULL, EXTRA_LABEL},
18161ba55bcSBaptiste Daroussin 	{"help-button",       no_argument,       NULL, HELP_BUTTON},
18261ba55bcSBaptiste Daroussin 	{"help-exit-code",    required_argument, NULL, HELP_EXIT_CODE},
18361ba55bcSBaptiste Daroussin 	{"help-label",        required_argument, NULL, HELP_LABEL},
18461ba55bcSBaptiste Daroussin 	{"help-print-items",  no_argument,       NULL, HELP_PRINT_ITEMS},
18561ba55bcSBaptiste Daroussin 	{"help-print-name",   no_argument,       NULL, HELP_PRINT_NAME},
18661ba55bcSBaptiste Daroussin 	{"help-status",       no_argument,       NULL, HELP_PRINT_ITEMS},
18761ba55bcSBaptiste Daroussin 	{"help-tags",         no_argument,       NULL, HELP_PRINT_NAME},
18861ba55bcSBaptiste Daroussin 	{"hfile",             required_argument, NULL, HFILE},
18961ba55bcSBaptiste Daroussin 	{"hline",             required_argument, NULL, HLINE},
19061ba55bcSBaptiste Daroussin 	{"hmsg",              required_argument, NULL, HMSG},
19161ba55bcSBaptiste Daroussin 	{"ignore",            no_argument,       NULL, IGNORE},
19261ba55bcSBaptiste Daroussin 	{"insecure",          no_argument,       NULL, INSECURE},
19361ba55bcSBaptiste Daroussin 	{"item-bottom-desc",  no_argument,       NULL, ITEM_BOTTOM_DESC},
19461ba55bcSBaptiste Daroussin 	{"item-depth",        no_argument,       NULL, ITEM_DEPTH},
19561ba55bcSBaptiste Daroussin 	{"item-help",         no_argument,       NULL, ITEM_BOTTOM_DESC},
19661ba55bcSBaptiste Daroussin 	{"item-prefix",       no_argument,       NULL, ITEM_PREFIX},
19761ba55bcSBaptiste Daroussin 	{"keep-tite",         no_argument,       NULL, ALTERNATE_SCREEN},
19861ba55bcSBaptiste Daroussin 	{"left1-button",      required_argument, NULL, LEFT1_BUTTON},
19961ba55bcSBaptiste Daroussin 	{"left1-exit-code",   required_argument, NULL, LEFT1_EXIT_CODE},
20061ba55bcSBaptiste Daroussin 	{"left2-button",      required_argument, NULL, LEFT2_BUTTON},
20161ba55bcSBaptiste Daroussin 	{"left2-exit-code",   required_argument, NULL, LEFT2_EXIT_CODE},
20261ba55bcSBaptiste Daroussin 	{"left3-button",      required_argument, NULL, LEFT3_BUTTON},
20361ba55bcSBaptiste Daroussin 	{"left3-exit-code",   required_argument, NULL, LEFT3_EXIT_CODE},
20461ba55bcSBaptiste Daroussin 	{"load-theme",        required_argument, NULL, LOAD_THEME},
205*d4ca0015SKyle Evans 	{"max-input",         required_argument, NULL, MAX_INPUT_FORM},
20661ba55bcSBaptiste Daroussin 	{"no-cancel",         no_argument,       NULL, NO_CANCEL},
20761ba55bcSBaptiste Daroussin 	{"nocancel",          no_argument,       NULL, NO_CANCEL},
20861ba55bcSBaptiste Daroussin 	{"no-descriptions",   no_argument,       NULL, NO_DESCRIPTIONS},
20961ba55bcSBaptiste Daroussin 	{"no-items",          no_argument,       NULL, NO_DESCRIPTIONS},
21061ba55bcSBaptiste Daroussin 	{"no-label",          required_argument, NULL, CANCEL_LABEL},
21161ba55bcSBaptiste Daroussin 	{"no-lines",          no_argument,       NULL, NO_LINES},
21261ba55bcSBaptiste Daroussin 	{"no-names",          no_argument,       NULL, NO_NAMES},
21361ba55bcSBaptiste Daroussin 	{"no-ok",             no_argument,       NULL, NO_OK},
21461ba55bcSBaptiste Daroussin 	{"nook",              no_argument,       NULL, NO_OK},
21561ba55bcSBaptiste Daroussin 	{"no-shadow",         no_argument,       NULL, NO_SHADOW},
21661ba55bcSBaptiste Daroussin 	{"no-tags",           no_argument,       NULL, NO_NAMES},
21761ba55bcSBaptiste Daroussin 	{"normal-screen",     no_argument,       NULL, NORMAL_SCREEN},
21861ba55bcSBaptiste Daroussin 	{"ok-exit-code",      required_argument, NULL, OK_EXIT_CODE},
21961ba55bcSBaptiste Daroussin 	{"ok-label",          required_argument, NULL, OK_LABEL},
22061ba55bcSBaptiste Daroussin 	{"output-fd",         required_argument, NULL, OUTPUT_FD},
22161ba55bcSBaptiste Daroussin 	{"output-separator",  required_argument, NULL, OUTPUT_SEPARATOR},
22261ba55bcSBaptiste Daroussin 	{"print-maxsize",     no_argument,       NULL, PRINT_MAXSIZE},
22361ba55bcSBaptiste Daroussin 	{"print-size",        no_argument,       NULL, PRINT_SIZE},
22461ba55bcSBaptiste Daroussin 	{"print-version",     no_argument,       NULL, PRINT_VERSION},
22561ba55bcSBaptiste Daroussin 	{"quoted",            no_argument,       NULL, QUOTED},
22661ba55bcSBaptiste Daroussin 	{"right1-button",     required_argument, NULL, RIGHT1_BUTTON},
22761ba55bcSBaptiste Daroussin 	{"right1-exit-code",  required_argument, NULL, RIGHT1_EXIT_CODE},
22861ba55bcSBaptiste Daroussin 	{"right2-button",     required_argument, NULL, RIGHT2_BUTTON},
22961ba55bcSBaptiste Daroussin 	{"right2-exit-code",  required_argument, NULL, RIGHT2_EXIT_CODE},
23061ba55bcSBaptiste Daroussin 	{"right3-button",     required_argument, NULL, RIGHT3_BUTTON},
23161ba55bcSBaptiste Daroussin 	{"right3-exit-code",  required_argument, NULL, RIGHT3_EXIT_CODE},
23261ba55bcSBaptiste Daroussin 	{"save-theme",        required_argument, NULL, SAVE_THEME},
23361ba55bcSBaptiste Daroussin 	{"separate-output",   no_argument,       NULL, SEPARATE_OUTPUT},
23461ba55bcSBaptiste Daroussin 	{"separator",         required_argument, NULL, OUTPUT_SEPARATOR},
23561ba55bcSBaptiste Daroussin 	{"shadow",            no_argument,       NULL, SHADOW},
23661ba55bcSBaptiste Daroussin 	{"single-quoted",     no_argument,       NULL, SINGLE_QUOTED},
23761ba55bcSBaptiste Daroussin 	{"sleep",             required_argument, NULL, SLEEP},
23861ba55bcSBaptiste Daroussin 	{"stderr",            no_argument,       NULL, STDERR},
23961ba55bcSBaptiste Daroussin 	{"stdout",            no_argument,       NULL, STDOUT},
24061ba55bcSBaptiste Daroussin 	{"switch-buttons",    no_argument,       NULL, SWITCH_BUTTONS},
24161ba55bcSBaptiste Daroussin 	{"tab-escape",        no_argument,       NULL, TAB_ESCAPE},
24261ba55bcSBaptiste Daroussin 	{"tab-len",           required_argument, NULL, TAB_LEN},
24361ba55bcSBaptiste Daroussin 	{"text-escape",       no_argument,       NULL, TEXT_ESCAPE},
24461ba55bcSBaptiste Daroussin 	{"text-unchanged",    no_argument,       NULL, TEXT_UNCHANGED},
24561ba55bcSBaptiste Daroussin 	{"theme",             required_argument, NULL, THEME},
24661ba55bcSBaptiste Daroussin 	{"timeout-exit-code", required_argument, NULL, TIMEOUT_EXIT_CODE},
24761ba55bcSBaptiste Daroussin 	{"time-format",       required_argument, NULL, TIME_FORMAT},
24861ba55bcSBaptiste Daroussin 	{"title",             required_argument, NULL, TITLE},
24961ba55bcSBaptiste Daroussin 	{"yes-label",         required_argument, NULL, OK_LABEL},
25061ba55bcSBaptiste Daroussin 	/* Dialogs */
25161ba55bcSBaptiste Daroussin 	{"calendar",     no_argument, NULL, CALENDAR},
25261ba55bcSBaptiste Daroussin 	{"checklist",    no_argument, NULL, CHECKLIST},
25361ba55bcSBaptiste Daroussin 	{"datebox",      no_argument, NULL, DATEBOX},
25461ba55bcSBaptiste Daroussin 	{"form",         no_argument, NULL, FORM},
25561ba55bcSBaptiste Daroussin 	{"gauge",        no_argument, NULL, GAUGE},
25661ba55bcSBaptiste Daroussin 	{"infobox",      no_argument, NULL, INFOBOX},
25761ba55bcSBaptiste Daroussin 	{"inputbox",     no_argument, NULL, INPUTBOX},
25861ba55bcSBaptiste Daroussin 	{"menu",         no_argument, NULL, MENU},
25961ba55bcSBaptiste Daroussin 	{"mixedform",    no_argument, NULL, MIXEDFORM},
26061ba55bcSBaptiste Daroussin 	{"mixedgauge",   no_argument, NULL, MIXEDGAUGE},
26161ba55bcSBaptiste Daroussin 	{"msgbox",       no_argument, NULL, MSGBOX},
26261ba55bcSBaptiste Daroussin 	{"passwordbox",  no_argument, NULL, PASSWORDBOX},
26361ba55bcSBaptiste Daroussin 	{"passwordform", no_argument, NULL, PASSWORDFORM},
26461ba55bcSBaptiste Daroussin 	{"pause",        no_argument, NULL, PAUSE},
26561ba55bcSBaptiste Daroussin 	{"radiolist",    no_argument, NULL, RADIOLIST},
26661ba55bcSBaptiste Daroussin 	{"rangebox",     no_argument, NULL, RANGEBOX},
26761ba55bcSBaptiste Daroussin 	{"textbox",      no_argument, NULL, TEXTBOX},
26861ba55bcSBaptiste Daroussin 	{"timebox",      no_argument, NULL, TIMEBOX},
26961ba55bcSBaptiste Daroussin 	{"treeview",     no_argument, NULL, TREEVIEW},
27061ba55bcSBaptiste Daroussin 	{"yesno",        no_argument, NULL, YESNO},
27161ba55bcSBaptiste Daroussin 	/* END */
27261ba55bcSBaptiste Daroussin 	{ NULL, 0, NULL, 0}
27361ba55bcSBaptiste Daroussin };
27461ba55bcSBaptiste Daroussin 
27561ba55bcSBaptiste Daroussin void usage(void)
27661ba55bcSBaptiste Daroussin {
27761ba55bcSBaptiste Daroussin 	printf("usage: bsddialog --help | --version\n");
27861ba55bcSBaptiste Daroussin 	printf("       bsddialog [--<opt>] --<dialog> <text> <rows> <cols> "
27961ba55bcSBaptiste Daroussin 	    "[<arg>] [--<opt>]\n");
28061ba55bcSBaptiste Daroussin 	printf("       bsddialog ... --<dialog1> ... [--and-dialog --<dialog2> "
28161ba55bcSBaptiste Daroussin 	    "...] ...\n");
28261ba55bcSBaptiste Daroussin 	printf("\n");
28361ba55bcSBaptiste Daroussin 
28461ba55bcSBaptiste Daroussin 	printf("Options:\n");
28561ba55bcSBaptiste Daroussin 	printf(" --alternate-screen, --ascii-lines, --backtitle <backtitle>,"
28661ba55bcSBaptiste Daroussin 	    " --begin-x <x>,\n --begin-y <y>, --bikeshed,"
28761ba55bcSBaptiste Daroussin 	    " --cancel-exit-code <retval>, --cancel-label <label>,\n"
28861ba55bcSBaptiste Daroussin 	    " --clear-dialog, --clear-screen, --columns-per-row <columns>,"
28961ba55bcSBaptiste Daroussin 	    " --cr-wrap,\n --datebox-format d/m/y|m/d/y|y/m/d,"
29061ba55bcSBaptiste Daroussin 	    " --date-format <format>,\n --default-button <label>,"
29161ba55bcSBaptiste Daroussin 	    " --default-item <name>, --default-no, --disable-esc,\n"
29261ba55bcSBaptiste Daroussin 	    " --error-exit-code <retval>, --esc-exit-code <retval>,"
29361ba55bcSBaptiste Daroussin 	    " --exit-label <label>,\n --extra-button,"
29461ba55bcSBaptiste Daroussin 	    " --extra-exit-code <retval>, --extra-label <label>,\n"
29561ba55bcSBaptiste Daroussin 	    " --left1-button <label>, --left1-exit-code <retval>,"
29661ba55bcSBaptiste Daroussin 	    " --left2-button <label>,\n --left2-exit-code <retval>,"
29761ba55bcSBaptiste Daroussin 	    " --left3-button <label>, --left3-exit-code <retval>,\n"
29861ba55bcSBaptiste Daroussin 	    " --help-button, --help-exit-code <retval>, --help-label <label>,\n"
29961ba55bcSBaptiste Daroussin 	    " --help-print-items, --help-print-name, --hfile <file>,"
30061ba55bcSBaptiste Daroussin 	    " --hline <string>,\n --hmsg <string>, --ignore, --insecure,"
30161ba55bcSBaptiste Daroussin 	    " --item-bottom-desc, --item-depth,\n --item-prefix,"
30261ba55bcSBaptiste Daroussin 	    " --load-theme <file>, --max-input <size>, --no-cancel,\n"
30361ba55bcSBaptiste Daroussin 	    " --no-descriptions, --no-label <label>, --no-lines, --no-names,"
30461ba55bcSBaptiste Daroussin 	    " --no-ok,\n --no-shadow, --normal-screen, --ok-exit-code <retval>,"
30561ba55bcSBaptiste Daroussin 	    " --ok-label <label>,\n --output-fd <fd>, --output-separator <sep>,"
30661ba55bcSBaptiste Daroussin 	    " --print-maxsize, --print-size,\n --print-version, --quoted,"
30761ba55bcSBaptiste Daroussin 	    " --right1-button <label>,\n --right1-exit-code <retval>,"
30861ba55bcSBaptiste Daroussin 	    " --right2-button <label>,\n --right2-exit-code <retval>,"
30961ba55bcSBaptiste Daroussin 	    " --right3-button <label>,\n --right3-exit-code <retval>,"
31061ba55bcSBaptiste Daroussin 	    " --save-theme <file>, --separate-output,\n --separator <sep>,"
31161ba55bcSBaptiste Daroussin 	    " --shadow, --single-quoted, --sleep <secs>, --stderr,\n --stdout,"
31261ba55bcSBaptiste Daroussin 	    " --switch-buttons, --tab-escape, --tab-len <spaces>,"
31361ba55bcSBaptiste Daroussin 	    " --text-escape,\n --text-unchanged, --theme 3d|blackwhite|flat,"
31461ba55bcSBaptiste Daroussin 	    " --timeout-exit-code <retval>,\n --time-format <format>,"
31561ba55bcSBaptiste Daroussin 	    " --title <title>, --yes-label <label>.");
31661ba55bcSBaptiste Daroussin 	printf("\n\n");
31761ba55bcSBaptiste Daroussin 
31861ba55bcSBaptiste Daroussin 	printf("Dialogs:\n");
31961ba55bcSBaptiste Daroussin 	printf(" --calendar <text> <rows> <cols> [<dd> <mm> <yy>]\n");
32061ba55bcSBaptiste Daroussin 	printf(" --checklist <text> <rows> <cols> <menurows> [<name> <desc> "
32161ba55bcSBaptiste Daroussin 	    "on|off] ...\n");
32261ba55bcSBaptiste Daroussin 	printf(" --datebox <text> <rows> <cols> [<dd> <mm> <yy>]\n");
32361ba55bcSBaptiste Daroussin 	printf(" --form <text> <rows> <cols> <formrows> [<label> <ylabel> "
32461ba55bcSBaptiste Daroussin 	    "<xlabel> <init> <yfield> <xfield> <fieldlen> <maxletters>] "
32561ba55bcSBaptiste Daroussin 	    "...\n");
32661ba55bcSBaptiste Daroussin 	printf(" --gauge <text> <rows> <cols> [<perc>]\n");
32761ba55bcSBaptiste Daroussin 	printf(" --infobox <text> <rows> <cols>\n");
32861ba55bcSBaptiste Daroussin 	printf(" --inputbox <text> <rows> <cols> [<init>]\n");
32961ba55bcSBaptiste Daroussin 	printf(" --menu <text> <rows> <cols> <menurows> [<name> <desc>] ...\n");
33061ba55bcSBaptiste Daroussin 	printf(" --mixedform <text> <rows> <cols> <formrows> [<label> <ylabel> "
33161ba55bcSBaptiste Daroussin 	    "<xlabel> <init> <yfield> <xfield> <fieldlen> <maxletters> "
33261ba55bcSBaptiste Daroussin 	    "0|1|2] ...\n");
33361ba55bcSBaptiste Daroussin 	printf(" --mixedgauge <text> <rows> <cols> <mainperc> [<minilabel> "
33461ba55bcSBaptiste Daroussin 	    "<miniperc>] ...\n");
33561ba55bcSBaptiste Daroussin 	printf(" --msgbox <text> <rows> <cols>\n");
33661ba55bcSBaptiste Daroussin 	printf(" --passwordbox <text> <rows> <cols> [<init>]\n");
33761ba55bcSBaptiste Daroussin 	printf(" --passwordform <text> <rows> <cols> <formrows> [<label> "
33861ba55bcSBaptiste Daroussin 	    "<ylabel> <xlabel> <init> <yfield> <xfield> <fieldlen> "
33961ba55bcSBaptiste Daroussin 	    "<maxletters>] ...\n");
34061ba55bcSBaptiste Daroussin 	printf(" --pause <text> <rows> <cols> <secs>\n");
34161ba55bcSBaptiste Daroussin 	printf(" --radiolist <text> <rows> <cols> <menurows> [<name> <desc> "
34261ba55bcSBaptiste Daroussin 	    "on|off] ...\n");
34361ba55bcSBaptiste Daroussin 	printf(" --rangebox <text> <rows> <cols> <min> <max> [<init>]\n");
34461ba55bcSBaptiste Daroussin 	printf(" --textbox <file> <rows> <cols>\n");
34561ba55bcSBaptiste Daroussin 	printf(" --timebox <text> <rows> <cols> [<hh> <mm> <ss>]\n");
34661ba55bcSBaptiste Daroussin 	printf(" --treeview <text> <rows> <cols> <menurows> [<depth> <name> "
34761ba55bcSBaptiste Daroussin 	    "<desc> on|off] ...\n");
34861ba55bcSBaptiste Daroussin 	printf(" --yesno <text> <rows> <cols>\n");
34961ba55bcSBaptiste Daroussin 	printf("\n");
35061ba55bcSBaptiste Daroussin 
35161ba55bcSBaptiste Daroussin 	printf("See 'man 1 bsddialog' for more information.\n");
35261ba55bcSBaptiste Daroussin }
35361ba55bcSBaptiste Daroussin 
35461ba55bcSBaptiste Daroussin int
35561ba55bcSBaptiste Daroussin parseargs(int argc, char **argv, struct bsddialog_conf *conf,
35661ba55bcSBaptiste Daroussin     struct options *opt)
35761ba55bcSBaptiste Daroussin {
35861ba55bcSBaptiste Daroussin 	int arg, parsed, i;
35961ba55bcSBaptiste Daroussin 	struct winsize ws;
36061ba55bcSBaptiste Daroussin 
36161ba55bcSBaptiste Daroussin 	bsddialog_initconf(conf);
36261ba55bcSBaptiste Daroussin 	conf->key.enable_esc = true;
36361ba55bcSBaptiste Daroussin 	conf->button.always_active = true;
36461ba55bcSBaptiste Daroussin 
36561ba55bcSBaptiste Daroussin 	memset(opt, 0, sizeof(struct options));
36661ba55bcSBaptiste Daroussin 	opt->theme = -1;
36761ba55bcSBaptiste Daroussin 	opt->output_fd = STDERR_FILENO;
36861ba55bcSBaptiste Daroussin 	opt->max_input_form = 2048;
36961ba55bcSBaptiste Daroussin 	opt->mandatory_dialog = true;
37061ba55bcSBaptiste Daroussin 
37161ba55bcSBaptiste Daroussin 	for (i = 0; i < argc; i++) {
37261ba55bcSBaptiste Daroussin 		if (strcmp(argv[i], "--and-dialog") == 0 ||
37361ba55bcSBaptiste Daroussin 		    strcmp(argv[i], "--and-widget") == 0) {
37461ba55bcSBaptiste Daroussin 			argc = i + 1;
37561ba55bcSBaptiste Daroussin 			break;
37661ba55bcSBaptiste Daroussin 		}
37761ba55bcSBaptiste Daroussin 	}
37861ba55bcSBaptiste Daroussin 	parsed = argc;
37961ba55bcSBaptiste Daroussin 	while ((arg = getopt_long(argc, argv, "", longopts, NULL)) != -1) {
38061ba55bcSBaptiste Daroussin 		switch (arg) {
38161ba55bcSBaptiste Daroussin 		/* Options */
38261ba55bcSBaptiste Daroussin 		case ALTERNATE_SCREEN:
38361ba55bcSBaptiste Daroussin 			opt->screen_mode = "smcup";
38461ba55bcSBaptiste Daroussin 			break;
38561ba55bcSBaptiste Daroussin 		case AND_DIALOG:
38661ba55bcSBaptiste Daroussin 			if (opt->dialogbuilder == NULL)
38761ba55bcSBaptiste Daroussin 				exit_error(true,"--and-dialog without "
38861ba55bcSBaptiste Daroussin 				    "previous --<dialog>");
38961ba55bcSBaptiste Daroussin 			break;
39061ba55bcSBaptiste Daroussin 		case ASCII_LINES:
39161ba55bcSBaptiste Daroussin 			conf->ascii_lines = true;
39261ba55bcSBaptiste Daroussin 			break;
39361ba55bcSBaptiste Daroussin 		case BACKTITLE:
39461ba55bcSBaptiste Daroussin 			opt->backtitle = optarg;
39561ba55bcSBaptiste Daroussin 			if (conf->y == BSDDIALOG_CENTER)
39661ba55bcSBaptiste Daroussin 				conf->auto_topmargin = 2;
39761ba55bcSBaptiste Daroussin 			break;
39861ba55bcSBaptiste Daroussin 		case BEGIN_X:
39961ba55bcSBaptiste Daroussin 			conf->x = (int)strtol(optarg, NULL, 10);
40061ba55bcSBaptiste Daroussin 			if (conf->x < BSDDIALOG_CENTER)
40161ba55bcSBaptiste Daroussin 				exit_error(false, "--begin-x %d is < %d",
40261ba55bcSBaptiste Daroussin 				    conf->x, BSDDIALOG_CENTER);
40361ba55bcSBaptiste Daroussin 			break;
40461ba55bcSBaptiste Daroussin 		case BEGIN_Y:
40561ba55bcSBaptiste Daroussin 			conf->y = (int)strtol(optarg, NULL, 10);
40661ba55bcSBaptiste Daroussin 			if (conf->y < BSDDIALOG_CENTER)
40761ba55bcSBaptiste Daroussin 				exit_error(false, "--begin-y %d is < %d",
40861ba55bcSBaptiste Daroussin 				    conf->y, BSDDIALOG_CENTER);
40961ba55bcSBaptiste Daroussin 			conf->auto_topmargin = 0;
41061ba55bcSBaptiste Daroussin 			break;
41161ba55bcSBaptiste Daroussin 		case BIKESHED:
41261ba55bcSBaptiste Daroussin 			opt->bikeshed = true;
41361ba55bcSBaptiste Daroussin 			break;
41461ba55bcSBaptiste Daroussin 		case CANCEL_EXIT_CODE:
41561ba55bcSBaptiste Daroussin 			set_exit_code(BSDDIALOG_CANCEL,
41661ba55bcSBaptiste Daroussin 			    (int)strtol(optarg, NULL, 10));
41761ba55bcSBaptiste Daroussin 			break;
41861ba55bcSBaptiste Daroussin 		case CANCEL_LABEL:
41961ba55bcSBaptiste Daroussin 			conf->button.cancel_label = optarg;
42061ba55bcSBaptiste Daroussin 			break;
42161ba55bcSBaptiste Daroussin 		case CLEAR_DIALOG:
42261ba55bcSBaptiste Daroussin 			conf->clear = true;
42361ba55bcSBaptiste Daroussin 			break;
42461ba55bcSBaptiste Daroussin 		case CLEAR_SCREEN:
42561ba55bcSBaptiste Daroussin 			opt->mandatory_dialog = false;
42661ba55bcSBaptiste Daroussin 			opt->clearscreen = true;
42761ba55bcSBaptiste Daroussin 			break;
42861ba55bcSBaptiste Daroussin 		case COLUMNS_PER_ROW:
42961ba55bcSBaptiste Daroussin 			conf->text.cols_per_row =
43061ba55bcSBaptiste Daroussin 			    (u_int)strtoul(optarg, NULL, 10);
43161ba55bcSBaptiste Daroussin 			break;
43261ba55bcSBaptiste Daroussin 		case CR_WRAP:
43361ba55bcSBaptiste Daroussin 			opt->cr_wrap = true;
43461ba55bcSBaptiste Daroussin 			break;
43561ba55bcSBaptiste Daroussin 		case DATEBOX_FORMAT:
43661ba55bcSBaptiste Daroussin 			if (strcasecmp(optarg, "d/m/y") == 0)
43761ba55bcSBaptiste Daroussin 				conf->date.format = "d/m/y";
43861ba55bcSBaptiste Daroussin 			else if (strcasecmp(optarg, "m/d/y") == 0)
43961ba55bcSBaptiste Daroussin 				conf->date.format = "m/d/y";
44061ba55bcSBaptiste Daroussin 			else if (strcasecmp(optarg, "y/m/d") == 0)
44161ba55bcSBaptiste Daroussin 				conf->date.format = "y/m/d";
44261ba55bcSBaptiste Daroussin 			else
44361ba55bcSBaptiste Daroussin 				exit_error(true,
44461ba55bcSBaptiste Daroussin 				    "date format \"%s\" is invalid", optarg);
44561ba55bcSBaptiste Daroussin 			break;
44661ba55bcSBaptiste Daroussin 		case DATE_FORMAT:
44761ba55bcSBaptiste Daroussin 			opt->date_fmt = optarg;
44861ba55bcSBaptiste Daroussin 			break;
44961ba55bcSBaptiste Daroussin 		case DEFAULT_BUTTON:
45061ba55bcSBaptiste Daroussin 			conf->button.default_label = optarg;
45161ba55bcSBaptiste Daroussin 			break;
45261ba55bcSBaptiste Daroussin 		case DEFAULT_ITEM:
45361ba55bcSBaptiste Daroussin 			opt->item_default = optarg;
45461ba55bcSBaptiste Daroussin 			break;
45561ba55bcSBaptiste Daroussin 		case DEFAULT_NO:
45661ba55bcSBaptiste Daroussin 			conf->button.default_cancel = true;
45761ba55bcSBaptiste Daroussin 			break;
45861ba55bcSBaptiste Daroussin 		case DISABLE_ESC:
45961ba55bcSBaptiste Daroussin 			conf->key.enable_esc = false;
46061ba55bcSBaptiste Daroussin 			break;
46161ba55bcSBaptiste Daroussin 		case ERROR_EXIT_CODE:
46261ba55bcSBaptiste Daroussin 			set_exit_code(BSDDIALOG_ERROR,
46361ba55bcSBaptiste Daroussin 			    (int)strtol(optarg, NULL, 10));
46461ba55bcSBaptiste Daroussin 			break;
46561ba55bcSBaptiste Daroussin 		case ESC_EXIT_CODE:
46661ba55bcSBaptiste Daroussin 			set_exit_code(BSDDIALOG_ESC,
46761ba55bcSBaptiste Daroussin 			    (int)strtol(optarg, NULL, 10));
46861ba55bcSBaptiste Daroussin 			break;
46961ba55bcSBaptiste Daroussin 		case EXIT_LABEL:
47061ba55bcSBaptiste Daroussin 			conf->button.ok_label = optarg;
47161ba55bcSBaptiste Daroussin 			break;
47261ba55bcSBaptiste Daroussin 		case EXTRA_BUTTON:
47361ba55bcSBaptiste Daroussin 			conf->button.with_extra = true;
47461ba55bcSBaptiste Daroussin 			break;
47561ba55bcSBaptiste Daroussin 		case EXTRA_EXIT_CODE:
47661ba55bcSBaptiste Daroussin 			set_exit_code(BSDDIALOG_EXTRA,
47761ba55bcSBaptiste Daroussin 			    (int)strtol(optarg, NULL, 10));
47861ba55bcSBaptiste Daroussin 			break;
47961ba55bcSBaptiste Daroussin 		case EXTRA_LABEL:
48061ba55bcSBaptiste Daroussin 			conf->button.extra_label = optarg;
48161ba55bcSBaptiste Daroussin 			break;
48261ba55bcSBaptiste Daroussin 		case HELP_BUTTON:
48361ba55bcSBaptiste Daroussin 			conf->button.with_help = true;
48461ba55bcSBaptiste Daroussin 			break;
48561ba55bcSBaptiste Daroussin 		case HELP_EXIT_CODE:
48661ba55bcSBaptiste Daroussin 			i = (int)strtol(optarg, NULL, 10);
48761ba55bcSBaptiste Daroussin 			set_exit_code(BSDDIALOG_HELP, i);
48861ba55bcSBaptiste Daroussin 			/* _TEM_HELP follows _HELP */
48961ba55bcSBaptiste Daroussin 			set_exit_code(BSDDIALOG_ITEM_HELP, i);
49061ba55bcSBaptiste Daroussin 			break;
49161ba55bcSBaptiste Daroussin 		case HELP_LABEL:
49261ba55bcSBaptiste Daroussin 			conf->button.help_label = optarg;
49361ba55bcSBaptiste Daroussin 			break;
49461ba55bcSBaptiste Daroussin 		case HELP_PRINT_ITEMS:
49561ba55bcSBaptiste Daroussin 			opt->help_print_items = true;
49661ba55bcSBaptiste Daroussin 			break;
49761ba55bcSBaptiste Daroussin 		case HELP_PRINT_NAME:
49861ba55bcSBaptiste Daroussin 			opt->help_print_item_name = true;
49961ba55bcSBaptiste Daroussin 			break;
50061ba55bcSBaptiste Daroussin 		case HFILE:
50161ba55bcSBaptiste Daroussin 			conf->key.f1_file = optarg;
50261ba55bcSBaptiste Daroussin 			break;
50361ba55bcSBaptiste Daroussin 		case HLINE:
50461ba55bcSBaptiste Daroussin 			if (optarg[0] != '\0')
50561ba55bcSBaptiste Daroussin 				conf->bottomtitle = optarg;
50661ba55bcSBaptiste Daroussin 			break;
50761ba55bcSBaptiste Daroussin 		case HMSG:
50861ba55bcSBaptiste Daroussin 			conf->key.f1_message = optarg;
50961ba55bcSBaptiste Daroussin 			break;
51061ba55bcSBaptiste Daroussin 		case IGNORE:
51161ba55bcSBaptiste Daroussin 			opt->ignore = true;
51261ba55bcSBaptiste Daroussin 			break;
51361ba55bcSBaptiste Daroussin 		case INSECURE:
51461ba55bcSBaptiste Daroussin 			conf->form.securech = '*';
51561ba55bcSBaptiste Daroussin 			break;
51661ba55bcSBaptiste Daroussin 		case ITEM_BOTTOM_DESC:
51761ba55bcSBaptiste Daroussin 			opt->item_bottomdesc = true;
51861ba55bcSBaptiste Daroussin 			break;
51961ba55bcSBaptiste Daroussin 		case ITEM_DEPTH:
52061ba55bcSBaptiste Daroussin 			opt->item_depth = true;
52161ba55bcSBaptiste Daroussin 			break;
52261ba55bcSBaptiste Daroussin 		case ITEM_PREFIX:
52361ba55bcSBaptiste Daroussin 			opt->item_prefix = true;
52461ba55bcSBaptiste Daroussin 			break;
52561ba55bcSBaptiste Daroussin 		case LEFT1_BUTTON:
52661ba55bcSBaptiste Daroussin 			conf->button.left1_label = optarg;
52761ba55bcSBaptiste Daroussin 			break;
52861ba55bcSBaptiste Daroussin 		case LEFT1_EXIT_CODE:
52961ba55bcSBaptiste Daroussin 			set_exit_code(BSDDIALOG_LEFT1,
53061ba55bcSBaptiste Daroussin 			    (int)strtol(optarg, NULL, 10));
53161ba55bcSBaptiste Daroussin 			break;
53261ba55bcSBaptiste Daroussin 		case LEFT2_BUTTON:
53361ba55bcSBaptiste Daroussin 			conf->button.left2_label = optarg;
53461ba55bcSBaptiste Daroussin 			break;
53561ba55bcSBaptiste Daroussin 		case LEFT2_EXIT_CODE:
53661ba55bcSBaptiste Daroussin 			set_exit_code(BSDDIALOG_LEFT2,
53761ba55bcSBaptiste Daroussin 			    (int)strtol(optarg, NULL, 10));
53861ba55bcSBaptiste Daroussin 			break;
53961ba55bcSBaptiste Daroussin 		case LEFT3_BUTTON:
54061ba55bcSBaptiste Daroussin 			conf->button.left3_label = optarg;
54161ba55bcSBaptiste Daroussin 			break;
54261ba55bcSBaptiste Daroussin 		case LEFT3_EXIT_CODE:
54361ba55bcSBaptiste Daroussin 			set_exit_code(BSDDIALOG_LEFT3,
54461ba55bcSBaptiste Daroussin 			    (int)strtol(optarg, NULL, 10));
54561ba55bcSBaptiste Daroussin 			break;
54661ba55bcSBaptiste Daroussin 		case LOAD_THEME:
54761ba55bcSBaptiste Daroussin 			opt->loadthemefile = optarg;
54861ba55bcSBaptiste Daroussin 			break;
549*d4ca0015SKyle Evans 		case MAX_INPUT_FORM:
55061ba55bcSBaptiste Daroussin 			opt->max_input_form = (u_int)strtoul(optarg, NULL, 10);
55161ba55bcSBaptiste Daroussin 			break;
55261ba55bcSBaptiste Daroussin 		case NO_CANCEL:
55361ba55bcSBaptiste Daroussin 			conf->button.without_cancel = true;
55461ba55bcSBaptiste Daroussin 			break;
55561ba55bcSBaptiste Daroussin 		case NO_DESCRIPTIONS:
55661ba55bcSBaptiste Daroussin 			conf->menu.no_desc = true;
55761ba55bcSBaptiste Daroussin 			break;
55861ba55bcSBaptiste Daroussin 		case NO_LINES:
55961ba55bcSBaptiste Daroussin 			conf->no_lines = true;
56061ba55bcSBaptiste Daroussin 			break;
56161ba55bcSBaptiste Daroussin 		case NO_NAMES:
56261ba55bcSBaptiste Daroussin 			conf->menu.no_name = true;
56361ba55bcSBaptiste Daroussin 			break;
56461ba55bcSBaptiste Daroussin 		case NO_OK:
56561ba55bcSBaptiste Daroussin 			conf->button.without_ok = true;
56661ba55bcSBaptiste Daroussin 			break;
56761ba55bcSBaptiste Daroussin 		case NO_SHADOW:
56861ba55bcSBaptiste Daroussin 			conf->shadow = false;
56961ba55bcSBaptiste Daroussin 			break;
57061ba55bcSBaptiste Daroussin 		case NORMAL_SCREEN:
57161ba55bcSBaptiste Daroussin 			opt->screen_mode = "rmcup";
57261ba55bcSBaptiste Daroussin 			break;
57361ba55bcSBaptiste Daroussin 		case OK_EXIT_CODE:
57461ba55bcSBaptiste Daroussin 			set_exit_code(BSDDIALOG_OK,
57561ba55bcSBaptiste Daroussin 			    (int)strtol(optarg, NULL, 10));
57661ba55bcSBaptiste Daroussin 			break;
57761ba55bcSBaptiste Daroussin 		case OK_LABEL:
57861ba55bcSBaptiste Daroussin 			conf->button.ok_label = optarg;
57961ba55bcSBaptiste Daroussin 			break;
58061ba55bcSBaptiste Daroussin 		case OUTPUT_FD:
58161ba55bcSBaptiste Daroussin 			opt->output_fd = (int)strtol(optarg, NULL, 10);
58261ba55bcSBaptiste Daroussin 			break;
58361ba55bcSBaptiste Daroussin 		case OUTPUT_SEPARATOR:
58461ba55bcSBaptiste Daroussin 			opt->item_output_sep = optarg;
58561ba55bcSBaptiste Daroussin 			break;
58661ba55bcSBaptiste Daroussin 		case QUOTED:
58761ba55bcSBaptiste Daroussin 			opt->item_always_quote = true;
58861ba55bcSBaptiste Daroussin 			break;
58961ba55bcSBaptiste Daroussin 		case PRINT_MAXSIZE:
59061ba55bcSBaptiste Daroussin 			opt->mandatory_dialog = false;
59161ba55bcSBaptiste Daroussin 			ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws);
59261ba55bcSBaptiste Daroussin 			dprintf(opt->output_fd, "MaxSize: %d, %d\n",
59361ba55bcSBaptiste Daroussin 			    ws.ws_row, ws.ws_col);
59461ba55bcSBaptiste Daroussin 			break;
59561ba55bcSBaptiste Daroussin 		case PRINT_SIZE:
59661ba55bcSBaptiste Daroussin 			conf->get_height = &opt->getH;
59761ba55bcSBaptiste Daroussin 			conf->get_width = &opt->getW;
59861ba55bcSBaptiste Daroussin 			break;
59961ba55bcSBaptiste Daroussin 		case PRINT_VERSION:
60061ba55bcSBaptiste Daroussin 			opt->mandatory_dialog = false;
60161ba55bcSBaptiste Daroussin 			dprintf(opt->output_fd, "Version: %s\n",
60261ba55bcSBaptiste Daroussin 			    LIBBSDDIALOG_VERSION);
60361ba55bcSBaptiste Daroussin 			break;
60461ba55bcSBaptiste Daroussin 		case RIGHT1_BUTTON:
60561ba55bcSBaptiste Daroussin 			conf->button.right1_label = optarg;
60661ba55bcSBaptiste Daroussin 			break;
60761ba55bcSBaptiste Daroussin 		case RIGHT1_EXIT_CODE:
60861ba55bcSBaptiste Daroussin 			set_exit_code(BSDDIALOG_RIGHT1,
60961ba55bcSBaptiste Daroussin 			    (int)strtol(optarg, NULL, 10));
61061ba55bcSBaptiste Daroussin 			break;
61161ba55bcSBaptiste Daroussin 		case RIGHT2_BUTTON:
61261ba55bcSBaptiste Daroussin 			conf->button.right2_label = optarg;
61361ba55bcSBaptiste Daroussin 			break;
61461ba55bcSBaptiste Daroussin 		case RIGHT2_EXIT_CODE:
61561ba55bcSBaptiste Daroussin 			set_exit_code(BSDDIALOG_RIGHT2,
61661ba55bcSBaptiste Daroussin 			    (int)strtol(optarg, NULL, 10));
61761ba55bcSBaptiste Daroussin 			break;
61861ba55bcSBaptiste Daroussin 		case RIGHT3_BUTTON:
61961ba55bcSBaptiste Daroussin 			conf->button.right3_label = optarg;
62061ba55bcSBaptiste Daroussin 			break;
62161ba55bcSBaptiste Daroussin 		case RIGHT3_EXIT_CODE:
62261ba55bcSBaptiste Daroussin 			set_exit_code(BSDDIALOG_RIGHT3,
62361ba55bcSBaptiste Daroussin 			    (int)strtol(optarg, NULL, 10));
62461ba55bcSBaptiste Daroussin 			break;
62561ba55bcSBaptiste Daroussin 		case SAVE_THEME:
62661ba55bcSBaptiste Daroussin 			opt->mandatory_dialog = false;
62761ba55bcSBaptiste Daroussin 			opt->savethemefile = optarg;
62861ba55bcSBaptiste Daroussin 			break;
62961ba55bcSBaptiste Daroussin 		case SEPARATE_OUTPUT:
63061ba55bcSBaptiste Daroussin 			opt->item_output_sepnl = true;
63161ba55bcSBaptiste Daroussin 			break;
63261ba55bcSBaptiste Daroussin 		case SHADOW:
63361ba55bcSBaptiste Daroussin 			conf->shadow = true;
63461ba55bcSBaptiste Daroussin 			break;
63561ba55bcSBaptiste Daroussin 		case SINGLE_QUOTED:
63661ba55bcSBaptiste Daroussin 			opt->item_singlequote = true;
63761ba55bcSBaptiste Daroussin 			break;
63861ba55bcSBaptiste Daroussin 		case SLEEP:
63961ba55bcSBaptiste Daroussin 			conf->sleep = (u_int)strtoul(optarg, NULL, 10);
64061ba55bcSBaptiste Daroussin 			break;
64161ba55bcSBaptiste Daroussin 		case STDERR:
64261ba55bcSBaptiste Daroussin 			opt->output_fd = STDERR_FILENO;
64361ba55bcSBaptiste Daroussin 			break;
64461ba55bcSBaptiste Daroussin 		case STDOUT:
64561ba55bcSBaptiste Daroussin 			opt->output_fd = STDOUT_FILENO;
64661ba55bcSBaptiste Daroussin 			break;
64761ba55bcSBaptiste Daroussin 		case SWITCH_BUTTONS:
64861ba55bcSBaptiste Daroussin 			conf->button.always_active = false;
64961ba55bcSBaptiste Daroussin 			break;
65061ba55bcSBaptiste Daroussin 		case TAB_ESCAPE:
65161ba55bcSBaptiste Daroussin 			opt->tab_escape = true;
65261ba55bcSBaptiste Daroussin 			break;
65361ba55bcSBaptiste Daroussin 		case TAB_LEN:
65461ba55bcSBaptiste Daroussin 			conf->text.tablen = (u_int)strtoul(optarg, NULL, 10);
65561ba55bcSBaptiste Daroussin 			break;
65661ba55bcSBaptiste Daroussin 		case TEXT_ESCAPE:
65761ba55bcSBaptiste Daroussin 			conf->text.escape = true;
65861ba55bcSBaptiste Daroussin 			break;
65961ba55bcSBaptiste Daroussin 		case TEXT_UNCHANGED:
66061ba55bcSBaptiste Daroussin 			opt->text_unchanged = true;
66161ba55bcSBaptiste Daroussin 			break;
66261ba55bcSBaptiste Daroussin 		case THEME:
66361ba55bcSBaptiste Daroussin 			if (strcasecmp(optarg, "blackwhite") == 0)
66461ba55bcSBaptiste Daroussin 				opt->theme = BSDDIALOG_THEME_BLACKWHITE;
66561ba55bcSBaptiste Daroussin 			else if (strcasecmp(optarg, "flat") == 0)
66661ba55bcSBaptiste Daroussin 				opt->theme = BSDDIALOG_THEME_FLAT;
66761ba55bcSBaptiste Daroussin 			else if (strcasecmp(optarg, "3d") == 0)
66861ba55bcSBaptiste Daroussin 				opt->theme = BSDDIALOG_THEME_3D;
66961ba55bcSBaptiste Daroussin 			else
67061ba55bcSBaptiste Daroussin 				exit_error(true,
67161ba55bcSBaptiste Daroussin 				    "--theme: \"%s\" is unknown", optarg);
67261ba55bcSBaptiste Daroussin 			break;
67361ba55bcSBaptiste Daroussin 		case TIMEOUT_EXIT_CODE:
67461ba55bcSBaptiste Daroussin 			set_exit_code(BSDDIALOG_TIMEOUT,
67561ba55bcSBaptiste Daroussin 			    (int)strtol(optarg, NULL, 10));
67661ba55bcSBaptiste Daroussin 			break;
67761ba55bcSBaptiste Daroussin 		case TIME_FORMAT:
67861ba55bcSBaptiste Daroussin 			opt->time_fmt = optarg;
67961ba55bcSBaptiste Daroussin 			break;
68061ba55bcSBaptiste Daroussin 		case TITLE:
68161ba55bcSBaptiste Daroussin 			conf->title = optarg;
68261ba55bcSBaptiste Daroussin 			break;
68361ba55bcSBaptiste Daroussin 		/* Dialogs */
68461ba55bcSBaptiste Daroussin 		case CALENDAR:
68561ba55bcSBaptiste Daroussin 			if (opt->dialogbuilder != NULL)
68661ba55bcSBaptiste Daroussin 				exit_error(true, "%s and --calendar without "
68761ba55bcSBaptiste Daroussin 				    "--and-dialog", opt->name);
68861ba55bcSBaptiste Daroussin 			opt->name = "--calendar";
68961ba55bcSBaptiste Daroussin 			opt->dialogbuilder = calendar_builder;
69061ba55bcSBaptiste Daroussin 			break;
69161ba55bcSBaptiste Daroussin 		case CHECKLIST:
69261ba55bcSBaptiste Daroussin 			if (opt->dialogbuilder != NULL)
69361ba55bcSBaptiste Daroussin 				exit_error(true, "%s and --checklist without "
69461ba55bcSBaptiste Daroussin 				    "--and-dialog", opt->name);
69561ba55bcSBaptiste Daroussin 			opt->name = "--checklist";
69661ba55bcSBaptiste Daroussin 			opt->dialogbuilder = checklist_builder;
69761ba55bcSBaptiste Daroussin 			conf->auto_downmargin = 1;
69861ba55bcSBaptiste Daroussin 			break;
69961ba55bcSBaptiste Daroussin 		case DATEBOX:
70061ba55bcSBaptiste Daroussin 			if (opt->dialogbuilder != NULL)
70161ba55bcSBaptiste Daroussin 				exit_error(true, "%s and --datebox without "
70261ba55bcSBaptiste Daroussin 				    "--and-dialog", opt->name);
70361ba55bcSBaptiste Daroussin 			opt->name = "--datebox";
70461ba55bcSBaptiste Daroussin 			opt->dialogbuilder = datebox_builder;
70561ba55bcSBaptiste Daroussin 			break;
70661ba55bcSBaptiste Daroussin 		case FORM:
70761ba55bcSBaptiste Daroussin 			if (opt->dialogbuilder != NULL)
70861ba55bcSBaptiste Daroussin 				exit_error(true, "%s and --form without "
70961ba55bcSBaptiste Daroussin 				    "--and-dialog", opt->name);
71061ba55bcSBaptiste Daroussin 			opt->name = "--form";
71161ba55bcSBaptiste Daroussin 			opt->dialogbuilder = form_builder;
71261ba55bcSBaptiste Daroussin 			conf->auto_downmargin = 1;
71361ba55bcSBaptiste Daroussin 			break;
71461ba55bcSBaptiste Daroussin 		case GAUGE:
71561ba55bcSBaptiste Daroussin 			if (opt->dialogbuilder != NULL)
71661ba55bcSBaptiste Daroussin 				exit_error(true, "%s and --gauge without "
71761ba55bcSBaptiste Daroussin 				    "--and-dialog", opt->name);
71861ba55bcSBaptiste Daroussin 			opt->name = "--gauge";
71961ba55bcSBaptiste Daroussin 			opt->dialogbuilder = gauge_builder;
72061ba55bcSBaptiste Daroussin 			break;
72161ba55bcSBaptiste Daroussin 		case INFOBOX:
72261ba55bcSBaptiste Daroussin 			if (opt->dialogbuilder != NULL)
72361ba55bcSBaptiste Daroussin 				exit_error(true, "%s and --infobox without "
72461ba55bcSBaptiste Daroussin 				    "--and-dialog", opt->name);
72561ba55bcSBaptiste Daroussin 			opt->name = "--infobox";
72661ba55bcSBaptiste Daroussin 			opt->dialogbuilder = infobox_builder;
72761ba55bcSBaptiste Daroussin 			break;
72861ba55bcSBaptiste Daroussin 		case INPUTBOX:
72961ba55bcSBaptiste Daroussin 			if (opt->dialogbuilder != NULL)
73061ba55bcSBaptiste Daroussin 				exit_error(true, "%s and --inputbox without "
73161ba55bcSBaptiste Daroussin 				    "--and-dialog", opt->name);
73261ba55bcSBaptiste Daroussin 			opt->name = "--inputbox";
73361ba55bcSBaptiste Daroussin 			opt->dialogbuilder = inputbox_builder;
73461ba55bcSBaptiste Daroussin 			conf->auto_downmargin = 1;
73561ba55bcSBaptiste Daroussin 			break;
73661ba55bcSBaptiste Daroussin 		case MENU:
73761ba55bcSBaptiste Daroussin 			if (opt->dialogbuilder != NULL)
73861ba55bcSBaptiste Daroussin 				exit_error(true, "%s and --menu without "
73961ba55bcSBaptiste Daroussin 				    "--and-dialog", opt->name);
74061ba55bcSBaptiste Daroussin 			opt->name = "--menu";
74161ba55bcSBaptiste Daroussin 			opt->dialogbuilder = menu_builder;
74261ba55bcSBaptiste Daroussin 			conf->auto_downmargin = 1;
74361ba55bcSBaptiste Daroussin 			break;
74461ba55bcSBaptiste Daroussin 		case MIXEDFORM:
74561ba55bcSBaptiste Daroussin 			if (opt->dialogbuilder != NULL)
74661ba55bcSBaptiste Daroussin 				exit_error(true, "%s and --mixedform without "
74761ba55bcSBaptiste Daroussin 				    "--and-dialog", opt->name);
74861ba55bcSBaptiste Daroussin 			opt->name = "--mixedform";
74961ba55bcSBaptiste Daroussin 			opt->dialogbuilder = mixedform_builder;
75061ba55bcSBaptiste Daroussin 			conf->auto_downmargin = 1;
75161ba55bcSBaptiste Daroussin 			break;
75261ba55bcSBaptiste Daroussin 		case MIXEDGAUGE:
75361ba55bcSBaptiste Daroussin 			if (opt->dialogbuilder != NULL)
75461ba55bcSBaptiste Daroussin 				exit_error(true, "%s and --mixedgauge without "
75561ba55bcSBaptiste Daroussin 				    "--and-dialog", opt->name);
75661ba55bcSBaptiste Daroussin 			opt->name = "--mixedgauge";
75761ba55bcSBaptiste Daroussin 			opt->dialogbuilder = mixedgauge_builder;
75861ba55bcSBaptiste Daroussin 			break;
75961ba55bcSBaptiste Daroussin 		case MSGBOX:
76061ba55bcSBaptiste Daroussin 			if (opt->dialogbuilder != NULL)
76161ba55bcSBaptiste Daroussin 				exit_error(true, "%s and --msgbox without "
76261ba55bcSBaptiste Daroussin 				    "--and-dialog", opt->name);
76361ba55bcSBaptiste Daroussin 			opt->name = "--";
76461ba55bcSBaptiste Daroussin 			opt->dialogbuilder = msgbox_builder;
76561ba55bcSBaptiste Daroussin 			break;
76661ba55bcSBaptiste Daroussin 		case PAUSE:
76761ba55bcSBaptiste Daroussin 			if (opt->dialogbuilder != NULL)
76861ba55bcSBaptiste Daroussin 				exit_error(true, "%s and --pause without "
76961ba55bcSBaptiste Daroussin 				    "--and-dialog", opt->name);
77061ba55bcSBaptiste Daroussin 			opt->name = "--pause";
77161ba55bcSBaptiste Daroussin 			opt->dialogbuilder = pause_builder;
77261ba55bcSBaptiste Daroussin 			break;
77361ba55bcSBaptiste Daroussin 		case PASSWORDBOX:
77461ba55bcSBaptiste Daroussin 			if (opt->dialogbuilder != NULL)
77561ba55bcSBaptiste Daroussin 				exit_error(true, "%s and --passwordbox without "
77661ba55bcSBaptiste Daroussin 				    "--and-dialog", opt->name);
77761ba55bcSBaptiste Daroussin 			opt->name = "--passwordbox";
77861ba55bcSBaptiste Daroussin 			opt->dialogbuilder = passwordbox_builder;
77961ba55bcSBaptiste Daroussin 			conf->auto_downmargin = 1;
78061ba55bcSBaptiste Daroussin 			break;
78161ba55bcSBaptiste Daroussin 		case PASSWORDFORM:
78261ba55bcSBaptiste Daroussin 			if (opt->dialogbuilder != NULL)
78361ba55bcSBaptiste Daroussin 				exit_error(true, "%s and --passwordform "
78461ba55bcSBaptiste Daroussin 				    "without --and-dialog", opt->name);
78561ba55bcSBaptiste Daroussin 			opt->name = "--passwordform";
78661ba55bcSBaptiste Daroussin 			opt->dialogbuilder = passwordform_builder;
78761ba55bcSBaptiste Daroussin 			conf->auto_downmargin = 1;
78861ba55bcSBaptiste Daroussin 			break;
78961ba55bcSBaptiste Daroussin 		case RADIOLIST:
79061ba55bcSBaptiste Daroussin 			if (opt->dialogbuilder != NULL)
79161ba55bcSBaptiste Daroussin 				exit_error(true, "%s and --radiolist without "
79261ba55bcSBaptiste Daroussin 				    "--and-dialog", opt->name);
79361ba55bcSBaptiste Daroussin 			opt->name = "--radiolist";
79461ba55bcSBaptiste Daroussin 			opt->dialogbuilder = radiolist_builder;
79561ba55bcSBaptiste Daroussin 			conf->auto_downmargin = 1;
79661ba55bcSBaptiste Daroussin 			break;
79761ba55bcSBaptiste Daroussin 		case RANGEBOX:
79861ba55bcSBaptiste Daroussin 			if (opt->dialogbuilder != NULL)
79961ba55bcSBaptiste Daroussin 				exit_error(true, "%s and --rangebox without "
80061ba55bcSBaptiste Daroussin 				    "--and-dialog", opt->name);
80161ba55bcSBaptiste Daroussin 			opt->name = "--rangebox";
80261ba55bcSBaptiste Daroussin 			opt->dialogbuilder = rangebox_builder;
80361ba55bcSBaptiste Daroussin 			break;
80461ba55bcSBaptiste Daroussin 		case TEXTBOX:
80561ba55bcSBaptiste Daroussin 			if (opt->dialogbuilder != NULL)
80661ba55bcSBaptiste Daroussin 				exit_error(true, "%s and --textbox without "
80761ba55bcSBaptiste Daroussin 				    "--and-dialog", opt->name);
80861ba55bcSBaptiste Daroussin 			opt->name = "--textbox";
80961ba55bcSBaptiste Daroussin 			opt->dialogbuilder = textbox_builder;
81061ba55bcSBaptiste Daroussin 			break;
81161ba55bcSBaptiste Daroussin 		case TIMEBOX:
81261ba55bcSBaptiste Daroussin 			if (opt->dialogbuilder != NULL)
81361ba55bcSBaptiste Daroussin 				exit_error(true, "%s and --timebox without "
81461ba55bcSBaptiste Daroussin 				    "--and-dialog", opt->name);
81561ba55bcSBaptiste Daroussin 			opt->name = "--timebox";
81661ba55bcSBaptiste Daroussin 			opt->dialogbuilder = timebox_builder;
81761ba55bcSBaptiste Daroussin 			break;
81861ba55bcSBaptiste Daroussin 		case TREEVIEW:
81961ba55bcSBaptiste Daroussin 			if (opt->dialogbuilder != NULL)
82061ba55bcSBaptiste Daroussin 				exit_error(true, "%s and --treeview without "
82161ba55bcSBaptiste Daroussin 				    "--and-dialog", opt->name);
82261ba55bcSBaptiste Daroussin 			opt->name = "--treeview";
82361ba55bcSBaptiste Daroussin 			opt->dialogbuilder = treeview_builder;
82461ba55bcSBaptiste Daroussin 			conf->auto_downmargin = 1;
82561ba55bcSBaptiste Daroussin 			break;
82661ba55bcSBaptiste Daroussin 		case YESNO:
82761ba55bcSBaptiste Daroussin 			if (opt->dialogbuilder != NULL)
82861ba55bcSBaptiste Daroussin 				exit_error(true, "%s and --yesno without "
82961ba55bcSBaptiste Daroussin 				    "--and-dialog", opt->name);
83061ba55bcSBaptiste Daroussin 			opt->name = "--yesno";
83161ba55bcSBaptiste Daroussin 			opt->dialogbuilder = yesno_builder;
83261ba55bcSBaptiste Daroussin 			break;
83361ba55bcSBaptiste Daroussin 		default: /* Error */
83461ba55bcSBaptiste Daroussin 			if (opt->ignore == true)
83561ba55bcSBaptiste Daroussin 				break;
83661ba55bcSBaptiste Daroussin 			exit_error(true, "--ignore to continue");
83761ba55bcSBaptiste Daroussin 		}
83861ba55bcSBaptiste Daroussin 	}
83961ba55bcSBaptiste Daroussin 
84061ba55bcSBaptiste Daroussin 	return (parsed);
84161ba55bcSBaptiste Daroussin }
842