biz31.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright (c) 1983 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
*/
#ident "%Z%%M% %I% %E% SMI" /* from UCB 4.7 6/25/83 */
#include "tip.h"
static void sigALRM();
static int timeout = 0;
static sigjmp_buf timeoutbuf;
/*
* Dial up on a BIZCOMP Model 1031 with either
* tone dialing (mod = "f")
* pulse dialing (mod = "w")
*/
static int
{
register int connected = 0;
printf("bizcomp out of sync\n");
exit(0);
}
printf("\nstarting call...");
echo("$\r$\n");
echo("\r$\n$\r$\n");
echo("\r$\n");
printf("ringing...");
/*
* The reply from the BIZCOMP should be:
* `^G NO CONNECTION\r\n^G\r\n' failure
* ` CONNECTION\r\n^G' success
*/
#ifdef ACULOG
if (timeout) {
char line[80];
}
#endif
if (!connected)
flush(" NO CONNECTION\r\n\07\r\n");
else
flush("CONNECTION\r\n\07");
if (timeout)
biz31_disconnect(); /* insurance */
return (connected);
}
{
}
{
}
{
sleep(2);
}
{
}
static int
echo(s)
register char *s;
{
char c;
while (c = *s++) {
switch (c) {
case '$':
s++;
break;
case '#':
c = *s++;
break;
default:
}
}
}
static void
sigALRM()
{
timeout = 1;
}
static int
detect(s)
register char *s;
{
char c;
timeout = 0;
while (*s) {
printf("\07timeout waiting for reply\n");
biz31_abort();
break;
}
alarm(0);
if (c != *s++)
break;
}
return (timeout == 0);
}
static int
flush(s)
register char *s;
{
char c;
while (*s++) {
break;
alarm(10);
alarm(0);
}
timeout = 0; /* guard against disconnection */
}
/*
* This convoluted piece of code attempts to get
* the bizcomp in sync. If you don't have the capacity or nread
* call there are gory ways to simulate this.
*/
static int
{
#ifdef FIOCAPACITY
struct capacity b;
#define IOCTL FIOCAPACITY
#endif
#ifdef FIONREAD
long b;
#define chars(b) (b)
#endif
register int already = 0;
char buf[10];
sleep(1);
if (chars(b) != 10) {
nono:
return (0);
sleep(2);
already++;
goto retry;
} else {
goto nono;
}
}
return (1);
}