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

  1. char *userv = "User Interface 4C(054), 10 Jul 86";
  2.  
  3. /*  C K U U S R --  "User Interface" for Unix Kermit (Part 1)  */
  4.  
  5. /*
  6.  Author: Frank da Cruz (SY.FDC@CU20B),
  7.  Columbia University Center for Computing Activities, January 1985.
  8.  Copyright (C) 1985, Trustees of Columbia University in the City of New York.
  9.  Permission is granted to any individual or institution to use, copy, or
  10.  redistribute this software so long as it is not sold for profit, provided this
  11.  copyright notice is retained. 
  12. */
  13.  
  14. /*
  15.  The ckuser module contains the terminal input and output functions for Unix
  16.  Kermit.  It includes a simple Unix-style command line parser as well as
  17.  an interactive prompting keyword command parser.  It depends on the existence
  18.  of Unix facilities like fopen, fgets, feof, (f)printf, argv/argc, etc.  Other
  19.  functions that are likely to vary among Unix implementations -- like setting
  20.  terminal modes or interrupts -- are invoked via calls to functions that are
  21.  defined in the system-dependent modules, ck?[ft]io.c.
  22.  
  23.  The command line parser processes any arguments found on the command line,
  24.  as passed to main() via argv/argc.  The interactive parser uses the facilities
  25.  of the cmd package (developed for this program, but usable by any program).
  26.  
  27.  Any command parser may be substituted for this one.  The only requirements
  28.  for the Kermit command parser are these:
  29.  
  30.  1. Set parameters via global variables like duplex, speed, ttname, etc.
  31.     See ckmain.c for the declarations and descriptions of these variables.
  32.  
  33.  2. If a command can be executed without the use of Kermit protocol, then
  34.     execute the command directly and set the variable sstate to 0. Examples
  35.     include 'set' commands, local directory listings, the 'connect' command.
  36.  
  37.  3. If a command requires the Kermit protocol, set the following variables:
  38.  
  39.     sstate                             string data
  40.       'x' (enter server mode)            (none)
  41.       'r' (send a 'get' command)         cmarg, cmarg2
  42.       'v' (enter receive mode)           cmarg2
  43.       'g' (send a generic command)       cmarg
  44.       's' (send files)                   nfils, cmarg & cmarg2 OR cmlist
  45.       'c' (send a remote host command)   cmarg
  46.  
  47.     cmlist is an array of pointers to strings.
  48.     cmarg, cmarg2 are pointers to strings.
  49.     nfils is an integer.    
  50.  
  51.     cmarg can be a filename string (possibly wild), or
  52.        a pointer to a prefabricated generic command string, or
  53.        a pointer to a host command string.
  54.     cmarg2 is the name to send a single file under, or
  55.        the name under which to store an incoming file; must not be wild.
  56.     cmlist is a list of nonwild filenames, such as passed via argv.
  57.     nfils is an integer, interpreted as follows:
  58.       -1: argument string is in cmarg, and should be expanded internally.
  59.        0: stdin.
  60.       >0: number of files to send, from cmlist.
  61.  
  62.  The screen() function is used to update the screen during file transfer.
  63.  The tlog() function maintains a transaction log.
  64.  The debug() function maintains a debugging log.
  65.  The intmsg() and chkint() functions provide the user i/o for interrupting
  66.    file transfers.
  67. */
  68.  
  69. /* Includes */
  70.  
  71. #include "ckcdeb.h"
  72. #include <stdio.h>
  73. #include <ctype.h>
  74. #ifndef AMIGA
  75. #include <signal.h>
  76. #endif
  77. #include "ckcker.h"
  78. #include "ckucmd.h"
  79. #include "ckuusr.h"
  80.  
  81. #ifdef vax11c
  82. #define KERMRC "kermit.ini"
  83. #else
  84. #define KERMRC ".kermrc"
  85. #endif
  86.  
  87. /* External Kermit Variables, see ckmain.c for description. */
  88.  
  89. extern int size, spsiz, rpsiz, npad, timint, rtimo, speed, local, server, 
  90.   displa, binary, fncnv, delay, parity, deblog, escape, xargc, flow,
  91.   turn, duplex, cxseen, czseen, nfils, ckxech, pktlog, seslog, tralog, stdouf,
  92.   turnch, chklen, bctr, bctu, dfloc, mdmtyp, keep,
  93.   rptflg, rptq, ebqflg, ebq, warn, quiet, cnflg, timef, spsizf, mypadn, tsecs;
  94.  
  95. extern long filcnt, tlci, tlco, ffc, tfc, fsize;
  96.  
  97. extern char *versio, *protv, *ckxv, *ckzv, *fnsv, *connv, *dftty, *cmdv;
  98. extern char *dialv, *loginv;
  99. extern char *ckxsys, *ckzsys, *cmarg, *cmarg2, **xargv, **cmlist;
  100. extern CHAR mystch, stchr, sstate, mypadc, padch, eol, seol, ctlq, filnam[], 
  101.  ttname[];
  102. extern char *DIRCMD, *PWDCMD, cmerrp[];
  103. char *strcpy(), *getenv();
  104. #ifdef AMIGA
  105. char *getcwd();
  106. #endif
  107.  
  108. /* Declarations from cmd package */
  109.  
  110. extern char cmdbuf[];            /* Command buffer */
  111.  
  112. /* Declarations from ck?fio.c module */
  113.  
  114. extern char *SPACMD, *zhome();        /* Space command, home directory. */
  115. extern int backgrd;            /* Kermit executing in background */
  116.  
  117. /* The background flag is set by ckutio.c (via conint() ) to note whether */
  118. /* this kermit is executing in background ('&' on shell command line).    */
  119.  
  120.  
  121. /* Variables and symbols local to this module */
  122.  
  123. char line[CMDBL+10], *lp;        /* Character buffer for anything */
  124. char debfil[50];            /* Debugging log file name */
  125. char pktfil[50];            /* Packet log file name */
  126. char sesfil[50];            /* Session log file name */
  127. char trafil[50];            /* Transaction log file name */
  128.  
  129. int n,                    /* General purpose int */
  130.     cflg,                /* Command-line connect cmd given */
  131.     action,                /* Action selected on command line*/
  132.     repars,                /* Reparse needed */
  133.     tlevel,                /* Take command level */
  134.     cwdf = 0;                /* CWD has been done */
  135.  
  136. #define MAXTAKE 20            /* Maximum nesting of TAKE files */
  137. FILE *tfile[MAXTAKE];            /* File pointers for TAKE command */
  138.  
  139. char *homdir;                /* Pointer to home directory string */
  140. char cmdstr[100];
  141.  
  142. /*  C M D L I N  --  Get arguments from command line  */
  143. /*
  144.  Simple Unix-style command line parser, conforming with 'A Proposed Command
  145.  Syntax Standard for Unix Systems', Hemenway & Armitage, Unix/World, Vol.1,
  146.  No.3, 1984.
  147. */
  148. cmdlin() {
  149.     char x;                /* Local general-purpose int */
  150.     cmarg = "";                /* Initialize globals */
  151.     cmarg2 = "";
  152.     action = cflg = 0;
  153.  
  154.     while (--xargc > 0) {        /* Go through command line words */
  155.     xargv++;
  156.     debug(F111,"xargv",*xargv,xargc);
  157.         if (**xargv == '-') {        /* Got an option (begins with dash) */
  158.         x = *(*xargv+1);        /* Get the option letter */
  159.         x = doarg(x);        /* Go handle the option */
  160.         if (x < 0) doexit(GOOD_EXIT);
  161.         } else {            /* No dash where expected */
  162.         usage();
  163.         doexit(BAD_EXIT);
  164.     }
  165.     }
  166.     debug(F101,"action","",action);
  167.     if (!local) {
  168.     if ((action == 'g') || (action == 'r') ||
  169.         (action == 'c') || (cflg != 0))
  170.         fatal("-l and -b required");
  171.     }
  172.     if (*cmarg2 != 0) {
  173.     if ((action != 's') && (action != 'r') &&
  174.         (action != 'v'))
  175.         fatal("-a without -s, -r, or -g");
  176.     }
  177.     if ((action == 'v') && (stdouf) && (!local)) {
  178.         if (isatty(1))
  179.         fatal("unredirected -k can only be used in local mode");
  180.     }
  181.     if ((action == 's') || (action == 'v') ||
  182.         (action == 'r') || (action == 'x')) {
  183.     if (local) displa = 1;
  184.     if (stdouf) displa = 0;
  185.     }
  186.  
  187.     if (quiet) displa = 0;        /* No display if quiet requested */
  188.  
  189.     if (cflg) {
  190.     conect();            /* Connect if requested */
  191.     if (action == 0) {
  192.         if (cnflg) conect();    /* And again if requested */
  193.         doexit(GOOD_EXIT);        /* Then exit indicating success */
  194.     }
  195.     }
  196.     if (displa) concb(escape);        /* (for console "interrupts") */
  197.     return(action);            /* Then do any requested protocol */
  198. }
  199.  
  200. /*  D O A R G  --  Do a command-line argument.  */
  201.  
  202. doarg(x) char x; {
  203.     int z; char *xp;
  204.  
  205.     xp = *xargv+1;            /* Pointer for bundled args */
  206.     while (x) {
  207.     switch (x) {
  208.  
  209. case 'x':                /* server */
  210.     if (action) fatal("conflicting actions");
  211.     action = 'x';
  212.     break;
  213.  
  214. case 'f':
  215.     if (action) fatal("conflicting actions");
  216.     action = setgen('F',"","","");
  217.     break;
  218.  
  219. case 'r':                /* receive */
  220.     if (action) fatal("conflicting actions");
  221.     action = 'v';
  222.     break;
  223.  
  224. case 'k':                /* receive to stdout */
  225.     if (action) fatal("conflicting actions");
  226.     stdouf = 1;
  227.     action = 'v';
  228.     break;
  229.  
  230. case 's':                 /* send */
  231.     if (action) fatal("conflicting actions");
  232.     if (*(xp+1)) fatal("invalid argument bundling after -s");
  233.     z = nfils = 0;            /* Initialize file counter, flag */
  234.     cmlist = xargv+1;            /* Remember this pointer */
  235.     while (--xargc > 0) {        /* Traverse the list */    
  236.     *xargv++;
  237.     if (**xargv == '-') {        /* Check for sending stdin */
  238.         if (strcmp(*xargv,"-") != 0) break;
  239.         z++;
  240.         }
  241.     nfils++;            /* Bump file counter */
  242.     }
  243.     xargc++, *xargv--;            /* Adjust argv/argc */
  244.     if (nfils < 1) fatal("missing filename for -s");
  245.     if (z > 1) fatal("-s: too many -'s");
  246.     if (z == 1) {
  247.     if (nfils == 1) nfils = 0;
  248.     else fatal("invalid mixture of filenames and '-' in -s");
  249.     }
  250.     if (nfils == 0) {
  251.     if (isatty(0)) fatal("sending from terminal not allowed");
  252.     }
  253.     debug(F101,*xargv,"",nfils);
  254.     action = 's';
  255.     break;
  256.  
  257. /* cont'd... */
  258.  
  259. /* ...doarg(), cont'd */
  260.  
  261. case 'g':                /* get */
  262.     if (action) fatal("conflicting actions");
  263.     if (*(xp+1)) fatal("invalid argument bundling after -g");
  264.     *xargv++, xargc--;
  265.     if ((xargc == 0) || (**xargv == '-'))
  266.         fatal("missing filename for -g");
  267.     cmarg = *xargv;
  268.     action = 'r';
  269.     break;
  270.  
  271. case 'c':                /* connect before */
  272.     cflg = 1;
  273.     break;
  274.  
  275. case 'n':                /* connect after */
  276.     cnflg = 1;
  277.     break;
  278.  
  279. case 'h':                /* help */
  280.     usage();
  281.     return(-1);
  282.  
  283. case 'a':                /* "as" */
  284.     if (*(xp+1)) fatal("invalid argument bundling after -a");
  285.     *xargv++, xargc--;
  286.     if ((xargc < 1) || (**xargv == '-'))
  287.         fatal("missing name in -a");
  288.     cmarg2 = *xargv;
  289.     break;
  290.  
  291. case 'l':                /* set line */
  292.     if (*(xp+1)) fatal("invalid argument bundling after -l");
  293.     *xargv++, xargc--;
  294.     if ((xargc < 1) || (**xargv == '-'))
  295.         fatal("communication line device name missing");
  296.     strcpy(ttname,*xargv);
  297. /*  if (strcmp(ttname,dftty) == 0) local = dfloc; else local = 1;  */
  298.     local = (strcmp(ttname,CTTNAM) != 0); /* (better than old way) */
  299.     debug(F101,"local","",local);
  300.     ttopen(ttname,&local,0);
  301.     break;
  302.  
  303. case 'b':                       /* set baud */
  304.     if (*(xp+1)) fatal("invalid argument bundling");
  305.     *xargv++, xargc--;
  306.     if ((xargc < 1) || (**xargv == '-'))
  307.         fatal("missing baud");
  308.     z = atoi(*xargv);            /* Convert to number */
  309.     if (chkspd(z) > -1) speed = z;    /* Check it */
  310.         else fatal("unsupported baud rate");
  311.     break;
  312.  
  313. case 'i':                /* Treat files as binary */
  314.     binary = 1;
  315.     break;
  316.  
  317. /* cont'd... */
  318.  
  319. /* ...doarg(), cont'd */
  320.  
  321.  
  322. case 'w':                /* File warning */
  323.     warn = 1;
  324.     break;
  325.  
  326. case 'q':                /* Quiet */
  327.     quiet = 1;
  328.     break;
  329.  
  330. case 'd':                /* debug */
  331.     debopn("debug.log");
  332.     break;
  333.  
  334. case 'p':                /* set parity */
  335.     if (*(xp+1)) fatal("invalid argument bundling");
  336.     *xargv++, xargc--;
  337.     if ((xargc < 1) || (**xargv == '-'))
  338.         fatal("missing parity");
  339.     switch(x = **xargv) {
  340.     case 'e':
  341.     case 'o':
  342.     case 'm':
  343.     case 's': parity = x; break;
  344.     case 'n': parity = 0; break;
  345.     default:  fatal("invalid parity");
  346.         }
  347.     break;
  348.  
  349. case 't':
  350.     turn = 1;                /* Line turnaround handshake */
  351.     turnch = XON;            /* XON is turnaround character */
  352.     duplex = 1;                /* Half duplex */
  353.     flow = 0;                /* No flow control */
  354.     break;
  355.  
  356. default:
  357.     fatal("invalid argument, type 'kermit -h' for help");
  358.         }
  359.  
  360.     x = *++xp;                /* See if options are bundled */
  361.     }
  362.     return(0);
  363. }
  364.  
  365. /* Misc */
  366.  
  367. fatal(msg) char *msg; {            /* Fatal error message */
  368.     fprintf(stderr,"\r\nFatal: %s\n",msg);
  369.     tlog(F110,"Fatal:",msg,0l);
  370.     doexit(BAD_EXIT);            /* Exit indicating failure */
  371. }
  372.  
  373.  
  374. ermsg(msg) char *msg; {            /* Print error message */
  375.     if (!quiet) fprintf(stderr,"\r\n%s - %s\n",cmerrp,msg);
  376.     tlog(F110,"Error -",msg,0l);
  377. }
  378.  
  379. /* Interactive command parser */ 
  380.  
  381.  
  382. /* Top-Level Keyword Table */
  383.  
  384. struct keytab cmdtab[] = {
  385.     "!",       XXSHE, 0,
  386.     "%",           XXCOM, CM_INV,
  387.     "bye",         XXBYE, 0,
  388.     "c",           XXCON, CM_INV,
  389.     "close",       XXCLO, 0,
  390.     "connect",     XXCON, 0,
  391.     "cwd",       XXCWD, 0,
  392.     "dial",       XXDIAL, 0,
  393.     "directory",   XXDIR, 0,
  394.     "echo",        XXECH, 0,
  395.     "exit",       XXEXI, 0,
  396.     "finish",       XXFIN, 0,
  397.     "get",       XXGET, 0,
  398.     "help",       XXHLP, 0,
  399.     "log",         XXLOG, 0,
  400.     "quit",       XXQUI, 0,
  401.     "r",           XXREC, CM_INV,
  402.     "receive",       XXREC, 0,
  403.     "remote",       XXREM, 0,
  404.     "s",           XXSEN, CM_INV,
  405.     "script",       XXLOGI, 0,
  406.     "send",       XXSEN, 0,
  407.     "server",       XXSER, 0,
  408.     "set",       XXSET, 0,
  409.     "show",        XXSHO, 0,
  410.     "space",       XXSPA, 0,
  411.     "statistics",  XXSTA, 0,
  412.     "take",       XXTAK, 0
  413. };
  414. int ncmd = (sizeof(cmdtab) / sizeof(struct keytab));
  415.  
  416. /* Parameter keyword table */
  417.  
  418. struct keytab prmtab[] = {
  419.     "baud",            XYSPEE,  CM_INV,
  420.     "block-check",      XYCHKT,  0,
  421.     "delay",            XYDELA,  0,
  422.     "duplex",            XYDUPL,  0,
  423.     "end-of-packet",    XYEOL,   CM_INV,    /* moved to send/receive */
  424.     "escape-character", XYESC,   0,
  425.     "file",           XYFILE,  0,
  426.     "flow-control",     XYFLOW,  0,
  427.     "handshake",        XYHAND,  0,
  428.     "incomplete",       XYIFD,   0,
  429.     "line",             XYLINE,  0,
  430.     "modem-dialer",    XYMODM,     0,
  431.     "packet-length",    XYLEN,   CM_INV,    /* moved to send/receive */
  432.     "pad-character",    XYPADC,  CM_INV,    /* moved to send/receive */
  433.     "padding",          XYNPAD,  CM_INV,    /* moved to send/receive */
  434.     "parity",            XYPARI,  0,
  435.     "prompt",            XYPROM,  0,
  436.     "receive",          XYRECV,  0,
  437.     "send",             XYSEND,  0,
  438.     "speed",            XYSPEE,  0,
  439.     "start-of-packet",  XYMARK,  CM_INV,    /* moved to send/receive */
  440.     "timeout",            XYTIMO,  CM_INV     /* moved to send/receive */
  441. };
  442. int nprm = (sizeof(prmtab) / sizeof(struct keytab)); /* How many parameters */
  443.  
  444.  
  445. /* Remote Command Table */
  446.  
  447. struct keytab remcmd[] = {
  448.     "cwd",       XZCWD, 0,
  449.     "delete",    XZDEL, 0,
  450.     "directory", XZDIR, 0,
  451.     "help",      XZHLP, 0,
  452.     "host",      XZHOS, 0,
  453.     "space",     XZSPA, 0,
  454.     "type",      XZTYP, 0,
  455.     "who",       XZWHO, 0
  456. };
  457. int nrmt = (sizeof(remcmd) / sizeof(struct keytab));
  458.  
  459. struct keytab logtab[] = {
  460.     "debugging",    LOGD, 0,
  461.     "packets",        LOGP, 0,
  462.     "session",      LOGS, 0,
  463.     "transactions", LOGT, 0
  464. };
  465. int nlog = (sizeof(logtab) / sizeof(struct keytab));
  466.  
  467. /* Show command arguments */
  468.  
  469. #define SHPAR 0                /* Parameters */
  470. #define SHVER 1                /* Versions */
  471.  
  472. struct keytab shotab[] = {
  473.     "parameters", SHPAR, 0,
  474.     "versions",   SHVER, 0
  475. };
  476.  
  477. /*  C M D I N I  --  Initialize the interactive command parser  */
  478.  
  479. cmdini() {
  480.  
  481. #ifdef AMIGA
  482.     congm();
  483.     concb(escape);
  484. #endif 
  485.     printf("%s,%s\nType ? for help\n",versio,ckxsys);
  486.     cmsetp("C-Kermit>");        /* Set default prompt. */
  487.  
  488.     tlevel = -1;            /* Take file level */
  489.  
  490. /* Look for init file in home or current directory. */
  491.  
  492.     homdir = zhome();
  493.     lp = line;
  494.     lp[0] = '\0';
  495.     if (homdir) {
  496.     strcpy(lp,homdir);
  497.     if (lp[0] == '/') strcat(lp,"/");
  498.     }
  499.     strcat(lp,KERMRC);
  500. #ifdef AMIGA
  501.     reqoff();            /* disable requestors */
  502. #endif
  503.     if ((tfile[0] = fopen(line,"r")) != NULL) {
  504.     tlevel = 0;
  505.     debug(F110,"init file",line,0);
  506.     }
  507.     if (homdir && (tlevel < 0)) {
  508.         strcpy(lp,KERMRC);
  509.     if ((tfile[0] = fopen(line,"r")) != NULL) {
  510.         tlevel = 0;
  511.         debug(F110,"init file",line,0);
  512.     } else {
  513.         debug(F100,"no init file","",0);
  514.         }
  515.     }
  516. #ifdef AMIGA
  517.     reqpop();                /* restore requestors */
  518. #else
  519.     congm();                /* Get console tty modes */
  520. #endif
  521. }
  522.  
  523.  
  524. /*  T R A P  --  Terminal interrupt handler */
  525.  
  526. trap() {
  527.     debug(F100,"terminal interrupt...","",0);
  528.     doexit(GOOD_EXIT);            /* Exit indicating success */
  529. }
  530.  
  531. /*  P A R S E R  --  Top-level interactive command parser.  */
  532.  
  533. parser() {
  534.     int xx, cbn;
  535.     char *cbp;
  536. #ifdef AMIGA
  537.     reqres();            /* restore AmigaDOS requestors */
  538. #endif
  539.     concb(escape);        /* Put console in cbreak mode. */
  540.     conint(trap);        /* Turn on console terminal interrupts. */
  541. /*
  542.  sstate becomes nonzero when a command has been parsed that requires some
  543.  action from the protocol module.  Any non-protocol actions, such as local
  544.  directory listing or terminal emulation, are invoked directly from below.
  545. */
  546.     if (local) printf("\n");        /*** Temporary kludge ***/
  547.     sstate = 0;                /* Start with no start state. */
  548.     while (sstate == 0) {        /* Parse cmds until action requested */
  549.     while ((tlevel > -1) && feof(tfile[tlevel])) { /* If end of take */
  550.         fclose(tfile[tlevel]);    /* file, close it */
  551.         tlevel--;        /* and forget about it. */
  552.         cmini(ckxech);        /* and clear the cmd buffer. */
  553.      }
  554.     if (tlevel > -1) {        /* If in take file */
  555.         cbp = cmdbuf;        /* Get the next line. */
  556.         cbn = CMDBL;
  557.  
  558. /* Loop to get next command line and all continuation lines from take file. */
  559.  
  560. again:        if (fgets(line,cbn,tfile[tlevel]) == NULL) continue;
  561.  
  562.         lp = line;            /* Got one, copy it. */
  563.         while (*cbp++ = *lp++)
  564.             if (--cbn < 1) fatal("Command too long for internal buffer");
  565.         if (*(cbp - 3) == '\\') {    /* Continued on next line? */
  566.         cbp -= 3;        /* If so, back up pointer, */
  567.         goto again;        /* go back, get next line. */
  568.         }
  569.         stripq(cmdbuf);        /* Strip any quotes from cmd buffer. */
  570.  
  571.     } else {            /* No take file, get typein. */
  572.  
  573.         prompt();            /* Issue interactive prompt. */
  574.         cmini(ckxech);
  575.         }
  576.     repars = 1;
  577.     displa = 0;
  578.     while (repars) {
  579.         cmres();            /* Reset buffer pointers. */
  580.         xx = cmkey(cmdtab,ncmd,"Command","");
  581.         debug(F101,"top-level cmkey","",xx);
  582.  
  583.         switch (docmd(xx)) {
  584.         case -4:        /* EOF */
  585.             doexit(GOOD_EXIT);    /* ...exit successfully */
  586.             case -1:        /* Reparse needed */
  587.             repars = 1;
  588.             continue;
  589.             case -2:        /* Invalid command given */
  590.             if (backgrd)     /* if in background, terminate */
  591.             fatal("Kermit command error in background execution");
  592.             if (tlevel > -1) {    /* If in take file, quit */
  593.             ermsg("Kermit command error: take file terminated.");
  594.             fclose(tfile[tlevel]);
  595.             tlevel--;
  596.             }
  597.             cmini(ckxech);    /* (fall thru) */
  598.              case -3:        /* Empty command OK at top level */
  599.         default:        /* Anything else (fall thru) */
  600.             repars = 0;        /* No reparse, get new command. */
  601.             continue;
  602.             }
  603.         }
  604.     }
  605. /* Got an action command; disable terminal interrupts and return start state */
  606.  
  607.     if (!local) connoi();        /* Interrupts off only if remote */
  608.     return(sstate);
  609. }
  610.  
  611. /*  D O E X I T  --  Exit from the program.  */
  612.  
  613. doexit(exitstat) int exitstat; {
  614.     
  615.     ttclos();                /* Close external line, if any */
  616.     if (local) {
  617.     strcpy(ttname,dftty);        /* Restore default tty */
  618.     local = dfloc;            /* And default remote/local status */
  619.     }
  620.     if (!quiet) conres();        /* Restore console terminal. */
  621.     if (!quiet) connoi();        /* Turn off console interrupt traps. */
  622.  
  623.     if (deblog) {            /* Close any open logs. */
  624.     debug(F100,"Debug Log Closed","",0);
  625.     *debfil = '\0';
  626.     deblog = 0;
  627.     zclose(ZDFILE);
  628.     }
  629.     if (pktlog) {
  630.     *pktfil = '\0';
  631.     pktlog = 0;
  632.     zclose(ZPFILE);
  633.     }
  634.     if (seslog) {
  635.         *sesfil = '\0';
  636.     seslog = 0;
  637.     zclose(ZSFILE);
  638.     }
  639.     if (tralog) {
  640.     tlog(F100,"Transaction Log Closed","",0l);
  641.     *trafil = '\0';
  642.     tralog = 0;
  643.     zclose(ZTFILE);
  644.     }
  645.  
  646. #ifdef AMIGA
  647.     syscleanup();
  648. #endif
  649.     exit(exitstat);                /* Exit from the program. */
  650. }
  651.  
  652. /*  B L D L E N  --  Make length-encoded copy of string  */
  653.  
  654. char *
  655. bldlen(str,dest) char *str, *dest; {
  656.     int len;
  657.     len = strlen(str);
  658.     *dest = tochar(len);
  659.     strcpy(dest+1,str);
  660.     return(dest+len+1);
  661. }
  662.  
  663.  
  664. /*  S E T G E N  --  Construct a generic command  */
  665.  
  666. setgen(type,arg1,arg2,arg3) char type, *arg1, *arg2, *arg3; {
  667.     char *upstr, *cp;
  668.  
  669.     cp = cmdstr;
  670.     *cp++ = type;
  671.     *cp = NUL;
  672.     if (*arg1 != NUL) {
  673.     upstr = bldlen(arg1,cp);
  674.     if (*arg2 != NUL) {
  675.         upstr = bldlen(arg2,upstr);
  676.         if (*arg3 != NUL) bldlen(arg3,upstr);
  677.     }
  678.     }
  679.     cmarg = cmdstr;
  680.     debug(F110,"setgen",cmarg,0);
  681.  
  682.     return('g');
  683. }
  684.  
  685. /*  D O C M D  --  Do a command  */
  686.  
  687. /*
  688.  Returns:
  689.    -2: user typed an illegal command
  690.    -1: reparse needed
  691.     0: parse was successful (even tho command may have failed).
  692. */ 
  693.  
  694. docmd(cx) int cx; {
  695.     int x, y;
  696.     char *s;
  697.  
  698.     switch (cx) {
  699.  
  700. case -4:                /* EOF */
  701.     if (!quiet) printf("\r\n");
  702.     doexit(GOOD_EXIT);
  703. case -3:                /* Null command */
  704.     return(0);
  705. case -2:                /* Error */
  706. case -1:                /* Reparse needed */
  707.     return(cx);
  708.  
  709. case XXBYE:                /* bye */
  710.     if ((x = cmcfm()) < 0) return(x);
  711.     if (!local) {
  712.     printf("You have to 'set line' first\n");
  713.     return(0);
  714.     }
  715.     sstate = setgen('L',"","","");
  716.     return(0);
  717.  
  718. case XXCOM:                /* comment */
  719.     if ((x = cmtxt("Text of comment line","",&s)) < 0) return(x);
  720.     return(0);
  721.  
  722. case XXCON:                         /* connect */
  723.     if ((x = cmcfm()) < 0) return(x);
  724.     return(doconect());
  725.  
  726. case XXCWD:
  727. #ifdef AMIGA
  728.     if (cmtxt("Name of local directory, or carriage return","",&s) < 0)
  729.         return(-1);
  730.     /* if no name, just print directory name */
  731.     if (*s) {
  732.     if (chdir(s)) perror(s);
  733.     cwdf = 1;
  734.     }
  735.     if (getcwd(line, sizeof(line)) == NULL)
  736.     printf("Current directory name not available.\n");
  737.     else
  738.     printf("%s\n", line);
  739. #else
  740.     if (cmtxt("Name of local directory, or carriage return",homdir,&s) < 0)
  741.         return(-1);    
  742.     if (chdir(s)) perror(s);
  743.     cwdf = 1;
  744.     system(PWDCMD);
  745. #endif
  746.     return(0);
  747.  
  748. case XXCLO:
  749.     x = cmkey(logtab,nlog,"Which log to close","");
  750.     if (x == -3) {
  751.     printf("?You must tell which log\n");
  752.     return(-2);
  753.     }
  754.     if (x < 0) return(x);
  755.     if ((y = cmcfm()) < 0) return(y);
  756.     switch (x) {
  757.  
  758.     case LOGD:
  759.         if (deblog == 0) {
  760.         printf("?Debugging log wasn't open\n");
  761.         return(0);
  762.         }
  763.         *debfil = '\0';
  764.         deblog = 0;
  765.         return(zclose(ZDFILE));
  766.  
  767.     case LOGP:
  768.         if (pktlog == 0) {
  769.         printf("?Packet log wasn't open\n");
  770.         return(0);
  771.         }
  772.         *pktfil = '\0';
  773.         pktlog = 0;
  774.         return(zclose(ZPFILE));
  775.  
  776.     case LOGS:
  777.         if (seslog == 0) {
  778.         printf("?Session log wasn't open\n");
  779.         return(0);
  780.         }
  781.         *sesfil = '\0';
  782.         seslog = 0;
  783.         return(zclose(ZSFILE));
  784.  
  785.         case LOGT:
  786.         if (tralog == 0) {
  787.         printf("?Transaction log wasn't open\n");
  788.         return(0);
  789.         }
  790.         *trafil = '\0';
  791.         tralog = 0;
  792.         return(zclose(ZTFILE));
  793.  
  794.     default:
  795. #ifdef MINIX
  796.         printf("\n?Unexpected log designator - %D\n", x);
  797. #else
  798.         printf("\n?Unexpected log designator - %ld\n", x);
  799. #endif
  800.         return(0);
  801.     }
  802.  
  803. case XXDIAL:                /* dial number */
  804.     if ((x = cmtxt("Number to be dialed","",&s)) < 0) return(x);
  805.     return(dial(s));
  806.  
  807. case XXDIR:                /* directory */
  808. #ifdef AMIGA
  809.     if ((x = cmtxt("Directory/file specification","",&s)) < 0) return(x);
  810. #else
  811.     if ((x = cmtxt("Directory/file specification",".",&s)) < 0) return(x);
  812. #endif
  813.     lp = line;
  814.     sprintf(lp,"%s %s",DIRCMD,s);
  815.     system(line);
  816.     return(0);
  817.  
  818.  
  819. case XXECH:                 /* echo */
  820.     if ((x = cmtxt("Material to be echoed","",&s)) < 0) return(x);
  821.     for ( ; *s; s++) {
  822.     if ((x = *s) == 0134) {        /* Convert octal escapes */
  823.         s++;            /* up to 3 digits */
  824.         for (x = y = 0; *s >= '0' && *s <= '7' && y < 3; s++,y++) {
  825.             x = x * 8 + (int) *s - 48;
  826.         }
  827.         s--;
  828.         }
  829.     putchar(x);
  830.     }
  831.     printf("\n");
  832.     return(0);
  833.  
  834. case XXQUI:                /* quit, exit */
  835. case XXEXI:
  836.     if ((x = cmcfm()) > -1) doexit(GOOD_EXIT);
  837.     else return(x);
  838.  
  839. case XXFIN:                /* finish */
  840.     if ((x = cmcfm()) < 0) return(x);
  841.     if (!local) {
  842.     printf("You have to 'set line' first\n");
  843.     return(0);
  844.     }
  845.     sstate = setgen('F',"","","");
  846.     return(0);
  847.  
  848. case XXGET:                /* get */
  849.     if (!local) {
  850.     printf("\nYou have to 'set line' first\n");
  851.     return(0);
  852.     }
  853.     x = cmtxt("Name of remote file(s), or carriage return","",&cmarg);
  854.     if ((x == -2) || (x == -1)) return(x);
  855.  
  856. /* If foreign file name omitted, get foreign and local names separately */
  857.  
  858.     if (*cmarg == NUL) {
  859.  
  860.     if (tlevel > -1) {        /* Input is from take file */
  861.  
  862.         if (fgets(line,100,tfile[tlevel]) == NULL)
  863.             fatal("take file ends prematurely in 'get'");
  864.         stripq(line);
  865.         for (x = strlen(line);
  866.             x > 0 && (line[x-1] == '\n' || line[x-1] == '\r');
  867.         x--)
  868.         line[x-1] = '\0';
  869.         cmarg = line;
  870.         if (fgets(cmdbuf,CMDBL,tfile[tlevel]) == NULL)
  871.             fatal("take file ends prematurely in 'get'");
  872.         stripq(cmdbuf);
  873.         if (*cmdbuf == NUL) cmarg2 = line; else cmarg2 = cmdbuf;
  874.  
  875.         } else {            /* Input is from terminal */
  876.  
  877.         char psave[40];        /* Save old prompt */
  878.         cmsavp(psave,40);
  879.         cmsetp(" Remote file specification: "); /* Make new one */
  880.         cmini(ckxech);
  881.         x = -1;
  882.         prompt();
  883.         while (x == -1) {        /* Prompt till they answer */
  884.             x = cmtxt("Name of remote file(s)","",&cmarg);
  885.         debug(F111," cmtxt",cmarg,x);
  886.         }
  887.         if (x < 0) {
  888.         cmsetp(psave);
  889.         return(x);
  890.         }
  891.         if (*cmarg == NUL) {     /* If user types a bare CR, */
  892.         printf("(cancelled)\n"); /* Forget about this. */
  893.             cmsetp(psave);        /* Restore old prompt, */
  894.         return(0);        /* and return. */
  895.         }
  896.         strcpy(line,cmarg);        /* Make a safe copy */
  897.         cmarg = line;
  898.         cmsetp(" Local name to store it under: ");    /* New prompt */
  899.         cmini(ckxech);
  900.         x = -1;
  901.         prompt();            /* Prompt */
  902.         while (x == -1) {        /* Again, parse till answered */
  903.             x = cmofi("Local file name","",&cmarg2);
  904.         }
  905.         cmsetp(psave);        /* Restore old prompt. */
  906.         if (x == -3) {                    /* If bare CR, */
  907.         printf("(cancelled)\n");    /* escape from this... */
  908.         return(0);                /* and return. */
  909.         } else if (x < 0) return(x);        /* Handle parse errors. */
  910.         if ((x = cmcfm()) < 0) return(-2);    /* Get confirmation. */
  911.         }
  912.     }
  913.     sstate = 'r';            /* All ok, set start state. */
  914.     if (local) displa = 1;
  915.     return(0);
  916.  
  917. case XXHLP:                /* Help */
  918.     x = cmkey(cmdtab,ncmd,"C-Kermit command","help");
  919.     return(dohlp(x));
  920.  
  921. case XXLOG:                /* Log */
  922.     x = cmkey(logtab,nlog,"What to log","");
  923.     if (x == -3) {
  924.     printf("?You must specify what is to be logged\n");
  925.     return(-2);
  926.     }
  927.     if (x < 0) return(x);
  928.     return(dolog(x));
  929.  
  930. case XXLOGI:                /* Send script remote system */
  931.     if ((x = cmtxt("Text of login script","",&s)) < 0) return(x);
  932.     return( login(s) );            /* Return 0=completed, -2=failed */
  933.  
  934. case XXREC:                /* Receive */
  935.     cmarg2 = "";
  936.     x = cmofi("Name under which to store the file, or CR","",&cmarg2);
  937.     if ((x == -1) || (x == -2)) return(x);
  938.     debug(F111,"cmofi cmarg2",cmarg2,x);
  939.     if ((x = cmcfm()) < 0) return(x);
  940.     sstate = 'v';
  941.     if (local) displa = 1;
  942.     return(0);
  943.  
  944. case XXREM:                /* Remote */
  945.     if (!local) {
  946.     printf("\nYou have to 'set line' first\n");
  947.     return(-2);
  948.     }
  949.     x = cmkey(remcmd,nrmt,"Remote Kermit server command","");
  950.     if (x == -3) {
  951.     printf("?You must specify a command for the remote server\n");
  952.     return(-2);
  953.     }
  954.     return(dormt(x));
  955.  
  956. case XXSEN:                /* Send */
  957.     cmarg = cmarg2 = "";
  958.     if ((x = cmifi("File(s) to send","",&s,&y)) < 0) {
  959.     if (x == -3) {
  960.         printf("?A file specification is required\n");
  961.         return(-2);
  962.     }
  963.     return(x);
  964.     }
  965.     nfils = -1;                /* Files come from internal list. */
  966.     strcpy(line,s);            /* Save copy of string just parsed. */
  967.     debug(F101,"Send: wild","",y);
  968.     *cmarg2 = '\0';            /* Initialize send-as name */
  969.     if (y == 0) {
  970.     if ((x = cmtxt("Name to send it with","",&cmarg2)) < 0) return(x);
  971.     } else {
  972.     if ((x = cmcfm()) < 0) return(x);
  973.     }
  974.     cmarg = line;            /* File to send */
  975.     debug(F110,"Sending:",cmarg,0);
  976.     if (*cmarg2 != '\0') debug(F110," as:",cmarg2,0);
  977.     sstate = 's';            /* Set start state */
  978.     if (local) displa = 1;
  979.     return(0);
  980.  
  981. case XXSER:                /* Server */
  982.     if ((x = cmcfm()) < 0) return(x);
  983.     sstate = 'x';
  984.     if (local) displa = 1;
  985. #ifdef AMIGA
  986.     reqoff();                /* no DOS requestors while server */
  987. #endif
  988.     return(0);
  989.  
  990. case XXSET:                /* Set */
  991.     x = cmkey(prmtab,nprm,"Parameter","");
  992.     if (x == -3) {
  993.     printf("?You must specify a parameter to set\n");
  994.     return(-2);
  995.     }
  996.     if (x < 0) return(x);
  997.     return(doprm(x));
  998.     
  999. /* XXSHE code by H. Fischer; copyright rights assigned to Columbia Univ */
  1000. /*
  1001.  Adapted to use getpwuid to find login shell because many systems do not
  1002.  have SHELL in environment, and to use direct calling of shell rather
  1003.  than intermediate system() call. -- H. Fischer
  1004. */
  1005. case XXSHE:                /* Local shell command */
  1006.     {
  1007.     int pid;
  1008. #ifdef AMIGA
  1009.     if (cmtxt("Command to execute","",&s) < 0) return(-1);
  1010. #else
  1011.     if (cmtxt("Unix shell command to execute","",&s) < 0) return(-1);
  1012. #endif
  1013.     conres();                /* Make console normal  */
  1014. #ifdef AMIGA
  1015.     system(s);
  1016. #else
  1017. #ifdef MSDOS
  1018.     zxcmd(s);
  1019. #else
  1020. #ifdef vax11c
  1021.  
  1022.     system(s);                /* Best we can do for VMS? */
  1023.  
  1024. #else                    /* All Unix systems... */
  1025.  
  1026.     if ((pid = fork()) == 0) {        /* Make child */
  1027.     char *shpath, *shname, *shptr;    /* For finding desired shell */
  1028.     struct passwd *p;
  1029.     extern struct passwd * getpwuid();
  1030.     extern int getuid();
  1031.     char *defShel = "/bin/sh";    /* Default */
  1032.  
  1033.     p = getpwuid( getuid() );    /* Get login data */
  1034.     if ( p == (struct passwd *) NULL || !*(p->pw_shell) )
  1035.         shpath = defShel;
  1036.     else
  1037.         shpath = p->pw_shell;
  1038.     shptr = shname = shpath;
  1039.     while (*shptr != '\0')
  1040.         if (*shptr++ == '/') shname = shptr;
  1041.     if (*s == NUL)            /* Interactive shell requested? */
  1042.         execl(shpath,shname,"-i",NULL);    /* Yes, do that */
  1043.     else                /* Otherwise, */
  1044.         execl(shpath,shname,"-c",s,NULL); /* exec the given command */
  1045.     exit(GOOD_EXIT); }        /* Just punt if it didnt work */
  1046.  
  1047.     else {                /* Parent */
  1048.  
  1049.         int wstat;            /* Kermit must wait for child */
  1050.     int (*istat)(), (*qstat)();
  1051.  
  1052.     istat = signal(SIGINT,SIG_IGN);    /* Let the fork handle keyboard */
  1053.     qstat = signal(SIGQUIT,SIG_IGN); /* interrupts itself... */
  1054.  
  1055.         while (((wstat = wait(0)) != pid) && (wstat != -1)) /* Wait for fork */
  1056.         ;
  1057.     signal(SIGINT,istat);        /* Restore interrupts */
  1058.     signal(SIGQUIT,qstat);
  1059.     }
  1060. #endif
  1061. #endif
  1062. #endif
  1063.     concb(escape);            /* Console back in cbreak mode */
  1064.     return(0);
  1065. }
  1066.  
  1067. case XXSHO:                /* Show */
  1068.     x = cmkey(shotab,2,"","parameters");
  1069.     if (x < 0) return(x);
  1070.     if (y = (cmcfm()) < 0) return(y);
  1071.     switch (x) {
  1072.  
  1073.     case SHPAR:
  1074.         shopar();
  1075.         break;
  1076.  
  1077.     case SHVER:
  1078.         printf("\nVersions:\n %s\n %s\n",versio,protv);
  1079.         printf(" %s\n",fnsv);
  1080.         printf(" %s\n %s\n",cmdv,userv);
  1081.         printf(" %s for%s\n",ckxv,ckxsys);
  1082.         printf(" %s for%s\n",ckzv,ckzsys);
  1083.         printf(" %s\n",connv);
  1084.         printf(" %s\n %s\n\n",dialv,loginv);
  1085.         break;
  1086.  
  1087.     default:
  1088.         printf("\nNothing to show...\n");
  1089.         break;
  1090.     }
  1091.     return(0);
  1092.  
  1093. case XXSPA:                /* space */
  1094.     if ((x = cmcfm()) < 0) return(x);
  1095.     system(SPACMD);
  1096.     return(0);
  1097.  
  1098. case XXSTA:                /* statistics */
  1099.     if ((x = cmcfm()) < 0) return(x);
  1100.     printf("\nMost recent transaction --\n");
  1101. #ifdef MINIX
  1102.     printf(" files: %D\n",filcnt);
  1103.     printf(" total file characters  : %D\n",tfc);
  1104.     printf(" communication line in  : %D\n",tlci);
  1105.     printf(" communication line out : %D\n",tlco);
  1106. #else
  1107.     printf(" files: %ld\n",filcnt);
  1108.     printf(" total file characters  : %ld\n",tfc);
  1109.     printf(" communication line in  : %ld\n",tlci);
  1110.     printf(" communication line out : %ld\n",tlco);
  1111. #endif
  1112.     printf(" elapsed time           : %d sec\n",tsecs);
  1113.     if (filcnt > 0) {
  1114.     if (tsecs > 0) {
  1115.         long lx;
  1116.         lx = (tfc / tsecs) * 10L;
  1117. #ifdef MINIX
  1118.         printf(" effective baud rate    : %D\n",lx);
  1119.         if (speed > 0) {
  1120.         lx = (lx * 100L) / (long)speed;
  1121.         printf(" efficiency             : %D %%\n",lx);
  1122. #else
  1123.         printf(" effective baud rate    : %ld\n",lx);
  1124.         if (speed > 0) {
  1125.         lx = (lx * 100L) / (long)speed;
  1126.         printf(" efficiency             : %ld %%\n",lx);
  1127. #endif
  1128.         }
  1129.     }
  1130.     printf(" block check type used  : %d\n",bctu);
  1131.     printf(" compression            : ");
  1132.     if (rptflg) printf("yes [%c]\n",rptq); else printf("no\n");
  1133.     printf(" 8th bit prefixing      : ");
  1134.     if (ebqflg) printf("yes [%c]\n",ebq); else printf("no\n\n");
  1135.     } else printf("\n");
  1136.     return(0);
  1137.  
  1138. case XXTAK:                /* take */
  1139.     if (tlevel > MAXTAKE-1) {
  1140.     printf("?Take files nested too deeply\n");
  1141.     return(-2);
  1142.     }
  1143.     if ((y = cmifi("C-Kermit command file","",&s,&x)) < 0) { 
  1144.     if (y == -3) {
  1145.         printf("?A file specification is required\n");
  1146.         return(-2);
  1147.     } else return(y);
  1148.     }
  1149.     if (x != 0) {
  1150.     printf("?Wildcards not allowed in command file name\n");
  1151.     return(-2);
  1152.     }
  1153.     strcpy(line,s);            /* Make a safe copy of the string */
  1154.     if ((y = cmcfm()) < 0) return(y);
  1155.     if ((tfile[++tlevel] = fopen(line,"r")) == NULL) {
  1156.     perror(line);
  1157.     debug(F110,"Failure to open",line,0);
  1158.     tlevel--;
  1159.     }
  1160.     return(0);
  1161.  
  1162. default:
  1163.     printf("Not available - %s\n",cmdbuf);
  1164.     return(-2);
  1165.     }
  1166. }
  1167.  
  1168. /*  S H O P A R  --  Show Parameters  */
  1169.  
  1170. shopar() {
  1171.  
  1172.     int i;
  1173.     extern struct keytab mdmtab[]; extern int nmdm;
  1174.  
  1175.     puts("\nCommunications Parameters:");
  1176.     printf(" Line: %s, speed: %d, mode: ",ttname,speed);
  1177.     if (local) printf("local"); else printf("remote");
  1178.  
  1179.     for (i = 0; i < nmdm; i++) {
  1180.     if (mdmtab[i].val == mdmtyp) {
  1181.         printf(", modem-dialer: %s",mdmtab[i].kwd);
  1182.         break;
  1183.     }
  1184.     }
  1185.     printf("\n Parity: ");
  1186.     switch (parity) {
  1187.     case 'e': printf("even");  break;
  1188.     case 'o': printf("odd");   break;
  1189.     case 'm': printf("mark");  break;
  1190.     case 's': printf("space"); break;
  1191.     case 0:   printf("none");  break;
  1192.     default:  printf("invalid - %d",parity); break;
  1193.     }        
  1194.     printf(", duplex: ");
  1195.     if (duplex) printf("half, "); else printf("full, ");
  1196.     printf("flow: ");
  1197.     if (flow == 1) printf("xon/xoff");
  1198.     else if (flow == 0) printf("none");
  1199.     else printf("%d",flow);
  1200.     printf(", handshake: ");
  1201.     if (turn) printf("%d\n",turnch); else printf("none\n");
  1202.  
  1203.     printf("\nProtocol Parameters:   Send    Receive");
  1204.     if (timef || spsizf) printf("    (* = override)");
  1205.     printf("\n Timeout:      %11d%9d", rtimo,  timint);
  1206.     if (timef) printf("*");
  1207.     printf("\n Padding:      %11d%9d\n", npad,   mypadn);
  1208.     printf(  " Pad Character:%11d%9d\n", padch,  mypadc);
  1209.     printf(  " Packet Start: %11d%9d\n", mystch, stchr);
  1210.     printf(  " Packet End:   %11d%9d\n", seol,   eol);
  1211.     printf(  " Packet Length:%11d", spsiz);
  1212.     printf( spsizf ? "*" : " " ); printf("%8d\n", rpsiz);
  1213.  
  1214.     printf("\nBlock Check Type: %d, Delay: %d\n",bctr,delay);
  1215.     if (ebqflg) printf("8th-Bit Prefix:      '%c'\n",ebq);
  1216.     if (rptflg) printf("Repeat-Count Prefix: '%c'\n",rptq);
  1217.  
  1218.     printf("\nFile parameters:\n File Names:   ");
  1219.     if (fncnv) printf("%-12s","converted"); else printf("%-12s","literal");
  1220. #ifdef DEBUG
  1221.     printf("   Debugging Log:    ");
  1222.     if (deblog) printf("%s",debfil); else printf("none");
  1223. #endif
  1224.     printf("\n File Type:    ");
  1225.     if (binary) printf("%-12s","binary"); else printf("%-12s","text");
  1226.     printf("   Packet Log:       ");
  1227.     if (pktlog) printf(pktfil); else printf("none");
  1228.     printf("\n File Warning: ");
  1229.     if (warn) printf("%-12s","on"); else printf("%-12s","off");
  1230.     printf("   Session Log:      ");
  1231.     if (seslog) printf(sesfil); else printf("none");
  1232.     printf("\n File Display: ");
  1233.     if (quiet) printf("%-12s","off"); else printf("%-12s","on");
  1234. #ifdef TLOG
  1235.     printf("   Transaction Log:  ");
  1236.     if (tralog) printf(trafil); else printf("none");
  1237. #endif
  1238.     printf("\n\nIncomplete File Disposition: ");
  1239.     if (keep) printf("keep"); else printf("discard");
  1240. #ifdef KERMRC    
  1241.     printf(", Init file: %s",KERMRC);
  1242. #endif
  1243.     puts("\n");
  1244. }
  1245.  
  1246. /*  D O C O N E C T  --  Do the connect command  */
  1247.  
  1248. /*  Note, we don't call this directly from dial, because we need to give */
  1249. /*  the user a chance to change parameters (e.g. parity) after the */
  1250. /*  connection is made. */
  1251.  
  1252. doconect() {
  1253.     int x;
  1254.     conres();                /* Put console back to normal */
  1255.     x = conect();            /* Connect */
  1256.     concb(escape);            /* Put console into cbreak mode, */
  1257.     return(x);                /* for more command parsing. */
  1258. }
  1259.  
  1260.  
  1261. /*  D O L O G  --  Do the log command  */
  1262.  
  1263. dolog(x) int x; {
  1264.     int y; char *s;
  1265.  
  1266.     switch (x) {
  1267.  
  1268.     case LOGD:
  1269. #ifdef DEBUG
  1270.         y = cmofi("Name of debugging log file","debug.log",&s);
  1271. #else
  1272.             y = -2; s = "";
  1273.         printf("%s","- Sorry, debug log not available\n");
  1274. #endif
  1275.         break;
  1276.  
  1277.     case LOGP:
  1278.         y = cmofi("Name of packet log file","packet.log",&s);
  1279.         break;
  1280.  
  1281.     case LOGS:
  1282.         y = cmofi("Name of session log file","session.log",&s);
  1283.         break;
  1284.  
  1285.     case LOGT:
  1286. #ifdef TLOG
  1287.         y = cmofi("Name of transaction log file","transact.log",&s);
  1288. #else
  1289.             y = -2; s = "";
  1290.         printf("%s","- Sorry, transaction log not available\n");
  1291. #endif
  1292.         break;
  1293.  
  1294.     default:
  1295.         printf("\n?Unexpected log designator - %d\n",x);
  1296.         return(-2);
  1297.     }
  1298.     if (y < 0) return(y);
  1299.  
  1300.     strcpy(line,s);
  1301.     s = line;
  1302.     if ((y = cmcfm()) < 0) return(y);
  1303.  
  1304. /* cont'd... */
  1305.  
  1306. /* ...dolog, cont'd */
  1307.  
  1308.  
  1309.     switch (x) {
  1310.  
  1311.     case LOGD:
  1312.         return(deblog = debopn(s));
  1313.  
  1314.     case LOGP:
  1315.         zclose(ZPFILE);
  1316.         y = zopeno(ZPFILE,s);
  1317.         if (y > 0) strcpy(pktfil,s); else *pktfil = '\0';
  1318.         return(pktlog = y);
  1319.  
  1320.     case LOGS:
  1321.         zclose(ZSFILE);
  1322.         y = zopeno(ZSFILE,s);
  1323.         if (y > 0) strcpy(sesfil,s); else *sesfil = '\0';
  1324.         return(seslog = y);
  1325.  
  1326.     case LOGT:
  1327.         zclose(ZTFILE);
  1328.         tralog = zopeno(ZTFILE,s);
  1329.         if (tralog > 0) {
  1330.         strcpy(trafil,s);
  1331.         tlog(F110,"Transaction Log:",versio,0l);
  1332.         tlog(F100,ckxsys,"",0);
  1333.         ztime(&s);
  1334.         tlog(F100,s,"",0l);
  1335.             }
  1336.         else *trafil = '\0';
  1337.         return(tralog);
  1338.  
  1339.     default:
  1340.         return(-2);
  1341.     }
  1342. }
  1343.  
  1344.  
  1345. /*  D E B O P N  --  Open a debugging file  */
  1346.  
  1347. debopn(s) char *s; {
  1348. #ifdef DEBUG
  1349.     char *tp;
  1350.     zclose(ZDFILE);
  1351.     deblog = zopeno(ZDFILE,s);
  1352.     if (deblog > 0) {
  1353.     strcpy(debfil,s);
  1354.     debug(F110,"Debug Log ",versio,0);
  1355.     debug(F100,ckxsys,"",0);
  1356.     ztime(&tp);
  1357.     debug(F100,tp,"",0);
  1358.     } else *debfil = '\0';
  1359.     return(deblog);
  1360. #else
  1361.     return(0);
  1362. #endif
  1363. }
  1364.