home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume21 / pscmenu / part02 < prev    next >
Encoding:
Text File  |  1991-07-25  |  28.8 KB  |  1,149 lines

  1. Newsgroups: comp.sources.misc
  2. From: Ted Wisniewski <ted@oz.plymouth.edu>
  3. Subject:  v21i035:  pscmenu - tty based menu system v2.0, Part02/02
  4. Message-ID: <1991Jul25.013400.27873@sparky.IMD.Sterling.COM>
  5. X-Md4-Signature: 3ee0a0d27a57c2811ea5703f67f1cabd
  6. Date: Thu, 25 Jul 1991 01:34:00 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: Ted Wisniewski <ted@oz.plymouth.edu>
  10. Posting-number: Volume 21, Issue 35
  11. Archive-name: pscmenu/part02
  12. Supersedes: pscmenu: Volume 16, Issue 99
  13. Environment: Ultrix, AIX
  14.  
  15.  
  16. #!/bin/sh
  17. # this is part.02 (part 2 of a multipart archive)
  18. # do not concatenate these parts, unpack them in order with /bin/sh
  19. # file MENU/utils.c continued
  20. #
  21. if test ! -r _shar_seq_.tmp; then
  22.     echo 'Please unpack part 1 first!'
  23.     exit 1
  24. fi
  25. (read Scheck
  26.  if test "$Scheck" != 2; then
  27.     echo Please unpack part "$Scheck" next!
  28.     exit 1
  29.  else
  30.     exit 0
  31.  fi
  32. ) < _shar_seq_.tmp || exit 1
  33. if test ! -f _shar_wnt_.tmp; then
  34.     echo 'x - still skipping MENU/utils.c'
  35. else
  36. echo 'x - continuing file MENU/utils.c'
  37. sed 's/^X//' << 'SHAR_EOF' >> 'MENU/utils.c' &&
  38. X    putp(clear_screen);
  39. X# else  TERM_INFO 
  40. X    tputs(CL,1,outc);
  41. X# endif TERM_INFO 
  42. X}
  43. X
  44. Xstart_rev()
  45. X/*
  46. X    Start the reverse video mode.
  47. X*/
  48. X{
  49. X# ifdef TERM_INFO 
  50. X    putp(enter_standout_mode);
  51. X# else  TERM_INFO 
  52. X    tputs(SO,1,outc);
  53. X# endif TERM_INFO 
  54. X}
  55. X
  56. Xend_rev()
  57. X/*
  58. X    End the reverse video mode.
  59. X*/
  60. X{
  61. X# ifdef TERM_INFO 
  62. X    putp(exit_standout_mode);
  63. X# else  TERM_INFO 
  64. X    tputs(SE,1,outc);
  65. X# endif TERM_INFO 
  66. X}
  67. X
  68. Xprint_str(string)
  69. Xchar *string;
  70. X/*
  71. X    Print an entire string to the screen.
  72. X*/
  73. X{
  74. X    (void) fputs(string,stdout);
  75. X    (void) fflush(stdout);
  76. X}
  77. X
  78. Xhi_lite(string)
  79. Xchar *string;
  80. X/*
  81. X    Hi-lite a string that will be printed.
  82. X*/
  83. X{
  84. X    start_rev();
  85. X    print_str(string);
  86. X    (void) fflush(stdout);
  87. X    end_rev();
  88. X}
  89. X
  90. Xsave_tty() 
  91. X/*
  92. X    Save Terminal characteristics Reset by call to reset_tty().
  93. X*/
  94. X{
  95. X      (void) ioctl(0, TCGETA, &ter_old);
  96. X}
  97. X
  98. Xreset_tty() 
  99. X/*
  100. X    This routine returns the terminal to the same state it
  101. X    had before this program was invoked.
  102. X*/
  103. X{
  104. X  (void) ioctl(0, TCSETA, &ter_old) ;
  105. X}
  106. X
  107. Xcrmode()
  108. X/*
  109. X    Turn on CRmode.
  110. X*/
  111. X{
  112. X    (void) ioctl(0,TCGETA,&ter_des);
  113. X    TERM_STRUCT |= CRMOD;
  114. X    (void) ioctl(0,TCSETA,&ter_des);
  115. X}
  116. X
  117. Xno_crmode()
  118. X/*
  119. X    Turn off CRmode.
  120. X*/
  121. X{
  122. X    (void) ioctl(0,TCGETA,&ter_des);
  123. X    TERM_STRUCT &= ~CRMOD;
  124. X    (void) ioctl(0,TCSETA,&ter_des);
  125. X}
  126. X
  127. Xecho()
  128. X/*
  129. X    Turn echo back on.
  130. X*/
  131. X{
  132. X    (void) ioctl(0,TCGETA,&ter_des);
  133. X    TERM_STRUCT |= ECHO;
  134. X    (void) ioctl(0,TCSETA,&ter_des);
  135. X}
  136. X
  137. Xno_echo()
  138. X/*
  139. X    Turn off echo.
  140. X*/
  141. X{
  142. X    (void) ioctl(0,TCGETA,&ter_des);
  143. X    TERM_STRUCT &= ~ECHO;
  144. X    (void) ioctl(0,TCSETA,&ter_des);
  145. X}
  146. X
  147. Xno_cbreak()
  148. X/*
  149. X    Take the terminal out of cbreak mode.
  150. X*/
  151. X{
  152. X    (void) ioctl(0,TCGETA,&ter_des);
  153. X    TERM_STRUCT |= CBREAK;
  154. X    (void) ioctl(0,TCSETA,&ter_des);
  155. X}
  156. X
  157. Xcbreak()
  158. X/*
  159. X    Place the Terminal in Cbreak mode.
  160. X*/
  161. X{
  162. X    (void) ioctl(0,TCGETA,&ter_des);
  163. X    TERM_STRUCT &= ~CBREAK;
  164. X    (void) ioctl(0,TCSETA,&ter_des);
  165. X}
  166. X    
  167. Xrm_lf(array)
  168. Xchar *array;
  169. X/*    
  170. X    Remove Trailing line feed from a line.
  171. X*/
  172. X{
  173. X    if(array[strlen(array)-1] == '\n')
  174. X      array[strlen(array)-1] = NULL;
  175. X}
  176. X
  177. Xread_str(string,max_length)
  178. Xchar *string;
  179. Xint max_length;
  180. X{
  181. X    char *str;
  182. X    int length = 0;
  183. X
  184. X    str = string;
  185. X    while((*str =my_getchar()) != LF && *str != CR && length <= max_length){
  186. X       if(*str ==  DEL  || *str == BS)
  187. X          if(*str != *string){
  188. X         outc(DEL);
  189. X         outc(SPACE);
  190. X         outc(DEL);
  191. X         *str--;
  192. X         length--;
  193. X          }else
  194. X         continue;
  195. X       else{
  196. X          if(length == max_length)
  197. X            outc(0x07);
  198. X          else{
  199. X            outc(*str);
  200. X            *str++;
  201. X            length++;
  202. X          }
  203. X       }
  204. X    }
  205. X    *str = NULL;
  206. X}
  207. X
  208. Xclear_array(array)
  209. Xchar *array;
  210. X{
  211. X    for(;*array != NULL;*array++)
  212. X        *array = NULL;
  213. X}
  214. X
  215. Xint get_input()
  216. X{
  217. X    char c, buffer[80];
  218. X    int ct = 0, len;
  219. X
  220. X    if((len = strlen(KU)-1) < 2)
  221. X      len = 1;
  222. X    while((c = my_getchar()) && (ct < len)){
  223. X       if((c == 0x1b) || (ct > 0)){
  224. X         buffer[ct] = c;
  225. X         ct++; 
  226. X       }else
  227. X         return(c);
  228. X    }
  229. X    buffer[ct] = c;
  230. X    buffer[ct+1] = NULL;
  231. X    if((strcmp(KU,buffer)) == 0)
  232. X      return(UP);
  233. X    else
  234. X      if((strcmp(KD,buffer)) == 0)
  235. X        return(DOWN);
  236. X      else
  237. X        if((strcmp(KL,buffer)) == 0)
  238. X          return(LEFT);
  239. X        else
  240. X          if((strcmp(KR,buffer)) == 0)
  241. X            return(RIGHT);
  242. X          else
  243. X            return(NULL);
  244. X}
  245. X
  246. X# ifdef SYSTEM_FIVE
  247. Xint my_getchar()
  248. X{
  249. X    struct termio tdes,tsave;
  250. X    char n;
  251. X    
  252. X    ioctl(0,TCGETA,&tdes);
  253. X    tsave = tdes;
  254. X
  255. X    tdes.c_cc[VMIN] = 1;
  256. X    tdes.c_cc[VTIME] = 0;
  257. X    ioctl(0,TCSETA,&tdes);
  258. X
  259. X    read(0,&n,1);
  260. X
  261. X    ioctl(0,TCSETA,&tsave);
  262. X    return(n);
  263. X}
  264. X
  265. X# else
  266. X
  267. Xint my_getchar()
  268. X{
  269. X    return(getchar());
  270. X}
  271. X# endif SYSTEM_FIVE
  272. SHAR_EOF
  273. echo 'File MENU/utils.c is complete' &&
  274. chmod 0600 MENU/utils.c ||
  275. echo 'restore of MENU/utils.c failed'
  276. Wc_c="`wc -c < 'MENU/utils.c'`"
  277. test 5282 -eq "$Wc_c" ||
  278.     echo 'MENU/utils.c: original size 5282, current size' "$Wc_c"
  279. rm -f _shar_wnt_.tmp
  280. fi
  281. # ============= MENU/menu.c ==============
  282. if test -f 'MENU/menu.c' -a X"$1" != X"-c"; then
  283.     echo 'x - skipping MENU/menu.c (File already exists)'
  284.     rm -f _shar_wnt_.tmp
  285. else
  286. > _shar_wnt_.tmp
  287. echo 'x - extracting MENU/menu.c (Text)'
  288. sed 's/^X//' << 'SHAR_EOF' > 'MENU/menu.c' &&
  289. X# include <stdio.h>
  290. X# include <sys/file.h>
  291. X# include <sys/ioctl.h>
  292. X# include "menu.h"
  293. X
  294. X/*    PSC MENU COPYRIGHT NOTICE
  295. X
  296. X    Part of PSCMenu
  297. X
  298. X    This software is to be considered to be public domain, it
  299. Xmay be copied, modified and parts of it may be used in other programs
  300. Xas long as this copyright notice remains intact.
  301. X
  302. X    Copyright()   PSC - Plymouth State College
  303. X    Written by:   Ted Wisniewski 12-9-1990
  304. X*/
  305. X
  306. X/*****************************************************************************
  307. X    Execute a process and have the output read into a buffer and then
  308. X    print it to the screen.
  309. X *****************************************************************************/
  310. X
  311. Xexec_pipe(comline)
  312. Xchar *comline;
  313. X{
  314. X    char inbuf[LINESZ], list[FOURK][80];
  315. X    FILE *f, *popen();
  316. X    int num = 1, length = 0;
  317. X
  318. X    move_csr(5,2);
  319. X    print_str("Working...");
  320. X    if((f = popen(comline,"r")) == NULL){
  321. X       Strcpy(list[0],"Command not found");
  322. X    }else
  323. X       while(fgets(inbuf,LINESZ,f) != NULL){
  324. X          rm_lf(inbuf);
  325. X          if(strlen(inbuf) > 70)
  326. X            chop_str(inbuf,70);
  327. X          else
  328. X            pad_str(inbuf);
  329. X          Strcpy(list[num],inbuf);
  330. X          if(strlen(inbuf) > length)
  331. X        length = strlen(inbuf);
  332. X          num++;
  333. X       }
  334. X       clr_area(2,5,1,15);
  335. X       print_output(list,num,length);
  336. X    Pclose(f);
  337. X}
  338. X
  339. X/**************************************************************************
  340. X Print output to the Menu Window,  when done clear the Window.
  341. X **************************************************************************/
  342. X
  343. Xprint_output(output,number,length)
  344. Xchar output[FOURK][80];
  345. Xint number, length;
  346. X{
  347. X    int i, k = 4, left;
  348. X
  349. X    left = number;
  350. X    for(i=1;i<number;++i){
  351. X       move_csr(5,k);
  352. X       print_str(output[i]);
  353. X       k++;
  354. X       if(i%15 == 14){
  355. X         left -= 15;
  356. X         if(cont_it() == 1){
  357. X            clr_area(5,4,(k-4),length+2);
  358. X            return;
  359. X         }
  360. X/*         clr_area(5,4,(k-4),length+2);*/
  361. X         move_csr(5,4);
  362. X         k = 4;
  363. X       }
  364. X       Fflush(stdout);
  365. X    }
  366. X    if(left < 15)
  367. X      clr_area(5+left,5,(15-left),length+2);
  368. X    continue_it(CONT_LINE);
  369. X    clr_area(5,4,(k-4),length+2);
  370. X}
  371. X
  372. X/**************************************************************************
  373. X Request input from the user as to whether he/she wishes to continue.
  374. X This routine gives the option to stop seeing output.
  375. X **************************************************************************/
  376. X
  377. Xcont_it()
  378. X{
  379. X    char c;
  380. X
  381. X    move_csr(20,CONT_LINE);
  382. X    hi_lite("Press space to continue or \'q\' to stop.");
  383. X    c = my_getchar();
  384. X    while(c != 'q' && c != ' ')
  385. X       c = my_getchar();
  386. X    erase_line(20,CONT_LINE,45);
  387. X    if(c == 'q')
  388. X       return 1;
  389. X    else
  390. X       return 0;
  391. X}
  392. X
  393. X/**************************************************************************
  394. X Request input from the user as to whether he/she wishes to continue.
  395. X **************************************************************************/
  396. X
  397. Xcontinue_it(line_num)
  398. Xint line_num;
  399. X{
  400. X    move_csr(27,line_num);
  401. X    hi_lite("Press a space to Continue.");
  402. X    while(my_getchar() != SPACE);
  403. X    erase_line(27,line_num,45);
  404. X}
  405. X
  406. X/*****************************************************************************
  407. X Print The current working directory at the bottom of the screen.
  408. X *****************************************************************************/
  409. X
  410. Xprt_curdir()
  411. X{
  412. X    char direct[BUF_SIZ], *getwd();
  413. X    int i;
  414. X
  415. X    move_csr(0,STATUS_LINE);
  416. X    hi_lite("Directory:");
  417. X    Getwd(direct);
  418. X    if(strlen(direct) < 40)
  419. X       for(i=strlen(direct);i<=40;i++)
  420. X          Strcat(direct," ");
  421. X    else
  422. X       for(i=40;i<=80;i++)
  423. X             direct[i] = NULL;
  424. X    move_csr(12,STATUS_LINE);
  425. X    hi_lite(direct);
  426. X}
  427. X
  428. X/*****************************************************************************
  429. X Clear an Area in the Menu Window.
  430. X *****************************************************************************/
  431. X
  432. Xclr_area(st_y,st_x,n_line,length)
  433. Xint st_y,st_x,n_line,length;
  434. X{
  435. X    int i;
  436. X
  437. X    for(i=0;i<=length;i++)
  438. X      line[i] = ' ';
  439. X    line[i+1] = NULL;
  440. X    for(i=(st_y-1);i<(n_line+st_y);i++){
  441. X       move_csr(st_x,i);
  442. X       print_str(line);
  443. X    }
  444. X}
  445. X
  446. X/*****************************************************************************
  447. X Erase a line within the Menu Window.
  448. X *****************************************************************************/
  449. X
  450. Xerase_line(x,y,length)
  451. Xint x,y,length;
  452. X{
  453. X    int i;
  454. X
  455. X    for(i=0;i<=length;i++)
  456. X        line[i] = ' ';
  457. X    line[i+1] = NULL;
  458. X    move_csr(x,y);
  459. X    print_str(line);
  460. X}
  461. X
  462. X/*****************************************************************************
  463. X Execute a shell command.  Output does not come to back to the window.
  464. X *****************************************************************************/
  465. X
  466. Xexec_cshell(command,flag)
  467. Xchar *command;
  468. Xint flag;
  469. X{
  470. X    clr_scr();
  471. X    Fflush(stdout);
  472. X    reset_tty();
  473. X    if(fork() == 0)
  474. X      Execl("/bin/csh","csh","-c",command,0);
  475. X    else
  476. X      Wait((int *)0);
  477. X    setup_tty();
  478. X    if(flag)
  479. X      continue_it(LAST_LINE);
  480. X    setup_screen();
  481. X}
  482. X
  483. X/*****************************************************************************
  484. X Draw borders and print Header on the screen.
  485. X *****************************************************************************/
  486. X
  487. Xsetup_screen()
  488. X{
  489. X    clr_scr();            /* Clear screen routine             */
  490. X    box_screen();
  491. X    move_csr((CENTER-strlen(HEADER)/2),FIRST_LINE);
  492. X    hi_lite(HEADER);
  493. X    move_csr(68,STATUS_LINE);
  494. X    hi_lite(CMD_LIN);
  495. X    prt_curdir();
  496. X}
  497. X
  498. X/*****************************************************************************
  499. X Make sure The user does not try to run menu in the background.
  500. X *****************************************************************************/
  501. X
  502. Xcheck_run()
  503. X{
  504. X        int     tpgrp;  /* terminal control process group */
  505. X
  506. X        if (ioctl(2, TIOCGPGRP, &tpgrp) != 0) { /* hope stderr open */
  507. X                exit(1);
  508. X        }
  509. X    if(getpgrp(0) != tpgrp){
  510. X      Fprintf(stderr,"\nSorry, Cannot run in background.\n");
  511. X      exit(0);
  512. X    }
  513. X}
  514. X
  515. X/*****************************************************************************
  516. X Make sure Output goes to the screen and terminal is capable of running
  517. X menu.
  518. X *****************************************************************************/
  519. X
  520. Xinitialize()
  521. X{
  522. X    int term;
  523. X
  524. X    if(!isatty(1)){
  525. X       Fprintf(stderr,"Sorry, Cannot output to the screen (exiting).\n");
  526. X       exit(4);
  527. X    }
  528. X    if((term = get_term()) == -1){
  529. X       Fprintf(stderr,"Sorry, Bad termcap entry (exiting).\n");
  530. X       exit(4);
  531. X    }
  532. X    save_tty();            /* Save tty states             */
  533. X    setup_tty();
  534. X}
  535. X
  536. X/*****************************************************************************
  537. X Prepare for Quit Menu, and exit (restore original settings).
  538. X *****************************************************************************/
  539. X
  540. Xquit()
  541. X/*
  542. X    Reset the terminal to the same as before it was run.
  543. X*/
  544. X{
  545. X    clr_scr();            /* Clear screen routine             */
  546. X    move_csr(0,LAST_LINE);
  547. X    reset_tty();
  548. X    exit(0);
  549. X}
  550. X
  551. X/*****************************************************************************
  552. X Set proper terminal settings for use while within menu.
  553. X *****************************************************************************/
  554. X
  555. Xsetup_tty()
  556. X{
  557. X    no_echo();
  558. X    cbreak();
  559. X    crmode();
  560. X}
  561. X
  562. Xint main(argc,argv)
  563. Xint argc;
  564. Xchar *argv[];
  565. X{
  566. X    int *num;
  567. X
  568. X        /************************************************************
  569. X        If More than two arguments are supplied print the
  570. X        Usage statement.
  571. X         ************************************************************/
  572. X    if(argc > 2){
  573. X      Fprintf(stderr,"Usage: menu\n");
  574. X      Fprintf(stderr,"Usage: menu [menu_directory]\n");
  575. X      exit(0);
  576. X    }else{
  577. X        /************************************************************
  578. X        If there are no additional arguments Use the default
  579. X        Menu directory.
  580. X         ************************************************************/
  581. X      if(argc == 1)
  582. X         Strcpy(menu_dir,MENU_DIR);
  583. X      else
  584. X        /************************************************************
  585. X        See if the directory name ends in a '/' if not add
  586. X        one.
  587. X         ************************************************************/
  588. X        if(argc == 2){
  589. X           Strcpy(menu_dir,argv[1]);
  590. X           check_dirname(menu_dir);
  591. X           if(menu_dir[strlen(menu_dir)-1] != '/')
  592. X              Strcat(menu_dir,"/");
  593. X        }
  594. X        Sprintf(buffer,"%s%s",menu_dir,MAIN_MENU);
  595. X        /************************************************************
  596. X            Check to make sure the menu directory is Read-able and
  597. X        executeable
  598. X         ************************************************************/
  599. X        if(access(menu_dir,R_OK|X_OK)){
  600. X           Fprintf(stderr,"Directory :%s: is not accessable ",menu_dir);
  601. X           Fprintf(stderr,"or does not exist.\n");
  602. X           exit(1);
  603. X        }
  604. X        /************************************************************
  605. X            Check to see if the main menu file exists, if it does 
  606. X            not exist, exit the program.
  607. X         ************************************************************/
  608. X        if(access(buffer,F_OK)){
  609. X           Fprintf(stderr,"Menu files do not exist in %s.\n",menu_dir);
  610. X           (void) exit(2);
  611. X        }
  612. X    }
  613. X# ifndef SYSTEM_FIVE
  614. X    (void) setpgrp(getpid(),0);
  615. X# else
  616. X    (void) setpgrp();
  617. X# endif SYSTEM_FIVE
  618. X    check_run();
  619. X    setbuf(stdin,NULL);    /* Make stdin unbuffered */
  620. X    initialize();        
  621. X    setup_screen();
  622. X    setup_sigs();
  623. X    main_menu->key = '@';            /* We start in main menu */
  624. X    (void) read_menu(main_menu,MAIN_MENU,&num);
  625. X    disp_menu(main_menu,num);
  626. X    Fflush(stdin);
  627. X    do_menu(main_menu,num);
  628. X    return(0);
  629. X}
  630. SHAR_EOF
  631. chmod 0600 MENU/menu.c ||
  632. echo 'restore of MENU/menu.c failed'
  633. Wc_c="`wc -c < 'MENU/menu.c'`"
  634. test 9066 -eq "$Wc_c" ||
  635.     echo 'MENU/menu.c: original size 9066, current size' "$Wc_c"
  636. rm -f _shar_wnt_.tmp
  637. fi
  638. # ============= MENU/signals.c ==============
  639. if test -f 'MENU/signals.c' -a X"$1" != X"-c"; then
  640.     echo 'x - skipping MENU/signals.c (File already exists)'
  641.     rm -f _shar_wnt_.tmp
  642. else
  643. > _shar_wnt_.tmp
  644. echo 'x - extracting MENU/signals.c (Text)'
  645. sed 's/^X//' << 'SHAR_EOF' > 'MENU/signals.c' &&
  646. X# include <signal.h>
  647. X# include "menu.h"
  648. X
  649. X/*    PSC MENU COPYRIGHT NOTICE
  650. X
  651. X    Part of PSCMenu
  652. X
  653. X    This software is to be considered to be public domain, it
  654. Xmay be copied, modified and parts of it may be used in other programs
  655. Xas long as this copyright notice remains intact.
  656. X
  657. X    Copyright()   PSC - Plymouth State College
  658. X    Written by:   Ted Wisniewski 12-9-1990
  659. X*/
  660. X
  661. X/*
  662. X *    void setup_sigs():
  663. X *
  664. X *    Parameters:    None.
  665. X *
  666. X *    Description:    Set up signal handling.
  667. X *
  668. X *    Returns:    None.
  669. X *
  670. X *    Last Modify:    05-8-91 (TW)
  671. X *
  672. X */
  673. X
  674. Xvoid setup_sigs()
  675. X{
  676. X    (void) signal(SIGHUP,catch);
  677. X    (void) signal(SIGSEGV,catch);
  678. X    (void) signal(SIGBUS,catch);
  679. X    (void) signal(SIGINT,SIG_IGN);
  680. X    (void) signal(SIGTSTP,SIG_IGN);
  681. X    (void) signal(SIGQUIT,SIG_IGN);
  682. X}
  683. X
  684. X/*
  685. X *    catch():
  686. X *
  687. X *    Parameters:    signo - The signal ID #.
  688. X *
  689. X *    Description:    Routine to catch specific signals.
  690. X *
  691. X *    Returns:    None.
  692. X *
  693. X *    Last Modify:    05-8-91 (TW)
  694. X *
  695. X */
  696. X
  697. Xcatch(signo)
  698. Xint signo;
  699. X{
  700. X    switch (signo){
  701. X       case SIGHUP:
  702. X        exit(1);
  703. X       break;
  704. X       case SIGSEGV:
  705. X       case SIGBUS:
  706. X        clr_scr();  
  707. X            reset_tty();
  708. X            end_rev();
  709. X        perror(" ");
  710. X        exit(1);
  711. X       break;
  712. X    }
  713. X}
  714. X
  715. X/*
  716. X *     log_out():
  717. X *
  718. X *    Parameters:    None.
  719. X *
  720. X *    Description:    Kill The process group of the parent to the menu,
  721. X *            hopefully this will be the users login shell.
  722. X *
  723. X *    Returns:    None.
  724. X *
  725. X *    Last Modify:    04-27-91 (TW)
  726. X *
  727. X */
  728. X
  729. Xvoid log_out()
  730. X{
  731. X    killpg(getppid(),SIGHUP);    /* Kill Parent Process        */
  732. X    killpg(getpid(),SIGHUP);    /* Suicide: Kill self.        */
  733. X}
  734. SHAR_EOF
  735. chmod 0600 MENU/signals.c ||
  736. echo 'restore of MENU/signals.c failed'
  737. Wc_c="`wc -c < 'MENU/signals.c'`"
  738. test 1463 -eq "$Wc_c" ||
  739.     echo 'MENU/signals.c: original size 1463, current size' "$Wc_c"
  740. rm -f _shar_wnt_.tmp
  741. fi
  742. # ============= MENU/menu.h ==============
  743. if test -f 'MENU/menu.h' -a X"$1" != X"-c"; then
  744.     echo 'x - skipping MENU/menu.h (File already exists)'
  745.     rm -f _shar_wnt_.tmp
  746. else
  747. > _shar_wnt_.tmp
  748. echo 'x - extracting MENU/menu.h (Text)'
  749. sed 's/^X//' << 'SHAR_EOF' > 'MENU/menu.h' &&
  750. X/*    PSC MENU COPYRIGHT NOTICE
  751. X
  752. X    Part of PSCMenu
  753. X
  754. X    This software is to be considered to be public domain, it
  755. Xmay be copied, modified and parts of it may be used in other programs
  756. Xas long as this copyright notice remains intact.
  757. X
  758. X    Copyright()   PSC - Plymouth State College
  759. X    Written by:   Ted Wisniewski 12-9-1990
  760. X*/
  761. X
  762. X# define     FOURK        4096
  763. X# define     ONEK        1024
  764. X# define    BUF_SIZ        256
  765. X# define    LINESZ        90
  766. X# define     FIRST_LINE    0
  767. X# define    STATUS_LINE    22
  768. X# define    NUMCOL        22
  769. X# define    DESCOL        25
  770. X# define     LAST_LINE    23
  771. X# define     CONT_LINE    21
  772. X# define     N_ENTRIES    9
  773. X# define     RE_DRAW        ('r' & 037)
  774. X# define     MAIN_MENU    "main.menu"
  775. X# define    MENU_DIR    "/usr/local/lib/menus/"
  776. X# define    CR        0x0d
  777. X# define    LF        0x0a
  778. X# define    SPACE        0x20
  779. X# define    TRUE        1
  780. X# define    FALSE        0
  781. X# define     CENTER        40
  782. X# define     HEADER        "Plymouth State College Menu System"
  783. X# define    CMD_LIN        "h)elp q)uit"
  784. X# define    CONTINUE    1
  785. X# define    NO_CONTINUE    0
  786. X
  787. X# define     Sprintf        (void) sprintf
  788. X# define    Strcpy        (void) strcpy
  789. X# define    Strcat        (void) strcat
  790. X# define    Fprintf        (void) fprintf
  791. X# define    Fflush        (void) fflush
  792. X# define    Fputc        (void) fputc
  793. X# define    Fputs        (void) fputs
  794. X# define    Fgets        (void) fgets
  795. X# define    Pclose        (void) pclose
  796. X# define    Getwd        (void) getwd
  797. X# define    Wait        (void) wait
  798. X# define    Execl        (void) execl
  799. X
  800. Xint catch();
  801. X
  802. Xchar *strcat(), *strcpy();
  803. X
  804. Xtypedef struct
  805. X{
  806. X    char key;        /* Key character for command types.  */
  807. X    char desc[LINESZ];    /* Description of command.         */
  808. X    char **script;        /* Strings to make a shell script.   */
  809. X    char cmd[LINESZ];      /* The Command.                      */
  810. X        char help_fil[LINESZ];  /* Name of the Help file for option. */
  811. X}menu_ent;
  812. X
  813. Xmenu_ent main_menu[N_ENTRIES];
  814. X
  815. Xtypedef int FLAG;
  816. X
  817. XFLAG m_flag;
  818. X
  819. X
  820. Xchar line[BUF_SIZ], buffer[BUF_SIZ], string[BUF_SIZ];
  821. Xchar menu_dir[BUF_SIZ];
  822. X
  823. Xint get_term();
  824. SHAR_EOF
  825. chmod 0600 MENU/menu.h ||
  826. echo 'restore of MENU/menu.h failed'
  827. Wc_c="`wc -c < 'MENU/menu.h'`"
  828. test 1799 -eq "$Wc_c" ||
  829.     echo 'MENU/menu.h: original size 1799, current size' "$Wc_c"
  830. rm -f _shar_wnt_.tmp
  831. fi
  832. # ============= MENU/utils.h ==============
  833. if test -f 'MENU/utils.h' -a X"$1" != X"-c"; then
  834.     echo 'x - skipping MENU/utils.h (File already exists)'
  835.     rm -f _shar_wnt_.tmp
  836. else
  837. > _shar_wnt_.tmp
  838. echo 'x - extracting MENU/utils.h (Text)'
  839. sed 's/^X//' << 'SHAR_EOF' > 'MENU/utils.h' &&
  840. X# ifdef TERM_INFO
  841. X#    include <curses.h>
  842. X#    include <term.h>
  843. X# endif TERM_INFO 
  844. X# include <stdio.h>
  845. X# ifdef HAS_TERMIO
  846. X#    include <termio.h>
  847. X# else
  848. X#    include <sgtty.h>
  849. X# endif
  850. X
  851. X/*    PSC MENU COPYRIGHT NOTICE
  852. X
  853. X    Part of PSCMenu
  854. X
  855. X    This software is to be considered to be public domain, it
  856. Xmay be copied, modified and parts of it may be used in other programs
  857. Xas long as this copyright notice remains intact.
  858. X
  859. X    Copyright()   PSC - Plymouth State College
  860. X    Written by:   Ted Wisniewski 12-9-1990
  861. X*/
  862. X
  863. X# define         MAXL        80
  864. X# define          THIS_TTY    0
  865. X# define        DEL        0x08
  866. X# define        BS        0x7f
  867. X# define        SPACE        0x20
  868. X# define        LF        0x0a
  869. X# define         CR        0x0d
  870. X
  871. X# define        UP        252
  872. X# define        DOWN        253
  873. X# define        LEFT        254
  874. X# define        RIGHT        255
  875. X
  876. Xchar *SO, *SE, *CE, *CM, *CL;
  877. Xchar *KU, *KD, *KR, *KL;
  878. X
  879. Xchar *getenv(), *tgetstr(), *tgoto();
  880. X
  881. Xint outc();
  882. X
  883. X# ifdef HAS_TERMIO
  884. X     struct termio ter_old, ter_des;
  885. X# define TERM_STRUCT    ter_des.c_lflag
  886. X# else
  887. X     struct sgttyb ter_old, ter_des;
  888. X# define TERM_STRUCT    ter_des.sg_flags
  889. X# endif HAS_TERMIO
  890. SHAR_EOF
  891. chmod 0600 MENU/utils.h ||
  892. echo 'restore of MENU/utils.h failed'
  893. Wc_c="`wc -c < 'MENU/utils.h'`"
  894. test 1028 -eq "$Wc_c" ||
  895.     echo 'MENU/utils.h: original size 1028, current size' "$Wc_c"
  896. rm -f _shar_wnt_.tmp
  897. fi
  898. # ============= MENU/menu.man ==============
  899. if test -f 'MENU/menu.man' -a X"$1" != X"-c"; then
  900.     echo 'x - skipping MENU/menu.man (File already exists)'
  901.     rm -f _shar_wnt_.tmp
  902. else
  903. > _shar_wnt_.tmp
  904. echo 'x - extracting MENU/menu.man (Text)'
  905. sed 's/^X//' << 'SHAR_EOF' > 'MENU/menu.man' &&
  906. X.TH MENU 1 "June 1990" "Newwords+ Manual"
  907. X\.@(#)menu.1 1.1 90/06/31 SMI;
  908. X.SH NAME
  909. Xmenu \- Runs the PSC Menu System.
  910. X.SH SYNOPSIS
  911. Xmenu [ menu_directory ]
  912. X.SH DESCRIPTION
  913. X
  914. XMenu is a menu system that is capable of doing any unix command 
  915. Xfrom the "menu".  The individual menus are read from menu files that
  916. Xare located in a "menu" directory.  The menu files are simple text files
  917. Xthat may be edited with any editor.  The "menu" is flexable, the only
  918. Xcommand line argument that is accepted is the name of a directory in which
  919. Xthe menu files are located.  The menu will accept the "~" in the directory
  920. Xargument to specify a users home directory.  A default directory is 
  921. Xspecified in the menu header file.
  922. X.SH SELECTING ITEMS & USING BUILTIN COMMANDS
  923. X
  924. XAn item is selected from the menu simply by entering the corre-
  925. Xsponding number that is displayed for the item.  It is important to know 
  926. Xthat you should not enter the selection and then press return.  The return
  927. Xkey has a special function.  The return key tells the menu to back up one
  928. Xmenu unless you are in the main menu, where it has no effect.  The PSC
  929. Xmenu system contains built in commands that allow you to: change directory,
  930. Xexecute a shell command, do directory listings, quit menu, help and re-draw
  931. Xthe screen. See the section on the "Built in Menu" for more details.
  932. X
  933. X.SH BUILT IN MENU
  934. X
  935. XThe Built in menu is a pop-up window that displays a list of builtin commands
  936. Xaccessable.  This menu is accessed by entering the letter 'h' from any
  937. Xmenu accept the builtin menu.  Options in this menu are: c, d, h, l, m, p,
  938. Xq, x, ?, L, P and <ctrl-R>.  These characters cause 
  939. Xthe following affects:
  940. X.nf
  941. X
  942. X    'c' - Change to a new working directory.
  943. X
  944. X    'd' - Get a short directory listing of the current directory.
  945. X
  946. X    'h' - Use the builtin help menu.
  947. X
  948. X    'l' - Get a long directory listing of the current directory.
  949. X
  950. X    'm' - Return to the "main" menu.  (main.menu)
  951. X
  952. X    'p' - Go to the previous menu.  This assumes that the last
  953. X           entry in the menu is a return to previous menu.  If it
  954. X           is not, it will execute the last entry a command.
  955. X
  956. X    'q' - Quit the Menu.
  957. X
  958. X    'x' - Execute a shell command.
  959. X
  960. X    '?' - Get help on a specified menu entry.  The help file for 
  961. X          that entry must exist for help to be given.
  962. X
  963. X    'L' - Log off the system.  This assumes that you ran the menu
  964. X           from your login shell.  If you did not do this it will 
  965. X              kill the shell it was run from.
  966. X
  967. X    'P' - Print a file using the visual directory to select the
  968. X           file to be printed.
  969. X
  970. X    <ctrl-R> Re-draw the screen in cases where you get garbled. 
  971. X                 (control key and 'R' are pressed at the same time).
  972. X.fi
  973. X
  974. X.SH MENU FILES
  975. XThe Menu files have a specific format that must be followed.  The first
  976. Xcharacter in each line must be $, ?, #, %, +, *, @, &, 1, 2, 3, 4, 5, 6.
  977. XThese are "key" characters that tell "menu" what kind of operation is to
  978. Xbe performed.
  979. X.PP
  980. X\'$'     This character means that this line is the menu header for this
  981. Xmenu, this must be the first character in the line.
  982. XThis must always be the first line in the "menu" file.  The second
  983. Xcharacter in this line is skipped anything after the second column is
  984. Xinterpreted as the menu heading.
  985. X.PP
  986. X\'?'    This character means that this line is a comment to be displayed to
  987. Xthe user when they use the menu.  
  988. X.PP
  989. X\'#'    This character means that this line is a the name or path to 
  990. Xthe help file on a menu selection.
  991. X.PP
  992. X\'%'     Execute in a sub-shell but do not use the continue line
  993. Xupon completion of command.  Similar to the '*' option.
  994. X.PP
  995. X\'+'     This character means that output from the name program be 
  996. Xoutput to the "menu" window.  It is best if the output is 70 columns
  997. Xwide or less, anything after 70 columns is chopped off. Some good examples
  998. Xare ls and ls -l.  Any program which actually does screen manipulation cannot
  999. Xuse the '+' option (It Will really get messed up).
  1000. X.PP
  1001. X\'@'     This character specifies that the menu to be loaded is to
  1002. Xbe considered the main menu so that pressing return will not do anything.
  1003. X.PP
  1004. X\'&'     This character specifies a menu to be loaded.  The path to the menu
  1005. Xfile is the default or the specified one given in the command argument.
  1006. X.PP
  1007. X\'*'     This character means that the invoked program will interfere with
  1008. Xthe "menu" window.  Such programs include more, less and any games.
  1009. X.PP
  1010. X\'1'     This character specifies that one file name is expected as an argument
  1011. Xfor the program to be run.  A good example would be: vi <filename>.
  1012. X.PP
  1013. X\'2'     This character specifies that two file names are expected as
  1014. Xarguments for the program to be run.  A good exmample would be:       
  1015. Xcp <file1> <file2>.
  1016. X.PP
  1017. X\'3'     This character specifies that a user name is expected as an argument
  1018. Xfor the program to be run.  A good exapmple would be:    mail <user>.
  1019. X.PP
  1020. X\'4'     This character specifies a topic to be used as an argument to the 
  1021. Xprogram to be run.  A good example would be:    man <topic>.
  1022. X.PP
  1023. X\'5'     Execute a C-Shell command with a file name as an argument.
  1024. XUses visual directory listing and a file is selected by using the arrow
  1025. Xkeys.  Useful when you know the file must exist.
  1026. X.PP
  1027. X\'6'    Execute a command in a pipe with a file name as an argument.
  1028. XUses visual directory listing and a file is selected by using the arrow 
  1029. Xkeys.  Useful when you know the file must exist.
  1030. X
  1031. X.SH DEFAULTS
  1032. X    The menu program looks for a file called "main.menu" in the default
  1033. Xor specified directory.  If the Directory does not exist or is not accessable
  1034. Xthe program will tell you of the condition and quietly exit.  If the file
  1035. X"main.menu" does not exist in the named directory the program will notify you
  1036. Xthat it could not find any menu files and quietly exits.  The return key
  1037. Xif pressed will do the last thing in the menu, unless that menu is defined
  1038. Xto be the main menu (this is done to make it easy to back out of menus
  1039. Xassuming of course that return to previous menu is that last option in that
  1040. Xmenu).
  1041. X.SH EXAMPLE MENU FILE
  1042. X.nf
  1043. X$ File Management Menu
  1044. X5 /bin/rm -i
  1045. X# /usr/local/lib/menu_help/remove.hlp
  1046. X? Remove a file.
  1047. X2 /bin/cp -i
  1048. X? Copy a file.
  1049. X5 rm -i
  1050. X? Remove a single file.
  1051. X* rm -i *
  1052. X? Cleanup your files.
  1053. X+ /bin/ls -l
  1054. X? List your Files.
  1055. X& menu.1
  1056. X? Return to main Menu.
  1057. X.fi
  1058. X
  1059. X.SH CAUTIONS
  1060. XIf you use the '+' menu command that tells the menu program to send
  1061. Xoutput to the menu window with a command that uses cursor addressing
  1062. Xor requires user input you may get some rather interesting results.
  1063. SHAR_EOF
  1064. chmod 0600 MENU/menu.man ||
  1065. echo 'restore of MENU/menu.man failed'
  1066. Wc_c="`wc -c < 'MENU/menu.man'`"
  1067. test 6412 -eq "$Wc_c" ||
  1068.     echo 'MENU/menu.man: original size 6412, current size' "$Wc_c"
  1069. rm -f _shar_wnt_.tmp
  1070. fi
  1071. # ============= MENU/dir.h ==============
  1072. if test -f 'MENU/dir.h' -a X"$1" != X"-c"; then
  1073.     echo 'x - skipping MENU/dir.h (File already exists)'
  1074.     rm -f _shar_wnt_.tmp
  1075. else
  1076. > _shar_wnt_.tmp
  1077. echo 'x - extracting MENU/dir.h (Text)'
  1078. sed 's/^X//' << 'SHAR_EOF' > 'MENU/dir.h' &&
  1079. X
  1080. X# define  PRT_MENU    "Choose a printer: arrow keys to move, return to select, 'q' to quit"
  1081. X# define  PRINT_PATH    "/usr/local/lib/menus/printers"
  1082. X# define  PRT_TO_SCR    "/usr/ucb/more"
  1083. X# define  OTHER_LINE    "n)ext page p)revious page"
  1084. X
  1085. X# define    UP        252
  1086. X# define    DOWN        253
  1087. X# define    LEFT        254
  1088. X# define    RIGHT        255
  1089. X
  1090. X# define    MAX_PRINTERS    24
  1091. X# define    MAX_ENT        1024
  1092. X# define    ENT_LEN        20
  1093. X
  1094. X# define    isposodd(x) (x % 2)
  1095. X# define    in_col_one(x) ((x / 2) + (x % 2))
  1096. X# define    in_col_two(x) (x - in_col_one(x))
  1097. X
  1098. Xstruct print_options
  1099. X{
  1100. X    char selection[80];
  1101. X    int option;
  1102. X    int x;
  1103. X    int y;
  1104. X};
  1105. X
  1106. Xstatic struct print_options print_opts[6] = {
  1107. X    {"CANCEL",0,5,20},
  1108. X    {"PRINT",0,16,20},
  1109. X    {"(Spacing %d)",0,26,20},
  1110. X    {"(Skip Page Break %s)",0,41,20},
  1111. X    {"(Copies %d)",0,65,20}
  1112. X};
  1113. X
  1114. Xtypedef struct
  1115. X{
  1116. X    char comment[40];
  1117. X    char command[128];
  1118. X}printer;
  1119. X
  1120. Xtypedef struct 
  1121. X{
  1122. X    int max_row;
  1123. X    int max_col;
  1124. X}dir_info;
  1125. X
  1126. XDIR *opendir();
  1127. Xstruct dirent *readdir();
  1128. Xint closedir();
  1129. X
  1130. Xint strcmp();
  1131. X
  1132. SHAR_EOF
  1133. chmod 0600 MENU/dir.h ||
  1134. echo 'restore of MENU/dir.h failed'
  1135. Wc_c="`wc -c < 'MENU/dir.h'`"
  1136. test 945 -eq "$Wc_c" ||
  1137.     echo 'MENU/dir.h: original size 945, current size' "$Wc_c"
  1138. rm -f _shar_wnt_.tmp
  1139. fi
  1140. rm -f _shar_seq_.tmp
  1141. echo You have unpacked the last part
  1142. exit 0
  1143.  
  1144. exit 0 # Just in case...
  1145.