home *** CD-ROM | disk | FTP | other *** search
/ kermit.columbia.edu / kermit.columbia.edu.tar / kermit.columbia.edu / test / tar / x30.tar.gz / x30.tar / ckuusr.c < prev    next >
C/C++ Source or Header  |  2010-04-02  |  355KB  |  13,315 lines

  1. #ifdef SSHTEST
  2. #define SSHBUILTIN
  3. #endif /* SSHTEST */
  4.  
  5. #include "ckcsym.h"
  6. char *userv = "User Interface 9.0.299, 2 April 2010";
  7.  
  8. /*  C K U U S R --  "User Interface" for C-Kermit (Part 1)  */
  9.  
  10. /*
  11.   Authors:
  12.     Frank da Cruz <fdc@columbia.edu>,
  13.       The Kermit Project, Columbia University, New York City
  14.     Jeffrey E Altman <jaltman@secure-endpoints.com>
  15.       Secure Endpoints Inc., New York City
  16.  
  17.   Copyright (C) 1985, 2010,
  18.     Trustees of Columbia University in the City of New York.
  19.     All rights reserved.  See the C-Kermit COPYING.TXT file or the
  20.     copyright text in the ckcmai.c module for disclaimer and permissions.
  21. */
  22.  
  23. /*
  24.   Originally the entire user interface was in one module, ckuusr.c.  Over
  25.   the years it has been split into many modules: ckuus2.c, ckuus3.c, ...,
  26.   ckuus7.c.  ckuus2.c contains the HELP command parser and help-text strings;
  27.   ckuusy.c contains the UNIX-style command-line interface; ckuusx.c contains
  28.   routines needed by both the command-line interface and the interactive
  29.   command parser.
  30. */
  31.  
  32. /*
  33.   The ckuus*.c modules depend on the existence of C library features like
  34.   fopen, fgets, feof, (f)printf, argv/argc, etc.  Other functions that are
  35.   likely to vary among different platforms -- like setting terminal modes or
  36.   interrupts -- are invoked via calls to functions that are defined in the
  37.   system- dependent modules, ck?[ft]io.c.  The command line parser processes
  38.   any arguments found on the command line, as passed to main() via argv/argc.
  39.   The interactive parser uses the facilities of the cmd package (developed for
  40.   this program, but usable by any program).  Any command parser may be
  41.   substituted for this one.  The only requirements for the Kermit command
  42.   parser are these:
  43.  
  44.   . Set parameters via global variables like duplex, speed, ttname, etc.  See
  45.     ckmain.c for the declarations and descriptions of these variables.
  46.  
  47.   . If a command can be executed without the use of Kermit protocol, then
  48.     execute the command directly and set the variable sstate to 0. Examples
  49.     include 'set' commands, local directory listings, the 'connect' command.
  50.  
  51.   . If a command requires the Kermit protocol, set the following variables:
  52.  
  53.      sstate                             string data
  54.        'x' (enter server mode)            (none)
  55.        'r' (send a 'get' command)         cmarg, cmarg2
  56.        'v' (enter receive mode)           cmarg2
  57.        'g' (send a generic command)       cmarg
  58.        's' (send files)                   nfils, cmarg & cmarg2 OR cmlist
  59.        'c' (send a remote host command)   cmarg
  60.  
  61.      cmlist is an array of pointers to strings.
  62.      cmarg, cmarg2 are pointers to strings.
  63.      nfils is an integer.
  64.  
  65.      cmarg can be a filename string (possibly wild), or
  66.     a pointer to a prefabricated generic command string, or
  67.     a pointer to a host command string.
  68.      cmarg2 is an "as-name" - the name to send file(s) under, or
  69.     the name under which to store incoming file(s); must not be wild.
  70.     A null or empty value means to use the file's own name.
  71.      cmlist is a list of filenames, such as passed via argv.
  72.      nfils is an integer, interpreted as follows:
  73.        -1: filespec (possibly wild) in cmarg, must be expanded internally.
  74.     0: send from stdin (standard input).
  75.        >0: number of files to send, from cmlist.
  76.  
  77.   The screen() function is used to update the screen during file transfer.
  78.   The tlog() function writes to a transaction log.
  79.   The debug() function writes to a debugging log.
  80.   The intmsg() and chkint() functions provide the user i/o for interrupting
  81.     file transfers.
  82. */
  83.  
  84. /* Includes */
  85.  
  86. #ifdef MULTINET
  87. #define MULTINET_OLD_STYLE        /* Leave select prototype undefined */
  88. #endif /* MULTINET */
  89.  
  90. #include "ckcdeb.h"
  91. #include "ckcasc.h"
  92. #include "ckcker.h"
  93. #include "ckcnet.h"            /* Network symbols */
  94. #include "ckuusr.h"
  95. #include "ckcxla.h"
  96.  
  97. int g_fncact = -1;            /* Needed for NOICP builds */
  98. int noinit = 0;                /* Flag for skipping init file */
  99. int nscanfile = SCANFILEBUF;
  100.  
  101. int rcdactive = 0;            /* RCD active */
  102. int keepallchars = 0;            /* See cmfld() */
  103.  
  104. int locus = 1;                /* Current LOCUS is LOCAL */
  105. #ifdef OS2
  106. int autolocus = 2;            /* Automatic LOCUS switching: ASK */
  107. #else /* OS2 */
  108. int autolocus = 1;            /* Automatic LOCUS switching enabled */
  109. #endif /* OS2 */
  110.  
  111. #ifndef NOICP
  112. #ifdef CKLEARN
  113. #ifdef VMS
  114. #include <time.h>            /* For CKLEARN */
  115. #endif /* VMS */
  116. #endif /* CKLEARN */
  117. #ifdef OS2
  118. #ifndef NT
  119. #define INCL_NOPM
  120. #define INCL_VIO            /* Needed for ckocon.h */
  121. #include <os2.h>
  122. #undef COMMENT
  123. #else
  124. #define APIRET ULONG
  125. #include <windows.h>
  126. #include <tapi.h>
  127. #include "cknwin.h"
  128. #include "ckntap.h"            /* CK_TAPI definition */
  129. #endif /* NT */
  130. #include "ckowin.h"
  131. #include "ckocon.h"
  132. extern int tcp_avail;
  133. extern bool viewonly;
  134. extern int k95stdout;
  135. extern int tt_scroll;
  136. #ifndef NOTERM
  137. extern tt_status[VNUM];
  138. #endif /* NOTERM */
  139. int display_demo = 1;
  140. #include "ckossh.h"
  141. #ifdef KUI
  142. #include "ikui.h"
  143. #endif /* KUI */
  144. #endif /* OS2 */
  145.  
  146. int optlines = 0;
  147. int didsetlin = 0;
  148.  
  149. #ifdef NEWFTP
  150. extern int ftpget, ftpisopen(), doftpres();
  151. _PROTOTYP(int doftptyp,(int));
  152. _PROTOTYP(VOID doftpglobaltype,(int));
  153. #endif /* NEWFTP */
  154.  
  155. #ifdef VMS
  156. extern int batch;
  157. #endif /* VMS */
  158.  
  159. #ifdef datageneral
  160. #include <packets:common.h>
  161. #define fgets(stringbuf,max,fd) dg_fgets(stringbuf,max,fd)
  162. #endif /* datageneral */
  163.  
  164. extern int xcmdsrc, hints, cmflgs, whyclosed;
  165.  
  166. char * hlptok = NULL;
  167.  
  168. #ifdef CK_TTGWSIZ            /* Whether to use more-prompting */
  169. int xaskmore = 1;            /* Momentary setting */
  170. int saveask  = 1;            /* Permanent setting */
  171. #else
  172. int xaskmore = 0;
  173. int saveask  = 0;
  174. #endif /* CK_TTGWSIZ */
  175.  
  176. #ifndef NOCSETS
  177. extern int nfilc;
  178. extern struct keytab fcstab[];
  179. extern int fcharset;
  180. #endif /* NOCSETS */
  181.  
  182. char * g_pswd = NULL;
  183. int g_pcpt = -1;
  184. int g_pflg = -1;
  185.  
  186. extern int cmd_rows, cmd_cols;
  187.  
  188. #ifdef CKROOT
  189. extern int ckrooterr;
  190. #endif /* CKROOT */
  191.  
  192. extern int inserver, filepeek;
  193.  
  194. #ifdef CKLEARN
  195. FILE * learnfp = NULL;
  196. char * learnfile = NULL;
  197. int learning = 0;
  198. #endif /* CKLEARN */
  199.  
  200. #ifndef NOXFER
  201. extern int atcapr, atdiso, nfils, moving, protocol, sendmode, epktflg, size,
  202.   sndsrc, server, displa, fncnv, fnspath, fnrpath, xfermode, urpsiz,
  203.   spsizf, spsiz, spsizr, spmax, wslotr, prefixing, fncact, reliable,
  204.   setreliable;
  205.  
  206. #ifdef IKSDCONF
  207. extern int iksdcf;
  208. #endif /* IKSDCONF */
  209.  
  210. #ifdef CK_LOGIN
  211. extern int isguest;
  212. #endif /* CK_LOGIN */
  213.  
  214. extern CK_OFF_T sendstart;
  215.  
  216. extern char *cmarg, *cmarg2, **cmlist, *dftty;
  217.  
  218. extern struct keytab fntab[]; extern int nfntab;
  219. extern struct ck_p ptab[NPROTOS];
  220.  
  221. int sndcmd = 0;        /* Last command was a SEND-class command. */
  222.  
  223. int g_xfermode = -1;
  224. int g_proto  = -1;
  225. int g_urpsiz = -1;
  226. int g_spsizf = -1;
  227. int g_spsiz  = -1;
  228. int g_spsizr = -1;
  229. int g_spmax  = -1;
  230. int g_wslotr = -1;
  231. int g_prefixing = -1;
  232. int g_fncnv  = -1;
  233. int g_fnspath = -1;
  234. int g_fnrpath = -1;
  235. int g_fnact  = -1;
  236. int g_displa = -1;
  237. int g_spath  = -1;
  238. int g_rpath  = -1;
  239. char * g_sfilter = NULL;
  240. char * g_rfilter = NULL;
  241.  
  242. extern int patterns;
  243. #ifdef PATTERNS
  244. extern char *txtpatterns[], *binpatterns[];
  245. int g_patterns = -1;
  246. #endif /* PATTERNS */
  247. int g_skipbup = -1;
  248.  
  249. #ifdef PIPESEND
  250. extern int usepipes, pipesend;
  251. extern char * sndfilter;
  252. #endif /* PIPESEND */
  253.  
  254. #ifndef NOSPL
  255. extern int sndxlo, sndxhi, sndxin;
  256. #endif /* NOSPL */
  257.  
  258. extern char fspec[];            /* Most recent filespec */
  259. extern int fspeclen;            /* Length of fspec[] buffer */
  260.  
  261. #ifndef NOFRILLS
  262. extern int rmailf;            /* MAIL command items */
  263. extern char optbuf[];
  264. #endif /* NOFRILLS */
  265.  
  266. extern int
  267.   en_cpy, en_cwd, en_del, en_dir, en_fin, en_get, en_bye, en_mai, en_pri,
  268.   en_hos, en_ren, en_sen, en_spa, en_set, en_typ, en_who, en_ret, en_xit,
  269.   en_mkd, en_rmd, en_asg;
  270.  
  271. #ifndef NOMSEND                /* Multiple SEND */
  272. extern char *msfiles[];
  273. int filesinlist = 0;            /* And ADD ... */
  274. extern struct filelist * filehead;
  275. extern struct filelist * filetail;
  276. extern struct filelist * filenext;
  277. extern int addlist;
  278. #endif /* NOMSEND */
  279.  
  280. static struct keytab addtab[] = {
  281. #ifdef PATTERNS
  282.     { "binary-patterns", ADD_BIN, 0 },
  283. #endif /* PATTERNS */
  284. #ifndef NOMSEND
  285.     { "send-list", ADD_SND, 0 },
  286. #endif /* NOMSEND */
  287. #ifdef PATTERNS
  288.     { "text-patterns", ADD_TXT, 0 },
  289. #endif /* PATTERNS */
  290.     { "", 0, 0 }
  291. };
  292. static int naddtab = sizeof(addtab)/sizeof(struct keytab) - 1;
  293.  
  294. #ifndef NOCSETS
  295. struct keytab assoctab[] = {
  296.     { "file-character-set",     ASSOC_FC, 0 },
  297.     { "transfer-character-set", ASSOC_TC, 0 },
  298.     { "xfer-character-set",     ASSOC_TC, CM_INV }
  299. };
  300. static int nassoc = sizeof(assoctab)/sizeof(struct keytab);
  301. extern int afcset[MAXFCSETS+1];        /* Character-set associations */
  302. extern int axcset[MAXTCSETS+1];
  303. #endif /* NOCSETS */
  304.  
  305. #ifndef ADDCMD
  306. #ifndef NOMSEND
  307. #define ADDCMD
  308. #endif /* NOMSEND */
  309. #ifndef ADDCMD
  310. #ifdef PATTERNS
  311. #define ADDCMD
  312. #endif /* PATTERNS */
  313. #endif /* ADDCMD */
  314. #endif /* ADDCMD */
  315. #endif /* NOXFER */
  316.  
  317. /* External Kermit Variables, see ckmain.c for description. */
  318.  
  319. extern xx_strp xxstring;
  320. extern long xvernum;
  321.  
  322. extern int local, xitsta, binary, msgflg, escape, duplex, quiet, tlevel,
  323.   pflag, zincnt, ckxech, carrier, what, nopush, haveline, bye_active;
  324. #ifdef TNCODE
  325. extern int debses;
  326. extern char tn_msg[];
  327. #endif /* TNCODE */
  328.  
  329. int sleepcan = 1;
  330. int g_binary = -1;
  331. int g_recursive = -1;
  332. int g_matchdot = -1;
  333. extern int nolinks;
  334.  
  335. extern long vernum;
  336. extern char *versio, *copyright[];
  337. extern char *ckxsys;
  338. #ifndef NOHELP
  339. extern char *introtxt[];
  340. extern char *newstxt[];
  341. #endif /* NOHELP */
  342.  
  343. #ifndef OS2
  344. #ifndef UNIX
  345. extern char *PWDCMD;
  346. #endif /* UNIX */
  347. extern char *WHOCMD;
  348. #endif /* OS2 */
  349.  
  350. extern char ttname[];
  351.  
  352. extern CHAR sstate;
  353.  
  354. extern int network;            /* Have active network connection */
  355. extern int nettype;            /* Type of network */
  356. extern int ttnproto;                    /* NET_TCPB protocol */
  357.  
  358. #ifndef NODIAL
  359. extern int dialsta, dialatmo, dialcon, dialcq; /* DIAL status, etc. */
  360. #endif /* NODIAL */
  361.  
  362. #ifdef CK_APC
  363. extern int apcactive, apcstatus;
  364. #endif /* CK_APC */
  365.  
  366. #ifndef NOPUSH
  367. #ifndef NOFRILLS
  368. extern char editor[];
  369. extern char editopts[];
  370. extern char editfile[];
  371. #endif /* NOFRILLS */
  372. #endif /* NOPUSH */
  373.  
  374. #ifdef BROWSER
  375. extern char browser[];            /* Web browser application */
  376. extern char browsopts[];        /* Web browser options */
  377. extern char browsurl[];            /* Most recent URL */
  378. #endif /* BROWSER */
  379. #ifndef NOFTP
  380. char ftpapp[CKMAXPATH+1] = { NUL, NUL }; /* ftp executable */
  381. char ftpopts[128] = { NUL, NUL };    /* ftp command-line options */
  382. #endif /* NOFTP */
  383. extern struct keytab onoff[];        /* On/Off keyword table */
  384.  
  385. #ifdef CK_TMPDIR
  386. int f_tmpdir = 0;            /* Directory changed temporarily */
  387. char savdir[TMPDIRLEN];            /* For saving current directory */
  388. #endif /* CK_TMPDIR */
  389.  
  390. int activecmd = -1;            /* Keyword index of active command */
  391. int doconx = -1;            /* CONNECT-class command active */
  392. int ooflag = 0;                /* User-settable on/off flag */
  393.  
  394. int rcflag = 0;                /* Pointer to home directory string */
  395. int repars,                /* Reparse needed */
  396.     techo = 0;                /* Take echo */
  397. int secho = 1;                /* SCRIPT echo */
  398.  
  399. int xitwarn =            /* Warn about open connection on exit */
  400. #ifdef NOWARN
  401. 0
  402. #else
  403. 1
  404. #endif /* NOWARN */
  405. ;
  406.  
  407. struct keytab onoffsw[] = {
  408.     { "/off", 0, 0 },
  409.     { "/on",  1, 0 }
  410. };
  411.  
  412. #ifdef CKEXEC
  413. struct keytab redirsw[] = {
  414.     { "/redirect", 1, 0 }
  415. };
  416. #endif /* CKEXEC */
  417.  
  418. #ifndef NOXMIT
  419. /* Variables for TRANSMIT command */
  420.  
  421. int xmitx = 1;            /* Whether to echo during TRANSMIT */
  422. int xmitf = 0;            /* Character to fill empty lines */
  423. int xmitl = 0;            /* 0 = Don't send linefeed too */
  424. int xmitp = LF;            /* Host line prompt */
  425. int xmits = 0;            /* Use shift-in/shift-out, 0 = no */
  426. int xmitw = 0;            /* Milliseconds to pause during TRANSMIT */
  427. int xmitt = 1;            /* Seconds to wait for each char to echo */
  428. int xmita = 1;            /* Action upon timeout */
  429.  
  430. #define XMI_BIN 1
  431. #define XMI_TXT 2
  432. #define XMI_CMD 3
  433. #define XMI_TRA 4
  434. #define XMI_VRB 5
  435. #define XMI_QUI 6
  436. #define XMI_NOW 7
  437. #define XMI_NOE 8
  438.  
  439. static struct keytab xmitsw[] = {    /* TRANSMIT command options */
  440.     { "/binary",          XMI_BIN, 0 },
  441. #ifdef PIPESEND
  442.     { "/command",         XMI_CMD, CM_INV|CM_PSH },
  443. #endif /* PIPESEND */
  444.     { "/noecho",          XMI_NOE, 0 },
  445.     { "/nowait",          XMI_NOW, 0 },
  446. #ifdef PIPESEND
  447.     { "/pipe",            XMI_CMD, 0 },
  448. #endif /* PIPESEND */
  449. #ifdef COMMENT
  450.     { "/quiet",           XMI_QUI, 0 },
  451. #endif /* COMMENT */
  452.     { "/text",            XMI_TXT, 0 },
  453.     { "/transparent",     XMI_TRA, 0 },
  454. #ifdef COMMENT
  455.     { "/verbose",         XMI_VRB, 0 },
  456. #endif /* COMMENT */
  457.     { "", 0, 0 }
  458. };
  459. #define NXMITSW sizeof(xmitsw)/sizeof(struct keytab) - 1
  460. static int nxmitsw = NXMITSW;
  461.  
  462. #endif /* NOXMIT */
  463.  
  464. /* Declarations from ck?fio.c module */
  465.  
  466. extern char *SPACMD, *SPACM2;        /* SPACE commands */
  467.  
  468. /* Command-oriented items */
  469.  
  470. #ifdef DCMDBUF
  471. extern char *cmdbuf;            /* Command buffers */
  472. extern char *atmbuf;
  473. extern char *line;            /* Character buffer for anything */
  474. extern char *tmpbuf;            /* Short temporary string buffer */
  475. extern int *ifcmd;
  476. extern int *intime;
  477. extern int *inpcas;
  478. #else
  479. extern char cmdbuf[];            /* Command buffers */
  480. extern char atmbuf[];
  481. extern char line[];            /* Character buffer for anything */
  482. extern char tmpbuf[];            /* Temporary buffer */
  483. extern int ifcmd[];
  484. extern int intime[];
  485. extern int inpcas[];
  486. #endif /* DCMDBUF */
  487.  
  488. #ifndef NOSPL
  489. extern char * prstring[];
  490. #endif /* NOSPL */
  491.  
  492. char *lp;                /* Pointer to line buffer */
  493.  
  494. #ifndef NOSPL
  495. int vareval = 1;            /* Evaluation method */
  496. int unkmacro = 0;            /* Flag for in ON_UNKNOWN_COMMAND */
  497. int oldeval = 0;
  498. char evalbuf[33];            /* EVALUATE result */
  499. extern char * inpbuf;            /* Buffer for INPUT and REINPUT */
  500. char *inpbp;                /* And pointer to same */
  501. int m_found;                /* MINPUT result */
  502. int i_active = 0;            /* INPUT command is active */
  503. char *ms[MINPMAX];            /* Pointers to MINPUT strings */
  504. static int mpinited = 0;        /* Flag they have been initialized */
  505. static int mp[MINPMAX];            /* and MINPUT flags */
  506. extern int fndiags, fnerror, fnsuccess;    /* Function diagnostics */
  507. #ifndef NOSEXP
  508. char * lastsexp = NULL;            /* S-Expressions */
  509. char * sexpval = NULL;
  510. int sexpecho = SET_AUTO;
  511. #endif /* NOSEXP */
  512. #endif /* NOSPL */
  513.  
  514. char psave[PROMPTL] = { NUL };        /* For saving & restoring prompt */
  515.  
  516. extern int success;            /* Command success/failure flag */
  517. extern int cmdlvl;            /* Current position in command stack */
  518.  
  519. #ifndef NOSPL
  520. int                    /* SET INPUT parameters. */
  521. /* Note, INPUT TIMEOUT, intime[], is on the command-level stack. */
  522.   inbufsize = 0,            /* INPUT buffer size */
  523.   indef = 1,                /* default timeout, seconds */
  524.   inecho = 1,                /* 1 = echo on */
  525.   inautodl = 0,                /* INPUT autodownload */
  526.   inintr = 1,                /* INPUT interrupion allowed */
  527.   insilence = 0;            /* 0 = no silence constraint */
  528.  
  529. #ifdef CKFLOAT
  530. CKFLOAT inscale = 1.0;            /* Timeout scale factor */
  531. #endif    /* CKFLOAT */
  532.  
  533. #ifdef OS2
  534. int interm = 1;                /* Terminal emulator displays input */
  535. #endif /* OS2 */
  536. int maclvl = -1;            /* Macro nesting level */
  537. int mecho = 0;                /* Macro echo, 0 = don't */
  538. char varnam[6];                /* For variable names */
  539. extern int macargc[];            /* ARGC from macro invocation */
  540.  
  541. extern char *m_arg[MACLEVEL][NARGS];    /* Stack of macro arguments */
  542. extern char *mrval[];
  543.  
  544. extern char **a_ptr[];            /* Array pointers */
  545. extern int a_dim[];            /* Array dimensions */
  546. extern int a_link[];
  547.  
  548. #ifdef DCMDBUF
  549. extern struct cmdptr *cmdstk;        /* The command stack itself */
  550. #else
  551. extern struct cmdptr cmdstk[];        /* The command stack itself */
  552. #endif /* DCMDBUF */
  553.  
  554. long ck_alarm = 0;            /* SET ALARM value */
  555. char alrm_date[24] = { ' ',' ',' ',' ',' ',' ',' ',' ',' ' };
  556. char alrm_time[24] = { ' ',' ',' ',' ',' ',' ',' ' };
  557.  
  558. struct keytab inputsw[] = {
  559.     { "/clear",   INPSW_CLR, 0 },
  560.     { "/count",   INPSW_COU, CM_ARG },
  561.     { "/nomatch", INPSW_NOM, 0 },
  562.     { "/nowrap",  INPSW_NOW, 0 }
  563. };
  564. static int ninputsw = sizeof(inputsw)/sizeof(struct keytab);
  565.  
  566. /* The following should be reconciled with the above */
  567.  
  568. #ifdef COMMENT                /* INPUT switches not used yet... */
  569. static struct keytab inswtab[] = {
  570. #ifdef COMMENT
  571.     { "/assign",       IN_ASG, CM_ARG },
  572. #endif /* COMMENT */
  573.     { "/autodownload", IN_ADL, CM_ARG },
  574.     { "/case",         IN_CAS, CM_ARG },
  575.     { "/echo",         IN_ECH, CM_ARG },
  576.     { "/interrupts",   IN_NOI, CM_ARG },
  577.     { "/silence",      IN_SIL, CM_ARG },
  578. #ifdef COMMENT
  579.     { "/pattern",      IN_PAT, CM_ARG },
  580. #endif /* COMMENT */
  581.     { "", 0, 0 }
  582. };
  583. static int ninswtab = (sizeof(inswtab) / sizeof(struct keytab)) - 1;
  584. #endif /* COMMENT */
  585.  
  586.  
  587. #endif /* NOSPL */
  588.  
  589. static int x, y, z = 0;            /* Local workers */
  590. static char *s;
  591.  
  592. #ifdef CK_MINPUT
  593. static char c1chars[] = {        /* C1 control chars escept NUL */
  594.     001,002,003,004,005,006,007,010,011,012,013,014,015,016,017,020,
  595.     021,022,023,024,025,026,027,030,031,032,033,034,035,036,037
  596. };
  597. #endif /* CK_MINPUT */
  598.  
  599. #define xsystem(s) zsyscmd(s)
  600.  
  601. /* Top-Level Interactive Command Keyword Table */
  602. /* Keywords must be in lowercase and in alphabetical order. */
  603.  
  604. struct keytab cmdtab[] = {
  605. #ifndef NOPUSH
  606.     { "!",       XXSHE, CM_INV|CM_PSH }, /* Shell escape */
  607. #else
  608.     { "!",       XXNOTAV, CM_INV|CM_PSH },
  609. #endif /* NOPUSH */
  610.     { "#",           XXCOM, CM_INV },    /* Comment */
  611. #ifndef NOSPL
  612.     { "(",           XXSEXP,CM_INV },    /* S-Expression */
  613.     { ".",           XXDEF, CM_INV },    /* Assignment */
  614.     { ":",           XXLBL, CM_INV },    /* Label */
  615. #endif /* NOSPL */
  616. #ifdef CK_REDIR
  617. #ifndef NOPUSH
  618.     { "<",           XXFUN, CM_INV|CM_PSH }, /* REDIRECT */
  619. #else
  620.     { "<",           XXNOTAV, CM_INV|CM_PSH }, /* REDIRECT */
  621. #endif /* NOPUSH */
  622. #endif /* CK_REDIR */
  623. #ifndef NOPUSH
  624.     { "@",           XXSHE, CM_INV|CM_PSH }, /* DCL escape */
  625. #else
  626.     { "@",           XXNOTAV, CM_INV|CM_PSH }, /* DCL escape */
  627. #endif /* NOPUSH */
  628.  
  629. #ifdef CK_RECALL
  630.     { "^",           XXREDO,CM_INV|CM_NOR }, /* Synonym for REDO */
  631. #endif /* CK_RECALL */
  632. #ifndef NOSPL
  633.     { "_asg",        XXASX,   CM_INV },    /* Used internally by FOR, etc */
  634.     { "_assign",     XXASX,   CM_INV },    /* Used internally by FOR, etc */
  635.     { "_decrement",  XX_DECR, CM_INV },
  636.     { "_define",     XXDFX,   CM_INV },    /* Used internally by FOR, etc */
  637.     { "_evaluate",   XX_EVAL, CM_INV },
  638.     { "_forward",    XXXFWD,  CM_INV },    /* Used internally by SWITCH   */
  639.     { "_getargs",    XXGTA,   CM_INV },    /* Used internally by FOR, etc */
  640.     { "_increment",  XX_INCR, CM_INV },
  641.     { "_putargs",    XXPTA,   CM_INV },    /* Used internally by FOR, etc */
  642.     { "_undefine",   XXUNDFX, CM_INV },
  643. #endif /* NOSPL */
  644.  
  645.     { "about",       XXVER,   CM_INV },    /* Synonym for VERSION */
  646. #ifndef NOSPL
  647. #ifdef NEWFTP
  648.     { "account",     XXACCT,  CM_INV }, /* (FTP) Account */
  649. #endif /* NEWFTP */
  650. #ifdef ADDCMD
  651.     { "add",         XXADD, 0 },    /* ADD */
  652. #endif /* ADDCMD */
  653. #ifndef NODIAL
  654.     { "answer",      XXANSW, CM_LOC },    /* ANSWER the phone */
  655. #else
  656.     { "answer",      XXNOTAV, CM_INV|CM_LOC }, /* ANSWER the phone */
  657. #endif /* NODIAL */
  658.     { "apc",         XXAPC, 0 },    /* Application Program Command */
  659. #ifndef NOSPL
  660.     { "array",       XXARRAY, 0 },    /* Array operations */
  661. #endif /* NOSPL */
  662.     { "ascii",       XXASC, CM_INV },    /* == SET FILE TYPE TEXT */
  663.     { "asg",         XXASS, CM_INV },    /* Invisible synonym for ASSIGN */
  664.     { "ask",         XXASK, 0 },    /* ASK for text, assign to variable */
  665.     { "askq",        XXASKQ,0 },    /* ASK quietly (no echo) */
  666. #ifndef NOSPL
  667.     { "ass",         XXASS, CM_INV|CM_ABR }, /* ASSIGN */
  668.     { "assert",      XXASSER, CM_INV },    /* ASSERT */
  669.     { "assign",      XXASS, 0 },    /* ASSIGN */
  670. #endif /* NOSPL */
  671. #ifndef NOXFER
  672. #ifndef NOCSETS
  673.     { "associate",   XXASSOC, 0 },    /* ASSOCIATE */
  674. #else
  675.     { "associate",   XXNOTAV, CM_INV },    /* ASSOCIATE */
  676. #endif /* NOCSETS */
  677. #endif /* NOXFER */
  678. #ifdef CK_KERBEROS
  679. #ifdef CK_AUTHENTICATION
  680.     { "authenticate",XXAUTH, 0 },    /* Authentication */
  681. #else
  682.     { "authenticate",XXAUTH, CM_INV },
  683. #endif /* CK_AUTHENTICATION */
  684. #endif /* CK_KERBEROS */
  685. #endif /* NOSPL */
  686. #ifndef NOFRILLS
  687.     { "back",        XXBACK, 0 },    /* BACK to previous directory */
  688. #else
  689.     { "back",        XXNOTAV,CM_INV },
  690. #endif /* NOFRILLS */
  691.     { "beep",        XXBEEP,CM_INV },    /* BEEP */
  692. #ifndef NOXFER
  693.     { "binary",      XXBIN, CM_INV },    /* == SET FILE TYPE BINARY */
  694. #endif /* NOXFER */
  695. #ifndef NOFRILLS
  696.     { "bug",         XXBUG, CM_INV },    /* BUG report instructions */
  697. #else
  698.     { "bug",         XXNOTAV, CM_INV },
  699. #endif /* NOFRILLS */
  700. #ifdef BROWSER
  701.     { "browse",      XXBROWS, CM_PSH|CM_LOC }, /* BROWSE (start browser) */
  702. #else
  703.     { "browse",      XXNOTAV, CM_INV|CM_PSH|CM_LOC },
  704. #endif /* BROWSER */
  705. #ifndef NOXFER
  706.     { "bye",         XXBYE, 0 },    /* BYE to remote server */
  707. #endif /* NOXFER */
  708. #ifndef NOLOCAL
  709.     { "c",           XXCON, CM_INV|CM_ABR|CM_LOC }, /* (CONNECT) */
  710. #endif /* NOLOCAL */
  711. #ifndef NOFRILLS
  712.     { "cat",         XXCAT, CM_INV },    /* Invisible synonym for TYPE */
  713. #endif /* NOFRILLS */
  714. #ifndef NOSPL
  715.  
  716. #ifndef NOXFER
  717.     { "cautious",    XXCAU, CM_INV },
  718. #endif /* NOXFER */
  719.  
  720. #endif /* NOSPL */
  721.  
  722.     { "cd",          XXCWD, 0 },    /* Change Directory */
  723.     { "cdup",        XXCDUP, CM_INV },    /* Change Directory Up */
  724.  
  725. #ifndef NOXFER
  726. #ifdef PIPESEND
  727.     { "cget",        XXCGET, CM_INV|CM_PSH }, /* CGET */
  728. #else
  729.     { "cget",        XXNOTAV, CM_INV|CM_PSH }, /* CGET */
  730. #endif /* PIPESEND */
  731. #endif /* NOXFER */
  732.     { "ch",          XXCHK,   CM_INV|CM_ABR },
  733.     { "check",       XXCHK,   0 },    /* CHECK for a feature */
  734. #ifdef CK_PERMS
  735. #ifdef UNIX
  736.     { "chmod",       XXCHMOD, 0 },    /* CHMOD */
  737. #else
  738.     { "chmod",       XXNOTAV, CM_INV },
  739. #endif /* UNIX */
  740. #else
  741.     { "chmod",       XXNOTAV, CM_INV },
  742. #endif /* CK_PERMS */
  743. #ifdef CKROOT
  744.     { "chroot",      XXCHRT,  CM_INV },    /* CHROOT */
  745. #endif /* CKROOT */
  746.     { "ckermit",     XXKERMI, CM_INV },    /* CKERMIT (like KERMIT) */
  747.     { "cl",          XXCLO,   CM_ABR|CM_INV },
  748. #ifndef NOFRILLS
  749.     { "clear",       XXCLE, 0 },    /* CLEAR input and/or device buffer */
  750. #else
  751.     { "clear",       XXNOTAV, CM_INV },
  752. #endif /* NOFRILLS */
  753.     { "close",         XXCLO, 0 },    /* CLOSE a log or other file */
  754.     { "cls",         XXCLS, CM_INV },    /* Clear Screen (CLS) */
  755.     { "comment",     XXCOM, CM_INV },    /* Introduce a comment */
  756. #ifndef NOLOCAL
  757.     { "connect",     XXCON, CM_LOC },    /* Begin terminal connection */
  758. #else
  759.     { "connect",     XXNOTAV, CM_LOC },
  760. #endif /* NOLOCAL */
  761.     { "continue",    XXCONT,  CM_INV },    /* CONTINUE */
  762. #ifndef NOFRILLS
  763. #ifdef ZCOPY
  764.     { "co",          XXCPY, CM_INV|CM_ABR },
  765.     { "cop",         XXCPY, CM_INV|CM_ABR },
  766.     { "copy",        XXCPY, 0 },    /* COPY a file */
  767. #else
  768.     { "copy",        XXNOTAV, CM_INV },
  769. #endif /* ZCOPY */
  770.     { "copyright",   XXCPR, CM_INV },    /* COPYRIGHT */
  771. #ifdef ZCOPY
  772.     { "cp",          XXCPY, CM_INV },    /* COPY a file */
  773. #endif /* ZCOPY */
  774. #ifndef NOLOCAL
  775. #ifndef OS2
  776.     { "cq",          XXCQ, CM_INV|CM_LOC }, /* CQ (connect quietly) */
  777. #endif /* OS2 */
  778. #endif /* NOLOCAL */
  779. #ifndef NOXFER
  780. #ifdef PIPESEND
  781.     { "creceive",    XXCREC,CM_INV|CM_PSH }, /* RECEIVE to a command */
  782.     { "csend",       XXCSEN,CM_INV|CM_PSH }, /* SEND from command */
  783. #else
  784.     { "creceive",    XXNOTAV,CM_INV|CM_PSH },
  785.     { "csend",       XXNOTAV,CM_INV|CM_PSH },
  786. #endif /* PIPESEND */
  787. #endif /* NOXFER */
  788. #endif /* NOFRILLS */
  789.  
  790.     { "cwd",         XXCWD,   CM_INV },    /* Traditional synonym for cd */
  791.  
  792. #ifndef NOSPL
  793.     { "date",        XXDATE,  0 },    /* DATE */
  794.     { "dcl",         XXDCL,   CM_INV },    /* DECLARE an array (see ARRAY) */
  795.     { "debug",       XXDEBUG, 0 },    /* Print a debugging msg [9.0]  */
  796.     { "declare",     XXDCL,   CM_INV },    /* DECLARE an array (see ARRAY) */
  797.     { "decrement",   XXDEC,   0 },    /* DECREMENT a numeric variable */
  798.     { "define",      XXDEF,   0 },    /* DEFINE a macro or variable   */
  799. #else
  800.     { "date",        XXNOTAV, CM_INV },
  801.     { "dcl",         XXNOTAV, CM_INV },
  802.     { "declare",     XXNOTAV, CM_INV },
  803.     { "decrement",   XXNOTAV, CM_INV },
  804.     { "define",      XXNOTAV, CM_INV },
  805. #endif /* NOSPL */
  806.  
  807. #ifndef NOFRILLS
  808.     { "delete",      XXDEL, 0 },    /* DELETE a file */
  809. #else
  810.     { "delete",      XXNOTAV, CM_INV },
  811. #endif /* NOFRILLS */
  812.  
  813. #ifndef NODIAL
  814.     { "dial",        XXDIAL,  CM_LOC },    /* DIAL a phone number */
  815. #else
  816.     { "dial",        XXNOTAV, CM_INV|CM_LOC },
  817. #endif /* NODIAL */
  818.  
  819. #ifdef NT
  820.     { "dialer",      XXDIALER, CM_INV }, /* K95 Dialer */
  821. #endif /* NT */
  822.  
  823.     { "directory",   XXDIR, 0 },    /* DIRECTORY of files */
  824.  
  825. #ifndef NOFRILLS
  826. #ifndef NOSERVER
  827.     { "disable",     XXDIS, 0 },    /* DISABLE a server function */
  828. #else
  829.     { "disable",     XXNOTAV, CM_INV },
  830. #endif /* NOSERVER */
  831. #endif /* NOFRILLS */
  832.  
  833. #ifndef NOSPL
  834.     { "do",          XXDO,  0 },    /* DO (execute) a macro */
  835. #else
  836.     { "do",          XXNOTAV, CM_INV },
  837. #endif /* NOSPL */
  838.  
  839.     { "e",           XXEXI, CM_INV|CM_ABR },
  840.  
  841. #ifndef NOFRILLS
  842. #ifndef NOXFER
  843.     { "e-packet",    XXERR, CM_INV },    /* Send an Error-Packet */
  844. #endif /* NOXFER */
  845. #endif /* NOFRILLS */
  846.  
  847.     { "echo",        XXECH, 0 },    /* ECHO text */
  848.  
  849. #ifndef NOFRILLS
  850. #ifndef NOPUSH
  851.     { "edit",        XXEDIT, CM_PSH },    /* EDIT */
  852. #else
  853.     { "edit",        XXNOTAV, CM_INV|CM_PSH }, /* EDIT */
  854. #endif /* NOPUSH */
  855. #endif /* NOFRILLS */
  856.  
  857.     { "eightbit",    XXEIGHT, CM_INV },    /* EIGHTBIT */
  858.  
  859. #ifndef NOSPL
  860.     { "else",        XXELS, CM_INV },    /* ELSE part of IF statement */
  861. #else
  862.     { "else",        XXNOTAV, CM_INV },    /* ELSE part of IF statement */
  863. #endif /* NOSPL */
  864.  
  865. #ifndef NOSERVER
  866. #ifndef NOFRILLS
  867.     { "enable",      XXENA,  0 },    /* ENABLE a server function */
  868. #else
  869.     { "enable",      XXNOTAV, CM_INV },
  870. #endif /* NOFRILLS */
  871. #endif /* NOSERVER */
  872.  
  873. #ifndef NOSPL
  874.     { "end",         XXEND,  0 },    /* END command file or macro */
  875. #else
  876.     { "end",         XXNOTAV, CM_INV },
  877. #endif /* NOSPL */
  878.  
  879.     { "erase",       XXDEL, CM_INV },    /* Synonym for DELETE */
  880.  
  881. #ifndef NOSPL
  882.     { "evaluate",    XXEVAL, 0 },    /* EVALUATE */
  883. #else
  884.     { "evaluate",    XXNOTAV, CM_INV },
  885. #endif /* NOSPL */
  886.  
  887.     { "ex",          XXEXI, CM_INV|CM_ABR }, /* Let "ex" still be EXIT */
  888.  
  889. #ifdef CKEXEC
  890.     { "exec",        XXEXEC, CM_INV|CM_LOC }, /* exec() */
  891. #else
  892.     { "exec",        XXNOTAV, CM_INV|CM_LOC },
  893. #endif /* CKEXEC */
  894.  
  895.     { "exit",       XXEXI, 0 },        /* EXIT from C-Kermit */
  896.     { "extended-options", XXXOPTS,CM_INV|CM_HLP }, /* Extended-Options */
  897.  
  898. #ifdef OS2
  899.     { "extproc",     XXCOM, CM_INV },    /* Dummy command for OS/2 */
  900. #endif /* OS2 */
  901.  
  902. #ifndef NOXFER
  903.     { "f",           XXFIN, CM_INV|CM_ABR }, /* Invisible abbrev for FIN */
  904. #endif /* NOXFER */
  905.  
  906. #ifndef NOSPL
  907.     { "fail",        XXFAIL, CM_INV },    /* FAIL */
  908.  
  909. #ifndef NOXFER
  910.     { "fast",        XXFAST, CM_INV },
  911. #endif /* NOXFER */
  912.  
  913. #ifdef CKCHANNELIO
  914.     { "fclose",      XXF_CL, CM_INV },    /* FCLOSE */
  915.     { "fcount",      XXF_CO, CM_INV },    /* FCOUNT */
  916.     { "fflush",      XXF_FL, CM_INV },    /* FFLUSH */
  917. #endif /* CKCHANNELIO */
  918.  
  919. #ifndef NOXFER
  920.     { "fi",          XXFIN, CM_INV|CM_ABR }, /* FINISH */
  921. #endif /* NOXFER */
  922.  
  923. #ifdef CKCHANNELIO
  924.     { "file",        XXFILE, 0 },    /* FILE */
  925. #endif /* CKCHANNELIO */
  926. #endif /* NOSPL */
  927.  
  928. #ifndef NOXFER
  929.     { "fin",         XXFIN, CM_INV|CM_ABR }, /* FINISH */
  930. #endif /* NOXFER */
  931.  
  932. #ifndef UNIXOROSK
  933.     { "find",        XXGREP, 0 },    /* FIND (grep) */
  934. #else
  935.     { "find",        XXGREP,CM_INV },
  936. #endif /* UNIXOROSK */
  937.  
  938. #ifndef NOXFER
  939.     { "finish",      XXFIN, 0 },    /* FINISH */
  940. #endif /* NOXFER */
  941.  
  942. #ifdef TCPSOCKET
  943.     { "firewall",    XXFIREW, CM_INV|CM_HLP },
  944. #endif /* TCPSOCKET */
  945.  
  946. #ifdef CKCHANNELIO
  947.     { "flist",       XXF_LI, CM_INV },    /* FLIST */
  948.     { "fopen",       XXF_OP, CM_INV },    /* FOPEN */
  949. #endif /* CKCHANNELIO */
  950.  
  951. #ifndef NOSPL
  952.     { "fo",          XXFOR, CM_INV|CM_ABR }, /* Invisible abbrev for... */
  953.     { "for",         XXFOR, 0 },    /* FOR loop */
  954.     { "forward",     XXFWD, CM_INV },    /* FORWARD */
  955. #endif /* NOSPL */
  956. #ifndef NOFRILLS
  957.     { "fot",       XXDIR, CM_INV },    /* "fot" = "dir" (for Chris) */
  958. #endif /* NOFRILLS */
  959.  
  960. #ifdef CKCHANNELIO
  961.     { "fread",      XXF_RE, CM_INV },    /* FREAD */
  962.     { "frewind",    XXF_RW, CM_INV },    /* FREWIND */
  963.     { "fseek",      XXF_SE, CM_INV },    /* FSEEK */
  964.     { "fstatus",    XXF_ST, CM_INV },    /* FSTATUS */
  965. #endif /* CKCHANNELIO */
  966.  
  967. #ifdef TCPSOCKET
  968. #ifndef NOFTP
  969. #ifdef SYSFTP
  970. #ifndef NOPUSH
  971.     { "ftp",       XXFTP,   CM_INV|CM_PSH|CM_LOC }, /* System FTP */
  972. #else
  973.     { "ftp",       XXNOTAV, CM_INV|CM_PSH|CM_LOC },
  974. #endif /* NOPUSH */
  975. #else  /* SYSFTP */
  976.     { "ftp",       XXFTP,   0 },    /* Built-in FTP */
  977. #endif /* SYSFTP */
  978. #else  /* NOFTP */
  979.     { "ftp",       XXNOTAV, CM_INV },    /* No FTP */
  980. #endif /* NOFTP */
  981. #endif /* TCPSOCKET */
  982.  
  983. #ifndef NOSPL
  984.     { "function",    XXFUNC, CM_INV|CM_HLP }, /* (for HELP FUNCTION) */
  985. #endif /* NOSPL */
  986.  
  987. #ifdef CKCHANNELIO
  988.     { "fwrite",      XXF_WR, CM_INV },    /* FWRITE */
  989. #endif /* CKCHANNELIO */
  990.  
  991. #ifndef NOXFER
  992.     { "g",           XXGET, CM_INV|CM_ABR }, /* Invisible abbrev for GET */
  993. #ifndef NOSPL
  994.     { "ge",          XXGET, CM_INV|CM_ABR }, /* Ditto */
  995. #endif /* NOSPL */
  996.     { "get",         XXGET, 0 },    /* GET */
  997. #endif /* NOXFER */
  998. #ifndef NOSPL
  999.     { "getc",        XXGETC, 0 },    /* GETC */
  1000. #ifdef OS2
  1001.     { "getkeycode",  XXGETK, 0 },    /* GETKEYCODE */
  1002. #endif /* OS2 */
  1003. #ifndef NOFRILLS
  1004.     { "getok",       XXGOK, 0 },    /* GETOK (ask for Yes/No/OK) */
  1005. #endif /* NOFRILLS */
  1006. #endif /* NOSPL */
  1007. #ifndef NOSPL
  1008.     { "goto",        XXGOTO,0 },    /* GOTO label in take file or macro */
  1009. #endif /* NOSPL */
  1010. #ifdef UNIXOROSK
  1011.     { "grep",        XXGREP,0 },    /* GREP (find) */
  1012. #else
  1013.     { "grep",        XXGREP,CM_INV },    /* GREP (find) */
  1014. #endif /* UNIXOROSK */
  1015.     { "h",           XXHLP, CM_INV|CM_ABR }, /* Invisible synonym for HELP */
  1016.     { "he",          XXHLP, CM_INV|CM_ABR }, /* Invisible synonym for HELP */
  1017. #ifndef NOFRILLS
  1018.     { "head",        XXHEAD, 0 },
  1019. #endif /* NOFRILLS */
  1020. #ifndef NOLOCAL
  1021.     { "hangup",      XXHAN, CM_LOC },    /* HANGUP the connection */
  1022. #endif /* NOLOCAL */
  1023.     { "hdirectory",  XXHDIR,  CM_INV },    /* DIR sorted by size biggest first */
  1024.     { "HELP",        XXHLP, 0 },    /* Display HELP text */
  1025. #ifndef NOHTTP
  1026. #ifdef TCPSOCKET
  1027.     { "http",        XXHTTP, 0 },    /* HTTP operations */
  1028. #endif /* TCPSOCKET */
  1029. #endif /* NOHTTP */
  1030. #ifndef NOSPL
  1031.     { "i",           XXINP, CM_INV|CM_ABR }, /* Invisible synonym for INPUT */
  1032.     { "if",          XXIF,  0 },         /* IF ( condition ) command */
  1033. #ifdef TCPSOCKET
  1034.     { "iksd",        XXIKSD, CM_INV },         /* Make connection to IKSD */
  1035. #else
  1036.     { "iksd",        XXNOTAV, CM_INV },
  1037. #endif /* TCPSOCKET */
  1038.     { "in",          XXINP, CM_INV|CM_ABR }, /* Invisible synonym for INPUT */
  1039.     { "increment",   XXINC, 0 },    /* Increment a numeric variable */
  1040.     { "input",       XXINP, 0 },    /* INPUT text from comm device */
  1041. #endif /* NOSPL */
  1042.  
  1043. #ifndef NOHELP
  1044.     { "int",         XXINT, CM_INV|CM_ABR },
  1045.     { "intr",        XXINT, CM_INV|CM_ABR },
  1046.     { "INTRO",       XXINT, 0 },
  1047.     { "introduction",XXINT, CM_INV },    /* Print introductory text */
  1048. #else
  1049.     { "intro",       XXNOTAV, CM_INV },
  1050.     { "introduction",XXNOTAV, CM_INV },
  1051. #endif /* NOHELP */
  1052.  
  1053. #ifdef OS2
  1054.     { "k95",         XXKERMI, CM_INV },    /* Hmmm what's this... */
  1055. #endif /* OS2 */
  1056.  
  1057. #ifndef NOSPL
  1058.     { "kcd",         XXKCD,   0      },
  1059. #endif /* NOSPL */
  1060.  
  1061.     { "kermit",      XXKERMI, CM_INV },
  1062.  
  1063. #ifdef OS2
  1064. #ifndef NOKVERBS
  1065.     { "kverb",       XXKVRB, CM_INV|CM_HLP }, /* Keyboard verb */
  1066. #endif /* NOKVERBS */
  1067. #endif /* OS2 */
  1068.  
  1069. #ifndef NOFRILLS
  1070.     { "l",           XXLOG, CM_INV|CM_ABR }, /* Invisible synonym for log */
  1071. #endif /* NOFRILLS */
  1072.  
  1073.     { "lcd",         XXLCWD, CM_INV },
  1074.     { "lcdup",       XXLCDU, CM_INV },
  1075.     { "lcwd",        XXLCWD, CM_INV },
  1076.     { "ldelete",     XXLDEL, CM_INV },
  1077.     { "ldirectory",  XXLDIR, CM_INV },
  1078.  
  1079. #ifdef CKLEARN
  1080.     { "learn",       XXLEARN, 0 },    /* LEARN - automatic script writing */
  1081. #else
  1082.     { "learn",       XXNOTAV, CM_INV },
  1083. #endif /* CKLEARN */
  1084.  
  1085.     { "li",          XXLNOUT, CM_INV|CM_ABR },
  1086.     { "LICENSE",     XXCPR, 0 },    /* LICENSE */
  1087.  
  1088. #ifndef NOSPL
  1089.     { "lineout",     XXLNOUT, 0 },    /* LINEOUT = OUTPUT + eol */
  1090. #endif /* NOSPL */
  1091.  
  1092. #ifdef NT
  1093.     { "link",        XXLINK, 0 },       /* LINK source destination */
  1094. #endif /* NT */
  1095.  
  1096.     { "lmkdir",      XXLMKD, CM_INV },
  1097.     { "lmv",         XXLREN, CM_INV },
  1098.  
  1099. #ifndef NOFRILLS
  1100.     { "lo",          XXLOG,  CM_INV|CM_ABR }, /* Invisible synonym for log */
  1101. #endif /* NOFRILLS */
  1102.  
  1103. #ifndef NOSPL
  1104.     { "local",       XXLOCAL, CM_INV },    /* LOCAL variable declaration */
  1105. #else
  1106.     { "local",       XXNOTAV, CM_INV },
  1107. #endif /* NOSPL */
  1108.  
  1109.     { "locus",       XXLOCU, CM_INV|CM_HLP }, /* "help locus" */
  1110.  
  1111.     { "log",           XXLOG, 0 },    /* Open a log file */
  1112.  
  1113.     { "login",       XXLOGIN,  0 },    /* (REMOTE) LOGIN to server or IKSD */
  1114.     { "logout",      XXLOGOUT, 0 },    /* LOGOUT from server or IKSD */
  1115.  
  1116. #ifndef NOFRILLS
  1117. #ifndef NODIAL
  1118.     { "lookup",      XXLOOK,  0 },    /* LOOKUP */
  1119. #else
  1120.     { "lookup",      XXNOTAV, CM_INV },
  1121. #endif /* NODIAL */
  1122.  
  1123.     { "lpwd",        XXLPWD, CM_INV },
  1124.     { "lrename",     XXLREN, CM_INV },
  1125.     { "lrmdir",      XXLRMD, CM_INV },
  1126.  
  1127. #ifdef UNIXOROSK
  1128.     { "ls",          XXLS,  CM_INV|CM_PSH }, /* UNIX ls command */
  1129. #else
  1130.     { "ls",          XXDIR, CM_INV },    /* Invisible synonym for DIR */
  1131. #endif /* UNIXOROSK */
  1132. #ifndef NOXFER
  1133.     { "mail",        XXMAI, 0 },    /* Send a file as e-mail */
  1134. #endif /* NOXFER */
  1135. #ifndef NOHELP
  1136.     { "manual",      XXMAN, CM_PSH },    /* MAN(UAL) */
  1137. #else
  1138.     { "manual",      XXNOTAV, CM_INV|CM_PSH },
  1139. #endif /* NOHELP */
  1140. #endif /* NOFRILLS */
  1141. #ifdef CK_MKDIR
  1142.     { "md",          XXMKDIR, CM_INV },    /* Synonym for MKDIR */
  1143. #endif /* CK_MKDIR */
  1144.     { "message",     XXMSG, 0 },    /* Print debugging message */
  1145. #ifdef CK_MINPUT
  1146.     { "minput",      XXMINP, 0 },    /* MINPUT */
  1147. #else
  1148.     { "minput",      XXNOTAV, CM_INV },
  1149. #endif /* CK_MINPUT */
  1150. #ifndef NOMSEND
  1151.     { "mget",        XXMGET, 0 },    /* MGET */
  1152. #else
  1153.     { "mget",        XXNOTAV, CM_INV },
  1154. #endif /* NOMSEND */
  1155. #ifdef CK_MKDIR
  1156.     { "mkdir",       XXMKDIR, 0 },    /* MKDIR */
  1157. #else
  1158.     { "mkdir",       XXNOTAV, CM_INV },
  1159. #endif /* CK_MKDIR */
  1160.  
  1161. #ifndef NOXFER
  1162. #ifndef NOMSEND
  1163.     { "mmove",       XXMMOVE, 0 },    /* MMOVE */
  1164. #else
  1165.     { "mmove",       XXNOTAV, CM_INV },
  1166. #endif /* NOMSEND */
  1167. #endif /* NOXFER */
  1168.  
  1169. #ifndef NOFRILLS
  1170.     { "more",        XXMORE, CM_INV },    /* MORE */
  1171. #endif /* NOFRILLS */
  1172.  
  1173. #ifndef NOXFER
  1174.     { "move",        XXMOVE, 0 },    /* MOVE  */
  1175. #endif /* NOXFER */
  1176.  
  1177. #ifndef NOSPL
  1178.     { "mpause",      XXMSL, CM_INV },    /* Millisecond sleep */
  1179. #else
  1180.     { "mpause",      XXNOTAV, CM_INV },
  1181. #endif /* NOSPL */
  1182.  
  1183. #ifndef NOXFER
  1184. #ifndef NOMSEND
  1185.     { "mput",        XXMSE, CM_INV },    /* MPUT = MSEND */
  1186.     { "ms",          XXMSE, CM_INV|CM_ABR },
  1187.     { "msend",       XXMSE, 0 },    /* Multiple SEND */
  1188. #else
  1189.     { "mput",        XXNOTAV, CM_INV },
  1190.     { "msend",       XXNOTAV, CM_INV },
  1191. #endif /* NOMSEND */
  1192. #endif /* NOXFER */
  1193.     { "msg",         XXMSG, CM_INV },    /* Print debugging message */
  1194. #ifndef NOSPL
  1195.     { "msleep",      XXMSL, 0 },    /* Millisecond sleep */
  1196. #else
  1197.     { "msleep",      XXNOTAV, CM_INV },
  1198. #endif /* NOSPL */
  1199. #ifndef NOFRILLS
  1200.     { "mv",          XXREN, CM_INV },    /* Synonym for rename */
  1201. #endif /* NOFRILLS */
  1202. #ifndef NOHELP
  1203.     { "news",        XXNEW, CM_INV },    /* Display NEWS of new features */
  1204. #else
  1205.     { "news",        XXNOTAV, CM_INV },
  1206. #endif /* NOHELP */
  1207.     { "nolocal",     XXNLCL, CM_INV },    /* Disable SET LINE / SET HOST */
  1208.     { "nopush",      XXNPSH, CM_INV },    /* Disable PUSH command/features */
  1209. #ifdef OS2
  1210.     { "noscroll",    XXNSCR, CM_INV },  /* Disable scroll operations */
  1211. #endif /* OS2 */
  1212. #ifndef NOSPL
  1213.     { "o",           XXOUT, CM_INV|CM_ABR }, /* Invisible synonym for OUTPUT */
  1214.     { "open",        XXOPE, 0 },    /* OPEN file for reading or writing */
  1215. #else
  1216.     { "open",        XXOPE, CM_INV },    /* OPEN */
  1217. #endif /* NOSPL */
  1218. #ifndef NOHELP
  1219.     { "options",     XXOPTS,CM_INV|CM_HLP }, /* Options */
  1220. #endif /* NOHELP */
  1221.     { "orientation", XXORIE, 0 },
  1222. #ifndef NOSPL
  1223.     { "output",      XXOUT, 0 },    /* OUTPUT text to comm device */
  1224. #else
  1225.     { "output",      XXNOTAV, CM_INV },
  1226. #endif /* NOSPL */
  1227. #ifdef ANYX25
  1228. #ifndef IBMX25
  1229.     { "pad",         XXPAD, CM_LOC },    /* X.3 PAD commands */
  1230. #endif /* IBMX25 */
  1231. #endif /* ANYX25 */
  1232.  
  1233. #ifdef NEWFTP
  1234.     { "passive",     XXPASV, CM_INV },    /* (FTP) PASSIVE */
  1235. #endif /* NEWFTP */
  1236.  
  1237. #ifndef NOHELP
  1238.     { "patterns",    XXPAT,CM_INV|CM_HLP }, /* Pattern syntax */
  1239. #endif /* NOHELP */
  1240.  
  1241. #ifndef NOSPL
  1242.     { "pause",       XXPAU, 0 },    /* Sleep for specified interval */
  1243. #else
  1244.     { "pause",       XXNOTAV, CM_INV },
  1245. #endif /* NOSPL */
  1246. #ifndef NODIAL
  1247.     { "pdial",       XXPDIA,  CM_LOC },    /* PDIAL (partial dial) */
  1248. #else
  1249.     { "pdial",       XXNOTAV, CM_INV|CM_LOC },
  1250. #endif /* NODIAL */
  1251. #ifdef TCPSOCKET
  1252. #ifndef NOPUSH
  1253.     { "ping",        XXPNG, CM_INV|CM_PSH|CM_LOC }, /* PING */
  1254. #else
  1255.     { "ping",        XXNOTAV, CM_INV|CM_PSH|CM_LOC },
  1256. #endif /* NOPUSH */
  1257. #endif /* TCPSOCKET */
  1258. #ifdef NETCMD
  1259. #ifndef NOPUSH
  1260.     { "pipe",        XXPIPE, CM_PSH },    /* PIPE */
  1261. #else
  1262.     { "pipe",        XXNOTAV, CM_INV|CM_PSH }, /* PIPE */
  1263. #endif /* NOPUSH */
  1264. #endif /* NETCMD */
  1265.  
  1266. #ifndef NOSPL
  1267.     { "pop",         XXEND, CM_INV },    /* Invisible synonym for END */
  1268. #endif /* NOSPL */
  1269. #ifndef NOFRILLS
  1270.     { "print",       XXPRI, 0 },    /* PRINT a file locally */
  1271. #endif /* NOFRILLS */
  1272.  
  1273.     { "prompt",      XXPROMP, CM_INV },    /* Go interactive (from script) */
  1274.  
  1275. #ifndef NOXFER
  1276. #ifdef CK_RESEND
  1277.     { "psend",       XXPSEN, CM_INV },    /* PSEND */
  1278. #else
  1279.     { "psend",       XXNOTAV, CM_INV },
  1280. #endif /* CK_RESEND */
  1281. #endif /* NOXFER */
  1282.  
  1283. #ifdef NETPTY
  1284.     { "pty",         XXPTY, CM_PSH },    /* PTY */
  1285. #else
  1286.     { "pty",         XXNOTAV, CM_INV|CM_PSH },
  1287. #endif /* NETPTY */
  1288.  
  1289. #ifndef NOPUSH
  1290.     { "pu",          XXSHE, CM_INV|CM_ABR|CM_PSH }, /* PU = PUSH */
  1291. #endif /* NOPUSH */
  1292.  
  1293. #ifdef CKPURGE
  1294.     { "purge",       XXPURGE, 0 },    /* PURGE (real) */
  1295. #else
  1296. #ifdef VMS
  1297.     { "purge",       XXPURGE, 0 },    /* PURGE (fake) */
  1298. #else
  1299.     { "purge",       XXNOTAV, CM_INV },
  1300. #endif /* VMS */
  1301. #endif /* CKPURGE */
  1302.  
  1303. #ifndef NOPUSH
  1304.     { "push",        XXSHE, CM_PSH },    /* PUSH command (like RUN, !) */
  1305. #else
  1306.     { "push",        XXNOTAV, CM_INV|CM_PSH },
  1307. #endif /* NOPUSH */
  1308.  
  1309. #ifndef NOXFER
  1310.     { "put",         XXSEN, CM_INV },    /* PUT = SEND */
  1311. #endif /* NOXFER */
  1312.  
  1313. #ifdef UNIX
  1314. #ifndef NOPUTENV
  1315.     { "putenv",      XXPUTE, CM_INV },    /* PUTENV */
  1316. #endif    /* NOPUTENV */
  1317. #endif    /* UNIX */
  1318.  
  1319.     { "pwd",         XXPWD, 0 },    /* Print Working Directory */
  1320.     { "q",           XXQUI, CM_INV|CM_ABR }, /* Invisible synonym for QUIT */
  1321.  
  1322. #ifndef NOXFER
  1323.     { "query",       XXRQUE,CM_INV },    /* (= REMOTE QUERY) */
  1324. #endif /* NOXFER */
  1325.  
  1326.     { "quit",        XXQUI, 0 },    /* QUIT from program = EXIT */
  1327.  
  1328. #ifndef NOXFER
  1329.     { "r",           XXREC, CM_INV|CM_ABR }, /* Inv synonym for RECEIVE */
  1330. #endif /* NOXFER */
  1331.  
  1332. #ifndef NOXFER
  1333.     { "rasg",        XXRASG, CM_INV },    /* REMOTE ASSIGN */
  1334.     { "rassign",     XXRASG, CM_INV },    /* ditto */
  1335.     { "rcd",         XXRCWD, CM_INV },    /* REMOTE CD */
  1336.     { "rcdup",       XXRCDUP,CM_INV },    /* REMOTE CD */
  1337.     { "rcopy",       XXRCPY, CM_INV },    /* REMOTE COPY */
  1338.     { "rcwd",        XXRCWD, CM_INV },    /* REMOTE CWD */
  1339.     { "rdelete",     XXRDEL, CM_INV },    /* REMOTE DELETE */
  1340.     { "rdirectory",  XXRDIR, CM_INV },    /* REMODE DIRECTORY */
  1341. #endif /* NOXFER */
  1342.  
  1343. #ifndef NOSPL
  1344.     { "read",        XXREA, 0 },    /* READ a line from a file */
  1345. #else
  1346.     { "read",        XXNOTAV, CM_INV },
  1347. #endif /* NOSPL */
  1348.  
  1349. #ifndef NOXFER
  1350.     { "receive",     XXREC, 0 },    /* RECEIVE files */
  1351. #endif /* NOXFER */
  1352.  
  1353. #ifndef NODIAL
  1354.     { "red",         XXRED, CM_INV|CM_ABR|CM_LOC }, /* Inv syn for REDIAL */
  1355.     { "redi",        XXRED, CM_INV|CM_ABR|CM_LOC }, /* ditto */
  1356.     { "redial",      XXRED, CM_LOC },    /* REDIAL last DIAL number */
  1357. #else
  1358.     { "red",         XXNOTAV, CM_INV|CM_LOC },
  1359.     { "redi",        XXNOTAV, CM_INV|CM_LOC },
  1360.     { "redial",      XXNOTAV, CM_INV|CM_LOC },
  1361. #endif /* NODIAL */
  1362.  
  1363. #ifdef CK_REDIR
  1364. #ifdef OS2
  1365. #ifndef NOPUSH
  1366.     { "redirect",    XXFUN, CM_INV|CM_PSH }, /* REDIRECT */
  1367. #else
  1368.     { "redirect",    XXNOTAV, CM_INV|CM_PSH },
  1369. #endif /* NOPUSH */
  1370. #else /* OS2 */
  1371. #ifndef NOPUSH
  1372.     { "redirect",    XXFUN, CM_PSH },    /* REDIRECT */
  1373. #else
  1374.     { "redirect",    XXNOTAV, CM_INV|CM_PSH },
  1375. #endif /* NOPUSH */
  1376. #endif /* OS2 */
  1377. #endif /* CK_REDIR */
  1378.  
  1379. #ifdef CK_RECALL
  1380.     { "redo",        XXREDO,  CM_NOR },    /* REDO */
  1381. #else
  1382.     { "redo",        XXNOTAV, CM_INV },
  1383. #endif /* CK_RECALL */
  1384.  
  1385. #ifndef NOXFER
  1386. #ifdef CK_RESEND
  1387.     { "reget",       XXREGET, 0 },    /* REGET */
  1388. #else
  1389.     { "reget",       XXNOTAV, CM_INV },
  1390. #endif /* CK_RESEND */
  1391. #endif /* NOXFER */
  1392.  
  1393. #ifndef NOSPL
  1394.     { "reinput",     XXREI, CM_INV },    /* REINPUT (from INPUT buffer) */
  1395. #else
  1396.     { "reinput",     XXNOTAV, CM_INV },
  1397. #endif /* NOSPL */
  1398.  
  1399. #ifndef NOXFER
  1400. #ifdef ADDCMD
  1401.     { "rem",         XXREM, CM_INV|CM_ABR },
  1402.     { "remo",        XXREM, CM_INV|CM_ABR },
  1403. #endif /* ADDCMD */
  1404.     { "remote",         XXREM, 0 },    /* Send REMOTE command to server */
  1405. #endif /* NOXFER */
  1406.  
  1407. #ifdef ADDCMD
  1408.     { "remove",      XXREMV,0 },    /* REMOVE (something from a list) */
  1409. #else
  1410.     { "remove",      XXNOTAV, CM_INV },
  1411. #endif /* ADDCMD */
  1412.  
  1413. #ifndef NOFRILLS
  1414. #ifndef NORENAME
  1415.     { "rename",      XXREN, 0 },    /* RENAME a local file */
  1416. #else
  1417.     { "rename",      XXNOTAV, CM_INV },
  1418. #endif /* NORENAME */
  1419.     { "replay",      XXTYP, CM_INV },    /* REPLAY (for now, just type) */
  1420. #endif /* NOFRILLS */
  1421.  
  1422. #ifndef NOXFER
  1423. #ifdef CK_RESEND
  1424.     { "rep",         XXTYP, CM_INV|CM_ABR },  /* REPLAY abbreviation */
  1425.     { "reput",       XXRSEN, CM_INV },          /* REPUT = RESEND */
  1426.     { "res",         XXRSEN, CM_INV|CM_ABR }, /* RESEND */
  1427.     { "rese",        XXRSEN, CM_INV|CM_ABR }, /* RESEND */
  1428.     { "resend",      XXRSEN, 0 },    /* RESEND */
  1429. #else
  1430.     { "reput",       XXNOTAV, CM_INV },
  1431.     { "res",         XXNOTAV, CM_INV },
  1432.     { "rese",        XXNOTAV, CM_INV },
  1433.     { "resend",      XXNOTAV, CM_INV },
  1434. #endif /* CK_RESEND */
  1435. #endif /* NOXFER */
  1436.  
  1437.     { "reset",       XXRESET, CM_INV },    /* RESET */
  1438.  
  1439. #ifdef CK_RESEND
  1440. #ifndef NOSPL
  1441.     { "ret",         XXRET, CM_INV|CM_ABR },
  1442. #endif /* NOSPL */
  1443. #endif /* CK_RESEND */
  1444.  
  1445. #ifndef NOXFER
  1446.     { "retrieve",    XXRETR, CM_INV },    /* RETRIEVE */
  1447. #endif /* NOXFER */
  1448.  
  1449. #ifndef NOSPL
  1450.     { "return",      XXRET, 0 },    /* RETURN from a function */
  1451. #else
  1452.     { "return",      XXNOTAV, CM_INV },
  1453. #endif /* NOSPL */
  1454.  
  1455. #ifndef NOXFER
  1456.     { "rexit",       XXRXIT, CM_INV },    /* REMOTE EXIT */
  1457. #endif /* NOXFER */
  1458.  
  1459. #ifdef CK_REXX
  1460. #ifndef NOPUSH
  1461.     { "rexx",        XXREXX, CM_PSH },    /* Execute a Rexx command */
  1462. #else
  1463.     { "rexx",        XXNOTAV, CM_INV|CM_PSH },
  1464. #endif /* NOPUSH */
  1465. #endif /* CK_REXX */
  1466.  
  1467. #ifndef NOXFER
  1468.     { "rhelp",       XXRHLP, CM_INV },    /* REMOTE HELP */
  1469.     { "rhost",       XXRHOS, CM_INV },    /* REMOTE HOST */
  1470.     { "rkermit",     XXRKER, CM_INV },    /* REMOTE KERMIT */
  1471. #endif /* NOXFER */
  1472.  
  1473. #ifdef TCPSOCKET
  1474.     { "rlogin",      XXRLOG, CM_LOC },    /* Make an Rlogin connection */
  1475. #else
  1476.     { "rlogin",      XXNOTAV, CM_INV|CM_LOC },
  1477. #endif /* TCPSOCKET */
  1478.  
  1479. #ifndef NOFRILLS
  1480.     { "rm",          XXDEL, CM_INV },    /* Invisible synonym for delete */
  1481. #endif /* NOFRILLS */
  1482.  
  1483. #ifdef CK_MKDIR
  1484.     { "rmdir",       XXRMDIR, 0 },    /* RMDIR */
  1485. #else
  1486.     { "rmdir",       XXNOTAV, CM_INV },
  1487. #endif /* CK_MKDIR */
  1488.  
  1489. #ifndef NOXFER
  1490.     { "rmessage",    XXRMSG, CM_INV },    /* REMOTE MESSAGE */
  1491.     { "rmkdir",      XXRMKD, CM_INV },    /* REMOTE MKDIR */
  1492.     { "rmsg",        XXRMSG, CM_INV },    /* REMOTE MESSAGE */
  1493. #ifndef NOSPL
  1494.     { "robust",      XXROB,  CM_INV },
  1495. #else
  1496.     { "robust",      XXNOTAV, CM_INV },
  1497. #endif /* NOSPL */
  1498.     { "rprint",      XXRPRI, CM_INV },  /* REMOTE PRINT */
  1499.     { "rpwd",        XXRPWD, CM_INV },    /* REMOTE PWD */
  1500.     { "rquery",      XXRQUE, CM_INV },    /* REMOTE QUERY */
  1501. #endif /* NOXFER */
  1502.  
  1503. #ifdef CK_RECALL
  1504.     { "rr",          XXREDO, CM_INV|CM_NOR },
  1505. #endif /* CK_RECALL */
  1506.  
  1507. #ifndef NOXFER
  1508.     { "rrename",    XXRREN, CM_INV },    /* REMOTE RENAME */
  1509.     { "rrmdir",     XXRRMD, CM_INV },    /* REMOTE REMDIR */
  1510.     { "rset",       XXRSET, CM_INV },    /* REMOTE SET */
  1511.     { "rspace",     XXRSPA, CM_INV },    /* REMOTE SPACE */
  1512.     { "rtype",      XXRTYP, CM_INV },    /* REMOTE TYPE */
  1513. #endif /* NOXFER */
  1514.  
  1515. #ifndef NOPUSH
  1516.     { "run",         XXSHE, CM_PSH },    /* RUN a program or command */
  1517. #else
  1518.     { "run",         XXNOTAV, CM_INV|CM_PSH },
  1519. #endif /* NOPUSH */
  1520.  
  1521. #ifndef NOXFER
  1522.     { "rwho",        XXRWHO, CM_INV },    /* REMOTE WHO */
  1523.     { "s",           XXSEN, CM_INV|CM_ABR }, /* Invisible synonym for send */
  1524. #endif /* NOXFER */
  1525.  
  1526. #ifndef NOSETKEY
  1527. #ifdef OS2
  1528.     { "save",       XXSAVE, 0 },        /* SAVE something */
  1529. #else
  1530.     { "save",       XXSAVE, CM_INV },
  1531. #endif /* OS2 */
  1532. #else
  1533.     { "save",       XXNOTAV, CM_INV },
  1534. #endif /* NOSETKEY */
  1535.  
  1536. #ifndef NOSCRIPT
  1537.     { "sc",        XXLOGI, CM_INV|CM_ABR|CM_LOC },
  1538.     { "scr",       XXLOGI, CM_INV|CM_ABR|CM_LOC },
  1539. #endif /* NOSCRIPT */
  1540.     { "screen",      XXSCRN, 0 },    /* SCREEN actions */
  1541. #ifndef NOSCRIPT
  1542.     { "script",       XXLOGI, CM_LOC },    /* Expect-Send-style script line */
  1543. #else
  1544.     { "script",       XXNOTAV, CM_INV|CM_LOC },
  1545. #endif /* NOSCRIPT */
  1546.  
  1547.     { "search",    XXGREP,CM_INV },    /* Synonym for GREP and FIND */
  1548.  
  1549. #ifndef NOXFER
  1550.     { "send",       XXSEN, 0 },        /* Send (a) file(s) */
  1551. #ifndef NOSERVER
  1552.     { "server",       XXSER, 0 },        /* Be a SERVER */
  1553. #else
  1554.     { "server",       XXNOTAV, CM_INV },
  1555. #endif /* NOSERVER */
  1556. #endif /* NOXFER */
  1557.  
  1558.     { "set",       XXSET, 0 },        /* SET parameters */
  1559.  
  1560. #ifndef NOSPL
  1561. #ifndef NOSEXP
  1562.     { "sexpression", XXSEXP, CM_INV|CM_HLP }, /* SEXPR */
  1563. #endif /* NOSEXP */
  1564.  
  1565. #ifdef SFTP_BUILTIN
  1566.     { "sftp",        XXSFTP, 0 },   /* SFTP */
  1567. #endif /* SFTP_BUILTIN */
  1568.  
  1569. #ifndef NOSHOW
  1570.     { "sh",          XXSHO, CM_INV|CM_ABR }, /* SHOW parameters */
  1571. #endif /* NOSHOW */
  1572.     { "shift",       XXSHIFT, 0 },    /* SHIFT args */
  1573. #else
  1574.     { "shift",       XXNOTAV, CM_INV },
  1575. #endif /* NOSPL */
  1576.  
  1577. #ifndef NOSHOW
  1578.     { "show",        XXSHO, 0 },        /* SHOW parameters */
  1579. #else
  1580.     { "show",        XXNOTAV, CM_INV },
  1581. #endif /* NOSHOW */
  1582.  
  1583. #ifdef NEWFTP
  1584.     { "site",        XXSITE, CM_INV },    /* (FTP) SITE */
  1585. #endif /* NEWFTP */
  1586.  
  1587. #ifdef SSHBUILTIN
  1588.     { "skermit",   XXSKRM, 0 },     /* SKERMIT */
  1589. #endif /* SSHBUILTIN */
  1590.  
  1591. #ifndef NOSPL
  1592. #ifndef NOFRILLS
  1593.     { "sleep",       XXPAU, CM_INV },    /* SLEEP for specified interval */
  1594. #endif /* NOFRILLS */
  1595. #endif /* NOSPL */
  1596.  
  1597. #ifndef NOSPL
  1598.     { "sort",        XXSORT, CM_INV },    /* (see ARRAY) */
  1599. #else
  1600.     { "sort",        XXNOTAV, CM_INV },
  1601. #endif /* NOSPL */
  1602.  
  1603. #ifndef MAC
  1604. #ifndef NOFRILLS
  1605.     { "sp",          XXSPA, CM_INV|CM_ABR },
  1606.     { "spa",         XXSPA, CM_INV|CM_ABR },
  1607. #endif /* NOFRILLS */
  1608.     { "space",       XXSPA, 0 },    /* Show available disk SPACE */
  1609. #endif /* MAC */
  1610.  
  1611. #ifndef NOFRILLS
  1612. #ifndef NOPUSH
  1613.     { "spawn",       XXSHE, CM_INV|CM_PSH }, /* Synonym for PUSH, RUN */
  1614. #else
  1615.     { "spawn",       XXNOTAV, CM_INV|CM_PSH }, /* Synonym for PUSH, RUN */
  1616. #endif /* NOPUSH */
  1617. #endif /* NOFRILLS */
  1618.  
  1619. #ifdef ANYSSH
  1620.     { "ssh",         XXSSH, 0 },
  1621. #endif /* ANYSSH */
  1622.  
  1623. #ifndef NOXFER
  1624.     { "sta",         XXSTA, CM_INV|CM_ABR },
  1625.     { "stat",        XXSTA, CM_INV|CM_ABR },
  1626.     { "statistics",  XXSTA, 0 },    /* Display file transfer stats */
  1627. #endif /* NOXFER */
  1628.  
  1629.     { "status",      XXSTATUS,0 },    /* Show status of previous command */
  1630.  
  1631. #ifndef NOSPL
  1632.     { "stop",        XXSTO,   0 },    /* STOP all take files and macros */
  1633.     { "succeed",     XXSUCC,  CM_INV },    /* SUCCEED */
  1634. #else
  1635.     { "stop",        XXNOTAV, CM_INV },
  1636.     { "succeed",     XXNOTAV, CM_INV },
  1637. #endif /* NOSPL */
  1638.  
  1639. #ifndef NOFRILLS
  1640.     { "SUPPORT",     XXBUG, 0 },    /* Tech support instructions */
  1641. #else
  1642.     { "support",     XXNOTAV, CM_INV },
  1643. #endif /* NOFRILLS */
  1644.  
  1645. #ifndef NOJC
  1646.     { "suspend",     XXSUS, CM_PSH },    /* SUSPEND C-Kermit (UNIX only) */
  1647. #else
  1648.     { "suspend",     XXNOTAV, CM_INV|CM_PSH },
  1649. #endif /* NOJC */
  1650.  
  1651. #ifndef NOSPL
  1652.     { "switch",      XXSWIT, 0 },    /* SWITCH */
  1653. #else
  1654.     { "switch",      XXNOTAV, CM_INV },
  1655. #endif /* NOSPL */
  1656.  
  1657. #ifdef CK_TAPI
  1658.     { "ta",       XXTAK, CM_INV|CM_ABR }, /* (because of TAPI) */
  1659. #endif /* CK_TAPI */
  1660.  
  1661. #ifndef NOFRILLS
  1662.     { "tail",        XXTAIL, 0 },    /* Display end of a local file */
  1663. #endif /* NOFRILLS */
  1664.  
  1665.     { "take",       XXTAK, 0 },        /* TAKE commands from a file */
  1666.  
  1667. #ifdef CK_TAPI
  1668.     { "tapi",       XXTAPI, CM_LOC },    /* Microsoft TAPI commands */
  1669. #else
  1670.     { "tapi",       XXNOTAV, CM_INV|CM_LOC },
  1671. #endif /* CK_TAPI */
  1672.  
  1673. #ifndef NOFRILLS
  1674. #ifdef TCPSOCKET
  1675.     { "tel",         XXTEL, CM_INV|CM_ABR|CM_LOC },
  1676.     { "telnet",      XXTEL, CM_LOC },    /* TELNET (TCP/IP only) */
  1677.     { "telopt",      XXTELOP, CM_INV },    /* TELOPT (ditto) */
  1678. #else
  1679.     { "tel",         XXNOTAV, CM_INV|CM_LOC },
  1680.     { "telnet",      XXNOTAV, CM_INV|CM_LOC },
  1681.     { "telopt",      XXNOTAV, CM_INV },
  1682. #endif /* TCPSOCKET */
  1683. #ifdef OS2
  1684.     { "terminal",    XXTERM, CM_INV|CM_LOC }, /* == SET TERMINAL TYPE */
  1685. #else
  1686.     { "terminal",    XXTERM, CM_INV },
  1687. #endif /* OS2 */
  1688. #endif /* NOFRILLS */
  1689. #ifndef NOXFER
  1690.     { "text",        XXASC, CM_INV },    /* == SET FILE TYPE TEXT */
  1691. #endif /* NOXFER */
  1692.     { "touch",       XXTOUC, 0 },    /* TOUCH */
  1693. #ifndef NOSPL
  1694.     { "trace",       XXTRACE, 0 },    /* TRACE */
  1695. #else
  1696.     { "trace",       XXNOTAV, CM_INV },
  1697. #endif /* NOSPL */
  1698.  
  1699. #ifndef NOCSETS
  1700.     { "translate",   XXXLA, 0 },    /* TRANSLATE local file char sets */
  1701. #else
  1702.     { "translate",   XXNOTAV, CM_INV },
  1703. #endif /* NOCSETS */
  1704.  
  1705. #ifndef NOXMIT
  1706.     { "transmit",    XXTRA, 0 },    /* Send (upload) a file, no protocol */
  1707. #else
  1708.     { "transmit",    XXNOTAV, CM_INV },
  1709. #endif /* NOXMIT */
  1710.  
  1711. #ifndef NOFRILLS
  1712.     { "type",        XXTYP, 0 },    /* Display a local file */
  1713. #endif /* NOFRILLS */
  1714.  
  1715. #ifndef NOSPL
  1716.     { "undcl",       XXUNDCL, CM_INV },
  1717.     { "undeclare",   XXUNDCL, 0 },    /* UNDECLARE an array */
  1718.     { "undefine",    XXUNDEF, 0 },    /* UNDEFINE a variable or macro */
  1719. #else
  1720.     { "undcl",       XXNOTAV, CM_INV },
  1721.     { "undeclare",   XXNOTAV, CM_INV },
  1722.     { "undefine",    XXNOTAV, CM_INV },
  1723. #endif /* NOSPL */
  1724.  
  1725. #ifdef NEWFTP
  1726.     { "user",        XXUSER,  CM_INV }, /* (FTP) USER */
  1727. #endif /* NEWFTP */
  1728.  
  1729.     { "version",     XXVER, 0 },    /* VERSION-number display */
  1730.  
  1731. #ifdef OS2
  1732.     { "viewonly",    XXVIEW, CM_LOC },    /* VIEWONLY Terminal Mode */
  1733. #endif /* OS2 */
  1734.  
  1735.     { "void",        XXVOID, 0 },    /* VOID */
  1736.  
  1737. #ifndef NOSPL
  1738.     { "wait",        XXWAI, 0 },    /* WAIT */
  1739. #else
  1740.     { "wait",        XXNOTAV, CM_INV },
  1741. #endif /* NOSPL */
  1742.  
  1743.     { "wdirectory",  XXWDIR,  CM_INV },    /* Like TOPS-20, reverse chron order */
  1744.     { "wermit",      XXKERMI, CM_INV },
  1745.  
  1746. #ifndef NOXFER
  1747.     { "where",       XXWHERE, 0 },    /* WHERE (did my file go?) */
  1748. #endif /* NOXFER */
  1749.  
  1750. #ifndef NOSPL
  1751.     { "while",       XXWHI, 0 },    /* WHILE loop */
  1752. #else
  1753.     { "while",       XXNOTAV, CM_INV },
  1754. #endif /* NOSPL */
  1755.  
  1756. #ifndef OS2
  1757. #ifndef MAC
  1758. #ifndef NOFRILLS
  1759.     { "who",         XXWHO, CM_PSH },    /* WHO's logged in? */
  1760. #endif /* NOFRILLS */
  1761. #endif /* MAC */
  1762. #endif /* OS2 */
  1763.  
  1764. #ifndef NOHELP
  1765.     { "wildcards",   XXWILD,CM_INV|CM_HLP }, /* Wildcard syntax */
  1766. #endif /* NOHELP */
  1767.  
  1768. #ifndef NOSPL
  1769.     { "wr",          XXWRI, CM_INV|CM_ABR },
  1770.     { "wri",         XXWRI, CM_INV|CM_ABR },
  1771.     { "writ",        XXWRI, CM_INV|CM_ABR },
  1772.     { "write",       XXWRI, 0 },    /* WRITE characters to a file */
  1773.     { "write-line",  XXWRL, CM_INV },    /* WRITE a line to a file */
  1774.     { "writeln",     XXWRL, CM_INV },    /* Pascalisch synonym for write-line */
  1775. #else
  1776.     { "wr",          XXNOTAV, CM_INV },
  1777.     { "wri",         XXNOTAV, CM_INV },
  1778.     { "writ",        XXNOTAV, CM_INV },
  1779.     { "write",       XXNOTAV, CM_INV },
  1780.     { "write-line",  XXNOTAV, CM_INV },
  1781.     { "writeln",     XXNOTAV, CM_INV },
  1782. #endif /* NOSPL */
  1783.  
  1784. #ifndef NOFRILLS
  1785.     { "xecho",       XXXECH,0 },    /* XECHO */
  1786. #endif /* NOFRILLS */
  1787.  
  1788. #ifndef NOSPL
  1789.     { "xif",         XXIFX, CM_INV },    /* Extended IF command (obsolete) */
  1790. #else
  1791.     { "xif",         XXNOTAV, CM_INV },
  1792. #endif /* NOSPL */
  1793.  
  1794. #ifndef NOCSETS
  1795.     { "xlate",       XXXLA, CM_INV },    /* Synonym for TRANSLATE */
  1796. #else
  1797.     { "xlate",       XXNOTAV, CM_INV },
  1798. #endif /* NOCSETS */
  1799.  
  1800. #ifndef NOXMIT
  1801.     { "xmit",        XXTRA, CM_INV },    /* Synonym for TRANSMIT */
  1802. #else
  1803.     { "xmit",        XXNOTAV, CM_INV },
  1804. #endif /* NOXMIT */
  1805.  
  1806. #ifndef OS2
  1807. #ifndef NOJC
  1808.     { "z",           XXSUS, CM_INV|CM_PSH }, /* Synonym for SUSPEND */
  1809. #else
  1810.     { "z",           XXNOTAV, CM_INV|CM_PSH },
  1811. #endif /* NOJC */
  1812. #endif /* OS2 */
  1813.  
  1814. #ifndef NOSPL
  1815.     { "{",           XXMACRO, CM_INV },    /* Immediate macro */
  1816. #endif /* NOSPL */
  1817.     { "", 0, 0 }
  1818. };
  1819. int ncmd = (sizeof(cmdtab) / sizeof(struct keytab)) - 1;
  1820.  
  1821. /* NOTE: Tokens must also be entered above into cmdtab[]. */
  1822.  
  1823. char toktab[] = {
  1824. #ifndef NOPUSH
  1825.     '!',                /* Shell escape */
  1826. #endif /* NOPUSH */
  1827.     '#',                /* Comment */
  1828. #ifndef NOSPL
  1829.     '(',                /* S-Expression */
  1830.     '.',                /* Assignment */
  1831. #endif /* NOSPL */
  1832.     ';',                /* Comment */
  1833. #ifndef NOSPL
  1834.     ':',                /* Label */
  1835. #endif /* NOSPL */
  1836. #ifndef NOPUSH
  1837. #ifdef CK_REDIR
  1838.     '<',                /* REDIRECT */
  1839. #endif /* CK_REDIR */
  1840.     '@',                /* DCL escape */
  1841. #endif /* NOPUSH */
  1842. #ifdef CK_RECALL
  1843.     '^',                /* Command recall */
  1844. #endif /* CK_RECALL */
  1845. #ifndef NOSPL
  1846.     '{',                /* Immediate macro */
  1847. #endif /* NOSPL */
  1848.     '\0'                /* End of this string */
  1849. };
  1850. int xxdot = 0;                /* Used with "." token */
  1851.  
  1852. struct keytab yesno[] = {        /* Yes/No keyword table */
  1853.     { "no",    0, 0 },
  1854.     { "ok",    1, 0 },
  1855.     { "yes",   1, 0 }
  1856. };
  1857. int nyesno = (sizeof(yesno) / sizeof(struct keytab));
  1858.  
  1859. /* Save keyword table */
  1860.  
  1861. struct keytab savtab[] = {
  1862. #ifdef OS2
  1863.     { "command",  XSCMD, 0 },
  1864. #else
  1865. #ifdef CK_RECALL
  1866.     { "command",  XSCMD, 0 },
  1867. #endif /* CK_RECALL */
  1868. #endif /* OS2 */
  1869. #ifndef NOSETKEY
  1870.     { "keymap",   XSKEY, 0 },
  1871. #endif /* NOSETKEY */
  1872. #ifdef OS2
  1873.     { "terminal", XSTERM, 0 },
  1874. #endif /* OS2 */
  1875.     { "", 0, 0 }
  1876. };
  1877. int nsav = (sizeof(savtab) / sizeof(struct keytab)) - 1;
  1878.  
  1879. /* Parameter keyword table */
  1880.  
  1881. struct keytab prmtab[] = {
  1882.     { "alarm",            XYALRM,  0 },
  1883. #ifdef COMMENT                /* SET ANSWER not implemented yet */
  1884. #ifndef NODIAL
  1885.     { "answer",           XYANSWER,0 },
  1886. #endif /* NODIAL */
  1887. #endif /* COMMENT */
  1888.     { "ask-timer",        XYTIMER, 0 },
  1889. #ifndef NOXFER
  1890.     { "attributes",       XYATTR,  0 },
  1891. #endif /* NOXFER */
  1892. #ifdef CK_AUTHENTICATION
  1893.     { "authentication",   XYAUTH,  0 },
  1894. #else  /* CK_AUTHENTICATION */
  1895. #ifdef CK_SSL
  1896.     { "authentication",   XYAUTH,  0 },
  1897. #endif /* CK_SSL */
  1898. #endif /* CK_AUTHENTICATION */
  1899.     { "b",          XYBACK,  CM_INV|CM_ABR|CM_PSH },
  1900.     { "ba",          XYBACK,  CM_INV|CM_ABR|CM_PSH },
  1901. #ifdef VMS
  1902.     { "background",       XYBACK,  CM_INV|CM_PSH },
  1903.     { "batch",            XYBACK,  CM_PSH },
  1904. #else
  1905.     { "background",       XYBACK,  CM_PSH },
  1906.     { "batch",            XYBACK,  CM_INV|CM_PSH },
  1907. #endif /* VMS */
  1908. #ifndef NOLOCAL
  1909.     { "baud",              XYSPEE,  CM_INV|CM_LOC },
  1910. #endif /* NOLOCAL */
  1911.     { "bell",             XYBELL,  0 },
  1912. #ifndef NOXFER
  1913.     { "block-check",        XYCHKT,  0 },
  1914. #endif /* NOXFER */
  1915. #ifdef OS2
  1916. #ifdef BPRINT
  1917.     { "bprinter",         XYBDCP,  CM_INV },
  1918. #endif /* BPRINT */
  1919. #endif /*  OS2 */
  1920. #ifdef BROWSER
  1921.     { "browser",          XYBROWSE,CM_PSH|CM_LOC },
  1922. #endif /* BROWSER */
  1923. #ifndef NOXFER
  1924. #ifdef DYNAMIC
  1925.     { "buffers",          XYBUF,   0 },
  1926. #endif /* DYNAMIC */
  1927. #endif /* NOXFER */
  1928. #ifndef NOLOCAL
  1929. #ifndef MAC
  1930.     { "carrier-watch",    XYCARR,  CM_LOC },
  1931. #endif /* MAC */
  1932. #endif /* NOLOCAL */
  1933. #ifndef NOSPL
  1934.     { "case",             XYCASE,  0 },
  1935. #endif /* NOSPL */
  1936.     { "cd",               XYCD,    0 },
  1937. #ifndef NOXFER
  1938.     { "cl",               XYCLEAR, CM_INV|CM_ABR },
  1939.     { "cle",              XYCLEAR, CM_INV|CM_ABR },
  1940.     { "clea",             XYCLEAR, CM_INV|CM_ABR },
  1941.     { "clear",            XYCLEAR, CM_INV|CM_ABR },
  1942.     { "clear-channel",    XYCLEAR, 0 },
  1943.     { "clearchannel",     XYCLEAR, CM_INV },
  1944. #endif /* NOXFER */
  1945. #ifndef NOLOCAL
  1946.     { "close-on-disconnect", XYDISC, CM_INV|CM_LOC },
  1947. #endif /* NOLOCAL */
  1948.     { "cmd",              XYCMD,   CM_INV },
  1949.     { "command",          XYCMD,   0 },
  1950. #ifdef CK_SPEED
  1951.     { "con",              XYQCTL,  CM_INV|CM_ABR },
  1952. #endif /* CK_SPEED */
  1953.     { "console",          XYCMD,   CM_INV },
  1954. #ifdef CK_SPEED
  1955.     { "control-character",XYQCTL,  0 },
  1956. #endif /* CK_SPEED */
  1957. #ifndef NOSPL
  1958.     { "count",            XYCOUN,  0 },
  1959. #endif /* NOSPL */
  1960. #ifndef NOXFER
  1961.     { "d",          XYDELA,  CM_INV|CM_ABR },
  1962.     { "de",          XYDELA,  CM_INV|CM_ABR },
  1963. #endif /* NOXFER */
  1964.     { "debug",            XYDEBU,  0 },
  1965. #ifdef VMS
  1966.     { "default",          XYDFLT,  0 },
  1967. #else
  1968. #ifndef MAC
  1969.     { "default",          XYDFLT,  CM_INV },
  1970. #endif /* MAC */
  1971. #endif /* VMS */
  1972. #ifndef NOXFER
  1973.     { "delay",              XYDELA,  0 },
  1974.     { "destination",      XYDEST,  0 },
  1975. #endif /* NOXFER */
  1976. #ifndef NODIAL
  1977.     { "di",          XYDIAL,  CM_INV|CM_ABR|CM_LOC },
  1978.     { "dia",          XYDIAL,  CM_INV|CM_ABR|CM_LOC },
  1979.     { "dial",             XYDIAL,  CM_LOC },
  1980. #endif /* NODIAL */
  1981. #ifdef OS2
  1982.     { "dialer",          XYDLR,   CM_INV },
  1983. #endif /* OS2 */
  1984. #ifndef NOLOCAL
  1985.     { "disconnect",       XYDISC,  CM_LOC },
  1986.     { "duplex",              XYDUPL,  CM_LOC },
  1987. #endif /* NOLOCAL */
  1988. #ifndef NOPUSH
  1989. #ifndef NOFRILLS
  1990.     { "editor",           XYEDIT,  CM_PSH },
  1991. #endif /*  NOFRILLS */
  1992. #endif /* NOPUSH */
  1993. #ifdef CK_CTRLZ
  1994.     { "eof",              XYEOF,   CM_INV },
  1995. #endif /* CK_CTRLZ */
  1996. #ifndef NOLOCAL
  1997.     { "escape-character", XYESC,   CM_LOC },
  1998. #endif /* NOLOCAL */
  1999. #ifndef NOSPL
  2000.     { "evaluate",         XYEVAL,  CM_INV },
  2001. #endif /* NOSPL */
  2002.     { "exit",          XYEXIT,  0 },
  2003. #ifndef NOXFER
  2004. #ifdef CK_XYZ
  2005. #ifndef NOPUSH
  2006. #ifndef XYZ_INTERNAL
  2007.     { "external-protocol",XYEXTRN, 0 },
  2008. #endif    /* XYZ_INTERNAL */
  2009. #endif    /* NOPUSH */
  2010. #endif    /* CK_XYZ */
  2011.     { "f-ack-bug",        XYFACKB, CM_INV },
  2012.     { "f-ack-path",       XYFACKP, CM_INV },
  2013. #endif /* NOXFER */
  2014.     { "file",             XYFILE,  0 },
  2015.     { "fl",                 XYFLOW,  CM_INV|CM_ABR },
  2016. #ifndef NOSPL
  2017.     { "flag",             XYFLAG,  0 },
  2018. #endif /* NOSPL */
  2019. #ifdef TCPSOCKET
  2020. #ifndef SYSFTP
  2021. #ifndef NOFTP
  2022.     { "ft",                 XYFTPX,  CM_INV|CM_ABR },
  2023.     { "ftp",                XYFTPX,  0 },
  2024. #endif /* NOFTP */
  2025. #endif /* SYSFTP */
  2026. #endif /* TCPSOCKET */
  2027. #ifdef BROWSER
  2028.     { "ftp-client",       XYFTP,   CM_PSH },
  2029. #endif /* BROWSER */
  2030.     { "flow-control",       XYFLOW,  0 },
  2031. #ifndef NOSPL
  2032.     { "function",         XYFUNC,  0 },
  2033. #endif /* NOSPL */
  2034. #ifdef NEWFTP
  2035.     { "get-put-remote",   XYGPR,   0 },
  2036. #endif /* NEWFTP */
  2037. #ifdef KUI
  2038.     { "gui",              XYGUI,   0 },
  2039. #endif /* KUI */
  2040.     { "handshake",          XYHAND,  0 },
  2041.     { "hints",            XYHINTS, 0 },
  2042. #ifdef NETCONN
  2043.     { "host",             XYHOST,  CM_LOC },
  2044. #endif /* NETCONN */
  2045. #ifndef NOSPL
  2046.     { "i",          XYINPU,  CM_INV|CM_ABR },
  2047. #endif /* NOSPL */
  2048. #ifdef IKSD
  2049.     { "iks",              XYIKS,   0 },
  2050. #else
  2051.     { "iks",              XYIKS,   CM_INV },
  2052. #endif /* IKSD */
  2053. #ifndef NOSPL
  2054.     { "in",          XYINPU,  CM_INV|CM_ABR },
  2055. #endif /* NOSPL */
  2056. #ifndef NOXFER
  2057.     { "incomplete",         XYIFD,   CM_INV },
  2058. #endif /* NOXFER */
  2059. #ifndef NOSPL
  2060.     { "input",            XYINPU,  0 },
  2061. #endif /* NOSPL */
  2062. #ifndef NOSETKEY
  2063.     { "key",          XYKEY,   0 },
  2064. #endif /* NOSETKEY */
  2065.     { "l",                XYLINE,  CM_INV|CM_ABR },
  2066. #ifndef NOCSETS
  2067.     { "language",         XYLANG,  0 },
  2068. #endif /* NOCSETS */
  2069. #ifndef NOLOCAL
  2070.     { "line",             XYLINE,  CM_LOC },
  2071.     { "local-echo",      XYLCLE,  CM_INV|CM_LOC },
  2072. #endif /* NOLOCAL */
  2073. #ifdef LOCUS
  2074.     { "locus",            XYLOCUS, 0 },
  2075. #endif /* LOCUS */
  2076. #ifndef NOSPL
  2077.     { "login",          XYLOGIN, CM_LOC },
  2078. #endif /* NOSPL */
  2079. #ifndef NOSPL
  2080.     { "macro",            XYMACR,  0 },
  2081. #endif /* NOSPL */
  2082.     { "match",            XYMATCH, 0 },
  2083. #ifdef COMMENT
  2084. #ifdef VMS
  2085.     { "messages",         XYMSGS,  0 },
  2086. #endif /* VMS */
  2087. #endif /* COMMENT */
  2088. #ifndef NODIAL
  2089.     { "modem",          XYMODM,  CM_LOC },
  2090. #endif /* NODIAL */
  2091. #ifndef NOLOCAL
  2092. #ifdef OS2MOUSE
  2093.     { "mouse",          XYMOUSE, 0 },
  2094. #endif /* OS2MOUSE */
  2095. #endif /* NOLOCAL */
  2096. #ifdef OS2
  2097.     { "mskermit",         XYMSK,   0 },
  2098. #endif /* OS2 */
  2099. #ifdef NETCONN
  2100.     { "network",          XYNET,   CM_LOC },
  2101. #endif /* NETCONN */
  2102. #ifndef NOSPL
  2103.     { "output",           XYOUTP,  0 },
  2104. #endif /* NOSPL */
  2105.     { "options",          XYOPTS,  0 },
  2106.     { "pause",            XYSLEEP, CM_INV },
  2107. #ifdef ANYX25
  2108. #ifndef IBMX25
  2109.     { "pad",              XYPAD,   CM_LOC },
  2110. #endif /* IBMX25 */
  2111. #endif /* ANYX25 */
  2112.     { "parity",              XYPARI,  0 },
  2113. #ifndef NOLOCAL
  2114. #ifdef OS2
  2115.     { "port",             XYLINE,  CM_LOC },
  2116. #else
  2117.     { "port",             XYLINE,  CM_INV|CM_LOC },
  2118. #endif /* OS2 */
  2119. #endif /* NOLOCAL */
  2120. #ifndef NOFRILLS
  2121.     { "pr",                 XYPROM,  CM_INV|CM_ABR },
  2122.     { "printer",          XYPRTR,  0 },
  2123. #endif /* NOFRILLS */
  2124. #ifdef OS2
  2125.     { "priority",         XYPRTY,  0 },
  2126. #endif /* OS2 */
  2127. #ifdef CK_SPEED
  2128.     { "prefixing",        XYPREFIX, 0 },
  2129. #endif /* CK_SPEED */
  2130. #ifndef NOFRILLS
  2131.     { "prompt",              XYPROM,  0 },
  2132. #endif /* NOFRILLS */
  2133. #ifndef NOXFER
  2134.     { "protocol",      XYPROTO, 0 },
  2135. #endif /* NOXFER */
  2136.     { "q",          XYQUIE,  CM_INV|CM_ABR },
  2137. #ifndef NOXFER
  2138.     { "q8flag",           XYQ8FLG, CM_INV },
  2139. #endif /* NOXFER */
  2140. #ifdef QNX
  2141.     { "qnx-port-lock",    XYQNXPL, 0 },
  2142. #else
  2143.     { "qnx-port-lock",    XYQNXPL, CM_INV },
  2144. #endif /* QNX */
  2145.     { "quiet",          XYQUIE,  0 },
  2146. #ifndef NOXFER
  2147.     { "rec",              XYRECV,  CM_INV|CM_ABR },
  2148.     { "receive",          XYRECV,  0 },
  2149.     { "recv",             XYRECV,  CM_INV },
  2150. #endif /* NOXFER */
  2151.     { "reliable",         XYRELY,  0 },
  2152.     { "rename",           XY_REN,  0 },
  2153. #ifndef NOXFER
  2154.     { "repeat",           XYREPT,  0 },
  2155.     { "retry-limit",      XYRETR,  0 },
  2156. #endif /* NOXFER */
  2157. #ifdef CKROOT
  2158.     { "root",             XYROOT,  0 },
  2159. #endif /* CKROOT */
  2160. #ifndef NOSCRIPT
  2161.     { "script",          XYSCRI,  CM_LOC },
  2162. #endif /* NOSCRIPT */
  2163. #ifndef NOXFER
  2164.     { "send",             XYSEND,  0 },
  2165. #ifndef NOLOCAL
  2166. #ifndef NOSERVER
  2167.     { "ser",              XYSERV,  CM_INV|CM_ABR },
  2168. #endif /* NOSERVER */
  2169. #endif /* NOXFER */
  2170.     { "serial",           XYSERIAL,CM_LOC },
  2171. #endif /* NOLOCAL */
  2172. #ifndef NOSERVER
  2173.     { "server",           XYSERV,  0 },
  2174. #endif /* NOSERVER */
  2175. #ifdef SESLIMIT
  2176. #ifndef NOLOCAL
  2177.     { "session-l",        XYSESS,  CM_INV|CM_ABR },
  2178. #endif /* NOLOCAL */
  2179.     { "session-limit",    XYLIMIT, CM_INV|CM_LOC }, /* Session Limit */
  2180. #endif /* SESLIMIT */
  2181.  
  2182. #ifndef NOLOCAL
  2183.     { "session-log",      XYSESS,  CM_LOC },
  2184. #endif /* NOLOCAL */
  2185.  
  2186. #ifndef NOSPL
  2187. #ifndef NOSEXP
  2188.     { "sexpression",      XYSEXP,  CM_INV },
  2189. #endif /* NOSEXP */
  2190. #endif /* NOSPL */
  2191.  
  2192.     { "sleep",            XYSLEEP, 0 },
  2193.  
  2194. #ifndef NOLOCAL
  2195.     { "speed",              XYSPEE,  CM_LOC },
  2196. #endif /* NOLOCAL */
  2197.  
  2198. #ifdef ANYSSH
  2199.     { "ssh",              XYSSH,   0 },
  2200. #endif /* ANYSSH */
  2201.  
  2202. #ifndef NOSPL
  2203.     { "startup-file",     XYSTARTUP, CM_INV },
  2204. #endif /* NOSPL */
  2205.  
  2206. #ifndef NOLOCAL
  2207. #ifdef HWPARITY
  2208.     { "stop-bits",        XYSTOP, CM_LOC },
  2209. #else
  2210. #ifdef TN_COMPORT
  2211.     { "stop-bits",        XYSTOP, CM_LOC },
  2212. #endif /* TN_COMPORT */
  2213. #endif /* HWPARITY */
  2214. #endif /* NOLOCAL */
  2215.  
  2216. #ifndef NOXFER
  2217. #ifdef STREAMING
  2218.     { "streaming",        XYSTREAM, 0 },
  2219. #endif /* STREAMING */
  2220. #endif /* NOXFER */
  2221.  
  2222. #ifndef NOJC
  2223.     { "suspend",          XYSUSP,  CM_PSH },
  2224. #endif /* NOJC */
  2225. #ifdef CKSYSLOG
  2226.     { "syslog",           XYSYSL,  CM_INV },
  2227. #endif /* CKSYSLOG */
  2228.     { "take",             XYTAKE,  0 },
  2229.  
  2230. #ifdef CK_TAPI
  2231.     { "tapi",             XYTAPI,  CM_LOC },
  2232. #endif /* CK_TAPI */
  2233.  
  2234. #ifndef NOTCPOPTS
  2235. #ifdef TCPSOCKET
  2236.     { "tcp",              XYTCP,   CM_LOC },
  2237. #endif /* TCPSOCKET */
  2238. #endif /* NOTCPOPTS */
  2239.  
  2240. #ifdef TNCODE
  2241.     { "tel",              XYTEL,   CM_INV|CM_ABR },
  2242.     { "telnet",           XYTEL,   0 },
  2243.     { "telopt",           XYTELOP, 0 },
  2244. #endif /* TNCODE */
  2245.  
  2246. #ifndef NOSPL
  2247.     { "temp-directory",   XYTMPDIR,0 },
  2248. #endif /* NOSPL */
  2249.  
  2250. #ifndef NOLOCAL
  2251.     { "terminal",         XYTERM,  CM_LOC },
  2252. #endif /* NOLOCAL */
  2253.  
  2254. #ifdef OS2
  2255.     { "title",          XYTITLE, CM_LOC },
  2256. #endif /* OS2 */
  2257. #ifdef TLOG
  2258.     { "transaction-log",  XYTLOG,  0 },
  2259. #endif /* TLOG */
  2260. #ifndef NOXFER
  2261.     { "transfer",         XYXFER,  0 },
  2262. #endif /* NOXFER */
  2263. #ifndef NOXMIT
  2264.     { "transmit",         XYXMIT,  0 },
  2265. #endif /* NOXMIT */
  2266. #ifndef NOXFER
  2267. #ifndef NOCSETS
  2268.     { "unknown-char-set", XYUNCS,  0 },
  2269. #endif /* NOCSETS */
  2270. #ifndef NOSPL
  2271.     { "variable-evaluation", XYVAREV, 0 },
  2272. #endif    /* NOSPL */
  2273. #endif /* NOXFER */
  2274.     { "wait",             XYSLEEP, CM_INV },
  2275. #ifndef NOPUSH
  2276. #ifdef UNIX
  2277.     { "wildcard-expansion", XYWILD, 0 },
  2278. #endif /* UNIX */
  2279. #endif /* NOPUSH */
  2280. #ifdef NT
  2281.     { "w",                XYWIND,  CM_INV|CM_ABR },
  2282.     { "wi",               XYWIND,  CM_INV|CM_ABR },
  2283.     { "win",              XYWIND,  CM_INV|CM_ABR },
  2284. #endif /* NT */
  2285.     { "window-size",      XYWIND,  0 },
  2286. #ifdef NT
  2287.     { "win95",            XYWIN95, 0 },
  2288. #endif /* NT */
  2289. #ifdef ANYX25
  2290.     { "x.25",             XYX25,   CM_LOC },
  2291.     { "x25",              XYX25,   CM_INV|CM_LOC },
  2292. #endif /* ANYX25 */
  2293.     { "xfer",             XYXFER,  CM_INV },
  2294. #ifndef NOXMIT
  2295.     { "xmit",             XYXMIT,  CM_INV },
  2296. #endif /* NOXMIT */
  2297.     { "", 0, 0 }
  2298. };
  2299. int nprm = (sizeof(prmtab) / sizeof(struct keytab)) - 1; /* How many */
  2300.  
  2301. struct keytab scntab[] = {        /* Screen commands */
  2302.     { "clear",   SCN_CLR, 0 },
  2303.     { "cleol",   SCN_CLE, 0 },
  2304.     { "move-to", SCN_MOV, 0 }
  2305. };
  2306. int nscntab = (sizeof(scntab) / sizeof(struct keytab)); /* How many */
  2307.  
  2308. #ifdef ANYSSH                /* SSH command table */
  2309. #ifdef SSHBUILTIN
  2310. int    ssh_pf_lcl_n = 0,
  2311.        ssh_pf_rmt_n = 0;
  2312. struct ssh_pf ssh_pf_lcl[32] = { 0, NULL, 0 }; /* SSH Port Forwarding */
  2313. struct ssh_pf ssh_pf_rmt[32] = { 0, NULL, 0 }; /* structs... */
  2314. extern char * ssh_hst, * ssh_cmd, * ssh_prt;
  2315. extern int    ssh_ver,   ssh_xfw;
  2316. char * ssh_tmpuid = NULL, *ssh_tmpcmd = NULL, *ssh_tmpport = NULL,
  2317.      * ssh_tmpstr = NULL;
  2318.  
  2319. int
  2320.  sshk_type = SSHKT_2D,            /* SSH KEY CREATE /TYPE:x */
  2321.  sshk_bits = 1024,            /* SSH KEY CREATE /BITS:n */
  2322.  sshk_din  = SKDF_OSSH,            /* SSH KEY DISPLAY /IN-FORMAT: */
  2323.  sshk_dout = SKDF_OSSH;            /* SSH KEY DISPLAY /OUT-FORMAT: */
  2324.  
  2325. char
  2326.  * sshk1_comment = NULL,        /* SSH V1 COMMENT */
  2327.  * sshkp_old = NULL,            /* Old key passphrase */
  2328.  * sshkp_new = NULL,            /* New key passphrase */
  2329.  * sshkc_pass = NULL,            /* KEY CREATE /PASS:xxx */
  2330.  * sshkc_comm = NULL,            /* KEY CREATE /V1-RSA-COMMENT:xxx */
  2331.  * sshd_file = NULL,            /* DISPLAY file */
  2332.  * sshk_file = NULL;            /* SSH CREATE KEY file */
  2333.  
  2334. static struct keytab sshclr[] = {
  2335.     { "local-port-forward",  SSHC_LPF, 0 },
  2336.     { "remote-port-forward", SSHC_RPF, 0 },
  2337.     { "", 0, 0 }
  2338. };
  2339. static int nsshclr = (sizeof(sshclr) / sizeof(struct keytab)) - 1;
  2340.  
  2341. struct keytab sshopnsw[] = {
  2342.     { "/command",        SSHSW_CMD, CM_ARG },
  2343.     { "/password",       SSHSW_PWD, CM_ARG },
  2344.     { "/subsystem",      SSHSW_SUB, CM_ARG },
  2345.     { "/user",           SSHSW_USR, CM_ARG },
  2346.     { "/version",        SSHSW_VER, CM_ARG },
  2347.     { "/x11-forwarding", SSHSW_X11, CM_ARG },
  2348.     { "", 0, 0 }
  2349. };
  2350. int nsshopnsw = (sizeof(sshopnsw) / sizeof(struct keytab)) - 1;
  2351.  
  2352. static struct keytab sshkwtab[] = {
  2353.     { "add",                 XSSH_ADD, 0 },
  2354.     { "agent",               XSSH_AGT, 0 },
  2355.     { "clear",               XSSH_CLR, 0 },
  2356.     { "forward-local-port",  XSSH_FLP, CM_INV },
  2357.     { "forward-remote-port", XSSH_FRP, CM_INV },
  2358.     { "key",                 XSSH_KEY, 0 },
  2359.     { "open",                XSSH_OPN, 0 },
  2360.     { "v2",                  XSSH_V2,  0 },
  2361.     { "", 0, 0 }
  2362. };
  2363. static int nsshcmd = (sizeof(sshkwtab) / sizeof(struct keytab)) - 1;
  2364.  
  2365. static struct keytab ssh2tab[] = {
  2366.     { "rekey", XSSH2_RKE, 0 },
  2367.     { "", 0, 0 }
  2368. };
  2369. static int nssh2tab = (sizeof(ssh2tab) / sizeof(struct keytab));
  2370.  
  2371. static struct keytab addfwd[] = {    /* SET SSH ADD command table */
  2372.     { "local-port-forward",  SSHF_LCL, 0 },
  2373.     { "remote-port-forward", SSHF_RMT, 0 },
  2374.     { "", 0, 0 }
  2375. };
  2376. static int naddfwd = (sizeof(addfwd) / sizeof(struct keytab)) - 1;
  2377.  
  2378. static struct keytab sshagent[] = {    /* SET SSH AGENT command table */
  2379.     { "add",    SSHA_ADD, 0 },
  2380.     { "delete", SSHA_DEL, 0 },
  2381.     { "list",   SSHA_LST, 0 },
  2382.     { "", 0, 0 }
  2383. };
  2384. static int nsshagent = (sizeof(sshagent) / sizeof(struct keytab)) - 1;
  2385.  
  2386. static struct keytab sshagtsw[] = {    /* SET SSH AGENT LIST switch table */
  2387.     { "/fingerprint", SSHASW_FP, 0 },
  2388.     { "", 0, 0 }
  2389. };
  2390. static int nsshagtsw = (sizeof(sshagtsw) / sizeof(struct keytab)) - 1;
  2391.  
  2392. static struct keytab sshkey[] = {    /* SET SSH KEY command table */
  2393.     { "change-passphrase",  SSHK_PASS, 0 },
  2394.     { "create",             SSHK_CREA, 0 },
  2395.     { "display",            SSHK_DISP, 0 },
  2396.     { "v1",                 SSHK_V1,   0 },
  2397.     { "", 0, 0 }
  2398. };
  2399. static int nsshkey = (sizeof(sshkey) / sizeof(struct keytab)) - 1;
  2400.  
  2401. static struct keytab sshkv1[] = {    /* SET SSH KEY V1 command table */
  2402.     { "set-comment",  1, 0 }
  2403. };
  2404.  
  2405. static struct keytab sshkpsw[] = {    /* SET SSH KEY PASSPHRASE table */
  2406.     { "/new-passphrase",  2, CM_ARG },
  2407.     { "/old-passphrase",  1, CM_ARG }
  2408. };
  2409.  
  2410. static struct keytab sshkcrea[] = {    /* SSH KEY CREATE table */
  2411.     { "/bits",           SSHKC_BI, CM_ARG },
  2412.     { "/passphrase",     SSHKC_PP, CM_ARG },
  2413.     { "/type",           SSHKC_TY, CM_ARG },
  2414.     { "/v1-rsa-comment", SSHKC_1R, CM_ARG }
  2415. };
  2416. static int nsshkcrea = (sizeof(sshkcrea) / sizeof(struct keytab));
  2417.  
  2418. static struct keytab sshkcty[] = {    /* SSH KEY CREATE /TYPE:xxx */
  2419.     { "srp",    SSHKT_SRP, 0 },
  2420.     { "v1-rsa", SSHKT_1R, 0 },
  2421.     { "v2-dsa", SSHKT_2D, 0 },
  2422.     { "v2-rsa", SSHKT_2R, 0 }
  2423. };
  2424. static int nsshkcty = (sizeof(sshkcty) / sizeof(struct keytab));
  2425.  
  2426. static struct keytab sshdswi[] = {    /* SET SSH KEY DISPLAY /switches */
  2427.     { "/format", SSHKD_OUT, CM_ARG }
  2428. };
  2429. static int nsshdswi = (sizeof(sshdswi) / sizeof(struct keytab));
  2430.  
  2431. #ifdef COMMENT
  2432. static struct keytab sshdifmt[] = {    /* SSH KEY DISPLAY /IN-FORMAT: */
  2433.     { "openssh", SKDF_OSSH, 0 },
  2434.     { "ssh.com", SKDF_SSHC, 0 }
  2435. };
  2436. static int nsshdifmt = (sizeof(sshdifmt) / sizeof(struct keytab));
  2437. #endif /* COMMENT */
  2438.  
  2439. static struct keytab sshdofmt[] = {    /* SSH KEY DISPLAY /IN-FORMAT: */
  2440.     { "fingerprint", SKDF_FING, 0 },
  2441.     { "ietf",        SKDF_IETF, 0 },
  2442.     { "openssh",     SKDF_OSSH, 0 },
  2443.     { "ssh.com",     SKDF_SSHC, 0 }
  2444. };
  2445. static int nsshdofmt = (sizeof(sshdofmt) / sizeof(struct keytab));
  2446.  
  2447. static struct keytab sshkermit[] = { /* SKERMIT */
  2448.     { "open",       SKRM_OPN, 0 }
  2449. };
  2450. static int nsshkermit = (sizeof(sshkermit) / sizeof(struct keytab));
  2451.  
  2452. struct keytab sshkrmopnsw[] = {
  2453.     { "/password",       SSHSW_PWD, CM_ARG },
  2454.     { "/user",           SSHSW_USR, CM_ARG },
  2455.     { "/version",        SSHSW_VER, CM_ARG },
  2456.     { "", 0, 0 }
  2457. };
  2458. int nsshkrmopnsw = (sizeof(sshkrmopnsw) / sizeof(struct keytab)) - 1;
  2459. #endif /* SSHBUILTIN */
  2460.  
  2461. #ifdef SFTP_BUILTIN
  2462. static struct keytab sftpkwtab[] = {    /* SFTP */
  2463.     {  "cd",        SFTP_CD,    0 },
  2464.     {  "chgrp",     SFTP_CHGRP, 0 },
  2465.     {  "chmod",     SFTP_CHMOD, 0 },
  2466.     {  "chown",     SFTP_CHOWN, 0 },
  2467.     {  "delete",    SFTP_RM,    0 },
  2468.     {  "dir",       SFTP_DIR,   0 },
  2469.     {  "get",       SFTP_GET,   0 },
  2470.     {  "mkdir",     SFTP_MKDIR, 0 },
  2471.     {  "open",      SFTP_OPN,   0 },
  2472.     {  "put",       SFTP_PUT,   0 },
  2473.     {  "pwd",       SFTP_PWD,   0 },
  2474.     {  "rename",    SFTP_REN,   0 },
  2475.     {  "rm",        SFTP_RM,    CM_INV },
  2476.     {  "rmdir",     SFTP_RMDIR, 0 },
  2477.     {  "symlink",   SFTP_LINK,  0 },
  2478.     {  "version",   SFTP_VER,   0 }
  2479. };
  2480. static int nsftpkwtab = (sizeof(sftpkwtab) / sizeof(struct keytab));
  2481. #endif /* SFTP_BUILTIN */
  2482. #endif /* ANYSSH */
  2483.  
  2484. #ifdef NETCONN
  2485. struct keytab netkey[] = {        /* SET NETWORK table */
  2486.     { "directory", XYNET_D,  0 },
  2487.     { "type",      XYNET_T,  0 }
  2488. };
  2489. int nnetkey = (sizeof(netkey) / sizeof(struct keytab));
  2490.  
  2491. struct keytab netcmd[] = {
  2492. /*
  2493.   These are the network types.
  2494. */
  2495. #ifdef NETCMD
  2496.     { "command",       NET_CMD,  CM_INV }, /* Command */
  2497. #endif /* NETCMD */
  2498.  
  2499. #ifdef DECNET                /* DECnet / PATHWORKS */
  2500.     { "decnet",        NET_DEC,  0 },
  2501. #endif /* DECNET */
  2502.  
  2503. #ifdef NETDLL
  2504.     { "dll",           NET_DLL,  CM_INV }, /* DLL to be loaded */
  2505. #endif /* NETDLL */
  2506.  
  2507. #ifdef NETFILE
  2508.     { "file",           NET_FILE, CM_INV }, /* FILE (real crude) */
  2509. #endif /* NETFILE */
  2510.  
  2511. #ifdef NPIPE                /* Named Pipes */
  2512.     { "named-pipe",     NET_PIPE,  0 },
  2513. #endif /* NPIPE */
  2514.  
  2515. #ifdef CK_NETBIOS
  2516.     { "netbios",        NET_BIOS,  0 },    /* NETBIOS */
  2517. #endif /* CK_NETBIOS */
  2518.  
  2519. #ifdef DECNET                /* DECnet / PATHWORKS (alias) */
  2520.     { "pathworks",     NET_DEC,  CM_INV },
  2521. #endif /* DECNET */
  2522.  
  2523. #ifdef NETCMD
  2524.     { "pipe",          NET_CMD,  0 },    /* Pipe */
  2525. #endif /* NETCMD */
  2526.  
  2527. #ifdef NETPTY
  2528.     { "pseudoterminal",NET_PTY, 0 },    /* Pseudoterminal */
  2529. #endif /* NETPTY */
  2530.  
  2531. #ifdef NETPTY
  2532.     { "pty",          NET_PTY,  CM_INV }, /* Inv syn for pseudoterm */
  2533. #endif /* NETPTY */
  2534.  
  2535. #ifdef SSHBUILTIN
  2536.     { "ssh",          NET_SSH,  0 },
  2537. #endif /* SSHBUILTIN */
  2538.  
  2539. #ifdef SUPERLAT
  2540.     { "superlat",     NET_SLAT, 0 },    /* Meridian Technologies' SuperLAT */
  2541. #endif /* SUPERLAT */
  2542.  
  2543. #ifdef TCPSOCKET            /* TCP/IP sockets library */
  2544.     { "tcp/ip",       NET_TCPB, 0 },
  2545. #endif /* TCPSOCKET */
  2546. #ifdef SUPERLAT
  2547.     { "tes32",        NET_SLAT, 0 },    /* Emulux TES32 */
  2548. #endif /* SUPERLAT */
  2549. #ifdef ANYX25                /* X.25 */
  2550. #ifdef SUNX25
  2551.     { "x",            NET_SX25, CM_INV|CM_ABR },
  2552.     { "x.25",         NET_SX25, 0 },
  2553.     { "x25",          NET_SX25, CM_INV },
  2554. #else
  2555. #ifdef STRATUSX25
  2556.     { "x",            NET_VX25, CM_INV|CM_ABR },
  2557.     { "x.25",         NET_VX25, 0 },
  2558.     { "x25",          NET_VX25, CM_INV },
  2559. #endif /* STRATUSX25 */
  2560. #endif /* SUNX25 */
  2561. #ifdef IBMX25
  2562.     { "x",            NET_IX25, CM_INV|CM_ABR },
  2563.     { "x.25",         NET_IX25, CM_INV },
  2564.     { "x25",          NET_IX25, CM_INV },
  2565. #endif /* IBMX25 */
  2566. #ifdef HPX25
  2567.     { "x",            NET_IX25, CM_INV|CM_ABR },
  2568.     { "x.25",         NET_IX25, 0 },
  2569.     { "x25",          NET_IX25, CM_INV },
  2570. #endif /* HPX25 */
  2571. #endif /* ANYX25 */
  2572.     { "", 0, 0 }
  2573. };
  2574. int nnets = (sizeof(netcmd) / sizeof(struct keytab));
  2575.  
  2576. #ifndef NOTCPOPTS
  2577. #ifdef TCPSOCKET
  2578.  
  2579. /* TCP options */
  2580.  
  2581. struct keytab tcpopt[] = {
  2582.     { "address",   XYTCP_ADDRESS, 0 },
  2583. #ifdef CK_DNS_SRV
  2584.     { "dns-service-records", XYTCP_DNS_SRV, 0 },
  2585. #endif /* CK_DNS_SRV */
  2586. #ifdef SO_DONTROUTE
  2587.     { "dontroute",   XYTCP_DONTROUTE, 0 },
  2588. #endif /* SO_DONTROUTE */
  2589. #ifndef NOHTTP
  2590.     { "http-proxy", XYTCP_HTTP_PROXY, 0 },
  2591. #endif /* NOHTTP */
  2592. #ifdef SO_KEEPALIVE
  2593.     { "keepalive", XYTCP_KEEPALIVE, 0 },
  2594. #endif /* SO_KEEPALIVE */
  2595. #ifdef SO_LINGER
  2596.     { "linger", XYTCP_LINGER, 0 },
  2597. #endif /* SO_LINGER */
  2598. #ifdef TCP_NODELAY
  2599.     { "nagle",  XYTCP_NAGLE,    CM_INV },
  2600.     { "nodelay", XYTCP_NODELAY, 0 },
  2601. #endif /* TCP_NODELAY */
  2602.     { "reverse-dns-lookup", XYTCP_RDNS, 0 },
  2603. #ifdef SO_RCVBUF
  2604.     { "recvbuf", XYTCP_RECVBUF, 0 },
  2605. #endif /* SO_RCVBUF */
  2606. #ifdef SO_SNDBUF
  2607.     { "sendbuf", XYTCP_SENDBUF, 0 },
  2608. #endif /* SO_SNDBUF */
  2609. #ifdef NT
  2610. #ifdef CK_SOCKS
  2611.     { "socks-server", XYTCP_SOCKS_SVR, 0 },
  2612. #endif /* CK_SOCKS */
  2613. #endif /* NT */
  2614. #ifdef VMS
  2615. #ifdef DEC_TCPIP
  2616.     { "ucx-port-bug", XYTCP_UCX, 0 },
  2617. #endif /* DEC_TCPIP */
  2618. #endif /* VMS */
  2619.     { "",0,0 }
  2620. };
  2621. int ntcpopt = (sizeof(tcpopt) / sizeof(struct keytab));
  2622. #endif /* TCPSOCKET */
  2623. #endif /* NOTCPOPTS */
  2624. #endif /* NETCONN */
  2625.  
  2626. #ifdef OS2
  2627. /* K95 Manual Chapter Table -- Keep these two tables in sync! */
  2628.  
  2629. static char * linktbl[] = {        /* Internal links in k95.htm */
  2630.     "#top",                /* 00 */
  2631.     "#what",                /* 01 */
  2632.     "#install",                /* 02 */
  2633.     "#start",                /* 03 */
  2634.     "#dialer",                /* 04 */
  2635.     "#entries",                /* 05 */
  2636.     "#command",                /* 06 */
  2637.     "#terminal",            /* 07 */
  2638.     "#transfer",            /* 08 */
  2639.     "#hostmode"                /* 09 */
  2640. };
  2641.  
  2642. static struct keytab chaptbl[] = {
  2643.     { "Command-Screen",     6, 0 },
  2644.     { "Contents",           0, 0 },
  2645.     { "Dialer-Entries",     5, 0 },
  2646.     { "File-Transfer",      8, 0 },
  2647.     { "Getting-Started",    3, 0 },
  2648.     { "Host-Mode",          9, 0 },
  2649.     { "Installation",       2, 0 },
  2650.     { "Terminal-Emulation", 7, 0 },
  2651.     { "Using-The-Dialer",   4, 0 },
  2652.     { "What-Is-K95",        1, 0 },
  2653.     { "",                   0, 0 }
  2654. };
  2655. static int nchaptbl = (sizeof(chaptbl) / sizeof(struct keytab) - 1);
  2656. #endif /* OS2 */
  2657.  
  2658. #ifndef NOXFER
  2659. /* Remote Command Table */
  2660.  
  2661. struct keytab remcmd[] = {
  2662. #ifndef NOSPL
  2663.     { "as",        XZASG, CM_INV|CM_ABR },
  2664.     { "asg",       XZASG, CM_INV },
  2665.     { "assign",    XZASG, 0 },
  2666. #endif /* NOSPL */
  2667.     { "cd",        XZCWD, 0 },
  2668.     { "cdup",      XZCDU, CM_INV },
  2669.     { "copy",      XZCPY, 0 },
  2670.     { "cwd",       XZCWD, CM_INV },
  2671.     { "delete",    XZDEL, 0 },
  2672.     { "directory", XZDIR, 0 },
  2673.     { "e",         XZXIT, CM_ABR|CM_INV },
  2674.     { "erase",     XZDEL, CM_INV },
  2675.     { "exit",      XZXIT, 0 },
  2676.     { "help",      XZHLP, 0 },
  2677. #ifndef NOPUSH
  2678.     { "host",      XZHOS, 0 },
  2679. #endif /* NOPUSH */
  2680. #ifndef NOFRILLS
  2681.     { "kermit",    XZKER, 0 },
  2682.     { "l",         XZLGI, CM_ABR|CM_INV },
  2683.     { "lo",        XZLGI, CM_ABR|CM_INV },
  2684.     { "log",       XZLGI, CM_ABR|CM_INV },
  2685.     { "login",     XZLGI, 0 },
  2686.     { "logout",    XZLGO, 0 },
  2687.     { "message",   XZMSG, 0 },
  2688.     { "mkdir",     XZMKD, 0 },
  2689.     { "print",     XZPRI, 0 },
  2690. #endif /* NOFRILLS */
  2691.     { "pwd",       XZPWD, 0 },
  2692. #ifndef NOSPL
  2693.     { "query",       XZQUE, 0 },
  2694. #endif /* NOSPL */
  2695.     { "rename",    XZREN, 0 },
  2696.     { "rmdir",     XZRMD, 0 },
  2697.     { "set",       XZSET, 0 },
  2698.     { "space",       XZSPA, 0 },
  2699. #ifndef NOFRILLS
  2700.     { "type",      XZTYP, 0 },
  2701.     { "who",       XZWHO, 0 },
  2702. #endif /* NOFRILLS */
  2703.     { "", 0, 0}
  2704. };
  2705. int nrmt = (sizeof(remcmd) / sizeof(struct keytab)) - 1;
  2706. #endif /* NOXFER */
  2707.  
  2708. struct keytab logtab[] = {
  2709. #ifdef CKLOGDIAL
  2710.     { "connections",  LOGM, CM_INV },
  2711.     { "cx",           LOGM, 0 },
  2712. #endif /* CKLOGDIAL */
  2713. #ifdef DEBUG
  2714.     { "debugging",    LOGD, 0 },
  2715. #endif /* DEBUG */
  2716.     { "packets",      LOGP, 0 },
  2717. #ifndef NOLOCAL
  2718.     { "session",      LOGS, 0 },
  2719. #endif /* NOLOCAL */
  2720. #ifdef TLOG
  2721.     { "transactions", LOGT, 0 },
  2722. #endif /* TLOG */
  2723.     { "", 0, 0 }
  2724. };
  2725. int nlog = (sizeof(logtab) / sizeof(struct keytab)) - 1;
  2726.  
  2727. struct keytab writab[] = {
  2728. #ifndef NOSPL
  2729.     { "append-file",     LOGW, CM_INV },
  2730. #endif /* NOSPL */
  2731.     { "debug-log",       LOGD, 0 },
  2732.     { "error",           LOGE, 0 },
  2733. #ifndef NOSPL
  2734.     { "file",            LOGW, 0 },
  2735. #endif /* NOSPL */
  2736.     { "packet-log",      LOGP, 0 },
  2737.     { "screen",          LOGX, 0 },
  2738. #ifndef NOLOCAL
  2739.     { "session-log",     LOGS, 0 },
  2740. #endif /* NOLOCAL */
  2741.     { "sys$output",      LOGX, CM_INV },
  2742.     { "t",               LOGT, CM_ABR|CM_INV }, /* Because of a typo in */
  2743.     { "tr",              LOGT, CM_ABR|CM_INV }, /* the book... */
  2744.     { "tra",             LOGT, CM_ABR|CM_INV },
  2745.     { "tran",            LOGT, CM_ABR|CM_INV },
  2746.     { "trans",           LOGT, CM_ABR|CM_INV },
  2747.     { "transa",          LOGT, CM_ABR|CM_INV },
  2748.     { "transac",         LOGT, CM_ABR|CM_INV },
  2749.     { "transact",        LOGT, CM_ABR|CM_INV },
  2750.     { "transacti",       LOGT, CM_ABR|CM_INV },
  2751.     { "transactio",      LOGT, CM_ABR|CM_INV },
  2752.     { "transaction",     LOGT, CM_ABR|CM_INV },
  2753.     { "transaction-log", LOGT, 0 },
  2754.     { "transactions",    LOGT, CM_INV }
  2755. };
  2756. int nwri = (sizeof(writab) / sizeof(struct keytab));
  2757.  
  2758. static struct keytab clrtab[] = {    /* Keywords for CLEAR command */
  2759. #ifndef NOSPL
  2760.     { "alarm",            CLR_ALR,         0 },
  2761. #ifdef CK_APC
  2762.     { "apc",              CLR_APC,         0 },
  2763. #endif /* CK_APC */
  2764. #ifdef PATTERNS
  2765.     { "binary-patterns",  CLR_BIN,         0 },
  2766. #endif /* PATTERNS */
  2767.     { "both",             CLR_DEV|CLR_INP, CM_INV },
  2768. #endif /* NOSPL */
  2769. #ifdef OS2
  2770.     { "command-screen",   CLR_CMD,         0 },
  2771. #endif /* OS2 */
  2772. #ifndef NOSPL
  2773.     { "device",           CLR_DEV,         CM_INV|CM_ABR },
  2774.     { "device-and-input", CLR_DEV|CLR_INP, 0 },
  2775. #endif /* NOSPL */
  2776.     { "device-buffer",    CLR_DEV,         0 },
  2777. #ifndef NODIAL
  2778.     { "dial-status",      CLR_DIA,     0 },
  2779. #endif /* NODIAL */
  2780. #ifndef NOSPL
  2781.     { "input-buffer",     CLR_INP,         0 },
  2782. #endif /* NOSPL */
  2783.     { "keyboard-buffer",  CLR_KBD,         0 },
  2784.     { "send-list",        CLR_SFL,         0 },
  2785. #ifdef OS2
  2786.     { "scr",              CLR_SCL,         CM_INV|CM_ABR },
  2787. #endif /* OS2 */
  2788.     { "screen",           CLR_SCR,         0 },
  2789. #ifdef OS2
  2790.     { "scrollback",       CLR_SCL,         CM_INV },
  2791.     { "terminal-screen",  CLR_TRM,         0 },
  2792. #endif /* OS2 */
  2793. #ifdef PATTERNS
  2794.     { "text-patterns",    CLR_TXT,         0 },
  2795. #endif /* PATTERNS */
  2796.     { "", 0, 0 }
  2797. };
  2798. int nclear = (sizeof(clrtab) / sizeof(struct keytab)) - 1;
  2799.  
  2800. struct keytab clstab[] = {        /* Keywords for CLOSE command */
  2801. #ifndef NOSPL
  2802.     { "!read",           LOGR, CM_INV },
  2803.     { "!write",          LOGW, CM_INV },
  2804. #ifndef NOPUSH
  2805. #endif /* NOPUSH */
  2806. #endif /* NOSPL */
  2807. #ifndef NOSPL
  2808.     { "append-file",     LOGW, CM_INV },
  2809. #endif /* NOSPL */
  2810. #ifndef NOLOCAL
  2811.     { "connection",      9999, 0 },
  2812. #endif /* NOLOCAL */
  2813. #ifdef CKLOGDIAL
  2814.     { "cx-log",          LOGM, 0 },
  2815. #endif /* CKLOGDIAL */
  2816. #ifdef DEBUG
  2817.     { "debug-log",       LOGD, 0 },
  2818. #endif /* DEBUG */
  2819.     { "host",            9999, CM_INV }, /* Synonym for CLOSE CONNECTION */
  2820.     { "line",            9999, CM_INV }, /* Synonym for CLOSE CONNECTION */
  2821.     { "p",               LOGP, CM_INV|CM_ABR },
  2822.     { "packet-log",      LOGP, 0 },
  2823.     { "port",            9999, CM_INV }, /* Synonym for CLOSE CONNECTION */
  2824. #ifndef NOSPL
  2825.     { "read-file",       LOGR, 0 },
  2826. #endif /* NOSPL */
  2827. #ifndef NOLOCAL
  2828.     { "session-log",     LOGS, 0 },
  2829. #endif /* NOLOCAL */
  2830. #ifdef TLOG
  2831.     { "t",               LOGT, CM_ABR|CM_INV }, /* Because of a typo in */
  2832.     { "tr",              LOGT, CM_ABR|CM_INV }, /* the book... */
  2833.     { "tra",             LOGT, CM_ABR|CM_INV },
  2834.     { "tran",            LOGT, CM_ABR|CM_INV },
  2835.     { "trans",           LOGT, CM_ABR|CM_INV },
  2836.     { "transa",          LOGT, CM_ABR|CM_INV },
  2837.     { "transac",         LOGT, CM_ABR|CM_INV },
  2838.     { "transact",        LOGT, CM_ABR|CM_INV },
  2839.     { "transacti",       LOGT, CM_ABR|CM_INV },
  2840.     { "transactio",      LOGT, CM_ABR|CM_INV },
  2841.     { "transaction",     LOGT, CM_ABR|CM_INV },
  2842.     { "transaction-log", LOGT, 0 },
  2843.     { "transactions",    LOGT, CM_INV },
  2844. #endif /* TLOG */
  2845. #ifndef NOSPL
  2846.     { "write-file",      LOGW, 0 },
  2847. #endif /* NOSPL */
  2848.     { "", 0, 0 }
  2849. };
  2850. int ncls = (sizeof(clstab) / sizeof(struct keytab)) - 1;
  2851.  
  2852. /* SHOW command arguments */
  2853.  
  2854. #ifndef NOSHOW
  2855. struct keytab shotab[] = {
  2856. #ifndef NOSPL
  2857.     { "alarm",        SHALRM, 0 },
  2858.     { "arg",          SHARG, CM_INV|CM_ABR },
  2859.     { "arguments",    SHARG, 0 },
  2860.     { "args",         SHARG, CM_INV },
  2861.     { "arrays",       SHARR, 0 },
  2862. #endif /* NOSPL */
  2863.  
  2864. #ifndef NOCSETS
  2865.     { "associations", SHASSOC, 0 },
  2866. #endif /* NOCSETS */
  2867.  
  2868. #ifndef NOXFER
  2869.     { "attributes",   SHATT, 0 },
  2870. #endif /* NOXFER */
  2871.  
  2872. #ifdef CK_AUTHENTICATION
  2873.     { "authentication", SHOAUTH, CM_INV },
  2874. #endif /* CK_AUTHENTICATION */
  2875.  
  2876. #ifndef NOPUSH
  2877. #ifdef BROWSER
  2878.     { "browser",      SHBROWSE, CM_PSH|CM_LOC },
  2879. #endif /*  BROWSER */
  2880. #endif /* NOPUSH */
  2881.     { "cd",           SHCD, 0 },
  2882.     { "character-sets", SHCSE, 0 },
  2883.     { "cmd",          SHCMD, CM_INV },
  2884. #ifndef NOLOCAL
  2885.     { "com",          SHCOM, CM_INV|CM_ABR },
  2886.     { "comm",         SHCOM, CM_INV|CM_ABR },
  2887.     { "communications", SHCOM, 0 },
  2888. #endif /* NOLOCAL */
  2889.     { "command",      SHCMD, 0 },
  2890.     { "connection",   SHCONNX, 0 },
  2891. #ifdef CK_SPEED
  2892.     { "control-prefixing", SHCTL, 0 },
  2893. #endif /* CK_SPEED */
  2894. #ifdef CKLOGDIAL
  2895.     { "cx",           SHCONNX, CM_INV },
  2896. #endif /* CKLOGDIAL */
  2897. #ifndef NOSPL
  2898.     { "count",        SHCOU, 0 },
  2899. #endif /* NOSPL */
  2900.     { "d",            SHDIA, CM_INV|CM_ABR },
  2901. #ifdef VMS
  2902.     { "default",      SHDFLT, 0 },
  2903. #else
  2904.     { "default",      SHDFLT, CM_INV },
  2905. #endif /* VMS */
  2906. #ifndef NODIAL
  2907.     { "dial",         SHDIA, CM_LOC },
  2908. #endif /* NODIAL */
  2909.     { "double/ignore",SHDBL, 0 },
  2910. #ifndef NOPUSH
  2911. #ifndef NOFRILLS
  2912.     { "editor",       SHEDIT, CM_PSH },
  2913. #endif /*  NOFRILLS */
  2914. #endif /* NOPUSH */
  2915. #ifndef NOLOCAL
  2916.     { "escape",       SHESC, CM_LOC },
  2917. #endif /* NOLOCAL */
  2918.     { "exit",         SHEXI, 0 },
  2919.     { "extended-options", SHXOPT, CM_INV },
  2920.     { "features",     SHFEA, 0 },
  2921.     { "file",         SHFIL, 0 },
  2922. #ifndef NOLOCAL
  2923.     { "flow-control", SHOFLO, 0 },
  2924. #endif /* NOLOCAL */
  2925. #ifdef BROWSER
  2926.     { "ftp",          SHOFTP, CM_PSH|CM_LOC },
  2927. #else
  2928. #ifndef NOFTP
  2929. #ifndef SYSFTP
  2930. #ifdef TCPSOCKET
  2931.     { "ftp",          SHOFTP, 0 },    /* (built-in ftp) */
  2932. #endif /* TCPSOCKET */
  2933. #endif /* SYSFTP */
  2934. #endif /* NOFTP */
  2935. #endif /* BROWSER */
  2936. #ifndef NOSPL
  2937.     { "functions",    SHFUN, 0 },
  2938.     { "globals",      SHVAR, 0 },
  2939. #endif /* NOSPL */
  2940. #ifdef KUI
  2941.     { "gui",          SHOGUI, 0 },
  2942. #endif /* KUI */
  2943. #ifdef CK_RECALL
  2944.     { "history",      SHHISTORY, 0 },
  2945. #endif /* CK_RECALL */
  2946.     { "ignore/double",SHDBL, CM_INV },
  2947.     { "iksd",         SHOIKS, CM_INV },
  2948. #ifndef NOSPL
  2949.     { "input",        SHINP, 0 },
  2950. #endif /* NOSPL */
  2951. #ifndef NOSETKEY
  2952.     { "k",            SHKEY, CM_INV|CM_ABR },
  2953.     { "key",          SHKEY, 0 },
  2954. #ifndef NOKVERBS
  2955.     { "kverbs",       SHKVB, 0 },
  2956. #endif /* NOKVERBS */
  2957. #endif /* NOSETKEY */
  2958. #ifdef CK_LABELED
  2959.     { "labeled-file-info", SHLBL, 0 },
  2960. #endif /* CK_LABELED */
  2961. #ifndef NOCSETS
  2962.     { "languages",    SHLNG, 0 },
  2963. #endif /* NOCSETS */
  2964.     { "logs",         SHLOG, 0 },
  2965. #ifndef NOSPL
  2966.     { "macros",       SHMAC, 0 },
  2967. #endif /* NOSPL */
  2968. #ifndef NODIAL
  2969.     { "modem",        SHMOD, CM_LOC },
  2970. #else
  2971.     { "modem-signals",SHCOM, CM_INV|CM_LOC },
  2972. #endif /* NODIAL */
  2973. #ifndef NOLOCAL
  2974. #ifdef OS2MOUSE
  2975.     { "mouse",        SHMOU, CM_LOC },
  2976. #endif /* OS2MOUSE */
  2977. #endif /* NOLOCAL */
  2978. #ifdef NETCONN
  2979.     { "network",      SHNET, CM_LOC },
  2980. #else
  2981.     { "network",      SHNET, CM_INV|CM_LOC },
  2982. #endif /* NETCONN */
  2983.     { "options",      SHOPTS, 0 },
  2984. #ifndef NOSPL
  2985.     { "output",       SHOUTP, CM_INV },
  2986. #endif /* NOSPL */
  2987. #ifdef ANYX25
  2988. #ifndef IBMX25
  2989.     { "pad",          SHPAD,  CM_LOC },
  2990. #endif /* IBMX25 */
  2991. #endif /* ANYX25 */
  2992.     { "parameters",   SHPAR,  CM_INV },
  2993. #ifdef PATTERNS
  2994.     { "patterns",     SHOPAT, 0 },
  2995. #endif /* PATTERNS */
  2996.     { "printer",      SHPRT,  0 },
  2997. #ifdef CK_SPEED
  2998.     { "prefixing",    SHCTL,  CM_INV },
  2999. #endif /* CK_SPEED */
  3000. #ifndef NOXFER
  3001.     { "protocol",     SHPRO,  0 },
  3002. #endif /* NOXFER */
  3003.     { "rename",       SHOREN, 0 },
  3004. #ifndef NOSPL
  3005.     { "scripts",      SHSCR,  CM_LOC },
  3006. #endif /* NOSPL */
  3007.     { "send-list",    SHSFL,  0 },
  3008. #ifndef NOSERVER
  3009.     { "server",       SHSER,  0 },
  3010. #endif /* NOSERVER */
  3011. #ifndef NOSEXP
  3012.     { "sexpression",  SHSEXP, 0 },
  3013. #endif /* NOSEXP */
  3014. #ifdef ANYSSH
  3015.     { "ssh",          SHOSSH, 0 },
  3016. #endif /* ANYSSH */
  3017.     { "stack",        SHSTK,  0 },
  3018.     { "status",       SHSTA,  0 },
  3019. #ifdef STREAMING
  3020.     { "streaming",    SHOSTR, 0 },
  3021. #endif /* STREAMING */
  3022. #ifndef NOLOCAL
  3023. #ifdef OS2
  3024.     { "tabs",          SHTAB, CM_INV|CM_LOC },
  3025. #endif /* OS2 */
  3026. #ifdef CK_TAPI
  3027.     { "tapi",          SHTAPI, CM_LOC },
  3028.     { "tapi-comm",     SHTAPI_C, CM_INV|CM_LOC },
  3029.     { "tapi-location", SHTAPI_L, CM_INV|CM_LOC },
  3030.     { "tapi-modem",    SHTAPI_M, CM_INV|CM_LOC },
  3031. #endif /* CK_TAPI */
  3032.     { "tcp",           SHTCP,  CM_LOC },
  3033. #ifdef TNCODE
  3034.     { "tel",           SHTEL,  CM_INV|CM_ABR },
  3035.     { "telnet",        SHTEL,  0 },
  3036.     { "telopt",        SHTOPT, 0 },
  3037. #endif /* TNCODE */
  3038.     { "terminal",      SHTER,  CM_LOC },
  3039. #endif /* NOLOCAL */
  3040. #ifndef NOXMIT
  3041.     { "tr",            SHXMI, CM_INV|CM_ABR },
  3042.     { "tra",           SHXMI, CM_INV|CM_ABR },
  3043.     { "tran",          SHXMI, CM_INV|CM_ABR },
  3044.     { "trans",         SHXMI, CM_INV|CM_ABR },
  3045. #endif /* NOXMIT */
  3046. #ifndef NOXFER
  3047.     { "transfer",      SHOXFER, 0 },
  3048. #endif /* NOXFER */
  3049. #ifndef NOXMIT
  3050.     { "transmit",      SHXMI, 0 },
  3051. #endif /* NOXMIT */
  3052. #ifdef CK_TRIGGER
  3053.     { "trigger",       SHTRIG, CM_LOC },
  3054. #endif /* CK_TRIGGER */
  3055. #ifndef NOSETKEY
  3056. #ifndef NOKVERBS
  3057. #ifdef OS2
  3058.     { "udk",           SHUDK, CM_LOC },
  3059. #endif /* OS2 */
  3060. #endif /* NOKVERBS */
  3061. #endif /* NOSETKEY */
  3062. #ifndef NOSPL
  3063.     { "variables",     SHBUI, 0 },
  3064. #endif /* NOSPL */
  3065. #ifndef NOFRILLS
  3066.     { "versions",      SHVER, 0 },
  3067. #endif /* NOFRILLS */
  3068. #ifdef OS2
  3069.     { "vscrn",         SHVSCRN, CM_INV|CM_LOC },
  3070. #endif /* OS2 */
  3071.     { "xfer",          SHOXFER,  CM_INV },
  3072. #ifndef NOXMIT
  3073.     { "xmit",          SHXMI,    CM_INV },
  3074. #endif /* NOXMIT */
  3075.     { "", 0, 0 }
  3076. };
  3077. int nsho = (sizeof(shotab) / sizeof(struct keytab)) - 1;
  3078. #endif /* NOSHOW */
  3079.  
  3080. #ifdef ANYX25
  3081. #ifndef IBMX25
  3082. struct keytab padtab[] = {              /* PAD commands */
  3083.     { "clear",      XYPADL, 0 },
  3084.     { "interrupt",  XYPADI, 0 },
  3085.     { "reset",      XYPADR, 0 },
  3086.     { "status",     XYPADS, 0 }
  3087. };
  3088. int npadc = (sizeof(padtab) / sizeof(struct keytab));
  3089. #endif /* IBMX25 */
  3090. #endif /* ANYX25 */
  3091.  
  3092. #ifndef NOSERVER
  3093. static struct keytab kmstab[] = {
  3094.     { "both",    3, 0 },
  3095.     { "local",   1, 0 },
  3096.     { "remote",  2, 0 }
  3097. };
  3098.  
  3099. static struct keytab enatab[] = {    /* ENABLE commands */
  3100.     { "all",        EN_ALL,  0 },
  3101. #ifndef NOSPL
  3102.     { "as",         EN_ASG,  CM_INV|CM_ABR },
  3103.     { "asg",        EN_ASG,  CM_INV },
  3104.     { "assign",     EN_ASG,  0 },
  3105. #endif /* NOSPL */
  3106. #ifndef datageneral
  3107.     { "bye",        EN_BYE,  0 },
  3108. #endif /* datageneral */
  3109.     { "cd",         EN_CWD,  0 },
  3110. #ifdef ZCOPY
  3111.     { "copy",       EN_CPY,  0 },
  3112. #endif /* ZCOPY */
  3113.     { "cwd",        EN_CWD,  CM_INV },
  3114.     { "delete",     EN_DEL,  0 },
  3115.     { "directory",  EN_DIR,  0 },
  3116.     { "enable",     EN_ENA,  CM_INV },
  3117.     { "exit",       EN_XIT,  0 },
  3118.     { "finish",     EN_FIN,  0 },
  3119.     { "get",        EN_GET,  0 },
  3120.     { "host",       EN_HOS,  0 },
  3121.     { "mail",       EN_MAI,  0 },
  3122.     { "mkdir",      EN_MKD,  0 },
  3123.     { "print",      EN_PRI,  0 },
  3124. #ifndef NOSPL
  3125.     { "query",      EN_QUE,  0 },
  3126. #endif /* NOSPL */
  3127.     { "rename",     EN_REN,  0 },
  3128.     { "retrieve",   EN_RET,  CM_INV },
  3129.     { "rmdir",      EN_RMD,  0 },
  3130.     { "send",       EN_SEN,  0 },
  3131.     { "set",        EN_SET,  0 },
  3132.     { "space",      EN_SPA,  0 },
  3133.     { "type",       EN_TYP,  0 },
  3134.     { "who",        EN_WHO,  0 }
  3135. };
  3136. static int nena = (sizeof(enatab) / sizeof(struct keytab));
  3137. #endif /* NOSERVER */
  3138.  
  3139. struct keytab txtbin[] = {
  3140.     { "all",        2, 0 },
  3141.     { "binary",     1, 0 },
  3142.     { "text",       0, 0 }
  3143. };
  3144.  
  3145. #ifndef NOXFER
  3146. static struct keytab sndtab[] = {    /* SEND command options */
  3147.     { "/after",           SND_AFT, CM_ARG },
  3148. #ifndef NOSPL
  3149.     { "/array",           SND_ARR, CM_ARG },
  3150. #endif /* NOSPL */
  3151.     { "/as-name",         SND_ASN, CM_ARG },
  3152.     { "/b",               SND_BIN, CM_INV|CM_ABR },
  3153.     { "/before",          SND_BEF, CM_ARG },
  3154.     { "/binary",          SND_BIN, 0 },
  3155. #ifdef CALIBRATE
  3156.     { "/c",               SND_CMD, CM_INV|CM_ABR },
  3157.     { "/calibrate",       SND_CAL, CM_INV|CM_ARG },
  3158. #endif /* CALIBRATE */
  3159.     { "/command",         SND_CMD, CM_PSH },
  3160.     { "/delete",          SND_DEL, 0 },
  3161. #ifdef UNIXOROSK
  3162.     { "/dotfiles",        SND_DOT, 0 },
  3163. #endif /* UNIXOROSK */
  3164.     { "/except",          SND_EXC, CM_ARG },
  3165. #ifdef PIPESEND
  3166.     { "/filter",          SND_FLT, CM_ARG|CM_PSH },
  3167. #endif /* PIPESEND */
  3168.     { "/filenames",       SND_NAM, CM_ARG },
  3169. #ifdef CKSYMLINK
  3170.     { "/followlinks",      SND_LNK, 0 },
  3171. #endif /* CKSYMLINK */
  3172. #ifdef VMS
  3173.     { "/image",           SND_IMG, 0 },
  3174. #else
  3175.     { "/image",           SND_BIN, CM_INV },
  3176. #endif /* VMS */
  3177. #ifdef CK_LABELED
  3178.     { "/labeled",         SND_LBL, 0 },
  3179. #endif /* CK_LABELED */
  3180.     { "/larger-than",     SND_LAR, CM_ARG },
  3181.     { "/listfile",        SND_FIL, CM_ARG },
  3182. #ifndef NOFRILLS
  3183.     { "/mail",            SND_MAI, CM_ARG },
  3184. #endif /* NOFRILLS */
  3185. #ifdef CK_TMPDIR
  3186.     { "/move-to",         SND_MOV, CM_ARG },
  3187. #endif /* CK_TMPDIR */
  3188.     { "/nobackupfiles",   SND_NOB, 0 },
  3189. #ifdef UNIXOROSK
  3190.     { "/nodotfiles",      SND_NOD, 0 },
  3191. #endif /* UNIXOROSK */
  3192. #ifdef CKSYMLINK
  3193.     { "/nofollowlinks",      SND_NLK, 0 },
  3194. #endif /* CKSYMLINK */
  3195.     { "/not-after",       SND_NAF, CM_ARG },
  3196.     { "/not-before",      SND_NBE, CM_ARG },
  3197.     { "/pathnames",       SND_PTH, CM_ARG },
  3198.     { "/print",           SND_PRI, CM_ARG },
  3199. #ifdef CK_XYZ
  3200.     { "/protocol",        SND_PRO, CM_ARG },
  3201. #else
  3202.     { "/protocol",        SND_PRO, CM_ARG|CM_INV },
  3203. #endif /* CK_XYZ */
  3204.     { "/quiet",           SND_SHH, 0 },
  3205.     { "/recover",         SND_RES, 0 },
  3206. #ifdef RECURSIVE
  3207. /* Systems where we do recursion */
  3208.     { "/recursive",       SND_REC, 0 },
  3209. #else
  3210. #ifdef VMS
  3211. /* Systems that do recursion themselves without our assistance */
  3212. /* if we give them the right kind of wildcard */
  3213.     { "/recursive",       SND_REC, 0 },
  3214. #else
  3215. #ifdef datageneral
  3216.     { "/recursive",       SND_REC, 0 },
  3217. #else
  3218.     { "/recursive",       SND_REC, CM_INV },
  3219. #endif /* datageneral */
  3220. #endif /* VMS */
  3221. #endif /* RECURSIVE */
  3222.     { "/rename-to",       SND_REN, CM_ARG },
  3223.     { "/since",           SND_AFT, CM_INV|CM_ARG },
  3224.     { "/smaller-than",    SND_SMA, CM_ARG },
  3225.     { "/starting-at",     SND_STA, CM_ARG },
  3226. #ifndef NOFRILLS
  3227.     { "/su",              SND_ASN, CM_ARG|CM_INV|CM_ABR },
  3228.     { "/sub",             SND_ASN, CM_ARG|CM_INV|CM_ABR },
  3229.     { "/subject",         SND_ASN, CM_ARG },
  3230. #endif /* NOFRILLS */
  3231. #ifdef RECURSIVE
  3232.     { "/subdirectories",  SND_REC, CM_INV },
  3233. #endif /* RECURSIVE */
  3234.     { "/text",            SND_TXT, 0 },
  3235.     { "/transparent",     SND_XPA, 0 },
  3236.     { "/type",            SND_TYP, CM_ARG }
  3237. };
  3238. #define NSNDTAB sizeof(sndtab)/sizeof(struct keytab)
  3239. static int nsndtab = NSNDTAB;
  3240.  
  3241. #ifndef NOMSEND
  3242. static struct keytab msndtab[] = {    /* MSEND options */
  3243.     { "/after",           SND_AFT, CM_ARG },
  3244.     { "/before",          SND_BEF, CM_ARG },
  3245.     { "/binary",          SND_BIN, 0 },
  3246.     { "/delete",          SND_DEL, 0 },
  3247.     { "/except",          SND_EXC, CM_ARG },
  3248.     { "/filenames",       SND_NAM, CM_ARG },
  3249. #ifdef CKSYMLINK
  3250.     { "/followlinks",      SND_LNK, 0 },
  3251. #endif /* CKSYMLINK */
  3252. #ifdef VMS
  3253.     { "/image",           SND_IMG, 0 },
  3254. #else
  3255.     { "/image",           SND_BIN, CM_INV },
  3256. #endif /* VMS */
  3257. #ifdef CK_LABELED
  3258.     { "/labeled",         SND_LBL, 0 },
  3259. #endif /* CK_LABELED */
  3260.     { "/larger-than",     SND_LAR, CM_ARG },
  3261.     { "/list",            SND_FIL, CM_ARG },
  3262. #ifndef NOFRILLS
  3263.     { "/mail",            SND_MAI, CM_ARG },
  3264. #endif /* NOFRILLS */
  3265. #ifdef CK_TMPDIR
  3266.     { "/move-to",         SND_MOV, CM_ARG },
  3267. #endif /* CK_TMPDIR */
  3268. #ifdef CKSYMLINK
  3269.     { "/nofollowlinks",    SND_NLK, 0 },
  3270. #endif /* CKSYMLINK */
  3271.     { "/not-after",       SND_NAF, CM_ARG },
  3272.     { "/not-before",      SND_NBE, CM_ARG },
  3273.     { "/pathnames",       SND_PTH, CM_ARG },
  3274.     { "/print",           SND_PRI, CM_ARG },
  3275. #ifdef CK_XYZ
  3276.     { "/protocol",        SND_PRO, CM_ARG },
  3277. #endif /* CK_XYZ */
  3278.     { "/quiet",           SND_SHH, 0 },
  3279.     { "/recover",         SND_RES, 0 },
  3280.     { "/rename-to",       SND_REN, CM_ARG },
  3281.     { "/since",           SND_AFT, CM_INV|CM_ARG },
  3282.     { "/smaller-than",    SND_SMA, CM_ARG },
  3283.     { "/starting-at",     SND_STA, CM_ARG },
  3284. #ifndef NOFRILLS
  3285.     { "/subject",         SND_ASN, CM_ARG },
  3286. #endif /* NOFRILLS */
  3287.     { "/text",            SND_TXT, 0 },
  3288.     { "/transparent",     SND_XPA, 0 },
  3289.     { "/type",            SND_TYP, CM_ARG }
  3290. };
  3291. #define NMSNDTAB sizeof(msndtab)/sizeof(struct keytab)
  3292. static int nmsndtab = NMSNDTAB;
  3293. #endif /* NOMSEND */
  3294. #endif /* NOXFER */
  3295.  
  3296. /* CONNECT command switches */
  3297.  
  3298. #define CONN_II  0    /* Idle interval */
  3299. #define CONN_IS  1    /* Idle string */
  3300. #define CONN_IL  2    /* Idle limit */
  3301. #define CONN_NV  3    /* Non-Verbose */
  3302. #define CONN_TL  4    /* Time limit */
  3303. #define CONN_TS  5    /* Trigger string */
  3304. #define CONN_AS  6    /* Asynchronous */
  3305. #define CONN_SY  7    /* Synchronous */
  3306. #define CONN_MAX 7    /* Number of CONNECT switches */
  3307.  
  3308. #ifndef NOLOCAL
  3309. static struct keytab conntab[] = {
  3310. #ifdef OS2
  3311.     { "/asynchronous",    CONN_AS, CM_INV },
  3312. #endif /* OS2 */
  3313. #ifdef XLIMITS
  3314.     { "/idle-interval",   CONN_II, CM_ARG },
  3315.     { "/idle-limit",      CONN_IL, CM_ARG },
  3316.     { "/idle-string",     CONN_IS, CM_ARG },
  3317.     { "/quietly",         CONN_NV, CM_INV },
  3318. #else
  3319.     { "/quietly",         CONN_NV, 0 },
  3320. #endif /* XLIMITS */
  3321. #ifdef OS2
  3322.     { "/synchronous",     CONN_SY, CM_INV },
  3323. #endif /* OS2 */
  3324. #ifdef XLIMITS
  3325.     { "/time-limit",      CONN_TL, CM_ARG },
  3326. #endif /* XLIMITS */
  3327. #ifdef CK_TRIGGER
  3328.     { "/trigger",         CONN_TS, CM_ARG },
  3329. #endif /* CK_TRIGGER */
  3330.     { "",0,0 }
  3331. };
  3332. #define NCONNTAB sizeof(conntab)/sizeof(struct keytab)
  3333. static int nconntab = NCONNTAB;
  3334. #endif /* NOLOCAL */
  3335.  
  3336. #ifndef NOXFER
  3337. static struct keytab stattab[] = {    /* STATISTICS command switches */
  3338.     { "/brief",   1, 0 },
  3339.     { "/verbose", 0, 0 }
  3340. };
  3341. #endif /* NOXFER */
  3342.  
  3343. #ifndef NOSPL
  3344. #ifdef COMMENT
  3345. struct mtab mactab[MAC_MAX] = {        /* Preinitialized macro table */
  3346.     { NULL, NULL, 0 }
  3347. };
  3348. #else
  3349. struct mtab *mactab;            /* Dynamically allocated macro table */
  3350. #endif /* COMMENT */
  3351. int nmac = 0;
  3352.  
  3353. struct keytab mackey[MAC_MAX];        /* Macro names as command keywords */
  3354. #endif /* NOSPL */
  3355.  
  3356. #ifndef NOSPL
  3357. #ifdef  OS2
  3358. struct keytab beeptab[] = {        /* Beep options */
  3359.     { "error", BP_FAIL, 0 },
  3360.     { "information", BP_NOTE, 0 },
  3361.     { "warning", BP_WARN, 0 }
  3362. };
  3363. int nbeeptab = sizeof(beeptab)/sizeof(struct keytab);
  3364.  
  3365. /* CLEAR COMMMAND-SCREEN options */
  3366.  
  3367. #define CLR_C_ALL 0
  3368. #define CLR_C_BOL 1
  3369. #define CLR_C_BOS 2
  3370. #define CLR_C_EOL 3
  3371. #define CLR_C_EOS 4
  3372. #define CLR_C_LIN 5
  3373. #define CLR_C_SCR 6
  3374.  
  3375. struct keytab clrcmdtab[] = {
  3376.     { "all",        CLR_C_ALL, 0 },
  3377.     { "bol",        CLR_C_BOL, 0 },
  3378.     { "bos",        CLR_C_BOS, 0 },
  3379.     { "eol",        CLR_C_EOL, 0 },
  3380.     { "eos",        CLR_C_EOS, 0 },
  3381.     { "line",       CLR_C_LIN, 0 },
  3382.     { "scrollback", CLR_C_SCR, 0 }
  3383. };
  3384. int nclrcmd = sizeof(clrcmdtab)/sizeof(struct keytab);
  3385. #endif /* OS2 */
  3386. #endif /* NOSPL */
  3387.  
  3388. #ifdef COMMENT
  3389. /* Not used at present */
  3390. static struct keytab pagetab[] = {
  3391.     { "/more",   1, CM_INV },
  3392.     { "/nopage", 0, 0 },
  3393.     { "/page",   1, 0 }
  3394. };
  3395. int npagetab = sizeof(pagetab)/sizeof(struct keytab);
  3396. #endif /* COMMENT */
  3397.  
  3398. #define TYP_NOP  0            /* /NOPAGE */
  3399. #define TYP_PAG  1            /* /PAGE */
  3400. #define TYP_HEA  2            /* /HEAD:n */
  3401. #define TYP_TAI  3            /* /TAIL:n */
  3402. #define TYP_PAT  4            /* /MATCH:pattern */
  3403. #define TYP_WID  5            /* /WIDTH:cols */
  3404. #define TYP_COU  6            /* /COUNT */
  3405. #define TYP_OUT  7            /* /OUTPUT:file */
  3406. #define TYP_PFX  8            /* /PREFIX:string */
  3407. #ifdef UNICODE
  3408. #define TYP_XIN  9            /* /TRANSLATE-FROM:charset */
  3409. #define TYP_XUT 10            /* /TRANSLATE-TO:charset */
  3410. #define TYP_XPA 11            /* /TRANSPARENT */
  3411. #endif /* UNICODE */
  3412. #ifdef KUI
  3413. #define TYP_GUI 12            /* /GUI:title */
  3414. #define TYP_HIG 13            /* /HEIGHT:rows */
  3415. #endif /* KUI */
  3416. #define TYP_NUM 14            /* /NUMBER */
  3417.  
  3418. static struct keytab typetab[] = {    /* TYPE command switches */
  3419.     { "/count",          TYP_COU, 0 },
  3420. #ifdef UNICODE
  3421.     { "/character-set",  TYP_XIN, CM_ARG },
  3422. #endif /* UNICODE */
  3423. #ifdef KUI
  3424.     { "/gui",            TYP_GUI, CM_ARG },
  3425. #endif /* KUI */
  3426.     { "/head",           TYP_HEA, CM_ARG },
  3427. #ifdef KUI
  3428.     { "/height",         TYP_HIG, CM_ARG },
  3429. #endif /* KUI */
  3430.     { "/match",          TYP_PAT, CM_ARG },
  3431. #ifdef CK_TTGWSIZ
  3432.     { "/more",           TYP_PAG, CM_INV },
  3433.     { "/nopage",         TYP_NOP, 0 },
  3434.     { "/number",         TYP_NUM, 0 },
  3435.     { "/output",         TYP_OUT, CM_ARG },
  3436.     { "/page",           TYP_PAG, 0 },
  3437. #endif /* CK_TTGWSIZ */
  3438.     { "/prefix",         TYP_PFX, CM_ARG },
  3439.     { "/tail",           TYP_TAI, CM_ARG },
  3440. #ifdef UNICODE
  3441.     { "/translate-to",   TYP_XUT, CM_ARG },
  3442.     { "/transparent",    TYP_XPA, 0 },
  3443. #endif /* UNICODE */
  3444.     { "/width",          TYP_WID, CM_ARG },
  3445. #ifdef UNICODE
  3446.     { "/xlate-to",       TYP_XUT, CM_INV|CM_ARG },
  3447. #endif /* UNICODE */
  3448.     { "", 0, 0 }
  3449. };
  3450. int ntypetab = sizeof(typetab)/sizeof(struct keytab) - 1;
  3451.  
  3452. int typ_page = -1;            /* TYPE /[NO]PAGE default */
  3453. int typ_wid  = -1;
  3454.  
  3455. #ifndef NOSPL
  3456. #define TRA_ALL 999            /* TRACE command */
  3457. #define TRA_ASG 0
  3458. #define TRA_CMD 1
  3459.  
  3460. int tra_asg = 0;
  3461. int tra_cmd = 0;
  3462.  
  3463. static struct keytab tracetab[] = {    /* TRACE options */
  3464.     { "all",            TRA_ALL, 0 },
  3465.     { "assignments",    TRA_ASG, 0 },
  3466.     { "command-level",  TRA_CMD, 0 }
  3467. };
  3468. static int ntracetab = sizeof(tracetab)/sizeof(struct keytab);
  3469. #endif /* NOSPL */
  3470.  
  3471. #ifndef NOSHOW
  3472. VOID
  3473. showtypopts() {
  3474.     printf(" TYPE ");
  3475.     if (typ_page > -1) {
  3476.     prtopt(&optlines,typ_page ? "/PAGE" : "/NOPAGE");
  3477.     } else
  3478.       prtopt(&optlines,"(no options set)");
  3479.     if (typ_wid > -1) {
  3480.     ckmakmsg(tmpbuf,TMPBUFSIZ,"/WIDTH:",ckitoa(typ_wid),NULL,NULL);
  3481.     prtopt(&optlines,tmpbuf);
  3482.     }
  3483.     prtopt(&optlines,"");
  3484. }
  3485. #endif /* NOSHOW */
  3486.  
  3487. #ifdef LOCUS
  3488. /* isauto == 1 if locus is being switched automatically */
  3489.  
  3490. VOID
  3491. setlocus(x, isauto) int x, isauto; {
  3492.     extern int quitting;
  3493.     if (x) x = 1;
  3494.     if (x && locus) return;
  3495.     if (!x && !locus) return;
  3496.     /* Get here if it actually needs to be changed */
  3497. #ifdef OS2
  3498.     if (isauto &&            /* Automatically switching */
  3499.     !quitting &&            /* not exiting */
  3500.     autolocus == 2) {        /* and AUTOLOCUS is set to ASK */
  3501.     char locmsg[300];
  3502.     ckmakmsg(locmsg,300,
  3503.          "Switching Locus to ",
  3504.          x ? "LOCAL" : "REMOTE",
  3505.          " for file management commands\n"
  3506.                  "such as CD, DIRECTORY, DELETE, RENAME.  Type HELP SET\n"
  3507.                  "LOCUS at the K-95> prompt for further info.  Use the\n"
  3508. #ifdef KUI
  3509.                   "Actions menu or SET LOCUS command to disable automatic\n"
  3510.                   "Locus switching or to disable these queries.",
  3511. #else /* KUI */
  3512.                   "SET LOCUS command to disable automatic locus switching\n"
  3513.                   "or to disable these queries.",
  3514. #endif /* KUI */
  3515.                   NULL);
  3516.     if (uq_ok(locmsg,"OK to switch Locus?",3,NULL,1)) {
  3517.         locus = x;
  3518. #ifdef KUI
  3519.         KuiSetProperty(KUI_LOCUS,x,0);
  3520. #endif /* KUI */
  3521.         return;
  3522.     }
  3523.     } else {
  3524. #endif /* OS2 */
  3525.         if (isauto && msgflg && !quitting)
  3526.           printf("Switching LOCUS for file-management commands to %s %s.\n",
  3527.          x ? "LOCAL" : "REMOTE",
  3528.          "(HELP LOCUS for info)"
  3529.          );
  3530.     locus = x;
  3531. #ifdef OS2
  3532. #ifdef KUI
  3533.     KuiSetProperty(KUI_LOCUS,x,0);
  3534. #endif /* KUI */
  3535.     }
  3536. #endif /* OS2 */
  3537. }
  3538.  
  3539. VOID
  3540. setautolocus(x) int x; {
  3541.     autolocus = x;
  3542. #ifdef KUI
  3543.     KuiSetProperty(KUI_AUTO_LOCUS,x,0);
  3544. #endif /* KUI */
  3545. }
  3546. #endif /* LOCUS */
  3547.  
  3548. int
  3549. settypopts() {                /* Set TYPE option defaults */
  3550.     int xp = -1;
  3551.     int c, getval;
  3552.     while (1) {
  3553.     if ((y = cmswi(typetab,ntypetab,"Switch","",xxstring)) < 0) {
  3554.         if (y == -3)
  3555.           break;
  3556.         else
  3557.           return(y);
  3558.     }
  3559.     c = cmgbrk();
  3560.     if ((getval = (c == ':' || c == '=')) && !(cmgkwflgs() & CM_ARG)) {
  3561.         printf("?This switch does not take an argument\n");
  3562.         return(-9);
  3563.     }
  3564.     switch (y) {
  3565.       case TYP_NOP: xp = 0; break;
  3566.       case TYP_PAG: xp = 1; break;
  3567.       case TYP_WID:
  3568.         if (getval)
  3569.           if ((x = cmnum("Column at which to truncate",
  3570.                  ckitoa(cmd_cols),10,&y,xxstring)) < 0)
  3571.         return(x);
  3572.         typ_wid = y;
  3573.         break;
  3574.  
  3575.           default:
  3576.         printf("?Sorry, this option can not be set\n");
  3577.         return(-9);
  3578.     }
  3579.     }
  3580.     if ((x = cmcfm()) < 0)        /* Get confirmation */
  3581.       return(x);
  3582.     if (xp > -1) typ_page = xp;        /* Confirmed, save defaults */
  3583.     return(success = 1);
  3584. }
  3585.  
  3586. /* Forward declarations of functions local to this module */
  3587.  
  3588. #ifdef UNIX
  3589. _PROTOTYP (int douchmod, ( void ) );
  3590. #endif /* UNIX */
  3591. #ifdef CKPURGE
  3592. _PROTOTYP (int dopurge,  ( void ) );
  3593. #endif /* CKPURGE */
  3594. #ifndef NOSPL
  3595. _PROTOTYP (int doundef,  ( int  ) );
  3596. _PROTOTYP (int doask,    ( int  ) );
  3597. _PROTOTYP (int dodef,    ( int  ) );
  3598. _PROTOTYP (int doelse,   ( void ) );
  3599. _PROTOTYP (int dofor,    ( void ) );
  3600. #endif /* NOSPL  */
  3601. #ifndef NODIAL
  3602. _PROTOTYP (int dodial,   ( int  ) );
  3603. #endif /* NODIAL */
  3604. _PROTOTYP (int dodel,    ( void ) );
  3605. _PROTOTYP (int dopaus,   ( int  ) );
  3606. #ifndef NOPUSH
  3607. #ifdef TCPSOCKET
  3608. _PROTOTYP (int doping,   ( void ) );
  3609. _PROTOTYP (int doftp,    ( void ) );
  3610. #endif /* TCPSOCKET */
  3611. #endif /* NOPUSH */
  3612. #ifndef NORENAME
  3613. #ifndef NOFRILLS
  3614. _PROTOTYP (int dorenam,  ( void ) );
  3615. #endif /* NOFRILLS */
  3616. #endif /* NORENAME */
  3617. #ifdef ZCOPY
  3618. _PROTOTYP (int docopy,   ( void ) );
  3619. #endif /* ZCOPY */
  3620. #ifdef NT
  3621. _PROTOTYP (int dolink,   ( void ));
  3622. #endif /* NT */
  3623. #ifdef CK_REXX
  3624. _PROTOTYP (int dorexx,   ( void ) );
  3625. #endif /* CK_REXX */
  3626.  
  3627. #ifdef TNCODE
  3628. static struct keytab telcmd[] = {
  3629.     { "abort", TN_ABORT, CM_INV },    /* Emotionally toned - don't show */
  3630.     { "ao",    TN_AO,    0 },
  3631.     { "ayt",   TN_AYT,   0 },
  3632.     { "break", BREAK,    0 },
  3633.     { "cancel",TN_ABORT, 0 },
  3634.     { "dmark", TN_DM,    0 },
  3635.     { "do",    DO,       0 },
  3636.     { "dont",  DONT,     0 },
  3637.     { "ec",    TN_EC,    0 },
  3638.     { "el",    TN_EL,    0 },
  3639.     { "eof",   TN_EOF,   0 },
  3640.     { "eor",   TN_EOR,   0 },
  3641. #ifdef CK_KERBEROS
  3642. #ifdef KRB5
  3643. #define TN_FWD 1
  3644.     { "forward", TN_FWD, CM_INV },
  3645. #endif /* KRB5 */
  3646. #endif /* CK_KERBEROS */
  3647.     { "ga",    TN_GA,    0 },
  3648.     { "ip",    TN_IP,    0 },
  3649.     { "nop",   TN_NOP,   0 },
  3650.     { "sak",   TN_SAK,   CM_INV },
  3651.     { "sb",    SB,       0 },
  3652.     { "se",    SE,       0 },
  3653.     { "susp",  TN_SUSP,  0 },
  3654.     { "will",  WILL,     0 },
  3655.     { "wont",  WONT,     0 }
  3656. };
  3657. static int ntelcmd = (sizeof(telcmd) / sizeof(struct keytab));
  3658.  
  3659. static struct keytab tnopts[] = {
  3660. #ifdef CK_AUTHENTICATION
  3661.     { "auth",   TELOPT_AUTHENTICATION,   0 },
  3662. #else
  3663.     { "auth",   TELOPT_AUTHENTICATION,   CM_INV },
  3664. #endif /* CK_AUTHENTICATION */
  3665.     { "binary", TELOPT_BINARY, 0 },
  3666. #ifdef TN_COMPORT
  3667.     { "c",      TELOPT_COMPORT, CM_INV|CM_ABR},
  3668.     { "co",     TELOPT_COMPORT, CM_INV|CM_ABR},
  3669.     { "com",    TELOPT_COMPORT, CM_INV|CM_ABR},
  3670.     { "com-port-control", TELOPT_COMPORT, 0 },
  3671.     { "comport-control", TELOPT_COMPORT, CM_INV},
  3672. #else  /* TN_COMPORT */
  3673.     { "com-port-control", TELOPT_COMPORT, CM_INV },
  3674.     { "comport-control", TELOPT_COMPORT, CM_INV},
  3675. #endif /* TN_COMPORT */
  3676.     { "echo", TELOPT_ECHO, 0 },
  3677. #ifdef CK_ENCRYPTION
  3678.     { "encrypt", TELOPT_ENCRYPTION, 0 },
  3679. #else
  3680.     { "encrypt", TELOPT_ENCRYPTION, CM_INV },
  3681. #endif /* CK_ENCRYPTION */
  3682. #ifdef CK_FORWARD_X
  3683.     { "forward-x", TELOPT_FORWARD_X, 0 },
  3684. #else
  3685.     { "forward-x", TELOPT_FORWARD_X, CM_INV },
  3686. #endif /* CK_FORWARD_X */
  3687. #ifdef IKS_OPTION
  3688.     { "kermit", TELOPT_KERMIT, 0 },
  3689. #else
  3690.     { "kermit", TELOPT_KERMIT, CM_INV },
  3691. #endif /* IKS_OPTION */
  3692.     { "lflow",  TELOPT_LFLOW, CM_INV },
  3693.     { "logout", TELOPT_LOGOUT, CM_INV },
  3694. #ifdef CK_NAWS
  3695.     { "naws", TELOPT_NAWS, 0 },
  3696. #else
  3697.     { "naws", TELOPT_NAWS, CM_INV },
  3698. #endif /* CK_NAWS */
  3699. #ifdef CK_ENVIRONMENT
  3700.     { "new-environment", TELOPT_NEWENVIRON,  0 },
  3701. #else
  3702.     { "new-environment", TELOPT_NEWENVIRON,  CM_INV },
  3703. #endif /* CK_ENVIRONMENT */
  3704.     { "pragma-heartbeat",TELOPT_PRAGMA_HEARTBEAT,  CM_INV },
  3705.     { "pragma-logon",    TELOPT_PRAGMA_LOGON,  CM_INV },
  3706.     { "pragma-sspi",     TELOPT_SSPI_LOGON,  CM_INV },
  3707.     { "sak",   TELOPT_IBM_SAK, CM_INV },
  3708. #ifdef CK_SNDLOC
  3709.     { "send-location",   TELOPT_SNDLOC,  0 },
  3710. #else
  3711.     { "send-location",   TELOPT_SNDLOC,  CM_INV },
  3712. #endif /* CK_SNDLOC */
  3713.     { "sga", TELOPT_SGA, 0 },
  3714. #ifdef CK_SSL
  3715.     { "start-tls",       TELOPT_START_TLS,  0 },
  3716. #else
  3717.     { "start-tls",       TELOPT_START_TLS,  CM_INV },
  3718. #endif /* CK_SSL */
  3719.     { "ttype", TELOPT_TTYPE, 0 },
  3720. #ifdef CK_ENVIRONMENT
  3721.     { "xdisplay-location", TELOPT_XDISPLOC, 0 },
  3722. #else
  3723.     { "xdisplay-location", TELOPT_XDISPLOC, CM_INV },
  3724. #endif /* CK_ENVIRONMENT */
  3725.     { "", 0, 0 }
  3726. };
  3727. static int ntnopts = (sizeof(tnopts) / sizeof(struct keytab)) - 1;
  3728.  
  3729. static struct keytab tnsbopts[] = {
  3730. #ifdef CK_NAWS
  3731.     { "naws", TELOPT_NAWS, 0 },
  3732. #endif /* CK_NAWS */
  3733.     { "", 0, 0 }
  3734. };
  3735. static int ntnsbopts = (sizeof(tnsbopts) / sizeof(struct keytab)) - 1;
  3736. #endif /* TNCODE */
  3737.  
  3738. #ifdef TCPSOCKET
  3739. #ifndef NOPUSH
  3740. #ifdef SYSFTP
  3741. int
  3742. doftp() {                /* (External) FTP command */
  3743.     char *p, *f;            /* (See doxftp() for internal one) */
  3744.     int x;
  3745.  
  3746.     if (network)            /* If we have a current connection */
  3747.       ckstrncpy(line,ttname,LINBUFSIZ);    /* get the host name */
  3748.     else *line = '\0';            /* as default host */
  3749.     for (p = line; *p; p++)        /* Remove ":service" from end. */
  3750.       if (*p == ':') { *p = '\0'; break; }
  3751.     if ((x = cmtxt("IP host name or number", line, &s, xxstring)) < 0)
  3752.       return(x);
  3753.     if (nopush) {
  3754.         printf("?Sorry, FTP command disabled\n");
  3755.         return(success = 0);
  3756.     }
  3757. /* Construct FTP command */
  3758. #ifdef VMS
  3759. #ifdef MULTINET                /* TGV MultiNet */
  3760.     ckmakmsg(line,LINBUFSIZ,"multinet ftp ",s,NULL,NULL);
  3761. #else
  3762.     ckmakmsg(line,LINBUFSIZ,"ftp ",s,NULL,NULL);
  3763. #endif /* MULTINET */
  3764. #else                    /* Not VMS */
  3765. #ifdef OS2ORUNIX
  3766. #ifndef NOFTP
  3767.     f = ftpapp;
  3768.     if (!f) f = "";
  3769.     if (!f[0]) f = "ftp";
  3770.     ckmakmsg(line,LINBUFSIZ,f," ",s,NULL);
  3771. #ifdef OS2
  3772.     p = line + strlen(ftpapp);
  3773.     while (p != line) {
  3774.         if (*p == '/') *p = '\\';
  3775.         p--;
  3776.     }
  3777. #endif /* OS2 */
  3778. #else /* NOFTP */
  3779.     ckmakmsg(line,LINBUFSIZ,"ftp ",s,NULL,NULL);
  3780. #endif /* NOFTP */
  3781. #else /* OS2ORUNIX */
  3782.     ckmakmsg(line,LINBUFSIZ,"ftp ",s,NULL,NULL);
  3783. #endif /* OS2ORUNIX */
  3784. #endif /* VMS */
  3785.     conres();                /* Make console normal  */
  3786. #ifdef DEC_TCPIP
  3787.     printf("\n");            /* Prevent prompt-stomping */
  3788. #endif /* DEC_TCPIP */
  3789.     x = zshcmd(line);
  3790.     concb((char)escape);
  3791.     return(success = x);
  3792. }
  3793. #endif /* SYSFTP */
  3794.  
  3795. int
  3796. doping() {                /* PING command */
  3797.     char *p;                /* just runs ping program */
  3798.     int x;
  3799.  
  3800.     if (network)            /* If we have a current connection */
  3801.       ckstrncpy(line,ttname,LINBUFSIZ);    /* get the host name */
  3802.     else *line = '\0';            /* as default host to be pinged. */
  3803.     for (p = line; *p; p++)        /* Remove ":service" from end. */
  3804.       if (*p == ':') { *p = '\0'; break; }
  3805.     if ((x = cmtxt("IP host name or number", line, &s, xxstring)) < 0)
  3806.       return(x);
  3807.     if (nopush) {
  3808.         printf("?Sorry, PING command disabled\n");
  3809.         return(success = 0);
  3810.     }
  3811.  
  3812.     /* Construct PING command */
  3813. #ifdef VMS
  3814. #ifdef MULTINET                /* TGV MultiNet */
  3815.     ckmakmsg(line,LINBUFSIZ,"multinet ping ",s," /num=1",NULL);
  3816. #else
  3817.     ckmakmsg(line,LINBUFSIZ,"ping ",s," 56 1",NULL); /* Other VMS TCP/IP's */
  3818. #endif /* MULTINET */
  3819. #else                    /* Not VMS */
  3820.     ckmakmsg(line,LINBUFSIZ,"ping ",s,NULL,NULL);
  3821. #endif /* VMS */
  3822.     conres();                /* Make console normal  */
  3823. #ifdef DEC_TCPIP
  3824.     printf("\n");            /* Prevent prompt-stomping */
  3825. #endif /* DEC_TCPIP */
  3826.     x = zshcmd(line);
  3827.     concb((char)escape);
  3828.     return(success = x);
  3829. }
  3830. #endif /* NOPUSH */
  3831. #endif /* TCPSOCKET */
  3832.  
  3833. static VOID
  3834. doend(x) int x; {
  3835. #ifndef NOSPL
  3836.     /* Pop from all FOR/WHILE/XIF/SWITCH's */
  3837.     debug(F101,"doend maclvl 1","",maclvl);
  3838.     while ((maclvl > 0) &&
  3839.        (m_arg[maclvl-1][0]) &&
  3840.        (cmdstk[cmdlvl].src == CMD_MD) &&
  3841.        (!strncmp(m_arg[maclvl-1][0],"_xif",4) ||
  3842.         !strncmp(m_arg[maclvl-1][0],"_for",4) ||
  3843.         !strncmp(m_arg[maclvl-1][0],"_whi",4) ||
  3844.         !strncmp(m_arg[maclvl-1][0],"_swi",4))) {
  3845.     debug(F110,"END popping",m_arg[maclvl-1][0],0);
  3846.     dogta(XXPTA);            /* Put args back */
  3847.     popclvl();            /* Pop up two levels */
  3848.     popclvl();
  3849.     debug(F101,"doend maclvl 2","",maclvl);
  3850.     }
  3851.     if (maclvl > -1) {
  3852.     if (mrval[maclvl])        /* Free previous retval if any */
  3853.       free(mrval[maclvl]);
  3854.     mrval[maclvl] = malloc(16);    /* Room for up to 15 digits */
  3855.     if (mrval[maclvl])        /* Record current retval */
  3856.       ckmakmsg(mrval[maclvl],16,ckitoa(x),NULL,NULL,NULL);
  3857.     }
  3858. #endif /* NOSPL */
  3859.     popclvl();                /* Now pop out of macro or TAKE file */
  3860. #ifndef NOSPL
  3861. #ifdef DEBUG
  3862.     if (deblog) {
  3863.     debug(F101,"END maclvl 3","",maclvl);
  3864.     debug(F111,"END mrval[maclvl]",mrval[maclvl],maclvl);
  3865.     debug(F111,"END mrval[maclvl+1]",mrval[maclvl+1],maclvl+1);
  3866.     }
  3867. #endif /* DEBUG */
  3868. #endif /* NOSPL */
  3869. }
  3870.  
  3871. #ifdef CKROOT
  3872. int
  3873. dochroot() {
  3874.     if ((x = cmdir("Name of new root directory","",&s,xxstring)) < 0) {
  3875.     if (x == -3) {
  3876.         printf("?Directory name required\n");
  3877.         return(-9);
  3878.     }
  3879.     return(x);
  3880.     }
  3881.     ckstrncpy(line,s,LINBUFSIZ);
  3882.     s = line;
  3883.     if ((x = cmcfm()) < 0) return(x);
  3884.     s = brstrip(s);
  3885.     x = zsetroot(s);
  3886.     if (x < 0) {
  3887.     char * m = NULL;
  3888.     switch (x) {
  3889.       case -1:
  3890.       case -2: m = "Not a directory"; break;
  3891.       case -3: m = "Internal error"; break;
  3892.       case -4: m = "Access denied"; break;
  3893.       case -5: m = "Off limits"; break;
  3894.     }
  3895.     if (m) printf("%s: \"%s\"\n", m, s);
  3896.     return(m ? -9 : -2);
  3897.     } else {
  3898.     nopush = 1;
  3899.     return(success = 1);
  3900.     }
  3901. }
  3902. #endif /* CKROOT */
  3903.  
  3904. #ifndef NOXFER
  3905. static char * asnbuf = NULL;        /* As-name buffer pointer */
  3906.  
  3907. char sndxnam[] = { "_array_x_" };    /* (with replaceable x!) */
  3908.  
  3909. /*
  3910.   The new SEND command, replacing BSEND, CSEND, PSEND, etc etc.
  3911.   Call with cx = top-level keyword value.  Returns:
  3912.     < 0  On parse error.
  3913.     0    On other type of failure (e.g. requested operation not allowed).
  3914.     1    On success with sstate set to 's' so protocol will begin.
  3915. */
  3916.  
  3917. /*  D O X S E N D  --  Parse SEND and related commands with switches  */
  3918.  
  3919. int
  3920. doxsend(cx) int cx; {
  3921.     int c, i, n, wild, confirmed = 0;    /* Workers */
  3922.     int x, y;                /* of the world... */
  3923.     int getval = 0;            /* Whether to get switch value */
  3924.     extern char * snd_move;        /* Directory to move sent files to */
  3925.     extern char * snd_rename;        /* What to rename sent files to */
  3926.     extern char * filefile;        /* File containing filenames to send */
  3927.     extern int xfiletype;        /* Send only text (or binary) files */
  3928.     extern struct keytab pathtab[];    /* PATHNAMES option keywords */
  3929.     extern int npathtab;        /* How many of them */
  3930.     extern int recursive;        /* Recursive directory traversal */
  3931.     extern int rprintf;            /* REMOTE PRINT flag */
  3932.     extern int fdispla;            /* TRANSFER DISPLAY setting */
  3933.     extern int skipbup;            /* Skip backup files when sending */
  3934.     struct stringint pv[SND_MAX+1];    /* Temporary array for switch values */
  3935.     struct FDB sf, sw, fl, cm;        /* FDBs for each parse function */
  3936.     int mlist = 0;            /* Flag for MSEND or MMOVE */
  3937.     char * m;                /* For making help messages */
  3938.     extern struct keytab protos[];    /* File transfer protocols */
  3939.     extern int xfrxla, g_xfrxla, nprotos;
  3940.     extern char sndbefore[], sndafter[], *sndexcept[]; /* Selection criteria */
  3941.     extern char sndnbefore[], sndnafter[];
  3942.     extern CK_OFF_T sndsmaller, sndlarger, calibrate;
  3943. #ifndef NOSPL
  3944.     int range[2];            /* Array range */
  3945.     char ** ap = NULL;            /* Array pointer */
  3946.     int arrayx = -1;            /* Array index */
  3947. #endif /* NOSPL */
  3948.  
  3949. #ifdef NEWFTP
  3950.     if ((ftpget == 1) || ((ftpget == 2) && ftpisopen())) {
  3951.     if (cx == XXMAI) {
  3952.         printf("?Sorry, No MAIL with FTP\n");
  3953.         return(-9);
  3954.     }
  3955.     return(doftpput(cx,0));
  3956.     }
  3957. #endif /* NEWFTP */
  3958.  
  3959.     for (i = 0; i <= SND_MAX; i++) {    /* Initialize switch values */
  3960.     pv[i].sval = NULL;        /* to null pointers */
  3961.     pv[i].ival = -1;        /* and -1 int values */
  3962.     pv[i].wval = (CK_OFF_T)-1;    /* and -1 wide values */
  3963.     }
  3964. #ifndef NOSPL
  3965.     range[0] = -1;
  3966.     range[1] = -1;
  3967.     sndxin = -1;            /* Array index */
  3968. #endif /* NOSPL */
  3969.     sndarray = NULL;            /* Array pointer */
  3970.  
  3971. #ifdef UNIXOROSK
  3972.     g_matchdot = matchdot;        /* Match dot files */
  3973. #endif /* UNIXOROSK */
  3974.     g_recursive = recursive;        /* Recursive sending */
  3975.     recursive = 0;            /* Save global value, set local */
  3976.     debug(F101,"xsend entry fncnv","",fncnv);
  3977.  
  3978.     /* Preset switch values based on top-level command that called us */
  3979.  
  3980.     switch (cx) {
  3981.       case XXMSE:            /* MSEND */
  3982.     mlist = 1; break;
  3983.       case XXCSEN:            /* CSEND */
  3984.     pv[SND_CMD].ival = 1; break;
  3985.       case XXMMOVE:            /* MMOVE */
  3986.     mlist = 1;
  3987.       case XXMOVE:            /* MOVE */
  3988.     pv[SND_DEL].ival = 1; break;
  3989.       case XXRSEN:            /* RESEND */
  3990.     pv[SND_BIN].ival = 1;        /* Implies /BINARY */
  3991.     pv[SND_RES].ival = 1; break;
  3992.       case XXMAI:            /* MAIL */
  3993.     pv[SND_MAI].ival = 1; break;
  3994.     }
  3995.  
  3996.     /* Set up chained parse functions... */
  3997.  
  3998.     cmfdbi(&sw,                /* First FDB - command switches */
  3999.        _CMKEY,            /* fcode */
  4000.        "Filename, or switch",    /* hlpmsg */
  4001.        "",                /* default */
  4002.        "",                /* addtl string data */
  4003. #ifdef NOMSEND
  4004.        nsndtab,            /* addtl numeric data 1: tbl size */
  4005. #else
  4006.        mlist ? nmsndtab : nsndtab,    /* addtl numeric data 1: tbl size */
  4007. #endif /* NOMSEND */
  4008.        4,                /* addtl numeric data 2: 4 = cmswi */
  4009.        xxstring,            /* Processing function */
  4010. #ifdef NOMSEND
  4011.        sndtab,            /* Keyword table */
  4012. #else
  4013.        mlist ? msndtab : sndtab,
  4014. #endif /* NOMSEND */
  4015.        &sf                /* Pointer to next FDB */
  4016.        );
  4017.     cmfdbi(&sf,                /* 2nd FDB - file to send */
  4018.        _CMIFI,            /* fcode */
  4019.        "File(s) to send",        /* hlpmsg */
  4020.        "",                /* default */
  4021.        "",                /* addtl string data */
  4022.        nolinks,            /* addtl numeric data 1 */
  4023.        0,                /* addtl numeric data 2 */
  4024.        xxstring,
  4025.        NULL,
  4026.        mlist ? &cm : &fl
  4027.        );
  4028.     cmfdbi(&fl,                /* 3rd FDB - command to send from */
  4029.        _CMFLD,            /* fcode */
  4030.        "Command",            /* hlpmsg */
  4031.        "",                /* default */
  4032.        "",                /* addtl string data */
  4033.        0,                /* addtl numeric data 1 */
  4034.        0,                /* addtl numeric data 2 */
  4035.        xxstring,
  4036.        NULL,
  4037.        &cm
  4038.        );
  4039.     cmfdbi(&cm,                /* 4th FDB - Confirmation */
  4040.        _CMCFM,            /* fcode */
  4041.        "",                /* hlpmsg */
  4042.        "",                /* default */
  4043.        "",                /* addtl string data */
  4044.        0,                /* addtl numeric data 1 */
  4045.        0,                /* addtl numeric data 2 */
  4046.        NULL,
  4047.        NULL,
  4048.        NULL
  4049.        );
  4050.  
  4051.     while (1) {                /* Parse 0 or more switches */
  4052.     x = cmfdb(&sw);            /* Parse something */
  4053.     debug(F101,"xsend cmfdb","",x);
  4054.     if (x < 0)            /* Error */
  4055.       goto xsendx;            /* or reparse needed */
  4056.     if (cmresult.fcode != _CMKEY)    /* Break out if not a switch */
  4057.       break;
  4058. /*
  4059.   They gave a switch, but let's see how they terminated it.
  4060.   If they ended it with : or =, then we must parse a value.
  4061.   If they ended it with anything else, then we must NOT parse a value.
  4062. */
  4063.     c = cmgbrk();            /* Get break character */
  4064.     getval = (c == ':' || c == '='); /* to see how they ended the switch */
  4065.     if (getval && !(cmresult.kflags & CM_ARG)) {
  4066.         printf("?This switch does not take arguments\n");
  4067.         x = -9;
  4068.         goto xsendx;
  4069.     }
  4070.     if (!getval && (cmgkwflgs() & CM_ARG)) {
  4071.         printf("?This switch requires an argument\n");
  4072.         x = -9;
  4073.         goto xsendx;
  4074.     }
  4075.     n = cmresult.nresult;        /* Numeric result = switch value */
  4076.     debug(F101,"xsend switch","",n);
  4077.  
  4078.     switch (n) {            /* Process the switch */
  4079.       case SND_CMD:            /* These take no args */
  4080.         if (nopush) {
  4081.         printf("?Sorry, system command access is disabled\n");
  4082.         x = -9;
  4083.         goto xsendx;
  4084.         }
  4085. #ifdef PIPESEND
  4086.         else if (sndfilter) {
  4087.         printf(
  4088. "?Sorry, no SEND /COMMAND or CSEND when SEND FILTER selected\n");
  4089.         x = -9;
  4090.         goto xsendx;
  4091.         }
  4092. #endif /* PIPESEND */
  4093.         sw.hlpmsg = "Command, or switch"; /* Change help message */
  4094.         pv[n].ival = 1;        /* Just set the flag */
  4095.         pv[SND_ARR].ival = 0;
  4096.         break;
  4097.  
  4098.       case SND_REC:            /* /RECURSIVE */
  4099.         recursive = 2;        /* Set the real variable */
  4100.         pv[SND_PTH].ival = PATH_REL; /* Give them relative pathnames */
  4101.         pv[n].ival = 1;        /* Just set the flag */
  4102.         break;
  4103.  
  4104.       case SND_RES:            /* /RECOVER (resend) */
  4105.         pv[SND_ARR].ival = 0;
  4106.         pv[SND_BIN].ival = 1;    /* Implies /BINARY */
  4107.       case SND_NOB:            /* /NOBACKUP */
  4108.       case SND_DEL:            /* /DELETE */
  4109.       case SND_SHH:            /* /QUIET */
  4110.         pv[n].ival = 1;        /* Just set the flag */
  4111.         break;
  4112.  
  4113. #ifdef UNIXOROSK
  4114. /* Like recursive, these are set immediately because they affect cmifi() */
  4115.       case SND_DOT:            /* /DOTFILES */
  4116.         matchdot = 1;
  4117.         break;
  4118.       case SND_NOD:            /* /NODOTFILES */
  4119.         matchdot = 0;
  4120.         break;
  4121. #endif /* UNIXOROSK */
  4122.  
  4123.       /* File transfer modes - each undoes the others */
  4124.  
  4125.       case SND_BIN:            /* Binary */
  4126.       case SND_TXT:            /* Text */
  4127.       case SND_IMG:            /* Image */
  4128.       case SND_LBL:            /* Labeled */
  4129.         pv[SND_BIN].ival = 0;
  4130.         pv[SND_TXT].ival = 0;
  4131.         pv[SND_IMG].ival = 0;
  4132.         pv[SND_LBL].ival = 0;
  4133.         pv[n].ival = 1;
  4134.         break;
  4135.  
  4136. #ifdef CKSYMLINK
  4137.       case SND_LNK:
  4138.       case SND_NLK:
  4139.         nolinks = (n == SND_NLK) ? 2 : 0;
  4140.         cmfdbi(&sf,            /* Redo cmifi() */
  4141.            _CMIFI,        /* fcode */
  4142.            "File(s) to send",    /* hlpmsg */
  4143.            "",            /* default */
  4144.            "",            /* addtl string data */
  4145.            nolinks,        /* addtl numeric data 1 */
  4146.            0,            /* addtl numeric data 2 */
  4147.            xxstring,
  4148.            NULL,
  4149.            mlist ? &cm : &fl
  4150.            );
  4151.         break;
  4152. #endif /* CKSYMLINK */
  4153.  
  4154.       case SND_EXC:            /* Excludes */
  4155.         if (!getval) break;
  4156.         if ((x = cmfld("Pattern","",&s,xxstring)) < 0) {
  4157.         if (x == -3) {
  4158.             printf("?Pattern required\n");
  4159.             x = -9;
  4160.         }
  4161.         goto xsendx;
  4162.         }
  4163.         if (pv[n].sval) free(pv[n].sval);
  4164.         y = strlen(s);
  4165.         if (y > 256) {
  4166.         printf("?Pattern too long - 256 max\n");
  4167.         x = -9;
  4168.         goto xsendx;
  4169.         }
  4170.         pv[n].sval = malloc(y+1);
  4171.         if (pv[n].sval) {
  4172.         strcpy(pv[n].sval,s);    /* safe */
  4173.         pv[n].ival = 1;
  4174.         }
  4175.         break;
  4176.  
  4177.       case SND_MOV:            /* MOVE after */
  4178.       case SND_REN:            /* RENAME after */
  4179.         if (!getval) break;
  4180.         if ((x = cmfld(n == SND_MOV ?
  4181.        "device and/or directory for source file after sending" :
  4182.        "new name for source file after sending",
  4183.                "",
  4184.                &s,
  4185.                n == SND_MOV ? xxstring : NULL
  4186.                )) < 0) {
  4187.         if (x == -3) {
  4188.             printf("%s\n", n == SND_MOV ?
  4189.                "?Destination required" :
  4190.                "?New name required"
  4191.                );
  4192.             x = -9;
  4193.         }
  4194.         goto xsendx;
  4195.         }
  4196.         if (pv[n].sval) free(pv[n].sval);
  4197.         s = brstrip(s);
  4198.         y = strlen(s);
  4199.         if (y > 0) {
  4200.         pv[n].sval = malloc(y+1);
  4201.         if (pv[n].sval) {
  4202.             strcpy(pv[n].sval,s); /* safe */
  4203.             pv[n].ival = 1;
  4204.         }
  4205.         }
  4206.         break;
  4207.  
  4208.       case SND_SMA:            /* Smaller / larger than */
  4209.       case SND_LAR: {
  4210.           CK_OFF_T w;
  4211.           if (!getval) break;
  4212.           if ((x = cmnumw("Size in bytes","0",10,&w,xxstring)) < 0)
  4213.         goto xsendx;
  4214.           pv[n].wval = w;
  4215.           break;
  4216.       }
  4217.       case SND_AFT:            /* Send /AFTER:date-time */
  4218.       case SND_BEF:            /* Send /BEFORE:date-time */
  4219.       case SND_NAF:            /* Send /NOT-AFTER:date-time */
  4220.       case SND_NBE:            /* Send /NOT-BEFORE:date-time */
  4221.         if (!getval) break;
  4222.         if ((x = cmdate("File date-time","",&s,0,xxstring)) < 0) {
  4223.         if (x == -3) {
  4224.             printf("?Date-time required\n");
  4225.             x = -9;
  4226.         }
  4227.         goto xsendx;
  4228.         }
  4229.         if (pv[n].sval) free(pv[n].sval);
  4230.         pv[n].sval = malloc((int)strlen(s)+1);
  4231.         if (pv[n].sval) {
  4232.         strcpy(pv[n].sval,s);    /* safe */
  4233.         pv[n].ival = 1;
  4234.         }
  4235.         break;
  4236.  
  4237.       case SND_MAI:            /* Send as mail (= MAIL) */
  4238. #ifdef IKSD
  4239.         if (inserver && !ENABLED(en_mai)) {
  4240.         printf("?Sorry, sending files as mail is disabled\n");
  4241.         return(-9);
  4242.         }
  4243. #endif /* IKSD */
  4244.         pv[n].ival = 1;
  4245.         if (!getval) break;
  4246.         if ((x = cmfld("e-mail address","",&s,xxstring)) < 0) {
  4247.         if (x == -3) {
  4248.             printf("?address required\n");
  4249.             x = -9;
  4250.         }
  4251.         goto xsendx;
  4252.         }
  4253.         s = brstrip(s);
  4254.         if (pv[n].sval) free(pv[n].sval);
  4255.         pv[n].sval = malloc((int)strlen(s)+1);
  4256.         if (pv[n].sval)
  4257.           strcpy(pv[n].sval,s);    /* safe */
  4258.         break;
  4259.  
  4260.       case SND_PRI:            /* Send to be printed (REMOTE PRINT) */
  4261. #ifdef IKSD
  4262.         if (inserver && !ENABLED(en_mai)) {
  4263.         printf("?Sorry, sending files for printing is disabled\n");
  4264.         return(-9);
  4265.         }
  4266. #endif /* IKSD */
  4267.         pv[n].ival = 1;
  4268.         if (!getval) break;
  4269.         if ((x = cmfld("Print options","",&s,xxstring)) < 0)
  4270.           if (x != -3) goto xsendx;
  4271.         s = brstrip(s);
  4272.         if (pv[n].sval) free(pv[n].sval);
  4273.         pv[n].sval = malloc((int)strlen(s)+1);
  4274.         if (pv[n].sval)
  4275.           strcpy(pv[n].sval,s);    /* safe */
  4276.         break;
  4277.  
  4278.       case SND_ASN:            /* As-name */
  4279.         debug(F101,"xsend /as-name getval","",getval);
  4280.         if (!getval) break;
  4281.         if ((x = cmfld("Name to send under","",&s,NULL)) < 0) {
  4282.         if (x == -3) {
  4283.             printf("?name required\n");
  4284.             x = -9;
  4285.         }
  4286.         goto xsendx;
  4287.         }
  4288.         s = brstrip(s);
  4289.         if ((y = strlen(s)) > 0) {
  4290.         if (pv[n].sval) free(pv[n].sval);
  4291.         pv[n].sval = malloc(y+1);
  4292.         if (pv[n].sval) {
  4293.             strcpy(pv[n].sval,s); /* safe */
  4294.             pv[n].ival = 1;
  4295.         }
  4296.         }
  4297.         break;
  4298.  
  4299.       case SND_STA: {        /* Starting position (= PSEND) */
  4300.           CK_OFF_T w;
  4301.           if (!getval) break;
  4302.           if ((x = cmnumw("0-based position","0",10,&w,xxstring)) < 0)
  4303.         goto xsendx;
  4304.           pv[n].wval = w;
  4305.           break;
  4306.       }
  4307.       case SND_PRO:            /* Protocol to use */
  4308.         if (!getval) break;
  4309.         if ((x = cmkey(protos,nprotos,"File-transfer protocol","",
  4310.                xxstring)) < 0) {
  4311.         if (x == -3) {
  4312.             printf("?name of protocol required\n");
  4313.             x = -9;
  4314.         }
  4315.         goto xsendx;
  4316.         }
  4317.         pv[n].ival = x;
  4318.         break;
  4319.  
  4320. #ifdef PIPESEND
  4321.       case SND_FLT:            /* Filter */
  4322.         debug(F101,"xsend /filter getval","",getval);
  4323.         if (!getval) break;
  4324.         if ((x = cmfld("Filter program to send through","",&s,NULL)) < 0) {
  4325.         if (x == -3)
  4326.           s = "";
  4327.         else
  4328.           goto xsendx;
  4329.         }
  4330.         if (*s) s = brstrip(s);
  4331.         y = strlen(s);
  4332.         for (x = 0; x < y; x++) {    /* Make sure they included "\v(...)" */
  4333.         if (s[x] != '\\') continue;
  4334.         if (s[x+1] == 'v') break;
  4335.         }
  4336.         if (x == y) {
  4337.         printf(
  4338.         "?Filter must contain a replacement variable for filename.\n"
  4339.                );
  4340.         x = -9;
  4341.         goto xsendx;
  4342.         }
  4343.         pv[n].ival = 1;
  4344.         if (pv[n].sval) {
  4345.         free(pv[n].sval);
  4346.         pv[n].sval = NULL;
  4347.         }
  4348.         if ((y = strlen(s)) > 0) {
  4349.         if ((pv[n].sval = malloc(y+1)))
  4350.           strcpy(pv[n].sval,s);    /* safe */
  4351.         }
  4352.         break;
  4353. #endif /* PIPESEND */
  4354.  
  4355.       case SND_PTH:            /* Pathnames */
  4356.         if (!getval) {
  4357.         pv[n].ival = PATH_REL;
  4358.         break;
  4359.         }
  4360.         if ((x = cmkey(pathtab,npathtab,"","absolute",xxstring)) < 0)
  4361.           goto xsendx;
  4362.         pv[n].ival = x;
  4363.         break;
  4364.  
  4365.       case SND_NAM:            /* Filenames */
  4366.         if (!getval) break;
  4367.         if ((x = cmkey(fntab,nfntab,"","converted",xxstring)) < 0)
  4368.           goto xsendx;
  4369.         debug(F101,"xsend /filenames","",x);
  4370.         pv[n].ival = x;
  4371.         break;
  4372.  
  4373. #ifdef CALIBRATE
  4374.           case SND_CAL: {        /* /CALIBRATE */
  4375.           CK_OFF_T w;
  4376.           if (getval) {
  4377.           if ((x = cmnumw("number of Kbytes to send",
  4378.                   "1024",10,&w,xxstring)) < 0)
  4379.             goto xsendx;
  4380.           } else
  4381.         w = (CK_OFF_T)1024;
  4382.           pv[n].wval = w;
  4383.           pv[SND_ARR].ival = 0;
  4384.           break;
  4385.       }
  4386. #endif /* CALIBRATE */
  4387.  
  4388.       case SND_FIL:            /* Name of file containing filnames */
  4389.         if (!getval) break;
  4390.         if ((x = cmifi("Name of file containing list of filenames",
  4391.                    "",&s,&y,xxstring)) < 0) {
  4392.         if (x == -3) {
  4393.             printf("?Filename required\n");
  4394.             x = -9;
  4395.         }
  4396.         goto xsendx;
  4397.         } else if (y) {
  4398.         printf("?Wildcards not allowed\n");
  4399.         x = -9;
  4400.         goto xsendx;
  4401.         }
  4402.         if (pv[n].sval)
  4403.           free(pv[n].sval);
  4404.         if (s) if (*s) {
  4405.         if ((pv[n].sval = malloc((int)strlen(s)+1))) {
  4406.             strcpy(pv[n].sval,s);
  4407.             pv[n].ival = 1;
  4408.             pv[SND_ARR].ival = 0;
  4409.         }
  4410.         }
  4411.         break;
  4412.  
  4413. #ifndef NOSPL
  4414.       case SND_ARR:            /* SEND /ARRAY: */
  4415.         if (!getval) break;
  4416.         ap = NULL;
  4417.         if ((x = cmfld("Array name (a single letter will do)",
  4418.                "",
  4419.                &s,
  4420.                NULL
  4421.                )) < 0) {
  4422.         if (x == -3)
  4423.           break;
  4424.         else
  4425.           return(x);
  4426.         }
  4427.         if ((x = arraybounds(s,&(range[0]),&(range[1]))) < 0) {
  4428.         printf("?Bad array: %s\n",s);
  4429.         return(-9);
  4430.         }
  4431.         if (!(ap = a_ptr[x])) {
  4432.         printf("?No such array: %s\n",s);
  4433.         return(-9);
  4434.         }
  4435.         pv[n].ival = 1;
  4436.         pv[SND_CMD].ival = 0;    /* Undo any conflicting ones... */
  4437.         pv[SND_RES].ival = 0;
  4438.         pv[SND_CAL].ival = 0;
  4439.         pv[SND_FIL].ival = 0;
  4440.         arrayx = x;
  4441.         break;
  4442. #endif /* NOSPL */
  4443.  
  4444.       case SND_XPA:            /* /TRANSPARENT */
  4445.         pv[n].ival = 1;
  4446.         break;
  4447.  
  4448.       case SND_TYP:            /* Only files of given type */
  4449.         if (!getval) break;
  4450.         if ((x = cmkey(txtbin,3,"","all",xxstring)) < 0)
  4451.           goto xsendx;
  4452.         pv[n].ival = (x == 2) ? -1 : x;
  4453.         break;
  4454.  
  4455.       default:
  4456.         printf("?Unexpected switch value - %d\n",cmresult.nresult);
  4457.         x = -9;
  4458.         goto xsendx;
  4459.     }
  4460.     }
  4461.     debug(F101,"xsend cmresult fcode","",cmresult.fcode);
  4462.  
  4463. #ifdef COMMENT
  4464.     /* List switch parsing results in debug log */
  4465.     for (i = 0; i <= SND_MAX; i++) {
  4466.     ckmakmsg(line,LINBUFSIZ,"xsend switch ",ckitoa(i),NULL,NULL);
  4467.     debug(F111,line, pv[i].sval, pv[i].ival);
  4468.     }
  4469. #endif /* COMMENT */
  4470.  
  4471. /* Now we have all switches, plus maybe a filename or command, or nothing */
  4472.  
  4473. #ifdef PIPESEND
  4474.     if (protocol != PROTO_K && pv[SND_CMD].ival > 0) {
  4475.     printf("?Sorry, %s works only with Kermit protocol\n",
  4476.            (cx == XXCSEN) ? "CSEND" : "SEND /COMMAND");
  4477.     x = -9;
  4478.     goto xsendx;
  4479.     }
  4480.     if (pv[SND_RES].ival > 0 ||    /* /RECOVER */
  4481.     pv[SND_STA].wval > 0) {    /* or /STARTING */
  4482.     if (sndfilter || pv[SND_FLT].ival > 0) {
  4483.         printf("?Sorry, no /RECOVER or /START if SEND FILTER selected\n");
  4484.         x = -9;
  4485.         goto xsendx;
  4486.     }
  4487.     }
  4488. #endif /* PIPESEND */
  4489.  
  4490.     cmarg = "";
  4491.     cmarg2 = "";
  4492.     line[0] = NUL;
  4493.     s = line;
  4494.     wild = 0;
  4495.  
  4496.     switch (cmresult.fcode) {        /* How did we get out of switch loop */
  4497.       case _CMIFI:            /* Input filename */
  4498.     ckstrncpy(line,cmresult.sresult,LINBUFSIZ); /* Name */
  4499.     if (pv[SND_ARR].ival > 0)
  4500.       cmarg2 = line;
  4501.     else
  4502.       wild = cmresult.nresult;    /* Wild flag */
  4503.     if (!recursive && !wild)
  4504.       nolinks = 0;
  4505.     break;
  4506.       case _CMFLD:            /* Field */
  4507.     /* Only allowed with /COMMAND and /ARRAY */
  4508.     if (pv[SND_CMD].ival < 1 && pv[SND_ARR].ival < 1) {
  4509. #ifdef CKROOT
  4510.         if (ckrooterr)
  4511.           printf("?Off limits: %s\n",cmresult.sresult);
  4512.         else
  4513. #endif /* CKROOT */
  4514.           printf("?%s - \"%s\"\n",
  4515.            iswild(cmresult.sresult) ?
  4516.            "No files match" : "File not found",
  4517.            cmresult.sresult
  4518.            );
  4519.         x = -9;
  4520.         goto xsendx;
  4521.     }
  4522.     ckstrncpy(line,cmresult.sresult,LINBUFSIZ);
  4523.     if (pv[SND_ARR].ival > 0)
  4524.       cmarg2 = line;
  4525.     break;
  4526.       case _CMCFM:            /* Confirmation */
  4527.     /* s = ""; */
  4528.     confirmed = 1;
  4529.     break;
  4530.       default:
  4531.     printf("?Unexpected function code: %d\n",cmresult.fcode);
  4532.     x = -9;
  4533.     goto xsendx;
  4534.     }
  4535.     debug(F110,"xsend string",s,0);
  4536.     debug(F101,"xsend confirmed","",confirmed);
  4537.  
  4538.     /* Save and change protocol and transfer mode */
  4539.     /* Global values are restored in main parse loop */
  4540.  
  4541.     g_proto = protocol;            /* Save current global protocol */
  4542.     g_urpsiz = urpsiz;
  4543.     g_spsizf = spsizf;
  4544.     g_spsiz = spsiz;
  4545.     g_spsizr = spsizr;
  4546.     g_spmax = spmax;
  4547.     g_wslotr = wslotr;
  4548.     g_prefixing = prefixing;
  4549.     g_fncact = fncact;
  4550.     g_fncnv = fncnv;
  4551.     g_fnspath = fnspath;
  4552.     g_fnrpath = fnrpath;
  4553.     g_xfrxla = xfrxla;
  4554.  
  4555.     if (pv[SND_PRO].ival > -1) {    /* Change according to switch */
  4556.     protocol = pv[SND_PRO].ival;
  4557.         if (ptab[protocol].rpktlen > -1) /* copied from initproto() */
  4558.             urpsiz = ptab[protocol].rpktlen;
  4559.         if (ptab[protocol].spktflg > -1)
  4560.             spsizf = ptab[protocol].spktflg;
  4561.         if (ptab[protocol].spktlen > -1) {
  4562.             spsiz = ptab[protocol].spktlen;
  4563.             if (spsizf)
  4564.           spsizr = spmax = spsiz;
  4565.         }
  4566.         if (ptab[protocol].winsize > -1)
  4567.             wslotr = ptab[protocol].winsize;
  4568.         if (ptab[protocol].prefix > -1)
  4569.             prefixing = ptab[protocol].prefix;
  4570.         if (ptab[protocol].fnca > -1)
  4571.             fncact  = ptab[protocol].fnca;
  4572.         if (ptab[protocol].fncn > -1)
  4573.             fncnv   = ptab[protocol].fncn;
  4574.         if (ptab[protocol].fnsp > -1)
  4575.             fnspath = ptab[protocol].fnsp;
  4576.         if (ptab[protocol].fnrp > -1)
  4577.             fnrpath = ptab[protocol].fnrp;
  4578.     }
  4579.     debug(F101,"xsend protocol","",protocol);
  4580.  
  4581.     if (pv[SND_NOB].ival > -1) {    /* /NOBACKUP (skip backup file) */
  4582.     g_skipbup = skipbup;
  4583.     skipbup = 1;
  4584.     }
  4585.     if (pv[SND_REC].ival > 0)        /* /RECURSIVE */
  4586.       recursive = 2;
  4587.  
  4588.     if (pv[SND_TYP].ival > -1) {    /* /TYPE */
  4589.     xfiletype = pv[SND_TYP].ival;
  4590.     if (xfiletype == 2)
  4591.       xfiletype = -1;
  4592.     }
  4593.     g_binary = binary;            /* Save global transfer mode */
  4594. #ifdef PATTERNS
  4595.     g_patterns = patterns;        /* Save FILE PATTERNS setting */
  4596. #endif /* PATTERNS */
  4597.     if (pv[SND_BIN].ival > 0) {        /* Change according to switch */
  4598.     /* If they said /BINARY they mean /BINARY */
  4599.     patterns = 0;            /* So no pattern-based switching */
  4600.     g_xfermode = xfermode;        /* or automatic transfer mode */
  4601.     xfermode = XMODE_M;
  4602.     binary = XYFT_B;
  4603.     debug(F101,"doxsend /BINARY xfermode","",xfermode);
  4604.     } else if (pv[SND_TXT].ival > 0) {    /* Ditto for /TEXT */
  4605.     patterns = 0;
  4606.     g_xfermode = xfermode;
  4607.     xfermode = XMODE_M;
  4608.     binary = XYFT_T;
  4609.     debug(F101,"doxsend /TEXT xfermode","",xfermode);
  4610.     } else if (pv[SND_IMG].ival > 0) {
  4611. #ifdef VMS
  4612.     binary = XYFT_I;
  4613. #else
  4614.     binary = XYFT_B;
  4615. #endif /* VMS */
  4616.     }
  4617. #ifdef CK_LABELED
  4618.     else if (pv[SND_LBL].ival > 0) {
  4619.     binary = XYFT_L;
  4620.     }
  4621. #endif /* CK_LABELED */
  4622.     debug(F101,"xsend binary","",binary);
  4623.  
  4624.     if (pv[SND_XPA].ival > 0)        /* /TRANSPARENT */
  4625.       xfrxla = 0;            /* Don't translate character sets */
  4626.  
  4627.     /* Check for legal combinations of switches, filenames, etc */
  4628.  
  4629. #ifdef PIPESEND
  4630.     if (pv[SND_CMD].ival > 0) {    /* COMMAND - strip any braces */
  4631.     debug(F110,"SEND /COMMAND before stripping",s,0);
  4632.     s = brstrip(s);
  4633.     debug(F110,"SEND /COMMAND after stripping",s,0);
  4634.     if (!*s) {
  4635.         printf("?Sorry, a command to send from is required\n");
  4636.         x = -9;
  4637.         goto xsendx;
  4638.     }
  4639.     cmarg = s;
  4640.     }
  4641. #endif /* PIPESEND */
  4642.  
  4643. /* Set up /MOVE and /RENAME */
  4644.  
  4645.     if (pv[SND_DEL].ival > 0 &&
  4646.     (pv[SND_MOV].ival > 0 || pv[SND_REN].ival > 0)) {
  4647.     printf("?Sorry, /DELETE conflicts with /MOVE or /RENAME\n");
  4648.     x = -9;
  4649.     goto xsendx;
  4650.     }
  4651. #ifdef CK_TMPDIR
  4652.     if (pv[SND_MOV].ival > 0) {
  4653.     int len;
  4654.     char * p = pv[SND_MOV].sval;
  4655. #ifdef CK_LOGIN
  4656.     if (isguest) {
  4657.         printf("?Sorry, /MOVE-TO not available to guests\n");
  4658.         x = -9;
  4659.         goto xsendx;
  4660.     }
  4661. #endif /* CK_LOGIN */
  4662.     len = strlen(p);
  4663.     if (!isdir(p)) {        /* Check directory */
  4664. #ifdef CK_MKDIR
  4665.         char * s = NULL;
  4666.         s = (char *)malloc(len + 4);
  4667.         if (s) {
  4668.         strcpy(s,p);        /* safe */
  4669. #ifdef datageneral
  4670.         if (s[len-1] != ':') { s[len++] = ':'; s[len] = NUL; }
  4671. #else
  4672.         if (s[len-1] != '/') { s[len++] = '/'; s[len] = NUL; }
  4673. #endif /* datageneral */
  4674.         s[len++] = 'X';
  4675.         s[len] = NUL;
  4676.         x = zmkdir(s);
  4677.         free(s);
  4678.         if (x < 0) {
  4679.             printf("?Can't create \"%s\"\n",p);
  4680.             x = -9;
  4681.             goto xsendx;
  4682.         }
  4683.         }
  4684. #else
  4685.         printf("?Directory \"%s\" not found\n",p);
  4686.         x = -9;
  4687.         goto xsendx;
  4688. #endif /* CK_MKDIR */
  4689.     }
  4690.         zfnqfp(p,LINBUFSIZ,tmpbuf);
  4691.     makestr(&snd_move,tmpbuf);
  4692.     }
  4693. #endif /* CK_TMPDIR */
  4694.  
  4695.     if (pv[SND_REN].ival > 0) {        /* /RENAME */
  4696.     char * p = pv[SND_REN].sval;
  4697. #ifdef CK_LOGIN
  4698.     if (isguest) {
  4699.         printf("?Sorry, /RENAME-TO not available to guests\n");
  4700.         x = -9;
  4701.         goto xsendx;
  4702.     }
  4703. #endif /* CK_LOGIN */
  4704.     if (!p) p = "";
  4705.     if (!*p) {
  4706.         printf("?New name required for /RENAME\n");
  4707.         x = -9;
  4708.         goto xsendx;
  4709.     }
  4710.     p = brstrip(p);
  4711. #ifndef NOSPL
  4712.     /* If name given is wild, rename string must contain variables */
  4713.     if (wild) {
  4714.         char * s = tmpbuf;
  4715.         x = TMPBUFSIZ;
  4716.         zzstring(p,&s,&x);
  4717.         if (!strcmp(tmpbuf,p)) {
  4718.         printf(
  4719.     "?/RENAME for file group must contain variables such as \\v(filename)\n"
  4720.                );
  4721.         x = -9;
  4722.         goto xsendx;
  4723.         }
  4724.     }
  4725. #endif /* NOSPL */
  4726.     makestr(&snd_rename,p);
  4727.     }
  4728.  
  4729. /* Handle /RECOVER and /START */
  4730.  
  4731. #ifdef CK_RESEND
  4732.     if (pv[SND_RES].ival > 0 && binary != XYFT_B && !filepeek
  4733. #ifdef PATTERNS
  4734.     && !patterns
  4735. #else
  4736. #ifdef VMS
  4737. /* VMS sets text/binary automatically later when it opens the file */
  4738.     && 0
  4739. #endif /* VMS */
  4740. #endif /* PATTERNS */
  4741.     ) {
  4742.     printf("?Sorry, /BINARY required\n");
  4743.     x = -9;
  4744.     goto xsendx;
  4745.     }
  4746.     if (pv[SND_STA].wval > 0) {        /* /START */
  4747.     if (wild) {
  4748.         printf("?Sorry, wildcards not permitted with /START\n");
  4749.         x = -9;
  4750.         goto xsendx;
  4751.     }
  4752.     if (sizeof(int) < 4) {
  4753.         printf("?Sorry, this command needs at least 32-bit integers\n");
  4754.         x = -9;
  4755.         goto xsendx;
  4756.     }
  4757. #ifdef CK_XYZ
  4758.     if (protocol != PROTO_K) {
  4759.         printf("?Sorry, SEND /START works only with Kermit protocol\n");
  4760.         x = -9;
  4761.         goto xsendx;
  4762.     }
  4763. #endif /* CK_XYZ */
  4764.     }
  4765. #ifdef CK_XYZ
  4766.     if (pv[SND_RES].ival > 0) {
  4767.     if (protocol != PROTO_K && protocol != PROTO_Z) {
  4768.         printf(
  4769.     "Sorry, /RECOVER is possible only with Kermit or ZMODEM protocol\n"
  4770.            );
  4771.         x = -9;
  4772.         goto xsendx;
  4773.     }
  4774.     }
  4775. #endif /* CK_XYZ */
  4776. #endif /* CK_RESEND */
  4777.  
  4778.     if (protocol == PROTO_K) {
  4779.     if ((pv[SND_MAI].ival > 0 ||    /* MAIL */
  4780.          pv[SND_PRI].ival > 0 ||    /* PRINT */
  4781.          pv[SND_RES].ival > 0    /* RESEND */
  4782.          ) &&
  4783.         (!atdiso || !atcapr)) {    /* Disposition attribute off? */
  4784.         printf("?Sorry, ATTRIBUTE DISPOSITION must be ON\n");
  4785.         x = -9;
  4786.         goto xsendx;
  4787.     }
  4788.     }
  4789.  
  4790. #ifdef CK_XYZ
  4791.     if (wild && (protocol == PROTO_X || protocol == PROTO_XC)) {
  4792.     printf(
  4793. "Sorry, you can only send one file at a time with XMODEM protocol\n"
  4794.            );
  4795.     x = -9;
  4796.     goto xsendx;
  4797.     }
  4798. #endif /* CK_XYZ */
  4799.  
  4800.     if (!confirmed) {            /* CR not typed yet, get more fields */
  4801.     char *m;
  4802.     if (mlist) {            /* MSEND or MMOVE */
  4803.         nfils = 0;            /* We already have the first one */
  4804. #ifndef NOMSEND
  4805.         msfiles[nfils++] = line;    /* Store pointer */
  4806.         lp = line + (int)strlen(line) + 1; /* Point past it */
  4807.         debug(F111,"xsend msend",msfiles[nfils-1],nfils-1);
  4808.         while (1) {            /* Get more filenames */
  4809.         char *p;
  4810.         if ((x = cmifi("Names of files to send, separated by spaces",
  4811.                    "", &s,&y,xxstring)) < 0) {
  4812.             if (x != -3)
  4813.               goto xsendx;
  4814.             if ((x = cmcfm()) < 0)
  4815.               goto xsendx;
  4816.             break;
  4817.         }
  4818.         msfiles[nfils++] = lp;    /* Got one, count it, point to it, */
  4819.         p = lp;            /* remember pointer, */
  4820.         while ((*lp++ = *s++))    /* and copy it into buffer */
  4821.           if (lp > (line + LINBUFSIZ)) { /* Avoid memory leak */
  4822.               printf("?MSEND list too long\n");
  4823.               line[0] = NUL;
  4824.               x = -9;
  4825.               goto xsendx;
  4826.           }
  4827.         debug(F111,"xsend msend",msfiles[nfils-1],nfils-1);
  4828.         if (nfils == 1) fspec[0] = NUL; /* Take care of \v(filespec) */
  4829. #ifdef ZFNQFP
  4830.         zfnqfp(p,TMPBUFSIZ,tmpbuf);
  4831.         p = tmpbuf;
  4832. #endif /* ZFNQFP */
  4833.         if (((int)strlen(fspec) + (int)strlen(p) + 1) < fspeclen) {
  4834.             strcat(fspec,p);    /* safe */
  4835.             strcat(fspec," ");    /* safe */
  4836.         } else
  4837. #ifdef COMMENT
  4838.           printf("WARNING - \\v(filespec) buffer overflow\n");
  4839. #else
  4840.           debug(F101,"doxsend filespec buffer overflow","",0);
  4841. #endif /* COMMENT */
  4842.         }
  4843. #endif /* NOMSEND */
  4844.     } else {            /* Regular SEND */
  4845.         char *p; int y;
  4846.         nfils = -1;
  4847.         if (pv[SND_MAI].ival > 0)
  4848.           m = (pv[SND_MAI].sval) ?
  4849.         "e-mail address (optional)" :
  4850.           "e-mail address (required)";
  4851.         else if (pv[SND_PRI].ival > 0)
  4852.           m = "printer options (optional)";
  4853.         else if (wild)
  4854.           m =
  4855. "\nOptional as-name template containing replacement variables \
  4856. like \\v(filename)";
  4857.         else
  4858.           m = "Optional name to send it with";
  4859.         if ((x = cmtxt(m,"",&p,NULL)) < 0)
  4860.           goto xsendx;
  4861.         if (!p) p = "";
  4862.         if (*p) {            /* If some text was given... */
  4863.         p = brstrip(p);        /* Replace /AS-NAME: value if any */
  4864.         if ((y = strlen(p)) > 0) {
  4865.                     if (pv[SND_MAI].ival > 0) {
  4866.                         makestr(&pv[SND_MAI].sval, p);
  4867.                     } else {
  4868.             if (pv[SND_ASN].sval) free(pv[SND_ASN].sval);
  4869.             pv[SND_ASN].sval = malloc(y+1);
  4870.             if (pv[SND_ASN].sval) {
  4871.                 strcpy(pv[SND_ASN].sval,p);    /* safe */
  4872.                 pv[SND_ASN].ival = 1;
  4873.             }
  4874.             }
  4875.         }
  4876.         }
  4877.     }
  4878.     }
  4879.     /* Set cmarg2 from as-name, however we got it. */
  4880.  
  4881.     if (pv[SND_ASN].ival > 0 && pv[SND_ASN].sval && !*cmarg2) {
  4882.     int x;
  4883.     x = strlen(line);
  4884.     ckstrncpy(line+x+2,pv[SND_ASN].sval,LINBUFSIZ-x-1);
  4885.     cmarg2 = line+x+2;
  4886.     debug(F110,"doxsend cmarg2",cmarg2,0);
  4887.     }
  4888.  
  4889. #ifndef NOFRILLS
  4890.     if ((pv[SND_MAI].ival > 0) && (pv[SND_PRI].ival > 0)) {
  4891.     printf("Sorry, /MAIL and /PRINT are conflicting options\n");
  4892.     x = -9;
  4893.     goto xsendx;
  4894.     }
  4895.     n = 0;                /* /MAIL or /PRINT? */
  4896.     if (pv[SND_MAI].ival > 0)
  4897.       n = SND_MAI;
  4898.     else if (pv[SND_PRI].ival > 0)
  4899.       n = SND_PRI;
  4900.     if (n) {                /* Yes... */
  4901. #ifdef DEBUG
  4902.     char * p;
  4903.     if (n == SND_MAI)
  4904.       p = "/MAIL";
  4905.     else
  4906.       p = "/PRINT";
  4907.     debug(F111,"xsend",p,n);
  4908. #endif /* DEBUG */
  4909. #ifdef CK_XYZ
  4910.     if (protocol != PROTO_K) {
  4911.         printf("Sorry, %s available only with Kermit protocol\n",
  4912.            (n == SND_MAI) ? "/MAIL" : "/PRINT"
  4913.            );
  4914.         x = -9;
  4915.         goto xsendx;
  4916.     }
  4917. #endif /* CK_XYZ */
  4918.     debug(F101,"xsend print/mail wild","",wild);
  4919.     *optbuf = NUL;            /* Wipe out any old options */
  4920.     s = pv[n].sval;            /* mail address or print switch val */
  4921.     if (!s) s = "";
  4922.     debug(F110,"doxsend mail address or printer options",s,0);
  4923.     if (n == SND_MAI && !*s) {
  4924.         printf("?E-mail address required\n");
  4925.         x = -9;
  4926.         goto xsendx;
  4927.     } else if ((int)strlen(s) > 94) { /* Ensure legal size */
  4928.         printf("?%s too long\n",
  4929.            (n == SND_MAI) ?
  4930.            "E-mail address" :
  4931.            "Print option string"
  4932.            );
  4933.         x = -9;
  4934.         goto xsendx;
  4935.     }
  4936.     ckstrncpy(optbuf,s,OPTBUFLEN);    /* OK, copy to option buffer */
  4937.     cmarg = line;            /* File to send */
  4938.     if (n == SND_MAI) {
  4939.         debug(F110,"xsend mailing",cmarg,0);
  4940.         debug(F110,"xsend address:",optbuf,0);
  4941.         rmailf = 1;
  4942.     } else {
  4943.         debug(F110,"xsend printing",cmarg,0);
  4944.         debug(F110,"xsend options",optbuf,0);
  4945.         rprintf = 1;
  4946.     }
  4947.     }
  4948. #endif /* NOFRILLS */
  4949.  
  4950. #ifdef CALIBRATE
  4951.     if (pv[SND_CAL].wval > 0) {        /* Handle /CALIBRATE */
  4952.     if (confirmed) {
  4953.         calibrate = pv[SND_CAL].wval * (CK_OFF_T)1024;
  4954.         sndsrc = -9;
  4955.         nfils = 1;
  4956.         wild = 0;
  4957. #ifndef NOMSEND
  4958.         addlist = 0;
  4959. #endif /* NOMSEND */
  4960.         ckstrncpy(line,"CALIBRATION",LINBUFSIZ);
  4961.         s = cmarg = line;
  4962.         if (!cmarg2) cmarg2 = "";
  4963.         debug(F110,"doxsend cmarg2 calibrate",cmarg2,0);
  4964.     } else if (line[0]) {
  4965.         calibrate = 0;
  4966.         pv[SND_CAL].ival = 0;
  4967.         pv[SND_CAL].wval = 0;
  4968.     }
  4969.     }
  4970. #endif /* CALIBRATE */
  4971.  
  4972.     if (pv[SND_FIL].ival > 0) {
  4973.     if (confirmed && !calibrate) {
  4974.         if (zopeni(ZMFILE,pv[SND_FIL].sval) < 1) {
  4975.         debug(F110,"xsend can't open",pv[SND_FIL].sval,0);
  4976.         printf("?Failure to open %s\n",filefile);
  4977.         x = -9;
  4978.         goto xsendx;
  4979.         }
  4980.         makestr(&filefile,pv[SND_FIL].sval); /* Open, remember name */
  4981.         debug(F110,"xsend opened",filefile,0);
  4982.         wild = 1;
  4983.     }
  4984.     }
  4985.  
  4986.     /* SEND alone... */
  4987.  
  4988. #ifndef NOSPL
  4989.     if (confirmed && pv[SND_ARR].ival > 0) {
  4990.     if (!*cmarg2) {
  4991.         sndxnam[7] = (char)((arrayx == 1) ? 64 : arrayx + ARRAYBASE);
  4992.         cmarg2 = sndxnam;
  4993.     }
  4994.     cmarg = "";
  4995.     goto sendend;
  4996.     }
  4997. #endif /* NOSPL */
  4998.  
  4999.     if (confirmed && !line[0] && !filefile && !calibrate) {
  5000. #ifndef NOMSEND
  5001.     if (filehead) {            /* OK if we have a SEND-LIST */
  5002.         nfils = filesinlist;
  5003.         sndsrc = nfils;        /* Like MSEND */
  5004.         addlist = 1;        /* But using a different list... */
  5005.         filenext = filehead;
  5006.         goto sendend;
  5007.     }
  5008. #endif /* NOMSEND */
  5009.     printf("?Filename required but not given\n");
  5010.     x = -9;
  5011.     goto xsendx;
  5012.     }
  5013.  
  5014.     /* Not send-list or array */
  5015.  
  5016. #ifndef NOMSEND
  5017.     addlist = 0;            /* Don't use SEND-LIST. */
  5018.     filenext = NULL;
  5019. #endif /* NOMSEND */
  5020.  
  5021.     if (mlist) {            /* MSEND or MMOVE */
  5022. #ifndef NOMSEND
  5023.     cmlist = msfiles;        /* List of files to send */
  5024.     sndsrc = nfils;
  5025.     cmarg2 = "";
  5026.     sendstart = (CK_OFF_T)0;
  5027. #endif /* NOMSEND */
  5028. #ifdef PIPESEND
  5029.     pipesend = 0;
  5030. #endif /* PIPESEND */
  5031.     } else if (filefile) {        /* File contains list of filenames */
  5032.     s = "";
  5033.     cmarg = "";
  5034.     cmarg2 = "";
  5035.     line[0] = NUL;
  5036.     nfils = 1;
  5037.     sndsrc = 1;
  5038.  
  5039.     } else if (!calibrate && pv[SND_ARR].ival < 1 && pv[SND_CMD].ival < 1) {
  5040.  
  5041.     nfils = sndsrc = -1;    /* Not MSEND, MMOVE, /LIST, or /ARRAY */
  5042.     if (                /* or /COMMAND */
  5043.  
  5044. #ifndef NOFRILLS
  5045.         !rmailf && !rprintf        /* Not MAIL or PRINT */
  5046. #else
  5047.         1
  5048. #endif /* NOFRILLS */
  5049.         ) {
  5050.         CK_OFF_T y = (CK_OFF_T)1;
  5051.         if (!wild)
  5052.           y = zchki(s);
  5053.         if (y < (CK_OFF_T)0) {
  5054.         printf("?Read access denied - \"%s\"\n", s);
  5055.         x = -9;
  5056.         goto xsendx;
  5057.         }
  5058.         if (s != line)        /* We might already have done this. */
  5059.           ckstrncpy(line,s,LINBUFSIZ); /* Copy of string just parsed. */
  5060.         else
  5061.           debug(F110,"doxsend line=s",line,0);
  5062.         cmarg = line;        /* File to send */
  5063.     }
  5064.     zfnqfp(cmarg,fspeclen,fspec);
  5065.     }
  5066.     if (!mlist) {            /* For all but MSEND... */
  5067. #ifdef PIPESEND
  5068.     if (pv[SND_CMD].ival > 0)    /* /COMMAND sets pipesend flag */
  5069.       pipesend = 1;
  5070.     debug(F101,"xsend /COMMAND pipesend","",pipesend);
  5071.     if (pipesend && filefile) {
  5072.         printf("?Invalid switch combination\n");
  5073.         x = -9;
  5074.         goto xsendx;
  5075.     }
  5076. #endif /* PIPESEND */
  5077.  
  5078. #ifndef NOSPL
  5079.     /* If as-name given and filespec is wild, as-name must contain variables */
  5080.     debug(F111,"doxsend cmarg2 wild",cmarg2,wild);
  5081.     if (wild && *cmarg2) {
  5082.         char * s = tmpbuf;
  5083.         x = TMPBUFSIZ;
  5084.         zzstring(cmarg2,&s,&x);
  5085.         if (!strcmp(tmpbuf,cmarg2)) {
  5086.         printf(
  5087.     "?As-name for file group must contain variables such as \\v(filename)\n"
  5088.                );
  5089.         x = -9;
  5090.         goto xsendx;
  5091.         }
  5092.     }
  5093. #endif /* NOSPL */
  5094.  
  5095.     /* Strip braces from as-name */
  5096.     debug(F110,"xsend cmarg2 before stripping",cmarg2,0);
  5097.     cmarg2 = brstrip(cmarg2);
  5098.     debug(F110,"xsend filename",cmarg,0);
  5099.     debug(F110,"xsend as-name",cmarg2,0);
  5100.  
  5101.     /* Copy as-name to a safe place */
  5102.  
  5103.     if (asnbuf) {
  5104.         free(asnbuf);
  5105.         asnbuf = NULL;
  5106.     }
  5107.     if ((y = strlen(cmarg2)) > 0) {
  5108.         asnbuf = (char *) malloc(y + 1);
  5109.         if (asnbuf) {
  5110.         strcpy(asnbuf,cmarg2);    /* safe */
  5111.         cmarg2 = asnbuf;
  5112.         } else cmarg2 = "";
  5113.     }
  5114.  
  5115. #ifdef CK_RESEND
  5116.     debug(F111,"xsend pv[SND_STA].ival","",pv[SND_STA].ival);
  5117.     if (pv[SND_STA].wval > (CK_OFF_T)-1) { /* /START position */
  5118.         if (wild) {
  5119.         printf("?/STARTING-AT may not be used with multiple files.\n");
  5120.         x = -9;
  5121.         goto xsendx;
  5122.         } else
  5123.           sendstart = pv[SND_STA].wval;
  5124.     } else
  5125.       sendstart = (CK_OFF_T)0;
  5126.     debug(F101,"xsend /STARTING","",sendstart);
  5127. #endif /* CK_RESEND */
  5128.     }
  5129.  
  5130. sendend:                /* Common successful exit */
  5131.     moving = 0;
  5132.     if (pv[SND_SHH].ival > 0) {        /* SEND /QUIET... */
  5133.     g_displa = fdispla;
  5134.     fdispla = 0;
  5135.     debug(F101,"xsend display","",fdispla);
  5136.     }
  5137.  
  5138. #ifndef NOSPL                /* SEND /ARRAY... */
  5139.     if (pv[SND_ARR].ival > 0) {
  5140.     if (!ap) { x = -2; goto xsendx; } /* (shouldn't happen) */
  5141.     if (range[0] == -1)        /* If low end of range not specified */
  5142.       range[0] = 1;            /* default to 1 */
  5143.     if (range[1] == -1)        /* If high not specified */
  5144.       range[1] = a_dim[arrayx];    /* default to size of array */
  5145.     if ((range[0] < 0) ||        /* Check range */
  5146.         (range[0] > a_dim[arrayx]) ||
  5147.         (range[1] < range[0]) ||
  5148.         (range[1] > a_dim[arrayx])) {
  5149.         printf("?Bad array range - [%d:%d]\n",range[0],range[1]);
  5150.         x = -9;
  5151.         goto xsendx;
  5152.     }
  5153.     sndarray = ap;            /* Array pointer */
  5154.     sndxin = arrayx;        /* Array index */
  5155.     sndxlo = range[0];        /* Array range */
  5156.     sndxhi = range[1];
  5157.     sndxnam[7] = (char)((sndxin == 1) ? 64 : sndxin + ARRAYBASE);
  5158.  
  5159. #ifdef COMMENT
  5160.     printf("SENDING FROM ARRAY: &%c[]...\n", /* debugging */
  5161.            (sndxin == 1) ? 64 : sndxin + ARRAYBASE);
  5162.     printf("Lo=%d\nHi=%d\n", sndxlo, sndxhi);
  5163.     printf("cmarg=[%s]\ncmarg2=[%s]\n", cmarg, cmarg2);
  5164.     while ((x = agnbyte()) > -1) {
  5165.         putchar((char)x);
  5166.     }
  5167.     return(1);
  5168. #endif /* COMMENT */
  5169.     }
  5170. #endif /* NOSPL */
  5171.  
  5172.     if (pv[SND_ARR].ival < 1) {        /* File selection & disposition... */
  5173.  
  5174.     if (pv[SND_DEL].ival > 0)    /* /DELETE was specified */
  5175.       moving = 1;
  5176.     debug(F101,"xsend /DELETE","",moving);
  5177.     if (pv[SND_AFT].ival > 0)    /* Copy SEND criteria */
  5178.       ckstrncpy(sndafter,pv[SND_AFT].sval,19);
  5179.     if (pv[SND_BEF].ival > 0)
  5180.       ckstrncpy(sndbefore,pv[SND_BEF].sval,19);
  5181.     if (pv[SND_NAF].ival > 0)
  5182.       ckstrncpy(sndnafter,pv[SND_NAF].sval,19);
  5183.     if (pv[SND_NBE].ival > 0)
  5184.       ckstrncpy(sndnbefore,pv[SND_NBE].sval,19);
  5185.     if (pv[SND_EXC].ival > 0)
  5186.       makelist(pv[SND_EXC].sval,sndexcept,NSNDEXCEPT);
  5187.     if (pv[SND_SMA].wval > (CK_OFF_T)-1)
  5188.       sndsmaller = pv[SND_SMA].wval;
  5189.     if (pv[SND_LAR].wval > (CK_OFF_T)-1)
  5190.       sndlarger = pv[SND_LAR].wval;
  5191.     if (pv[SND_NAM].ival > -1) {
  5192.         g_fncnv = fncnv;        /* Save global value */
  5193.         fncnv = pv[SND_NAM].ival;
  5194.         debug(F101,"xsend fncnv","",fncnv);
  5195.     }
  5196.     if (pv[SND_PTH].ival > -1) {
  5197.         g_spath = fnspath;        /* Save global values */
  5198.         fnspath = pv[SND_PTH].ival;
  5199. #ifndef NZLTOR
  5200.         if (fnspath != PATH_OFF) {
  5201.         g_fncnv = fncnv;    /* Bad bad... */
  5202.         fncnv = XYFN_C;
  5203.         }
  5204. #endif /* NZLTOR */
  5205.         debug(F101,"xsend fnspath","",fnspath);
  5206.         debug(F101,"xsend fncnv","",fncnv);
  5207.     }
  5208.     }
  5209.  
  5210. #ifdef PIPESEND
  5211.     if (pv[SND_FLT].ival > 0) {
  5212.     makestr(&sndfilter,pv[SND_FLT].sval);
  5213.     debug(F110,"xsend /FILTER", sndfilter, 0);
  5214.     }
  5215. #endif /* PIPESEND */
  5216.  
  5217. #ifdef CK_APC
  5218. /* MOVE not allowed in APCs */
  5219.     if (moving &&
  5220.     (apcactive == APC_LOCAL || apcactive == APC_REMOTE)
  5221.     && !(apcstatus & APC_UNCH))
  5222.       return(success = 0);
  5223. #endif /* CK_APC */
  5224. #ifdef IKS_OPTION
  5225.     if (
  5226. #ifdef CK_XYZ
  5227.         protocol == PROTO_K &&
  5228. #endif /* CK_XYZ */
  5229.         !iks_wait(KERMIT_REQ_START,1)) {
  5230.         printf("?A Kermit Server is not available to process this command.\n");
  5231.         printf("?Start a RECEIVE command to complement this command.\n");
  5232.     }
  5233. #endif /* IKS_OPTION */
  5234.  
  5235. #ifdef IKSD
  5236. #ifdef CK_LOGIN
  5237.     if (moving && inserver && isguest) {
  5238.         printf("?File deletion not allowed for guests.\n");
  5239.     return(-9);
  5240.     }
  5241. #endif /* CK_LOGIN */
  5242. #endif /* IKSD */
  5243.  
  5244.     sstate = 's';            /* Set start state to SEND */
  5245.     sndcmd = 1;
  5246. #ifdef CK_RESEND
  5247.     if (pv[SND_RES].ival > 0)        /* Send sendmode appropriately */
  5248.       sendmode = SM_RESEND;
  5249.     else if (pv[SND_STA].ival > 0)
  5250.       sendmode = SM_PSEND;
  5251.     else
  5252. #endif /* CK_RESEND */
  5253.     if (mlist)
  5254.       sendmode = SM_MSEND;
  5255.     else
  5256.       sendmode = SM_SEND;
  5257. #ifdef MAC
  5258.     what = W_SEND;
  5259.     scrcreate();
  5260. #endif /* MAC */
  5261.     if (local && pv[SND_SHH].ival != 0) { /* If in local mode, */
  5262.     displa = 1;            /* turn on file transfer display */
  5263.     }
  5264.     x = 0;
  5265.  
  5266.   xsendx:                /* Common exit, including failure */
  5267.     debug(F101,"doxsend sndsrc","",sndsrc);
  5268.     for (i = 0; i <= SND_MAX; i++) {    /* Free malloc'd memory */
  5269.     if (pv[i].sval)
  5270.       free(pv[i].sval);
  5271.     }
  5272.     return(x);
  5273. }
  5274. #endif /* NOXFER */
  5275.  
  5276. #ifndef NOLOCAL
  5277. /*  D O X C O N N  --  CONNECT command parsing with switches */
  5278.  
  5279. #ifdef XLIMITS
  5280. #define XLIMORTRIGGER
  5281. #else
  5282. #ifdef CK_TRIGGER
  5283. #define XLIMORTRIGGER
  5284. #endif /* CK_TRIGGER */
  5285. #endif /*  XLIMITS */
  5286.  
  5287. #ifdef CKTIDLE
  5288. int tt_idlelimit = 0;            /* Terminal idle limit */
  5289. int tt_idleact = IDLE_RET;        /* Terminal idle action */
  5290. #endif /* CKTIDLE */
  5291.  
  5292. #ifdef OS2                /* K95 only: */
  5293. extern int
  5294.   tt_idlesnd_tmo;            /*   Idle interval */
  5295. int tt_timelimit = 0;            /*   Time limit, 0 = none */
  5296. extern char *                /* Parse results - strings: */
  5297.   tt_idlesnd_str;            /*   Idle string */
  5298. #endif /* OS2 */
  5299.  
  5300. #ifdef CK_TRIGGER
  5301. extern char *tt_trigger[];
  5302. extern CHAR *tt_trmatch[];
  5303. extern char *triggerval;
  5304. static char *g_tt_trigger[TRIGGERS];
  5305. #endif /* CK_TRIGGER */
  5306.  
  5307. #ifdef OS2
  5308. static int g_tt_idlesnd_tmo, g_tt_timelimit; /* For saving and restoring */
  5309. static int g_tt_idlelimit, g_tt_saved = 0;
  5310. static char * g_tt_idlesnd_str;        /* global settings */
  5311. #endif /* OS2 */
  5312.  
  5313. static struct stringint pv[CONN_MAX+1];
  5314.  
  5315. VOID
  5316. resconn() {
  5317.     int i;
  5318.  
  5319. #ifdef OS2
  5320.     if ( g_tt_saved ) {
  5321.         tt_idlelimit   = g_tt_idlelimit;
  5322.         tt_idlesnd_tmo = g_tt_idlesnd_tmo;
  5323.         tt_timelimit   = g_tt_timelimit;
  5324.         tt_idlesnd_str = g_tt_idlesnd_str;
  5325.         g_tt_saved = 0;
  5326.     }
  5327. #endif /* OS2 */
  5328.  
  5329. #ifdef CK_TRIGGER
  5330.     for (i = 0; i < TRIGGERS; i++)
  5331.       tt_trigger[i] = g_tt_trigger[i];
  5332. #endif /* CK_TRIGGER */
  5333.  
  5334.     for (i = 0; i <= CONN_MAX; i++) {    /* Free malloc'd memory */
  5335.     if (pv[i].sval)
  5336.       free(pv[i].sval);
  5337.         pv[i].sval = NULL;
  5338.     }
  5339. }
  5340.  
  5341. int
  5342. doxconn(cx) int cx; {
  5343.     int c, i, n;            /* Workers */
  5344.     int x, y;
  5345.     int getval = 0;            /* Whether to get switch value */
  5346.     int async = 0;                      /* Make an async connect */
  5347.     struct FDB sw, cm;            /* FDBs for each parse function */
  5348.     extern FILE * tfile[];
  5349.     extern char * macp[];
  5350.  
  5351. #ifdef OS2
  5352.     g_tt_idlesnd_tmo = tt_idlesnd_tmo;    /* Save global settings */
  5353.     g_tt_timelimit   = tt_timelimit;
  5354.     g_tt_idlelimit   = tt_idlelimit;
  5355.     g_tt_idlesnd_str = tt_idlesnd_str;
  5356.     g_tt_saved = 1;
  5357. #endif /* OS2 */
  5358.  
  5359. #ifdef CK_TRIGGER
  5360.     if (!tt_trigger[0]) {        /* First initialization */
  5361.     for (i = 1; i < TRIGGERS; i++)
  5362.       tt_trigger[i] = NULL;
  5363.     }
  5364.     for (i = 0; i < TRIGGERS; i++)
  5365.       g_tt_trigger[i] = tt_trigger[i];
  5366.     if (triggerval) {
  5367.     free(triggerval);
  5368.     triggerval = NULL;
  5369.     }
  5370. #endif /* CK_TRIGGER */
  5371.  
  5372.     for (i = 0; i <= CONN_MAX; i++) {    /* Initialize switch values */
  5373.     pv[i].sval = NULL;        /* to null pointers */
  5374.     pv[i].ival = -1;        /* and -1 int values */
  5375.     pv[i].wval = (CK_OFF_T)-1;
  5376.     }
  5377.     if (cx == XXCQ)            /* CQ == CONNECT /QUIETLY */
  5378.       pv[CONN_NV].ival = 1;
  5379.  
  5380.     /* Set up chained parse functions... */
  5381.  
  5382.     cmfdbi(&sw,                /* First FDB - command switches */
  5383.        _CMKEY,            /* fcode */
  5384.        "Switch",            /* hlpmsg */
  5385.        "",                /* default */
  5386.        "",                /* addtl string data */
  5387.        nconntab,            /* addtl numeric data 1: tbl size */
  5388.        4,                /* addtl numeric data 2: 4 = cmswi */
  5389.        xxstring,            /* Processing function */
  5390.        conntab,            /* Keyword table */
  5391.        &cm                /* Pointer to next FDB */
  5392.        );
  5393.     cmfdbi(&cm,                /* 2nd FDB - Confirmation */
  5394.        _CMCFM,            /* fcode */
  5395.        "",                /* hlpmsg */
  5396.        "",                /* default */
  5397.        "",                /* addtl string data */
  5398.        0,                /* addtl numeric data 1 */
  5399.        0,                /* addtl numeric data 2 */
  5400.        NULL,
  5401.        NULL,
  5402.        NULL
  5403.        );
  5404.  
  5405.     while (1) {                /* Parse 0 or more switches */
  5406.     x = cmfdb(&sw);            /* Parse switch or confirmation */
  5407.     debug(F101,"doxconn cmfdb","",x);
  5408.     if (x < 0) {            /* Error */
  5409.         if (x == -9 || x == -2)
  5410.           printf("?No switches match - \"%s\"\n",atmbuf);
  5411.         goto xconnx;        /* or reparse needed */
  5412.     }
  5413.     if (cmresult.fcode != _CMKEY)    /* Break out if not a switch */
  5414.       break;
  5415.     c = cmgbrk();            /* Get break character */
  5416.     getval = (c == ':' || c == '='); /* to see how they ended the switch */
  5417.     if (getval && !(cmresult.kflags & CM_ARG)) {
  5418.         printf("?This switch does not take arguments\n");
  5419.         x = -9;
  5420.         goto xconnx;
  5421.     }
  5422.     if (!getval && (cmgkwflgs() & CM_ARG)) {
  5423.         printf("?This switch requires an argument\n");
  5424.         return(-9);
  5425.     }
  5426.     n = cmresult.nresult;        /* Numeric result = switch value */
  5427.     debug(F101,"doxconn switch","",n);
  5428.  
  5429.     switch (n) {            /* Process the switch */
  5430. #ifdef OS2
  5431.       case CONN_AS:            /* Asynchronous */
  5432.             pv[CONN_AS].ival = 1;
  5433.             pv[CONN_SY].ival = 0;
  5434.             break;
  5435.           case CONN_SY:                 /* Synchronous */
  5436.             pv[CONN_SY].ival = 1;
  5437.             pv[CONN_AS].ival = 0;
  5438.             break;
  5439. #endif /* OS2 */
  5440.       case CONN_NV:            /* Non-verbal */
  5441.         pv[n].ival = 1;
  5442.         break;
  5443. #ifdef XLIMITS
  5444.       case CONN_II:            /* Idle-interval */
  5445.       case CONN_IL:            /* Idle-limit */
  5446.       case CONN_TL:            /* Time-limit */
  5447.         if (!getval) break;
  5448.         if ((x = cmnum("Seconds","0",10,&y,xxstring)) < 0)
  5449.           goto xconnx;
  5450.         pv[n].ival = y;
  5451.         break;
  5452.       case CONN_IS:            /* Idle-string */
  5453. #endif /* XLIMITS */
  5454. #ifdef CK_TRIGGER
  5455.       case CONN_TS:            /* Trigger-string */
  5456. #endif /* CK_TRIGGER */
  5457. #ifdef XLIMORTRIGGER
  5458.         if (!getval) break;
  5459.         if ((x = cmfld("String (enclose in braces if it contains spaces)",
  5460.                "",&s,xxstring)) < 0) {
  5461.         if (x == -3) {
  5462.             printf("?String required\n");
  5463.             x = -9;
  5464.         }
  5465.         goto xconnx;
  5466.         }
  5467.         if (n != CONN_TS)
  5468.           s = brstrip(s);
  5469.         if ((y = strlen(s)) > 0) {
  5470.         if (pv[n].sval) free(pv[n].sval);
  5471.         pv[n].sval = malloc(y+1);
  5472.         if (pv[n].sval) {
  5473.             strcpy(pv[n].sval,s); /* safe */
  5474.             pv[n].ival = 1;
  5475.         }
  5476.         }
  5477.         break;
  5478. #endif /* XLIMORTRIGGER */
  5479.       default:
  5480.         printf("?Unexpected switch value - %d\n",cmresult.nresult);
  5481.         x = -9;
  5482.         goto xconnx;
  5483.     }
  5484.     }
  5485.     debug(F101,"doxconn cmresult.fcode","",cmresult.fcode);
  5486.     if (cmresult.fcode != _CMCFM) {
  5487.     printf("?Unexpected function code: %d\n",cmresult.fcode);
  5488.     x = -9;
  5489.     goto xconnx;
  5490.     }
  5491.  
  5492.     /* Command was confirmed so we can pre-pop command level. */
  5493.     /* This is so CONNECT module won't think we're executing a script */
  5494.     /* if CONNECT was the final command in the script. */
  5495.  
  5496.     if (cmdlvl > 0)
  5497.       prepop();
  5498.  
  5499. #ifdef OS2                /* Make results available globally */
  5500.     if (pv[CONN_IL].ival > -1)        /* Idle limit */
  5501.       tt_idlelimit = pv[CONN_IL].ival;
  5502.     if (pv[CONN_II].ival > -1)        /* Idle limit */
  5503.       tt_idlesnd_tmo = pv[CONN_II].ival;
  5504.     if (pv[CONN_IS].sval)        /* Idle string */
  5505.       if (tt_idlesnd_str = (char *)malloc((int)strlen(pv[CONN_IS].sval)+1))
  5506.     strcpy(tt_idlesnd_str,pv[CONN_IS].sval); /* safe */
  5507.     if (pv[CONN_TL].ival > -1)        /* Session limit */
  5508.       tt_timelimit = pv[CONN_TL].ival;
  5509.     async = (pv[CONN_AS].ival > 0 ||
  5510.              pv[CONN_SY].ival <= 0 && cmdlvl == 0) ? 1 : 0;
  5511. #endif /* OS2 */
  5512.  
  5513. #ifdef CK_TRIGGER
  5514.     if (pv[CONN_TS].sval)        /* Trigger strings */
  5515.       makelist(pv[CONN_TS].sval,tt_trigger,TRIGGERS);
  5516.     for (i = 0; i < TRIGGERS; i++)    /* Trigger match pointers */
  5517.       tt_trmatch[i] = NULL;
  5518.     if (triggerval) {            /* Reset trigger value */
  5519.     free(triggerval);
  5520.     triggerval = NULL;
  5521.     }
  5522. #endif /* CK_TRIGGER */
  5523.  
  5524. #ifdef SSHCMD
  5525. /*
  5526.   2010/03/01...
  5527.   The previous connection was through the external ssh client and now, with
  5528.   that connection closed, the user says "connect" and expects a new connection
  5529.   to be made to the same host, because that's how all the other connection
  5530.   methods work, so (and this is quite a hack)...
  5531. */
  5532.     if (!ckstrcmp("ssh ",ttname,4,0)) {    /* Previous "host" was "ssh blah" */
  5533.     _PROTOTYP (int redossh, ( void ) );
  5534.     extern int ttyfd;
  5535.     if (ttyfd < 0) {        /* And connection is no longer open */
  5536.         int xx;
  5537.         xx = redossh();        /* So redo the SSH connection */
  5538.         if (xx < 0) return(xx);
  5539.         goto xconnx;
  5540.     }
  5541.     }
  5542. #endif    /* SSHCMD */
  5543.     x = doconect((pv[CONN_NV].ival > 0) ? 1 : 0, async);
  5544.     {
  5545.     int xx;
  5546.     debug(F101,"doxconn doconect returns","",x);
  5547.     if ((xx = ttchk()) < 0) dologend();
  5548.     debug(F101,"doxconn ttchk returns","",xx);
  5549.     }
  5550.  
  5551. #ifdef CK_TRIGGER
  5552.     debug(F111,"doxconn doconect triggerval",triggerval,x);
  5553. #endif /* CK_TRIGGER */
  5554.  
  5555.   xconnx:
  5556.     /* Back from CONNECT -- Restore global settings */
  5557.  
  5558.     if (!async)
  5559.       resconn();
  5560.  
  5561.     success = (x > 0) ? 1 : 0;
  5562.     return(x);
  5563. }
  5564. #endif /* NOLOCAL */
  5565.  
  5566. #ifdef ADDCMD
  5567. /* cx == XXADD or XXREMV */
  5568. /* fc == ADD_BIN or ADD_TXT */
  5569. static int
  5570. doadd(cx,fc) int cx, fc; {
  5571. #ifdef PATTERNS
  5572.     char * tmp[FTPATTERNS];
  5573.     char **p = NULL;
  5574.     int i, j, k, n = 0, x = 0, last;
  5575.  
  5576. #endif /* PATTERNS */
  5577.     if (cx != XXADD && cx != XXREMV) {
  5578.     printf("?Unexpected function code: %d\n",cx);
  5579.     return(-9);
  5580.     }
  5581. #ifdef PATTERNS
  5582.     while (n < FTPATTERNS) {        /* Collect new patterns */
  5583.     tmp[n] = NULL;
  5584.     if ((x = cmfld("Pattern","",&s,xxstring)) < 0)
  5585.       break;
  5586.     ckstrncpy(line,s,LINBUFSIZ);
  5587.     s = brstrip(line);
  5588.     makestr(&(tmp[n++]),s);
  5589.     }
  5590.     if (x == -3)
  5591.       x = cmcfm();
  5592.     if (x < 0)
  5593.       goto xdoadd;
  5594.     p = (fc == ADD_BIN) ? binpatterns : txtpatterns; /* Which list */
  5595.     last = 0;
  5596.     for (i = 0; i < FTPATTERNS; i++) { /* Find last one in list */
  5597.     if (!p[i]) {
  5598.         last = i;
  5599.         break;
  5600.     }
  5601.     }
  5602.     if (cx == XXADD) {            /* Adding */
  5603.     if (last + n > FTPATTERNS) {    /* Check if too many */
  5604.         printf("?Too many patterns - %d is the maximum\n", FTPATTERNS);
  5605.         goto xdoadd;
  5606.     }
  5607.         for (i = 0; i < n; i++) {        /* Copy in the new ones. */
  5608.           for (j = 0, x = 0; x == 0 && j < last ; j++ )
  5609.             x = !ckstrcmp(tmp[i],p[j],-1,filecase); /* match */
  5610.           if (x == 0)
  5611.             makestr(&(p[last++]),tmp[i]);
  5612.         }
  5613.         makestr(&(p[last]),NULL);    /* Null-terminate the list */
  5614.         x = 1;
  5615.         goto xdoadd;                    /* Done */
  5616.     } else if (cx == XXREMV) {        /* Remove something(s) */
  5617.     int j, k;
  5618.     if (last == 0)                    /* List is empty */
  5619.       goto xdoadd;                    /* Nothing to remove */
  5620.     for (i = 0; i < n; i++) {            /* i = Patterns they typed */
  5621.         for (j = 0; j < last; j++) {        /* j = Patterns in list */
  5622.         /* Change this to ckstrcmp()... */
  5623.         if (filecase)
  5624.                   x = !ckstrcmp(tmp[i],p[j],-1,filecase); /* match */
  5625.         else
  5626.           x = ckstrcmp(tmp[i],p[j],-1,0); /* Case-independent match */
  5627.         if (x) {                    /* This one matches */
  5628.             makestr(&(p[j]),NULL);      /* Free it */
  5629.             for (k = j; k < last; k++)  /* Move the rest up */
  5630.               p[k] = p[k+1];
  5631.             p[k] = NULL;            /* Erase last one */
  5632.             if (!p[k])
  5633.               break;
  5634.         }
  5635.         }
  5636.     }
  5637.     }
  5638.   xdoadd:                /* Common exit */
  5639.     for (i = 0; i < n; i++)
  5640.       if (tmp[i])
  5641.     free(tmp[i]);
  5642.     return(x);
  5643. #endif /* PATTERNS */
  5644. }
  5645.  
  5646. /* ADD SEND-LIST */
  5647.  
  5648. static int
  5649. addsend(cx) int cx; {
  5650. #ifndef NOMSEND
  5651.     extern struct keytab fttab[];
  5652.     extern int nfttyp;
  5653.     struct filelist * flp;
  5654.     char * fmode = "";
  5655.     int xmode = 0;
  5656.     int xbinary = 0;
  5657. #endif /* NOMSEND */
  5658.  
  5659. #ifdef NOMSEND
  5660.     printf("?Sorry, ADD/REMOVE SEND-LIST not available.\n");
  5661.     return(-9);
  5662. #endif /* NOMSEND */
  5663.     if (cx == XXREMV) {
  5664.     printf("?Sorry, REMOVE SEND-LIST not implemented yet.\n");
  5665.     return(-9);
  5666.     }
  5667. #ifndef NOMSEND
  5668. #ifndef XYZ_INTERNAL
  5669.     if (protocol != PROTO_K) {
  5670.        printf("?Sorry, ADD SEND-LIST does not work with external protocols\n");
  5671.        return(-9);
  5672.     }
  5673. #endif /* XYZ_INTERNAL */
  5674.  
  5675.     x = cmifi("File specification to add","", &s,&y,xxstring);
  5676.     if (x < 0) {
  5677.     if (x == -3) {
  5678.         printf("?A file specification is required\n");
  5679.         return(-9);
  5680.     } else
  5681.       return(x);
  5682.     }
  5683.     ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  5684.     s = tmpbuf;
  5685.     if (filesinlist == 0)        /* Take care of \v(filespec) */
  5686.       fspec[0] = NUL;
  5687.     zfnqfp(s,LINBUFSIZ,line);
  5688.     s = line;
  5689.     if (((int)strlen(fspec) + (int)strlen(s) + 1) < fspeclen) {
  5690.     strcat(fspec,s);        /* safe */
  5691.     strcat(fspec," ");        /* safe */
  5692.     } else
  5693.       printf("WARNING - \\v(filespec) buffer overflow\n");
  5694.  
  5695.  
  5696.     xbinary = binary;
  5697.     if ((patterns || filepeek)        /* FILE PATTERNS or SCAN is ON */
  5698. #ifdef CK_LABELED
  5699.     && binary != XYFT_L        /* And not if FILE TYPE LABELED */
  5700. #endif /* CK_LABELED */
  5701. #ifdef VMS
  5702.     && binary != XYFT_I        /* or FILE TYPE IMAGE */
  5703. #endif /* VMS */
  5704.     ) {
  5705.     int k, x;
  5706.     x = -1;
  5707.     k = scanfile(line,&x,nscanfile);
  5708.     if (k > 0) xbinary = (k == FT_BIN) ? XYFT_B : XYFT_T;
  5709.     }
  5710.     fmode = gfmode(xbinary,0);
  5711.     if ((x = cmkey(fttab,nfttyp,
  5712.            "type of file transfer", fmode, xxstring)) < 0)
  5713.       return(x);
  5714.     xmode = x;
  5715.  
  5716.     cmarg2 = "";
  5717.     if ((x = cmfld(y ?
  5718.   "\nAs-name template containing replacement variables such as \\v(filename)" :
  5719.   "Name to send it with", "",&s,NULL)) < 0)
  5720.       if (x != -3)
  5721.     return(x);
  5722. #ifndef NOSPL
  5723.     if (y && *s) {
  5724.     char * p = tmpbuf;
  5725.     x = TMPBUFSIZ;
  5726.     zzstring(s,&p,&x);
  5727.     if (!strcmp(tmpbuf,s)) {
  5728.         printf(
  5729.   "?As-name for file group must contain variables such as \\v(filename)\n"
  5730.            );
  5731.         return(-9);
  5732.     }
  5733.     }
  5734. #endif /* NOSPL */
  5735.     ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  5736.     cmarg2 = tmpbuf;
  5737.  
  5738.     if ((x = cmcfm()) < 0)
  5739.       return(x);
  5740.     flp = (struct filelist *) malloc(sizeof(struct filelist));
  5741.     if (flp) {
  5742.     if (filetail)
  5743.       filetail->fl_next = flp;
  5744.     filetail = flp;
  5745.     if (!filehead)
  5746.       filehead = flp;
  5747.     x = (int) strlen(line);    /* Length of filename */
  5748.     s = (char *) malloc(x + 1);
  5749.     if (s) {
  5750.         strcpy(s,line);        /* safe */
  5751.         flp->fl_name = s;
  5752.         flp->fl_mode = xmode;
  5753.         x = (int) strlen(cmarg2);    /* Length of as-name */
  5754.         if (x < 1) {
  5755.         flp->fl_alias = NULL;
  5756.         } else {
  5757.         s = (char *) malloc(x + 1);
  5758.         if (s) {
  5759.             strcpy(s,cmarg2);    /* safe */
  5760.             flp->fl_alias = s;
  5761.         } else {
  5762.             printf("Sorry, can't allocate space for as-name");
  5763.             return(-9);
  5764.         }
  5765.         }
  5766.         flp->fl_next = NULL;
  5767.         filesinlist++;        /* Count this node */
  5768.         return(success = 1);    /* Finished adding this node */
  5769.     } else {
  5770.         printf("Sorry, can't allocate space for name");
  5771.         return(-9);
  5772.     }
  5773.     } else {
  5774.     printf("Sorry, can't allocate file list node");
  5775.     return(-9);
  5776.     }
  5777. #endif /* NOMSEND */
  5778. }
  5779. #endif /* ADDCMD */
  5780.  
  5781. #ifndef NOHTTP                /* HTTP ops... */
  5782. #ifdef TCPSOCKET
  5783. #define HTTP_GET 0            /* GET */
  5784. #define HTTP_PUT 1            /* PUT */
  5785. #define HTTP_POS 2            /* POST */
  5786. #define HTTP_IDX 3            /* INDEX */
  5787. #define HTTP_HED 4                      /* HEAD */
  5788. #define HTTP_DEL 5                      /* DELETE */
  5789. #define HTTP_CON 6                      /* CONNECT */
  5790. #define HTTP_OPN 7                      /* OPEN */
  5791. #define HTTP_CLS 8                      /* CLOSE */
  5792.  
  5793. static struct keytab httptab[] = {
  5794.     { "close",   HTTP_CLS, 0 },
  5795.     { "connect", HTTP_CON, 0 },
  5796.     { "delete",  HTTP_DEL, 0 },
  5797.     { "get",     HTTP_GET, 0 },
  5798.     { "head",    HTTP_HED, 0 },
  5799.     { "index",   HTTP_IDX, 0 },
  5800.     { "open",    HTTP_OPN, 0 },
  5801.     { "put",     HTTP_PUT, 0 },
  5802.     { "post",    HTTP_POS, 0 }
  5803. };
  5804. static int nhttptab = sizeof(httptab)/sizeof(struct keytab);
  5805.  
  5806. /* HTTP switches */
  5807. #define HT_SW_AG 0            /* /AGENT */
  5808. #define HT_SW_HD 1            /* /HEADER */
  5809. #define HT_SW_US 2            /* /USER */
  5810. #define HT_SW_PW 3            /* /PASSWORD */
  5811. #define HT_SW_AR 4                      /* /ARRAY */
  5812. #define HT_SW_TP 5                      /* /TOSCREEN */
  5813.  
  5814. static struct keytab httpswtab[] = {
  5815.     { "/agent",    HT_SW_AG, CM_ARG },
  5816. #ifndef NOSPL
  5817.     { "/array",    HT_SW_AR, CM_ARG },
  5818. #endif /* NOSPL */
  5819.     { "/header",   HT_SW_HD, CM_ARG },
  5820.     { "/password", HT_SW_PW, CM_ARG },
  5821.     { "/toscreen", HT_SW_TP, 0 },
  5822.     { "/user",     HT_SW_US, CM_ARG },
  5823.     { "", 0, 0 }
  5824. };
  5825. static int nhttpswtab = sizeof(httpswtab)/sizeof(struct keytab) - 1;
  5826.  
  5827. /* HTTP PUT/POST switches */
  5828. #define HT_PP_MT 0            /* /MIME-TYPE */
  5829.  
  5830. static struct keytab httpptab[] = {
  5831.     { "/mime-type", HT_PP_MT, CM_ARG },
  5832.     { "", 0, 0 }
  5833. };
  5834. static int nhttpptab = sizeof(httpptab)/sizeof(struct keytab) - 1;
  5835.  
  5836. #define HTTP_MAXHDR 8
  5837.  
  5838. static int
  5839. xdohttp(action, lfile, rf, dfile, agent, hdr, user, pass, mime, array, type)
  5840.     int action;
  5841.     char *lfile, *rf, *dfile, *agent, *hdr, *user, *pass, *mime, array;
  5842.     int type;
  5843. /* xdohttp */ {
  5844.     int i, rc = 0;
  5845.     char * hdrlist[HTTP_MAXHDR];
  5846.     char rfile[CKMAXPATH+1];
  5847.     extern int httpfd;
  5848.  
  5849.     /* Check for a valid state to execute the command */
  5850.     if (inserver) {
  5851.         printf("?The HTTP command may not be used from the IKS\r\n");
  5852.     } else if (httpfd == -1) {
  5853.         if (http_reopen() < 0)
  5854.       printf("?No connection\n");
  5855.         else
  5856.       rc = 1;
  5857.     } else {
  5858.     rc = 1;
  5859.     }
  5860.  
  5861.     /* If the command is not valid, exit with failure */
  5862.     if (rc == 0)
  5863.         return(success = 0);
  5864.  
  5865.     if (action != HTTP_CON && rf[0] != '/') {
  5866.         rfile[0] = '/';
  5867.         ckstrncpy(&rfile[1],rf,CKMAXPATH);
  5868.     } else {
  5869.         ckstrncpy(rfile,rf,CKMAXPATH);
  5870.     }
  5871.     for (i = 0; i < HTTP_MAXHDR; i++)    /* Initialize header list */
  5872.       hdrlist[i] = NULL;
  5873.     makelist(hdr,hdrlist,HTTP_MAXHDR);    /* Make header list */
  5874.  
  5875. #ifdef BETADEBUG
  5876.     for (i = 0; i < nhttptab; i++)    /* Find action keyword */
  5877.       if (httptab[i].kwval == action)
  5878.     break;
  5879.     if (i == nhttptab) {        /* Shouldn't happen... */
  5880.     printf("?Invalid action - %d\n",action);
  5881.     return(0);            /* Failure */
  5882.     }
  5883.  
  5884.     printf("HTTP action:  %s\n",httptab[i].kwd);
  5885.     printf(" Agent:       %s\n",agent ? agent : "(null)");
  5886.  
  5887.     if (hdrlist[1]) {
  5888.     printf(" Header list: 1. %s\n",hdrlist[0]);
  5889.     for (i = 1; i < HTTP_MAXHDR && hdrlist[i]; i++)
  5890.       printf("%15d. %s\n",i+1,hdrlist[i]);
  5891.     } else
  5892.       printf(" Header:      %s\n",hdrlist[0] ? hdrlist[0] : "(null)");
  5893.  
  5894.     printf(" User:        %s\n",user ? user : "(null)");
  5895. #ifdef COMMENT
  5896.     printf(" Password:    %s\n",pass ? pass : "(null)");
  5897. #endif /* COMMENT */
  5898.  
  5899. #ifndef NOSPL
  5900.     if (array)
  5901.       printf(" Array:       \\%%%c[]\n", array);
  5902.     else
  5903.       printf(" Array:       (none)\n");
  5904. #endif /* NOSPL */
  5905.  
  5906.     if (action == HTTP_PUT || action == HTTP_POS)
  5907.       printf(" Mime-type:   %s\n",mime ? mime : "(null)");
  5908.  
  5909.     printf(" Local file:  %s\n",lfile ? lfile : "(null)");
  5910.     printf(" Remote file: %s\n",rfile ? rfile : "(null)");
  5911.     printf(" Destination file: %s\n",dfile ? dfile : "(null)");
  5912. #endif /* BETADEBUG */
  5913.  
  5914.     /* The http_xxxx() functions return 0 on success, -1 on failure */
  5915.     switch (action) {
  5916.       case HTTP_CON: {
  5917.       extern int ttyfd;
  5918.       rc = http_connect(httpfd,agent,hdrlist,user,pass,array,rfile);
  5919.       break;
  5920.       }
  5921.       case HTTP_DEL:
  5922.         rc = http_delete(agent,hdrlist,user,pass,array,rfile);
  5923.         break;
  5924.       case HTTP_GET:
  5925.         rc = http_get(agent,hdrlist,user,pass,array,lfile,rfile,type);
  5926.         break;
  5927.       case HTTP_HED:
  5928.         rc = http_head(agent,hdrlist,user,pass,array,lfile,rfile,type);
  5929.         break;
  5930.       case HTTP_PUT:
  5931.         rc = http_put(agent,hdrlist,mime,user,pass,array,lfile,rfile,dfile,
  5932.               type);
  5933.         break;
  5934.       case HTTP_POS:
  5935.         rc = http_post(agent,hdrlist,mime,user,pass,array,lfile,rfile,dfile,
  5936.                type);
  5937.         break;
  5938.       case HTTP_IDX:
  5939.         rc = http_index(agent,hdrlist,user,pass,array,lfile,rfile,type);
  5940.         break;
  5941.       default:
  5942.         rc = -1;
  5943.     }
  5944.     return(rc == 0 ? 1 : 0);            /* Success is set by caller */
  5945. }
  5946. #endif /* TCPSOCKET */
  5947. #endif /* NOHTTP */
  5948.  
  5949. #ifndef NOSPL                /* ARRAY ops... */
  5950. static struct keytab arraytab[] = {
  5951.     { "clear",     ARR_CLR, 0 },
  5952.     { "copy",      ARR_CPY, 0 },
  5953.     { "dcl",       ARR_DCL, CM_INV },
  5954.     { "declare",   ARR_DCL, 0 },
  5955.     { "destroy",   ARR_DST, CM_INV },
  5956.     { "equate",    ARR_EQU, CM_INV },
  5957.     { "link",      ARR_EQU, 0 },
  5958.     { "resize",    ARR_RSZ, 0 },
  5959.     { "set",       ARR_SET, 0 },
  5960. #ifndef NOSHOW
  5961.     { "show",      ARR_SHO, 0 },
  5962. #endif /* NOSHOW */
  5963.     { "sort",      ARR_SRT, 0 },
  5964.     { "undeclare", ARR_DST, 0 },
  5965.     { "", 0, 0 }
  5966. };
  5967. static int narraytab = sizeof(arraytab)/sizeof(struct keytab) - 1;
  5968.  
  5969. #ifdef CKLEARN
  5970. static struct keytab learnswi[] = {
  5971.     { "/close",    2, 0 },
  5972.     { "/off",      0, 0 },
  5973.     { "/on",       1, 0 }
  5974. };
  5975. #endif /* CKLEARN */
  5976.  
  5977. int
  5978. arrayitoa(x) int x; {            /* Array index to array letter */
  5979.     if (x == 1)
  5980.       return(64);
  5981.     else if (x < 0 || x > (122 - ARRAYBASE))
  5982.       return(-1);
  5983.     else
  5984.       return(x + ARRAYBASE);
  5985. }
  5986.  
  5987. int
  5988. arrayatoi(c) int c; {            /* Array letter to array index */
  5989.     if (c == 64)
  5990.       c = 96;
  5991.     if (c > 63 && c < 91)
  5992.       c += 32;
  5993.     if (c < ARRAYBASE || c > 122)
  5994.       return(-1);
  5995.     return(c - ARRAYBASE);
  5996. }
  5997.  
  5998. static int                /* Declare an array */
  5999. dodcl(cx) int cx; {
  6000.     int i, n, v, lo, hi, rc = 0;
  6001.     int isdynamic = 0;
  6002.     char tmpbuf[64];
  6003.     char ** p = NULL;
  6004.     char tmp[64];            /* Local temporary string buffer */
  6005.     if ((y = cmfld("Array name","",&s,NULL)) < 0) { /* Parse array name */
  6006.     if (y == -3) {
  6007.         printf("?Array name required\n");
  6008.         return(-9);
  6009.     } else return(y);
  6010.     }
  6011.     ckstrncpy(line,s,LINBUFSIZ);
  6012.     s = line;
  6013.     x = arraybounds(s,&lo,&hi);        /* Check syntax and get bounds */
  6014.     debug(F111,"dodcl arraybounds",s,x);
  6015.     if (x < 0) {            /* Error - Maybe it's a variable */
  6016.     char * p;            /* whose value is an array name */
  6017.     int n;
  6018.     p = tmpbuf;
  6019.     n = 63;
  6020.     p[0] = NUL;
  6021.     if (s[0] == CMDQ && s[1] == '&')
  6022.       s++;
  6023.     if (zzstring(s,&p,&n) > -1) {
  6024.         s = tmpbuf;
  6025.         x = arraybounds(s,&lo,&hi);
  6026.         debug(F111,"dodcl arraybounds 2",s,x);
  6027.     }
  6028.     if (x < 0) {
  6029.         printf("?Bad array name - \"%s\"\n",s);
  6030.         return(-9);
  6031.     }
  6032.     }
  6033.     debug(F101,"dodcl hi","",hi);
  6034.     debug(F101,"dodcl lo","",lo);
  6035.     debug(F101,"dodcl lo+1","",lo+1);
  6036.  
  6037.     if (lo == -1 && hi == -1) {        /* Have good array name and bounds */
  6038.     isdynamic = 1;
  6039.     n = CMDBL / 5;
  6040.     } else if (hi > -1) {
  6041.     printf("?Segment notation not allowed in array declarations\n");
  6042.     return(-9);
  6043.     } else if ((lo+1) < 0) {
  6044.     debug(F101,"dodcl underflow","",lo+1);
  6045.         printf("?Dimension underflow\n");
  6046.         return(-9);
  6047.     } else
  6048.       n = lo;
  6049.     x = arrayitoa(x);
  6050.     if (cx == XXUNDCL) {
  6051.     n = 0;
  6052.     v = 0;
  6053.     if ((y = cmcfm()) < 0)
  6054.       return(y);
  6055.     } else {
  6056.     p = (char **)malloc(sizeof(char **)*(n+1));
  6057.     if (!p) {
  6058.         printf("?Memory allocation error\n");
  6059.         return(-9);
  6060.     }
  6061.     v = 0;                /* Highest initialized member */
  6062.     p[0] = NULL;            /* Element 0 */
  6063.     keepallchars = 1;
  6064.     while (n > 0 && v < n) {    /* Parse initializers */
  6065.         p[v+1] = NULL;
  6066.         ckmakxmsg(tmp,
  6067.               64,
  6068.               "Initial value for \\&",
  6069.               ckctoa((char)x),
  6070.               "[",
  6071.               ckitoa(v+1),
  6072.               "]",
  6073.               NULL,NULL,NULL,NULL,NULL,NULL,NULL
  6074.               );
  6075.         
  6076.         rc = cmfld((char *)tmp,"",&s,xxstring); /* Get field */
  6077.         if (rc < 0) {        /* Error... */
  6078.         if (rc == -3) {        /* Empty element */
  6079.             if (cmflgs == 1)    /* because end of line? */
  6080.               break;        /* Yes, done initializing */
  6081.             else        /* No, it's just empty */
  6082.               continue;        /* Go on to next one. */
  6083.         } else {        /* Other parse error */
  6084.             goto dclx;        /* Go free temp pointers */
  6085.         }
  6086.         }
  6087.         rc = 1;
  6088.         if (v == 0 && !strcmp(s,"=")) /* Skip the = sign. */
  6089.           continue;
  6090.         s = brstrip(s);        /* Strip any braces */
  6091.         makestr(&(p[++v]),s);
  6092.     }
  6093.     keepallchars = 0;
  6094.     if ((y = cmtxt("Carriage return to confirm","",&s,NULL)) < 0)
  6095.       return(y);
  6096.     if (isdynamic)
  6097.       n = v;
  6098.     }
  6099.     if (dclarray((char)x,n) < 0) {    /* Declare the array */
  6100.     printf("?Declare failed\n");
  6101.     goto dclx;
  6102.     }
  6103.     for (i = 1; i <= v; i++) {        /* Add any initial values */
  6104.     tmp[0] = '&';
  6105.     ckmakmsg(&tmp[1],63,ckctoa((char)x),"[",ckitoa(i),"]");
  6106.     if (addmac(tmp,p[i]) < 0) {
  6107.         printf("Array initialization error: %s %s\n",tmp,p[i]);
  6108.         rc = -9;
  6109.         goto dclx;
  6110.     }
  6111.     }
  6112.   dclx:
  6113.     if (p) {
  6114.     for (i = 1; i <= v; i++)
  6115.       if (p[i]) free(p[i]);
  6116.     free((char *)p);
  6117.     }
  6118.     debug(F101,"DCL rc","",rc);
  6119.     return(success = rc);
  6120. }
  6121.  
  6122. static int
  6123. rszarray() {
  6124.     int i, x, y, n, lo, hi, islink = -1;
  6125.     char c, * s, ** ap = NULL;
  6126.     if ((x = cmfld("Array name","",&s,NULL)) < 0) { /* Parse array name */
  6127.     if (x == -3) {
  6128.         printf("?Array name required\n");
  6129.         return(-9);
  6130.     } else return(x);
  6131.     }
  6132.     ckstrncpy(line,s,LINBUFSIZ);    /* Make safe copy of name */
  6133.     s = line;
  6134.     x = arraybounds(s,&lo,&hi);
  6135.     if (x < 0) {            /* Parse the name, get index */
  6136.     printf("?Bad array reference - \"%s\"\n", s);
  6137.     return(-9);
  6138.     }
  6139.     if (lo < 0 && hi < 0) {
  6140.     y = cmnum("New size","",10,&lo,xxstring);
  6141.     if (y < 0) {
  6142.         if (y == -3)
  6143.           printf("?New size required\n");
  6144.         return(y);
  6145.     }
  6146.     }
  6147.     if ((y = cmcfm()) < 0)
  6148.       return(y);
  6149.     if (a_link[x] > -1) {        /* Link? */
  6150.     islink = x;            /* Yes follow it */
  6151.     x = a_link[x];            /* and remember */
  6152.     }
  6153.     if (!a_ptr[x]) {
  6154.     printf("?Array not declared - \"%s\"\n", s);
  6155.     return(-9);
  6156.     }
  6157.     if (lo < 0) {
  6158.     printf("?New size required\n");
  6159.     return(-9);
  6160.     }
  6161.     if (hi > -1) {
  6162.     printf("?Array segments not allowed for this operation\n");
  6163.     return(-9);
  6164.     }
  6165.     c = arrayitoa(x);            /* Get array letter */
  6166.     if (c == '@') {            /* Argument vector array off limits */
  6167.     printf("?Sorry, \\&@[] is read-only\n");
  6168.     return(-9);
  6169.     }
  6170.     if (lo == 0) {            /* If new size is 0... */
  6171.     dclarray(c,0);            /* Undeclare the array */
  6172.     return(success = 1);
  6173.     }
  6174.     n = a_dim[x];            /* Current size */
  6175.     ap = (char **) malloc((lo+1) * sizeof(char *)); /* New array */
  6176.     y = (n < lo) ? n : lo;
  6177.     for (i = 0; i <= y; i++)        /* Copy the part that fits */
  6178.       ap[i] = a_ptr[x][i];
  6179.     if (n < lo) {            /* If original array smaller */
  6180.     for (; i <= lo; i++)        /* initialize extra elements in */
  6181.       ap[i] = NULL;            /* new array to NULL. */
  6182.     } else if (n > lo) {        /* If new array smaller */
  6183.     for (; i <= lo; i++)        /* deallocate leftover elements */
  6184.       makestr(&(a_ptr[x][i]),NULL);    /* from original array. */
  6185.     }
  6186.     free((char *)a_ptr[x]);        /* Free original array list */
  6187.     a_ptr[x] = ap;            /* Replace with new one */
  6188.     a_dim[x] = lo;            /* Record the new dimension */
  6189.     if (islink > -1) {            /* Was this a link? */
  6190.     a_ptr[islink] = ap;        /* If so point to the resized array */
  6191.     a_dim[islink] = lo;
  6192.     } else {                /* If not are there links to here? */
  6193.     for (i = 0; i < (int) 'z' - ARRAYBASE; i++) { /* Any linked arrays? */
  6194.         if (i != x && a_link[i] == x) {     /* Find and update them */
  6195.         a_ptr[i] = ap;
  6196.         a_dim[i] = lo;
  6197.         }
  6198.     }
  6199.     }
  6200.     return(success = 1);
  6201. }
  6202.  
  6203. static int
  6204. copyarray() {
  6205.     int i, j, x1, lo1, hi1, x2, lo2, hi2, whole = 0;
  6206.     char c1, c2, * a1, * a2;
  6207.     if ((y = cmfld("Name of source array","",&s,NULL)) < 0)
  6208.       return(y);
  6209.     ckstrncpy(line,s,LINBUFSIZ);
  6210.     a1 = line;
  6211.     if ((x1 = arraybounds(a1,&lo1,&hi1)) < 0) {
  6212.     printf("?Bad array reference - \"%s\"\n", a1);
  6213.     return(-9);
  6214.     } else if (!a_ptr[x1]) {
  6215.     printf("?Array not declared - \"%s\"\n", a1);
  6216.     return(-9);
  6217.     }
  6218.     c1 = arrayitoa(x1);
  6219.  
  6220.     if ((y = cmfld("Name of destination array","",&s,NULL)) < 0)
  6221.       return(y);
  6222.     ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  6223.     a2 = tmpbuf;
  6224.     if ((x2 = arraybounds(a2,&lo2,&hi2)) < 0) {
  6225.     printf("?Bad array reference - \"%s\"\n", a2);
  6226.     return(-9);
  6227.     }
  6228.     c2 = arrayitoa(x2);
  6229.  
  6230.     if ((x = cmcfm()) < 0)
  6231.       return(x);
  6232.  
  6233.     if (c2 == '@') {            /* Argument vector array off limits */
  6234.     printf("?Sorry, \\&@[] is read-only\n");
  6235.     return(-9);
  6236.     }
  6237.     if (lo1 < 0 && lo2 < 0 && hi1 < 0 && hi2 < 0) /* Special case for */
  6238.       whole = 1;                      /* whole array... */
  6239.  
  6240.     if (lo1 < 0) lo1 = whole ? 0 : 1;    /* Supply lower bound of source */
  6241.     if (hi1 < 0) hi1 = a_dim[x1];    /* Supply upper bound of source */
  6242.     if (lo2 < 0) lo2 = whole ? 0 : 1;    /* Lower bound of target */
  6243.     if (hi2 < 0) hi2 = lo2 + hi1 - lo1;    /* Upper bound of target */
  6244.     if (a_ptr[x2]) {            /* Target array is already declared? */
  6245.     if (hi2 > a_dim[x2])        /* If upper bound out of range */
  6246.       hi2 = a_dim[x2];        /* shrink to fit */
  6247.     } else {                /* Otherwise... */
  6248.     x2 = dclarray(c2, hi2);        /* declare the target array */
  6249.     }
  6250.     for (i = lo1, j = lo2; i <= hi1 && j <= hi2; i++,j++) { /* Copy */
  6251.     makestr(&(a_ptr[x2][j]),a_ptr[x1][i]);
  6252.     }
  6253.     return(success = 1);
  6254. }
  6255.  
  6256. static int                /* Undeclare an array */
  6257. unarray() {
  6258.     int x, y, n, rc = 0;
  6259.     char c, * s;
  6260.  
  6261.     if ((y = cmfld("Array name","",&s,NULL)) < 0) { /* Parse array name */
  6262.     if (y == -3) {
  6263.         printf("?Array name required\n");
  6264.         return(-9);
  6265.     } else return(y);
  6266.     }
  6267.     ckstrncpy(line,s,LINBUFSIZ);    /* Make safe copy of name */
  6268.     s = line;
  6269.     if ((y = cmcfm()) < 0)
  6270.       return(y);
  6271.     if ((x = arraybounds(s,&y,&n)) < 0) { /* Parse the name, get index */
  6272.     printf("?Bad array reference - \"%s\"\n", s);
  6273.     return(-9);
  6274.     }
  6275.     if (y > 0 || n > 0) {
  6276.     printf("?Partial arrays can not be destroyed\n");
  6277.     return(-9);
  6278.     }
  6279.     c = arrayitoa(x);            /* Get array letter */
  6280.     if (a_ptr[x]) {            /* If array is declared */
  6281.     if (c == '@') {            /* Argument vector array off limits */
  6282.         printf("?Sorry, \\&@[] is read-only\n");
  6283.         return(-9);
  6284.     }
  6285.     rc = dclarray(c,-1);        /* Undeclare the array */
  6286.     } else                /* It wasn't declared */
  6287.       rc = 1;
  6288.     if (rc > -1) {            /* Set return code and success */
  6289.     success = 1;
  6290.     rc = 1;
  6291.     } else {
  6292.     success = 0;
  6293.     printf("?Failed - destroy \"\\&%c[]\"\n", c);
  6294.     rc = -9;
  6295.     }
  6296.     return(rc);
  6297. }
  6298.  
  6299. static int
  6300. clrarray(cx) int cx; {
  6301.     int i, x, lo, hi;
  6302.     char c, * s, * val = NULL;
  6303.  
  6304.     if ((x = cmfld("Array name","",&s,NULL)) < 0) { /* Parse array name */
  6305.     if (x == -3) {
  6306.         printf("?Array name required\n");
  6307.         return(-9);
  6308.     } else return(x);
  6309.     }
  6310.     ckstrncpy(line,s,LINBUFSIZ);    /* Make safe copy of name */
  6311.     s = line;
  6312.     if (cx == ARR_SET) {        /* SET */
  6313.     if ((x = cmtxt("Value","",&val,xxstring)) < 0)
  6314.       return(x);
  6315.     ckstrncpy(tmpbuf,val,TMPBUFSIZ); /* Value to set */
  6316.     val = tmpbuf;
  6317.     if (!*val) val = NULL;
  6318.     } else if ((x = cmcfm()) < 0)    /* CLEAR */
  6319.       return(x);
  6320.  
  6321.     if ((x = arraybounds(s,&lo,&hi)) < 0) { /* Parse the name */
  6322.     printf("?Bad array reference - \"%s\"\n", s);
  6323.     return(-9);
  6324.     }
  6325.     c = arrayitoa(x);            /* Get array letter */
  6326.     if (!a_ptr[x]) {            /* If array is declared */
  6327.     printf("?Array %s is not declared\n", s);
  6328.     return(-9);
  6329.     } else if (c == '@') {        /* Argument vector array off limits */
  6330.     printf("?Sorry, \\&@[] is read-only\n");
  6331.     return(-9);
  6332.     }
  6333.     if (lo < 0) lo = 0;
  6334.     if (hi < 0) hi = a_dim[x];
  6335.     for (i = lo; i <= hi; i++)        /* Clear/Set selected range */
  6336.       makestr(&(a_ptr[x][i]),val);
  6337.  
  6338.     return(success = 1);
  6339. }
  6340.  
  6341. extern char **aa_ptr[CMDSTKL][28];
  6342. extern int aa_dim[CMDSTKL][28];
  6343.  
  6344. static int                /* Create symbolic link to an array */
  6345. linkarray() {
  6346.     int i = 0, x, y, lo, hi, flag = 0;
  6347.     char c, * s, * p;
  6348.  
  6349.     if ((x = cmfld("Array name not currently in use","",&s,NULL)) < 0) {
  6350.     if (x == -3) {
  6351.         printf("?Array name required\n");
  6352.         return(-9);
  6353.     } else return(x);
  6354.     }
  6355.     ckstrncpy(line,s,LINBUFSIZ);    /* Make safe copy of link name */
  6356.     s = line;
  6357.     if ((x = cmfld("Name of existing array","",&p,xxstring)) < 0) {
  6358.     if (x == -3) {
  6359.         printf("?Array name required\n");
  6360.         return(-9);
  6361.     } else return(x);
  6362.     }
  6363.     ckstrncpy(tmpbuf,p,TMPBUFSIZ);    /* Make safe copy of array name */
  6364.     p = tmpbuf;
  6365.     if ((x = cmcfm()) < 0)
  6366.       return(x);
  6367.  
  6368.     if ((x = arraybounds(s,&lo,&hi)) < 0) { /* Parse the link name */
  6369.     printf("?Bad array reference - \"%s\"\n", s);
  6370.     return(-9);
  6371.     }
  6372.     if (a_ptr[x]) {            /* Must not already exist */
  6373.     c = arrayitoa(x);
  6374.     printf("?Array already exists: \\&%c[]\n", c);
  6375.     return(-9);
  6376.     }
  6377.     if (lo > -1 || hi > -1) {
  6378.     printf("?Sorry, whole arrays only: %s\n",s);
  6379.     return(-9);
  6380.     }
  6381.     if ((y = arraybounds(p,&lo,&hi)) < 0) { /* Parse the array name */
  6382.     printf("?Bad array reference - \"%s\"\n", s);
  6383.     return(-9);
  6384.     }
  6385.     if (lo > -1 || hi > -1) {
  6386.     printf("?Sorry, whole arrays only: %s\n",p);
  6387.     return(-9);
  6388.     }
  6389.     if (x == y) {
  6390.     for (i = cmdlvl; i >= 0; i--)
  6391.       if (aa_ptr[i][x]) {
  6392.           flag++;
  6393.           break;
  6394.       }
  6395.     }
  6396.     if (flag) {
  6397.     a_ptr[x] = aa_ptr[i][y];    /* Link to saved copy */
  6398.     a_dim[x] = aa_dim[i][y];
  6399.     } else {                /* Otherwise... */
  6400.     c = arrayitoa(y);        /* Check if it's declared */
  6401.     if (!a_ptr[y]) {
  6402.         printf("?Array is not declared: \\&%c[]\n", c);
  6403.         return(-9);
  6404.     }
  6405.     if (a_link[y] > -1) {        /* And if it's a link itself */
  6406.         printf("?Links to links not allowed: \\&%c[]\n", c);
  6407.         return(-9);
  6408.     }
  6409.     a_ptr[x] = a_ptr[y];        /* All OK, make the link */
  6410.     a_dim[x] = a_dim[y];
  6411.     }
  6412.     a_link[x] = y;
  6413.     return(success = 1);
  6414. }
  6415. #endif /* NOSPL */
  6416.  
  6417. #ifndef NOCSETS
  6418. static char * dcsetname = NULL;
  6419.  
  6420. /* Get Display Character-Set Name */
  6421.  
  6422. char *
  6423. getdcset() {
  6424.     char * s;
  6425.     int y;
  6426. #ifdef PCFONTS
  6427.     extern int tt_font, ntermfont;
  6428.     extern struct keytab term_font[];
  6429. #endif /* PCFONTS */
  6430.  
  6431.     s = "";
  6432. #ifdef OS2
  6433.     y = os2getcp();            /* Default is current code page */
  6434.     switch (y) {
  6435.       case 437: s = "cp437"; break;
  6436.       case 850: s = "cp850"; break;
  6437.       case 852: s = "cp852"; break;
  6438.       case 857: s = "cp857"; break;
  6439.       case 858: s = "cp858"; break;
  6440.       case 862: s = "cp862"; break;
  6441.       case 866: s = "cp866"; break;
  6442.       case 869: s = "cp869"; break;
  6443.       case 1250: s = "cp1250"; break;
  6444.       case 1251: s = "cp1251"; break;
  6445.       case 1252: s = "cp1252"; break;
  6446.       case 1253: s = "cp1253"; break;
  6447.       case 1254: s = "cp1254"; break;
  6448.       case 1255: s = "cp1255"; break;
  6449.       case 1256: s = "cp1256"; break;
  6450.       case 1257: s = "cp1257"; break;
  6451.       case 1258: s = "cp1258"; break;
  6452.     }
  6453. #ifdef PCFONTS
  6454. /*
  6455.    If the user has loaded a font with SET TERMINAL FONT then we want
  6456.    to change the default code page to the font that was loaded.
  6457. */
  6458.     if (tt_font != TTF_ROM) {
  6459.     for (y = 0; y < ntermfont; y++ ) {
  6460.         if (term_font[y].kwval == tt_font) {
  6461.         s = term_font[y].kwd;
  6462.         break;
  6463.         }
  6464.     }
  6465.     }
  6466. #endif /* PCFONTS */
  6467. #else /* OS2 */
  6468. #ifdef COMMENT
  6469.     /* Hack not needed as of C-Kermit 7.1 */
  6470.     if (fcharset == FC_1LATIN) {
  6471.     s = "latin1-iso";        /* Hack to avoid reporting "cp1252" */
  6472.     } else {                /* Report current file character set */
  6473. #endif /* COMMENT */
  6474.     for (y = 0; y <= nfilc; y++)
  6475.       if (fcstab[y].kwval == fcharset) {
  6476.           s = fcstab[y].kwd;
  6477.           break;
  6478.       }
  6479. #ifdef COMMENT
  6480.     }
  6481. #endif /* COMMENT */
  6482. #endif /* OS2 */
  6483.     makestr(&dcsetname,s);        /* Return stable pointer */
  6484.     return((char *)dcsetname);
  6485. }
  6486. #endif /* NOCSETS */
  6487.  
  6488. #ifndef NOFRILLS
  6489. static int
  6490. doclear() {
  6491.     if ((x = cmkey(clrtab,nclear,"item to clear",
  6492. #ifdef NOSPL
  6493.            "device-buffer"
  6494. #else
  6495.            "device-and-input"
  6496. #endif /* NOSPL */
  6497.            ,xxstring)) < 0) return(x);
  6498. #ifndef NOSPL
  6499. #ifdef OS2
  6500.     if (x == CLR_CMD || x == CLR_TRM) {
  6501.     if ((z = cmkey(clrcmdtab,nclrcmd,"how much screen to clear\n",
  6502.                "all",xxstring)) < 0)
  6503.       return(z);
  6504.     }
  6505. #endif /* OS2 */
  6506. #endif /* NOSPL */
  6507.     if ((y = cmcfm()) < 0)
  6508.       return(y);
  6509.  
  6510.     /* Clear device input buffer if requested */
  6511.     y = (x & CLR_DEV) ? ttflui() : 0;
  6512.  
  6513.     if (x & CLR_SCR)            /* CLEAR SCREEN */
  6514.       y = ck_cls();            /* (= SCREEN CLEAR = CLS) */
  6515.  
  6516.     if (x & CLR_KBD) {            /* CLEAR KEYBOARD */
  6517.     int n;
  6518.     n = conchk();
  6519.     y = 0;
  6520.     while (n-- > 0 && (y = coninc(0) > -1))
  6521.       ;
  6522.     y = (y > -1) ? 0 : -1;
  6523.     }
  6524.  
  6525. #ifndef NOSPL
  6526.     /* Clear INPUT command buffer if requested */
  6527.     if (x & CLR_INP) {
  6528.     for (z = 0; z < inbufsize; z++)
  6529.       inpbuf[z] = NUL;
  6530.     inpbp = inpbuf;
  6531.     y = 0;
  6532.     }
  6533. #ifdef CK_APC
  6534.     if (x & CLR_APC) {
  6535.     debug(F101,"Executing CLEAR APC","",apcactive);
  6536.     apcactive = 0;
  6537.     y = 0;
  6538.     }
  6539. #endif /* CK_APC */
  6540.     if (x & CLR_ALR) {
  6541.     setalarm(0L);
  6542.     y = 0;
  6543.     }
  6544. #endif /* NOSPL */
  6545.  
  6546. #ifdef PATTERNS
  6547.     if (x & (CLR_TXT|CLR_BIN)) {
  6548.     int i;
  6549.     for (i = 0; i < FTPATTERNS; i++) {
  6550.         if (x & CLR_TXT)
  6551.           makestr(&txtpatterns[i],NULL);
  6552.         if (x & CLR_BIN)
  6553.           makestr(&binpatterns[i],NULL);
  6554.     }
  6555.     y = 0;
  6556.     }
  6557. #endif /* PATTERNS */
  6558.  
  6559. #ifndef NODIAL
  6560.     if (x & CLR_DIA) {
  6561.     dialsta = DIA_UNK;
  6562.     y = 0;
  6563.     }
  6564. #endif /* NODIAL */
  6565.  
  6566. #ifndef NOMSEND
  6567.     if (x & CLR_SFL) {            /* CLEAR SEND-LIST */
  6568.     if (filehead) {
  6569.         struct filelist * flp, * next;
  6570.         flp = filehead;
  6571.         while (flp) {
  6572.         if (flp->fl_name)
  6573.           free(flp->fl_name);
  6574.         if (flp->fl_alias)
  6575.           free(flp->fl_alias);
  6576.         next = flp->fl_next;
  6577.         free((char *)flp);
  6578.         flp = next;
  6579.         }
  6580.     }
  6581.     filesinlist = 0;
  6582.     filehead = NULL;
  6583.     filetail = NULL;
  6584.     addlist = 0;
  6585.     y = 0;
  6586.     }
  6587. #endif /* NOMSEND */
  6588.  
  6589. #ifdef OS2
  6590. #ifndef NOLOCAL
  6591.     switch (x) {
  6592.       case CLR_SCL:
  6593.     clearscrollback(VTERM);
  6594.     break;
  6595.       case CLR_CMD:
  6596.     switch ( z ) {
  6597.       case CLR_C_ALL:
  6598.         clear();
  6599.         break;
  6600.       case CLR_C_BOS:
  6601.         clrboscr_escape(VCMD,SP);
  6602.         break;
  6603.       case CLR_C_BOL:
  6604.         clrbol_escape(VCMD,SP);
  6605.         break;
  6606.       case CLR_C_EOL:
  6607.         clrtoeoln(VCMD,SP);
  6608.         break;
  6609.       case CLR_C_EOS:
  6610.         clreoscr_escape(VCMD,SP);
  6611.         break;
  6612.       case CLR_C_LIN:
  6613.         clrline_escape(VCMD,SP);
  6614.         break;
  6615.       case CLR_C_SCR:
  6616.         clearscrollback(VCMD);
  6617.         break;
  6618.     default:
  6619.         printf("Not implemented yet, sorry.\n");
  6620.         break;
  6621.     }
  6622.     break;
  6623.  
  6624. #ifndef NOTERM
  6625.       case CLR_TRM:
  6626.      switch ( z ) {
  6627.       case CLR_C_ALL:
  6628.          if (VscrnGetBufferSize(VTERM) > 0 ) {
  6629.          VscrnScroll(VTERM, UPWARD, 0,
  6630.                  VscrnGetHeight(VTERM)-(tt_status[VTERM]?2:1),
  6631.                  VscrnGetHeight(VTERM) -
  6632.                  (tt_status[VTERM]?1:0), TRUE, SP
  6633.                  );
  6634.          cleartermscreen(VTERM);
  6635.          }
  6636.          break;
  6637.       case CLR_C_BOS:
  6638.         clrboscr_escape(VTERM,SP);
  6639.         break;
  6640.       case CLR_C_BOL:
  6641.         clrbol_escape(VTERM,SP);
  6642.         break;
  6643.       case CLR_C_EOL:
  6644.         clrtoeoln(VTERM,SP);
  6645.         break;
  6646.       case CLR_C_EOS:
  6647.         clreoscr_escape(VTERM,SP);
  6648.         break;
  6649.       case CLR_C_LIN:
  6650.         clrline_escape(VTERM,SP);
  6651.         break;
  6652.      case CLR_C_SCR:
  6653.          clearscrollback(VTERM);
  6654.          break;
  6655.      default:
  6656.          printf("Not implemented yet, sorry.\n");
  6657.          break;
  6658.     }
  6659.     break;
  6660. #endif /* NOTERM */
  6661.     }
  6662.     y = 0;
  6663. #endif /* NOLOCAL */
  6664. #endif /* OS2 */
  6665.     return(success = (y == 0));
  6666. }
  6667. #endif /* NOFRILLS */
  6668.  
  6669. #ifndef NOSPL
  6670. static int
  6671. doeval(cx) int cx; {
  6672.     char *p;
  6673.     char vnambuf[VNAML], * vnp = NULL;    /* These must be on the stack */
  6674.     if (!oldeval) {
  6675.     if ((y = cmfld("Variable name","",&s,
  6676.                ((cx == XX_EVAL) ? xxstring : NULL))) < 0) {
  6677.         if (y == -3) {
  6678.         printf("?Variable name required\n");
  6679.         return(-9);
  6680.         } else return(y);
  6681.     }
  6682.     ckstrncpy(vnambuf,s,VNAML);    /* Make a copy. */
  6683.     vnp = vnambuf;
  6684.     if (vnambuf[0] == CMDQ &&
  6685.         (vnambuf[1] == '%' || vnambuf[1] == '&'))
  6686.       vnp++;
  6687.     y = 0;
  6688.     if (*vnp == '%' || *vnp == '&') {
  6689.         if ((y = parsevar(vnp,&x,&z)) < 0)
  6690.           return(y);
  6691.     }
  6692.     }
  6693.     if ((x = cmtxt("Integer arithmetic expression","",&s,xxstring)) < 0)
  6694.       return(x);
  6695.     p = evala(s);
  6696.     if (!p) p = "";
  6697.     if (oldeval && *p)
  6698.       printf("%s\n", p);
  6699.     ckstrncpy(evalbuf,p,32);
  6700.     if (!oldeval)
  6701.       return(success = addmac(vnambuf,p));
  6702.     else
  6703.       return(success = *p ? 1 : 0);
  6704. }
  6705. #endif /* NOSPL */
  6706.  
  6707. #ifdef TNCODE
  6708. static int
  6709. dotelopt() {
  6710.     if ((x = cmkey(telcmd, ntelcmd, "TELNET command", "", xxstring)) < 0 )
  6711.       return(x);
  6712.     switch (x) {
  6713.       case WILL:
  6714.       case WONT:
  6715.       case DO:
  6716.       case DONT:
  6717.     if ((y = cmkey(tnopts,ntnopts,"TELNET option","",xxstring)) < 0)
  6718.       return(y);
  6719.     if ((z = cmcfm()) < 0) return(z);
  6720.  
  6721.     switch (x) {
  6722.       case WILL:
  6723.         if (TELOPT_UNANSWERED_WILL(y))
  6724.           return(success = 0);
  6725.         break;
  6726.       case WONT:
  6727.         if (TELOPT_UNANSWERED_WONT(y))
  6728.           return(success = 0);
  6729.         break;
  6730.       case DO:
  6731.         if (TELOPT_UNANSWERED_DO(y))
  6732.           return(success = 0);
  6733.         break;
  6734.       case DONT:
  6735.         if (TELOPT_UNANSWERED_DONT(y))
  6736.           return(success = 0);
  6737.         break;
  6738.     }
  6739.     if (local) {
  6740.         success = ((tn_sopt(x,y) > -1) ? 1 : 0);
  6741.     } else {
  6742.         printf("ff%02x%02x\n",x,y);
  6743.         success = 1;
  6744.     }
  6745.     if (success) {
  6746.         switch (x) {
  6747.           case WILL:
  6748.         TELOPT_UNANSWERED_WILL(y) = 1;
  6749.         break;
  6750.           case WONT:
  6751.         if ( TELOPT_ME(y) )
  6752.           TELOPT_UNANSWERED_WONT(y) = 1;
  6753.         break;
  6754.           case DO:
  6755.         TELOPT_UNANSWERED_DO(y) = 1;
  6756.         break;
  6757.           case DONT:
  6758.         if ( TELOPT_ME(y) )
  6759.           TELOPT_UNANSWERED_DONT(y) = 1;
  6760.         break;
  6761.         }
  6762.         if (tn_wait("XXTELOP") < 0) {
  6763.         tn_push();
  6764.         success = 0;
  6765.         }
  6766.     }
  6767.     return(success);
  6768.       case SB:
  6769.     if ((y=cmkey(tnsbopts,ntnsbopts,"TELNET option","",xxstring)) < 0)
  6770.       return(y);
  6771.     switch (y) {
  6772.       case TELOPT_NAWS:
  6773.         /* Some compilers require switch() to have at least 1 case */
  6774. #ifdef CK_NAWS
  6775.         TELOPT_SB(TELOPT_NAWS).naws.x = 0;
  6776.         TELOPT_SB(TELOPT_NAWS).naws.y = 0;
  6777.         if (local)
  6778.           return(success = ((tn_snaws() > -1) ? 1 : 0));
  6779.         else
  6780.           return(success = 0);
  6781. #else
  6782.         return(success = 0);
  6783. #endif /* CK_NAWS */
  6784.     }
  6785.         return(success = 0);
  6786.  
  6787. #ifdef CK_KERBEROS
  6788. #ifdef KRB5
  6789.       case TN_FWD:
  6790.         success = (kerberos5_forward() == AUTH_SUCCESS);
  6791.         return(success);
  6792. #endif /* KRB5 */
  6793. #endif /* CK_KERBEROS */
  6794.  
  6795.       default:
  6796.     if ((z = cmcfm()) < 0) return(z);
  6797. #ifndef NOLOCAL
  6798.     if (local) {
  6799.         CHAR temp[3];
  6800.         if (network && IS_TELNET()) { /* TELNET */
  6801.         temp[0] = (CHAR) IAC;
  6802.         temp[1] = x;
  6803.         temp[2] = NUL;
  6804.         success = (ttol((CHAR *)temp,2) > -1 ? 1 : 0);
  6805.         if (tn_deb || debses || deblog) {
  6806.             /* TN_MSG_LEN is in ckctel.h */
  6807.             ckmakmsg(tn_msg,256,"TELNET SENT ",TELCMD(x),NULL,NULL);
  6808.             debug(F101,tn_msg,"",x);
  6809.             if (debses || tn_deb) tn_debug(tn_msg);
  6810.         }
  6811.         return(success);
  6812.         }
  6813.             return(success = 0);
  6814.     } else {
  6815. #endif /* NOLOCAL */
  6816.         printf("ff%02x\n",x);
  6817.         return(success = 1);
  6818. #ifndef NOLOCAL
  6819.     }
  6820. #endif /* NOLOCAL */
  6821.     }
  6822. }
  6823. #endif /* TNCODE */
  6824.  
  6825.  
  6826. #ifndef NOPUSH
  6827. #ifndef NOFRILLS
  6828. static int
  6829. doedit() {
  6830. #ifdef OS2
  6831.     char * p = NULL;
  6832. #endif /* OS2 */
  6833.     if (!editor[0]) {
  6834.     s = getenv("EDITOR");
  6835.     if (s) ckstrncpy(editor,s,CKMAXPATH);
  6836.     editor[CKMAXPATH] = NUL;
  6837.     if (!editor[0]) {
  6838.         printf("?Editor not defined - use SET EDITOR to define\n");
  6839.         return(-9);
  6840.     }
  6841.     }
  6842.     ckstrncpy(tmpbuf,editfile,TMPBUFSIZ);
  6843. /*
  6844.   cmiofi() lets us parse the name of an existing file, or the name of
  6845.   a nonexistent file to be created.
  6846. */
  6847.     x = cmiofi("File to edit", (char *)tmpbuf, &s, &y, xxstring);
  6848.     debug(F111,"edit",s,x);
  6849.     if (x < 0 && x != -3)
  6850.       return(x);
  6851.     if (x == -3) {
  6852.     tmpbuf[0] = NUL;
  6853.     } else {
  6854.     ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  6855.     }
  6856.     if ((z = cmcfm()) < 0) return(z);
  6857.     if (y) {
  6858.     printf("?A single file please\n");
  6859.     return(-9);
  6860.     }
  6861.     if (nopush) {
  6862.     printf("?Sorry, editing not allowed\n");
  6863.     return(success = 0);
  6864.     }
  6865.     if (tmpbuf[0]) {
  6866.     /* Get full path in case we change directories between EDIT commands */
  6867.     zfnqfp(tmpbuf, CKMAXPATH, editfile);
  6868.     editfile[CKMAXPATH] = NUL;
  6869. #ifdef OS2
  6870.     p = editfile;            /* Flip the stupid slashes */
  6871.     while (*p) {
  6872.         if (*p == '/') *p = '\\';
  6873.         p++;
  6874.     }
  6875. #endif /* OS2 */
  6876.     } else
  6877.       editfile[0] = NUL;
  6878.     if (editfile[0]) {
  6879.     if (zchki(editfile) < (CK_OFF_T)0 && zchko(editfile) < 0) {
  6880.         printf("?Access denied: %s\n",editfile);
  6881.         return(-9);
  6882.     }
  6883.     }
  6884.     x = 0;
  6885.     if (editopts[0]) {
  6886. #ifdef OS2
  6887.     x = ckindex("%1",(char *)editopts,0,0,1);
  6888.     if (x > 0)
  6889.       editopts[x] = 's';
  6890.     else
  6891. #endif /* OS2 */
  6892.       x = ckindex("%s",(char *)editopts,0,0,1);
  6893.     }
  6894.     if (((int)strlen(editopts) + (int)strlen(editfile) + 1) < TMPBUFSIZ) {
  6895.     if (x)
  6896.       sprintf(tmpbuf,editopts,editfile);
  6897.     else
  6898.       sprintf(tmpbuf,"%s %s",editopts,editfile);
  6899.     }
  6900.     s = line;
  6901.     ckmakmsg(s,LINBUFSIZ,editor," ",tmpbuf,NULL);
  6902. #ifdef OS2
  6903.     p = s + strlen(editor);        /* And again with the slashes */
  6904.     while (p != s) {
  6905.     if (*p == '/') *p = '\\';
  6906.     p--;
  6907.     }
  6908. #endif /* OS2 */
  6909.     conres();
  6910.     x = zshcmd(s);
  6911.     concb((char)escape);
  6912.     return(x);
  6913. }
  6914. #endif /* NOFRILLS */
  6915. #endif /* NOPUSH */
  6916.  
  6917. #ifdef BROWSER
  6918. static int
  6919. dobrowse() {
  6920. #ifdef OS2
  6921.     char * p = NULL;
  6922. #endif /* OS2 */
  6923.     if (nopush) {
  6924.     printf("?Sorry, browsing not allowed\n");
  6925.     return(success = 0);
  6926.     }
  6927. #ifndef NT
  6928.     /* Windows lets the Shell Execute the URL if no Browser is defined */
  6929.     if (!browser[0]) {
  6930.     s = getenv("BROWSER");
  6931.     if (s) ckstrncpy(browser,s,CKMAXPATH);
  6932.     browser[CKMAXPATH] = NUL;
  6933.     if (!browser[0]) {
  6934.         printf("?Browser not defined - use SET BROWSER to define\n");
  6935.         return(-9);
  6936.     }
  6937.     }
  6938. #endif /* NT */
  6939.     ckstrncpy(tmpbuf,browsurl,TMPBUFSIZ);
  6940.     if ((x = cmtxt("URL",(char *)browsurl,&s,xxstring)) < 0)
  6941.       return(x);
  6942.     ckstrncpy(browsurl,s,4096);
  6943.     x = 0;
  6944.     if (browsopts[0]) {
  6945. #ifdef OS2
  6946.     x = ckindex("%1",(char *)browsopts,0,0,1);
  6947.     if (x > 0)
  6948.       browsopts[x] = 's';
  6949.     else
  6950. #endif /* OS2 */
  6951.       x = ckindex("%s",(char *)browsopts,0,0,1);
  6952.     }
  6953.     if (((int)strlen(browsopts) + (int)strlen(browsurl) + 1) < TMPBUFSIZ) {
  6954.     if (x)
  6955.       sprintf(tmpbuf,browsopts,browsurl);
  6956.     else
  6957.       sprintf(tmpbuf,"%s %s",browsopts,browsurl);
  6958.     }
  6959. #ifdef NT
  6960.     if (!browser[0])
  6961.       return(success = Win32ShellExecute(browsurl));
  6962. #endif /* NT */
  6963.     s = line;
  6964.     ckmakmsg(s,LINBUFSIZ,browser," ",tmpbuf,NULL);
  6965. #ifdef OS2
  6966.     p = line + strlen(browser);        /* Flip slashes */
  6967.     while (p != line) {
  6968.     if (*p == '/') *p = '\\';
  6969.     p--;
  6970.     }
  6971. #endif /* OS2 */
  6972.     conres();
  6973.     x = zshcmd(s);
  6974.     concb((char)escape);
  6975.     return(x);
  6976. }
  6977. #endif /* BROWSER */
  6978.  
  6979. #ifdef CK_RECALL
  6980. static int
  6981. doredo() {            /* Find a previous cmd and redo it */
  6982.     extern int on_recall, in_recall;
  6983.     int x;
  6984.     char * p;
  6985.  
  6986.     if ((x = cmtxt(
  6987. "pattern, or first few characters of a previous command",
  6988.            "*",&s,xxstring)) < 0)
  6989.       return(x);
  6990.     ckstrncpy(line,s,LINBUFSIZ);
  6991.     x = strlen(s);
  6992.     s = line;
  6993.     if (*s == '{') {            /* Braces disable adding * to end */
  6994.     if (s[x-1] == '}') {
  6995.         s[x-1] = NUL;
  6996.         s++;
  6997.         x--;
  6998.     }
  6999.     } else {                /* No braces, add * to end. */
  7000.     s[x] = '*';
  7001.     s[x+1] = NUL;
  7002.     }
  7003.  
  7004.     while (x > 0 && s[x] == '*' && s[x-1] == '*') s[x--] = NUL;
  7005.  
  7006.     if (!on_recall || !in_recall) {
  7007.     printf("?Sorry, command recall can't be used now.\n");
  7008.     return(-9);
  7009.     }
  7010.     if ((p = cmgetcmd(s))) {        /* Look for it history buffer */
  7011.     ckmakmsg(cmdbuf,CMDBL,p,"\r",NULL,NULL); /* Copy to command buffer */
  7012.     if (!quiet)            /* Echo it */
  7013.       printf("%s\n",cmdbuf);
  7014.     cmaddnext();            /* Force re-add to history buffer */
  7015.     return(cmflgs = -1);        /* Force reparse */
  7016.     } else {
  7017.     printf("?Sorry - \"%s\" not found\n", s);
  7018.     return(-9);
  7019.     }
  7020. }
  7021. #endif /* CK_RECALL */
  7022.  
  7023. #ifndef NOXFER
  7024. #ifndef NOCSETS
  7025. static int
  7026. doassoc()  {                /* ASSOCIATE */
  7027.     extern struct keytab tcstab[];
  7028.     extern int ntcs;
  7029.     if ((x = cmkey(assoctab, nassoc, "", "", xxstring)) < 0 )
  7030.       return(x);
  7031.  
  7032.     switch (x) {            /* Associate what? */
  7033.  
  7034.       case ASSOC_TC:            /* Transfer character-set... */
  7035.     if ((x = cmkey(tcstab, ntcs,
  7036.                "transfer character-set name","",xxstring)) < 0)
  7037.       return(x);
  7038.     if ((y = cmkey(fcstab, nfilc,
  7039.                "with file character-set","", xxstring)) < 0)
  7040.       if (y != -3)
  7041.         return(y);
  7042.     if ((z = cmcfm()) < 0)
  7043.       return(z);
  7044.     axcset[x] = y;
  7045.     return(success = 1);
  7046.  
  7047.       case ASSOC_FC:            /* File character-set... */
  7048.     if ((x = cmkey(fcstab, nfilc,
  7049.                "file character-set name","",xxstring)) < 0)
  7050.       return(x);
  7051.     if ((y = cmkey(tcstab, ntcs,
  7052.                "with transfer character-set","", xxstring)) < 0)
  7053.       if (y != -3)
  7054.         return(y);
  7055.     if ((z = cmcfm()) < 0)
  7056.       return(z);
  7057.     afcset[x] = y;
  7058.     return(success = 1);
  7059.  
  7060.       default:
  7061.     return(-2);
  7062.     }
  7063. }
  7064. #endif /* NOCSETS */
  7065. #endif /* NOXFER */
  7066.  
  7067. #ifndef NOHELP
  7068. static int
  7069. domanual() {
  7070. #ifdef OS2
  7071.     if ((x = cmcfm()) < 0)
  7072.       return(x);
  7073.     if (nopush) {
  7074.     printf("?Sorry, access to system commands is disabled.\n");
  7075.     return(-9);
  7076.     }
  7077.     y = mxlook(mactab,"manual",nmac);
  7078.     if (y > -1) {
  7079.     z = maclvl;            /* Save the current maclvl */
  7080.     dodo(y,NULL,cmdstk[cmdlvl].ccflgs); /* Run the macro */
  7081.     while (maclvl > z) {
  7082.         debug(F101,"XXMAN loop maclvl 1","",maclvl);
  7083.         sstate = (CHAR) parser(1);
  7084.         debug(F101,"XXMAN loop maclvl 2","",maclvl);
  7085.         if (sstate) proto();
  7086.     }
  7087.     debug(F101,"XXMAN loop exit maclvl","",maclvl);
  7088.     return(success);
  7089.     }
  7090.     return(success = 0);
  7091. #else
  7092.     if ((x = cmtxt(
  7093. #ifdef UNIX
  7094.            "Carriage return to confirm the command, or manual topic",
  7095. #else
  7096.            "Carriage return to confirm the command, or help topic",
  7097. #endif /* UNIX */
  7098.            "kermit",
  7099.            &s,
  7100.            xxstring
  7101.            )
  7102.      ) < 0)
  7103.       return(x);
  7104. #endif /* OS2 */
  7105.  
  7106. #ifdef UNIX
  7107.     ckmakmsg(tmpbuf,TMPBUFSIZ,"man ",s,NULL,NULL);
  7108. #else
  7109.     ckmakmsg(tmpbuf,TMPBUFSIZ,"help ",s,NULL,NULL);
  7110. #endif /* UNIX */
  7111.     debug(F110,"MANUAL",tmpbuf,0);
  7112.     if (nopush) {
  7113.     printf("?Sorry, access to system commands is disabled.\n");
  7114.     return(-9);
  7115.     } else {
  7116.     conres();            /* Restore the console */
  7117.     success = zshcmd(tmpbuf);
  7118.     concb((char)escape);        /* Restore CBREAK mode */
  7119.     return(success);
  7120.     }
  7121. }
  7122. #endif /* NOHELP */
  7123.  
  7124. #ifndef NOHTTP
  7125. #ifdef TCPSOCKET
  7126. static struct keytab sslswtab[] = {
  7127.     { "/ssl", 1, 0 },
  7128.     { "/tls", 1, 0 }
  7129. };
  7130.  
  7131. #ifndef NOURL
  7132. struct urldata http_url = {NULL,NULL,NULL,NULL,NULL,NULL,NULL};
  7133. #endif /* NOURL */
  7134.  
  7135. static int
  7136. dohttp() {                /* HTTP */
  7137.     struct FDB sw, kw, fi;
  7138.     int n, getval, allinone = 0;
  7139.     char c, * p;
  7140.     char rdns[128];
  7141.  
  7142.     char * http_agent = NULL;        /* Parse results */
  7143.     char * http_hdr   = NULL;
  7144.     char * http_user  = NULL;
  7145.     char * http_pass  = NULL;
  7146.     char * http_mime  = NULL;
  7147.     char * http_lfile = NULL;
  7148.     char * http_rfile = NULL;
  7149.     char * http_dfile = NULL;
  7150.     char   http_array = NUL;
  7151.     int    http_action = -1;
  7152.  
  7153.     char * http_host = NULL;
  7154.     char * http_srv  = NULL;
  7155.     int    http_ssl  = 0;
  7156.  
  7157.     static char * http_d_agent = NULL;
  7158.     static char * http_d_user = NULL;
  7159.     static char * http_d_pass = NULL;
  7160.  
  7161.     static int    http_d_type = 0;
  7162.     int           http_type = http_d_type;
  7163.  
  7164. #ifdef OS2
  7165.     p = "Kermit 95";            /* Default user agent */
  7166. #else
  7167.     p = "C-Kermit";
  7168. #endif /* OS2 */
  7169.     makestr(&http_agent,p);
  7170.     makestr(&http_mime,"text/HTML");    /* MIME type default */
  7171.     rdns[0] = '\0';
  7172.  
  7173.     cmfdbi(&sw,                /* 1st FDB - general switches */
  7174.        _CMKEY,                /* fcode */
  7175.        "OPEN, CLOSE, GET, HEAD, PUT, INDEX, or POST,\n or switch", /* hlpmsg */
  7176.        "",                /* default */
  7177.        "",                /* addtl string data */
  7178.        nhttpswtab,            /* addtl numeric data 1: tbl size */
  7179.        4,                /* addtl numeric data 2: 4 = cmswi */
  7180.        xxstring,            /* Processing function */
  7181.        httpswtab,            /* Keyword table */
  7182.        &kw                /* Pointer to next FDB */
  7183.        );
  7184.     cmfdbi(&kw,                /* 2nd FDB - commands */
  7185.        _CMKEY,                /* fcode */
  7186.        "Command",            /* hlpmsg */
  7187.        "",                /* default */
  7188.        "",                /* addtl string data */
  7189.        nhttptab,            /* addtl numeric data 1: tbl size */
  7190.        0,                /* addtl numeric data 2: 0 = keyword */
  7191.        xxstring,            /* Processing function */
  7192.        httptab,                /* Keyword table */
  7193.        NULL                /* Pointer to next FDB */
  7194.        );
  7195.  
  7196.     while (1) {
  7197.     x = cmfdb(&sw);            /* Parse something */
  7198.     if (x < 0)            /* Error */
  7199.       goto xhttp;
  7200.     n = cmresult.nresult;
  7201.     if (cmresult.fdbaddr == &kw)    /* Command - exit this loop */
  7202.       break;
  7203.     c = cmgbrk();            /* Switch... */
  7204.     getval = (c == ':' || c == '=');
  7205.     x = -9;
  7206.     if (getval && !(cmgkwflgs() & CM_ARG)) {
  7207.         printf("?This switch does not take an argument\n");
  7208.         goto xhttp;
  7209.     }
  7210.     switch (cmresult.nresult) {    /* Handle each switch */
  7211.           case HT_SW_TP:                /* /TOSCREEN */
  7212.             http_type = 1;
  7213.             break;
  7214.       case HT_SW_AG:        /* /AGENT */
  7215.         if (getval) {
  7216.         if ((x = cmfld("User agent",p,&s,xxstring)) < 0)
  7217.           goto xhttp;
  7218.         } else {
  7219.         s = p;
  7220.         }
  7221.         makestr(&http_agent,s);
  7222.         break;
  7223.       case HT_SW_HD:        /* /HEADER */
  7224.         s = NULL;
  7225.         if (getval) {
  7226.         if ((x = cmfld("Header line","",&s,xxstring)) < 0) {
  7227.             if (x == -3)
  7228.               s = NULL;
  7229.             else
  7230.               goto xhttp;
  7231.         }
  7232.         }
  7233.         makestr(&http_hdr,s);
  7234.         break;
  7235.       case HT_SW_US:        /* /USER */
  7236.         s = NULL;
  7237.         if (getval) {
  7238.         if ((x = cmfld("User ID","",&s,xxstring)) < 0) {
  7239.                   if (x == -3)
  7240.                     s = "";
  7241.                   else
  7242.             goto xhttp;
  7243.                 }
  7244.         }
  7245.         makestr(&http_user,s);
  7246.         break;
  7247.       case HT_SW_PW:        /* /PASSWORD */
  7248.         debok = 0;
  7249.         s = NULL;
  7250.         if (getval) {
  7251.         if ((x = cmfld("Password","",&s,xxstring)) < 0)
  7252.           goto xhttp;
  7253.         }
  7254.         makestr(&http_pass,s);
  7255.         break;
  7256. #ifndef NOSPL
  7257.       case HT_SW_AR: {        /* /ARRAY: */
  7258.           char * s2, array = NUL;
  7259.           if (!getval) {
  7260.           printf("?This switch requires an argument\n");
  7261.           x = -9;
  7262.           goto xhttp;
  7263.           }
  7264.           if ((x = cmfld("Array name (a single letter will do)",
  7265.                  "",
  7266.                  &s,
  7267.                  NULL
  7268.                  )) < 0) {
  7269.           if (x == -3) {
  7270.               printf("?Array name required\n");
  7271.               x = -9;
  7272.               goto xhttp;
  7273.           } else
  7274.             goto xhttp;
  7275.           }
  7276.           if (!*s) {
  7277.           printf("?Array name required\n");
  7278.           x = -9;
  7279.           goto xhttp;
  7280.           }
  7281.           s2 = s;
  7282.           if (*s == CMDQ) s++;
  7283.           if (*s == '&') s++;
  7284.           if (!isalpha(*s)) {
  7285.           printf("?Bad array name - \"%s\"\n",s2);
  7286.           x = -9;
  7287.           goto xhttp;
  7288.           }
  7289.           array = *s++;
  7290.           if (isupper(array))
  7291.         array = tolower(array);
  7292.           if (*s && (*s != '[' || *(s+1) != ']')) {
  7293.           printf("?Bad array name - \"%s\"\n",s2);
  7294.           http_array = NUL;
  7295.           x = -9;
  7296.           goto xhttp;
  7297.           }
  7298.           http_array = array;
  7299.           break;
  7300.       }
  7301. #endif /* NOSPL */
  7302.       default:
  7303.         x = -2;
  7304.         goto xhttp;
  7305.     }
  7306.     }
  7307.     http_action = n;            /* Save the action */
  7308.     if (http_action == HTTP_PUT || http_action == HTTP_POS) {
  7309.     cmfdbi(&sw,            /* 1st FDB - switch */
  7310.            _CMKEY,            /* fcode */
  7311.            "Local filename\n Or switch", /* help */
  7312.            "",            /* default */
  7313.            "",            /* addtl string data */
  7314.            nhttpptab,        /* keyword table size */
  7315.            4,            /* addtl numeric data 2: 4 = cmswi */
  7316.            xxstring,        /* Processing function */
  7317.            httpptab,        /* Keyword table */
  7318.            &fi            /* Pointer to next FDB */
  7319.            );
  7320.     cmfdbi(&fi,            /* 2nd FDB - filename */
  7321.            _CMIFI,            /* fcode */
  7322.            "Local filename",    /* hlpmsg */
  7323.            "",            /* default */
  7324.            "",            /* addtl string data */
  7325.            0,            /* addtl numeric data 1 */
  7326.            0,            /* addtl numeric data 2 */
  7327.            xxstring,
  7328.            NULL,
  7329.            NULL
  7330.            );
  7331.     while (1) {
  7332.         x = cmfdb(&sw);
  7333.         if (x < 0)
  7334.           goto xhttp;        /* Free any malloc'd temp strings */
  7335.         n = cmresult.nresult;
  7336.         if (cmresult.fcode != _CMKEY)
  7337.           break;
  7338.         c = cmgbrk();        /* Switch... */
  7339.         getval = (c == ':' || c == '=');
  7340.         if (getval && !(cmgkwflgs() & CM_ARG)) {
  7341.         printf("?This switch does not take an argument\n");
  7342.         x = -9;
  7343.         goto xhttp;
  7344.         }
  7345.         switch (n) {
  7346.           case HT_PP_MT:
  7347.         s = "text/HTML";
  7348.         if (getval) {
  7349.             if ((x = cmfld("MIME type",
  7350.                    "text/HTML",&s,xxstring)) < 0)
  7351.               goto xhttp;
  7352.         }
  7353.         makestr(&http_mime,s);
  7354.         break;
  7355.           default:
  7356.         x = -2;
  7357.         goto xhttp;
  7358.         }
  7359.     }
  7360.     makestr(&http_lfile,cmresult.sresult);
  7361.     n = ckindex("/",http_lfile,-1,1,0);
  7362.     if (n)
  7363.       p = &http_lfile[n];
  7364.     else
  7365.       p = http_lfile;
  7366.     if ((x = cmfld("URL or remote filename",p,&s,xxstring)) < 0) {
  7367.           if (x == -3) {
  7368.             printf("?%s what?\n",(http_action == HTTP_PUT) ? "Put" : "Post");
  7369.             x = -9;
  7370.           }
  7371.           goto xhttp;
  7372.         }
  7373.     if (!*s) s = NULL;
  7374.     makestr(&http_rfile,s);
  7375.  
  7376.     if ((x = cmtxt("Response filename","",&s,xxstring)) < 0) {
  7377.           if (x != -3)
  7378.             goto xhttp;
  7379.         }
  7380.         if (*s)
  7381.           makestr(&http_dfile,s);
  7382.     }
  7383.     switch (http_action) {
  7384.       case HTTP_DEL:            /* DELETE */
  7385.     if ((x = cmfld("URL or remote source file","",&s,xxstring)) < 0) {
  7386.           if (x == -3) {
  7387.             printf("?Delete what?\n");
  7388.             x = -9;
  7389.           }
  7390.           goto xhttp;
  7391.         }
  7392.     makestr(&http_rfile,s);
  7393.     break;
  7394.       case HTTP_CON:            /* CONNECT */
  7395.         if ((x = cmfld("Remote host[:port]","",&s,xxstring)) < 0) {
  7396.           if (x == -3) {
  7397.             printf("?Remote host[:port] is required\n");
  7398.             x = -9;
  7399.           }
  7400.           goto xhttp;
  7401.         }
  7402.     makestr(&http_rfile,s);
  7403.     break;
  7404.       case HTTP_HED: {            /* HEAD */
  7405.       char buf[CKMAXPATH+1];
  7406.       if ((x = cmfld("URL or remote source file","",&s,xxstring)) < 0) {
  7407.           if (x == -3) {
  7408.           printf("?Head of what?\n");
  7409.           x = -9;
  7410.           }
  7411.           goto xhttp;
  7412.       }
  7413.       makestr(&http_rfile,s);
  7414.  
  7415.       if (http_array || http_type) { /* Default result filename */
  7416.           p = "";             /* None if /ARRAY or /TOSCREEN */
  7417.       } else {
  7418.           n = ckindex("/",http_rfile,-1,1,0); /* Otherwise strip path */
  7419.           if (n)                          /* and add ".head" */
  7420.         p = &http_rfile[n];
  7421.           else
  7422.         p = http_rfile;
  7423.           ckmakmsg(buf,CKMAXPATH,p,".head",NULL,NULL);
  7424.           p = buf;
  7425.       }
  7426.       if ((x = cmofi("Local filename",p,&s,xxstring)) < 0) {
  7427.           if (x != -3)
  7428.         goto xhttp;
  7429.       }
  7430.       makestr(&http_lfile,s);
  7431.       break;
  7432.       }
  7433.       case HTTP_GET:            /* GET */
  7434.       case HTTP_IDX: {            /* INDEX */
  7435.       extern int wildena;
  7436.       int tmp;
  7437.       char * lfile = "";
  7438.       if ((x = cmfld("URL or remote source file","",&s,xxstring)) < 0) {
  7439.           if (x == -3) {
  7440.           printf("?Get what?\n");
  7441.           x = -9;
  7442.           }
  7443.           goto xhttp;
  7444.       }
  7445.       makestr(&http_rfile,s);
  7446.       if (http_action == HTTP_GET && !http_type)
  7447.         zstrip(http_rfile,&lfile);
  7448.       /* URLs often contain question marks or other metacharacters */
  7449.       /* cmofi() doesn't like them */
  7450.       tmp = wildena;
  7451.       wildena = 0;
  7452.       if ((x = cmofi("Local filename",lfile,&s,xxstring)) < 0) {
  7453.           wildena = tmp;
  7454.           if (x != -3)
  7455.         goto xhttp;
  7456.       }
  7457.       wildena = tmp;
  7458.       makestr(&http_lfile,s);
  7459.       break;
  7460.       }
  7461.       case HTTP_OPN: {
  7462.       int sslswitch = 0;
  7463. #ifdef CK_SSL
  7464.       struct FDB sw, fl;
  7465.       cmfdbi(&sw,
  7466.          _CMKEY,        /* fcode */
  7467.          "IP host name or address, or switch", /* hlpmsg */
  7468.          "",            /* default */
  7469.          "",            /* addtl string data */
  7470.          2,            /* addtl numeric data 1: tbl size */
  7471.          4,            /* addtl numeric data 2: 4 = cmswi */
  7472.          xxstring,        /* Processing function */
  7473.          sslswtab,        /* Keyword table */
  7474.          &fl            /* Pointer to next FDB */
  7475.          );
  7476.       cmfdbi(&fl,            /* 2nd FDB - host */
  7477.          _CMFLD,        /* fcode */
  7478.          "",            /* hlpmsg */
  7479.          "",            /* default */
  7480.          "",            /* addtl string data */
  7481.          0,            /* addtl numeric data 1 */
  7482.          0,            /* addtl numeric data 2 */
  7483.          xxstring,
  7484.          NULL,
  7485.          NULL
  7486.          );
  7487.       x = cmfdb(&sw);        /* Parse switch or host */
  7488.       if (x < 0)            /* Error */
  7489.         goto xhttp;
  7490.       if (cmresult.fcode == _CMFLD) { /* Host */
  7491.           s = cmresult.sresult;      /* Set up expected pointer */
  7492.           goto havehost;              /* Go parse rest of command */
  7493.       }
  7494.       sslswitch = 1;        /* /SSL or /TLS switch - set flag */
  7495. #endif /* CK_SSL */
  7496.  
  7497.       /* Parse host */
  7498.  
  7499.       if ((x = cmfld("URL, hostname, or ip-address","",&s,xxstring)) < 0) {
  7500.           if (x == -3) {
  7501.           printf("?Open what?\n");
  7502.           x = -9;
  7503.           }
  7504.           goto xhttp;
  7505.       }
  7506.  
  7507.     havehost:            /* Come here with s -> host */
  7508. #ifdef CK_URL
  7509.       x = urlparse(s,&http_url);    /* Was a URL given? */
  7510.       if (x < 1) {            /* Not a URL */
  7511. #endif /* CK_URL */
  7512.           makestr(&http_host,s);
  7513.           if ((x =
  7514.            cmfld("Service name or port number",
  7515.              sslswitch ? "https" : "http",&s,xxstring)) < 0)
  7516.         goto xhttp;
  7517.           else
  7518.         makestr(&http_srv,s);
  7519. #ifdef CK_URL
  7520.       } else if (ckstrcmp(http_url.svc,"http",-1,0) && /* Non-HTTP URL */
  7521.              ckstrcmp(http_url.svc,"https",-1,0)) {
  7522.           printf("?Non-HTTP URL\n");
  7523.           x = -9;
  7524.           goto xhttp;
  7525.       } else {            /* Have HTTP URL */
  7526.           makestr(&http_srv, http_url.svc);
  7527.           makestr(&http_user,http_url.usr);
  7528.           makestr(&http_pass,http_url.psw);
  7529.           makestr(&http_host,http_url.hos);
  7530.           if (http_url.por)
  7531.         makestr(&http_srv,http_url.por);
  7532.           makestr(&http_rfile,http_url.pth);
  7533.       }
  7534.       if (http_rfile) {        /* Open, GET, and Close */
  7535.           printf("?Directory/file path not allowed in HTTP OPEN URL\n");
  7536.           x = -9;
  7537.           goto xhttp;
  7538.       }
  7539.       if (!ckstrcmp("https",http_srv,-1,0) || sslswitch ||
  7540.           !ckstrcmp("443",http_srv,-1,0))
  7541.         http_ssl = 1;
  7542. #endif /* CK_URL */
  7543.       break;
  7544.       }
  7545.       case HTTP_CLS:
  7546.         break;
  7547.     }
  7548.     if ((x = cmcfm()) < 0)
  7549.       goto xhttp;
  7550.  
  7551.     if (http_action == HTTP_OPN) {
  7552.         x = (http_open(http_host,http_srv,http_ssl,rdns,128,http_agent) == 0);
  7553.         if (x) {
  7554.             if (!quiet) {
  7555.               if (rdns[0])
  7556.                 printf("Connected to %s [%s]\r\n",http_host,rdns);
  7557.               else
  7558.                 printf("Connected to %s\r\n",http_host);
  7559.             }
  7560.             if (http_agent) {
  7561.                 if (http_d_agent)
  7562.           free(http_d_agent);
  7563.                 http_d_agent = http_agent;
  7564.                 http_agent = NULL;
  7565.             }
  7566.             if (http_user) {
  7567.                 if (http_d_user)
  7568.           free(http_d_user);
  7569.                 http_d_user = http_user;
  7570.                 http_user = NULL;
  7571.             }
  7572.             if (http_pass) {
  7573.                 if (http_d_pass) {
  7574.                     memset(http_d_pass,0,strlen(http_d_pass));
  7575.                     free(http_d_pass);
  7576.                 }
  7577.                 http_d_pass = http_pass;
  7578.                 http_pass = NULL;
  7579.             }
  7580.             http_d_type = http_type;
  7581.         } else {
  7582.             if (!quiet)
  7583.           printf("?HTTP Connection failed.\r\n");
  7584.         }
  7585.     } else if (http_action == HTTP_CLS) {
  7586.         if (http_d_agent) {
  7587.             free(http_d_agent);
  7588.             http_d_agent = NULL;
  7589.         }
  7590.         if (http_d_user) {
  7591.             free(http_d_user);
  7592.             http_d_user = NULL;
  7593.         }
  7594.         if (http_d_pass) {
  7595.             memset(http_d_pass,0,strlen(http_d_pass));
  7596.             free(http_d_pass);
  7597.             http_d_pass = NULL;
  7598.         }
  7599.         http_d_type = 0;
  7600.         x = (http_close() == 0);
  7601.     }
  7602.     if ((http_action != HTTP_CLS) &&
  7603.     (http_action != HTTP_CON) && http_rfile) { /* Remote file is URL? */
  7604.  
  7605.     /* All-in-one actions when a URL is given... */
  7606.  
  7607. #ifdef CK_URL
  7608.     if (urlparse(http_rfile,&http_url) > 0) { /* Have URL? */
  7609.         if (ckstrcmp(http_url.svc,"http",-1,0) && /* It's an HTTP URL? */
  7610.         ckstrcmp(http_url.svc,"https",-1,0)) {
  7611.         printf("?Non-HTTP URL\n");
  7612.         x = -9;
  7613.         goto xhttp;
  7614.         } else {            /* Yes, collect the pieces */
  7615.         makestr(&http_srv, http_url.svc);
  7616.         makestr(&http_user,http_url.usr);
  7617.         makestr(&http_pass,http_url.psw);
  7618.         makestr(&http_host,http_url.hos);
  7619.         if (http_url.por)
  7620.           makestr(&http_srv,http_url.por);
  7621.         makestr(&http_rfile,http_url.pth);
  7622.         }
  7623.         if (!http_rfile) {        /* Still have a path? */
  7624.                 makestr(&http_rfile,"/");
  7625.         }
  7626.         if (!ckstrcmp("https",http_srv,-1,0) || /* Check for SSL/TLS */
  7627.         !ckstrcmp("443",http_srv,-1,0))
  7628.           http_ssl = 1;
  7629.         if (http_isconnected())    /* Close any open HTTP connection */
  7630.           http_close();
  7631.         if (http_pass == NULL && http_d_pass != NULL)
  7632.           makestr(&http_pass,http_d_pass);
  7633.         x = (http_open(http_host,
  7634.                http_srv,http_ssl,rdns,128,http_d_agent) == 0);
  7635.         if (x < 0) {
  7636.         x = 0;
  7637.         goto xhttp;
  7638.         }
  7639.         allinone = 1;
  7640.     }
  7641. #endif /* CK_URL */
  7642.         if (http_pass == NULL && http_d_pass != NULL)
  7643.       makestr(&http_pass,http_d_pass);
  7644.  
  7645.     if (http_action == HTTP_OPN && allinone) {
  7646.         http_action = HTTP_GET;
  7647.     }
  7648.         x = xdohttp(http_action,
  7649.                     http_lfile,
  7650.             http_rfile,
  7651.                     http_dfile,
  7652.             http_agent ? http_agent : http_d_agent,
  7653.             http_hdr,
  7654.             http_user  ? http_user  : http_d_user,
  7655.             http_pass  ? http_pass  : http_d_pass,
  7656.             http_mime,
  7657.             http_array,
  7658.             http_type
  7659.             );
  7660.     if (allinone)
  7661.       x = (http_close() == 0);
  7662.     }
  7663.  
  7664.   xhttp:
  7665.     if (http_agent) free(http_agent);
  7666.     if (http_hdr)   free(http_hdr);
  7667.     if (http_user)  free(http_user);
  7668.     if (http_pass) {
  7669.         memset(http_pass,0,strlen(http_pass));
  7670.         free(http_pass);
  7671.     }
  7672.     if (http_mime)  free(http_mime);
  7673.     if (http_lfile) free(http_lfile);
  7674.     if (http_rfile) free(http_rfile);
  7675.     if (http_dfile) free(http_dfile);
  7676.     if (http_host)  free(http_host);
  7677.     if (http_srv)   free(http_srv);
  7678.  
  7679.     if (x > -1)
  7680.       success = x;
  7681.     return(x);
  7682. }
  7683. #endif /* TCPSOCKET */
  7684. #endif /* NOHTTP */
  7685.  
  7686.  
  7687. #ifndef NOSPL
  7688. static int
  7689. dotrace() {
  7690.     int on = 1;
  7691.     struct FDB sw, kw;
  7692.     cmfdbi(&sw,                /* 1st FDB - switch */
  7693.        _CMKEY,            /* fcode */
  7694.        "Trace object;\n Or switch", /* help */
  7695.        "",                /* default */
  7696.        "",                /* addtl string data */
  7697.        2,                /* keyword table size */
  7698.        4,                /* addtl numeric data 2: 4 = cmswi */
  7699.        xxstring,            /* Processing function */
  7700.        onoffsw,            /* Keyword table */
  7701.        &kw                /* Pointer to next FDB */
  7702.        );
  7703.     cmfdbi(&kw,                /* 2nd FDB - Trace object */
  7704.        _CMKEY,            /* fcode */
  7705.        "Trace object",        /* help */
  7706.        "all",            /* default */
  7707.        "",                /* addtl string data */
  7708.        ntracetab,            /* keyword table size */
  7709.        0,                /* addtl numeric data 2: 0 = keyword */
  7710.        xxstring,            /* Processing function */
  7711.        tracetab,            /* Keyword table */
  7712.        NULL                /* Pointer to next FDB */
  7713.        );
  7714.     if ((x = cmfdb(&sw)) < 0)
  7715.       return(x);
  7716.     if (cmresult.fdbaddr == &sw) {
  7717.     on = cmresult.nresult;
  7718.     if ((x = cmkey(tracetab, ntracetab,"","all",xxstring)) < 0)
  7719.       return(x);
  7720.     } else {
  7721.     x = cmresult.nresult;
  7722.     }
  7723.     if ((y = cmcfm()) < 0)
  7724.       return(y);
  7725.  
  7726.     switch (x) {
  7727.       case TRA_ASG:
  7728.     tra_asg = on;
  7729.     break;
  7730.       case TRA_CMD:
  7731.     tra_cmd = on;
  7732.     break;
  7733.       case TRA_ALL:
  7734.     tra_asg = on;
  7735.     tra_cmd = on;
  7736.     break;
  7737.       default:
  7738.     return(-2);
  7739.     }
  7740.     printf("TRACE %s\n", on ? "ON" : "OFF");
  7741.     return(success = 1);
  7742. }
  7743. #endif /* NOSPL */
  7744.  
  7745.  
  7746. static int
  7747. doprompt() {
  7748.     extern int xcmdsrc;
  7749.     if ((x = cmtxt("Optional message","",&s,xxstring)) < 0)
  7750.       return(x);
  7751. #ifdef NOSPL
  7752.     printf("?Sorry, PROMPT requires script programming language\n");
  7753.     return(-9);
  7754. #else
  7755.     debug(F101,"Prompt cmdlvl","",cmdlvl);
  7756.     cmdlvl++;
  7757.     if (cmdlvl > CMDSTKL) {
  7758.     printf("?Command stack overflow: %d\n",cmdlvl);
  7759.     cmdlvl--;
  7760.     return(-9);
  7761.     }
  7762.     xcmdsrc = CMD_KB;
  7763.     cmdstk[cmdlvl].src = CMD_KB;    /* Say we're at the prompt */
  7764.     cmdstk[cmdlvl].lvl = 0;
  7765.     cmdstk[cmdlvl].ccflgs = cmdstk[cmdlvl-1].ccflgs;
  7766.     if (tra_cmd)
  7767.       printf("[%d] +P: \"(prompt)\"\n",cmdlvl);
  7768.     concb((char)escape);
  7769.     if (!quiet)
  7770.       printf(
  7771. "(Recursive command prompt: Resume script with CONTINUE, STOP to stop...)\n"
  7772.             );
  7773.     if (*s) {                /* If prompt given */
  7774.     makestr(&(prstring[cmdlvl-1]),cmgetp()); /* Save current prompt */
  7775.     cmsetp(s);            /* Set new one */
  7776.     }
  7777.     return(success = 1);
  7778. #endif /* NOSPL */
  7779. }
  7780.  
  7781. #ifdef CKLEARN
  7782. VOID
  7783. learncmd(s) char *s; {            /* Record commands in learned script */
  7784.     char buf[64];
  7785.     int i, k;
  7786.     if (learnfp && learning) {        /* Only if open and on */
  7787.     k = ckstrncpy(buf,s,64);
  7788.     for (i = 0; i < k; i++) {    /* Get top-level command keyword */
  7789.         if (buf[i] <= SP) {
  7790.         buf[i] = NUL;
  7791.         break;
  7792.         }
  7793.     }
  7794.     k = lookup(cmdtab,buf,ncmd,NULL); /* Look it up */
  7795.     if (k == XXCON || k == XXLEARN)      /* Don't record CONNECT or LEARN */
  7796.       return;
  7797.     if (k == XXTEL) {
  7798.         fputs("SET HOST /NETWORK:TCP",learnfp);
  7799.         fputs(&s[i],learnfp);
  7800.         fputs(" TELNET /TELNET",learnfp);
  7801.         fputs("\nIF FAIL STOP 1 Connection failed\n",learnfp);
  7802.     } else {
  7803.         fputs(s,learnfp);
  7804.         fputs("\n",learnfp);
  7805.     }
  7806.     }
  7807. }
  7808. #endif /* CKLEARN */
  7809.  
  7810.  
  7811. #ifdef SSHCMD
  7812. /*
  7813.   2010/03/01...
  7814.   Reopen a connection that was made with an external ssh client
  7815.   after it has been closed.
  7816.  */
  7817. int
  7818. redossh() {
  7819.     int x, netsave;
  7820.     x = nettype;
  7821.     debug(F111,"redossh nettype",ttname,nettype);
  7822.     if ((y = setlin(XXSSH,0,1)) < 0) {
  7823.     if (errno)
  7824.       printf("?%s\n",ck_errstr());
  7825.     else
  7826.       return(y);
  7827.     nettype = x;            /* Failed, restore net type. */
  7828.     success = 0;
  7829.     return(y);
  7830.     }
  7831.     netsave = x;
  7832.     return(y);
  7833. }
  7834. #endif    /* SSHCMD */
  7835.  
  7836. /*  D O C M D  --  Do a command  */
  7837.  
  7838. /*
  7839.  Returns:
  7840.    -2: user typed an illegal command
  7841.    -1: reparse needed
  7842.     0: parse was successful (even tho command may have failed).
  7843. */
  7844. #ifdef DEBUG
  7845. int cmdstats[256] = { -1, -1 };
  7846. #endif /* DEBUG */
  7847.  
  7848. int
  7849. docmd(cx) int cx; {
  7850.     extern int nolocal, cmkwflgs;
  7851.  
  7852.     debug(F101,"docmd entry, cx","",cx);
  7853.     activecmd = cx;
  7854.     doconx = ((activecmd == XXCON)  || (activecmd == XXTEL) ||
  7855.           (activecmd == XXRLOG) || (activecmd == XXPIPE) ||
  7856.               (activecmd == XXIKSD) || (activecmd == XXPTY));
  7857. /*
  7858.   Originally all commands were handled with a big switch() statement,
  7859.   but eventually this started blowing up compilers.  Now we have a series
  7860.   of separate if statements and small switches, with the commands that are
  7861.   most commonly executed in scipts and loops coming first, to speed up
  7862.   compute-bound scripts.
  7863.   */
  7864.  
  7865. #ifdef DEBUG
  7866.     if (cmdstats[0] == -1) {        /* Count commands */
  7867.     int i;                /* for tuning... */
  7868.     for (i = 0; i < 256; i++)
  7869.       cmdstats[i] = 0;
  7870.     }
  7871. #endif /* DEBUG */
  7872.  
  7873.     switch (cx) {
  7874.       case -4:                /* EOF */
  7875. #ifdef OSK
  7876.     if (msgflg)  printf("\n");
  7877. #else
  7878.     if (msgflg)  printf("\r\n");
  7879. #endif /* OSK */
  7880.       doexit(GOOD_EXIT,xitsta);
  7881.       case -3:                /* Null command */
  7882.     return(0);
  7883.       case -9:                /* Like -2, but errmsg already done */
  7884.       case -1:                /* Reparse needed */
  7885.     return(cx);
  7886.       case -6:                /* Special */
  7887.       case -2:                /* Error, maybe */
  7888.  
  7889. #ifndef NOSPL
  7890. /*
  7891.   Maybe they typed a macro name.  Let's look it up and see.
  7892. */
  7893.     if (cx == -6)            /* If they typed CR */
  7894.       ckstrncat(cmdbuf,"\015",CMDBL); /*  add it back to command buffer. */
  7895.     if (ifcmd[cmdlvl] == 2)        /* Watch out for IF commands. */
  7896.       ifcmd[cmdlvl]--;
  7897.     repars = 1;            /* Force reparse */
  7898.     cmres();
  7899.     cx = XXDO;            /* Try DO command */
  7900. #else
  7901.     return(cx);
  7902. #endif /* NOSPL */
  7903.       default:
  7904.     if (cx < 0)
  7905.       return(cx);
  7906.     break;
  7907.     }
  7908. #ifdef DEBUG
  7909.     if (cx < 256)
  7910.       cmdstats[cx]++;
  7911. #endif /* DEBUG */
  7912.  
  7913.     if ((cmkwflgs & CM_PSH)
  7914. #ifndef NOPUSH
  7915.     && nopush
  7916. #endif /* NOPUSH */
  7917.     ) {
  7918.     printf("?Access to system disabled\n");
  7919.     return(-9);
  7920.     }
  7921.     if ((cmkwflgs & CM_LOC)
  7922. #ifndef NOLOCAL
  7923.     && nolocal
  7924. #endif /* NOLOCAL */
  7925.     ) {
  7926.     printf("?Connections disabled\n");
  7927.     return(-9);
  7928.     }
  7929.  
  7930. #ifndef NOSPL
  7931.     /* Used in FOR loops */
  7932.  
  7933.     if (cx == XX_INCR || cx == XXINC  || /* _INCREMENT, INCREMENT */
  7934.     cx == XX_DECR || cx == XXDEC)     /* _DECREMENT, DECREMENT */
  7935.       return(doincr(cx));
  7936.  
  7937.     /* Define (or change the definition of) a macro or variable */
  7938.  
  7939.     if (cx == XXUNDEF || cx == XXUNDFX) {
  7940. #ifdef IKSD
  7941.     if (inserver && !ENABLED(en_asg)) {
  7942.         printf("?Sorry, DEFINE/ASSIGN disabled\n");
  7943.         return(-9);
  7944.     }
  7945. #endif /* IKSD */
  7946.     return(doundef(cx));        /* [_]UNDEFINE */
  7947.     }
  7948.     if (cx == XXDEF || cx == XXASS ||
  7949.     cx == XXDFX || cx == XXASX) {
  7950. #ifdef IKSD
  7951.     if (inserver && !ENABLED(en_asg)) {
  7952.         printf("?Sorry, DEFINE/ASSIGN disabled\n");
  7953.         return(-9);
  7954.     }
  7955. #endif /* IKSD */
  7956.     if (atmbuf[0] == '.' && !atmbuf[1]) /* "." entered as keyword */
  7957.       xxdot = 1;            /* i.e. with space after it... */
  7958.     return(dodef(cx));        /* DEFINE, ASSIGN, etc... */
  7959.     }
  7960.  
  7961.     /* IF, WHILE, and friends  */
  7962.  
  7963.     if (cx == XXIF || cx == XXIFX || cx == XXWHI || cx == XXASSER) {
  7964.     return(doif(cx));
  7965.     }
  7966.     if (cx == XXSWIT) {            /* SWITCH */
  7967.     return(doswitch());
  7968.     }
  7969.  
  7970.     /* GOTO, FORWARD, and _FORWARD (used internally by FOR, WHILE, etc) */
  7971.  
  7972.     if (cx == XXGOTO || cx == XXFWD || cx == XXXFWD) { /* GOTO or FORWARD */
  7973.     /* Note, here we don't set SUCCESS/FAILURE flag */
  7974. #ifdef COMMENT
  7975.     if ((y = cmfld("label","",&s,xxstring)) < 0) {
  7976.         if (y == -3) {
  7977.         if (cx != XXXFWD) {
  7978.             printf("?Label name required\n");
  7979.             return(-9);
  7980.         }
  7981.         } else
  7982.           return(y);
  7983.     }
  7984.     ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  7985.     if ((x = cmcfm()) < 0) return(x);
  7986. #else
  7987.     if ((y = cmtxt("label","",&s,xxstring)) < 0) {
  7988.         if (y == -3) {
  7989.         if (cx != XXXFWD) {
  7990.             printf("?GOTO: Label name required: \"%s\" \"%s\"\n",
  7991.                atmbuf,
  7992.                cmdbuf);
  7993.             return(-9);
  7994.         }
  7995.         } else
  7996.           return(y);
  7997.     }
  7998.     ckstrncpy(tmpbuf,brstrip(s),TMPBUFSIZ);
  7999. #endif /* COMMENT */
  8000.     s = tmpbuf;
  8001.     debug(F111,"GOTO target",s,cx);
  8002.     return(dogoto(s,cx));
  8003.     }
  8004.     if (cx == XXDO || cx == XXMACRO) {    /* DO (a macro) */
  8005.     char mnamebuf[16];        /* (buffer for controlled temp name) */
  8006.     struct FDB kw, fl;
  8007.     int mx;                /* Macro index (on stack!) */
  8008.  
  8009.     debug(F101,"XXMACRO 0",line,cx);
  8010.     if (cx == XXDO) {
  8011.         if (nmac == 0) {
  8012.         printf("\n?No macros defined\n");
  8013.         return(-9);
  8014.         }
  8015.         for (y = 0; y < nmac; y++) { /* copy the macro table into a */
  8016.         mackey[y].kwd = mactab[y].kwd; /* regular keyword table */
  8017.         mackey[y].kwval = y;    /* with value = pointer to macro tbl */
  8018.         mackey[y].flgs = mactab[y].flgs;
  8019.         }
  8020.         cmfdbi(&kw,            /* First FDB - macro name */
  8021.            _CMKEY,        /* fcode */
  8022.            "Macro",        /* hlpmsg */
  8023.            "",            /* default */
  8024.            "",            /* addtl string data */
  8025.            nmac,        /* addtl numeric data 1: tbl size */
  8026.            0,            /* addtl numeric data 2: 0 = cmkey */
  8027.            xxstring,        /* Processing function */
  8028.            mackey,        /* Keyword table */
  8029.            &fl            /* Pointer to next FDB */
  8030.            );
  8031.         cmfdbi(&fl,            /* 2nd FDB - for "{" */
  8032.            _CMFLD,        /* fcode */
  8033.            "",            /* hlpmsg */
  8034.            "",
  8035.            "",            /* addtl string data */
  8036.            0,            /* addtl numeric data 1 */
  8037.            0,            /* addtl numeric data 2 */
  8038.            xxstring,
  8039.            NULL,
  8040.            NULL
  8041.            );
  8042.         x = cmfdb(&kw);        /* Parse something */
  8043.         if (x < 0) {        /* Error */
  8044.         if (x == -3) {
  8045.             printf("?Macro name required\n");
  8046.             return(-9);
  8047.         } else
  8048.           return(x);
  8049.         }
  8050.         if (cmresult.fcode == _CMKEY) {
  8051.         extern int mtchanged;
  8052.         char * macroname = NULL;
  8053.  
  8054.         /* In case args include an \fexec() that changes the macro table */
  8055.  
  8056.         mx = x;            /* Save macro index on stack */
  8057.         mtchanged = 0;        /* Mark state of macro table */
  8058.         makestr(¯oname,mactab[mx].kwd); /* Save name */
  8059.  
  8060.         if ((y = cmtxt("optional arguments","",&s,xxstring)) < 0)
  8061.           return(y);        /* Get macro args */
  8062.  
  8063.         if (mtchanged) {    /* Macro table changed? */
  8064.             mx = mlook(mactab,macroname,nmac); /* Look up name again */
  8065.         }
  8066.         if (macroname)
  8067.           free(macroname);
  8068.  
  8069.         return(dodo(mx,s,cmdstk[cmdlvl].ccflgs) < 1 ?
  8070.                (success = 0) : 1);
  8071.         }
  8072.         ckstrncpy(line,cmresult.sresult,LINBUFSIZ);    /* _CMFLD */
  8073.         if (atmbuf[0] == '{') {
  8074.         if ((y = cmcfm()) < 0)
  8075.           return(y);
  8076.         }
  8077.     } else {            /* XXMACRO ("immediate macro") */
  8078.         int k = 0;
  8079.         line[k++] = '{';
  8080.         line[k++] = SP;
  8081.         line[k] = NUL;
  8082.         debug(F111,"XXMACRO A",line,k);
  8083.         if ((y = cmtxt("Braced list of commands","",&s,xxstring)) < 0)
  8084.           return(y);
  8085.         k = ckstrncpy(line+k,s,LINBUFSIZ-k);
  8086.         debug(F111,"XXMACRO B",line,k);
  8087.     }
  8088.     x = strlen(line);
  8089.     if ((line[0] == '{' && line[x-1] != '}') || line[0] == '}')
  8090.       return(-2);
  8091.     if (line[0] != '{' && line[x-1] != '}') {
  8092.         /* Unknown command.  If ON_UNKNOWN_COMMAND macro is defined, */
  8093.         /* parse args and then execute it, but only if it is not */
  8094.         /* already active. */
  8095.         int k = -1;
  8096.         if (!unkmacro) {
  8097.         k = mxlook(mactab,"on_unknown_command",nmac);
  8098.         }
  8099.         if (k > -1) {
  8100.         ckstrncpy(tmpbuf,atmbuf,TMPBUFSIZ);
  8101.         z = maclvl;        /* Save the current maclvl */
  8102.         if ((y = cmtxt("text","",&s,xxstring)) < 0)
  8103.           return(y);
  8104.         ckstrncat(tmpbuf," ",TMPBUFSIZ);
  8105.         ckstrncat(tmpbuf,s,TMPBUFSIZ);
  8106.         unkmacro = 1;
  8107.         debug(F110,"ON_UNKNOWN_COMMAND",s,0);
  8108.         dodo(k,tmpbuf,cmdstk[cmdlvl].ccflgs); /* Run the macro */
  8109.         while (maclvl > z) {
  8110.             sstate = (CHAR) parser(1);
  8111.             if (sstate) proto();
  8112.         }
  8113.         debug(F101,"UNKMAC loop exit maclvl","",maclvl);
  8114.         unkmacro = 0;
  8115.         return(success);
  8116.         }
  8117.             if (x > 0)
  8118.           printf("?Not a command or macro name: \"%s\"\n",line);
  8119.             else
  8120.           printf("?Not a command or macro name.\n");
  8121.         return(-9);
  8122.     }
  8123.     s = brstrip(line);
  8124.     sprintf(mnamebuf," ..tmp:%03d",cmdlvl);    /* safe (16) */
  8125.     x = addmac(mnamebuf,s);
  8126.     return(dodo(x,NULL,cmdstk[cmdlvl].ccflgs) < 1 ? (success = 0) : 1);
  8127.     }
  8128.  
  8129.     if (cx == XXLBL) {            /* LABEL */
  8130.     if ((x = cmfld("label","",&s,xxstring)) < 0) {
  8131.         if (x == -3) {
  8132. #ifdef COMMENT
  8133.         printf("?LABEL: Label name required: \"%s\"\n", cmdbuf);
  8134.         return(-9);
  8135. #else
  8136.         s = "";
  8137. #endif /* COMMENT */
  8138.         } else return(x);
  8139.  
  8140.     }
  8141.     debug(F111,"LABEL",s,x);
  8142.     if ((x = cmcfm()) < 0) return(x);
  8143.     return(0);
  8144.     }
  8145.  
  8146.     if (cx == XXEVAL || cx == XX_EVAL) /* _EVALUATE,  EVALUATE  */
  8147.       return(doeval(cx));
  8148.  
  8149. #ifndef NOSEXP
  8150.     if (cx == XXSEXP) {            /* Lisp-like S-Expression */
  8151.     struct stringarray * q;
  8152.     char /* *p, *r, */ *tmp, *m;
  8153.     int i, k, n, quote = 0, contd = 0, size = 0, len = 0;
  8154.     extern int sexprc, sexppv;
  8155.  
  8156.     tmp = tmpbuf;            /* Buffer to collect SEXP */
  8157.     tmpbuf[0] = NUL;        /* Clear it */
  8158.     size = TMPBUFSIZ;        /* Capacity of buffer */
  8159.     sexprc = -1;            /* Assume bad input */
  8160.     n = 0;                /* Paren balance counter */
  8161.  
  8162.     while (1) {            /* Allow SEXP on multiple lines */
  8163.         m = contd ?
  8164.           "Continuation of S-Expression" :
  8165.         "S-Expression (\"help sexp\" for details)";
  8166.         x = cmtxt(m,"",&s,xxstring);
  8167.         if (x < 0)
  8168.           return(x);
  8169.         if (!*s)            /* Needed for (=) and (:) */
  8170.           s = cmdbuf+1;        /* I can't explain why. */
  8171.         k = ckmakmsg(tmp, size, contd ? " " : "(", s, NULL, NULL);
  8172.         if (k < 1) {
  8173.         printf("?SEXP too long - %d max\n",TMPBUFSIZ);
  8174.         return(-9);
  8175.         }
  8176.         debug(F111,contd ? "sexp contd" : "sexp",s,k);
  8177.  
  8178.         for (i = len; i < len+k; i++) { /* Check balance  */
  8179.         if (!quote && tmpbuf[i] == CMDQ) {
  8180.             quote = 1;
  8181.             continue;
  8182.         }
  8183.         if (quote) {
  8184.             quote = 0;
  8185.             continue;
  8186.         }
  8187.         if (tmpbuf[i] == '(')
  8188.           n++;
  8189.         else if (tmpbuf[i] == ')')
  8190.           n--;
  8191.         }
  8192.         if (n == 0) {        /* Break when balanced */
  8193.         break;
  8194.         }
  8195.         if (n < 0) {        /* Too many right parens */
  8196.         printf("?Unbalanced S-Expression: \"%s\"\n",tmpbuf);
  8197.         return(-9);
  8198.         }
  8199.         contd++;            /* Need more right parens */
  8200.         cmini(ckxech);        /* so keep parsing */
  8201.         tmp += k;            /* adjust buffer pointer */
  8202.         size -= k;            /* and capacity */
  8203.         len += k;            /* and length so far */
  8204.     }
  8205.     s = tmpbuf;
  8206.     makestr(&lastsexp,s);
  8207.     q = cksplit(1,SEXPMAX,s,NULL,NULL,8,0,0); /* Precheck for > 1 SEXP */
  8208.     debug(F101,"sexp split","",q->a_size);
  8209.  
  8210.     if (q->a_size == 1) {        /* We should get exactly one back */
  8211.         char * result, * dosexp();
  8212.         sexprc = 0;            /* Reset out-of-band return code */
  8213.         result = dosexp(s);        /* Get result */
  8214.         debug(F111,"sexp result",result,sexprc);
  8215.         if (sexprc == 0) {        /* Success */
  8216.         /* Echo the result if desired */
  8217.         if ((!xcmdsrc && sexpecho != SET_OFF) || sexpecho == SET_ON)
  8218.           printf(" %s\n",result ? result : "");
  8219.         makestr(&sexpval,result);
  8220.         success = sexppv > -1 ? sexppv : 1;
  8221.         return(success);
  8222.         }
  8223.     }
  8224.     if (sexprc < 0)
  8225.       printf("?Invalid S-Expression: \"%s\"\n",lastsexp);
  8226.     return(-9);
  8227.     }
  8228. #endif /* NOSEXP */
  8229.  
  8230. #endif /* NOSPL */
  8231.  
  8232.     if (cx == XXECH || cx == XXXECH || cx == XXVOID
  8233. #ifndef NOSPL
  8234.     || cx == XXAPC
  8235. #endif /* NOSPL */
  8236.     ) {                /* ECHO or APC */
  8237.     if ((x = cmtxt((cx == XXECH || cx == XXXECH) ?
  8238.                "Text to be echoed" :
  8239.                ((cx == XXVOID) ? "Text" :
  8240.             "Application Program Command text"),
  8241.                "",
  8242.                &s,
  8243.                xxstring
  8244.                )
  8245.          ) < 0)
  8246.       return(x);
  8247.     if (!s) s = "";
  8248. #ifdef COMMENT
  8249. /* This is to preserve the pre-8.0 behavior but it's too confusing */
  8250.     x = strlen(s);
  8251.     x = (x > 1) ? ((s[0] == '"' && s[x-1] == '"') ? 1 : 0) : 0;
  8252. #endif /* COMMENT */
  8253.     s = brstrip(s);            /* Strip braces and doublequotes */
  8254.     if (cx == XXECH) {        /* ECHO */
  8255. #ifndef NOSPL
  8256.         if (!fndiags || fnsuccess) {
  8257. #endif /* NOSPL */
  8258. #ifdef COMMENT
  8259.         /* The "if (x)" business preserves previous behavior */
  8260.         /* by putting back the doublequotes if they were included. */
  8261.         if (x)
  8262.           printf("\"%s\"\n",s);
  8263.         else
  8264. #endif /* COMMENT */
  8265.           printf("%s\n",s);
  8266. #ifndef NOSPL
  8267.         }
  8268. #endif /* NOSPL */
  8269.     } else if (cx == XXXECH) {    /* XECHO */
  8270.         if (x)
  8271.           printf("\"%s\"",s);
  8272.         else
  8273.           printf("%s",s);
  8274. #ifdef UNIX
  8275.         fflush(stdout);
  8276. #endif /* UNIX */
  8277.     } else if (cx == XXAPC) {    /* APC */
  8278. #ifdef CK_APC
  8279.         if (apcactive == APC_LOCAL ||
  8280.         (apcactive == APC_REMOTE && !(apcstatus & APC_UNCH)))
  8281.           return(success = 0);
  8282. #endif /* CK_APC */
  8283.         if (!local) {
  8284.         printf("%c_%s%c\\",ESC,s,ESC);
  8285. #ifdef UNIX
  8286.         fflush(stdout);
  8287. #endif /* UNIX */
  8288.  
  8289.         } else {            /* Local mode - have connection */
  8290. #ifndef NOSPL
  8291.         if (ckmakxmsg(tmpbuf,    /* Form APC string in buffer */
  8292.                   TMPBUFSIZ,
  8293.                   ckctoa((char)ESC),
  8294.                   ckctoa('_'),
  8295.                   s,
  8296.                   ckctoa((char)ESC),
  8297.                   ckctoa('\\'),
  8298.                   NULL,NULL,NULL,NULL,NULL,NULL,NULL
  8299.                   ) > 0)
  8300.           return(success = dooutput(tmpbuf, XXOUT));
  8301.         printf("?Too long\n");
  8302.         return(-9);
  8303. #else
  8304.         printf("%c_%s%c\\",ESC,s,ESC);
  8305. #endif /* NOSPL */
  8306.         }
  8307.     }
  8308.     return(success = 1);
  8309.     }
  8310.  
  8311. #ifndef NOSPL
  8312. /* Copy macro args from/to two levels up, used internally by _floop et al. */
  8313.     if (cx == XXGTA || cx == XXPTA) {    /* _GETARGS, _PUTARGS */
  8314.     int x;
  8315.     debug(F101,"docmd XXGTA","",XXGTA);
  8316.     debug(F101,"docmd cx","",cx);
  8317.     debug(F101,"docmd XXGTA maclvl","",maclvl);
  8318.     x = dogta(cx);
  8319.     debug(F101,"docmd dogta returns","",x);
  8320.     debug(F101,"docmd dogta maclvl","",maclvl);
  8321.     return(x);
  8322.     }
  8323. #endif /* NOSPL */
  8324.  
  8325. #ifndef NOSPL
  8326. #ifdef CKCHANNELIO
  8327.     if (cx == XXFILE)
  8328.       return(dofile(cx));
  8329.     else if (cx == XXF_RE || cx == XXF_WR || cx == XXF_OP ||
  8330.          cx == XXF_CL || cx == XXF_SE || cx == XXF_RW ||
  8331.          cx == XXF_FL || cx == XXF_LI || cx == XXF_ST || cx == XXF_CO)
  8332.       return(dofile(cx));
  8333. #endif /* CKCHANNELIO */
  8334.  
  8335. /* ASK, ASKQ, READ */
  8336.     if (cx == XXASK  || cx == XXASKQ || cx == XXREA ||
  8337.     cx == XXRDBL || cx == XXGETC || cx == XXGETK) {
  8338.     return(doask(cx));
  8339.     }
  8340. #endif /* NOSPL */
  8341.  
  8342. #ifndef NOFRILLS
  8343.     if (cx == XXBUG) {            /* BUG */
  8344.     if ((x = cmcfm()) < 0) return(x);
  8345.     return(dobug());
  8346.     }
  8347. #endif /* NOFRILLS */
  8348.  
  8349. #ifndef NOXFER
  8350.     if (cx == XXBYE) {            /* BYE */
  8351.     extern int ftp_cmdlin;
  8352.     if ((x = cmcfm()) < 0) return(x);
  8353.  
  8354. #ifdef NEWFTP
  8355.     if ((ftpget == 1) || ((ftpget == 2) && ftpisopen())) {
  8356.         extern int stayflg, ftp_fai;
  8357.         success = ftpbye();
  8358.         if (ftp_cmdlin && !stayflg && !local)
  8359.           doexit(ftp_fai ? BAD_EXIT : GOOD_EXIT,-1);
  8360.         else
  8361.           return(success);
  8362.     }
  8363. #endif /* NEWFTP */
  8364.  
  8365.     if (!local) {
  8366.         printf("?No connection - use EXIT to quit.\n");
  8367.         return(-9);
  8368.     }
  8369.  
  8370. #ifdef CK_XYZ
  8371.     if (protocol != PROTO_K) {
  8372.         printf("?Sorry, BYE only works with Kermit protocol\n");
  8373.         return(-9);
  8374.     }
  8375. #endif /* CK_XYZ */
  8376.  
  8377. #ifdef IKS_OPTION
  8378.         if (
  8379. #ifdef CK_XYZ
  8380.             protocol == PROTO_K &&
  8381. #endif /* CK_XYZ */
  8382.             !iks_wait(KERMIT_REQ_START,1)) {
  8383.         printf(
  8384.          "?A Kermit Server is not available to process this command\n");
  8385.         return(-9);            /* Correct the return code */
  8386.         }
  8387. #endif /* IKS_OPTION */
  8388.  
  8389.     bye_active = 1;
  8390.     sstate = setgen('L',"","","");
  8391.     if (local) ttflui();        /* If local, flush tty input buffer */
  8392.     return(0);
  8393.     }
  8394. #endif /* NOXFER */
  8395.  
  8396.     if (cx == XXBEEP) {            /* BEEP */
  8397.         int x;
  8398. #ifdef OS2
  8399.     int y;
  8400.         if ((y = cmkey(beeptab, nbeeptab, "which kind of beep", "information",
  8401.                xxstring)) < 0 )
  8402.       return (y);
  8403.         if ((x = cmcfm()) < 0) return(x);
  8404.         bleep((short)y);        /* y is one of the BP_ values */
  8405. #else  /* OS2 */
  8406.         if ((x = cmcfm()) < 0) return(x);
  8407. #ifndef NOSPL
  8408.         bleep(BP_NOTE);
  8409. #else
  8410.     putchar('\07');
  8411. #endif /* NOSPL */
  8412. #endif /* OS2 */
  8413.         return(0);
  8414.     }
  8415.  
  8416. #ifndef NOFRILLS
  8417.     if (cx == XXCLE)            /* CLEAR */
  8418.       return(success = doclear());
  8419. #endif /* NOFRILLS */
  8420.  
  8421.     if (cx == XXCOM) {            /* COMMENT */
  8422.     if ((x = cmtxt("Text of comment line","",&s,NULL)) < 0)
  8423.       return(x);
  8424.     /* Don't change SUCCESS flag for this one */
  8425.     return(0);
  8426.     }
  8427.  
  8428. #ifndef NOLOCAL
  8429.     if (cx == XXCON || cx == XXCQ)    /* CONNECT or CONNECT /QUIETLY */
  8430.       return(doxconn(cx));
  8431. #endif /* NOLOCAL */
  8432.  
  8433. #ifndef NOFRILLS
  8434. #ifdef ZCOPY
  8435.     if (cx == XXCPY) {            /* COPY a file */
  8436. #ifdef IKSD
  8437.     if (inserver && !ENABLED(en_cpy)) {
  8438.         printf("?Sorry, COPY is disabled\n");
  8439.         return(-9);
  8440.     }
  8441. #endif /* IKSD */
  8442. #ifdef CK_APC
  8443.     if (apcactive == APC_LOCAL ||
  8444.         (apcactive == APC_REMOTE && !(apcstatus & APC_UNCH))
  8445.         )
  8446.       return(success = 0);
  8447. #endif /* CK_APC */
  8448.     return(docopy());
  8449.     }
  8450. #endif /* ZCOPY */
  8451. #ifdef NT
  8452.     if ( cx == XXLINK ) {
  8453. #ifdef IKSD
  8454.         if (inserver && !ENABLED(en_cpy)) {
  8455.             printf("?Sorry, LINK (COPY) is disabled\n");
  8456.             return(-9);
  8457.         }
  8458. #endif /* IKSD */
  8459. #ifdef CK_APC
  8460.         if (apcactive == APC_LOCAL ||
  8461.             (apcactive == APC_REMOTE && !(apcstatus & APC_UNCH))
  8462.             )
  8463.           return(success = 0);
  8464. #endif /* CK_APC */
  8465.         return(dolink());
  8466.     }
  8467. #endif /* NT */
  8468. #endif /* NOFRILLS */
  8469.  
  8470.     /* CD and friends */
  8471.     if (cx == XXCWD  || cx == XXCDUP || cx == XXBACK ||
  8472.     cx == XXLCWD || cx == XXLCDU || cx == XXKCD) {
  8473. #ifdef LOCUS
  8474.     if (!locus) {
  8475.         if (cx == XXCWD) {
  8476. #ifdef NOXFER
  8477.                 return(-2);
  8478. #else
  8479.                 return(dormt(XZCWD));
  8480. #endif /* NOXFER */
  8481.         } else if (cx == XXCDUP) {
  8482. #ifdef NOXFER
  8483.                 return(-2);
  8484. #else
  8485.                 return(dormt(XZCDU));
  8486. #endif /* NOXFER */
  8487.             }
  8488.     }
  8489. #endif /* LOCUS */
  8490. #ifdef IKSD
  8491.     if (inserver && !ENABLED(en_cwd)) {
  8492.         printf("?Sorry, changing directories is disabled\n");
  8493.         return(-9);
  8494.     }
  8495. #endif /* IKSD */
  8496.     return(success = docd(cx));
  8497.     }
  8498.  
  8499.     if (cx == XXCHK)            /* CHECK */
  8500.       return(success = dochk());
  8501.  
  8502.     if (cx == XXCLO) {            /* CLOSE */
  8503.     x = cmkey(clstab,ncls,"\"CONNECTION\", or log or file to close",
  8504.           "connection",xxstring);
  8505.     if (x == -3) {
  8506.         printf("?You must say which file or log\n");
  8507.         return(-9);
  8508.     }
  8509.     if (x < 0) return(x);
  8510.     if ((y = cmcfm()) < 0) return(y);
  8511. #ifndef NOLOCAL
  8512.     if (x == 9999) {        /* CLOSE CONNECTION */
  8513.         x = clsconnx(0);
  8514.         switch (x) {
  8515.           case 0:
  8516.         if (msgflg) printf("?Connection was not open\n");
  8517.           case -1:
  8518.         return(0);
  8519.           case 1:
  8520.         whyclosed = WC_CLOS;
  8521.         return(1);
  8522.         }
  8523.         return(0);
  8524.     }
  8525. #endif /* NOLOCAL */
  8526.     y = doclslog(x);
  8527.     success = (y == 1);
  8528.     return(success);
  8529.     }
  8530.  
  8531. #ifndef NOSPL
  8532.     if (cx == XXDCL || cx == XXUNDCL) {    /* DECLARE an array */
  8533.     return(dodcl(cx));
  8534.     }
  8535. #endif /* NOSPL */
  8536.  
  8537. #ifndef NODIAL
  8538.     if (cx == XXRED  || cx == XXDIAL || cx == XXPDIA ||
  8539.     cx == XXANSW || cx == XXLOOK) { /* DIAL, REDIAL etc */
  8540. #ifdef VMS
  8541.     extern int batch;
  8542. #else
  8543. #ifdef UNIXOROSK
  8544.     extern int backgrd;
  8545. #endif /* UNIXOROSK */
  8546. #endif /* VMS */
  8547.     x = dodial(cx);
  8548.     debug(F101,"dodial returns","",x);
  8549.     if ((cx == XXDIAL || cx == XXRED || cx == XXANSW) &&
  8550.         (x > 0) &&            /* If DIAL or REDIAL succeeded */
  8551.         (dialsta != DIA_PART) &&    /* and it wasn't partial */
  8552.         (dialcon > 0)) {
  8553.         if ((dialcon == 1 ||    /* And DIAL CONNECT is ON, */
  8554.         ((dialcon == 2) &&    /* or DIAL CONNECT is AUTO */
  8555.          !xcmdsrc        /* and we're at top level... */
  8556. #ifdef VMS
  8557.          && !batch        /* Not if running from batch */
  8558. #else
  8559. #ifdef UNIXOROSK
  8560.          && !backgrd        /* Not if running in background */
  8561. #endif /* UNIXOROSK */
  8562. #endif /* VMS */
  8563.          ))) /* Or AUTO */
  8564.           x = doconect(dialcq,    /* Then also CONNECT */
  8565.                            cmdlvl == 0 ? 1 : 0
  8566.                );
  8567.         if (ttchk() < 0)
  8568.           dologend();
  8569.     }
  8570.     return(success = x);
  8571.     }
  8572. #endif /* NODIAL */
  8573.  
  8574. #ifndef NOPUSH
  8575. #ifdef CK_REXX
  8576.     if (cx == XXREXX) {            /* REXX */
  8577.         extern int nopush;
  8578.         if ( nopush )
  8579.           return(success=0);
  8580.         return(dorexx());
  8581.     }
  8582. #endif /* CK_REXX */
  8583. #endif /* NOPUSH */
  8584.  
  8585. #ifndef NOFRILLS
  8586.     if (cx == XXDEL || cx == XXLDEL) {    /* DELETE */
  8587. #ifdef LOCUS
  8588.     if (!locus && cx != XXLDEL) {
  8589. #ifdef NOXFER
  8590.         return(-2);
  8591. #else
  8592.         return(dormt(XZDEL));
  8593. #endif /* NOXFER */
  8594.         }
  8595. #endif /* LOCUS */
  8596. #ifdef IKSD
  8597.     if (inserver && (!ENABLED(en_del)
  8598. #ifdef CK_LOGIN
  8599.              || isguest
  8600. #endif /* CK_LOGIN */
  8601.              )) {
  8602.         printf("?Sorry, DELETE is disabled\n");
  8603.         return(-9);
  8604.     }
  8605. #endif /* IKSD */
  8606. #ifdef CK_APC
  8607.     if ((apcactive == APC_LOCAL) ||
  8608.         ((apcactive == APC_REMOTE) && (!(apcstatus & APC_UNCH))))
  8609.       return(success = 0);
  8610. #endif /* CK_APC */
  8611.     return(dodel());
  8612.     }
  8613. #endif /* NOFRILLS */
  8614.  
  8615.     if (cx == XXTOUC)            /* TOUCH */
  8616.       return(dodir(cx));
  8617.  
  8618.     /* DIRECTORY commands */
  8619.  
  8620.     if (cx == XXDIR  || cx == XXLS || cx == XXLDIR ||
  8621.     cx == XXWDIR || cx == XXHDIR) {
  8622. #ifdef LOCUS
  8623.     if (!locus && cx != XXLDIR) {
  8624. #ifdef NOXFER
  8625.         return(-2);
  8626. #else
  8627.         return(dormt(XZDIR));
  8628. #endif /* NOXFER */
  8629.         }
  8630. #endif /* LOCUS */
  8631. #ifdef IKSD
  8632.     if (inserver && !ENABLED(en_dir)) {
  8633.         printf("?Sorry, DIRECTORY is disabled\n");
  8634.         return(-9);
  8635.     }
  8636. #endif /* IKSD */
  8637.     return(dodir(cx));
  8638.     }
  8639.  
  8640. #ifndef NOSPL
  8641.     if (cx == XXELS)            /* ELSE */
  8642.       return(doelse());
  8643. #endif /* NOSPL */
  8644.  
  8645. #ifndef NOSERVER
  8646. #ifndef NOFRILLS
  8647.     if (cx == XXENA || cx == XXDIS) {    /* ENABLE, DISABLE */
  8648.     s = (cx == XXENA) ?
  8649.       "Server function to enable" :
  8650.         "Server function to disable";
  8651.  
  8652.     if ((x = cmkey(enatab,nena,s,"",xxstring)) < 0) {
  8653.         if (x == -3) {
  8654.         printf("?Name of server function required\n");
  8655.         return(-9);
  8656.         } else return(x);
  8657.     }
  8658.     if ((y = cmkey(kmstab,3,"mode","both",xxstring)) < 0) {
  8659.         if (y == -3) {
  8660.         printf("?Please specify remote, local, or both\n");
  8661.         return(-9);
  8662.         } else return(y);
  8663.     }
  8664.     if (cx == XXDIS)        /* Disabling, not enabling */
  8665.       y = 3 - y;
  8666.     if ((z = cmcfm()) < 0) return(z);
  8667. #ifdef CK_APC
  8668.     if ((apcactive == APC_LOCAL) ||
  8669.         ((apcactive == APC_REMOTE) && (!(apcstatus & APC_UNCH))))
  8670.       return(success = 0);
  8671. #endif /* CK_APC */
  8672. #ifdef IKSD
  8673.         /* This may seem like it duplicates the work in doenable()  */
  8674.         /* but this code returns failure whereas doenable() returns */
  8675.         /* success.                                                 */
  8676.         if (inserver &&
  8677. #ifdef IKSDCONF
  8678.             iksdcf &&
  8679. #endif /* IKSDCONF */
  8680.             (x == EN_HOS || x == EN_PRI || x == EN_MAI || x == EN_WHO ||
  8681.               isguest))
  8682.             return(success = 0);
  8683. #endif /* IKSD */
  8684.     return(doenable(y,x));
  8685.     }
  8686. #endif /* NOFRILLS */
  8687. #endif /* NOSERVER */
  8688.  
  8689. #ifndef NOSPL
  8690.     if (cx == XXRET) {            /* RETURN */
  8691.     if ((x = cmtxt("Optional return value","",&s,NULL)) < 0)
  8692.       return(x);
  8693.     s = brstrip(s);            /* Strip braces */
  8694.     if (cmdlvl == 0)        /* At top level, nothing happens... */
  8695.       return(success = 1);
  8696.     switch (cmdstk[cmdlvl].src) {    /* Action depends on command source */
  8697.       case CMD_TF:            /* Command file */
  8698.         popclvl();            /* Pop command level */
  8699.         return(success = 1);    /* always succeeds */
  8700.       case CMD_MD:            /* Macro */
  8701.       case CMD_KB:            /* Prompt */
  8702.         return(doreturn(s));    /* Trailing text is return value. */
  8703.       default:            /* Shouldn't happen */
  8704.         return(-2);
  8705.     }
  8706.     }
  8707. #endif /* NOSPL */
  8708.  
  8709. #ifndef NOSPL
  8710.     if (cx == XXOPE)            /* OPEN */
  8711.       return(doopen());
  8712. #endif /* NOSPL */
  8713.  
  8714. #ifndef NOSPL
  8715.     if (cx == XXOUT || cx == XXLNOUT) {    /* OUTPUT or LINEOUT */
  8716.     if ((x = cmtxt("Text to be output","",&s,NULL)) < 0)
  8717.       return(x);
  8718. #ifdef CK_APC
  8719.     if ((apcactive == APC_LOCAL) ||
  8720.         ((apcactive == APC_REMOTE) && (!(apcstatus & APC_UNCH))))
  8721.       return(success = 0);
  8722. #endif /* CK_APC */
  8723.     debug(F110,"OUTPUT 1",s,0);
  8724.     s = brstrip(s);            /* Strip enclosing braces, */
  8725.     debug(F110,"OUTPUT 2",s,0);
  8726. /*
  8727.   I don't think I could ever fully explain this in a million years...
  8728.   We have read the user's string without calling the variable-expander
  8729.   function.  Now, before we call it, we have to double backslashes that
  8730.   appear before \N, \B, \L, and \ itself, so the expander function will
  8731.   reduce them back to single backslashes, so when we call dooutput()...
  8732.   But it's more complicated than that.
  8733. */
  8734.     if (cmdgquo()) {        /* Only if COMMAND QUOTING ON ... */
  8735.         for (x = 0, y = 0; s[x]; x++, y++) {
  8736.         if (s[x] == CMDQ) {
  8737.             char c = s[x+1];
  8738.             if (c == 'n' || c == 'N' ||
  8739.             c == 'b' || c == 'B' ||
  8740.             c == 'l' || c == 'L' ||
  8741.             c == CMDQ)
  8742.               line[y++] = CMDQ;
  8743.         }
  8744.         line[y] = s[x];
  8745.         }
  8746.         line[y++] = '\0';        /* Now expand variables, etc. */
  8747.         debug(F110,"OUTPUT 3",line,0);
  8748.         s = line+y+1;
  8749.         x = LINBUFSIZ - (int) strlen(line) - 1;
  8750.         debug(F101,"OUTPUT size","",x);
  8751.         if (zzstring(line,&s,&x) < 0)
  8752.           return(success = 0);
  8753.         s = line+y+1;
  8754.         debug(F110,"OUTPUT 4",s,0);
  8755.     }
  8756.     success = dooutput(s,cx);
  8757.     return(success);
  8758.     }
  8759. #endif /* NOSPL */
  8760.  
  8761. #ifdef ANYX25
  8762. #ifndef IBMX25
  8763.     if (cx == XXPAD) {            /* PAD commands */
  8764.     x = cmkey(padtab,npadc,"PAD command","",xxstring);
  8765.     if (x == -3) {
  8766.         printf("?You must specify a PAD command to execute\n");
  8767.         return(-9);
  8768.     }
  8769.     if (x < 0) return(x);
  8770.  
  8771.     switch (x) {
  8772.       case XYPADL:
  8773.         if (x25stat() < 0)
  8774.           printf("Sorry, you must 'set network' & 'set host' first\r\n");
  8775.         else {
  8776.         x25clear();
  8777.         initpad();
  8778.         }
  8779.         break;
  8780.       case XYPADS:
  8781.         if (x25stat() < 0)
  8782.           printf("Not connected\r\n");
  8783.         else {
  8784.         extern int linkid, lcn;
  8785.         conol("Connected thru ");
  8786.         conol(ttname);
  8787.         printf(", Link id %d, Logical channel number %d\r\n",
  8788.                linkid,lcn);
  8789.         }
  8790.         break;
  8791.       case XYPADR:
  8792.         if (x25stat() < 0)
  8793.           printf("Sorry, you must 'set network' & 'set host' first\r\n");
  8794.         else
  8795.           x25reset(0,0);
  8796.         break;
  8797.       case XYPADI:
  8798.         if (x25stat() < 0)
  8799.           printf("Sorry, you must 'set network' & 'set host' first\r\n");
  8800.         else
  8801.           x25intr(0);
  8802.     }
  8803.     return(0);
  8804.     }
  8805. #endif /* IBMX25 */
  8806. #endif /* ANYX25 */
  8807.  
  8808. #ifndef NOSPL
  8809.     if (cx == XXPAU || cx == XXWAI || cx == XXMSL) /* PAUSE, WAIT, etc */
  8810.       return(dopaus(cx));
  8811. #endif /* NOSPL */
  8812.  
  8813. #ifndef NOFRILLS
  8814.     if (cx == XXPRI) {
  8815. #ifdef IKSD
  8816. #ifdef CK_LOGIN
  8817.     if (inserver && (isguest || !ENABLED(en_pri))) {
  8818.         printf("?Sorry, printing is disabled\n");
  8819.         return(-9);
  8820.     }
  8821. #endif /* CK_LOGIN */
  8822. #endif /* IKSD */
  8823.     if ((x = cmifi("File to print","",&s,&y,xxstring)) < 0) {
  8824.         if (x == -3) {
  8825.         printf("?A file specification is required\n");
  8826.         return(-9);
  8827.         } else return(x);
  8828.     }
  8829.     if (y != 0) {
  8830.         printf("?Wildcards not allowed\n");
  8831.         return(-9);
  8832.     }
  8833.     ckstrncpy(line,s,LINBUFSIZ);
  8834.     s = "";
  8835. #ifndef NT
  8836.     if ((x = cmtxt("Local print command options, or carriage return","",&s,
  8837.                xxstring)) < 0)
  8838.       return(x);
  8839. #endif /* NT */
  8840.     if ((x = cmcfm()) < 0)
  8841.       return(x);
  8842.     return(success = (zprint(s,line) == 0) ? 1 : 0);
  8843.     }
  8844. #endif /* NOFRILLS */
  8845.  
  8846. #ifdef TCPSOCKET
  8847. #ifndef NOPUSH
  8848.     if (cx == XXPNG)             /* PING an IP host */
  8849.       return(doping());
  8850. #endif /* NOPUSH */
  8851.  
  8852. #ifndef NOFTP
  8853.     if (cx == XXFTP)            /* FTP */
  8854. #ifdef SYSFTP
  8855. #ifndef NOPUSH
  8856.       return(doftp());            /* Just runs system's ftp program */
  8857. #else
  8858.       return(-2);
  8859. #endif /* NOPUSH */
  8860. #else
  8861.     return(doxftp());
  8862. #endif /* SYSFTP */
  8863. #endif /* NOFTP */
  8864. #endif /* TCPSOCKET */
  8865.  
  8866.     if (cx == XXPWD || cx == XXLPWD) {    /* PWD */
  8867. #ifdef OS2
  8868.     char *pwp;
  8869. #endif /* OS2 */
  8870.     if ((x = cmcfm()) < 0)
  8871.       return(x);
  8872. #ifdef LOCUS
  8873.     if (!locus && cx != XXLPWD) {
  8874. #ifdef NOXFER
  8875.         return(-2);
  8876. #else
  8877.         return(dormt(XZPWD));
  8878. #endif /* NOXFER */
  8879.         }
  8880. #endif /* LOCUS */
  8881.  
  8882. #ifndef MAC
  8883. #ifndef OS2
  8884. #ifdef UNIX
  8885.     printf("%s\n",zgtdir());
  8886. #else
  8887.     xsystem(PWDCMD);
  8888. #endif /* UNIX */
  8889.     return(success = 1);        /* Blind faith */
  8890. #else  /* OS2 */
  8891.     if (pwp = zgtdir()) {
  8892.         if (*pwp) {
  8893. #ifdef NT
  8894.         line[0] = NUL;
  8895.         ckGetLongPathName(pwp,line,LINBUFSIZ);
  8896.         line[LINBUFSIZ-1] = NUL;
  8897.         tmpbuf[0] = NUL;
  8898.         GetShortPathName(pwp,tmpbuf,TMPBUFSIZ);
  8899.         tmpbuf[TMPBUFSIZ-1] = NUL;
  8900.         pwp = line;
  8901.         if (!strcmp(line,tmpbuf)) {
  8902. #endif /* NT */
  8903.             printf("%s\n",pwp);
  8904. #ifdef NT
  8905.         } else {
  8906.             printf("  Long name:  %s\n",line);
  8907.             printf("  Short name: %s\n",tmpbuf);
  8908.         }            
  8909. #endif /* NT */
  8910.         }
  8911.         return(success = ((int)strlen(pwp) > 0));
  8912.     } else return(success = 0);
  8913. #endif /* OS2 */
  8914. #else  /* MAC */
  8915.     if (pwp = zgtdir()) {
  8916.         printf("%s\n",pwp);
  8917.         return(success = ((int)strlen(pwp) > 0));
  8918.     } else return(success = 0);
  8919. #endif /* MAC */
  8920.     }
  8921.  
  8922.     if (cx == XXQUI || cx == XXEXI) {    /* EXIT, QUIT */
  8923.     extern int quitting;
  8924.  
  8925.     if ((y = cmnum("exit status code",ckitoa(xitsta),10,&x,xxstring)) < 0)
  8926.       return(y);
  8927.     if ((y = cmtxt("Optional EXIT message","",&s,xxstring)) < 0)
  8928.       return(y);
  8929.     s = brstrip(s);
  8930.     ckstrncpy(line,s,LINBUFSIZ);
  8931.  
  8932.     if (!hupok(0))            /* Check if connection still open */
  8933.       return(success = 0);
  8934.  
  8935.     if (line[0])            /* Print EXIT message if given */
  8936.       printf("%s\n",(char *)line);
  8937.  
  8938.     quitting = 1;            /* Flag that we are quitting. */
  8939.  
  8940. #ifdef VMS
  8941.     doexit(GOOD_EXIT,x);
  8942. #else
  8943. #ifdef OSK
  8944. /* Returning any codes here makes the OS-9 shell print an error message. */
  8945.     doexit(GOOD_EXIT,-1);
  8946. #else
  8947. #ifdef datageneral
  8948.         doexit(GOOD_EXIT,x);
  8949. #else
  8950.     doexit(x,-1);
  8951. #endif /* datageneral */
  8952. #endif /* OSK */
  8953. #endif /* VMS */
  8954.     }
  8955.  
  8956. #ifndef NOXFER
  8957. #ifndef NOFRILLS
  8958.     if (cx == XXERR) {            /* ERROR */
  8959. #ifdef CK_XYZ
  8960.     if (protocol != PROTO_K) {
  8961.         printf("Sorry, E-PACKET only works with Kermit protocol\n");
  8962.         return(-9);
  8963.     }
  8964. #endif /* CK_XYZ */
  8965.     if ((x = cmcfm()) < 0) return(x);
  8966.     ttflui();
  8967.     epktflg = 1;
  8968.     sstate = 'a';
  8969.     return(0);
  8970.     }
  8971. #endif /* NOFRILLS */
  8972.  
  8973.     if (cx == XXFIN) {            /* FINISH */
  8974. #ifdef NEWFTP
  8975.     if ((ftpget == 1) || ((ftpget == 2) && ftpisopen()))
  8976.       return(ftpbye());
  8977. #endif /* NEWFTP */
  8978. #ifdef CK_XYZ
  8979.     if (protocol != PROTO_K) {
  8980.         printf("Sorry, FINISH only works with Kermit protocol\n");
  8981.         return(-9);
  8982.     }
  8983. #endif /* CK_XYZ */
  8984.     if ((x = cmcfm()) < 0) return(x);
  8985.  
  8986. #ifdef IKS_OPTION
  8987.         if (
  8988. #ifdef CK_XYZ
  8989.             protocol == PROTO_K &&
  8990. #endif /* CK_XYZ */
  8991.             !iks_wait(KERMIT_REQ_START,1)) {
  8992.         printf(
  8993.               "?A Kermit Server is not available to process this command\n");
  8994.         return(-9);            /* Correct the return code */
  8995.         }
  8996. #endif /* IKS_OPTION */
  8997.  
  8998.     sstate = setgen('F',"","","");
  8999.     if (local) ttflui();        /* If local, flush tty input buffer */
  9000.     return(0);
  9001.     }
  9002. #endif /* NOXFER */
  9003.  
  9004. #ifndef NOSPL
  9005.     if (cx == XXFOR)            /* FOR loop */
  9006.       return(dofor());
  9007. #endif /* NOSPL */
  9008.  
  9009. #ifndef NOXFER
  9010.     /* GET MGET REGET RETRIEVE etc */
  9011.     if (cx == XXGET || cx == XXMGET || cx == XXREGET || cx == XXRETR) {
  9012. #ifdef IKSD
  9013.     if (inserver && !ENABLED(en_sen)) {
  9014.         printf("?Sorry, reception of files is disabled\n");
  9015.         return(-9);
  9016.     }
  9017. #endif /* IKSD */
  9018.     return(doxget(cx));
  9019.     }
  9020. #endif /* NOXFER */
  9021.  
  9022. #ifndef NOSPL
  9023. #ifndef NOFRILLS
  9024.     if (cx == XXGOK) {            /* GETOK */
  9025.     return(success = doask(cx));
  9026.     }
  9027. #endif /* NOFRILLS */
  9028. #endif /* NOSPL */
  9029.  
  9030.     if (cx == XXHLP) {            /* HELP */
  9031. #ifdef NOHELP
  9032.     return(dohlp(XXHLP));
  9033. #else
  9034.     x = cmkey2(cmdtab,
  9035.            ncmd,"\nCommand or topic","help",toktab,xxstring,1+2+8);
  9036.     debug(F111,"HELP command x",cmdbuf,x);
  9037.     if (x == -5) {
  9038.         y = chktok(toktab);
  9039.         debug(F101,"HELP cmkey token","",y);
  9040.         /* ungword(); */
  9041.         switch (y) {
  9042. #ifndef NOPUSH
  9043.           case '!':
  9044.           case '@': x = XXSHE; break;
  9045.           case '<': x = XXFUN; break;
  9046. #endif /* NOPUSH */
  9047.           case '#': x = XXCOM; break;
  9048.           case ';': x = XXCOM; break;
  9049. #ifndef NOSPL
  9050.               case '.': x = XXDEF; break;
  9051.           case ':': x = XXLBL; break;
  9052. #ifndef NOSEXP
  9053.           case '(': x = XXSEXP; break;
  9054. #endif /* NOSEXP */
  9055. #endif /* NOSPL */
  9056. #ifdef CK_RECALL
  9057.           case '^': x = XXREDO; break;
  9058. #endif    /* CK_RECALL */
  9059.           case '&': x = XXECH; break; /* (what is this?) */
  9060.           default:
  9061.         printf("\n?Invalid - %s\n",cmdbuf);
  9062.         x = -2;
  9063.         }
  9064.     }
  9065.     makestr(&hlptok,atmbuf);
  9066.     debug(F111,"HELP token",hlptok,x);
  9067.     return(dohlp(x));
  9068. #endif /* NOHELP */
  9069.     }
  9070.  
  9071. #ifndef NOHELP
  9072.     if (cx == XXINT)            /* INTRO */
  9073.       return(hmsga(introtxt));
  9074.     if (cx == XXNEW) {            /* NEWS */
  9075.     int x;
  9076.     extern char * k_info_dir;
  9077.     x = hmsga(newstxt);
  9078.     return(x);
  9079.     }
  9080.  
  9081. #ifdef OS2ONLY
  9082.     if (cx == XXUPD) {            /* View UPDATE file */
  9083.         extern char exedir[];
  9084.         char * pTopic;
  9085.         char updstr[2048];
  9086.         if ((x = cmtxt("topic name","",&pTopic,xxstring)) < 0)
  9087.             return x;
  9088. #ifdef COMMENT
  9089.     sprintf(updstr,
  9090.         "start view %s\\docs\\k2.inf+%s\\docs\\using_ck.inf+\
  9091. %s\\docs\\dialing.inf+%s\\docs\\modems.inf %s",
  9092.         exedir,exedir,exedir,exedir,pTopic
  9093.         );
  9094. #else
  9095.     if (ckmakxmsg(updstr,
  9096.              2048,
  9097.              "start view ",
  9098.              exedir,
  9099.              "\\docs\\k2.inf+",
  9100.              exedir,
  9101.              "\\docs\\using_ck.inf+",
  9102.              exedir,
  9103.              "\\docs\\dialing.inf+",
  9104.              exedir,
  9105.              "\\docs\\modems.inf ",
  9106.              pTopic,
  9107.              NULL,
  9108.              NULL
  9109.              ) > 0)
  9110. #endif /* COMMENT */
  9111.       system(updstr);
  9112.         return(success = 1);
  9113.     }
  9114. #endif /* OS2ONLY */
  9115. #endif /* NOHELP */
  9116.  
  9117. #ifndef NOLOCAL
  9118.     if (cx == XXHAN) {            /* HANGUP */
  9119.     if ((x = cmcfm()) < 0) return(x);
  9120. #ifdef NEWFTP
  9121.     if ((ftpget == 1) || ((ftpget == 2) && !local && ftpisopen()))
  9122.       return(success = ftpbye());
  9123. #endif /* NEWFTP */
  9124. #ifndef NODIAL
  9125.     if ((x = mdmhup()) < 1) {
  9126.         debug(F101,"HANGUP mdmup","",x);
  9127. #endif /* NODIAL */
  9128.         x = tthang();
  9129.         debug(F101,"HANGUP tthang","",x);
  9130.         x = (x > -1);
  9131. #ifndef NODIAL
  9132.     }
  9133.     dialsta = DIA_UNK;
  9134. #endif /* NODIAL */
  9135.     whyclosed = WC_CLOS;
  9136.     ttchk();            /* In case of CLOSE-ON-DISCONNECT */
  9137.     dologend();
  9138. #ifdef OS2
  9139.     if (x)
  9140.       DialerSend(OPT_KERMIT_HANGUP, 0);
  9141. #endif /* OS2 */
  9142.     if (x) haveline = 0;
  9143.     return(success = x);
  9144.     }
  9145. #endif /* NOLOCAL */
  9146.  
  9147. #ifndef NOSPL
  9148.     /* INPUT, REINPUT, and MINPUT */
  9149.  
  9150.     if (cx == XXINP || cx == XXREI || cx == XXMINP) {
  9151.     long zz;
  9152.     int flags = 0, incount = 0;
  9153.     extern int itsapattern, isjoin, isinbuflen;
  9154.     int c, getval;
  9155.  
  9156.     struct FDB sw, nu, fl;
  9157.     int fc, havetime = 0;
  9158.     char * m;
  9159.  
  9160.     if (cx == XXREI) {
  9161.         m = "Timeout in seconds (ignored)";
  9162.     } else {
  9163.         m = "Seconds to wait for input,\n or time of day hh:mm:ss,\
  9164.  or switch";
  9165.     }
  9166.     cmfdbi(&sw,            /* First FDB - command switches */
  9167.            _CMKEY,            /* fcode */
  9168.            m,            /* helpmsg */
  9169.            ckitoa(indef),        /* default */
  9170.            "",            /* addtl string data */
  9171.            ninputsw,        /* addtl numeric data 1: tbl size */
  9172.            4,            /* addtl numeric data 2: 4 = cmswi */
  9173.            xxstring,        /* Processing function */
  9174.            inputsw,            /* Keyword table */
  9175.            &nu            /* Pointer to next FDB */
  9176.            );
  9177.     cmfdbi(&nu,
  9178.            _CMNUM,            /* Number */
  9179.            m,            /* Help message */
  9180.            ckitoa(indef),        /* default */
  9181.            "",            /* N/A */
  9182.            10,            /* Radix = 10 */
  9183.            0,            /* N/A */
  9184.            xxstring,        /* Processing function */
  9185.            NULL,            /* N/A */
  9186.            &fl            /* Next */
  9187.            );
  9188.     cmfdbi(&fl,            /* Time of day hh:mm:ss */
  9189.            _CMFLD,            /* fcode */
  9190.            "",            /* hlpmsg */
  9191.            "",
  9192.            "",            /* addtl string data */
  9193.            0,            /* addtl numeric data 1 */
  9194.            0,            /* addtl numeric data 2 */
  9195.            xxstring,
  9196.            NULL,
  9197.            NULL
  9198.            );
  9199.     fc = (cx == XXREI) ? cmfdb(&nu) : cmfdb(&sw); /* Parse something */
  9200.  
  9201.     for (y = 0; y < MINPMAX; y++) {    /* Initialize search strings */
  9202.         mp[y] = 0;            /* Assume it's not a pattern */
  9203.         if (!mpinited) {
  9204.         ms[y] = NULL;
  9205.         }
  9206.         if (ms[y]) {
  9207.         free(ms[y]);        /* Free old strings, if any */
  9208.         ms[y] = NULL;
  9209.         }
  9210.     }
  9211.     mpinited = 1;
  9212.     while (!havetime) {
  9213.         if (fc < 0) {        /* Error */
  9214.         if (fc == -3) {
  9215.             printf("?Syntax error in INPUT-class command\n");
  9216.             return(-9);
  9217.         } else
  9218.           return(fc);
  9219.         }
  9220.         switch (cmresult.fcode) {
  9221.           case _CMKEY:        /* Switch */
  9222.         c = cmgbrk();
  9223.         if ((getval = (c == ':' || c == '=')) &&
  9224.             !(cmgkwflgs() & CM_ARG)) {
  9225.             printf("?This switch does not take an argument\n");
  9226.             return(-9);
  9227.         }
  9228.         if (getval && cmresult.nresult == INPSW_COU) {
  9229.             if ((y = cmnum("Number of bytes to read",
  9230.                    "",10,&x,xxstring)) < 0)
  9231.               return(y);
  9232.             incount = x;
  9233.         }
  9234.         flags |= cmresult.nresult;
  9235.         fc = cmfdb(&sw);    /* Maybe parse more switches */
  9236.         continue;
  9237.  
  9238.           case _CMNUM:        /* Seconds to time out */
  9239.         x = cmresult.nresult;
  9240. #ifdef CKFLOAT
  9241.         if (inscale != 1.0)    /* Scale */
  9242.           x *= inscale;        
  9243. #endif    /* CKFLOAT */
  9244.         havetime++;
  9245.         break;
  9246.  
  9247.           case _CMFLD:
  9248.         zz = tod2sec(atmbuf);    /* Convert to secs since midnight */
  9249.         if (zz < 0L) {
  9250.             printf("?Number, expression, or time of day required\n");
  9251.             return(-9);
  9252.         } else {
  9253.             char now[32];    /* Current time */
  9254.             char *p;
  9255.             long tnow;
  9256.             p = now;
  9257.             ztime(&p);
  9258.             tnow = atol(p+11) * 3600L + atol(p+14) * 60L + atol(p+17);
  9259.             if (zz < tnow)    /* User's time before now */
  9260.               zz += 86400L;    /* So make it tomorrow */
  9261.             zz -= tnow;        /* Seconds from now. */
  9262.             if (zz > -1L) {
  9263.             x = zz;
  9264.             if (zz != (long) x) {
  9265.                 printf(
  9266. "Sorry, arithmetic overflow - hh:mm:ss not usable on this platform.\n"
  9267. );
  9268.                 return(-9);
  9269.             }
  9270.             }
  9271.             havetime++;
  9272.         }
  9273.         break;
  9274.           default:        
  9275.         printf("?Internal error\n");
  9276.         return(-9);
  9277.         }
  9278.     }
  9279.     /* Now parse the search text */
  9280.  
  9281. #ifdef CK_MINPUT
  9282.     if (cx == XXMINP) {        /* MINPUT */
  9283.         int i, k = 0, n = 0;
  9284.         struct stringarray * q;
  9285.         keepallchars = 1;
  9286.         while (k < MINPMAX) {
  9287.         if ((y = cmfld("String or pattern","",&s,xxstring)) < 0) {
  9288.             if (y == -3) {
  9289.             if ((y = cmcfm()) < 0)
  9290.               return(y);
  9291.             break;
  9292.             } else {
  9293.             return(y);
  9294.             }
  9295.         }
  9296.         debug(F111,"MINPUT field",s,k);
  9297.         if (isjoin) {
  9298.             if ((q = cksplit(1,0,s," ",(char *)c1chars,3,0,0))) {
  9299.             char ** ap = q->a_head;
  9300.             n = q->a_size;
  9301.             debug(F101,"minput cksplit size","",n);
  9302.             for (i = 1; i <= n && k < MINPMAX; i++) {
  9303.                 if (!ap[i]) /* Add non-empty elements */
  9304.                   continue;
  9305.                 if (!*(ap[i]))
  9306.                   continue;
  9307.                 makestr(&(ms[k]),ap[i]);
  9308.                 debug(F111,"MINPUT JOIN",ms[k],k);
  9309.                 k++;
  9310.             }
  9311.             }
  9312.         } else {
  9313.             if (s) if (*s) {
  9314.             makestr(&(ms[k]),brstrip(s));
  9315.             if (itsapattern) mp[k] = 1;
  9316.             debug(F111,"MINPUT",ms[k],itsapattern);
  9317.             k++;
  9318.             }
  9319.         }
  9320.         }
  9321.         keepallchars = 0;
  9322.     } else {
  9323. #endif /* CK_MINPUT */
  9324.  
  9325.         /* INPUT or REINPUT */
  9326.  
  9327.         if (flags & INPSW_COU) {
  9328.         if ((y = cmcfm()) < 0)
  9329.           return(y);
  9330.         } else {
  9331.         if ((y = cmtxt("Material to be input","",&s,xxstring)) < 0)
  9332.           return(y);
  9333.         }
  9334.         mp[0] = itsapattern ? 1 : 0;
  9335.         makestr(&(ms[0]),brstrip(s));
  9336.         ms[1] = NULL;
  9337.  
  9338. #ifdef CK_MINPUT
  9339.     }
  9340. #endif /* CK_MINPUT */
  9341.  
  9342.     if (incount > 0)        /* No searching if /COUNT: given */
  9343.       makestr(&(ms[0]),NULL);
  9344.  
  9345.     if (cx == XXINP || cx == XXMINP) { /* Not REINPUT... */
  9346.         i_active = 1;
  9347.         /* Go try to input the search string */
  9348.         success = doinput(x,ms,mp,flags,incount);
  9349.         i_active = 0;
  9350.     } else {            /* REINPUT */
  9351.         success = doreinp(x,ms[0],itsapattern);
  9352.     }
  9353.     if (intime[cmdlvl] && !success) { /* TIMEOUT-ACTION = QUIT? */
  9354.         popclvl();            /* If so, pop command level. */
  9355.         if (pflag && cmdlvl == 0) {
  9356.         if (cx == XXINP)  printf("?INPUT timed out\n");
  9357.         if (cx == XXMINP) printf("?MINPUT timed out\n");
  9358.         if (cx == XXREI)  printf("?REINPUT failed\n");
  9359.         }
  9360.     }
  9361.     return(success);        /* Return do(re)input's return code */
  9362.     }
  9363.  
  9364. #endif /* NOSPL */
  9365.  
  9366.     if (cx == XXLOG) {            /* LOG */
  9367.     x = cmkey(logtab,nlog,"What to log","",xxstring);
  9368.     if (x == -3) {
  9369.         printf("?Type of log required\n");
  9370.         return(-9);
  9371.     }
  9372.     if (x < 0) return(x);
  9373.     x = dolog(x);
  9374.     if (x < 0)
  9375.       return(x);
  9376.     else
  9377.       return(success = x);
  9378.     }
  9379.  
  9380.     if (cx == XXLOGIN) {        /* (REMOTE) LOGIN */
  9381. #ifdef NEWFTP
  9382.     if ((ftpget == 1) || ((ftpget == 2) && ftpisopen()))
  9383.       return(success = doftpusr());
  9384. #endif /* NEWFTP */
  9385. #ifdef IKSD
  9386.     if (inserver) {
  9387.         printf("?Already logged in\n");
  9388.         return(-9);
  9389.     } else
  9390. #endif /* IKSD */
  9391.     {
  9392. #ifdef NOXFER
  9393.         return(-2);
  9394. #else
  9395.         return(dormt(XZLGI));
  9396. #endif /* NOXFER */
  9397.     }
  9398.     }
  9399.     if (cx == XXLOGOUT) {        /* (REMOTE) LOGOUT */
  9400. #ifdef NEWFTP
  9401.     if ((ftpget == 1) || ((ftpget == 2) && ftpisopen()))
  9402.       return(success = doftpres());
  9403. #endif /* NEWFTP */
  9404.  
  9405. #ifdef IKSD
  9406.         if (inserver) {
  9407.         if ((x = cmcfm()) < 0)
  9408.           return(x);
  9409.         doexit(GOOD_EXIT,xitsta);
  9410.     } else
  9411. #endif /* IKSD */
  9412.     if (!local || (network && ttchk() < 0)) {
  9413.         printf("?No connection.\n");
  9414.         return(-9);
  9415.     } else {
  9416. #ifdef NOXFER
  9417.         return(-2);
  9418. #else
  9419.         return(dormt(XZLGO));
  9420. #endif /* NOXFER */
  9421.     }
  9422.     }
  9423.  
  9424. #ifndef NOSCRIPT
  9425.     if (cx == XXLOGI) {            /* UUCP-style script */
  9426.     if ((x = cmtxt("expect-send expect-send ...","",&s,xxstring)) < 0)
  9427.       return(x);
  9428. #ifdef CK_APC
  9429.     if ((apcactive == APC_LOCAL) ||
  9430.         ((apcactive == APC_REMOTE) && (!(apcstatus & APC_UNCH))))
  9431.       return(success = 0);
  9432. #endif /* CK_APC */
  9433. #ifdef VMS
  9434.     conres();            /* For Ctrl-C to work... */
  9435. #endif /* VMS */
  9436.     return(success = dologin(s));    /* Return 1=completed, 0=failed */
  9437.     }
  9438. #endif /* NOSCRIPT */
  9439.  
  9440. #ifndef NOXFER
  9441. #ifdef PIPESEND
  9442.     if (cx == XXCREC) {            /* CRECEIVE */
  9443.     if (protocol != PROTO_K) {
  9444.         printf("?Sorry, CRECEIVE works only with Kermit protocol\n");
  9445.         return(-9);
  9446.     } else
  9447.       return(doxget(cx));
  9448.     }
  9449.     if (cx == XXCGET) {            /* CGET */
  9450.     return(doxget(cx));
  9451.     }
  9452. #endif /* PIPESEND */
  9453.  
  9454.     if (cx == XXREC)            /* RECEIVE */
  9455.       return(doxget(cx));
  9456. #endif /* NOXFER */
  9457.  
  9458. #ifndef NOXFER
  9459.     if (cx == XXREM) {            /* REMOTE */
  9460. #ifdef NEWFTP
  9461.     if ((ftpget == 1) || ((ftpget == 2) && ftpisopen()))
  9462.       return(doftprmt(0,0));
  9463. #endif /* NEWFTP */
  9464. #ifdef CK_XYZ
  9465.     if (protocol != PROTO_K) {
  9466.         printf("Sorry, REMOTE commands only work with Kermit protocol\n");
  9467.         return(-9);
  9468.     }
  9469. #endif /* CK_XYZ */
  9470.     x = cmkey(remcmd,nrmt,"Remote Kermit server command","",xxstring);
  9471.     if (x == -3) {
  9472.         printf("?You must specify a command for the remote server\n");
  9473.         return(-9);
  9474.     }
  9475.     return(dormt(x));
  9476.     }
  9477. #endif /* NOXFER */
  9478.  
  9479. #ifndef NORENAME
  9480. #ifndef NOFRILLS
  9481.     if (cx == XXREN || cx == XXLREN) {    /* RENAME */
  9482. #ifdef LOCUS
  9483.     if (!locus && cx != XXLREN) {
  9484. #ifdef NOXFER
  9485.         return(-2);
  9486. #else
  9487.         return(dormt(XZREN));
  9488. #endif /* NOXFER */
  9489.         }
  9490. #endif /* LOCUS */
  9491. #ifdef IKSD
  9492.     if (inserver && (!ENABLED(en_ren)
  9493. #ifdef CK_LOGIN
  9494.              || isguest
  9495. #endif /* CK_LOGIN */
  9496.              )) {
  9497.         printf("?Sorry, renaming of files is disabled\n");
  9498.         return(-9);
  9499.     }
  9500. #endif /* IKSD */
  9501. #ifdef CK_APC
  9502.     if ((apcactive == APC_LOCAL) ||
  9503.         ((apcactive == APC_REMOTE) && (!(apcstatus & APC_UNCH))))
  9504.       return(success = 0);
  9505. #endif /* CK_APC */
  9506.     return(dorenam());
  9507.     }
  9508. #endif /* NOFRILLS */
  9509. #endif /* NORENAME */
  9510.  
  9511.     if (cx == XXEIGHT) {        /* EIGHTBIT */
  9512.     extern int parity, cmask, cmdmsk;
  9513.     if ((x = cmcfm()) < 0)
  9514.       return(x);
  9515.     parity = 0;
  9516.     cmask = 0xff;
  9517.     cmdmsk = 0xff;
  9518.     return(success = 1);
  9519.     }
  9520.  
  9521. #ifndef NOXFER
  9522. /* SEND, CSEND, MOVE, MAIL, and RESEND use the new common code */
  9523.  
  9524.     if (cx == XXSEN            /* SEND */
  9525. #ifdef PIPESEND
  9526.     || cx == XXCSEN            /* CSEND */
  9527. #endif /* PIPESEND */
  9528.     || cx == XXMOVE            /* MOVE */
  9529.     || cx == XXMAI            /* MAIL */
  9530. #ifdef CK_RESEND
  9531.     || cx == XXRSEN            /* RESEND */
  9532. #endif /* CK_RESEND */
  9533.     ) {
  9534. #ifdef IKSD
  9535.     if (inserver && !ENABLED(en_get)) {
  9536.         printf("?Sorry, sending files is disabled\n");
  9537.         return(-9);
  9538.     }
  9539. #endif /* IKSD */
  9540.     return(doxsend(cx));
  9541.     }
  9542.  
  9543. /* PSEND, ADD, and REMOVE use special parsing */
  9544.  
  9545. #ifdef ADDCMD
  9546.     /* ADD and REMOVE */
  9547.     if (cx == XXADD || cx == XXREMV) {
  9548.     char * m;
  9549.     m = (cx == XXADD) ? "Add to which list?" : "Remove from which list?";
  9550.     x = cmkey(addtab,naddtab,m,"",xxstring);
  9551.     if (x < 0)
  9552.       return(x);
  9553. #ifndef NOMSEND
  9554.     if (x == ADD_SND)
  9555.       return(addsend(cx));
  9556.     else
  9557. #endif /* NOMSEND */
  9558.       return(doadd(cx,x));
  9559.     }
  9560. #endif /* ADDCMD */
  9561.  
  9562. #ifdef CK_RESEND
  9563.     if (cx == XXPSEN) {            /* PSEND */
  9564.     int seekto = 0;            /* FIX THIS */
  9565.  
  9566.     cmarg = cmarg2 = "";
  9567.     x = cmifi("File to partially send", "", &s, &y, xxstring);
  9568.     if (x < 0) {
  9569.         if (x == -3) {
  9570.         printf("?A file specification is required\n");
  9571.         return(-9);
  9572.         } else return(x);
  9573.     }
  9574.     nfils = -1;            /* Files come from internal list. */
  9575. #ifndef NOMSEND
  9576.         addlist = 0;            /* Don't use SEND-LIST. */
  9577.         filenext = NULL;
  9578. #endif /* NOMSEND */
  9579.     ckstrncpy(line,s,LINBUFSIZ);    /* Save copy of string just parsed. */
  9580.     debug(F110,"PSEND line",line,0);
  9581.     if (y != 0) {
  9582.         printf("?Sorry, wildcards not permitted in this command\n");
  9583.         return(-9);
  9584.     }
  9585.     if (sizeof(int) < 4) {
  9586.         printf("?Sorry, this command needs 32-bit integers\n");
  9587.         return(-9);
  9588.     }
  9589.     x = cmnum("starting position (byte number)",
  9590.           "",10,&seekto,xxstring);
  9591.     if (x < 0)
  9592.       return(x);
  9593.     zfnqfp(s,fspeclen,fspec);    /* Get full path */
  9594.     if ((x = cmtxt("Name to send it with","",&s,NULL)) < 0)
  9595.       return(x);
  9596.     ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  9597.  
  9598. #ifdef IKSD
  9599.     if (inserver && !ENABLED(en_get)) {
  9600.         printf("?Sorry, sending files is disabled\n");
  9601.         return(-9);
  9602.     }
  9603. #endif /* IKSD */
  9604. #ifdef PIPESEND
  9605.     if (sndfilter) {
  9606.         printf("?Sorry, no PSEND while SEND FILTER selected\n");
  9607.         return(-9);
  9608.     }
  9609. #endif /* PIPESEND */
  9610. #ifdef CK_XYZ
  9611.     if ((protocol == PROTO_X || protocol == PROTO_XC)) {
  9612.         printf("Sorry, PSEND works only with Kermit protocol\n");
  9613.         return(-9);
  9614.     }
  9615. #endif /* CK_XYZ */
  9616.  
  9617.     cmarg2 = brstrip(tmpbuf);    /* Strip braces */
  9618.     cmarg = line;            /* File to send */
  9619.     debug(F110,"PSEND filename",cmarg,0);
  9620.     debug(F110,"PSEND as-name",cmarg2,0);
  9621.     sendstart = seekto;
  9622.     sstate = 's';            /* Set start state to SEND */
  9623. #ifndef NOMSEND
  9624.     addlist = 0;
  9625.     filenext = NULL;
  9626. #endif /* NOMSEND */
  9627.     sendmode = SM_PSEND;
  9628. #ifdef MAC
  9629.     what = W_SEND;
  9630.     scrcreate();
  9631. #endif /* MAC */
  9632.     if (local) {            /* If in local mode, */
  9633.         displa = 1;            /* enable file transfer display */
  9634.     }
  9635.     return(0);
  9636.     }
  9637. #endif /* CK_RESEND */
  9638. #endif /* NOXFER */
  9639.  
  9640. #ifndef NOXFER
  9641. #ifndef NOMSEND
  9642.     if (cx == XXMSE || cx == XXMMOVE) {
  9643. #ifdef NEWFTP
  9644.     if ((ftpget == 1) || ((ftpget == 2) && ftpisopen()))
  9645.       return(doftpput(cx,0));
  9646. #endif /* NEWFTP */
  9647. #ifdef CK_XYZ
  9648.     if (protocol == PROTO_X || protocol == PROTO_XC) {
  9649.         printf(
  9650. "Sorry, you can only send one file at a time with XMODEM protocol\n"
  9651.            );
  9652.         return(-9);
  9653.     }
  9654. #endif /* CK_XYZ */
  9655.         return(doxsend(cx));
  9656.     }
  9657.  
  9658. #ifdef COMMENT                /* (moved to doxsend) */
  9659.     if (cx == XXMSE || cx == XXMMOVE) {    /* MSEND and MMOVE commands */
  9660.     nfils = 0;            /* Like getting a list of */
  9661.     lp = line;            /* files on the command line */
  9662.     addlist = 0;            /* Do not use SEND-LIST */
  9663.     filenext = NULL;        /* Ditto ! */
  9664.  
  9665.     while (1) {
  9666.         char *p;
  9667.         if ((x = cmifi("Names of files to send, separated by spaces","",
  9668.                &s,&y,xxstring)) < 0) {
  9669.         if (x == -3) {
  9670.             if (nfils <= 0) {
  9671.             printf("?A file specification is required\n");
  9672.             return(-9);
  9673.             } else break;
  9674.         }
  9675.         return(x);
  9676.         }
  9677.         msfiles[nfils++] = lp;    /* Got one, count it, point to it, */
  9678.         p = lp;            /* remember pointer, */
  9679.         while (*lp++ = *s++)    /* and copy it into buffer */
  9680.           if (lp > (line + LINBUFSIZ)) { /* Avoid memory leak */
  9681.           printf("?MSEND list too long\n");
  9682.           line[0] = NUL;
  9683.           return(-9);
  9684.           }
  9685.         debug(F111,"msfiles",msfiles[nfils-1],nfils-1);
  9686.         if (nfils == 1) *fspec = NUL; /* Take care of \v(filespec) */
  9687. #ifdef ZFNQFP
  9688.         zfnqfp(p,TMPBUFSIZ,tmpbuf);
  9689.         p = tmpbuf;
  9690. #endif /* ZFNQFP */
  9691.         if (((int)strlen(fspec) + (int)strlen(p) + 1) < fspeclen) {
  9692.         strcat(fspec,p);    /* safe */
  9693.         strcat(fspec," ");    /* safe */
  9694.         } else printf("WARNING - \\v(filespec) buffer overflow\n");
  9695.     }
  9696.     cmlist = msfiles;        /* Point cmlist to pointer array */
  9697.     cmarg2 = "";            /* No internal expansion list (yet) */
  9698.     sndsrc = nfils;            /* Filenames come from cmlist */
  9699.     sendmode = SM_MSEND;        /* Remember this kind of SENDing */
  9700.     sstate = 's';            /* Set start state for SEND */
  9701.     if (cx == XXMMOVE)        /* If MMOVE'ing, */
  9702.       moving = 1;            /*  set this flag. */
  9703. #ifdef MAC
  9704.     what = W_SEND;
  9705.     scrcreate();
  9706. #endif /* MAC */
  9707.     if (local) {            /* If in local mode, */
  9708.         displa = 1;            /* turn on file transfer display */
  9709.         ttflui();            /* and flush tty input buffer. */
  9710.     }
  9711.     return(0);
  9712.     }
  9713. #endif /* COMMENT */
  9714. #endif /* NOMSEND */
  9715. #endif /* NOXFER */
  9716.  
  9717. #ifndef NOSERVER
  9718.     if (cx == XXSER) {            /* SERVER */
  9719. #ifdef CK_XYZ
  9720.     if (protocol != PROTO_K) {
  9721.         printf("Sorry, SERVER only works with Kermit protocol\n");
  9722.         return(-9);
  9723.     }
  9724. #endif /* CK_XYZ */
  9725. #ifdef COMMENT
  9726. /*
  9727.   Parse for time limit, but since we don't use it yet,
  9728.   the parsing is commented out.
  9729. */
  9730.     x_ifnum = 1;            /* Turn off internal complaints */
  9731.     y = cmnum("optional time limit, seconds, or time of day as hh:mm:ss",
  9732.           "0", 10, &x, xxstring
  9733.           );
  9734.     x_ifnum = 0;
  9735.     if (y < 0) {
  9736.         if (y == -2) {        /* Invalid number or expression */
  9737.         zz = tod2sec(atmbuf);    /* Convert to secs since midnight */
  9738.         if (zz < 0L) {
  9739.             printf("?Number, expression, or time of day required\n");
  9740.             return(-9);
  9741.         } else {
  9742.             char now[32];    /* Current time */
  9743.             char *p;
  9744.             long tnow;
  9745.             p = now;
  9746.             ztime(&p);
  9747.             tnow = atol(p+11) * 3600L + atol(p+14) * 60L + atol(p+17);
  9748.             if (zz < tnow)    /* User's time before now */
  9749.               zz += 86400L;    /* So make it tomorrow */
  9750.             zz -= tnow;        /* Seconds from now. */
  9751.         }
  9752.         } else
  9753.           return(y);
  9754.     }
  9755.     if (zz > -1L) {
  9756.         x = zz;
  9757.         if (zz != (long) x) {
  9758.         printf(
  9759. "Sorry, arithmetic overflow - hh:mm:ss not usable on this platform.\n"
  9760.                );
  9761.         return(-9);
  9762.         }
  9763.     }
  9764.     if (x < 0)
  9765.       x = 0;
  9766. #endif /* COMMENT */
  9767.  
  9768.     if ((x = cmcfm()) < 0) return(x);
  9769.     sstate = 'x';
  9770. #ifdef MAC
  9771.     what = W_RECV;
  9772.     scrcreate();
  9773. #endif /* MAC */
  9774.     if (local) displa = 1;
  9775. #ifdef AMIGA
  9776.     reqoff();            /* No DOS requestors while server */
  9777. #endif /* AMIGA */
  9778.     return(0);
  9779.     }
  9780. #endif /* NOSERVER */
  9781.  
  9782.     if (cx == XXSAVE) {            /* SAVE command */
  9783.     x = cmkey(savtab,nsav,"option","keymap",xxstring);
  9784.     if (x == -3) {
  9785.         printf("?You must specify an option to save\n");
  9786.         return(-9);
  9787.     }
  9788.     if (x < 0) return(x);
  9789.     /* have to set success separately for each item in doprm()... */
  9790.     /* actually not really, could have just had doprm return 0 or 1 */
  9791.     /* and set success here... */
  9792.     y = dosave(x);
  9793.     if (y == -3) {
  9794.         printf("?More fields required\n");
  9795.         return(-9);
  9796.     } else return(y);
  9797.     }
  9798.  
  9799.     if (cx == XXSET) {            /* SET command */
  9800.     x = cmkey(prmtab,nprm,"Parameter","",xxstring);
  9801.     if (x == -3) {
  9802.         printf("?You must specify a parameter to set\n");
  9803.         return(-9);
  9804.     }
  9805.     if (x < 0) return(x);
  9806.     /* have to set success separately for each item in doprm()... */
  9807.     /* actually not really, could have just had doprm return 0 or 1 */
  9808.     /* and set success here... */
  9809.     y = doprm(x,0);
  9810.     if (y == -3) {
  9811.         printf("?More fields required\n");
  9812.         return(-9);
  9813.     } else return(y);
  9814.     }
  9815.  
  9816. #ifndef NOPUSH
  9817.     if (cx == XXSHE            /* SHELL (system) command */
  9818.     || cx == XXEXEC            /* exec() */
  9819.     ) {
  9820.     int rx = 0;
  9821.     char * p = NULL;
  9822.     int i /* ,n */ ;
  9823. #ifdef UNIXOROSK
  9824.     char * args[256];
  9825. #endif /* UNIXOROSK */
  9826.  
  9827. #ifdef IKSD
  9828.     if (inserver && (nopush || !ENABLED(en_hos))) {
  9829.         printf("?Sorry, host command access is disabled\n");
  9830.         return(-9);
  9831.     }
  9832. #endif /* IKSD */
  9833.  
  9834. #ifdef CKEXEC
  9835.     if (cx == XXEXEC) {        /* EXEC (overlay ourselves) */
  9836.         struct FDB sw, fl;
  9837.         cmfdbi(&sw,            /* First FDB - command switches */
  9838.            _CMKEY,        /* fcode */
  9839.            "Command to overlay C-Kermit\n or switch", /* hlpmsg */
  9840.            "",            /* default */
  9841.            "",            /* addtl string data */
  9842.            1,            /* addtl numeric data 1: tbl size */
  9843.            4,            /* addtl numeric data 2: 4 = cmswi */
  9844.            xxstring,        /* Processing function */
  9845.            redirsw,        /* Keyword table */
  9846.            &fl            /* Pointer to next FDB */
  9847.            );
  9848.         cmfdbi(&fl,            /* 2nd FDB - command to exec */
  9849.            _CMFLD,        /* fcode */
  9850.            "Command to overlay C-Kermit", /* hlpmsg */
  9851.            "",            /* default */
  9852.            "",            /* addtl string data */
  9853.            0,            /* addtl numeric data 1 */
  9854.            0,            /* addtl numeric data 2 */
  9855.            xxstring,
  9856.            NULL,
  9857.            NULL            /* No more after this */
  9858.            );
  9859.         while (1) {
  9860.         x = cmfdb(&sw);        /* Parse something */
  9861.         debug(F101,"exec cmfdb","",x);
  9862.         if (x < 0)
  9863.           return(x);
  9864.         /* Generalize this if we add more switches */
  9865.         if (cmresult.fcode == _CMKEY) {
  9866.             rx = 1;
  9867.             continue;
  9868.         }
  9869.         if (cmresult.fcode == _CMFLD)
  9870.           break;
  9871.         return(-2);
  9872.         }
  9873.         ckstrncpy(tmpbuf,cmresult.sresult,TMPBUFSIZ);
  9874.         if (!tmpbuf[0]) {
  9875.         printf("?Command required\n");
  9876.         return(-9);
  9877.         }
  9878.         p = brstrip(tmpbuf);
  9879.         args[0] = NULL;        /* Set argv[0] to it */
  9880.         makestr(&args[0],p);
  9881.         for (i = 1; i < 255; i++) {    /* Get arguments for command */
  9882.         if ((x = cmfld("Argument","",&s,xxstring)) < 0) {
  9883.             if (x == -3) {
  9884.             if ((x = cmcfm()) < 0)
  9885.               return(x);
  9886.             break;
  9887.             } else
  9888.               return(x);
  9889.         }
  9890.         args[i] = NULL;
  9891.         s = brstrip(s);
  9892.         makestr(&args[i],s);
  9893.         }
  9894.         args[i] = NULL;
  9895.     } else {
  9896. #endif /* CKEXEC */
  9897.         if ((x = cmtxt("System command to execute","",&s,xxstring)) < 0)
  9898.           return(x);
  9899. #ifdef CKEXEC
  9900.     }
  9901. #endif /* CKEXEC */
  9902.         if (nopush)
  9903.           return(success = 0);
  9904. #ifdef CK_APC
  9905.     if (apcactive == APC_REMOTE && !(apcstatus & APC_UNCH))
  9906.       return(success = 0);
  9907. #endif /* CK_APC */
  9908.     conres();            /* Make console normal  */
  9909. #ifdef OS2
  9910.     if (!(s && *s)) {
  9911.         os2push();
  9912.             return(success = 1);
  9913.     } else
  9914. #endif /* OS2 */
  9915.       if (cx == XXSHE) {
  9916.           x = zshcmd(s);
  9917.           debug(F101,"RUN zshcmd code","",x);
  9918.           concb((char)escape);
  9919.           return(success = x);
  9920. #ifdef CKEXEC
  9921.       } else {
  9922. #ifdef DEBUG
  9923.           if (deblog) {
  9924.           debug(F111,"EXEC cmd",p,0);
  9925.           for (i = 0; i < 256 && args[i]; i++)
  9926.             debug(F111,"EXEC arg",args[i],i);
  9927.           }
  9928. #endif /* DEBUG */
  9929.           if (p) {
  9930.           z_exec(p,args,rx);    /* Overlay ourself */
  9931.           debug(F100,"EXEC fails","",0);
  9932.           concb((char)escape);    /* In case it returns */
  9933.           }
  9934.           return(success = 0);
  9935. #endif /* CKEXEC */
  9936.       }
  9937.     }
  9938.  
  9939. #ifdef CK_REDIR
  9940.     if (cx == XXFUN) {            /* REDIRECT */
  9941. #ifdef CK_APC
  9942.     if ((apcactive == APC_LOCAL) ||
  9943.         ((apcactive == APC_REMOTE) && (!(apcstatus & APC_UNCH))))
  9944.       return(success = 0);
  9945. #endif /* CK_APC */
  9946.     ckmakmsg(tmpbuf,
  9947.          TMPBUFSIZ,
  9948.          "Local command to run,\n",
  9949.          "with its standard input/output redirected to ",
  9950.          local ? ttname : "the communications connection",
  9951.          "\n"
  9952.          );
  9953.     if ((x = cmtxt(tmpbuf,"",&s,xxstring)) < 0)
  9954.       return(x);
  9955.         if (nopush) {
  9956.             printf("?REDIRECT disabled\n");
  9957.             return(success=0);
  9958.         }
  9959.     if (!local) {
  9960.         printf("?SET LINE or SET HOST required first\n");
  9961.         return(-9);
  9962.     }
  9963.     if (!*s) {
  9964.         printf("?REDIRECT requires a command to redirect\n");
  9965.         return(-9);
  9966.     }
  9967.     return(success = ttruncmd(s));
  9968.     }
  9969. #endif /* CK_REDIR */
  9970. #endif /* NOPUSH */
  9971.  
  9972. #ifndef NOSHOW
  9973.     if (cx == XXSHO) {            /* SHOW */
  9974.     x = cmkey(shotab,nsho,"","parameters",xxstring);
  9975.     if (x < 0) return(x);
  9976.     return(doshow(x));
  9977.     }
  9978. #endif /* NOSHOW */
  9979.  
  9980. #ifndef MAC
  9981.     if (cx == XXSPA) {            /* SPACE */
  9982. #ifdef IKSD
  9983.     if (inserver && !ENABLED(en_spa)) {
  9984.         printf("?Sorry, SPACE command disabled\n");
  9985.         return(-9);
  9986.     }
  9987. #endif /* IKSD */
  9988. #ifdef datageneral
  9989.     /* AOS/VS can take an argument after its "space" command. */
  9990.     if ((x = cmtxt("Confirm, or local directory name","",&s,xxstring)) < 0)
  9991.       return(x);
  9992.     if (nopush) {
  9993.         printf("?Sorry, SPACE command disabled\n");
  9994.         return(-9);
  9995.     } else if (*s == NUL) {
  9996.         xsystem(SPACMD);
  9997.     } else {
  9998.         ckmakmsg(line,LINBUFSIZ,"space ",s,NULL,NULL);
  9999.         xsystem(line);
  10000.     }
  10001. #else
  10002. #ifdef OS2
  10003.     if ((x = cmtxt("Press Enter for current disk,\n\
  10004.  or specify a disk letter like A:","",&s,xxstring)) < 0)
  10005.       return(x);
  10006.     if (*s == NUL) {        /* Current disk */
  10007.             unsigned long space = zdskspace(0);
  10008.             if (space > 0 && space < 1024)
  10009.               printf(" Free space: unknown\n");
  10010.             else
  10011.           printf(" Free space: %ldK\n", space/1024L);
  10012.     } else {
  10013.         int drive = toupper(*s);
  10014.             unsigned long space = zdskspace(drive - 'A' + 1);
  10015.             if (space > 0 && space < 1024)
  10016.               printf(" Drive %c: unknown free\n");
  10017.             else
  10018.               printf(" Drive %c: %ldK free\n", drive,space / 1024L);
  10019.     }
  10020. #else
  10021. #ifdef UNIXOROSK
  10022.     x = cmdir("Confirm for current disk,\n\
  10023.  or specify a disk device or directory","",&s,xxstring);
  10024.     if (x == -3)
  10025.       s = "";
  10026.     else if (x < 0)
  10027.       return(x);
  10028.         ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  10029.         s = tmpbuf;
  10030.     if ((x = cmcfm()) < 0) return(x);
  10031.     if (nopush) {
  10032.         printf("?Sorry, SPACE command disabled\n");
  10033.         return(-9);
  10034.     }
  10035.     if (!*s) {            /* Current disk */
  10036.         xsystem(SPACMD);
  10037.     } else {            /* Specified disk */
  10038.         ckmakmsg(line,LINBUFSIZ,SPACM2," ",s,NULL);
  10039.         xsystem(line);
  10040.     }
  10041. #else
  10042.     if ((x = cmcfm()) < 0) return(x);
  10043.     if (nopush) {
  10044.         printf("?Sorry, SPACE command disabled\n");
  10045.         return(-9);
  10046.     }
  10047.     xsystem(SPACMD);
  10048. #endif /* UNIXOROSK */
  10049. #endif /* OS2 */
  10050. #endif /* datageneral */
  10051.     return(success = 1);        /* Pretend it worked */
  10052.     }
  10053. #endif /* MAC */
  10054.  
  10055. #ifndef NOXFER
  10056.     if (cx == XXSTA) {            /* STATISTICS */
  10057.     if ((x = cmkey(stattab,2,"Carriage return, or option",
  10058.                "/brief",xxstring)) < 0)
  10059.       return(x);
  10060.     if ((y = cmcfm()) < 0) return(y);
  10061.     return(success = dostat(x));
  10062.     }
  10063. #endif /* NOXFER */
  10064.  
  10065.     if (cx == XXSTO || cx == XXEND) {    /* STOP, END, or POP */
  10066.     if ((y = cmnum("exit status code","0",10,&x,xxstring)) < 0)
  10067.       return(y);
  10068.     if ((y = cmtxt("Message to print","",&s,xxstring)) < 0)
  10069.       return(y);
  10070.     s = brstrip(s);
  10071.     if (*s) printf("%s\n",s);
  10072.     if (cx == XXSTO) {
  10073.         dostop();
  10074.     } else {
  10075.         doend(x);
  10076.     }
  10077.     return(success = (x == 0));
  10078.     }
  10079.     if (cx == XXSUS) {            /* SUSPEND */
  10080.     if ((y = cmcfm()) < 0) return(y);
  10081. #ifdef NOJC
  10082.     printf("Sorry, this version of Kermit cannot be suspended\n");
  10083. #else
  10084. #ifdef IKSD
  10085.     if (inserver) {
  10086.         printf("?Sorry, IKSD can not be suspended\n");
  10087.         return(-9);
  10088.     } else
  10089. #endif /* IKSD */
  10090.       if (nopush) {
  10091.         printf("?Sorry, access to system is disabled\n");
  10092.         return(-9);
  10093.     }
  10094.     stptrap(0);
  10095. #endif /* NOJC */
  10096.     return(0);
  10097.     }
  10098.  
  10099.     if (cx == XXTAK) {            /* TAKE */
  10100.     char * scriptenv = NULL;    
  10101. #ifdef OS2
  10102.         char * GetAppData(int);
  10103.     extern char startupdir[],exedir[],inidir[];
  10104.     char * keymapenv = NULL;
  10105.         char * appdata0 = NULL, *appdata1 = NULL;
  10106.     int xx;
  10107. #define TAKEPATHLEN 4096
  10108. #else /* OS2 */
  10109. #define TAKEPATHLEN 1024
  10110. #endif /* OS2 */
  10111.     char takepath[TAKEPATHLEN];
  10112.  
  10113.     if (tlevel >= MAXTAKE-1) {
  10114.         printf("?Take files nested too deeply\n");
  10115.         return(-9);
  10116.     }
  10117. #ifdef OS2
  10118. #ifdef NT
  10119.     scriptenv = getenv("K95SCRIPTS");
  10120.     keymapenv = getenv("K95KEYMAPS");
  10121.         makestr(&appdata0,(char *)GetAppData(0));
  10122.         makestr(&appdata1,(char *)GetAppData(1));
  10123. #else /* NT */
  10124.     scriptenv = getenv("K2SCRIPTS");
  10125.     keymapenv = getenv("K2KEYMAPS");
  10126. #endif /* NT */
  10127. #endif /* OS2 */
  10128.  
  10129.     if (!scriptenv)            /* Let this work for Unix etc too */
  10130.       scriptenv = getenv("CK_SCRIPTS"); /* Use this if defined */
  10131. #ifndef OS2
  10132.     if (!scriptenv)            /* Otherwise use home directory */
  10133.       scriptenv = homepath();
  10134. #endif /* OS2 */
  10135.     if (!scriptenv)
  10136.       scriptenv = "";
  10137.     ckstrncpy(takepath,scriptenv,TAKEPATHLEN);
  10138.     debug(F110,"TAKE initial takepath",takepath,0);
  10139.  
  10140. #ifdef OS2
  10141.     if (!keymapenv)
  10142.       keymapenv = getenv("CK_KEYMAPS");
  10143.     if (!keymapenv)
  10144.       keymapenv = "";
  10145.  
  10146.     ckstrncat(takepath,
  10147.           (scriptenv && scriptenv[strlen(scriptenv)-1]==';')?"":";",
  10148.           TAKEPATHLEN
  10149.           );
  10150.     ckstrncat(takepath,keymapenv?keymapenv:"",TAKEPATHLEN);
  10151.     ckstrncat(takepath,
  10152.           (keymapenv && keymapenv[strlen(keymapenv)-1]==';')?"":";",
  10153.           TAKEPATHLEN
  10154.           );
  10155.     ckstrncat(takepath,startupdir,TAKEPATHLEN);
  10156.     ckstrncat(takepath,";",TAKEPATHLEN);
  10157.     ckstrncat(takepath,startupdir,TAKEPATHLEN);
  10158.     ckstrncat(takepath,"SCRIPTS/;",TAKEPATHLEN);
  10159.     ckstrncat(takepath,startupdir,TAKEPATHLEN);
  10160.     ckstrncat(takepath,"KEYMAPS/;",TAKEPATHLEN);
  10161.  
  10162.     ckstrncat(takepath,appdata1,TAKEPATHLEN);
  10163.     ckstrncat(takepath,"Kermit 95/;",TAKEPATHLEN);
  10164.     ckstrncat(takepath,appdata1,TAKEPATHLEN);
  10165.     ckstrncat(takepath,"Kermit 95/SCRIPTS/;",TAKEPATHLEN);
  10166.     ckstrncat(takepath,appdata1,TAKEPATHLEN);
  10167.     ckstrncat(takepath,"Kermit 95/KEYMAPS/;",TAKEPATHLEN);
  10168.  
  10169.     ckstrncat(takepath,appdata0,TAKEPATHLEN);
  10170.     ckstrncat(takepath,"Kermit 95/;",TAKEPATHLEN);
  10171.     ckstrncat(takepath,appdata0,TAKEPATHLEN);
  10172.     ckstrncat(takepath,"Kermit 95/SCRIPTS/;",TAKEPATHLEN);
  10173.     ckstrncat(takepath,appdata0,TAKEPATHLEN);
  10174.     ckstrncat(takepath,"Kermit 95/KEYMAPS/;",TAKEPATHLEN);
  10175.  
  10176.     ckstrncat(takepath,inidir,TAKEPATHLEN);
  10177.     ckstrncat(takepath,";",TAKEPATHLEN);
  10178.     ckstrncat(takepath,inidir,TAKEPATHLEN);
  10179.     ckstrncat(takepath,"SCRIPTS/;",TAKEPATHLEN);
  10180.     ckstrncat(takepath,inidir,TAKEPATHLEN);
  10181.     ckstrncat(takepath,"KEYMAPS/;",TAKEPATHLEN);
  10182.  
  10183.     ckstrncat(takepath,zhome(),TAKEPATHLEN);
  10184.     ckstrncat(takepath,";",TAKEPATHLEN);
  10185.     ckstrncat(takepath,zhome(),TAKEPATHLEN);
  10186.     ckstrncat(takepath,"SCRIPTS/;",TAKEPATHLEN);
  10187.     ckstrncat(takepath,zhome(),TAKEPATHLEN);
  10188.     ckstrncat(takepath,"KEYMAPS/;",TAKEPATHLEN);
  10189.  
  10190.     ckstrncat(takepath,exedir,TAKEPATHLEN);
  10191.     ckstrncat(takepath,";",TAKEPATHLEN);
  10192.     ckstrncat(takepath,exedir,TAKEPATHLEN);
  10193.     ckstrncat(takepath,"SCRIPTS/;",TAKEPATHLEN);
  10194.     ckstrncat(takepath,exedir,TAKEPATHLEN);
  10195.     ckstrncat(takepath,"KEYMAPS/;",TAKEPATHLEN);
  10196. #endif /* OS2 */
  10197.     debug(F110,"TAKE final takepath",takepath,0);
  10198.  
  10199.     if ((y = cmifip("Commands from file",
  10200.             "",&s,&x,0,takepath,xxstring)) < 0) {
  10201.         if (y == -3) {
  10202.         printf("?A file name is required\n");
  10203.         return(-9);
  10204.         } else
  10205.           return(y);
  10206.     }
  10207.     if (x != 0) {
  10208.         printf("?Wildcards not allowed in command file name\n");
  10209.         return(-9);
  10210.     }
  10211.     ckstrncpy(line,s,LINBUFSIZ);
  10212.     debug(F110,"TAKE file",s,0);
  10213.     if (isdir(s)) {
  10214.         printf("?Can't execute a directory - \"%s\"\n", s);
  10215.         return(-9);
  10216.     }
  10217. #ifndef NOTAKEARGS
  10218.     {
  10219.         char * p;
  10220.         x = strlen(line);
  10221.         debug(F111,"TAKE args",line,x);
  10222.         p = line + x + 1;
  10223.         if ((y = cmtxt("Optional arguments","",&s,xxstring)) < 0)
  10224.           return(y);
  10225.         if (*s) {            /* Args given? */
  10226.         ckstrncpy(p,s,LINBUFSIZ-x-1);
  10227. #ifdef ZFNQFP
  10228.         zfnqfp(line,TMPBUFSIZ,tmpbuf);
  10229.         s = tmpbuf;
  10230. #else
  10231.         s = line;
  10232. #endif /* ZFNQFP */
  10233.         debug(F110,"TAKE filename",s,0);
  10234.         x = strlen(s);
  10235.         debug(F101,"TAKE new len",s,x);
  10236.  
  10237. #ifdef COMMENT
  10238. /*
  10239.   This was added in C-Kermit 7.0 to allow args to be passed from the TAKE
  10240.   command to the command file.  But it overwrites the current argument vector,
  10241.   which is at best surprising, and at worst unsafe.
  10242. */
  10243.         addmac("%0",s);        /* Define %0 = name of file */
  10244.         varnam[0] = '%';
  10245.         varnam[2] = '\0';
  10246.         debug(F110,"take arg 0",s,0);
  10247.         debug(F110,"take args",p,0);
  10248.         for (y = 1; y < 10; y++) { /* Clear current args %1..%9 */
  10249.             varnam[1] = (char) (y + '0');
  10250.             delmac(varnam,0);
  10251.         }
  10252.         xwords(p,MAXARGLIST,NULL,0); /* Assign new args */
  10253.         debug(F110,"take args",p,0);
  10254. #else
  10255. /*
  10256.   This method is used in 8.0.  If the TAKE command includes arguments, we
  10257.   insert an intermediate temporary macro between the current level; we pass
  10258.   the arguments to the macro and then the macro TAKEs the command file.
  10259.   If the user Ctrl-C's out of the TAKE file, some temporary macro definitions
  10260.   and other small malloc'd bits might be left behind.
  10261. */
  10262.         {
  10263.             char * q = NULL;
  10264.             char * r = NULL;
  10265.             int k, m;
  10266.             m = maclvl;
  10267.             q = (char *)malloc(x+24);
  10268.             if (q) {
  10269.             r = (char *)malloc(x+24);
  10270.             if (r) {
  10271.                 sprintf(q,"_file[%s](%d)",s,cmdlvl); /* safe */
  10272.                 sprintf(r,"take %s",s); /* safe */
  10273.                 k = addmac(q,r);
  10274.                 if (k > -1) {
  10275.                 dodo(k,p,0);
  10276.                 while (maclvl > m) {
  10277.                     sstate = (CHAR) parser(1);
  10278.                     if (sstate) proto();
  10279.                 }
  10280.                 }
  10281.                 k = delmac(q,0);
  10282.                 free(q);
  10283.                 free(r);
  10284.                 return(success);
  10285.             }
  10286.             }
  10287.         }
  10288.         return(success = 0);
  10289. #endif /* COMMENT */
  10290.         }
  10291.     }
  10292. #else
  10293.     if ((y = cmcfm()) < 0) return(y);
  10294. #endif /* NOTAKEARGS */
  10295.     return(success = dotake(line));
  10296.     }
  10297.  
  10298. #ifndef NOLOCAL
  10299. #ifdef OS2
  10300.     if (cx == XXVIEW) {            /* VIEW Only Terminal mode */
  10301.     viewonly = TRUE;
  10302.     success = doconect(0, 0);
  10303.     viewonly = FALSE;
  10304.     return success;
  10305.     }
  10306. #endif /* OS2 */
  10307.  
  10308. #ifdef NETCONN
  10309.     if (cx == XXTEL || cx == XXIKSD) {    /* TELNET */
  10310.     int x,z;
  10311. #ifdef OS2
  10312.     if (!tcp_avail) {
  10313.         printf("?Sorry, either TCP/IP is not available on this system or\n\
  10314. necessary DLLs did not load.  Use SHOW NETWORK to check network status.\n");
  10315.         success = 0;
  10316.         return(-9);
  10317.     } else
  10318. #endif /* OS2 */
  10319.       {
  10320.       x = nettype;            /* Save net type in case of failure */
  10321.       z = ttnproto;            /* Save protocol in case of failure */
  10322.       nettype = NET_TCPB;
  10323.       ttnproto = (cx == XXTEL) ? NP_TELNET : NP_KERMIT;
  10324.       if ((y = setlin(XYHOST,0,1)) <= 0) {
  10325.               nettype = x;        /* Failed, restore net type. */
  10326.               ttnproto = z;        /* and protocol */
  10327.               success = 0;
  10328.       }
  10329.       didsetlin++;
  10330.         }
  10331.     return(y);
  10332.     }
  10333.  
  10334. #ifndef PTYORPIPE
  10335. #ifdef NETCMD
  10336. #define PTYORPIPE
  10337. #else
  10338. #ifdef NETPTY
  10339. #define PTYORPIPE
  10340. #endif /* NETPTY */
  10341. #endif /* NETCMD */
  10342. #endif /* PTYORPIPE */
  10343.  
  10344. #ifdef PTYORPIPE
  10345.     if (cx == XXPIPE || cx == XXPTY) {    /* PIPE or PTY */
  10346.     int x;
  10347.     extern int netsave;
  10348.     x = nettype;            /* Save net type in case of failure */
  10349.     nettype = (cx == XXPIPE) ? NET_CMD : NET_PTY;
  10350.     if ((y = setlin(XYHOST,0,1)) < 0) {
  10351.         nettype = x;        /* Failed, restore net type. */
  10352.         ttnproto = z;        /* and protocol */
  10353.         success = 0;
  10354.     }
  10355.     didsetlin++;
  10356.     netsave = x;
  10357.     return(y);
  10358.     }
  10359. #endif /* PTYORPIPE */
  10360.  
  10361. #ifdef ANYSSH
  10362.     if (cx == XXSSH) {            /* SSH (Secure Shell) */
  10363.     extern int netsave;
  10364. #ifdef SSHBUILTIN
  10365.     int k, x, havehost = 0, trips = 0;
  10366.         int    tmpver = -1, tmpxfw = -1;
  10367. #ifndef SSHTEST
  10368.         extern int sl_ssh_xfw, sl_ssh_xfw_saved;
  10369.         extern int sl_ssh_ver, sl_ssh_ver_saved;
  10370. #endif /* SSHTEST */
  10371.         extern int mdmtyp, mdmsav, cxtype, sl_uid_saved;
  10372.         extern char * slmsg;
  10373.     extern char uidbuf[], sl_uidbuf[];
  10374.         extern char pwbuf[], * g_pswd;
  10375.         extern int pwflg, pwcrypt, g_pflg, g_pcpt, nolocal;
  10376.     struct FDB sw, kw, fl;
  10377.  
  10378.         if (ssh_tmpstr)
  10379.       memset(ssh_tmpstr,0,strlen(ssh_tmpstr));
  10380.         makestr(&ssh_tmpstr,NULL);
  10381.         makestr(&ssh_tmpuid,NULL);
  10382.         makestr(&ssh_tmpcmd,NULL);
  10383.         makestr(&ssh_tmpport,NULL);
  10384.  
  10385.     cmfdbi(&kw,            /* 1st FDB - commands */
  10386.            _CMKEY,            /* fcode */
  10387.            "host [ port ],\n or action",    /* hlpmsg */
  10388.            "",            /* default */
  10389.            "",            /* addtl string data */
  10390.            nsshcmd,            /* addtl numeric data 1: tbl size */
  10391.            0,            /* addtl numeric data 2: 0 = keyword */
  10392.            xxstring,        /* Processing function */
  10393.            sshkwtab,        /* Keyword table */
  10394.            &fl            /* Pointer to next FDB */
  10395.            );
  10396.     cmfdbi(&fl,            /* Host */
  10397.            _CMFLD,            /* fcode */
  10398.            "",            /* hlpmsg */
  10399.            "",            /* default */
  10400.            "",            /* addtl string data */
  10401.            0,            /* addtl numeric data 1 */
  10402.            0,            /* addtl numeric data 2 */
  10403.            xxstring,
  10404.            NULL,
  10405.            NULL
  10406.            );
  10407.  
  10408.     x = cmfdb(&kw);
  10409.     if (x == -3) {
  10410.         printf("?ssh what?\n");
  10411.         return(-9);
  10412.     }
  10413.     if (x < 0)
  10414.       return(x);
  10415.     havehost = 0;
  10416.     if (cmresult.fcode == _CMFLD) {
  10417.         havehost = 1;
  10418.         ckstrncpy(line,cmresult.sresult,LINBUFSIZ); /* Hostname */
  10419.         cmresult.nresult = XSSH_OPN;
  10420.     }
  10421.     switch (cmresult.nresult) {    /* SSH keyword */
  10422.       case XSSH_OPN:        /* SSH OPEN */
  10423.         if (!havehost) {
  10424.         if ((x = cmfld("Host","",&s,xxstring)) < 0)
  10425.           return(x);
  10426.         ckstrncpy(line,s,LINBUFSIZ);
  10427.         }
  10428.         /* Parse [ port ] [ switches ] */
  10429.         cmfdbi(&kw,            /* Switches */
  10430.            _CMKEY,
  10431.            "Port number or service name,\nor switch",
  10432.            "",
  10433.            "",
  10434.            nsshopnsw,
  10435.            4,
  10436.            xxstring,
  10437.            sshopnsw,
  10438.            &fl
  10439.            );
  10440.         cmfdbi(&fl,            /* Port number or service name */
  10441.            _CMFLD,
  10442.            "",
  10443.            "",
  10444.            "",
  10445.            0,
  10446.            0,
  10447.            xxstring,
  10448.            NULL,
  10449.            NULL
  10450.            );
  10451.         trips = 0;            /* Explained below */
  10452.         while (1) {            /* Parse port and switches */
  10453.         x = cmfdb(&kw);        /* Get a field */
  10454.         if (x == -3)        /* User typed CR so quit from loop */
  10455.           break;
  10456.         if (x < 0)        /* Other parse error, pass it back */
  10457.           return(x);
  10458.         switch (cmresult.fcode) { /* Field or Keyword? */
  10459.                   case _CMFLD:          /* Field */
  10460.                     makestr(&ssh_tmpport,cmresult.sresult);
  10461.             break;
  10462.           case _CMKEY:        /* Keyword */
  10463.             switch (cmresult.nresult) {    /* Which one? */
  10464.               case SSHSW_USR:            /* /USER: */
  10465.             if (!cmgbrk()) {
  10466.                 printf("?This switch requires an argument\n");
  10467.                 return(-9);
  10468.             }
  10469.             if ((y = cmfld("Username","",&s,xxstring)) < 0)
  10470.               return(y);
  10471.             s = brstrip(s);
  10472.             makestr(&ssh_tmpuid,s);
  10473.             break;
  10474.                       case SSHSW_PWD:
  10475.             if (!cmgbrk()) {
  10476.                 printf("?This switch requires an argument\n");
  10477.                 return(-9);
  10478.             }
  10479.             debok = 0;
  10480.             if ((x = cmfld("Password","",&s,xxstring)) < 0) {
  10481.                 if (x == -3) {
  10482.                 makestr(&ssh_tmpstr,"");
  10483.                 } else {
  10484.                 return(x);
  10485.                 }
  10486.             } else {
  10487.                 s = brstrip(s);
  10488.                 if ((x = (int)strlen(s)) > PWBUFL) {
  10489.                 makestr(&slmsg,"Internal error");
  10490.                 printf("?Sorry, too long - max = %d\n",PWBUFL);
  10491.                 return(-9);
  10492.                 }
  10493.                 makestr(&ssh_tmpstr,s);
  10494.             }
  10495.             break;
  10496.  
  10497.               case SSHSW_VER:
  10498.             if ((x = cmnum("Number","",10,&z,xxstring)) < 0)
  10499.               return(x);
  10500.             if (z < 1 || z > 2) {
  10501.                 printf("?Out of range: %d\n",z);
  10502.                 return(-9);
  10503.             }
  10504.                         tmpver = z;
  10505.             break;
  10506.               case SSHSW_CMD:
  10507.               case SSHSW_SUB:
  10508.             if ((x = cmfld("Text","",&s,xxstring)) < 0)
  10509.               return(x);
  10510.                         makestr(&ssh_tmpcmd,s);
  10511.             ssh_cas = (cmresult.nresult == SSHSW_SUB);
  10512.             break;
  10513.               case SSHSW_X11:
  10514.             if ((x = cmkey(onoff,2,"","on",xxstring)) < 0)
  10515.               return(x);
  10516.                         tmpxfw = x;
  10517.             break;
  10518.               default:
  10519.                 return(-2);
  10520.             }
  10521.         }
  10522.         if (trips++ == 0) {    /* After first time through */
  10523.             cmfdbi(&kw,        /* only parse switches, not port. */
  10524.                _CMKEY,
  10525.                "Switch",
  10526.                "",
  10527.                "",
  10528.                nsshopnsw,
  10529.                4,
  10530.                xxstring,
  10531.                sshopnsw,
  10532.                NULL
  10533.                );
  10534.         }
  10535.         }
  10536.         if ((x = cmcfm()) < 0)    /* Get confirmation */
  10537.           return(x);
  10538.             if (clskconnx(1) < 0) {    /* Close current Kermit connection */
  10539.               if ( ssh_tmpstr ) {
  10540.                   memset(ssh_tmpstr,0,strlen(ssh_tmpstr));
  10541.                   makestr(&ssh_tmpstr,NULL);
  10542.               }
  10543.               return(success = 0);
  10544.             }
  10545.         makestr(&ssh_hst,line);    /* Stash everything */
  10546.         if (ssh_tmpuid) {
  10547.                 if (!sl_uid_saved) {
  10548.                     ckstrncpy(sl_uidbuf,uidbuf,UIDBUFLEN);
  10549.                     sl_uid_saved = 1;
  10550.                 }
  10551.         ckstrncpy(uidbuf,ssh_tmpuid,UIDBUFLEN);
  10552.         makestr(&ssh_tmpuid,NULL);
  10553.         }
  10554.             if (ssh_tmpport) {
  10555.                 makestr(&ssh_prt,ssh_tmpport);
  10556.                 makestr(&ssh_tmpport,NULL);
  10557.             } else
  10558.                 makestr(&ssh_prt,NULL);
  10559.  
  10560.             if (ssh_tmpcmd) {
  10561.                 makestr(&ssh_cmd,brstrip(ssh_tmpcmd));
  10562.                 makestr(&ssh_tmpcmd,NULL);
  10563.             } else
  10564.                 makestr(&ssh_cmd,NULL);
  10565.  
  10566.             if (tmpver > -1) {
  10567. #ifndef SSHTEST
  10568.                 if (!sl_ssh_ver_saved) {
  10569.                     sl_ssh_ver = ssh_ver;
  10570.                     sl_ssh_ver_saved = 1;
  10571.                 }
  10572. #endif /* SSHTEST */
  10573.                 ssh_ver = tmpver;
  10574.             }
  10575.             if (tmpxfw > -1) {
  10576. #ifndef SSHTEST
  10577.                 if (!sl_ssh_xfw_saved) {
  10578.                     sl_ssh_xfw = ssh_xfw;
  10579.                     sl_ssh_xfw_saved = 1;
  10580.                 }
  10581. #endif /* SSHTEST */
  10582.                 ssh_xfw = tmpxfw;
  10583.             }
  10584.         if (ssh_tmpstr) {
  10585.         if (ssh_tmpstr[0]) {
  10586.             ckstrncpy(pwbuf,ssh_tmpstr,PWBUFL+1);
  10587.             pwflg = 1;
  10588.             pwcrypt = 0;
  10589.         } else
  10590.           pwflg = 0;
  10591.         makestr(&ssh_tmpstr,NULL);
  10592.         }
  10593.         nettype = NET_SSH;
  10594.         if (mdmsav < 0)
  10595.           mdmsav = mdmtyp;
  10596.         mdmtyp = -nettype;
  10597.         x = 1;
  10598.  
  10599. #ifndef NOSPL
  10600.             makestr(&g_pswd,pwbuf);             /* Save global pwbuf */
  10601.             g_pflg = pwflg;                     /* and flag */
  10602.             g_pcpt = pwcrypt;
  10603. #endif /* NOSPL */
  10604.  
  10605.         /* Line parameter to ttopen() is ignored */
  10606.         debug(F110,"SSH line",line,0);
  10607.         k = ttopen(line,&x,mdmtyp, 0);
  10608.         if (k < 0) {
  10609.         printf("?Unable to connect to %s\n",ssh_hst);
  10610.         mdmtyp = mdmsav;
  10611.                 slrestor();
  10612.         return(success = 0);
  10613.         }
  10614.         duplex = 0;             /* Remote echo */
  10615.         ckstrncpy(ttname,line,TTNAMLEN); /* Record the command */
  10616.         debug(F110,"ssh ttname",ttname,0);
  10617.         makestr(&slmsg,NULL);    /* No SET LINE error message */
  10618.         cxtype = CXT_SSH;
  10619. #ifndef NODIAL
  10620.         dialsta = DIA_UNK;
  10621. #endif /* NODIAL */
  10622.         success = 1;        /* SET LINE succeeded */
  10623.         network = 1;        /* Network connection (not serial) */
  10624.         local = 1;            /* Local mode (not remote) */
  10625.         if ((reliable != SET_OFF || !setreliable))
  10626.           reliable = SET_ON;    /* Transport is reliable end to end */
  10627. #ifdef OS2
  10628.             DialerSend(OPT_KERMIT_CONNECT, 0);
  10629. #endif /* OS2 */
  10630.         setflow();            /* Set appropriate flow control */
  10631.  
  10632.         haveline = 1;
  10633. #ifdef CKLOGDIAL
  10634. #ifdef NETCONN
  10635.         dolognet();
  10636. #endif /* NETCONN */
  10637. #endif /* CKLOGDIAL */
  10638.  
  10639. #ifndef NOSPL
  10640.         if (local) {
  10641.         if (nmac) {        /* Any macros defined? */
  10642.             int k;        /* Yes */
  10643.             k = mlook(mactab,"on_open",nmac); /* Look this up */
  10644.             if (k >= 0) {                  /* If found, */
  10645.             if (dodo(k,ssh_hst,0) > -1)   /* set it up, */
  10646.               parser(1);              /* and execute it */
  10647.             }
  10648.         }
  10649.         }
  10650. #endif /* NOSPL */
  10651. #ifdef LOCUS        
  10652.         if (autolocus)
  10653.         setlocus(1,1);
  10654. #endif /* LOCUS */
  10655.  
  10656.     /* Command was confirmed so we can pre-pop command level. */
  10657.     /* This is so CONNECT module won't think we're executing a */
  10658.     /* script if CONNECT was the final command in the script. */
  10659.         if (cmdlvl > 0)
  10660.           prepop();
  10661.         success = doconect(0,cmdlvl == 0 ? 1 : 0);
  10662.         if (ttchk() < 0)
  10663.           dologend();
  10664.         return(success);
  10665.  
  10666.       case XSSH_CLR:
  10667.         if ((y = cmkey(sshclr,nsshclr,"","", xxstring)) < 0) {
  10668.             if (y == -3) {
  10669.             printf("?clear what?\n");
  10670.             return(-9);
  10671.         }
  10672.             return(y);
  10673.         }
  10674.         if ((x = cmcfm()) < 0)
  10675.           return(x);
  10676.         switch (y) {
  10677.           case SSHC_LPF:
  10678.                 ssh_pf_lcl_n = 0;
  10679.         break;
  10680.           case SSHC_RPF:
  10681.         ssh_pf_rmt_n = 0;
  10682.         break;
  10683.           default:
  10684.         return(-2);
  10685.         }
  10686.             return(success = 1);    /* or whatever */
  10687.  
  10688.       case XSSH_AGT: {        /* SSH AGENT */
  10689.           int doeach = 0;
  10690.           if ((y = cmkey(sshagent,nsshagent,"","",xxstring)) < 0)
  10691.         return(y);
  10692.           switch (y) {
  10693.         case SSHA_ADD:        /* SSH AGENT ADD ... */
  10694.           if ((x = cmifi("Identity file","",&s,&y,xxstring)) < 0) {
  10695. #ifndef SSHTEST
  10696.               if (x == -3)    /* No name given */
  10697.             doeach = 1;    /* so do them all */
  10698.               else
  10699. #endif /* SSHTEST */
  10700.             return(x);
  10701.           }
  10702.           ckstrncpy(line,s,LINBUFSIZ);
  10703.           if ((x = cmcfm()) < 0)
  10704.             return(x);
  10705. #ifdef SSHTEST
  10706.           x = 0;
  10707. #else
  10708.           if (doeach) {
  10709.                       int i;
  10710.                       x = 0;
  10711.                       for (i = 0; i < ssh_idf_n; i++)
  10712.             x += ssh_agent_add_file(ssh_idf[i]);
  10713.           } else
  10714.             x = ssh_agent_add_file(line);
  10715. #endif /* SSHTEST */
  10716.           return(success = (x == 0));
  10717.  
  10718.         case SSHA_DEL: {    /* SSH AGENT DELETE ... */
  10719.             int doall = 0;
  10720.             if ((x = cmifi("Identity file","",&s,&y,xxstring)) < 0) {
  10721. #ifndef SSHTEST
  10722.             if (x == -3)    /* No name given */
  10723.               doall = 1;    /* so do them all */
  10724.             else
  10725. #endif /* SSHTEST */
  10726.               return(x);
  10727.             }
  10728.             ckstrncpy(line,s,LINBUFSIZ);
  10729.             if ((x = cmcfm()) < 0)
  10730.               return(x);
  10731. #ifdef SSHTEST
  10732.             x = 0;
  10733. #else
  10734.             if (doall)
  10735.               x = ssh_agent_delete_all();
  10736.             else
  10737.               x = ssh_agent_delete_file(line);
  10738. #endif /* SSHTEST */
  10739.             return(success = (x == 0));
  10740.         }
  10741.         case SSHA_LST: {
  10742.             int fingerprint = 0;
  10743.             if ((y = cmswi(sshagtsw,nsshagtsw,"","",xxstring)) < 0) {
  10744.             if (y != -3)
  10745.               return(y);
  10746.             } else if (cmgbrk() > SP) {
  10747.             printf("?This switch does not take an argument\n");
  10748.             return(-9);
  10749.             } else if (y == SSHASW_FP) {
  10750.             fingerprint = 1;
  10751.             }
  10752.             if ((x = cmcfm()) < 0)
  10753.               return(x);
  10754. #ifdef SSHTEST
  10755.             return(success = 1);
  10756. #else
  10757.             return(success =
  10758.                (ssh_agent_list_identities(fingerprint) == 0));
  10759. #endif /* SSHTEST */
  10760.         }
  10761.         default:
  10762.           return(-2);
  10763.           }
  10764.       }
  10765.       case XSSH_ADD: {        /* SSH ADD */
  10766.           /* ssh add { local, remote } port host port */
  10767.           int cx, i, j, k;
  10768.           char * h;
  10769.           if ((cx = cmkey(addfwd,naddfwd,"","", xxstring)) < 0)
  10770.         return(cx);
  10771.           if ((x = cmnum((cx == SSHF_LCL) ?
  10772.                  "Local port number" : "Remote port number",
  10773.                  "",10,&j,xxstring)) < 0)
  10774.         return(x);
  10775.           if ((x = cmfld("Host","",&s,xxstring)) < 0)
  10776.         return(x);
  10777.           makestr(&h,s);
  10778.           if ((x = cmnum("Port","",10,&k,xxstring)) < 0)
  10779.         return(x);
  10780.           if ((x = cmcfm()) < 0)
  10781.         return(x);
  10782.  
  10783.           switch(cx) {
  10784.         case SSHF_LCL:
  10785.            if (ssh_pf_lcl_n == 32) {
  10786.                printf(
  10787. "?Maximum number of local port forwardings already specified\n"
  10788.                  );
  10789.                free(h);
  10790.                return(success = 0);
  10791.           }
  10792.           ssh_pf_lcl[ssh_pf_lcl_n].p1 = j;
  10793.           makestr(&(ssh_pf_lcl[ssh_pf_lcl_n].host),h);
  10794.           makestr(&h,NULL);
  10795.           ssh_pf_lcl[ssh_pf_lcl_n].p2 = k;
  10796.           ssh_pf_lcl_n++;
  10797.           break;
  10798.         case SSHF_RMT:
  10799.           if (ssh_pf_rmt_n == 32) {
  10800.               printf(
  10801. "?Maximum number of remote port forwardings already specified\n"
  10802.                 );
  10803.               free(h);
  10804.               return(success = 0);
  10805.           }
  10806.           ssh_pf_rmt[ssh_pf_rmt_n].p1 = j;
  10807.           makestr(&(ssh_pf_rmt[ssh_pf_rmt_n].host),h);
  10808.           makestr(&h,NULL);
  10809.           ssh_pf_rmt[ssh_pf_rmt_n].p2 = k;
  10810.           ssh_pf_rmt_n++;
  10811.           }
  10812.           return(success = 1);
  10813.       }
  10814.       /* Not supporting arbitrary forwarding yet */
  10815.       case XSSH_FLP:        /* SSH FORWARD-LOCAL-PORT */
  10816.       case XSSH_FRP: {        /* SSH FORWARD-REMOTE-PORT */
  10817.           int li_port = 0;
  10818.           int to_port = 0;
  10819.           char * fw_host = NULL;
  10820.           int n;
  10821.               if ((x = cmnum(cmresult.nresult == XSSH_FLP ?
  10822.                               "local-port":"remote-port",
  10823.                               "",10,&li_port,xxstring)) < 0)
  10824.                   return(x);
  10825.               if (li_port < 1 || li_port > 65535) {
  10826.                   printf("?Out range - min: 1, max: 65535\n");
  10827.                   return(-9);
  10828.               }
  10829.           if ((x = cmfld("host",ssh_hst?ssh_hst:"",&s,xxstring)) < 0)
  10830.         return(x);
  10831.               n = ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  10832.               fw_host = tmpbuf;
  10833.               if ((x = cmnum("host-port",ckuitoa(li_port),10,
  10834.                               &to_port,xxstring)) < 0)
  10835.                   return(x);
  10836.               if (to_port < 1 || to_port > 65535) {
  10837.                   printf("?Out range - min: 1, max: 65535\n");
  10838.                   return(-9);
  10839.               }
  10840.           if ((x = cmcfm()) < 0)
  10841.         return(x);
  10842.           switch (cmresult.nresult) {
  10843.                 case XSSH_FLP:    /* SSH FORWARD-LOCAL-PORT */
  10844. #ifndef SSHTEST
  10845.                   ssh_fwd_local_port(li_port,fw_host,to_port);
  10846. #endif /* SSHTEST */
  10847.           return(success = 1);
  10848.         case XSSH_FRP:    /* SSH FORWARD-REMOTE-PORT */
  10849. #ifndef SSHTEST
  10850.                   ssh_fwd_remote_port(li_port,fw_host,to_port);
  10851. #endif /* SSHTEST */
  10852.           return(success = 1);
  10853.           }
  10854.           return(success = 1);
  10855.       }
  10856.     case XSSH_V2:        /* SSH V2 */
  10857.       if ((cx = cmkey(ssh2tab,nssh2tab,"","", xxstring)) < 0)
  10858.         return(cx);
  10859.       switch (cx) {
  10860.         case XSSH2_RKE:
  10861.           if ((x = cmcfm()) < 0)
  10862.         return(x);
  10863. #ifndef SSHTEST
  10864.           ssh_v2_rekey();
  10865. #endif /* SSHTEST */
  10866.           return(success = 1);
  10867.         default:
  10868.           return(-2);
  10869.       }
  10870.     case XSSH_KEY:
  10871.       if ((cx = cmkey(sshkey,nsshkey,"","", xxstring)) < 0)
  10872.         return(cx);
  10873.       switch (cx) {
  10874.         case SSHK_PASS: {    /* Change passphrase */
  10875.           char * oldp = NULL, * newp = NULL;
  10876.           struct FDB df, sw;
  10877.           cmfdbi(&sw,
  10878.              _CMKEY,        /* fcode */
  10879.              "Filename, or switch", /* hlpmsg */
  10880.              "",        /* default */
  10881.              "",        /* addtl string data */
  10882.              2,            /* addtl numeric data 1: tbl size */
  10883.              4,            /* addtl numeric data 2: 4 = cmswi */
  10884.              xxstring,        /* Processing function */
  10885.              sshkpsw,        /* Keyword table */
  10886.              &df        /* Pointer to next FDB */
  10887.              );
  10888.           cmfdbi(&df,        /* 2nd FDB - file for display */
  10889.              _CMIFI,        /* output file */
  10890.              "",        /* hlpmsg */
  10891.              "",        /* default */
  10892.              "",        /* addtl string data */
  10893.              0,            /* addtl numeric data 1 */
  10894.              0,            /* addtl numeric data 2 */
  10895.              xxstring,
  10896.              NULL,
  10897.              NULL
  10898.              );
  10899.           line[0] = NUL;
  10900.  
  10901.           while (1) {
  10902.           x = cmfdb(&sw);
  10903.           if (x == -3) break;
  10904.           if (x < 0)
  10905.             return(x);
  10906.           if (cmresult.fcode != _CMKEY)
  10907.             break;
  10908.           if (!cmgbrk()) {
  10909.               printf("?This switch requires an argument\n");
  10910.               return(-9);
  10911.           }
  10912.           if ((y = cmfld("Passphrase","",&s,xxstring)) < 0)
  10913.             return(y);
  10914.           switch (cmresult.nresult) {
  10915.             case 1:        /* Old */
  10916.               makestr(&oldp,s);
  10917.               break;
  10918.             case 2:        /* New */
  10919.               makestr(&newp,s);
  10920.           }
  10921.           }
  10922.           if (cmresult.fcode == _CMIFI) { /* Filename */
  10923.           ckstrncpy(line,cmresult.sresult,LINBUFSIZ);
  10924.           if (zfnqfp(line,TMPBUFSIZ,tmpbuf))
  10925.             ckstrncpy(line,tmpbuf,LINBUFSIZ);
  10926.           }
  10927.           if ((x = cmcfm()) < 0) return(x);
  10928.  
  10929. #ifndef SSHTEST
  10930.           x = sshkey_change_passphrase(line[0] ? line : NULL,
  10931.                          oldp, newp);
  10932. #endif /* SSHTEST */
  10933.           makestr(&oldp,NULL);
  10934.           makestr(&newp,NULL);
  10935.           success = (x == 0);
  10936.           return(success);
  10937.         }
  10938.         case SSHK_CREA: {    /* SSH KEY CREATE /switches... */
  10939.           int bits = 1024, keytype = SSHKT_2R;
  10940.           char * pass = NULL, * comment = NULL;
  10941.           struct FDB df, sw;
  10942.  
  10943.               /*
  10944.                * char * sshkey_default_file(int keytype) 
  10945.                * will provide the default filename for a given keytype
  10946.                * is it possible to have the default value for the 2nd
  10947.                * FDB set and changed when a /TYPE switch is provided?
  10948.                * Would this allow for tab completion of the filename?
  10949.                */
  10950.           cmfdbi(&sw,
  10951.              _CMKEY,        /* fcode */
  10952.              "Filename, or switch", /* hlpmsg */
  10953.              "",        /* default */
  10954.              "",        /* addtl string data */
  10955.              nsshkcrea,        /* addtl numeric data 1: tbl size */
  10956.              4,            /* addtl numeric data 2: 4 = cmswi */
  10957.              xxstring,        /* Processing function */
  10958.              sshkcrea,        /* Keyword table */
  10959.              &df        /* Pointer to next FDB */
  10960.              );
  10961.           cmfdbi(&df,        /* 2nd FDB - file for display */
  10962.              _CMOFI,        /* output file */
  10963.              "",        /* hlpmsg */
  10964.              "",        /* default */
  10965.              "",        /* addtl string data */
  10966.              0,            /* addtl numeric data 1 */
  10967.              0,            /* addtl numeric data 2 */
  10968.              xxstring,
  10969.              NULL,
  10970.              NULL
  10971.              );
  10972.           line[0] = NUL;
  10973.  
  10974.           while (1) {
  10975.           x = cmfdb(&sw);
  10976.           if (x == -3) break;
  10977.           if (x < 0)
  10978.             return(x);
  10979.           if (cmresult.fcode != _CMKEY)
  10980.             break;
  10981.           if (!cmgbrk()) {
  10982.               printf("?This switch requires an argument\n");
  10983.               return(-9);
  10984.           }
  10985.           switch (cmresult.nresult) {
  10986.             case SSHKC_BI:    /* /BITS:n */
  10987.               if ((y = cmnum("","1024",10,&z,xxstring)) < 0)
  10988.             return(y);
  10989.               if (z < 512 || z > 4096) {
  10990.               printf("?Out range - min: 512, max: 4096\n");
  10991.               return(-9);
  10992.               }
  10993.               bits = z;
  10994.               break;
  10995.             case SSHKC_PP:    /* /PASSPHRASE:blah */
  10996.               if ((y = cmfld("Passphrase","",&s,xxstring)) < 0)
  10997.             return(y);
  10998.               makestr(&pass,s);
  10999.               break;
  11000.             case SSHKC_TY:    /* /TYPE:keyword */
  11001.               if ((y = cmkey(sshkcty,nsshkcty,"",
  11002.                      "v2-rsa",xxstring)) < 0)
  11003.             return(y);
  11004.               keytype = y;
  11005.               break;
  11006.             case SSHKC_1R:    /* /COMMENT */
  11007.               if ((y = cmfld("Text","",&s,xxstring)) < 0)
  11008.             return(y);
  11009.               makestr(&comment,s);
  11010.               break;
  11011.           }
  11012.           }
  11013.           if (cmresult.fcode == _CMOFI) { /* Filename */
  11014.                   if (cmresult.sresult) {
  11015.                       ckstrncpy(line,cmresult.sresult,LINBUFSIZ);
  11016.                       if (zfnqfp(line,TMPBUFSIZ,tmpbuf))
  11017.                           ckstrncpy(line,tmpbuf,LINBUFSIZ);
  11018.           }
  11019.           }
  11020.           if ((y = cmcfm()) < 0) /* Confirm */
  11021.         return(y);
  11022. #ifndef SSHTEST
  11023.           x = sshkey_create(line[0] ? line : NULL,
  11024.                 bits, pass, keytype, comment);
  11025.           if (pass)
  11026.         memset(pass,0,strlen(pass));
  11027. #endif /* SSHTEST */
  11028.           makestr(&pass,NULL);
  11029.           makestr(&comment,NULL);
  11030.           return(success = (x == 0));
  11031.         }
  11032.         case SSHK_DISP: {    /* SSH KEY DISPLAY /switches... */
  11033.           char c;
  11034.           int infmt = 0, outfmt = 0;
  11035.           struct FDB df, sw;
  11036.           cmfdbi(&sw,
  11037.              _CMKEY,        /* fcode */
  11038.              "Filename, or switch", /* hlpmsg */
  11039.              "",        /* default */
  11040.              "",        /* addtl string data */
  11041.              nsshdswi,        /* addtl numeric data 1: tbl size */
  11042.              4,            /* addtl numeric data 2: 4 = cmswi */
  11043.              xxstring,        /* Processing function */
  11044.              sshdswi,        /* Keyword table */
  11045.              &df        /* Pointer to next FDB */
  11046.              );
  11047.           cmfdbi(&df,        /* 2nd FDB - file for display */
  11048.              _CMIFI,        /* fcode */
  11049.              "",        /* hlpmsg */
  11050.              "",        /* default */
  11051.              "",        /* addtl string data */
  11052.              0,            /* addtl numeric data 1 */
  11053.              0,            /* addtl numeric data 2 */
  11054.              xxstring,
  11055.              NULL,
  11056.              NULL
  11057.              );
  11058.           line[0] = NUL;
  11059.  
  11060.           while (1) {
  11061.           x = cmfdb(&sw);
  11062.           if (x == -3) break;
  11063.           if (x < 0)
  11064.             return(x);
  11065.           if (cmresult.fcode != _CMKEY)
  11066.             break;
  11067.           if (!cmgbrk()) {
  11068.               printf("?This switch requires an argument\n");
  11069.               return(-9);
  11070.           }
  11071.           switch (cmresult.nresult) {
  11072. #ifdef COMMENT
  11073.             case SSHKD_IN:    /* /IN-FORMAT: */
  11074.               if ((y = cmkey(sshdifmt,nsshdifmt,
  11075.                      "","",xxstring)) < 0)
  11076.             return(y);
  11077.               infmt = y;
  11078.               break;
  11079. #endif /* COMMENT */
  11080.             case SSHKD_OUT:    /* /FORMAT: */
  11081.               if ((y = cmkey(sshdofmt,nsshdofmt,
  11082.                      "","",xxstring)) < 0)
  11083.             return(y);
  11084.               outfmt = y;
  11085.               break;
  11086.           }
  11087.           }
  11088.           if (cmresult.fcode == _CMIFI) { /* Filename */
  11089.           ckstrncpy(line,cmresult.sresult,LINBUFSIZ);
  11090.           if (zfnqfp(line,TMPBUFSIZ,tmpbuf))
  11091.             ckstrncpy(line,tmpbuf,LINBUFSIZ);
  11092.           }
  11093. #ifdef COMMENT
  11094.           if (!line[0]) {
  11095.           printf("?Key filename required\n");
  11096.           return(-9);
  11097.           }
  11098. #endif /* COMMENT */
  11099.           if ((y = cmcfm()) < 0) /* Confirm */
  11100.         return(y);
  11101. #ifndef SSHTEST
  11102.           switch (outfmt) {
  11103.         case SKDF_OSSH:
  11104.                   /* 2nd param is optional passphrase */
  11105.           x = sshkey_display_public(line[0] ? line : NULL, NULL);
  11106.           break;
  11107.         case SKDF_SSHC:
  11108.                   /* 2nd param is optional passphrase */
  11109.           x = sshkey_display_public_as_ssh2(line[0] ? line : NULL,
  11110.                             NULL);
  11111.           break;
  11112.         case SKDF_IETF:
  11113.           x = sshkey_display_fingerprint(line[0] ? line : NULL, 1);
  11114.           break;
  11115.         case SKDF_FING:
  11116.           x = sshkey_display_fingerprint(line[0] ? line : NULL, 0);
  11117.           break;
  11118.           }
  11119. #endif /* SSHTEST */
  11120.           return(success = (x == 0));
  11121.         }
  11122.         case SSHK_V1:        /* SSH KEY V1 SET-COMMENT */
  11123.           if ((x = cmkey(sshkv1,1,"","set-comment", xxstring)) < 0)
  11124.         return(x);
  11125.           if (x != 1) return(-2);
  11126.           if ((x = cmifi("Key file name","",&s,&y,xxstring)) < 0) {
  11127.           if (x == -3) {
  11128.               printf("?Name of key file required\n");
  11129.               return(-9);
  11130.           }
  11131.           }
  11132.           ckstrncpy(line,s,LINBUFSIZ);
  11133.           if ((x = cmtxt("Comment text","",&s,xxstring)) < 0)
  11134.         return(x);
  11135. #ifndef SSHTEST
  11136.           x = sshkey_v1_change_comment(line,  /* filename */
  11137.                        s,     /* new comment */
  11138.                        NULL   /* passphrase */
  11139.                        );
  11140. #endif /* SSHTEST */
  11141.           success = (x == 0);
  11142.           return(success);
  11143.       }
  11144.       default:
  11145.         return(-2);
  11146.     }
  11147. #else  /* SSHBUILTIN */
  11148. #ifdef SSHCMD
  11149.     x = nettype;
  11150.     if ((y = setlin(XXSSH,0,1)) < 0) {
  11151.         if (errno)
  11152.           printf("?%s\n",ck_errstr());
  11153.             else
  11154. #ifdef COMMENT
  11155.         /* This isn't right either because it catches command editing */
  11156.           printf("?Sorry, pseudoterminal open failed\n");
  11157.             if (hints)
  11158.           printf("Hint: Try \"ssh -t %s\"\n",line);
  11159. #else
  11160.           return(y);
  11161. #endif /* COMMENT */
  11162.         nettype = x;        /* Failed, restore net type. */
  11163.         ttnproto = z;        /* and protocol */
  11164.         success = 0;
  11165.     }
  11166.     didsetlin++;
  11167.     netsave = x;
  11168.     return(y);
  11169. #endif /* SSHCMD */
  11170. #endif /* SSHBUILTIN */
  11171.     }
  11172. #endif /* ANYSSH */
  11173.  
  11174. #ifdef SSHBUILTIN
  11175.     if (cx == XXSKRM) {            /* SKERMIT (Secure Shell Kermit) */
  11176.     extern int netsave;
  11177.     int k, x, havehost = 0, trips = 0;
  11178.         int    tmpver = -1, tmpxfw = -1;
  11179. #ifndef SSHTEST
  11180.         extern int sl_ssh_xfw, sl_ssh_xfw_saved;
  11181.         extern int sl_ssh_ver, sl_ssh_ver_saved;
  11182. #endif /* SSHTEST */
  11183.         extern int mdmtyp, mdmsav, cxtype, sl_uid_saved;
  11184.         extern char * slmsg;
  11185.     extern char uidbuf[], sl_uidbuf[];
  11186.         extern char pwbuf[], * g_pswd;
  11187.         extern int pwflg, pwcrypt, g_pflg, g_pcpt, nolocal;
  11188.     struct FDB sw, kw, fl;
  11189.  
  11190.         if (ssh_tmpstr)
  11191.       memset(ssh_tmpstr,0,strlen(ssh_tmpstr));
  11192.         makestr(&ssh_tmpstr,NULL);
  11193.         makestr(&ssh_tmpuid,NULL);
  11194.         makestr(&ssh_tmpcmd,NULL);
  11195.         makestr(&ssh_tmpport,NULL);
  11196.  
  11197.     cmfdbi(&kw,            /* 1st FDB - commands */
  11198.            _CMKEY,            /* fcode */
  11199.            "host [ port ],\n or action", /* hlpmsg */
  11200.            "",            /* default */
  11201.            "",            /* addtl string data */
  11202.            nsshkermit,        /* addtl numeric data 1: tbl size */
  11203.            0,            /* addtl numeric data 2: 0 = keyword */
  11204.            xxstring,        /* Processing function */
  11205.            sshkermit,        /* Keyword table */
  11206.            &fl            /* Pointer to next FDB */
  11207.            );
  11208.     cmfdbi(&fl,            /* Host */
  11209.            _CMFLD,            /* fcode */
  11210.            "",            /* hlpmsg */
  11211.            "",            /* default */
  11212.            "",            /* addtl string data */
  11213.            0,            /* addtl numeric data 1 */
  11214.            0,            /* addtl numeric data 2 */
  11215.            xxstring,
  11216.            NULL,
  11217.            NULL
  11218.            );
  11219.  
  11220.     x = cmfdb(&kw);
  11221.     if (x == -3) {
  11222.         printf("?skermit what?\n");
  11223.         return(-9);
  11224.     }
  11225.     if (x < 0)
  11226.       return(x);
  11227.     havehost = 0;
  11228.     if (cmresult.fcode == _CMFLD) {
  11229.         havehost = 1;
  11230.         ckstrncpy(line,cmresult.sresult,LINBUFSIZ); /* Hostname */
  11231.         cmresult.nresult = SKRM_OPN;
  11232.     }
  11233.     switch (cmresult.nresult) {    /* SSH keyword */
  11234.       case SKRM_OPN:        /* SSH OPEN */
  11235.         if (!havehost) {
  11236.         if ((x = cmfld("Host","",&s,xxstring)) < 0)
  11237.           return(x);
  11238.         ckstrncpy(line,s,LINBUFSIZ);
  11239.         }
  11240.         /* Parse [ port ] [ switches ] */
  11241.         cmfdbi(&kw,            /* Switches */
  11242.            _CMKEY,
  11243.            "Port number or service name,\nor switch",
  11244.            "",
  11245.            "",
  11246.            nsshkrmopnsw,
  11247.            4,
  11248.            xxstring,
  11249.            sshkrmopnsw,
  11250.            &fl
  11251.            );
  11252.         cmfdbi(&fl,            /* Port number or service name */
  11253.            _CMFLD,
  11254.            "",
  11255.            "",
  11256.            "",
  11257.            0,
  11258.            0,
  11259.            xxstring,
  11260.            NULL,
  11261.            NULL
  11262.            );
  11263.         trips = 0;            /* Explained below */
  11264.         while (1) {            /* Parse port and switches */
  11265.         x = cmfdb(&kw);        /* Get a field */
  11266.         if (x == -3)        /* User typed CR so quit from loop */
  11267.           break;
  11268.         if (x < 0)        /* Other parse error, pass it back */
  11269.           return(x);
  11270.         switch (cmresult.fcode) { /* Field or Keyword? */
  11271.                   case _CMFLD:          /* Field */
  11272.                     makestr(&ssh_tmpport,cmresult.sresult);
  11273.             break;
  11274.           case _CMKEY:        /* Keyword */
  11275.             switch (cmresult.nresult) {    /* Which one? */
  11276.               case SSHSW_USR:            /* /USER: */
  11277.             if (!cmgbrk()) {
  11278.                 printf("?This switch requires an argument\n");
  11279.                 return(-9);
  11280.             }
  11281.             if ((y = cmfld("Username","",&s,xxstring)) < 0)
  11282.               return(y);
  11283.             s = brstrip(s);
  11284.             makestr(&ssh_tmpuid,s);
  11285.             break;
  11286.                       case SSHSW_PWD:
  11287.             if (!cmgbrk()) {
  11288.                 printf("?This switch requires an argument\n");
  11289.                 return(-9);
  11290.             }
  11291.             debok = 0;
  11292.             if ((x = cmfld("Password","",&s,xxstring)) < 0) {
  11293.                 if (x == -3) {
  11294.                 makestr(&ssh_tmpstr,"");
  11295.                 } else {
  11296.                 return(x);
  11297.                 }
  11298.             } else {
  11299.                 s = brstrip(s);
  11300.                 if ((x = (int)strlen(s)) > PWBUFL) {
  11301.                 makestr(&slmsg,"Internal error");
  11302.                 printf("?Sorry, too long - max = %d\n",PWBUFL);
  11303.                 return(-9);
  11304.                 }
  11305.                 makestr(&ssh_tmpstr,s);
  11306.             }
  11307.             break;
  11308.  
  11309.                     case SSHSW_VER:
  11310.             if ((x = cmnum("Number","",10,&z,xxstring)) < 0)
  11311.               return(x);
  11312.             if (z < 1 || z > 2) {
  11313.                 printf("?Out of range: %d\n",z);
  11314.                 return(-9);
  11315.             }
  11316.                         tmpver = z;
  11317.             break;
  11318.                     default:
  11319.                         return(-2);
  11320.             }
  11321.                   }
  11322.         if (trips++ == 0) {    /* After first time through */
  11323.             cmfdbi(&kw,        /* only parse switches, not port. */
  11324.                _CMKEY,
  11325.                "Switch",
  11326.                "",
  11327.                "",
  11328.                nsshkrmopnsw,
  11329.                4,
  11330.                xxstring,
  11331.                sshkrmopnsw,
  11332.                NULL
  11333.                );
  11334.         }
  11335.         }
  11336.         if ((x = cmcfm()) < 0)    /* Get confirmation */
  11337.           return(x);
  11338.               if (clskconnx(1) < 0) {    /* Close current Kermit connection */
  11339.                   if ( ssh_tmpstr ) {
  11340.                       memset(ssh_tmpstr,0,strlen(ssh_tmpstr));
  11341.                       makestr(&ssh_tmpstr,NULL);
  11342.                   }
  11343.                   return(success = 0);
  11344.               }
  11345.               makestr(&ssh_hst,line);    /* Stash everything */
  11346.               if (ssh_tmpuid) {
  11347.                   if (!sl_uid_saved) {
  11348.                       ckstrncpy(sl_uidbuf,uidbuf,UIDBUFLEN);
  11349.                       sl_uid_saved = 1;
  11350.                   }
  11351.                   ckstrncpy(uidbuf,ssh_tmpuid,UIDBUFLEN);
  11352.                   makestr(&ssh_tmpuid,NULL);
  11353.               }
  11354.               if (ssh_tmpport) {
  11355.                   makestr(&ssh_prt,ssh_tmpport);
  11356.                   makestr(&ssh_tmpport,NULL);
  11357.               } else
  11358.                   makestr(&ssh_prt,NULL);
  11359.  
  11360.               /* Set the Subsystem to Kermit */
  11361.               ssh_cas = 1;
  11362.               makestr(&ssh_cmd,"kermit");
  11363.  
  11364.               if (tmpver > -1) {
  11365. #ifndef SSHTEST
  11366.                   if (!sl_ssh_ver_saved) {
  11367.                       sl_ssh_ver = ssh_ver;
  11368.                       sl_ssh_ver_saved = 1;
  11369.                   }
  11370. #endif /* SSHTEST */
  11371.                   ssh_ver = tmpver;
  11372.               }
  11373.               /* Disable X11 Forwarding */
  11374. #ifndef SSHTEST
  11375.               if (!sl_ssh_xfw_saved) {
  11376.                   sl_ssh_xfw = ssh_xfw;
  11377.                   sl_ssh_xfw_saved = 1;
  11378.               }
  11379. #endif /* SSHTEST */
  11380.               ssh_xfw = 0;
  11381.  
  11382.               if (ssh_tmpstr) {
  11383.                   if (ssh_tmpstr[0]) {
  11384.                       ckstrncpy(pwbuf,ssh_tmpstr,PWBUFL+1);
  11385.                       pwflg = 1;
  11386.                       pwcrypt = 0;
  11387.                   } else
  11388.                       pwflg = 0;
  11389.                   makestr(&ssh_tmpstr,NULL);
  11390.               }
  11391.               nettype = NET_SSH;
  11392.               if (mdmsav < 0)
  11393.                   mdmsav = mdmtyp;
  11394.               mdmtyp = -nettype;
  11395.               x = 1;
  11396.  
  11397. #ifndef NOSPL
  11398.             makestr(&g_pswd,pwbuf);    /* Save global pwbuf */
  11399.             g_pflg = pwflg;        /* and flag */
  11400.             g_pcpt = pwcrypt;
  11401. #endif /* NOSPL */
  11402.  
  11403.         /* Line parameter to ttopen() is ignored */
  11404.         k = ttopen(line,&x,mdmtyp, 0);
  11405.         if (k < 0) {
  11406.         printf("?Unable to connect to %s\n",ssh_hst);
  11407.         mdmtyp = mdmsav;
  11408.                 slrestor();
  11409.         return(success = 0);
  11410.         }
  11411.         duplex = 0;             /* Remote echo */
  11412.         ckstrncpy(ttname,line,TTNAMLEN); /* Record the command */
  11413.         debug(F110,"ssh ttname",ttname,0);
  11414.         makestr(&slmsg,NULL);    /* No SET LINE error message */
  11415.         cxtype = CXT_SSH;
  11416. #ifndef NODIAL
  11417.         dialsta = DIA_UNK;
  11418. #endif /* NODIAL */
  11419.         success = 1;        /* SET LINE succeeded */
  11420.         network = 1;        /* Network connection (not serial) */
  11421.         local = 1;            /* Local mode (not remote) */
  11422.         if ((reliable != SET_OFF || !setreliable))
  11423.           reliable = SET_ON;    /* Transport is reliable end to end */
  11424. #ifdef OS2
  11425.             DialerSend(OPT_KERMIT_CONNECT, 0);
  11426. #endif /* OS2 */
  11427.         setflow();            /* Set appropriate flow control */
  11428.  
  11429.         haveline = 1;
  11430. #ifdef CKLOGDIAL
  11431. #ifdef NETCONN
  11432.         dolognet();
  11433. #endif /* NETCONN */
  11434. #endif /* CKLOGDIAL */
  11435.  
  11436. #ifndef NOSPL
  11437.         if (local) {
  11438.         if (nmac) {        /* Any macros defined? */
  11439.             int k;        /* Yes */
  11440.             k = mlook(mactab,"on_open",nmac); /* Look this up */
  11441.             if (k >= 0) {                  /* If found, */
  11442.             if (dodo(k,ssh_hst,0) > -1)   /* set it up, */
  11443.               parser(1);              /* and execute it */
  11444.             }
  11445.         }
  11446.         }
  11447. #endif /* NOSPL */
  11448. #ifdef LOCUS        
  11449.         if (autolocus)
  11450.         setlocus(1,1);
  11451. #endif /* LOCUS */
  11452.  
  11453.     /* Command was confirmed so we can pre-pop command level. */
  11454.     /* This is so CONNECT module won't think we're executing a */
  11455.     /* script if CONNECT was the final command in the script. */
  11456.         if (cmdlvl > 0)
  11457.           prepop();
  11458.         return(success = 1);
  11459.  
  11460.       default:
  11461.         return(-2);
  11462.     }
  11463.     }
  11464. #endif /* SSHBUILTIN */
  11465.  
  11466. #ifdef SFTP_BUILTIN
  11467.     if (cx == XXSFTP) {            /* SFTP (Secure Shell File Transfer) */
  11468.     extern int netsave;
  11469.     int k, x, havehost = 0, trips = 0;
  11470.         int    tmpver = -1, tmpxfw = -1;
  11471. #ifndef SSHTEST
  11472.         extern int sl_ssh_xfw, sl_ssh_xfw_saved;
  11473.         extern int sl_ssh_ver, sl_ssh_ver_saved;
  11474. #endif /* SSHTEST */
  11475.         extern int mdmtyp, mdmsav, cxtype, sl_uid_saved;
  11476.         extern char * slmsg;
  11477.     extern char uidbuf[], sl_uidbuf[];
  11478.         extern char pwbuf[], * g_pswd;
  11479.         extern int pwflg, pwcrypt, g_pflg, g_pcpt, nolocal;
  11480.     struct FDB sw, kw, fl;
  11481.  
  11482.         if (ssh_tmpstr)
  11483.       memset(ssh_tmpstr,0,strlen(ssh_tmpstr));
  11484.         makestr(&ssh_tmpstr,NULL);
  11485.         makestr(&ssh_tmpuid,NULL);
  11486.         makestr(&ssh_tmpcmd,NULL);
  11487.         makestr(&ssh_tmpport,NULL);
  11488.  
  11489.     cmfdbi(&kw,            /* 1st FDB - commands */
  11490.            _CMKEY,            /* fcode */
  11491.            "host [ port ],\n or action", /* hlpmsg */
  11492.            "",            /* default */
  11493.            "",            /* addtl string data */
  11494.            nsftpkwtab,        /* addtl numeric data 1: tbl size */
  11495.            0,            /* addtl numeric data 2: 0 = keyword */
  11496.            xxstring,        /* Processing function */
  11497.            sftpkwtab,        /* Keyword table */
  11498.            &fl            /* Pointer to next FDB */
  11499.            );
  11500.     cmfdbi(&fl,            /* Host */
  11501.            _CMFLD,            /* fcode */
  11502.            "",            /* hlpmsg */
  11503.            "",            /* default */
  11504.            "",            /* addtl string data */
  11505.            0,            /* addtl numeric data 1 */
  11506.            0,            /* addtl numeric data 2 */
  11507.            xxstring,
  11508.            NULL,
  11509.            NULL
  11510.            );
  11511.  
  11512.     x = cmfdb(&kw);
  11513.     if (x == -3) {
  11514.         printf("?sftp what?\n");
  11515.         return(-9);
  11516.     }
  11517.     if (x < 0)
  11518.       return(x);
  11519.     havehost = 0;
  11520.     if (cmresult.fcode == _CMFLD) {
  11521.         havehost = 1;
  11522.         ckstrncpy(line,cmresult.sresult,LINBUFSIZ); /* Hostname */
  11523.         cmresult.nresult = SFTP_OPN;
  11524.     }
  11525.     switch (cmresult.nresult) {    /* SFTP keyword */
  11526.       case SFTP_OPN:        /* SFTP OPEN */
  11527.         if (!havehost) {
  11528.         if ((x = cmfld("Host","",&s,xxstring)) < 0)
  11529.           return(x);
  11530.         ckstrncpy(line,s,LINBUFSIZ);
  11531.         }
  11532.         /* Parse [ port ] [ switches ] */
  11533.         cmfdbi(&kw,            /* Switches */
  11534.            _CMKEY,
  11535.            "Port number or service name,\nor switch",
  11536.            "",
  11537.            "",
  11538.            nsshkrmopnsw,
  11539.            4,
  11540.            xxstring,
  11541.            sshkrmopnsw,
  11542.            &fl
  11543.            );
  11544.         cmfdbi(&fl,            /* Port number or service name */
  11545.            _CMFLD,
  11546.            "",
  11547.            "",
  11548.            "",
  11549.            0,
  11550.            0,
  11551.            xxstring,
  11552.            NULL,
  11553.            NULL
  11554.            );
  11555.         trips = 0;            /* Explained below */
  11556.         while (1) {            /* Parse port and switches */
  11557.         x = cmfdb(&kw);        /* Get a field */
  11558.         if (x == -3)        /* User typed CR so quit from loop */
  11559.           break;
  11560.         if (x < 0)        /* Other parse error, pass it back */
  11561.           return(x);
  11562.         switch (cmresult.fcode) { /* Field or Keyword? */
  11563.                   case _CMFLD:          /* Field */
  11564.                     makestr(&ssh_tmpport,cmresult.sresult);
  11565.             break;
  11566.           case _CMKEY:        /* Keyword */
  11567.             switch (cmresult.nresult) {    /* Which one? */
  11568.               case SSHSW_USR:            /* /USER: */
  11569.             if (!cmgbrk()) {
  11570.                 printf("?This switch requires an argument\n");
  11571.                 return(-9);
  11572.             }
  11573.             if ((y = cmfld("Username","",&s,xxstring)) < 0)
  11574.               return(y);
  11575.             s = brstrip(s);
  11576.             makestr(&ssh_tmpuid,s);
  11577.             break;
  11578.                       case SSHSW_PWD:
  11579.             if (!cmgbrk()) {
  11580.                 printf("?This switch requires an argument\n");
  11581.                 return(-9);
  11582.             }
  11583.             debok = 0;
  11584.             if ((x = cmfld("Password","",&s,xxstring)) < 0) {
  11585.                 if (x == -3) {
  11586.                 makestr(&ssh_tmpstr,"");
  11587.                 } else {
  11588.                 return(x);
  11589.                 }
  11590.             } else {
  11591.                 s = brstrip(s);
  11592.                 if ((x = (int)strlen(s)) > PWBUFL) {
  11593.                 makestr(&slmsg,"Internal error");
  11594.                 printf("?Sorry, too long - max = %d\n",PWBUFL);
  11595.                 return(-9);
  11596.                 }
  11597.                 makestr(&ssh_tmpstr,s);
  11598.             }
  11599.             break;
  11600.  
  11601.                     case SSHSW_VER:
  11602.             if ((x = cmnum("Number","",10,&z,xxstring)) < 0)
  11603.               return(x);
  11604.             if (z < 1 || z > 2) {
  11605.                 printf("?Out of range: %d\n",z);
  11606.                 return(-9);
  11607.             }
  11608.                         tmpver = z;
  11609.             break;
  11610.                     default:
  11611.                         return(-2);
  11612.             }
  11613.         }
  11614.         if (trips++ == 0) {    /* After first time through */
  11615.             cmfdbi(&kw,        /* only parse switches, not port. */
  11616.                _CMKEY,
  11617.                "Switch",
  11618.                "",
  11619.                "",
  11620.                nsshkrmopnsw,
  11621.                4,
  11622.                xxstring,
  11623.                sshkrmopnsw,
  11624.                NULL
  11625.                );
  11626.         }
  11627.         }
  11628.         if ((x = cmcfm()) < 0)    /* Get confirmation */
  11629.           return(x);
  11630.               if (clskconnx(1) < 0) {    /* Close current Kermit connection */
  11631.                   if ( ssh_tmpstr ) {
  11632.                       memset(ssh_tmpstr,0,strlen(ssh_tmpstr));
  11633.                       makestr(&ssh_tmpstr,NULL);
  11634.                   }
  11635.                   return(success = 0);
  11636.               }
  11637.               makestr(&ssh_hst,line);    /* Stash everything */
  11638.               if (ssh_tmpuid) {
  11639.                   if (!sl_uid_saved) {
  11640.                       ckstrncpy(sl_uidbuf,uidbuf,UIDBUFLEN);
  11641.                       sl_uid_saved = 1;
  11642.                   }
  11643.                   ckstrncpy(uidbuf,ssh_tmpuid,UIDBUFLEN);
  11644.                   makestr(&ssh_tmpuid,NULL);
  11645.               }
  11646.               if (ssh_tmpport) {
  11647.                   makestr(&ssh_prt,ssh_tmpport);
  11648.                   makestr(&ssh_tmpport,NULL);
  11649.               } else
  11650.                   makestr(&ssh_prt,NULL);
  11651.  
  11652.               /* Set the Subsystem to Kermit */
  11653.               ssh_cas = 1;
  11654.               makestr(&ssh_cmd,"sftp");
  11655.  
  11656.               if (tmpver > -1) {
  11657. #ifndef SSHTEST
  11658.                   if (!sl_ssh_ver_saved) {
  11659.                       sl_ssh_ver = ssh_ver;
  11660.                       sl_ssh_ver_saved = 1;
  11661.                   }
  11662. #endif /* SSHTEST */
  11663.                   ssh_ver = tmpver;
  11664.               }
  11665.               /* Disable X11 Forwarding */
  11666. #ifndef SSHTEST
  11667.               if (!sl_ssh_xfw_saved) {
  11668.                   sl_ssh_xfw = ssh_xfw;
  11669.                   sl_ssh_xfw_saved = 1;
  11670.               }
  11671. #endif /* SSHTEST */
  11672.               ssh_xfw = 0;
  11673.  
  11674.               if (ssh_tmpstr) {
  11675.                   if (ssh_tmpstr[0]) {
  11676.                       ckstrncpy(pwbuf,ssh_tmpstr,PWBUFL+1);
  11677.                       pwflg = 1;
  11678.                       pwcrypt = 0;
  11679.                   } else
  11680.                       pwflg = 0;
  11681.                   makestr(&ssh_tmpstr,NULL);
  11682.               }
  11683.               nettype = NET_SSH;
  11684.               if (mdmsav < 0)
  11685.                   mdmsav = mdmtyp;
  11686.               mdmtyp = -nettype;
  11687.               x = 1;
  11688.  
  11689. #ifndef NOSPL
  11690.             makestr(&g_pswd,pwbuf);             /* Save global pwbuf */
  11691.             g_pflg = pwflg;                     /* and flag */
  11692.             g_pcpt = pwcrypt;
  11693. #endif /* NOSPL */
  11694.  
  11695.         /* Line parameter to ttopen() is ignored */
  11696.         k = ttopen(line,&x,mdmtyp, 0);
  11697.         if (k < 0) {
  11698.         printf("?Unable to connect to %s\n",ssh_hst);
  11699.         mdmtyp = mdmsav;
  11700.                 slrestor();
  11701.         return(success = 0);
  11702.         }
  11703.         duplex = 0;             /* Remote echo */
  11704.         ckstrncpy(ttname,line,TTNAMLEN); /* Record the command */
  11705.         debug(F110,"ssh ttname",ttname,0);
  11706.         makestr(&slmsg,NULL);    /* No SET LINE error message */
  11707.         cxtype = CXT_SSH;
  11708. #ifndef NODIAL
  11709.         dialsta = DIA_UNK;
  11710. #endif /* NODIAL */
  11711.         success = 1;        /* SET LINE succeeded */
  11712.         network = 1;        /* Network connection (not serial) */
  11713.         local = 1;            /* Local mode (not remote) */
  11714.         if ((reliable != SET_OFF || !setreliable))
  11715.           reliable = SET_ON;    /* Transport is reliable end to end */
  11716. #ifdef OS2
  11717.             DialerSend(OPT_KERMIT_CONNECT, 0);
  11718. #endif /* OS2 */
  11719.         setflow();            /* Set appropriate flow control */
  11720.  
  11721.         haveline = 1;
  11722. #ifdef CKLOGDIAL
  11723. #ifdef NETCONN
  11724.         dolognet();
  11725. #endif /* NETCONN */
  11726. #endif /* CKLOGDIAL */
  11727.  
  11728. #ifndef NOSPL
  11729.         if (local) {
  11730.         if (nmac) {        /* Any macros defined? */
  11731.             int k;        /* Yes */
  11732.             k = mlook(mactab,"on_open",nmac); /* Look this up */
  11733.             if (k >= 0) {                  /* If found, */
  11734.             if (dodo(k,ssh_hst,0) > -1)   /* set it up, */
  11735.               parser(1);              /* and execute it */
  11736.             }
  11737.         }
  11738.         }
  11739. #endif /* NOSPL */
  11740. #ifdef LOCUS        
  11741.         if (autolocus)
  11742.         setlocus(1,1);
  11743. #endif /* LOCUS */
  11744.  
  11745.     /* Command was confirmed so we can pre-pop command level. */
  11746.     /* This is so CONNECT module won't think we're executing a */
  11747.     /* script if CONNECT was the final command in the script. */
  11748.         if (cmdlvl > 0)
  11749.           prepop();
  11750.  
  11751.             success = sftp_do_init();
  11752.         return(success = 1);
  11753.  
  11754.       case SFTP_CD:
  11755.       case SFTP_CHGRP:
  11756.       case SFTP_CHMOD:
  11757.       case SFTP_CHOWN:
  11758.       case SFTP_RM:
  11759.       case SFTP_DIR:
  11760.       case SFTP_GET:
  11761.       case SFTP_MKDIR:
  11762.       case SFTP_PUT:
  11763.       case SFTP_PWD:
  11764.       case SFTP_REN:
  11765.       case SFTP_RMDIR:
  11766.       case SFTP_LINK:
  11767.       case SFTP_VER:
  11768.         if ((y = cmtxt("command parameters","",&s,xxstring)) < 0) 
  11769.           return(y);
  11770.         if (ssh_tchk() < 0 || !ssh_cas || strcmp(ssh_cmd,"sftp")) {
  11771.         printf("?Not connected to SFTP Service\n");
  11772.         return(success = 0);
  11773.         }
  11774.         success = sftp_do_cmd(cmresult.nresult,s);
  11775.         return(success);
  11776.       default:
  11777.         return(-2);
  11778.     }
  11779.     }
  11780. #endif /* SFTP_BUILTIN */
  11781.  
  11782.     if (cx == XXRLOG) {            /* RLOGIN */
  11783. #ifdef RLOGCODE
  11784.     int x,z;
  11785. #ifdef OS2
  11786.     if (!tcp_avail) {
  11787.         printf("?Sorry, either TCP/IP is not available on this system or\n\
  11788. necessary DLLs did not load.  Use SHOW NETWORK to check network status.\n"
  11789.            );
  11790.         success = 0;
  11791.         return(-9);
  11792.     } else {
  11793. #endif /* OS2 */
  11794.         x = nettype;        /* Save net type in case of failure */
  11795.         z = ttnproto;        /* Save protocol in case of failure */
  11796.         nettype = NET_TCPB;
  11797.         ttnproto = NP_RLOGIN;
  11798.         if ((y = setlin(XYHOST,0,1)) <= 0) {
  11799.         nettype = x;        /* Failed, restore net type. */
  11800.         ttnproto = z;        /* and protocol */
  11801.         success = 0;
  11802.         }
  11803.         didsetlin++;
  11804. #ifdef OS2
  11805.     }
  11806. #endif /* OS2 */
  11807.     return(y);
  11808. #else
  11809.     printf("?Sorry, RLOGIN is not configured in this copy of C-Kermit.\n");
  11810.     return(-9);
  11811. #endif /* RLOGCODE */
  11812.     }
  11813. #endif /* NETCONN */
  11814. #endif /* NOLOCAL */
  11815.  
  11816. #ifndef NOXMIT
  11817.     if (cx == XXTRA) {            /* TRANSMIT */
  11818.     extern int xfrxla;
  11819.     int i, n, xpipe = 0, xbinary = 0, xxlate = 1, xxnowait = 0, getval;
  11820.     int xxecho = 0;
  11821.     int scan = 1;
  11822.     char c;
  11823.     struct FDB sf, sw, tx;        /* FDBs for parse functions */
  11824. #ifndef NOCSETS
  11825.     extern int tcs_transp;        /* Term charset is transparent */
  11826. #else
  11827.     int tcs_transp = 1;
  11828. #endif /* NOCSETS */
  11829.  
  11830. #ifdef COMMENT
  11831.     xbinary = binary;        /* Default text/binary mode */
  11832. #else
  11833.     xbinary = 0;            /* Default is text */
  11834. #endif /* COMMENT */
  11835.     xxecho = xmitx;
  11836.  
  11837.     cmfdbi(&sw,            /* First FDB - command switches */
  11838.            _CMKEY,            /* fcode */
  11839.            "Filename, or switch",    /* hlpmsg */
  11840.            "",            /* default */
  11841.            "",            /* addtl string data */
  11842.            nxmitsw,            /* addtl numeric data 1: tbl size */
  11843.            4,            /* addtl numeric data 2: 4 = cmswi */
  11844.            xxstring,        /* Processing function */
  11845.            xmitsw,            /* Keyword table */
  11846.            &sf            /* Pointer to next FDB */
  11847.            );
  11848.     cmfdbi(&sf,            /* 2nd FDB - file to send */
  11849.            _CMIFI,            /* fcode */
  11850.            "File to transmit",    /* hlpmsg */
  11851.            "",            /* default */
  11852.            "",            /* addtl string data */
  11853.            0,            /* addtl numeric data 1 */
  11854.            0,            /* addtl numeric data 2 */
  11855.            xxstring,
  11856.            NULL,
  11857. #ifdef PIPESEND
  11858.            &tx
  11859. #else
  11860.            NULL
  11861. #endif /* PIPESEND */
  11862.            );
  11863. #ifdef PIPESEND
  11864.         cmfdbi(&tx,
  11865.            _CMTXT,            /* fcode */
  11866.            "Command",        /* hlpmsg */
  11867.            "",            /* default */
  11868.            "",            /* addtl string data */
  11869.            0,            /* addtl numeric data 1 */
  11870.            0,            /* addtl numeric data 2 */
  11871.            xxstring,
  11872.            NULL,
  11873.            NULL
  11874.            );
  11875. #endif /* PIPESEND */
  11876.  
  11877.     while (1) {
  11878.         x = cmfdb(&sw);
  11879.         if (x < 0)
  11880.           return(x);
  11881.         if (cmresult.fcode != _CMKEY)
  11882.           break;
  11883.         c = cmgbrk();        /* Have switch, get break character */
  11884.         if ((getval = (c == ':' || c == '=')) && !(cmgkwflgs() & CM_ARG)) {
  11885.         printf("?This switch does not take an argument\n");
  11886.         return(-9);
  11887.         }
  11888.         if (!getval && (cmgkwflgs() & CM_ARG)) {
  11889.         printf("?This switch requires an argument\n");
  11890.         return(-9);
  11891.         }
  11892.         n = cmresult.nresult;    /* Numeric result = switch ID */
  11893.         switch (n) {        /* Process the switch */
  11894. #ifdef PIPESEND
  11895.           case XMI_CMD:        /* Transmit from a command */
  11896.         if (nopush) {
  11897.             printf("?Sorry, system command access is disabled\n");
  11898.             return(-9);
  11899.         }
  11900.         sw.hlpmsg = "Command, or switch"; /* Change help message */
  11901.         xpipe = 1;        /* (No way to undo this one) */
  11902.         break;
  11903. #endif /* PIPESEND */
  11904.  
  11905.           case XMI_BIN:        /* Binary */
  11906.         xbinary = 1;
  11907.         xxlate = 0;        /* Don't translate charsets */
  11908.         scan = 0;
  11909.         break;
  11910.  
  11911.           case XMI_TXT:        /* Text */
  11912.         xbinary = 0;
  11913.         xxlate = !tcs_transp;    /* Translate if TERM CHAR not TRANSP */
  11914.         scan = 0;
  11915.         break;
  11916.  
  11917.           case XMI_TRA:        /* Transparent text */
  11918.         xbinary = 0;
  11919.         xxlate = 0;        /* But don't translate charsets */
  11920.         scan = 0;
  11921.         break;
  11922.  
  11923. #ifdef COMMENT
  11924.           case XMI_VRB:        /* /VERBOSE */
  11925.           case XMI_QUI:        /* /QUIET */
  11926.         break;            /* (not implemented yet) */
  11927. #endif /* COMMENT */
  11928.  
  11929.           case XMI_NOW:        /* /NOWAIT */
  11930.         xxnowait = 1;
  11931.         break;
  11932.  
  11933.           case XMI_NOE:        /* /NOWAIT */
  11934.         xxecho = 0;
  11935.         break;
  11936.  
  11937.           default:
  11938.         return(-2);
  11939.         }
  11940.  
  11941.     }
  11942.     if (cmresult.fcode != _CMIFI && cmresult.fcode != _CMTXT)
  11943.       return(-2);
  11944.     ckstrncpy(line,cmresult.sresult,LINBUFSIZ); /* Filename */
  11945.     if (zfnqfp(line,TMPBUFSIZ,tmpbuf))
  11946.       ckstrncpy(line,tmpbuf,LINBUFSIZ);
  11947.     s = line;
  11948.     if ((y = cmcfm()) < 0)        /* Confirm */
  11949.       return(y);
  11950. #ifdef CK_APC
  11951.     if ((apcactive == APC_LOCAL) ||
  11952.         ((apcactive == APC_REMOTE) && (!(apcstatus & APC_UNCH))))
  11953.       return(success = 0);
  11954. #endif /* CK_APC */
  11955.     if (cmresult.nresult != 0) {
  11956.         printf("?Only a single file may be transmitted\n");
  11957.         return(-9);
  11958.     }
  11959. #ifdef PIPESEND
  11960.     if (xpipe) {
  11961.         s = brstrip(s);
  11962.         if (!*s) {
  11963.         printf("?Sorry, a command to send from is required\n");
  11964.         return(-9);
  11965.         }
  11966.         pipesend = 1;
  11967.     }
  11968. #endif /* PIPESEND */
  11969.  
  11970.     if (scan && (filepeek
  11971. #ifndef NOXFER
  11972.              || patterns
  11973. #endif /* NOXFER */
  11974.              )) {        /* If user didn't specify type */
  11975.         int k, x;                  /* scan the file to see */
  11976.         x = -1;
  11977.         k = scanfile(s,&x,nscanfile);
  11978.         if (k > 0) xbinary = (k == FT_BIN) ? XYFT_B : XYFT_T;
  11979.     }
  11980.     if (!xfrxla) xxlate = 0;
  11981.     success = transmit(s,
  11982.                (char) (xxnowait ? '\0' : (char)xmitp),
  11983.                xxlate,
  11984.                xbinary,
  11985.                xxecho
  11986.                );
  11987.     return(success);
  11988.     }
  11989. #endif /* NOXMIT */
  11990.  
  11991. #ifndef NOFRILLS
  11992.     if (cx == XXTYP  || cx == XXCAT || cx == XXMORE ||
  11993.     cx == XXHEAD || cx == XXTAIL) {
  11994.     int paging = 0, havename = 0, head = 0, width = 0;
  11995.     int height = 0, count = 0;
  11996.     char pfxbuf[64], * prefix = NULL;
  11997.     char outfile[CKMAXPATH+1];
  11998.     struct FDB sf, sw;
  11999.     char * pat = NULL;
  12000.     int incs = 0, outcs = 0, cset = -1, number = 0;
  12001. #ifdef UNICODE
  12002.         char * tocs = "";
  12003.     extern int fileorder;
  12004. #ifdef OS2
  12005. #ifdef NT
  12006.     char guibuf[128], * gui_title = NULL;
  12007.     int  gui = 0;
  12008. #endif /* NT */
  12009. #ifndef NOCSETS
  12010.     extern int tcsr, tcsl;
  12011. #endif /* NOCSETS */
  12012. #endif /* OS2 */
  12013. #endif /* UNICODE */
  12014.  
  12015.     outfile[0] = NUL;
  12016.  
  12017.     if (cx == XXMORE)
  12018.       paging = 1;
  12019.     else if (cx == XXCAT)
  12020.       paging = 0;
  12021.     else
  12022.       paging = (typ_page < 0) ? xaskmore : typ_page;
  12023.     if (paging < 0)
  12024.       paging = saveask;
  12025.  
  12026.     if (cx == XXHEAD) {
  12027.         head = 10;
  12028.         cx = XXTYP;
  12029.     } else if (cx == XXTAIL) {
  12030.         head = -10;
  12031.         cx = XXTYP;
  12032.     }
  12033.  
  12034. #ifdef IKSD
  12035.     if (inserver && !ENABLED(en_typ)) {
  12036.         printf("?Sorry, TYPE command disabled\n");
  12037.         return(-9);
  12038.     }
  12039. #endif /* IKSD */
  12040.  
  12041.     cmfdbi(&sw,            /* 2nd FDB - optional /PAGE switch */
  12042.            _CMKEY,            /* fcode */
  12043.            "Filename or switch",    /* hlpmsg */
  12044.            "",            /* default */
  12045.            "",            /* addtl string data */
  12046.            ntypetab,        /* addtl numeric data 1: tbl size */
  12047.            4,            /* addtl numeric data 2: 4 = cmswi */
  12048.            xxstring,        /* Processing function */
  12049.            typetab,            /* Keyword table */
  12050.            &sf            /* Pointer to next FDB */
  12051.            );
  12052.     cmfdbi(&sf,            /* 1st FDB - file to type */
  12053.            _CMIFI,            /* fcode */
  12054.            "",            /* hlpmsg */
  12055.            "",            /* default */
  12056.            "",            /* addtl string data */
  12057.            0,            /* addtl numeric data 1 */
  12058.            0,            /* addtl numeric data 2 */
  12059.            xxstring,
  12060.            NULL,
  12061.            NULL
  12062.            );
  12063.  
  12064.     while (!havename) {
  12065.         x = cmfdb(&sw);        /* Parse something */
  12066.         debug(F101,"type cmfdb","",x);
  12067.         debug(F101,"type cmresult.fcode","",cmresult.fcode);
  12068.         debug(F101,"type cmresult.nresult","",cmresult.nresult);
  12069.         if (x < 0) {            /* Error */
  12070.         if (x == -3) {
  12071.             x = -9;
  12072.             printf("?Filename required\n");
  12073.         }
  12074.         return(x);
  12075.         } else if (cmresult.fcode == _CMKEY) {
  12076.         char c; int getval;
  12077.         c = cmgbrk();
  12078.         getval = (c == ':' || c == '=');
  12079.         if (getval && !(cmgkwflgs() & CM_ARG)) {
  12080.             printf("?This switch does not take an argument\n");
  12081.             return(-9);
  12082.         }
  12083. #ifdef COMMENT
  12084.         if (!getval && (cmgkwflgs() & CM_ARG)) {
  12085.             printf("?This switch requires an argument\n");
  12086.             /* Not if it has a default! */
  12087.             return(-9);
  12088.         }
  12089. #endif /* COMMENT */
  12090.         switch (cmresult.nresult) {
  12091. #ifdef CK_TTGWSIZ
  12092.           case TYP_PAG:
  12093.             paging = 1;
  12094.             break;
  12095.  
  12096.           case TYP_NOP:
  12097.             paging = 0;
  12098.             break;
  12099. #endif /* CK_TTGWSIZ */
  12100.  
  12101.           case TYP_COU:
  12102.             paging = 0;
  12103.             count = 1;
  12104.             break;
  12105.  
  12106.           case TYP_HEA:
  12107.           case TYP_TAI:
  12108.             y = 10;
  12109.             if (getval)
  12110.               if ((x = cmnum("Number of lines",
  12111.                      "10",10,&y,xxstring)) < 0)
  12112.             return(x);
  12113.             head = (cmresult.nresult == TYP_TAI) ? -y : y;
  12114.             break;
  12115.  
  12116.           case TYP_WID:
  12117.             y = typ_wid > -1 ? typ_wid : cmd_cols;
  12118.             if (getval)
  12119.               if ((x = cmnum("Column at which to truncate",
  12120.                      ckitoa(y),10,&y,xxstring)) < 0)
  12121.             return(x);
  12122.             width = y;
  12123.             break;
  12124.  
  12125. #ifdef KUI
  12126.           case TYP_HIG:
  12127.             if (getval)
  12128.               if ((x = cmnum("Height of GUI dialog",
  12129.                      ckitoa(y),10,&y,xxstring)) < 0)
  12130.             return(x);
  12131.             height = y;
  12132.             break;
  12133. #endif /* KUI */
  12134.  
  12135.           case TYP_PAT:
  12136.             if (!getval && (cmgkwflgs() & CM_ARG)) {
  12137.             printf("?This switch requires an argument\n");
  12138.             return(-9);
  12139.             }
  12140.             if ((x = cmfld("pattern","",&s,xxstring)) < 0)
  12141.               return(x);
  12142.             ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  12143.             pat = tmpbuf;
  12144.             break;
  12145.  
  12146.           case TYP_PFX:
  12147.             if (!getval && (cmgkwflgs() & CM_ARG)) {
  12148.             printf("?This switch requires an argument\n");
  12149.             return(-9);
  12150.             }
  12151.             if ((x = cmfld("prefix for each line","",&s,xxstring)) < 0)
  12152.               return(x);
  12153.             if ((int)strlen(s) > 63) {
  12154.             printf("?Too long - 63 max\n");
  12155.             return(-9);
  12156.             }
  12157.             ckstrncpy(pfxbuf,s,64);
  12158.             prefix = brstrip(pfxbuf);
  12159.             number = 0;
  12160.             break;
  12161.  
  12162. #ifdef KUI
  12163.           case TYP_GUI:
  12164.             if (!getval && (cmgkwflgs() & CM_ARG)) {
  12165.             printf("?This switch requires an argument\n");
  12166.             return(-9);
  12167.             }
  12168.             if ((x = cmfld("Dialog box title","",&s,xxstring)) < 0) {
  12169.             if (x != -3)
  12170.               return(x);
  12171.             } else {
  12172.             if ((int)strlen(s) > 127) {
  12173.                 printf("?Too long - 127 max\n");
  12174.                 return(-9);
  12175.             }
  12176.             ckstrncpy(guibuf,s,128);
  12177.             gui_title = brstrip(guibuf);
  12178.             }
  12179.             gui = 1;
  12180.             break;
  12181. #endif /* KUI */
  12182.  
  12183.           case TYP_NUM:        /* /NUMBER */
  12184.             number = 1;
  12185.             prefix = NULL;
  12186.             break;
  12187.  
  12188. #ifdef UNICODE
  12189.           case TYP_XPA:        /* /TRANSPARENT */
  12190.             incs = 0;
  12191.             cset = 0;
  12192.             outcs = -1;
  12193.             break;
  12194.  
  12195.           case TYP_XIN:        /* /CHARACTER-SET: */
  12196.             if (!getval && (cmgkwflgs() & CM_ARG)) {
  12197.             printf("?This switch requires an argument\n");
  12198.             return(-9);
  12199.             }
  12200.             if ((incs = cmkey(fcstab,nfilc,
  12201.                       "character-set name","",xxstring)) < 0) {
  12202.             if (incs == -3)    /* Note: No default */
  12203.               incs = -2;
  12204.             return(incs);
  12205.             }
  12206.             cset = incs;
  12207.             break;
  12208.  
  12209.           case TYP_XUT:        /* /TRANSLATE-TO: */
  12210.             if (!getval && (cmgkwflgs() & CM_ARG)) {
  12211.             printf("?This switch requires an argument\n");
  12212.             return(-9);
  12213.             }
  12214. #ifdef OS2
  12215.             if (!inserver && !k95stdout) {
  12216.             tocs = "ucs2";
  12217.             } else {
  12218. #ifdef CKOUNI
  12219.             tocs = rlookup(txrtab,ntxrtab,tcsl);
  12220. #else /* CKOUNI */
  12221.             extern struct keytab ttcstab[];
  12222.             extern int ntxrtab;
  12223.             tocs = rlookup(ttcstab,ntermc,tocs);
  12224.             if (!tocs)
  12225.               tocs = getdcset();
  12226. #endif /* CKOUNI */
  12227.                     }
  12228. #else /* OS2 */
  12229.             tocs = getdcset();
  12230. #endif /* OS2 */
  12231.             if ((outcs = cmkey(fcstab,nfilc,
  12232.                        "character-set",tocs,xxstring)) < 0)
  12233.               return(outcs);
  12234.             break;
  12235. #endif /* UNICODE */
  12236.           case TYP_OUT:
  12237.             if ((x = cmofi("File for result lines","",
  12238.                    &s,xxstring)) < 0)
  12239.               return(x);
  12240.             ckstrncpy(outfile,s,CKMAXPATH);
  12241.             break;
  12242.         }
  12243.         } else if (cmresult.fcode == _CMIFI)
  12244.           havename = 1;
  12245.         else
  12246.           return(-2);
  12247.     }
  12248.     if (havename) {
  12249.         ckstrncpy(line,cmresult.sresult,LINBUFSIZ);
  12250.         y = cmresult.nresult;
  12251.     } else {
  12252.         if ((x = cmifi("Filename","",&s,&y,xxstring)) < 0) {
  12253.         if (x == -3) {
  12254.             printf("?Name of an existing file required\n");
  12255.             return(-9);
  12256.         } else return(x);
  12257.         }
  12258.         ckstrncpy(line,s,LINBUFSIZ);
  12259.     }
  12260.     if (y != 0) {
  12261.         printf("?A single file please\n");
  12262.         return(-9);
  12263.     }
  12264. #ifdef KUI
  12265.     if ( outfile[0] && gui ) {
  12266.         printf("?/GUI and /OUTPUT are incompatible\n");
  12267.         return(-9);
  12268.     }
  12269. #endif /* KUI */
  12270.  
  12271.     if ((y = cmcfm()) < 0)        /* Confirm the command */
  12272.       return(y);
  12273.  
  12274. #ifdef UNICODE
  12275.     fileorder = -1;
  12276.     if (cset < 0 && filepeek) {    /* If no charset switches given */
  12277.         int k, x = -1;
  12278.         k = scanfile(line,&x,nscanfile); /* Call file analyzer */
  12279.         debug(F111,"type scanfile",line,k);
  12280.         debug(F101,"type scanfile flag","",x);
  12281.         switch(k) {
  12282.           case FT_UTF8:        /* which can detect UTF-8... */
  12283.         cset = 0;
  12284.         incs = FC_UTF8;
  12285.         break;
  12286.           case FT_UCS2:        /* and UCS-2... */
  12287.         cset = 0;
  12288.         incs = FC_UCS2;
  12289.         fileorder = x;        /* even if there is no BOM. */
  12290.         debug(F101,"type fileorder","",fileorder);
  12291.         break;
  12292.         }
  12293.     }
  12294. #ifdef OS2
  12295.         if (cset < 0) {            /* If input charset still not known */
  12296. #ifdef CKOUNI
  12297.             tocs = rlookup(txrtab,ntxrtab,tcsl);
  12298. #else /* CKOUNI */
  12299.             extern struct keytab ttcstab[];
  12300.             extern int ntxrtab;
  12301.             tocs = rlookup(ttcstab,ntermc,incs);
  12302.             if (!tocs)
  12303.           tocs = getdcset();
  12304. #endif /* CKOUNI */
  12305.             incs = lookup(fcstab,tocs,nfilc,&x);
  12306.         }
  12307. #endif /* OS2 */
  12308.  
  12309.         if (outcs == 0 && incs != 0) {    /* Supply default target charset */
  12310.         int x = 0;            /* if switch not given. */
  12311.         tocs = getdcset();
  12312.         outcs = lookup(fcstab,tocs,nfilc,&x);
  12313.     }
  12314. #else  /* !UNICODE */
  12315.     if (cset < 0) incs = outcs = 0;
  12316. #endif /* UNICODE */
  12317.  
  12318.     if (outfile[0] && paging)    /* This combination makes no sense */
  12319.       paging = 0;            /* so turn off paging */
  12320.  
  12321. #ifdef KUI
  12322.     /* No paging when dialog is used */
  12323.     if ( gui && paging )
  12324.       paging = 0;
  12325.  
  12326.     if ( !gui && height ) {
  12327.         printf("?The /HEIGHT switch is not supported without /GUI\n");
  12328.         return(-9);
  12329.     }
  12330. #endif /* KUI */
  12331.  
  12332.     if (count) paging = -1;
  12333.     debug(F111,"type",line,paging);
  12334. #ifdef KUI
  12335.     if ( gui ) {
  12336.         s = (char *)1;    /* ok, its an ugly hack */
  12337.         if (gui_text_popup_create(gui_title ?
  12338.                       gui_title : line, height,width) < 0) {
  12339.         printf("?/GUI not supported on this system\n");
  12340.         gui = 0;
  12341.         return(-9);
  12342.         }
  12343.         width = 0;
  12344.     } else
  12345. #endif /* KUI */
  12346.       s = outfile;
  12347.     success =
  12348.       dotype(line,paging,0,head,pat,width,prefix,incs,outcs,s,number);
  12349.     return(success);
  12350.     }
  12351. #endif /* NOFRILLS */
  12352.  
  12353. #ifndef NOCSETS
  12354.     if (cx == XXXLA) {            /* TRANSLATE file's charset */
  12355.     _PROTOTYP (int doxlate, ( void ) );
  12356.     return(doxlate());
  12357.     }
  12358. #endif /* NOCSETS */
  12359.  
  12360.     if (cx == XXVER) {            /* VERSION */
  12361.     int n = 0;
  12362.     extern char * ck_patch, * ck_s_test;
  12363. #ifdef COMMENT
  12364.     extern int hmtopline;
  12365. #endif /* COMMENT */
  12366.     if ((y = cmcfm()) < 0)
  12367.           return(y);
  12368.  
  12369. #ifdef CK_64BIT
  12370.     printf("\n%s, for%s (64-bit)\n Numeric: %ld",versio,ckxsys,vernum);
  12371. #else
  12372.     printf("\n%s, for%s\n Numeric: %ld",versio,ckxsys,vernum);
  12373. #endif    /* CK_64BIT */
  12374.     printf("\n\n");
  12375.         printf("Authors:\n");
  12376.     printf(" Frank da Cruz, Columbia University\n");
  12377.         printf(" Jeffrey Eric Altman, Secure Endpoints, Inc. %s\n",
  12378.            "<jaltman@secure-endpoints.com>"
  12379.            );
  12380.     printf(" Contributions from many others.\n");
  12381.     n = 7;
  12382.     if (*ck_s_test) {
  12383.         printf("\nTHIS IS A TEST VERSION, NOT FOR PRODUCTION USE.\n");
  12384.         n += 2;
  12385.     }
  12386.     if (*ck_patch) {
  12387.         printf(" Patches: %s\n", ck_patch);
  12388.         n++;
  12389.     }
  12390.     printf(" Type COPYRIGHT for copyright and license.\n\n");
  12391. #ifdef OS2
  12392.     shoreg();
  12393. #else
  12394. #ifdef COMMENT
  12395.     hmtopline = n+1;
  12396.     hmsga(copyright);
  12397.     hmtopline = 0;
  12398. #endif /* COMMENT */
  12399. #endif /* OS2 */
  12400.     return(success = 1);
  12401.     }
  12402.  
  12403.     if (cx == XXCPR) {            /* COPYRIGHT or LICENSE */
  12404.     if ((y = cmcfm()) < 0)
  12405.           return(y);
  12406. #ifdef OS2
  12407.     if (inserver) {            /* Free WIKSD */
  12408.         extern char * wiksdcpr[];
  12409.         hmsga(wiksdcpr);
  12410.     } else
  12411. #endif /* OS2 */
  12412.       hmsga(copyright);
  12413.     return(success = 1);
  12414.     }
  12415.  
  12416. #ifndef MAC                /* Only for multiuser systems */
  12417. #ifndef OS2
  12418. #ifndef NOFRILLS
  12419.     if (cx == XXWHO) {            /* WHO */
  12420.     char *wc;
  12421. #ifdef IKSD
  12422.     if (inserver && !ENABLED(en_who)) {
  12423.         printf("?Sorry, WHO command disabled\n");
  12424.         return(-9);
  12425.     }
  12426. #endif /* IKSD */
  12427. #ifdef datageneral
  12428.     if ((z = cmcfm()) < 0) return(z);
  12429.     if (nopush) {
  12430.         printf("?Sorry, who not allowed\n");
  12431.         return(success = 0);
  12432.     }
  12433.         xsystem(WHOCMD);
  12434. #else
  12435.     if ((y = cmtxt("user name","",&s,xxstring)) < 0) return(y);
  12436.         if (nopush) {
  12437.         printf("?Sorry, WHO command disabled\n");
  12438.         return(success = 0);
  12439.     }
  12440.     if (!(wc = getenv("CK_WHO"))) wc = WHOCMD;
  12441.     if (wc)
  12442.       if ((int) strlen(wc) > 0) {
  12443.           ckmakmsg(line,LINBUFSIZ,wc," ",s,NULL);
  12444.           xsystem(line);
  12445.       }
  12446. #endif /* datageneral */
  12447.     return(success = 1);
  12448.     }
  12449. #endif /* NOFRILLS */
  12450. #endif /* OS2 */
  12451. #endif /* MAC */
  12452.  
  12453. #ifndef NOFRILLS
  12454.     if (cx == XXWRI || cx == XXWRL || cx == XXWRBL) { /* WRITE */
  12455.     int x,y;            /* On stack in case of \fexec() */
  12456.     if ((x = cmkey(writab,nwri,"to file or log","",xxstring)) < 0) {
  12457.         if (x == -3) printf("?Write to what?\n");
  12458.         return(x);
  12459.     }
  12460.     if ((y = cmtxt("text","",&s,xxstring)) < 0) return(y);
  12461.     s = brstrip(s);
  12462.     switch (x) {
  12463.       case LOGD: y = ZDFILE; break;
  12464.       case LOGP: y = ZPFILE; break;
  12465. #ifndef NOLOCAL
  12466.       case LOGS: y = ZSFILE; break;
  12467. #endif /* NOLOCAL */
  12468.       case LOGT: y = ZTFILE; break;
  12469. #ifndef NOSPL
  12470.       case LOGW: y = ZWFILE; break;
  12471. #endif /* NOSPL */
  12472.       case LOGX:            /* SCREEN (stdout) */
  12473.       case LOGE:            /* ERROR  (stderr) */
  12474.         if (x == LOGE) {
  12475.         debug(F110,
  12476.               (cx == XXWRL) ? "WRITELN ERROR" : "WRITE ERROR", s,0);
  12477.         fprintf(stderr,"%s%s",s,(cx == XXWRL) ? "\n" : "");
  12478.         } else {
  12479.         debug(F110,
  12480.               (cx == XXWRL) ? "WRITELN SCREEN" : "WRITE SCREEN", s,0);
  12481.         printf("%s%s",s,(cx == XXWRL) ? "\n" : "");
  12482.         }
  12483.         return(success = 1);
  12484.       default: return(-2);
  12485.     }
  12486.     if (chkfn(y) > 0) {
  12487.         x = (cx == XXWRI) ? zsout(y,s) : zsoutl(y,s);
  12488.         debug(F111,"WRITE",
  12489.           (cx == XXWRI) ? "zsout" : "zsoutl",
  12490.           x);
  12491.         if (x < 0) printf("?Write error\n");
  12492.     } else {
  12493.         x = -1;
  12494.         printf("?File or log not open\n");
  12495.     }
  12496.     debug(F101,"WRITE x","",x);
  12497.     return(success = (x == 0) ? 1 : 0);
  12498.     }
  12499. #endif /* NOFRILLS */
  12500.  
  12501. #ifndef NOXFER
  12502.     if (cx == XXASC || cx == XXBIN) {
  12503.     if ((x = cmcfm()) < 0) return(x);
  12504. #ifdef NEWFTP
  12505. /*
  12506.   Make C-Kermit work like other ftp clients, where
  12507.   the ASCII (TEXT) and BINARY commands are global settings.
  12508. */
  12509.     if (ftpisopen()) {
  12510.         doftpglobaltype((cx == XXASC) ? XYFT_T : XYFT_B);
  12511.         /* Fall thru--the command it should apply to both FTP and Kermit */
  12512.         /* return(success = 1); */
  12513.     }
  12514. #endif /* NEWFTP */
  12515.  
  12516.     xfermode = XMODE_M;        /* Set manual Kermit transfer mode */
  12517.     binary = (cx == XXASC) ? XYFT_T : XYFT_B;
  12518.     return(success = 1);
  12519.     }
  12520. #endif /* NOXFER */
  12521.  
  12522.     if (cx == XXCLS) {
  12523.     if ((x = cmcfm()) < 0) return(x);
  12524.     y = ck_cls();
  12525.     return(success = (y > -1) ? 1 : 0);
  12526.     }
  12527.  
  12528. #ifdef CK_MKDIR
  12529.     if (cx == XXMKDIR || cx == XXLMKD) {
  12530.     char *p;
  12531. #ifdef LOCUS
  12532.     if (!locus && cx != XXLMKD) {
  12533. #ifdef NOXFER
  12534.         return(-2);
  12535. #else
  12536.         return(dormt(XZMKD));
  12537. #endif /* NOXFER */
  12538.         }
  12539. #endif /* LOCUS */
  12540. #ifdef IKSD
  12541.     if (inserver && !ENABLED(en_mkd)) {
  12542.         printf("?Sorry, directory creation is disabled\n");
  12543.         return(-9);
  12544.     }
  12545. #endif /* IKSD */
  12546.     if ((x = cmfld("Name for new directory","",&s,xxstring)) < 0) {
  12547.         if (x != -3) {
  12548.         return(x);
  12549.         } else {
  12550.         printf("?Directory name required\n");
  12551.         return(-9);
  12552.         }
  12553.     }
  12554.     ckstrncpy(line,s,LINBUFSIZ);
  12555.     s = line;
  12556.     if ((x = cmcfm()) < 0) return(x);
  12557.     s = brstrip(s);
  12558.     bgchk();            /* Set msgflg */
  12559.     x = ckmkdir(0,s,&p,msgflg,0);
  12560. #ifdef COMMENT
  12561.     if (msgflg && x == 0)
  12562.       printf("?Directory already exists\n");
  12563. #endif /* COMMENT */
  12564.     return(success = (x < 0) ? 0 : 1);
  12565.     }
  12566.     if (cx == XXRMDIR || cx == XXLRMD) { /* RMDIR */
  12567.     char *p;
  12568. #ifdef LOCUS
  12569.     if (!locus && cx != XXLRMD) {
  12570. #ifdef NOXFER
  12571.         return(-2);
  12572. #else
  12573.         return(dormt(XZRMD));
  12574. #endif /* NOXFER */
  12575.         }
  12576. #endif /* LOCUS */
  12577. #ifdef IKSD
  12578.     if (inserver && !ENABLED(en_rmd)) {
  12579.         printf("?Sorry, directory removal is disabled\n");
  12580.         return(-9);
  12581.     }
  12582. #endif /* IKSD */
  12583.     if ((x = cmdir("Name of directory to be removed","",&s,xxstring)) < 0)
  12584.       return(x);
  12585.     ckstrncpy(line,s,LINBUFSIZ);
  12586.     s = line;
  12587.     if ((x = cmcfm()) < 0) return(x);
  12588.     s = brstrip(s);
  12589.     x = ckmkdir(1,s,&p,msgflg,0);
  12590.     return(success = (x < 0) ? 0 : 1);
  12591.     }
  12592. #endif /* CK_MKDIR */
  12593.  
  12594. #ifdef TNCODE
  12595.     if (cx == XXTELOP)
  12596.       return(dotelopt());
  12597. #endif /* TNCODE */
  12598.  
  12599. #ifndef NOPUSH
  12600.     if (cx == XXNPSH) {
  12601.     if ((z = cmcfm()) < 0) return(z);
  12602.         nopush = 1;
  12603. #ifndef NOSERVER
  12604.         en_hos = 0;
  12605. #endif /* NOSERVER */
  12606. #ifdef PIPESEND
  12607.     usepipes = 0;
  12608. #endif /* PIPESEND */
  12609.         return(success = 1);
  12610.     }
  12611. #endif /* NOPUSH */
  12612.  
  12613. #ifdef OS2
  12614.     if (cx == XXNSCR) {
  12615.     if ((z = cmcfm()) < 0) return(z);
  12616.         tt_scroll = 0;
  12617.         return(success = 1);
  12618.     }
  12619. #endif /* OS2 */
  12620.  
  12621. #ifndef NOSPL
  12622.     if (cx == XXLOCAL)            /* LOCAL variable declarations */
  12623.       return(success = dolocal());
  12624. #endif /* NOSPL */
  12625.  
  12626.     if (cx == XXKERMI) {        /* The KERMIT command */
  12627.     char * list[65];
  12628.     extern char **xargv;
  12629.     extern int xargc;
  12630.     int i;
  12631.     if ((y = cmtxt("kermit command-line arguments, -h for help",
  12632.                "",&s,xxstring)) < 0)
  12633.       return(y);
  12634.     ckstrncpy(line,"kermit ",LINBUFSIZ);
  12635.     ckstrncat(line,s,LINBUFSIZ-8);
  12636.     xwords(line,64,list,0);
  12637.     for (i = 1; i < 64; i++) {
  12638.         if (!list[i])
  12639.           break;
  12640.     }
  12641.     i--;
  12642.     xargc = i;
  12643.     xargv = list;
  12644.     xargv++;
  12645.     sstate = cmdlin();
  12646.     if (sstate) {
  12647.         extern int justone;
  12648.         debug(F000,"KERMIT sstate","",sstate);
  12649.         justone = 1;        /* Force return to command mode */
  12650.         proto();            /* after protocol */
  12651.         return(success);
  12652.     } else {
  12653.         debug(F101,"KERMIT sstate","",sstate);
  12654.         return(success = 1);    /* Not exactly right, but... */
  12655.     }
  12656.     }
  12657.     if (cx == XXDATE) {            /* DATE command */
  12658.     extern char cmdatebuf[], * cmdatemsg;
  12659.  
  12660. #ifndef COMMENT
  12661.     char * dp;
  12662.     if ((y = cmtxt("date and/or time, or carriage return for current",
  12663.                "",&s,xxstring)) < 0)
  12664.       return(y);
  12665.     s = brstrip(s);
  12666.     dp = cmcvtdate(s,1);
  12667.     if (!dp) {
  12668.         printf("?%s\n",cmdatemsg ? cmdatemsg : "Date conversion error");
  12669.         success = 0;
  12670.     } else {
  12671.         printf("%s\n",dp);
  12672.         success = 1;
  12673.     }
  12674. #else
  12675.     /* This works fine but messes up my "dates" torture-test script */
  12676.  
  12677.     if ((x = cmdate("Date and/or time, or carriage return for current",
  12678.             "",&s,0,xxstring)) < 0) {
  12679.         return(x);
  12680.     } else {
  12681.         printf("%s\n",cmdatebuf);
  12682.         success = 1;
  12683.     }
  12684. #endif /* COMMENT */
  12685.     return(success);
  12686.     }
  12687. #ifndef NOPUSH
  12688. #ifndef NOFRILLS
  12689.     if (cx == XXEDIT)
  12690.       return(doedit());
  12691. #endif /* NOFRILLS */
  12692. #endif /* NOPUSH */
  12693.  
  12694. #ifdef BROWSER                /* Defined only ifndef NOPUSH */
  12695.     if (cx == XXBROWS)
  12696.       return(dobrowse());
  12697. #endif /* BROWSER */
  12698.  
  12699. #ifdef CK_TAPI
  12700.     if (cx == XXTAPI) {            /* Microsoft TAPI */
  12701.     return (success = dotapi());
  12702.     }
  12703. #endif /* CK_TAPI */
  12704.  
  12705. #ifndef NOXFER
  12706.     if (cx == XXWHERE) {
  12707.     extern char * rfspec, * sfspec, * srfspec, * rrfspec;
  12708.     if ((x = cmcfm()) < 0) return(x);
  12709.     printf("\nFile most recently...\n\n");
  12710.     printf("  Sent:       %s\n",   sfspec ? sfspec : "(none)");
  12711.     if (sfspec && srfspec) {
  12712.         printf("  Stored as:  %s\n",   srfspec);
  12713.         printf("\n");
  12714.     }
  12715.     printf("  Received:   %s\n",   rrfspec ? rrfspec : "(none)");
  12716.     if (rfspec && rrfspec)
  12717.     printf("  Stored as:  %s\n",   rfspec);
  12718.     printf(
  12719. "\nIf the full path is not shown, then the file is probably in your current\n"
  12720.            );
  12721.     printf(
  12722. "directory or your download directory (if any - SHOW FILE to find out).\n\n"
  12723.            );
  12724.     return(success = 1);
  12725.     }
  12726. #endif /* NOXFER */
  12727.  
  12728. #ifdef CK_RECALL
  12729.     if (cx == XXREDO)
  12730.       return(doredo());
  12731. #endif /* CK_RECALL */
  12732.  
  12733. #ifdef CKROOT
  12734.     if (cx == XXCHRT)            /* Change Kermit's root directory */
  12735.       return(dochroot());
  12736. #endif /* CKROOT */
  12737.  
  12738. #ifdef CK_KERBEROS
  12739.     if (cx == XXAUTH) {            /* KERBEROS */
  12740.     x = cp_auth();            /* Parse it */
  12741. #ifdef IKSD
  12742.         if (inserver) {
  12743.             printf("?Command disabled in IKSD.\r\n");
  12744.             return(success = 0);
  12745.         }
  12746. #endif /* IKSD */
  12747.     if (x < 0)            /* Pass parse errors back */
  12748.       return(x);
  12749.     return(success = doauth(cx));
  12750.     }
  12751. #endif /* CK_KERBEROS */
  12752.  
  12753. #ifndef NOLOCAL
  12754.     if (cx == XXTERM) {
  12755.     return(settrmtyp());
  12756.     }
  12757. #endif /* NOLOCAL */
  12758.  
  12759.     if (cx == XXSTATUS) {
  12760.     if ((x = cmcfm()) < 0) return(x);
  12761.     printf( " %s\n", success ? "SUCCESS" : "FAILURE" );
  12762.     return(0);            /* Don't change it */
  12763.     }
  12764.  
  12765.     if (cx == XXFAIL) {
  12766.     if ((x = cmcfm()) < 0) return(x);
  12767.     return(success = 0);
  12768.     }
  12769.  
  12770.     if (cx == XXSUCC) {
  12771.     if ((x = cmcfm()) < 0) return(x);
  12772.     return(success = 1);
  12773.     }
  12774.  
  12775.     if (cx == XXNLCL) {
  12776.     extern int nolocal;
  12777.     if ((x = cmcfm()) < 0) return(x);
  12778.     nolocal = 1;
  12779.     return(success = 1);
  12780.     }
  12781.  
  12782. #ifndef NOXFER
  12783.     if (cx == XXRASG)            /* Shortcuts for REMOTE commands */
  12784.       return(dormt(XZASG));
  12785.     if (cx == XXRCWD)
  12786.       return(dormt(XZCWD));
  12787.     if (cx == XXRCPY)
  12788.       return(dormt(XZCPY));
  12789.     if (cx == XXRDEL)
  12790.       return(dormt(XZDEL));
  12791.     if (cx == XXRDIR)
  12792.       return(dormt(XZDIR));
  12793.     if (cx == XXRXIT)
  12794.       return(dormt(XZXIT));
  12795.     if (cx == XXRHLP)
  12796.       return(dormt(XZHLP));
  12797.     if (cx == XXRHOS)
  12798.       return(dormt(XZHOS));
  12799.     if (cx == XXRKER)
  12800.       return(dormt(XZKER));
  12801.     if (cx == XXRPWD)
  12802.       return(dormt(XZPWD));
  12803.     if (cx == XXRQUE)
  12804.       return(dormt(XZQUE));
  12805.     if (cx == XXRREN)
  12806.       return(dormt(XZREN));
  12807.     if (cx == XXRMKD)
  12808.       return(dormt(XZMKD));
  12809.     if (cx == XXRMSG)
  12810.       return(dormt(XZMSG));
  12811.     if (cx == XXRRMD)
  12812.       return(dormt(XZRMD));
  12813.     if (cx == XXRSET)
  12814.       return(dormt(XZSET));
  12815.     if (cx == XXRSPA)
  12816.       return(dormt(XZSPA));
  12817.     if (cx == XXRTYP)
  12818.       return(dormt(XZTYP));
  12819.     if (cx == XXRWHO)
  12820.       return(dormt(XZWHO));
  12821.     if (cx == XXRCDUP)
  12822.       return(dormt(XZCDU));
  12823.     if (cx == XXRPRI)
  12824.       return(dormt(XZPRI));
  12825. #endif /* NOXFER */
  12826.  
  12827.     if (cx == XXRESET) {        /* RESET */
  12828.     if ((x = cmcfm()) < 0)
  12829.       return(x);
  12830.     concb((char)escape);        /* Make command echoing to normal */
  12831.     doclean(0);            /* Close all files */
  12832.     return(success = 1);
  12833.     }
  12834.  
  12835. #ifndef NOXFER
  12836. #ifndef NOCSETS
  12837.     if (cx == XXASSOC)            /* ASSOCIATE */
  12838.       return(doassoc());
  12839. #endif /* NOCSETS */
  12840. #endif /* NOXFER */
  12841.  
  12842. #ifndef NOSPL
  12843.     if (cx == XXSHIFT) {        /* SHIFT */
  12844.     if ((y = cmnum("Number of arguments to shift","1",10,&x,xxstring)) < 0)
  12845.       return(y);
  12846.     if ((z = cmcfm()) < 0)
  12847.       return(z);
  12848.     return(success = doshift(x));
  12849.     }
  12850. #endif /* NOSPL */
  12851.  
  12852. #ifndef NOHELP
  12853.     if (cx == XXMAN)
  12854.       return(domanual());
  12855. #endif /* NOHELP */
  12856.  
  12857. #ifndef NOSPL
  12858.     if (cx == XXSORT)            /* SORT an array */
  12859.       return(dosort());
  12860. #endif /* NOSPL */
  12861.  
  12862.     if (cx == XXPURGE) {
  12863. #ifdef IKSD
  12864.     if (inserver && (!ENABLED(en_del)
  12865. #ifdef CK_LOGIN
  12866.                           || isguest
  12867. #endif /* CK_LOGIN */
  12868.              )) {
  12869.         printf("?Sorry, DELETE is disabled\n");
  12870.         return(-9);
  12871.     }
  12872. #endif /* IKSD */
  12873. #ifdef CK_APC
  12874.     if ((apcactive == APC_LOCAL) ||
  12875.         ((apcactive == APC_REMOTE) && (!(apcstatus & APC_UNCH))))
  12876.       return(success = 0);
  12877. #endif /* CK_APC */
  12878. #ifdef CKPURGE
  12879.         return(dopurge());
  12880. #else
  12881. #ifdef VMS
  12882.     if ((x = cmtxt("optional switches followed by filespec",
  12883.                "",&s,xxstring)) < 0)
  12884.       return(x);
  12885.     if (nopush) {
  12886.         printf("?Sorry, DCL access is disabled\n");
  12887.         return(-9);
  12888.     }
  12889.     ckstrncpy(line,s,LINBUFSIZ);
  12890.     s = line;
  12891.     x = mlook(mactab,"purge",nmac);
  12892.     return(success = dodo(x,s,cmdstk[cmdlvl].ccflgs));
  12893. #else
  12894.     return(-2);
  12895. #endif /* VMS */
  12896. #endif /* CKPURGE */
  12897.     }
  12898.  
  12899. #ifndef NOSPL
  12900.     if (cx == XXFAST) {
  12901.     if ((x = cmcfm()) < 0) return(x);
  12902.     x = mlook(mactab,"fast",nmac);
  12903.     return(success = dodo(x,NULL,cmdstk[cmdlvl].ccflgs));
  12904.     }
  12905.     if (cx == XXCAU) {
  12906.     if ((x = cmcfm()) < 0) return(x);
  12907.     x = mlook(mactab,"cautious",nmac);
  12908.     return(success = dodo(x,NULL,cmdstk[cmdlvl].ccflgs));
  12909.     }
  12910.     if (cx == XXROB) {
  12911.     if ((x = cmcfm()) < 0) return(x);
  12912.     x = mlook(mactab,"robust",nmac);
  12913.     return(success = dodo(x,NULL,cmdstk[cmdlvl].ccflgs));
  12914.     }
  12915. #endif /* NOSPL */
  12916.  
  12917.     if (cx == XXSCRN) {            /* SCREEN */
  12918.     int row, col;
  12919.     if ((x = cmkey(scntab, nscntab,"screen action","", xxstring)) < 0)
  12920.       return(x);
  12921.     switch (x) {            /* MOVE-TO (cursor position) */
  12922.       case SCN_MOV:
  12923.         if ((y = cmnum("Row (1-based)","",10,&z,xxstring)) < 0)
  12924.           return(y);
  12925.         row = z;
  12926.         y = cmnum("Column (1-based)","1",10,&z,xxstring);
  12927.         if (y < 0)
  12928.           return(y);
  12929.         col = z;
  12930.         if ((y = cmcfm()) < 0)
  12931.           return(y);
  12932.         if (row < 0 || col < 0) {
  12933.         printf("?Row and Column must be 1 or greater\n");
  12934.         return(-9);
  12935.         }
  12936.         if (cmd_rows > 0 && row > cmd_rows)
  12937.           row = cmd_rows;
  12938.         if (cmd_cols > 0 && col > cmd_cols)
  12939.           col = cmd_cols;
  12940.         y = ck_curpos(row,col);
  12941.         return(success = (y > -1) ? 1 : 0);
  12942.  
  12943.       case SCN_CLR:            /* CLEAR */
  12944.         if ((y = cmcfm()) < 0)
  12945.           return(y);
  12946.         debug(F100,"screen calling ck_cls()","",0);
  12947.         y = ck_cls();
  12948.         return(success = (y > -1) ? 1 : 0);
  12949.  
  12950.       case SCN_CLE:            /* CLEOL */
  12951.         if ((y = cmcfm()) < 0)
  12952.           return(y);
  12953.         y = ck_cleol();
  12954.         return(success = (y > -1) ? 1 : 0);
  12955.     }
  12956.     }
  12957.  
  12958. #ifndef NOHTTP
  12959. #ifdef TCPSOCKET
  12960.     if (cx == XXHTTP)
  12961.       return(dohttp());
  12962. #endif /* TCPSOCKET */
  12963. #endif /* NOHTTP */
  12964.  
  12965. #ifndef NOSPL
  12966.     if (cx == XXARRAY) {        /* ARRAY */
  12967. #ifndef NOSHOW
  12968.     extern int showarray();
  12969. #endif /* NOSHOW */
  12970.     if ((x = cmkey(arraytab, narraytab,"Array operation","",xxstring)) < 0)
  12971.       return(x);
  12972.     switch (x) {
  12973.       case ARR_DCL:
  12974.         return(dodcl(XXDCL));
  12975.       case ARR_SRT:
  12976.         return(dosort());
  12977. #ifndef NOSHOW
  12978.       case ARR_SHO:
  12979.         return(showarray());
  12980. #endif /* NOSHOW */
  12981.       case ARR_CPY:
  12982.         return(copyarray());
  12983.       case ARR_SET:
  12984.       case ARR_CLR:
  12985.         return(clrarray(x));
  12986.       case ARR_DST:
  12987.         return(unarray());
  12988.       case ARR_RSZ:
  12989.         return(rszarray());
  12990.       case ARR_EQU:
  12991.         return(linkarray());
  12992.  
  12993.       default:
  12994.         printf("?Sorry, not implemented yet - \"%s\"\n",cmdbuf);
  12995.         return(-9);
  12996.     }
  12997.     }
  12998.     if (cx == XXTRACE)            /* TRACE */
  12999.       return(dotrace());
  13000. #endif /* NOSPL */
  13001.  
  13002. #ifdef CK_PERMS
  13003. #ifdef UNIX
  13004.     if (cx == XXCHMOD)
  13005.       return(douchmod());        /* Do Unix chmod */
  13006. #endif /* UNIX */
  13007. #endif /* CK_PERMS */
  13008.  
  13009.     if (cx == XXPROMP)
  13010.       return(doprompt());
  13011.  
  13012.     if (cx == XXGREP)
  13013.       return(dogrep());
  13014.  
  13015.     if (cx == XXDEBUG) {        /* DEBUG */
  13016. #ifndef DEBUG
  13017.     int dummy = 0;
  13018.     return(seton(&dummy));
  13019. #else
  13020.     return(seton(&deblog));
  13021. #endif /* DEBUG */
  13022.     }
  13023.     if (cx == XXMSG) {            /* MESSAGE */
  13024.     extern int debmsg;        /* Script debugging messages */
  13025.     if ((x = cmtxt("Message to print if SET DEBUG is ON or STDERR",
  13026.          "",&s,xxstring)) < 0)
  13027.       return(x);
  13028.     if (!s)                /* Watch out for null result */
  13029.       s = "";            /* Make it an empty string */
  13030.     else                 /* Not null */
  13031.       s = brstrip(s);        /* Strip braces and doublequotes */
  13032.     switch (debmsg) {        /* Not debugging - don't print */
  13033.       case 0:
  13034.         break;
  13035.       case 1:
  13036.         printf("%s\n",s);        /* Print to stdout */
  13037.         break;
  13038.       case 2:
  13039.         fprintf(stderr,"%s\n",s);    /* Ditto but print to stderr */
  13040.         break;
  13041.     }
  13042.     return(0);            /* Return without affecting SUCCESS */
  13043.     }
  13044.  
  13045. #ifdef CKLEARN
  13046.     if (cx == XXLEARN) {        /* LEARN */
  13047.     struct FDB of, sw, cm;
  13048.     int closing = 0, off = 0, on = 0, confirmed = 0;
  13049.     char c;
  13050.  
  13051.     cmfdbi(&sw,            /* 2nd FDB - optional /PAGE switch */
  13052.            _CMKEY,            /* fcode */
  13053.            "Script file name, or switch", /* hlpmsg */
  13054.            "",            /* default */
  13055.            "",            /* addtl string data */
  13056.            3,            /* addtl numeric data 1: tbl size */
  13057.            4,            /* addtl numeric data 2: 4 = cmswi */
  13058.            xxstring,        /* Processing function */
  13059.            learnswi,        /* Keyword table */
  13060.            &of            /* Pointer to next FDB */
  13061.            );
  13062.     cmfdbi(&of,_CMOFI,"","","",0,0,xxstring,NULL,&cm);
  13063.     cmfdbi(&cm,_CMCFM,"","","",0,0,NULL,NULL,NULL);
  13064.     line[0] = NUL;
  13065.  
  13066.     while (!confirmed) {
  13067.         x = cmfdb(&sw);        /* Parse something */
  13068.         if (x < 0)
  13069.           return(x);
  13070.         switch (cmresult.fcode) {    /* What was it? */
  13071.           case _CMOFI:        /* Output file name */
  13072.         ckstrncpy(line,cmresult.sresult,LINBUFSIZ);
  13073.         break;
  13074.           case _CMKEY:        /* Switch */
  13075.         c = cmgbrk();
  13076.         if ((c == ':' || c == '=') && !(cmgkwflgs() & CM_ARG)) {
  13077.             printf("?This switch does not take an argument\n");
  13078.             return(-9);
  13079.         }
  13080.         switch (cmresult.nresult) {
  13081.           case 2:        /* /CLOSE */
  13082.             closing = 1;    /* Fall thru on purpose */
  13083.           case 0:        /* /OFF */
  13084.             off = 1;
  13085.             on = 0;
  13086.             break;
  13087.           case 1:        /* /ON */
  13088.             on = 1;
  13089.             off = 0;
  13090.             break;
  13091.         }
  13092.         break;
  13093.           case _CMCFM:        /* Confirmation */
  13094.         confirmed++;
  13095.         break;
  13096.         }
  13097.     }
  13098.     if (closing) {
  13099.         if (learnfp) {
  13100.         fclose(learnfp);
  13101.         learnfp = NULL;
  13102.         }
  13103.         makestr(&learnfile,NULL);
  13104.     }
  13105.     if (line[0]) {
  13106.         if (!on && !off)
  13107.           on = 1;
  13108.         if (learnfp) {
  13109.         fclose(learnfp);
  13110.         learnfp = NULL;
  13111.         }
  13112.         makestr(&learnfile,line);
  13113.         if (learnfile) {
  13114.         char * modes = "w";
  13115.         learnfp = fopen(learnfile,modes);
  13116.         if (!learnfp) {
  13117.             debug(F110,"LEARN file open error",learnfile,0);
  13118.             perror(learnfile);
  13119.             return(-9);
  13120.         } else {
  13121. #ifdef ZFNQFP
  13122.             if (zfnqfp(learnfile,TMPBUFSIZ,tmpbuf))
  13123.               makestr(&learnfile,tmpbuf);
  13124. #endif /* ZFNQFP */
  13125.             debug(F110,"LEARN file open ok",learnfile,0);
  13126.             if (!quiet) {
  13127.             printf("Recording to %s...\n\n",learnfile);
  13128.             printf(
  13129. " WARNING: If you type your password during script recording, it will appear\n\
  13130.  in the file.  Be sure to edit it or take other appropriate precautions.\n\n"
  13131.                    );
  13132.             }
  13133.             fputs(  "; Scriptfile: ",learnfp);
  13134.             fputs(learnfile,learnfp);
  13135.             fputs("\n; Directory:  ",learnfp);
  13136.             fputs(zgtdir(),learnfp);
  13137.             fputs("\n; Recorded:   ",learnfp);
  13138.             fputs(ckdate(),learnfp);
  13139.             fputs("\n",learnfp);
  13140.         }
  13141.         }
  13142.     }
  13143.     if (on) {
  13144.         learning = 1;
  13145.     } else if (off) {
  13146.         learning = 0;
  13147.     }
  13148.     debug(F101,"LEARN learning","",learning);
  13149.     return(success = 1);
  13150.     }
  13151. #endif /* CKLEARN */
  13152.  
  13153. #ifdef NEWFTP
  13154.     if (cx == XXUSER || cx == XXACCT) {
  13155.     if (!ftpisopen()) {
  13156.         printf("?FTP connection is not open\n");
  13157.         return(-9);
  13158.     }
  13159.     return(success = (cx == XXUSER) ? doftpusr() : doftpacct());
  13160.     }
  13161.     if (cx == XXSITE || cx == XXPASV) {
  13162.     if (!ftpisopen()) {
  13163.         printf("?FTP connection is not open\n");
  13164.         return(-9);
  13165.     }
  13166.     return(success = (cx == XXSITE) ? doftpsite() : dosetftppsv());
  13167.     }
  13168. #endif /* NEWFTP */
  13169.  
  13170.     if (cx == XXORIE) {            /* ORIENTATION */
  13171.     extern char * myname;
  13172.     int i, y, n = 0;
  13173.         char * s, *p, vbuf[32];
  13174.     char * vars[16];       char * legend[16];
  13175.  
  13176.     if ((y = cmcfm()) < 0)
  13177.       return(y);
  13178.  
  13179.     printf("\nProgram name:\n  %s\n\n",myname);
  13180.     n += 4;
  13181.  
  13182. #ifdef NT
  13183.     vars[0] = "home";      legend[0] = "Your home directory";
  13184.     vars[1] = "directory"; legend[1] = "K95's current directory";
  13185.     vars[2] = "exedir";    legend[2] = "K95 Program directory";
  13186.     vars[3] = "inidir";    legend[3] = "K95 Initialization file directory";
  13187.     vars[4] = "startup";   legend[4] = "Current directory when started";
  13188.     
  13189.         vars[5] = "common";
  13190.         legend[5] = "K95 data for all users and K95SITE.INI file";
  13191.     
  13192.         vars[6] = "personal";  legend[6] = "Your personal data directory tree";
  13193.         vars[7] = "desktop";   legend[7] = "Your deskop directory tree";
  13194.     
  13195.         vars[8] = "appdata";
  13196.         legend[8] = "Your personal K95 data tree and K95CUSTOM.INI file";
  13197.     
  13198.         vars[9] = "download";  legend[9] = "Your K95 download directory";
  13199.         vars[10] = "tmpdir";   legend[10] = "Your TEMP directory";
  13200.     vars[11] = NULL;       legend[11] = NULL;
  13201.  
  13202.     for (i = 0; i < 16 && vars[i]; i++) {
  13203.         printf("%s:\n",legend[i]);
  13204.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13205.         ckmakmsg(vbuf,32,"\\v(",vars[i],")",NULL);
  13206.         printf("  Variable:   %s\n",vbuf);
  13207.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13208.         y = TMPBUFSIZ;
  13209.         s = tmpbuf;
  13210.         zzstring(vbuf,&s,&y);
  13211.         line[0] = NUL;
  13212.         ckGetLongPathName(tmpbuf,line,LINBUFSIZ);
  13213.         printf("  Long name:  %s\n",line);
  13214.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13215.         line[0] = NUL;
  13216.         GetShortPathName(tmpbuf,line,LINBUFSIZ);
  13217.         printf("  Short name: %s\n",line);
  13218.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13219.             printf("\n");
  13220.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13221.     }
  13222. #else  /* NT */
  13223.  
  13224.     vars[0] = "home";      legend[0] = "Your home directory";
  13225.     vars[1] = "directory"; legend[1] = "Kermit's current directory";
  13226.     vars[2] = "exedir";    legend[2] = "Kermit's program directory";
  13227.     vars[3] = "inidir";    legend[3] = "Initialization file directory";
  13228.     vars[4] = "startup";   legend[4] = "Current directory when started";
  13229.     vars[5] = "download";  legend[5] = "Kermit download directory";
  13230.     vars[6] = NULL;           legend[6] = NULL;
  13231.  
  13232.     for (i = 0; i < 16 && vars[i]; i++) {
  13233.         printf("%s:\n",legend[i]);
  13234.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13235.         ckmakmsg(vbuf,32,"\\v(",vars[i],")",NULL);
  13236.         printf("  Variable: %s\n",vbuf);
  13237.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13238.         y = TMPBUFSIZ;
  13239.         s = tmpbuf;
  13240.         zzstring(vbuf,&s,&y);
  13241.             printf("  Value:    %s\n",tmpbuf);
  13242.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13243.             printf("\n");
  13244.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13245.     }
  13246. #endif /* NT */
  13247.     return(success = 1);
  13248.     }
  13249.  
  13250. #ifdef NT
  13251.     if (cx == XXDIALER) {
  13252.         StartDialer();
  13253.         return(success = 1);
  13254.     }
  13255. #endif /* NT */
  13256.  
  13257.     if (cx == XXCONT) {            /* CONTINUE */
  13258.     if ((x = cmcfm()) < 0)
  13259.       return(x);
  13260.     if (!xcmdsrc) {            /* At prompt: continue script */
  13261.         if (cmdlvl > 0)
  13262.           popclvl();        /* Pop command level */
  13263.         return(success = 1);    /* always succeeds */
  13264. #ifndef NOSPL
  13265.     } else {            /* In script: whatever... */
  13266.         x = mlook(mactab,"continue",nmac);
  13267.         /* Don't set success */
  13268.         return(dodo(x,NULL,cmdstk[cmdlvl].ccflgs));
  13269. #endif /* NOSPL */
  13270.     }
  13271.     }
  13272. #ifdef UNIX
  13273. #ifndef NOPUTENV
  13274. /*
  13275.   NOTE: Syntax is PUTENV name value, not PUTENV name=value.
  13276.   I could check for this but it would be too much magic.
  13277. */
  13278.     if (cx == XXPUTE) {            /* PUTENV */
  13279.         char * t = tmpbuf;        /* Create or alter environment var */
  13280.     char * s1 = NULL, * s2 = NULL;
  13281.     if ((x = cmfld("Variable name","",&s,xxstring)) < 0)
  13282.           return(x);
  13283.     if (s) if (s == "") s = NULL;
  13284.     (VOID) makestr(&s1,s);
  13285.     if (s && !s1) {
  13286.         printf("?PUTENV - memory allocation failure\n");
  13287.         return(-9);
  13288.     }
  13289.     if ((x = cmtxt("Value","",&s,xxstring)) < 0)
  13290.       return(x);
  13291.     if (s) if (s == "") s = NULL;
  13292.     (VOID) makestr(&s2,s);
  13293.     success = doputenv(s1,s2);
  13294.     (VOID) makestr(&s1,NULL);
  13295.     (VOID) makestr(&s2,NULL);
  13296.     return(success);
  13297.     }
  13298. #endif    /* NOPUTENV */
  13299. #endif    /* UNIX */
  13300.  
  13301.     if (cx == XXNOTAV) {        /* Command in table not available */
  13302.     ckstrncpy(tmpbuf,atmbuf,TMPBUFSIZ);
  13303.     if ((x = cmtxt("Rest of command","",&s,NULL)) < 0)
  13304.       return(x);
  13305.     printf("Sorry, \"%s\" not configured in this version of Kermit.\n",
  13306.            tmpbuf
  13307.            );
  13308.     return(success = 0);
  13309.     }
  13310.     return(-2);                /* None of the above */
  13311.  
  13312. } /* end of docmd() */
  13313.  
  13314. #endif /* NOICP */
  13315.