biz31.c revision 8d489c7a815fcac696803219572e95aa01532b0f
/*
* 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.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include "tip.h"
static int detect(char *);
static int bizsync(int);
static void echo(char *);
static void flush(char *);
static void sigALRM(void);
static int timeout = 0;
static sigjmp_buf timeoutbuf;
void biz31_disconnect(void);
/*
* Dial up on a BIZCOMP Model 1031 with either
* tone dialing (mod = "f")
* pulse dialing (mod = "w")
*/
static int
{
int connected = 0;
(void) printf("bizcomp out of sync\n");
exit(0);
}
(void) printf("\nstarting call...");
echo("$\r$\n");
echo("\r$\n$\r$\n");
echo("\r$\n");
(void) 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);
}
/* ARGSUSED */
int
{
}
/* ARGSUSED */
int
{
}
void
biz31_disconnect(void)
{
(void) sleep(2);
}
void
biz31_abort(void)
{
}
static void
echo(char *s)
{
char c;
while (c = *s++) {
switch (c) {
case '$':
s++;
break;
case '#':
c = *s++;
break;
default:
}
}
}
static void
sigALRM(void)
{
timeout = 1;
}
static int
detect(char *s)
{
char c;
timeout = 0;
while (*s) {
(void) printf("\07timeout waiting for reply\n");
biz31_abort();
break;
}
(void) alarm(0);
if (c != *s++)
break;
}
return (timeout == 0);
}
static void
flush(char *s)
{
char c;
while (*s++) {
break;
(void) alarm(10);
(void) 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
int already = 0;
char buf[10];
(void) sleep(1);
if (chars(b) != 10) {
nono:
return (0);
(void) sleep(2);
already++;
goto retry;
} else {
goto nono;
}
}
return (1);
}