#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)acu.c 8.1 (Berkeley) 6/6/93";
#endif
__RCSID("$NetBSD: acu.c,v 1.18 2021/09/11 20:28:06 andvar Exp $");
#endif
#include "tip.h"
static acu_t *acu = NULL;
static int conflag;
static jmp_buf jmpbuf;
__dead static void acuabort(int);
static acu_t *acutype(char *);
const char *
tip_connect(void)
{
char * volatile cp;
char *phnum, string[256];
FILE *fd;
int volatile tried;
cp = PN;
tried = 0;
if (!DU) {
if (CM != NULL)
xpwrite(FD, CM, strlen(CM));
return (NULL);
}
(void)signal(SIGINT, acuabort);
(void)signal(SIGQUIT, acuabort);
if (setjmp(jmpbuf)) {
(void)signal(SIGINT, SIG_IGN);
(void)signal(SIGQUIT, SIG_IGN);
(void)printf("\ncall aborted\n");
if (acu != NULL) {
setboolean(value(VERBOSE), FALSE);
if (conflag)
disconnect(NULL);
else
(*acu->acu_abort)();
}
return ("interrupt");
}
if ((acu = acutype(AT)) == NULL)
return ("unknown ACU type");
if (*cp != '@') {
while (*cp) {
for (phnum = cp; *cp && *cp != ','; cp++)
;
if (*cp)
*cp++ = '\0';
if ((conflag = (*acu->acu_dialer)(phnum, CU)) != 0) {
if (CM != NULL)
xpwrite(FD, CM, strlen(CM));
return (NULL);
} else
tried++;
}
} else {
if ((fd = fopen(PH, "r")) == NULL) {
(void)printf("%s: ", PH);
return ("can't open phone number file");
}
while (fgets(string, sizeof(string), fd) != NULL) {
for (cp = string; !any(*cp, " \t\n"); cp++)
;
if (*cp == '\n') {
(void)fclose(fd);
return ("unrecognizable host name");
}
*cp++ = '\0';
if (strcmp(string, value(HOST)))
continue;
while (any(*cp, " \t"))
cp++;
if (*cp == '\n') {
(void)fclose(fd);
return ("missing phone number");
}
for (phnum = cp; *cp && *cp != ',' && *cp != '\n'; cp++)
;
if (*cp)
*cp++ = '\0';
if ((conflag = (*acu->acu_dialer)(phnum, CU)) != 0) {
(void)fclose(fd);
if (CM != NULL)
xpwrite(FD, CM, strlen(CM));
return (NULL);
} else
tried++;
}
(void)fclose(fd);
}
if (!tried) {
}
else
(*acu->acu_abort)();
return (tried ? "call failed" : "missing phone number");
}
void
disconnect(const char *reason)
{
if (!conflag) {
return;
}
if (reason == NULL) {
if (boolean(value(VERBOSE)))
(void)printf("\r\ndisconnecting...");
} else
(*acu->acu_disconnect)();
}
static void
acuabort(int s)
{
(void)signal(s, SIG_IGN);
longjmp(jmpbuf, 1);
}
static acu_t *
acutype(char *s)
{
acu_t *p;
for (p = acutable; p->acu_name != NULL; p++)
if (!strcmp(s, p->acu_name))
return (p);
return (NULL);
}