From: pjc@pcbox.UUCP (Paul J. Condie) Newsgroups: alt.sources Subject: menu(1) part 4 of 11 Message-ID: <426@pcbox.UUCP> Date: 6 Apr 90 17:38:48 GMT #!/bin/sh # this is part 4 of a multipart archive # do not concatenate these parts, unpack them in order with /bin/sh # file ParseTitle.c continued # CurArch=4 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 ParseTitle.c" sed 's/^X//' << 'SHAR_EOF' >> ParseTitle.c X#ifdef ALARM X if (MAILCALL) X checkmail (); X#endif X return (0); X} SHAR_EOF echo "File ParseTitle.c is complete" chmod 0444 ParseTitle.c || echo "restore of ParseTitle.c fails" echo "x - extracting ParseBox.c (Text)" sed 's/^X//' << 'SHAR_EOF' > ParseBox.c && Xstatic char Sccsid[] = "@(#)ParseBox.c 1.7 DeltaDate 1/22/90 ExtrDate 1/22/90"; X X/* FUNCTION: ParseBox() X** Parses keyword ".BOX". X** ARGS: keyword the keyword "BOX" X** menufile the unix menu file X** menu menu structure X** gnames holder of goto menu names X** gfiles holder of goto menu names (menu file) X** gindex # of gnames X*/ X X#include X#include X#include "menu.h" X X XParseBox (keyword, menufile, menu, KeyWord, ParseKey, gnames, gfiles, X gindex, opnumber) X X char keyword[]; X FILE *menufile; X struct MenuInfo *menu; X char KeyWord[][MAXKEYLENGTH]; X int (*ParseKey[])(); X char gnames[][15], gfiles[][15]; X int *gindex; X int *opnumber; X{ X char *fgets(), line[BUFSIZE+1]; X char boxtype[30]; X char *sptr; X X /* Default Values */ X menu->boxtype = StandoutLine; X menu->boxtype = menu->boxtype | (DumbLine << 9); X X fgets (line, BUFSIZE, menufile); X sptr = line; X SKIPJUNK(sptr); X X /* get border type for active menu */ X sscanf (sptr, "%s", boxtype); X sptr += strlen(boxtype); X if (strcmp (boxtype, "DumbLine") == 0) X menu->boxtype = DumbLine; X else if (strcmp (boxtype, "StandoutLine") == 0) X menu->boxtype = StandoutLine; X else if (strcmp (boxtype, "SingleLine") == 0 || X strcmp (boxtype, "DrawLine") == 0) X menu->boxtype = SingleLine; X else if (strcmp (boxtype, "MosaicLine") == 0) X menu->boxtype = MosaicLine; X else if (strcmp (boxtype, "DiamondLine") == 0) X menu->boxtype = DiamondLine; X else if (strcmp (boxtype, "DotLine") == 0) X menu->boxtype = DotLine; X else if (strcmp (boxtype, "PlusLine") == 0) X menu->boxtype = PlusLine; X X /* get border type for inactive menu - dim (high 8 bits) */ X sscanf (sptr, "%s", boxtype); X sptr += strlen(boxtype); X if (strcmp (boxtype, "DumbLine") == 0) X menu->boxtype = menu->boxtype | (DumbLine << 9); X else if (strcmp (boxtype, "StandoutLine") == 0) X menu->boxtype = menu->boxtype | (DumbLine << 9); X else if (strcmp (boxtype, "SingleLine") == 0 || X strcmp (boxtype, "DrawLine") == 0) X menu->boxtype = menu->boxtype | (SingleLine << 9); X else if (strcmp (boxtype, "MosaicLine") == 0) X menu->boxtype = menu->boxtype | (MosaicLine << 9); X else if (strcmp (boxtype, "DiamondLine") == 0) X menu->boxtype = menu->boxtype | (DiamondLine << 9); X else if (strcmp (boxtype, "DotLine") == 0) X menu->boxtype = menu->boxtype | (DotLine << 9); X else if (strcmp (boxtype, "PlusLine") == 0) X menu->boxtype = menu->boxtype | (PlusLine << 9); X X drawbox (stdscr, 1,1, LINES-1,COLS, menu->boxtype & 0777, StandoutLine, X FALSE, FALSE); X return (0); X} SHAR_EOF chmod 0444 ParseBox.c || echo "restore of ParseBox.c fails" echo "x - extracting ParseWindo.c (Text)" sed 's/^X//' << 'SHAR_EOF' > ParseWindo.c && Xstatic char Sccsid[] = "@(#)ParseWindo.c 1.4 DeltaDate 11/13/88 ExtrDate 1/22/90"; X X/* FUNCTION: ParseWindow() X** Parses keyword ".WINDOW". X** ARGS: keyword the keyword "WINDOW" X** menufile the unix menu file X** menu menu structure X** gnames holder of goto menu names X** gfiles holder of goto menu names (menu file) X** gindex # of gnames X** RETURNS: 0 X*/ X X#include X#include "menu.h" X Xextern int swin, ewin, longest; X XParseWindow (keyword, menufile, menu, KeyWord, ParseKey, gnames, gfiles, X gindex, opnumber) X X char keyword[]; X FILE *menufile; X struct MenuInfo *menu; X char KeyWord[][MAXKEYLENGTH]; X int (*ParseKey[])(); X char gnames[][15], gfiles[][15]; X int *gindex; X int *opnumber; X{ X int i, j, row, col; X char line[BUFSIZE]; X X X EndWindow (menu); X X fscanf (menufile, "%d", &menu->wfrow); X if (menu->wfrow < 0) menu->wfrow = 0; X if (menu->wfrow < menu->titlecount) menu->wfrow = menu->titlecount; X if (menu->wfrow > LINES-1) menu->wfrow = LINES-1; X fscanf (menufile, "%d", &menu->wlrow); X if (menu->wlrow < 0) menu->wlrow = 0; X if (menu->wlrow > LINES-1) menu->wlrow = LINES-1; X fscanf (menufile, "%d", &menu->wfcol); X if (menu->wfcol < 0) menu->wfcol = 0; X if (menu->wfcol > COLS-1) menu->wfcol = COLS-1; X fscanf (menufile, "%d", &menu->wlcol); X if (menu->wlcol < 0) menu->wlcol = 0; X if (menu->wlcol > COLS-1) menu->wlcol = COLS-1; X X/* X** Now lets read in the window heading. X*/ X fgets (line, BUFSIZE+1, menufile); X line[strlen(line)-1] = '\0'; X X/* X** Determine where to display heading. X*/ X for (i = 0, j = 0; line[i] != '\0'; i++) X if (line[i] == '\\') j++; X row = menu->wfrow - 1; X col = (menu->wlcol - menu->wfcol)/2-(strlen(line)-1-j*2)/2 + menu->wfcol; X col -= (((strlen(line)-1-j*2) % 2) == 0) ? 0 : 1; X if (strlen(line) > 0) displaytext (row, col, line+1); X X longest = 0; X swin = ewin; X return (0); X} SHAR_EOF chmod 0444 ParseWindo.c || echo "restore of ParseWindo.c fails" echo "x - extracting ParseLine.c (Text)" sed 's/^X//' << 'SHAR_EOF' > ParseLine.c && Xstatic char Sccsid[] = "@(#)ParseLine.c 1.6 DeltaDate 1/22/90 ExtrDate 1/22/90"; X X/* FUNCTION: ParseLine() X** Parses keyword "LINE". X** ARGS: keyword the keyword "LINE" X** menufile the unix menu file X** menu menu structure X** gnames holder of goto menu names X** gfiles holder of goto menu names (menu file) X** gindex # of gnames X*/ X X#include X#include X#include "menu.h" X X X XParseLine (keyword, menufile, menu, KeyWord, ParseKey, gnames, gfiles, X gindex, opnumber) X X char keyword[]; X FILE *menufile; X struct MenuInfo *menu; X char KeyWord[][MAXKEYLENGTH]; X int (*ParseKey[])(); X char gnames[][15], gfiles[][15]; X int *gindex; X int *opnumber; X{ X int col; X char *fgets(), line[BUFSIZE+1]; X char linetype[30]; X char *sptr; X X X /* default values */ X menu->linetype = StandoutLine; X menu->linetype = menu->linetype | (DumbLine << 9); X X fgets (line, BUFSIZE, menufile); X sptr = line; X SKIPJUNK(sptr); X X /* get border type for active menu */ X sscanf (sptr, "%s", linetype); X sptr += strlen(linetype); X if (strcmp (linetype, "DumbLine") == 0) X menu->linetype = DumbLine; X else if (strcmp (linetype, "StandoutLine") == 0) X menu->linetype = StandoutLine; X else if (strcmp (linetype, "SingleLine") == 0 || X strcmp (linetype, "DrawLine") == 0) X menu->linetype = SingleLine; X else if (strcmp (linetype, "MosaicLine") == 0) X menu->linetype = MosaicLine; X else if (strcmp (linetype, "DiamondLine") == 0) X menu->linetype = DiamondLine; X else if (strcmp (linetype, "DotLine") == 0) X menu->linetype = DotLine; X else if (strcmp (linetype, "PlusLine") == 0) X menu->linetype = PlusLine; X X /* get border type for inactive menu - dim (high 8 bits) */ X sscanf (sptr, "%s", linetype); X sptr += strlen(linetype); X if (strcmp (linetype, "DumbLine") == 0) X menu->linetype = menu->linetype | (DumbLine << 9); X else if (strcmp (linetype, "StandoutLine") == 0) X menu->linetype = menu->linetype | (DumbLine << 9); X else if (strcmp (linetype, "SingleLine") == 0 || X strcmp (linetype, "DrawLine") == 0) X menu->linetype = menu->linetype | (SingleLine << 9); X else if (strcmp (linetype, "MosaicLine") == 0) X menu->linetype = menu->linetype | (MosaicLine << 9); X else if (strcmp (linetype, "DiamondLine") == 0) X menu->linetype = menu->linetype | (DiamondLine << 9); X else if (strcmp (linetype, "DotLine") == 0) X menu->linetype = menu->linetype | (DotLine << 9); X else if (strcmp (linetype, "PlusLine") == 0) X menu->linetype = menu->linetype | (PlusLine << 9); X X drawline (stdscr, menu->titlecount, menu->linetype&0777, StandoutLine, X menu->boxtype); X X menu->titlecount++; X return (0); X} SHAR_EOF chmod 0444 ParseLine.c || echo "restore of ParseLine.c fails" echo "x - extracting ParseComnt.c (Text)" sed 's/^X//' << 'SHAR_EOF' > ParseComnt.c && Xstatic char Sccsid[] = "@(#)ParseComnt.c 1.5 DeltaDate 11/13/88 ExtrDate 1/22/90"; X X/* FUNCTION: ParseComnt() X** Parses keyword "###". X## A comment line. X** ARGS: keyword the keyword "###" X** menufile the unix menu file X** menu menu structure X** gnames holder of goto menu names X** gfiles holder of goto menu names (menu file) X** gindex # of gnames X*/ X X#include X#include "menu.h" X X XParseComnt (keyword, menufile, menu, KeyWord, ParseKey, gnames, gfiles, X gindex, opnumber) X X char keyword[]; X FILE *menufile; X struct MenuInfo *menu; X char KeyWord[][MAXKEYLENGTH]; X int (*ParseKey[])(); X char gnames[][15], gfiles[][15]; X int *gindex; X int *opnumber; X{ X char *fgets(), line[BUFSIZE+1]; X X X fgets (line, BUFSIZE, menufile); X return (0); X} SHAR_EOF chmod 0444 ParseComnt.c || echo "restore of ParseComnt.c fails" echo "x - extracting ParseUnix.c (Text)" sed 's/^X//' << 'SHAR_EOF' > ParseUnix.c && Xstatic char Sccsid[] = "@(#)ParseUnix.c 1.5 DeltaDate 1/22/90 ExtrDate 1/22/90"; X X/* FUNCTION: ParseUnix() X** Parses keyword ".unix". X** ARGS: keyword the keyword "unix" X** menufile the unix menu file X** menu menu structure X** gnames holder of goto menu names X** gfiles holder of goto menu names (menu file) X** gindex # of gnames X** RETURNS: none X*/ X X#include X#include X#include "menu.h" X Xextern int debug; X X X XParseUnix (keyword, menufile, menu, KeyWord, ParseKey, gnames, gfiles, X gindex, opnumber) X X char keyword[]; X FILE *menufile; X struct MenuInfo *menu; X char KeyWord[][MAXKEYLENGTH]; X int (*ParseKey[])(); X char gnames[][15], gfiles[][15]; X int *gindex; X int *opnumber; X{ X char command[MAXLEN+1]; X int rc; X char *comptr; X char tmpstr[80]; X int redrawflag = FALSE; X X X X /* X ** Read in option command X ** strcat continuation lines X */ X fgets (command, MAXLEN, menufile); X command[strlen(command)-1] = '\0'; /* get rid of \n */ X while (command[strlen(command)-1] == '\\') X { X if (strlen(command) > MAXLEN) X { X BEEP; X mvprintw (ErrRow-2, 0, X ".UNIX command is too long. Max = %d",MAXLEN); X shutdown (); X } X command[strlen(command)-1] = '\n'; /* replace \ with \n */ X fgets (command+strlen(command), MAXLEN, menufile); X command[strlen(command)-1] = '\0'; /* get rid of \n */ X } X X comptr = command; X SKIPJUNK(comptr); X sscanf (comptr, "%s", tmpstr); /* do we have a REDRAW */ X if (strcmp (tmpstr, "REDRAW") == 0) X { X redrawflag = TRUE; X comptr += strlen(tmpstr); X SKIPJUNK(comptr); X sscanf (comptr, "%s", tmpstr); /* do we have a GETINPUT */ X } X X if (strcmp (tmpstr, "GETINPUT") == 0) X { X /* get screen name */ X comptr += strlen(tmpstr); X SKIPJUNK(comptr); X sscanf (comptr, "%s", tmpstr); /* screen name */ X comptr += strlen(tmpstr); X SKIPJUNK(comptr); /* sitting at system(3) */ X rc = runscreen (tmpstr, menu, *opnumber); X if (rc == KEY_CANCEL) X return (0); X } X X reset_shell_mode (); X rc = system (comptr); X reset_prog_mode (); X X /* X ** Going from a shell return code (char) to a c return code (int) X ** the shell return code gets put in the high byte. So we will X ** shift the int right 8 bytes. X */ X rc = rc >> 8; /* to get shell rc */ X if (debug) X { X fprintf (stderr, "\n[%s] <%s> rc=%d command=%s", X __FILE__, keyword, rc, comptr); X fflush (stderr); X } X X /* X ** Shell can't handle negative return codes so we will convert X ** the return code to negative so menu can use it. X ** -1 = QUIT X ** -2 = MAINMENU X ** -3 = PREVMENU X ** -4 = NOWAYJOSE X ** 100+offset = GNAME X */ X if (rc < GNAMEOFFSET) X rc -= rc * 2; /* make negative */ X X if (redrawflag) X clearok (stdscr, TRUE); X X return (rc); X} X/* Paul J. Condie 12/88 */ SHAR_EOF chmod 0444 ParseUnix.c || echo "restore of ParseUnix.c fails" echo "x - extracting ParseGname.c (Text)" sed 's/^X//' << 'SHAR_EOF' > ParseGname.c && Xstatic char Sccsid[] = "@(#)ParseGname.c 1.5 DeltaDate 11/13/88 ExtrDate 1/22/90"; X X/* FUNCTION: ParseGname() X** Parses keyword ".GNAME". X** ARGS: keyword the keyword "GNAME" X** menufile the unix menu file X** menu menu structure X** gnames holder of goto menu names X** gfiles holder of goto menu names (menu file) X** gindex # of gnames X*/ X X#include X#include "menu.h" X X X XParseGname (keyword, menufile, menu, KeyWord, ParseKey, gnames, gfiles, X gindex, opnumber) X X char keyword[]; X FILE *menufile; X struct MenuInfo *menu; X char KeyWord[][MAXKEYLENGTH]; X int (*ParseKey[])(); X char gnames[][15], gfiles[][15]; X int *gindex; X int *opnumber; X{ X char name[BUFSIZE+1]; X char file[BUFSIZE+1]; X int i; X int NameFound; X X X if (*gindex >= MAXGNAME) X { X BEEP; X mvprintw (20, 0, X "Exceeded maximum (%d) number of goto menu names", X MAXGNAME-1); X shutdown (); X } X fscanf (menufile, "%s %s", name, file); X if (strlen(name) >= 15 || strlen(file) >= 15) X { X BEEP; X mvprintw (20, 0, X "The goto menu name and the goto menu file is limited to 14 characters"); X shutdown (); X } X X /* Check if we already have this menu name */ X NameFound = FALSE; X for (i = 0; i < *gindex; i++) X { X if (strcmp (name, gnames[i]) == 0) X { X NameFound = TRUE; X strcpy (gfiles[i], file); /* new menu file */ X } X } X if (!NameFound) X { X /* a new name */ X strcpy (gnames[*gindex], name); X strcpy (gfiles[*gindex], file); X (*gindex)++; X strcpy (gnames[*gindex], ""); /* null last one */ X } X fgets (name, BUFSIZE, menufile); /* junk rest of line */ X return (0); X} SHAR_EOF chmod 0444 ParseGname.c || echo "restore of ParseGname.c fails" echo "x - extracting ParseAuthr.c (Text)" sed 's/^X//' << 'SHAR_EOF' > ParseAuthr.c && Xstatic char Sccsid[] = "@(#)ParseAuthr.c 1.5 DeltaDate 1/22/90 ExtrDate 1/22/90"; X X/* FUNCTION: ParseAuthr() X** Parses keyword "AUTHORIZE". X** This function determines whether you are authorized X** to run this menu or not. X** ARGS: keyword the keyword "AUTHORIZE" X** menufile the unix menu file X** menu menu structure X** gnames holder of goto menu names X** gfiles holder of goto menu names (menu file) X** gindex # of gnames X** RETURNS: 0 you are authorized X** NOWAYJOSE nowayjose X*/ X X#include X#include X#include "menu.h" X X X XParseAuthr (keyword, menufile, menu, KeyWord, ParseKey, gnames, gfiles, X gindex, opnumber) X X char keyword[]; X FILE *menufile; X struct MenuInfo *menu; X char KeyWord[][MAXKEYLENGTH]; X int (*ParseKey[])(); X char gnames[][15], gfiles[][15]; X int *gindex; X int *opnumber; X{ X char *strchr(); X char line[MAXLEN+100], *lptr, word[15]; X char user[15]; X int OKflag; X struct passwd *getpwuid(); X struct passwd *pw; /* password entry */ X X X pw = getpwuid (getuid()); /* get real uid */ X strcpy (user, pw->pw_name); X X /* X ** Read in option command X ** strcat continuation lines X */ X fgets (line, BUFSIZE, menufile); X line[strlen(line)-1] = '\0'; /* get rid of \n */ X while (line[strlen(line)-1] == '\\') X { X if (strlen(line) >= MAXLEN) X { X BEEP; X mvprintw (ErrRow-2, 0, X "Option command is too long. Max = %d",MAXLEN); X shutdown (); X } X line[strlen(line)-1] = '\0'; /* junk \ */ X fgets (line+strlen(line), BUFSIZE, menufile); X line[strlen(line)-1] = '\0'; /* get rid of \n */ X } X X lptr = line; X OKflag = FALSE; X while (lptr && (sscanf (lptr, "%s", word) == 1)) X { X if (strcmp (user, word) == 0) X { X OKflag = TRUE; X break; X } X lptr = strchr (++lptr, ' '); X } X X if (!OKflag) X return (NOWAYJOSE); X return (0); X} SHAR_EOF chmod 0444 ParseAuthr.c || echo "restore of ParseAuthr.c fails" echo "x - extracting ParseText.c (Text)" sed 's/^X//' << 'SHAR_EOF' > ParseText.c && X#ifndef LINT Xstatic char Sccsid[] = "@(#)ParseText.c 1.6 DeltaDate 1/22/90 ExtrDate 1/22/90"; X#endif X X/* FUNCTION: ParseText() X** Parses keyword "TEXT". X** ARGS: keyword the keyword "TEXT" X** menufile the unix menu file X** menu menu structure X** gnames holder of goto menu names X** gfiles holder of goto menu names (menu file) X** gindex # of gnames X** RETURNS: 0 X*/ X X#include X#include X#include "menu.h" X X XParseText (keyword, menufile, menu, KeyWord, ParseKey, gnames, gfiles, X gindex, opnumber) X X char keyword[]; X FILE *menufile; X struct MenuInfo *menu; X char KeyWord[][MAXKEYLENGTH]; X int (*ParseKey[])(); X char gnames[][15], gfiles[][15]; X int *gindex; X int *opnumber; X{ X char *fgets(), line[BUFSIZE+1]; X char *getval(); X int row; X int col; X char fline[BUFSIZE+1]; /* formated line */ X int j; X int i; X char *ws; X X fgets (line, BUFSIZE, menufile); /* read row, col */ X ws = line; X SKIPJUNK (ws); X sscanf (ws, "%s", fline); /* get row */ X row = strcmp (fline, "-0") == 0 ? LINES : atoi(fline); X ws += strlen(fline); X SKIPJUNK (ws); X sscanf (ws, "%s", fline); /* get col */ X col = strcmp (fline, "-0") == 0 ? COLS : atoi(fline); X X fgets (line, BUFSIZE, menufile); /* read text */ X line[strlen(line)-1] = '\0'; X for (j = 0, i = 0; i < strlen (line); j++, i++) X if (line[i] == '$') X { X char *sptr, *b4ptr; X X sptr = b4ptr = line+i; X strcpy (fline+j, getval (&sptr, '$')); X i += (int)(sptr - b4ptr); X j += strlen (fline+j) - 1; X i--; X } X else X { X fline[j] = line[i]; X } X fline[j] = '\0'; X X /* X ** If the row or column is negative X ** then we use relative addressing X ** the row or col is subtracted from # of rows on screen. X */ X if (row < 0) X row = abs(row) > LINES ? LINES-1 : LINES+row-1; X else X row = row > LINES-1 ? LINES-1 : row; X if (col < 0) X col = abs(col) > COLS ? COLS-1 : COLS+col-1; X else X col = col > COLS-1 ? COLS-1 : col; X displaytext (row, col, fline); X return (0); X} X/* Paul J. Condie 4/88 */ SHAR_EOF chmod 0444 ParseText.c || echo "restore of ParseText.c fails" echo "x - extracting ParseCur.c (Text)" sed 's/^X//' << 'SHAR_EOF' > ParseCur.c && X#ifndef LINT Xstatic char Sccsid[] = "@(#)ParseCur.c 1.5 DeltaDate 1/22/90 ExtrDate 1/22/90"; X#endif X X X/* FUNCTION: ParseCursor() X** Parses keyword "CURSOR". X** ARGS: keyword the keyword "CURSOR" X** menufile the unix menu file X** menu menu structure X** gnames holder of goto menu names X** gfiles holder of goto menu names (menu file) X** gindex # of gnames X*/ X X#include X#include X#include "menu.h" X X XParseCursor (keyword, menufile, menu, KeyWord, ParseKey, gnames, gfiles, X gindex, opnumber) X X char keyword[]; X FILE *menufile; X struct MenuInfo *menu; X char KeyWord[][MAXKEYLENGTH]; X int (*ParseKey[])(); X char gnames[][15], gfiles[][15]; X int *gindex; X int *opnumber; X{ X char *fgets(), line[BUFSIZE+1]; X char *ws; X char tmpstr[20]; X X fgets (line, BUFSIZE, menufile); X ws = line; X SKIPJUNK (ws); X sscanf (ws, "%s", tmpstr); /* get row */ X menu->row_cursor = strcmp (tmpstr, "-0") == 0 ? LINES : atoi(tmpstr); X ws += strlen(tmpstr); X SKIPJUNK (ws); X sscanf (ws, "%s", tmpstr); /* get col */ X menu->col_cursor = strcmp (tmpstr, "-0") == 0 ? COLS : atoi(tmpstr); X X /* X ** If the row or column is negative X ** then we use relative addressing X ** the row or col is subtracted from # of rows on screen. X */ X if (menu->row_cursor < 0) X menu->row_cursor = abs(menu->row_cursor) > LINES ? X LINES-1 : LINES+menu->row_cursor-1; X else X menu->row_cursor = menu->row_cursor > LINES-1 ? X LINES-1 : menu->row_cursor; X if (menu->col_cursor < 0) X menu->col_cursor = abs(menu->col_cursor) > COLS ? X COLS-1 : COLS+menu->col_cursor-1; X else X menu->col_cursor = menu->col_cursor > COLS-1 ? X COLS-1 : menu->col_cursor; X return (0); X} X/* Paul J. Condie 4/88 */ SHAR_EOF chmod 0444 ParseCur.c || echo "restore of ParseCur.c fails" echo "x - extracting ParseSpace.c (Text)" sed 's/^X//' << 'SHAR_EOF' > ParseSpace.c && Xstatic char Sccsid[] = "@(#)ParseSpace.c 1.4 DeltaDate 1/22/90 ExtrDate 1/22/90"; X X/* FUNCTION: ParseSpace() X** ARGS: keyword the keyword found X** menufile the unix menu file X** menu menu structure X** gnames holder of goto menu names X** gfiles holder of goto menu names (menu file) X** gindex # of gnames X** RETURNS: 0 X*/ X X#include X#include "menu.h" X Xextern int swin, ewin, longest; X X XParseSpace (keyword, menufile, menu, KeyWord, ParseKey, gnames, gfiles, gindex, opnumber) X X char keyword[]; X FILE *menufile; X struct MenuInfo *menu; X char KeyWord[][MAXKEYLENGTH]; X int (*ParseKey[])(); X char gnames[][15], gfiles[][15]; X int *gindex; X int *opnumber; X{ X struct OptionInfo *malloc(); X char *fgets(), line[BUFSIZE]; X X X if (menu->optioncount >= MAXOPTION) X { X BEEP; X mvprintw (ErrRow, 0, "Exceeded maximum allowable options."); X shutdown (); X } X menu->option[menu->optioncount] = malloc (sizeof (struct OptionInfo)); X if (menu->option[menu->optioncount] == NULL) X { X BEEP; X mvprintw (ErrRow, 0, "Unable to allocate memory for option."); X shutdown (); X } X X strcpy (menu->option[menu->optioncount]->keyword, keyword); X menu->option[menu->optioncount]->opnumber = 0; /* no number */ X strcpy (menu->option[menu->optioncount]->description, ""); X strcpy (menu->option[menu->optioncount]->command, ""); X X fgets (line, BUFSIZE, menufile); /* junk rest of line */ X menu->optioncount++; X ewin++; X return (0); X} SHAR_EOF chmod 0444 ParseSpace.c || echo "restore of ParseSpace.c fails" echo "x - extracting ParInclude.c (Text)" sed 's/^X//' << 'SHAR_EOF' > ParInclude.c && X#ifndef LINT Xstatic char Sccsid[] = "@(#)ParInclude.c 1.2 DeltaDate 1/22/90 ExtrDate 1/22/90"; X#endif X X/* FUNCTION: ParInclude() X** Parses keyword ".INCLUDE". X** ARGS: keyword the keyword "INCLUDE" X** menufile the unix menu file X** menu menu structure X** gnames holder of goto menu names X** gfiles holder of goto menu names (menu file) X** gindex # of gnames X*/ X X#include X#include "menu.h" X X XParInclude (keyword, menufile, menu, KeyWord, ParseKey, gnames, gfiles, X gindex, opnumber) X X char keyword[]; X FILE *menufile; X struct MenuInfo *menu; X char KeyWord[][MAXKEYLENGTH]; X int (*ParseKey[])(); X char gnames[][15], gfiles[][15]; X int *gindex; X int *opnumber; X{ X FILE *fopen(), *newfile; X char *fgets(), line[BUFSIZE+1]; X char *findfile(); X char *getenv(); X char unixfile[100]; X char filename[30]; X int rc; X int KEYFOUND; X int idx; X char newkey[MAXKEYLENGTH]; X X fgets (line, BUFSIZE, menufile); X sscanf (line, "%s", filename); X X /* X ** Open and Parse the new menu file X */ X strcpy (unixfile, findfile (filename, ".", getenv("MENUDIR"), "")); X if ((newfile = fopen (unixfile, "r")) == NULL) X { X BEEP; X mvprintw (ErrRow-2, 0, "Unable to locate .INCLUDE (%s) file.", X filename); X shutdown (); X } X X X /* loop through each keyword */ X rc = fscanf (newfile, "%s", newkey); X while (rc != EOF) X { X /* X ** Check if we found a defined keyword X */ X KEYFOUND = FALSE; X for (idx = 1; idx <= MAXKEYS; idx++) X { X /* X if (strcmp (newkey, KeyWord[idx]) == 0) X */ X if (strmatch (newkey, KeyWord[idx])) X { X KEYFOUND = TRUE; X if (ParseKey[idx] != NULL) X { X rc = (*ParseKey[idx]) (newkey, X newfile, menu, KeyWord, X ParseKey, gnames, gfiles, X gindex, opnumber); X if (rc != 0) return (rc); X } X break; X } X } X if (!KEYFOUND) X { X BEEP; X mvprintw (ErrRow-2, 0, "ERROR: (%s) Key not found.", X newkey); X shutdown (); X } X rc = fscanf (newfile, "%s", newkey); X } /* end while */ X X /* X rc = parsedriver (newfile, KeyWord, ParseKey, menu, gnames, gfiles, X &gindex); X */ X fclose (newfile); X X return (0); X} SHAR_EOF chmod 0444 ParInclude.c || echo "restore of ParInclude.c fails" echo "x - extracting ParAssign.c (Text)" sed 's/^X//' << 'SHAR_EOF' > ParAssign.c && X#ifndef LINT Xstatic char Sccsid[] = "%W% DeltaDate %G% ExtrDate %H%"; X#endif X X/* FUNCTION: ParAssign() X** Parses keyword "*=*" X** A variable=value assignment. X** ARGS: keyword the keyword "*=*" X** menufile the unix menu file X** menu menu structure X** gnames holder of goto menu names X** gfiles holder of goto menu names (menu file) X** gindex # of gnames X*/ X X#include X#include "menu.h" X Xextern int debug; X X XParAssign (keyword, menufile, menu, KeyWord, ParseKey, gnames, gfiles, X gindex, opnumber) X X char keyword[]; X FILE *menufile; X struct MenuInfo *menu; X char KeyWord[][MAXKEYLENGTH]; X int (*ParseKey[])(); X char gnames[][15], gfiles[][15]; X int *gindex; X int *opnumber; X{ X char *fgets(); X char line[BUFSIZE+1]; X char assignment[2*BUFSIZE]; X char *aptr; X X X fgets (line, BUFSIZE, menufile); X line[strlen(line)-1] = '\0'; X strcpy (assignment, keyword); X strcat (assignment, line); X aptr = assignment; X if (debug) X { X fprintf (stderr, "\n[ParAssign] command=:%s:", aptr); X fflush (stderr); X } X setvariable (&aptr); X return (0); X} SHAR_EOF chmod 0644 ParAssign.c || echo "restore of ParAssign.c fails" echo "x - extracting ShowOption.c (Text)" sed 's/^X//' << 'SHAR_EOF' > ShowOption.c && Xstatic char Sccsid[] = "@(#)ShowOption.c 1.3 DeltaDate 10/16/88 ExtrDate 1/22/90"; X X/* FUNCTION: ShowOption() X** Displays a option to the screen. X** ARGS: menu menu structure X** index option # to display X** RETURNS: none X*/ X X#include X#include "menu.h" X Xextern int debug; X X XShowOption (menu, index) X X struct MenuInfo *menu; X int index; X{ X X X /* X ** Now display option. X */ X mvprintw (menu->option[index]->row, menu->option[index]->col, "%2d. ", X menu->option[index]->opnumber); X X displaytext (menu->option[index]->row, menu->option[index]->col+5, X menu->option[index]->description); X X if (debug) X { X fprintf (stderr, "\n[ShowOption] <%s> row=%d col=%d", X menu->option[index]->keyword, X menu->option[index]->row, X menu->option[index]->col); X } X} SHAR_EOF chmod 0444 ShowOption.c || echo "restore of ShowOption.c fails" echo "x - extracting RunSystem.c (Text)" sed 's/^X//' << 'SHAR_EOF' > RunSystem.c && Xstatic char Sccsid[] = "%W% DeltaDate %G% ExtrDate %H%"; X X/* FUNCTION: RunSystem() X** Runs keyword ".SYSTEM". X** ARGS: option option info sturcture X** RETURNS: none X*/ X X#include X#include X#include "menu.h" X Xextern int errno; Xextern int debug; X XRunSystem (menu, opnumber, KeyWord, ParseKey, ShowKey, RunKey, X gnames, gfiles, gindex) X struct MenuInfo *menu; X int opnumber; X int (*ParseKey[MAXKEYS])(), X (*ShowKey[MAXKEYS])(), X (*RunKey[MAXKEYS])(); X char KeyWord[MAXKEYS][MAXKEYLENGTH]; X char gnames[MAXGNAME][15]; X char gfiles[MAXGNAME][15]; X int gindex; X{ X char command[BUFSIZ]; X int rc; /* return code */ X char *comptr; X int screenflag = FALSE; X X X X comptr = menu->option[opnumber]->command; X SKIPJUNK(comptr); X X if (substr (comptr, "GETINPUT") != NULL) X { X sscanf (comptr, "%s", command); X /* X ** Loop through each variable=value until GETINPUT is found X */ X do X { X if (strcmp (command, "GETINPUT") == 0) X { X screenflag = TRUE; X /* get screen name */ X comptr += strlen(command); X SKIPJUNK(comptr); X sscanf (comptr, "%s", command);/* screen name */ X comptr += strlen(command); X SKIPJUNK(comptr); /* sitting at system(3) */ X rc = runscreen (command, menu, opnumber); X if (rc == KEY_CANCEL) X return (0); X break; X } X else X { X rc = setvariable (&comptr); X if (rc != 0) break; X } X X SKIPJUNK(comptr); X rc = sscanf (comptr, "%s", command);/* next var=value */ X } while (rc != EOF); X } /* end if GETINPUT */ X X X /* run system command */ X refresh(); /* force curses to flush attributes */ X sprintf (command, "%s;echo \"One moment, loading %s%s%s ....\"; %s", X#if BSD || SUN X "clear", X#else X "tput clear", X#endif X#if BSD || SUN X NULL, X#else X "`tput smul`", X#endif X menu->option[opnumber]->description, X#if BSD || SUN X NULL, X#else X "`tput rmul`", X#endif X comptr); X reset_shell_mode (); X if (debug) X { X fprintf (stderr, "\n[RunSystem] <%s> command=:%s:", X menu->option[opnumber]->keyword, command); X } X rc = system (command); X if (debug) X { X fprintf (stderr, X "\n[RunSystem] <%s> return code = %d, errno = %d", X rc, errno); X } X X/* Pending survey on whether majority of users want this or not X if ( rc ) X { X printf( "\n\nPress RETURN when ready ==> " ) ; X fflush( stdout ) ; X beep() ; X getchar() ; X } X*/ X reset_prog_mode (); X clearok (stdscr, TRUE); X X X if (rc == 0 && screenflag) X return (REPARSE); X return (rc); X} SHAR_EOF chmod 0644 RunSystem.c || echo "restore of RunSystem.c fails" echo "x - extracting RunExit.c (Text)" sed 's/^X//' << 'SHAR_EOF' > RunExit.c && Xstatic char Sccsid[] = "@(#)RunExit.c 1.5 DeltaDate 1/22/90 ExtrDate 1/22/90"; X X/* FUNCTION: RunExit() X** Runs keyword ".EXIT". X** Exit menu program. X** ARGS: option option info sturcture X** RETURNS: none X*/ X X#include X#include "menu.h" X XRunExit (menu, opnumber, KeyWord, ParseKey, ShowKey, RunKey, X gnames, gfiles, gindex) X struct MenuInfo *menu; X int opnumber; X int (*ParseKey[MAXKEYS])(), X (*ShowKey[MAXKEYS])(), X (*RunKey[MAXKEYS])(); X char KeyWord[MAXKEYS][MAXKEYLENGTH]; X char gnames[MAXGNAME][15]; X char gfiles[MAXGNAME][15]; X int gindex; X{ X char command[BUFSIZ]; X int rc; /* return code */ X X refresh (); X if (strcmp (menu->option[opnumber]->command, "") != 0) X { X sprintf (command, "%s", menu->option[opnumber]->command); X reset_shell_mode (); X rc = system (command); X reset_prog_mode (); X } X return (QUIT); X} SHAR_EOF chmod 0444 RunExit.c || echo "restore of RunExit.c fails" echo "x - extracting RunSetenv.c (Text)" sed 's/^X//' << 'SHAR_EOF' > RunSetenv.c && Xstatic char Sccsid[] = "@(#)RunSetenv.c 1.7 DeltaDate 1/22/90 ExtrDate 1/22/90"; X X/* FUNCTION: RunSetenv() X** Runs keyword ".SETENV". X** ARGS: option option info sturcture X** RETURNS: none X*/ X X#include X#include X#include X#include "menu.h" X X XRunSetenv (menu, opnumber, KeyWord, ParseKey, ShowKey, RunKey, X gnames, gfiles, gindex) X struct MenuInfo *menu; X int opnumber; X int (*ParseKey[MAXKEYS])(), X (*ShowKey[MAXKEYS])(), X (*RunKey[MAXKEYS])(); X char KeyWord[MAXKEYS][MAXKEYLENGTH]; X char gnames[MAXGNAME][15]; X char gfiles[MAXGNAME][15]; X int gindex; X{ X char *strchr(); X int rc; X char command[BUFSIZ]; X char *comptr; X int BELLFLAG=FALSE; X X X /* X ** The first argument [ BELL ] X */ X comptr = menu->option[opnumber]->command; X SKIPJUNK(comptr); X sscanf (comptr, "%s", command); /* do we have a BELL */ X if (strcmp (command, "BELL") == 0) X { X BELLFLAG = TRUE; X comptr += strlen(command); X } X X do X { X rc = setvariable (&comptr); X if (rc != 0) break; X rc = sscanf (comptr, "%s", command); /* get next var=value */ X if (rc == EOF) break; X /* if the command has an = sign in it, it is another one */ X if (!strmatch(command, "*=*")) X break; X } while (rc != EOF); X X SKIPJUNK(comptr); X mvprintw (ErrRow, 0, "%s", comptr); /* dispaly message */ X if (BELLFLAG) X BEEP; X X return (REPARSE); X} X/* Paul J. Condie 10/88 */ SHAR_EOF chmod 0444 RunSetenv.c || echo "restore of RunSetenv.c fails" echo "x - extracting RunMenu.c (Text)" sed 's/^X//' << 'SHAR_EOF' > RunMenu.c && Xstatic char Sccsid[] = "@(#)RunMenu.c 1.7 DeltaDate 1/22/90 ExtrDate 1/22/90"; X X/* FUNCTION: RunMenu() X** Runs keyword ".MENU". X** ARGS: option option info sturcture X** RETURNS: none X*/ X X#include X#include X#include "menu.h" X XRunMenu (menu, opnumber, KeyWord, ParseKey, ShowKey, RunKey, X gnames, gfiles, gindex) X struct MenuInfo *menu; X int opnumber; X int (*ParseKey[MAXKEYS])(), X (*ShowKey[MAXKEYS])(), X (*RunKey[MAXKEYS])(); X char KeyWord[MAXKEYS][MAXKEYLENGTH]; X char gnames[MAXGNAME][15]; X char gfiles[MAXGNAME][15]; X int gindex; X{ X char command[BUFSIZ]; X int rc; /* return code */ X char *comptr; X X /* X ** The first argument is the menu script filename X */ X comptr = menu->option[opnumber]->command; X SKIPJUNK (comptr); X sscanf (comptr, "%s", command); /* filename */ X comptr += strlen(command); X SKIPJUNK (comptr); X sscanf (comptr, "%s", command); /* next argument */ X X /* X ** Loop through each variable=value || GETINPUT X */ X do X { X if (strcmp (command, "GETINPUT") == 0) X { X /* get screen name */ X comptr += strlen(command); X SKIPJUNK(comptr); X sscanf (comptr, "%s", command); /* screen name */ X comptr += strlen(command); X SKIPJUNK(comptr); /* sitting at next argument */ X rc = runscreen (command, menu, opnumber); X if (rc == KEY_CANCEL) X return (0); X } X else X { X rc = setvariable (&comptr); X if (rc != 0) break; X } X X rc = sscanf (comptr, "%s", command);/* next var=value */ X } while (rc != EOF); X X return (SUBMENU); X} X/* Paul J. Condie 5/88 */ SHAR_EOF chmod 0444 RunMenu.c || echo "restore of RunMenu.c fails" echo "x - extracting RunPopMenu.c (Text)" sed 's/^X//' << 'SHAR_EOF' > RunPopMenu.c && X#ifndef LINT Xstatic char Sccsid[] = "@(#)RunPopMenu.c 1.8 DeltaDate 1/22/90 ExtrDate 1/22/90"; X#endif X X/* FUNCTION: RunPopMenu() X** Runs keyword ".POPMENU". X** RunPopMenu will use recursion if there is another .POPMENU X** within .POPMENU. X** ARGS: option option info sturcture X** RETURNS: none X*/ X X#include X#include X#include X#include "menu.h" X X#define INITMENU 0 X#define CREATEMENU -2 X#define UNHILIGHTBOX -1 X X XRunPopMenu (menu, opnumber, KeyWord, ParseKey, ShowKey, RunKey, X gnames, gfiles, gindex) X struct MenuInfo *menu; X int opnumber; X int (*ParseKey[MAXKEYS])(), X (*ShowKey[MAXKEYS])(), X (*RunKey[MAXKEYS])(); X char KeyWord[MAXKEYS][MAXKEYLENGTH]; X char gnames[MAXGNAME][15]; X char gfiles[MAXGNAME][15]; X int gindex; X{ X FILE *fopen(), *menufile; X char *strchr(); X char *findfile(); X char *getenv(); X char command[BUFSIZ]; X int rc; /* return code */ X char *comptr; X int row, col; /* top left corner */ X char *filename; X int i; X static int popmid = 9; /* popup menu id */ X int titleline[200]; /* title 1 on stdscr */ X char poptitle[200]; /* title for popmenu */ X int DIMFLAG = TRUE; X struct MenuInfo pmenu; X char PopMenu[100][80]; /* the pop menu */ X int AUTOFIG = FALSE; /* figure row/col */ X X X comptr = menu->option[opnumber]->command; X SKIPJUNK(comptr); X sscanf (comptr, "%s", command); /* do we have NoDim */ X if (strcmp (command, "NoDim") == 0) X { X DIMFLAG = FALSE; X comptr += strlen(command); X } X X SKIPJUNK(comptr); X sscanf (comptr, "%s", command); /* menufile name */ X comptr += strlen(command); X SKIPJUNK(comptr); X X /* do we have a row/column parameter X ** we'll use titleline for working storage X */ X sscanf (comptr, "%s", titleline); /* get next argument */ X if (*comptr != '\0' && strchr (titleline, '=') == (char *)NULL) X { X /* we have a row/column parameter */ X /* get row and column */ X sscanf (comptr, "%d", &row); X comptr = strchr (comptr, ' '); /* past row */ X SKIPJUNK(comptr); /* at begining of col */ X sscanf (comptr, "%d", &col); X comptr = strchr (comptr, ' '); /* past column */ X } X else X AUTOFIG = TRUE; X X X /* X ** Loop through each variable=value X */ X do X { X rc = setvariable (&comptr); X if (rc != 0) break; X } while (rc != EOF); X X /* X ** Open and Parse the popmenu X */ X filename = findfile (command, ".", getenv("MENUDIR"), ""); X if ((menufile = fopen (filename, "r")) == NULL) X { X BEEP; X mvprintw (ErrRow-2, 0, "Unable to locate (%s) file.", command); X shutdown (); X } X X /* X ** The ParseTitle will put the .POPMENU title on line 0 of stdscr X ** so we need to save original title X ** then read and compare title 1 to see what the title for popmenu X ** should be. X ** Then write the original title back out. (whew) X */ X /* save title line 0 with attributes */ X for (i = 0; i <= COLS; i++) X titleline[i] = mvwinch (stdscr, 0, i); X X initmenu (&pmenu); X X rc = parsedriver (menufile, KeyWord, ParseKey, &pmenu, gnames, gfiles, X &gindex); X fclose (menufile); X X if (AUTOFIG) X { X int longest; X X /* X ** try to put menu as close to the option as possible X ** menu->option[opnumber]->row holds the X ** location on stdscr of the option that selected this. X */ X row = menu->option[opnumber]->row - 1; X col = menu->option[opnumber]->col + X strlen (menu->option[opnumber]->description); X if (popmid == 9) X col += 4; X X /* make sure it fits on the screen */ X if ((row + pmenu.optioncount + 2) > LINES) X row = LINES - pmenu.optioncount - 2; X X for (i = 0, longest = 0; i < pmenu.optioncount; i++) X if (strlen (pmenu.option[i]->description) > longest) X longest = strlen (pmenu.option[i]->description); X if ((col + longest + 4) > COLS) X col = COLS - longest - 4; X X /* X ** Recalculate the options row and col for recursion X */ X for (i = 0; i < pmenu.optioncount; i++) X { X pmenu.option[i]->row = row + 1 + i; X pmenu.option[i]->col = col; X } X } X X /* find popmenu title in line 0 */ X for (i = 0; i <= COLS; i++) X { X poptitle[i] = ' '; X if (mvwinch (stdscr, 0,i) != titleline[i]) X { X poptitle[i] = mvwinch(stdscr, 0,i); X } X else X poptitle[i] = ' '; X /* write original title back out */ X mvwaddch (stdscr, 0,i, titleline[i]); X } X poptitle[i] = '\0'; X /* junk trailing spaces */ X for (i = strlen(poptitle)-1; i >= 0; i--) X if (poptitle[i] == ' ') X poptitle[i] = '\0'; X else X break; X X if (rc != 0) return (rc); /* from parsemenu */ X X X X /* if .BOX||.LINE && DIM then unhilight */ X if (DIMFLAG) X { X /* Dim the .BOX */ X if (menu->boxtype) X drawbox (stdscr, 1,1, LINES-1,COLS, X (menu->boxtype&0777000)>>9, DumbLine, X FALSE, FALSE); X X /* Dim the .LINE */ X if (menu->linetype) X drawline (stdscr, menu->titlecount-1, X (menu->linetype&0777000)>>9, DumbLine, X menu->boxtype); X X wnoutrefresh (stdscr); X } X X /* popmid = 10+ */ X popmid++; SHAR_EOF echo "End of part 4" echo "File RunPopMenu.c is continued in part 5" echo "5" > s2_seq_.tmp exit 0