home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
TELECOM
/
tterm_src.lzh
/
dial.c
< prev
next >
Wrap
Text File
|
1996-03-04
|
5KB
|
219 lines
/*********************************************************************
dial.c - dialing routines for tterm
*********************************************************************/
#include "common.h"
#define DIRECTORY "/USR/TTERM/"
#define EXTENSION ".dial" /* append to username */
#define MAXUNLEN FILENAME_MAX-5 /* truncate user name if necessary */
#define MAXENTRYS 10 /* for now */
typedef struct host
{
char
namestr[32],
dialstr[32];
} HOSTLIST;
HOSTLIST *hostlist;
char
dialerfile[128], /* name of dialer file */
*m_responses[]={ /* modem responses */
"CONNECT","NO CARRIER","NO DIALTONE","BUSY","NO ANSWER","ERROR","OK",0};
extern void
DialerToScreen(int);
extern int
DialerCleanup(void);
/*********************************************************************
SET the DIALER FILE
*********************************************************************/
SetDialerFile()
{
char *t;
strcpy(dialerfile,DIRECTORY);
t=getenv("USER"); /* get the user name */
if(t == 0)
t="generic";
sprintf(dialerfile,"%s%s%s%s",SysDev(),DIRECTORY,t,EXTENSION);
tprint("Dialer file is ");tprint(dialerfile);tprint("\012\n");
}
/*********************************************************************
DIALER
*********************************************************************/
Dialer()
{
u_int32 interval=g_tickrate/6;
u_int32 snooze;
signal_code wakeup;
int khar;
char
*t,
dialstr[32];
t_puts("Checking For Modem...");
m_puts("AT\n");
if(WaitSerial(5) == 0)
{
tprint(
"\012\nModem is not responding or is not attached to this port\012\n");
return 0;
}
ClearLine();
t_puts("OK.\012\n");
if(GetNumber(dialstr) == -1)
{
tprint("ABORTED!\012\n");
return 0;
}
t_puts("\012\nDialing...");
t=dialstr;
while(*t)
{
m_putc(*t++);
while(!ModemReady());
khar=m_getc();
ToScreen(khar);
}
T_PutC = DialerToScreen;
}
/*********************************************************************
DIALER TO SCREEN function - this isn't necessary but I wrote it in JIC
I ever figure out how to make a decent login macro work
*********************************************************************/
void DialerToScreen(int khar)
{
static char
to[80],
*ip=to;
int cntr;
ToScreen(khar); /* have to write it out anyway */
*ip++ = khar;
if(khar == 0x0A) /* if a linefeed */
{
*ip = 0;
ip = to;
cntr = 0;
while(m_responses[cntr] != 0) /* check for valid final message */
{
if(strstr(to,m_responses[cntr++]) != 0)
nextphase = TRUE;
}
}
}
/*********************************************************************
GET a NUMBER to dial - returns -1 on error
*********************************************************************/
GetNumber(char *dialstr)
{
FILE *fpath;
int cntr,top,listsize;
int status,rtn;
HOSTLIST *host;
char outstr[80];
fpath=fopen(dialerfile,"r");
if(fpath == 0)
{
tprint("\012\nUnable to open dial directory ");
tprint(dialerfile); tprint("\012\n");
return -1;
}
top=MAXENTRYS;
listsize=0;
hostlist=malloc(sizeof(HOSTLIST) * top);
if(hostlist == 0)
return -1;
host=hostlist;
status=0;
while(status != 1)
{
status=LoadDialRecord(host,fpath);
if(status == 0)
{
host++;
listsize++;
if(listsize >= top)
break;
}
}
fclose(fpath);
if(listsize == 0) /* if no entrys */
{
tprint(dialerfile); tprint(" has no valid entries!\012\n");
return -1;
}
tprint("\012\nDialing directory from ");
tprint(dialerfile); tprint("\012\012\n");
for(cntr=0; cntr < listsize; cntr++)
{
sprintf(outstr,"%d. %s\012\n",cntr,hostlist[cntr].namestr);
tprint(outstr);
}
t_puts("Selection? ");
eatterminal();
status=GetOneChar();
status-=0x30;
if(status < 0 || status > listsize)
rtn=-1;
else
{
strcpy(dialstr,hostlist[status].dialstr);
rtn=1;
}
free(hostlist);
return rtn;
}
/*********************************************************************
LOAD a DIALer RECORD - currently only two lines are relevant
returns 0 if an entire record and terminator read
1 if end of file
-1 if error in record entry
*********************************************************************/
LoadDialRecord(h,fpath)
HOSTLIST *h;
FILE *fpath;
{
char instring[128];
/* get the host name */
if(fgets(instring,128,fpath) == 0)
return 1;
if(instring[0] == '/' && instring[1] == '/')
return -1;
strncpy(h->namestr,instring,31);
/* get the dial string */
if(fgets(instring,128,fpath) == 0)
return 1;
if(instring[0] == '/' && instring[1] == '/')
return -1;
strncpy(h->dialstr,instring,31);
/* search for a '//' or EOF -- this lets us add entrys later w/o
sacrificing compatability */
while(fgets(instring,128,fpath) != 0)
{
if(instring[0] == '/' && instring[1] == '/')
return 0;
}
return 1;
}