menu(1) part 7 of 14
Paul J. Condie
pjc at pcbox.UUCP
Thu Dec 27 07:09:50 AEST 1990
#!/bin/sh
# this is part 7 of a multipart archive
# do not concatenate these parts, unpack them in order with /bin/sh
# file runscreen.c continued
#
CurArch=7
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 runscreen.c"
sed 's/^X//' << 'SHAR_EOF' >> runscreen.c
X }
X rc = runpopen (FLD->before_field, buf);
X switch (rc)
X {
X case 0:
X /*
X ** aok accept input
X ** if buf is not null replace $var
X */
X ifvarset (buf, swin, menu->srn[sidx]->field);
X break;
X case 1:
X /*
X ** aok prompt for input
X ** if buf display on message line.
X */
X move (ErrRow, 0); clrtoeol ();
X attrset (A_REVERSE);
X mvprintw (ErrRow, 0, "%s", buf);
X attrset (A_NORMAL);
X refresh ();
X sleep (3);
X break;
X case 2:
X /* skip this field */
X ifvarset (buf, swin, menu->srn[sidx]->field);
X NoInput = TRUE;
X break;
X
X default:
X /* do nothing */
X break;
X }
X }
X
X
X if (getenv(FLD->name) != (char *)NULL)
X strcpy (input, getenv (FLD->name));
X else
X strcpy (input, "");
X Fld.strVal = input;
X
X
X /*
X ** This is so GetInput doesn't overwrite the
X ** must enter message.
X */
X if (promptptr == (char *)NULL)
X promptptr = FLD->prompt;
X else if (strcmp (promptptr, "NOMSG") == 0)
X promptptr = NOMSG;
X
X
X /* if noinput == FALSE prompt for input */
X if (!NoInput)
X {
X exitkey = GetInput (swin, FLD->row, FLD->col, &Fld,
X A_REVERSE, FLD->mask, tmprange[fidx], FLD->length,
X FLD->min_input, FLD->type, FLD->adjust, CHAR,
X NOAUTO, FLD->mustenter, ErrRow, ErrRow,
X promptptr, helpfile, FLD->name);
X /* set the environment variable */
X rc = setenv (FLD->name, Fld.strVal);
X if (rc < 0)
X {
X mvwprintw (stdscr, ErrRow,0,
X "Unable to allocate environment memory to set variable %s.",
X FLD->name);
X BEEP;
X }
X }
X else
X {
X /* use the exitkey from the last field */
X if (exitkey != KEY_UP)
X exitkey = KEY_DOWN;
X }
X promptptr = (char *)NULL;
X
X
X
X
X if (exitkey == KeyReturn) exitkey = KEY_RETURN;
X if (exitkey == KeyUp) exitkey = KEY_UP;
X if (exitkey == KeyDown) exitkey = KEY_DOWN;
X if (exitkey == KeyTab) exitkey = KEY_TAB;
X if (exitkey == KeyBTab) exitkey = KEY_BTAB;
X if (exitkey == KeyCancel) exitkey = KEY_CANCEL;
X if (exitkey == KeyAccept) exitkey = KEY_ACCEPT;
X
X
X /* run after_field command */
X if (exitkey != KEY_CANCEL && FLD->after_field != (char *)NULL)
X {
X char buf[BUFSIZ+1];
X
X if (promptptr == (char *)NULL ||
X strcmp (promptptr, "DONT_CLEAR") != 0)
X {
X move (ErrRow,0); clrtoeol();
X mvprintw (ErrRow,1, "Working ...");
X refresh ();
X }
X rc = runpopen (FLD->after_field, buf);
X switch (rc)
X {
X case 0:
X /*
X ** aok continue to next field
X ** If buf has var=value set and redisplay
X */
X ifvarset (buf, swin, menu->srn[sidx]->field);
X break;
X case 1:
X /*
X ** aok prompt for input
X ** if buf display on message line.
X */
X move (ErrRow, 0); clrtoeol ();
X attrset (A_REVERSE);
X mvprintw (ErrRow, 0, "%s", buf);
X attrset (A_NORMAL);
X wnoutrefresh (stdscr);
X promptptr = "DONT_CLEAR";
X BELL;
X continue;
X
X default:
X /* do nothing */
X break;
X }
X } /* end after_field */
X
X /* if exitlastfield accept input and exit on last field */
X if (SRN->exitlastfield && fidx == fieldcount &&
X exitkey == KEY_RETURN)
X exitkey = KEY_ACCEPT;
X
X switch (exitkey)
X {
X case KEY_CANCEL:
X /* reset $field_name to orginal data */
X for (fidx = 0; SRN->field[fidx] !=
X (struct FieldInfo *)NULL && fidx <= MAXFIELDS;
X fidx++)
X setenv (FLD->name, fielddata[fidx]);
X break;
X
X case KEY_ACCEPT:
X /* make sure mustenter fields have been entered */
X for (fidx = 0; fidx <= fieldcount; fidx++)
X {
X if (FLD->mustenter &&
X strlen (getenv(FLD->name)) <= 0)
X {
X mvwprintw (stdscr, ErrRow,1,
X "This is a must enter field.");
X BEEP;
X wnoutrefresh (stdscr);
X promptptr = "DONT_CLEAR";
X exitkey = KEY_DOWN; /* not done */
X break;
X }
X }
X /* if mustenter then more input */
X if (fidx <= fieldcount)
X break;
X break;
X
X case KEY_TAB:
X fidx += 4;
X fidx = fidx >= fieldcount ? 0 : ++fidx;
X break;
X
X case KEY_BTAB:
X fidx -= 4;
X fidx = fidx < 0 ? fieldcount : --fidx;
X break;
X
X case KEY_UP:
X fidx = fidx <= 0 ? fieldcount : --fidx;
X break;
X
X case KEY_RETURN:
X case KEY_DOWN:
X default:
X fidx = fidx >= fieldcount ? 0 : ++fidx;
X break;
X }
X } while (exitkey != KEY_CANCEL && exitkey != KEY_ACCEPT);
X
X if (exitkey != KEY_CANCEL && SRN->after_screen != (char *)NULL)
X {
X char buf[BUFSIZ+1];
X
X move (ErrRow,0); clrtoeol();
X mvprintw (ErrRow,1, "Working ...");
X refresh ();
X rc = runpopen (SRN->after_screen, buf);
X switch (rc)
X {
X case 0:
X /*
X ** aok
X ** if buf display on message line with no bell.
X */
X move (ErrRow, 0); clrtoeol ();
X attrset (A_REVERSE);
X mvprintw (ErrRow, 0, "%s", buf);
X attrset (A_NORMAL);
X wnoutrefresh (stdscr);
X promptptr = "DONT_CLEAR";
X break;
X
X case 1:
X /*
X ** aok prompt for input
X ** if buf display on message line with bell.
X */
X move (ErrRow, 0); clrtoeol ();
X attrset (A_REVERSE);
X mvprintw (ErrRow, 0, "%s", buf);
X attrset (A_NORMAL);
X wnoutrefresh (stdscr);
X promptptr = "DONT_CLEAR";
X BELL;
X break;
X
X default:
X /* do nothing */
X break;
X }
X } /* end after_screen */
X
X delwin (swin); /* junk screen window */
X if (!SRN->exitoncancel || exitkey == KEY_CANCEL)
X {
X wmove (stdscr,LINES-1,0);
X clrtoeol (); /* clear field prompt */
X touchwin (stdscr);
X }
X
X /* junk tmp range values */
X for (i = 0; i < MAXFIELDS; i++)
X {
X if (tmprange[i] != (char *)NULL)
X free (tmprange[i]);
X tmprange[i] = (char *)NULL;
X }
X
X if (SRN->exitoncancel && exitkey != KEY_CANCEL)
X goto herewegoagain;
X
X if (exitkey == KEY_CANCEL)
X return (exitkey);
X else
X return (0);
X}
X
X
X
Xchar *format (data, mask, fldtype)
X char *data; /* data 2b formated */
X char *mask; /* mask to format to */
X char fldtype; /* GetInput field type */
X{
X static char fmtdefault[100];
X char *wsptr;
X char *source;
X int i;
X
X
X strcpy (fmtdefault, data);
X wsptr = fmtdefault;
X source = data;
X
X if (strlen(mask) > 0)
X {
X for (; *mask != '\0'; mask++, wsptr++)
X {
X if (IsMask (fldtype, *mask))
X *wsptr = *mask; /* format char */
X else
X {
X if (*source != '\0')
X {
X *wsptr = *source;
X source++;
X }
X else
X *wsptr = ' '; /* no data */
X }
X }
X *wsptr = '\0';
X }
X wsptr = fmtdefault;
X return (wsptr);
X}
X
X
X
X/*
X** if buf contains space separated $var=value
X** then setenv $var to value
X*/
Xifvarset (buf, swin, field)
X char *buf; /* var=value ... */
X WINDOW *swin; /* window to write to */
X struct FieldInfo *field[];
X{
X char *substr();
X char *wsptr;
X char variable[100]; /* name */
X char value[200]; /* value to set name to */
X int i;
X int rc;
X
X
X wsptr = buf;
X while ((wsptr = substr (wsptr, "$")) != (char *)NULL)
X {
X wsptr++; /* get past $ */
X /* get the enviroment variable */
X for (i = 0; *wsptr != '=' && *wsptr != '\0'; i++, wsptr++)
X variable[i] = *wsptr;
X variable[i] = '\0';
X if (strcmp (variable, "") == 0 || *wsptr != '=')
X {
X BEEP;
X mvprintw (ErrRow-2, 0,
X "Error occured while setting enviroment variable %s",
X buf);
X shutdown ();
X }
X wsptr++; /* get past the = */
X
X if (*wsptr == '"')
X strcpy (value, getval (&wsptr, '"'));
X else
X strcpy (value, getval (&wsptr, '0'));
X
X /* find the appropriate field */
X for (i = 0; field[i] != (struct FieldInfo *)NULL &&
X i <= MAXFIELDS; i++)
X {
X if (strcmp (field[i]->name, variable) == 0)
X {
X /* found field */
X adjustfield (value, field[i]->adjust,
X field[i]->length);
X
X /* format value to the mask and display */
X mvwprintw (swin, field[i]->row, field[i]->col,
X "%s", format (value, field[i]->mask,
X field[i]->type));
X break;
X }
X } /* end for */
X /* set the enviroment variable */
X rc = setenv (variable, value);
X if (rc != 0)
X {
X BEEP;
X mvprintw (ErrRow-2, 0,
X "Error occured while setting enviroment variable %s",
X variable);
X shutdown ();
X }
X
X } /* end while */
X wnoutrefresh (swin);
X}
X
X
X
X
Xadjustfield (data, fldadjust, fldlength)
X char *data; /* data 2b formated */
X char fldadjust;
X int fldlength;
X{
X char *source;
X int i;
X
X
X switch (fldadjust)
X {
X case LFADJ_BFILL:
X /* get to end of data */
X for (i = 0, source = data; *source != '\0'; i++, source++)
X ;
X /* blank fill rest of field */
X for (; i < fldlength; i++, source++)
X *source = ' ';
X *source = '\0';
X break;
X }
X}
X/* Paul J. Condie 11/88 */
SHAR_EOF
echo "File runscreen.c is complete"
chmod 0644 runscreen.c || echo "restore of runscreen.c fails"
echo "x - extracting getval.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > getval.c &&
X#ifndef LINT
Xstatic char Sccsid[] = "%W% DeltaDate %G% ExtrDate %H%";
X#endif
X
X/*
X** getval()
X** ARGS:
X** sptr - pointer to beginning of value 2b parsed
X** endch - $ process only the dollar part of value
X** - ` process only the single quote part of value
X** - " process only the double quote part of value
X** - 0 process until a space or invalid is found
X** - 1 process entire string until '\0' is found
X** RETURNS:
X** sptr - pointer to end of value 2b parsed
X** rval - the resulting value.
X**
X** var=one
X** var="one"
X** var=$var
X** var="one $var"
X** var=${var}
X** var=`ls`
X** var=one"two three"
X** var=~/
X** var=~usr/
X*/
X
X#include <stdio.h>
X#include <ctype.h>
X#include <pwd.h>
X
X#define DQUOTE '"'
X#define SQUOTE '`'
X#define LITERAL '\''
X#define DOLLAR '$'
X#define ESCAPE '\\'
X#define BRACE '{'
X#define COMCHAR '#'
X#define TILDE '~'
X#ifndef TRUE
X#define TRUE 1
X#define FALSE 0
X#endif
X
X#ifndef TEST
Xextern int debug;
X#endif
X
X
Xchar *getval (sptr, endch)
X char **sptr; /* pointer to $+1 */
X char endch;
X{
X char *getenv();
X struct passwd *getpwnam();
X FILE *popen(), *pp;
X static char value[400];
X char tmpval[400];
X static char *rval; /* pointer for return */
X int i;
X int EOV = FALSE; /* End Of Value */
X int dqflag = FALSE; /* double quote flag */
X struct passwd *pw;
X
X
X strcpy (value, "");
X rval = value;
X while (!EOV && **sptr)
X {
X switch (**sptr)
X {
X case SQUOTE:
X (*sptr)++; /* get past ' */
X for (i = 0; **sptr != '`' && **sptr; i++, (*sptr)++)
X tmpval[i] = **sptr;
X if (**sptr)
X (*sptr)++; /* get past ' */
X tmpval[i] = '\0';
X /* open pipe and read results */
X if ((pp = popen (tmpval, "r")) != NULL)
X {
X for (; ((i = fgetc(pp)) != EOF); rval++)
X {
X *rval = i ;
X if (!isprint(*rval))
X rval--;
X }
X pclose (pp);
X }
X if (endch == SQUOTE)
X {
X *rval = '\0';
X rval = value;
X return (rval);
X }
X break;
X
X case DQUOTE:
X (*sptr)++;
X dqflag = dqflag == FALSE ? TRUE : FALSE;
X if (endch == DQUOTE && dqflag == FALSE)
X {
X *rval = '\0';
X rval = value;
X return (rval);
X }
X break;
X
X case DOLLAR:
X /* Substitutable parameter */
X
X (*sptr)++; /* get past $ */
X
X /*
X ** The braces are required only when parameter is
X ** followed by a letter, digit, or underscore.
X */
X if (**sptr == BRACE)
X {
X (*sptr)++; /* get past { */
X for (i = 0; **sptr != '}' && **sptr;
X i++, (*sptr)++)
X tmpval[i] = **sptr;
X if (**sptr)
X (*sptr)++; /* get past } */
X }
X else
X {
X for (i = 0; isalnum(**sptr) || **sptr == '_';
X i++, (*sptr)++)
X tmpval[i] = **sptr;
X }
X tmpval[i] = '\0';
X if (getenv(tmpval) != (char *)NULL)
X strcpy (rval, getenv(tmpval));
X rval += strlen (rval);
X if (endch == DOLLAR)
X {
X *rval = '\0';
X rval = value;
X return (rval);
X }
X break;
X
X case TILDE:
X (*sptr)++; /* get past ~ */
X /*
X ** ~/ = $HOME
X ** ~user/ = home(user)
X */
X for (i = 0; **sptr != '/' && **sptr; i++, (*sptr)++)
X tmpval[i] = **sptr;
X tmpval[i] = '\0';
X if (strcmp (tmpval, "") == 0)
X if (getenv("LOGNAME") != (char *)NULL)
X strcpy (tmpval, getenv ("LOGNAME"));
X /*
X ** tmpval holds the user name
X ** now we get the password entry
X */
X pw = getpwnam (tmpval);
X strcpy (rval, pw->pw_dir);
X rval += strlen (pw->pw_dir);
X break;
X
X default:
X if (dqflag || **sptr != ' ' || endch == '1')
X {
X *rval++ = **sptr;
X (*sptr)++;
X }
X else
X EOV = TRUE;
X break;
X } /* end switch */
X } /* end while */
X
X *rval = '\0';
X rval = value;
X#ifndef TEST
X if (debug)
X {
X fprintf (stderr, "\n[%s] value=:%s:, :%s:",
X __FILE__, value, *sptr);
X fflush (stderr);
X }
X#endif
X return (rval);
X}
X
X
X
X#ifdef TEST
Xmain (argc, argv)
X int argc;
X char *argv[];
X{
X char *getval();
X char *sptr;
X char *rval;
X
X sptr = argv[1];
X if (argc == 3)
X rval = getval (&sptr, argv[2][0]);
X else
X rval = getval (&sptr, '1');
X printf ("\nparameter value :%s:", rval);
X printf ("\narg pointer :%s:", sptr);
X}
X#endif
X/* Paul J. Condie 5/89 */
SHAR_EOF
chmod 0644 getval.c || echo "restore of getval.c fails"
echo "x - extracting clean_menu.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > clean_menu.c &&
X#ifndef LINT
Xstatic char Sccsid[] = "%W% DeltaDate %G% ExtrDate %H%";
X#endif
X
X#include "menu.h"
X
Xclean_menu (menu)
X struct MenuInfo *menu;
X{
X int i,j;
X int textcnt;
X
X
X /*
X ** Just to keep things simple, lets start from scratch on the
X ** next menu selected.
X */
X
X /* free options */
X for (i = 0; i < menu->optioncount; i++)
X {
X if (menu->option[i]->command)
X free (menu->option[i]->command);
X free (menu->option[i]);
X }
X
X /* free screens */
X for (i = 0; menu->srn[i] != (struct ScreenInfo *)NULL &&
X i <= MAXSCREENS; i++)
X {
X /* screen information */
X if (menu->srn[i]->fielddefaults != (char *)NULL)
X free (menu->srn[i]->fielddefaults);
X
X /* text stuff */
X for (textcnt = 0;
X menu->srn[i]->textinfo[textcnt] != (struct TextInfo *)NULL;
X textcnt++)
X {
X free (menu->srn[i]->textinfo[textcnt]->text);
X free (menu->srn[i]->textinfo[textcnt]);
X }
X
X if (menu->srn[i]->after_screen != (char *)NULL)
X free (menu->srn[i]->after_screen);
X
X
X /* free field information */
X for (j = 0;
X menu->srn[i]->field[j] != (struct FieldInfo *)NULL &&
X j <= MAXFIELDS; j++)
X {
X if (menu->srn[i]->field[j]->before_field != (char *)NULL)
X free (menu->srn[i]->field[j]->before_field);
X if (menu->srn[i]->field[j]->after_field != (char *)NULL)
X free (menu->srn[i]->field[j]->after_field);
X free (menu->srn[i]->field[j]);
X }
X
X
X free (menu->srn[i]);
X menu->srn[i] = (struct ScreenInfo *)NULL;
X } /* end screens */
X
X if (menu->after_menu != (char *)NULL)
X free (menu->after_menu);
X}
X/* Paul J. Condie 6/89 */
SHAR_EOF
chmod 0644 clean_menu.c || echo "restore of clean_menu.c fails"
echo "x - extracting slength.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > slength.c &&
X#ifndef LINT
Xstatic char Sccsid[] = "@(#)slength.c 1.1 DeltaDate 1/22/90 ExtrDate 1/22/90";
X#endif
X
X/*
X** How long is a string not counting attributes.
X*/
X
Xslength (s)
X char *s;
X{
X register int i = 0;
X
X while (*s)
X {
X if (*s == '\\')
X {
X s++;
X s++;
X continue;
X }
X s++;
X i++;
X }
X return (i);
X}
X/* Paul J. Condie 11-89 */
SHAR_EOF
chmod 0444 slength.c || echo "restore of slength.c fails"
echo "x - extracting runpopen.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > runpopen.c &&
X/*
X** ARGS:
X** command - the command to run
X** RETURNS:
X** -1 unable to open pope
X** x return code from command
X*/
X
X#include <stdio.h>
X
X#ifndef DEBUG
Xextern int debug;
X#else
Xint debug;
X#endif
Xextern int errno;
X
Xrunpopen (command, result)
X char *command; /* command to run */
X char *result; /* from pipe */
X{
X FILE *popen(), *pp;
X char *fgets();
X int rc;
X
X strcpy (result, "");
X if ((pp = popen (command, "r")) == (FILE *)NULL)
X {
X if (debug)
X {
X fprintf (stderr,
X "\n[%s] %d Unable to popen command=:%s:",
X __FILE__, errno, command);
X fflush (stderr);
X }
X return (-1);
X }
X
X if (fgets (result, BUFSIZ, pp) == (char *)NULL)
X strcpy (result, "");
X else
X if (result[strlen(result)-1] == '\n')
X result[strlen(result)-1] = '\0'; /* junk \n */
X
X rc = pclose (pp);
X return (rc >> 8); /* shell rc is in high 8 bits */
X}
X/* Paul J. Condie 4-90 */
X
X
X#ifdef DEBUG
Xmain (argc, argv)
X int argc;
X char *argv[];
X{
X int rc;
X char buf[BUFSIZ+1];
X
X rc = runpopen (argv[1], buf);
X printf ("\n%d :%s:", rc, buf);
X exit (rc);
X}
X#endif
SHAR_EOF
chmod 0644 runpopen.c || echo "restore of runpopen.c fails"
echo "x - extracting mygetch.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > mygetch.c &&
X#include <curses.h>
X
X#ifndef ESC
X#define ESC 27
X#endif
X
Xextern int debug;
X
X
Xmygetch ()
X{
X int row; /* row where mouse is at */
X int col; /* col where mouse is at */
X int rc;
X
X#ifdef UNIXPC
X rc = mouse3b1 (&row, &col);
X#else
X rc = getch();
X#endif
X return (rc); /* character inputted */
X}
X
X
X#ifdef UNIXPC
X
X#include <stdio.h>
X#include <sys/types.h>
X#include <sys/stat.h>
X#include <sys/window.h>
X
Xmouse3b1 (row, col)
X int *row;
X int *col;
X{
X char *readkey();
X char *strchr();
X struct stat sbuf;
X struct umdata umdata;
X int wd; /* window descriptor */
X int rc;
X char kbuf[80]; /* key buffer */
X char *sptr;
X int prow;
X int pcol;
X
X
X /* find window (wd) */
X rc = fstat (0, &sbuf);
X if (rc != 0)
X return (getch());
X wd = sbuf.st_dev; /* window descriptor */
X
X umdata.um_flags = MSDOWN|MSIN|MSOUT;
X /* rectangle in pixels */
X umdata.um_x = 0;
X umdata.um_y = 0;
X umdata.um_w = 100;
X umdata.um_h = 100;
X umdata.um_icon = 0; /* use system cursor icon */
X
X while (1)
X {
X rc = ioctl (0, WIOCSETMOUSE, &umdata);
X if (rc != 0)
X {
X if (debug)
X {
X fprintf (stderr,
X "\n[%s] %d=ioctl(%d,WIOCSETMOUSE) failed",
X __FILE__, rc, wd);
X fflush (stderr);
X }
X return (getch());
X }
X strcpy (kbuf, readkey ());
X if (kbuf[0] != (char)ESC)
X return ((int)kbuf[0]);
X if (debug)
X {
X fprintf (stderr, "\n[%s] mouse report = :%s:", __FILE__,
X kbuf+1);
X fflush (stderr);
X }
X
X /*
X ** screen size in pixels 720,288
X ** one char = 9x12 pixels
X ** Mouse reports take the form:
X ** ESC [ ? {x-pos} ; {y-pos} ; {buttons} ; {reason} M
X */
X sptr = strchr (kbuf, '?');
X sptr++;
X sscanf (sptr, "%d", &pcol);
X sptr = strchr (sptr, ';');
X sptr++;
X sscanf (sptr, "%d", &prow);
X /* convert from pixel to character row/col the mouse is on */
X *col = pcol / 9;
X *row = prow / 12;
X if (debug)
X {
X fprintf (stderr, "\n[%s] mouse row %d, col %d",
X __FILE__, *row, *col);
X fflush (stderr);
X }
X setoption (*row, *col); /* hi-light menu option */
X }
X}
X
X
X/*
X** readkey()
X** Returns:
X** the string of characters generated by a key
X*/
X#include <stdio.h>
X#include <signal.h>
X#include <ctype.h>
X
X
Xstatic int sig_caught;
X
Xchar *readkey ()
X{
X int (*oldsig)();
X int _Catch_Alarm();
X int oldalarm;
X char ch;
X int rc;
X static char keybuf[80];
X char *sptr;
X
X strcpy (keybuf, "");
X sptr = keybuf;
X *sptr = getch (); rc = 1;
X if (*sptr != 27) /* check for escape */
X {
X sptr++;
X *sptr = '\0';
X sptr = keybuf;
X return (sptr);
X }
X sptr++;
X
X /*
X ** check to see if this is a multi-char key
X ** loop until read returns -1 (no input) or
X ** a time out signal occurs indicating no more input
X **
X ** The best resolution we have is 1 second, so we set a 1 second alarm
X ** and try to read. If we fail for 1 second, we assume there is no
X ** key waiting. Problem here is that 1 second is too long, people
X ** can type faster than this.
X */
X while (rc == 1)
X {
X oldsig = signal (SIGALRM, _Catch_Alarm);
X oldalarm = alarm (1);
X sig_caught = 0;
X *sptr = getch (); rc = 1;
X if (sig_caught)
X {
X sig_caught = 0;
X alarm (oldalarm);
X rc = -2;
X }
X signal (SIGALRM, oldsig);
X alarm (oldalarm);
X sptr++;
X }
X sptr--;
X *sptr = '\0';
X sptr = keybuf;
X return (sptr);
X}
X
X_Catch_Alarm ()
X{
X sig_caught = 1;
X}
X#endif
X/* Paul J. Condie 5-90 */
SHAR_EOF
chmod 0644 mygetch.c || echo "restore of mygetch.c fails"
echo "x - extracting menu.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > menu.h &&
X#ifndef LINT
Xstatic char ID_menu[] = "%W% DeltaDate %G% ExtrDate %H%";
X#endif
X
X#define VERSION "3.63" /* current version */
X
X#ifndef BELL
X#define BELL printf ("%c", 7)
X#endif
X#ifndef BEEP
X#define BEEP printf ("%c", 7)
X#endif
X#ifndef NULL
X#define NULL 0
X#endif
X#define null 0
X#define MENUINIT ".menuinit" /* initialize filename */
X#define HELPFILE "menu.hlp"
X#define BORDERCHAR ' '
X#define MAXTITLE 6 /* maximum # of title lines */
X#define MAXKEYS 25 /* maximum # of keys */
X#define MAXKEYLENGTH 15 /* maximum length of keyword */
X#define MAXOPTION 60 /* max # of option 2b displayed */
X#define MAXMENU 20 /* max nested menus */
X#define MAXGNAME 20 /* max goto menu names */
X#define MAXLEN 2048 /* max length of option command */
X#define MAXSCREENS 10 /* max .DEFINE_SCREEN per menu */
X#define MAXFIELDS 40 /* max fields per .DEFINE_SCREEN */
X#define MAXTEXT 20 /* max # of text per .DEFINE_SCREEN */
X#define ErrRow (LINES-1) /* last line to print error message */
X#define GNAMEOFFSET 100 /* Offset return code for gnames */
X
X#define QUIT -1
X#define MAINMENU -2
X#define PREVIOUSMENU -3
X#define NOWAYJOSE -4 /* not authorized for menu */
X#define REPARSE -5 /* reparse & display the current menu */
X#define SUBMENU -99 /* a submenu was selected */
X
X#define BUFSIZE 512
X
X/* Line drawing types */
X#define DumbLine 1
X#define StandoutLine 2
X#define SingleLine 3
X#define MosaicLine 4
X#define DiamondLine 5
X#define DotLine 6
X#define PlusLine 7
X
X#define AUTO 999
X
X
X/*
X** Keys not defined in some curses.h
X*/
X
X#ifndef KEY_HELP
X# define KEY_HELP 0553
X#endif
X#ifndef KEY_REFRESH
X# define KEY_REFRESH 0565
X#endif
X#ifndef KEY_CANCEL
X# define KEY_CANCEL 0543
X#endif
X#ifndef KEY_TAB
X# define KEY_TAB '\t'
X#endif
X#ifndef KEY_BTAB
X# define KEY_BTAB 0541
X#endif
X#ifndef KEY_RETURN
X# define KEY_RETURN '\r'
X#endif
X#ifndef KEY_LINEFEED
X# define KEY_LINEFEED '\n'
X#endif
X#ifndef KEY_REFRESH
X# define KEY_REFRESH 0565
X#endif
X#ifndef KEY_BEG
X# define KEY_BEG 0542
X#endif
X#ifndef KEY_END
X# define KEY_END 0550
X#endif
X#ifndef KEY_ACCEPT
X#define KEY_ACCEPT 1000
X#endif
X#ifndef KEY_MAINMENU
X#define KEY_MAINMENU 1001
X#endif
X#ifndef KEY_PREVMENU
X#define KEY_PREVMENU 1002
X#endif
X#ifndef KEY_EXITMENU
X#define KEY_EXITMENU 1003
X#endif
X#ifndef KEY_POPGNAME
X#define KEY_POPGNAME 1004
X#endif
X#ifndef KEY_GNAME
X#define KEY_GNAME 1005
X#endif
X
X/*
X** MACROS
X*/
X
X#define SKIPJUNK(s) /* \
X ** This macro skips over spaces, tabs, etc. \
X ** ARGS: char *s \
X */ \
X for (;*s != '\0' && (isspace(*s)); s++) \
X ;
X
X
X/*
X** STRUCTURES
X*/
X
Xstruct MenuInfo
X{
X char name [15]; /* file name */
X int wfrow; /* window first row */
X int wlrow; /* window last row */
X int wfcol; /* window first col */
X int wlcol; /* window last col */
X int row_cursor; /* row for cursor */
X int col_cursor; /* col for cursor */
X unsigned boxtype; /* 0 = no box */
X unsigned linetype; /* same as box */
X int titlecount;
X int optioncount; /* base 0 */
X struct OptionInfo *option [MAXOPTION];
X struct ScreenInfo *srn [MAXSCREENS+1]; /* .DEFINE_SCREEN */
X /* NULL = EOL */
X char *after_menu; /* command to run */
X};
X
X
Xstruct OptionInfo
X{
X char keyword [MAXKEYLENGTH+1];
X int opnumber; /* option number */
X char description [200];
X char *command;
X int row; /* row to display */
X int col; /* col to display */
X};
X
Xstruct ScreenInfo
X{
X char name [31]; /* screen name */
X char title [100]; /* window title */
X int toprow; /* upper left corner */
X char toprowvar[40];
X int leftcol;
X char leftcolvar[40];
X int rows; /* # rows in win */
X int cols; /* # cols in win */
X unsigned boxtype; /* 0 = no box */
X int exitlastfield; /* after last field */
X int exitoncancel; /* only on KEY_CANCEL */
X char helpfile[16];
X struct TextInfo *textinfo[MAXTEXT+1]; /* text information */
X char *fielddefaults; /* init field command */
X char *after_screen; /* command to run */
X struct FieldInfo *field [MAXFIELDS+1];
X};
X
X
Xstruct FieldInfo
X{
X char name [30]; /* field name */
X char label [50]; /* field label */
X int row; /* start position */
X int col;
X int length;
X int min_input;
X char mask [100];
X char range [MAXLEN];
X char type;
X char adjust;
X int mustenter;
X char prompt [100];
X char terminator[3]; /* field terminators */
X int noinput;
X char *before_field; /* before command */
X char *after_field; /* after command */
X};
X
Xstruct TextInfo
X{
X int row; /* row to display txt */
X int col; /* col to diplay txt */
X char *text; /* the text */
X};
SHAR_EOF
chmod 0644 menu.h || echo "restore of menu.h fails"
echo "x - extracting terminal.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > terminal.h &&
X#ifndef LINT
Xstatic char ID_terminal[] = "@(#)terminal.h 1.7 DeltaDate 1/22/90 ExtrDate 1/22/90";
X#endif
X
X/* Mover Keys */
Xextern int KeyReturn;
Xextern int KeyDown;
Xextern int KeyUp;
Xextern int KeyTab;
Xextern int KeyBTab;
X
X/* Edit Keys */
Xextern int KeyBeg;
Xextern int KeyEnd;
Xextern int KeyRight;
Xextern int KeyLeft;
Xextern int KeyBackspace;
Xextern int KeyEOL;
Xextern int KeyDL;
Xextern int KeyDC;
Xextern int KeyIC;
X
X/* Other Keys */
Xextern int KeyHelp;
Xextern int KeyRedraw;
Xextern int KeyCancel;
Xextern int KeySave;
Xextern int KeyPrint;
Xextern int KeyAccept;
X
X
X/* Menu Specific Keys */
Xextern int KeyMainMenu;
Xextern int KeyPrevMenu;
Xextern int KeyExitMenu;
Xextern int KeyGname;
Xextern int KeyPopGname;
SHAR_EOF
chmod 0444 terminal.h || echo "restore of terminal.h fails"
echo "x - extracting LexDeSrn.l (Text)"
sed 's/^X//' << 'SHAR_EOF' > LexDeSrn.l &&
X%{
X#ifndef LINT
Xstatic char Sccsid[] = "%W% DeltaDate %G% ExtrDate %H%";
X#endif
X%}
X
X%{
X#include "y.tab.h"
X#include "menu.h"
X
X#undef YYLMAX
X#define YYLMAX MAXLEN
X
Xchar *malloc();
X%}
X%%
X%{
X/*
X** Operators:
X** " \ [ ] ^ - ? . * + | ( ) $ / { } % < >
X** - match a range
X** ^ match all except or match begining of line if outside []
X** . match any character except \n
X** ? optional ab?c matches ac or abc
X** | alternation ab|cd matches either ab or cd
X** $ match end of line
X** / trailing context ab/cd matches ab only if followed by cd
X** <> start conditions
X** {} repetitions a{1,5} or definition expansion {abc}
X** % separator for source segments
X**
X** object match one occurence of object
X** object* matches zero or more occurrences of object
X** object+ matches one or more occurrences of object
X** object{m,n} match m through n occurrences of object
X*/
X%}
X
X%{ /* Screen Stuff
X%}
X"window_rows" return (SCREEN_ROWS);
X"window_title" return (SCREEN_TITLE);
X"window_cols" return (SCREEN_COLS);
X"window_border" return (SCREEN_BORDER);
X"window_pos" return (SCREEN_POS);
X"helpfile" return (SCREEN_HELP);
X"exit_last_field" return (EXIT_LAST_FIELD);
X"exit_on_cancel" return (EXIT_ON_CANCEL);
X"text" return (SCREEN_TEXT);
X"field_defaults" return (FIELD_DEFAULTS);
X"after_screen" return (AFTER_SCREEN);
X
X%{ /* Field Stuff
X%}
X"field_name" return(FIELD_NAME);
X"field_label" return(FIELD_LABEL);
X"field_row" return (FIELD_ROW);
X"field_col" return (FIELD_COL);
X"field_mask" return (FIELD_MASK);
X"field_range" return (FIELD_RANGE);
X"field_length" return (FIELD_LENGTH);
X"field_min" return (FIELD_MIN);
X"field_type" return (FIELD_TYPE);
X"field_edits" return (FIELD_TYPE);
X"field_adjust" return (FIELD_ADJUST);
X"field_mustenter" return (FIELD_MUSTENTER);
X"field_prompt" return (FIELD_PROMPT);
X"field_terminator" return (FIELD_TERMINATOR);
X"field_noinput" return (FIELD_NOINPUT);
X"before_field" return (BEFORE_FIELD);
X"after_field" return (AFTER_FIELD);
X
X"ENDSCREEN" return(0);
X
X
X%{ /* Comment line */
X%}
X### { while (input() != '\n'); }
X
X[0-9]+ {
X yylval.number = atoi (yytext);
X return (NUMBER);
X }
X
X%{ /* Alphanumeric string with a leading $ and alphabetic character. */
X%}
X[$][A-Za-z][A-Za-z0-9_\[\]]* {
X yylval.string = malloc(strlen(yytext)+1);
X strcpy(yylval.string,yytext);
X return (EVAR);
X }
X
X%{ /* Alphanumeric string with a leading alphabetic character. */
X%}
X[A-Za-z][A-Za-z0-9_]* {
X yylval.string = malloc(strlen(yytext)+1);
X strcpy(yylval.string,yytext);
X return (STRING);
X }
X
X%{/* Quoted string with a possible " in the string. ex. "abc\"def" */
X%}
X\"[^"]* {
X if (yytext[yyleng-1] == '\\')
X {
X yymore ();
X }
X else
X {
X int i,j;
X /*
X ** need to validate that it is a quote
X ** a core dump will occur if not.
X */
X input (); /* get last " */
X yylval.string=malloc(strlen(yytext)+1);
X for (j=0,i=1; i < strlen(yytext); i++)
X {
X if (yytext[i] == '\\' &&
X yytext[i+1] == '"')
X continue;
X yylval.string[j++] = yytext[i];
X }
X yylval.string[j] = '\0';
X return (QUOTE_STRING);
X }
X }
X
X"," return (COMMA);
X"=" return (EQUAL);
X%{/* Ignore blank, tab, newline */
X%}
X[ \t\n] ;
X%%
SHAR_EOF
chmod 0644 LexDeSrn.l || echo "restore of LexDeSrn.l fails"
echo "x - extracting menu.hlp (Text)"
sed 's/^X//' << 'SHAR_EOF' > menu.hlp &&
XTABLE_OF_CONTENTS
Xmenu.hlp menu Menus - Help using menus.
Xmenu.hlp popmenu Pop-menus - Help using popmenus.
Xmenu.hlp GETINPUT Input - Editing commands.
Xmenu.hlp help Help - Using help.
XTABLE_OF_CONTENTS
X
X
Xmenu
X.TITLE Menu Help
X
X \RMENU COMMANDS:\N
X m \D- Go directly to main menu.\N
X p \D- Return to previous menu.\N
X g or ^g \D- Go directly to a specific menu.\N
X h or ? \D- This help screen.\N
X ^r \D- Redraw the screen.\N
X e \D- Exit.\N
X ! \D- Enter a unix command.\N
X
X \RSELECTING OPTIONS:\N
X - Use "up arrow key", "^k", "down arrow key", "^j" or
X "tab key" to place bar on option and press "return".
X
X or
X
X - Enter option number and press "return".
X
Xmenu
X
X
Xpopmenu
X.TITLE Pop-Up Menu Help
XSELECTING OPTIONS:
X Use "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
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
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.
X KEY_TOC (^t) Display help table of contents.
Xhelp
SHAR_EOF
chmod 0644 menu.hlp || echo "restore of menu.hlp fails"
echo "x - extracting runrealid.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > runrealid.c &&
X#ifndef LINT
Xstatic char Sccsid[] = "@(#)runrealid.c 1.1 DeltaDate 1/22/90 ExtrDate 1/22/90";
X#endif
X
X#include <stdio.h>
X
Xmain ( argc, argv )
X int argc;
X char *argv[];
X{
X register int uid, euid, gid, egid ;
X
X /* who am i */
X uid = getuid() ;
X euid = geteuid() ;
X gid = getgid() ;
X egid = getegid() ;
X
X /* reset back to the read id */
X setuid( uid ) ;
X setgid( gid ) ;
X
X system( argv[1] ) ;
X
X /* reset back to the fake id */
X setuid( euid ) ;
X setgid( egid ) ;
X}
X/* Sam S. Lok 11/89 */
SHAR_EOF
chmod 0444 runrealid.c || echo "restore of runrealid.c fails"
echo "x - extracting ParseDeSrn.y (Text)"
sed 's/^X//' << 'SHAR_EOF' > ParseDeSrn.y &&
X%{
X#ifndef LINT
Xstatic char Sccsid[] = "%W% DeltaDate %G% ExtrDate %H%";
X#endif
X%}
X
X%{
X#include <curses.h>
X#include "GetInput.h"
X#include "menu.h"
X
X#define FLD yyscreen->field[fieldcount-1]
X
X#ifdef _yydebug
Xextern int yydebug;
X#endif
Xextern int debug;
Xstruct ScreenInfo *yyscreen;
Xint fieldcount;
Xchar eott[50]; /* error on this token */
Xchar *malloc();
Xint textcount; /* # of text(s) */
X%}
X%{
X/*
X** The %union declares yylval and the Yacc value stack as a C language
X** union of types specified in the body.
X**
X** The %type assigns member declared in the %union to non-terminals.
X** The %token <..> assigns member declared in the %union to terminals.
X*/
X%}
X%union{
X int number;
X char *string;
X}
X
X%token <number> NUMBER
X%token <string> STRING
X%token <string> QUOTE_STRING
X%token <string> EVAR
X%token COMMA EQUAL
X%token SCREEN_TITLE SCREEN_ROWS SCREEN_COLS SCREEN_BORDER SCREEN_POS
X%token SCREEN_HELP EXIT_LAST_FIELD EXIT_ON_CANCEL SCREEN_TEXT AFTER_SCREEN
X%token FIELD_NAME FIELD_LABEL FIELD_ROW FIELD_COL FIELD_MASK FIELD_RANGE
X%token FIELD_LENGTH FIELD_MIN FIELD_TYPE FIELD_ADJUST FIELD_MUSTENTER
X%token FIELD_TERMINATOR FIELD_PROMPT FIELD_DEFAULTS FIELD_NOINPUT
X%token BEFORE_FIELD AFTER_FIELD
X
X%%
X
X
Xscreen : valid_field
X | screen valid_field
X | screen COMMA valid_field
X ;
X
Xvalid_field : screen_pos
X {
X strcpy (eott, "window_pos");
X if (debug)
X {
X fprintf (stderr,
X "\n[ParseDeSrn]<.DEFINE_SCREEN> window_pos");
X fflush (stderr);
X }
X }
X ;
X | screen_rows
X {
X strcpy (eott, "window_rows");
X if (debug)
X {
X fprintf (stderr,
X "\n[ParseDeSrn]<.DEFINE_SCREEN> window_rows");
X fflush (stderr);
X }
X }
X ;
X | screen_cols
X {
X strcpy (eott, "window_cols");
X if (debug)
X {
X fprintf (stderr,
X "\n[ParseDeSrn]<.DEFINE_SCREEN> window_cols");
X fflush (stderr);
X }
X }
X ;
X | screen_border
X {
X strcpy (eott, "window_border");
X if (debug)
X {
X fprintf (stderr,
X "\n[ParseDeSrn]<.DEFINE_SCREEN> window_border");
X fflush (stderr);
X }
X }
X ;
X | screen_title
X {
X strcpy (eott, "window_title");
X if (debug)
X {
X fprintf (stderr,
X "\n[ParseDeSrn]<.DEFINE_SCREEN> window_title");
X fflush (stderr);
X }
X }
X ;
X | screen_help
X {
X strcpy (eott, "helpfile");
X if (debug)
X {
X fprintf (stderr,
X "\n[ParseDeSrn]<.DEFINE_SCREEN> helpfile");
X fflush (stderr);
X }
X }
X ;
X | exit_last_field
X {
X strcpy (eott, "exit_last_field");
X if (debug)
X {
X fprintf (stderr,
X "\n[ParseDeSrn]<.DEFINE_SCREEN> exit_last_field");
X fflush (stderr);
X }
X }
X ;
X | exit_on_cancel
X {
X strcpy (eott, "exit_on_cancel");
X if (debug)
X {
X fprintf (stderr,
X "\n[ParseDeSrn]<.DEFINE_SCREEN> exit_on_cancel");
X fflush (stderr);
X }
X }
X ;
X | screen_text
X {
X strcpy (eott, "text");
X if (debug)
X {
X fprintf (stderr,
X "\n[ParseDeSrn]<.DEFINE_SCREEN> text");
X fflush (stderr);
X }
X }
X ;
X | after_screen
X {
X strcpy (eott, "after_screen");
X if (debug)
X {
X fprintf (stderr,
X "\n[ParseDeSrn]<.DEFINE_SCREEN> after_screen");
X fflush (stderr);
X }
X }
X ;
X
X | field_name
X {
X strcpy (eott, "field_name");
X if (debug)
X {
X fprintf (stderr,
X "\n[ParseDeSrn]<.DEFINE_SCREEN> field_name");
X fflush (stderr);
X }
X }
X ;
X | field_label
X {
X strcpy (eott, "field_label");
X if (debug)
X {
X fprintf (stderr,
X "\n[ParseDeSrn]<.DEFINE_SCREEN> field_label");
X fflush (stderr);
X }
X }
X ;
X | field_row
X {
X strcpy (eott, "field_row");
X if (debug)
X {
X fprintf (stderr,
X "\n[ParseDeSrn]<.DEFINE_SCREEN> field_row");
X fflush (stderr);
X }
X }
X ;
X | field_col
X {
X strcpy (eott, "field_col");
X if (debug)
X {
X fprintf (stderr,
X "\n[ParseDeSrn]<.DEFINE_SCREEN> field_col");
X fflush (stderr);
X }
X }
X ;
X | field_mask
X {
X strcpy (eott, "field_mask");
X if (debug)
X {
X fprintf (stderr,
X "\n[ParseDeSrn]<.DEFINE_SCREEN> field_mask");
X fflush (stderr);
X }
X }
X ;
X | field_range
X {
X strcpy (eott, "field_range");
X if (debug)
X {
X fprintf (stderr,
X "\n[ParseDeSrn]<.DEFINE_SCREEN> field_range");
X fflush (stderr);
X }
X }
X ;
X | field_length
X {
X strcpy (eott, "field_length");
X if (debug)
X {
X fprintf (stderr,
X "\n[ParseDeSrn]<.DEFINE_SCREEN> field_length");
X fflush (stderr);
X }
X }
X ;
X | field_min
X {
X strcpy (eott, "field_min");
X if (debug)
X {
X fprintf (stderr,
X "\n[ParseDeSrn]<.DEFINE_SCREEN> field_min");
X fflush (stderr);
X }
X }
X ;
X | field_type
X {
X strcpy (eott, "field_edits");
X if (debug)
X {
X fprintf (stderr,
X "\n[ParseDeSrn]<.DEFINE_SCREEN> field_edits");
X fflush (stderr);
X }
X }
X ;
X | field_adjust
X {
X strcpy (eott, "field_adjust");
X if (debug)
X {
X fprintf (stderr,
X "\n[ParseDeSrn]<.DEFINE_SCREEN> field_adjust");
X fflush (stderr);
X }
X }
X ;
X | field_mustenter
X {
X strcpy (eott, "field_mustenter");
X if (debug)
X {
X fprintf (stderr,
SHAR_EOF
echo "End of part 7"
echo "File ParseDeSrn.y is continued in part 8"
echo "8" > s2_seq_.tmp
exit 0
More information about the Alt.sources
mailing list