home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-07-25 | 28.8 KB | 1,149 lines |
- Newsgroups: comp.sources.misc
- From: Ted Wisniewski <ted@oz.plymouth.edu>
- Subject: v21i035: pscmenu - tty based menu system v2.0, Part02/02
- Message-ID: <1991Jul25.013400.27873@sparky.IMD.Sterling.COM>
- X-Md4-Signature: 3ee0a0d27a57c2811ea5703f67f1cabd
- Date: Thu, 25 Jul 1991 01:34:00 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: Ted Wisniewski <ted@oz.plymouth.edu>
- Posting-number: Volume 21, Issue 35
- Archive-name: pscmenu/part02
- Supersedes: pscmenu: Volume 16, Issue 99
- Environment: Ultrix, AIX
-
-
- #!/bin/sh
- # this is part.02 (part 2 of a multipart archive)
- # do not concatenate these parts, unpack them in order with /bin/sh
- # file MENU/utils.c continued
- #
- if test ! -r _shar_seq_.tmp; then
- echo 'Please unpack part 1 first!'
- exit 1
- fi
- (read Scheck
- if test "$Scheck" != 2; then
- echo Please unpack part "$Scheck" next!
- exit 1
- else
- exit 0
- fi
- ) < _shar_seq_.tmp || exit 1
- if test ! -f _shar_wnt_.tmp; then
- echo 'x - still skipping MENU/utils.c'
- else
- echo 'x - continuing file MENU/utils.c'
- sed 's/^X//' << 'SHAR_EOF' >> 'MENU/utils.c' &&
- X putp(clear_screen);
- X# else TERM_INFO
- X tputs(CL,1,outc);
- X# endif TERM_INFO
- X}
- X
- Xstart_rev()
- X/*
- X Start the reverse video mode.
- X*/
- X{
- X# ifdef TERM_INFO
- X putp(enter_standout_mode);
- X# else TERM_INFO
- X tputs(SO,1,outc);
- X# endif TERM_INFO
- X}
- X
- Xend_rev()
- X/*
- X End the reverse video mode.
- X*/
- X{
- X# ifdef TERM_INFO
- X putp(exit_standout_mode);
- X# else TERM_INFO
- X tputs(SE,1,outc);
- X# endif TERM_INFO
- X}
- X
- Xprint_str(string)
- Xchar *string;
- X/*
- X Print an entire string to the screen.
- X*/
- X{
- X (void) fputs(string,stdout);
- X (void) fflush(stdout);
- X}
- X
- Xhi_lite(string)
- Xchar *string;
- X/*
- X Hi-lite a string that will be printed.
- X*/
- X{
- X start_rev();
- X print_str(string);
- X (void) fflush(stdout);
- X end_rev();
- X}
- X
- Xsave_tty()
- X/*
- X Save Terminal characteristics Reset by call to reset_tty().
- X*/
- X{
- X (void) ioctl(0, TCGETA, &ter_old);
- X}
- X
- Xreset_tty()
- X/*
- X This routine returns the terminal to the same state it
- X had before this program was invoked.
- X*/
- X{
- X (void) ioctl(0, TCSETA, &ter_old) ;
- X}
- X
- Xcrmode()
- X/*
- X Turn on CRmode.
- X*/
- X{
- X (void) ioctl(0,TCGETA,&ter_des);
- X TERM_STRUCT |= CRMOD;
- X (void) ioctl(0,TCSETA,&ter_des);
- X}
- X
- Xno_crmode()
- X/*
- X Turn off CRmode.
- X*/
- X{
- X (void) ioctl(0,TCGETA,&ter_des);
- X TERM_STRUCT &= ~CRMOD;
- X (void) ioctl(0,TCSETA,&ter_des);
- X}
- X
- Xecho()
- X/*
- X Turn echo back on.
- X*/
- X{
- X (void) ioctl(0,TCGETA,&ter_des);
- X TERM_STRUCT |= ECHO;
- X (void) ioctl(0,TCSETA,&ter_des);
- X}
- X
- Xno_echo()
- X/*
- X Turn off echo.
- X*/
- X{
- X (void) ioctl(0,TCGETA,&ter_des);
- X TERM_STRUCT &= ~ECHO;
- X (void) ioctl(0,TCSETA,&ter_des);
- X}
- X
- Xno_cbreak()
- X/*
- X Take the terminal out of cbreak mode.
- X*/
- X{
- X (void) ioctl(0,TCGETA,&ter_des);
- X TERM_STRUCT |= CBREAK;
- X (void) ioctl(0,TCSETA,&ter_des);
- X}
- X
- Xcbreak()
- X/*
- X Place the Terminal in Cbreak mode.
- X*/
- X{
- X (void) ioctl(0,TCGETA,&ter_des);
- X TERM_STRUCT &= ~CBREAK;
- X (void) ioctl(0,TCSETA,&ter_des);
- X}
- X
- Xrm_lf(array)
- Xchar *array;
- X/*
- X Remove Trailing line feed from a line.
- X*/
- X{
- X if(array[strlen(array)-1] == '\n')
- X array[strlen(array)-1] = NULL;
- X}
- X
- Xread_str(string,max_length)
- Xchar *string;
- Xint max_length;
- X{
- X char *str;
- X int length = 0;
- X
- X str = string;
- X while((*str =my_getchar()) != LF && *str != CR && length <= max_length){
- X if(*str == DEL || *str == BS)
- X if(*str != *string){
- X outc(DEL);
- X outc(SPACE);
- X outc(DEL);
- X *str--;
- X length--;
- X }else
- X continue;
- X else{
- X if(length == max_length)
- X outc(0x07);
- X else{
- X outc(*str);
- X *str++;
- X length++;
- X }
- X }
- X }
- X *str = NULL;
- X}
- X
- Xclear_array(array)
- Xchar *array;
- X{
- X for(;*array != NULL;*array++)
- X *array = NULL;
- X}
- X
- Xint get_input()
- X{
- X char c, buffer[80];
- X int ct = 0, len;
- X
- X if((len = strlen(KU)-1) < 2)
- X len = 1;
- X while((c = my_getchar()) && (ct < len)){
- X if((c == 0x1b) || (ct > 0)){
- X buffer[ct] = c;
- X ct++;
- X }else
- X return(c);
- X }
- X buffer[ct] = c;
- X buffer[ct+1] = NULL;
- X if((strcmp(KU,buffer)) == 0)
- X return(UP);
- X else
- X if((strcmp(KD,buffer)) == 0)
- X return(DOWN);
- X else
- X if((strcmp(KL,buffer)) == 0)
- X return(LEFT);
- X else
- X if((strcmp(KR,buffer)) == 0)
- X return(RIGHT);
- X else
- X return(NULL);
- X}
- X
- X# ifdef SYSTEM_FIVE
- Xint my_getchar()
- X{
- X struct termio tdes,tsave;
- X char n;
- X
- X ioctl(0,TCGETA,&tdes);
- X tsave = tdes;
- X
- X tdes.c_cc[VMIN] = 1;
- X tdes.c_cc[VTIME] = 0;
- X ioctl(0,TCSETA,&tdes);
- X
- X read(0,&n,1);
- X
- X ioctl(0,TCSETA,&tsave);
- X return(n);
- X}
- X
- X# else
- X
- Xint my_getchar()
- X{
- X return(getchar());
- X}
- X# endif SYSTEM_FIVE
- SHAR_EOF
- echo 'File MENU/utils.c is complete' &&
- chmod 0600 MENU/utils.c ||
- echo 'restore of MENU/utils.c failed'
- Wc_c="`wc -c < 'MENU/utils.c'`"
- test 5282 -eq "$Wc_c" ||
- echo 'MENU/utils.c: original size 5282, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= MENU/menu.c ==============
- if test -f 'MENU/menu.c' -a X"$1" != X"-c"; then
- echo 'x - skipping MENU/menu.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting MENU/menu.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'MENU/menu.c' &&
- X# include <stdio.h>
- X# include <sys/file.h>
- X# include <sys/ioctl.h>
- X# include "menu.h"
- X
- X/* PSC MENU COPYRIGHT NOTICE
- X
- X Part of PSCMenu
- X
- X This software is to be considered to be public domain, it
- Xmay be copied, modified and parts of it may be used in other programs
- Xas long as this copyright notice remains intact.
- X
- X Copyright() PSC - Plymouth State College
- X Written by: Ted Wisniewski 12-9-1990
- X
- X*/
- X
- X/*****************************************************************************
- X Execute a process and have the output read into a buffer and then
- X print it to the screen.
- X *****************************************************************************/
- X
- Xexec_pipe(comline)
- Xchar *comline;
- X{
- X char inbuf[LINESZ], list[FOURK][80];
- X FILE *f, *popen();
- X int num = 1, length = 0;
- X
- X move_csr(5,2);
- X print_str("Working...");
- X if((f = popen(comline,"r")) == NULL){
- X Strcpy(list[0],"Command not found");
- X }else
- X while(fgets(inbuf,LINESZ,f) != NULL){
- X rm_lf(inbuf);
- X if(strlen(inbuf) > 70)
- X chop_str(inbuf,70);
- X else
- X pad_str(inbuf);
- X Strcpy(list[num],inbuf);
- X if(strlen(inbuf) > length)
- X length = strlen(inbuf);
- X num++;
- X }
- X clr_area(2,5,1,15);
- X print_output(list,num,length);
- X Pclose(f);
- X}
- X
- X/**************************************************************************
- X Print output to the Menu Window, when done clear the Window.
- X **************************************************************************/
- X
- Xprint_output(output,number,length)
- Xchar output[FOURK][80];
- Xint number, length;
- X{
- X int i, k = 4, left;
- X
- X left = number;
- X for(i=1;i<number;++i){
- X move_csr(5,k);
- X print_str(output[i]);
- X k++;
- X if(i%15 == 14){
- X left -= 15;
- X if(cont_it() == 1){
- X clr_area(5,4,(k-4),length+2);
- X return;
- X }
- X/* clr_area(5,4,(k-4),length+2);*/
- X move_csr(5,4);
- X k = 4;
- X }
- X Fflush(stdout);
- X }
- X if(left < 15)
- X clr_area(5+left,5,(15-left),length+2);
- X continue_it(CONT_LINE);
- X clr_area(5,4,(k-4),length+2);
- X}
- X
- X/**************************************************************************
- X Request input from the user as to whether he/she wishes to continue.
- X This routine gives the option to stop seeing output.
- X **************************************************************************/
- X
- Xcont_it()
- X{
- X char c;
- X
- X move_csr(20,CONT_LINE);
- X hi_lite("Press space to continue or \'q\' to stop.");
- X c = my_getchar();
- X while(c != 'q' && c != ' ')
- X c = my_getchar();
- X erase_line(20,CONT_LINE,45);
- X if(c == 'q')
- X return 1;
- X else
- X return 0;
- X}
- X
- X/**************************************************************************
- X Request input from the user as to whether he/she wishes to continue.
- X **************************************************************************/
- X
- Xcontinue_it(line_num)
- Xint line_num;
- X{
- X move_csr(27,line_num);
- X hi_lite("Press a space to Continue.");
- X while(my_getchar() != SPACE);
- X erase_line(27,line_num,45);
- X}
- X
- X/*****************************************************************************
- X Print The current working directory at the bottom of the screen.
- X *****************************************************************************/
- X
- Xprt_curdir()
- X{
- X char direct[BUF_SIZ], *getwd();
- X int i;
- X
- X move_csr(0,STATUS_LINE);
- X hi_lite("Directory:");
- X Getwd(direct);
- X if(strlen(direct) < 40)
- X for(i=strlen(direct);i<=40;i++)
- X Strcat(direct," ");
- X else
- X for(i=40;i<=80;i++)
- X direct[i] = NULL;
- X move_csr(12,STATUS_LINE);
- X hi_lite(direct);
- X}
- X
- X/*****************************************************************************
- X Clear an Area in the Menu Window.
- X *****************************************************************************/
- X
- Xclr_area(st_y,st_x,n_line,length)
- Xint st_y,st_x,n_line,length;
- X{
- X int i;
- X
- X for(i=0;i<=length;i++)
- X line[i] = ' ';
- X line[i+1] = NULL;
- X for(i=(st_y-1);i<(n_line+st_y);i++){
- X move_csr(st_x,i);
- X print_str(line);
- X }
- X}
- X
- X/*****************************************************************************
- X Erase a line within the Menu Window.
- X *****************************************************************************/
- X
- Xerase_line(x,y,length)
- Xint x,y,length;
- X{
- X int i;
- X
- X for(i=0;i<=length;i++)
- X line[i] = ' ';
- X line[i+1] = NULL;
- X move_csr(x,y);
- X print_str(line);
- X}
- X
- X/*****************************************************************************
- X Execute a shell command. Output does not come to back to the window.
- X *****************************************************************************/
- X
- Xexec_cshell(command,flag)
- Xchar *command;
- Xint flag;
- X{
- X clr_scr();
- X Fflush(stdout);
- X reset_tty();
- X if(fork() == 0)
- X Execl("/bin/csh","csh","-c",command,0);
- X else
- X Wait((int *)0);
- X setup_tty();
- X if(flag)
- X continue_it(LAST_LINE);
- X setup_screen();
- X}
- X
- X/*****************************************************************************
- X Draw borders and print Header on the screen.
- X *****************************************************************************/
- X
- Xsetup_screen()
- X{
- X clr_scr(); /* Clear screen routine */
- X box_screen();
- X move_csr((CENTER-strlen(HEADER)/2),FIRST_LINE);
- X hi_lite(HEADER);
- X move_csr(68,STATUS_LINE);
- X hi_lite(CMD_LIN);
- X prt_curdir();
- X}
- X
- X/*****************************************************************************
- X Make sure The user does not try to run menu in the background.
- X *****************************************************************************/
- X
- Xcheck_run()
- X{
- X int tpgrp; /* terminal control process group */
- X
- X if (ioctl(2, TIOCGPGRP, &tpgrp) != 0) { /* hope stderr open */
- X exit(1);
- X }
- X if(getpgrp(0) != tpgrp){
- X Fprintf(stderr,"\nSorry, Cannot run in background.\n");
- X exit(0);
- X }
- X}
- X
- X/*****************************************************************************
- X Make sure Output goes to the screen and terminal is capable of running
- X menu.
- X *****************************************************************************/
- X
- Xinitialize()
- X{
- X int term;
- X
- X if(!isatty(1)){
- X Fprintf(stderr,"Sorry, Cannot output to the screen (exiting).\n");
- X exit(4);
- X }
- X if((term = get_term()) == -1){
- X Fprintf(stderr,"Sorry, Bad termcap entry (exiting).\n");
- X exit(4);
- X }
- X save_tty(); /* Save tty states */
- X setup_tty();
- X}
- X
- X/*****************************************************************************
- X Prepare for Quit Menu, and exit (restore original settings).
- X *****************************************************************************/
- X
- Xquit()
- X/*
- X Reset the terminal to the same as before it was run.
- X*/
- X{
- X clr_scr(); /* Clear screen routine */
- X move_csr(0,LAST_LINE);
- X reset_tty();
- X exit(0);
- X}
- X
- X/*****************************************************************************
- X Set proper terminal settings for use while within menu.
- X *****************************************************************************/
- X
- Xsetup_tty()
- X{
- X no_echo();
- X cbreak();
- X crmode();
- X}
- X
- Xint main(argc,argv)
- Xint argc;
- Xchar *argv[];
- X{
- X int *num;
- X
- X /************************************************************
- X If More than two arguments are supplied print the
- X Usage statement.
- X ************************************************************/
- X if(argc > 2){
- X Fprintf(stderr,"Usage: menu\n");
- X Fprintf(stderr,"Usage: menu [menu_directory]\n");
- X exit(0);
- X }else{
- X /************************************************************
- X If there are no additional arguments Use the default
- X Menu directory.
- X ************************************************************/
- X if(argc == 1)
- X Strcpy(menu_dir,MENU_DIR);
- X else
- X /************************************************************
- X See if the directory name ends in a '/' if not add
- X one.
- X ************************************************************/
- X if(argc == 2){
- X Strcpy(menu_dir,argv[1]);
- X check_dirname(menu_dir);
- X if(menu_dir[strlen(menu_dir)-1] != '/')
- X Strcat(menu_dir,"/");
- X }
- X Sprintf(buffer,"%s%s",menu_dir,MAIN_MENU);
- X /************************************************************
- X Check to make sure the menu directory is Read-able and
- X executeable
- X ************************************************************/
- X if(access(menu_dir,R_OK|X_OK)){
- X Fprintf(stderr,"Directory :%s: is not accessable ",menu_dir);
- X Fprintf(stderr,"or does not exist.\n");
- X exit(1);
- X }
- X /************************************************************
- X Check to see if the main menu file exists, if it does
- X not exist, exit the program.
- X ************************************************************/
- X if(access(buffer,F_OK)){
- X Fprintf(stderr,"Menu files do not exist in %s.\n",menu_dir);
- X (void) exit(2);
- X }
- X }
- X# ifndef SYSTEM_FIVE
- X (void) setpgrp(getpid(),0);
- X# else
- X (void) setpgrp();
- X# endif SYSTEM_FIVE
- X check_run();
- X setbuf(stdin,NULL); /* Make stdin unbuffered */
- X initialize();
- X setup_screen();
- X setup_sigs();
- X main_menu->key = '@'; /* We start in main menu */
- X (void) read_menu(main_menu,MAIN_MENU,&num);
- X disp_menu(main_menu,num);
- X Fflush(stdin);
- X do_menu(main_menu,num);
- X return(0);
- X}
- SHAR_EOF
- chmod 0600 MENU/menu.c ||
- echo 'restore of MENU/menu.c failed'
- Wc_c="`wc -c < 'MENU/menu.c'`"
- test 9066 -eq "$Wc_c" ||
- echo 'MENU/menu.c: original size 9066, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= MENU/signals.c ==============
- if test -f 'MENU/signals.c' -a X"$1" != X"-c"; then
- echo 'x - skipping MENU/signals.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting MENU/signals.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'MENU/signals.c' &&
- X# include <signal.h>
- X# include "menu.h"
- X
- X/* PSC MENU COPYRIGHT NOTICE
- X
- X Part of PSCMenu
- X
- X This software is to be considered to be public domain, it
- Xmay be copied, modified and parts of it may be used in other programs
- Xas long as this copyright notice remains intact.
- X
- X Copyright() PSC - Plymouth State College
- X Written by: Ted Wisniewski 12-9-1990
- X
- X*/
- X
- X/*
- X * void setup_sigs():
- X *
- X * Parameters: None.
- X *
- X * Description: Set up signal handling.
- X *
- X * Returns: None.
- X *
- X * Last Modify: 05-8-91 (TW)
- X *
- X */
- X
- Xvoid setup_sigs()
- X{
- X (void) signal(SIGHUP,catch);
- X (void) signal(SIGSEGV,catch);
- X (void) signal(SIGBUS,catch);
- X (void) signal(SIGINT,SIG_IGN);
- X (void) signal(SIGTSTP,SIG_IGN);
- X (void) signal(SIGQUIT,SIG_IGN);
- X}
- X
- X/*
- X * catch():
- X *
- X * Parameters: signo - The signal ID #.
- X *
- X * Description: Routine to catch specific signals.
- X *
- X * Returns: None.
- X *
- X * Last Modify: 05-8-91 (TW)
- X *
- X */
- X
- Xcatch(signo)
- Xint signo;
- X{
- X switch (signo){
- X case SIGHUP:
- X exit(1);
- X break;
- X case SIGSEGV:
- X case SIGBUS:
- X clr_scr();
- X reset_tty();
- X end_rev();
- X perror(" ");
- X exit(1);
- X break;
- X }
- X}
- X
- X/*
- X * log_out():
- X *
- X * Parameters: None.
- X *
- X * Description: Kill The process group of the parent to the menu,
- X * hopefully this will be the users login shell.
- X *
- X * Returns: None.
- X *
- X * Last Modify: 04-27-91 (TW)
- X *
- X */
- X
- Xvoid log_out()
- X{
- X killpg(getppid(),SIGHUP); /* Kill Parent Process */
- X killpg(getpid(),SIGHUP); /* Suicide: Kill self. */
- X}
- SHAR_EOF
- chmod 0600 MENU/signals.c ||
- echo 'restore of MENU/signals.c failed'
- Wc_c="`wc -c < 'MENU/signals.c'`"
- test 1463 -eq "$Wc_c" ||
- echo 'MENU/signals.c: original size 1463, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= MENU/menu.h ==============
- if test -f 'MENU/menu.h' -a X"$1" != X"-c"; then
- echo 'x - skipping MENU/menu.h (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting MENU/menu.h (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'MENU/menu.h' &&
- X/* PSC MENU COPYRIGHT NOTICE
- X
- X Part of PSCMenu
- X
- X This software is to be considered to be public domain, it
- Xmay be copied, modified and parts of it may be used in other programs
- Xas long as this copyright notice remains intact.
- X
- X Copyright() PSC - Plymouth State College
- X Written by: Ted Wisniewski 12-9-1990
- X
- X*/
- X
- X# define FOURK 4096
- X# define ONEK 1024
- X# define BUF_SIZ 256
- X# define LINESZ 90
- X# define FIRST_LINE 0
- X# define STATUS_LINE 22
- X# define NUMCOL 22
- X# define DESCOL 25
- X# define LAST_LINE 23
- X# define CONT_LINE 21
- X# define N_ENTRIES 9
- X# define RE_DRAW ('r' & 037)
- X# define MAIN_MENU "main.menu"
- X# define MENU_DIR "/usr/local/lib/menus/"
- X# define CR 0x0d
- X# define LF 0x0a
- X# define SPACE 0x20
- X# define TRUE 1
- X# define FALSE 0
- X# define CENTER 40
- X# define HEADER "Plymouth State College Menu System"
- X# define CMD_LIN "h)elp q)uit"
- X# define CONTINUE 1
- X# define NO_CONTINUE 0
- X
- X# define Sprintf (void) sprintf
- X# define Strcpy (void) strcpy
- X# define Strcat (void) strcat
- X# define Fprintf (void) fprintf
- X# define Fflush (void) fflush
- X# define Fputc (void) fputc
- X# define Fputs (void) fputs
- X# define Fgets (void) fgets
- X# define Pclose (void) pclose
- X# define Getwd (void) getwd
- X# define Wait (void) wait
- X# define Execl (void) execl
- X
- Xint catch();
- X
- Xchar *strcat(), *strcpy();
- X
- Xtypedef struct
- X{
- X char key; /* Key character for command types. */
- X char desc[LINESZ]; /* Description of command. */
- X char **script; /* Strings to make a shell script. */
- X char cmd[LINESZ]; /* The Command. */
- X char help_fil[LINESZ]; /* Name of the Help file for option. */
- X}menu_ent;
- X
- Xmenu_ent main_menu[N_ENTRIES];
- X
- Xtypedef int FLAG;
- X
- XFLAG m_flag;
- X
- X
- Xchar line[BUF_SIZ], buffer[BUF_SIZ], string[BUF_SIZ];
- Xchar menu_dir[BUF_SIZ];
- X
- Xint get_term();
- SHAR_EOF
- chmod 0600 MENU/menu.h ||
- echo 'restore of MENU/menu.h failed'
- Wc_c="`wc -c < 'MENU/menu.h'`"
- test 1799 -eq "$Wc_c" ||
- echo 'MENU/menu.h: original size 1799, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= MENU/utils.h ==============
- if test -f 'MENU/utils.h' -a X"$1" != X"-c"; then
- echo 'x - skipping MENU/utils.h (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting MENU/utils.h (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'MENU/utils.h' &&
- X# ifdef TERM_INFO
- X# include <curses.h>
- X# include <term.h>
- X# endif TERM_INFO
- X# include <stdio.h>
- X# ifdef HAS_TERMIO
- X# include <termio.h>
- X# else
- X# include <sgtty.h>
- X# endif
- X
- X/* PSC MENU COPYRIGHT NOTICE
- X
- X Part of PSCMenu
- X
- X This software is to be considered to be public domain, it
- Xmay be copied, modified and parts of it may be used in other programs
- Xas long as this copyright notice remains intact.
- X
- X Copyright() PSC - Plymouth State College
- X Written by: Ted Wisniewski 12-9-1990
- X
- X*/
- X
- X# define MAXL 80
- X# define THIS_TTY 0
- X# define DEL 0x08
- X# define BS 0x7f
- X# define SPACE 0x20
- X# define LF 0x0a
- X# define CR 0x0d
- X
- X# define UP 252
- X# define DOWN 253
- X# define LEFT 254
- X# define RIGHT 255
- X
- Xchar *SO, *SE, *CE, *CM, *CL;
- Xchar *KU, *KD, *KR, *KL;
- X
- Xchar *getenv(), *tgetstr(), *tgoto();
- X
- Xint outc();
- X
- X# ifdef HAS_TERMIO
- X struct termio ter_old, ter_des;
- X# define TERM_STRUCT ter_des.c_lflag
- X# else
- X struct sgttyb ter_old, ter_des;
- X# define TERM_STRUCT ter_des.sg_flags
- X# endif HAS_TERMIO
- SHAR_EOF
- chmod 0600 MENU/utils.h ||
- echo 'restore of MENU/utils.h failed'
- Wc_c="`wc -c < 'MENU/utils.h'`"
- test 1028 -eq "$Wc_c" ||
- echo 'MENU/utils.h: original size 1028, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= MENU/menu.man ==============
- if test -f 'MENU/menu.man' -a X"$1" != X"-c"; then
- echo 'x - skipping MENU/menu.man (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting MENU/menu.man (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'MENU/menu.man' &&
- X.TH MENU 1 "June 1990" "Newwords+ Manual"
- X\.@(#)menu.1 1.1 90/06/31 SMI;
- X.SH NAME
- Xmenu \- Runs the PSC Menu System.
- X.SH SYNOPSIS
- Xmenu [ menu_directory ]
- X.SH DESCRIPTION
- X
- XMenu is a menu system that is capable of doing any unix command
- Xfrom the "menu". The individual menus are read from menu files that
- Xare located in a "menu" directory. The menu files are simple text files
- Xthat may be edited with any editor. The "menu" is flexable, the only
- Xcommand line argument that is accepted is the name of a directory in which
- Xthe menu files are located. The menu will accept the "~" in the directory
- Xargument to specify a users home directory. A default directory is
- Xspecified in the menu header file.
- X.SH SELECTING ITEMS & USING BUILTIN COMMANDS
- X
- XAn item is selected from the menu simply by entering the corre-
- Xsponding number that is displayed for the item. It is important to know
- Xthat you should not enter the selection and then press return. The return
- Xkey has a special function. The return key tells the menu to back up one
- Xmenu unless you are in the main menu, where it has no effect. The PSC
- Xmenu system contains built in commands that allow you to: change directory,
- Xexecute a shell command, do directory listings, quit menu, help and re-draw
- Xthe screen. See the section on the "Built in Menu" for more details.
- X
- X.SH BUILT IN MENU
- X
- XThe Built in menu is a pop-up window that displays a list of builtin commands
- Xaccessable. This menu is accessed by entering the letter 'h' from any
- Xmenu accept the builtin menu. Options in this menu are: c, d, h, l, m, p,
- Xq, x, ?, L, P and <ctrl-R>. These characters cause
- Xthe following affects:
- X.nf
- X
- X 'c' - Change to a new working directory.
- X
- X 'd' - Get a short directory listing of the current directory.
- X
- X 'h' - Use the builtin help menu.
- X
- X 'l' - Get a long directory listing of the current directory.
- X
- X 'm' - Return to the "main" menu. (main.menu)
- X
- X 'p' - Go to the previous menu. This assumes that the last
- X entry in the menu is a return to previous menu. If it
- X is not, it will execute the last entry a command.
- X
- X 'q' - Quit the Menu.
- X
- X 'x' - Execute a shell command.
- X
- X '?' - Get help on a specified menu entry. The help file for
- X that entry must exist for help to be given.
- X
- X 'L' - Log off the system. This assumes that you ran the menu
- X from your login shell. If you did not do this it will
- X kill the shell it was run from.
- X
- X 'P' - Print a file using the visual directory to select the
- X file to be printed.
- X
- X <ctrl-R> Re-draw the screen in cases where you get garbled.
- X (control key and 'R' are pressed at the same time).
- X.fi
- X
- X.SH MENU FILES
- XThe Menu files have a specific format that must be followed. The first
- Xcharacter in each line must be $, ?, #, %, +, *, @, &, 1, 2, 3, 4, 5, 6.
- XThese are "key" characters that tell "menu" what kind of operation is to
- Xbe performed.
- X.PP
- X\'$' This character means that this line is the menu header for this
- Xmenu, this must be the first character in the line.
- XThis must always be the first line in the "menu" file. The second
- Xcharacter in this line is skipped anything after the second column is
- Xinterpreted as the menu heading.
- X.PP
- X\'?' This character means that this line is a comment to be displayed to
- Xthe user when they use the menu.
- X.PP
- X\'#' This character means that this line is a the name or path to
- Xthe help file on a menu selection.
- X.PP
- X\'%' Execute in a sub-shell but do not use the continue line
- Xupon completion of command. Similar to the '*' option.
- X.PP
- X\'+' This character means that output from the name program be
- Xoutput to the "menu" window. It is best if the output is 70 columns
- Xwide or less, anything after 70 columns is chopped off. Some good examples
- Xare ls and ls -l. Any program which actually does screen manipulation cannot
- Xuse the '+' option (It Will really get messed up).
- X.PP
- X\'@' This character specifies that the menu to be loaded is to
- Xbe considered the main menu so that pressing return will not do anything.
- X.PP
- X\'&' This character specifies a menu to be loaded. The path to the menu
- Xfile is the default or the specified one given in the command argument.
- X.PP
- X\'*' This character means that the invoked program will interfere with
- Xthe "menu" window. Such programs include more, less and any games.
- X.PP
- X\'1' This character specifies that one file name is expected as an argument
- Xfor the program to be run. A good example would be: vi <filename>.
- X.PP
- X\'2' This character specifies that two file names are expected as
- Xarguments for the program to be run. A good exmample would be:
- Xcp <file1> <file2>.
- X.PP
- X\'3' This character specifies that a user name is expected as an argument
- Xfor the program to be run. A good exapmple would be: mail <user>.
- X.PP
- X\'4' This character specifies a topic to be used as an argument to the
- Xprogram to be run. A good example would be: man <topic>.
- X.PP
- X\'5' Execute a C-Shell command with a file name as an argument.
- XUses visual directory listing and a file is selected by using the arrow
- Xkeys. Useful when you know the file must exist.
- X.PP
- X\'6' Execute a command in a pipe with a file name as an argument.
- XUses visual directory listing and a file is selected by using the arrow
- Xkeys. Useful when you know the file must exist.
- X
- X.SH DEFAULTS
- X The menu program looks for a file called "main.menu" in the default
- Xor specified directory. If the Directory does not exist or is not accessable
- Xthe program will tell you of the condition and quietly exit. If the file
- X"main.menu" does not exist in the named directory the program will notify you
- Xthat it could not find any menu files and quietly exits. The return key
- Xif pressed will do the last thing in the menu, unless that menu is defined
- Xto be the main menu (this is done to make it easy to back out of menus
- Xassuming of course that return to previous menu is that last option in that
- Xmenu).
- X.SH EXAMPLE MENU FILE
- X.nf
- X$ File Management Menu
- X5 /bin/rm -i
- X# /usr/local/lib/menu_help/remove.hlp
- X? Remove a file.
- X2 /bin/cp -i
- X? Copy a file.
- X5 rm -i
- X? Remove a single file.
- X* rm -i *
- X? Cleanup your files.
- X+ /bin/ls -l
- X? List your Files.
- X& menu.1
- X? Return to main Menu.
- X.fi
- X
- X.SH CAUTIONS
- XIf you use the '+' menu command that tells the menu program to send
- Xoutput to the menu window with a command that uses cursor addressing
- Xor requires user input you may get some rather interesting results.
- SHAR_EOF
- chmod 0600 MENU/menu.man ||
- echo 'restore of MENU/menu.man failed'
- Wc_c="`wc -c < 'MENU/menu.man'`"
- test 6412 -eq "$Wc_c" ||
- echo 'MENU/menu.man: original size 6412, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= MENU/dir.h ==============
- if test -f 'MENU/dir.h' -a X"$1" != X"-c"; then
- echo 'x - skipping MENU/dir.h (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting MENU/dir.h (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'MENU/dir.h' &&
- X
- X# define PRT_MENU "Choose a printer: arrow keys to move, return to select, 'q' to quit"
- X# define PRINT_PATH "/usr/local/lib/menus/printers"
- X# define PRT_TO_SCR "/usr/ucb/more"
- X# define OTHER_LINE "n)ext page p)revious page"
- X
- X# define UP 252
- X# define DOWN 253
- X# define LEFT 254
- X# define RIGHT 255
- X
- X# define MAX_PRINTERS 24
- X# define MAX_ENT 1024
- X# define ENT_LEN 20
- X
- X# define isposodd(x) (x % 2)
- X# define in_col_one(x) ((x / 2) + (x % 2))
- X# define in_col_two(x) (x - in_col_one(x))
- X
- Xstruct print_options
- X{
- X char selection[80];
- X int option;
- X int x;
- X int y;
- X};
- X
- Xstatic struct print_options print_opts[6] = {
- X {"CANCEL",0,5,20},
- X {"PRINT",0,16,20},
- X {"(Spacing %d)",0,26,20},
- X {"(Skip Page Break %s)",0,41,20},
- X {"(Copies %d)",0,65,20}
- X};
- X
- Xtypedef struct
- X{
- X char comment[40];
- X char command[128];
- X}printer;
- X
- Xtypedef struct
- X{
- X int max_row;
- X int max_col;
- X}dir_info;
- X
- XDIR *opendir();
- Xstruct dirent *readdir();
- Xint closedir();
- X
- Xint strcmp();
- X
- SHAR_EOF
- chmod 0600 MENU/dir.h ||
- echo 'restore of MENU/dir.h failed'
- Wc_c="`wc -c < 'MENU/dir.h'`"
- test 945 -eq "$Wc_c" ||
- echo 'MENU/dir.h: original size 945, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- rm -f _shar_seq_.tmp
- echo You have unpacked the last part
- exit 0
-
- exit 0 # Just in case...
-