And this is how we wrote things in March, 1987. Lattice C, either 2.1 or 3.0...the last Lattice we used. Went to MS C 4 later in '87:
/*
*********************************************
* asynch communications function *
*********************************************
*/
/* comiox.c : c translation of nysdc standard fortran
subroutine to (a) dial up and logon to m3,
(b) write a string to m3, or (c) read a
string from m3.
gotten from Morristown sdc and used first in NAWGA
and Quickload by Adel & Barr, Inc. Rumor has
it that Mo'town got it from Berkeley pc engineering.
to use, include "comio.h"
3/7/86 MODIFIED TO CHECK FOR NO CARRIER OR SYSTEM UNAVAILABLE
9/15/86 modified to correct for bug discovered in PC front in
Zurich: xon was not being set as second com-record delimiter
*/
#include "sascomp.h"
comio()
{
int cmpst;
int tries;
char iodata[256];
char atdt_phone[30];
int rstat, r2stat, rdtry;
int cerr, comstat;
dbg_flg = FALSE; /* turn off echo: logon does it in box */
cparams[CINDX]->cdelcnt = 1;
cparams[CINDX]->cdelims[0] = CR; /* dc1,cr */
cparams[CINDX]->cdelims[1] = DC1; /* 0DH, 11H */
cparams[CINDX]->cparyflg = TRUE; /* parity check on (HRK 11-21-86)*/
tries = 0;
cerr = config(CPORT,1200,7,2,1); /* 1200bps,even,1stop */
if (cerr != 0) then
{
printf("\r\n config error=%d",comm_err);
return(COM_ERR);
}
RETRY: /* re-entry point */
cerr = copen(CPORT,&buff,1024);
if (cerr != 0) then
{
printf("\r\nError opening COM%d, =%d",CPORT,comm_err);
cclose(CPORT);
return(COM_ERR);
}
cparams[CINDX]->cstrcnt = 5;
cparams[CINDX]->cstrip[0] = 0x7f; /* del */
cparams[CINDX]->cstrip[1] = 0x00; /* null */
cparams[CINDX]->cstrip[2] = 0x0a; /* lf */
cparams[CINDX]->cstrip[3] = 0x0d; /* cr */
cparams[CINDX]->cstrip[4] = DC1;
cparams[CINDX]->cretryrd = 6000; /* try 5000 reads bef tmout */
cparams[CINDX]->cwrwait = 200;
cparams[CINDX]->creadwt = 50; /* delay 40MS between reads */
/* Set our window display for log on */
nocur(); /* turn off cursor */
window(14,3,20,78);
border(12); /* draw double line border around window */
strcpy(iodata," MARK III communications");
shwstr(1,3,iodata,11);
window(15,4,19,77); /* resize window to show inside box */
attrib(1);
clear(); /* clear the window, leave rest screen alone */
/* hangup phone: this is necessary if using Hayes internal modem, which
doesnt always know it's been hung up by host */
strcpy(iodata,"ATH0");
if ((comstat = comwr(iodata)) != OK)
return(COM_ERR);
scroll(1); /* display what we sent */
shwstr(5,2,iodata,1);
msdelay(2000);
/* NOW dial phone */
strcpy(atdt_phone,"ATDT");
strcat(atdt_phone,phone);
if ((comstat = comwr(atdt_phone)) != OK)
return(COM_ERR);
scroll(1);
shwstr(5,2,atdt_phone,1);
/* wrote phone #: now wait until we get "CONNECT" or timeout */
rdtry = 1;
if ((comstat = comrd(iodata)) != OK)
return(COM_ERR);
scroll(1);
shwstr(5,2,iodata,1);
rstat = strncmp(iodata,"CONNECT",7);
while (rstat != 0)
{
rdtry++;
if (rdtry == 5)
{
printf("\r\nFOUR tries, no connect");
cclose(CPORT);
return(COM_ERR);
} /* endif */
if ((comstat = comrd(iodata)) != OK)
return(COM_ERR);
scroll(1);
shwstr(5,2,iodata,1);
if ((rstat = strncmp(iodata,"NO CA",5)) == 0)
{
cclose(CPORT);
tries++;
beep();
scroll(2);
if (tries == 3)
{
cclose(CPORT);
strcpy(oplin,"Unable to Connect");
shwstr(5,2,oplin,1);
sofdel(2);
return(COM_ERR);
}
strcpy(oplin,"Redialing");
shwstr(5,2,oplin,1);
sofdel(1);
goto RETRY;
}
rstat = strncmp(iodata,"CONNECT",7);
} /* end while rstat */
/* send some HHHHH's */
cparams[CINDX]->cwrwait = 200; /* slow down our xmit */
cparams[CINDX]->ceolcnt = 0; /* don't send <cr> w/ HHHHs */
cparams[CINDX]->ceol[0] = '\0';
if ((comstat = comwr(HHHH)) != OK)
return(COM_ERR);
scroll(1);
shwstr(5,2,HHHH,1);
cparams[CINDX]->ceolcnt = 1; /* now change back to CR end write */
cparams[CINDX]->ceol[0] = CR;
/* look for U#= */
cparams[CINDX]->cdelims[1] = 0x11; /* DC1, or XON, if you prefer */
cparams[CINDX]->cdelcnt = 2; /* add dc1 to delims */
if ((comstat = comrd(iodata)) != OK)
return(COM_ERR);
scroll(1);
shwstr(5,2,iodata,1);
rstat = strncmp(iodata,"U#=",3);
if (rstat != 0) then
{
printf("\r\nConnected, but garbage, not U#");
hangup();
cclose(CPORT);
return(COM_ERR);
}
/* send user number */
if ((comstat = comwr(USR_NUM)) != OK)
return(COM_ERR);
strcpy(iodata,"AGY02900,!!!!!!");
shwstr(5,5,iodata,1);
rstat = 1;
r2stat = 1;
while ((rstat && r2stat) != 0)
{
if ((comstat = comrd(iodata)) != OK)
return(COM_ERR);
scroll(1);
shwstr(5,2,iodata,1);
if ((cmpst = strncmp(iodata,"SYSTEM UNAVAIL",11)) == 0)
{
beep();
msdelay(7000);
cclose(CPORT);
window(1,1,25,80);
clear();
attrib(1);
rowcol(1,1);
printf("\r\nMARK III SYSTEM UNAVAILABLE!!!!!!!!");
printf("\r\nCONTACT ADMINISTRATIVE PERSONNEL!!!!!!!");
c = getch();
exit(1);
}
rstat = strncmp(iodata,"READY",5);
r2stat = strncmp(iodata,"USED",4);
} /* end while iodata != READY or USED */
/* logged on : send HOLD and wait for ready from it */
if ((comstat = comwr(HOLD)) != OK)
return(COM_ERR);
scroll(1);
shwstr(5,2,HOLD,1);
rstat = 1;
r2stat = 1;
while ((rstat && r2stat) != 0)
{
if ((comstat = comrd(iodata)) != OK)
return(COM_ERR);
scroll(1);
shwstr(5,2,iodata,1);
rstat = strncmp(iodata,"READY",5);
r2stat = strncmp(iodata,"USED",4);
}
/* ok, we're almost ready to get back to the calling program
but first, shorten the delay between chars we send */
cparams[CINDX]->cretryrd = 6000;
cparams[CINDX]->cwrwait = 0;
/* and change window back to correct size */
window(14,1,20,80);
clear();
attrib(1);
window(1,1,25,80);
border(11);
/* finished logon */
return(OK);
} /* end function comio */
/*
*************************
* hangup *
*************************
*/
hangup()
#define PLUSES "+++"
#define ATH0 "ATH0"
{
char iodata[256];
int comstat;
cparams[CINDX]->cwrwait = 100;
cparams[CINDX]->cretryrd = 3800; /* 2 second wait */
cparams[CINDX]->ceolcnt = 0;
cparams[CINDX]->ceol[0] = '\0';
sofdel(2);
if ((comstat = comwr(PLUSES)) != OK)
return(COM_ERR);
sofdel(1);
rdcnt = cread(CPORT,iodata,80);
cparams[CINDX]->ceolcnt = 1; /* now change back to CR end write */
cparams[CINDX]->ceol[0] = CR;
if ((comstat = comwr(ATH0)) != OK)
return(COM_ERR);
rdcnt = cread(CPORT,iodata,80);
cclose(CPORT);
return(OK);
} /* return */
/*********************************
* one second software delay *
*********************************/
sofdel(secdel)
int secdel;
{
int msarg;
msarg = 1000*secdel;
msdelay(msarg);
return;
}