home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / communic / kermit / ckuusr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1984-01-01  |  42.8 KB  |  1,338 lines

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