home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / ckv201.zip / ckuusy.c < prev    next >
C/C++ Source or Header  |  2002-02-01  |  114KB  |  3,961 lines

  1. #include "ckcsym.h"
  2. #define XFATAL fatal
  3.  
  4. /*  C K U U S Y --  "User Interface" for Unix Kermit, part Y  */
  5.  
  6. /*  Command-Line Argument Parser */
  7.  
  8. /*
  9.   Author: Frank da Cruz <fdc@columbia.edu>
  10.   Columbia University, New York City.
  11.  
  12.   Copyright (C) 1985, 2002,
  13.     Trustees of Columbia University in the City of New York.
  14.     All rights reserved.  See the C-Kermit COPYING.TXT file or the
  15.     copyright text in the ckcmai.c module for disclaimer and permissions.
  16. */
  17. #include "ckcdeb.h"
  18.  
  19. char * bannerfile = NULL;
  20. char * helpfile = NULL;
  21. extern int xferlog, filepeek, nolinks;
  22. extern char * xferfile;
  23.  
  24. #include "ckcasc.h"
  25. #include "ckcker.h"
  26. #include "ckucmd.h"
  27. #include "ckcnet.h"
  28. #include "ckuusr.h"
  29. #include "ckcxla.h"
  30. #ifdef CK_SSL
  31. #include "ck_ssl.h"
  32. #endif /* CK_SSL */
  33. #include <signal.h>
  34.  
  35. #ifdef OS2
  36. #include <io.h>
  37. #ifdef KUI
  38. #include "ikui.h"
  39. extern struct _kui_init kui_init;
  40. #endif /* KUI */
  41. #endif /* OS2 */
  42.  
  43. extern int inserver, fncnv, f_save, xfermode;
  44. #ifdef PATTERNS
  45. extern int patterns;
  46. #endif /* PATTERNS */
  47.  
  48. #ifndef NOICP
  49. extern int cmdint;
  50. #endif /* NOICP */
  51. extern int suspend;
  52.  
  53. #ifdef NETCONN
  54. #ifdef ANYX25
  55. extern int revcall, closgr, cudata;
  56. extern char udata[];
  57. extern int x25fd;
  58. #endif /* ANYX25 */
  59. #ifndef VMS
  60. #ifndef OS2
  61. #ifndef OSK
  62. extern
  63. #endif /* OSK */
  64. #endif /* OS2 */
  65. #endif /* VMS */
  66.  
  67. int telnetfd;
  68. extern struct keytab netcmd[];
  69. extern int tn_exit;
  70. #ifndef NOICP
  71. #ifndef NODIAL
  72. extern int nnets, nnetdir;              /* Network services directory */
  73. extern char *netdir[];
  74. extern char *nh_p[];                    /* Network directory entry pointers */
  75. extern char *nh_p2[];                   /* Network directory entry nettype */
  76. extern char *nh_px[4][MAXDNUMS + 1];
  77. #endif /* NODIAL */
  78. extern int nhcount;
  79. extern char * n_name;                   /* Network name pointer */
  80. #endif /* NOICP */
  81. #endif /* NETCONN */
  82.  
  83. #ifndef NOSPL
  84. extern int nmac;
  85. extern struct mtab *mactab;
  86. #endif /* NOSPL */
  87. extern char uidbuf[];
  88.  
  89. #ifdef CK_LOGIN
  90. extern int logintimo;
  91. #endif /* CK_LOGIN */
  92.  
  93. extern char * myname, * dftty;
  94. extern int howcalled;
  95.  
  96. extern char *ckxsys, *ckzsys, **xargv, *xarg0, **cmlist, *clcmds;
  97.  
  98. extern int action, cflg, xargc, cnflg, local, quiet, escape, network, mdmtyp,
  99.   bgset, backgrd, xargs, binary, parity, turn, turnch, duplex, flow, clfils,
  100.   noinit, stayflg, nettype, cfilef, noherald, cmask, cmdmsk, exitonclose,
  101.   haveline, justone, cxtype, xfinish, ttnproto;
  102.  
  103. extern long speed;
  104. extern char ttname[];
  105. extern char * pipedata, * cmdfil;
  106.  
  107. #ifndef NOXFER
  108. extern char *cmarg, *cmarg2;
  109.  
  110. extern int nfils, stdouf, stdinf, displa, maxrps, rpsiz, ckwarn, urpsiz,
  111.   wslotr, swcapr, ckdelay, recursive, reliable, xreliable, fnspath, fncact,
  112.   clearrq, setreliable;
  113.  
  114. #ifdef PIPESEND
  115. extern int usepipes, pipesend;
  116. #endif /* PIPESEND */
  117. extern int protocol;
  118. #endif /* NOXFER */
  119.  
  120. #ifdef OS2
  121. extern struct keytab os2devtab[];
  122. extern int nos2dev;
  123. extern int ttslip;
  124. #ifdef OS2PM
  125. extern int os2pm;
  126. #endif /* OS2PM */
  127. #endif /* OS2 */
  128.  
  129. #ifdef CK_NETBIOS
  130. extern unsigned char NetBiosAdapter;
  131. #endif /* CK_NETBIOS */
  132.  
  133. #ifdef XFATAL
  134. #undef XFATAL
  135. #endif /* XFATAL */
  136.  
  137. #ifdef TNCODE
  138. _PROTOTYP(static int dotnarg, (char x) );
  139. #endif /* TNCODE */
  140.  
  141. int haveftpuid = 0;            /* Have FTP user ID */
  142. static int have_cx = 0;            /* Have connection */
  143.  
  144. #ifdef NEWFTP
  145. extern char * ftp_host;
  146. #endif /* NEWFTP */
  147.  
  148. extern int what;
  149.  
  150. #ifndef NOICP
  151. #ifndef NODIAL
  152. extern int nmdm, telephony;
  153. extern struct keytab mdmtab[];
  154. extern int usermdm, dialudt;
  155. #endif /* NODIAL */
  156. _PROTOTYP(static int pmsg, (char *) );
  157. _PROTOTYP(static int fmsg, (char *) );
  158. static int pmsg(s) char *s; { printf("%s\n", s); return(0); }
  159. static int fmsg(s) char *s; { fatal(s); return(0); }
  160. #define XFATAL(s) return(what==W_COMMAND?pmsg(s):fmsg(s))
  161. #else
  162. #define XFATAL fatal
  163. #endif /* NOICP */
  164.  
  165. #ifndef NOHTTP
  166. #define HTTP_GET 1
  167. #define HTTP_PUT 2
  168. #define HTTP_HED 3
  169. #endif /* NOHTTP */
  170.  
  171. #ifdef CK_URL
  172. /* URLs we recognize */
  173.  
  174. #define URL_FTP    1
  175. #define URL_HTTP   2
  176. #define URL_HTTPS  3
  177. #define URL_IKSD   4
  178. #define URL_TELNET 5
  179. #define URL_LOGIN  6
  180.  
  181. struct keytab urltab[] = {
  182. #ifdef NEWFTP
  183.     "ftp",    URL_FTP,    0,
  184. #endif /* NEWFTP */
  185. #ifndef NOHTTP
  186.     "http",   URL_HTTP,   0,
  187.     "https",  URL_HTTPS,  0,
  188. #endif /* NOHTTP */
  189.     "iksd",   URL_IKSD,   0,
  190.     "telnet", URL_TELNET, 0,
  191.     "", 0, 0
  192. };
  193. int nurltab = sizeof(urltab)/sizeof(struct keytab) - 1;
  194.  
  195. #ifndef URLBUFLEN
  196. #define URLBUFLEN 1024
  197. #endif /* URLBUFLEN */
  198. static char urlbuf[URLBUFLEN];
  199. struct urldata g_url = {NULL,NULL,NULL,NULL,NULL,NULL,NULL};
  200.  
  201. /* u r l p a r s e  --  Parse a possible URL */
  202.  
  203. /*
  204.   Returns 0 if the candidate does not seem to be a URL.
  205.   Returns 1 if it might be a URL, with the above pointers set to its pieces:
  206.     service : [ // ] [ user [ : password ] @ ] host [ : service ] [ / path ]
  207.  
  208.   Example: ftp://ds.internic.net:21/rfc/rfc1234.txt
  209.     url.svc = [ftp]
  210.     url.usr = [(NULL)]
  211.     url.psw = [(NULL)]
  212.     url.hos = [ds.internic.net]
  213.     url.por = [21]
  214.     url.pth = [rfc/rfc1234.txt]
  215.  
  216.   It might be a URL if it contains a possible service name followed by a
  217.   a colon (:).  Thus "telnet:xyzcorp.com" is a minimal URL, whereas a
  218.   full-blown example would be:
  219.  
  220.     ftp://olga:secret@ftp.xyzcorp.com/public/oofa.txt
  221.  
  222.   The caller must verify the results, i.e. that the service string is a real
  223.   TCP service, etc.  This routine just parses the fields.
  224.  
  225.   struct urldata defined in ckcker.h
  226. */
  227.  
  228. int
  229. urlparse(s,url) char *s; struct urldata * url; {
  230.     char * p = NULL, * urlbuf = NULL;
  231.     int x;
  232.  
  233.     if (!s || !url)
  234.         return(0);
  235.  
  236.     if (!*s)
  237.         return(0);
  238.  
  239.     makestr(&urlbuf,s);
  240.  
  241.     if (url->sav) {            /* In case we were called before... */
  242.         free(url->sav);
  243.         url->sav = NULL;
  244.     }
  245.     if (url->svc) {
  246.         free(url->svc);
  247.         url->svc = NULL;
  248.     }
  249.     if (url->hos) {
  250.         free(url->svc);
  251.         url->hos = NULL;
  252.     }
  253.     if (url->por) {
  254.         free(url->por);
  255.         url->por = NULL;
  256.     }
  257.     if (url->usr) {
  258.         free(url->usr);
  259.         url->usr = NULL;
  260.     }
  261.     if (url->psw) {
  262.         free(url->psw);
  263.         url->psw = NULL;
  264.     }
  265.     if (url->pth) {
  266.         free(url->pth);
  267.         url->pth = NULL;
  268.     }
  269.     p = urlbuf;                /* Was a service requested? */
  270.     while (*p && *p != ':')        /* Look for colon */
  271.       p++;
  272.     if (*p == ':') {                    /* Have a colon */
  273.         *p++ = NUL;            /* Get service name or number */
  274.         if (*p == ':')            /* a second colon */
  275.           *p++ = NUL;            /* get rid of that one too */
  276.         while (*p == '/') *p++ = NUL;    /* and slashes */
  277. #ifdef COMMENT
  278.         /* Trailing slash is part of path - leave it - jaltman */
  279.         x = strlen(p);                  /* Length of remainder */
  280.         if (p[x-1] == '/')              /* If there is a trailing slash */
  281.           p[x-1] = NUL;            /* remove it. */
  282. #endif /* COMMENT */
  283.         if (urlbuf[0]) {        /* Anything left? */
  284.             char *q = p, *r = p, *w = p;
  285.         makestr(&url->svc,urlbuf);
  286.  
  287.             while (*p != NUL && *p != '@') /* look for @ */
  288.           p++;
  289.             if (*p == '@') {        /* Signifies user ID, maybe password */
  290.                 *p++ = NUL;
  291.         url->hos = p;
  292.                 while (*w != NUL && *w != ':')
  293.                   w++;
  294.                 if (*w == ':')
  295.                   *w++ = NUL;
  296.         url->usr = r;        /* Username */
  297.         url->psw = w;        /* Password */
  298.                 q = p;
  299.             } else {            /* No username or password */
  300.                 p = q;
  301.         url->hos = p;
  302.             }
  303.             while (*p != NUL && *p != ':' && *p != '/')    /* Port? */
  304.               p++;
  305.             if (*p == ':') {        /* TCP port */
  306.                 *p++ = NUL;
  307.                 r = p;
  308.         url->por = r;
  309.                 while (*p != NUL && *p != '/')
  310.           p++;
  311.                 /* '/' is part of path, leave it until we can copy */
  312.                 if (*p == '/') {
  313.             makestr(&url->pth,p);  /* Path */
  314.             *p = NUL;
  315.                 }
  316.             } else {            /* No port */
  317.                 /* '/' is part of path, leave it */
  318.                 if (*p == '/') {
  319.             makestr(&url->pth,p);  /* Path */
  320.             *p = NUL;
  321.                 }
  322.             }
  323.         }
  324.     /* Copy non-NULL result strings */
  325.     if (url->svc) if (*url->svc) {
  326.             p = url->svc;
  327.             url->svc = NULL;
  328.             makestr(&url->svc,p);
  329.         }
  330.     if (url->hos) if (*url->hos) {
  331.             p = url->hos;
  332.             url->hos = NULL;
  333.             makestr(&url->hos,p);
  334.         }
  335.     if (url->por) if (*url->por) {
  336.             p = url->por;
  337.             url->por = NULL;
  338.             makestr(&url->por,p);
  339.         }
  340.     if (url->usr) if (*url->usr) {
  341.             p = url->usr;
  342.             url->usr = NULL;
  343.             makestr(&url->usr,p);
  344.         }
  345.     if (url->psw) if (*url->psw) {
  346.             p = url->psw;
  347.             url->psw = NULL;
  348.             makestr(&url->psw,p);
  349.         }
  350.  
  351.         /* Save a copy of the full url if one was found. */
  352.     if (url->svc) 
  353.       makestr(&url->sav,s);
  354.         free(urlbuf);
  355.     return(url->svc ? 1 : 0);
  356.     }
  357.     return(0);
  358. }
  359. #endif /* CK_URL */
  360.  
  361. #ifndef NOCMDL
  362.  
  363. char *hlp1[] = {
  364. #ifndef NOICP
  365. " [filename] [-x arg [-x arg]...[-yyy]..] [ = text ] ]\n",
  366. #else
  367. "[-x arg [-x arg]...[-yyy]..]\n",
  368. #endif /* NOICP */
  369. "\n",
  370. "  -x is an option requiring an argument, -y an option with no argument.\n",
  371. "  If the first command-line argument is the name of a file, interactive-\n",
  372. "  mode commands are executed from the file.  The '=' argument tells Kermit\n",
  373. "  not to parse the remainder of the command line, but to make the words\n",
  374. "  following '=' available as \\%1, \\%2, ... \\%9.  The command file \
  375. (if any)\n",
  376. "  is executed before the command-line options.\n",
  377. "\n",
  378. #ifndef NOICP
  379. "If no action command is included, or -S is, then after the command line is\n",
  380. "executed, Kermit issues its prompt and waits for you to type commands.\n",
  381. #else
  382. "Operation by command-line options only.\n",
  383. #endif /* NOICP */
  384. ""
  385. };
  386.  
  387. static
  388. char *hlp2[] = {
  389. "  [option-list] host[:port] [port]\n",
  390. "  The option-list consists of zero, one, or more of:\n",
  391. "  -8                Negotiate Telnet Binary in both directions\n",
  392. "  -a                Require use of Telnet authentication\n",
  393. "  -d                Turn on debug mode\n",
  394. "  -E                No escape character\n",
  395. "  -K                Refuse use of authentication; do not send username\n",
  396. "  -l user           Set username and request Telnet authentication\n",
  397. "  -L                Negotiate Telnet Binary Output only\n",
  398. "  -x                Require Encryption\n",
  399. "  -D                Disable forward-X\n",
  400. "  -T cert=file      Use certificate in file\n",
  401. "  -T key=file       Use private key in file\n",
  402. "  -T crlfile=file   Use CRL in file\n",
  403. "  -T crldir=dir     Use CRLs in directory\n",
  404. "  -T cipher=string  Use only ciphers in string\n",
  405. "  -f                Forward credentials to host\n",
  406. "  -k realm          Set default Kerberos realm\n",
  407. ""
  408. };
  409.  
  410. /* Command-line option help lines.  Update this when adding new options! */
  411.  
  412. char * opthlp[128];                     /* Option help */
  413. char * arghlp[128];                     /* Argument for option */
  414. int optact[128];                        /* Action-option flag */
  415.  
  416. VOID
  417. fatal2(msg1,msg2) char *msg1, *msg2; {
  418.     char buf[256];
  419.     if (!msg1) msg1 = "";
  420.     if (!msg2) msg2 = "";
  421.     ckmakmsg(buf,256,"\"",msg1,"\" - ",msg2);
  422. #ifndef NOICP
  423.     if (what == W_COMMAND)
  424.       printf("%s\n",buf);
  425.     else
  426. #endif /* NOICP */
  427.       fatal((char *)buf);
  428. }
  429.  
  430. static SIGTYP
  431. #ifdef CK_ANSI
  432. cl_int(int dummy)
  433. #else /* CK_ANSI */
  434. cl_int(dummy) int dummy;
  435. #endif /* CK_ANSI */
  436. {                    /* Command-line interrupt handler */
  437.     doexit(BAD_EXIT,1);
  438.     SIGRETURN;
  439. }
  440.  
  441. #ifdef NEWFTP
  442. extern int ftp_action, ftp_cmdlin;
  443.  
  444. static int
  445. xx_ftp(host, port) char * host, * port; {
  446. #ifdef CK_URL
  447.     extern int haveurl;
  448. #endif /* CK_URL */
  449.     extern char * ftp_logname;
  450.     int use_tls = 0;
  451.     char * p;
  452.  
  453.     if (port) if (!*port) port = NULL;
  454.  
  455.     if (!host)
  456.       return(0);
  457.     if (!*host)
  458.       return(0);
  459.     debug(F111,"ftp xx_ftp host",ftp_host,haveftpuid);
  460.     debug(F111,"ftp xx_ftp uidbuf",uidbuf,haveftpuid);
  461.     ftp_cmdlin = 1;            /* 1 = FTP started from command line */
  462.     if (nfils > 0)
  463.       ftp_cmdlin++;            /* 2 = same plus file transfer */
  464.  
  465.     if (haveftpuid) {
  466.     makestr(&ftp_logname,uidbuf);
  467.     debug(F111,"ftp_logname",ftp_logname,haveftpuid);
  468.     }
  469.     if (!port) {
  470.     if ((p = ckstrchr(ftp_host,':')))
  471.       *p++ = NUL;
  472.     port = p;
  473.     }
  474.     if (!port) {
  475. #ifdef CK_URL
  476.         if (haveurl) {
  477.         if (g_url.por) 
  478.           port = g_url.por;
  479.             else if (g_url.svc)
  480.           port = g_url.svc;
  481.             else 
  482.           port = "ftp";
  483.         } else
  484. #endif /* CK_URL */
  485.       port = "ftp";
  486.     }
  487.  
  488. #ifdef CK_SSL
  489.     if (haveurl && g_url.svc)
  490.       use_tls = !ckstrcmp("ftps",g_url.svc,-1,0);
  491. #endif /* CK_SSL */
  492.  
  493.     if (ftpopen(ftp_host,port,use_tls) < 1)
  494.       return(-1);
  495.     debug(F111,"ftp xx_ftp action",ckctoa((char)ftp_action),nfils);
  496.     if (nfils > 0) {
  497.     switch (ftp_action) {
  498.       case 'g':
  499.         return(cmdlinget(stayflg));
  500.       case 'p':
  501.       case 's':
  502.         return(cmdlinput(stayflg));
  503.     }
  504.     }
  505.     return(1);
  506. }
  507. #endif /* NEWFTP */
  508.  
  509.  
  510. #ifndef NOHTTP
  511. static
  512. char * http_hlp[] = {
  513.     " -h             This message.\n",
  514.     " -d             Debug to debug.log.\n",
  515.     " -S             Stay (issue command prompt when done).\n",
  516.     " -Y             Do not execute Kermit initialization file.\n",
  517.     " -q             Quiet (suppress most messages).\n",
  518.     " -u name        Username.\n",
  519.     " -P password    Password.\n",
  520.     " -g pathname    Get remote pathname.\n",
  521.     " -p pathname    Put remote pathname.\n",
  522.     " -H pathname    Head remote pathname.\n",
  523.     " -l pathname    Local path for -g, -p, and -H.\n",
  524. #ifdef CK_SSL
  525.     " -z opt[=value] Security options...\n",
  526.     "    cert=file   Client certificate file\n",
  527.     "    certsok     Accept all certificates\n",
  528.     "    key=file    Client private key file\n",
  529.     "    secure      Use SSL\n",
  530.     "    verify=n    0 = none, 1 = peer , 2 = certificate required\n",
  531. #endif /* CK_SSL */
  532.     ""
  533. };
  534.  
  535. #define HT_CERTFI 0
  536. #define HT_OKCERT 1
  537. #define HT_KEY    2
  538. #define HT_SECURE 3
  539. #define HT_VERIFY 4
  540.  
  541. static struct keytab httpztab[] = {
  542.     { "cert",    HT_CERTFI, CM_ARG },
  543.     { "certsok", HT_OKCERT, 0 },
  544.     { "key",     HT_KEY,    CM_ARG },
  545.     { "secure",  HT_SECURE, 0 },
  546.     { "verify",  HT_VERIFY, CM_ARG },
  547.     { "", 0, 0 }
  548. };
  549. static int nhttpztab = sizeof(httpztab) / sizeof(struct keytab) - 1;
  550. #endif /* NOHTTP */
  551.  
  552. /*  U S A G E */
  553.  
  554. VOID
  555. usage() {
  556. #ifdef MINIX
  557.     conol("Usage: ");
  558.     conol(xarg0);
  559.     conol(" [-x arg [-x arg]...[-yyy]..] ]\n");
  560. #else
  561.     conol("Usage: ");
  562.     conol(xarg0);
  563.     if (howcalled == I_AM_KERMIT || howcalled == I_AM_IKSD ||
  564.         howcalled == I_AM_SSHSUB)
  565.       conola(hlp1);
  566.     else if (howcalled == I_AM_TELNET)
  567.       conola(hlp2);
  568.     if (howcalled == I_AM_KERMIT || howcalled == I_AM_IKSD ||
  569.         howcalled == I_AM_SSHSUB) {
  570.     int c;
  571.     conoll("");
  572.     conoll("Complete listing of command-line options:");
  573.     conoll("");
  574.     for (c = 31; c < 128; c++) {
  575.         if (!opthlp[c])
  576.           continue;
  577.         if (arghlp[c]) {
  578.         printf(" -%c <arg>%s\n",
  579.                (char)c,
  580.                (optact[c] ? " (action option)" : "")
  581.                );
  582.         printf("     %s\n",opthlp[c]);
  583.         printf("     Argument: %s\n\n",arghlp[c]);
  584.         } else {            /* Option without arg */
  585.         printf(" -%c  %s%s\n",
  586.                (char)c, opthlp[c],
  587.                (optact[c]?" (action option)":"")
  588.                );
  589.         printf("     Argument: (none)\n\n");
  590.         }
  591.     }
  592. #ifdef OS2ORUNIX
  593.     printf("To prevent this message from scrolling, use '%s -h | more'.\n",
  594.            xarg0);
  595. #endif /* OS2ORUNIX */
  596.     printf("For a list of extended options use '%s --help'.\n",
  597.            xarg0);
  598.     }
  599. #endif /* MINIX */
  600. }
  601.  
  602.  
  603. /*  C M D L I N  --  Get arguments from command line  */
  604.  
  605. int
  606. cmdlin() {
  607.     char x;                             /* Local general-purpose char */
  608.     extern int haveurl;
  609.  
  610. #ifdef NEWFTP
  611.     char * port = NULL;
  612. #endif /* NEWFTP */
  613.  
  614. #ifndef NOXFER
  615.     cmarg = "";                         /* Initialize globals */
  616.     cmarg2 = "";
  617. #endif /* NOXFER */
  618.     action = 0;
  619.     cflg = 0;
  620.  
  621.     signal(SIGINT,cl_int);
  622.  
  623. /* Here we handle different "Command Line Personalities" */
  624.  
  625. #ifdef TCPSOCKET
  626. #ifndef NOHTTP
  627.     if (howcalled == I_AM_HTTP) {       /* If I was called as HTTP... */
  628.     char rdns[128];
  629. #ifdef OS2
  630.     char * agent = "Kermit 95";
  631. #else   
  632.     char * agent = "C-Kermit";
  633. #endif /* OS2 */
  634.  
  635.         debug(F100,"http personality","",0);
  636. #ifdef CK_URL
  637.         if (haveurl) {
  638.             int type;
  639.             char * lfile;
  640.  
  641.         type = lookup(urltab,g_url.svc,nurltab,NULL);
  642.             if (!(type == URL_HTTP || type == URL_HTTPS)) {
  643.                 printf("?Internal Error: HTTP command line processing\n");
  644.                 debug(F100,"Error: HTTP command line processing","",0);
  645.                 doexit(BAD_EXIT,1);
  646.             }
  647.             rdns[0] = '\0';
  648.             lfile = "";
  649.             x = (http_open(g_url.hos,g_url.por ? g_url.por : g_url.svc, 
  650.                            type == URL_HTTPS, rdns,128) == 0);
  651.             if (x) {
  652.                 if (!quiet) {
  653.                     if (rdns[0])
  654.               printf("Connected to %s [%s]\r\n",g_url.hos,rdns);
  655.                     else
  656.               printf("Connected to %s\r\n",g_url.hos);
  657.                 }
  658.                 if (g_url.pth)
  659.                   zstrip(g_url.pth,&lfile);
  660.                 else
  661.           g_url.pth = "/";
  662.  
  663.                 if (!*lfile)
  664.                   lfile = "index.html";
  665.  
  666.                 x = http_get(agent,
  667.                  NULL,    /* hdrlist */
  668.                  g_url.usr,
  669.                  g_url.psw,
  670.                  0,
  671.                  lfile ,
  672.                  g_url.pth,
  673.                  0        /* stdio */
  674.                  );
  675.                 x = (http_close() == 0);
  676.             } else {
  677.                 if (!quiet)
  678.           printf("?HTTP Connection failed.\r\n");
  679.             }
  680.             doexit(x ? GOOD_EXIT : BAD_EXIT, -1);
  681.         } else 
  682. #endif /* CK_URL */
  683.       {
  684.           extern int debtim;
  685.           int http_action = 0;
  686.           char * host = NULL, * svc = NULL, * lpath = NULL;
  687.           char * user = NULL, * pswd = NULL, * path = NULL;
  688.           char * xp;
  689.  
  690.           while (--xargc > 0) {    /* Go through command line words */
  691.           xargv++;
  692.           debug(F111,"cmdlin http xargv",*xargv,xargc);
  693.           xp = *xargv+1;
  694.           if (**xargv == '-') { /* Got an option */
  695.               int xx;
  696.               x = *(*xargv+1);    /* Get the option letter */
  697.               switch (x) {
  698.             case 'd':    /* Debug */
  699. #ifdef DEBUG
  700.               if (deblog) {
  701.                   debtim = 1;
  702.               } else {
  703.                   deblog = debopn("debug.log",0);
  704.               }
  705. #endif /* DEBUG */
  706.               break;
  707.             case 'S':    /* Stay */
  708.             case 'Y':    /* No initialization file */
  709.               break;    /* (already done in prescan) */
  710.             case 'q':    /* Quiet */
  711.               quiet = 1;
  712.               break;
  713.             case 'u':    /* Options that require arguments */
  714.             case 'P':
  715.             case 'g':
  716.             case 'p':
  717.             case 'H':
  718.             case 'l':
  719.               if (*(xp+1)) {
  720.                   XFATAL("Invalid argument bundling");
  721.               }
  722.               xargv++, xargc--;
  723.               if ((xargc < 1) || (**xargv == '-')) {
  724.                   XFATAL("Missing argument");
  725.               }
  726.               switch (x) {
  727.                 case 'u':
  728.                   user = *xargv;
  729.                   break;
  730.                 case 'P':
  731.                   pswd = *xargv;
  732.                   break;
  733.                 case 'l':
  734.                   if (http_action != HTTP_PUT)
  735.                 lpath = *xargv;
  736.                   break;
  737.                 case 'g':
  738.                   http_action = HTTP_GET;
  739.                   path = *xargv;
  740.                   debug(F111,"cmdlin http GET",path,http_action);
  741.                   break;
  742.                 case 'p':
  743.                   http_action = HTTP_PUT;
  744.                   path = *xargv;
  745.                   break;
  746.                 case 'H':
  747.                   http_action = HTTP_HED;
  748.                   path = *xargv;
  749.               }
  750.               break;
  751.  
  752. #ifdef CK_SSL
  753.                         case 'z': {
  754.                 /* *xargv contains a value of the form tag=value */
  755.                 /* we need to lookup the tag and save the value  */
  756.                 int x,y,z;
  757.                 char * p, * q;
  758.                 makestr(&p,*xargv);
  759.                 y = ckindex("=",p,0,0,1);
  760.                 if (y > 0)
  761.                               p[y-1] = '\0';
  762.                 x = lookup(httpztab,p,nhttpztab,&z);
  763.                 if (x < 0) {
  764.                 printf("?Invalid security option: \"%s\"\n",p);
  765.                 } else {
  766.                 printf("Security option: \"%s",p);
  767.                 if (httpztab[z].flgs & CM_ARG) {
  768.                     q = &p[y];
  769.                     if (!*q)
  770.                                       fatal("?Missing required value");
  771.                 }
  772.                 /* -z options w/args */
  773.                 switch (httpztab[z].kwval) {
  774.                   case HT_CERTFI:
  775.                     makestr(&ssl_rsa_cert_file,q);
  776.                     break;
  777.                   case HT_OKCERT:
  778.                     ssl_certsok_flag = 1;
  779.                     break;
  780.                   case HT_KEY:
  781.                     makestr(&ssl_rsa_key_file,q);
  782.                     break;
  783.                   case HT_SECURE:
  784.                     svc="https";
  785.                     break;
  786.                   case HT_VERIFY:
  787.                     if (!rdigits(q))
  788.                                       printf("?Bad number: %s\n",q);
  789.                     ssl_verify_flag = atoi(q);
  790.                     break;
  791.                 }
  792.                 }
  793.                 free(p);
  794.                 break;
  795.                         }
  796. #endif /* CK_SSL */
  797.  
  798.             case 'h':    /* Help */
  799.             default:
  800.               printf("Usage: %s host [ options... ]\n",xarg0);
  801.               conola(http_hlp);
  802.               doexit(GOOD_EXIT,-1);
  803.               }
  804.           } else {        /* No dash - must be hostname */
  805.               host = *xargv;
  806.               if (xargc > 1) {
  807.               svc = *(xargv+1);
  808.               if (svc) if (*svc == '-' || !*svc)
  809.                 svc = NULL;
  810.               if (svc) {
  811.                   xargv++;
  812.                   xargc--;
  813.               }
  814.               }
  815.           }
  816.           }
  817.           if (!svc) svc = "";
  818.           if (!*svc) svc = "http";
  819.           if (!host) XFATAL("No http host given");
  820.  
  821.           /* Check action args before opening the connection */
  822.           if (http_action) {
  823.           if (http_action == HTTP_PUT) {
  824.               if (!lpath)
  825.             XFATAL("No local path for http PUT");
  826.           }
  827.           if (!path)
  828.             XFATAL("No remote path for http action");
  829.           }
  830.           /* Now it's OK to open the connection */
  831.           rdns[0] = NUL;
  832.           x = (http_open(host,
  833.                  svc,!ckstrcmp("https",svc,-1,0),rdns,128
  834.                  ) == 0);
  835.           if (!x) {
  836.           if (!quiet)
  837.             printf("?HTTP Connection failed.\r\n");
  838.           doexit(BAD_EXIT,-1);
  839.           }
  840.           if (!quiet) {
  841.           if (rdns[0])
  842.             printf("Connected to %s [%s]\r\n",host,rdns);
  843.           else
  844.             printf("Connected to %s\r\n",host);
  845.           }
  846.           if (http_action) {
  847.                   int pcpy = 0;
  848.           if (http_action != HTTP_PUT) { /* Supply default */
  849.               if (!lpath) {         /* local path... */
  850.               zstrip(path,&lpath);
  851.               if (!lpath)
  852.                 lpath = "";
  853.               if (!*lpath)
  854.                 lpath = "index.html";
  855.               }
  856.           }
  857.                   if (*path != '/') {
  858.                       char * p = (char *) malloc(strlen(path)+2);
  859.                       if (!p) fatal("?Memory allocation error\n");
  860.                       *p = '/';
  861.                       strcpy(&p[1],path);      /* safe */
  862.                       path = p;
  863.                       pcpy = 1;
  864.                   }
  865.           switch (http_action) {
  866.             case HTTP_GET:
  867.               x = http_get(agent,NULL,user,pswd,0,lpath,path,0);
  868.               break;
  869.               
  870.             case HTTP_PUT:
  871.               x = http_put(agent,NULL,"text/HTML",
  872.                    user,pswd,0,lpath,path,NULL,0);
  873.               break;
  874.  
  875.             case HTTP_HED:
  876.               x = http_head(agent,NULL,user,pswd,0,lpath,path,0);
  877.               break;
  878.           }
  879.           debug(F101,"cmdline http result","",x);
  880.                   x = (http_close() == 0);
  881.                   if (pcpy) free(path);
  882.                   doexit(x ? GOOD_EXIT : BAD_EXIT, -1);
  883.           }
  884.           return(0);
  885.       }
  886.     } else
  887. #endif /* NOHTTP */
  888. #ifdef NEWFTP
  889.       if (howcalled == I_AM_FTP) {    /* If I was called as FTP... */
  890.       debug(F100,"ftp personality","",0);
  891. #ifdef CK_URL
  892.       if (haveurl)
  893.             doftparg('U');
  894.       else 
  895. #endif /* CK_URL */
  896.         {
  897.         while (--xargc > 0) {    /* Go through command line words */
  898.             xargv++;
  899.             debug(F111,"cmdlin ftp xargv",*xargv,xargc);
  900.             if (**xargv == '-') { /* Got an option */
  901.             int xx;
  902.             x = *(*xargv+1); /* Get the option letter */
  903.             xx = doftparg(x);
  904.             if (xx < 0) {
  905.                 if (what == W_COMMAND)
  906.                   return(0);
  907.                 else
  908.                   doexit(BAD_EXIT,1);
  909.             }
  910.             } else {        /* No dash - must be hostname */
  911.             makestr(&ftp_host,*xargv);
  912.             if (xargc > 1) {
  913.                 port = *(xargv+1);
  914.                 if (port) if (*port == '-' || !*port)
  915.                   port = NULL;
  916.                 if (port) {
  917.                 xargv++;
  918.                 xargc--;
  919.                 }
  920.             }
  921.             debug(F110,"cmdlin ftp host",ftp_host,0);
  922.             debug(F110,"cmdlin ftp port",port,0);
  923.             }
  924.         } /* while */
  925.         } /* if (haveurl) */
  926.  
  927.       if (ftp_host) {
  928.           int xx;
  929. #ifdef NODIAL
  930.           xx = xx_ftp(ftp_host,port);
  931.           if (xx < 0 && (haveurl || ftp_cmdlin > 1)) doexit(BAD_EXIT,-1);
  932. #else
  933. #ifdef NOICP
  934.           xx = xx_ftp(ftp_host,port);
  935.           if (xx < 0 && (haveurl || ftp_cmdlin > 1)) doexit(BAD_EXIT,-1);
  936. #else
  937.           if (*ftp_host == '=') {    /* Skip directory lookup */
  938.           xx = xx_ftp(&ftp_host[1],port);
  939.           if (xx < 0 && (haveurl || ftp_cmdlin > 1))
  940.             doexit(BAD_EXIT,-1);
  941.           } else {            /* Want lookup */
  942.           int i;
  943.           nhcount = 0;        /* Check network directory */
  944.           debug(F101,"cmdlin nnetdir","",nnetdir);
  945.           if (nnetdir > 0)    /* If there is a directory... */
  946.             lunet(ftp_host);    /* Look up the name */
  947.           else            /* If no directory */
  948.             nhcount = 0;    /* we didn't find anything there */
  949. #ifdef DEBUG
  950.           if (deblog) {
  951.               debug(F101,"cmdlin lunet nhcount","",nhcount);
  952.               if (nhcount > 0) {
  953.               debug(F110,"cmdlin lunet nh_p[0]",nh_p[0],0);
  954.               debug(F110,"cmdlin lunet nh_p2[0]",nh_p2[0],0);
  955.               debug(F110,"cmdlin lunet nh_px[0][0]",
  956.                 nh_px[0][0],0);
  957.               }
  958.           }
  959. #endif /* DEBUG */
  960.           if (nhcount == 0) {
  961.               xx = xx_ftp(ftp_host,port);
  962.               if (xx < 0 && (haveurl || ftp_cmdlin > 1))
  963.             doexit(BAD_EXIT,-1);
  964.           } else {
  965.               for (i = 0; i < nhcount; i++) {
  966.               if (ckstrcmp(nh_p2[i],"tcp/ip",6,0))
  967.                 continue;
  968.               makestr(&ftp_host,nh_p[i]);
  969.               debug(F110,"cmdlin calling xx_ftp",ftp_host,0);
  970.               if (!quiet)
  971.                 printf("Trying %s...\n",ftp_host);
  972.               if (xx_ftp(ftp_host,port) > -1)
  973.                 break;
  974.               }
  975.           }
  976.           }
  977. #endif /* NODIAL */
  978. #endif /* NOICP */
  979.           if (!ftpisconnected())
  980.         doexit(BAD_EXIT,-1);
  981.       }
  982.       return(0);
  983.       }
  984. #endif /* NEWFTP */
  985.  
  986. #ifdef TNCODE
  987.     if (howcalled == I_AM_TELNET) {     /* If I was called as Telnet... */
  988.  
  989.         while (--xargc > 0) {        /* Go through command line words */
  990.             xargv++;
  991.             debug(F111,"cmdlin xargv",*xargv,xargc);
  992.             if (**xargv == '=')
  993.           return(0);
  994.             if (!strcmp(*xargv,"--"))    /* getopt() conformance */
  995.           return(0);
  996. #ifdef VMS
  997.             else if (**xargv == '/')
  998.           continue;
  999. #endif /* VMS */
  1000.             else if (**xargv == '-') {    /* Got an option (begins with dash) */
  1001.                 int xx;
  1002.                 x = *(*xargv+1);    /* Get the option letter */
  1003.                 debug(F111,"cmdlin args 1",*xargv,xargc);
  1004.                 xx = dotnarg(x);
  1005.                 debug(F101,"cmdlin doarg","",xx);
  1006.                 debug(F111,"cmdlin args 2",*xargv,xargc);
  1007.                 if (xx < 0) {
  1008. #ifndef NOICP
  1009.                     if (what == W_COMMAND)
  1010.               return(0);
  1011.                     else
  1012. #endif /* NOICP */
  1013.               {
  1014. #ifdef OS2
  1015.               sleep(1);    /* Give it a chance... */
  1016. #endif /* OS2 */
  1017.               doexit(BAD_EXIT,1); /* Go handle option */
  1018.               }
  1019.                 }
  1020.             } else {            /* No dash must be hostname */
  1021.                 ckstrncpy(ttname,*xargv,TTNAMLEN+1);
  1022.                 debug(F110,"cmdlin telnet host",ttname,0);
  1023.  
  1024. #ifndef NOICP
  1025. #ifndef NODIAL
  1026.                 nhcount = 0;        /* Check network directory */
  1027.                 debug(F101,"cmdlin nnetdir","",nnetdir);
  1028.                 if (nnetdir > 0)    /* If there is a directory... */
  1029.           lunet(*xargv);    /* Look up the name */
  1030.                 else            /* If no directory */
  1031.           nhcount = 0;        /* we didn't find anything there */
  1032. #ifdef DEBUG
  1033.                 if (deblog) {
  1034.                     debug(F101,"cmdlin lunet nhcount","",nhcount);
  1035.                     if (nhcount > 0) {
  1036.                         debug(F110,"cmdlin lunet nh_p[0]",nh_p[0],0);
  1037.                         debug(F110,"cmdlin lunet nh_p2[0]",nh_p2[0],0);
  1038.                         debug(F110,"cmdlin lunet nh_px[0][0]",nh_px[0][0],0);
  1039.                     }
  1040.                 }
  1041. #endif /* DEBUG */
  1042.                 if (nhcount > 0 && nh_p2[0]) /* If network type specified */
  1043.           if (ckstrcmp(nh_p2[0],"tcp/ip",6,0)) /* it must be TCP/IP */
  1044.             nhcount = 0;
  1045.                 if (nhcount == 1) {    /* Still OK, so make substitution */
  1046.                     ckstrncpy(ttname,nh_p[0],TTNAMLEN+1);
  1047.                     debug(F110,"cmdlin lunet substitution",ttname,0);
  1048.                 }
  1049. #endif /* NODIAL */
  1050. #endif /* NOICP */
  1051.  
  1052.                 if (--xargc > 0 && !haveurl) { /* Service from command line? */
  1053.                     xargv++;
  1054.                     ckstrncat(ttname,":",TTNAMLEN+1);
  1055.                     ckstrncat(ttname,*xargv,TTNAMLEN+1);
  1056.                     debug(F110,"cmdlin telnet host2",ttname,0);
  1057.                 }
  1058. #ifndef NOICP
  1059. #ifndef NODIAL
  1060.                 else if (nhcount) {    /* No - how about in net directory? */
  1061.                     if (nh_px[0][0]) {
  1062.                         ckstrncat(ttname,":",TTNAMLEN+1);
  1063.                         ckstrncat(ttname,nh_px[0][0],TTNAMLEN+1);
  1064.                     }
  1065.                 }
  1066. #endif /* NODIAL */
  1067. #endif /* NOICP */
  1068.                 local = 1;        /* Try to open the connection */
  1069.                 nettype = NET_TCPB;
  1070.                 mdmtyp = -nettype;
  1071.                 if (ttopen(ttname,&local,mdmtyp,0) < 0) {
  1072.                     XFATAL("can't open host connection");
  1073.                 }
  1074.                 network = 1;        /* It's open */
  1075. #ifdef CKLOGDIAL
  1076.                 dolognet();
  1077. #endif /* CKLOGDIAL */
  1078. #ifndef NOXFER
  1079.                 reliable = 1;        /* It's reliable */
  1080.                 xreliable = 1;        /* ... */
  1081.                 setreliable = 1;
  1082. #endif /* NOXFER */
  1083.                 cflg = 1;        /* Connect */
  1084.                 stayflg = 1;        /* Stay */
  1085.                 tn_exit = 1;        /* Telnet-like exit condition */
  1086.                 quiet = 1;
  1087.                 exitonclose = 1;    /* Exit when connection closes */
  1088. #ifndef NOSPL
  1089.                 if (local) {
  1090.                     if (nmac) {        /* Any macros defined? */
  1091.                         int k;        /* Yes */
  1092.                         k = mlook(mactab,"on_open",nmac); /* Look this up */
  1093.                         if (k >= 0) {                     /* If found, */
  1094.                             if (dodo(k,ttname,0) > -1)    /* set it up, */
  1095.                                 parser(1);                /* and execute it */
  1096.                         }
  1097.                     }
  1098.                 }
  1099. #endif /* NOSPL */
  1100.                 break;
  1101.             }
  1102.         }
  1103.         return(0);
  1104.     }
  1105. #endif /* TNCODE */
  1106. #ifdef COMMENT
  1107. #ifdef RLOGCODE
  1108.     else if (howcalled == I_AM_RLOGIN) { /* If I was called as Rlogin... */
  1109.         /* Add rlogin command-line parsing here... */
  1110.         return(0);
  1111.     }
  1112. #endif /* RLOGCODE */
  1113. #endif /* COMMENT */
  1114. #endif /* TCPSOCKET */
  1115.  
  1116.     if (howcalled == I_AM_SSHSUB)
  1117.       return(0);
  1118.  
  1119. /*
  1120.   From here down: We were called as "kermit" or "iksd".
  1121.  
  1122.   If we were started directly from a Kermit script file,
  1123.   the filename of the script is in argv[1], so skip past it.
  1124. */
  1125.     if (xargc > 1) {
  1126.         int n = 1;
  1127.         if (*xargv[1] != '-') {
  1128.  
  1129. #ifdef KERBANG
  1130.             /* If we were started with a Kerbang script, the script */
  1131.             /* arguments were already picked up in prescan / cmdini() */
  1132.             /* and there is nothing here for us anyway. */
  1133.             if (!strcmp(xargv[1],"+"))
  1134.               return(0);
  1135. #endif /* KERBANG */
  1136.  
  1137.             if (cfilef) {               /* Command file found in prescan() */
  1138.                 xargc -= n;             /* Skip past it */
  1139.                 xargv += n;
  1140.                 cfilef = 0;
  1141.                 debug(F101,"cmdlin cfilef set to 0","",cfilef);
  1142.             }
  1143.         }
  1144.     }
  1145. /*
  1146.   Regular Unix-style command line parser, mostly conforming with 'A Proposed
  1147.   Command Syntax Standard for Unix Systems', Hemenway & Armitage, Unix/World,
  1148.   Vol.1, No.3, 1984.
  1149. */
  1150.     while (--xargc > 0) {               /* Go through command line words */
  1151.         xargv++;
  1152.         debug(F111,"cmdlin xargv",*xargv,xargc);
  1153.         if (**xargv == '=')
  1154.           return(0);
  1155.         if (!strcmp(*xargv,"--"))       /* getopt() conformance */
  1156.           return(0);
  1157. #ifdef VMS
  1158.         else if (**xargv == '/')
  1159.           continue;
  1160. #endif /* VMS */
  1161.         else if (**xargv == '-') {      /* Got an option (begins with dash) */
  1162.             int xx;
  1163.             x = *(*xargv+1);            /* Get the option letter */
  1164.             debug(F111,"cmdlin args 1",*xargv,xargc);
  1165.             xx = doarg(x);
  1166.             debug(F101,"cmdlin doarg","",xx);
  1167.             debug(F111,"cmdlin args 2",*xargv,xargc);
  1168.             if (xx < 0) {
  1169. #ifndef NOICP
  1170.                 if (what == W_COMMAND)
  1171.                   return(0);
  1172.                 else
  1173. #endif /* NOICP */
  1174.                   {
  1175. #ifdef OS2
  1176.                       sleep(1);         /* Give it a chance... */
  1177. #endif /* OS2 */
  1178.                       doexit(BAD_EXIT,1); /* Go handle option */
  1179.                   }
  1180.             }
  1181.         } else if (!haveurl) {        /* No dash where expected */
  1182.         char xbuf[32];
  1183.             char buf[128];
  1184.         int k;
  1185.         k = ckstrncpy(xbuf,*xargv,40);
  1186.         if (k > 30) {
  1187.         xbuf[30] = '.';
  1188.         xbuf[29] = '.';
  1189.         xbuf[28] = '.';
  1190.         }
  1191.         xbuf[31] = NUL;
  1192.             ckmakmsg(buf,
  1193.              128,
  1194.              "invalid command-line option, type \"",
  1195.              myname,
  1196.              " -h\" for help",
  1197.              NULL
  1198.              );
  1199.         fatal2(xbuf,buf);
  1200.         }
  1201.     }
  1202. #ifdef DEBUG
  1203.     if (deblog) {
  1204. #ifndef NOICP
  1205.         debug(F101,"cmdlin what","",what);
  1206. #endif /* NOICP */
  1207.         debug(F101,"cmdlin action","",action);
  1208. #ifndef NOXFER
  1209.         debug(F101,"cmdlin stdouf","",stdouf);
  1210. #endif /* NOXFER */
  1211.     }
  1212. #endif /* DEBUG */
  1213.  
  1214. #ifdef NOICP
  1215.     if (!action && !cflg && !cnflg) {
  1216.         debug(F100,"cmdlin NOICP fatal no action","",0);
  1217.         XFATAL("?No actions specified on command line");
  1218.     }
  1219. #else
  1220.     if (inserver && what == 0) {        /* Internet Kermit server checks */
  1221.         if (local || (action != 0 && action != 'x')) {
  1222.             if (local)
  1223.               printf("local\r\n");
  1224.             if (action)
  1225.               printf("action=%c\r\n",action);
  1226.             debug(F100,"cmdlin fatal 1","",0);
  1227.             XFATAL("No actions or connections allowed with -A");
  1228.         }
  1229.     }
  1230. #endif /* NOICP */
  1231.  
  1232. #ifndef NOLOCAL
  1233.     if (!local) {
  1234.         if ((action == 'c') || (cflg != 0)) {
  1235.             debug(F100,"cmdlin fatal 2","",0);
  1236.             XFATAL("-l or -j or -X required");
  1237.         }
  1238.     }
  1239. #endif /* NOLOCAL */
  1240. #ifndef NOXFER
  1241.     if (*cmarg2 != 0) {
  1242.         if ((action != 's') && (action != 'r') && (action != 'v')) {
  1243.             debug(F100,"cmdlin fatal 3","",0);
  1244.             XFATAL("-a without -s, -r, or -g");
  1245.         }
  1246.         if (action == 'r' || action == 'v') {
  1247. #ifdef CK_TMPDIR
  1248.             if (isdir(cmarg2)) {        /* -a is a directory */
  1249.                 if (!zchdir(cmarg2)) {  /* try to change to it */
  1250.                     debug(F100,"cmdlin fatal 4","",0);
  1251.                     XFATAL("can't change to '-a' directory");
  1252.                 } else cmarg2 = "";
  1253.             } else
  1254. #endif /* CK_TMPDIR */
  1255.               if (zchko(cmarg2) < 0) {
  1256.                   debug(F100,"cmdlin fatal 5","",0);
  1257.                   XFATAL("write access to -a file denied");
  1258.               }
  1259.         }
  1260.     }
  1261.     if ((action == 'v') && (stdouf) && (!local)) {
  1262.         if (is_a_tty(1)) {
  1263.             debug(F100,"cmdlin fatal 6","",0);
  1264.             XFATAL("unredirected -k can only be used in local mode");
  1265.         }
  1266.     }
  1267.     if ((action == 's') || (action == 'v') ||
  1268.         (action == 'r') || (action == 'x')) {
  1269.         if (local)
  1270.           displa = 1;
  1271.         if (stdouf) {
  1272.             displa = 0;
  1273.             quiet = 1;
  1274.         }
  1275.     }
  1276.     if (quiet) displa = 0;              /* No display if quiet requested */
  1277. #endif /* NOXFER */
  1278. #ifdef DEBUG
  1279.     if (action)
  1280.       debug(F000,"cmdlin returns action","",action);
  1281.     else
  1282.       debug(F101,"cmdlin returns action","",action);
  1283. #endif /* DEBUG */
  1284.  
  1285.     return(action);                     /* Then do any requested protocol */
  1286. }
  1287.  
  1288. /* Extended argument parsing: --keyword[:value] (or =value) */
  1289.  
  1290. /*
  1291.   XA_xxxx symbols are defined in ckuusr.h.
  1292.   If you add a new one, also remember to update doshow(),
  1293.   SHXOPT section, in ckuus5.c.
  1294. */
  1295. struct keytab xargtab[] = {
  1296. #ifdef CK_LOGIN
  1297.     { "anonymous",   XA_ANON, CM_ARG|CM_PRE },
  1298. #endif /* CK_LOGIN */
  1299.     { "bannerfile",  XA_BAFI, CM_ARG },
  1300.     { "cdfile",      XA_CDFI, CM_ARG },
  1301.     { "cdmessage",   XA_CDMS, CM_ARG },
  1302.     { "cdmsg",       XA_CDMS, CM_ARG|CM_INV },
  1303. #ifndef NOCSETS
  1304.     { "charset",     XA_CSET, CM_ARG|CM_PRE },
  1305. #endif /* NOCSETS */
  1306. #ifdef IKSDB
  1307.     { "database",    XA_DBAS, CM_ARG|CM_PRE },
  1308.     { "dbfile",      XA_DBFI, CM_ARG|CM_PRE },
  1309. #endif /* IKSDB */
  1310. #ifdef KUI
  1311.     { "facename",    XA_FNAM, CM_ARG|CM_PRE|CM_INV },
  1312.     { "fontname",    XA_FNAM, CM_ARG|CM_PRE },
  1313.     { "fontsize",    XA_FSIZ, CM_ARG|CM_PRE },
  1314. #endif /* KUI */
  1315. #ifdef COMMENT
  1316. #ifdef NEWFTP
  1317.     { "ftp",         XA_FTP,  CM_ARG },
  1318. #endif /* NEWFTP */
  1319. #endif /* COMMENT */
  1320. #ifndef NOLOCAL
  1321. #ifdef OS2
  1322.     { "height",      XA_ROWS, CM_ARG|CM_PRE },
  1323. #endif /* OS2 */
  1324. #endif /* NOLOCAL */
  1325.     { "help",        XA_HELP, 0 },
  1326. #ifndef NOHELP
  1327.     { "helpfile",    XA_HEFI, CM_ARG },
  1328. #endif /* NOHELP */
  1329. #ifdef CK_LOGIN
  1330.     { "initfile",    XA_ANFI, CM_ARG|CM_PRE },
  1331. #endif /* CK_LOGIN */
  1332.     { "nointerrupts",XA_NOIN, CM_PRE },
  1333.     { "noperms",     XA_NPRM, 0 },
  1334. #ifdef COMMENT
  1335.     { "password",    XA_PASS, CM_ARG|CM_INV },
  1336. #endif /* COMMENT */
  1337. #ifdef CK_LOGIN
  1338. #ifndef NOXFER
  1339. #ifdef CK_PERM
  1340.     { "permissions", XA_PERM, CM_ARG|CM_PRE },
  1341.     { "perms",       XA_PERM, CM_ARG|CM_PRE|CM_INV },
  1342. #endif /* CK_PERM */
  1343. #endif /* NOXFER */
  1344. #ifdef UNIX
  1345.     { "privid",      XA_PRIV, CM_ARG|CM_PRE },
  1346. #endif /* UNIX */
  1347. #ifndef NOLOCAL
  1348. #ifndef NOCSETS
  1349.     { "rcharset",    XA_CSET, CM_ARG|CM_PRE|CM_INV },
  1350. #endif /* NOCSETS */
  1351. #endif /* NOLOCAL */
  1352. #ifdef UNIX
  1353.     { "root",        XA_ROOT, CM_ARG|CM_PRE },
  1354. #else /* UNIX */
  1355. #ifdef CKROOT
  1356.     { "root",        XA_ROOT, CM_ARG|CM_PRE },
  1357. #endif /* CKROOT */
  1358. #endif /* UNIX */
  1359. #ifdef COMMENT
  1360. #ifdef SSHBUILTIN
  1361.     { "ssh",         XA_SSH,  CM_ARG },
  1362. #endif /* SSHBUILTIN */
  1363. #endif /* COMMENT */
  1364. #ifdef CKSYSLOG
  1365.     { "syslog",      XA_SYSL, CM_ARG|CM_PRE },
  1366. #endif /* CKSYSLOG */
  1367. #ifndef NOLOCAL
  1368. #ifdef COMMENT
  1369. #ifdef TNCODE
  1370.     { "telnet",      XA_TEL,  CM_ARG },
  1371. #endif /* TNCODE */
  1372. #endif /* COMMENT */
  1373.     { "termtype",    XA_TERM, CM_ARG|CM_PRE },
  1374. #endif /* NOLOCAL */
  1375.     { "timeout",     XA_TIMO, CM_ARG|CM_PRE },
  1376. #ifndef NOLOCAL
  1377. #ifndef NOSPL
  1378.     { "user",        XA_USER, CM_ARG },
  1379. #endif /* NOSPL */
  1380. #endif /* NOLOCAL */
  1381.     { "userfile",    XA_USFI, CM_ARG|CM_PRE },
  1382.     { "version",     XA_VERS, 0 },
  1383. #ifndef NOLOCAL
  1384. #ifdef OS2
  1385.     { "width",       XA_COLS, CM_ARG|CM_PRE },
  1386. #endif /* OS2 */
  1387. #endif /* NOLOCAL */
  1388. #ifdef CKWTMP
  1389.     { "wtmpfile",    XA_WTFI, CM_ARG|CM_PRE },
  1390.     { "wtmplog",     XA_WTMP, CM_ARG|CM_PRE },
  1391. #endif /* CKWTMP */
  1392. #endif /* CK_LOGIN */
  1393.     { "xferfile",    XA_IKFI, CM_ARG|CM_PRE },
  1394.     { "xferlog",     XA_IKLG, CM_ARG|CM_PRE },
  1395. #ifndef NOLOCAL
  1396. #ifdef KUI
  1397.     { "xpos",        XA_XPOS, CM_ARG|CM_PRE },
  1398.     { "ypos",        XA_YPOS, CM_ARG|CM_PRE },
  1399. #endif /* KUI */
  1400. #endif /* NOLOCAL */
  1401.     {"", 0, 0 }
  1402. };
  1403. int nxargs = sizeof(xargtab)/sizeof(struct keytab) - 1;
  1404.  
  1405. static struct keytab oktab[] = {
  1406.     { "0",     0, 0 },
  1407.     { "1",     1, 0 },
  1408.     { "2",     2, 0 },
  1409.     { "3",     3, 0 },
  1410.     { "4",     4, 0 },
  1411.     { "5",     5, 0 },
  1412.     { "6",     6, 0 },
  1413.     { "7",     7, 0 },
  1414.     { "8",     8, 0 },
  1415.     { "9",     9, 0 },
  1416.     { "false", 0, 0 },
  1417.     { "no",    0, 0 },
  1418.     { "off",   0, 0 },
  1419.     { "ok",    1, 0 },
  1420.     { "on",    1, 0 },
  1421.     { "true",  1, 0 },
  1422.     { "yes",   1, 0 }
  1423. };
  1424. static int noktab = sizeof(oktab)/sizeof(struct keytab);
  1425.  
  1426. #define XARGBUFL 32
  1427.  
  1428. char * xopthlp[XA_MAX+1];               /* Extended option help */
  1429. char * xarghlp[XA_MAX+1];               /* Extended argument for option */
  1430.  
  1431. static VOID
  1432. inixopthlp() {
  1433.     int i, j;
  1434.     for (i = 0; i <= XA_MAX; i++) {     /* Initialize all to null */
  1435.         xopthlp[i] = NULL;
  1436.         xarghlp[i] = NULL;
  1437.     }
  1438.     for (i = 0; i < nxargs; i++) {      /* Then for each defined keyword */
  1439.         j = xargtab[i].kwval;           /* index by associated value */
  1440.         if (j < 0 || j > XA_MAX)
  1441.           continue;
  1442.         switch (j) {
  1443. #ifdef CK_LOGIN
  1444.           case XA_ANON:                 /* "--anonymous" */
  1445.             xopthlp[j] = "--anonymous:{on,off} [IKSD only]";
  1446.             xarghlp[j] = "Whether to allow anonymous IKSD logins";
  1447.             break;
  1448. #ifdef UNIX
  1449.       case XA_PRIV:
  1450.             xopthlp[j] = "--privid:{on,off} [IKSD only]";
  1451.             xarghlp[j] = "Whether to allow privileged IDs to login to IKSD";
  1452.             break;
  1453. #endif /* UNIX */
  1454. #endif /* CK_LOGIN */
  1455.           case XA_BAFI:                 /* "--bannerfile" */
  1456.             xopthlp[j] = "--bannerfile:<filename>";
  1457.             xarghlp[j] = "File to display upon startup or IKSD login";
  1458.             break;
  1459.           case XA_CDFI:                 /* "--cdfile" */
  1460.             xopthlp[j] = "--cdfile:<filename>";
  1461.             xarghlp[j] = "File to display when server changes directory";
  1462.             break;
  1463.           case XA_CDMS:                 /* "--cdmessage" */
  1464.             xopthlp[j] = "--cdmessage:{on,off}";
  1465.             xarghlp[j] = "Whether to display CD message file";
  1466.             break;
  1467.           case XA_HELP:                 /* "--help" */
  1468.             xopthlp[j] = "--help";
  1469.             xarghlp[j] = "Print this help text about extended options";
  1470.             break;
  1471.           case XA_HEFI:                 /* "--help" */
  1472.             xopthlp[j] = "--helpfile:<filename>";
  1473.             xarghlp[j] = "File containing custom info for HELP command";
  1474.             break;
  1475.           case XA_IKFI:                 /* "--xferfile" */
  1476.             xopthlp[j] = "--xferfile:<filename> [IKSD only]";
  1477.             xarghlp[j] = "Name of ftpd-like logfile.";
  1478.             break;
  1479.           case XA_IKLG:                 /* "--xferlog" */
  1480.             xopthlp[j] = "--xferlog:{on,off} [IKSD only]";
  1481.             xarghlp[j] = "Whether to keep an ftpd-like logfile.";
  1482.             break;
  1483. #ifdef CK_LOGIN
  1484.           case XA_ANFI:                 /* "--initfile" */
  1485.             xopthlp[j] = "--initfile:<filename> [IKSD only]";
  1486.             xarghlp[j] = "Initialization file for anonymous users.";
  1487.             break;
  1488. #ifdef CK_PERM
  1489.           case XA_PERM:                 /* "--permissions" */
  1490.             xopthlp[j] = "--permissions:<octalnum> [IKSD only]";
  1491.             xarghlp[j] = "Permissions for files uploaded by anonymous users.";
  1492.             break;
  1493. #endif /* CK_PERM */
  1494. #ifdef UNIX
  1495.           case XA_ROOT:                 /* "--root" */
  1496.             xopthlp[j] = "--root:<directory> [IKSD only]";
  1497.             xarghlp[j] = "File-system root for anonymous users.";
  1498.             break;
  1499. #else /* UNIX */
  1500. #ifdef CKROOT
  1501.           case XA_ROOT:                 /* "--root" */
  1502.             xopthlp[j] = "--root:<directory> [IKSD only]";
  1503.             xarghlp[j] = "File-system root for anonymous users.";
  1504.             break;
  1505. #endif /* CKROOT */
  1506. #endif /* UNIX */
  1507. #endif /* CK_LOGIN */
  1508. #ifdef CKSYSLOG
  1509.           case XA_SYSL:                 /* "--syslog" */
  1510.             xopthlp[j] = "--syslog:<digit> [IKSD only]";
  1511.             xarghlp[j] = "Syslog recording level, 0-6.";
  1512.             break;
  1513. #endif /* CKSYSLOG */
  1514.           case XA_USFI:                 /* "--userfile" */
  1515.             xopthlp[j] = "--userfile:<filename> [IKSD only]";
  1516.             xarghlp[j] = "Forbidden user file.";
  1517.             break;
  1518. #ifdef CKWTMP
  1519.           case XA_WTFI:                 /* "--wtmpfile" */
  1520.             xopthlp[j] = "--wtmpfile:<filename> [IKSD only]";
  1521.             xarghlp[j] = "Name of wtmp logfile.";
  1522.             break;
  1523.           case XA_WTMP:                 /* "--wtmplog" */
  1524.             xopthlp[j] = "--wtmplog:{on,off} [IKSD only]";
  1525.             xarghlp[j] = "Whether to keep a wtmp logfile.";
  1526.             break;
  1527. #endif /* CKWTMP */
  1528. #ifdef CK_LOGIN
  1529.           case XA_TIMO:                 /* "--timeout" */
  1530.             xopthlp[j] = "--timeout:<seconds> [IKSD only]";
  1531.             xarghlp[j] =
  1532.  "How long to wait for login before closing the connection.";
  1533.             break;
  1534. #endif /* CK_LOGIN */
  1535.           case XA_NOIN:
  1536.             xopthlp[j] = "--nointerrupts";
  1537.             xarghlp[j] = "Disable keyboard interrupts.";
  1538.             break;
  1539. #ifdef IKSDB
  1540.           case XA_DBAS:
  1541.             xopthlp[j] = "--database:{on,off}";
  1542.             xarghlp[j] = "Enable/Disable IKSD database (IKSD only)";
  1543.             break;
  1544.           case XA_DBFI:
  1545.             xopthlp[j] = "--dbfile:<filename>";
  1546.             xarghlp[j] = "Specify IKSD database file (IKSD only)";
  1547.             break;
  1548. #endif /* IKSDB */
  1549. #ifdef CK_PERMS
  1550.       case XA_NPRM:
  1551.             xopthlp[j] = "--noperms";
  1552.             xarghlp[j] = "Disable file-transfer Permissions attribute.";
  1553.             break;
  1554. #endif /* CK_PERMS */
  1555. #ifdef KUI
  1556.       case XA_XPOS:
  1557.         xopthlp[j] = "--xpos:n";
  1558.         xarghlp[j] = "X-coordinate of window position (number).";
  1559.         break;
  1560.       case XA_YPOS:
  1561.         xopthlp[j] = "--ypos:n";
  1562.         xarghlp[j] = "Y-coordinate of window position (number).";
  1563.         break;
  1564.       case XA_FNAM:
  1565.         xopthlp[j] = "--fontname:s (or --facename:s)";
  1566.         xarghlp[j] = "Font/typeface name: string with _ replacing blank.";
  1567.         break;
  1568.       case XA_FSIZ:
  1569.         xopthlp[j] = "--fontsize:n";
  1570.         xarghlp[j] = "Font point size (number).";
  1571.         break;
  1572. #endif /* KUI */
  1573. #ifdef OS2
  1574.       case XA_ROWS:
  1575.         xopthlp[j] = "--height:n";
  1576.         xarghlp[j] = "Screen height (number of rows).";
  1577.         break;
  1578.       case XA_COLS:
  1579.         xopthlp[j] = "--width:n";
  1580.         xarghlp[j] = "Screen width (number of columns).";
  1581.         break;
  1582. #endif /* OS2 */
  1583.       case XA_CSET:
  1584.         xopthlp[j] = "--rcharset:name";
  1585.         xarghlp[j] = "Name of remote terminal character set.";
  1586.         break;
  1587.       case XA_TERM:
  1588.         xopthlp[j] = "--termtype:name";
  1589. #ifdef OS2
  1590.         xarghlp[j] = "Choose terminal emulation.";
  1591. #else
  1592.         xarghlp[j] = "Choose terminal type.";
  1593. #endif /* OS2 */
  1594.         break;
  1595.       case XA_USER:
  1596.         xopthlp[j] = "--user:name";
  1597. #ifndef NETCONN
  1598.         xarghlp[j] = "Username (for network login)";
  1599. #else
  1600.         xarghlp[j] = "Username.";
  1601. #endif /* NETCONN */
  1602.         break;
  1603.        }
  1604.     }
  1605. }
  1606.  
  1607. VOID
  1608. iniopthlp() {
  1609.     int i;
  1610.     for (i = 0; i < 128; i++) {
  1611.         optact[i] = 0;
  1612.         switch(i) {
  1613. #ifdef OS2
  1614.           case '#':                     /* K95 Startup Flags */
  1615.             opthlp[i] = "Kermit 95 Startup Flags";
  1616.             arghlp[i] = "\n"\
  1617.               "   1 - turn off Win95 special fixes\n"\
  1618.               "   2 - do not load optional network dlls\n"\
  1619.               "   4 - do not load optional tapi dlls\n"\
  1620.               "   8 - do not load optional kerberos dlls\n"\
  1621.               "  16 - do not load optional zmodem dlls\n"\
  1622.               "  32 - use stdin for input instead of the console\n"\
  1623.               "  64 - use stdout for output instead of the console\n"\
  1624.               " 128 - do not terminate process in response to Session Logoff";
  1625.             break;
  1626. #endif /* OS2 */
  1627.           case '0':                     /* In the middle */
  1628.             opthlp[i] =
  1629.               "100% transparent CONNECT mode for \"in-the-middle\" operation";
  1630.             arghlp[i] = NULL;
  1631.             break;
  1632.  
  1633.           case '8':
  1634.             opthlp[i] = "Connection is 8-bit clean";
  1635.             arghlp[i] = NULL;
  1636.             break;
  1637.  
  1638. #ifdef NEWFTP
  1639.           case '9':
  1640.             opthlp[i] = "Make a connection to an FTP server";
  1641.             arghlp[i] = "IP-address-or-hostname[:optional-TCP-port]";
  1642.             break;
  1643. #endif /* NEWFTP */
  1644.  
  1645. #ifdef IKSD
  1646.           case 'A':
  1647.             opthlp[i] = "Kermit is to be started as an Internet service";
  1648. #ifdef NT
  1649.             arghlp[i] = "  socket handle of incoming connection";
  1650. #else /* NT */
  1651.             arghlp[i] = NULL;
  1652. #endif /* NT */
  1653.             break;
  1654. #endif /* IKSD */
  1655.           case 'B': opthlp[i] =
  1656.       "Kermit is running in Batch or Background (no controlling terminal)";
  1657.             break;
  1658. #ifndef NOSPL
  1659.           case 'C':
  1660.             opthlp[i] = "Interactive-mode Commands to be executed";
  1661.             arghlp[i] = "Commands separated by commas, list in doublequotes";
  1662.             break;
  1663. #endif /* NOSPL */
  1664.           case 'D':
  1665.             opthlp[i] = "Delay before starting to send";
  1666.             arghlp[i] = "Number of seconds";
  1667.             break;
  1668.           case 'E':
  1669.             opthlp[i] = "Exit automatically when connection closes";
  1670.             arghlp[i] = NULL;
  1671.             break;
  1672. #ifdef TCPSOCKET
  1673.           case 'F':
  1674.             opthlp[i] = "Make a TCP connection";
  1675.             arghlp[i] = "Numeric file descriptor of open TCP connection";
  1676.             break;
  1677. #endif /* TCPSOCKET */
  1678.           case 'G':
  1679.             opthlp[i] = "GET from server, send to standard output";
  1680.             arghlp[i] = "Remote file specification";
  1681.             optact[i] = 1;
  1682.             break;
  1683.           case 'H':
  1684.             opthlp[i] = "Suppress program startup Herald and greeting";
  1685.             arghlp[i] = NULL;
  1686.             break;
  1687.           case 'I':
  1688.             opthlp[i] = "Connection is reliable, streaming is allowed";
  1689.             arghlp[i] = NULL;
  1690.             break;
  1691. #ifdef TCPSOCKET
  1692.           case 'J':
  1693.             opthlp[i] = "'Be like Telnet'";
  1694.             arghlp[i] = "IP hostname/address optionally followed by service";
  1695.             break;
  1696. #endif /* TCPSOCKET */
  1697.           case 'L':
  1698.             opthlp[i] = "Recursive directory descent for files in -s option";
  1699.             arghlp[i] = NULL;
  1700.             break;
  1701.           case 'M':
  1702.             opthlp[i] = "My user name (for use with Telnet, Rlogin, etc)";
  1703.             arghlp[i] = "Username string";
  1704.             break;
  1705. #ifdef NETBIOS
  1706.           case 'N':
  1707.             opthlp[i] = "NETBIOS adapter number";
  1708.             arghlp[i] = "Number";
  1709.             break;
  1710. #endif /* NETBIOS */
  1711.           case 'O':                     /* Be a server for One command only */
  1712.             opthlp[i] = "Be a server for One command only";
  1713.             arghlp[i] = NULL;
  1714.             optact[i] = 1;
  1715.             break;
  1716.           case 'P':
  1717.             opthlp[i] = "Don't convert file (Path) names";
  1718.             arghlp[i] = NULL;
  1719.             break;
  1720.           case 'Q':
  1721.             opthlp[i] = "Quick (FAST) Kermit protocol settings";
  1722.             arghlp[i] = NULL;
  1723.             break;
  1724.           case 'R':                     /* Remote-Only */
  1725.             opthlp[i] = "Remote-only (makes IF REMOTE true)";
  1726.             arghlp[i] = NULL;
  1727.             break;
  1728.           case 'S':                     /* "Stay" - enter interactive */
  1729.             opthlp[i] = "Stay (enter command parser after action options)";
  1730.             arghlp[i] = NULL;
  1731.             break;
  1732.           case 'T':                     /* Text file transfer mode */
  1733.             opthlp[i] = "Transfer files in Text mode";
  1734.             arghlp[i] = NULL;
  1735.             break;
  1736. #ifdef ANYX25
  1737.           case 'U':                     /* X.25 call user data */
  1738.             opthlp[i] = "X.25 call User data";
  1739.             arghlp[i] = "Call-user-data string";
  1740.             break;
  1741. #endif /* ANYX25 */
  1742.           case 'V':                     /* No automatic filetype switching */
  1743.             opthlp[i] = "Disable automatic per-file text/binary switching";
  1744.             arghlp[i] = NULL;
  1745.             break;
  1746. #ifdef COMMENT
  1747. #ifdef OS2
  1748.           case 'W':                     /* Win32 Window Handle */
  1749.             opthlp[i] = "";
  1750.             arghlp[i] = NULL;
  1751.             break;
  1752. #endif /* OS2 */
  1753. #endif /* COMMENT */
  1754. #ifdef ANYX25
  1755.           case 'X':                     /* SET HOST to X.25 address */
  1756.             opthlp[i] = "Make an X.25 connection";
  1757.             arghlp[i] = "X.25 or X.121 address";
  1758.             break;
  1759. #endif /* ANYX25 */
  1760.           case 'Y':                     /* No initialization file */
  1761.             opthlp[i] = "Skip initialization file";
  1762.             arghlp[i] = NULL;
  1763.             break;
  1764. #ifdef ANYX25
  1765.           case 'Z':                     /* SET HOST to X.25 file descriptor */
  1766.             opthlp[i] = "Make an X.25 connection";
  1767.             arghlp[i] = "Numeric file descriptor of open X.25 connection";
  1768.             break;
  1769. #endif /* ANYX25 */
  1770.           case 'a':                     /* as-name */
  1771.             opthlp[i] = "As-name for file(s) in -s, -r, or -g";
  1772.             arghlp[i] = "As-name string (alternative filename)";
  1773.             break;
  1774.           case 'b':                     /* Set bits-per-second for serial */
  1775.             opthlp[i] = "Speed for serial device";
  1776.             arghlp[i] = "Numeric Bits per second";
  1777.             break;
  1778.           case 'c':                     /* Connect before */
  1779.             optact[i] = 1;
  1780.             opthlp[i] = "CONNECT before transferring files";
  1781.             arghlp[i] = NULL;
  1782.             break;
  1783.           case 'd':                     /* DEBUG */
  1784.             opthlp[i] = "Create debug.log file (a second -d adds timestamps)";
  1785.             arghlp[i] = NULL;
  1786.             break;
  1787.           case 'e':                     /* Extended packet length */
  1788.             opthlp[i] = "Maximum length for incoming file-transfer packets";
  1789.             arghlp[i] = "Length in bytes";
  1790.             break;
  1791.           case 'f':                     /* finish */
  1792.             optact[i] = 1;
  1793.             opthlp[i] = "Send Finish command to a Kermit server";
  1794.             arghlp[i] = NULL;
  1795.             break;
  1796.           case 'g':                     /* get */
  1797.             optact[i] = 1;
  1798.             opthlp[i] = "GET file(s) from a Kermit server";
  1799.             arghlp[i] = "Remote file specification";
  1800.             break;
  1801.           case 'h':                     /* help */
  1802.             optact[i] = 1;
  1803. #ifdef OS2ORUNIX
  1804.             opthlp[i] =
  1805.           "Print this message (pipe thru 'more' to prevent scrolling)";
  1806. #else
  1807.           "Print this message";
  1808. #endif /* OS2ORUNIX */
  1809.             arghlp[i] = NULL;
  1810.             break;
  1811.           case 'i':                     /* Treat files as binary */
  1812.             opthlp[i] ="Transfer files in binary mode";
  1813.             arghlp[i] = NULL;
  1814.             break;
  1815. #ifdef TCPSOCKET
  1816.           case 'j':                     /* SET HOST (TCP/IP socket) */
  1817.             opthlp[i] = "Make a TCP connection";
  1818.             arghlp[i] =
  1819.           "TCP host name/address and optional service name or number";
  1820.             break;
  1821. #endif /* TCPSOCKET */
  1822.           case 'k':                     /* receive to stdout */
  1823.             optact[i] = 1;
  1824.             opthlp[i] = "RECEIVE file(s) to standard output";
  1825.             arghlp[i] = NULL;
  1826.             break;
  1827.           case 'l':                     /* SET LINE */
  1828.             opthlp[i] = "Make connection on serial communications device";
  1829.             arghlp[i] = "Serial device name";
  1830.             break;
  1831.           case 'm':                     /* Modem type */
  1832.             opthlp[i] = "Modem type for use with -l device";
  1833.             arghlp[i] = "Modem name as in SET MODEM TYPE command";
  1834.             break;
  1835.           case 'n':                     /* connect after */
  1836.             optact[i] = 1;
  1837.             opthlp[i] = "CONNECT after transferring files";
  1838.             arghlp[i] = NULL;
  1839.             break;
  1840. #ifdef ANYX25
  1841.           case 'o':                     /* X.25 closed user group */
  1842.             opthlp[i] = "X.25 closed user group";
  1843.             arghlp[i] = "User group string";
  1844.             break;
  1845. #endif /* ANYX25 */
  1846.           case 'p':                     /* SET PARITY */
  1847.             opthlp[i] = "Parity";
  1848.             arghlp[i] = "One of the following: even, odd, mark, none, space";
  1849.             break;
  1850.           case 'q':                     /* Quiet */
  1851.             opthlp[i] = "Quiet (suppress most messages)";
  1852.             arghlp[i] = NULL;
  1853.             break;
  1854.           case 'r':                     /* receive */
  1855.             optact[i] = 1;
  1856.             opthlp[i] = "RECEIVE file(s)";
  1857.             arghlp[i] = NULL;
  1858.             break;
  1859.           case 's':                     /* send */
  1860.             optact[i] = 1;
  1861.             opthlp[i] = "SEND file(s)";
  1862.             arghlp[i] = "One or more file specifications";
  1863.             break;
  1864.           case 't':                     /* Line turnaround handshake */
  1865.             opthlp[i] = "XON Turnaround character for half-duplex connections";
  1866.             arghlp[i] = NULL;
  1867.             break;
  1868. #ifdef ANYX25
  1869.           case 'u':                     /* X.25 reverse charge call */
  1870.             opthlp[i] = "X.25 reverse charge call";
  1871.             arghlp[i] = NULL;
  1872.             break;
  1873. #endif /* ANYX25 */
  1874.           case 'v':                     /* Vindow size */
  1875.             opthlp[i] = "Window size";
  1876.             arghlp[i] = "Number, 1 to 32";
  1877.             break;
  1878.           case 'w':                     /* Writeover */
  1879.             opthlp[i] = "Incoming files Write over existing files";
  1880.             arghlp[i] = NULL;
  1881.             break;
  1882.           case 'x':                     /* Server */
  1883.             optact[i] = 1;
  1884.             opthlp[i] = "Be a Kermit SERVER";
  1885.             arghlp[i] = NULL;
  1886.             break;
  1887.           case 'y':                     /* Alternate init-file name */
  1888.             opthlp[i] = "Alternative initialization file";
  1889.             arghlp[i] = "File specification";
  1890.             break;
  1891.           case 'z':                     /* Not background */
  1892.             opthlp[i] = "Force foreground behavior";
  1893.             arghlp[i] = NULL;
  1894.             break;
  1895.           default:
  1896.             opthlp[i] = NULL;
  1897.             arghlp[i] = NULL;
  1898.         }
  1899.     }
  1900.     inixopthlp();
  1901. }
  1902.  
  1903. int
  1904. doxarg(s,pre) char ** s; int pre; {
  1905. #ifdef IKSD
  1906. #ifdef CK_LOGIN
  1907.     extern int ckxsyslog, ckxwtmp, ckxanon;
  1908. #ifdef UNIX
  1909.     extern int ckxpriv;
  1910. #endif /* UNIX */
  1911. #ifdef CK_PERMS
  1912.     extern int ckxperms;
  1913. #endif /* CK_PERMS */
  1914.     extern char * anonfile, * userfile, * anonroot;
  1915. #endif /* CK_LOGIN */
  1916. #ifdef CKWTMP
  1917.     extern char * wtmpfile;
  1918. #endif /* CKWTMP */
  1919. #endif /* IKSD */
  1920.     extern int srvcdmsg;
  1921.     extern char * cdmsgfile[], * cdmsgstr;
  1922.     char tmpbuf[CKMAXPATH+1];
  1923.  
  1924.     int i, x, y, z, havearg = 0;
  1925.     char buf[XARGBUFL], c, * p;
  1926.  
  1927.     if (nxargs < 1)
  1928.       return(-1);
  1929.  
  1930.     c = *(*s + 1);                      /* Hyphen or Plus sign */
  1931.  
  1932.     p = *s + 2;
  1933.     for (i = 0; *p && i < XARGBUFL; i++) {
  1934.         buf[i] = *p++;
  1935.         if (buf[i] == '=' || buf[i] == ':') {
  1936.             havearg = 1;
  1937.             buf[i] = NUL;
  1938.             break;
  1939.         } else if (buf[i] < ' ') {
  1940.             buf[i] = NUL;
  1941.             break;
  1942.         }
  1943.     }
  1944.     if (i > XARGBUFL - 1)
  1945.       return(-1);
  1946.     buf[i] = NUL;
  1947.  
  1948.     x = lookup(xargtab,buf,nxargs,&z);  /* Lookup the option keyword */
  1949.  
  1950.     if (x < 0)                          /* On any kind of error */
  1951.       return(-1);                       /* fail. */
  1952.  
  1953.     /* Handle prescan versus post-initialization file */
  1954.  
  1955.     if (((xargtab[z].flgs & CM_PRE) || (c == '+')) && !pre)
  1956.       return(0);
  1957.     else if (pre && !(xargtab[z].flgs & CM_PRE) && (c != '+'))
  1958.       return(0);
  1959.  
  1960.     /* Ensure that argument is given if and only if required */
  1961.  
  1962.     p = havearg ? *s + i + 3 : NULL;
  1963.  
  1964.     if ((xargtab[z].flgs & CM_ARG) && !havearg)
  1965.       return(-1);
  1966.     else if ((!(xargtab[z].flgs & CM_ARG)) && havearg)
  1967.       return(-1);
  1968.  
  1969.     switch (x) {                        /* OK to process this option... */
  1970. #ifdef CKSYSLOG
  1971.       case XA_SYSL:                     /* IKS: Syslog level */
  1972.         y = 0;
  1973.         if (isdigit(*p)) {
  1974.             while (*p) {
  1975.                 if (*p < '0' || *p > '9')
  1976.                   return(-1);
  1977.                 y = y * 10 + (*p++ - '0');
  1978.             }
  1979.         } else {
  1980.             y = lookup(oktab,p,noktab,&z);
  1981.             if (y > 0) y = SYSLG_DF;    /* Yes = default logging level */
  1982.         }
  1983. #ifndef SYSLOGLEVEL
  1984.         /* If specified on cc command line, user can't change it. */
  1985.         if (!inserver)                  /* Don't allow voluminous syslogging */
  1986.           if (y > SYSLG_FA)             /* by ordinary users. */
  1987.             y = SYSLG_FA;
  1988. #endif /* SYSLOGLEVEL */
  1989.         if (y < 0) return(-1);
  1990. #ifdef DEBUG
  1991.         if (y >= SYSLG_DB)
  1992.           if (!deblog)
  1993.             deblog = debopn("debug.log",0);
  1994. #endif /* DEBUG */
  1995. #ifdef SYSLOGLEVEL
  1996.         /* If specified on cc command line, user can't change it. */
  1997.         y = SYSLOGLEVEL;
  1998. #endif /* SYSLOGLEVEL */
  1999.         ckxsyslog = y;
  2000.         /* printf("ckxsyslog=%d\n",ckxsyslog); */
  2001.         break;
  2002. #endif /* CKSYSLOG */
  2003.  
  2004. #ifdef CK_LOGIN
  2005. #ifdef CKWTMP
  2006.       case XA_WTMP:                     /* IKS: wtmp log */
  2007.         y = lookup(oktab,p,noktab,&z);
  2008.         if (y < 0) return(-1);
  2009.         ckxwtmp = y;
  2010.         /* printf("ckxwtmp=%d\n",ckxwtmp); */
  2011.         break;
  2012.  
  2013.       case XA_WTFI:                     /* IKS: wtmp logfile */
  2014.         if (zfnqfp(p,CKMAXPATH,tmpbuf))
  2015.           p = tmpbuf;
  2016.         makestr(&wtmpfile,p);
  2017.         /* printf("wtmpfile=%s\n",wtmpfile); */
  2018.         break;
  2019. #endif /* CKWTMP */
  2020.  
  2021.       case XA_ANON:                     /* IKS: Anonymous login allowed */
  2022.         y = lookup(oktab,p,noktab,&z);
  2023.         if (y < 0) return(-1);
  2024.         ckxanon = y;
  2025.         /* printf("ckxanon=%d\n",ckxanon); */
  2026.         break;
  2027.  
  2028. #ifdef UNIX
  2029.       case XA_PRIV:                     /* IKS: Priv'd login allowed */
  2030.         y = lookup(oktab,p,noktab,&z);
  2031.         if (y < 0) return(-1);
  2032.         ckxpriv = y;
  2033.         /* printf("ckxpriv=%d\n",ckxpriv); */
  2034.         break;
  2035. #endif /* UNIX */
  2036.  
  2037. #ifdef CK_PERMS
  2038.       case XA_PERM:                     /* IKS: Anonymous Upload Permissions */
  2039.         y = 0;
  2040.         while (*p) {
  2041.             if (*p < '0' || *p > '7')
  2042.               return(-1);
  2043.             y = y * 8 + (*p++ - '0');
  2044.         }
  2045.         ckxperms = y;
  2046.         /* printf("ckxperms=%04o\n",ckxperms); */
  2047.         break;
  2048. #endif /* CK_PERMS */
  2049.  
  2050.       case XA_ANFI:                     /* Anonymous init file */
  2051.         if (zfnqfp(p,CKMAXPATH,tmpbuf))
  2052.           p = tmpbuf;
  2053.         makestr(&anonfile,p);
  2054.         /* printf("anonfile=%s\n",anonfile); */
  2055.         break;
  2056.  
  2057.       case XA_USFI:                     /* IKS: Forbidden user file */
  2058.         if (zfnqfp(p,CKMAXPATH,tmpbuf))
  2059.           p = tmpbuf;
  2060.         makestr(&userfile,p);
  2061.         /* printf("userfile=%s\n",userfile); */
  2062.         break;
  2063.  
  2064.       case XA_ROOT:                     /* IKS: Anonymous root */
  2065.         if (zfnqfp(p,CKMAXPATH,tmpbuf))
  2066.           p = tmpbuf;
  2067.         makestr(&anonroot,p);
  2068.         /* printf("anonroot=%s\n",anonroot); */
  2069.         break;
  2070. #endif /* CK_LOGIN */
  2071.  
  2072.       case XA_CDFI:                     /* CD filename */
  2073. #ifdef COMMENT
  2074.         /* Do NOT expand this one! */
  2075.         if (zfnqfp(p,CKMAXPATH,tmpbuf))
  2076.           p = tmpbuf;
  2077. #endif /* COMMENT */
  2078.         makelist(p,cdmsgfile,16);
  2079.         makestr(&cdmsgstr,p);
  2080.         /* printf("cdmsgstr=%s\n",cdmsgstr); */
  2081.         break;
  2082.  
  2083.       case XA_CDMS:                     /* CD messages */
  2084.         y = lookup(oktab,p,noktab,&z);
  2085.         if (y < 0) return(-1);
  2086.         srvcdmsg = y;
  2087.         /* printf("srvcdmsg=%d\n",srvcdmsg); */
  2088.         break;
  2089.  
  2090. #ifndef NOXFER
  2091.       case XA_IKLG:                     /* Transfer log on/off */
  2092.         y = lookup(oktab,p,noktab,&z);
  2093.         if (y < 0) return(-1);
  2094.         xferlog = y;
  2095.         /* printf("xferlog=%d\n",xferlog); */
  2096.         break;
  2097.  
  2098.       case XA_IKFI:                     /* Transfer log file */
  2099.         if (zfnqfp(p,CKMAXPATH,tmpbuf))
  2100.           p = tmpbuf;
  2101.         makestr(&xferfile,p);
  2102.         xferlog = 1;
  2103.         /* printf("xferfile=%s\n",xferfile); */
  2104.         break;
  2105.  
  2106.       case XA_BAFI:                     /* IKS: banner (greeting) file */
  2107.         if (zfnqfp(p,CKMAXPATH,tmpbuf))
  2108.           p = tmpbuf;
  2109.         makestr(&bannerfile,p);
  2110.         /* printf("bannerfile=%s\n",bannerfile); */
  2111.         break;
  2112. #endif /* NOXFER */
  2113.  
  2114. #ifndef NOHELP
  2115.       case XA_HELP:                     /* Help */
  2116.         /* printf("help\n"); */
  2117.         for (i = 0; i <= XA_MAX; i++)
  2118.           if (xopthlp[i])
  2119.             printf("%s\n   %s\n\n",xopthlp[i],xarghlp[i]);
  2120.         if (stayflg || what == W_COMMAND)
  2121.           break;
  2122.         else
  2123.           doexit(GOOD_EXIT,-1);
  2124. #endif /* NOHELP */
  2125.  
  2126. #ifndef NOHELP
  2127.       case XA_HEFI:                     /* IKS: custom help file */
  2128.         if (zfnqfp(p,CKMAXPATH,tmpbuf))
  2129.           p = tmpbuf;
  2130.         makestr(&helpfile,p);
  2131.         /* printf("helpfile=%s\n",helpfile); */
  2132.         break;
  2133. #endif /* NOHELP */
  2134.  
  2135. #ifdef CK_LOGIN
  2136.       case XA_TIMO:
  2137.         if (!rdigits(p))
  2138.           return(-1);
  2139.         logintimo = atoi(p);
  2140.         /* printf("logintimo=%d\n",p); */
  2141.         break;
  2142. #endif /* CK_LOGIN */
  2143.  
  2144.       case XA_NOIN:                     /* No interrupts */
  2145. #ifndef NOICP
  2146.         cmdint = 0;
  2147. #endif /* NOICP */
  2148.     suspend = 0;
  2149.         break;
  2150.  
  2151. #ifdef IKSDB
  2152.       case XA_DBFI: {
  2153.           extern char * dbdir, * dbfile;
  2154.           extern int dbenabled;
  2155.           struct zfnfp * zz;
  2156.           if ((zz = zfnqfp(p,CKMAXPATH,tmpbuf))) {
  2157.               makestr(&dbdir,zz->fpath);
  2158.               makestr(&dbfile,(char *)tmpbuf);
  2159.               dbenabled = 1;
  2160.           }
  2161.           break;
  2162.       }
  2163.       case XA_DBAS: {
  2164.           extern int dbenabled;
  2165.           y = lookup(oktab,p,noktab,&z);
  2166.           if (y < 0) return(-1);
  2167.           dbenabled = y;
  2168.           break;
  2169.       }
  2170. #endif /* IKSDB */
  2171.  
  2172.       case XA_VERS: {
  2173.       extern char * ck_s_ver, * ck_s_xver;
  2174.       printf("%s",ck_s_ver);
  2175.       if (*ck_s_xver)
  2176.         printf(" [%s]\n",ck_s_xver);
  2177.       printf("\n");
  2178.       if (stayflg || what == W_COMMAND)
  2179.         break;
  2180.       else
  2181.         doexit(GOOD_EXIT,-1);
  2182.       }
  2183. #ifndef NOXFER
  2184. #ifdef CK_PERMS
  2185.       case XA_NPRM: {
  2186.       extern int atlpri, atlpro, atgpri, atgpro;
  2187.       atlpri = 0;
  2188.       atlpro = 0;
  2189.       atgpri = 0;
  2190.       atgpro = 0;
  2191.       break;
  2192.       }
  2193. #endif /* CK_PERMS */
  2194. #endif /* NOXFER */
  2195.  
  2196. #ifdef KUI
  2197.       case XA_XPOS:
  2198.         if (!rdigits(p))
  2199.           return(-1);
  2200.     kui_init.pos_init++;
  2201.     kui_init.pos_x = atoi(p);
  2202.         break;
  2203.  
  2204.       case XA_YPOS:
  2205.         if (!rdigits(p))
  2206.           return(-1);
  2207.     kui_init.pos_init++;
  2208.     kui_init.pos_y = atoi(p);
  2209.         break;
  2210.  
  2211.       case XA_FNAM: {
  2212.       extern struct _kui_init kui_init;
  2213.       extern struct keytab * term_font;
  2214.       extern struct keytab * _term_font;
  2215.       extern int tt_font, ntermfont;
  2216.       int x, z;
  2217.       if (ntermfont == 0)
  2218.         BuildFontTable(&term_font, &_term_font, &ntermfont);
  2219.       if (!(term_font && _term_font && ntermfont > 0))
  2220.         return(-1);
  2221.       x = lookup(_term_font,p,ntermfont,&z);
  2222.       if (x < 0)
  2223.         return(-1);
  2224.       tt_font = x;
  2225.       kui_init.face_init++;
  2226.       makestr(&kui_init.facename,term_font[z].kwd);
  2227.       break;
  2228.       }
  2229.       case XA_FSIZ: {
  2230.       extern struct _kui_init kui_init;
  2231.       extern int tt_font_size;
  2232.  
  2233.       if (!rdigits(p))
  2234.         return(-1);
  2235.       kui_init.font_init++;
  2236.       tt_font_size = kui_init.font_size = atoi(p);
  2237.       break;
  2238.       }
  2239. #endif /* KUI */
  2240.  
  2241. #ifndef NOLOCAL
  2242.       case XA_TERM: {            /* Terminal type */
  2243.           extern struct keytab ttyptab[];
  2244.           extern int nttyp;
  2245. #ifdef TNCODE
  2246.       extern char * tn_term;
  2247. #endif /* TNCODE */
  2248. #ifdef OS2
  2249.       int x, z;
  2250.       extern int tt_type, tt_type_mode;
  2251.       x = lookup(ttyptab,p,nttyp,&z);
  2252.       if (x < 0)
  2253.         return(-1);
  2254.       tt_type_mode = tt_type = x;
  2255. #endif /* OS2 */
  2256. #ifdef TNCODE
  2257.       makestr(&tn_term,p);
  2258. #endif /* TNCODE */
  2259.       break;
  2260.       }
  2261.       case XA_CSET: {            /* Remote Character Set */
  2262. #ifndef NOCSETS
  2263. #ifdef CKOUNI
  2264.           extern struct keytab txrtab[];
  2265.           extern int ntxrtab;
  2266.           x = lookup(txrtab,p,ntxrtab,&z);
  2267. #else /* CKOUNI */
  2268.           extern struct keytab ttcstab[];
  2269.           extern int ntermc;
  2270.           x = lookup(ttcstab,p,ntermc,&z);
  2271. #endif /* CKOUNI */
  2272.       if (x < 0)
  2273.         return(-1);
  2274.           setremcharset(z,4 /* TT_GR_ALL (in ckuus7.c) */);
  2275. #else /* NOCSETS */
  2276.           return(-1);
  2277. #endif /* NOCSETS */
  2278.       break;
  2279.       }
  2280.       case XA_ROWS: {            /* Screen rows (height) */
  2281. #ifdef OS2
  2282.           extern int row_init;
  2283. #else /* OS2 */
  2284.       extern int tt_rows;
  2285. #endif /* OS2 */
  2286.       if (!rdigits(p))
  2287.         return(-1);
  2288. #ifdef OS2
  2289.       if (!os2_settermheight(atoi(p)))
  2290.         return(-1);
  2291.           row_init++;
  2292. #else  /* Not OS/2 */
  2293.       tt_rows = atoi(p);
  2294. #endif /* OS2 */
  2295.       break;
  2296.       }
  2297.       case XA_COLS: {            /* Screen columns (width) */
  2298. #ifdef OS2
  2299.           extern int col_init;
  2300. #else /* OS2 */
  2301.       extern int tt_cols;
  2302. #endif /* OS2 */
  2303.       if (!rdigits(p))
  2304.         return(-1);
  2305. #ifdef OS2
  2306.       if (!os2_settermwidth(atoi(p)))
  2307.         return(-1);
  2308.           col_init++;
  2309. #else  /* Not OS/2 */
  2310.       tt_cols = atoi(p);
  2311. #endif /* OS2 */
  2312.       break;
  2313.       }
  2314.  
  2315. #ifdef COMMENT                /* TO BE FILLED IN ... */
  2316.       case XA_TEL:            /* Make a Telnet connection */
  2317.       case XA_FTP:            /* Make an FTP connection */
  2318.       case XA_SSH:            /* Make an SSH connection */
  2319. #endif /* COMMENT */
  2320.  
  2321. #ifndef NOSPL
  2322.       case XA_USER:            /* Username for login */
  2323. #ifdef IKSD
  2324.     if (!inserver)
  2325. #endif /* IKSD */
  2326.     {
  2327.         ckstrncpy(uidbuf,*xargv,UIDBUFLEN);
  2328.         haveftpuid = 1;
  2329.     }
  2330.     break;
  2331. #endif /* NOSPL */
  2332. #endif /* NOLOCAL */
  2333.  
  2334.       default:
  2335.         return(-1);
  2336.     }
  2337.     return(0);
  2338. }
  2339.  
  2340. #ifdef IKSD
  2341. #ifdef IKSDCONF
  2342. #define IKS_ANON 0
  2343. #define IKS_BAFI 1
  2344. #define IKS_CDFI 2
  2345. #define IKS_CDMS 3
  2346. #define IKS_HEFI 4
  2347. #define IKS_ANFI 5
  2348. #define IKS_USFI 6
  2349. #define IKS_IKLG 7
  2350. #define IKS_IKFI 8
  2351. #define IKS_DBAS 9
  2352. #define IKS_DBFI 10
  2353. #define IKS_PERM 11
  2354. #define IKS_PRIV 12
  2355. #define IKS_ROOT 13
  2356. #define IKS_TIMO 14
  2357. #define IKS_WTFI 15
  2358. #define IKS_WTMP 16
  2359. #define IKS_SRVR 17
  2360. #define IKS_NOIN 18
  2361. #define IKS_INIT 19
  2362. #define IKS_ANLG 20
  2363. #define IKS_ACCT 21
  2364. #define IKS_NTDOM 22
  2365. #define IKS_SYSL 23
  2366.  
  2367. #ifdef CK_LOGIN
  2368. static struct keytab iksantab[] = {
  2369. #ifdef OS2
  2370.     { "account",     IKS_ACCT, 0 },
  2371. #endif /* OS2 */
  2372.     { "initfile",    IKS_ANFI, 0 },
  2373.     { "login",       IKS_ANLG, 0 },
  2374. #ifdef UNIX
  2375.     { "root",        IKS_ROOT, 0 },
  2376. #else
  2377. #ifdef CKROOT
  2378.     { "root",        IKS_ROOT, 0 },
  2379. #endif /* CKROOT */
  2380. #endif /* UNIX */
  2381.     { "", 0, 0 }
  2382. };
  2383. static int niksantab = sizeof(iksantab) / sizeof(struct keytab) - 1;
  2384. #endif /* CK_LOGIN */
  2385.  
  2386. static struct keytab ikstab[] = {
  2387. #ifdef CK_LOGIN
  2388.     { "anonymous",   IKS_ANON, 0 },
  2389. #endif /* CK_LOGIN */
  2390.     { "bannerfile",  IKS_BAFI, 0 },
  2391.     { "cdfile",      IKS_CDFI, 0 },
  2392.     { "cdmessage",   IKS_CDMS, 0 },
  2393.     { "cdmsg",       IKS_CDMS, CM_INV },
  2394. #ifdef IKSDB
  2395.     { "database",    IKS_DBAS, 0 },
  2396.     { "dbfile",      IKS_DBFI, 0 },
  2397. #endif /* IKSDB */
  2398. #ifdef CK_LOGIN
  2399. #ifdef NT
  2400.     { "default-domain", IKS_NTDOM, 0 },
  2401. #endif /* NT */
  2402. #endif /* CK_LOGIN */
  2403. #ifndef NOHELP
  2404.     { "helpfile",    IKS_HEFI, 0 },
  2405. #endif /* NOHELP */
  2406.     { "initfile",    IKS_INIT, 0 },
  2407.     { "no-initfile", IKS_NOIN, 0 },
  2408. #ifdef CK_LOGIN
  2409. #ifdef CK_PERM
  2410.     { "permissions", IKS_PERM, 0 },
  2411.     { "perms",       IKS_PERM, CM_INV },
  2412. #endif /* CK_PERM */
  2413. #ifdef UNIX
  2414.     { "privid",      IKS_PRIV, 0 },
  2415. #endif /* UNIX */
  2416.     { "server-only", IKS_SRVR, 0 },
  2417. #ifdef CKSYSLOG
  2418.     { "syslog",      IKS_SYSL, 0 },
  2419. #endif /* CKSYSLOG */
  2420.     { "timeout",     IKS_TIMO, 0 },
  2421.     { "userfile",    IKS_USFI, 0 },
  2422. #ifdef CKWTMP
  2423.     { "wtmpfile",    IKS_WTFI, 0 },
  2424.     { "wtmplog",     IKS_WTMP, 0 },
  2425. #endif /* CKWTMP */
  2426. #endif /* CK_LOGIN */
  2427.     { "xferfile",    IKS_IKFI, 0 },
  2428.     { "xferlog",     IKS_IKLG, 0 }
  2429. };
  2430. static int nikstab = sizeof(ikstab) / sizeof(struct keytab);
  2431. #endif /* IKSDCONF */
  2432.  
  2433. #ifndef NOICP
  2434. int
  2435. setiks() {                /* SET IKS */
  2436. #ifdef IKSDCONF
  2437. #ifdef CK_LOGIN
  2438.     extern int ckxsyslog, ckxwtmp, ckxanon;
  2439. #ifdef UNIX
  2440.     extern int ckxpriv;
  2441. #endif /* UNIX */
  2442. #ifdef CK_PERMS
  2443.     extern int ckxperms;
  2444. #endif /* CK_PERMS */
  2445.     extern char * anonfile, * userfile, * anonroot;
  2446. #ifdef OS2
  2447.     extern char * anonacct;
  2448. #endif /* OS2 */
  2449. #ifdef NT
  2450.     extern char * iks_domain;
  2451. #endif /* NT */
  2452. #endif /* CK_LOGIN */
  2453. #ifdef CKWTMP
  2454.     extern char * wtmpfile;
  2455. #endif /* CKWTMP */
  2456.     extern int srvcdmsg, success, iksdcf, rcflag, noinit, arg_x;
  2457.     extern char * cdmsgfile[], * cdmsgstr, *kermrc;
  2458.     extern xx_strp xxstring;
  2459.     int x, y, z;
  2460.     char *s;
  2461.     char tmpbuf[CKMAXPATH+1];
  2462.  
  2463.     if ((y = cmkey(ikstab,nikstab,"","",xxstring)) < 0)
  2464.       return(y);
  2465.  
  2466. #ifdef CK_LOGIN
  2467.     if (y == IKS_ANON) {
  2468.         if ((y = cmkey(iksantab,niksantab,"","",xxstring)) < 0)
  2469.       return(y);
  2470.     }
  2471. #endif /* CK_LOGIN */
  2472.  
  2473.     switch (y) {
  2474. #ifdef CKSYSLOG
  2475.       case IKS_SYSL:                     /* IKS: Syslog level */
  2476.         if ((z = cmkey(oktab,noktab,"","",xxstring)) < 0)
  2477.       return(z);
  2478.         if ((x = cmcfm()) < 0) return(x);
  2479.         if (iksdcf) return(success = 0);
  2480. #ifndef SYSLOGLEVEL
  2481.         /* If specified on cc command line, user can't change it. */
  2482.         if (!inserver)                  /* Don't allow voluminous syslogging */
  2483.           if (y > SYSLG_FA)             /* by ordinary users. */
  2484.             y = SYSLG_FA;
  2485. #endif /* SYSLOGLEVEL */
  2486.         if (y < 0) return(-1);
  2487. #ifdef DEBUG
  2488.         if (y >= SYSLG_DB)
  2489.           if (!deblog)
  2490.             deblog = debopn("debug.log",0);
  2491. #endif /* DEBUG */
  2492. #ifdef SYSLOGLEVEL
  2493.         /* If specified on cc command line, user can't change it. */
  2494.         y = SYSLOGLEVEL;
  2495. #endif /* SYSLOGLEVEL */
  2496.         ckxsyslog = y;
  2497.         /* printf("ckxsyslog=%d\n",ckxsyslog); */
  2498.         break;
  2499. #endif /* CKSYSLOG */
  2500.  
  2501. #ifdef CK_LOGIN
  2502. #ifdef NT
  2503.       case IKS_NTDOM:
  2504.         if ((z = cmtxt(
  2505.  "DOMAIN to be used for user authentication when none is specified",
  2506.                        "", &s,xxstring)) < 0)
  2507.       return(z);
  2508.         if (iksdcf) return(success = 0);
  2509.         if (!*s) s= NULL;
  2510.           makestr(&iks_domain,s);
  2511.         break;
  2512. #endif /* NT */
  2513. #ifdef OS2
  2514.       case IKS_ACCT:
  2515.         if ((z = cmtxt("Name of local account to use for anonymous logins",
  2516.             "GUEST", &s,xxstring)) < 0)
  2517.       return(z);
  2518.         if (iksdcf) return(success = 0);
  2519.         if (*s) {
  2520.             makestr(&anonacct,s);
  2521.         } else if ( anonacct ) {
  2522.         free(anonacct);
  2523.         anonacct = NULL;
  2524.     }
  2525.         break;
  2526. #endif /* OS2 */
  2527.       case IKS_ANLG:
  2528.         if ((z = cmkey(oktab,noktab,"","no",xxstring)) < 0)
  2529.       return(z);
  2530.         if ((x = cmcfm()) < 0) return(x);
  2531.         if (iksdcf) return(success = 0);
  2532.         ckxanon = z;
  2533. #ifdef OS2
  2534.     if (ckxanon && !anonacct)
  2535.       makestr(&anonacct,"GUEST");
  2536. #endif /* OS2 */
  2537.         break;
  2538. #endif /* CK_LOGIN */
  2539.       case IKS_BAFI:
  2540.         if ((z = cmifi("Filename","",&s,&x,xxstring)) < 0)
  2541.       return(z);
  2542.         if (x) {
  2543.             printf("?Wildcards not allowed\n");
  2544.             return(-9);
  2545.         }
  2546.         debug(F110,"bannerfile before zfnqfp()",s,0);
  2547.         if (zfnqfp(s,CKMAXPATH,tmpbuf)) {
  2548.             debug(F110,"bannerfile after zfnqfp()",tmpbuf,0);
  2549.             s = tmpbuf;
  2550.         }
  2551.         if ((x = cmcfm()) < 0) return(x);
  2552.         if (iksdcf) return(success = 0);
  2553.         if (*s)
  2554.       makestr(&bannerfile,s);
  2555.         break;
  2556.       case IKS_CDFI:
  2557.         if ((z = cmtxt("list of cd message file names","READ.ME",
  2558.                &s,xxstring)) < 0)
  2559.       return(z);
  2560.         if (iksdcf) return(success = 0);
  2561.         if (*s) {
  2562.             makelist(s,cdmsgfile,16);
  2563.             makestr(&cdmsgstr,s);
  2564.         }
  2565.         break;
  2566.       case IKS_CDMS:
  2567.         if ((z = cmkey(oktab,noktab,"","no",xxstring)) < 0)
  2568.       return(z);
  2569.         if ((x = cmcfm()) < 0) return(x);
  2570.         if (iksdcf) return(success = 0);
  2571.         srvcdmsg = z;
  2572.         break;
  2573.       case IKS_HEFI:
  2574.         if ((z = cmifi("Filename","",&s,&x,xxstring)) < 0)
  2575.       return(z);
  2576.         if (x) {
  2577.             printf("?Wildcards not allowed\n");
  2578.             return(-9);
  2579.         }
  2580.         if (zfnqfp(s,CKMAXPATH,tmpbuf))
  2581.           s = tmpbuf;
  2582.         if ((x = cmcfm()) < 0) return(x);
  2583.         if (iksdcf) return(success = 0);
  2584.         if (*s)
  2585.       makestr(&helpfile,s);
  2586.         break;
  2587.       case IKS_ANFI:
  2588.         if ((z = cmifi("Filename","",&s,&x,xxstring)) < 0)
  2589.       return(z);
  2590.         if (x) {
  2591.             printf("?Wildcards not allowed\n");
  2592.             return(-9);
  2593.         }
  2594.         if (zfnqfp(s,CKMAXPATH,tmpbuf))
  2595.           s = tmpbuf;
  2596.         if ((x = cmcfm()) < 0) return(x);
  2597.         if (iksdcf) return(success = 0);
  2598.         if (*s)
  2599.       makestr(&anonfile,s);
  2600.         break;
  2601.       case IKS_USFI:
  2602.         if ((z = cmifi("Filename","",&s,&x,xxstring)) < 0)
  2603.       return(z);
  2604.         if (x) {
  2605.             printf("?Wildcards not allowed\n");
  2606.             return(-9);
  2607.         }
  2608.         if (zfnqfp(s,CKMAXPATH,tmpbuf))
  2609.           s = tmpbuf;
  2610.         if ((x = cmcfm()) < 0) return(x);
  2611.         if (iksdcf) return(success = 0);
  2612.         if (*s)
  2613.       makestr(&userfile,s);
  2614.         break;
  2615.       case IKS_IKFI:
  2616.         if ((z = cmifi("Filename","",&s,&x,xxstring)) < 0)
  2617.       return(z);
  2618.         if (x) {
  2619.             printf("?Wildcards not allowed\n");
  2620.             return(-9);
  2621.         }
  2622.         if (zfnqfp(s,CKMAXPATH,tmpbuf))
  2623.           s = tmpbuf;
  2624.         if ((x = cmcfm()) < 0) return(x);
  2625.         if (iksdcf) return(success = 0);
  2626.         if (*s) {
  2627.             makestr(&xferfile,s);
  2628.             xferlog = 1;
  2629.         }
  2630.         break;
  2631.       case IKS_IKLG:
  2632.         if ((z = cmkey(oktab,noktab,"","no",xxstring)) < 0)
  2633.       return(z);
  2634.         if ((x = cmcfm()) < 0) return(x);
  2635.         if (iksdcf) return(success = 0);
  2636.         xferlog = z;
  2637.         break;
  2638.  
  2639. #ifdef CK_LOGIN
  2640. #ifdef CK_PERM
  2641.       case IKS_PERM:
  2642.         if ((z = cmtxt("Octal file permssion code","000",
  2643.                &s,xxstring)) < 0)
  2644.       return(z);
  2645.     if (z < 0) return(z);
  2646.         if (iksdcf) return(success = 0);
  2647.         y = 0;
  2648.         while (*s) {
  2649.             if (*s < '0' || *s > '7')
  2650.               return(-9);
  2651.             y = y * 8 + (*s++ - '0');
  2652.         }
  2653.         ckxperms = y;
  2654.         break;
  2655. #endif /* CK_PERM */
  2656. #ifdef UNIX
  2657.       case IKS_PRIV:                     /* IKS: Priv'd login allowed */
  2658.         if ((z = cmkey(oktab,noktab,"","no",xxstring)) < 0)
  2659.       return(z);
  2660.         if ((x = cmcfm()) < 0) return(x);
  2661.         if (iksdcf) return(success = 0);
  2662.         ckxpriv = z;
  2663.         break;
  2664. #endif /* UNIX */
  2665.  
  2666.       case IKS_ROOT:                     /* IKS: Anonymous root */
  2667.     if ((z = cmdir("Name of disk and/or directory","",&s,
  2668.                xxstring)) < 0 ) {
  2669.         if (z != -3)
  2670.           return(z);
  2671.     }
  2672.         if (*s) {
  2673.         if (zfnqfp(s,CKMAXPATH,tmpbuf))
  2674.           s = tmpbuf;
  2675.         } else
  2676.       s = "";
  2677.         if ((x = cmcfm()) < 0) return(x);
  2678.         if (iksdcf) return(success = 0);
  2679.         if (*s)
  2680.       makestr(&anonroot,s);
  2681.         /* printf("anonroot=%s\n",anonroot); */
  2682.         break;
  2683.  
  2684.       case IKS_TIMO:
  2685.     z = cmnum("login timeout, seconds","0",10,&x,xxstring);
  2686.     if (z < 0) return(z);
  2687.         if (x < 0 || x > 7200) {
  2688.             printf("?Value must be between 0 and 7200\r\n");
  2689.             return(-9);
  2690.         }
  2691.         if ((z = cmcfm()) < 0) return(z);
  2692.         if (iksdcf) return(success = 0);
  2693.         logintimo = x;
  2694.         break;
  2695.  
  2696. #ifdef CKWTMP
  2697.       case IKS_WTMP:                     /* IKS: wtmp log */
  2698.         if ((z = cmkey(oktab,noktab,"","no",xxstring)) < 0)
  2699.       return(z);
  2700.         if ((x = cmcfm()) < 0) return(x);
  2701.         if (iksdcf) return(success = 0);
  2702.         ckxwtmp = z;
  2703.         break;
  2704.  
  2705.       case IKS_WTFI:                     /* IKS: wtmp logfile */
  2706.         if ((z = cmifi("Filename","",&s,&x,xxstring)) < 0)
  2707.       return(z);
  2708.         if (x) {
  2709.             printf("?Wildcards not allowed\n");
  2710.             return(-9);
  2711.         }
  2712.         if (zfnqfp(s,CKMAXPATH,tmpbuf))
  2713.           s = tmpbuf;
  2714.         if ((x = cmcfm()) < 0) return(x);
  2715.         if (iksdcf) return(success = 0);
  2716.         if (*s)
  2717.       makestr(&wtmpfile,s);
  2718.         break;
  2719. #endif /* CKWTMP */
  2720. #endif /* CK_LOGIN */
  2721. #ifdef IKSDB
  2722.       case IKS_DBFI: {
  2723.           extern char * dbdir, * dbfile;
  2724.           extern int dbenabled;
  2725.           struct zfnfp * zz;
  2726.           if ((z = cmifi("Filename","",&s,&x,xxstring)) < 0)
  2727.         return(z);
  2728.           if (x) {
  2729.               printf("?Wildcards not allowed\n");
  2730.               return(-9);
  2731.           }
  2732.           zz = zfnqfp(s,CKMAXPATH,tmpbuf);
  2733.           if ((x = cmcfm()) < 0) return(x);
  2734.           if (iksdcf) return(success = 0);
  2735.           if (zz) {
  2736.               makestr(&dbdir,zz->fpath);
  2737.               makestr(&dbfile,(char *)tmpbuf);
  2738.               dbenabled = 1;
  2739.           } else
  2740.         return(success = 0);
  2741.           break;
  2742.       }
  2743.       case IKS_DBAS: {
  2744.           extern int dbenabled;
  2745.           if ((z = cmkey(oktab,noktab,"","no",xxstring)) < 0)
  2746.         return(z);
  2747.           if ((x = cmcfm()) < 0) return(x);
  2748.           if (iksdcf) return(success = 0);
  2749.           dbenabled = z;
  2750.           break;
  2751.       }
  2752. #endif /* IKSDB */
  2753.  
  2754.       case IKS_INIT:
  2755.         if ((z = cmtxt("Alternate init file specification","",
  2756.                &s,xxstring)) < 0)
  2757.       return(z);
  2758.         if (z < 0) return(z);
  2759.         if (iksdcf) return(success = 0);
  2760.         ckstrncpy(kermrc,s,KERMRCL);
  2761.         rcflag = 1;            /* Flag that this has been done */
  2762.         break;
  2763.  
  2764.       case IKS_NOIN:
  2765.         if ((z = cmkey(oktab,noktab,"","no",xxstring)) < 0)
  2766.       return(z);
  2767.         if ((x = cmcfm()) < 0) return(x);
  2768.         if (iksdcf) return(success = 0);
  2769.         noinit = z;
  2770.         break;
  2771.  
  2772.       case IKS_SRVR:
  2773.         if ((z = cmkey(oktab,noktab,"","no",xxstring)) < 0)
  2774.       return(z);
  2775.         if ((x = cmcfm()) < 0) return(x);
  2776.         if (iksdcf) return(success = 0);
  2777.         arg_x = z;
  2778.         break;
  2779.  
  2780.       default:
  2781.         return(-9);
  2782.     }
  2783.     return(success = (inserver ? 1 : 0));
  2784. #else /* IKSDCONF */
  2785.     if ((x = cmcfm()) < 0)
  2786.       return(x);
  2787.     return(success = 0);
  2788. #endif /* IKSDCONF */
  2789. }
  2790. #endif /* NOICP */
  2791. #endif /* IKSD */
  2792.  
  2793. /*  D O A R G  --  Do a command-line argument.  */
  2794.  
  2795. int
  2796. #ifdef CK_ANSIC
  2797. doarg(char x)
  2798. #else
  2799. doarg(x) char x;
  2800. #endif /* CK_ANSIC */
  2801. /* doarg */ {
  2802.     int i, n, y, z, xx; long zz; char *xp;
  2803.  
  2804. #ifdef NETCONN
  2805. #define YYBUFLEN 256
  2806.     char tmpbuf[YYBUFLEN+1];            /* Local storage for network things */
  2807.     char line[YYBUFLEN+1];
  2808. #endif /* NETCONN */
  2809.  
  2810. #ifdef IKSD
  2811.     /* Internet Kermit Server set some way besides -A... */
  2812.     if (inserver)
  2813.       dofast();
  2814. #endif /* IKSD */
  2815.  
  2816.     xp = *xargv+1;                      /* Pointer for bundled args */
  2817.     debug(F111,"doarg entry",xp,xargc);
  2818.     while (x) {
  2819.         debug(F000,"doarg arg","",x);
  2820.         switch (x) {                    /* Big switch on arg */
  2821.  
  2822. #ifndef COMMENT
  2823.       case '-':            /* Extended commands... */
  2824.         if (doxarg(xargv,0) < 0) {
  2825.         XFATAL("Extended option error");
  2826.         } /* Full thru... */
  2827.       case '+':            /* Extended command for prescan() */
  2828.         return(0);
  2829. #else  /* NOICP */
  2830.       case '-':
  2831.       case '+':
  2832.         XFATAL("Extended options not configured");
  2833. #endif /* NOICP */
  2834.  
  2835. #ifndef NOSPL
  2836.       case 'C': {            /* Commands for parser */
  2837.           char * s;
  2838.           xargv++, xargc--;
  2839.           if ((xargc < 1) || (**xargv == '-')) {
  2840.           XFATAL("No commands given for -C");
  2841.           }
  2842.           s = *xargv;        /* Get the argument (must be quoted) */
  2843.           if (!*s)            /* If empty quotes */
  2844.         s = NULL;        /* ignore this option */
  2845.           if (s) {
  2846.           makestr(&clcmds,s);    /* Make pokeable copy */
  2847.           s = clcmds;        /* Change tabs to spaces */
  2848.           while (*s) {
  2849.               if (*s == '\t') *s = ' ';
  2850.               s++;
  2851.           }
  2852.           }
  2853.           break;
  2854.       }
  2855. #endif /* NOSPL */
  2856.  
  2857. #ifndef NOXFER
  2858.       case 'D':            /* Delay */
  2859.         if (*(xp+1)) {
  2860.         XFATAL("invalid argument bundling");
  2861.         }
  2862.         xargv++, xargc--;
  2863.         if ((xargc < 1) || (**xargv == '-')) {
  2864.         XFATAL("missing delay value");
  2865.         }
  2866.         z = atoi(*xargv);        /* Convert to number */
  2867.         if (z > -1)            /* If in range */
  2868.           ckdelay = z;        /* set it */
  2869.         else {
  2870.         XFATAL("bad delay value");
  2871.         }
  2872.         break;
  2873. #endif /* NOXFER */
  2874.  
  2875.       case 'E':            /* Exit on close */
  2876. #ifdef NETCONN
  2877.         tn_exit = 1;
  2878. #endif /* NETCONN */
  2879.         exitonclose = 1;
  2880.         break;
  2881.  
  2882. #ifndef NOICP
  2883.       case 'S':            /* "Stay" - enter interactive */
  2884.         stayflg = 1;        /* command parser after executing */
  2885.         xfinish = 0;        /* command-line actions. */
  2886.         break;
  2887. #endif /* NOICP */
  2888.  
  2889.       case 'T':            /* File transfer mode = text */
  2890.         binary = XYFT_T;
  2891.         xfermode = XMODE_M;        /* Transfer mode manual */
  2892.         filepeek = 0;
  2893. #ifdef PATTERNS
  2894.         patterns = 0;
  2895. #endif /* PATTERNS */
  2896.         break;
  2897.  
  2898.       case '7':
  2899.         break;
  2900.  
  2901. #ifdef IKSD
  2902.       case 'A': {            /* Internet server */
  2903.           /* Already done in prescan() */
  2904.           /* but implies 'x' &&  'Q'   */
  2905. #ifdef OS2
  2906.           char * p;
  2907.           if (*(xp+1)) {
  2908.           XFATAL("invalid argument bundling");
  2909.           }
  2910. #ifdef NT
  2911.           /* Support for Pragma Systems Telnet/Terminal Servers */
  2912.           p = getenv("PRAGMASYS_INETD_SOCK");
  2913.           if (!(p && atoi(p) != 0)) {
  2914.           xargv++, xargc--;
  2915.           if (xargc < 1 || **xargv == '-') {
  2916.               XFATAL("missing socket handle");
  2917.           }
  2918.           }
  2919. #else /* NT */
  2920.           xargv++, xargc--;
  2921.           if (xargc < 1 || **xargv == '-') {
  2922.           XFATAL("missing socket handle");
  2923.           }
  2924. #endif /* NT */
  2925. #endif /* OS2 */
  2926. #ifdef NOICP                            /* If no Interactive Command Parser */
  2927.           action = 'x';        /* -A implies -x. */
  2928. #endif /* NOICP */
  2929. #ifndef NOXFER
  2930.           dofast();
  2931. #endif /* NOXFER */
  2932.           break;
  2933.       }
  2934. #endif /* IKSD */
  2935.  
  2936. #ifndef NOXFER
  2937.       case 'Q':            /* Quick (i.e. FAST) */
  2938.         dofast();
  2939.         break;
  2940. #endif /* NOXFER */
  2941.  
  2942.       case 'R':            /* Remote-Only */
  2943.         break;            /* This is handled in prescan(). */
  2944.  
  2945. #ifndef NOSERVER
  2946.       case 'x':            /* server */
  2947.       case 'O':            /* (for One command only) */
  2948.         if (action) {
  2949.         XFATAL("conflicting actions");
  2950.         }
  2951.         if (x == 'O') justone = 1;
  2952.         xfinish = 1;
  2953.         action = 'x';
  2954.         break;
  2955. #endif /* NOSERVER */
  2956.  
  2957. #ifndef NOXFER
  2958.       case 'f':            /* finish */
  2959.         if (action) {
  2960.         XFATAL("conflicting actions");
  2961.         }
  2962.         action = setgen('F',"","","");
  2963.         break;
  2964. #endif /* NOXFER */
  2965.  
  2966.       case 'r': {            /* receive */
  2967.           if (action) {
  2968.           XFATAL("conflicting actions");
  2969.           }
  2970.           action = 'v';
  2971.           break;
  2972.       }
  2973.  
  2974. #ifndef NOXFER
  2975.       case 'k':            /* receive to stdout */
  2976.         if (action) {
  2977.         XFATAL("conflicting actions");
  2978.         }
  2979.         stdouf = 1;
  2980.         action = 'v';
  2981.         break;
  2982.  
  2983.       case 's': {            /* send */
  2984.           int fil2snd, rc;
  2985.           if (!recursive)
  2986.           nolinks = 0;        /* Follow links by default */
  2987.  
  2988.           if (action) {
  2989.           XFATAL("conflicting actions");
  2990.           }
  2991.           if (*(xp+1)) {
  2992.           XFATAL("invalid argument bundling after -s");
  2993.           }
  2994.           nfils = 0;        /* Initialize file counter */
  2995.           fil2snd = 0;        /* Assume nothing to send  */
  2996.           z = 0;            /* Flag for stdin */
  2997.           cmlist = xargv + 1;    /* Remember this pointer */
  2998.           while (++xargv, --xargc > 0) { /* Traverse the list */
  2999. #ifdef PIPESEND
  3000.           if (usepipes && protocol == PROTO_K && **xargv == '!') {
  3001.               cmarg = *xargv;
  3002.               cmarg++;
  3003.               debug(F110,"doarg pipesend",cmarg,0);
  3004.               nfils = -1;
  3005.               z = 1;
  3006.               pipesend = 1;
  3007.           } else
  3008. #endif /* PIPESEND */
  3009.             if (**xargv == '-') { /* Check for sending stdin */
  3010.             if (strcmp(*xargv,"-") != 0) /* next option? */
  3011.               break;
  3012.             z++;        /* "-" alone means send from stdin. */
  3013. #ifdef RECURSIVE
  3014.             } else if (!strcmp(*xargv,".")) {
  3015.             fil2snd = 1;
  3016.             nfils++;
  3017.             recursive = 1;
  3018.             nolinks = 2;
  3019. #endif /* RECURSIVE */
  3020.             } else /* Check if file exists */
  3021.               if ((rc = zchki(*xargv)) > -1 || (rc == -2)) {
  3022.               if  (rc != -2)
  3023.                 fil2snd = 1;
  3024.               nfils++;    /* Bump file counter */
  3025.               } else if (iswild(*xargv) && nzxpand(*xargv,0) > 0) {
  3026.               /* or contains wildcard characters matching real files */
  3027.               fil2snd = 1;
  3028.               nfils++;
  3029.               }
  3030.           }
  3031.           xargc++, xargv--;        /* Adjust argv/argc */
  3032.           if (!fil2snd && z == 0) {
  3033. #ifdef VMS
  3034.           XFATAL("%CKERMIT-E-SEARCHFAIL, no files for -s");
  3035. #else
  3036.           XFATAL("No files for -s");
  3037. #endif /* VMS */
  3038.           }
  3039.           if (z > 1) {
  3040.           XFATAL("-s: too many -'s");
  3041.           }
  3042.           if (z == 1 && fil2snd) {
  3043.           XFATAL("invalid mixture of filenames and '-' in -s");
  3044.           }
  3045.           debug(F101,"doarg s nfils","",nfils);
  3046.           debug(F101,"doarg s z","",z);
  3047.           if (nfils == 0) {        /* no file parameters were specified */
  3048.           if (is_a_tty(0)) {    /* (used to be is_a_tty(1) - why?) */
  3049.               XFATAL("sending from terminal not allowed");
  3050.           } else stdinf = 1;
  3051.           }
  3052.           debug(F101,"doarg s stdinf","",stdinf);
  3053.           debug(F111,"doarg",*xargv,nfils);
  3054.           action = 's';
  3055.           break;
  3056.       }
  3057.  
  3058.       case 'g':            /* get */
  3059.       case 'G':            /* get to stdout */
  3060.         if (action) {
  3061.         XFATAL("conflicting actions");
  3062.         }
  3063.         if (*(xp+1)) {
  3064.         XFATAL("invalid argument bundling after -g");
  3065.         }
  3066.         xargv++, xargc--;
  3067.         if ((xargc == 0) || (**xargv == '-')) {
  3068.         XFATAL("missing filename for -g");
  3069.         }
  3070.         if (x == 'G') stdouf = 1;
  3071.         cmarg = *xargv;
  3072.         action = 'r';
  3073.         break;
  3074. #endif /* NOXFER */
  3075.  
  3076. #ifndef NOLOCAL
  3077.       case 'c':            /* connect before */
  3078.         cflg = 1;
  3079.         break;
  3080.  
  3081.       case 'n':            /* connect after */
  3082.         cnflg = 1;
  3083.         break;
  3084. #endif /* NOLOCAL */
  3085.  
  3086.       case 'h':            /* help */
  3087.         usage();
  3088. #ifndef NOICP
  3089.         if (stayflg || what == W_COMMAND)
  3090.           break;
  3091.         else
  3092. #endif /* NOICP */
  3093.           doexit(GOOD_EXIT,-1);
  3094.  
  3095. #ifndef NOXFER
  3096.       case 'a':            /* "as" */
  3097.         if (*(xp+1)) {
  3098.         XFATAL("invalid argument bundling after -a");
  3099.         }
  3100.         xargv++, xargc--;
  3101.         if ((xargc < 1) || (**xargv == '-')) {
  3102.         XFATAL("missing name in -a");
  3103.         }
  3104.         cmarg2 = *xargv;
  3105.         debug(F111,"doarg a",cmarg2,xargc);
  3106.         break;
  3107. #endif /* NOXFER */
  3108.  
  3109. #ifndef NOICP
  3110.       case 'Y':            /* No initialization file */
  3111.         noinit = 1;
  3112.         break;
  3113.  
  3114.       case 'y':            /* Alternate init-file name */
  3115.         noinit = 0;
  3116.         if (*(xp+1)) {
  3117.         XFATAL("invalid argument bundling after -y");
  3118.         }
  3119.         xargv++, xargc--;
  3120.         if (xargc < 1) {
  3121.         XFATAL("missing filename in -y");
  3122.         }
  3123.         /* strcpy(kermrc,*xargv); ... already done in prescan()... */
  3124.         break;
  3125. #endif /* NOICP */
  3126.  
  3127. #ifndef NOXFER
  3128.       case 'I':            /* Assume we have an "Internet" */
  3129.         reliable = 1;        /* or other reliable connection */
  3130.         xreliable = 1;
  3131.         setreliable = 1;
  3132.  
  3133.         /* I'm not so sure about this -- what about VMS? (next comment) */
  3134.         clearrq = 1;        /* therefore the channel is clear */
  3135.  
  3136. #ifndef VMS
  3137. /*
  3138.   Since this can trigger full control-character unprefixing, we need to
  3139.   ensure that our terminal or pty driver is not doing Xon/Xoff; otherwise
  3140.   we can become deadlocked the first time we receive a file that contains
  3141.   Xoff.
  3142. */
  3143.         flow = FLO_NONE;
  3144. #endif /* VMS */
  3145.         break;
  3146. #endif /* NOXFER */
  3147.  
  3148. #ifndef NOLOCAL
  3149.       case 'l':            /* SET LINE */
  3150. #ifdef NETCONN
  3151. #ifdef ANYX25
  3152.       case 'X':            /* SET HOST to X.25 address */
  3153. #ifdef SUNX25
  3154.       case 'Z':            /* SET HOST to X.25 file descriptor */
  3155. #endif /* SUNX25 */
  3156. #endif /* ANYX25 */
  3157. #ifdef TCPSOCKET
  3158.       case 'J':
  3159.       case 'j':            /* SET HOST (TCP/IP socket) */
  3160. #endif /* TCPSOCKET */
  3161. #endif /* NETCONN */
  3162. #ifndef NOXFER
  3163.         if (x == 'j' || x == 'J' || x == 'X' || x == 'Z') {
  3164.         reliable = 1;        /* or other reliable connection */
  3165.         xreliable = 1;
  3166.         setreliable = 1;
  3167.         }
  3168. #endif /* NOXFER */
  3169.         network = 0;
  3170.         if (*(xp+1)) {
  3171.         XFATAL("invalid argument bundling after -l or -j");
  3172.         }
  3173.         xargv++, xargc--;
  3174.         if ((xargc < 1) || (**xargv == '-')) {
  3175.         XFATAL("communication line device name missing");
  3176.         }
  3177.  
  3178. #ifdef NETCONN
  3179.         if (x == 'J') {
  3180.         cflg    = 1;        /* Connect */
  3181.         stayflg = 1;        /* Stay */
  3182.         tn_exit = 1;        /* Telnet-like exit condition */
  3183.         exitonclose = 1;
  3184.         }
  3185. #endif /* NETCONN */
  3186.         ckstrncpy(ttname,*xargv,TTNAMLEN+1);
  3187.         local = (strcmp(ttname,CTTNAM) != 0);
  3188.         if (local && strcmp(ttname,"0") == 0)
  3189.           local = 0;
  3190. /*
  3191.   NOTE: We really do not need to call ttopen here, since it should be called
  3192.   again later, automatically, when we first try to condition the device via
  3193.   ttpkt or ttvt.  Calling ttopen here has the bad side effect of making the
  3194.   order of the -b and -l options significant, but order of command-line options
  3195.   should not matter.  However, the network cases immediately below complicate
  3196.   matters a bit, so we'll settle this in a future edit.
  3197. */
  3198.         if (x == 'l') {
  3199.         if (ttopen(ttname,&local,mdmtyp,0) < 0) {
  3200.             XFATAL("can't open device");
  3201.         }
  3202. #ifdef CKLOGDIAL
  3203.         dologline();
  3204. #endif /* CKLOGDIAL */
  3205.         debug(F101,"doarg speed","",speed);
  3206.         cxtype = (mdmtyp > 0) ? CXT_MODEM : CXT_DIRECT;
  3207.         speed = ttgspd();    /* Get the speed. */
  3208.         setflow();        /* Do something about flow control. */
  3209. #ifndef NOSPL
  3210.         if (local) {
  3211.             if (nmac) {        /* Any macros defined? */
  3212.             int k;        /* Yes */
  3213.             k = mlook(mactab,"on_open",nmac); /* Look this up */
  3214.             if (k >= 0) {    /* If found, */
  3215.                 if (dodo(k,ttname,0) > -1) /* set it up, */
  3216.                   parser(1); /* and execute it */
  3217.             }
  3218.             }
  3219.         }
  3220. #endif /* NOSPL */
  3221.  
  3222. #ifdef NETCONN
  3223.         } else {
  3224.         if (x == 'j' || x == 'J') { /* IP network host name */
  3225.             char * s = line;
  3226.             char * service = tmpbuf;
  3227.             if (xargc > 0) {    /* Check if it's followed by */
  3228.             /* A service name or number */
  3229.             if (*(xargv+1) && *(*(xargv+1)) != '-') {
  3230.                 xargv++, xargc--;
  3231.                 ckstrncat(ttname,":",TTNAMLEN+1);
  3232.                 ckstrncat(ttname,*xargv,TTNAMLEN+1);
  3233.             }
  3234.             }
  3235.             nettype = NET_TCPB;
  3236.             mdmtyp = -nettype;    /* Perhaps already set in init file */
  3237.             telnetfd = 1;    /* Or maybe an open file descriptor */
  3238.             ckstrncpy(line, ttname, YYBUFLEN); /* Working copy */
  3239.             for (s = line; *s != NUL && *s != ':'; s++);
  3240.             if (*s) {
  3241.             *s++ = NUL;
  3242.             ckstrncpy(service, s, YYBUFLEN);
  3243.             } else *service = NUL;
  3244.             s = line;
  3245. #ifndef NODIAL
  3246. #ifndef NOICP
  3247.             /* Look up in network directory */
  3248.             x = 0;
  3249.             if (*s == '=') {    /* If number starts with = sign */
  3250.             s++;        /* strip it */
  3251.             while (*s == SP) /* and also any leading spaces */
  3252.               s++;
  3253.             ckstrncpy(line,s,YYBUFLEN); /* Do this again. */
  3254.             nhcount = 0;
  3255.             } else if (!isdigit(line[0])) {
  3256. /*
  3257.   nnetdir will be greater than 0 if the init file has been processed and it
  3258.   contained a SET NETWORK DIRECTORY command.
  3259. */
  3260.             xx = 0;        /* Initialize this */
  3261.             if (nnetdir > 0) /* If there is a directory... */
  3262.               xx = lunet(line); /* Look up the name */
  3263.             else        /* If no directory */
  3264.               nhcount = 0;    /* we didn't find anything there */
  3265.             if (xx < 0) {    /* Lookup error: */
  3266.                 ckmakmsg(tmpbuf,
  3267.                      YYBUFLEN,
  3268.                     "?Fatal network directory lookup error - ",
  3269.                      line,
  3270.                      "\n",
  3271.                      NULL
  3272.                      );
  3273.                 XFATAL(tmpbuf);
  3274.             }
  3275.             }
  3276. #endif /* NOICP */
  3277. #endif /* NODIAL */
  3278.             /* Add service to line specification for ttopen() */
  3279.             if (*service) {    /* There is a service specified */
  3280.             ckstrncat(line, ":",LINBUFSIZ);
  3281.             ckstrncat(line, service,LINBUFSIZ);
  3282.             ttnproto = NP_DEFAULT;
  3283.             } else {
  3284.             ckstrncat(line, ":telnet",LINBUFSIZ);
  3285.             ttnproto = NP_TELNET;
  3286.             }
  3287.  
  3288. #ifndef NOICP
  3289. #ifndef NODIAL
  3290.             if ((nhcount > 1) && !quiet && !backgrd) {
  3291.             printf("%d entr%s found for \"%s\"%s\n",
  3292.                    nhcount,
  3293.                    (nhcount == 1) ? "y" : "ies",
  3294.                    s,
  3295.                    (nhcount > 0) ? ":" : "."
  3296.                    );
  3297.             for (i = 0; i < nhcount; i++)
  3298.               printf("%3d. %s %-12s => %s\n",
  3299.                  i+1, n_name, nh_p2[i], nh_p[i]
  3300.                  );
  3301.             }
  3302.             if (nhcount == 0)
  3303.               n = 1;
  3304.             else
  3305.               n = nhcount;
  3306. #else
  3307.             n = 1;
  3308.             nhcount = 0;
  3309. #endif /* NODIAL */
  3310.             for (i = 0; i < n; i++) {
  3311. #ifndef NODIAL
  3312.             if (nhcount >= 1) {
  3313.                 /* Copy the current entry to line */
  3314.                 ckstrncpy(line,nh_p[i],LINBUFSIZ);
  3315.                     /* Check to see if the network entry contains a service */
  3316.                 for (s = line ; (*s != NUL) && (*s != ':'); s++)
  3317.                   ;
  3318.                 /* If directory does not have a service ... */
  3319.                 /* and the user specified one */
  3320.                 if (!*s && *service) {
  3321.                 ckstrncat(line, ":",LINBUFSIZ);
  3322.                 ckstrncat(line, service,LINBUFSIZ);
  3323.                 }
  3324.                 if (lookup(netcmd,nh_p2[i],nnets,&z) > -1) {
  3325.                 mdmtyp = 0 - netcmd[z].kwval;
  3326.                 } else {
  3327.                 printf(
  3328.                  "Error - network type \"%s\" not supported\n",
  3329.                        nh_p2[i]
  3330.                        );
  3331.                 continue;
  3332.                 }
  3333.             }
  3334. #endif /* NODIAL */
  3335.             }
  3336. #endif /* NOICP */
  3337.             ckstrncpy(ttname, line,TTNAMLEN+1);
  3338.             cxtype = CXT_TCPIP;    /* Set connection type */
  3339.             setflow();        /* Set appropriate flow control. */
  3340. #ifdef SUNX25
  3341.         } else if (x == 'X') {    /* X.25 address */
  3342.             nettype = NET_SX25;
  3343.             mdmtyp = -nettype;
  3344.         } else if (x == 'Z') {    /* Open X.25 file descriptor */
  3345.             nettype = NET_SX25;
  3346.             mdmtyp = -nettype;
  3347.             x25fd = 1;
  3348. #endif /* SUNX25 */
  3349. #ifdef STRATUSX25
  3350.         } else if (x == 'X') {    /* X.25 address */
  3351.             nettype = NET_VX25;
  3352.             mdmtyp = -nettype;
  3353. #endif /* STRATUSX25 */
  3354. #ifdef IBMX25
  3355.         } else if (x == 'X') {    /* X.25 address */
  3356.             nettype = NET_IX25;
  3357.             mdmtyp = -nettype;
  3358. #endif /* IBMX25 */
  3359. #ifdef HPX25
  3360.         } else if (x == 'X') {    /* X.25 address */
  3361.             nettype = NET_HX25;
  3362.             mdmtyp = -nettype;
  3363. #endif /* HPX25 */
  3364.         }
  3365.         if (ttopen(ttname,&local,mdmtyp,0) < 0) {
  3366.             XFATAL("can't open host connection");
  3367.         }
  3368.         network = 1;
  3369. #ifdef CKLOGDIAL
  3370.         dolognet();
  3371. #endif /* CKLOGDIAL */
  3372.         cxtype = CXT_X25;    /* Set connection type */
  3373.         setflow();        /* Set appropriate flow control. */
  3374. #ifndef NOSPL
  3375.         if (local) {
  3376.             if (nmac) {        /* Any macros defined? */
  3377.             int k;        /* Yes */
  3378.             k = mlook(mactab,"on_open",nmac); /* Look this up */
  3379.             if (k >= 0) {    /* If found, */
  3380.                 if (dodo(k,ttname,0) > -1) /* set it up, */
  3381.                   parser(1);        /* and execute it */
  3382.             }
  3383.             }
  3384.         }
  3385. #endif /* NOSPL */
  3386. #endif /* NETCONN */
  3387.         }
  3388.         /* add more here -- decnet, etc... */
  3389.         haveline = 1;
  3390.         break;
  3391.  
  3392. #ifdef ANYX25
  3393.       case 'U':            /* X.25 call user data */
  3394.         if (*(xp+1)) {
  3395.         XFATAL("invalid argument bundling");
  3396.         }
  3397.         xargv++, xargc--;
  3398.         if ((xargc < 1) || (**xargv == '-')) {
  3399.         XFATAL("missing call user data string");
  3400.         }
  3401.         ckstrncpy(udata,*xargv,MAXCUDATA);
  3402.         if ((int)strlen(udata) <= MAXCUDATA) {
  3403.         cudata = 1;
  3404.         } else {
  3405.         XFATAL("Invalid call user data");
  3406.         }
  3407.         break;
  3408.  
  3409.       case 'o':            /* X.25 closed user group */
  3410.         if (*(xp+1)) {
  3411.         XFATAL("invalid argument bundling");
  3412.         }
  3413.         xargv++, xargc--;
  3414.         if ((xargc < 1) || (**xargv == '-')) {
  3415.         XFATAL("missing closed user group index");
  3416.         }
  3417.         z = atoi(*xargv);        /* Convert to number */
  3418.         if (z >= 0 && z <= 99) {
  3419.         closgr = z;
  3420.         } else {
  3421.         XFATAL("Invalid closed user group index");
  3422.         }
  3423.         break;
  3424.  
  3425.       case 'u':            /* X.25 reverse charge call */
  3426.         revcall = 1;
  3427.         break;
  3428. #endif /* ANYX25 */
  3429. #endif /* NOLOCAL */
  3430.  
  3431.       case 'b':            /* Bits-per-second for serial device */
  3432.         if (*(xp+1)) {
  3433.         XFATAL("invalid argument bundling");
  3434.         }
  3435.         xargv++, xargc--;
  3436.         if ((xargc < 1) || (**xargv == '-')) {
  3437.         XFATAL("missing bps");
  3438.         }
  3439.         zz = atol(*xargv);        /* Convert to long int */
  3440.         i = zz / 10L;
  3441. #ifndef NOLOCAL
  3442.         if (ttsspd(i) > -1)        /* Check and set it */
  3443. #endif /* NOLOCAL */
  3444.           speed = ttgspd();        /* and read it back. */
  3445. #ifndef NOLOCAL
  3446.         else {
  3447.         XFATAL("unsupported transmission rate");
  3448.         }
  3449. #endif /* NOLOCAL */
  3450.         break;
  3451.  
  3452. #ifndef NODIAL
  3453. #ifndef NOICP
  3454.       case 'm':            /* Modem type */
  3455.         if (*(xp+1)) {
  3456.         XFATAL("invalid argument bundling after -m");
  3457.         }
  3458.         xargv++, xargc--;
  3459.         if ((xargc < 1) || (**xargv == '-')) {
  3460.         XFATAL("modem type missing");
  3461.         }
  3462.         y = lookup(mdmtab,*xargv,nmdm,&z);
  3463.         if (y < 0) {
  3464.         XFATAL("unknown modem type");
  3465.         }
  3466.         usermdm = 0;
  3467.         usermdm = (y == dialudt) ? x : 0;
  3468.         initmdm(y);
  3469.         break;
  3470. #endif /* NOICP */
  3471. #endif /* NODIAL */
  3472.  
  3473. #ifndef NOXFER
  3474.       case 'e':            /* Extended packet length */
  3475.         if (*(xp+1)) {
  3476.         XFATAL("invalid argument bundling after -e");
  3477.         }
  3478.         xargv++, xargc--;
  3479.         if ((xargc < 1) || (**xargv == '-')) {
  3480.         XFATAL("missing length");
  3481.         }
  3482.         z = atoi(*xargv);        /* Convert to number */
  3483.         if (z > 10 && z <= maxrps) {
  3484.         rpsiz = urpsiz = z;
  3485.         if (z > 94) rpsiz = 94;    /* Fallback if other Kermit can't */
  3486.         } else {
  3487.         XFATAL("Unsupported packet length");
  3488.         }
  3489.         break;
  3490.  
  3491.       case 'v':            /* Vindow size */
  3492.         if (*(xp+1)) {
  3493.         XFATAL("invalid argument bundling");
  3494.         }
  3495.         xargv++, xargc--;
  3496.         if ((xargc < 1) || (**xargv == '-')) {
  3497.         XFATAL("missing or bad window size");
  3498.         }
  3499.         z = atoi(*xargv);        /* Convert to number */
  3500.         if (z < 32) {        /* If in range */
  3501.         wslotr = z;        /* set it */
  3502.         if (z > 1) swcapr = 1;    /* Set capas bit if windowing */
  3503.         } else {
  3504.         XFATAL("Unsupported packet length");
  3505.         }
  3506.         break;
  3507. #endif /* NOXFER */
  3508.  
  3509.       case 'i':            /* Treat files as binary */
  3510.         binary = XYFT_B;
  3511.         xfermode = XMODE_M;        /* Transfer mode manual */
  3512.         filepeek = 0;
  3513. #ifdef PATTERNS
  3514.         patterns = 0;
  3515. #endif /* PATTERNS */
  3516.         break;
  3517.  
  3518. #ifndef NOXFER
  3519.       case 'w':            /* Writeover */
  3520.         ckwarn = 0;
  3521.         fncact = XYFX_X;
  3522.         break;
  3523. #endif /* NOXFER */
  3524.  
  3525.       case 'q':            /* Quiet */
  3526.         quiet = 1;
  3527.         break;
  3528.  
  3529. #ifdef DEBUG
  3530.       case 'd':            /* DEBUG */
  3531.         break;            /* Handled in prescan() */
  3532. #endif /* DEBUG */
  3533.  
  3534.       case '0': {            /* In the middle */
  3535.           extern int tt_escape, lscapr;
  3536.           tt_escape = 0;        /* No escape character */
  3537.           flow = 0;            /* No Xon/Xoff (what about hwfc?) */
  3538. #ifndef NOXFER
  3539.           lscapr = 0;        /* No locking shifts */
  3540. #endif /* NOXFER */
  3541. #ifdef CK_APC
  3542.           {
  3543.           extern int apcstatus;    /* No APCs */
  3544.           apcstatus = APC_OFF;
  3545.           }
  3546. #endif /* CK_APC */
  3547. #ifdef CK_AUTODL
  3548.           {                /* No autodownload */
  3549.           extern int autodl;
  3550.           autodl = 0;
  3551.           }
  3552. #endif /* CK_AUTODL */
  3553. #ifndef NOCSETS
  3554.           {
  3555.           extern int tcsr, tcsl; /* No character-set translation */
  3556.           tcsr = 0;
  3557.           tcsl = tcsr;        /* Make these equal */
  3558.           }
  3559. #endif /* NOCSETS */
  3560. #ifdef TNCODE
  3561.           TELOPT_DEF_C_U_MODE(TELOPT_KERMIT) = TN_NG_RF;
  3562.           TELOPT_DEF_C_ME_MODE(TELOPT_KERMIT) = TN_NG_RF;
  3563.           TELOPT_DEF_S_U_MODE(TELOPT_KERMIT) = TN_NG_RF;
  3564.           TELOPT_DEF_S_ME_MODE(TELOPT_KERMIT) = TN_NG_RF;
  3565. #endif /* TNCODE */
  3566.       }
  3567. /* Fall thru... */
  3568.  
  3569.       case '8':            /* 8-bit clean */
  3570.         parity = 0;
  3571.         cmdmsk = 0xff;
  3572.         cmask = 0xff;
  3573.         break;
  3574.  
  3575.       case 'V': {
  3576.           extern int xfermode;
  3577. #ifdef PATTERNS
  3578.           extern int patterns;
  3579.           patterns = 0;        /* No patterns */
  3580. #endif /* PATTERNS */
  3581.           xfermode = XMODE_M;    /* Manual transfer mode */
  3582.           filepeek = 0;
  3583.           break;
  3584.       }
  3585.  
  3586.       case 'p':            /* SET PARITY */
  3587.         if (*(xp+1)) {
  3588.         XFATAL("invalid argument bundling");
  3589.         }
  3590.         xargv++, xargc--;
  3591.         if ((xargc < 1) || (**xargv == '-')) {
  3592.         XFATAL("missing parity");
  3593.         }
  3594.         switch(x = **xargv) {
  3595.           case 'e':
  3596.           case 'o':
  3597.           case 'm':
  3598.           case 's': parity = x; break;
  3599.           case 'n': parity = 0; break;
  3600.           default:  { XFATAL("invalid parity"); }
  3601.         }
  3602.         break;
  3603.  
  3604.       case 't':            /* Line turnaround handshake */
  3605.         turn = 1;
  3606.         turnch = XON;        /* XON is turnaround character */
  3607.         duplex = 1;            /* Half duplex */
  3608.         flow = 0;            /* No flow control */
  3609.         break;
  3610.  
  3611.       case 'B':
  3612.         bgset = 1;            /* Force background (batch) */
  3613.         backgrd = 1;
  3614.         break;
  3615.  
  3616.       case 'z':            /* Force foreground */
  3617.         bgset = 0;
  3618.         backgrd = 0;
  3619.         break;
  3620.  
  3621. #ifndef NOXFER
  3622. #ifdef RECURSIVE
  3623.       case 'L':
  3624.         recursive = 2;
  3625.         nolinks = 2;
  3626.         fnspath = PATH_REL;
  3627.         break;
  3628. #endif /* RECURSIVE */
  3629. #endif /* NOXFER */
  3630.  
  3631. #ifndef NOSPL
  3632.       case 'M':            /* My User Name */
  3633.         if (*(xp+1)) {
  3634.         XFATAL("invalid argument bundling");
  3635.         }
  3636.         xargv++, xargc--;
  3637.         if ((xargc < 1) || (**xargv == '-')) {
  3638.         XFATAL("missing username");
  3639.         }
  3640.         if ((int)strlen(*xargv) > 63) {
  3641.         XFATAL("username too long");
  3642.         }
  3643. #ifdef IKSD
  3644.         if (!inserver)
  3645. #endif /* IKSD */
  3646.           {
  3647.           ckstrncpy(uidbuf,*xargv,UIDBUFLEN);
  3648.           haveftpuid = 1;
  3649.           }
  3650.         break;
  3651. #endif /* NOSPL */
  3652.  
  3653. #ifdef CK_NETBIOS
  3654.       case 'N':            /* NetBios Adapter Number follows */
  3655.         if (*(xp+1)) {
  3656.         XFATAL("invalid argument bundling after -N");
  3657.         }
  3658.         xargv++, xargc--;
  3659.         if ((xargc < 1) || (**xargv == '-')) {
  3660.         XFATAL("missing NetBios Adapter number");
  3661.         }
  3662.         if ((strlen(*xargv) != 1) ||
  3663.         (*xargv)[0] != 'X' &&
  3664.         (atoi(*xargv) < 0) &&
  3665.         (atoi(*xargv) > 9)) {
  3666.         XFATAL("Invalid NetBios Adapter - Adapters 0 to 9 are valid");
  3667.         }
  3668.         break;
  3669. #endif /* CK_NETBIOS */
  3670.  
  3671. #ifdef NETCONN
  3672.       case 'F':
  3673.         network = 1;
  3674.         if (*(xp+1)) {
  3675.         XFATAL("invalid argument bundling after -F");
  3676.         }
  3677.         xargv++, xargc--;
  3678.         if ((xargc < 1) || (**xargv == '-')) {
  3679.         XFATAL("network file descriptor missing");
  3680.         }
  3681.         ckstrncpy(ttname,*xargv,TTNAMLEN+1);
  3682.         nettype = NET_TCPB;
  3683.         mdmtyp = -nettype;
  3684.         telnetfd = 1;
  3685.         local = 1;
  3686.         break;
  3687. #endif /* NETCONN */
  3688.  
  3689. #ifdef COMMENT
  3690. #ifdef OS2PM
  3691.       case 'P':            /* OS/2 Presentation Manager */
  3692.         if (*(xp+1)) {
  3693.         XFATAL("invalid argument bundling after -P");
  3694.         }
  3695.         xargv++, xargc--;
  3696.         if ((xargc < 1) || (**xargv == '-')) {
  3697.         XFATAL("pipe data missing");
  3698.         }
  3699.         pipedata = *xargv;
  3700.         break;
  3701. #endif /* OS2PM */
  3702. #else
  3703.       case 'P':            /* Filenames literal */
  3704.         fncnv  = XYFN_L;
  3705.         f_save = XYFN_L;
  3706.         break;
  3707. #endif /* COMMENT */
  3708.  
  3709. #ifndef NOICP
  3710.       case 'H':
  3711.         noherald = 1;
  3712.         break;
  3713. #endif /* NOICP */
  3714.  
  3715. #ifdef OS2
  3716.       case 'W':
  3717.         if (*(xp+1)) {
  3718.         XFATAL("invalid argument bundling after -W");
  3719.         }
  3720.         xargv++, xargc--;
  3721.         if ((xargc < 1)) { /* could be negative */
  3722.         XFATAL("Window handle missing");
  3723.         }
  3724.         xargv++, xargc--;
  3725.         if ((xargc < 1) || (**xargv == '-')) {
  3726.         XFATAL("Kermit Instance missing");
  3727.         }
  3728.         /* Action done in prescan */
  3729.         break;
  3730.  
  3731.       case '#':            /* K95 stdio threads */
  3732.         xargv++, xargc--;        /* Skip past argument */
  3733.         break;            /* Action done in prescan */
  3734. #endif /* OS2 */
  3735.  
  3736. #ifdef NEWFTP
  3737.       case '9':            /* FTP */
  3738.         if (*(xp+1)) {
  3739.         XFATAL("invalid argument bundling after -9");
  3740.         }
  3741.         xargv++, xargc--;
  3742.         if ((xargc < 1) || (**xargv == '-')) {
  3743.         XFATAL("FTP server address missing");
  3744.         }
  3745.         makestr(&ftp_host,*xargv);
  3746.         break;
  3747. #endif /* NEWFTP */
  3748.  
  3749.       default:
  3750.         fatal2(*xargv,
  3751. #ifdef NT
  3752.                    "invalid command-line option, type \"k95 -h\" for help"
  3753. #else
  3754. #ifdef OS2
  3755.                    "invalid command-line option, type \"k2 -h\" for help"
  3756. #else
  3757.                    "invalid command-line option, type \"kermit -h\" for help"
  3758. #endif /* OS2 */
  3759. #endif /* NT */
  3760.            );
  3761.         }
  3762.     if (!xp) break;
  3763.     x = *++xp;            /* See if options are bundled */
  3764.     }
  3765.     return(0);
  3766. }
  3767.  
  3768. #ifdef TNCODE
  3769. /*  D O T N A R G  --  Do a telnet command-line argument.  */
  3770.  
  3771. static int
  3772. #ifdef CK_ANSIC
  3773. dotnarg(char x)
  3774. #else
  3775. dotnarg(x) char x;
  3776. #endif /* CK_ANSIC */
  3777. /* dotnarg */ {
  3778.     char *xp;
  3779.  
  3780.     xp = *xargv+1;                      /* Pointer for bundled args */
  3781.     debug(F111,"doarg entry",xp,xargc);
  3782.     while (x) {
  3783.         debug(F000,"doarg arg","",x);
  3784.         switch (x) {                    /* Big switch on arg */
  3785.  
  3786.       case '-':
  3787.       case '+':
  3788.         XFATAL("Extended options not configured");
  3789.  
  3790. /*
  3791.  * -8                Negotiate Telnet Binary in both directions
  3792.  * -a                Require use of Telnet authentication
  3793.  * -c                Do not read the .telnetrc file
  3794.  * -d                Turn on debug mode
  3795.  * -E                No escape character
  3796.  * -K                Refuse use of authentication; do not send username
  3797.  * -l user           Set username and request Telnet authentication
  3798.  * -L                Negotiate Telnet Binary Output only
  3799.  * -S tos            Use the IP type-of-service tos
  3800.  * -x                Require Encryption
  3801.  * -D                Disable forward-X
  3802.  * -T cert=file      Use certificate in file
  3803.  * -T key=file       Use private key in file
  3804.  * -T crlfile=file   Use CRL in file
  3805.  * -T crldir=dir     Use CRLs in directory
  3806.  * -T cipher=string  Use only ciphers in string
  3807.  * -X atype          Disable use of atype authentication
  3808.  * -f                Forward credentials to host
  3809.  * -k realm          Set default realm
  3810.  *
  3811.  */
  3812.       case 'h':            /* help */
  3813.         usage();
  3814.         doexit(GOOD_EXIT,-1);
  3815.         break;
  3816.  
  3817.       case '8':            /* Telnet Binary in both directions */
  3818.         TELOPT_DEF_C_U_MODE(TELOPT_BINARY) = TN_NG_MU;
  3819.         TELOPT_DEF_C_ME_MODE(TELOPT_BINARY) = TN_NG_MU;
  3820.         parity = 0;
  3821.         cmdmsk = 0xff;
  3822.         cmask = 0xff;
  3823.         break;
  3824.  
  3825.       case 'a':            /* Require Telnet Auth */
  3826.         TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  3827.         break;
  3828.  
  3829.       case 'd':
  3830. #ifdef DEBUG
  3831.         if (!deblog) {
  3832.         /* extern int debtim; */
  3833.         deblog = debopn("debug.log",0);
  3834.         /* debtim = 1; */
  3835.         }
  3836. #endif /* DEBUG */
  3837.         break;
  3838.  
  3839.       case 'E': {            /* No Escape character */
  3840.           extern int tt_escape;
  3841.           tt_escape = 0;
  3842.       }
  3843.         break;
  3844.  
  3845.       case 'K':
  3846.         TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_RF;
  3847.         uidbuf[0] = NUL;
  3848.         break;
  3849.  
  3850.       case 'l': /* Set username and request telnet authentication */
  3851.         if (*(xp+1)) {
  3852.         XFATAL("invalid argument bundling");
  3853.         }
  3854.         xargv++, xargc--;
  3855.         if ((xargc < 1) || (**xargv == '-')) {
  3856.         XFATAL("missing username");
  3857.         }
  3858.         if ((int)strlen(*xargv) > 63) {
  3859.         XFATAL("username too long");
  3860.         }
  3861.         ckstrncpy(uidbuf,*xargv,UIDBUFLEN);
  3862.         TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  3863.         break;
  3864.  
  3865.       case 'L':            /* Require BINARY mode outbound only */
  3866.         TELOPT_DEF_C_ME_MODE(TELOPT_BINARY) = TN_NG_MU;
  3867.         break;
  3868.  
  3869.       case 'x':            /* Require Encryption */
  3870.         TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION) = TN_NG_MU;
  3871.         TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_MU;
  3872.         break;
  3873.  
  3874.       case 'D':            /* Disable use of Forward X */
  3875.         TELOPT_DEF_C_U_MODE(TELOPT_FORWARD_X) = TN_NG_RF;
  3876.         break;
  3877.  
  3878.       case 'f':            /* Forward credentials to host */
  3879.         {
  3880. #ifdef CK_AUTHENTICATION
  3881.         extern int forward_flag;
  3882.         forward_flag = 1;
  3883. #endif
  3884.         break;
  3885.         }
  3886.  
  3887.       case 'k': {
  3888. #ifdef CK_KERBEROS
  3889.           extern char * krb5_d_realm, * krb4_d_realm;
  3890. #endif /* CK_KERBEROS */
  3891.           if (*(xp+1)) {
  3892.           XFATAL("invalid argument bundling");
  3893.           }
  3894.           xargv++, xargc--;
  3895.           if ((xargc < 1) || (**xargv == '-')) {
  3896.           XFATAL("missing realm");
  3897.           }
  3898. #ifdef CK_KERBEROS
  3899.           if ((int)strlen(*xargv) > 63) {
  3900.           XFATAL("realm too long");
  3901.           }
  3902.           makestr(&krb5_d_realm,*xargv);
  3903.           makestr(&krb4_d_realm,*xargv);
  3904. #endif /* CK_KERBEROS */
  3905.           break;
  3906.       }
  3907.  
  3908.       case 'T': {
  3909.           if (*(xp+1)) {
  3910.           XFATAL("invalid argument bundling");
  3911.           }
  3912.           xargv++, xargc--;
  3913.           if ((xargc < 1) || (**xargv == '-')) {
  3914.           XFATAL("missing cert=, key=, crlfile=, crldir=, or cipher=");
  3915.           }
  3916. #ifdef CK_SSL
  3917.           if (!strncmp(*xargv,"cert=",5)) {
  3918.           extern char * ssl_rsa_cert_file;
  3919.           makestr(&ssl_rsa_cert_file,&(*xargv[5]));
  3920.           } else if ( !strncmp(*xargv,"key=",4) ) {
  3921.           extern char * ssl_rsa_key_file;
  3922.           makestr(&ssl_rsa_key_file,&(*xargv[4]));
  3923.           } else if ( !strncmp(*xargv,"crlfile=",8) ) {
  3924.           extern char * ssl_crl_file;
  3925.           makestr(&ssl_crl_file,&(*xargv[8]));
  3926.           } else if ( !strncmp(*xargv,"crldir=",7) ) {
  3927.           extern char * ssl_crl_dir;
  3928.           makestr(&ssl_crl_dir,&(*xargv[7]));
  3929.           } else if ( !strncmp(*xargv,"cipher=",7) ) {
  3930.           extern char * ssl_cipher_list;
  3931.           makestr(&ssl_cipher_list,&(*xargv[7]));
  3932.           } else {
  3933.           XFATAL("invalid parameter");
  3934.           }
  3935. #endif /* CK_SSL */
  3936.           break;
  3937.       }
  3938.  
  3939.       default:
  3940.         fatal2(*xargv,
  3941.            "invalid command-line option, type \"telnet -h\" for help"
  3942.            );
  3943.         }
  3944.  
  3945.     if (!xp) break;
  3946.     x = *++xp;            /* See if options are bundled */
  3947.     }
  3948.     return(0);
  3949. }
  3950. #endif /* TNCODE */
  3951. #else /* No command-line interface... */
  3952.  
  3953. extern int xargc;
  3954. int
  3955. cmdlin() {
  3956.     if (xargc > 1) {
  3957.         XFATAL("Sorry, command-line options disabled.");
  3958.     }
  3959. }
  3960. #endif /* NOCMDL */
  3961.