home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / convergent / ctuser.c < prev    next >
C/C++ Source or Header  |  2020-01-01  |  44KB  |  1,518 lines

  1. char *userv = "User interface CTOS/BTOS Version-2.00, Apr 1992";
  2.  
  3. /*  C K U S E R --  "User Interface" for C-Kermit (Part 1)  */
  4.  
  5. /* modified for CTOS C2.0 by Joel Dunn, UNC-CH, October 1986 */
  6. /* modified for CTOS/BTOS Kermit 2.00 by D. Drury, E. Arnerich Jan 1992 */
  7.  
  8. /*  Frank da Cruz, Columbia University Center for Computing Activities, 1985 */
  9. /*
  10.  The ckuser module contains the terminal input and output functions for
  11.  C-Kermit.  It includes a simple Unix-style command line parser as well as
  12.  an interactive prompting keyword command parser.  It depends on the existence
  13.  of Unix facilities like fopen, fgets, feof, (f)printf, argv/argc, etc.  Other
  14.  functions that are likely to vary among C implementations -- like setting
  15.  terminal modes or interrupts -- are invoked via calls to functions that are
  16.  defined in the system-dependent modules, ck[xz]*.c.
  17.  
  18.  The command line parser processes any arguments found on the command line,
  19.  as passed to main() via argv/argc.  The interactive parser uses the facilities
  20.  of the cmd package (developed for this program, but usable by any program).
  21.  
  22.  Any command parser may be substituted for this one.  The only requirements
  23.  for the Kermit command parser are these:
  24.  
  25.  1. Set parameters via global variables like duplex, speed, ttname, etc.
  26.     See ckmain.c for the declarations and descriptions of these variables.
  27.  
  28.  2. If a command can be executed without the use of Kermit protocol, then
  29.     execute the command directly and set the variable sstate to 0. Examples
  30.     include 'set' commands, local directory listings, the 'connect' command.
  31.  
  32.  3. If a command requires the Kermit protocol, set the following variables:
  33.  
  34.     sstate                             string data
  35.       'x' (enter server mode)            (none)
  36.       'r' (send a 'get' command)         cmarg, cmarg2
  37.       'v' (enter receive mode)           cmarg2
  38.       'g' (send a generic command)       cmarg
  39.       's' (send files)                   nfils, cmarg & cmarg2 OR cmlist
  40.       'c' (send a remote host command)   cmarg
  41.  
  42.     cmlist is an array of pointers to strings.
  43.     cmarg, cmarg2 are pointers to strings.
  44.     nfils is an integer.
  45.  
  46.     cmarg can be a filename string (possibly wild), or
  47.        a pointer to a prefabricated generic command string, or
  48.        a pointer to a host command string.
  49.     cmarg2 is the name to send a single file under, or
  50.        the name under which to store an incoming file; must not be wild.
  51.     cmlist is a list of nonwild filenames, such as passed via argv.
  52.     nfils is an integer, interpreted as follows:
  53.       -1: argument string is in cmarg, and should be expanded internally.
  54.        0: stdin.
  55.       >0: number of files to send, from cmlist.
  56.  
  57.  The screen() function is used to update the screen during file transfer.
  58.  The tlog() function maintains a transaction log.
  59.  The debug() function maintains a debugging log.
  60.  The intmsg() and chkint() functions provide the user i/o for interrupting
  61.    file transfers.
  62. */
  63. /*      MODIFICATIONS:
  64.  
  65.             May 1991
  66.             Added GOTO, IF, HANGUP, commands to top level
  67.             command list.  Enhanced EXIT/QUIT commands.
  68.  
  69.             The GOTO command is implemented as a standalone
  70.             command that only is applicable is the variable
  71.             "tlevel" is > -1. (meaning a take file is being
  72.             processed)  The implementation is ported from UNIX
  73.             Kermit version 5A.
  74.  
  75.             The IF command implementation is a subset of the UNIX
  76.                         Kermit version 5A.
  77.             The syntax of the IF statement is:
  78.             IF {success | failure | count | equal | defined}. 
  79.                         Success and Failure values
  80.             are determined by the contents of the global
  81.             variable "success".  The Count is initialized
  82.             using the SET COUNT command.  Count is decremented
  83.             each time an IF COUNT is executed.  The IF COUNT
  84.             fails if COUNT = 0.  NOTE: There is only one
  85.             count value maintained for each take file.
  86.                         EQUAL compares two argum:wq
  87.  
  88.  
  89.             The COUNT parameter is implemented as a parameter
  90.             that is only applicable if the variable "tlevel" >
  91.             -1.  COUNT is maintained as an integer.
  92.  
  93.                         NOTE: The global success variable is only modified in
  94.              parser() upon return from execution of a top level
  95.             command.  This differs from Unix Kermit which modifies
  96.              success inside each command (at all levels).
  97.  
  98.             EXITSTAT is implemented for EXIT/QUIT to take advantage
  99.             of the CTOS/BTOS Exit Run capability to indicate
  100.             to the next function the conditions under which
  101.             Kermit exited. It can be used with any EXIT or QUIT
  102.             command.  By default, no EXITSTAT is the same as
  103.             Exit 0.
  104.             EXITSTAT is maintained as an integer.
  105.            OCTOBER 1991
  106.             Implemented variables.
  107.                         ASK, ASKQ, ASSIGN, IF EQUAL, IF DEFINED, DELETE 
  108.             SHOW MACRO
  109.  
  110.        APRIL 1992
  111.             Implemented SET END commands.            
  112.  
  113.             Implemented SET RETRY and SET TIMEOUT commands 
  114.  
  115.             Re-arranged "SHOW" command output to better fit
  116.             screen.
  117.  
  118.             Many thanks to Joel Dunn for his considerable
  119.             knowledge of the particulars of CTOS/BTOS and
  120.             sharing that knowledge with us.
  121.             Joel: We hope you get an office with a window!
  122.  
  123.             Thanks also to Bill Price of U. S. Army Information 
  124.                         Software Systems Development Center at Fort Lee, VA
  125.                         for his assistance and knowledge of CTOS/BTOS.
  126.  
  127.             Doug Drury
  128.             Evan Arnerich
  129.             ITT Federal Servics Corporation
  130.             2810 Industrial Parkway
  131.             Santa Maria, CA 93454
  132.             (805) 928-4371
  133. */
  134. /* Includes */
  135.  
  136. #include "ctermi.h"
  137. #include "ctcmd.h"
  138. #include "ctuser.h"
  139.  
  140. /* External Kermit Variables, see ckmain.c for description. */
  141.  
  142. extern int size, spsiz, npad, timint, speed, local, server, image, flow,
  143.   displa, binary, fncnv, delaytime, parity, deblog, escape, xargc, maxtry,
  144.   turn, duplex, cxseen, czseen, nfils, ckxech, pktlog, seslog, tralog, stdouf,
  145.   turnch, chklen, bctr, bctu, fsize, dfloc, mdmtyp,
  146.   rptflg, ebqflg, warn, quiet, cnflg, timef, mypadn, termtype;
  147.  
  148. extern long filcnt, tlci, tlco, ffc, tfc;
  149.  
  150. extern char *versio, *protv, *ckxv, *ckzv, *fnsv, *connv, *dftty, *cmdv;
  151. extern char *ckxsys, *ckzsys, *cmarg, *cmarg2, **xargv, **cmlist;
  152. extern char mystch, sstate, mypadc, padch, eol, ctlq, filnam[], ttname[];
  153. extern char g_vars[MAXVARS][MAXVARL], *ckdirv, *ckvt100v;
  154. int expand_var;
  155. char *strcpy();
  156.  
  157. /* Declarations from cmd package */
  158.  
  159. extern char cmdbuf[];             /* Command buffer */
  160. extern char inicmd[MAXINI][CMDBL];     /* Commands from -O */
  161. extern int  inicmd_index, inicmd_count; /* from command line  */
  162.  
  163. /* Declarations from ckzctos module */
  164.  
  165. extern char *zhome();        /* Home directory. */
  166.  
  167. /* Variables and symbols local to this module */
  168.  
  169. char savbuf[CMDBL+4];             /* Buffer to hold command part of IF*/
  170. char line[100], *lp;            /* Character buffer for anything */
  171. char debfil[50];            /* Debugging log file name */
  172. char pktfil[50];            /* Packet log file name */
  173. char sesfil[50];            /* Session log file name */
  174. char trafil[50];            /* Transaction log file name */
  175. struct ucbtype                /* CTOS user control block */
  176.     {
  177.     int reserved;
  178.     char sizevol;
  179.     char volname[12];
  180.     char sizedir;
  181.     char dirname[12];
  182.     char sizepw;
  183.     char password[12];
  184.     } ucb;
  185. struct vhbtype                /* CTOS volume home block */
  186.     {
  187.     char reserved[108];
  188.     long int freespace;
  189.     } vhb;
  190. char showvol[13];            /* Current volume for CWD */
  191. char showdir[13];            /* Current directory for CWD */
  192. char showpw[13];            /* Current password for CWD */
  193.  
  194. int n,                    /* General purpose int */
  195.     cflg,                /* Command-line connect cmd given */
  196.     action,                /* Action selected on command line*/
  197.     repars,                /* Reparse needed */
  198.     tlevel,                /* Take command level */
  199.     terror = 0,                         /* Take Error Action 0 = quit */
  200.     techo = 1;                          /* Take Echo 1 = on */
  201.     success = 1;                        /* Command success indicator  */
  202.  
  203. #define MAXTAKE 20            /* Maximum nesting of TAKE files */
  204. FILE *tfile[MAXTAKE];            /* File pointers for TAKE command */
  205. int count[MAXTAKE];                     /* Array of counts 1 per take file */
  206.  
  207. char *homdir;                /* Pointer to home directory string */
  208. char cmdstr[100];
  209.  
  210. /*  C M D L I N  --  Get arguments from command line  */
  211. /*
  212.  Simple Unix-style command line parser, conforming with 'A Proposed Command
  213.  Syntax Standard for Unix Systems', Hemenway & Armitage, Unix/World, Vol.1,
  214.  No.3, 1984.
  215. */
  216. cmdlin() {
  217.     char x;
  218.     cmarg = "";                /* Initialize. */
  219.     cmarg2 = "";
  220.     action = cflg = 0;
  221.  
  222.     while (--xargc > 0) {        /* Go through command line words */
  223.     *xargv++;
  224.     debug(F111,"xargv",*xargv,xargc);
  225.         if (**xargv == '-') {        /* Got an option (begins with dash) */
  226.         x = *(*xargv+1);        /* Get the option letter */
  227.         x = doarg(x);        /* Go handle the option */
  228.         if (x < 0) doexit(0);
  229.         } else {            /* No dash where expected */
  230.         usage();
  231.         doexit(1);
  232.     }
  233.     }
  234.     debug(F101,"action","",action);
  235.     if (!local) {
  236.     if ((action == 'g') || (action == 'r') ||
  237.         (action == 'c') || (cflg != 0))
  238.         fatal("-l and -b required");
  239.     }
  240.     if (*cmarg2 != 0) {
  241.     if ((action != 's') && (action != 'r') &&
  242.         (action != 'v'))
  243.         fatal("-a without -s, -r, or -g");
  244.     }
  245.     if ((action == 'v') && (stdouf) && (!local)) {
  246.         if (isatty(1))
  247.         fatal("unredirected -k can only be used in local mode");
  248.     }
  249.     if ((action == 's') || (action == 'v') ||
  250.         (action == 'r') || (action == 'x')) {
  251.     if (local) displa = 1;
  252.     if (stdouf) displa = 0;
  253.     }
  254.  
  255.     if (quiet) displa = 0;        /* No display if quiet requested */
  256.  
  257.     if (cflg) {
  258.     conect();            /* Connect if requested */
  259.     if (action == 0) {
  260.         if (cnflg) conect();    /* And again if requested */
  261.         doexit(0);            /*  exit with status = 0 */
  262.     }
  263.     }
  264.     if (displa) concb(escape);        /* (for console "interrupts") */
  265.     return(action);            /* Then do any requested protocol */
  266. }
  267.  
  268. /*  D O A R G  --  Do a command-line argument.  */
  269.  
  270. doarg(x) char x; {
  271.     int z; char *xp;
  272.  
  273.     xp = *xargv+1;            /* Pointer for bundled args */
  274.     while (x) {
  275.  
  276.     switch (x) {
  277.  
  278. case 'O':
  279.     if (inicmd_count >= MAXINI) fatal("too many -O arguments");
  280.     if (*(xp+1)) fatal("invalid argument bundling after -O");
  281.  
  282.     *xargv++; xargc--;
  283.     while (strlen(inicmd[inicmd_count]) < CMDBL &&
  284.     **xargv != '-' && xargc > 0) {        /* copy text to inicmd */
  285.     if (strlen(inicmd[inicmd_count]) !=0)
  286.         strcat(inicmd[inicmd_count], " ");
  287.     strcat(inicmd[inicmd_count], *xargv);
  288.     *xargv++; xargc--;
  289.     }
  290.     if (**xargv == '-') xp = *xargv;        /* point to next '-' */
  291.  
  292.     if (!inicmd[inicmd_count]) fatal("missing command for -O option");
  293.     strcat(inicmd[inicmd_count++], "\n");    /* point to next inicmd */
  294.     break;
  295.  
  296. case 'x':                /* server */
  297.     if (action) fatal("conflicting actions");
  298.     action = 'x';
  299.     break;
  300.  
  301. case 'f':
  302.     if (action) fatal("conflicting actions");
  303.     action = setgen('F',"","","");
  304.     break;
  305.  
  306. case 'r':                /* receive */
  307.     if (action) fatal("conflicting actions");
  308.     action = 'v';
  309.     break;
  310.  
  311. case 'k':                /* receive to stdout */
  312.     if (action) fatal("conflicting actions");
  313.     stdouf = 1;
  314.     action = 'v';
  315.     break;
  316.  
  317. case 's':                 /* send */
  318.     if (action) fatal("conflicting actions");
  319.     if (*(xp+1)) fatal("invalid argument bundling after -s");
  320.     z = nfils = 0;            /* Initialize file counter, flag */
  321.     cmlist = xargv+1;            /* Remember this pointer */
  322.     while (--xargc > 0) {        /* Traverse the list */
  323.     *xargv++;
  324.     if (**xargv == '-') {        /* Check for sending stdin */
  325.         if (strcmp(*xargv,"-") != 0) break;
  326.         z++;
  327.         }
  328.     nfils++;            /* Bump file counter */
  329.     }
  330.     xargc++, *xargv--;            /* Adjust argv/argc */
  331.     if (nfils < 1) fatal("missing filename for -s");
  332.     if (z > 1) fatal("-s: too many -'s");
  333.     if (z == 1) {
  334.     if (nfils == 1) nfils = 0;
  335.     else fatal("invalid mixture of filenames and '-' in -s");
  336.     }
  337.     if (nfils == 0) {
  338.     if (isatty(0)) fatal("sending from terminal not allowed");
  339.     }
  340.     debug(F101,*xargv,"",nfils);
  341.     action = 's';
  342.     break;
  343.  
  344. /* cont'd... */
  345.  
  346. /* ...doarg(), cont'd */
  347.  
  348. case 'g':                /* get */
  349.     if (action) fatal("conflicting actions");
  350.     if (*(xp+1)) fatal("invalid argument bundling after -g");
  351.     *xargv++, xargc--;
  352.     if ((xargc == 0) || (**xargv == '-'))
  353.         fatal("missing filename for -g");
  354.     cmarg = *xargv;
  355.     action = 'r';
  356.     break;
  357.  
  358. case 'c':                /* connect before */
  359.     cflg = 1;
  360.     break;
  361.  
  362. case 'n':                /* connect after */
  363.     cnflg = 1;
  364.     break;
  365.  
  366. case 'h':                /* help */
  367.     usage();
  368.     return(-1);
  369.  
  370. case 'a':                /* "as" */
  371.     if (*(xp+1)) fatal("invalid argument bundling after -a");
  372.     *xargv++, xargc--;
  373.     if ((xargc < 1) || (**xargv == '-'))
  374.         fatal("missing name in -a");
  375.     cmarg2 = *xargv;
  376.     break;
  377.  
  378. case 'l':                /* set line */
  379.     if (*(xp+1)) fatal("invalid argument bundling after -l");
  380.     *xargv++, xargc--;
  381.     if ((xargc < 1) || (**xargv == '-'))
  382.         fatal("communication line device name missing");
  383.     strcpy(ttname,*xargv);
  384.     if (strcmp(ttname,dftty) == 0) local = dfloc; else local = 1;
  385.     break;
  386.  
  387. case 'b':                       /* set baud */
  388.     if (*(xp+1)) fatal("invalid argument bundling");
  389.     *xargv++, xargc--;
  390.     if ((xargc < 1) || (**xargv == '-'))
  391.         fatal("missing baud");
  392.     z = atoi(*xargv);            /* Convert to number */
  393.     if (chkspd(z) > -1) speed = z;    /* Check it */
  394.         else fatal("unsupported baud rate");
  395.     break;
  396.  
  397. case 'i':                /* Treat files as binary */
  398.     binary = 1;
  399.     break;
  400.  
  401. /* cont'd... */
  402.  
  403. /* ...doarg(), cont'd */
  404.  
  405.  
  406. case 'w':                /* File warning */
  407.     warn = 1;
  408.     break;
  409.  
  410. case 'q':                /* Quiet */
  411.     quiet = 1;
  412.     break;
  413.  
  414. case 'd':                /* debug */
  415.     debopn("debug.log");
  416.     break;
  417.  
  418. case 'p':                /* set parity */
  419.     if (*(xp+1)) fatal("invalid argument bundling");
  420.     *xargv++, xargc--;
  421.     if ((xargc < 1) || (**xargv == '-'))
  422.         fatal("missing parity");
  423.     switch(x = **xargv) {
  424.     case 'e':
  425.     case 'o':
  426.     case 'm':
  427.     case 's': parity = x; break;
  428.     case 'n': parity = 0; break;
  429.     default:  fatal("invalid parity");
  430.         }
  431.     break;
  432.  
  433. case 't':
  434.     turn = 1;                /* Line turnaround handshake */
  435.     turnch = XON;            /* XON is turnaround character */
  436.     duplex = 1;                /* Half duplex */
  437.     flow = 0;                /* No flow control */
  438.     break;
  439.  
  440. default:
  441.     fatal("invalid argument, type 'kermit -h' for help");
  442.         }
  443.  
  444.     x = *++xp;                /* See if options are bundled */
  445.     }
  446.     return(0);
  447. }
  448.  
  449. /* Misc */
  450.  
  451. fatal(msg) char *msg; {            /* Fatal error message */
  452.     fprintf(stderr,"\r\nFatal: %s\n",msg);
  453.     tlog(F110,"Fatal:",msg,0l);
  454.     doexit(1);                /*  exit with status = 1 */
  455. }
  456.  
  457.  
  458. ermsg(msg) char *msg; {            /* Print error message */
  459.     if (!quiet) fprintf(stderr,"\r\nError - %s\n",msg);
  460.     tlog(F110,"Error -",msg,0l);
  461. }
  462.  
  463. /* Interactive command parser */
  464.  
  465.  
  466. /* Top-Level Keyword Table */
  467.  
  468. struct keytab cmdtab[] = {
  469.     "!",       XXSHE, 0,
  470.     "ask",       XXASK, 0,    /* added 1991 */
  471.     "askq",       XXASKQ, 0,    /* added 1991 */
  472.     "assign",      XXASS, 0,    /* added 1991 */
  473.     "bye",         XXBYE, 0,
  474.     "c",           XXCON, CM_INV,
  475.     "close",       XXCLO, 0,
  476.     "connect",     XXCON, 0,
  477.     "cwd",       XXCWD, 0,
  478.     "delete",       XXDEL, 0,    /* added 1991 */
  479.     "dial",       XXDIAL, 0,   /* modified 1991 added RACAL-VADIC support */
  480.     "directory",   XXDIR, 0,
  481.     "echo",        XXECH, 0,
  482.     "exit",       XXEXI, 0,    /* modified 1991 to exit with optional value */
  483.     "finish",       XXFIN, 0,
  484.     "get",       XXGET, 0,
  485.     "goto",        XXGOTO, 0,      /* added 4/5/91 goto lable in take file */
  486.     "h",       XXHLP, CM_INV,       /* distinguish between help & hangup */
  487.     "hangup",      XXHAN, 0,           /* added modem hangup command 4/5/91 */
  488.     "help",       XXHLP, 0,
  489.     "if",          XXIF,  0,           /* added 4/5/91 UNIX like IF */
  490.     "input",       XXINP, 0,           /* added 7/91 UNIX/DOS like input */
  491.     "log",         XXLOG, 0,
  492.     "output",      XXOUT, 0,           /* added 7/91 UNIX/DOS like output */
  493.     "pause",       XXPAU, 0,
  494.     "pop",         XXPOP, 0,           /* added 6/91 */
  495.     "quit",       XXQUI, 0,
  496.     "r",           XXREC, CM_INV,
  497.     "receive",       XXREC, 0,
  498.     "reinput",     XXRINP, 0,          /* added 7/91 UNIX/DOS like reinput */
  499.     "remote",       XXREM, 0,
  500.     "s",           XXSEN, CM_INV,
  501.     "script",       XXLOGI, 0,
  502.     "send",       XXSEN, 0,
  503.     "server",       XXSER, 0,
  504.     "set",       XXSET, 0,
  505.     "show",        XXSHO, 0,
  506.     "space",       XXSPA, 0,
  507.     "statistics",  XXSTA, 0,
  508.     "take",       XXTAK, 0
  509. };
  510. int ncmd = (sizeof(cmdtab) / sizeof(struct keytab));
  511.  
  512. /* Parameter keyword table */
  513.  
  514. struct keytab prmtab[] = {
  515.     "baud",            XYSPEE,  CM_INV,
  516.     "block-check",      XYCHKT,  0,
  517.     "count",        XYCOUN,  0,    /* added 4/5/91 set count */
  518.     "delay",            XYDELA,  0,
  519.     "duplex",            XYDUPL,  0,
  520.     "end-of-packet",    XYEOL,   0,
  521.     "escape-character", XYESC,   0,
  522.     "file",           XYFILE,  0,
  523.     "flow-control",     XYFLOW,  0,
  524.     "handshake",        XYHAND,  0,
  525.     "line",             XYLINE,  0,
  526.     "modem-dialer",    XYMODM,     0,
  527.     "packet-length",    XYLEN,   0,
  528.     "pad-character",    XYPADC,  0,
  529.     "padding",          XYNPAD,  0,
  530.     "parity",            XYPARI,  0,
  531.     "prompt",            XYPROM,  0,
  532.     "retry",            XYRETR,  0,
  533.     "speed",            XYSPEE,  0,
  534.     "start-of-packet",  XYMARK,  0,
  535.     "take",             XYTAKE,  0,
  536.     "terminal",        XYTERM,  0,
  537.     "timeout",            XYTIMO,  0
  538. };
  539. int nprm = (sizeof(prmtab) / sizeof(struct keytab)); /* How many parameters */
  540.  
  541.  
  542. /* Remote Command Table */
  543.  
  544. struct keytab remcmd[] = {
  545.     "cwd",       XZCWD, 0,
  546.     "delete",    XZDEL, 0,
  547.     "directory", XZDIR, 0,
  548.     "help",      XZHLP, 0,
  549.     "host",      XZHOS, 0,
  550.     "space",     XZSPA, 0,
  551.     "type",      XZTYP, 0,
  552.     "who",       XZWHO, 0
  553. };
  554. int nrmt = (sizeof(remcmd) / sizeof(struct keytab));
  555.  
  556. struct keytab logtab[] = {
  557.     "debugging",    LOGD, 0,
  558.     "packets",        LOGP, 0,
  559.     "session",      LOGS, 0,
  560.     "transactions", LOGT, 0
  561. };
  562. int nlog = (sizeof(logtab) / sizeof(struct keytab));
  563.  
  564. /* Show command arguments */
  565.  
  566. #define SHPAR 0                /* Parameters */
  567. #define SHVER 1                /* Versions */
  568. #define SHMAC 2                /* Macros (variables) */
  569. struct keytab shotab[] = {
  570.     "parameters", SHPAR, 0,
  571.     "versions",   SHVER, 0,
  572.     "macros",      SHMAC, 0
  573. };                  
  574. int nsho = (sizeof(shotab) / sizeof(struct keytab));
  575.  
  576. struct keytab iftab[] = {
  577.     "success", XXIFSU, 0,
  578.     "failure", XXIFFA, 0,
  579.     "count",   XXIFCO, 0,
  580.     "equal",   XXIFEQ, 0,
  581.     "defined", XXIFDE, 0,
  582.     "exist",   XXIFEX, 0
  583. };
  584. int nif = (sizeof(iftab) / sizeof(struct keytab));
  585.  
  586. /*  C M D I N I  --  Initialize the interactive command parser  */
  587.  
  588. cmdini() {
  589.  
  590.     printf("%s,%s\nType ? for help\n",versio,ckxsys);
  591.     cmsetp("CTOS-Kermit>");        /* Set default prompt. */
  592.  
  593.     tlevel = -1;            /* Take file level */
  594.  
  595. /* Look for init file ".kermrc" in home or current directory. */
  596.  
  597.     homdir = zhome();
  598.     lp = line;
  599.     if (homdir)
  600.     sprintf(lp,"<%s>.kermrc",homdir);
  601.     else
  602.         sprintf(lp,".kermrc");
  603.     if ((tfile[0] = fopen(line,"r")) != NULL) {
  604.     tlevel = 0;
  605.     debug(F110,"init file",line,0);
  606.     }
  607.     if (homdir && (tlevel < 0)) {
  608.         sprintf(lp,".kermrc");
  609.     if ((tfile[0] = fopen(line,"r")) != NULL) {
  610.         tlevel = 0;
  611.         debug(F110,"init file",line,0);
  612.     } else {
  613.         debug(F100,"no init file","",0);
  614.         }
  615.     }
  616.  
  617.     congm();                /* Get console tty modes */
  618. }
  619.  
  620.  
  621. /*  T R A P  --  Terminal interrupt handler */
  622.  
  623. trap() {
  624.     debug(F100,"terminal interrupt...","",0);
  625.     doexit(0);                /* exit with status = 0 */
  626. }
  627.  
  628. /*  P A R S E R  --  Top-level interactive command parser.  */
  629.  
  630. parser() {
  631.     int xx;
  632.     concb(escape);        /* Put console in cbreak mode. */
  633.     conint(trap);        /* Turn on console terminal interrupts. */
  634. /*
  635.  sstate becomes nonzero when a command has been parsed that requires some
  636.  action from the protocol module.  Any non-protocol actions, such as local
  637.  directory listing or terminal emulation, are invoked directly from below.
  638. */
  639.     if (local) printf("\n");        /*** Temporary kludge ***/
  640.     sstate = 0;                /* Start with no start state. */
  641.  
  642.     while (sstate == 0) {        /* Parse cmds until action requested */
  643.     while ((tlevel > -1) && feof(tfile[tlevel])) { /* If end of take */
  644.         fclose(tfile[tlevel]);    /* file, close it */
  645.         tlevel--;        /* and forget about it. */
  646.         cmini(ckxech);        /* and clear the cmd buffer. */
  647.      }
  648.         if ((tlevel > -1) && !terror && !success) {
  649.             ermsg("Kermit command error: take file terminated.");
  650.             fclose(tfile[tlevel]);
  651.                         tlevel--;
  652.         }
  653.  
  654.         if (*savbuf) {            /* Do we have command part of IF left? */
  655.            strcpy(cmdbuf,savbuf);    /*process command part of IF */
  656.            *savbuf = NUL;
  657.         }
  658.         else {                   /* Otherwise check TAKE or Interactive */
  659.          if (tlevel > -1 || inicmd_index < inicmd_count) {
  660.           expand_var = 0;
  661.           if (inicmd_index < inicmd_count)
  662.             strcpy(cmdbuf, inicmd[inicmd_index++]);
  663.           else
  664.                     if (fgets(cmdbuf,CMDBL,tfile[tlevel]) == NULL) continue;
  665.                   if (*cmdbuf == ':') continue;  /* Skip label */
  666.                   stripq(cmdbuf);        /* Strip any quotes. */
  667.          }
  668.              else {                /* Otherwise. */
  669.             prompt();            /* Issue interactive prompt. */
  670.             cmini(ckxech);
  671.              }
  672.     }
  673.     repars = 1;
  674.     displa = 0;
  675.     while (repars) {
  676.         cmres();            /* Reset buffer pointers. */
  677.         expand_var = 1;
  678.             xx = cmkey(cmdtab,ncmd,"Command","");   
  679.           debug(F101,"top-level cmkey","",xx);
  680.             debug(F101,"success value","",success);
  681.         switch (docmd(xx)) {
  682.         case -4:        /* EOF */
  683.             doexit(0);        /*  exit with status 0 */
  684.             case -1:        /* Reparse needed */
  685.             repars = 1;
  686.             continue;
  687.             case -2:        /* Invalid command given */
  688.             success = 0;        /* Set Success to False */
  689.                 cmini(ckxech);    /* (fall thru) */
  690.                     repars = 0;
  691.                     continue;
  692.             case -9:
  693.                     repars = 0;         /* Returned by commands that do */
  694.                     continue;           /* manipulate success           */
  695.              case -3:        /* Empty command OK at top level */
  696.         default:        /* Anything else (fall thru) */
  697.             repars = 0;        /* No reparse, get new command. */
  698.             success = 1;        /* Command success indication */
  699.                  continue;
  700.             }
  701.         }
  702.     }
  703. /* Got an action command; disable terminal interrupts and return start state */
  704.  
  705.     if (!local) connoi();        /* Interrupts off only if remote */
  706.     return(sstate);
  707. }
  708.  
  709. /*  D O E X I T  --  Exit from the program.                          */
  710. /*                   invokes ErrorExit to pass exit value to the     */
  711. /*                   specified Exit Run File                         */
  712.  
  713. doexit(exitstat) int exitstat; {
  714.  
  715. /*    ttclos();                 Close external line, if any */
  716. /* I have commented this TTCLOS out because it is done by HANGUP.  If   */
  717. /* HANGUP is not executed, the line will be left up if mdmtyp != direct */
  718. /* (the operating system will close the file, but won't drop the modem  */
  719. /* carrier signal, so the line will stay up )                           */
  720. /* If mdmtyp == direct, this TTCLOS is not needed anyway because the OS */
  721. /* will close the file.  This is the way UNIX and MS-DOS Kermit works.  */
  722. /* I left it in the code to show that it was used at one time and can   */
  723. /* be implemented again if someone needs to do it.                      */
  724. /* D. Drury 1991 */
  725.  
  726.     if (local) {
  727.     strcpy(ttname,dftty);        /* Restore default tty */
  728.     local = dfloc;            /* And default remote/local status */ }
  729.     if (!quiet) conres();        /* Restore console terminal. */
  730.     if (!quiet) connoi();        /* Turn off console interrupt traps. */
  731.  
  732.     if (deblog) {            /* Close any open logs. */
  733.     debug(F100,"Debug Log Closed","",0);
  734.     *debfil = '\0';
  735.     deblog = 0;
  736.     zclose(ZDFILE);
  737.     }
  738.     if (pktlog) {
  739.     *pktfil = '\0';
  740.     pktlog = 0;
  741.     zclose(ZPFILE);
  742.     }
  743.     if (seslog) {
  744.         *sesfil = '\0';
  745.     seslog = 0;
  746.     zclose(ZSFILE);
  747.     }
  748.     if (tralog) {
  749.     tlog(F100,"Transaction Log Closed","",0l);
  750.     *trafil = '\0';
  751.     tralog = 0;
  752.     zclose(ZTFILE);
  753.     }
  754.         errorexit(exitstat);        /* Exit from the program. */
  755. }
  756.  
  757. /*  B L D L E N  --  Make length-encoded copy of string  */
  758.  
  759. char *
  760. bldlen(str,dest) char *str, *dest; {
  761.     int len;
  762.     len = strlen(str);
  763.     *dest = tochar(len);
  764.     strcpy(dest+1,str);
  765.     return(dest+len+1);
  766. }
  767.  
  768.  
  769. /*  S E T G E N  --  Construct a generic command  */
  770.  
  771. setgen(type,arg1,arg2,arg3) char type, *arg1, *arg2, *arg3; {
  772.     char *upstr, *cp;
  773.  
  774.     cp = cmdstr;
  775.     *cp++ = type;
  776.     *cp = NUL;
  777.     if (*arg1 != NUL) {
  778.     upstr = bldlen(arg1,cp);
  779.     if (*arg2 != NUL) {
  780.         upstr = bldlen(arg2,upstr);
  781.         if (*arg3 != NUL) bldlen(arg3,upstr);
  782.     }
  783.     }
  784.     cmarg = cmdstr;
  785.     debug(F110,"setgen",cmarg,0);
  786.  
  787.     return('g');
  788. }
  789.  
  790. /*  D O C M D  --  Do a command  */
  791.  
  792. /*
  793.  Returns:
  794.    -2: user typed an illegal command
  795.    -1: reparse needed
  796.    -9: parse successful - success not modified on return
  797.     0: parse was successful (even tho command may have failed).
  798. */
  799.  
  800. docmd(cx) int cx; {
  801.     int x, y;
  802.     char *s;
  803.  
  804.     expand_var = 1;            /* expand vars as default */
  805.  
  806.     switch (cx) {
  807.  
  808. case -4:                /* EOF */
  809.     if (!quiet) printf("\r\n");
  810.     doexit(0);
  811. case -3:                /* Null command */
  812.     return(0);
  813. case -2:                /* Error */
  814. case -1:                /* Reparse needed */
  815.     return(cx);
  816.  
  817. case XXASK:                /* ask (with echo input)    */
  818. case XXASKQ:                /* askq (no echo of input)    */
  819.     expand_var = 0;            /* don't expand 1st var        */
  820.     s = cmdbuf;
  821.     if ((x = cmfld("Variable Name","",&s)) < 0) return(x);
  822.     y = ckvar(s);
  823.     if (y < 0) {            /* See if we have a variable    */
  824.        printf("\n? Invalid variable name\n");
  825.        return(y);
  826.     }
  827.     if ((x = cmtxt("Prompt string","",&s)) < 0) {
  828.     printf("You must specify prompt text\n");
  829.     return(x);
  830.     }                        /* prompt the operator    */
  831.     if ((x = cmcfm()) < 0) return(x);
  832.     if (askvar(y, cmdbuf, (cx == XXASK)) < 0)
  833.     printf("\n?More parameters are needed\n"); /* to input the string */
  834.     return(0);
  835.  
  836. case XXASS:                             /* assign */
  837.     expand_var = 0;            /* don't expand 1st var    */
  838.     s = cmdbuf;
  839.     if ((x = cmfld("Variable Name","",&s)) < 0) return(x);
  840.  
  841.     y = ckvar(s);
  842.     if (y < 0) {            /* See if we have a variable */
  843.        printf("\n? Invalid variable name\n");
  844.        return(y);
  845.     }
  846.     if ((x = cmtxt("Value to be assigned","",&s)) < 0) return(x);
  847.     if ((x = cmcfm()) < 0) return(x);
  848.     savvar(y, cmdbuf);            /* save the value into g_vars */
  849.     return(0);
  850.  
  851. case XXBYE:                /* bye */
  852.     if ((x = cmcfm()) < 0) return(x);
  853.     if (!local) {
  854.     printf("You have to 'set line' first\n");
  855.     return(-2);
  856.     }
  857.     sstate = setgen('L',"","","");
  858.     return(0);
  859.  
  860. case XXCON:                         /* connect */
  861.     if ((x = cmcfm()) < 0) return(x);
  862.     conres();                /* restore tty to normal mode */
  863.     x = conect();
  864.     concb(escape);            /* tty back in character mode */
  865.     return(x);
  866.  
  867. case XXCWD:                /* change working directory */
  868.     *homdir = "[sys]<wp>";
  869.     if (cmtxt("Name of local directory, or CR for [sys]<wp>",
  870.           homdir,&s) < 0)
  871.       return(-1);
  872.     if (zchdir(s)) perror("Invalid directory string\n");
  873.     if (getucb(&ucb, sizeof(ucb))) return(0);
  874.     for (x = 0; x < 13; x++)
  875.         {
  876.         if (x < ucb.sizevol) showvol[x] = ucb.volname[x];
  877.         else showvol[x] = 0x00;
  878.         }
  879.     for (x = 0; x < 13; x++)
  880.         {
  881.         if (x < ucb.sizedir) showdir[x] = ucb.dirname[x];
  882.         else showdir[x] = 0x00;
  883.         }
  884.     for (x = 0; x < 13; x++)
  885.         {
  886.         if (x < ucb.sizepw) showpw[x] = ucb.password[x];
  887.         else showpw[x] = 0x00;
  888.         }
  889.     printf("Current Path = [%s]<%s>^%s\n\n", showvol, showdir,showpw);
  890.     return(0);
  891.  
  892. case XXCLO:
  893.     x = cmkey(logtab,nlog,"Which log to close","");
  894.     if (x == -3) {
  895.     printf("?You must tell which log\n");
  896.     return(-2);
  897.     }
  898.     if (x < 0) return(x);
  899.     if ((y = cmcfm()) < 0) return(y);
  900.     switch (x) {
  901.  
  902.     case LOGD:
  903.         if (deblog == 0) {
  904.         printf("?Debugging log wasn't open\n");
  905.         return(0);
  906.         }
  907.         *debfil = '\0';
  908.         deblog = 0;
  909.         return(zclose(ZDFILE));
  910.  
  911.     case LOGP:
  912.         if (pktlog == 0) {
  913.         printf("?Packet log wasn't open\n");
  914.         return(-2);
  915.         }
  916.         *pktfil = '\0';
  917.         pktlog = 0;
  918.         return(zclose(ZPFILE));
  919.  
  920.     case LOGS:
  921.         if (seslog == 0) {
  922.         printf("?Session log wasn't open\n");
  923.         return(-2);
  924.         }
  925.         *sesfil = '\0';
  926.         seslog = 0;
  927.         return(zclose(ZSFILE));
  928.  
  929.         case LOGT:
  930.         if (tralog == 0) {
  931.         printf("?Transaction log wasn't open\n");
  932.         return(-2);
  933.         }
  934.         *trafil = '\0';
  935.         tralog = 0;
  936.         return(zclose(ZTFILE));
  937.  
  938.     default:
  939.         printf("\n?Unexpected log designator - %ld\n", x);
  940.         return(0);
  941.     }
  942.  
  943. case XXDEL:                /* delete */
  944.     if ((x = cmifi("File to delete","",&s,&y)) < 0) {
  945.     if (x == -3) 
  946.         printf("?A file specification is required\n");
  947.     return(-2);
  948.     }
  949.     strcpy(line,s);            /* Make a safe copy of the name. */
  950.     debug(F110,"xxdel line",s,0);
  951.     if ((y = cmcfm()) < 0) return(y);    /* Confirm the user's command. */
  952.     if (zdelet(line) != 0);        /* Delete the file. */
  953.     return(-2);
  954.     return(0);
  955.  
  956. case XXDIAL:                /* dial number */
  957.     if ((x = cmtxt("Number to be dialed","",&s)) < 0) return(x);
  958.     return( dial(s) );            /* return success 0=connected -2=fail*/
  959.  
  960. case XXDIR:                /* list files in current directory */
  961.     printdir();
  962.     return(0);
  963.  
  964. case XXECH:                /* echo */
  965.     x = cmtxt("Material to be echoed","",&s);
  966.     if (x < 0) return(x);
  967.     printf("%s\n",s);
  968.     return(0);
  969.  
  970. case XXQUI:                /* quit, exit */
  971. case XXEXI:
  972.     y = cmnum("Value to pass to Exit Run","0",10,&x);
  973.     if ((y = cmcfm()) > -1) {
  974.         if (x < 0) x = 0;
  975.         doexit(x);
  976.     }
  977.     else return(-2);
  978.  
  979. case XXFIN:                /* finish */
  980.     if ((x = cmcfm()) < 0) return(x);
  981.     if (!local) {
  982.     printf("You have to 'set line' first\n");
  983.     return(0);
  984.     }
  985.     sstate = setgen('F',"","","");
  986.     return(0);
  987.  
  988. case XXGET:                /* Get */
  989.     if (!local) {
  990.     printf("\nYou have to 'set line' first\n");
  991.     return(-2);
  992.     }
  993.     x = cmtxt("Name of remote file(s), or carriage return","",&cmarg);
  994.     if ((x == -2) || (x == -1)) return(x);
  995.  
  996. /* If foreign file name omitted, get foreign and local names separately */
  997.  
  998.     if (*cmarg == NUL) {
  999.  
  1000.     if (tlevel > -1) {        /* Input is from take file */
  1001.  
  1002.         if (fgets(line,100,tfile[tlevel]) == NULL)
  1003.             fatal("take file ends prematurely in 'get'");
  1004.         stripq(line);
  1005.         cmarg = line;
  1006.         if (fgets(cmdbuf,CMDBL,tfile[tlevel]) == NULL)
  1007.             fatal("take file ends prematurely in 'get'");
  1008.         stripq(cmdbuf);
  1009.         if (*cmdbuf == NUL) cmarg2 = line; else cmarg2 = cmdbuf;
  1010.  
  1011.         } else {            /* Input is from terminal */
  1012.  
  1013.         char psave[40];        /* Save old prompt */
  1014.         cmsavp(psave,40);
  1015.         cmsetp(" Remote file specification: "); /* Make new one */
  1016.         cmini(ckxech);
  1017.         x = -1;
  1018.         while (x < 0) {        /* Prompt till they answer */
  1019.             prompt();
  1020.             x = cmtxt("Name of remote file(s)","",&cmarg);
  1021.             if (*cmarg == NUL) x = -1;
  1022.         }
  1023.         strcpy(line,cmarg);        /* Make a safe copy */
  1024.         cmarg = line;
  1025.         cmsetp(" Local name to store it under: ");    /* New prompt */
  1026.         cmini(ckxech);
  1027.         x = -1;
  1028.         while (x < 0) {        /* Again, prompt till answered */
  1029.             prompt();
  1030.             x = cmofi("Local file name",cmarg,&cmarg2);
  1031.         if (x == -2) return(x);
  1032.             }
  1033.         cmsetp(psave);        /* Restore old prompt. */
  1034.         if ((x == cmcfm()) < 0) return(-2);
  1035.         }
  1036.     }
  1037.     sstate = 'r';            /* All ok, set start state. */
  1038.     if (local) displa = 1;
  1039.     return(0);
  1040.  
  1041. case XXGOTO:                           /* GOTO */
  1042.     if (tlevel < 0) {
  1043.     printf ("GOTO only useful from inside a TAKE file\n");
  1044.     return(0);
  1045.     }
  1046.  
  1047.     strcpy(line,cmdbuf);            /* Save copy of string just parsed. */
  1048.     *cmarg2 = NUL;            /* Initialize lable name */
  1049.     if ((x = cmfld("Label to GOTO",cmarg2,&s)) < 0) return(x);
  1050.     x = dogoto(s);        /* dogoto will return -2 if condition is invalid */
  1051.     return(x);            /* otherwise it will return -9                   */
  1052.  
  1053. case XXHAN:                            /* HANGUP */
  1054.     if (x = (cmcfm()) < 0) return(x);
  1055.     x = tthang();
  1056.     printf ("The modem connection should have hung up \n");
  1057.     return (x);
  1058.  
  1059. case XXHLP:                /* Help */
  1060.     x = cmkey(cmdtab,ncmd,"C-Kermit command","help");
  1061.     return(dohlp(x));
  1062.  
  1063. case XXIF:                             /* IF */
  1064.     x = cmkey(iftab,nif,"Condition","");
  1065.     if (x == -3)
  1066.     return(-2);
  1067.     if (x < 0) return(x); 
  1068.     x = doif(x);
  1069.     return(x);
  1070.  
  1071. case XXINP:                            /* INPUT */
  1072.     y = cmnum("Input wait time","0",10,&x);
  1073.     y = cmtxt("String to look for","",&s);
  1074.     x = doinput(s, x);
  1075.     return(x);
  1076.  
  1077. case XXOUT:                            /* OUTPUT */
  1078.     y = cmtxt("String to output","",&s);
  1079.     x = dooutput(s);
  1080.     return(x);
  1081.  
  1082. case XXPAU:
  1083.     y = cmnum("Number of seconds to PAUSE","0",10,&x);
  1084.     if (y = (cmcfm()) < 0) return(x);
  1085.  
  1086.     if (x < 0) return(-2);
  1087.     x = x*10;     /*delay expects tenths of seconds */
  1088.     delay(x);
  1089.     return(0);
  1090.  
  1091. case XXPOP:         /* POP  like MS-DOS v3.01 POP */
  1092.     if (x = (cmcfm()) < 0) return(x);
  1093.     if (tlevel < 0) {
  1094.        printf("POP is only useful from inside a Take file\n");
  1095.        return(-2);
  1096.     }
  1097.     fclose(tfile[tlevel]);
  1098.     tlevel--;
  1099.     return(-9);  /* return without modifying SUCCESS */
  1100.  
  1101. case XXLOG:                /* Log */
  1102.     x = cmkey(logtab,nlog,"What to log","");
  1103.     if (x == -3) {
  1104.     printf("?You must specify what is to be logged\n");
  1105.     return(-2);
  1106.     }
  1107.     if (x < 0) return(x);
  1108.     return(dolog(x));
  1109.  
  1110. case XXLOGI:                /* login to remote system */
  1111.     if ((x = cmtxt("Text of login script","",&s)) < 0) return(x);
  1112.     return( login(s) );            /* return success 0=completed -2=fail*/
  1113.  
  1114. case XXREC:                /* Receive */
  1115.     cmarg2 = "";
  1116.     x = cmofi("Name under which to store the file, or CR","",&cmarg2);
  1117.     if ((x == -1) || (x == -2)) return(x);
  1118.     debug(F111,"cmofi cmarg2",cmarg2,x);
  1119.     if ((x = cmcfm()) < 0) return(x);
  1120.     sstate = 'v';
  1121.     if (local) displa = 1;
  1122.     return(0);
  1123.  
  1124. case XXREM:                /* Remote */
  1125.     if (!local) {
  1126.     printf("\nYou have to 'set line' first\n");
  1127.     return(-2);
  1128.     }
  1129.     x = cmkey(remcmd,nrmt,"Remote Kermit server command","");
  1130.     if (x == -3) {
  1131.     printf("?You must specify a command for the remote server\n");
  1132.     return(-2);
  1133.     }
  1134.     return(dormt(x));
  1135.  
  1136. case XXRINP:                            /* Reinput */
  1137.     y = cmtxt("String to look for","",&s);
  1138.     x = dorinput(s);
  1139.     return(x);
  1140.  
  1141. case XXSEN:                /* Send */
  1142.     cmarg = cmarg2 = "";
  1143.     if ((x = cmifi("File(s) to send","",&s,&y)) < 0) {
  1144.     if (x == -3) {
  1145.         printf("?A file specification is required\n");
  1146.         return(-2);
  1147.     }
  1148.     return(x);
  1149.     }
  1150.     nfils = -1;                /* Files come from internal list. */
  1151.     strcpy(line,s);            /* Save copy of string just parsed. */
  1152.     debug(F101,"Send: wild","",y);
  1153.     *cmarg2 = '\0';            /* Initialize send-as name */
  1154.     if (y == 0) {
  1155.     if ((x = cmfld("Name to send it with",line,&cmarg2)) < 0) return(x);
  1156.     }
  1157.     if ((x = cmcfm()) < 0) return(x);
  1158.     cmarg = line;            /* File to send */
  1159.     debug(F110,"Sending:",cmarg,0);
  1160.     debug(F110," as:",cmarg2,0);
  1161.     sstate = 's';            /* Set start state */
  1162.     if (local) displa = 1;
  1163.     return(0);
  1164.  
  1165. case XXSER:                /* Server */
  1166.     if (x = (cmcfm()) < 0) return(x);
  1167.     sstate = 'x';
  1168.     if (local) displa = 1;
  1169.     return(0);
  1170.  
  1171. case XXSET:                /* Set */
  1172.     x = cmkey(prmtab,nprm,"Parameter","");
  1173.     if (x == -3) {
  1174.     printf("?You must specify a parameter to set\n");
  1175.     return(-2);
  1176.     }
  1177.     if (x < 0) return(x);
  1178.     return(doprm(x));
  1179.  
  1180. /* not implemented for CTOS yet */
  1181. /*case XXSHE:
  1182.       return(0);*/
  1183.  
  1184. case XXSHO:                /* Show */
  1185.     x = cmkey(shotab,nsho,"","parameters");
  1186.     if (x < 0) return(x);
  1187.     if (y = (cmcfm()) < 0) return(y);
  1188.     switch (x) {
  1189.  
  1190.     case SHPAR:
  1191.         shopar();
  1192.         break;
  1193.  
  1194.     case SHVER:
  1195.         printf("\nVersions:\n %s\n %s\n %s\n",versio,protv,fnsv);
  1196.         printf(" %s\n %s\n %s for%s\n",cmdv,userv,ckxv,ckxsys);
  1197.         printf(" %s for%s\n %s\n",ckzv,ckzsys,connv);
  1198.         printf(" %s\n %s\n\n",ckdirv,ckvt100v);
  1199.         break;
  1200.  
  1201.     case SHMAC:
  1202.         shomac();
  1203.         break;
  1204.  
  1205.     default:
  1206.         printf("\nNothing to show...\n");
  1207.         break;
  1208.     }
  1209.     return(0);
  1210.  
  1211. case XXSPA:                /* free space on user's default volume */
  1212.     if (getucb(&ucb, sizeof(ucb))) return(0);
  1213.     if (getvhb(&ucb.volname[0], ucb.sizevol, &vhb, sizeof(vhb))) return(0);
  1214.     vhb.freespace *= 512;
  1215.     printf("\nNumber of bytes free on volume is %ld\n\n",vhb.freespace);
  1216.     return(0);
  1217.  
  1218. case XXSTA:                /* statistics */
  1219.     if (x = (cmcfm()) < 0) return(x);
  1220.     printf("\nMost recent transaction --\n");
  1221.     printf(" files: %ld\n",filcnt);
  1222.     printf(" total file characters  : %ld\n",tfc);
  1223.     printf(" communication line in  : %ld\n",tlci);
  1224.     printf(" communication line out : %ld\n\n",tlco);
  1225.     printf(" block check type used  : %d\n",bctu);
  1226.     printf(" compression            : ");
  1227.     if (rptflg) printf("yes\n"); else printf("no\n");
  1228.     printf(" 8th bit prefixing      : ");
  1229.     if (ebqflg) printf("yes\n"); else printf("no\n\n");
  1230.     return(0);
  1231.  
  1232. case XXTAK:                /* take */
  1233.     if (tlevel > MAXTAKE-1) {
  1234.     printf("?Take files nested too deeply\n");
  1235.     return(-2);
  1236.     }
  1237.     if ((y = cmifi("C-Kermit command file","",&s,&x)) < 0) {
  1238.     if (y == -3) {
  1239.         printf("?A file specification is required\n");
  1240.         return(-2);
  1241.     } else return(y);
  1242.     }
  1243.     if (x != 0) {
  1244.     printf("?Wildcards not allowed in command file name\n");
  1245.     return(-2);
  1246.     }
  1247.     strcpy(line,s);            /* Make a safe copy of the string */
  1248.     if ((y = cmcfm()) < 0) return(y);
  1249.     if ((tfile[++tlevel] = fopen(line,"r")) == NULL) {
  1250.     perror("take");
  1251.     printf("Can't open command file - %s\n",line);
  1252.     debug(F110,"Failure to open",line,0);
  1253.     tlevel--;
  1254.     return(-2);
  1255.     }
  1256.     return(0);
  1257.  
  1258. default:
  1259.     printf("Not available yet - %s\n",cmdbuf);
  1260.     return(-2);
  1261.     }
  1262. }
  1263.  
  1264. /*  S H O P A R  --  Show Parameters  */
  1265.  
  1266. shopar() {
  1267.  
  1268.     printf("\nLine: %s, speed: %d, mode: ",ttname,speed);
  1269.     if (local) printf("local"); else printf("remote");
  1270.     printf(", modem-dialer: ");
  1271.     switch (mdmtyp) {
  1272.     case 1:
  1273.     case 3:
  1274.         printf("hayes");
  1275.         break;
  1276.     case 2:
  1277.         printf("ventel");
  1278.         break;
  1279.     case 4:
  1280.         printf("racal");
  1281.         break;
  1282.     default:
  1283.         printf("direct");
  1284.         break;
  1285.     }
  1286.     printf("\n Parity: ");
  1287.     switch (parity) {
  1288.     case 'e': printf("even");  break;
  1289.     case 'o': printf("odd");   break;
  1290.     case 'm': printf("mark");  break;
  1291.     case 's': printf("space"); break;
  1292.     case 0:   printf("none");  break;
  1293.     default:  printf("invalid - %d",parity); break;
  1294.     }
  1295.     printf(", duplex: ");
  1296.     if (duplex) printf("half, "); else printf("full, ");
  1297.     printf("flow: ");
  1298.     if (flow == 1) printf("xon/xoff");
  1299.     else if (flow == 0) printf("none");
  1300.     else printf("%d",flow);
  1301.     printf(", handshake: ");
  1302.     if (turn) printf("%d\n",turnch); else printf("none\n");
  1303.     printf(" Retries: %d, timeout: %d, delay: %d\n",maxtry,timint,delaytime);
  1304.     printf(" Padding: %d, pad character: %d\n",mypadn,mypadc);
  1305.     printf(" Packet start: %d, end: %d, length: %d",mystch,eol,spsiz);
  1306.     printf(", block check: %d\n",bctr);
  1307.     printf("\nTerminal: ");
  1308.     if (termtype) printf("VT100\n"); else printf("none\n");
  1309.     printf("\nFile parameters:            Logs:\n");
  1310.     printf(" Names:        ");
  1311.     if (fncnv) printf("converted"); else printf("literal  ");
  1312.     printf("     Debugging:     ");
  1313.     if (deblog) printf("%s\n",debfil); else printf("none\n");
  1314.     printf(" Type:         ");
  1315.     if (binary) printf("binary"); else printf("text  ");
  1316.     printf("        Packets:       ");
  1317.     if (pktlog) printf("%s\n",pktfil); else printf("none\n");
  1318.     printf(" Warning:      ");
  1319.     if (warn) printf("on "); else printf("off");
  1320.     printf("           Session:       ");
  1321.     if (seslog) printf("%s\n",sesfil); else printf("none\n");
  1322.     printf(" Display:      ");
  1323.     if (quiet) printf("off"); else printf("on ");
  1324.     printf("           Transactions:  ");
  1325.     if (tralog) printf("%s\n",trafil); else printf("none\n");
  1326.     printf("\n\nTake File Termination On Error (take error):");
  1327.     if (terror) printf(" off\n");
  1328.     else printf(" on\n");
  1329.     printf("Take File Echo (take echo):");
  1330.     if (techo) printf(" on\n");
  1331.     else printf(" off\n");
  1332.     printf("\n");
  1333. }
  1334.  
  1335. /* S H O M A C -- Show Macros (variables)  */
  1336.  
  1337. shomac() {
  1338.  
  1339.     int y;
  1340.  
  1341.     printf("\nVariables:\n\n");
  1342.     for (y = 0; y < MAXVARS>>1; y++)
  1343.     printf("\\\\%%%c: %-20.20s       \\\\%%%c: %-20.20s\n",
  1344.         y+'A', g_vars[y], y+'N', g_vars[y+('N'-'A')]);
  1345. }
  1346.  
  1347. /*  D O L O G  --  */
  1348.  
  1349. dolog(x) int x; {
  1350.     int y; char *s;
  1351.  
  1352.     switch (x) {
  1353.  
  1354.     case LOGD:
  1355.         y = cmofi("Name of debugging log file","debug.log",&s);
  1356.         break;
  1357.  
  1358.     case LOGP:
  1359.         y = cmofi("Name of packet log file","packet.log",&s);
  1360.         break;
  1361.  
  1362.     case LOGS:
  1363.         y = cmofi("Name of session log file","session.log",&s);
  1364.         break;
  1365.  
  1366.     case LOGT:
  1367.         y = cmofi("Name of transaction log file","transaction.log",&s);
  1368.         break;
  1369.  
  1370.     default:
  1371.         printf("\n?Unexpected log designator - %d\n",x);
  1372.         return(-2);
  1373.     }
  1374.     if (y < 0) return(y);
  1375.  
  1376.     strcpy(line,s);
  1377.     s = line;
  1378.     if ((y = cmcfm()) < 0) return(y);
  1379.  
  1380. /* cont'd... */
  1381.  
  1382. /* ...dolog, cont'd */
  1383.  
  1384.  
  1385.     switch (x) {
  1386.  
  1387.     case LOGD:
  1388.         return(deblog = debopn(s));
  1389.  
  1390.     case LOGP:
  1391.         zclose(ZPFILE);
  1392.         y = zopeno(ZPFILE,s);
  1393.         if (y > 0) strcpy(pktfil,s); else *pktfil = '\0';
  1394.         return(pktlog = y);
  1395.  
  1396.     case LOGS:
  1397.         zclose(ZSFILE);
  1398.         y = zopeno(ZSFILE,s);
  1399.         if (y > 0) strcpy(sesfil,s); else *sesfil = '\0';
  1400.         return(seslog = y);
  1401.  
  1402.     case LOGT:
  1403.         zclose(ZTFILE);
  1404.         tralog = zopeno(ZTFILE,s);
  1405.         if (tralog > 0) {
  1406.         strcpy(trafil,s);
  1407.         tlog(F110,"Transaction Log:",versio,0l);
  1408.         tlog(F100,ckxsys,"",0l);
  1409.         ztime(&s);
  1410.         tlog(F100,s,"",0l);
  1411.             }
  1412.         else *trafil = '\0';
  1413.         return(tralog);
  1414.  
  1415.     default:
  1416.         return(-2);
  1417.     }
  1418. }
  1419.  
  1420.  
  1421. /*  D E B O P N  --  Open a debugging file  */
  1422.  
  1423. debopn(s) char *s; {
  1424.     char *tp;
  1425.     zclose(ZDFILE);
  1426.     deblog = zopeno(ZDFILE,s);
  1427.     if (deblog > 0) {
  1428.     strcpy(debfil,s);
  1429.     debug(F110,"Debug Log ",versio,0);
  1430.     debug(F100,ckxsys,"",0);
  1431.     ztime(&tp);
  1432.     debug(F100,tp,"",0);
  1433.     } else *debfil = '\0';
  1434.     return(deblog);
  1435. }
  1436.  
  1437. /*  D O G O T O -- Execute a goto within a take file  */
  1438.  
  1439. dogoto(s) char *s; {
  1440.  
  1441.     int i, x, y;
  1442.  
  1443.     y = strlen(s);
  1444.     if (*s != ':') {
  1445.         y++;                    /* If the label does't start */
  1446.     for (i = y; i > 0; i--) {      /* with a colon, insert one  */
  1447.         s[i] = s[i-1];             /* while keeping all existing */
  1448.     }                              /* characters (hence y++)     */
  1449.     s[0] = ':';             /* insert the colon */
  1450.     s[y++] = NUL;             /* NULL terminate the label */
  1451.     }
  1452.     x = 0;
  1453.     rewind(tfile[tlevel]);           /* Reset file ptr to beginning */
  1454.     while (! feof(tfile[tlevel])) {
  1455.        if (fgets(cmdbuf,CMDBL,tfile[tlevel]) == NULL)
  1456.        break;
  1457.     lp = cmdbuf;
  1458.     while (*lp == ' ' || *lp == '\t')
  1459.         lp++;             /* ditch white space */
  1460.         if (!xxstrcmp(s,lp,y)) {     /* case insensitive strcmp */
  1461.        x = 1;             /* found the right spot ! */
  1462.        break;
  1463.     }
  1464.     }
  1465.     if (x == 0) {
  1466.     debug(F101,"goto failed in take level","",tlevel);
  1467.  
  1468.         /* if we couldn't find the label we're hosed because
  1469.            we already messed up the file pointer, so the only
  1470.            thing to do here is close the file an pop up to the
  1471.            next level.
  1472.      */
  1473.     fclose(tfile[tlevel]);
  1474.     tlevel--;
  1475.         printf("Error -- Label %s not found\n",s);
  1476.     cmini(ckxech);        /* and clear the cmd buffer. */
  1477.     return(-2);        /* and return error */
  1478.     }
  1479.     else return(0);
  1480. }
  1481. /*  X X S T R C M P  -- case insensitive string compare
  1482.                         xxstr1 must be null or new line terminated
  1483.                         returns false if strings are equal
  1484.                         returns true if strings are not equal
  1485. */
  1486. xxstrcmp(xxstr1,xxstr2,len) char *xxstr1, *xxstr2; int len; {
  1487.     int x, y;
  1488.  
  1489.     y = 0;
  1490.     x = 0;
  1491.  
  1492.     while(xxstr1[x] != '\0' && xxstr1[x] != '\n') {
  1493.     if (isalpha(xxstr1[x]) && isalpha(xxstr2[x])) {
  1494.        if (tolower(xxstr1[x]) != tolower(xxstr2[x])) {
  1495.           y = 1;
  1496.               break;
  1497.        }
  1498.     }
  1499.     /* see if both are non-alpha */
  1500.     else if (!isalpha(xxstr1[x]) && !isalpha(xxstr2[x])) {
  1501.                  if (xxstr1[x] != xxstr2[x]) {
  1502.            y = 1;
  1503.                      break;
  1504.         }
  1505.            }
  1506.            else {
  1507.               y = 1;
  1508.                   break;        /* one alpha - one not alpha */
  1509.            }
  1510.         x++;
  1511.                 if (x > len) {      /* if reached end of label but  */
  1512.                    y = 1;          /* not end of search string     */
  1513.                    break;          /* then set not equal and exit  */
  1514.         }
  1515.    }
  1516.    return(y);                   /* all characters equal */
  1517. }
  1518.