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

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