home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Columbia Kermit
/
kermit.zip
/
archives
/
ncr9800.tar.gz
/
ncr9800.tar
/
ckvusr.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-07-13
|
51KB
|
1,502 lines
char *userv = "User Interface 4E(060), 06 June 90";
/* C K V U S R -- "User Interface" for NCR-VRX Kermit (Part 1) */
/**********************************************************************
* *
* 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 *
* *
* *
***********************************************************************/
/*
4E, support for Apollo Aegis, Data General added, July 87.
*/
/*
Author: Frank da Cruz (fdc@cunixc.cc.columbia.edu, FDCCU@CUVMA.BITNET),
Columbia University Center for Computing Activities.
First released January 1985.
Copyright (C) 1985, 1989, 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.
*/
/*
The ckuusr module contains the terminal input and output functions for VRX
Kermit. It includes a simple NCR-VRX-style command line parser as well as
an interactive prompting keyword command parser. It depends on the existence
of VRX facilities like fopen, fgets, feof, (f)printf, argv/argc, etc. Other
functions that are likely to vary among VRX implementations -- like setting
terminal modes or interrupts -- are invoked via calls to functions that are
defined in the system-dependent modules, ck?[ft]io.c.
The command line parser processes any arguments found on the command line,
as passed to main() via argv/argc. The interactive parser uses the facilities
of the cmd package (developed for this program, but usable by any program).
Any command parser may be substituted for this one. The only requirements
for the Kermit command parser are these:
1. Set parameters via global variables like duplex, speed, ttname, etc.
See ckmain.c for the declarations and descriptions of these variables.
2. If a command can be executed without the use of Kermit protocol, then
execute the command directly and set the variable sstate to 0. Examples
include 'set' commands, local directory listings, the 'connect' command.
3. If a command requires the Kermit protocol, set the following variables:
sstate string data
'x' (enter server mode) (none)
'r' (send a 'get' command) cmarg, cmarg2
'v' (enter receive mode) cmarg2
'g' (send a generic command) cmarg
's' (send files) nfils, cmarg & cmarg2 OR cmlist
'c' (send a remote host command) cmarg
cmlist is an array of pointers to strings.
cmarg, cmarg2 are pointers to strings.
nfils is an integer.
cmarg can be a filename string (possibly wild), or
a pointer to a prefabricated generic command string, or
a pointer to a host command string.
cmarg2 is the name to send a single file under, or
the name under which to store an incoming file; must not be wild.
cmlist is a list of nonwild filenames, such as passed via argv.
nfils is an integer, interpreted as follows:
-1: argument string is in cmarg, and should be expanded internally.
0: stdin.
>0: number of files to send, from cmlist.
The screen() function is used to update the screen during file transfer.
The tlog() function maintains a transaction log.
The debug() function maintains a debugging log.
The intmsg() and chkint() functions provide the user i/o for interrupting
file transfers.
*/
/* Includes */
#include "ckcdeb.h"
#include <stdio.h>
#include <ctype.h>
#include <signal.h>
#include "ckcker.h"
#include "ckucmd.h"
#include "ckuusr.h"
#include "kermisc.h"
#ifdef MCS_FLAG
#include "mcs.h"
#endif
/* External Kermit Variables, see ckmain.c for description. */
extern int EXECL();
extern void errhdlr();
#ifdef MCS_FLAG
extern void \:FINISH();
#endif
extern int size, rpsiz, urpsiz, speed, local,
server, displa, binary, parity, deblog, escape, xargc, flow,
turn, duplex, nfils, ckxech, pktlog, seslog, tralog, stdouf,
turnch, dfloc, keep, maxrps, /* warn, */ quiet, cnflg, tlevel,
send_id, recv_id, send_num, recv_num, send_renum, recv_renum,
send_addnum, recv_addnum;
extern char *versio, *protv, *ckxv, *ckzv, *fnsv, *connv, *dftty, *cmdv;
extern char *dialv, *loginv;
extern char *ckxsys, *ckzsys, *cmarg, *cmarg2, **xargv, **cmlist;
extern char cmerrp[];
extern CHAR sstate, ttname[];
char *strcpy(), *GETENV();
/* Declarations from cmd package */
extern char cmdbuf[]; /* Command buffer */
extern int cmflgs; /* Command flags */
/* Declarations from ck?fio.c module */
extern char *zhome(); /* Space command, home directory. */
extern int backgrd; /* Kermit executing in background */
/* The background flag is set by ckutio.c (via conint() ) to note whether */
/* this kermit is executing in background ('&' on shell command line). */
/* Variables and symbols local to this module */
char line[CMDBL+10], *lp; /* Character buffer for anything */
char debfil[50]; /* Debugging log file name */
char pktfil[50]; /* Packet log file name */
char sesfil[50]; /* Session log file name */
char trafil[50]; /* Transaction log file name */
int n, /* General purpose int */
cflg, /* Command-line connect cmd given */
action, /* Action selected on command line*/
repars, /* Reparse needed */
cwdf = 0; /* CWD has been done */
#define MAXTAKE 20 /* Maximum nesting of TAKE files */
FILE *tfile[MAXTAKE]; /* File pointers for TAKE command */
char *homdir; /* Pointer to home directory string */
char cmdstr[100]; /* Place to build generic command */
/* C M D L I N -- Get arguments from command line */
/*
Simple NCR-VRX-style command line parser, conforming with 'A Proposed Command
Syntax Standard for NCR-VRX Systems', Hemenway & Armitage, Unix/World, Vol.1,
No.3, 1984.
*/
cmdlin()
{
char x; /* Local general-purpose int */
cmarg = ""; /* Initialize globals */
cmarg2 = "";
action = cflg = 0;
while (--xargc > 0) { /* Go through command line words */
xargv++;
if (deblog)
debug(F111, "xargv", *xargv, xargc);
if (**xargv == '-') { /* Got an option (begins with dash) */
x = *(*xargv + 1); /* Get the option letter */
x = doarg(x); /* Go handle the option */
if (x < 0)
doexit(BAD_EXIT);
} else { /* No dash where expected */
usage();
doexit(BAD_EXIT);
}
}
if (deblog)
debug(F101, "action", "", action);
if (!local) {
if ((action == 'g') || (action == 'r') || (action ==
'c') || (cflg != 0))
fatal("-l and -b required");
}
if (*cmarg2 != 0) {
if ((action != 's') && (action != 'r') && (action !=
'v'))
fatal("-a without -s, -r, or -g");
}
if ((action == 'v') && (stdouf) && (!local)) {
if (isatty(1))
fatal("unredirected -k can only be used in local mode");
}
if ((action == 's') || (action == 'v') || (action == 'r') ||
(action == 'x')) {
if (local)
displa = 1;
if (stdouf) {
displa = 0;
quiet = 1;
}
}
if (quiet)
displa = 0; /* No display if quiet requested */
if (cflg) {
conect(); /* Connect if requested */
if (action == 0) {
if (cnflg)
conect(); /* And again if requested */
doexit(GOOD_EXIT); /* Then exit indicating success */
}
}
if (displa)
concb(escape); /* (for console "interrupts") */
return(action); /* Then do any requested protocol */
}
/* D O A R G -- Do a command-line argument. */
doarg(x)
char x;
{
int z;
char *xp;
if (deblog) debug(F101,"funct: doarg> x:","",x);
xp = *xargv + 1; /* Pointer for bundled args */
while (x) {
switch (x) {
case 'x': /* server */
if (action)
fatal("conflicting actions");
action = 'x';
break;
case 'f':
if (action)
fatal("conflicting actions");
action = setgen('F', "", "", "");
break;
/*
* case 'r': * receive *
* if (action)
* fatal("conflicting actions");
* action = 'v';
* break;
*
* case 'k': * receive to stdout *
* if (action)
* fatal("conflicting actions");
* stdouf = 1;
* action = 'v';
* break;
*
* case 's': * send *
* if (action)
* fatal("conflicting actions");
* if (*(xp + 1))
* fatal("invalid argument bundling after -s");
* * Initialize file counter, flag *
* z = nfils = 0;
* * Remember this pointer *
* cmlist = xargv + 1;
* while (--xargc > 0) { * Traverse the list *
* *xargv++;
* if (**xargv == '-') { * Check for sending stdin *
* if (strcmp(*xargv, "-") != 0)
* break;
* z++;
* }
* nfils++; * Bump file counter *
* }
* xargc++, *xargv--; * Adjust argv/argc *
* if (nfils < 1)
* fatal("missing filename for -s");
* if (z > 1)
* fatal("-s: too many -'s");
* if (z == 1) {
* if (nfils == 1)
* nfils = 0;
* else
* fatal("invalid mixture of filenames and '-' in -s");
* }
* if (nfils == 0) {
* if (isatty(0))
* fatal("sending from terminal not allowed");
* }
* if (deblog)
* debug(F101, *xargv, "", nfils);
* action = 's';
* break;
*
* case 'g': * get *
* if (action)
* fatal("conflicting actions");
* if (*(xp + 1))
* fatal("invalid argument bundling after -g");
* *xargv++, xargc--;
* if ((xargc == 0) || (**xargv == '-'))
* fatal("missing filename for -g");
* cmarg = *xargv;
* action = 'r';
* break;
*
* case 'c': * connect before *
* cflg = 1;
* break;
*
* case 'n': * connect after *
* cnflg = 1;
* break;
*/
case 'h': /* help */
usage();
return(-1);
/* case 'a': * "as" *
* if (*(xp + 1))
* fatal("invalid argument bundling after -a");
* *xargv++, xargc--;
* if ((xargc < 1) || (**xargv == '-'))
* fatal("missing name in -a");
* cmarg2 = *xargv;
* break;
*
* case 'l': * set line *
* if (*(xp + 1))
* fatal("invalid argument bundling after -l");
* *xargv++, xargc--;
* if ((xargc < 1) || (**xargv == '-'))
* fatal("communication line device name missing");
* strcpy(ttname, *xargv);
*
* * if (strcmp(ttname,dftty) == 0) local = dfloc;
* else local = 1; *
*
* * (better than old way) *
* local = (strcmp(ttname, CTTNAM) != 0);
* if (deblog)
* debug(F101, "local", "", local);
* ttopen(ttname, &local, 0);
* break;
*
* case 'b': * set baud *
* if (*(xp + 1))
* fatal("invalid argument bundling");
* *xargv++, xargc--;
* if ((xargc < 1) || (**xargv == '-'))
* fatal("missing baud");
* z = atoi(*xargv); * Convert to number *
* if (chkspd(z) > -1)
* speed = z; * Check it *
* else
* fatal("unsupported baud rate");
* break;
*/
case 'e': /* Extended packet length */
if (*(xp + 1))
fatal("invalid argument bundling");
*xargv++, xargc--;
if ((xargc < 1) || (**xargv == '-'))
fatal("missing length");
z = atoi(*xargv); /* Convert to number */
if (z > 10 && z < maxrps) {
rpsiz = urpsiz = z;
if (z > 94)
rpsiz = 94; /* Fallback if other Kermit can't */
} else
fatal("Unsupported packet length");
break;
case 'i': /* Treat files as binary */
binary = 1;
break;
/* case 'w': * File warning *
* warn = 1;
* break;
*/
case 'q': /* Quiet */
quiet = 1;
break;
case 'd': /* debug */
debopn("debuglog");
break;
case 'p': /* set parity */
if (*(xp + 1))
fatal("invalid argument bundling");
*xargv++, xargc--;
if ((xargc < 1) || (**xargv == '-'))
fatal("missing parity");
switch (x = **xargv) {
case 'e':
case 'o':
case 'm':
case 's':
parity = x;
break;
case 'n':
parity = 0;
break;
default:
fatal("invalid parity");
}
break;
case 't':
turn = 1; /* Line turnaround handshake */
turnch = XON; /* XON is turnaround character */
duplex = 1; /* Half duplex */
flow = 0; /* No flow control */
break;
default:
fatal("invalid argument, type 'kermit -h' for help");
}
x = *++xp; /* See if options are bundled */
}
return(0);
}
fatal(msg)
char *msg;
{ /* Fatal error message */
fprintf(stderr, "\r\nFatal: %s\n", msg);
tlog(F110, "Fatal:", msg, 0l);
doexit(BAD_EXIT); /* Exit indicating failure */
}
ermsg(msg)
char *msg;
{ /* Print error message */
if (!quiet)
fprintf(stderr, "\r\n%s - %s\n", cmerrp, msg);
tlog(F110, "Error -", msg, 0l);
}
/* Interactive command parser */
/* Top-Level Keyword Table */
struct keytab cmdtab[] = {
"!", XXSHE, CM_INV,
"%", XXCOM, CM_INV,
"bye", XXBYE, CM_INV,
"c", XXCON, CM_INV,
"cd", XXCWD, CM_INV,
"close", XXCLO, 0,
"connect", XXCON, CM_INV,
"cwd", XXCWD, CM_INV,
"dial", XXDIAL, CM_INV,
"directory", XXDIR, CM_INV,
"echo", XXECH, 0,
"exit", XXEXI, 0,
"finish", XXFIN, CM_INV,
"get", XXGET, CM_INV,
"hangup", XXHAN, CM_INV,
"help", XXHLP, 0,
"log", XXLOG, 0,
"quit", XXQUI, 0,
"r", XXREC, CM_INV,
"receive", XXREC, CM_INV,
"remote", XXREM, CM_INV,
"s", XXSEN, CM_INV,
"script", XXLOGI, CM_INV,
"send", XXSEN, CM_INV,
"server", XXSER, 0,
"set", XXSET, 0,
"show", XXSHO, 0,
"space", XXSPA, CM_INV,
"statistics", XXSTA, 0,
"take", XXTAK, 0
};
int ncmd = (sizeof(cmdtab)
/ sizeof(struct keytab )
);
/* Parameter keyword table */
struct keytab prmtab[] = {
"baud", XYSPEE, CM_INV,
"add-linenum", XYADD, CM_INV, /* moved to send/receive */
"block-check", XYCHKT, 0,
"delay", XYDELA, CM_INV,
"duplex", XYDUPL, 0,
"end-of-packet", XYEOL, CM_INV, /* moved to send/receive */
"escape-character", XYESC, CM_INV,
"file", XYFILE, 0,
"flow-control", XYFLOW, 0,
"handshake", XYHAND, 0,
"id-fields", XYID, CM_INV, /* moved to send/receive */
"incomplete", XYIFD, 0,
"line", XYLINE, CM_INV,
"line-numbers", XYNUM, CM_INV, /* moved to send/receive */
"modem-dialer", XYMODM, CM_INV,
"packet-length", XYLEN, CM_INV, /* moved to send/receive */
"pad-character", XYPADC, CM_INV, /* moved to send/receive */
"padding", XYNPAD, CM_INV, /* moved to send/receive */
"parity", XYPARI, 0,
"prompt", XYPROM, 0,
"receive", XYRECV, 0,
"retry", XYRETR, 0,
"renumber", XYRNUM, CM_INV, /* moved to send/receive */
"send", XYSEND, 0,
"speed", XYSPEE, CM_INV,
"start-of-packet", XYMARK, CM_INV, /* moved to send/receive */
"terminal", XYTERM, CM_INV,
"timeout", XYTIMO, CM_INV /* moved to send/receive */
};
int nprm = (sizeof(prmtab)
/ sizeof(struct keytab )
); /* How many parameters */
/* Remote Command Table */
struct keytab remcmd[] = {
"cd", XZCWD, CM_INV,
"cwd", XZCWD, 0,
"delete", XZDEL, 0,
"directory", XZDIR, 0,
"help", XZHLP, 0,
"host", XZHOS, 0,
"space", XZSPA, 0,
"type", XZTYP, 0,
"who", XZWHO, 0
};
int nrmt = (sizeof(remcmd)
/ sizeof(struct keytab )
);
struct keytab logtab[] = {
"debugging", LOGD, 0,
"packets", LOGP, 0,
"session", LOGS, CM_INV,
"transactions", LOGT, 0
};
int nlog = (sizeof(logtab)
/ sizeof(struct keytab )
);
/* Show command arguments */
#define SHPAR 0 /* Parameters */
#define SHVER 1 /* Versions */
struct keytab shotab[] = {
"parameters", SHPAR, 0,
"versions", SHVER, 0
};
/* C M D I N I -- Initialize the interactive command parser */
cmdini()
{
tlevel = -1; /* Take file level */
#ifndef MCS_FLAG
cmsetp("IVS-Kermit>"); /* Set default prompt */
#else
cmsetp("MCS-Kermit>"); /* Set default prompt */
#endif
/* Look for init file in home or current directory. */
homdir = zhome(); /* home dir not used */
lp = line;
lp[0] = '\0';
/*
* if (homdir) {
* strcpy(lp, homdir);
* if (lp[0] == '/')
* strcat(lp, "/");
* }
* strcat(lp, KERMRC);
* if ((tfile[0] = fopen(line, "r")) != NULL) {
* tlevel = 0;
* if (deblog)
* debug(F110, "init file", line, 0);
* }
* if (homdir && (tlevel < 0)) {
* strcpy(lp, KERMRC);
* if ((tfile[0] = fopen(line, "r")) != NULL) {
* tlevel = 0;
* if (deblog)
* debug(F110, "init file", line, 0);
* } else {
* if (deblog)
* debug(F100, "no init file", "", 0);
* }
* }
*/
/* Look for the init file. In the V environment, the file
location is controlled by the filelocation parameter.
If CAT or CAT/NOCAT is specified, we'll look in the
current subcatalog node. If NOCAT is specified, we'll
look on disk. If there is no volume assigned, then we
could get a resource not available message. */
strcpy(lp, KERMRC);
if ((tfile[0] = fopen(line, "r")) != NULL) {
tlevel = 0;
if (deblog) debug(F110, "init file", line, 0);
} else {
if (deblog) debug(F100, "no init file", "", 0);
}
congm(); /* Get console tty modes */
}
/* Display version herald and initial prompt */
herald()
{
if (!backgrd)
#ifndef MCS_FLAG
printf("%s\nType ? for help\n", versio);
#else
sprintf("%s\nType ? for help\n", versio);
mcs_printf(print_str);
#endif
}
/* T R A P -- Terminal interrupt handler */
trap()
{
if (deblog)
debug(F100, "terminal interrupt...", "", 0);
doexit(GOOD_EXIT); /* Exit indicating success */
}
/* S T P T R A P -- Handle SIGTSTP signals */
stptrap()
{
conres(); /* Reset the console */
doexit(GOOD_EXIT); /* Probably won't happen otherwise */
concb(); /* Put console back in Kermit mode */
}
/* P A R S E R -- Top-level interactive command parser. */
char parser()
{
int xx, cbn;
char *cbp;
concb(escape); /* Put console in cbreak mode. */
conint(trap); /* Turn on console terminal interrupts. */
/*
sstate becomes nonzero when a command has been parsed that requires some
action from the protocol module. Any non-protocol actions, such as local
directory listing or terminal emulation, are invoked directly from below.
*/
if (local && !backgrd)
#ifndef MCS_FLAG
printf("\n"); /*** Temporary kludge ***/
#else
mcs_printf("\n"); /*** Temporary kludge ***/
#endif
sstate = 0; /* Start with no start state. */
while (sstate == 0) { /* Parse cmds until action requested */
while ((tlevel > -1) && feof(tfile[tlevel])) { /* If end of take */
fclose(tfile[tlevel--]); /* file, close it. */
cmini(ckxech); /* and clear the cmd buffer. */
if (tlevel < 0) { /* Just popped out of cmd files? */
conint(trap); /* Check background stuff again. */
return(0); /* End of init file or whatever. */
}
}
if (deblog)
debug(F101, "tlevel", "", tlevel);
if (tlevel > -1) { /* If in take file */
cbp = cmdbuf; /* Get the next line. */
cbn = CMDBL;
/* Loop to get next command line and
all continuation lines from take file. */
again:
if (fgets(line, cbn, tfile[tlevel]) == NULL)
continue;
lp = line; /* Got one, copy it. */
while (*cbp++ = *lp++)
if (--cbn < 1)
fatal("Command too long for internal buffer");
if (*(cbp - 3) == '\\') { /* Continued on next line? */
cbp -= 3; /* If so, back up pointer, */
goto again; /* go back, get next line. */
}
/* Strip any quotes from cmd buffer. */
stripq(cmdbuf);
} else { /* No take file, get typein. */
if (!backgrd)
prompt(); /* Issue interactive prompt. */
cmini(ckxech);
}
repars = 1;
displa = 0;
while (repars) {
cmres(); /* Reset buffer pointers. */
xx = cmkey(cmdtab, ncmd, "Command", "");
if (deblog)
debug(F101, "top-level cmkey", "", xx);
switch (docmd(xx)) {
case -4: /* EOF */
doexit(GOOD_EXIT); /* ...exit successfully */
case -1: /* Reparse needed */
repars = 1;
continue;
case -2: /* Invalid command given */
if (backgrd) /* if in background, terminate */
fatal("Kermit command error in background execution");
if (tlevel > -1) { /* If in take file, quit */
ermsg("Kermit command error: take file terminated.");
fclose(tfile[tlevel]);
tlevel--;
}
cmini(ckxech); /* fall thru */
case -3: /* Empty command OK at top level */
default: /* Anything else (fall thru) */
repars = 0; /* No reparse, get new command. */
*cmdbuf = NUL; /* Clear out the command buffer */
continue;
}
}
}
/* Got an action command; disable terminal
interrupts and return start state */
if (!local)
connoi(); /* Interrupts off only if remote */
return(sstate);
}
/* D O E X I T -- Exit from the program. */
doexit(exitstat)
int exitstat;
{
ttclos(); /* Close external line, if any */
if (local) {
strcpy(ttname, dftty); /* Restore default tty */
local = dfloc; /* And default remote/local status */
}
if (!quiet)
conres(); /* Restore console terminal. */
if (!quiet)
connoi(); /* Turn off console interrupt traps. */
if (deblog) { /* Close any open logs. */
if (deblog)
debug(F100, "Debug Log Closed", "", 0);
*debfil = '\0';
deblog = 0;
zclose(ZDFILE);
}
if (pktlog) {
*pktfil = '\0';
pktlog = 0;
zclose(ZPFILE);
}
/* if (seslog) { packet log disabled from opening
*sesfil = '\0';
seslog = 0;
zclose(ZSFILE);
} */
if (tralog) {
tlog(F100, "Transaction Log Closed", "", 0l);
*trafil = '\0';
tralog = 0;
zclose(ZTFILE);
}
syscleanup();
#ifndef MCS_FLAG
exit(exitstat); /* Exit from the program. */
#else
\:FINISH(exitstat);
#endif
}
/* B L D L E N -- Make length-encoded copy of string */
char *
bldlen(str, dest)
char *str, *dest;
{
int len;
len = strlen(str);
*dest = tochar(len);
strcpy(dest + 1, str);
return(dest + len + 1);
}
/* S E T G E N -- Construct a generic command */
setgen(type, arg1, arg2, arg3)
char type, *arg1, *arg2, *arg3;
{
char *upstr, *cp;
cp = cmdstr;
*cp++ = type;
*cp = NUL;
if (*arg1 != NUL) {
upstr = bldlen(arg1, cp);
if (*arg2 != NUL) {
upstr = bldlen(arg2, upstr);
if (*arg3 != NUL)
bldlen(arg3, upstr);
}
}
cmarg = cmdstr;
if (deblog)
debug(F110, "setgen", cmarg, 0);
return('g');
}
/* C M D N O T I -- Command not implemented message */
cmdnoti() {
int c;
#ifndef MCS_FLAG
printf("\nV-Kermit does not support: %s.\n",cmdbuf);
#else
sprintf(print_str,"\nV-Kermit does not support: %s.\n",cmdbuf);
mcs_printf(print_str);
#endif
if (cmflgs != 1) {
/* The command was not terminated with a carriage return. So there
must be something following it on the input line. Since the command
was not implemented, we'll flush the rest of the input line. */
while ((c = getchar()) != NL && c != CR) ;
}
return(0);
}
/* D O C M D -- Do a command */
/*
Returns:
-2: user typed an illegal command
-1: reparse needed
0: parse was successful (even tho command may have failed).
*/
docmd(cx)
int cx;
{
int x, y;
char *s;
char temp[400];
switch (cx) {
case -4: /* EOF */
if (!quiet && !backgrd)
#ifndef MCS_FLAG
printf("\r\n");
#else
mcs_printf("\r\n");
#endif
doexit(GOOD_EXIT);
case -3: /* Null command */
return(0);
case -2: /* Error */
case -1: /* Reparse needed */
return(cx);
case XXBYE: /* bye */
return(cmdnoti());
/* if ((x = cmcfm()) < 0)
* return(x);
* if (!local) {
* printf("You have to 'set line' first\n");
* return(0);
* }
* sstate = setgen('L', "", "", "");
* return(0);
*/
case XXCOM: /* comment */
if ((x = cmtxt("Text of comment line", "", &s)) < 0)
return(x);
return(0);
case XXCON: /* connect */
return(cmdnoti()); /* command not implemented */
/*
* if ((x = cmcfm()) < 0)
* return(x);
* return(doconect());
*/
case XXCWD: /* change directory */
return(cmdnoti()); /* command not implemented */
/*
* if (cmtxt("Name of local directory, or carriage return",
* homdir, &s) < 0)
* return(-1);
* if (CHDIR(s)) {
* sprintf(temp, "docmd: %s", s);
* errhdlr(s);
* }
* cwdf = 1;
* return(0);
*/
case XXCLO:
x = cmkey(logtab, nlog, "Which log to close", "");
if (x == -3) {
#ifndef MCS_FLAG
printf("?You must tell which log\n");
#else
mcs_printf("?You must tell which log\n");
#endif
return(-2);
}
if (x < 0)
return(x);
if ((y = cmcfm()) < 0)
return(y);
switch (x) {
case LOGD:
if (deblog == 0) {
#ifndef MCS_FLAG
printf("?Debugging log wasn't open\n");
#else
mcs_printf("?Debugging log wasn't open\n");
#endif
return(0);
}
*debfil = '\0';
deblog = 0;
return(zclose(ZDFILE));
case LOGP:
if (pktlog == 0) {
#ifndef MCS_FLAG
printf("?Packet log wasn't open\n");
#else
mcs_printf("?Packet log wasn't open\n");
#endif
return(0);
}
*pktfil = '\0';
pktlog = 0;
return(zclose(ZPFILE));
/*
* case LOGS:
* if (seslog == 0) {
* printf("?Session log wasn't open\n");
* return(0);
* }
* *sesfil = '\0';
* seslog = 0;
* return(zclose(ZSFILE));
*/
case LOGT:
if (tralog == 0) {
#ifndef MCS_FLAG
printf("?Transaction log wasn't open\n");
#else
mcs_printf("?Transaction log wasn't open\n");
#endif
return(0);
}
*trafil = '\0';
tralog = 0;
return(zclose(ZTFILE));
default:
#ifndef MCS_FLAG
printf("\n?Unexpected log designator - %ld\n", x);
#else
sprintf(print_str,"\n?Unexpected log designator - %ld\n", x);
mcs_printf(print_str);
#endif
return(0);
}
case XXDIAL: /* dial number */
return(cmdnoti()); /* command not implemented */
/*
* if ((x = cmtxt("Number to be dialed", "", &s)) < 0)
* return(x);
* return(ckdial(s));
*/
case XXDIR: /* list directory */
return(cmdnoti()); /* command not implemented */
/*
* if ((x = cmtxt("Directory/file specification", ".",
* &s)) < 0)
* return(x);
* lp = line;
* SYSTEM(line);
* return(0);
*/
case XXECH: /* echo */
if ((x = cmtxt("Material to be echoed", "", &s)) < 0)
return(x);
for ( ; *s; s++) {
if ((x = *s) == 0134) { /* Convert octal escapes */
s++; /* up to 3 digits */
for (x = y = 0; *s >= '0' && *s <= '7' &&
y < 3; s++, y++) {
x = x * 8 + (int) *s - 48;
}
s--;
}
putchar(x);
}
#ifndef MCS_FLAG
printf("\n");
#else
mcs_printf("\n");
#endif
return(0);
case XXQUI: /* quit, exit */
case XXEXI:
if ((x = cmcfm()) > -1)
doexit(GOOD_EXIT);
else
return(x);
case XXFIN: /* finish */
return(cmdnoti()); /* command not implemented */
/* if ((x = cmcfm()) < 0)
* return(x);
* if (!local) {
* printf("You have to 'set line' first\n");
* return(0);
* }
* sstate = setgen('F', "", "", "");
*/
case XXGET: /* get */
return(cmdnoti()); /* command not implemented */
/* if (!local) {
* printf("\nYou have to 'set line' first\n");
* return(0);
* }
* x = cmtxt("Name of remote file(s), or carriage return",
* "", &cmarg);
* if ((x == -2) || (x == -1))
* return(x);
*
* * If foreign file name omitted, get
* foreign and local names separately *
*
* x = 0; * For some reason cmtxt
* returns 1 *
* if (*cmarg == NUL) {
*
* if (tlevel > -1) { * Input is from take file *
*
* if (fgets(line, 100, tfile[tlevel]) ==
* NULL)
* fatal("take file ends prematurely in 'get'");
* if (deblog)
* debug(F110, "take-get 2nd line",
* line, 0);
* stripq(line);
* for (x = strlen(line); x > 0 && (line[x-1] ==
* '\n' || line[x-1] == '\r'); x--)
* line[x-1] = '\0';
* cmarg = line;
* if (fgets(cmdbuf, CMDBL, tfile[tlevel]) ==
* NULL)
* fatal("take file ends prematurely in 'get'");
* stripq(cmdbuf);
* for (x = strlen(cmdbuf); x > 0 && (cmdbuf[x-1] ==
* '\n' || cmdbuf[x-1] == '\r'); x--)
* cmdbuf[x-1] = '\0';
* if (*cmdbuf == NUL)
* cmarg2 = line;
* else
* cmarg2 = cmdbuf;
* x = 0; * Return code *
*
* } else { * Input is from terminal *
*
* char psave[40]; * Save old prompt *
* cmsavp(psave, 40);
* cmsetp(" Remote file specification: "); * Make new one *
* cmini(ckxech);
* x = -1;
* if (!backgrd)
* prompt();
* while (x == -1) { * Prompt till they answer *
* x = cmtxt("Name of remote file(s)",
* "", &cmarg);
* if (deblog)
* debug(F111, " cmtxt",
* cmarg, x);
* }
* if (x < 0) {
* cmsetp(psave);
* return(x);
* }
* if (*cmarg == NUL) { * If user types a bare CR, *
* printf("(cancelled)\n"); * Forget about this. *
* cmsetp(psave); * Restore old prompt, *
* return(0); * and return. *
* }
* strcpy(line, cmarg); * Make a safe copy *
* cmarg = line;
* * New prompt *
* cmsetp(" Local name to store it under: ");
* cmini(ckxech);
* x = -1;
* if (!backgrd) prompt();
* while (x == -1) { * Again, parse till answered *
* x = cmofi("Local file name", "", &cmarg2);
* }
* if (x == -3) { * If bare CR, *
* printf("(cancelled)\n"); * escape from this *
* cmsetp(psave); * Restore old prompt, *
* return(0); * and return. *
* } else if (x < 0)
* return(x); * Handle parse errors. *
*
* x = -1; * Get confirmation. *
* while (x == -1)
* x = cmcfm();
* cmsetp(psave); * Restore old prompt. *
* }
* }
* if (x == 0) { * Good return from cmtxt or
* cmcfm, *
* sstate = 'r'; * set start state. *
* if (local)
* displa = 1;
* }
* return(x);
*/
case XXHLP: /* Help */
#ifndef MCS_FLAG
x = cmkey(cmdtab, ncmd, "IVS-Kermit command", "help");
#else
x = cmkey(cmdtab, ncmd, "MCS-Kermit command", "help");
#endif
return(dohlp(x));
case XXHAN: /* Hangup */
return(cmdnoti()); /* command not implemented */
/*
* if ((x = cmcfm()) > -1)
* return(tthang());
*/
case XXLOG: /* Log */
x = cmkey(logtab, nlog, "What to log", "");
if (x == -3) {
#ifndef MCS_FLAG
printf("?You must specify what is to be logged\n");
#else
mcs_printf("?You must specify what is to be logged\n");
#endif
return(-2);
}
if (x < 0)
return(x);
return(dolog(x));
case XXLOGI: /* Send script remote system */
return(cmdnoti()); /* command not implemented */
/*
* if ((x = cmtxt("Text of login script", "", &s)) < 0)
* return(x);
* return( login(s) ); * Return 0=completed,
* -2=failed *
*/
case XXREC: /* Receive */
return(cmdnoti()); /* command not implemented */
/* cmarg2 = "";
* x = cmofi("Name under which to store the file, or CR",
* "", &cmarg2);
* if ((x == -1) || (x == -2))
* return(x);
* if (deblog)
* debug(F111, "cmofi cmarg2", cmarg2, x);
* if ((x = cmcfm()) < 0)
* return(x);
* sstate = 'v';
* if (local)
* displa = 1;
* return(0);
*/
case XXREM: /* Remote */
return(cmdnoti()); /* command not implemented */
/*
* if (!local) {
* printf("\nYou have to 'set line' first\n");
* return(-2);
* }
* x = cmkey(remcmd, nrmt, "Remote Kermit server command", "");
* if (x == -3) {
* printf("?You must specify a command for the remote server\n");
* return(-2);
* }
* return(dormt(x));
*/
case XXSEN: /* Send */
return(cmdnoti()); /* command not implemented */
/* cmarg = cmarg2 = "";
* if ((x = cmifi("File(s) to send", "", &s, &y)) < 0) {
* if (x == -3) {
* printf("?A file specification is required\n");
* return(-2);
* }
* return(x);
* }
* nfils = -1; * Files come from internal list. *
* strcpy(line, s); * Save copy of string just parsed. *
* if (deblog)
* debug(F101, "Send: wild", "", y);
* *cmarg2 = '\0'; * Initialize send-as name *
* if (y == 0) {
* if ((x = cmtxt("Name to send it with", "", &cmarg2)) <
* 0)
* return(x);
* } else {
* if ((x = cmcfm()) < 0)
* return(x);
* }
* cmarg = line; * File to send *
* if (deblog)
* debug(F110, "Sending:", cmarg, 0);
* if (*cmarg2 != '\0' && deblog)
* debug(F110, " as:", cmarg2, 0);
* sstate = 's'; * Set start state *
* if (local)
* displa = 1;
* return(0);
*/
case XXSER: /* Server */
if ((x = cmcfm()) < 0)
return(x);
sstate = 'x';
if (local)
displa = 1;
return(0);
case XXSET: /* Set */
x = cmkey(prmtab, nprm, "Parameter", "");
if (x == -3) {
#ifndef MCS_FLAG
printf("?You must specify a parameter to set\n");
#else
mcs_printf("?You must specify a parameter to set\n");
#endif
return(-2);
}
if (x < 0)
return(x);
return(doprm(x));
/* XXSHE code by H. Fischer; copyright rights assigned to Columbia Univ */
/*
Adapted to use getpwuid to find login shell because many systems do not
have SHELL in environment, and to use direct calling of shell rather
than intermediate system() call. -- H. Fischer
*/
case XXSHE: /* Local shell command */
return(cmdnoti()); /* command not implemented */
/*
* {
* int pid;
* if (cmtxt("NCR-VRX shell command to execute",
* "", &s) < 0)
* return(-1);
* conres(); * Make console normal *
*
* SYSTEM("x :cli prefix Kermit_Baby:");
*
* if ((pid = FORK()) == 0) { * Make child *
* char *shpath, *shname, *shptr;
* * For finding desired shell *
* struct passwd *p;
* extern struct passwd *GETPWUID();
* extern int GETUID();
* char *defShel = "/bin/sh"; * Default *
*
* p = GETPWUID( GETUID() ); * Get login data *
* if ( p == (struct passwd *) NULL ||
* !*(p->pw_shell) )
* shpath = defShel;
* else
* shpath = p->pw_shell;
* shptr = shname = shpath;
* while (*shptr != '\0')
* if (*shptr++ == '/')
* shname = shptr;
*
* * Remove following uid calls if they cause trouble *
*
* if (*s == NUL) * Interactive shell requested? *
* EXECL(shpath, shname, "-i",
* NULL); * Yes, do that *
* else * Otherwise, *
* EXECL(shpath, shname, "-c",
* s, NULL); * exec the given command *
* exit(BAD_EXIT);
* } * Just punt if it didn't work *
* else { * Parent *
*
* int wstat; * Kermit must wait for child *
* SIGTYP (*istat)(), (*qstat)();
*
* istat = SIGNAL(SIGINT, SIG_IGN); * Let the fork handle
* keyboard *
* qstat = SIGNAL(SIGQUIT, SIG_IGN); * interrupts itself *
*
* while (((wstat = WAIT((int *)0)) !=
* pid) && (wstat != -1))
* ;
* * Wait for fork *
* SIGNAL(SIGINT, istat); * Restore interrupts *
* SIGNAL(SIGQUIT, qstat);
* }
* concb(escape); * Console back in cbreak
* mode *
* return(0);
* }
*/
case XXSHO: /* Show */
x = cmkey(shotab, 2, "", "parameters");
if (x < 0)
return(x);
if ((y = cmcfm()) < 0)
return(y);
switch (x) {
case SHPAR:
shopar();
break;
case SHVER:
#ifndef MCS_FLAG
printf("\nVersions:\n %s\n %s\n", versio, protv);
printf(" %s\n", fnsv);
printf(" %s\n %s\n", cmdv, userv);
printf(" %s for%s\n", ckxv, ckxsys);
printf(" %s for%s\n", ckzv, ckzsys);
#else
sprintf(print_str,"\nVersions:\n %s\n %s\n", versio, protv);
mcs_printf(print_str);
sprintf(print_str," %s\n", fnsv);
mcs_printf(print_str);
sprintf(print_str," %s\n %s\n", cmdv, userv);
mcs_printf(print_str);
sprintf(print_str," %s for%s\n", ckxv, ckxsys);
mcs_printf(print_str);
sprintf(print_str," %s for%s\n", ckzv, ckzsys);
mcs_printf(print_str);
#endif
break;
default:
printf("\nNothing to show...\n");
break;
}
return(0);
case XXSPA: /* space */
return(cmdnoti()); /* command not implemented */
/*
* if ((x = cmcfm()) < 0)
* return(x);
* return(0);
*/
case XXSTA: /* statistics */
if ((x = cmcfm()) < 0)
return(x);
return(dostat());
case XXTAK: /* take */
if (tlevel > MAXTAKE - 1) {
#ifndef MCS_FLAG
printf("?Take files nested too deeply\n");
#else
mcs_printf("?Take files nested too deeply\n");
#endif
return(-2);
}
#ifndef MCS_FLAG
if ((y = cmifi("IVS-Kermit command file", "", &s, &x)) <
#else
if ((y = cmifi("MCS-Kermit command file", "", &s, &x)) <
#endif
0) {
if (y == -3) {
#ifndef MCS_FLAG
printf("?A file specification is required\n");
#else
mcs_printf("?A file specification is required\n");
#endif
return(-2);
} else
return(y);
}
if (x != 0) {
#ifndef MCS_FLAG
printf("?Wildcards not allowed in command file name\n");
#else
mcs_printf("?Wildcards not allowed in command file name\n");
#endif
return(-2);
}
strcpy(line, s); /* Make a safe copy of the string */
if ((y = cmcfm()) < 0)
return(y);
if ((tfile[++tlevel] = fopen(line, "r")) == NULL) {
sprintf(temp, "docmd: %s", line);
errhdlr(temp);
if (deblog)
debug(F110, "Failure to open", line, 0);
tlevel--;
}
return(0);
default:
#ifndef MCS_FLAG
printf("V-Kermit does not support: %s\n", cmdbuf);
#else
sprintf(print_str,"V-Kermit does not support: %s.\n",cmdbuf);
mcs_printf(print_str);
#endif
return(-2);
}
}
/* D O C O N E C T -- Do the connect command */
/* Note, we don't call this directly from dial, because we need to give */
/* the user a chance to change parameters (e.g. parity) after the */
/* connection is made. */
doconect()
{
int x;
conres(); /* Put console back to normal */
x = conect(); /* Connect */
concb(escape); /* Put console into cbreak mode, */
return(x); /* for more command parsing. */
}