Index: stable/2.2/gnu/usr.bin/dialog/dialog.1 =================================================================== --- stable/2.2/gnu/usr.bin/dialog/dialog.1 (revision 40697) +++ stable/2.2/gnu/usr.bin/dialog/dialog.1 (revision 40698) @@ -1,239 +1,313 @@ -.TH DIALOG 1 "10 January 1994" +.TH DIALOG 1 "2 October 1998" .SH NAME dialog \- display dialog boxes from shell scripts .SH SYNOPSIS .B dialog --clear .br .BI "dialog --create-rc " file .br .B dialog [ .BI "\-\-title " title ] [ .B \-\-clear ] [ .BI "\-\-hline " line ] [ .BI "\-\-hfile " file ] .B box-options .SH DESCRIPTION .B Dialog is a program which allows you to present a variety of questions or display messages in dialog box form from a shell script. The following types of dialog objects are currently supported: .LP .BR yes/no " box," " menu" " box," " input" " box," .BR message " box," " text" " box," " info" " box," -.BR checklist " box and" " program" " box." +.BR checklist " box," " program" " box," +.BR ftree " and " tree " boxes." .SH OPTIONS .TP .B \-\-clear The screen will be cleared to the .BR "screen attribute" " on exit." .TP .BI \-\-create-rc " file" .RB "Since " dialog " supports run-time configuration," this can be used to dump a sample configuration file to the file specified by .IR file "." .TP .BI \-\-title " title" Specifies a .I title string to be displayed at the top of the dialog box. .TP .BI \-\-hline " line" Specifies a .I line string to be displayed at the bottom of the dialog box. .TP .BI \-\-hfile " file" Specifies a .I file to be displayed by pressing ? or F1. .TP .B Box Options .TP .BI \-\-yesno " text height width" .RB A " yes/no" " dialog box of size" .I height rows by .I width columns will be displayed. The string specified by .I text is displayed inside the dialog box. If this string is too long to fit in one line, it will be automatically divided into multiple lines at the appropriate points. The .I text string may also contain the sub-string .I "\en" or newline characters .I `\en\' to control line breaking explicitly. This dialog box is useful for asking questions that require the user to answer either yes or no. .RB "The dialog box has a" " Yes" " button and a " No button, in which the user can switch between by pressing the .IR TAB " key." .TP .BI \-\-msgbox " text height width" .RB A " message" " box is very similar to a" " yes/no" " box." The only difference between a .B message box and a .B yes/no box is that a .B message box has only a single .B OK button. You can use this dialog box to display any message you like. After reading the message, the user can press the .I ENTER key so that .B dialog will exit and the calling shell script can continue its operation. .TP .BI \-\-infobox " text height width" .RB An " info" " box is basically a" " message" " box." However, in this case, .B dialog will exit immediately after displaying the message to the user. The screen is not cleared when .B dialog exits, so that the message will remain on the screen until the calling shell script clears it later. This is useful when you want to inform the user that some operations are carrying on that may require some time to finish. .TP .BI \-\-inputbox " text height width" .RB "An " input " box is useful when you want to ask questions that" require the user to input a string as the answer. When inputing the string, the .I BACKSPACE key can be used to correct typing errors. If the input string is longer than can be fitted in the dialog box, the input field will be scrolled. On exit, the input string will be printed on .IR stderr "." .TP .BI \-\-textbox " file height width" .RB A " text" " box lets you display the contents of a text file in a" dialog box. It is like a simple text file viewer. The user can move through the file by using the .IR UP/DOWN ", " PGUP/PGDN .RI and " HOME/END" " keys available on most keyboards." If the lines are too long to be displayed in the box, the .I LEFT/RIGHT keys can be used to scroll the text region horizontally. For more convenience, forward and backward searching functions are also provided. .IP "\fB\-\-menu \fItext height width menu-height \fR[ \fItag item \fR] \fI..." As its name suggests, a .B menu box is a dialog box that can be used to present a list of choices in the form of a menu for the user to choose. Each menu entry consists of a .IR tag " string and an " item " string. The" .I tag gives the entry a name to distinguish it from the other entries in the menu. The .I item is a short description of the option that the entry represents. The user can move between the menu entries by pressing the .I UP/DOWN keys, the first letter of the .I tag as a hot-key, or the number keys .IR 1-9 ". There are" .I menu-height entries displayed in the menu at one time, but the menu will be scrolled if there are more entries than that. When .B dialog exits, the .I tag of the chosen menu entry will be printed on .IR stderr "." .TP .BI \-\-prgbox " command height width" .RB A " program" " box lets you display output of command in" dialog box. .IP "\fB\-\-checklist \fItext height width list-height \fR[ \fItag item status \fR] \fI..." .RB "A " checklist " box is similar to a " menu " box in that there are" multiple entries presented in the form of a menu. Instead of choosing one entry among the entries, each entry can be turned on or off by the user. The initial on/off state of each entry is specified by .IR status "." On exit, a list of the .I tag strings of those entries that are turned on will be printed on .IR stderr "." +.IP "\fB\-\-ftree \fIfile FS text height width menu-height" +.B ftree +box is a dialog box showing the tree described by the data from the file +.IR file "." +The data in the file should look like find(1) output. For the +find output, the field separator +.I FS +will be +.IR \'/\' ". If" +.IR height " and" +.IR width " are" +positive numbers, they set the absolute size of the whole +.BR ftree " box. If" +.IR height " and" +.IR width " are negative numbers, the size of the" +.B ftree +box will be +selected automatically. +.I menu-height +sets the height of the tree subwindow inside the +.B ftree +box and must be set. +.I text +is shown inside the +.B ftree +box above the tree subwindow and can contain newline characters +.I '\en\' +to split lines. One can navigate in the tree by pressing +.IR UP/DOWN " or " \'+\'/\'-\' ", " PG_UP/PG_DOWN " or " \'b\'/SPACE +.RI "and " HOME/END " or " \'g\'/\'G\' "." +A leaf of the tree is selected by pressing +.IR TAB " or " LEFT/RIGHT +the +.B OK +button and pressing +.IR ENTER "." +The selected leaf (to be more +exact, the full path to it from the root of the tree) is printed to +.IR stderr "." +If +.B Cancel +and then +.I ENTER +is pressed, nothing is printed to +.IR stderr "." +.I file +may contain data like find(1) +output, as well as like the output of find(1) with +.I -d +option. Some of the transient paths to the leaves of the tree may be +absent. Such data is corrected when fed from file. +.IP "\fB\-\-tree \fIFS text height width menu-height \fR[ \fIitem \fR] \fI..." +.B tree +box is like +.B ftree +box with some exceptions. First, the data is not +entered from a file, but from the command line as +.I item item ... +Second, the data thus entered is not corrected in any way. +Thus, the data like the output of find(1) with +.I -d +option will look incorrectly. .SH "RUN-TIME CONFIGURATION" .TP 4 1. Create a sample configuration file by typing: .LP .in +1i "dialog --create-rc " .TP 4 2. At start, .B dialog determines the settings to use as follows: .RS .TP 4 a) if environment variable .B DIALOGRC is set, its value determines the name of the configuration file. .TP 4 b) if the file in (a) can't be found, use the file .I $HOME/.dialogrc as the configuration file. .TP 4 c) if the file in (b) can't be found, use compiled in defaults. .RE .TP 4 3. Edit the sample configuration file and copy it to some place that .B dialog can find, as stated in step 2 above. .SH ENVIRONMENT .TP 15 .B DIALOGRC Define this variable if you want to specify the name of the configuration file to use. .SH FILES .TP 20 .I $HOME/.dialogrc default configuration file .SH DIAGNOSTICS Exit status is 0 if .BR dialog " is exited by pressing the " Yes " or " OK button, and 1 if the .BR No " or " Cancel button is pressed. Otherwise, if errors occur inside .B dialog or .B dialog is exited by pressing the .I ESC key, the exit status is -1. .SH SEE ALSO -.Xr dialog 3 - +dialog(3) .SH BUGS Text files containing .I tab characters may cause problems with .B text box. .I Tab characters in text files must first be expanded to spaces before being .RB "displayed by " text " box." -.TP +.sp 1 Screen update is too slow. +.sp 1 +The +.B ftree +and +.B tree +boxes do not allow the tree to be moved to the left or to +the right. Thus, if there are many levels of data, some of the leaves can be +rendered invisible. A standard display with 80 characters allows for 17 +levels to be visible. Deeper levels are invisible. However, the navigation +in the tree and selection of leaves do work. .SH AUTHOR Savio Lam (lam836@cs.cuhk.hk) +.sp 1 +Changes by Anatoly A. Orehovsky (tolik@mpeks.tomsk.su) (ftree and tree boxes) Index: stable/2.2/gnu/usr.bin/dialog/dialog.c =================================================================== --- stable/2.2/gnu/usr.bin/dialog/dialog.c (revision 40697) +++ stable/2.2/gnu/usr.bin/dialog/dialog.c (revision 40698) @@ -1,372 +1,422 @@ /* * dialog - Display simple dialog boxes from shell scripts * * AUTHOR: Savio Lam (lam836@cs.cuhk.hk) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * * HISTORY: * * 17/12/93 - Version 0.1 released. * * 19/12/93 - menu will now scroll if there are more items than can fit * on the screen. * - added 'checklist', a dialog box with a list of options that * can be turned on or off. A list of options that are on is * returned on exit. * * 20/12/93 - Version 0.15 released. * * 29/12/93 - Incorporated patch from Patrick J. Volkerding * (volkerdi@mhd1.moorhead.msus.edu) that made these changes: * - increased MAX_LEN to 2048 * - added 'infobox', equivalent to a message box without pausing * - added option '--clear' that will clear the screen * - Explicit line breaking when printing prompt text can be * invoked by real newline '\n' besides the string "\n" * - an optional parameter '--title ' can be used to * specify a title string for the dialog box * * 03/01/94 - added 'textbox', a dialog box for displaying text from a file. * - Version 0.2 released. * * 04/01/94 - some fixes and improvements for 'textbox': * - fixed a bug that will cause a segmentation violation when a * line is longer than MAX_LEN characters. Lines will now be * truncated if they are longer than MAX_LEN characters. * - removed wrefresh() from print_line(). This will increase * efficiency of print_page() which calls print_line(). * - display current position in the form of percentage into file. * - Version 0.21 released. * * 05/01/94 - some changes for faster screen update. * * 07/01/94 - much more flexible color settings. Can use all 16 colors * (8 normal, 8 highlight) of the Linux console. * * 08/01/94 - added run-time configuration using configuration file. * * 09/01/94 - some minor bug fixes and cleanups for menubox, checklist and * textbox. * * 11/01/94 - added a man page. * * 13/01/94 - some changes for easier porting to other Unix systems (tested * on Ultrix, SunOS and HPUX) * - Version 0.3 released. * * 08/06/94 - Patches by Stuart Herbert - S.Herbert@shef.ac.uk * Fixed attr_clear and the textbox stuff to work with ncurses 1.8.5 * Fixed the wordwrap routine - it'll actually wrap properly now * Added a more 3D look to everything - having your own rc file could * prove 'interesting' to say the least :-) * Added radiolist option * - Version 0.4 released. + * + * 09/28/98 - Patches by Anatoly A. Orehovsky - tolik@mpeks.tomsk.su + * Added ftree and tree options + * */ #include #include #include #include #include void Usage(unsigned char *name); int main(int argc, unsigned char *argv[]) { int offset = 0, clear_screen = 0, end_common_opts = 0, retval; unsigned char *title = NULL; unsigned char result[MAX_LEN]; char *hline = NULL, *hfile = NULL; if (argc < 2) { Usage(argv[0]); exit(-1); } else if (!strcmp(argv[1], "--create-rc")) { #ifdef HAVE_NCURSES if (argc != 3) { Usage(argv[0]); exit(-1); } dialog_create_rc(argv[2]); return 0; #else fprintf(stderr, "\nThis option is currently unsupported on your system.\n"); return -1; #endif } while (offset < argc-1 && !end_common_opts) { /* Common options */ if (!strcmp(argv[offset+1], "--title")) { if (argc-offset < 3 || title != NULL) { /* No two "--title" please! */ Usage(argv[0]); exit(-1); } else { title = argv[offset+2]; offset += 2; } } else if (!strcmp(argv[offset+1], "--hline")) { if (argc-offset < 3 || hline != NULL) { /* No two "--hline" please! */ Usage(argv[0]); exit(-1); } else { hline = argv[offset+2]; use_helpline(hline); offset += 2; } } else if (!strcmp(argv[offset+1], "--hfile")) { if (argc-offset < 3 || hfile != NULL) { /* No two "--hfile" please! */ Usage(argv[0]); exit(-1); } else { hfile = argv[offset+2]; use_helpfile(hfile); offset += 2; } } else if (!strcmp(argv[offset+1], "--clear")) { if (clear_screen) { /* Hey, "--clear" can't appear twice! */ Usage(argv[0]); exit(-1); } else if (argc == 2) { /* we only want to clear the screen */ init_dialog(); dialog_update(); /* init_dialog() will clear the screen for us */ end_dialog(); return 0; } else { clear_screen = 1; offset++; } } else /* no more common options */ end_common_opts = 1; } if (argc-1 == offset) { /* no more options */ Usage(argv[0]); exit(-1); } /* Box options */ if (!strcmp(argv[offset+1], "--yesno")) { if (argc-offset != 5) { Usage(argv[0]); exit(-1); } init_dialog(); retval = dialog_yesno(title, argv[offset+2], atoi(argv[offset+3]), atoi(argv[offset+4])); dialog_update(); if (clear_screen) /* clear screen before exit */ dialog_clear(); end_dialog(); return retval; } else if (!strcmp(argv[offset+1], "--msgbox")) { if (argc-offset != 5) { Usage(argv[0]); exit(-1); } init_dialog(); retval = dialog_msgbox(title, argv[offset+2], atoi(argv[offset+3]), atoi(argv[offset+4]), 1); dialog_update(); if (clear_screen) /* clear screen before exit */ dialog_clear(); end_dialog(); return retval; } else if (!strcmp(argv[offset+1], "--prgbox")) { if (argc-offset != 5) { Usage(argv[0]); exit(-1); } init_dialog(); retval = dialog_prgbox(title, argv[offset+2], atoi(argv[offset+3]), atoi(argv[offset+4]), TRUE, TRUE); dialog_update(); if (clear_screen) /* clear screen before exit */ dialog_clear(); end_dialog(); return WEXITSTATUS(retval); } else if (!strcmp(argv[offset+1], "--infobox")) { if (argc-offset != 5) { Usage(argv[0]); exit(-1); } init_dialog(); retval = dialog_msgbox(title, argv[offset+2], atoi(argv[offset+3]), atoi(argv[offset+4]), 0); dialog_update(); if (clear_screen) /* clear screen before exit */ dialog_clear(); end_dialog(); return retval; } else if (!strcmp(argv[offset+1], "--textbox")) { if (argc-offset != 5) { Usage(argv[0]); exit(-1); } init_dialog(); retval = dialog_textbox(title, argv[offset+2], atoi(argv[offset+3]), atoi(argv[offset+4])); dialog_update(); if (clear_screen) /* clear screen before exit */ dialog_clear(); end_dialog(); return retval; } else if (!strcmp(argv[offset+1], "--menu")) { if (argc-offset < 8 || ((argc-offset) % 2)) { Usage(argv[0]); exit(-1); } init_dialog(); retval = dialog_menu(title, argv[offset+2], atoi(argv[offset+3]), atoi(argv[offset+4]), atoi(argv[offset+5]), (argc-offset-6)/2, argv+offset + 6, result, NULL, NULL); dialog_update(); if (retval == 0) fputs(result, stderr); if (clear_screen) /* clear screen before exit */ dialog_clear(); end_dialog(); return retval; } else if (!strcmp(argv[offset+1], "--checklist")) { if (argc-offset < 9 || ((argc-offset-6) % 3)) { Usage(argv[0]); exit(-1); } init_dialog(); retval = dialog_checklist(title, argv[offset+2], atoi(argv[offset+3]), atoi(argv[offset+4]), atoi(argv[offset+5]), (argc-offset-6)/3, argv+offset + 6, result); dialog_update(); if (retval == 0) { unsigned char *s, *h; int first; h = result; first = 1; while ((s = strchr(h, '\n')) != NULL) { *s++ = '\0'; if (!first) fputc(' ', stderr); else first = 0; fprintf(stderr, "\"%s\"", h); h = s; } } if (clear_screen) /* clear screen before exit */ dialog_clear(); end_dialog(); return retval; } else if (!strcmp(argv[offset+1], "--radiolist")) { if (argc-offset < 9 || ((argc-offset-6) % 3)) { Usage(argv[0]); exit(-1); } init_dialog(); retval = dialog_radiolist(title, argv[offset+2], atoi(argv[offset+3]), atoi(argv[offset+4]), atoi(argv[offset+5]), (argc-offset-6)/3, argv+offset + 6, result); dialog_update(); if (retval == 0) fputs(result, stderr); if (clear_screen) /* clear screen before exit */ dialog_clear(); end_dialog(); return retval; } else if (!strcmp(argv[offset+1], "--inputbox")) { if (argc-offset != 5 && argc-offset != 6) { Usage(argv[0]); exit(-1); } if (argc-offset == 6) strcpy(result, argv[offset+5]); else *result = '\0'; init_dialog(); retval = dialog_inputbox(title, argv[offset+2], atoi(argv[offset+3]), atoi(argv[offset+4]), result); dialog_update(); if (retval == 0) fputs(result, stderr); if (clear_screen) /* clear screen before exit */ dialog_clear(); end_dialog(); return retval; } +/* ftree and tree options */ + else if (!strcmp(argv[offset+1], "--ftree")) { + unsigned char *tresult; + if (argc-offset != 8) { + Usage(argv[0]); + exit(-1); + } + init_dialog(); + retval = dialog_ftree(argv[offset+2], *argv[offset+3], + title, argv[offset+4], atoi(argv[offset+5]), atoi(argv[offset+6]), + atoi(argv[offset+7]), &tresult); + dialog_update(); + if (!retval) + { + fputs(tresult, stderr); + free(tresult); + } + if (clear_screen) /* clear screen before exit */ + dialog_clear(); + end_dialog(); + return retval; + } + else if (!strcmp(argv[offset+1], "--tree")) { + unsigned char *tresult; + if (argc-offset < 8) { + Usage(argv[0]); + exit(-1); + } + init_dialog(); + retval = dialog_tree(argv+offset+7, argc-offset-7, *argv[offset+2], + title, argv[offset+3], atoi(argv[offset+4]), atoi(argv[offset+5]), + atoi(argv[offset+6]), &tresult); + + dialog_update(); + if (!retval) + fputs(tresult, stderr); + + if (clear_screen) /* clear screen before exit */ + dialog_clear(); + end_dialog(); + return retval; + } + Usage(argv[0]); exit(-1); } /* End of main() */ /* * Print program usage */ void Usage(unsigned char *name) { fprintf(stderr, "\ \ndialog version 0.3, by Savio Lam (lam836@cs.cuhk.hk).\ \n patched to version %s by Stuart Herbert (S.Herbert@shef.ac.uk)\ \n Changes Copyright (C) 1995 by Andrey A. Chernov, Moscow, Russia\ +\n patched by Anatoly A. Orehovsky (tolik@mpeks.tomsk.su)\ \n\ \n* Display dialog boxes from shell scripts *\ \n\ \nUsage: %s --clear\ \n %s --create-rc \ \n %s [--title ] [--clear] [--hline <line>] [--hfile <file>]\\\ \n <Box options>\ \n\ \nBox options:\ \n\ \n --yesno <text> <height> <width>\ \n --msgbox <text> <height> <width>\ \n --prgbox \"<command line>\" <height> <width>\ \n --infobox <text> <height> <width>\ \n --inputbox <text> <height> <width> [<init string>]\ \n --textbox <file> <height> <width>\ \n --menu <text> <height> <width> <menu height> <tag1> <item1>...\ \n --checklist <text> <height> <width> <list height> <tag1> <item1> <status1>...\ -\n --radiolist <text> <height> <width> <list height> <tag1> <item1> <status1>...\n", VERSION, name, name, name); +\n --radiolist <text> <height> <width> <list height> <tag1> <item1> <status1>...\ +\n --ftree <file> <FS> <text> <height> <width> <menu height>\ +\n --tree <FS> <text> <height> <width> <menu height> <item1>...\n", VERSION, name, name, name); } /* End of Usage() */