2 * dialog - Display simple dialog boxes from shell scripts
4 * ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
5 * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcap@cfw.com)
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 static void Usage (const char *name
);
26 typedef int (jumperFn
) (const char *title
, int argc
, const char * const * argv
);
30 int argmin
, argmax
, argmod
;
34 jumperFn j_menu
, j_checklist
, j_radiolist
, j_yesno
, j_textbox
, j_inputbox
;
35 jumperFn j_msgbox
, j_infobox
;
37 static struct Mode modes
[] =
39 {"--menu", 9, 0, 3, j_menu
},
40 {"--checklist", 9, 0, 3, j_checklist
},
41 {"--radiolist", 9, 0, 3, j_radiolist
},
42 {"--yesno", 5,5,1, j_yesno
},
43 {"--textbox", 5,5,1, j_textbox
},
44 {"--inputbox", 5, 6, 1, j_inputbox
},
45 {"--msgbox", 5, 5, 1, j_msgbox
},
46 {"--infobox", 5, 5, 1, j_infobox
},
50 static struct Mode
*modePtr
;
57 main (int argc
, const char * const * argv
)
59 int offset
= 0, opt_clear
= 0, end_common_opts
= 0, retval
;
60 const char *title
= NULL
;
63 (void) setlocale (LC_ALL
, "");
67 trace(TRACE_CALLS
|TRACE_UPDATE
);
74 while (offset
< argc
- 1 && !end_common_opts
) { /* Common options */
75 if (!strcmp (argv
[offset
+ 1], "--title")) {
76 if (argc
- offset
< 3 || title
!= NULL
) {
80 title
= argv
[offset
+ 2];
83 } else if (!strcmp (argv
[offset
+ 1], "--backtitle")) {
84 if (backtitle
!= NULL
) {
88 backtitle
= argv
[offset
+ 2];
91 } else if (!strcmp (argv
[offset
+ 1], "--clear")) {
92 if (opt_clear
) { /* Hey, "--clear" can't appear twice! */
95 } else if (argc
== 2) { /* we only want to clear the screen */
97 refresh (); /* init_dialog() will clear the screen for us */
104 } else /* no more common options */
108 if (argc
- 1 == offset
) { /* no more options */
112 /* use a table to look for the requested mode, to avoid code duplication */
114 for (modePtr
= modes
; modePtr
->name
; modePtr
++) /* look for the mode */
115 if (!strcmp (argv
[offset
+ 1], modePtr
->name
))
120 if (argc
- offset
< modePtr
->argmin
)
122 if (modePtr
->argmax
&& argc
- offset
> modePtr
->argmax
)
128 retval
= (*(modePtr
->jumper
)) (title
, argc
- offset
, argv
+ offset
);
130 if (opt_clear
) { /* clear screen before exit */
131 attr_clear (stdscr
, LINES
, COLS
, screen_attr
);
140 * Print program usage
143 Usage (const char *name
)
146 \ndialog, by Savio Lam (lam836@cs.cuhk.hk).\
147 \n patched by Stuart Herbert (S.Herbert@shef.ac.uk)\
148 \n modified/gutted for use as a Linux kernel config tool by \
149 \n William Roadcap (roadcapw@cfw.com)\
151 \n* Display dialog boxes from shell scripts *\
154 \n %s [--title <title>] [--backtitle <backtitle>] --clear <Box options>\
158 \n --menu <text> <height> <width> <menu height> <tag1> <item1>...\
159 \n --checklist <text> <height> <width> <list height> <tag1> <item1> <status1>...\
160 \n --radiolist <text> <height> <width> <list height> <tag1> <item1> <status1>...\
161 \n --textbox <file> <height> <width>\
162 \n --inputbox <text> <height> <width> [<init>]\
163 \n --yesno <text> <height> <width>\
169 * These are the program jumpers
173 j_menu (const char *t
, int ac
, const char * const * av
)
175 return dialog_menu (t
, av
[2], atoi (av
[3]), atoi (av
[4]),
176 atoi (av
[5]), av
[6], (ac
- 6) / 2, av
+ 7);
180 j_checklist (const char *t
, int ac
, const char * const * av
)
182 return dialog_checklist (t
, av
[2], atoi (av
[3]), atoi (av
[4]),
183 atoi (av
[5]), (ac
- 6) / 3, av
+ 6, FLAG_CHECK
);
187 j_radiolist (const char *t
, int ac
, const char * const * av
)
189 return dialog_checklist (t
, av
[2], atoi (av
[3]), atoi (av
[4]),
190 atoi (av
[5]), (ac
- 6) / 3, av
+ 6, FLAG_RADIO
);
194 j_textbox (const char *t
, int ac
, const char * const * av
)
196 return dialog_textbox (t
, av
[2], atoi (av
[3]), atoi (av
[4]));
200 j_yesno (const char *t
, int ac
, const char * const * av
)
202 return dialog_yesno (t
, av
[2], atoi (av
[3]), atoi (av
[4]));
206 j_inputbox (const char *t
, int ac
, const char * const * av
)
208 int ret
= dialog_inputbox (t
, av
[2], atoi (av
[3]), atoi (av
[4]),
209 ac
== 6 ? av
[5] : (char *) NULL
);
211 fprintf(stderr
, dialog_input_result
);
216 j_msgbox (const char *t
, int ac
, const char * const * av
)
218 return dialog_msgbox (t
, av
[2], atoi (av
[3]), atoi (av
[4]), 1);
222 j_infobox (const char *t
, int ac
, const char * const * av
)
224 return dialog_msgbox (t
, av
[2], atoi (av
[3]), atoi (av
[4]), 0);