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

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