menu(1) part 12 of 14

Paul J. Condie pjc at pcbox.UUCP
Thu Dec 27 07:15:41 AEST 1990


#!/bin/sh
# this is part 12 of a multipart archive
# do not concatenate these parts, unpack them in order with /bin/sh
# file utilities.d/libgeti.d/GetInput.3X continued
#
CurArch=12
if test ! -r s2_seq_.tmp
then echo "Please unpack part 1 first!"
     exit 1; fi
( read Scheck
  if test "$Scheck" != $CurArch
  then echo "Please unpack part $Scheck next!"
       exit 1;
  else exit 0; fi
) < s2_seq_.tmp || exit 1
echo "x - Continuing file utilities.d/libgeti.d/GetInput.3X"
sed 's/^X//' << 'SHAR_EOF' >> utilities.d/libgeti.d/GetInput.3X
X				This is validated against the file /usr/lib/acct/holidays by default.  Modify GetInput.h to change default.
X	GT_Today		- date must be greater than todays date.
X	GE_Today		- greater than or equal to todays date.
X	LT_Today		- less than todays date.
X	LE_Today		- less than or equal to todays date.
X.fi
X.TP
XTIME
XA time field.
X.br
XValid mask characters:
X.nf
X	HH	hours  (01-12)
X	MM	minutes  (00-59)
X	SS	seconds  (00-59)
X	TT	tenths  (00-99)
X	II	military hours  (00-24)
X.fi
XSome examples:
X.nf
X	HH:MM
X	HH:MM:SS
X	HH:MM:SS:TT
X	II:MM
X	II:MM:SS
X	II:MM:SS:TT
X.fi
X.TP
XSET
XThis field type specifies a set of values that are acceptable in the input 
Xfield.
XThe acceptable values within the set are specified in the \fIFldRange\fP 
Xargument.  
XThe user selects one of the set values specified in the field range by
Xpressing the space bar, which will toggle through the set values,
Xor by pressing the first character in the desired value.
X
XThe format of the FldRange can only be comma separated values 
X(ex. "CA,ID,TX").  
XRange values, such as "1-5", don't work.  You would have to say "1,2,3,4,5".
X.br
XThe FldLength is automatically set to the longest set value in the FldRange.
X.TP
XMENU
XThis field type is similar to the SET type.  The difference is when the user
Xattempts to type something in the field a pop-up menu of available choices
Xare displyed, as specified in field_range.  
XThe user makes a selection by hi-lighting the choice and pressing return.
X.br
XSee SET type for specifying the FldRange.
XThe limit is ten items in the FldRange.
X.TP
XPROTECT
XThis X's out the field so what is typed on the keyboard can not be seen on
Xthe screen.  Useful for password entry.
X.RE
X. \ ---------------------------------
X.TP
XFldAdjust
XIndicates whether to adjust the text right or left within the field
Xand whether or not to zero or blank fill the field.
X.RS 6
X.TP 15
XNOFILL
Xno action.
X.TP
XRTADJ_ZFILL
Xright adjust, zero fill
X.TP
XRTADJ_BFILL
Xright adjust, blank fill
X.TP
XLFADJ_ZFILL
Xleft adjust, zero fill
X.TP
XLFADJ_BFILL
Xleft adjust, blank fill
X.RE
X. \ ---------------------------------
X.TP 6
XFldType
XThis argument describes the memory variable that is to hold
Xthe input data.  The address that you loaded into "&Fld".
X.RS 6
X.TP 10
XCHAR
Xcharacter field
X.TP
XINT
Xinteger
X.TP
XSHORT
Xshort integer
X.TP
XLONG
Xlong integer
X.TP
XDOUBLE
Xdouble
X.TP
XFLOAT
Xfloating point
X.TP
XMONEY
Xdouble which accepts only two decimal positions.
X.RE
X. \ ---------------------------------
X.TP 11
XFldExit
X.RS 6
X.TP 10
XAUTONEXT
XGetInput() will exit, with the value of KEY_RETURN, when the last character 
Xin the field is keyed in.
X.TP
XNOAUTO
XWill not exit field until a accept key (see defining keyboard keys) is pressed.
X.RE
X. \ ---------------------------------
X.TP
XMustEnter
X.RS 6
X.TP 12
XMUSTENTER
XThis is a must enter field and the value of FldMin must be
Xentered before exiting field.
X.TP
XNOMUST
XNot a must enter field.
X.RE
X. \ ---------------------------------
X.RE
X.TP 6
XErrRow
XIndicates what row/column to display an error message if one occurs.
XThe row specified is for stdscr.
XIf a optional column is to be specified on where to start the message, the
Xformat would be for example 2302 where 23 is the row and 02 is the column.
XOtherwise, a default of column zero is used.
XGetInput will do a clrtoeol() before displaying the error message, therefore,
Xthe entire row must be given over to GetInput.
XIf this row is outside the boundary of the window unpredictable results will
Xoccur, for example, winch() will return garbage.
X.TP
XMsgRow
XIndicates what row to display help messages.
XThe row specified is for stdscr.
XIf a optional column is to be specified on where to start the message, the
Xformat would be for example 2202 where 22 is the row and 02 is the column.
XOtherwise, a default of column zero is used.
XGetInput will do a clrtoeol() before displaying the message, therefore,
Xthe entire row must be given over to GetInput.
XIf this row is outside the boundary of the window unpredictable results will
Xoccur, for example, winch() will return garbage.
X.RS 6
X.TP 10
XNULL
XNo active message line.  Only if PromptMsg == NOMSG.
X.RE
X.TP
X*PromptMsg
XPrompt message to be displayed.  The prompt message is always displayed
Xto stdscr, regardless of the win specified.
X.RS 6
X.TP 10
XNOMSG
XNo message to be displayed.
X.RE
X.TP
XHelpFile
XFile name containing on-line help messages.  Current directory
Xis searched first for helpfile and then getenv("HELPDIR") directory is
Xsearched.
X.RS 6
X.TP 10
XNOHELP
XNo help file is available for this field.
X
X.PP
XThe default helpfile (GetInput.hlp) is shown below.  Where this file is
Xinstalled will vary from machine to machine.
X
X.nf
X\fBGETINPUT\fP
X .TITLE GETINPUT Help
XMover Keys:
X        KEY_RETURN  (^m)    Traverse forwards through the fields.
X        KEY_DOWN  (^j)      Traverse forwards through the fields.
X        KEY_UP  (^k)        Traverse backwards through the fields.
X        KEY_TAB  (^i)       Fast forward through the fields.
X        KEY_BTAB            Fast reverse through the fields.
XField Editing Keys:
X        KEY_BEG  (^b)       Place cursor at beginning of field.
X        KEY_END  (^e)       Place cursor at end of input in field.
X        KEY_RIGHT  (^l)     Forward space within the field.
X        KEY_LEFT  (^h)      Backspace within the field (non-destructive).
X        KEY_BACKSPACE  (^h) Same as KEY_LEFT.
X        KEY_EOL  (^d)       Delete from cursor to end of field.
X        KEY_DL  (^c)        Clear field and home cursor.
X        KEY_DC  (^x)        Delete a character.
X        KEY_IC  (^t)        Toggle between type-over and insert mode.
XOther Keys:
X        KEY_HELP  (?)       Display help screen.
X        KEY_REFRESH  (^r)   Redraw the screen.
X        KEY_ACCEPT  (^a)    Accept all input and exit screen.
X        KEY_CANCEL  (esc)   Cancel all input and exit screen.
X        KEY_SAVE  (^f)      Save screen to a file.
X        KEY_PRINT  (^p)     Print screen to lp.
X\fBGETINPUT\fP
X
X
X
X\fBpopmenu\fP
X.TITLE Pop-Up Menu Help
XSELECTING OPTIONS:
X    To select an option press the "up arrow key",
X    "k", "down arrow key", "j" to place bar on
X    option and press "return".
X
X    KEY_CANCEL (esc)   - Cancel selection.
X\fBpopmenu\fP
X
X
X
X\fBhelp\fP
X.TITLE Using Help
XHelp displays consist of a description displayed in a window.
XIf the description doesn't fit in the window, the Up Arrow and
XDown Arrow keys can be used to view a few more lines of the 
Xdisplay.  Exiting the help system will return the display to 
Xthe state it was in when you asked for help.
X
X   The following keys are active in help:
X        KEY_CANCEL  (esc)   Exit help.
X        KEY_DOWN  (^j)      View a few more lines.
X        KEY_UP  (^k)        View the previous lines.
X        KEY_BEG  (^b)       Display first page.
X        KEY_END  (^e)       Display last page.
X        KEY_TOC  (^t)       Display table of contents.
X\fBhelp\fP
X.fi
X.RE
X.TP
XHelpTag
XTag in help file where messages are to be found.  The tag 
Xsurrounds the help message.  For example:
X.nf
X
Xhelptag
X[ .TITLE  Title line goes here. ]
XI put any help message for the user between the tags.  
XIt can be any length as it will be displayed one screen 
Xat a time.
XThe following screen attributes may be used:
X\\S  =  Standout
X\\B  =  Bold
X\\U  =  Underline
X\\D  =  Dim
X\\R  =  Reverse video
X\\L  =  Blink
X\\N  =  Normal (reset)
X
X\\BThis text is in bold face.  \\NBack in normal mode.
Xhelptag
X
XThe \fITABLE_OF_CONTENTS\fP tagname is a special tag describing what
Xis to be contained in the table of contents menu.  The following is the
Xsyntax for this tagname.
XTABLE_OF_CONTENTS
Xhelpfile   tagname   description
XTABLE_OF_CONTENTS
X.fi
X.RS 6
X.TP 10
XNOTAG
XNo tag.  Should only be used if (HelpFile == NOHELP).
X.RE
X.SH EXAMPLE
X.nf
X#include <curses.h>
X#include "GetInput.h"
X
Xmain ()
X{
X	union FldUnion Fld;
X	char	name[20], tempstring[50];
X	int	exitcode;
X
X   initscr ();
X   cbreak ();
X   noecho ();
X   nonl ();
X   keypad (stdscr, TRUE);
X
X   name[0] = '\\0';
X   Fld.strVal = name;
X   exitcode = GetInput (stdscr, 2, 0, &Fld, A_REVERSE, NOMASK, 
X                  NORANGE, 20, 0, UPPER_AN, NOFILL, CHAR, 
X                  NOAUTO, MUSTENTER, 21, 20, 
X                  "Please enter your name.", NOHELP, NOTAG);
X
X   Fld.strVal = tempstring;
X   exitcode = GetInput (stdscr, 4, 0, &Fld, A_BOLD, "HH:MM:SS:TT",
X                  NORANGE, 6, 6, TIME, NOFILL, CHAR, AUTONEXT, 
X                  NOMUST, 20, 21, "Time Field HH:MM:SS:TT", 
X                  "myhelpfile", "field2");
X
X   Fld.strVal = tempstring;
X   exitcode = GetInput (stdscr, 8, 0, &Fld, A_NORMAL, 
X                  "(999) 999-9999", NORANGE, 10, 5, NUMERIC, 
X                  RTADJ_ZFILL, CHAR, NOAUTO, MUSTENTER, 20, NULL, 
X                  NOMSG, NOHELP, NOTAG);
X
X   Fld.strVal = tempstring;
X   exitcode = GetInput (stdscr, 9, 1, &Fld, A_REVERSE, NOMASK,
X                  "CA, NV, ID", 2, 2, SET, NOFILL, CHAR, NOAUTO,
X                  NOMUST, 20, 20, "Select your state.", NOHELP, 
X                  NOTAG);
X   endwin ();
X}
X.fi
X.SH AUTHOR
XIrving Griesman  (original author)
X.br
XEnhanced & Maintained by Paul J. Condie
X.br
X{ihnp4,lll-crg,qantel,pyramid}!ptsfa!pbody!pcbox!pjc
X
X.SH FILES
XGetInput.hlp	- default GetInput help file.
X
X.SH DIAGNOSTICS
XGetInput returns the the decimal value of the key pressed from the getch()
Xfunction.  If the key pressed has an associated curses key GetInput returns
Xthe value of the curses key.  See Defining keyboard keys.
X
X.SH SEE ALSO
Xmenu(1), curses(3X), popmenu(3).
X
X.SH WARNING
XPutting a field on the same row as your message row or error row may cause
Xunpredictable results.  This is not recommended.
X
X.SH BUGS
XThere is a bug in curses when you call getch() which this routine does.
XWhen in keypad() mode and an ESC character is read, curses 
Xdoes a timed read (1 second) waiting for other characters to appear.  if
Xsome other characters are received within the one second time interval,
Xcurses attempts to match the received string with a caps string defined for the terminal (i.e. ESC[A, ESC[B are arrow keys for a vt100 type terminal)
Xand then returns a #defined int value which can be tested for easily.
XIn some cases untrapped alarm calls occur.  The solution is to trap (ignore)
Xalarm calls.
X.PP
XOn a mustenter field with a fldmin specified a control key (i.e. KEY_DOWN, etc.)
Xwill exit the
Xfield if that is the first key the user presses.  Once the user has tried
Xto input a value in the field even if he clears the field the control key
Xwill not exit until fldmin is inputed.
X
X.nf
XThe following example does not turn the reverse video off when you leave the field on the sun.
Xrc = GetInput (stdscr, 0, 1, &Fld, A_REVERSE, "VVVVVV.VVVVV.VV.VV.V", 
X	NORANGE, 16, 6, UPPER_AN, NOFILL, CHAR, NOAUTO, MUSTENTER, 
X	ERRROW, MSGROW, "Please enter niu location.", "cfgsrn.hlp", NOTAG);
X.fi
X
X.PP
XA core dump of (DisPrmpt at line 37) indicates the string was not null terminated.
SHAR_EOF
echo "File utilities.d/libgeti.d/GetInput.3X is complete"
chmod 0644 utilities.d/libgeti.d/GetInput.3X || echo "restore of utilities.d/libgeti.d/GetInput.3X fails"
echo "x - extracting utilities.d/libgeti.d/RingMenu.3 (Text)"
sed 's/^X//' << 'SHAR_EOF' > utilities.d/libgeti.d/RingMenu.3 &&
X. \ @(#)RingMenu.3	1.1 DeltaDate 1/22/90 ExtrDate 1/22/90 
X.po 6
X.TH RINGMENU 3L
X.SH NAME
XRingMenu \- Produce a Ring Menu.
X
X.SH SYNOPSIS
X.B "int RingMenu ( win, line, optNum, title, optTable )"
X.B "WINDOW *win ;"
X.B "unsigned short line, optNum ;"
X.B "char *title, *optTable[][2] ;"
X
X.SH DESCRIPTION
XRingMenu accepts a two dimensional pointers arrary, optTable, as specification to display a ring 
Xmenu.  OptTable[][0] is the option name, while optTable[][1] is the description for the option.  The 
Xlast pair of entry in OpTable must be NULL to signify the end of the menu.  The optNumth option is 
Xhighlighted, or the first item will be highlighted if optNum is 0.  The ring menu will be displayed on 
Xwindow win on line number line.  Description for option is displayed on the line+1 line.  An option-
Xal title may be displayed to the left of the ring menu or NULL may be passed if no title is desired..
X
XUser may use the arrow keys, or the equivalent control keys to move the highlighted option, and then 
Xhit the RETURN key to select the desired option.  Or a capital letter match may also select a particu-
Xlar option, there is no need to hit RETURN in this case.
X
XRingMenu accepts at most 20 options.
X
X.SH AUTHOR
XSam S. Lok
X
X.SH RETURN VALUES
XThe position number of the selected option.  The first option being 1.
X
X.SH DIAGNOSTICS
XNone.
X
X.SH EXAMPLES
X	short	option = 1 ;
X
X	static	char	*emp_menu[][2] = {	/* The menu */
X		{ "Query",	"Query existing employee" },
X		{ "Add",	"Add new employee" },
X		{ "Change",	"Update existing employee" },
X		{ "Delete",	"Delete existing employee" },
X		{ "Print",	"Screen dump to printer" },
X		{ "Exit",	"Return to menu" },
X		{ NULL,	NULL } 
X	} ;
X
X	option = RingMenu( stdscr, ERRLINE, option, "Employee:", emp_menu ) ;
X
X.SH FILES
XNone.
X
X.SH SEE ALSO
Xmenu(1L), popmenu(3L), GetInput(3L).
X
X.SH WARNINGS
XRingMenu ignores options more than 20.
XRingMenu.c makes uses of GetInput(3L)'s GetInput.h, keys.h, ShowHelp() and ScrnPrnt(), other-
Xwise, it is very much self contained.
SHAR_EOF
chmod 0444 utilities.d/libgeti.d/RingMenu.3 || echo "restore of utilities.d/libgeti.d/RingMenu.3 fails"
echo "x - extracting utilities.d/libgeti.d/ShowHelp.3 (Text)"
sed 's/^X//' << 'SHAR_EOF' > utilities.d/libgeti.d/ShowHelp.3 &&
X. \ %W% DeltaDate %G% ExtrDate %H% 
X.po 6
X.TH SHOWHELP 3 "libgeti"
X
X.SH NAME
XShowHelp \- creates and displays a help window using curses
X
X.SH SYNOPSIS
X.B "void  ShowHelp (help_file_name, tag, error_row)
X.br
X.B "char	help_file_name[];"
X.br
X.B "char	tag[];"
X.br
X.B "int	error_row;"
X
X.SH \s9DESCRIPTION\s0
X.B ShowHelp
Xsearches the \fIhelp_file_name\fP for the specified \fItag\fP, creates and
Xcenters a curses window on the screen.  Then displays the content of the tag
Xin the window.  The size of the help window is automatically adjusted to the 
Xsize of message to be displayed.
X
X.SS ARGUMENTS
X.TP 6
Xhelp_file_name
XThe unix file name containing the help message to be displayed.
X.TP 6
Xtag
XThe tag in the help file that contains the help message to be displayed.
X.TP 6
Xerror_row
XThe row on the screen (stdscr) to display any error messages.
X
X.SH HELP FILE SYNTAX
XA help file may consist of multiple help tags.  Any text found outside a helptag
Xis ignored.  See the following example.
X
X.nf
X\fBhelptag\fP
X[ .TITLE  A optional Title line goes here. ]
XI put any help message for the user between the tags.  
XIt can be any length as it will be displayed one screen 
Xat a time.
XThe following screen attributes may be used:
X\\S  =  Standout
X\\B  =  Bold
X\\U  =  Underline
X\\D  =  Dim
X\\R  =  Reverse video
X\\L  =  Blink
X\\N  =  Normal (reset)
X
X\\BThis text is in bold face.  \\NBack in normal mode.
X\fBhelptag\fP
X
X
XThe \fITABLE_OF_CONTENTS\fP tagname is a special tag describing what
Xis to be contained in the table of contents menu.  The following is the
Xsyntax for this tagname.
XTABLE_OF_CONTENTS
Xhelpfile   tagname   description
XTABLE_OF_CONTENTS
X
X
X\fBhelp\fP
X .TITLE Using Help
XHelp displays consist of a description displayed in a window.
XIf the description doesn't fit in the window, the Up Arrow and
XDown Arrow keys can be used to view a few more lines of the 
Xdisplay.  Exiting the help system will return the display to 
Xthe state it was in when you asked for help.
X
X   The following keys are active in help:
X        KEY_CANCEL  (esc)   Exit help.
X        KEY_DOWN  (^j)      View a few more lines.
X        KEY_UP  (^k)        View the previous lines.
X        KEY_BEG  (^b)       Display first page.
X        KEY_END  (^e)       Display last page.
X        KEY_TOC  (^t)       Display table of contents.
X\fBhelp\fP
X.fi
X
X.SH AUTHOR
XPaul J. Condie         2/89
X.br
X{ihnp4,lll-crg,qantel,pyramid}!ptsfa!pbody!pcbox!pjc
X
X.SH SEE ALSO
Xcurses(3X).
SHAR_EOF
chmod 0644 utilities.d/libgeti.d/ShowHelp.3 || echo "restore of utilities.d/libgeti.d/ShowHelp.3 fails"
echo "x - extracting utilities.d/libgeti.d/drawbox.3 (Text)"
sed 's/^X//' << 'SHAR_EOF' > utilities.d/libgeti.d/drawbox.3 &&
X. \ @(#)drawbox.3	1.2 DeltaDate 1/22/90 ExtrDate 1/22/90 
X.po 6
X.TH DRAWBOX 3 "libgeti"
X
X.SH NAME
Xdrawbox \- draws a box in a curses window
X
X.SH SYNOPSIS
X.B #define	DumbLine	1
X.br
X.B #define	StandoutLine	2
X.br
X.B #define	SingleLine	3	/* alternate character line */
X.br
X.B #define	MosaicLine	4	/* alternate character line */
X.br
X.B #define	DiamondLine	5	/* alternate character line */
X.br
X.B #define	DotLine		6	/* alternate character line */
X.br
X.B #define	PlusLine	7	/* alternate character line */
X
Xextern int	KeyHelp;
X
X.B "void  drawbox (win, from_row, from_col, to_row, to_col, trythis, trythat, vscroll, help\fI, percent\fP)"
X.br
X.B "WINDOW	*win;"
X.br
X.B "int	from_row;"
X.br
X.B "int	from_col;"
X.br
X.B "int	to_row;"
X.br
X.B "int	to_col;"
X.br
X.B "int	trythis;"
X.br
X.B "int	trythat;"
X.br
X.B "int	vscroll;"
X.br
X.B "int	help;"
X.br
X.B "\fIfloat	percent;\fP"
X
X.SH DESCRIPTION
X.B Drawbox
Xdraws a box within a curses window.  This is similar to the box(3X) function
Xin curses, but provides more flexibility in where to draw the box and what
Xthe box should look like.
X
X.SS ARGUMENTS
X.TP 6
Xwin
XThe curses window to draw the box in.
X.TP 6
Xfrom_row, from_col, to_row, to_col
XDimensions of the box.  Upper left corner and lower right corner of the box.
XTo draw a box around the whole window (like box(3) does) 
Xtry: \fI1,1, LINES,COLS\fP as the box dimensions.
X.TP 6
Xtrythis
XWhat line type to try first.  Any one of the #defines shown above.  
XIf the terminal
Xdoes not support alternate character lines then drawbox will \fItrythat\fP line.
X.TP 6
Xtrythat
XWhat line to use if trythis doesn't work.  This should not be a
Xalternate character line.
X.TP 6
Xvscroll
XIf TRUE vertical scroll bars will be drawn in the right side of the box.
X.TP 6
Xhelp
XIf TRUE the help key (KeyHelp) will be displayed in the lower right corner 
Xof the box to indicate help is available.
X.TP 6
Xpercent
XAn optional decimal value between 0.0 and 1.0 to indicate the position of the
Xvertical scroll bars in the right side of the box.  Any other value or an
Xundefined value will put the scoll bar at the bottom.
X
X.SH AUTHOR
XPaul J. Condie         7/87
X.br
X{ihnp4,lll-crg,qantel,pyramid}!ptsfa!pbody!pcbox!pjc
X
X.SH EXAMPLE
X.nf
X#include	<curses.h>
X
X
Xmain ()
X{
X	drawbox (stdscr, 1,1, LINES,COLS, SingleLine, StandoutLine, TRUE, TRUE, 0.5);
X}
X.fi
X
X.SH SEE ALSO
Xcurses(3X).
SHAR_EOF
chmod 0644 utilities.d/libgeti.d/drawbox.3 || echo "restore of utilities.d/libgeti.d/drawbox.3 fails"
echo "x - extracting utilities.d/libgeti.d/popmenu.3 (Text)"
sed 's/^X//' << 'SHAR_EOF' > utilities.d/libgeti.d/popmenu.3 &&
X.po 6
X.TH POPMENU 3 "libgeti"
X
X.SH NAME
Xpopmenu \- runs a popup type menu
X
X.SH SYNOPSIS
X.B #define	NEWMENU		0
X.br
X.B #define	CREATEMENU	-2
X.br
X.B #define	DIMWINDOW	-1
X.br
X.br
X.B extern int	KeyHelp;
X.br
X.B extern int	KeyCancel;
X.br
X.B extern int	KeyUp;
X.br
X.B extern int	KeyDown;
X.br
X
X.B "int  popmenu (menu_id, searchStr)"
X.br
X.B "int		menu_id;"
X.br
X.B "char	*searchStr;"
X
X.SH \s9DESCRIPTION\s0
X.B Popmenu
Xis a generic curses popup menu program.  The synopsis of popmenu will vary
Xdepending on whether you are initializing a new menu or running
Xa previously defined menu.  The above synopsis will run menu (menu_id)
Xthat you have previously defined.
X.PP
XAn optional search string,\fI*searchStr\fP, is needed as the 
Xsecond parameter in order for \fIpopmenu\fP to perform initial start-up
Xsearch.  If (char *)NULL is passed, no start-up search will be done
Xand the first or last selected option will be the default option.
X.PP
XPopmenu will return the number (counting from the top of the menu)
Xof the item selected.  If the user selected the second item in the menu
Xthen \fIpopmenu\fP will return (2).
X.br
XA negative return value indicates the user canceled the selection.
X.PP
XAfter you run a menu you will need to touchwin(stdscr); wrefresh(stdscr);
Xin order to remove the popmenu from the screen.
X.PP
XThe KeyCancel defines the key where the user does not want to make any
Xchoice.  The KeyHelp defines what key is to display the help.  The KeyUp and
XKeyDown inaddition to the curses arrow key move the select bar up and down.
XKeyIC is used to toggle between \fIfull\fP and \fIfirst\fP character matching
Xschemes.
X
X.SH DEFINE NEW MENU
X.B "popmenu (action, menu_id, row, column, title, helpfile, win_size, sizeof( option_base ), option_base, mtype )"
X.br
X.B "int	action;"
X.br
X.B "int	menu_id;"
X.br
X.B "int	row;"
X.br
X.B "int	column;"
X.br
X.B "char	*title;"
X.br
X.B "char	*helpfile;"
X.br
X.B "int	win_size;"
X.br
X.B "char	*option_base;"
X.br
X     or
X.br
X.B "char	**option_base;"
X.br
X.B "int		mtype;"
X
X.SS ARGUMENTS
X.TP 6
Xaction
XNEWMENU - tells popmenu that you want to initialize a new menu.
XIf one already exists for this menu_id it will be deleted and then recreated
Xfrom the new list.
X.br
X
XCREATEMENU - If a menu already exists for this menu_id then this flag has
Xno effect.  Otherwise, it initializes a new menu from the list provided.
X
XDIMWINDOW - Dims the reverse video box around the menu.
X.br
Xpopmenu (DIMWINDOW, menu_id);
X.TP 6
Xmenu_id
XA unique identifier that you chose to be assiciated with a menu.
XYou use this identifier to run the menu.
X.TP 6
Xrow, column
XThe upper left corner of where you want the menu box to popup at.
X.TP 6
Xtitle
XTitle to be centered on the first row of the menu.  If title is null no title
Xwill be displayed.
X.TP 6
Xhelpfile
XThe helpfile name that contains help text to be displayed when the uses presses
Xthe help key.  If a helpfile is supplied a "?" is displayed in the lower
Xright hand corner of the menu.  Set to null if no help file is provided.
X.br
XThe help file should be in a format corresponding to GetInput(3),  see
XGetInput(3X) for more information.  Popmenu is hard-coded to look for
X\fIhelptag\fP "popmenu" in the helpfile.
X.TP 6
Xwin_size
XThe length of the pop-up window.  This may be less than the number of
Xoptions, so that popmenu() will only display
X.I win_size
Xnumber of options on the screen.  A window size of 6 or the number of options,
Xwhichever is less, is used if this field is set to 0.  Note that this field
Xshould not be set to be more than 22, which is the normal screen size (24)
Xminus 2 for the borders.
X.TP 6
Xsizeof( option_base[0] ) or 0
XIs an integer telling popmenu() the size of one option array element.  It can
Xalso be set to
X.I zero(0)
Xif (char **) array is passed as the next argument,
X.I popmenu
Xwill figure out the increment as the size of a char pointer.
X.TP 6
Xoption_base    
XThis is a (char *) to an array which store
Xthe options you want to appear in the menu.  This array can be either a
Xtwo dimensional char array, or a structure array, or even an array of pointers.
XThe first char string in each array element up to the first NULL character is
Xused to be displayed as options.  The rest of the field may just be table
Xlook-up items.  Also, The last element must be NULL to signify the end of the
Xtable.
X.TP 6
Xmtype
X.I mtype
Xis either TRUE or FALSE.  When TRUE, \fIpopmenu\fP performs full length,
Xnon-case-sensitive option matching, otherwise, a first character only
Xmatching scheme will be used.
X.PP
XFor menus that has to be built dynamically during run time,
Xthere are benefit of preparing your option table either way.  With a pre-set
Xchar array storing the menu entries, cpu usage is optimized in the expense of
Xmemory; while using char *array will optimize memory usage but has to allocate
Xmemory on the fly.  Menus built at compiled time are about equal with either
Xmethod.
X
X.SH CREDITS
XPaul J. Condie      7/87	(original author)
X.br
X{ihnp4,lll-crg,qantel,pyramid}!ptsfa!pbody!pcbox!pjc
X
XSam S. Lok		enhancements
X
X.SH EXAMPLE
X.nf
X#include	<curses.h>
X
X#define	NEWMENU	0
X
Xint	KeyHelp = 23;		/* control w */
Xint	KeyCancel = 27;		/* ESC */
Xint	KeyDown;
Xint	KeyUp;
X
Xmain ()
X{
X	int	option;		/* the option the user selected */
X	static char	mymenu[][7] = {
X		"QUERY", "ADD", "DELETE", (char *)NULL };
X	static char	*yourmenu[] = {
X		"QUERY", "ADD", "DELETE", (char *)NULL };
X
X
X	/* define a new menu */
X	popmenu(NEWMENU, 1, 5,10, "Title", "", 3, sizeof( mymenu[0] ), mymenu, TRUE );
X	popmenu(NEWMENU, 2, 7,15, "Title", "", 0, 0, yourmenu, TRUE );
X
X	/* run the menu */
X	option = popmenu (1, "c");
X	option = popmenu (2, (char *)NULL);
X
X	/* remove the menu from the screen */
X	touchwin (stdscr);
X	wrefresh (stdscr);
X}
X.fi
X
X.SH SEE ALSO
Xcurses(3X), GetInput(3X).
SHAR_EOF
chmod 0644 utilities.d/libgeti.d/popmenu.3 || echo "restore of utilities.d/libgeti.d/popmenu.3 fails"
echo "x - extracting utilities.d/libgeti.d/GetInput.hlp (Text)"
sed 's/^X//' << 'SHAR_EOF' > utilities.d/libgeti.d/GetInput.hlp &&
XGETINPUT
X.TITLE GETINPUT Help
XMover Keys:
X        KEY_RETURN  (^m)    Traverse forwards through the fields.
X        KEY_DOWN  (^j)      Traverse forwards through the fields.
X        KEY_UP  (^k)        Traverse backwards through the fields.
X        KEY_TAB  (^i)       Fast forward through the fields.
X        KEY_BTAB            Fast reverse through the fields.
XField Editing Keys:
X        KEY_BEG  (^b)       Place cursor at beginning of field.
X        KEY_END  (^e)       Place cursor at end of input in field.
X        KEY_RIGHT  (^l)     Forward space within the field.
X        KEY_LEFT  (^h)      Backspace within the field (non-destructive).
X        KEY_BACKSPACE  (^h) Same as KEY_LEFT.
X        KEY_EOL  (^d)       Delete from cursor to end of field.
X        KEY_DL  (^c)        Clear field and home cursor.
X        KEY_DC  (^x)        Delete a character.
X        KEY_IC  (^t)        Toggle between type-over and insert mode.
XOther Keys:
X        KEY_HELP  (?)       Display help screen.
X        KEY_REFRESH  (^r)   Redraw the screen.
X        KEY_ACCEPT  (^a)    Accept all input and exit screen.
X        KEY_CANCEL  (esc)   Cancel all input and exit screen.
X        KEY_SAVE  (^f)      Save screen to a file.
X        KEY_PRINT  (^p)     Print screen to lp.
XGETINPUT
X
X
X
Xpopmenu
X.TITLE Pop-Up Menu Help
XSELECTING OPTIONS:
X    Press the "up arrow key", "^k", "down arrow key", "^j" 
X    to place bar on option and press "return".
X
X    or
X
X    Enter the first character of the option you
X    wish to select and press "return".
X
X    KEY_CANCEL (esc)   - Cancel selection.
Xpopmenu
X
X
X
Xhelp
X.TITLE Using Help
XHelp displays consist of a description displayed in a window.
XIf the description doesn't fit in the window, the Up Arrow and
XDown Arrow keys can be used to view a few more lines of the 
Xdisplay.  Exiting the help system will return the display to 
Xthe state it was in when you asked for help.
X
X   The following keys are active in help:
X        KEY_CANCEL  (esc)   Exit help.
X        KEY_DOWN  (^j)      View a few more lines.
X        KEY_UP  (^k)        View the previous lines.
X        KEY_BEG  (^b)       Display first page.
X        KEY_END  (^e)       Display last page.
Xhelp
SHAR_EOF
chmod 0444 utilities.d/libgeti.d/GetInput.hlp || echo "restore of utilities.d/libgeti.d/GetInput.hlp fails"
echo "x - extracting utilities.d/checkpass.d/checkpass.1 (Text)"
sed 's/^X//' << 'SHAR_EOF' > utilities.d/checkpass.d/checkpass.1 &&
X. \ %W% DeltaDate %G% ExtrDate %H% 
X.po 6
X.TH CHECKPASS 1 "" "Menu Utility"
X
X.SH \s9NAME\s0
Xcheckpass \- find matching passwd in /etc/passwd file for a specified login.
X
X.SH SYNOPSIS
Xcheckpass login passwd 
X
X.SH DESCRIPTION
X.I Checkpass 
Xfinds the \fIlogin\fP password in the /etc/passwd file, encrypts the
X\fIpasswd\fP and does a comparison. 
X.SH FILES
X/etc/passwd
X
X.SH AUTHOR
XVickie C. Chui
X
X.SH DIAGNOSTICS
XCheckpass returns exit code zero if it was successful, otherwise, it
Xreturns a 4.
SHAR_EOF
chmod 0644 utilities.d/checkpass.d/checkpass.1 || echo "restore of utilities.d/checkpass.d/checkpass.1 fails"
echo "x - extracting utilities.d/checkpass.d/checkpass.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > utilities.d/checkpass.d/checkpass.c &&
X/*
X *	checkpass.c:  encrypt entered passwd and comparing it against 
X *		 the /etc/passwd.
X *	
X *	Inputs:	 argv[1] - login
X *		 argv[2] - passwd
X *	
X *	Return Values: 4 failure
X *		0 - matched passwd found
X */
X
X#include <pwd.h>
X
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X{
X	struct 	passwd *getpwnam(), *pwentry;
X	char 	salt[2], 
X		*crypt(),
X		*encryptedpw;
X
X
X	/* check number of arguments */
X	if(argc != 3) {
X		printf("Usage:  checkpass login passwd\n");
X		exit(4);
X	}
X	
X	/* get passwd for login from /etc/passwd file */
X	if((pwentry=getpwnam(argv[1])) == (struct passwd *) 0) 
X		exit(4);
X
X	salt[0] = *(pwentry->pw_passwd);
X	salt[1] = *(pwentry->pw_passwd +1);
X
X	/* encrypt entered passwd */
X	encryptedpw = crypt(argv[2], salt);
X
X	/* compare passwd in /etc/passwd with the encrypted passwd */
X	if(strcmp(encryptedpw, pwentry->pw_passwd) )
X		exit(4);
X	exit(0);
X}
SHAR_EOF
chmod 0644 utilities.d/checkpass.d/checkpass.c || echo "restore of utilities.d/checkpass.d/checkpass.c fails"
echo "x - extracting utilities.d/lock.d/junk (Text)"
sed 's/^X//' << 'SHAR_EOF' > utilities.d/lock.d/junk &&
X				lockfd = open(diallock, O_WRONLY|O_CREAT|O_EXCL,
X						0444) ;
X				if (lockfd < 0) 
X				{
X					if (debug & D_DEVICE) 
X					{
X						dialmsg("%s: %s\n", errstring(),
X							diallock) ;
X					}
X					continue ;
X				}
X				else
X				{
X					/* pjc */
X					/* write process id to lock file */
X					sprintf (tmpstr, "%d", getpid());
X					sprintf (spid, "%10.10s", tmpstr);
X					write (lockfd, spid, strlen(spid));
X				}
X
X				(void) close(lockfd) ;
SHAR_EOF
chmod 0644 utilities.d/lock.d/junk || echo "restore of utilities.d/lock.d/junk fails"
echo "x - extracting utilities.d/lock.d/lock.1 (Text)"
sed 's/^X//' << 'SHAR_EOF' > utilities.d/lock.d/lock.1 &&
X. \ %W% DeltaDate %G% ExtrDate %H% 
X.po 6
X.TH LOCK 1 "" "Menu Utility"
X
X.SH \s9NAME\s0
Xlock \- does a lock on a file
X
X.SH SYNOPSIS
X.B lock  filename
X
X.SH DESCRIPTION
X.B LOCK
Xis designed to be a utility program to be used in conjunction with the menu(1)
Xprogram.  Lock does a lock on a file.  When used with the menu(1)
Xprogram the filename should probably be the program name.  A "LCK.." is 
Xprepended
Xto the filename to indicate that this is a lock file.  This is in keeping
Xwith uucp lock file syntax.  If the \fILCK..filename\fP
Xdoes not exist it will be created.  The lock file is created/looked for in
Xgetenv("LOCKDIR").
X
X
X.SH EXAMPLE
X.nf
Xlock program_name
Xif [ $? -eq 0 ]
X   then	program_name
X		unlock program_name
Xfi
X.fi
X
X.SH FILES
X\fI$LOCKDIR/LCK..filename\fP	the lock file
X
X.SH AUTHOR
XPaul J. Condie       10/88
X.br
X{att,bellcore,sun,ames,pyramid}!pacbell!pcbox!pjc
X
X.SH SEE ALSO
Xmenu(1), unlock(1).
X
X.SH DIAGNOSTICS
XLock returns a zero if the lock was successfully created,
X99 no file specified on command line,
Xotherwise, it returns \fIerrno\fP.  See errno description in manual.
SHAR_EOF
chmod 0644 utilities.d/lock.d/lock.1 || echo "restore of utilities.d/lock.d/lock.1 fails"
echo "x - extracting utilities.d/lock.d/lock.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > utilities.d/lock.d/lock.c &&
X/*
X** Returns:
X**	0	lock successful
X**	99	no file on command line
X**	otherwise	errno
X*/
X
X#include	<stdio.h>
X#include	<fcntl.h>
X#include	<errno.h>
X
Xmain (argc, argv)
X	int	argc;
X	char	*argv[];
X{
X	char		*getenv();
X	int		fd;			/* file descriptor */
X	char		file[40];
X
X	if (argc != 2)
X		exit (1);
X
X	if (getenv("LOCKDIR") != (char *)NULL)
X		sprintf (file, "%s/LCK..%s", getenv("LOCKDIR"), argv[1]);
X	else
X		sprintf (file, "LCK..%s", argv[1]);
X
X	if ((fd = open (file, O_WRONLY|O_CREAT|O_EXCL, 0444)) < 0)
X	{
X		/* check to see if process is still running */
X		exit (errno);
X	}
X
X	/* write process id to lock file */
X	/*
X	sprintf (tmpstr, "%d", getpid());
X	sprintf (spid, "%10.10s", tmpstr);
X	write (lockfd, spid, strlen(spid));
X	*/
X
X	close (fd);
X	exit (0);
X}
X/* Paul J. Condie  8-89 */
SHAR_EOF
chmod 0644 utilities.d/lock.d/lock.c || echo "restore of utilities.d/lock.d/lock.c fails"
echo "x - extracting utilities.d/lock.d/unlock.1 (Text)"
sed 's/^X//' << 'SHAR_EOF' > utilities.d/lock.d/unlock.1 &&
X. \ %W% DeltaDate %G% ExtrDate %H% 
X.po 6
X.TH UNLOCK 1 "" "Menu Utility"
X
X.SH \s9NAME\s0
Xunlock \- unlocks a semaphore lock on a file
X
X.SH SYNOPSIS
Xlock  filename
X
X.SH DESCRIPTION
X.B UNLOCK
Xis designed to be a utility program to be used in conjunction with the menu(1)
Xprogram.  Unlock does a semaphore unlock on a file then unlinks the filename.  
XThe filename should have been previously locked using lock(1).
XA "LCK.." is prepended
Xto the filename to indicate that this is a lock file.
XThe lock file is looked for in getenv("LOCKDIR").
X
X.PP
XThe important thing for unlock is to make sure it runs regardless of how
Xthe program exits.  Examples of how insure that this happens is illustrated
Xbelow:
X.br
Xtrap 'unlock pgm; trap 2' 2; (pgm; unlock pgm); trap 2
X.br
X(nohup pgm; nohup unlock)&
X
X.SH FILES
X\fI$LOCKDIR/LCK..filename\fP	the lock file
X
X.SH AUTHOR
XPaul J. Condie          10/88
X.br
X{att,bellcore,sun,ames,pyramid}!pacbell!pcbox!pjc
X
X.SH SEE ALSO
Xmenu(1), lock(1).
X
X.SH DIAGNOSTICS
XUnlock returns exit code zero if the unlock was successful, otherwise, it
Xreturns a non-zero.
SHAR_EOF
chmod 0644 utilities.d/lock.d/unlock.1 || echo "restore of utilities.d/lock.d/unlock.1 fails"
echo "x - extracting utilities.d/lock.d/unlock.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > utilities.d/lock.d/unlock.c &&
X/*
X** Name:	unlock(1)
X** Returns:
X**	0	unlock successful
X**	99	no file on command line
X**	otherwise	errno
X*/
X
X#include	<stdio.h>
X#include	<errno.h>
X
Xmain (argc, argv)
X	int	argc;
X	char	*argv[];
X{
X	char		*getenv();
X	char		file[40];
X
X	if (argc != 2)
X		exit (99);
X
X	if (getenv("LOCKDIR") != (char *)NULL)
X		sprintf (file, "%s/LCK..%s", getenv("LOCKDIR"), argv[1]);
X	else
X		sprintf (file, "LCK..%s", argv[1]);
X
X	if (unlink (file) < 0)
X		exit (errno);
X
X	exit (0);
X}
X/* Paul J. Condie  8-89 */
SHAR_EOF
chmod 0644 utilities.d/lock.d/unlock.c || echo "restore of utilities.d/lock.d/unlock.c fails"
echo "x - extracting utilities.d/lock.d/uulock.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > utilities.d/lock.d/uulock.c &&
X/*
X
X  Lock a tty and then run a program.  Blow away old locks.
X
X  Written for Sys V with HDB style locks.
X  Written by Jon Zeeff (zeeff at b-tech.ann-arbor.mi.us)
X  This program placed in the public domain.
X
X*/
X
X#include <stdio.h>
X#include <sys/types.h>
X#include <sys/stat.h>
X#include <signal.h>
X#include <fcntl.h>
X#include <termio.h>
X#include <sys/errno.h>
X
Xchar *strcpy();
Xchar *strcat();
Xunsigned sleep();
Xunsigned alarm();
Xvoid exit();
Xint pid;
X
XFILE *lock;
Xchar tty_lock[100];
X
Xmain(argc,argv)
Xint argc;
Xchar **argv;
X{
X
X        if (argc < 3) {
X           fprintf(stderr,"Usage: uulock tty command args\n");
X           exit(1);
X        }
X 
X	/* create a hdb style lock file */
X
X        strcpy(tty_lock,"/usr/spool/locks/LCK..");
X        strcat(tty_lock,argv[1]);
X
X        check_lock(tty_lock);
X        umask(022);
X
X	lock = fopen(tty_lock,"w");
X	if (lock) {
X		fprintf(lock,"%10.10d\n",(int)getpid());
X		fclose(lock);
X
X                if (pid = fork()) {
X		  int w;
X                  while ((w = wait((int *)0)) != pid && w != -1);
X                  unlink(tty_lock);
X                } else {
X                   execvp(argv[2],&argv[2]);
X		   printf("Can't exec that program\n");
X		   exit(2);
X                } 
X	} else {
X          fprintf(stderr,"tty port in use\n");
X          return 2;
X        }
X
X   return 0;
X}
X
X/* remove a lock file if the process is no longer there */
X
Xcheck_lock(file_name)
Xchar *file_name;
X{
X
X	int fd;
X        char lock_pid[11];
X	extern int errno;
X
X	if ((fd = open(file_name, O_RDONLY)) == -1) {
X           unlink(file_name);
X           return 0;
X        }
X
X	read(fd,lock_pid, 10);
X	close(fd);
X
X	if ((kill(atoi(lock_pid), 0)) == 0 || errno == EPERM) 
X           return 1;    /* process is active */
X
X        unlink(file_name);
X        return 0;
X}
SHAR_EOF
chmod 0644 utilities.d/lock.d/uulock.c || echo "restore of utilities.d/lock.d/uulock.c fails"
echo "x - extracting utilities.d/m.d/adduser (Text)"
sed 's/^X//' << 'SHAR_EOF' > utilities.d/m.d/adduser &&
X#! /bin/ksh
X# %W%   DeltaDate %G%   ExtrDate %H%
X
X###  adduser
X###	Add a new user login to the system.
X###	This script is designed to be run from the menu(1) program.
X###	Menu script file is sadmin.m
X###	This script needs to be run with a set uid to root.
X###
X###  Arguments:
X###	$1 = login ID
X###	$2 = encrypted password
X###	$3 = numerical user ID
X###	$4 = numerical group ID
X###	$5 = Text (Users Read Name)
X###	$6 = directory to create users home directory in
X###	$7 = program to use as Shell
X###	$8 = default .profile for user
X###	$9 = default printer
X###	$10 =	password file
X###	$11 =	group file
X###
X###  Note:
X###  	In order to get chgrp to work you need to chown to $LOGNAME first.
X###  	The setuid does not work for chgrp ????
X###
X
X###	Validate argument count
Xif [ $# -ne 11 ]
X   then	echo "[$0] Incorrect argument count."
X	exit 1
Xfi
X
XLOGNAME=$1
XPASSWD=$2
XUID=$3
XGID=$4
XNAME=$5
XHOMEDIR=$6
XLOGSHELL=$7
XDPROFILE=$8
XPRINTER=$9
Xshift; shift
XPWDFILE=$8
XGROUPFILE=$9
X
X###	Validate must enter arguments.
Xif [ -z "$LOGNAME" ]
X   then	echo "No Login specified.  Aborting adduser."
X	exit 1
Xfi
Xif [ -z "$UID" ]
X   then	echo "No User ID specified.  Aborting adduser."
X	exit 1
Xfi
Xif [ -z "$GID" ]
X   then	echo "No Group ID specified.  Aborting adduser."
X	exit 1
Xfi
Xif [ -z "$HOMEDIR" ]
X   then	echo "No Home Directory specified.  Aborting adduser."
X	exit 1
Xfi
Xif [ -z "$LOGSHELL" ]
X   then	echo "No Login Shell specified.  Aborting adduser."
X	exit 1
Xfi
Xif [ -z "$PWDFILE" ]
X   then	echo "No Password File specified.  Aborting adduser."
X	exit 1
Xfi
Xif [ -z "$GROUPFILE" ]
X   then	echo "No Group File specified.  Aborting adduser."
X	exit 1
Xfi
X
X
X
X# Prompt for conformation
Xreply=`MenuPrompt \`tput lines\` 0 "Are You Sure (y/n) ? "`
Xif [ "$reply" != "y" ]
X   then	echo "$LOGNAME not added."
X	exit 1
Xfi
X
Xtrap "MenuMsg `tput lines` 0 'Too late to abort adduser!'" 2 3 15
X
X
X
X
X###	Make home directory
XMenuMsg `tput lines` 0 "Making a home directory."
XMAKEDIR=yes
Xif [ -s "$HOMEDIR" ]
X   then	reply=`MenuPrompt \`tput lines\` 0 "Warning: $HOMEDIR already exists.  Okay to use it. (y/n) ?  "`
X	if [ "$reply" = "y" ]
X	   then MAKEDIR=no
X	fi
Xfi
Xif [ "$MAKEDIR" = "yes" ]
X   then	mkdir $HOMEDIR
X	rcde=$?
X	if [ $rcde -ne 0 ]
X	   then echo "[$rcde]  Could not create $HOMEDIR."
X		exit 1
X	fi
Xfi
X###	The home directory will be chown'd after we add entry to password file.
SHAR_EOF
echo "End of part 12"
echo "File utilities.d/m.d/adduser is continued in part 13"
echo "13" > s2_seq_.tmp
exit 0



More information about the Alt.sources mailing list