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

  1. From: pjc@pcbox.UUCP (Paul J. Condie)
  2. Newsgroups: alt.sources
  3. Subject: menu(1) part 5 of 14
  4. Message-ID: <439@pcbox.UUCP>
  5. Date: 26 Dec 90 20:07:38 GMT
  6.  
  7.  
  8. #!/bin/sh
  9. # this is part 5 of a multipart archive
  10. # do not concatenate these parts, unpack them in order with /bin/sh
  11. # file ParseAuthr.c continued
  12. #
  13. CurArch=5
  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 ParseAuthr.c"
  24. sed 's/^X//' << 'SHAR_EOF' >> ParseAuthr.c
  25. X              if (strcmp (user, word) == 0)
  26. X              {
  27. X            OKflag = TRUE;
  28. X            break;
  29. X              }
  30. X              lptr = strchr (++lptr, ' ');
  31. X       }
  32. X
  33. X       if (!OKflag)
  34. X              return (NOWAYJOSE);
  35. X       return (0);
  36. X}
  37. SHAR_EOF
  38. echo "File ParseAuthr.c is complete"
  39. chmod 0644 ParseAuthr.c || echo "restore of ParseAuthr.c fails"
  40. echo "x - extracting ParseText.c (Text)"
  41. sed 's/^X//' << 'SHAR_EOF' > ParseText.c &&
  42. X#ifndef LINT
  43. Xstatic char Sccsid[] = "%W%   DeltaDate %G%   ExtrDate %H%";
  44. X#endif
  45. X
  46. X/*  FUNCTION:    ParseText()
  47. X**        Parses keyword "TEXT".
  48. X**  ARGS:    keyword        the keyword "TEXT"
  49. X**        menufile    the unix menu file
  50. X**        menu        menu structure
  51. X**        gnames        holder of goto menu names
  52. X**        gfiles        holder of goto menu names (menu file)
  53. X**        gindex        # of gnames
  54. X**  RETURNS:    0
  55. X*/
  56. X
  57. X#include    <curses.h>
  58. X#include    <ctype.h>
  59. X#include    "menu.h"
  60. X
  61. X
  62. XParseText (keyword, menufile, menu, KeyWord, ParseKey, gnames, gfiles, 
  63. X    gindex, opnumber)
  64. X
  65. X    char        keyword[];
  66. X    FILE        *menufile;
  67. X    struct MenuInfo    *menu;
  68. X    char        KeyWord[][MAXKEYLENGTH];
  69. X    int        (*ParseKey[])();
  70. X    char        gnames[][15], gfiles[][15];
  71. X    int        *gindex;
  72. X    int        *opnumber;
  73. X{
  74. X    char        *fgets(), line[BUFSIZE+1];
  75. X    char        *getval();
  76. X    int        row;
  77. X    int        col;
  78. X    char        fline[BUFSIZE+1];        /* formated line */
  79. X    int        j;
  80. X    int        i;
  81. X    char        *ws;
  82. X
  83. X       fgets (line, BUFSIZE, menufile);        /* read row, col */
  84. X    ws = line;
  85. X    SKIPJUNK (ws);
  86. X    sscanf (ws, "%s", fline);            /* get row */
  87. X    row = strcmp (fline, "-0") == 0 ? LINES : atoi(fline);
  88. X    ws += strlen(fline);
  89. X    SKIPJUNK (ws);
  90. X    sscanf (ws, "%s", fline);            /* get col */
  91. X    col = strcmp (fline, "-0") == 0 ? COLS : atoi(fline);
  92. X    
  93. X       fgets (line, BUFSIZE, menufile);        /* read text */
  94. X       line[strlen(line)-1] = '\0';
  95. X       for (j = 0, i = 0; i < strlen (line); j++, i++)
  96. X              if (line[i] == '$')
  97. X              {
  98. X            char    *sptr, *b4ptr;
  99. X
  100. X                 sptr = b4ptr = line+i;
  101. X                 strcpy (fline+j, getval (&sptr, '$'));
  102. X                 i += (int)(sptr - b4ptr);
  103. X                 j += strlen (fline+j) - 1;
  104. X                 i--;
  105. X              }
  106. X              else
  107. X              {
  108. X            fline[j] = line[i];
  109. X              }
  110. X    fline[j] = '\0';
  111. X
  112. X    /*
  113. X    **   If the row or column is negative
  114. X    **     then  we use relative addressing
  115. X    **              the row or col is subtracted from # of rows on screen.
  116. X    */
  117. X    if (row < 0)
  118. X        row = abs(row) > LINES ? LINES-1 : LINES+row-1;
  119. X    else
  120. X        row = row > LINES-1 ? LINES-1 : row;
  121. X    if (col < 0)
  122. X        col = abs(col) > COLS ? COLS-1 : COLS+col-1;
  123. X    else
  124. X        col = col > COLS-1 ? COLS-1 : col;
  125. X       displaytext (stdscr, row, col, fline);
  126. X    return (0);
  127. X}
  128. X/* Paul J. Condie  4/88 */
  129. SHAR_EOF
  130. chmod 0644 ParseText.c || echo "restore of ParseText.c fails"
  131. echo "x - extracting ParseCur.c (Text)"
  132. sed 's/^X//' << 'SHAR_EOF' > ParseCur.c &&
  133. X#ifndef LINT
  134. Xstatic char Sccsid[] = "@(#)ParseCur.c    1.5   DeltaDate 1/22/90   ExtrDate 1/22/90";
  135. X#endif
  136. X
  137. X
  138. X/*  FUNCTION:    ParseCursor()
  139. X**        Parses keyword "CURSOR".
  140. X**  ARGS:    keyword        the keyword "CURSOR"
  141. X**        menufile    the unix menu file
  142. X**        menu        menu structure
  143. X**        gnames        holder of goto menu names
  144. X**        gfiles        holder of goto menu names (menu file)
  145. X**        gindex        # of gnames
  146. X*/
  147. X
  148. X#include    <curses.h>
  149. X#include    <ctype.h>
  150. X#include    "menu.h"
  151. X
  152. X
  153. XParseCursor (keyword, menufile, menu, KeyWord, ParseKey, gnames, gfiles, 
  154. X    gindex, opnumber)
  155. X
  156. X    char        keyword[];
  157. X    FILE        *menufile;
  158. X    struct MenuInfo    *menu;
  159. X    char        KeyWord[][MAXKEYLENGTH];
  160. X    int        (*ParseKey[])();
  161. X    char        gnames[][15], gfiles[][15];
  162. X    int        *gindex;
  163. X    int        *opnumber;
  164. X{
  165. X    char    *fgets(), line[BUFSIZE+1];
  166. X    char    *ws;
  167. X    char    tmpstr[20];
  168. X
  169. X       fgets (line, BUFSIZE, menufile);
  170. X    ws = line;
  171. X    SKIPJUNK (ws);
  172. X    sscanf (ws, "%s", tmpstr);            /* get row */
  173. X    menu->row_cursor = strcmp (tmpstr, "-0") == 0 ? LINES : atoi(tmpstr);
  174. X    ws += strlen(tmpstr);
  175. X    SKIPJUNK (ws);
  176. X    sscanf (ws, "%s", tmpstr);            /* get col */
  177. X    menu->col_cursor = strcmp (tmpstr, "-0") == 0 ? COLS : atoi(tmpstr);
  178. X
  179. X    /*
  180. X    **   If the row or column is negative
  181. X    **     then  we use relative addressing
  182. X    **              the row or col is subtracted from # of rows on screen.
  183. X    */
  184. X    if (menu->row_cursor < 0)
  185. X        menu->row_cursor = abs(menu->row_cursor) > LINES ? 
  186. X            LINES-1 : LINES+menu->row_cursor-1;
  187. X    else
  188. X        menu->row_cursor = menu->row_cursor > LINES-1 ? 
  189. X            LINES-1 : menu->row_cursor;
  190. X    if (menu->col_cursor < 0)
  191. X        menu->col_cursor = abs(menu->col_cursor) > COLS ? 
  192. X            COLS-1 : COLS+menu->col_cursor-1;
  193. X    else
  194. X        menu->col_cursor = menu->col_cursor > COLS-1 ? 
  195. X            COLS-1 : menu->col_cursor;
  196. X    return (0);
  197. X}
  198. X/* Paul J. Condie  4/88 */
  199. SHAR_EOF
  200. chmod 0444 ParseCur.c || echo "restore of ParseCur.c fails"
  201. echo "x - extracting ParseSpace.c (Text)"
  202. sed 's/^X//' << 'SHAR_EOF' > ParseSpace.c &&
  203. Xstatic char Sccsid[] = "%W%   DeltaDate %G%   ExtrDate %H%";
  204. X
  205. X/*  FUNCTION:    ParseSpace()
  206. X**  ARGS:    keyword        the keyword found
  207. X**        menufile    the unix menu file
  208. X**        menu        menu structure
  209. X**        gnames        holder of goto menu names
  210. X**        gfiles        holder of goto menu names (menu file)
  211. X**        gindex        # of gnames
  212. X**  RETURNS:    0
  213. X*/
  214. X
  215. X#include    <curses.h>
  216. X#include    "menu.h"
  217. X
  218. Xextern    int    swin, ewin, longest;
  219. X
  220. X
  221. XParseSpace (keyword, menufile, menu, KeyWord, ParseKey, gnames, gfiles, gindex, opnumber)
  222. X
  223. X    char        keyword[];
  224. X    FILE        *menufile;
  225. X    struct MenuInfo    *menu;
  226. X    char        KeyWord[][MAXKEYLENGTH];
  227. X    int        (*ParseKey[])();
  228. X    char        gnames[][15], gfiles[][15];
  229. X    int        *gindex;
  230. X    int        *opnumber;
  231. X{
  232. X    struct OptionInfo    *malloc();
  233. X    char    *fgets(), line[BUFSIZE];
  234. X
  235. X
  236. X   if (menu->optioncount >= MAXOPTION)
  237. X   {
  238. X      BEEP;
  239. X      mvprintw (ErrRow, 0, "Exceeded maximum allowable options.");
  240. X      shutdown ();
  241. X   }
  242. X   menu->option[menu->optioncount] = malloc (sizeof (struct OptionInfo));
  243. X   if (menu->option[menu->optioncount] == NULL)
  244. X   {
  245. X      BEEP;
  246. X      mvprintw (ErrRow, 0, "Unable to allocate memory for option.");
  247. X      shutdown ();
  248. X   }
  249. X
  250. X   strcpy (menu->option[menu->optioncount]->keyword, keyword);
  251. X   menu->option[menu->optioncount]->opnumber = 0;        /* no number */
  252. X   strcpy (menu->option[menu->optioncount]->description, "");
  253. X   menu->option[menu->optioncount]->command = (char *) malloc (5);
  254. X   strcpy (menu->option[menu->optioncount]->command, "");
  255. X
  256. X   fgets (line, sizeof(line)-1, menufile);        /* junk rest of line */
  257. X   menu->optioncount++;
  258. X   ewin++;
  259. X   return (0);
  260. X}
  261. SHAR_EOF
  262. chmod 0644 ParseSpace.c || echo "restore of ParseSpace.c fails"
  263. echo "x - extracting ParInclude.c (Text)"
  264. sed 's/^X//' << 'SHAR_EOF' > ParInclude.c &&
  265. X#ifndef LINT
  266. Xstatic char Sccsid[] = "%W%   DeltaDate %G%   ExtrDate %H%";
  267. X#endif
  268. X
  269. X/*  FUNCTION:    ParInclude()
  270. X**        Parses keyword ".INCLUDE".
  271. X**  ARGS:    keyword        the keyword "INCLUDE"
  272. X**        menufile    the unix menu file
  273. X**        menu        menu structure
  274. X**        gnames        holder of goto menu names
  275. X**        gfiles        holder of goto menu names (menu file)
  276. X**        gindex        # of gnames
  277. X*/
  278. X
  279. X#include    <curses.h>
  280. X#include    "menu.h"
  281. X
  282. X
  283. XParInclude (keyword, menufile, menu, KeyWord, ParseKey, gnames, gfiles, 
  284. X    gindex, opnumber)
  285. X
  286. X    char        keyword[];
  287. X    FILE        *menufile;
  288. X    struct MenuInfo    *menu;
  289. X    char        KeyWord[][MAXKEYLENGTH];
  290. X    int        (*ParseKey[])();
  291. X    char        gnames[][15], gfiles[][15];
  292. X    int        *gindex;
  293. X    int        *opnumber;
  294. X{
  295. X    FILE        *fopen(), *newfile;
  296. X    char        *fgets(), line[BUFSIZE+1];
  297. X    char        *findfile();
  298. X    char        *getenv();
  299. X    char        *getval();
  300. X    char        unixfile[100];
  301. X    char        filename[100];
  302. X    int        rc;
  303. X    int        KEYFOUND;
  304. X    int        idx;
  305. X    char        newkey[MAXKEYLENGTH];
  306. X    char        *sptr;
  307. X
  308. X    fgets (line, BUFSIZE, menufile);
  309. X    sscanf (line, "%s", filename);
  310. X
  311. X    /*
  312. X    **  Open and Parse the new menu file
  313. X    */
  314. X    sptr = filename;
  315. X    strcpy (unixfile, getval (&sptr, 1));
  316. X    strcpy (filename, unixfile);
  317. X    if (filename[0] != '/')
  318. X        strcpy (unixfile, findfile (filename, ".", getenv("MENUDIR"), 
  319. X        ""));
  320. X          if ((newfile = fopen (unixfile, "r")) == NULL)
  321. X          {
  322. X            BEEP;
  323. X                mvprintw (ErrRow-2, 0, "Unable to locate .INCLUDE (%s) file.", 
  324. X                filename);
  325. X                shutdown ();
  326. X          }
  327. X
  328. X
  329. X       /* loop through each keyword */
  330. X       rc = fscanf (newfile, "%s", newkey);
  331. X       while (rc != EOF)
  332. X       {
  333. X        /*
  334. X        **  Check if we found a defined keyword
  335. X        */
  336. X              KEYFOUND = FALSE;
  337. X              for (idx = 1; idx <= MAXKEYS; idx++)
  338. X              {
  339. X            /*
  340. X                 if (strcmp (newkey, KeyWord[idx]) == 0)
  341. X            */
  342. X                 if (strmatch (newkey, KeyWord[idx]))
  343. X                 {
  344. X                        KEYFOUND = TRUE;
  345. X                    if (ParseKey[idx] != NULL)
  346. X                    {
  347. X                               rc = (*ParseKey[idx]) (newkey, 
  348. X                        newfile, menu, KeyWord,
  349. X                        ParseKey, gnames, gfiles, 
  350. X                        gindex, opnumber);
  351. X                           if (rc != 0)   return (rc);
  352. X                  }
  353. X                        break;
  354. X                 }
  355. X              }
  356. X              if (!KEYFOUND)
  357. X              {
  358. X                 BEEP;
  359. X                 mvprintw (ErrRow-2, 0, "ERROR: (%s) Key not found.", 
  360. X                    newkey);
  361. X                 shutdown ();
  362. X              }
  363. X              rc = fscanf (newfile, "%s", newkey);
  364. X    } /* end while */
  365. X
  366. X    /*
  367. X          rc = parsedriver (newfile, KeyWord, ParseKey, menu, gnames, gfiles, 
  368. X            &gindex);
  369. X    */
  370. X          fclose (newfile);
  371. X
  372. X       return (0);
  373. X}
  374. SHAR_EOF
  375. chmod 0644 ParInclude.c || echo "restore of ParInclude.c fails"
  376. echo "x - extracting ParAssign.c (Text)"
  377. sed 's/^X//' << 'SHAR_EOF' > ParAssign.c &&
  378. X#ifndef LINT
  379. Xstatic char Sccsid[] = "%W%   DeltaDate %G%   ExtrDate %H%";
  380. X#endif
  381. X
  382. X/*  FUNCTION:    ParAssign()
  383. X**        Parses keyword "*=*"
  384. X**        A variable=value assignment.
  385. X**  ARGS:    keyword        the keyword "*=*"
  386. X**        menufile    the unix menu file
  387. X**        menu        menu structure
  388. X**        gnames        holder of goto menu names
  389. X**        gfiles        holder of goto menu names (menu file)
  390. X**        gindex        # of gnames
  391. X*/
  392. X
  393. X#include    <curses.h>
  394. X#include    "menu.h"
  395. X
  396. Xextern int    debug;
  397. X
  398. X
  399. XParAssign (keyword, menufile, menu, KeyWord, ParseKey, gnames, gfiles, 
  400. X    gindex, opnumber)
  401. X
  402. X    char        keyword[];
  403. X    FILE        *menufile;
  404. X    struct MenuInfo    *menu;
  405. X    char        KeyWord[][MAXKEYLENGTH];
  406. X    int        (*ParseKey[])();
  407. X    char        gnames[][15], gfiles[][15];
  408. X    int        *gindex;
  409. X    int        *opnumber;
  410. X{
  411. X    char    *fgets();
  412. X    char    line[BUFSIZE+1];
  413. X    char    *assignment;
  414. X    char    *aptr;
  415. X    char    *sptr;
  416. X
  417. X
  418. X       fgets (line, BUFSIZE, menufile);
  419. X    line[strlen(line)-1] = '\0';            /* junk \n */
  420. X    /* if comment (#,###) junk rest of line */
  421. X    for (aptr = line; *aptr; aptr++)
  422. X        if (*aptr == '#'  ||  strncmp (aptr, "###", 3) == 0)
  423. X        {
  424. X            *aptr = '\0';            /* junk comment */
  425. X            for (sptr = aptr-1, aptr = line; 
  426. X                 sptr >= aptr && (*sptr == ' ' || *sptr == '\t'); 
  427. X                 sptr--)
  428. X                *sptr = '\0';    /* junk trailing white space */
  429. X            break;
  430. X        }
  431. X    assignment = (char *)malloc (strlen(keyword) + strlen(line) + 20);
  432. X    strcpy (assignment, keyword);
  433. X    strcat (assignment, line);    /* the rest of the quoted value */
  434. X    aptr = assignment;
  435. X    if (debug)
  436. X    {
  437. X        fprintf (stderr, "\n[ParAssign]  command=:%s:", aptr);
  438. X        fflush (stderr);
  439. X    }
  440. X    setvariable (&aptr);
  441. X    free (assignment);
  442. X    return (0);
  443. X}
  444. SHAR_EOF
  445. chmod 0644 ParAssign.c || echo "restore of ParAssign.c fails"
  446. echo "x - extracting ParAftMenu.c (Text)"
  447. sed 's/^X//' << 'SHAR_EOF' > ParAftMenu.c &&
  448. X#ifndef LINT
  449. Xstatic char Sccsid[] = "%W%   DeltaDate %G%   ExtrDate %H%";
  450. X#endif
  451. X
  452. X/*  FUNCTION:    ParAftMenu()
  453. X**        Parses keyword ".AFTER_MENU".
  454. X**  ARGS:    keyword        the keyword "unix"
  455. X**        menufile    the unix menu file
  456. X**        menu        menu structure
  457. X**        gnames        holder of goto menu names
  458. X**        gfiles        holder of goto menu names (menu file)
  459. X**        gindex        # of gnames
  460. X**  RETURNS:    none
  461. X*/
  462. X
  463. X#include    <curses.h>
  464. X#include    <ctype.h>
  465. X#include    "menu.h"
  466. X
  467. X
  468. Xextern    int    debug;
  469. X
  470. X
  471. X
  472. XParAftMenu (keyword, menufile, menu, KeyWord, ParseKey, gnames, gfiles, 
  473. X        gindex, opnumber)
  474. X
  475. X    char        keyword[];
  476. X    FILE        *menufile;
  477. X    struct MenuInfo    *menu;
  478. X    char        KeyWord[][MAXKEYLENGTH];
  479. X    int        (*ParseKey[])();
  480. X    char        gnames[][15], gfiles[][15];
  481. X    int        *gindex;
  482. X    int        *opnumber;
  483. X{
  484. X    char        command[MAXLEN+1];
  485. X    int        rc;
  486. X    char        *comptr;
  487. X    char        tmpstr[80];
  488. X    int        redrawflag = FALSE;
  489. X
  490. X
  491. X
  492. X    /*
  493. X    **    Read in option command
  494. X    **    strcat continuation lines
  495. X    */
  496. X       fgets (command, sizeof(command)-1, menufile);
  497. X       command[strlen(command)-1] = '\0';        /* get rid of \n */
  498. X       while (command[strlen(command)-1] == '\\')
  499. X       {
  500. X              if (strlen(command) > MAXLEN)
  501. X              {
  502. X                 BEEP;
  503. X                 mvprintw (ErrRow-2, 0, 
  504. X                  ".AFTER_MENU command is too long.  Max = %d",
  505. X                  MAXLEN);
  506. X                 shutdown ();
  507. X              }
  508. X              command[strlen(command)-1] = '\n';    /* replace \ with \n */
  509. X              fgets (command+strlen(command), sizeof(command)-1, menufile);
  510. X              command[strlen(command)-1] = '\0';    /* get rid of \n */
  511. X       }
  512. X
  513. X    comptr = command;
  514. X    SKIPJUNK(comptr);
  515. X
  516. X    /* save command for later */
  517. X    menu->after_menu = (char *)malloc (strlen(comptr)+5);
  518. X    strcpy (menu->after_menu, comptr);
  519. X    return (0);
  520. X}
  521. X/* Paul J. Condie  4-90 */
  522. SHAR_EOF
  523. chmod 0644 ParAftMenu.c || echo "restore of ParAftMenu.c fails"
  524. echo "x - extracting ShowOption.c (Text)"
  525. sed 's/^X//' << 'SHAR_EOF' > ShowOption.c &&
  526. Xstatic char Sccsid[] = "%W%   DeltaDate %G%   ExtrDate %H%";
  527. X
  528. X/*  FUNCTION:    ShowOption()
  529. X**        Displays a option to the screen.
  530. X**  ARGS:    menu        menu structure
  531. X**        index        option # to display
  532. X**  RETURNS:    none
  533. X*/
  534. X
  535. X#include    <curses.h>
  536. X#include    "menu.h"
  537. X
  538. Xextern int    debug;
  539. X
  540. X
  541. XShowOption (menu, index)
  542. X
  543. X    struct MenuInfo    *menu;
  544. X    int        index;
  545. X{
  546. X
  547. X
  548. X    /*
  549. X    **    Now display option.
  550. X    */
  551. X       mvprintw (menu->option[index]->row, menu->option[index]->col, "%2d.  ",
  552. X        menu->option[index]->opnumber);
  553. X   
  554. X       displaytext (stdscr, menu->option[index]->row, 
  555. X             menu->option[index]->col+5,
  556. X        menu->option[index]->description);
  557. X
  558. X    if (debug)
  559. X    {
  560. X        fprintf (stderr, "\n[ShowOption] <%s> row=%d col=%d", 
  561. X            menu->option[index]->keyword,
  562. X            menu->option[index]->row, 
  563. X            menu->option[index]->col);
  564. X    }
  565. X}
  566. SHAR_EOF
  567. chmod 0644 ShowOption.c || echo "restore of ShowOption.c fails"
  568. echo "x - extracting RunSystem.c (Text)"
  569. sed 's/^X//' << 'SHAR_EOF' > RunSystem.c &&
  570. Xstatic char Sccsid[] = "%W%   DeltaDate %G%   ExtrDate %H%";
  571. X
  572. X/*  FUNCTION:    RunSystem()
  573. X**        Runs keyword ".SYSTEM".
  574. X**  ARGS:    option        option info sturcture
  575. X**  RETURNS:    none
  576. X*/
  577. X
  578. X#include    <curses.h>
  579. X#include    <ctype.h>
  580. X#include    <signal.h>
  581. X#include    "menu.h"
  582. X
  583. Xextern    int    errno;
  584. Xextern    int    debug;
  585. X
  586. XRunSystem (menu, opnumber, KeyWord, ParseKey, ShowKey, RunKey, 
  587. X        gnames, gfiles, gindex)
  588. X    struct MenuInfo        *menu;
  589. X    int            opnumber;
  590. X    int            (*ParseKey[MAXKEYS])(),
  591. X                (*ShowKey[MAXKEYS])(),
  592. X                (*RunKey[MAXKEYS])();
  593. X    char            KeyWord[MAXKEYS][MAXKEYLENGTH];
  594. X    char            gnames[MAXGNAME][15];
  595. X    char            gfiles[MAXGNAME][15];
  596. X    int            gindex;
  597. X{
  598. X    int            shutdown();
  599. X    char            *command = (char *)NULL;
  600. X    int            rc;        /* return code */
  601. X    char            *comptr;
  602. X    int            screenflag = FALSE;
  603. X
  604. X
  605. X
  606. X    /*
  607. X    ** we need to allocate enough space to hold the command
  608. X    ** the description and the tput clear stuff
  609. X    */
  610. X    command = (char *)malloc (strlen (menu->option[opnumber]->command) +
  611. X            strlen (menu->option[opnumber]->description) + 100);
  612. X    comptr = menu->option[opnumber]->command;
  613. X    SKIPJUNK(comptr);
  614. X
  615. X    if (substr (comptr, "GETINPUT") != NULL)
  616. X    {
  617. X        sscanf (comptr, "%s", command);
  618. X        /*
  619. X        **  Loop through each variable=value until GETINPUT is found
  620. X        */
  621. X        do
  622. X        {
  623. X            if (strcmp (command, "GETINPUT") == 0)
  624. X            {
  625. X                screenflag = TRUE;
  626. X                /* get screen name */
  627. X                comptr += strlen(command);
  628. X                SKIPJUNK(comptr);
  629. X                   sscanf (comptr, "%s", command);/* screen name */
  630. X                comptr += strlen(command);
  631. X                SKIPJUNK(comptr);     /* sitting at system(3) */
  632. X                rc = runscreen (command, menu, opnumber);
  633. X                if (rc == KEY_CANCEL)
  634. X                {
  635. X                    free (command);
  636. X                    return (0);
  637. X                }
  638. X                break;
  639. X            }
  640. X            else
  641. X            {
  642. X                rc = setvariable (&comptr);
  643. X                if (rc != 0) break;
  644. X            }
  645. X
  646. X            SKIPJUNK(comptr);
  647. X               rc = sscanf (comptr, "%s", command);/* next var=value */
  648. X        } while (rc != EOF);
  649. X    } /* end if GETINPUT */
  650. X
  651. X
  652. X    /* run system command */
  653. X    refresh();            /* force curses to flush attributes */
  654. X    sprintf (command, "%s;echo \"One moment, loading %s%s%s ....\"; %s",
  655. X#if BSD || SUN
  656. X            "clear",
  657. X#else
  658. X            "tput clear",
  659. X#endif
  660. X#if BSD || SUN
  661. X            "",
  662. X#else
  663. X            "`tput smul`",
  664. X#endif
  665. X            menu->option[opnumber]->description,
  666. X#if BSD || SUN
  667. X            "",
  668. X#else
  669. X            "`tput rmul`",
  670. X#endif
  671. X            comptr);
  672. X       reset_shell_mode ();
  673. X    if (debug)
  674. X    {
  675. X        fprintf (stderr, "\n[RunSystem] <%s> command=:%s:", 
  676. X            menu->option[opnumber]->keyword, command);
  677. X    }
  678. X    signal (SIGINT, shutdown);
  679. X    signal (SIGQUIT, shutdown);
  680. X       rc = system (command);
  681. X    signal (SIGINT, SIG_IGN);
  682. X    signal (SIGQUIT, SIG_IGN);
  683. X    if (debug)
  684. X    {
  685. X        fprintf (stderr, 
  686. X            "\n[RunSystem] <%s> return code = %d, errno = %d", 
  687. X            rc, errno);
  688. X    }
  689. X
  690. X       reset_prog_mode ();
  691. X    clearok (stdscr, TRUE);
  692. X
  693. X
  694. X    free (command);
  695. X
  696. X    if (rc == 0  &&  screenflag)
  697. X        return (REPARSE);
  698. X       return (rc);
  699. X}
  700. SHAR_EOF
  701. chmod 0644 RunSystem.c || echo "restore of RunSystem.c fails"
  702. echo "x - extracting RunExit.c (Text)"
  703. sed 's/^X//' << 'SHAR_EOF' > RunExit.c &&
  704. Xstatic char Sccsid[] = "%W%   DeltaDate %G%   ExtrDate %H%";
  705. X
  706. X/*  FUNCTION:    RunExit()
  707. X**        Runs keyword ".EXIT".
  708. X**        Exit menu program.
  709. X**  ARGS:    option        option info sturcture
  710. X**  RETURNS:    none
  711. X*/
  712. X
  713. X#include    <curses.h>
  714. X#include    <signal.h>
  715. X#include    "menu.h"
  716. X
  717. Xextern int    trapsigs;
  718. X
  719. XRunExit (menu, opnumber, KeyWord, ParseKey, ShowKey, RunKey, 
  720. X        gnames, gfiles, gindex)
  721. X    struct MenuInfo        *menu;
  722. X    int            opnumber;
  723. X    int            (*ParseKey[MAXKEYS])(),
  724. X                (*ShowKey[MAXKEYS])(),
  725. X                (*RunKey[MAXKEYS])();
  726. X    char            KeyWord[MAXKEYS][MAXKEYLENGTH];
  727. X    char            gnames[MAXGNAME][15];
  728. X    char            gfiles[MAXGNAME][15];
  729. X    int            gindex;
  730. X{
  731. X    int            shutdown();
  732. X    int            rc;        /* return code */
  733. X
  734. X    refresh ();
  735. X    if (strcmp (menu->option[opnumber]->command, "") != 0)
  736. X    {
  737. X           reset_shell_mode ();
  738. X        signal (SIGINT, shutdown);
  739. X        signal (SIGQUIT, shutdown);
  740. X           rc = system (menu->option[opnumber]->command);
  741. X        if (trapsigs)
  742. X        {
  743. X            signal (SIGINT, SIG_IGN);
  744. X            signal (SIGQUIT, SIG_IGN);
  745. X        }
  746. X           reset_prog_mode ();
  747. X    }
  748. X    return (QUIT);
  749. X}
  750. SHAR_EOF
  751. chmod 0644 RunExit.c || echo "restore of RunExit.c fails"
  752. echo "x - extracting RunSetenv.c (Text)"
  753. sed 's/^X//' << 'SHAR_EOF' > RunSetenv.c &&
  754. Xstatic char Sccsid[] = "@(#)RunSetenv.c    1.7   DeltaDate 1/22/90   ExtrDate 1/22/90";
  755. X
  756. X/*  FUNCTION:    RunSetenv()
  757. X**        Runs keyword ".SETENV".
  758. X**  ARGS:    option        option info sturcture
  759. X**  RETURNS:    none
  760. X*/
  761. X
  762. X#include    <curses.h>
  763. X#include    <string.h>
  764. X#include    <ctype.h>
  765. X#include    "menu.h"
  766. X
  767. X
  768. XRunSetenv (menu, opnumber, KeyWord, ParseKey, ShowKey, RunKey, 
  769. X        gnames, gfiles, gindex)
  770. X    struct MenuInfo        *menu;
  771. X    int            opnumber;
  772. X    int            (*ParseKey[MAXKEYS])(),
  773. X                (*ShowKey[MAXKEYS])(),
  774. X                (*RunKey[MAXKEYS])();
  775. X    char            KeyWord[MAXKEYS][MAXKEYLENGTH];
  776. X    char            gnames[MAXGNAME][15];
  777. X    char            gfiles[MAXGNAME][15];
  778. X    int            gindex;
  779. X{
  780. X    char            *strchr();
  781. X    int            rc;
  782. X    char            command[BUFSIZ];
  783. X    char            *comptr;
  784. X    int            BELLFLAG=FALSE;
  785. X
  786. X
  787. X    /*
  788. X    **  The first argument [ BELL ]
  789. X    */
  790. X    comptr = menu->option[opnumber]->command;
  791. X    SKIPJUNK(comptr);
  792. X       sscanf (comptr, "%s", command);        /* do we have a BELL */
  793. X    if (strcmp (command, "BELL") == 0)
  794. X    {
  795. X        BELLFLAG = TRUE;
  796. X        comptr += strlen(command);
  797. X    }
  798. X
  799. X    do
  800. X    {
  801. X        rc = setvariable (&comptr);
  802. X        if (rc != 0) break;
  803. X           rc = sscanf (comptr, "%s", command);    /* get next var=value */
  804. X        if (rc == EOF)   break;
  805. X        /* if the command has an = sign in it, it is another one */
  806. X        if (!strmatch(command, "*=*"))
  807. X            break;
  808. X    } while (rc != EOF);
  809. X
  810. X    SKIPJUNK(comptr);
  811. X    mvprintw (ErrRow, 0, "%s", comptr);        /* dispaly message */
  812. X    if (BELLFLAG)
  813. X        BEEP;
  814. X
  815. X    return (REPARSE);
  816. X}
  817. X/* Paul J. Condie  10/88 */
  818. SHAR_EOF
  819. chmod 0444 RunSetenv.c || echo "restore of RunSetenv.c fails"
  820. echo "x - extracting RunMenu.c (Text)"
  821. sed 's/^X//' << 'SHAR_EOF' > RunMenu.c &&
  822. Xstatic char Sccsid[] = "@(#)RunMenu.c    1.7   DeltaDate 1/22/90   ExtrDate 1/22/90";
  823. X
  824. X/*  FUNCTION:    RunMenu()
  825. X**        Runs keyword ".MENU".
  826. X**  ARGS:    option        option info sturcture
  827. X**  RETURNS:    none
  828. X*/
  829. X
  830. X#include    <curses.h>
  831. X#include    <ctype.h>
  832. X#include    "menu.h"
  833. X
  834. XRunMenu (menu, opnumber, KeyWord, ParseKey, ShowKey, RunKey, 
  835. X        gnames, gfiles, gindex)
  836. X    struct MenuInfo        *menu;
  837. X    int            opnumber;
  838. X    int            (*ParseKey[MAXKEYS])(),
  839. X                (*ShowKey[MAXKEYS])(),
  840. X                (*RunKey[MAXKEYS])();
  841. X    char            KeyWord[MAXKEYS][MAXKEYLENGTH];
  842. X    char            gnames[MAXGNAME][15];
  843. X    char            gfiles[MAXGNAME][15];
  844. X    int            gindex;
  845. X{
  846. X    char            command[BUFSIZ];
  847. X    int            rc;        /* return code */
  848. X    char            *comptr;
  849. X
  850. X    /*
  851. X    **  The first argument is the menu script filename
  852. X    */
  853. X    comptr = menu->option[opnumber]->command;
  854. X    SKIPJUNK (comptr);
  855. X       sscanf (comptr, "%s", command);            /* filename */
  856. X    comptr += strlen(command);
  857. X    SKIPJUNK (comptr);
  858. X       sscanf (comptr, "%s", command);        /* next argument */
  859. X
  860. X    /*
  861. X    **  Loop through each variable=value || GETINPUT
  862. X    */
  863. X    do
  864. X    {
  865. X        if (strcmp (command, "GETINPUT") == 0)
  866. X        {
  867. X            /* get screen name */
  868. X            comptr += strlen(command);
  869. X            SKIPJUNK(comptr);
  870. X               sscanf (comptr, "%s", command);    /* screen name */
  871. X            comptr += strlen(command);
  872. X            SKIPJUNK(comptr);    /* sitting at next argument */
  873. X            rc = runscreen (command, menu, opnumber);
  874. X            if (rc == KEY_CANCEL)
  875. X                return (0);
  876. X        }
  877. X        else
  878. X        {
  879. X            rc = setvariable (&comptr);
  880. X            if (rc != 0) break;
  881. X        }
  882. X
  883. X           rc = sscanf (comptr, "%s", command);/* next var=value */
  884. X    } while (rc != EOF);
  885. X
  886. X    return (SUBMENU);
  887. X}
  888. X/* Paul J. Condie  5/88 */
  889. SHAR_EOF
  890. chmod 0444 RunMenu.c || echo "restore of RunMenu.c fails"
  891. echo "x - extracting RunPopMenu.c (Text)"
  892. sed 's/^X//' << 'SHAR_EOF' > RunPopMenu.c &&
  893. X#ifndef LINT
  894. Xstatic char Sccsid[] = "%W%   DeltaDate %G%   ExtrDate %H%";
  895. X#endif
  896. X
  897. X/*  FUNCTION:    RunPopMenu()
  898. X**        Runs keyword ".POPMENU".
  899. X**        RunPopMenu will use recursion if there is another .POPMENU
  900. X**        within .POPMENU.
  901. X**  ARGS:    option        option info sturcture
  902. X**  RETURNS:    none
  903. X*/
  904. X
  905. X#include    <curses.h>
  906. X#include    <string.h>
  907. X#include    <ctype.h>
  908. X#include    "menu.h"
  909. X
  910. X#define    INITMENU    0
  911. X#define    CREATEMENU    -2
  912. X#define    UNHILIGHTBOX    -1
  913. X
  914. X
  915. XRunPopMenu (menu, opnumber, KeyWord, ParseKey, ShowKey, RunKey, 
  916. X        gnames, gfiles, gindex)
  917. X    struct MenuInfo        *menu;
  918. X    int            opnumber;
  919. X    int            (*ParseKey[MAXKEYS])(),
  920. X                (*ShowKey[MAXKEYS])(),
  921. X                (*RunKey[MAXKEYS])();
  922. X    char            KeyWord[MAXKEYS][MAXKEYLENGTH];
  923. X    char            gnames[MAXGNAME][15];
  924. X    char            gfiles[MAXGNAME][15];
  925. X    int            gindex;
  926. X{
  927. X    FILE            *fopen(), *menufile;
  928. X    char            *strchr();
  929. X    char            *findfile();
  930. X    char            *getenv();
  931. X    char            command[BUFSIZ];
  932. X    int            rc;            /* return code */
  933. X    char            *comptr;
  934. X    int            row, col;        /* top left corner */
  935. X    char            *filename;
  936. X    int            i;
  937. X    static int        popmid = 9;        /* popup menu id */
  938. X    int            titleline[200];        /* title 1 on stdscr */
  939. X    char            poptitle[200];        /* title for popmenu */
  940. X    int            DIMFLAG = TRUE;
  941. X    struct MenuInfo        pmenu;
  942. X    char            PopMenu[100][80];    /* the pop menu */
  943. X    int            AUTOFIG = FALSE;    /* figure row/col */
  944. X
  945. X
  946. X    comptr = menu->option[opnumber]->command;
  947. X    SKIPJUNK(comptr);
  948. X       sscanf (comptr, "%s", command);        /* do we have NoDim */
  949. X    if (strcmp (command, "NoDim") == 0)
  950. X    {
  951. X        DIMFLAG = FALSE;
  952. X        comptr += strlen(command);
  953. X    }
  954. X
  955. X    SKIPJUNK(comptr);
  956. X       sscanf (comptr, "%s", command);        /* menufile name */
  957. X    comptr += strlen(command);
  958. X    SKIPJUNK(comptr);
  959. X
  960. X    /* do we have a row/column parameter 
  961. X    ** we'll use titleline for working storage
  962. X    */
  963. X       sscanf (comptr, "%s", titleline);    /* get next argument */
  964. X    if (*comptr != '\0' && strchr (titleline, '=') == (char *)NULL)
  965. X    {
  966. X        /* we have a row/column parameter */
  967. X        /* get row and column */
  968. X        sscanf (comptr, "%d", &row);
  969. X        comptr = strchr (comptr, ' ');        /* past row */
  970. X        SKIPJUNK(comptr);            /* at begining of col */
  971. X        sscanf (comptr, "%d", &col);
  972. X        comptr = strchr (comptr, ' ');        /* past column */
  973. X    }
  974. X    else
  975. X        AUTOFIG = TRUE;
  976. X
  977. X
  978. X    /*
  979. X    **  Loop through each variable=value
  980. X    */
  981. X    do
  982. X    {
  983. X        rc = setvariable (&comptr);
  984. X        if (rc != 0) break;
  985. X    } while (rc != EOF);
  986. X
  987. X    /*
  988. X    **  Open and Parse the popmenu
  989. X    */
  990. X    filename = findfile (command, ".", getenv("MENUDIR"), "");
  991. X          if ((menufile = fopen (filename, "r")) == NULL)
  992. X          {
  993. X            BEEP;
  994. X                mvprintw (ErrRow-2, 0, "Unable to locate (%s) file.", command);
  995. X                shutdown ();
  996. X          }
  997. X
  998. X    /*
  999. X    **  The ParseTitle will put the .POPMENU title on line 0 of stdscr
  1000. X    **  so we need to save original title
  1001. X    **  then read and compare title 1 to see what the title for popmenu
  1002. X    **  should be.
  1003. X    **  Then write the original title back out. (whew)
  1004. X    */
  1005. X    /* save title line 0 with attributes */
  1006. X    for (i = 0; i <= COLS; i++)
  1007. X        titleline[i] = mvwinch (stdscr, 0, i);
  1008. X
  1009. X    initmenu (&pmenu);
  1010. X
  1011. X          rc = parsedriver (menufile, KeyWord, ParseKey, &pmenu, gnames, gfiles, 
  1012. X            &gindex);
  1013. X          fclose (menufile);
  1014. X
  1015. X    if (AUTOFIG)
  1016. X    {
  1017. X        int    longest;
  1018. X
  1019. X        /*
  1020. X        ** try to put menu as close to the option as possible
  1021. X        **  menu->option[opnumber]->row holds the
  1022. X        **  location on stdscr of the option that selected this.
  1023. X        */
  1024. X        row = menu->option[opnumber]->row - 1;
  1025. X        col = menu->option[opnumber]->col + 
  1026. X                        strlen (menu->option[opnumber]->description);
  1027. X        if (popmid == 9)
  1028. X            col += 4;
  1029. X
  1030. X        /* make sure it fits on the screen */
  1031. X        if ((row + pmenu.optioncount + 2) > LINES)
  1032. X            row = LINES - pmenu.optioncount - 2;
  1033. X
  1034. X        for (i = 0, longest = 0; i < pmenu.optioncount; i++)
  1035. X            if (strlen (pmenu.option[i]->description) > longest)
  1036. X                longest = strlen (pmenu.option[i]->description);
  1037. X        if ((col + longest + 4) > COLS)
  1038. X            col = COLS - longest - 4;
  1039. X
  1040. X        if (row < 0)
  1041. X            row = 0;
  1042. X
  1043. X        /*
  1044. X        **  Recalculate the options row and col for recursion
  1045. X        */
  1046. X        for (i = 0; i < pmenu.optioncount; i++)
  1047. X        {
  1048. X            pmenu.option[i]->row = row + 1 + i;
  1049. X            pmenu.option[i]->col = col;
  1050. X        }
  1051. X    }
  1052. X
  1053. X    /* find popmenu title in line 0 */
  1054. X    for (i = 0; i <= COLS; i++)
  1055. X    {
  1056. X        poptitle[i] = ' ';
  1057. X        if (mvwinch (stdscr, 0,i) != titleline[i])
  1058. X        {
  1059. X            poptitle[i] = mvwinch(stdscr, 0,i);
  1060. X        }
  1061. X        else
  1062. X            poptitle[i] = ' ';
  1063. X        /* write original title back out */
  1064. X        mvwaddch (stdscr, 0,i, titleline[i]);
  1065. X    }
  1066. X    poptitle[i] = '\0';
  1067. X    /* junk trailing spaces */
  1068. X    for (i = strlen(poptitle)-1; i >= 0; i--)
  1069. X        if (poptitle[i] == ' ')
  1070. X            poptitle[i] = '\0';
  1071. X        else
  1072. X            break;
  1073. X
  1074. X    if (rc != 0) return (rc);            /* from parsemenu */
  1075. X
  1076. X
  1077. X
  1078. X    /* if .BOX||.LINE && DIM then unhilight */
  1079. X    if (DIMFLAG)
  1080. X    {
  1081. X        /* Dim the .BOX */
  1082. X        if (menu->boxtype)
  1083. X            drawbox (stdscr, 1,1, LINES-1,COLS, 
  1084. X                (menu->boxtype&0777000)>>9, DumbLine,
  1085. X                FALSE, FALSE);
  1086. X
  1087. X        /* Dim the .LINE */
  1088. X        if (menu->linetype)
  1089. X            drawline (stdscr, menu->titlecount-1, 
  1090. X                (menu->linetype&0777000)>>9, DumbLine, 
  1091. X                menu->boxtype);
  1092. X
  1093. X        wnoutrefresh (stdscr);
  1094. X    }
  1095. X
  1096. X    /* popmid = 10+ */
  1097. X    popmid++;
  1098. X    for (i = 0; i < pmenu.optioncount; i++)
  1099. X        strcpy (PopMenu[i], pmenu.option[i]->description);
  1100. X    strcpy (PopMenu[i], "");
  1101. X    popmenu (INITMENU, popmid, row, col, poptitle, HELPFILE,
  1102. X            LINES-2, sizeof(PopMenu[0]), PopMenu);
  1103. X
  1104. X    rc = popmenu (popmid, (char *)NULL);
  1105. X
  1106. X    /* run option selected */
  1107. X    if (rc > 0)
  1108. X    {
  1109. X        for (i = 1; i <= MAXKEYS && strcmp (KeyWord[i], "") != 0; i++)
  1110. X            if (strcmp (pmenu.option[rc-1]->keyword, 
  1111. X                    KeyWord[i]) == 0)
  1112. X            {
  1113. X                if (RunKey[i] != NULL)
  1114. X                {
  1115. X                    /*
  1116. X                    **  Dim box is option is a .POPMENU or
  1117. X                    **  a .GETINPUT or a .SYSTEM GETINPUT
  1118. X                    */
  1119. X                    comptr = pmenu.option[rc-1]->command;
  1120. X                    SKIPJUNK(comptr);
  1121. X                       sscanf (comptr, "%s", command);
  1122. X                    if (strcmp (pmenu.option[rc-1]->keyword, ".POPMENU") == 0  ||
  1123. X                        strcmp (pmenu.option[rc-1]->keyword, ".GETINPUT") == 0 ||
  1124. X                        (strcmp (pmenu.option[rc-1]->keyword, ".SYSTEM") == 0 && 
  1125. X                         strcmp (command, "GETINPUT") == 0))
  1126. X                        popmenu (UNHILIGHTBOX, popmid);
  1127. X
  1128. X                         rc = (*RunKey[i]) (&pmenu, rc-1,
  1129. X                        KeyWord, ParseKey, ShowKey, 
  1130. X                        RunKey, gnames, gfiles, gindex);
  1131. X                }
  1132. X                break;
  1133. X            }
  1134. X    }
  1135. X    else
  1136. X        rc = 0;            /* popmenu was cancelled, continue */
  1137. X
  1138. X    popmid--;
  1139. X
  1140. X    /* run after_menu if there is one */
  1141. X    if (pmenu.after_menu != (char *)NULL)
  1142. X        RunAftMenu (&pmenu);
  1143. X
  1144. X    clean_menu (&pmenu);
  1145. X
  1146. X    if (DIMFLAG)
  1147. X    {
  1148. X        /* hilight .BOX */
  1149. X        if (menu->boxtype)
  1150. X            drawbox (stdscr, 1,1, LINES-1,COLS, 
  1151. X                menu->boxtype & 0777, StandoutLine,
  1152. X                FALSE, FALSE);
  1153. X
  1154. X        /* hilight .LINE */
  1155. X        if (menu->linetype)
  1156. X            drawline (stdscr, menu->titlecount-1,
  1157. X                menu->linetype & 0777, StandoutLine,
  1158. X                menu->boxtype);
  1159. X    }
  1160. X
  1161. X    touchwin (stdscr);
  1162. X
  1163. X        if (rc != 0)  
  1164. X        return (rc);
  1165. X    else
  1166. X        return (REPARSE);
  1167. X}
  1168. X/* Paul J. Condie  10/88 */
  1169. SHAR_EOF
  1170. chmod 0644 RunPopMenu.c || echo "restore of RunPopMenu.c fails"
  1171. echo "x - extracting RunGetI.c (Text)"
  1172. sed 's/^X//' << 'SHAR_EOF' > RunGetI.c &&
  1173. X#ifndef LINT
  1174. Xstatic char Sccsid[] = "%W%   DeltaDate %G%   ExtrDate %H%";
  1175. X#endif
  1176. X
  1177. X/*  FUNCTION:    RunGetInpt()
  1178. X**        Runs keyword ".GETINPUT".
  1179. X**  ARGS:    option        option info sturcture
  1180. X**  RETURNS:    none
  1181. X*/
  1182. X
  1183. X#include    <curses.h>
  1184. X#include    <term.h>
  1185. X#include    <ctype.h>
  1186. X#include    "menu.h"
  1187. X
  1188. X
  1189. X
  1190. XRunGetInput (menu, opnumber, KeyWord, ParseKey, ShowKey, RunKey, 
  1191. X        gnames, gfiles, gindex)
  1192. X    struct MenuInfo        *menu;
  1193. X    int            opnumber;
  1194. X    int            (*ParseKey[MAXKEYS])(),
  1195. X                (*ShowKey[MAXKEYS])(),
  1196. X                (*RunKey[MAXKEYS])();
  1197. X    char            KeyWord[MAXKEYS][MAXKEYLENGTH];
  1198. X    char            gnames[MAXGNAME][15];
  1199. X    char            gfiles[MAXGNAME][15];
  1200. X    int            gindex;
  1201. X{
  1202. X    char            screen_name[50];
  1203. X    int            rc;        /* return code */
  1204. X    char            *comptr;
  1205. X
  1206. X    /*
  1207. X    **  The first argument is the screen name
  1208. X    */
  1209. X    comptr = menu->option[opnumber]->command;
  1210. X    SKIPJUNK(comptr);
  1211. X       sscanf (menu->option[opnumber]->command, "%s", screen_name);
  1212. X    comptr += strlen (screen_name);
  1213. X    SKIPJUNK(comptr);
  1214. X
  1215. X    /*
  1216. X    **  Loop through each variable=value
  1217. X    */
  1218. X    do
  1219. X    {
  1220. X        rc = setvariable (&comptr);
  1221. X        if (rc != 0) break;
  1222. X    } while (rc != EOF);
  1223. X
  1224. X    rc = runscreen (screen_name, menu, opnumber);
  1225. X    if (rc == KEY_CANCEL)
  1226. X        return (0);
  1227. X    else
  1228. X        return (REPARSE);
  1229. X}
  1230. SHAR_EOF
  1231. chmod 0644 RunGetI.c || echo "restore of RunGetI.c fails"
  1232. echo "x - extracting RunAftMenu.c (Text)"
  1233. sed 's/^X//' << 'SHAR_EOF' > RunAftMenu.c &&
  1234. X/*  FUNCTION:    RunAftMenu()
  1235. X**        Runs keyword ".AFTER_MENU".
  1236. X**  ARGS:
  1237. X**        menu        menu structure
  1238. X**  RETURNS:    none
  1239. X*/
  1240. X
  1241. X#include    <curses.h>
  1242. X#include    <ctype.h>
  1243. X#include    <signal.h>
  1244. X#include    "menu.h"
  1245. X
  1246. X
  1247. Xextern    int    debug;
  1248. Xextern    int    trapsigs;
  1249. X
  1250. X
  1251. X
  1252. XRunAftMenu (menu)
  1253. X    struct MenuInfo    *menu;
  1254. X{
  1255. X    int        shutdown();
  1256. X    int        rc;
  1257. X    char        *comptr;
  1258. X    char        tmpstr[80];
  1259. X    int        redrawflag = FALSE;
  1260. X
  1261. X
  1262. X
  1263. X    comptr = menu->after_menu;
  1264. X    SKIPJUNK(comptr);
  1265. X
  1266. X
  1267. X       sscanf (comptr, "%s", tmpstr);        /* do we have a REDRAW */
  1268. X    if (strcmp (tmpstr, "REDRAW") == 0)
  1269. X    {
  1270. X        redrawflag = TRUE;
  1271. X        comptr += strlen(tmpstr);
  1272. X        SKIPJUNK(comptr);
  1273. X           sscanf (comptr, "%s", tmpstr);    /* do we have a GETINPUT */
  1274. X    }
  1275. X
  1276. X    if (strcmp (tmpstr, "GETINPUT") == 0)
  1277. X    {
  1278. X        /* get screen name */
  1279. X        comptr += strlen(tmpstr);
  1280. X        SKIPJUNK(comptr);
  1281. X           sscanf (comptr, "%s", tmpstr);        /* screen name */
  1282. X        comptr += strlen(tmpstr);
  1283. X        SKIPJUNK(comptr);        /* sitting at system(3) */
  1284. X        rc = runscreen (tmpstr, menu, 1);
  1285. X        if (rc == KEY_CANCEL)
  1286. X            return (0);
  1287. X    }
  1288. X
  1289. X    reset_shell_mode ();
  1290. X    signal (SIGINT, shutdown);
  1291. X    signal (SIGQUIT, shutdown);
  1292. X       rc = system (comptr);
  1293. X    if (trapsigs)
  1294. X    {
  1295. X        signal (SIGINT, SIG_IGN);
  1296. X        signal (SIGQUIT, SIG_IGN);
  1297. X    }
  1298. X    reset_prog_mode ();
  1299. X    keypad (stdscr, TRUE);
  1300. X
  1301. X    /*
  1302. X    **  Going from a shell return code (char) to a c return code (int)
  1303. X    **  the shell return code gets put in the high byte.  So we will
  1304. X    **  shift the int right 8 bytes.
  1305. X    */
  1306. X    rc = rc >> 8;                    /* to get shell rc */
  1307. X    if (debug)
  1308. X    {
  1309. X        fprintf (stderr, "\n[%s] <%s> rc=%d  command=%s", 
  1310. X            __FILE__, ".AFTER_MENU", rc, comptr);
  1311. X        fflush (stderr);
  1312. X    }
  1313. X
  1314. X    /*
  1315. X    **  Shell can't handle negative return codes so we will convert 
  1316. X    **  the return code to negative so menu can use it.
  1317. X    **    -1 = QUIT
  1318. X    **    -2 = MAINMENU
  1319. X    **    -3 = PREVMENU
  1320. X    **    -4 = NOWAYJOSE
  1321. X    **    100+offset = GNAME
  1322. X    */
  1323. X    if (rc < GNAMEOFFSET)
  1324. X        rc -= rc * 2;                /* make negative */
  1325. X
  1326. X    if (redrawflag)
  1327. X        clearok (stdscr, TRUE);
  1328. X
  1329. X    return (rc);
  1330. X}
  1331. X/* Paul J. Condie  4-90 */
  1332. SHAR_EOF
  1333. chmod 0644 RunAftMenu.c || echo "restore of RunAftMenu.c fails"
  1334. echo "x - extracting GetOption.c (Text)"
  1335. sed 's/^X//' << 'SHAR_EOF' > GetOption.c &&
  1336. Xstatic char Sccsid[] = "%W%   DeltaDate %G%   ExtrDate %H%";
  1337. X#include    <curses.h>
  1338. X#include    <ctype.h>
  1339. X#include    "menu.h"
  1340. X#include    "terminal.h"
  1341. X
  1342. Xextern int    HotKeys;
  1343. X    int    ch;            /* input character */
  1344. X
  1345. X
  1346. XGetOption (row, col, s)
  1347. X
  1348. X    int    row;            /* row to get user input */
  1349. X    int    col;            /* col to get user input */
  1350. X    char    *s;            /* memory string to store input */
  1351. X{
  1352. X    char    *findfile();
  1353. X    char    *getenv();
  1354. X    char    *ws;            /* working string */
  1355. X    int    cc;            /* column count */
  1356. X    int    i;            /* work variable */
  1357. X    char    hlpfile[100];
  1358. X
  1359. X
  1360. X    ws = s;                /* set to memory string */
  1361. X    cc = col;
  1362. X
  1363. X    for (i = col; i <= col+3; i++)    /* blank out prompt field */
  1364. X       mvaddch (row, i, ' ');
  1365. X                    /* display default text */
  1366. X    while (*ws)
  1367. X    {
  1368. X        move (row, cc++);
  1369. X        addch (*ws);
  1370. X        ws++;
  1371. X    }
  1372. X                    /* loop until done */
  1373. X    for (;;)
  1374. X    {
  1375. X        move (row, cc);
  1376. X        refresh ();
  1377. X        ch = mygetch ();
  1378. X        move (ErrRow, 0);  clrtoeol ();
  1379. X
  1380. X              if (ch == KeyDown)       ch = KEY_DOWN;
  1381. X              if (ch == KeyUp)    ch = KEY_UP;
  1382. X              if (ch == KeyTab)    ch = KEY_TAB;
  1383. X              if (ch == KeyBTab)    ch = KEY_BTAB;
  1384. X              if (ch == KeyReturn)    ch = KEY_RETURN;
  1385. X        if (ch == KeyBackspace)    ch = KEY_BACKSPACE;
  1386. X        if (ch == KeyRedraw)    ch = KEY_REFRESH;
  1387. X        if (ch == KeyHelp)    ch = KEY_HELP;
  1388. X        if (ch == KeyMainMenu)    ch = KEY_MAINMENU;
  1389. X        if (ch == KeyPrevMenu)    ch = KEY_PREVMENU;
  1390. X        if (ch == KeyExitMenu)    ch = KEY_EXITMENU;
  1391. X        if (ch == KeyGname)    ch = KEY_GNAME;
  1392. X        if (ch == KeyPopGname)    ch = KEY_POPGNAME;
  1393. X
  1394. X        if (ch >= 'a' && ch <= 'z')
  1395. X            ch = toupper (ch);
  1396. X
  1397. X        switch (ch)
  1398. X        {
  1399. X           case KEY_DOWN:
  1400. X           case KEY_UP:
  1401. X           case KEY_TAB:
  1402. X           case KEY_BTAB:
  1403. X            *s = '\0';    /* reset select to null */
  1404. X           case KEY_RETURN:
  1405. X           case KEY_LINEFEED:
  1406. X           case '0':
  1407. X           case '1':
  1408. X           case '2':
  1409. X           case '3':
  1410. X           case '4':
  1411. X           case '5':
  1412. X           case '6':
  1413. X           case '7':
  1414. X           case '8':
  1415. X           case '9':
  1416. X            return (ch);
  1417. X
  1418. X           case '!':
  1419. X            if (getenv ("SHELL") != (char *)NULL)
  1420. X                return (ch);
  1421. X            break;
  1422. X
  1423. X           case KEY_HELP:
  1424. X           case KEY_EXITMENU:
  1425. X           case KEY_MAINMENU:
  1426. X           case KEY_PREVMENU:
  1427. X           case KEY_GNAME:
  1428. X            if (HotKeys)
  1429. X            {
  1430. X                return (ch);
  1431. X            }
  1432. X            else
  1433. X            {
  1434. X                if (ch == KEY_HELP)
  1435. X                    *ws = KeyHelp;
  1436. X                else if (ch == KEY_EXITMENU)
  1437. X                    *ws = KeyExitMenu;
  1438. X                else if (ch == KEY_MAINMENU)
  1439. X                    *ws = KeyMainMenu;
  1440. X                else if (ch == KEY_PREVMENU)
  1441. X                    *ws = KeyPrevMenu;
  1442. X                else if (ch == KEY_GNAME)
  1443. X                    *ws = KeyGname;
  1444. X                move (row, cc);
  1445. X                addch (*ws);
  1446. X                ws++;
  1447. X                *ws = '\0';
  1448. X                cc++;        /*move over one column*/
  1449. X            }
  1450. X            break;
  1451. X            
  1452. X           case KEY_BACKSPACE:
  1453. X            if (cc == col) 
  1454. X                continue;
  1455. X            else
  1456. X            {
  1457. X                move (row, --cc);    /* back up one column */
  1458. X                addch (' ');
  1459. X                ws--;
  1460. X                *ws = '\0';
  1461. X            }
  1462. X            break;
  1463. X
  1464. X           case KEY_REFRESH:
  1465. X            /* redraw screen */
  1466. X            clearok (stdscr, TRUE);
  1467. X            refresh ();
  1468. X            break;
  1469. X
  1470. X           case KEY_POPGNAME:
  1471. X            return (KeyPopGname);
  1472. X
  1473. X           case ' ':
  1474. X           case 'A':
  1475. X           case 'B':
  1476. X           case 'C':
  1477. X           case 'D':
  1478. X           case 'E':
  1479. X           case 'F':
  1480. X           case 'G':
  1481. X           case 'H':
  1482. X           case 'I':
  1483. X           case 'J':
  1484. X           case 'K':
  1485. X           case 'L':
  1486. X           case 'M':
  1487. X           case 'N':
  1488. X           case 'O':
  1489. X           case 'P':
  1490. X           case 'Q':
  1491. X           case 'R':
  1492. X           case 'S':
  1493. X           case 'T':
  1494. X           case 'U':
  1495. X           case 'V':
  1496. X           case 'W':
  1497. X           case 'X':
  1498. X           case 'Y':
  1499. X           case 'Z':
  1500. X            return (ch);
  1501. X
  1502. X           default:
  1503. X            if (isprint (ch))
  1504. X            {
  1505. X                *ws = ch;
  1506. X                move (row, cc);
  1507. X                addch (*ws);
  1508. X                ws++;
  1509. X                *ws = '\0';
  1510. X                cc++;        /*move over one column*/
  1511. X            }
  1512. X            break;
  1513. X        } /* end switch */
  1514. X    } /* end for */
  1515. X}
  1516. SHAR_EOF
  1517. chmod 0644 GetOption.c || echo "restore of GetOption.c fails"
  1518. echo "x - extracting EndWindow.c (Text)"
  1519. sed 's/^X//' << 'SHAR_EOF' > EndWindow.c &&
  1520. Xstatic char Sccsid[] = "@(#)EndWindow.c    1.1   DeltaDate 9/6/87   ExtrDate 1/22/90";
  1521. X/*  FUNCTION:    EndWindow()
  1522. X**        When a "WINDOW" keyword is found this function
  1523. X**        recalculates the row and column to begin 
  1524. X**        displaying the next subwindow.
  1525. X**  ARGS:    menu    current menu structure
  1526. X*/
  1527. X
  1528. X#include    "menu.h"
  1529. X
  1530. Xextern    int    swin, ewin, longest;
  1531. X
  1532. X
  1533. XEndWindow (menu)
  1534. X
  1535. X    struct MenuInfo    *menu;
  1536. X{
  1537. X    int        i;
  1538. X
  1539. X
  1540. X   if (swin == ewin)  return;
  1541. X
  1542. X   longest += 5;
  1543. X
  1544. X/*
  1545. X**    Calculate what row and column to display option on.
  1546. X*/
  1547. X
  1548. X   for (i = swin; i < ewin; i++)
  1549. X   {
  1550. X      menu->option[i]->row = ((menu->wlrow - menu->wfrow) / 2 + menu->wfrow) -
  1551. X                  ((ewin - swin) / 2) + i - swin;
  1552. X      menu->option[i]->col = (menu->wlcol - menu->wfcol) / 2 - 
  1553. X                  longest / 2 + menu->wfcol;
  1554. X   }
  1555. X}
  1556. SHAR_EOF
  1557. chmod 0444 EndWindow.c || echo "restore of EndWindow.c fails"
  1558. echo "x - extracting displaytxt.c (Text)"
  1559. sed 's/^X//' << 'SHAR_EOF' > displaytxt.c &&
  1560. Xstatic char Sccsid[] = "%W%   DeltaDate %G%   ExtrDate %H%";
  1561. X
  1562. X/*  FUNCTION:    displaytext()
  1563. X**        Displays a string to the screen with atributes.
  1564. X**  ARGS:    
  1565. X**        win    curses window to display to
  1566. X**        row    screen row
  1567. X**        col    screen col
  1568. X**        s    the string
  1569. X**  RETURNS:    none
  1570. X*/
  1571. X
  1572. X#include    <curses.h>
  1573. X
  1574. Xdisplaytext (win, row, col, s)
  1575. X    WINDOW    *win;
  1576. X    int    row, col;
  1577. X    char    s[];
  1578. X{
  1579. X    int    i;
  1580. X
  1581. X    wmove (win, row, col);
  1582. X
  1583. X/*
  1584. X**    Now display looking for terminal attributes.
  1585. X*/
  1586. X      for (i = 0; s[i] != '\0'; i++)
  1587. X      {
  1588. X         if (s[i] == '\\')
  1589. X     {
  1590. X#ifdef BSD
  1591. X        if (s[i+1] != 'N') s[i+1] = 'S';   /* Berk only supports standout */
  1592. X#endif
  1593. X            switch (s[++i])
  1594. X            {
  1595. X           case 'S':
  1596. X#ifdef BSD
  1597. X            wstandout (win);
  1598. X#else
  1599. X               wattrset (win, win->_attrs|A_STANDOUT);
  1600. X#endif
  1601. X            break;
  1602. X           case 'B':
  1603. X#ifdef SYS5
  1604. X            wattrset (win, win->_attrs|A_BOLD);
  1605. X#endif
  1606. X            break;
  1607. X           case 'U':
  1608. X#ifdef SYS5
  1609. X            wattrset (win, win->_attrs|A_UNDERLINE);
  1610. X#endif
  1611. X            break;
  1612. X           case 'D':
  1613. X#ifdef SYS5
  1614. X            wattrset (win, win->_attrs|A_DIM);
  1615. X#endif
  1616. X            break;
  1617. X           case 'R':
  1618. X#ifdef SYS5
  1619. X            wattrset (win, win->_attrs|A_REVERSE);
  1620. X#endif
  1621. X            break;
  1622. X           case 'L':
  1623. X#ifdef SYS5
  1624. X            wattrset (win, win->_attrs|A_BLINK);
  1625. X#endif
  1626. X            break;
  1627. X           case 'N': 
  1628. X#ifdef BSD
  1629. X            wstandend (win);
  1630. X#else
  1631. X            wattrset (win, A_NORMAL);
  1632. X#endif
  1633. X            break;
  1634. X        }
  1635. X     }
  1636. X         else
  1637. X            waddch (win, s[i]);
  1638. X      }
  1639. X}
  1640. SHAR_EOF
  1641. chmod 0644 displaytxt.c || echo "restore of displaytxt.c fails"
  1642. echo "x - extracting SetTerm.c (Text)"
  1643. sed 's/^X//' << 'SHAR_EOF' > SetTerm.c &&
  1644. X#ifndef LINT
  1645. Xstatic char Sccsid[] = "%W%   DeltaDate %G%   ExtrDate %H%";
  1646. X#endif
  1647. X
  1648. X#include    <curses.h>
  1649. X#include    "menu.h"
  1650. X
  1651. X                /* default values for dumb terminals */
  1652. X                /* a -1 indicates nokey */
  1653. X/* Mover Keys */
  1654. Xint    KeyReturn    = '\r';    /* \r - menu & GetInput */
  1655. Xint    KeyDown        = 10;    /* \n - menu & GetInput */
  1656. Xint    KeyUp        = 11;    /* ^k - menu & GetInput */
  1657. Xint    KeyTab        = '\t';    /* \t - menu & GetInput */
  1658. Xint    KeyBTab        = -1;    /*    - menu & GetInput */
  1659. X
  1660. X/* Edit Keys */
  1661. Xint    KeyBeg        = 2;    /* ^b - GetInput */
  1662. Xint    KeyEnd        = 5;    /* ^e - GetInput */
  1663. Xint    KeyRight    = 12;    /* ^l - GetInput */
  1664. Xint    KeyLeft        = 8;    /* \b - GetInput */
  1665. Xint    KeyBackspace    = '\b';    /* \b - GetInput */
  1666. Xint    KeyEOL        = 4;    /* ^d - GetInput clear to end of field */
  1667. Xint    KeyDL        = 3;    /* ^c - GetInput clear field and home cursor */
  1668. Xint    KeyDC        = 24;    /* ^x - GetInput delete character */
  1669. Xint    KeyIC        = 20;    /* ^t - GetInput typeover/insert mode */
  1670. X
  1671. X/* Other Keys */
  1672. Xint    KeyHelp        = '?';    /* ?  - menu & GetInput */
  1673. Xint    KeyTOC        = 20;    /* ^t - ShowHelp */
  1674. Xint    KeyRedraw    = 18;    /* ^r - menu & GetInput */
  1675. Xint    KeyCancel    = 27;    /* ESC - menu & GetInput pop-up menus */
  1676. SHAR_EOF
  1677. echo "End of part 5"
  1678. echo "File SetTerm.c is continued in part 6"
  1679. echo "6" > s2_seq_.tmp
  1680. exit 0
  1681.