home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Columbia Kermit
/
kermit.zip
/
c
/
qnxcon.c
< prev
next >
Wrap
C/C++ Source or Header
|
2020-01-01
|
3KB
|
142 lines
/*
* connect command for QNX
*
*/
/*
* c o n n e c t
*
* Establish a virtual terminal connection with the remote host, over an
* assigned tty line.
*/
#include <io.h>
#include <dev.h>
#include <stdio.h>
#define TRUE 1
#define FALSE 0
#define ctl(x) ((x) ^ 64)
#define unpar(ch) ((ch) & 127)
#define KILL 0x0100
#define EXC_BREAK 0x0002
extern int remote,
lecho,
speed;
extern char escchr, *ttyname;
connect()
{
int pid, /* process id of child task */
exstat, /* exit status of child */
connected; /* Boolean connect flag */
char bel = '\07', /* DING !! */
c,
term[5]; /* the controlling terminal */
unsigned oldconr, oldconw; /* [???] should this be here? */
if (remote) /* Nothing to connect to in remote */
{ /* mode, so just return */
printmsg("No line specified for connection.");
return;
}
speed = 0; /* Don't set the console's speed */
sprintf(term, "$tty%d", fdevno(stderr));
pid = fork(); /* Start fork to get typeout from remote host */
if (pid) /* parent: read from terminal, send out port */
{
FILE *tt2r, *ttyw;
if ((tt2r = fopen(term,"r")) == NULL) {
fprintf(stderr,"Can't open console\n"); /* Open up the console */
return;
}
ttbin(tt2r,&oldconr);
if ((ttyw = fopen(ttyname, "wu")) == NULL) {
fprintf(stderr,"Can't open tty line\n");
return;
}
printmsg("connected...\r");
connected = TRUE; /* Put us in "connect mode" */
while (connected)
{
c = getc(tt2r); /* Get a character */
c = unpar(c); /* Turn off the parity */
if (c == escchr) /* Check for escape character */
{
c = getc(tt2r);
c = unpar(c); /* Turn off the parity */
if (c == escchr)
{
c = dopar(c); /* Do parity if the user requested */
putc(c, ttyw); /* write to tty line */
}
else
switch (toupper(c))
{
case 'C':
connected = FALSE;
fprintf(stdout,"\r\n");
break;
case 'H':
{
char hlpbuf[100],e;
sprintf(hlpbuf,
"\n\n C to close the connection\n B to send a break\n");
fprintf(stdout, hlpbuf);
e = escchr;
if (e < ' ') {
putc('^', stderr);
e = ctl(e);
}
sprintf(hlpbuf," %c to send itself\r\n",e);
fprintf(stdout, hlpbuf);
break;
}
case 'B':
combreak(ttyw);
break;
default:
putc(bel, stderr);
break;
}
}
else
{ /* If not escape charater, */
if (lecho) putc(c, stdout); /* Echo char if requested */
c = dopar(c); /* Do parity if the user requested */
putc(c, ttyw); /* write it out */
c = NULL; /* Nullify it (why?) */
}
}
set_exception(pid, KILL, 0); /* Done, kill the child */
wait(&exstat); /* and bury him */
ttres(tt2r,&oldconr);
printmsg("disconnected.");
return; /* Done */
}
else /* child: read remote input, output to console */
{
char c;
FILE *ttyr;
if ((ttyr = fopen(ttyname , "r")) == NULL)
fprintf(stderr,"Can't open tty line in interior fork\n");
stdout = fopen(term,"w");
while (1)
{
c = getc(ttyr); /* read a character */
putc(c, stdout); /* write to terminal */
fflush(stdout);
}
}
}