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

  1. From: pjc@pcbox.UUCP (Paul J. Condie)
  2. Newsgroups: alt.sources
  3. Subject: menu(1)  part 3 of 11
  4. Message-ID: <425@pcbox.UUCP>
  5. Date: 6 Apr 90 17:37:40 GMT
  6.  
  7.  
  8. #!/bin/sh
  9. # this is part 3 of a multipart archive
  10. # do not concatenate these parts, unpack them in order with /bin/sh
  11. # file Main.c continued
  12. #
  13. CurArch=3
  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 Main.c"
  24. sed 's/^X//' << 'SHAR_EOF' >> Main.c
  25. X**                    1 = sub menu 2 = sub sub menu etc.
  26. X**                    menuname[mptr--] = previous menu
  27. X*/
  28. X    char        menuname[MAXMENU][15];            /* filenames  */
  29. X    char        filename[80];
  30. X    int        menuoption[MAXMENU];    /* what option to highlight */
  31. X    int        i, exitkey, mptr=0, rc;
  32. X    int        j;            /* loop variable */
  33. X    char        gnames[MAXGNAME][15];    /* goto menu names */
  34. X    char        gfiles[MAXGNAME][15];    /* goto file names */
  35. X    int        gindex = 0;        /* goto index */
  36. X    char        *ws;
  37. X    extern int    optind;
  38. X    extern char    *optarg;
  39. X    int        gotorow = 6;        /* default goto menu row */
  40. X    int        gotocol = 8;        /* default goto menu col */
  41. X    int        keys = 0;        /* show keyboard values */
  42. X    int        parse_rc = 0;        /* parsedriver return code */
  43. X
  44. X
  45. X
  46. X       TrapSignal (shutdown);
  47. X       signal (SIGALRM, SIG_IGN);        /* to fix bug in curses */
  48. X       while ((rc = getopt (argc, argv, "dp:vk:")) != EOF)
  49. X              switch (rc)
  50. X              {
  51. X            case 'd':
  52. X            /* Get debug excited */
  53. X            debug++;
  54. X            break;
  55. X
  56. X            case 'p':
  57. X            /* Set row and column for ^g */
  58. X            sscanf (optarg, "%d,%d", &gotorow, &gotocol);
  59. X            break;
  60. X
  61. X                case 'v':
  62. X            /* Show Version */
  63. X            fprintf (stderr, "%s   Version %s\n", argv[0], VERSION);
  64. X            exit (0);
  65. X            break;
  66. X           case 'k':
  67. X            /* Show keyboard key values - for .menuinit */
  68. X            keys++;
  69. X            break;
  70. X              }
  71. X       if (argc == optind  &&  (!keys))
  72. X       {
  73. X              fprintf (stderr, 
  74. X               "\nUsage: %s [-v] [-p row,col] [ -keyboard ] menufile\n",
  75. X                argv[0]);
  76. X              exit (1);
  77. X       }
  78. X    if (!keys)
  79. X           sscanf (argv[optind], "%s", menuname[0]);
  80. X       menuoption[0] = 1;
  81. X
  82. X    /* curses stuff */
  83. X       initscr ();
  84. X       cbreak ();
  85. X       noecho ();
  86. X       nonl ();
  87. X#ifdef SYS5
  88. X       keypad (stdscr, TRUE);
  89. X#endif
  90. X
  91. X       SetTerm ();                /* set terminal keyboard */
  92. X    if (keys)
  93. X    {
  94. X        keyboard ();
  95. X        shutdown ();
  96. X    }
  97. X
  98. X       LoadKeys (KeyWord, ParseKey, ShowKey, RunKey);
  99. X
  100. X
  101. X    /*
  102. X    **    Parse, Show and Run each menu selected until exit program.
  103. X    */
  104. X       do
  105. X       {
  106. X              move (0,0);
  107. X              clrtobot ();                /* clear screen */
  108. X
  109. X        /*
  110. X        **  Check the parse return code from the last parse
  111. X        **  to determine what message to display.
  112. X        */
  113. X        switch (parse_rc)
  114. X        {
  115. X           case NOWAYJOSE:
  116. X            BEEP;
  117. X            attrset (A_REVERSE|A_BOLD);
  118. X                  mvprintw (ErrRow, 0, 
  119. X                  "You have not been authorized to run that menu.");
  120. X            attrset (A_NORMAL);
  121. X            break;
  122. X        }
  123. X
  124. X              initmenu (&menu);            /* init menu defaults */
  125. X
  126. X        /* open menu script file */
  127. X        strcpy (filename, findfile (menuname[mptr], ".",
  128. X            getenv("MENUDIR"), ""));
  129. X              if ((menufile = fopen (filename, "r")) == NULL)
  130. X        {
  131. X                    BEEP;
  132. X                    mvprintw (20, 0, "Unable to locate (%s) file.", 
  133. X                    menuname[mptr]);
  134. X                    shutdown ();
  135. X        }
  136. X
  137. X
  138. X        /*
  139. X        **  Return Codes from parsedriver:
  140. X        **    NOWAYJOSE - not authorized for this menu.
  141. X        */
  142. X              parse_rc = parsedriver (menufile, KeyWord, ParseKey, &menu, 
  143. X                gnames, gfiles, &gindex);
  144. X              fclose (menufile);
  145. X
  146. X        switch (parse_rc)
  147. X        {
  148. X           case 0:
  149. X            /* success */
  150. X            break;
  151. X
  152. X           case QUIT:
  153. X            shutdown ();
  154. X            break;
  155. X
  156. X           case MAINMENU:
  157. X            /* not tested */
  158. X            mptr = 0;
  159. X            break;
  160. X
  161. X           default:
  162. X             if (mptr > 0)
  163. X             {
  164. X                    mptr--;        /* return to previous menu */
  165. X                    continue;
  166. X             }
  167. X             else
  168. X            {
  169. X                BEEP;
  170. X                attrset (A_REVERSE|A_BOLD);
  171. X                      mvprintw (ErrRow, 0, 
  172. X                      "You have not been authorized to run that menu.");
  173. X                attrset (A_NORMAL);
  174. X                    shutdown ();  /* not authorized for main menu */
  175. X            }
  176. X            break;
  177. X        } /* end switch (parse_rc) */
  178. X
  179. X        /* display menu */
  180. X              showdriver (KeyWord, ShowKey, &menu);
  181. X
  182. X        /*
  183. X        **  rundriver will return:
  184. X        **    MAINMENU    go directly to main menu
  185. X        **    PREVIOUSMENU    go to previous menu
  186. X        **    REPARSE        reparse & display current menu
  187. X        **    QUIT        quit program.
  188. X        **    0 - 99        option number containing sub menu 
  189. X        **            filename.
  190. X        **    GNAMEOFFSET-199 go directly to menu 
  191. X        **            gnames[exitkey%GNAMEOFFSET]
  192. X        */
  193. X              exitkey = rundriver (KeyWord, RunKey, ShowKey, ParseKey, &menu, 
  194. X                &menuoption[mptr], gnames, gfiles, gindex,
  195. X                gotorow, gotocol);
  196. X
  197. X        clean_menu (&menu);        /* free menu space */
  198. X
  199. X
  200. X              switch (exitkey)
  201. X              {
  202. X                case MAINMENU:
  203. X            mptr = 0;
  204. X            break;
  205. X                case PREVIOUSMENU:
  206. X            if (mptr > 0)   mptr--;
  207. X            break;
  208. X            case REPARSE:
  209. X            break;
  210. X            case QUIT:
  211. X            break;
  212. X        /*
  213. X        **    A submenu option has been selected or a goto menu.
  214. X        **    exitkey is the option # selected (which is a submenu)
  215. X        **    The submenu filename is in menu.option[exitkey]->command
  216. X        */
  217. X                default:
  218. X            if (exitkey >= GNAMEOFFSET)    /* goto gname menu */
  219. X                   strcpy (menuname[++mptr], 
  220. X                    gfiles[exitkey % GNAMEOFFSET]);
  221. X            else
  222. X                   sscanf (menu.option[exitkey]->command, "%s", 
  223. X                       menuname[++mptr]);
  224. X
  225. X            menuoption[mptr] = 1;
  226. X            break;
  227. X              }
  228. X       } while (exitkey != QUIT);
  229. X       shutdown ();
  230. X}
  231. X
  232. X
  233. X
  234. Xshutdown ()
  235. X{
  236. X   refresh ();
  237. X   endwin ();
  238. X   exit (1);
  239. X}
  240. SHAR_EOF
  241. echo "File Main.c is complete"
  242. chmod 0444 Main.c || echo "restore of Main.c fails"
  243. echo "x - extracting LoadKeys.c (Text)"
  244. sed 's/^X//' << 'SHAR_EOF' > LoadKeys.c &&
  245. Xstatic char Sccsid[] = "@(#)LoadKeys.c    1.7   DeltaDate 1/22/90   ExtrDate 1/22/90";
  246. X
  247. X/*  FUNCTION:    LoadKeys()
  248. X**        Identifies all the recognizable keywords and the
  249. X**        function(s) 2b called to process the keyword.
  250. X**  ARGS:    KeyWord        array to hold keywords
  251. X**        ParseKey    array to hold parse functions
  252. X**        ShowKey        array to hold display functions
  253. X**        RunKey        array to hold run functions
  254. X**  RETURNS:    zilch
  255. X*/
  256. X
  257. X#include        "menu.h"
  258. X
  259. XLoadKeys (KeyWord, ParseKey, ShowKey, RunKey)
  260. X
  261. X    char    KeyWord[][MAXKEYLENGTH];
  262. X    int    (*ParseKey[])(), (*ShowKey[])(), (*RunKey[])();
  263. X{
  264. X    int    ParseTitle(), ParseOption(), ParseBanner(), ParseBox(), 
  265. X        ParseLine(), ParseWindow(), ParseComnt(), ParseUnix(),
  266. X        ParseGname(), ParseAuthr(), ParseText(), ParseCursor(),
  267. X        ParseSpace(), ParseDefineScreen(), ParInclude(), ParAssign();
  268. X    int    ShowOption();
  269. X    int    RunSystem(), RunExit(), RunSetenv(), RunMenu(), RunPopMenu(),
  270. X        RunGetInput();
  271. X
  272. X
  273. X/*
  274. X**    SECTION 1:
  275. X**    Starting with base 1.
  276. X**    Identify keywords to be acted upon when found in your
  277. X**    menu file.
  278. X**    Make sure MAXKEYS is >= the number of entries here.
  279. X*/
  280. X
  281. X   strcpy (KeyWord[1], ".TITLE");    /* title line */
  282. X   strcpy (KeyWord[2], ".MENU");    /* submenu option */
  283. X   strcpy (KeyWord[3], ".SYSTEM");    /* system call option */
  284. X   strcpy (KeyWord[4], ".BOX");      /* encase menu in a box */
  285. X   strcpy (KeyWord[5], ".BANNER");     /* welcome banner screen */
  286. X   strcpy (KeyWord[6], ".LINE");     /* line between title & options */
  287. X   strcpy (KeyWord[7], ".WINDOW");     /* window area for options */
  288. X   strcpy (KeyWord[8], "###");         /* comment line */
  289. X   strcpy (KeyWord[9], ".UNIX");     /* unix command line */
  290. X   strcpy (KeyWord[10], ".GNAME");     /* menu name (used in goto menu) */
  291. X   strcpy (KeyWord[11], ".AUTHORIZE");     /* login's authorized to run menu */
  292. X   strcpy (KeyWord[12], ".TEXT");     /* display text at row and column */
  293. X   strcpy (KeyWord[13], ".CURSOR");     /* where to put the cursor */
  294. X   strcpy (KeyWord[14], ".EXIT");     /* exit menu program */
  295. X   strcpy (KeyWord[15], ".SETENV");     /* set enviroment variable */
  296. X   strcpy (KeyWord[16], ".SPACE");     /* put a space between options */
  297. X   strcpy (KeyWord[17], ".POPMENU");     /* pop menu option */
  298. X   strcpy (KeyWord[18], ".DEFINE_SCREEN");/* define a prompt screen */
  299. X   strcpy (KeyWord[19], ".GETINPUT");    /* prompt screen */
  300. X   strcpy (KeyWord[20], ".INCLUDE");    /* include a menu file */
  301. X   strcpy (KeyWord[21], "*=*");        /* assignment - variable=value */
  302. X
  303. X   strcpy (KeyWord[22], "");         /* END OF LIST */
  304. X
  305. X
  306. X/*
  307. X**    SECTION 2:
  308. X**    Starting with base 1.
  309. X**    Identify function names to correspond with above keywords.
  310. X**    These functions describe what is to be done when above keyword
  311. X**    is found while parsing the "menu file".
  312. X**    Every keyword needs a Parse??? function.
  313. X*/
  314. X
  315. X   ParseKey[1] = ParseTitle;
  316. X   ParseKey[2] = ParseOption;
  317. X   ParseKey[3] = ParseOption;
  318. X   ParseKey[4] = ParseBox;
  319. X   ParseKey[5] = ParseBanner;
  320. X   ParseKey[6] = ParseLine;
  321. X   ParseKey[7] = ParseWindow;
  322. X   ParseKey[8] = ParseComnt;
  323. X   ParseKey[9] = ParseUnix;
  324. X   ParseKey[10] = ParseGname;
  325. X   ParseKey[11] = ParseAuthr;
  326. X   ParseKey[12] = ParseText;
  327. X   ParseKey[13] = ParseCursor;
  328. X   ParseKey[14] = ParseOption;
  329. X   ParseKey[15] = ParseOption;
  330. X   ParseKey[16] = ParseSpace;
  331. X   ParseKey[17] = ParseOption;
  332. X   ParseKey[18] = ParseDefineScreen;
  333. X   ParseKey[19] = ParseOption;
  334. X   ParseKey[20] = ParInclude;
  335. X   ParseKey[21] = ParAssign;
  336. X
  337. X
  338. X/*
  339. X**    SECTION 3:
  340. X**    These functions describe what is to be done to display the
  341. X**    option to the screen.  The option you loaded into OptionInfo.
  342. X**    If set to NULL then the option is not displayed.
  343. X*/
  344. X
  345. X   ShowKey[1] = NULL;
  346. X   ShowKey[2] = ShowOption;
  347. X   ShowKey[3] = ShowOption;
  348. X   ShowKey[4] = NULL;
  349. X   ShowKey[5] = NULL;
  350. X   ShowKey[6] = NULL;
  351. X   ShowKey[7] = NULL;
  352. X   ShowKey[8] = NULL;
  353. X   ShowKey[9] = NULL;
  354. X   ShowKey[10] = NULL;
  355. X   ShowKey[11] = NULL;
  356. X   ShowKey[12] = NULL;
  357. X   ShowKey[13] = NULL;
  358. X   ShowKey[14] = ShowOption;
  359. X   ShowKey[15] = ShowOption;
  360. X   ShowKey[16] = NULL;
  361. X   ShowKey[17] = ShowOption;
  362. X   ShowKey[18] = NULL;
  363. X   ShowKey[19] = ShowOption;
  364. X   ShowKey[20] = NULL;
  365. X   ShowKey[21] = NULL;
  366. X
  367. X
  368. X/*
  369. X**    SECTION 4:
  370. X**    These functions explain what you want done when the user
  371. X**    selects the option on the screen with the corresponding 
  372. X**    keyword.
  373. X**    If set to NULL the keyword becomes unselectable.
  374. X*/
  375. X
  376. X   RunKey[1] = NULL;
  377. X   RunKey[2] = RunMenu;
  378. X   RunKey[3] = RunSystem;
  379. X   RunKey[4] = NULL;
  380. X   RunKey[5] = NULL;
  381. X   RunKey[6] = NULL;
  382. X   RunKey[7] = NULL;
  383. X   RunKey[8] = NULL;
  384. X   RunKey[9] = NULL;
  385. X   RunKey[10] = NULL;
  386. X   RunKey[11] = NULL;
  387. X   RunKey[12] = NULL;
  388. X   RunKey[13] = NULL;
  389. X   RunKey[14] = RunExit;
  390. X   RunKey[15] = RunSetenv;
  391. X   RunKey[16] = NULL;
  392. X   RunKey[17] = RunPopMenu;
  393. X   RunKey[18] = NULL;
  394. X   RunKey[19] = RunGetInput;
  395. X   RunKey[20] = NULL;
  396. X   RunKey[21] = NULL;
  397. X}
  398. SHAR_EOF
  399. chmod 0444 LoadKeys.c || echo "restore of LoadKeys.c fails"
  400. echo "x - extracting parsedrive.c (Text)"
  401. sed 's/^X//' << 'SHAR_EOF' > parsedrive.c &&
  402. Xstatic char Sccsid[] = "@(#)parsedrive.c    1.5   DeltaDate 1/22/90   ExtrDate 1/22/90";
  403. X
  404. X/*  FUNCTION:    parsedriver()
  405. X**        This is the driver routine in parseing the menu
  406. X**        file.  This function calls the appropriate parse
  407. X**        function for that keyword.
  408. X**  ARGS:    keyword        the keyword "AUTHORIZE"
  409. X**        menufile    the unix menu file
  410. X**        menu        menu structure
  411. X**        gnames        holder of goto menu names
  412. X**        gfiles        holder of goto menu names (menu file)
  413. X**        gindex        # of gnames
  414. X**  RETURNS:    0    success
  415. X*/
  416. X
  417. X#include    <curses.h>
  418. X#include    "menu.h"
  419. X
  420. X    int    swin, ewin, longest;
  421. X
  422. Xparsedriver (menufile, KeyWord, ParseKey, menu, gname, gfile, gindex)
  423. X
  424. X    FILE        *menufile;
  425. X    char        KeyWord[][MAXKEYLENGTH];
  426. X    int        (*ParseKey[])();
  427. X    struct MenuInfo    *menu;
  428. X    char        gname[][15], gfile[][15];
  429. X    int        *gindex;
  430. X{
  431. X    char    keyword[80];
  432. X    int    rcde, I, KEYFOUND;
  433. X    int    opnumber = 0;                /* last option number */
  434. X
  435. X
  436. X       /* Set default .WINDOW area */
  437. X       menu->wfcol = 0;
  438. X       menu->wlcol = COLS-1;
  439. X    menu->wfrow = 0;
  440. X       menu->wlrow = LINES-1;
  441. X       menu->titlecount = 0;
  442. X       menu->optioncount = 0;
  443. X       swin = ewin = longest = 0;
  444. X
  445. X       /* loop through each keyword */
  446. X       rcde = fscanf (menufile, "%s", keyword);
  447. X       while (rcde != EOF)
  448. X       {
  449. X        if (strlen (keyword) >= 80-2)
  450. X        {
  451. X                  BEEP;
  452. X                  mvprintw (ErrRow-2, 0, 
  453. X                "Your keyword <%s> is toooo looong.  Max = %d",
  454. X                keyword, 80-2);
  455. X                  shutdown ();
  456. X        }
  457. X        /*
  458. X        **  Check if we found a defined keyword
  459. X        */
  460. X              KEYFOUND = FALSE;
  461. X              for (I = 1; I <= MAXKEYS; I++)
  462. X              {
  463. X            /*
  464. X                 if (strcmp (keyword, KeyWord[I]) == 0)
  465. X            */
  466. X                 if (strmatch (keyword, KeyWord[I]))
  467. X                 {
  468. X                        KEYFOUND = TRUE;
  469. X                    if (ParseKey[I] != NULL)
  470. X                    {
  471. X                               rcde = (*ParseKey[I]) (keyword, 
  472. X                        menufile, menu, KeyWord, 
  473. X                        ParseKey, gname, gfile, gindex, 
  474. X                        &opnumber);
  475. X                    /*
  476. X                    ** The return code from each parse
  477. X                    ** function must be 0 in order to
  478. X                    ** continue.
  479. X                    */
  480. X                           if (rcde != 0)   return (rcde);
  481. X                    }
  482. X                        break;
  483. X                 }
  484. X              }
  485. X              if (!KEYFOUND)
  486. X              {
  487. X                 BEEP;
  488. X                 mvprintw (ErrRow-2, 0, "ERROR: (%s) Key not found.", 
  489. X                    keyword);
  490. X                 shutdown ();
  491. X              }
  492. X              rcde = fscanf (menufile, "%s", keyword);
  493. X       } 
  494. X
  495. X       EndWindow (menu);
  496. X       return (0);
  497. X}
  498. SHAR_EOF
  499. chmod 0444 parsedrive.c || echo "restore of parsedrive.c fails"
  500. echo "x - extracting showdriver.c (Text)"
  501. sed 's/^X//' << 'SHAR_EOF' > showdriver.c &&
  502. Xstatic char Sccsid[] = "@(#)showdriver.c    1.2   DeltaDate 10/16/88   ExtrDate 1/22/90";
  503. X
  504. X/*  FUNCTION:    showdriver()
  505. X**        The driver module to initially display the options
  506. X**        to the screen.
  507. X**  ARGS:    keyword        the keyword found
  508. X**        ShowKey        show functions
  509. X**        menu        menu structure
  510. X**  RETURNS:    none
  511. X*/
  512. X
  513. X#include    <curses.h>
  514. X#include    "menu.h"
  515. X
  516. X
  517. Xshowdriver (KeyWord, ShowKey, menu)
  518. X
  519. X    char        KeyWord[][MAXKEYLENGTH];
  520. X    int        (*ShowKey[])();
  521. X    struct MenuInfo    *menu;
  522. X{
  523. X    int        i, j;
  524. X
  525. X
  526. X
  527. X    /*
  528. X    **    Loop through options and call apropriate function.
  529. X    */
  530. X
  531. X       for (i = 0; i < menu->optioncount; i++)
  532. X              for (j = 1; j <= MAXKEYS; j++)
  533. X                 if (strcmp (menu->option[i]->keyword, KeyWord[j]) == 0)
  534. X             {
  535. X                    if (ShowKey[j] != NULL)   
  536. X                    (*ShowKey[j]) (menu, i);
  537. X                    break;
  538. X             }
  539. X       refresh ();
  540. X}
  541. SHAR_EOF
  542. chmod 0444 showdriver.c || echo "restore of showdriver.c fails"
  543. echo "x - extracting rundriver.c (Text)"
  544. sed 's/^X//' << 'SHAR_EOF' > rundriver.c &&
  545. Xstatic char Sccsid[] = "@(#)rundriver.c    1.11   DeltaDate 1/22/90   ExtrDate 1/22/90";
  546. X
  547. X/*  FUNCTION:    rundriver()
  548. X**        The driver module to run each selectable option.
  549. X**        Runmenu will call the appropriate run function
  550. X**        for that keyword.
  551. X**  ARGS:    keyword        the keyword "AUTHORIZE"
  552. X**        menufile    the unix menu file
  553. X**        menu        menu structure
  554. X**        gnames        holder of goto menu names
  555. X**        gfiles        holder of goto menu names (menu file)
  556. X**        gindex        # of gnames
  557. X**  RETURNS:    QUIT        exit pgm
  558. X**        MAIN        go to main menu
  559. X**        PREVIOUS    go to previous menu
  560. X**        index to submenu
  561. X*/
  562. X
  563. X#include    <curses.h>
  564. X#include    <signal.h>
  565. X#include    "menu.h"
  566. X#include    "terminal.h"
  567. X
  568. X#define        INITMENU    0
  569. X#define        GOTOMENU    1
  570. X
  571. Xextern int    MAILCALL;
  572. X
  573. X
  574. Xrundriver (KeyWord, RunKey, ShowKey, ParseKey, menu, option, gnames, 
  575. X        gfiles, gindex, gotorow, gotocol)
  576. X
  577. X    char        KeyWord[][MAXKEYLENGTH];
  578. X    int        (*RunKey[])(), *option;
  579. X    int        (*ShowKey[])();
  580. X    int        (*ParseKey[])();
  581. X    struct MenuInfo    *menu;
  582. X    char        gnames[][15], gfiles[][15];
  583. X    int        gindex;
  584. X    int        gotorow;
  585. X    int        gotocol;
  586. X{
  587. X    FILE        *fopen(), *fp;
  588. X    char        *findfile();
  589. X    char        select[78], command[200];
  590. X    char        matchstr[60];
  591. X    int        exitkey, index;
  592. X    int        i, j;
  593. X    int        lastopnumber = 0;        /* last option # */
  594. X    int        MATCHED;            /* char match flag */
  595. X    int        ch;
  596. X
  597. X
  598. X    /*
  599. X       **  What is the last option number ?
  600. X       */
  601. X    for (i = menu->optioncount-1; i >= 0; i--)
  602. X        if (menu->option[i]->opnumber != 0)
  603. X        {
  604. X            lastopnumber = menu->option[i]->opnumber;
  605. X            break;
  606. X        }
  607. X
  608. X    if (lastopnumber <= 0)   return (QUIT);        /* no options */
  609. X    select[0] = '\0';
  610. X    matchstr[0] = '\0';
  611. X
  612. X    /*
  613. X       **  Loop through options untill user exits menu or selects
  614. X       **  another menu.
  615. X       */
  616. X    for (;;)
  617. X    {
  618. X#ifndef ALARM
  619. X        if (MAILCALL)
  620. X            checkmail ();
  621. X#endif
  622. X
  623. X        /* highlight current option */
  624. X/*
  625. X#ifdef BSD
  626. X        standout ();
  627. X#else
  628. X        attrset (A_REVERSE);
  629. X#endif
  630. X*/
  631. X
  632. X        for (i = 1; i <= MAXKEYS  &&  KeyWord[i] != NULL; i++)
  633. X            if (strcmp (menu->option[*option-1]->keyword, 
  634. X                    KeyWord[i]) == 0)
  635. X            {
  636. X                if (ShowKey[i] != NULL)
  637. X                {
  638. X                    /* display option */
  639. X                    (*ShowKey[i]) (menu, (*option)-1);
  640. X                    mvaddch (menu->option[(*option)-1]->row,
  641. X                           menu->option[(*option)-1]->col-1,
  642. X                           ' ');
  643. X                    /*
  644. X                    ** turn on reverse video 
  645. X                    ** maintaining current attributes
  646. X                    */
  647. X                    exitkey =  slength(menu->option[(*option)-1]->description) + menu->option[(*option)-1]->col + 5;
  648. X                    for (j = menu->option[(*option)-1]->col-1; j <= exitkey; j++)
  649. X                    {
  650. X                        ch = mvinch (menu->option[(*option)-1]->row, j);
  651. X                        ch |= A_REVERSE;
  652. X                        mvaddch (menu->option[(*option)-1]->row, j, ch);
  653. X                    }
  654. X
  655. X                }
  656. X                break;
  657. X            }
  658. X
  659. X#ifdef BSD
  660. X        standend ();
  661. X#else
  662. X        attrset (A_NORMAL);
  663. X#endif
  664. X
  665. X        if (RunKey[i] != NULL)
  666. X            exitkey = GetOption (menu->row_cursor, menu->col_cursor,
  667. X                         select);
  668. X        else
  669. X            /* so we don't go in a loop */
  670. X            exitkey = (exitkey == KEY_UP || 
  671. X                       exitkey == KeyUp) ? KEY_UP : KEY_DOWN;
  672. X
  673. X        if (exitkey == KeyDown)       exitkey = KEY_DOWN;
  674. X        if (exitkey == KeyUp)        exitkey = KEY_UP;
  675. X        if (exitkey == KeyTab)        exitkey = KEY_TAB;
  676. X        if (exitkey == KeyBTab)        exitkey = KEY_BTAB;
  677. X        if (exitkey == KeyReturn)    exitkey = KEY_RETURN;
  678. X        if (exitkey == KeyMainMenu)    exitkey = KEY_MAINMENU;
  679. X        if (exitkey == KeyPrevMenu)    exitkey = KEY_PREVMENU;
  680. X        if (exitkey == KeyExitMenu)    exitkey = KEY_EXITMENU;
  681. X        if (exitkey == KeyGname)    exitkey = KEY_GNAME;
  682. X
  683. X        /* unhighlight current option */
  684. X        if (ShowKey[i] != NULL)
  685. X        {
  686. X            mvaddch (menu->option[(*option)-1]->row, 
  687. X                menu->option[(*option)-1]->col-1, ' ');
  688. X            strcat (menu->option[(*option)-1]->description, " ");
  689. X            (*ShowKey[i]) (menu, *option-1);
  690. X            menu->option[(*option)-1]->description[strlen(menu->option[(*option)-1]->description)-1] = '\0';
  691. X
  692. X            /*
  693. X            mvaddch (menu->option[(*option)-1]->row, 
  694. X                menu->option[(*option)-1]->col + 
  695. X                strlen (menu->option[(*option)-1]->description)+5, 
  696. X                ' ');
  697. X                */
  698. X        }
  699. X
  700. X
  701. X        switch (exitkey)
  702. X        {
  703. X        case KEY_DOWN:
  704. X        case 'j':
  705. X            *option =*option >= menu->optioncount ? 1 : ++(*option);
  706. X            break;
  707. X
  708. X        case KEY_UP:
  709. X        case 'k':
  710. X            *option =*option <= 1 ? menu->optioncount : --(*option);
  711. X            break;
  712. X
  713. X        case KEY_TAB:
  714. X            /* A tab will hop forward four options at a time. */
  715. X            if (menu->optioncount > 4)
  716. X            {
  717. X                *option += 4;
  718. X                if (*option > menu->optioncount)
  719. X                    *option = 1 + *option - 
  720. X                          menu->optioncount - 1;
  721. X            }
  722. X            else
  723. X                *option = *option >= menu->optioncount ? 1 : 
  724. X                      ++(*option);
  725. X            break;
  726. X
  727. X        case KEY_BTAB:
  728. X            /* A back tab will hop backward 4 options at a time. */
  729. X            if (menu->optioncount > 4)
  730. X            {
  731. X                *option -= 4;
  732. X                if (*option < 0)
  733. X                    *option = menu->optioncount - abs(*option);
  734. X            }
  735. X            else
  736. X                *option = *option <= 1 ? menu->optioncount:--(*option);
  737. X            break;
  738. X
  739. X        /*
  740. X        **    This section is to highlight the selected option 
  741. X        **    before the user presses the return_key to select it.
  742. X        */
  743. X        case '0':
  744. X        case '1':
  745. X        case '2':
  746. X        case '3':
  747. X        case '4':
  748. X        case '5':
  749. X        case '6':
  750. X        case '7':
  751. X        case '8':
  752. X        case '9':
  753. X            sprintf (select, "%s%c", select, exitkey);
  754. X            if (matoi (select) < 1  ||  
  755. X                matoi (select) > lastopnumber)
  756. X            {
  757. X                /* Invalid Option */
  758. X                attrset (A_REVERSE);
  759. X                mvprintw (ErrRow, 0, "To select an option enter the option number and press return.");
  760. X                attrset (A_NORMAL);
  761. X                select[0] = '\0';
  762. X            }
  763. X            else
  764. X            {
  765. X                /* find the element cooresponding to opnumber */
  766. X                for (i = 0; i < menu->optioncount; i++)
  767. X                    if (matoi(select) == menu->option[i]->opnumber)
  768. X                    {
  769. X                        *option = i+1;
  770. X                        break;
  771. X                    }
  772. X            }
  773. X            break;
  774. X
  775. X            case 'A':
  776. X            case 'B':
  777. X            case 'C':
  778. X            case 'D':
  779. X            case 'E':
  780. X            case 'F':
  781. X            case 'G':
  782. X            case 'H':
  783. X            case 'I':
  784. X            case 'J':
  785. X            case 'K':
  786. X            case 'L':
  787. X            case 'M':
  788. X            case 'N':
  789. X            case 'O':
  790. X            case 'P':
  791. X            case 'Q':
  792. X            case 'R':
  793. X            case 'S':
  794. X            case 'T':
  795. X            case 'U':
  796. X            case 'V':
  797. X            case 'W':
  798. X            case 'X':
  799. X            case 'Y':
  800. X            case 'Z':
  801. X            case ' ':
  802. X            /* character matching */
  803. X            sprintf (matchstr, "%s%c", matchstr, exitkey);
  804. X            MATCHED = FALSE;
  805. X            for (i = 0; i < menu->optioncount; i++)
  806. X            {
  807. X                strcpy (command, menu->option[i]->description);
  808. X                upper (command);
  809. X                if (strncmp (command, matchstr, 
  810. X                    strlen(matchstr)) == 0)
  811. X                {
  812. X                    MATCHED = TRUE;
  813. X                    sprintf (select, "%d", 
  814. X                        menu->option[i]->opnumber);
  815. X                    *option = i + 1;
  816. X                    break;
  817. X                }
  818. X            }
  819. X            if (!MATCHED)
  820. X                strcpy (matchstr, "");
  821. X            break;
  822. X
  823. X        case KEY_EXITMENU:
  824. X            /* check if we have a .EXIT option */
  825. X            for (i = 0; i < menu->optioncount; i++)
  826. X                if (strcmp (menu->option[i]->keyword, ".EXIT") == 0)
  827. X                    RunExit (menu, i, KeyWord, ParseKey, ShowKey, 
  828. X                        RunKey, gnames, gfiles, gindex);
  829. X            return (QUIT);
  830. X
  831. X        case KEY_MAINMENU:
  832. X            return (MAINMENU);
  833. X
  834. X        case KEY_PREVMENU:
  835. X            return (PREVIOUSMENU);
  836. X
  837. X        case '!':
  838. X            /*
  839. X        **    Shell Option.
  840. X        **    Prompt user for a command to be executed within a 
  841. X        **      shell (system(1)).
  842. X        */
  843. X            select[0] = '\0';
  844. X            mvaddch (ErrRow, 0, '!');
  845. X            move (ErrRow, 1);
  846. X            echo ();
  847. X            refresh ();
  848. X#ifdef ALARM
  849. X            alarm (0);        /* turn off mail check */
  850. X            signal (SIGALRM, SIG_IGN);
  851. X#endif
  852. X            getstr (select);
  853. X#ifdef ALARM
  854. X            if (MAILCALL)
  855. X                checkmail ();
  856. X#endif
  857. X            noecho ();
  858. X            sprintf (command, "%s;runrealid \"%s\";%s;%s",
  859. X#if BSD || SUN
  860. X                "clear",
  861. X#else
  862. X                "tput clear",
  863. X#endif
  864. X                select,
  865. X                "echo \"\\n[Press return to continue]\\c\"",
  866. X                "read reply");
  867. X            reset_shell_mode ();
  868. X            system (command);
  869. X            reset_prog_mode ();
  870. X            move (ErrRow,0);
  871. X            clrtoeol ();
  872. X            select[0] = '\0';
  873. X            matchstr[0] = '\0';
  874. X            clearok (stdscr, TRUE);
  875. X            break;
  876. X
  877. X        case KEY_HELP:
  878. X        /*
  879. X        **    Show Help Screen Option.
  880. X        **    Search directories for a menu.hlp file.
  881. X        **    If found display to screen.
  882. X        */
  883. X            strcpy (command, findfile ("menu.hlp", ".",
  884. X                getenv("HELPDIR"), getenv("MENUDIR"),
  885. X                ""));
  886. X#ifdef ALARM
  887. X            alarm (0);        /* turn off mail check */
  888. X            signal (SIGALRM, SIG_IGN);
  889. X#endif
  890. X            ShowHelp (command, "menu", ErrRow);
  891. X#ifdef ALARM
  892. X            if (MAILCALL)
  893. X                checkmail ();
  894. X#endif
  895. X            clearok (stdscr, TRUE);
  896. X            select[0] ='\0';
  897. X            matchstr[0] ='\0';
  898. X            break;
  899. X
  900. X        case KEY_GNAME:
  901. X            /*
  902. X            **    Goto Menu option
  903. X            **    Prompt user for the Gname (goto menu name) 
  904. X            **    that the user wants to go to.
  905. X            **    And then return GNAMEOFFSET + gindex to main.  
  906. X            **    The > GNAMEOFFSET indicates a goto menu option.
  907. X            */
  908. X            select[0] = '\0';
  909. X            echo ();
  910. X            mvprintw (ErrRow, 0, "Goto ");
  911. X#ifdef ALARM
  912. X            alarm (0);        /* turn off mail check */
  913. X            signal (SIGALRM, SIG_IGN);
  914. X#endif
  915. X            getstr (select);
  916. X#ifdef ALARM
  917. X            if (MAILCALL)
  918. X                checkmail ();
  919. X#endif
  920. X            noecho ();
  921. X            for (i = 0; i < gindex; i++)
  922. X            {
  923. X                if (strcmp (select, gnames[i]) == 0)
  924. X                    return (GNAMEOFFSET + i);
  925. X            }
  926. X            BEEP;
  927. X            attrset (A_REVERSE);
  928. X            mvprintw (ErrRow, 0, "[%s] not found.", select);
  929. X            attrset (A_NORMAL);
  930. X            select[0] = '\0';
  931. X            matchstr[0] ='\0';
  932. X            break;
  933. X
  934. X        case KEY_RETURN:
  935. X        case KEY_LINEFEED:
  936. X            /*
  937. X            **    We now take an action based upon what is in 
  938. X            **    select - that which the user typed in.
  939. X            */
  940. X            if (select[0] == KeyExitMenu)
  941. X            {
  942. X                /* check if we have a .EXIT option */
  943. X                for (i = 0; i < menu->optioncount; i++)
  944. X                    if (strcmp (menu->option[i]->keyword, 
  945. X                        ".EXIT") == 0)
  946. X                    {
  947. X                        RunExit (menu, i, KeyWord,
  948. X                            ParseKey, ShowKey, RunKey,
  949. X                            gnames, gfiles, gindex);
  950. X                        break;
  951. X                    }
  952. X                return (QUIT);
  953. X            }
  954. X            if (select[0] == KeyMainMenu)    return (MAINMENU);
  955. X            if (select[0] == KeyPrevMenu)    return (PREVIOUSMENU);
  956. X
  957. X            /*
  958. X            **    Goto Menu option
  959. X            **    Prompt user for the Gname (goto menu name) 
  960. X            **    that the user wants to go to.
  961. X            **    And then return GNAMEOFFSET + gindex to main.  
  962. X            **    The > GNAMEOFFSET indicates a goto menu option.
  963. X            */
  964. X            if (select[0] == KeyGname)
  965. X            {
  966. X                select[0] = '\0';
  967. X                echo ();
  968. X                mvprintw (ErrRow, 0, "Goto ");
  969. X#ifdef ALARM
  970. X                alarm (0);    /* turn off mail check */
  971. X                signal (SIGALRM, SIG_IGN);
  972. X#endif
  973. X                getstr (select);
  974. X#ifdef ALARM
  975. X                if (MAILCALL)
  976. X                    checkmail ();
  977. X#endif
  978. X                noecho ();
  979. X                for (i = 0; i < gindex; i++)
  980. X                {
  981. X                    if (strcmp (select, gnames[i]) == 0)
  982. X                        return (GNAMEOFFSET + i);
  983. X                }
  984. X                BEEP;
  985. X                attrset (A_REVERSE);
  986. X                mvprintw (ErrRow, 0, "[%s] not found.", select);
  987. X                attrset (A_NORMAL);
  988. X                select[0] = '\0';
  989. X                matchstr[0] ='\0';
  990. X                break;
  991. X            }
  992. X
  993. X            /*
  994. X            **    Show Help Screen Option.
  995. X            **    Search directories for a menu.hlp file.
  996. X            **    If found display to screen.
  997. X            */
  998. X            if (select[0] == KeyHelp)
  999. X            {
  1000. X                strcpy (command, findfile ("menu.hlp", 
  1001. X                    ".", getenv("HELPDIR"), 
  1002. X                    getenv("MENUDIR"), ""));
  1003. X#ifdef ALARM
  1004. X                alarm (0);        /* turn off mail check */
  1005. X                signal (SIGALRM, SIG_IGN);
  1006. X#endif
  1007. X                ShowHelp (command, "menu", ErrRow);
  1008. X#ifdef ALARM
  1009. X                if (MAILCALL)
  1010. X                    checkmail ();
  1011. X#endif
  1012. X                clearok (stdscr, TRUE);
  1013. X                select[0] ='\0';
  1014. X                matchstr[0] ='\0';
  1015. X                break;
  1016. X            }
  1017. X
  1018. X
  1019. X            /*
  1020. X            **    The user has manually typed in a option to be 
  1021. X            **    executed.  Execute the appropriate option.
  1022. X            */
  1023. X            if (strlen (select) > 0)
  1024. X            {
  1025. X                index = matoi (select);
  1026. X                if (index < 1  ||  index > lastopnumber)
  1027. X                {
  1028. X                    /* Invalid Option */
  1029. X                    attrset (A_REVERSE);
  1030. X                    mvprintw (ErrRow, 0, "To select an option enter the option number and press return.");
  1031. X                    attrset (A_NORMAL);
  1032. X                    select[0] = '\0';
  1033. X                    break;
  1034. X                }
  1035. X                /* find the element cooresponding to opnumber */
  1036. X                for (i = 0; i < menu->optioncount; i++)
  1037. X                    if (index == menu->option[i]->opnumber)
  1038. X                    {
  1039. X                        *option = i+1;
  1040. X                        break;
  1041. X                    }
  1042. X            }
  1043. X
  1044. X            /*
  1045. X            **  Run the option the user selected.
  1046. X            */
  1047. X            for (i = 1; i <= MAXKEYS; i++)
  1048. X                if (strcmp (menu->option[*option-1]->keyword, 
  1049. X                    KeyWord[i]) == 0)
  1050. X                {
  1051. X                    if (RunKey[i] != NULL)
  1052. X                    {
  1053. X#ifdef ALARM
  1054. X                        alarm (0); /* turn off mail */
  1055. X                        signal (SIGALRM, SIG_IGN);
  1056. X#endif
  1057. X                        exitkey = (*RunKey[i]) (menu, *option-1, KeyWord,
  1058. X                            ParseKey, ShowKey, RunKey,
  1059. X                            gnames, gfiles, gindex);
  1060. X                        /* .MENU is a special case */
  1061. X                        if (exitkey == SUBMENU)
  1062. X                            return (*option-1);
  1063. X                        if (exitkey == MAINMENU)
  1064. X                            return (MAINMENU);
  1065. X                        if (exitkey == PREVIOUSMENU)
  1066. X                            return (PREVIOUSMENU);
  1067. X                        if (exitkey == QUIT)
  1068. X                            return (QUIT);
  1069. X                        if (exitkey == REPARSE)
  1070. X                            return (REPARSE);
  1071. X                        if (exitkey >= GNAMEOFFSET  &&  
  1072. X                            exitkey <= GNAMEOFFSET + gindex)
  1073. X                            return (exitkey);
  1074. X#ifdef ALARM
  1075. X                        if (MAILCALL)
  1076. X                            checkmail ();
  1077. X#endif
  1078. X                    }
  1079. X                    break;
  1080. X                }
  1081. X            select[0] = '\0';
  1082. X            matchstr[0] = '\0';
  1083. X            break;
  1084. X
  1085. X        default:
  1086. X            if (exitkey == KeyPopGname  &&  gindex > 0)
  1087. X            {
  1088. X                /*
  1089. X                **   Popup menu for goto names.
  1090. X                */
  1091. X#ifdef ALARM
  1092. X                alarm (0);    /* turn off mail check */
  1093. X                signal (SIGALRM, SIG_IGN);
  1094. X#endif
  1095. X                popmenu (INITMENU, GOTOMENU, gotorow, gotocol, 
  1096. X                    "GOTO MENU", HELPFILE, LINES-2, 
  1097. X                    sizeof(gnames[0]), gnames);
  1098. X
  1099. X                move (ErrRow,0);
  1100. X                clrtoeol ();
  1101. X                BEEP;
  1102. X                mvprintw (ErrRow, 0, "Goto what menu ?");
  1103. X                refresh ();
  1104. X                exitkey = popmenu (GOTOMENU);
  1105. X                touchwin (stdscr);
  1106. X                refresh ();
  1107. X#ifdef ALARM
  1108. X                if (MAILCALL)
  1109. X                    checkmail ();
  1110. X#endif
  1111. X                if (exitkey >= 1  &&  exitkey <= gindex)
  1112. X                    return (GNAMEOFFSET + exitkey-1);
  1113. X            }
  1114. X
  1115. X            move (ErrRow,0);
  1116. X            clrtoeol ();
  1117. X            mvprintw (ErrRow, 0, "Say What.");
  1118. X            select[0] = '\0';
  1119. X            matchstr[0] = '\0';
  1120. X            break;
  1121. X        }
  1122. X    }
  1123. X}
  1124. X
  1125. X
  1126. X
  1127. X/*
  1128. X**  My ascii to integer
  1129. X**  Return -1 if string contains more than digits.
  1130. X*/
  1131. Xmatoi (s)
  1132. X    char    *s;
  1133. X{
  1134. X    int    value;
  1135. X
  1136. X    value = atoi (s);
  1137. X    while (*s)
  1138. X    {
  1139. X        if (*s < '0' || *s > '9')
  1140. X            return (-1);
  1141. X        s++;
  1142. X    }
  1143. X    return (value);
  1144. X}
  1145. SHAR_EOF
  1146. chmod 0444 rundriver.c || echo "restore of rundriver.c fails"
  1147. echo "x - extracting ParseOpton.c (Text)"
  1148. sed 's/^X//' << 'SHAR_EOF' > ParseOpton.c &&
  1149. Xstatic char Sccsid[] = "@(#)ParseOpton.c    1.7   DeltaDate 1/22/90   ExtrDate 1/22/90";
  1150. X
  1151. X/*  FUNCTION:    ParseOption()
  1152. X**        This function parses user selectable options.
  1153. X**  ARGS:    keyword        the keyword found
  1154. X**        menufile    the unix menu file
  1155. X**        menu        menu structure
  1156. X**        gnames        holder of goto menu names
  1157. X**        gfiles        holder of goto menu names (menu file)
  1158. X**        gindex        # of gnames
  1159. X**  RETURNS:    0
  1160. X*/
  1161. X
  1162. X#include    <curses.h>
  1163. X#include    "menu.h"
  1164. X
  1165. Xextern    int    swin, ewin, longest;
  1166. Xextern    int    debug;
  1167. X
  1168. X
  1169. XParseOption (keyword, menufile, menu, KeyWord, ParseKey, gnames, gfiles, 
  1170. Xgindex, opnumber)
  1171. X
  1172. X    char        keyword[];
  1173. X    FILE        *menufile;
  1174. X    struct MenuInfo    *menu;
  1175. X    char        KeyWord[][MAXKEYLENGTH];
  1176. X    int        (*ParseKey[])();
  1177. X    char        gnames[][15], gfiles[][15];
  1178. X    int        *gindex;
  1179. X    int        *opnumber;
  1180. X{
  1181. X    struct OptionInfo    *malloc();
  1182. X    char            *getval();
  1183. X    char        *fgets(), line[MAXLEN+100];
  1184. X    int        i = 0;
  1185. X    int        j;
  1186. X    char        *ws;
  1187. X
  1188. X
  1189. X    if (menu->optioncount >= MAXOPTION)
  1190. X    {
  1191. X        BEEP;
  1192. X        mvprintw (ErrRow-2, 0, "Exceeded maximum allowable options.");
  1193. X        shutdown ();
  1194. X    }
  1195. X    menu->option[menu->optioncount] = malloc (sizeof (struct OptionInfo));
  1196. X    if (menu->option[menu->optioncount] == NULL)
  1197. X    {
  1198. X        BEEP;
  1199. X        mvprintw (ErrRow-2, 0, "Unable to allocate memory for option.");
  1200. X        shutdown ();
  1201. X    }
  1202. X
  1203. X    strcpy (menu->option[menu->optioncount]->keyword, keyword);
  1204. X
  1205. X    /*
  1206. X    **    Read in option command
  1207. X    **    strcat continuation lines
  1208. X    */
  1209. X    fgets (line, BUFSIZE, menufile);
  1210. X    line[strlen(line)-1] = '\0';            /* get rid of \n */
  1211. X    while (line[strlen(line)-1] == '\\')
  1212. X    {
  1213. X        if (strlen(line) >= MAXLEN)
  1214. X        {
  1215. X            BEEP;
  1216. X            mvprintw (ErrRow-2, 0, 
  1217. X                "Option command is too long.  Max = %d",MAXLEN);
  1218. X            shutdown ();
  1219. X        }
  1220. X        line[strlen(line)-1] = '\n';        /* replace \ with \n */
  1221. X        fgets (line+strlen(line), BUFSIZE, menufile);
  1222. X        line[strlen(line)-1] = '\0';        /* get rid of \n */
  1223. X    }
  1224. X    strcpy (menu->option[menu->optioncount]->command, line);
  1225. X    if (debug)
  1226. X    {
  1227. X        fprintf (stderr, "\n[ParseOpton] <%s> command=:%s:",
  1228. X            keyword, menu->option[menu->optioncount]->command);
  1229. X        fflush (stderr);
  1230. X    }
  1231. X
  1232. X    /*
  1233. X    **    Read in option description
  1234. X    */
  1235. X    fgets (line, BUFSIZE+1, menufile);
  1236. X    line[strlen(line)-1] = '\0';
  1237. X    for (j = 0, i = 0; i < strlen (line); j++, i++)
  1238. X        if (line[i] == '$')
  1239. X        {
  1240. X            char    *sptr, *b4ptr;
  1241. X
  1242. X            sptr = b4ptr = line+i;
  1243. X            strcpy (menu->option[menu->optioncount]->description+j, 
  1244. X                getval (&sptr, '$'));
  1245. X            i += (int)(sptr - b4ptr);
  1246. X            j += strlen (menu->option[menu->optioncount]->description+j) - 1;
  1247. X            i--;
  1248. X        }
  1249. X        else
  1250. X        {
  1251. X            menu->option[menu->optioncount]->description[j] = line[i];
  1252. X        }
  1253. X    menu->option[menu->optioncount]->description[j] = '\0';
  1254. X
  1255. X
  1256. X    /*
  1257. X    **    Determine length of longest option
  1258. X    */
  1259. X    if (slength (menu->option[menu->optioncount]->description) > longest)
  1260. X        longest = slength(menu->option[menu->optioncount]->description);
  1261. X
  1262. X    /* set option number 2b displayed */
  1263. X    (*opnumber)++;
  1264. X    menu->option[menu->optioncount]->opnumber = *opnumber;
  1265. X
  1266. X    menu->optioncount++;
  1267. X    ewin++;
  1268. X    return (0);
  1269. X}
  1270. SHAR_EOF
  1271. chmod 0444 ParseOpton.c || echo "restore of ParseOpton.c fails"
  1272. echo "x - extracting ParseBaner.c (Text)"
  1273. sed 's/^X//' << 'SHAR_EOF' > ParseBaner.c &&
  1274. Xstatic char Sccsid[] = "@(#)ParseBaner.c    1.4   DeltaDate 11/13/88   ExtrDate 1/22/90";
  1275. X
  1276. X/*  FUNCTION:    ParseBanner()
  1277. X**        Parses the "BANNER" keyword.
  1278. X**  RETURNS:    0
  1279. X*/
  1280. X
  1281. X#include    <curses.h>
  1282. X#include    "menu.h"
  1283. X
  1284. X
  1285. XParseBanner (keyword, menufile, menu, KeyWord, ParseKey, gnames, gfiles, 
  1286. X    gindex, opnumber)
  1287. X
  1288. X    char        keyword[];
  1289. X    FILE        *menufile;
  1290. X    struct MenuInfo    *menu;
  1291. X    char        KeyWord[][MAXKEYLENGTH];
  1292. X    int        (*ParseKey[])();
  1293. X    char        gnames[][15], gfiles[][15];
  1294. X    int        *gindex;
  1295. X    int        *opnumber;
  1296. X{
  1297. X    static int    onetime = FALSE;        /* show only 1 time */
  1298. X    int    row, col, rstart, rstop, cstart, cstop;
  1299. X    int    ulc=0, llc=0, linecount, increment;
  1300. X    char    flag[5], upper[4][30], lower[4][30];
  1301. X
  1302. X
  1303. X   fscanf (menufile, "%d", &linecount);
  1304. X
  1305. X/*
  1306. X**    Load the input banner text into upper and lower arrays.
  1307. X*/
  1308. X
  1309. X   for (row = 1; row <= linecount; row++)
  1310. X   {
  1311. X      fscanf (menufile, "%s", flag);
  1312. X      if (strncmp (flag, ".U", 2) == 0)
  1313. X      {
  1314. X         fgets (upper[ulc], 80, menufile);
  1315. X         upper[ulc][strlen(upper[ulc])-1] = '\0';
  1316. X         ulc++;
  1317. X      }
  1318. X      else
  1319. X      {
  1320. X         fgets (lower[llc], 80, menufile);
  1321. X         lower[llc][strlen(lower[llc])-1] = '\0';
  1322. X         llc++;
  1323. X      }
  1324. X   }
  1325. X
  1326. X   if (onetime)
  1327. X    return (0);
  1328. X   onetime++;
  1329. X
  1330. X#ifdef BSD
  1331. X   standout ();
  1332. X#else
  1333. X   attrset (A_STANDOUT);
  1334. X#endif
  1335. X   for (rstart = 24/2-1, rstop = 24/2+1, 
  1336. X        cstart = COLS/2-2, cstop = COLS/2+1;
  1337. X        rstart >= 0 && rstop <= 23 && cstart >= 0 && cstop <= COLS-1;
  1338. X        rstart--, rstop++, cstart-=3, cstop+=3)
  1339. X   {
  1340. X      for (row = rstart; row <= rstop; row++)
  1341. X      {
  1342. X         if (row == rstart  ||  row == rstop)
  1343. X         {
  1344. X            for (col = cstart; col <= cstop; col++)
  1345. X               mvaddch (row, col, BORDERCHAR);
  1346. X         }
  1347. X         else
  1348. X         {
  1349. X            mvaddch (row, cstart, BORDERCHAR);
  1350. X            mvaddch (row, cstop, BORDERCHAR);
  1351. X         }
  1352. X      }
  1353. X      refresh ();
  1354. X   }
  1355. X
  1356. X   increment = 2;
  1357. X   for (rstart = rstart+3, rstop=rstop-2, cstart = cstart+1, cstop = cstop-1;
  1358. X        cstart >= 0  &&  cstop <= COLS-1;
  1359. X        rstart++, rstop--, cstart-=increment, cstop+=increment)
  1360. X   {
  1361. X      for (row = 1; row <= 23; row++)
  1362. X      {
  1363. X         if (row < rstart  ||  row > rstop)
  1364. X         {
  1365. X            for (col = cstart; col <= cstart+increment; col++)
  1366. X               mvaddch (row, col, BORDERCHAR);
  1367. X            for (col = cstop-increment; col <= cstop; col++)
  1368. X               mvaddch (row, col, BORDERCHAR);
  1369. X         }
  1370. X         else
  1371. X         {
  1372. X            mvaddch (row, cstart, BORDERCHAR);
  1373. X            mvaddch (row, cstop, BORDERCHAR);
  1374. X         }
  1375. X      }
  1376. X      refresh ();
  1377. X   }
  1378. X
  1379. X#ifdef BSD
  1380. X   standout ();
  1381. X#else
  1382. X   attrset (A_REVERSE);
  1383. X#endif
  1384. X   for (row = 0; ulc > 0; row++, ulc--)
  1385. X      mvprintw (row+4, COLS/2-strlen(upper[row])/2-1, "%s", upper[row]);
  1386. X   for (row = 0; llc > 0; row++, llc--)
  1387. X      mvprintw (row+17, COLS/2-strlen(lower[row])/2-1, "%s", lower[row]);
  1388. X
  1389. X   mvprintw (23, 27, "Press return to continue");
  1390. X   move (23,0);
  1391. X   getch ();
  1392. X   refresh ();
  1393. X#ifdef BSD
  1394. X   standend ();
  1395. X#else
  1396. X   attrset (A_NORMAL);
  1397. X#endif
  1398. X   move (0,0); clrtobot ();
  1399. X   return (0);
  1400. X}
  1401. SHAR_EOF
  1402. chmod 0444 ParseBaner.c || echo "restore of ParseBaner.c fails"
  1403. echo "x - extracting ParseTitle.c (Text)"
  1404. sed 's/^X//' << 'SHAR_EOF' > ParseTitle.c &&
  1405. Xstatic char Sccsid[] = "@(#)ParseTitle.c    1.8   DeltaDate 1/22/90   ExtrDate 1/22/90";
  1406. X
  1407. X/*  FUNCTION:    ParseTitle()
  1408. X**        Parses keyword "TITLE".
  1409. X**  ARGS:    keyword        the keyword "TITLE"
  1410. X**        menufile    the unix menu file
  1411. X**        menu        menu structure
  1412. X**        gnames        holder of goto menu names
  1413. X**        gfiles        holder of goto menu names (menu file)
  1414. X**        gindex        # of gnames
  1415. X**  RETURNS:    0
  1416. X*/
  1417. X
  1418. X#include    <curses.h>
  1419. X#include    "menu.h"
  1420. X
  1421. X
  1422. Xextern int    MAILCALL;
  1423. Xextern int    mailrow;
  1424. Xextern int    mailcol;
  1425. X
  1426. X
  1427. XParseTitle (keyword, menufile, menu, KeyWord, ParseKey, gnames, gfiles, 
  1428. X    gindex, opnumber)
  1429. X
  1430. X    char        keyword[];
  1431. X    FILE        *menufile;
  1432. X    struct MenuInfo    *menu;
  1433. X    char        KeyWord[][MAXKEYLENGTH];
  1434. X    int        (*ParseKey[])();
  1435. X    char        gnames[][15], gfiles[][15];
  1436. X    int        *gindex;
  1437. X    int        *opnumber;
  1438. X{
  1439. X    char    *fgets(), line[201];
  1440. X    char    *getenv();
  1441. X    char    *getval();
  1442. X    char    section[3][201];          /* section[0] = left justified */
  1443. X                          /* section[1] = centered */
  1444. X                          /* section[2] = right justified */
  1445. X    int    i = 0;                  /* index into line */
  1446. X    int    j;                  /* index into section */
  1447. X    int    k, row, col;
  1448. X    char    *ws;
  1449. X    int    mailsection=999;          /* section $MAIL was found */
  1450. X                          /* we set to 999 so sub menus */
  1451. X                          /* that don't have a $MAIL wont */
  1452. X                          /* recalculate mailcol */
  1453. X
  1454. X
  1455. X
  1456. X   fgets (line, 200, menufile);
  1457. X
  1458. X/*
  1459. X**    Get title line
  1460. X*/
  1461. X   fgets (line, 200, menufile);
  1462. X   line[strlen(line)-1] = '\0';
  1463. X   
  1464. X   section[0][0] = section[1][0] = section[2][0] = '\0';
  1465. X
  1466. X/*
  1467. X**    Now we break input line into left, center, and right sections
  1468. X**    Loop through each section.
  1469. X*/
  1470. X
  1471. X   for (k = 0; k <= 2; k++)
  1472. X   {
  1473. X      /* Loop through each character of line until we find next section */
  1474. X      for (j = 0; i < strlen (line)  &&  strncmp (line+i, "...", 3) != 0;
  1475. X          i++, j++)
  1476. X      {
  1477. X         if (strncmp (line+i, "$DATE", 5) == 0)
  1478. X         {
  1479. X            sysdate (section[k]+j, "mm/dd/yy");
  1480. X            j += 7;
  1481. X            i += 4;
  1482. X         }
  1483. X         else
  1484. X            if (strncmp (line+i, "$TIME", 5) == 0)
  1485. X            {
  1486. X               systime (section[k]+j, "HH:MM zz");
  1487. X               j += 7;
  1488. X               i += 4;
  1489. X            }
  1490. X            else
  1491. X               if (strncmp (line+i, "$MAIL", 5) == 0)
  1492. X           {
  1493. X          /*
  1494. X          **  User wants 2b notified when mail arrives.
  1495. X          **  The mailfile is located in enviroment $MAIL
  1496. X          **  if the mailfile exists and size is greater than zero
  1497. X          **  mailfile = getenv("$MAIL")
  1498. X          **  We need to process entire line b4 we find mailcol
  1499. X          */
  1500. X          MAILCALL = TRUE;
  1501. X          strcpy (section[k]+j, "mAiL");    /* unique ? */
  1502. X          mailrow = menu->titlecount;
  1503. X          mailsection = k;
  1504. X                  i += 4;                /* get past $MAIL */
  1505. X                  j += 3;                /* for "MAIL" */
  1506. X           }
  1507. X           else
  1508. X          /*
  1509. X          **  A environment variable
  1510. X          */
  1511. X                  if (line[i] == '$')
  1512. X                 {
  1513. X            char    *sptr, *b4ptr;
  1514. X
  1515. X             sptr = b4ptr = line+i;
  1516. X             strcpy (section[k]+j, getval (&sptr, '$'));
  1517. X             i += (int)(sptr - b4ptr);
  1518. X             j += strlen (section[k]+j) - 1;
  1519. X             i--;
  1520. X              }
  1521. X              else
  1522. X                     section[k][j] = line[i];
  1523. X      }
  1524. X      section[k][j] = '\0';
  1525. X      i += 3;
  1526. X   }
  1527. X
  1528. X   if (menu->titlecount >= MAXTITLE)
  1529. X   {
  1530. X      BEEP;
  1531. X      mvprintw (ErrRow, 0, "Number of Title lines exceed the maximim.");
  1532. X      shutdown ();
  1533. X   }
  1534. X   (menu->titlecount)++;
  1535. X   (menu->wfrow)++;            /* reduce window size to center in */
  1536. X
  1537. X
  1538. X/*
  1539. X**    Now we display the three sections to the screen
  1540. X*/
  1541. X
  1542. X   for (k = 0; k <= 2; k++)
  1543. X   {
  1544. X/*
  1545. X**    First we must find out what column to start displaying on.
  1546. X**    Taking into account the terminal attribute characters.
  1547. X*/
  1548. X      switch (k)
  1549. X      {
  1550. X         case 0:
  1551. X            /* left justified */
  1552. X            row = menu->titlecount - 1;
  1553. X            col = 0;
  1554. X            break;
  1555. X     case 1:
  1556. X            /* center */
  1557. X            for (i = 0, j = 0; section[k][i] != '\0'; i++)
  1558. X               if (section[k][i] == '\\') j++;
  1559. X            col = COLS/2-(strlen(section[k])-j*2)/2;
  1560. X            col -= (((strlen(section[k])-j*2) % 2) == 0) ? 0 : 1;
  1561. X            row = menu->titlecount - 1;
  1562. X            move (menu->titlecount-1, i); 
  1563. X            break;
  1564. X     case 2:
  1565. X            /* right justify */
  1566. X            for (i = 0, j = 0; section[k][i] != '\0'; i++)
  1567. X               if (section[k][i] == '\\') j++;
  1568. X            row = menu->titlecount - 1;
  1569. X            col = COLS-strlen(section[k])+j*2;
  1570. X            break;
  1571. X      }  /* end switch */
  1572. X
  1573. X      if (MAILCALL  &&  mailsection == k)
  1574. X      {
  1575. X         /* find mailcol - remember the attributes */
  1576. X         for (i = 0, j = 0; section[k][i] != '\0' &&
  1577. X              strncmp (section[k]+i, "mAiL", 4) != 0; i++)
  1578. X            if (section[k][i] == '\\') j++;
  1579. X         mailcol = i - j*2 + col;        /* for \R */
  1580. X     memcpy (section[k]+i, "    ", 4);        /* get rid of mAiL */
  1581. X      }
  1582. X
  1583. X      displaytext (row, col, section[k]);
  1584. X   }  /* end for loop */
  1585. SHAR_EOF
  1586. echo "End of part 3"
  1587. echo "File ParseTitle.c is continued in part 4"
  1588. echo "4" > s2_seq_.tmp
  1589. exit 0
  1590.