2 * dialog - Display simple dialog boxes from shell scripts
4 * AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 * 17/12/93 - Version 0.1 released.
25 * 19/12/93 - menu will now scroll if there are more items than can fit
27 * - added 'checklist', a dialog box with a list of options that
28 * can be turned on or off. A list of options that are on is
31 * 20/12/93 - Version 0.15 released.
33 * 29/12/93 - Incorporated patch from Patrick J. Volkerding
34 * (volkerdi@mhd1.moorhead.msus.edu) that made these changes:
35 * - increased MAX_LEN to 2048
36 * - added 'infobox', equivalent to a message box without pausing
37 * - added option '--clear' that will clear the screen
38 * - Explicit line breaking when printing prompt text can be
39 * invoked by real newline '\n' besides the string "\n"
40 * - an optional parameter '--title <string>' can be used to
41 * specify a title string for the dialog box
43 * 03/01/94 - added 'textbox', a dialog box for displaying text from a file.
44 * - Version 0.2 released.
46 * 04/01/94 - some fixes and improvements for 'textbox':
47 * - fixed a bug that will cause a segmentation violation when a
48 * line is longer than MAX_LEN characters. Lines will now be
49 * truncated if they are longer than MAX_LEN characters.
50 * - removed wrefresh() from print_line(). This will increase
51 * efficiency of print_page() which calls print_line().
52 * - display current position in the form of percentage into file.
53 * - Version 0.21 released.
55 * 05/01/94 - some changes for faster screen update.
57 * 07/01/94 - much more flexible color settings. Can use all 16 colors
58 * (8 normal, 8 highlight) of the Linux console.
60 * 08/01/94 - added run-time configuration using configuration file.
62 * 09/01/94 - some minor bug fixes and cleanups for menubox, checklist and
65 * 11/01/94 - added a man page.
67 * 13/01/94 - some changes for easier porting to other Unix systems (tested
68 * on Ultrix, SunOS and HPUX)
69 * - Version 0.3 released.
71 * 08/06/94 - Patches by Stuart Herbert - S.Herbert@shef.ac.uk
72 * Fixed attr_clear and the textbox stuff to work with ncurses 1.8.5
73 * Fixed the wordwrap routine - it'll actually wrap properly now
74 * Added a more 3D look to everything - having your own rc file could
75 * prove 'interesting' to say the least :-)
76 * Added radiolist option
77 * - Version 0.4 released.
79 * 09/28/98 - Patches by Anatoly A. Orehovsky - tolik@mpeks.tomsk.su
80 * Added ftree and tree options
90 void Usage(unsigned char *name);
92 int main(int argc, unsigned char *argv[])
94 int offset = 0, clear_screen = 0, end_common_opts = 0, retval;
95 unsigned char *title = NULL;
96 unsigned char result[MAX_LEN];
97 char *hline = NULL, *hfile = NULL;
103 else if (!strcmp(argv[1], "--create-rc")) {
109 dialog_create_rc(argv[2]);
112 fprintf(stderr, "\nThis option is currently unsupported on your system.\n");
117 while (offset < argc-1 && !end_common_opts) { /* Common options */
118 if (!strcmp(argv[offset+1], "--title")) {
119 if (argc-offset < 3 || title != NULL) { /* No two "--title" please! */
124 title = argv[offset+2];
128 else if (!strcmp(argv[offset+1], "--hline")) {
129 if (argc-offset < 3 || hline != NULL) { /* No two "--hline" please! */
134 hline = argv[offset+2];
139 else if (!strcmp(argv[offset+1], "--hfile")) {
140 if (argc-offset < 3 || hfile != NULL) { /* No two "--hfile" please! */
145 hfile = argv[offset+2];
150 else if (!strcmp(argv[offset+1], "--clear")) {
151 if (clear_screen) { /* Hey, "--clear" can't appear twice! */
155 else if (argc == 2) { /* we only want to clear the screen */
157 dialog_update(); /* init_dialog() will clear the screen for us */
166 else /* no more common options */
170 if (argc-1 == offset) { /* no more options */
177 if (!strcmp(argv[offset+1], "--yesno")) {
178 if (argc-offset != 5) {
183 retval = dialog_yesno(title, argv[offset+2], atoi(argv[offset+3]),
184 atoi(argv[offset+4]));
187 if (clear_screen) /* clear screen before exit */
192 else if (!strcmp(argv[offset+1], "--msgbox")) {
193 if (argc-offset != 5) {
198 retval = dialog_msgbox(title, argv[offset+2], atoi(argv[offset+3]),
199 atoi(argv[offset+4]), 1);
202 if (clear_screen) /* clear screen before exit */
207 else if (!strcmp(argv[offset+1], "--prgbox")) {
208 if (argc-offset != 5) {
213 retval = dialog_prgbox(title, argv[offset+2], atoi(argv[offset+3]),
214 atoi(argv[offset+4]), TRUE, TRUE);
217 if (clear_screen) /* clear screen before exit */
220 return WEXITSTATUS(retval);
222 else if (!strcmp(argv[offset+1], "--infobox")) {
223 if (argc-offset != 5) {
228 retval = dialog_msgbox(title, argv[offset+2], atoi(argv[offset+3]),
229 atoi(argv[offset+4]), 0);
232 if (clear_screen) /* clear screen before exit */
237 else if (!strcmp(argv[offset+1], "--textbox")) {
238 if (argc-offset != 5) {
243 retval = dialog_textbox(title, argv[offset+2], atoi(argv[offset+3]),
244 atoi(argv[offset+4]));
247 if (clear_screen) /* clear screen before exit */
252 else if (!strcmp(argv[offset+1], "--menu")) {
253 if (argc-offset < 8 || ((argc-offset) % 2)) {
258 retval = dialog_menu(title, argv[offset+2], atoi(argv[offset+3]),
259 atoi(argv[offset+4]), atoi(argv[offset+5]),
260 (argc-offset-6)/2, argv+offset + 6, result,
264 fputs(result, stderr);
265 if (clear_screen) /* clear screen before exit */
270 else if (!strcmp(argv[offset+1], "--checklist")) {
271 if (argc-offset < 9 || ((argc-offset-6) % 3)) {
276 retval = dialog_checklist(title, argv[offset+2], atoi(argv[offset+3]),
277 atoi(argv[offset+4]), atoi(argv[offset+5]),
278 (argc-offset-6)/3, argv+offset + 6, result);
282 unsigned char *s, *h; int first;
286 while ((s = strchr(h, '\n')) != NULL) {
292 fprintf(stderr, "\"%s\"", h);
296 if (clear_screen) /* clear screen before exit */
301 else if (!strcmp(argv[offset+1], "--radiolist")) {
302 if (argc-offset < 9 || ((argc-offset-6) % 3)) {
307 retval = dialog_radiolist(title, argv[offset+2], atoi(argv[offset+3]),
308 atoi(argv[offset+4]), atoi(argv[offset+5]),
309 (argc-offset-6)/3, argv+offset + 6, result);
313 fputs(result, stderr);
314 if (clear_screen) /* clear screen before exit */
319 else if (!strcmp(argv[offset+1], "--inputbox")) {
320 if (argc-offset != 5 && argc-offset != 6) {
324 if (argc-offset == 6)
325 strcpy(result, argv[offset+5]);
329 retval = dialog_inputbox(title, argv[offset+2], atoi(argv[offset+3]),
330 atoi(argv[offset+4]), result);
334 fputs(result, stderr);
335 if (clear_screen) /* clear screen before exit */
340 /* ftree and tree options */
341 else if (!strcmp(argv[offset+1], "--ftree")) {
342 unsigned char *tresult;
343 if (argc-offset != 8) {
348 retval = dialog_ftree(argv[offset+2], *argv[offset+3],
349 title, argv[offset+4], atoi(argv[offset+5]), atoi(argv[offset+6]),
350 atoi(argv[offset+7]), &tresult);
355 fputs(tresult, stderr);
358 if (clear_screen) /* clear screen before exit */
363 else if (!strcmp(argv[offset+1], "--tree")) {
364 unsigned char *tresult;
365 if (argc-offset < 8) {
370 retval = dialog_tree(argv+offset+7, argc-offset-7, *argv[offset+2],
371 title, argv[offset+3], atoi(argv[offset+4]), atoi(argv[offset+5]),
372 atoi(argv[offset+6]), &tresult);
376 fputs(tresult, stderr);
378 if (clear_screen) /* clear screen before exit */
391 * Print program usage
393 void Usage(unsigned char *name)
396 \ndialog version 0.3, by Savio Lam (lam836@cs.cuhk.hk).\
397 \n patched to version %s by Stuart Herbert (S.Herbert@shef.ac.uk)\
398 \n Changes Copyright (C) 1995 by Andrey A. Chernov, Moscow, Russia\
399 \n patched by Anatoly A. Orehovsky (tolik@mpeks.tomsk.su)\
401 \n* Display dialog boxes from shell scripts *\
404 \n %s --create-rc <file>\
405 \n %s [--title <title>] [--clear] [--hline <line>] [--hfile <file>]\\\
410 \n --yesno <text> <height> <width>\
411 \n --msgbox <text> <height> <width>\
412 \n --prgbox \"<command line>\" <height> <width>\
413 \n --infobox <text> <height> <width>\
414 \n --inputbox <text> <height> <width> [<init string>]\
415 \n --textbox <file> <height> <width>\
416 \n --menu <text> <height> <width> <menu height> <tag1> <item1>...\
417 \n --checklist <text> <height> <width> <list height> <tag1> <item1> <status1>...\
418 \n --radiolist <text> <height> <width> <list height> <tag1> <item1> <status1>...\
419 \n --ftree <file> <FS> <text> <height> <width> <menu height>\
420 \n --tree <FS> <text> <height> <width> <menu height> <item1>...\n", VERSION, name, name, name);