home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
TELECOM
/
UUCP_Blars.lzh
/
dcpio.c
< prev
next >
Wrap
Text File
|
1992-01-25
|
6KB
|
338 lines
/*
* "DCP" a uucp clone. Copyright Richard H. Lamb 1985,1986,1987
* IO routines
* Ported to OS-9/68000: Wolfgang Ocker January 1988
*/
#include <sgstat.h>
#include <signal.h>
#include "dcp.h"
#ifndef min
#define min(a,b) ((a<b)?(a):(b))
#endif
extern int I_HAVE_HAYES;
struct _sgs ttybufa, ttybufb;
static short rflag;
int fpr, fpw;
static int line_baud;
static int byte_rates[] = { 5, 7, 11, 13, 15, 30, 60, 120, 180,
200, 240, 360, 480, 720, 960, 1920 } ;
static char last_device[40] = "";
void clkint(signum)
{
switch (signum) {
case SIG_DATAREADY:
rflag = TRUE;
break;
case SIG_CARRIER:
;
default:
;
}
}
setline(tty, baud)
int tty, baud;
{
_gs_opt(tty, &ttybufa);
ttybufb = ttybufa;
if (baud < 0) {
ttybufa._sgs_parity = D8S1NONE | 0x80; /* RTS/CTS */
baud = -baud;
_ss_enrts(tty);
}
else
if (baud == 0)
ttybufa._sgs_parity = (ttybufa._sgs_parity & 0x80) | D8S1NONE;
else
ttybufa._sgs_parity = D8S1NONE;
ttybufa._sgs_echo = 0;
ttybufa._sgs_pause = 0;
ttybufa._sgs_case = 0;
ttybufa._sgs_backsp = 0;
ttybufa._sgs_delete = 0;
ttybufa._sgs_alf = 0;
ttybufa._sgs_nulls = 0;
ttybufa._sgs_bspch = 0;
ttybufa._sgs_dlnch = 0;
ttybufa._sgs_eorch = 0;
ttybufa._sgs_eofch = 0;
ttybufa._sgs_rlnch = 0;
ttybufa._sgs_dulnch = 0;
ttybufa._sgs_psch = 0;
ttybufa._sgs_kbich = 0;
ttybufa._sgs_kbach = 0;
ttybufa._sgs_bsech = 0;
ttybufa._sgs_bellch = 0;
ttybufa._sgs_xon = 0;
ttybufa._sgs_xoff = 0;
ttybufa._sgs_tabcr = 0;
if (baud) {
ttybufa._sgs_baud = baud;
line_baud = baud;
}
else
line_baud = ttybufa._sgs_baud;
_ss_opt(tty, &ttybufa);
}
swrite(data, num)
int num;
unsigned char *data;
{
write(fpw, data, num);
printmsg(10, "swrite: \"%.*s\"", num, data);
return(num);
}
/*
* non-blocking read essential to "g" protocol
* see "dcpgpkt.c" for description
* Requests for I/O should get qued and an event flag given. Then the
* REQUESTING process (e.g.gmachine()) waits for the event
* flag to fire processing either a read or a write.
*/
sread(buf, num, timeout)
register int num;
register unsigned char *buf;
int timeout;
{
register int ticks, wait_ticks;
register int to_read;
static int clk_tck = -1;
static int sig_not_init = TRUE;
if (timeout <= 0)
if (_gs_rdy(fpr) < num)
return(0);
else
return(read(fpr, buf, num));
if (sig_not_init) {
intercept(clkint);
sig_not_init = FALSE;
clk_tck = CLK_TCK;
}
ticks = timeout * clk_tck;
while (ticks > 0) {
rflag = FALSE;
if ((to_read = _gs_rdy(fpr)) >= num)
return(read(fpr, buf, num));
to_read = num - to_read; /* Anzahl zu lesender Zeichen */
wait_ticks = to_read * clk_tck / byte_rates[line_baud];
if (wait_ticks <= 10) {
_ss_ssig(fpr, SIG_DATAREADY);
sigmask(1);
if (rflag) {
_ss_rel(fpr);
sigmask(-1);
continue;
}
ticks = tsleep(ticks);
_ss_rel(fpr);
}
else
ticks = tsleep(min(ticks, wait_ticks));
}
if (_gs_rdy(fpr) >= num)
return(read(fpr, buf, num));
return(0);
}
#ifdef NOTDEF
/*
* To realize a timeout under OS-9 we must use the _ss_ssig()
* PutStat and a sleep()
*/
for (i = 0; i < num; ) {
while ((_gs_rdy(fpr) > 0) && (i < num)) {
read(fpr, &c, 1);
buf[i++] = c;
}
if (i < num) {
rflag = FALSE;
_ss_ssig(fpr, SIG_DATAREADY);
tsleep(1);
if (!rflag && (_gs_rdy(fpr) <= 0) && !rflag) {
if (sleep(timeout) == 0)
if (!rflag && (_gs_rdy(fpr) <= 0) && !rflag) {
printmsg(1, "Time out (%d)!!!", timeout);
_ss_rel(fpr);
return(i);
}
}
if (!rflag)
_ss_rel(fpr);
}
}
return(i);
}
#endif
openline(name, speed)
char *name;
char *speed;
{
if (name != NULL)
if (last_device[0] != '\0' && strcmp(last_device, name)) {
last_device[0] = '\0';
}
printmsg(8, "open line %s, speed %s", (name ? name : "NULL"),
(speed ? speed : "NULL"));
if (name == NULL)
return(openrline());
else
strcpy(last_device, name);
if ((fpr = open(name, S_IREAD | S_IWRITE | S_ISHARE)) < 0)
return(-1);
fpw = fpr;
setline(fpw, getbaud(speed));
return(0);
}
openrline()
{
fpw = 1;
fpr = 0;
setline(fpw, 0);
setline(fpr, 0);
}
/* closeline()
{
if (fpr != -1) {
_ss_opt(fpr, &ttybufb);
close(fpr);
}
if (fpw != -1) {
_ss_opt(fpw, &ttybufb);
close(fpw);
}
}
*/
closeline()
{
if (I_HAVE_HAYES && (fpw != -1)) {
sleep(2);
write(fpw, "+++", 3);
sleep(2);
write(fpw, "\raaaatz\r", 8);
sleep(2);
}
last_device[0] = '\0';
if (fpr != -1) {
_ss_opt(fpw, &ttybufb);
close(fpr);
}
if (fpw != -1 && fpw != fpr) {
_ss_opt(fpr, &ttybufb);
close(fpw);
}
}
#define ABS(x) ((x) < 0 ? -(x) : (x))
int SIOSpeed(s)
char *s;
{
int baud;
if (baud = ABS(getbaud(s))) {
ttybufa._sgs_baud = baud;
_ss_opt(fpw, &ttybufa);
_ss_opt(fpr, &ttybufa);
}
}
struct {
int baudrate;
char *code;
} rates[] = { {B19200, "19200"},
{B9600, "9600"},
{B4800, "4800"},
{B2400, "2400"},
{B1200, "1200"},
{B300, "300"} };
int getbaud(s)
char *s;
{
int i, baud;
char c;
char stmp[100];
if (s == NULL)
return(0);
strcpy(stmp, s);
s = stmp;
c = s[strlen(s)-1];
if (!isdigit(c))
s[strlen(s)-1] = '\0';
i = baud = 0;
do {
if (strcmp(s, rates[i].code) == 0) {
baud = rates[i].baudrate;
break;
}
} while (rates[++i].baudrate != 0);
if (baud == 0)
baud = B1200;
if (c == 'h' || c == 'H' || c == 'r' || c == 'R')
baud = -baud;
return(baud);
}