Path: utzoo!utgpu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!usc!ucsd!pacbell.com!pacbell!pcbox!pjc From: pjc@pcbox.UUCP (Paul J. Condie) Newsgroups: alt.sources Subject: menu(1) part 6 of 14 Keywords: menu Message-ID: <440@pcbox.UUCP> Date: 26 Dec 90 20:08:44 GMT Organization: Yet Another Box - Casto Valley, Ca. Lines: 1600 #!/bin/sh # this is part 6 of a multipart archive # do not concatenate these parts, unpack them in order with /bin/sh # file SetTerm.c continued # CurArch=6 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 SetTerm.c" sed 's/^X//' << 'SHAR_EOF' >> SetTerm.c Xint KeySave = 6; /* ^f - GetInput save screen to a file */ Xint KeyPrint = 16; /* ^p - GetInput prints screen to lp */ Xint KeyAccept = 1; /* ^a - GetInput accepts input */ X X X/* Menu Specific */ Xint HotKeys = 0; /* for hot keyboard */ Xint KeyMainMenu = 'm'; /* goto main menu */ Xint KeyPrevMenu = 'p'; /* goto previous menu */ Xint KeyExitMenu = 'e'; /* exit menu */ Xint KeyGname = 'g'; /* goto a specific menu (dumb) */ Xint KeyPopGname = 7; /* ^g - goto a specific menu (popmenu) */ X X X XSetTerm () X{ X FILE *fopen(), *menuinit; X char *getenv(); X char *findfile(); X char *strchr(); X char *ws; X char filename[100], line[BUFSIZE]; X char *s1; X X X char *terminal; X X /* X ** Parse the .menuinit file X ** First look in current directory then $HOME then in $MENUDIR X */ X strcpy (filename, findfile (MENUINIT, ".", X (char *)getenv("HOME"), (char *)getenv("MENUDIR"), "")); X if ((menuinit = fopen (filename, "r")) == NULL) X { X /* no file found - use the defaults */ X return (0); X } X X /* set terminal keys */ X while (fgets (line, BUFSIZE, menuinit) != (char *)NULL) X { X if (strncmp ("HOTKEYS", line, 7) == 0) X HotKeys = 1; X X /* X ** The following keywords require a = sign X */ X X if ((s1 = strchr (line, '=')) == (char *)NULL) X continue; X X s1++; /* get past the = */ X X /* Mover Keys */ X if (strncmp ("KEY_RETURN", line, 10) == 0) X sscanf (s1, "%d", &KeyReturn); X else if (strncmp ("KEY_DOWN", line, 8) == 0) X sscanf (s1, "%d", &KeyDown); X else if (strncmp ("KEY_UP", line, 6) == 0) X sscanf (s1, "%d", &KeyUp); X else if (strncmp ("KEY_TAB", line, 7) == 0) X sscanf (s1, "%d", &KeyTab); X else if (strncmp ("KEY_BTAB", line, 8) == 0) X sscanf (s1, "%d", &KeyBTab); X X /* Edit Keys */ X else if (strncmp ("KEY_BEG", line, 7) == 0) X sscanf (s1, "%d", &KeyBeg); X else if (strncmp ("KEY_END", line, 7) == 0) X sscanf (s1, "%d", &KeyEnd); X else if (strncmp ("KEY_RIGHT", line, 9) == 0) X sscanf (s1, "%d", &KeyRight); X else if (strncmp ("KEY_LEFT", line, 8) == 0) X sscanf (s1, "%d", &KeyLeft); X else if (strncmp ("KEY_BACKSPACE", line, 13) == 0) X sscanf (s1, "%d", &KeyBackspace); X else if (strncmp ("KEY_EOL", line, 13) == 0) X sscanf (s1, "%d", &KeyEOL); X else if (strncmp ("KEY_DL", line, 14) == 0) X sscanf (s1, "%d", &KeyDL); X else if (strncmp ("KEY_DC", line, 6) == 0) X sscanf (s1, "%d", &KeyDC); X else if (strncmp ("KEY_IC", line, 6) == 0) X sscanf (s1, "%d", &KeyIC); X X /* Other Keys */ X else if (strncmp ("KEY_HELP", line, 8) == 0) X sscanf (s1, "%d", &KeyHelp); X else if (strncmp ("KEY_REFRESH", line, 10) == 0) X sscanf (s1, "%d", &KeyRedraw); X else if (strncmp ("KEY_ACCEPT", line, 10) == 0) X sscanf (s1, "%d", &KeyAccept); X else if (strncmp ("KEY_CANCEL", line, 10) == 0) X sscanf (s1, "%d", &KeyCancel); X else if (strncmp ("KEY_SAVE", line, 8) == 0) X sscanf (s1, "%d", &KeySave); X else if (strncmp ("KEY_PRINT", line, 9) == 0) X sscanf (s1, "%d", &KeyPrint); X else if (strncmp ("KEY_EXITMENU", line, 12) == 0) X sscanf (s1, "%d", &KeyExitMenu); X else if (strncmp ("KEY_MAINMENU", line, 12) == 0) X sscanf (s1, "%d", &KeyMainMenu); X else if (strncmp ("KEY_PREVMENU", line, 12) == 0) X sscanf (s1, "%d", &KeyPrevMenu); X else if (strncmp ("KEY_GNAME", line, 9) == 0) X sscanf (s1, "%d", &KeyGname); X else if (strncmp ("KEY_POPGNAME", line, 12) == 0) X sscanf (s1, "%d", &KeyPopGname); X else if (strncmp ("KEY_TOC", line, 7) == 0) X sscanf (s1, "%d", &KeyTOC); X } X fclose (menuinit); X return (0); X} X/* Paul J. Condie 11/88 */ SHAR_EOF echo "File SetTerm.c is complete" chmod 0644 SetTerm.c || echo "restore of SetTerm.c fails" echo "x - extracting systime.c (Text)" sed 's/^X//' << 'SHAR_EOF' > systime.c && X#ifndef LINT Xstatic char Sccsid[] = "@(#)systime.c 1.2 DeltaDate 5/6/88 ExtrDate 1/22/90"; X#endif X X#include X#include X Xsystime (timeStr, mask) X X char *timeStr, *mask; X{ X long tloc ; X struct tm *ltime, *localtime() ; X char tmpstr[4] ; X int tmpval; X X tloc = time((long *) 0) ; X ltime = localtime(&tloc) ; X X ltime->tm_mon++; X X if (mask == NULL) X { X sprintf (timeStr, "%2d:%02d:%02d", ltime->tm_hour, ltime->tm_min, X ltime->tm_sec) ; X } X else X while (*mask != '\0') X { X switch (*mask) X { X case 'H': X if (ltime->tm_hour > 12) X { X tmpval = ltime->tm_hour - 12; X sprintf (tmpstr, "%2d", tmpval); X } X else X sprintf (tmpstr, "%2d", ltime->tm_hour); X break; X case 'M': X sprintf (tmpstr, "%02d", ltime->tm_min); X break; X case 'S': X sprintf (tmpstr, "%02d", ltime->tm_sec); X break; X case 'I': X sprintf (tmpstr, "%2d", ltime->tm_hour); X break; X case 'Z': X if (ltime->tm_hour >= 12) X strcpy (tmpstr, "PM"); X else X strcpy (tmpstr, "AM"); X break; X case 'z': X if (ltime->tm_hour >= 12) X strcpy (tmpstr, "pm"); X else X strcpy (tmpstr, "am"); X break; X default: X *timeStr = *mask; X timeStr++; X mask++; X continue; X } /* end switch */ X *timeStr = tmpstr[0]; X timeStr++; X *timeStr = tmpstr[1]; X timeStr++; X mask += 2; X } /* end while */ X X *timeStr = '\0'; X return (0); X} SHAR_EOF chmod 0444 systime.c || echo "restore of systime.c fails" echo "x - extracting sysdate.c (Text)" sed 's/^X//' << 'SHAR_EOF' > sysdate.c && X#ifndef LINT Xstatic char Sccsid[] = "@(#)sysdate.c 1.1 DeltaDate 9/6/87 ExtrDate 1/22/90"; X#endif X X#include X Xsysdate (dateStr, mask) X X char *dateStr, *mask; X{ X long tloc ; X struct tm *ltime, *localtime() ; X Xstatic char *shortmon[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", X "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; X Xstatic char *longmon[]= X {"January","February","March","April","May","June", X "July","August","September","October","November","December"}; X Xstatic char *shortday[]= {"sun","mon","tue","wed","thr","fri","sat"}; X Xstatic char *longday[]= {"Sunday","Monday","Tuesday","Wednessday", X "Thursday", "Friday", "Saturday"}; X X X tloc = time ((long *) 0) ; X ltime = localtime (&tloc) ; X X while (*mask != '\0') X { X X/* X** Process month X*/ X if (strncmp (mask, "mmmmm", 5) == 0) X { X sprintf (dateStr, "%s", longmon[ltime->tm_mon]); X mask += 5; X dateStr += strlen (longmon[ltime->tm_mon]); X continue; X } X else X if (strncmp (mask, "mmm", 3) == 0) X { X sprintf (dateStr, "%s", shortmon [ltime->tm_mon]); X mask += 3; X dateStr += 3; X continue; X } X else X if (strncmp (mask, "mm", 2) == 0) X { X sprintf (dateStr, "%.2d", ltime->tm_mon + 1); X mask += 2; X dateStr += 2; X continue; X } X X/* X** Process day X*/ X if (strncmp (mask, "ddddd", 5) == 0) X { X sprintf (dateStr, "%s", longday [ ltime->tm_wday ]); X mask += 5; X dateStr += strlen (longday[ltime->tm_wday]); X continue; X } X else X if (strncmp (mask, "ddd", 3) == 0) X { X sprintf (dateStr, "%s", shortday [ltime->tm_wday]); X mask += 3; X dateStr += 3; X continue; X } X else X if (strncmp (mask, "dd", 2) == 0) X { X sprintf (dateStr, "%.2d", ltime->tm_mday); X mask += 2; X dateStr += 2; X continue; X } X if (strncmp (mask, "jjj", 3) == 0) X { X sprintf (dateStr, "%3d", ltime->tm_yday + 1); X mask += 3; X dateStr += 3; X continue; X } X X/* X** Process year X*/ X if (strncmp (mask, "yyyy", 4) == 0) X { X sprintf (dateStr, "19%.2d", ltime->tm_year); X mask += 4; X dateStr += 4; X continue; X } X else X if (strncmp (mask, "yy", 2) == 0) X { X sprintf (dateStr, "%.2d", ltime->tm_year); X mask += 2; X dateStr += 2; X continue; X } X X/* X** Process mask X*/ X *dateStr = *mask; X dateStr++; X mask++; X } X X *dateStr = '\0'; X return (0); X} SHAR_EOF chmod 0444 sysdate.c || echo "restore of sysdate.c fails" echo "x - extracting checkmail.c (Text)" sed 's/^X//' << 'SHAR_EOF' > checkmail.c && X#ifndef LINT Xstatic char Sccsid[] = "@(#)checkmail.c 1.3 DeltaDate 1/22/90 ExtrDate 1/22/90"; X#endif X X#include X#include X X#ifndef BELL X#define BELL printf ("%c", 7); X#endif X Xextern int mailrow; Xextern int mailcol; X Xcheckmail () X{ X int rc; X static int mailcheck = 30; /* default */ X X#ifdef ALARM X alarm (0); /* turn off alarm */ X#endif X if ((rc = anymail()) != FALSE) X { X /* we got mail */ X attrset (A_REVERSE); X if (rc == 1 || rc == 3) X mvprintw (mailrow,mailcol, "MAIL"); X else X mvprintw (mailrow,mailcol, "EMAIL"); X attrset (A_NORMAL); X#ifdef ALARM X BELL; X#endif X } X else X mvprintw (mailrow,mailcol, " "); X X#ifdef ALARM X signal (SIGALRM, checkmail); X if ((char *)getenv("MAILCHECK") != (char *)0) X sscanf ((char *)getenv("MAILCHECK"), "%d", &mailcheck); X if (mailcheck < 10) X mailcheck = 10; X alarm (mailcheck); /* set alarm again */ X#endif X} X/* Paul J. Condie 4/88 */ SHAR_EOF chmod 0444 checkmail.c || echo "restore of checkmail.c fails" echo "x - extracting anymail.c (Text)" sed 's/^X//' << 'SHAR_EOF' > anymail.c && X#ifndef LINT Xstatic char Sccsid[] = "@(#)anymail.c 1.3 DeltaDate 1/22/90 ExtrDate 1/22/90"; X#endif X X/* FUNCTION: anymail() X** If the first word in the mail file is Forward it returns X** no mail. X** RETURNS: FALSE - no unix or email. X** 1 - unix mail. X** 2 - email X** 3 - both unix and email X*/ X#include X#include X#include X Xanymail () X{ X FILE *fopen(), *fp; X char *getenv(); X struct stat Statbuf; X int rc = 0; /* return code */ X char *mailfile; X static int FIRST_TIME = 1; X static int FORWARDFLAG = 0; X char tmpstr[80]; X X X if ((mailfile = getenv("MAIL")) != (char *)0) X if (stat (mailfile, &Statbuf) == 0) X { X /* there is a mail file */ X if (Statbuf.st_size > 0) X { X /* there is something in the mail file */ X if (FIRST_TIME) X { X /* check to see if mail is being Forwarded */ X FIRST_TIME = 0; X if ((fp=fopen (mailfile, "r")) != (FILE *)NULL) X { X fscanf (fp, "%s", tmpstr); X if (strcmp (tmpstr, "Forward") == 0) X FORWARDFLAG = 1; X fclose (fp); X } X } X if (!FORWARDFLAG) X rc = 1; X } X } X if ((mailfile = getenv("EMAIL")) != (char *)0) X if (stat (mailfile, &Statbuf) == 0) X { X if (Statbuf.st_size > 0) X rc = rc == 1 ? 3 : 2; X } X return (rc); X} SHAR_EOF chmod 0444 anymail.c || echo "restore of anymail.c fails" echo "x - extracting setenv.c (Text)" sed 's/^X//' << 'SHAR_EOF' > setenv.c && X#ifndef LINT Xstatic char Sccsid[] = "@(#)setenv.c 1.2 DeltaDate 1/22/90 ExtrDate 1/22/90"; X#endif X X/* PROGRAM NAME: @(#)setenv.c 1.2 X* REVISION DATE: X* REVISION LEVEL: X* CONTACT PERSON: Library Staff X* AUTHOR: Stephen J. Muir X* ABSTRACT: setenv/delenv - add, change or delete environment variables X* KEYWORDS: environment, shell, getenv X* DESCRIPTION: Setenv allows a program to set environment variables. X* delenv allows a program to delete environment variables. X* PROJECTS: X* SOFTWARE CATEGORY: application development tools X* COPYRIGHT: Notice X This is the confidential, unpublished property of Pacific Bell. X Receipt or possession of it does not convey any rights to divulge, X reproduce, use, or allow others to use it without the specific written X authorization of Pacific Bell and use must conform strictly to X the license agreement between user and Pacific Bell. X X COPYRIGHT (c) 1986 Pacific Bell. All Rights Reserved. X X* OPERATING ENVIRONMENT: all standard AT&T UNIX machines. X* SOFTWARE DEPENDENCIES: none. X* HARDWARE DEPENDENCIES: X* LIMITATIONS: X* DOCUMENTATION: setenv.3 manual page X* COMPILE COMMAND: cc setenv.c X* SIZE: X* SUPPORT LEVEL: X* MODULE LIST: X*/ X# include X X/* This is the number of extra array elements to allocate each time it becomes X * necessary. X */ X# define INC 10 X Xextern char **environ, *malloc (); Xextern int free (); X Xstatic char **original, **current, **limit; X X/* This routine should be called only once (when either "setenv" or "delenv" is X * called for the first time). It would only be called again if it fails due X * to lack of memory. It makes a copy of the original environment because the X * original environment array and its elements were not obtained from "malloc" X * and the "free" routine cannot, therefore, be called with any of its X * elements. X * X * return values: X * 0: success X * -1: out of memory - nothing has changed X */ Xstatic /* this is a private routine */ Xinitialise () X { register char **old, **new_ptr, *tmp, **new_env; X X /* count number of existing strings */ X for (old = environ; *old; ++old) X ; X X /* make space for extra strings */ X if ((new_ptr = X new_env = X (char **)malloc (sizeof (char **) * ((old - environ) + INC + 1)) X ) X == 0 X ) X return (-1); X X /* "limit" points to the last element of the array -- it is used to X * decide when to recreate it X */ X limit = new_env + (old - environ) + INC; X X /* copy across old strings */ X for (old = environ; *old; ++old) X { if ((tmp = malloc (strlen (*old) + 1)) == 0) X { /* out of memory -- undo everything */ X while (new_ptr != new_env) X free (*--new_ptr); X free ((char *)new_ptr); X return (-1); X } X strcpy (tmp, *old); X *new_ptr++ = tmp; X } X /* "current" points to the null pointer at the end of the array */ X *(current = new_ptr) = 0; X X /* this is really just a flag to say it's initialised */ X original = environ; X /* overwrite old environment with new */ X environ = new_env; X return (0); X } X X/* This is a special routine to compare a string "name" of the form "NAME" with X * a string "name_value" of the form "NAME=VALUE". It returns zero if the X * comparison is successful X */ Xstatic /* this is a private routine */ Xdiffer (name, name_value) X char *name, *name_value; X { while (*name && *name_value) X if (*name++ != *name_value++) X return (1); X return (*name_value != '='); X } X X/* This routine deletes an environment variable, e.g. delenv ("SHELL"); X * X * return values: X * 0: success X * 1: environment variable not found X * -1: out of memory - nothing has changed X */ Xdelenv (name) X char *name; X { register char **ptr; X X /* initialise if necessary */ X if (original == 0 && initialise ()) X return (-1); X X /* attempt to find it */ X for (ptr = environ; *ptr && differ (name, *ptr); ++ptr) X ; X if (*ptr == 0) X return (1); /* not found */ X X /* delete it */ X free (*ptr); X *ptr = *--current; X *current = 0; X return (0); X } X X/* This routine sets a new environment variable, replacing an existing one X * where appropriate, e.g. setenv ("SHELL", "/bin/csh"); X * X * return values: X * 0: success X * -1: out of memory - nothing has changed X */ Xsetenv (name, value) X char *name, *value; X { register char **old, **new_ptr, *cp, *tmp, **new_env; X X /* initialise if necessary */ X if (original == 0 && initialise ()) X return (-1); X X /* allocate space for the new string */ X if ((cp = tmp = malloc (strlen (name) + strlen (value) + 2)) == 0) X return (-1); X X /* find an existing one if we can - we do this now as we will lose X * the original "name" pointer in the while loop following X */ X for (old = environ; *old && differ (name, *old); ++old) X ; X X /* make the new entry */ X while (*name) X *cp++ = *name++; X *cp++ = '='; X while (*value) X *cp++ = *value++; X *cp = '\0'; X X /* case 1: overwrite previous value */ X if (*old) X { free (*old); X *old = tmp; X } X X /* case 2: no previous value and no space left - allocate more */ X else if (current == limit) X { if ((new_ptr = X new_env = X (char **)malloc (sizeof (char **) * X ((old - environ) + INC + 1) X ) X ) == 0 X ) X { free (tmp); X return (-1); X } X limit = new_env + (old - environ) + INC; X for (old = environ; *old; ) X *new_ptr++ = *old++; X *new_ptr++ = tmp; X *(current = new_ptr) = 0; X free ((char *)environ); X environ = new_env; X } X X /* case 3: no previous value and there is enough space */ X else X { *current++ = tmp; X *current = 0; X } X return (0); X } SHAR_EOF chmod 0444 setenv.c || echo "restore of setenv.c fails" echo "x - extracting strmatch.c (Text)" sed 's/^X//' << 'SHAR_EOF' > strmatch.c && X#ifndef LINT Xstatic char Sccsid[] = "@(#)strmatch.c 1.1 DeltaDate 10/20/88 ExtrDate 1/22/90"; X#endif X X#ifndef TRUE X#define TRUE 1 X#endif X#ifndef FALSE X#define FALSE 0 X#endif X#ifndef BOOL X#define BOOL int X#endif X X#define M_ALL '*' X#define M_ONE '?' X#define M_SET '[' X#define M_RNG '-' X#define M_END ']' X X XBOOL strmatch (name, pat) X X char *name, *pat; X{ X char c, k; X BOOL ok; X X X while ((c = *pat++) != '\0') X { X switch (c) X { X case M_ONE: X if (*name++ == '\0') return (FALSE); X break; X X case M_ALL: X if (*pat == '\0') return (TRUE); X for (; *name != '\0'; ++name) X if (strmatch (name, pat)) return (TRUE); X return (FALSE); X X case M_SET: X ok = FALSE; X k = *name++; X while ((c = *pat++) != M_END) X if (*pat == M_RNG) X { X if (c <= k && k <= pat[1]) X ok = TRUE; X pat += 2; X } X else X if (c == k) ok = TRUE; X if (!ok) return (FALSE); X break; X X default: X if (*name++ != c) return (FALSE); X break; X } X } X return (*name == '\0'); X} SHAR_EOF chmod 0444 strmatch.c || echo "restore of strmatch.c fails" echo "x - extracting setvar.c (Text)" sed 's/^X//' << 'SHAR_EOF' > setvar.c && X#ifndef LINT Xstatic char Sccsid[] = "%W% DeltaDate %G% ExtrDate %H%"; X#endif X X#include X#include X#include X#include "menu.h" X X X Xsetvariable (cptr) X char **cptr; /* command pointer var=value */ X{ X char *getenv(); X char *getval(); X char variable[100]; X char value[100]; X int rc; /* return code */ X int i, j; X X if (*cptr == (char *)NULL) return (EOF); X X /* skip junk characters */ X for (;**cptr != '\0' && (!isalpha(**cptr)) && (!isdigit(**cptr)); X (*cptr)++) X if (**cptr == '!') X break; X ; X if (**cptr == '\0') return (EOF); /* end of line */ X X /* get the enviroment variable */ X for (i = 0; **cptr != '=' && **cptr != '\0'; i++, (*cptr)++) X variable[i] = **cptr; X variable[i] = '\0'; X if (strcmp (variable, "") == 0 || **cptr != '=') X { X BEEP; X mvprintw (ErrRow-2, 0, X "Error occured while setting enviroment variable %s", X variable); X shutdown (); X } X (*cptr)++; /* get past the = */ X X strcpy (value, getval (cptr, '0')); X X /* set the enviroment variable */ X if (variable[0] == '!') X { X /* X ** if ! X ** then only set if not already set X */ X /* junk ! - shift left one */ X for (i = 0; variable[i] != '\0'; i++) X variable[i] = variable[i+1]; X rc = 0; X if (getenv(variable) == (char *)NULL) X rc = setenv (variable, value); X } X else 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 return (0); X} X/* Paul J. Condie 10/88 */ SHAR_EOF chmod 0644 setvar.c || echo "restore of setvar.c fails" echo "x - extracting drawline.c (Text)" sed 's/^X//' << 'SHAR_EOF' > drawline.c && X#ifndef LINT Xstatic char Sccsid[] = "@(#)drawline.c 1.2 DeltaDate 1/22/90 ExtrDate 1/22/90"; X#endif X X#include X#include X X#define DumbLine 1 /* A_NORMAL */ X#define StandoutLine 2 /* A_STANDOUT */ X#define SingleLine 3 /* A_ALTCHARSET */ X#define MosaicLine 4 /* A_ALTCHARSET */ X#define DiamondLine 5 /* A_ALTCHARSET */ X#define DotLine 6 /* A_ALTCHARSET */ X#define PlusLine 7 /* A_ALTCHARSET */ X X#define CANDRAWGRAPHICS (enter_alt_charset_mode != NULL && \ X strcmp(enter_alt_charset_mode, "") != 0) X X Xdrawline (win, row, trythis, trythat, box) X WINDOW *win; X int row; X int trythis; X int trythat; X int box; X{ X int col; X int hchar; /* horizonal char */ X int lchar; /* left char */ X int rchar; /* right char */ X int attribute; X int boxtype; X X X boxtype = trythis; X attribute = (boxtype == DumbLine || boxtype == StandoutLine) ? A_NORMAL : A_ALTCHARSET; X if (attribute == A_ALTCHARSET) X /* can this terminal do graphics ? */ X boxtype = CANDRAWGRAPHICS ? trythis : trythat; X X switch (boxtype) X { X case DumbLine: X /* draw a dumb line */ X hchar = '-'; X lchar = '+'; X rchar = '+'; X break; X X case StandoutLine: X /* draw a standout line */ X attribute = A_STANDOUT; X hchar = ' '; X lchar = ' '; X rchar = ' '; X break; X X case SingleLine: X /* attempt to draw a graphic single line */ X hchar = 'q'; X lchar = 't'; X rchar = 'u'; X break; X X case MosaicLine: X hchar = 'a'; X lchar = 'a'; X rchar = 'a'; X break; X X case DiamondLine: X hchar = '`'; X lchar = '`'; X rchar = '`'; X break; X X case DotLine: X hchar = '~'; X lchar = '~'; X rchar = '~'; X break; X X case PlusLine: X hchar = 'n'; X lchar = 'n'; X rchar = 'n'; X break; X break; X X default: X return (-1); X } X X#ifdef BSD X standout (); X#else X wattrset (win, attribute); X#endif X for (col = 0; col <= COLS-1; col++) X mvwaddch (win, row, col, hchar); X X if (box) X { X mvwaddch (win, row, 0, lchar); X mvwaddch (win, row, COLS-1, rchar); X } X X#ifdef BSD X standend (); X#else X wattrset (win, A_NORMAL); X#endif X return (0); X} X/* Paul J. Condie 10/88 */ SHAR_EOF chmod 0444 drawline.c || echo "restore of drawline.c fails" echo "x - extracting initmenu.c (Text)" sed 's/^X//' << 'SHAR_EOF' > initmenu.c && X#ifndef LINT Xstatic char Sccsid[] = "%W% DeltaDate %G% ExtrDate %H%"; X#endif X X#include X#include "menu.h" X Xinitmenu (menu) X struct MenuInfo *menu; X{ X /* set default menu settings */ X menu->row_cursor = LINES - 2; X menu->col_cursor = COLS - 4; X menu->boxtype = 0; X menu->linetype = 0; X menu->srn[0] = (struct ScreenInfo *)NULL; X menu->after_menu = (char *)NULL; X} SHAR_EOF chmod 0644 initmenu.c || echo "restore of initmenu.c fails" echo "x - extracting keyboard.c (Text)" sed 's/^X//' << 'SHAR_EOF' > keyboard.c && X#include X#include X#include "menu.h" X Xkeyboard () X{ X char *getenv(); X int ch; X int wrow = 0; /* from row */ X int wcol = 10; /* from col */ X int sstart; /* scrool start row */ X int send; /* scrool end row */ X int prow; /* print row */ X int dflag=0; X WINDOW *bwin; X X X sstart = wrow + 10; X send = wrow + 20; X prow = sstart; X X mvprintw (1,0, "Keyboard"); X mvprintw (2,4, "Fun"); X X drawbox (stdscr, wrow+1,wcol, wrow+23,wcol+40, StandoutLine, X StandoutLine, FALSE, FALSE); X mvprintw (2,wcol+40, "StandoutLine"); X drawbox (stdscr, wrow+2,wcol+1, wrow+22,wcol+39, DumbLine, DumbLine, X FALSE, FALSE); X mvprintw (3,wcol+39, "DumbLine"); X X /* to get around bug in curses of not turning attributes off */ X /* X for (ch = 0; ch <= LINES; ch++) X { X mvprintw (ch,70, "hi"); X refresh (); X mvprintw (ch,70, " "); X } X */ X X /* terminal type */ X mvprintw (wrow+3, wcol+4, "Terminal = %s", getenv("TERM")); X X /* DrawLine ? */ X if (enter_alt_charset_mode == NULL || X strcmp (enter_alt_charset_mode, "") == 0) X mvprintw (wrow+4, wcol+4, "Alternate Characters = No"); X else X { X dflag++; X mvprintw (wrow+4, wcol+4, "Alternate Characters = Yes"); X X mvprintw (5,wcol+44, "Check termcap/terminfo"); X mvprintw (6,wcol+44, "setting if the alternate"); X mvprintw (7,wcol+44, "character lines below"); X mvprintw (8,wcol+44, "don't look right."); X X bwin = newwin (13, 27, 10, wcol+43); X drawbox (bwin, 1,1, 13,27, SingleLine, SingleLine, FALSE,FALSE); X drawbox (bwin, 2,2, 12,26, MosaicLine, MosaicLine, FALSE,FALSE); X drawbox (bwin, 3,3, 11,25, DiamondLine, DiamondLine, FALSE,FALSE); X drawbox (bwin, 4,4, 10,24, DotLine, DotLine, FALSE,FALSE); X drawbox (bwin, 5,5, 9,23, PlusLine, PlusLine, FALSE,FALSE); X X mvwprintw (bwin, 0,7, " SingleLine "); X mvwprintw (bwin, 1,7, " MosaicLine "); X mvwprintw (bwin, 2,7, " DiamondLine "); X mvwprintw (bwin, 3,7, " DotLine "); X mvwprintw (bwin, 4,7, " PlusLine "); X } X X /* Show all attributes */ X mvprintw (11,0, "Curses"); X mvprintw (12,0, "Attributes"); X X attrset (A_NORMAL); X mvprintw (14,0, "NORMAL"); X attrset (A_STANDOUT); X mvprintw (15,0, "STANDOUT"); X attrset (A_REVERSE); X mvprintw (16,0, "REVERSE"); X attrset (A_UNDERLINE); X mvprintw (17,0, "UNDERLINE"); X attrset (A_BLINK); X mvprintw (18,0, "BLINK"); X attrset (A_DIM); X mvprintw (19,0, "DIM"); X attrset (A_BOLD); X mvprintw (20,0, "BOLD"); X X attrset (A_NORMAL); X X /* key codes */ X mvprintw (wrow+6,wcol+8, "Press a Key"); X mvprintw (wrow+7,wcol+8, "Press zero to exit."); X X /* set up scroll */ X scrollok (stdscr, TRUE); X wsetscrreg (stdscr, sstart, send); X X mvprintw (sstart-2, wcol+4, " (.menuinit)"); X attrset (A_BOLD); X mvprintw (sstart-1, wcol+4, "char dec hex octal"); X attrset (A_NORMAL); X do X { X refresh (); X if (dflag) X { X touchwin (bwin); X wrefresh (bwin); X } X move (wrow+6, wcol+8+strlen("Press a Key")+1); X refresh (); X ch = getch (); X X /* X nodelay (stdscr, TRUE); X while ((ch = getch()) != -1) X print ch X nodelay (stdscr, FALSE); X */ X X if (prow > send-2) X { X scroll (stdscr); X attrset (A_STANDOUT); X mvprintw (prow+1,wcol-1, " "); X mvprintw (prow+1,wcol+39, " "); X attrset (A_NORMAL); X X mvprintw (prow+1,wcol, "|"); X mvprintw (prow+1,wcol+38, "|"); X } X else X prow++; X if (ch == '\t') X mvprintw (prow,wcol+4, "\t\\t\t%d\t%x\t%o", ch,ch,ch); X else if (ch == '\n') X mvprintw (prow,wcol+4, "\t\\n\t%d\t%x\t%o", X ch,ch,ch); X else if (ch == '\r') X mvprintw (prow,wcol+4, "\t\\r\t%d\t%x\t%o", X ch,ch,ch); X else if (ch == '\b') X mvprintw (prow,wcol+4, "\t\\b\t%d\t%x\t%o", X ch,ch,ch); X else X mvprintw (prow,wcol+4, "\t%c\t%d\t%x\t%o", ch,ch,ch,ch); X X } while (ch != '0'); X if (dflag) X { X touchwin (bwin); X wrefresh (bwin); X } X} X/* Paul J. Condie */ SHAR_EOF chmod 0644 keyboard.c || echo "restore of keyboard.c fails" echo "x - extracting runscreen.c (Text)" sed 's/^X//' << 'SHAR_EOF' > runscreen.c && X#ifndef LINT Xstatic char Sccsid[] = "%W% DeltaDate %G% ExtrDate %H%"; X#endif X X/* FUNCTION: runscreen() X*/ X X#include X#include "GetInput.h" X#include "menu.h" X#include "terminal.h" X X#define SRN menu->srn[sidx] X#define FLD menu->srn[sidx]->field[fidx] X Xextern int debug; X X Xrunscreen (screen_name, menu, opnumber) X char screen_name[]; X struct MenuInfo *menu; X int opnumber; X{ X FILE *popen(), *pp; X char *getenv(); X char *getval(); X char *findfile(); X char *format(); X char *malloc(); X WINDOW *swin; X union FldUnion Fld; X int rc; /* return code */ X int exitkey; X int sidx; X int fidx = 0; X char fielddata[MAXFIELDS+1][100]; X int fieldcount; X char *promptptr = (char *)NULL; X char fmtdefault[100];/* formated default value */ X char *wsptr; /* working storage pointer */ X int helpflag; X char helpfile[80]; X char tmptitle[100]; X char Title[100]; /* tmp for AUTO */ X int Rows; /* tmp for AUTO */ X int Cols; /* tmp for AUTO */ X int toprow; X int leftcol; X int i; /* tmp loop var */ X char value[200]; X char input[100]; /* what user inputted */ X char *tmprange[MAXFIELDS+1]; X int NoInput; X X X Xherewegoagain: X X helpflag = TRUE; X X /* Find the screen definition */ X for (sidx = 0; menu->srn[sidx] != (struct ScreenInfo *)NULL && X sidx <= MAXSCREENS; sidx++) X { X if (strcmp (screen_name, menu->srn[sidx]->name) == 0) X break; X } X if (sidx > MAXSCREENS || menu->srn[sidx] == (struct ScreenInfo *)NULL) X { X BEEP; X mvprintw (ErrRow-2,0, "Could not find your screen definition."); X shutdown (); X } X X /* loop through each field */ X /* save current field data - if KEY_CANCEL reset to this */ X for (fidx = 0; SRN->field[fidx] != (struct FieldInfo *)NULL && X fidx <= MAXFIELDS; fidx++) X { X if (getenv(FLD->name) != (char *)NULL) X strcpy (fielddata[fidx], getenv (FLD->name)); X else X strcpy (fielddata[fidx], ""); X X X /* range values */ X if (strcmp (FLD->range, "") == 0) X tmprange[fidx] = (char *)NULL; X else if (FLD->range[0] != '`' && X FLD->range[strlen(FLD->range)-1] != '`') X { X /* not a command */ X tmprange[fidx] = (char *)malloc (strlen (FLD->range)+4); X strcpy (tmprange[fidx], FLD->range); X } X else if (FLD->range[0] == '`' && X FLD->range[strlen(FLD->range)-1] == '`' && X tmprange[fidx] == (char *)NULL) X { X /* we have a command to run - get new range values */ X /* junk the grave accents and ! if there is one */ X tmprange[fidx] = (char *) malloc (MAXLEN+4); X strcpy (tmprange[fidx], FLD->range+1); X if (tmprange[fidx][0] == '!') X strcpy (tmprange[fidx], FLD->range+2); X tmprange[fidx][strlen(tmprange[fidx])-1] = '\0'; 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 if (debug) X { X fprintf (stderr, X "\n[runscreen] <%s> popen=:%s:", X SRN->name, tmprange[fidx]); X fflush (stderr); X } X if ((pp = popen (tmprange[fidx], "r")) == (FILE *)NULL) X { X BEEP; X mvprintw (ErrRow-2,0, X "Could not open pipe = %s", tmprange[fidx]); X shutdown (); X } X fgets (tmprange[fidx], MAXLEN-1, pp); X tmprange[fidx][strlen(tmprange[fidx])-1] = '\0'; /* junk \n */ X pclose (pp); X } X } X X X /* set tmp variables used for AUTO */ X strcpy (Title, SRN->title); X Rows = SRN->rows; X Cols = SRN->cols; X X /* if title is set to AUTO then use the description text */ X if (atoi(Title) == AUTO) X { X strcpy (Title, menu->option[opnumber]->description); X /* junk ending period if there is one */ X if (Title[strlen(Title)-1] == '.') X Title[strlen(Title)-1] = '\0'; X } X X /* for SET and MENU type determine field_length */ X for (fidx = 0; SRN->field[fidx] != (struct FieldInfo *)NULL && X fidx <= MAXFIELDS; fidx++) X { X /* for SET and MENU types get field_length */ X if (FLD->type == SET || FLD->type == MENU) X FLD->length = GetSetLen (tmprange[fidx]); X } X X /* calculate window_rows & window_cols if AUTO */ X if (Rows == AUTO) X { X /* field with largest row + 4 */ X Rows = 0; X for (fidx = 0; SRN->field[fidx] != (struct FieldInfo *)NULL && X fidx <= MAXFIELDS; fidx++) X { X if (FLD->row > Rows) X Rows = FLD->row; X } X X /* make sure window is big enough to hold text stuff */ X for (i = 0; SRN->textinfo[i] != (struct TextInfo *)NULL; i++) X if (SRN->textinfo[i]->row + 1 > Rows) X Rows = SRN->textinfo[i]->row + 1; X Rows += 3; X } X if (Cols == AUTO) X { X /* field with largest col + length + 4 or title */ X /* make sure screen is big enough to hold the title */ X wsptr = Title; X strcpy (tmptitle, getval (&wsptr, '1')); X Cols = strlen (tmptitle); X for (fidx = 0; SRN->field[fidx] != (struct FieldInfo *)NULL && X fidx <= MAXFIELDS; fidx++) X { X if (strlen(FLD->mask) > 0) X { X if ((FLD->col + strlen(FLD->mask) + 1) > Cols) X Cols = FLD->col + strlen(FLD->mask) + 1; X } X else X if ((FLD->col + FLD->length + 1) > Cols) X Cols = FLD->col + FLD->length + 1; X } X X /* make sure window is big enough to hold text stuff */ X for (i = 0; SRN->textinfo[i] != (struct TextInfo *)NULL; i++) X if (SRN->textinfo[i]->col + X strlen(SRN->textinfo[i]->text) + 1 > Cols) X Cols = SRN->textinfo[i]->col + X strlen(SRN->textinfo[i]->text) + 1; X Cols += 2; X } X X /* use environment variable if there is one */ X wsptr = SRN->toprowvar; X if (strcmp (SRN->toprowvar, "") != 0) X toprow = atoi (getval (&wsptr, '1')); X else X toprow = SRN->toprow; X wsptr = SRN->leftcolvar; X if (strcmp (SRN->leftcolvar, "") != 0) X leftcol = atoi (getval (&wsptr, '1')); X else X leftcol = SRN->leftcol; X X if (toprow == AUTO) X { X /* X ** Figure out where to put the screen X ** try to put screen as close to the option as possible X */ X toprow = menu->option[opnumber]->row - 2; X /* X for (rc = 0, leftcol = 0; rc < menu->optioncount ; rc++) X if (strlen (menu->option[rc]->description) > leftcol) X leftcol = strlen (menu->option[rc]->description); X leftcol = menu->option[opnumber]->col + X ((leftcol + 4) / 2); X */ X leftcol = menu->option[opnumber]->col + X strlen(menu->option[opnumber]->description) + 4; X X /* make sure it fits on the screen */ X if ((toprow + Rows) > LINES-1) X toprow = LINES - Rows - 1; X toprow = toprow < 0 ? 0 : toprow; X X if ((leftcol + Cols + 2) > COLS) X leftcol = COLS - Cols - 1; X leftcol = leftcol < 0 ? 0 : leftcol; X } X X X /* create the window */ X swin = newwin (Rows, Cols, toprow, leftcol); X keypad (swin, TRUE); X X /* X ** check if recalculation of rows & cols is necessary X ** see newwin() for info on why X */ X if (Rows == 0 && Cols == 0 && X toprow == 0 && leftcol == 0) X { X /* a full-screen was created */ X Rows = LINES-1; X Cols = COLS; X } X else if (Rows == 0 || Cols == 0) X { X Rows = LINES - toprow; X Cols = COLS - leftcol; X if (Rows == LINES) X Rows--; X } X X X if (strcmp (SRN->helpfile, "") == 0) X helpflag = FALSE; X else X strcpy (helpfile, findfile (SRN->helpfile, ".", X getenv("HELPDIR"), getenv("MENUDIR"), "")); X drawbox (swin, 1,1, Rows,Cols, SRN->boxtype & 0777, X StandoutLine, FALSE, helpflag); X X /* display title */ X wsptr = Title; X strcpy (tmptitle, getval (&wsptr, '1')); X wattrset (swin, A_STANDOUT); X mvwprintw (swin, 0, ((Cols)/2)-(strlen(tmptitle)/2), "%s", tmptitle); X wattrset (swin, A_NORMAL); X X /* display text stuff */ X for (i = 0; SRN->textinfo[i] != (struct TextInfo *)NULL; i++) X displaytext (swin, SRN->textinfo[i]->row, SRN->textinfo[i]->col, X SRN->textinfo[i]->text); X X /* X ** Run fielddefaults if there is one and load results into $field_name X */ X if (SRN->fielddefaults != (char *)NULL) X { X if (debug) X { X fprintf (stderr, "\n[runscreen] <%s> popen=:%s:", X SRN->name, SRN->fielddefaults); X fflush (stderr); 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 if ((pp = popen (SRN->fielddefaults, "r")) == (FILE *)NULL) X { X BEEP; X mvprintw (ErrRow-2,0, "Could not open pipe = %s", X SRN->fielddefaults); X shutdown (); X } X X /* read and set each $field_name until no more input */ X rc = 99; X for (fidx = 0; SRN->field[fidx] != (struct FieldInfo *)NULL && X fidx <= MAXFIELDS; fidx++) X { X strcpy (value, ""); X if (rc == EOF) X { X if (debug) X { X fprintf (stderr, X "\n[runscreen] <%s> read nothing from popen", X SRN->name); X fprintf (stderr, X "\n[runscreen] <%s> field %s =:%s:", X SRN->name, FLD->name, value); X fflush (stderr); X } X continue; X } X X /* get a word from the pipe */ X rc = fscanf (pp, "%s", fmtdefault); X if (rc == EOF) continue; X if (debug) X { X fprintf (stderr, X "\n[runscreen] <%s> read from popen=:%s:", X SRN->name, fmtdefault); X fflush (stderr); X } X X X /* check for a quoted value */ X if (fmtdefault[0] == '"') X { X /* X ** found a quoted value X ** read until another quote or end of line X */ X strcpy (value, fmtdefault+1); /* junk 1st " */ X wsptr = value + strlen(value); X if (*(wsptr-1) == '"') X { X /* quote is on first word */ X *(wsptr-1) = '\0'; X } X else X { X while ((rc = fgetc (pp)) != EOF) X { X if ((*wsptr = (char)rc) == '"') X { X *wsptr = '\0'; X break; X } X wsptr++; X } /* end while */ X } X } X else X strcpy (value, fmtdefault); X if (debug) X { X fprintf (stderr, X "\n[runscreen] <%s> field %s =:%s:", X SRN->name, FLD->name, value); X fflush (stderr); X } X X /* set $field_name with new value */ X adjustfield (value, FLD->adjust, FLD->length); X rc = setenv (FLD->name, value); X } /* end for each field */ X pclose(pp); X } X X X X /* X ** display field stuff X ** Loop through each field X ** print the label X ** put in the field terminators X ** get, format and print default value in getenv () or fielddefault X */ X for (fidx = 0; SRN->field[fidx] != (struct FieldInfo *)NULL && X fidx <= MAXFIELDS; X fidx++) X { X /* print label */ X if (strlen(FLD->label) > 0) X mvwprintw (swin, FLD->row, X FLD->col - strlen(FLD->label) - 2, X "%s", FLD->label); X X /* print field terminators */ X if (strlen(FLD->terminator) > 0) X { X /* left */ X mvwprintw (swin, FLD->row, FLD->col - 1, X "%c", FLD->terminator[0]); X /* right */ X if (strlen(FLD->mask) > 0) X mvwprintw (swin, FLD->row, X FLD->col + strlen(FLD->mask), X "%c", FLD->terminator[1]); X else X mvwprintw (swin, FLD->row, X FLD->col + FLD->length, X "%c", FLD->terminator[1]); X } X X /* get default value from getenv() */ X if (getenv(FLD->name) != (char *)NULL) X strcpy (value, getenv (FLD->name)); X else X strcpy (value, ""); X X /* format default value to the mask */ X strcpy (fmtdefault, format (value, FLD->mask, FLD->type)); X /* print default data */ X if (strlen(fmtdefault) > 0) X mvwprintw (swin, FLD->row, FLD->col, "%s", fmtdefault); X } X fieldcount = fidx-1; /* save field count */ X X X /* X ** GetInput() from fields untill KEY_CANCEL || KEY_ACCEPT || X ** exit_last_field || exit_on_cancel X */ X if (promptptr == (char *)NULL || X strcmp (promptptr, "DONT_CLEAR") != 0) X { X move (ErrRow,0); clrtoeol(); X } X fidx = 0; /* start with first field */ X X do X { X NoInput = FLD->noinput; X /* run before_inpput command */ X if (FLD->before_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 (); SHAR_EOF echo "End of part 6" echo "File runscreen.c is continued in part 7" echo "7" > s2_seq_.tmp exit 0