home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Jason Aller Floppy Collection
/
164.img
/
UUPC.ZIP
/
LOCAL.ZIP
/
ULIB.C
< prev
Wrap
C/C++ Source or Header
|
1987-08-26
|
5KB
|
260 lines
/* ibmpc/ulib.c
DCP system-dependent library
Services provided by ulib.c:
serial I/O
UNIX commands simulation
login
*/
#include <string.h>
#include "dcp.h"
/*
login - login handler
*/
/* Currently a very dumb login handshake for PC in slave mode. */
login()
{
char line[132];
for ( ; ; ) {
msgtime = 9999; /* make it very long */
rmsg(line, 0); /* wait for a <CR> or <NL> */
msgtime = 2 * MSGTIME;
wmsg("Login:", 0);
rmsg(line, 0);
printmsg(0, "login: login=%s", line);
wmsg("Password:", 0);
rmsg(line, 0);
printmsg(14, "login: password=%s", line);
if (strcmp(line, "uucp") == SAME)
break;
};
return('I');
} /*login*/
/*
notimp - "perform" Unix commands which aren't implemented
*/
notimp(argc, argv)
int argc;
char *argv[];
{
fprintf(stderr, "shell: command '%s' is not implemented.\n", *argv);
} /*notimp*/
/*
shell - simulate a Unix command
Only the 'rmail' and 'rnews' command are currently supported.
*/
shell(command, inname, outname, errname)
char *command;
char *inname;
char *outname;
char *errname;
{
char *argvec[50];
int rmail();
int rnews();
char **argvp;
char argcp;
int (*proto)();
argcp = getargs(command, argvec);
argvp = argvec;
if ( debuglevel > 5 ) {
int args;
args = argcp;
while ( args )
fprintf(stderr, "shell: args: %d, %s\n", args--, *argvp++);
argvp = argvec;
}
proto = notimp;
if (strcmp(*argvp, "rmail") == SAME)
proto = rmail;
else if (strcmp(*argvp, "rnews") == SAME)
proto = rnews;
if (*inname != '\0') {
char localname[64];
importpath(localname, inname);
if (freopen(localname, "rb", stdin) == NULL) {
extern int errno;
fprintf(stderr, "shell: couldn't open %s (%s), errno=%d.\n",
inname, localname, errno);
}
}
(*proto)(argcp, argvp);
freopen("con", "r", stdin);
} /*shell*/
/* IBM-PC I/O routines */
/* "DCP" a uucp clone. Copyright Richard H. Lamb 1985,1986,1987 */
/*************** BASIC I/O ***************************/
/* Saltzers serial pkg */
/* Some notes: When pkts are flying in both directions, there seems to */
/* be some interupt handling problems as far as recieving. checksum errs*/
/* may therfore occur often even though we recover from them. This is */
/* especially true with sliding windows. Errors are very few in the VMS */
/* version. RH Lamb*/
#include "comm.h"
#define STOPBIT 1
/*
swrite - write to the serial port
*/
swrite(data, num)
int num;
char *data;
{
int i;
for (i = 0; i < num; i++) send_com(*(data++));
return(i);
} /*swrite*/
/*
sread - read from the serial port
*/
/* Non-blocking read essential to "g" protocol.
See "dcpgpkt.c" for description.
This all changes in a multi-tasking system. Requests for
I/O should get queued 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.
Could be implemented on VAX/VMS or DG but not MS-DOS. */
sread(buf, expected, timeout)
char *buf;
int expected, timeout;
{
long start;
start = time((long *)NULL);
for ( ; ; ) {
int pending;
pending = r_count_pending();
printmsg(20, "---> pending=%d expected=%d", pending, expected);
if (pending >= expected) {
int i;
for (i = 0; i < expected; i++)
*(buf++) = receive_com();
return(pending);
} else {
int elapsed;
elapsed = time((long *)NULL) - start;
if (elapsed >= timeout)
return(pending);
}
}
} /*sread*/
/*
openline - open the serial port for I/O
*/
openline(name, baud)
char *name, *baud;
{
int i;
sscanf(name, "COM%d", &i);
select_port(i);
save_com();
install_com();
sscanf(baud, "%d", &i);
open_com(i, 'D', 'N', STOPBIT, 'D');
dtr_on();
return(0);
} /*openline*/
/*
closeline - close the serial port down
*/
closeline()
{
dtr_off();
close_com();
restore_com();
} /*closeline*/
/*
sleep() - wait n seconds
Simply delay until n seconds have passed.
*/
void sleep(interval)
int interval;
{
long start;
start = time((long *)NULL);
while ((time((long *)NULL) - start) < interval);
} /*sleep*/
/*
SIOSpeed - re-specify the speed of an opened serial port
*/
void SIOSpeed(baud)
char *baud;
{
int speed;
dtr_off();
close_com();
sscanf(baud, "%d", &speed);
open_com(speed, 'D', 'N', STOPBIT, 'D');
dtr_on();
} /*SIOSpeed*/