menu(1) part 14 of 14
Paul J. Condie
pjc at pcbox.UUCP
Thu Dec 27 07:17:44 AEST 1990
#!/bin/sh
# this is part 14 of a multipart archive
# do not concatenate these parts, unpack them in order with /bin/sh
# file utilities.d/msgbox.d/msgbox.c continued
#
CurArch=14
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/msgbox.d/msgbox.c"
sed 's/^X//' << 'SHAR_EOF' >> utilities.d/msgbox.d/msgbox.c
X#define ARG_COUNT_ERR 1 /* improper argc value in main */
X#define MSG_LEN_ERR 2 /* argv[2] message is out of range (1 - 78 chars) */
X#define STANDOUT 2 /* drawbox() needs this for border attribute. */
X
X
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X{
X char msg[78]; /* a message gotten from argv[2] or error msg */
X
X int BoxColumns, /* total columns in box, calculated */
X BoxStartCol, /* starting left most column of box, calculated */
X BoxTop, /* starting top most row of box, from argv[1] */
X ErrStatus; /* values: NO_ERR, ARG_COUNT_ERR, MSG_LEN_ERR */
X
X WINDOW *MsgWind; /* The mesage box itself */
X
X /* derive the box's top row value from argv[1] via atoi() */
X BoxTop = atoi(argv[2]);
X
X /* if error in argv[2], use 0 as BoxTop value */
X if (BoxTop > MAX_ROW || BoxTop < 1) {
X BoxTop=0;
X }
X
X /* check for proper arg count and proper msg length; If in error, form msg
X * as an error message; if no error, use argv[2] as msg.
X */
X if (argc < 2 || argc > 3) {
X ErrStatus=ARG_COUNT_ERR;
X } else {
X /* check the string length of the message */
X if (strlen(argv[1]) && strlen(argv[1]) < 79 ) {
X ErrStatus=NO_ERR;
X } else {
X ErrStatus=MSG_LEN_ERR;
X }
X }
X
X
X /* if no errors were found, use argv[2] as msg, else use a USEAGE message */
X if (ErrStatus == NO_ERR) {
X strcpy(msg, argv[1]);
X } else {
X sprintf(msg,
X " USAGE: %s \"Quote mark delimited message (1-78 chars)\" [TopRow] ",
X argv[0]);
X }
X
X BoxColumns=strlen(msg) + 2; /* size box on msg */
X BoxStartCol=(80 - BoxColumns)/2; /* center window horizontally */
X
X
X initscr();
X
X
X /* Create a new window to display a message to the user */
X MsgWind=newwin(BOX_ROWS, BoxColumns, BoxTop, BoxStartCol);
X drawbox(MsgWind, 1, 1, BOX_ROWS, BoxColumns, STANDOUT, STANDOUT, 0, 0);
X mvwaddstr(MsgWind, 2, 1, msg);
X wrefresh(MsgWind);
X
X endwin();
X
X /* give humans time to view usage error message */
X if (ErrStatus != NO_ERR)
X sleep(5);
X
X exit(ErrStatus);
X
X} /* end main */
SHAR_EOF
echo "File utilities.d/msgbox.d/msgbox.c is complete"
chmod 0644 utilities.d/msgbox.d/msgbox.c || echo "restore of utilities.d/msgbox.d/msgbox.c fails"
echo "x - extracting utilities.d/MenuMsg.d/MenuMsg.1 (Text)"
sed 's/^X//' << 'SHAR_EOF' > utilities.d/MenuMsg.d/MenuMsg.1 &&
X. \ %W% DeltaDate %G% ExtrDate %H%
X.po 6
X.TH MENUMSG 1 "" "Menu Utility"
X
X.SH \s9NAME\s0
XMenuMsg -\ writes a message to a menu screen
X
X.SH SYNOPSIS
X.B MenuMsg [ DONT_CLEAR ] row col message
X
X.SH DESCRIPTION
X.B MenuMsg
Xis designed to be a utility program to be used in conjunction with the menu(1)
Xprogram. This can be used to display a message to a menu screen without
Xmessing up the screen. The [ DONT_CLEAR ] option causes MenuMsg not to
Xclear the line before displaying the message.
X
X
X.SH EXAMPLE
XTo print a message to the message row:
X.nf
X
X MenuMsg `tput lines` 0 "This is a message."
X.fi
X
X.SH AUTHOR
XPaul J. Condie 7/90
X.br
X{att,bellcore,sun,ames,pyramid}!pacbell!pcbox!pjc
X
X.SH SEE ALSO
Xmenu(1).
SHAR_EOF
chmod 0644 utilities.d/MenuMsg.d/MenuMsg.1 || echo "restore of utilities.d/MenuMsg.d/MenuMsg.1 fails"
echo "x - extracting utilities.d/MenuMsg.d/MenuMsg.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > utilities.d/MenuMsg.d/MenuMsg.c &&
X/*
X** MenuMsg(1)
X** Display text to a menu(1) screen without trashing the screen.
X** ARGS
X** row and col to dispaly text to
X*/
X
X#include <curses.h>
X#include <term.h>
X
Xmain (argc, argv)
X int argc;
X char *argv[];
X{
X FILE *fopen(), *fp;
X char *tparm();
X char *getenv();
X char *tparm();
X int _outch();
X char *term;
X int status;
X char *str;
X int row;
X int col;
X
X if ((fp = fopen ("/dev/tty", "w")) == (FILE *)NULL)/* reopen terminal */
X exit (1);
X if ((term = getenv ("TERM")) == (char *)NULL)
X exit (1);
X setupterm (term, 1, &status); /* set-up terminal */
X if (status != 1)
X exit (1);
X if (cursor_address == NULL) /* we need cursor movement */
X exit (1);
X if (strcmp (argv[1], "DONT_CLEAR") == 0)
X {
X sscanf (argv[2], "%d", &row);
X sscanf (argv[3], "%d", &col);
X fprintf (fp, "%s%s", tparm (cursor_address, row, col), argv[4]);
X }
X else
X {
X sscanf (argv[1], "%d", &row);
X sscanf (argv[2], "%d", &col);
X fprintf (fp, "%s", tparm (cursor_address, row, col));
X fprintf (fp, "%s", tparm (clr_eol));
X fprintf (fp, "%s%s", tparm (cursor_address, row, col), argv[3]);
X }
X /*
X tputs (tparm (cursor_address, row, col), 1, _outch);
X fprintf (fp, "%s", argv[3]);
X */
X fclose (fp);
X}
X/* Paul J. Condie 7-90 */
SHAR_EOF
chmod 0644 utilities.d/MenuMsg.d/MenuMsg.c || echo "restore of utilities.d/MenuMsg.d/MenuMsg.c fails"
echo "x - extracting utilities.d/MenuMsg.d/MenuPrompt.1 (Text)"
sed 's/^X//' << 'SHAR_EOF' > utilities.d/MenuMsg.d/MenuPrompt.1 &&
X. \ %W% DeltaDate %G% ExtrDate %H%
X.po 6
X.TH MENUPROMPT 1 "" "Menu Utility"
X
X.SH \s9NAME\s0
XMenuPrompt -\ writes a prompt message to a menu screen then prompts for a reply
X
X.SH SYNOPSIS
X.B MenuPrompt [ DONT_CLEAR ] row col message
X
X.SH DESCRIPTION
X.B MenuPrompt
Xis designed to be a utility program to be used in conjunction with the menu(1)
Xprogram. This can be used to prompt for a reply from the user within a
Xmenu screen.
X
X
X.SH EXAMPLE
XTo prompt the user:
X.nf
X
X reply=`MenuPrompt \\`tput lines\\` 0 "Do you want to continue (y/n) ? "`
X.fi
X
X.SH AUTHOR
XPaul J. Condie 7/90
X.br
X{att,bellcore,sun,ames,pyramid}!pacbell!pcbox!pjc
X
X.SH SEE ALSO
Xmenu(1).
SHAR_EOF
chmod 0644 utilities.d/MenuMsg.d/MenuPrompt.1 || echo "restore of utilities.d/MenuMsg.d/MenuPrompt.1 fails"
echo "x - extracting utilities.d/MenuMsg.d/MenuPrompt.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > utilities.d/MenuMsg.d/MenuPrompt.c &&
X/*
X** MenuPrompt(1)
X** ARGS
X** row and col to dispaly text to
X*/
X
X#include <curses.h>
X#include <term.h>
X
Xmain (argc, argv)
X int argc;
X char *argv[];
X{
X FILE *fopen(), *fpout, *fpin;
X char *tparm();
X char *getenv();
X char *tparm();
X int _outch();
X char *term;
X int status;
X char *strp;
X int row;
X int col;
X char buf[BUFSIZ];
X int ch;
X
X if ((fpout = fopen ("/dev/tty", "w")) == (FILE *)NULL)
X exit (1);
X if ((fpin = fopen ("/dev/tty", "r")) == (FILE *)NULL)
X exit (1);
X if ((term = getenv ("TERM")) == (char *)NULL)
X exit (1);
X setupterm (term, 1, &status); /* set-up terminal */
X if (status != 1)
X exit (1);
X if (cursor_address == NULL) /* we need cursor movement */
X exit (1);
X if (strcmp (argv[1], "DONT_CLEAR") == 0)
X {
X sscanf (argv[2], "%d", &row);
X sscanf (argv[3], "%d", &col);
X fprintf (fpout, "%s%s", tparm (cursor_address, row, col),
X argv[4]);
X }
X else
X {
X sscanf (argv[1], "%d", &row);
X sscanf (argv[2], "%d", &col);
X fprintf (fpout, "%s", tparm (cursor_address, row, col));
X fprintf (fpout, "%s", tparm (clr_eol));
X fprintf (fpout, "%s%s", tparm (cursor_address, row, col),
X argv[3]);
X }
X
X strp = buf;
X while (1)
X {
X ch = fgetc (fpin);
X if ((char)ch == '\n' || (char)ch == '\r')
X break;
X *strp = (char)ch;
X fprintf (fpout, "%c", *strp); fflush (stdout);
X strp++;
X }
X *strp = '\0';
X printf ("%s", buf);
X
X fclose (fpin);
X fclose (fpout);
X}
X/* Paul J. Condie 7-90 */
SHAR_EOF
chmod 0644 utilities.d/MenuMsg.d/MenuPrompt.c || echo "restore of utilities.d/MenuMsg.d/MenuPrompt.c fails"
echo "x - extracting utilities.d/MenuMsg.d/makefile (Text)"
sed 's/^X//' << 'SHAR_EOF' > utilities.d/MenuMsg.d/makefile &&
Xall: MenuMsg MenuPrompt
X
XMenuMsg: MenuMsg.o
X $(CC) -O MenuMsg.c -lcurses -o MenuMsg
X
XMenuPrompt: MenuPrompt.o
X $(CC) -O MenuPrompt.c -lcurses -o MenuPrompt
SHAR_EOF
chmod 0644 utilities.d/MenuMsg.d/makefile || echo "restore of utilities.d/MenuMsg.d/makefile fails"
rm -f s2_seq_.tmp
echo "You have unpacked the last part"
exit 0
More information about the Alt.sources
mailing list