2 * --- T2-COPYRIGHT-NOTE-BEGIN ---
3 * This copyright note is auto-generated by ./scripts/Create-CopyPatch.
5 * T2 SDE: misc/confdialog/confdialog.c
6 * Copyright (C) 2004 - 2005 The T2 SDE Project
7 * Copyright (C) 1998 - 2003 ROCK Linux Project
9 * More information can be found in the files COPYING and README.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 2 of the License. A copy of the
14 * GNU General Public License can be found in the file COPYING.
15 * --- T2-COPYRIGHT-NOTE-END ---
18 * dialog - Display simple dialog boxes from shell scripts
20 * ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
21 * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcap@cfw.com)
22 * MODIFIED FOR ROCK LINUX CONFIG BY: Clifford Wolf (clifford@clifford.at)
24 * This program is free software; you can redistribute it and/or
25 * modify it under the terms of the GNU General Public License
26 * as published by the Free Software Foundation; either version 2
27 * of the License, or (at your option) any later version.
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
34 * You should have received a copy of the GNU General Public License
35 * along with this program; if not, write to the Free Software
36 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
41 static void Usage (const char *name
);
43 typedef int (jumperFn
) (const char *title
, int argc
, const char * const * argv
);
47 int argmin
, argmax
, argmod
;
51 jumperFn j_menu
, j_checklist
, j_radiolist
, j_yesno
, j_textbox
, j_inputbox
;
52 jumperFn j_msgbox
, j_infobox
;
54 static struct Mode modes
[] =
56 {"--menu", 9, 0, 3, j_menu
},
57 {"--checklist", 9, 0, 3, j_checklist
},
58 {"--radiolist", 9, 0, 3, j_radiolist
},
59 {"--yesno", 5,5,1, j_yesno
},
60 {"--textbox", 5,5,1, j_textbox
},
61 {"--inputbox", 5, 6, 1, j_inputbox
},
62 {"--msgbox", 5, 5, 1, j_msgbox
},
63 {"--infobox", 5, 5, 1, j_infobox
},
67 static struct Mode
*modePtr
;
74 main (int argc
, const char * const * argv
)
76 int offset
= 0, clear_screen
= 0, end_common_opts
= 0, retval
;
77 const char *title
= NULL
;
80 (void) setlocale (LC_ALL
, "");
84 trace(TRACE_CALLS
|TRACE_UPDATE
);
91 while (offset
< argc
- 1 && !end_common_opts
) { /* Common options */
92 if (!strcmp (argv
[offset
+ 1], "--title")) {
93 if (argc
- offset
< 3 || title
!= NULL
) {
97 title
= argv
[offset
+ 2];
100 } else if (!strcmp (argv
[offset
+ 1], "--backtitle")) {
101 if (backtitle
!= NULL
) {
105 backtitle
= argv
[offset
+ 2];
108 } else if (!strcmp (argv
[offset
+ 1], "--clear")) {
109 if (clear_screen
) { /* Hey, "--clear" can't appear twice! */
112 } else if (argc
== 2) { /* we only want to clear the screen */
114 refresh (); /* init_dialog() will clear the screen for us */
121 } else /* no more common options */
125 if (argc
- 1 == offset
) { /* no more options */
129 /* use a table to look for the requested mode, to avoid code duplication */
131 for (modePtr
= modes
; modePtr
->name
; modePtr
++) /* look for the mode */
132 if (!strcmp (argv
[offset
+ 1], modePtr
->name
))
137 if (argc
- offset
< modePtr
->argmin
)
139 if (modePtr
->argmax
&& argc
- offset
> modePtr
->argmax
)
145 retval
= (*(modePtr
->jumper
)) (title
, argc
- offset
, argv
+ offset
);
147 if (clear_screen
) { /* clear screen before exit */
148 attr_clear (stdscr
, LINES
, COLS
, screen_attr
);
157 * Print program usage
160 Usage (const char *name
)
163 \ndialog, by Savio Lam (lam836@cs.cuhk.hk).\
164 \n patched by Stuart Herbert (S.Herbert@shef.ac.uk)\
165 \n modified/gutted for use as a Linux kernel config tool by \
166 \n William Roadcap (roadcapw@cfw.com)\
167 \n modified/gutted for use as a ROCK Linux config tool by \
168 \n Clifford Wolf (clifford@clifford.at)\
170 \n* Display dialog boxes from shell scripts *\
173 \n %s [--title <title>] [--backtitle <backtitle>] --clear <Box options>\
177 \n --menu <text> <height> <width> <menu height> <active item> <tag1> <item1>...\
178 \n --checklist <text> <height> <width> <list height> <tag1> <item1> <status1>...\
179 \n --radiolist <text> <height> <width> <list height> <tag1> <item1> <status1>...\
180 \n --textbox <file> <height> <width>\
181 \n --inputbox <text> <height> <width> [<init>]\
182 \n --yesno <text> <height> <width>\
188 * These are the program jumpers
192 j_menu (const char *t
, int ac
, const char * const * av
)
194 return dialog_menu (t
, av
[2], atoi (av
[3]), atoi (av
[4]),
195 atoi (av
[5]), av
[6], (ac
- 6) / 2, av
+ 7);
199 j_checklist (const char *t
, int ac
, const char * const * av
)
201 return dialog_checklist (t
, av
[2], atoi (av
[3]), atoi (av
[4]),
202 atoi (av
[5]), (ac
- 6) / 3, av
+ 6, FLAG_CHECK
);
206 j_radiolist (const char *t
, int ac
, const char * const * av
)
208 return dialog_checklist (t
, av
[2], atoi (av
[3]), atoi (av
[4]),
209 atoi (av
[5]), (ac
- 6) / 3, av
+ 6, FLAG_RADIO
);
213 j_textbox (const char *t
, int ac
, const char * const * av
)
215 return dialog_textbox (t
, av
[2], atoi (av
[3]), atoi (av
[4]));
219 j_yesno (const char *t
, int ac
, const char * const * av
)
221 return dialog_yesno (t
, av
[2], atoi (av
[3]), atoi (av
[4]));
225 j_inputbox (const char *t
, int ac
, const char * const * av
)
227 int ret
= dialog_inputbox (t
, av
[2], atoi (av
[3]), atoi (av
[4]),
228 ac
== 6 ? av
[5] : (char *) NULL
);
230 fprintf(stderr
, dialog_input_result
);
235 j_msgbox (const char *t
, int ac
, const char * const * av
)
237 return dialog_msgbox (t
, av
[2], atoi (av
[3]), atoi (av
[4]), 1);
241 j_infobox (const char *t
, int ac
, const char * const * av
)
243 return dialog_msgbox (t
, av
[2], atoi (av
[3]), atoi (av
[4]), 0);