Index: stable/2.2/gnu/lib/libdialog/Makefile =================================================================== --- stable/2.2/gnu/lib/libdialog/Makefile (revision 40695) +++ stable/2.2/gnu/lib/libdialog/Makefile (revision 40696) @@ -1,37 +1,38 @@ # Makefile for libdialog -# $Id: Makefile,v 1.18 1996/08/13 12:46:10 jkh Exp $ +# $Id: Makefile,v 1.19 1996/08/30 02:06:46 peter Exp $ LIB= dialog MAN3= dialog.3 SHLIB_MAJOR= 3 SHLIB_MINOR= 0 SRCS= kernel.c rc.c checklist.c inputbox.c menubox.c msgbox.c \ lineedit.c radiolist.c textbox.c yesno.c prgbox.c raw_popen.c \ - fselect.c ui_objects.c dir.c notify.c help.c gauge.c + fselect.c ui_objects.c dir.c notify.c help.c gauge.c tree.c CFLAGS+= -I${.CURDIR} -Wall -Wstrict-prototypes -DLOCALE LDADD+= -lncurses -lmytinfo DPADD+= ${LIBNCURSES} ${LIBMYTINFO} beforeinstall: ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 ${.CURDIR}/dialog.h \ ${DESTDIR}/usr/include MLINKS+=dialog.3 draw_shadow.3 dialog.3 draw_box.3 \ dialog.3 line_edit.3 dialog.3 strheight.3 \ dialog.3 strwidth.3 dialog.3 dialog_create_rc.3 \ dialog.3 dialog_yesno.3 dialog.3 dialog_prgbox.3 \ dialog.3 dialog_textbox.3 dialog.3 dialog_menu.3 \ dialog.3 dialog_checklist.3 dialog.3 dialog_radiolist.3 \ dialog.3 dialog_inputbox.3 dialog.3 dialog_clear_norefresh.3 \ dialog.3 dialog_clear.3 dialog.3 dialog_update.3 \ dialog.3 dialog_fselect.3 dialog.3 dialog_notify.3 \ dialog.3 dialog_mesgbox.3 dialog.3 dialog_gauge.3 \ dialog.3 init_dialog.3 dialog.3 end_dialog.3 \ dialog.3 use_helpfile.3 dialog.3 use_helpline.3 \ dialog.3 get_helpline.3 dialog.3 restore_helpline.3 \ - dialog.3 dialog_msgbox.3 + dialog.3 dialog_msgbox.3 dialog.3 dialog_ftree.3 \ + dialog.3 dialog_tree.3 .include Index: stable/2.2/gnu/lib/libdialog/dialog.3 =================================================================== --- stable/2.2/gnu/lib/libdialog/dialog.3 (revision 40695) +++ stable/2.2/gnu/lib/libdialog/dialog.3 (revision 40696) @@ -1,401 +1,465 @@ .\" .\" Copyright (c) 1995, Jordan Hubbard .\" .\" All rights reserved. .\" .\" This manual page may be used, modified, copied, distributed, and .\" sold, in both source and binary form provided that the above .\" copyright and these terms are retained, verbatim, as the first .\" lines of this file. Under no circumstances is the author .\" responsible for the proper functioning of the software described herein .\" nor does the author assume any responsibility for damages incurred with .\" its use. .\" -.\" $Id: dialog.3,v 1.3.2.1 1998/02/15 21:37:54 steve Exp $ +.\" $Id: dialog.3,v 1.3.2.2 1998/06/06 06:09:14 jkoshy Exp $ .\" -.Dd December 18, 1995 +.Dd October 2, 1998 .Dt dialog 3 .Os FreeBSD 2 .Sh NAME .Nm draw_shadow , .Nm draw_box , .Nm line_edit , .Nm strheight , .Nm strwidth , .Nm dialog_create_rc, .Nm dialog_yesno , .Nm dialog_prgbox , .Nm dialog_msgbox , .Nm dialog_textbox , .Nm dialog_menu , .Nm dialog_checklist , .Nm dialog_radiolist , .Nm dialog_inputbox , .Nm dialog_clear_norefresh , .Nm dialog_clear , .Nm dialog_update , .Nm dialog_fselect , .Nm dialog_notify , .Nm dialog_mesgbox , .Nm dialog_gauge , .Nm init_dialog , .Nm end_dialog , .Nm use_helpfile , .Nm use_helpline , .Nm get_helpline , -.Nm restore_helpline +.Nm restore_helpline , +.Nm dialog_ftree , +.Nm dialog_tree .Nd Provide a simple ncurses-based "GUI" interface. .Sh DESCRIPTION The dialog library attempts to provide a fairly simplistic set of fixed-presentation menus, input boxes, gauges, file requestors and other general purpose "GUI" (a bit of a stretch, since it uses ncurses) objects. Since the library also had its roots in a shell-script writer's utility (see the \fBdialog(1)\fR command), the early API was somewhat primitively based on strings being passed in or out and parsed. This API was later extended to take either the original arguments or arrays of \fBdialogMenuItem\fR structures, giving the user much more control over the internal behavior of each control. The \fBdialogMenuItem\fR structure internals are public: .nf typedef struct _dmenu_item { char *\fBprompt\fR; char *\fBtitle\fR; int (*\fBchecked\fR)(struct _dmenu_item *self); int (*\fBfire\fR)(struct _dmenu_item *self); int (*\fBselected\fR)(struct _dmenu_item *self, int is_selected); void *\fBdata\fR; char \fBlbra\fR, \fBmark\fR, \fBrbra\fR; } \fBdialogMenuItem\fR; .fi The \fBprompt\fR and \fBtitle\fR strings are pretty much self-explanatory, and the \fBchecked\fR and \fBfire\fR function pointers provide optional display and action hooks (the \fBdata\fR variable being available for the convenience of those hooks) when more tightly coupled feedback between a menu object and user code is required. The \fBselected\fR hook also allows you to verify whether or not a given item is selected (the cursor is over it) for implementing pretty much any possible context-sensitive behavior. A number of clever tricks for simulating various kinds of item types can also be done by adjusting the values of \fBlbra\fR (default: '['), \fB\mark\fR (default: '*' for radio menus, 'X' for check menus) and \fBrbra\fR (default: ']') and declaring a reasonable \fBchecked\fR hook, which should return TRUE for the `marked' state and FALSE for `unmarked.' If an item has a \fBfire\fR hook associated with it, it will also be called whenever the item is "toggled" in some way and should return one of the following codes: .nf #define DITEM_SUCCESS 0 /* Successful completion */ #define DITEM_FAILURE -1 /* Failed to "fire" */ #define DITEM_LEAVE_MENU -2 /* Treat selection as "Ok" */ #define DITEM_REDRAW -3 /* Menu has changed, redraw it */ Two special globals also exist for putting a dialog at any arbitrary X,Y location (the early designers rather short-sightedly made no provisions for this). If set to zero, the default centering behavior will be in effect. .fi .Sh SYNOPSIS .Fd #include .Ft "void" .Fn draw_shadow "WINDOW *win" "int y" "int x" "int height" "int width" Draws a shadow in curses window \fBwin\fR using the dimensions of \fBx, y, width\fR and \fBheight\fR. Returns 0 on success, -1 on failure. .Ft "void" .Fn draw_box "WINDOW *win" "int y" "int x" "int height" "int width" "chtype box" "chtype border" Draws a bordered box using the dimensions of \fBx, y, width\fR and \fBheight\fR. The attributes from \fBbox\fR and \fBborder\fR are used, if specified, while painting the box and border regions of the object. .Ft "int" .Fo line_edit .Fa "WINDOW *dialog" .Fa "int box_y" .Fa "int box_x" .Fa "int flen" .Fa "int box_width" .Fa "chtype attrs" .Fa "int first" .Fa "unsigned char *result" .Fa "int attr_mask" .Fc Invoke a simple line editor with an edit box of dimensions \fBbox_x, box_y\fR and \fBbox_width\fR. The field length is constrained by \fBflen\fR, starting at the \fBfirst\fR character specified and optionally displayed with character attributes \fBattrs\fR. The string being edited is stored in \fBresult\fR. Returns 0 on success, -1 on failure. .Ft "int" .Fn strheight "const char *p" Returns the height of string in \fBp\fR, counting newlines. .Ft "int" .Fn strwidth "const char *p" Returns the width of string in \fBp\fR, counting newlines. .Ft "void" .Fn dialog_create_rc "unsigned char *filename" Dump dialog library settings into \fBfilename\fR for later retrieval as defaults. Returns 0 on success, -1 on failure. .Ft "int" .Fn dialog_yesno "unsigned char *title" "unsigned char *prompt" "int height" "int width" Display a text box using \fBtitle\fR and \fBprompt\fR strings of dimensions \fBheight\fR and \fBwidth\fR. Also paint a pair of \fBYes\fR and \fBNo\fR buttons at the bottom. If the \fBYes\fR button is chosen, return FALSE. If \fBNo\fR, return TRUE. .Ft "int" .Fn dialog_prgbox "unsigned char *title" "const unsigned char *line" "int height" "int width" "int pause" "int use_shell" Display a text box of dimensions \fBheight\fR and \fBwidth\fR containing the output of command \fBline\fR. If \fBuse_shell\fR is TRUE, \fBline\fR is passed as an argument to \fBsh(1)\fR, otherwise it is simply passed to \fBexec(3)\fR. If \fBpause\fR is TRUE, a final confirmation requestor will be put up when execution terminates. Returns 0 on success, -1 on failure. .Ft "int" .Fn dialog_textbox "unsigned char *title" "unsigned char *prompt" "int height" "int width" Display a text box containing the contents of string \fBprompt\fR of dimensions \fBheight\fR and \fBwidth\fR. Returns 0 on success, -1 on failure. .Ft "int" .Fn dialog_menu "unsigned char *title" "unsigned char *prompt" "int height" "int width" "int menu_height" "int item_no" "void *itptr" "unsigned char *result, int *ch, int *sc" Display a menu of dimensions \fBheight\fR and \fBwidth\fR with an optional internal menu height of \fBmenu_height\fR. The \fBitem_no\fR and \fBitptr\fR arguments are of particular importance since they, together, determine which of the 2 available APIs to use. To use the older and traditional interface, \fBitem_no\fR should be a positive integer representing the number of string pointer pairs to find in \fBitptr\fR (which should be of type \fBchar **\fR), the strings are expected to be in prompt and title order for each item and the \fBresult\fR parameter is expected to point to an array where the prompt string of the item selected will be copied. To use the newer interface, \fBitem_no\fR should be a \fInegative\fR integer representing the number of \fBdialogMenuItem\fR structures pointed to by \fBitptr\fR (which should be of type \fBdialogMenuItem *\fR), one structure per item. In the new interface, the \fBresult\fR variable is used as a simple boolean (not a pointer) and should be NULL if \fBitptr\fR only points to menu items and the default \fBOK\fR and \fBCancel\fR buttons are desired. If \fBresult\fR is non-NULL, then \fBitptr\fR is actually expected to point 2 locations \fBpast\fR the start of the menu item list. \fBitptr\fR[-1] is then expected to point to an item representing the \fBCancel\fR button, from which the \fBprompt\fR and \fBfire\fR actions are used to override the default behavior, and \fBitptr\fR[-2] to the same for the \fBOK\fR button. Using either API behavior, the \fBch\fR and \fBsc\fR values may be passed in to preserve current item selection and scroll position values across calls. Returns 0 on success, 1 on Cancel and -1 on failure or ESC. .Ft "int" .Fn dialog_checklist "unsigned char *title" "unsigned char *prompt" "int height" "int width" "int m_height" "int item_no" "void *itptr" "unsigned char *result" Display a menu of dimensions \fBheight\fR and \fBwidth\fR with an optional internal menu height of \fBmenu_height\fR. The \fBitem_no\fR and \fBitptr\fR arguments are of particular importance since they, together, determine which of the 2 available APIs to use. To use the older and traditional interface, \fBitem_no\fR should be a positive integer representing the number of string pointer tuples to find in \fBitptr\fR (which should be of type \fBchar **\fR), the strings are expected to be in prompt, title and state ("on" or "off") order for each item and the \fBresult\fR parameter is expected to point to an array where the prompt string of the item(s) selected will be copied. To use the newer interface, \fBitem_no\fR should be a \fInegative\fR integer representing the number of \fBdialogMenuItem\fR structures pointed to by \fBitptr\fR (which should be of type \fBdialogMenuItem *\fR), one structure per item. In the new interface, the \fBresult\fR variable is used as a simple boolean (not a pointer) and should be NULL if \fBitptr\fR only points to menu items and the default \fBOK\fR and \fBCancel\fR buttons are desired. If \fBresult\fR is non-NULL, then \fBitptr\fR is actually expected to point 2 locations \fBpast\fR the start of the menu item list. \fBitptr\fR[-1] is then expected to point to an item representing the \fBCancel\fR button, from which the \fBprompt\fR and \fBfire\fR actions are used to override the default behavior, and \fBitptr\fR[-2] to the same for the \fBOK\fR button. In the standard API model, the menu supports the selection of multiple items, each of which is marked with an `X' character to denote selection. When the OK button is selected, the prompt values for all items selected are concatenated into the \fBresult\fR string. In the new API model, it is not actually necessary to preserve "checklist" semantics at all since practically everything about how each item is displayed or marked as "selected" is fully configurable. You could have a single checklist menu that actually contained a group of items with "radio" behavior, "checklist" behavior and standard menu item behavior. The only reason to call \fBdialog_checklist\fR over \fBdialog_radiolist\fR in the new API model is to inherit the base behavior, you're no longer constrained by it. Returns 0 on success, 1 on Cancel and -1 on failure or ESC. .Ft "int" .Fn dialog_radiolist "unsigned char *title" "unsigned char *prompt" "int height" "int width" "int m_height" "int item_no" "void *it" "unsigned char *result" Display a menu of dimensions \fBheight\fR and \fBwidth\fR with an optional internal menu height of \fBmenu_height\fR. The \fBitem_no\fR and \fBitptr\fR arguments are of particular importance since they, together, determine which of the 2 available APIs to use. To use the older and traditional interface, \fBitem_no\fR should be a positive integer representing the number of string pointer tuples to find in \fBitptr\fR (which should be of type \fBchar **\fR), the strings are expected to be in prompt, title and state ("on" or "off") order for each item and the \fBresult\fR parameter is expected to point to an array where the prompt string of the item(s) selected will be copied. To use the newer interface, \fBitem_no\fR should be a \fInegative\fR integer representing the number of \fBdialogMenuItem\fR structures pointed to by \fBitptr\fR (which should be of type \fBdialogMenuItem *\fR), one structure per item. In the new interface, the \fBresult\fR variable is used as a simple boolean (not a pointer) and should be NULL if \fBitptr\fR only points to menu items and the default \fBOK\fR and \fBCancel\fR buttons are desired. If \fBresult\fR is non-NULL, then \fBitptr\fR is actually expected to point 2 locations \fBpast\fR the start of the menu item list. \fBitptr\fR[-1] is then expected to point to an item representing the \fBCancel\fR button, from which the \fBprompt\fR and \fBfire\fR actions are used to override the default behavior, and \fBitptr\fR[-2] does the same for the traditional \fBOK\fR button. In the standard API model, the menu supports the selection of only one of multiple items, the currently active item marked with an `*' character to denote selection. When the OK button is selected, the prompt value for this item is copied into the \fBresult\fR string. In the new API model, it is not actually necessary to preserve "radio button" semantics at all since practically everything about how each item is displayed or marked as "selected" is fully configurable. You could have a single radio menu that actually contained a group of items with "checklist" behavior, "radio" behavior and standard menu item behavior. The only reason to call \fBdialog_radiolist\fR over \fBdialog_checklistlist\fR in the new API model is to inherit the base behavior. Returns 0 on success, 1 on Cancel and -1 on failure or ESC. .Ft "int" .Fn dialog_inputbox "unsigned char *title" "unsigned char *prompt" "int height" "int width" "unsigned char *result" Displays a single-line text input field in a box displaying \fBtitle\fR and \fBprompt\fR of dimensions \fBheight\fR and \fBwidth\fR. The field entered is stored in \fBresult\fR. Returns 0 on success, -1 on failure or ESC. .Ft "char *" .Fn dialog_fselect "char *dir" "char *fmask" Brings up a file selector dialog starting at \fBdir\fR and showing only those file names matching \fBfmask\fR. Returns filename selected or NULL. .Ft "int" .Fn dialog_dselect "char *dir" "char *fmask" Brings up a directory selector dialog starting at \fBdir\fR and showing only those directory names matching \fBfmask\fR. Returns directory name selected or NULL. .Ft "void" .Fn dialog_notify "char *msg" Bring up a generic "hey, you!" notifier dialog containing \fBmsg\fR. .Ft "int" .Fn dialog_mesgbox "unsigned char *title" "unsigned char *prompt" "int height" "int width" Like a notifier dialog, but with more control over \fBtitle\fR, \fBprompt\fR, \fBwidth\fR and \fBheight\fR. This object will also wait for user confirmation, unlike \fBdialog_notify\fR. Returns 0 on success, -1 on failure. .Ft "void" .Fn dialog_gauge "char *title" "char *prompt" "int y" "int x" "int height" "int width" "int perc" Display a horizontal bar-graph style gauge. A value of \fB100\fR for \fBperc\fR constitutes a full gauge, a value of \fB0\fR an empty one. .Ft "void" .Fn use_helpfile "char *helpfile" For any menu supporting context sensitive help, invoke the text box object on this file whenever the \fBF1\fR key is pressed. .Ft "void" .Fn use_helpline "char *helpline" Display this line of helpful text below any menu being displayed. .Ft "char *" .Fn get_helpline "void" Get the current value of the helpful text line. .Ft "void" .Fn dialog_clear_norefresh "void" Clear the screen back to the dialog background color, but don't refresh the contents just yet. .Ft "void" .Fn dialog_clear "void" Clear the screen back to the dialog background color immediately. .Ft "void" .Fn dialog_update "void" Do any pending screen refreshes now. .Ft "void" .Fn init_dialog "void" Initialize the dialog library (call this routine before any other dialog API calls). .Ft "void" .Fn end_dialog "void" Shut down the dialog library (call this if you need to get back to sanity). +.Ft "int" +.Fn dialog_ftree "unsigned char *filename" "unsigned char FS" \ +"unsigned char *title" "unsigned char *prompt" "int height" "int width" \ +"int menu_height" "unsigned char **result" + +\fBdialog_ftree\fR shows a tree described by the data from the file +\fBfilename\fR. The data in the file should look like \fBfind(1)\fR output. +For the \fBfind(1)\fR output, the field separator \fBFS\fR will be \fB\'/\'\fR. If +\fBheight\fR and \fBwidth\fR are positive numbers, they set the absolute +size of the whole \fBdialog_ftree\fR box. If \fBheight\fR and +\fBwidth\fR are negative numbers, the size of the \fBdialog_ftree\fR box +will be calculated automatically. \fBmenu_height\fR sets the height of the +tree subwindow inside the \fBdialog_ftree\fR box and must be set. +\fBtitle\fR is shown centered on the upper border of the \fBdialog_ftree\fR +box. \fBprompt\fR is shown inside the \fBdialog_ftree\fR box above the tree +subwindow and can contain \fB\'\\n\'\fR to split lines. One can navigate in +the tree by pressing \fBUP/DOWN\fR or \fB\'+\'/\'-\'\fR, \fBPG_UP/PG_DOWN\fR or +\fB\'b\'/SPACE\fR and \fBHOME/END\fR or \fB\'g\'/\'G\'\fR. A leaf of the +tree is selected by pressing \fBTAB\fR or \fBLEFT/RIGHT\fR the \fBOK\fR +button and pressing \fBENTER\fR. filename may contain data like +\fBfind(1)\fR output, as well as like the output of \fBfind(1)\fR with +\fB-d\fR option. Some of the transient paths to the leaves of the tree may +be absent. Such data is corrected when fed from filename. + +The function returns 0 and a pointer to the selected leaf (to the path to +the leaf from the root of the tree) into result, if the \fBOK\fR button was +selected. The memory allocated for the building of the tree is freed on +exiting \fBdialog_ftree\fR. The memory for the result line should be freed +later manually, if necessary. If the \fBCancel\fR button was selected, the +function returns 1. In case of exiting \fBdialog_ftree\fR on \fBESC\fR, the +function returns -1. + +.Ft "int" +.Fo dialog_tree +.Fa "unsigned char **names" +.Fa "int size" +.Fa "unsigned char FS" +.Fa "unsigned char *title" +.Fa "unsigned char *prompt" +.Fa "int height" +.Fa "int width" +.Fa "int menu_height" +.Fa "unsigned char **result" +.Fc + +\fBdialog_tree\fR displays the tree very much like \fBdialog_ftree\fR does, +with some exceptions. The source data for the building of the tree is an +array \fBnames\fR of paths to the leaves (should be similar to \fBfind(1)\fR +output) of the size \fBsize\fR. However, there is no correction of data like +in \fBdialog_ftree\fR. Thus, to display a correct tree, the array must +already contain correct data. Besides, in each session every unique use of +\fBdialog_tree\fR is kept in memory, and later, when calling +\fBdialog_tree\fR with the same \fBnames\fR, \fBsize\fR, \fBFS\fR, +\fBheight\fR, \fBwidth\fR and \fBmenu_height\fR the position of the cursor +in the tree subwindow is restored. + +The function returns the same results as \fBdialog_ftree\fR. If 0 is +returned, result will contain a pointer from the array \fBnames\fR. + .Sh SEE ALSO .Xr dialog 1 , .Xr ncurses 3 .Sh AUTHORS The primary author would appear to be Savio Lam with contributions over the years by Stuart Herbert , Marc van Kempen , -Andrey Chernov and Jordan Hubbard . +Andrey Chernov , Jordan Hubbard and +Anatoly A. Orehovsky . .Sh HISTORY These functions appeared in .Em FreeBSD-2.0 as the \fBdialog(1)\fR command and were soon split into library and command by Andrey Chernov. Marc van Kempen implemented most of the -extra controls and objects and Jordan Hubbard added the dialogMenuItem -renovations and this man page. +extra controls and objects, Jordan Hubbard added the dialogMenuItem +renovations and this man page and Anatoly A. Orehovsky implemented +dialog_ftree() and dialog_tree(). + .Sh BUGS Sure! Index: stable/2.2/gnu/lib/libdialog/dialog.h =================================================================== --- stable/2.2/gnu/lib/libdialog/dialog.h (revision 40695) +++ stable/2.2/gnu/lib/libdialog/dialog.h (revision 40696) @@ -1,161 +1,207 @@ #ifndef _DIALOG_H_INCLUDE #define _DIALOG_H_INCLUDE /* * dialog.h -- common declarations for all dialog modules * * AUTHOR: Savio Lam (lam836@cs.cuhk.hk) * * Substantial rennovation: 12/18/95, Jordan K. Hubbard * * 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. */ #define HAVE_NCURSES #ifdef HAVE_NCURSES #include #else #ifdef ultrix #include #else #include #endif #endif /* special return codes for `fire' actions */ #define DITEM_STATUS(flag) ((flag) & 0x0000FFFF) #define DITEM_SUCCESS 0 #define DITEM_FAILURE 1 /* Flags - returned in upper 16 bits of return status */ #define DITEM_LEAVE_MENU (1 << 16) #define DITEM_REDRAW (1 << 17) #define DITEM_RECREATE (1 << 18) #define DITEM_RESTORE (1 << 19) #define DITEM_CONTINUE (1 << 20) /* Attributes as used by entry fields right now */ #define DITEM_NO_ECHO 0x0001 /* negative offsets for buttons in item lists, if specified */ #define OK_BUTTON -2 #define CANCEL_BUTTON -1 /* for use in describing more exotic behaviors */ typedef struct _dmenu_item { char *prompt; char *title; int (*checked)(struct _dmenu_item *self); int (*fire)(struct _dmenu_item *self); void (*selected)(struct _dmenu_item *self, int is_selected); void *data; char lbra, mark, rbra; - int aux; + long aux; } dialogMenuItem; #define VERSION "0.4" #define MAX_LEN 2048 #ifndef TRUE #define TRUE (1) #endif #ifndef FALSE #define FALSE (0) #endif extern int DialogX, DialogY, DialogInputAttrs; /* * Attribute names */ #define screen_attr attributes[0] #define shadow_attr attributes[1] #define dialog_attr attributes[2] #define title_attr attributes[3] #define border_attr attributes[4] #define button_active_attr attributes[5] #define button_inactive_attr attributes[6] #define button_key_active_attr attributes[7] #define button_key_inactive_attr attributes[8] #define button_label_active_attr attributes[9] #define button_label_inactive_attr attributes[10] #define inputbox_attr attributes[11] #define inputbox_border_attr attributes[12] #define searchbox_attr attributes[13] #define searchbox_title_attr attributes[14] #define searchbox_border_attr attributes[15] #define position_indicator_attr attributes[16] #define menubox_attr attributes[17] #define menubox_border_attr attributes[18] #define item_attr attributes[19] #define item_selected_attr attributes[20] #define tag_attr attributes[21] #define tag_selected_attr attributes[22] #define tag_key_attr attributes[23] #define tag_key_selected_attr attributes[24] #define check_attr attributes[25] #define check_selected_attr attributes[26] #define uarrow_attr attributes[27] #define darrow_attr attributes[28] /* number of attributes */ #define ATTRIBUTE_COUNT 29 extern chtype attributes[]; #ifdef HAVE_NCURSES extern bool use_shadow; void draw_shadow(WINDOW *win, int y, int x, int height, int width); #endif void draw_box(WINDOW *win, int y, int x, int height, int width, chtype box, chtype border); int line_edit(WINDOW *dialog, int box_y, int box_x, int flen, int box_width, chtype attrs, int first, unsigned char *result, int attr_mask); int strheight(const char *p); int strwidth(const char *p); void dialog_create_rc(unsigned char *filename); int dialog_yesno(unsigned char *title, unsigned char *prompt, int height, int width); int dialog_prgbox(unsigned char *title, const unsigned char *line, int height, int width, int pause, int use_shell); int dialog_msgbox(unsigned char *title, unsigned char *prompt, int height, int width, int pause); int dialog_textbox(unsigned char *title, unsigned char *file, int height, int width); int dialog_menu(unsigned char *title, unsigned char *prompt, int height, int width, int menu_height, int item_no, void *itptr, unsigned char *result, int *ch, int *sc); int dialog_checklist(unsigned char *title, unsigned char *prompt, int height, int width, int list_height, int item_no, void *itptr, unsigned char *result); int dialog_radiolist(unsigned char *title, unsigned char *prompt, int height, int width, int list_height, int item_no, void *itptr, unsigned char *result); int dialog_inputbox(unsigned char *title, unsigned char *prompt, int height, int width, unsigned char *result); void dialog_clear_norefresh(void); void dialog_clear(void); void dialog_update(void); void init_dialog(void); void end_dialog(void); /* Additions to libdialog */ char *dialog_fselect(char *dir, char *fmask); int dialog_dselect(char *dir, char *fmask); void dialog_notify(char *msg); int dialog_mesgbox(unsigned char *title, unsigned char *prompt, int height, int width); void use_helpfile(char *helpfile); void use_helpline(char *helpline); char *get_helpline(void); void restore_helpline(char *helpline); void dialog_gauge(char *title, char *prompt, int y, int x, int height, int width, int perc); + +/* + * Display a tree menu from file + * + * filename - file with like find(1) output + * FS - fields separator + * title - title of dialog box + * prompt - prompt text into dialog box + * height - height of dialog box + * width - width of dialog box + * menu_height - height of menu box + * result - pointer to char array + * + * return values: + * -1 - ESC pressed + * 0 - Ok, result set (must be freed later) + * 1 - Cancel + */ +int dialog_ftree(unsigned char *filename, unsigned char FS, + unsigned char *title, unsigned char *prompt, + int height, int width, int menu_height, + unsigned char **result); + +/* + * Display a tree menu from array + * + * names - array with like find(1) output + * size - size of array + * FS - fields separator + * title - title of dialog box + * prompt - prompt text into dialog box + * height - height of dialog box + * width - width of dialog box + * menu_height - height of menu box + * result - pointer to char array + * + * return values: + * -1 - ESC pressed + * 0 - Ok, result set + * 1 - Cancel + */ + +int dialog_tree(unsigned char **names, int size, unsigned char FS, + unsigned char *title, unsigned char *prompt, + int height, int width, int menu_height, + unsigned char **result); #endif /* _DIALOG_H_INCLUDE */ Index: stable/2.2/gnu/lib/libdialog/dir.c =================================================================== --- stable/2.2/gnu/lib/libdialog/dir.c (revision 40695) +++ stable/2.2/gnu/lib/libdialog/dir.c (revision 40696) @@ -1,549 +1,549 @@ /**************************************************************************** * * Program: dir.c * Author: Marc van Kempen * desc: Directory routines, sorting and reading * * Copyright (c) 1995, Marc van Kempen * * All rights reserved. * * This software may be used, modified, copied, distributed, and * sold, in both source and binary form provided that the above * copyright and these terms are retained, verbatim, as the first * lines of this file. Under no circumstances is the author * responsible for the proper functioning of this software, nor does * the author assume any responsibility for damages incurred with * its use. * ****************************************************************************/ #include #include #include /* XXX for _POSIX_VERSION ifdefs */ #if !defined sgi && !defined _POSIX_VERSION #include #endif #if defined __sun__ #include #endif #if defined sgi || defined _POSIX_VERSION #include #endif #include #include #include #include #include #include "dir.h" /**************************************************************************** * * local prototypes * ****************************************************************************/ void toggle_dotfiles(void); int show_dotfiles(void); int dir_alphasort(const void *d1, const void *d2); int dir_sizesort(const void *d1, const void *d2); int dir_datesort(const void *d1, const void *d2); int dir_extsort(const void *d1, const void *d2); /**************************************************************************** * * global variables * ****************************************************************************/ /* This is user-selectable, I've set them fixed for now however */ void *_sort_func = dir_alphasort; static int _showdotfiles = TRUE; /**************************************************************************** * * Functions * ****************************************************************************/ int dir_select_nd( #if defined __linux__ const struct dirent *d #else struct dirent *d #endif ) /* * desc: allways include a directory entry , except * for the current directory and other dot-files * keep '..' however. * pre: points to a dirent * post: returns TRUE if d->d_name != "." else FALSE */ { if (strcmp(d->d_name, ".")==0 || (d->d_name[0] == '.' && strlen(d->d_name) > 1 && d->d_name[1] != '.')) { return(FALSE); } else { return(TRUE); } }/* dir_select_nd() */ int dir_select( #ifdef __linux__ const struct dirent *d #else struct dirent *d #endif ) /* * desc: allways include a directory entry , except * for the current directory * pre: points to a dirent * post: returns TRUE if d->d_name != "." else FALSE */ { if (strcmp(d->d_name, ".")==0) { /* don't include the current directory */ return(FALSE); } else { return(TRUE); } } /* dir_select() */ int dir_select_root_nd( #ifdef __linux__ const struct dirent *d #else struct dirent *d #endif ) /* * desc: allways include a directory entry , except * for the current directory and the parent directory. * Also skip any other dot-files. * pre: points to a dirent * post: returns TRUE if d->d_name[0] != "." else FALSE */ { if (d->d_name[0] == '.') { /* don't include the current directory */ return(FALSE); /* nor the parent directory */ } else { return(TRUE); } } /* dir_select_root_nd() */ int dir_select_root( #ifdef __linux__ const struct dirent *d #else struct dirent *d #endif ) /* * desc: allways include a directory entry , except * for the current directory and the parent directory * pre: points to a dirent * post: returns TRUE if d->d_name[0] != "." else FALSE */ { if (strcmp(d->d_name, ".") == 0 || strcmp(d->d_name, "..") == 0) { return(FALSE); } else { return(TRUE); } }/* dir_select_root() */ #ifdef NO_ALPHA_SORT int alphasort(const void *d1, const void *d2) /* * desc: a replacement for what should be in the library */ { return(strcmp(((struct dirent *) d1)->d_name, ((struct dirent *) d2)->d_name)); } /* alphasort() */ #endif int dir_alphasort(const void *d1, const void *d2) /* * desc: compare d1 and d2, but put directories always first * put '..' always on top * */ { DirList *f1 = ((DirList *) d1), *f2 = ((DirList *) d2); struct stat *s1 = &(f1->filestatus); struct stat *s2 = &(f2->filestatus); /* check for '..' */ if (strcmp(((DirList *) d1)->filename, "..") == 0) { return(-1); } if (strcmp(((DirList *) d2)->filename, "..") == 0) { return(1); } /* put directories first */ if ((s1->st_mode & S_IFDIR) && (s2->st_mode & S_IFDIR)) { return(strcmp(f1->filename, f2->filename)); }; if (s1->st_mode & S_IFDIR) { return(-1); } if (s2->st_mode & S_IFDIR) { return(1); } return(strcmp(f1->filename, f2->filename)); } /* dir_alphasort() */ int dir_sizesort(const void *d1, const void *d2) /* * desc: compare d1 and d2, but put directories always first * */ { DirList *f1 = ((DirList *) d1), *f2 = ((DirList *) d2); struct stat *s1 = &(f1->filestatus); struct stat *s2 = &(f2->filestatus); /* check for '..' */ if (strcmp(((DirList *) d1)->filename, "..") == 0) { return(-1); } if (strcmp(((DirList *) d2)->filename, "..") == 0) { return(1); } /* put directories first */ if ((s1->st_mode & S_IFDIR) && (s2->st_mode & S_IFDIR)) { return(s1->st_size < s2->st_size ? -1 : s1->st_size >= s2->st_size); }; if (s1->st_mode & S_IFDIR) { return(-1); } if (s2->st_mode & S_IFDIR) { return(1); } return(s1->st_size < s2->st_size ? -1 : s1->st_size >= s2->st_size); } /* dir_sizesort() */ int dir_datesort(const void *d1, const void *d2) /* * desc: compare d1 and d2 on date, but put directories always first */ { DirList *f1 = ((DirList *) d1), *f2 = ((DirList *) d2); struct stat *s1 = &(f1->filestatus); struct stat *s2 = &(f2->filestatus); /* check for '..' */ if (strcmp(((DirList *) d1)->filename, "..") == 0) { return(-1); } if (strcmp(((DirList *) d2)->filename, "..") == 0) { return(1); } /* put directories first */ if ((s1->st_mode & S_IFDIR) && (s2->st_mode & S_IFDIR)) { return(s1->st_mtime < s2->st_mtime ? -1 : s1->st_mtime >= s2->st_mtime); }; if (s1->st_mode & S_IFDIR) { return(-1); } if (s2->st_mode & S_IFDIR) { return(1); } return(s1->st_mtime < s2->st_mtime ? -1 : s1->st_mtime >= s2->st_mtime); } /* dir_datesort() */ int null_strcmp(char *s1, char *s2) /* * desc: compare strings allowing NULL pointers */ { if ((s1 == NULL) && (s2 == NULL)) { return(0); } if (s1 == NULL) { return(-1); } if (s2 == NULL) { return(1); } return(strcmp(s1, s2)); } /* null_strcmp() */ int dir_extsort(const void *d1, const void *d2) /* * desc: compare d1 and d2 on extension, but put directories always first * extension = "the characters after the last dot in the filename" * pre: d1 and d2 are pointers to DirList type records * post: see code */ { DirList *f1 = ((DirList *) d1), *f2 = ((DirList *) d2); struct stat *s1 = &(f1->filestatus); struct stat *s2 = &(f2->filestatus); char *ext1, *ext2; int extf, ret; /* check for '..' */ if (strcmp(((DirList *) d1)->filename, "..") == 0) { return(-1); } if (strcmp(((DirList *) d2)->filename, "..") == 0) { return(1); } /* find the first extension */ ext1 = f1->filename + strlen(f1->filename); extf = FALSE; while (!extf && (ext1 > f1->filename)) { extf = (*--ext1 == '.'); } if (!extf) { ext1 = NULL; } else { ext1++; } /* ext1 == NULL if there's no "extension" else ext1 points */ /* to the first character of the extension string */ /* find the second extension */ ext2 = f2->filename + strlen(f2->filename); extf = FALSE; while (!extf && (ext2 > f2->filename)) { extf = (*--ext2 == '.'); } if (!extf) { ext2 = NULL; } else { ext2++; } /* idem as for ext1 */ if ((s1->st_mode & S_IFDIR) && (s2->st_mode & S_IFDIR)) { ret = null_strcmp(ext1, ext2); if (ret == 0) { return(strcmp(f1->filename, f2->filename)); } else { return(ret); } }; if (s1->st_mode & S_IFDIR) { return(-1); } if (s2->st_mode & S_IFDIR) { return(1); } ret = null_strcmp(ext1, ext2); if (ret == 0) { return(strcmp(f1->filename, f2->filename)); } else { return(ret); } } /* dir_extsort() */ void get_dir(char *dirname, char *fmask, DirList **dir, int *n) /* * desc: get the files in the current directory * pre: == NULL * post: contains dir-entries */ { char cwd[MAXPATHLEN]; char buf[256]; struct dirent **dire; struct stat status; int i, j, nb; long d; getcwd(cwd, MAXPATHLEN); if (strcmp(cwd, "/") == 0) { /* we are in the root directory */ if (show_dotfiles()) { *n = scandir(dirname, &dire, dir_select_root, alphasort); } else { *n = scandir(dirname, &dire, dir_select_root_nd, alphasort); } } else { if (show_dotfiles()) { *n = scandir(dirname, &dire, dir_select, alphasort); } else { *n = scandir(dirname, &dire, dir_select_nd, alphasort); } } /* There is the possibility that we have entered a directory */ /* which we are not allowed to read, scandir thus returning */ /* -1 for *n. */ /* Actually I should also check for lack of memory, but I'll */ /* let my application happily crash if this is the case */ /* Solution: */ /* manually insert the parent directory as the only */ /* directory entry, and return. */ if (*n == -1) { *n = 1; *dir = (DirList *) malloc(sizeof(DirList)); strcpy((*dir)[0].filename, ".."); lstat("..", &status); (*dir)[0].filestatus = status; (*dir)[0].link = FALSE; return; } *dir = (DirList *) malloc( *n * sizeof(DirList) ); d = 0; i = 0; j = 0; while (j<*n) { lstat(dire[j]->d_name, &status); /* check if this file is to be included */ /* always include directories, the rest is subject to fmask */ if (S_ISDIR(status.st_mode) || fnmatch(fmask, dire[j]->d_name, FNM_NOESCAPE) != FNM_NOMATCH) { strcpy((*dir)[i].filename, dire[j]->d_name); (*dir)[i].filestatus = status; if ((S_IFMT & status.st_mode) == S_IFLNK) { /* handle links */ (*dir)[i].link = TRUE; stat(dire[j]->d_name, &status); - nb = readlink(dire[j]->d_name, buf, 256); + nb = readlink(dire[j]->d_name, buf, sizeof(buf) - 1); if (nb == -1) { printf("get_dir(): Error reading link: %s\n", dire[j]->d_name); exit(-1); } else { (*dir)[i].linkname = malloc(sizeof(char) * nb + 1); strncpy((*dir)[i].linkname, buf, nb); (*dir)[i].linkname[nb] = 0; } (*dir)[i].filestatus = status; } else { (*dir)[i].link = FALSE; (*dir)[i].linkname = NULL; } i++; } else { /* skip this entry */ } j++; } *n = i; /* sort the directory with the directory names on top */ qsort((*dir), *n, sizeof(DirList), _sort_func); /* Free the allocated memory */ for (i=0; i<*n; i++) { free(dire[i]); } free(dire); return; }/* get_dir() */ void FreeDir(DirList *d, int n) /* * desc: free the dirlist d * pre: d != NULL * post: memory allocated to d has been released */ { int i; if (d) { for (i=0; i