📄 ckuusr.c
字号:
char *userv = "User Interface 4C(053), 19 Mar 86";/* C K U U S R -- "User Interface" for Unix Kermit (Part 1) *//* 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.*//* Form Feed *//* The ckuser module contains the terminal input and output functions for Unix Kermit. It includes a simple Unix-style command line parser as well as an interactive prompting keyword command parser. It depends on the existence of Unix facilities like fopen, fgets, feof, (f)printf, argv/argc, etc. Other functions that are likely to vary among Unix 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.*//* Form Feed *//* Includes */#include <stdio.h>#include <ctype.h>#ifndef AMIGA#include <signal.h>#endif#include "ckcdeb.h"#include "ckcker.h"#include "ckucmd.h"#include "ckuusr.h"#ifdef AMIGA#define KERMRC "s:kermit-startup"#else#ifdef vax11c#define KERMRC "kermit.ini"#else#define KERMRC ".kermrc"#endif#endif/* External Kermit Variables, see ckmain.c for description. */extern int size, spsiz, rpsiz, npad, timint, rtimo, speed, local, server, displa, binary, fncnv, delay, parity, deblog, escape, xargc, flow, turn, duplex, cxseen, czseen, nfils, ckxech, pktlog, seslog, tralog, stdouf, turnch, chklen, bctr, bctu, dfloc, mdmtyp, keep, rptflg, rptq, ebqflg, ebq, warn, quiet, cnflg, timef, spsizf, mypadn, tsecs;extern long filcnt, tlci, tlco, ffc, tfc, fsize;extern char *versio, *protv, *ckxv, *ckzv, *fnsv, *connv, *dftty, *cmdv;extern char *dialv, *loginv;extern char *ckxsys, *ckzsys, *cmarg, *cmarg2, **xargv, **cmlist;extern CHAR mystch, stchr, sstate, mypadc, padch, eol, seol, ctlq, filnam[], ttname[];extern char *DIRCMD, *PWDCMD, cmerrp[];char *strcpy(), *getenv();/* Declarations from cmd package */extern char cmdbuf[]; /* Command buffer *//* Declarations from ck?fio.c module */extern char *SPACMD, *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 */ tlevel, /* Take command level */ 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];/* Form Feed *//* C M D L I N -- Get arguments from command line *//* Simple Unix-style command line parser, conforming with 'A Proposed Command Syntax Standard for Unix 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++; 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(GOOD_EXIT); } else { /* No dash where expected */ usage(); doexit(BAD_EXIT); } } 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; } 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 */}/* Form Feed *//* D O A R G -- Do a command-line argument. */doarg(x) char x; { int z; char *xp; 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"); z = nfils = 0; /* Initialize file counter, flag */ cmlist = xargv+1; /* Remember this pointer */ 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"); } debug(F101,*xargv,"",nfils); action = 's'; break;/* cont'd... *//* Form Feed *//* ...doarg(), cont'd */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; */ local = (strcmp(ttname,CTTNAM) != 0); /* (better than old way) */ 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 'i': /* Treat files as binary */ binary = 1; break;/* cont'd... *//* Form Feed *//* ...doarg(), cont'd */case 'w': /* File warning */ warn = 1; break;case 'q': /* Quiet */ quiet = 1; break;case 'd': /* debug */ debopn("debug.log"); 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);}/* Form Feed *//* Misc */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 */#ifdef AMIGA if (!quiet) printf3("\r\n%s - %s\n",cmerrp,msg);#else if (!quiet) fprintf(stderr,"\r\n%s - %s\n",cmerrp,msg);#endif tlog(F110,"Error -",msg,0l);}/* Form Feed *//* Interactive command parser *//* Top-Level Keyword Table */struct keytab cmdtab[] = { "!", XXSHE, 0, "%", XXCOM, CM_INV, "bye", XXBYE, 0, "c", XXCON, CM_INV, "close", XXCLO, 0, "connect", XXCON, 0, "cwd", XXCWD, 0, "dial", XXDIAL, 0, "directory", XXDIR, 0, "echo", XXECH, 0, "exit", XXEXI, 0, "finish", XXFIN, 0, "get", XXGET, 0, "help", XXHLP, 0, "log", XXLOG, 0, "quit", XXQUI, 0, "r", XXREC, CM_INV, "receive", XXREC, 0, "remote", XXREM, 0, "s", XXSEN, CM_INV, "script", XXLOGI, 0, "send", XXSEN, 0, "server", XXSER, 0, "set", XXSET, 0, "show", XXSHO, 0, "space", XXSPA, 0, "statistics", XXSTA, 0, "take", XXTAK, 0};int ncmd = (sizeof(cmdtab) / sizeof(struct keytab));/* Form Feed *//* Parameter keyword table */struct keytab prmtab[] = { "baud", XYSPEE, CM_INV, "block-check", XYCHKT, 0, "delay", XYDELA, 0, "duplex", XYDUPL, 0, "end-of-packet", XYEOL, CM_INV, /* moved to send/receive */ "escape-character", XYESC, 0, "file", XYFILE, 0, "flow-control", XYFLOW, 0, "handshake", XYHAND, 0, "incomplete", XYIFD, 0, "line", XYLINE, 0, "modem-dialer", XYMODM, 0, "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 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -