home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume39 / pscmenu / part01 < prev    next >
Encoding:
Text File  |  1993-08-29  |  59.3 KB  |  2,358 lines

  1. Newsgroups: comp.sources.misc
  2. From: Ted Wisniewski <ted@oz.plymouth.edu>
  3. Subject: v39i060:  pscmenu - tty based menu system v2.3, Part01/02
  4. Message-ID: <csm-v39i060=pscmenu.115434@sparky.Sterling.COM>
  5. X-Md4-Signature: c1c3b8dd963d027ef1ef5b7df5c1a04e
  6. Sender: kent@sparky.sterling.com (Kent Landfield)
  7. Reply-To: ted@oz.plymouth.edu (The Wizard of Oz)
  8. Organization: Plymouth State College - Plymouth, N.H.
  9. Date: Sun, 29 Aug 1993 16:55:00 GMT
  10. Approved: kent@sparky.sterling.com
  11.  
  12. Submitted-by: Ted Wisniewski <ted@oz.plymouth.edu>
  13. Posting-number: Volume 39, Issue 60
  14. Archive-name: pscmenu/part01
  15. Environment: UNIX, curses
  16. Supersedes: pscmenu: Volume 22, Issue 98-99
  17.  
  18. PSCMenu is a menu system that is capable of doing any unix command 
  19. from the "menu".  The individual menus are read from menu files that
  20. are located in a "menu" directory.  The menu files are simple text files
  21. that may be edited with any editor.  The "menu" is flexible, the only
  22. command line argument that is accepted is the name of a directory in which
  23. the menu files are located.  A default directory is specified in the
  24. menu header file. 
  25.  
  26. This Menu system should compile on just about any machine.  I 
  27. have it working under Ultrix, AIX (IBM system V), SUN and HP-UX.  
  28. These are the only variations of UNIX that I know it has worked on.  
  29. If you have problems just ask.  
  30.  
  31. Ted
  32. ----
  33. #! /bin/sh
  34. # This is a shell archive.  Remove anything before this line, then feed it
  35. # into a shell via "sh file" or similar.  To overwrite existing files,
  36. # type "sh file -c".
  37. # Contents:  MENU MENU/appl.c MENU/demos MENU/demos/HELP
  38. #   MENU/demos/sub_menu.menu MENU/dir.c MENU/files.c MENU/menu.c
  39. #   MENU/menu.h MENU/menu.man MENU/terminal.c
  40. # Wrapped by kent@sparky on Sun Aug 29 11:50:48 1993
  41. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  42. echo If this archive is complete, you will see the following message:
  43. echo '          "shar: End of archive 1 (of 2)."'
  44. if test ! -d 'MENU' ; then
  45.     echo shar: Creating directory \"'MENU'\"
  46.     mkdir 'MENU'
  47. fi
  48. if test -f 'MENU/appl.c' -a "${1}" != "-c" ; then 
  49.   echo shar: Will not clobber existing file \"'MENU/appl.c'\"
  50. else
  51.   echo shar: Extracting \"'MENU/appl.c'\" \(12748 characters\)
  52.   sed "s/^X//" >'MENU/appl.c' <<'END_OF_FILE'
  53. X# define    __APPL_C
  54. X
  55. X# include "config.h"
  56. X# include "proto.h"
  57. X# include "utils.h"
  58. X# include "menu.h"
  59. X
  60. X/*    PSC MENU COPYRIGHT NOTICE
  61. X
  62. X    Part of PSCMenu
  63. X
  64. X    This software is to be considered to be public domain, it
  65. Xmay be copied, modified and parts of it may be used in other programs
  66. Xas long as this copyright notice remains intact.
  67. X
  68. X    Copyright()   PSC - Plymouth State College
  69. X    Written by:   Ted Wisniewski 12-9-1990
  70. X*/
  71. X
  72. X/*
  73. X *    static disp_help():
  74. X *
  75. X *    Parameters:     None
  76. X *    
  77. X *    Purpose:    Display the Help Window.
  78. X *
  79. X *    Returns:    None
  80. X *
  81. X *    Last Modify:    01-12-91 (TW)
  82. X *
  83. X */
  84. X
  85. Xstatic int disp_help()
  86. X{
  87. X    char Key;
  88. X    
  89. X    clear_window(inside_window);
  90. X    box_window(help_window);
  91. X    my_print(help_window,"Command Summary:",2,1);
  92. X    my_print(help_window,"(q)       Quit Menu",2,3);
  93. X    my_print(help_window,"(x)       Execute Command",2,4);
  94. X    my_print(help_window,"(C)       Change Directory",2,5);
  95. X    my_print(help_window,"(D)       Show Directory",2,6);
  96. X    my_print(help_window,"(l)       Long Directory",2,7);
  97. X    my_print(help_window,"(?)       Get Help on Item",2,8);
  98. X    my_print(help_window,"(m)       Go to Main Menu",2,9);
  99. X    my_print(help_window,"(p)       Go to Prev Menu",2,10);
  100. X    my_print(help_window,"(L)       Log off!",2,11);
  101. X# ifdef ENABLE_PRINT
  102. X    my_print(help_window,"(P)       Print a file.",2,12);
  103. X# else
  104. X    my_print(help_window,"(P)       Disabled, sorry.",2,12);
  105. X# endif
  106. X    my_print(help_window,"(ctrl-R)  Redraw Screen.",2,13);
  107. X    hi_lite(help_window,"Space Bar to exit.",5,16);
  108. X    move_csr(help_window,2,15);
  109. X    Key = my_getchar(help_window);
  110. X    clear_window(help_window);
  111. X    return(Key);
  112. X}
  113. X
  114. X/*
  115. X *    static do_help():
  116. X *
  117. X *    Parameters:    name - String containing a file name.
  118. X *            y    - Number of lines from top of screen.
  119. X *    
  120. X *    Purpose:    read a file name into the string.
  121. X *
  122. X *    Returns:    None.
  123. X *
  124. X *    Last Modify:    01-12-91 (TW)
  125. X *
  126. X */
  127. X
  128. Xstatic void One_fname(name,y)
  129. Xchar *name;
  130. Xint y;
  131. X{
  132. X    clear_array(name);
  133. X    my_print(inside_window,"Filename: ",2,y);
  134. X    read_str(inside_window,name,30);
  135. X}
  136. X
  137. X/*
  138. X *    static Two_fname():
  139. X *
  140. X *    Parameters:    name - String containing a file name.
  141. X *            y    - Number of lines from top of screen.
  142. X *    
  143. X *    Purpose:
  144. X *
  145. X *    Returns:
  146. X *
  147. X *    Last Modify:    01-12-91 (TW)
  148. X *
  149. X */
  150. X
  151. Xstatic void Two_fname(name,y)
  152. Xchar *name;
  153. Xint y;
  154. X{
  155. X    clear_array(name);
  156. X    my_print(inside_window,"New File: ",2,y);
  157. X    read_str(inside_window,name,30);
  158. X}
  159. X
  160. X/*
  161. X *    static change():
  162. X *
  163. X *    Parameters:    None.
  164. X *    
  165. X *    Purpose:    Change to a new working directory.
  166. X *
  167. X *    Returns:    None.
  168. X *
  169. X *    Last Modify:    01-12-91 (TW)
  170. X *
  171. X */
  172. X
  173. Xstatic void change()
  174. X{
  175. X    clear_array(buffer);
  176. X    my_print(inside_window,"Directory: ",2,2);
  177. X    read_str(inside_window,buffer,30);
  178. X    (void) chdir(buffer);
  179. X    erase_line(inside_window,2,2,60);
  180. X    prt_curdir();
  181. X    clear_array(buffer);
  182. X}
  183. X
  184. X/*
  185. X *    static exec_it():
  186. X *
  187. X *     Parameters:    None.
  188. X *    
  189. X *    Purpose:    Execute A shell commenad.
  190. X *
  191. X *    Returns:    None.
  192. X *
  193. X *    Last Modify:    01-12-91 (TW)
  194. X *
  195. X */
  196. X
  197. Xstatic void exec_it()
  198. X{
  199. X    my_print(inside_window,"Command: ",2,2);
  200. X    clear_array(buffer);
  201. X    read_str(inside_window,buffer,30);
  202. X    exec_cshell(buffer,CONTINUE);
  203. X}
  204. X
  205. X/*
  206. X *    static ask_who():
  207. X *
  208. X *    Parameters:    None.
  209. X *    
  210. X *    Purpose:    Ask for a login name.
  211. X *
  212. X *    Returns:    None.
  213. X *
  214. X *    Last Modify:    01-12-91 (TW)
  215. X *
  216. X */
  217. X
  218. Xstatic void ask_who(name,y)
  219. Xchar *name;
  220. Xint y;
  221. X{
  222. X    clear_array(name);
  223. X    my_print(inside_window,"To Whom: ",2,y);
  224. X    read_str(inside_window,name,30);
  225. X    move_csr(inside_window,2,3);
  226. X}
  227. X
  228. X/*
  229. X *    static ask_what():
  230. X *
  231. X *    Parameters:    name - Name of what you are asking.
  232. X *            y    - number of rows down from top of screen.
  233. X *    
  234. X *    Purpose:    Ask for a topic.
  235. X *
  236. X *    Returns:    None.
  237. X *
  238. X *    Last Modify:    01-12-91 (TW)
  239. X *
  240. X */
  241. X
  242. Xstatic void ask_what(name,y)
  243. Xchar *name;
  244. Xint y;
  245. X{
  246. X    clear_array(name);
  247. X    my_print(inside_window,"Topic: ",2,y);
  248. X    read_str(inside_window,name,30);
  249. X}
  250. X
  251. X/*
  252. X *    void check_dirname():
  253. X *
  254. X *    Parameters:    string - Name of directory.
  255. X *    
  256. X *    Purpose:    Expand '~' to users Home Directory.
  257. X *
  258. X *    Returns:    None.
  259. X *
  260. X *    Last Modify:    01-12-91 (TW)
  261. X *
  262. X */
  263. X
  264. Xvoid check_dirname(string)
  265. Xchar *string;
  266. X{
  267. X    char *tmp_str;
  268. X
  269. X    tmp_str = (char *) malloc(80);;
  270. X    if(*string == TILD){
  271. X      Strcpy(tmp_str,getenv("HOME"));
  272. X      Strcat(tmp_str,string+1);
  273. X      Strcat(tmp_str,"/");
  274. X      string = tmp_str;
  275. X    }
  276. X}
  277. X
  278. Xvoid do_padding(string,width)
  279. Xchar string[];
  280. Xint width;
  281. X{
  282. X    int ct;
  283. X
  284. X    if(strlen(string) > width)
  285. X       string[strlen(string)] = NULL;
  286. X    else
  287. X       for(ct=0;ct<=width+1;ct++){
  288. X          if(string[ct] == NULL){
  289. X             string[ct] = SPACE;
  290. X             string[ct+1] = NULL;
  291. X          }
  292. X       }
  293. X}
  294. X
  295. X/*
  296. X *    void disp_menu():
  297. X *
  298. X *    Parameters:    menu -  a pointer to the menu information
  299. X *            n_ent - The number of entries in the menu.
  300. X *
  301. X *    Purpose:    Display the Menu on the screen.
  302. X *
  303. X *    Returns:    None.
  304. X *
  305. X *    Last Modify:    01-12-91 (TW)
  306. X *            07-06-93 (TW)
  307. X *
  308. X */
  309. X
  310. Xvoid disp_menu(menu,n_ent)
  311. Xmenu_ent *menu;
  312. Xint n_ent;
  313. X{
  314. X    int ind = 0;
  315. X    char tmp[5];
  316. X    
  317. X    while(ind < n_ent){
  318. X       if(ind == 0){
  319. X         center_line(inside_window,menu[0].desc,2,78,1);
  320. X       }else
  321. X         if(ind > 0){
  322. X           if(menu[0].cflag == FALSE){
  323. X             Sprintf(tmp,"%d)",ind);
  324. X             my_print(inside_window,tmp,NUMCOL,(ind*2) + 3);
  325. X             hi_lite(inside_window,menu[ind].desc,DESCOL,(ind*2) + 3);
  326. X           }else{
  327. X         if(ind < 10)
  328. X               Sprintf(tmp,"%d)",ind);
  329. X         else
  330. X               Sprintf(tmp,"%c)",(ind - 10) + 'a');
  331. X             my_print(inside_window,tmp,NUMCOL,(ind) + 3);
  332. X             my_print(inside_window,menu[ind].desc,DESCOL,(ind) + 3);
  333. X           }
  334. X         }
  335. X       ind++;
  336. X    }
  337. X}
  338. X
  339. X/*
  340. X *    static do_help():
  341. X *
  342. X *    Parameters:    menu - pointer to menu information.
  343. X *            num  - the number of entries in the menu.
  344. X *    
  345. X *    Purpose:    Show help on a menu option.
  346. X *
  347. X *    Returns:    None.
  348. X *
  349. X *    Last Modify:    01-12-91 (TW)
  350. X *
  351. X */
  352. X
  353. Xstatic void do_help(menu,num)
  354. Xmenu_ent *menu;
  355. Xint num;
  356. X{
  357. X    char buff[256];
  358. X
  359. X     Sprintf(buff,"cat %s",menu[num].help_fil);
  360. X     exec_pipe(buff);
  361. X}
  362. X
  363. Xvoid strc_cpy(destin, source, character)
  364. Xchar *destin, *source, character;
  365. X{
  366. X    for(;*source != NULL, *source != character; *source++,*destin++)
  367. X       *destin = *source;
  368. X    *destin = NULL;
  369. X}
  370. X
  371. Xchar *get_arg(string)
  372. Xchar *string;
  373. X{
  374. X    return(NULL);
  375. X}
  376. X
  377. Xvoid choose_option(string)
  378. Xchar *string;
  379. X{
  380. X    char cmd[80], option_file[80], command[256];
  381. X    char *ptr;
  382. X
  383. X    if((ptr = index(string,COLON)) != NULL){
  384. X      strcpy(option_file,ptr+2);
  385. X      strc_cpy(cmd,string,COLON);
  386. X      ptr = get_arg(option_file);
  387. X    fprintf(stderr,"OPTION = %s",ptr);
  388. X      (void) sprintf(command,"%s %s",cmd, ptr);
  389. X    }else
  390. X      return;
  391. X    fprintf(stderr,"Command = %s",cmd);
  392. X}
  393. X
  394. X/*
  395. X *    void do_menu():
  396. X *
  397. X *    Parameters:     menu  - pointer to menu information.
  398. X *            n_ent - number of menu entries.
  399. X *    
  400. X *    Purpose:    Main work loop, keystrokes interpreted.
  401. X *
  402. X *    Returns:    None
  403. X *
  404. X *    Last Modify:    01-12-91 (TW)
  405. X *            07-06-93 (TW)
  406. X *
  407. X */
  408. X
  409. Xvoid do_menu(menu,n_ent)
  410. Xmenu_ent *menu;
  411. Xint n_ent;
  412. X{
  413. X    char buff[LINESZ], inp = NULL, *ptr;
  414. X    int tmp, num;
  415. X
  416. X    move_csr(inside_window,4,20);
  417. X    while(inp != QUIT_KEY) {
  418. X       switch (inp) {
  419. X            case CHANGE_DIR:
  420. X          clear_window(inside_window);
  421. X              change();
  422. X              disp_menu(menu,n_ent);
  423. X            break;
  424. X        case EXEC_COMM:
  425. X          clear_window(inside_window);
  426. X          exec_it();
  427. X              disp_menu(menu,n_ent);
  428. X        break;
  429. X        case SHORT_DIR:
  430. X          clear_window(inside_window);
  431. X              exec_cshell("ls",CONTINUE);
  432. X              disp_menu(menu,n_ent);
  433. X            break;
  434. X        case DO_PRINT:
  435. X# ifdef ENABLE_PRINT
  436. X          clear_window(inside_window);
  437. X          do_printers();
  438. X          disp_menu(menu,n_ent);
  439. X# endif
  440. X        break;
  441. X        case '?':
  442. X          Sprintf(buff,"Get help on item %d..%d? ",1,n_ent-1);
  443. X          hi_lite(inside_window,buff,23,19);
  444. X          num = (my_getchar(inside_window) - '0');
  445. X             erase_line(inside_window,23,19,30);
  446. X          if((num > 0) && (num < n_ent)){
  447. X             if((check_file(menu[num].help_fil)) == -1){
  448. X                   hi_lite(inside_window,"Sorry, There is no help file for this.",21,20);
  449. X                  continue_it(20);
  450. X                   erase_line(inside_window,21,20,40);
  451. X             }else{
  452. X                clear_window(inside_window);
  453. X                do_help(menu,num);
  454. X                    disp_menu(menu,n_ent);
  455. X             }
  456. X          }
  457. X        break;
  458. X        case LONG_DIR:
  459. X          clear_window(inside_window);
  460. X              exec_pipe("ls -l");
  461. X              disp_menu(menu,n_ent);
  462. X        break;
  463. X        case RE_DRAW:
  464. X            clear_window(stdscr);
  465. X          setup_screen();
  466. X          disp_menu(menu,n_ent);
  467. X        break;
  468. X            case TO_MAIN:
  469. X          if(m_flag != TRUE){
  470. X            clear_window(inside_window);
  471. X              (void) read_menu(menu,MAIN_MENU,&n_ent);
  472. X              disp_menu(menu,n_ent);
  473. X            m_flag = TRUE;
  474. X          }
  475. X            break;
  476. X        case LOGOUT:
  477. X          clear_window(stdscr);
  478. X          move_csr(stdscr,0,LAST_LINE);
  479. X          unset_modes();
  480. X          log_out();
  481. X        break;
  482. X            case PREV_MENU:
  483. X        case LF:
  484. X        case RETURN:
  485. X           if(m_flag != TRUE)
  486. X              inp = n_ent-1 + '0';
  487. X        default:
  488. X              tmp = inp - '0';
  489. X          if(inp >= 'a')
  490. X            tmp = (inp - 'a') + 10;
  491. X              if((tmp >= 1) && (tmp < n_ent)){
  492. X                switch(menu[tmp].key){
  493. X                   case EXEC_PIPE:
  494. X                  clear_window(inside_window);
  495. X                exec_pipe(menu[tmp].cmd);
  496. X                disp_menu(menu,n_ent);
  497. X                   break;
  498. X                   case EXEC_NCNT:
  499. X              exec_cshell(menu[tmp].cmd,NO_CONTINUE);
  500. X                disp_menu(menu,n_ent);
  501. X                   break;
  502. X                   case EXEC_CONT:
  503. X              exec_cshell(menu[tmp].cmd,CONTINUE);
  504. X                disp_menu(menu,n_ent);
  505. X                   break;
  506. X               case OPTN_CHSE:
  507. X/*
  508. X              choose_option(menu[tmp].cmd);
  509. X                disp_menu(menu,n_ent);
  510. X*/
  511. X                break;
  512. X               case LOAD_MAIN: menu->key = LOAD_MAIN;
  513. X                   case LOAD_MENU:
  514. X                  clear_window(inside_window);
  515. X                (void) read_menu(menu,menu[tmp].cmd,&n_ent);
  516. X                disp_menu(menu,n_ent);
  517. X                   break;
  518. X                   case FILE_ASK1:
  519. X                  clear_window(inside_window);
  520. X              One_fname(buffer,2);
  521. X              if((strlen(buffer)) != 0){
  522. X                Sprintf(string,"%s %s",menu[tmp].cmd,buffer);
  523. X                exec_cshell(string,CONTINUE);
  524. X                clear_array(string);
  525. X              }else
  526. X                erase_line(inside_window,2,2,40);
  527. X                disp_menu(menu,n_ent);
  528. X                   break;
  529. X                   case FILE_ASK2:
  530. X                  clear_window(inside_window);
  531. X              One_fname(buffer,2);
  532. X              if((strlen(buffer)) != 0){
  533. X                Sprintf(string,"%s %s ",menu[tmp].cmd,buffer);
  534. X                Two_fname(buffer,3);
  535. X                if((strlen(buffer)) != 0){
  536. X                  if(!isprint(buffer[strlen(buffer)]))
  537. X                     rm_lf(buffer);
  538. X                  Strcat(string,buffer);
  539. X                  exec_cshell(string,CONTINUE);
  540. X                  clear_array(string);
  541. X                }else{
  542. X                  erase_line(inside_window,2,2,40);
  543. X                  erase_line(inside_window,2,3,40);
  544. X                }
  545. X              }else
  546. X                erase_line(inside_window,2,2,40);
  547. X                disp_menu(menu,n_ent);
  548. X                   break;
  549. X                   case ASKS_USER:
  550. X                  clear_window(inside_window);
  551. X              ask_who(buffer,2);
  552. X              if((strlen(buffer)) != 0){
  553. X                Sprintf(string,"%s %s",menu[tmp].cmd,buffer);
  554. X                exec_cshell(string,CONTINUE);
  555. X                clear_array(buffer);
  556. X                clear_array(string);
  557. X              }else
  558. X                erase_line(inside_window,2,2,40);
  559. X                disp_menu(menu,n_ent);
  560. X                   break;
  561. X                   case ASKS_WHAT:
  562. X                  clear_window(inside_window);
  563. X              ask_what(buffer,2);
  564. X              if((strlen(buffer)) != 0){
  565. X                Sprintf(string,"%s %s",menu[tmp].cmd,buffer);
  566. X                exec_cshell(string,CONTINUE);
  567. X                clear_array(buffer);
  568. X                clear_array(string);
  569. X              }else
  570. X                erase_line(inside_window,2,2,40);
  571. X                disp_menu(menu,n_ent);
  572. X                   break;
  573. X               case VISL_SHLL:
  574. X                  clear_window(inside_window);
  575. X              ptr = do_selection();
  576. X              if(ptr != NULL){
  577. X                Sprintf(string,"%s %s",menu[tmp].cmd,ptr);
  578. X                exec_cshell(string,CONTINUE);
  579. X                clear_array(buffer);
  580. X                clear_array(string);
  581. X              }
  582. X              disp_menu(menu,n_ent);
  583. X               break;
  584. X               case VISL_PIPE:
  585. X                  clear_window(inside_window);
  586. X              ptr = do_selection();
  587. X              if(ptr != NULL){
  588. X                Sprintf(string,"%s %s",menu[tmp].cmd,ptr);
  589. X                exec_pipe(string);
  590. X                clear_array(buffer);
  591. X                clear_array(string);
  592. X              }
  593. X              disp_menu(menu,n_ent);
  594. X               break;
  595. X                   default:
  596. X               break;
  597. X         }
  598. X       }
  599. X      }
  600. X      move_csr(stdscr,0,23);
  601. X      inp = my_getchar(inside_window);
  602. X      if(inp == HELP_KEY){
  603. X         inp = disp_help();
  604. X         if(inp != EXEC_COMM && inp!= SHORT_DIR && 
  605. X        inp != CHANGE_DIR && inp != RE_DRAW)
  606. X           disp_menu(menu,n_ent);
  607. X      }
  608. X    }
  609. X    quit();
  610. X}
  611. X
  612. X/*
  613. X *    void chop_str():
  614. X *
  615. X *    Parameters:    instring   - A string to chop to 70 columns
  616. X *                max_length - max length for string.
  617. X *    
  618. X *    Purpose:    Strip anything after the 70th column off.
  619. X *
  620. X *    Returns:    None.
  621. X *
  622. X *    Last Modify:    06-10-91 (TW)
  623. X *
  624. X */
  625. X
  626. Xvoid chop_str(instring,max_length)
  627. Xchar *instring;
  628. Xint max_length;
  629. X{
  630. X    int length,i;
  631. X    
  632. X    length = strlen(instring);
  633. X    while(*instring != NULL)
  634. X       *instring++;
  635. X    for(i=length;i>max_length;i--,*instring--)
  636. X      *instring = NULL;
  637. X}
  638. X
  639. Xvoid pad_str(instring)
  640. Xchar *instring;
  641. X{
  642. X    int length,i;
  643. X    
  644. X    length = strlen(instring);
  645. X    for(i=length;i<=70;i++)
  646. X       instring[i] = SPACE;
  647. X    instring[70] = NULL;
  648. X}
  649. END_OF_FILE
  650.   if test 12748 -ne `wc -c <'MENU/appl.c'`; then
  651.     echo shar: \"'MENU/appl.c'\" unpacked with wrong size!
  652.   fi
  653.   # end of 'MENU/appl.c'
  654. fi
  655. if test ! -d 'MENU/demos' ; then
  656.     echo shar: Creating directory \"'MENU/demos'\"
  657.     mkdir 'MENU/demos'
  658. fi
  659. if test ! -d 'MENU/demos/HELP' ; then
  660.     echo shar: Creating directory \"'MENU/demos/HELP'\"
  661.     mkdir 'MENU/demos/HELP'
  662. fi
  663. if test -f 'MENU/demos/sub_menu.menu' -a "${1}" != "-c" ; then 
  664.   echo shar: Will not clobber existing file \"'MENU/demos/sub_menu.menu'\"
  665. else
  666.   echo shar: Extracting \"'MENU/demos/sub_menu.menu'\" \(991 characters\)
  667.   sed "s/^X//" >'MENU/demos/sub_menu.menu' <<'END_OF_FILE'
  668. X! Example Sub-menu (7-option)
  669. X................................
  670. X* /usr/local/bin/elm
  671. X? Use ELM (Exec C-Shell)
  672. X#
  673. X................................
  674. X% /usr/local/bin/elm
  675. X? Use ELM (Exec C-Shell)
  676. X#
  677. X................................
  678. X+ /bin/cat main.menu
  679. X? View "main.menu" (In Pipe).
  680. X#
  681. X................................
  682. X+ /bin/cat main.menu
  683. X? View "main.menu" (In Pipe).
  684. X# 
  685. X................................
  686. X+ /bin/cat main.menu
  687. X? View "main.menu" (In Pipe).
  688. X# 
  689. X................................
  690. X+ /bin/cat main.menu
  691. X? View "main.menu" (In Pipe).
  692. X# 
  693. X................................
  694. X+ /bin/cat main.menu
  695. X? View "main.menu" (In Pipe).
  696. X# 
  697. X................................
  698. X+ /bin/cat main.menu
  699. X? View "main.menu" (In Pipe).
  700. X# 
  701. X................................
  702. X+ /bin/cat main.menu
  703. X? View "main.menu" (In Pipe).
  704. X# 
  705. X................................
  706. X+ /bin/cat main.menu
  707. X? View "main.menu" (In Pipe).
  708. X# 
  709. X................................
  710. X& main.menu
  711. X? Return to Main Menu.
  712. X# 
  713. X................................
  714. END_OF_FILE
  715.   if test 991 -ne `wc -c <'MENU/demos/sub_menu.menu'`; then
  716.     echo shar: \"'MENU/demos/sub_menu.menu'\" unpacked with wrong size!
  717.   fi
  718.   # end of 'MENU/demos/sub_menu.menu'
  719. fi
  720. if test -f 'MENU/dir.c' -a "${1}" != "-c" ; then 
  721.   echo shar: Will not clobber existing file \"'MENU/dir.c'\"
  722. else
  723.   echo shar: Extracting \"'MENU/dir.c'\" \(13211 characters\)
  724.   sed "s/^X//" >'MENU/dir.c' <<'END_OF_FILE'
  725. X# define    __DIR_C
  726. X
  727. X# include "config.h"
  728. X# include "proto.h"
  729. X# include "menu.h"
  730. X# include <sys/types.h>
  731. X# include <stdlib.h>
  732. X# include <memory.h>
  733. X
  734. X# ifndef HPUX
  735. X# include <sys/dir.h>
  736. X# else
  737. X# include <sys/dirent.h>
  738. X# endif HPUX
  739. X
  740. X# include <sys/stat.h>
  741. X# include <signal.h>
  742. X# include "dir.h"
  743. X
  744. X/*
  745. X *    is_directory(directory,file):  
  746. X *            The first parameter is the name
  747. X *            directory and the second is the
  748. X *            name of the file in the directory.
  749. X *
  750. X *    Purpose:    Determine if a file is a directory file.
  751. X *
  752. X *    Return:        -1 = Failure to stat file, (file may not exist)
  753. X *                1  = Is a directory file.
  754. X *            0  = Is a regular file.
  755. X *
  756. X *    Last Modify:    3-31-91 (TW)
  757. X */
  758. X
  759. Xint is_directory(file_name)
  760. Xchar *file_name;
  761. X{
  762. X    struct stat st_buf;
  763. X
  764. X    if(stat(file_name,&st_buf) < 0)
  765. X      return(-1);
  766. X    else
  767. X      if(st_buf.st_mode & S_IFDIR)
  768. X        return(1);
  769. X    return(0);
  770. X}
  771. X
  772. X/*
  773. X *    void replace_spaces(string):
  774. X *            The Parameter "string" is a file name that may
  775. X *            contain spaces.  Replace all spaces with the
  776. X *            '*' character.
  777. X *
  778. X *    Purpose:    Make it so a file with spaces in the name may
  779. X *            be accessed.
  780. X *
  781. X *    Returns:    None
  782. X *
  783. X *    Last Modify:    11-22-91 (TW)
  784. X *
  785. X */
  786. X
  787. Xvoid replace_spaces(string)
  788. Xchar *string;
  789. X{
  790. X    for(;*string != NULL;*string++)
  791. X      if(isspace(*string) || iscntrl(*string))
  792. X        *string = ASTER;
  793. X}
  794. X
  795. X/*
  796. X *    int get_dir(dir_entries,name):
  797. X *            The parameter "dir_entries" an character array of
  798. X *            MAX_ENT entries, with each entry being ENT_LEN in
  799. X *             length.
  800. X *
  801. X *    Purpose:    Read the current directory file and extract the
  802. X *            file names and sort the list.
  803. X *
  804. X *    Return Values:    -1  = Failed to read the directory file.
  805. X *            ct  = The number of files in the directory, the count
  806. X *            excludes (dot) files and Directory Files.
  807. X *
  808. X *    Last Modify:    3-31-91 (TW)
  809. X *            5-01-91 (TW)
  810. X */
  811. X
  812. Xint get_dir(dir_entries,name)
  813. Xchar dir_entries[MAX_ENT][ENT_LEN];
  814. Xchar *name;
  815. X{
  816. X    DIR *dirp;
  817. X# if defined (SUN) || defined (BSD43)
  818. X    struct direct *dp;
  819. X# else
  820. X    struct dirent *dp;
  821. X# endif SUN
  822. X    int i = 0,ct;
  823. X    
  824. X    if((dirp = opendir(name)) == (DIR *)NULL)    /* Open the directory */
  825. X      return(-1);                     /* Return with error  */
  826. X    for(dp = readdir(dirp);dp != NULL; dp = readdir(dirp)){
  827. X       if(dp->d_name[0] != DOT && !is_directory(dp->d_name)){
  828. X          replace_spaces(dp->d_name);
  829. X          memccpy(dir_entries[i],dp->d_name,NULL,18);
  830. X          dir_entries[i][18] = ASTER;         /* Just in case long name*/
  831. X          i++;
  832. X          ct = i;
  833. X       }
  834. X    }
  835. X    closedir(dirp);                    /* Close the Directory */
  836. X    qsort(dir_entries,ct,20,strcmp);        /* Sort the List       */
  837. X    return(ct);
  838. X}
  839. X
  840. X/*
  841. X *    print_other()
  842. X *    
  843. X *    Parameters:    None
  844. X *
  845. X *     Purpose:    Print Some Instructions.
  846. X *    
  847. X *    Last Modify:    3-31-91 (TW)
  848. X */
  849. X
  850. Xvoid print_other()
  851. X{
  852. X
  853. X    hi_lite(stdscr,"Select a file?   Use: Arrow Keys to move, Return to select, 'q' to abort",2,2); 
  854. X    hi_lite(stdscr,"n - next page, p - previous page",24,3);
  855. X    hi_lite(stdscr,"h,j,k,l keys also move selection bar.",38,20);
  856. X}
  857. X
  858. X/*
  859. X *    int print_dir(dir_entries,start_ent,n_entries,end,dptr)
  860. X *
  861. X *    Parameters:    dir_entries - The list of files.
  862. X *            start_ent   - Start printing with entry #.
  863. X *            n_entries   - How many entries are there.
  864. X *            end         - What # do we stop printing at.
  865. X *            dptr        - Special info.
  866. X *    Purpose:    Print a select group of file names ont the screen.
  867. X *
  868. X *    Returns:    The Number of the last entry printed.
  869. X *
  870. X *    Last Modify:    3-31-91 (TW)
  871. X */
  872. X
  873. Xint print_dir(dir_entries,start_ent,n_entries,end,dptr)
  874. Xchar dir_entries[MAX_ENT][ENT_LEN];
  875. Xint start_ent,n_entries,end;
  876. Xdir_info *dptr;
  877. X{
  878. X    int i, row = 5, col = 0;
  879. X    int this_scr;
  880. X
  881. X    print_other();            /* Print Directions on the top of the*/
  882. X                    /* Screen.                 */
  883. X    dptr->max_row = dptr->max_col = 0;
  884. X    this_scr = start_ent + 45;
  885. X    if(n_entries > end){
  886. X      if(this_scr > n_entries)
  887. X         this_scr = n_entries;
  888. X    }else{
  889. X      this_scr = n_entries;
  890. X    }
  891. X    /*
  892. X     * Print all for this screen.
  893. X         */
  894. X    for(i=start_ent;i<this_scr;i++){
  895. X      if((i != 0) && ((i % 15) == 0) && ((i % 45) != 0)){
  896. X         col++;
  897. X         row = 5;
  898. X      }
  899. X      my_print(stdscr,dir_entries[i],(col*20)+10,row);
  900. X      row++;
  901. X      if(dptr->max_row < row-2)
  902. X         dptr->max_row = row-2;
  903. X      if(dptr->max_col < ((col)+1)*20)
  904. X         dptr->max_col = ((col+1)*20);
  905. X      
  906. X    }
  907. X    return(this_scr);
  908. X}
  909. X
  910. X/*
  911. X *    move_entry(dir_entries,row,col,row_off,start,flag)
  912. X *
  913. X *    Parameters:    dir_entries - The list of file Names.
  914. X *            row         - Which row we are on.
  915. X *            row_off        - Row offset from top of screen.
  916. X *            start        - The array index number of the
  917. X *                      first file name.
  918. X *            flag        - Boolean: True == Highlight
  919. X *                      False == No Highlight
  920. X *
  921. X *    Purpose:    Allow user to move a high-lite bar to select a
  922. X *            file.
  923. X *
  924. X *    Last Modify:    3-31-91 (TW)
  925. X */
  926. X
  927. Xvoid move_entry(dir_entries,row,col,row_off,start,flag)
  928. Xchar dir_entries[MAX_ENT][ENT_LEN];
  929. Xint row,col,row_off,start,flag;
  930. X{
  931. X    int index;
  932. X
  933. X    if(col == 0)
  934. X      index = ((col%13))+row+start;
  935. X    else
  936. X      index = (((col/15)*15))+row+start;
  937. X    if(!flag)
  938. X      my_print(stdscr,dir_entries[index],col+10,row+row_off);
  939. X    else
  940. X      hi_lite(stdscr,dir_entries[index],col+10,row+row_off);
  941. X}
  942. X
  943. X/*
  944. X *    char *select_item(dir_ent,number,start,end,dp)
  945. X *
  946. X *    parameters:    dir_ent - The list of file Names.
  947. X *            number  - 
  948. X *            start   - The Starting Number for the current screen.
  949. X *            end     - The number of the last one on this screen.
  950. X *            dp      - Special Info.
  951. X *
  952. X *    Purpose:    Loop to get selections. Ultimately returns a file name.
  953. X *
  954. X *    Last Modify:    3-31-91 (TW)
  955. X *            5-01-91 (TW)
  956. X */
  957. X
  958. Xchar *select_item(dir_ent,number,start,end,dp)
  959. Xchar dir_ent[MAX_ENT][ENT_LEN];
  960. Xint number,start,end;
  961. Xdir_info *dp;
  962. X{
  963. X    int row = 0, col = 0, row_off = 5, x;
  964. X    int inp;
  965. X
  966. X    hi_lite(stdscr,dir_ent[0],col+10,row+row_off);
  967. X    for(;;){
  968. X    switch(inp = get_input()){
  969. X       case 'n':            /* Go to next page        */
  970. X       case 'N':
  971. X           if(number > end){
  972. X             start += 45;
  973. X             clr_area(stdscr,2,2,2,76);
  974. X             clr_area(stdscr,3,2,dp->max_row,dp->max_col+5);
  975. X             end = print_dir(dir_ent,start,number,end,dp);
  976. X             row = col = 0;
  977. X             move_entry(dir_ent,row,col,row_off,start,1);
  978. X           }
  979. X       break;
  980. X       case 'p':            /* Go to the previous page    */
  981. X          case 'P':
  982. X           if(start >= 45){
  983. X                  start -= 45;
  984. X             clr_area(stdscr,2,2,2,76);
  985. X             clr_area(stdscr,3,2,dp->max_row,dp->max_col+5);
  986. X             end = print_dir(dir_ent,start,number,end-45,dp);
  987. X             row = col = 0;
  988. X             move_entry(dir_ent,row,col,row_off,start,1);
  989. X           }
  990. X       break;
  991. X       case 'j':            /* Move the hi-lite bar down     */
  992. X       case 'J':
  993. X       case DOWN:
  994. X           if(row != 14){
  995. X             move_entry(dir_ent,row,col,row_off,start,0);
  996. X             row++;
  997. X             move_entry(dir_ent,row,col,row_off,start,1);
  998. X           }
  999. X       break;
  1000. X       case 'k':            /* Move The hi-lite bar up    */
  1001. X       case 'K':
  1002. X       case UP:
  1003. X           if(row != 0){
  1004. X             move_entry(dir_ent,row,col,row_off,start,0);
  1005. X             row--;
  1006. X             move_entry(dir_ent,row,col,row_off,start,1);
  1007. X        }
  1008. X       break;
  1009. X       case 'l':            /* Move The hi-lite bar Right    */
  1010. X       case 'L':
  1011. X       case RIGHT:
  1012. X           if(col < 40){
  1013. X             move_entry(dir_ent,row,col,row_off,start,0);
  1014. X             col += 20;
  1015. X             move_entry(dir_ent,row,col,row_off,start,1);
  1016. X        }
  1017. X       break;
  1018. X       case 'h':            /* Move The hi-lite bar Left    */
  1019. X       case 'H':
  1020. X       case LEFT:
  1021. X           if(col != 0){
  1022. X             move_entry(dir_ent,row,col,row_off,start,0);
  1023. X             col -= 20;
  1024. X             move_entry(dir_ent,row,col,row_off,start,1);
  1025. X        }
  1026. X       break;
  1027. X       case LF:            /* Make a selection        */
  1028. X       case RETURN:
  1029. X           if(col == 0)
  1030. X             x = ((col%14))+row+start;
  1031. X           else
  1032. X             x = (((col/15)*15))+row+start;
  1033. X           if(strlen(dir_ent[x]) >= 1){
  1034. X             clr_area(stdscr,2,2,2,76);
  1035. X             clr_area(stdscr,3,2,dp->max_row,dp->max_col+5);
  1036. X             clr_area(stdscr,20,38,1,38);
  1037. X             return(dir_ent[x]);
  1038. X            }else{
  1039. X             clr_area(stdscr,2,2,2,76);
  1040. X             clr_area(stdscr,3,2,dp->max_row,dp->max_col+5);
  1041. X             clr_area(stdscr,20,38,1,38);
  1042. X             return(NULL);
  1043. X           }
  1044. X       break;
  1045. X       case QUIT_KEY:        /* Do Not make a selection    */
  1046. X            clr_area(stdscr,2,2,2,76);
  1047. X            clr_area(stdscr,3,2,dp->max_row,dp->max_col+5);
  1048. X            clr_area(stdscr,20,38,1,38);
  1049. X            return(NULL);
  1050. X       break;
  1051. X       default:
  1052. X       break;
  1053. X    }
  1054. X     }
  1055. X}
  1056. X
  1057. X/*    
  1058. X *    int read_printers(printers)
  1059. X *    
  1060. X *    Parameters:    printers - A list of printers read from file.
  1061. X *    
  1062. X *    Purpose:    Read printer info. from a file (PRINT_PATH).
  1063. X *
  1064. X *    Returns:    -1    = Failure.
  1065. X *            index = The number of printers defined.
  1066. X *
  1067. X *    Last Modify:    3-31-91 (TW)
  1068. X */
  1069. X
  1070. Xint read_printers(printers)
  1071. Xprinter printers[MAX_PRINTERS];
  1072. X{
  1073. X    FILE *fp;
  1074. X    int index = 0;
  1075. X    char buff[256];
  1076. X    
  1077. X    if((fp = fopen(PRINT_PATH,"r")) == (FILE *)NULL){
  1078. X       return(-1);
  1079. X    }else{
  1080. X       while(!feof(fp)){
  1081. X         Fgets(buff,256,fp);
  1082. X         if(buff[strlen(buff)-1] == LF)
  1083. X           buff[strlen(buff)-1] = NULL;
  1084. X         if(strlen(buff) > 31)
  1085. X           buff[31] = NULL;
  1086. X         if(!feof(fp) && (index < MAX_PRINTERS)){
  1087. X            switch(buff[0]){
  1088. X           case '?':        /* Text comment user sees */
  1089. X            memccpy(printers[index].comment,buff+2,NULL,30);
  1090. X           break;
  1091. X           case '*':        /* Printing Commmand      */
  1092. X            memccpy(printers[index].command,buff+2,NULL,30);
  1093. X            index++;
  1094. X           break;
  1095. X           default:
  1096. X           break;
  1097. X        }
  1098. X         }
  1099. X    }
  1100. X    fclose(fp);
  1101. X    }
  1102. X    return(index);    /* Return Count */
  1103. X}
  1104. X
  1105. X/*
  1106. X *    show_printers(printers,num)
  1107. X *
  1108. X *    Parameters:    printers - A list of printers read from file.
  1109. X *            num      - The Number of printers read.
  1110. X *
  1111. X *    Purpose:    Print The Printer selections on the screen.
  1112. X *
  1113. X *    Returns:    None
  1114. X *
  1115. X *    Last Modify:    3-31-91 (TW);
  1116. X */
  1117. X
  1118. Xvoid show_printers(printers,num)
  1119. Xprinter printers[MAX_PRINTERS];
  1120. Xint num;
  1121. X{
  1122. X    int i, row = 6;
  1123. X
  1124. X    for(i=0;i<num;i++){
  1125. X      if(!isposodd(i))
  1126. X        my_print(stdscr,printers[i].comment,5,row);
  1127. X      else{
  1128. X        my_print(stdscr,printers[i].comment,45,row);
  1129. X        row++;
  1130. X      }
  1131. X    }
  1132. X}
  1133. X
  1134. X/*
  1135. X *    char *choose_print(string)
  1136. X *
  1137. X *    Parameters:    string - The file to be printed.
  1138. X *    
  1139. X *    Purpose:    Allow User to choose a printer.
  1140. X *
  1141. X *    Returns:    A pointer to the printer string.
  1142. X *
  1143. X *    Last Modify:    3-31-91 (TW)
  1144. X */
  1145. X
  1146. Xchar *choose_print(string)
  1147. Xchar *string;
  1148. X{
  1149. X    printer printers[MAX_PRINTERS];
  1150. X    int i = 0, row = 0, col = 1, num,ans,max;
  1151. X    char buffer[256];
  1152. X
  1153. X    if((num = read_printers(printers)) == -1){
  1154. X      hi_lite(stdscr,"Error reading printer file, Press a key.",5,2);
  1155. X      my_getchar();
  1156. X      return(NULL);
  1157. X    }
  1158. X    show_printers(printers,num);
  1159. X    hi_lite(stdscr,PRT_MENU,5,2);
  1160. X    (void) sprintf(buffer,"Filename: %s",string);
  1161. X    hi_lite(stdscr,buffer,5,4);
  1162. X    hi_lite(stdscr,printers[i].comment,5,6);
  1163. X    do{
  1164. X      switch(ans = get_input()){
  1165. X         case 'j':            /* Move Hi-Lite Bar down    */
  1166. X         case 'J':
  1167. X         case DOWN:
  1168. X          if(col == 1)
  1169. X            max = in_col_one(num);
  1170. X          else
  1171. X            max = in_col_two(num);
  1172. X          if(row+1 < max){
  1173. X            if(col == 1)
  1174. X              my_print(stdscr,printers[i].comment,5,row+6);
  1175. X              else
  1176. X              my_print(stdscr,printers[i].comment,45,row+6);
  1177. X            i+=2;
  1178. X                row++;
  1179. X            if(col == 1)
  1180. X              hi_lite(stdscr,printers[i].comment,5,row+6);
  1181. X            else
  1182. X              hi_lite(stdscr,printers[i].comment,45,row+6);
  1183. X          }
  1184. X         break;
  1185. X         case 'k':            /* Move Hi-Lite Bar up      */
  1186. X         case 'K':
  1187. X         case UP:
  1188. X          if(row >= 1){
  1189. X            if(col == 1)
  1190. X              my_print(stdscr,printers[i].comment,5,row+6);
  1191. X              else
  1192. X              my_print(stdscr,printers[i].comment,45,row+6);
  1193. X            i-=2;
  1194. X              row--;
  1195. X            if(col == 1)
  1196. X              hi_lite(stdscr,printers[i].comment,5,row+6);
  1197. X            else
  1198. X              hi_lite(stdscr,printers[i].comment,45,row+6);
  1199. X          }
  1200. X         break;
  1201. X         case 'l':            /* Move Hi-Lite Bar right    */
  1202. X         case 'L':
  1203. X         case RIGHT:
  1204. X             if(col == 1 && ((i + 1) < num)){
  1205. X            my_print(stdscr,printers[i].comment,5,row+6);
  1206. X            col++;
  1207. X            i++;
  1208. X            hi_lite(stdscr,printers[i].comment,45,row+6);
  1209. X              }
  1210. X         break;
  1211. X         case 'h':            /* Move Hi-Lite Bar left    */
  1212. X         case 'H':
  1213. X         case LEFT:
  1214. X             if(col > 1){
  1215. X            my_print(stdscr,printers[i].comment,45,row+6);
  1216. X            col--;
  1217. X            i--;
  1218. X            hi_lite(stdscr,printers[i].comment,5,row+6);
  1219. X          }
  1220. X         break;
  1221. X         case RETURN:
  1222. X         case LF:
  1223. X              return(printers[i].command);
  1224. X         break;
  1225. X         case QUIT_KEY:
  1226. X              return(NULL);
  1227. X         break;
  1228. X      }
  1229. X    }while(ans != QUIT_KEY);
  1230. X    return(NULL);
  1231. X}
  1232. X
  1233. X/*
  1234. X *    char *do_selection()
  1235. X *    
  1236. X *    Parameters:    None
  1237. X *    
  1238. X *    Purpose:    Control module for selecting a file.
  1239. X *
  1240. X *    Returns:    The Selected File Name.
  1241. X *
  1242. X *    Last Modify:    3-31-91 (TW)
  1243. X */
  1244. X
  1245. Xchar *do_selection()
  1246. X{
  1247. X    extern WINDOW *inside_window;
  1248. X    char dir_entries[MAX_ENT][ENT_LEN];
  1249. X    int start_ent = 0, num = 0, end = 0;
  1250. X    char *strng, buff[256];
  1251. X    dir_info *dp;
  1252. X
  1253. X    dp = (dir_info *) malloc(sizeof(dir_info));
  1254. X# if !defined (HPUX) && !defined (USE_CWD)
  1255. X    (void) getwd(buff);
  1256. X# else
  1257. X    (void) getcwd(buff,BUF_SIZ);
  1258. X# endif HPUX && USE_CWD
  1259. X    if((num = get_dir(dir_entries,buff)) == -1 || num == 0)
  1260. X          return(NULL);
  1261. X    end = print_dir(dir_entries,start_ent,num,45,dp);
  1262. X    strng = select_item(dir_entries,num,start_ent,end,dp);
  1263. X    return(strng);
  1264. X}
  1265. X
  1266. X/*
  1267. X *    do_printers()
  1268. X *    
  1269. X *    Parameters:    None
  1270. X *    
  1271. X *    Purpose:    Control module for  printing a file
  1272. X *
  1273. X *    Returns:    None.
  1274. X *
  1275. X *    Last Modify:    3-31-91 (TW)
  1276. X */
  1277. X
  1278. Xvoid do_printers()
  1279. X{
  1280. X    char *strng1, *strng2;
  1281. X    char buff[256];
  1282. X
  1283. X    hi_lite(stdscr,"           ",68,STATUS_LINE);
  1284. X    strng1 = do_selection();
  1285. X    if(strng1 != NULL){
  1286. X      strng2 = choose_print(strng1);
  1287. X      if(strng2 != NULL){
  1288. X         Sprintf(buff,"%s %s",strng2,strng1);
  1289. X         exec_cshell(buff,CONTINUE);    
  1290. X      }else{
  1291. X         clr_area(stdscr,3,2,19,73);
  1292. X      }
  1293. X    }
  1294. X    hi_lite(stdscr,CMD_LIN,68,STATUS_LINE);
  1295. X}
  1296. END_OF_FILE
  1297.   if test 13211 -ne `wc -c <'MENU/dir.c'`; then
  1298.     echo shar: \"'MENU/dir.c'\" unpacked with wrong size!
  1299.   fi
  1300.   # end of 'MENU/dir.c'
  1301. fi
  1302. if test -f 'MENU/files.c' -a "${1}" != "-c" ; then 
  1303.   echo shar: Will not clobber existing file \"'MENU/files.c'\"
  1304. else
  1305.   echo shar: Extracting \"'MENU/files.c'\" \(4026 characters\)
  1306.   sed "s/^X//" >'MENU/files.c' <<'END_OF_FILE'
  1307. X# define    __FILES_C
  1308. X
  1309. X# include "config.h"
  1310. X# include "proto.h"
  1311. X# include <stdio.h>
  1312. X# include <sys/file.h>
  1313. X# include <curses.h>
  1314. X# include "menu.h"
  1315. X
  1316. X/*    PSC MENU COPYRIGHT NOTICE
  1317. X
  1318. X    Part of PSCMenu
  1319. X
  1320. X    This software is to be considered to be public domain, it
  1321. Xmay be copied, modified and parts of it may be used in other programs
  1322. Xas long as this copyright notice remains intact.
  1323. X
  1324. X    Copyright()   PSC - Plymouth State College
  1325. X    Written by:   Ted Wisniewski 12-9-1990
  1326. X*/
  1327. X
  1328. X/*
  1329. X *    int check_file(instring)
  1330. X *
  1331. X *    Parameters:    instring - The Name of the file to be accessed.
  1332. X *
  1333. X *    Returns:    -1  = Failure, file may not exist.
  1334. X *            1   = File is Readable.
  1335. X *
  1336. X *     Purpose:    Determine if a file is readable.
  1337. X *
  1338. X *    Last Modify:    3-31-91 (TW)
  1339. X */
  1340. Xint check_file(instring)
  1341. Xchar *instring;
  1342. X{
  1343. X    if(strlen(instring) > 0){
  1344. X      if((access(instring,R_OK)) == -1)
  1345. X        return(-1);
  1346. X      else
  1347. X        return(1);
  1348. X    }else
  1349. X      return(-1);
  1350. X}
  1351. X
  1352. X/*
  1353. X *    read_menu(menu,file_name,num)
  1354. X *
  1355. X *    Parameters:    menu         - Pointer to the menu to be loaded.
  1356. X *            file_name    - Name of the menu file.
  1357. X *            num         - The number of menu entries read.
  1358. X *
  1359. X *    Returns:    None.
  1360. X *
  1361. X *    Purpose:    Read a menu from file information.
  1362. X *    
  1363. X *    Last Modify:    3-31-91 (TW)
  1364. X */
  1365. X
  1366. Xvoid read_menu(menu,file_name,num)
  1367. Xmenu_ent *menu;
  1368. Xchar *file_name;
  1369. Xint *num;
  1370. X{
  1371. X    FILE *fp;
  1372. X    int index = 0, max_item = 7;
  1373. X    int flag = FALSE;
  1374. X    char buff[256];
  1375. X    
  1376. X    if(menu->key == LOAD_MAIN)
  1377. X       m_flag = TRUE;
  1378. X    else
  1379. X       m_flag = FALSE;
  1380. X    Sprintf(buff,"%s%s",menu_dir,file_name);
  1381. X    if((access(buff,R_OK|F_OK)) == -1){
  1382. X       hi_lite(stdscr,"Menu file cannot be accessed.",26,11);
  1383. X       continue_it(20);
  1384. X       erase_line(stdscr,26,11,30);
  1385. X    }else{
  1386. X       fp = fopen(buff,"r");
  1387. X       while(!feof(fp)){
  1388. X          Fgets(buff,256,fp);
  1389. X          rm_lf(buff);
  1390. X          if(!feof(fp) && (index <= max_item)){
  1391. X        switch (buff[0]){
  1392. X          case HEAD_COMP:    /* Compressed Header */
  1393. X            max_item = 14;
  1394. X            menu[index].cflag = TRUE;
  1395. X            menu[index].key = buff[0];
  1396. X            Strcpy(menu[index].desc,buff+2);
  1397. X            index++;
  1398. X          break;
  1399. X          case HEAD_SCRN:    /* Menu Header */
  1400. X            menu[index].cflag = FALSE;
  1401. X            menu[index].key = buff[0];
  1402. X            Strcpy(menu[index].desc,buff+2);
  1403. X            index++;
  1404. X          break;
  1405. X          case ITEM_CMNT:     /* Menu Comment (User sees)     */
  1406. X            Strcpy(menu[index].desc,buff+2);
  1407. X            chop_str(menu[index].desc,36);
  1408. X            if(flag == TRUE){
  1409. X              index++;
  1410. X              flag = FALSE;
  1411. X            }
  1412. X          break;
  1413. X          case HELP_FILE:    /* Help file name         */
  1414. X            Strcpy(menu[index].help_fil,buff+2);
  1415. X            flag = TRUE;
  1416. X          break;
  1417. X          case EXEC_PIPE:    /* Exec in pipe            */
  1418. X            menu[index].key = buff[0];
  1419. X            Strcpy(menu[index].cmd,buff+2);
  1420. X            flag = TRUE;
  1421. X          break;
  1422. X          case OPTN_CHSE:
  1423. X            menu[index].key = buff[0];
  1424. X            Strcpy(menu[index].cmd,buff+2);
  1425. X            flag = TRUE;
  1426. X          break;
  1427. X          case EXEC_NCNT:    /* '%' Do not use continue line  */
  1428. X          case EXEC_CONT:    /* This command to be executed   */
  1429. X                    /* in a sub-shell. Use Continue  */
  1430. X            menu[index].key = buff[0];
  1431. X            Strcpy(menu[index].cmd,buff+2);
  1432. X            flag = TRUE;
  1433. X          break;
  1434. X          case LOAD_MAIN:    /* This Menu is a main Menu      */
  1435. X          case LOAD_MENU:    /* This Menu is a regular Menu.  */
  1436. X            menu[index].key = buff[0];
  1437. X            Strcpy(menu[index].cmd,buff+2);
  1438. X            flag = TRUE;
  1439. X          break;
  1440. X          case FILE_ASK1:    /* Ask for a file name        */
  1441. X            menu[index].key = buff[0];
  1442. X            Strcpy(menu[index].cmd,buff+2);
  1443. X            flag = TRUE;
  1444. X          break;
  1445. X          case FILE_ASK2:    /* Ask for two file Names    */
  1446. X            menu[index].key = buff[0];
  1447. X            Strcpy(menu[index].cmd,buff+2);
  1448. X            flag = TRUE;
  1449. X          break;
  1450. X          case ASKS_USER:    /* Ask Whom            */
  1451. X            menu[index].key = buff[0];
  1452. X            Strcpy(menu[index].cmd,buff+2);
  1453. X            flag = TRUE;
  1454. X          break;
  1455. X          case ASKS_WHAT:    /* Ask what?            */
  1456. X            menu[index].key = buff[0];
  1457. X            Strcpy(menu[index].cmd,buff+2);
  1458. X            flag = TRUE;
  1459. X          break;
  1460. X          case VISL_SHLL:    /* Use visual directory in shell */
  1461. X            menu[index].key = buff[0];
  1462. X            Strcpy(menu[index].cmd,buff+2);
  1463. X            flag = TRUE;
  1464. X          break;
  1465. X          case VISL_PIPE:    /* Use visual in pipe        */
  1466. X            menu[index].key = buff[0];
  1467. X            Strcpy(menu[index].cmd,buff+2);
  1468. X            flag = TRUE;
  1469. X          break;
  1470. X          default:
  1471. X          break;
  1472. X        }
  1473. X          }
  1474. X        }
  1475. X    (void) fclose(fp);
  1476. X    *num = index;
  1477. X    }
  1478. X}
  1479. END_OF_FILE
  1480.   if test 4026 -ne `wc -c <'MENU/files.c'`; then
  1481.     echo shar: \"'MENU/files.c'\" unpacked with wrong size!
  1482.   fi
  1483.   # end of 'MENU/files.c'
  1484. fi
  1485. if test -f 'MENU/menu.c' -a "${1}" != "-c" ; then 
  1486.   echo shar: Will not clobber existing file \"'MENU/menu.c'\"
  1487. else
  1488.   echo shar: Extracting \"'MENU/menu.c'\" \(8561 characters\)
  1489.   sed "s/^X//" >'MENU/menu.c' <<'END_OF_FILE'
  1490. X# define    __MENU_C
  1491. X
  1492. X# include "config.h"
  1493. X# include "proto.h"
  1494. X# include "menu.h"
  1495. X
  1496. X# include <sys/file.h>
  1497. X# include <sys/ioctl.h>
  1498. X# include <sys/wait.h>
  1499. X
  1500. X# ifdef HPUX
  1501. X# include <sys/bsdtty.h>
  1502. X# endif HPUX
  1503. X
  1504. X/*    PSC MENU COPYRIGHT NOTICE
  1505. X
  1506. X    Part of PSCMenu
  1507. X
  1508. X    This software is to be considered to be public domain, it
  1509. Xmay be copied, modified and parts of it may be used in other programs
  1510. Xas long as this copyright notice remains intact.
  1511. X
  1512. X    Copyright()   PSC - Plymouth State College
  1513. X    Written by:   Ted Wisniewski 12-9-1990
  1514. X*/
  1515. X
  1516. X/*****************************************************************************
  1517. X Erase a line within the Menu Window.
  1518. X *****************************************************************************/
  1519. X
  1520. Xvoid erase_line(window_name,x,y,length)
  1521. XWINDOW *window_name;
  1522. Xint x,y,length;
  1523. X{
  1524. X    int i;
  1525. X
  1526. X    for(i=0;i<=length;i++)
  1527. X        line[i] = SPACE;
  1528. X    line[i+1] = NULL;
  1529. X    my_print(window_name,line,x,y);
  1530. X}
  1531. X
  1532. X/**************************************************************************
  1533. X Request input from the user as to whether he/she wishes to continue.
  1534. X This routine gives the option to stop seeing output.
  1535. X **************************************************************************/
  1536. X
  1537. Xint cont_it()
  1538. X{
  1539. X    char c;
  1540. X
  1541. X    hi_lite(stdscr,"Press space to continue or \'q\' to stop.",20,CONT_LINE);
  1542. X    c = my_getchar(stdscr);
  1543. X    while(c != QUIT_KEY && c != SPACE)
  1544. X       c = my_getchar(stdscr);
  1545. X    erase_line(stdscr,20,CONT_LINE,45);
  1546. X    if(c == QUIT_KEY)
  1547. X       return 1;
  1548. X    else
  1549. X       return 0;
  1550. X}
  1551. X
  1552. X/**************************************************************************
  1553. X Request input from the user as to whether he/she wishes to continue.
  1554. X **************************************************************************/
  1555. X
  1556. Xvoid continue_it(line_num)
  1557. Xint line_num;
  1558. X{
  1559. X    hi_lite(stdscr,"Press a space to Continue.",27,line_num);
  1560. X    while(my_getchar(stdscr) != SPACE);
  1561. X    erase_line(stdscr,27,line_num,45);
  1562. X}
  1563. X
  1564. X/*****************************************************************************
  1565. X Clear an Area in the Menu Window.
  1566. X *****************************************************************************/
  1567. X
  1568. Xvoid clr_area(window,st_y,st_x,n_line,length)
  1569. XWINDOW *window;
  1570. Xint st_y,st_x,n_line,length;
  1571. X{
  1572. X    int i;
  1573. X
  1574. X    for(i=0;i<=length;i++)
  1575. X      line[i] = SPACE;
  1576. X    line[i+1] = NULL;
  1577. X    for(i=(st_y-1);i<(n_line+st_y);i++)
  1578. X       my_print(stdscr,line,st_x,i);
  1579. X}
  1580. X
  1581. X/**************************************************************************
  1582. X Print output to the Menu Window,  when done clear the Window.
  1583. X **************************************************************************/
  1584. X
  1585. Xvoid print_output(output,number,length)
  1586. Xchar output[FOURK][80];
  1587. Xint number, length;
  1588. X{
  1589. X    int i, k = 4, left;
  1590. X
  1591. X    left = number;
  1592. X    for(i=1;i<number;++i){
  1593. X       my_print(inside_window,output[i],5,k);
  1594. X       k++;
  1595. X       if(i%15 == 14){
  1596. X         left -= 15;
  1597. X         if(cont_it() == 1){
  1598. X            clr_area(stdscr,5,4,(k-4),length+2);
  1599. X            return;
  1600. X         }
  1601. X         move_csr(inside_window,5,4);
  1602. X         k = 4;
  1603. X       }
  1604. X    }
  1605. X    clear_to_bot(inside_window);
  1606. X
  1607. X    if(left < 15)
  1608. X      clr_area(stdscr,5+left,5,(15-left),length+2);
  1609. X
  1610. X    continue_it(CONT_LINE);
  1611. X    clr_area(stdscr,5,4,(k-4),length+2);
  1612. X}
  1613. X
  1614. X/*****************************************************************************
  1615. X    Execute a process and have the output read into a buffer and then
  1616. X    print it to the screen.
  1617. X *****************************************************************************/
  1618. X
  1619. Xvoid exec_pipe(comline)
  1620. Xchar *comline;
  1621. X{
  1622. X    char inbuf[LINESZ], list[FOURK][80];
  1623. X    FILE *f, *popen();
  1624. X    int num = 1, length = 0;
  1625. X
  1626. X    my_print(inside_window,"Working...",5,1);
  1627. X    if((f = popen(comline,"r")) == NULL){
  1628. X       Strcpy(list[0],"Command not found");
  1629. X    }else
  1630. X       while(fgets(inbuf,LINESZ,f) != NULL){
  1631. X          rm_lf(inbuf);
  1632. X          if(strlen(inbuf) > MAXCOLINWIN)
  1633. X            chop_str(inbuf,MAXCOLINWIN);
  1634. X          else
  1635. X            pad_str(inbuf);
  1636. X          Strcpy(list[num],inbuf);
  1637. X          if(strlen(inbuf) > length)
  1638. X        length = strlen(inbuf);
  1639. X          num++;
  1640. X       }
  1641. X       clr_area(stdscr,2,5,1,15);
  1642. X       print_output(list,num,length);
  1643. X    Pclose(f);
  1644. X    clear_window(inside_window);
  1645. X}
  1646. X
  1647. X/*****************************************************************************
  1648. X Print The current working directory at the bottom of the screen.
  1649. X *****************************************************************************/
  1650. X
  1651. Xvoid prt_curdir()
  1652. X{
  1653. X# if !defined (HPUX) && !defined (USE_CWD)
  1654. X    char direct[BUF_SIZ], *getwd();
  1655. X# else
  1656. X      char direct[BUF_SIZ], *getcwd();
  1657. X# endif HPUX && USE_CWD
  1658. X    int i;
  1659. X
  1660. X    hi_lite(stdscr,"Directory:",0,STATUS_LINE);
  1661. X# if !defined (HPUX) && !defined (USE_CWD)
  1662. X    Getwd(direct);
  1663. X# else
  1664. X      Getwd(direct,BUF_SIZ);
  1665. X# endif HPUX && USE_CWD
  1666. X    if(strlen(direct) < 40)
  1667. X       for(i=strlen(direct);i<=40;i++)
  1668. X          Strcat(direct," ");
  1669. X    else
  1670. X       for(i=40;i<=80;i++)
  1671. X             direct[i] = NULL;
  1672. X    hi_lite(stdscr,direct,12,STATUS_LINE);
  1673. X}
  1674. X
  1675. X/*****************************************************************************
  1676. X Draw borders and print Header on the screen.
  1677. X *****************************************************************************/
  1678. X
  1679. Xvoid setup_screen()
  1680. X{
  1681. X    inside_window = newwin(21,78,1,1);
  1682. X    help_window = newwin(17,30,3,25);
  1683. X    clear_window(stdscr);        /* Clear screen routine             */
  1684. X    box_screen(HEADER);
  1685. X    hi_lite(stdscr,CMD_LIN,68,STATUS_LINE);
  1686. X    prt_curdir();
  1687. X# ifdef PRINT_TIME
  1688. X    print_time();
  1689. X# endif
  1690. X}
  1691. X
  1692. X/*****************************************************************************
  1693. X Execute a shell command.  Output does not come to back to the window.
  1694. X *****************************************************************************/
  1695. X
  1696. Xvoid exec_cshell(command,flag)
  1697. Xchar *command;
  1698. Xint flag;
  1699. X{
  1700. X# ifdef PRINT_TIME
  1701. X    unset_alarm();
  1702. X# endif
  1703. X    clear_window(stdscr);
  1704. X    unset_modes(); 
  1705. X    if(fork() == 0){
  1706. X      Execl("/bin/csh","csh","-c",command,0);
  1707. X    }else
  1708. X      Wait((int *)0);
  1709. X    setup_modes();
  1710. X    if(flag)
  1711. X      continue_it(LAST_LINE);
  1712. X    setup_screen();
  1713. X# ifdef PRINT_TIME
  1714. X    set_alarm();
  1715. X# endif
  1716. X}
  1717. X
  1718. X/*****************************************************************************
  1719. X Make sure Output goes to the screen and terminal is capable of running
  1720. X menu.
  1721. X *****************************************************************************/
  1722. X
  1723. Xvoid initialize()
  1724. X{
  1725. X    int term;
  1726. X
  1727. X    if(!isatty(1)){
  1728. X       Fprintf(stderr,"Sorry, Cannot output to the screen (exiting).\n");
  1729. X       exit(4);
  1730. X    }
  1731. X    if((term = get_term()) == -1){
  1732. X       Fprintf(stderr,"Sorry, Bad termcap entry (exiting).\n");
  1733. X       exit(4);
  1734. X    }
  1735. X    setup_modes();
  1736. X}
  1737. X
  1738. Xint main(argc,argv)
  1739. Xint argc;
  1740. Xchar *argv[];
  1741. X{
  1742. X    int *num;
  1743. X
  1744. X        /************************************************************
  1745. X        If More than two arguments are supplied print the
  1746. X        Usage statement.
  1747. X         ************************************************************/
  1748. X    if(argc > 2){
  1749. X      Fprintf(stderr,"Usage: menu\n");
  1750. X      Fprintf(stderr,"Usage: menu [menu_directory]\n");
  1751. X      exit(0);
  1752. X    }else{
  1753. X        /************************************************************
  1754. X        If there are no additional arguments Use the default
  1755. X        Menu directory.
  1756. X         ************************************************************/
  1757. X      if(argc == 1)
  1758. X         Strcpy(menu_dir,MENU_DIR);
  1759. X      else
  1760. X        /************************************************************
  1761. X        See if the directory name ends in a '/' if not add
  1762. X        one.
  1763. X         ************************************************************/
  1764. X        if(argc == 2){
  1765. X           Strcpy(menu_dir,argv[1]);
  1766. X           check_dirname(menu_dir);
  1767. X           if(menu_dir[strlen(menu_dir)-1] != SLASH)
  1768. X              Strcat(menu_dir,"/");
  1769. X        }
  1770. X        Sprintf(buffer,"%s%s",menu_dir,MAIN_MENU);
  1771. X        /************************************************************
  1772. X            Check to make sure the menu directory is Read-able and
  1773. X        executeable
  1774. X         ************************************************************/
  1775. X        if(access(menu_dir,R_OK|X_OK)){
  1776. X           Fprintf(stderr,"Directory :%s: is not accessable ",menu_dir);
  1777. X           Fprintf(stderr,"or does not exist.\n");
  1778. X           exit(1);
  1779. X        }
  1780. X        /************************************************************
  1781. X            Check to see if the main menu file exists, if it does 
  1782. X            not exist, exit the program.
  1783. X         ************************************************************/
  1784. X        if(access(buffer,F_OK)){
  1785. X           Fprintf(stderr,"Menu files do not exist in %s.\n",menu_dir);
  1786. X           (void) exit(2);
  1787. X        }
  1788. X    }
  1789. X    if(getuid() != 0)
  1790. X# ifndef SYSTEM_FIVE            /* Need to prevent ctrl-z in apps */
  1791. X      (void) setpgrp(getpid(),0);
  1792. X# else
  1793. X      (void) setpgrp();
  1794. X# endif SYSTEM_FIVE
  1795. X
  1796. X    initialize();        
  1797. X# ifdef PRINT_TIME
  1798. X    set_alarm();
  1799. X# endif
  1800. X    setup_screen();
  1801. X    setup_sigs();
  1802. X    main_menu->key = LOAD_MAIN;        /* We start in main menu */
  1803. X    (void) read_menu(main_menu,MAIN_MENU,&num);
  1804. X    disp_menu(main_menu,num);
  1805. X    Fflush(stdin);
  1806. X    do_menu(main_menu,num);
  1807. X    return(0);
  1808. X}
  1809. END_OF_FILE
  1810.   if test 8561 -ne `wc -c <'MENU/menu.c'`; then
  1811.     echo shar: \"'MENU/menu.c'\" unpacked with wrong size!
  1812.   fi
  1813.   # end of 'MENU/menu.c'
  1814. fi
  1815. if test -f 'MENU/menu.h' -a "${1}" != "-c" ; then 
  1816.   echo shar: Will not clobber existing file \"'MENU/menu.h'\"
  1817. else
  1818.   echo shar: Extracting \"'MENU/menu.h'\" \(3520 characters\)
  1819.   sed "s/^X//" >'MENU/menu.h' <<'END_OF_FILE'
  1820. X/*    PSC MENU COPYRIGHT NOTICE
  1821. X
  1822. X    Part of PSCMenu
  1823. X
  1824. X    This software is to be considered to be public domain, it
  1825. Xmay be copied, modified and parts of it may be used in other programs
  1826. Xas long as this copyright notice remains intact.
  1827. X
  1828. X    Copyright()   PSC - Plymouth State College
  1829. X    Written by:   Ted Wisniewski 12-9-1990
  1830. X*/
  1831. X
  1832. X# ifndef __MENU_H
  1833. X# define __MENU_H
  1834. X
  1835. X# include <stdio.h>
  1836. X# include <stdlib.h>
  1837. X# include <strings.h>
  1838. X# include <ctype.h>
  1839. X# include <sys/types.h>
  1840. X# include <sys/ioctl.h>
  1841. X# include <unistd.h>
  1842. X# include <curses.h>
  1843. X
  1844. X# define     FOURK        4096
  1845. X# define     ONEK        1024
  1846. X# define    BUF_SIZ        256
  1847. X# define    LINESZ        90
  1848. X# define    MAXCOLINWIN    70
  1849. X# define     FIRST_LINE    0
  1850. X# define    STATUS_LINE    22
  1851. X# define    NUMCOL        22
  1852. X# define    DESCOL        25
  1853. X# define     LAST_LINE    23
  1854. X# define     CONT_LINE    21
  1855. X# define     N_ENTRIES    16
  1856. X# define    COLON        ':'
  1857. X# define    DOT        '.'
  1858. X# define    TILD        '~'
  1859. X# define    SLASH        '/'
  1860. X# define    ASTER        '*'
  1861. X# define     MAIN_MENU    "main.menu"
  1862. X
  1863. X/*
  1864. X    User typed keystrokes.
  1865. X*/
  1866. X
  1867. X# define     RE_DRAW        ('r' & 037)
  1868. X# define    RETURN        '\r'
  1869. X# define    LF        '\n'
  1870. X# define    SPACE        ' '
  1871. X# define    CHANGE_DIR    'C'
  1872. X# define    SHORT_DIR    'D'
  1873. X# define    HELP        'h'
  1874. X# define    HELP_KEY    'h'
  1875. X# define    LONG_DIR    'l'
  1876. X# define    LOGOUT        'L'
  1877. X# define    TO_MAIN        'm'
  1878. X# define    PREV_MENU    'p'
  1879. X# define    DO_PRINT    'P'
  1880. X# define    QUIT_KEY    'q'
  1881. X# define    EXEC_COMM    'x'
  1882. X
  1883. X/*
  1884. X    MENU file keys + meanings.
  1885. X*/
  1886. X
  1887. X# define    HEAD_COMP    '!'    /* Screen header (Compressed)    */
  1888. X# define    HEAD_SCRN    '$'    /* Menu screen header         */
  1889. X# define    ITEM_CMNT    '?'    /* Item Comment            */
  1890. X# define    HELP_FILE    '#'    /* Item Help file        */
  1891. X# define    EXEC_PIPE    '+'    /* Exec in pipe               */
  1892. X# define    OPTN_CHSE    '-'    /* Choose Option?        */
  1893. X# define    EXEC_NCNT    '%'    /* Exec in subshell, no cont.    */
  1894. X# define    EXEC_CONT    '*'    /* Exec in subshell, continue?     */
  1895. X# define    LOAD_MAIN    '@'    /* Load a top level menu    */
  1896. X# define    LOAD_MENU    '&'    /* Load specified menu file     */
  1897. X# define    FILE_ASK1    '1'    /* Ask for filename, subshell    */
  1898. X# define    FILE_ASK2    '2'    /* Ask for two files, subshell    */
  1899. X# define    ASKS_USER    '3'    /* Ask for a username, subshell */
  1900. X# define    ASKS_WHAT    '4'    /* Ask for a topic, subshell    */
  1901. X# define    VISL_SHLL    '5'    /* Use visual directory, subshll*/
  1902. X# define    VISL_PIPE    '6'    /* Use visual directory, pipe    */
  1903. X
  1904. X#ifndef TRUE
  1905. X# define    TRUE        1
  1906. X# define    FALSE        0
  1907. X#endif TRUE
  1908. X
  1909. X# define     CENTER        40
  1910. X/*# define     HEADER        "Plymouth State College Menu System"*/
  1911. X# define     HEADER        "PSC Menu System"
  1912. X# define    CMD_LIN        "h)elp q)uit"
  1913. X# define    CONTINUE    1
  1914. X# define    NO_CONTINUE    0
  1915. X# define    TIME_OUT    60
  1916. X# define    OFF        0
  1917. X
  1918. X# define     Sprintf        (void) sprintf
  1919. X# define    Strcpy        (void) strcpy
  1920. X# define    Strcat        (void) strcat
  1921. X# define    Fprintf        (void) fprintf
  1922. X# define    Fflush        (void) fflush
  1923. X# define    Fputc        (void) fputc
  1924. X# define    Fputs        (void) fputs
  1925. X# define    Fgets        (void) fgets
  1926. X# define    Pclose        (void) pclose
  1927. X
  1928. X# if !defined (HPUX) && ! defined (USE_CWD)
  1929. X#   define    Getwd        (void) getwd
  1930. X# else
  1931. X#   define    Getwd        (void) getcwd
  1932. X# endif HPUX && USE_CWD
  1933. X
  1934. X# define    Wait        (void) wait
  1935. X# define    Execl        (void) execl
  1936. X
  1937. Xvoid catch();
  1938. X
  1939. XWINDOW *inside_window, *help_window;
  1940. X
  1941. Xtypedef struct
  1942. X{
  1943. X    char key;        /* Key character for command types.  */
  1944. X    int cflag;        /* Compressed Menu flag.         */
  1945. X    char desc[LINESZ];    /* Description of command.         */
  1946. X    char cmd[LINESZ];      /* The Command.                      */
  1947. X        char help_fil[LINESZ];  /* Name of the Help file for option. */
  1948. X}menu_ent;
  1949. X
  1950. Xmenu_ent main_menu[N_ENTRIES];
  1951. X
  1952. Xtypedef int FLAG;
  1953. X
  1954. XFLAG m_flag;
  1955. X
  1956. X
  1957. Xchar line[BUF_SIZ], buffer[BUF_SIZ], string[BUF_SIZ];
  1958. Xchar menu_dir[BUF_SIZ];
  1959. X
  1960. Xstatic int alarm_on = FALSE;
  1961. X
  1962. Xint get_term();
  1963. X
  1964. X# endif __MENU_H
  1965. END_OF_FILE
  1966.   if test 3520 -ne `wc -c <'MENU/menu.h'`; then
  1967.     echo shar: \"'MENU/menu.h'\" unpacked with wrong size!
  1968.   fi
  1969.   # end of 'MENU/menu.h'
  1970. fi
  1971. if test -f 'MENU/menu.man' -a "${1}" != "-c" ; then 
  1972.   echo shar: Will not clobber existing file \"'MENU/menu.man'\"
  1973. else
  1974.   echo shar: Extracting \"'MENU/menu.man'\" \(6667 characters\)
  1975.   sed "s/^X//" >'MENU/menu.man' <<'END_OF_FILE'
  1976. X.TH MENU 1 "July 1993" "PSCmenu"
  1977. X\.@(#)pscmenu2.3 93/07/11 TTW;
  1978. X.SH NAME
  1979. Xmenu \- Runs the PSC Menu System.
  1980. X.SH SYNOPSIS
  1981. Xmenu [ menu_directory ]
  1982. X.SH DESCRIPTION
  1983. X
  1984. XMenu is a menu system that is capable of doing any unix command 
  1985. Xfrom the "menu".  The individual menus are read from menu files that
  1986. Xare located in a "menu" directory.  The menu files are simple text files
  1987. Xthat may be edited with any editor.  The "menu" is flexable, the only
  1988. Xcommand line argument that is accepted is the name of a directory in which
  1989. Xthe menu files are located.  The menu will accept the "~" in the directory
  1990. Xargument to specify a users home directory.  A default directory is 
  1991. Xspecified in the menu header file.
  1992. X.SH SELECTING ITEMS & USING BUILTIN COMMANDS
  1993. X
  1994. XAn item is selected from the menu simply by entering the corresponding 
  1995. Xnumber/letter that is displayed for the item.  It is important to know 
  1996. Xthat you should not enter the selection and then press return.  The return
  1997. Xkey has a special function.  The return key tells the menu to back up one
  1998. Xmenu unless you are in the main menu (this assumes that the menu item is
  1999. Xdesignated to return to the previous menu), where it has no effect.  The PSC
  2000. Xmenu system contains built in commands that allow you to: change directory,
  2001. Xexecute a shell command, do directory listings, quit menu, help and re-draw
  2002. Xthe screen. See the section on the "Built in Menu" for more details.
  2003. X
  2004. X.SH BUILT IN MENU
  2005. X
  2006. XThe Built in menu is a pop-up window that displays a list of builtin commands
  2007. Xaccessable.  This menu is accessed by entering the letter 'h' from any
  2008. Xmenu accept the builtin menu.  Options in this menu are: C, D, h, l, m, p,
  2009. Xq, x, ?, L, P and <ctrl-R>.  These characters cause 
  2010. Xthe following affects:
  2011. X.nf
  2012. X
  2013. X    'C' - Change to a new working directory.
  2014. X
  2015. X    'D' - Get a short directory listing of the current directory.
  2016. X
  2017. X    'h' - Use the builtin help menu.
  2018. X
  2019. X    'l' - Get a long directory listing of the current directory.
  2020. X
  2021. X    'm' - Return to the "main" menu.  (main.menu)
  2022. X
  2023. X    'p' - Go to the previous menu.  This assumes that the last
  2024. X           entry in the menu is a return to previous menu.  If it
  2025. X           is not, it will do the last entry, in that menu.
  2026. X
  2027. X    'q' - Quit the Menu.
  2028. X
  2029. X    'x' - Execute a shell command.
  2030. X
  2031. X    '?' - Get help on a specified menu entry.  The help file for 
  2032. X          that entry must exist for help to be given.
  2033. X
  2034. X    'L' - Log off the system.  This assumes that you ran the menu
  2035. X           from your login shell.  If you did not do this it will 
  2036. X              kill the shell it was run from.
  2037. X
  2038. X    'P' - Print a file using the visual directory to select the
  2039. X           file to be printed.
  2040. X
  2041. X    <ctrl-R> Re-draw the screen in cases where you get garbled. 
  2042. X                 (control key and 'R' are pressed at the same time).
  2043. X.fi
  2044. X
  2045. X.SH MENU FILES
  2046. XThe Menu files have a specific format that must be followed.  The first
  2047. Xcharacter in each line must be $, !, ?, #, %, +, *, @, &, 1, 2, 3, 4, 5, 6.
  2048. XThese are "key" characters that tell "menu" what kind of operation is to
  2049. Xbe performed.
  2050. X.PP
  2051. X\'$'     This character means that this line is the menu header for this
  2052. Xmenu, this must be the first character in the line.
  2053. XThis must always be the first line in the "menu" file.  The second
  2054. Xcharacter in this line is skipped anything after the second column is
  2055. Xinterpreted as the menu heading.  This option allows you to have up
  2056. Xto 7 menu entries.
  2057. X.PP
  2058. X\'!'    This does the same as the '$' option with the exception that
  2059. Xit specifies the the menu can have up to 14 entries.
  2060. X.PP
  2061. X\'?'    This character means that this line is a comment to be displayed to
  2062. Xthe user when they use the menu.  
  2063. X.PP
  2064. X\'#'    This character means that this line is a the name or path to 
  2065. Xthe help file on a menu selection.
  2066. X.PP
  2067. X\'%'     Execute in a sub-shell but do not use the continue line
  2068. Xupon completion of command.  Similar to the '*' option.
  2069. X.PP
  2070. X\'+'     This character means that output from the name program be 
  2071. Xoutput to the "menu" window.  It is best if the output is 70 columns
  2072. Xwide or less, anything after 70 columns is chopped off. Some good examples
  2073. Xare ls and ls -l.  Any program which actually does screen manipulation cannot
  2074. Xuse the '+' option (It Will really get messed up).
  2075. X.PP
  2076. X\'@'     This character specifies that the menu to be loaded is to
  2077. Xbe considered the main menu so that pressing return will not do anything.
  2078. X.PP
  2079. X\'&'     This character specifies a menu to be loaded.  The path to the menu
  2080. Xfile is the default or the specified one given in the command argument.
  2081. X.PP
  2082. X\'*'     This character means that the invoked program will interfere with
  2083. Xthe "menu" window.  Such programs include more, less and any games.
  2084. X.PP
  2085. X\'1'     This character specifies that one file name is expected as an argument
  2086. Xfor the program to be run.  A good example would be: vi <filename>.
  2087. X.PP
  2088. X\'2'     This character specifies that two file names are expected as
  2089. Xarguments for the program to be run.  A good exmample would be:       
  2090. Xcp <file1> <file2>.
  2091. X.PP
  2092. X\'3'     This character specifies that a user name is expected as an argument
  2093. Xfor the program to be run.  A good exapmple would be:    mail <user>.
  2094. X.PP
  2095. X\'4'     This character specifies a topic to be used as an argument to the 
  2096. Xprogram to be run.  A good example would be:    man <topic>.
  2097. X.PP
  2098. X\'5'     Execute a C-Shell command with a file name as an argument.
  2099. XUses visual directory listing and a file is selected by using the arrow
  2100. Xkeys.  Useful when you know the file must exist.
  2101. X.PP
  2102. X\'6'    Execute a command in a pipe with a file name as an argument.
  2103. XUses visual directory listing and a file is selected by using the arrow 
  2104. Xkeys.  Useful when you know the file must exist.
  2105. X
  2106. X.SH DEFAULTS
  2107. X    The menu program looks for a file called "main.menu" in the default
  2108. Xor specified directory.  If the Directory does not exist or is not accessable
  2109. Xthe program will tell you of the condition and quietly exit.  If the file
  2110. X"main.menu" does not exist in the named directory the program will notify you
  2111. Xthat it could not find any menu files and quietly exits.  The return key
  2112. Xif pressed will do the last thing in the menu, unless that menu is defined
  2113. Xto be the main menu (this is done to make it easy to back out of menus
  2114. Xassuming of course that return to previous menu is that last option in that
  2115. Xmenu).
  2116. X.SH EXAMPLE MENU FILE
  2117. X.nf
  2118. X$ File Management Menu
  2119. X5 /bin/rm -i
  2120. X# /usr/local/lib/menu_help/remove.hlp
  2121. X? Remove a file.
  2122. X2 /bin/cp -i
  2123. X? Copy a file.
  2124. X5 rm -i
  2125. X? Remove a single file.
  2126. X* rm -i *
  2127. X? Cleanup your files.
  2128. X+ /bin/ls -l
  2129. X? List your Files.
  2130. X& menu.1
  2131. X? Return to main Menu.
  2132. X.fi
  2133. X
  2134. X.SH CAUTIONS
  2135. XIf you use the '+' menu command that tells the menu program to send
  2136. Xoutput to the menu window with a command that uses cursor addressing
  2137. Xor requires user input you may get some rather interesting results.
  2138. END_OF_FILE
  2139.   if test 6667 -ne `wc -c <'MENU/menu.man'`; then
  2140.     echo shar: \"'MENU/menu.man'\" unpacked with wrong size!
  2141.   fi
  2142.   # end of 'MENU/menu.man'
  2143. fi
  2144. if test -f 'MENU/terminal.c' -a "${1}" != "-c" ; then 
  2145.   echo shar: Will not clobber existing file \"'MENU/terminal.c'\"
  2146. else
  2147.   echo shar: Extracting \"'MENU/terminal.c'\" \(2983 characters\)
  2148.   sed "s/^X//" >'MENU/terminal.c' <<'END_OF_FILE'
  2149. X# define    __TERMINAL_C
  2150. X
  2151. X# include "config.h"
  2152. X# include "proto.h"
  2153. X# include <stdio.h>
  2154. X# include <curses.h>
  2155. X
  2156. X# if defined (AIX) || defined (HPUX)
  2157. X# include <sgtty.h>
  2158. X# include <sys/ioctl.h>
  2159. X
  2160. Xvoid aix_echo_on() 
  2161. X{
  2162. X    struct sgttyb terminal;
  2163. X
  2164. X    (void) ioctl(0, TIOCGETP, &terminal);
  2165. X    terminal.sg_flags &= ~(ECHO);
  2166. X    (void) ioctl(0, TIOCSETP, &terminal);
  2167. X}
  2168. X
  2169. Xvoid aix_echo_off() 
  2170. X{
  2171. X    struct sgttyb terminal;
  2172. X
  2173. X      (void) ioctl(0, TIOCGETP, &terminal);
  2174. X    terminal.sg_flags |= ~(ECHO);
  2175. X      (void) ioctl(0, TIOCSETP, &terminal) ;
  2176. X}
  2177. X# endif
  2178. X
  2179. Xvoid setup_modes()
  2180. X{
  2181. X     noecho();
  2182. X    crmode();
  2183. X}
  2184. X
  2185. Xvoid unset_modes()
  2186. X{
  2187. X# if defined (AIX) || defined (HPUX)
  2188. X    aix_echo_on();
  2189. X# else
  2190. X     echo();
  2191. X# endif
  2192. X    nocrmode();
  2193. X}
  2194. X
  2195. Xvoid start_up()
  2196. X{
  2197. X      savetty();
  2198. X    initscr();
  2199. X    setup_modes();
  2200. X}
  2201. X
  2202. Xvoid end_up()
  2203. X{
  2204. X      resetty();
  2205. X    endwin();
  2206. X    unset_modes();
  2207. X}
  2208. X
  2209. Xvoid move_csr(window_name,x,y)
  2210. XWINDOW *window_name;
  2211. Xunsigned short x,y;
  2212. X{
  2213. X    wmove(window_name,y,x);
  2214. X    wrefresh(window_name);
  2215. X}
  2216. X
  2217. Xstatic void window_print(window_name,string)
  2218. XWINDOW *window_name;
  2219. Xchar *string;
  2220. X{
  2221. X    wprintw(window_name,string);
  2222. X    wrefresh(window_name);
  2223. X}
  2224. X
  2225. Xvoid my_print(window_name,string,x,y)
  2226. XWINDOW *window_name;
  2227. Xchar *string;
  2228. Xunsigned short x,y;
  2229. X{
  2230. X    move_csr(window_name,x,y);
  2231. X    window_print(window_name,string);
  2232. X}
  2233. X
  2234. Xstatic void reverse(window_name)
  2235. XWINDOW *window_name;
  2236. X{
  2237. X    wstandout(window_name);
  2238. X    wrefresh(window_name);
  2239. X}
  2240. X
  2241. Xstatic void unreverse(window_name)
  2242. XWINDOW *window_name;
  2243. X{
  2244. X    wstandend(window_name);
  2245. X    wrefresh(window_name);
  2246. X}
  2247. X
  2248. Xstatic void hi_lite_string(window_name,string)
  2249. XWINDOW *window_name;
  2250. Xchar *string;
  2251. X{
  2252. X    reverse(window_name);
  2253. X    window_print(window_name,string);
  2254. X    unreverse(window_name);
  2255. X}
  2256. X
  2257. Xvoid hi_lite(window_name,string,x,y)
  2258. XWINDOW *window_name;
  2259. Xchar *string;
  2260. Xunsigned short x,y;
  2261. X{
  2262. X    move_csr(window_name,x,y);
  2263. X    hi_lite_string(window_name,string);
  2264. X}
  2265. X
  2266. Xstatic void wind_print_char(window_name,character)
  2267. XWINDOW *window_name;
  2268. Xunsigned char character;
  2269. X{
  2270. X    waddch(window_name,character);
  2271. X    wrefresh(window_name);
  2272. X}
  2273. X
  2274. Xvoid print_char(window_name,character,x,y)
  2275. XWINDOW *window_name;
  2276. Xunsigned char character;
  2277. Xunsigned short x,y;
  2278. X{
  2279. X    move_csr(window_name,x,y);
  2280. X    wind_print_char(window_name,character);
  2281. X}
  2282. X
  2283. Xstatic void wind_hi_lite_char(window_name,character)
  2284. XWINDOW *window_name;
  2285. Xunsigned char character;
  2286. X{
  2287. X    reverse(window_name);
  2288. X    wind_print_char(window_name,character);
  2289. X    unreverse(window_name);
  2290. X}
  2291. X
  2292. Xvoid hi_lite_char(window_name,character,x,y)
  2293. XWINDOW *window_name;
  2294. Xunsigned char character;
  2295. Xunsigned short x,y;
  2296. X{
  2297. X    move_csr(window_name,x,y);
  2298. X    wind_hi_lite_char(window_name,character);
  2299. X}
  2300. X
  2301. Xvoid clear_to_bot(window_name)
  2302. XWINDOW *window_name;
  2303. X{
  2304. X    wclrtobot(window_name);
  2305. X    wrefresh(window_name);
  2306. X}
  2307. X
  2308. Xvoid clear_window(window_name)
  2309. XWINDOW *window_name;
  2310. X{
  2311. X    wclear(window_name);
  2312. X    wrefresh(window_name);
  2313. X}
  2314. X
  2315. Xunsigned short my_getchar(window_name)
  2316. XWINDOW *window_name;
  2317. X{
  2318. X    unsigned short in_char;
  2319. X
  2320. X    in_char = wgetch(window_name);
  2321. X    wrefresh(window_name);
  2322. X    return(in_char);
  2323. X}
  2324. X
  2325. Xvoid clear_to_eol(window_name)
  2326. XWINDOW *window_name;
  2327. X{
  2328. X    wclrtoeol(window_name);
  2329. X    wrefresh(window_name);
  2330. X}
  2331. END_OF_FILE
  2332.   if test 2983 -ne `wc -c <'MENU/terminal.c'`; then
  2333.     echo shar: \"'MENU/terminal.c'\" unpacked with wrong size!
  2334.   fi
  2335.   # end of 'MENU/terminal.c'
  2336. fi
  2337. echo shar: End of archive 1 \(of 2\).
  2338. cp /dev/null ark1isdone
  2339. MISSING=""
  2340. for I in 1 2 ; do
  2341.     if test ! -f ark${I}isdone ; then
  2342.     MISSING="${MISSING} ${I}"
  2343.     fi
  2344. done
  2345. if test "${MISSING}" = "" ; then
  2346.     echo You have unpacked both archives.
  2347.     rm -f ark[1-9]isdone
  2348. else
  2349.     echo You still must unpack the following archives:
  2350.     echo "        " ${MISSING}
  2351. fi
  2352. exit 0
  2353. exit 0 # Just in case...
  2354.