home *** CD-ROM | disk | FTP | other *** search
/ kermit.columbia.edu / kermit.columbia.edu.tar / kermit.columbia.edu / tmp4 / ckuusr.c < prev    next >
C/C++ Source or Header  |  2009-11-10  |  366KB  |  13,247 lines

  1. #ifdef SSHTEST
  2. #define SSHBUILTIN
  3. #endif /* SSHTEST */
  4.  
  5. #include "ckcsym.h"
  6. char *userv = "User Interface 9.0.295, 10 November 2009";
  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, 2009,
  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, CM_INV },
  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. #ifdef CK_MINPUT
  1145.     { "minput",      XXMINP, 0 },    /* MINPUT */
  1146. #else
  1147.     { "minput",      XXNOTAV, CM_INV },
  1148. #endif /* CK_MINPUT */
  1149. #ifndef NOMSEND
  1150.     { "mget",        XXMGET, 0 },    /* MGET */
  1151. #else
  1152.     { "mget",        XXNOTAV, CM_INV },
  1153. #endif /* NOMSEND */
  1154. #ifdef CK_MKDIR
  1155.     { "mkdir",       XXMKDIR, 0 },    /* MKDIR */
  1156. #else
  1157.     { "mkdir",       XXNOTAV, CM_INV },
  1158. #endif /* CK_MKDIR */
  1159.  
  1160. #ifndef NOXFER
  1161. #ifndef NOMSEND
  1162.     { "mmove",       XXMMOVE, 0 },    /* MMOVE */
  1163. #else
  1164.     { "mmove",       XXNOTAV, CM_INV },
  1165. #endif /* NOMSEND */
  1166. #endif /* NOXFER */
  1167.  
  1168. #ifndef NOFRILLS
  1169.     { "more",        XXMORE, CM_INV },    /* MORE */
  1170. #endif /* NOFRILLS */
  1171.  
  1172. #ifndef NOXFER
  1173.     { "move",        XXMOVE, 0 },    /* MOVE  */
  1174. #endif /* NOXFER */
  1175.  
  1176. #ifndef NOSPL
  1177.     { "mpause",      XXMSL, CM_INV },    /* Millisecond sleep */
  1178. #else
  1179.     { "mpause",      XXNOTAV, CM_INV },
  1180. #endif /* NOSPL */
  1181.  
  1182. #ifndef NOXFER
  1183. #ifndef NOMSEND
  1184.     { "mput",        XXMSE, CM_INV },    /* MPUT = MSEND */
  1185.     { "ms",          XXMSE, CM_INV|CM_ABR },
  1186.     { "msend",       XXMSE, 0 },    /* Multiple SEND */
  1187. #else
  1188.     { "mput",        XXNOTAV, CM_INV },
  1189.     { "msend",       XXNOTAV, CM_INV },
  1190. #endif /* NOMSEND */
  1191. #endif /* NOXFER */
  1192. #ifndef NOSPL
  1193.     { "msleep",      XXMSL, 0 },    /* Millisecond sleep */
  1194. #else
  1195.     { "msleep",      XXNOTAV, CM_INV },
  1196. #endif /* NOSPL */
  1197. #ifndef NOFRILLS
  1198.     { "mv",          XXREN, CM_INV },    /* Synonym for rename */
  1199. #endif /* NOFRILLS */
  1200. #ifndef NOHELP
  1201.     { "news",        XXNEW, CM_INV },    /* Display NEWS of new features */
  1202. #else
  1203.     { "news",        XXNOTAV, CM_INV },
  1204. #endif /* NOHELP */
  1205.     { "nolocal",     XXNLCL, CM_INV },    /* Disable SET LINE / SET HOST */
  1206.     { "nopush",      XXNPSH, CM_INV },    /* Disable PUSH command/features */
  1207. #ifdef OS2
  1208.     { "noscroll",    XXNSCR, CM_INV },  /* Disable scroll operations */
  1209. #endif /* OS2 */
  1210. #ifndef NOSPL
  1211.     { "o",           XXOUT, CM_INV|CM_ABR }, /* Invisible synonym for OUTPUT */
  1212.     { "open",        XXOPE, 0 },    /* OPEN file for reading or writing */
  1213. #else
  1214.     { "open",        XXOPE, CM_INV },    /* OPEN */
  1215. #endif /* NOSPL */
  1216. #ifndef NOHELP
  1217.     { "options",     XXOPTS,CM_INV|CM_HLP }, /* Options */
  1218. #endif /* NOHELP */
  1219.     { "orientation", XXORIE, 0 },
  1220. #ifndef NOSPL
  1221.     { "output",      XXOUT, 0 },    /* OUTPUT text to comm device */
  1222. #else
  1223.     { "output",      XXNOTAV, CM_INV },
  1224. #endif /* NOSPL */
  1225. #ifdef ANYX25
  1226. #ifndef IBMX25
  1227.     { "pad",         XXPAD, CM_LOC },    /* X.3 PAD commands */
  1228. #endif /* IBMX25 */
  1229. #endif /* ANYX25 */
  1230.  
  1231. #ifdef NEWFTP
  1232.     { "passive",     XXPASV, CM_INV },    /* (FTP) PASSIVE */
  1233. #endif /* NEWFTP */
  1234.  
  1235. #ifndef NOHELP
  1236.     { "patterns",    XXPAT,CM_INV|CM_HLP }, /* Pattern syntax */
  1237. #endif /* NOHELP */
  1238.  
  1239. #ifndef NOSPL
  1240.     { "pause",       XXPAU, 0 },    /* Sleep for specified interval */
  1241. #else
  1242.     { "pause",       XXNOTAV, CM_INV },
  1243. #endif /* NOSPL */
  1244. #ifndef NODIAL
  1245.     { "pdial",       XXPDIA,  CM_LOC },    /* PDIAL (partial dial) */
  1246. #else
  1247.     { "pdial",       XXNOTAV, CM_INV|CM_LOC },
  1248. #endif /* NODIAL */
  1249. #ifdef TCPSOCKET
  1250. #ifndef NOPUSH
  1251.     { "ping",        XXPNG, CM_INV|CM_PSH|CM_LOC }, /* PING */
  1252. #else
  1253.     { "ping",        XXNOTAV, CM_INV|CM_PSH|CM_LOC },
  1254. #endif /* NOPUSH */
  1255. #endif /* TCPSOCKET */
  1256. #ifdef NETCMD
  1257. #ifndef NOPUSH
  1258.     { "pipe",        XXPIPE, CM_PSH },    /* PIPE */
  1259. #else
  1260.     { "pipe",        XXNOTAV, CM_INV|CM_PSH }, /* PIPE */
  1261. #endif /* NOPUSH */
  1262. #endif /* NETCMD */
  1263.  
  1264. #ifndef NOSPL
  1265.     { "pop",         XXEND, CM_INV },    /* Invisible synonym for END */
  1266. #endif /* NOSPL */
  1267. #ifndef NOFRILLS
  1268.     { "print",       XXPRI, 0 },    /* PRINT a file locally */
  1269. #endif /* NOFRILLS */
  1270.  
  1271.     { "prompt",      XXPROMP, CM_INV },    /* Go interactive (from script) */
  1272.  
  1273. #ifndef NOXFER
  1274. #ifdef CK_RESEND
  1275.     { "psend",       XXPSEN, CM_INV },    /* PSEND */
  1276. #else
  1277.     { "psend",       XXNOTAV, CM_INV },
  1278. #endif /* CK_RESEND */
  1279. #endif /* NOXFER */
  1280.  
  1281. #ifdef NETPTY
  1282.     { "pty",         XXPTY, CM_PSH },    /* PTY */
  1283. #else
  1284.     { "pty",         XXNOTAV, CM_INV|CM_PSH },
  1285. #endif /* NETPTY */
  1286.  
  1287. #ifndef NOPUSH
  1288.     { "pu",          XXSHE, CM_INV|CM_ABR|CM_PSH }, /* PU = PUSH */
  1289. #endif /* NOPUSH */
  1290.  
  1291. #ifdef CKPURGE
  1292.     { "purge",       XXPURGE, 0 },    /* PURGE (real) */
  1293. #else
  1294. #ifdef VMS
  1295.     { "purge",       XXPURGE, 0 },    /* PURGE (fake) */
  1296. #else
  1297.     { "purge",       XXNOTAV, CM_INV },
  1298. #endif /* VMS */
  1299. #endif /* CKPURGE */
  1300.  
  1301. #ifndef NOPUSH
  1302.     { "push",        XXSHE, CM_PSH },    /* PUSH command (like RUN, !) */
  1303. #else
  1304.     { "push",        XXNOTAV, CM_INV|CM_PSH },
  1305. #endif /* NOPUSH */
  1306.  
  1307. #ifndef NOXFER
  1308.     { "put",         XXSEN, CM_INV },    /* PUT = SEND */
  1309. #endif /* NOXFER */
  1310.  
  1311. #ifdef UNIX
  1312. #ifndef NOPUTENV
  1313.     { "putenv",      XXPUTE, CM_INV },    /* PUTENV */
  1314. #endif    /* NOPUTENV */
  1315. #endif    /* UNIX */
  1316.  
  1317.     { "pwd",         XXPWD, 0 },    /* Print Working Directory */
  1318.     { "q",           XXQUI, CM_INV|CM_ABR }, /* Invisible synonym for QUIT */
  1319.  
  1320. #ifndef NOXFER
  1321.     { "query",       XXRQUE,CM_INV },    /* (= REMOTE QUERY) */
  1322. #endif /* NOXFER */
  1323.  
  1324.     { "quit",        XXQUI, 0 },    /* QUIT from program = EXIT */
  1325.  
  1326. #ifndef NOXFER
  1327.     { "r",           XXREC, CM_INV|CM_ABR }, /* Inv synonym for RECEIVE */
  1328. #endif /* NOXFER */
  1329.  
  1330. #ifndef NOXFER
  1331.     { "rasg",        XXRASG, CM_INV },    /* REMOTE ASSIGN */
  1332.     { "rassign",     XXRASG, CM_INV },    /* ditto */
  1333.     { "rcd",         XXRCWD, CM_INV },    /* REMOTE CD */
  1334.     { "rcdup",       XXRCDUP,CM_INV },    /* REMOTE CD */
  1335.     { "rcopy",       XXRCPY, CM_INV },    /* REMOTE COPY */
  1336.     { "rcwd",        XXRCWD, CM_INV },    /* REMOTE CWD */
  1337.     { "rdelete",     XXRDEL, CM_INV },    /* REMOTE DELETE */
  1338.     { "rdirectory",  XXRDIR, CM_INV },    /* REMODE DIRECTORY */
  1339. #endif /* NOXFER */
  1340.  
  1341. #ifndef NOSPL
  1342.     { "read",        XXREA, 0 },    /* READ a line from a file */
  1343. #else
  1344.     { "read",        XXNOTAV, CM_INV },
  1345. #endif /* NOSPL */
  1346.  
  1347. #ifndef NOXFER
  1348.     { "receive",     XXREC, 0 },    /* RECEIVE files */
  1349. #endif /* NOXFER */
  1350.  
  1351. #ifndef NODIAL
  1352.     { "red",         XXRED, CM_INV|CM_ABR|CM_LOC }, /* Inv syn for REDIAL */
  1353.     { "redi",        XXRED, CM_INV|CM_ABR|CM_LOC }, /* ditto */
  1354.     { "redial",      XXRED, CM_LOC },    /* REDIAL last DIAL number */
  1355. #else
  1356.     { "red",         XXNOTAV, CM_INV|CM_LOC },
  1357.     { "redi",        XXNOTAV, CM_INV|CM_LOC },
  1358.     { "redial",      XXNOTAV, CM_INV|CM_LOC },
  1359. #endif /* NODIAL */
  1360.  
  1361. #ifdef CK_REDIR
  1362. #ifdef OS2
  1363. #ifndef NOPUSH
  1364.     { "redirect",    XXFUN, CM_INV|CM_PSH }, /* REDIRECT */
  1365. #else
  1366.     { "redirect",    XXNOTAV, CM_INV|CM_PSH },
  1367. #endif /* NOPUSH */
  1368. #else /* OS2 */
  1369. #ifndef NOPUSH
  1370.     { "redirect",    XXFUN, CM_PSH },    /* REDIRECT */
  1371. #else
  1372.     { "redirect",    XXNOTAV, CM_INV|CM_PSH },
  1373. #endif /* NOPUSH */
  1374. #endif /* OS2 */
  1375. #endif /* CK_REDIR */
  1376.  
  1377. #ifdef CK_RECALL
  1378.     { "redo",        XXREDO,  CM_NOR },    /* REDO */
  1379. #else
  1380.     { "redo",        XXNOTAV, CM_INV },
  1381. #endif /* CK_RECALL */
  1382.  
  1383. #ifndef NOXFER
  1384. #ifdef CK_RESEND
  1385.     { "reget",       XXREGET, 0 },    /* REGET */
  1386. #else
  1387.     { "reget",       XXNOTAV, CM_INV },
  1388. #endif /* CK_RESEND */
  1389. #endif /* NOXFER */
  1390.  
  1391. #ifndef NOSPL
  1392.     { "reinput",     XXREI, CM_INV },    /* REINPUT (from INPUT buffer) */
  1393. #else
  1394.     { "reinput",     XXNOTAV, CM_INV },
  1395. #endif /* NOSPL */
  1396.  
  1397. #ifndef NOXFER
  1398. #ifdef ADDCMD
  1399.     { "rem",         XXREM, CM_INV|CM_ABR },
  1400.     { "remo",        XXREM, CM_INV|CM_ABR },
  1401. #endif /* ADDCMD */
  1402.     { "remote",         XXREM, 0 },    /* Send REMOTE command to server */
  1403. #endif /* NOXFER */
  1404.  
  1405. #ifdef ADDCMD
  1406.     { "remove",      XXREMV,0 },    /* REMOVE (something from a list) */
  1407. #else
  1408.     { "remove",      XXNOTAV, CM_INV },
  1409. #endif /* ADDCMD */
  1410.  
  1411. #ifndef NOFRILLS
  1412. #ifndef NORENAME
  1413.     { "rename",      XXREN, 0 },    /* RENAME a local file */
  1414. #else
  1415.     { "rename",      XXNOTAV, CM_INV },
  1416. #endif /* NORENAME */
  1417.     { "replay",      XXTYP, CM_INV },    /* REPLAY (for now, just type) */
  1418. #endif /* NOFRILLS */
  1419.  
  1420. #ifndef NOXFER
  1421. #ifdef CK_RESEND
  1422.     { "rep",         XXTYP, CM_INV|CM_ABR },  /* REPLAY abbreviation */
  1423.     { "reput",       XXRSEN, CM_INV },          /* REPUT = RESEND */
  1424.     { "res",         XXRSEN, CM_INV|CM_ABR }, /* RESEND */
  1425.     { "rese",        XXRSEN, CM_INV|CM_ABR }, /* RESEND */
  1426.     { "resend",      XXRSEN, 0 },    /* RESEND */
  1427. #else
  1428.     { "reput",       XXNOTAV, CM_INV },
  1429.     { "res",         XXNOTAV, CM_INV },
  1430.     { "rese",        XXNOTAV, CM_INV },
  1431.     { "resend",      XXNOTAV, CM_INV },
  1432. #endif /* CK_RESEND */
  1433. #endif /* NOXFER */
  1434.  
  1435.     { "reset",       XXRESET, CM_INV },    /* RESET */
  1436.  
  1437. #ifdef CK_RESEND
  1438. #ifndef NOSPL
  1439.     { "ret",         XXRET, CM_INV|CM_ABR },
  1440. #endif /* NOSPL */
  1441. #endif /* CK_RESEND */
  1442.  
  1443. #ifndef NOXFER
  1444.     { "retrieve",    XXRETR, CM_INV },    /* RETRIEVE */
  1445. #endif /* NOXFER */
  1446.  
  1447. #ifndef NOSPL
  1448.     { "return",      XXRET, 0 },    /* RETURN from a function */
  1449. #else
  1450.     { "return",      XXNOTAV, CM_INV },
  1451. #endif /* NOSPL */
  1452.  
  1453. #ifndef NOXFER
  1454.     { "rexit",       XXRXIT, CM_INV },    /* REMOTE EXIT */
  1455. #endif /* NOXFER */
  1456.  
  1457. #ifdef CK_REXX
  1458. #ifndef NOPUSH
  1459.     { "rexx",        XXREXX, CM_PSH },    /* Execute a Rexx command */
  1460. #else
  1461.     { "rexx",        XXNOTAV, CM_INV|CM_PSH },
  1462. #endif /* NOPUSH */
  1463. #endif /* CK_REXX */
  1464.  
  1465. #ifndef NOXFER
  1466.     { "rhelp",       XXRHLP, CM_INV },    /* REMOTE HELP */
  1467.     { "rhost",       XXRHOS, CM_INV },    /* REMOTE HOST */
  1468.     { "rkermit",     XXRKER, CM_INV },    /* REMOTE KERMIT */
  1469. #endif /* NOXFER */
  1470.  
  1471. #ifdef TCPSOCKET
  1472.     { "rlogin",      XXRLOG, CM_LOC },    /* Make an Rlogin connection */
  1473. #else
  1474.     { "rlogin",      XXNOTAV, CM_INV|CM_LOC },
  1475. #endif /* TCPSOCKET */
  1476.  
  1477. #ifndef NOFRILLS
  1478.     { "rm",          XXDEL, CM_INV },    /* Invisible synonym for delete */
  1479. #endif /* NOFRILLS */
  1480.  
  1481. #ifdef CK_MKDIR
  1482.     { "rmdir",       XXRMDIR, 0 },    /* RMDIR */
  1483. #else
  1484.     { "rmdir",       XXNOTAV, CM_INV },
  1485. #endif /* CK_MKDIR */
  1486.  
  1487. #ifndef NOXFER
  1488.     { "rmessage",    XXRMSG, CM_INV },    /* REMOTE MESSAGE */
  1489.     { "rmkdir",      XXRMKD, CM_INV },    /* REMOTE MKDIR */
  1490.     { "rmsg",        XXRMSG, CM_INV },    /* REMOTE MESSAGE */
  1491. #ifndef NOSPL
  1492.     { "robust",      XXROB,  CM_INV },
  1493. #else
  1494.     { "robust",      XXNOTAV, CM_INV },
  1495. #endif /* NOSPL */
  1496.     { "rprint",      XXRPRI, CM_INV },  /* REMOTE PRINT */
  1497.     { "rpwd",        XXRPWD, CM_INV },    /* REMOTE PWD */
  1498.     { "rquery",      XXRQUE, CM_INV },    /* REMOTE QUERY */
  1499. #endif /* NOXFER */
  1500.  
  1501. #ifdef CK_RECALL
  1502.     { "rr",          XXREDO, CM_INV|CM_NOR },
  1503. #endif /* CK_RECALL */
  1504.  
  1505. #ifndef NOXFER
  1506.     { "rrename",    XXRREN, CM_INV },    /* REMOTE RENAME */
  1507.     { "rrmdir",     XXRRMD, CM_INV },    /* REMOTE REMDIR */
  1508.     { "rset",       XXRSET, CM_INV },    /* REMOTE SET */
  1509.     { "rspace",     XXRSPA, CM_INV },    /* REMOTE SPACE */
  1510.     { "rtype",      XXRTYP, CM_INV },    /* REMOTE TYPE */
  1511. #endif /* NOXFER */
  1512.  
  1513. #ifndef NOPUSH
  1514.     { "run",         XXSHE, CM_PSH },    /* RUN a program or command */
  1515. #else
  1516.     { "run",         XXNOTAV, CM_INV|CM_PSH },
  1517. #endif /* NOPUSH */
  1518.  
  1519. #ifndef NOXFER
  1520.     { "rwho",        XXRWHO, CM_INV },    /* REMOTE WHO */
  1521.     { "s",           XXSEN, CM_INV|CM_ABR }, /* Invisible synonym for send */
  1522. #endif /* NOXFER */
  1523.  
  1524. #ifndef NOSETKEY
  1525. #ifdef OS2
  1526.     { "save",       XXSAVE, 0 },        /* SAVE something */
  1527. #else
  1528.     { "save",       XXSAVE, CM_INV },
  1529. #endif /* OS2 */
  1530. #else
  1531.     { "save",       XXNOTAV, CM_INV },
  1532. #endif /* NOSETKEY */
  1533.  
  1534. #ifndef NOSCRIPT
  1535.     { "sc",        XXLOGI, CM_INV|CM_ABR|CM_LOC },
  1536.     { "scr",       XXLOGI, CM_INV|CM_ABR|CM_LOC },
  1537. #endif /* NOSCRIPT */
  1538.     { "screen",      XXSCRN, 0 },    /* SCREEN actions */
  1539. #ifndef NOSCRIPT
  1540.     { "script",       XXLOGI, CM_LOC },    /* Expect-Send-style script line */
  1541. #else
  1542.     { "script",       XXNOTAV, CM_INV|CM_LOC },
  1543. #endif /* NOSCRIPT */
  1544.  
  1545.     { "search",    XXGREP,CM_INV },    /* Synonym for GREP and FIND */
  1546.  
  1547. #ifndef NOXFER
  1548.     { "send",       XXSEN, 0 },        /* Send (a) file(s) */
  1549. #ifndef NOSERVER
  1550.     { "server",       XXSER, 0 },        /* Be a SERVER */
  1551. #else
  1552.     { "server",       XXNOTAV, CM_INV },
  1553. #endif /* NOSERVER */
  1554. #endif /* NOXFER */
  1555.  
  1556.     { "set",       XXSET, 0 },        /* SET parameters */
  1557.  
  1558. #ifndef NOSPL
  1559. #ifndef NOSEXP
  1560.     { "sexpression", XXSEXP, CM_INV|CM_HLP }, /* SEXPR */
  1561. #endif /* NOSEXP */
  1562.  
  1563. #ifdef SFTP_BUILTIN
  1564.     { "sftp",        XXSFTP, 0 },   /* SFTP */
  1565. #endif /* SFTP_BUILTIN */
  1566.  
  1567. #ifndef NOSHOW
  1568.     { "sh",          XXSHO, CM_INV|CM_ABR }, /* SHOW parameters */
  1569. #endif /* NOSHOW */
  1570.     { "shift",       XXSHIFT, 0 },    /* SHIFT args */
  1571. #else
  1572.     { "shift",       XXNOTAV, CM_INV },
  1573. #endif /* NOSPL */
  1574.  
  1575. #ifndef NOSHOW
  1576.     { "show",        XXSHO, 0 },        /* SHOW parameters */
  1577. #else
  1578.     { "show",        XXNOTAV, CM_INV },
  1579. #endif /* NOSHOW */
  1580.  
  1581. #ifdef NEWFTP
  1582.     { "site",        XXSITE, CM_INV },    /* (FTP) SITE */
  1583. #endif /* NEWFTP */
  1584.  
  1585. #ifdef SSHBUILTIN
  1586.     { "skermit",   XXSKRM, 0 },     /* SKERMIT */
  1587. #endif /* SSHBUILTIN */
  1588.  
  1589. #ifndef NOSPL
  1590. #ifndef NOFRILLS
  1591.     { "sleep",       XXPAU, CM_INV },    /* SLEEP for specified interval */
  1592. #endif /* NOFRILLS */
  1593. #endif /* NOSPL */
  1594.  
  1595. #ifndef NOSPL
  1596.     { "sort",        XXSORT, CM_INV },    /* (see ARRAY) */
  1597. #else
  1598.     { "sort",        XXNOTAV, CM_INV },
  1599. #endif /* NOSPL */
  1600.  
  1601. #ifndef MAC
  1602. #ifndef NOFRILLS
  1603.     { "sp",          XXSPA, CM_INV|CM_ABR },
  1604.     { "spa",         XXSPA, CM_INV|CM_ABR },
  1605. #endif /* NOFRILLS */
  1606.     { "space",       XXSPA, 0 },    /* Show available disk SPACE */
  1607. #endif /* MAC */
  1608.  
  1609. #ifndef NOFRILLS
  1610. #ifndef NOPUSH
  1611.     { "spawn",       XXSHE, CM_INV|CM_PSH }, /* Synonym for PUSH, RUN */
  1612. #else
  1613.     { "spawn",       XXNOTAV, CM_INV|CM_PSH }, /* Synonym for PUSH, RUN */
  1614. #endif /* NOPUSH */
  1615. #endif /* NOFRILLS */
  1616.  
  1617. #ifdef ANYSSH
  1618.     { "ssh",         XXSSH, 0 },
  1619. #endif /* ANYSSH */
  1620.  
  1621. #ifndef NOXFER
  1622.     { "sta",         XXSTA, CM_INV|CM_ABR },
  1623.     { "stat",        XXSTA, CM_INV|CM_ABR },
  1624.     { "statistics",  XXSTA, 0 },    /* Display file transfer stats */
  1625. #endif /* NOXFER */
  1626.  
  1627.     { "status",      XXSTATUS,0 },    /* Show status of previous command */
  1628.  
  1629. #ifndef NOSPL
  1630.     { "stop",        XXSTO,   0 },    /* STOP all take files and macros */
  1631.     { "succeed",     XXSUCC,  CM_INV },    /* SUCCEED */
  1632. #else
  1633.     { "stop",        XXNOTAV, CM_INV },
  1634.     { "succeed",     XXNOTAV, CM_INV },
  1635. #endif /* NOSPL */
  1636.  
  1637. #ifndef NOFRILLS
  1638.     { "SUPPORT",     XXBUG, 0 },    /* Tech support instructions */
  1639. #else
  1640.     { "support",     XXNOTAV, CM_INV },
  1641. #endif /* NOFRILLS */
  1642.  
  1643. #ifndef NOJC
  1644.     { "suspend",     XXSUS, CM_PSH },    /* SUSPEND C-Kermit (UNIX only) */
  1645. #else
  1646.     { "suspend",     XXNOTAV, CM_INV|CM_PSH },
  1647. #endif /* NOJC */
  1648.  
  1649. #ifndef NOSPL
  1650.     { "switch",      XXSWIT, 0 },    /* SWITCH */
  1651. #else
  1652.     { "switch",      XXNOTAV, CM_INV },
  1653. #endif /* NOSPL */
  1654.  
  1655. #ifdef CK_TAPI
  1656.     { "ta",       XXTAK, CM_INV|CM_ABR }, /* (because of TAPI) */
  1657. #endif /* CK_TAPI */
  1658.  
  1659. #ifndef NOFRILLS
  1660.     { "tail",        XXTAIL, 0 },    /* Display end of a local file */
  1661. #endif /* NOFRILLS */
  1662.  
  1663.     { "take",       XXTAK, 0 },        /* TAKE commands from a file */
  1664.  
  1665. #ifdef CK_TAPI
  1666.     { "tapi",       XXTAPI, CM_LOC },    /* Microsoft TAPI commands */
  1667. #else
  1668.     { "tapi",       XXNOTAV, CM_INV|CM_LOC },
  1669. #endif /* CK_TAPI */
  1670.  
  1671. #ifndef NOFRILLS
  1672. #ifdef TCPSOCKET
  1673.     { "tel",         XXTEL, CM_INV|CM_ABR|CM_LOC },
  1674.     { "telnet",      XXTEL, CM_LOC },    /* TELNET (TCP/IP only) */
  1675.     { "telopt",      XXTELOP, CM_INV },    /* TELOPT (ditto) */
  1676. #else
  1677.     { "tel",         XXNOTAV, CM_INV|CM_LOC },
  1678.     { "telnet",      XXNOTAV, CM_INV|CM_LOC },
  1679.     { "telopt",      XXNOTAV, CM_INV },
  1680. #endif /* TCPSOCKET */
  1681. #ifdef OS2
  1682.     { "terminal",    XXTERM, CM_INV|CM_LOC }, /* == SET TERMINAL TYPE */
  1683. #else
  1684.     { "terminal",    XXTERM, CM_INV },
  1685. #endif /* OS2 */
  1686. #endif /* NOFRILLS */
  1687. #ifndef NOXFER
  1688.     { "text",        XXASC, CM_INV },    /* == SET FILE TYPE TEXT */
  1689. #endif /* NOXFER */
  1690.     { "touch",       XXTOUC, 0 },    /* TOUCH */
  1691. #ifndef NOSPL
  1692.     { "trace",       XXTRACE, 0 },    /* TRACE */
  1693. #else
  1694.     { "trace",       XXNOTAV, CM_INV },
  1695. #endif /* NOSPL */
  1696.  
  1697. #ifndef NOCSETS
  1698.     { "translate",   XXXLA, 0 },    /* TRANSLATE local file char sets */
  1699. #else
  1700.     { "translate",   XXNOTAV, CM_INV },
  1701. #endif /* NOCSETS */
  1702.  
  1703. #ifndef NOXMIT
  1704.     { "transmit",    XXTRA, 0 },    /* Send (upload) a file, no protocol */
  1705. #else
  1706.     { "transmit",    XXNOTAV, CM_INV },
  1707. #endif /* NOXMIT */
  1708.  
  1709. #ifndef NOFRILLS
  1710.     { "type",        XXTYP, 0 },    /* Display a local file */
  1711. #endif /* NOFRILLS */
  1712.  
  1713. #ifndef NOSPL
  1714.     { "undcl",       XXUNDCL, CM_INV },
  1715.     { "undeclare",   XXUNDCL, 0 },    /* UNDECLARE an array */
  1716.     { "undefine",    XXUNDEF, 0 },    /* UNDEFINE a variable or macro */
  1717. #else
  1718.     { "undcl",       XXNOTAV, CM_INV },
  1719.     { "undeclare",   XXNOTAV, CM_INV },
  1720.     { "undefine",    XXNOTAV, CM_INV },
  1721. #endif /* NOSPL */
  1722.  
  1723. #ifdef NEWFTP
  1724.     { "user",        XXUSER,  CM_INV }, /* (FTP) USER */
  1725. #endif /* NEWFTP */
  1726.  
  1727.     { "version",     XXVER, 0 },    /* VERSION-number display */
  1728.  
  1729. #ifdef OS2
  1730.     { "viewonly",    XXVIEW, CM_LOC },    /* VIEWONLY Terminal Mode */
  1731. #endif /* OS2 */
  1732.  
  1733.     { "void",        XXVOID, 0 },    /* VOID */
  1734.  
  1735. #ifndef NOSPL
  1736.     { "wait",        XXWAI, 0 },    /* WAIT */
  1737. #else
  1738.     { "wait",        XXNOTAV, CM_INV },
  1739. #endif /* NOSPL */
  1740.  
  1741.     { "wdirectory",  XXWDIR,  CM_INV },    /* Like TOPS-20, reverse chron order */
  1742.     { "wermit",      XXKERMI, CM_INV },
  1743.  
  1744. #ifndef NOXFER
  1745.     { "where",       XXWHERE, 0 },    /* WHERE (did my file go?) */
  1746. #endif /* NOXFER */
  1747.  
  1748. #ifndef NOSPL
  1749.     { "while",       XXWHI, 0 },    /* WHILE loop */
  1750. #else
  1751.     { "while",       XXNOTAV, CM_INV },
  1752. #endif /* NOSPL */
  1753.  
  1754. #ifndef OS2
  1755. #ifndef MAC
  1756. #ifndef NOFRILLS
  1757.     { "who",         XXWHO, CM_PSH },    /* WHO's logged in? */
  1758. #endif /* NOFRILLS */
  1759. #endif /* MAC */
  1760. #endif /* OS2 */
  1761.  
  1762. #ifndef NOHELP
  1763.     { "wildcards",   XXWILD,CM_INV|CM_HLP }, /* Wildcard syntax */
  1764. #endif /* NOHELP */
  1765.  
  1766. #ifndef NOSPL
  1767.     { "wr",          XXWRI, CM_INV|CM_ABR },
  1768.     { "wri",         XXWRI, CM_INV|CM_ABR },
  1769.     { "writ",        XXWRI, CM_INV|CM_ABR },
  1770.     { "write",       XXWRI, 0 },    /* WRITE characters to a file */
  1771.     { "write-line",  XXWRL, CM_INV },    /* WRITE a line to a file */
  1772.     { "writeln",     XXWRL, CM_INV },    /* Pascalisch synonym for write-line */
  1773. #else
  1774.     { "wr",          XXNOTAV, CM_INV },
  1775.     { "wri",         XXNOTAV, CM_INV },
  1776.     { "writ",        XXNOTAV, CM_INV },
  1777.     { "write",       XXNOTAV, CM_INV },
  1778.     { "write-line",  XXNOTAV, CM_INV },
  1779.     { "writeln",     XXNOTAV, CM_INV },
  1780. #endif /* NOSPL */
  1781.  
  1782. #ifndef NOFRILLS
  1783.     { "xecho",       XXXECH,0 },    /* XECHO */
  1784. #endif /* NOFRILLS */
  1785.  
  1786. #ifndef NOSPL
  1787.     { "xif",         XXIFX, CM_INV },    /* Extended IF command (obsolete) */
  1788. #else
  1789.     { "xif",         XXNOTAV, CM_INV },
  1790. #endif /* NOSPL */
  1791.  
  1792. #ifndef NOCSETS
  1793.     { "xlate",       XXXLA, CM_INV },    /* Synonym for TRANSLATE */
  1794. #else
  1795.     { "xlate",       XXNOTAV, CM_INV },
  1796. #endif /* NOCSETS */
  1797.  
  1798. #ifndef NOXMIT
  1799.     { "xmit",        XXTRA, CM_INV },    /* Synonym for TRANSMIT */
  1800. #else
  1801.     { "xmit",        XXNOTAV, CM_INV },
  1802. #endif /* NOXMIT */
  1803.  
  1804. #ifndef OS2
  1805. #ifndef NOJC
  1806.     { "z",           XXSUS, CM_INV|CM_PSH }, /* Synonym for SUSPEND */
  1807. #else
  1808.     { "z",           XXNOTAV, CM_INV|CM_PSH },
  1809. #endif /* NOJC */
  1810. #endif /* OS2 */
  1811.  
  1812. #ifndef NOSPL
  1813.     { "{",           XXMACRO, CM_INV },    /* Immediate macro */
  1814. #endif /* NOSPL */
  1815.     { "", 0, 0 }
  1816. };
  1817. int ncmd = (sizeof(cmdtab) / sizeof(struct keytab)) - 1;
  1818.  
  1819. /* NOTE: Tokens must also be entered above into cmdtab[]. */
  1820.  
  1821. char toktab[] = {
  1822. #ifndef NOPUSH
  1823.     '!',                /* Shell escape */
  1824. #endif /* NOPUSH */
  1825.     '#',                /* Comment */
  1826. #ifndef NOSPL
  1827.     '(',                /* S-Expression */
  1828.     '.',                /* Assignment */
  1829. #endif /* NOSPL */
  1830.     ';',                /* Comment */
  1831. #ifndef NOSPL
  1832.     ':',                /* Label */
  1833. #endif /* NOSPL */
  1834. #ifndef NOPUSH
  1835. #ifdef CK_REDIR
  1836.     '<',                /* REDIRECT */
  1837. #endif /* CK_REDIR */
  1838.     '@',                /* DCL escape */
  1839. #endif /* NOPUSH */
  1840. #ifdef CK_RECALL
  1841.     '^',                /* Command recall */
  1842. #endif /* CK_RECALL */
  1843. #ifndef NOSPL
  1844.     '{',                /* Immediate macro */
  1845. #endif /* NOSPL */
  1846.     '\0'                /* End of this string */
  1847. };
  1848. int xxdot = 0;                /* Used with "." token */
  1849.  
  1850. struct keytab yesno[] = {        /* Yes/No keyword table */
  1851.     { "no",    0, 0 },
  1852.     { "ok",    1, 0 },
  1853.     { "yes",   1, 0 }
  1854. };
  1855. int nyesno = (sizeof(yesno) / sizeof(struct keytab));
  1856.  
  1857. /* Save keyword table */
  1858.  
  1859. struct keytab savtab[] = {
  1860. #ifdef OS2
  1861.     { "command",  XSCMD, 0 },
  1862. #else
  1863. #ifdef CK_RECALL
  1864.     { "command",  XSCMD, 0 },
  1865. #endif /* CK_RECALL */
  1866. #endif /* OS2 */
  1867. #ifndef NOSETKEY
  1868.     { "keymap",   XSKEY, 0 },
  1869. #endif /* NOSETKEY */
  1870. #ifdef OS2
  1871.     { "terminal", XSTERM, 0 },
  1872. #endif /* OS2 */
  1873.     { "", 0, 0 }
  1874. };
  1875. int nsav = (sizeof(savtab) / sizeof(struct keytab)) - 1;
  1876.  
  1877. /* Parameter keyword table */
  1878.  
  1879. struct keytab prmtab[] = {
  1880.     { "alarm",            XYALRM,  0 },
  1881. #ifdef COMMENT                /* SET ANSWER not implemented yet */
  1882. #ifndef NODIAL
  1883.     { "answer",           XYANSWER,0 },
  1884. #endif /* NODIAL */
  1885. #endif /* COMMENT */
  1886.     { "ask-timer",        XYTIMER, 0 },
  1887. #ifndef NOXFER
  1888.     { "attributes",       XYATTR,  0 },
  1889. #endif /* NOXFER */
  1890. #ifdef CK_AUTHENTICATION
  1891.     { "authentication",   XYAUTH,  0 },
  1892. #else  /* CK_AUTHENTICATION */
  1893. #ifdef CK_SSL
  1894.     { "authentication",   XYAUTH,  0 },
  1895. #endif /* CK_SSL */
  1896. #endif /* CK_AUTHENTICATION */
  1897.     { "b",          XYBACK,  CM_INV|CM_ABR|CM_PSH },
  1898.     { "ba",          XYBACK,  CM_INV|CM_ABR|CM_PSH },
  1899. #ifdef VMS
  1900.     { "background",       XYBACK,  CM_INV|CM_PSH },
  1901.     { "batch",            XYBACK,  CM_PSH },
  1902. #else
  1903.     { "background",       XYBACK,  CM_PSH },
  1904.     { "batch",            XYBACK,  CM_INV|CM_PSH },
  1905. #endif /* VMS */
  1906. #ifndef NOLOCAL
  1907.     { "baud",              XYSPEE,  CM_INV|CM_LOC },
  1908. #endif /* NOLOCAL */
  1909.     { "bell",             XYBELL,  0 },
  1910. #ifndef NOXFER
  1911.     { "block-check",        XYCHKT,  0 },
  1912. #endif /* NOXFER */
  1913. #ifdef OS2
  1914. #ifdef BPRINT
  1915.     { "bprinter",         XYBDCP,  CM_INV },
  1916. #endif /* BPRINT */
  1917. #endif /*  OS2 */
  1918. #ifdef BROWSER
  1919.     { "browser",          XYBROWSE,CM_PSH|CM_LOC },
  1920. #endif /* BROWSER */
  1921. #ifndef NOXFER
  1922. #ifdef DYNAMIC
  1923.     { "buffers",          XYBUF,   0 },
  1924. #endif /* DYNAMIC */
  1925. #endif /* NOXFER */
  1926. #ifndef NOLOCAL
  1927. #ifndef MAC
  1928.     { "carrier-watch",    XYCARR,  CM_LOC },
  1929. #endif /* MAC */
  1930. #endif /* NOLOCAL */
  1931. #ifndef NOSPL
  1932.     { "case",             XYCASE,  0 },
  1933. #endif /* NOSPL */
  1934.     { "cd",               XYCD,    0 },
  1935. #ifndef NOXFER
  1936.     { "cl",               XYCLEAR, CM_INV|CM_ABR },
  1937.     { "cle",              XYCLEAR, CM_INV|CM_ABR },
  1938.     { "clea",             XYCLEAR, CM_INV|CM_ABR },
  1939.     { "clear",            XYCLEAR, CM_INV|CM_ABR },
  1940.     { "clear-channel",    XYCLEAR, 0 },
  1941.     { "clearchannel",     XYCLEAR, CM_INV },
  1942. #endif /* NOXFER */
  1943. #ifndef NOLOCAL
  1944.     { "close-on-disconnect", XYDISC, CM_INV|CM_LOC },
  1945. #endif /* NOLOCAL */
  1946.     { "cmd",              XYCMD,   CM_INV },
  1947.     { "command",          XYCMD,   0 },
  1948. #ifdef CK_SPEED
  1949.     { "con",              XYQCTL,  CM_INV|CM_ABR },
  1950. #endif /* CK_SPEED */
  1951.     { "console",          XYCMD,   CM_INV },
  1952. #ifdef CK_SPEED
  1953.     { "control-character",XYQCTL,  0 },
  1954. #endif /* CK_SPEED */
  1955. #ifndef NOSPL
  1956.     { "count",            XYCOUN,  0 },
  1957. #endif /* NOSPL */
  1958. #ifndef NOXFER
  1959.     { "d",          XYDELA,  CM_INV|CM_ABR },
  1960.     { "de",          XYDELA,  CM_INV|CM_ABR },
  1961. #endif /* NOXFER */
  1962.     { "debug",            XYDEBU,  0 },
  1963. #ifdef VMS
  1964.     { "default",          XYDFLT,  0 },
  1965. #else
  1966. #ifndef MAC
  1967.     { "default",          XYDFLT,  CM_INV },
  1968. #endif /* MAC */
  1969. #endif /* VMS */
  1970. #ifndef NOXFER
  1971.     { "delay",              XYDELA,  0 },
  1972.     { "destination",      XYDEST,  0 },
  1973. #endif /* NOXFER */
  1974. #ifndef NODIAL
  1975.     { "di",          XYDIAL,  CM_INV|CM_ABR|CM_LOC },
  1976.     { "dia",          XYDIAL,  CM_INV|CM_ABR|CM_LOC },
  1977.     { "dial",             XYDIAL,  CM_LOC },
  1978. #endif /* NODIAL */
  1979. #ifdef OS2
  1980.     { "dialer",          XYDLR,   CM_INV },
  1981. #endif /* OS2 */
  1982. #ifndef NOLOCAL
  1983.     { "disconnect",       XYDISC,  CM_LOC },
  1984.     { "duplex",              XYDUPL,  CM_LOC },
  1985. #endif /* NOLOCAL */
  1986. #ifndef NOPUSH
  1987. #ifndef NOFRILLS
  1988.     { "editor",           XYEDIT,  CM_PSH },
  1989. #endif /*  NOFRILLS */
  1990. #endif /* NOPUSH */
  1991. #ifdef CK_CTRLZ
  1992.     { "eof",              XYEOF,   CM_INV },
  1993. #endif /* CK_CTRLZ */
  1994. #ifndef NOLOCAL
  1995.     { "escape-character", XYESC,   CM_LOC },
  1996. #endif /* NOLOCAL */
  1997. #ifndef NOSPL
  1998.     { "evaluate",         XYEVAL,  CM_INV },
  1999. #endif /* NOSPL */
  2000.     { "exit",          XYEXIT,  0 },
  2001. #ifndef NOXFER
  2002. #ifdef CK_XYZ
  2003. #ifndef NOPUSH
  2004. #ifndef XYZ_INTERNAL
  2005.     { "external-protocol",XYEXTRN, 0 },
  2006. #endif    /* XYZ_INTERNAL */
  2007. #endif    /* NOPUSH */
  2008. #endif    /* CK_XYZ */
  2009.     { "f-ack-bug",        XYFACKB, CM_INV },
  2010.     { "f-ack-path",       XYFACKP, CM_INV },
  2011. #endif /* NOXFER */
  2012.     { "file",             XYFILE,  0 },
  2013.     { "fl",                 XYFLOW,  CM_INV|CM_ABR },
  2014. #ifndef NOSPL
  2015.     { "flag",             XYFLAG,  0 },
  2016. #endif /* NOSPL */
  2017. #ifdef TCPSOCKET
  2018. #ifndef SYSFTP
  2019. #ifndef NOFTP
  2020.     { "ft",                 XYFTPX,  CM_INV|CM_ABR },
  2021.     { "ftp",                XYFTPX,  0 },
  2022. #endif /* NOFTP */
  2023. #endif /* SYSFTP */
  2024. #endif /* TCPSOCKET */
  2025. #ifdef BROWSER
  2026.     { "ftp-client",       XYFTP,   CM_PSH },
  2027. #endif /* BROWSER */
  2028.     { "flow-control",       XYFLOW,  0 },
  2029. #ifndef NOSPL
  2030.     { "function",         XYFUNC,  0 },
  2031. #endif /* NOSPL */
  2032. #ifdef NEWFTP
  2033.     { "get-put-remote",   XYGPR,   0 },
  2034. #endif /* NEWFTP */
  2035. #ifdef KUI
  2036.     { "gui",              XYGUI,   0 },
  2037. #endif /* KUI */
  2038.     { "handshake",          XYHAND,  0 },
  2039.     { "hints",            XYHINTS, 0 },
  2040. #ifdef NETCONN
  2041.     { "host",             XYHOST,  CM_LOC },
  2042. #endif /* NETCONN */
  2043. #ifndef NOSPL
  2044.     { "i",          XYINPU,  CM_INV|CM_ABR },
  2045. #endif /* NOSPL */
  2046. #ifdef IKSD
  2047.     { "iks",              XYIKS,   0 },
  2048. #else
  2049.     { "iks",              XYIKS,   CM_INV },
  2050. #endif /* IKSD */
  2051. #ifndef NOSPL
  2052.     { "in",          XYINPU,  CM_INV|CM_ABR },
  2053. #endif /* NOSPL */
  2054. #ifndef NOXFER
  2055.     { "incomplete",         XYIFD,   CM_INV },
  2056. #endif /* NOXFER */
  2057. #ifndef NOSPL
  2058.     { "input",            XYINPU,  0 },
  2059. #endif /* NOSPL */
  2060. #ifndef NOSETKEY
  2061.     { "key",          XYKEY,   0 },
  2062. #endif /* NOSETKEY */
  2063.     { "l",                XYLINE,  CM_INV|CM_ABR },
  2064. #ifndef NOCSETS
  2065.     { "language",         XYLANG,  0 },
  2066. #endif /* NOCSETS */
  2067. #ifndef NOLOCAL
  2068.     { "line",             XYLINE,  CM_LOC },
  2069.     { "local-echo",      XYLCLE,  CM_INV|CM_LOC },
  2070. #endif /* NOLOCAL */
  2071. #ifdef LOCUS
  2072.     { "locus",            XYLOCUS, 0 },
  2073. #endif /* LOCUS */
  2074. #ifndef NOSPL
  2075.     { "login",          XYLOGIN, CM_LOC },
  2076. #endif /* NOSPL */
  2077. #ifndef NOSPL
  2078.     { "macro",            XYMACR,  0 },
  2079. #endif /* NOSPL */
  2080.     { "match",            XYMATCH, 0 },
  2081. #ifdef COMMENT
  2082. #ifdef VMS
  2083.     { "messages",         XYMSGS,  0 },
  2084. #endif /* VMS */
  2085. #endif /* COMMENT */
  2086. #ifndef NODIAL
  2087.     { "modem",          XYMODM,  CM_LOC },
  2088. #endif /* NODIAL */
  2089. #ifndef NOLOCAL
  2090. #ifdef OS2MOUSE
  2091.     { "mouse",          XYMOUSE, 0 },
  2092. #endif /* OS2MOUSE */
  2093. #endif /* NOLOCAL */
  2094. #ifdef OS2
  2095.     { "mskermit",         XYMSK,   0 },
  2096. #endif /* OS2 */
  2097. #ifdef NETCONN
  2098.     { "network",          XYNET,   CM_LOC },
  2099. #endif /* NETCONN */
  2100. #ifndef NOSPL
  2101.     { "output",           XYOUTP,  0 },
  2102. #endif /* NOSPL */
  2103.     { "options",          XYOPTS,  0 },
  2104.     { "pause",            XYSLEEP, CM_INV },
  2105. #ifdef ANYX25
  2106. #ifndef IBMX25
  2107.     { "pad",              XYPAD,   CM_LOC },
  2108. #endif /* IBMX25 */
  2109. #endif /* ANYX25 */
  2110.     { "parity",              XYPARI,  0 },
  2111. #ifndef NOLOCAL
  2112. #ifdef OS2
  2113.     { "port",             XYLINE,  CM_LOC },
  2114. #else
  2115.     { "port",             XYLINE,  CM_INV|CM_LOC },
  2116. #endif /* OS2 */
  2117. #endif /* NOLOCAL */
  2118. #ifndef NOFRILLS
  2119.     { "pr",                 XYPROM,  CM_INV|CM_ABR },
  2120.     { "printer",          XYPRTR,  0 },
  2121. #endif /* NOFRILLS */
  2122. #ifdef OS2
  2123.     { "priority",         XYPRTY,  0 },
  2124. #endif /* OS2 */
  2125. #ifdef CK_SPEED
  2126.     { "prefixing",        XYPREFIX, 0 },
  2127. #endif /* CK_SPEED */
  2128. #ifndef NOFRILLS
  2129.     { "prompt",              XYPROM,  0 },
  2130. #endif /* NOFRILLS */
  2131. #ifndef NOXFER
  2132.     { "protocol",      XYPROTO, 0 },
  2133. #endif /* NOXFER */
  2134.     { "q",          XYQUIE,  CM_INV|CM_ABR },
  2135. #ifndef NOXFER
  2136.     { "q8flag",           XYQ8FLG, CM_INV },
  2137. #endif /* NOXFER */
  2138. #ifdef QNX
  2139.     { "qnx-port-lock",    XYQNXPL, 0 },
  2140. #else
  2141.     { "qnx-port-lock",    XYQNXPL, CM_INV },
  2142. #endif /* QNX */
  2143.     { "quiet",          XYQUIE,  0 },
  2144. #ifndef NOXFER
  2145.     { "rec",              XYRECV,  CM_INV|CM_ABR },
  2146.     { "receive",          XYRECV,  0 },
  2147.     { "recv",             XYRECV,  CM_INV },
  2148. #endif /* NOXFER */
  2149.     { "reliable",         XYRELY,  0 },
  2150.     { "rename",           XY_REN,  0 },
  2151. #ifndef NOXFER
  2152.     { "repeat",           XYREPT,  0 },
  2153.     { "retry-limit",      XYRETR,  0 },
  2154. #endif /* NOXFER */
  2155. #ifdef CKROOT
  2156.     { "root",             XYROOT,  0 },
  2157. #endif /* CKROOT */
  2158. #ifndef NOSCRIPT
  2159.     { "script",          XYSCRI,  CM_LOC },
  2160. #endif /* NOSCRIPT */
  2161. #ifndef NOXFER
  2162.     { "send",             XYSEND,  0 },
  2163. #ifndef NOLOCAL
  2164. #ifndef NOSERVER
  2165.     { "ser",              XYSERV,  CM_INV|CM_ABR },
  2166. #endif /* NOSERVER */
  2167. #endif /* NOXFER */
  2168.     { "serial",           XYSERIAL,CM_LOC },
  2169. #endif /* NOLOCAL */
  2170. #ifndef NOSERVER
  2171.     { "server",           XYSERV,  0 },
  2172. #endif /* NOSERVER */
  2173. #ifdef SESLIMIT
  2174. #ifndef NOLOCAL
  2175.     { "session-l",        XYSESS,  CM_INV|CM_ABR },
  2176. #endif /* NOLOCAL */
  2177.     { "session-limit",    XYLIMIT, CM_INV|CM_LOC }, /* Session Limit */
  2178. #endif /* SESLIMIT */
  2179.  
  2180. #ifndef NOLOCAL
  2181.     { "session-log",      XYSESS,  CM_LOC },
  2182. #endif /* NOLOCAL */
  2183.  
  2184. #ifndef NOSPL
  2185. #ifndef NOSEXP
  2186.     { "sexpression",      XYSEXP,  CM_INV },
  2187. #endif /* NOSEXP */
  2188. #endif /* NOSPL */
  2189.  
  2190.     { "sleep",            XYSLEEP, 0 },
  2191.  
  2192. #ifndef NOLOCAL
  2193.     { "speed",              XYSPEE,  CM_LOC },
  2194. #endif /* NOLOCAL */
  2195.  
  2196. #ifdef ANYSSH
  2197.     { "ssh",              XYSSH,   0 },
  2198. #endif /* ANYSSH */
  2199.  
  2200. #ifndef NOSPL
  2201.     { "startup-file",     XYSTARTUP, CM_INV },
  2202. #endif /* NOSPL */
  2203.  
  2204. #ifndef NOLOCAL
  2205. #ifdef HWPARITY
  2206.     { "stop-bits",        XYSTOP, CM_LOC },
  2207. #else
  2208. #ifdef TN_COMPORT
  2209.     { "stop-bits",        XYSTOP, CM_LOC },
  2210. #endif /* TN_COMPORT */
  2211. #endif /* HWPARITY */
  2212. #endif /* NOLOCAL */
  2213.  
  2214. #ifndef NOXFER
  2215. #ifdef STREAMING
  2216.     { "streaming",        XYSTREAM, 0 },
  2217. #endif /* STREAMING */
  2218. #endif /* NOXFER */
  2219.  
  2220. #ifndef NOJC
  2221.     { "suspend",          XYSUSP,  CM_PSH },
  2222. #endif /* NOJC */
  2223. #ifdef CKSYSLOG
  2224.     { "syslog",           XYSYSL,  CM_INV },
  2225. #endif /* CKSYSLOG */
  2226.     { "take",             XYTAKE,  0 },
  2227.  
  2228. #ifdef CK_TAPI
  2229.     { "tapi",             XYTAPI,  CM_LOC },
  2230. #endif /* CK_TAPI */
  2231.  
  2232. #ifndef NOTCPOPTS
  2233. #ifdef TCPSOCKET
  2234.     { "tcp",              XYTCP,   CM_LOC },
  2235. #endif /* TCPSOCKET */
  2236. #endif /* NOTCPOPTS */
  2237.  
  2238. #ifdef TNCODE
  2239.     { "tel",              XYTEL,   CM_INV|CM_ABR },
  2240.     { "telnet",           XYTEL,   0 },
  2241.     { "telopt",           XYTELOP, 0 },
  2242. #endif /* TNCODE */
  2243.  
  2244. #ifndef NOSPL
  2245.     { "temp-directory",   XYTMPDIR,0 },
  2246. #endif /* NOSPL */
  2247.  
  2248. #ifndef NOLOCAL
  2249.     { "terminal",         XYTERM,  CM_LOC },
  2250. #endif /* NOLOCAL */
  2251.  
  2252. #ifdef OS2
  2253.     { "title",          XYTITLE, CM_LOC },
  2254. #endif /* OS2 */
  2255. #ifdef TLOG
  2256.     { "transaction-log",  XYTLOG,  0 },
  2257. #endif /* TLOG */
  2258. #ifndef NOXFER
  2259.     { "transfer",         XYXFER,  0 },
  2260. #endif /* NOXFER */
  2261. #ifndef NOXMIT
  2262.     { "transmit",         XYXMIT,  0 },
  2263. #endif /* NOXMIT */
  2264. #ifndef NOXFER
  2265. #ifndef NOCSETS
  2266.     { "unknown-char-set", XYUNCS,  0 },
  2267. #endif /* NOCSETS */
  2268. #ifndef NOSPL
  2269.     { "variable-evaluation", XYVAREV, 0 },
  2270. #endif    /* NOSPL */
  2271. #endif /* NOXFER */
  2272.     { "wait",             XYSLEEP, CM_INV },
  2273. #ifndef NOPUSH
  2274. #ifdef UNIX
  2275.     { "wildcard-expansion", XYWILD, 0 },
  2276. #endif /* UNIX */
  2277. #endif /* NOPUSH */
  2278. #ifdef NT
  2279.     { "w",                XYWIND,  CM_INV|CM_ABR },
  2280.     { "wi",               XYWIND,  CM_INV|CM_ABR },
  2281.     { "win",              XYWIND,  CM_INV|CM_ABR },
  2282. #endif /* NT */
  2283.     { "window-size",      XYWIND,  0 },
  2284. #ifdef NT
  2285.     { "win95",            XYWIN95, 0 },
  2286. #endif /* NT */
  2287. #ifdef ANYX25
  2288.     { "x.25",             XYX25,   CM_LOC },
  2289.     { "x25",              XYX25,   CM_INV|CM_LOC },
  2290. #endif /* ANYX25 */
  2291.     { "xfer",             XYXFER,  CM_INV },
  2292. #ifndef NOXMIT
  2293.     { "xmit",             XYXMIT,  CM_INV },
  2294. #endif /* NOXMIT */
  2295.     { "", 0, 0 }
  2296. };
  2297. int nprm = (sizeof(prmtab) / sizeof(struct keytab)) - 1; /* How many */
  2298.  
  2299. struct keytab scntab[] = {        /* Screen commands */
  2300.     { "clear",   SCN_CLR, 0 },
  2301.     { "cleol",   SCN_CLE, 0 },
  2302.     { "move-to", SCN_MOV, 0 }
  2303. };
  2304. int nscntab = (sizeof(scntab) / sizeof(struct keytab)); /* How many */
  2305.  
  2306. #ifdef ANYSSH                /* SSH command table */
  2307. #ifdef SSHBUILTIN
  2308. int    ssh_pf_lcl_n = 0,
  2309.        ssh_pf_rmt_n = 0;
  2310. struct ssh_pf ssh_pf_lcl[32] = { 0, NULL, 0 }; /* SSH Port Forwarding */
  2311. struct ssh_pf ssh_pf_rmt[32] = { 0, NULL, 0 }; /* structs... */
  2312. extern char * ssh_hst, * ssh_cmd, * ssh_prt;
  2313. extern int    ssh_ver,   ssh_xfw;
  2314. char * ssh_tmpuid = NULL, *ssh_tmpcmd = NULL, *ssh_tmpport = NULL,
  2315.      * ssh_tmpstr = NULL;
  2316.  
  2317. int
  2318.  sshk_type = SSHKT_2D,            /* SSH KEY CREATE /TYPE:x */
  2319.  sshk_bits = 1024,            /* SSH KEY CREATE /BITS:n */
  2320.  sshk_din  = SKDF_OSSH,            /* SSH KEY DISPLAY /IN-FORMAT: */
  2321.  sshk_dout = SKDF_OSSH;            /* SSH KEY DISPLAY /OUT-FORMAT: */
  2322.  
  2323. char
  2324.  * sshk1_comment = NULL,        /* SSH V1 COMMENT */
  2325.  * sshkp_old = NULL,            /* Old key passphrase */
  2326.  * sshkp_new = NULL,            /* New key passphrase */
  2327.  * sshkc_pass = NULL,            /* KEY CREATE /PASS:xxx */
  2328.  * sshkc_comm = NULL,            /* KEY CREATE /V1-RSA-COMMENT:xxx */
  2329.  * sshd_file = NULL,            /* DISPLAY file */
  2330.  * sshk_file = NULL;            /* SSH CREATE KEY file */
  2331.  
  2332. static struct keytab sshclr[] = {
  2333.     { "local-port-forward",  SSHC_LPF, 0 },
  2334.     { "remote-port-forward", SSHC_RPF, 0 },
  2335.     { "", 0, 0 }
  2336. };
  2337. static int nsshclr = (sizeof(sshclr) / sizeof(struct keytab)) - 1;
  2338.  
  2339. struct keytab sshopnsw[] = {
  2340.     { "/command",        SSHSW_CMD, CM_ARG },
  2341.     { "/password",       SSHSW_PWD, CM_ARG },
  2342.     { "/subsystem",      SSHSW_SUB, CM_ARG },
  2343.     { "/user",           SSHSW_USR, CM_ARG },
  2344.     { "/version",        SSHSW_VER, CM_ARG },
  2345.     { "/x11-forwarding", SSHSW_X11, CM_ARG },
  2346.     { "", 0, 0 }
  2347. };
  2348. int nsshopnsw = (sizeof(sshopnsw) / sizeof(struct keytab)) - 1;
  2349.  
  2350. static struct keytab sshkwtab[] = {
  2351.     { "add",                 XSSH_ADD, 0 },
  2352.     { "agent",               XSSH_AGT, 0 },
  2353.     { "clear",               XSSH_CLR, 0 },
  2354.     { "forward-local-port",  XSSH_FLP, CM_INV },
  2355.     { "forward-remote-port", XSSH_FRP, CM_INV },
  2356.     { "key",                 XSSH_KEY, 0 },
  2357.     { "open",                XSSH_OPN, 0 },
  2358.     { "v2",                  XSSH_V2,  0 },
  2359.     { "", 0, 0 }
  2360. };
  2361. static int nsshcmd = (sizeof(sshkwtab) / sizeof(struct keytab)) - 1;
  2362.  
  2363. static struct keytab ssh2tab[] = {
  2364.     { "rekey", XSSH2_RKE, 0 },
  2365.     { "", 0, 0 }
  2366. };
  2367. static int nssh2tab = (sizeof(ssh2tab) / sizeof(struct keytab));
  2368.  
  2369. static struct keytab addfwd[] = {    /* SET SSH ADD command table */
  2370.     { "local-port-forward",  SSHF_LCL, 0 },
  2371.     { "remote-port-forward", SSHF_RMT, 0 },
  2372.     { "", 0, 0 }
  2373. };
  2374. static int naddfwd = (sizeof(addfwd) / sizeof(struct keytab)) - 1;
  2375.  
  2376. static struct keytab sshagent[] = {    /* SET SSH AGENT command table */
  2377.     { "add",    SSHA_ADD, 0 },
  2378.     { "delete", SSHA_DEL, 0 },
  2379.     { "list",   SSHA_LST, 0 },
  2380.     { "", 0, 0 }
  2381. };
  2382. static int nsshagent = (sizeof(sshagent) / sizeof(struct keytab)) - 1;
  2383.  
  2384. static struct keytab sshagtsw[] = {    /* SET SSH AGENT LIST switch table */
  2385.     { "/fingerprint", SSHASW_FP, 0 },
  2386.     { "", 0, 0 }
  2387. };
  2388. static int nsshagtsw = (sizeof(sshagtsw) / sizeof(struct keytab)) - 1;
  2389.  
  2390. static struct keytab sshkey[] = {    /* SET SSH KEY command table */
  2391.     { "change-passphrase",  SSHK_PASS, 0 },
  2392.     { "create",             SSHK_CREA, 0 },
  2393.     { "display",            SSHK_DISP, 0 },
  2394.     { "v1",                 SSHK_V1,   0 },
  2395.     { "", 0, 0 }
  2396. };
  2397. static int nsshkey = (sizeof(sshkey) / sizeof(struct keytab)) - 1;
  2398.  
  2399. static struct keytab sshkv1[] = {    /* SET SSH KEY V1 command table */
  2400.     { "set-comment",  1, 0 }
  2401. };
  2402.  
  2403. static struct keytab sshkpsw[] = {    /* SET SSH KEY PASSPHRASE table */
  2404.     { "/new-passphrase",  2, CM_ARG },
  2405.     { "/old-passphrase",  1, CM_ARG }
  2406. };
  2407.  
  2408. static struct keytab sshkcrea[] = {    /* SSH KEY CREATE table */
  2409.     { "/bits",           SSHKC_BI, CM_ARG },
  2410.     { "/passphrase",     SSHKC_PP, CM_ARG },
  2411.     { "/type",           SSHKC_TY, CM_ARG },
  2412.     { "/v1-rsa-comment", SSHKC_1R, CM_ARG }
  2413. };
  2414. static int nsshkcrea = (sizeof(sshkcrea) / sizeof(struct keytab));
  2415.  
  2416. static struct keytab sshkcty[] = {    /* SSH KEY CREATE /TYPE:xxx */
  2417.     { "srp",    SSHKT_SRP, 0 },
  2418.     { "v1-rsa", SSHKT_1R, 0 },
  2419.     { "v2-dsa", SSHKT_2D, 0 },
  2420.     { "v2-rsa", SSHKT_2R, 0 }
  2421. };
  2422. static int nsshkcty = (sizeof(sshkcty) / sizeof(struct keytab));
  2423.  
  2424. static struct keytab sshdswi[] = {    /* SET SSH KEY DISPLAY /switches */
  2425.     { "/format", SSHKD_OUT, CM_ARG }
  2426. };
  2427. static int nsshdswi = (sizeof(sshdswi) / sizeof(struct keytab));
  2428.  
  2429. #ifdef COMMENT
  2430. static struct keytab sshdifmt[] = {    /* SSH KEY DISPLAY /IN-FORMAT: */
  2431.     { "openssh", SKDF_OSSH, 0 },
  2432.     { "ssh.com", SKDF_SSHC, 0 }
  2433. };
  2434. static int nsshdifmt = (sizeof(sshdifmt) / sizeof(struct keytab));
  2435. #endif /* COMMENT */
  2436.  
  2437. static struct keytab sshdofmt[] = {    /* SSH KEY DISPLAY /IN-FORMAT: */
  2438.     { "fingerprint", SKDF_FING, 0 },
  2439.     { "ietf",        SKDF_IETF, 0 },
  2440.     { "openssh",     SKDF_OSSH, 0 },
  2441.     { "ssh.com",     SKDF_SSHC, 0 }
  2442. };
  2443. static int nsshdofmt = (sizeof(sshdofmt) / sizeof(struct keytab));
  2444.  
  2445. static struct keytab sshkermit[] = { /* SKERMIT */
  2446.     { "open",       SKRM_OPN, 0 }
  2447. };
  2448. static int nsshkermit = (sizeof(sshkermit) / sizeof(struct keytab));
  2449.  
  2450. struct keytab sshkrmopnsw[] = {
  2451.     { "/password",       SSHSW_PWD, CM_ARG },
  2452.     { "/user",           SSHSW_USR, CM_ARG },
  2453.     { "/version",        SSHSW_VER, CM_ARG },
  2454.     { "", 0, 0 }
  2455. };
  2456. int nsshkrmopnsw = (sizeof(sshkrmopnsw) / sizeof(struct keytab)) - 1;
  2457. #endif /* SSHBUILTIN */
  2458.  
  2459. #ifdef SFTP_BUILTIN
  2460. static struct keytab sftpkwtab[] = {    /* SFTP */
  2461.     {  "cd",        SFTP_CD,    0 },
  2462.     {  "chgrp",     SFTP_CHGRP, 0 },
  2463.     {  "chmod",     SFTP_CHMOD, 0 },
  2464.     {  "chown",     SFTP_CHOWN, 0 },
  2465.     {  "delete",    SFTP_RM,    0 },
  2466.     {  "dir",       SFTP_DIR,   0 },
  2467.     {  "get",       SFTP_GET,   0 },
  2468.     {  "mkdir",     SFTP_MKDIR, 0 },
  2469.     {  "open",      SFTP_OPN,   0 },
  2470.     {  "put",       SFTP_PUT,   0 },
  2471.     {  "pwd",       SFTP_PWD,   0 },
  2472.     {  "rename",    SFTP_REN,   0 },
  2473.     {  "rm",        SFTP_RM,    CM_INV },
  2474.     {  "rmdir",     SFTP_RMDIR, 0 },
  2475.     {  "symlink",   SFTP_LINK,  0 },
  2476.     {  "version",   SFTP_VER,   0 }
  2477. };
  2478. static int nsftpkwtab = (sizeof(sftpkwtab) / sizeof(struct keytab));
  2479. #endif /* SFTP_BUILTIN */
  2480. #endif /* ANYSSH */
  2481.  
  2482. #ifdef NETCONN
  2483. struct keytab netkey[] = {        /* SET NETWORK table */
  2484.     { "directory", XYNET_D,  0 },
  2485.     { "type",      XYNET_T,  0 }
  2486. };
  2487. int nnetkey = (sizeof(netkey) / sizeof(struct keytab));
  2488.  
  2489. struct keytab netcmd[] = {
  2490. /*
  2491.   These are the network types.
  2492. */
  2493. #ifdef NETCMD
  2494.     { "command",       NET_CMD,  CM_INV }, /* Command */
  2495. #endif /* NETCMD */
  2496.  
  2497. #ifdef DECNET                /* DECnet / PATHWORKS */
  2498.     { "decnet",        NET_DEC,  0 },
  2499. #endif /* DECNET */
  2500.  
  2501. #ifdef NETDLL
  2502.     { "dll",           NET_DLL,  CM_INV }, /* DLL to be loaded */
  2503. #endif /* NETDLL */
  2504.  
  2505. #ifdef NETFILE
  2506.     { "file",           NET_FILE, CM_INV }, /* FILE (real crude) */
  2507. #endif /* NETFILE */
  2508.  
  2509. #ifdef NPIPE                /* Named Pipes */
  2510.     { "named-pipe",     NET_PIPE,  0 },
  2511. #endif /* NPIPE */
  2512.  
  2513. #ifdef CK_NETBIOS
  2514.     { "netbios",        NET_BIOS,  0 },    /* NETBIOS */
  2515. #endif /* CK_NETBIOS */
  2516.  
  2517. #ifdef DECNET                /* DECnet / PATHWORKS (alias) */
  2518.     { "pathworks",     NET_DEC,  CM_INV },
  2519. #endif /* DECNET */
  2520.  
  2521. #ifdef NETCMD
  2522.     { "pipe",          NET_CMD,  0 },    /* Pipe */
  2523. #endif /* NETCMD */
  2524.  
  2525. #ifdef NETPTY
  2526.     { "pseudoterminal",NET_PTY, 0 },    /* Pseudoterminal */
  2527. #endif /* NETPTY */
  2528.  
  2529. #ifdef NETPTY
  2530.     { "pty",          NET_PTY,  CM_INV }, /* Inv syn for pseudoterm */
  2531. #endif /* NETPTY */
  2532.  
  2533. #ifdef SSHBUILTIN
  2534.     { "ssh",          NET_SSH,  0 },
  2535. #endif /* SSHBUILTIN */
  2536.  
  2537. #ifdef SUPERLAT
  2538.     { "superlat",     NET_SLAT, 0 },    /* Meridian Technologies' SuperLAT */
  2539. #endif /* SUPERLAT */
  2540.  
  2541. #ifdef TCPSOCKET            /* TCP/IP sockets library */
  2542.     { "tcp/ip",       NET_TCPB, 0 },
  2543. #endif /* TCPSOCKET */
  2544. #ifdef SUPERLAT
  2545.     { "tes32",        NET_SLAT, 0 },    /* Emulux TES32 */
  2546. #endif /* SUPERLAT */
  2547. #ifdef ANYX25                /* X.25 */
  2548. #ifdef SUNX25
  2549.     { "x",            NET_SX25, CM_INV|CM_ABR },
  2550.     { "x.25",         NET_SX25, 0 },
  2551.     { "x25",          NET_SX25, CM_INV },
  2552. #else
  2553. #ifdef STRATUSX25
  2554.     { "x",            NET_VX25, CM_INV|CM_ABR },
  2555.     { "x.25",         NET_VX25, 0 },
  2556.     { "x25",          NET_VX25, CM_INV },
  2557. #endif /* STRATUSX25 */
  2558. #endif /* SUNX25 */
  2559. #ifdef IBMX25
  2560.     { "x",            NET_IX25, CM_INV|CM_ABR },
  2561.     { "x.25",         NET_IX25, CM_INV },
  2562.     { "x25",          NET_IX25, CM_INV },
  2563. #endif /* IBMX25 */
  2564. #ifdef HPX25
  2565.     { "x",            NET_IX25, CM_INV|CM_ABR },
  2566.     { "x.25",         NET_IX25, 0 },
  2567.     { "x25",          NET_IX25, CM_INV },
  2568. #endif /* HPX25 */
  2569. #endif /* ANYX25 */
  2570.     { "", 0, 0 }
  2571. };
  2572. int nnets = (sizeof(netcmd) / sizeof(struct keytab));
  2573.  
  2574. #ifndef NOTCPOPTS
  2575. #ifdef TCPSOCKET
  2576.  
  2577. /* TCP options */
  2578.  
  2579. struct keytab tcpopt[] = {
  2580.     { "address",   XYTCP_ADDRESS, 0 },
  2581. #ifdef CK_DNS_SRV
  2582.     { "dns-service-records", XYTCP_DNS_SRV, 0 },
  2583. #endif /* CK_DNS_SRV */
  2584. #ifdef SO_DONTROUTE
  2585.     { "dontroute",   XYTCP_DONTROUTE, 0 },
  2586. #endif /* SO_DONTROUTE */
  2587. #ifndef NOHTTP
  2588.     { "http-proxy", XYTCP_HTTP_PROXY, 0 },
  2589. #endif /* NOHTTP */
  2590. #ifdef SO_KEEPALIVE
  2591.     { "keepalive", XYTCP_KEEPALIVE, 0 },
  2592. #endif /* SO_KEEPALIVE */
  2593. #ifdef SO_LINGER
  2594.     { "linger", XYTCP_LINGER, 0 },
  2595. #endif /* SO_LINGER */
  2596. #ifdef TCP_NODELAY
  2597.     { "nagle",  XYTCP_NAGLE,    CM_INV },
  2598.     { "nodelay", XYTCP_NODELAY, 0 },
  2599. #endif /* TCP_NODELAY */
  2600.     { "reverse-dns-lookup", XYTCP_RDNS, 0 },
  2601. #ifdef SO_RCVBUF
  2602.     { "recvbuf", XYTCP_RECVBUF, 0 },
  2603. #endif /* SO_RCVBUF */
  2604. #ifdef SO_SNDBUF
  2605.     { "sendbuf", XYTCP_SENDBUF, 0 },
  2606. #endif /* SO_SNDBUF */
  2607. #ifdef NT
  2608. #ifdef CK_SOCKS
  2609.     { "socks-server", XYTCP_SOCKS_SVR, 0 },
  2610. #endif /* CK_SOCKS */
  2611. #endif /* NT */
  2612. #ifdef VMS
  2613. #ifdef DEC_TCPIP
  2614.     { "ucx-port-bug", XYTCP_UCX, 0 },
  2615. #endif /* DEC_TCPIP */
  2616. #endif /* VMS */
  2617.     { "",0,0 }
  2618. };
  2619. int ntcpopt = (sizeof(tcpopt) / sizeof(struct keytab));
  2620. #endif /* TCPSOCKET */
  2621. #endif /* NOTCPOPTS */
  2622. #endif /* NETCONN */
  2623.  
  2624. #ifdef OS2
  2625. /* K95 Manual Chapter Table -- Keep these two tables in sync! */
  2626.  
  2627. static char * linktbl[] = {        /* Internal links in k95.htm */
  2628.     "#top",                /* 00 */
  2629.     "#what",                /* 01 */
  2630.     "#install",                /* 02 */
  2631.     "#start",                /* 03 */
  2632.     "#dialer",                /* 04 */
  2633.     "#entries",                /* 05 */
  2634.     "#command",                /* 06 */
  2635.     "#terminal",            /* 07 */
  2636.     "#transfer",            /* 08 */
  2637.     "#hostmode"                /* 09 */
  2638. };
  2639.  
  2640. static struct keytab chaptbl[] = {
  2641.     { "Command-Screen",     6, 0 },
  2642.     { "Contents",           0, 0 },
  2643.     { "Dialer-Entries",     5, 0 },
  2644.     { "File-Transfer",      8, 0 },
  2645.     { "Getting-Started",    3, 0 },
  2646.     { "Host-Mode",          9, 0 },
  2647.     { "Installation",       2, 0 },
  2648.     { "Terminal-Emulation", 7, 0 },
  2649.     { "Using-The-Dialer",   4, 0 },
  2650.     { "What-Is-K95",        1, 0 },
  2651.     { "",                   0, 0 }
  2652. };
  2653. static int nchaptbl = (sizeof(chaptbl) / sizeof(struct keytab) - 1);
  2654. #endif /* OS2 */
  2655.  
  2656. #ifndef NOXFER
  2657. /* Remote Command Table */
  2658.  
  2659. struct keytab remcmd[] = {
  2660. #ifndef NOSPL
  2661.     { "as",        XZASG, CM_INV|CM_ABR },
  2662.     { "asg",       XZASG, CM_INV },
  2663.     { "assign",    XZASG, 0 },
  2664. #endif /* NOSPL */
  2665.     { "cd",        XZCWD, 0 },
  2666.     { "cdup",      XZCDU, CM_INV },
  2667.     { "copy",      XZCPY, 0 },
  2668.     { "cwd",       XZCWD, CM_INV },
  2669.     { "delete",    XZDEL, 0 },
  2670.     { "directory", XZDIR, 0 },
  2671.     { "e",         XZXIT, CM_ABR|CM_INV },
  2672.     { "erase",     XZDEL, CM_INV },
  2673.     { "exit",      XZXIT, 0 },
  2674.     { "help",      XZHLP, 0 },
  2675. #ifndef NOPUSH
  2676.     { "host",      XZHOS, 0 },
  2677. #endif /* NOPUSH */
  2678. #ifndef NOFRILLS
  2679.     { "kermit",    XZKER, 0 },
  2680.     { "l",         XZLGI, CM_ABR|CM_INV },
  2681.     { "lo",        XZLGI, CM_ABR|CM_INV },
  2682.     { "log",       XZLGI, CM_ABR|CM_INV },
  2683.     { "login",     XZLGI, 0 },
  2684.     { "logout",    XZLGO, 0 },
  2685.     { "message",   XZMSG, 0 },
  2686.     { "mkdir",     XZMKD, 0 },
  2687.     { "print",     XZPRI, 0 },
  2688. #endif /* NOFRILLS */
  2689.     { "pwd",       XZPWD, 0 },
  2690. #ifndef NOSPL
  2691.     { "query",       XZQUE, 0 },
  2692. #endif /* NOSPL */
  2693.     { "rename",    XZREN, 0 },
  2694.     { "rmdir",     XZRMD, 0 },
  2695.     { "set",       XZSET, 0 },
  2696.     { "space",       XZSPA, 0 },
  2697. #ifndef NOFRILLS
  2698.     { "type",      XZTYP, 0 },
  2699.     { "who",       XZWHO, 0 },
  2700. #endif /* NOFRILLS */
  2701.     { "", 0, 0}
  2702. };
  2703. int nrmt = (sizeof(remcmd) / sizeof(struct keytab)) - 1;
  2704. #endif /* NOXFER */
  2705.  
  2706. struct keytab logtab[] = {
  2707. #ifdef CKLOGDIAL
  2708.     { "connections",  LOGM, CM_INV },
  2709.     { "cx",           LOGM, 0 },
  2710. #endif /* CKLOGDIAL */
  2711. #ifdef DEBUG
  2712.     { "debugging",    LOGD, 0 },
  2713. #endif /* DEBUG */
  2714.     { "packets",      LOGP, 0 },
  2715. #ifndef NOLOCAL
  2716.     { "session",      LOGS, 0 },
  2717. #endif /* NOLOCAL */
  2718. #ifdef TLOG
  2719.     { "transactions", LOGT, 0 },
  2720. #endif /* TLOG */
  2721.     { "", 0, 0 }
  2722. };
  2723. int nlog = (sizeof(logtab) / sizeof(struct keytab)) - 1;
  2724.  
  2725. struct keytab writab[] = {
  2726. #ifndef NOSPL
  2727.     { "append-file",     LOGW, CM_INV },
  2728. #endif /* NOSPL */
  2729.     { "debug-log",       LOGD, 0 },
  2730.     { "error",           LOGE, 0 },
  2731. #ifndef NOSPL
  2732.     { "file",            LOGW, 0 },
  2733. #endif /* NOSPL */
  2734.     { "packet-log",      LOGP, 0 },
  2735.     { "screen",          LOGX, 0 },
  2736. #ifndef NOLOCAL
  2737.     { "session-log",     LOGS, 0 },
  2738. #endif /* NOLOCAL */
  2739.     { "sys$output",      LOGX, CM_INV },
  2740.     { "t",               LOGT, CM_ABR|CM_INV }, /* Because of a typo in */
  2741.     { "tr",              LOGT, CM_ABR|CM_INV }, /* the book... */
  2742.     { "tra",             LOGT, CM_ABR|CM_INV },
  2743.     { "tran",            LOGT, CM_ABR|CM_INV },
  2744.     { "trans",           LOGT, CM_ABR|CM_INV },
  2745.     { "transa",          LOGT, CM_ABR|CM_INV },
  2746.     { "transac",         LOGT, CM_ABR|CM_INV },
  2747.     { "transact",        LOGT, CM_ABR|CM_INV },
  2748.     { "transacti",       LOGT, CM_ABR|CM_INV },
  2749.     { "transactio",      LOGT, CM_ABR|CM_INV },
  2750.     { "transaction",     LOGT, CM_ABR|CM_INV },
  2751.     { "transaction-log", LOGT, 0 },
  2752.     { "transactions",    LOGT, CM_INV }
  2753. };
  2754. int nwri = (sizeof(writab) / sizeof(struct keytab));
  2755.  
  2756. static struct keytab clrtab[] = {    /* Keywords for CLEAR command */
  2757. #ifndef NOSPL
  2758.     { "alarm",            CLR_ALR,         0 },
  2759. #ifdef CK_APC
  2760.     { "apc",              CLR_APC,         0 },
  2761. #endif /* CK_APC */
  2762. #ifdef PATTERNS
  2763.     { "binary-patterns",  CLR_BIN,         0 },
  2764. #endif /* PATTERNS */
  2765.     { "both",             CLR_DEV|CLR_INP, CM_INV },
  2766. #endif /* NOSPL */
  2767. #ifdef OS2
  2768.     { "command-screen",   CLR_CMD,         0 },
  2769. #endif /* OS2 */
  2770. #ifndef NOSPL
  2771.     { "device",           CLR_DEV,         CM_INV|CM_ABR },
  2772.     { "device-and-input", CLR_DEV|CLR_INP, 0 },
  2773. #endif /* NOSPL */
  2774.     { "device-buffer",    CLR_DEV,         0 },
  2775. #ifndef NODIAL
  2776.     { "dial-status",      CLR_DIA,     0 },
  2777. #endif /* NODIAL */
  2778. #ifndef NOSPL
  2779.     { "input-buffer",     CLR_INP,         0 },
  2780. #endif /* NOSPL */
  2781.     { "keyboard-buffer",  CLR_KBD,         0 },
  2782.     { "send-list",        CLR_SFL,         0 },
  2783. #ifdef OS2
  2784.     { "scr",              CLR_SCL,         CM_INV|CM_ABR },
  2785. #endif /* OS2 */
  2786.     { "screen",           CLR_SCR,         0 },
  2787. #ifdef OS2
  2788.     { "scrollback",       CLR_SCL,         CM_INV },
  2789.     { "terminal-screen",  CLR_TRM,         0 },
  2790. #endif /* OS2 */
  2791. #ifdef PATTERNS
  2792.     { "text-patterns",    CLR_TXT,         0 },
  2793. #endif /* PATTERNS */
  2794.     { "", 0, 0 }
  2795. };
  2796. int nclear = (sizeof(clrtab) / sizeof(struct keytab)) - 1;
  2797.  
  2798. struct keytab clstab[] = {        /* Keywords for CLOSE command */
  2799. #ifndef NOSPL
  2800.     { "!read",           LOGR, CM_INV },
  2801.     { "!write",          LOGW, CM_INV },
  2802. #ifndef NOPUSH
  2803. #endif /* NOPUSH */
  2804. #endif /* NOSPL */
  2805. #ifndef NOSPL
  2806.     { "append-file",     LOGW, CM_INV },
  2807. #endif /* NOSPL */
  2808. #ifndef NOLOCAL
  2809.     { "connection",      9999, 0 },
  2810. #endif /* NOLOCAL */
  2811. #ifdef CKLOGDIAL
  2812.     { "cx-log",          LOGM, 0 },
  2813. #endif /* CKLOGDIAL */
  2814. #ifdef DEBUG
  2815.     { "debug-log",       LOGD, 0 },
  2816. #endif /* DEBUG */
  2817.     { "host",            9999, CM_INV }, /* Synonym for CLOSE CONNECTION */
  2818.     { "line",            9999, CM_INV }, /* Synonym for CLOSE CONNECTION */
  2819.     { "p",               LOGP, CM_INV|CM_ABR },
  2820.     { "packet-log",      LOGP, 0 },
  2821.     { "port",            9999, CM_INV }, /* Synonym for CLOSE CONNECTION */
  2822. #ifndef NOSPL
  2823.     { "read-file",       LOGR, 0 },
  2824. #endif /* NOSPL */
  2825. #ifndef NOLOCAL
  2826.     { "session-log",     LOGS, 0 },
  2827. #endif /* NOLOCAL */
  2828. #ifdef TLOG
  2829.     { "t",               LOGT, CM_ABR|CM_INV }, /* Because of a typo in */
  2830.     { "tr",              LOGT, CM_ABR|CM_INV }, /* the book... */
  2831.     { "tra",             LOGT, CM_ABR|CM_INV },
  2832.     { "tran",            LOGT, CM_ABR|CM_INV },
  2833.     { "trans",           LOGT, CM_ABR|CM_INV },
  2834.     { "transa",          LOGT, CM_ABR|CM_INV },
  2835.     { "transac",         LOGT, CM_ABR|CM_INV },
  2836.     { "transact",        LOGT, CM_ABR|CM_INV },
  2837.     { "transacti",       LOGT, CM_ABR|CM_INV },
  2838.     { "transactio",      LOGT, CM_ABR|CM_INV },
  2839.     { "transaction",     LOGT, CM_ABR|CM_INV },
  2840.     { "transaction-log", LOGT, 0 },
  2841.     { "transactions",    LOGT, CM_INV },
  2842. #endif /* TLOG */
  2843. #ifndef NOSPL
  2844.     { "write-file",      LOGW, 0 },
  2845. #endif /* NOSPL */
  2846.     { "", 0, 0 }
  2847. };
  2848. int ncls = (sizeof(clstab) / sizeof(struct keytab)) - 1;
  2849.  
  2850. /* SHOW command arguments */
  2851.  
  2852. #ifndef NOSHOW
  2853. struct keytab shotab[] = {
  2854. #ifndef NOSPL
  2855.     { "alarm",        SHALRM, 0 },
  2856.     { "arg",          SHARG, CM_INV|CM_ABR },
  2857.     { "arguments",    SHARG, 0 },
  2858.     { "args",         SHARG, CM_INV },
  2859.     { "arrays",       SHARR, 0 },
  2860. #endif /* NOSPL */
  2861.  
  2862. #ifndef NOCSETS
  2863.     { "associations", SHASSOC, 0 },
  2864. #endif /* NOCSETS */
  2865.  
  2866. #ifndef NOXFER
  2867.     { "attributes",   SHATT, 0 },
  2868. #endif /* NOXFER */
  2869.  
  2870. #ifdef CK_AUTHENTICATION
  2871.     { "authentication", SHOAUTH, CM_INV },
  2872. #endif /* CK_AUTHENTICATION */
  2873.  
  2874. #ifndef NOPUSH
  2875. #ifdef BROWSER
  2876.     { "browser",      SHBROWSE, CM_PSH|CM_LOC },
  2877. #endif /*  BROWSER */
  2878. #endif /* NOPUSH */
  2879.     { "cd",           SHCD, 0 },
  2880.     { "character-sets", SHCSE, 0 },
  2881.     { "cmd",          SHCMD, CM_INV },
  2882. #ifndef NOLOCAL
  2883.     { "com",          SHCOM, CM_INV|CM_ABR },
  2884.     { "comm",         SHCOM, CM_INV|CM_ABR },
  2885.     { "communications", SHCOM, 0 },
  2886. #endif /* NOLOCAL */
  2887.     { "command",      SHCMD, 0 },
  2888.     { "connection",   SHCONNX, 0 },
  2889. #ifdef CK_SPEED
  2890.     { "control-prefixing", SHCTL, 0 },
  2891. #endif /* CK_SPEED */
  2892. #ifdef CKLOGDIAL
  2893.     { "cx",           SHCONNX, CM_INV },
  2894. #endif /* CKLOGDIAL */
  2895. #ifndef NOSPL
  2896.     { "count",        SHCOU, 0 },
  2897. #endif /* NOSPL */
  2898.     { "d",            SHDIA, CM_INV|CM_ABR },
  2899. #ifdef VMS
  2900.     { "default",      SHDFLT, 0 },
  2901. #else
  2902.     { "default",      SHDFLT, CM_INV },
  2903. #endif /* VMS */
  2904. #ifndef NODIAL
  2905.     { "dial",         SHDIA, CM_LOC },
  2906. #endif /* NODIAL */
  2907.     { "double/ignore",SHDBL, 0 },
  2908. #ifndef NOPUSH
  2909. #ifndef NOFRILLS
  2910.     { "editor",       SHEDIT, CM_PSH },
  2911. #endif /*  NOFRILLS */
  2912. #endif /* NOPUSH */
  2913. #ifndef NOLOCAL
  2914.     { "escape",       SHESC, CM_LOC },
  2915. #endif /* NOLOCAL */
  2916.     { "exit",         SHEXI, 0 },
  2917.     { "extended-options", SHXOPT, CM_INV },
  2918.     { "features",     SHFEA, 0 },
  2919.     { "file",         SHFIL, 0 },
  2920. #ifndef NOLOCAL
  2921.     { "flow-control", SHOFLO, 0 },
  2922. #endif /* NOLOCAL */
  2923. #ifdef BROWSER
  2924.     { "ftp",          SHOFTP, CM_PSH|CM_LOC },
  2925. #else
  2926. #ifndef NOFTP
  2927. #ifndef SYSFTP
  2928. #ifdef TCPSOCKET
  2929.     { "ftp",          SHOFTP, 0 },    /* (built-in ftp) */
  2930. #endif /* TCPSOCKET */
  2931. #endif /* SYSFTP */
  2932. #endif /* NOFTP */
  2933. #endif /* BROWSER */
  2934. #ifndef NOSPL
  2935.     { "functions",    SHFUN, 0 },
  2936.     { "globals",      SHVAR, 0 },
  2937. #endif /* NOSPL */
  2938. #ifdef KUI
  2939.     { "gui",          SHOGUI, 0 },
  2940. #endif /* KUI */
  2941. #ifdef CK_RECALL
  2942.     { "history",      SHHISTORY, 0 },
  2943. #endif /* CK_RECALL */
  2944.     { "ignore/double",SHDBL, CM_INV },
  2945.     { "iksd",         SHOIKS, CM_INV },
  2946. #ifndef NOSPL
  2947.     { "input",        SHINP, 0 },
  2948. #endif /* NOSPL */
  2949. #ifndef NOSETKEY
  2950.     { "k",            SHKEY, CM_INV|CM_ABR },
  2951.     { "key",          SHKEY, 0 },
  2952. #ifndef NOKVERBS
  2953.     { "kverbs",       SHKVB, 0 },
  2954. #endif /* NOKVERBS */
  2955. #endif /* NOSETKEY */
  2956. #ifdef CK_LABELED
  2957.     { "labeled-file-info", SHLBL, 0 },
  2958. #endif /* CK_LABELED */
  2959. #ifndef NOCSETS
  2960.     { "languages",    SHLNG, 0 },
  2961. #endif /* NOCSETS */
  2962.     { "logs",         SHLOG, 0 },
  2963. #ifndef NOSPL
  2964.     { "macros",       SHMAC, 0 },
  2965. #endif /* NOSPL */
  2966. #ifndef NODIAL
  2967.     { "modem",        SHMOD, CM_LOC },
  2968. #else
  2969.     { "modem-signals",SHCOM, CM_INV|CM_LOC },
  2970. #endif /* NODIAL */
  2971. #ifndef NOLOCAL
  2972. #ifdef OS2MOUSE
  2973.     { "mouse",        SHMOU, CM_LOC },
  2974. #endif /* OS2MOUSE */
  2975. #endif /* NOLOCAL */
  2976. #ifdef NETCONN
  2977.     { "network",      SHNET, CM_LOC },
  2978. #else
  2979.     { "network",      SHNET, CM_INV|CM_LOC },
  2980. #endif /* NETCONN */
  2981.     { "options",      SHOPTS, 0 },
  2982. #ifndef NOSPL
  2983.     { "output",       SHOUTP, CM_INV },
  2984. #endif /* NOSPL */
  2985. #ifdef ANYX25
  2986. #ifndef IBMX25
  2987.     { "pad",          SHPAD,  CM_LOC },
  2988. #endif /* IBMX25 */
  2989. #endif /* ANYX25 */
  2990.     { "parameters",   SHPAR,  CM_INV },
  2991. #ifdef PATTERNS
  2992.     { "patterns",     SHOPAT, 0 },
  2993. #endif /* PATTERNS */
  2994.     { "printer",      SHPRT,  0 },
  2995. #ifdef CK_SPEED
  2996.     { "prefixing",    SHCTL,  CM_INV },
  2997. #endif /* CK_SPEED */
  2998. #ifndef NOXFER
  2999.     { "protocol",     SHPRO,  0 },
  3000. #endif /* NOXFER */
  3001.     { "rename",       SHOREN, 0 },
  3002. #ifndef NOSPL
  3003.     { "scripts",      SHSCR,  CM_LOC },
  3004. #endif /* NOSPL */
  3005.     { "send-list",    SHSFL,  0 },
  3006. #ifndef NOSERVER
  3007.     { "server",       SHSER,  0 },
  3008. #endif /* NOSERVER */
  3009. #ifndef NOSEXP
  3010.     { "sexpression",  SHSEXP, 0 },
  3011. #endif /* NOSEXP */
  3012. #ifdef ANYSSH
  3013.     { "ssh",          SHOSSH, 0 },
  3014. #endif /* ANYSSH */
  3015.     { "stack",        SHSTK,  0 },
  3016.     { "status",       SHSTA,  0 },
  3017. #ifdef STREAMING
  3018.     { "streaming",    SHOSTR, 0 },
  3019. #endif /* STREAMING */
  3020. #ifndef NOLOCAL
  3021. #ifdef OS2
  3022.     { "tabs",          SHTAB, CM_INV|CM_LOC },
  3023. #endif /* OS2 */
  3024. #ifdef CK_TAPI
  3025.     { "tapi",          SHTAPI, CM_LOC },
  3026.     { "tapi-comm",     SHTAPI_C, CM_INV|CM_LOC },
  3027.     { "tapi-location", SHTAPI_L, CM_INV|CM_LOC },
  3028.     { "tapi-modem",    SHTAPI_M, CM_INV|CM_LOC },
  3029. #endif /* CK_TAPI */
  3030.     { "tcp",           SHTCP,  CM_LOC },
  3031. #ifdef TNCODE
  3032.     { "tel",           SHTEL,  CM_INV|CM_ABR },
  3033.     { "telnet",        SHTEL,  0 },
  3034.     { "telopt",        SHTOPT, 0 },
  3035. #endif /* TNCODE */
  3036.     { "terminal",      SHTER,  CM_LOC },
  3037. #endif /* NOLOCAL */
  3038. #ifndef NOXMIT
  3039.     { "tr",            SHXMI, CM_INV|CM_ABR },
  3040.     { "tra",           SHXMI, CM_INV|CM_ABR },
  3041.     { "tran",          SHXMI, CM_INV|CM_ABR },
  3042.     { "trans",         SHXMI, CM_INV|CM_ABR },
  3043. #endif /* NOXMIT */
  3044. #ifndef NOXFER
  3045.     { "transfer",      SHOXFER, 0 },
  3046. #endif /* NOXFER */
  3047. #ifndef NOXMIT
  3048.     { "transmit",      SHXMI, 0 },
  3049. #endif /* NOXMIT */
  3050. #ifdef CK_TRIGGER
  3051.     { "trigger",       SHTRIG, CM_LOC },
  3052. #endif /* CK_TRIGGER */
  3053. #ifndef NOSETKEY
  3054. #ifndef NOKVERBS
  3055. #ifdef OS2
  3056.     { "udk",           SHUDK, CM_LOC },
  3057. #endif /* OS2 */
  3058. #endif /* NOKVERBS */
  3059. #endif /* NOSETKEY */
  3060. #ifndef NOSPL
  3061.     { "variables",     SHBUI, 0 },
  3062. #endif /* NOSPL */
  3063. #ifndef NOFRILLS
  3064.     { "versions",      SHVER, 0 },
  3065. #endif /* NOFRILLS */
  3066. #ifdef OS2
  3067.     { "vscrn",         SHVSCRN, CM_INV|CM_LOC },
  3068. #endif /* OS2 */
  3069.     { "xfer",          SHOXFER,  CM_INV },
  3070. #ifndef NOXMIT
  3071.     { "xmit",          SHXMI,    CM_INV },
  3072. #endif /* NOXMIT */
  3073.     { "", 0, 0 }
  3074. };
  3075. int nsho = (sizeof(shotab) / sizeof(struct keytab)) - 1;
  3076. #endif /* NOSHOW */
  3077.  
  3078. #ifdef ANYX25
  3079. #ifndef IBMX25
  3080. struct keytab padtab[] = {              /* PAD commands */
  3081.     { "clear",      XYPADL, 0 },
  3082.     { "interrupt",  XYPADI, 0 },
  3083.     { "reset",      XYPADR, 0 },
  3084.     { "status",     XYPADS, 0 }
  3085. };
  3086. int npadc = (sizeof(padtab) / sizeof(struct keytab));
  3087. #endif /* IBMX25 */
  3088. #endif /* ANYX25 */
  3089.  
  3090. #ifndef NOSERVER
  3091. static struct keytab kmstab[] = {
  3092.     { "both",    3, 0 },
  3093.     { "local",   1, 0 },
  3094.     { "remote",  2, 0 }
  3095. };
  3096.  
  3097. static struct keytab enatab[] = {    /* ENABLE commands */
  3098.     { "all",        EN_ALL,  0 },
  3099. #ifndef NOSPL
  3100.     { "as",         EN_ASG,  CM_INV|CM_ABR },
  3101.     { "asg",        EN_ASG,  CM_INV },
  3102.     { "assign",     EN_ASG,  0 },
  3103. #endif /* NOSPL */
  3104. #ifndef datageneral
  3105.     { "bye",        EN_BYE,  0 },
  3106. #endif /* datageneral */
  3107.     { "cd",         EN_CWD,  0 },
  3108. #ifdef ZCOPY
  3109.     { "copy",       EN_CPY,  0 },
  3110. #endif /* ZCOPY */
  3111.     { "cwd",        EN_CWD,  CM_INV },
  3112.     { "delete",     EN_DEL,  0 },
  3113.     { "directory",  EN_DIR,  0 },
  3114.     { "enable",     EN_ENA,  CM_INV },
  3115.     { "exit",       EN_XIT,  0 },
  3116.     { "finish",     EN_FIN,  0 },
  3117.     { "get",        EN_GET,  0 },
  3118.     { "host",       EN_HOS,  0 },
  3119.     { "mail",       EN_MAI,  0 },
  3120.     { "mkdir",      EN_MKD,  0 },
  3121.     { "print",      EN_PRI,  0 },
  3122. #ifndef NOSPL
  3123.     { "query",      EN_QUE,  0 },
  3124. #endif /* NOSPL */
  3125.     { "rename",     EN_REN,  0 },
  3126.     { "retrieve",   EN_RET,  CM_INV },
  3127.     { "rmdir",      EN_RMD,  0 },
  3128.     { "send",       EN_SEN,  0 },
  3129.     { "set",        EN_SET,  0 },
  3130.     { "space",      EN_SPA,  0 },
  3131.     { "type",       EN_TYP,  0 },
  3132.     { "who",        EN_WHO,  0 }
  3133. };
  3134. static int nena = (sizeof(enatab) / sizeof(struct keytab));
  3135. #endif /* NOSERVER */
  3136.  
  3137. struct keytab txtbin[] = {
  3138.     { "all",        2, 0 },
  3139.     { "binary",     1, 0 },
  3140.     { "text",       0, 0 }
  3141. };
  3142.  
  3143. #ifndef NOXFER
  3144. static struct keytab sndtab[] = {    /* SEND command options */
  3145.     { "/after",           SND_AFT, CM_ARG },
  3146. #ifndef NOSPL
  3147.     { "/array",           SND_ARR, CM_ARG },
  3148. #endif /* NOSPL */
  3149.     { "/as-name",         SND_ASN, CM_ARG },
  3150.     { "/b",               SND_BIN, CM_INV|CM_ABR },
  3151.     { "/before",          SND_BEF, CM_ARG },
  3152.     { "/binary",          SND_BIN, 0 },
  3153. #ifdef CALIBRATE
  3154.     { "/c",               SND_CMD, CM_INV|CM_ABR },
  3155.     { "/calibrate",       SND_CAL, CM_INV|CM_ARG },
  3156. #endif /* CALIBRATE */
  3157.     { "/command",         SND_CMD, CM_PSH },
  3158.     { "/delete",          SND_DEL, 0 },
  3159. #ifdef UNIXOROSK
  3160.     { "/dotfiles",        SND_DOT, 0 },
  3161. #endif /* UNIXOROSK */
  3162.     { "/except",          SND_EXC, CM_ARG },
  3163. #ifdef PIPESEND
  3164.     { "/filter",          SND_FLT, CM_ARG|CM_PSH },
  3165. #endif /* PIPESEND */
  3166.     { "/filenames",       SND_NAM, CM_ARG },
  3167. #ifdef CKSYMLINK
  3168.     { "/followlinks",      SND_LNK, 0 },
  3169. #endif /* CKSYMLINK */
  3170. #ifdef VMS
  3171.     { "/image",           SND_IMG, 0 },
  3172. #else
  3173.     { "/image",           SND_BIN, CM_INV },
  3174. #endif /* VMS */
  3175. #ifdef CK_LABELED
  3176.     { "/labeled",         SND_LBL, 0 },
  3177. #endif /* CK_LABELED */
  3178.     { "/larger-than",     SND_LAR, CM_ARG },
  3179.     { "/listfile",        SND_FIL, CM_ARG },
  3180. #ifndef NOFRILLS
  3181.     { "/mail",            SND_MAI, CM_ARG },
  3182. #endif /* NOFRILLS */
  3183. #ifdef CK_TMPDIR
  3184.     { "/move-to",         SND_MOV, CM_ARG },
  3185. #endif /* CK_TMPDIR */
  3186.     { "/nobackupfiles",   SND_NOB, 0 },
  3187. #ifdef UNIXOROSK
  3188.     { "/nodotfiles",      SND_NOD, 0 },
  3189. #endif /* UNIXOROSK */
  3190. #ifdef CKSYMLINK
  3191.     { "/nofollowlinks",      SND_NLK, 0 },
  3192. #endif /* CKSYMLINK */
  3193.     { "/not-after",       SND_NAF, CM_ARG },
  3194.     { "/not-before",      SND_NBE, CM_ARG },
  3195.     { "/pathnames",       SND_PTH, CM_ARG },
  3196.     { "/print",           SND_PRI, CM_ARG },
  3197. #ifdef CK_XYZ
  3198.     { "/protocol",        SND_PRO, CM_ARG },
  3199. #else
  3200.     { "/protocol",        SND_PRO, CM_ARG|CM_INV },
  3201. #endif /* CK_XYZ */
  3202.     { "/quiet",           SND_SHH, 0 },
  3203.     { "/recover",         SND_RES, 0 },
  3204. #ifdef RECURSIVE
  3205. /* Systems where we do recursion */
  3206.     { "/recursive",       SND_REC, 0 },
  3207. #else
  3208. #ifdef VMS
  3209. /* Systems that do recursion themselves without our assistance */
  3210. /* if we give them the right kind of wildcard */
  3211.     { "/recursive",       SND_REC, 0 },
  3212. #else
  3213. #ifdef datageneral
  3214.     { "/recursive",       SND_REC, 0 },
  3215. #else
  3216.     { "/recursive",       SND_REC, CM_INV },
  3217. #endif /* datageneral */
  3218. #endif /* VMS */
  3219. #endif /* RECURSIVE */
  3220.     { "/rename-to",       SND_REN, CM_ARG },
  3221.     { "/since",           SND_AFT, CM_INV|CM_ARG },
  3222.     { "/smaller-than",    SND_SMA, CM_ARG },
  3223.     { "/starting-at",     SND_STA, CM_ARG },
  3224. #ifndef NOFRILLS
  3225.     { "/su",              SND_ASN, CM_ARG|CM_INV|CM_ABR },
  3226.     { "/sub",             SND_ASN, CM_ARG|CM_INV|CM_ABR },
  3227.     { "/subject",         SND_ASN, CM_ARG },
  3228. #endif /* NOFRILLS */
  3229. #ifdef RECURSIVE
  3230.     { "/subdirectories",  SND_REC, CM_INV },
  3231. #endif /* RECURSIVE */
  3232.     { "/text",            SND_TXT, 0 },
  3233.     { "/transparent",     SND_XPA, 0 },
  3234.     { "/type",            SND_TYP, CM_ARG }
  3235. };
  3236. #define NSNDTAB sizeof(sndtab)/sizeof(struct keytab)
  3237. static int nsndtab = NSNDTAB;
  3238.  
  3239. #ifndef NOMSEND
  3240. static struct keytab msndtab[] = {    /* MSEND options */
  3241.     { "/after",           SND_AFT, CM_ARG },
  3242.     { "/before",          SND_BEF, CM_ARG },
  3243.     { "/binary",          SND_BIN, 0 },
  3244.     { "/delete",          SND_DEL, 0 },
  3245.     { "/except",          SND_EXC, CM_ARG },
  3246.     { "/filenames",       SND_NAM, CM_ARG },
  3247. #ifdef CKSYMLINK
  3248.     { "/followlinks",      SND_LNK, 0 },
  3249. #endif /* CKSYMLINK */
  3250. #ifdef VMS
  3251.     { "/image",           SND_IMG, 0 },
  3252. #else
  3253.     { "/image",           SND_BIN, CM_INV },
  3254. #endif /* VMS */
  3255. #ifdef CK_LABELED
  3256.     { "/labeled",         SND_LBL, 0 },
  3257. #endif /* CK_LABELED */
  3258.     { "/larger-than",     SND_LAR, CM_ARG },
  3259.     { "/list",            SND_FIL, CM_ARG },
  3260. #ifndef NOFRILLS
  3261.     { "/mail",            SND_MAI, CM_ARG },
  3262. #endif /* NOFRILLS */
  3263. #ifdef CK_TMPDIR
  3264.     { "/move-to",         SND_MOV, CM_ARG },
  3265. #endif /* CK_TMPDIR */
  3266. #ifdef CKSYMLINK
  3267.     { "/nofollowlinks",    SND_NLK, 0 },
  3268. #endif /* CKSYMLINK */
  3269.     { "/not-after",       SND_NAF, CM_ARG },
  3270.     { "/not-before",      SND_NBE, CM_ARG },
  3271.     { "/pathnames",       SND_PTH, CM_ARG },
  3272.     { "/print",           SND_PRI, CM_ARG },
  3273. #ifdef CK_XYZ
  3274.     { "/protocol",        SND_PRO, CM_ARG },
  3275. #endif /* CK_XYZ */
  3276.     { "/quiet",           SND_SHH, 0 },
  3277.     { "/recover",         SND_RES, 0 },
  3278.     { "/rename-to",       SND_REN, CM_ARG },
  3279.     { "/since",           SND_AFT, CM_INV|CM_ARG },
  3280.     { "/smaller-than",    SND_SMA, CM_ARG },
  3281.     { "/starting-at",     SND_STA, CM_ARG },
  3282. #ifndef NOFRILLS
  3283.     { "/subject",         SND_ASN, CM_ARG },
  3284. #endif /* NOFRILLS */
  3285.     { "/text",            SND_TXT, 0 },
  3286.     { "/transparent",     SND_XPA, 0 },
  3287.     { "/type",            SND_TYP, CM_ARG }
  3288. };
  3289. #define NMSNDTAB sizeof(msndtab)/sizeof(struct keytab)
  3290. static int nmsndtab = NMSNDTAB;
  3291. #endif /* NOMSEND */
  3292. #endif /* NOXFER */
  3293.  
  3294. /* CONNECT command switches */
  3295.  
  3296. #define CONN_II  0    /* Idle interval */
  3297. #define CONN_IS  1    /* Idle string */
  3298. #define CONN_IL  2    /* Idle limit */
  3299. #define CONN_NV  3    /* Non-Verbose */
  3300. #define CONN_TL  4    /* Time limit */
  3301. #define CONN_TS  5    /* Trigger string */
  3302. #define CONN_AS  6    /* Asynchronous */
  3303. #define CONN_SY  7    /* Synchronous */
  3304. #define CONN_MAX 7    /* Number of CONNECT switches */
  3305.  
  3306. #ifndef NOLOCAL
  3307. static struct keytab conntab[] = {
  3308. #ifdef OS2
  3309.     { "/asynchronous",    CONN_AS, CM_INV },
  3310. #endif /* OS2 */
  3311. #ifdef XLIMITS
  3312.     { "/idle-interval",   CONN_II, CM_ARG },
  3313.     { "/idle-limit",      CONN_IL, CM_ARG },
  3314.     { "/idle-string",     CONN_IS, CM_ARG },
  3315.     { "/quietly",         CONN_NV, CM_INV },
  3316. #else
  3317.     { "/quietly",         CONN_NV, 0 },
  3318. #endif /* XLIMITS */
  3319. #ifdef OS2
  3320.     { "/synchronous",     CONN_SY, CM_INV },
  3321. #endif /* OS2 */
  3322. #ifdef XLIMITS
  3323.     { "/time-limit",      CONN_TL, CM_ARG },
  3324. #endif /* XLIMITS */
  3325. #ifdef CK_TRIGGER
  3326.     { "/trigger",         CONN_TS, CM_ARG },
  3327. #endif /* CK_TRIGGER */
  3328.     { "",0,0 }
  3329. };
  3330. #define NCONNTAB sizeof(conntab)/sizeof(struct keytab)
  3331. static int nconntab = NCONNTAB;
  3332. #endif /* NOLOCAL */
  3333.  
  3334. #ifndef NOXFER
  3335. static struct keytab stattab[] = {    /* STATISTICS command switches */
  3336.     { "/brief",   1, 0 },
  3337.     { "/verbose", 0, 0 }
  3338. };
  3339. #endif /* NOXFER */
  3340.  
  3341. #ifndef NOSPL
  3342. #ifdef COMMENT
  3343. struct mtab mactab[MAC_MAX] = {        /* Preinitialized macro table */
  3344.     { NULL, NULL, 0 }
  3345. };
  3346. #else
  3347. struct mtab *mactab;            /* Dynamically allocated macro table */
  3348. #endif /* COMMENT */
  3349. int nmac = 0;
  3350.  
  3351. struct keytab mackey[MAC_MAX];        /* Macro names as command keywords */
  3352. #endif /* NOSPL */
  3353.  
  3354. #ifndef NOSPL
  3355. #ifdef  OS2
  3356. struct keytab beeptab[] = {        /* Beep options */
  3357.     { "error", BP_FAIL, 0 },
  3358.     { "information", BP_NOTE, 0 },
  3359.     { "warning", BP_WARN, 0 }
  3360. };
  3361. int nbeeptab = sizeof(beeptab)/sizeof(struct keytab);
  3362.  
  3363. /* CLEAR COMMMAND-SCREEN options */
  3364.  
  3365. #define CLR_C_ALL 0
  3366. #define CLR_C_BOL 1
  3367. #define CLR_C_BOS 2
  3368. #define CLR_C_EOL 3
  3369. #define CLR_C_EOS 4
  3370. #define CLR_C_LIN 5
  3371. #define CLR_C_SCR 6
  3372.  
  3373. struct keytab clrcmdtab[] = {
  3374.     { "all",        CLR_C_ALL, 0 },
  3375.     { "bol",        CLR_C_BOL, 0 },
  3376.     { "bos",        CLR_C_BOS, 0 },
  3377.     { "eol",        CLR_C_EOL, 0 },
  3378.     { "eos",        CLR_C_EOS, 0 },
  3379.     { "line",       CLR_C_LIN, 0 },
  3380.     { "scrollback", CLR_C_SCR, 0 }
  3381. };
  3382. int nclrcmd = sizeof(clrcmdtab)/sizeof(struct keytab);
  3383. #endif /* OS2 */
  3384. #endif /* NOSPL */
  3385.  
  3386. #ifdef COMMENT
  3387. /* Not used at present */
  3388. static struct keytab pagetab[] = {
  3389.     { "/more",   1, CM_INV },
  3390.     { "/nopage", 0, 0 },
  3391.     { "/page",   1, 0 }
  3392. };
  3393. int npagetab = sizeof(pagetab)/sizeof(struct keytab);
  3394. #endif /* COMMENT */
  3395.  
  3396. #define TYP_NOP  0            /* /NOPAGE */
  3397. #define TYP_PAG  1            /* /PAGE */
  3398. #define TYP_HEA  2            /* /HEAD:n */
  3399. #define TYP_TAI  3            /* /TAIL:n */
  3400. #define TYP_PAT  4            /* /MATCH:pattern */
  3401. #define TYP_WID  5            /* /WIDTH:cols */
  3402. #define TYP_COU  6            /* /COUNT */
  3403. #define TYP_OUT  7            /* /OUTPUT:file */
  3404. #define TYP_PFX  8            /* /PREFIX:string */
  3405. #ifdef UNICODE
  3406. #define TYP_XIN  9            /* /TRANSLATE-FROM:charset */
  3407. #define TYP_XUT 10            /* /TRANSLATE-TO:charset */
  3408. #define TYP_XPA 11            /* /TRANSPARENT */
  3409. #endif /* UNICODE */
  3410. #ifdef KUI
  3411. #define TYP_GUI 12            /* /GUI:title */
  3412. #define TYP_HIG 13            /* /HEIGHT:rows */
  3413. #endif /* KUI */
  3414. #define TYP_NUM 14            /* /NUMBER */
  3415.  
  3416. static struct keytab typetab[] = {    /* TYPE command switches */
  3417.     { "/count",          TYP_COU, 0 },
  3418. #ifdef UNICODE
  3419.     { "/character-set",  TYP_XIN, CM_ARG },
  3420. #endif /* UNICODE */
  3421. #ifdef KUI
  3422.     { "/gui",            TYP_GUI, CM_ARG },
  3423. #endif /* KUI */
  3424.     { "/head",           TYP_HEA, CM_ARG },
  3425. #ifdef KUI
  3426.     { "/height",         TYP_HIG, CM_ARG },
  3427. #endif /* KUI */
  3428.     { "/match",          TYP_PAT, CM_ARG },
  3429. #ifdef CK_TTGWSIZ
  3430.     { "/more",           TYP_PAG, CM_INV },
  3431.     { "/nopage",         TYP_NOP, 0 },
  3432.     { "/number",         TYP_NUM, 0 },
  3433.     { "/output",         TYP_OUT, CM_ARG },
  3434.     { "/page",           TYP_PAG, 0 },
  3435. #endif /* CK_TTGWSIZ */
  3436.     { "/prefix",         TYP_PFX, CM_ARG },
  3437.     { "/tail",           TYP_TAI, CM_ARG },
  3438. #ifdef UNICODE
  3439.     { "/translate-to",   TYP_XUT, CM_ARG },
  3440.     { "/transparent",    TYP_XPA, 0 },
  3441. #endif /* UNICODE */
  3442.     { "/width",          TYP_WID, CM_ARG },
  3443. #ifdef UNICODE
  3444.     { "/xlate-to",       TYP_XUT, CM_INV|CM_ARG },
  3445. #endif /* UNICODE */
  3446.     { "", 0, 0 }
  3447. };
  3448. int ntypetab = sizeof(typetab)/sizeof(struct keytab) - 1;
  3449.  
  3450. int typ_page = -1;            /* TYPE /[NO]PAGE default */
  3451. int typ_wid  = -1;
  3452.  
  3453. #ifndef NOSPL
  3454. #define TRA_ALL 999            /* TRACE command */
  3455. #define TRA_ASG 0
  3456. #define TRA_CMD 1
  3457.  
  3458. int tra_asg = 0;
  3459. int tra_cmd = 0;
  3460.  
  3461. static struct keytab tracetab[] = {    /* TRACE options */
  3462.     { "all",            TRA_ALL, 0 },
  3463.     { "assignments",    TRA_ASG, 0 },
  3464.     { "command-level",  TRA_CMD, 0 }
  3465. };
  3466. static int ntracetab = sizeof(tracetab)/sizeof(struct keytab);
  3467. #endif /* NOSPL */
  3468.  
  3469. #ifndef NOSHOW
  3470. VOID
  3471. showtypopts() {
  3472.     printf(" TYPE ");
  3473.     if (typ_page > -1) {
  3474.     prtopt(&optlines,typ_page ? "/PAGE" : "/NOPAGE");
  3475.     } else
  3476.       prtopt(&optlines,"(no options set)");
  3477.     if (typ_wid > -1) {
  3478.     ckmakmsg(tmpbuf,TMPBUFSIZ,"/WIDTH:",ckitoa(typ_wid),NULL,NULL);
  3479.     prtopt(&optlines,tmpbuf);
  3480.     }
  3481.     prtopt(&optlines,"");
  3482. }
  3483. #endif /* NOSHOW */
  3484.  
  3485. #ifdef LOCUS
  3486. /* isauto == 1 if locus is being switched automatically */
  3487.  
  3488. VOID
  3489. setlocus(x, isauto) int x, isauto; {
  3490.     extern int quitting;
  3491.     if (x) x = 1;
  3492.     if (x && locus) return;
  3493.     if (!x && !locus) return;
  3494.     /* Get here if it actually needs to be changed */
  3495. #ifdef OS2
  3496.     if (isauto &&            /* Automatically switching */
  3497.     !quitting &&            /* not exiting */
  3498.     autolocus == 2) {        /* and AUTOLOCUS is set to ASK */
  3499.     char locmsg[300];
  3500.     ckmakmsg(locmsg,300,
  3501.          "Switching Locus to ",
  3502.          x ? "LOCAL" : "REMOTE",
  3503.          " for file management commands\n"
  3504.                  "such as CD, DIRECTORY, DELETE, RENAME.  Type HELP SET\n"
  3505.                  "LOCUS at the K-95> prompt for further info.  Use the\n"
  3506. #ifdef KUI
  3507.                   "Actions menu or SET LOCUS command to disable automatic\n"
  3508.                   "Locus switching or to disable these queries.",
  3509. #else /* KUI */
  3510.                   "SET LOCUS command to disable automatic locus switching\n"
  3511.                   "or to disable these queries.",
  3512. #endif /* KUI */
  3513.                   NULL);
  3514.     if (uq_ok(locmsg,"OK to switch Locus?",3,NULL,1)) {
  3515.         locus = x;
  3516. #ifdef KUI
  3517.         KuiSetProperty(KUI_LOCUS,x,0);
  3518. #endif /* KUI */
  3519.         return;
  3520.     }
  3521.     } else {
  3522. #endif /* OS2 */
  3523.         if (isauto && msgflg && !quitting)
  3524.           printf("Switching LOCUS for file-management commands to %s %s.\n",
  3525.          x ? "LOCAL" : "REMOTE",
  3526.          "(HELP LOCUS for info)"
  3527.          );
  3528.     locus = x;
  3529. #ifdef OS2
  3530. #ifdef KUI
  3531.     KuiSetProperty(KUI_LOCUS,x,0);
  3532. #endif /* KUI */
  3533.     }
  3534. #endif /* OS2 */
  3535. }
  3536.  
  3537. VOID
  3538. setautolocus(x) int x; {
  3539.     autolocus = x;
  3540. #ifdef KUI
  3541.     KuiSetProperty(KUI_AUTO_LOCUS,x,0);
  3542. #endif /* KUI */
  3543. }
  3544. #endif /* LOCUS */
  3545.  
  3546. int
  3547. settypopts() {                /* Set TYPE option defaults */
  3548.     int xp = -1;
  3549.     int c, getval;
  3550.     while (1) {
  3551.     if ((y = cmswi(typetab,ntypetab,"Switch","",xxstring)) < 0) {
  3552.         if (y == -3)
  3553.           break;
  3554.         else
  3555.           return(y);
  3556.     }
  3557.     c = cmgbrk();
  3558.     if ((getval = (c == ':' || c == '=')) && !(cmgkwflgs() & CM_ARG)) {
  3559.         printf("?This switch does not take an argument\n");
  3560.         return(-9);
  3561.     }
  3562.     switch (y) {
  3563.       case TYP_NOP: xp = 0; break;
  3564.       case TYP_PAG: xp = 1; break;
  3565.       case TYP_WID:
  3566.         if (getval)
  3567.           if ((x = cmnum("Column at which to truncate",
  3568.                  ckitoa(cmd_cols),10,&y,xxstring)) < 0)
  3569.         return(x);
  3570.         typ_wid = y;
  3571.         break;
  3572.  
  3573.           default:
  3574.         printf("?Sorry, this option can not be set\n");
  3575.         return(-9);
  3576.     }
  3577.     }
  3578.     if ((x = cmcfm()) < 0)        /* Get confirmation */
  3579.       return(x);
  3580.     if (xp > -1) typ_page = xp;        /* Confirmed, save defaults */
  3581.     return(success = 1);
  3582. }
  3583.  
  3584. /* Forward declarations of functions local to this module */
  3585.  
  3586. #ifdef UNIX
  3587. _PROTOTYP (int douchmod, ( void ) );
  3588. #endif /* UNIX */
  3589. #ifdef CKPURGE
  3590. _PROTOTYP (int dopurge,  ( void ) );
  3591. #endif /* CKPURGE */
  3592. #ifndef NOSPL
  3593. _PROTOTYP (int doundef,  ( int  ) );
  3594. _PROTOTYP (int doask,    ( int  ) );
  3595. _PROTOTYP (int dodef,    ( int  ) );
  3596. _PROTOTYP (int doelse,   ( void ) );
  3597. _PROTOTYP (int dofor,    ( void ) );
  3598. #endif /* NOSPL  */
  3599. #ifndef NODIAL
  3600. _PROTOTYP (int dodial,   ( int  ) );
  3601. #endif /* NODIAL */
  3602. _PROTOTYP (int dodel,    ( void ) );
  3603. _PROTOTYP (int dopaus,   ( int  ) );
  3604. #ifndef NOPUSH
  3605. #ifdef TCPSOCKET
  3606. _PROTOTYP (int doping,   ( void ) );
  3607. _PROTOTYP (int doftp,    ( void ) );
  3608. #endif /* TCPSOCKET */
  3609. #endif /* NOPUSH */
  3610. #ifndef NORENAME
  3611. #ifndef NOFRILLS
  3612. _PROTOTYP (int dorenam,  ( void ) );
  3613. #endif /* NOFRILLS */
  3614. #endif /* NORENAME */
  3615. #ifdef ZCOPY
  3616. _PROTOTYP (int docopy,   ( void ) );
  3617. #endif /* ZCOPY */
  3618. #ifdef NT
  3619. _PROTOTYP (int dolink,   ( void ));
  3620. #endif /* NT */
  3621. #ifdef CK_REXX
  3622. _PROTOTYP (int dorexx,   ( void ) );
  3623. #endif /* CK_REXX */
  3624.  
  3625. #ifdef TNCODE
  3626. static struct keytab telcmd[] = {
  3627.     { "abort", TN_ABORT, CM_INV },    /* Emotionally toned - don't show */
  3628.     { "ao",    TN_AO,    0 },
  3629.     { "ayt",   TN_AYT,   0 },
  3630.     { "break", BREAK,    0 },
  3631.     { "cancel",TN_ABORT, 0 },
  3632.     { "dmark", TN_DM,    0 },
  3633.     { "do",    DO,       0 },
  3634.     { "dont",  DONT,     0 },
  3635.     { "ec",    TN_EC,    0 },
  3636.     { "el",    TN_EL,    0 },
  3637.     { "eof",   TN_EOF,   0 },
  3638.     { "eor",   TN_EOR,   0 },
  3639. #ifdef CK_KERBEROS
  3640. #ifdef KRB5
  3641. #define TN_FWD 1
  3642.     { "forward", TN_FWD, CM_INV },
  3643. #endif /* KRB5 */
  3644. #endif /* CK_KERBEROS */
  3645.     { "ga",    TN_GA,    0 },
  3646.     { "ip",    TN_IP,    0 },
  3647.     { "nop",   TN_NOP,   0 },
  3648.     { "sak",   TN_SAK,   CM_INV },
  3649.     { "sb",    SB,       0 },
  3650.     { "se",    SE,       0 },
  3651.     { "susp",  TN_SUSP,  0 },
  3652.     { "will",  WILL,     0 },
  3653.     { "wont",  WONT,     0 }
  3654. };
  3655. static int ntelcmd = (sizeof(telcmd) / sizeof(struct keytab));
  3656.  
  3657. static struct keytab tnopts[] = {
  3658. #ifdef CK_AUTHENTICATION
  3659.     { "auth",   TELOPT_AUTHENTICATION,   0 },
  3660. #else
  3661.     { "auth",   TELOPT_AUTHENTICATION,   CM_INV },
  3662. #endif /* CK_AUTHENTICATION */
  3663.     { "binary", TELOPT_BINARY, 0 },
  3664. #ifdef TN_COMPORT
  3665.     { "c",      TELOPT_COMPORT, CM_INV|CM_ABR},
  3666.     { "co",     TELOPT_COMPORT, CM_INV|CM_ABR},
  3667.     { "com",    TELOPT_COMPORT, CM_INV|CM_ABR},
  3668.     { "com-port-control", TELOPT_COMPORT, 0 },
  3669.     { "comport-control", TELOPT_COMPORT, CM_INV},
  3670. #else  /* TN_COMPORT */
  3671.     { "com-port-control", TELOPT_COMPORT, CM_INV },
  3672.     { "comport-control", TELOPT_COMPORT, CM_INV},
  3673. #endif /* TN_COMPORT */
  3674.     { "echo", TELOPT_ECHO, 0 },
  3675. #ifdef CK_ENCRYPTION
  3676.     { "encrypt", TELOPT_ENCRYPTION, 0 },
  3677. #else
  3678.     { "encrypt", TELOPT_ENCRYPTION, CM_INV },
  3679. #endif /* CK_ENCRYPTION */
  3680. #ifdef CK_FORWARD_X
  3681.     { "forward-x", TELOPT_FORWARD_X, 0 },
  3682. #else
  3683.     { "forward-x", TELOPT_FORWARD_X, CM_INV },
  3684. #endif /* CK_FORWARD_X */
  3685. #ifdef IKS_OPTION
  3686.     { "kermit", TELOPT_KERMIT, 0 },
  3687. #else
  3688.     { "kermit", TELOPT_KERMIT, CM_INV },
  3689. #endif /* IKS_OPTION */
  3690.     { "lflow",  TELOPT_LFLOW, CM_INV },
  3691.     { "logout", TELOPT_LOGOUT, CM_INV },
  3692. #ifdef CK_NAWS
  3693.     { "naws", TELOPT_NAWS, 0 },
  3694. #else
  3695.     { "naws", TELOPT_NAWS, CM_INV },
  3696. #endif /* CK_NAWS */
  3697. #ifdef CK_ENVIRONMENT
  3698.     { "new-environment", TELOPT_NEWENVIRON,  0 },
  3699. #else
  3700.     { "new-environment", TELOPT_NEWENVIRON,  CM_INV },
  3701. #endif /* CK_ENVIRONMENT */
  3702.     { "pragma-heartbeat",TELOPT_PRAGMA_HEARTBEAT,  CM_INV },
  3703.     { "pragma-logon",    TELOPT_PRAGMA_LOGON,  CM_INV },
  3704.     { "pragma-sspi",     TELOPT_SSPI_LOGON,  CM_INV },
  3705.     { "sak",   TELOPT_IBM_SAK, CM_INV },
  3706. #ifdef CK_SNDLOC
  3707.     { "send-location",   TELOPT_SNDLOC,  0 },
  3708. #else
  3709.     { "send-location",   TELOPT_SNDLOC,  CM_INV },
  3710. #endif /* CK_SNDLOC */
  3711.     { "sga", TELOPT_SGA, 0 },
  3712. #ifdef CK_SSL
  3713.     { "start-tls",       TELOPT_START_TLS,  0 },
  3714. #else
  3715.     { "start-tls",       TELOPT_START_TLS,  CM_INV },
  3716. #endif /* CK_SSL */
  3717.     { "ttype", TELOPT_TTYPE, 0 },
  3718. #ifdef CK_ENVIRONMENT
  3719.     { "xdisplay-location", TELOPT_XDISPLOC, 0 },
  3720. #else
  3721.     { "xdisplay-location", TELOPT_XDISPLOC, CM_INV },
  3722. #endif /* CK_ENVIRONMENT */
  3723.     { "", 0, 0 }
  3724. };
  3725. static int ntnopts = (sizeof(tnopts) / sizeof(struct keytab)) - 1;
  3726.  
  3727. static struct keytab tnsbopts[] = {
  3728. #ifdef CK_NAWS
  3729.     { "naws", TELOPT_NAWS, 0 },
  3730. #endif /* CK_NAWS */
  3731.     { "", 0, 0 }
  3732. };
  3733. static int ntnsbopts = (sizeof(tnsbopts) / sizeof(struct keytab)) - 1;
  3734. #endif /* TNCODE */
  3735.  
  3736. #ifdef TCPSOCKET
  3737. #ifndef NOPUSH
  3738. #ifdef SYSFTP
  3739. int
  3740. doftp() {                /* (External) FTP command */
  3741.     char *p, *f;            /* (See doxftp() for internal one) */
  3742.     int x;
  3743.  
  3744.     if (network)            /* If we have a current connection */
  3745.       ckstrncpy(line,ttname,LINBUFSIZ);    /* get the host name */
  3746.     else *line = '\0';            /* as default host */
  3747.     for (p = line; *p; p++)        /* Remove ":service" from end. */
  3748.       if (*p == ':') { *p = '\0'; break; }
  3749.     if ((x = cmtxt("IP host name or number", line, &s, xxstring)) < 0)
  3750.       return(x);
  3751.     if (nopush) {
  3752.         printf("?Sorry, FTP command disabled\n");
  3753.         return(success = 0);
  3754.     }
  3755. /* Construct FTP command */
  3756. #ifdef VMS
  3757. #ifdef MULTINET                /* TGV MultiNet */
  3758.     ckmakmsg(line,LINBUFSIZ,"multinet ftp ",s,NULL,NULL);
  3759. #else
  3760.     ckmakmsg(line,LINBUFSIZ,"ftp ",s,NULL,NULL);
  3761. #endif /* MULTINET */
  3762. #else                    /* Not VMS */
  3763. #ifdef OS2ORUNIX
  3764. #ifndef NOFTP
  3765.     f = ftpapp;
  3766.     if (!f) f = "";
  3767.     if (!f[0]) f = "ftp";
  3768.     ckmakmsg(line,LINBUFSIZ,f," ",s,NULL);
  3769. #ifdef OS2
  3770.     p = line + strlen(ftpapp);
  3771.     while (p != line) {
  3772.         if (*p == '/') *p = '\\';
  3773.         p--;
  3774.     }
  3775. #endif /* OS2 */
  3776. #else /* NOFTP */
  3777.     ckmakmsg(line,LINBUFSIZ,"ftp ",s,NULL,NULL);
  3778. #endif /* NOFTP */
  3779. #else /* OS2ORUNIX */
  3780.     ckmakmsg(line,LINBUFSIZ,"ftp ",s,NULL,NULL);
  3781. #endif /* OS2ORUNIX */
  3782. #endif /* VMS */
  3783.     conres();                /* Make console normal  */
  3784. #ifdef DEC_TCPIP
  3785.     printf("\n");            /* Prevent prompt-stomping */
  3786. #endif /* DEC_TCPIP */
  3787.     x = zshcmd(line);
  3788.     concb((char)escape);
  3789.     return(success = x);
  3790. }
  3791. #endif /* SYSFTP */
  3792.  
  3793. int
  3794. doping() {                /* PING command */
  3795.     char *p;                /* just runs ping program */
  3796.     int x;
  3797.  
  3798.     if (network)            /* If we have a current connection */
  3799.       ckstrncpy(line,ttname,LINBUFSIZ);    /* get the host name */
  3800.     else *line = '\0';            /* as default host to be pinged. */
  3801.     for (p = line; *p; p++)        /* Remove ":service" from end. */
  3802.       if (*p == ':') { *p = '\0'; break; }
  3803.     if ((x = cmtxt("IP host name or number", line, &s, xxstring)) < 0)
  3804.       return(x);
  3805.     if (nopush) {
  3806.         printf("?Sorry, PING command disabled\n");
  3807.         return(success = 0);
  3808.     }
  3809.  
  3810.     /* Construct PING command */
  3811. #ifdef VMS
  3812. #ifdef MULTINET                /* TGV MultiNet */
  3813.     ckmakmsg(line,LINBUFSIZ,"multinet ping ",s," /num=1",NULL);
  3814. #else
  3815.     ckmakmsg(line,LINBUFSIZ,"ping ",s," 56 1",NULL); /* Other VMS TCP/IP's */
  3816. #endif /* MULTINET */
  3817. #else                    /* Not VMS */
  3818.     ckmakmsg(line,LINBUFSIZ,"ping ",s,NULL,NULL);
  3819. #endif /* VMS */
  3820.     conres();                /* Make console normal  */
  3821. #ifdef DEC_TCPIP
  3822.     printf("\n");            /* Prevent prompt-stomping */
  3823. #endif /* DEC_TCPIP */
  3824.     x = zshcmd(line);
  3825.     concb((char)escape);
  3826.     return(success = x);
  3827. }
  3828. #endif /* NOPUSH */
  3829. #endif /* TCPSOCKET */
  3830.  
  3831. static VOID
  3832. doend(x) int x; {
  3833. #ifndef NOSPL
  3834.     /* Pop from all FOR/WHILE/XIF/SWITCH's */
  3835.     debug(F101,"doend maclvl 1","",maclvl);
  3836.     while ((maclvl > 0) &&
  3837.        (m_arg[maclvl-1][0]) &&
  3838.        (cmdstk[cmdlvl].src == CMD_MD) &&
  3839.        (!strncmp(m_arg[maclvl-1][0],"_xif",4) ||
  3840.         !strncmp(m_arg[maclvl-1][0],"_for",4) ||
  3841.         !strncmp(m_arg[maclvl-1][0],"_whi",4) ||
  3842.         !strncmp(m_arg[maclvl-1][0],"_swi",4))) {
  3843.     debug(F110,"END popping",m_arg[maclvl-1][0],0);
  3844.     dogta(XXPTA);            /* Put args back */
  3845.     popclvl();            /* Pop up two levels */
  3846.     popclvl();
  3847.     debug(F101,"doend maclvl 2","",maclvl);
  3848.     }
  3849.     if (maclvl > -1) {
  3850.     if (mrval[maclvl])        /* Free previous retval if any */
  3851.       free(mrval[maclvl]);
  3852.     mrval[maclvl] = malloc(16);    /* Room for up to 15 digits */
  3853.     if (mrval[maclvl])        /* Record current retval */
  3854.       ckmakmsg(mrval[maclvl],16,ckitoa(x),NULL,NULL,NULL);
  3855.     }
  3856. #endif /* NOSPL */
  3857.     popclvl();                /* Now pop out of macro or TAKE file */
  3858. #ifndef NOSPL
  3859. #ifdef DEBUG
  3860.     if (deblog) {
  3861.     debug(F101,"END maclvl 3","",maclvl);
  3862.     debug(F111,"END mrval[maclvl]",mrval[maclvl],maclvl);
  3863.     debug(F111,"END mrval[maclvl+1]",mrval[maclvl+1],maclvl+1);
  3864.     }
  3865. #endif /* DEBUG */
  3866. #endif /* NOSPL */
  3867. }
  3868.  
  3869. #ifdef CKROOT
  3870. int
  3871. dochroot() {
  3872.     if ((x = cmdir("Name of new root directory","",&s,xxstring)) < 0) {
  3873.     if (x == -3) {
  3874.         printf("?Directory name required\n");
  3875.         return(-9);
  3876.     }
  3877.     return(x);
  3878.     }
  3879.     ckstrncpy(line,s,LINBUFSIZ);
  3880.     s = line;
  3881.     if ((x = cmcfm()) < 0) return(x);
  3882.     s = brstrip(s);
  3883.     x = zsetroot(s);
  3884.     if (x < 0) {
  3885.     char * m = NULL;
  3886.     switch (x) {
  3887.       case -1:
  3888.       case -2: m = "Not a directory"; break;
  3889.       case -3: m = "Internal error"; break;
  3890.       case -4: m = "Access denied"; break;
  3891.       case -5: m = "Off limits"; break;
  3892.     }
  3893.     if (m) printf("%s: \"%s\"\n", m, s);
  3894.     return(m ? -9 : -2);
  3895.     } else {
  3896.     nopush = 1;
  3897.     return(success = 1);
  3898.     }
  3899. }
  3900. #endif /* CKROOT */
  3901.  
  3902. #ifndef NOXFER
  3903. static char * asnbuf = NULL;        /* As-name buffer pointer */
  3904.  
  3905. char sndxnam[] = { "_array_x_" };    /* (with replaceable x!) */
  3906.  
  3907. /*
  3908.   The new SEND command, replacing BSEND, CSEND, PSEND, etc etc.
  3909.   Call with cx = top-level keyword value.  Returns:
  3910.     < 0  On parse error.
  3911.     0    On other type of failure (e.g. requested operation not allowed).
  3912.     1    On success with sstate set to 's' so protocol will begin.
  3913. */
  3914.  
  3915. /*  D O X S E N D  --  Parse SEND and related commands with switches  */
  3916.  
  3917. int
  3918. doxsend(cx) int cx; {
  3919.     int c, i, n, wild, confirmed = 0;    /* Workers */
  3920.     int x, y;                /* of the world... */
  3921.     int getval = 0;            /* Whether to get switch value */
  3922.     extern char * snd_move;        /* Directory to move sent files to */
  3923.     extern char * snd_rename;        /* What to rename sent files to */
  3924.     extern char * filefile;        /* File containing filenames to send */
  3925.     extern int xfiletype;        /* Send only text (or binary) files */
  3926.     extern struct keytab pathtab[];    /* PATHNAMES option keywords */
  3927.     extern int npathtab;        /* How many of them */
  3928.     extern int recursive;        /* Recursive directory traversal */
  3929.     extern int rprintf;            /* REMOTE PRINT flag */
  3930.     extern int fdispla;            /* TRANSFER DISPLAY setting */
  3931.     extern int skipbup;            /* Skip backup files when sending */
  3932.     struct stringint pv[SND_MAX+1];    /* Temporary array for switch values */
  3933.     struct FDB sf, sw, fl, cm;        /* FDBs for each parse function */
  3934.     int mlist = 0;            /* Flag for MSEND or MMOVE */
  3935.     char * m;                /* For making help messages */
  3936.     extern struct keytab protos[];    /* File transfer protocols */
  3937.     extern int xfrxla, g_xfrxla, nprotos;
  3938.     extern char sndbefore[], sndafter[], *sndexcept[]; /* Selection criteria */
  3939.     extern char sndnbefore[], sndnafter[];
  3940.     extern CK_OFF_T sndsmaller, sndlarger, calibrate;
  3941. #ifndef NOSPL
  3942.     int range[2];            /* Array range */
  3943.     char ** ap = NULL;            /* Array pointer */
  3944.     int arrayx = -1;            /* Array index */
  3945. #endif /* NOSPL */
  3946.  
  3947. #ifdef NEWFTP
  3948.     if ((ftpget == 1) || ((ftpget == 2) && ftpisopen())) {
  3949.     if (cx == XXMAI) {
  3950.         printf("?Sorry, No MAIL with FTP\n");
  3951.         return(-9);
  3952.     }
  3953.     return(doftpput(cx,0));
  3954.     }
  3955. #endif /* NEWFTP */
  3956.  
  3957.     for (i = 0; i <= SND_MAX; i++) {    /* Initialize switch values */
  3958.     pv[i].sval = NULL;        /* to null pointers */
  3959.     pv[i].ival = -1;        /* and -1 int values */
  3960.     pv[i].wval = (CK_OFF_T)-1;    /* and -1 wide values */
  3961.     }
  3962. #ifndef NOSPL
  3963.     range[0] = -1;
  3964.     range[1] = -1;
  3965.     sndxin = -1;            /* Array index */
  3966. #endif /* NOSPL */
  3967.     sndarray = NULL;            /* Array pointer */
  3968.  
  3969. #ifdef UNIXOROSK
  3970.     g_matchdot = matchdot;        /* Match dot files */
  3971. #endif /* UNIXOROSK */
  3972.     g_recursive = recursive;        /* Recursive sending */
  3973.     recursive = 0;            /* Save global value, set local */
  3974.     debug(F101,"xsend entry fncnv","",fncnv);
  3975.  
  3976.     /* Preset switch values based on top-level command that called us */
  3977.  
  3978.     switch (cx) {
  3979.       case XXMSE:            /* MSEND */
  3980.     mlist = 1; break;
  3981.       case XXCSEN:            /* CSEND */
  3982.     pv[SND_CMD].ival = 1; break;
  3983.       case XXMMOVE:            /* MMOVE */
  3984.     mlist = 1;
  3985.       case XXMOVE:            /* MOVE */
  3986.     pv[SND_DEL].ival = 1; break;
  3987.       case XXRSEN:            /* RESEND */
  3988.     pv[SND_BIN].ival = 1;        /* Implies /BINARY */
  3989.     pv[SND_RES].ival = 1; break;
  3990.       case XXMAI:            /* MAIL */
  3991.     pv[SND_MAI].ival = 1; break;
  3992.     }
  3993.  
  3994.     /* Set up chained parse functions... */
  3995.  
  3996.     cmfdbi(&sw,                /* First FDB - command switches */
  3997.        _CMKEY,            /* fcode */
  3998.        "Filename, or switch",    /* hlpmsg */
  3999.        "",                /* default */
  4000.        "",                /* addtl string data */
  4001. #ifdef NOMSEND
  4002.        nsndtab,            /* addtl numeric data 1: tbl size */
  4003. #else
  4004.        mlist ? nmsndtab : nsndtab,    /* addtl numeric data 1: tbl size */
  4005. #endif /* NOMSEND */
  4006.        4,                /* addtl numeric data 2: 4 = cmswi */
  4007.        xxstring,            /* Processing function */
  4008. #ifdef NOMSEND
  4009.        sndtab,            /* Keyword table */
  4010. #else
  4011.        mlist ? msndtab : sndtab,
  4012. #endif /* NOMSEND */
  4013.        &sf                /* Pointer to next FDB */
  4014.        );
  4015.     cmfdbi(&sf,                /* 2nd FDB - file to send */
  4016.        _CMIFI,            /* fcode */
  4017.        "File(s) to send",        /* hlpmsg */
  4018.        "",                /* default */
  4019.        "",                /* addtl string data */
  4020.        nolinks,            /* addtl numeric data 1 */
  4021.        0,                /* addtl numeric data 2 */
  4022.        xxstring,
  4023.        NULL,
  4024.        mlist ? &cm : &fl
  4025.        );
  4026.     cmfdbi(&fl,                /* 3rd FDB - command to send from */
  4027.        _CMFLD,            /* fcode */
  4028.        "Command",            /* hlpmsg */
  4029.        "",                /* default */
  4030.        "",                /* addtl string data */
  4031.        0,                /* addtl numeric data 1 */
  4032.        0,                /* addtl numeric data 2 */
  4033.        xxstring,
  4034.        NULL,
  4035.        &cm
  4036.        );
  4037.     cmfdbi(&cm,                /* 4th FDB - Confirmation */
  4038.        _CMCFM,            /* fcode */
  4039.        "",                /* hlpmsg */
  4040.        "",                /* default */
  4041.        "",                /* addtl string data */
  4042.        0,                /* addtl numeric data 1 */
  4043.        0,                /* addtl numeric data 2 */
  4044.        NULL,
  4045.        NULL,
  4046.        NULL
  4047.        );
  4048.  
  4049.     while (1) {                /* Parse 0 or more switches */
  4050.     x = cmfdb(&sw);            /* Parse something */
  4051.     debug(F101,"xsend cmfdb","",x);
  4052.     if (x < 0)            /* Error */
  4053.       goto xsendx;            /* or reparse needed */
  4054.     if (cmresult.fcode != _CMKEY)    /* Break out if not a switch */
  4055.       break;
  4056. /*
  4057.   They gave a switch, but let's see how they terminated it.
  4058.   If they ended it with : or =, then we must parse a value.
  4059.   If they ended it with anything else, then we must NOT parse a value.
  4060. */
  4061.     c = cmgbrk();            /* Get break character */
  4062.     getval = (c == ':' || c == '='); /* to see how they ended the switch */
  4063.     if (getval && !(cmresult.kflags & CM_ARG)) {
  4064.         printf("?This switch does not take arguments\n");
  4065.         x = -9;
  4066.         goto xsendx;
  4067.     }
  4068.     if (!getval && (cmgkwflgs() & CM_ARG)) {
  4069.         printf("?This switch requires an argument\n");
  4070.         x = -9;
  4071.         goto xsendx;
  4072.     }
  4073.     n = cmresult.nresult;        /* Numeric result = switch value */
  4074.     debug(F101,"xsend switch","",n);
  4075.  
  4076.     switch (n) {            /* Process the switch */
  4077.       case SND_CMD:            /* These take no args */
  4078.         if (nopush) {
  4079.         printf("?Sorry, system command access is disabled\n");
  4080.         x = -9;
  4081.         goto xsendx;
  4082.         }
  4083. #ifdef PIPESEND
  4084.         else if (sndfilter) {
  4085.         printf(
  4086. "?Sorry, no SEND /COMMAND or CSEND when SEND FILTER selected\n");
  4087.         x = -9;
  4088.         goto xsendx;
  4089.         }
  4090. #endif /* PIPESEND */
  4091.         sw.hlpmsg = "Command, or switch"; /* Change help message */
  4092.         pv[n].ival = 1;        /* Just set the flag */
  4093.         pv[SND_ARR].ival = 0;
  4094.         break;
  4095.  
  4096.       case SND_REC:            /* /RECURSIVE */
  4097.         recursive = 2;        /* Set the real variable */
  4098.         pv[SND_PTH].ival = PATH_REL; /* Give them relative pathnames */
  4099.         pv[n].ival = 1;        /* Just set the flag */
  4100.         break;
  4101.  
  4102.       case SND_RES:            /* /RECOVER (resend) */
  4103.         pv[SND_ARR].ival = 0;
  4104.         pv[SND_BIN].ival = 1;    /* Implies /BINARY */
  4105.       case SND_NOB:            /* /NOBACKUP */
  4106.       case SND_DEL:            /* /DELETE */
  4107.       case SND_SHH:            /* /QUIET */
  4108.         pv[n].ival = 1;        /* Just set the flag */
  4109.         break;
  4110.  
  4111. #ifdef UNIXOROSK
  4112. /* Like recursive, these are set immediately because they affect cmifi() */
  4113.       case SND_DOT:            /* /DOTFILES */
  4114.         matchdot = 1;
  4115.         break;
  4116.       case SND_NOD:            /* /NODOTFILES */
  4117.         matchdot = 0;
  4118.         break;
  4119. #endif /* UNIXOROSK */
  4120.  
  4121.       /* File transfer modes - each undoes the others */
  4122.  
  4123.       case SND_BIN:            /* Binary */
  4124.       case SND_TXT:            /* Text */
  4125.       case SND_IMG:            /* Image */
  4126.       case SND_LBL:            /* Labeled */
  4127.         pv[SND_BIN].ival = 0;
  4128.         pv[SND_TXT].ival = 0;
  4129.         pv[SND_IMG].ival = 0;
  4130.         pv[SND_LBL].ival = 0;
  4131.         pv[n].ival = 1;
  4132.         break;
  4133.  
  4134. #ifdef CKSYMLINK
  4135.       case SND_LNK:
  4136.       case SND_NLK:
  4137.         nolinks = (n == SND_NLK) ? 2 : 0;
  4138.         cmfdbi(&sf,            /* Redo cmifi() */
  4139.            _CMIFI,        /* fcode */
  4140.            "File(s) to send",    /* hlpmsg */
  4141.            "",            /* default */
  4142.            "",            /* addtl string data */
  4143.            nolinks,        /* addtl numeric data 1 */
  4144.            0,            /* addtl numeric data 2 */
  4145.            xxstring,
  4146.            NULL,
  4147.            mlist ? &cm : &fl
  4148.            );
  4149.         break;
  4150. #endif /* CKSYMLINK */
  4151.  
  4152.       case SND_EXC:            /* Excludes */
  4153.         if (!getval) break;
  4154.         if ((x = cmfld("Pattern","",&s,xxstring)) < 0) {
  4155.         if (x == -3) {
  4156.             printf("?Pattern required\n");
  4157.             x = -9;
  4158.         }
  4159.         goto xsendx;
  4160.         }
  4161.         if (pv[n].sval) free(pv[n].sval);
  4162.         y = strlen(s);
  4163.         if (y > 256) {
  4164.         printf("?Pattern too long - 256 max\n");
  4165.         x = -9;
  4166.         goto xsendx;
  4167.         }
  4168.         pv[n].sval = malloc(y+1);
  4169.         if (pv[n].sval) {
  4170.         strcpy(pv[n].sval,s);    /* safe */
  4171.         pv[n].ival = 1;
  4172.         }
  4173.         break;
  4174.  
  4175.       case SND_MOV:            /* MOVE after */
  4176.       case SND_REN:            /* RENAME after */
  4177.         if (!getval) break;
  4178.         if ((x = cmfld(n == SND_MOV ?
  4179.        "device and/or directory for source file after sending" :
  4180.        "new name for source file after sending",
  4181.                "",
  4182.                &s,
  4183.                n == SND_MOV ? xxstring : NULL
  4184.                )) < 0) {
  4185.         if (x == -3) {
  4186.             printf("%s\n", n == SND_MOV ?
  4187.                "?Destination required" :
  4188.                "?New name required"
  4189.                );
  4190.             x = -9;
  4191.         }
  4192.         goto xsendx;
  4193.         }
  4194.         if (pv[n].sval) free(pv[n].sval);
  4195.         s = brstrip(s);
  4196.         y = strlen(s);
  4197.         if (y > 0) {
  4198.         pv[n].sval = malloc(y+1);
  4199.         if (pv[n].sval) {
  4200.             strcpy(pv[n].sval,s); /* safe */
  4201.             pv[n].ival = 1;
  4202.         }
  4203.         }
  4204.         break;
  4205.  
  4206.       case SND_SMA:            /* Smaller / larger than */
  4207.       case SND_LAR: {
  4208.           CK_OFF_T w;
  4209.           if (!getval) break;
  4210.           if ((x = cmnumw("Size in bytes","0",10,&w,xxstring)) < 0)
  4211.         goto xsendx;
  4212.           pv[n].wval = w;
  4213.           break;
  4214.       }
  4215.       case SND_AFT:            /* Send /AFTER:date-time */
  4216.       case SND_BEF:            /* Send /BEFORE:date-time */
  4217.       case SND_NAF:            /* Send /NOT-AFTER:date-time */
  4218.       case SND_NBE:            /* Send /NOT-BEFORE:date-time */
  4219.         if (!getval) break;
  4220.         if ((x = cmdate("File date-time","",&s,0,xxstring)) < 0) {
  4221.         if (x == -3) {
  4222.             printf("?Date-time required\n");
  4223.             x = -9;
  4224.         }
  4225.         goto xsendx;
  4226.         }
  4227.         if (pv[n].sval) free(pv[n].sval);
  4228.         pv[n].sval = malloc((int)strlen(s)+1);
  4229.         if (pv[n].sval) {
  4230.         strcpy(pv[n].sval,s);    /* safe */
  4231.         pv[n].ival = 1;
  4232.         }
  4233.         break;
  4234.  
  4235.       case SND_MAI:            /* Send as mail (= MAIL) */
  4236. #ifdef IKSD
  4237.         if (inserver && !ENABLED(en_mai)) {
  4238.         printf("?Sorry, sending files as mail is disabled\n");
  4239.         return(-9);
  4240.         }
  4241. #endif /* IKSD */
  4242.         pv[n].ival = 1;
  4243.         if (!getval) break;
  4244.         if ((x = cmfld("e-mail address","",&s,xxstring)) < 0) {
  4245.         if (x == -3) {
  4246.             printf("?address required\n");
  4247.             x = -9;
  4248.         }
  4249.         goto xsendx;
  4250.         }
  4251.         s = brstrip(s);
  4252.         if (pv[n].sval) free(pv[n].sval);
  4253.         pv[n].sval = malloc((int)strlen(s)+1);
  4254.         if (pv[n].sval)
  4255.           strcpy(pv[n].sval,s);    /* safe */
  4256.         break;
  4257.  
  4258.       case SND_PRI:            /* Send to be printed (REMOTE PRINT) */
  4259. #ifdef IKSD
  4260.         if (inserver && !ENABLED(en_mai)) {
  4261.         printf("?Sorry, sending files for printing is disabled\n");
  4262.         return(-9);
  4263.         }
  4264. #endif /* IKSD */
  4265.         pv[n].ival = 1;
  4266.         if (!getval) break;
  4267.         if ((x = cmfld("Print options","",&s,xxstring)) < 0)
  4268.           if (x != -3) goto xsendx;
  4269.         s = brstrip(s);
  4270.         if (pv[n].sval) free(pv[n].sval);
  4271.         pv[n].sval = malloc((int)strlen(s)+1);
  4272.         if (pv[n].sval)
  4273.           strcpy(pv[n].sval,s);    /* safe */
  4274.         break;
  4275.  
  4276.       case SND_ASN:            /* As-name */
  4277.         debug(F101,"xsend /as-name getval","",getval);
  4278.         if (!getval) break;
  4279.         if ((x = cmfld("Name to send under","",&s,NULL)) < 0) {
  4280.         if (x == -3) {
  4281.             printf("?name required\n");
  4282.             x = -9;
  4283.         }
  4284.         goto xsendx;
  4285.         }
  4286.         s = brstrip(s);
  4287.         if ((y = strlen(s)) > 0) {
  4288.         if (pv[n].sval) free(pv[n].sval);
  4289.         pv[n].sval = malloc(y+1);
  4290.         if (pv[n].sval) {
  4291.             strcpy(pv[n].sval,s); /* safe */
  4292.             pv[n].ival = 1;
  4293.         }
  4294.         }
  4295.         break;
  4296.  
  4297.       case SND_STA: {        /* Starting position (= PSEND) */
  4298.           CK_OFF_T w;
  4299.           if (!getval) break;
  4300.           if ((x = cmnumw("0-based position","0",10,&w,xxstring)) < 0)
  4301.         goto xsendx;
  4302.           pv[n].wval = w;
  4303.           break;
  4304.       }
  4305.       case SND_PRO:            /* Protocol to use */
  4306.         if (!getval) break;
  4307.         if ((x = cmkey(protos,nprotos,"File-transfer protocol","",
  4308.                xxstring)) < 0) {
  4309.         if (x == -3) {
  4310.             printf("?name of protocol required\n");
  4311.             x = -9;
  4312.         }
  4313.         goto xsendx;
  4314.         }
  4315.         pv[n].ival = x;
  4316.         break;
  4317.  
  4318. #ifdef PIPESEND
  4319.       case SND_FLT:            /* Filter */
  4320.         debug(F101,"xsend /filter getval","",getval);
  4321.         if (!getval) break;
  4322.         if ((x = cmfld("Filter program to send through","",&s,NULL)) < 0) {
  4323.         if (x == -3)
  4324.           s = "";
  4325.         else
  4326.           goto xsendx;
  4327.         }
  4328.         if (*s) s = brstrip(s);
  4329.         y = strlen(s);
  4330.         for (x = 0; x < y; x++) {    /* Make sure they included "\v(...)" */
  4331.         if (s[x] != '\\') continue;
  4332.         if (s[x+1] == 'v') break;
  4333.         }
  4334.         if (x == y) {
  4335.         printf(
  4336.         "?Filter must contain a replacement variable for filename.\n"
  4337.                );
  4338.         x = -9;
  4339.         goto xsendx;
  4340.         }
  4341.         pv[n].ival = 1;
  4342.         if (pv[n].sval) {
  4343.         free(pv[n].sval);
  4344.         pv[n].sval = NULL;
  4345.         }
  4346.         if ((y = strlen(s)) > 0) {
  4347.         if ((pv[n].sval = malloc(y+1)))
  4348.           strcpy(pv[n].sval,s);    /* safe */
  4349.         }
  4350.         break;
  4351. #endif /* PIPESEND */
  4352.  
  4353.       case SND_PTH:            /* Pathnames */
  4354.         if (!getval) {
  4355.         pv[n].ival = PATH_REL;
  4356.         break;
  4357.         }
  4358.         if ((x = cmkey(pathtab,npathtab,"","absolute",xxstring)) < 0)
  4359.           goto xsendx;
  4360.         pv[n].ival = x;
  4361.         break;
  4362.  
  4363.       case SND_NAM:            /* Filenames */
  4364.         if (!getval) break;
  4365.         if ((x = cmkey(fntab,nfntab,"","converted",xxstring)) < 0)
  4366.           goto xsendx;
  4367.         debug(F101,"xsend /filenames","",x);
  4368.         pv[n].ival = x;
  4369.         break;
  4370.  
  4371. #ifdef CALIBRATE
  4372.           case SND_CAL: {        /* /CALIBRATE */
  4373.           CK_OFF_T w;
  4374.           if (getval) {
  4375.           if ((x = cmnumw("number of Kbytes to send",
  4376.                   "1024",10,&w,xxstring)) < 0)
  4377.             goto xsendx;
  4378.           } else
  4379.         w = (CK_OFF_T)1024;
  4380.           pv[n].wval = w;
  4381.           pv[SND_ARR].ival = 0;
  4382.           break;
  4383.       }
  4384. #endif /* CALIBRATE */
  4385.  
  4386.       case SND_FIL:            /* Name of file containing filnames */
  4387.         if (!getval) break;
  4388.         if ((x = cmifi("Name of file containing list of filenames",
  4389.                    "",&s,&y,xxstring)) < 0) {
  4390.         if (x == -3) {
  4391.             printf("?Filename required\n");
  4392.             x = -9;
  4393.         }
  4394.         goto xsendx;
  4395.         } else if (y) {
  4396.         printf("?Wildcards not allowed\n");
  4397.         x = -9;
  4398.         goto xsendx;
  4399.         }
  4400.         if (pv[n].sval)
  4401.           free(pv[n].sval);
  4402.         if (s) if (*s) {
  4403.         if ((pv[n].sval = malloc((int)strlen(s)+1))) {
  4404.             strcpy(pv[n].sval,s);
  4405.             pv[n].ival = 1;
  4406.             pv[SND_ARR].ival = 0;
  4407.         }
  4408.         }
  4409.         break;
  4410.  
  4411. #ifndef NOSPL
  4412.       case SND_ARR:            /* SEND /ARRAY: */
  4413.         if (!getval) break;
  4414.         ap = NULL;
  4415.         if ((x = cmfld("Array name (a single letter will do)",
  4416.                "",
  4417.                &s,
  4418.                NULL
  4419.                )) < 0) {
  4420.         if (x == -3)
  4421.           break;
  4422.         else
  4423.           return(x);
  4424.         }
  4425.         if ((x = arraybounds(s,&(range[0]),&(range[1]))) < 0) {
  4426.         printf("?Bad array: %s\n",s);
  4427.         return(-9);
  4428.         }
  4429.         if (!(ap = a_ptr[x])) {
  4430.         printf("?No such array: %s\n",s);
  4431.         return(-9);
  4432.         }
  4433.         pv[n].ival = 1;
  4434.         pv[SND_CMD].ival = 0;    /* Undo any conflicting ones... */
  4435.         pv[SND_RES].ival = 0;
  4436.         pv[SND_CAL].ival = 0;
  4437.         pv[SND_FIL].ival = 0;
  4438.         arrayx = x;
  4439.         break;
  4440. #endif /* NOSPL */
  4441.  
  4442.       case SND_XPA:            /* /TRANSPARENT */
  4443.         pv[n].ival = 1;
  4444.         break;
  4445.  
  4446.       case SND_TYP:            /* Only files of given type */
  4447.         if (!getval) break;
  4448.         if ((x = cmkey(txtbin,3,"","all",xxstring)) < 0)
  4449.           goto xsendx;
  4450.         pv[n].ival = (x == 2) ? -1 : x;
  4451.         break;
  4452.  
  4453.       default:
  4454.         printf("?Unexpected switch value - %d\n",cmresult.nresult);
  4455.         x = -9;
  4456.         goto xsendx;
  4457.     }
  4458.     }
  4459.     debug(F101,"xsend cmresult fcode","",cmresult.fcode);
  4460.  
  4461. #ifdef COMMENT
  4462.     /* List switch parsing results in debug log */
  4463.     for (i = 0; i <= SND_MAX; i++) {
  4464.     ckmakmsg(line,LINBUFSIZ,"xsend switch ",ckitoa(i),NULL,NULL);
  4465.     debug(F111,line, pv[i].sval, pv[i].ival);
  4466.     }
  4467. #endif /* COMMENT */
  4468.  
  4469. /* Now we have all switches, plus maybe a filename or command, or nothing */
  4470.  
  4471. #ifdef PIPESEND
  4472.     if (protocol != PROTO_K && pv[SND_CMD].ival > 0) {
  4473.     printf("?Sorry, %s works only with Kermit protocol\n",
  4474.            (cx == XXCSEN) ? "CSEND" : "SEND /COMMAND");
  4475.     x = -9;
  4476.     goto xsendx;
  4477.     }
  4478.     if (pv[SND_RES].ival > 0 ||    /* /RECOVER */
  4479.     pv[SND_STA].wval > 0) {    /* or /STARTING */
  4480.     if (sndfilter || pv[SND_FLT].ival > 0) {
  4481.         printf("?Sorry, no /RECOVER or /START if SEND FILTER selected\n");
  4482.         x = -9;
  4483.         goto xsendx;
  4484.     }
  4485.     }
  4486. #endif /* PIPESEND */
  4487.  
  4488.     cmarg = "";
  4489.     cmarg2 = "";
  4490.     line[0] = NUL;
  4491.     s = line;
  4492.     wild = 0;
  4493.  
  4494.     switch (cmresult.fcode) {        /* How did we get out of switch loop */
  4495.       case _CMIFI:            /* Input filename */
  4496.     ckstrncpy(line,cmresult.sresult,LINBUFSIZ); /* Name */
  4497.     if (pv[SND_ARR].ival > 0)
  4498.       cmarg2 = line;
  4499.     else
  4500.       wild = cmresult.nresult;    /* Wild flag */
  4501.     if (!recursive && !wild)
  4502.       nolinks = 0;
  4503.     break;
  4504.       case _CMFLD:            /* Field */
  4505.     /* Only allowed with /COMMAND and /ARRAY */
  4506.     if (pv[SND_CMD].ival < 1 && pv[SND_ARR].ival < 1) {
  4507. #ifdef CKROOT
  4508.         if (ckrooterr)
  4509.           printf("?Off limits: %s\n",cmresult.sresult);
  4510.         else
  4511. #endif /* CKROOT */
  4512.           printf("?%s - \"%s\"\n",
  4513.            iswild(cmresult.sresult) ?
  4514.            "No files match" : "File not found",
  4515.            cmresult.sresult
  4516.            );
  4517.         x = -9;
  4518.         goto xsendx;
  4519.     }
  4520.     ckstrncpy(line,cmresult.sresult,LINBUFSIZ);
  4521.     if (pv[SND_ARR].ival > 0)
  4522.       cmarg2 = line;
  4523.     break;
  4524.       case _CMCFM:            /* Confirmation */
  4525.     /* s = ""; */
  4526.     confirmed = 1;
  4527.     break;
  4528.       default:
  4529.     printf("?Unexpected function code: %d\n",cmresult.fcode);
  4530.     x = -9;
  4531.     goto xsendx;
  4532.     }
  4533.     debug(F110,"xsend string",s,0);
  4534.     debug(F101,"xsend confirmed","",confirmed);
  4535.  
  4536.     /* Save and change protocol and transfer mode */
  4537.     /* Global values are restored in main parse loop */
  4538.  
  4539.     g_proto = protocol;            /* Save current global protocol */
  4540.     g_urpsiz = urpsiz;
  4541.     g_spsizf = spsizf;
  4542.     g_spsiz = spsiz;
  4543.     g_spsizr = spsizr;
  4544.     g_spmax = spmax;
  4545.     g_wslotr = wslotr;
  4546.     g_prefixing = prefixing;
  4547.     g_fncact = fncact;
  4548.     g_fncnv = fncnv;
  4549.     g_fnspath = fnspath;
  4550.     g_fnrpath = fnrpath;
  4551.     g_xfrxla = xfrxla;
  4552.  
  4553.     if (pv[SND_PRO].ival > -1) {    /* Change according to switch */
  4554.     protocol = pv[SND_PRO].ival;
  4555.         if (ptab[protocol].rpktlen > -1) /* copied from initproto() */
  4556.             urpsiz = ptab[protocol].rpktlen;
  4557.         if (ptab[protocol].spktflg > -1)
  4558.             spsizf = ptab[protocol].spktflg;
  4559.         if (ptab[protocol].spktlen > -1) {
  4560.             spsiz = ptab[protocol].spktlen;
  4561.             if (spsizf)
  4562.           spsizr = spmax = spsiz;
  4563.         }
  4564.         if (ptab[protocol].winsize > -1)
  4565.             wslotr = ptab[protocol].winsize;
  4566.         if (ptab[protocol].prefix > -1)
  4567.             prefixing = ptab[protocol].prefix;
  4568.         if (ptab[protocol].fnca > -1)
  4569.             fncact  = ptab[protocol].fnca;
  4570.         if (ptab[protocol].fncn > -1)
  4571.             fncnv   = ptab[protocol].fncn;
  4572.         if (ptab[protocol].fnsp > -1)
  4573.             fnspath = ptab[protocol].fnsp;
  4574.         if (ptab[protocol].fnrp > -1)
  4575.             fnrpath = ptab[protocol].fnrp;
  4576.     }
  4577.     debug(F101,"xsend protocol","",protocol);
  4578.  
  4579.     if (pv[SND_NOB].ival > -1) {    /* /NOBACKUP (skip backup file) */
  4580.     g_skipbup = skipbup;
  4581.     skipbup = 1;
  4582.     }
  4583.     if (pv[SND_REC].ival > 0)        /* /RECURSIVE */
  4584.       recursive = 2;
  4585.  
  4586.     if (pv[SND_TYP].ival > -1) {    /* /TYPE */
  4587.     xfiletype = pv[SND_TYP].ival;
  4588.     if (xfiletype == 2)
  4589.       xfiletype = -1;
  4590.     }
  4591.     g_binary = binary;            /* Save global transfer mode */
  4592. #ifdef PATTERNS
  4593.     g_patterns = patterns;        /* Save FILE PATTERNS setting */
  4594. #endif /* PATTERNS */
  4595.     if (pv[SND_BIN].ival > 0) {        /* Change according to switch */
  4596.     /* If they said /BINARY they mean /BINARY */
  4597.     patterns = 0;            /* So no pattern-based switching */
  4598.     g_xfermode = xfermode;        /* or automatic transfer mode */
  4599.     xfermode = XMODE_M;
  4600.     binary = XYFT_B;
  4601.     debug(F101,"doxsend /BINARY xfermode","",xfermode);
  4602.     } else if (pv[SND_TXT].ival > 0) {    /* Ditto for /TEXT */
  4603.     patterns = 0;
  4604.     g_xfermode = xfermode;
  4605.     xfermode = XMODE_M;
  4606.     binary = XYFT_T;
  4607.     debug(F101,"doxsend /TEXT xfermode","",xfermode);
  4608.     } else if (pv[SND_IMG].ival > 0) {
  4609. #ifdef VMS
  4610.     binary = XYFT_I;
  4611. #else
  4612.     binary = XYFT_B;
  4613. #endif /* VMS */
  4614.     }
  4615. #ifdef CK_LABELED
  4616.     else if (pv[SND_LBL].ival > 0) {
  4617.     binary = XYFT_L;
  4618.     }
  4619. #endif /* CK_LABELED */
  4620.     debug(F101,"xsend binary","",binary);
  4621.  
  4622.     if (pv[SND_XPA].ival > 0)        /* /TRANSPARENT */
  4623.       xfrxla = 0;            /* Don't translate character sets */
  4624.  
  4625.     /* Check for legal combinations of switches, filenames, etc */
  4626.  
  4627. #ifdef PIPESEND
  4628.     if (pv[SND_CMD].ival > 0) {    /* COMMAND - strip any braces */
  4629.     debug(F110,"SEND /COMMAND before stripping",s,0);
  4630.     s = brstrip(s);
  4631.     debug(F110,"SEND /COMMAND after stripping",s,0);
  4632.     if (!*s) {
  4633.         printf("?Sorry, a command to send from is required\n");
  4634.         x = -9;
  4635.         goto xsendx;
  4636.     }
  4637.     cmarg = s;
  4638.     }
  4639. #endif /* PIPESEND */
  4640.  
  4641. /* Set up /MOVE and /RENAME */
  4642.  
  4643.     if (pv[SND_DEL].ival > 0 &&
  4644.     (pv[SND_MOV].ival > 0 || pv[SND_REN].ival > 0)) {
  4645.     printf("?Sorry, /DELETE conflicts with /MOVE or /RENAME\n");
  4646.     x = -9;
  4647.     goto xsendx;
  4648.     }
  4649. #ifdef CK_TMPDIR
  4650.     if (pv[SND_MOV].ival > 0) {
  4651.     int len;
  4652.     char * p = pv[SND_MOV].sval;
  4653. #ifdef CK_LOGIN
  4654.     if (isguest) {
  4655.         printf("?Sorry, /MOVE-TO not available to guests\n");
  4656.         x = -9;
  4657.         goto xsendx;
  4658.     }
  4659. #endif /* CK_LOGIN */
  4660.     len = strlen(p);
  4661.     if (!isdir(p)) {        /* Check directory */
  4662. #ifdef CK_MKDIR
  4663.         char * s = NULL;
  4664.         s = (char *)malloc(len + 4);
  4665.         if (s) {
  4666.         strcpy(s,p);        /* safe */
  4667. #ifdef datageneral
  4668.         if (s[len-1] != ':') { s[len++] = ':'; s[len] = NUL; }
  4669. #else
  4670.         if (s[len-1] != '/') { s[len++] = '/'; s[len] = NUL; }
  4671. #endif /* datageneral */
  4672.         s[len++] = 'X';
  4673.         s[len] = NUL;
  4674.         x = zmkdir(s);
  4675.         free(s);
  4676.         if (x < 0) {
  4677.             printf("?Can't create \"%s\"\n",p);
  4678.             x = -9;
  4679.             goto xsendx;
  4680.         }
  4681.         }
  4682. #else
  4683.         printf("?Directory \"%s\" not found\n",p);
  4684.         x = -9;
  4685.         goto xsendx;
  4686. #endif /* CK_MKDIR */
  4687.     }
  4688.         zfnqfp(p,LINBUFSIZ,tmpbuf);
  4689.     makestr(&snd_move,tmpbuf);
  4690.     }
  4691. #endif /* CK_TMPDIR */
  4692.  
  4693.     if (pv[SND_REN].ival > 0) {        /* /RENAME */
  4694.     char * p = pv[SND_REN].sval;
  4695. #ifdef CK_LOGIN
  4696.     if (isguest) {
  4697.         printf("?Sorry, /RENAME-TO not available to guests\n");
  4698.         x = -9;
  4699.         goto xsendx;
  4700.     }
  4701. #endif /* CK_LOGIN */
  4702.     if (!p) p = "";
  4703.     if (!*p) {
  4704.         printf("?New name required for /RENAME\n");
  4705.         x = -9;
  4706.         goto xsendx;
  4707.     }
  4708.     p = brstrip(p);
  4709. #ifndef NOSPL
  4710.     /* If name given is wild, rename string must contain variables */
  4711.     if (wild) {
  4712.         char * s = tmpbuf;
  4713.         x = TMPBUFSIZ;
  4714.         zzstring(p,&s,&x);
  4715.         if (!strcmp(tmpbuf,p)) {
  4716.         printf(
  4717.     "?/RENAME for file group must contain variables such as \\v(filename)\n"
  4718.                );
  4719.         x = -9;
  4720.         goto xsendx;
  4721.         }
  4722.     }
  4723. #endif /* NOSPL */
  4724.     makestr(&snd_rename,p);
  4725.     }
  4726.  
  4727. /* Handle /RECOVER and /START */
  4728.  
  4729. #ifdef CK_RESEND
  4730.     if (pv[SND_RES].ival > 0 && binary != XYFT_B && !filepeek
  4731. #ifdef PATTERNS
  4732.     && !patterns
  4733. #else
  4734. #ifdef VMS
  4735. /* VMS sets text/binary automatically later when it opens the file */
  4736.     && 0
  4737. #endif /* VMS */
  4738. #endif /* PATTERNS */
  4739.     ) {
  4740.     printf("?Sorry, /BINARY required\n");
  4741.     x = -9;
  4742.     goto xsendx;
  4743.     }
  4744.     if (pv[SND_STA].wval > 0) {        /* /START */
  4745.     if (wild) {
  4746.         printf("?Sorry, wildcards not permitted with /START\n");
  4747.         x = -9;
  4748.         goto xsendx;
  4749.     }
  4750.     if (sizeof(int) < 4) {
  4751.         printf("?Sorry, this command needs at least 32-bit integers\n");
  4752.         x = -9;
  4753.         goto xsendx;
  4754.     }
  4755. #ifdef CK_XYZ
  4756.     if (protocol != PROTO_K) {
  4757.         printf("?Sorry, SEND /START works only with Kermit protocol\n");
  4758.         x = -9;
  4759.         goto xsendx;
  4760.     }
  4761. #endif /* CK_XYZ */
  4762.     }
  4763. #ifdef CK_XYZ
  4764.     if (pv[SND_RES].ival > 0) {
  4765.     if (protocol != PROTO_K && protocol != PROTO_Z) {
  4766.         printf(
  4767.     "Sorry, /RECOVER is possible only with Kermit or ZMODEM protocol\n"
  4768.            );
  4769.         x = -9;
  4770.         goto xsendx;
  4771.     }
  4772.     }
  4773. #endif /* CK_XYZ */
  4774. #endif /* CK_RESEND */
  4775.  
  4776.     if (protocol == PROTO_K) {
  4777.     if ((pv[SND_MAI].ival > 0 ||    /* MAIL */
  4778.          pv[SND_PRI].ival > 0 ||    /* PRINT */
  4779.          pv[SND_RES].ival > 0    /* RESEND */
  4780.          ) &&
  4781.         (!atdiso || !atcapr)) {    /* Disposition attribute off? */
  4782.         printf("?Sorry, ATTRIBUTE DISPOSITION must be ON\n");
  4783.         x = -9;
  4784.         goto xsendx;
  4785.     }
  4786.     }
  4787.  
  4788. #ifdef CK_XYZ
  4789.     if (wild && (protocol == PROTO_X || protocol == PROTO_XC)) {
  4790.     printf(
  4791. "Sorry, you can only send one file at a time with XMODEM protocol\n"
  4792.            );
  4793.     x = -9;
  4794.     goto xsendx;
  4795.     }
  4796. #endif /* CK_XYZ */
  4797.  
  4798.     if (!confirmed) {            /* CR not typed yet, get more fields */
  4799.     char *m;
  4800.     if (mlist) {            /* MSEND or MMOVE */
  4801.         nfils = 0;            /* We already have the first one */
  4802. #ifndef NOMSEND
  4803.         msfiles[nfils++] = line;    /* Store pointer */
  4804.         lp = line + (int)strlen(line) + 1; /* Point past it */
  4805.         debug(F111,"xsend msend",msfiles[nfils-1],nfils-1);
  4806.         while (1) {            /* Get more filenames */
  4807.         char *p;
  4808.         if ((x = cmifi("Names of files to send, separated by spaces",
  4809.                    "", &s,&y,xxstring)) < 0) {
  4810.             if (x != -3)
  4811.               goto xsendx;
  4812.             if ((x = cmcfm()) < 0)
  4813.               goto xsendx;
  4814.             break;
  4815.         }
  4816.         msfiles[nfils++] = lp;    /* Got one, count it, point to it, */
  4817.         p = lp;            /* remember pointer, */
  4818.         while ((*lp++ = *s++))    /* and copy it into buffer */
  4819.           if (lp > (line + LINBUFSIZ)) { /* Avoid memory leak */
  4820.               printf("?MSEND list too long\n");
  4821.               line[0] = NUL;
  4822.               x = -9;
  4823.               goto xsendx;
  4824.           }
  4825.         debug(F111,"xsend msend",msfiles[nfils-1],nfils-1);
  4826.         if (nfils == 1) fspec[0] = NUL; /* Take care of \v(filespec) */
  4827. #ifdef ZFNQFP
  4828.         zfnqfp(p,TMPBUFSIZ,tmpbuf);
  4829.         p = tmpbuf;
  4830. #endif /* ZFNQFP */
  4831.         if (((int)strlen(fspec) + (int)strlen(p) + 1) < fspeclen) {
  4832.             strcat(fspec,p);    /* safe */
  4833.             strcat(fspec," ");    /* safe */
  4834.         } else
  4835. #ifdef COMMENT
  4836.           printf("WARNING - \\v(filespec) buffer overflow\n");
  4837. #else
  4838.           debug(F101,"doxsend filespec buffer overflow","",0);
  4839. #endif /* COMMENT */
  4840.         }
  4841. #endif /* NOMSEND */
  4842.     } else {            /* Regular SEND */
  4843.         char *p; int y;
  4844.         nfils = -1;
  4845.         if (pv[SND_MAI].ival > 0)
  4846.           m = (pv[SND_MAI].sval) ?
  4847.         "e-mail address (optional)" :
  4848.           "e-mail address (required)";
  4849.         else if (pv[SND_PRI].ival > 0)
  4850.           m = "printer options (optional)";
  4851.         else if (wild)
  4852.           m =
  4853. "\nOptional as-name template containing replacement variables \
  4854. like \\v(filename)";
  4855.         else
  4856.           m = "Optional name to send it with";
  4857.         if ((x = cmtxt(m,"",&p,NULL)) < 0)
  4858.           goto xsendx;
  4859.         if (!p) p = "";
  4860.         if (*p) {            /* If some text was given... */
  4861.         p = brstrip(p);        /* Replace /AS-NAME: value if any */
  4862.         if ((y = strlen(p)) > 0) {
  4863.                     if (pv[SND_MAI].ival > 0) {
  4864.                         makestr(&pv[SND_MAI].sval, p);
  4865.                     } else {
  4866.             if (pv[SND_ASN].sval) free(pv[SND_ASN].sval);
  4867.             pv[SND_ASN].sval = malloc(y+1);
  4868.             if (pv[SND_ASN].sval) {
  4869.                 strcpy(pv[SND_ASN].sval,p);    /* safe */
  4870.                 pv[SND_ASN].ival = 1;
  4871.             }
  4872.             }
  4873.         }
  4874.         }
  4875.     }
  4876.     }
  4877.     /* Set cmarg2 from as-name, however we got it. */
  4878.  
  4879.     if (pv[SND_ASN].ival > 0 && pv[SND_ASN].sval && !*cmarg2) {
  4880.     int x;
  4881.     x = strlen(line);
  4882.     ckstrncpy(line+x+2,pv[SND_ASN].sval,LINBUFSIZ-x-1);
  4883.     cmarg2 = line+x+2;
  4884.     debug(F110,"doxsend cmarg2",cmarg2,0);
  4885.     }
  4886.  
  4887. #ifndef NOFRILLS
  4888.     if ((pv[SND_MAI].ival > 0) && (pv[SND_PRI].ival > 0)) {
  4889.     printf("Sorry, /MAIL and /PRINT are conflicting options\n");
  4890.     x = -9;
  4891.     goto xsendx;
  4892.     }
  4893.     n = 0;                /* /MAIL or /PRINT? */
  4894.     if (pv[SND_MAI].ival > 0)
  4895.       n = SND_MAI;
  4896.     else if (pv[SND_PRI].ival > 0)
  4897.       n = SND_PRI;
  4898.     if (n) {                /* Yes... */
  4899. #ifdef DEBUG
  4900.     char * p;
  4901.     if (n == SND_MAI)
  4902.       p = "/MAIL";
  4903.     else
  4904.       p = "/PRINT";
  4905.     debug(F111,"xsend",p,n);
  4906. #endif /* DEBUG */
  4907. #ifdef CK_XYZ
  4908.     if (protocol != PROTO_K) {
  4909.         printf("Sorry, %s available only with Kermit protocol\n",
  4910.            (n == SND_MAI) ? "/MAIL" : "/PRINT"
  4911.            );
  4912.         x = -9;
  4913.         goto xsendx;
  4914.     }
  4915. #endif /* CK_XYZ */
  4916.     debug(F101,"xsend print/mail wild","",wild);
  4917.     *optbuf = NUL;            /* Wipe out any old options */
  4918.     s = pv[n].sval;            /* mail address or print switch val */
  4919.     if (!s) s = "";
  4920.     debug(F110,"doxsend mail address or printer options",s,0);
  4921.     if (n == SND_MAI && !*s) {
  4922.         printf("?E-mail address required\n");
  4923.         x = -9;
  4924.         goto xsendx;
  4925.     } else if ((int)strlen(s) > 94) { /* Ensure legal size */
  4926.         printf("?%s too long\n",
  4927.            (n == SND_MAI) ?
  4928.            "E-mail address" :
  4929.            "Print option string"
  4930.            );
  4931.         x = -9;
  4932.         goto xsendx;
  4933.     }
  4934.     ckstrncpy(optbuf,s,OPTBUFLEN);    /* OK, copy to option buffer */
  4935.     cmarg = line;            /* File to send */
  4936.     if (n == SND_MAI) {
  4937.         debug(F110,"xsend mailing",cmarg,0);
  4938.         debug(F110,"xsend address:",optbuf,0);
  4939.         rmailf = 1;
  4940.     } else {
  4941.         debug(F110,"xsend printing",cmarg,0);
  4942.         debug(F110,"xsend options",optbuf,0);
  4943.         rprintf = 1;
  4944.     }
  4945.     }
  4946. #endif /* NOFRILLS */
  4947.  
  4948. #ifdef CALIBRATE
  4949.     if (pv[SND_CAL].wval > 0) {        /* Handle /CALIBRATE */
  4950.     if (confirmed) {
  4951.         calibrate = pv[SND_CAL].wval * (CK_OFF_T)1024;
  4952.         sndsrc = -9;
  4953.         nfils = 1;
  4954.         wild = 0;
  4955. #ifndef NOMSEND
  4956.         addlist = 0;
  4957. #endif /* NOMSEND */
  4958.         ckstrncpy(line,"CALIBRATION",LINBUFSIZ);
  4959.         s = cmarg = line;
  4960.         if (!cmarg2) cmarg2 = "";
  4961.         debug(F110,"doxsend cmarg2 calibrate",cmarg2,0);
  4962.     } else if (line[0]) {
  4963.         calibrate = 0;
  4964.         pv[SND_CAL].ival = 0;
  4965.         pv[SND_CAL].wval = 0;
  4966.     }
  4967.     }
  4968. #endif /* CALIBRATE */
  4969.  
  4970.     if (pv[SND_FIL].ival > 0) {
  4971.     if (confirmed && !calibrate) {
  4972.         if (zopeni(ZMFILE,pv[SND_FIL].sval) < 1) {
  4973.         debug(F110,"xsend can't open",pv[SND_FIL].sval,0);
  4974.         printf("?Failure to open %s\n",filefile);
  4975.         x = -9;
  4976.         goto xsendx;
  4977.         }
  4978.         makestr(&filefile,pv[SND_FIL].sval); /* Open, remember name */
  4979.         debug(F110,"xsend opened",filefile,0);
  4980.         wild = 1;
  4981.     }
  4982.     }
  4983.  
  4984.     /* SEND alone... */
  4985.  
  4986. #ifndef NOSPL
  4987.     if (confirmed && pv[SND_ARR].ival > 0) {
  4988.     if (!*cmarg2) {
  4989.         sndxnam[7] = (char)((arrayx == 1) ? 64 : arrayx + ARRAYBASE);
  4990.         cmarg2 = sndxnam;
  4991.     }
  4992.     cmarg = "";
  4993.     goto sendend;
  4994.     }
  4995. #endif /* NOSPL */
  4996.  
  4997.     if (confirmed && !line[0] && !filefile && !calibrate) {
  4998. #ifndef NOMSEND
  4999.     if (filehead) {            /* OK if we have a SEND-LIST */
  5000.         nfils = filesinlist;
  5001.         sndsrc = nfils;        /* Like MSEND */
  5002.         addlist = 1;        /* But using a different list... */
  5003.         filenext = filehead;
  5004.         goto sendend;
  5005.     }
  5006. #endif /* NOMSEND */
  5007.     printf("?Filename required but not given\n");
  5008.     x = -9;
  5009.     goto xsendx;
  5010.     }
  5011.  
  5012.     /* Not send-list or array */
  5013.  
  5014. #ifndef NOMSEND
  5015.     addlist = 0;            /* Don't use SEND-LIST. */
  5016.     filenext = NULL;
  5017. #endif /* NOMSEND */
  5018.  
  5019.     if (mlist) {            /* MSEND or MMOVE */
  5020. #ifndef NOMSEND
  5021.     cmlist = msfiles;        /* List of files to send */
  5022.     sndsrc = nfils;
  5023.     cmarg2 = "";
  5024.     sendstart = (CK_OFF_T)0;
  5025. #endif /* NOMSEND */
  5026. #ifdef PIPESEND
  5027.     pipesend = 0;
  5028. #endif /* PIPESEND */
  5029.     } else if (filefile) {        /* File contains list of filenames */
  5030.     s = "";
  5031.     cmarg = "";
  5032.     cmarg2 = "";
  5033.     line[0] = NUL;
  5034.     nfils = 1;
  5035.     sndsrc = 1;
  5036.  
  5037.     } else if (!calibrate && pv[SND_ARR].ival < 1 && pv[SND_CMD].ival < 1) {
  5038.  
  5039.     nfils = sndsrc = -1;    /* Not MSEND, MMOVE, /LIST, or /ARRAY */
  5040.     if (                /* or /COMMAND */
  5041.  
  5042. #ifndef NOFRILLS
  5043.         !rmailf && !rprintf        /* Not MAIL or PRINT */
  5044. #else
  5045.         1
  5046. #endif /* NOFRILLS */
  5047.         ) {
  5048.         CK_OFF_T y = (CK_OFF_T)1;
  5049.         if (!wild)
  5050.           y = zchki(s);
  5051.         if (y < (CK_OFF_T)0) {
  5052.         printf("?Read access denied - \"%s\"\n", s);
  5053.         x = -9;
  5054.         goto xsendx;
  5055.         }
  5056.         if (s != line)        /* We might already have done this. */
  5057.           ckstrncpy(line,s,LINBUFSIZ); /* Copy of string just parsed. */
  5058.         else
  5059.           debug(F110,"doxsend line=s",line,0);
  5060.         cmarg = line;        /* File to send */
  5061.     }
  5062.     zfnqfp(cmarg,fspeclen,fspec);
  5063.     }
  5064.     if (!mlist) {            /* For all but MSEND... */
  5065. #ifdef PIPESEND
  5066.     if (pv[SND_CMD].ival > 0)    /* /COMMAND sets pipesend flag */
  5067.       pipesend = 1;
  5068.     debug(F101,"xsend /COMMAND pipesend","",pipesend);
  5069.     if (pipesend && filefile) {
  5070.         printf("?Invalid switch combination\n");
  5071.         x = -9;
  5072.         goto xsendx;
  5073.     }
  5074. #endif /* PIPESEND */
  5075.  
  5076. #ifndef NOSPL
  5077.     /* If as-name given and filespec is wild, as-name must contain variables */
  5078.     debug(F111,"doxsend cmarg2 wild",cmarg2,wild);
  5079.     if (wild && *cmarg2) {
  5080.         char * s = tmpbuf;
  5081.         x = TMPBUFSIZ;
  5082.         zzstring(cmarg2,&s,&x);
  5083.         if (!strcmp(tmpbuf,cmarg2)) {
  5084.         printf(
  5085.     "?As-name for file group must contain variables such as \\v(filename)\n"
  5086.                );
  5087.         x = -9;
  5088.         goto xsendx;
  5089.         }
  5090.     }
  5091. #endif /* NOSPL */
  5092.  
  5093.     /* Strip braces from as-name */
  5094.     debug(F110,"xsend cmarg2 before stripping",cmarg2,0);
  5095.     cmarg2 = brstrip(cmarg2);
  5096.     debug(F110,"xsend filename",cmarg,0);
  5097.     debug(F110,"xsend as-name",cmarg2,0);
  5098.  
  5099.     /* Copy as-name to a safe place */
  5100.  
  5101.     if (asnbuf) {
  5102.         free(asnbuf);
  5103.         asnbuf = NULL;
  5104.     }
  5105.     if ((y = strlen(cmarg2)) > 0) {
  5106.         asnbuf = (char *) malloc(y + 1);
  5107.         if (asnbuf) {
  5108.         strcpy(asnbuf,cmarg2);    /* safe */
  5109.         cmarg2 = asnbuf;
  5110.         } else cmarg2 = "";
  5111.     }
  5112.  
  5113. #ifdef CK_RESEND
  5114.     debug(F111,"xsend pv[SND_STA].ival","",pv[SND_STA].ival);
  5115.     if (pv[SND_STA].wval > (CK_OFF_T)-1) { /* /START position */
  5116.         if (wild) {
  5117.         printf("?/STARTING-AT may not be used with multiple files.\n");
  5118.         x = -9;
  5119.         goto xsendx;
  5120.         } else
  5121.           sendstart = pv[SND_STA].wval;
  5122.     } else
  5123.       sendstart = (CK_OFF_T)0;
  5124.     debug(F101,"xsend /STARTING","",sendstart);
  5125. #endif /* CK_RESEND */
  5126.     }
  5127.  
  5128. sendend:                /* Common successful exit */
  5129.     moving = 0;
  5130.     if (pv[SND_SHH].ival > 0) {        /* SEND /QUIET... */
  5131.     g_displa = fdispla;
  5132.     fdispla = 0;
  5133.     debug(F101,"xsend display","",fdispla);
  5134.     }
  5135.  
  5136. #ifndef NOSPL                /* SEND /ARRAY... */
  5137.     if (pv[SND_ARR].ival > 0) {
  5138.     if (!ap) { x = -2; goto xsendx; } /* (shouldn't happen) */
  5139.     if (range[0] == -1)        /* If low end of range not specified */
  5140.       range[0] = 1;            /* default to 1 */
  5141.     if (range[1] == -1)        /* If high not specified */
  5142.       range[1] = a_dim[arrayx];    /* default to size of array */
  5143.     if ((range[0] < 0) ||        /* Check range */
  5144.         (range[0] > a_dim[arrayx]) ||
  5145.         (range[1] < range[0]) ||
  5146.         (range[1] > a_dim[arrayx])) {
  5147.         printf("?Bad array range - [%d:%d]\n",range[0],range[1]);
  5148.         x = -9;
  5149.         goto xsendx;
  5150.     }
  5151.     sndarray = ap;            /* Array pointer */
  5152.     sndxin = arrayx;        /* Array index */
  5153.     sndxlo = range[0];        /* Array range */
  5154.     sndxhi = range[1];
  5155.     sndxnam[7] = (char)((sndxin == 1) ? 64 : sndxin + ARRAYBASE);
  5156.  
  5157. #ifdef COMMENT
  5158.     printf("SENDING FROM ARRAY: &%c[]...\n", /* debugging */
  5159.            (sndxin == 1) ? 64 : sndxin + ARRAYBASE);
  5160.     printf("Lo=%d\nHi=%d\n", sndxlo, sndxhi);
  5161.     printf("cmarg=[%s]\ncmarg2=[%s]\n", cmarg, cmarg2);
  5162.     while ((x = agnbyte()) > -1) {
  5163.         putchar((char)x);
  5164.     }
  5165.     return(1);
  5166. #endif /* COMMENT */
  5167.     }
  5168. #endif /* NOSPL */
  5169.  
  5170.     if (pv[SND_ARR].ival < 1) {        /* File selection & disposition... */
  5171.  
  5172.     if (pv[SND_DEL].ival > 0)    /* /DELETE was specified */
  5173.       moving = 1;
  5174.     debug(F101,"xsend /DELETE","",moving);
  5175.     if (pv[SND_AFT].ival > 0)    /* Copy SEND criteria */
  5176.       ckstrncpy(sndafter,pv[SND_AFT].sval,19);
  5177.     if (pv[SND_BEF].ival > 0)
  5178.       ckstrncpy(sndbefore,pv[SND_BEF].sval,19);
  5179.     if (pv[SND_NAF].ival > 0)
  5180.       ckstrncpy(sndnafter,pv[SND_NAF].sval,19);
  5181.     if (pv[SND_NBE].ival > 0)
  5182.       ckstrncpy(sndnbefore,pv[SND_NBE].sval,19);
  5183.     if (pv[SND_EXC].ival > 0)
  5184.       makelist(pv[SND_EXC].sval,sndexcept,NSNDEXCEPT);
  5185.     if (pv[SND_SMA].wval > (CK_OFF_T)-1)
  5186.       sndsmaller = pv[SND_SMA].wval;
  5187.     if (pv[SND_LAR].wval > (CK_OFF_T)-1)
  5188.       sndlarger = pv[SND_LAR].wval;
  5189.     if (pv[SND_NAM].ival > -1) {
  5190.         g_fncnv = fncnv;        /* Save global value */
  5191.         fncnv = pv[SND_NAM].ival;
  5192.         debug(F101,"xsend fncnv","",fncnv);
  5193.     }
  5194.     if (pv[SND_PTH].ival > -1) {
  5195.         g_spath = fnspath;        /* Save global values */
  5196.         fnspath = pv[SND_PTH].ival;
  5197. #ifndef NZLTOR
  5198.         if (fnspath != PATH_OFF) {
  5199.         g_fncnv = fncnv;    /* Bad bad... */
  5200.         fncnv = XYFN_C;
  5201.         }
  5202. #endif /* NZLTOR */
  5203.         debug(F101,"xsend fnspath","",fnspath);
  5204.         debug(F101,"xsend fncnv","",fncnv);
  5205.     }
  5206.     }
  5207.  
  5208. #ifdef PIPESEND
  5209.     if (pv[SND_FLT].ival > 0) {
  5210.     makestr(&sndfilter,pv[SND_FLT].sval);
  5211.     debug(F110,"xsend /FILTER", sndfilter, 0);
  5212.     }
  5213. #endif /* PIPESEND */
  5214.  
  5215. #ifdef CK_APC
  5216. /* MOVE not allowed in APCs */
  5217.     if (moving &&
  5218.     (apcactive == APC_LOCAL || apcactive == APC_REMOTE)
  5219.     && !(apcstatus & APC_UNCH))
  5220.       return(success = 0);
  5221. #endif /* CK_APC */
  5222. #ifdef IKS_OPTION
  5223.     if (
  5224. #ifdef CK_XYZ
  5225.         protocol == PROTO_K &&
  5226. #endif /* CK_XYZ */
  5227.         !iks_wait(KERMIT_REQ_START,1)) {
  5228.         printf("?A Kermit Server is not available to process this command.\n");
  5229.         printf("?Start a RECEIVE command to complement this command.\n");
  5230.     }
  5231. #endif /* IKS_OPTION */
  5232.  
  5233. #ifdef IKSD
  5234. #ifdef CK_LOGIN
  5235.     if (moving && inserver && isguest) {
  5236.         printf("?File deletion not allowed for guests.\n");
  5237.     return(-9);
  5238.     }
  5239. #endif /* CK_LOGIN */
  5240. #endif /* IKSD */
  5241.  
  5242.     sstate = 's';            /* Set start state to SEND */
  5243.     sndcmd = 1;
  5244. #ifdef CK_RESEND
  5245.     if (pv[SND_RES].ival > 0)        /* Send sendmode appropriately */
  5246.       sendmode = SM_RESEND;
  5247.     else if (pv[SND_STA].ival > 0)
  5248.       sendmode = SM_PSEND;
  5249.     else
  5250. #endif /* CK_RESEND */
  5251.     if (mlist)
  5252.       sendmode = SM_MSEND;
  5253.     else
  5254.       sendmode = SM_SEND;
  5255. #ifdef MAC
  5256.     what = W_SEND;
  5257.     scrcreate();
  5258. #endif /* MAC */
  5259.     if (local && pv[SND_SHH].ival != 0) { /* If in local mode, */
  5260.     displa = 1;            /* turn on file transfer display */
  5261.     }
  5262.     x = 0;
  5263.  
  5264.   xsendx:                /* Common exit, including failure */
  5265.     debug(F101,"doxsend sndsrc","",sndsrc);
  5266.     for (i = 0; i <= SND_MAX; i++) {    /* Free malloc'd memory */
  5267.     if (pv[i].sval)
  5268.       free(pv[i].sval);
  5269.     }
  5270.     return(x);
  5271. }
  5272. #endif /* NOXFER */
  5273.  
  5274. #ifndef NOLOCAL
  5275. /*  D O X C O N N  --  CONNECT command parsing with switches */
  5276.  
  5277. #ifdef XLIMITS
  5278. #define XLIMORTRIGGER
  5279. #else
  5280. #ifdef CK_TRIGGER
  5281. #define XLIMORTRIGGER
  5282. #endif /* CK_TRIGGER */
  5283. #endif /*  XLIMITS */
  5284.  
  5285. #ifdef CKTIDLE
  5286. int tt_idlelimit = 0;            /* Terminal idle limit */
  5287. int tt_idleact = IDLE_RET;        /* Terminal idle action */
  5288. #endif /* CKTIDLE */
  5289.  
  5290. #ifdef OS2                /* K95 only: */
  5291. extern int
  5292.   tt_idlesnd_tmo;            /*   Idle interval */
  5293. int tt_timelimit = 0;            /*   Time limit, 0 = none */
  5294. extern char *                /* Parse results - strings: */
  5295.   tt_idlesnd_str;            /*   Idle string */
  5296. #endif /* OS2 */
  5297.  
  5298. #ifdef CK_TRIGGER
  5299. extern char *tt_trigger[];
  5300. extern CHAR *tt_trmatch[];
  5301. extern char *triggerval;
  5302. static char *g_tt_trigger[TRIGGERS];
  5303. #endif /* CK_TRIGGER */
  5304.  
  5305. #ifdef OS2
  5306. static int g_tt_idlesnd_tmo, g_tt_timelimit; /* For saving and restoring */
  5307. static int g_tt_idlelimit, g_tt_saved = 0;
  5308. static char * g_tt_idlesnd_str;        /* global settings */
  5309. #endif /* OS2 */
  5310.  
  5311. static struct stringint pv[CONN_MAX+1];
  5312.  
  5313. VOID
  5314. resconn() {
  5315.     int i;
  5316.  
  5317. #ifdef OS2
  5318.     if ( g_tt_saved ) {
  5319.         tt_idlelimit   = g_tt_idlelimit;
  5320.         tt_idlesnd_tmo = g_tt_idlesnd_tmo;
  5321.         tt_timelimit   = g_tt_timelimit;
  5322.         tt_idlesnd_str = g_tt_idlesnd_str;
  5323.         g_tt_saved = 0;
  5324.     }
  5325. #endif /* OS2 */
  5326.  
  5327. #ifdef CK_TRIGGER
  5328.     for (i = 0; i < TRIGGERS; i++)
  5329.       tt_trigger[i] = g_tt_trigger[i];
  5330. #endif /* CK_TRIGGER */
  5331.  
  5332.     for (i = 0; i <= CONN_MAX; i++) {    /* Free malloc'd memory */
  5333.     if (pv[i].sval)
  5334.       free(pv[i].sval);
  5335.         pv[i].sval = NULL;
  5336.     }
  5337. }
  5338.  
  5339. int
  5340. doxconn(cx) int cx; {
  5341.     int c, i, n;            /* Workers */
  5342.     int x, y;
  5343.     int getval = 0;            /* Whether to get switch value */
  5344.     int async = 0;                      /* Make an async connect */
  5345.     struct FDB sw, cm;            /* FDBs for each parse function */
  5346.     extern FILE * tfile[];
  5347.     extern char * macp[];
  5348.  
  5349. #ifdef OS2
  5350.     g_tt_idlesnd_tmo = tt_idlesnd_tmo;    /* Save global settings */
  5351.     g_tt_timelimit   = tt_timelimit;
  5352.     g_tt_idlelimit   = tt_idlelimit;
  5353.     g_tt_idlesnd_str = tt_idlesnd_str;
  5354.     g_tt_saved = 1;
  5355. #endif /* OS2 */
  5356.  
  5357. #ifdef CK_TRIGGER
  5358.     if (!tt_trigger[0]) {        /* First initialization */
  5359.     for (i = 1; i < TRIGGERS; i++)
  5360.       tt_trigger[i] = NULL;
  5361.     }
  5362.     for (i = 0; i < TRIGGERS; i++)
  5363.       g_tt_trigger[i] = tt_trigger[i];
  5364.     if (triggerval) {
  5365.     free(triggerval);
  5366.     triggerval = NULL;
  5367.     }
  5368. #endif /* CK_TRIGGER */
  5369.  
  5370.     for (i = 0; i <= CONN_MAX; i++) {    /* Initialize switch values */
  5371.     pv[i].sval = NULL;        /* to null pointers */
  5372.     pv[i].ival = -1;        /* and -1 int values */
  5373.     pv[i].wval = (CK_OFF_T)-1;
  5374.     }
  5375.     if (cx == XXCQ)            /* CQ == CONNECT /QUIETLY */
  5376.       pv[CONN_NV].ival = 1;
  5377.  
  5378.     /* Set up chained parse functions... */
  5379.  
  5380.     cmfdbi(&sw,                /* First FDB - command switches */
  5381.        _CMKEY,            /* fcode */
  5382.        "Switch",            /* hlpmsg */
  5383.        "",                /* default */
  5384.        "",                /* addtl string data */
  5385.        nconntab,            /* addtl numeric data 1: tbl size */
  5386.        4,                /* addtl numeric data 2: 4 = cmswi */
  5387.        xxstring,            /* Processing function */
  5388.        conntab,            /* Keyword table */
  5389.        &cm                /* Pointer to next FDB */
  5390.        );
  5391.     cmfdbi(&cm,                /* 2nd FDB - Confirmation */
  5392.        _CMCFM,            /* fcode */
  5393.        "",                /* hlpmsg */
  5394.        "",                /* default */
  5395.        "",                /* addtl string data */
  5396.        0,                /* addtl numeric data 1 */
  5397.        0,                /* addtl numeric data 2 */
  5398.        NULL,
  5399.        NULL,
  5400.        NULL
  5401.        );
  5402.  
  5403.     while (1) {                /* Parse 0 or more switches */
  5404.     x = cmfdb(&sw);            /* Parse switch or confirmation */
  5405.     debug(F101,"doxconn cmfdb","",x);
  5406.     if (x < 0) {            /* Error */
  5407.         if (x == -9 || x == -2)
  5408.           printf("?No switches match - \"%s\"\n",atmbuf);
  5409.         goto xconnx;        /* or reparse needed */
  5410.     }
  5411.     if (cmresult.fcode != _CMKEY)    /* Break out if not a switch */
  5412.       break;
  5413.     c = cmgbrk();            /* Get break character */
  5414.     getval = (c == ':' || c == '='); /* to see how they ended the switch */
  5415.     if (getval && !(cmresult.kflags & CM_ARG)) {
  5416.         printf("?This switch does not take arguments\n");
  5417.         x = -9;
  5418.         goto xconnx;
  5419.     }
  5420.     if (!getval && (cmgkwflgs() & CM_ARG)) {
  5421.         printf("?This switch requires an argument\n");
  5422.         return(-9);
  5423.     }
  5424.     n = cmresult.nresult;        /* Numeric result = switch value */
  5425.     debug(F101,"doxconn switch","",n);
  5426.  
  5427.     switch (n) {            /* Process the switch */
  5428. #ifdef OS2
  5429.       case CONN_AS:            /* Asynchronous */
  5430.             pv[CONN_AS].ival = 1;
  5431.             pv[CONN_SY].ival = 0;
  5432.             break;
  5433.           case CONN_SY:                 /* Synchronous */
  5434.             pv[CONN_SY].ival = 1;
  5435.             pv[CONN_AS].ival = 0;
  5436.             break;
  5437. #endif /* OS2 */
  5438.       case CONN_NV:            /* Non-verbal */
  5439.         pv[n].ival = 1;
  5440.         break;
  5441. #ifdef XLIMITS
  5442.       case CONN_II:            /* Idle-interval */
  5443.       case CONN_IL:            /* Idle-limit */
  5444.       case CONN_TL:            /* Time-limit */
  5445.         if (!getval) break;
  5446.         if ((x = cmnum("Seconds","0",10,&y,xxstring)) < 0)
  5447.           goto xconnx;
  5448.         pv[n].ival = y;
  5449.         break;
  5450.       case CONN_IS:            /* Idle-string */
  5451. #endif /* XLIMITS */
  5452. #ifdef CK_TRIGGER
  5453.       case CONN_TS:            /* Trigger-string */
  5454. #endif /* CK_TRIGGER */
  5455. #ifdef XLIMORTRIGGER
  5456.         if (!getval) break;
  5457.         if ((x = cmfld("String (enclose in braces if it contains spaces)",
  5458.                "",&s,xxstring)) < 0) {
  5459.         if (x == -3) {
  5460.             printf("?String required\n");
  5461.             x = -9;
  5462.         }
  5463.         goto xconnx;
  5464.         }
  5465.         if (n != CONN_TS)
  5466.           s = brstrip(s);
  5467.         if ((y = strlen(s)) > 0) {
  5468.         if (pv[n].sval) free(pv[n].sval);
  5469.         pv[n].sval = malloc(y+1);
  5470.         if (pv[n].sval) {
  5471.             strcpy(pv[n].sval,s); /* safe */
  5472.             pv[n].ival = 1;
  5473.         }
  5474.         }
  5475.         break;
  5476. #endif /* XLIMORTRIGGER */
  5477.       default:
  5478.         printf("?Unexpected switch value - %d\n",cmresult.nresult);
  5479.         x = -9;
  5480.         goto xconnx;
  5481.     }
  5482.     }
  5483.     debug(F101,"doxconn cmresult.fcode","",cmresult.fcode);
  5484.     if (cmresult.fcode != _CMCFM) {
  5485.     printf("?Unexpected function code: %d\n",cmresult.fcode);
  5486.     x = -9;
  5487.     goto xconnx;
  5488.     }
  5489.  
  5490.     /* Command was confirmed so we can pre-pop command level. */
  5491.     /* This is so CONNECT module won't think we're executing a script */
  5492.     /* if CONNECT was the final command in the script. */
  5493.  
  5494.     if (cmdlvl > 0)
  5495.       prepop();
  5496.  
  5497. #ifdef OS2                /* Make results available globally */
  5498.     if (pv[CONN_IL].ival > -1)        /* Idle limit */
  5499.       tt_idlelimit = pv[CONN_IL].ival;
  5500.     if (pv[CONN_II].ival > -1)        /* Idle limit */
  5501.       tt_idlesnd_tmo = pv[CONN_II].ival;
  5502.     if (pv[CONN_IS].sval)        /* Idle string */
  5503.       if (tt_idlesnd_str = (char *)malloc((int)strlen(pv[CONN_IS].sval)+1))
  5504.     strcpy(tt_idlesnd_str,pv[CONN_IS].sval); /* safe */
  5505.     if (pv[CONN_TL].ival > -1)        /* Session limit */
  5506.       tt_timelimit = pv[CONN_TL].ival;
  5507.     async = (pv[CONN_AS].ival > 0 ||
  5508.              pv[CONN_SY].ival <= 0 && cmdlvl == 0) ? 1 : 0;
  5509. #endif /* OS2 */
  5510.  
  5511. #ifdef CK_TRIGGER
  5512.     if (pv[CONN_TS].sval)        /* Trigger strings */
  5513.       makelist(pv[CONN_TS].sval,tt_trigger,TRIGGERS);
  5514.     for (i = 0; i < TRIGGERS; i++)    /* Trigger match pointers */
  5515.       tt_trmatch[i] = NULL;
  5516.     if (triggerval) {            /* Reset trigger value */
  5517.     free(triggerval);
  5518.     triggerval = NULL;
  5519.     }
  5520. #endif /* CK_TRIGGER */
  5521.  
  5522.     x = doconect((pv[CONN_NV].ival > 0) ? 1 : 0, async);
  5523.     {
  5524.     int xx;
  5525.     debug(F101,"doxconn doconect returns","",x);
  5526.     if ((xx = ttchk()) < 0) dologend();
  5527.     debug(F101,"doxconn ttchk returns","",xx);
  5528.     }
  5529.  
  5530. #ifdef CK_TRIGGER
  5531.     debug(F111,"doxconn doconect triggerval",triggerval,x);
  5532. #endif /* CK_TRIGGER */
  5533.  
  5534.   xconnx:
  5535.     /* Back from CONNECT -- Restore global settings */
  5536.  
  5537.     if (!async)
  5538.       resconn();
  5539.  
  5540.     success = (x > 0) ? 1 : 0;
  5541.     return(x);
  5542. }
  5543. #endif /* NOLOCAL */
  5544.  
  5545. #ifdef ADDCMD
  5546. /* cx == XXADD or XXREMV */
  5547. /* fc == ADD_BIN or ADD_TXT */
  5548. static int
  5549. doadd(cx,fc) int cx, fc; {
  5550. #ifdef PATTERNS
  5551.     char * tmp[FTPATTERNS];
  5552.     char **p = NULL;
  5553.     int i, j, k, n = 0, x = 0, last;
  5554.  
  5555. #endif /* PATTERNS */
  5556.     if (cx != XXADD && cx != XXREMV) {
  5557.     printf("?Unexpected function code: %d\n",cx);
  5558.     return(-9);
  5559.     }
  5560. #ifdef PATTERNS
  5561.     while (n < FTPATTERNS) {        /* Collect new patterns */
  5562.     tmp[n] = NULL;
  5563.     if ((x = cmfld("Pattern","",&s,xxstring)) < 0)
  5564.       break;
  5565.     ckstrncpy(line,s,LINBUFSIZ);
  5566.     s = brstrip(line);
  5567.     makestr(&(tmp[n++]),s);
  5568.     }
  5569.     if (x == -3)
  5570.       x = cmcfm();
  5571.     if (x < 0)
  5572.       goto xdoadd;
  5573.     p = (fc == ADD_BIN) ? binpatterns : txtpatterns; /* Which list */
  5574.     last = 0;
  5575.     for (i = 0; i < FTPATTERNS; i++) { /* Find last one in list */
  5576.     if (!p[i]) {
  5577.         last = i;
  5578.         break;
  5579.     }
  5580.     }
  5581.     if (cx == XXADD) {            /* Adding */
  5582.     if (last + n > FTPATTERNS) {    /* Check if too many */
  5583.         printf("?Too many patterns - %d is the maximum\n", FTPATTERNS);
  5584.         goto xdoadd;
  5585.     }
  5586.         for (i = 0; i < n; i++) {        /* Copy in the new ones. */
  5587.           for (j = 0, x = 0; x == 0 && j < last ; j++ )
  5588.             x = !ckstrcmp(tmp[i],p[j],-1,filecase); /* match */
  5589.           if (x == 0)
  5590.             makestr(&(p[last++]),tmp[i]);
  5591.         }
  5592.         makestr(&(p[last]),NULL);    /* Null-terminate the list */
  5593.         x = 1;
  5594.         goto xdoadd;                    /* Done */
  5595.     } else if (cx == XXREMV) {        /* Remove something(s) */
  5596.     int j, k;
  5597.     if (last == 0)                    /* List is empty */
  5598.       goto xdoadd;                    /* Nothing to remove */
  5599.     for (i = 0; i < n; i++) {            /* i = Patterns they typed */
  5600.         for (j = 0; j < last; j++) {        /* j = Patterns in list */
  5601.         /* Change this to ckstrcmp()... */
  5602.         if (filecase)
  5603.                   x = !ckstrcmp(tmp[i],p[j],-1,filecase); /* match */
  5604.         else
  5605.           x = ckstrcmp(tmp[i],p[j],-1,0); /* Case-independent match */
  5606.         if (x) {                    /* This one matches */
  5607.             makestr(&(p[j]),NULL);      /* Free it */
  5608.             for (k = j; k < last; k++)  /* Move the rest up */
  5609.               p[k] = p[k+1];
  5610.             p[k] = NULL;            /* Erase last one */
  5611.             if (!p[k])
  5612.               break;
  5613.         }
  5614.         }
  5615.     }
  5616.     }
  5617.   xdoadd:                /* Common exit */
  5618.     for (i = 0; i < n; i++)
  5619.       if (tmp[i])
  5620.     free(tmp[i]);
  5621.     return(x);
  5622. #endif /* PATTERNS */
  5623. }
  5624.  
  5625. /* ADD SEND-LIST */
  5626.  
  5627. static int
  5628. addsend(cx) int cx; {
  5629. #ifndef NOMSEND
  5630.     extern struct keytab fttab[];
  5631.     extern int nfttyp;
  5632.     struct filelist * flp;
  5633.     char * fmode = "";
  5634.     int xmode = 0;
  5635.     int xbinary = 0;
  5636. #endif /* NOMSEND */
  5637.  
  5638. #ifdef NOMSEND
  5639.     printf("?Sorry, ADD/REMOVE SEND-LIST not available.\n");
  5640.     return(-9);
  5641. #endif /* NOMSEND */
  5642.     if (cx == XXREMV) {
  5643.     printf("?Sorry, REMOVE SEND-LIST not implemented yet.\n");
  5644.     return(-9);
  5645.     }
  5646. #ifndef NOMSEND
  5647. #ifndef XYZ_INTERNAL
  5648.     if (protocol != PROTO_K) {
  5649.        printf("?Sorry, ADD SEND-LIST does not work with external protocols\n");
  5650.        return(-9);
  5651.     }
  5652. #endif /* XYZ_INTERNAL */
  5653.  
  5654.     x = cmifi("File specification to add","", &s,&y,xxstring);
  5655.     if (x < 0) {
  5656.     if (x == -3) {
  5657.         printf("?A file specification is required\n");
  5658.         return(-9);
  5659.     } else
  5660.       return(x);
  5661.     }
  5662.     ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  5663.     s = tmpbuf;
  5664.     if (filesinlist == 0)        /* Take care of \v(filespec) */
  5665.       fspec[0] = NUL;
  5666.     zfnqfp(s,LINBUFSIZ,line);
  5667.     s = line;
  5668.     if (((int)strlen(fspec) + (int)strlen(s) + 1) < fspeclen) {
  5669.     strcat(fspec,s);        /* safe */
  5670.     strcat(fspec," ");        /* safe */
  5671.     } else
  5672.       printf("WARNING - \\v(filespec) buffer overflow\n");
  5673.  
  5674.  
  5675.     xbinary = binary;
  5676.     if ((patterns || filepeek)        /* FILE PATTERNS or SCAN is ON */
  5677. #ifdef CK_LABELED
  5678.     && binary != XYFT_L        /* And not if FILE TYPE LABELED */
  5679. #endif /* CK_LABELED */
  5680. #ifdef VMS
  5681.     && binary != XYFT_I        /* or FILE TYPE IMAGE */
  5682. #endif /* VMS */
  5683.     ) {
  5684.     int k, x;
  5685.     x = -1;
  5686.     k = scanfile(line,&x,nscanfile);
  5687.     if (k > 0) xbinary = (k == FT_BIN) ? XYFT_B : XYFT_T;
  5688.     }
  5689.     fmode = gfmode(xbinary,0);
  5690.     if ((x = cmkey(fttab,nfttyp,
  5691.            "type of file transfer", fmode, xxstring)) < 0)
  5692.       return(x);
  5693.     xmode = x;
  5694.  
  5695.     cmarg2 = "";
  5696.     if ((x = cmfld(y ?
  5697.   "\nAs-name template containing replacement variables such as \\v(filename)" :
  5698.   "Name to send it with", "",&s,NULL)) < 0)
  5699.       if (x != -3)
  5700.     return(x);
  5701. #ifndef NOSPL
  5702.     if (y && *s) {
  5703.     char * p = tmpbuf;
  5704.     x = TMPBUFSIZ;
  5705.     zzstring(s,&p,&x);
  5706.     if (!strcmp(tmpbuf,s)) {
  5707.         printf(
  5708.   "?As-name for file group must contain variables such as \\v(filename)\n"
  5709.            );
  5710.         return(-9);
  5711.     }
  5712.     }
  5713. #endif /* NOSPL */
  5714.     ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  5715.     cmarg2 = tmpbuf;
  5716.  
  5717.     if ((x = cmcfm()) < 0)
  5718.       return(x);
  5719.     flp = (struct filelist *) malloc(sizeof(struct filelist));
  5720.     if (flp) {
  5721.     if (filetail)
  5722.       filetail->fl_next = flp;
  5723.     filetail = flp;
  5724.     if (!filehead)
  5725.       filehead = flp;
  5726.     x = (int) strlen(line);    /* Length of filename */
  5727.     s = (char *) malloc(x + 1);
  5728.     if (s) {
  5729.         strcpy(s,line);        /* safe */
  5730.         flp->fl_name = s;
  5731.         flp->fl_mode = xmode;
  5732.         x = (int) strlen(cmarg2);    /* Length of as-name */
  5733.         if (x < 1) {
  5734.         flp->fl_alias = NULL;
  5735.         } else {
  5736.         s = (char *) malloc(x + 1);
  5737.         if (s) {
  5738.             strcpy(s,cmarg2);    /* safe */
  5739.             flp->fl_alias = s;
  5740.         } else {
  5741.             printf("Sorry, can't allocate space for as-name");
  5742.             return(-9);
  5743.         }
  5744.         }
  5745.         flp->fl_next = NULL;
  5746.         filesinlist++;        /* Count this node */
  5747.         return(success = 1);    /* Finished adding this node */
  5748.     } else {
  5749.         printf("Sorry, can't allocate space for name");
  5750.         return(-9);
  5751.     }
  5752.     } else {
  5753.     printf("Sorry, can't allocate file list node");
  5754.     return(-9);
  5755.     }
  5756. #endif /* NOMSEND */
  5757. }
  5758. #endif /* ADDCMD */
  5759.  
  5760. #ifndef NOHTTP                /* HTTP ops... */
  5761. #ifdef TCPSOCKET
  5762. #define HTTP_GET 0            /* GET */
  5763. #define HTTP_PUT 1            /* PUT */
  5764. #define HTTP_POS 2            /* POST */
  5765. #define HTTP_IDX 3            /* INDEX */
  5766. #define HTTP_HED 4                      /* HEAD */
  5767. #define HTTP_DEL 5                      /* DELETE */
  5768. #define HTTP_CON 6                      /* CONNECT */
  5769. #define HTTP_OPN 7                      /* OPEN */
  5770. #define HTTP_CLS 8                      /* CLOSE */
  5771.  
  5772. static struct keytab httptab[] = {
  5773.     { "close",   HTTP_CLS, 0 },
  5774.     { "connect", HTTP_CON, 0 },
  5775.     { "delete",  HTTP_DEL, 0 },
  5776.     { "get",     HTTP_GET, 0 },
  5777.     { "head",    HTTP_HED, 0 },
  5778.     { "index",   HTTP_IDX, 0 },
  5779.     { "open",    HTTP_OPN, 0 },
  5780.     { "put",     HTTP_PUT, 0 },
  5781.     { "post",    HTTP_POS, 0 }
  5782. };
  5783. static int nhttptab = sizeof(httptab)/sizeof(struct keytab);
  5784.  
  5785. /* HTTP switches */
  5786. #define HT_SW_AG 0            /* /AGENT */
  5787. #define HT_SW_HD 1            /* /HEADER */
  5788. #define HT_SW_US 2            /* /USER */
  5789. #define HT_SW_PW 3            /* /PASSWORD */
  5790. #define HT_SW_AR 4                      /* /ARRAY */
  5791. #define HT_SW_TP 5                      /* /TOSCREEN */
  5792.  
  5793. static struct keytab httpswtab[] = {
  5794.     { "/agent",    HT_SW_AG, CM_ARG },
  5795. #ifndef NOSPL
  5796.     { "/array",    HT_SW_AR, CM_ARG },
  5797. #endif /* NOSPL */
  5798.     { "/header",   HT_SW_HD, CM_ARG },
  5799.     { "/password", HT_SW_PW, CM_ARG },
  5800.     { "/toscreen", HT_SW_TP, 0 },
  5801.     { "/user",     HT_SW_US, CM_ARG },
  5802.     { "", 0, 0 }
  5803. };
  5804. static int nhttpswtab = sizeof(httpswtab)/sizeof(struct keytab) - 1;
  5805.  
  5806. /* HTTP PUT/POST switches */
  5807. #define HT_PP_MT 0            /* /MIME-TYPE */
  5808.  
  5809. static struct keytab httpptab[] = {
  5810.     { "/mime-type", HT_PP_MT, CM_ARG },
  5811.     { "", 0, 0 }
  5812. };
  5813. static int nhttpptab = sizeof(httpptab)/sizeof(struct keytab) - 1;
  5814.  
  5815. #define HTTP_MAXHDR 8
  5816.  
  5817. static int
  5818. xdohttp(action, lfile, rf, dfile, agent, hdr, user, pass, mime, array, type)
  5819.     int action;
  5820.     char *lfile, *rf, *dfile, *agent, *hdr, *user, *pass, *mime, array;
  5821.     int type;
  5822. /* xdohttp */ {
  5823.     int i, rc = 0;
  5824.     char * hdrlist[HTTP_MAXHDR];
  5825.     char rfile[CKMAXPATH+1];
  5826.     extern int httpfd;
  5827.  
  5828.     /* Check for a valid state to execute the command */
  5829.     if (inserver) {
  5830.         printf("?The HTTP command may not be used from the IKS\r\n");
  5831.     } else if (httpfd == -1) {
  5832.         if (http_reopen() < 0)
  5833.       printf("?No connection\n");
  5834.         else
  5835.       rc = 1;
  5836.     } else {
  5837.     rc = 1;
  5838.     }
  5839.  
  5840.     /* If the command is not valid, exit with failure */
  5841.     if (rc == 0)
  5842.         return(success = 0);
  5843.  
  5844.     if (action != HTTP_CON && rf[0] != '/') {
  5845.         rfile[0] = '/';
  5846.         ckstrncpy(&rfile[1],rf,CKMAXPATH);
  5847.     } else {
  5848.         ckstrncpy(rfile,rf,CKMAXPATH);
  5849.     }
  5850.     for (i = 0; i < HTTP_MAXHDR; i++)    /* Initialize header list */
  5851.       hdrlist[i] = NULL;
  5852.     makelist(hdr,hdrlist,HTTP_MAXHDR);    /* Make header list */
  5853.  
  5854. #ifdef BETADEBUG
  5855.     for (i = 0; i < nhttptab; i++)    /* Find action keyword */
  5856.       if (httptab[i].kwval == action)
  5857.     break;
  5858.     if (i == nhttptab) {        /* Shouldn't happen... */
  5859.     printf("?Invalid action - %d\n",action);
  5860.     return(0);            /* Failure */
  5861.     }
  5862.  
  5863.     printf("HTTP action:  %s\n",httptab[i].kwd);
  5864.     printf(" Agent:       %s\n",agent ? agent : "(null)");
  5865.  
  5866.     if (hdrlist[1]) {
  5867.     printf(" Header list: 1. %s\n",hdrlist[0]);
  5868.     for (i = 1; i < HTTP_MAXHDR && hdrlist[i]; i++)
  5869.       printf("%15d. %s\n",i+1,hdrlist[i]);
  5870.     } else
  5871.       printf(" Header:      %s\n",hdrlist[0] ? hdrlist[0] : "(null)");
  5872.  
  5873.     printf(" User:        %s\n",user ? user : "(null)");
  5874. #ifdef COMMENT
  5875.     printf(" Password:    %s\n",pass ? pass : "(null)");
  5876. #endif /* COMMENT */
  5877.  
  5878. #ifndef NOSPL
  5879.     if (array)
  5880.       printf(" Array:       \\%%%c[]\n", array);
  5881.     else
  5882.       printf(" Array:       (none)\n");
  5883. #endif /* NOSPL */
  5884.  
  5885.     if (action == HTTP_PUT || action == HTTP_POS)
  5886.       printf(" Mime-type:   %s\n",mime ? mime : "(null)");
  5887.  
  5888.     printf(" Local file:  %s\n",lfile ? lfile : "(null)");
  5889.     printf(" Remote file: %s\n",rfile ? rfile : "(null)");
  5890.     printf(" Destination file: %s\n",dfile ? dfile : "(null)");
  5891. #endif /* BETADEBUG */
  5892.  
  5893.     /* The http_xxxx() functions return 0 on success, -1 on failure */
  5894.     switch (action) {
  5895.       case HTTP_CON: {
  5896.       extern int ttyfd;
  5897.       rc = http_connect(httpfd,agent,hdrlist,user,pass,array,rfile);
  5898.       break;
  5899.       }
  5900.       case HTTP_DEL:
  5901.         rc = http_delete(agent,hdrlist,user,pass,array,rfile);
  5902.         break;
  5903.       case HTTP_GET:
  5904.         rc = http_get(agent,hdrlist,user,pass,array,lfile,rfile,type);
  5905.         break;
  5906.       case HTTP_HED:
  5907.         rc = http_head(agent,hdrlist,user,pass,array,lfile,rfile,type);
  5908.         break;
  5909.       case HTTP_PUT:
  5910.         rc = http_put(agent,hdrlist,mime,user,pass,array,lfile,rfile,dfile,
  5911.               type);
  5912.         break;
  5913.       case HTTP_POS:
  5914.         rc = http_post(agent,hdrlist,mime,user,pass,array,lfile,rfile,dfile,
  5915.                type);
  5916.         break;
  5917.       case HTTP_IDX:
  5918.         rc = http_index(agent,hdrlist,user,pass,array,lfile,rfile,type);
  5919.         break;
  5920.       default:
  5921.         rc = -1;
  5922.     }
  5923.     return(rc == 0 ? 1 : 0);            /* Success is set by caller */
  5924. }
  5925. #endif /* TCPSOCKET */
  5926. #endif /* NOHTTP */
  5927.  
  5928. #ifndef NOSPL                /* ARRAY ops... */
  5929. static struct keytab arraytab[] = {
  5930.     { "clear",     ARR_CLR, 0 },
  5931.     { "copy",      ARR_CPY, 0 },
  5932.     { "dcl",       ARR_DCL, CM_INV },
  5933.     { "declare",   ARR_DCL, 0 },
  5934.     { "destroy",   ARR_DST, CM_INV },
  5935.     { "equate",    ARR_EQU, CM_INV },
  5936.     { "link",      ARR_EQU, 0 },
  5937.     { "resize",    ARR_RSZ, 0 },
  5938.     { "set",       ARR_SET, 0 },
  5939. #ifndef NOSHOW
  5940.     { "show",      ARR_SHO, 0 },
  5941. #endif /* NOSHOW */
  5942.     { "sort",      ARR_SRT, 0 },
  5943.     { "undeclare", ARR_DST, 0 },
  5944.     { "", 0, 0 }
  5945. };
  5946. static int narraytab = sizeof(arraytab)/sizeof(struct keytab) - 1;
  5947.  
  5948. #ifdef CKLEARN
  5949. static struct keytab learnswi[] = {
  5950.     { "/close",    2, 0 },
  5951.     { "/off",      0, 0 },
  5952.     { "/on",       1, 0 }
  5953. };
  5954. #endif /* CKLEARN */
  5955.  
  5956. int
  5957. arrayitoa(x) int x; {            /* Array index to array letter */
  5958.     if (x == 1)
  5959.       return(64);
  5960.     else if (x < 0 || x > (122 - ARRAYBASE))
  5961.       return(-1);
  5962.     else
  5963.       return(x + ARRAYBASE);
  5964. }
  5965.  
  5966. int
  5967. arrayatoi(c) int c; {            /* Array letter to array index */
  5968.     if (c == 64)
  5969.       c = 96;
  5970.     if (c > 63 && c < 91)
  5971.       c += 32;
  5972.     if (c < ARRAYBASE || c > 122)
  5973.       return(-1);
  5974.     return(c - ARRAYBASE);
  5975. }
  5976.  
  5977. static int                /* Declare an array */
  5978. dodcl(cx) int cx; {
  5979.     int i, n, v, lo, hi, rc = 0;
  5980.     int isdynamic = 0;
  5981.     char tmpbuf[64];
  5982.     char ** p = NULL;
  5983.     char tmp[64];            /* Local temporary string buffer */
  5984.     if ((y = cmfld("Array name","",&s,NULL)) < 0) { /* Parse array name */
  5985.     if (y == -3) {
  5986.         printf("?Array name required\n");
  5987.         return(-9);
  5988.     } else return(y);
  5989.     }
  5990.     ckstrncpy(line,s,LINBUFSIZ);
  5991.     s = line;
  5992.     x = arraybounds(s,&lo,&hi);        /* Check syntax and get bounds */
  5993.     debug(F111,"dodcl arraybounds",s,x);
  5994.     if (x < 0) {            /* Error - Maybe it's a variable */
  5995.     char * p;            /* whose value is an array name */
  5996.     int n;
  5997.     p = tmpbuf;
  5998.     n = 63;
  5999.     p[0] = NUL;
  6000.     if (s[0] == CMDQ && s[1] == '&')
  6001.       s++;
  6002.     if (zzstring(s,&p,&n) > -1) {
  6003.         s = tmpbuf;
  6004.         x = arraybounds(s,&lo,&hi);
  6005.         debug(F111,"dodcl arraybounds 2",s,x);
  6006.     }
  6007.     if (x < 0) {
  6008.         printf("?Bad array name - \"%s\"\n",s);
  6009.         return(-9);
  6010.     }
  6011.     }
  6012.     debug(F101,"dodcl hi","",hi);
  6013.     debug(F101,"dodcl lo","",lo);
  6014.     debug(F101,"dodcl lo+1","",lo+1);
  6015.  
  6016.     if (lo == -1 && hi == -1) {        /* Have good array name and bounds */
  6017.     isdynamic = 1;
  6018.     n = CMDBL / 5;
  6019.     } else if (hi > -1) {
  6020.     printf("?Segment notation not allowed in array declarations\n");
  6021.     return(-9);
  6022.     } else if ((lo+1) < 0) {
  6023.     debug(F101,"dodcl underflow","",lo+1);
  6024.         printf("?Dimension underflow\n");
  6025.         return(-9);
  6026.     } else
  6027.       n = lo;
  6028.     x = arrayitoa(x);
  6029.     if (cx == XXUNDCL) {
  6030.     n = 0;
  6031.     v = 0;
  6032.     if ((y = cmcfm()) < 0)
  6033.       return(y);
  6034.     } else {
  6035.     p = (char **)malloc(sizeof(char **)*(n+1));
  6036.     if (!p) {
  6037.         printf("?Memory allocation error\n");
  6038.         return(-9);
  6039.     }
  6040.     v = 0;                /* Highest initialized member */
  6041.     p[0] = NULL;            /* Element 0 */
  6042.     keepallchars = 1;
  6043.     while (n > 0 && v < n) {    /* Parse initializers */
  6044.         p[v+1] = NULL;
  6045.         ckmakxmsg(tmp,
  6046.               64,
  6047.               "Initial value for \\&",
  6048.               ckctoa((char)x),
  6049.               "[",
  6050.               ckitoa(v+1),
  6051.               "]",
  6052.               NULL,NULL,NULL,NULL,NULL,NULL,NULL
  6053.               );
  6054.         
  6055.         rc = cmfld((char *)tmp,"",&s,xxstring); /* Get field */
  6056.         if (rc < 0) {        /* Error... */
  6057.         if (rc == -3) {        /* Empty element */
  6058.             if (cmflgs == 1)    /* because end of line? */
  6059.               break;        /* Yes, done initializing */
  6060.             else        /* No, it's just empty */
  6061.               continue;        /* Go on to next one. */
  6062.         } else {        /* Other parse error */
  6063.             goto dclx;        /* Go free temp pointers */
  6064.         }
  6065.         }
  6066.         rc = 1;
  6067.         if (v == 0 && !strcmp(s,"=")) /* Skip the = sign. */
  6068.           continue;
  6069.         s = brstrip(s);        /* Strip any braces */
  6070.         makestr(&(p[++v]),s);
  6071.     }
  6072.     keepallchars = 0;
  6073.     if ((y = cmtxt("Carriage return to confirm","",&s,NULL)) < 0)
  6074.       return(y);
  6075.     if (isdynamic)
  6076.       n = v;
  6077.     }
  6078.     if (dclarray((char)x,n) < 0) {    /* Declare the array */
  6079.     printf("?Declare failed\n");
  6080.     goto dclx;
  6081.     }
  6082.     for (i = 1; i <= v; i++) {        /* Add any initial values */
  6083.     tmp[0] = '&';
  6084.     ckmakmsg(&tmp[1],63,ckctoa((char)x),"[",ckitoa(i),"]");
  6085.     if (addmac(tmp,p[i]) < 0) {
  6086.         printf("Array initialization error: %s %s\n",tmp,p[i]);
  6087.         rc = -9;
  6088.         goto dclx;
  6089.     }
  6090.     }
  6091.   dclx:
  6092.     if (p) {
  6093.     for (i = 1; i <= v; i++)
  6094.       if (p[i]) free(p[i]);
  6095.     free((char *)p);
  6096.     }
  6097.     debug(F101,"DCL rc","",rc);
  6098.     return(success = rc);
  6099. }
  6100.  
  6101. static int
  6102. rszarray() {
  6103.     int i, x, y, n, lo, hi, islink = -1;
  6104.     char c, * s, ** ap = NULL;
  6105.     if ((x = cmfld("Array name","",&s,NULL)) < 0) { /* Parse array name */
  6106.     if (x == -3) {
  6107.         printf("?Array name required\n");
  6108.         return(-9);
  6109.     } else return(x);
  6110.     }
  6111.     ckstrncpy(line,s,LINBUFSIZ);    /* Make safe copy of name */
  6112.     s = line;
  6113.     x = arraybounds(s,&lo,&hi);
  6114.     if (x < 0) {            /* Parse the name, get index */
  6115.     printf("?Bad array reference - \"%s\"\n", s);
  6116.     return(-9);
  6117.     }
  6118.     if (lo < 0 && hi < 0) {
  6119.     y = cmnum("New size","",10,&lo,xxstring);
  6120.     if (y < 0) {
  6121.         if (y == -3)
  6122.           printf("?New size required\n");
  6123.         return(y);
  6124.     }
  6125.     }
  6126.     if ((y = cmcfm()) < 0)
  6127.       return(y);
  6128.     if (a_link[x] > -1) {        /* Link? */
  6129.     islink = x;            /* Yes follow it */
  6130.     x = a_link[x];            /* and remember */
  6131.     }
  6132.     if (!a_ptr[x]) {
  6133.     printf("?Array not declared - \"%s\"\n", s);
  6134.     return(-9);
  6135.     }
  6136.     if (lo < 0) {
  6137.     printf("?New size required\n");
  6138.     return(-9);
  6139.     }
  6140.     if (hi > -1) {
  6141.     printf("?Array segments not allowed for this operation\n");
  6142.     return(-9);
  6143.     }
  6144.     c = arrayitoa(x);            /* Get array letter */
  6145.     if (c == '@') {            /* Argument vector array off limits */
  6146.     printf("?Sorry, \\&@[] is read-only\n");
  6147.     return(-9);
  6148.     }
  6149.     if (lo == 0) {            /* If new size is 0... */
  6150.     dclarray(c,0);            /* Undeclare the array */
  6151.     return(success = 1);
  6152.     }
  6153.     n = a_dim[x];            /* Current size */
  6154.     ap = (char **) malloc((lo+1) * sizeof(char *)); /* New array */
  6155.     y = (n < lo) ? n : lo;
  6156.     for (i = 0; i <= y; i++)        /* Copy the part that fits */
  6157.       ap[i] = a_ptr[x][i];
  6158.     if (n < lo) {            /* If original array smaller */
  6159.     for (; i <= lo; i++)        /* initialize extra elements in */
  6160.       ap[i] = NULL;            /* new array to NULL. */
  6161.     } else if (n > lo) {        /* If new array smaller */
  6162.     for (; i <= lo; i++)        /* deallocate leftover elements */
  6163.       makestr(&(a_ptr[x][i]),NULL);    /* from original array. */
  6164.     }
  6165.     free((char *)a_ptr[x]);        /* Free original array list */
  6166.     a_ptr[x] = ap;            /* Replace with new one */
  6167.     a_dim[x] = lo;            /* Record the new dimension */
  6168.     if (islink > -1) {            /* Was this a link? */
  6169.     a_ptr[islink] = ap;        /* If so point to the resized array */
  6170.     a_dim[islink] = lo;
  6171.     } else {                /* If not are there links to here? */
  6172.     for (i = 0; i < (int) 'z' - ARRAYBASE; i++) { /* Any linked arrays? */
  6173.         if (i != x && a_link[i] == x) {     /* Find and update them */
  6174.         a_ptr[i] = ap;
  6175.         a_dim[i] = lo;
  6176.         }
  6177.     }
  6178.     }
  6179.     return(success = 1);
  6180. }
  6181.  
  6182. static int
  6183. copyarray() {
  6184.     int i, j, x1, lo1, hi1, x2, lo2, hi2, whole = 0;
  6185.     char c1, c2, * a1, * a2;
  6186.     if ((y = cmfld("Name of source array","",&s,NULL)) < 0)
  6187.       return(y);
  6188.     ckstrncpy(line,s,LINBUFSIZ);
  6189.     a1 = line;
  6190.     if ((x1 = arraybounds(a1,&lo1,&hi1)) < 0) {
  6191.     printf("?Bad array reference - \"%s\"\n", a1);
  6192.     return(-9);
  6193.     } else if (!a_ptr[x1]) {
  6194.     printf("?Array not declared - \"%s\"\n", a1);
  6195.     return(-9);
  6196.     }
  6197.     c1 = arrayitoa(x1);
  6198.  
  6199.     if ((y = cmfld("Name of destination array","",&s,NULL)) < 0)
  6200.       return(y);
  6201.     ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  6202.     a2 = tmpbuf;
  6203.     if ((x2 = arraybounds(a2,&lo2,&hi2)) < 0) {
  6204.     printf("?Bad array reference - \"%s\"\n", a2);
  6205.     return(-9);
  6206.     }
  6207.     c2 = arrayitoa(x2);
  6208.  
  6209.     if ((x = cmcfm()) < 0)
  6210.       return(x);
  6211.  
  6212.     if (c2 == '@') {            /* Argument vector array off limits */
  6213.     printf("?Sorry, \\&@[] is read-only\n");
  6214.     return(-9);
  6215.     }
  6216.     if (lo1 < 0 && lo2 < 0 && hi1 < 0 && hi2 < 0) /* Special case for */
  6217.       whole = 1;                      /* whole array... */
  6218.  
  6219.     if (lo1 < 0) lo1 = whole ? 0 : 1;    /* Supply lower bound of source */
  6220.     if (hi1 < 0) hi1 = a_dim[x1];    /* Supply upper bound of source */
  6221.     if (lo2 < 0) lo2 = whole ? 0 : 1;    /* Lower bound of target */
  6222.     if (hi2 < 0) hi2 = lo2 + hi1 - lo1;    /* Upper bound of target */
  6223.     if (a_ptr[x2]) {            /* Target array is already declared? */
  6224.     if (hi2 > a_dim[x2])        /* If upper bound out of range */
  6225.       hi2 = a_dim[x2];        /* shrink to fit */
  6226.     } else {                /* Otherwise... */
  6227.     x2 = dclarray(c2, hi2);        /* declare the target array */
  6228.     }
  6229.     for (i = lo1, j = lo2; i <= hi1 && j <= hi2; i++,j++) { /* Copy */
  6230.     makestr(&(a_ptr[x2][j]),a_ptr[x1][i]);
  6231.     }
  6232.     return(success = 1);
  6233. }
  6234.  
  6235. static int                /* Undeclare an array */
  6236. unarray() {
  6237.     int x, y, n, rc = 0;
  6238.     char c, * s;
  6239.  
  6240.     if ((y = cmfld("Array name","",&s,NULL)) < 0) { /* Parse array name */
  6241.     if (y == -3) {
  6242.         printf("?Array name required\n");
  6243.         return(-9);
  6244.     } else return(y);
  6245.     }
  6246.     ckstrncpy(line,s,LINBUFSIZ);    /* Make safe copy of name */
  6247.     s = line;
  6248.     if ((y = cmcfm()) < 0)
  6249.       return(y);
  6250.     if ((x = arraybounds(s,&y,&n)) < 0) { /* Parse the name, get index */
  6251.     printf("?Bad array reference - \"%s\"\n", s);
  6252.     return(-9);
  6253.     }
  6254.     if (y > 0 || n > 0) {
  6255.     printf("?Partial arrays can not be destroyed\n");
  6256.     return(-9);
  6257.     }
  6258.     c = arrayitoa(x);            /* Get array letter */
  6259.     if (a_ptr[x]) {            /* If array is declared */
  6260.     if (c == '@') {            /* Argument vector array off limits */
  6261.         printf("?Sorry, \\&@[] is read-only\n");
  6262.         return(-9);
  6263.     }
  6264.     rc = dclarray(c,-1);        /* Undeclare the array */
  6265.     } else                /* It wasn't declared */
  6266.       rc = 1;
  6267.     if (rc > -1) {            /* Set return code and success */
  6268.     success = 1;
  6269.     rc = 1;
  6270.     } else {
  6271.     success = 0;
  6272.     printf("?Failed - destroy \"\\&%c[]\"\n", c);
  6273.     rc = -9;
  6274.     }
  6275.     return(rc);
  6276. }
  6277.  
  6278. static int
  6279. clrarray(cx) int cx; {
  6280.     int i, x, lo, hi;
  6281.     char c, * s, * val = NULL;
  6282.  
  6283.     if ((x = cmfld("Array name","",&s,NULL)) < 0) { /* Parse array name */
  6284.     if (x == -3) {
  6285.         printf("?Array name required\n");
  6286.         return(-9);
  6287.     } else return(x);
  6288.     }
  6289.     ckstrncpy(line,s,LINBUFSIZ);    /* Make safe copy of name */
  6290.     s = line;
  6291.     if (cx == ARR_SET) {        /* SET */
  6292.     if ((x = cmtxt("Value","",&val,xxstring)) < 0)
  6293.       return(x);
  6294.     ckstrncpy(tmpbuf,val,TMPBUFSIZ); /* Value to set */
  6295.     val = tmpbuf;
  6296.     if (!*val) val = NULL;
  6297.     } else if ((x = cmcfm()) < 0)    /* CLEAR */
  6298.       return(x);
  6299.  
  6300.     if ((x = arraybounds(s,&lo,&hi)) < 0) { /* Parse the name */
  6301.     printf("?Bad array reference - \"%s\"\n", s);
  6302.     return(-9);
  6303.     }
  6304.     c = arrayitoa(x);            /* Get array letter */
  6305.     if (!a_ptr[x]) {            /* If array is declared */
  6306.     printf("?Array %s is not declared\n", s);
  6307.     return(-9);
  6308.     } else if (c == '@') {        /* Argument vector array off limits */
  6309.     printf("?Sorry, \\&@[] is read-only\n");
  6310.     return(-9);
  6311.     }
  6312.     if (lo < 0) lo = 0;
  6313.     if (hi < 0) hi = a_dim[x];
  6314.     for (i = lo; i <= hi; i++)        /* Clear/Set selected range */
  6315.       makestr(&(a_ptr[x][i]),val);
  6316.  
  6317.     return(success = 1);
  6318. }
  6319.  
  6320. extern char **aa_ptr[CMDSTKL][28];
  6321. extern int aa_dim[CMDSTKL][28];
  6322.  
  6323. static int                /* Create symbolic link to an array */
  6324. linkarray() {
  6325.     int i = 0, x, y, lo, hi, flag = 0;
  6326.     char c, * s, * p;
  6327.  
  6328.     if ((x = cmfld("Array name not currently in use","",&s,NULL)) < 0) {
  6329.     if (x == -3) {
  6330.         printf("?Array name required\n");
  6331.         return(-9);
  6332.     } else return(x);
  6333.     }
  6334.     ckstrncpy(line,s,LINBUFSIZ);    /* Make safe copy of link name */
  6335.     s = line;
  6336.     if ((x = cmfld("Name of existing array","",&p,xxstring)) < 0) {
  6337.     if (x == -3) {
  6338.         printf("?Array name required\n");
  6339.         return(-9);
  6340.     } else return(x);
  6341.     }
  6342.     ckstrncpy(tmpbuf,p,TMPBUFSIZ);    /* Make safe copy of array name */
  6343.     p = tmpbuf;
  6344.     if ((x = cmcfm()) < 0)
  6345.       return(x);
  6346.  
  6347.     if ((x = arraybounds(s,&lo,&hi)) < 0) { /* Parse the link name */
  6348.     printf("?Bad array reference - \"%s\"\n", s);
  6349.     return(-9);
  6350.     }
  6351.     if (a_ptr[x]) {            /* Must not already exist */
  6352.     c = arrayitoa(x);
  6353.     printf("?Array already exists: \\&%c[]\n", c);
  6354.     return(-9);
  6355.     }
  6356.     if (lo > -1 || hi > -1) {
  6357.     printf("?Sorry, whole arrays only: %s\n",s);
  6358.     return(-9);
  6359.     }
  6360.     if ((y = arraybounds(p,&lo,&hi)) < 0) { /* Parse the array name */
  6361.     printf("?Bad array reference - \"%s\"\n", s);
  6362.     return(-9);
  6363.     }
  6364.     if (lo > -1 || hi > -1) {
  6365.     printf("?Sorry, whole arrays only: %s\n",p);
  6366.     return(-9);
  6367.     }
  6368.     if (x == y) {
  6369.     for (i = cmdlvl; i >= 0; i--)
  6370.       if (aa_ptr[i][x]) {
  6371.           flag++;
  6372.           break;
  6373.       }
  6374.     }
  6375.     if (flag) {
  6376.     a_ptr[x] = aa_ptr[i][y];    /* Link to saved copy */
  6377.     a_dim[x] = aa_dim[i][y];
  6378.     } else {                /* Otherwise... */
  6379.     c = arrayitoa(y);        /* Check if it's declared */
  6380.     if (!a_ptr[y]) {
  6381.         printf("?Array is not declared: \\&%c[]\n", c);
  6382.         return(-9);
  6383.     }
  6384.     if (a_link[y] > -1) {        /* And if it's a link itself */
  6385.         printf("?Links to links not allowed: \\&%c[]\n", c);
  6386.         return(-9);
  6387.     }
  6388.     a_ptr[x] = a_ptr[y];        /* All OK, make the link */
  6389.     a_dim[x] = a_dim[y];
  6390.     }
  6391.     a_link[x] = y;
  6392.     return(success = 1);
  6393. }
  6394. #endif /* NOSPL */
  6395.  
  6396. #ifndef NOCSETS
  6397. static char * dcsetname = NULL;
  6398.  
  6399. /* Get Display Character-Set Name */
  6400.  
  6401. char *
  6402. getdcset() {
  6403.     char * s;
  6404.     int y;
  6405. #ifdef PCFONTS
  6406.     extern int tt_font, ntermfont;
  6407.     extern struct keytab term_font[];
  6408. #endif /* PCFONTS */
  6409.  
  6410.     s = "";
  6411. #ifdef OS2
  6412.     y = os2getcp();            /* Default is current code page */
  6413.     switch (y) {
  6414.       case 437: s = "cp437"; break;
  6415.       case 850: s = "cp850"; break;
  6416.       case 852: s = "cp852"; break;
  6417.       case 857: s = "cp857"; break;
  6418.       case 858: s = "cp858"; break;
  6419.       case 862: s = "cp862"; break;
  6420.       case 866: s = "cp866"; break;
  6421.       case 869: s = "cp869"; break;
  6422.       case 1250: s = "cp1250"; break;
  6423.       case 1251: s = "cp1251"; break;
  6424.       case 1252: s = "cp1252"; break;
  6425.       case 1253: s = "cp1253"; break;
  6426.       case 1254: s = "cp1254"; break;
  6427.       case 1255: s = "cp1255"; break;
  6428.       case 1256: s = "cp1256"; break;
  6429.       case 1257: s = "cp1257"; break;
  6430.       case 1258: s = "cp1258"; break;
  6431.     }
  6432. #ifdef PCFONTS
  6433. /*
  6434.    If the user has loaded a font with SET TERMINAL FONT then we want
  6435.    to change the default code page to the font that was loaded.
  6436. */
  6437.     if (tt_font != TTF_ROM) {
  6438.     for (y = 0; y < ntermfont; y++ ) {
  6439.         if (term_font[y].kwval == tt_font) {
  6440.         s = term_font[y].kwd;
  6441.         break;
  6442.         }
  6443.     }
  6444.     }
  6445. #endif /* PCFONTS */
  6446. #else /* OS2 */
  6447. #ifdef COMMENT
  6448.     /* Hack not needed as of C-Kermit 7.1 */
  6449.     if (fcharset == FC_1LATIN) {
  6450.     s = "latin1-iso";        /* Hack to avoid reporting "cp1252" */
  6451.     } else {                /* Report current file character set */
  6452. #endif /* COMMENT */
  6453.     for (y = 0; y <= nfilc; y++)
  6454.       if (fcstab[y].kwval == fcharset) {
  6455.           s = fcstab[y].kwd;
  6456.           break;
  6457.       }
  6458. #ifdef COMMENT
  6459.     }
  6460. #endif /* COMMENT */
  6461. #endif /* OS2 */
  6462.     makestr(&dcsetname,s);        /* Return stable pointer */
  6463.     return((char *)dcsetname);
  6464. }
  6465. #endif /* NOCSETS */
  6466.  
  6467. #ifndef NOFRILLS
  6468. static int
  6469. doclear() {
  6470.     if ((x = cmkey(clrtab,nclear,"item to clear",
  6471. #ifdef NOSPL
  6472.            "device-buffer"
  6473. #else
  6474.            "device-and-input"
  6475. #endif /* NOSPL */
  6476.            ,xxstring)) < 0) return(x);
  6477. #ifndef NOSPL
  6478. #ifdef OS2
  6479.     if (x == CLR_CMD || x == CLR_TRM) {
  6480.     if ((z = cmkey(clrcmdtab,nclrcmd,"how much screen to clear\n",
  6481.                "all",xxstring)) < 0)
  6482.       return(z);
  6483.     }
  6484. #endif /* OS2 */
  6485. #endif /* NOSPL */
  6486.     if ((y = cmcfm()) < 0)
  6487.       return(y);
  6488.  
  6489.     /* Clear device input buffer if requested */
  6490.     y = (x & CLR_DEV) ? ttflui() : 0;
  6491.  
  6492.     if (x & CLR_SCR)            /* CLEAR SCREEN */
  6493.       y = ck_cls();            /* (= SCREEN CLEAR = CLS) */
  6494.  
  6495.     if (x & CLR_KBD) {            /* CLEAR KEYBOARD */
  6496.     int n;
  6497.     n = conchk();
  6498.     y = 0;
  6499.     while (n-- > 0 && (y = coninc(0) > -1))
  6500.       ;
  6501.     y = (y > -1) ? 0 : -1;
  6502.     }
  6503.  
  6504. #ifndef NOSPL
  6505.     /* Clear INPUT command buffer if requested */
  6506.     if (x & CLR_INP) {
  6507.     for (z = 0; z < inbufsize; z++)
  6508.       inpbuf[z] = NUL;
  6509.     inpbp = inpbuf;
  6510.     y = 0;
  6511.     }
  6512. #ifdef CK_APC
  6513.     if (x & CLR_APC) {
  6514.     debug(F101,"Executing CLEAR APC","",apcactive);
  6515.     apcactive = 0;
  6516.     y = 0;
  6517.     }
  6518. #endif /* CK_APC */
  6519.     if (x & CLR_ALR) {
  6520.     setalarm(0L);
  6521.     y = 0;
  6522.     }
  6523. #endif /* NOSPL */
  6524.  
  6525. #ifdef PATTERNS
  6526.     if (x & (CLR_TXT|CLR_BIN)) {
  6527.     int i;
  6528.     for (i = 0; i < FTPATTERNS; i++) {
  6529.         if (x & CLR_TXT)
  6530.           makestr(&txtpatterns[i],NULL);
  6531.         if (x & CLR_BIN)
  6532.           makestr(&binpatterns[i],NULL);
  6533.     }
  6534.     y = 0;
  6535.     }
  6536. #endif /* PATTERNS */
  6537.  
  6538. #ifndef NODIAL
  6539.     if (x & CLR_DIA) {
  6540.     dialsta = DIA_UNK;
  6541.     y = 0;
  6542.     }
  6543. #endif /* NODIAL */
  6544.  
  6545. #ifndef NOMSEND
  6546.     if (x & CLR_SFL) {            /* CLEAR SEND-LIST */
  6547.     if (filehead) {
  6548.         struct filelist * flp, * next;
  6549.         flp = filehead;
  6550.         while (flp) {
  6551.         if (flp->fl_name)
  6552.           free(flp->fl_name);
  6553.         if (flp->fl_alias)
  6554.           free(flp->fl_alias);
  6555.         next = flp->fl_next;
  6556.         free((char *)flp);
  6557.         flp = next;
  6558.         }
  6559.     }
  6560.     filesinlist = 0;
  6561.     filehead = NULL;
  6562.     filetail = NULL;
  6563.     addlist = 0;
  6564.     y = 0;
  6565.     }
  6566. #endif /* NOMSEND */
  6567.  
  6568. #ifdef OS2
  6569. #ifndef NOLOCAL
  6570.     switch (x) {
  6571.       case CLR_SCL:
  6572.     clearscrollback(VTERM);
  6573.     break;
  6574.       case CLR_CMD:
  6575.     switch ( z ) {
  6576.       case CLR_C_ALL:
  6577.         clear();
  6578.         break;
  6579.       case CLR_C_BOS:
  6580.         clrboscr_escape(VCMD,SP);
  6581.         break;
  6582.       case CLR_C_BOL:
  6583.         clrbol_escape(VCMD,SP);
  6584.         break;
  6585.       case CLR_C_EOL:
  6586.         clrtoeoln(VCMD,SP);
  6587.         break;
  6588.       case CLR_C_EOS:
  6589.         clreoscr_escape(VCMD,SP);
  6590.         break;
  6591.       case CLR_C_LIN:
  6592.         clrline_escape(VCMD,SP);
  6593.         break;
  6594.       case CLR_C_SCR:
  6595.         clearscrollback(VCMD);
  6596.         break;
  6597.     default:
  6598.         printf("Not implemented yet, sorry.\n");
  6599.         break;
  6600.     }
  6601.     break;
  6602.  
  6603. #ifndef NOTERM
  6604.       case CLR_TRM:
  6605.      switch ( z ) {
  6606.       case CLR_C_ALL:
  6607.          if (VscrnGetBufferSize(VTERM) > 0 ) {
  6608.          VscrnScroll(VTERM, UPWARD, 0,
  6609.                  VscrnGetHeight(VTERM)-(tt_status[VTERM]?2:1),
  6610.                  VscrnGetHeight(VTERM) -
  6611.                  (tt_status[VTERM]?1:0), TRUE, SP
  6612.                  );
  6613.          cleartermscreen(VTERM);
  6614.          }
  6615.          break;
  6616.       case CLR_C_BOS:
  6617.         clrboscr_escape(VTERM,SP);
  6618.         break;
  6619.       case CLR_C_BOL:
  6620.         clrbol_escape(VTERM,SP);
  6621.         break;
  6622.       case CLR_C_EOL:
  6623.         clrtoeoln(VTERM,SP);
  6624.         break;
  6625.       case CLR_C_EOS:
  6626.         clreoscr_escape(VTERM,SP);
  6627.         break;
  6628.       case CLR_C_LIN:
  6629.         clrline_escape(VTERM,SP);
  6630.         break;
  6631.      case CLR_C_SCR:
  6632.          clearscrollback(VTERM);
  6633.          break;
  6634.      default:
  6635.          printf("Not implemented yet, sorry.\n");
  6636.          break;
  6637.     }
  6638.     break;
  6639. #endif /* NOTERM */
  6640.     }
  6641.     y = 0;
  6642. #endif /* NOLOCAL */
  6643. #endif /* OS2 */
  6644.     return(success = (y == 0));
  6645. }
  6646. #endif /* NOFRILLS */
  6647.  
  6648. #ifndef NOSPL
  6649. static int
  6650. doeval(cx) int cx; {
  6651.     char *p;
  6652.     char vnambuf[VNAML], * vnp = NULL;    /* These must be on the stack */
  6653.     if (!oldeval) {
  6654.     if ((y = cmfld("Variable name","",&s,
  6655.                ((cx == XX_EVAL) ? xxstring : NULL))) < 0) {
  6656.         if (y == -3) {
  6657.         printf("?Variable name required\n");
  6658.         return(-9);
  6659.         } else return(y);
  6660.     }
  6661.     ckstrncpy(vnambuf,s,VNAML);    /* Make a copy. */
  6662.     vnp = vnambuf;
  6663.     if (vnambuf[0] == CMDQ &&
  6664.         (vnambuf[1] == '%' || vnambuf[1] == '&'))
  6665.       vnp++;
  6666.     y = 0;
  6667.     if (*vnp == '%' || *vnp == '&') {
  6668.         if ((y = parsevar(vnp,&x,&z)) < 0)
  6669.           return(y);
  6670.     }
  6671.     }
  6672.     if ((x = cmtxt("Integer arithmetic expression","",&s,xxstring)) < 0)
  6673.       return(x);
  6674.     p = evala(s);
  6675.     if (!p) p = "";
  6676.     if (oldeval && *p)
  6677.       printf("%s\n", p);
  6678.     ckstrncpy(evalbuf,p,32);
  6679.     if (!oldeval)
  6680.       return(success = addmac(vnambuf,p));
  6681.     else
  6682.       return(success = *p ? 1 : 0);
  6683. }
  6684. #endif /* NOSPL */
  6685.  
  6686. #ifdef TNCODE
  6687. static int
  6688. dotelopt() {
  6689.     if ((x = cmkey(telcmd, ntelcmd, "TELNET command", "", xxstring)) < 0 )
  6690.       return(x);
  6691.     switch (x) {
  6692.       case WILL:
  6693.       case WONT:
  6694.       case DO:
  6695.       case DONT:
  6696.     if ((y = cmkey(tnopts,ntnopts,"TELNET option","",xxstring)) < 0)
  6697.       return(y);
  6698.     if ((z = cmcfm()) < 0) return(z);
  6699.  
  6700.     switch (x) {
  6701.       case WILL:
  6702.         if (TELOPT_UNANSWERED_WILL(y))
  6703.           return(success = 0);
  6704.         break;
  6705.       case WONT:
  6706.         if (TELOPT_UNANSWERED_WONT(y))
  6707.           return(success = 0);
  6708.         break;
  6709.       case DO:
  6710.         if (TELOPT_UNANSWERED_DO(y))
  6711.           return(success = 0);
  6712.         break;
  6713.       case DONT:
  6714.         if (TELOPT_UNANSWERED_DONT(y))
  6715.           return(success = 0);
  6716.         break;
  6717.     }
  6718.     if (local) {
  6719.         success = ((tn_sopt(x,y) > -1) ? 1 : 0);
  6720.     } else {
  6721.         printf("ff%02x%02x\n",x,y);
  6722.         success = 1;
  6723.     }
  6724.     if (success) {
  6725.         switch (x) {
  6726.           case WILL:
  6727.         TELOPT_UNANSWERED_WILL(y) = 1;
  6728.         break;
  6729.           case WONT:
  6730.         if ( TELOPT_ME(y) )
  6731.           TELOPT_UNANSWERED_WONT(y) = 1;
  6732.         break;
  6733.           case DO:
  6734.         TELOPT_UNANSWERED_DO(y) = 1;
  6735.         break;
  6736.           case DONT:
  6737.         if ( TELOPT_ME(y) )
  6738.           TELOPT_UNANSWERED_DONT(y) = 1;
  6739.         break;
  6740.         }
  6741.         if (tn_wait("XXTELOP") < 0) {
  6742.         tn_push();
  6743.         success = 0;
  6744.         }
  6745.     }
  6746.     return(success);
  6747.       case SB:
  6748.     if ((y=cmkey(tnsbopts,ntnsbopts,"TELNET option","",xxstring)) < 0)
  6749.       return(y);
  6750.     switch (y) {
  6751.       case TELOPT_NAWS:
  6752.         /* Some compilers require switch() to have at least 1 case */
  6753. #ifdef CK_NAWS
  6754.         TELOPT_SB(TELOPT_NAWS).naws.x = 0;
  6755.         TELOPT_SB(TELOPT_NAWS).naws.y = 0;
  6756.         if (local)
  6757.           return(success = ((tn_snaws() > -1) ? 1 : 0));
  6758.         else
  6759.           return(success = 0);
  6760. #else
  6761.         return(success = 0);
  6762. #endif /* CK_NAWS */
  6763.     }
  6764.         return(success = 0);
  6765.  
  6766. #ifdef CK_KERBEROS
  6767. #ifdef KRB5
  6768.       case TN_FWD:
  6769.         success = (kerberos5_forward() == AUTH_SUCCESS);
  6770.         return(success);
  6771. #endif /* KRB5 */
  6772. #endif /* CK_KERBEROS */
  6773.  
  6774.       default:
  6775.     if ((z = cmcfm()) < 0) return(z);
  6776. #ifndef NOLOCAL
  6777.     if (local) {
  6778.         CHAR temp[3];
  6779.         if (network && IS_TELNET()) { /* TELNET */
  6780.         temp[0] = (CHAR) IAC;
  6781.         temp[1] = x;
  6782.         temp[2] = NUL;
  6783.         success = (ttol((CHAR *)temp,2) > -1 ? 1 : 0);
  6784.         if (tn_deb || debses || deblog) {
  6785.             /* TN_MSG_LEN is in ckctel.h */
  6786.             ckmakmsg(tn_msg,256,"TELNET SENT ",TELCMD(x),NULL,NULL);
  6787.             debug(F101,tn_msg,"",x);
  6788.             if (debses || tn_deb) tn_debug(tn_msg);
  6789.         }
  6790.         return(success);
  6791.         }
  6792.             return(success = 0);
  6793.     } else {
  6794. #endif /* NOLOCAL */
  6795.         printf("ff%02x\n",x);
  6796.         return(success = 1);
  6797. #ifndef NOLOCAL
  6798.     }
  6799. #endif /* NOLOCAL */
  6800.     }
  6801. }
  6802. #endif /* TNCODE */
  6803.  
  6804.  
  6805. #ifndef NOPUSH
  6806. #ifndef NOFRILLS
  6807. static int
  6808. doedit() {
  6809. #ifdef OS2
  6810.     char * p = NULL;
  6811. #endif /* OS2 */
  6812.     if (!editor[0]) {
  6813.     s = getenv("EDITOR");
  6814.     if (s) ckstrncpy(editor,s,CKMAXPATH);
  6815.     editor[CKMAXPATH] = NUL;
  6816.     if (!editor[0]) {
  6817.         printf("?Editor not defined - use SET EDITOR to define\n");
  6818.         return(-9);
  6819.     }
  6820.     }
  6821.     ckstrncpy(tmpbuf,editfile,TMPBUFSIZ);
  6822. /*
  6823.   cmiofi() lets us parse the name of an existing file, or the name of
  6824.   a nonexistent file to be created.
  6825. */
  6826.     x = cmiofi("File to edit", (char *)tmpbuf, &s, &y, xxstring);
  6827.     debug(F111,"edit",s,x);
  6828.     if (x < 0 && x != -3)
  6829.       return(x);
  6830.     if (x == -3) {
  6831.     tmpbuf[0] = NUL;
  6832.     } else {
  6833.     ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  6834.     }
  6835.     if ((z = cmcfm()) < 0) return(z);
  6836.     if (y) {
  6837.     printf("?A single file please\n");
  6838.     return(-9);
  6839.     }
  6840.     if (nopush) {
  6841.     printf("?Sorry, editing not allowed\n");
  6842.     return(success = 0);
  6843.     }
  6844.     if (tmpbuf[0]) {
  6845.     /* Get full path in case we change directories between EDIT commands */
  6846.     zfnqfp(tmpbuf, CKMAXPATH, editfile);
  6847.     editfile[CKMAXPATH] = NUL;
  6848. #ifdef OS2
  6849.     p = editfile;            /* Flip the stupid slashes */
  6850.     while (*p) {
  6851.         if (*p == '/') *p = '\\';
  6852.         p++;
  6853.     }
  6854. #endif /* OS2 */
  6855.     } else
  6856.       editfile[0] = NUL;
  6857.     if (editfile[0]) {
  6858.     if (zchki(editfile) < (CK_OFF_T)0 && zchko(editfile) < 0) {
  6859.         printf("?Access denied: %s\n",editfile);
  6860.         return(-9);
  6861.     }
  6862.     }
  6863.     x = 0;
  6864.     if (editopts[0]) {
  6865. #ifdef OS2
  6866.     x = ckindex("%1",(char *)editopts,0,0,1);
  6867.     if (x > 0)
  6868.       editopts[x] = 's';
  6869.     else
  6870. #endif /* OS2 */
  6871.       x = ckindex("%s",(char *)editopts,0,0,1);
  6872.     }
  6873.     if (((int)strlen(editopts) + (int)strlen(editfile) + 1) < TMPBUFSIZ) {
  6874.     if (x)
  6875.       sprintf(tmpbuf,editopts,editfile);
  6876.     else
  6877.       sprintf(tmpbuf,"%s %s",editopts,editfile);
  6878.     }
  6879.     s = line;
  6880.     ckmakmsg(s,LINBUFSIZ,editor," ",tmpbuf,NULL);
  6881. #ifdef OS2
  6882.     p = s + strlen(editor);        /* And again with the slashes */
  6883.     while (p != s) {
  6884.     if (*p == '/') *p = '\\';
  6885.     p--;
  6886.     }
  6887. #endif /* OS2 */
  6888.     conres();
  6889.     x = zshcmd(s);
  6890.     concb((char)escape);
  6891.     return(x);
  6892. }
  6893. #endif /* NOFRILLS */
  6894. #endif /* NOPUSH */
  6895.  
  6896. #ifdef BROWSER
  6897. static int
  6898. dobrowse() {
  6899. #ifdef OS2
  6900.     char * p = NULL;
  6901. #endif /* OS2 */
  6902.     if (nopush) {
  6903.     printf("?Sorry, browsing not allowed\n");
  6904.     return(success = 0);
  6905.     }
  6906. #ifndef NT
  6907.     /* Windows lets the Shell Execute the URL if no Browser is defined */
  6908.     if (!browser[0]) {
  6909.     s = getenv("BROWSER");
  6910.     if (s) ckstrncpy(browser,s,CKMAXPATH);
  6911.     browser[CKMAXPATH] = NUL;
  6912.     if (!browser[0]) {
  6913.         printf("?Browser not defined - use SET BROWSER to define\n");
  6914.         return(-9);
  6915.     }
  6916.     }
  6917. #endif /* NT */
  6918.     ckstrncpy(tmpbuf,browsurl,TMPBUFSIZ);
  6919.     if ((x = cmtxt("URL",(char *)browsurl,&s,xxstring)) < 0)
  6920.       return(x);
  6921.     ckstrncpy(browsurl,s,4096);
  6922.     x = 0;
  6923.     if (browsopts[0]) {
  6924. #ifdef OS2
  6925.     x = ckindex("%1",(char *)browsopts,0,0,1);
  6926.     if (x > 0)
  6927.       browsopts[x] = 's';
  6928.     else
  6929. #endif /* OS2 */
  6930.       x = ckindex("%s",(char *)browsopts,0,0,1);
  6931.     }
  6932.     if (((int)strlen(browsopts) + (int)strlen(browsurl) + 1) < TMPBUFSIZ) {
  6933.     if (x)
  6934.       sprintf(tmpbuf,browsopts,browsurl);
  6935.     else
  6936.       sprintf(tmpbuf,"%s %s",browsopts,browsurl);
  6937.     }
  6938. #ifdef NT
  6939.     if (!browser[0])
  6940.       return(success = Win32ShellExecute(browsurl));
  6941. #endif /* NT */
  6942.     s = line;
  6943.     ckmakmsg(s,LINBUFSIZ,browser," ",tmpbuf,NULL);
  6944. #ifdef OS2
  6945.     p = line + strlen(browser);        /* Flip slashes */
  6946.     while (p != line) {
  6947.     if (*p == '/') *p = '\\';
  6948.     p--;
  6949.     }
  6950. #endif /* OS2 */
  6951.     conres();
  6952.     x = zshcmd(s);
  6953.     concb((char)escape);
  6954.     return(x);
  6955. }
  6956. #endif /* BROWSER */
  6957.  
  6958. #ifdef CK_RECALL
  6959. static int
  6960. doredo() {            /* Find a previous cmd and redo it */
  6961.     extern int on_recall, in_recall;
  6962.     int x;
  6963.     char * p;
  6964.  
  6965.     if ((x = cmtxt(
  6966. "pattern, or first few characters of a previous command",
  6967.            "*",&s,xxstring)) < 0)
  6968.       return(x);
  6969.     ckstrncpy(line,s,LINBUFSIZ);
  6970.     x = strlen(s);
  6971.     s = line;
  6972.     if (*s == '{') {            /* Braces disable adding * to end */
  6973.     if (s[x-1] == '}') {
  6974.         s[x-1] = NUL;
  6975.         s++;
  6976.         x--;
  6977.     }
  6978.     } else {                /* No braces, add * to end. */
  6979.     s[x] = '*';
  6980.     s[x+1] = NUL;
  6981.     }
  6982.  
  6983.     while (x > 0 && s[x] == '*' && s[x-1] == '*') s[x--] = NUL;
  6984.  
  6985.     if (!on_recall || !in_recall) {
  6986.     printf("?Sorry, command recall can't be used now.\n");
  6987.     return(-9);
  6988.     }
  6989.     if ((p = cmgetcmd(s))) {        /* Look for it history buffer */
  6990.     ckmakmsg(cmdbuf,CMDBL,p,"\r",NULL,NULL); /* Copy to command buffer */
  6991.     if (!quiet)            /* Echo it */
  6992.       printf("%s\n",cmdbuf);
  6993.     cmaddnext();            /* Force re-add to history buffer */
  6994.     return(cmflgs = -1);        /* Force reparse */
  6995.     } else {
  6996.     printf("?Sorry - \"%s\" not found\n", s);
  6997.     return(-9);
  6998.     }
  6999. }
  7000. #endif /* CK_RECALL */
  7001.  
  7002. #ifndef NOXFER
  7003. #ifndef NOCSETS
  7004. static int
  7005. doassoc()  {                /* ASSOCIATE */
  7006.     extern struct keytab tcstab[];
  7007.     extern int ntcs;
  7008.     if ((x = cmkey(assoctab, nassoc, "", "", xxstring)) < 0 )
  7009.       return(x);
  7010.  
  7011.     switch (x) {            /* Associate what? */
  7012.  
  7013.       case ASSOC_TC:            /* Transfer character-set... */
  7014.     if ((x = cmkey(tcstab, ntcs,
  7015.                "transfer character-set name","",xxstring)) < 0)
  7016.       return(x);
  7017.     if ((y = cmkey(fcstab, nfilc,
  7018.                "with file character-set","", xxstring)) < 0)
  7019.       if (y != -3)
  7020.         return(y);
  7021.     if ((z = cmcfm()) < 0)
  7022.       return(z);
  7023.     axcset[x] = y;
  7024.     return(success = 1);
  7025.  
  7026.       case ASSOC_FC:            /* File character-set... */
  7027.     if ((x = cmkey(fcstab, nfilc,
  7028.                "file character-set name","",xxstring)) < 0)
  7029.       return(x);
  7030.     if ((y = cmkey(tcstab, ntcs,
  7031.                "with transfer character-set","", xxstring)) < 0)
  7032.       if (y != -3)
  7033.         return(y);
  7034.     if ((z = cmcfm()) < 0)
  7035.       return(z);
  7036.     afcset[x] = y;
  7037.     return(success = 1);
  7038.  
  7039.       default:
  7040.     return(-2);
  7041.     }
  7042. }
  7043. #endif /* NOCSETS */
  7044. #endif /* NOXFER */
  7045.  
  7046. #ifndef NOHELP
  7047. static int
  7048. domanual() {
  7049. #ifdef OS2
  7050.     if ((x = cmcfm()) < 0)
  7051.       return(x);
  7052.     if (nopush) {
  7053.     printf("?Sorry, access to system commands is disabled.\n");
  7054.     return(-9);
  7055.     }
  7056.     y = mxlook(mactab,"manual",nmac);
  7057.     if (y > -1) {
  7058.     z = maclvl;            /* Save the current maclvl */
  7059.     dodo(y,NULL,cmdstk[cmdlvl].ccflgs); /* Run the macro */
  7060.     while (maclvl > z) {
  7061.         debug(F101,"XXMAN loop maclvl 1","",maclvl);
  7062.         sstate = (CHAR) parser(1);
  7063.         debug(F101,"XXMAN loop maclvl 2","",maclvl);
  7064.         if (sstate) proto();
  7065.     }
  7066.     debug(F101,"XXMAN loop exit maclvl","",maclvl);
  7067.     return(success);
  7068.     }
  7069.     return(success = 0);
  7070. #else
  7071.     if ((x = cmtxt(
  7072. #ifdef UNIX
  7073.            "Carriage return to confirm the command, or manual topic",
  7074. #else
  7075.            "Carriage return to confirm the command, or help topic",
  7076. #endif /* UNIX */
  7077.            "kermit",
  7078.            &s,
  7079.            xxstring
  7080.            )
  7081.      ) < 0)
  7082.       return(x);
  7083. #endif /* OS2 */
  7084.  
  7085. #ifdef UNIX
  7086.     ckmakmsg(tmpbuf,TMPBUFSIZ,"man ",s,NULL,NULL);
  7087. #else
  7088.     ckmakmsg(tmpbuf,TMPBUFSIZ,"help ",s,NULL,NULL);
  7089. #endif /* UNIX */
  7090.     debug(F110,"MANUAL",tmpbuf,0);
  7091.     if (nopush) {
  7092.     printf("?Sorry, access to system commands is disabled.\n");
  7093.     return(-9);
  7094.     } else {
  7095.     conres();            /* Restore the console */
  7096.     success = zshcmd(tmpbuf);
  7097.     concb((char)escape);        /* Restore CBREAK mode */
  7098.     return(success);
  7099.     }
  7100. }
  7101. #endif /* NOHELP */
  7102.  
  7103. #ifndef NOHTTP
  7104. #ifdef TCPSOCKET
  7105. static struct keytab sslswtab[] = {
  7106.     { "/ssl", 1, 0 },
  7107.     { "/tls", 1, 0 }
  7108. };
  7109.  
  7110. #ifndef NOURL
  7111. struct urldata http_url = {NULL,NULL,NULL,NULL,NULL,NULL,NULL};
  7112. #endif /* NOURL */
  7113.  
  7114. static int
  7115. dohttp() {                /* HTTP */
  7116.     struct FDB sw, kw, fi;
  7117.     int n, getval, allinone = 0;
  7118.     char c, * p;
  7119.     char rdns[128];
  7120.  
  7121.     char * http_agent = NULL;        /* Parse results */
  7122.     char * http_hdr   = NULL;
  7123.     char * http_user  = NULL;
  7124.     char * http_pass  = NULL;
  7125.     char * http_mime  = NULL;
  7126.     char * http_lfile = NULL;
  7127.     char * http_rfile = NULL;
  7128.     char * http_dfile = NULL;
  7129.     char   http_array = NUL;
  7130.     int    http_action = -1;
  7131.  
  7132.     char * http_host = NULL;
  7133.     char * http_srv  = NULL;
  7134.     int    http_ssl  = 0;
  7135.  
  7136.     static char * http_d_agent = NULL;
  7137.     static char * http_d_user = NULL;
  7138.     static char * http_d_pass = NULL;
  7139.  
  7140.     static int    http_d_type = 0;
  7141.     int           http_type = http_d_type;
  7142.  
  7143. #ifdef OS2
  7144.     p = "Kermit 95";            /* Default user agent */
  7145. #else
  7146.     p = "C-Kermit";
  7147. #endif /* OS2 */
  7148.     makestr(&http_agent,p);
  7149.     makestr(&http_mime,"text/HTML");    /* MIME type default */
  7150.     rdns[0] = '\0';
  7151.  
  7152.     cmfdbi(&sw,                /* 1st FDB - general switches */
  7153.        _CMKEY,                /* fcode */
  7154.        "OPEN, CLOSE, GET, HEAD, PUT, INDEX, or POST,\n or switch", /* hlpmsg */
  7155.        "",                /* default */
  7156.        "",                /* addtl string data */
  7157.        nhttpswtab,            /* addtl numeric data 1: tbl size */
  7158.        4,                /* addtl numeric data 2: 4 = cmswi */
  7159.        xxstring,            /* Processing function */
  7160.        httpswtab,            /* Keyword table */
  7161.        &kw                /* Pointer to next FDB */
  7162.        );
  7163.     cmfdbi(&kw,                /* 2nd FDB - commands */
  7164.        _CMKEY,                /* fcode */
  7165.        "Command",            /* hlpmsg */
  7166.        "",                /* default */
  7167.        "",                /* addtl string data */
  7168.        nhttptab,            /* addtl numeric data 1: tbl size */
  7169.        0,                /* addtl numeric data 2: 0 = keyword */
  7170.        xxstring,            /* Processing function */
  7171.        httptab,                /* Keyword table */
  7172.        NULL                /* Pointer to next FDB */
  7173.        );
  7174.  
  7175.     while (1) {
  7176.     x = cmfdb(&sw);            /* Parse something */
  7177.     if (x < 0)            /* Error */
  7178.       goto xhttp;
  7179.     n = cmresult.nresult;
  7180.     if (cmresult.fdbaddr == &kw)    /* Command - exit this loop */
  7181.       break;
  7182.     c = cmgbrk();            /* Switch... */
  7183.     getval = (c == ':' || c == '=');
  7184.     x = -9;
  7185.     if (getval && !(cmgkwflgs() & CM_ARG)) {
  7186.         printf("?This switch does not take an argument\n");
  7187.         goto xhttp;
  7188.     }
  7189.     switch (cmresult.nresult) {    /* Handle each switch */
  7190.           case HT_SW_TP:                /* /TOSCREEN */
  7191.             http_type = 1;
  7192.             break;
  7193.       case HT_SW_AG:        /* /AGENT */
  7194.         if (getval) {
  7195.         if ((x = cmfld("User agent",p,&s,xxstring)) < 0)
  7196.           goto xhttp;
  7197.         } else {
  7198.         s = p;
  7199.         }
  7200.         makestr(&http_agent,s);
  7201.         break;
  7202.       case HT_SW_HD:        /* /HEADER */
  7203.         s = NULL;
  7204.         if (getval) {
  7205.         if ((x = cmfld("Header line","",&s,xxstring)) < 0) {
  7206.             if (x == -3)
  7207.               s = NULL;
  7208.             else
  7209.               goto xhttp;
  7210.         }
  7211.         }
  7212.         makestr(&http_hdr,s);
  7213.         break;
  7214.       case HT_SW_US:        /* /USER */
  7215.         s = NULL;
  7216.         if (getval) {
  7217.         if ((x = cmfld("User ID","",&s,xxstring)) < 0) {
  7218.                   if (x == -3)
  7219.                     s = "";
  7220.                   else
  7221.             goto xhttp;
  7222.                 }
  7223.         }
  7224.         makestr(&http_user,s);
  7225.         break;
  7226.       case HT_SW_PW:        /* /PASSWORD */
  7227.         debok = 0;
  7228.         s = NULL;
  7229.         if (getval) {
  7230.         if ((x = cmfld("Password","",&s,xxstring)) < 0)
  7231.           goto xhttp;
  7232.         }
  7233.         makestr(&http_pass,s);
  7234.         break;
  7235. #ifndef NOSPL
  7236.       case HT_SW_AR: {        /* /ARRAY: */
  7237.           char * s2, array = NUL;
  7238.           if (!getval) {
  7239.           printf("?This switch requires an argument\n");
  7240.           x = -9;
  7241.           goto xhttp;
  7242.           }
  7243.           if ((x = cmfld("Array name (a single letter will do)",
  7244.                  "",
  7245.                  &s,
  7246.                  NULL
  7247.                  )) < 0) {
  7248.           if (x == -3) {
  7249.               printf("?Array name required\n");
  7250.               x = -9;
  7251.               goto xhttp;
  7252.           } else
  7253.             goto xhttp;
  7254.           }
  7255.           if (!*s) {
  7256.           printf("?Array name required\n");
  7257.           x = -9;
  7258.           goto xhttp;
  7259.           }
  7260.           s2 = s;
  7261.           if (*s == CMDQ) s++;
  7262.           if (*s == '&') s++;
  7263.           if (!isalpha(*s)) {
  7264.           printf("?Bad array name - \"%s\"\n",s2);
  7265.           x = -9;
  7266.           goto xhttp;
  7267.           }
  7268.           array = *s++;
  7269.           if (isupper(array))
  7270.         array = tolower(array);
  7271.           if (*s && (*s != '[' || *(s+1) != ']')) {
  7272.           printf("?Bad array name - \"%s\"\n",s2);
  7273.           http_array = NUL;
  7274.           x = -9;
  7275.           goto xhttp;
  7276.           }
  7277.           http_array = array;
  7278.           break;
  7279.       }
  7280. #endif /* NOSPL */
  7281.       default:
  7282.         x = -2;
  7283.         goto xhttp;
  7284.     }
  7285.     }
  7286.     http_action = n;            /* Save the action */
  7287.     if (http_action == HTTP_PUT || http_action == HTTP_POS) {
  7288.     cmfdbi(&sw,            /* 1st FDB - switch */
  7289.            _CMKEY,            /* fcode */
  7290.            "Local filename\n Or switch", /* help */
  7291.            "",            /* default */
  7292.            "",            /* addtl string data */
  7293.            nhttpptab,        /* keyword table size */
  7294.            4,            /* addtl numeric data 2: 4 = cmswi */
  7295.            xxstring,        /* Processing function */
  7296.            httpptab,        /* Keyword table */
  7297.            &fi            /* Pointer to next FDB */
  7298.            );
  7299.     cmfdbi(&fi,            /* 2nd FDB - filename */
  7300.            _CMIFI,            /* fcode */
  7301.            "Local filename",    /* hlpmsg */
  7302.            "",            /* default */
  7303.            "",            /* addtl string data */
  7304.            0,            /* addtl numeric data 1 */
  7305.            0,            /* addtl numeric data 2 */
  7306.            xxstring,
  7307.            NULL,
  7308.            NULL
  7309.            );
  7310.     while (1) {
  7311.         x = cmfdb(&sw);
  7312.         if (x < 0)
  7313.           goto xhttp;        /* Free any malloc'd temp strings */
  7314.         n = cmresult.nresult;
  7315.         if (cmresult.fcode != _CMKEY)
  7316.           break;
  7317.         c = cmgbrk();        /* Switch... */
  7318.         getval = (c == ':' || c == '=');
  7319.         if (getval && !(cmgkwflgs() & CM_ARG)) {
  7320.         printf("?This switch does not take an argument\n");
  7321.         x = -9;
  7322.         goto xhttp;
  7323.         }
  7324.         switch (n) {
  7325.           case HT_PP_MT:
  7326.         s = "text/HTML";
  7327.         if (getval) {
  7328.             if ((x = cmfld("MIME type",
  7329.                    "text/HTML",&s,xxstring)) < 0)
  7330.               goto xhttp;
  7331.         }
  7332.         makestr(&http_mime,s);
  7333.         break;
  7334.           default:
  7335.         x = -2;
  7336.         goto xhttp;
  7337.         }
  7338.     }
  7339.     makestr(&http_lfile,cmresult.sresult);
  7340.     n = ckindex("/",http_lfile,-1,1,0);
  7341.     if (n)
  7342.       p = &http_lfile[n];
  7343.     else
  7344.       p = http_lfile;
  7345.     if ((x = cmfld("URL or remote filename",p,&s,xxstring)) < 0) {
  7346.           if (x == -3) {
  7347.             printf("?%s what?\n",(http_action == HTTP_PUT) ? "Put" : "Post");
  7348.             x = -9;
  7349.           }
  7350.           goto xhttp;
  7351.         }
  7352.     if (!*s) s = NULL;
  7353.     makestr(&http_rfile,s);
  7354.  
  7355.     if ((x = cmtxt("Response filename","",&s,xxstring)) < 0) {
  7356.           if (x != -3)
  7357.             goto xhttp;
  7358.         }
  7359.         if (*s)
  7360.           makestr(&http_dfile,s);
  7361.     }
  7362.     switch (http_action) {
  7363.       case HTTP_DEL:            /* DELETE */
  7364.     if ((x = cmfld("URL or remote source file","",&s,xxstring)) < 0) {
  7365.           if (x == -3) {
  7366.             printf("?Delete what?\n");
  7367.             x = -9;
  7368.           }
  7369.           goto xhttp;
  7370.         }
  7371.     makestr(&http_rfile,s);
  7372.     break;
  7373.       case HTTP_CON:            /* CONNECT */
  7374.         if ((x = cmfld("Remote host[:port]","",&s,xxstring)) < 0) {
  7375.           if (x == -3) {
  7376.             printf("?Remote host[:port] is required\n");
  7377.             x = -9;
  7378.           }
  7379.           goto xhttp;
  7380.         }
  7381.     makestr(&http_rfile,s);
  7382.     break;
  7383.       case HTTP_HED: {            /* HEAD */
  7384.       char buf[CKMAXPATH+1];
  7385.       if ((x = cmfld("URL or remote source file","",&s,xxstring)) < 0) {
  7386.           if (x == -3) {
  7387.           printf("?Head of what?\n");
  7388.           x = -9;
  7389.           }
  7390.           goto xhttp;
  7391.       }
  7392.       makestr(&http_rfile,s);
  7393.  
  7394.       if (http_array || http_type) { /* Default result filename */
  7395.           p = "";             /* None if /ARRAY or /TOSCREEN */
  7396.       } else {
  7397.           n = ckindex("/",http_rfile,-1,1,0); /* Otherwise strip path */
  7398.           if (n)                          /* and add ".head" */
  7399.         p = &http_rfile[n];
  7400.           else
  7401.         p = http_rfile;
  7402.           ckmakmsg(buf,CKMAXPATH,p,".head",NULL,NULL);
  7403.           p = buf;
  7404.       }
  7405.       if ((x = cmofi("Local filename",p,&s,xxstring)) < 0) {
  7406.           if (x != -3)
  7407.         goto xhttp;
  7408.       }
  7409.       makestr(&http_lfile,s);
  7410.       break;
  7411.       }
  7412.       case HTTP_GET:            /* GET */
  7413.       case HTTP_IDX: {            /* INDEX */
  7414.       extern int wildena;
  7415.       int tmp;
  7416.       char * lfile = "";
  7417.       if ((x = cmfld("URL or remote source file","",&s,xxstring)) < 0) {
  7418.           if (x == -3) {
  7419.           printf("?Get what?\n");
  7420.           x = -9;
  7421.           }
  7422.           goto xhttp;
  7423.       }
  7424.       makestr(&http_rfile,s);
  7425.       if (http_action == HTTP_GET && !http_type)
  7426.         zstrip(http_rfile,&lfile);
  7427.       /* URLs often contain question marks or other metacharacters */
  7428.       /* cmofi() doesn't like them */
  7429.       tmp = wildena;
  7430.       wildena = 0;
  7431.       if ((x = cmofi("Local filename",lfile,&s,xxstring)) < 0) {
  7432.           wildena = tmp;
  7433.           if (x != -3)
  7434.         goto xhttp;
  7435.       }
  7436.       wildena = tmp;
  7437.       makestr(&http_lfile,s);
  7438.       break;
  7439.       }
  7440.       case HTTP_OPN: {
  7441.       int sslswitch = 0;
  7442. #ifdef CK_SSL
  7443.       struct FDB sw, fl;
  7444.       cmfdbi(&sw,
  7445.          _CMKEY,        /* fcode */
  7446.          "IP host name or address, or switch", /* hlpmsg */
  7447.          "",            /* default */
  7448.          "",            /* addtl string data */
  7449.          2,            /* addtl numeric data 1: tbl size */
  7450.          4,            /* addtl numeric data 2: 4 = cmswi */
  7451.          xxstring,        /* Processing function */
  7452.          sslswtab,        /* Keyword table */
  7453.          &fl            /* Pointer to next FDB */
  7454.          );
  7455.       cmfdbi(&fl,            /* 2nd FDB - host */
  7456.          _CMFLD,        /* fcode */
  7457.          "",            /* hlpmsg */
  7458.          "",            /* default */
  7459.          "",            /* addtl string data */
  7460.          0,            /* addtl numeric data 1 */
  7461.          0,            /* addtl numeric data 2 */
  7462.          xxstring,
  7463.          NULL,
  7464.          NULL
  7465.          );
  7466.       x = cmfdb(&sw);        /* Parse switch or host */
  7467.       if (x < 0)            /* Error */
  7468.         goto xhttp;
  7469.       if (cmresult.fcode == _CMFLD) { /* Host */
  7470.           s = cmresult.sresult;      /* Set up expected pointer */
  7471.           goto havehost;              /* Go parse rest of command */
  7472.       }
  7473.       sslswitch = 1;        /* /SSL or /TLS switch - set flag */
  7474. #endif /* CK_SSL */
  7475.  
  7476.       /* Parse host */
  7477.  
  7478.       if ((x = cmfld("URL, hostname, or ip-address","",&s,xxstring)) < 0) {
  7479.           if (x == -3) {
  7480.           printf("?Open what?\n");
  7481.           x = -9;
  7482.           }
  7483.           goto xhttp;
  7484.       }
  7485.  
  7486.     havehost:            /* Come here with s -> host */
  7487. #ifdef CK_URL
  7488.       x = urlparse(s,&http_url);    /* Was a URL given? */
  7489.       if (x < 1) {            /* Not a URL */
  7490. #endif /* CK_URL */
  7491.           makestr(&http_host,s);
  7492.           if ((x =
  7493.            cmfld("Service name or port number",
  7494.              sslswitch ? "https" : "http",&s,xxstring)) < 0)
  7495.         goto xhttp;
  7496.           else
  7497.         makestr(&http_srv,s);
  7498. #ifdef CK_URL
  7499.       } else if (ckstrcmp(http_url.svc,"http",-1,0) && /* Non-HTTP URL */
  7500.              ckstrcmp(http_url.svc,"https",-1,0)) {
  7501.           printf("?Non-HTTP URL\n");
  7502.           x = -9;
  7503.           goto xhttp;
  7504.       } else {            /* Have HTTP URL */
  7505.           makestr(&http_srv, http_url.svc);
  7506.           makestr(&http_user,http_url.usr);
  7507.           makestr(&http_pass,http_url.psw);
  7508.           makestr(&http_host,http_url.hos);
  7509.           if (http_url.por)
  7510.         makestr(&http_srv,http_url.por);
  7511.           makestr(&http_rfile,http_url.pth);
  7512.       }
  7513.       if (http_rfile) {        /* Open, GET, and Close */
  7514.           printf("?Directory/file path not allowed in HTTP OPEN URL\n");
  7515.           x = -9;
  7516.           goto xhttp;
  7517.       }
  7518.       if (!ckstrcmp("https",http_srv,-1,0) || sslswitch ||
  7519.           !ckstrcmp("443",http_srv,-1,0))
  7520.         http_ssl = 1;
  7521. #endif /* CK_URL */
  7522.       break;
  7523.       }
  7524.       case HTTP_CLS:
  7525.         break;
  7526.     }
  7527.     if ((x = cmcfm()) < 0)
  7528.       goto xhttp;
  7529.  
  7530.     if (http_action == HTTP_OPN) {
  7531.         x = (http_open(http_host,http_srv,http_ssl,rdns,128,http_agent) == 0);
  7532.         if (x) {
  7533.             if (!quiet) {
  7534.               if (rdns[0])
  7535.                 printf("Connected to %s [%s]\r\n",http_host,rdns);
  7536.               else
  7537.                 printf("Connected to %s\r\n",http_host);
  7538.             }
  7539.             if (http_agent) {
  7540.                 if (http_d_agent)
  7541.           free(http_d_agent);
  7542.                 http_d_agent = http_agent;
  7543.                 http_agent = NULL;
  7544.             }
  7545.             if (http_user) {
  7546.                 if (http_d_user)
  7547.           free(http_d_user);
  7548.                 http_d_user = http_user;
  7549.                 http_user = NULL;
  7550.             }
  7551.             if (http_pass) {
  7552.                 if (http_d_pass) {
  7553.                     memset(http_d_pass,0,strlen(http_d_pass));
  7554.                     free(http_d_pass);
  7555.                 }
  7556.                 http_d_pass = http_pass;
  7557.                 http_pass = NULL;
  7558.             }
  7559.             http_d_type = http_type;
  7560.         } else {
  7561.             if (!quiet)
  7562.           printf("?HTTP Connection failed.\r\n");
  7563.         }
  7564.     } else if (http_action == HTTP_CLS) {
  7565.         if (http_d_agent) {
  7566.             free(http_d_agent);
  7567.             http_d_agent = NULL;
  7568.         }
  7569.         if (http_d_user) {
  7570.             free(http_d_user);
  7571.             http_d_user = NULL;
  7572.         }
  7573.         if (http_d_pass) {
  7574.             memset(http_d_pass,0,strlen(http_d_pass));
  7575.             free(http_d_pass);
  7576.             http_d_pass = NULL;
  7577.         }
  7578.         http_d_type = 0;
  7579.         x = (http_close() == 0);
  7580.     }
  7581.     if ((http_action != HTTP_CLS) &&
  7582.     (http_action != HTTP_CON) && http_rfile) { /* Remote file is URL? */
  7583.  
  7584.     /* All-in-one actions when a URL is given... */
  7585.  
  7586. #ifdef CK_URL
  7587.     if (urlparse(http_rfile,&http_url) > 0) { /* Have URL? */
  7588.         if (ckstrcmp(http_url.svc,"http",-1,0) && /* It's an HTTP URL? */
  7589.         ckstrcmp(http_url.svc,"https",-1,0)) {
  7590.         printf("?Non-HTTP URL\n");
  7591.         x = -9;
  7592.         goto xhttp;
  7593.         } else {            /* Yes, collect the pieces */
  7594.         makestr(&http_srv, http_url.svc);
  7595.         makestr(&http_user,http_url.usr);
  7596.         makestr(&http_pass,http_url.psw);
  7597.         makestr(&http_host,http_url.hos);
  7598.         if (http_url.por)
  7599.           makestr(&http_srv,http_url.por);
  7600.         makestr(&http_rfile,http_url.pth);
  7601.         }
  7602.         if (!http_rfile) {        /* Still have a path? */
  7603.                 makestr(&http_rfile,"/");
  7604.         }
  7605.         if (!ckstrcmp("https",http_srv,-1,0) || /* Check for SSL/TLS */
  7606.         !ckstrcmp("443",http_srv,-1,0))
  7607.           http_ssl = 1;
  7608.         if (http_isconnected())    /* Close any open HTTP connection */
  7609.           http_close();
  7610.         if (http_pass == NULL && http_d_pass != NULL)
  7611.           makestr(&http_pass,http_d_pass);
  7612.         x = (http_open(http_host,
  7613.                http_srv,http_ssl,rdns,128,http_d_agent) == 0);
  7614.         if (x < 0) {
  7615.         x = 0;
  7616.         goto xhttp;
  7617.         }
  7618.         allinone = 1;
  7619.     }
  7620. #endif /* CK_URL */
  7621.         if (http_pass == NULL && http_d_pass != NULL)
  7622.       makestr(&http_pass,http_d_pass);
  7623.  
  7624.     if (http_action == HTTP_OPN && allinone) {
  7625.         http_action = HTTP_GET;
  7626.     }
  7627.         x = xdohttp(http_action,
  7628.                     http_lfile,
  7629.             http_rfile,
  7630.                     http_dfile,
  7631.             http_agent ? http_agent : http_d_agent,
  7632.             http_hdr,
  7633.             http_user  ? http_user  : http_d_user,
  7634.             http_pass  ? http_pass  : http_d_pass,
  7635.             http_mime,
  7636.             http_array,
  7637.             http_type
  7638.             );
  7639.     if (allinone)
  7640.       x = (http_close() == 0);
  7641.     }
  7642.  
  7643.   xhttp:
  7644.     if (http_agent) free(http_agent);
  7645.     if (http_hdr)   free(http_hdr);
  7646.     if (http_user)  free(http_user);
  7647.     if (http_pass) {
  7648.         memset(http_pass,0,strlen(http_pass));
  7649.         free(http_pass);
  7650.     }
  7651.     if (http_mime)  free(http_mime);
  7652.     if (http_lfile) free(http_lfile);
  7653.     if (http_rfile) free(http_rfile);
  7654.     if (http_dfile) free(http_dfile);
  7655.     if (http_host)  free(http_host);
  7656.     if (http_srv)   free(http_srv);
  7657.  
  7658.     if (x > -1)
  7659.       success = x;
  7660.     return(x);
  7661. }
  7662. #endif /* TCPSOCKET */
  7663. #endif /* NOHTTP */
  7664.  
  7665.  
  7666. #ifndef NOSPL
  7667. static int
  7668. dotrace() {
  7669.     int on = 1;
  7670.     struct FDB sw, kw;
  7671.     cmfdbi(&sw,                /* 1st FDB - switch */
  7672.        _CMKEY,            /* fcode */
  7673.        "Trace object;\n Or switch", /* help */
  7674.        "",                /* default */
  7675.        "",                /* addtl string data */
  7676.        2,                /* keyword table size */
  7677.        4,                /* addtl numeric data 2: 4 = cmswi */
  7678.        xxstring,            /* Processing function */
  7679.        onoffsw,            /* Keyword table */
  7680.        &kw                /* Pointer to next FDB */
  7681.        );
  7682.     cmfdbi(&kw,                /* 2nd FDB - Trace object */
  7683.        _CMKEY,            /* fcode */
  7684.        "Trace object",        /* help */
  7685.        "all",            /* default */
  7686.        "",                /* addtl string data */
  7687.        ntracetab,            /* keyword table size */
  7688.        0,                /* addtl numeric data 2: 0 = keyword */
  7689.        xxstring,            /* Processing function */
  7690.        tracetab,            /* Keyword table */
  7691.        NULL                /* Pointer to next FDB */
  7692.        );
  7693.     if ((x = cmfdb(&sw)) < 0)
  7694.       return(x);
  7695.     if (cmresult.fdbaddr == &sw) {
  7696.     on = cmresult.nresult;
  7697.     if ((x = cmkey(tracetab, ntracetab,"","all",xxstring)) < 0)
  7698.       return(x);
  7699.     } else {
  7700.     x = cmresult.nresult;
  7701.     }
  7702.     if ((y = cmcfm()) < 0)
  7703.       return(y);
  7704.  
  7705.     switch (x) {
  7706.       case TRA_ASG:
  7707.     tra_asg = on;
  7708.     break;
  7709.       case TRA_CMD:
  7710.     tra_cmd = on;
  7711.     break;
  7712.       case TRA_ALL:
  7713.     tra_asg = on;
  7714.     tra_cmd = on;
  7715.     break;
  7716.       default:
  7717.     return(-2);
  7718.     }
  7719.     printf("TRACE %s\n", on ? "ON" : "OFF");
  7720.     return(success = 1);
  7721. }
  7722. #endif /* NOSPL */
  7723.  
  7724.  
  7725. static int
  7726. doprompt() {
  7727.     extern int xcmdsrc;
  7728.     if ((x = cmtxt("Optional message","",&s,xxstring)) < 0)
  7729.       return(x);
  7730. #ifdef NOSPL
  7731.     printf("?Sorry, PROMPT requires script programming language\n");
  7732.     return(-9);
  7733. #else
  7734.     debug(F101,"Prompt cmdlvl","",cmdlvl);
  7735.     cmdlvl++;
  7736.     if (cmdlvl > CMDSTKL) {
  7737.     printf("?Command stack overflow: %d\n",cmdlvl);
  7738.     cmdlvl--;
  7739.     return(-9);
  7740.     }
  7741.     xcmdsrc = CMD_KB;
  7742.     cmdstk[cmdlvl].src = CMD_KB;    /* Say we're at the prompt */
  7743.     cmdstk[cmdlvl].lvl = 0;
  7744.     cmdstk[cmdlvl].ccflgs = cmdstk[cmdlvl-1].ccflgs;
  7745.     if (tra_cmd)
  7746.       printf("[%d] +P: \"(prompt)\"\n",cmdlvl);
  7747.     concb((char)escape);
  7748.     if (!quiet)
  7749.       printf(
  7750. "(Recursive command prompt: Resume script with CONTINUE, STOP to stop...)\n"
  7751.             );
  7752.     if (*s) {                /* If prompt given */
  7753.     makestr(&(prstring[cmdlvl-1]),cmgetp()); /* Save current prompt */
  7754.     cmsetp(s);            /* Set new one */
  7755.     }
  7756.     return(success = 1);
  7757. #endif /* NOSPL */
  7758. }
  7759.  
  7760. #ifdef CKLEARN
  7761. VOID
  7762. learncmd(s) char *s; {            /* Record commands in learned script */
  7763.     char buf[64];
  7764.     int i, k;
  7765.     if (learnfp && learning) {        /* Only if open and on */
  7766.     k = ckstrncpy(buf,s,64);
  7767.     for (i = 0; i < k; i++) {    /* Get top-level command keyword */
  7768.         if (buf[i] <= SP) {
  7769.         buf[i] = NUL;
  7770.         break;
  7771.         }
  7772.     }
  7773.     k = lookup(cmdtab,buf,ncmd,NULL); /* Look it up */
  7774.     if (k == XXCON || k == XXLEARN)      /* Don't record CONNECT or LEARN */
  7775.       return;
  7776.     if (k == XXTEL) {
  7777.         fputs("SET HOST /NETWORK:TCP",learnfp);
  7778.         fputs(&s[i],learnfp);
  7779.         fputs(" TELNET /TELNET",learnfp);
  7780.         fputs("\nIF FAIL STOP 1 Connection failed\n",learnfp);
  7781.     } else {
  7782.         fputs(s,learnfp);
  7783.         fputs("\n",learnfp);
  7784.     }
  7785.     }
  7786. }
  7787. #endif /* CKLEARN */
  7788.  
  7789.  
  7790. /*  D O C M D  --  Do a command  */
  7791.  
  7792. /*
  7793.  Returns:
  7794.    -2: user typed an illegal command
  7795.    -1: reparse needed
  7796.     0: parse was successful (even tho command may have failed).
  7797. */
  7798. #ifdef DEBUG
  7799. int cmdstats[256] = { -1, -1 };
  7800. #endif /* DEBUG */
  7801.  
  7802. int
  7803. docmd(cx) int cx; {
  7804.     extern int nolocal, cmkwflgs;
  7805.  
  7806.     debug(F101,"docmd entry, cx","",cx);
  7807.     activecmd = cx;
  7808.     doconx = ((activecmd == XXCON)  || (activecmd == XXTEL) ||
  7809.           (activecmd == XXRLOG) || (activecmd == XXPIPE) ||
  7810.               (activecmd == XXIKSD) || (activecmd == XXPTY));
  7811. /*
  7812.   Originally all commands were handled with a big switch() statement,
  7813.   but eventually this started blowing up compilers.  Now we have a series
  7814.   of separate if statements and small switches, with the commands that are
  7815.   most commonly executed in scipts and loops coming first, to speed up
  7816.   compute-bound scripts.
  7817.   */
  7818.  
  7819. #ifdef DEBUG
  7820.     if (cmdstats[0] == -1) {        /* Count commands */
  7821.     int i;                /* for tuning... */
  7822.     for (i = 0; i < 256; i++)
  7823.       cmdstats[i] = 0;
  7824.     }
  7825. #endif /* DEBUG */
  7826.  
  7827.     switch (cx) {
  7828.       case -4:                /* EOF */
  7829. #ifdef OSK
  7830.     if (msgflg)  printf("\n");
  7831. #else
  7832.     if (msgflg)  printf("\r\n");
  7833. #endif /* OSK */
  7834.       doexit(GOOD_EXIT,xitsta);
  7835.       case -3:                /* Null command */
  7836.     return(0);
  7837.       case -9:                /* Like -2, but errmsg already done */
  7838.       case -1:                /* Reparse needed */
  7839.     return(cx);
  7840.       case -6:                /* Special */
  7841.       case -2:                /* Error, maybe */
  7842.  
  7843. #ifndef NOSPL
  7844. /*
  7845.   Maybe they typed a macro name.  Let's look it up and see.
  7846. */
  7847.     if (cx == -6)            /* If they typed CR */
  7848.       ckstrncat(cmdbuf,"\015",CMDBL); /*  add it back to command buffer. */
  7849.     if (ifcmd[cmdlvl] == 2)        /* Watch out for IF commands. */
  7850.       ifcmd[cmdlvl]--;
  7851.     repars = 1;            /* Force reparse */
  7852.     cmres();
  7853.     cx = XXDO;            /* Try DO command */
  7854. #else
  7855.     return(cx);
  7856. #endif /* NOSPL */
  7857.       default:
  7858.     if (cx < 0)
  7859.       return(cx);
  7860.     break;
  7861.     }
  7862. #ifdef DEBUG
  7863.     if (cx < 256)
  7864.       cmdstats[cx]++;
  7865. #endif /* DEBUG */
  7866.  
  7867.     if ((cmkwflgs & CM_PSH)
  7868. #ifndef NOPUSH
  7869.     && nopush
  7870. #endif /* NOPUSH */
  7871.     ) {
  7872.     printf("?Access to system disabled\n");
  7873.     return(-9);
  7874.     }
  7875.     if ((cmkwflgs & CM_LOC)
  7876. #ifndef NOLOCAL
  7877.     && nolocal
  7878. #endif /* NOLOCAL */
  7879.     ) {
  7880.     printf("?Connections disabled\n");
  7881.     return(-9);
  7882.     }
  7883.  
  7884. #ifndef NOSPL
  7885.     /* Used in FOR loops */
  7886.  
  7887.     if (cx == XX_INCR || cx == XXINC  || /* _INCREMENT, INCREMENT */
  7888.     cx == XX_DECR || cx == XXDEC)     /* _DECREMENT, DECREMENT */
  7889.       return(doincr(cx));
  7890.  
  7891.     /* Define (or change the definition of) a macro or variable */
  7892.  
  7893.     if (cx == XXUNDEF || cx == XXUNDFX) {
  7894. #ifdef IKSD
  7895.     if (inserver && !ENABLED(en_asg)) {
  7896.         printf("?Sorry, DEFINE/ASSIGN disabled\n");
  7897.         return(-9);
  7898.     }
  7899. #endif /* IKSD */
  7900.     return(doundef(cx));        /* [_]UNDEFINE */
  7901.     }
  7902.     if (cx == XXDEF || cx == XXASS ||
  7903.     cx == XXDFX || cx == XXASX) {
  7904. #ifdef IKSD
  7905.     if (inserver && !ENABLED(en_asg)) {
  7906.         printf("?Sorry, DEFINE/ASSIGN disabled\n");
  7907.         return(-9);
  7908.     }
  7909. #endif /* IKSD */
  7910.     if (atmbuf[0] == '.' && !atmbuf[1]) /* "." entered as keyword */
  7911.       xxdot = 1;            /* i.e. with space after it... */
  7912.     return(dodef(cx));        /* DEFINE, ASSIGN, etc... */
  7913.     }
  7914.  
  7915.     /* IF, WHILE, and friends  */
  7916.  
  7917.     if (cx == XXIF || cx == XXIFX || cx == XXWHI || cx == XXASSER) {
  7918.     return(doif(cx));
  7919.     }
  7920.     if (cx == XXSWIT) {            /* SWITCH */
  7921.     return(doswitch());
  7922.     }
  7923.  
  7924.     /* GOTO, FORWARD, and _FORWARD (used internally by FOR, WHILE, etc) */
  7925.  
  7926.     if (cx == XXGOTO || cx == XXFWD || cx == XXXFWD) { /* GOTO or FORWARD */
  7927.     /* Note, here we don't set SUCCESS/FAILURE flag */
  7928. #ifdef COMMENT
  7929.     if ((y = cmfld("label","",&s,xxstring)) < 0) {
  7930.         if (y == -3) {
  7931.         if (cx != XXXFWD) {
  7932.             printf("?Label name required\n");
  7933.             return(-9);
  7934.         }
  7935.         } else
  7936.           return(y);
  7937.     }
  7938.     ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  7939.     if ((x = cmcfm()) < 0) return(x);
  7940. #else
  7941.     if ((y = cmtxt("label","",&s,xxstring)) < 0) {
  7942.         if (y == -3) {
  7943.         if (cx != XXXFWD) {
  7944.             printf("?GOTO: Label name required: \"%s\" \"%s\"\n",
  7945.                atmbuf,
  7946.                cmdbuf);
  7947.             return(-9);
  7948.         }
  7949.         } else
  7950.           return(y);
  7951.     }
  7952.     ckstrncpy(tmpbuf,brstrip(s),TMPBUFSIZ);
  7953. #endif /* COMMENT */
  7954.     s = tmpbuf;
  7955.     debug(F111,"GOTO target",s,cx);
  7956.     return(dogoto(s,cx));
  7957.     }
  7958.     if (cx == XXDO || cx == XXMACRO) {    /* DO (a macro) */
  7959.     char mnamebuf[16];        /* (buffer for controlled temp name) */
  7960.     struct FDB kw, fl;
  7961.     int mx;                /* Macro index (on stack!) */
  7962.  
  7963.     debug(F101,"XXMACRO 0",line,cx);
  7964.     if (cx == XXDO) {
  7965.         if (nmac == 0) {
  7966.         printf("\n?No macros defined\n");
  7967.         return(-9);
  7968.         }
  7969.         for (y = 0; y < nmac; y++) { /* copy the macro table into a */
  7970.         mackey[y].kwd = mactab[y].kwd; /* regular keyword table */
  7971.         mackey[y].kwval = y;    /* with value = pointer to macro tbl */
  7972.         mackey[y].flgs = mactab[y].flgs;
  7973.         }
  7974.         cmfdbi(&kw,            /* First FDB - macro name */
  7975.            _CMKEY,        /* fcode */
  7976.            "Macro",        /* hlpmsg */
  7977.            "",            /* default */
  7978.            "",            /* addtl string data */
  7979.            nmac,        /* addtl numeric data 1: tbl size */
  7980.            0,            /* addtl numeric data 2: 0 = cmkey */
  7981.            xxstring,        /* Processing function */
  7982.            mackey,        /* Keyword table */
  7983.            &fl            /* Pointer to next FDB */
  7984.            );
  7985.         cmfdbi(&fl,            /* 2nd FDB - for "{" */
  7986.            _CMFLD,        /* fcode */
  7987.            "",            /* hlpmsg */
  7988.            "",
  7989.            "",            /* addtl string data */
  7990.            0,            /* addtl numeric data 1 */
  7991.            0,            /* addtl numeric data 2 */
  7992.            xxstring,
  7993.            NULL,
  7994.            NULL
  7995.            );
  7996.         x = cmfdb(&kw);        /* Parse something */
  7997.         if (x < 0) {        /* Error */
  7998.         if (x == -3) {
  7999.             printf("?Macro name required\n");
  8000.             return(-9);
  8001.         } else
  8002.           return(x);
  8003.         }
  8004.         if (cmresult.fcode == _CMKEY) {
  8005.         extern int mtchanged;
  8006.         char * macroname = NULL;
  8007.  
  8008.         /* In case args include an \fexec() that changes the macro table */
  8009.  
  8010.         mx = x;            /* Save macro index on stack */
  8011.         mtchanged = 0;        /* Mark state of macro table */
  8012.         makestr(¯oname,mactab[mx].kwd); /* Save name */
  8013.  
  8014.         if ((y = cmtxt("optional arguments","",&s,xxstring)) < 0)
  8015.           return(y);        /* Get macro args */
  8016.  
  8017.         if (mtchanged) {    /* Macro table changed? */
  8018.             mx = mlook(mactab,macroname,nmac); /* Look up name again */
  8019.         }
  8020.         if (macroname)
  8021.           free(macroname);
  8022.  
  8023.         return(dodo(mx,s,cmdstk[cmdlvl].ccflgs) < 1 ?
  8024.                (success = 0) : 1);
  8025.         }
  8026.         ckstrncpy(line,cmresult.sresult,LINBUFSIZ);    /* _CMFLD */
  8027.         if (atmbuf[0] == '{') {
  8028.         if ((y = cmcfm()) < 0)
  8029.           return(y);
  8030.         }
  8031.     } else {            /* XXMACRO ("immediate macro") */
  8032.         int k = 0;
  8033.         line[k++] = '{';
  8034.         line[k++] = SP;
  8035.         line[k] = NUL;
  8036.         debug(F111,"XXMACRO A",line,k);
  8037.         if ((y = cmtxt("Braced list of commands","",&s,xxstring)) < 0)
  8038.           return(y);
  8039.         k = ckstrncpy(line+k,s,LINBUFSIZ-k);
  8040.         debug(F111,"XXMACRO B",line,k);
  8041.     }
  8042.     x = strlen(line);
  8043.     if ((line[0] == '{' && line[x-1] != '}') || line[0] == '}')
  8044.       return(-2);
  8045.     if (line[0] != '{' && line[x-1] != '}') {
  8046.         /* Unknown command.  If ON_UNKNOWN_COMMAND macro is defined, */
  8047.         /* parse args and then execute it, but only if it is not */
  8048.         /* already active. */
  8049.         int k = -1;
  8050.         if (!unkmacro) {
  8051.         k = mxlook(mactab,"on_unknown_command",nmac);
  8052.         }
  8053.         if (k > -1) {
  8054.         ckstrncpy(tmpbuf,atmbuf,TMPBUFSIZ);
  8055.         z = maclvl;        /* Save the current maclvl */
  8056.         if ((y = cmtxt("text","",&s,xxstring)) < 0)
  8057.           return(y);
  8058.         ckstrncat(tmpbuf," ",TMPBUFSIZ);
  8059.         ckstrncat(tmpbuf,s,TMPBUFSIZ);
  8060.         unkmacro = 1;
  8061.         debug(F110,"ON_UNKNOWN_COMMAND",s,0);
  8062.         dodo(k,tmpbuf,cmdstk[cmdlvl].ccflgs); /* Run the macro */
  8063.         while (maclvl > z) {
  8064.             sstate = (CHAR) parser(1);
  8065.             if (sstate) proto();
  8066.         }
  8067.         debug(F101,"UNKMAC loop exit maclvl","",maclvl);
  8068.         unkmacro = 0;
  8069.         return(success);
  8070.         }
  8071.             if (x > 0)
  8072.           printf("?Not a command or macro name: \"%s\"\n",line);
  8073.             else
  8074.           printf("?Not a command or macro name.\n");
  8075.         return(-9);
  8076.     }
  8077.     s = brstrip(line);
  8078.     sprintf(mnamebuf," ..tmp:%03d",cmdlvl);    /* safe (16) */
  8079.     x = addmac(mnamebuf,s);
  8080.     return(dodo(x,NULL,cmdstk[cmdlvl].ccflgs) < 1 ? (success = 0) : 1);
  8081.     }
  8082.  
  8083.     if (cx == XXLBL) {            /* LABEL */
  8084.     if ((x = cmfld("label","",&s,xxstring)) < 0) {
  8085.         if (x == -3) {
  8086. #ifdef COMMENT
  8087.         printf("?LABEL: Label name required: \"%s\"\n", cmdbuf);
  8088.         return(-9);
  8089. #else
  8090.         s = "";
  8091. #endif /* COMMENT */
  8092.         } else return(x);
  8093.  
  8094.     }
  8095.     debug(F111,"LABEL",s,x);
  8096.     if ((x = cmcfm()) < 0) return(x);
  8097.     return(0);
  8098.     }
  8099.  
  8100.     if (cx == XXEVAL || cx == XX_EVAL) /* _EVALUATE,  EVALUATE  */
  8101.       return(doeval(cx));
  8102.  
  8103. #ifndef NOSEXP
  8104.     if (cx == XXSEXP) {            /* Lisp-like S-Expression */
  8105.     struct stringarray * q;
  8106.     char /* *p, *r, */ *tmp, *m;
  8107.     int i, k, n, quote = 0, contd = 0, size = 0, len = 0;
  8108.     extern int sexprc, sexppv;
  8109.  
  8110.     tmp = tmpbuf;            /* Buffer to collect SEXP */
  8111.     tmpbuf[0] = NUL;        /* Clear it */
  8112.     size = TMPBUFSIZ;        /* Capacity of buffer */
  8113.     sexprc = -1;            /* Assume bad input */
  8114.     n = 0;                /* Paren balance counter */
  8115.  
  8116.     while (1) {            /* Allow SEXP on multiple lines */
  8117.         m = contd ?
  8118.           "Continuation of S-Expression" :
  8119.         "S-Expression (\"help sexp\" for details)";
  8120.         x = cmtxt(m,"",&s,xxstring);
  8121.         if (x < 0)
  8122.           return(x);
  8123.         if (!*s)            /* Needed for (=) and (:) */
  8124.           s = cmdbuf+1;        /* I can't explain why. */
  8125.         k = ckmakmsg(tmp, size, contd ? " " : "(", s, NULL, NULL);
  8126.         if (k < 1) {
  8127.         printf("?SEXP too long - %d max\n",TMPBUFSIZ);
  8128.         return(-9);
  8129.         }
  8130.         debug(F111,contd ? "sexp contd" : "sexp",s,k);
  8131.  
  8132.         for (i = len; i < len+k; i++) { /* Check balance  */
  8133.         if (!quote && tmpbuf[i] == CMDQ) {
  8134.             quote = 1;
  8135.             continue;
  8136.         }
  8137.         if (quote) {
  8138.             quote = 0;
  8139.             continue;
  8140.         }
  8141.         if (tmpbuf[i] == '(')
  8142.           n++;
  8143.         else if (tmpbuf[i] == ')')
  8144.           n--;
  8145.         }
  8146.         if (n == 0) {        /* Break when balanced */
  8147.         break;
  8148.         }
  8149.         if (n < 0) {        /* Too many right parens */
  8150.         printf("?Unbalanced S-Expression: \"%s\"\n",tmpbuf);
  8151.         return(-9);
  8152.         }
  8153.         contd++;            /* Need more right parens */
  8154.         cmini(ckxech);        /* so keep parsing */
  8155.         tmp += k;            /* adjust buffer pointer */
  8156.         size -= k;            /* and capacity */
  8157.         len += k;            /* and length so far */
  8158.     }
  8159.     s = tmpbuf;
  8160.     makestr(&lastsexp,s);
  8161.     q = cksplit(1,SEXPMAX,s,NULL,NULL,8,0,0); /* Precheck for > 1 SEXP */
  8162.     debug(F101,"sexp split","",q->a_size);
  8163.  
  8164.     if (q->a_size == 1) {        /* We should get exactly one back */
  8165.         char * result, * dosexp();
  8166.         sexprc = 0;            /* Reset out-of-band return code */
  8167.         result = dosexp(s);        /* Get result */
  8168.         debug(F111,"sexp result",result,sexprc);
  8169.         if (sexprc == 0) {        /* Success */
  8170.         /* Echo the result if desired */
  8171.         if ((!xcmdsrc && sexpecho != SET_OFF) || sexpecho == SET_ON)
  8172.           printf(" %s\n",result ? result : "");
  8173.         makestr(&sexpval,result);
  8174.         success = sexppv > -1 ? sexppv : 1;
  8175.         return(success);
  8176.         }
  8177.     }
  8178.     if (sexprc < 0)
  8179.       printf("?Invalid S-Expression: \"%s\"\n",lastsexp);
  8180.     return(-9);
  8181.     }
  8182. #endif /* NOSEXP */
  8183.  
  8184. #endif /* NOSPL */
  8185.  
  8186.     if (cx == XXECH || cx == XXXECH || cx == XXVOID
  8187. #ifndef NOSPL
  8188.     || cx == XXAPC
  8189. #endif /* NOSPL */
  8190.     ) {                /* ECHO or APC */
  8191.     if ((x = cmtxt((cx == XXECH || cx == XXXECH) ?
  8192.                "Text to be echoed" :
  8193.                ((cx == XXVOID) ? "Text" :
  8194.             "Application Program Command text"),
  8195.                "",
  8196.                &s,
  8197.                xxstring
  8198.                )
  8199.          ) < 0)
  8200.       return(x);
  8201.     if (!s) s = "";
  8202. #ifdef COMMENT
  8203. /* This is to preserver the pre-8.0 behavior but it's too confusing */
  8204.     x = strlen(s);
  8205.     x = (x > 1) ? ((s[0] == '"' && s[x-1] == '"') ? 1 : 0) : 0;
  8206. #endif /* COMMENT */
  8207.     s = brstrip(s);            /* Strip braces and doublequotes */
  8208.     if (cx == XXECH) {        /* ECHO */
  8209. #ifndef NOSPL
  8210.         if (!fndiags || fnsuccess) {
  8211. #endif /* NOSPL */
  8212. #ifdef COMMENT
  8213.         /* The "if (x)" business preserves previous behavior */
  8214.         /* by putting back the doublequotes if they were included. */
  8215.         if (x)
  8216.           printf("\"%s\"\n",s);
  8217.         else
  8218. #endif /* COMMENT */
  8219.           printf("%s\n",s);
  8220. #ifndef NOSPL
  8221.         }
  8222. #endif /* NOSPL */
  8223.     } else if (cx == XXXECH) {    /* XECHO */
  8224.         if (x)
  8225.           printf("\"%s\"",s);
  8226.         else
  8227.           printf("%s",s);
  8228. #ifdef UNIX
  8229.         fflush(stdout);
  8230. #endif /* UNIX */
  8231.     } else if (cx == XXAPC) {    /* APC */
  8232. #ifdef CK_APC
  8233.         if (apcactive == APC_LOCAL ||
  8234.         (apcactive == APC_REMOTE && !(apcstatus & APC_UNCH)))
  8235.           return(success = 0);
  8236. #endif /* CK_APC */
  8237.         if (!local) {
  8238.         printf("%c_%s%c\\",ESC,s,ESC);
  8239. #ifdef UNIX
  8240.         fflush(stdout);
  8241. #endif /* UNIX */
  8242.  
  8243.         } else {            /* Local mode - have connection */
  8244. #ifndef NOSPL
  8245.         if (ckmakxmsg(tmpbuf,    /* Form APC string in buffer */
  8246.                   TMPBUFSIZ,
  8247.                   ckctoa((char)ESC),
  8248.                   ckctoa('_'),
  8249.                   s,
  8250.                   ckctoa((char)ESC),
  8251.                   ckctoa('\\'),
  8252.                   NULL,NULL,NULL,NULL,NULL,NULL,NULL
  8253.                   ) > 0)
  8254.           return(success = dooutput(tmpbuf, XXOUT));
  8255.         printf("?Too long\n");
  8256.         return(-9);
  8257. #else
  8258.         printf("%c_%s%c\\",ESC,s,ESC);
  8259. #endif /* NOSPL */
  8260.         }
  8261.     }
  8262.     return(success = 1);
  8263.     }
  8264.  
  8265. #ifndef NOSPL
  8266. /* Copy macro args from/to two levels up, used internally by _floop et al. */
  8267.     if (cx == XXGTA || cx == XXPTA) {    /* _GETARGS, _PUTARGS */
  8268.     int x;
  8269.     debug(F101,"docmd XXGTA","",XXGTA);
  8270.     debug(F101,"docmd cx","",cx);
  8271.     debug(F101,"docmd XXGTA maclvl","",maclvl);
  8272.     x = dogta(cx);
  8273.     debug(F101,"docmd dogta returns","",x);
  8274.     debug(F101,"docmd dogta maclvl","",maclvl);
  8275.     return(x);
  8276.     }
  8277. #endif /* NOSPL */
  8278.  
  8279. #ifndef NOSPL
  8280. #ifdef CKCHANNELIO
  8281.     if (cx == XXFILE)
  8282.       return(dofile(cx));
  8283.     else if (cx == XXF_RE || cx == XXF_WR || cx == XXF_OP ||
  8284.          cx == XXF_CL || cx == XXF_SE || cx == XXF_RW ||
  8285.          cx == XXF_FL || cx == XXF_LI || cx == XXF_ST || cx == XXF_CO)
  8286.       return(dofile(cx));
  8287. #endif /* CKCHANNELIO */
  8288.  
  8289. /* ASK, ASKQ, READ */
  8290.     if (cx == XXASK  || cx == XXASKQ || cx == XXREA ||
  8291.     cx == XXRDBL || cx == XXGETC || cx == XXGETK) {
  8292.     return(doask(cx));
  8293.     }
  8294. #endif /* NOSPL */
  8295.  
  8296. #ifndef NOFRILLS
  8297.     if (cx == XXBUG) {            /* BUG */
  8298.     if ((x = cmcfm()) < 0) return(x);
  8299.     return(dobug());
  8300.     }
  8301. #endif /* NOFRILLS */
  8302.  
  8303. #ifndef NOXFER
  8304.     if (cx == XXBYE) {            /* BYE */
  8305.     extern int ftp_cmdlin;
  8306.     if ((x = cmcfm()) < 0) return(x);
  8307.  
  8308. #ifdef NEWFTP
  8309.     if ((ftpget == 1) || ((ftpget == 2) && ftpisopen())) {
  8310.         extern int stayflg, ftp_fai;
  8311.         success = ftpbye();
  8312.         if (ftp_cmdlin && !stayflg && !local)
  8313.           doexit(ftp_fai ? BAD_EXIT : GOOD_EXIT,-1);
  8314.         else
  8315.           return(success);
  8316.     }
  8317. #endif /* NEWFTP */
  8318.  
  8319.     if (!local) {
  8320.         printf("?No connection - use EXIT to quit.\n");
  8321.         return(-9);
  8322.     }
  8323.  
  8324. #ifdef CK_XYZ
  8325.     if (protocol != PROTO_K) {
  8326.         printf("?Sorry, BYE only works with Kermit protocol\n");
  8327.         return(-9);
  8328.     }
  8329. #endif /* CK_XYZ */
  8330.  
  8331. #ifdef IKS_OPTION
  8332.         if (
  8333. #ifdef CK_XYZ
  8334.             protocol == PROTO_K &&
  8335. #endif /* CK_XYZ */
  8336.             !iks_wait(KERMIT_REQ_START,1)) {
  8337.         printf(
  8338.          "?A Kermit Server is not available to process this command\n");
  8339.         return(-9);            /* Correct the return code */
  8340.         }
  8341. #endif /* IKS_OPTION */
  8342.  
  8343.     bye_active = 1;
  8344.     sstate = setgen('L',"","","");
  8345.     if (local) ttflui();        /* If local, flush tty input buffer */
  8346.     return(0);
  8347.     }
  8348. #endif /* NOXFER */
  8349.  
  8350.     if (cx == XXBEEP) {            /* BEEP */
  8351.         int x;
  8352. #ifdef OS2
  8353.     int y;
  8354.         if ((y = cmkey(beeptab, nbeeptab, "which kind of beep", "information",
  8355.                xxstring)) < 0 )
  8356.       return (y);
  8357.         if ((x = cmcfm()) < 0) return(x);
  8358.         bleep((short)y);        /* y is one of the BP_ values */
  8359. #else  /* OS2 */
  8360.         if ((x = cmcfm()) < 0) return(x);
  8361. #ifndef NOSPL
  8362.         bleep(BP_NOTE);
  8363. #else
  8364.     putchar('\07');
  8365. #endif /* NOSPL */
  8366. #endif /* OS2 */
  8367.         return(0);
  8368.     }
  8369.  
  8370. #ifndef NOFRILLS
  8371.     if (cx == XXCLE)            /* CLEAR */
  8372.       return(success = doclear());
  8373. #endif /* NOFRILLS */
  8374.  
  8375.     if (cx == XXCOM) {            /* COMMENT */
  8376.     if ((x = cmtxt("Text of comment line","",&s,NULL)) < 0)
  8377.       return(x);
  8378.     /* Don't change SUCCESS flag for this one */
  8379.     return(0);
  8380.     }
  8381.  
  8382. #ifndef NOLOCAL
  8383.     if (cx == XXCON || cx == XXCQ)    /* CONNECT or CONNECT /QUIETLY */
  8384.       return(doxconn(cx));
  8385. #endif /* NOLOCAL */
  8386.  
  8387. #ifndef NOFRILLS
  8388. #ifdef ZCOPY
  8389.     if (cx == XXCPY) {            /* COPY a file */
  8390. #ifdef IKSD
  8391.     if (inserver && !ENABLED(en_cpy)) {
  8392.         printf("?Sorry, COPY is disabled\n");
  8393.         return(-9);
  8394.     }
  8395. #endif /* IKSD */
  8396. #ifdef CK_APC
  8397.     if (apcactive == APC_LOCAL ||
  8398.         (apcactive == APC_REMOTE && !(apcstatus & APC_UNCH))
  8399.         )
  8400.       return(success = 0);
  8401. #endif /* CK_APC */
  8402.     return(docopy());
  8403.     }
  8404. #endif /* ZCOPY */
  8405. #ifdef NT
  8406.     if ( cx == XXLINK ) {
  8407. #ifdef IKSD
  8408.         if (inserver && !ENABLED(en_cpy)) {
  8409.             printf("?Sorry, LINK (COPY) is disabled\n");
  8410.             return(-9);
  8411.         }
  8412. #endif /* IKSD */
  8413. #ifdef CK_APC
  8414.         if (apcactive == APC_LOCAL ||
  8415.             (apcactive == APC_REMOTE && !(apcstatus & APC_UNCH))
  8416.             )
  8417.           return(success = 0);
  8418. #endif /* CK_APC */
  8419.         return(dolink());
  8420.     }
  8421. #endif /* NT */
  8422. #endif /* NOFRILLS */
  8423.  
  8424.     /* CD and friends */
  8425.     if (cx == XXCWD  || cx == XXCDUP || cx == XXBACK ||
  8426.     cx == XXLCWD || cx == XXLCDU || cx == XXKCD) {
  8427. #ifdef LOCUS
  8428.     if (!locus) {
  8429.         if (cx == XXCWD) {
  8430. #ifdef NOXFER
  8431.                 return(-2);
  8432. #else
  8433.                 return(dormt(XZCWD));
  8434. #endif /* NOXFER */
  8435.         } else if (cx == XXCDUP) {
  8436. #ifdef NOXFER
  8437.                 return(-2);
  8438. #else
  8439.                 return(dormt(XZCDU));
  8440. #endif /* NOXFER */
  8441.             }
  8442.     }
  8443. #endif /* LOCUS */
  8444. #ifdef IKSD
  8445.     if (inserver && !ENABLED(en_cwd)) {
  8446.         printf("?Sorry, changing directories is disabled\n");
  8447.         return(-9);
  8448.     }
  8449. #endif /* IKSD */
  8450.     return(success = docd(cx));
  8451.     }
  8452.  
  8453.     if (cx == XXCHK)            /* CHECK */
  8454.       return(success = dochk());
  8455.  
  8456.     if (cx == XXCLO) {            /* CLOSE */
  8457.     x = cmkey(clstab,ncls,"\"CONNECTION\", or log or file to close",
  8458.           "connection",xxstring);
  8459.     if (x == -3) {
  8460.         printf("?You must say which file or log\n");
  8461.         return(-9);
  8462.     }
  8463.     if (x < 0) return(x);
  8464.     if ((y = cmcfm()) < 0) return(y);
  8465. #ifndef NOLOCAL
  8466.     if (x == 9999) {        /* CLOSE CONNECTION */
  8467.         x = clsconnx(0);
  8468.         switch (x) {
  8469.           case 0:
  8470.         if (msgflg) printf("?Connection was not open\n");
  8471.           case -1:
  8472.         return(0);
  8473.           case 1:
  8474.         whyclosed = WC_CLOS;
  8475.         return(1);
  8476.         }
  8477.         return(0);
  8478.     }
  8479. #endif /* NOLOCAL */
  8480.     y = doclslog(x);
  8481.     success = (y == 1);
  8482.     return(success);
  8483.     }
  8484.  
  8485. #ifndef NOSPL
  8486.     if (cx == XXDCL || cx == XXUNDCL) {    /* DECLARE an array */
  8487.     return(dodcl(cx));
  8488.     }
  8489. #endif /* NOSPL */
  8490.  
  8491. #ifndef NODIAL
  8492.     if (cx == XXRED  || cx == XXDIAL || cx == XXPDIA ||
  8493.     cx == XXANSW || cx == XXLOOK) { /* DIAL, REDIAL etc */
  8494. #ifdef VMS
  8495.     extern int batch;
  8496. #else
  8497. #ifdef UNIXOROSK
  8498.     extern int backgrd;
  8499. #endif /* UNIXOROSK */
  8500. #endif /* VMS */
  8501.     x = dodial(cx);
  8502.     debug(F101,"dodial returns","",x);
  8503.     if ((cx == XXDIAL || cx == XXRED || cx == XXANSW) &&
  8504.         (x > 0) &&            /* If DIAL or REDIAL succeeded */
  8505.         (dialsta != DIA_PART) &&    /* and it wasn't partial */
  8506.         (dialcon > 0)) {
  8507.         if ((dialcon == 1 ||    /* And DIAL CONNECT is ON, */
  8508.         ((dialcon == 2) &&    /* or DIAL CONNECT is AUTO */
  8509.          !xcmdsrc        /* and we're at top level... */
  8510. #ifdef VMS
  8511.          && !batch        /* Not if running from batch */
  8512. #else
  8513. #ifdef UNIXOROSK
  8514.          && !backgrd        /* Not if running in background */
  8515. #endif /* UNIXOROSK */
  8516. #endif /* VMS */
  8517.          ))) /* Or AUTO */
  8518.           x = doconect(dialcq,    /* Then also CONNECT */
  8519.                            cmdlvl == 0 ? 1 : 0
  8520.                );
  8521.         if (ttchk() < 0)
  8522.           dologend();
  8523.     }
  8524.     return(success = x);
  8525.     }
  8526. #endif /* NODIAL */
  8527.  
  8528. #ifndef NOPUSH
  8529. #ifdef CK_REXX
  8530.     if (cx == XXREXX) {            /* REXX */
  8531.         extern int nopush;
  8532.         if ( nopush )
  8533.           return(success=0);
  8534.         return(dorexx());
  8535.     }
  8536. #endif /* CK_REXX */
  8537. #endif /* NOPUSH */
  8538.  
  8539. #ifndef NOFRILLS
  8540.     if (cx == XXDEL || cx == XXLDEL) {    /* DELETE */
  8541. #ifdef LOCUS
  8542.     if (!locus && cx != XXLDEL) {
  8543. #ifdef NOXFER
  8544.         return(-2);
  8545. #else
  8546.         return(dormt(XZDEL));
  8547. #endif /* NOXFER */
  8548.         }
  8549. #endif /* LOCUS */
  8550. #ifdef IKSD
  8551.     if (inserver && (!ENABLED(en_del)
  8552. #ifdef CK_LOGIN
  8553.              || isguest
  8554. #endif /* CK_LOGIN */
  8555.              )) {
  8556.         printf("?Sorry, DELETE is disabled\n");
  8557.         return(-9);
  8558.     }
  8559. #endif /* IKSD */
  8560. #ifdef CK_APC
  8561.     if ((apcactive == APC_LOCAL) ||
  8562.         ((apcactive == APC_REMOTE) && (!(apcstatus & APC_UNCH))))
  8563.       return(success = 0);
  8564. #endif /* CK_APC */
  8565.     return(dodel());
  8566.     }
  8567. #endif /* NOFRILLS */
  8568.  
  8569.     if (cx == XXTOUC)            /* TOUCH */
  8570.       return(dodir(cx));
  8571.  
  8572.     /* DIRECTORY commands */
  8573.  
  8574.     if (cx == XXDIR  || cx == XXLS || cx == XXLDIR ||
  8575.     cx == XXWDIR || cx == XXHDIR) {
  8576. #ifdef LOCUS
  8577.     if (!locus && cx != XXLDIR) {
  8578. #ifdef NOXFER
  8579.         return(-2);
  8580. #else
  8581.         return(dormt(XZDIR));
  8582. #endif /* NOXFER */
  8583.         }
  8584. #endif /* LOCUS */
  8585. #ifdef IKSD
  8586.     if (inserver && !ENABLED(en_dir)) {
  8587.         printf("?Sorry, DIRECTORY is disabled\n");
  8588.         return(-9);
  8589.     }
  8590. #endif /* IKSD */
  8591.     return(dodir(cx));
  8592.     }
  8593.  
  8594. #ifndef NOSPL
  8595.     if (cx == XXELS)            /* ELSE */
  8596.       return(doelse());
  8597. #endif /* NOSPL */
  8598.  
  8599. #ifndef NOSERVER
  8600. #ifndef NOFRILLS
  8601.     if (cx == XXENA || cx == XXDIS) {    /* ENABLE, DISABLE */
  8602.     s = (cx == XXENA) ?
  8603.       "Server function to enable" :
  8604.         "Server function to disable";
  8605.  
  8606.     if ((x = cmkey(enatab,nena,s,"",xxstring)) < 0) {
  8607.         if (x == -3) {
  8608.         printf("?Name of server function required\n");
  8609.         return(-9);
  8610.         } else return(x);
  8611.     }
  8612.     if ((y = cmkey(kmstab,3,"mode","both",xxstring)) < 0) {
  8613.         if (y == -3) {
  8614.         printf("?Please specify remote, local, or both\n");
  8615.         return(-9);
  8616.         } else return(y);
  8617.     }
  8618.     if (cx == XXDIS)        /* Disabling, not enabling */
  8619.       y = 3 - y;
  8620.     if ((z = cmcfm()) < 0) return(z);
  8621. #ifdef CK_APC
  8622.     if ((apcactive == APC_LOCAL) ||
  8623.         ((apcactive == APC_REMOTE) && (!(apcstatus & APC_UNCH))))
  8624.       return(success = 0);
  8625. #endif /* CK_APC */
  8626. #ifdef IKSD
  8627.         /* This may seem like it duplicates the work in doenable()  */
  8628.         /* but this code returns failure whereas doenable() returns */
  8629.         /* success.                                                 */
  8630.         if (inserver &&
  8631. #ifdef IKSDCONF
  8632.             iksdcf &&
  8633. #endif /* IKSDCONF */
  8634.             (x == EN_HOS || x == EN_PRI || x == EN_MAI || x == EN_WHO ||
  8635.               isguest))
  8636.             return(success = 0);
  8637. #endif /* IKSD */
  8638.     return(doenable(y,x));
  8639.     }
  8640. #endif /* NOFRILLS */
  8641. #endif /* NOSERVER */
  8642.  
  8643. #ifndef NOSPL
  8644.     if (cx == XXRET) {            /* RETURN */
  8645.     if ((x = cmtxt("Optional return value","",&s,NULL)) < 0)
  8646.       return(x);
  8647.     s = brstrip(s);            /* Strip braces */
  8648.     if (cmdlvl == 0)        /* At top level, nothing happens... */
  8649.       return(success = 1);
  8650.     switch (cmdstk[cmdlvl].src) {    /* Action depends on command source */
  8651.       case CMD_TF:            /* Command file */
  8652.         popclvl();            /* Pop command level */
  8653.         return(success = 1);    /* always succeeds */
  8654.       case CMD_MD:            /* Macro */
  8655.       case CMD_KB:            /* Prompt */
  8656.         return(doreturn(s));    /* Trailing text is return value. */
  8657.       default:            /* Shouldn't happen */
  8658.         return(-2);
  8659.     }
  8660.     }
  8661. #endif /* NOSPL */
  8662.  
  8663. #ifndef NOSPL
  8664.     if (cx == XXOPE)            /* OPEN */
  8665.       return(doopen());
  8666. #endif /* NOSPL */
  8667.  
  8668. #ifndef NOSPL
  8669.     if (cx == XXOUT || cx == XXLNOUT) {    /* OUTPUT or LINEOUT */
  8670.     if ((x = cmtxt("Text to be output","",&s,NULL)) < 0)
  8671.       return(x);
  8672. #ifdef CK_APC
  8673.     if ((apcactive == APC_LOCAL) ||
  8674.         ((apcactive == APC_REMOTE) && (!(apcstatus & APC_UNCH))))
  8675.       return(success = 0);
  8676. #endif /* CK_APC */
  8677.     debug(F110,"OUTPUT 1",s,0);
  8678.     s = brstrip(s);            /* Strip enclosing braces, */
  8679.     debug(F110,"OUTPUT 2",s,0);
  8680. /*
  8681.   I don't think I could ever fully explain this in a million years...
  8682.   We have read the user's string without calling the variable-expander
  8683.   function.  Now, before we call it, we have to double backslashes that
  8684.   appear before \N, \B, \L, and \ itself, so the expander function will
  8685.   reduce them back to single backslashes, so when we call dooutput()...
  8686.   But it's more complicated than that.
  8687. */
  8688.     if (cmdgquo()) {        /* Only if COMMAND QUOTING ON ... */
  8689.         for (x = 0, y = 0; s[x]; x++, y++) {
  8690.         if (s[x] == CMDQ) {
  8691.             char c = s[x+1];
  8692.             if (c == 'n' || c == 'N' ||
  8693.             c == 'b' || c == 'B' ||
  8694.             c == 'l' || c == 'L' ||
  8695.             c == CMDQ)
  8696.               line[y++] = CMDQ;
  8697.         }
  8698.         line[y] = s[x];
  8699.         }
  8700.         line[y++] = '\0';        /* Now expand variables, etc. */
  8701.         debug(F110,"OUTPUT 3",line,0);
  8702.         s = line+y+1;
  8703.         x = LINBUFSIZ - (int) strlen(line) - 1;
  8704.         debug(F101,"OUTPUT size","",x);
  8705.         if (zzstring(line,&s,&x) < 0)
  8706.           return(success = 0);
  8707.         s = line+y+1;
  8708.         debug(F110,"OUTPUT 4",s,0);
  8709.     }
  8710.     success = dooutput(s,cx);
  8711.     return(success);
  8712.     }
  8713. #endif /* NOSPL */
  8714.  
  8715. #ifdef ANYX25
  8716. #ifndef IBMX25
  8717.     if (cx == XXPAD) {            /* PAD commands */
  8718.     x = cmkey(padtab,npadc,"PAD command","",xxstring);
  8719.     if (x == -3) {
  8720.         printf("?You must specify a PAD command to execute\n");
  8721.         return(-9);
  8722.     }
  8723.     if (x < 0) return(x);
  8724.  
  8725.     switch (x) {
  8726.       case XYPADL:
  8727.         if (x25stat() < 0)
  8728.           printf("Sorry, you must 'set network' & 'set host' first\r\n");
  8729.         else {
  8730.         x25clear();
  8731.         initpad();
  8732.         }
  8733.         break;
  8734.       case XYPADS:
  8735.         if (x25stat() < 0)
  8736.           printf("Not connected\r\n");
  8737.         else {
  8738.         extern int linkid, lcn;
  8739.         conol("Connected thru ");
  8740.         conol(ttname);
  8741.         printf(", Link id %d, Logical channel number %d\r\n",
  8742.                linkid,lcn);
  8743.         }
  8744.         break;
  8745.       case XYPADR:
  8746.         if (x25stat() < 0)
  8747.           printf("Sorry, you must 'set network' & 'set host' first\r\n");
  8748.         else
  8749.           x25reset(0,0);
  8750.         break;
  8751.       case XYPADI:
  8752.         if (x25stat() < 0)
  8753.           printf("Sorry, you must 'set network' & 'set host' first\r\n");
  8754.         else
  8755.           x25intr(0);
  8756.     }
  8757.     return(0);
  8758.     }
  8759. #endif /* IBMX25 */
  8760. #endif /* ANYX25 */
  8761.  
  8762. #ifndef NOSPL
  8763.     if (cx == XXPAU || cx == XXWAI || cx == XXMSL) /* PAUSE, WAIT, etc */
  8764.       return(dopaus(cx));
  8765. #endif /* NOSPL */
  8766.  
  8767. #ifndef NOFRILLS
  8768.     if (cx == XXPRI) {
  8769. #ifdef IKSD
  8770. #ifdef CK_LOGIN
  8771.     if (inserver && (isguest || !ENABLED(en_pri))) {
  8772.         printf("?Sorry, printing is disabled\n");
  8773.         return(-9);
  8774.     }
  8775. #endif /* CK_LOGIN */
  8776. #endif /* IKSD */
  8777.     if ((x = cmifi("File to print","",&s,&y,xxstring)) < 0) {
  8778.         if (x == -3) {
  8779.         printf("?A file specification is required\n");
  8780.         return(-9);
  8781.         } else return(x);
  8782.     }
  8783.     if (y != 0) {
  8784.         printf("?Wildcards not allowed\n");
  8785.         return(-9);
  8786.     }
  8787.     ckstrncpy(line,s,LINBUFSIZ);
  8788.     s = "";
  8789. #ifndef NT
  8790.     if ((x = cmtxt("Local print command options, or carriage return","",&s,
  8791.                xxstring)) < 0)
  8792.       return(x);
  8793. #endif /* NT */
  8794.     if ((x = cmcfm()) < 0)
  8795.       return(x);
  8796.     return(success = (zprint(s,line) == 0) ? 1 : 0);
  8797.     }
  8798. #endif /* NOFRILLS */
  8799.  
  8800. #ifdef TCPSOCKET
  8801. #ifndef NOPUSH
  8802.     if (cx == XXPNG)             /* PING an IP host */
  8803.       return(doping());
  8804. #endif /* NOPUSH */
  8805.  
  8806. #ifndef NOFTP
  8807.     if (cx == XXFTP)            /* FTP */
  8808. #ifdef SYSFTP
  8809. #ifndef NOPUSH
  8810.       return(doftp());            /* Just runs system's ftp program */
  8811. #else
  8812.       return(-2);
  8813. #endif /* NOPUSH */
  8814. #else
  8815.     return(doxftp());
  8816. #endif /* SYSFTP */
  8817. #endif /* NOFTP */
  8818. #endif /* TCPSOCKET */
  8819.  
  8820.     if (cx == XXPWD || cx == XXLPWD) {    /* PWD */
  8821. #ifdef OS2
  8822.     char *pwp;
  8823. #endif /* OS2 */
  8824.     if ((x = cmcfm()) < 0)
  8825.       return(x);
  8826. #ifdef LOCUS
  8827.     if (!locus && cx != XXLPWD) {
  8828. #ifdef NOXFER
  8829.         return(-2);
  8830. #else
  8831.         return(dormt(XZPWD));
  8832. #endif /* NOXFER */
  8833.         }
  8834. #endif /* LOCUS */
  8835.  
  8836. #ifndef MAC
  8837. #ifndef OS2
  8838. #ifdef UNIX
  8839.     printf("%s\n",zgtdir());
  8840. #else
  8841.     xsystem(PWDCMD);
  8842. #endif /* UNIX */
  8843.     return(success = 1);        /* Blind faith */
  8844. #else  /* OS2 */
  8845.     if (pwp = zgtdir()) {
  8846.         if (*pwp) {
  8847. #ifdef NT
  8848.         line[0] = NUL;
  8849.         ckGetLongPathName(pwp,line,LINBUFSIZ);
  8850.         line[LINBUFSIZ-1] = NUL;
  8851.         tmpbuf[0] = NUL;
  8852.         GetShortPathName(pwp,tmpbuf,TMPBUFSIZ);
  8853.         tmpbuf[TMPBUFSIZ-1] = NUL;
  8854.         pwp = line;
  8855.         if (!strcmp(line,tmpbuf)) {
  8856. #endif /* NT */
  8857.             printf("%s\n",pwp);
  8858. #ifdef NT
  8859.         } else {
  8860.             printf("  Long name:  %s\n",line);
  8861.             printf("  Short name: %s\n",tmpbuf);
  8862.         }            
  8863. #endif /* NT */
  8864.         }
  8865.         return(success = ((int)strlen(pwp) > 0));
  8866.     } else return(success = 0);
  8867. #endif /* OS2 */
  8868. #else  /* MAC */
  8869.     if (pwp = zgtdir()) {
  8870.         printf("%s\n",pwp);
  8871.         return(success = ((int)strlen(pwp) > 0));
  8872.     } else return(success = 0);
  8873. #endif /* MAC */
  8874.     }
  8875.  
  8876.     if (cx == XXQUI || cx == XXEXI) {    /* EXIT, QUIT */
  8877.     extern int quitting;
  8878.  
  8879.     if ((y = cmnum("exit status code",ckitoa(xitsta),10,&x,xxstring)) < 0)
  8880.       return(y);
  8881.     if ((y = cmtxt("Optional EXIT message","",&s,xxstring)) < 0)
  8882.       return(y);
  8883.     s = brstrip(s);
  8884.     ckstrncpy(line,s,LINBUFSIZ);
  8885.  
  8886.     if (!hupok(0))            /* Check if connection still open */
  8887.       return(success = 0);
  8888.  
  8889.     if (line[0])            /* Print EXIT message if given */
  8890.       printf("%s\n",(char *)line);
  8891.  
  8892.     quitting = 1;            /* Flag that we are quitting. */
  8893.  
  8894. #ifdef VMS
  8895.     doexit(GOOD_EXIT,x);
  8896. #else
  8897. #ifdef OSK
  8898. /* Returning any codes here makes the OS-9 shell print an error message. */
  8899.     doexit(GOOD_EXIT,-1);
  8900. #else
  8901. #ifdef datageneral
  8902.         doexit(GOOD_EXIT,x);
  8903. #else
  8904.     doexit(x,-1);
  8905. #endif /* datageneral */
  8906. #endif /* OSK */
  8907. #endif /* VMS */
  8908.     }
  8909.  
  8910. #ifndef NOXFER
  8911. #ifndef NOFRILLS
  8912.     if (cx == XXERR) {            /* ERROR */
  8913. #ifdef CK_XYZ
  8914.     if (protocol != PROTO_K) {
  8915.         printf("Sorry, E-PACKET only works with Kermit protocol\n");
  8916.         return(-9);
  8917.     }
  8918. #endif /* CK_XYZ */
  8919.     if ((x = cmcfm()) < 0) return(x);
  8920.     ttflui();
  8921.     epktflg = 1;
  8922.     sstate = 'a';
  8923.     return(0);
  8924.     }
  8925. #endif /* NOFRILLS */
  8926.  
  8927.     if (cx == XXFIN) {            /* FINISH */
  8928. #ifdef NEWFTP
  8929.     if ((ftpget == 1) || ((ftpget == 2) && ftpisopen()))
  8930.       return(ftpbye());
  8931. #endif /* NEWFTP */
  8932. #ifdef CK_XYZ
  8933.     if (protocol != PROTO_K) {
  8934.         printf("Sorry, FINISH only works with Kermit protocol\n");
  8935.         return(-9);
  8936.     }
  8937. #endif /* CK_XYZ */
  8938.     if ((x = cmcfm()) < 0) return(x);
  8939.  
  8940. #ifdef IKS_OPTION
  8941.         if (
  8942. #ifdef CK_XYZ
  8943.             protocol == PROTO_K &&
  8944. #endif /* CK_XYZ */
  8945.             !iks_wait(KERMIT_REQ_START,1)) {
  8946.         printf(
  8947.               "?A Kermit Server is not available to process this command\n");
  8948.         return(-9);            /* Correct the return code */
  8949.         }
  8950. #endif /* IKS_OPTION */
  8951.  
  8952.     sstate = setgen('F',"","","");
  8953.     if (local) ttflui();        /* If local, flush tty input buffer */
  8954.     return(0);
  8955.     }
  8956. #endif /* NOXFER */
  8957.  
  8958. #ifndef NOSPL
  8959.     if (cx == XXFOR)            /* FOR loop */
  8960.       return(dofor());
  8961. #endif /* NOSPL */
  8962.  
  8963. #ifndef NOXFER
  8964.     /* GET MGET REGET RETRIEVE etc */
  8965.     if (cx == XXGET || cx == XXMGET || cx == XXREGET || cx == XXRETR) {
  8966. #ifdef IKSD
  8967.     if (inserver && !ENABLED(en_sen)) {
  8968.         printf("?Sorry, reception of files is disabled\n");
  8969.         return(-9);
  8970.     }
  8971. #endif /* IKSD */
  8972.     return(doxget(cx));
  8973.     }
  8974. #endif /* NOXFER */
  8975.  
  8976. #ifndef NOSPL
  8977. #ifndef NOFRILLS
  8978.     if (cx == XXGOK) {            /* GETOK */
  8979.     return(success = doask(cx));
  8980.     }
  8981. #endif /* NOFRILLS */
  8982. #endif /* NOSPL */
  8983.  
  8984.     if (cx == XXHLP) {            /* HELP */
  8985. #ifdef NOHELP
  8986.     return(dohlp(XXHLP));
  8987. #else
  8988.     x = cmkey2(cmdtab,
  8989.            ncmd,"\nCommand or topic","help",toktab,xxstring,1+2+8);
  8990.     debug(F111,"HELP command x",cmdbuf,x);
  8991.     if (x == -5) {
  8992.         y = chktok(toktab);
  8993.         debug(F101,"HELP cmkey token","",y);
  8994.         /* ungword(); */
  8995.         switch (y) {
  8996. #ifndef NOPUSH
  8997.           case '!':
  8998.           case '@': x = XXSHE; break;
  8999.           case '<': x = XXFUN; break;
  9000. #endif /* NOPUSH */
  9001.           case '#': x = XXCOM; break;
  9002.           case ';': x = XXCOM; break;
  9003. #ifndef NOSPL
  9004.               case '.': x = XXDEF; break;
  9005.           case ':': x = XXLBL; break;
  9006. #ifndef NOSEXP
  9007.           case '(': x = XXSEXP; break;
  9008. #endif /* NOSEXP */
  9009. #endif /* NOSPL */
  9010. #ifdef CK_RECALL
  9011.           case '^': x = XXREDO; break;
  9012. #endif    /* CK_RECALL */
  9013.           case '&': x = XXECH; break; /* (what is this?) */
  9014.           default:
  9015.         printf("\n?Invalid - %s\n",cmdbuf);
  9016.         x = -2;
  9017.         }
  9018.     }
  9019.     makestr(&hlptok,atmbuf);
  9020.     debug(F111,"HELP token",hlptok,x);
  9021.     return(dohlp(x));
  9022. #endif /* NOHELP */
  9023.     }
  9024.  
  9025. #ifndef NOHELP
  9026.     if (cx == XXINT)            /* INTRO */
  9027.       return(hmsga(introtxt));
  9028.     if (cx == XXNEW) {            /* NEWS */
  9029.     int x;
  9030.     extern char * k_info_dir;
  9031.     x = hmsga(newstxt);
  9032.     return(x);
  9033.     }
  9034.  
  9035. #ifdef OS2ONLY
  9036.     if (cx == XXUPD) {            /* View UPDATE file */
  9037.         extern char exedir[];
  9038.         char * pTopic;
  9039.         char updstr[2048];
  9040.         if ((x = cmtxt("topic name","",&pTopic,xxstring)) < 0)
  9041.             return x;
  9042. #ifdef COMMENT
  9043.     sprintf(updstr,
  9044.         "start view %s\\docs\\k2.inf+%s\\docs\\using_ck.inf+\
  9045. %s\\docs\\dialing.inf+%s\\docs\\modems.inf %s",
  9046.         exedir,exedir,exedir,exedir,pTopic
  9047.         );
  9048. #else
  9049.     if (ckmakxmsg(updstr,
  9050.              2048,
  9051.              "start view ",
  9052.              exedir,
  9053.              "\\docs\\k2.inf+",
  9054.              exedir,
  9055.              "\\docs\\using_ck.inf+",
  9056.              exedir,
  9057.              "\\docs\\dialing.inf+",
  9058.              exedir,
  9059.              "\\docs\\modems.inf ",
  9060.              pTopic,
  9061.              NULL,
  9062.              NULL
  9063.              ) > 0)
  9064. #endif /* COMMENT */
  9065.       system(updstr);
  9066.         return(success = 1);
  9067.     }
  9068. #endif /* OS2ONLY */
  9069. #endif /* NOHELP */
  9070.  
  9071. #ifndef NOLOCAL
  9072.     if (cx == XXHAN) {            /* HANGUP */
  9073.     if ((x = cmcfm()) < 0) return(x);
  9074. #ifdef NEWFTP
  9075.     if ((ftpget == 1) || ((ftpget == 2) && !local && ftpisopen()))
  9076.       return(success = ftpbye());
  9077. #endif /* NEWFTP */
  9078. #ifndef NODIAL
  9079.     if ((x = mdmhup()) < 1) {
  9080.         debug(F101,"HANGUP mdmup","",x);
  9081. #endif /* NODIAL */
  9082.         x = tthang();
  9083.         debug(F101,"HANGUP tthang","",x);
  9084.         x = (x > -1);
  9085. #ifndef NODIAL
  9086.     }
  9087.     dialsta = DIA_UNK;
  9088. #endif /* NODIAL */
  9089.     whyclosed = WC_CLOS;
  9090.     ttchk();            /* In case of CLOSE-ON-DISCONNECT */
  9091.     dologend();
  9092. #ifdef OS2
  9093.     if (x)
  9094.       DialerSend(OPT_KERMIT_HANGUP, 0);
  9095. #endif /* OS2 */
  9096.     if (x) haveline = 0;
  9097.     return(success = x);
  9098.     }
  9099. #endif /* NOLOCAL */
  9100.  
  9101. #ifndef NOSPL
  9102.     /* INPUT, REINPUT, and MINPUT */
  9103.  
  9104.     if (cx == XXINP || cx == XXREI || cx == XXMINP) {
  9105.     long zz;
  9106.     int flags = 0, incount = 0;
  9107.     extern int itsapattern, isjoin, isinbuflen;
  9108.     int c, getval;
  9109.  
  9110.     struct FDB sw, nu, fl;
  9111.     int fc, havetime = 0;
  9112.     char * m;
  9113.  
  9114.     if (cx == XXREI) {
  9115.         m = "Timeout in seconds (ignored)";
  9116.     } else {
  9117.         m = "Seconds to wait for input,\n or time of day hh:mm:ss,\
  9118.  or switch";
  9119.     }
  9120.     cmfdbi(&sw,            /* First FDB - command switches */
  9121.            _CMKEY,            /* fcode */
  9122.            m,            /* helpmsg */
  9123.            ckitoa(indef),        /* default */
  9124.            "",            /* addtl string data */
  9125.            ninputsw,        /* addtl numeric data 1: tbl size */
  9126.            4,            /* addtl numeric data 2: 4 = cmswi */
  9127.            xxstring,        /* Processing function */
  9128.            inputsw,            /* Keyword table */
  9129.            &nu            /* Pointer to next FDB */
  9130.            );
  9131.     cmfdbi(&nu,
  9132.            _CMNUM,            /* Number */
  9133.            m,            /* Help message */
  9134.            ckitoa(indef),        /* default */
  9135.            "",            /* N/A */
  9136.            10,            /* Radix = 10 */
  9137.            0,            /* N/A */
  9138.            xxstring,        /* Processing function */
  9139.            NULL,            /* N/A */
  9140.            &fl            /* Next */
  9141.            );
  9142.     cmfdbi(&fl,            /* Time of day hh:mm:ss */
  9143.            _CMFLD,            /* fcode */
  9144.            "",            /* hlpmsg */
  9145.            "",
  9146.            "",            /* addtl string data */
  9147.            0,            /* addtl numeric data 1 */
  9148.            0,            /* addtl numeric data 2 */
  9149.            xxstring,
  9150.            NULL,
  9151.            NULL
  9152.            );
  9153.     fc = (cx == XXREI) ? cmfdb(&nu) : cmfdb(&sw); /* Parse something */
  9154.  
  9155.     for (y = 0; y < MINPMAX; y++) {    /* Initialize search strings */
  9156.         mp[y] = 0;            /* Assume it's not a pattern */
  9157.         if (!mpinited) {
  9158.         ms[y] = NULL;
  9159.         }
  9160.         if (ms[y]) {
  9161.         free(ms[y]);        /* Free old strings, if any */
  9162.         ms[y] = NULL;
  9163.         }
  9164.     }
  9165.     mpinited = 1;
  9166.     while (!havetime) {
  9167.         if (fc < 0) {        /* Error */
  9168.         if (fc == -3) {
  9169.             printf("?Syntax error in INPUT-class command\n");
  9170.             return(-9);
  9171.         } else
  9172.           return(fc);
  9173.         }
  9174.         switch (cmresult.fcode) {
  9175.           case _CMKEY:        /* Switch */
  9176.         c = cmgbrk();
  9177.         if ((getval = (c == ':' || c == '=')) &&
  9178.             !(cmgkwflgs() & CM_ARG)) {
  9179.             printf("?This switch does not take an argument\n");
  9180.             return(-9);
  9181.         }
  9182.         if (getval && cmresult.nresult == INPSW_COU) {
  9183.             if ((y = cmnum("Number of bytes to read",
  9184.                    "",10,&x,xxstring)) < 0)
  9185.               return(y);
  9186.             incount = x;
  9187.         }
  9188.         flags |= cmresult.nresult;
  9189.         fc = cmfdb(&sw);    /* Maybe parse more switches */
  9190.         continue;
  9191.  
  9192.           case _CMNUM:        /* Seconds to time out */
  9193.         x = cmresult.nresult;
  9194. #ifdef CKFLOAT
  9195.         if (inscale != 1.0)    /* Scale */
  9196.           x *= inscale;        
  9197. #endif    /* CKFLOAT */
  9198.         havetime++;
  9199.         break;
  9200.  
  9201.           case _CMFLD:
  9202.         zz = tod2sec(atmbuf);    /* Convert to secs since midnight */
  9203.         if (zz < 0L) {
  9204.             printf("?Number, expression, or time of day required\n");
  9205.             return(-9);
  9206.         } else {
  9207.             char now[32];    /* Current time */
  9208.             char *p;
  9209.             long tnow;
  9210.             p = now;
  9211.             ztime(&p);
  9212.             tnow = atol(p+11) * 3600L + atol(p+14) * 60L + atol(p+17);
  9213.             if (zz < tnow)    /* User's time before now */
  9214.               zz += 86400L;    /* So make it tomorrow */
  9215.             zz -= tnow;        /* Seconds from now. */
  9216.             if (zz > -1L) {
  9217.             x = zz;
  9218.             if (zz != (long) x) {
  9219.                 printf(
  9220. "Sorry, arithmetic overflow - hh:mm:ss not usable on this platform.\n"
  9221. );
  9222.                 return(-9);
  9223.             }
  9224.             }
  9225.             havetime++;
  9226.         }
  9227.         break;
  9228.           default:        
  9229.         printf("?Internal error\n");
  9230.         return(-9);
  9231.         }
  9232.     }
  9233.     /* Now parse the search text */
  9234.  
  9235. #ifdef CK_MINPUT
  9236.     if (cx == XXMINP) {        /* MINPUT */
  9237.         int i, k = 0, n = 0;
  9238.         struct stringarray * q;
  9239.         keepallchars = 1;
  9240.         while (k < MINPMAX) {
  9241.         if ((y = cmfld("String or pattern","",&s,xxstring)) < 0) {
  9242.             if (y == -3) {
  9243.             if ((y = cmcfm()) < 0)
  9244.               return(y);
  9245.             break;
  9246.             } else {
  9247.             return(y);
  9248.             }
  9249.         }
  9250.         debug(F111,"MINPUT field",s,k);
  9251.         if (isjoin) {
  9252.             if ((q = cksplit(1,0,s," ",(char *)c1chars,3,0,0))) {
  9253.             char ** ap = q->a_head;
  9254.             n = q->a_size;
  9255.             debug(F101,"minput cksplit size","",n);
  9256.             for (i = 1; i <= n && k < MINPMAX; i++) {
  9257.                 if (!ap[i]) /* Add non-empty elements */
  9258.                   continue;
  9259.                 if (!*(ap[i]))
  9260.                   continue;
  9261.                 makestr(&(ms[k]),ap[i]);
  9262.                 debug(F111,"MINPUT JOIN",ms[k],k);
  9263.                 k++;
  9264.             }
  9265.             }
  9266.         } else {
  9267.             if (s) if (*s) {
  9268.             makestr(&(ms[k]),brstrip(s));
  9269.             if (itsapattern) mp[k] = 1;
  9270.             debug(F111,"MINPUT",ms[k],itsapattern);
  9271.             k++;
  9272.             }
  9273.         }
  9274.         }
  9275.         keepallchars = 0;
  9276.     } else {
  9277. #endif /* CK_MINPUT */
  9278.  
  9279.         /* INPUT or REINPUT */
  9280.  
  9281.         if (flags & INPSW_COU) {
  9282.         if ((y = cmcfm()) < 0)
  9283.           return(y);
  9284.         } else {
  9285.         if ((y = cmtxt("Material to be input","",&s,xxstring)) < 0)
  9286.           return(y);
  9287.         }
  9288.         mp[0] = itsapattern ? 1 : 0;
  9289.         makestr(&(ms[0]),brstrip(s));
  9290.         ms[1] = NULL;
  9291.  
  9292. #ifdef CK_MINPUT
  9293.     }
  9294. #endif /* CK_MINPUT */
  9295.  
  9296.     if (incount > 0)        /* No searching if /COUNT: given */
  9297.       makestr(&(ms[0]),NULL);
  9298.  
  9299.     if (cx == XXINP || cx == XXMINP) { /* Not REINPUT... */
  9300.         i_active = 1;
  9301.         /* Go try to input the search string */
  9302.         success = doinput(x,ms,mp,flags,incount);
  9303.         i_active = 0;
  9304.     } else {            /* REINPUT */
  9305.         success = doreinp(x,ms[0],itsapattern);
  9306.     }
  9307.     if (intime[cmdlvl] && !success) { /* TIMEOUT-ACTION = QUIT? */
  9308.         popclvl();            /* If so, pop command level. */
  9309.         if (pflag && cmdlvl == 0) {
  9310.         if (cx == XXINP)  printf("?INPUT timed out\n");
  9311.         if (cx == XXMINP) printf("?MINPUT timed out\n");
  9312.         if (cx == XXREI)  printf("?REINPUT failed\n");
  9313.         }
  9314.     }
  9315.     return(success);        /* Return do(re)input's return code */
  9316.     }
  9317.  
  9318. #endif /* NOSPL */
  9319.  
  9320.     if (cx == XXLOG) {            /* LOG */
  9321.     x = cmkey(logtab,nlog,"What to log","",xxstring);
  9322.     if (x == -3) {
  9323.         printf("?Type of log required\n");
  9324.         return(-9);
  9325.     }
  9326.     if (x < 0) return(x);
  9327.     x = dolog(x);
  9328.     if (x < 0)
  9329.       return(x);
  9330.     else
  9331.       return(success = x);
  9332.     }
  9333.  
  9334.     if (cx == XXLOGIN) {        /* (REMOTE) LOGIN */
  9335. #ifdef NEWFTP
  9336.     if ((ftpget == 1) || ((ftpget == 2) && ftpisopen()))
  9337.       return(success = doftpusr());
  9338. #endif /* NEWFTP */
  9339. #ifdef IKSD
  9340.     if (inserver) {
  9341.         printf("?Already logged in\n");
  9342.         return(-9);
  9343.     } else
  9344. #endif /* IKSD */
  9345.     {
  9346. #ifdef NOXFER
  9347.         return(-2);
  9348. #else
  9349.         return(dormt(XZLGI));
  9350. #endif /* NOXFER */
  9351.     }
  9352.     }
  9353.     if (cx == XXLOGOUT) {        /* (REMOTE) LOGOUT */
  9354. #ifdef NEWFTP
  9355.     if ((ftpget == 1) || ((ftpget == 2) && ftpisopen()))
  9356.       return(success = doftpres());
  9357. #endif /* NEWFTP */
  9358.  
  9359. #ifdef IKSD
  9360.         if (inserver) {
  9361.         if ((x = cmcfm()) < 0)
  9362.           return(x);
  9363.         doexit(GOOD_EXIT,xitsta);
  9364.     } else
  9365. #endif /* IKSD */
  9366.     if (!local || (network && ttchk() < 0)) {
  9367.         printf("?No connection.\n");
  9368.         return(-9);
  9369.     } else {
  9370. #ifdef NOXFER
  9371.         return(-2);
  9372. #else
  9373.         return(dormt(XZLGO));
  9374. #endif /* NOXFER */
  9375.     }
  9376.     }
  9377.  
  9378. #ifndef NOSCRIPT
  9379.     if (cx == XXLOGI) {            /* UUCP-style script */
  9380.     if ((x = cmtxt("expect-send expect-send ...","",&s,xxstring)) < 0)
  9381.       return(x);
  9382. #ifdef CK_APC
  9383.     if ((apcactive == APC_LOCAL) ||
  9384.         ((apcactive == APC_REMOTE) && (!(apcstatus & APC_UNCH))))
  9385.       return(success = 0);
  9386. #endif /* CK_APC */
  9387. #ifdef VMS
  9388.     conres();            /* For Ctrl-C to work... */
  9389. #endif /* VMS */
  9390.     return(success = dologin(s));    /* Return 1=completed, 0=failed */
  9391.     }
  9392. #endif /* NOSCRIPT */
  9393.  
  9394. #ifndef NOXFER
  9395. #ifdef PIPESEND
  9396.     if (cx == XXCREC) {            /* CRECEIVE */
  9397.     if (protocol != PROTO_K) {
  9398.         printf("?Sorry, CRECEIVE works only with Kermit protocol\n");
  9399.         return(-9);
  9400.     } else
  9401.       return(doxget(cx));
  9402.     }
  9403.     if (cx == XXCGET) {            /* CGET */
  9404.     return(doxget(cx));
  9405.     }
  9406. #endif /* PIPESEND */
  9407.  
  9408.     if (cx == XXREC)            /* RECEIVE */
  9409.       return(doxget(cx));
  9410. #endif /* NOXFER */
  9411.  
  9412. #ifndef NOXFER
  9413.     if (cx == XXREM) {            /* REMOTE */
  9414. #ifdef NEWFTP
  9415.     if ((ftpget == 1) || ((ftpget == 2) && ftpisopen()))
  9416.       return(doftprmt(0,0));
  9417. #endif /* NEWFTP */
  9418. #ifdef CK_XYZ
  9419.     if (protocol != PROTO_K) {
  9420.         printf("Sorry, REMOTE commands only work with Kermit protocol\n");
  9421.         return(-9);
  9422.     }
  9423. #endif /* CK_XYZ */
  9424.     x = cmkey(remcmd,nrmt,"Remote Kermit server command","",xxstring);
  9425.     if (x == -3) {
  9426.         printf("?You must specify a command for the remote server\n");
  9427.         return(-9);
  9428.     }
  9429.     return(dormt(x));
  9430.     }
  9431. #endif /* NOXFER */
  9432.  
  9433. #ifndef NORENAME
  9434. #ifndef NOFRILLS
  9435.     if (cx == XXREN || cx == XXLREN) {    /* RENAME */
  9436. #ifdef LOCUS
  9437.     if (!locus && cx != XXLREN) {
  9438. #ifdef NOXFER
  9439.         return(-2);
  9440. #else
  9441.         return(dormt(XZREN));
  9442. #endif /* NOXFER */
  9443.         }
  9444. #endif /* LOCUS */
  9445. #ifdef IKSD
  9446.     if (inserver && (!ENABLED(en_ren)
  9447. #ifdef CK_LOGIN
  9448.              || isguest
  9449. #endif /* CK_LOGIN */
  9450.              )) {
  9451.         printf("?Sorry, renaming of files is disabled\n");
  9452.         return(-9);
  9453.     }
  9454. #endif /* IKSD */
  9455. #ifdef CK_APC
  9456.     if ((apcactive == APC_LOCAL) ||
  9457.         ((apcactive == APC_REMOTE) && (!(apcstatus & APC_UNCH))))
  9458.       return(success = 0);
  9459. #endif /* CK_APC */
  9460.     return(dorenam());
  9461.     }
  9462. #endif /* NOFRILLS */
  9463. #endif /* NORENAME */
  9464.  
  9465.     if (cx == XXEIGHT) {        /* EIGHTBIT */
  9466.     extern int parity, cmask, cmdmsk;
  9467.     if ((x = cmcfm()) < 0)
  9468.       return(x);
  9469.     parity = 0;
  9470.     cmask = 0xff;
  9471.     cmdmsk = 0xff;
  9472.     return(success = 1);
  9473.     }
  9474.  
  9475. #ifndef NOXFER
  9476. /* SEND, CSEND, MOVE, MAIL, and RESEND use the new common code */
  9477.  
  9478.     if (cx == XXSEN            /* SEND */
  9479. #ifdef PIPESEND
  9480.     || cx == XXCSEN            /* CSEND */
  9481. #endif /* PIPESEND */
  9482.     || cx == XXMOVE            /* MOVE */
  9483.     || cx == XXMAI            /* MAIL */
  9484. #ifdef CK_RESEND
  9485.     || cx == XXRSEN            /* RESEND */
  9486. #endif /* CK_RESEND */
  9487.     ) {
  9488. #ifdef IKSD
  9489.     if (inserver && !ENABLED(en_get)) {
  9490.         printf("?Sorry, sending files is disabled\n");
  9491.         return(-9);
  9492.     }
  9493. #endif /* IKSD */
  9494.     return(doxsend(cx));
  9495.     }
  9496.  
  9497. /* PSEND, ADD, and REMOVE use special parsing */
  9498.  
  9499. #ifdef ADDCMD
  9500.     /* ADD and REMOVE */
  9501.     if (cx == XXADD || cx == XXREMV) {
  9502.     char * m;
  9503.     m = (cx == XXADD) ? "Add to which list?" : "Remove from which list?";
  9504.     x = cmkey(addtab,naddtab,m,"",xxstring);
  9505.     if (x < 0)
  9506.       return(x);
  9507. #ifndef NOMSEND
  9508.     if (x == ADD_SND)
  9509.       return(addsend(cx));
  9510.     else
  9511. #endif /* NOMSEND */
  9512.       return(doadd(cx,x));
  9513.     }
  9514. #endif /* ADDCMD */
  9515.  
  9516. #ifdef CK_RESEND
  9517.     if (cx == XXPSEN) {            /* PSEND */
  9518.     int seekto = 0;            /* FIX THIS */
  9519.  
  9520.     cmarg = cmarg2 = "";
  9521.     x = cmifi("File to partially send", "", &s, &y, xxstring);
  9522.     if (x < 0) {
  9523.         if (x == -3) {
  9524.         printf("?A file specification is required\n");
  9525.         return(-9);
  9526.         } else return(x);
  9527.     }
  9528.     nfils = -1;            /* Files come from internal list. */
  9529. #ifndef NOMSEND
  9530.         addlist = 0;            /* Don't use SEND-LIST. */
  9531.         filenext = NULL;
  9532. #endif /* NOMSEND */
  9533.     ckstrncpy(line,s,LINBUFSIZ);    /* Save copy of string just parsed. */
  9534.     debug(F110,"PSEND line",line,0);
  9535.     if (y != 0) {
  9536.         printf("?Sorry, wildcards not permitted in this command\n");
  9537.         return(-9);
  9538.     }
  9539.     if (sizeof(int) < 4) {
  9540.         printf("?Sorry, this command needs 32-bit integers\n");
  9541.         return(-9);
  9542.     }
  9543.     x = cmnum("starting position (byte number)",
  9544.           "",10,&seekto,xxstring);
  9545.     if (x < 0)
  9546.       return(x);
  9547.     zfnqfp(s,fspeclen,fspec);    /* Get full path */
  9548.     if ((x = cmtxt("Name to send it with","",&s,NULL)) < 0)
  9549.       return(x);
  9550.     ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  9551.  
  9552. #ifdef IKSD
  9553.     if (inserver && !ENABLED(en_get)) {
  9554.         printf("?Sorry, sending files is disabled\n");
  9555.         return(-9);
  9556.     }
  9557. #endif /* IKSD */
  9558. #ifdef PIPESEND
  9559.     if (sndfilter) {
  9560.         printf("?Sorry, no PSEND while SEND FILTER selected\n");
  9561.         return(-9);
  9562.     }
  9563. #endif /* PIPESEND */
  9564. #ifdef CK_XYZ
  9565.     if ((protocol == PROTO_X || protocol == PROTO_XC)) {
  9566.         printf("Sorry, PSEND works only with Kermit protocol\n");
  9567.         return(-9);
  9568.     }
  9569. #endif /* CK_XYZ */
  9570.  
  9571.     cmarg2 = brstrip(tmpbuf);    /* Strip braces */
  9572.     cmarg = line;            /* File to send */
  9573.     debug(F110,"PSEND filename",cmarg,0);
  9574.     debug(F110,"PSEND as-name",cmarg2,0);
  9575.     sendstart = seekto;
  9576.     sstate = 's';            /* Set start state to SEND */
  9577. #ifndef NOMSEND
  9578.     addlist = 0;
  9579.     filenext = NULL;
  9580. #endif /* NOMSEND */
  9581.     sendmode = SM_PSEND;
  9582. #ifdef MAC
  9583.     what = W_SEND;
  9584.     scrcreate();
  9585. #endif /* MAC */
  9586.     if (local) {            /* If in local mode, */
  9587.         displa = 1;            /* enable file transfer display */
  9588.     }
  9589.     return(0);
  9590.     }
  9591. #endif /* CK_RESEND */
  9592. #endif /* NOXFER */
  9593.  
  9594. #ifndef NOXFER
  9595. #ifndef NOMSEND
  9596.     if (cx == XXMSE || cx == XXMMOVE) {
  9597. #ifdef NEWFTP
  9598.     if ((ftpget == 1) || ((ftpget == 2) && ftpisopen()))
  9599.       return(doftpput(cx,0));
  9600. #endif /* NEWFTP */
  9601. #ifdef CK_XYZ
  9602.     if (protocol == PROTO_X || protocol == PROTO_XC) {
  9603.         printf(
  9604. "Sorry, you can only send one file at a time with XMODEM protocol\n"
  9605.            );
  9606.         return(-9);
  9607.     }
  9608. #endif /* CK_XYZ */
  9609.         return(doxsend(cx));
  9610.     }
  9611.  
  9612. #ifdef COMMENT                /* (moved to doxsend) */
  9613.     if (cx == XXMSE || cx == XXMMOVE) {    /* MSEND and MMOVE commands */
  9614.     nfils = 0;            /* Like getting a list of */
  9615.     lp = line;            /* files on the command line */
  9616.     addlist = 0;            /* Do not use SEND-LIST */
  9617.     filenext = NULL;        /* Ditto ! */
  9618.  
  9619.     while (1) {
  9620.         char *p;
  9621.         if ((x = cmifi("Names of files to send, separated by spaces","",
  9622.                &s,&y,xxstring)) < 0) {
  9623.         if (x == -3) {
  9624.             if (nfils <= 0) {
  9625.             printf("?A file specification is required\n");
  9626.             return(-9);
  9627.             } else break;
  9628.         }
  9629.         return(x);
  9630.         }
  9631.         msfiles[nfils++] = lp;    /* Got one, count it, point to it, */
  9632.         p = lp;            /* remember pointer, */
  9633.         while (*lp++ = *s++)    /* and copy it into buffer */
  9634.           if (lp > (line + LINBUFSIZ)) { /* Avoid memory leak */
  9635.           printf("?MSEND list too long\n");
  9636.           line[0] = NUL;
  9637.           return(-9);
  9638.           }
  9639.         debug(F111,"msfiles",msfiles[nfils-1],nfils-1);
  9640.         if (nfils == 1) *fspec = NUL; /* Take care of \v(filespec) */
  9641. #ifdef ZFNQFP
  9642.         zfnqfp(p,TMPBUFSIZ,tmpbuf);
  9643.         p = tmpbuf;
  9644. #endif /* ZFNQFP */
  9645.         if (((int)strlen(fspec) + (int)strlen(p) + 1) < fspeclen) {
  9646.         strcat(fspec,p);    /* safe */
  9647.         strcat(fspec," ");    /* safe */
  9648.         } else printf("WARNING - \\v(filespec) buffer overflow\n");
  9649.     }
  9650.     cmlist = msfiles;        /* Point cmlist to pointer array */
  9651.     cmarg2 = "";            /* No internal expansion list (yet) */
  9652.     sndsrc = nfils;            /* Filenames come from cmlist */
  9653.     sendmode = SM_MSEND;        /* Remember this kind of SENDing */
  9654.     sstate = 's';            /* Set start state for SEND */
  9655.     if (cx == XXMMOVE)        /* If MMOVE'ing, */
  9656.       moving = 1;            /*  set this flag. */
  9657. #ifdef MAC
  9658.     what = W_SEND;
  9659.     scrcreate();
  9660. #endif /* MAC */
  9661.     if (local) {            /* If in local mode, */
  9662.         displa = 1;            /* turn on file transfer display */
  9663.         ttflui();            /* and flush tty input buffer. */
  9664.     }
  9665.     return(0);
  9666.     }
  9667. #endif /* COMMENT */
  9668. #endif /* NOMSEND */
  9669. #endif /* NOXFER */
  9670.  
  9671. #ifndef NOSERVER
  9672.     if (cx == XXSER) {            /* SERVER */
  9673. #ifdef CK_XYZ
  9674.     if (protocol != PROTO_K) {
  9675.         printf("Sorry, SERVER only works with Kermit protocol\n");
  9676.         return(-9);
  9677.     }
  9678. #endif /* CK_XYZ */
  9679. #ifdef COMMENT
  9680. /*
  9681.   Parse for time limit, but since we don't use it yet,
  9682.   the parsing is commented out.
  9683. */
  9684.     x_ifnum = 1;            /* Turn off internal complaints */
  9685.     y = cmnum("optional time limit, seconds, or time of day as hh:mm:ss",
  9686.           "0", 10, &x, xxstring
  9687.           );
  9688.     x_ifnum = 0;
  9689.     if (y < 0) {
  9690.         if (y == -2) {        /* Invalid number or expression */
  9691.         zz = tod2sec(atmbuf);    /* Convert to secs since midnight */
  9692.         if (zz < 0L) {
  9693.             printf("?Number, expression, or time of day required\n");
  9694.             return(-9);
  9695.         } else {
  9696.             char now[32];    /* Current time */
  9697.             char *p;
  9698.             long tnow;
  9699.             p = now;
  9700.             ztime(&p);
  9701.             tnow = atol(p+11) * 3600L + atol(p+14) * 60L + atol(p+17);
  9702.             if (zz < tnow)    /* User's time before now */
  9703.               zz += 86400L;    /* So make it tomorrow */
  9704.             zz -= tnow;        /* Seconds from now. */
  9705.         }
  9706.         } else
  9707.           return(y);
  9708.     }
  9709.     if (zz > -1L) {
  9710.         x = zz;
  9711.         if (zz != (long) x) {
  9712.         printf(
  9713. "Sorry, arithmetic overflow - hh:mm:ss not usable on this platform.\n"
  9714.                );
  9715.         return(-9);
  9716.         }
  9717.     }
  9718.     if (x < 0)
  9719.       x = 0;
  9720. #endif /* COMMENT */
  9721.  
  9722.     if ((x = cmcfm()) < 0) return(x);
  9723.     sstate = 'x';
  9724. #ifdef MAC
  9725.     what = W_RECV;
  9726.     scrcreate();
  9727. #endif /* MAC */
  9728.     if (local) displa = 1;
  9729. #ifdef AMIGA
  9730.     reqoff();            /* No DOS requestors while server */
  9731. #endif /* AMIGA */
  9732.     return(0);
  9733.     }
  9734. #endif /* NOSERVER */
  9735.  
  9736.     if (cx == XXSAVE) {            /* SAVE command */
  9737.     x = cmkey(savtab,nsav,"option","keymap",xxstring);
  9738.     if (x == -3) {
  9739.         printf("?You must specify an option to save\n");
  9740.         return(-9);
  9741.     }
  9742.     if (x < 0) return(x);
  9743.     /* have to set success separately for each item in doprm()... */
  9744.     /* actually not really, could have just had doprm return 0 or 1 */
  9745.     /* and set success here... */
  9746.     y = dosave(x);
  9747.     if (y == -3) {
  9748.         printf("?More fields required\n");
  9749.         return(-9);
  9750.     } else return(y);
  9751.     }
  9752.  
  9753.     if (cx == XXSET) {            /* SET command */
  9754.     x = cmkey(prmtab,nprm,"Parameter","",xxstring);
  9755.     if (x == -3) {
  9756.         printf("?You must specify a parameter to set\n");
  9757.         return(-9);
  9758.     }
  9759.     if (x < 0) return(x);
  9760.     /* have to set success separately for each item in doprm()... */
  9761.     /* actually not really, could have just had doprm return 0 or 1 */
  9762.     /* and set success here... */
  9763.     y = doprm(x,0);
  9764.     if (y == -3) {
  9765.         printf("?More fields required\n");
  9766.         return(-9);
  9767.     } else return(y);
  9768.     }
  9769.  
  9770. #ifndef NOPUSH
  9771.     if (cx == XXSHE            /* SHELL (system) command */
  9772.     || cx == XXEXEC            /* exec() */
  9773.     ) {
  9774.     int rx = 0;
  9775.     char * p = NULL;
  9776.     int i /* ,n */ ;
  9777. #ifdef UNIXOROSK
  9778.     char * args[256];
  9779. #endif /* UNIXOROSK */
  9780.  
  9781. #ifdef IKSD
  9782.     if (inserver && (nopush || !ENABLED(en_hos))) {
  9783.         printf("?Sorry, host command access is disabled\n");
  9784.         return(-9);
  9785.     }
  9786. #endif /* IKSD */
  9787.  
  9788. #ifdef CKEXEC
  9789.     if (cx == XXEXEC) {        /* EXEC (overlay ourselves) */
  9790.         struct FDB sw, fl;
  9791.         cmfdbi(&sw,            /* First FDB - command switches */
  9792.            _CMKEY,        /* fcode */
  9793.            "Command to overlay C-Kermit\n or switch", /* hlpmsg */
  9794.            "",            /* default */
  9795.            "",            /* addtl string data */
  9796.            1,            /* addtl numeric data 1: tbl size */
  9797.            4,            /* addtl numeric data 2: 4 = cmswi */
  9798.            xxstring,        /* Processing function */
  9799.            redirsw,        /* Keyword table */
  9800.            &fl            /* Pointer to next FDB */
  9801.            );
  9802.         cmfdbi(&fl,            /* 2nd FDB - command to exec */
  9803.            _CMFLD,        /* fcode */
  9804.            "Command to overlay C-Kermit", /* hlpmsg */
  9805.            "",            /* default */
  9806.            "",            /* addtl string data */
  9807.            0,            /* addtl numeric data 1 */
  9808.            0,            /* addtl numeric data 2 */
  9809.            xxstring,
  9810.            NULL,
  9811.            NULL            /* No more after this */
  9812.            );
  9813.         while (1) {
  9814.         x = cmfdb(&sw);        /* Parse something */
  9815.         debug(F101,"exec cmfdb","",x);
  9816.         if (x < 0)
  9817.           return(x);
  9818.         /* Generalize this if we add more switches */
  9819.         if (cmresult.fcode == _CMKEY) {
  9820.             rx = 1;
  9821.             continue;
  9822.         }
  9823.         if (cmresult.fcode == _CMFLD)
  9824.           break;
  9825.         return(-2);
  9826.         }
  9827.         ckstrncpy(tmpbuf,cmresult.sresult,TMPBUFSIZ);
  9828.         if (!tmpbuf[0]) {
  9829.         printf("?Command required\n");
  9830.         return(-9);
  9831.         }
  9832.         p = brstrip(tmpbuf);
  9833.         args[0] = NULL;        /* Set argv[0] to it */
  9834.         makestr(&args[0],p);
  9835.         for (i = 1; i < 255; i++) {    /* Get arguments for command */
  9836.         if ((x = cmfld("Argument","",&s,xxstring)) < 0) {
  9837.             if (x == -3) {
  9838.             if ((x = cmcfm()) < 0)
  9839.               return(x);
  9840.             break;
  9841.             } else
  9842.               return(x);
  9843.         }
  9844.         args[i] = NULL;
  9845.         s = brstrip(s);
  9846.         makestr(&args[i],s);
  9847.         }
  9848.         args[i] = NULL;
  9849.     } else {
  9850. #endif /* CKEXEC */
  9851.         if ((x = cmtxt("System command to execute","",&s,xxstring)) < 0)
  9852.           return(x);
  9853. #ifdef CKEXEC
  9854.     }
  9855. #endif /* CKEXEC */
  9856.         if (nopush)
  9857.           return(success = 0);
  9858. #ifdef CK_APC
  9859.     if (apcactive == APC_REMOTE && !(apcstatus & APC_UNCH))
  9860.       return(success = 0);
  9861. #endif /* CK_APC */
  9862.     conres();            /* Make console normal  */
  9863. #ifdef OS2
  9864.     if (!(s && *s)) {
  9865.         os2push();
  9866.             return(success = 1);
  9867.     } else
  9868. #endif /* OS2 */
  9869.       if (cx == XXSHE) {
  9870.           x = zshcmd(s);
  9871.           debug(F101,"RUN zshcmd code","",x);
  9872.           concb((char)escape);
  9873.           return(success = x);
  9874. #ifdef CKEXEC
  9875.       } else {
  9876. #ifdef DEBUG
  9877.           if (deblog) {
  9878.           debug(F111,"EXEC cmd",p,0);
  9879.           for (i = 0; i < 256 && args[i]; i++)
  9880.             debug(F111,"EXEC arg",args[i],i);
  9881.           }
  9882. #endif /* DEBUG */
  9883.           if (p) {
  9884.           z_exec(p,args,rx);    /* Overlay ourself */
  9885.           debug(F100,"EXEC fails","",0);
  9886.           concb((char)escape);    /* In case it returns */
  9887.           }
  9888.           return(success = 0);
  9889. #endif /* CKEXEC */
  9890.       }
  9891.     }
  9892.  
  9893. #ifdef CK_REDIR
  9894.     if (cx == XXFUN) {            /* REDIRECT */
  9895. #ifdef CK_APC
  9896.     if ((apcactive == APC_LOCAL) ||
  9897.         ((apcactive == APC_REMOTE) && (!(apcstatus & APC_UNCH))))
  9898.       return(success = 0);
  9899. #endif /* CK_APC */
  9900.     ckmakmsg(tmpbuf,
  9901.          TMPBUFSIZ,
  9902.          "Local command to run,\n",
  9903.          "with its standard input/output redirected to ",
  9904.          local ? ttname : "the communications connection",
  9905.          "\n"
  9906.          );
  9907.     if ((x = cmtxt(tmpbuf,"",&s,xxstring)) < 0)
  9908.       return(x);
  9909.         if (nopush) {
  9910.             printf("?REDIRECT disabled\n");
  9911.             return(success=0);
  9912.         }
  9913.     if (!local) {
  9914.         printf("?SET LINE or SET HOST required first\n");
  9915.         return(-9);
  9916.     }
  9917.     if (!*s) {
  9918.         printf("?REDIRECT requires a command to redirect\n");
  9919.         return(-9);
  9920.     }
  9921.     return(success = ttruncmd(s));
  9922.     }
  9923. #endif /* CK_REDIR */
  9924. #endif /* NOPUSH */
  9925.  
  9926. #ifndef NOSHOW
  9927.     if (cx == XXSHO) {            /* SHOW */
  9928.     x = cmkey(shotab,nsho,"","parameters",xxstring);
  9929.     if (x < 0) return(x);
  9930.     return(doshow(x));
  9931.     }
  9932. #endif /* NOSHOW */
  9933.  
  9934. #ifndef MAC
  9935.     if (cx == XXSPA) {            /* SPACE */
  9936. #ifdef IKSD
  9937.     if (inserver && !ENABLED(en_spa)) {
  9938.         printf("?Sorry, SPACE command disabled\n");
  9939.         return(-9);
  9940.     }
  9941. #endif /* IKSD */
  9942. #ifdef datageneral
  9943.     /* AOS/VS can take an argument after its "space" command. */
  9944.     if ((x = cmtxt("Confirm, or local directory name","",&s,xxstring)) < 0)
  9945.       return(x);
  9946.     if (nopush) {
  9947.         printf("?Sorry, SPACE command disabled\n");
  9948.         return(-9);
  9949.     } else if (*s == NUL) {
  9950.         xsystem(SPACMD);
  9951.     } else {
  9952.         ckmakmsg(line,LINBUFSIZ,"space ",s,NULL,NULL);
  9953.         xsystem(line);
  9954.     }
  9955. #else
  9956. #ifdef OS2
  9957.     if ((x = cmtxt("Press Enter for current disk,\n\
  9958.  or specify a disk letter like A:","",&s,xxstring)) < 0)
  9959.       return(x);
  9960.     if (*s == NUL) {        /* Current disk */
  9961.             unsigned long space = zdskspace(0);
  9962.             if (space > 0 && space < 1024)
  9963.               printf(" Free space: unknown\n");
  9964.             else
  9965.           printf(" Free space: %ldK\n", space/1024L);
  9966.     } else {
  9967.         int drive = toupper(*s);
  9968.             unsigned long space = zdskspace(drive - 'A' + 1);
  9969.             if (space > 0 && space < 1024)
  9970.               printf(" Drive %c: unknown free\n");
  9971.             else
  9972.               printf(" Drive %c: %ldK free\n", drive,space / 1024L);
  9973.     }
  9974. #else
  9975. #ifdef UNIXOROSK
  9976.     x = cmdir("Confirm for current disk,\n\
  9977.  or specify a disk device or directory","",&s,xxstring);
  9978.     if (x == -3)
  9979.       s = "";
  9980.     else if (x < 0)
  9981.       return(x);
  9982.         ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  9983.         s = tmpbuf;
  9984.     if ((x = cmcfm()) < 0) return(x);
  9985.     if (nopush) {
  9986.         printf("?Sorry, SPACE command disabled\n");
  9987.         return(-9);
  9988.     }
  9989.     if (!*s) {            /* Current disk */
  9990.         xsystem(SPACMD);
  9991.     } else {            /* Specified disk */
  9992.         ckmakmsg(line,LINBUFSIZ,SPACM2," ",s,NULL);
  9993.         xsystem(line);
  9994.     }
  9995. #else
  9996.     if ((x = cmcfm()) < 0) return(x);
  9997.     if (nopush) {
  9998.         printf("?Sorry, SPACE command disabled\n");
  9999.         return(-9);
  10000.     }
  10001.     xsystem(SPACMD);
  10002. #endif /* UNIXOROSK */
  10003. #endif /* OS2 */
  10004. #endif /* datageneral */
  10005.     return(success = 1);        /* Pretend it worked */
  10006.     }
  10007. #endif /* MAC */
  10008.  
  10009. #ifndef NOXFER
  10010.     if (cx == XXSTA) {            /* STATISTICS */
  10011.     if ((x = cmkey(stattab,2,"Carriage return, or option",
  10012.                "/brief",xxstring)) < 0)
  10013.       return(x);
  10014.     if ((y = cmcfm()) < 0) return(y);
  10015.     return(success = dostat(x));
  10016.     }
  10017. #endif /* NOXFER */
  10018.  
  10019.     if (cx == XXSTO || cx == XXEND) {    /* STOP, END, or POP */
  10020.     if ((y = cmnum("exit status code","0",10,&x,xxstring)) < 0)
  10021.       return(y);
  10022.     if ((y = cmtxt("Message to print","",&s,xxstring)) < 0)
  10023.       return(y);
  10024.     s = brstrip(s);
  10025.     if (*s) printf("%s\n",s);
  10026.     if (cx == XXSTO) {
  10027.         dostop();
  10028.     } else {
  10029.         doend(x);
  10030.     }
  10031.     return(success = (x == 0));
  10032.     }
  10033.     if (cx == XXSUS) {            /* SUSPEND */
  10034.     if ((y = cmcfm()) < 0) return(y);
  10035. #ifdef NOJC
  10036.     printf("Sorry, this version of Kermit cannot be suspended\n");
  10037. #else
  10038. #ifdef IKSD
  10039.     if (inserver) {
  10040.         printf("?Sorry, IKSD can not be suspended\n");
  10041.         return(-9);
  10042.     } else
  10043. #endif /* IKSD */
  10044.       if (nopush) {
  10045.         printf("?Sorry, access to system is disabled\n");
  10046.         return(-9);
  10047.     }
  10048.     stptrap(0);
  10049. #endif /* NOJC */
  10050.     return(0);
  10051.     }
  10052.  
  10053.     if (cx == XXTAK) {            /* TAKE */
  10054.     char * scriptenv = NULL;    
  10055. #ifdef OS2
  10056.         char * GetAppData(int);
  10057.     extern char startupdir[],exedir[],inidir[];
  10058.     char * keymapenv = NULL;
  10059.         char * appdata0 = NULL, *appdata1 = NULL;
  10060.     int xx;
  10061. #define TAKEPATHLEN 4096
  10062. #else /* OS2 */
  10063. #define TAKEPATHLEN 1024
  10064. #endif /* OS2 */
  10065.     char takepath[TAKEPATHLEN];
  10066.  
  10067.     if (tlevel >= MAXTAKE-1) {
  10068.         printf("?Take files nested too deeply\n");
  10069.         return(-9);
  10070.     }
  10071. #ifdef OS2
  10072. #ifdef NT
  10073.     scriptenv = getenv("K95SCRIPTS");
  10074.     keymapenv = getenv("K95KEYMAPS");
  10075.         makestr(&appdata0,(char *)GetAppData(0));
  10076.         makestr(&appdata1,(char *)GetAppData(1));
  10077. #else /* NT */
  10078.     scriptenv = getenv("K2SCRIPTS");
  10079.     keymapenv = getenv("K2KEYMAPS");
  10080. #endif /* NT */
  10081. #endif /* OS2 */
  10082.  
  10083.     if (!scriptenv)            /* Let this work for Unix etc too */
  10084.       scriptenv = getenv("CK_SCRIPTS"); /* Use this if defined */
  10085. #ifndef OS2
  10086.     if (!scriptenv)            /* Otherwise use home directory */
  10087.       scriptenv = homepath();
  10088. #endif /* OS2 */
  10089.     if (!scriptenv)
  10090.       scriptenv = "";
  10091.     ckstrncpy(takepath,scriptenv,TAKEPATHLEN);
  10092.     debug(F110,"TAKE initial takepath",takepath,0);
  10093.  
  10094. #ifdef OS2
  10095.     if (!keymapenv)
  10096.       keymapenv = getenv("CK_KEYMAPS");
  10097.     if (!keymapenv)
  10098.       keymapenv = "";
  10099.  
  10100.     ckstrncat(takepath,
  10101.           (scriptenv && scriptenv[strlen(scriptenv)-1]==';')?"":";",
  10102.           TAKEPATHLEN
  10103.           );
  10104.     ckstrncat(takepath,keymapenv?keymapenv:"",TAKEPATHLEN);
  10105.     ckstrncat(takepath,
  10106.           (keymapenv && keymapenv[strlen(keymapenv)-1]==';')?"":";",
  10107.           TAKEPATHLEN
  10108.           );
  10109.     ckstrncat(takepath,startupdir,TAKEPATHLEN);
  10110.     ckstrncat(takepath,";",TAKEPATHLEN);
  10111.     ckstrncat(takepath,startupdir,TAKEPATHLEN);
  10112.     ckstrncat(takepath,"SCRIPTS/;",TAKEPATHLEN);
  10113.     ckstrncat(takepath,startupdir,TAKEPATHLEN);
  10114.     ckstrncat(takepath,"KEYMAPS/;",TAKEPATHLEN);
  10115.  
  10116.     ckstrncat(takepath,appdata1,TAKEPATHLEN);
  10117.     ckstrncat(takepath,"Kermit 95/;",TAKEPATHLEN);
  10118.     ckstrncat(takepath,appdata1,TAKEPATHLEN);
  10119.     ckstrncat(takepath,"Kermit 95/SCRIPTS/;",TAKEPATHLEN);
  10120.     ckstrncat(takepath,appdata1,TAKEPATHLEN);
  10121.     ckstrncat(takepath,"Kermit 95/KEYMAPS/;",TAKEPATHLEN);
  10122.  
  10123.     ckstrncat(takepath,appdata0,TAKEPATHLEN);
  10124.     ckstrncat(takepath,"Kermit 95/;",TAKEPATHLEN);
  10125.     ckstrncat(takepath,appdata0,TAKEPATHLEN);
  10126.     ckstrncat(takepath,"Kermit 95/SCRIPTS/;",TAKEPATHLEN);
  10127.     ckstrncat(takepath,appdata0,TAKEPATHLEN);
  10128.     ckstrncat(takepath,"Kermit 95/KEYMAPS/;",TAKEPATHLEN);
  10129.  
  10130.     ckstrncat(takepath,inidir,TAKEPATHLEN);
  10131.     ckstrncat(takepath,";",TAKEPATHLEN);
  10132.     ckstrncat(takepath,inidir,TAKEPATHLEN);
  10133.     ckstrncat(takepath,"SCRIPTS/;",TAKEPATHLEN);
  10134.     ckstrncat(takepath,inidir,TAKEPATHLEN);
  10135.     ckstrncat(takepath,"KEYMAPS/;",TAKEPATHLEN);
  10136.  
  10137.     ckstrncat(takepath,zhome(),TAKEPATHLEN);
  10138.     ckstrncat(takepath,";",TAKEPATHLEN);
  10139.     ckstrncat(takepath,zhome(),TAKEPATHLEN);
  10140.     ckstrncat(takepath,"SCRIPTS/;",TAKEPATHLEN);
  10141.     ckstrncat(takepath,zhome(),TAKEPATHLEN);
  10142.     ckstrncat(takepath,"KEYMAPS/;",TAKEPATHLEN);
  10143.  
  10144.     ckstrncat(takepath,exedir,TAKEPATHLEN);
  10145.     ckstrncat(takepath,";",TAKEPATHLEN);
  10146.     ckstrncat(takepath,exedir,TAKEPATHLEN);
  10147.     ckstrncat(takepath,"SCRIPTS/;",TAKEPATHLEN);
  10148.     ckstrncat(takepath,exedir,TAKEPATHLEN);
  10149.     ckstrncat(takepath,"KEYMAPS/;",TAKEPATHLEN);
  10150. #endif /* OS2 */
  10151.     debug(F110,"TAKE final takepath",takepath,0);
  10152.  
  10153.     if ((y = cmifip("Commands from file",
  10154.             "",&s,&x,0,takepath,xxstring)) < 0) {
  10155.         if (y == -3) {
  10156.         printf("?A file name is required\n");
  10157.         return(-9);
  10158.         } else
  10159.           return(y);
  10160.     }
  10161.     if (x != 0) {
  10162.         printf("?Wildcards not allowed in command file name\n");
  10163.         return(-9);
  10164.     }
  10165.     ckstrncpy(line,s,LINBUFSIZ);
  10166.     debug(F110,"TAKE file",s,0);
  10167.     if (isdir(s)) {
  10168.         printf("?Can't execute a directory - \"%s\"\n", s);
  10169.         return(-9);
  10170.     }
  10171. #ifndef NOTAKEARGS
  10172.     {
  10173.         char * p;
  10174.         x = strlen(line);
  10175.         debug(F111,"TAKE args",line,x);
  10176.         p = line + x + 1;
  10177.         if ((y = cmtxt("Optional arguments","",&s,xxstring)) < 0)
  10178.           return(y);
  10179.         if (*s) {            /* Args given? */
  10180.         ckstrncpy(p,s,LINBUFSIZ-x-1);
  10181. #ifdef ZFNQFP
  10182.         zfnqfp(line,TMPBUFSIZ,tmpbuf);
  10183.         s = tmpbuf;
  10184. #else
  10185.         s = line;
  10186. #endif /* ZFNQFP */
  10187.         debug(F110,"TAKE filename",s,0);
  10188.         x = strlen(s);
  10189.         debug(F101,"TAKE new len",s,x);
  10190.  
  10191. #ifdef COMMENT
  10192. /*
  10193.   This was added in C-Kermit 7.0 to allow args to be passed from the TAKE
  10194.   command to the command file.  But it overwrites the current argument vector,
  10195.   which is at best surprising, and at worst unsafe.
  10196. */
  10197.         addmac("%0",s);        /* Define %0 = name of file */
  10198.         varnam[0] = '%';
  10199.         varnam[2] = '\0';
  10200.         debug(F110,"take arg 0",s,0);
  10201.         debug(F110,"take args",p,0);
  10202.         for (y = 1; y < 10; y++) { /* Clear current args %1..%9 */
  10203.             varnam[1] = (char) (y + '0');
  10204.             delmac(varnam,0);
  10205.         }
  10206.         xwords(p,MAXARGLIST,NULL,0); /* Assign new args */
  10207.         debug(F110,"take args",p,0);
  10208. #else
  10209. /*
  10210.   This method is used in 8.0.  If the TAKE command includes arguments, we
  10211.   insert an intermediate temporary macro between the current level; we pass
  10212.   the arguments to the macro and then the macro TAKEs the command file.
  10213.   If the user Ctrl-C's out of the TAKE file, some temporary macro definitions
  10214.   and other small malloc'd bits might be left behind.
  10215. */
  10216.         {
  10217.             char * q = NULL;
  10218.             char * r = NULL;
  10219.             int k, m;
  10220.             m = maclvl;
  10221.             q = (char *)malloc(x+24);
  10222.             if (q) {
  10223.             r = (char *)malloc(x+24);
  10224.             if (r) {
  10225.                 sprintf(q,"_file[%s](%d)",s,cmdlvl); /* safe */
  10226.                 sprintf(r,"take %s",s); /* safe */
  10227.                 k = addmac(q,r);
  10228.                 if (k > -1) {
  10229.                 dodo(k,p,0);
  10230.                 while (maclvl > m) {
  10231.                     sstate = (CHAR) parser(1);
  10232.                     if (sstate) proto();
  10233.                 }
  10234.                 }
  10235.                 k = delmac(q,0);
  10236.                 free(q);
  10237.                 free(r);
  10238.                 return(success);
  10239.             }
  10240.             }
  10241.         }
  10242.         return(success = 0);
  10243. #endif /* COMMENT */
  10244.         }
  10245.     }
  10246. #else
  10247.     if ((y = cmcfm()) < 0) return(y);
  10248. #endif /* NOTAKEARGS */
  10249.     return(success = dotake(line));
  10250.     }
  10251.  
  10252. #ifndef NOLOCAL
  10253. #ifdef OS2
  10254.     if (cx == XXVIEW) {            /* VIEW Only Terminal mode */
  10255.     viewonly = TRUE;
  10256.     success = doconect(0, 0);
  10257.     viewonly = FALSE;
  10258.     return success;
  10259.     }
  10260. #endif /* OS2 */
  10261.  
  10262. #ifdef NETCONN
  10263.     if (cx == XXTEL || cx == XXIKSD) {    /* TELNET */
  10264.     int x,z;
  10265. #ifdef OS2
  10266.     if (!tcp_avail) {
  10267.         printf("?Sorry, either TCP/IP is not available on this system or\n\
  10268. necessary DLLs did not load.  Use SHOW NETWORK to check network status.\n");
  10269.         success = 0;
  10270.         return(-9);
  10271.     } else
  10272. #endif /* OS2 */
  10273.       {
  10274.       x = nettype;            /* Save net type in case of failure */
  10275.       z = ttnproto;            /* Save protocol in case of failure */
  10276.       nettype = NET_TCPB;
  10277.       ttnproto = (cx == XXTEL) ? NP_TELNET : NP_KERMIT;
  10278.       if ((y = setlin(XYHOST,0,1)) <= 0) {
  10279.               nettype = x;        /* Failed, restore net type. */
  10280.               ttnproto = z;        /* and protocol */
  10281.               success = 0;
  10282.       }
  10283.       didsetlin++;
  10284.         }
  10285.     return(y);
  10286.     }
  10287.  
  10288. #ifndef PTYORPIPE
  10289. #ifdef NETCMD
  10290. #define PTYORPIPE
  10291. #else
  10292. #ifdef NETPTY
  10293. #define PTYORPIPE
  10294. #endif /* NETPTY */
  10295. #endif /* NETCMD */
  10296. #endif /* PTYORPIPE */
  10297.  
  10298. #ifdef PTYORPIPE
  10299.     if (cx == XXPIPE || cx == XXPTY) {    /* PIPE or PTY */
  10300.     int x;
  10301.     extern int netsave;
  10302.     x = nettype;            /* Save net type in case of failure */
  10303.     nettype = (cx == XXPIPE) ? NET_CMD : NET_PTY;
  10304.     if ((y = setlin(XYHOST,0,1)) < 0) {
  10305.         nettype = x;        /* Failed, restore net type. */
  10306.         ttnproto = z;        /* and protocol */
  10307.         success = 0;
  10308.     }
  10309.     didsetlin++;
  10310.     netsave = x;
  10311.     return(y);
  10312.     }
  10313. #endif /* PTYORPIPE */
  10314.  
  10315. #ifdef ANYSSH
  10316.     if (cx == XXSSH) {            /* SSH (Secure Shell) */
  10317.     extern int netsave;
  10318. #ifdef SSHBUILTIN
  10319.     int k, x, havehost = 0, trips = 0;
  10320.         int    tmpver = -1, tmpxfw = -1;
  10321. #ifndef SSHTEST
  10322.         extern int sl_ssh_xfw, sl_ssh_xfw_saved;
  10323.         extern int sl_ssh_ver, sl_ssh_ver_saved;
  10324. #endif /* SSHTEST */
  10325.         extern int mdmtyp, mdmsav, cxtype, sl_uid_saved;
  10326.         extern char * slmsg;
  10327.     extern char uidbuf[], sl_uidbuf[];
  10328.         extern char pwbuf[], * g_pswd;
  10329.         extern int pwflg, pwcrypt, g_pflg, g_pcpt, nolocal;
  10330.     struct FDB sw, kw, fl;
  10331.  
  10332.         if (ssh_tmpstr)
  10333.       memset(ssh_tmpstr,0,strlen(ssh_tmpstr));
  10334.         makestr(&ssh_tmpstr,NULL);
  10335.         makestr(&ssh_tmpuid,NULL);
  10336.         makestr(&ssh_tmpcmd,NULL);
  10337.         makestr(&ssh_tmpport,NULL);
  10338.  
  10339.     cmfdbi(&kw,            /* 1st FDB - commands */
  10340.            _CMKEY,            /* fcode */
  10341.            "host [ port ],\n or action",    /* hlpmsg */
  10342.            "",            /* default */
  10343.            "",            /* addtl string data */
  10344.            nsshcmd,            /* addtl numeric data 1: tbl size */
  10345.            0,            /* addtl numeric data 2: 0 = keyword */
  10346.            xxstring,        /* Processing function */
  10347.            sshkwtab,        /* Keyword table */
  10348.            &fl            /* Pointer to next FDB */
  10349.            );
  10350.     cmfdbi(&fl,            /* Host */
  10351.            _CMFLD,            /* fcode */
  10352.            "",            /* hlpmsg */
  10353.            "",            /* default */
  10354.            "",            /* addtl string data */
  10355.            0,            /* addtl numeric data 1 */
  10356.            0,            /* addtl numeric data 2 */
  10357.            xxstring,
  10358.            NULL,
  10359.            NULL
  10360.            );
  10361.  
  10362.     x = cmfdb(&kw);
  10363.     if (x == -3) {
  10364.         printf("?ssh what?\n");
  10365.         return(-9);
  10366.     }
  10367.     if (x < 0)
  10368.       return(x);
  10369.     havehost = 0;
  10370.     if (cmresult.fcode == _CMFLD) {
  10371.         havehost = 1;
  10372.         ckstrncpy(line,cmresult.sresult,LINBUFSIZ); /* Hostname */
  10373.         cmresult.nresult = XSSH_OPN;
  10374.     }
  10375.     switch (cmresult.nresult) {    /* SSH keyword */
  10376.       case XSSH_OPN:        /* SSH OPEN */
  10377.         if (!havehost) {
  10378.         if ((x = cmfld("Host","",&s,xxstring)) < 0)
  10379.           return(x);
  10380.         ckstrncpy(line,s,LINBUFSIZ);
  10381.         }
  10382.         /* Parse [ port ] [ switches ] */
  10383.         cmfdbi(&kw,            /* Switches */
  10384.            _CMKEY,
  10385.            "Port number or service name,\nor switch",
  10386.            "",
  10387.            "",
  10388.            nsshopnsw,
  10389.            4,
  10390.            xxstring,
  10391.            sshopnsw,
  10392.            &fl
  10393.            );
  10394.         cmfdbi(&fl,            /* Port number or service name */
  10395.            _CMFLD,
  10396.            "",
  10397.            "",
  10398.            "",
  10399.            0,
  10400.            0,
  10401.            xxstring,
  10402.            NULL,
  10403.            NULL
  10404.            );
  10405.         trips = 0;            /* Explained below */
  10406.         while (1) {            /* Parse port and switches */
  10407.         x = cmfdb(&kw);        /* Get a field */
  10408.         if (x == -3)        /* User typed CR so quit from loop */
  10409.           break;
  10410.         if (x < 0)        /* Other parse error, pass it back */
  10411.           return(x);
  10412.         switch (cmresult.fcode) { /* Field or Keyword? */
  10413.                   case _CMFLD:          /* Field */
  10414.                     makestr(&ssh_tmpport,cmresult.sresult);
  10415.             break;
  10416.           case _CMKEY:        /* Keyword */
  10417.             switch (cmresult.nresult) {    /* Which one? */
  10418.               case SSHSW_USR:            /* /USER: */
  10419.             if (!cmgbrk()) {
  10420.                 printf("?This switch requires an argument\n");
  10421.                 return(-9);
  10422.             }
  10423.             if ((y = cmfld("Username","",&s,xxstring)) < 0)
  10424.               return(y);
  10425.             s = brstrip(s);
  10426.             makestr(&ssh_tmpuid,s);
  10427.             break;
  10428.                       case SSHSW_PWD:
  10429.             if (!cmgbrk()) {
  10430.                 printf("?This switch requires an argument\n");
  10431.                 return(-9);
  10432.             }
  10433.             debok = 0;
  10434.             if ((x = cmfld("Password","",&s,xxstring)) < 0) {
  10435.                 if (x == -3) {
  10436.                 makestr(&ssh_tmpstr,"");
  10437.                 } else {
  10438.                 return(x);
  10439.                 }
  10440.             } else {
  10441.                 s = brstrip(s);
  10442.                 if ((x = (int)strlen(s)) > PWBUFL) {
  10443.                 makestr(&slmsg,"Internal error");
  10444.                 printf("?Sorry, too long - max = %d\n",PWBUFL);
  10445.                 return(-9);
  10446.                 }
  10447.                 makestr(&ssh_tmpstr,s);
  10448.             }
  10449.             break;
  10450.  
  10451.               case SSHSW_VER:
  10452.             if ((x = cmnum("Number","",10,&z,xxstring)) < 0)
  10453.               return(x);
  10454.             if (z < 1 || z > 2) {
  10455.                 printf("?Out of range: %d\n",z);
  10456.                 return(-9);
  10457.             }
  10458.                         tmpver = z;
  10459.             break;
  10460.               case SSHSW_CMD:
  10461.               case SSHSW_SUB:
  10462.             if ((x = cmfld("Text","",&s,xxstring)) < 0)
  10463.               return(x);
  10464.                         makestr(&ssh_tmpcmd,s);
  10465.             ssh_cas = (cmresult.nresult == SSHSW_SUB);
  10466.             break;
  10467.               case SSHSW_X11:
  10468.             if ((x = cmkey(onoff,2,"","on",xxstring)) < 0)
  10469.               return(x);
  10470.                         tmpxfw = x;
  10471.             break;
  10472.               default:
  10473.                 return(-2);
  10474.             }
  10475.         }
  10476.         if (trips++ == 0) {    /* After first time through */
  10477.             cmfdbi(&kw,        /* only parse switches, not port. */
  10478.                _CMKEY,
  10479.                "Switch",
  10480.                "",
  10481.                "",
  10482.                nsshopnsw,
  10483.                4,
  10484.                xxstring,
  10485.                sshopnsw,
  10486.                NULL
  10487.                );
  10488.         }
  10489.         }
  10490.         if ((x = cmcfm()) < 0)    /* Get confirmation */
  10491.           return(x);
  10492.             if (clskconnx(1) < 0) {    /* Close current Kermit connection */
  10493.               if ( ssh_tmpstr ) {
  10494.                   memset(ssh_tmpstr,0,strlen(ssh_tmpstr));
  10495.                   makestr(&ssh_tmpstr,NULL);
  10496.               }
  10497.               return(success = 0);
  10498.             }
  10499.         makestr(&ssh_hst,line);    /* Stash everything */
  10500.         if (ssh_tmpuid) {
  10501.                 if (!sl_uid_saved) {
  10502.                     ckstrncpy(sl_uidbuf,uidbuf,UIDBUFLEN);
  10503.                     sl_uid_saved = 1;
  10504.                 }
  10505.         ckstrncpy(uidbuf,ssh_tmpuid,UIDBUFLEN);
  10506.         makestr(&ssh_tmpuid,NULL);
  10507.         }
  10508.             if (ssh_tmpport) {
  10509.                 makestr(&ssh_prt,ssh_tmpport);
  10510.                 makestr(&ssh_tmpport,NULL);
  10511.             } else
  10512.                 makestr(&ssh_prt,NULL);
  10513.  
  10514.             if (ssh_tmpcmd) {
  10515.                 makestr(&ssh_cmd,brstrip(ssh_tmpcmd));
  10516.                 makestr(&ssh_tmpcmd,NULL);
  10517.             } else
  10518.                 makestr(&ssh_cmd,NULL);
  10519.  
  10520.             if (tmpver > -1) {
  10521. #ifndef SSHTEST
  10522.                 if (!sl_ssh_ver_saved) {
  10523.                     sl_ssh_ver = ssh_ver;
  10524.                     sl_ssh_ver_saved = 1;
  10525.                 }
  10526. #endif /* SSHTEST */
  10527.                 ssh_ver = tmpver;
  10528.             }
  10529.             if (tmpxfw > -1) {
  10530. #ifndef SSHTEST
  10531.                 if (!sl_ssh_xfw_saved) {
  10532.                     sl_ssh_xfw = ssh_xfw;
  10533.                     sl_ssh_xfw_saved = 1;
  10534.                 }
  10535. #endif /* SSHTEST */
  10536.                 ssh_xfw = tmpxfw;
  10537.             }
  10538.         if (ssh_tmpstr) {
  10539.         if (ssh_tmpstr[0]) {
  10540.             ckstrncpy(pwbuf,ssh_tmpstr,PWBUFL+1);
  10541.             pwflg = 1;
  10542.             pwcrypt = 0;
  10543.         } else
  10544.           pwflg = 0;
  10545.         makestr(&ssh_tmpstr,NULL);
  10546.         }
  10547.         nettype = NET_SSH;
  10548.         if (mdmsav < 0)
  10549.           mdmsav = mdmtyp;
  10550.         mdmtyp = -nettype;
  10551.         x = 1;
  10552.  
  10553. #ifndef NOSPL
  10554.             makestr(&g_pswd,pwbuf);             /* Save global pwbuf */
  10555.             g_pflg = pwflg;                     /* and flag */
  10556.             g_pcpt = pwcrypt;
  10557. #endif /* NOSPL */
  10558.  
  10559.         /* Line parameter to ttopen() is ignored */
  10560.         k = ttopen(line,&x,mdmtyp, 0);
  10561.         if (k < 0) {
  10562.         printf("?Unable to connect to %s\n",ssh_hst);
  10563.         mdmtyp = mdmsav;
  10564.                 slrestor();
  10565.         return(success = 0);
  10566.         }
  10567.         duplex = 0;             /* Remote echo */
  10568.         ckstrncpy(ttname,line,TTNAMLEN); /* Record the command */
  10569.         debug(F110,"ssh ttname",ttname,0);
  10570.         makestr(&slmsg,NULL);    /* No SET LINE error message */
  10571.         cxtype = CXT_SSH;
  10572. #ifndef NODIAL
  10573.         dialsta = DIA_UNK;
  10574. #endif /* NODIAL */
  10575.         success = 1;        /* SET LINE succeeded */
  10576.         network = 1;        /* Network connection (not serial) */
  10577.         local = 1;            /* Local mode (not remote) */
  10578.         if ((reliable != SET_OFF || !setreliable))
  10579.           reliable = SET_ON;    /* Transport is reliable end to end */
  10580. #ifdef OS2
  10581.             DialerSend(OPT_KERMIT_CONNECT, 0);
  10582. #endif /* OS2 */
  10583.         setflow();            /* Set appropriate flow control */
  10584.  
  10585.         haveline = 1;
  10586. #ifdef CKLOGDIAL
  10587. #ifdef NETCONN
  10588.         dolognet();
  10589. #endif /* NETCONN */
  10590. #endif /* CKLOGDIAL */
  10591.  
  10592. #ifndef NOSPL
  10593.         if (local) {
  10594.         if (nmac) {        /* Any macros defined? */
  10595.             int k;        /* Yes */
  10596.             k = mlook(mactab,"on_open",nmac); /* Look this up */
  10597.             if (k >= 0) {                  /* If found, */
  10598.             if (dodo(k,ssh_hst,0) > -1)   /* set it up, */
  10599.               parser(1);              /* and execute it */
  10600.             }
  10601.         }
  10602.         }
  10603. #endif /* NOSPL */
  10604. #ifdef LOCUS        
  10605.         if (autolocus)
  10606.         setlocus(1,1);
  10607. #endif /* LOCUS */
  10608.  
  10609.     /* Command was confirmed so we can pre-pop command level. */
  10610.     /* This is so CONNECT module won't think we're executing a */
  10611.     /* script if CONNECT was the final command in the script. */
  10612.         if (cmdlvl > 0)
  10613.           prepop();
  10614.         success = doconect(0,cmdlvl == 0 ? 1 : 0);
  10615.         if (ttchk() < 0)
  10616.           dologend();
  10617.         return(success);
  10618.  
  10619.       case XSSH_CLR:
  10620.         if ((y = cmkey(sshclr,nsshclr,"","", xxstring)) < 0) {
  10621.             if (y == -3) {
  10622.             printf("?clear what?\n");
  10623.             return(-9);
  10624.         }
  10625.             return(y);
  10626.         }
  10627.         if ((x = cmcfm()) < 0)
  10628.           return(x);
  10629.         switch (y) {
  10630.           case SSHC_LPF:
  10631.                 ssh_pf_lcl_n = 0;
  10632.         break;
  10633.           case SSHC_RPF:
  10634.         ssh_pf_rmt_n = 0;
  10635.         break;
  10636.           default:
  10637.         return(-2);
  10638.         }
  10639.             return(success = 1);    /* or whatever */
  10640.  
  10641.       case XSSH_AGT: {        /* SSH AGENT */
  10642.           int doeach = 0;
  10643.           if ((y = cmkey(sshagent,nsshagent,"","",xxstring)) < 0)
  10644.         return(y);
  10645.           switch (y) {
  10646.         case SSHA_ADD:        /* SSH AGENT ADD ... */
  10647.           if ((x = cmifi("Identity file","",&s,&y,xxstring)) < 0) {
  10648. #ifndef SSHTEST
  10649.               if (x == -3)    /* No name given */
  10650.             doeach = 1;    /* so do them all */
  10651.               else
  10652. #endif /* SSHTEST */
  10653.             return(x);
  10654.           }
  10655.           ckstrncpy(line,s,LINBUFSIZ);
  10656.           if ((x = cmcfm()) < 0)
  10657.             return(x);
  10658. #ifdef SSHTEST
  10659.           x = 0;
  10660. #else
  10661.           if (doeach) {
  10662.                       int i;
  10663.                       x = 0;
  10664.                       for (i = 0; i < ssh_idf_n; i++)
  10665.             x += ssh_agent_add_file(ssh_idf[i]);
  10666.           } else
  10667.             x = ssh_agent_add_file(line);
  10668. #endif /* SSHTEST */
  10669.           return(success = (x == 0));
  10670.  
  10671.         case SSHA_DEL: {    /* SSH AGENT DELETE ... */
  10672.             int doall = 0;
  10673.             if ((x = cmifi("Identity file","",&s,&y,xxstring)) < 0) {
  10674. #ifndef SSHTEST
  10675.             if (x == -3)    /* No name given */
  10676.               doall = 1;    /* so do them all */
  10677.             else
  10678. #endif /* SSHTEST */
  10679.               return(x);
  10680.             }
  10681.             ckstrncpy(line,s,LINBUFSIZ);
  10682.             if ((x = cmcfm()) < 0)
  10683.               return(x);
  10684. #ifdef SSHTEST
  10685.             x = 0;
  10686. #else
  10687.             if (doall)
  10688.               x = ssh_agent_delete_all();
  10689.             else
  10690.               x = ssh_agent_delete_file(line);
  10691. #endif /* SSHTEST */
  10692.             return(success = (x == 0));
  10693.         }
  10694.         case SSHA_LST: {
  10695.             int fingerprint = 0;
  10696.             if ((y = cmswi(sshagtsw,nsshagtsw,"","",xxstring)) < 0) {
  10697.             if (y != -3)
  10698.               return(y);
  10699.             } else if (cmgbrk() > SP) {
  10700.             printf("?This switch does not take an argument\n");
  10701.             return(-9);
  10702.             } else if (y == SSHASW_FP) {
  10703.             fingerprint = 1;
  10704.             }
  10705.             if ((x = cmcfm()) < 0)
  10706.               return(x);
  10707. #ifdef SSHTEST
  10708.             return(success = 1);
  10709. #else
  10710.             return(success =
  10711.                (ssh_agent_list_identities(fingerprint) == 0));
  10712. #endif /* SSHTEST */
  10713.         }
  10714.         default:
  10715.           return(-2);
  10716.           }
  10717.       }
  10718.       case XSSH_ADD: {        /* SSH ADD */
  10719.           /* ssh add { local, remote } port host port */
  10720.           int cx, i, j, k;
  10721.           char * h;
  10722.           if ((cx = cmkey(addfwd,naddfwd,"","", xxstring)) < 0)
  10723.         return(cx);
  10724.           if ((x = cmnum((cx == SSHF_LCL) ?
  10725.                  "Local port number" : "Remote port number",
  10726.                  "",10,&j,xxstring)) < 0)
  10727.         return(x);
  10728.           if ((x = cmfld("Host","",&s,xxstring)) < 0)
  10729.         return(x);
  10730.           makestr(&h,s);
  10731.           if ((x = cmnum("Port","",10,&k,xxstring)) < 0)
  10732.         return(x);
  10733.           if ((x = cmcfm()) < 0)
  10734.         return(x);
  10735.  
  10736.           switch(cx) {
  10737.         case SSHF_LCL:
  10738.            if (ssh_pf_lcl_n == 32) {
  10739.                printf(
  10740. "?Maximum number of local port forwardings already specified\n"
  10741.                  );
  10742.                free(h);
  10743.                return(success = 0);
  10744.           }
  10745.           ssh_pf_lcl[ssh_pf_lcl_n].p1 = j;
  10746.           makestr(&(ssh_pf_lcl[ssh_pf_lcl_n].host),h);
  10747.           makestr(&h,NULL);
  10748.           ssh_pf_lcl[ssh_pf_lcl_n].p2 = k;
  10749.           ssh_pf_lcl_n++;
  10750.           break;
  10751.         case SSHF_RMT:
  10752.           if (ssh_pf_rmt_n == 32) {
  10753.               printf(
  10754. "?Maximum number of remote port forwardings already specified\n"
  10755.                 );
  10756.               free(h);
  10757.               return(success = 0);
  10758.           }
  10759.           ssh_pf_rmt[ssh_pf_rmt_n].p1 = j;
  10760.           makestr(&(ssh_pf_rmt[ssh_pf_rmt_n].host),h);
  10761.           makestr(&h,NULL);
  10762.           ssh_pf_rmt[ssh_pf_rmt_n].p2 = k;
  10763.           ssh_pf_rmt_n++;
  10764.           }
  10765.           return(success = 1);
  10766.       }
  10767.       /* Not supporting arbitrary forwarding yet */
  10768.       case XSSH_FLP:        /* SSH FORWARD-LOCAL-PORT */
  10769.       case XSSH_FRP: {        /* SSH FORWARD-REMOTE-PORT */
  10770.           int li_port = 0;
  10771.           int to_port = 0;
  10772.           char * fw_host = NULL;
  10773.           int n;
  10774.               if ((x = cmnum(cmresult.nresult == XSSH_FLP ?
  10775.                               "local-port":"remote-port",
  10776.                               "",10,&li_port,xxstring)) < 0)
  10777.                   return(x);
  10778.               if (li_port < 1 || li_port > 65535) {
  10779.                   printf("?Out range - min: 1, max: 65535\n");
  10780.                   return(-9);
  10781.               }
  10782.           if ((x = cmfld("host",ssh_hst?ssh_hst:"",&s,xxstring)) < 0)
  10783.         return(x);
  10784.               n = ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  10785.               fw_host = tmpbuf;
  10786.               if ((x = cmnum("host-port",ckuitoa(li_port),10,
  10787.                               &to_port,xxstring)) < 0)
  10788.                   return(x);
  10789.               if (to_port < 1 || to_port > 65535) {
  10790.                   printf("?Out range - min: 1, max: 65535\n");
  10791.                   return(-9);
  10792.               }
  10793.           if ((x = cmcfm()) < 0)
  10794.         return(x);
  10795.           switch (cmresult.nresult) {
  10796.                 case XSSH_FLP:    /* SSH FORWARD-LOCAL-PORT */
  10797. #ifndef SSHTEST
  10798.                   ssh_fwd_local_port(li_port,fw_host,to_port);
  10799. #endif /* SSHTEST */
  10800.           return(success = 1);
  10801.         case XSSH_FRP:    /* SSH FORWARD-REMOTE-PORT */
  10802. #ifndef SSHTEST
  10803.                   ssh_fwd_remote_port(li_port,fw_host,to_port);
  10804. #endif /* SSHTEST */
  10805.           return(success = 1);
  10806.           }
  10807.           return(success = 1);
  10808.       }
  10809.     case XSSH_V2:        /* SSH V2 */
  10810.       if ((cx = cmkey(ssh2tab,nssh2tab,"","", xxstring)) < 0)
  10811.         return(cx);
  10812.       switch (cx) {
  10813.         case XSSH2_RKE:
  10814.           if ((x = cmcfm()) < 0)
  10815.         return(x);
  10816. #ifndef SSHTEST
  10817.           ssh_v2_rekey();
  10818. #endif /* SSHTEST */
  10819.           return(success = 1);
  10820.         default:
  10821.           return(-2);
  10822.       }
  10823.     case XSSH_KEY:
  10824.       if ((cx = cmkey(sshkey,nsshkey,"","", xxstring)) < 0)
  10825.         return(cx);
  10826.       switch (cx) {
  10827.         case SSHK_PASS: {    /* Change passphrase */
  10828.           char * oldp = NULL, * newp = NULL;
  10829.           struct FDB df, sw;
  10830.           cmfdbi(&sw,
  10831.              _CMKEY,        /* fcode */
  10832.              "Filename, or switch", /* hlpmsg */
  10833.              "",        /* default */
  10834.              "",        /* addtl string data */
  10835.              2,            /* addtl numeric data 1: tbl size */
  10836.              4,            /* addtl numeric data 2: 4 = cmswi */
  10837.              xxstring,        /* Processing function */
  10838.              sshkpsw,        /* Keyword table */
  10839.              &df        /* Pointer to next FDB */
  10840.              );
  10841.           cmfdbi(&df,        /* 2nd FDB - file for display */
  10842.              _CMIFI,        /* output file */
  10843.              "",        /* hlpmsg */
  10844.              "",        /* default */
  10845.              "",        /* addtl string data */
  10846.              0,            /* addtl numeric data 1 */
  10847.              0,            /* addtl numeric data 2 */
  10848.              xxstring,
  10849.              NULL,
  10850.              NULL
  10851.              );
  10852.           line[0] = NUL;
  10853.  
  10854.           while (1) {
  10855.           x = cmfdb(&sw);
  10856.           if (x == -3) break;
  10857.           if (x < 0)
  10858.             return(x);
  10859.           if (cmresult.fcode != _CMKEY)
  10860.             break;
  10861.           if (!cmgbrk()) {
  10862.               printf("?This switch requires an argument\n");
  10863.               return(-9);
  10864.           }
  10865.           if ((y = cmfld("Passphrase","",&s,xxstring)) < 0)
  10866.             return(y);
  10867.           switch (cmresult.nresult) {
  10868.             case 1:        /* Old */
  10869.               makestr(&oldp,s);
  10870.               break;
  10871.             case 2:        /* New */
  10872.               makestr(&newp,s);
  10873.           }
  10874.           }
  10875.           if (cmresult.fcode == _CMIFI) { /* Filename */
  10876.           ckstrncpy(line,cmresult.sresult,LINBUFSIZ);
  10877.           if (zfnqfp(line,TMPBUFSIZ,tmpbuf))
  10878.             ckstrncpy(line,tmpbuf,LINBUFSIZ);
  10879.           }
  10880.           if ((x = cmcfm()) < 0) return(x);
  10881.  
  10882. #ifndef SSHTEST
  10883.           x = sshkey_change_passphrase(line[0] ? line : NULL,
  10884.                          oldp, newp);
  10885. #endif /* SSHTEST */
  10886.           makestr(&oldp,NULL);
  10887.           makestr(&newp,NULL);
  10888.           success = (x == 0);
  10889.           return(success);
  10890.         }
  10891.         case SSHK_CREA: {    /* SSH KEY CREATE /switches... */
  10892.           int bits = 1024, keytype = SSHKT_2R;
  10893.           char * pass = NULL, * comment = NULL;
  10894.           struct FDB df, sw;
  10895.  
  10896.               /*
  10897.                * char * sshkey_default_file(int keytype) 
  10898.                * will provide the default filename for a given keytype
  10899.                * is it possible to have the default value for the 2nd
  10900.                * FDB set and changed when a /TYPE switch is provided?
  10901.                * Would this allow for tab completion of the filename?
  10902.                */
  10903.           cmfdbi(&sw,
  10904.              _CMKEY,        /* fcode */
  10905.              "Filename, or switch", /* hlpmsg */
  10906.              "",        /* default */
  10907.              "",        /* addtl string data */
  10908.              nsshkcrea,        /* addtl numeric data 1: tbl size */
  10909.              4,            /* addtl numeric data 2: 4 = cmswi */
  10910.              xxstring,        /* Processing function */
  10911.              sshkcrea,        /* Keyword table */
  10912.              &df        /* Pointer to next FDB */
  10913.              );
  10914.           cmfdbi(&df,        /* 2nd FDB - file for display */
  10915.              _CMOFI,        /* output file */
  10916.              "",        /* hlpmsg */
  10917.              "",        /* default */
  10918.              "",        /* addtl string data */
  10919.              0,            /* addtl numeric data 1 */
  10920.              0,            /* addtl numeric data 2 */
  10921.              xxstring,
  10922.              NULL,
  10923.              NULL
  10924.              );
  10925.           line[0] = NUL;
  10926.  
  10927.           while (1) {
  10928.           x = cmfdb(&sw);
  10929.           if (x == -3) break;
  10930.           if (x < 0)
  10931.             return(x);
  10932.           if (cmresult.fcode != _CMKEY)
  10933.             break;
  10934.           if (!cmgbrk()) {
  10935.               printf("?This switch requires an argument\n");
  10936.               return(-9);
  10937.           }
  10938.           switch (cmresult.nresult) {
  10939.             case SSHKC_BI:    /* /BITS:n */
  10940.               if ((y = cmnum("","1024",10,&z,xxstring)) < 0)
  10941.             return(y);
  10942.               if (z < 512 || z > 4096) {
  10943.               printf("?Out range - min: 512, max: 4096\n");
  10944.               return(-9);
  10945.               }
  10946.               bits = z;
  10947.               break;
  10948.             case SSHKC_PP:    /* /PASSPHRASE:blah */
  10949.               if ((y = cmfld("Passphrase","",&s,xxstring)) < 0)
  10950.             return(y);
  10951.               makestr(&pass,s);
  10952.               break;
  10953.             case SSHKC_TY:    /* /TYPE:keyword */
  10954.               if ((y = cmkey(sshkcty,nsshkcty,"",
  10955.                      "v2-rsa",xxstring)) < 0)
  10956.             return(y);
  10957.               keytype = y;
  10958.               break;
  10959.             case SSHKC_1R:    /* /COMMENT */
  10960.               if ((y = cmfld("Text","",&s,xxstring)) < 0)
  10961.             return(y);
  10962.               makestr(&comment,s);
  10963.               break;
  10964.           }
  10965.           }
  10966.           if (cmresult.fcode == _CMOFI) { /* Filename */
  10967.                   if (cmresult.sresult) {
  10968.                       ckstrncpy(line,cmresult.sresult,LINBUFSIZ);
  10969.                       if (zfnqfp(line,TMPBUFSIZ,tmpbuf))
  10970.                           ckstrncpy(line,tmpbuf,LINBUFSIZ);
  10971.           }
  10972.           }
  10973.           if ((y = cmcfm()) < 0) /* Confirm */
  10974.         return(y);
  10975. #ifndef SSHTEST
  10976.           x = sshkey_create(line[0] ? line : NULL,
  10977.                 bits, pass, keytype, comment);
  10978.           if (pass)
  10979.         memset(pass,0,strlen(pass));
  10980. #endif /* SSHTEST */
  10981.           makestr(&pass,NULL);
  10982.           makestr(&comment,NULL);
  10983.           return(success = (x == 0));
  10984.         }
  10985.         case SSHK_DISP: {    /* SSH KEY DISPLAY /switches... */
  10986.           char c;
  10987.           int infmt = 0, outfmt = 0;
  10988.           struct FDB df, sw;
  10989.           cmfdbi(&sw,
  10990.              _CMKEY,        /* fcode */
  10991.              "Filename, or switch", /* hlpmsg */
  10992.              "",        /* default */
  10993.              "",        /* addtl string data */
  10994.              nsshdswi,        /* addtl numeric data 1: tbl size */
  10995.              4,            /* addtl numeric data 2: 4 = cmswi */
  10996.              xxstring,        /* Processing function */
  10997.              sshdswi,        /* Keyword table */
  10998.              &df        /* Pointer to next FDB */
  10999.              );
  11000.           cmfdbi(&df,        /* 2nd FDB - file for display */
  11001.              _CMIFI,        /* fcode */
  11002.              "",        /* hlpmsg */
  11003.              "",        /* default */
  11004.              "",        /* addtl string data */
  11005.              0,            /* addtl numeric data 1 */
  11006.              0,            /* addtl numeric data 2 */
  11007.              xxstring,
  11008.              NULL,
  11009.              NULL
  11010.              );
  11011.           line[0] = NUL;
  11012.  
  11013.           while (1) {
  11014.           x = cmfdb(&sw);
  11015.           if (x == -3) break;
  11016.           if (x < 0)
  11017.             return(x);
  11018.           if (cmresult.fcode != _CMKEY)
  11019.             break;
  11020.           if (!cmgbrk()) {
  11021.               printf("?This switch requires an argument\n");
  11022.               return(-9);
  11023.           }
  11024.           switch (cmresult.nresult) {
  11025. #ifdef COMMENT
  11026.             case SSHKD_IN:    /* /IN-FORMAT: */
  11027.               if ((y = cmkey(sshdifmt,nsshdifmt,
  11028.                      "","",xxstring)) < 0)
  11029.             return(y);
  11030.               infmt = y;
  11031.               break;
  11032. #endif /* COMMENT */
  11033.             case SSHKD_OUT:    /* /FORMAT: */
  11034.               if ((y = cmkey(sshdofmt,nsshdofmt,
  11035.                      "","",xxstring)) < 0)
  11036.             return(y);
  11037.               outfmt = y;
  11038.               break;
  11039.           }
  11040.           }
  11041.           if (cmresult.fcode == _CMIFI) { /* Filename */
  11042.           ckstrncpy(line,cmresult.sresult,LINBUFSIZ);
  11043.           if (zfnqfp(line,TMPBUFSIZ,tmpbuf))
  11044.             ckstrncpy(line,tmpbuf,LINBUFSIZ);
  11045.           }
  11046. #ifdef COMMENT
  11047.           if (!line[0]) {
  11048.           printf("?Key filename required\n");
  11049.           return(-9);
  11050.           }
  11051. #endif /* COMMENT */
  11052.           if ((y = cmcfm()) < 0) /* Confirm */
  11053.         return(y);
  11054. #ifndef SSHTEST
  11055.           switch (outfmt) {
  11056.         case SKDF_OSSH:
  11057.                   /* 2nd param is optional passphrase */
  11058.           x = sshkey_display_public(line[0] ? line : NULL, NULL);
  11059.           break;
  11060.         case SKDF_SSHC:
  11061.                   /* 2nd param is optional passphrase */
  11062.           x = sshkey_display_public_as_ssh2(line[0] ? line : NULL,
  11063.                             NULL);
  11064.           break;
  11065.         case SKDF_IETF:
  11066.           x = sshkey_display_fingerprint(line[0] ? line : NULL, 1);
  11067.           break;
  11068.         case SKDF_FING:
  11069.           x = sshkey_display_fingerprint(line[0] ? line : NULL, 0);
  11070.           break;
  11071.           }
  11072. #endif /* SSHTEST */
  11073.           return(success = (x == 0));
  11074.         }
  11075.         case SSHK_V1:        /* SSH KEY V1 SET-COMMENT */
  11076.           if ((x = cmkey(sshkv1,1,"","set-comment", xxstring)) < 0)
  11077.         return(x);
  11078.           if (x != 1) return(-2);
  11079.           if ((x = cmifi("Key file name","",&s,&y,xxstring)) < 0) {
  11080.           if (x == -3) {
  11081.               printf("?Name of key file required\n");
  11082.               return(-9);
  11083.           }
  11084.           }
  11085.           ckstrncpy(line,s,LINBUFSIZ);
  11086.           if ((x = cmtxt("Comment text","",&s,xxstring)) < 0)
  11087.         return(x);
  11088. #ifndef SSHTEST
  11089.           x = sshkey_v1_change_comment(line,  /* filename */
  11090.                        s,     /* new comment */
  11091.                        NULL   /* passphrase */
  11092.                        );
  11093. #endif /* SSHTEST */
  11094.           success = (x == 0);
  11095.           return(success);
  11096.       }
  11097.       default:
  11098.         return(-2);
  11099.     }
  11100. #else  /* SSHBUILTIN */
  11101. #ifdef SSHCMD
  11102.     x = nettype;
  11103.     if ((y = setlin(XXSSH,0,1)) < 0) {
  11104.         if (errno)
  11105.           printf("?%s\n",ck_errstr());
  11106.             else
  11107. #ifdef COMMENT
  11108.         /* This isn't right either because it catches command editing */
  11109.           printf("?Sorry, pseudoterminal open failed\n");
  11110.             if (hints)
  11111.           printf("Hint: Try \"ssh -t %s\"\n",line);
  11112. #else
  11113.           return(y);
  11114. #endif /* COMMENT */
  11115.         nettype = x;        /* Failed, restore net type. */
  11116.         ttnproto = z;        /* and protocol */
  11117.         success = 0;
  11118.     }
  11119.     didsetlin++;
  11120.     netsave = x;
  11121.     return(y);
  11122. #endif /* SSHCMD */
  11123. #endif /* SSHBUILTIN */
  11124.     }
  11125. #endif /* ANYSSH */
  11126.  
  11127. #ifdef SSHBUILTIN
  11128.     if (cx == XXSKRM) {            /* SKERMIT (Secure Shell Kermit) */
  11129.     extern int netsave;
  11130.     int k, x, havehost = 0, trips = 0;
  11131.         int    tmpver = -1, tmpxfw = -1;
  11132. #ifndef SSHTEST
  11133.         extern int sl_ssh_xfw, sl_ssh_xfw_saved;
  11134.         extern int sl_ssh_ver, sl_ssh_ver_saved;
  11135. #endif /* SSHTEST */
  11136.         extern int mdmtyp, mdmsav, cxtype, sl_uid_saved;
  11137.         extern char * slmsg;
  11138.     extern char uidbuf[], sl_uidbuf[];
  11139.         extern char pwbuf[], * g_pswd;
  11140.         extern int pwflg, pwcrypt, g_pflg, g_pcpt, nolocal;
  11141.     struct FDB sw, kw, fl;
  11142.  
  11143.         if (ssh_tmpstr)
  11144.       memset(ssh_tmpstr,0,strlen(ssh_tmpstr));
  11145.         makestr(&ssh_tmpstr,NULL);
  11146.         makestr(&ssh_tmpuid,NULL);
  11147.         makestr(&ssh_tmpcmd,NULL);
  11148.         makestr(&ssh_tmpport,NULL);
  11149.  
  11150.     cmfdbi(&kw,            /* 1st FDB - commands */
  11151.            _CMKEY,            /* fcode */
  11152.            "host [ port ],\n or action", /* hlpmsg */
  11153.            "",            /* default */
  11154.            "",            /* addtl string data */
  11155.            nsshkermit,        /* addtl numeric data 1: tbl size */
  11156.            0,            /* addtl numeric data 2: 0 = keyword */
  11157.            xxstring,        /* Processing function */
  11158.            sshkermit,        /* Keyword table */
  11159.            &fl            /* Pointer to next FDB */
  11160.            );
  11161.     cmfdbi(&fl,            /* Host */
  11162.            _CMFLD,            /* fcode */
  11163.            "",            /* hlpmsg */
  11164.            "",            /* default */
  11165.            "",            /* addtl string data */
  11166.            0,            /* addtl numeric data 1 */
  11167.            0,            /* addtl numeric data 2 */
  11168.            xxstring,
  11169.            NULL,
  11170.            NULL
  11171.            );
  11172.  
  11173.     x = cmfdb(&kw);
  11174.     if (x == -3) {
  11175.         printf("?skermit what?\n");
  11176.         return(-9);
  11177.     }
  11178.     if (x < 0)
  11179.       return(x);
  11180.     havehost = 0;
  11181.     if (cmresult.fcode == _CMFLD) {
  11182.         havehost = 1;
  11183.         ckstrncpy(line,cmresult.sresult,LINBUFSIZ); /* Hostname */
  11184.         cmresult.nresult = SKRM_OPN;
  11185.     }
  11186.     switch (cmresult.nresult) {    /* SSH keyword */
  11187.       case SKRM_OPN:        /* SSH OPEN */
  11188.         if (!havehost) {
  11189.         if ((x = cmfld("Host","",&s,xxstring)) < 0)
  11190.           return(x);
  11191.         ckstrncpy(line,s,LINBUFSIZ);
  11192.         }
  11193.         /* Parse [ port ] [ switches ] */
  11194.         cmfdbi(&kw,            /* Switches */
  11195.            _CMKEY,
  11196.            "Port number or service name,\nor switch",
  11197.            "",
  11198.            "",
  11199.            nsshkrmopnsw,
  11200.            4,
  11201.            xxstring,
  11202.            sshkrmopnsw,
  11203.            &fl
  11204.            );
  11205.         cmfdbi(&fl,            /* Port number or service name */
  11206.            _CMFLD,
  11207.            "",
  11208.            "",
  11209.            "",
  11210.            0,
  11211.            0,
  11212.            xxstring,
  11213.            NULL,
  11214.            NULL
  11215.            );
  11216.         trips = 0;            /* Explained below */
  11217.         while (1) {            /* Parse port and switches */
  11218.         x = cmfdb(&kw);        /* Get a field */
  11219.         if (x == -3)        /* User typed CR so quit from loop */
  11220.           break;
  11221.         if (x < 0)        /* Other parse error, pass it back */
  11222.           return(x);
  11223.         switch (cmresult.fcode) { /* Field or Keyword? */
  11224.                   case _CMFLD:          /* Field */
  11225.                     makestr(&ssh_tmpport,cmresult.sresult);
  11226.             break;
  11227.           case _CMKEY:        /* Keyword */
  11228.             switch (cmresult.nresult) {    /* Which one? */
  11229.               case SSHSW_USR:            /* /USER: */
  11230.             if (!cmgbrk()) {
  11231.                 printf("?This switch requires an argument\n");
  11232.                 return(-9);
  11233.             }
  11234.             if ((y = cmfld("Username","",&s,xxstring)) < 0)
  11235.               return(y);
  11236.             s = brstrip(s);
  11237.             makestr(&ssh_tmpuid,s);
  11238.             break;
  11239.                       case SSHSW_PWD:
  11240.             if (!cmgbrk()) {
  11241.                 printf("?This switch requires an argument\n");
  11242.                 return(-9);
  11243.             }
  11244.             debok = 0;
  11245.             if ((x = cmfld("Password","",&s,xxstring)) < 0) {
  11246.                 if (x == -3) {
  11247.                 makestr(&ssh_tmpstr,"");
  11248.                 } else {
  11249.                 return(x);
  11250.                 }
  11251.             } else {
  11252.                 s = brstrip(s);
  11253.                 if ((x = (int)strlen(s)) > PWBUFL) {
  11254.                 makestr(&slmsg,"Internal error");
  11255.                 printf("?Sorry, too long - max = %d\n",PWBUFL);
  11256.                 return(-9);
  11257.                 }
  11258.                 makestr(&ssh_tmpstr,s);
  11259.             }
  11260.             break;
  11261.  
  11262.                     case SSHSW_VER:
  11263.             if ((x = cmnum("Number","",10,&z,xxstring)) < 0)
  11264.               return(x);
  11265.             if (z < 1 || z > 2) {
  11266.                 printf("?Out of range: %d\n",z);
  11267.                 return(-9);
  11268.             }
  11269.                         tmpver = z;
  11270.             break;
  11271.                     default:
  11272.                         return(-2);
  11273.             }
  11274.                   }
  11275.         if (trips++ == 0) {    /* After first time through */
  11276.             cmfdbi(&kw,        /* only parse switches, not port. */
  11277.                _CMKEY,
  11278.                "Switch",
  11279.                "",
  11280.                "",
  11281.                nsshkrmopnsw,
  11282.                4,
  11283.                xxstring,
  11284.                sshkrmopnsw,
  11285.                NULL
  11286.                );
  11287.         }
  11288.         }
  11289.         if ((x = cmcfm()) < 0)    /* Get confirmation */
  11290.           return(x);
  11291.               if (clskconnx(1) < 0) {    /* Close current Kermit connection */
  11292.                   if ( ssh_tmpstr ) {
  11293.                       memset(ssh_tmpstr,0,strlen(ssh_tmpstr));
  11294.                       makestr(&ssh_tmpstr,NULL);
  11295.                   }
  11296.                   return(success = 0);
  11297.               }
  11298.               makestr(&ssh_hst,line);    /* Stash everything */
  11299.               if (ssh_tmpuid) {
  11300.                   if (!sl_uid_saved) {
  11301.                       ckstrncpy(sl_uidbuf,uidbuf,UIDBUFLEN);
  11302.                       sl_uid_saved = 1;
  11303.                   }
  11304.                   ckstrncpy(uidbuf,ssh_tmpuid,UIDBUFLEN);
  11305.                   makestr(&ssh_tmpuid,NULL);
  11306.               }
  11307.               if (ssh_tmpport) {
  11308.                   makestr(&ssh_prt,ssh_tmpport);
  11309.                   makestr(&ssh_tmpport,NULL);
  11310.               } else
  11311.                   makestr(&ssh_prt,NULL);
  11312.  
  11313.               /* Set the Subsystem to Kermit */
  11314.               ssh_cas = 1;
  11315.               makestr(&ssh_cmd,"kermit");
  11316.  
  11317.               if (tmpver > -1) {
  11318. #ifndef SSHTEST
  11319.                   if (!sl_ssh_ver_saved) {
  11320.                       sl_ssh_ver = ssh_ver;
  11321.                       sl_ssh_ver_saved = 1;
  11322.                   }
  11323. #endif /* SSHTEST */
  11324.                   ssh_ver = tmpver;
  11325.               }
  11326.               /* Disable X11 Forwarding */
  11327. #ifndef SSHTEST
  11328.               if (!sl_ssh_xfw_saved) {
  11329.                   sl_ssh_xfw = ssh_xfw;
  11330.                   sl_ssh_xfw_saved = 1;
  11331.               }
  11332. #endif /* SSHTEST */
  11333.               ssh_xfw = 0;
  11334.  
  11335.               if (ssh_tmpstr) {
  11336.                   if (ssh_tmpstr[0]) {
  11337.                       ckstrncpy(pwbuf,ssh_tmpstr,PWBUFL+1);
  11338.                       pwflg = 1;
  11339.                       pwcrypt = 0;
  11340.                   } else
  11341.                       pwflg = 0;
  11342.                   makestr(&ssh_tmpstr,NULL);
  11343.               }
  11344.               nettype = NET_SSH;
  11345.               if (mdmsav < 0)
  11346.                   mdmsav = mdmtyp;
  11347.               mdmtyp = -nettype;
  11348.               x = 1;
  11349.  
  11350. #ifndef NOSPL
  11351.             makestr(&g_pswd,pwbuf);    /* Save global pwbuf */
  11352.             g_pflg = pwflg;        /* and flag */
  11353.             g_pcpt = pwcrypt;
  11354. #endif /* NOSPL */
  11355.  
  11356.         /* Line parameter to ttopen() is ignored */
  11357.         k = ttopen(line,&x,mdmtyp, 0);
  11358.         if (k < 0) {
  11359.         printf("?Unable to connect to %s\n",ssh_hst);
  11360.         mdmtyp = mdmsav;
  11361.                 slrestor();
  11362.         return(success = 0);
  11363.         }
  11364.         duplex = 0;             /* Remote echo */
  11365.         ckstrncpy(ttname,line,TTNAMLEN); /* Record the command */
  11366.         debug(F110,"ssh ttname",ttname,0);
  11367.         makestr(&slmsg,NULL);    /* No SET LINE error message */
  11368.         cxtype = CXT_SSH;
  11369. #ifndef NODIAL
  11370.         dialsta = DIA_UNK;
  11371. #endif /* NODIAL */
  11372.         success = 1;        /* SET LINE succeeded */
  11373.         network = 1;        /* Network connection (not serial) */
  11374.         local = 1;            /* Local mode (not remote) */
  11375.         if ((reliable != SET_OFF || !setreliable))
  11376.           reliable = SET_ON;    /* Transport is reliable end to end */
  11377. #ifdef OS2
  11378.             DialerSend(OPT_KERMIT_CONNECT, 0);
  11379. #endif /* OS2 */
  11380.         setflow();            /* Set appropriate flow control */
  11381.  
  11382.         haveline = 1;
  11383. #ifdef CKLOGDIAL
  11384. #ifdef NETCONN
  11385.         dolognet();
  11386. #endif /* NETCONN */
  11387. #endif /* CKLOGDIAL */
  11388.  
  11389. #ifndef NOSPL
  11390.         if (local) {
  11391.         if (nmac) {        /* Any macros defined? */
  11392.             int k;        /* Yes */
  11393.             k = mlook(mactab,"on_open",nmac); /* Look this up */
  11394.             if (k >= 0) {                  /* If found, */
  11395.             if (dodo(k,ssh_hst,0) > -1)   /* set it up, */
  11396.               parser(1);              /* and execute it */
  11397.             }
  11398.         }
  11399.         }
  11400. #endif /* NOSPL */
  11401. #ifdef LOCUS        
  11402.         if (autolocus)
  11403.         setlocus(1,1);
  11404. #endif /* LOCUS */
  11405.  
  11406.     /* Command was confirmed so we can pre-pop command level. */
  11407.     /* This is so CONNECT module won't think we're executing a */
  11408.     /* script if CONNECT was the final command in the script. */
  11409.         if (cmdlvl > 0)
  11410.           prepop();
  11411.         return(success = 1);
  11412.  
  11413.       default:
  11414.         return(-2);
  11415.     }
  11416.     }
  11417. #endif /* SSHBUILTIN */
  11418.  
  11419. #ifdef SFTP_BUILTIN
  11420.     if (cx == XXSFTP) {            /* SFTP (Secure Shell File Transfer) */
  11421.     extern int netsave;
  11422.     int k, x, havehost = 0, trips = 0;
  11423.         int    tmpver = -1, tmpxfw = -1;
  11424. #ifndef SSHTEST
  11425.         extern int sl_ssh_xfw, sl_ssh_xfw_saved;
  11426.         extern int sl_ssh_ver, sl_ssh_ver_saved;
  11427. #endif /* SSHTEST */
  11428.         extern int mdmtyp, mdmsav, cxtype, sl_uid_saved;
  11429.         extern char * slmsg;
  11430.     extern char uidbuf[], sl_uidbuf[];
  11431.         extern char pwbuf[], * g_pswd;
  11432.         extern int pwflg, pwcrypt, g_pflg, g_pcpt, nolocal;
  11433.     struct FDB sw, kw, fl;
  11434.  
  11435.         if (ssh_tmpstr)
  11436.       memset(ssh_tmpstr,0,strlen(ssh_tmpstr));
  11437.         makestr(&ssh_tmpstr,NULL);
  11438.         makestr(&ssh_tmpuid,NULL);
  11439.         makestr(&ssh_tmpcmd,NULL);
  11440.         makestr(&ssh_tmpport,NULL);
  11441.  
  11442.     cmfdbi(&kw,            /* 1st FDB - commands */
  11443.            _CMKEY,            /* fcode */
  11444.            "host [ port ],\n or action", /* hlpmsg */
  11445.            "",            /* default */
  11446.            "",            /* addtl string data */
  11447.            nsftpkwtab,        /* addtl numeric data 1: tbl size */
  11448.            0,            /* addtl numeric data 2: 0 = keyword */
  11449.            xxstring,        /* Processing function */
  11450.            sftpkwtab,        /* Keyword table */
  11451.            &fl            /* Pointer to next FDB */
  11452.            );
  11453.     cmfdbi(&fl,            /* Host */
  11454.            _CMFLD,            /* fcode */
  11455.            "",            /* hlpmsg */
  11456.            "",            /* default */
  11457.            "",            /* addtl string data */
  11458.            0,            /* addtl numeric data 1 */
  11459.            0,            /* addtl numeric data 2 */
  11460.            xxstring,
  11461.            NULL,
  11462.            NULL
  11463.            );
  11464.  
  11465.     x = cmfdb(&kw);
  11466.     if (x == -3) {
  11467.         printf("?sftp what?\n");
  11468.         return(-9);
  11469.     }
  11470.     if (x < 0)
  11471.       return(x);
  11472.     havehost = 0;
  11473.     if (cmresult.fcode == _CMFLD) {
  11474.         havehost = 1;
  11475.         ckstrncpy(line,cmresult.sresult,LINBUFSIZ); /* Hostname */
  11476.         cmresult.nresult = SFTP_OPN;
  11477.     }
  11478.     switch (cmresult.nresult) {    /* SFTP keyword */
  11479.       case SFTP_OPN:        /* SFTP OPEN */
  11480.         if (!havehost) {
  11481.         if ((x = cmfld("Host","",&s,xxstring)) < 0)
  11482.           return(x);
  11483.         ckstrncpy(line,s,LINBUFSIZ);
  11484.         }
  11485.         /* Parse [ port ] [ switches ] */
  11486.         cmfdbi(&kw,            /* Switches */
  11487.            _CMKEY,
  11488.            "Port number or service name,\nor switch",
  11489.            "",
  11490.            "",
  11491.            nsshkrmopnsw,
  11492.            4,
  11493.            xxstring,
  11494.            sshkrmopnsw,
  11495.            &fl
  11496.            );
  11497.         cmfdbi(&fl,            /* Port number or service name */
  11498.            _CMFLD,
  11499.            "",
  11500.            "",
  11501.            "",
  11502.            0,
  11503.            0,
  11504.            xxstring,
  11505.            NULL,
  11506.            NULL
  11507.            );
  11508.         trips = 0;            /* Explained below */
  11509.         while (1) {            /* Parse port and switches */
  11510.         x = cmfdb(&kw);        /* Get a field */
  11511.         if (x == -3)        /* User typed CR so quit from loop */
  11512.           break;
  11513.         if (x < 0)        /* Other parse error, pass it back */
  11514.           return(x);
  11515.         switch (cmresult.fcode) { /* Field or Keyword? */
  11516.                   case _CMFLD:          /* Field */
  11517.                     makestr(&ssh_tmpport,cmresult.sresult);
  11518.             break;
  11519.           case _CMKEY:        /* Keyword */
  11520.             switch (cmresult.nresult) {    /* Which one? */
  11521.               case SSHSW_USR:            /* /USER: */
  11522.             if (!cmgbrk()) {
  11523.                 printf("?This switch requires an argument\n");
  11524.                 return(-9);
  11525.             }
  11526.             if ((y = cmfld("Username","",&s,xxstring)) < 0)
  11527.               return(y);
  11528.             s = brstrip(s);
  11529.             makestr(&ssh_tmpuid,s);
  11530.             break;
  11531.                       case SSHSW_PWD:
  11532.             if (!cmgbrk()) {
  11533.                 printf("?This switch requires an argument\n");
  11534.                 return(-9);
  11535.             }
  11536.             debok = 0;
  11537.             if ((x = cmfld("Password","",&s,xxstring)) < 0) {
  11538.                 if (x == -3) {
  11539.                 makestr(&ssh_tmpstr,"");
  11540.                 } else {
  11541.                 return(x);
  11542.                 }
  11543.             } else {
  11544.                 s = brstrip(s);
  11545.                 if ((x = (int)strlen(s)) > PWBUFL) {
  11546.                 makestr(&slmsg,"Internal error");
  11547.                 printf("?Sorry, too long - max = %d\n",PWBUFL);
  11548.                 return(-9);
  11549.                 }
  11550.                 makestr(&ssh_tmpstr,s);
  11551.             }
  11552.             break;
  11553.  
  11554.                     case SSHSW_VER:
  11555.             if ((x = cmnum("Number","",10,&z,xxstring)) < 0)
  11556.               return(x);
  11557.             if (z < 1 || z > 2) {
  11558.                 printf("?Out of range: %d\n",z);
  11559.                 return(-9);
  11560.             }
  11561.                         tmpver = z;
  11562.             break;
  11563.                     default:
  11564.                         return(-2);
  11565.             }
  11566.         }
  11567.         if (trips++ == 0) {    /* After first time through */
  11568.             cmfdbi(&kw,        /* only parse switches, not port. */
  11569.                _CMKEY,
  11570.                "Switch",
  11571.                "",
  11572.                "",
  11573.                nsshkrmopnsw,
  11574.                4,
  11575.                xxstring,
  11576.                sshkrmopnsw,
  11577.                NULL
  11578.                );
  11579.         }
  11580.         }
  11581.         if ((x = cmcfm()) < 0)    /* Get confirmation */
  11582.           return(x);
  11583.               if (clskconnx(1) < 0) {    /* Close current Kermit connection */
  11584.                   if ( ssh_tmpstr ) {
  11585.                       memset(ssh_tmpstr,0,strlen(ssh_tmpstr));
  11586.                       makestr(&ssh_tmpstr,NULL);
  11587.                   }
  11588.                   return(success = 0);
  11589.               }
  11590.               makestr(&ssh_hst,line);    /* Stash everything */
  11591.               if (ssh_tmpuid) {
  11592.                   if (!sl_uid_saved) {
  11593.                       ckstrncpy(sl_uidbuf,uidbuf,UIDBUFLEN);
  11594.                       sl_uid_saved = 1;
  11595.                   }
  11596.                   ckstrncpy(uidbuf,ssh_tmpuid,UIDBUFLEN);
  11597.                   makestr(&ssh_tmpuid,NULL);
  11598.               }
  11599.               if (ssh_tmpport) {
  11600.                   makestr(&ssh_prt,ssh_tmpport);
  11601.                   makestr(&ssh_tmpport,NULL);
  11602.               } else
  11603.                   makestr(&ssh_prt,NULL);
  11604.  
  11605.               /* Set the Subsystem to Kermit */
  11606.               ssh_cas = 1;
  11607.               makestr(&ssh_cmd,"sftp");
  11608.  
  11609.               if (tmpver > -1) {
  11610. #ifndef SSHTEST
  11611.                   if (!sl_ssh_ver_saved) {
  11612.                       sl_ssh_ver = ssh_ver;
  11613.                       sl_ssh_ver_saved = 1;
  11614.                   }
  11615. #endif /* SSHTEST */
  11616.                   ssh_ver = tmpver;
  11617.               }
  11618.               /* Disable X11 Forwarding */
  11619. #ifndef SSHTEST
  11620.               if (!sl_ssh_xfw_saved) {
  11621.                   sl_ssh_xfw = ssh_xfw;
  11622.                   sl_ssh_xfw_saved = 1;
  11623.               }
  11624. #endif /* SSHTEST */
  11625.               ssh_xfw = 0;
  11626.  
  11627.               if (ssh_tmpstr) {
  11628.                   if (ssh_tmpstr[0]) {
  11629.                       ckstrncpy(pwbuf,ssh_tmpstr,PWBUFL+1);
  11630.                       pwflg = 1;
  11631.                       pwcrypt = 0;
  11632.                   } else
  11633.                       pwflg = 0;
  11634.                   makestr(&ssh_tmpstr,NULL);
  11635.               }
  11636.               nettype = NET_SSH;
  11637.               if (mdmsav < 0)
  11638.                   mdmsav = mdmtyp;
  11639.               mdmtyp = -nettype;
  11640.               x = 1;
  11641.  
  11642. #ifndef NOSPL
  11643.             makestr(&g_pswd,pwbuf);             /* Save global pwbuf */
  11644.             g_pflg = pwflg;                     /* and flag */
  11645.             g_pcpt = pwcrypt;
  11646. #endif /* NOSPL */
  11647.  
  11648.         /* Line parameter to ttopen() is ignored */
  11649.         k = ttopen(line,&x,mdmtyp, 0);
  11650.         if (k < 0) {
  11651.         printf("?Unable to connect to %s\n",ssh_hst);
  11652.         mdmtyp = mdmsav;
  11653.                 slrestor();
  11654.         return(success = 0);
  11655.         }
  11656.         duplex = 0;             /* Remote echo */
  11657.         ckstrncpy(ttname,line,TTNAMLEN); /* Record the command */
  11658.         debug(F110,"ssh ttname",ttname,0);
  11659.         makestr(&slmsg,NULL);    /* No SET LINE error message */
  11660.         cxtype = CXT_SSH;
  11661. #ifndef NODIAL
  11662.         dialsta = DIA_UNK;
  11663. #endif /* NODIAL */
  11664.         success = 1;        /* SET LINE succeeded */
  11665.         network = 1;        /* Network connection (not serial) */
  11666.         local = 1;            /* Local mode (not remote) */
  11667.         if ((reliable != SET_OFF || !setreliable))
  11668.           reliable = SET_ON;    /* Transport is reliable end to end */
  11669. #ifdef OS2
  11670.             DialerSend(OPT_KERMIT_CONNECT, 0);
  11671. #endif /* OS2 */
  11672.         setflow();            /* Set appropriate flow control */
  11673.  
  11674.         haveline = 1;
  11675. #ifdef CKLOGDIAL
  11676. #ifdef NETCONN
  11677.         dolognet();
  11678. #endif /* NETCONN */
  11679. #endif /* CKLOGDIAL */
  11680.  
  11681. #ifndef NOSPL
  11682.         if (local) {
  11683.         if (nmac) {        /* Any macros defined? */
  11684.             int k;        /* Yes */
  11685.             k = mlook(mactab,"on_open",nmac); /* Look this up */
  11686.             if (k >= 0) {                  /* If found, */
  11687.             if (dodo(k,ssh_hst,0) > -1)   /* set it up, */
  11688.               parser(1);              /* and execute it */
  11689.             }
  11690.         }
  11691.         }
  11692. #endif /* NOSPL */
  11693. #ifdef LOCUS        
  11694.         if (autolocus)
  11695.         setlocus(1,1);
  11696. #endif /* LOCUS */
  11697.  
  11698.     /* Command was confirmed so we can pre-pop command level. */
  11699.     /* This is so CONNECT module won't think we're executing a */
  11700.     /* script if CONNECT was the final command in the script. */
  11701.         if (cmdlvl > 0)
  11702.           prepop();
  11703.  
  11704.             success = sftp_do_init();
  11705.         return(success = 1);
  11706.  
  11707.       case SFTP_CD:
  11708.       case SFTP_CHGRP:
  11709.       case SFTP_CHMOD:
  11710.       case SFTP_CHOWN:
  11711.       case SFTP_RM:
  11712.       case SFTP_DIR:
  11713.       case SFTP_GET:
  11714.       case SFTP_MKDIR:
  11715.       case SFTP_PUT:
  11716.       case SFTP_PWD:
  11717.       case SFTP_REN:
  11718.       case SFTP_RMDIR:
  11719.       case SFTP_LINK:
  11720.       case SFTP_VER:
  11721.         if ((y = cmtxt("command parameters","",&s,xxstring)) < 0) 
  11722.           return(y);
  11723.         if (ssh_tchk() < 0 || !ssh_cas || strcmp(ssh_cmd,"sftp")) {
  11724.         printf("?Not connected to SFTP Service\n");
  11725.         return(success = 0);
  11726.         }
  11727.         success = sftp_do_cmd(cmresult.nresult,s);
  11728.         return(success);
  11729.       default:
  11730.         return(-2);
  11731.     }
  11732.     }
  11733. #endif /* SFTP_BUILTIN */
  11734.  
  11735.     if (cx == XXRLOG) {            /* RLOGIN */
  11736. #ifdef RLOGCODE
  11737.     int x,z;
  11738. #ifdef OS2
  11739.     if (!tcp_avail) {
  11740.         printf("?Sorry, either TCP/IP is not available on this system or\n\
  11741. necessary DLLs did not load.  Use SHOW NETWORK to check network status.\n"
  11742.            );
  11743.         success = 0;
  11744.         return(-9);
  11745.     } else {
  11746. #endif /* OS2 */
  11747.         x = nettype;        /* Save net type in case of failure */
  11748.         z = ttnproto;        /* Save protocol in case of failure */
  11749.         nettype = NET_TCPB;
  11750.         ttnproto = NP_RLOGIN;
  11751.         if ((y = setlin(XYHOST,0,1)) <= 0) {
  11752.         nettype = x;        /* Failed, restore net type. */
  11753.         ttnproto = z;        /* and protocol */
  11754.         success = 0;
  11755.         }
  11756.         didsetlin++;
  11757. #ifdef OS2
  11758.     }
  11759. #endif /* OS2 */
  11760.     return(y);
  11761. #else
  11762.     printf("?Sorry, RLOGIN is not configured in this copy of C-Kermit.\n");
  11763.     return(-9);
  11764. #endif /* RLOGCODE */
  11765.     }
  11766. #endif /* NETCONN */
  11767. #endif /* NOLOCAL */
  11768.  
  11769. #ifndef NOXMIT
  11770.     if (cx == XXTRA) {            /* TRANSMIT */
  11771.     extern int xfrxla;
  11772.     int i, n, xpipe = 0, xbinary = 0, xxlate = 1, xxnowait = 0, getval;
  11773.     int xxecho = 0;
  11774.     int scan = 1;
  11775.     char c;
  11776.     struct FDB sf, sw, tx;        /* FDBs for parse functions */
  11777. #ifndef NOCSETS
  11778.     extern int tcs_transp;        /* Term charset is transparent */
  11779. #else
  11780.     int tcs_transp = 1;
  11781. #endif /* NOCSETS */
  11782.  
  11783. #ifdef COMMENT
  11784.     xbinary = binary;        /* Default text/binary mode */
  11785. #else
  11786.     xbinary = 0;            /* Default is text */
  11787. #endif /* COMMENT */
  11788.     xxecho = xmitx;
  11789.  
  11790.     cmfdbi(&sw,            /* First FDB - command switches */
  11791.            _CMKEY,            /* fcode */
  11792.            "Filename, or switch",    /* hlpmsg */
  11793.            "",            /* default */
  11794.            "",            /* addtl string data */
  11795.            nxmitsw,            /* addtl numeric data 1: tbl size */
  11796.            4,            /* addtl numeric data 2: 4 = cmswi */
  11797.            xxstring,        /* Processing function */
  11798.            xmitsw,            /* Keyword table */
  11799.            &sf            /* Pointer to next FDB */
  11800.            );
  11801.     cmfdbi(&sf,            /* 2nd FDB - file to send */
  11802.            _CMIFI,            /* fcode */
  11803.            "File to transmit",    /* hlpmsg */
  11804.            "",            /* default */
  11805.            "",            /* addtl string data */
  11806.            0,            /* addtl numeric data 1 */
  11807.            0,            /* addtl numeric data 2 */
  11808.            xxstring,
  11809.            NULL,
  11810. #ifdef PIPESEND
  11811.            &tx
  11812. #else
  11813.            NULL
  11814. #endif /* PIPESEND */
  11815.            );
  11816. #ifdef PIPESEND
  11817.         cmfdbi(&tx,
  11818.            _CMTXT,            /* fcode */
  11819.            "Command",        /* hlpmsg */
  11820.            "",            /* default */
  11821.            "",            /* addtl string data */
  11822.            0,            /* addtl numeric data 1 */
  11823.            0,            /* addtl numeric data 2 */
  11824.            xxstring,
  11825.            NULL,
  11826.            NULL
  11827.            );
  11828. #endif /* PIPESEND */
  11829.  
  11830.     while (1) {
  11831.         x = cmfdb(&sw);
  11832.         if (x < 0)
  11833.           return(x);
  11834.         if (cmresult.fcode != _CMKEY)
  11835.           break;
  11836.         c = cmgbrk();        /* Have switch, get break character */
  11837.         if ((getval = (c == ':' || c == '=')) && !(cmgkwflgs() & CM_ARG)) {
  11838.         printf("?This switch does not take an argument\n");
  11839.         return(-9);
  11840.         }
  11841.         if (!getval && (cmgkwflgs() & CM_ARG)) {
  11842.         printf("?This switch requires an argument\n");
  11843.         return(-9);
  11844.         }
  11845.         n = cmresult.nresult;    /* Numeric result = switch ID */
  11846.         switch (n) {        /* Process the switch */
  11847. #ifdef PIPESEND
  11848.           case XMI_CMD:        /* Transmit from a command */
  11849.         if (nopush) {
  11850.             printf("?Sorry, system command access is disabled\n");
  11851.             return(-9);
  11852.         }
  11853.         sw.hlpmsg = "Command, or switch"; /* Change help message */
  11854.         xpipe = 1;        /* (No way to undo this one) */
  11855.         break;
  11856. #endif /* PIPESEND */
  11857.  
  11858.           case XMI_BIN:        /* Binary */
  11859.         xbinary = 1;
  11860.         xxlate = 0;        /* Don't translate charsets */
  11861.         scan = 0;
  11862.         break;
  11863.  
  11864.           case XMI_TXT:        /* Text */
  11865.         xbinary = 0;
  11866.         xxlate = !tcs_transp;    /* Translate if TERM CHAR not TRANSP */
  11867.         scan = 0;
  11868.         break;
  11869.  
  11870.           case XMI_TRA:        /* Transparent text */
  11871.         xbinary = 0;
  11872.         xxlate = 0;        /* But don't translate charsets */
  11873.         scan = 0;
  11874.         break;
  11875.  
  11876. #ifdef COMMENT
  11877.           case XMI_VRB:        /* /VERBOSE */
  11878.           case XMI_QUI:        /* /QUIET */
  11879.         break;            /* (not implemented yet) */
  11880. #endif /* COMMENT */
  11881.  
  11882.           case XMI_NOW:        /* /NOWAIT */
  11883.         xxnowait = 1;
  11884.         break;
  11885.  
  11886.           case XMI_NOE:        /* /NOWAIT */
  11887.         xxecho = 0;
  11888.         break;
  11889.  
  11890.           default:
  11891.         return(-2);
  11892.         }
  11893.  
  11894.     }
  11895.     if (cmresult.fcode != _CMIFI && cmresult.fcode != _CMTXT)
  11896.       return(-2);
  11897.     ckstrncpy(line,cmresult.sresult,LINBUFSIZ); /* Filename */
  11898.     if (zfnqfp(line,TMPBUFSIZ,tmpbuf))
  11899.       ckstrncpy(line,tmpbuf,LINBUFSIZ);
  11900.     s = line;
  11901.     if ((y = cmcfm()) < 0)        /* Confirm */
  11902.       return(y);
  11903. #ifdef CK_APC
  11904.     if ((apcactive == APC_LOCAL) ||
  11905.         ((apcactive == APC_REMOTE) && (!(apcstatus & APC_UNCH))))
  11906.       return(success = 0);
  11907. #endif /* CK_APC */
  11908.     if (cmresult.nresult != 0) {
  11909.         printf("?Only a single file may be transmitted\n");
  11910.         return(-9);
  11911.     }
  11912. #ifdef PIPESEND
  11913.     if (xpipe) {
  11914.         s = brstrip(s);
  11915.         if (!*s) {
  11916.         printf("?Sorry, a command to send from is required\n");
  11917.         return(-9);
  11918.         }
  11919.         pipesend = 1;
  11920.     }
  11921. #endif /* PIPESEND */
  11922.  
  11923.     if (scan && (filepeek
  11924. #ifndef NOXFER
  11925.              || patterns
  11926. #endif /* NOXFER */
  11927.              )) {        /* If user didn't specify type */
  11928.         int k, x;                  /* scan the file to see */
  11929.         x = -1;
  11930.         k = scanfile(s,&x,nscanfile);
  11931.         if (k > 0) xbinary = (k == FT_BIN) ? XYFT_B : XYFT_T;
  11932.     }
  11933.     if (!xfrxla) xxlate = 0;
  11934.     success = transmit(s,
  11935.                (char) (xxnowait ? '\0' : (char)xmitp),
  11936.                xxlate,
  11937.                xbinary,
  11938.                xxecho
  11939.                );
  11940.     return(success);
  11941.     }
  11942. #endif /* NOXMIT */
  11943.  
  11944. #ifndef NOFRILLS
  11945.     if (cx == XXTYP  || cx == XXCAT || cx == XXMORE ||
  11946.     cx == XXHEAD || cx == XXTAIL) {
  11947.     int paging = 0, havename = 0, head = 0, width = 0;
  11948.     int height = 0, count = 0;
  11949.     char pfxbuf[64], * prefix = NULL;
  11950.     char outfile[CKMAXPATH+1];
  11951.     struct FDB sf, sw;
  11952.     char * pat = NULL;
  11953.     int incs = 0, outcs = 0, cset = -1, number = 0;
  11954. #ifdef UNICODE
  11955.         char * tocs = "";
  11956.     extern int fileorder;
  11957. #ifdef OS2
  11958. #ifdef NT
  11959.     char guibuf[128], * gui_title = NULL;
  11960.     int  gui = 0;
  11961. #endif /* NT */
  11962. #ifndef NOCSETS
  11963.     extern int tcsr, tcsl;
  11964. #endif /* NOCSETS */
  11965. #endif /* OS2 */
  11966. #endif /* UNICODE */
  11967.  
  11968.     outfile[0] = NUL;
  11969.  
  11970.     if (cx == XXMORE)
  11971.       paging = 1;
  11972.     else if (cx == XXCAT)
  11973.       paging = 0;
  11974.     else
  11975.       paging = (typ_page < 0) ? xaskmore : typ_page;
  11976.     if (paging < 0)
  11977.       paging = saveask;
  11978.  
  11979.     if (cx == XXHEAD) {
  11980.         head = 10;
  11981.         cx = XXTYP;
  11982.     } else if (cx == XXTAIL) {
  11983.         head = -10;
  11984.         cx = XXTYP;
  11985.     }
  11986.  
  11987. #ifdef IKSD
  11988.     if (inserver && !ENABLED(en_typ)) {
  11989.         printf("?Sorry, TYPE command disabled\n");
  11990.         return(-9);
  11991.     }
  11992. #endif /* IKSD */
  11993.  
  11994.     cmfdbi(&sw,            /* 2nd FDB - optional /PAGE switch */
  11995.            _CMKEY,            /* fcode */
  11996.            "Filename or switch",    /* hlpmsg */
  11997.            "",            /* default */
  11998.            "",            /* addtl string data */
  11999.            ntypetab,        /* addtl numeric data 1: tbl size */
  12000.            4,            /* addtl numeric data 2: 4 = cmswi */
  12001.            xxstring,        /* Processing function */
  12002.            typetab,            /* Keyword table */
  12003.            &sf            /* Pointer to next FDB */
  12004.            );
  12005.     cmfdbi(&sf,            /* 1st FDB - file to type */
  12006.            _CMIFI,            /* fcode */
  12007.            "",            /* hlpmsg */
  12008.            "",            /* default */
  12009.            "",            /* addtl string data */
  12010.            0,            /* addtl numeric data 1 */
  12011.            0,            /* addtl numeric data 2 */
  12012.            xxstring,
  12013.            NULL,
  12014.            NULL
  12015.            );
  12016.  
  12017.     while (!havename) {
  12018.         x = cmfdb(&sw);        /* Parse something */
  12019.         debug(F101,"type cmfdb","",x);
  12020.         debug(F101,"type cmresult.fcode","",cmresult.fcode);
  12021.         debug(F101,"type cmresult.nresult","",cmresult.nresult);
  12022.         if (x < 0) {            /* Error */
  12023.         if (x == -3) {
  12024.             x = -9;
  12025.             printf("?Filename required\n");
  12026.         }
  12027.         return(x);
  12028.         } else if (cmresult.fcode == _CMKEY) {
  12029.         char c; int getval;
  12030.         c = cmgbrk();
  12031.         getval = (c == ':' || c == '=');
  12032.         if (getval && !(cmgkwflgs() & CM_ARG)) {
  12033.             printf("?This switch does not take an argument\n");
  12034.             return(-9);
  12035.         }
  12036. #ifdef COMMENT
  12037.         if (!getval && (cmgkwflgs() & CM_ARG)) {
  12038.             printf("?This switch requires an argument\n");
  12039.             /* Not if it has a default! */
  12040.             return(-9);
  12041.         }
  12042. #endif /* COMMENT */
  12043.         switch (cmresult.nresult) {
  12044. #ifdef CK_TTGWSIZ
  12045.           case TYP_PAG:
  12046.             paging = 1;
  12047.             break;
  12048.  
  12049.           case TYP_NOP:
  12050.             paging = 0;
  12051.             break;
  12052. #endif /* CK_TTGWSIZ */
  12053.  
  12054.           case TYP_COU:
  12055.             paging = 0;
  12056.             count = 1;
  12057.             break;
  12058.  
  12059.           case TYP_HEA:
  12060.           case TYP_TAI:
  12061.             y = 10;
  12062.             if (getval)
  12063.               if ((x = cmnum("Number of lines",
  12064.                      "10",10,&y,xxstring)) < 0)
  12065.             return(x);
  12066.             head = (cmresult.nresult == TYP_TAI) ? -y : y;
  12067.             break;
  12068.  
  12069.           case TYP_WID:
  12070.             y = typ_wid > -1 ? typ_wid : cmd_cols;
  12071.             if (getval)
  12072.               if ((x = cmnum("Column at which to truncate",
  12073.                      ckitoa(y),10,&y,xxstring)) < 0)
  12074.             return(x);
  12075.             width = y;
  12076.             break;
  12077.  
  12078. #ifdef KUI
  12079.           case TYP_HIG:
  12080.             if (getval)
  12081.               if ((x = cmnum("Height of GUI dialog",
  12082.                      ckitoa(y),10,&y,xxstring)) < 0)
  12083.             return(x);
  12084.             height = y;
  12085.             break;
  12086. #endif /* KUI */
  12087.  
  12088.           case TYP_PAT:
  12089.             if (!getval && (cmgkwflgs() & CM_ARG)) {
  12090.             printf("?This switch requires an argument\n");
  12091.             return(-9);
  12092.             }
  12093.             if ((x = cmfld("pattern","",&s,xxstring)) < 0)
  12094.               return(x);
  12095.             ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  12096.             pat = tmpbuf;
  12097.             break;
  12098.  
  12099.           case TYP_PFX:
  12100.             if (!getval && (cmgkwflgs() & CM_ARG)) {
  12101.             printf("?This switch requires an argument\n");
  12102.             return(-9);
  12103.             }
  12104.             if ((x = cmfld("prefix for each line","",&s,xxstring)) < 0)
  12105.               return(x);
  12106.             if ((int)strlen(s) > 63) {
  12107.             printf("?Too long - 63 max\n");
  12108.             return(-9);
  12109.             }
  12110.             ckstrncpy(pfxbuf,s,64);
  12111.             prefix = brstrip(pfxbuf);
  12112.             number = 0;
  12113.             break;
  12114.  
  12115. #ifdef KUI
  12116.           case TYP_GUI:
  12117.             if (!getval && (cmgkwflgs() & CM_ARG)) {
  12118.             printf("?This switch requires an argument\n");
  12119.             return(-9);
  12120.             }
  12121.             if ((x = cmfld("Dialog box title","",&s,xxstring)) < 0) {
  12122.             if (x != -3)
  12123.               return(x);
  12124.             } else {
  12125.             if ((int)strlen(s) > 127) {
  12126.                 printf("?Too long - 127 max\n");
  12127.                 return(-9);
  12128.             }
  12129.             ckstrncpy(guibuf,s,128);
  12130.             gui_title = brstrip(guibuf);
  12131.             }
  12132.             gui = 1;
  12133.             break;
  12134. #endif /* KUI */
  12135.  
  12136.           case TYP_NUM:        /* /NUMBER */
  12137.             number = 1;
  12138.             prefix = NULL;
  12139.             break;
  12140.  
  12141. #ifdef UNICODE
  12142.           case TYP_XPA:        /* /TRANSPARENT */
  12143.             incs = 0;
  12144.             cset = 0;
  12145.             outcs = -1;
  12146.             break;
  12147.  
  12148.           case TYP_XIN:        /* /CHARACTER-SET: */
  12149.             if (!getval && (cmgkwflgs() & CM_ARG)) {
  12150.             printf("?This switch requires an argument\n");
  12151.             return(-9);
  12152.             }
  12153.             if ((incs = cmkey(fcstab,nfilc,
  12154.                       "character-set name","",xxstring)) < 0) {
  12155.             if (incs == -3)    /* Note: No default */
  12156.               incs = -2;
  12157.             return(incs);
  12158.             }
  12159.             cset = incs;
  12160.             break;
  12161.  
  12162.           case TYP_XUT:        /* /TRANSLATE-TO: */
  12163.             if (!getval && (cmgkwflgs() & CM_ARG)) {
  12164.             printf("?This switch requires an argument\n");
  12165.             return(-9);
  12166.             }
  12167. #ifdef OS2
  12168.             if (!inserver && !k95stdout) {
  12169.             tocs = "ucs2";
  12170.             } else {
  12171. #ifdef CKOUNI
  12172.             tocs = rlookup(txrtab,ntxrtab,tcsl);
  12173. #else /* CKOUNI */
  12174.             extern struct keytab ttcstab[];
  12175.             extern int ntxrtab;
  12176.             tocs = rlookup(ttcstab,ntermc,tocs);
  12177.             if (!tocs)
  12178.               tocs = getdcset();
  12179. #endif /* CKOUNI */
  12180.                     }
  12181. #else /* OS2 */
  12182.             tocs = getdcset();
  12183. #endif /* OS2 */
  12184.             if ((outcs = cmkey(fcstab,nfilc,
  12185.                        "character-set",tocs,xxstring)) < 0)
  12186.               return(outcs);
  12187.             break;
  12188. #endif /* UNICODE */
  12189.           case TYP_OUT:
  12190.             if ((x = cmofi("File for result lines","",
  12191.                    &s,xxstring)) < 0)
  12192.               return(x);
  12193.             ckstrncpy(outfile,s,CKMAXPATH);
  12194.             break;
  12195.         }
  12196.         } else if (cmresult.fcode == _CMIFI)
  12197.           havename = 1;
  12198.         else
  12199.           return(-2);
  12200.     }
  12201.     if (havename) {
  12202.         ckstrncpy(line,cmresult.sresult,LINBUFSIZ);
  12203.         y = cmresult.nresult;
  12204.     } else {
  12205.         if ((x = cmifi("Filename","",&s,&y,xxstring)) < 0) {
  12206.         if (x == -3) {
  12207.             printf("?Name of an existing file required\n");
  12208.             return(-9);
  12209.         } else return(x);
  12210.         }
  12211.         ckstrncpy(line,s,LINBUFSIZ);
  12212.     }
  12213.     if (y != 0) {
  12214.         printf("?A single file please\n");
  12215.         return(-9);
  12216.     }
  12217. #ifdef KUI
  12218.     if ( outfile[0] && gui ) {
  12219.         printf("?/GUI and /OUTPUT are incompatible\n");
  12220.         return(-9);
  12221.     }
  12222. #endif /* KUI */
  12223.  
  12224.     if ((y = cmcfm()) < 0)        /* Confirm the command */
  12225.       return(y);
  12226.  
  12227. #ifdef UNICODE
  12228.     fileorder = -1;
  12229.     if (cset < 0 && filepeek) {    /* If no charset switches given */
  12230.         int k, x = -1;
  12231.         k = scanfile(line,&x,nscanfile); /* Call file analyzer */
  12232.         debug(F111,"type scanfile",line,k);
  12233.         debug(F101,"type scanfile flag","",x);
  12234.         switch(k) {
  12235.           case FT_UTF8:        /* which can detect UTF-8... */
  12236.         cset = 0;
  12237.         incs = FC_UTF8;
  12238.         break;
  12239.           case FT_UCS2:        /* and UCS-2... */
  12240.         cset = 0;
  12241.         incs = FC_UCS2;
  12242.         fileorder = x;        /* even if there is no BOM. */
  12243.         debug(F101,"type fileorder","",fileorder);
  12244.         break;
  12245.         }
  12246.     }
  12247. #ifdef OS2
  12248.         if (cset < 0) {            /* If input charset still not known */
  12249. #ifdef CKOUNI
  12250.             tocs = rlookup(txrtab,ntxrtab,tcsl);
  12251. #else /* CKOUNI */
  12252.             extern struct keytab ttcstab[];
  12253.             extern int ntxrtab;
  12254.             tocs = rlookup(ttcstab,ntermc,incs);
  12255.             if (!tocs)
  12256.           tocs = getdcset();
  12257. #endif /* CKOUNI */
  12258.             incs = lookup(fcstab,tocs,nfilc,&x);
  12259.         }
  12260. #endif /* OS2 */
  12261.  
  12262.         if (outcs == 0 && incs != 0) {    /* Supply default target charset */
  12263.         int x = 0;            /* if switch not given. */
  12264.         tocs = getdcset();
  12265.         outcs = lookup(fcstab,tocs,nfilc,&x);
  12266.     }
  12267. #else  /* !UNICODE */
  12268.     if (cset < 0) incs = outcs = 0;
  12269. #endif /* UNICODE */
  12270.  
  12271.     if (outfile[0] && paging)    /* This combination makes no sense */
  12272.       paging = 0;            /* so turn off paging */
  12273.  
  12274. #ifdef KUI
  12275.     /* No paging when dialog is used */
  12276.     if ( gui && paging )
  12277.       paging = 0;
  12278.  
  12279.     if ( !gui && height ) {
  12280.         printf("?The /HEIGHT switch is not supported without /GUI\n");
  12281.         return(-9);
  12282.     }
  12283. #endif /* KUI */
  12284.  
  12285.     if (count) paging = -1;
  12286.     debug(F111,"type",line,paging);
  12287. #ifdef KUI
  12288.     if ( gui ) {
  12289.         s = (char *)1;    /* ok, its an ugly hack */
  12290.         if (gui_text_popup_create(gui_title ?
  12291.                       gui_title : line, height,width) < 0) {
  12292.         printf("?/GUI not supported on this system\n");
  12293.         gui = 0;
  12294.         return(-9);
  12295.         }
  12296.         width = 0;
  12297.     } else
  12298. #endif /* KUI */
  12299.       s = outfile;
  12300.     success =
  12301.       dotype(line,paging,0,head,pat,width,prefix,incs,outcs,s,number);
  12302.     return(success);
  12303.     }
  12304. #endif /* NOFRILLS */
  12305.  
  12306. #ifndef NOCSETS
  12307.     if (cx == XXXLA) {            /* TRANSLATE file's charset */
  12308.     _PROTOTYP (int doxlate, ( void ) );
  12309.     return(doxlate());
  12310.     }
  12311. #endif /* NOCSETS */
  12312.  
  12313.     if (cx == XXVER) {            /* VERSION */
  12314.     int n = 0;
  12315.     extern char * ck_patch, * ck_s_test;
  12316. #ifdef COMMENT
  12317.     extern int hmtopline;
  12318. #endif /* COMMENT */
  12319.     if ((y = cmcfm()) < 0)
  12320.           return(y);
  12321.  
  12322. #ifdef CK_64BIT
  12323.     printf("\n%s, for%s (64-bit)\n Numeric: %ld",versio,ckxsys,vernum);
  12324. #else
  12325.     printf("\n%s, for%s\n Numeric: %ld",versio,ckxsys,vernum);
  12326. #endif    /* CK_64BIT */
  12327.     printf("\n\n");
  12328.         printf("Authors:\n");
  12329.     printf(" Frank da Cruz, Columbia University\n");
  12330.         printf(" Jeffrey Eric Altman, Secure Endpoints, Inc. %s\n",
  12331.            "<jaltman@secure-endpoints.com>"
  12332.            );
  12333.     printf(" Contributions from many others.\n");
  12334.     n = 7;
  12335.     if (*ck_s_test) {
  12336.         printf("\nTHIS IS A TEST VERSION, NOT FOR PRODUCTION USE.\n");
  12337.         n += 2;
  12338.     }
  12339.     if (*ck_patch) {
  12340.         printf(" Patches: %s\n", ck_patch);
  12341.         n++;
  12342.     }
  12343.     printf(" Type COPYRIGHT for copyright and license.\n\n");
  12344. #ifdef OS2
  12345.     shoreg();
  12346. #else
  12347. #ifdef COMMENT
  12348.     hmtopline = n+1;
  12349.     hmsga(copyright);
  12350.     hmtopline = 0;
  12351. #endif /* COMMENT */
  12352. #endif /* OS2 */
  12353.     return(success = 1);
  12354.     }
  12355.  
  12356.     if (cx == XXCPR) {            /* COPYRIGHT or LICENSE */
  12357.     if ((y = cmcfm()) < 0)
  12358.           return(y);
  12359. #ifdef OS2
  12360.     if (inserver) {            /* Free WIKSD */
  12361.         extern char * wiksdcpr[];
  12362.         hmsga(wiksdcpr);
  12363.     } else
  12364. #endif /* OS2 */
  12365.       hmsga(copyright);
  12366.     return(success = 1);
  12367.     }
  12368.  
  12369. #ifndef MAC                /* Only for multiuser systems */
  12370. #ifndef OS2
  12371. #ifndef NOFRILLS
  12372.     if (cx == XXWHO) {            /* WHO */
  12373.     char *wc;
  12374. #ifdef IKSD
  12375.     if (inserver && !ENABLED(en_who)) {
  12376.         printf("?Sorry, WHO command disabled\n");
  12377.         return(-9);
  12378.     }
  12379. #endif /* IKSD */
  12380. #ifdef datageneral
  12381.     if ((z = cmcfm()) < 0) return(z);
  12382.     if (nopush) {
  12383.         printf("?Sorry, who not allowed\n");
  12384.         return(success = 0);
  12385.     }
  12386.         xsystem(WHOCMD);
  12387. #else
  12388.     if ((y = cmtxt("user name","",&s,xxstring)) < 0) return(y);
  12389.         if (nopush) {
  12390.         printf("?Sorry, WHO command disabled\n");
  12391.         return(success = 0);
  12392.     }
  12393.     if (!(wc = getenv("CK_WHO"))) wc = WHOCMD;
  12394.     if (wc)
  12395.       if ((int) strlen(wc) > 0) {
  12396.           ckmakmsg(line,LINBUFSIZ,wc," ",s,NULL);
  12397.           xsystem(line);
  12398.       }
  12399. #endif /* datageneral */
  12400.     return(success = 1);
  12401.     }
  12402. #endif /* NOFRILLS */
  12403. #endif /* OS2 */
  12404. #endif /* MAC */
  12405.  
  12406. #ifndef NOFRILLS
  12407.     if (cx == XXWRI || cx == XXWRL || cx == XXWRBL) { /* WRITE */
  12408.     int x,y;            /* On stack in case of \fexec() */
  12409.     if ((x = cmkey(writab,nwri,"to file or log","",xxstring)) < 0) {
  12410.         if (x == -3) printf("?Write to what?\n");
  12411.         return(x);
  12412.     }
  12413.     if ((y = cmtxt("text","",&s,xxstring)) < 0) return(y);
  12414.     s = brstrip(s);
  12415.     switch (x) {
  12416.       case LOGD: y = ZDFILE; break;
  12417.       case LOGP: y = ZPFILE; break;
  12418. #ifndef NOLOCAL
  12419.       case LOGS: y = ZSFILE; break;
  12420. #endif /* NOLOCAL */
  12421.       case LOGT: y = ZTFILE; break;
  12422. #ifndef NOSPL
  12423.       case LOGW: y = ZWFILE; break;
  12424. #endif /* NOSPL */
  12425.       case LOGX:            /* SCREEN (stdout) */
  12426.       case LOGE:            /* ERROR  (stderr) */
  12427.         if (x == LOGE) {
  12428.         debug(F110,
  12429.               (cx == XXWRL) ? "WRITELN ERROR" : "WRITE ERROR", s,0);
  12430.         fprintf(stderr,"%s%s",s,(cx == XXWRL) ? "\n" : "");
  12431.         } else {
  12432.         debug(F110,
  12433.               (cx == XXWRL) ? "WRITELN SCREEN" : "WRITE SCREEN", s,0);
  12434.         printf("%s%s",s,(cx == XXWRL) ? "\n" : "");
  12435.         }
  12436.         return(success = 1);
  12437.       default: return(-2);
  12438.     }
  12439.     if (chkfn(y) > 0) {
  12440.         x = (cx == XXWRI) ? zsout(y,s) : zsoutl(y,s);
  12441.         debug(F111,"WRITE",
  12442.           (cx == XXWRI) ? "zsout" : "zsoutl",
  12443.           x);
  12444.         if (x < 0) printf("?Write error\n");
  12445.     } else {
  12446.         x = -1;
  12447.         printf("?File or log not open\n");
  12448.     }
  12449.     debug(F101,"WRITE x","",x);
  12450.     return(success = (x == 0) ? 1 : 0);
  12451.     }
  12452. #endif /* NOFRILLS */
  12453.  
  12454. #ifndef NOXFER
  12455.     if (cx == XXASC || cx == XXBIN) {
  12456.     if ((x = cmcfm()) < 0) return(x);
  12457. #ifdef NEWFTP
  12458. /*
  12459.   Make C-Kermit work like other ftp clients, where
  12460.   the ASCII (TEXT) and BINARY commands are global settings.
  12461. */
  12462.     if (ftpisopen()) {
  12463.         doftpglobaltype((cx == XXASC) ? XYFT_T : XYFT_B);
  12464.         /* Fall thru--the command it should apply to both FTP and Kermit */
  12465.         /* return(success = 1); */
  12466.     }
  12467. #endif /* NEWFTP */
  12468.  
  12469.     xfermode = XMODE_M;        /* Set manual Kermit transfer mode */
  12470.     binary = (cx == XXASC) ? XYFT_T : XYFT_B;
  12471.     return(success = 1);
  12472.     }
  12473. #endif /* NOXFER */
  12474.  
  12475.     if (cx == XXCLS) {
  12476.     if ((x = cmcfm()) < 0) return(x);
  12477.     y = ck_cls();
  12478.     return(success = (y > -1) ? 1 : 0);
  12479.     }
  12480.  
  12481. #ifdef CK_MKDIR
  12482.     if (cx == XXMKDIR || cx == XXLMKD) {
  12483.     char *p;
  12484. #ifdef LOCUS
  12485.     if (!locus && cx != XXLMKD) {
  12486. #ifdef NOXFER
  12487.         return(-2);
  12488. #else
  12489.         return(dormt(XZMKD));
  12490. #endif /* NOXFER */
  12491.         }
  12492. #endif /* LOCUS */
  12493. #ifdef IKSD
  12494.     if (inserver && !ENABLED(en_mkd)) {
  12495.         printf("?Sorry, directory creation is disabled\n");
  12496.         return(-9);
  12497.     }
  12498. #endif /* IKSD */
  12499.     if ((x = cmfld("Name for new directory","",&s,xxstring)) < 0) {
  12500.         if (x != -3) {
  12501.         return(x);
  12502.         } else {
  12503.         printf("?Directory name required\n");
  12504.         return(-9);
  12505.         }
  12506.     }
  12507.     ckstrncpy(line,s,LINBUFSIZ);
  12508.     s = line;
  12509.     if ((x = cmcfm()) < 0) return(x);
  12510.     s = brstrip(s);
  12511.     bgchk();            /* Set msgflg */
  12512.     x = ckmkdir(0,s,&p,msgflg,0);
  12513. #ifdef COMMENT
  12514.     if (msgflg && x == 0)
  12515.       printf("?Directory already exists\n");
  12516. #endif /* COMMENT */
  12517.     return(success = (x < 0) ? 0 : 1);
  12518.     }
  12519.     if (cx == XXRMDIR || cx == XXLRMD) { /* RMDIR */
  12520.     char *p;
  12521. #ifdef LOCUS
  12522.     if (!locus && cx != XXLRMD) {
  12523. #ifdef NOXFER
  12524.         return(-2);
  12525. #else
  12526.         return(dormt(XZRMD));
  12527. #endif /* NOXFER */
  12528.         }
  12529. #endif /* LOCUS */
  12530. #ifdef IKSD
  12531.     if (inserver && !ENABLED(en_rmd)) {
  12532.         printf("?Sorry, directory removal is disabled\n");
  12533.         return(-9);
  12534.     }
  12535. #endif /* IKSD */
  12536.     if ((x = cmdir("Name of directory to be removed","",&s,xxstring)) < 0)
  12537.       return(x);
  12538.     ckstrncpy(line,s,LINBUFSIZ);
  12539.     s = line;
  12540.     if ((x = cmcfm()) < 0) return(x);
  12541.     s = brstrip(s);
  12542.     x = ckmkdir(1,s,&p,msgflg,0);
  12543.     return(success = (x < 0) ? 0 : 1);
  12544.     }
  12545. #endif /* CK_MKDIR */
  12546.  
  12547. #ifdef TNCODE
  12548.     if (cx == XXTELOP)
  12549.       return(dotelopt());
  12550. #endif /* TNCODE */
  12551.  
  12552. #ifndef NOPUSH
  12553.     if (cx == XXNPSH) {
  12554.     if ((z = cmcfm()) < 0) return(z);
  12555.         nopush = 1;
  12556. #ifndef NOSERVER
  12557.         en_hos = 0;
  12558. #endif /* NOSERVER */
  12559. #ifdef PIPESEND
  12560.     usepipes = 0;
  12561. #endif /* PIPESEND */
  12562.         return(success = 1);
  12563.     }
  12564. #endif /* NOPUSH */
  12565.  
  12566. #ifdef OS2
  12567.     if (cx == XXNSCR) {
  12568.     if ((z = cmcfm()) < 0) return(z);
  12569.         tt_scroll = 0;
  12570.         return(success = 1);
  12571.     }
  12572. #endif /* OS2 */
  12573.  
  12574. #ifndef NOSPL
  12575.     if (cx == XXLOCAL)            /* LOCAL variable declarations */
  12576.       return(success = dolocal());
  12577. #endif /* NOSPL */
  12578.  
  12579.     if (cx == XXKERMI) {        /* The KERMIT command */
  12580.     char * list[65];
  12581.     extern char **xargv;
  12582.     extern int xargc;
  12583.     int i;
  12584.     if ((y = cmtxt("kermit command-line arguments, -h for help",
  12585.                "",&s,xxstring)) < 0)
  12586.       return(y);
  12587.     ckstrncpy(line,"kermit ",LINBUFSIZ);
  12588.     ckstrncat(line,s,LINBUFSIZ-8);
  12589.     xwords(line,64,list,0);
  12590.     for (i = 1; i < 64; i++) {
  12591.         if (!list[i])
  12592.           break;
  12593.     }
  12594.     i--;
  12595.     xargc = i;
  12596.     xargv = list;
  12597.     xargv++;
  12598.     sstate = cmdlin();
  12599.     if (sstate) {
  12600.         extern int justone;
  12601.         debug(F000,"KERMIT sstate","",sstate);
  12602.         justone = 1;        /* Force return to command mode */
  12603.         proto();            /* after protocol */
  12604.         return(success);
  12605.     } else {
  12606.         debug(F101,"KERMIT sstate","",sstate);
  12607.         return(success = 1);    /* Not exactly right, but... */
  12608.     }
  12609.     }
  12610.     if (cx == XXDATE) {            /* DATE command */
  12611.     extern char cmdatebuf[], * cmdatemsg;
  12612.  
  12613. #ifndef COMMENT
  12614.     char * dp;
  12615.     if ((y = cmtxt("date and/or time, or carriage return for current",
  12616.                "",&s,xxstring)) < 0)
  12617.       return(y);
  12618.     s = brstrip(s);
  12619.     dp = cmcvtdate(s,1);
  12620.     if (!dp) {
  12621.         printf("?%s\n",cmdatemsg ? cmdatemsg : "Date conversion error");
  12622.         success = 0;
  12623.     } else {
  12624.         printf("%s\n",dp);
  12625.         success = 1;
  12626.     }
  12627. #else
  12628.     /* This works fine but messes up my "dates" torture-test script */
  12629.  
  12630.     if ((x = cmdate("Date and/or time, or carriage return for current",
  12631.             "",&s,0,xxstring)) < 0) {
  12632.         return(x);
  12633.     } else {
  12634.         printf("%s\n",cmdatebuf);
  12635.         success = 1;
  12636.     }
  12637. #endif /* COMMENT */
  12638.     return(success);
  12639.     }
  12640. #ifndef NOPUSH
  12641. #ifndef NOFRILLS
  12642.     if (cx == XXEDIT)
  12643.       return(doedit());
  12644. #endif /* NOFRILLS */
  12645. #endif /* NOPUSH */
  12646.  
  12647. #ifdef BROWSER                /* Defined only ifndef NOPUSH */
  12648.     if (cx == XXBROWS)
  12649.       return(dobrowse());
  12650. #endif /* BROWSER */
  12651.  
  12652. #ifdef CK_TAPI
  12653.     if (cx == XXTAPI) {            /* Microsoft TAPI */
  12654.     return (success = dotapi());
  12655.     }
  12656. #endif /* CK_TAPI */
  12657.  
  12658. #ifndef NOXFER
  12659.     if (cx == XXWHERE) {
  12660.     extern char * rfspec, * sfspec, * srfspec, * rrfspec;
  12661.     if ((x = cmcfm()) < 0) return(x);
  12662.     printf("\nFile most recently...\n\n");
  12663.     printf("  Sent:       %s\n",   sfspec ? sfspec : "(none)");
  12664.     if (sfspec && srfspec) {
  12665.         printf("  Stored as:  %s\n",   srfspec);
  12666.         printf("\n");
  12667.     }
  12668.     printf("  Received:   %s\n",   rrfspec ? rrfspec : "(none)");
  12669.     if (rfspec && rrfspec)
  12670.     printf("  Stored as:  %s\n",   rfspec);
  12671.     printf(
  12672. "\nIf the full path is not shown, then the file is probably in your current\n"
  12673.            );
  12674.     printf(
  12675. "directory or your download directory (if any - SHOW FILE to find out).\n\n"
  12676.            );
  12677.     return(success = 1);
  12678.     }
  12679. #endif /* NOXFER */
  12680.  
  12681. #ifdef CK_RECALL
  12682.     if (cx == XXREDO)
  12683.       return(doredo());
  12684. #endif /* CK_RECALL */
  12685.  
  12686. #ifdef CKROOT
  12687.     if (cx == XXCHRT)            /* Change Kermit's root directory */
  12688.       return(dochroot());
  12689. #endif /* CKROOT */
  12690.  
  12691. #ifdef CK_KERBEROS
  12692.     if (cx == XXAUTH) {            /* KERBEROS */
  12693.     x = cp_auth();            /* Parse it */
  12694. #ifdef IKSD
  12695.         if (inserver) {
  12696.             printf("?Command disabled in IKSD.\r\n");
  12697.             return(success = 0);
  12698.         }
  12699. #endif /* IKSD */
  12700.     if (x < 0)            /* Pass parse errors back */
  12701.       return(x);
  12702.     return(success = doauth(cx));
  12703.     }
  12704. #endif /* CK_KERBEROS */
  12705.  
  12706. #ifndef NOLOCAL
  12707.     if (cx == XXTERM) {
  12708.     return(settrmtyp());
  12709.     }
  12710. #endif /* NOLOCAL */
  12711.  
  12712.     if (cx == XXSTATUS) {
  12713.     if ((x = cmcfm()) < 0) return(x);
  12714.     printf( " %s\n", success ? "SUCCESS" : "FAILURE" );
  12715.     return(0);            /* Don't change it */
  12716.     }
  12717.  
  12718.     if (cx == XXFAIL) {
  12719.     if ((x = cmcfm()) < 0) return(x);
  12720.     return(success = 0);
  12721.     }
  12722.  
  12723.     if (cx == XXSUCC) {
  12724.     if ((x = cmcfm()) < 0) return(x);
  12725.     return(success = 1);
  12726.     }
  12727.  
  12728.     if (cx == XXNLCL) {
  12729.     extern int nolocal;
  12730.     if ((x = cmcfm()) < 0) return(x);
  12731.     nolocal = 1;
  12732.     return(success = 1);
  12733.     }
  12734.  
  12735. #ifndef NOXFER
  12736.     if (cx == XXRASG)            /* Shortcuts for REMOTE commands */
  12737.       return(dormt(XZASG));
  12738.     if (cx == XXRCWD)
  12739.       return(dormt(XZCWD));
  12740.     if (cx == XXRCPY)
  12741.       return(dormt(XZCPY));
  12742.     if (cx == XXRDEL)
  12743.       return(dormt(XZDEL));
  12744.     if (cx == XXRDIR)
  12745.       return(dormt(XZDIR));
  12746.     if (cx == XXRXIT)
  12747.       return(dormt(XZXIT));
  12748.     if (cx == XXRHLP)
  12749.       return(dormt(XZHLP));
  12750.     if (cx == XXRHOS)
  12751.       return(dormt(XZHOS));
  12752.     if (cx == XXRKER)
  12753.       return(dormt(XZKER));
  12754.     if (cx == XXRPWD)
  12755.       return(dormt(XZPWD));
  12756.     if (cx == XXRQUE)
  12757.       return(dormt(XZQUE));
  12758.     if (cx == XXRREN)
  12759.       return(dormt(XZREN));
  12760.     if (cx == XXRMKD)
  12761.       return(dormt(XZMKD));
  12762.     if (cx == XXRMSG)
  12763.       return(dormt(XZMSG));
  12764.     if (cx == XXRRMD)
  12765.       return(dormt(XZRMD));
  12766.     if (cx == XXRSET)
  12767.       return(dormt(XZSET));
  12768.     if (cx == XXRSPA)
  12769.       return(dormt(XZSPA));
  12770.     if (cx == XXRTYP)
  12771.       return(dormt(XZTYP));
  12772.     if (cx == XXRWHO)
  12773.       return(dormt(XZWHO));
  12774.     if (cx == XXRCDUP)
  12775.       return(dormt(XZCDU));
  12776.     if (cx == XXRPRI)
  12777.       return(dormt(XZPRI));
  12778. #endif /* NOXFER */
  12779.  
  12780.     if (cx == XXRESET) {        /* RESET */
  12781.     if ((x = cmcfm()) < 0)
  12782.       return(x);
  12783.     concb((char)escape);        /* Make command echoing to normal */
  12784.     doclean(0);            /* Close all files */
  12785.     return(success = 1);
  12786.     }
  12787.  
  12788. #ifndef NOXFER
  12789. #ifndef NOCSETS
  12790.     if (cx == XXASSOC)            /* ASSOCIATE */
  12791.       return(doassoc());
  12792. #endif /* NOCSETS */
  12793. #endif /* NOXFER */
  12794.  
  12795. #ifndef NOSPL
  12796.     if (cx == XXSHIFT) {        /* SHIFT */
  12797.     if ((y = cmnum("Number of arguments to shift","1",10,&x,xxstring)) < 0)
  12798.       return(y);
  12799.     if ((z = cmcfm()) < 0)
  12800.       return(z);
  12801.     return(success = doshift(x));
  12802.     }
  12803. #endif /* NOSPL */
  12804.  
  12805. #ifndef NOHELP
  12806.     if (cx == XXMAN)
  12807.       return(domanual());
  12808. #endif /* NOHELP */
  12809.  
  12810. #ifndef NOSPL
  12811.     if (cx == XXSORT)            /* SORT an array */
  12812.       return(dosort());
  12813. #endif /* NOSPL */
  12814.  
  12815.     if (cx == XXPURGE) {
  12816. #ifdef IKSD
  12817.     if (inserver && (!ENABLED(en_del)
  12818. #ifdef CK_LOGIN
  12819.                           || isguest
  12820. #endif /* CK_LOGIN */
  12821.              )) {
  12822.         printf("?Sorry, DELETE is disabled\n");
  12823.         return(-9);
  12824.     }
  12825. #endif /* IKSD */
  12826. #ifdef CK_APC
  12827.     if ((apcactive == APC_LOCAL) ||
  12828.         ((apcactive == APC_REMOTE) && (!(apcstatus & APC_UNCH))))
  12829.       return(success = 0);
  12830. #endif /* CK_APC */
  12831. #ifdef CKPURGE
  12832.         return(dopurge());
  12833. #else
  12834. #ifdef VMS
  12835.     if ((x = cmtxt("optional switches followed by filespec",
  12836.                "",&s,xxstring)) < 0)
  12837.       return(x);
  12838.     if (nopush) {
  12839.         printf("?Sorry, DCL access is disabled\n");
  12840.         return(-9);
  12841.     }
  12842.     ckstrncpy(line,s,LINBUFSIZ);
  12843.     s = line;
  12844.     x = mlook(mactab,"purge",nmac);
  12845.     return(success = dodo(x,s,cmdstk[cmdlvl].ccflgs));
  12846. #else
  12847.     return(-2);
  12848. #endif /* VMS */
  12849. #endif /* CKPURGE */
  12850.     }
  12851.  
  12852. #ifndef NOSPL
  12853.     if (cx == XXFAST) {
  12854.     if ((x = cmcfm()) < 0) return(x);
  12855.     x = mlook(mactab,"fast",nmac);
  12856.     return(success = dodo(x,NULL,cmdstk[cmdlvl].ccflgs));
  12857.     }
  12858.     if (cx == XXCAU) {
  12859.     if ((x = cmcfm()) < 0) return(x);
  12860.     x = mlook(mactab,"cautious",nmac);
  12861.     return(success = dodo(x,NULL,cmdstk[cmdlvl].ccflgs));
  12862.     }
  12863.     if (cx == XXROB) {
  12864.     if ((x = cmcfm()) < 0) return(x);
  12865.     x = mlook(mactab,"robust",nmac);
  12866.     return(success = dodo(x,NULL,cmdstk[cmdlvl].ccflgs));
  12867.     }
  12868. #endif /* NOSPL */
  12869.  
  12870.     if (cx == XXSCRN) {            /* SCREEN */
  12871.     int row, col;
  12872.     if ((x = cmkey(scntab, nscntab,"screen action","", xxstring)) < 0)
  12873.       return(x);
  12874.     switch (x) {            /* MOVE-TO (cursor position) */
  12875.       case SCN_MOV:
  12876.         if ((y = cmnum("Row (1-based)","",10,&z,xxstring)) < 0)
  12877.           return(y);
  12878.         row = z;
  12879.         y = cmnum("Column (1-based)","1",10,&z,xxstring);
  12880.         if (y < 0)
  12881.           return(y);
  12882.         col = z;
  12883.         if ((y = cmcfm()) < 0)
  12884.           return(y);
  12885.         if (row < 0 || col < 0) {
  12886.         printf("?Row and Column must be 1 or greater\n");
  12887.         return(-9);
  12888.         }
  12889.         if (cmd_rows > 0 && row > cmd_rows)
  12890.           row = cmd_rows;
  12891.         if (cmd_cols > 0 && col > cmd_cols)
  12892.           col = cmd_cols;
  12893.         y = ck_curpos(row,col);
  12894.         return(success = (y > -1) ? 1 : 0);
  12895.  
  12896.       case SCN_CLR:            /* CLEAR */
  12897.         if ((y = cmcfm()) < 0)
  12898.           return(y);
  12899.         debug(F100,"screen calling ck_cls()","",0);
  12900.         y = ck_cls();
  12901.         return(success = (y > -1) ? 1 : 0);
  12902.  
  12903.       case SCN_CLE:            /* CLEOL */
  12904.         if ((y = cmcfm()) < 0)
  12905.           return(y);
  12906.         y = ck_cleol();
  12907.         return(success = (y > -1) ? 1 : 0);
  12908.     }
  12909.     }
  12910.  
  12911. #ifndef NOHTTP
  12912. #ifdef TCPSOCKET
  12913.     if (cx == XXHTTP)
  12914.       return(dohttp());
  12915. #endif /* TCPSOCKET */
  12916. #endif /* NOHTTP */
  12917.  
  12918. #ifndef NOSPL
  12919.     if (cx == XXARRAY) {        /* ARRAY */
  12920. #ifndef NOSHOW
  12921.     extern int showarray();
  12922. #endif /* NOSHOW */
  12923.     if ((x = cmkey(arraytab, narraytab,"Array operation","",xxstring)) < 0)
  12924.       return(x);
  12925.     switch (x) {
  12926.       case ARR_DCL:
  12927.         return(dodcl(XXDCL));
  12928.       case ARR_SRT:
  12929.         return(dosort());
  12930. #ifndef NOSHOW
  12931.       case ARR_SHO:
  12932.         return(showarray());
  12933. #endif /* NOSHOW */
  12934.       case ARR_CPY:
  12935.         return(copyarray());
  12936.       case ARR_SET:
  12937.       case ARR_CLR:
  12938.         return(clrarray(x));
  12939.       case ARR_DST:
  12940.         return(unarray());
  12941.       case ARR_RSZ:
  12942.         return(rszarray());
  12943.       case ARR_EQU:
  12944.         return(linkarray());
  12945.  
  12946.       default:
  12947.         printf("?Sorry, not implemented yet - \"%s\"\n",cmdbuf);
  12948.         return(-9);
  12949.     }
  12950.     }
  12951.     if (cx == XXTRACE)            /* TRACE */
  12952.       return(dotrace());
  12953. #endif /* NOSPL */
  12954.  
  12955. #ifdef CK_PERMS
  12956. #ifdef UNIX
  12957.     if (cx == XXCHMOD)
  12958.       return(douchmod());        /* Do Unix chmod */
  12959. #endif /* UNIX */
  12960. #endif /* CK_PERMS */
  12961.  
  12962.     if (cx == XXPROMP)
  12963.       return(doprompt());
  12964.  
  12965.     if (cx == XXGREP)
  12966.       return(dogrep());
  12967.  
  12968.     if (cx == XXDEBUG) {        /* DEBUG */
  12969. #ifndef DEBUG
  12970.     int dummy = 0;
  12971.     return(seton(&dummy));
  12972. #else
  12973.     return(seton(&deblog));
  12974. #endif /* DEBUG */
  12975.     }
  12976.  
  12977. #ifdef CKLEARN
  12978.     if (cx == XXLEARN) {        /* LEARN */
  12979.     struct FDB of, sw, cm;
  12980.     int closing = 0, off = 0, on = 0, confirmed = 0;
  12981.     char c;
  12982.  
  12983.     cmfdbi(&sw,            /* 2nd FDB - optional /PAGE switch */
  12984.            _CMKEY,            /* fcode */
  12985.            "Script file name, or switch", /* hlpmsg */
  12986.            "",            /* default */
  12987.            "",            /* addtl string data */
  12988.            3,            /* addtl numeric data 1: tbl size */
  12989.            4,            /* addtl numeric data 2: 4 = cmswi */
  12990.            xxstring,        /* Processing function */
  12991.            learnswi,        /* Keyword table */
  12992.            &of            /* Pointer to next FDB */
  12993.            );
  12994.     cmfdbi(&of,_CMOFI,"","","",0,0,xxstring,NULL,&cm);
  12995.     cmfdbi(&cm,_CMCFM,"","","",0,0,NULL,NULL,NULL);
  12996.     line[0] = NUL;
  12997.  
  12998.     while (!confirmed) {
  12999.         x = cmfdb(&sw);        /* Parse something */
  13000.         if (x < 0)
  13001.           return(x);
  13002.         switch (cmresult.fcode) {    /* What was it? */
  13003.           case _CMOFI:        /* Output file name */
  13004.         ckstrncpy(line,cmresult.sresult,LINBUFSIZ);
  13005.         break;
  13006.           case _CMKEY:        /* Switch */
  13007.         c = cmgbrk();
  13008.         if ((c == ':' || c == '=') && !(cmgkwflgs() & CM_ARG)) {
  13009.             printf("?This switch does not take an argument\n");
  13010.             return(-9);
  13011.         }
  13012.         switch (cmresult.nresult) {
  13013.           case 2:        /* /CLOSE */
  13014.             closing = 1;    /* Fall thru on purpose */
  13015.           case 0:        /* /OFF */
  13016.             off = 1;
  13017.             on = 0;
  13018.             break;
  13019.           case 1:        /* /ON */
  13020.             on = 1;
  13021.             off = 0;
  13022.             break;
  13023.         }
  13024.         break;
  13025.           case _CMCFM:        /* Confirmation */
  13026.         confirmed++;
  13027.         break;
  13028.         }
  13029.     }
  13030.     if (closing) {
  13031.         if (learnfp) {
  13032.         fclose(learnfp);
  13033.         learnfp = NULL;
  13034.         }
  13035.         makestr(&learnfile,NULL);
  13036.     }
  13037.     if (line[0]) {
  13038.         if (!on && !off)
  13039.           on = 1;
  13040.         if (learnfp) {
  13041.         fclose(learnfp);
  13042.         learnfp = NULL;
  13043.         }
  13044.         makestr(&learnfile,line);
  13045.         if (learnfile) {
  13046.         char * modes = "w";
  13047.         learnfp = fopen(learnfile,modes);
  13048.         if (!learnfp) {
  13049.             debug(F110,"LEARN file open error",learnfile,0);
  13050.             perror(learnfile);
  13051.             return(-9);
  13052.         } else {
  13053. #ifdef ZFNQFP
  13054.             if (zfnqfp(learnfile,TMPBUFSIZ,tmpbuf))
  13055.               makestr(&learnfile,tmpbuf);
  13056. #endif /* ZFNQFP */
  13057.             debug(F110,"LEARN file open ok",learnfile,0);
  13058.             if (!quiet) {
  13059.             printf("Recording to %s...\n\n",learnfile);
  13060.             printf(
  13061. " WARNING: If you type your password during script recording, it will appear\n\
  13062.  in the file.  Be sure to edit it or take other appropriate precautions.\n\n"
  13063.                    );
  13064.             }
  13065.             fputs(  "; Scriptfile: ",learnfp);
  13066.             fputs(learnfile,learnfp);
  13067.             fputs("\n; Directory:  ",learnfp);
  13068.             fputs(zgtdir(),learnfp);
  13069.             fputs("\n; Recorded:   ",learnfp);
  13070.             fputs(ckdate(),learnfp);
  13071.             fputs("\n",learnfp);
  13072.         }
  13073.         }
  13074.     }
  13075.     if (on) {
  13076.         learning = 1;
  13077.     } else if (off) {
  13078.         learning = 0;
  13079.     }
  13080.     debug(F101,"LEARN learning","",learning);
  13081.     return(success = 1);
  13082.     }
  13083. #endif /* CKLEARN */
  13084.  
  13085. #ifdef NEWFTP
  13086.     if (cx == XXUSER || cx == XXACCT) {
  13087.     if (!ftpisopen()) {
  13088.         printf("?FTP connection is not open\n");
  13089.         return(-9);
  13090.     }
  13091.     return(success = (cx == XXUSER) ? doftpusr() : doftpacct());
  13092.     }
  13093.     if (cx == XXSITE || cx == XXPASV) {
  13094.     if (!ftpisopen()) {
  13095.         printf("?FTP connection is not open\n");
  13096.         return(-9);
  13097.     }
  13098.     return(success = (cx == XXSITE) ? doftpsite() : dosetftppsv());
  13099.     }
  13100. #endif /* NEWFTP */
  13101.  
  13102.     if (cx == XXORIE) {            /* ORIENTATION */
  13103.     extern char * myname;
  13104.     int i, y, n = 0;
  13105.         char * s, *p, vbuf[32];
  13106.     char * vars[16];       char * legend[16];
  13107.  
  13108.     if ((y = cmcfm()) < 0)
  13109.       return(y);
  13110.  
  13111.     printf("\nProgram name:\n  %s\n\n",myname);
  13112.     n += 4;
  13113.  
  13114. #ifdef NT
  13115.     vars[0] = "home";      legend[0] = "Your home directory";
  13116.     vars[1] = "directory"; legend[1] = "K95's current directory";
  13117.     vars[2] = "exedir";    legend[2] = "K95 Program directory";
  13118.     vars[3] = "inidir";    legend[3] = "K95 Initialization file directory";
  13119.     vars[4] = "startup";   legend[4] = "Current directory when started";
  13120.     
  13121.         vars[5] = "common";
  13122.         legend[5] = "K95 data for all users and K95SITE.INI file";
  13123.     
  13124.         vars[6] = "personal";  legend[6] = "Your personal data directory tree";
  13125.         vars[7] = "desktop";   legend[7] = "Your deskop directory tree";
  13126.     
  13127.         vars[8] = "appdata";
  13128.         legend[8] = "Your personal K95 data tree and K95CUSTOM.INI file";
  13129.     
  13130.         vars[9] = "download";  legend[9] = "Your K95 download directory";
  13131.         vars[10] = "tmpdir";   legend[10] = "Your TEMP directory";
  13132.     vars[11] = NULL;       legend[11] = NULL;
  13133.  
  13134.     for (i = 0; i < 16 && vars[i]; i++) {
  13135.         printf("%s:\n",legend[i]);
  13136.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13137.         ckmakmsg(vbuf,32,"\\v(",vars[i],")",NULL);
  13138.         printf("  Variable:   %s\n",vbuf);
  13139.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13140.         y = TMPBUFSIZ;
  13141.         s = tmpbuf;
  13142.         zzstring(vbuf,&s,&y);
  13143.         line[0] = NUL;
  13144.         ckGetLongPathName(tmpbuf,line,LINBUFSIZ);
  13145.         printf("  Long name:  %s\n",line);
  13146.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13147.         line[0] = NUL;
  13148.         GetShortPathName(tmpbuf,line,LINBUFSIZ);
  13149.         printf("  Short name: %s\n",line);
  13150.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13151.             printf("\n");
  13152.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13153.     }
  13154. #else  /* NT */
  13155.  
  13156.     vars[0] = "home";      legend[0] = "Your home directory";
  13157.     vars[1] = "directory"; legend[1] = "Kermit's current directory";
  13158.     vars[2] = "exedir";    legend[2] = "Kermit's program directory";
  13159.     vars[3] = "inidir";    legend[3] = "Initialization file directory";
  13160.     vars[4] = "startup";   legend[4] = "Current directory when started";
  13161.     vars[5] = "download";  legend[5] = "Kermit download directory";
  13162.     vars[6] = NULL;           legend[6] = NULL;
  13163.  
  13164.     for (i = 0; i < 16 && vars[i]; i++) {
  13165.         printf("%s:\n",legend[i]);
  13166.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13167.         ckmakmsg(vbuf,32,"\\v(",vars[i],")",NULL);
  13168.         printf("  Variable: %s\n",vbuf);
  13169.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13170.         y = TMPBUFSIZ;
  13171.         s = tmpbuf;
  13172.         zzstring(vbuf,&s,&y);
  13173.             printf("  Value:    %s\n",tmpbuf);
  13174.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13175.             printf("\n");
  13176.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13177.     }
  13178. #endif /* NT */
  13179.     return(success = 1);
  13180.     }
  13181.  
  13182. #ifdef NT
  13183.     if (cx == XXDIALER) {
  13184.         StartDialer();
  13185.         return(success = 1);
  13186.     }
  13187. #endif /* NT */
  13188.  
  13189.     if (cx == XXCONT) {            /* CONTINUE */
  13190.     if ((x = cmcfm()) < 0)
  13191.       return(x);
  13192.     if (!xcmdsrc) {            /* At prompt: continue script */
  13193.         if (cmdlvl > 0)
  13194.           popclvl();        /* Pop command level */
  13195.         return(success = 1);    /* always succeeds */
  13196. #ifndef NOSPL
  13197.     } else {            /* In script: whatever... */
  13198.         x = mlook(mactab,"continue",nmac);
  13199.         /* Don't set success */
  13200.         return(dodo(x,NULL,cmdstk[cmdlvl].ccflgs));
  13201. #endif /* NOSPL */
  13202.     }
  13203.     }
  13204. #ifdef UNIX
  13205. #ifndef NOPUTENV
  13206. /*
  13207.   NOTE: Syntax is PUTENV name value, not PUTENV name=value.
  13208.   I could check for this but it would be too much magic.
  13209. */
  13210.     if (cx == XXPUTE) {            /* PUTENV */
  13211.         char * t = tmpbuf;        /* Create or alter environment var */
  13212.     char * s1 = NULL, * s2 = NULL;
  13213.     if ((x = cmfld("Variable name","",&s,xxstring)) < 0)
  13214.           return(x);
  13215.     if (s) if (s == "") s = NULL;
  13216.     (VOID) makestr(&s1,s);
  13217.     if (s && !s1) {
  13218.         printf("?PUTENV - memory allocation failure\n");
  13219.         return(-9);
  13220.     }
  13221.     if ((x = cmtxt("Value","",&s,xxstring)) < 0)
  13222.       return(x);
  13223.     if (s) if (s == "") s = NULL;
  13224.     (VOID) makestr(&s2,s);
  13225.     success = doputenv(s1,s2);
  13226.     (VOID) makestr(&s1,NULL);
  13227.     (VOID) makestr(&s2,NULL);
  13228.     return(success);
  13229.     }
  13230. #endif    /* NOPUTENV */
  13231. #endif    /* UNIX */
  13232.  
  13233.     if (cx == XXNOTAV) {        /* Command in table not available */
  13234.     ckstrncpy(tmpbuf,atmbuf,TMPBUFSIZ);
  13235.     if ((x = cmtxt("Rest of command","",&s,NULL)) < 0)
  13236.       return(x);
  13237.     printf("Sorry, \"%s\" not configured in this version of Kermit.\n",
  13238.            tmpbuf
  13239.            );
  13240.     return(success = 0);
  13241.     }
  13242.     return(-2);                /* None of the above */
  13243.  
  13244. } /* end of docmd() */
  13245.  
  13246. #endif /* NOICP */
  13247.