v20i009: menubar - C Menubar function, Patch01

J.E. King jek5036 at ultb.isc.rit.edu
Wed May 22 14:44:24 AEST 1991


Submitted-by: J.E. King <jek5036 at ultb.isc.rit.edu>
Posting-number: Volume 20, Issue 9
Archive-name: menubar/patch01
Patch-To: menubar: Volume 18, Issue 80

The following patch makes the termlock (terminal lock) program 
supplied as part of the menubar submission compilable and usable 
on sysv machines.

To apply this patch, run the patch through the patch utility via 

	% patch < patchfile.

Jim King <jek5036 at ultb.isc.rit.edu>

-- cut here -- cut here -- cut here -- cut here -- cut here -- cut here --
diff -c3 Old/Makefile New/Makefile
*** Old/Makefile	Mon May  6 11:56:11 1991
--- New/Makefile	Mon May  6 11:54:09 1991
***************
*** 2,8 ****
  # Makefile for termlock, curses implemented
  # by Jim King (jek5036 at ultb.isc.rit.edu)
  #
! # Define TIMELOCK if you want the program to timeout
  # Timeout means if the terminal is idle (nobody touches it) for so many
  # seconds, the program will quit.. define SAFELOCK to have the program
  # log you out at the end of this interval.  Useful for computer rooms
--- 2,8 ----
  # Makefile for termlock, curses implemented
  # by Jim King (jek5036 at ultb.isc.rit.edu)
  #
! # Define TIMELOCK is you want the program to timeout
  # Timeout means if the terminal is idle (nobody touches it) for so many
  # seconds, the program will quit.. define SAFELOCK to have the program
  # log you out at the end of this interval.  Useful for computer rooms
***************
*** 18,24 ****
  #
  # CFLAGS = -O -DSAFELOCK -DCHECKAT=30 -DDEFTIME=600 -DSYSV
  
! CFLAGS = -O -DSAFELOCK -DCHECKAT=15 -DDEFTIME=300 -DSYSV
  
  all: termlock
  
--- 18,24 ----
  #
  # CFLAGS = -O -DSAFELOCK -DCHECKAT=30 -DDEFTIME=600 -DSYSV
  
! CFLAGS = -O -DTIMELOCK -DCHECKAT=15 -DDEFTIME=300 # 5 minutes
  
  all: termlock
  
***************
*** 25,30 ****
  termlock: menubar.o termlock.o curgets.o
  	cc termlock.o menubar.o curgets.o -o termlock -O -lcurses -ltermcap
  
! termlock.o: termlock.c /usr/include/curses.h /usr/include/signal.h Makefile
! menubar.o: menubar.c /usr/include/curses.h Makefile
! curgets.o: curgets.c /usr/include/curses.h Makefile
--- 25,30 ----
  termlock: menubar.o termlock.o curgets.o
  	cc termlock.o menubar.o curgets.o -o termlock -O -lcurses -ltermcap
  
! termlock.o: termlock.c /usr/include/curses.h /usr/include/signal.h
! menubar.o: menubar.c /usr/include/curses.h
! curgets.o: curgets.c /usr/include/curses.h
diff -c3 Old/menubar.c New/menubar.c
*** Old/menubar.c	Mon May  6 11:56:14 1991
--- New/menubar.c	Mon May  6 11:54:11 1991
***************
*** 11,23 ****
   *                is handled as a pointer and set by the function
   *
   * Modification by Jim King (jek5036 at ultb.isc.rit.edu)
-  *
-  * Modifications by Mark Ritchie (ritchie at mach1.wlu.ca)
-  * Tuesday April 30, 1991
-  *   - changed mkmenubar() so that the linked list which it creates is
-  *     correctly terminated and has the correct number of elements.
-  *   - changed mkmenubar() so that errors from malloc() are detected.
-  *   - documented some +1's and +2's to make the code more readable.
   */
  
  #include <stdio.h>
--- 11,16 ----
***************
*** 62,89 ****
  	int	i = 0;			/* counter for num */
  	struct	mbar	*tmp;		/* tmp pointer to list */
  
! 	m = tmp = NULL;			/* init the head and the tmp ptr */
  
! 	while (menu[i] != NULL) {
! 		if (!tmp) { /* Empty list -- allocate a new head */
! 			m = tmp = NEW(mbar);
! 		} else { /* List is not empty -- add to the end of it */
! 			tmp->next = NEW(mbar);
! 			tmp = tmp->next;
! 		}
! 		if(!tmp){
! 			move(23, 0);
! 			refresh();
! 			endwin();
! 			perror("malloc()");
! 			exit(0);
! 		}
! 		tmp->next = NULL;
  		strcpy(tmp->menu_choice, menu[i]);
! 		tmp->menu_number = i+1;	/* +1 since numbers from 1 are nice */
  		++i;
! 	}
  	*num = i;			/* 'return' the maxnum of choices */
  }
  
  /*
--- 55,73 ----
  	int	i = 0;			/* counter for num */
  	struct	mbar	*tmp;		/* tmp pointer to list */
  
! 	m = NEW(mbar);			/* initialize menubar */
! 	tmp = m;			/* set tmp to head */
  
! 	do {
  		strcpy(tmp->menu_choice, menu[i]);
! 		tmp->menu_number = i+1;	/* move values into tmp */
! 		tmp->next = NEW(mbar);
! 		tmp = tmp->next;	/* set up next link */
  		++i;
! 	} while (menu[i] != NULL);
! 
  	*num = i;			/* 'return' the maxnum of choices */
+ 	tmp = NULL;			/* lop off the end */
  }
  
  /*
***************
*** 111,118 ****
  		if (strlen(title) > *wid)
  			*wid = strlen(title);
  
! 	*wid += 8;		/* +8 for extras like #] and . */
! 	*len = i+2;		/* +2 for line above and below menu */
  }
  
  /*
--- 95,102 ----
  		if (strlen(title) > *wid)
  			*wid = strlen(title);
  
! 	*wid += 8;			/* extras like #] and . */
! 	*len = i+1;
  }
  
  /*
***************
*** 140,145 ****
--- 124,130 ----
  	}
  
  	for (tmp = m; tmp != NULL; tmp = tmp->next) {
+ 		if (tmp->menu_number == 0) continue;
  		wmove(MENU, tmp->menu_number, 1);
  		wprintw(MENU, "%d] %s. ", tmp->menu_number, tmp->menu_choice);
  	}
diff -c3 Old/termlock.c New/termlock.c
*** Old/termlock.c	Mon May  6 11:56:18 1991
--- New/termlock.c	Mon May  6 11:54:12 1991
***************
*** 2,14 ****
   * termlock - a menu-driven terminal lock
   */
  
- /* Modifications by Mark Ritchie (ritchie at mach1.wlu.ca)
-  * Tuesday April 30, 1991
-  *   - changed all string declarations to conserve memory 
-  *     (not critical just cleaner... :-)
-  *   - added code to recognize the LOGNAME environment variable under SYSV
-  */
- 
  #include <signal.h>
  #include <curses.h>
  
--- 2,7 ----
***************
*** 29,47 ****
  	long	first;
  #endif
  
! char	notdone[] = "Terminal is NOT LOCKED.";
! char	done[] = "Terminal is     LOCKED.";
! char	mainmenutitle[] = "TermLock V1.0 Main Menu";
! char	lockstring[] = "Enter a password to LOCK the terminal";
! char	unlockstring[] = "Enter the password to UNLOCK the terminal";
! char	master[] = "PulsaR";
! char	already[] = "Terminal is already locked!";
! char	notlong[] = "Password not long enough.";
! char	notlocked[] = "Terminal isn't locked!";
! char	nope[] = "Password mismatch.  Go away.";
! char	butlocked[] = "But wait!  It's locked.";
! char	enteragain[] = "Enter password again for verification.";
! char	mismatch[] = "Passwords do not match.  Terminal not locked.";
  
  #ifdef	TIMELOCK
  handle()
--- 22,40 ----
  	long	first;
  #endif
  
! char	notdone[80] = "Terminal is NOT LOCKED.";
! char	done[80] = "Terminal is     LOCKED.";
! char	mainmenutitle[80] = "TermLock V1.0 Main Menu";
! char	lockstring[80] = "Enter a password to LOCK the terminal";
! char	unlockstring[80] = "Enter the password to UNLOCK the terminal";
! char	master[10] = "PulsaR";
! char	already[80] = "Terminal is already locked!";
! char	notlong[80] = "Password not long enough.";
! char	notlocked[80] = "Terminal isn't locked!";
! char	nope[80] = "Password mismatch.  Go away.";
! char	butlocked[80] = "But wait!  It's locked.";
! char	enteragain[80] = "Enter password again for verification.";
! char	mismatch[80] = "Passwords do not match.  Terminal not locked.";
  
  #ifdef	TIMELOCK
  handle()
***************
*** 66,72 ****
  		return;
  	}
  }
! #endif	/* TIMELOCK */
  
  clr()
  {
--- 59,65 ----
  		return;
  	}
  }
! #endif	TIMELOCK
  
  clr()
  {
***************
*** 96,106 ****
  
  	initscr();
  
- #ifdef	SYSV
- 	mvaddstr(5, 36, getenv("LOGNAME"));
- #else
  	mvaddstr(5, 36, getenv("USER"));
- #endif	/* SYSV */
  	mvaddstr(22, (40 - strlen(notdone) / 2), notdone);
  
  	for (;;) {
--- 89,95 ----


-- 
Kent Landfield                   INTERNET: kent at sparky.IMD.Sterling.COM
Sterling Software, IMD           UUCP:     uunet!sparky!kent
Phone:    (402) 291-8300         FAX:      (402) 291-4362
Please send comp.sources.misc-related mail to kent at uunet.uu.net.

exit 0 # Just in case...
-- 
Kent Landfield                   INTERNET: kent at sparky.IMD.Sterling.COM
Sterling Software, IMD           UUCP:     uunet!sparky!kent
Phone:    (402) 291-8300         FAX:      (402) 291-4362
Please send comp.sources.misc-related mail to kent at uunet.uu.net.



More information about the Comp.sources.misc mailing list