[net.bugs.4bsd] fix to the tip vadic 3451 code in 4.2bsd -- and an improvement

smk@axiom.UUCP (Steven M. Kramer) (01/20/84)

The dialer code had an error where an extra \r in the code disable the
dialing attempt.  I took that out.  Also, our vadic look-alike doesn't
look for EXACTLY the same words so a couple of mods are there (but
probably not necessary for most sites).  The improvement is to use
the interval timer code of 4.2 rather than sleeping a WHOLE second
between each character `typed'.  This speeds up the process tremeddously.
I found around 2/10 sec is a reasonable delay.

I hope this makes it to 43 so I don't have to fix the uucp/cu code in
each version of unix!

*** v3451.c.orig	Sat Jun 25 05:10:44 1983
--- v3451.c	Thu Jan 19 15:55:01 1984
***************
*** 6,11
   * Routines for calling up on a Vadic 3451 Modem
   */
  #include "tip.h"
  
  static	jmp_buf Sjbuf;
  

--- 6,19 -----
   * Routines for calling up on a Vadic 3451 Modem
   */
  #include "tip.h"
+ #ifdef AXIOM
+ #include <sys/time.h>
+ /* The sleeps done here are handled not by sleep(3), but by the
+    fast_sleep at the botton of this file (to get better resolution).
+ */
+ #define sleep(n)	fast_sleep(n*200000)
+ #define sleepx		fast_sleepx
+ #endif
  
  static	jmp_buf Sjbuf;
  
***************
*** 61,66
  	 * brain damaged design).
  	 */
  	vawrite("\r", 1 + slow);
  	vawrite("\r", 1 + slow);
  	if (!expect("DIALING:")) {
  		printf("Vadic failed to dial\n");

--- 69,86 -----
  	 * brain damaged design).
  	 */
  	vawrite("\r", 1 + slow);
+ #ifdef AXIOM
+ /*
+  *	This extra \r is BAD!!  It cancels the call and leaves the
+  *	3451 in limbo (which i heard was somewhere in North Dakota).
+  *
+  *	Also, the DIALING: below is wrong, it should be DIALING...
+  *	So I fixed that
+  *
+  *	1/9/84 Steve Kramer
+  */
+ 	if (!expect("DIALING...")) {
+ #else
  	vawrite("\r", 1 + slow);
  	if (!expect("DIALING:")) {
  #endif
***************
*** 63,68
  	vawrite("\r", 1 + slow);
  	vawrite("\r", 1 + slow);
  	if (!expect("DIALING:")) {
  		printf("Vadic failed to dial\n");
  #ifdef ACULOG
  		logent(value(HOST), num, "vadic", "failed to dial");

--- 83,89 -----
  #else
  	vawrite("\r", 1 + slow);
  	if (!expect("DIALING:")) {
+ #endif
  		printf("Vadic failed to dial\n");
  #ifdef ACULOG
  		logent(value(HOST), num, "vadic", "failed to dial");
***************
*** 174,176
  			return (1);
  	return (c == '\0');
  }

--- 195,259 -----
  			return (1);
  	return (c == '\0');
  }
+ #ifdef AXIOM
+ /*	We should really use the fast timer stuff because it's
+ 	unnecessary to wait a whole second between writes to
+ 	the Vadic.  This code was taken from sleep(3).
+ */
+ 
+ #define	mask(s)	(1<<((s)-1))
+ #define	setvec(vec, a) \
+ 	vec.sv_handler = a; vec.sv_mask = vec.sv_onstack = 0
+ 
+ static int ringring;
+ 
+ fast_sleep (n)
+ 	unsigned n;
+ {
+ 	int sleepx(), omask;
+ 	struct itimerval itv, oitv;
+ 	register struct itimerval *itp = &itv;
+ 	struct sigvec vec, ovec;
+ 
+ 	if (n == 0)
+ 		return;
+ 	timerclear(&itp->it_interval);
+ 	timerclear(&itp->it_value);
+ 	if (setitimer(ITIMER_REAL, itp, &oitv) < 0)
+ 		return;
+ 	setvec(ovec, SIG_DFL);
+ 	omask = sigblock(0);
+ 	itp->it_value.tv_sec = n/1000000;
+ 	itp->it_value.tv_usec = n%1000000;
+ 	if (timerisset(&oitv.it_value)) {
+ 		if (timercmp(&oitv.it_value, &itp->it_value, >))
+ 			oitv.it_value.tv_sec -= itp->it_value.tv_sec;
+ 		else {
+ 			itp->it_value = oitv.it_value;
+ 			/*
+ 			 * This is a hack, but we must have time to
+ 			 * return from the setitimer after the alarm
+ 			 * or else it'll be restarted.  And, anyway,
+ 			 * sleep never did anything more than this before.
+ 			 */
+ 			oitv.it_value.tv_sec = 1;
+ 			oitv.it_value.tv_usec = 0;
+ 		}
+ 	}
+ 	setvec(vec, sleepx);
+ 	(void) sigvec(SIGALRM, &vec, &ovec);
+ 	ringring = 0;
+ 	(void) setitimer(ITIMER_REAL, itp, (struct itimerval *)0);
+ 	while (!ringring)
+ 		sigpause(omask &~ mask(SIGALRM));
+ 	(void) sigvec(SIGALRM, &ovec, (struct sigvec *)0);
+ 	(void) setitimer(ITIMER_REAL, &oitv, (struct itimerval *)0);
+ }
+ 
+ static
+ sleepx()
+ {
+ 
+ 	ringring = 1;
+ }
+ #endif
-- 
	--steve kramer
	{allegra,genrad,ihnp4,utzoo,philabs,uw-beaver}!linus!axiom!smk	(UUCP)
	linus!axiom!smk@mitre-bedford					(MIL)