home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2411 < prev    next >
Internet Message Format  |  1990-12-28  |  40KB

  1. From: pjc@pcbox.UUCP (Paul J. Condie)
  2. Newsgroups: alt.sources
  3. Subject: menu(1) part 6 of 14
  4. Message-ID: <440@pcbox.UUCP>
  5. Date: 26 Dec 90 20:08:44 GMT
  6.  
  7.  
  8. #!/bin/sh
  9. # this is part 6 of a multipart archive
  10. # do not concatenate these parts, unpack them in order with /bin/sh
  11. # file SetTerm.c continued
  12. #
  13. CurArch=6
  14. if test ! -r s2_seq_.tmp
  15. then echo "Please unpack part 1 first!"
  16.      exit 1; fi
  17. ( read Scheck
  18.   if test "$Scheck" != $CurArch
  19.   then echo "Please unpack part $Scheck next!"
  20.        exit 1;
  21.   else exit 0; fi
  22. ) < s2_seq_.tmp || exit 1
  23. echo "x - Continuing file SetTerm.c"
  24. sed 's/^X//' << 'SHAR_EOF' >> SetTerm.c
  25. Xint    KeySave        = 6;    /* ^f - GetInput save screen to a file */
  26. Xint    KeyPrint    = 16;    /* ^p - GetInput prints screen to lp */
  27. Xint    KeyAccept    = 1;    /* ^a - GetInput accepts input */
  28. X
  29. X
  30. X/* Menu Specific */
  31. Xint    HotKeys        = 0;    /* for hot keyboard */
  32. Xint    KeyMainMenu    = 'm';    /* goto main menu */
  33. Xint    KeyPrevMenu    = 'p';    /* goto previous menu */
  34. Xint    KeyExitMenu    = 'e';    /* exit menu */
  35. Xint    KeyGname    = 'g';    /* goto a specific menu (dumb) */
  36. Xint    KeyPopGname    = 7;    /* ^g  - goto a specific menu (popmenu) */
  37. X
  38. X
  39. X
  40. XSetTerm ()
  41. X{
  42. X    FILE    *fopen(), *menuinit;
  43. X    char    *getenv();
  44. X    char    *findfile();
  45. X    char    *strchr();
  46. X    char    *ws;
  47. X    char    filename[100], line[BUFSIZE];
  48. X    char    *s1;
  49. X
  50. X
  51. X    char    *terminal;
  52. X
  53. X    /*
  54. X    **  Parse the .menuinit file
  55. X    **  First look in current directory then $HOME then in $MENUDIR
  56. X    */
  57. X    strcpy (filename, findfile (MENUINIT, ".", 
  58. X        (char *)getenv("HOME"), (char *)getenv("MENUDIR"), ""));
  59. X    if ((menuinit = fopen (filename, "r")) == NULL)
  60. X    {
  61. X        /* no file found - use the defaults */
  62. X        return (0);
  63. X    }
  64. X
  65. X    /* set terminal keys */
  66. X    while (fgets (line, BUFSIZE, menuinit) != (char *)NULL)
  67. X    {
  68. X        if (strncmp ("HOTKEYS", line, 7) == 0)
  69. X            HotKeys = 1;
  70. X            
  71. X        /*
  72. X        **  The following keywords require a = sign
  73. X        */
  74. X
  75. X        if ((s1 = strchr (line, '=')) == (char *)NULL)
  76. X            continue;
  77. X
  78. X        s1++;                    /* get past the = */
  79. X
  80. X        /* Mover Keys */
  81. X        if (strncmp ("KEY_RETURN", line, 10) == 0)
  82. X            sscanf (s1, "%d", &KeyReturn);
  83. X        else if (strncmp ("KEY_DOWN", line, 8) == 0)
  84. X            sscanf (s1, "%d", &KeyDown);
  85. X        else if (strncmp ("KEY_UP", line, 6) == 0)
  86. X            sscanf (s1, "%d", &KeyUp);
  87. X        else if (strncmp ("KEY_TAB", line, 7) == 0)
  88. X            sscanf (s1, "%d", &KeyTab);
  89. X        else if (strncmp ("KEY_BTAB", line, 8) == 0)
  90. X            sscanf (s1, "%d", &KeyBTab);
  91. X
  92. X        /* Edit Keys */
  93. X        else if (strncmp ("KEY_BEG", line, 7) == 0)
  94. X            sscanf (s1, "%d", &KeyBeg);
  95. X        else if (strncmp ("KEY_END", line, 7) == 0)
  96. X            sscanf (s1, "%d", &KeyEnd);
  97. X        else if (strncmp ("KEY_RIGHT", line, 9) == 0)
  98. X            sscanf (s1, "%d", &KeyRight);
  99. X        else if (strncmp ("KEY_LEFT", line, 8) == 0)
  100. X            sscanf (s1, "%d", &KeyLeft);
  101. X        else if (strncmp ("KEY_BACKSPACE", line, 13) == 0)
  102. X            sscanf (s1, "%d", &KeyBackspace);
  103. X        else if (strncmp ("KEY_EOL", line, 13) == 0)
  104. X            sscanf (s1, "%d", &KeyEOL);
  105. X        else if (strncmp ("KEY_DL", line, 14) == 0)
  106. X            sscanf (s1, "%d", &KeyDL);
  107. X        else if (strncmp ("KEY_DC", line, 6) == 0)
  108. X            sscanf (s1, "%d", &KeyDC);
  109. X        else if (strncmp ("KEY_IC", line, 6) == 0)
  110. X            sscanf (s1, "%d", &KeyIC);
  111. X
  112. X        /* Other Keys */
  113. X        else if (strncmp ("KEY_HELP", line, 8) == 0)
  114. X            sscanf (s1, "%d", &KeyHelp);
  115. X        else if (strncmp ("KEY_REFRESH", line, 10) == 0)
  116. X            sscanf (s1, "%d", &KeyRedraw);
  117. X        else if (strncmp ("KEY_ACCEPT", line, 10) == 0)
  118. X            sscanf (s1, "%d", &KeyAccept);
  119. X        else if (strncmp ("KEY_CANCEL", line, 10) == 0)
  120. X            sscanf (s1, "%d", &KeyCancel);
  121. X        else if (strncmp ("KEY_SAVE", line, 8) == 0)
  122. X            sscanf (s1, "%d", &KeySave);
  123. X        else if (strncmp ("KEY_PRINT", line, 9) == 0)
  124. X            sscanf (s1, "%d", &KeyPrint);
  125. X        else if (strncmp ("KEY_EXITMENU", line, 12) == 0)
  126. X            sscanf (s1, "%d", &KeyExitMenu);
  127. X        else if (strncmp ("KEY_MAINMENU", line, 12) == 0)
  128. X            sscanf (s1, "%d", &KeyMainMenu);
  129. X        else if (strncmp ("KEY_PREVMENU", line, 12) == 0)
  130. X            sscanf (s1, "%d", &KeyPrevMenu);
  131. X        else if (strncmp ("KEY_GNAME", line, 9) == 0)
  132. X            sscanf (s1, "%d", &KeyGname);
  133. X        else if (strncmp ("KEY_POPGNAME", line, 12) == 0)
  134. X            sscanf (s1, "%d", &KeyPopGname);
  135. X        else if (strncmp ("KEY_TOC", line, 7) == 0)
  136. X            sscanf (s1, "%d", &KeyTOC);
  137. X    }
  138. X    fclose (menuinit);
  139. X    return (0);
  140. X}
  141. X/* Paul J. Condie  11/88 */
  142. SHAR_EOF
  143. echo "File SetTerm.c is complete"
  144. chmod 0644 SetTerm.c || echo "restore of SetTerm.c fails"
  145. echo "x - extracting systime.c (Text)"
  146. sed 's/^X//' << 'SHAR_EOF' > systime.c &&
  147. X#ifndef LINT
  148. Xstatic char Sccsid[] = "@(#)systime.c    1.2   DeltaDate 5/6/88   ExtrDate 1/22/90";
  149. X#endif
  150. X
  151. X#include <stdio.h>
  152. X#include <time.h>
  153. X
  154. Xsystime (timeStr, mask)
  155. X
  156. X    char *timeStr, *mask;
  157. X{
  158. X    long        tloc ;
  159. X    struct tm      *ltime, *localtime() ;
  160. X    char         tmpstr[4] ;
  161. X    int        tmpval;
  162. X
  163. X   tloc = time((long *) 0) ;
  164. X   ltime = localtime(&tloc) ;
  165. X
  166. X   ltime->tm_mon++;
  167. X
  168. X   if (mask == NULL)
  169. X   {
  170. X      sprintf (timeStr, "%2d:%02d:%02d", ltime->tm_hour, ltime->tm_min, 
  171. X           ltime->tm_sec) ;
  172. X   }
  173. X   else
  174. X      while (*mask != '\0')
  175. X      {
  176. X         switch (*mask)
  177. X         {
  178. X            case 'H':
  179. X            if (ltime->tm_hour > 12)
  180. X            {
  181. X               tmpval = ltime->tm_hour - 12;
  182. X               sprintf (tmpstr, "%2d", tmpval);
  183. X            }
  184. X            else
  185. X               sprintf (tmpstr, "%2d", ltime->tm_hour);
  186. X                break;
  187. X        case 'M':
  188. X            sprintf (tmpstr, "%02d", ltime->tm_min);
  189. X            break;
  190. X        case 'S':
  191. X            sprintf (tmpstr, "%02d", ltime->tm_sec);
  192. X            break;
  193. X        case 'I':
  194. X            sprintf (tmpstr, "%2d", ltime->tm_hour);
  195. X            break;
  196. X        case 'Z':
  197. X            if (ltime->tm_hour >= 12)
  198. X               strcpy (tmpstr, "PM");
  199. X            else
  200. X               strcpy (tmpstr, "AM");
  201. X            break;
  202. X        case 'z':
  203. X            if (ltime->tm_hour >= 12)
  204. X               strcpy (tmpstr, "pm");
  205. X            else
  206. X               strcpy (tmpstr, "am");
  207. X            break;
  208. X        default:
  209. X            *timeStr = *mask;
  210. X            timeStr++;
  211. X            mask++;
  212. X            continue;
  213. X         }   /* end switch */
  214. X         *timeStr = tmpstr[0];
  215. X     timeStr++;
  216. X         *timeStr = tmpstr[1];
  217. X     timeStr++;
  218. X         mask += 2;
  219. X      }  /* end while */
  220. X
  221. X   *timeStr = '\0';
  222. X   return (0);
  223. X}
  224. SHAR_EOF
  225. chmod 0444 systime.c || echo "restore of systime.c fails"
  226. echo "x - extracting sysdate.c (Text)"
  227. sed 's/^X//' << 'SHAR_EOF' > sysdate.c &&
  228. X#ifndef LINT
  229. Xstatic char Sccsid[] = "@(#)sysdate.c    1.1   DeltaDate 9/6/87   ExtrDate 1/22/90";
  230. X#endif
  231. X
  232. X#include    <time.h>
  233. X
  234. Xsysdate (dateStr, mask)
  235. X
  236. X    char *dateStr, *mask;
  237. X{
  238. X    long        tloc ;
  239. X    struct tm      *ltime, *localtime() ;
  240. X
  241. Xstatic    char        *shortmon[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
  242. X                          "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
  243. X
  244. Xstatic    char        *longmon[]= 
  245. X          {"January","February","March","April","May","June",
  246. X           "July","August","September","October","November","December"};
  247. X
  248. Xstatic    char        *shortday[]= {"sun","mon","tue","wed","thr","fri","sat"};
  249. X
  250. Xstatic    char        *longday[]= {"Sunday","Monday","Tuesday","Wednessday",
  251. X                        "Thursday", "Friday", "Saturday"};
  252. X
  253. X
  254. X   tloc = time ((long *) 0) ;
  255. X   ltime = localtime (&tloc) ;
  256. X
  257. X   while (*mask != '\0')
  258. X   {
  259. X
  260. X/*
  261. X**    Process month
  262. X*/
  263. X      if (strncmp (mask, "mmmmm", 5) == 0)
  264. X      {
  265. X     sprintf (dateStr, "%s", longmon[ltime->tm_mon]);
  266. X     mask += 5;
  267. X     dateStr += strlen (longmon[ltime->tm_mon]);
  268. X     continue;
  269. X      }
  270. X      else
  271. X         if (strncmp (mask, "mmm", 3) == 0)
  272. X         {
  273. X            sprintf (dateStr, "%s", shortmon [ltime->tm_mon]);
  274. X        mask += 3;
  275. X        dateStr += 3;
  276. X        continue;
  277. X         }
  278. X     else
  279. X        if (strncmp (mask, "mm", 2) == 0)
  280. X        {
  281. X           sprintf (dateStr, "%.2d", ltime->tm_mon + 1);
  282. X           mask += 2;
  283. X           dateStr += 2;
  284. X            continue;
  285. X        }
  286. X
  287. X/*
  288. X**    Process day
  289. X*/
  290. X      if (strncmp (mask, "ddddd", 5) == 0)
  291. X      {
  292. X         sprintf (dateStr, "%s", longday [ ltime->tm_wday ]);
  293. X     mask += 5;
  294. X     dateStr += strlen (longday[ltime->tm_wday]);
  295. X     continue;
  296. X      }
  297. X      else
  298. X         if (strncmp (mask, "ddd", 3) == 0)
  299. X         {
  300. X            sprintf (dateStr, "%s", shortday [ltime->tm_wday]);
  301. X        mask += 3;
  302. X        dateStr += 3;
  303. X        continue;
  304. X         }
  305. X         else
  306. X            if (strncmp (mask, "dd", 2) == 0)
  307. X        {
  308. X           sprintf (dateStr, "%.2d", ltime->tm_mday);
  309. X           mask += 2;
  310. X           dateStr += 2;
  311. X           continue;
  312. X        }
  313. X      if (strncmp (mask, "jjj", 3) == 0)
  314. X      {
  315. X         sprintf (dateStr, "%3d", ltime->tm_yday + 1);
  316. X     mask += 3;
  317. X     dateStr += 3;
  318. X     continue;
  319. X      }
  320. X
  321. X/*
  322. X**    Process year
  323. X*/
  324. X      if (strncmp (mask, "yyyy", 4) == 0)
  325. X      {
  326. X         sprintf (dateStr, "19%.2d", ltime->tm_year);
  327. X     mask += 4;
  328. X     dateStr += 4;
  329. X     continue;
  330. X      }
  331. X      else
  332. X         if (strncmp (mask, "yy", 2) == 0)
  333. X     {
  334. X        sprintf (dateStr, "%.2d", ltime->tm_year);
  335. X        mask += 2;
  336. X        dateStr += 2;
  337. X        continue;
  338. X      }
  339. X
  340. X/*
  341. X**    Process mask
  342. X*/
  343. X      *dateStr = *mask;
  344. X      dateStr++;
  345. X      mask++;
  346. X   }
  347. X
  348. X   *dateStr = '\0';
  349. X   return (0);
  350. X}
  351. SHAR_EOF
  352. chmod 0444 sysdate.c || echo "restore of sysdate.c fails"
  353. echo "x - extracting checkmail.c (Text)"
  354. sed 's/^X//' << 'SHAR_EOF' > checkmail.c &&
  355. X#ifndef LINT
  356. Xstatic char Sccsid[] = "@(#)checkmail.c    1.3   DeltaDate 1/22/90   ExtrDate 1/22/90";
  357. X#endif
  358. X
  359. X#include    <curses.h>
  360. X#include    <signal.h>
  361. X
  362. X#ifndef BELL
  363. X#define    BELL        printf ("%c", 7);
  364. X#endif
  365. X
  366. Xextern    int        mailrow;
  367. Xextern    int        mailcol;
  368. X
  369. Xcheckmail ()
  370. X{
  371. X    int        rc;
  372. X    static int    mailcheck = 30;            /* default */
  373. X
  374. X#ifdef ALARM
  375. X    alarm (0);                    /* turn off alarm */
  376. X#endif
  377. X    if ((rc = anymail()) != FALSE)
  378. X    {
  379. X        /* we got mail */
  380. X        attrset (A_REVERSE);
  381. X        if (rc == 1  ||  rc == 3)
  382. X            mvprintw (mailrow,mailcol, "MAIL");
  383. X        else
  384. X            mvprintw (mailrow,mailcol, "EMAIL");
  385. X        attrset (A_NORMAL);
  386. X#ifdef ALARM
  387. X        BELL;
  388. X#endif
  389. X    }
  390. X    else
  391. X        mvprintw (mailrow,mailcol, "    ");
  392. X
  393. X#ifdef ALARM
  394. X    signal (SIGALRM, checkmail);
  395. X    if ((char *)getenv("MAILCHECK") != (char *)0)
  396. X        sscanf ((char *)getenv("MAILCHECK"), "%d", &mailcheck);
  397. X    if (mailcheck < 10)
  398. X        mailcheck = 10;
  399. X    alarm (mailcheck);                /* set alarm again */
  400. X#endif
  401. X}
  402. X/* Paul J. Condie  4/88 */
  403. SHAR_EOF
  404. chmod 0444 checkmail.c || echo "restore of checkmail.c fails"
  405. echo "x - extracting anymail.c (Text)"
  406. sed 's/^X//' << 'SHAR_EOF' > anymail.c &&
  407. X#ifndef LINT
  408. Xstatic char Sccsid[] = "@(#)anymail.c    1.3   DeltaDate 1/22/90   ExtrDate 1/22/90";
  409. X#endif
  410. X
  411. X/*    FUNCTION:    anymail()
  412. X**            If the first word in the mail file is Forward it returns
  413. X**            no mail.
  414. X**    RETURNS:    FALSE    - no unix or email.
  415. X**            1    - unix mail.
  416. X**            2    - email
  417. X**            3    - both unix and email
  418. X*/
  419. X#include    <stdio.h>
  420. X#include    <sys/types.h>
  421. X#include    <sys/stat.h>
  422. X
  423. Xanymail ()
  424. X{
  425. X    FILE        *fopen(), *fp;
  426. X    char        *getenv();
  427. X    struct stat    Statbuf;
  428. X    int        rc = 0;                /* return code */
  429. X    char        *mailfile;
  430. X    static int    FIRST_TIME = 1;
  431. X    static int    FORWARDFLAG = 0;
  432. X    char        tmpstr[80];
  433. X
  434. X
  435. X   if ((mailfile = getenv("MAIL")) != (char *)0)
  436. X       if (stat (mailfile, &Statbuf) == 0)  
  437. X       {
  438. X        /* there is a mail file */
  439. X        if (Statbuf.st_size > 0)
  440. X        {
  441. X            /* there is something in the mail file */
  442. X            if (FIRST_TIME)
  443. X            {
  444. X                /* check to see if mail is being Forwarded */
  445. X                FIRST_TIME = 0;
  446. X                if ((fp=fopen (mailfile, "r")) != (FILE *)NULL)
  447. X                {
  448. X                    fscanf (fp, "%s", tmpstr);
  449. X                    if (strcmp (tmpstr, "Forward") == 0)
  450. X                        FORWARDFLAG = 1;
  451. X                    fclose (fp);
  452. X                }
  453. X            }
  454. X            if (!FORWARDFLAG)
  455. X                rc = 1;
  456. X        }
  457. X       }
  458. X   if ((mailfile = getenv("EMAIL")) != (char *)0)
  459. X       if (stat (mailfile, &Statbuf) == 0) 
  460. X       {
  461. X        if (Statbuf.st_size > 0)
  462. X            rc = rc == 1 ? 3 : 2;
  463. X       }
  464. X   return (rc);
  465. X}
  466. SHAR_EOF
  467. chmod 0444 anymail.c || echo "restore of anymail.c fails"
  468. echo "x - extracting setenv.c (Text)"
  469. sed 's/^X//' << 'SHAR_EOF' > setenv.c &&
  470. X#ifndef LINT
  471. Xstatic char Sccsid[] = "@(#)setenv.c    1.2   DeltaDate 1/22/90   ExtrDate 1/22/90";
  472. X#endif
  473. X
  474. X/* PROGRAM NAME:  @(#)setenv.c    1.2  
  475. X*  REVISION DATE: 
  476. X*  REVISION LEVEL:
  477. X*  CONTACT PERSON: Library Staff
  478. X*  AUTHOR: Stephen J. Muir 
  479. X*  ABSTRACT: setenv/delenv - add, change or delete environment variables
  480. X*  KEYWORDS: environment, shell, getenv
  481. X*  DESCRIPTION: Setenv allows a program to set environment variables.
  482. X*          delenv allows a program to delete environment variables.
  483. X*  PROJECTS: 
  484. X*  SOFTWARE CATEGORY: application development tools
  485. X*  COPYRIGHT:              Notice
  486. X   This is the confidential, unpublished property of Pacific Bell.
  487. X   Receipt or possession of it does not convey any rights to divulge,
  488. X   reproduce, use, or allow others to use it without the specific written
  489. X   authorization of Pacific Bell and use must conform strictly to
  490. X   the license agreement between user and Pacific Bell.
  491. X
  492. X      COPYRIGHT (c) 1986 Pacific Bell. All Rights Reserved. 
  493. X
  494. X*  OPERATING ENVIRONMENT: all standard AT&T UNIX machines.
  495. X*  SOFTWARE DEPENDENCIES: none.
  496. X*  HARDWARE DEPENDENCIES: 
  497. X*  LIMITATIONS: 
  498. X*  DOCUMENTATION: setenv.3 manual page
  499. X*  COMPILE COMMAND: cc setenv.c 
  500. X*  SIZE: 
  501. X*  SUPPORT LEVEL:
  502. X*  MODULE LIST:
  503. X*/
  504. X# include <string.h>
  505. X
  506. X/* This is the number of extra array elements to allocate each time it becomes
  507. X * necessary.
  508. X */
  509. X# define INC    10
  510. X
  511. Xextern char    **environ, *malloc ();
  512. Xextern int    free ();
  513. X
  514. Xstatic char    **original, **current, **limit;
  515. X
  516. X/* This routine should be called only once (when either "setenv" or "delenv" is
  517. X * called for the first time).  It would only be called again if it fails due
  518. X * to lack of memory.  It makes a copy of the original environment because the
  519. X * original environment array and its elements were not obtained from "malloc"
  520. X * and the "free" routine cannot, therefore, be called with any of its
  521. X * elements.
  522. X *
  523. X * return values:
  524. X *     0: success
  525. X *    -1: out of memory - nothing has changed
  526. X */
  527. Xstatic    /* this is a private routine */
  528. Xinitialise ()
  529. X    { register char    **old, **new_ptr, *tmp, **new_env;
  530. X
  531. X      /* count number of existing strings */
  532. X      for (old = environ; *old; ++old)
  533. X        ;
  534. X
  535. X      /* make space for extra strings */
  536. X      if ((new_ptr =
  537. X           new_env =
  538. X           (char **)malloc (sizeof (char **) * ((old - environ) + INC + 1))
  539. X          )
  540. X          == 0
  541. X         )
  542. X        return (-1);
  543. X
  544. X      /* "limit" points to the last element of the array -- it is used to
  545. X       * decide when to recreate it
  546. X       */
  547. X      limit = new_env + (old - environ) + INC;
  548. X
  549. X      /* copy across old strings */
  550. X      for (old = environ; *old; ++old)
  551. X      { if ((tmp = malloc (strlen (*old) + 1)) == 0)
  552. X        { /* out of memory -- undo everything */
  553. X          while (new_ptr != new_env)
  554. X        free (*--new_ptr);
  555. X          free ((char *)new_ptr);
  556. X          return (-1);
  557. X        }
  558. X        strcpy (tmp, *old);
  559. X        *new_ptr++ = tmp;
  560. X      }
  561. X      /* "current" points to the null pointer at the end of the array */
  562. X      *(current = new_ptr) = 0;
  563. X
  564. X      /* this is really just a flag to say it's initialised */
  565. X      original = environ;
  566. X      /* overwrite old environment with new */
  567. X      environ = new_env;
  568. X      return (0);
  569. X    }
  570. X
  571. X/* This is a special routine to compare a string "name" of the form "NAME" with
  572. X * a string "name_value" of the form "NAME=VALUE".  It returns zero if the
  573. X * comparison is successful
  574. X */
  575. Xstatic    /* this is a private routine */
  576. Xdiffer (name, name_value)
  577. X    char    *name, *name_value;
  578. X    { while (*name && *name_value)
  579. X        if (*name++ != *name_value++)
  580. X            return (1);
  581. X      return (*name_value != '=');
  582. X    }
  583. X
  584. X/* This routine deletes an environment variable, e.g. delenv ("SHELL");
  585. X *
  586. X * return values:
  587. X *     0: success
  588. X *     1: environment variable not found
  589. X *    -1: out of memory - nothing has changed
  590. X */
  591. Xdelenv (name)
  592. X    char    *name;
  593. X    { register char    **ptr;
  594. X
  595. X      /* initialise if necessary */
  596. X      if (original == 0 && initialise ())
  597. X        return (-1);
  598. X
  599. X      /* attempt to find it */
  600. X      for (ptr = environ; *ptr && differ (name, *ptr); ++ptr)
  601. X        ;
  602. X      if (*ptr == 0)
  603. X        return (1);    /* not found */
  604. X
  605. X      /* delete it */
  606. X      free (*ptr);
  607. X      *ptr = *--current;
  608. X      *current = 0;
  609. X      return (0);
  610. X    }
  611. X
  612. X/* This routine sets a new environment variable, replacing an existing one
  613. X * where appropriate, e.g. setenv ("SHELL", "/bin/csh");
  614. X *
  615. X * return values:
  616. X *     0: success
  617. X *    -1: out of memory - nothing has changed
  618. X */
  619. Xsetenv (name, value)
  620. X    char    *name, *value;
  621. X    { register char    **old, **new_ptr, *cp, *tmp, **new_env;
  622. X
  623. X      /* initialise if necessary */
  624. X      if (original == 0 && initialise ())
  625. X        return (-1);
  626. X
  627. X      /* allocate space for the new string */
  628. X      if ((cp = tmp = malloc (strlen (name) + strlen (value) + 2)) == 0)
  629. X        return (-1);
  630. X
  631. X      /* find an existing one if we can - we do this now as we will lose
  632. X       * the original "name" pointer in the while loop following
  633. X       */
  634. X      for (old = environ; *old && differ (name, *old); ++old)
  635. X        ;
  636. X
  637. X      /* make the new entry */
  638. X      while (*name)
  639. X        *cp++ = *name++;
  640. X      *cp++ = '=';
  641. X      while (*value)
  642. X        *cp++ = *value++;
  643. X      *cp = '\0';
  644. X
  645. X      /* case 1: overwrite previous value */
  646. X      if (*old)
  647. X      { free (*old);
  648. X        *old = tmp;
  649. X      }
  650. X
  651. X      /* case 2: no previous value and no space left - allocate more */
  652. X      else if (current == limit)
  653. X      { if ((new_ptr =
  654. X         new_env =
  655. X         (char **)malloc (sizeof (char **) *
  656. X                  ((old - environ) + INC + 1)
  657. X                 )
  658. X        ) == 0
  659. X           )
  660. X        { free (tmp);
  661. X          return (-1);
  662. X        }
  663. X        limit = new_env + (old - environ) + INC;
  664. X        for (old = environ; *old; )
  665. X        *new_ptr++ = *old++;
  666. X        *new_ptr++ = tmp;
  667. X        *(current = new_ptr) = 0;
  668. X        free ((char *)environ);
  669. X        environ = new_env;
  670. X      }
  671. X
  672. X      /* case 3: no previous value and there is enough space */
  673. X      else
  674. X      { *current++ = tmp;
  675. X        *current = 0;
  676. X      }
  677. X      return (0);
  678. X    }
  679. SHAR_EOF
  680. chmod 0444 setenv.c || echo "restore of setenv.c fails"
  681. echo "x - extracting strmatch.c (Text)"
  682. sed 's/^X//' << 'SHAR_EOF' > strmatch.c &&
  683. X#ifndef LINT
  684. Xstatic char Sccsid[] = "@(#)strmatch.c    1.1   DeltaDate 10/20/88   ExtrDate 1/22/90";
  685. X#endif
  686. X
  687. X#ifndef    TRUE
  688. X#define    TRUE    1
  689. X#endif
  690. X#ifndef    FALSE
  691. X#define    FALSE    0
  692. X#endif
  693. X#ifndef    BOOL
  694. X#define    BOOL    int
  695. X#endif
  696. X
  697. X#define    M_ALL    '*'
  698. X#define    M_ONE    '?'
  699. X#define    M_SET    '['
  700. X#define    M_RNG    '-'
  701. X#define    M_END    ']'
  702. X
  703. X
  704. XBOOL strmatch (name, pat)
  705. X
  706. X    char        *name, *pat;
  707. X{
  708. X       char        c, k;
  709. X    BOOL        ok;
  710. X
  711. X
  712. X   while ((c = *pat++) != '\0')
  713. X   {
  714. X      switch (c)
  715. X      {
  716. X     case M_ONE:
  717. X        if (*name++ == '\0')   return (FALSE);
  718. X        break;
  719. X    
  720. X    case M_ALL:
  721. X        if (*pat == '\0')   return (TRUE);
  722. X        for (; *name != '\0'; ++name)
  723. X           if (strmatch (name, pat))   return (TRUE);
  724. X        return (FALSE);
  725. X
  726. X    case M_SET:
  727. X        ok = FALSE;
  728. X        k = *name++;
  729. X        while ((c = *pat++) != M_END)
  730. X           if (*pat == M_RNG)
  731. X           {
  732. X              if (c <= k  &&  k <= pat[1])
  733. X             ok = TRUE;
  734. X              pat += 2;
  735. X           }
  736. X           else
  737. X              if (c == k)   ok = TRUE;
  738. X        if (!ok)   return (FALSE);
  739. X        break;
  740. X
  741. X    default:
  742. X        if (*name++ != c)   return (FALSE);
  743. X        break;
  744. X      }
  745. X   }
  746. X   return (*name == '\0');
  747. X}
  748. SHAR_EOF
  749. chmod 0444 strmatch.c || echo "restore of strmatch.c fails"
  750. echo "x - extracting setvar.c (Text)"
  751. sed 's/^X//' << 'SHAR_EOF' > setvar.c &&
  752. X#ifndef LINT
  753. Xstatic char Sccsid[] = "%W%   DeltaDate %G%   ExtrDate %H%";
  754. X#endif
  755. X
  756. X#include    <curses.h>
  757. X#include    <ctype.h>
  758. X#include    <string.h>
  759. X#include    "menu.h"
  760. X
  761. X
  762. X
  763. Xsetvariable (cptr)
  764. X    char    **cptr;                /* command pointer var=value */
  765. X{
  766. X    char    *getenv();
  767. X    char    *getval();
  768. X    char    variable[100];
  769. X    char    value[100];
  770. X    int    rc;                /* return code */
  771. X    int    i, j;
  772. X
  773. X    if (*cptr == (char *)NULL)   return (EOF);
  774. X
  775. X    /* skip junk characters */
  776. X    for (;**cptr != '\0' &&  (!isalpha(**cptr)) && (!isdigit(**cptr)); 
  777. X          (*cptr)++) 
  778. X        if (**cptr == '!')
  779. X            break;
  780. X        ;
  781. X    if (**cptr == '\0') return (EOF);    /* end of line */
  782. X
  783. X    /* get the enviroment variable */
  784. X    for (i = 0; **cptr != '=' && **cptr != '\0'; i++, (*cptr)++)
  785. X        variable[i] = **cptr;
  786. X    variable[i] = '\0';
  787. X    if (strcmp (variable, "") == 0  ||  **cptr != '=')
  788. X    {
  789. X        BEEP;
  790. X        mvprintw (ErrRow-2, 0, 
  791. X           "Error occured while setting enviroment variable %s",
  792. X           variable);
  793. X        shutdown ();
  794. X    }
  795. X    (*cptr)++;                    /* get past the = */
  796. X
  797. X    strcpy (value, getval (cptr, '0'));
  798. X
  799. X    /* set the enviroment variable */
  800. X    if (variable[0] == '!')
  801. X    {
  802. X        /*
  803. X        **  if !
  804. X        **     then only set if not already set
  805. X        */
  806. X        /* junk ! - shift left one */
  807. X        for (i = 0; variable[i] != '\0'; i++)
  808. X            variable[i] = variable[i+1];
  809. X        rc = 0;
  810. X        if (getenv(variable) == (char *)NULL)
  811. X            rc = setenv (variable, value);
  812. X    }
  813. X    else
  814. X        rc = setenv (variable, value);
  815. X    if (rc != 0)
  816. X    {
  817. X        BEEP;
  818. X        mvprintw (ErrRow-2, 0, 
  819. X           "Error occured while setting enviroment variable %s",
  820. X           variable);
  821. X        shutdown ();
  822. X    }
  823. X    return (0);
  824. X}
  825. X/* Paul J. Condie  10/88 */
  826. SHAR_EOF
  827. chmod 0644 setvar.c || echo "restore of setvar.c fails"
  828. echo "x - extracting drawline.c (Text)"
  829. sed 's/^X//' << 'SHAR_EOF' > drawline.c &&
  830. X#ifndef LINT
  831. Xstatic char Sccsid[] = "@(#)drawline.c    1.2   DeltaDate 1/22/90   ExtrDate 1/22/90";
  832. X#endif
  833. X
  834. X#include    <curses.h>
  835. X#include    <term.h>
  836. X
  837. X#define    DumbLine    1    /* A_NORMAL */
  838. X#define    StandoutLine    2    /* A_STANDOUT */
  839. X#define    SingleLine    3    /* A_ALTCHARSET */
  840. X#define    MosaicLine    4    /* A_ALTCHARSET */
  841. X#define    DiamondLine    5    /* A_ALTCHARSET */
  842. X#define    DotLine        6    /* A_ALTCHARSET */
  843. X#define    PlusLine    7    /* A_ALTCHARSET */
  844. X
  845. X#define    CANDRAWGRAPHICS    (enter_alt_charset_mode != NULL  && \
  846. X             strcmp(enter_alt_charset_mode, "") != 0)
  847. X
  848. X
  849. Xdrawline (win, row, trythis, trythat, box)
  850. X    WINDOW    *win;
  851. X    int    row;
  852. X    int    trythis;
  853. X    int    trythat;
  854. X    int    box;
  855. X{
  856. X    int    col;
  857. X    int    hchar;                    /* horizonal char */
  858. X    int    lchar;                    /* left char */
  859. X    int    rchar;                    /* right char */
  860. X    int    attribute;
  861. X    int    boxtype;
  862. X
  863. X
  864. X    boxtype = trythis;
  865. X    attribute = (boxtype == DumbLine || boxtype == StandoutLine) ? A_NORMAL : A_ALTCHARSET;
  866. X    if (attribute == A_ALTCHARSET)
  867. X        /* can this terminal do graphics ? */
  868. X        boxtype = CANDRAWGRAPHICS ? trythis : trythat;
  869. X
  870. X    switch (boxtype)
  871. X    {
  872. X       case DumbLine:
  873. X        /* draw a dumb line */
  874. X        hchar = '-';
  875. X        lchar = '+';
  876. X        rchar = '+';
  877. X        break;
  878. X
  879. X       case StandoutLine:
  880. X        /* draw a standout line */
  881. X        attribute = A_STANDOUT;
  882. X        hchar = ' ';
  883. X        lchar = ' ';
  884. X        rchar = ' ';
  885. X        break;
  886. X
  887. X       case SingleLine:
  888. X        /* attempt to draw a graphic single line */
  889. X        hchar = 'q';
  890. X        lchar = 't';
  891. X        rchar = 'u';
  892. X        break;
  893. X
  894. X       case MosaicLine:
  895. X        hchar = 'a';
  896. X        lchar = 'a';
  897. X        rchar = 'a';
  898. X        break;
  899. X
  900. X       case DiamondLine:
  901. X        hchar = '`';
  902. X        lchar = '`';
  903. X        rchar = '`';
  904. X        break;
  905. X
  906. X       case DotLine:
  907. X        hchar = '~';
  908. X        lchar = '~';
  909. X        rchar = '~';
  910. X        break;
  911. X
  912. X       case PlusLine:
  913. X        hchar = 'n';
  914. X        lchar = 'n';
  915. X        rchar = 'n';
  916. X        break;
  917. X        break;
  918. X
  919. X       default:
  920. X        return (-1);
  921. X    }
  922. X
  923. X#ifdef BSD
  924. X       standout ();
  925. X#else
  926. X       wattrset (win, attribute);
  927. X#endif
  928. X       for (col = 0; col <= COLS-1; col++)
  929. X              mvwaddch (win, row, col, hchar);
  930. X
  931. X    if (box)
  932. X    {
  933. X        mvwaddch (win, row, 0, lchar);
  934. X        mvwaddch (win, row, COLS-1, rchar);
  935. X    }
  936. X
  937. X#ifdef BSD
  938. X       standend ();
  939. X#else
  940. X       wattrset (win, A_NORMAL);
  941. X#endif
  942. X    return (0);
  943. X}
  944. X/* Paul J. Condie  10/88 */
  945. SHAR_EOF
  946. chmod 0444 drawline.c || echo "restore of drawline.c fails"
  947. echo "x - extracting initmenu.c (Text)"
  948. sed 's/^X//' << 'SHAR_EOF' > initmenu.c &&
  949. X#ifndef LINT
  950. Xstatic char Sccsid[] = "%W%   DeltaDate %G%   ExtrDate %H%";
  951. X#endif
  952. X
  953. X#include    <curses.h>
  954. X#include    "menu.h"
  955. X
  956. Xinitmenu (menu)
  957. X    struct MenuInfo    *menu;
  958. X{
  959. X      /* set default menu settings */
  960. X      menu->row_cursor = LINES - 2;
  961. X      menu->col_cursor = COLS - 4;
  962. X      menu->boxtype = 0;
  963. X      menu->linetype = 0;
  964. X      menu->srn[0] = (struct ScreenInfo *)NULL;
  965. X      menu->after_menu = (char *)NULL;
  966. X}
  967. SHAR_EOF
  968. chmod 0644 initmenu.c || echo "restore of initmenu.c fails"
  969. echo "x - extracting keyboard.c (Text)"
  970. sed 's/^X//' << 'SHAR_EOF' > keyboard.c &&
  971. X#include    <curses.h>
  972. X#include    <term.h>
  973. X#include    "menu.h"
  974. X
  975. Xkeyboard ()
  976. X{
  977. X    char    *getenv();
  978. X    int    ch;
  979. X    int    wrow = 0;                /* from row */
  980. X    int    wcol = 10;                /* from col */
  981. X    int    sstart;                    /* scrool start row */
  982. X    int    send;                    /* scrool end row */
  983. X    int    prow;                    /* print row */
  984. X    int    dflag=0;
  985. X    WINDOW    *bwin;
  986. X
  987. X
  988. X    sstart = wrow + 10;
  989. X    send = wrow + 20;
  990. X    prow = sstart;
  991. X
  992. X    mvprintw (1,0, "Keyboard");
  993. X    mvprintw (2,4, "Fun");
  994. X
  995. X    drawbox (stdscr, wrow+1,wcol, wrow+23,wcol+40, StandoutLine, 
  996. X        StandoutLine, FALSE, FALSE);
  997. X    mvprintw (2,wcol+40, "StandoutLine");
  998. X    drawbox (stdscr, wrow+2,wcol+1, wrow+22,wcol+39, DumbLine, DumbLine,
  999. X        FALSE, FALSE);
  1000. X    mvprintw (3,wcol+39, "DumbLine");
  1001. X
  1002. X    /* to get around bug in curses of not turning attributes off */
  1003. X    /*
  1004. X    for (ch = 0; ch <= LINES; ch++)
  1005. X    {
  1006. X        mvprintw (ch,70, "hi");
  1007. X        refresh ();
  1008. X        mvprintw (ch,70, "  ");
  1009. X    }
  1010. X    */
  1011. X
  1012. X    /* terminal type */
  1013. X    mvprintw (wrow+3, wcol+4, "Terminal = %s", getenv("TERM"));
  1014. X
  1015. X    /* DrawLine ? */
  1016. X    if (enter_alt_charset_mode == NULL  ||
  1017. X        strcmp (enter_alt_charset_mode, "") == 0)
  1018. X        mvprintw (wrow+4, wcol+4, "Alternate Characters = No");
  1019. X    else
  1020. X    {
  1021. X        dflag++;
  1022. X        mvprintw (wrow+4, wcol+4, "Alternate Characters = Yes");
  1023. X
  1024. X        mvprintw (5,wcol+44, "Check termcap/terminfo");
  1025. X        mvprintw (6,wcol+44, "setting if the alternate");
  1026. X        mvprintw (7,wcol+44, "character lines below");
  1027. X        mvprintw (8,wcol+44, "don't look right.");
  1028. X
  1029. X        bwin = newwin (13, 27, 10, wcol+43);
  1030. X        drawbox (bwin, 1,1, 13,27, SingleLine, SingleLine, FALSE,FALSE);
  1031. X        drawbox (bwin, 2,2, 12,26, MosaicLine, MosaicLine, FALSE,FALSE);
  1032. X        drawbox (bwin, 3,3, 11,25, DiamondLine, DiamondLine, FALSE,FALSE);
  1033. X        drawbox (bwin, 4,4, 10,24, DotLine, DotLine, FALSE,FALSE);
  1034. X        drawbox (bwin, 5,5, 9,23, PlusLine, PlusLine, FALSE,FALSE);
  1035. X
  1036. X        mvwprintw (bwin, 0,7, " SingleLine ");
  1037. X        mvwprintw (bwin, 1,7, " MosaicLine ");
  1038. X        mvwprintw (bwin, 2,7, " DiamondLine ");
  1039. X        mvwprintw (bwin, 3,7, " DotLine ");
  1040. X        mvwprintw (bwin, 4,7, " PlusLine ");
  1041. X    }
  1042. X
  1043. X    /* Show all attributes */
  1044. X    mvprintw (11,0, "Curses");
  1045. X    mvprintw (12,0, "Attributes");
  1046. X
  1047. X    attrset (A_NORMAL);
  1048. X    mvprintw (14,0, "NORMAL");
  1049. X    attrset (A_STANDOUT);
  1050. X    mvprintw (15,0, "STANDOUT");
  1051. X    attrset (A_REVERSE);
  1052. X    mvprintw (16,0, "REVERSE");
  1053. X    attrset (A_UNDERLINE);
  1054. X    mvprintw (17,0, "UNDERLINE");
  1055. X    attrset (A_BLINK);
  1056. X    mvprintw (18,0, "BLINK");
  1057. X    attrset (A_DIM);
  1058. X    mvprintw (19,0, "DIM");
  1059. X    attrset (A_BOLD);
  1060. X    mvprintw (20,0, "BOLD");
  1061. X
  1062. X    attrset (A_NORMAL);
  1063. X
  1064. X    /* key codes */
  1065. X    mvprintw (wrow+6,wcol+8, "Press a Key");
  1066. X    mvprintw (wrow+7,wcol+8, "Press zero to exit.");
  1067. X
  1068. X    /* set up scroll */
  1069. X    scrollok (stdscr, TRUE);
  1070. X    wsetscrreg (stdscr, sstart, send);
  1071. X
  1072. X    mvprintw (sstart-2, wcol+4, "      (.menuinit)");
  1073. X    attrset (A_BOLD);
  1074. X    mvprintw (sstart-1, wcol+4, "char      dec     hex    octal");
  1075. X    attrset (A_NORMAL);
  1076. X    do
  1077. X    {
  1078. X        refresh ();
  1079. X        if (dflag)
  1080. X        {
  1081. X            touchwin (bwin);
  1082. X            wrefresh (bwin);
  1083. X        }
  1084. X        move (wrow+6, wcol+8+strlen("Press a Key")+1);
  1085. X        refresh ();
  1086. X        ch = getch ();
  1087. X
  1088. X        /*
  1089. X        nodelay (stdscr, TRUE);
  1090. X        while ((ch = getch()) != -1)
  1091. X            print ch
  1092. X        nodelay (stdscr, FALSE);
  1093. X        */
  1094. X
  1095. X        if (prow > send-2)
  1096. X        {
  1097. X            scroll (stdscr);
  1098. X            attrset (A_STANDOUT);
  1099. X            mvprintw (prow+1,wcol-1, " ");
  1100. X            mvprintw (prow+1,wcol+39, " ");
  1101. X            attrset (A_NORMAL);
  1102. X
  1103. X            mvprintw (prow+1,wcol, "|");
  1104. X            mvprintw (prow+1,wcol+38, "|");
  1105. X        }
  1106. X        else
  1107. X            prow++;
  1108. X        if (ch == '\t')
  1109. X            mvprintw (prow,wcol+4, "\t\\t\t%d\t%x\t%o", ch,ch,ch);
  1110. X        else    if (ch == '\n')
  1111. X                mvprintw (prow,wcol+4, "\t\\n\t%d\t%x\t%o", 
  1112. X                        ch,ch,ch);
  1113. X        else    if (ch == '\r')
  1114. X                mvprintw (prow,wcol+4, "\t\\r\t%d\t%x\t%o", 
  1115. X                        ch,ch,ch);
  1116. X        else    if (ch == '\b')
  1117. X                mvprintw (prow,wcol+4, "\t\\b\t%d\t%x\t%o", 
  1118. X                        ch,ch,ch);
  1119. X        else
  1120. X            mvprintw (prow,wcol+4, "\t%c\t%d\t%x\t%o", ch,ch,ch,ch);
  1121. X
  1122. X    } while (ch != '0');
  1123. X    if (dflag)
  1124. X    {
  1125. X        touchwin (bwin);
  1126. X        wrefresh (bwin);
  1127. X    }
  1128. X}
  1129. X/* Paul J. Condie */
  1130. SHAR_EOF
  1131. chmod 0644 keyboard.c || echo "restore of keyboard.c fails"
  1132. echo "x - extracting runscreen.c (Text)"
  1133. sed 's/^X//' << 'SHAR_EOF' > runscreen.c &&
  1134. X#ifndef LINT
  1135. Xstatic char Sccsid[] = "%W%   DeltaDate %G%   ExtrDate %H%";
  1136. X#endif
  1137. X
  1138. X/*  FUNCTION:    runscreen()
  1139. X*/
  1140. X
  1141. X#include    <curses.h>
  1142. X#include    "GetInput.h"
  1143. X#include    "menu.h"
  1144. X#include    "terminal.h"
  1145. X
  1146. X#define    SRN    menu->srn[sidx]
  1147. X#define    FLD    menu->srn[sidx]->field[fidx]
  1148. X
  1149. Xextern int debug;
  1150. X
  1151. X
  1152. Xrunscreen (screen_name, menu, opnumber)
  1153. X    char            screen_name[];
  1154. X    struct MenuInfo        *menu;
  1155. X    int            opnumber;
  1156. X{
  1157. X    FILE            *popen(), *pp;
  1158. X    char            *getenv();
  1159. X    char            *getval();
  1160. X    char            *findfile();
  1161. X    char            *format();
  1162. X    char            *malloc();
  1163. X    WINDOW            *swin;
  1164. X    union FldUnion        Fld;
  1165. X    int            rc;        /* return code */
  1166. X    int            exitkey;
  1167. X    int            sidx;
  1168. X    int            fidx = 0;
  1169. X    char            fielddata[MAXFIELDS+1][100];
  1170. X    int            fieldcount;
  1171. X    char            *promptptr = (char *)NULL;
  1172. X    char            fmtdefault[100];/* formated default value */
  1173. X    char            *wsptr;        /* working storage pointer */
  1174. X    int            helpflag;
  1175. X    char            helpfile[80];
  1176. X    char            tmptitle[100];
  1177. X    char            Title[100];    /* tmp for AUTO */
  1178. X    int            Rows;        /* tmp for AUTO */
  1179. X    int            Cols;        /* tmp for AUTO */
  1180. X    int            toprow;
  1181. X    int            leftcol;
  1182. X    int            i;        /* tmp loop var */
  1183. X    char            value[200];
  1184. X    char            input[100];    /* what user inputted */
  1185. X    char            *tmprange[MAXFIELDS+1];
  1186. X    int            NoInput;
  1187. X
  1188. X
  1189. X
  1190. Xherewegoagain:
  1191. X
  1192. X    helpflag = TRUE;
  1193. X
  1194. X    /* Find the screen definition */
  1195. X    for (sidx = 0; menu->srn[sidx] != (struct ScreenInfo *)NULL && 
  1196. X        sidx <= MAXSCREENS; sidx++)
  1197. X    {
  1198. X        if (strcmp (screen_name, menu->srn[sidx]->name) == 0)
  1199. X            break;
  1200. X    }
  1201. X    if (sidx > MAXSCREENS  ||  menu->srn[sidx] == (struct ScreenInfo *)NULL)
  1202. X    {
  1203. X        BEEP;
  1204. X        mvprintw (ErrRow-2,0, "Could not find your screen definition.");
  1205. X        shutdown ();
  1206. X    }
  1207. X
  1208. X    /* loop through each field */
  1209. X    /* save current field data - if KEY_CANCEL reset to this */
  1210. X    for (fidx = 0; SRN->field[fidx] != (struct FieldInfo *)NULL && 
  1211. X         fidx <= MAXFIELDS; fidx++)
  1212. X    {
  1213. X        if (getenv(FLD->name) != (char *)NULL)
  1214. X            strcpy (fielddata[fidx], getenv (FLD->name));
  1215. X        else
  1216. X            strcpy (fielddata[fidx], "");
  1217. X
  1218. X
  1219. X        /*  range values */
  1220. X        if (strcmp (FLD->range, "") == 0)
  1221. X            tmprange[fidx] = (char *)NULL;
  1222. X        else if (FLD->range[0] != '`'  && 
  1223. X             FLD->range[strlen(FLD->range)-1] != '`')
  1224. X        {
  1225. X            /* not a command */
  1226. X            tmprange[fidx] = (char *)malloc (strlen (FLD->range)+4);
  1227. X            strcpy (tmprange[fidx], FLD->range);
  1228. X        }
  1229. X        else if (FLD->range[0] == '`'  && 
  1230. X             FLD->range[strlen(FLD->range)-1] == '`'  &&
  1231. X            tmprange[fidx] == (char *)NULL)
  1232. X        {
  1233. X            /* we have a command to run - get new range values */
  1234. X            /* junk the grave accents and ! if there is one */
  1235. X            tmprange[fidx] = (char *) malloc (MAXLEN+4);
  1236. X            strcpy (tmprange[fidx], FLD->range+1);
  1237. X            if (tmprange[fidx][0] == '!')
  1238. X                strcpy (tmprange[fidx], FLD->range+2);
  1239. X            tmprange[fidx][strlen(tmprange[fidx])-1] = '\0';
  1240. X
  1241. X            if (promptptr == (char *)NULL || 
  1242. X                strcmp (promptptr, "DONT_CLEAR") != 0)
  1243. X            {
  1244. X                move (ErrRow,0);  clrtoeol();
  1245. X                mvprintw (ErrRow,1, "Working ...");
  1246. X                refresh ();
  1247. X            }
  1248. X            if (debug)
  1249. X            {
  1250. X                fprintf (stderr, 
  1251. X                    "\n[runscreen] <%s> popen=:%s:", 
  1252. X                    SRN->name, tmprange[fidx]);
  1253. X                fflush (stderr);
  1254. X            }
  1255. X            if ((pp = popen (tmprange[fidx], "r")) == (FILE *)NULL)
  1256. X            {
  1257. X                BEEP;
  1258. X                mvprintw (ErrRow-2,0, 
  1259. X                    "Could not open pipe = %s", tmprange[fidx]);
  1260. X                shutdown ();
  1261. X            }
  1262. X            fgets (tmprange[fidx], MAXLEN-1, pp);
  1263. X            tmprange[fidx][strlen(tmprange[fidx])-1] = '\0';   /* junk \n */
  1264. X            pclose (pp);
  1265. X        }
  1266. X    }
  1267. X
  1268. X
  1269. X    /* set tmp variables used for AUTO */
  1270. X    strcpy (Title, SRN->title);
  1271. X    Rows = SRN->rows;
  1272. X    Cols = SRN->cols;
  1273. X
  1274. X    /* if title is set to AUTO then use the description text */
  1275. X    if (atoi(Title) == AUTO)
  1276. X    {
  1277. X        strcpy (Title, menu->option[opnumber]->description);
  1278. X        /* junk ending period if there is one */
  1279. X        if (Title[strlen(Title)-1] == '.')  
  1280. X            Title[strlen(Title)-1] = '\0';
  1281. X    }
  1282. X
  1283. X    /* for SET and MENU type determine field_length */
  1284. X    for (fidx = 0; SRN->field[fidx] != (struct FieldInfo *)NULL && 
  1285. X         fidx <= MAXFIELDS; fidx++)
  1286. X    {
  1287. X        /* for SET and MENU types get field_length */
  1288. X        if (FLD->type == SET  ||  FLD->type == MENU)
  1289. X            FLD->length = GetSetLen (tmprange[fidx]);
  1290. X    }
  1291. X
  1292. X    /* calculate window_rows & window_cols if AUTO */
  1293. X    if (Rows == AUTO)
  1294. X    {
  1295. X        /* field with largest row + 4 */
  1296. X        Rows = 0;
  1297. X        for (fidx = 0; SRN->field[fidx] != (struct FieldInfo *)NULL && 
  1298. X             fidx <= MAXFIELDS; fidx++)
  1299. X        {
  1300. X            if (FLD->row > Rows)
  1301. X                Rows = FLD->row;
  1302. X        }
  1303. X        
  1304. X        /* make sure window is big enough to hold text stuff */
  1305. X        for (i = 0; SRN->textinfo[i] != (struct TextInfo *)NULL; i++)
  1306. X            if (SRN->textinfo[i]->row + 1 > Rows)
  1307. X                Rows = SRN->textinfo[i]->row + 1;
  1308. X        Rows += 3;
  1309. X    }
  1310. X    if (Cols == AUTO)
  1311. X    {
  1312. X        /* field with largest col + length + 4   or  title */
  1313. X        /* make sure screen is big enough to hold the title */
  1314. X        wsptr = Title;
  1315. X        strcpy (tmptitle, getval (&wsptr, '1'));
  1316. X        Cols = strlen (tmptitle);
  1317. X        for (fidx = 0; SRN->field[fidx] != (struct FieldInfo *)NULL && 
  1318. X             fidx <= MAXFIELDS; fidx++)
  1319. X        {
  1320. X            if (strlen(FLD->mask) > 0)
  1321. X            {
  1322. X                if ((FLD->col + strlen(FLD->mask) + 1) > Cols)
  1323. X                    Cols = FLD->col + strlen(FLD->mask) + 1;
  1324. X            }
  1325. X            else
  1326. X                if ((FLD->col + FLD->length + 1) > Cols)
  1327. X                    Cols = FLD->col + FLD->length + 1;
  1328. X        }
  1329. X
  1330. X        /* make sure window is big enough to hold text stuff */
  1331. X        for (i = 0; SRN->textinfo[i] != (struct TextInfo *)NULL; i++)
  1332. X                if (SRN->textinfo[i]->col +
  1333. X                strlen(SRN->textinfo[i]->text) + 1 > Cols)
  1334. X                    Cols = SRN->textinfo[i]->col + 
  1335. X                    strlen(SRN->textinfo[i]->text) + 1;
  1336. X        Cols += 2;
  1337. X    }
  1338. X
  1339. X    /* use environment variable if there is one */
  1340. X    wsptr = SRN->toprowvar;
  1341. X    if (strcmp (SRN->toprowvar, "") != 0)
  1342. X        toprow = atoi (getval (&wsptr, '1'));
  1343. X    else
  1344. X        toprow = SRN->toprow;
  1345. X    wsptr = SRN->leftcolvar;
  1346. X    if (strcmp (SRN->leftcolvar, "") != 0)
  1347. X        leftcol = atoi (getval (&wsptr, '1'));
  1348. X    else
  1349. X        leftcol = SRN->leftcol;
  1350. X
  1351. X    if (toprow == AUTO)
  1352. X    {
  1353. X        /*
  1354. X        ** Figure out where to put the screen 
  1355. X        ** try to put screen as close to the option as possible 
  1356. X        */
  1357. X        toprow = menu->option[opnumber]->row - 2;
  1358. X        /*
  1359. X        for (rc = 0, leftcol = 0; rc < menu->optioncount ; rc++)
  1360. X            if (strlen (menu->option[rc]->description) > leftcol)
  1361. X                leftcol = strlen (menu->option[rc]->description);
  1362. X        leftcol = menu->option[opnumber]->col + 
  1363. X                  ((leftcol + 4) / 2);
  1364. X        */
  1365. X        leftcol = menu->option[opnumber]->col +
  1366. X                   strlen(menu->option[opnumber]->description) + 4;
  1367. X
  1368. X        /* make sure it fits on the screen */
  1369. X        if ((toprow + Rows) > LINES-1)
  1370. X            toprow = LINES - Rows - 1;
  1371. X        toprow = toprow < 0 ? 0 : toprow;
  1372. X
  1373. X        if ((leftcol + Cols + 2) > COLS)
  1374. X            leftcol = COLS - Cols - 1;
  1375. X        leftcol = leftcol < 0 ? 0 : leftcol;
  1376. X    }
  1377. X
  1378. X
  1379. X    /* create the window */
  1380. X    swin = newwin (Rows, Cols, toprow, leftcol);
  1381. X    keypad (swin, TRUE);
  1382. X
  1383. X    /* 
  1384. X    **    check if recalculation of rows & cols is necessary
  1385. X    **    see newwin() for info on why
  1386. X    */
  1387. X    if (Rows == 0  &&  Cols == 0  &&  
  1388. X        toprow == 0  && leftcol == 0)
  1389. X    {
  1390. X        /* a full-screen was created */
  1391. X        Rows = LINES-1;
  1392. X        Cols = COLS;
  1393. X    }
  1394. X    else      if (Rows == 0  ||  Cols == 0)
  1395. X        {
  1396. X            Rows = LINES - toprow;
  1397. X            Cols = COLS - leftcol;
  1398. X            if (Rows == LINES)
  1399. X                Rows--;
  1400. X        }
  1401. X
  1402. X
  1403. X    if (strcmp (SRN->helpfile, "") == 0)
  1404. X        helpflag = FALSE;
  1405. X    else
  1406. X        strcpy (helpfile, findfile (SRN->helpfile, ".",
  1407. X            getenv("HELPDIR"), getenv("MENUDIR"), ""));
  1408. X    drawbox (swin, 1,1, Rows,Cols, SRN->boxtype & 0777, 
  1409. X        StandoutLine, FALSE, helpflag);
  1410. X
  1411. X    /* display title */
  1412. X    wsptr = Title;
  1413. X    strcpy (tmptitle, getval (&wsptr, '1'));
  1414. X    wattrset (swin, A_STANDOUT);
  1415. X    mvwprintw (swin, 0, ((Cols)/2)-(strlen(tmptitle)/2), "%s", tmptitle);
  1416. X    wattrset (swin, A_NORMAL);
  1417. X
  1418. X    /* display text stuff */
  1419. X    for (i = 0; SRN->textinfo[i] != (struct TextInfo *)NULL; i++)
  1420. X        displaytext (swin, SRN->textinfo[i]->row, SRN->textinfo[i]->col,
  1421. X            SRN->textinfo[i]->text);
  1422. X
  1423. X    /*
  1424. X    **  Run fielddefaults if there is one and load results into $field_name
  1425. X    */
  1426. X    if (SRN->fielddefaults != (char *)NULL)
  1427. X    {
  1428. X        if (debug)
  1429. X        {
  1430. X            fprintf (stderr, "\n[runscreen] <%s> popen=:%s:", 
  1431. X                SRN->name, SRN->fielddefaults);
  1432. X            fflush (stderr);
  1433. X        }
  1434. X        if (promptptr == (char *)NULL ||
  1435. X            strcmp (promptptr, "DONT_CLEAR") != 0)
  1436. X        {
  1437. X            move (ErrRow,0);  clrtoeol();
  1438. X            mvprintw (ErrRow,1, "Working ...");
  1439. X            refresh ();
  1440. X        }
  1441. X        if ((pp = popen (SRN->fielddefaults, "r")) == (FILE *)NULL)
  1442. X        {
  1443. X            BEEP;
  1444. X            mvprintw (ErrRow-2,0, "Could not open pipe = %s",
  1445. X                SRN->fielddefaults);
  1446. X            shutdown ();
  1447. X        }
  1448. X
  1449. X        /* read and set each $field_name until no more input */
  1450. X        rc = 99;
  1451. X        for (fidx = 0; SRN->field[fidx] != (struct FieldInfo *)NULL && 
  1452. X            fidx <= MAXFIELDS; fidx++)
  1453. X        {
  1454. X            strcpy (value, "");
  1455. X            if (rc == EOF) 
  1456. X            {
  1457. X                if (debug)
  1458. X                {
  1459. X                    fprintf (stderr, 
  1460. X                              "\n[runscreen] <%s> read nothing from popen",
  1461. X                        SRN->name);
  1462. X                    fprintf (stderr, 
  1463. X                                "\n[runscreen] <%s> field %s =:%s:",
  1464. X                          SRN->name, FLD->name, value);
  1465. X                    fflush (stderr);
  1466. X                }
  1467. X                continue;
  1468. X            }
  1469. X
  1470. X            /* get a word from the pipe */
  1471. X               rc = fscanf (pp, "%s", fmtdefault);
  1472. X            if (rc == EOF) continue;
  1473. X            if (debug)
  1474. X            {
  1475. X                fprintf (stderr, 
  1476. X                      "\n[runscreen] <%s> read from popen=:%s:",
  1477. X                    SRN->name, fmtdefault);
  1478. X                fflush (stderr);
  1479. X            }
  1480. X
  1481. X                
  1482. X            /* check for a quoted value */
  1483. X            if (fmtdefault[0] == '"')
  1484. X            {
  1485. X                /*
  1486. X                ** found a quoted value 
  1487. X                ** read until another quote or end of line
  1488. X                */
  1489. X                strcpy (value, fmtdefault+1);    /* junk 1st " */
  1490. X                wsptr = value + strlen(value);
  1491. X                if (*(wsptr-1) == '"')
  1492. X                {
  1493. X                    /* quote is on first word */
  1494. X                    *(wsptr-1) = '\0';
  1495. X                }
  1496. X                else
  1497. X                {
  1498. X                    while ((rc = fgetc (pp)) != EOF)
  1499. X                    {
  1500. X                        if ((*wsptr = (char)rc) == '"')
  1501. X                        {
  1502. X                            *wsptr = '\0';
  1503. X                            break;
  1504. X                        }
  1505. X                        wsptr++;
  1506. X                    } /* end while */
  1507. X                }
  1508. X            }
  1509. X            else
  1510. X                strcpy (value, fmtdefault);
  1511. X            if (debug)
  1512. X            {
  1513. X                fprintf (stderr, 
  1514. X                              "\n[runscreen] <%s> field %s =:%s:",
  1515. X                        SRN->name, FLD->name, value);
  1516. X                fflush (stderr);
  1517. X            }
  1518. X
  1519. X            /* set $field_name with new value */
  1520. X            adjustfield (value, FLD->adjust, FLD->length);
  1521. X            rc = setenv (FLD->name, value);
  1522. X        } /* end for each field */
  1523. X        pclose(pp);
  1524. X    }
  1525. X
  1526. X
  1527. X
  1528. X    /*
  1529. X    **  display field stuff
  1530. X    **  Loop through each field
  1531. X    **    print the label
  1532. X    **    put in the field terminators
  1533. X    **    get, format and print default value in getenv () or fielddefault
  1534. X    */
  1535. X    for (fidx = 0; SRN->field[fidx] != (struct FieldInfo *)NULL && 
  1536. X        fidx <= MAXFIELDS;
  1537. X        fidx++)
  1538. X    {
  1539. X        /* print label */
  1540. X        if (strlen(FLD->label) > 0)
  1541. X            mvwprintw (swin, FLD->row, 
  1542. X                FLD->col - strlen(FLD->label) - 2,
  1543. X                "%s", FLD->label);
  1544. X
  1545. X        /* print field terminators */
  1546. X        if (strlen(FLD->terminator) > 0)
  1547. X        {
  1548. X            /* left */
  1549. X            mvwprintw (swin, FLD->row, FLD->col - 1,
  1550. X                "%c", FLD->terminator[0]);
  1551. X            /* right */
  1552. X            if (strlen(FLD->mask) > 0)
  1553. X                mvwprintw (swin, FLD->row, 
  1554. X                    FLD->col + strlen(FLD->mask),
  1555. X                    "%c", FLD->terminator[1]);
  1556. X            else
  1557. X                mvwprintw (swin, FLD->row, 
  1558. X                    FLD->col + FLD->length,
  1559. X                    "%c", FLD->terminator[1]);
  1560. X        }
  1561. X
  1562. X        /* get default value from getenv() */
  1563. X        if (getenv(FLD->name) != (char *)NULL)
  1564. X            strcpy (value, getenv (FLD->name));
  1565. X        else
  1566. X            strcpy (value, "");
  1567. X
  1568. X        /* format default value to the mask */
  1569. X        strcpy (fmtdefault, format (value, FLD->mask, FLD->type));
  1570. X        /* print default data */
  1571. X        if (strlen(fmtdefault) > 0)
  1572. X            mvwprintw (swin, FLD->row, FLD->col, "%s", fmtdefault);
  1573. X    }
  1574. X    fieldcount = fidx-1;                /* save field count */
  1575. X
  1576. X
  1577. X    /*
  1578. X    **  GetInput() from fields untill KEY_CANCEL || KEY_ACCEPT ||
  1579. X    **    exit_last_field || exit_on_cancel
  1580. X    */
  1581. X    if (promptptr == (char *)NULL ||
  1582. X        strcmp (promptptr, "DONT_CLEAR") != 0)
  1583. X    {
  1584. X        move (ErrRow,0);  clrtoeol();
  1585. X    }
  1586. X    fidx = 0;                /* start with first field */
  1587. X
  1588. X    do
  1589. X    {
  1590. X        NoInput = FLD->noinput;
  1591. X        /* run before_inpput command */
  1592. X        if (FLD->before_field != (char *)NULL)
  1593. X        {
  1594. X            char    buf[BUFSIZ+1];
  1595. X
  1596. X            if (promptptr == (char *)NULL || 
  1597. X                strcmp (promptptr, "DONT_CLEAR") != 0)
  1598. X            {
  1599. X                move (ErrRow,0);  clrtoeol();
  1600. X                mvprintw (ErrRow,1, "Working ...");
  1601. X                refresh ();
  1602. SHAR_EOF
  1603. echo "End of part 6"
  1604. echo "File runscreen.c is continued in part 7"
  1605. echo "7" > s2_seq_.tmp
  1606. exit 0
  1607.