home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Columbia Kermit
/
kermit.zip
/
archives
/
ncr9800.tar.gz
/
ncr9800.tar
/
ckvcon.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-07-13
|
13KB
|
382 lines
char *connv = "Connect Command for VRX/E, V4E(017) 10 May 90";
/* C K V C O N -- Dumb terminal connection to remote system, for NCR-VRX */
/**********************************************************************
* *
* IVS / MCS-Kermit REL 2 *
* source code *
* *
* Change History: *
* *
* 1. Modify C-Kermit(4E) source code to *
* produce new module for MCS/IVS-Kermit *
* ORIGINAL RELEASE *
* June 22, 1990 *
* *
* *
***********************************************************************/
/*
This module should work under all versions of NCR-VRX. It calls externally
defined system-dependent functions for i/o, but depends upon the existence
of the FORK() function.
Author: Frank da Cruz (SY.FDC@CU20B),
Columbia University Center for Computing Activities, January 1985.
Copyright (C) 1985, Trustees of Columbia University in the City of New York.
Permission is granted to any individual or institution to use, copy, or
redistribute this software so long as it is not sold for profit, provided this
copyright notice is retained.
Enhanced by H. Fischer to detect when child process (modem reader)
reports that the communications line has been broken and hang up.
Also enhanced to allow escaping from connect state to command
interpreter, to allow sending/receiving without breaking connection.
*/
#include <stdio.h>
#include <ctype.h> /* Character types */
#include "ckcdeb.h"
#include "ckcker.h"
#include <signal.h>
#include "kermisc.h"
#include <setjmp.h> /* Longjumps */
#ifdef MCS_FLAG
#include "mcs.h"
#endif
#ifndef SIGUSR1
#define SIGUSR1 16
#endif
extern int local, speed, escape, duplex, parity, flow, seslog, mdmtyp;
extern int errno, cmask, fmask, deblog;
extern char ttname[], sesfil[];
extern CHAR dopar();
extern void errhdlr();
int i, active; /* Variables global to this module */
int io_retry = 0;
char *chstr();
char temp[50];
#define LBUFL 200 /* Line buffer */
char lbuf[LBUFL];
/* Connect state parent/child communication signal handlers */
static jmp_buf env_con; /* Envir ptr for connect errors */
static
conn_int()
{ /* Modem read failure handler, */
longjmp(env_con, 1); /* notifies parent process to stop */
}
/* C O N E C T -- Perform terminal connection */
conect()
{
int pid, /* process id of child (modem reader) */
parent_id, /* process id of parent (keyboard reader) */
n;
int c; /* c is a character, but must be signed
integer to pass thru -1, which is the
modem disconnection signal, and is
different from the character 0377 */
char errmsg[50], *erp;
if (!local) {
#ifndef MCS_FLAG
printf("Sorry, you must 'set line' first\n");
#else
mcs_printf("Sorry, you must 'set line' first\n");
#endif
return(-2);
}
if (speed < 0) {
#ifndef MCS_FLAG
printf("Sorry, you must 'set speed' first\n");
#else
mcs_printf("Sorry, you must 'set speed' first\n");
#endif
return(-2);
}
if ((escape < 0) || (escape > 0177)) {
#ifndef MCS_FLAG
printf("Your escape character is not ASCII - %d\n",
escape);
#else
sprintf(print_str,"Your escape character is not ASCII - %d\n",
escape);
mcs_printf(print_str);
#endif
return(-2);
}
if (ttopen(ttname, &local, mdmtyp) < 0) {
erp = errmsg;
sprintf(erp, "conect: Sorry, can't open %s", ttname);
errhdlr(errmsg);
return(-2);
}
#ifndef MCS_FLAG
printf("Connecting thru %s, speed %d.\r\n", ttname, speed);
printf("The escape character is %s (%d).\r\n", chstr(escape),
escape);
printf("Type the escape character followed by C to get back,\r\n");
printf("or followed by ? to see other options.\r\n");
#else
sprintf(print_str,"Connecting thru %s, speed %d.\r\n", ttname, speed);
mcs_printf(print_str);
sprintf(print_str,"The escape character is %s (%d).\r\n", chstr(escape),
escape);
mcs_printf(print_str);
mcs_printf("Type the escape character followed by C to get back,\r\n");
mcs_printf("or followed by ? to see other options.\r\n");
#endif
/* Condition console terminal and communication line */
if (conbin(escape) < 0) {
#ifndef MCS_FLAG
printf("Sorry, can't condition console terminal\n");
#else
mcs_printf("Sorry, can't condition console terminal\n");
#endif
return(-2);
}
if (ttvt(speed, flow) < 0) {
conres();
#ifndef MCS_FLAG
printf("Sorry, Can't condition communication line\n");
#else
mcs_printf("Sorry, Can't condition communication line\n");
#endif
return(-2);
}
parent_id = getpid(); /* Get parent id for signalling */
SIGNAL(SIGUSR1, SIG_IGN); /* Don't KILL parent */
pid = FORK(); /* All ok, make a FORK */
if (pid == -1) {
conres(); /* Reset the console. */
errhdlr("conect: Can't create keyboard FORK");
#ifndef MCS_FLAG
printf("[Back at Local System]\n");
#else
mcs_printf("[Back at Local System]\n");
#endif
return(0);
}
io_retry = 0;
if (pid) {
active = 1; /* This FORK reads, sends keystrokes */
if (!setjmp(env_con)) { /* comm error in child process */
SIGNAL(SIGUSR1, conn_int); /* routine for child process exit */
while (active) {
c = coninc(0) & cmask; /* Get character from keyboard */
if ((c & 0177) == escape) { /* Look for escape char */
c = coninc(0) & 0177; /* Got esc, get its arg */
doesc(c); /* And process it */
} else { /* Ordinary character */
if (ttoc(dopar(c)) > -1) {
if (duplex) { /* Half duplex? */
conoc(c); /* Yes, also echo it. */
if (seslog) /* And maybe log it. */
/* code folded from here */
if (zchout(ZSFILE, c) < 0)
seslog = 0;
/* unfolding */
}
} else {
errhdlr("conect: Can't send character");
active = 0;
}
}
}
} /* Come here on death of child */
KILL(pid, 9); /* Done, KILL inferior FORK. */
WAIT((int *)0); /* Wait till gone. */
conres(); /* Reset the console. */
#ifndef MCS_FLAG
printf("\r[Back at Local System]\n");
#else
mcs_printf("\r[Back at Local System]\n");
#endif
return(0);
} else { /* Inferior reads, prints port input */
sleep(1); /* Wait for parent's handler setup */
while (1) { /* Fresh read, WAIT for a character */
if ((c = ttinc(0)) < 0) { /* Comm line hangup detected */
if (errno == 9999) /* this value set by myread() */
#ifndef MCS_FLAG
printf("\r\nCommunications disconnect ");
#else
mcs_printf("\r\nCommunications disconnect ");
#endif
else if (io_retry++ < 3) {
tthang();
continue;
}
errhdlr("conect: Can't get character");
KILL(parent_id, SIGUSR1); /* notify parent. */
PAUSE(); /* Wait to be KILLed by parent. */
}
c &= cmask; /* Got a char, strip parity, etc */
conoc(c); /* Put it on the screen. */
if (seslog)
zchout(ZSFILE, c); /* If logging, log it. */
while ((n = ttchk()) > 0) { /* Any more left in buffer? */
if (n > LBUFL)
n = LBUFL; /* Get them all at once. */
if ((n = ttxin(n, lbuf)) > 0) {
for (i = 0; i < n; i++)
lbuf[i] &= cmask; /* Strip */
conxo(n, lbuf); /* Output */
if (seslog)
zsoutx(ZSFILE, lbuf,
n); /* Log */
}
}
}
}
}
/* H C O N N E -- Give help message for connect. */
hconne()
{
int c;
static char *hlpmsg[] = {
"\r\n C to close the connection, or:",
"\r\n 0 (zero) to send a null",
"\r\n B to send a BREAK",
"\r\n H to hangup and close connection",
"\r\n S for status",
"\r\n ? for help",
"\r\n escape character twice to send the escape character.\r\n\r\n",
"" };
conola(hlpmsg); /* Print the help message. */
conol("Command>"); /* Prompt for command. */
c = coninc(0) & 0177; /* Get character, strip any parity. */
conoc(c); /* Echo it. */
conoll("");
return(c); /* Return it. */
}
/* C H S T R -- Make a printable string out of a character */
char *
chstr(c)
int c;
{
static char s[8];
char *cp = s;
if (c < SP) {
sprintf(cp, "CTRL-%c", ctl(c));
} else
sprintf(cp, "'%c'\n", c);
cp = s;
return(cp);
}
/* D O E S C -- Process an escape character argument */
doesc(c)
char c;
{
CHAR d;
while (1) {
if (c == escape) { /* Send escape character */
d = dopar(c);
ttoc(d);
return;
} else if /* Or else look it up below. */
(isupper(c))
c = tolower(c);
switch (c) {
case 'c': /* Close connection */
case '\03':
active = 0;
conol("\r\n");
return;
case 'b': /* Send a BREAK signal */
case '\02':
ttsndb();
return;
case 'h': /* Hangup */
case '\010':
tthang();
active = 0;
conol("\r\n");
return;
case 's': /* Status */
conol("\r\nConnected thru ");
conol(ttname);
if (speed >= 0) {
sprintf(temp, ", speed %d", speed);
conol(temp);
}
sprintf(temp, ", %d bits", (cmask == 0177) ?
7 : 8);
if (parity) {
conol(", ");
switch (parity) {
case 'e':
conol("even");
break;
case 'o':
conol("odd");
break;
case 's':
conol("space");
break;
case 'm':
conol("mark");
break;
}
conol(" parity");
}
if (seslog) {
conol(", logging to ");
conol(sesfil);
}
conoll("");
return;
case '?': /* Help */
c = hconne();
continue;
case '0': /* Send a null */
c = '\0';
d = dopar(c);
ttoc(d);
return;
case SP: /* Space, ignore */
return;
default: /* Other */
conoc(BEL);
return; /* Invalid esc arg, beep */
}
}
}