home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / ck9196.zip / ckuus7.c < prev    next >
C/C++ Source or Header  |  2000-01-02  |  384KB  |  13,261 lines

  1. #include "ckcsym.h"
  2.  
  3. #ifndef NOICP
  4.  
  5. /*  C K U U S 7 --  "User Interface" for C-Kermit, part 7  */
  6.  
  7. /*
  8.   Author: Frank da Cruz <fdc@columbia.edu>,
  9.   Columbia University Academic Information Systems, New York City.
  10.  
  11.   Copyright (C) 1985, 2000,
  12.     Trustees of Columbia University in the City of New York.
  13.     All rights reserved.  See the C-Kermit COPYING.TXT file or the
  14.     copyright text in the ckcmai.c module for disclaimer and permissions.
  15. */
  16.  
  17. /*
  18.   This file created from parts of ckuus3.c, which became too big for
  19.   Mark Williams Coherent compiler to handle.
  20. */
  21.  
  22. /*
  23.   Definitions here supersede those from system include files.
  24. */
  25. #include "ckcdeb.h"            /* Debugging & compiler things */
  26. #include "ckcasc.h"            /* ASCII character symbols */
  27. #include "ckcker.h"            /* Kermit application definitions */
  28. #include "ckcxla.h"            /* Character set translation */
  29. #include "ckcnet.h"            /* Network symbols */
  30. #include "ckuusr.h"            /* User interface symbols */
  31. #include "ckucmd.h"
  32.  
  33. #ifdef VMS
  34. #ifndef TCPSOCKET
  35. #include <errno.h>
  36. #endif /* TCPSOCKET */
  37. #endif /* VMS */
  38.  
  39. #ifdef OS2
  40. #ifndef NT
  41. #define INCL_NOPM
  42. #define INCL_VIO            /* Needed for ckocon.h */
  43. #define INCL_DOSMODULEMGR
  44. #include <os2.h>
  45. #undef COMMENT
  46. #else /* NT */
  47. #define APIRET ULONG
  48. #include <windows.h>
  49. #include <tapi.h>
  50. #include "cknwin.h"
  51. #include "ckntap.h"
  52. #endif /* NT */
  53. #include "ckowin.h"
  54. #include "ckocon.h"
  55. #include "ckodir.h"
  56. #ifdef OS2MOUSE
  57. #include "ckokey.h"
  58. #endif /* OS2MOUSE */
  59. #ifdef KUI
  60. #include "ikui.h"
  61. #endif /* KUI */
  62. #ifdef putchar
  63. #undef putchar
  64. #endif /* putchar */
  65. #define putchar(x) conoc(x)
  66. extern int mskkeys;
  67. #endif /* OS2 */
  68.  
  69. #ifdef CK_AUTHENTICATION
  70. #include "ckuath.h"
  71. #endif /* CK_AUTHENTICATION */
  72. #ifdef CK_SSL
  73. #include "ck_ssl.h"
  74. #endif /* CK_SSL */
  75.  
  76. #ifdef STRATUS                /* Stratus Computer, Inc.  VOS */
  77. #ifdef putchar
  78. #undef putchar
  79. #endif /* putchar */
  80. #define putchar(x) conoc(x)
  81. #ifdef getchar
  82. #undef getchar
  83. #endif /* getchar */
  84. #define getchar(x) coninc(0)
  85. #endif /* STRATUS */
  86.  
  87. char * slmsg = NULL;
  88. static char * tmpslmsg = NULL;
  89.  
  90. static int x, y = 0, z;
  91. static char *s;
  92.  
  93. extern CHAR feol;
  94. extern int g_matchdot, saveask, hints;
  95.  
  96. extern char * k_info_dir;
  97.  
  98. #ifndef NOSPL
  99. extern int nmac;
  100. extern struct mtab *mactab;
  101. #endif /* NOSPL */
  102.  
  103. #ifndef NOXFER
  104. #ifdef CK_SPEED
  105. extern short ctlp[];            /* Control-char prefixing table */
  106. #endif /* CK_SPEED */
  107.  
  108. #ifdef PIPESEND
  109. extern char * sndfilter;
  110. extern char * rcvfilter;
  111. #endif /* PIPESEND */
  112.  
  113. extern char * snd_move;
  114. extern char * snd_rename;
  115. extern char * g_snd_move;
  116. extern char * g_snd_rename;
  117. extern char * rcv_move;
  118. extern char * rcv_rename;
  119. extern char * g_rcv_move;
  120. extern char * g_rcv_rename;
  121.  
  122. #ifdef PATTERNS
  123. extern char *binpatterns[], *txtpatterns[];
  124. extern int patterns;
  125. #endif /* PATTERNS */
  126.  
  127. extern char * remdest;
  128. #ifdef CK_TMPDIR
  129. char * dldir = NULL;
  130. #endif /* CK_TMPDIR */
  131.  
  132. extern struct ck_p ptab[];
  133.  
  134. extern int protocol, remfile, rempipe, remappd, reliable, xreliable, fmask,
  135.   fncnv, frecl, maxrps, wslotr, bigsbsiz, bigrbsiz, urpsiz, rpsiz, spsiz,
  136.   bctr, npad, timef, timint, spsizr, spsizf, maxsps, spmax, nfils, displa,
  137.   atcapr, pkttim, rtimo, fncact, mypadn, fdispla, f_save, pktpaus, setreliable,
  138.   fnrpath, fnspath, atenci, atenco, atdati, atdato, atleni, atleno, atblki,
  139.   atblko, attypi, attypo, atsidi, atsido, atsysi, atsyso, atdisi, atdiso;
  140.  
  141. extern int stathack;
  142.  
  143. #ifdef STRATUS
  144. extern int atfrmi, atfrmo, atcrei, atcreo, atacti, atacto;
  145. #endif /* STRATUS */
  146. #ifdef CK_PERMS
  147. extern int atlpri, atlpro, atgpri, atgpro;
  148. #endif /* CK_PERMS */
  149.  
  150. extern CHAR
  151.   sstate, eol, seol, stchr, mystch, mypadc, padch, ctlq, myctlq;
  152.  
  153. #ifdef IKSD
  154. extern int inserver;
  155. #ifdef IKSDCONF
  156. extern int iksdcf;
  157. #endif /* IKSDCONF */
  158. #endif /* IKSD */
  159.  
  160. extern char *cmarg, *cmarg2;
  161.  
  162. #ifndef NOFRILLS
  163. extern char optbuf[];            /* Buffer for MAIL or PRINT options */
  164. extern int rprintf;            /* REMOTE PRINT flag */
  165. #endif /* NOFRILLS */
  166. #endif /* NOXFER */
  167.  
  168. #ifdef CK_TRIGGER
  169. extern char * tt_trigger[];
  170. #endif /* CK_TRIGGER */
  171.  
  172. extern int tcs_transp;
  173. #ifdef PCTERM
  174. extern int tt_pcterm;
  175. #endif /* PCTERM */
  176. #ifdef NT
  177. extern int tt_vtnt;
  178. #endif /* NT */
  179.  
  180. /* Note: gcc -Wall wants braces around each keyword table entry. */
  181.  
  182. static struct keytab psltab[] = {    /* SET LINE/PORT command options */
  183.     { "/connect", SL_CNX, 0 },
  184. #ifdef VMS
  185.     { "/noshare", SL_NSH, 0 },
  186. #endif /* VMS */
  187.     { "/server",  SL_SRV, 0 },
  188. #ifdef VMS
  189.     { "/share",   SL_SHR, 0 },
  190. #endif /* VMS */
  191.     { "", 0, 0 }
  192. };
  193. static int npsltab = sizeof(psltab)/sizeof(struct keytab) - 1;
  194.  
  195. #ifdef NETCONN
  196. static struct keytab shtab[] = {    /* SET HOST command options */
  197. #ifdef NETCMD
  198.     "/command",      SL_CMD,    CM_INV,    /* (COMMAND is also a network type) */
  199. #endif /* NETCMD */
  200.     "/connect",      SL_CNX,    0,
  201.     "/network-type", SL_NET,    CM_ARG,
  202.     "/nowait",       SL_NOWAIT, 0,
  203. #ifndef NOSPL
  204.     "/password",     SL_PSW,    CM_ARG,
  205. #endif /* NOSPL */
  206. #ifdef NETCMD
  207.     "/pipe",         SL_CMD,    0,
  208. #endif /* NETCMD */
  209. #ifdef NETPTY
  210.     "/pty",          SL_PTY,    0,
  211. #endif /* NETPTY */
  212.     "/server",       SL_SRV,    0,
  213.     "/userid",       SL_UID,    CM_ARG,
  214.     "/wait",         SL_WAIT,   0,
  215.     "", 0, 0
  216. };
  217. static int nshtab = sizeof(shtab)/sizeof(struct keytab) - 1;
  218.  
  219. static struct keytab shteltab[] = {    /* TELNET command options */
  220. #ifdef CK_AUTHENTICATION
  221.     "/auth",         SL_AUTH, CM_ARG,
  222. #endif /* CK_AUTHENTICATION */
  223. #ifdef CK_ENCRYPTION
  224.     "/encrypt",      SL_ENC,  CM_ARG,
  225. #endif /* CK_ENCRYPTION */
  226.     "/nowait",       SL_NOWAIT, 0,
  227. #ifndef NOSPL
  228.     "/password",     SL_PSW, CM_ARG,
  229. #endif /* NOSPL */
  230.     "/userid",       SL_UID, CM_ARG,
  231.     "/wait",         SL_WAIT,   0,
  232.     "", 0 ,0
  233. };
  234. static int nshteltab = sizeof(shteltab)/sizeof(struct keytab) - 1;
  235.  
  236. #ifdef RLOGCODE
  237. static struct keytab shrlgtab[] = {    /* SET HOST RLOGIN command options */
  238. #ifdef CK_KERBEROS
  239. #ifdef CK_ENCRYPTION
  240.     "/encrypt",      SL_ENC, 0,
  241. #endif /* CK_ENCRYPTION */
  242.     "/k4",           SL_KRB4, CM_INV,
  243.     "/k5",           SL_KRB5, CM_INV,
  244.     "/kerberos4",    SL_KRB4, 0,
  245.     "/kerberos5",    SL_KRB5, 0,
  246.     "/kerberos_iv",  SL_KRB4, CM_INV,
  247.     "/kerberos_v",   SL_KRB5, CM_INV,
  248.     "/krb4",         SL_KRB4, CM_INV,
  249.     "/krb5",         SL_KRB5, CM_INV,
  250. #endif /* CK_KERBEROS */
  251.     "", 0 ,0
  252. };
  253. static int nshrlgtab = sizeof(shrlgtab)/sizeof(struct keytab)-1;
  254. #endif /* RLOGCODE */
  255.  
  256. extern struct keytab netcmd[];
  257. extern int nnets;
  258. #ifndef NODIAL
  259. extern int dirline;
  260. extern int nnetdir;            /* Network services directory */
  261. extern char *netdir[];
  262. _PROTOTYP( VOID ndreset, (void) );
  263. char *nh_p[MAXDNUMS + 1];        /* Network directory entry pointers */
  264. char *nh_p2[MAXDNUMS + 1];        /* Network directory entry nettype */
  265. char *nh_px[4][MAXDNUMS + 1];        /* Network-specific stuff... */
  266. #endif /* NODIAL */
  267. int nhcount = 0;
  268. int ndinited = 0;
  269. char * n_name = NULL;            /* Network name pointer */
  270. static int oldplex = -1;        /* Duplex holder around network */
  271. #endif /* NETCONN */
  272.  
  273. _PROTOTYP(static int remtxt, (char **) );
  274. _PROTOTYP(VOID rmsg, (void) );
  275. _PROTOTYP(static int remcfm, (void) );
  276.  
  277. extern int nopush;
  278.  
  279. int mdmsav = -1;            /* Save modem type around network */
  280. extern int isguest;            /* Global flag for anonymous login */
  281.  
  282. extern xx_strp xxstring;
  283.  
  284. extern int success, binary, b_save, ckwarn, msgflg, quiet, cmask, pflag, local,
  285.   nettype, escape, mdmtyp, duplex, dfloc, network, cdtimo, autoflow, tnlm,
  286.   sosi, tlevel, lf_opts, backgrd, flow, debses, parity, ttnproto, ckxech,
  287.   x_ifnum, cmflgs, haveline, cxtype, cxflow[];
  288.  
  289. extern char psave[];            /* For saving & restoring prompt */
  290. extern int sprmlen, rprmlen;
  291.  
  292. #ifdef OS2
  293. static struct keytab strmkeytab[] = {
  294.     "clear",   0, 0,
  295.     "default", 1, 0
  296. };
  297. static int nstrmkeytab = sizeof(strmkeytab)/sizeof(struct keytab);
  298.  
  299. static struct keytab strmswitab[] = {
  300.     "/literal", 0, 0
  301. };
  302. static int nstrmswitab = sizeof(strmswitab)/sizeof(struct keytab);
  303.  
  304. static struct keytab normrev[] = {
  305.     "dark-display", 0, 0,
  306.     "light-display", 1, 0,
  307.     "normal",   0, 0,
  308.     "reverse",  1, 0
  309. };
  310.  
  311. static struct keytab prnmtab[] = {
  312.     "auto", 1, 0,
  313.     "copy", 2, 0,
  314.     "off",  0, 0,
  315.     "on",   1, CM_INV,            /* Compatibility with XPRINT version */
  316.     "transparent", 3, 0
  317. };
  318. static int nprnmtab = sizeof(prnmtab)/sizeof(struct keytab);
  319.  
  320. extern int tt_diff_upd;
  321.  
  322. #ifdef NT
  323. #define stricmp _stricmp
  324. extern int tt_attr_bug;
  325. #endif /* NT */
  326. extern int tt_rows[], tt_cols[];
  327. extern int tt_cols_usr;
  328. extern int tt_szchng[VNUM];
  329. int tt_modechg = TVC_ENA;
  330. extern struct _vtG G[4];
  331. extern int priority;
  332. extern bool send_c1;
  333. int send_c1_usr = FALSE;
  334. extern int sgrcolors;
  335. extern int marginbell, marginbellcol;
  336. extern int autoscroll, wy_autopage;
  337. extern int tt_sac;
  338. extern int dec_nrc, dec_lang, dec_kbd;
  339. #else /* OS2 */
  340. extern int tt_rows, tt_cols;
  341. #endif /*  OS2 */
  342.  
  343. extern int tt_escape;
  344. extern long speed;
  345.  
  346. extern char *dftty;
  347.  
  348. extern char *tp, *lp;            /* Temporary buffer & pointers */
  349. extern char ttname[];
  350.  
  351. int tttapi = 0;                /* is Line TAPI? */
  352. struct keytab * tapilinetab = NULL;
  353. struct keytab * _tapilinetab = NULL;
  354. int ntapiline = 0;
  355.  
  356. #ifdef NETCONN                /* Network items */
  357.  
  358. #ifdef ANYX25
  359. extern int revcall, closgr, cudata, nx25;
  360. extern char udata[];
  361. extern struct keytab x25tab[];
  362. #ifndef IBMX25
  363. extern int npadx3;
  364. extern CHAR padparms[];
  365. extern struct keytab padx3tab[];
  366. #endif /* IBMX25 */
  367. #endif /* ANYX25 */
  368.  
  369. #ifdef OS2
  370. #ifndef NT
  371. extern bool ttslip,ttppp;
  372. #endif /* NT */
  373. #endif /* OS2 */
  374. #ifdef NPIPE
  375. extern char pipename[];
  376. #endif /* NPIPE */
  377.  
  378. #ifdef TCPSOCKET
  379. static struct keytab tcprawtab[] = {    /* SET HOST options */
  380.     "/default",    NP_DEFAULT,    CM_INV,
  381. #ifdef CK_AUTHENTICATION
  382. #ifdef CK_KERBEROS
  383. #ifdef RLOGCODE
  384.     "/ek4login",    NP_EK4LOGIN,    0,
  385.     "/ek5login",    NP_EK5LOGIN,    0,
  386.     "/k4login",     NP_K4LOGIN,     0,
  387.     "/k5login",     NP_K5LOGIN,     0,
  388. #endif /* RLOGCODE */
  389. #endif /* CK_KERBEROS */
  390. #endif /* CK_AUTHENTICATION */
  391.     "/no-telnet-init", NP_NONE,   0,
  392.     "/none",       NP_NONE,   CM_INV,
  393.     "/raw-socket", NP_TCPRAW, 0,
  394. #ifdef RLOGCODE
  395.     "/rlogin",     NP_RLOGIN, 0,
  396. #endif /* RLOGCODE */
  397. #ifdef CK_SSL
  398.     "/ssl",        NP_SSL,    0,
  399.     "/ssl-telnet", NP_SSL_TELNET, 0,
  400. #endif /* CK_SSL */
  401.     "/telnet",     NP_TELNET, 0,
  402. #ifdef CK_SSL
  403.     "/tls",        NP_TLS,    0,
  404.     "/tls-telnet", NP_TLS_TELNET, 0,
  405. #endif /* CK_SSL */
  406.     "", 0, 0
  407. };
  408. static int ntcpraw = (sizeof(tcprawtab) / sizeof(struct keytab)) - 1;
  409.  
  410. #ifdef RLOGCODE
  411. _PROTOTYP( int rlog_naws, (void) );
  412. #endif /* RLOGCODE */
  413. #endif /* TCPSOCKET */
  414.  
  415. #ifdef SUPERLAT
  416. extern char slat_pwd[18];
  417. #endif /* SUPERLAT */
  418. #endif /* NETCONN */
  419.  
  420. #ifdef TNCODE
  421. extern int tn_wait_flg;
  422. #endif /* TNCODE */
  423.  
  424. #ifdef COMMENT
  425. #ifndef NOSETKEY
  426. extern KEY *keymap;
  427. #ifndef OS2
  428. #define mapkey(x) keymap[x]
  429. #endif /* OS2 */
  430. extern MACRO *macrotab;
  431. _PROTOTYP( VOID shostrdef, (CHAR *) );
  432. #ifndef NOKVERBS
  433. extern struct keytab kverbs[];
  434. extern int nkverbs;
  435. #endif /* NOKVERBS */
  436. #endif /* NOSETKEY */
  437. #else
  438. #ifndef NOSETKEY
  439. extern KEY *keymap;
  440. extern MACRO *macrotab;
  441. _PROTOTYP( VOID shostrdef, (CHAR *) );
  442. #ifndef NOKVERBS
  443. extern struct keytab kverbs[];
  444. extern int nkverbs;
  445. #endif /* NOKVERBS */
  446. #endif /* NOSETKEY */
  447. #endif /* COMMENT */
  448.  
  449. #ifdef OS2                /* AUTODOWNLOAD parameters */
  450. extern int    adl_kmode, adl_zmode;    /* Match Packet to signal download */
  451. extern char * adl_kstr;            /* KERMIT Download String */
  452. extern char * adl_zstr;            /* ZMODEM Download String */
  453. extern int adl_kc0, adl_zc0;        /* Process ADL C0s in emulation */
  454. #endif /* OS2 */
  455.  
  456. /* Keyword tables ... */
  457.  
  458. extern struct keytab onoff[], rltab[];
  459. extern int nrlt;
  460.  
  461. /* SET FILE parameters */
  462.  
  463. static struct keytab filtab[] = {
  464. #ifndef NOXFER
  465. #ifdef PATTERNS
  466.     "binary-patterns",   XYFIBP, 0,
  467. #endif /* PATTERNS */
  468.     "bytesize",         XYFILS, 0,
  469. #ifndef NOCSETS
  470.     "character-set",    XYFILC, 0,
  471. #endif /* NOCSETS */
  472.     "collision",        XYFILX, 0,
  473.     "destination",      XYFILY, 0,
  474.     "display",          XYFILD, CM_INV,
  475. #ifdef CK_TMPDIR
  476.     "download-directory", XYFILG, 0,
  477. #endif /* CK_TMPDIR */
  478. #endif /* NOXFER */
  479.     "end-of-line",      XYFILA, 0,
  480.     "eol",              XYFILA, CM_INV,
  481. #ifdef CK_CTRLZ
  482.     "eof",              XYFILV, 0,
  483. #endif /* CK_CTRLZ */
  484.     "fastlookups",      9997,   CM_INV,
  485. #ifndef NOXFER
  486.     "incomplete",       XYFILI, 0,
  487. #ifdef CK_LABELED
  488.     "label",            XYFILL, 0,
  489. #endif /* CK_LABELED */
  490.     "names",            XYFILN, 0,
  491. #ifdef UNIX
  492.     "output",           XYFILH, 0,
  493. #endif /* UNIX */
  494. #ifdef PATTERNS
  495.     "patterns",         XYFIPA, 0,
  496. #endif /* PATTERNS */
  497. #ifdef VMS
  498.     "record-length",    XYFILR, 0,
  499. #endif /* VMS */
  500. #ifdef PATTERNS
  501.     "text-patterns",    XYFITP, 0,
  502. #endif /* PATTERNS */
  503. #endif /* NOXFER */
  504.     "type",             XYFILT, 0,
  505. #ifdef UNICODE
  506.     "ucs",              XYFILU, 0,
  507. #endif /* UNICODE */
  508. #ifndef NOXFER
  509.     "warning",          XYFILW, CM_INV
  510. #endif /* NOXFER */
  511. };
  512. static int nfilp = (sizeof(filtab) / sizeof(struct keytab));
  513.  
  514. struct keytab pathtab[] = {
  515.     "absolute",  PATH_ABS,  0,
  516.     "none",      PATH_OFF,  CM_INV,
  517.     "off",       PATH_OFF,  0,
  518.     "on",        PATH_ABS,  CM_INV,
  519.     "relative",  PATH_REL,  0
  520. };
  521. int npathtab = (sizeof(pathtab) / sizeof(struct keytab));
  522.  
  523. struct keytab rpathtab[] = {
  524.     "absolute",  PATH_ABS,  0,
  525.     "auto",      PATH_AUTO, 0,
  526.     "none",      PATH_OFF,  CM_INV,
  527.     "off",       PATH_OFF,  0,
  528.     "on",        PATH_ABS,  CM_INV,
  529.     "relative",  PATH_REL,  0
  530. };
  531. int nrpathtab = (sizeof(rpathtab) / sizeof(struct keytab));
  532.  
  533. #ifdef CK_CTRLZ
  534. struct keytab eoftab[] = {        /* EOF detection method */
  535.     "ctrl-z",          1, 0,
  536.     "length",          0, 0,
  537.     "noctrl-z",        0, CM_INV
  538. };
  539. #endif /* CK_CTRLZ */
  540.  
  541. struct keytab fttab[] = {        /* File types for SET FILE TYPE */
  542.     "ascii",     XYFT_T, CM_INV,
  543. #ifdef VMS
  544.     "b",         XYFT_B, CM_INV|CM_ABR,
  545. #endif /* VMS */
  546.     "binary",    XYFT_B, 0,
  547. #ifdef VMS
  548.     "block",     XYFT_I, CM_INV,
  549.     "image",     XYFT_I, 0,
  550. #endif /* VMS */
  551. #ifdef CK_LABELED
  552.     "labeled",   XYFT_L, 0,
  553. #endif /* CK_LABELED */
  554. #ifdef MAC
  555.     "macbinary", XYFT_M, 0,
  556. #endif /* MAC */
  557.     "text",      XYFT_T, 0
  558. };
  559. int nfttyp = (sizeof(fttab) / sizeof(struct keytab));
  560.  
  561. static struct keytab rfttab[] = {    /* File types for REMOTE SET FILE */
  562.     "ascii",     XYFT_T, CM_INV,
  563.     "binary",    XYFT_B, 0,
  564. #ifdef VMS
  565.     "labeled",   XYFT_L, 0,
  566. #else
  567. #ifdef OS2
  568.     "labeled",   XYFT_L, 0,
  569. #endif /* OS2 */
  570. #endif /* VMS */
  571.     "text",      XYFT_T, 0
  572. };
  573. static int nrfttyp = (sizeof(rfttab) / sizeof(struct keytab));
  574.  
  575. #ifdef OS2ORUNIX
  576. #define ZOF_BLK  0
  577. #define ZOF_NBLK 1
  578. #define ZOF_BUF  2
  579. #define ZOF_NBUF 3
  580. static struct keytab zoftab[] = {
  581.     "blocking",    ZOF_BLK,  0,
  582.     "buffered",    ZOF_BUF,  0,
  583.     "nonblocking", ZOF_NBLK, 0,
  584.     "unbuffered",  ZOF_NBUF, 0
  585. };
  586. static int nzoftab = (sizeof(zoftab) / sizeof(struct keytab));
  587. #endif /* OS2ORUNIX */
  588.  
  589. #ifdef CK_AUTHENTICATION
  590. extern int auth_type_user[];
  591. int sl_auth_type_user[AUTHTYPLSTSZ] = {AUTHTYPE_NULL, AUTHTYPE_NULL};
  592. int sl_auth_saved = 0;
  593. int sl_topt_a_su = 0;
  594. int sl_topt_a_s_saved = 0;
  595. int sl_topt_a_cm = 0;
  596. int sl_topt_a_c_saved = 0;
  597. #endif /* CK_AUTHENTICATION */
  598. #ifdef CK_ENCRYPTION
  599. extern int cx_type;
  600. int sl_cx_type = 0;
  601. int sl_cx_saved = 0;
  602. int sl_topt_e_su = 0;
  603. int sl_topt_e_sm = 0;
  604. int sl_topt_e_s_saved = 0;
  605. int sl_topt_e_cu = 0;
  606. int sl_topt_e_cm = 0;
  607. int sl_topt_e_c_saved = 0;
  608. #endif /* CK_ENCRYPTION */
  609. extern char uidbuf[];
  610. static int uidflag = 0;
  611. char sl_uidbuf[UIDBUFLEN] = { NUL, NUL };
  612. int  sl_uid_saved = 0;
  613. #ifdef TNCODE
  614. int  sl_tn_wait = 0;
  615. int  sl_tn_saved = 0;
  616. #endif /* TNCODE */
  617.  
  618. extern int query;            /* Global flag for QUERY active */
  619.  
  620. #ifndef NOSPL
  621. #ifndef NOXFER
  622. static struct keytab vartyp[] = {    /* Variable types for REMOTE QUERY */
  623.     "global",   (int) 'G', CM_INV,
  624.     "kermit",   (int) 'K', 0,
  625.     "system",   (int) 'S', 0,
  626.     "user",     (int) 'G', 0
  627. };
  628. static int nvartyp = (sizeof(vartyp) / sizeof(struct keytab));
  629. #endif /* NOXFER */
  630. #endif /* NOSPL */
  631.  
  632. #ifdef CK_TIMERS
  633. static struct keytab timotab[] = {    /* Timer types */
  634.     "dynamic", 1, 0,
  635.     "fixed",   0, 0
  636. };
  637. #endif /* CK_TIMERS */
  638.  
  639. #ifdef DCMDBUF
  640. extern char *atxbuf, *atmbuf;        /* Atom buffer */
  641. extern char *cmdbuf;            /* Command buffer */
  642. extern char *line, *tmpbuf;        /* Character buffers for anything */
  643. extern int *intime;            /* INPUT TIMEOUT */
  644.  
  645. #else  /* Not DCMDBUF ... */
  646.  
  647. extern char atxbuf[], atmbuf[];        /* Atom buffer */
  648. extern char cmdbuf[];            /* Command buffer */
  649. extern char line[], tmpbuf[];        /* Character buffer for anything */
  650. extern int intime[];
  651.  
  652. #endif /* DCMDBUF */
  653.  
  654. #ifndef NOCSETS
  655. extern struct keytab fcstab[];        /* For SET FILE CHARACTER-SET */
  656. extern struct csinfo fcsinfo[];        /* File character set info. */
  657. extern struct keytab ttcstab[];
  658. extern int nfilc, fcharset, tcharset, ntermc, tcsr, tcsl;
  659. #ifdef CKOUNI
  660. extern int tt_utf8;
  661. #endif /* CKOUNI */
  662. #ifdef OS2
  663. _PROTOTYP( int os2setcp, (int) );
  664. _PROTOTYP( int os2getcp, (void) );
  665. _PROTOTYP( void os2debugoff, (void) );
  666. #endif /* OS2 */
  667. #endif /* NOCSETS */
  668.  
  669. extern int cmdlvl;            /* Overall command level */
  670.  
  671. #ifndef NOSPL
  672. #ifdef DCMDBUF
  673. extern int *inpcas;            /* INPUT CASE setting on cmd stack */
  674. #else
  675. extern int inpcas[];
  676. #endif /* DCMDBUF */
  677. #endif /* NOSPL */
  678.  
  679. #ifdef CK_CURSES
  680. #ifndef VMS
  681. _PROTOTYP(int tgetent,(char *, char *));
  682. #else
  683. #ifdef __DECC
  684. _PROTOTYP(int tgetent,(char *, char *));
  685. #endif /* __DECC */
  686. #endif /* VMS */
  687. #endif /* CK_CURSES */
  688.  
  689. #ifndef NOXMIT
  690. #define XMITF 0                /* SET TRANSMIT values */
  691. #define XMITL 1                /* (Local to this module) */
  692. #define XMITP 2
  693. #define XMITE 3
  694. #define XMITX 4
  695. #define XMITS 5
  696. #define XMITW 6
  697. #define XMITT 7
  698.  
  699. #define XMBUFL 50
  700. extern int xmitf, xmitl, xmitp, xmitx, xmits, xmitw, xmitt;
  701. char xmitbuf[XMBUFL+1] = { NUL };    /* TRANSMIT eof string */
  702.  
  703. struct keytab xmitab[] = {        /* SET TRANSMIT */
  704.     "echo",     XMITX, 0,
  705.     "eof",      XMITE, 0,
  706.     "fill",     XMITF, 0,
  707.     "linefeed", XMITL, 0,
  708.     "locking-shift", XMITS, 0,
  709.     "pause",    XMITW, 0,
  710.     "prompt",   XMITP, 0,
  711.     "timeout",  XMITT, 0
  712. };
  713. int nxmit = (sizeof(xmitab) / sizeof(struct keytab));
  714. #endif /* NOXMIT */
  715.  
  716. /* For SET FILE COLLISION */
  717. /* Some of the following may be possible for some C-Kermit implementations */
  718. /* but not others.  Those that are not possible for your implementation */
  719. /* should be ifdef'd out. */
  720.  
  721. struct keytab colxtab[] = { /* SET FILE COLLISION options */
  722. #ifndef MAC
  723.     "append",    XYFX_A, 0,  /* append to old file */
  724. #endif /* MAC */
  725. #ifdef COMMENT
  726.     "ask",       XYFX_Q, 0,  /* ask what to do (not implemented) */
  727. #endif
  728.     "backup",    XYFX_B, 0,  /* rename old file */
  729. #ifndef MAC
  730.     /* This crashes Mac Kermit. */
  731.     "discard",   XYFX_D, 0,  /* don't accept new file */
  732.     "no-supersede", XYFX_D, CM_INV, /* ditto (MSK compatibility) */
  733. #endif /* MAC */
  734.     "overwrite", XYFX_X, 0,  /* overwrite the old file == file warning off */
  735.     "rename",    XYFX_R, 0   /* rename the incoming file == file warning on */
  736. #ifndef MAC
  737.     /* This crashes Mac Kermit. */
  738. ,   "update",    XYFX_U, 0  /* replace if newer */
  739. #endif /* MAC */
  740. };
  741. int ncolx = (sizeof(colxtab) / sizeof(struct keytab));
  742.  
  743. static struct keytab rfiltab[] = {    /* for REMOTE SET FILE */
  744. #ifndef NOCSETS
  745.     "character-set", XYFILC, 0,
  746. #endif /* NOCSETS */
  747.     "collision",     XYFILX, 0,
  748.     "incomplete",    XYFILI, 0,
  749.     "names",         XYFILN, 0,
  750.     "record-length", XYFILR, 0,
  751.     "type",          XYFILT, 0
  752. };
  753. int nrfilp = (sizeof(rfiltab) / sizeof(struct keytab));
  754.  
  755. struct keytab eoltab[] = {           /* File eof delimiters */
  756.     "cr",        XYFA_C, 0,
  757.     "crlf",      XYFA_2, 0,
  758.     "lf",        XYFA_L, 0
  759. };
  760. static int neoltab = (sizeof(eoltab) / sizeof(struct keytab));
  761.  
  762. struct keytab fntab[] = {           /* File naming */
  763.     "converted", XYFN_C, 0,
  764.     "literal",   XYFN_L, 0,
  765.     "standard",  XYFN_C, CM_INV
  766. };
  767. int nfntab = (sizeof(fntab) / sizeof(struct keytab));
  768.  
  769. #ifndef NOLOCAL
  770. /* Terminal parameters table */
  771. static struct keytab trmtab[] = {
  772. #ifdef OS2
  773.     "answerback",    XYTANS, 0,
  774. #endif /* OS2 */
  775. #ifdef CK_APC
  776.     "apc",           XYTAPC, 0,
  777. #endif /* CK_APC */
  778. #ifdef OS2
  779.     "arrow-keys",    XYTARR, 0,
  780. #endif /* OS2 */
  781. #ifdef NT
  782.     "at",         XYTATTR, CM_INV|CM_ABR,
  783.     "att",         XYTATTR, CM_INV|CM_ABR,
  784.     "attr",         XYTATTR, CM_INV|CM_ABR,
  785.     "attr-bug",      XYTATTBUG, CM_INV,
  786. #endif /* NT */
  787. #ifdef OS2
  788.     "attribute",     XYTATTR, 0,
  789. #endif /* OS2 */
  790. #ifdef CK_APC
  791. #ifdef CK_AUTODL
  792.    "autodownload",   XYTAUTODL, 0,
  793. #endif /* CK_AUTODL */
  794. #endif /* CK_APC */
  795. #ifdef OS2
  796.     "autopage",      XYTAPAGE,  0,
  797.     "autoscroll",    XYTASCRL,  0,
  798.     "bell",          XYTBEL, CM_INV,
  799. #endif /* OS2 */
  800.     "bytesize",      XYTBYT, 0,
  801. #ifndef NOCSETS
  802. #ifndef KUI
  803. #ifdef OS2
  804.     "character-set", XYTCS,  CM_INV,
  805. #else /* OS2 */
  806.     "character-set", XYTCS,  0,
  807. #endif /* OS2 */
  808. #endif /* KUI */
  809. #endif /* NOCSETS */
  810. #ifdef OS2
  811.     "code-page",     XYTCPG, 0,
  812.     "color",         XYTCOL, 0,
  813.     "controls",      XYTCTRL, 0,
  814. #endif /* OS2 */
  815.     "cr-display",    XYTCRD, 0,
  816. #ifdef OS2
  817.     "cursor",        XYTCUR, 0,
  818. #endif /* OS2 */
  819.     "debug",         XYTDEB, 0,
  820. #ifdef OS2
  821.     "dg-unix-mode",     XYTUNX, 0,
  822. #endif /* OS2 */
  823.     "echo",          XYTEC,  0,
  824.     "escape-character", XYTESC, 0,
  825. #ifdef OS2
  826. #ifdef PCFONTS
  827.     "font",          XYTFON, 0,
  828. #endif /* PCFONTS */
  829. #endif /* OS2 */
  830.     "height",        XYTHIG, 0,
  831. #ifdef OS2
  832.     "idle-send",     XYTIDLE,0,
  833. #ifndef NOCSETS
  834.     "kbd-follows-gl/gr", XYTKBDGL, 0,
  835. #endif /* NOCSETS */
  836.     "key",           XYTKEY, 0,
  837.     "keyboard-mode", XYTKBMOD, 0,
  838.     "keypad-mode",   XYTKPD, 0,
  839. #endif /* OS2 */
  840. #ifndef NOCSETS
  841. #ifdef OS2
  842.     "local-character-set", XYTLCS,  0,
  843. #else
  844.     "local-character-set", XYTLCS,  CM_INV,
  845. #endif /* OS2 */
  846. #endif /* NOCSETS */
  847.     "locking-shift", XYTSO,  0,
  848. #ifdef OS2
  849.     "margin-bell",   XYTMBEL, 0,
  850. #endif /* OS2 */
  851. #ifdef OS2MOUSE
  852.     "mouse",         XYTMOU, CM_INV,
  853. #endif /* OS2MOUSE */
  854.     "newline-mode",  XYTNL,  0,
  855. #ifdef OS2
  856.     "output-pacing", XYTPAC, 0,
  857. #ifdef PCTERM
  858.     "pcterm",        XYTPCTERM, 0,
  859. #endif /* PCTERM */
  860. #endif /* OS2 */
  861. #ifdef OS2ORUNIX
  862.     "print",         XYTPRN, 0,
  863. #endif /* OS2ORUNIX */
  864. #ifndef NOCSETS
  865. #ifdef OS2
  866.     "remote-character-set", XYTRCS,  0,
  867. #else
  868.     "remote-character-set", XYTRCS,  CM_INV,
  869. #endif /* OS2 */
  870. #endif /* NOCSETS */
  871. #ifdef OS2
  872.     "roll-mode",     XYTROL, 0,
  873.     "s",             XYTUPD, CM_ABR|CM_INV,
  874.     "sc",            XYTUPD, CM_ABR|CM_INV,
  875.     "scr",           XYTUPD, CM_ABR|CM_INV,
  876.     "scree",         XYTUPD, CM_ABR|CM_INV,
  877.     "screen",        XYTUPD, CM_ABR|CM_INV,
  878.     "screen-",       XYTUPD, CM_ABR|CM_INV,
  879.     "screen-mode",   XYTSCNM,   0,
  880.     "screen-optimize", XYTOPTI, 0,
  881.     "screen-update", XYTUPD, 0,
  882.     "scrollback",    XYSCRS, 0,
  883.     "send-data",     XYTSEND, 0,
  884.     "send-end-of-block", XYTSEOB, 0,
  885.     "sgr-colors",    XYTSGRC, 0,
  886.     "sni-ch.code",   XYTSNICC, 0,
  887.     "sni-firmware-versions", XYTSNIFV, 0,
  888.     "sni-language",  XYTVTLNG, 0,
  889.     "sni-pagemode",  XYTSNIPM, CM_INV,
  890.     "sni-scrollmode",XYTSNISM, CM_INV,
  891.     "spacing-attribute-character", XYTSAC, CM_INV,
  892.     "statusline",    XYTSTAT, 0,
  893.     "transmit-timeout", XYTCTS, 0,
  894. #endif /* OS2 */
  895. #ifdef CK_TRIGGER
  896.     "trigger",       XYTRIGGER, 0,
  897. #endif /* CK_TRIGGER */
  898. #ifdef OS2
  899.     "type",          XYTTYP, 0,
  900. #else
  901.     "type",          XYTTYP, CM_INV,
  902. #endif /* OS2 */
  903.  
  904. #ifndef NOCSETS
  905. #ifdef UNICODE
  906.     "unicode",       XYTUNI, CM_INV,
  907. #endif /* UNICODE */
  908. #endif /* NOCSETS */
  909. #ifdef OS2
  910.     "unix-mode",     XYTUNX, CM_INV,
  911. #ifdef NT
  912.     "video-change",  XYTVCH, 0,
  913. #endif /* NT */
  914.     "vt-language",   XYTVTLNG, 0,
  915.     "vt-nrc-mode",   XYTVTNRC, 0,
  916. #endif /* OS2 */
  917.     "width",         XYTWID, 0,
  918. #ifdef OS2
  919.     "wrap",          XYTWRP, 0,
  920. #endif /* OS2 */
  921.     "", 0, 0
  922. };
  923. int ntrm = (sizeof(trmtab) / sizeof(struct keytab)) - 1;
  924.  
  925. #ifdef OS2
  926. struct keytab termctrl[] = {     /* SET TERM CONTROLS */
  927.     "7",     7, 0,
  928.     "8",     8, 0
  929. };
  930. int ntermctrl = (sizeof(termctrl) / sizeof(struct keytab));
  931.  
  932. struct keytab rolltab[] = {   /* Set TERM Roll Options */
  933.     "insert",    TTR_INSERT, 0,
  934.     "off",       TTR_OVER,   CM_INV,
  935.     "on",        TTR_INSERT, CM_INV,
  936.     "overwrite", TTR_OVER,   0
  937. };
  938. int nroll = (sizeof(rolltab) / sizeof(struct keytab));
  939.  
  940. #define TT_GR_ALL 4
  941. #define TT_GR_G0  0
  942. #define TT_GR_G1  1
  943. #define TT_GR_G2  2
  944. #define TT_GR_G3  3
  945. #define TT_GR_KBD 4
  946. struct keytab graphsettab[] = {  /* DEC VT Graphic Sets */
  947.     "all",   TT_GR_ALL, 0,
  948.     "g0",    TT_GR_G0,  0,
  949.     "g1",    TT_GR_G1,  0,
  950.     "g2",    TT_GR_G2,  0,
  951.     "g3",    TT_GR_G3,  0,
  952.     "keyboard", TT_GR_KBD, 0,
  953.     "", 0, 0
  954. };
  955. int ngraphset = (sizeof(graphsettab) / sizeof(struct keytab)) - 1;
  956.  
  957. struct keytab adltab[] = {        /* Autodownload Options */
  958.     "kermit",         TAD_K,      0,
  959.     "off",        TAD_OFF,     0,
  960.     "on",        TAD_ON,        0,
  961.     "zmodem",         TAD_Z,      0
  962. };
  963. int nadltab = (sizeof(adltab) / sizeof(struct keytab));
  964.  
  965. struct keytab adlxtab[] = {        /* Autodownload Options */
  966.     "c0-conflicts",     TAD_X_C0,       0,
  967.     "detection-method", TAD_X_DETECT,     0,
  968.     "string",         TAD_X_STR,      0
  969. };
  970. int nadlxtab = (sizeof(adlxtab) / sizeof(struct keytab));
  971.  
  972. struct keytab adldtab[] = {        /* Auto-dl Detection Methods */
  973.     "packet",    ADL_PACK,    0,
  974.     "string",    ADL_STR,    0
  975. };
  976. int nadldtab = (sizeof(adldtab) / sizeof(struct keytab));
  977.  
  978. struct keytab adlc0tab[] = {        /* Auto-dl Detection Methods */
  979.     "ignored-by-emulator",    0,    0,
  980.     "processed-by-emulator",    1,    0
  981. };
  982. int nadlc0tab = (sizeof(adlc0tab) / sizeof(struct keytab));
  983.  
  984. struct keytab vtlangtab[] = {
  985.     "belgian",        VTL_BELGIAN , 0,
  986.     "british",        VTL_BRITISH , 0,
  987.     "canadian",       VTL_CANADIAN, 0,
  988.     "czech",          VTL_CZECH   , 0,
  989.     "danish",         VTL_DANISH  , 0,
  990.     "dutch",          VTL_DUTCH   , 0,
  991.     "finnish",        VTL_FINNISH , 0,
  992.     "french",         VTL_FRENCH  , 0,
  993.     "french-canadian",VTL_FR_CAN  , 0,
  994.     "german",         VTL_GERMAN  , 0,
  995.     "greek",          VTL_GREEK   , 0,
  996.     "hebrew",         VTL_HEBREW  , 0,
  997.     "hungarian",      VTL_HUNGARIA, 0,
  998.     "italian",        VTL_ITALIAN , 0,
  999.     "latin-american", VTL_LATIN_AM, 0,
  1000.     "north-american", VTL_NORTH_AM, 0,
  1001.     "norwegian",      VTL_NORWEGIA, 0,
  1002.     "polish",         VTL_POLISH  , 0,
  1003.     "portugese",      VTL_PORTUGES, 0,
  1004.     "romanian",       VTL_ROMANIAN, 0,
  1005.     "russian",        VTL_RUSSIAN , 0,
  1006.     "scs",            VTL_SCS     , CM_INV,
  1007.     "slovak",         VTL_SLOVAK  , 0,
  1008.     "spanish",        VTL_SPANISH , 0,
  1009.     "swedish",        VTL_SWEDISH , 0,
  1010.     "swiss-french",   VTL_SW_FR   , 0,
  1011.     "swiss-german",   VTL_SW_GR   , 0,
  1012.     "turkish-f",      VTL_TURK_F  , CM_INV,
  1013.     "turkish-q",      VTL_TURK_Q  , CM_INV
  1014. };
  1015. int nvtlangtab = (sizeof(vtlangtab) / sizeof(struct keytab));
  1016. #endif /* OS2 */
  1017.  
  1018. struct keytab crdtab[] = {        /* Carriage-return display */
  1019.     "crlf",        1, 0,
  1020.     "normal",      0, 0
  1021. };
  1022. extern int tt_crd;            /* Carriage-return display variable */
  1023.  
  1024. #ifdef CK_APC
  1025. extern int apcstatus, apcactive;
  1026. static struct keytab apctab[] = {    /* Terminal APC parameters */
  1027.     "off",     APC_OFF,  0,
  1028.     "on",     APC_ON,   0,
  1029.     "unchecked", APC_UNCH, 0
  1030. };
  1031. #endif /* CK_APC */
  1032. #endif /* NOLOCAL */
  1033.  
  1034. extern int autodl;
  1035.  
  1036. struct keytab beltab[] = {        /* Terminal bell mode */
  1037. #ifdef OS2
  1038.     "audible", XYB_AUD,  0,
  1039.     "none",    XYB_NONE, 0,
  1040. #else
  1041.     "audible", XYB_AUD,  CM_INV,
  1042.     "none",    XYB_NONE, CM_INV,
  1043. #endif /* OS2 */
  1044. #ifdef OS2
  1045.     "off",     XYB_NONE, CM_INV,
  1046.     "on",      XYB_AUD,  CM_INV,
  1047. #else
  1048.     "off",     XYB_NONE, 0,
  1049.     "on",      XYB_AUD,  0,
  1050. #endif /* OS2 */
  1051. #ifdef OS2
  1052.     "visible", XYB_VIS,  0,
  1053. #endif /* OS2 */
  1054.     "", 0, 0
  1055. };
  1056. int nbeltab = sizeof(beltab)/sizeof(struct keytab) - 1;
  1057.  
  1058. int tt_unicode = 1;            /* Use Unicode if possible */
  1059.  
  1060. #ifdef OS2
  1061. /*
  1062.   OS/2 serial communication devices.
  1063. */
  1064. struct keytab os2devtab[] = {
  1065.     "1",    1, CM_INV,            /* Invisible synonyms, like */
  1066.     "2",    2, CM_INV,            /* "set port 1" */
  1067.     "3",    3, CM_INV,
  1068.     "4",    4, CM_INV,
  1069.     "5",    5, CM_INV,
  1070.     "6",    6, CM_INV,
  1071.     "7",    7, CM_INV,
  1072.     "8",    8, CM_INV,
  1073.     "com1", 1, 0,            /* Real device names */
  1074.     "com2", 2, 0,
  1075.     "com3", 3, 0,
  1076.     "com4", 4, 0,
  1077.     "com5", 5, 0,
  1078.     "com6", 6, 0,
  1079.     "com7", 7, 0,
  1080.     "com8", 8, 0
  1081. #ifdef OS2ONLY
  1082.    ,"slipcom1", 1, 0,            /* For use with SLIP driver */
  1083.     "slipcom2", 2, 0,            /* shared access */
  1084.     "slipcom3", 3, 0,
  1085.     "slipcom4", 4, 0,
  1086.     "slipcom5", 5, 0,
  1087.     "slipcom6", 6, 0,
  1088.     "slipcom7", 7, 0,
  1089.     "slipcom8", 8, 0,
  1090.     "pppcom1", 1, 0,            /* For use with PPP driver */
  1091.     "pppcom2", 2, 0,            /* shared access */
  1092.     "pppcom3", 3, 0,
  1093.     "pppcom4", 4, 0,
  1094.     "pppcom5", 5, 0,
  1095.     "pppcom6", 6, 0,
  1096.     "pppcom7", 7, 0,
  1097.     "pppcom8", 8, 0
  1098. #endif /* OS2ONLY */
  1099. };
  1100. int nos2dev = (sizeof(os2devtab) / sizeof(struct keytab));
  1101.  
  1102. #ifdef OS2ONLY
  1103. struct keytab os2ppptab[] = {
  1104.     "0",    0, CM_INV,
  1105.     "1",    1, CM_INV,            /* Invisible synonyms, like */
  1106.     "2",    2, CM_INV,            /* "set port 1" */
  1107.     "3",    3, CM_INV,
  1108.     "4",    4, CM_INV,
  1109.     "5",    5, CM_INV,
  1110.     "6",    6, CM_INV,
  1111.     "7",    7, CM_INV,
  1112.     "8",    8, CM_INV,
  1113.     "9",    9, CM_INV,
  1114.     "ppp0", 0, 0,
  1115.     "ppp1", 1, 0,            /* For use with PPP driver */
  1116.     "ppp2", 2, 0,            /* shared access */
  1117.     "ppp3", 3, 0,
  1118.     "ppp4", 4, 0,
  1119.     "ppp5", 5, 0,
  1120.     "ppp6", 6, 0,
  1121.     "ppp7", 7, 0,
  1122.     "ppp8", 8, 0,
  1123.     "ppp9", 9, 0
  1124. };
  1125. int nos2ppp = (sizeof(os2ppptab) / sizeof(struct keytab));
  1126. #endif /* OS2ONLY */
  1127.  
  1128. /*
  1129.   Terminal parameters that can be set by SET commands.
  1130.   Used by the ck?con.c terminal emulator code.
  1131.   For now, only used for #ifdef OS2.  Should add these for Macintosh.
  1132. */
  1133. int tt_arrow = TTK_NORM;        /* Arrow key mode: normal (cursor) */
  1134. int tt_keypad = TTK_NORM;        /* Keypad mode: normal (numeric) */
  1135. int tt_shift_keypad = 0;             /* Keypad Shift mode: Off */
  1136. int tt_wrap = 1;            /* Terminal wrap, 1 = On */
  1137. int tt_type = TT_VT320;            /* Terminal type, initially VT320 */
  1138. int tt_type_mode = TT_VT320;        /* Terminal type set by host command */
  1139. int tt_cursor = 0;            /* Terminal cursor, 0 = Underline */
  1140. int tt_cursor_usr = 0;            /* Users Terminal cursor type */
  1141. int tt_cursorena_usr = 1;        /* Users Terminal cursor enabled */
  1142. int tt_answer = 0;            /* Terminal answerback (disabled) */
  1143. int tt_scrsize[VNUM] = {512,512,512,1};    /* Terminal scrollback buffer size */
  1144. int tt_roll[VNUM] = {1,1,1,1};        /* Terminal roll (on) */
  1145. int tt_pacing = 0;            /* Terminal output-pacing (none) */
  1146. int tt_inpacing = 0;            /* Terminal input-pacing (none) */
  1147. int tt_ctstmo = 15;            /* Terminal transmit-timeout */
  1148. int tt_codepage = -1;            /* Terminal code-page */
  1149. int tt_update = 100;            /* Terminal screen-update interval */
  1150. int tt_updmode = TTU_FAST;        /* Terminal screen-update mode FAST */
  1151. extern int updmode;
  1152. int tt_font = TTF_ROM;            /* Terminal screen font */
  1153. #ifndef KUI
  1154. int tt_status = 1;            /* Terminal status line displayed */
  1155. int tt_status_usr = 1;
  1156. #else  /* KUI */
  1157. #ifdef K95G
  1158. int tt_status = 1;            /* Terminal status line displayed */
  1159. int tt_status_usr = 1;
  1160. #else /* K95G */
  1161. int tt_status = 0;            /* Terminal status line displayed */
  1162. int tt_status_usr = 0;
  1163. #endif /* K95G */
  1164. #endif /* KUI */
  1165. int tt_senddata = 0;            /* Let host read terminal data */
  1166. extern int wy_blockend;            /* Terminal Send Data EOB type */
  1167. int tt_hidattr = 1;            /* Attributes are hidden */
  1168. int tt_idlesnd_tmo = 0;            /* Idle Send Timeout, disabled */
  1169. char * tt_idlesnd_str = NULL;        /* Idle Send String, none */
  1170.  
  1171. extern unsigned char colornormal, colorselect,
  1172. colorunderline, colorstatus, colorhelp, colorborder,
  1173. colorgraphic, colordebug, colorreverse;
  1174.  
  1175. extern int trueblink, trueunderline, truereverse;
  1176.  
  1177. extern int bgi, fgi;
  1178. extern int scrninitialized[];
  1179.  
  1180. struct keytab audibletab[] = {        /* Terminal Bell Audible mode */
  1181.     "beep",          XYB_BEEP, 0,    /* Values ORd with bell mode */
  1182.     "system-sounds", XYB_SYS, 0
  1183. };
  1184. int naudibletab = sizeof(audibletab)/sizeof(struct keytab);
  1185.  
  1186. struct keytab akmtab[] = {        /* Arrow key mode */
  1187.     "application", TTK_APPL, 0,
  1188.     "cursor",      TTK_NORM, 0
  1189. };
  1190. struct keytab kpmtab[] = {        /* Keypad mode */
  1191.     "application", TTK_APPL, 0,
  1192.     "numeric",     TTK_NORM, 0
  1193. };
  1194.  
  1195. struct keytab ttcolmodetab[] = {
  1196.     "current-color", 0, 0,
  1197.     "default-color",  1, 0
  1198. };
  1199. int ncolmode = sizeof(ttcolmodetab)/sizeof(struct keytab);
  1200.  
  1201. #define TTCOLNOR  0
  1202. #define TTCOLREV  1
  1203. #define TTCOLUND  2
  1204. #define TTCOLSTA  3
  1205. #define TTCOLHLP  4
  1206. #define TTCOLBOR  5
  1207. #define TTCOLSEL  6
  1208. #define TTCOLDEB  7
  1209. #define TTCOLGRP  8
  1210.  
  1211. #define TTCOLRES  10
  1212. #define TTCOLERA  11
  1213.  
  1214. struct keytab ttycoltab[] = {            /* Terminal Screen coloring */
  1215.     "border",             TTCOLBOR, 0,        /* Screen border color */
  1216.     "debug-terminal",     TTCOLDEB, 0,        /* Debug color */
  1217.     "erase",              TTCOLERA, 0,          /* Erase mode */
  1218.     "graphic",            TTCOLGRP, 0,          /* Graphic Color */
  1219.     "help-text",          TTCOLHLP, 0,        /* Help screens */
  1220.     "normal",             TTCOLNOR, CM_INV,    /* Normal screen text */
  1221.     "reset-on-esc[0m",    TTCOLRES, 0,          /* Reset on ESC [ 0 m */
  1222.     "reverse-video",      TTCOLREV, 0,          /* Reverse video */
  1223.     "status-line",        TTCOLSTA, 0,        /* Status line */
  1224.     "selection",          TTCOLSEL, 0,        /* Selection color */
  1225.     "terminal-screen",    TTCOLNOR, 0,        /* Better name than "normal" */
  1226.     "underlined-text",    TTCOLUND, 0        /* Underlined text */
  1227. };
  1228. int ncolors = (sizeof(ttycoltab) / sizeof(struct keytab));
  1229.  
  1230. #define TTATTNOR  0
  1231. #define TTATTBLI  1
  1232. #define TTATTREV  2
  1233. #define TTATTUND  3
  1234. #define TTATTPRO  4
  1235. #define TTATTBLD  5
  1236. #define TTATTDIM  6
  1237. #define TTATTINV  7
  1238. #define TTATTDONE 8
  1239.  
  1240. struct keytab ttyattrtab[] = {
  1241.     "blink",     TTATTBLI, 0,
  1242.     "protected",TTATTPRO, 0,
  1243.     "reverse",    TTATTREV, 0,
  1244.     "underline",TTATTUND, 0
  1245. };
  1246. int nattrib = (sizeof(ttyattrtab) / sizeof(struct keytab));
  1247.  
  1248. struct keytab ttyprotab[] = {
  1249.     "bold",        TTATTBLD, 0,
  1250.     "dim",       TTATTDIM, 0,
  1251.     "done",       TTATTDONE, CM_INV,
  1252.     "invisible",   TTATTINV, 0,
  1253.     "normal",       TTATTNOR, 0,
  1254.     "reverse",       TTATTREV, 0,
  1255.     "underlined",  TTATTUND, 0
  1256.  
  1257. };
  1258. int nprotect = (sizeof(ttyprotab) / sizeof(struct keytab));
  1259.  
  1260. struct keytab ttyseobtab[] = {
  1261.     "crlf_etx",     1, 0,
  1262.     "us_cr",     0, 0
  1263. };
  1264.  
  1265. struct keytab ttyclrtab[] = {        /* Colors */
  1266.     "black",       0, 0,
  1267.     "blue",        1, 0,
  1268.     "brown",       6, 0,
  1269.     "cyan",        3, 0,
  1270.     "darkgray",    8, CM_INV,
  1271.     "dgray",       8, 0,
  1272.     "green",       2, 0,
  1273.     "lblue",       9, CM_INV,
  1274.     "lcyan",      11, CM_INV,
  1275.     "lgray",       7, CM_INV,
  1276.     "lgreen",     10, CM_INV,
  1277.     "lightblue",   9, 0,
  1278.     "lightcyan",  11, 0,
  1279.     "lightgray",   7, 0,
  1280.     "lightgreen", 10, 0,
  1281.     "lightmagenta",13,0,
  1282.     "lightred",   12, 0,
  1283.     "lmagenta",   13, CM_INV,
  1284.     "lred",       12, CM_INV,
  1285.     "magenta",     5, 0,
  1286.     "red",         4, 0,
  1287.     "white",      15, 0,
  1288.     "yellow",     14, 0
  1289. };
  1290. int nclrs = (sizeof (ttyclrtab) / sizeof (struct keytab));
  1291.  
  1292. struct keytab ttycurtab[] = {
  1293.     "full",        TTC_BLOCK, 0,
  1294.     "half",        TTC_HALF,  0,
  1295.     "underline",   TTC_ULINE, 0
  1296. };
  1297. int ncursors = 3;
  1298.  
  1299. struct keytab ttyptab[] = {
  1300.     "aixterm",  TT_AIXTERM, 0,          /* IBM AIXterm */
  1301.     "ansi-bbs", TT_ANSI,    0,        /* ANSI.SYS (BBS) */
  1302.     "at386",    TT_AT386,   0,        /* Unixware ANSI */
  1303.     "avatar/0+",TT_ANSI,    0,          /* AVATAR/0+ */
  1304.     "ba80",     TT_BA80,    0,          /* Nixdorf BA80 */
  1305.     "be",       TT_BEOS,    CM_INV|CM_ABR,
  1306.     "beos-ansi",TT_BEOS,    CM_INV,     /* BeOS ANSI */
  1307.     "beterm",   TT_BEOS,    0,          /* BeOS Terminal (as of PR2 ) */
  1308.     "d200",     TT_DG200,   CM_INV|CM_ABR, /* Data General DASHER 200 */
  1309.     "d210",     TT_DG210,   CM_INV|CM_ABR, /* Data General DASHER 210 */
  1310.     "d217",     TT_DG217,   CM_INV|CM_ABR, /* Data General DASHER 217 */
  1311.     "dg200",    TT_DG200,   0,        /* Data General DASHER 200 */
  1312.     "dg210",    TT_DG210,   0,          /* Data General DASHER 210 */
  1313.     "dg217",    TT_DG217,   0,          /* Data General DASHER 217 */
  1314.     "h1500",    TT_HZL1500, CM_INV,        /* Hazeltine 1500 */
  1315.     "h19",      TT_H19,     CM_INV,    /* Heath-19 */
  1316.     "heath19",  TT_H19,     0,        /* Heath-19 */
  1317.     "hft",      TT_HFT,     0,          /* IBM High Function Terminal */
  1318.     "hp2621a",  TT_HP2621,  0,        /* HP 2621A */
  1319.     "hpterm",   TT_HPTERM,  0,        /* HP TERM */
  1320.     "hz1500",   TT_HZL1500, 0,        /* Hazeltine 1500 */
  1321.     "ibm3151",  TT_IBM31,   CM_INV,    /* IBM 3101-xx,3161 */
  1322.     "linux",    TT_LINUX,   0,          /* Linux */
  1323.     "qansi",    TT_QANSI,   0,        /* QNX ANSI */
  1324.     "qnx",      TT_QNX,     0,        /* QNX Console */
  1325.     "scoansi",  TT_SCOANSI, 0,        /* SCO ANSI */
  1326.     "sni-97801",TT_97801, 0,        /* SNI 97801 */
  1327. /*
  1328.   The idea of NONE is to let the console driver handle the escape sequences,
  1329.   which, in theory at least, would give not only ANSI emulation, but also any
  1330.   other kind of emulation that might be provided by alternative console
  1331.   drivers, if any existed.
  1332.  
  1333.   For this to work, ckocon.c would need to be modified to make higher-level
  1334.   calls, like VioWrtTTY(), DosWrite(), or (simply) write(), rather than
  1335.   VioWrt*Cell() and similar, and it would also have to give up its rollback
  1336.   feature, and its status line and help screens would also have to be
  1337.   forgotten or else done in an ANSI way.
  1338.  
  1339.   As matters stand, we already have perfectly good ANSI emulation built in,
  1340.   and there are no alternative console drivers available, so there is no point
  1341.   in having a terminal type of NONE, so it is commented out.  However, should
  1342.   you uncomment it, it will work like a "glass tty" -- no escape sequence
  1343.   interpretation at all; somewhat similar to debug mode, except without the
  1344.   debugging (no highlighting of control chars or escape sequences); help
  1345.   screens, status line, and rollback will still work.
  1346. */
  1347. #ifdef OS2PM
  1348. #ifdef COMMENT
  1349.     "tek4014", TT_TEK40, 0,
  1350. #endif /* COMMENT */
  1351. #endif /* OS2PM */
  1352.     "tty",     TT_NONE,  0,
  1353.     "tvi910+", TT_TVI910, 0,
  1354.     "tvi925",  TT_TVI925, 0,
  1355.     "tvi950",  TT_TVI950, 0,
  1356.     "vc404",   TT_VC4404, 0,
  1357.     "vc4404",  TT_VC4404, CM_INV,
  1358.     "vip7809", TT_VIP7809, 0,
  1359.     "vt100",   TT_VT100, 0,
  1360.     "vt102",   TT_VT102, 0,
  1361.     "vt220",   TT_VT220, 0,
  1362.     "vt220pc", TT_VT220PC, 0,
  1363.     "vt320",   TT_VT320, 0,
  1364.     "vt320pc", TT_VT320PC, 0,
  1365.     "vt52",    TT_VT52,  0,
  1366. #ifdef NT
  1367.     "vtnt",    TT_VTNT,  0,
  1368. #else /* NT */
  1369.     "vtnt",    TT_VTNT,  CM_INV,
  1370. #endif /* NT */
  1371.     "wy160",   TT_WY160, 0,
  1372.     "wy30",    TT_WY30,  0,
  1373.     "wy370",   TT_WY370, 0,
  1374.     "wy50",    TT_WY50,  0,
  1375.     "wy60",    TT_WY60,  0,
  1376.     "wyse30",  TT_WY30,  CM_INV,
  1377.     "wyse370", TT_WY370, CM_INV,
  1378.     "wyse50",  TT_WY50,  CM_INV,
  1379.     "wyse60",  TT_WY60,  CM_INV
  1380. };
  1381. int nttyp = (sizeof(ttyptab) / sizeof(struct keytab));
  1382.  
  1383. struct keytab ttkeytab[] = {
  1384.     "aixterm",  TT_AIXTERM, 0,          /* IBM AIXterm */
  1385.     "ansi-bbs",  TT_ANSI,    0,        /* ANSI.SYS (BBS) */
  1386.     "at386",     TT_AT386,   0,        /* Unixware ANSI */
  1387.     "avatar/0+", TT_ANSI,    0,         /* AVATAR/0+ */
  1388.     "ba80",      TT_BA80,    0,         /* Nixdorf BA80 */
  1389.     "be",        TT_BEOS,    CM_INV|CM_ABR,
  1390.     "beos-ansi", TT_BEOS,    CM_INV,    /* BeOS ANSI */
  1391.     "beterm",    TT_BEOS,    0,         /* BeOS Terminal (as of PR2) */
  1392.     "d200",      TT_DG200,   CM_INV|CM_ABR, /* Data General DASHER 200 */
  1393.     "d210",      TT_DG210,   CM_INV|CM_ABR, /* Data General DASHER 210 */
  1394.     "d217",      TT_DG217,   CM_INV|CM_ABR, /* Data General DASHER 217 */
  1395.     "dg200",     TT_DG200,   0,        /* Data General DASHER 200 */
  1396.     "dg210",     TT_DG210,   0,        /* Data General DASHER 210 */
  1397.     "dg217",     TT_DG217,   0,        /* Data General DASHER 217 */
  1398.     "emacs",     TT_KBM_EMACS,   0,     /* Emacs mode */
  1399.     "h19",       TT_H19,     CM_INV,    /* Heath-19 */
  1400.     "heath19",   TT_H19,     0,        /* Heath-19 */
  1401.     "hebrew",    TT_KBM_HEBREW,   0,    /* Hebrew mode */
  1402.     "hft",       TT_HFT,     0,         /* IBM High Function Terminal */
  1403.     "hp2621a",   TT_HP2621,  0,        /* HP 2621A */
  1404.     "hpterm",    TT_HPTERM,  0,        /* HP TERM */
  1405.     "hz1500",    TT_HZL1500, 0,        /* Hazeltine 1500 */
  1406.     "ibm3151",   TT_IBM31,   CM_INV,    /* IBM 3101-xx,3161 */
  1407.     "linux",     TT_LINUX,   0,         /* Linux */
  1408.     "qansi",     TT_QANSI,         0,   /* QNX ANSI */
  1409.     "qnx",       TT_QNX,           0,   /* QNX */
  1410.     "russian",   TT_KBM_RUSSIAN,   0,   /* Russian mode */
  1411.     "scoansi",   TT_SCOANSI, 0,        /* SCO ANSI */
  1412.     "sni-97801", TT_97801, 0,           /* SNI 97801 */
  1413. #ifdef OS2PM
  1414. #ifdef COMMENT
  1415.     "tek4014", TT_TEK40, 0,
  1416. #endif /* COMMENT */
  1417. #endif /* OS2PM */
  1418.     "tty",     TT_NONE,  0,
  1419.     "tvi910+", TT_TVI910, 0,
  1420.     "tvi925",  TT_TVI925, 0,
  1421.     "tvi950",  TT_TVI950, 0,
  1422.     "vc404",   TT_VC4404, 0,
  1423.     "vc4404",  TT_VC4404, CM_INV,
  1424.     "vip7809", TT_VIP7809, 0,
  1425.     "vt100",   TT_VT100, 0,
  1426.     "vt102",   TT_VT102, 0,
  1427.     "vt220",   TT_VT220, 0,
  1428.     "vt220pc", TT_VT220PC, 0,
  1429.     "vt320",   TT_VT320, 0,
  1430.     "vt320pc", TT_VT320PC, 0,
  1431.     "vt52",    TT_VT52,  0,
  1432.     "vtnt",    TT_VTNT,  CM_INV,
  1433.     "wp",      TT_KBM_WP,   0,        /* Word Perfect mode */
  1434.     "wy160",   TT_WY160,  0,
  1435.     "wy30",    TT_WY30,  0,
  1436.     "wy370",   TT_WY370, 0,
  1437.     "wy50",    TT_WY50,  0,
  1438.     "wy60",    TT_WY60,  0,
  1439.     "wyse30",  TT_WY30,  CM_INV,
  1440.     "wyse370", TT_WY370, CM_INV,
  1441.     "wyse50",  TT_WY50,  CM_INV,
  1442.     "wyse60",  TT_WY60,  CM_INV
  1443. };
  1444. int nttkey = (sizeof(ttkeytab) / sizeof(struct keytab));
  1445.  
  1446. struct keytab kbmodtab[] = {
  1447.     "normal",  KBM_EN, 0,
  1448.     "none",    KBM_EN, CM_INV,
  1449.     "emacs",   KBM_EM, 0,
  1450.     "english", KBM_EN, CM_INV,
  1451.     "hebrew",  KBM_HE, 0,
  1452.     "russian", KBM_RU, 0,
  1453.     "wp",      KBM_WP, 0
  1454. };
  1455. int nkbmodtab = (sizeof(kbmodtab) / sizeof(struct keytab));
  1456.  
  1457. struct keytab prtytab[] = { /* OS/2 Priority Levels */
  1458.     "foreground-server", XYP_SRV, 0,
  1459.     "idle",              XYP_IDLE, CM_INV,
  1460.     "regular",           XYP_REG, 0,
  1461.     "time-critical",     XYP_RTP, 0
  1462. };
  1463. int nprty = (sizeof(prtytab) / sizeof(struct keytab));
  1464. #endif /* OS2 */
  1465.  
  1466. #ifdef NT
  1467. struct keytab win95tab[] = { /* Win95 work-arounds */
  1468.     "8.3-filenames",         XYW8_3, 0,
  1469.     "alt-gr",              XYWAGR, 0,
  1470.     "keyboard-translation",  XYWKEY, 0,
  1471.     "lucida-substitutions",  XYWLUC, 0,
  1472.     "overlapped-io",         XYWOIO, 0,
  1473.     "popups",                XYWPOPUP, 0,
  1474.     "select-bug",            XYWSELECT, 0
  1475. };
  1476. int nwin95 = (sizeof(win95tab) / sizeof(struct keytab));
  1477. #endif /* NT */
  1478.  
  1479. #ifdef OS2MOUSE
  1480. extern int wideresult;
  1481. int tt_mouse = 1;            /* Terminal mouse on/off */
  1482.  
  1483. struct keytab mousetab[] = {        /* Mouse items */
  1484.     "activate", XYM_ON,    0,
  1485.     "button",   XYM_BUTTON, 0,
  1486.     "clear",    XYM_CLEAR, 0
  1487. };
  1488. int nmtab = (sizeof(mousetab)/sizeof(struct keytab));
  1489.  
  1490. struct keytab mousebuttontab[] = {    /* event button */
  1491.     "one",           XYM_B1, CM_INV,
  1492.     "three",         XYM_B3, CM_INV,
  1493.     "two",           XYM_B2, CM_INV,
  1494.     "1",             XYM_B1, 0,
  1495.     "2",             XYM_B2, 0,
  1496.     "3",             XYM_B3, 0
  1497. };
  1498. int nmbtab = (sizeof(mousebuttontab) / sizeof(struct keytab));
  1499.  
  1500. struct keytab mousemodtab[] = {        /* event button key modifier */
  1501.     "alt",        XYM_ALT,   0,
  1502.     "alt-shift",    XYM_SHIFT|XYM_ALT, 0,
  1503.     "ctrl",        XYM_CTRL,  0,
  1504.     "ctrl-alt",        XYM_CTRL|XYM_ALT, 0,
  1505.     "ctrl-alt-shift",    XYM_CTRL|XYM_SHIFT|XYM_ALT, 0,
  1506.     "ctrl-shift",    XYM_CTRL|XYM_SHIFT, 0,
  1507.     "none",          0, 0,
  1508.     "shift",        XYM_SHIFT, 0
  1509. };
  1510. int nmmtab = (sizeof(mousemodtab) / sizeof(struct keytab));
  1511.  
  1512. struct keytab mclicktab[] = {        /* event button click modifier */
  1513.     "click",        XYM_C1,  0,
  1514.     "drag",         XYM_DRAG, 0,
  1515.     "double-click", XYM_C2,  0
  1516. };
  1517. int nmctab = (sizeof(mclicktab) / sizeof(struct keytab));
  1518.  
  1519. #ifndef NOKVERBS
  1520. extern int nkverbs;
  1521. extern struct keytab kverbs[];
  1522. #endif /* NOKVERBS */
  1523. #endif /* OS2MOUSE */
  1524.  
  1525. /* #ifdef VMS */
  1526. struct keytab fbtab[] = {        /* Binary record types for VMS */
  1527.     "fixed",     XYFT_B, 0,        /* Fixed is normal for binary */
  1528.     "undefined", XYFT_U, 0        /* Undefined if they ask for it */
  1529. };
  1530. int nfbtyp = (sizeof(fbtab) / sizeof(struct keytab));
  1531. /* #endif */
  1532.  
  1533. #ifdef VMS
  1534. struct keytab lbltab[] = {        /* Labeled File info */
  1535.     "acl",         LBL_ACL, 0,
  1536.     "backup-date", LBL_BCK, 0,
  1537.     "name",        LBL_NAM, 0,
  1538.     "owner",       LBL_OWN, 0,
  1539.     "path",        LBL_PTH, 0
  1540. };
  1541. int nlblp = (sizeof(lbltab) / sizeof(struct keytab));
  1542. #else
  1543. #ifdef OS2
  1544. struct keytab lbltab[] = {        /* Labeled File info */
  1545.     "archive",   LBL_ARC, 0,
  1546.     "extended",  LBL_EXT, 0,
  1547.     "hidden",    LBL_HID, 0,
  1548.     "read-only", LBL_RO,  0,
  1549.     "system",    LBL_SYS, 0
  1550. };
  1551. int nlblp = (sizeof(lbltab) / sizeof(struct keytab));
  1552. #endif /* OS2 */
  1553. #endif /* VMS */
  1554.  
  1555. #ifdef CK_CURSES
  1556. #ifdef CK_PCT_BAR
  1557. static struct keytab fdftab[] = {    /* SET FILE DISPLAY FULL options */
  1558.     "thermometer", 1, 0,
  1559.     "no-thermometer", 0, 0
  1560. };
  1561. extern int thermometer;
  1562. #endif /* CK_PCT_BAR */
  1563. #endif /* CK_CURSES */
  1564.  
  1565. static struct keytab fdtab[] = {    /* SET FILE DISPLAY options */
  1566. #ifdef MAC                /* Macintosh */
  1567.     "fullscreen", XYFD_R, 0,        /* Full-screen but not curses */
  1568.     "none",   XYFD_N, 0,
  1569.     "off",    XYFD_N, CM_INV,
  1570.     "on",     XYFD_R, CM_INV,
  1571.     "quiet",  XYFD_N, CM_INV
  1572.  
  1573. #else                    /* Not Mac */
  1574.     "brief", XYFD_B, 0,            /* Brief */
  1575.     "crt", XYFD_S, 0,            /* CRT display */
  1576. #ifdef CK_CURSES
  1577. #ifdef COMMENT
  1578.     "curses",     XYFD_C, CM_INV,    /* Full-screen, curses */
  1579. #endif /* COMMENT */
  1580.     "fullscreen", XYFD_C, 0,        /* Full-screen, whatever the method */
  1581. #endif /* CK_CURSES */
  1582.     "none",   XYFD_N, 0,        /* No display */
  1583.     "off",    XYFD_N, CM_INV,        /* Ditto */
  1584.     "on",     XYFD_R, CM_INV,        /* On = Serial */
  1585.     "quiet",  XYFD_N, CM_INV,        /* No display */
  1586.     "serial", XYFD_R, 0            /* Serial */
  1587. #endif /* MAC */
  1588. };
  1589. int nfdtab = (sizeof(fdtab) / sizeof(struct keytab));
  1590.  
  1591. struct keytab rsrtab[] = {        /* For REMOTE SET RECEIVE */
  1592.     "packet-length", XYLEN, 0,
  1593.     "timeout", XYTIMO, 0
  1594. };
  1595. int nrsrtab = (sizeof(rsrtab) / sizeof(struct keytab));
  1596.  
  1597. /* Send/Receive Parameters */
  1598.  
  1599. struct keytab srtab[] = {
  1600.     "backup", XYBUP, 0,
  1601. #ifndef NOCSETS
  1602.     "character-set-selection", XYCSET, 0,
  1603. #endif /* NOCSETS */
  1604.     "control-prefix", XYQCTL, 0,
  1605. #ifdef CKXXCHAR
  1606.     "double-character", XYDBL, 0,
  1607. #endif /* CKXXCHAR */
  1608.     "end-of-packet", XYEOL, 0,
  1609. #ifdef PIPESEND
  1610.     "filter", XYFLTR, 0,
  1611. #endif /* PIPESEND */
  1612. #ifdef CKXXCHAR
  1613.     "ignore-character", XYIGN, 0,
  1614. #endif /* CKXXCHAR */
  1615.     "move-to", XYMOVE, 0,
  1616.     "negotiation-string-max-length", XYINIL, CM_INV,
  1617.     "packet-length", XYLEN, 0,
  1618.     "pad-character", XYPADC, 0,
  1619.     "padding", XYNPAD, 0,
  1620.     "pathnames", XYFPATH, 0,
  1621.     "pause", XYPAUS, 0,
  1622.     "quote", XYQCTL, CM_INV,        /* = CONTROL-PREFIX */
  1623.     "rename-to", XYRENAME, 0,
  1624.     "start-of-packet", XYMARK, 0,
  1625.     "timeout", XYTIMO, 0,
  1626. #ifdef VMS
  1627.     "version-numbers", 887, 0,        /* VMS version numbers */
  1628. #endif /* VMS */
  1629.     "", 0, 0
  1630. };
  1631. int nsrtab = (sizeof(srtab) / sizeof(struct keytab)) - 1;
  1632.  
  1633. #ifdef UNICODE
  1634. #define UCS_BOM 1
  1635. #define UCS_BYT 2
  1636. static struct keytab ucstab[] = {
  1637.     "bom",        UCS_BOM, 0,
  1638.     "byte-order", UCS_BYT, 0,
  1639.     "", 0, 0
  1640. };
  1641. int nucstab = (sizeof(ucstab) / sizeof(struct keytab)) - 1;
  1642.  
  1643. static struct keytab botab[] = {
  1644.     "big-endian", 0, 0,
  1645.     "little-endian", 1, 0
  1646. };
  1647. static int nbotab = 2;
  1648. #endif /* UNICODE */
  1649.  
  1650. /* REMOTE SET */
  1651.  
  1652. struct keytab rmstab[] = {
  1653.     "attributes",  XYATTR, 0,
  1654.     "block-check", XYCHKT, 0,
  1655.     "file",        XYFILE, 0,
  1656.     "incomplete",  XYIFD,  CM_INV, /* REMOTE SET FILE INCOMPLETE preferred */
  1657.     "receive",     XYRECV, 0,
  1658.     "retry",       XYRETR, 0,
  1659.     "server",      XYSERV, 0,
  1660.     "transfer",    XYXFER, 0,
  1661.     "window",      XYWIND, 0,
  1662.     "xfer",        XYXFER, CM_INV
  1663. };
  1664. int nrms = (sizeof(rmstab) / sizeof(struct keytab));
  1665.  
  1666. struct keytab attrtab[] = {
  1667. #ifdef STRATUS
  1668.     "account",         AT_ACCT, 0,
  1669. #endif /* STRATUS */
  1670.     "all",           AT_XALL, 0,
  1671. #ifdef COMMENT
  1672.     "blocksize",     AT_BLKS, 0,    /* (not used) */
  1673. #endif /* COMMENT */
  1674. #ifndef NOCSETS
  1675.     "character-set", AT_ENCO, 0,
  1676. #endif /* NOCSETS */
  1677. #ifdef STRATUS
  1678.     "creator",         AT_CREA, 0,
  1679. #endif /* STRATUS */
  1680.     "date",          AT_DATE, 0,
  1681.     "disposition",   AT_DISP, 0,
  1682.     "encoding",      AT_ENCO, CM_INV,
  1683. #ifdef STRATUS
  1684.     "format",         AT_RECF, 0,
  1685. #endif /* STRATUS */
  1686.     "length",        AT_LENK, 0,
  1687.     "off",           AT_ALLN, 0,
  1688.     "on",            AT_ALLY, 0,
  1689. #ifdef COMMENT
  1690.     "os-specific",   AT_SYSP, 0,    /* (not used by UNIX or VMS) */
  1691. #endif /* COMMENT */
  1692. #ifdef CK_PERMS
  1693.     "protection",    AT_LPRO, 0,
  1694.     "permissions",   AT_LPRO, CM_INV,
  1695. #endif /* CK_PERMS */
  1696.     "system-id",     AT_SYSI, 0,
  1697.     "type",          AT_FTYP, 0
  1698. };
  1699. int natr = (sizeof(attrtab) / sizeof(struct keytab)); /* how many attributes */
  1700.  
  1701. #ifndef NOSPL
  1702. extern int indef, inecho, insilence, inbufsize, inautodl, inintr;
  1703. extern char * inpbuf, * inpbp;
  1704. #ifdef OS2
  1705. extern int interm;
  1706. #endif /* OS2 */
  1707. struct keytab inptab[] = {        /* SET INPUT parameters */
  1708. #ifdef CK_AUTODL
  1709.     "autodownload",    IN_ADL, 0,
  1710. #endif /* CK_AUTODL */
  1711.     "buffer-length",   IN_BUF, 0,
  1712.     "cancellation",    IN_CAN, 0,
  1713.     "case",            IN_CAS, 0,
  1714.     "default-timeout", IN_DEF, CM_INV,    /* There is no default timeout */
  1715.     "echo",            IN_ECH, 0,
  1716. #ifdef OS2
  1717.     "pacing",          IN_PAC, CM_INV,
  1718. #endif /* OS2 */
  1719.     "silence",         IN_SIL, 0,
  1720. #ifdef OS2
  1721.     "terminal",           IN_TRM, 0,
  1722. #endif /* OS2 */
  1723.     "timeout-action",  IN_TIM, 0
  1724. };
  1725. int ninp = (sizeof(inptab) / sizeof(struct keytab));
  1726.  
  1727. struct keytab intimt[] = {        /* SET INPUT TIMEOUT parameters */
  1728.     "proceed", 0, 0,            /* 0 = proceed */
  1729.     "quit",    1, 0            /* 1 = quit */
  1730. };
  1731.  
  1732. struct keytab incast[] = {        /* SET INPUT CASE parameters */
  1733.     "ignore",  0, 0,            /* 0 = ignore */
  1734.     "observe", 1, 0            /* 1 = observe */
  1735. };
  1736. #endif /* NOSPL */
  1737.  
  1738. struct keytab nabltab[] = {        /* For any command that needs */
  1739.     "disabled", 0, 0,
  1740.     "enabled",  1, 0,
  1741.     "off",      0, CM_INV,        /* these keywords... */
  1742.     "on",       1, CM_INV
  1743. };
  1744. int nnabltab = sizeof(nabltab) / sizeof(struct keytab);
  1745.  
  1746. #ifdef OS2
  1747. struct keytab tvctab[] = {        /* SET TERM VIDEO-CHANGE */
  1748.     "disabled",   TVC_DIS, 0,
  1749.     "enabled",    TVC_ENA, 0
  1750. #ifdef NT
  1751.     ,"win95-safe", TVC_W95, 0
  1752. #endif /* NT */
  1753. };
  1754. int ntvctab = sizeof(tvctab) / sizeof(struct keytab);
  1755.  
  1756. struct keytab msktab[] = { /* SET MS-DOS KERMIT compatibilities */
  1757. #ifdef COMMENT
  1758.     "color", MSK_COLOR,  0,
  1759. #endif /* COMMENT */
  1760.     "keycodes", MSK_KEYS, 0
  1761. };
  1762. int nmsk = (sizeof(msktab) / sizeof(struct keytab));
  1763.  
  1764. struct keytab scrnupd[] = {        /* SET TERMINAL SCREEN-UPDATE */
  1765.     "fast", TTU_FAST,  0,
  1766.     "smooth", TTU_SMOOTH, 0
  1767. };
  1768. int nscrnupd = (sizeof(scrnupd) / sizeof(struct keytab));
  1769.  
  1770. struct keytab termfont[] = {        /* SET TERMINAL FONT */
  1771. #ifdef COMMENT
  1772.     "cp111", TTF_111, 0,
  1773.     "cp112", TTF_112, 0,
  1774.     "cp113", TTF_113, 0,
  1775. #endif /* COMMENT */
  1776.     "cp437", TTF_437, 0,
  1777.     "cp850", TTF_850, 0,
  1778. #ifdef COMMENT
  1779.     "cp851", TTF_851, 0,
  1780. #endif /* COMMENT */
  1781.     "cp852", TTF_852, 0,
  1782. #ifdef COMMENT
  1783.     "cp853", TTF_853, 0,
  1784.     "cp860", TTF_860, 0,
  1785.     "cp861", TTF_861, 0,
  1786. #endif /* COMMENT */
  1787.     "cp862", TTF_862, 0,
  1788. #ifdef COMMENT
  1789.     "cp863", TTF_863, 0,
  1790.     "cp864", TTF_864, 0,
  1791.     "cp865", TTF_865, 0,
  1792. #endif /* COMMENT */
  1793.     "cp866", TTF_866, 0,
  1794. #ifdef COMMENT
  1795.     "cp880", TTF_880, 0,
  1796.     "cp881", TTF_881, 0,
  1797.     "cp882", TTF_882, 0,
  1798.     "cp883", TTF_883, 0,
  1799.     "cp884", TTF_884, 0,
  1800.     "cp885", TTF_885, 0,
  1801. #endif /* COMMENT */
  1802.     "default", TTF_ROM, 0
  1803. };
  1804. int ntermfont = (sizeof(termfont) / sizeof(struct keytab));
  1805.  
  1806. struct keytab anbktab[] = {        /* For any command that needs */
  1807.     "message", 2, 0,            /* these keywords... */
  1808.     "off",     0, 0,
  1809.     "on",      1, 0,
  1810.     "unsafe-messag0", 99, CM_INV,
  1811.     "unsafe-message", 3,  CM_INV
  1812. };
  1813. int nansbk = (sizeof(anbktab) / sizeof(struct keytab));
  1814.  
  1815. int win95_popup = 1;
  1816. #ifdef NT
  1817. int win95altgr  = 0;
  1818. #ifdef KUI
  1819. int win95lucida = 0;
  1820. #else /* KUI */
  1821. int win95lucida = 1;
  1822. #endif /* KUI */
  1823. extern int win95selectbug;
  1824. extern int win95_8_3;
  1825.  
  1826. #ifdef COMMENT
  1827. extern CHAR (*xlr[MAXTCSETS+1][MAXFCSETS+1])(CHAR);
  1828. extern struct keytab tcstab[];
  1829. extern int ntcs;
  1830. #endif /* COMMENT */
  1831. extern int maxow, maxow_usr; owwait;    /* Overlapped I/O variables */
  1832. #endif /* NT */
  1833. #endif /* OS2 */
  1834.  
  1835.  
  1836. /* The following routines broken out of doprm() to give compilers a break. */
  1837.  
  1838. /*  S E T O N  --  Parse on/off (default on), set parameter to result  */
  1839.  
  1840. int
  1841. seton(prm) int *prm; {
  1842.     int x, y;
  1843.     if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  1844.     if ((x = cmcfm()) < 0) return(x);
  1845.     *prm = y;
  1846.     return(1);
  1847. }
  1848.  
  1849. /*  S E T O N A U T O --  Parse on/off/auto (default auto) & set result */
  1850.  
  1851. struct keytab onoffaut[] = {
  1852.     "auto", SET_AUTO, 0,        /* 2 */
  1853.     "off",  SET_OFF,  0,        /* 0 */
  1854.     "on",   SET_ON,   0            /* 1 */
  1855. };
  1856.  
  1857. int
  1858. setonaut(prm) int *prm; {
  1859.     int x, y;
  1860.     if ((y = cmkey(onoffaut,3,"","auto",xxstring)) < 0) return(y);
  1861.     if ((x = cmcfm()) < 0) return(x);
  1862.     *prm = y;
  1863.     return(1);
  1864. }
  1865.  
  1866. /*  S E T N U M  --  Set parameter to result of cmnum() parse.  */
  1867. /*
  1868.  Call with pointer to integer variable to be set,
  1869.    x = number from cnum parse, y = return code from cmnum,
  1870.    max = maximum value to accept, -1 if no maximum.
  1871.  Returns -9 on failure, after printing a message, or 1 on success.
  1872. */
  1873. int
  1874. setnum(prm,x,y,max) int x, y, *prm, max; {
  1875.     debug(F101,"setnum","",y);
  1876.     if (y == -3) {
  1877.     printf("\n?Value required\n");
  1878.     return(-9);
  1879.     }
  1880.     if (y == -2) {
  1881.     printf("%s?Not a number: %s\n",cmflgs == 1 ? "" : "\n", atxbuf);
  1882.     return(-9);
  1883.     }
  1884.     if (y < 0) return(y);
  1885.     if (max > -1 && x > max) {
  1886.     printf("?Sorry, %d is the maximum\n",max);
  1887.     return(-9);
  1888.     }
  1889.     if ((y = cmcfm()) < 0) return(y);
  1890.     *prm = x;
  1891.     return(1);
  1892. }
  1893.  
  1894. /*  S E T C C  --  Set parameter var to an ASCII control character value.  */
  1895. /*
  1896.   Parses a number, or a literal control character, or a caret (^) followed
  1897.   by an ASCII character whose value is 63-95 or 97-122, then gets confirmation,
  1898.   then sets the parameter to the code value of the character given.  If there
  1899.   are any parse errors, they are returned, otherwise on success 1 is returned.
  1900. */
  1901. int
  1902. setcc(dflt,var) char *dflt; int *var; {
  1903.     int x, y;
  1904.     unsigned int c;
  1905.     char *hlpmsg = "Control character,\n\
  1906.  numeric ASCII value,\n\
  1907.  or in ^X notation,\n\
  1908.  or preceded by a backslash and entered literally";
  1909.  
  1910.     /* This is a hack to turn off complaints from expression evaluator. */
  1911.     x_ifnum = 1;
  1912.     y = cmnum(hlpmsg, dflt, 10, &x, xxstring); /* Parse a number */
  1913.     x_ifnum = 0;                   /* Allow complaints again */
  1914.     if (y < 0) {            /* Parse failed */
  1915.     if (y != -2)            /* Reparse needed or somesuch */
  1916.       return(y);            /* Pass failure back up the chain */
  1917.     }
  1918.     /* Did they type a real control character? */
  1919.  
  1920.     for (c = strlen(atmbuf) - 1; c > 0; c--) /* Trim */
  1921.       if (atmbuf[c] == SP) atmbuf[c] = NUL;
  1922.  
  1923.     if (y < 0) {            /* It was not a number */
  1924.     if ((c = atmbuf[0]) && !atmbuf[1]) { /* Was it a literal Ctrl char? */
  1925.         if ((c > 037) && (c != 0177)) {
  1926.         printf("\n?Not a control character - %d\n",c);
  1927.         return(-9);
  1928.         } else {
  1929.         if ((y = cmcfm()) < 0)    /* Confirm */
  1930.           return(y);
  1931.         *var = c;        /* Set the variable */
  1932.         return(1);
  1933.         }
  1934.     } else if (atmbuf[0] == '^' && !atmbuf[2]) { /* Or ^X notation? */
  1935.         c = atmbuf[1];
  1936.         if (islower((char) c))    /* Uppercase lowercase letters */
  1937.           c = toupper(c);
  1938.         if (c > 62 && c < 96) {    /* Check range */
  1939.         if ((y = cmcfm()) < 0)
  1940.           return(y);
  1941.         *var = ctl(c);        /* OK */
  1942.         return(1);
  1943.         } else {
  1944.         printf("?Not a control character - %s\n", atmbuf);
  1945.         return(-9);
  1946.         }
  1947.     } else {            /* Something illegal was typed */
  1948.         printf("?Invalid - %s\n", atmbuf);
  1949.         return(-9);
  1950.     }
  1951.     }
  1952.     if ((x > 037) && (x != 0177)) {    /* They typed a number */
  1953.     printf("\n?Not in ASCII control range - %d\n",x);
  1954.     return(-9);
  1955.     }
  1956.     if ((y = cmcfm()) < 0)        /* In range, confirm */
  1957.       return(y);
  1958.     *var = x;                /* Set variable */
  1959.     return(1);
  1960. }
  1961.  
  1962. #ifndef NOSPL                /* The SORT command... */
  1963.  
  1964. static struct keytab srtswtab[] = {    /* SORT command switches */
  1965.     "/case",    SRT_CAS, CM_ARG,
  1966.     "/key",     SRT_KEY, CM_ARG,
  1967.     "/numeric", SRT_NUM, 0,
  1968.     "/range",   SRT_RNG, CM_ARG,
  1969.     "/reverse", SRT_REV, 0
  1970. };
  1971. static int nsrtswtab = sizeof(srtswtab)/sizeof(struct keytab);
  1972.  
  1973. extern char **a_ptr[];            /* Array pointers */
  1974. extern int a_dim[];            /* Array dimensions */
  1975.  
  1976. int
  1977. dosort() {                /* Do the SORT command */
  1978.     char c, *p = NULL, ** ap, ** xp = NULL;
  1979.     struct FDB sw, fl, cm;
  1980.     int hi, lo;
  1981.     int xn = 0, xr = -1, xk = -1, xc = -1, xs = 0;
  1982.     int getval = 0, range[2], confirmed = 0;
  1983.  
  1984.     cmfdbi(&sw,                /* First FDB - command switches */
  1985.        _CMKEY,            /* fcode */
  1986.        "Array name or switch",
  1987.        "",                /* default */
  1988.        "",                /* addtl string data */
  1989.        nsrtswtab,            /* addtl numeric data 1: tbl size */
  1990.        4,                /* addtl numeric data 2: 4 = cmswi */
  1991.        NULL,            /* Processing function */
  1992.        srtswtab,            /* Keyword table */
  1993.        &fl                /* Pointer to next FDB */
  1994.        );
  1995.     cmfdbi(&fl,                /* Anything that doesn't match */
  1996.        _CMFLD,            /* fcode */
  1997.        "Array name",        /* hlpmsg */
  1998.        "",                /* default */
  1999.        "",                /* addtl string data */
  2000.        0,                /* addtl numeric data 1 */
  2001.        0,                /* addtl numeric data 2 */
  2002.        NULL,
  2003.        NULL,
  2004.        &cm
  2005.        );
  2006.     cmfdbi(&cm,                /* Or premature confirmation */
  2007.        _CMCFM,            /* fcode */
  2008.        "",                /* hlpmsg */
  2009.        "",                /* default */
  2010.        "",                /* addtl string data */
  2011.        0,                /* addtl numeric data 1 */
  2012.        0,                /* addtl numeric data 2 */
  2013.        NULL,
  2014.        NULL,
  2015.        NULL
  2016.        );
  2017.  
  2018.     range[0] = -1;
  2019.     range[1] = -1;
  2020.  
  2021.     while (1) {                /* Parse 0 or more switches */
  2022.     x = cmfdb(&sw);
  2023.     if (x < 0)
  2024.       return(x);
  2025.     if (cmresult.fcode != _CMKEY)    /* Break out if not a switch */
  2026.       break;
  2027.     c = cmgbrk();
  2028.     getval = (c == ':' || c == '=');
  2029.     if (getval && !(cmresult.kflags & CM_ARG)) {
  2030.         printf("?This switch does not take arguments\n");
  2031.         return(-9);
  2032.     }
  2033.     switch (cmresult.nresult) {
  2034.       case SRT_REV:
  2035.         xr = 1;
  2036.         break;
  2037.       case SRT_KEY:
  2038.         if (getval) {
  2039.         if ((y = cmnum("Column for comparison (1-based)",
  2040.                    "1",10,&x,xxstring)) < 0)
  2041.           return(y);
  2042.         xk = x - 1;
  2043.         } else
  2044.           xk = 0;
  2045.         break;
  2046.       case SRT_CAS:
  2047.         if (getval) {
  2048.         if ((y = cmkey(onoff,2,"","on",xxstring)) < 0)
  2049.           return(y);
  2050.         xc = y;
  2051.         } else
  2052.           xc = 1;
  2053.         break;
  2054.       case SRT_RNG:            /* /RANGE */
  2055.         if (getval) {
  2056.         char buf[32];
  2057.         char buf2[16];
  2058.         int i;
  2059.         char * p, * q;
  2060.         if ((y = cmfld("low:high element","1",&s,NULL)) < 0)
  2061.           return(y);
  2062.         s = brstrip(s);
  2063.         ckstrncpy(buf,s,32);
  2064.         p = buf;
  2065.         for (i = 0; *p && i < 2; i++) { /* Get low and high */
  2066.             q = p;        /* Start of this piece */
  2067.             while (*p) {    /* Find end of this piece */
  2068.             if (*p == ':') {
  2069.                 *p = NUL;
  2070.                 p++;
  2071.                 break;
  2072.             }
  2073.             p++;
  2074.             }
  2075.             y = 15;        /* Evaluate this piece */
  2076.             s = buf2;
  2077.             zzstring(q,&s,&y);
  2078.             s = evalx(buf2);
  2079.             if (s) if (*s) ckstrncpy(buf2,s,16);
  2080.             if (!rdigits(buf2)) {
  2081.             printf("?Not numeric: %s\n",buf2);
  2082.             return(-9);
  2083.             }
  2084.             range[i] = atoi(buf2);
  2085.         }
  2086.         }
  2087.         break;
  2088.       case SRT_NUM:            /* /NUMERIC */
  2089.         xn = 1;
  2090.         break;
  2091.       default:
  2092.         return(-2);
  2093.     }
  2094.     }
  2095.     switch (cmresult.fcode) {
  2096.       case _CMCFM:
  2097.     confirmed = 1;
  2098.     break;
  2099.       case _CMFLD:
  2100.     ckstrncpy(line,cmresult.sresult,LINBUFSIZ); /* Safe copy of name */
  2101.     s = line;
  2102.     break;
  2103.       default:
  2104.     printf("?Unexpected function code: %d\n",cmresult.fcode);
  2105.     return(-9);
  2106.     }
  2107.     if (confirmed) {
  2108.     printf("?Array name required\n");
  2109.     return(-9);
  2110.     }
  2111.     sprintf(tmpbuf,"Second array to sort according to %s",s);
  2112.     debug(F101,"XXX 1","",0);
  2113.     if ((x = cmfld(tmpbuf,"",&p,NULL)) < 0)
  2114.       if (x != -3)
  2115.     return(x);
  2116.     debug(F101,"XXX 2","",0);
  2117.     tmpbuf[0] = NUL;
  2118.     strcpy(tmpbuf,p);
  2119.     p = tmpbuf;
  2120.     if ((x = cmcfm()) < 0)        /* Get confirmation */
  2121.       return(x);
  2122.     debug(F101,"XXX 3","",0);
  2123.  
  2124.     x = arraybounds(s,&lo,&hi);        /* Get array index & bounds */
  2125.     if (x < 0) {            /* Check */
  2126.     printf("?Bad array name: %s\n",s);
  2127.     return(-9);
  2128.     }
  2129.     if (lo > -1) range[0] = lo;        /* Set range */
  2130.     if (hi > -1) range[1] = hi;
  2131.     ap = a_ptr[x];            /* Get pointer to array element list */
  2132.     if (!ap) {                /* Check */
  2133.     printf("?Array not declared: %s\n", s);
  2134.     return(-9);
  2135.     }
  2136.     if (range[0] < 0)            /* Starting element */
  2137.       range[0] = 1;
  2138.     if (range[1] < 0)            /* Final element */
  2139.       range[1] = a_dim[x];
  2140.     if (range[1] > a_dim[x]) {
  2141.     printf("?range %d:%d exceeds array dimension %d\n",
  2142.            range[0],range[1],a_dim[x]
  2143.            );
  2144.     return(-9);
  2145.     }
  2146.     ap += range[0];
  2147.     xs = range[1] - range[0] + 1;    /* Number of elements to sort */
  2148.     if (xs < 1) {            /* Check */
  2149.     printf("?Bad range: %d:%d\n",range[0],range[1]);
  2150.     return(-9);
  2151.     }
  2152.     if (xk < 0) xk = 0;            /* Key position */
  2153.     if (xr < 0) xr = 0;            /* Reverse flag */
  2154.     if (xn)                /* Numeric flag */
  2155.       xc = 2;
  2156.     else if (xc < 0)            /* Not numeric */
  2157.       xc = inpcas[cmdlvl];        /* so alpha case option */
  2158.  
  2159.     if (*p) {                /* Parallel array given? */
  2160.     y = xarray(p);            /* Yes, get its index. */
  2161.     if (y < 0) {
  2162.         printf("?Bad array name: %s\n", p);
  2163.         return(-9);
  2164.     }
  2165.     if (y != x) {            /* If the 2 arrays are different  */
  2166.         xp = a_ptr[y];        /* Pointer to 2nd array element list */
  2167.         if (!xp) {
  2168.         printf("?Array not declared: %s\n", p);
  2169.         return(-9);
  2170.         }
  2171.         if (a_dim[y] < range[1]) {
  2172.         printf("?Array %s smaller than %s\n", p, s);
  2173.         return(-9);
  2174.         }
  2175.         xp += range[0];        /* Set base to same as 1st array */
  2176.     }
  2177.     }
  2178.     debug(F101,"XXX xp","",xp);
  2179.     debug(F101,"XXX xc","",xc);
  2180.     sh_sort(ap,xp,xs,xk,xr,xc);        /* Sort the array(s) */
  2181.     return(success = 1);        /* Always succeeds */
  2182. }
  2183. #endif /* NOSPL */
  2184.  
  2185. static struct keytab purgtab[] = {    /* PURGE command switches */
  2186.     "/after",        PU_AFT,  CM_ARG,
  2187.     "/ask",          PU_ASK,  0,
  2188.     "/before",       PU_BEF,  CM_ARG,
  2189.     "/delete",       PU_DELE, CM_INV,
  2190. #ifdef UNIXOROSK
  2191.     "/dotfiles",     PU_DOT,  0,
  2192. #endif /* UNIXOROSK */
  2193.     "/except",       PU_EXC,  CM_ARG,
  2194.     "/heading",      PU_HDG,  0,
  2195.     "/keep",         PU_KEEP, CM_ARG,
  2196.     "/larger-than",  PU_LAR,  CM_ARG,
  2197.     "/list",         PU_LIST, 0,
  2198.     "/log",          PU_LIST, CM_INV,
  2199.     "/noask",        PU_NASK, 0,
  2200.     "/nodelete",     PU_NODE, CM_INV,
  2201. #ifdef UNIXOROSK
  2202.     "/nodotfiles",   PU_NODOT,0,
  2203. #endif /* UNIXOROSK */
  2204.     "/noheading",    PU_NOH,  0,
  2205.     "/nol",          PU_NOLI, CM_INV|CM_ABR,
  2206.     "/nolist",       PU_NOLI, 0,
  2207.     "/nolog",        PU_NOLI, CM_INV,
  2208. #ifdef CK_TTGWSIZ
  2209.     "/nopage",       PU_NOPA, 0,
  2210. #endif /* CK_TTGWSIZ */
  2211.     "/not-after",    PU_NAF,  CM_ARG,
  2212.     "/not-before",   PU_NBF,  CM_ARG,
  2213.     "/not-since",    PU_NAF,  CM_INV|CM_ARG,
  2214. #ifdef CK_TTGWSIZ
  2215.     "/page",         PU_PAGE, 0,
  2216. #endif /* CK_TTGWSIZ */
  2217.     "/quiet",        PU_QUIE, CM_INV,
  2218. #ifdef RECURSIVE
  2219.     "/recursive",    PU_RECU, 0,
  2220. #endif /* RECURSIVE */
  2221.     "/since",        PU_AFT,  CM_ARG|CM_INV,
  2222.     "/simulate",     PU_NODE, 0,
  2223.     "/smaller-than", PU_SMA,  CM_ARG,
  2224.     "/verbose",      PU_VERB, CM_INV
  2225. };
  2226. static int npurgtab = sizeof(purgtab)/sizeof(struct keytab);
  2227.  
  2228. int
  2229. bkupnum(s,i) char * s; int *i; {
  2230.     int k = 0, pos = 0;
  2231.     char * p = NULL, *q;
  2232.     *i = pos;
  2233.     if (!s) s = "";
  2234.     if (!*s)
  2235.       return(-1);
  2236.     if ((k = strlen(s)) < 5)
  2237.       return(-1);
  2238.  
  2239.     if (s[k-1] != '~')
  2240.       return(-1);
  2241.     pos = k - 2;
  2242.     q = s + pos;
  2243.     while (q >= s && isdigit(*q)) {
  2244.     p = q--;
  2245.     pos--;
  2246.     }
  2247.     if (!p)
  2248.       return(-1);
  2249.     if (q < s+2)
  2250.       return(-1);
  2251.     if (*q != '~' || *(q-1) != '.')
  2252.       return(-1);
  2253.     pos--;
  2254.     *i = pos;
  2255.     debug(F111,"bkupnum",s+pos,pos);
  2256.     return(atoi(p));
  2257. }
  2258.  
  2259. #ifdef CKPURGE
  2260. /* Presently only for UNIX because we need direct access to the file array. */
  2261. /* Not needed for VMS anyway, because we don't make backup files there. */
  2262.  
  2263. #define MAXKEEP 32            /* Biggest /KEEP: value */
  2264.  
  2265. static int
  2266.   pu_keep = 0, pu_list = 0, pu_dot = 0, pu_ask = 0, pu_hdg = 0;
  2267.  
  2268. #ifdef CK_TTGWSIZ
  2269. static int pu_page = -1;
  2270. #else
  2271. static int pu_page = 0;
  2272. #endif /* CK_TTGWSIZ */
  2273.  
  2274. #ifndef NOSHOW
  2275. VOID
  2276. showpurgopts() {            /* SHOW PURGE command options */
  2277.     int x = 0;
  2278.     extern int optlines;
  2279.     prtopt(&optlines,"PURGE");
  2280.     if (pu_ask > -1) {
  2281.     x++;
  2282.     prtopt(&optlines, pu_ask ? "/ASK" : "/NOASK");
  2283.     }
  2284. #ifdef UNIXOROSK
  2285.     if (pu_dot > -1) {
  2286.     x++;
  2287.     prtopt(&optlines, pu_dot ? "/DOTFILES" : "/NODOTFILES");
  2288.     }
  2289. #endif /* UNIXOROSK */
  2290.     if (pu_keep > -1) {
  2291.     x++;
  2292.     sprintf(tmpbuf, "%s:%d", "/KEEP", pu_keep);
  2293.     prtopt(&optlines,tmpbuf);
  2294.     }
  2295.     if (pu_list > -1) {
  2296.     x++;
  2297.     prtopt(&optlines, pu_list ? "/LIST" : "/NOLIST");
  2298.     }
  2299.     if (pu_hdg > -1) {
  2300.     x++;
  2301.     prtopt(&optlines, pu_hdg ? "/HEADING" : "/NOHEADING");
  2302.     }
  2303. #ifdef CK_TTGWSIZ
  2304.     if (pu_page > -1) {
  2305.     x++;
  2306.     prtopt(&optlines, pu_page ? "/PAGE" : "/NOPAGE");
  2307.     }
  2308. #endif /* CK_TTGWSIZ */
  2309.     if (!x) prtopt(&optlines,"(no options set)");
  2310.     prtopt(&optlines,"");
  2311. }
  2312. #endif /* NOSHOW */
  2313.  
  2314. int
  2315. setpurgopts() {                /* Set PURGE command options */
  2316.     int c, z, getval = 0;
  2317.     int
  2318.       x_keep  = -1, x_list = -1, x_page = -1,
  2319.       x_hdg   = -1, x_ask  = -1, x_dot  = -1;
  2320.  
  2321.     while (1) {
  2322.     if ((y = cmswi(purgtab,npurgtab,"Switch","",xxstring)) < 0) {
  2323.         if (y == -3)
  2324.           break;
  2325.         else
  2326.           return(y);
  2327.     }
  2328.     c = cmgbrk();
  2329.     if ((getval = (c == ':' || c == '=')) && !(cmgkwflgs() & CM_ARG)) {
  2330.         printf("?This switch does not take an argument\n");
  2331.         return(-9);
  2332.     }
  2333.     if (!getval && (cmgkwflgs() & CM_ARG)) {
  2334.         printf("?This switch requires an argument\n");
  2335.         return(-9);
  2336.     }
  2337.     switch (y) {
  2338.       case PU_KEEP:
  2339.         z = 1;
  2340.         if (c == ':' || c == '=')
  2341.           if ((y = cmnum("How many backup files to keep",
  2342.                  "1",10,&z,xxstring)) < 0)
  2343.         return(y);
  2344.         if (z < 0 || z > MAXKEEP) {
  2345.         printf("?Please specify a number between 0 and %d\n",
  2346.                MAXKEEP
  2347.                );
  2348.         return(-9);
  2349.         }
  2350.         x_keep = z;
  2351.         break;
  2352.       case PU_LIST:
  2353.       case PU_VERB:
  2354.         x_list = 1;
  2355.         break;
  2356.       case PU_QUIE:
  2357.       case PU_NOLI:
  2358.         x_list = 0;
  2359.         break;
  2360. #ifdef CK_TTGWSIZ
  2361.       case PU_PAGE:
  2362.         x_page = 1;
  2363.         break;
  2364.       case PU_NOPA:
  2365.         x_page = 0;
  2366.         break;
  2367. #endif /* CK_TTGWSIZ */
  2368.       case PU_HDG:
  2369.         x_hdg = 1;
  2370.         break;
  2371.       case PU_NOH:
  2372.         x_hdg = 0;
  2373.         break;
  2374.       case PU_ASK:
  2375.         x_ask = 1;
  2376.         break;
  2377.       case PU_NASK:
  2378.         x_ask = 0;
  2379.         break;
  2380. #ifdef UNIXOROSK
  2381.       case PU_DOT:
  2382.         x_dot = 1;
  2383.         break;
  2384.       case PU_NODOT:
  2385.         x_dot = 0;
  2386.         break;
  2387. #endif /* UNIXOROSK */
  2388.       default:
  2389.         printf("?This option can not be set\n");
  2390.         return(-9);
  2391.     }
  2392.     }
  2393.     if ((x = cmcfm()) < 0)        /* Get confirmation */
  2394.       return(x);
  2395.     if (x_keep > -1)            /* Set PURGE defaults. */
  2396.       pu_keep = x_keep;
  2397.     if (x_list > -1)
  2398.       pu_list = x_list;
  2399. #ifdef CK_TTGWSIZ
  2400.     if (x_page > -1)
  2401.       pu_page = x_page;
  2402. #endif /* CK_TTGWSIZ */
  2403.     if (x_hdg > -1)
  2404.       pu_hdg = x_hdg;
  2405.     if (x_ask > -1)
  2406.       pu_ask = x_ask;
  2407.     if (x_dot > -1)
  2408.       pu_dot = x_dot;
  2409.     return(success = 1);
  2410. }
  2411.  
  2412. int
  2413. dopurge() {                /* Do the PURGE command */
  2414.     extern char ** mtchs;
  2415.     extern int xaskmore, cmd_rows, recursive;
  2416.     int simulate = 0, asking = 0;
  2417.     int listing = 0, paging = -1, lines = 0, deleting = 1, errors = 0;
  2418.     struct FDB sw, sf, cm;
  2419.     int g, i, j, k, m = 0, n, x, y, z, done = 0, count = 0, flags = 0;
  2420.     int tokeep = 0, getval = 0, havename = 0, confirmed = 0;
  2421.     int xx[MAXKEEP+1];            /* Array of numbers to keep */
  2422.     int min = -1;
  2423.     int x_hdg = 0, fs = 0, rc = 0;
  2424.     long minsize = -1L, maxsize = -1L;
  2425.     char namebuf[CKMAXPATH+4];
  2426.     char basebuf[CKMAXPATH+4];
  2427.     char
  2428.       * pu_aft = NULL,
  2429.       * pu_bef = NULL,
  2430.       * pu_naf = NULL,
  2431.       * pu_nbf = NULL,
  2432.       * pu_exc = NULL;
  2433.     char * pxlist[8];            /* Exception list */
  2434.  
  2435.     if (pu_keep > -1)            /* Set PURGE defaults. */
  2436.       tokeep = pu_keep;
  2437.     if (pu_list > -1)
  2438.       listing = pu_list;
  2439. #ifdef CK_TTGWSIZ
  2440.     if (pu_page > -1)
  2441.       paging = pu_page;
  2442. #endif /* CK_TTGWSIZ */
  2443.  
  2444.     for (i = 0; i <= MAXKEEP; i++)    /* Clear this number buffer */
  2445.       xx[i] = 0;
  2446.     for (i = 0; i < 8; i++)        /* Initialize these... */
  2447.       pxlist[i] = NULL;
  2448.  
  2449.     g_matchdot = matchdot;        /* Save these... */
  2450.     saveask = xaskmore;
  2451.  
  2452.     cmfdbi(&sw,                /* 1st FDB - PURGE switches */
  2453.        _CMKEY,            /* fcode */
  2454.        "Filename or switch",    /* hlpmsg */
  2455.        "",                /* default */
  2456.        "",                /* addtl string data */
  2457.        npurgtab,            /* addtl numeric data 1: tbl size */
  2458.        4,                /* addtl numeric data 2: 4 = cmswi */
  2459.        xxstring,            /* Processing function */
  2460.        purgtab,            /* Keyword table */
  2461.        &sf                /* Pointer to next FDB */
  2462.        );
  2463.     cmfdbi(&sf,                /* 2nd FDB - filespec to purge */
  2464.        _CMIFI,            /* fcode */
  2465.        "",
  2466.        "",                /* default */
  2467.        "",                /* addtl string data */
  2468.        0,                /* addtl numeric data 1 */
  2469.        0,                /* addtl numeric data 2 */
  2470.        xxstring,
  2471.        NULL,
  2472.        &cm
  2473.        );
  2474.     cmfdbi(&cm,                /* Or premature confirmation */
  2475.        _CMCFM,            /* fcode */
  2476.        "",                /* hlpmsg */
  2477.        "",                /* default */
  2478.        "",                /* addtl string data */
  2479.        0,                /* addtl numeric data 1 */
  2480.        0,                /* addtl numeric data 2 */
  2481.        NULL,
  2482.        NULL,
  2483.        NULL
  2484.        );
  2485.  
  2486.     while (!havename && !confirmed) {
  2487.     x = cmfdb(&sw);            /* Parse something */
  2488.     if (x < 0) {            /* Error */
  2489.         rc = x;
  2490.         goto xpurge;
  2491.     } else if (cmresult.fcode == _CMKEY) {
  2492.         char c;
  2493.         c = cmgbrk();
  2494.         if ((getval = (c == ':' || c == '=')) && !(cmgkwflgs() & CM_ARG)) {
  2495.         printf("?This switch does not take an argument\n");
  2496.         rc = -9;
  2497.         goto xpurge;
  2498.         }
  2499.         if (!getval && (cmgkwflgs() & CM_ARG)) {
  2500.         printf("?This switch requires an argument\n");
  2501.         rc = -9;
  2502.         goto xpurge;
  2503.         }
  2504.         switch (k = cmresult.nresult) {
  2505.           case PU_KEEP:
  2506.         z = 1;
  2507.         if (c == ':' || c == '=') {
  2508.             if ((y = cmnum("How many backup files to keep",
  2509.                    "1",10,&z,xxstring)) < 0) {
  2510.             rc = y;
  2511.             goto xpurge;
  2512.             }
  2513.         }
  2514.         if (z < 0 || z > MAXKEEP) {
  2515.             printf("?Please specify a number between 0 and %d\n",
  2516.                MAXKEEP
  2517.                );
  2518.             rc = -9;
  2519.             goto xpurge;
  2520.         }
  2521.         tokeep = z;
  2522.         break;
  2523.           case PU_LIST:
  2524.         listing = 1;
  2525.         break;
  2526.           case PU_NOLI:
  2527.         listing = 0;
  2528.         break;
  2529. #ifdef CK_TTGWSIZ
  2530.           case PU_PAGE:
  2531.         paging = 1;
  2532.         break;
  2533.           case PU_NOPA:
  2534.         paging = 0;
  2535.         break;
  2536. #endif /* CK_TTGWSIZ */
  2537.           case PU_DELE:
  2538.         deleting = 1;
  2539.         break;
  2540.           case PU_NODE:
  2541.         deleting = 0;
  2542.         simulate = 1;
  2543.         listing = 1;
  2544.         break;
  2545.           case PU_ASK:
  2546.         asking = 1;
  2547.         break;
  2548.           case PU_NASK:
  2549.         asking = 0;
  2550.         break;
  2551.           case PU_AFT:
  2552.           case PU_BEF:
  2553.           case PU_NAF:
  2554.           case PU_NBF:
  2555.         if ((x = cmdate("File-time","",&s,0,xxstring)) < 0) {
  2556.             if (x == -3) {
  2557.             printf("?Date-time required\n");
  2558.             rc = -9;
  2559.             } else
  2560.               rc = x;
  2561.             goto xpurge;
  2562.         }
  2563.         fs++;
  2564.         switch (k) {
  2565.           case PU_AFT: makestr(&pu_aft,s); break;
  2566.           case PU_BEF: makestr(&pu_bef,s); break;
  2567.           case PU_NAF: makestr(&pu_naf,s); break;
  2568.           case PU_NBF: makestr(&pu_nbf,s); break;
  2569.         }
  2570.         break;
  2571.           case PU_SMA:
  2572.           case PU_LAR:
  2573.         if ((x = cmnum("File size in bytes","0",10,&y,xxstring)) < 0) {
  2574.             rc = x;
  2575.             goto xpurge;
  2576.         }
  2577.         fs++;
  2578.         switch (cmresult.nresult) {
  2579.           case PU_SMA: minsize = y; break;
  2580.           case PU_LAR: maxsize = y; break;
  2581.         }
  2582.         break;
  2583.           case PU_DOT:
  2584.         matchdot = 1;
  2585.         break;
  2586.           case PU_NODOT:
  2587.         matchdot = 0;
  2588.         break;
  2589.           case PU_EXC:
  2590.         if ((x = cmfld("Pattern","",&s,xxstring)) < 0) {
  2591.             if (x == -3) {
  2592.             printf("?Pattern required\n");
  2593.             rc = -9;
  2594.             } else
  2595.               rc = x;
  2596.             goto xpurge;
  2597.         }
  2598.         fs++;
  2599.         makestr(&pu_exc,s);
  2600.         break;
  2601.           case PU_HDG:
  2602.         x_hdg = 1;
  2603.         break;
  2604. #ifdef RECURSIVE
  2605.           case PU_RECU:        /* /RECURSIVE */
  2606.         recursive = 2;
  2607.         break;
  2608. #endif /* RECURSIVE */
  2609.           default:
  2610.         printf("?Not implemented yet - \"%s\"\n",atmbuf);
  2611.         rc = -9;
  2612.         goto xpurge;
  2613.         }
  2614.     } else if (cmresult.fcode == _CMIFI) {
  2615.         havename = 1;
  2616.     } else if (cmresult.fcode == _CMCFM) {
  2617.         confirmed = 1;
  2618.     } else {
  2619.         rc = -2;
  2620.         goto xpurge;
  2621.     }
  2622.     }
  2623.     if (havename) {
  2624. #ifdef CKREGEX
  2625.     sprintf(line,"%s.~[1-9]*~",cmresult.sresult);
  2626. #else
  2627.     sprintf(line,"%s.~*~",cmresult.sresult);
  2628. #endif /* CKREGEX */
  2629.     } else {
  2630. #ifdef CKREGEX
  2631.     strcpy(line,"*.~[1-9]*~");
  2632. #else
  2633.     strcpy(line,"*.~*~");
  2634. #endif /* CKREGEX */
  2635.     }
  2636.     if (!confirmed) {
  2637.     if ((x = cmcfm()) < 0) {
  2638.         rc = x;
  2639.         goto xpurge;
  2640.     }
  2641.     }
  2642.     /* Parse finished - now action */
  2643.  
  2644. #ifdef CK_LOGIN
  2645.     if (isguest) {
  2646.     printf("?File deletion by guests not permitted.\n");
  2647.     rc = -9;
  2648.     goto xpurge;
  2649.     }
  2650. #endif /* CK_LOGIN */
  2651.  
  2652. #ifdef CK_TTGWSIZ
  2653.     if (paging < 0)            /* /[NO]PAGE not given */
  2654.       paging = xaskmore;        /* so use prevailing */
  2655. #endif /* CK_TTGWSIZ */
  2656.  
  2657.     lines = 0;
  2658.     if (x_hdg > 0) {
  2659.     printf("Purging %s, keeping %d...%s\n",
  2660.            s,
  2661.            tokeep,
  2662.            simulate ? " (SIMULATION)" : "");
  2663.     lines += 2;
  2664.     }
  2665.     flags = ZX_FILONLY;
  2666.     if (recursive) flags |= ZX_RECURSE;
  2667.     n = nzxpand(line,flags);        /* Get list of backup files */
  2668.     if (tokeep < 1) {            /* Deleting all of them... */
  2669.     for (i = 0; i < n; i++) {
  2670.         if (fs) if (fileselect(mtchs[i],
  2671.                    pu_aft,pu_bef,pu_naf,pu_nbf,
  2672.                    minsize,maxsize,0,8,pxlist) < 1) {
  2673.         if (listing > 0) {
  2674.             printf(" %s (SKIPPED)\n",mtchs[i]);
  2675. #ifdef CK_TTGWSIZ
  2676.             if (paging)
  2677.               if (++lines > cmd_rows - 3) {
  2678.               if (!askmore()) goto xpurge; else lines = 0;
  2679.               }
  2680. #endif /* CK_TTGWSIZ */
  2681.         }
  2682.         continue;
  2683.         }
  2684.         if (asking) {
  2685.         int x;
  2686.         sprintf(tmpbuf," Delete %s? ",mtchs[i]);
  2687.         x = getyesno(tmpbuf,1);
  2688.         switch (x) {
  2689.           case 0: continue;
  2690.           case 1: break;
  2691.           case 2: goto xpurge;
  2692.         }
  2693.         }
  2694.         x = deleting ? zdelet(mtchs[i]) : 0;
  2695.         if (x > -1) {
  2696.         if (listing)
  2697.           printf(" %s (%s)\n", mtchs[i],deleting ? "OK" : "SELECTED");
  2698.         count++;
  2699.         } else {
  2700.         errors++;
  2701.         if (listing)
  2702.           printf(" %s (FAILED)\n", mtchs[i]);
  2703.         }
  2704. #ifdef CK_TTGWSIZ
  2705.         if (listing && paging)
  2706.           if (++lines > cmd_rows - 3) {
  2707.           if (!askmore()) goto xpurge; else lines = 0;
  2708.           }
  2709. #endif /* CK_TTGWSIZ */
  2710.     }
  2711.     goto xpurge;
  2712.     }
  2713.     if (n < tokeep) {            /* Not deleting any */
  2714.     count = 0;
  2715.     if (listing)
  2716.       printf(" Matches = %d: Not enough to purge.\n");
  2717.     goto xpurge;
  2718.     }
  2719.  
  2720.     /* General case - delete some but not others */
  2721.  
  2722.     sh_sort(mtchs,NULL,n,0,0,filecase);    /* Alphabetize the list (ESSENTIAL) */
  2723.  
  2724.     g = 0;                /* Start of current group */
  2725.     for (i = 0; i < n; i++) {        /* Go thru sorted file list */
  2726.     x = znext(namebuf);        /* Get next file */
  2727.     if (x < 1 || !namebuf[0] || i == n - 1)    /* No more? */
  2728.       done = 1;            /* NOTE: 'done' must be 0 or 1 only */
  2729.     if (fs) if (fileselect(namebuf,
  2730.                    pu_aft,pu_bef,pu_naf,pu_nbf,
  2731.                    minsize,maxsize,0,8,pxlist) < 1) {
  2732.         if (listing > 0) {
  2733.         printf(" %s (SKIPPED)\n",namebuf);
  2734.         if (++lines > cmd_rows - 3)
  2735.           if (!askmore()) goto xpurge; else lines = 0;
  2736.         }
  2737.         continue;
  2738.     }
  2739.     if (x > 0)
  2740.       if ((m = bkupnum(namebuf,&z)) < 0) /* This file's backup number. */
  2741.         continue;
  2742.     for (j = 0; j < tokeep; j++) {    /* Insert in list. */
  2743.         if (m > xx[j]) {
  2744.         for (k = tokeep - 1; k > j; k--)
  2745.           xx[k] = xx[k-1];
  2746.         xx[j] = m;
  2747.         break;
  2748.         }
  2749.     }
  2750.     /* New group? */
  2751.     if (done || (i > 0 && ckstrcmp(namebuf,basebuf,z,1))) {
  2752.         if (i + done - g > tokeep) { /* Do we have enough to purge? */
  2753.         min = xx[tokeep-1];    /* Yes, lowest backup number to keep */
  2754.         debug(F111,"dopurge group",basebuf,min);
  2755.         for (j = g; j < i + done; j++) { /* Go through this group */
  2756.             x = bkupnum(mtchs[j],&z);    /* Get file backup number */
  2757.             if (x > 0 && x < min) {      /* Below minimum? */
  2758.             x = deleting ? zdelet(mtchs[j]) : 0;
  2759.             if (x < 0) errors++;
  2760.             if (listing)
  2761.               printf(" %s (%s)\n",
  2762.                  mtchs[j],
  2763.                  ((x < 0) ? "ERROR" :
  2764.                   (deleting ? "DELETED" : "SELECTED"))
  2765.                  );
  2766.             count++;
  2767.             } else if (listing)    /* Not below minimum - keep this one */
  2768.               printf(" %s (KEPT)\n",mtchs[j]);
  2769. #ifdef CK_TTGWSIZ
  2770.             if (listing && paging)
  2771.               if (++lines > cmd_rows - 3) {
  2772.               if (!askmore()) goto xpurge; else lines = 0;
  2773.               }
  2774. #endif /* CK_TTGWSIZ */
  2775.         }
  2776.         } else if (listing && paging) { /* Not enough to purge */
  2777.         printf(" %s.~*~ (KEPT)\n",basebuf);
  2778. #ifdef CK_TTGWSIZ
  2779.         if (++lines > cmd_rows - 3) {
  2780.             if (!askmore()) goto xpurge; else lines = 0;
  2781.         }
  2782. #endif /* CK_TTGWSIZ */
  2783.         }
  2784.         for (j = 0; j < tokeep; j++) /* Clear the backup number list */
  2785.           xx[j] = 0;
  2786.         g = i;            /* Reset the group pointer */
  2787.     }
  2788.     if (done)            /* No more files, done. */
  2789.       break;
  2790.     strncpy(basebuf,namebuf,z);    /* Set basename of this file */
  2791.     basebuf[z] = NUL;
  2792.     }
  2793.   xpurge:                /* Common exit point */
  2794.     if (g_matchdot > -1) {
  2795.     matchdot = g_matchdot;        /* Restore these... */
  2796.     g_matchdot = -1;
  2797.     }
  2798. #ifdef CK_TTGWSIZ
  2799.     if (saveask > -1) {
  2800.     xaskmore = saveask;
  2801.     saveask = -1;
  2802.     }
  2803. #endif /* CK_TTGWSIZ */
  2804.     if (rc < 0) return(rc);        /* Parse error */
  2805.     if (x_hdg)
  2806.       printf("Files purged: %d%s\n",
  2807.          count,
  2808.          deleting ? "" : " (not really)"
  2809.          );
  2810.     return(success = count > 0 ? 1 : (errors > 0) ? 0 : 1);
  2811. }
  2812. #endif /* CKPURGE */
  2813.  
  2814. #ifndef NOXFER
  2815. #ifndef NOLOCAL
  2816. int
  2817. doxdis() {
  2818.     extern int nolocal;
  2819.     int x, y = 0, z;
  2820. #ifdef COMMENT
  2821.     char *s;
  2822. #endif /* COMMENT */
  2823.  
  2824.     if ((x = cmkey(fdtab,nfdtab,"file transfer display style","",
  2825.            xxstring)) < 0)
  2826.       return(x);
  2827. #ifdef CK_PCT_BAR
  2828.     if ((y = cmkey(fdftab,2,"","thermometer",xxstring)) < 0)
  2829.       return(y);
  2830. #endif /* CK_PCT_BAR */
  2831.     if ((z = cmcfm()) < 0) return(z);
  2832. #ifdef CK_CURSES
  2833.     if (x == XYFD_C) {            /* FULLSCREEN */
  2834. #ifdef COMMENT
  2835. #ifndef MYCURSES
  2836.     extern char * trmbuf;        /* Real curses */
  2837.     int z;
  2838. #endif /* MYCURSES */
  2839. #endif /* COMMENT */
  2840.  
  2841.         if (nolocal)            /* Nothing to do in this case */
  2842.             return(success = 1);
  2843.  
  2844. #ifdef COMMENT
  2845. #ifndef MYCURSES
  2846. #ifndef VMS
  2847.     s = getenv("TERM");
  2848.         debug(F110,"doxdis TERM",s,0);
  2849.     if (!s) s = "";
  2850.     fxdinit(x);
  2851.     if (*s && trmbuf) {        /* Don't call tgetent */
  2852.         z = tgetent(trmbuf,s);    /* if trmbuf not allocated */
  2853.         debug(F111,"doxdis tgetent",s,z);
  2854.     } else {
  2855.         z = 0;
  2856.         debug(F110,"doxdis tgetent skipped",s,0);
  2857.     }
  2858.     if (z < 1) {
  2859.         printf("Sorry, terminal type unknown: \"%s\"\n",s);
  2860.         return(success = 0);
  2861.     }
  2862. #endif /* VMS */
  2863. #endif /* MYCURSES */
  2864. #else
  2865.     fxdinit(x);
  2866. #endif /* COMMENT */
  2867.  
  2868. #ifdef CK_PCT_BAR
  2869.     thermometer = y;
  2870. #endif /* CK_PCT_BAR */
  2871.  
  2872.     line[0] = '\0';            /* (What's this for?) */
  2873.     }
  2874. #endif /* CK_CURSES */
  2875.     fdispla = x;            /* It's OK. */
  2876.     return(success = 1);
  2877. }
  2878. #endif /* NOLOCAL */
  2879. #endif /* NOXFER */
  2880.  
  2881. int
  2882. setfil(rmsflg) int rmsflg; {
  2883. #ifndef NOXFER
  2884.     if (rmsflg) {
  2885.     if ((y = cmkey(rfiltab,nrfilp,"Remote file parameter","",
  2886.                xxstring)) < 0) {
  2887.         if (y == -3) {
  2888.         printf("?Remote file parameter required\n");
  2889.         return(-9);
  2890.         } else return(y);
  2891.     }
  2892.     } else {
  2893. #endif /* NOXFER */
  2894.     if ((y = cmkey(filtab,nfilp,"File parameter","",xxstring)) < 0)
  2895.       return(y);
  2896. #ifndef NOXFER
  2897.     }
  2898. #endif /* NOXFER */
  2899.     switch (y) {
  2900. #ifdef COMMENT                /* Not needed */
  2901.       case XYFILB:            /* Blocksize */
  2902.     if ((y = cmnum("file block size",ckitoa(DBLKSIZ),10,&z,xxstring)) < 0)
  2903.       return(y);
  2904.     if ((x = cmcfm()) < 0) return(x);
  2905.     if (rmsflg) {
  2906.         sstate = setgen('S', "311", ckitoa(z), "");
  2907.         return((int) sstate);
  2908.     } else {
  2909.         fblksiz = z;
  2910.         return(success = 1);
  2911.     }
  2912. #endif /* COMMENT */
  2913.  
  2914. #ifndef NOXFER
  2915.       case XYFILS:            /* Byte size */
  2916.     if ((y = cmnum("file byte size (7 or 8)","8",10,&z,xxstring)) < 0)
  2917.       return(y);
  2918.     if (z != 7 && z != 8) {
  2919.         printf("\n?The choices are 7 and 8\n");
  2920.         return(0);
  2921.     }
  2922.     if ((y = cmcfm()) < 0) return(y);
  2923.     if (z == 7) fmask = 0177;
  2924.     else if (z == 8) fmask = 0377;
  2925.     return(success = 1);
  2926.  
  2927. #ifndef NOCSETS
  2928.       case XYFILC: {            /* Character set */
  2929.       char * csetname = NULL;
  2930.       extern int
  2931.         r_cset, s_cset, afcset[];    /* SEND CHARACTER-SET AUTO or MANUAL */
  2932.  
  2933.       struct FDB kw, fl;
  2934.       cmfdbi(&kw,            /* First FDB - command switches */
  2935.          _CMKEY,        /* fcode */
  2936.          rmsflg ? "server character-set name" : "",  /* help */
  2937.          "",            /* default */
  2938.          "",            /* addtl string data */
  2939.          nfilc,            /* addtl numeric data 1: tbl size */
  2940.          0,            /* addtl numeric data 2: 0 = keyword */
  2941.          xxstring,        /* Processing function */
  2942.          fcstab,        /* Keyword table */
  2943.          rmsflg ? &fl : NULL    /* Pointer to next FDB */
  2944.        );
  2945.       cmfdbi(&fl,            /* Anything that doesn't match */
  2946.          _CMFLD,        /* fcode */
  2947.          "",            /* hlpmsg */
  2948.          "",            /* default */
  2949.          "",            /* addtl string data */
  2950.          0,            /* addtl numeric data 1 */
  2951.          0,            /* addtl numeric data 2 */
  2952.          xxstring,
  2953.          NULL,
  2954.          NULL
  2955.          );
  2956.       if ((x = cmfdb(&kw)) < 0)
  2957.         return(x);
  2958.       if (cmresult.fcode == _CMKEY) {
  2959.           x = cmresult.nresult;
  2960.           csetname = fcsinfo[x].keyword;
  2961.       } else {
  2962.           ckstrncpy(line,cmresult.sresult,LINBUFSIZ);
  2963.           csetname = line;
  2964.       }
  2965.       if ((z = cmcfm()) < 0) return(z);
  2966.       if (rmsflg) {
  2967.           sstate = setgen('S', "320", csetname, "");
  2968.           return((int) sstate);
  2969.       }
  2970.       fcharset = x;
  2971.       if (s_cset == XMODE_A)    /* If SEND CHARACTER-SET is AUTO */
  2972.         if (x > -1 && x <= MAXFCSETS)
  2973.           if (afcset[x] > -1 && afcset[x] <= MAXTCSETS)
  2974.         tcharset = afcset[x]; /* Pick corresponding xfer charset */
  2975.       setxlatype(tcharset,fcharset); /* Translation type */
  2976.       /* If I say SET FILE CHARACTER-SET blah, I want to be blah! */
  2977.       r_cset = XMODE_M;        /* Don't switch incoming set! */
  2978.       return(success = 1);
  2979.       }
  2980. #endif /* NOCSETS */
  2981.  
  2982. #ifndef NOLOCAL
  2983.       case XYFILD:            /* Display */
  2984.     return(doxdis());
  2985. #endif /* NOLOCAL */
  2986. #endif /* NOXFER */
  2987.  
  2988.       case XYFILA:            /* End-of-line */
  2989. #ifdef NLCHAR
  2990.     s = "";
  2991.     if (NLCHAR == 015)
  2992.       s = "cr";
  2993.     else if (NLCHAR == 012)
  2994.       s = "lf";
  2995.     if ((x = cmkey(eoltab, neoltab,
  2996.                "local text-file line terminator",s,xxstring)) < 0)
  2997.       return(x);
  2998. #else
  2999.     if ((x = cmkey(eoltab, neoltab,
  3000.                "local text-file line terminator","crlf",xxstring)) < 0)
  3001.       return(x);
  3002. #endif /* NLCHAR */
  3003.     if ((z = cmcfm()) < 0) return(z);
  3004.     feol = (CHAR) x;
  3005.     return(success = 1);
  3006.  
  3007. #ifndef NOXFER
  3008.       case XYFILN:            /* Names */
  3009.     if ((x = cmkey(fntab,nfntab,"how to handle filenames","converted",
  3010.                xxstring)) < 0)
  3011.       return(x);
  3012.     if ((z = cmcfm()) < 0) return(z);
  3013.     if (rmsflg) {
  3014.         sstate = setgen('S', "301", ckitoa(1 - x), "");
  3015.         return((int) sstate);
  3016.     } else {
  3017.         ptab[protocol].fncn = x;    /* Set structure */
  3018.         fncnv = x;            /* Set variable */
  3019.         f_save = x;            /* Set and set "permanent" variable */
  3020.         return(success = 1);
  3021.     }
  3022.  
  3023.       case XYFILR:            /* Record length */
  3024.     if ((y = cmnum("file record length",
  3025.                ckitoa(DLRECL),10,&z,xxstring)) < 0)
  3026.       return(y);
  3027.     if ((x = cmcfm()) < 0) return(x);
  3028.     if (rmsflg) {
  3029.         sstate = setgen('S', "312", ckitoa(z), "");
  3030.         return((int) sstate);
  3031.     } else {
  3032.         frecl = z;
  3033.         return(success = 1);
  3034.     }
  3035.  
  3036. #ifdef COMMENT
  3037.       case XYFILO:            /* Organization */
  3038.     if ((x = cmkey(forgtab,nforg,"file organization","sequential",
  3039.                xxstring)) < 0)
  3040.       return(x);
  3041.     if ((y = cmcfm()) < 0) return(y);
  3042.     if (rmsflg) {
  3043.         sstate = setgen('S', "314", ckitoa(x), "");
  3044.         return((int) sstate);
  3045.     } else {
  3046.         forg = x;
  3047.         return(success = 1);
  3048.     }
  3049. #endif /* COMMENT */
  3050.  
  3051. #ifdef COMMENT                /* Not needed */
  3052.       case XYFILF:            /* Format */
  3053.     if ((x = cmkey(frectab,nfrec,"file record format","stream",
  3054.                xxstring)) < 0)
  3055.       return(x);
  3056.     if ((y = cmcfm()) < 0) return(y);
  3057.     if (rmsflg) {
  3058.         sstate = setgen('S', "313", ckitoa(x), "");
  3059.         return((int) sstate);
  3060.     } else {
  3061.         frecfm = x;
  3062.         return(success = 1);
  3063.     }
  3064. #endif /* COMMENT */
  3065.  
  3066. #ifdef COMMENT
  3067.       case XYFILP:            /* Printer carriage control */
  3068.     if ((x = cmkey(fcctab,nfcc,"file carriage control","newline",
  3069.                xxstring)) < 0)
  3070.       return(x);
  3071.     if ((y = cmcfm()) < 0) return(y);
  3072.     if (rmsflg) {
  3073.         sstate = setgen('S', "315", ckitoa(x), "");
  3074.         return((int) sstate);
  3075.     } else {
  3076.         fcctrl = x;
  3077.         return(success = 1);
  3078.     }
  3079. #endif /* COMMENT */
  3080. #endif /* NOXFER */
  3081.  
  3082.       case XYFILT:            /* Type */
  3083.     if ((x = cmkey(rmsflg ? rfttab  : fttab,
  3084.                rmsflg ? nrfttyp : nfttyp,
  3085.                "type of file transfer","text",xxstring)) < 0)
  3086.       return(x);
  3087.  
  3088. #ifdef VMS
  3089.         /* Allow VMS users to choose record format for binary files */
  3090.         if ((x == XYFT_B) && (rmsflg == 0)) {
  3091.         if ((x = cmkey(fbtab,nfbtyp,"VMS record format","fixed",
  3092.                xxstring)) < 0)
  3093.           return(x);
  3094.     }
  3095. #endif /* VMS */
  3096.     if ((y = cmcfm()) < 0) return(y);
  3097.     binary = x;
  3098.     b_save = x;
  3099. #ifdef MAC
  3100.     (void) mac_setfildflg(binary);
  3101. #endif /* MAC */
  3102. #ifndef NOXFER
  3103.     if (rmsflg) {
  3104.         /* Allow for LABELED in VMS & OS/2 */
  3105.         sstate = setgen('S', "300", ckitoa(x), "");
  3106.         return((int) sstate);
  3107.     } else {
  3108. #endif /* NOXFER */
  3109.         return(success = 1);
  3110. #ifndef NOXFER
  3111.     }
  3112. #endif /* NOXFER */
  3113.  
  3114. #ifndef NOXFER
  3115.       case XYFILX:            /* Collision Action */
  3116.     if ((x = cmkey(colxtab,ncolx,"Filename collision action","backup",
  3117.                xxstring)) < 0)
  3118.       return(x);
  3119.     if ((y = cmcfm()) < 0) return(y);
  3120. #ifdef CK_LOGIN
  3121.     if (isguest) {
  3122.         /* Don't let guests change existing files */
  3123.         printf("?This command not valid for guests\n");
  3124.         return(-9);
  3125.     }
  3126. #endif /* CK_LOGIN */
  3127.     fncact = x;
  3128.     ptab[protocol].fnca = x;
  3129.     if (rmsflg) {
  3130.         sstate = setgen('S', "302", ckitoa(fncact), "");
  3131.         return((int) sstate);
  3132.     } else {
  3133.         if (fncact == XYFX_R) ckwarn = 1; /* FILE WARNING implications */
  3134.         if (fncact == XYFX_X) ckwarn = 0; /* ... */
  3135.         return(success = 1);
  3136.     }
  3137.  
  3138.       case XYFILW:            /* Warning/Write-Protect */
  3139.     if ((x = seton(&ckwarn)) < 0) return(x);
  3140.     if (ckwarn)
  3141.       fncact = XYFX_R;
  3142.     else
  3143.       fncact = XYFX_X;
  3144.     return(success = 1);
  3145.  
  3146. #ifdef CK_LABELED
  3147.       case XYFILL:            /* LABELED FILE parameters */
  3148.     if ((x = cmkey(lbltab,nlblp,"Labeled file feature","",
  3149.                xxstring)) < 0)
  3150.       return(x);
  3151.     if ((success = seton(&y)) < 0)
  3152.       return(success);
  3153.     if (y)                /* Set or reset the selected bit */
  3154.       lf_opts |= x;            /* in the options bitmask. */
  3155.     else
  3156.       lf_opts &= ~x;
  3157.     return(success);
  3158. #endif /* CK_LABELED */
  3159.  
  3160.       case XYFILI: {            /* INCOMPLETE */
  3161.       extern struct keytab ifdatab[];
  3162.       extern int keep;
  3163.       if ((y = cmkey(ifdatab,3,"","auto",xxstring)) < 0) return(y);
  3164.       if ((x = cmcfm()) < 0) return(x);
  3165.       if (rmsflg) {
  3166.           sstate = setgen('S',
  3167.                   "310",
  3168.                   y == 0 ? "0" : (y == 1 ? "1" : "2"),
  3169.                   ""
  3170.                   );
  3171.           return((int) sstate);
  3172.       } else {
  3173.           keep = y;
  3174.           return(success = 1);
  3175.       }
  3176.       }
  3177.  
  3178. #ifdef CK_TMPDIR
  3179.       case XYFILG: {            /* Download directory */
  3180.       int x;
  3181.       char *s;
  3182. #ifdef ZFNQFP
  3183.       struct zfnfp * fnp;
  3184. #endif /* ZFNQFP */
  3185. #ifdef MAC
  3186.       char temp[34];
  3187. #endif /* MAC */
  3188.  
  3189. #ifdef GEMDOS
  3190.       if ((x = cmdir("Name of local directory, or carriage return",
  3191.              "",&s,
  3192.              NULL)) < 0 ) {
  3193.           if (x != -3)
  3194.         return(x);
  3195.       }
  3196. #else
  3197. #ifdef OS2
  3198.       if ((x = cmdir("Name of PC disk and/or directory,\n\
  3199.        or press the Enter key to use current directory",
  3200.              "",&s,xxstring)) < 0 ) {
  3201.           if (x != -3)
  3202.         return(x);
  3203.       }
  3204. #else
  3205. #ifdef MAC
  3206.       x = ckstrncpy(temp,homdir,32);
  3207.       if (x > 0) if (temp[x-1] != ':') { temp[x] = ':'; temp[x+1] = NUL; }
  3208.       if ((x = cmtxt("Name of Macintosh volume and/or folder,\n\
  3209.  or press the Return key for the desktop on the boot disk",
  3210.              temp,&s, xxstring)) < 0 )
  3211.         return(x);
  3212. #else
  3213.       if ((x = cmdir("Name of local directory, or carriage return",
  3214.              "", &s, xxstring)) < 0 ) {
  3215.           if (x != -3)
  3216.         return(x);
  3217.       }
  3218. #endif /* MAC */
  3219. #endif /* OS2 */
  3220. #endif /* GEMDOS */
  3221.       debug(F110,"download dir",s,0);
  3222.  
  3223. #ifndef MAC
  3224.       if (x == 2) {
  3225.           printf("?Wildcards not allowed in directory name\n");
  3226.           return(-9);
  3227.       }
  3228. #endif /* MAC */
  3229.  
  3230. #ifdef ZFNQFP
  3231.       if ((fnp = zfnqfp(s,TMPBUFSIZ - 1,tmpbuf))) {
  3232.           if (fnp->fpath)
  3233.         if ((int) strlen(fnp->fpath) > 0)
  3234.           s = fnp->fpath;
  3235.       }
  3236.       debug(F110,"download zfnqfp",s,0);
  3237. #endif /* ZFNQFP */
  3238.  
  3239.       strcpy(line,s);        /* Make a safe copy */
  3240.       s = line;
  3241. #ifndef MAC
  3242.       if ((x = cmcfm()) < 0)    /* Get confirmation */
  3243.         return(x);
  3244. #endif /* MAC */
  3245.  
  3246. #ifdef CK_LOGIN
  3247.     if (isguest) {
  3248.         /* Don't let guests change existing files */
  3249.         printf("?This command not valid for guests\n");
  3250.         return(-9);
  3251.     }
  3252. #endif /* CK_LOGIN */
  3253.       x = strlen(line);
  3254.  
  3255. #ifdef datageneral
  3256.       if (line[x-1] == ':')        /* homdir ends in colon, */
  3257.         line[x-1] = NUL;        /* and "dir" doesn't like that... */
  3258. #endif /* datageneral */
  3259.  
  3260.           makestr(&dldir,line);
  3261.       return(success = (dldir != NULL));
  3262.       }
  3263. #endif /* CK_TMPDIR */
  3264.       case XYFILY:
  3265.     return(setdest());
  3266. #endif /* NOXFER */
  3267.  
  3268. #ifdef CK_CTRLZ
  3269.       case XYFILV: {            /* EOF */
  3270.       extern int eofmethod;
  3271.       if ((x = cmkey(eoftab,3,"end-of-file detection method","",
  3272.              xxstring)) < 0)
  3273.         return(x);
  3274.       if ((y = cmcfm()) < 0)
  3275.         return(y);
  3276.       eofmethod = x;
  3277.       return(success = 1);
  3278.       }
  3279. #endif /* CK_CTRLZ */
  3280.  
  3281. #ifndef NOXFER
  3282. #ifdef UNIX
  3283.       case XYFILH: {            /* OUTPUT */
  3284.       extern int zofbuffer, zobufsize, zofblock;
  3285. #ifdef DYNAMIC
  3286.       extern char * zoutbuffer;
  3287. #endif /* DYNAMIC */
  3288.  
  3289.       if ((x = cmkey(zoftab,nzoftab,"output file writing method","",
  3290.              xxstring)) < 0)
  3291.         return(x);
  3292.       if (x == ZOF_BUF || x == ZOF_NBUF) {
  3293.           if ((y = cmnum("output buffer size","32768",10,&z,xxstring)) < 0)
  3294.         return(y);
  3295.           if (z < 1) {
  3296.           printf("?Bad size - %d\n", z);
  3297.           return(-9);
  3298.           }
  3299.       }
  3300.       if ((y = cmcfm()) < 0) return(y);
  3301.       switch (x) {
  3302.         case ZOF_BUF:
  3303.         case ZOF_NBUF:
  3304.           zofbuffer = (x == ZOF_BUF);
  3305.           zobufsize = z;
  3306.           break;
  3307.         case ZOF_BLK:
  3308.         case ZOF_NBLK:
  3309.           zofblock = (x == ZOF_BLK);
  3310.           break;
  3311.       }
  3312. #ifdef DYNAMIC
  3313.       if (zoutbuffer) free(zoutbuffer);
  3314.       if (!(zoutbuffer = (char *)malloc(z))) {
  3315.           printf("MEMORY ALLOCATION ERROR - FATAL\n");
  3316.           doexit(BAD_EXIT,-1);
  3317.       } else
  3318.         zobufsize = z;
  3319. #else
  3320.       if (z <= OBUFSIZE) {
  3321.           zobufsize = z;
  3322.       } else {
  3323.           printf("?Sorry, %d is too big - %d is the maximum\n",z,OBUFSIZE);
  3324.           return(-9);
  3325.       }
  3326. #endif /* DYNAMIC */
  3327.       return(success = 1);
  3328.       }
  3329. #endif /* UNIX */
  3330.  
  3331. #ifdef PATTERNS
  3332.       case XYFIBP:            /* BINARY-PATTERN */
  3333.       case XYFITP: {            /* TEXT-PATTERN */
  3334.       char * tmp[FTPATTERNS];
  3335.       int i, n = 0;
  3336.       while (n < FTPATTERNS) {
  3337.           tmp[n] = NULL;
  3338.           if ((x = cmfld("Pattern","",&s,xxstring)) < 0)
  3339.         break;
  3340.           strcpy(line,s);
  3341.           s = brstrip(line);
  3342.           makestr(&(tmp[n++]),s);
  3343.       }
  3344.       if (x == -3) x = cmcfm();
  3345.       for (i = 0; i <= n; i++) {
  3346.           if (x > -1) {
  3347.           if (y == XYFIBP)
  3348.             makestr(&(binpatterns[i]),tmp[i]);
  3349.           else
  3350.             makestr(&(txtpatterns[i]),tmp[i]);
  3351.           }
  3352.           free(tmp[i]);
  3353.       }
  3354.       if (y == XYFIBP)        /* Null-terminate the list */
  3355.         makestr(&(binpatterns[i]),NULL);
  3356.       else
  3357.         makestr(&(txtpatterns[i]),NULL);
  3358.       return(x);
  3359.       }
  3360.  
  3361.       case XYFIPA:            /* PATTERNS */
  3362.     if ((x = setonaut(&patterns)) < 0)
  3363.       return(x);
  3364.     return(success = 1);
  3365. #endif /* PATTERNS */
  3366. #endif /* NOXFER */
  3367.  
  3368. #ifdef UNICODE
  3369.       case XYFILU: {            /* UCS */
  3370.       extern int ucsorder, ucsbom, byteorder;
  3371.       if ((x = cmkey(ucstab,nucstab,"","",xxstring)) < 0)
  3372.         return(x);
  3373.       switch (x) {
  3374.         case UCS_BYT:
  3375.           if ((y = cmkey(botab,nbotab,
  3376.                  "Byte order",
  3377.                  byteorder ? "little-endian" : "big-endian",
  3378.                  xxstring
  3379.                  )
  3380.            ) < 0)
  3381.         return(y);
  3382.           if ((x = cmcfm()) < 0)
  3383.         return(x);
  3384.           ucsorder = y;
  3385.           return(success = 1);
  3386.         case UCS_BOM:
  3387.           if ((y = cmkey(onoff,2,"","on",xxstring)) < 0)
  3388.         return(y);
  3389.           if ((x = cmcfm()) < 0)
  3390.         return(x);
  3391.           ucsbom = y;
  3392.           return(success = 1);
  3393.         default:
  3394.           return(-2);
  3395.       }
  3396.       }
  3397. #endif /* UNICODE */
  3398.  
  3399.       case 9997:            /* FASTLOOKUPS */
  3400.     return(success = seton(&stathack));
  3401.  
  3402.       default:
  3403.     printf("?unexpected file parameter\n");
  3404.     return(-2);
  3405.     }
  3406. }
  3407.  
  3408. #ifndef NOLOCAL
  3409. #ifdef OS2
  3410. /* MS-DOS KERMIT compatibility modes */
  3411. int
  3412. setmsk() {
  3413.     if ((y = cmkey(msktab,nmsk,"MS-DOS Kermit compatibility mode",
  3414.                     "keycodes",xxstring)) < 0) return(y);
  3415.  
  3416.     switch ( y ) {
  3417. #ifdef COMMENT
  3418.       case MSK_COLOR:
  3419.         return(seton(&mskcolors));
  3420. #endif /* COMMENT */
  3421.       case MSK_KEYS:
  3422.     return(seton(&mskkeys));
  3423.       default:                /* Shouldn't get here. */
  3424.         return(-2);
  3425.     }
  3426. }
  3427. #endif /* OS2 */
  3428.  
  3429. int
  3430. settrmtyp() {
  3431. #ifdef OS2
  3432. #ifdef TNCODE
  3433.     extern int ttnum;             /* Last Telnet Terminal Type sent */
  3434.     extern int ttnumend;         /* Has end of list been found */
  3435. #endif /* TNCODE */
  3436.     if ((x = cmkey(ttyptab,nttyp,"","vt320",xxstring)) < 0)
  3437.       return(x);
  3438.     if ((y = cmcfm()) < 0)
  3439.       return(y);
  3440.     settermtype(x,1);
  3441. #ifdef TNCODE
  3442.     /* So we send the correct terminal name to the host if it asks for it */
  3443.     ttnum = -1;                /* Last Telnet Terminal Type sent */
  3444.     ttnumend = 0;            /* end of list not found */
  3445. #endif /* TNCODE */
  3446.     return(success = 1);
  3447. #else  /* Not OS2 */
  3448.     printf(
  3449. "\n Sorry, this version of C-Kermit does not support the SET TERMINAL TYPE\n");
  3450.     printf(
  3451. " command.  Type \"help set terminal\" for further information.\n");
  3452. #endif /* OS2 */
  3453.     return(success = 0);
  3454. }
  3455.  
  3456. int
  3457. settrm() {
  3458.     int i = 0;
  3459. #ifdef OS2
  3460.     extern int colorreset, user_erasemode;
  3461. #endif /* OS2 */
  3462.     if ((y = cmkey(trmtab,ntrm,"", "",xxstring)) < 0) return(y);
  3463. #ifdef MAC
  3464.     printf("\n?Sorry, not implemented yet.  Please use the Settings menu.\n");
  3465.     return(-9);
  3466. #else
  3467. #ifdef IKSD
  3468.     if (inserver) {
  3469.     if ((y = cmcfm()) < 0) return(y);
  3470.         printf("?Sorry, command disabled.\r\n");
  3471.         return(success = 0);
  3472.     }
  3473. #endif /* IKSD */
  3474.  
  3475.     switch (y) {
  3476.       case XYTBYT:            /* SET TERMINAL BYTESIZE */
  3477.     if ((y = cmnum("bytesize for terminal connection","8",10,&x,
  3478.                xxstring)) < 0)
  3479.       return(y);
  3480.     if (x != 7 && x != 8) {
  3481.         printf("\n?The choices are 7 and 8\n");
  3482.         return(success = 0);
  3483.     }
  3484.     if ((y = cmcfm()) < 0) return(y);
  3485.     if (x == 7) cmask = 0177;
  3486.     else if (x == 8) {
  3487.         cmask = 0377;
  3488.         parity = 0;
  3489.     }
  3490. #ifdef OS2
  3491.     if (IS97801(tt_type_mode))
  3492.       SNI_bitmode(x);
  3493. #endif /* OS2 */
  3494.         return(success = 1);
  3495.  
  3496.       case XYTSO:            /* SET TERMINAL LOCKING-SHIFT */
  3497.     return(seton(&sosi));
  3498.  
  3499.       case XYTNL:            /* SET TERMINAL NEWLINE-MODE */
  3500.     return(seton(&tnlm));
  3501.  
  3502. #ifdef OS2
  3503.       case XYTCOL:
  3504.     if ((x = cmkey(ttycoltab,ncolors,"","terminal",xxstring)) < 0)
  3505.       return(x);
  3506.     else if (x == TTCOLRES) {
  3507.         if ((y = cmkey(ttcolmodetab,ncolmode,
  3508.                "","default-color",xxstring)) < 0)
  3509.           return(y);
  3510.         if ((z = cmcfm()) < 0)
  3511.           return(z);
  3512.         colorreset = y;
  3513.         return(success = 1);
  3514.     } else if (x == TTCOLERA) {
  3515.         if ((y = cmkey(ttcolmodetab,ncolmode,"",
  3516.                "current-color",xxstring)) < 0)
  3517.           return(y);
  3518.         if ((z = cmcfm()) < 0)
  3519.           return(z);
  3520.         user_erasemode = y;
  3521.         return(success=1);
  3522.     } else {            /* No parse error */
  3523.         int fg = 0, bg = 0;
  3524.         fg = cmkey(ttyclrtab, nclrs,
  3525.                (x == TTCOLBOR ?
  3526.             "color for screen border" :
  3527.             "foreground color and then background color"),
  3528.                "lgray", xxstring);
  3529.         if (fg < 0)
  3530.           return(fg);
  3531.         if (x != TTCOLBOR) {
  3532.         if ((bg = cmkey(ttyclrtab,nclrs,
  3533.                 "background color","blue",xxstring)) < 0)
  3534.           return(bg);
  3535.         }
  3536.         if ((y = cmcfm()) < 0)
  3537.           return(y);
  3538.         switch (x) {
  3539.           case TTCOLNOR:
  3540.         colornormal = fg | bg << 4;
  3541.         fgi = fg & 0x08;
  3542.         bgi = bg & 0x08;
  3543.         break;
  3544.           case TTCOLREV:
  3545.         colorreverse = fg | bg << 4;
  3546.         break;
  3547.           case TTCOLUND:
  3548.         colorunderline = fg | bg << 4;
  3549.         break;
  3550.           case TTCOLGRP:
  3551.         colorgraphic = fg | bg << 4;
  3552.         break;
  3553.           case TTCOLDEB:
  3554.         colordebug = fg | bg << 4;
  3555.         break;
  3556.           case TTCOLSTA:
  3557.         colorstatus = fg | bg << 4;
  3558.         break;
  3559.           case TTCOLHLP:
  3560.         colorhelp = fg | bg << 4;
  3561.         break;
  3562.           case TTCOLBOR:
  3563.         colorborder = fg;
  3564.         break;
  3565.           case TTCOLSEL:
  3566.         colorselect = fg | bg << 4;
  3567.         break;
  3568.           default:
  3569.         printf("%s - invalid\n",cmdbuf);
  3570.         return(-9);
  3571.         break;
  3572.         }
  3573.         scrninitialized[VTERM] = 0;
  3574.         VscrnInit(VTERM);
  3575.     }
  3576.     return(success = 1);
  3577.  
  3578.       case XYTCUR: {            /* SET TERMINAL CURSOR */
  3579.       extern int cursorena[];
  3580.           extern int cursoron[] ;       /* Cursor state on/off       */
  3581.       if ((x = cmkey(ttycurtab,ncursors,"","underline",xxstring)) < 0)
  3582.         return(x);
  3583.       if ((z = cmkey(onoff,2,"","on",xxstring)) < 0)
  3584.         return(z);
  3585.       if ((y = cmcfm()) < 0) return(y);
  3586.       tt_cursor = tt_cursor_usr = x;
  3587.       cursorena[VTERM] = tt_cursorena_usr = z;/* turn cursor on/off */
  3588.           cursoron[VTERM] = FALSE; /* Force newcursor to restore the cursor */
  3589.       return(success = 1);
  3590.       }
  3591. #endif /* OS2 */
  3592.  
  3593.       case XYTTYP:            /* SET TERMINAL TYPE */
  3594.     return(settrmtyp());
  3595.  
  3596. #ifdef OS2
  3597.       case XYTARR:            /* SET TERMINAL ARROW-KEYS */
  3598.     if ((x = cmkey(akmtab,2,"","",xxstring)) < 0) return(x);
  3599.     if ((y = cmcfm()) < 0) return(y);
  3600.     tt_arrow = x;            /* TTK_NORM / TTK_APPL; see ckuusr.h */
  3601.     return(success = 1);
  3602.  
  3603.       case XYTKPD:            /* SET TERMINAL KEYPAD-MODE */
  3604.     if ((x = cmkey(kpmtab,2,"","",xxstring)) < 0) return(x);
  3605.     if ((y = cmcfm()) < 0) return(y);
  3606.     tt_keypad = x;            /* TTK_NORM / TTK_APPL; see ckuusr.h */
  3607.     return(success = 1);
  3608.  
  3609.       case XYTUNX: {            /* SET TERM UNIX-MODE (DG) */
  3610.         extern int dgunix,dgunix_usr;
  3611.     x = seton(&dgunix);
  3612.     dgunix_usr = dgunix;
  3613.     return(x);
  3614.       }
  3615.       case XYTKBMOD: {            /* SET TERM KEYBOARD MODE */
  3616.       extern int tt_kb_mode;
  3617.       if ((x = cmkey(kbmodtab,
  3618.              nkbmodtab,
  3619.              "normal",
  3620.              "special keyboard mode for terminal emulation",
  3621.              xxstring)
  3622.            ) < 0)
  3623.         return(x);
  3624.       if ((y = cmcfm()) < 0) return(y);
  3625.       tt_kb_mode = x;
  3626.       return(success = 1);
  3627.       }
  3628.  
  3629.       case XYTWRP:            /* SET TERMINAL WRAP */
  3630.     return(seton(&tt_wrap));
  3631.  
  3632.       case XYSCRS:
  3633.     if ((y = cmnum("CONNECT scrollback buffer size, lines","2000",10,&x,
  3634.                xxstring)) < 0)
  3635.       return(y);
  3636.     /* The max number of lines is the RAM  */
  3637.     /* we can actually dedicate to a       */
  3638.     /* scrollback buffer given the maximum */
  3639.     /* process memory space of 512MB       */
  3640.     if (x < 256 || x > 2000000L) {
  3641.         printf("\n?The size must be between 256 and 2,000,000.\n");
  3642.         return(success = 0);
  3643.      }
  3644.     if ((y = cmcfm()) < 0) return(y);
  3645.     tt_scrsize[VTERM] = x;
  3646.     VscrnInit(VTERM);
  3647.     return(success = 1);
  3648. #endif /* OS2 */
  3649.  
  3650. #ifndef NOCSETS
  3651. #ifndef KUI
  3652.       case XYTCS:            /* SET TERMINAL CHARACTER-SET */
  3653.       /* set terminal character-set <remote> <local> */
  3654.     if ((x = cmkey(
  3655. #ifdef CKOUNI
  3656.                        txrtab,ntxrtab,
  3657. #else  /* CKOUNI */
  3658.                        ttcstab,ntermc,
  3659. #endif /* CKOUNI */
  3660.                "remote terminal character-set","",xxstring)) < 0)
  3661.       return(x);
  3662.     if (
  3663. #ifdef CKOUNI
  3664.             x == TX_TRANSP
  3665. #else  /* CKOUNI */
  3666.             x == FC_TRANSP
  3667. #endif /* CKOUNI */
  3668.            ) {        /* TRANSPARENT? */
  3669.         if ((x = cmcfm()) < 0) return(x); /* Confirm the command */
  3670. #ifdef CKOUNI
  3671.             tt_utf8 = 0;        /* Turn off the UTF8 flag */
  3672.         tcsr = tcsl = TX_ASCII;    /* Make them both the same */
  3673. #else /* CKOUNI */
  3674.         tcsr = tcsl = FC_USASCII;
  3675. #endif /* CKOUNI */
  3676.         tcs_transp = 1;
  3677. #ifdef OS2
  3678. #ifdef UNICODE
  3679.             dec_kbd = tcsr = tcsl = TX_TRANSP;
  3680. #else /* UNICODE */
  3681.         y = os2getcp();        /* Default is current code page */
  3682.         switch (y) {
  3683.           case 437: tcsr = tcsl = FC_CP437; break;
  3684.           case 850: tcsr = tcsl = FC_CP850; break;
  3685.           case 852: tcsr = tcsl = FC_CP852; break;
  3686.           case 862: tcsr = tcsl = FC_CP862; break;
  3687.           case 866: tcsr = tcsl = FC_CP866; break;
  3688.         }
  3689. #endif /* UNICODE */
  3690.  
  3691. #ifdef UNICODE
  3692.         if (!cs_is_nrc(tcsl)) {
  3693.         G[0].def_designation = G[0].designation = TX_ASCII;
  3694.         G[0].init = TRUE;
  3695.         G[0].def_c1 = G[0].c1 = FALSE;
  3696.         G[0].size = cs94;
  3697.         G[0].national = FALSE;
  3698.                 dec_nrc = TX_ASCII;
  3699.         } else
  3700.           dec_nrc = tcsl;
  3701.  
  3702.         for (i = cs_is_nrc(tcsl) ? 0 : 1; i < 4; i++) {
  3703.         G[i].def_designation = G[i].designation = tcsl;
  3704.         G[i].init = TRUE;
  3705.         G[i].def_c1 = G[i].c1 = FALSE;
  3706.         switch (cs_size(G[i].designation)) { /* 94, 96, or 128 */
  3707.         case 128:
  3708.         case 96:
  3709.             G[i].size = G[i].def_size = cs96;
  3710.             break;
  3711.         case 94:
  3712.             G[i].size = G[i].def_size = cs94;
  3713.             break;
  3714.         default:
  3715.             G[i].size = G[i].def_size = csmb;
  3716.             break;
  3717.         }
  3718.         G[i].national = cs_is_nrc(x);
  3719.         }
  3720. #else /* UNICODE */
  3721.         for (i = 0; i < 4; i++) {
  3722.         G[i].def_designation = G[i].designation = FC_TRANSP;
  3723.         G[i].init = FALSE;
  3724.         G[i].size = G[i].def_size = cs96;
  3725.         G[i].c1 = G[i].def_c1 = FALSE;
  3726.         G[i].national = FALSE;
  3727.         G[i].rtoi = NULL;
  3728.         G[i].itol = NULL;
  3729.         G[i].ltoi = NULL;
  3730.         G[i].itor = NULL;
  3731.             }
  3732. #endif /* UNICODE */
  3733. #endif /* OS2 */
  3734.         return(success = 1);
  3735.     }
  3736.     tcs_transp = 0;
  3737.  
  3738. #ifdef CKOUNI
  3739.     if (x == TX_UTF8) {
  3740.         if ((x = cmcfm()) < 0)    /* Confirm the command */
  3741.           return(x);
  3742.         tt_utf8 = 1;        /* Turn this on if we are UTF8 */
  3743.         return(success = 1);
  3744.     }
  3745. #endif /* CKOUNI */
  3746.  
  3747. /* Not transparent or UTF8, so get local set to translate it into */
  3748.  
  3749.     s = "";
  3750. #ifdef OS2
  3751.      y = os2getcp();            /* Default is current code page */
  3752.     switch (y) {
  3753.       case 437: s = "cp437"; break;
  3754.       case 850: s = "cp850"; break;
  3755.       case 852: s = "cp852"; break;
  3756.       case 857: s = "cp857"; break;
  3757.       case 858: s = "cp858"; break;
  3758.       case 862: s = "cp862"; break;
  3759.       case 866: s = "cp866"; break;
  3760.       case 869: s = "cp869"; break;
  3761.       case 1250: s = "cp1250"; break;
  3762.       case 1251: s = "cp1251"; break;
  3763.       case 1252: s = "cp1252"; break;
  3764.       case 1253: s = "cp1253"; break;
  3765.       case 1254: s = "cp1254"; break;
  3766.       case 1255: s = "cp1255"; break;
  3767.       case 1256: s = "cp1256"; break;
  3768.       case 1257: s = "cp1257"; break;
  3769.       case 1258: s = "cp1258"; break;
  3770.     }
  3771. #ifdef OS2ONLY
  3772. /*
  3773.    If the user has loaded a font with SET TERMINAL FONT then we want
  3774.    to change the default code page to the font that was loaded.
  3775. */
  3776.     if (tt_font != TTF_ROM) {
  3777.         for (y = 0; y < ntermfont; y++ ) {
  3778.         if (termfont[y].kwval == tt_font) {
  3779.             s = termfont[y].kwd;
  3780.             break;
  3781.         }
  3782.         }
  3783.     }
  3784. #endif /* OS2ONLY */
  3785. #else  /* Not K95... */
  3786.     s = fcsinfo[fcharset].keyword;
  3787. #endif /* OS2 */
  3788.  
  3789.     if ((y = cmkey(
  3790. #ifdef CKOUNI
  3791.                        txrtab,ntxrtab,
  3792. #else /* CKOUNI */
  3793.                        ttcstab,ntermc,
  3794. #endif /* CKOUNI */
  3795.                "local character-set",s,xxstring)) < 0)
  3796.       return(y);
  3797.  
  3798. #ifdef UNICODE
  3799.           if (y == TX_UTF8) {
  3800.               printf("?UTF8 may not be used as a local character set.\r\n");
  3801.               return(-9);
  3802.           }
  3803. #endif /* UNICODE */
  3804. #ifdef OS2
  3805.     if ((z = cmkey(graphsettab,ngraphset,
  3806.                "DEC VT intermediate graphic set","all",xxstring)) < 0)
  3807.       return(z);
  3808.     {
  3809.         int eol;
  3810.         if ((eol = cmcfm()) < 0)
  3811.           return(eol); /* Confirm the command */
  3812.     }
  3813.     tcsr = x;            /* Remote character set */
  3814.     tcsl = y;            /* Local character set */
  3815. #ifdef CKOUNI
  3816.         tt_utf8 = 0;            /* Turn off UTF8 flag */
  3817. #endif /* CKOUNI */
  3818.  
  3819.     if (z == TT_GR_ALL) {
  3820.         int i;
  3821. #ifdef UNICODE
  3822.             dec_kbd = x;
  3823. #endif /* UNICODE */
  3824.         for (i = 0; i < 4; i++) {
  3825.         G[i].def_designation = G[i].designation = x;
  3826.         G[i].init = TRUE;
  3827.         switch (cs_size(x)) {    /* 94, 96, or 128 */
  3828.           case 128:
  3829.           case 96:
  3830.             G[i].size = G[i].def_size = cs96;
  3831.             break;
  3832.           case 94:
  3833.             G[i].size = G[i].def_size = cs94;
  3834.             break;
  3835.           default:
  3836.             G[i].size = G[i].def_size = csmb;
  3837.             break;
  3838.         }
  3839.         G[i].c1 = G[i].def_c1 = x != tcsl && cs_is_std(x);
  3840.         G[i].national = cs_is_nrc(x);
  3841.             }
  3842.         if (!cs_is_nrc(x)) {
  3843.         G[0].designation = G[0].def_designation = FC_USASCII;
  3844.         G[0].size = G[0].def_size = cs94;
  3845.             }
  3846. #ifdef UNICODE
  3847.         } else if (z == TT_GR_KBD) {    /* Keyboard only */
  3848.             dec_kbd = x;
  3849. #endif /* UNICODE */
  3850.         } else {            /* Specific Gn */
  3851.         G[z].def_designation = G[z].designation = x;
  3852.         G[z].init = TRUE;
  3853.         switch (cs_size(x)) {    /* 94, 96, or 128 */
  3854.           case 128:
  3855.           case 96:
  3856.         G[i].size = G[i].def_size = cs96;
  3857.         break;
  3858.           case 94:
  3859.         G[i].size = G[i].def_size = cs94;
  3860.         break;
  3861.           default:
  3862.         G[i].size = G[i].def_size = csmb;
  3863.         break;
  3864.         }
  3865.         G[i].c1 = G[i].def_c1 = x != tcsl && cs_is_std(x);
  3866.         G[i].national = cs_is_nrc(x);
  3867.         }
  3868. #else /* not OS2 */
  3869.     if ((z = cmcfm()) < 0) return(z); /* Confirm the command */
  3870.     tcsr = x;            /* Remote character set */
  3871.     tcsl = y;            /* Local character set */
  3872. #endif /* OS2 */
  3873.     return(success = 1);
  3874. #endif /* UNICODE */
  3875. #endif /* NOCSETS */
  3876.  
  3877. #ifndef NOCSETS
  3878.       case XYTLCS:            /* SET TERMINAL LOCAL-CHARACTER-SET */
  3879.     /* set terminal character-set <local> */
  3880.     s = "";
  3881. #ifdef OS2
  3882.      y = os2getcp();            /* Default is current code page */
  3883.     switch (y) {
  3884.       case 437: s = "cp437"; break;
  3885.       case 850: s = "cp850"; break;
  3886.       case 852: s = "cp852"; break;
  3887.       case 857: s = "cp857"; break;
  3888.       case 858: s = "cp858"; break;
  3889.       case 862: s = "cp862"; break;
  3890.       case 866: s = "cp866"; break;
  3891.       case 869: s = "cp869"; break;
  3892.       case 1250: s = "cp1250"; break;
  3893.       case 1251: s = "cp1251"; break;
  3894.       case 1252: s = "cp1252"; break;
  3895.       case 1253: s = "cp1253"; break;
  3896.       case 1254: s = "cp1254"; break;
  3897.       case 1255: s = "cp1255"; break;
  3898.       case 1256: s = "cp1256"; break;
  3899.       case 1257: s = "cp1257"; break;
  3900.       case 1258: s = "cp1258"; break;
  3901.     }
  3902. #ifdef OS2ONLY
  3903. /*
  3904.    If the user has loaded a font with SET TERMINAL FONT then we want
  3905.    to change the default code page to the font that was loaded.
  3906. */
  3907.     if (tt_font != TTF_ROM) {
  3908.         for (y = 0; y < ntermfont; y++ ) {
  3909.         if (termfont[y].kwval == tt_font) {
  3910.             s = termfont[y].kwd;
  3911.             break;
  3912.         }
  3913.         }
  3914.     }
  3915. #endif /* OS2ONLY */
  3916. #else /* OS2 */
  3917.                     /* Make current file char set */
  3918.     for (y = 0; y <= nfilc; y++)    /* be the default... */
  3919.       if (fcstab[y].kwval == fcharset) {
  3920.           s = fcstab[y].kwd;
  3921.           break;
  3922.       }
  3923. #endif /* OS2 */
  3924.     if ((y = cmkey(
  3925. #ifdef CKOUNI
  3926.                        txrtab,ntxrtab,
  3927. #else /* CKOUNI */
  3928.                        fcstab,nfilc,
  3929. #endif /* CKOUNI */
  3930.                "local character-set",s,xxstring)) < 0)
  3931.       return(y);
  3932.  
  3933. #ifdef UNICODE
  3934.           if (y == TX_UTF8) {
  3935.               printf("?UTF8 may not be used as a local character set.\r\n");
  3936.               return(-9);
  3937.           }
  3938. #endif /* UNICODE */
  3939.  
  3940. #ifdef OS2
  3941.         if ((z = cmcfm()) < 0) return(z); /* Confirm the command */
  3942.     tcsl = y;            /* Local character set */
  3943.     {
  3944.         int i;
  3945.         for (i = 0; i < 4; i++) {
  3946.         G[i].init = TRUE;
  3947.         x = G[i].designation;
  3948.         G[i].c1 = (x != tcsl) && cs_is_std(x);
  3949.         x = G[i].def_designation;
  3950.         G[i].def_c1 = (x != tcsl) && cs_is_std(x);
  3951.             }
  3952.         }
  3953. #else /* not OS2 */
  3954.     if ((z = cmcfm()) < 0) return(z); /* Confirm the command */
  3955.     tcsl = y;            /* Local character set */
  3956. #endif /* OS2 */
  3957.     return(success = 1);
  3958. #endif /* NOCSETS */
  3959.  
  3960. #ifndef NOCSETS
  3961. #ifdef UNICODE
  3962.       case XYTUNI:            /* SET TERMINAL UNICODE */
  3963.     return(seton(&tt_unicode));
  3964. #endif /* UNICODE */
  3965.  
  3966.       case XYTRCS:            /* SET TERMINAL REMOTE-CHARACTER-SET */
  3967.     /* set terminal character-set <remote> <Graphic-set> */
  3968.     if ((x = cmkey(
  3969. #ifdef CKOUNI
  3970.                 txrtab, ntxrtab,
  3971. #else /* CKOUNI */
  3972.                 ttcstab,ntermc,
  3973. #endif /* CKOUNI */
  3974.                "remote terminal character-set","",xxstring)) < 0)
  3975.       return(x);
  3976.  
  3977.     /* KUI can't have a Transparent Character Set */
  3978. #ifdef UNICODE
  3979.     if (x == TX_TRANSP)
  3980. #else /* UNICODE */
  3981.     if (x == FC_TRANSP)
  3982. #endif /* UNICODE */
  3983.       {                /* TRANSPARENT? */
  3984.           if ((x = cmcfm()) < 0)    /* Confirm the command */
  3985.         return(x);
  3986. #ifndef OS2
  3987.           tcsr = tcsl;        /* Make both sets the same */
  3988. #else
  3989. #ifdef CKOUNI
  3990.               tt_utf8 = 0;        /* Turn off UTF8 flag */
  3991.               tcsr = tcsl = dec_kbd = TX_TRANSP; /* No translation */
  3992.  
  3993.           if (!cs_is_nrc(tcsl)) {
  3994.           G[0].def_designation = G[i].designation = TX_ASCII;
  3995.           G[0].init = TRUE;
  3996.           G[0].def_c1 = G[i].c1 = FALSE;
  3997.           G[0].size = cs94;
  3998.           G[0].national = FALSE;
  3999.           }
  4000.           for (i = cs_is_nrc(tcsl) ? 0 : 1; i < 4; i++) {
  4001.           G[i].def_designation = G[i].designation = tcsl;
  4002.           G[i].init = TRUE;
  4003.           G[i].def_c1 = G[i].c1 = FALSE;
  4004.           switch (cs_size(G[i].designation)) { /* 94, 96, or 128 */
  4005.             case 128:
  4006.             case 96:
  4007.               G[i].size = G[i].def_size = cs96;
  4008.               break;
  4009.             case 94:
  4010.               G[i].size = G[i].def_size = cs94;
  4011.               break;
  4012.             default:
  4013.               G[i].size = G[i].def_size = csmb;
  4014.               break;
  4015.           }
  4016.           G[i].national = cs_is_nrc(x);
  4017.           }
  4018. #else /* CKOUNI */
  4019.           tcsr = tcsl;        /* Make both sets the same */
  4020.           for (i = 0; i < 4; i++) {
  4021.           G[i].def_designation = G[i].designation = FC_TRANSP;
  4022.           G[i].init = FALSE;
  4023.           G[i].size = G[i].def_size = cs96;
  4024.           G[i].c1 = G[i].def_c1 = FALSE;
  4025.           G[i].rtoi = NULL;
  4026.           G[i].itol = NULL;
  4027.           G[i].ltoi = NULL;
  4028.           G[i].itor = NULL;
  4029.           G[i].national = FALSE;
  4030.           }
  4031. #endif /* CKOUNI */
  4032. #endif /* OS2 */
  4033.           return(success = 1);
  4034.       }
  4035.  
  4036. #ifdef CKOUNI
  4037.     if (x == TX_UTF8) {
  4038.         if ((x = cmcfm()) < 0) return(x); /* Confirm the command */
  4039.         tt_utf8 = 1;        /* Turn it on if we are UTF8 */
  4040.         return(success = 1);
  4041.     }
  4042. #endif /* CKOUNI */
  4043.  
  4044. #ifdef OS2
  4045.     if ((z = cmkey(graphsettab,ngraphset,
  4046.                "DEC VT intermediate graphic set","all",xxstring)) < 0)
  4047.       return(z);
  4048.     {
  4049.         int eol;
  4050.         if ((eol = cmcfm()) < 0)    /* Confirm the command */
  4051.           return(eol);
  4052.     }
  4053.     tcsr = x;            /* Remote character set */
  4054. #ifdef CKOUNI
  4055.     tt_utf8 = 0;            /* Turn off UTF8 flag */
  4056. #endif /* CKOUNI */
  4057.  
  4058.     if (z == TT_GR_ALL) {
  4059.         int i;
  4060. #ifdef UNICODE
  4061.             dec_kbd = x;
  4062. #endif /* UNICODE */
  4063.         for (i = 0; i < 4; i++) {
  4064.         G[i].def_designation = G[i].designation = x;
  4065.         G[i].init = TRUE;
  4066.         switch (cs_size(x)) {    /* 94, 96, or 128 */
  4067.           case 128:
  4068.           case 96:
  4069.             G[i].size = G[i].def_size = cs96;
  4070.             break;
  4071.           case 94:
  4072.             G[i].size = G[i].def_size = cs94;
  4073.             break;
  4074.           default:
  4075.             G[i].size = G[i].def_size = csmb;
  4076.             break;
  4077.         }
  4078.         G[i].c1 = G[i].def_c1 = x != tcsl && cs_is_std(x);
  4079.         G[i].national = cs_is_nrc(x);
  4080.             }
  4081.         if (!cs_is_nrc(x)) {
  4082.         G[0].designation = G[0].def_designation = FC_USASCII;
  4083.         G[0].size = G[0].def_size = cs94;
  4084.             }
  4085. #ifdef UNICODE
  4086.         } else if (z == TT_GR_KBD) {    /* Keyboard only */
  4087.             dec_kbd = x;
  4088. #endif /* UNICODE */
  4089.         } else {            /* Specific Gn */
  4090.         G[z].def_designation = G[z].designation = x;
  4091.         G[z].init = TRUE;
  4092.         switch (cs_size(x)) {    /* 94, 96, or 128 */
  4093.           case 128:
  4094.           case 96:
  4095.         G[i].size = G[i].def_size = cs96;
  4096.         break;
  4097.           case 94:
  4098.         G[i].size = G[i].def_size = cs94;
  4099.         break;
  4100.           default:
  4101.         G[i].size = G[i].def_size = csmb;
  4102.         break;
  4103.         }
  4104.         G[z].c1 = G[z].def_c1 = x != tcsl && cs_is_std(x);
  4105.         G[z].national = cs_is_nrc(x);
  4106.         }
  4107. #else /* not OS2 */
  4108.     if ((z = cmcfm()) < 0) return(z); /* Confirm the command */
  4109.     tcsr = x;            /* Remote character set */
  4110. #endif /* OS2 */
  4111.     return(success = 1);
  4112. #endif /* NOCSETS */
  4113.  
  4114.       case XYTEC:            /* SET TERMINAL ECHO */
  4115.     if ((x = cmkey(rltab,nrlt,"which side echos during CONNECT",
  4116.                "remote", xxstring)) < 0) return(x);
  4117.     if ((y = cmcfm()) < 0) return(y);
  4118.     duplex = x;
  4119.     return(success = 1);
  4120.  
  4121.       case XYTESC:            /* SET TERM ESC */
  4122.     if ((x = cmkey(nabltab,nnabltab,"","enabled",xxstring)) < 0)
  4123.       return(x);
  4124.     if ((y = cmcfm()) < 0) return(y);
  4125.     tt_escape = x;
  4126.     return(1);
  4127.  
  4128.       case XYTCRD:            /* SET TERMINAL CR-DISPLAY */
  4129.     if ((x = cmkey(crdtab,2,"", "normal", xxstring)) < 0) return(x);
  4130.     if ((y = cmcfm()) < 0) return(y);
  4131.     tt_crd = x;
  4132.     return(success = 1);
  4133.  
  4134. #ifdef OS2
  4135.       case XYTANS: {            /* SET TERMINAL ANSWERBACK */
  4136. /*
  4137.   NOTE: We let them enable and disable the answerback sequence, but we
  4138.   do NOT let them change it, and we definitely do not let the host set it.
  4139.   This is a security feature.
  4140.  
  4141.   As of 1.1.8 we allow the SET TERM ANSWERBACK MESSAGE <string> to be
  4142.   used just as MS-DOS Kermit does.  C0 and C1 controls as well as DEL
  4143.   are not allowed to be used as characters.  They are translated to
  4144.   underscore.  This may not be set by APC.
  4145. */
  4146.       if ((x = cmkey(anbktab,nansbk,"", "off", xxstring)) < 0)
  4147.         return(x);
  4148.       if (x < 2) {
  4149.           if ((y = cmcfm()) < 0)
  4150.         return(y);
  4151.           tt_answer = x;
  4152.           return(success = 1);
  4153.       } else if ( x == 2 || x == 3) {
  4154.           int len = 0;
  4155.           extern int safeanswerbk;
  4156.           extern char useranswerbk[];
  4157.           if ((y = cmtxt("Answerback extension","",&s,xxstring)) < 0)
  4158.         return(y);
  4159.           if (apcactive == APC_LOCAL ||
  4160.           (apcactive == APC_REMOTE && apcstatus != APC_UNCH))
  4161.         return(success = 0);
  4162.           len = strlen(s);
  4163.           if (x == 2) {
  4164.           /* Safe Answerback's don't have C0/C1 chars */
  4165.           for (z = 0; z < len; z++) {
  4166.               if ((s[z] & 0x7F) <= SP || (s[z] & 0x7F) == DEL)
  4167.             useranswerbk[z] = '_';
  4168.               else
  4169.             useranswerbk[z] = s[z];
  4170.           }
  4171.           useranswerbk[z] = '\0';
  4172.           safeanswerbk = 1 ;    /* TRUE */
  4173.           } else {
  4174.           ckstrncpy(useranswerbk,s,60);    /* (see ckocon.c) */
  4175.           safeanswerbk = 0;    /* FALSE */
  4176.           }
  4177.           updanswerbk();
  4178.           return(success = 1);
  4179.       } else
  4180.         return(success = 0);
  4181.       }
  4182. #endif /* OS2 */
  4183.  
  4184. #ifdef CK_APC
  4185.       case XYTAPC:
  4186.     if ((y = cmkey(apctab,3,"application program command execution","",
  4187.                xxstring)) < 0)
  4188.       return(y);
  4189.     if ((x = cmcfm()) < 0)
  4190.       return(x);
  4191.     if (apcactive == APC_LOCAL ||
  4192.         (apcactive == APC_REMOTE && apcstatus != APC_UNCH))
  4193.       return(success = 0);
  4194.     apcstatus = y;
  4195.     return(success = 1);
  4196.  
  4197. #ifdef CK_AUTODL
  4198.       case XYTAUTODL:            /* AUTODOWNLOAD */
  4199. #ifndef OS2
  4200.     x = seton(&autodl);        /* For C-Kermit: ON, OFF, AUTO */
  4201.     if (x > 0)
  4202.       success = 1;
  4203.     return(x);
  4204. #else /* OS2 */
  4205.     if ((y = cmkey(adltab,nadltab,"Auto-download options","",
  4206.                xxstring)) < 0)
  4207.       return(y);
  4208.     switch (y) {
  4209.       case TAD_ON:
  4210.       case TAD_OFF:
  4211.         if ((x = cmcfm()) < 0)
  4212.           return(x);
  4213.         autodl = y;
  4214.         break;
  4215.       case TAD_K:
  4216.         if ((y = cmkey(adlxtab,nadlxtab,"","", xxstring)) < 0)
  4217.           return(y);
  4218.         switch (y) {
  4219.           case TAD_X_C0:
  4220.         if ((y = cmkey(adlc0tab,nadlc0tab,"",
  4221.                    "processed-by-emulator",xxstring)) < 0)
  4222.           return(y);
  4223.         if ((x = cmcfm()) < 0)
  4224.           return(x);
  4225.         adl_kc0 = y;
  4226.         break;
  4227.           case TAD_X_DETECT:
  4228.         if ((y = cmkey(adldtab,nadldtab,"","packet",xxstring)) < 0)
  4229.           return(y);
  4230.         if ((x = cmcfm()) < 0)
  4231.           return(x);
  4232.         adl_kmode = y;
  4233.         break;
  4234.           case TAD_X_STR:
  4235.         if ((y = cmtxt("Kermit start string","KERMIT READY TO SEND...",
  4236.                    &s,xxstring)) < 0)
  4237.           return(y);
  4238.         free(adl_kstr);
  4239.         adl_kstr = strdup(s);
  4240.         break;
  4241.         }
  4242.         break;
  4243.  
  4244.       case TAD_Z:
  4245.         if ((y = cmkey(adlxtab,nadlxtab,"","",xxstring)) < 0)
  4246.           return(y);
  4247.         switch (y) {
  4248.           case TAD_X_C0:
  4249.         if ((y = cmkey(adlc0tab,nadlc0tab,"",
  4250.                    "processed-by-emulator",xxstring)) < 0)
  4251.           return(y);
  4252.         if ((x = cmcfm()) < 0)
  4253.           return(x);
  4254.         adl_zc0 = y;
  4255.         break;
  4256.           case TAD_X_DETECT:
  4257.         if ((y = cmkey(adldtab,nadldtab,"","packet",xxstring)) < 0)
  4258.           return(y);
  4259.         if ((x = cmcfm()) < 0)
  4260.           return(x);
  4261.         adl_zmode = y;
  4262.         break;
  4263.           case TAD_X_STR:
  4264.         if ((y = cmtxt("","rz\\{13}",&s,xxstring)) < 0)
  4265.           return(y);
  4266.         free(adl_zstr);
  4267.         adl_zstr = strdup(s);
  4268.         break;
  4269.         }
  4270.         break;
  4271.     }
  4272.     return(success = 1);
  4273. #endif /* OS2 */
  4274. #endif /* CK_AUTODL */
  4275. #endif /* CK_APC */
  4276.  
  4277. #ifdef OS2
  4278.       case XYTBEL:
  4279.         return(success = setbell());
  4280.  
  4281.       case XYTMBEL:            /* MARGIN-BELL */
  4282.     if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  4283.     if (y) {            /* ON */
  4284.         if ((z = cmnum("Column at which to set margin bell",
  4285.                "72",10,&x,xxstring)) < 0)
  4286.           return(z);
  4287.     }
  4288.     if ((z = cmcfm()) < 0) return(z);
  4289.     marginbell = y;
  4290.     marginbellcol = x;
  4291.     return(success = 1);
  4292.  
  4293.       case XYTIDLE:            /* IDLE-SEND */
  4294.     if ((z = cmnum("seconds of idle time to wait, or 0 to disable",
  4295.                "0",10,&x,xxstring)) < 0)
  4296.       return(z);
  4297.     if ((y = cmtxt("string to send, may contain kverbs and variables",
  4298.                "\\v(newline)",&s,xxstring)) < 0)
  4299.       return(y);
  4300.     tt_idlesnd_tmo = x;
  4301.     if (tt_idlesnd_str) {
  4302.         free(tt_idlesnd_str);
  4303.         tt_idlesnd_str = NULL;
  4304.     }
  4305.     s = brstrip(s);
  4306.     tt_idlesnd_str = strdup(s);
  4307.     puterror(VTERM);
  4308.     return(success = 1);
  4309. #endif /* OS2 */
  4310.  
  4311.       case XYTDEB:            /* TERMINAL DEBUG */
  4312.     x = debses;            /* What it was before */
  4313.     y = seton(&debses);        /* Go parse ON or OFF */
  4314. #ifdef OS2
  4315.     if (y > 0)            /* Command succeeded? */
  4316.       if ((x != 0) && (debses == 0)) /* It was on and we turned it off? */
  4317.         os2debugoff();        /* Fix OS/2 coloration */
  4318. #endif /* OS2 */
  4319.     return(y);
  4320.  
  4321. #ifdef OS2
  4322.       case XYTASCRL:                    /* SET TERMINAL AUTOSCROLL */
  4323.           y = seton(&autoscroll);
  4324.           return(y);
  4325.  
  4326.       case XYTAPAGE:                    /* SET TERMINAL AUTOPAGE */
  4327.           y = seton(&wy_autopage);
  4328.           return(y);
  4329.  
  4330.       case XYTROL:            /* SET TERMINAL ROLL */
  4331.         if ((y = cmkey(rolltab,nroll,"scrollback mode","insert",xxstring))<0)
  4332.             return(y);
  4333.         if ((x = cmcfm()) < 0) return(x);
  4334.         tt_roll[VTERM] = y;
  4335.     return(success = 1);
  4336.  
  4337.       case XYTCTS:            /* SET TERMINAL TRANSMIT-TIMEOUT */
  4338.     y = cmnum("Maximum seconds to allow CTS off during CONNECT",
  4339.           "5",10,&x,xxstring);
  4340.     return(setnum(&tt_ctstmo,x,y,10000));
  4341.  
  4342.       case XYTCPG: {            /* SET TERMINAL CODE-PAGE */
  4343.         int i;
  4344.     int cp = -1;
  4345.     y = cmnum("PC code page to use during terminal emulation",
  4346.           "850",10,&x,xxstring);
  4347.     if ((x = setnum(&cp,x,y,11000)) < 0) return(x);
  4348.     if (os2setcp(cp) != 1) {
  4349. #ifdef NT
  4350.         if (isWin95())
  4351.           printf(
  4352.          "Sorry, Windows 95 does not support code page switching\n");
  4353.         else
  4354. #endif /* NT */
  4355.           printf(
  4356.          "Sorry, %d is not a valid code page for this system.\n",cp);
  4357.         return(-9);
  4358.     }
  4359.     /* Force the terminal character-sets conversions to be updated */
  4360.     for ( i = 0; i < 4; i++ )
  4361.       G[i].init = TRUE;
  4362.     return(1);
  4363.     }
  4364.  
  4365.       case XYTPAC:            /* SET TERMINAL OUTPUT-PACING */
  4366.     y = cmnum(
  4367.        "Pause between sending each character during CONNECT, milliseconds",
  4368.           "-1",10,&x,xxstring);
  4369.     return(setnum(&tt_pacing,x,y,10000));
  4370.  
  4371. #ifdef OS2MOUSE
  4372.       case XYTMOU: {            /* SET TERMINAL MOUSE */
  4373.       int old_mou = tt_mouse;
  4374.       if ((x = seton(&tt_mouse)) < 0)
  4375.         return(x);
  4376.       if (tt_mouse != old_mou)
  4377.         if (tt_mouse)
  4378.           os2_mouseon();
  4379.         else
  4380.           os2_mouseoff();
  4381.       return(1);
  4382.       }
  4383. #endif /* OS2MOUSE */
  4384. #endif /* OS2 */
  4385.  
  4386.       case XYTWID: {
  4387.       if ((y = cmnum(
  4388. #ifdef OS2
  4389.              "number of columns in display window during CONNECT",
  4390. #else
  4391.              "number of columns on your screen",
  4392. #endif /* OS2 */
  4393.              "80",10,&x,xxstring)) < 0)
  4394.             return(y);
  4395.           if ((y = cmcfm()) < 0) return(y);
  4396. #ifdef OS2
  4397.       if (x % 2) {
  4398.           printf("\n?The width must be an even value\n.");
  4399.           return(success = 0);
  4400.       }
  4401.  
  4402.       if ( IsOS2FullScreen() ) {
  4403.           if ( x != 40 && x != 80 && x != 132 ) {
  4404.           printf("\n?The width must be 40, 80,");
  4405. #ifdef NT
  4406.           printf(" or 132 under Windows 95.\n.");
  4407. #else /* NT */
  4408.           printf(" or 132 in a Full Screen session.\n.");
  4409. #endif /* NT */
  4410.           return(success = 0);
  4411.           }
  4412.       } else {
  4413.           if ( !IsWARPed() && x != 80 ) {
  4414.           printf("\n?OS/2 version is pre-WARP: the width must equal ");
  4415.           printf("80 in a Windowed Session\n.");
  4416.           return(success = 0);
  4417.                 }
  4418.           if (x < 20 || x > MAXTERMCOL ) {
  4419.           printf(
  4420.             "\n?The width must be between 20 and %d\n.",MAXTERMCOL);
  4421.           return(success = 0);
  4422.           }
  4423.       }
  4424.       if (x > 8192/(tt_rows[VTERM]+1)) {
  4425.           printf(
  4426. "\n?The max screen area is 8192 cells: %d(rows) x %d(cols) = %d cells.\n",
  4427.              tt_rows[VTERM]+1,x,x*(tt_rows[VTERM]+1));
  4428.           return(success = 0);
  4429.       }
  4430.       tt_cols[VTERM] = x;
  4431.       tt_cols_usr = x;
  4432.       VscrnSetWidth( VTERM, x);
  4433. #ifdef TNCODE
  4434.       if (TELOPT_ME(TELOPT_NAWS))
  4435.         tn_snaws();
  4436. #endif /* TNCODE */
  4437. #ifdef RLOGCODE
  4438.       if (TELOPT_ME(TELOPT_NAWS))
  4439.         rlog_naws();
  4440. #endif /* RLOGCODE */
  4441.  
  4442. /*
  4443.    We do not set tt_szchng here because that would result in the screen buffer
  4444.    being reallocated and the screen cleared.  But that is not necessary when
  4445.    only the screen width is being changed since the buffer allocates the full
  4446.    width
  4447. */
  4448. #else  /* Not OS/2 */
  4449.       tt_cols = x;
  4450. #endif /* OS2 */
  4451.       return(success = 1);
  4452.       }
  4453.  
  4454.       case XYTHIG:
  4455.        if ((y = cmnum(
  4456. #ifdef OS2
  4457.  "number of rows in display window during CONNECT, not including status line",
  4458.  tt_status?"24":"25",
  4459. #else
  4460.  "24","number of rows on your screen",
  4461. #endif /* OS2 */
  4462.                10,&x,xxstring)) < 0)
  4463.       return(y);
  4464.     if ((y = cmcfm()) < 0) return(y);
  4465.  
  4466. #ifdef OS2
  4467.     if (tt_modechg == TVC_DIS) {
  4468.         printf("\n?SET TERMINAL VIDEO-CHANGE DISABLED\n");
  4469.         return(success = 0);
  4470.     }
  4471.     if (IsOS2FullScreen()) {
  4472.             if (tt_status && x != 24 && x != 42 && x != 49 && x != 59) {
  4473.                 printf("\n?The height must be 24, 42, 49");
  4474. #ifdef NT
  4475.                 printf(" or 59 under Windows 95.\n.");
  4476. #else /* NT */
  4477.                 printf(" or 59 in a Full Screen session.\n.");
  4478. #endif /* NT */
  4479.                 return(success = 0);
  4480.         } else if (!tt_status &&
  4481.                x != 25 &&
  4482.                x != 43 &&
  4483.                x != 50) {
  4484.                 printf("\n?The height must be 25, 43, 50");
  4485. #ifdef NT
  4486.                 printf(" or 60 under Windows 95.\n.");
  4487. #else /* NT */
  4488.                 printf(" or 60 in a Full Screen session.\n.");
  4489. #endif /* NT */
  4490.                 return(success = 0);
  4491.         }
  4492.     } else if (tt_modechg == TVC_W95) {
  4493.             if (tt_status && x != 24 && x != 42 && x != 49) {
  4494.                 printf("\n?The height must be 24, 42, 49");
  4495. #ifdef NT
  4496.                 printf(" under Windows 95.\n.");
  4497. #else /* NT */
  4498.                 printf(" in a Full Screen session.\n.");
  4499. #endif /* NT */
  4500.                 return(success = 0);
  4501.         } else if (!tt_status &&
  4502.                x != 25 &&
  4503.                x != 43 &&
  4504.                x != 50) {
  4505.                 printf("\n?The height must be 25, 43, 50");
  4506. #ifdef NT
  4507.                 printf(" under Windows 95.\n.");
  4508. #else /* NT */
  4509.                 printf(" in a Full Screen session.\n.");
  4510. #endif /* NT */
  4511.                 return(success = 0);
  4512.         }
  4513.     } else {
  4514.             if (x < 8 || x > MAXTERMROW ) {
  4515.                 printf("\n?The height must be between 8 and %d\n.",MAXTERMROW);
  4516.                 return(success = 0);
  4517.         }
  4518.     }
  4519.         if (x > 8192/tt_cols[VTERM]) {
  4520.             printf(
  4521.  "\n?The max screen area is 8192 cells: %d(rows) x %d(cols) = %d cells.\n",
  4522.            x,tt_cols[VTERM],x*tt_cols[VTERM]);
  4523.             return(success = 0);
  4524.     }
  4525.         tt_szchng[VTERM] = 1;
  4526.         tt_rows[VTERM] = x;
  4527.         VscrnInit( VTERM );        /* Height set here */
  4528. #ifdef TNCODE
  4529.       if (TELOPT_ME(TELOPT_NAWS))
  4530.         tn_snaws();
  4531. #endif /* TNCODE */
  4532. #ifdef RLOGCODE
  4533.       if (TELOPT_ME(TELOPT_NAWS))
  4534.         rlog_naws();
  4535. #endif /* RLOGCODE */
  4536. #else  /* Not OS/2 */
  4537.     tt_rows = x;
  4538. #endif /* OS2 */
  4539.         return(success = 1);
  4540.  
  4541. #ifdef OS2
  4542.       case XYTPRN: {            /* Print Mode */
  4543.       extern bool xprint, cprint, aprint, uprint;
  4544.       if ((y = cmkey(prnmtab,nprnmtab,"","off", xxstring)) < 0) return(y);
  4545.       if ((x = cmcfm()) < 0) return(x);
  4546.       switch (y) {
  4547.         case 0:
  4548.           if (cprint || uprint || aprint || xprint)
  4549.                 printeroff();
  4550.           cprint = xprint = uprint = aprint = 0;
  4551.           break;
  4552.         case 1:
  4553.           if (!(cprint || uprint || aprint || xprint))
  4554.                 printeron();
  4555.           aprint = 1;
  4556.           cprint = xprint = uprint = 0;
  4557.           break;
  4558.         case 2:
  4559.           if (!(cprint || uprint || aprint || xprint))
  4560.                 printeron();
  4561.           cprint = 1;
  4562.           aprint = xprint = uprint = 0;
  4563.           break;
  4564.         case 3:
  4565.           if (!(cprint || uprint || aprint || xprint))
  4566.                 printeron();
  4567.           uprint = 1;
  4568.           aprint = xprint = cprint = 0;
  4569.           break;
  4570.       }
  4571.       return(1);
  4572.       }
  4573. #else
  4574. #ifdef XPRINT
  4575.       case XYTPRN: {
  4576.       extern int tt_print;
  4577.       if ((x = seton(&tt_print)) < 0)
  4578.         return(x);
  4579.       return(success = 1);
  4580.       }
  4581. #endif /* XPRINT */
  4582. #endif /* OS2 */
  4583.  
  4584. #ifdef OS2
  4585.       case XYTSCNM: {
  4586.       extern int decscnm, decscnm_usr;
  4587.       if ((y = cmkey(normrev,4,"",
  4588.              decscnm_usr?"reverse":"normal",
  4589.              xxstring)
  4590.            ) < 0)
  4591.         return(y);
  4592.       if ((x = cmcfm()) < 0) return(x);
  4593.       decscnm_usr = y;
  4594.       if (decscnm != decscnm_usr)
  4595.             flipscreen(VTERM);
  4596.       return(1);
  4597.     }
  4598.     case XYTOPTI:
  4599.         if ((y = cmkey(onoff,2,"",tt_diff_upd?"on":"off",
  4600.                         xxstring)) < 0) return(y);
  4601.         if ((x = cmcfm()) < 0) return(x);
  4602.         tt_diff_upd = y;
  4603.         return(1);
  4604.     case XYTUPD: {
  4605.     int mode, delay;
  4606.     if ((mode = cmkey(scrnupd,nscrnupd,"","fast",xxstring)) < 0) {
  4607.         return(mode);
  4608.         } else {
  4609.         y = cmnum(
  4610.         "Pause between FAST screen updates in CONNECT mode, milliseconds",
  4611.               "100",10,&x,xxstring
  4612.               );
  4613.         if (x < 0 || x > 1000 ) {
  4614.         printf(
  4615.         "\n?The update rate must be between 0 and 1000 milliseconds.\n"
  4616.                );
  4617.         return(success = 0);
  4618.             }
  4619.             if ((y = cmcfm()) < 0) return(y);
  4620.  
  4621.         updmode = tt_updmode = mode;
  4622.         return(setnum(&tt_update,x,y,10000));
  4623.     }
  4624.     }
  4625.     case XYTCTRL:
  4626.       if ((x = cmkey(termctrl,ntermctrl,"","7",xxstring)) < 0) {
  4627.           return(x);
  4628.       } else {
  4629.           if ((y = cmcfm()) < 0)
  4630.           return(y);
  4631.           switch ( x ) {
  4632.           case 8:
  4633.           send_c1 = send_c1_usr = TRUE;
  4634.           break;
  4635.           case 7:
  4636.           default:
  4637.           send_c1 = send_c1_usr = FALSE;
  4638.           break;
  4639.           }
  4640.       }
  4641.       return(success = TRUE);
  4642.       break;
  4643.  
  4644. #ifdef PCFONTS
  4645.       case XYTFON:
  4646.     if ( !IsOS2FullScreen() ) {
  4647.         printf(
  4648.         "\n?SET TERMINAL FONT is only supported in Full Screen sessions.\n");
  4649.         return(success = FALSE);
  4650.         }
  4651.  
  4652.     if ((x = cmkey(termfont,ntermfont,"","default",xxstring)) < 0) {
  4653.             return(x);
  4654.         } else {
  4655.         if ((y = cmcfm()) < 0) return(y);
  4656.             if ( !os2LoadPCFonts() ) {
  4657.                 tt_font = x;
  4658.         return(success = TRUE);
  4659.         } else {
  4660.         printf(
  4661.       "\n?PCFONTS.DLL is not available in CKERMIT executable directory.\n");
  4662.                 return(success = FALSE);
  4663.         }
  4664.     }
  4665.     break;
  4666. #endif /* PCFONTS */
  4667.       case XYTVCH: {
  4668.       extern int pheight, marginbot, cmd_rows, cmd_cols;
  4669.       if ((x = cmkey(tvctab,ntvctab,"",isWin95()?"win95-safe":"enabled",
  4670.              xxstring)) < 0)
  4671.         return(x);
  4672.       if ((y = cmcfm()) < 0) return(y);
  4673.       if (x != tt_modechg) {
  4674.           switch (x) {
  4675.         case TVC_DIS:
  4676.           /* When disabled the heights of all of the virtual screens */
  4677.           /* must be equal to the physical height of the console     */
  4678.           /* window and may not be changed.                          */
  4679.           /* The width of the window may not be altered.             */
  4680.           tt_modechg = TVC_ENA;            /* Termporary */
  4681.           if (marginbot > pheight-(tt_status?1:0))
  4682.             marginbot = pheight-(tt_status?1:0);
  4683.           tt_szchng[VCMD] = 1 ;
  4684.           tt_rows[VCMD] = pheight;
  4685.           VscrnInit(VCMD);
  4686.           SetCols(VCMD);
  4687.           cmd_rows = y;
  4688.  
  4689.           tt_szchng[VTERM] = 2 ;
  4690.           tt_rows[VTERM] = pheight - (tt_status?1:0);
  4691.           VscrnInit(VTERM);
  4692.  
  4693.           break;
  4694.  
  4695.         case TVC_ENA:
  4696.           /* When enabled the physical height of the console windows */
  4697.           /* should be adjusted to the height of the virtual screen  */
  4698.           /* The width may be set to anything.                       */
  4699.           /* nothing to do                                           */
  4700.           break;
  4701.  
  4702.           case TVC_W95:
  4703.           /* Win95-safe mode allows the physical height to change    */
  4704.           /* but restricts it to a width of 80 and a height equal to */
  4705.           /* 25, 43, or 50.  Must be adjusted now.                   */
  4706.           /* The virtual heights must be equal to the above.         */
  4707.           if (pheight != 25 && pheight != 43 && pheight != 50) {
  4708.               if (pheight < 25)
  4709.             y = 25;
  4710.               else if (pheight < 43)
  4711.             y = 43;
  4712.               else
  4713.             y = 50;
  4714.           } else
  4715.             y = pheight;
  4716.  
  4717.           tt_modechg = TVC_ENA;    /* Temporary */
  4718.  
  4719.           tt_szchng[VCMD] = 1;
  4720.           tt_rows[VCMD] = y;
  4721.           tt_cols[VCMD] = 80;
  4722.           VscrnInit(VCMD);
  4723.           SetCols(VCMD);
  4724.           cmd_rows = y;
  4725.           cmd_cols = 80;
  4726.  
  4727.           marginbot = y-(tt_status?1:0);
  4728.           tt_szchng[VTERM] = 2;
  4729.           tt_rows[VTERM] = y - (tt_status?1:0);
  4730.           tt_cols[VTERM] = 80;
  4731.           VscrnInit(VTERM);
  4732.           break;
  4733.           }
  4734.           tt_modechg = x;
  4735.       }
  4736.       return(1);
  4737.       }
  4738.       case XYTSTAT: {
  4739.           extern int marginbot;
  4740.           if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  4741.           if ((x = cmcfm()) < 0) return(x);
  4742.           if (y != tt_status || y != tt_status_usr) {
  4743.               /* Might need to fixup the margins */
  4744.               if ( marginbot == VscrnGetHeight(VTERM)-(tt_status?1:0) )
  4745.                 if (y) {
  4746.                     marginbot--;
  4747.                 } else {
  4748.                     marginbot++;
  4749.                 }
  4750.               tt_status_usr = tt_status = y;
  4751.               if (y) {
  4752.                     tt_szchng[VTERM] = 2;
  4753.                     tt_rows[VTERM]--;
  4754.                     VscrnInit(VTERM);  /* Height set here */
  4755. #ifdef TNCODE
  4756.             if (TELOPT_ME(TELOPT_NAWS))
  4757.               tn_snaws();
  4758. #endif /* TNCODE */
  4759. #ifdef RLOGCODE
  4760.             if (TELOPT_ME(TELOPT_NAWS))
  4761.               rlog_naws();
  4762. #endif /* RLOGCODE */
  4763.               } else {
  4764.           tt_szchng[VTERM] = 1;
  4765.           tt_rows[VTERM]++;
  4766.           VscrnInit(VTERM);    /* Height set here */
  4767. #ifdef TNCODE
  4768.           if (TELOPT_ME(TELOPT_NAWS))
  4769.             tn_snaws();
  4770. #endif /* TNCODE */
  4771. #ifdef RLOGCODE
  4772.           if (TELOPT_ME(TELOPT_NAWS))
  4773.             rlog_naws();
  4774. #endif /* RLOGCODE */
  4775.               }
  4776.           }
  4777.           return(1);
  4778.       }
  4779. #endif /* OS2 */
  4780.  
  4781. #ifdef NT
  4782.       case XYTATTBUG:
  4783.     if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  4784.     if ((x = cmcfm()) < 0) return(x);
  4785.     tt_attr_bug = y;
  4786.     return(1);
  4787. #endif /* NT */
  4788.  
  4789. #ifdef OS2
  4790.       case XYTSGRC:
  4791.     if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  4792.     if ((x = cmcfm()) < 0) return(x);
  4793.     sgrcolors = y;
  4794.     return(1);
  4795.  
  4796.       case XYTSEND:
  4797.       if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  4798.       if ((x = cmcfm()) < 0) return(x);
  4799.       tt_senddata = y;
  4800.       return(1);
  4801.  
  4802.       case XYTSEOB:
  4803.       if ((y = cmkey(ttyseobtab,2,"","us_cr",xxstring)) < 0) return(y);
  4804.       if ((x = cmcfm()) < 0) return(x);
  4805.       wy_blockend = y;
  4806.       return(1);
  4807.  
  4808.       case XYTATTR:
  4809.     if ((x = cmkey(ttyattrtab,nattrib,"","underline",xxstring)) < 0)
  4810.       return(x);
  4811.     switch (x) {
  4812.       case TTATTBLI:
  4813.         if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  4814.         if ((x = cmcfm()) < 0) return(x);
  4815.         trueblink = y;
  4816. #ifndef KUI
  4817.         if ( !trueblink && trueunderline ) {
  4818.         trueunderline = 0;
  4819.         printf("Warning: Underline being simulated by color.\n");
  4820.         }
  4821.  
  4822. #endif /* KUI */
  4823.         break;
  4824.  
  4825.       case TTATTREV:
  4826.         if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  4827.         if ((x = cmcfm()) < 0) return(x);
  4828.         truereverse = y;
  4829.         break;
  4830.  
  4831.       case TTATTUND:
  4832.         if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  4833.         if ((x = cmcfm()) < 0) return(x);
  4834.         trueunderline = y;
  4835. #ifndef KUI
  4836.         if (!trueblink && trueunderline) {
  4837.         trueblink = 1;
  4838.         printf("Warning: True blink mode is active.\n");
  4839.         }
  4840. #endif /* KUI */
  4841.         break;
  4842.  
  4843.       case TTATTPRO: {    /* Set default Protected Character attribute */
  4844.           extern vtattrib WPattrib;    /* current WP Mode Attrib */
  4845.           extern vtattrib defWPattrib; /* default WP Mode Attrib */
  4846.           vtattrib wpa = {0,0,0,0,0,1,0,0,0};    /* Protected */
  4847.           int done = 0;
  4848.  
  4849.           x = 0;
  4850.           while (!done) {
  4851.           if ((y = cmkey(ttyprotab,nprotect,"",
  4852.                  x?"done":"dim",xxstring)) < 0)
  4853.             return(y);
  4854.           switch (y) {
  4855.             case TTATTNOR:
  4856.               break;
  4857.             case TTATTBLI:    /* Blinking doesn't work */
  4858.               wpa.blinking = TRUE;
  4859.               break;
  4860.             case TTATTREV:
  4861.               wpa.reversed = TRUE;
  4862.               break;
  4863.             case TTATTUND:
  4864.               wpa.underlined = TRUE;
  4865.               break;
  4866.             case TTATTBLD:
  4867.               wpa.bold = TRUE;
  4868.               break;
  4869.             case TTATTDIM:
  4870.               wpa.dim = TRUE;
  4871.               break;
  4872.             case TTATTINV:
  4873.               wpa.invisible = TRUE ;
  4874.               break;
  4875.             case TTATTDONE:
  4876.               done = TRUE;
  4877.               break;
  4878.           }
  4879.           x = 1;        /* One attribute has been chosen */
  4880.           }
  4881.           if ((x = cmcfm()) < 0) return(x);
  4882.           WPattrib = defWPattrib = wpa;
  4883.           break;
  4884.       }
  4885.     }
  4886.     return(1);
  4887.  
  4888.       case XYTKEY: {            /* SET TERMINAL KEY */
  4889.       int t, x, y;
  4890.       int clear = 0, deflt = 0;
  4891.       int confirmed = 0;
  4892.       int flag = 0;
  4893.       int kc = -1;            /* Key code */
  4894.           int litstr = 0;               /* Literal String? */
  4895.       char *s = NULL;        /* Key binding */
  4896. #ifndef NOKVERBS
  4897.       char *p = NULL;        /* Worker */
  4898. #endif /* NOKVERBS */
  4899.       con_event defevt;
  4900.       extern int os2gks;
  4901.       extern int mskkeys;
  4902.       extern int initvik;
  4903.           struct FDB kw,sw,nu,cm;
  4904.  
  4905.           defevt.type = error;
  4906.  
  4907.       if ((t = cmkey(ttkeytab,nttkey,"","",xxstring)) < 0)
  4908.         return(t);
  4909.       cmfdbi(&nu,            /* First FDB - command switches */
  4910.          _CMNUM,        /* fcode */
  4911.          "/literal, keycode, or action",
  4912.          "",            /* default */
  4913.          "",            /* addtl string data */
  4914.          10,            /* addtl numeric data 1: radix */
  4915.          0,            /* addtl numeric data 2: 0 */
  4916.          xxstring,        /* Processing function */
  4917.          NULL,            /* Keyword table */
  4918.          &sw            /* Pointer to next FDB */
  4919.          );            /*  */
  4920.       cmfdbi(&sw,            /* Second FDB - switches */
  4921.          _CMKEY,        /* fcode */
  4922.          "",
  4923.          "",            /* default */
  4924.          "",            /* addtl string data */
  4925.          nstrmswitab,        /* addtl numeric data 1: tbl size */
  4926.          4,            /* addtl numeric data 2: 4 = cmswi */
  4927.          xxstring,        /* Processing function */
  4928.          strmswitab,        /* Keyword table */
  4929.          &kw            /* Pointer to next FDB */
  4930.          );
  4931.       cmfdbi(&kw,            /* Third FDB - command switches */
  4932.          _CMKEY,        /* fcode */
  4933.          "/literal, keycode, or action",
  4934.          "",            /* default */
  4935.          "",            /* addtl string data */
  4936.          nstrmkeytab,        /* addtl numeric data 1: tbl size */
  4937.          0,            /* addtl numeric data 2 */
  4938.          xxstring,        /* Processing function */
  4939.          strmkeytab,        /* Keyword table */
  4940.          &cm            /* Pointer to next FDB */
  4941.          );
  4942.       cmfdbi(&cm,            /* Final FDB - Confirmation */
  4943.          _CMCFM,        /* fcode */
  4944.          "",
  4945.          "",            /* default */
  4946.          "",            /* addtl string data */
  4947.          0,                 /* addtl numeric data 1: tbl size */
  4948.          0,            /* addtl numeric data 2: 4 = cmswi */
  4949.          xxstring,        /* Processing function */
  4950.          NULL,            /* Keyword table */
  4951.          NULL            /* Pointer to next FDB */
  4952.          );
  4953.       while (kc < 0) {
  4954.           x = cmfdb(&nu);        /* Parse something */
  4955.               if (x < 0)
  4956.                 return(x);
  4957.  
  4958.           switch (cmresult.fcode) {
  4959.                 case _CMCFM:
  4960.           printf(" Press key to be defined: ");
  4961.           conbin((char)escape);    /* Put terminal in binary mode */
  4962.           os2gks = 0;        /* Turn off Kverb preprocessing */
  4963.           kc = congks(0);    /* Get character or scan code */
  4964.           os2gks = 1;        /* Turn on Kverb preprocessing */
  4965.           concb((char)escape);    /* Restore terminal to cbreak mode */
  4966.           if (kc < 0) {        /* Check for error */
  4967.               printf("?Error reading key\n");
  4968.               return(0);
  4969.           }
  4970.           shokeycode(kc,t);    /* Show current definition */
  4971.           flag = 1;        /* Remember it's a multiline command */
  4972.                   break;
  4973.         case _CMNUM:
  4974.           kc = cmresult.nresult;
  4975.           break;
  4976.         case _CMKEY:
  4977.           if (cmresult.fdbaddr == &sw) { /* Switch */
  4978.               if (cmresult.nresult == 0)
  4979.             litstr = 1;
  4980.           } else if (cmresult.fdbaddr == &kw) { /* Keyword */
  4981.               if (cmresult.nresult == 0)
  4982.             clear = 1;
  4983.               else
  4984.             deflt = 1;
  4985.               if ((x = cmcfm()) < 0)
  4986.             return(x);
  4987.               if (clear)
  4988.             clearkeymap(t);
  4989.               else if (deflt)
  4990.                 defaultkeymap(t);
  4991.               initvik = 1;
  4992.               return(1);
  4993.           }
  4994.           }
  4995.       }
  4996.  
  4997.     /* Normal SET TERMINAL KEY <terminal> <scancode> <value> command... */
  4998.  
  4999.       if (mskkeys)
  5000.         kc = msktock(kc);
  5001.  
  5002.       if (kc < 0 || kc >= KMSIZE) {
  5003.           printf("?key code must be between 0 and %d\n", KMSIZE - 1);
  5004.           return(-9);
  5005.       }
  5006.       if (kc == escape) {
  5007.           printf("Sorry, %d is the CONNECT-mode escape character\n",kc);
  5008.           return(-9);
  5009.       }
  5010.       wideresult = -1;
  5011.       if (flag) {
  5012.           cmsavp(psave,PROMPTL);
  5013.           cmsetp(" Enter new definition: ");
  5014.           cmini(ckxech);
  5015.       }
  5016.     def_again:
  5017.       if (flag) prompt(NULL);
  5018.       if ((y = cmtxt("key definition,\n\
  5019.  or Ctrl-C to cancel this command,\n\
  5020.  or Enter to restore default definition",
  5021.              "",&s,NULL)) < 0) {
  5022.           if (flag)            /* Handle parse errors */
  5023.         goto def_again;
  5024.           else
  5025.         return(y);
  5026.       }
  5027.       s = brstrip(s);
  5028. #ifndef NOKVERBS
  5029.       p = s;            /* Save this place */
  5030. #endif /* NOKVERBS */
  5031. /*
  5032.   If the definition included any \Kverbs, quote the backslash so the \Kverb
  5033.   will still be in the definition when the key is pressed.  We don't do this
  5034.   in zzstring(), because \Kverbs are valid only in this context and nowhere
  5035.   else.
  5036.  
  5037.   We use this code active for all versions that support SET KEY, even if they
  5038.   don't support \Kverbs, because otherwise \K would behave differently for
  5039.   different versions.
  5040. */
  5041.       for (x = 0, y = 0; s[x]; x++, y++) { /* Convert \K to \\K */
  5042.           if ((x > 0) &&
  5043.           (s[x] == 'K' || s[x] == 'k')
  5044.           ) {            /* Have K */
  5045.  
  5046.           if ((x == 1 && s[x-1] == CMDQ) ||
  5047.               (x > 1 && s[x-1] == CMDQ && s[x-2] != CMDQ)) {
  5048.               line[y++] = CMDQ;    /* Make it \\K */
  5049.           }
  5050.           if (x > 1 && s[x-1] == '{' && s[x-2] == CMDQ) {
  5051.               line[y-1] = CMDQ;    /* Have \{K */
  5052.               line[y++] = '{';    /* Make it \\{K */
  5053.           }
  5054.           }
  5055.           line[y] = s[x];
  5056.       }
  5057.       line[y++] = NUL;        /* Terminate */
  5058.       s = line + y + 1;        /* Point to after it */
  5059.       x = LINBUFSIZ - (int) strlen(line) - 1; /* Get remaining space */
  5060.       if ((x < (LINBUFSIZ / 2)) ||
  5061.           (zzstring(line, &s, &x) < 0)) { /* Expand variables, etc. */
  5062.           printf("?Key definition too long\n");
  5063.           if (flag) cmsetp(psave);
  5064.           return(-9);
  5065.       }
  5066.       s = line + y + 1;        /* Point to result. */
  5067.  
  5068. #ifndef NOKVERBS
  5069. /*
  5070.   Special case: see if the definition starts with a \Kverb.
  5071.   If it does, point to it with p, otherwise set p to NULL.
  5072. */
  5073.       p = s;
  5074.       if (*p++ == CMDQ) {
  5075.           if (*p == '{') p++;
  5076.           p = (*p == 'k' || *p == 'K') ? p + 1 : NULL;
  5077.       }
  5078. #endif /* NOKVERBS */
  5079.  
  5080.       switch (strlen(s)) {        /* Action depends on length */
  5081.         case 0:            /* Clear individual key def */
  5082.           deletekeymap(t,kc);
  5083.           break;
  5084.         case 1:
  5085.               if (!litstr) {
  5086.           defevt.type = key;    /* Single character */
  5087.           defevt.key.scancode = *s;
  5088.           break;
  5089.               }
  5090.         default:            /* Character string */
  5091. #ifndef NOKVERBS
  5092.           if (p) {
  5093.           y = xlookup(kverbs,p,nkverbs,&x); /* Look it up */
  5094.           /* Need exact match */
  5095.           debug(F101,"set key kverb lookup",0,y);
  5096.           if (y > -1) {
  5097.               defevt.type = kverb;
  5098.               defevt.kverb.id = y;
  5099.               break;
  5100.           }
  5101.           }
  5102. #endif /* NOKVERBS */
  5103.               if (litstr) {
  5104.           defevt.type = literal;
  5105.           defevt.literal.string = (char *) malloc(strlen(s)+1);
  5106.           if (defevt.literal.string)
  5107.             strcpy(defevt.literal.string, s);
  5108.               } else {
  5109.           defevt.type = macro;
  5110.           defevt.macro.string = (char *) malloc(strlen(s)+1);
  5111.           if (defevt.macro.string)
  5112.             strcpy(defevt.macro.string, s);
  5113.               }
  5114.           break;
  5115.       }
  5116.       insertkeymap(t, kc, defevt);
  5117.       if (flag)
  5118.         cmsetp(psave);
  5119.       initvik = 1;            /* Update VIK table */
  5120.       return(1);
  5121.       }
  5122.  
  5123. #ifdef PCTERM
  5124.       case XYTPCTERM:                   /* PCTERM Keyboard Mode */
  5125.         if ((x = seton(&tt_pcterm)) < 0) return(x);
  5126.         return(success = 1);
  5127. #endif /* PCTERM */
  5128. #endif /* OS2 */
  5129.  
  5130. #ifdef CK_TRIGGER
  5131.       case XYTRIGGER:
  5132.     if ((y = cmtxt("String to trigger automatic return to command mode",
  5133.                "",&s,xxstring)) < 0)
  5134.       return(y);
  5135.     makelist(s,tt_trigger,TRIGGERS);
  5136.     return(1);
  5137. #endif /* CK_TRIGGER */
  5138.  
  5139. #ifdef OS2
  5140.       case XYTSAC:
  5141.     if ((y = cmnum("ASCII value to use for spacing attributes",
  5142.                "32",10,&x,xxstring)) < 0)
  5143.           return(y);
  5144.     if ((y = cmcfm()) < 0) return(y);
  5145.     tt_sac = x;
  5146.     return(success = 1);
  5147.  
  5148.       case XYTKBDGL: {      /* SET TERM KBD-FOLLOWS-GL/GR */
  5149.           extern int tt_kb_glgr;        /* from ckoco3.c */
  5150.           if ((x = seton(&tt_kb_glgr)) < 0)
  5151.               return(x);
  5152.           return(success = 1);
  5153.       }
  5154. #ifndef NOCSETS
  5155.       case XYTVTLNG:        /* SET TERM DEC-LANGUAGE */
  5156.     if ((y = cmkey(vtlangtab,nvtlangtab,"VT language",
  5157.                "north-american",xxstring)) < 0)
  5158.       return(y);
  5159.     if ((x = cmcfm()) < 0) return(x);
  5160.  
  5161.     /* A real VT terminal would use the language to set the   */
  5162.     /* default keyboard language for both 8-bit multinational */
  5163.     /* and 7-bit national modes.  For 8-bit mode it would     */
  5164.     /* set the terminal character-set to the ISO set if it    */
  5165.     /* is not already set.                                    */
  5166.     /* Latin-1 can be replaced by DEC Multinational           */
  5167.     switch (y) {
  5168.           case VTL_NORTH_AM:  /* North American */
  5169.         /* Multinational: Latin-1   */
  5170.         /* National:      US_ASCII  */
  5171.         dec_lang = y;
  5172.         dec_nrc = TX_ASCII;
  5173.         dec_kbd = TX_8859_1;
  5174.         break;
  5175.           case VTL_BRITISH :
  5176.         /* Multinational: Latin-1   */
  5177.         /* National:      UK_ASCII  */
  5178.         dec_lang = y;
  5179.         dec_nrc = TX_BRITISH;
  5180.         dec_kbd = TX_8859_1;
  5181.         break;
  5182.           case VTL_FRENCH  :
  5183.           case VTL_BELGIAN :
  5184.           case VTL_CANADIAN:
  5185.         /* Multinational: Latin-1   */
  5186.         /* National:      FR_ASCII  */
  5187.         dec_lang = y;
  5188.         dec_nrc = TX_FRENCH;
  5189.         dec_kbd = TX_8859_1;
  5190.         break;
  5191.           case VTL_FR_CAN  :
  5192.         /* Multinational: Latin-1   */
  5193.         /* National:      FC_ASCII  */
  5194.         dec_lang = y;
  5195.         dec_nrc = TX_CN_FRENCH;
  5196.         dec_kbd = TX_8859_1;
  5197.         break;
  5198.           case VTL_DANISH  :
  5199.           case VTL_NORWEGIA:
  5200.         /* Multinational: Latin-1   */
  5201.         /* National:      NO_ASCII  */
  5202.         dec_lang = y;
  5203.         dec_nrc = TX_NORWEGIAN;
  5204.         dec_kbd = TX_8859_1;
  5205.         break;
  5206.           case VTL_FINNISH :
  5207.         /* Multinational: Latin-1   */
  5208.         /* National:      FI_ASCII  */
  5209.         dec_lang = y;
  5210.         dec_nrc = TX_FINNISH;
  5211.         dec_kbd = TX_8859_1;
  5212.         break;
  5213.           case VTL_GERMAN  :
  5214.         /* Multinational: Latin-1   */
  5215.         /* National:      GR_ASCII  */
  5216.         dec_lang = y;
  5217.         dec_nrc = TX_GERMAN;
  5218.         dec_kbd = TX_8859_1;
  5219.         break;
  5220.           case VTL_DUTCH   :
  5221.         /* Multinational: Latin-1   */
  5222.         /* National:      DU_ASCII  */
  5223.         dec_lang = y;
  5224.         dec_nrc = TX_DUTCH;
  5225.         dec_kbd = TX_8859_1;
  5226.         break;
  5227.           case VTL_ITALIAN :
  5228.         /* Multinational: Latin-1   */
  5229.         /* National:      IT_ASCII  */
  5230.         dec_lang = y;
  5231.         dec_nrc = TX_ITALIAN;
  5232.         dec_kbd = TX_8859_1;
  5233.         break;
  5234.           case VTL_SW_FR   :
  5235.           case VTL_SW_GR   :
  5236.         /* Multinational: Latin-1   */
  5237.         /* National:      CH_ASCII  */
  5238.         dec_lang = y;
  5239.         dec_nrc = TX_SWISS;
  5240.         dec_kbd = TX_8859_1;
  5241.         break;
  5242.           case VTL_SWEDISH :
  5243.         /* Multinational: Latin-1   */
  5244.         /* National:      SW_ASCII  */
  5245.         dec_lang = y;
  5246.         dec_nrc = TX_SWEDISH;
  5247.         dec_kbd = TX_8859_1;
  5248.         break;
  5249.           case VTL_SPANISH :
  5250.         /* Multinational: Latin-1   */
  5251.         /* National:      SP_ASCII  */
  5252.         dec_lang = y;
  5253.         dec_nrc = TX_SPANISH;
  5254.         dec_kbd = TX_8859_1;
  5255.         break;
  5256.           case VTL_PORTUGES:
  5257.         /* Multinational: Latin-1   */
  5258.         /* National:      Portugese ASCII  */
  5259.         dec_lang = y;
  5260.         dec_nrc = TX_PORTUGUESE;
  5261.         dec_kbd = TX_8859_1;
  5262.         break;
  5263.           case VTL_HEBREW  :
  5264.         /* Multinational: Latin-Hebrew / DEC-Hebrew  */
  5265.         /* National:      DEC 7-bit Hebrew  */
  5266.         dec_lang = y;
  5267.         dec_nrc = TX_HE7;
  5268.         dec_kbd = TX_8859_8;
  5269.         break;
  5270.           case VTL_GREEK   :
  5271.         /* Multinational: Latin-Greek / DEC-Greek   */
  5272.         /* National:      DEC Greek NRC             */
  5273.         /* is ELOT927 equivalent to DEC Greek????   */
  5274.         dec_lang = y;
  5275.         dec_nrc = TX_ELOT927;
  5276.         dec_kbd = TX_8859_7;
  5277.         break;
  5278. #ifdef COMMENT
  5279.           case VTL_TURK_Q  :
  5280.           case VTL_TURK_F  :
  5281.         /* Multinational: Latin-Turkish / DEC-Turkish   */
  5282.         /* National:      DEC 7-bit Turkish             */
  5283.         break;
  5284. #endif /* COMMENT */
  5285.           case VTL_HUNGARIA:
  5286.         /* Multinational: Latin-2   */
  5287.         /* National:      no national mode  */
  5288.         dec_lang = y;
  5289.         dec_nrc = TX_HUNGARIAN;
  5290.         dec_kbd = TX_8859_2;
  5291.         break;
  5292.           case VTL_SLOVAK  :
  5293.           case VTL_CZECH   :
  5294.           case VTL_POLISH  :
  5295.           case VTL_ROMANIAN:
  5296.         /* Multinational: Latin-2   */
  5297.         /* National:      no national mode  */
  5298.         dec_lang = y;
  5299.         dec_nrc = TX_ASCII;
  5300.         dec_kbd = TX_8859_2;
  5301.         break;
  5302.           case VTL_RUSSIAN :
  5303.         /* Multinational: Latin-Cyrillic / KOI-8   */
  5304.         /* National:      DEC Russian NRC  */
  5305.         dec_lang = y;
  5306.         dec_nrc = TX_KOI7;
  5307.         dec_kbd = TX_8859_5;
  5308.         break;
  5309.           case VTL_LATIN_AM:
  5310.         /* Multinational: not listed in table   */
  5311.         /* National:      not listed in table  */
  5312.         dec_lang = y;
  5313.         dec_nrc = TX_ASCII;
  5314.         dec_kbd = TX_8859_1;
  5315.         break;
  5316. #ifdef COMMENT
  5317.           case VTL_SCS     :
  5318.         /* Multinational: Latin-2   */
  5319.         /* National:      SCS NRC   */
  5320.         break;
  5321. #endif /* COMMENT */
  5322.           default:
  5323.         return(success = 0);
  5324.     }
  5325.     if (IS97801(tt_type_mode)) {
  5326.         SNI_bitmode(cmask == 0377 ? 8 : 7);
  5327.     }
  5328.     return(success = 1);
  5329. #endif /* NOCSETS */
  5330.  
  5331.       case XYTVTNRC: {            /* SET TERM DEC-NRC-MODE */
  5332.       extern int decnrcm_usr, decnrcm;        /* from ckoco3.c */
  5333.       if ((x = seton(&decnrcm_usr)) < 0)
  5334.             return(x);
  5335.       decnrcm = decnrcm_usr;
  5336.       return(success = 1);
  5337.       }
  5338.       case XYTSNIPM: {                  /* SET TERM SNI-PAGEMODE */
  5339.           extern int sni_pagemode, sni_pagemode_usr;
  5340.           if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5341.           if ((x = cmcfm()) < 0) return(x);
  5342.           sni_pagemode_usr = sni_pagemode = y;
  5343.           return(success = 1);
  5344.       }
  5345.       case XYTSNISM: {                  /* SET TERM SNI-SCROLLMODE */
  5346.           extern int sni_scroll_mode, sni_scroll_mode_usr;
  5347.           if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5348.           if ((x = cmcfm()) < 0) return(x);
  5349.           sni_scroll_mode_usr = sni_scroll_mode = y;
  5350.           return(success = 1);
  5351.       }
  5352.       case XYTSNICC: {  /* SET TERM SNI-CH.CODE */
  5353.       extern int sni_chcode_usr;
  5354.       if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5355.       if ((x = cmcfm()) < 0) return(x);
  5356.       sni_chcode_usr = y;
  5357.       SNI_chcode(y);
  5358.       return(success = 1);
  5359.       }
  5360.       case XYTSNIFV: {  /* SET TERM SNI-FIRMWARE-VERSIONS */
  5361.       extern CHAR sni_kbd_firmware[], sni_term_firmware[];
  5362.       CHAR kbd[7],term[7];
  5363.  
  5364.       if ((x = cmfld("Keyboard Firmware Version",sni_kbd_firmware,
  5365.              &s, xxstring)) < 0)
  5366.             return(x);
  5367.       if ((int)strlen(s) != 6) {
  5368.           printf("?Sorry - the firmware version must be 6 digits long\n");
  5369.           return(-9);
  5370.       }
  5371.       for (i = 0; i < 6; i++) {
  5372.           if (!isdigit(s[i])) {
  5373.    printf("?Sorry - the firmware version can only contain digits [0-9]\n");
  5374.                   return(-9);
  5375.               }
  5376.       }
  5377.       strcpy(kbd,s);
  5378.  
  5379.       if ((x = cmfld("Terminal Firmware Version",sni_term_firmware,
  5380.              &s, xxstring)) < 0)
  5381.             return(x);
  5382.       if ((int)strlen(s) != 6) {
  5383.           printf("?Sorry - the firmware version must be 6 digits long\n");
  5384.           return(-9);
  5385.       }
  5386.       for (i = 0; i < 6; i++) {
  5387.           if (!isdigit(s[i])) {
  5388.    printf("?Sorry - the firmware version can only contain digits [0-9]\n");
  5389.                    return(-9);
  5390.               }
  5391.       }
  5392.       strcpy(term,s);
  5393.       if ((x = cmcfm()) < 0) return(x);
  5394.  
  5395.       strcpy(sni_kbd_firmware,kbd);
  5396.       strcpy(sni_term_firmware,term);
  5397.       return(success = 1);
  5398.     }
  5399. #endif /* OS2 */
  5400.  
  5401.       default:                /* Shouldn't get here. */
  5402.     return(-2);
  5403.     }
  5404. #endif /* MAC */
  5405. #ifdef COMMENT
  5406.     /*
  5407.       This was supposed to shut up picky compilers but instead it makes
  5408.       most compilers complain about "statement not reached".
  5409.     */
  5410.     return(-2);
  5411. #endif /* COMMENT */
  5412. #ifdef OS2
  5413. return(-2);
  5414. #endif /* OS2 */
  5415. }
  5416.  
  5417. #ifdef OS2
  5418. int
  5419. settitle(void) {
  5420.     extern char usertitle[];
  5421.     if ((y = cmtxt("title text","",&s,xxstring)) < 0)
  5422.       return(y);
  5423. #ifdef IKSD
  5424.     if (inserver) {
  5425.         printf("?Sorry, command disabled.\r\n");
  5426.         return(success = 0);
  5427.     }
  5428. #endif /* IKSD */
  5429.  
  5430.     ckstrncpy(usertitle,s,64);
  5431.     os2settitle("",1);
  5432.     return(1);
  5433. }
  5434.  
  5435. static struct keytab dialertab[] = {    /* K95 Dialer types */
  5436.     "backspace",     0, 0,
  5437.     "enter",           1, 0
  5438. };
  5439. static int ndialer = 2;
  5440.  
  5441. int
  5442. setdialer(void) {
  5443.     int t, x, y;
  5444.     int clear = 0, deflt = 0;
  5445.     int kc;                /* Key code */
  5446.     char *s = NULL;            /* Key binding */
  5447. #ifndef NOKVERBS
  5448.     char *p = NULL;            /* Worker */
  5449. #endif /* NOKVERBS */
  5450.     con_event defevt;
  5451.     extern int os2gks;
  5452.     extern int mskkeys;
  5453.     extern int initvik;
  5454.  
  5455.     defevt.type = error;
  5456.  
  5457.     if (( x = cmkey(dialertab, ndialer,
  5458.             "Kermit-95 dialer work-arounds",
  5459.             "", xxstring)) < 0 )
  5460.       return(x);
  5461.     switch (x) {
  5462.       case 0:                /* Backspace */
  5463.     kc = 264;
  5464.     break;
  5465.       case 1:                /* Enter */
  5466.     kc = 269;
  5467.     break;
  5468.       default:
  5469.     printf("Illegal value in setdialer()\n");
  5470.     return(-9);
  5471.     }
  5472.     if ((y = cmtxt("Key definition","",&s,xxstring)) < 0)
  5473.       return(y);
  5474.  
  5475. #ifdef IKSD
  5476.     if (inserver) {
  5477.         printf("?Sorry, command disabled.\r\n");
  5478.         return(success = 0);
  5479.     }
  5480. #endif /* IKSD */
  5481.     s = brstrip(s);
  5482. #ifndef NOKVERBS
  5483.     p = s;                /* Save this place */
  5484. #endif /* NOKVERBS */
  5485. /*
  5486.   If the definition included any \Kverbs, quote the backslash so the \Kverb
  5487.   will still be in the definition when the key is pressed.  We don't do this
  5488.   in zzstring(), because \Kverbs are valid only in this context and nowhere
  5489.   else.
  5490.  
  5491.   We use this code active for all versions that support SET KEY, even if they
  5492.   don't support \Kverbs, because otherwise \K would behave differently for
  5493.   different versions.
  5494. */
  5495.     for (x = 0, y = 0; s[x]; x++, y++) { /* Convert \K to \\K */
  5496.     if ((x > 0) &&
  5497.         (s[x] == 'K' || s[x] == 'k')
  5498.         ) {                /* Have K */
  5499.  
  5500.         if ((x == 1 && s[x-1] == CMDQ) ||
  5501.         (x > 1 && s[x-1] == CMDQ && s[x-2] != CMDQ)) {
  5502.         line[y++] = CMDQ;    /* Make it \\K */
  5503.         }
  5504.         if (x > 1 && s[x-1] == '{' && s[x-2] == CMDQ) {
  5505.           line[y-1] = CMDQ;    /* Have \{K */
  5506.           line[y++] = '{';    /* Make it \\{K */
  5507.         }
  5508.     }
  5509.     line[y] = s[x];
  5510.     }
  5511.     line[y++] = NUL;            /* Terminate */
  5512.     s = line + y + 1;            /* Point to after it */
  5513.     x = LINBUFSIZ - (int) strlen(line) - 1; /* Calculate remaining space */
  5514.     if ((x < (LINBUFSIZ / 2)) ||
  5515.     (zzstring(line, &s, &x) < 0)) { /* Expand variables, etc. */
  5516.     printf("?Key definition too long\n");
  5517.     return(-9);
  5518.     }
  5519.     s = line + y + 1;            /* Point to result. */
  5520.  
  5521. #ifndef NOKVERBS
  5522. /*
  5523.   Special case: see if the definition starts with a \Kverb.
  5524.   If it does, point to it with p, otherwise set p to NULL.
  5525. */
  5526.     p = s;
  5527.     if (*p++ == CMDQ) {
  5528.     if (*p == '{') p++;
  5529.     p = (*p == 'k' || *p == 'K') ? p + 1 : NULL;
  5530.     }
  5531. #endif /* NOKVERBS */
  5532.  
  5533.     /* Now reprogram the default value for all terminal types */
  5534.     /* remember to treat Wyse and Televideo terminals special */
  5535.     /* because of their use of Kverbs for Backspace and Enter */
  5536.     for (t = 0; t <= TT_MAX; t++) {
  5537.         if ( ISDG200(t) && kc == 264) {
  5538.         extern char * udkfkeys[] ;
  5539.         if (kc == 264) {        /* \Kdgbs */
  5540.         if (udkfkeys[83])
  5541.           free(udkfkeys[83]);
  5542.         udkfkeys[83] = strdup(s);
  5543.         }
  5544.     } else if (ISWYSE(t) || ISTVI(t)) {
  5545.         extern char * udkfkeys[] ;
  5546.         if (kc == 264) {        /* \Kwybs or \Ktvibs */
  5547.         if (udkfkeys[32])
  5548.           free(udkfkeys[32]);
  5549.         udkfkeys[32] = strdup(s);
  5550.         }
  5551.         if (kc == 269) {        /* \Kwyenter and \Kwyreturn */
  5552.         if (udkfkeys[39])    /* \Ktvienter and \Ktvireturn */
  5553.           free(udkfkeys[39]);
  5554.         udkfkeys[39] = strdup(s);
  5555.         if (udkfkeys[49])
  5556.           free(udkfkeys[49]);
  5557.         udkfkeys[49] = strdup(s);
  5558.         }
  5559.     } else {
  5560.         switch (strlen(s)) {    /* Action depends on length */
  5561.           case 0:            /* Clear individual key def */
  5562.         deletekeymap(t,kc);
  5563.         break;
  5564.           case 1:
  5565.         defevt.type = key;    /* Single character */
  5566.         defevt.key.scancode = *s;
  5567.         break;
  5568.           default:            /* Character string */
  5569. #ifndef NOKVERBS
  5570.         if (p) {
  5571.             y = xlookup(kverbs,p,nkverbs,&x); /* Look it up */
  5572.             /* Exact match req'd */
  5573.             debug(F101,"set key kverb lookup",0,y);
  5574.             if (y > -1) {
  5575.             defevt.type = kverb;
  5576.             defevt.kverb.id = y;
  5577.             break;
  5578.             }
  5579.         }
  5580. #endif /* NOKVERBS */
  5581.         defevt.type = macro;
  5582.         defevt.macro.string = (char *) malloc(strlen(s)+1);
  5583.         if (defevt.macro.string)
  5584.           strcpy(defevt.macro.string, s);
  5585.         break;
  5586.         }
  5587.         insertkeymap( t, kc, defevt ) ;
  5588.         initvik = 1;        /* Update VIK table */
  5589.     }
  5590.     }
  5591.     return(1);
  5592. }
  5593. #endif /* OS2 */
  5594.  
  5595. #ifdef NT
  5596. int
  5597. setwin95( void ) {
  5598.     int x, y, z;
  5599.  
  5600.     if (( y = cmkey(win95tab, nwin95,
  5601.             "Windows 95 specific work-arounds",
  5602.             "keyboard-translation",
  5603.             xxstring)) < 0 )
  5604.     return (y);
  5605.     switch (y) {
  5606.       case XYWPOPUP:
  5607.     if ((y = cmkey(onoff,2,"popups are used to prompt the user for data",
  5608.                "on",xxstring)) < 0)
  5609.       return(y);
  5610.     if ((x = cmcfm()) < 0) return(x);
  5611.     win95_popup = y;
  5612.     return(1);
  5613.  
  5614.       case XYW8_3:
  5615.     if ((y = cmkey(onoff,2,"8.3 FAT file names","off",xxstring)) < 0)
  5616.       return(y);
  5617.     if ((x = cmcfm()) < 0) return(x);
  5618.     win95_8_3 = y;
  5619.     return(1);
  5620.  
  5621.       case XYWSELECT:
  5622.     if ((y = cmkey(onoff,2,"\"select()\" fails on write","off",
  5623.              xxstring)) < 0)
  5624.       return(y);
  5625.     if ((x = cmcfm()) < 0) return(x);
  5626.     win95selectbug = y;
  5627.     return(1);
  5628.  
  5629.       case XYWAGR:
  5630.     if ((y = cmkey(onoff,2,"Right-Alt is Alt-Gr","off",xxstring)) < 0)
  5631.       return(y);
  5632.     if ((x = cmcfm()) < 0) return(x);
  5633.     win95altgr = y;
  5634.     return(1);
  5635.  
  5636.       case XYWOIO:
  5637.     if ((y = cmkey(onoff,2,"Use Overlapped I/O","on",xxstring)) < 0)
  5638.       return(y);
  5639.     if (y) {
  5640.         if ((x = cmnum("Maximum number of outstanding I/O requests",
  5641.                "10",10,&z,xxstring)) < 0)
  5642.           return(x);
  5643.         if (z < 1 || z > 30) {
  5644.         printf(
  5645. "?Maximum outstanding I/O requests must be between 1 and 30.\n");
  5646.         return(-9);
  5647.         }
  5648.     } else
  5649.       z = 1;
  5650.     if ((x = cmcfm()) < 0) return(x);
  5651.     owwait = !y;
  5652.     maxow = maxow_usr = z;
  5653.     return(1);
  5654.  
  5655.       case XYWKEY:
  5656. #ifndef COMMENT
  5657.         printf("\n?\"Keyboard-Translation\" is no longer required.\n");
  5658.         return(-9);
  5659. #else /* COMMENT */
  5660.     if (( z = cmkey(tcstab, ntcs,
  5661.             "Keyboard Character Set",
  5662.             "latin1-iso",
  5663.             xxstring)) < 0)
  5664.       return (z);
  5665.     if ((x = cmcfm()) < 0)
  5666.       return(x);
  5667.  
  5668.     win95kcsi = z;
  5669.     win95kl2 = (win95kcsi == TC_2LATIN);
  5670.  
  5671.     if (win95kcsi == TC_TRANSP) {
  5672.         win95kcs = NULL;
  5673.     } else {
  5674. #ifdef UNICODE
  5675.         win95kcs = xlr[win95kcsi][tx2fc(tcsl)];
  5676. #else /* UNICODE */
  5677.         win95kcs = xlr[win95kcsi][tcsl];
  5678. #endif /* UNICODE */
  5679.     }
  5680.     return(1);
  5681. #endif /* COMMENT */
  5682.  
  5683.       case XYWLUC:
  5684.     if ((y = cmkey(onoff,2,"Unicode-to-Lucida-Console substitutions",
  5685.                "on",xxstring)) < 0)
  5686.       return(y);
  5687.     if ((x = cmcfm()) < 0) return(x);
  5688.     win95lucida = y;
  5689.     return(1);
  5690.  
  5691.       default:
  5692.     printf("Illegal value in setwin95()\n");
  5693.     return(-9);
  5694.     }
  5695. }
  5696. #endif /* NT */
  5697.  
  5698. #ifdef OS2
  5699. int
  5700. setprty (
  5701. #ifdef CK_ANSIC
  5702.     void
  5703. #endif /* CK_ANSIC */
  5704. /* setprty */ ) {
  5705.     int x, y, z;
  5706.  
  5707.     if (( y = cmkey(prtytab, nprty,
  5708.             "priority level of terminal and communication threads",
  5709.             "foreground-server",
  5710.             xxstring)) < 0 )
  5711.       return (y);
  5712.  
  5713.     if ((x = cmcfm()) < 0)
  5714.       return (x);
  5715. #ifdef IKSD
  5716.     if (inserver &&
  5717. #ifdef IKSDCONF
  5718.          iksdcf
  5719. #else
  5720.          1
  5721. #endif /* IKSDCONF */
  5722.     ) {
  5723.     if ((y = cmcfm()) < 0) return(y);
  5724.         printf("?Sorry, command disabled.\r\n");
  5725.         return(success = 0);
  5726.     }
  5727. #endif /* IKSD */
  5728.     priority = y;
  5729.     return(TRUE);
  5730. }
  5731. #endif /* OS2 */
  5732.  
  5733. int
  5734. setbell() {
  5735.     int z, y, x;
  5736.  
  5737.     if ((y = cmkey(beltab,nbeltab,
  5738. #ifdef OS2
  5739.         "how console and terminal bells should\nbe generated", "audible",
  5740. #else
  5741.         "Whether Kermit should ring the terminal bell (beep)", "on",
  5742. #endif /* OS2 */
  5743.            xxstring)) < 0)
  5744.       return(y);
  5745.  
  5746. #ifdef IKSD
  5747.     if (inserver) {
  5748.     if ((y = cmcfm()) < 0) return(y);
  5749.         printf("?Sorry, command disabled.\r\n");
  5750.         return(success = 0);
  5751.     }
  5752. #endif /* IKSD */
  5753.  
  5754.     switch (y) {            /* SET BELL */
  5755.       case XYB_NONE:
  5756. #ifdef OS2
  5757.       case XYB_VIS:
  5758. #endif /* OS2 */
  5759.     if ((x = cmcfm()) < 0)
  5760.       return(x);
  5761. #ifdef OS2
  5762.     tt_bell = y;
  5763. #else
  5764.     tt_bell = 0;
  5765. #endif /* OS2 */
  5766.     break;
  5767.  
  5768.       case XYB_AUD:
  5769. #ifdef OS2
  5770.     if ((x = cmkey(audibletab, naudibletab,
  5771.            "how audible console and terminal\nbells should be generated",
  5772.                "beep",xxstring))<0)
  5773.       return(x);
  5774.     if ((z = cmcfm()) < 0)
  5775.       return(z);
  5776.     tt_bell = y | x;
  5777. #else
  5778.     /* This lets C-Kermit accept but ignore trailing K95 keywords */
  5779.     if ((x = cmtxt("Confirm with carriage return","",&s,xxstring)) < 0)
  5780.       return(x);
  5781.     tt_bell = 1;
  5782. #endif /* OS2 */
  5783.     break;
  5784.     }
  5785.     return(1);
  5786. }
  5787.  
  5788. #ifdef OS2MOUSE
  5789. int
  5790. setmou(
  5791. #ifdef CK_ANSIC
  5792.        void
  5793. #endif /* CK_ANSIC */
  5794.  /* setmou */ ) {
  5795.     extern int initvik;
  5796.     int button = 0, event = 0;
  5797.     char * p;
  5798.  
  5799.     if ((y = cmkey(mousetab,nmtab,"","",xxstring)) < 0)
  5800.       return(y);
  5801.  
  5802. #ifdef IKSD
  5803.     if (inserver) {
  5804.     if ((y = cmcfm()) < 0) return(y);
  5805.         printf("?Sorry, command disabled.\r\n");
  5806.         return(success = 0);
  5807.     }
  5808. #endif /* IKSD */
  5809.  
  5810.     if (y == XYM_ON) {            /* MOUSE ACTIVATION */
  5811.         int old_mou = tt_mouse;
  5812.         if ((x = seton(&tt_mouse)) < 0)
  5813.             return(x);
  5814.         if (tt_mouse != old_mou)
  5815.           if (tt_mouse)
  5816.             os2_mouseon();
  5817.           else
  5818.             os2_mouseoff();
  5819.         return(1);
  5820.     }
  5821.  
  5822.     if (y == XYM_CLEAR) {        /* Reset Mouse Defaults */
  5823.     if ((x = cmcfm()) < 0) return(x);
  5824.     mousemapinit(-1,-1);
  5825.     initvik = 1;            /* Update VIK Table */
  5826.     return 1;
  5827.     }
  5828.     if (y != XYM_BUTTON) {        /* Shouldn't happen. */
  5829.     printf("Internal parsing error\n");
  5830.     return(-9);
  5831.     }
  5832.  
  5833.     /* MOUSE EVENT ... */
  5834.  
  5835.     if ((button = cmkey(mousebuttontab,nmbtab,
  5836.             "Button number, one of the following","1",
  5837.             xxstring)) < 0)
  5838.       return(button);
  5839.  
  5840.     if ((y =  cmkey(mousemodtab,nmmtab,
  5841.             "Keyboard modifier, one of the following",
  5842.             "none",xxstring)) < 0)
  5843.       return(y);
  5844.  
  5845.     event |= y;                /* OR in the bits */
  5846.  
  5847.     if ((y =  cmkey(mclicktab,nmctab,"","click",xxstring)) < 0)
  5848.       return(y);
  5849.  
  5850.     /* Two bits are assigned, if neither are set then it is button one */
  5851.  
  5852.     event |= y;            /* OR in the bit */
  5853.  
  5854.     wideresult = -1;
  5855.  
  5856.     if ((y = cmtxt("definition,\n\
  5857. or Ctrl-C to cancel this command,\n\
  5858. or Enter to restore default definition",
  5859.            "",&s,NULL)) < 0) {
  5860.     return(y);
  5861.     }
  5862.     s = brstrip(s);
  5863.     p = s;                /* Save this place */
  5864. /*
  5865.   If the definition included any \Kverbs, quote the backslash so the \Kverb
  5866.   will still be in the definition when the key is pressed.  We don't do this
  5867.   in zzstring(), because \Kverbs are valid only in this context and nowhere
  5868.   else.  This code copied from SET KEY, q.v. for addt'l commentary.
  5869. */
  5870.     for (x = 0, y = 0; s[x]; x++, y++) { /* Convert \K to \\K */
  5871.     if ((x > 0) &&
  5872.         (s[x] == 'K' || s[x] == 'k')
  5873.         ) {                /* Have K */
  5874.  
  5875.         if ((x == 1 && s[x-1] == CMDQ) ||
  5876.         (x > 1 && s[x-1] == CMDQ && s[x-2] != CMDQ)) {
  5877.         line[y++] = CMDQ;    /* Make it \\K */
  5878.         }
  5879.         if (x > 1 && s[x-1] == '{' && s[x-2] == CMDQ) {
  5880.           line[y-1] = CMDQ;    /* Have \{K */
  5881.           line[y++] = '{';    /* Make it \\{K */
  5882.         }
  5883.     }
  5884.     line[y] = s[x];
  5885.     }
  5886.     line[y++] = NUL;            /* Terminate */
  5887.     s = line + y + 1;            /* Point to after it */
  5888.     x = LINBUFSIZ - (int) strlen(line) - 1; /* Calculate remaining space */
  5889.     if ((x < (LINBUFSIZ / 2)) ||
  5890.     (zzstring(line, &s, &x) < 0)) { /* Expand variables, etc. */
  5891.     printf("?Key definition too long\n");
  5892.     return(-9);
  5893.     }
  5894.     s = line + y + 1;            /* Point to result. */
  5895.  
  5896. #ifndef NOKVERBS
  5897. /*
  5898.   Special case: see if the definition starts with a \Kverb.
  5899.   If it does, point to it with p, otherwise set p to NULL.
  5900. */
  5901.     p = s;
  5902.     if (*p++ == CMDQ) {
  5903.     if (*p == '{') p++;
  5904.     p = (*p == 'k' || *p == 'K') ? p + 1 : NULL;
  5905.     }
  5906. #else
  5907.     p = NULL;
  5908. #endif /* NOKVERBS */
  5909.  
  5910.     /* free the old definition if necessary */
  5911.     if (mousemap[button][event].type == macro) {
  5912.         free( mousemap[button][event].macro.string);
  5913.     mousemap[button][event].macro.string = NULL;
  5914.     }
  5915.     switch (strlen(s)) {        /* Action depends on length */
  5916.       case 0:                /* Reset to default binding */
  5917.         mousemapinit( button, event );
  5918.         break;
  5919.       case 1:                /* Single character */
  5920.           mousemap[button][event].type = key;
  5921.         mousemap[button][event].key.scancode = *s;
  5922.           break;
  5923.       default:                /* Character string */
  5924. #ifndef NOKVERBS
  5925.     if (p) {
  5926.         y = xlookup(kverbs,p,nkverbs,&x); /* Look it up */
  5927.         debug(F101,"set mouse kverb lookup",0,y); /* need exact match */
  5928.         if (y > -1) {
  5929.             /* Assign the kverb to the event */
  5930.             mousemap[button][event].type = kverb;
  5931.             mousemap[button][event].kverb.id = F_KVERB | y;
  5932.             break;
  5933.         }
  5934.     }
  5935. #endif /* NOKVERBS */
  5936.  
  5937.        /* Otherwise, it's a macro, so assign the macro to the event */
  5938.        mousemap[button][event].type = macro;
  5939.        mousemap[button][event].macro.string = (MACRO) malloc(strlen(s)+1);
  5940.        if (mousemap[button][event].macro.string)
  5941.          strcpy((char *) mousemap[button][event].macro.string, s);
  5942.         break;
  5943.     }
  5944.     initvik = 1;            /* Update VIK Table */
  5945.     return(1);
  5946. }
  5947. #endif /* OS2MOUSE */
  5948. #endif /* NOLOCAL */
  5949.  
  5950. #ifndef NOXFER
  5951. int                    /* SET SEND/RECEIVE */
  5952. setsr(xx, rmsflg) int xx; int rmsflg; {
  5953.     if (xx == XYRECV)
  5954.       strcpy(line,"Parameter for inbound packets");
  5955.     else
  5956.       strcpy(line,"Parameter for outbound packets");
  5957.  
  5958.     if (rmsflg) {
  5959.     if ((y = cmkey(rsrtab,nrsrtab,line,"",xxstring)) < 0) {
  5960.         if (y == -3) {
  5961.         printf("?Remote receive parameter required\n");
  5962.         return(-9);
  5963.         } else return(y);
  5964.     }
  5965.     } else {
  5966.     if ((y = cmkey(srtab,nsrtab,line,"",xxstring)) < 0) return(y);
  5967.     }
  5968.     switch (y) {
  5969.       case XYQCTL:            /* CONTROL-PREFIX */
  5970.     if ((x = cmnum("ASCII value of control prefix","",10,&y,xxstring)) < 0)
  5971.       return(x);
  5972.     if ((x = cmcfm()) < 0) return(x);
  5973.     if ((y > 32 && y < 63) || (y > 95 && y < 127)) {
  5974.         if (xx == XYRECV)
  5975.           ctlq = (CHAR) y;        /* RECEIVE prefix, use with caution! */
  5976.         else
  5977.           myctlq = (CHAR) y;    /* SEND prefix, OK to change */
  5978.         return(success = 1);
  5979.     } else {
  5980.         printf("?Illegal value for prefix character\n");
  5981.         return(-9);
  5982.     }
  5983.  
  5984.       case XYEOL:
  5985.     if ((y = setcc("13",&z)) < 0)
  5986.         return(y);
  5987.     if (z > 31) {
  5988.         printf("Sorry, the legal values are 0-31\n");
  5989.         return(-9);
  5990.     }
  5991.     if (xx == XYRECV)
  5992.       eol = (CHAR) z;
  5993.     else
  5994.       seol = (CHAR) z;
  5995.     return(success = y);
  5996.  
  5997.       case XYLEN:
  5998.     y = cmnum("Maximum number of characters in a packet","90",10,&x,
  5999.           xxstring);
  6000.     if (xx == XYRECV) {        /* Receive... */
  6001.         if ((y = setnum(&z,x,y,maxrps)) < 0)
  6002.           return(y);
  6003.         if (protocol != PROTO_K) {
  6004.         printf("?Sorry, this command does not apply to %s protocol.\n",
  6005.                ptab[protocol].p_name
  6006.                );
  6007.         printf("Use SET SEND PACKET-LENGTH for XYZMODEM\n");
  6008.         return(-9);
  6009.         }
  6010.         if (z < 10) {
  6011.         printf("Sorry, 10 is the minimum\n");
  6012.         return(-9);
  6013.         }
  6014.         if (rmsflg) {
  6015.         sstate = setgen('S', "401", ckitoa(z), "");
  6016.         return((int) sstate);
  6017.         } else {
  6018.         if (protocol == PROTO_K) {
  6019.             if (z > MAXRP) z = MAXRP;
  6020.             y = adjpkl(z,wslotr,bigrbsiz);
  6021.             if (y != z) {
  6022.             urpsiz = y;
  6023.             if (!cmdsrc())
  6024.               if (msgflg) printf(
  6025. " Adjusting receive packet-length to %d for %d window slots\n",
  6026.                          y, wslotr);
  6027.             }
  6028.             urpsiz = y;
  6029.             ptab[protocol].rpktlen = urpsiz;
  6030.             rpsiz =  (y > 94) ? 94 : y;
  6031.         } else {
  6032. #ifdef CK_XYZ
  6033.             if ((protocol == PROTO_X || protocol == PROTO_XC) &&
  6034.                          z != 128 && z != 1024) {
  6035.             printf("Sorry, bad packet length for XMODEM.\n");
  6036.             printf("Please use 128 or 1024.\n");
  6037.             return(-9);
  6038.             }
  6039. #endif /* CK_XYZ */
  6040.             urpsiz = rpsiz = z;
  6041.         }
  6042.         }
  6043.     } else {            /* Send... */
  6044.         if ((y = setnum(&z,x,y,maxsps)) < 0)
  6045.           return(y);
  6046.         if (z < 10) {
  6047.         printf("Sorry, 10 is the minimum\n");
  6048.         return(-9);
  6049.         }
  6050.         if (protocol == PROTO_K) {
  6051.         if (z > MAXSP) z = MAXSP;
  6052.         spsiz = z;        /* Set it */
  6053.         y = adjpkl(spsiz,wslotr,bigsbsiz);
  6054.         if (y != spsiz && !cmdsrc())
  6055.           if (msgflg)
  6056.             printf("Adjusting packet size to %d for %d window slots\n",
  6057.                y,wslotr);
  6058.         } else
  6059.           y = z;
  6060. #ifdef CK_XYZ
  6061.         if ((protocol == PROTO_X || protocol == PROTO_XC) &&
  6062.                  z != 128 && z != 1024) {
  6063.         printf("Sorry, bad packet length for XMODEM.\n");
  6064.         printf("Please use 128 or 1024.\n");
  6065.         return(-9);
  6066.         }
  6067. #endif /* CK_XYZ */
  6068.         spsiz = spmax = spsizr = y;    /* Set it and flag that it was set */
  6069.         spsizf = 1;            /* to allow overriding Send-Init. */
  6070.         ptab[protocol].spktflg = spsizf;
  6071.         ptab[protocol].spktlen = spsiz;
  6072.     }
  6073.     if (pflag && protocol == PROTO_K && !cmdsrc()) {
  6074.         if (z > 94 && !reliable && msgflg) {
  6075.         /* printf("Extended-length packets requested.\n"); */
  6076.         if (bctr < 2 && z > 200) printf("\
  6077. Remember to SET BLOCK 2 or 3 for long packets.\n");
  6078.         }
  6079.         if (speed <= 0L) speed = ttgspd();
  6080. #ifdef COMMENT
  6081. /*
  6082.   Kermit does this now itself.
  6083. */
  6084.         if (speed <= 0L && z > 200 && msgflg) {
  6085.         printf("\
  6086. Make sure your timeout interval is long enough for %d-byte packets.\n",z);
  6087.         }
  6088. #endif /* COMMENT */
  6089.     }
  6090.     return(success = y);
  6091.  
  6092.       case XYMARK:
  6093. #ifdef DOOMSDAY
  6094. /*
  6095.   Printable start-of-packet works for UNIX and VMS only!
  6096. */
  6097.     x_ifnum = 1;
  6098.     y = cmnum("Code for packet-start character","1",10,&x,xxstring);
  6099.     x_ifnum = 0;
  6100.     if ((y = setnum(&z,x,y,126)) < 0) return(y);
  6101. #else
  6102.     if ((y = setcc("1",&z)) < 0)
  6103.         return(y);
  6104. #endif /* DOOMSDAY */
  6105.     if (xx == XYRECV)
  6106.       stchr = (CHAR) z;
  6107.     else {
  6108.         mystch = (CHAR) z;
  6109. #ifdef IKS_OPTION
  6110.         /* If IKS negotiation in use   */
  6111.         if (TELOPT_U(TELOPT_KERMIT) || TELOPT_ME(TELOPT_KERMIT))
  6112.           tn_siks(KERMIT_SOP);    /* Report change to other side */
  6113. #endif /* IKS_OPTION */
  6114.         }
  6115.     return(success = y);
  6116.  
  6117.       case XYNPAD:            /* PADDING */
  6118.     y = cmnum("How many padding characters for inbound packets","0",10,&x,
  6119.           xxstring);
  6120.     if ((y = setnum(&z,x,y,94)) < 0) return(y);
  6121.     if (xx == XYRECV)
  6122.       mypadn = (CHAR) z;
  6123.     else
  6124.       npad = (CHAR) z;
  6125.     return(success = y);
  6126.  
  6127.       case XYPADC:            /* PAD-CHARACTER */
  6128.     if ((y = setcc("0",&z)) < 0) return(y);
  6129.     if (xx == XYRECV) mypadc = z; else padch = z;
  6130.     return(success = y);
  6131.  
  6132.       case XYTIMO:            /* TIMEOUT */
  6133.     if (xx == XYRECV) {
  6134.         y = cmnum("Packet timeout interval",ckitoa(URTIME),10,&x,xxstring);
  6135.         if ((y = setnum(&z,x,y,94)) < 0) return(y);
  6136.  
  6137.         if (rmsflg) {        /* REMOTE SET RECEIVE TIMEOUT */
  6138.         sstate = setgen('S', "402", ckitoa(z), "");
  6139.         return((int) sstate);
  6140.         } else {            /* SET RECEIVE TIMEOUT */
  6141.         pkttim = z;        /*   Value to put in my negotiation */
  6142.         }                /*   packet for other Kermit to use */
  6143.  
  6144.     } else {            /* SET SEND TIMEOUT */
  6145. #ifdef CK_TIMERS
  6146.         extern int rttflg, mintime, maxtime;
  6147.         int tmin = 0, tmax = 0;
  6148. #endif /* CK_TIMERS */
  6149.         y = cmnum("Packet timeout interval","",10,&x,xxstring);
  6150.         if (y == -3) {        /* They cancelled a previous */
  6151.         x = DMYTIM;        /* SET SEND command, so restore */
  6152.         timef = 0;        /* and turn off the override flag */
  6153.         y = cmcfm();
  6154.         }
  6155. #ifdef CK_TIMERS
  6156.         if (y < 0) return(y);
  6157.         if (x < 0) {
  6158.         printf("?Out of range - %d\n",x);
  6159.         return(-9);
  6160.         }
  6161.         if ((z = cmkey(timotab,2,"","dynamic",xxstring)) < 0) return(z);
  6162.         if (z) {
  6163.         if ((y = cmnum("Minimum timeout to allow",
  6164.                    "1",10,&tmin,xxstring)) < 0)
  6165.           return(y);
  6166.         if (tmin < 1) {
  6167.             printf("?Out of range - %d\n",x);
  6168.             return(-9);
  6169.         }
  6170.         if ((y = cmnum("Maximum timeout to allow",
  6171.                    "0",10,&tmax,xxstring)) < 0)
  6172.           return(y);
  6173.         /* 0 means let Kermit choose, < 0 means no maximum */
  6174.         }
  6175.         if ((y = cmcfm()) < 0)
  6176.           return(y);
  6177.         rttflg = z;            /* Round-trip timer flag */
  6178.         z = x;
  6179. #else
  6180.         if ((y = setnum(&z,x,y,94)) < 0)
  6181.           return(y);
  6182. #endif /* CK_TIMERS */
  6183.         timef = 1;            /* Turn on the override flag */
  6184.         timint = rtimo = z;        /* Override value for me to use */
  6185. #ifdef CK_TIMERS
  6186.         if (rttflg) {        /* Lower and upper bounds */
  6187.         mintime = tmin;
  6188.         maxtime = tmax;
  6189.         }
  6190. #endif /* CK_TIMERS */
  6191.     }
  6192.     return(success = 1);
  6193.  
  6194.       case XYFPATH:            /* PATHNAMES */
  6195.     if (xx == XYRECV) {
  6196.         y = cmkey(rpathtab,nrpathtab,"","auto",xxstring);
  6197.     } else {
  6198.         y = cmkey(pathtab,npathtab,"","off",xxstring);
  6199.     }
  6200.     if (y < 0) return(y);
  6201.  
  6202.     if ((x = cmcfm()) < 0) return(x);
  6203.     if (xx == XYRECV) {        /* SET RECEIVE PATHNAMES */
  6204.         fnrpath = y;
  6205.         ptab[protocol].fnrp = fnrpath;
  6206.     } else {            /* SET SEND PATHNAMES */
  6207.         fnspath = y;
  6208.         ptab[protocol].fnsp = fnspath;
  6209.     }
  6210.     return(success = 1);        /* Note: 0 = ON, 1 = OFF */
  6211.     /* In other words, ON = leave pathnames ON, OFF = take them off. */
  6212.  
  6213.       case XYPAUS:            /* SET SEND/RECEIVE PAUSE */
  6214.     y = cmnum("Milliseconds to pause between packets","0",10,&x,xxstring);
  6215.     if ((y = setnum(&z,x,y,15000)) < 0)
  6216.       return(y);
  6217.     pktpaus = z;
  6218.     return(success = 1);
  6219.  
  6220. #ifdef CKXXCHAR                /* SET SEND/RECEIVE IGNORE/DOUBLE */
  6221.       case XYIGN:
  6222.       case XYDBL: {
  6223.       int i, zz;
  6224.       short *p;
  6225.       extern short dblt[];
  6226.       extern int dblflag, ignflag;
  6227.  
  6228.       /* Make space for a temporary copy of the ignore/double table */
  6229.  
  6230.       zz = y;
  6231. #ifdef COMMENT
  6232.       if (zz == XYIGN && xx == XYSEND) {
  6233.           blah blah who cares
  6234.       }
  6235.       if (zz == XYDBL && xx == XYRECV) {
  6236.           blah blah
  6237.       }
  6238. #endif /* COMMENT */
  6239.       p = (short *)malloc(256 * sizeof(short));
  6240.       if (!p) {
  6241.           printf("?Internal error - malloc failure\n");
  6242.           return(-9);
  6243.       }
  6244.       for (i = 0; i < 256; i++) p[i] = dblt[i]; /* Copy current table */
  6245.  
  6246.       while (1) {            /* Collect a list of numbers */
  6247. #ifndef NOSPL
  6248.           x_ifnum = 1;        /* Turn off complaints from eval() */
  6249. #endif /* NOSPL */
  6250.           if ((x = cmnum(zz == XYDBL ?
  6251.                  "Character to double" :
  6252.                  "Character to ignore",
  6253.                  "",10,&y,xxstring
  6254.                  )) < 0) {
  6255. #ifndef NOSPL
  6256.           x_ifnum = 0;
  6257. #endif /* NOSPL */
  6258.           if (x == -3)        /* Done */
  6259.             break;
  6260.           if (x == -2) {
  6261.               if (p) { free(p); p = NULL; }
  6262.               debug(F110,"SET S/R DOUBLE/IGNORE atmbuf",atmbuf,0);
  6263.               if (!ckstrcmp(atmbuf,"none",4,0) ||
  6264.               !ckstrcmp(atmbuf,"non",3,0) ||
  6265.               !ckstrcmp(atmbuf,"no",2,0) ||
  6266.               !ckstrcmp(atmbuf,"n",1,0)) {
  6267.               if ((x = cmcfm()) < 0) /* Get confirmation */
  6268.                 return(x);
  6269.               for (y = 0; y < 256; y++)
  6270.                 dblt[y] &= (zz == XYDBL) ? 1 : 2;
  6271.               if (zz == XYDBL) dblflag = 0;
  6272.               if (zz == XYIGN) ignflag = 0;
  6273.               return(success = 1);
  6274.               } else {
  6275.               printf(
  6276.                 "?Please specify a number or the word NONE\n");
  6277.               return(-9);
  6278.               }
  6279.           } else {
  6280.               free(p);
  6281.               p = NULL;
  6282.               return(x);
  6283.           }
  6284.           }
  6285. #ifndef NOSPL
  6286.           x_ifnum = 0;
  6287. #endif /* NOSPL */
  6288.           if (y < 0 || y > 255) {
  6289.           printf("?Please enter a character code in range 0-255\n");
  6290.           free(p);
  6291.           p = NULL;
  6292.           return(-9);
  6293.           }
  6294.           p[y] |= (zz == XYDBL) ? 2 : 1;
  6295.           if (zz == XYDBL) dblflag = 1;
  6296.           if (zz == XYIGN) ignflag = 1;
  6297.       } /* End of while loop */
  6298.  
  6299.       if ((x = cmcfm()) < 0) return(x);
  6300. /*
  6301.   Get here only if they have made no mistakes.  Copy temporary table back to
  6302.   permanent one, then free temporary table and return successfully.
  6303. */
  6304.       if (p) {
  6305.           for (i = 0; i < 256; i++) dblt[i] = p[i];
  6306.           free(p);
  6307.           p = NULL;
  6308.       }
  6309.       return(success = 1);
  6310.       }
  6311. #endif /* CKXXCHAR */
  6312.  
  6313. #ifdef PIPESEND
  6314.       case XYFLTR: {            /* SET { SEND, RECEIVE } FILTER */
  6315.       if ((y = cmtxt((xx == XYSEND) ?
  6316.         "Filter program for sending files -\n\
  6317.  use \\v(filename) to substitute filename" :
  6318.         "Filter program for receiving files -\n\
  6319.  use \\v(filename) to substitute filename",
  6320.              "",&s,NULL)) < 0)
  6321.         return(y);
  6322.       if (!*s) {            /* Removing a filter... */
  6323.           if (xx == XYSEND && sndfilter) {
  6324.           free(sndfilter);
  6325.           sndfilter = NULL;
  6326.           } else if (rcvfilter) {
  6327.           free(rcvfilter);
  6328.           rcvfilter = NULL;
  6329.           }
  6330.           return(success = 1);
  6331.       }                /* Adding a filter... */
  6332.       s = brstrip(s);        /* Strip any braces */
  6333.       y = strlen(s);
  6334.       if (xx == XYSEND) {        /* For SEND filter... */
  6335.           for (x = 0; x < y; x++) {    /* make sure they included "\v(...)" */
  6336.           if (s[x] != '\\') continue;
  6337.           if (s[x+1] == 'v') break;
  6338.           }
  6339.           if (x == y) {
  6340.           printf(
  6341.           "?Filter must contain a replacement variable for filename.\n"
  6342.              );
  6343.           return(-9);
  6344.           }
  6345.       }
  6346.       if (xx == XYSEND) {
  6347.           makestr(&sndfilter,s);
  6348.       } else {
  6349.           makestr(&rcvfilter,s);
  6350.       }
  6351.       return(success = 1);
  6352.       }
  6353. #endif /* PIPESEND */
  6354.  
  6355.       case XYINIL:
  6356.     y = cmnum("Max length for protocol init string","-1",10,&x,xxstring);
  6357.     if ((y = setnum(&z,x,y,-1)) < 0)
  6358.       return(y);
  6359.     if (xx == XYSEND)
  6360.       sprmlen = z;
  6361.     else
  6362.       rprmlen = z;
  6363.     return(success = 1);
  6364.  
  6365. #ifndef NOCSETS
  6366.       case XYCSET: {            /* CHARACTER-SET-SELECTION */
  6367.       extern struct keytab xfrmtab[];
  6368.       extern int r_cset, s_cset;
  6369.       if ((y = cmkey(xfrmtab,2,"","automatic",xxstring)) < 0)
  6370.         return(y);
  6371.       if ((x = cmcfm()) < 0)
  6372.         return(x);
  6373.       if (xx == XYSEND)
  6374.         s_cset = y;
  6375.       else
  6376.         r_cset = y;
  6377.       return(success = 1);
  6378.       }
  6379. #endif /* NOCSETS */
  6380.  
  6381.       case XYBUP:
  6382.     if ((y = cmkey(onoff,2,"","on",xxstring)) < 0)
  6383.       return(y);
  6384.     if ((x = cmcfm()) < 0) return(x);
  6385.     if (xx == XYSEND) {
  6386.         extern int skipbup;
  6387.         skipbup = (y == 0) ? 1 : 0;
  6388.         return(success = 1);
  6389.     } else {
  6390.         printf(
  6391. "?Please use SET FILE COLLISION to choose the desired action\n");
  6392.         return(-9);
  6393.     }
  6394.  
  6395.       case XYMOVE:
  6396.     y = cmdir("Directory to move file(s) to after successful transfer",
  6397.           "",&s,xxstring);
  6398.     if (y < 0 && y != -3)
  6399.       return(y);
  6400.     strcpy(line,s);
  6401.     s = brstrip(line);
  6402.     if ((x = cmcfm()) < 0)
  6403.       return(x);
  6404.     if (xx == XYSEND) {
  6405.         if (*s) {
  6406.         makestr(&snd_move,s);
  6407.         makestr(&g_snd_move,s);
  6408.         } else {
  6409.         makestr(&snd_move,NULL);
  6410.         makestr(&g_snd_move,NULL);
  6411.         }
  6412.     } else {
  6413.         if (*s) {
  6414.         makestr(&rcv_move,s);
  6415.         makestr(&g_rcv_move,s);
  6416.         } else {
  6417.         makestr(&rcv_move,NULL);
  6418.         makestr(&g_rcv_move,NULL);
  6419.         }
  6420.     }
  6421.     return(success = 1);
  6422.  
  6423.       case XYRENAME:
  6424.     y = cmdir("Template to rename file(s) to after successful transfer",
  6425.           "",&s,NULL);
  6426.     if (y < 0 && y != -3)
  6427.       return(y);
  6428.     strcpy(line,s);
  6429.     s = brstrip(line);
  6430.     if ((x = cmcfm()) < 0)
  6431.       return(x);
  6432.     if (xx == XYSEND) {
  6433.         if (*s) {
  6434.         makestr(&snd_rename,s);
  6435.         makestr(&g_snd_rename,s);
  6436.         } else {
  6437.         makestr(&snd_rename,NULL);
  6438.         makestr(&g_snd_rename,NULL);
  6439.         }
  6440.     } else {
  6441.         if (*s) {
  6442.         makestr(&rcv_rename,s);
  6443.         makestr(&g_rcv_rename,s);
  6444.         } else {
  6445.         makestr(&rcv_rename,NULL);
  6446.         makestr(&g_rcv_rename,NULL);
  6447.         }
  6448.     }
  6449.     return(success = 1);
  6450.  
  6451. #ifdef VMS
  6452.       case 887:            /* VERSION-NUMBERS */
  6453.     if (xx == XYSEND) {
  6454.         extern int vmssversions;
  6455.         return(seton(&vmssversions));
  6456.     } else {
  6457.         extern int vmsrversions;
  6458.         return(seton(&vmsrversions));
  6459.     }
  6460. #endif /* VMS */
  6461.  
  6462.       default:
  6463.     return(-2);
  6464.     }                    /* End of SET SEND/RECEIVE... */
  6465. }
  6466. #endif /* NOXFER */
  6467.  
  6468. #ifndef NOXMIT
  6469. int
  6470. setxmit() {
  6471.     if ((y = cmkey(xmitab,nxmit,"","",xxstring)) < 0) return(y);
  6472.     switch (y) {
  6473.       case XMITE:            /* EOF */
  6474.     y = cmtxt("Characters to send at end of file,\n\
  6475.  Use backslash codes for control characters","",&s,xxstring);
  6476.     if (y < 0) return(y);
  6477.     if ((int)strlen(s) > XMBUFL) {
  6478.         printf("?Too many characters, %d maximum\n",XMBUFL);
  6479.         return(-2);
  6480.     }
  6481.     strcpy(xmitbuf,s);
  6482.     return(success = 1);
  6483.  
  6484.       case XMITF:            /* Fill */
  6485.     y = cmnum("Numeric code for blank-line fill character","0",10,&x,
  6486.           xxstring);
  6487.     if ((y = setnum(&z,x,y,127)) < 0) return(y);
  6488.     xmitf = z;
  6489.     return(success = 1);
  6490.       case XMITL:            /* Linefeed */
  6491.         return(seton(&xmitl));
  6492.       case XMITS:            /* Locking-Shift */
  6493.         return(seton(&xmits));
  6494.       case XMITP:            /* Prompt */
  6495.     y = cmnum("Numeric code for host's prompt character, 0 for none",
  6496.           "10",10,&x,xxstring);
  6497.     if ((y = setnum(&z,x,y,127)) < 0) return(y);
  6498.     xmitp = z;
  6499.     return(success = 1);
  6500.       case XMITX:            /* Echo */
  6501.         return(seton(&xmitx));
  6502.       case XMITW:            /* Pause */
  6503.     y = cmnum("Number of milliseconds to pause between binary characters\n\
  6504. or text lines during transmission","0",10,&x,xxstring);
  6505.     if ((y = setnum(&z,x,y,1000)) < 0) return(y);
  6506.     xmitw = z;
  6507.     return(success = 1);
  6508.       case XMITT:            /* Timeout */
  6509.     y = cmnum("Seconds to wait for each character to echo",
  6510.           "1",10,&x,xxstring);
  6511.     if ((y = setnum(&z,x,y,1000)) < 0) return(y);
  6512.     xmitt = z;
  6513.     return(success = 1);
  6514.       default:
  6515.     return(-2);
  6516.     }
  6517. }
  6518. #endif /* NOXMIT */
  6519.  
  6520. /*  D O R M T  --  Do a remote command  */
  6521.  
  6522. VOID
  6523. rmsg() {
  6524.     if (pflag)
  6525.       printf(
  6526. #ifdef CK_NEED_SIG
  6527.        " Type your escape character, %s, followed by X or E to cancel.\n",
  6528.        dbchr(escape)
  6529. #else
  6530.        " Press the X or E key to cancel.\n"
  6531. #endif /* CK_NEED_SIG */
  6532.       );
  6533. }
  6534.  
  6535. #ifndef NOXFER
  6536. static int xzcmd = 0;            /* Global copy of REMOTE cmd index */
  6537.  
  6538. /*  R E M C F M  --  Confirm a REMOTE command  */
  6539. /*
  6540.   Like cmcfm(), but allows for a redirection indicator on the end,
  6541.   like "> filename" or "| command".  Returns what cmcfm() would have
  6542.   returned: -1 if reparse needed, etc etc blah blah.  On success,
  6543.   returns 1 with:
  6544.  
  6545.     char * remdest containing the name of the file or command.
  6546.     int remfile set to 1 if there is to be any redirection.
  6547.     int rempipe set to 1 if remdest is a command, 0 if it is a file.
  6548. */
  6549. static int
  6550. remcfm() {
  6551.     int x;
  6552.     char *s;
  6553.     char c;
  6554.  
  6555.     remfile = 0;
  6556.     rempipe = 0;
  6557.     if ((x = cmtxt(
  6558.          "> filename, | command,\n\
  6559. or type carriage return to confirm the command",
  6560.            "",&s,xxstring)) < 0)
  6561.       return(x);
  6562.     if (remdest) {
  6563.     free(remdest);
  6564.     remdest = NULL;
  6565.     }
  6566.     debug(F101,"remcfm local","",local);
  6567.     debug(F110,"remcfm s",s,0);
  6568.     debug(F101,"remcfm cmd","",xzcmd);
  6569.  
  6570.     if (!*s) {                /* No redirection indicator */
  6571.     if (!local &&
  6572.         (xzcmd == XZDIR || xzcmd == XZTYP ||
  6573.          xzcmd == XZXIT || xzcmd == XZSPA ||
  6574.          xzcmd == XZHLP || xzcmd == XZPWD ||
  6575.          xzcmd == XZLGI || xzcmd == XZLGO ||
  6576.          xzcmd == XZWHO || xzcmd == XZHOS)) {
  6577.         printf("?\"%s\" has no effect in remote mode\n",cmdbuf);
  6578.         return(-9);
  6579.     } else
  6580.       return(1);
  6581.     }
  6582.     c = *s;                /* We have something */
  6583.     if (c != '>' && c != '|') {        /* Is it > or | ? */
  6584.     printf("?Not confirmed\n");    /* No */
  6585.     return(-9);
  6586.     }
  6587.     s++;                /* See what follows */
  6588.     if (c == '>' && *s == '>') {    /* Allow for ">>" too */
  6589.     s++;
  6590.     remappd = 1;            /* Append to output file */
  6591.     }
  6592.     while (*s == SP || *s == HT) s++;    /* Strip intervening whitespace */
  6593.     if (!*s) {
  6594.     printf("?%s missing\n", c == '>' ? "Filename" : "Command");
  6595.     return(-9);
  6596.     }
  6597.     if (c == '>' && zchko(s) < 0) {    /* Check accessibility */
  6598.     printf("?Access denied - %s\n", s);
  6599.     return(-9);
  6600.     }
  6601.     remfile = 1;            /* Set global results */
  6602.     rempipe = (c == '|');
  6603.     if (rempipe
  6604. #ifndef NOPUSH
  6605.     && nopush
  6606. #endif /* NOPUSH */
  6607.     ) {
  6608.     printf("?Sorry, access to external commands is disabled.\n");
  6609.     return(-9);
  6610.     }
  6611.     makestr(&remdest,s);
  6612. #ifndef NODEBUG
  6613.     if (deblog) {
  6614.     debug(F101,"remcfm remfile","",remfile);
  6615.     debug(F101,"remcfm remappd","",remappd);
  6616.     debug(F101,"remcfm rempipe","",rempipe);
  6617.     debug(F110,"remcfm remdest",remdest, 0);
  6618.     }
  6619. #endif /* NODEBUG */
  6620.     return(1);
  6621. }
  6622.  
  6623. /*  R E M T X T  --  Like remcfm()...  */
  6624. /*
  6625.    ... but for REMOTE commands that end with cmtxt().
  6626.    Here we must decipher braces to discover whether the trailing
  6627.    redirection indicator is intended for local use, or to be sent out
  6628.    to the server, as in:
  6629.  
  6630.      remote host blah blah > file                 This end
  6631.      remote host { blah blah } > file             This end
  6632.      remote host { blah blah > file }             That end
  6633.      remote host { blah blah > file } > file      Both ends
  6634.  
  6635.    Pipes too:
  6636.  
  6637.      remote host blah blah | cmd                  This end
  6638.      remote host { blah blah } | cmd              This end
  6639.      remote host { blah blah | cmd }              That end
  6640.      remote host { blah blah | cmd } | cmd        Both ends
  6641.  
  6642.    Or both:
  6643.  
  6644.      remote host blah blah | cmd > file           This end, etc etc...
  6645.  
  6646.    Note: this really only makes sense for REMOTE HOST, but why be picky?
  6647.    Call after calling cmtxt(), with pointer to string that cmtxt() parsed,
  6648.    as in "remtxt(&s);".
  6649.  
  6650.    Returns:
  6651.     1 on success with braces & redirection things removed & pointer updated,
  6652.    -9 on failure (bad indirection), after printing error message.
  6653. */
  6654. static int
  6655. remtxt(p) char ** p; {
  6656.     int i, x, bpos, ppos;
  6657.     char c, *s, *q;
  6658.  
  6659.     remfile = 0;            /* Initialize global results */
  6660.     rempipe = 0;
  6661.     remappd = 0;
  6662.     if (remdest) {
  6663.     free(remdest);
  6664.     remdest = NULL;
  6665.     }
  6666.     s = *p;
  6667.     if (!s)                /* No redirection indicator */
  6668.       s = "";
  6669.     if (!*s) {                /* Ditto */
  6670.     if (!local &&
  6671.         (xzcmd == XZDIR || xzcmd == XZTYP ||
  6672.          xzcmd == XZXIT || xzcmd == XZSPA ||
  6673.          xzcmd == XZHLP || xzcmd == XZPWD ||
  6674.          xzcmd == XZLGI || xzcmd == XZLGO ||
  6675.          xzcmd == XZWHO || xzcmd == XZHOS)) {
  6676.         printf("?\"%s\" has no effect in remote mode\n",cmdbuf);
  6677.         if (hints) {
  6678.         printf("Hint: try again with an output redirector.\n");
  6679.         }
  6680.         return(-9);
  6681.     } else
  6682.       return(1);
  6683.     }
  6684.     bpos = -1;                /* Position of > (bracket) */
  6685.     ppos = -1;                /* Position of | (pipe) */
  6686.     x = strlen(s);            /* Length of cmtxt() string */
  6687.  
  6688.     for (i = x-1; i >= 0; i--) {    /* Search right to left. */
  6689.     c = s[i];
  6690.     if (c == '}')            /* Break on first right brace */
  6691.       break;            /* Don't look at contents of braces */
  6692.     else if (c == '>')        /* Record position of > */
  6693.       bpos = i;
  6694.     else if (c == '|')        /* and of | */
  6695.       ppos = i;
  6696.     }
  6697.     if (bpos < 0 && ppos < 0) {        /* No redirectors. */
  6698.     if (!local &&
  6699.         (xzcmd == XZDIR || xzcmd == XZTYP ||
  6700.          xzcmd == XZXIT || xzcmd == XZSPA ||
  6701.          xzcmd == XZHLP || xzcmd == XZPWD ||
  6702.          xzcmd == XZLGI || xzcmd == XZLGO ||
  6703.          xzcmd == XZWHO || xzcmd == XZHOS)) {
  6704.         printf("?\"%s\" has no effect in remote mode\n",cmdbuf);
  6705.         if (hints) {
  6706.         printf("Hint: try again with an output redirector.\n");
  6707.         }
  6708.         return(-9);
  6709.     }
  6710.     s = brstrip(s);            /* Remove outer braces if any. */
  6711.     *p = s;                /* Point to result */
  6712.     return(1);            /* and return. */
  6713.     }
  6714.     remfile = 1;            /* It's | or > */
  6715.     i = -1;                /* Get leftmost symbol */
  6716.     if (bpos > -1)            /* Bracket */
  6717.       i = bpos;
  6718.     if (ppos > -1 && (ppos < bpos || bpos < 0)) { /* or pipe */
  6719.     i = ppos;
  6720.     rempipe = 1;
  6721.     }
  6722.     c = s[i];                /* Copy of symbol */
  6723.  
  6724.     if (c == '>' && s[i+1] == '>')    /* ">>" for append? */
  6725.       remappd = 1;               /* It's not just a flag it's a number */
  6726.  
  6727.     q = s + i + 1 + remappd;        /* Point past symbol in string */
  6728.     while (*q == SP || *q == HT) q++;    /* and any intervening whitespace */
  6729.     if (!*q) {
  6730.     printf("?%s missing\n", c == '>' ? "Filename" : "Command");
  6731.     return(-9);
  6732.     }
  6733.     if (c == '>' && zchko(q) < 0) {    /* (Doesn't work for | cmd > file) */
  6734.     printf("?Access denied - %s\n", q);
  6735.     return(-9);
  6736.     }
  6737.     makestr(&remdest,q);        /* Create the destination string */
  6738.     q = s + i - 1;            /* Point before symbol */
  6739.     while (q > s && (*q == SP || *q == HT)) /* Strip trailing whitespace */
  6740.       q--;
  6741.     *(q+1) = NUL;            /* Terminate the string. */
  6742.     s = brstrip(s);            /* Remove any braces */
  6743.     *p = s;                /* Set return value */
  6744.  
  6745. #ifndef NODEBUG
  6746.     if (deblog) {
  6747.     debug(F101,"remtxt remfile","",remfile);
  6748.     debug(F101,"remtxt remappd","",remappd);
  6749.     debug(F101,"remtxt rempipe","",rempipe);
  6750.     debug(F110,"remtxt remdest",remdest, 0);
  6751.     debug(F110,"remtxt command",s,0);
  6752.     }
  6753. #endif /* NODEBUG */
  6754.  
  6755.     return(1);
  6756. }
  6757.  
  6758. int
  6759. plogin(xx) int xx; {
  6760.     char *p1 = NULL, *p2 = NULL, *p3 = NULL;
  6761.     int psaved = 0, rc = 0;
  6762. #ifdef CK_RECALL
  6763.     int sv_recall = -1;            /* For turning off command recall */
  6764.     extern int on_recall;        /* around Password prompting */
  6765. #endif /* CK_RECALL */
  6766.     debug(F101,"plogin local","",local);
  6767.  
  6768.     if (!local || (network && ttchk() < 0)) {
  6769.     printf("?No connection\n");
  6770.     return(-9);
  6771.     }
  6772.     if ((x = cmfld("User ID","",&s,xxstring)) < 0) { /* Get User ID */
  6773.     if (x != -3) return(x);
  6774.     }
  6775.     y = strlen(s);
  6776.     if (y > 0) {
  6777.     if ((p1 = malloc(y + 1)) == NULL) {
  6778.         printf("?Internal error: malloc\n");
  6779.         rc = -9;
  6780.         goto XZXLGI;
  6781.     } else
  6782.       strcpy(p1,s);
  6783.     if ((rc = cmfld("Password","",&s,xxstring)) < 0)
  6784.       if (rc != -3) goto XZXLGI;
  6785.     y = strlen(s);
  6786.     if (y > 0) {
  6787.         if ((p2 = malloc(y + 1)) == NULL) {
  6788.         printf("?Internal error: malloc\n");
  6789.         rc = -9;
  6790.         goto XZXLGI;
  6791.         } else
  6792.           strcpy(p2,s);
  6793.         if ((rc = cmfld("Account","",&s,xxstring)) < 0)
  6794.           if (rc != -3) goto XZXLGI;
  6795.         y = strlen(s);
  6796.         if (y > 0) {
  6797.         if ((p3 = malloc(y + 1)) == NULL) {
  6798.             printf("?Internal error: malloc\n");
  6799.             rc = -9;
  6800.             goto XZXLGI;
  6801.         } else
  6802.           strcpy(p3,s);
  6803.         }
  6804.     }
  6805.     }
  6806.     if ((rc = remtxt(&s)) < 0)        /* Confirm & handle redirectors */
  6807.       goto XZXLGI;
  6808.  
  6809.     if (!p1) {                /* No Userid specified... */
  6810.     /* Prompt for username, password, and account */
  6811. #ifdef CK_RECALL
  6812.     sv_recall = on_recall;
  6813.     on_recall = 0;
  6814. #endif /* CK_RECALL */
  6815.     cmsavp(psave,PROMPTL);        /* Save old prompt */
  6816.     psaved = 1;
  6817.     debug(F110,"REMOTE LOGIN saved",psave,0);
  6818.  
  6819.     cmsetp("Username: ");        /* Make new prompt */
  6820.     concb((char)escape);        /* Put console in cbreak mode */
  6821.     cmini(1);
  6822.     prompt(xxstring);
  6823.     rc = -9;
  6824.     for (x = -1; x < 0; ) {        /* Prompt till they answer */
  6825.         cmres();            /* Reset the parser */
  6826.         x = cmtxt("","",&s,NULL);    /* Get a literal line of text */
  6827.     }
  6828.     y = strlen(s);
  6829.     if (y < 1) {
  6830.         printf("?Canceled\n");
  6831.         goto XZXLGI;
  6832.     }
  6833.     if ((p1 = malloc(y + 1)) == NULL) {
  6834.         printf("?Internal error: malloc\n");
  6835.         goto XZXLGI;
  6836.     } else
  6837.       strcpy(p1,s);
  6838.  
  6839.     cmsetp("Password: ");        /* Make new prompt */
  6840.     concb((char)escape);        /* Put console in cbreak mode */
  6841.     cmini(0);            /* No echo */
  6842.     prompt(xxstring);
  6843.     for (x = -1; x < 0 && x != -3; ) { /* Get answer */
  6844.         cmres();            /* Reset the parser */
  6845.         x = cmtxt("","",&s,NULL);    /* Get literal line of text */
  6846.     }
  6847.     if ((p2 = malloc((int)strlen(s) + 1)) == NULL) {
  6848.         printf("?Internal error: malloc\n");
  6849.         goto XZXLGI;
  6850.     } else
  6851.       strcpy(p2,s);
  6852.     printf("\r\n");
  6853.     if ((rc = cmcfm()) < 0)
  6854.       goto XZXLGI;
  6855.     }
  6856.     sstate = setgen('I',p1,p2,p3);    /* Get here with at least user ID */
  6857.     rc = 0;
  6858.  
  6859.   XZXLGI:                /* Common exit point */
  6860.     if (psaved)
  6861.       cmsetp(psave);            /* Restore original prompt */
  6862. #ifdef CK_RECALL
  6863.     if (sv_recall > -1)            /* Put back command recall */
  6864.       on_recall = sv_recall;
  6865. #endif /* CK_RECALL */
  6866.     if (p3) { free(p3); p3 = NULL; }    /* Free malloc'd storage */
  6867.     if (p2) { free(p2); p2 = NULL; }
  6868.     if (p1) { free(p1); p1 = NULL; }
  6869.     if (rc > -1) {
  6870.     if (local && rc > -1)        /* If local, flush tty input buffer */
  6871.       ttflui();
  6872.     }
  6873.     return(rc);
  6874. }
  6875.  
  6876. #ifdef OS2
  6877. int
  6878. dormt(xx) int xx; {
  6879.     int rc = 0;
  6880.     extern int term_io;
  6881.     int term_io_sav = term_io;
  6882.     term_io = 0;
  6883.     rc = xxdormt(xx);
  6884.     term_io = term_io_sav;
  6885.     return rc;
  6886. }
  6887.  
  6888.  
  6889. int
  6890. xxdormt(xx) int xx;
  6891. #else /* OS2 */
  6892. int
  6893. dormt(xx) int xx;
  6894. #endif /* OS2 */
  6895. {                    /* REMOTE commands */
  6896.     int x, y, retcode;
  6897.     char *s, sbuf[50], *s2;
  6898.  
  6899.     remfile = 0;            /* Clear these */
  6900.     rempipe = 0;
  6901.     remappd = 0;
  6902.  
  6903.     if (xx < 0) return(xx);        /* REMOTE what? */
  6904.  
  6905.     xzcmd = xx;                /* Make global copy of arg */
  6906.  
  6907.     if (xx == XZSET) {            /* REMOTE SET */
  6908.     if ((y = cmkey(rmstab,nrms,"","",xxstring)) < 0) {
  6909.         if (y == -3) {
  6910.         printf("?Parameter name required\n");
  6911.         return(-9);
  6912.         } else return(y);
  6913.     }
  6914.     return(doprm(y,1));
  6915.     }
  6916.  
  6917.     switch (xx) {            /* Others... */
  6918.  
  6919.       case XZCWD:            /* CWD (CD) */
  6920.     if ((x = cmtxt("Remote directory name","",&s,xxstring)) < 0)
  6921.       return(x);
  6922.     if ((x = remtxt(&s)) < 0)
  6923.       return(x);
  6924.     debug(F111,"XZCWD: ",s,x);
  6925.     *sbuf = NUL;
  6926.     s2 = sbuf;
  6927. /*
  6928.   The following is commented out because since the disappearance of the
  6929.   DECSYSTEM-20 from the planet, no known computer requires a password for
  6930.   changing directory.
  6931. */
  6932. #ifdef DIRPWDPR
  6933.     if (*s != NUL) {        /* If directory name given, */
  6934.                     /* get password on separate line. */
  6935.         if (tlevel > -1) {        /* From take file... */
  6936.  
  6937.         if (fgets(sbuf,50,tfile[tlevel]) == NULL)
  6938.           fatal("take file ends prematurely in 'remote cwd'");
  6939.         debug(F110," pswd from take file",s2,0);
  6940.         for (x = (int)strlen(sbuf);
  6941.              x > 0 && (sbuf[x-1] == NL || sbuf[x-1] == CR);
  6942.              x--)
  6943.           sbuf[x-1] = '\0';
  6944.  
  6945.         } else {            /* From terminal... */
  6946.  
  6947.         printf(" Password: ");    /* get a password */
  6948. #ifdef IKSD
  6949.                 if (!local && inserver) {
  6950.                     x = coninc(0);
  6951.                 } else
  6952. #endif /* IKSD */
  6953. #ifdef OS2
  6954.           x = is_a_tty(0) ? coninc(0) : /* with no echo ... */
  6955.                     getchar();
  6956. #else /* OS2 */
  6957.                 x = getchar();
  6958. #endif /* OS2 */
  6959.         while ((x != NL) && (x != CR)) {
  6960.             if ((x &= 0177) == '?') {
  6961.             printf("? Password of remote directory\n Password: ");
  6962.             s2 = sbuf;
  6963.             *sbuf = NUL;
  6964.             } else if (x == ESC) /* Mini command line editor... */
  6965.               bleep(BP_WARN);
  6966.             else if (x == BS || x == 0177)
  6967.               s2--;
  6968.             else if (x == 025) {    /* Ctrl-U */
  6969.             s2 = sbuf;
  6970.             *sbuf = NUL;
  6971.             } else
  6972.               *s2++ = x;
  6973.  
  6974.                     /* Get the next character */
  6975. #ifdef IKSD
  6976.                     if (!local && inserver) {
  6977.                         x = coninc(0);
  6978.                     } else
  6979. #endif /* IKSD */
  6980. #ifdef OS2
  6981.                     x = is_a_tty(0) ? coninc(0) : /* with no echo ... */
  6982.               getchar();
  6983. #else /* OS2 */
  6984.                     x = getchar();
  6985. #endif /* OS2 */
  6986.         }
  6987.         *s2 = NUL;
  6988.         putchar('\n');
  6989.         }
  6990.         s2 = sbuf;
  6991.     } else s2 = "";
  6992. #endif /* DIRPWDPR */
  6993.  
  6994.     debug(F110," password",s2,0);
  6995.     sstate = setgen('C',s,s2,"");
  6996.     retcode = 0;
  6997.     break;
  6998.  
  6999.       case XZDEL:                /* Delete */
  7000.     if ((x = cmtxt("Name of remote file(s) to delete",
  7001.                "",&s,xxstring)) < 0) {
  7002.         if (x == -3) {
  7003.         printf("?Name of remote file(s) required\n");
  7004.         return(-9);
  7005.         } else return(x);
  7006.     }
  7007.     if ((x = remtxt(&s)) < 0)
  7008.       return(x);
  7009.     if (local) ttflui();        /* If local, flush tty input buffer */
  7010.     retcode = sstate = rfilop(s,'E');
  7011.     break;
  7012.  
  7013.       case XZDIR:            /* Directory */
  7014.     if ((x = cmtxt("Remote directory or file specification","",&s,
  7015.                xxstring)) < 0)
  7016.       return(x);
  7017.     if ((x = remtxt(&s)) < 0)
  7018.       return(x);
  7019.     if (local) ttflui();        /* If local, flush tty input buffer */
  7020.     rmsg();
  7021.     retcode = sstate = setgen('D',s,"","");
  7022.     break;
  7023.  
  7024.       case XZHLP:            /* Help */
  7025.     if ((x = remcfm()) < 0) return(x);
  7026.     sstate = setgen('H',"","","");
  7027.     retcode = 0;
  7028.     break;
  7029.  
  7030.       case XZHOS:            /* Host */
  7031.     if ((x = cmtxt("Command for remote system","",&s,xxstring)) < 0)
  7032.       return(x);
  7033.     if ((x = remtxt(&s)) < 0)
  7034.       return(x);
  7035.     if ((y = (int)strlen(s)) < 1)
  7036.       return(x);
  7037.     strcpy(line,s);
  7038.     cmarg = line;
  7039.     rmsg();
  7040.     retcode = sstate = 'c';
  7041.     break;
  7042.  
  7043. #ifndef NOFRILLS
  7044.       case XZKER:
  7045.     if ((x = cmtxt("Command for remote Kermit","",&s,xxstring)) < 0)
  7046.       return(x);
  7047.     if ((x = remtxt(&s)) < 0)
  7048.       return(x);
  7049.     if ((int)strlen(s) < 1)  {
  7050.         if (x == -3) {
  7051.         printf("?Remote Kermit command required\n");
  7052.         return(-9);
  7053.         } else return(x);
  7054.     }
  7055.     strcpy(line,s);
  7056.     cmarg = line;
  7057.     retcode = sstate = 'k';
  7058.     rmsg();
  7059.     break;
  7060.  
  7061.       case XZLGI:            /* Login */
  7062.     return(plogin(XXREM));
  7063.  
  7064.       case XZLGO: {            /* Logout */
  7065.       extern int bye_active;
  7066.       if ((x = remcfm()) < 0) return(x);
  7067.       sstate = setgen('I',"","","");
  7068.       retcode = 0;
  7069.       bye_active = 1;        /* Close connection when done */
  7070.       break;
  7071.       }
  7072.  
  7073.       case XZPRI:            /* Print */
  7074.     if (!atdiso || !atcapr) {    /* Disposition attribute off? */
  7075.         printf("?Disposition Attribute is Off\n");
  7076.         return(-2);
  7077.     }
  7078.     cmarg = "";
  7079.     cmarg2 = "";
  7080.     if ((x = cmifi("Local file(s) to print on remote printer","",&s,&y,
  7081.                xxstring)) < 0) {
  7082.         if (x == -3) {
  7083.         printf("?Name of local file(s) required\n");
  7084.         return(-9);
  7085.         }
  7086.         return(x);
  7087.     }
  7088.     strcpy(line,s);            /* Make a safe copy of filename */
  7089.     *optbuf = NUL;            /* Wipe out any old options */
  7090.     if ((x = cmtxt("Options for remote print command","",&s,xxstring)) < 0)
  7091.       return(x);
  7092.     if ((x = remtxt(&s)) < 0)
  7093.       return(x);
  7094.     strcpy(optbuf,s);        /* Make a safe copy of options */
  7095.     if ((int)strlen(optbuf) > 94) {    /* Make sure this is legal */
  7096.         printf("?Option string too long\n");
  7097.         return(-9);
  7098.     }
  7099.     nfils = -1;            /* Expand file list internally */
  7100.     cmarg = line;            /* Point to file list. */
  7101.     rprintf = 1;            /* REMOTE PRINT modifier for SEND */
  7102.     sstate = 's';            /* Set start state to SEND */
  7103.     if (local) displa = 1;
  7104.     retcode = 0;
  7105.     break;
  7106. #endif /* NOFRILLS */
  7107.  
  7108.       case XZSPA:            /* Space */
  7109.     if ((x = cmtxt("Confirm, or remote directory name",
  7110.                "",&s,xxstring)) < 0)
  7111.       return(x);
  7112.     if ((x = remtxt(&s)) < 0)
  7113.       return(x);
  7114.     retcode = sstate = setgen('U',s,"","");
  7115.     break;
  7116.  
  7117. #ifndef NOFRILLS
  7118.       case XZTYP:            /* Type */
  7119.     if ((x = cmtxt("Remote file specification","",&s,xxstring)) < 0)
  7120.       return(x);
  7121.     if ((int)strlen(s) < 1) {
  7122.         printf("?Remote filename required\n");
  7123.         return(-9);
  7124.     }
  7125.     if ((x = remtxt(&s)) < 0)
  7126.       return(x);
  7127.     rmsg();
  7128.     retcode = sstate = rfilop(s,'T');
  7129.     break;
  7130. #endif /* NOFRILLS */
  7131.  
  7132. #ifndef NOFRILLS
  7133.       case XZWHO:
  7134.     if ((x = cmtxt("Remote user name, or carriage return",
  7135.                "",&s,xxstring)) < 0)
  7136.       return(x);
  7137.     if ((x = remtxt(&s)) < 0)
  7138.       return(x);
  7139.     retcode = sstate = setgen('W',s,"","");
  7140.     break;
  7141. #endif /* NOFRILLS */
  7142.  
  7143.       case XZPWD:            /* PWD */
  7144.     if ((x = remcfm()) < 0) return(x);
  7145.     sstate = setgen('A',"","","");
  7146.     retcode = 0;
  7147.     break;
  7148.  
  7149. #ifndef NOSPL
  7150.       case XZQUE: {            /* Query */
  7151.       char buf[2];
  7152.       extern char querybuf[], * qbufp;
  7153.       extern int qbufn;
  7154.       if ((y = cmkey(vartyp,nvartyp,"","",xxstring)) < 0)
  7155.         return(y);
  7156.       if ((x = cmtxt(y == 'F' ? "Remote function invocation" :
  7157.              ('K' ? "Remote variable name or function":
  7158.              "Remote variable name"),
  7159.              "",
  7160.              &s,
  7161.              (y == 'K') ? xxstring : NULL
  7162.              )) < 0)    /* Don't evaluate */
  7163.         return(x);
  7164.       if ((x = remtxt(&s)) < 0)
  7165.         return(x);
  7166.       query = 1;            /* QUERY is active */
  7167.       qbufp = querybuf;        /* Initialize query response buffer */
  7168.       qbufn = 0;
  7169.       querybuf[0] = NUL;
  7170.       buf[0] = (char) (y & 127);
  7171.       buf[1] = NUL;
  7172.       retcode = sstate = setgen('V',"Q",(char *)buf,s);
  7173.       break;
  7174.       }
  7175.  
  7176.       case XZASG: {            /* Assign */
  7177.       char buf[VNAML];
  7178.       if ((y = cmfld("Remote variable name","",&s,NULL)) < 0) /* No eval */
  7179.         return(y);
  7180.       strcpy(buf,s);
  7181.       if ((x = cmtxt("Assignment for remote variable",
  7182.            "",&s,xxstring)) < 0) /* Evaluate this one */
  7183.         return(x);
  7184.       if ((x = remtxt(&s)) < 0)
  7185.         return(x);
  7186. #ifdef COMMENT
  7187. /*
  7188.   Server commands can't be long packets.  In principle there's no reason
  7189.   why they shouldn't be, except that we don't know at this point if the
  7190.   server is capable of accepting long packets because we haven't started
  7191.   the protocol yet.  In practice, allowing a long packet here breaks a lot
  7192.   of assumptions, causes buffer overruns and crashes, etc.  To be fixed
  7193.   later.  (But since this is commented out, evidently I fixed it later...)
  7194. */
  7195.       if ((int)strlen(s) > 85) {    /* Allow for encoding expansion */
  7196.           printf("?Sorry, value is too long - 85 characters max\n");
  7197.           return(-9);
  7198.       }
  7199. #endif /* COMMENT */
  7200.       retcode = sstate = setgen('V',"S",(char *)buf,s);
  7201.       break;
  7202.       }
  7203. #endif /* NOSPL */
  7204.  
  7205. #ifndef MAXPATHLEN
  7206. #define MAXPATHLEN 256
  7207. #endif /* MAXPATHLEN */
  7208.  
  7209.       case XZCPY: {            /* Copy */
  7210.       char buf[MAXPATHLEN+1];
  7211.       buf[MAXPATHLEN] = '\0';
  7212.       if ((x = cmfld("Name of remote file to copy","",&s,xxstring)) < 0) {
  7213.           if (x == -3) {
  7214.           printf("?Name of remote file required\n");
  7215.           return(-9);
  7216.           }
  7217.           else
  7218.         return(x);
  7219.       }
  7220.       ckstrncpy(buf,s,MAXPATHLEN);
  7221.       if ((x = cmfld("Name of remote destination file or directory",
  7222.              "",&s, xxstring)) < 0) {
  7223.           if (x == -3) {
  7224.           printf("?Name of remote file or directory required\n");
  7225.           return(-9);
  7226.           } else return(x);
  7227.       }
  7228.       strcpy(tmpbuf,s);
  7229.       if ((x = remcfm()) < 0)
  7230.         return(x);
  7231.       if (local) ttflui();        /* If local, flush tty input buffer */
  7232.       retcode = sstate = setgen('K',buf,tmpbuf,"");
  7233.       break;
  7234.       }
  7235.       case XZREN: {            /* Rename */
  7236.       char buf[MAXPATHLEN+1];
  7237.       buf[MAXPATHLEN] = '\0';
  7238.       if ((x = cmfld("Name of remote file to rename",
  7239.              "",&s,xxstring)) < 0) {
  7240.           if (x == -3) {
  7241.           printf("?Name of remote file required\n");
  7242.           return(-9);
  7243.           } else return(x);
  7244.       }
  7245.       ckstrncpy(buf,s,MAXPATHLEN);
  7246.       if ((x = cmfld("New name of remote file","",&s, xxstring)) < 0) {
  7247.           if (x == -3) {
  7248.           printf("?Name of remote file required\n");
  7249.           return(-9);
  7250.           } else return(x);
  7251.       }
  7252.       strcpy(tmpbuf,s);
  7253.       if ((x = remcfm()) < 0)
  7254.         return(x);
  7255.       if (local) ttflui();        /* If local, flush device buffer */
  7256.       retcode = sstate = setgen('R',buf,tmpbuf,"");
  7257.       break;
  7258.       }
  7259.       case XZMKD:            /* mkdir */
  7260.       case XZRMD:            /* rmdir */
  7261.     if ((x = cmtxt((xx == XZMKD) ?
  7262.                "Name of remote directory to create" :
  7263.                "Name of remote directory to delete",
  7264.                "",
  7265.                &s,
  7266.                xxstring
  7267.                )) < 0) {
  7268.         if (x == -3) {
  7269.         printf("?Name required\n");
  7270.         return(-9);
  7271.         } else return(x);
  7272.     }
  7273.     if ((x = remtxt(&s)) < 0)
  7274.       return(x);
  7275.     if (local) ttflui();        /* If local, flush tty input buffer */
  7276.     retcode = sstate = rfilop(s, (char)(xx == XZMKD ? 'm' : 'd'));
  7277.     break;
  7278.  
  7279.       case XZXIT:            /* Exit */
  7280.     if ((x = remcfm()) < 0) return(x);
  7281.     sstate = setgen('X',"","","");
  7282.     retcode = 0;
  7283.     break;
  7284.  
  7285.       default:
  7286.         if ((x = remcfm()) < 0) return(x);
  7287.         printf("?Not implemented - %s\n",cmdbuf);
  7288.         return(-2);
  7289.     }
  7290.     if (local && retcode > -1)        /* If local, flush tty input buffer */
  7291.       ttflui();
  7292.     return(retcode);
  7293. }
  7294.  
  7295.  
  7296. /*  R F I L O P  --  Remote File Operation  */
  7297.  
  7298. CHAR
  7299. #ifdef CK_ANSIC
  7300. rfilop(char * s, char t)
  7301. #else
  7302. rfilop(s,t) char *s, t;
  7303. #endif /* CK_ANSIC */
  7304. /* rfilop */ {
  7305.     if (*s == NUL) {
  7306.     printf("?File specification required\n");
  7307.     return((CHAR) 0);
  7308.     }
  7309.     debug(F111,"rfilop",s,t);
  7310.     return(setgen(t,s,"",""));
  7311. }
  7312. #endif /* NOXFER */
  7313.  
  7314. #ifdef ANYX25
  7315. int
  7316. setx25() {
  7317.     if ((y = cmkey(x25tab,nx25,"X.25 call options","",xxstring)) < 0)
  7318.       return(y);
  7319.     switch (y) {
  7320.       case XYUDAT:
  7321.     if ((z = cmkey(onoff,2,"X.25 call user data","",xxstring))
  7322.         < 0) return(z);
  7323.     if (z == 0) {
  7324.         if ((z = cmcfm()) < 0) return(z);
  7325.         cudata = 0;             /* disable call user data */
  7326.         return (success = 1);
  7327.     }
  7328.     if ((x = cmtxt("X.25 call user data string","",&s,xxstring)) < 0)
  7329.       return(x);
  7330.     if ((int)strlen(s) == 0) {
  7331.         return (-3);
  7332.     } else if ((int)strlen(s) > MAXCUDATA) {
  7333.         printf("?The length must be > 0 and <= %d\n",MAXCUDATA);
  7334.         return(-2);
  7335.     }
  7336.     if ((y = cmcfm()) < 0) return(y);
  7337.     strcpy(udata,s);
  7338.     cudata = 1;            /* X.25 call user data specified */
  7339.     return (success = 1);
  7340.       case XYCLOS:
  7341.     if ((z = cmkey(onoff,2,"X.25 closed user group call","",xxstring))
  7342.         < 0) return(z);
  7343.     if (z == 0) {
  7344.         if ((z = cmcfm()) < 0) return(z);
  7345.         closgr = -1;        /* disable closed user group */
  7346.         return (success = 1);
  7347.     }
  7348.     if ((y = cmnum("0 <= cug index >= 99","",10,&x,xxstring)) < 0)
  7349.       return(y);
  7350.     if (x < 0 || x > 99) {
  7351.         printf("?The choices are 0 <= cug index >= 99\n");
  7352.         return(-2);
  7353.     }
  7354.     if ((y = cmcfm()) < 0) return(y);
  7355.     closgr = x;            /* closed user group selected */
  7356.     return (success = 1);
  7357.  
  7358.       case XYREVC:
  7359.     if((z = cmkey(onoff,2,"X.25 reverse charge call","",xxstring)) < 0)
  7360.       return(z);
  7361.     if ((x = cmcfm()) < 0) return(x);
  7362.     revcall = z;
  7363.     return (success = 1);
  7364.     }
  7365. }
  7366.  
  7367. #ifndef IBMX25
  7368. int
  7369. setpadp() {
  7370.     if ((y = cmkey(padx3tab,npadx3,"PAD X.3 parameter name","",xxstring)) < 0)
  7371.       return(y);
  7372.     x = y;
  7373.     switch (x) {
  7374.       case PAD_BREAK_CHARACTER:
  7375.     if ((y = cmnum("PAD break character value","",10,&z,xxstring)) < 0)
  7376.       return(y);
  7377.     if ((y = cmcfm()) < 0) return(y);
  7378.     break;
  7379.       case PAD_ESCAPE:
  7380.     if ((y = cmnum("PAD escape","",10,&z,xxstring)) < 0) return(y);
  7381.     if (z != 0 && z != 1) {
  7382.         printf("?The choices are 0 or 1\n");
  7383.         return(-2);
  7384.     }
  7385.     if ((y = cmcfm()) < 0) return(y);
  7386.     break;
  7387.       case PAD_ECHO:
  7388.      if ((y = cmnum("PAD echo","",10,&z,xxstring)) < 0) return(y);
  7389.     if (z != 0 && z != 1) {
  7390.         printf("?The choices are 0 or 1\n");
  7391.         return(-2);
  7392.     }
  7393.     if ((y = cmcfm()) < 0) return(y);
  7394.     break;
  7395.       case PAD_DATA_FORWARD_CHAR:
  7396.      if ((y = cmnum("PAD data forward char","",10,&z,xxstring)) < 0)
  7397.       return(y);
  7398.     if (z != 0 && z != 2) {
  7399.         printf("?The choices are 0 or 2\n");
  7400.         return(-2);
  7401.     }
  7402.     if ((y = cmcfm()) < 0) return(y);
  7403.     break;
  7404.       case PAD_DATA_FORWARD_TIMEOUT:
  7405.      if ((y = cmnum("PAD data forward timeout","",10,&z,xxstring)) < 0)
  7406.         return(y);
  7407.     if (z < 0 || z > 255) {
  7408.         printf("?The choices are 0 or 1 <= timeout <= 255\n");
  7409.         return(-2);
  7410.     }
  7411.     if ((y = cmcfm()) < 0) return(y);
  7412.     break;
  7413.       case PAD_FLOW_CONTROL_BY_PAD:
  7414.      if ((y = cmnum("PAD pad flow control","",10,&z,xxstring)) < 0)
  7415.       return(y);
  7416.     if (z != 0 && z != 1) {
  7417.         printf("?The choices are 0 or 1\n");
  7418.         return(-2);
  7419.     }
  7420.     if ((y = cmcfm()) < 0) return(y);
  7421.     break;
  7422.       case PAD_SUPPRESSION_OF_SIGNALS:
  7423.      if ((y = cmnum("PAD service","",10,&z,xxstring)) < 0) return(y);
  7424.     if (z != 0 && z != 1) {
  7425.         printf("?The choices are 0 or 1\n");
  7426.         return(-2);
  7427.     }
  7428.     if ((y = cmcfm()) < 0) return(y);
  7429.     break;
  7430.  
  7431.       case PAD_BREAK_ACTION:
  7432.      if ((y = cmnum("PAD break action","",10,&z,xxstring)) < 0) return(y);
  7433.     if (z != 0 && z != 1 && z != 2 && z != 5 && z != 8 && z != 21) {
  7434.         printf("?The choices are 0, 1, 2, 5, 8 or 21\n");
  7435.         return(-2);
  7436.     }
  7437.     if ((y = cmcfm()) < 0) return(y);
  7438.     break;
  7439.  
  7440.       case PAD_SUPPRESSION_OF_DATA:
  7441.      if ((y = cmnum("PAD data delivery","",10,&z,xxstring)) < 0) return(y);
  7442.     if (z != 0 && z != 1) {
  7443.         printf("?The choices are 0 or 1\n");
  7444.         return(-2);
  7445.     }
  7446.     if ((y = cmcfm()) < 0) return(y);
  7447.     break;
  7448.  
  7449.       case PAD_PADDING_AFTER_CR:
  7450.      if ((y = cmnum("PAD crpad","",10,&z,xxstring)) < 0) return(y);
  7451.     if (z < 0 || z > 7) {
  7452.         printf("?The choices are 0 or 1 <= crpad <= 7\n");
  7453.         return(-2);
  7454.     }
  7455.     if ((y = cmcfm()) < 0) return(y);
  7456.     break;
  7457.  
  7458.       case PAD_LINE_FOLDING:
  7459.      if ((y = cmnum("PAD linefold","",10,&z,xxstring)) < 0) return(y);
  7460.     if (z < 0 || z > 255) {
  7461.         printf("?The choices are 0 or 1 <= linefold <= 255\n");
  7462.         return(-2);
  7463.     }
  7464.     if ((y = cmcfm()) < 0) return(y);
  7465.     break;
  7466.  
  7467.       case PAD_LINE_SPEED:
  7468.      if ((y = cmnum("PAD baudrate","",10,&z,xxstring)) < 0) return(y);
  7469.     if (z < 0 || z > 18) {
  7470.         printf("?The choices are 0 <= baudrate <= 18\n");
  7471.         return(-2);
  7472.     }
  7473.     if ((y = cmcfm()) < 0) return(y);
  7474.     break;
  7475.  
  7476.       case PAD_FLOW_CONTROL_BY_USER:
  7477.      if ((y = cmnum("PAD terminal flow control","",10,&z,xxstring)) < 0)
  7478.         return(y);
  7479.     if (z != 0 && z != 1) {
  7480.         printf("?The choices are 0 or 1\n");
  7481.         return(-2);
  7482.     }
  7483.     if ((y = cmcfm()) < 0) return(y);
  7484.     break;
  7485.  
  7486.       case PAD_LF_AFTER_CR:
  7487.      if ((y = cmnum("PAD crpad","",10,&z,xxstring)) < 0) return(y);
  7488.     if (z < 0 || z == 3 || z > 7) {
  7489.         printf("?The choices are 0, 1, 2, 4, 5, 6 or 7\n");
  7490.         return(-2);
  7491.     }
  7492.     if ((y = cmcfm()) < 0) return(y);
  7493.     break;
  7494.  
  7495.       case PAD_PADDING_AFTER_LF:
  7496.      if ((y = cmnum("PAD lfpad","",10,&z,xxstring)) < 0) return(y);
  7497.     if (z < 0 || z > 7) {
  7498.         printf("?The choices are 0 or 1 <= lfpad <= 7\n");
  7499.         return(-2);
  7500.     }
  7501.     if ((y = cmcfm()) < 0) return(y);
  7502.     break;
  7503.  
  7504.       case PAD_EDITING:
  7505.      if ((y = cmnum("PAD edit control","",10,&z,xxstring)) < 0) return(y);
  7506.     if (z != 0 && z != 1) {
  7507.         printf("?The choices are 0 or 1\n");
  7508.         return(-2);
  7509.     }
  7510.     if ((y = cmcfm()) < 0) return(y);
  7511.     break;
  7512.  
  7513.       case PAD_CHAR_DELETE_CHAR:
  7514.      if ((y = cmnum("PAD char delete char","",10,&z,xxstring)) < 0)
  7515.         return(y);
  7516.     if (z < 0 || z > 127) {
  7517.         printf("?The choices are 0 or 1 <= chardelete <= 127\n");
  7518.         return(-2);
  7519.     }
  7520.     if ((y = cmcfm()) < 0) return(y);
  7521.     break;
  7522.  
  7523.       case PAD_BUFFER_DELETE_CHAR:
  7524.      if ((y = cmnum("PAD buffer delete char","",10,&z,xxstring)) < 0)
  7525.         return(y);
  7526.     if (z < 0 || z > 127) {
  7527.         printf("?The choices are 0 or 1 <= bufferdelte <= 127\n");
  7528.         return(-2);
  7529.     }
  7530.     if ((y = cmcfm()) < 0) return(y);
  7531.     break;
  7532.  
  7533.       case PAD_BUFFER_DISPLAY_CHAR:
  7534.      if ((y = cmnum("PAD display line char","",10,&z,xxstring)) < 0)
  7535.         return(y);
  7536.     if (z < 0 || z > 127) {
  7537.         printf("?The choices are 0 or 1 <= displayline <= 127\n");
  7538.         return(-2);
  7539.     }
  7540.     if ((y = cmcfm()) < 0) return(y);
  7541.     break;
  7542.     }
  7543.     padparms[x] = z;
  7544.     return(success = 1);
  7545. }
  7546. #endif /* IBMX25 */
  7547. #endif /* ANYX25 */
  7548.  
  7549. #ifndef NOXFER
  7550. int
  7551. setat(rmsflg) int rmsflg; {
  7552.     int xx;
  7553.     if ((y = cmkey(attrtab,natr,"File Attribute packets","",xxstring)) < 0)
  7554.       return(y);
  7555.     if (y == AT_XALL) {            /* ATTRIBUTES ALL ON or ALL OFF */
  7556.     if ((z = seton(&xx)) < 0) return(z);
  7557.     if (rmsflg) {
  7558.         printf("Sorry, command not available\n");
  7559.         return(-9);
  7560.     } else {
  7561.         atenci = xx;        /* Encoding in */
  7562.         atenco = xx;        /* Encoding out */
  7563.         atdati = xx;        /* Date in */
  7564.         atdato = xx;        /* Date out */
  7565.         atdisi = xx;        /* Disposition in/out */
  7566.         atdiso = xx;
  7567.         atleni = xx;        /* Length in/out (both kinds) */
  7568.         atleno = xx;
  7569.         atblki = xx;        /* Blocksize in/out */
  7570.         atblko = xx;
  7571.         attypi = xx;        /* File type in/out */
  7572.         attypo = xx;
  7573.         atsidi = xx;        /* System ID in/out */
  7574.         atsido = xx;
  7575.         atsysi = xx;        /* System-dependent params in/out */
  7576.         atsyso = xx;
  7577. #ifdef CK_PERMS                /* Protection */
  7578.         atlpri = xx;        /* Local in */
  7579.         atlpro = xx;        /* Local out */
  7580.         atgpri = xx;        /* Generic in */
  7581.         atgpro = xx;        /* Generic out */
  7582. #endif /* CK_PERMS */
  7583. #ifdef STRATUS
  7584.         atfrmi = xx;        /* Format in/out */
  7585.         atfrmo = xx;
  7586.         atcrei = xx;        /* Creator id in/out */
  7587.         atcreo = xx;
  7588.         atacti = xx;        /* Account in/out */
  7589.         atacto = xx;
  7590. #endif /* STRATUS */
  7591.     }
  7592.     return(z);
  7593.     } else if (y == AT_ALLY || y == AT_ALLN) { /* ATTRIBUTES ON or OFF */
  7594.     if ((x = cmcfm()) < 0) return(x);
  7595.     atcapr = (y == AT_ALLY) ? 1 : 0;
  7596.     if (rmsflg) {
  7597.         sstate = setgen('S', "132", atcapr ? "1" : "0", "");
  7598.         return((int) sstate);
  7599.     } else return(success = 1);
  7600.     }
  7601.     /* Otherwise, it's an individual attribute that wants turning off/on */
  7602.  
  7603.     if ((z = cmkey(onoff,2,"","",xxstring)) < 0) return(z);
  7604.     if ((x = cmcfm()) < 0) return(x);
  7605.  
  7606. /* There are better ways to do this... */
  7607. /* The real problem is that we're not separating the in and out cases */
  7608. /* and so we have to arbitrarily pick the "in" case, i.e tell the remote */
  7609. /* server to ignore incoming attributes of the specified type, rather */
  7610. /* than telling it not to send them.  The protocol does not (yet) define */
  7611. /* codes for "in-and-out-at-the-same-time". */
  7612.  
  7613.     switch (y) {
  7614. #ifdef CK_PERMS
  7615. /* We're lumping local and generic protection together for now... */
  7616.       case AT_LPRO:
  7617.       case AT_GPRO:
  7618.     if (rmsflg) {
  7619.         sstate = setgen('S', "143", z ? "1" : "0", "");
  7620.         return((int) sstate);
  7621.     }
  7622.     atlpri = atlpro = atgpri = atgpro = z; break;
  7623. #endif /* CK_PERMS */
  7624.       case AT_DISP:
  7625.     if (rmsflg) {
  7626.         sstate = setgen('S', "142", z ? "1" : "0", "");
  7627.         return((int) sstate);
  7628.     }
  7629.     atdisi = atdiso = z; break;
  7630.       case AT_ENCO:
  7631.     if (rmsflg) {
  7632.         sstate = setgen('S', "141", z ? "1" : "0", "");
  7633.         return((int) sstate);
  7634.     }
  7635.     atenci = atenco = z; break;
  7636.       case AT_DATE:
  7637.     if (rmsflg) {
  7638.         sstate = setgen('S', "135", z ? "1" : "0", "");
  7639.         return((int) sstate);
  7640.     }
  7641.     atdati = atdato = z; break;
  7642.       case AT_LENB:
  7643.       case AT_LENK:
  7644.     if (rmsflg) {
  7645.         sstate = setgen('S', "133", z ? "1" : "0", "");
  7646.         return((int) sstate);
  7647.     }
  7648.     atleni = atleno = z; break;
  7649.       case AT_BLKS:
  7650.     if (rmsflg) {
  7651.         sstate = setgen('S', "139", z ? "1" : "0", "");
  7652.         return((int) sstate);
  7653.     }
  7654.     atblki = atblko = z; break;
  7655.       case AT_FTYP:
  7656.     if (rmsflg) {
  7657.         sstate = setgen('S', "134", z ? "1" : "0", "");
  7658.         return((int) sstate);
  7659.     }
  7660.     attypi = attypo = z; break;
  7661. #ifdef STRATUS
  7662.       case AT_CREA:
  7663.     if (rmsflg) {
  7664.         sstate = setgen('S', "136", z ? "1" : "0", "");
  7665.         return((int) sstate);
  7666.     }
  7667.     atcrei = atcreo = z; break;
  7668.       case AT_ACCT:
  7669.     if (rmsflg) {
  7670.         sstate = setgen('S', "137", z ? "1" : "0", "");
  7671.         return((int) sstate);
  7672.     }
  7673.     atacti = atacto = z; break;
  7674. #endif /* STRATUS */
  7675.       case AT_SYSI:
  7676.     if (rmsflg) {
  7677.         sstate = setgen('S', "145", z ? "1" : "0", "");
  7678.         return((int) sstate);
  7679.     }
  7680.     atsidi = atsido = z; break;
  7681. #ifdef STRATUS
  7682.       case AT_RECF:
  7683.     if (rmsflg) {
  7684.         sstate = setgen('S', "146", z ? "1" : "0", "");
  7685.         return((int) sstate);
  7686.     }
  7687.         atfrmi = atfrmo = z; break;
  7688. #endif /* STRATUS */
  7689.       case AT_SYSP:
  7690.     if (rmsflg) {
  7691.         sstate = setgen('S', "147", z ? "1" : "0", "");
  7692.         return((int) sstate);
  7693.     }
  7694.     atsysi = atsyso = z; break;
  7695.       default:
  7696.     printf("?Not available\n");
  7697.     return(-2);
  7698.     }
  7699.     return(1);
  7700. }
  7701. #endif /* NOXFER */
  7702.  
  7703. #ifndef NOSPL
  7704. int
  7705. setinp() {
  7706.     if ((y = cmkey(inptab,ninp,"","",xxstring)) < 0) return(y);
  7707.     switch (y) {
  7708. #ifdef OS2
  7709.       case IN_PAC:            /* SET INPUT PACING */
  7710.     z = cmnum("milliseconds","0",10,&x,xxstring);
  7711.     return(setnum(&tt_inpacing,x,z,1000));
  7712.       case IN_TRM:            /* SET INPUT TERMINAL */
  7713.     return(seton(&interm));
  7714. #endif /* OS2 */
  7715.       case IN_DEF:            /* SET INPUT DEFAULT-TIMEOUT */
  7716.     z = cmnum("Positive number","",10,&x,xxstring);
  7717.     return(setnum(&indef,x,z,94));
  7718.       case IN_TIM:            /* SET INPUT TIMEOUT-ACTION */
  7719.     if ((z = cmkey(intimt,2,"","",xxstring)) < 0) return(z);
  7720.     if ((x = cmcfm()) < 0) return(x);
  7721.     intime[cmdlvl] = z;
  7722.     return(success = 1);
  7723.       case IN_CAS:            /* SET INPUT CASE */
  7724.     if ((z = cmkey(incast,2,"","",xxstring)) < 0) return(z);
  7725.     if ((x = cmcfm()) < 0) return(x);
  7726.     inpcas[cmdlvl] = z;
  7727.     return(success = 1);
  7728.       case IN_ECH:            /* SET INPUT ECHO */
  7729.     return(seton(&inecho));
  7730.       case IN_SIL:            /* SET INPUT SILENCE */
  7731.     z = cmnum("Seconds of inactivity before INPUT fails","",10,&x,
  7732.           xxstring);
  7733.     return(setnum(&insilence,x,z,-1));
  7734.  
  7735.       case IN_BUF:            /* SET INPUT BUFFER-SIZE */
  7736.     if ((z = cmnum("Number of bytes in INPUT buffer",
  7737.                ckitoa(INPBUFSIZ),10,&x, xxstring)) < 0)
  7738.       return(z);
  7739.     if ((y = cmcfm()) < 0) return(y);
  7740.     inbufsize = 0;
  7741.     if (inpbuf) {
  7742.         free(inpbuf);
  7743.         inpbuf = NULL;
  7744.         inpbp = NULL;
  7745.     }
  7746.     if (!(s = (char *)malloc(x + 1)))
  7747.       return(0);
  7748.     inpbuf = s;
  7749.     inpbp = s;
  7750.     inbufsize = x;
  7751.     for (x = 0; x <= inbufsize; x++)
  7752.       inpbuf[x] = NUL;
  7753.     return(success = 1);
  7754.  
  7755. #ifdef CK_AUTODL
  7756.       case IN_ADL:            /* AUTODOWNLOAD */
  7757.     return(seton(&inautodl));
  7758. #endif /* CK_AUTODL */
  7759.  
  7760.       case IN_CAN:            /* SET INPUT INTERRUPTS */
  7761.     return(seton(&inintr));
  7762.     }
  7763.     return(0);
  7764. }
  7765. #endif /* NOSPL */
  7766.  
  7767. #ifdef NETCONN
  7768. VOID
  7769. ndreset() {
  7770. #ifndef NODIAL                /* This depends on DIAL... */
  7771.     int i=0, j=0;
  7772.     if (!ndinited)            /* Don't free garbage... */
  7773.       return;
  7774.     for (i = 0; i < nhcount; i++) {    /* Clean out previous list */
  7775.     if (nh_p[i])
  7776.       free(nh_p[i]);
  7777.     nh_p[i] = NULL;
  7778.     if (nh_p2[i])
  7779.       free(nh_p2[i]);
  7780.     nh_p2[i] = NULL;
  7781.     for (j = 0; j < 4; j++) {
  7782.         if (nh_px[j][i])
  7783.           free(nh_px[j][i]);
  7784.         nh_px[j][i] = NULL;
  7785.     }
  7786.     }
  7787. #endif /* NODIAL */
  7788. }
  7789.  
  7790. VOID
  7791. ndinit() {                /* Net directory pointers */
  7792. #ifndef NODIAL                /* This depends on DIAL... */
  7793.     int i, j;
  7794.     if (ndinited++)            /* Don't do this more than once. */
  7795.       return;
  7796.     for (i = 0; i < MAXDDIR; i++) {    /* Init all pointers to NULL */
  7797.     netdir[i] = NULL;
  7798.     }
  7799.     for (i = 0; i < MAXDNUMS; i++) {
  7800.     nh_p[i] = NULL;
  7801.     nh_p2[i] = NULL;
  7802.     for (j = 0; j < 4; j++)
  7803.       nh_px[j][i] = NULL;
  7804.     }
  7805. #endif /* NODIAL */
  7806. }
  7807.  
  7808. #ifndef NODIAL
  7809. #ifdef NETCONN
  7810. VOID                    /* Get net defaults from environment */
  7811. getnetenv() {
  7812.     char *p = NULL;
  7813.  
  7814.     makestr(&p,getenv("K_NET_DIRECTORY")); /* Dialing directories */
  7815.     if (p) {
  7816.     int i;
  7817.     xwords(p,MAXDDIR,netdir,0);
  7818.     for (i = 0; i < MAXDDIR; i++) { /* Fill in any gaps... */
  7819.         if (!netdir[i+1])
  7820.           break;
  7821.         else
  7822.           netdir[i] = netdir[i+1];
  7823.             debug(F111,"netdir[i]",netdir[i],i);
  7824.     }
  7825.     nnetdir = i;
  7826.     }
  7827. }
  7828. #endif /* NETCONN */
  7829. #endif /* NODIAL */
  7830.  
  7831. int
  7832. #ifdef CK_ANSIC
  7833. lunet(char *s)                /* s = name to look up   */
  7834. #else
  7835. lunet(s) char *s;
  7836. #endif /* CK_ANSIC */
  7837. /* lunet */ {
  7838. #ifndef NODIAL                /* This depends on DIAL... */
  7839.     int n, n1, t, dd = 0;
  7840.     int ambiguous = 0;
  7841.     FILE * f;
  7842.     char *line = NULL;
  7843.     extern int dialdpy;
  7844.     int netdpy = dialdpy;
  7845.     char *info[8];
  7846.  
  7847.     nhcount = 0;            /* Set this before returning */
  7848.  
  7849.     if (!s || nnetdir < 1)        /* Validate arguments */
  7850.       return(-1);
  7851.  
  7852.     if (isdigit(*s) || *s == '*' || *s == '.')
  7853.       return(0);
  7854.  
  7855.     if ((n1 = (int) strlen(s)) < 1)    /* Length of string to look up */
  7856.       return(-1);
  7857.  
  7858.     if (!(line = malloc(1024)))        /* Allocate input buffer */
  7859.       return(-1);
  7860.  
  7861.   lu_again:
  7862.     f = NULL;                /* Network directory file descriptor */
  7863.     t = nhcount = 0;            /* Match count */
  7864.     dd = 0;                /* Directory counter */
  7865.  
  7866.     dirline = 0;
  7867.     while (1) {                /* We make one pass */
  7868.     if (!f) {            /* Directory not open */
  7869.             if (dd >= nnetdir)        /* No directories left? */
  7870.           break;            /* Done. */
  7871.         if ((f = fopen(netdir[dd],"r")) == NULL) { /* Open it */
  7872.         perror(netdir[dd]);    /* Can't, print message saying why */
  7873.         dd++;
  7874.         continue;        /* But go on to next one. */
  7875.         }
  7876.         if (netdpy)
  7877.           printf("Opening %s...\n",netdir[dd]);
  7878.             dd++;
  7879.     }
  7880.     line[0] = NUL;
  7881.     if (getnct(line,1023,f,1) < 0) { /* Read a line */
  7882.         if (f) {            /* f can be clobbered! */
  7883.         fclose(f);        /* Close the file */
  7884.         f = NULL;        /* Indicate next one needs opening */
  7885.         }
  7886.         continue;
  7887.     }
  7888.     if (!line[0])            /* Empty line */
  7889.       continue;
  7890.  
  7891.     xwords(line,7,info,0);        /* Parse it */
  7892.  
  7893.     if (!info[1] || !info[2] || !info[3]) /* Required fields */
  7894.       continue;
  7895.     if (*info[1] == ';')        /* Full-line comment */
  7896.       continue;
  7897.     if ((n = (int) strlen(info[1])) < 1) /* Length of name-tag */
  7898.       continue;
  7899.     if (n < n1)            /* Search name is longer */
  7900.       continue;            /* Can't possibly match */
  7901.     if (ambiguous && n != n1)
  7902.       continue;
  7903.     if (ckstrcmp(s,info[1],n1,0))    /* Compare using length of */
  7904.       continue;            /* search string s. */
  7905.  
  7906.     /* Have a match */
  7907.  
  7908.     makestr(&(nh_p[nhcount]), info[3]);    /* address */
  7909.     makestr(&(nh_p2[nhcount]),info[2]);    /* net type */
  7910.     makestr(&(nh_px[0][nhcount]),info[4]); /* net-specific stuff... */
  7911.     makestr(&(nh_px[1][nhcount]),info[5]);
  7912.     makestr(&(nh_px[2][nhcount]),info[6]);
  7913.     makestr(&(nh_px[3][nhcount]),info[7]);
  7914.  
  7915.     nhcount++;            /* Count this match */
  7916.     if (nhcount > MAXDNUMS) {    /* Watch out for too many */
  7917.         printf("Warning: %d matches found, %d max\n",
  7918.            nhcount,
  7919.            MAXDNUMS
  7920.            );
  7921.         nhcount = MAXDNUMS;
  7922.         break;
  7923.     }
  7924.     if (nhcount == 1) {        /* First one - save entry name */
  7925.         if (n_name) {        /* Free the one from before if any */
  7926.         free(n_name);
  7927.         n_name = NULL;
  7928.         }
  7929.         if (!(n_name = (char *)malloc(n + 1))) { /* Allocate new storage */
  7930.         printf("?memory allocation error - lunet:3\n");
  7931.         if (line) {
  7932.             free(line);
  7933.             line = NULL;
  7934.         }
  7935.         nhcount = 0;
  7936.         return(-1);
  7937.         }
  7938.         t = n;            /* Remember its length */
  7939.         strcpy(n_name,info[1]);
  7940.     } else {            /* Second or subsequent one */
  7941.         if ((int) strlen(info[1]) == t) /* Lengths compare */
  7942.           if (!ckstrcmp(n_name,info[1],t,0)) /* Caseless compare OK */
  7943.         continue;
  7944.  
  7945.         /* Name given by user matches entries with different names */
  7946.  
  7947.         if (ambiguous)        /* Been here before */
  7948.           break;
  7949.  
  7950.         ambiguous = 1;        /* Now an exact match is required */
  7951.         ndreset();            /* Clear out previous list */
  7952.         goto lu_again;        /* Do it all over again. */
  7953.     }
  7954.     }
  7955.     if (line) {
  7956.     free(line);
  7957.     line = NULL;
  7958.     }
  7959.     if (nhcount == 0 && ambiguous)
  7960.       printf("Ambiguous - \"%s\" different names in network directory\n",s);
  7961. #else
  7962.     nhcount = 0;
  7963. #endif /* NODIAL */
  7964.     return(nhcount);
  7965. }
  7966. #endif /* NETCONN */
  7967.  
  7968. #ifndef NOLOCAL
  7969. /*  C L S C O N N X  --  Close connection  */
  7970.  
  7971. int
  7972. clsconnx(ask) int ask; {
  7973.     int x, rc = 0;
  7974.     debug(F101,"clsconnx local","",local);
  7975.     if (local) {
  7976.     x = ask ? hupok(1) : 1;        /* Make sure it's OK to close */
  7977.     if (!x) {
  7978.         rc = -1;
  7979.         debug(F101,"clsconnx hupok says no","",rc);
  7980.         return(rc);
  7981.     }
  7982.     ttflui();            /* Clear away buffered up junk */
  7983. #ifndef NODIAL
  7984. #ifdef OS2ONLY
  7985. /* Don't hangup a line that is shared with the SLIP or PPP driver */
  7986.     if (!ttslip && !ttppp)
  7987. #endif /* OS2ONLY */
  7988.       mdmhup();
  7989. #endif /* NODIAL */
  7990.     if (network && msgflg)
  7991.       printf(" Closing connection\n");
  7992.     ttclos(0);            /* Close old connection, if any */
  7993.     rc = 1;
  7994.     {
  7995.         extern int wasclosed, whyclosed;
  7996.         if (wasclosed) {
  7997.         whyclosed = WC_CLOS;
  7998. #ifndef NOSPL
  7999.                 if (nmac) {        /* Any macros defined? */
  8000.             int k;        /* Yes */
  8001.             /* printf("ON_CLOSE CLSCONNX\n"); */
  8002.             wasclosed = 0;
  8003.             k = mlook(mactab,"on_close",nmac);    /* Look this up */
  8004.             if (k >= 0) {            /* If found, */
  8005.             if (dodo(k,ckitoa(whyclosed),0) > -1) /* set it up, */
  8006.               parser(1);            /* and execute it */
  8007.             }
  8008.         }
  8009. #endif /* NOSPL */
  8010.         whyclosed = WC_REMO;
  8011.         wasclosed = 0;
  8012.         }
  8013.     }
  8014.     }
  8015. #ifdef VMS                /* Or maybe #ifndef UNIX? */
  8016.     else {                /* Need to do this in VMS to */
  8017.     ttclos(0);            /* free the tty channel number */
  8018.     rc = 1;                /* obtained in ttopen() or else */
  8019.     }                    /* subsequent ttopen's won't work */
  8020. #endif /* VMS */
  8021. #ifdef CKLOGDIAL
  8022.     dologend();
  8023. #endif /* CKLOGDIAL */
  8024.     haveline = 0;
  8025.     if (mdmtyp < 0) {            /* Switching from net to async? */
  8026.     if (mdmsav > -1)        /* Restore modem type from last */
  8027.       mdmtyp = mdmsav;        /* SET MODEM command, if any. */
  8028.     else
  8029.       mdmtyp = 0;
  8030.     mdmsav = -1;
  8031.     }
  8032.     if (network)
  8033.       network = 0;
  8034. #ifdef NETCONN
  8035.     if (oldplex > -1) {            /* Restore previous duplex setting. */
  8036.     duplex = oldplex;
  8037.     oldplex = -1;
  8038.     }
  8039. #endif /* NETCONN */
  8040. #ifndef MAC
  8041.     strcpy(ttname,dftty);        /* Restore default communication */
  8042. #endif /* MAC */
  8043.     local = dfloc;            /* device and local/remote status */
  8044.     if (local) {
  8045.     cxtype = CXT_DIRECT;        /* Something reasonable */
  8046.     speed = ttgspd();        /* Get the current speed */
  8047.     } else {
  8048.     cxtype = CXT_REMOTE;
  8049.     speed = -1L;
  8050.     }
  8051. #ifndef NOXFER
  8052.     if (xreliable > -1 && !setreliable) {
  8053.     reliable = xreliable;
  8054.     debug(F101,"clsconnx reliable A","",reliable);
  8055.     } else if (!setreliable) {
  8056.     reliable = SET_AUTO;
  8057.     debug(F101,"clsconnx reliable B","",reliable);
  8058.     }
  8059. #endif /* NOXFER */
  8060.     setflow();                /* Revert flow control */
  8061.     return(rc);
  8062. }
  8063.  
  8064. VOID
  8065. slrestor() {
  8066.     int x;
  8067. #ifdef CK_AUTHENTICATION
  8068.     if (sl_auth_saved) {
  8069.         for (x = 0; x < AUTHTYPLSTSZ; x++)
  8070.       auth_type_user[x] = sl_auth_type_user[x];
  8071.         sl_auth_saved = 0;
  8072.     }
  8073.     if (sl_topt_a_s_saved) {
  8074.         TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = sl_topt_a_su;
  8075.         sl_topt_a_s_saved = 0;
  8076.     }
  8077.     if (sl_topt_a_c_saved) {
  8078.         TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = sl_topt_a_cm;
  8079.         sl_topt_a_c_saved = 0;
  8080.     }
  8081. #endif /* CK_AUTHENTICATION */
  8082. #ifdef CK_ENCRYPTION
  8083.     if (sl_cx_saved) {
  8084.         cx_type = sl_cx_type;
  8085.         sl_cx_saved = 0;
  8086.     }
  8087.     if (sl_topt_e_s_saved) {
  8088.         TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION)  = sl_topt_e_su;
  8089.         TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION) = sl_topt_e_sm;
  8090.         sl_topt_e_s_saved = 0;
  8091.     }
  8092.     if (sl_topt_e_c_saved) {
  8093.         TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION)  = sl_topt_e_cu;
  8094.         TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION) = sl_topt_e_cm;
  8095.         sl_topt_e_c_saved = 0;
  8096.     }
  8097. #endif /* CK_ENCRYPTION */
  8098.     if (sl_uid_saved) {
  8099.         ckstrncpy(uidbuf,sl_uidbuf,UIDBUFLEN);
  8100.         sl_uid_saved = 0;
  8101.     }
  8102. #ifdef TNCODE
  8103.     if (sl_tn_saved) {
  8104.         tn_wait_flg = sl_tn_wait;
  8105.         sl_tn_saved = 0;
  8106.     }
  8107. #endif /* TNCODE */
  8108. }
  8109.  
  8110. /* S E T L I N -- parse name of and then open communication device. */
  8111. /*
  8112.   Call with:
  8113.     xx == XYLINE for a serial (tty) line, XYHOST for a network host,
  8114.     zz == 0 means if user doesn't give a device name, continue current
  8115.             active connection (if any);
  8116.     zz != 0 means if user doesn't give a device name, then close the
  8117.             current connection and restore the default communication device.
  8118.     fc == 0 to just make the connection, 1 to also CONNECT (e.g. "telnet").
  8119. */
  8120. int netsave = -1;
  8121.  
  8122. static char * tmpstring = NULL;
  8123. static char * tmpusrid = NULL;
  8124.  
  8125. int
  8126. setlin(xx, zz, fc) int xx, zz, fc; {
  8127.     extern char pwbuf[], * g_pswd;
  8128.     extern int pwflg, pwcrypt, g_pflg, g_pcpt, nolocal;
  8129.     int wait;
  8130.     int tn_wait_sv;
  8131.     int mynet;
  8132.     int _local = -1;
  8133.     int c, i, haveswitch = 0;
  8134.     int getval = 0;
  8135.     int wild = 0;            /* Filespec has wildcards */
  8136.     int cx = 0;                /* Connect after */
  8137.     int sx = 0;                /* Become server after */
  8138. #ifdef CK_ENCRYPTION
  8139.     int encrypt = 0;                    /* Encrypted? */
  8140.     int e_type = -1;                    /* Telnet /ENCRYPT type */
  8141. #endif /* CK_ENCRYPTION */
  8142. #ifdef CK_AUTHENTICATION
  8143.     int a_type = -1;            /* Authentication type */
  8144. #endif /* CK_AUTHENTICATION */
  8145. #ifdef VMS
  8146.     int shr = 0;            /* Share serial device */
  8147. #endif /* VMS */
  8148.     int confirmed = 0;            /* Command has been entered */
  8149.     struct FDB sw, tx, nx;
  8150. #ifdef OS2
  8151.     struct FDB fl;
  8152. #endif /* OS2 */
  8153.  
  8154.     char * ss;
  8155. #ifdef TCPSOCKET
  8156.     int rawflg = 0;
  8157. #endif /* TCPSOCKET */
  8158.  
  8159. #ifdef OS2
  8160. #define SRVBUFSIZ PIPENAML
  8161. #else /* OS2 */
  8162. #define SRVBUFSIZ 63
  8163. #endif /* OS2 */
  8164.  
  8165.     char srvbuf[SRVBUFSIZ+1];
  8166.     char hostname[15*65];
  8167.  
  8168. #ifdef OS2
  8169. #ifdef NT
  8170.     int xxtapi = 0;
  8171. #else
  8172.     int xxslip = 0, xxppp = 0;
  8173. #endif /* NT */
  8174. #endif /* OS2 */
  8175.  
  8176.     debug(F101,"setline fc","",fc);
  8177.     debug(F101,"setline zz","",zz);
  8178.  
  8179. #ifdef TNCODE
  8180.     tn_wait_sv = tn_wait_flg;
  8181.     wait = tn_wait_flg;
  8182. #else
  8183.     tn_wait_sv = 0;
  8184.     wait = 0;
  8185. #endif /* TNCODE */
  8186.  
  8187.     mynet = nettype;
  8188.  
  8189.     if (nolocal) {
  8190.     slmsg = "Making connections is disabled";
  8191.     printf("?Sorry, making connections is disabled\n");
  8192.     return(-9);
  8193.     }
  8194.     if (netsave > -1)
  8195.       nettype = netsave;
  8196.  
  8197.     if (fc != 0 || zz == 0)        /* Preset /CONNECT switch */
  8198.       cx = 1;
  8199.  
  8200.     debug(F101,"setline cx","",cx);
  8201.  
  8202.     *srvbuf = NUL;
  8203.  
  8204.     line[0] = NUL;
  8205.     s = line;
  8206.  
  8207. #ifdef NETCONN
  8208. #ifndef NOSPL
  8209. #ifdef CK_SRP
  8210.     if (tmpstring)
  8211.         makestr(&tmpstring,NULL);
  8212. #endif /* CK_SRP */
  8213. #ifdef RLOGCODE
  8214.     if (tmpusrid)
  8215.         makestr(&tmpusrid,NULL);
  8216. #endif /* RLOGCODE */
  8217. #endif /* NOSPL */
  8218. #endif /* NETCONN */
  8219.  
  8220.     autoflow = 1;            /* Enable automatic flow setting */
  8221.  
  8222.     if (xx == XYHOST) {            /* SET HOST <hostname> */
  8223. #ifndef NETCONN
  8224.     slmsg = "Network connections not supported";
  8225.         printf("?%s\n",slmsg);
  8226.     return(-9);
  8227. #else /* NETCONN */
  8228. #ifndef NOPUSH
  8229.     if ((mynet == NET_CMD || mynet == NET_PTY) && nopush) {
  8230.         slmsg = "Access to external commands is disabled";
  8231.         printf("?Sorry, access to external commands is disabled\n");
  8232.         return(-9);
  8233.     }
  8234. #endif /* NOPUSH */
  8235.  
  8236. /*
  8237.   Here we parse optional switches and then the hostname or whatever,
  8238.   which depends on the network type.  The tricky part is, the network type
  8239.   can be set by a switch.
  8240. */
  8241. #ifndef NOSPL
  8242.     makestr(&g_pswd,pwbuf);        /* Save global pwbuf */
  8243.     g_pflg = pwflg;            /* and flag */
  8244.     g_pcpt = pwcrypt;
  8245. #endif /* NOSPL */
  8246.  
  8247.     confirmed = 0;
  8248.     haveswitch = 0;
  8249. #ifdef NETFILE
  8250.     if (mynet != NET_FILE) {
  8251. #endif /* NETFILE */
  8252.         ss = (mynet == NET_CMD || mynet == NET_PTY) ?
  8253.           "Command, or switch" :
  8254.         (mynet == NET_TCPA || mynet == NET_TCPB) ?
  8255.           "Hostname, ip-address, or switch" :
  8256.             "Host or switch";
  8257.         if (fc) {
  8258.                 if (ttnproto == NP_TELNET || ttnproto == NP_KERMIT) {
  8259.                     if (nshteltab) {
  8260.             haveswitch++;
  8261.             cmfdbi(&sw,_CMKEY,ss,"","",nshteltab,4,xxstring,
  8262.                  shteltab,&nx);
  8263.             }
  8264.                 }
  8265. #ifdef RLOGCODE
  8266.                 else if (ttnproto == NP_RLOGIN) {
  8267.                     if (nshrlgtab) {
  8268.             haveswitch++;
  8269.             cmfdbi(&sw,_CMKEY,ss,"","",nshrlgtab,4,xxstring,
  8270.                    shrlgtab,&nx);
  8271.             }
  8272.                 }
  8273. #endif /* RLOGCODE */
  8274.         } else {
  8275.         haveswitch++;
  8276.         cmfdbi(&sw,_CMKEY,ss,"","",nshtab,4,xxstring,shtab,&nx);
  8277.         }
  8278. #ifdef NETFILE
  8279.     }
  8280. #endif /* NETFILE */
  8281.     if (mynet == NET_TCPB || mynet == NET_SLAT) {
  8282.         cmfdbi(&nx,_CMFLD,"Host","","",0,0,xxstring,NULL,NULL);
  8283. #ifdef NETFILE
  8284.     } else if (mynet == NET_FILE) {
  8285.         cmfdbi(&nx,_CMIFI,"Filename","","",0,0,xxstring,NULL,NULL);
  8286. #endif /* NETFILE */
  8287. #ifdef PTYORPIPE
  8288.     } else if (mynet == NET_CMD || mynet == NET_PTY) {
  8289.         cmfdbi(&nx,_CMTXT,"Command","","",0,0,xxstring,NULL,NULL);
  8290. #endif /* PTYORPIPE */
  8291.     } else {
  8292.         cmfdbi(&nx,_CMTXT,"Host","","",0,0,xxstring,NULL,NULL);
  8293.     }
  8294.     while (1) {
  8295.         x = cmfdb(haveswitch ? &sw : &nx);
  8296.         debug(F101,"setlin cmfdb","",x);
  8297.         if (x < 0)
  8298.           if (x != -3)
  8299.         return(x);
  8300.         if (x == -3) {
  8301.         if ((x = cmcfm()) < 0) {
  8302.             return(x);
  8303.         } else {
  8304.             confirmed = 1;
  8305.             break;
  8306.         }
  8307.         }
  8308.         if (cmresult.fcode != _CMKEY) {    /* Not a switch */
  8309.         strcpy(line,cmresult.sresult); /* Save the data that */
  8310.         s = line;               /* was parsed... */
  8311.         if (cmresult.fcode == _CMIFI) {
  8312.             wild = cmresult.nresult;
  8313.         } else if (cmresult.fcode == _CMTXT) {
  8314.             confirmed = 1;
  8315.         }
  8316.         break;            /* and break out of this loop */
  8317.         }
  8318.         c = cmgbrk();        /* Have switch - get break character */
  8319.         getval = (c == ':' || c == '='); /* Must parse an agument? */
  8320.         if (getval && !(cmresult.kflags & CM_ARG)) {
  8321.         printf("?This switch does not take arguments\n");
  8322.         return(-9);
  8323.         }
  8324.         if (!getval && (cmgkwflgs() & CM_ARG)) {
  8325.         printf("?This switch requires an argument\n");
  8326.         return(-9);
  8327.         }
  8328.         switch (cmresult.nresult) { /* It's a switch.. */
  8329.           case SL_CNX:        /* /CONNECT */
  8330.         cx = 1;
  8331.         sx = 0;
  8332.         break;
  8333.           case SL_SRV:        /* /SERVER */
  8334.         cx = 0;
  8335.         sx = 1;
  8336.         break;
  8337. #ifdef NETCMD
  8338.           case SL_CMD:        /* /COMMAND */
  8339.         netsave = mynet;
  8340.         mynet = NET_CMD;
  8341.         break;
  8342. #endif /* NETCMD */
  8343. #ifdef NETPTY
  8344.           case SL_PTY:        /* /PTY */
  8345.         netsave = mynet;
  8346.         mynet = NET_PTY;
  8347.         break;
  8348. #endif /* NETPTY */
  8349.           case SL_NET:        /* /NETWORK-TYPE */
  8350.         if ((x = cmkey(netcmd,nnets,"","",xxstring)) < 0)
  8351.           return(x);
  8352.         mynet = x;
  8353.         break;
  8354. #ifndef NOSPL
  8355.           case SL_PSW:        /* /PASSWORD: */
  8356.         if (!getval)
  8357.           break;
  8358.                 if ((x = cmfld("Password","",&s,xxstring)) < 0) {
  8359.                     if (x == -3) {
  8360.                         makestr(&tmpstring,"");
  8361.                     } else {
  8362.                         return(x);
  8363.                     }
  8364.                 } else {
  8365.                     s = brstrip(s);
  8366.                     if ((x = (int)strlen(s)) > PWBUFL) {
  8367.             slmsg = "Internal error";
  8368.                         printf("?Sorry, too long - max = %d\n",PWBUFL);
  8369.                         return(-9);
  8370.                     }
  8371.                     makestr(&tmpstring,s);
  8372.                 }
  8373.         break;
  8374. #endif /* NOSPL */
  8375.           case SL_UID:        /* /USERID: */
  8376.         if (!getval)
  8377.           break;
  8378.                 if ((x = cmfld("Userid","",&s,xxstring)) < 0) {
  8379.                     if (x == -3) {
  8380.                         makestr(&tmpusrid,"");
  8381.                     } else {
  8382.                         return(x);
  8383.                     }
  8384.                 } else {
  8385.                     s = brstrip(s);
  8386.                     if ((x = (int)strlen(s)) > 63) {
  8387.             slmsg = "Internal error";
  8388.                         printf("?Sorry, too long - max = %d\n",63);
  8389.                         return(-9);
  8390.                     }
  8391.                     makestr(&tmpusrid,s);
  8392.                 }
  8393.         break;
  8394. #ifdef CK_AUTHENTICATION
  8395. #ifdef CK_SRP
  8396.               case SL_SRP:
  8397.                 a_type = AUTHTYPE_SRP;
  8398.                 break;
  8399. #endif /* CK_SRP */
  8400. #ifdef CK_SSL
  8401.               case SL_SSL:
  8402.                 a_type = AUTHTYPE_SSL;
  8403.                 break;
  8404. #endif /* CK_SSL */
  8405. #ifdef NT
  8406.               case SL_NTLM:
  8407.                 a_type = AUTHTYPE_NTLM;
  8408.                 break;
  8409. #endif /* NT */
  8410. #ifdef CK_KERBEROS
  8411.               case SL_KRB4:
  8412.                 a_type = AUTHTYPE_KERBEROS_V4;
  8413.                 if (ttnproto == NP_RLOGIN)
  8414.           ttnproto =
  8415. #ifdef CK_ENCRYPTION
  8416.             encrypt ? NP_EK4LOGIN :
  8417. #endif /* CK_ENCRYPTION */
  8418.               NP_K4LOGIN;
  8419.                 else if (ttnproto == NP_K5LOGIN)
  8420.           ttnproto = NP_K4LOGIN;
  8421. #ifdef CK_ENCRYPTION
  8422.                 else if (ttnproto == NP_EK5LOGIN)
  8423.           ttnproto = NP_EK4LOGIN;
  8424. #endif /* CK_ENCRYPTION */
  8425.                 break;
  8426.           case SL_KRB5:
  8427.                 a_type = AUTHTYPE_KERBEROS_V5;
  8428.                 if (ttnproto == NP_RLOGIN)
  8429.           ttnproto =
  8430. #ifdef CK_ENCRYPTION
  8431.             encrypt ? NP_EK5LOGIN :
  8432. #endif /* CK_ENCRYPTION */
  8433.               NP_K5LOGIN;
  8434.         else if (ttnproto == NP_K4LOGIN)
  8435.           ttnproto = NP_K5LOGIN;
  8436. #ifdef CK_ENCRYPTION
  8437.         else if (ttnproto == NP_EK4LOGIN)
  8438.           ttnproto = NP_EK5LOGIN;
  8439. #endif /* CK_ENCRYPTION */
  8440.         break;
  8441. #endif /* CK_KERBEROS */
  8442.           case SL_AUTH: {
  8443.           extern struct keytab autyptab[];
  8444.           extern int nautyp;
  8445.           if ((x = cmkey(autyptab,nautyp,"type of authentication",
  8446.                  "automatic",xxstring)) < 0)
  8447.                     return(x);
  8448.           a_type = x;
  8449.           break;
  8450.           }
  8451. #endif /* CK_AUTHENTICATION */
  8452. #ifdef CK_ENCRYPTION
  8453.               case SL_ENC:
  8454.         switch (ttnproto) {
  8455.           case NP_K4LOGIN:
  8456.                     ttnproto = NP_EK4LOGIN;
  8457.                     encrypt = 1;
  8458.                     break;
  8459.           case NP_K5LOGIN:
  8460.                     ttnproto = NP_EK5LOGIN;
  8461.                     encrypt = 1;
  8462.                     break;
  8463.                   case NP_KERMIT:
  8464.           case NP_TELNET: {
  8465.               static struct keytab * tnetbl = NULL;
  8466.               static int ntnetbl = 0;
  8467.               x = ck_get_crypt_table(&tnetbl,&ntnetbl);
  8468.               debug(F101,"ck_get_crypt_table x","",x);
  8469.               debug(F101,"ck_get_crypt_table n","",ntnetbl);
  8470.               if (x < 1 || !tnetbl || ntnetbl < 1) /* Didn't get it */
  8471.                         x = 0;
  8472.               if (!x) {
  8473.               slmsg = "Internal error";
  8474.               printf("?Oops, types not loaded\n");
  8475.               return(-9);
  8476.               }
  8477.               if ((x = cmkey(tnetbl,ntnetbl,"type of encryption",
  8478.                      "automatic",xxstring)) < 0)
  8479.                         return(x);
  8480.               e_type = x;
  8481.               break;
  8482.           }
  8483.         }
  8484.                 break;
  8485. #endif /* CK_ENCRYPTION */
  8486.           case SL_WAIT:
  8487.         wait = 1;
  8488.         break;
  8489.           case SL_NOWAIT:
  8490.         wait = 0;
  8491.         break;
  8492.         }
  8493.     }
  8494.  
  8495. #ifdef NETFILE
  8496.     if (mynet == NET_FILE)        /* Parsed by cmifi() */
  8497.       if ((x = cmcfm()) < 0)    /* Needs confirmation */
  8498.         return(x);
  8499. #endif /* NETFILE */
  8500.  
  8501. #ifdef NETCMD
  8502.     if (mynet == NET_CMD || mynet == NET_PTY) {
  8503.         char *p = NULL;
  8504.         if (!confirmed) {
  8505.         if ((x = cmtxt("Rest of command","",&s,xxstring)) < 0)
  8506.           return(x);
  8507.         if (*s) {
  8508.             strncat(line," ",LINBUFSIZ);
  8509.             strncat(line,s,LINBUFSIZ);
  8510.         }
  8511.         s = line;
  8512.         }
  8513.         s = brstrip(s);
  8514.         makestr(&p,s);
  8515.         strcpy(line,p);
  8516.         makestr(&p,NULL);
  8517.         s = line;
  8518.     }
  8519.     debug(F110,"SUNDAY 2",line,0);
  8520. #endif /* NETCMD */
  8521.  
  8522. #ifdef NPIPE                /* Named pipe */
  8523.     if (mynet == NET_PIPE) {    /* Needs backslash twiddling */
  8524.         if (*s) {
  8525.         if (strcmp(s,"*")) {    /* If remote, */
  8526.             strcpy(line,"\\\\"); /* begin with server name */
  8527.             strncat(line,s,LINBUFSIZ);
  8528.         } else {
  8529.             line[0]='\0';
  8530.         }
  8531.         strncat(line,"\\pipe\\", LINBUFSIZ); /* Make it a pipe name */
  8532.         strncat(line,pipename, LINBUFSIZ); /* Add name of pipe */
  8533.         s = line;
  8534.         }
  8535.     }
  8536. #endif /* NPIPE */
  8537.  
  8538. #ifdef SUPERLAT
  8539.     if (mynet == NET_SLAT) {    /* Needs password, etc. */
  8540.         slat_pwd[0] = NUL;        /* Erase any previous password */
  8541.  
  8542.         if (*s) {            /* If they gave a host name... */
  8543.         if ((x = cmfld(
  8544.              "password,\n or carriage return if no password required",
  8545.                    "",
  8546.                    &s,
  8547.                    xxstring
  8548.                    )) < 0 && x != -3)
  8549.           return(x);
  8550.         ckstrncpy(slat_pwd,s,18); /* Set the password, if any */
  8551.         }
  8552.         if ((x = cmcfm()) < 0) return(x); /* Confirm the command */
  8553.         s = line;
  8554.     }
  8555. #endif /* SUPERLAT */
  8556.  
  8557. #ifdef TCPSOCKET
  8558.     if (mynet == NET_TCPB) {    /* TCP/IP connection */
  8559.         debug(F110,"setlin service 0",srvbuf,0);
  8560.         debug(F110,"setlin host s 2",s,0);
  8561.         if (*s) {        /* If they gave a host name... */
  8562.         debug(F110,"setlin host s 1",s,0);
  8563. #ifdef NOLISTEN
  8564.         if (mynet == NET_TCPB && *s == '*') {
  8565.             slmsg = "Incoming connections not supported";
  8566.             printf(
  8567.      "?Sorry, incoming connections not supported in this version of Kermit.\n"
  8568.                );
  8569.             return(-9);
  8570.         }
  8571. #endif /* NOLISTEN */
  8572. #ifdef RLOGCODE
  8573.         /* Allow a username if rlogin is requested */
  8574.         if (ttnproto == NP_RLOGIN
  8575. #ifdef CK_AUTHENTICATION
  8576. #ifdef CK_KERBEROS
  8577.             || ttnproto == NP_K4LOGIN || ttnproto == NP_EK4LOGIN
  8578.             || ttnproto == NP_K4LOGIN || ttnproto == NP_EK4LOGIN
  8579. #endif /* CK_KERBEROS */
  8580. #endif /* CK_AUTHENTICATION */
  8581.              ) {
  8582.             int y;
  8583.             uidflag = 0;
  8584.             /* Check for "host:service" */
  8585.             for ( ; (*s != '\0') && (*s != ':'); s++) ;
  8586.             if (*s) {    /* Service, save it */
  8587.             *s = NUL;
  8588.             ckstrncpy(srvbuf,++s,SRVBUFSIZ);
  8589.             } else {        /* No :service, then use default. */
  8590. #ifdef VMS
  8591.             switch (ttnproto) {
  8592.               case NP_RLOGIN:
  8593.                 strcpy(srvbuf,"513"); /* Use "login" */
  8594.                 break;
  8595.                           case NP_K4LOGIN:
  8596.               case NP_K5LOGIN:
  8597.                 strcpy(srvbuf,"543"); /* Use "klogin" */
  8598.                 break;
  8599.                           case NP_EK4LOGIN:
  8600.               case NP_EK5LOGIN:
  8601.                 strcpy(srvbuf,"2105"); /* Use "eklogin" */
  8602.                 break;
  8603.             }
  8604. #else /* VMS */
  8605.             switch (ttnproto) {
  8606.               case NP_RLOGIN:
  8607.                 strcpy(srvbuf,"login");
  8608.                 break;
  8609.                           case NP_K4LOGIN:
  8610.                           case NP_K5LOGIN:
  8611.                 strcpy(srvbuf,"klogin");
  8612.                 break;
  8613.                           case NP_EK4LOGIN:
  8614.                           case NP_EK5LOGIN:
  8615.                 strcpy(srvbuf,"eklogin");
  8616.                 break;
  8617.             }
  8618. #endif /* VMS */
  8619.             }
  8620.             if (!confirmed) {
  8621.             y = cmfld("Userid on remote system",
  8622.                   uidbuf,&s,xxstring);
  8623.             if (y < 0 && y != -3)
  8624.               return(y);
  8625.             if ((int)strlen(s) > 63) {
  8626.                 slmsg = "Internal error";
  8627.                 printf("Sorry, too long\n");
  8628.                 return(-9);
  8629.             }
  8630.                         makestr(&tmpusrid,s);
  8631.             }
  8632.         } else {    /* TELNET or SET HOST */
  8633. #endif /* RLOGCODE */
  8634.             /* s = line; */
  8635.             /* Check for "host:service" */
  8636.             for ( ; (*s != '\0') && (*s != ':'); s++) ;
  8637.             if (*s) {    /* Service, save it */
  8638.             *s = NUL;
  8639.             ckstrncpy(srvbuf,++s,SRVBUFSIZ);
  8640.             } else if (!confirmed) {
  8641.             /* No :service, let them type one. */
  8642.             if (*line != '*') { /* Not incoming */
  8643.                 if (ttnproto == NP_KERMIT) {
  8644.                 if ((x = cmfld(
  8645.                            "TCP service name or number",
  8646.                            "kermit",&s,xxstring)
  8647.                      ) < 0 && x != -3)
  8648.                   return(x);
  8649. #ifdef RLOGCODE
  8650.                 } else if (ttnproto == NP_RLOGIN) {
  8651.                 if ((x = cmfld(
  8652.   "TCP service name or number,\n or carriage return for rlogin (513)",
  8653.                            "login",&s,xxstring)
  8654.                      ) < 0 && x != -3)
  8655.                   return(x);
  8656. #ifdef CK_AUTHENTICATION
  8657. #ifdef CK_KERBEROS
  8658.                 } else if (ttnproto == NP_K4LOGIN ||
  8659.                        ttnproto == NP_K5LOGIN) {
  8660.                 if ((x = cmfld(
  8661.   "TCP service name or number,\n or carriage return for klogin (543)",
  8662.                            "klogin",&s,xxstring)
  8663.                      ) < 0 && x != -3)
  8664.                   return(x);
  8665.                 } else if (ttnproto == NP_EK4LOGIN ||
  8666.                        ttnproto == NP_EK5LOGIN) {
  8667.                 if ((x = cmfld(
  8668.   "TCP service name or number,\n or carriage return for eklogin (2105)",
  8669.                            "eklogin",&s,xxstring)
  8670.                      ) < 0 && x != -3)
  8671.                   return(x);
  8672. #endif /* CK_KERBEROS */
  8673. #endif /* CK_AUTHENTICATION */
  8674. #endif /* RLOGCODE */
  8675.                 } else {
  8676.                 if ((x = cmfld(
  8677.                            "TCP service name or number",
  8678.                            "telnet",&s,xxstring)
  8679.                      ) < 0 && x != -3)
  8680.                   return(x);
  8681.                 }
  8682.             } else { /* Incoming connection */
  8683.                 if ((x = cmfld("TCP service name or number",
  8684.                        "",&s,xxstring)
  8685.                  ) < 0 && x != -3)
  8686.                   return(x);
  8687.             }
  8688.             if (*s)        /* If they gave a service, */
  8689.               ckstrncpy(srvbuf,s,SRVBUFSIZ); /* copy it */
  8690.             }
  8691. #ifdef RLOGCODE
  8692.         }
  8693. #endif /* RLOGCODE */
  8694.         if (!confirmed) {
  8695.                     char * defproto;
  8696.                     switch (ttnproto) {
  8697.               case NP_RLOGIN:
  8698.                         defproto = "/rlogin";
  8699.                         break;
  8700.                 case NP_K4LOGIN:
  8701.                 defproto = "/k4login";
  8702.                 break;
  8703.                       case NP_K5LOGIN:
  8704.                         defproto = "/k5login";
  8705.                         break;
  8706.                       case NP_EK4LOGIN:
  8707.                         defproto = "/ek4login";
  8708.                         break;
  8709.                       case NP_EK5LOGIN:
  8710.                 defproto = "/ek5login";
  8711.                 break;
  8712.               case NP_KERMIT:
  8713.               case NP_TELNET:
  8714.                         defproto = "/telnet";
  8715.                         break;
  8716.               default:
  8717.                         defproto = "/default";
  8718.                     }
  8719.             if ((x = cmkey(tcprawtab,ntcpraw,"Switch",defproto,
  8720.                    xxstring)) < 0) {
  8721.             if (x != -3)
  8722.               return(x);
  8723.             else if ((x = cmcfm()) < 0)
  8724.               return(x);
  8725.             } else {
  8726.             rawflg = x;
  8727.             if ((x = cmcfm()) < 0)
  8728.               return(x);
  8729.             switch (rawflg) {
  8730. #ifdef CK_SSL
  8731.                           case NP_SSL:
  8732.                 ttnproto = rawflg;
  8733.                 ssl_only_flag = 1;
  8734.                 tls_only_flag = 0;
  8735.                 break;
  8736.  
  8737.                           case NP_TLS:
  8738.                 ttnproto = rawflg;
  8739.                 ssl_only_flag = 0;
  8740.                 tls_only_flag = 1;
  8741.                 break;
  8742.  
  8743.                           case NP_SSL_TELNET:
  8744.                             ttnproto = NP_TELNET;
  8745.                             ssl_only_flag = 1;
  8746.                             tls_only_flag = 0;
  8747.                             break;
  8748.  
  8749.                           case NP_TLS_TELNET:
  8750.                             ttnproto = NP_TELNET;
  8751.                             ssl_only_flag = 0;
  8752.                             tls_only_flag = 1;
  8753.                             break;
  8754. #endif /* CK_SSL */
  8755.                           case NP_NONE:
  8756.               case NP_TCPRAW:
  8757.                           case NP_RLOGIN:
  8758.                           case NP_K4LOGIN:
  8759.                           case NP_K5LOGIN:
  8760.                           case NP_EK4LOGIN:
  8761.                           case NP_EK5LOGIN:
  8762.               case NP_TELNET:
  8763.               case NP_KERMIT:
  8764.               default:
  8765.                 ttnproto = rawflg;
  8766. #ifdef CK_SSL
  8767.                 ssl_only_flag = 0;
  8768.                 tls_only_flag = 0;
  8769. #endif /* CK_SSL */
  8770.                 break;
  8771.             }
  8772.             }
  8773.         }
  8774.         }
  8775.         s = line;
  8776.     }
  8777. #endif /* TCPSOCKET */
  8778.  
  8779.     if (!*s) {
  8780.         if (!network) {
  8781.         slmsg = "Hostname or address required";
  8782.         printf("?%s\n",slmsg);
  8783.         return(-9);
  8784.         } else if (!zz) { /* No hostname given */
  8785. #ifdef CKLOGDIAL
  8786. #ifdef NETCONN
  8787.         dolognet();
  8788. #endif /* NETCONN */
  8789. #endif /* CKLOGDIAL */
  8790.         if (cx) {
  8791.             success = doconect(0);
  8792. #ifdef CKLOGDIAL
  8793.             if (ttchk() < 0)
  8794.               dologend();
  8795. #endif /* CKLOGDIAL */
  8796.             return(success);
  8797.         } else
  8798.           return(1);
  8799.         }
  8800.     }
  8801.  
  8802. #ifndef NODIAL
  8803.     /* Look up in network directory */
  8804.     x = 0;
  8805.     debug(F101,"setlin mynet 1","",mynet);
  8806.     debug(F111,"setlin nnetdir",s,nnetdir);
  8807.     if (*s == '=') {        /* If number starts with = sign */
  8808.         s++;            /* strip it */
  8809.         while (*s == SP) s++;    /* and any leading spaces */
  8810.         strcpy(line,s);        /* Do this again. */
  8811.         s = line;
  8812.         debug(F110,"setlin host s 3",s,0);
  8813.         nhcount = 0;
  8814.     } else if (*s) {        /* We want to look it up. */
  8815.         if (nnetdir > 0)        /* If there is a directory... */
  8816.           x = lunet(line);        /* (sets nhcount) */
  8817.         else            /* otherwise */
  8818.           nhcount = 0;        /* we didn't find any there */
  8819.         if (x < 0) {        /* Internal error? */
  8820.         slmsg = "Network directory lookup error";
  8821.         printf("?Fatal network directory lookup error - %s\n",line);
  8822.         return(-9);
  8823.         }
  8824.         debug(F111,"setlin lunet nhcount",line,nhcount);
  8825.     }
  8826. #endif /* NODIAL */
  8827.  
  8828.     /* New connection wanted.  Make a copy of the host name/address... */
  8829.  
  8830.     ckstrncpy(tmpbuf,s,TMPBUFSIZ);    /* Because we are reusing line[] */
  8831.     s = tmpbuf;            /* for net directory entries...  */
  8832.     debug(F111,"setlin host s 5",s,mdmtyp);
  8833.     if (clsconnx(1) < 0)        /* Close current connection */
  8834.       return(success = 0);
  8835.     if (*s) {            /* They gave a hostname */
  8836.         _local = 1;            /* Network connection always local */
  8837.         if (mdmsav < 0)
  8838.           mdmsav = mdmtyp;        /* Remember old modem type */
  8839.         mdmtyp = -mynet;        /* Special code for network */
  8840.         if (mynet == NET_TCPB) {    /* For TCP/IP telnet connections */
  8841.         oldplex = duplex;    /* Remember previous duplex */
  8842.         duplex = 0;        /* Set full duplex and let */
  8843.                                 /* negotiations change if necessary. */
  8844.         }
  8845.     } else {            /* They just said "set host" */
  8846.         s = dftty;            /* So go back to normal */
  8847.         _local = dfloc;        /* default tty, location, */
  8848.         if (zz) {
  8849.         setflow();        /* Maybe change flow control */
  8850.         haveline = 1;        /* (* is this right? *) */
  8851.                     /* why aren't we calling clsconnx()? */
  8852. #ifdef CKLOGDIAL
  8853.         dologend();
  8854. #endif /* CKLOGDIAL */
  8855.         return(success = 1);
  8856.         }
  8857.     }
  8858. #endif /* NETCONN */
  8859.     }
  8860.  
  8861. /* Serial tty device, possibly modem, connection... */
  8862.  
  8863.     if (xx == XYLINE            /* SET LINE or SET PORT */
  8864. #ifdef CK_TAPI
  8865.     || xx == XYTAPI_LIN        /* SET TAPI LINE */
  8866. #endif /* CK_TAPI */
  8867.     ) {
  8868. #ifdef OS2
  8869. /*
  8870.   User can type:
  8871.     COM1..COM8 = Regular COM port
  8872.     1..8       = Synonym for COM1..COM8, is translated to COM1..COM8
  8873.     _n         = (n is a number) = open file handle
  8874.     string     = any text string = name of some other kind of device,
  8875.                  taken literally, as given.
  8876. */
  8877.     s = "Communication device name";
  8878. #ifdef CK_TAPI
  8879.     if (TAPIAvail)
  8880.           cktapiBuildLineTable(&tapilinetab, &_tapilinetab, &ntapiline);
  8881.     if (!(tapilinetab && _tapilinetab && ntapiline > 0) &&
  8882.         xx == XYTAPI_LIN ) {
  8883.         slmsg = "TAPI device not configured";
  8884.         printf("\nNo TAPI Line Devices are configured for this system\n");
  8885.         return(-9);
  8886.     }
  8887.     if (xx == XYTAPI_LIN) {        /* Default (first) TAPI line */
  8888.         s = "tapi";            /* (whatever it is) */
  8889.     } else {            /* Query the user */
  8890. #endif /* CK_TAPI */
  8891.  
  8892. /* Now parse optional switches and then device name */
  8893.  
  8894.         confirmed = 0;
  8895.         cmfdbi(&sw,_CMKEY,"Device name, or switch",
  8896.            "","",npsltab,4,xxstring,psltab,&fl);
  8897.         cmfdbi(&fl,_CMFLD,"",dftty,"",0,0,xxstring,NULL,NULL);
  8898.         while (1) {
  8899.         x = cmfdb(&sw);
  8900.         debug(F101,"setlin cmfdb","",x);
  8901.         if (x < 0)
  8902.           if (x != -3)
  8903.             return(x);
  8904.         if (x == -3) {
  8905.             if ((x = cmcfm()) < 0) {
  8906.             return(x);
  8907.             } else {
  8908.             confirmed = 1;
  8909.             break;
  8910.             }
  8911.         }
  8912.         if (cmresult.fcode == _CMFLD) {
  8913.             s = cmresult.sresult;
  8914.             break;
  8915.         } else if (cmresult.fcode == _CMKEY) {
  8916.             switch (cmresult.nresult) {
  8917.               case SL_CNX:    /* /CONNECT */
  8918.             cx = 1;
  8919.             sx = 0;
  8920.             break;
  8921.               case SL_SRV:    /* /SERVER */
  8922.             cx = 0;
  8923.             sx = 1;
  8924.             break;
  8925.             }
  8926.         }
  8927.         }
  8928. #ifdef CK_TAPI
  8929.     }
  8930. #endif /* CK_TAPI */
  8931.  
  8932.     debug(F110,"OS2 SET PORT s",s,0);
  8933.     y = lookup(os2devtab,s,nos2dev,&x); /* Look up in keyword table */
  8934.     debug(F101,"OS2 SET PORT x","",x);
  8935.     debug(F101,"OS2 SET PORT y","",y);
  8936.     if ((y > -1) && (x >= 0 && x < 8)) { /* User typed a digit 1..8 */
  8937.         s = os2devtab[x+8].kwd;    /* Substitite its real name */
  8938. #ifdef NT
  8939.         xxtapi = 0;
  8940. #else /* NT */
  8941.         xxslip = xxppp = 0;
  8942. #endif /* NT */
  8943.         debug(F110,"OS2 SET PORT subst s",s,"");
  8944. #ifndef NT
  8945.     } else if ((y >-1) && (x >= 16 && x < 24)) { /* SLIP access */
  8946.         s = os2devtab[x-8].kwd;    /* Substitite its real name */
  8947.         debug(F110,"OS2 SET PORT SLIP subst s",s,"");
  8948.         xxslip = 1;
  8949.         xxppp  = 0;
  8950.     } else if ((y >-1) && (x >= 24 && x < 32)) { /* PPP access */
  8951.         s = os2devtab[x-16].kwd;    /* Substitite its real name */
  8952.         debug(F110,"OS2 SET PORT PPP subst s",s,"");
  8953.         xxppp = 1;
  8954.         xxslip = 0;
  8955.         if ((y = cmkey(os2ppptab,
  8956.                nos2ppp,
  8957.                "PPP driver interface",
  8958.                "ppp0",
  8959.                xxstring)
  8960.          ) < 0)
  8961.         return(y);
  8962.         debug(F101,"OS2 SET PORT PPP INTERFACE y","",y);
  8963.         xxppp = (y % 10) + 1;
  8964. #endif /* NT */
  8965.     } else if (*s == '_') {        /* User used "_" prefix */
  8966.         s++;            /* Remove it */
  8967.         /* Rest must be numeric */
  8968.         debug(F110,"OS2 SET PORT HANDLE _subst s",s,0);
  8969.         if (!rdigits(s)) {
  8970.         slmsg = "Invalid file handle";
  8971.         printf("?Invalid format for file handle\n");
  8972.         return(-9);
  8973.         }
  8974. #ifdef NT
  8975.         xxtapi = 0;
  8976. #else /* NT */
  8977.         xxslip = xxppp = 0;
  8978. #endif /* NT */
  8979.     } else {            /* A normal COMx port or a string */
  8980.         s = brstrip(s);        /* Strip braces if any */
  8981. #ifdef NT
  8982. #ifdef CK_TAPI
  8983.         /* Windows TAPI support - Look up in keyword table */
  8984.         if (tapilinetab && _tapilinetab && ntapiline > 0) {
  8985.         if (!ckstrcmp(s,"tapi",4,0)) {
  8986.  
  8987.             /* Find out what the lowest numbered TAPI device is */
  8988.             /* and use it as the default.                       */
  8989.             int j = 9999, k = -1;
  8990.             for (i = 0; i < ntapiline; i++) {
  8991.                 if (tapilinetab[i].kwval < j) {
  8992.                 j = tapilinetab[i].kwval;
  8993.                 k = i;
  8994.             }
  8995.             }
  8996.             if (k >= 0)
  8997.               s = _tapilinetab[k].kwd;
  8998.             else
  8999.               s = "";
  9000.  
  9001.             if ((y = cmkey(_tapilinetab,ntapiline,
  9002.                    "TAPI device name",s,xxstring)) < 0)
  9003.               return(y);
  9004.  
  9005.             xxtapi = 1;
  9006.  
  9007.             /* Get the non Underscored string */
  9008.             for (i = 0; i < ntapiline; i++ ) {
  9009.                 if (tapilinetab[i].kwval == y) {
  9010.                 s = tapilinetab[i].kwd;
  9011.                 break;
  9012.             }
  9013.             }
  9014.         } else
  9015.           xxtapi = 0;
  9016.         }
  9017. #endif /* CK_TAPI */
  9018. #else /* NT */
  9019.         /* not OS/2 SLIP or PPP */
  9020.         xxslip = xxppp = 0;
  9021. #endif /* NT */
  9022.         }
  9023.     strcpy(tmpbuf,s);        /* Copy to a safe place */
  9024.     s = tmpbuf;
  9025.     if ((x = cmcfm()) < 0)
  9026.       return(x);
  9027.  
  9028. #else /* !OS2 */
  9029.  
  9030.     cmfdbi(&sw,_CMKEY,"Device name, or switch",
  9031.            "","",npsltab,4,xxstring,psltab,&tx);
  9032.     cmfdbi(&tx,_CMTXT,"",dftty,"",0,0,xxstring,NULL,NULL);
  9033.     while (!confirmed) {
  9034.         x = cmfdb(&sw);
  9035.         debug(F101,"setlin cmfdb","",x);
  9036.         if (x < 0)
  9037.           if (x != -3)
  9038.         return(x);
  9039.         if (x == -3) {
  9040.         if ((x = cmcfm()) < 0) {
  9041.             return(x);
  9042.         } else {
  9043.             confirmed = 1;
  9044.             break;
  9045.         }
  9046.         }
  9047.         switch (cmresult.fcode) {
  9048.           case _CMTXT:
  9049.         strcpy(tmpbuf,cmresult.sresult);
  9050.         s = tmpbuf;
  9051.         debug(F110,"setlin CMTXT",tmpbuf,0);
  9052.         confirmed = 1;
  9053.         break;
  9054.           case _CMKEY:        /* Switch */
  9055.         debug(F101,"setlin CMKEY",tmpbuf,cmresult.nresult);
  9056.         switch (cmresult.nresult) {
  9057.           case SL_CNX:        /* /CONNECT */
  9058.             cx = 1;
  9059.             sx = 0;
  9060.             break;
  9061.           case SL_SRV:        /* /SERVER */
  9062.             cx = 0;
  9063.             sx = 1;
  9064.             break;
  9065. #ifdef VMS
  9066.           case SL_SHR:        /* /SHARE */
  9067.             shr = 1;
  9068.             break;
  9069.           case SL_NSH:        /* /NOSHARE */
  9070.             shr = 0;
  9071.             break;
  9072. #endif /* VMS */
  9073.         }
  9074.         continue;
  9075.           default:
  9076.         debug(F101,"setlin bad cmfdb result","",cmresult.fcode);
  9077.         slmsg = "Internal error";
  9078.         printf("?Internal parsing error\n");
  9079.         return(-9);
  9080.         }
  9081.     }
  9082. #endif /* OS2 */
  9083.     if (!confirmed)
  9084.       if ((x = cmcfm()) < 0)
  9085.         return(x);
  9086.     debug(F101,"setlin confirmed mdmtyp","",mdmtyp);
  9087.     if (clsconnx(1) < 0)        /* Close the connection */
  9088.       return(success = 0);
  9089.     if (*s) {            /* They gave a device name */
  9090.         _local = -1;        /* Let ttopen decide about it */
  9091.     } else {            /* They just said "set line" */
  9092.         s = dftty;            /* so go back to normal tty */
  9093.         _local = dfloc;        /* and mode. */
  9094.     }
  9095. #ifdef VMS
  9096.     {
  9097.         extern int ok_to_share;
  9098.         ok_to_share = shr;
  9099.     }
  9100. #endif /* VMS */
  9101.  
  9102. #ifdef OS2                /* Must wait until after ttclos() */
  9103. #ifdef NT                /* to change these settings       */
  9104. #ifdef CK_TAPI
  9105.     tttapi = xxtapi;
  9106. #endif /* CK_TAPI */
  9107. #else
  9108.     ttslip = xxslip;
  9109.     ttppp  = xxppp;
  9110. #endif /* NT */
  9111.     debug(F110,"OS2 SET PORT final s",s,"");
  9112. #endif /* OS2 */
  9113.     }
  9114.     success = 0;
  9115.     if (mdmtyp > -1) {            /* Serial connections... */
  9116.     /* Open the new line */
  9117.     if ((y = ttopen(s,&_local,mdmtyp,cdtimo)) > -1) {
  9118.         cxtype = (mdmtyp > 0) ? CXT_MODEM : CXT_DIRECT;
  9119. #ifdef COMMENT
  9120.         flow = cxflow[cxtype];    /* Set connection type and flow */
  9121. #else
  9122.         setflow();            /* Only if autoflow()! */
  9123. #endif /* COMMENT */
  9124.         success = 1;
  9125. #ifdef CK_TAPI
  9126.         /* if the line is a tapi device, then we need to auto-execute */
  9127.         /* SET MODEM TYPE TAPI - which we do the equivalent of here.  */
  9128.         if (xxtapi) {
  9129.         extern int usermdm;
  9130.         usermdm = 0;
  9131.         initmdm(38);           /* From ckudia.c n_TAPI == 38 */
  9132.         }
  9133. #endif /* CK_TAPI */
  9134.  
  9135.     } else {
  9136. #ifdef OS2ONLY
  9137.         if (!strcmp(s,dftty))   /* Do not generate an error with dftty */
  9138.           ;
  9139.         else if (y == -6 && ttslip) {
  9140.         slmsg = "Can't access SLIP driver";
  9141.         if (!quiet || cmdsrc() == 0)
  9142.           printf("?Unable to access SLIP driver.\n");
  9143.         } else if (y == -6 && ttppp) {
  9144.         if (!quiet || cmdsrc() == 0)
  9145.           slmsg = "Can't access PPP driver";
  9146.         printf("?Unable to access PPP driver (wrong interface?)\n");
  9147.         } else
  9148. #endif /* OS2ONLY */
  9149.           if (y == -2) {
  9150.           slmsg = "Timed out - no carrier";
  9151.           if (!quiet || cmdsrc() == 0) {
  9152.               printf("?Timed out, no carrier.\n");
  9153.               printf(
  9154.             "Try SET CARRIER OFF and SET LINE again, or else\n");
  9155.               printf("SET MODEM, SET LINE, and then DIAL.\n");
  9156.           }
  9157.           } else if (y == -3) {
  9158.           slmsg = "Access to lock denied";
  9159.           if (!quiet || cmdsrc() == 0) {
  9160. #ifdef UNIX
  9161.               printf(
  9162. "Sorry, write access to UUCP lockfile directory denied.\n");
  9163. #ifndef NOHINTS
  9164.               if (hints) {
  9165.               printf("\n*************************\n");
  9166.               printf(
  9167. "HINT (Use SET HINTS OFF to suppress future hints):\n");
  9168.               printf(
  9169. "Please read the installation instructions file, %sckuins.txt,\n",
  9170.                  k_info_dir ? k_info_dir : ""
  9171.                  );
  9172.               printf(
  9173. "or the UNIX appendix of the manual, \"Using C-Kermit\".\n"
  9174.                  );
  9175.               printf("*************************\n\n");
  9176.               }
  9177. #endif /* NOHINTS */
  9178. #else
  9179.               printf("Sorry, access to lock denied: %s\n",s);
  9180. #endif /* UNIX */
  9181.           }
  9182.           } else if (y == -4) {
  9183.           slmsg = "Access to device denied";
  9184.           if (!quiet || cmdsrc() == 0) {
  9185.               printf("Sorry, access to device denied: %s\n",s);
  9186. #ifdef UNIX
  9187. #ifndef NOHINTS
  9188.               if (hints) {
  9189.               printf("\n*************************\n");
  9190.               printf(
  9191. "HINT (Use SET HINTS OFF to suppress future hints):\n");
  9192.               printf(
  9193. "Please read the installation instructions file, %sckuins.txt,\n",
  9194.                  k_info_dir ? k_info_dir : ""
  9195.                  );
  9196.               printf(
  9197. "or the UNIX appendix of the manual, \"Using C-Kermit\".\n"
  9198.                  );
  9199.               printf("*************************\n\n");
  9200.               }
  9201. #endif /* NOHINTS */
  9202. #endif /* UNIX */
  9203.           }
  9204.           } else if (y == -5) {
  9205.           slmsg = "Device is in use or unavailable";
  9206.           if (!quiet || cmdsrc() == 0)
  9207. #ifdef VMS
  9208.             printf(
  9209.            "Sorry, device is in use or otherwise unavailable: %s\n",s);
  9210. #else
  9211.             printf("Sorry, device is in use: %s\n",s);
  9212. #endif /* VMS */
  9213.           } else {            /* Other error. */
  9214.           slmsg = "Device open failed";
  9215.           if (
  9216. #ifdef VMS
  9217.               1
  9218. #else
  9219.               errno
  9220. #endif /* VMS */
  9221.               ) {
  9222.               int x;        /* Find a safe, long buffer */
  9223.               makestr(&tmpslmsg,ck_errstr());
  9224.               slmsg = tmpslmsg;
  9225. #ifndef VMS
  9226.               debug(F111,"setlin serial errno",slmsg,errno);
  9227. #endif /* VMS */
  9228.               if (!quiet || cmdsrc() == 0) {
  9229.               x = strlen(line) + 2; /* for the error message. */
  9230.               if (LINBUFSIZ - x > 100) { /* Room for 100 chars */
  9231.                   tp = line + x;
  9232.                   sprintf(tp,"Sorry, can't open connection: %s",s);
  9233.                   perror(tp);
  9234.               } else
  9235.                 printf("Sorry, can't open connection: %s\n",s);
  9236.               }
  9237.           } else if (!quiet || cmdsrc() == 0)
  9238.             printf("Sorry, can't open connection: %s\n",s);
  9239.           }
  9240.     }
  9241.     }
  9242. #ifdef NETCONN
  9243.     else {                /* mdmtyp < 0: Network connection */
  9244.     char *p;
  9245.     int i, n;
  9246. #ifndef NODIAL
  9247.     debug(F101,"setlin mynet 3","",mynet);
  9248.     debug(F101,"setlin nhcount","",nhcount);
  9249.     if ((nhcount > 1) && !quiet && !backgrd) {
  9250.         int k;
  9251.         printf("%d entr%s found for \"%s\"%s\n",
  9252.            nhcount,
  9253.            (nhcount == 1) ? "y" : "ies",
  9254.            s,
  9255.            (nhcount > 0) ? ":" : "."
  9256.            );
  9257.         for (i = 0; i < nhcount; i++) {
  9258.             printf("%3d. %-12s => %-9s %s",
  9259.                i+1,n_name,nh_p2[i],nh_p[i]);
  9260.         for (k = 0; k < 4; k++) { /* Also list net-specific items */
  9261.             if (nh_px[k][i])      /* free format... */
  9262.               printf(" %s",nh_px[k][i]);
  9263.             else
  9264.               break;
  9265.         }
  9266.         printf("\n");
  9267.         }
  9268.     }
  9269.     if (nhcount == 0)
  9270.       n = 1;
  9271.     else
  9272.       n = nhcount;
  9273. #else
  9274.     n = 1;
  9275.     nhcount = 0;
  9276. #endif /* NODIAL */
  9277.     for (i = 0; i < n; i++) {    /* Loop for each entry found */
  9278. #ifndef NODIAL
  9279.         debug(F101,"setlin loop i","",i);
  9280.         if (nhcount > 0) {        /* If we found at least one entry... */
  9281.         strcpy(line,nh_p[i]);    /* Copy the current entry to line[] */
  9282.         if (lookup(netcmd,nh_p2[i],nnets,&x) > -1) { /* Net type */
  9283.             mynet = netcmd[x].kwval;
  9284.             mdmtyp  = 0 - mynet;
  9285.             debug(F101,"setlin mynet 4","",mynet);
  9286.         } else {
  9287.             slmsg = "Network type not supported";
  9288.             printf("Error - network type \"%s\" not supported\n",
  9289.                nh_p2[i]
  9290.                );
  9291.             continue;
  9292.         }
  9293.  
  9294.         switch (mynet) {    /* Net-specific things */
  9295.  
  9296.           case NET_TCPB: {    /* TCP/IP */
  9297. #ifdef TCPSOCKET
  9298.               char *q;
  9299.               int flag = 0;
  9300.  
  9301.               /* Extract ":service", if any, from host string */
  9302.               debug(F110,"setlin service 1",line,0);
  9303.               for (q = line; (*q != '\0') && (*q != ':'); q++)
  9304.             ;
  9305.               if (*q == ':') { *q++ = NUL; flag = 1; }
  9306.               debug(F111,"setlin service 2",line,flag);
  9307.  
  9308.               /* Get service, if any, from directory entry */
  9309.  
  9310.               if (!*srvbuf) {
  9311.               if (nh_px[0][i]) {
  9312.                   ckstrncpy(srvbuf,nh_px[0][i],SRVBUFSIZ);
  9313.                   debug(F110,"setlin service 3",srvbuf,0);
  9314.               }
  9315.               if (flag) {
  9316.                   ckstrncpy(srvbuf,q,SRVBUFSIZ);
  9317.                   debug(F110,"setlin service 4",srvbuf,0);
  9318.               }
  9319.               }
  9320.  
  9321.                       /* Save the hostname */
  9322.                       strcpy(hostname,line);
  9323.  
  9324.               /* If we have a service, append to host name/address */
  9325.               if (*srvbuf) {
  9326.               strncat(line, ":", LINBUFSIZ);
  9327.               strncat(line, srvbuf, LINBUFSIZ);
  9328.               debug(F110,"setlin service 5",line,0);
  9329.               }
  9330. #ifdef RLOGCODE
  9331.               /* If no service given but command was RLOGIN */
  9332.               else if (ttnproto == NP_RLOGIN) {    /* add this... */
  9333.               strncat(line, ":login",LINBUFSIZ);
  9334.               debug(F110,"setlin service 6",line,0);
  9335.               }
  9336. #ifdef CK_AUTHENTICATION
  9337. #ifdef CK_KERBEROS
  9338.               else if (ttnproto == NP_K4LOGIN ||
  9339.                    ttnproto == NP_K5LOGIN) { /* add this... */
  9340.               strncat(line, ":klogin",LINBUFSIZ);
  9341.               debug(F110,"setlin service 7",line,0);
  9342.               }
  9343.               else if (ttnproto == NP_EK4LOGIN ||
  9344.                    ttnproto == NP_EK5LOGIN) { /* add this... */
  9345.               strncat(line, ":eklogin",LINBUFSIZ);
  9346.               debug(F110,"setlin service 8",line,0);
  9347.               }
  9348. #endif /* CK_KERBEROS */
  9349. #endif /* CK_AUTHENTICATION */
  9350. #endif /* RLOGCODE */
  9351.               else {        /* Otherwise, add ":telnet". */
  9352.               strncat(line, ":telnet", LINBUFSIZ);
  9353.               debug(F110,"setlin service 9",line,0);
  9354.               }
  9355.  
  9356.                       if (tmpusrid) if (tmpusrid[0]) {
  9357.                           ckstrncpy(uidbuf,tmpusrid,UIDBUFLEN);
  9358.                           makestr(&tmpusrid,NULL);
  9359.                           uidflag = 1;
  9360.                       }
  9361.  
  9362.               /* Fifth field, if any, is user ID (for rlogin) */
  9363.  
  9364.               if (nh_px[1][i] && !uidflag)
  9365.             ckstrncpy(uidbuf,tmpusrid,UIDBUFLEN);
  9366. #ifdef RLOGCODE
  9367.               if ((ttnproto == NP_RLOGIN
  9368. #ifdef CK_AUTHENTICATION
  9369. #ifdef CK_KERBEROS
  9370.                || ttnproto == NP_K4LOGIN || ttnproto == NP_EK4LOGIN
  9371.                || ttnproto == NP_K5LOGIN || ttnproto == NP_EK5LOGIN
  9372. #endif /* CK_KERBEROS */
  9373. #endif /* CK_AUTHENTICATION */
  9374.                ) && !uidbuf[0]) {
  9375.               slmsg = "Username required";
  9376.               printf("Username required for rlogin\n");
  9377.               return(-9);
  9378.               }
  9379. #endif /* RLOGCODE */
  9380. #endif /* TCPSOCKET */
  9381.               break;
  9382.           }
  9383.  
  9384.  
  9385.           case NET_PIPE:
  9386. #ifdef NPIPE
  9387.             if (!pipename[0]) {    /* User didn't give a pipename */
  9388.             if (nh_px[0][i]) { /* But directory entry has one */
  9389.                 if (strcmp(pipename,"\\pipe\\")) {
  9390.                 strcpy(pipename,"\\pipe\\");
  9391.                 strncat(srvbuf,nh_px[0][i],PIPENAML-6);
  9392.                 } else {
  9393.                 ckstrncpy(pipename,nh_px[0][i],PIPENAML);
  9394.                 }
  9395.                 debug(F110,"setlin pipeneme",pipename,0);
  9396.             }
  9397.             }
  9398. #endif /* NPIPE */
  9399.             break;
  9400.  
  9401.           case NET_SLAT:
  9402. #ifdef SUPERLAT
  9403.             if (!slat_pwd[0]) {    /* User didn't give a password */
  9404.             if (nh_px[0][i]) { /* But directory entry has one */
  9405.                 ckstrncpy(slat_pwd,nh_px[0][i],18);
  9406.                 debug(F110,"setlin SuperLAT password",slat_pwd,0);
  9407.             }
  9408.             }
  9409. #endif /* SUPERLAT */
  9410.             break;
  9411.  
  9412.           case NET_SX25:    /* X.25 keyword parameters */
  9413.           case NET_IX25:
  9414.           case NET_VX25: {
  9415. #ifdef ANYX25
  9416.               int k;        /* Cycle through the four fields */
  9417.               for (k = 0; k < 4; k++) {
  9418.               if (!nh_px[k][i]) /* Bail out if none left */
  9419.                 break;
  9420.               if (!ckstrcmp(nh_px[k][i],"cug=",4,0)) {
  9421.                   closgr = atoi(nh_px[k][i]+4);
  9422.                   debug(F101,"X25 CUG","",closgr);
  9423.               } else if (!ckstrcmp(nh_px[k][i],"cud=",4,0)) {
  9424.                   cudata = 1;
  9425.                   ckstrncpy(udata,nh_px[k][i]+4,MAXCUDATA);
  9426.                   debug(F110,"X25 CUD",cudata,0);
  9427.               } else if (!ckstrcmp(nh_px[k][i],"rev=",4,0)) {
  9428.                   revcall = !ckstrcmp(nh_px[k][i]+4,"=on",3,0);
  9429.                   debug(F101,"X25 REV","",revcall);
  9430. #ifndef IBMX25
  9431.               } else if (!ckstrcmp(nh_px[k][i],"pad=",4,0)) {
  9432.                   int x3par, x3val;
  9433.                   char *s1, *s2;
  9434.                   s1 = s2 = nh_px[k][i]+4; /* PAD parameters */
  9435.                   while (*s2) {            /* Pick them apart */
  9436.                   if (*s2 == ':') {
  9437.                       *s2 = NUL;
  9438.                       x3par = atoi(s1);
  9439.                       s1 = ++s2;
  9440.                       continue;
  9441.                   } else if (*s2 == ',') {
  9442.                       *s2 = NUL;
  9443.                       x3val = atoi(s1);
  9444.                       s1 = ++s2;
  9445.                       debug(F111,"X25 PAD",x3par,x3val);
  9446.                       if (x3par > -1 &&
  9447.                       x3par <= MAXPADPARMS)
  9448.                     padparms[x3par] = x3val;
  9449.                       continue;
  9450.                   } else
  9451.                     s2++;
  9452.                   }
  9453. #endif /* IBMX25 */
  9454.               }
  9455.               }
  9456. #endif /* ANYX25 */
  9457.               break;
  9458.           }
  9459.  
  9460.           default:        /* Nothing special for other nets */
  9461.             break;
  9462.         }
  9463.         } else {            /* No directory entries found. */
  9464.         strcpy(line,tmpbuf);    /* Put this back... */
  9465.         if (mynet == NET_TCPB)    /* If the user gave a TCP service */
  9466.                   strcpy(hostname,line);
  9467.           if (*srvbuf) {    /* append it to host name/address */
  9468.               strncat(line, ":", LINBUFSIZ);
  9469.               strncat(line, srvbuf,LINBUFSIZ);
  9470.           }
  9471.         }
  9472. #endif /* NODIAL */
  9473.         /*
  9474.            Get here with host name/address and all net-specific
  9475.            parameters set, ready to open the connection.
  9476.         */
  9477.         mdmtyp = -mynet;        /* This should have been done */
  9478.                     /* already but just in case ... */
  9479.  
  9480.         debug(F110,"setlin net line[] before ttopen",line,0);
  9481.         debug(F101,"setlin net mdmtyp before ttopen","",mdmtyp);
  9482.         debug(F101,"setlin net ttnproto","",ttnproto);
  9483.  
  9484. #ifdef CK_AUTHENTICATION
  9485.             if ((ttnproto == NP_TELNET || ttnproto == NP_KERMIT) &&
  9486.                  a_type > -1) {
  9487.                 if (!sl_auth_saved) {
  9488.                     int x;
  9489.                     for (x = 0; x < AUTHTYPLSTSZ; x++)
  9490.               sl_auth_type_user[x] = auth_type_user[x];
  9491.                     sl_auth_saved = 1;
  9492.                 }
  9493.                 if (!sl_topt_a_s_saved) {
  9494.                     sl_topt_a_su = TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION);
  9495.                     sl_topt_a_s_saved = 1;
  9496.                 }
  9497.                 if (!sl_topt_a_c_saved) {
  9498.                     sl_topt_a_cm = TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION);
  9499.                     sl_topt_a_c_saved = 1;
  9500.                 }
  9501.                 switch (a_type) {
  9502.                   case AUTHTYPE_AUTO:
  9503.                     auth_type_user[0] = AUTHTYPE_AUTO;
  9504.                     TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_RQ;
  9505.                     TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_RQ;
  9506.                     break;
  9507.                   case AUTHTYPE_NULL:
  9508.             auth_type_user[0] = AUTHTYPE_NULL;
  9509.             TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_RF;
  9510.             TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_RF;
  9511.             break;
  9512. #ifdef CK_SRP
  9513.           case AUTHTYPE_SRP:
  9514.                     auth_type_user[0] = AUTHTYPE_SRP;
  9515.                     auth_type_user[1] = AUTHTYPE_NULL;
  9516.                     TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  9517.                     TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  9518.                     break;
  9519. #endif /* CK_SRP */
  9520. #ifdef CK_SSL
  9521.           case AUTHTYPE_SSL:
  9522.                     auth_type_user[0] = AUTHTYPE_SSL;
  9523.                     auth_type_user[1] = AUTHTYPE_NULL;
  9524.                     TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  9525.                     TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  9526.                     break;
  9527. #endif /* CK_SSL */
  9528. #ifdef NT
  9529.           case AUTHTYPE_NTLM:
  9530.                     auth_type_user[0] = AUTHTYPE_NTLM;
  9531.                     auth_type_user[1] = AUTHTYPE_NULL;
  9532.                     TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  9533.                     TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  9534.                     break;
  9535. #endif /* NT */
  9536. #ifdef CK_KERBEROS
  9537.           case AUTHTYPE_KERBEROS_V4:
  9538.                     auth_type_user[0] = AUTHTYPE_KERBEROS_V4;
  9539.                     auth_type_user[1] = AUTHTYPE_NULL;
  9540.                     TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  9541.                     TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  9542.                     break;
  9543.  
  9544.           case AUTHTYPE_KERBEROS_V5:
  9545.                     auth_type_user[0] = AUTHTYPE_KERBEROS_V5;
  9546.                     auth_type_user[1] = AUTHTYPE_NULL;
  9547.                     TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  9548.                     TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  9549.                     break;
  9550. #endif /* CK_KERBEROS */
  9551.                 }
  9552.             }
  9553.  
  9554.             /*
  9555.                If the user is going to require a Kerberos connection
  9556.                of a particular type, let's make sure we have a valid TGT.
  9557.             */
  9558.         slmsg = "Authentication failure";
  9559.             if ((ttnproto == NP_TELNET || ttnproto == NP_KERMIT) &&
  9560.         (line[0] == '*' &&
  9561.          TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) == TN_NG_MU ||
  9562.          line[0] != '*' &&
  9563.          TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) == TN_NG_MU)
  9564.         ) {
  9565. #ifdef CK_KERBEROS
  9566.                 if ( auth_type_user[0] == AUTHTYPE_KERBEROS_V4 ) {
  9567.                     extern int krb4_autoget;
  9568.                     if (!ck_krb4_is_installed()) {
  9569.             printf(
  9570.         "?Required authentication method (Kerberos 4) is not installed\n"
  9571.                    );
  9572.                         slrestor();
  9573.             return(success = 0);
  9574.                     }
  9575. #ifdef COMMENT
  9576.                     /* This code results in false failures when using */
  9577.                     /* kerberos to machines in realms other than the  */
  9578.                     /* default since we don't know the realm of the   */
  9579.                     /* other machine until perform the reverse DNS    */
  9580.                     /* lookup.                                        */
  9581.             else if (line[0] != '*' && !ck_krb4_is_tgt_valid() &&
  9582.                    (!krb4_autoget ||
  9583.                 krb4_autoget && !ck_krb4_autoget_TGT(NULL))) {
  9584.                         printf(
  9585.         "?Kerberos 4: Ticket Getting Ticket not valid.\n"
  9586.                    );
  9587.                         slrestor();
  9588.                         return(success = 0);
  9589.                     }
  9590. #endif /* COMMENT */
  9591.                 } else if (auth_type_user[0] == AUTHTYPE_KERBEROS_V5) {
  9592.                     extern int krb5_autoget;
  9593.                     if (!ck_krb5_is_installed()) {
  9594.             printf(
  9595.         "?Required authentication method (Kerberos 5) is not installed\n"
  9596.                    );
  9597.                         slrestor();
  9598.                         return(success = 0);
  9599.                     }
  9600. #ifdef COMMENT
  9601.                     /* This code results in false failures when using */
  9602.                     /* kerberos to machines in realms other than the  */
  9603.                     /* default since we don't know the realm of the   */
  9604.                     /* other machine until perform the reverse DNS    */
  9605.                     /* lookup.                                        */
  9606.             else if (line[0] != '*' && !ck_krb5_is_tgt_valid() &&
  9607.                    (!krb5_autoget ||
  9608.                 krb5_autoget && !ck_krb5_autoget_TGT(NULL))) {
  9609.                         printf(
  9610.         "?Kerberos 5: Ticket Getting Ticket not valid.\n"
  9611.                    );
  9612.                         slrestor();
  9613.                         return(success = 0);
  9614.                     }
  9615. #endif /* COMMENT */
  9616.                 }
  9617. #endif /* CK_KERBEROS */
  9618. #ifdef NT
  9619.                 if (auth_type_user[0] == AUTHTYPE_NTLM) {
  9620.                     if (!ck_ntlm_is_installed()) {
  9621.             printf(
  9622.         "?Required authentication method (NTLM) is not installed\n"
  9623.                    );
  9624.                         slrestor();
  9625.                         return(success = 0);
  9626.                     } else if (line[0] != '*' && !ck_ntlm_is_valid()) {
  9627.                         printf("?NTLM: Credentials are unavailable.\n");
  9628.                         slrestor();
  9629.                         return(success = 0);
  9630.                     }
  9631.                 }
  9632. #endif /* NT */
  9633. #ifdef CK_SSL
  9634.                 if (auth_type_user[0] == AUTHTYPE_SSL) {
  9635.                     if (!ck_ssleay_is_installed()) {
  9636.             printf(
  9637.         "?Required authentication method (SSL) is not installed\n"
  9638.                    );
  9639.                         slrestor();
  9640.                         return(success = 0);
  9641.                     }
  9642.                 }
  9643. #endif /* CK_SSL */
  9644. #ifdef CK_SRP
  9645.                 if (auth_type_user[0] == AUTHTYPE_SRP) {
  9646.                     if (!ck_srp_is_installed()) {
  9647.             printf(
  9648.         "?Required authentication method (SRP) is not installed\n"
  9649.                    );
  9650.                         slrestor();
  9651.                         return(success = 0);
  9652.                     }
  9653.                 }
  9654. #endif /* CK_SRP */
  9655.             }
  9656. #endif /* CK_AUTHENTICATION */
  9657. #ifdef CK_ENCRYPTION
  9658.             if ((ttnproto == NP_TELNET || ttnproto == NP_KERMIT) &&
  9659.                  e_type > -1) {
  9660.                 if (!sl_cx_saved) {
  9661.                     sl_cx_type = cx_type;
  9662.                     sl_cx_saved = 1;
  9663.                 }
  9664.                 if (!sl_topt_e_s_saved) {
  9665.                     sl_topt_e_su = TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION);
  9666.                     sl_topt_e_sm = TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION);
  9667.                     sl_topt_e_s_saved = 1;
  9668.                 }
  9669.                 if (!sl_topt_e_c_saved) {
  9670.                     sl_topt_e_cu = TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION);
  9671.                     sl_topt_e_cm = TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION);
  9672.                     sl_topt_e_c_saved = 1;
  9673.                 }
  9674.                 cx_type = e_type;
  9675.                 if (cx_type == CX_AUTO) {
  9676.                     TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION) = TN_NG_RQ;
  9677.                     TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_RQ;
  9678.                     TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION) = TN_NG_RQ;
  9679.                     TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_RQ;
  9680.                 } else if (cx_type == CX_NONE) {
  9681.                     TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION) = TN_NG_RF;
  9682.                     TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_RF;
  9683.                     TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION) = TN_NG_RF;
  9684.                     TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_RF;
  9685.                 } else {
  9686.                     TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION) = TN_NG_MU;
  9687.                     TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_MU;
  9688.                     TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION) = TN_NG_MU;
  9689.                     TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_MU;
  9690.                 }
  9691.             }
  9692.             if (ttnproto == NP_EK4LOGIN || ttnproto == NP_EK5LOGIN ||
  9693.         (ttnproto == NP_TELNET || ttnproto == NP_KERMIT) &&
  9694.         ((line[0] == '*' &&
  9695.           TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION) == TN_NG_MU &&
  9696.           TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION) == TN_NG_MU) ||
  9697.          (line[0] != '*' &&
  9698.           TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION) == TN_NG_MU &&
  9699.           TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION) == TN_NG_MU))
  9700.         ) {
  9701.                 if (!ck_crypt_is_installed()) {
  9702.             slmsg = "Encryption failure";
  9703.                     printf("?Required Encryption methods are not installed\n");
  9704.                     slrestor();
  9705.                     return(success = 0);
  9706.                 }
  9707.             }
  9708. #endif /* CK_ENCRYPTION */
  9709. #ifdef RLOGCODE
  9710. #ifdef CK_KERBEROS
  9711. #ifdef KRB4
  9712.             if (ttnproto == NP_K4LOGIN || ttnproto == NP_EK4LOGIN) {
  9713.                 extern int krb4_autoget;
  9714.                 char tgt[256];
  9715.                 char * realm;
  9716.  
  9717.                 /* this is fine except for one huge problem         */
  9718.                 /* we don't have the full hostname at this point    */
  9719.                 /* so we really need to perform a DNS lookup before */
  9720.                 /* calling ttopen().                                */
  9721.  
  9722.                 realm = ck_krb4_realmofhost(ckgetfqhostname(hostname));
  9723.                 sprintf(tgt,"krbtgt.%s@%s",realm,realm);
  9724.  
  9725.                 if (!ck_krb4_is_installed()) {
  9726.             printf(
  9727.         "?Required authentication method (Kerberos 4) is not installed\n"
  9728.                );
  9729.                     slrestor();
  9730.                     return(success = 0);
  9731.                 } else {
  9732.                     if ((ck_krb4_tkt_isvalid(tgt) <= 0) &&
  9733.             (!krb4_autoget ||
  9734.              krb4_autoget && !ck_krb4_autoget_TGT(realm))) {
  9735.             printf(
  9736.                "?Kerberos 4: Ticket Getting Ticket not valid.\n");
  9737.             slrestor();
  9738.             return(success = 0);
  9739.                     }
  9740.                 }
  9741.             }
  9742. #endif /* KRB4 */
  9743. #ifdef KRB5
  9744.             if (ttnproto == NP_K5LOGIN || ttnproto == NP_EK5LOGIN) {
  9745.                 extern int krb5_autoget;
  9746.                 char tgt[256];
  9747.                 char * realm;
  9748.  
  9749.                 /* this is fine except for one huge problem         */
  9750.                 /* we don't have the full hostname at this point    */
  9751.                 /* so we really need to perform a DNS lookup before */
  9752.                 /* calling ttopen().                                */
  9753.  
  9754.                 realm = ck_krb5_realmofhost(ckgetfqhostname(hostname));
  9755.                 sprintf(tgt,"krbtgt/%s@%s",realm,realm);
  9756.  
  9757.                 if (!ck_krb5_is_installed()) {
  9758.             printf(
  9759.         "?Required authentication method (Kerberos 5) is not installed\n"
  9760.                );
  9761.                     slrestor();
  9762.                     return(success = 0);
  9763.                 } else if (!((ck_krb5_tkt_isvalid(NULL,tgt) > 0) ||
  9764.                               ck_krb5_is_tgt_valid()) &&
  9765.                (!krb5_autoget ||
  9766.                 krb5_autoget && !ck_krb5_autoget_TGT(realm))) {
  9767.                     printf("?Kerberos 5: Ticket Getting Ticket not valid.\n");
  9768.                     slrestor();
  9769.                     return(success = 0);
  9770.                 }
  9771.             }
  9772. #endif /* KRB5 */
  9773. #endif /* CK_KERBEROS */
  9774. #endif /* RLOGCODE */
  9775.  
  9776. #ifdef NETCONN
  9777. #ifndef NOSPL
  9778.             if (tmpstring) {
  9779.                 if (tmpstring[0]) {
  9780.                     ckstrncpy(pwbuf,tmpstring,PWBUFL+1);
  9781.                     pwflg = 1;
  9782.                     pwcrypt = 0;
  9783.                 } else
  9784.                     pwflg = 0;
  9785.                 makestr(&tmpstring,NULL);
  9786.             }
  9787. #ifdef RLOGCODE
  9788.             if (tmpusrid) if (tmpusrid[0]) {
  9789.                 if (!sl_uid_saved) {
  9790.                     ckstrncpy(sl_uidbuf,uidbuf,UIDBUFLEN);
  9791.                     sl_uid_saved = 1;
  9792.                 }
  9793.         ckstrncpy(uidbuf,tmpusrid,UIDBUFLEN);
  9794.                 makestr(&tmpusrid,NULL);
  9795.                 uidflag = 1;
  9796.             }
  9797. #endif /* RLOGCODE */
  9798. #endif /* NOSPL */
  9799. #endif /* NETCONN */
  9800.  
  9801. #ifdef TNCODE
  9802.             if (!sl_tn_saved) {
  9803.                 sl_tn_wait = tn_wait_flg;
  9804.                 sl_tn_saved = 1;
  9805.             }
  9806.         tn_wait_flg = wait;
  9807. #endif /* TNCODE */
  9808.  
  9809.         /* Try to open */
  9810.         if ((y = ttopen(line, &_local, mdmtyp, 0 )) < 0) {
  9811.                 slrestor();
  9812.         slmsg = "Network connection failure";
  9813. #ifdef VMS
  9814.         if (hints && !cmdsrc() && ttnproto == NP_RLOGIN) {
  9815.             slmsg = "RLOGIN failure";
  9816.             printf("*************************\n");
  9817.             printf("Hint: The RLOGIN port is privileged in VMS.\n");
  9818.             printf("(Use SET HINTS OFF to suppress future hints.)\n");
  9819.             printf("*************************\n");
  9820.         }
  9821. #else  /* Not VMS... */
  9822.         if (errno) {
  9823.             int x;
  9824.             debug(F111,"set host line, errno","",errno);
  9825.             makestr(&tmpslmsg,ck_errstr());
  9826.             slmsg = tmpslmsg;
  9827.             x = strlen(line) + 2;
  9828.             if (LINBUFSIZ - x > 100) {
  9829.             tp = line + x;
  9830. #ifdef OS2
  9831.             printf("Can't connect to %s\n",line);
  9832. #else /* OS2 */
  9833. #ifdef COMMENT
  9834.             sprintf(tp,"Can't connect to %s",line);
  9835.             perror(tp);
  9836. #endif /* COMMENT */
  9837. #ifdef UNIX
  9838.             if (hints && !cmdsrc() && ttnproto == NP_RLOGIN) {
  9839.                 slmsg = "RLOGIN failure";
  9840.                 printf("*************************\n");
  9841.                 printf(
  9842.                  "Hint: The RLOGIN port is privileged in UNIX.\n");
  9843.                 printf(
  9844.                 "(Use SET HINTS OFF to suppress future hints.)\n");
  9845.                 printf("*************************\n");
  9846.             }
  9847. #endif /* UNIX */
  9848. #endif /* OS2 */
  9849.             } else printf("Can't connect to %s\n",line);
  9850.         } else
  9851. #endif /* VMS */
  9852.           printf("Can't open connection to %s\n",line);
  9853.         continue;
  9854.         } else {
  9855.         success = 1;
  9856.         switch (mynet) {
  9857.           case NET_TCPA:
  9858.           case NET_TCPB:
  9859.             cxtype = CXT_TCPIP;
  9860.             break;
  9861.           case NET_SLAT:
  9862.             cxtype = CXT_LAT;
  9863.             break;
  9864.           case NET_SX25:
  9865.           case NET_IX25:
  9866.           case NET_HX25:
  9867.           case NET_VX25:
  9868.             cxtype = CXT_X25;
  9869.             break;
  9870.           case NET_BIOS:
  9871.             cxtype = CXT_NETBIOS;
  9872.             break;
  9873.           case NET_FILE:
  9874.           case NET_PIPE:
  9875.           case NET_CMD:
  9876.           case NET_DLL:
  9877.           case NET_PTY:
  9878.             cxtype = CXT_PIPE;
  9879.             break;
  9880.           default:
  9881.             cxtype = CXT_PIPE;
  9882.             break;
  9883.         }
  9884.         break;
  9885.         }
  9886.     } /* for-loop */
  9887.     s = line;
  9888.     } /* network connection */
  9889. #endif /* NETCONN */
  9890. /*
  9891.   NOTE:
  9892.   The following will fail if Kermit is running as a daemon with no
  9893.   controlling tty.  Needs research.
  9894. */
  9895.     if (!success) {
  9896.     local = dfloc;            /* Go back to normal */
  9897. #ifndef MAC
  9898.     strcpy(ttname,dftty);        /* Restore default tty name */
  9899. #endif /* MAC */
  9900.     speed = ttgspd();
  9901.     network = 0;            /* No network connection active */
  9902.     haveline = 0;
  9903.     if (mdmtyp < 0) {        /* Switching from net to async? */
  9904.         if (mdmsav > -1)        /* Restore modem type from last */
  9905.           mdmtyp = mdmsav;        /* SET MODEM command, if any. */
  9906.         else
  9907.           mdmtyp = 0;
  9908.         mdmsav = -1;
  9909.     }
  9910.     return(0);            /* Return failure */
  9911.     }
  9912.     if (_local > -1) local = _local;    /* Opened ok, set local/remote. */
  9913.     slmsg = NULL;
  9914.     network = (mdmtyp < 0);        /* Remember connection type. */
  9915.     strcpy(ttname,s);            /* Copy name into real place. */
  9916.     debug(F110,"setlin ok",ttname,0);
  9917.     debug(F101,"setlin network","",network);
  9918.     if (!network)
  9919.       speed = ttgspd();            /* Get the current speed. */
  9920.     debug(F101,"setlin local","",local);
  9921. #ifdef NETCONN
  9922.     if (network) {
  9923.     debug(F101,"setlin mynet","",mynet);
  9924. #ifndef NOXFER
  9925.     /* Force prefixing of 255 on TCP/IP connections... */
  9926.     if (mynet == NET_TCPB) {
  9927.         debug(F101,"setlin reliable A","",reliable);
  9928. #ifdef CK_SPEED
  9929.         ctlp[(unsigned)255] = 1;
  9930. #endif /* CK_SPEED */
  9931.         if (reliable != SET_OFF || !setreliable)
  9932.           reliable = SET_ON;    /* Transport is reliable end to end */
  9933.         debug(F101,"setlin reliable B","",reliable);
  9934.     } else if (mynet == NET_SX25 ||
  9935.            mynet == NET_VX25 ||
  9936.            mynet == NET_IX25 ||
  9937.            mynet == NET_HX25) {
  9938.         duplex = 1;            /* Local echo for X.25 */
  9939.         if (reliable != SET_OFF || !setreliable)
  9940.           reliable = SET_ON;    /* Transport is reliable end to end */
  9941.     }
  9942. #endif /* NOXFER */
  9943.     }
  9944. #endif /* NETCONN */
  9945. #ifndef NOXFER
  9946.     debug(F101,"setlin reliable","",reliable);
  9947. #endif /* NOXFER */
  9948. #ifdef OS2
  9949.     if (mdmtyp <= 0)            /* Network or Direct Connection */
  9950.       DialerSend(OPT_KERMIT_CONNECT, 0);
  9951. #endif /* OS2 */
  9952.  
  9953.     setflow();                /* Set appropriate flow control */
  9954.  
  9955.     haveline = 1;
  9956. #ifdef CKLOGDIAL
  9957. #ifdef NETCONN
  9958.     if (network)            /* Start connection log record */
  9959.       dolognet();
  9960.     else
  9961. #endif /* NETCONN */
  9962.       dologline();
  9963. #endif /* CKLOGDIAL */
  9964.  
  9965. #ifndef NOSPL
  9966.     if (local) {
  9967.     if (nmac) {            /* Any macros defined? */
  9968.         int k;            /* Yes */
  9969.         k = mlook(mactab,"on_open",nmac);    /* Look this up */
  9970.         if (k >= 0) {            /* If found, */
  9971.         if (dodo(k,ttname,0) > -1)    /* set it up, */
  9972.           parser(1);            /* and execute it */
  9973.         }
  9974.     }
  9975.     }
  9976. #endif /* NOSPL */
  9977.  
  9978.     if (local && (cx || sx)) {        /* /CONNECT or /SERVER switch given */
  9979.     extern int carrier;
  9980.     if (xx == XYLINE && carrier != CAR_OFF) { /* on serial connection... */
  9981.         /* Open() turns on DTR -- wait up to a second for CD to come up */
  9982.         int i, x;
  9983.         for (i = 0; i < 10; i++) {    /* WAIT 1 CD... */
  9984.         x = ttgmdm();
  9985.         if (x < 0 || x & BM_DCD)
  9986.           break;
  9987.         msleep(100);
  9988.         }
  9989.     }
  9990.     if (cx) {            /* /CONNECT */
  9991.         success = doconect(0);
  9992. #ifdef CKLOGDIAL
  9993.         if (ttchk() < 0)
  9994.           dologend();
  9995. #endif /* CKLOGDIAL */
  9996.         return(success);
  9997. #ifndef NOXFER
  9998.     } else if (sx) {        /* /SERVER */
  9999.         sstate = 'x';
  10000. #ifdef MAC
  10001.         what = W_RECV;
  10002.         scrcreate();
  10003. #endif /* MAC */
  10004.         if (local) displa = 1;
  10005. #ifdef AMIGA
  10006.         reqoff();            /* No DOS requestors while server */
  10007. #endif /* AMIGA */
  10008. #endif /* NOXFER */
  10009.     }
  10010.     }
  10011.     return(success = 1);
  10012. }
  10013. #endif /* NOLOCAL */
  10014.  
  10015. #ifdef CKCHANNELIO
  10016. /*
  10017.   C-Library based file-i/o package for scripts.  This should be portable to
  10018.   all C-Kermit versions since it uses the same APIs we have always used for
  10019.   processing command files.  The entire channel i/o package is contained
  10020.   herein, apart from some keyword table entries in the main keyword table
  10021.   and the help text in the HELP command module.
  10022.  
  10023.   On platforms like VMS and VOS, this package handles only UNIX-style
  10024.   stream files.  If desired, it can be replaced for those platforms by
  10025.   <#>ifdef'ing out this code and adding the equivalent replacement routines
  10026.   to the ck?fio.c module, e.g. for RMS-based file i/o in ckvfio.c.
  10027. */
  10028.  
  10029. /* Define NOSTAT if the <#>include causes trouble. */
  10030.  
  10031. #ifndef NOSTAT
  10032. #ifdef VMS
  10033. #ifdef VAXC                /* As it does in VAX C */
  10034. #define NOSTAT
  10035. #endif /* VAXC */
  10036. #endif /* VMS */
  10037. #endif /* NOSTAT */
  10038.  
  10039. #ifndef NOSTAT
  10040. #include <sys/stat.h>
  10041. #endif /* NOSTAT */
  10042.  
  10043. #ifdef NLCHAR
  10044. static int z_lt = 1;            /* Length of line terminator */
  10045. #else
  10046. static int z_lt = 2;
  10047. #endif /* NLCHAR */
  10048.  
  10049. struct ckz_file {            /* C-Kermit file struct */
  10050.     FILE * z_fp;            /* Includes the C-Lib file struct */
  10051.     unsigned int z_flags;        /* Plus C-Kermit mode flags, */
  10052.     long z_nline;            /* current line number if known, */
  10053.     char z_name[CKMAXPATH+2];        /* and the file's name. */
  10054. };
  10055. static struct ckz_file * z_file = NULL;    /* Array of C-Kermit file structs */
  10056. static int z_inited = 0;        /* Flag for array initialized */
  10057. int z_maxchan = Z_MAXCHAN;        /* Max number of C-Kermit channels */
  10058. int z_openmax = CKMAXOPEN;        /* Max number of open files overall */
  10059. int z_nopen = 0;            /* How many channels presently open */
  10060. int z_error = 0;            /* Most recent error */
  10061. int z_filcount = -1;            /* Most recent FILE COUNT result */
  10062.  
  10063. #define RD_LINE 0            /* FILE READ options */
  10064. #define RD_CHAR 1
  10065. #define RD_SIZE 2
  10066.  
  10067. #define WR_LINE RD_LINE            /* FILE WRITE options */
  10068. #define WR_CHAR RD_CHAR
  10069. #define WR_SIZE RD_SIZE
  10070. #define WR_STRI 3
  10071. #define WR_LPAD 4
  10072. #define WR_RPAD 5
  10073.  
  10074. #ifdef UNIX
  10075. extern int ckmaxfiles;            /* Filled in by sysinit(). */
  10076. #endif /* UNIX */
  10077.  
  10078. /* See ckcker.h for error numbers */
  10079. /* See ckcdeb.h for Z_MAXCHAN and CKMAXOPEN definitions */
  10080. /* NOTE: For VMS we might be able to fill in ckmaxfiles */
  10081. /* from FILLM and CHANNELCNT -- find out about these... */
  10082.  
  10083. static char * fopnargs[] = {        /* Mode combinations for fopen() */
  10084. #ifdef COMMENT
  10085.     /* All combinations of rwa */
  10086.     "",  "r",  "w",  "rw",  "a",  "ra",  "wa",  "rwa", /* Text mode */
  10087.     "b", "rb", "wb", "rwb", "ab", "rab", "wab", "rwab" /* Binary mode */
  10088. #else
  10089.     /* Combinations and syntax permitted by C libraries... */
  10090.     "",  "r",  "w",  "r+",  "a",  "",   "a",  "", /* Text mode */
  10091. #ifdef OS2
  10092.     "",  "rb", "wb", "r+b", "ab", "",   "ab", "" /* Binary modes for K95 */
  10093. #else
  10094. #ifdef VMS
  10095.     "",  "rb", "wb", "r+b", "ab", "",   "ab", "" /* Binary modes for VMS */
  10096. #else
  10097.     "",  "r",   "w", "r+",  "a",  "",   "a",  "" /* Binary modes for UNIX */
  10098. #endif /* VMS */
  10099. #endif /* OS2 */
  10100. #endif /* COMMENT */
  10101. };
  10102. static int nfopnargs = sizeof(fopnargs) / sizeof(char *);
  10103.  
  10104. char *                    /* Error messages */
  10105. ckferror(n) int n; {
  10106.     switch (n) {
  10107.       case FX_NER: return("No error");
  10108.       case FX_SYS: return(ck_errstr());
  10109.       case FX_EOF: return("End of file");
  10110.       case FX_NOP: return("File not open");
  10111.       case FX_CHN: return("Channel out of range");
  10112.       case FX_RNG: return("Parameter out of range");
  10113.       case FX_NMF: return("Too many files open");
  10114.       case FX_FOP: return("Operation conflicts with OPEN mode");
  10115.       case FX_NYI: return("OPEN mode not supported");
  10116.       case FX_BOM: return("Illegal combination of OPEN modes");
  10117.       case FX_ACC: return("Access denied");
  10118.       case FX_FNF: return("File not found");
  10119.       case FX_OFL: return("Buffer overflow");
  10120.       case FX_LNU: return("Current line number unknown");
  10121.       case FX_UNK: return("Operation fails - reason unknown");
  10122.       default: return("Error number out of range");
  10123.     }
  10124. }
  10125.  
  10126. /*
  10127.   Z _ O P E N --  Open a file for the requested type of access.
  10128.  
  10129.   Call with:
  10130.     name:  Name of file to be opened.
  10131.     flags: Any combination of FM_xxx values except FM_EOF (ckcker.h).
  10132.   Returns:
  10133.     >= 0 on success: The assigned channel number
  10134.     <  0 on failure: A negative FX_xxx error code (ckcker.h).
  10135. */
  10136. int
  10137. z_open(name, flags) char * name; int flags; {
  10138.     int i, n;
  10139.     FILE * t;
  10140.     char * mode;
  10141.     debug(F111,"z_open",name,flags);
  10142.     if (!name) name = "";        /* Check name argument */
  10143.     if (!name[0])
  10144.       return(z_error = FX_BFN);
  10145.     if (flags & FM_CMD)            /* Opening pipes not implemented yet */
  10146.       return(z_error = FX_NYI);        /* (and not portable either) */
  10147.     debug(F101,"z_open nfopnargs","",nfopnargs);
  10148.     if (flags < 0 || flags >= nfopnargs) /* Range check flags */
  10149.       return(z_error = FX_RNG);
  10150.     mode = fopnargs[flags];        /* Get fopen() arg */
  10151.     debug(F111,"z_open fopen args",mode,flags);
  10152.     if (!mode[0])            /* Check for illegal combinations */
  10153.       return(z_error = FX_BOM);
  10154.     if (!z_inited) {            /* If file structs not inited */
  10155.     debug(F101,"z_open z_maxchan 1","",z_maxchan);
  10156. #ifdef UNIX
  10157.     debug(F101,"z_open ckmaxfiles","",ckmaxfiles);
  10158.     if (ckmaxfiles > 0) {        /* Set in ck?tio.c: sysinit() */
  10159.         int x;
  10160.         x = ckmaxfiles - ZNFILS - 5;
  10161.         if (x > z_maxchan)        /* sysconf() value greater than */
  10162.           z_maxchan = x;        /* value from header files. */
  10163.         debug(F101,"z_open z_maxchan 2","",z_maxchan);
  10164.     }
  10165. #endif /* UNIX */
  10166.     if (z_maxchan < Z_MINCHAN)    /* Allocate at least this many. */
  10167.       z_maxchan = Z_MINCHAN;
  10168.     debug(F101,"z_open z_maxchan 3","",z_maxchan);
  10169.     /* Note: This could be a pretty big chunk of memory */
  10170.     /* if z_maxchan is a big number.  If this becomes a problem */
  10171.     /* we'll need to malloc and free each element at open/close time */
  10172.     if (!(z_file = (struct ckz_file *)
  10173.           malloc(sizeof(struct ckz_file) * (z_maxchan + 1))))
  10174.       return(z_error = FX_NMF);
  10175.     for (i = 0; i < z_maxchan; i++) {
  10176.         z_file[i].z_fp = NULL;
  10177.         z_file[i].z_flags = 0;
  10178.         z_file[i].z_nline = 0;
  10179.         *(z_file[i].z_name) = '\0';
  10180.     }
  10181.     z_inited = 1;            /* Remember we did */
  10182.     }
  10183.     for (n = -1, i = 0; i < z_maxchan; i++) {
  10184.     if (!z_file[i].z_fp) {
  10185.         n = i;
  10186.         break;
  10187.     }
  10188.     }
  10189.     if (n < 0 || n >= z_maxchan)    /* Any free channels? */
  10190.       return(z_error = FX_NMF);        /* No, fail. */
  10191.     errno = 0;
  10192.  
  10193.     z_file[n].z_flags = 0;        /* In case of failure... */
  10194.  
  10195.     t = fopen(name, mode);        /* Try to open the file. */
  10196.     if (!t) {                /* Failed... */
  10197.     debug(F111,"z_open error",name,errno);
  10198. #ifdef EMFILE
  10199.     if (errno == EMFILE)
  10200.       return(z_error = FX_NMF);
  10201. #endif /* EMFILE */
  10202.     return(z_error = (errno ?  FX_SYS : FX_UNK)); /* Return error code */
  10203.     }
  10204. #ifdef NT
  10205. #ifdef O_SEQUENTIAL
  10206.     if (t)                /* Caching hint for NT */
  10207.       _setmode(_fileno(t),O_SEQUENTIAL);
  10208. #endif /* O_SEQUENTIAL */
  10209. #endif /* NT */
  10210.     z_nopen++;                /* Open, count it. */
  10211.     z_file[n].z_fp = t;            /* Stash the file pointer */
  10212.     z_file[n].z_flags = flags;        /* and the flags */
  10213.     z_error = 0;
  10214.     zfnqfp(name,CKMAXPATH,z_file[n].z_name); /* and the file's full name */
  10215.     return(n);                /* Return the channel number */
  10216. }
  10217.  
  10218. int
  10219. z_close(channel) int channel; {        /* Close file on given channel */
  10220.     int x;
  10221.     FILE * t;
  10222.     if (!z_inited)            /* Called before any files are open? */
  10223.       return(z_error = FX_NOP);
  10224.     if (channel >= z_maxchan)        /* Channel out of range? */
  10225.       return(z_error = FX_CHN);
  10226.     if (!(t = z_file[channel].z_fp))    /* Channel wasn't open? */
  10227.       return(z_error = FX_NOP);
  10228.     errno = 0;                /* Set errno 0 to get a good reading */
  10229.     x = fclose(t);            /* Try to close */
  10230.     if (x == EOF)            /* On failure */
  10231.       return(z_error = FX_SYS);        /* indicate system error. */
  10232.     z_nopen--;                /* Closed OK, decrement open count */
  10233.     z_file[channel].z_fp = NULL;    /* Set file pointer to NULL */
  10234.     z_file[channel].z_nline = 0;    /* Current line number is 0 */
  10235.     z_file[channel].z_flags = 0;    /* Set flags to 0 */
  10236.     *(z_file[channel].z_name) = '\0';    /* Clear name */
  10237.     return(z_error = 0);
  10238. }
  10239.  
  10240. /*
  10241.   Z _ O U T  --  Output string to channel.
  10242.  
  10243.   Call with:
  10244.     channel:     Channel number to write to.
  10245.     s:           String to write.
  10246.     length > -1: How many characters of s to write.
  10247.     length < 0:  Write entire NUL-terminated string.
  10248.     flags == 0:  Supply line termination.
  10249.     flags >  0:  Don't supply line termination.
  10250.     flags <  0:  Write 'length' NUL characters.
  10251.   Special case:
  10252.     If flags > -1 and s is empty or NULL and length == 1, write 1 NUL.
  10253.   Returns:
  10254.     Number of characters written to channel on success, or
  10255.     negative FX_xxx error code on failure.
  10256. */
  10257. int
  10258. z_out(channel,s,length,flags) int channel, flags, length; char * s; {
  10259.     FILE * t;
  10260.     int x, n;
  10261.     char c = '\0';
  10262.  
  10263.     if (!s) s = "";            /* Guard against null pointer */
  10264. #ifdef DEBUG
  10265.     if (deblog) {
  10266.     debug(F111,"z_out",s,channel);
  10267.     debug(F101,"z_out length","",length);
  10268.     debug(F101,"z_out flags","",flags);
  10269.     }
  10270. #endif /* DEBUG */
  10271.     if (!z_inited)            /* File i/o inited? */
  10272.       return(z_error = FX_NOP);
  10273.     if (channel >= z_maxchan)        /* Channel in range? */
  10274.       return(z_error = FX_CHN);
  10275.     if (!(t = z_file[channel].z_fp))    /* File open? */
  10276.       return(z_error = FX_NOP);
  10277.     if (!((z_file[channel].z_flags) & (FM_WRI|FM_APP)))    /* In write mode? */
  10278.       return(z_error = FX_FOP);
  10279.     n = length;                /* Length of string to write */
  10280.     if (n < 0) {            /* Negative means get it ourselves */
  10281.     if (flags < 0)            /* Except when told to write NULs in */
  10282.       return(z_error = FX_RNG);    /* which case args are inconsistent */
  10283.     n = strlen(s);            /* Get length of string arg */
  10284.     }
  10285.     errno = 0;                /* Reset errno */
  10286.     debug(F101,"z_out n","",n);
  10287.     if (flags < 0) {            /* Writing NULs... */
  10288.     int i;
  10289.     for (i = 0; i < n; i++) {
  10290.         x = fwrite(&c,1,1,t);
  10291.         if (x < 1)
  10292.           return(z_error = (errno ? FX_SYS : FX_UNK));
  10293.     }
  10294.     z_file[channel].z_nline = -1;    /* Current line no longer known */
  10295.     z_error = 0;
  10296.     return(i);
  10297.     } else {                /* Writing string arg */
  10298.     if (n == 1 && !s[0])        /* Writing one char but it's NUL */
  10299.       x = fwrite(&c,1,1,t);
  10300.     else                /* Writing non-NUL char or string */
  10301.       x = fwrite(s,1,n,t);
  10302.     debug(F101,"z_out fwrite",ckitoa(x),errno);
  10303.     if (x < n)            /* Failure to write requested amount */
  10304.       return(z_error = (errno ? FX_SYS : FX_UNK)); /* Return error */
  10305.     if (flags == 0) {        /* If supplying line termination */
  10306.         if (fwrite("\n",1,1,t))    /* do that  */
  10307.           x += z_lt;        /* count the terminator */
  10308.         if (z_file[channel].z_nline > -1) /* count this line */
  10309.           z_file[channel].z_nline++;
  10310.     } else {
  10311.         z_file[channel].z_nline = -1; /* Current line no longer known */
  10312.     }
  10313.     }
  10314.     z_error = 0;
  10315.     return(x);
  10316. }
  10317.  
  10318. #define Z_INBUFLEN 64
  10319.  
  10320. /*
  10321.   Z _ I N  --  Multichannel i/o file input function.
  10322.  
  10323.   Call with:
  10324.     channel number to read from.
  10325.     s = address of destination buffer.
  10326.     buflen = destination buffer length.
  10327.     length = Number of bytes to read, must be < buflen.
  10328.     flags: 0 = read a line; nonzero = read the given number of bytes.
  10329.   Returns:
  10330.     Number of bytes read into buffer or a negative error code.
  10331.     A terminating NUL is deposited after the last byte that was read.
  10332. */
  10333. int
  10334. z_in(channel,s,buflen,length,flags)
  10335.  int channel, buflen, length, flags; char * s;
  10336. /* z_in */ {
  10337.     int i, j, x;
  10338.     FILE * t;
  10339.     char * p;
  10340.  
  10341.     if (!z_inited)            /* Check everything... */
  10342.       return(z_error = FX_NOP);
  10343.     if (channel >= z_maxchan)
  10344.       return(z_error = FX_CHN);
  10345.     if (!(t = z_file[channel].z_fp))
  10346.       return(z_error = FX_NOP);
  10347.     if (!((z_file[channel].z_flags) & FM_REA))
  10348.       return(z_error = FX_FOP);
  10349.     if (!s)                /* Check destination */
  10350.      return(z_error = FX_RNG);
  10351.     s[0] = NUL;
  10352.     if (length == 0)            /* Read 0 bytes - easy. */
  10353.       return(z_error = 0);
  10354.     debug(F101,"z_in channel","",channel);
  10355.     debug(F101,"z_in buflen","",buflen);
  10356.     debug(F101,"z_in length","",length);
  10357.     debug(F101,"z_in flags","",flags);
  10358.     if (length < 0 || buflen < 0)    /* Check length args */
  10359.       return(z_error = FX_RNG);
  10360.     if (buflen <= length)
  10361.       return(z_error = FX_RNG);
  10362.     errno = 0;                /* Reset errno */
  10363.     if (flags) {            /* Read block or byte */
  10364.     i = fread(s,1,length,t);
  10365. #ifdef DEBUG
  10366.     if (deblog) {
  10367.         debug(F111,"z_in block",s,i);
  10368.         debug(F101,"z_in block errno","",errno);
  10369.         debug(F101,"z_in block ferror","",ferror(t));
  10370.         debug(F101,"z_in block feof","",feof(t));
  10371.     }
  10372. #endif /* DEBUG */
  10373.     z_file[channel].z_nline = -1;    /* Current line no longer known */
  10374.     } else {                /* Read line */
  10375. #ifndef COMMENT
  10376.     /* This method is used because it's simpler than the others */
  10377.         /* and also marginally faster. */
  10378.     for (i = 0; i < length; i++) {
  10379.         if ((x = getc(t)) == EOF)
  10380.           break;
  10381.         s[i] = x;
  10382.         if (s[i] == '\n') {
  10383.         s[i] = '\0';
  10384.         break;
  10385.         }
  10386.     }
  10387.     debug(F111,"z_in line byte loop",ckitoa(errno),i);
  10388.     if (z_file[channel].z_nline > -1)
  10389.       z_file[channel].z_nline++;
  10390. #else
  10391. #ifdef COMMENT2
  10392.     /* Straightforward but strlen() slows it down. */
  10393.     s[0] = '\0';
  10394.     i = 0;
  10395.     if (fgets(s,length,t)) {
  10396.         i = strlen(s);
  10397.         if (i > 0 && s[i-1] == '\n') i--;
  10398.     }
  10399.     debug(F111,"z_in line fgets",ckitoa(errno),i);
  10400.     if (z_file[channel].z_nline > -1)
  10401.       z_file[channel].z_nline++;
  10402. #else
  10403.     /* This is a do-it-yourself fgets() with its own readahead and */
  10404.     /* putback.  It's a bit faster than real fgets() but not enough */
  10405.     /* to justify the added complexity or the risk of the ftell() and */
  10406.     /* fseek() calls failing. */
  10407.     int k, flag = 0;
  10408.     long pos;
  10409.     for (i = 0; !flag && i <= (length - Z_INBUFLEN); i += Z_INBUFLEN) {
  10410.         k = ((length - i) < Z_INBUFLEN) ? length - i : Z_INBUFLEN;
  10411.         if ((x = fread(s+i,1,k,t)) < 1)
  10412.           break;
  10413.         s[i+x] = '\0';
  10414.         for (j = 0; j < x; j++) {
  10415.         if (s[i+j] == '\n') {
  10416.             s[i+j] = '\0';
  10417.             flag ++;
  10418.             pos = ftell(t);
  10419.             if (pos > -1) {
  10420.             pos -= (x - j - 1);
  10421.             x = fseek(t, pos, 0);
  10422.             i += j;
  10423.             break;
  10424.             } else
  10425.               return(z_error = FX_SYS);
  10426.         }
  10427.         }
  10428.     }
  10429.     if (z_file[channel].z_nline > -1)
  10430.       z_file[channel].z_nline++;
  10431.     debug(F111,"z_in line chunk loop",ckitoa(errno),i);
  10432. #endif /* COMMENT2 */
  10433. #endif /* COMMENT */
  10434.     }
  10435.     debug(F111,"z_in i",ckitoa(errno),i);
  10436.     if (i < 0) i = 0;            /* NUL-terminate result */
  10437.     s[i] = '\0';
  10438.     if (i > 0) {
  10439.     z_error = 0;
  10440.     return(i);
  10441.     }
  10442.     if (i == 0 && feof(t))        /* EOF on reading? */
  10443.       return(z_error = FX_EOF);        /* Return EOF code */
  10444.     return(errno ? (z_error = -1) : i);    /* Return length or system error */
  10445. }
  10446.  
  10447. int
  10448. z_flush(channel) int channel; {        /* Flush output channel */
  10449.     FILE * t;
  10450.     int x;
  10451.     if (!z_inited)            /* Regular checks */
  10452.       return(z_error = FX_NOP);
  10453.     if (channel >= z_maxchan)
  10454.       return(z_error = FX_CHN);
  10455.     if (!(t = z_file[channel].z_fp))
  10456.       return(z_error = FX_NOP);
  10457.     if (!((z_file[channel].z_flags) & (FM_WRI|FM_APP)))    /* Write access? */
  10458.       return(z_error = FX_FOP);
  10459.     errno = 0;                /* Reset errno */
  10460.     x = fflush(t);            /* Try to flush */
  10461.     return(x ? (z_error = FX_SYS) : 0);    /* Return system error or 0 if OK */
  10462. }
  10463.  
  10464. int
  10465. #ifdef CK_ANSIC
  10466. z_seek(int channel, long pos)        /* Move file pointer to byte */
  10467. #else
  10468. z_seek(channel,pos) int channel; long pos; /* (seek to given position) */
  10469. #endif /* CK_ANSIC */
  10470. {
  10471.     int i, x = 0, rc;
  10472.     FILE * t;
  10473.     if (!z_inited)            /* Check... */
  10474.       return(z_error = FX_NOP);
  10475.     if (channel >= z_maxchan)
  10476.       return(z_error = FX_CHN);
  10477.     if (!(t = z_file[channel].z_fp))
  10478.       return(z_error = FX_NOP);
  10479.     if (pos < 0L) {
  10480.     x = 2;
  10481.     pos = (pos == -2) ? -1L : 0L;
  10482.     }
  10483.     errno = 0;
  10484.     rc = fseek(t,pos,x);        /* Try to seek */
  10485.     debug(F111,"z_seek",ckitoa(errno),rc);
  10486.     if (rc < 0)                /* OK? */
  10487.       return(z_error = FX_SYS);    /* No. */
  10488.     z_file[channel].z_nline = ((pos || x) ? -1 : 0);
  10489.     return(z_error = 0);
  10490. }
  10491.  
  10492. int
  10493. #ifdef CK_ANSIC
  10494. z_line(int channel, long pos)        /* Move file pointer to line */
  10495. #else
  10496. z_line(channel,pos) int channel; long pos; /* (seek to given position) */
  10497. #endif /* CK_ANSIC */
  10498. {
  10499.     int i, len, x = 0;
  10500.     long current = 0L, prev = -1L, old = -1L;
  10501.     FILE * t;
  10502.     char tmpbuf[256];
  10503.     if (!z_inited)            /* Check... */
  10504.       return(z_error = FX_NOP);
  10505.     if (channel >= z_maxchan)
  10506.       return(z_error = FX_CHN);
  10507.     if (!(t = z_file[channel].z_fp))
  10508.       return(z_error = FX_NOP);
  10509.     debug(F101,"z_line pos","",pos);
  10510.     if (pos < 0L) {            /* EOF wanted */
  10511.         long n;
  10512.     n = z_file[channel].z_nline;
  10513.     if (n < 0) {
  10514.         rewind(t);
  10515.         n = 0;
  10516.     }
  10517.     while (1) {            /* This could take a while... */
  10518.         if ((x = getc(t)) == EOF)
  10519.           break;
  10520.         if (x == '\n') {
  10521.         n++;
  10522.         if (pos == -2) {
  10523.             old = prev;
  10524.             prev = ftell(t);
  10525.         }
  10526.         }
  10527.     }
  10528.     if (pos == -2) {
  10529.         if ((x = z_seek(channel,old)) < 0)
  10530.           return(z_error = x);
  10531.         else
  10532.           n--;
  10533.     }
  10534.     z_file[channel].z_nline = n;
  10535.     return(z_error = 0);
  10536.     }
  10537.     if (pos == 0L) {            /* Rewind wanted */
  10538.     z_file[channel].z_nline = 0L;
  10539.     rewind(t);
  10540.     debug(F100,"z_line rewind","",0);
  10541.     return(0L);
  10542.     }
  10543.     tmpbuf[255] = NUL;            /* Make sure buf is NUL terminated */
  10544.     current = z_file[channel].z_nline;    /* Current line */
  10545.     /*
  10546.       If necessary the following could be optimized, e.g. for positioning
  10547.       to a previous line in a large file without starting over.
  10548.     */
  10549.     if (current < 0 || pos < current) {    /* Not known or behind us... */
  10550.     debug(F101,"z_line rewinding","",pos);
  10551.     if ((x = z_seek(channel, 0L)) < 0) /* Rewind */
  10552.       return(z_error = x);
  10553.     if (pos == 0)            /* If 0th line wanted we're done */
  10554.       return(z_error = 0);
  10555.     current = 0;
  10556.     }
  10557.     while (current < pos) {        /* Search for specified line */
  10558.     if (fgets(tmpbuf,255,t)) {
  10559.         len = strlen(tmpbuf);
  10560.         if (len > 0 && tmpbuf[len-1] == '\n') {
  10561.         current++;
  10562.         debug(F111,"z_line read",ckitoa(len),current);
  10563.         } else if (len == 0) {
  10564.         return(z_error = FX_UNK);
  10565.         }
  10566.     } else {
  10567.         z_file[channel].z_nline = -1L;
  10568.         debug(F101,"z_line premature EOF","",current);
  10569.         return(z_error = FX_EOF);
  10570.     }
  10571.     }
  10572.     z_file[channel].z_nline = current;
  10573.     debug(F101,"z_line result","",current);
  10574.     z_error = 0;
  10575.     return(current);
  10576. }
  10577.  
  10578. char *
  10579. z_getname(channel) int channel; {    /* Return name of file on channel */
  10580.     FILE * t;
  10581.     if (!z_inited) {
  10582.     z_error = FX_NOP;
  10583.     return(NULL);
  10584.     }
  10585.     if (channel >= z_maxchan) {
  10586.     z_error = FX_CHN;
  10587.     return(NULL);
  10588.     }
  10589.     if (!(t = z_file[channel].z_fp)) {
  10590.     z_error = FX_NOP;
  10591.     return(NULL);
  10592.     }
  10593.     return((char *)(z_file[channel].z_name));
  10594. }
  10595.  
  10596. int
  10597. z_getmode(channel) int channel; {    /* Return OPEN modes of channel */
  10598.     FILE * t;                /* 0 if file not open */
  10599. #ifndef NOSTAT
  10600.     struct stat statbuf;
  10601. #endif /* NOSTAT */
  10602.     int x;
  10603.     if (!z_inited)
  10604.       return(0);
  10605.     if (channel >= z_maxchan)
  10606.       return(z_error = FX_CHN);
  10607.     if (!(t = z_file[channel].z_fp))
  10608.       return(0);
  10609.     x = z_file[channel].z_flags;
  10610.     if (feof(t)) {            /* This might not work for */
  10611.     x |= FM_EOF;            /* output files */
  10612. #ifndef NOSTAT
  10613.     /* But this does if we can use it. */
  10614.     } else if (stat(z_file[channel].z_name,&statbuf) > -1) {
  10615.     if (ftell(t) == statbuf.st_size)
  10616.       x |= FM_EOF;
  10617. #endif /* NOSTAT */
  10618.     }
  10619.     return(x);
  10620. }
  10621.  
  10622. long
  10623. z_getpos(channel) int channel; {    /* Get file pointer position */
  10624.     FILE * t;                /* on this channel */
  10625.     long x;
  10626.     if (!z_inited)
  10627.       return(z_error = FX_NOP);
  10628.     if (channel >= z_maxchan)
  10629.       return(z_error = FX_CHN);
  10630.     if (!(t = z_file[channel].z_fp))
  10631.       return(z_error = FX_NOP);
  10632.     x = ftell(t);
  10633.     return((x < 0L) ? (z_error = FX_SYS) : x);
  10634. }
  10635.  
  10636. long
  10637. z_getline(channel) int channel; {    /* Get current line number */
  10638.     FILE * t;                /* in file on this channel */
  10639.     long rc;
  10640.     if (!z_inited)
  10641.       return(z_error = FX_NOP);
  10642.     if (channel >= z_maxchan)
  10643.       return(z_error = FX_CHN);
  10644.     if (!(t = z_file[channel].z_fp))
  10645.       return(z_error = FX_NOP);
  10646.     debug(F101,"z_getline","",z_file[channel].z_nline);
  10647.     rc = z_file[channel].z_nline;
  10648.     return((rc < 0) ? (z_error = FX_LNU) : rc);
  10649. }
  10650.  
  10651. int
  10652. z_getfnum(channel) int channel; {    /* Get file number / handle */
  10653.     FILE * t;                /* for file on this channel */
  10654.     if (!z_inited)
  10655.       return(z_error = FX_NOP);
  10656.     if (channel >= z_maxchan)
  10657.       return(z_error = FX_CHN);
  10658.     if (!(t = z_file[channel].z_fp))
  10659.       return(z_error = FX_NOP);
  10660.     z_error = 0;
  10661.     return(fileno(t));
  10662. }
  10663.  
  10664. /*
  10665.   Line-oriented counts and seeks are as dumb as they can be at the moment.
  10666.   Later we can speed them up by building little indexes.
  10667. */
  10668. long
  10669. z_count(channel, what) int channel, what; { /* Count bytes or lines in file */
  10670.     FILE * t;
  10671.     int i, x;
  10672.     long pos, count = 0L;
  10673.     if (!z_inited)            /* Check stuff... */
  10674.       return(z_error = FX_NOP);
  10675.     if (channel >= z_maxchan)
  10676.       return(z_error = FX_CHN);
  10677.     if (!(t = z_file[channel].z_fp))
  10678.       return(z_error = FX_NOP);
  10679.     pos = ftell(t);            /* Save current file pointer */
  10680.     errno = 0;
  10681.     z_error = 0;
  10682.     if (what == RD_CHAR) {        /* Size in bytes requested */
  10683.     if (!fseek(t,0L,2)) {        /* Seek to end */
  10684.         count = ftell(t);        /* Get file pointer */
  10685.         fseek(t,pos,0);        /* Restore file file pointer */
  10686.         return(count);
  10687.     } else                /* Fallback in case seek fails */
  10688.       return(zgetfs(z_file[channel].z_name));
  10689.     }
  10690.     rewind(t);                /* Line count requested - rewind. */
  10691.     while (1) {                /* Count lines. */
  10692.     if ((x = getc(t)) == EOF)    /* Stupid byte loop */
  10693.       break;            /* but it works as well as anything */
  10694.     if (x == '\n')            /* else... */
  10695.       count++;
  10696.     }
  10697.     x = fseek(t,pos,0);            /* Restore file pointer */
  10698.     return(count);
  10699. }
  10700.  
  10701. /* User interface for generalized channel-oriented file i/o */
  10702.  
  10703. struct keytab fctab[] = {        /* FILE subcommands */
  10704.     "close",      FIL_CLS, 0,
  10705.     "count",      FIL_COU, 0,
  10706.     "flush",      FIL_FLU, 0,
  10707.     "list",       FIL_LIS, 0,
  10708.     "open",       FIL_OPN, 0,
  10709.     "read",       FIL_REA, 0,
  10710.     "rewind",     FIL_REW, 0,
  10711.     "seek",       FIL_SEE, 0,
  10712.     "status",     FIL_STA, 0,
  10713.     "write",      FIL_WRI, 0
  10714. };
  10715. int nfctab = (sizeof (fctab) / sizeof (struct keytab));
  10716.  
  10717. static struct keytab fcswtab[] = {    /* OPEN modes */
  10718.     "/append",    FM_APP,  0,
  10719.     "/binary",    FM_BIN,  0,
  10720. #ifdef COMMENT
  10721.     "/command",   FM_CMD,  0,        /* Not implemented */
  10722. #endif /* COMMENT */
  10723.     "/read",      FM_REA,  0,
  10724.     "/write",     FM_WRI,  0
  10725. };
  10726. static int nfcswtab = (sizeof (fcswtab) / sizeof (struct keytab));
  10727.  
  10728. static struct keytab fclkwtab[] = {    /* CLOSE options */
  10729.     "all",        1,       0
  10730. };
  10731.  
  10732. static struct keytab fsekwtab[] = {    /* SEEK symbols */
  10733.     "eof",        1,       0,
  10734.     "last",       2,       0
  10735. };
  10736. static int nfsekwtab = (sizeof (fsekwtab) / sizeof (struct keytab));
  10737.  
  10738. #define SEE_LINE  RD_LINE        /* SEEK options */
  10739. #define SEE_CHAR  RD_CHAR
  10740. #define SEE_REL   3
  10741. #define SEE_ABS   4
  10742.  
  10743. static struct keytab fskswtab[] = {
  10744.     "/absolute",  SEE_ABS,  0,
  10745.     "/byte",      SEE_CHAR, 0,
  10746.     "/character", SEE_CHAR, CM_INV,
  10747.     "/line",      SEE_LINE, 0,
  10748.     "/relative",  SEE_REL,  0
  10749. };
  10750. static int nfskswtab = (sizeof (fskswtab) / sizeof (struct keytab));
  10751.  
  10752. #define COU_LINE  RD_LINE        /* COUNT options */
  10753. #define COU_CHAR  RD_CHAR
  10754. #define COU_LIS   3
  10755. #define COU_NOL   4
  10756.  
  10757. static struct keytab fcoswtab[] = {
  10758.     "/bytes",     COU_CHAR, 0,
  10759.     "/characters",COU_CHAR, CM_INV,
  10760.     "/lines",     COU_LINE, 0,
  10761.     "/list",      COU_LIS,  0,
  10762.     "/nolist",    COU_NOL,  0,
  10763.     "/quiet",     COU_NOL,  CM_INV
  10764. };
  10765. static int nfcoswtab = (sizeof (fcoswtab) / sizeof (struct keytab));
  10766.  
  10767. static struct keytab frdtab[] = {    /* READ types */
  10768.     "/block",     RD_SIZE, CM_INV|CM_ARG,
  10769.     "/byte",      RD_CHAR, CM_INV,
  10770.     "/character", RD_CHAR, 0,
  10771.     "/line",      RD_LINE, 0,
  10772.     "/size",      RD_SIZE, CM_ARG
  10773. };
  10774. static int nfrdtab = (sizeof (frdtab) / sizeof (struct keytab));
  10775.  
  10776. static struct keytab fwrtab[] = {    /* WRITE types */
  10777.     "/block",     WR_SIZE, CM_INV|CM_ARG,
  10778.     "/byte",      WR_CHAR, CM_INV,
  10779.     "/character", WR_CHAR, 0,
  10780.     "/line",      WR_LINE, 0,
  10781.     "/lpad",      WR_LPAD, CM_ARG,
  10782.     "/rpad",      WR_RPAD, CM_ARG,
  10783.     "/size",      WR_SIZE, CM_ARG,
  10784.     "/string",    WR_STRI, 0
  10785. };
  10786. static int nfwrtab = (sizeof (fwrtab) / sizeof (struct keytab));
  10787.  
  10788. static char blanks[] = "\040\040\040\040"; /* Some blanks for formatting */
  10789.  
  10790. int
  10791. dofile(op) int op; {            /* Do the FILE command */
  10792.     char vnambuf[VNAML];        /* Buffer for variable names */
  10793.     char *vnp = NULL;            /* Pointer to same */
  10794.     char zfilnam[CKMAXPATH+2];
  10795.     char * p;
  10796.     struct FDB fl, sw, nu;
  10797.     long z;
  10798.     int rsize, filmode = 0, relative = -1, eofflg = 0;
  10799.     int rc, x, y, cx, n, getval, dummy, confirmed, listing = -1;
  10800.     int charflag = 0, sizeflag = 0;
  10801.     int pad = 32, wr_lpad = 0, wr_rpad = 0;
  10802.  
  10803.     if (op == XXFILE) {            /* FILE command was given */
  10804.     /* Get subcommand */
  10805.     if ((cx = cmkey(fctab,nfctab,"Operation","",xxstring)) < 0) {
  10806.         if (cx == -3) {
  10807.         printf("?File operation required\n");
  10808.         x = -9;
  10809.         }
  10810.         return(cx);
  10811.     }
  10812.     } else {                /* Shorthand command was given */
  10813.     switch (op) {
  10814.       case XXF_CL: cx = FIL_CLS; break; /* FCLOSE */
  10815.       case XXF_FL: cx = FIL_FLU; break; /* FFLUSH */
  10816.       case XXF_LI: cx = FIL_LIS; break; /* FLIST */
  10817.       case XXF_OP: cx = FIL_OPN; break; /* etc... */
  10818.       case XXF_RE: cx = FIL_REA; break;
  10819.       case XXF_RW: cx = FIL_REW; break;
  10820.       case XXF_SE: cx = FIL_SEE; break;
  10821.       case XXF_ST: cx = FIL_STA; break;
  10822.       case XXF_WR: cx = FIL_WRI; break;
  10823.       case XXF_CO: cx = FIL_COU; break;
  10824.       default: return(-2);
  10825.     }
  10826.     }
  10827.     switch (cx) {            /* Do requested subcommand */
  10828.       case FIL_OPN:            /* OPEN */
  10829.     cmfdbi(&sw,            /* Switches */
  10830.            _CMKEY,            /* fcode */
  10831.            "Variable or switch",    /* hlpmsg */
  10832.            "",            /* default */
  10833.            "",            /* addtl string data */
  10834.            nfcswtab,        /* addtl numeric data 1: tbl size */
  10835.            4,            /* addtl numeric data 2: 4 = cmswi */
  10836.            xxstring,        /* Processing function */
  10837.            fcswtab,            /* Keyword table */
  10838.            &fl            /* Pointer to next FDB */
  10839.            );
  10840.     cmfdbi(&fl,            /* Anything that doesn't match */
  10841.            _CMFLD,            /* fcode */
  10842.            "Variable",        /* hlpmsg */
  10843.            "",
  10844.            "",
  10845.            0,
  10846.            0,
  10847.            NULL,
  10848.            NULL,
  10849.            NULL
  10850.            );
  10851.     while (1) {
  10852.         x = cmfdb(&sw);        /* Parse something */
  10853.         if (x < 0) {
  10854.         if (x == -3) {
  10855.             printf("?Variable name and file name required\n");
  10856.             x = -9;
  10857.         }
  10858.         return(x);
  10859.         }
  10860.         if (cmresult.fcode == _CMFLD)
  10861.           break;
  10862.         else if (cmresult.fcode == _CMKEY) {
  10863.         char c;
  10864.         c = cmgbrk();
  10865.         if ((getval =
  10866.              (c == ':' || c == '=')) && !(cmgkwflgs() & CM_ARG)) {
  10867.             printf("?This switch does not take an argument\n");
  10868.             return(-9);
  10869.         }
  10870. #ifdef COMMENT
  10871.         /* Uncomment if we add any switches ere that take args */
  10872.         if (!getval && (cmgkwflgs() & CM_ARG)) {
  10873.             printf("?This switch requires an argument\n");
  10874.             return(-9);        /* (none do...) */
  10875.         }
  10876. #endif /* COMMENT */
  10877.         filmode |= cmresult.nresult; /* OR in the file mode */
  10878.         } else
  10879.           return(-2);
  10880.     }
  10881.     strcpy(vnambuf,cmresult.sresult); /* Not a switch - get the string */
  10882.     if (!vnambuf[0] || chknum(vnambuf)) { /* (if there is one...) */
  10883.         printf("?Variable name required\n");
  10884.         return(-9);
  10885.     }
  10886.     vnp = vnambuf;            /* Check variable-name syntax */
  10887.     if (vnambuf[0] == CMDQ &&
  10888.         (vnambuf[1] == '%' || vnambuf[1] == '&'))
  10889.       vnp++;
  10890.     y = 0;
  10891.     if (*vnp == '%' || *vnp == '&') {
  10892.         if ((y = parsevar(vnp,&x,&dummy)) < 0) {
  10893.         printf("?Syntax error in variable name\n");
  10894.         return(-9);
  10895.         }
  10896.     }
  10897.     if (!(filmode & FM_RWA))    /* If no access mode specified */
  10898.       filmode |= FM_REA;        /* default to /READ. */
  10899.  
  10900.     y = 0;                /* Now parse the filename */
  10901.     if ((filmode & FM_RWA) == FM_WRI)
  10902.       x = cmofi("Name of new file","",&s,xxstring);
  10903.     else if ((filmode & FM_RWA) == FM_REA)
  10904.       x = cmifi("Name of existing file","",&s,&y,xxstring);
  10905.     else {
  10906.         x = cmiofi("Filename","",&s,&y,xxstring);
  10907.         debug(F101,"fopen /append x","",x);
  10908.     }
  10909.     if (x == -9) {
  10910.         if (zchko(s) < 0) {
  10911.         printf("Can't create \"%s\"\n",s);
  10912.         return(x);
  10913.         }
  10914.     } else if (x < 0) {
  10915.         if (x == -3) {
  10916.         printf("?Filename required\n");
  10917.         x = -9;
  10918.         }
  10919.         return(x);
  10920.     }
  10921.     if (y) {            /* No wildcards */
  10922.         printf("?Wildcards not allowed here\n");
  10923.         return(-9);
  10924.     }
  10925.     if (filmode & (FM_APP|FM_WRI)) { /* Check output access */
  10926.         if (zchko(s) < 0) {         /* and set error code if denied */
  10927.         z_error = FX_ACC;
  10928.         printf("?Write access denied - \"%s\"\n",s);
  10929.         return(-9);
  10930.         }
  10931.     }
  10932.     ckstrncpy(zfilnam,s,CKMAXPATH);    /* Is OK - make safe copy */
  10933.     if ((x = cmcfm()) < 0)        /* Get confirmation of command */
  10934.       return(x);
  10935.     if ((n = z_open(zfilnam,filmode)) < 0) {
  10936.         printf("?OPEN failed - %s: %s\n",zfilnam,ckferror(n));
  10937.         return(-9);
  10938.     }
  10939.     addmac(vnambuf,ckitoa(n));    /* Assign channel number to variable */
  10940.     return(success = 1);
  10941.  
  10942.       case FIL_REW:            /* REWIND */
  10943.     if ((x = cmnum("Channel number","",10,&n, xxstring)) < 0) {
  10944.         if (x == -3) {
  10945.         printf("?Channel number required\n");
  10946.         x = -9;
  10947.         }
  10948.         return(x);
  10949.     }
  10950.     if ((x = cmcfm()) < 0)
  10951.       return(x);
  10952.     if ((rc = z_seek(n,0L)) < 0) {
  10953.         printf("?REWIND failed - Channel %d: %s\n",n,ckferror(rc));
  10954.         return(-9);
  10955.     }
  10956.     return(success = 1);
  10957.  
  10958.       case FIL_CLS:            /* CLOSE */
  10959.       cmfdbi(&sw,            /* Second FDB - switches */
  10960.          _CMKEY,        /* fcode */
  10961.          "Channel number; or keyword",
  10962.          "",
  10963.          "",            /* addtl string data */
  10964.          1,            /* addtl numeric data 1: tbl size */
  10965.          0,            /* addtl numeric data 2: 4 = cmswi */
  10966.          xxstring,        /* Processing function */
  10967.          fclkwtab,        /* Keyword table */
  10968.          &nu            /* Pointer to next FDB */
  10969.          );
  10970.       cmfdbi(&nu,            /* First FDB - command switches */
  10971.          _CMNUM,        /* fcode */
  10972.          "",
  10973.          "",            /* default */
  10974.          "",            /* addtl string data */
  10975.          10,            /* addtl numeric data 1: radix */
  10976.          0,            /* addtl numeric data 2: 0 */
  10977.          xxstring,        /* Processing function */
  10978.          NULL,            /* Keyword table */
  10979.          NULL            /* Pointer to next FDB */
  10980.          );            /*  */
  10981.     x = cmfdb(&sw);            /* Parse something */
  10982.     if (x < 0) {
  10983.         if (x == -3) {
  10984.         printf("?Channel number or ALL required\n");
  10985.         x = -9;
  10986.         }
  10987.         return(x);
  10988.     }
  10989.     if (cmresult.fcode == _CMNUM)
  10990.       n = cmresult.nresult;
  10991.     else if (cmresult.fcode == _CMKEY)
  10992.       n = -1;
  10993.     if ((x = cmcfm()) < 0)
  10994.       return(x);
  10995.     rc = 1;
  10996.     if (n < 0) {
  10997.         int count = 0;
  10998.         int i;
  10999.         for (i = 0; i < z_maxchan; i++) {
  11000.         x = z_close(i);
  11001.         if (x == FX_SYS) {
  11002.             printf("?CLOSE failed - Channel %d: %s\n",n,ckferror(x));
  11003.             rc = 0;
  11004.         } else if (x > -1)
  11005.           count++;
  11006.         }
  11007.         debug(F101,"FILE CLOSE ALL","",count);
  11008.     } else if ((x = z_close(n)) < 0) {
  11009.         printf("?CLOSE failed - Channel %d: %s\n",n,ckferror(x));
  11010.         return(-9);
  11011.     }
  11012.     return(success = rc);
  11013.  
  11014.       case FIL_REA:            /* READ */
  11015.       case FIL_WRI:            /* WRITE */
  11016.     rsize = 0;
  11017.     cmfdbi(&sw,            /* Switches */
  11018.            _CMKEY,            /* fcode */
  11019.            "Channel or switch",    /* hlpmsg */
  11020.            "",            /* default */
  11021.            "",            /* addtl string data */
  11022.            (cx == FIL_REA) ? nfrdtab : nfwrtab,
  11023.            4,            /* addtl numeric data 2: 4 = cmswi */
  11024.            xxstring,        /* Processing function */
  11025.            (cx == FIL_REA) ? frdtab : fwrtab, /* Keyword table */
  11026.            &nu            /* Pointer to next FDB */
  11027.            );
  11028.     cmfdbi(&nu,            /* Channel number */
  11029.            _CMNUM,            /* fcode */
  11030.            "Channel",
  11031.            "",            /* default */
  11032.            "",            /* addtl string data */
  11033.            10,            /* addtl numeric data 1: radix */
  11034.            0,            /* addtl numeric data 2: 0 */
  11035.            xxstring,        /* Processing function */
  11036.            NULL,            /* Keyword table */
  11037.            NULL            /* Pointer to next FDB */
  11038.            );
  11039.     do {
  11040.         x = cmfdb(&sw);        /* Parse something */
  11041.         if (x < 0) {
  11042.         if (x == -3) {
  11043.             printf("?Channel number required\n");
  11044.             x = -9;
  11045.         }
  11046.         return(x);
  11047.         }
  11048.         if (cmresult.fcode == _CMNUM) /* Channel number */
  11049.           break;
  11050.         else if (cmresult.fcode == _CMKEY) { /* Switch */
  11051.         char c;
  11052.         c = cmgbrk();
  11053.         if ((getval =
  11054.              (c == ':' || c == '=')) && !(cmgkwflgs() & CM_ARG)) {
  11055.             printf("?This switch does not take an argument\n");
  11056.             return(-9);
  11057.         }
  11058.         if (!getval && (cmgkwflgs() & CM_ARG)) {
  11059.             printf("?This switch requires an argument\n");
  11060.             return(-9);
  11061.         }
  11062.         switch (cmresult.nresult) {
  11063.           case WR_LINE:
  11064.             charflag = 0;
  11065.             sizeflag = 0;
  11066.             rsize = 0;
  11067.             break;
  11068.           case WR_CHAR:
  11069.             rsize = 1;
  11070.             charflag = 1;
  11071.             sizeflag = 1;
  11072.             break;
  11073.           case WR_SIZE:
  11074.             if ((x = cmnum("Bytes","",10,&rsize, xxstring)) < 0) {
  11075.             if (x == -3) {
  11076.                 printf("?Number required\n");
  11077.                 x = -9;
  11078.             }
  11079.             return(x);
  11080.             }
  11081.             charflag = 0;
  11082.             sizeflag = 1;
  11083.             break;
  11084.           case WR_STRI:
  11085.             rsize = 1;
  11086.             charflag = 0;
  11087.             sizeflag = 0;
  11088.             break;
  11089.           case WR_LPAD:
  11090.           case WR_RPAD:
  11091.             if ((x = cmnum("Numeric ASCII character value",
  11092.                    "32",10,&pad, xxstring)) < 0)
  11093.               return(x);
  11094.             if (cmresult.nresult == WR_LPAD)
  11095.               wr_lpad = 1;
  11096.             else
  11097.               wr_rpad = 1;
  11098.             break;
  11099.         }
  11100.         debug(F101,"FILE READ rsize 2","",rsize);
  11101.         } else
  11102.           return(-2);
  11103.     } while
  11104.       (cmresult.fcode == _CMKEY);
  11105.  
  11106.     n = cmresult.nresult;        /* Channel */
  11107.     debug(F101,"FILE READ/WRITE channel","",n);
  11108.  
  11109.     if (cx == FIL_WRI) {        /* WRITE */
  11110.         int len = 0;
  11111.         if ((x = cmtxt("Text","",&s,xxstring)) < 0)
  11112.           return(x);
  11113.         strcpy(line,s);        /* Make a safe copy */
  11114.         s = line;
  11115.         s = brstrip(s);        /* Strip braces */
  11116.         if (charflag) {        /* Write one char */
  11117.         len = 1;        /* So length = 1 */
  11118.         rsize = 1;        /* Don't supply terminator */
  11119.         } else if (!sizeflag) {    /* Write a string */
  11120.         len = -1;        /* So length is unspecified */
  11121.         } else {            /* Write a block of given size */
  11122.         int i, k, xx;
  11123.         if (rsize > TMPBUFSIZ) {
  11124.             z_error = FX_OFL;
  11125.             printf("?Buffer overflow\n");
  11126.             return(-9);
  11127.         }
  11128.         len = rsize;        /* rsize is really length */
  11129.         rsize = 1;        /* Don't supply a terminator */
  11130.         xx = strlen(s);        /* Size of given string */
  11131.         if (xx >= len) {    /* Bigger or equal */
  11132.             s[len] = NUL;
  11133.         } else if (wr_lpad) {    /* Smaller, left-padding requested */
  11134.             for (i = 0; i < len - xx; i++) /* Must make a copy */
  11135.               tmpbuf[i] = pad;
  11136.             strcpy(tmpbuf+i,s);
  11137.             tmpbuf[len] = NUL;
  11138.             s = tmpbuf;        /* Redirect write source */
  11139.         } else {        /* Smaller with right-padding */
  11140.             for (i = xx; i < len; i++)
  11141.               s[i] = pad;
  11142.             s[len] = NUL;
  11143.         }
  11144.         }
  11145.         if ((rc = z_out(n,s,len,rsize)) < 0) { /* Try to write */
  11146.         printf("?Channel %d WRITE error: %s\n",n,ckferror(rc));
  11147.         return(-9);
  11148.         }
  11149.     } else {            /* FIL_REA READ */
  11150.         confirmed = 0;
  11151.         vnambuf[0] = NUL;
  11152.         x = cmfld("Variable name","",&s,NULL);
  11153.         debug(F111,"FILE READ cmfld",s,x);
  11154.         if (x < 0) {
  11155.         if (x == -3 || !*s) {
  11156.             if ((x = cmcfm()) < 0)
  11157.               return(x);
  11158.             else
  11159.               confirmed++;
  11160.         } else
  11161.           return(x);
  11162.         }
  11163.         strcpy(vnambuf,s);
  11164.         debug(F111,"FILE READ vnambuf",vnambuf,confirmed);
  11165.         if (vnambuf[0]) {        /* Variable name given, check it */
  11166.         if (!confirmed) {
  11167.             x = cmcfm();
  11168.             if (x < 0)
  11169.               return(x);
  11170.             else
  11171.               confirmed++;
  11172.         }
  11173.         vnp = vnambuf;
  11174.         if (vnambuf[0] == CMDQ &&
  11175.             (vnambuf[1] == '%' || vnambuf[1] == '&'))
  11176.           vnp++;
  11177.         y = 0;
  11178.         if (*vnp == '%' || *vnp == '&') {
  11179.             if ((y = parsevar(vnp,&x,&dummy)) < 0) {
  11180.             printf("?Syntax error in variable name\n");
  11181.             return(-9);
  11182.             }
  11183.         }
  11184.         }
  11185.         debug(F111,"FILE READ variable",vnambuf,confirmed);
  11186.  
  11187.         if (!confirmed)
  11188.           if ((x = cmcfm()) < 0)
  11189.         return(x);
  11190.  
  11191.         line[0] = NUL;        /* Clear destination buffer */
  11192.         if (rsize >= LINBUFSIZ)    /* Don't overrun it */
  11193.           rsize = LINBUFSIZ - 1;
  11194.  
  11195.         if (rsize == 0)        /* Read a line */
  11196.           rc = z_in(n,line,LINBUFSIZ,LINBUFSIZ-1,0);
  11197.         else
  11198.           rc = z_in(n,line,LINBUFSIZ,rsize,1); /* Read a block */
  11199.         if (rc < 0) {        /* Error... */
  11200.         debug(F101,"FILE READ error","",rc);
  11201.         debug(F101,"FILE READ errno","",errno);
  11202.         if (rc == FX_EOF) {    /* EOF - fail but no error message */
  11203.             return(success = 0);
  11204.         } else {        /* Other error - fail and print msg */
  11205.             printf("?READ error: %s\n",ckferror(rc));
  11206.             return(-9);
  11207.         }
  11208.         }
  11209.         debug(F110,"FILE READ data",line,0);
  11210.         if (vnambuf[0])        /* Read OK - If variable name given */
  11211.           addmac(vnambuf,line);    /* Assign result to variable */
  11212.         else            /* otherwise */
  11213.           printf("%s\n",line);    /* just print it */
  11214.     }
  11215.     return(success = 1);
  11216.  
  11217.       case FIL_SEE:            /* SEEK */
  11218.       case FIL_COU:            /* COUNT */
  11219.     rsize = RD_CHAR;        /* Defaults to /BYTE */
  11220.     cmfdbi(&sw,            /* Switches */
  11221.            _CMKEY,            /* fcode */
  11222.            "Channel or switch",    /* hlpmsg */
  11223.            "",            /* default */
  11224.            "",            /* addtl string data */
  11225.            ((cx == FIL_SEE) ? nfskswtab : nfcoswtab),
  11226.            4,            /* addtl numeric data 2: 4 = cmswi */
  11227.            xxstring,        /* Processing function */
  11228.            ((cx == FIL_SEE) ? fskswtab : fcoswtab),
  11229.            &nu            /* Pointer to next FDB */
  11230.            );
  11231.     cmfdbi(&nu,            /* Channel number */
  11232.            _CMNUM,            /* fcode */
  11233.            "Channel",
  11234.            "",            /* default */
  11235.            "",            /* addtl string data */
  11236.            10,            /* addtl numeric data 1: radix */
  11237.            0,            /* addtl numeric data 2: 0 */
  11238.            xxstring,        /* Processing function */
  11239.            NULL,            /* Keyword table */
  11240.            NULL            /* Pointer to next FDB */
  11241.            );
  11242.     do {
  11243.         x = cmfdb(&sw);        /* Parse something */
  11244.         if (x < 0) {
  11245.         if (x == -3) {
  11246.             printf("?Channel number required\n");
  11247.             x = -9;
  11248.         }
  11249.         return(x);
  11250.         }
  11251.         if (cmresult.fcode == _CMNUM) /* Channel number */
  11252.           break;
  11253.         else if (cmresult.fcode == _CMKEY) { /* Switch */
  11254.         char c;
  11255.         c = cmgbrk();
  11256.         if ((getval =
  11257.              (c == ':' || c == '=')) && !(cmgkwflgs() & CM_ARG)) {
  11258.             printf("?This switch does not take an argument\n");
  11259.             return(-9);
  11260.         }
  11261.         if (cx == FIL_SEE) {
  11262.             switch (cmresult.nresult) {
  11263.               case SEE_REL: relative = 1; break;
  11264.               case SEE_ABS: relative = 0; break;
  11265.               default: rsize = cmresult.nresult;
  11266.             }
  11267.         } else if (cx == FIL_COU) {
  11268.             switch (cmresult.nresult) {
  11269.               case COU_LIS: listing = 1; break;
  11270.               case COU_NOL: listing = 0; break;
  11271.               default: rsize = cmresult.nresult;
  11272.             }
  11273.         }
  11274.         }
  11275.     } while
  11276.       (cmresult.fcode == _CMKEY);
  11277.  
  11278.     n = cmresult.nresult;        /* Channel */
  11279.     debug(F101,"FILE SEEK/COUNT channel","",n);
  11280.     if (cx == FIL_COU) {
  11281.         if ((x = cmcfm()) < 0)
  11282.           return(x);
  11283.         z_filcount = z_count(n,rsize);
  11284.         if (z_filcount < 0) {
  11285.         rc = z_filcount;
  11286.         printf("?COUNT error: %s\n",ckferror(rc));
  11287.         return(-9);
  11288.         }
  11289.         if (listing < 0)
  11290.           listing = !cmdsrc();
  11291.         if (listing)
  11292.           printf(" %ld %s%s\n",
  11293.              z_filcount,
  11294.              ((rsize == RD_CHAR) ? "byte" : "line"),
  11295.              ((z_filcount == 1L) ? "" : "s")
  11296.              );
  11297.         return(success = (z_filcount > -1) ? 1 : 0);
  11298.     }
  11299.     cmfdbi(&sw,            /* SEEK symbolic targets (EOF) */
  11300.            _CMKEY,            /* fcode */
  11301.            "Channel number;\n or keyword",
  11302.            "",
  11303.            "",            /* addtl string data */
  11304.            nfsekwtab,        /* addtl numeric data 1: table size */
  11305.            0,            /* addtl numeric data 2: 4 = cmswi */
  11306.            xxstring,        /* Processing function */
  11307.            fsekwtab,        /* Keyword table */
  11308.            &nu            /* Pointer to next FDB */
  11309.            );
  11310.     cmfdbi(&nu,            /* Channel number */
  11311.            _CMNUM,            /* fcode */
  11312.            "",
  11313.            "",            /* default */
  11314.            "",            /* addtl string data */
  11315.            10,            /* addtl numeric data 1: radix */
  11316.            0,            /* addtl numeric data 2: 0 */
  11317.            xxstring,        /* Processing function */
  11318.            NULL,            /* Keyword table */
  11319.            NULL            /* Pointer to next FDB */
  11320.            );
  11321.     x = cmfdb(&sw);            /* Parse something */
  11322.     if (x < 0) {
  11323.         if (x == -3) {
  11324.         printf("?Channel number or EOF required\n");
  11325.         x = -9;
  11326.         }
  11327.         return(x);
  11328.     }
  11329.     if (cmresult.fcode == _CMNUM) {
  11330.         y = cmresult.nresult;
  11331.         debug(F110,"FILE SEEK atmbuf",atmbuf,0);
  11332.         if (relative < 0) {
  11333.         if (cx == FIL_SEE && (atmbuf[0] == '+' || atmbuf[0] == '-'))
  11334.           relative = 1;
  11335.         else
  11336.           relative = 0;
  11337.         }
  11338.     } else if (cmresult.fcode == _CMKEY) {
  11339.         eofflg = cmresult.nresult;
  11340.         relative = 0;
  11341.         y = 0 - eofflg;
  11342.     }
  11343.     if ((x = cmcfm()) < 0)
  11344.       return(x);
  11345.     z = y;                /* Convert to long */
  11346.     y = 1;                /* Recycle this */
  11347.     z_flush(n);
  11348.     debug(F101,"FILE SEEK relative","",relative);
  11349.     debug(F101,"FILE SEEK rsize","",rsize);
  11350.  
  11351.     if (rsize == RD_CHAR) {        /* Seek to byte position */
  11352.         if (relative) {
  11353.         long pos;
  11354.         pos = z_getpos(n);
  11355.         if (pos < 0L) {
  11356.             rc = pos;
  11357.             printf("?Relative SEEK failed: %s\n",ckferror(rc));
  11358.             return(-9);
  11359.         }
  11360.         z += pos;
  11361.         } else {
  11362.         if (z < 0 && !eofflg) {    /* Negative arg but not relative */
  11363.             y = 0;        /* Remember this was bad */
  11364.             z = 0;        /* but substitute 0 */
  11365.         }
  11366.         }
  11367.         debug(F101,"FILE SEEK /CHAR z","",z);
  11368.         if (z < 0 && !eofflg) {
  11369.         z_error = FX_RNG;
  11370.         return(success = 0);
  11371.         }
  11372.         if ((rc = z_seek(n,z)) < 0) {
  11373.         if (rc == FX_EOF) return(success = 0);
  11374.         printf("?SEEK /BYTE failed - Channel %d: %s\n",n,ckferror(rc));
  11375.         return(-9);
  11376.         }
  11377.     } else {            /* Seek to line */
  11378.         if (relative) {
  11379.         long pos;
  11380.         pos = z_getline(n);
  11381.         debug(F101,"FILE SEEK /LINE pos","",pos);
  11382.         if (pos < 0L) {
  11383.             rc = pos;
  11384.             printf("?Relative SEEK failed: %s\n",ckferror(rc));
  11385.             return(-9);
  11386.         }
  11387.         z += pos;
  11388.         }
  11389.         debug(F101,"FILE SEEK /LINE z","",z);
  11390.         if (z < 0 && !eofflg) {
  11391.         z_error = FX_RNG;
  11392.         return(success = 0);
  11393.         }
  11394.         if ((rc = z_line(n,z)) < 0) {
  11395.         if (rc == FX_EOF) return(success = 0);
  11396.         printf("?SEEK /LINE failed - Channel %d: %s\n",n,ckferror(rc));
  11397.         return(-9);
  11398.         }
  11399.     }
  11400.     return(success = y);
  11401.  
  11402.       case FIL_LIS: {            /* LIST open files */
  11403. #ifdef CK_TTGWSIZ
  11404.       extern int cmd_rows, cmd_cols;
  11405. #endif /* CK_TTGWSIZ */
  11406.           extern int xaskmore;
  11407.       int i, x, n = 0, paging = 0;
  11408.       char * s;
  11409.  
  11410.       if ((x = cmcfm()) < 0)
  11411.         return(x);
  11412.  
  11413. #ifdef CK_TTGWSIZ
  11414.       if (cmd_rows > 0 && cmd_cols > 0)
  11415. #endif /* CK_TTGWSIZ */
  11416.         paging = xaskmore;
  11417.  
  11418.       printf("System open file limit: %4d\n", z_openmax);
  11419.       printf("Maximum for FILE OPEN:  %4d\n", z_maxchan);
  11420.       printf("Files currently open:   %4d\n\n", z_nopen);
  11421.       n = 4;
  11422.       for (i = 0; i < z_maxchan; i++) {
  11423.           s = z_getname(i);        /* Got one? */
  11424.           if (s) {            /* Yes */
  11425.           char m[8];
  11426.           m[0] = NUL;
  11427.           printf("%2d. %s",i,s); /* Print name */
  11428.           n++;             /* Count it */
  11429.           x = z_getmode(i);     /* Get modes & print them */
  11430.           if (x > -1) {
  11431.               if (x & FM_REA) strcat(m,"R");
  11432.               if (x & FM_WRI) strcat(m,"W");
  11433.               if (x & FM_APP) strcat(m,"A");
  11434.               if (x & FM_BIN) strcat(m,"B");
  11435.               if (m[0])
  11436.             printf(" (%s)",m);
  11437.               if (x & FM_EOF)
  11438.             printf(" [EOF]");
  11439.               else
  11440.             printf(" %ld",z_getpos(i)); /* And file position too */
  11441.           }
  11442.           printf("\n");
  11443. #ifdef CK_TTGWSIZ
  11444.           if (paging > 0) {    /* Pause at end of screen */
  11445.               if (n > cmd_rows - 3) {
  11446.               if (!askmore())
  11447.                 break;
  11448.               else
  11449.                 n = 0;
  11450.               }
  11451.           }
  11452. #endif /* CK_TTGWSIZ */
  11453.           }
  11454.       }
  11455.       return(success = 1);
  11456.       }
  11457.  
  11458.       case FIL_FLU:            /* FLUSH */
  11459.     if ((x = cmnum("Channel number","",10,&n, xxstring)) < 0) {
  11460.         if (x == -3) {
  11461.         printf("?Channel number required\n");
  11462.         x = -9;
  11463.         }
  11464.         return(x);
  11465.     }
  11466.     if ((x = cmcfm()) < 0)
  11467.       return(x);
  11468.     if ((rc = z_flush(n)) < 0) {
  11469.         printf("?FLUSH failed - Channel %d: %s\n",n,ckferror(rc));
  11470.         return(-9);
  11471.     }
  11472.     return(success = 1);
  11473.  
  11474.       case FIL_STA:            /* STATUS */
  11475.     if ((x = cmnum("Channel number","",10,&n, xxstring)) < 0) {
  11476.         if (x == -3) {
  11477.         printf("?Channel number required\n");
  11478.         x = -9;
  11479.         }
  11480.         return(x);
  11481.     }
  11482.     if ((x = cmcfm()) < 0)
  11483.       return(x);
  11484.     p = blanks + 3;            /* Tricky formatting... */
  11485.     if (n < 1000) p--;
  11486.     if (n < 100) p--;
  11487.     if (n < 10) p--;
  11488.     if ((rc = z_getmode(n)) < 0) {
  11489.         printf("Channel %d:%s%s\n",n,p,ckferror(rc));
  11490.         return(success = 0);
  11491.     } else if (!rc) {
  11492.         printf("Channel %d:%sNot open\n",n,p);
  11493.         return(success = 0);
  11494.     } else {
  11495.         long xx;
  11496.         s = z_getname(n);
  11497.         if (!s) s = "(name unknown)";
  11498.         printf("Channel %d:%sOpen\n",n,p);
  11499.         printf(" File:        %s\n Modes:      ",s);
  11500.         if (rc & FM_REA) printf(" /READ");
  11501.         if (rc & FM_WRI) printf(" /WRITE");
  11502.         if (rc & FM_APP) printf(" /APPEND");
  11503.         if (rc & FM_BIN) printf(" /BINARY");
  11504.         if (rc & FM_CMD) printf(" /COMMAND");
  11505.         if (rc & FM_EOF) printf(" [EOF]");
  11506.         printf("\n Size:        %ld\n",z_count(n,RD_CHAR));
  11507.         printf(" At byte:     %ld\n",z_getpos(n));
  11508.         xx = z_getline(n);
  11509.         if (xx > -1)
  11510.           printf(" At line:     %ld\n",xx);
  11511.         return(success = 1);
  11512.     }
  11513.       default:
  11514.     return(-2);
  11515.     }
  11516. }
  11517. #endif /* CKCHANNELIO */
  11518.  
  11519. #ifndef NOSETKEY
  11520. /* Save Key maps and in OS/2 Mouse maps */
  11521. int
  11522. savkeys(name,disp) char * name; int disp; {
  11523.     char *tp;
  11524.     static struct filinfo xx;
  11525.     int savfil, i, j, k;
  11526.     char buf[1024];
  11527.  
  11528.     zclose(ZMFILE);
  11529.  
  11530.     if (disp) {
  11531.     xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  11532.     xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = '\0';
  11533.     xx.lblopts = 0;
  11534.     savfil = zopeno(ZMFILE,name,NULL,&xx);
  11535.     } else savfil = zopeno(ZMFILE,name,NULL,NULL);
  11536.  
  11537.     if (savfil) {
  11538. #ifdef OS2
  11539.     ztime(&tp);
  11540.     zsout(ZMFILE, "; Kermit 95 SAVE KEYMAP file: ");
  11541.     zsoutl(ZMFILE,tp);
  11542.     if (mskkeys) {
  11543.         zsoutl(ZMFILE,
  11544.      "if eq \"\\v(program)\" \"C-Kermit\" set mskermit keycodes on");
  11545.     } else {
  11546.         zsoutl(ZMFILE,
  11547.          "if NOT eq \"\\v(program)\" \"C-Kermit\" stop 1 C-Kermit required.");
  11548.         zsoutl(ZMFILE,"set mskermit keycodes off");
  11549.     }
  11550.     zsoutl(ZMFILE,"");
  11551. #else /* OS2 */
  11552.     ztime(&tp);
  11553.     zsout(ZMFILE, "; C-Kermit SAVE KEYMAP file: ");
  11554.     zsoutl(ZMFILE,tp);
  11555. #endif /* OS2 */
  11556.  
  11557.     zsoutl(ZMFILE,"; Clear previous keyboard mappings ");
  11558.     zsoutl(ZMFILE,"set key clear");
  11559. #ifdef OS2
  11560.     for (k = 0; k < nttkey; k++) {
  11561.         if (!ttkeytab[k].flgs) {
  11562.         sprintf(buf, "set terminal key %s clear", ttkeytab[k].kwd);
  11563.         zsoutl(ZMFILE,buf);
  11564.         }
  11565.     }
  11566. #endif /* OS2 */
  11567.     zsoutl(ZMFILE,"");
  11568.  
  11569.     for (i = 0; i < KMSIZE; i++) {
  11570.         if (macrotab[i]) {
  11571.         int len = strlen((char *)macrotab[i]);
  11572. #ifdef OS2
  11573.         sprintf(buf,"set key \\%d ",mskkeys ? cktomsk(i) : i);
  11574. #else /* OS2 */
  11575.         sprintf(buf,"set key \\%d ",i);
  11576. #endif /* OS2 */
  11577.         zsout(ZMFILE,buf);
  11578.  
  11579.         for (j = 0; j < len; j++) {
  11580.             char ch = macrotab[i][j];
  11581.             if (ch <= SP || ch >= DEL ||
  11582.              ch == '-' || ch == ',' ||
  11583.                          ch == '{' || ch == '}' ||
  11584.                          ch == ';' || ch == '?' ||
  11585.                          ch == '.' || ch == '\'' ||
  11586.                          ch == '\\' || ch == '/' ||
  11587.                          ch == '#') {
  11588.             sprintf(buf, "\\{%d}", ch);
  11589.             zsout(ZMFILE,buf);
  11590.             } else {
  11591.             sprintf(buf, "%c", ch);
  11592.             zsout(ZMFILE,buf);
  11593.             }
  11594.         }
  11595. #ifdef OS2
  11596.         sprintf(buf, "\t; %s", keyname(i));
  11597.         zsoutl(ZMFILE,buf);
  11598. #else
  11599.         zsoutl(ZMFILE,"");
  11600. #endif /* OS2 */
  11601.         } else if ( keymap[i] != i ) {
  11602. #ifndef NOKVERBS
  11603.         if (IS_KVERB(keymap[i])) {
  11604.             for (j = 0; j < nkverbs; j++)
  11605.               if (kverbs[j].kwval == (keymap[i] & ~F_KVERB))
  11606.             break;
  11607.             if (j != nkverbs) {
  11608. #ifdef OS2
  11609.             sprintf(buf, "set key \\%d \\K%s\t; %s",
  11610.                 mskkeys ? cktomsk(i) : i,
  11611.                 kverbs[j].kwd, keyname(i)
  11612.                 );
  11613.             zsoutl(ZMFILE,buf);
  11614. #else
  11615.             sprintf(buf, "set key \\%d \\K%s", i, kverbs[j].kwd);
  11616.             zsoutl(ZMFILE,buf);
  11617. #endif
  11618.             }
  11619.         } else
  11620. #endif /* NOKVERBS */
  11621.           {
  11622. #ifdef OS2
  11623.               sprintf(buf, "set key \\%d \\{%d}\t; %s",
  11624.                   mskkeys ? cktomsk(i) : i,
  11625.                   keymap[i],
  11626.                   keyname(i)
  11627.                   );
  11628.               zsoutl(ZMFILE,buf);
  11629. #else
  11630.               sprintf(buf, "set key \\%d \\{%d}", i, keymap[i]);
  11631.               zsoutl(ZMFILE,buf);
  11632. #endif /* OS2 */
  11633.           }
  11634.         }
  11635.     }
  11636. #ifdef OS2
  11637.     /* OS/2 also has the SET TERMINAL KEY <termtype> defines */
  11638.     for (k = 0; k < nttkey; k++) {
  11639.         extern struct keynode * ttkeymap[];
  11640.         struct keynode * pnode = NULL;
  11641.  
  11642.         if (ttkeytab[k].flgs)    /* Don't process CM_INV or CM_ABR */
  11643.           continue;
  11644.  
  11645.         zsoutl(ZMFILE,"");
  11646.         sprintf(buf, "; SET TERMINAL KEY %s", ttkeytab[k].kwd );
  11647.         zsoutl(ZMFILE,buf);
  11648.  
  11649.         for (pnode = ttkeymap[ttkeytab[k].kwval];
  11650.          pnode;
  11651.          pnode = pnode->next
  11652.          ) {
  11653.         switch (pnode->def.type) {
  11654.           case key:
  11655.             sprintf(buf, "set terminal key %s \\%d \\{%d}\t; %s",
  11656.                      ttkeytab[k].kwd,
  11657.                 mskkeys ? cktomsk(pnode->key) : pnode->key,
  11658.                 pnode->def.key.scancode,
  11659.                 keyname(pnode->key)
  11660.                 );
  11661.             zsoutl(ZMFILE,buf);
  11662.             break;
  11663.           case kverb:
  11664.             for (j = 0; j < nkverbs; j++)
  11665.               if (kverbs[j].kwval == (pnode->def.kverb.id & ~F_KVERB))
  11666.             break;
  11667.             if (j != nkverbs) {
  11668.             sprintf(buf, "set terminal key %s \\%d \\K%s\t; %s",
  11669.                 ttkeytab[k].kwd,
  11670.                 mskkeys ? cktomsk(pnode->key) : pnode->key,
  11671.                 kverbs[j].kwd, keyname(pnode->key)
  11672.                 );
  11673.             zsoutl(ZMFILE,buf);
  11674.             }
  11675.             break;
  11676.           case macro: {
  11677.               int len = strlen((char *)pnode->def.macro.string);
  11678.               sprintf(buf,"set terminal key %s \\%d ",
  11679.                   ttkeytab[k].kwd,
  11680.                   mskkeys ? cktomsk(pnode->key) : pnode->key);
  11681.               zsout(ZMFILE,buf);
  11682.  
  11683.               for (j = 0; j < len; j++) {
  11684.               char ch = pnode->def.macro.string[j];
  11685.               if (ch <= SP || ch >= DEL ||
  11686.                                ch == '-' || ch == ',' ||
  11687.                                ch == '{' || ch == '}' ||
  11688.                                ch == ';' || ch == '?' ||
  11689.                                ch == '.' || ch == '\'' ||
  11690.                                ch == '\\' || ch == '/' ||
  11691.                                ch == '#') {
  11692.                   sprintf(buf, "\\{%d}", ch);
  11693.                   zsout(ZMFILE,buf);
  11694.               } else {
  11695.                   sprintf(buf, "%c", ch);
  11696.                   zsout(ZMFILE,buf);
  11697.               }
  11698.               }
  11699.               sprintf(buf, "\t; %s", keyname(pnode->key));
  11700.               zsoutl(ZMFILE,buf);
  11701.               break;
  11702.           }
  11703.           case literal: {
  11704.               int len = strlen((char *)pnode->def.literal.string);
  11705.               sprintf(buf,"set terminal key %s /literal \\%d ",
  11706.                   ttkeytab[k].kwd,
  11707.                   mskkeys ? cktomsk(pnode->key) : pnode->key);
  11708.               zsout(ZMFILE,buf);
  11709.  
  11710.               for (j = 0; j < len; j++) {
  11711.               char ch = pnode->def.literal.string[j];
  11712.               if (ch <= SP || ch >= DEL ||
  11713.                                ch == '-' || ch == ',' ||
  11714.                                ch == '{' || ch == '}' ||
  11715.                                ch == ';' || ch == '?' ||
  11716.                                ch == '.' || ch == '\'' ||
  11717.                                ch == '\\' || ch == '/' ||
  11718.                                ch == '#') {
  11719.                   sprintf(buf, "\\{%d}", ch);
  11720.                   zsout(ZMFILE,buf);
  11721.               } else {
  11722.                   sprintf(buf, "%c", ch);
  11723.                   zsout(ZMFILE,buf);
  11724.               }
  11725.               }
  11726.               sprintf(buf, "\t; %s", keyname(pnode->key));
  11727.               zsoutl(ZMFILE,buf);
  11728.               break;
  11729.           }
  11730.           case esc:
  11731.             sprintf(buf,
  11732.                "set terminal key %s /literal \\%d \\{%d}\\{%d}\t; %s",
  11733.                 ttkeytab[k].kwd,
  11734.                 mskkeys ? cktomsk(pnode->key) : pnode->key,
  11735.                 ISDG200(ttkeytab[k].kwval) ? 30 : 27,
  11736.                 pnode->def.esc.key & ~F_ESC,
  11737.                 keyname(pnode->key)
  11738.                 );
  11739.             zsoutl(ZMFILE,buf);
  11740.             break;
  11741.           case csi:
  11742.             sprintf(buf,
  11743.                "set terminal key %s /literal \\%d \\{27}[\\{%d}\t; %s",
  11744.                 ttkeytab[k].kwd,
  11745.                 mskkeys ? cktomsk(pnode->key) : pnode->key,
  11746.                 pnode->def.csi.key & ~F_CSI,
  11747.                 keyname(pnode->key)
  11748.                 );
  11749.             zsoutl(ZMFILE,buf);
  11750.             break;
  11751.           default:
  11752.             continue;
  11753.         }
  11754.         }
  11755.     }
  11756. #endif /* OS2 */
  11757.  
  11758.     zsoutl(ZMFILE,"");
  11759.     zsoutl(ZMFILE,"; End");
  11760.     zclose(ZMFILE);
  11761.     return(success = 1);
  11762.     } else {
  11763.     return(success = 0);
  11764.     }
  11765. }
  11766. #endif /* NOSETKEY */
  11767.  
  11768. #ifdef OS2
  11769. struct keytab cmdtrmopt[] = {
  11770.     "scrollback", 0, 0
  11771. };
  11772.  
  11773. _PROTOTYP(int savscrbk, (int, char *, int));
  11774. #endif /* OS2 */
  11775.  
  11776. int
  11777. dosave(xx) int xx; {
  11778.     int x, y, disp;
  11779.     char * s = NULL;
  11780.     extern struct keytab disptb[];
  11781. #ifdef ZFNQFP
  11782.     struct zfnfp * fnp;
  11783. #endif /* ZFNQFP */
  11784.  
  11785.     switch (xx) {
  11786. #ifdef OS2
  11787.     case XSCMD:
  11788.     case XSTERM:
  11789.     if ((y = cmkey(cmdtrmopt,1,"What to save","scrollback",xxstring)) < 0)
  11790.       return(y);
  11791.     z = cmofi("Name of Scrollback file","scrollbk.txt",&s,xxstring);
  11792.     if (z < 0) return(z);
  11793.     if (z == 2) {
  11794.         printf("?Sorry, %s is a directory name\n",s);
  11795.         return(-9);
  11796.     }
  11797. #ifdef ZFNQFP
  11798.     if (fnp = zfnqfp(s,TMPBUFSIZ - 1,tmpbuf)) {
  11799.         if (fnp->fpath)
  11800.         if ((int) strlen(fnp->fpath) > 0)
  11801.           s = fnp->fpath;
  11802.     }
  11803. #endif /* ZFNQFP */
  11804.  
  11805.     strcpy(line,s);
  11806.     s = line;
  11807. #ifdef MAC
  11808.     z = 0;
  11809. #else
  11810.     if ((z = cmkey(disptb,2,"Disposition","new",xxstring)) < 0)
  11811.       return(z);
  11812. #endif /* MAC */
  11813.     disp = z;
  11814.     if ((x = cmcfm()) < 0) return(x);
  11815.         switch (xx) {
  11816.       case XSCMD:
  11817.             return(success = savscrbk(VCMD,s,disp));
  11818.       case XSTERM:
  11819.             return(success = savscrbk(VTERM,s,disp));
  11820.       default:
  11821.             return(success = 0);
  11822.         }
  11823. #endif /* OS2 */
  11824. #ifndef NOSETKEY
  11825.       case XSKEY:
  11826.     y = cmofi("Name of Kermit command file","keymap.ksc",&s,xxstring);
  11827.     if (y < 0) return(y);
  11828.     if (y == 2) {
  11829.         printf("?Sorry, %s is a directory name\n",s);
  11830.         return(-9);
  11831.     }
  11832. #ifdef ZFNQFP
  11833.     if (fnp = zfnqfp(s,TMPBUFSIZ - 1,tmpbuf)) {
  11834.         if (fnp->fpath)
  11835.         if ((int) strlen(fnp->fpath) > 0)
  11836.           s = fnp->fpath;
  11837.     }
  11838. #endif /* ZFNQFP */
  11839.  
  11840.     strcpy(line,s);
  11841.     s = line;
  11842. #ifdef MAC
  11843.     y = 0;
  11844. #else
  11845.     if ((y = cmkey(disptb,2,"Disposition","new",xxstring)) < 0)
  11846.       return(y);
  11847. #endif /* MAC */
  11848.     disp = y;
  11849.     if ((x = cmcfm()) < 0) return(x);
  11850.     return (savkeys(s,disp));
  11851. #endif /* NOSETKEY */
  11852.  
  11853.       default:
  11854.     if ((x = cmcfm()) < 0) return(x);
  11855.     printf("Not implemented - %s\n",cmdbuf);
  11856.     return(success = 0);
  11857.     }
  11858. }
  11859.  
  11860. /*
  11861.   R E A D T E X T
  11862.  
  11863.   Read text with a custom prompt into given buffer using command parser but
  11864.   with no echoing or entry into recall buffer.
  11865. */
  11866. int
  11867. readtext(prmpt, buffer, bufsiz) char * prmpt; char * buffer; int bufsiz; {
  11868. #ifdef CK_RECALL
  11869.     int sv_recall;            /* For turning off command recall */
  11870.     extern int on_recall;        /* around Password prompting */
  11871. #endif /* CK_RECALL */
  11872.     int rc;
  11873. #ifdef OS2
  11874.     extern int vmode;
  11875.     int vmode_sav = vmode;
  11876.  
  11877.     if (win95_popup
  11878. #ifdef IKSD
  11879.          && !inserver
  11880. #endif /* IKSD */
  11881.          )
  11882.       return(popup_readtext(vmode,prmpt,buffer,bufsiz,0));
  11883.  
  11884.     if (vmode == VTERM) {
  11885.         vmode = VCMD;
  11886.         VscrnIsDirty(VTERM);
  11887.         VscrnIsDirty(VCMD);
  11888.     }
  11889. #endif /* OS2 */
  11890.  
  11891. #ifdef CK_RECALL
  11892.     sv_recall = on_recall;        /* Save and turn off command recall */
  11893.     on_recall = 0;
  11894. #endif /* CK_RECALL */
  11895.     cmsavp(psave,PROMPTL);        /* Save old prompt */
  11896.     cmsetp(prmpt);            /* Make new prompt */
  11897.     concb((char)escape);        /* Put console in cbreak mode */
  11898.     cmini(1);                /* and echo mode */
  11899.     if (pflag) prompt(xxstring);    /* Issue prompt if at top level */
  11900.     cmres();                /* Reset the parser */
  11901.     for (rc = -1; rc < 0; ) {        /* Prompt till they answer */
  11902.         rc = cmtxt("","",&s,NULL);    /* Get a literal line of text */
  11903.         cmres();            /* Reset the parser again */
  11904.     }
  11905.     ckstrncpy(buffer,s,bufsiz);
  11906. #ifdef CK_RECALL
  11907.     on_recall = sv_recall;        /* Restore command recall */
  11908. #endif /* CK_RECALL */
  11909.     cmsetp(psave);            /* Restore original prompt */
  11910.  
  11911. #ifdef OS2
  11912.     if (vmode != vmode_sav) {
  11913.         vmode = VTERM;
  11914.         VscrnIsDirty(VCMD);
  11915.         VscrnIsDirty(VTERM);
  11916.     }
  11917. #endif /* OS2 */
  11918.     return(0);
  11919. }
  11920. #endif /* NOICP */
  11921.  
  11922. /* A general function to allow a Password or other information  */
  11923. /* to be read from the command prompt without it going into     */
  11924. /* the recall buffer or being echo'd.                           */
  11925.  
  11926. int
  11927. readpass(prmpt, buffer, bufsiz) char * prmpt; char * buffer; int bufsiz; {
  11928. #ifdef NOICP
  11929.     printf("%s", prmpt);
  11930.     gets(buffer);
  11931.     return(1);
  11932. #else  /* NOICP */
  11933. #ifdef CK_RECALL
  11934.     int sv_recall;            /* For turning off command recall */
  11935.     extern int on_recall;        /* around Password prompting */
  11936. #endif /* CK_RECALL */
  11937.     int rc;
  11938. #ifdef OS2
  11939.     extern int vmode;
  11940.     int vmode_sav = vmode;
  11941. #endif /* OS2 */
  11942. #ifdef CKSYSLOG
  11943.     int savlog;
  11944. #endif /* CKSYSLOG */
  11945. #ifdef OS2
  11946.     if (win95_popup
  11947. #ifdef IKSD
  11948.          && !inserver
  11949. #endif /* IKSD */
  11950.          )
  11951.       return(popup_readpass(vmode,prmpt,buffer,bufsiz,0));
  11952. #endif /* OS2 */
  11953. #ifdef CKSYSLOG
  11954.     savlog = ckxsyslog;            /* Save and turn off syslogging */
  11955.     ckxsyslog = 0;
  11956. #endif /* CKSYSLOG */
  11957. #ifdef OS2
  11958.     if (vmode == VTERM) {
  11959.         vmode = VCMD;
  11960.         VscrnIsDirty(VTERM);
  11961.         VscrnIsDirty(VCMD);
  11962.     }
  11963. #endif /* OS2 */
  11964. #ifdef CK_RECALL
  11965.     sv_recall = on_recall;        /* Save and turn off command recall */
  11966.     on_recall = 0;
  11967. #endif /* CK_RECALL */
  11968.     cmsavp(psave,PROMPTL);        /* Save old prompt */
  11969.     cmsetp(prmpt);            /* Make new prompt */
  11970.     concb((char)escape);        /* Put console in cbreak mode */
  11971.     cmini(0);                /* and no-echo mode */
  11972.     if (pflag) prompt(xxstring);    /* Issue prompt if at top level */
  11973.     cmres();                /* Reset the parser */
  11974.     for (rc = -1; rc < 0; ) {        /* Prompt till they answer */
  11975.         rc = cmtxt("","",&s,NULL);    /* Get a literal line of text */
  11976.         cmres();            /* Reset the parser again */
  11977.     }
  11978.     ckstrncpy(buffer,s,bufsiz);
  11979. #ifdef CK_RECALL
  11980.     on_recall = sv_recall;        /* Restore command recall */
  11981. #endif /* CK_RECALL */
  11982.     printf("\r\n");            /* Echo a CRLF */
  11983.     cmsetp(psave);            /* Restore original prompt */
  11984.     cmini(1);                /* Restore echo mode */
  11985. #ifdef OS2
  11986.     if (vmode != vmode_sav) {
  11987.         vmode = VTERM;
  11988.         VscrnIsDirty(VCMD);
  11989.         VscrnIsDirty(VTERM);
  11990.     }
  11991. #endif /* OS2 */
  11992. #ifdef CKSYSLOG
  11993.     ckxsyslog = savlog;            /* Restore syslogging */
  11994. #endif /* CKSYSLOG */
  11995.     return(0);
  11996. #endif /* NOICP */
  11997. }
  11998.  
  11999. #ifndef NOICP
  12000. struct keytab authtab[] = {        /* Available authentication types */
  12001. #ifdef CK_KERBEROS
  12002.     "k4",        AUTH_KRB4, CM_INV,
  12003.     "k5",        AUTH_KRB5, CM_INV,
  12004.     "kerberos4", AUTH_KRB4, 0,
  12005.     "kerberos5", AUTH_KRB5, 0,
  12006.     "krb4",      AUTH_KRB4, CM_INV,
  12007.     "krb5",      AUTH_KRB5, CM_INV,
  12008. #endif /* CK_KERBEROS */
  12009. #ifdef NT
  12010.     "ntlm",      AUTH_NTLM, 0,
  12011. #endif /* NT */
  12012. #ifdef CK_SRP
  12013.     "srp",       AUTH_SRP,  0,
  12014. #endif /* CK_SRP */
  12015. #ifdef CK_SSL
  12016.     "ssl",       AUTH_SSL,  0,
  12017. #endif /* CK_SSL */
  12018.     "",         0,      0
  12019. };
  12020. int authtabn = sizeof(authtab)/sizeof(struct keytab)-1;
  12021.  
  12022. #ifdef CK_KERBEROS
  12023. struct keytab kerbtab[] = {        /* Kerberos authentication types */
  12024.     "k4",        AUTH_KRB4, CM_INV,
  12025.     "k5",        AUTH_KRB5, CM_INV,
  12026.     "kerberos4", AUTH_KRB4, 0,
  12027.     "kerberos5", AUTH_KRB5, 0,
  12028.     "krb4",      AUTH_KRB4, CM_INV,
  12029.     "krb5",      AUTH_KRB5, CM_INV
  12030. };
  12031. int kerbtabn = sizeof(kerbtab)/sizeof(struct keytab);
  12032.  
  12033. static struct keytab krb_s_tbl[] = {    /* AUTHENTICATE command switches: */
  12034.     "/cache",   KRB_S_CA, CM_ARG
  12035. };
  12036. static int krb_s_n = sizeof(krb_s_tbl)/sizeof(struct keytab);
  12037.  
  12038. static struct keytab krb_v_tbl[] = {    /* KERBEROS version values: */
  12039.     "4",    4, 0,
  12040.     "5",    5, 0,            /* (add others as needed...) */
  12041.     "auto", 0, 0            /* Note: 0 = auto */
  12042. };
  12043. static int krb_v_n = sizeof(krb_v_tbl)/sizeof(struct keytab);
  12044.  
  12045. static struct keytab krb_a_tbl[] = {    /* KERBEROS actions: */
  12046.     "destroy",           KRB_A_DE, 0,
  12047.     "initialize",        KRB_A_IN, 0,
  12048.     "list-credentials",  KRB_A_LC, 0
  12049. };
  12050. static int krb_a_n = sizeof(krb_a_tbl)/sizeof(struct keytab);
  12051.  
  12052. static struct keytab krb4_i_tbl[] = {    /* KERBEROS 4 INITIALIZE switches: */
  12053.     "/brief",            KRB_I_BR, 0,      /* /BRIEF       */
  12054.     "/instance",         KRB_I_IN, CM_ARG, /* /INSTANCE:   */
  12055.     "/lifetime",         KRB_I_LF, CM_ARG, /* /LIFETIME:   */
  12056.     "/not-preauth",      KRB_I_NPA, 0,     /* /NOT-PREAUTH */
  12057.     "/password",         KRB_I_PW, CM_ARG, /* /PASSWORD:   */
  12058. #ifdef OS2
  12059.     "/popup",            KRB_I_POP, 0,     /* /POPUP       */
  12060. #endif /* OS2 */
  12061.     "/preauth",          KRB_I_PA, 0,      /* /PREAUTH     */
  12062.     "/realm",            KRB_I_RL, CM_ARG, /* /REALM:      */
  12063.     "/verbose",          KRB_I_VB, 0,      /* /VERBOSE     */
  12064.     "", 0, 0
  12065. };
  12066. static int krb4_i_n = sizeof(krb4_i_tbl)/sizeof(struct keytab) - 1;
  12067.  
  12068. static struct keytab krb5_i_tbl[] = {    /* KERBEROS 5 INITIALIZE switches: */
  12069.     "/addresses",        KRB_I_ADR, CM_ARG,
  12070.     "/forwardable",      KRB_I_FW,  0,       /* /FORWARDABLE */
  12071.     "/instance",         KRB_I_IN, CM_ARG, /* /INSTANCE:   */
  12072.     "/k4",               KRB_I_K4,  CM_INV, /* /KERBEROS4   */
  12073.     "/kerberos4",        KRB_I_K4,  0,      /* /KERBEROS4   */
  12074.     "/krb4",             KRB_I_K4,  CM_INV, /* /KERBEROS4   */
  12075.     "/lifetime",         KRB_I_LF,  CM_ARG, /* /LIFETIME:   */
  12076.     "/no-k4",            KRB_I_NK4, CM_INV,/* /NO-KERBEROS4 */
  12077.     "/no-kerberos4",     KRB_I_NK4, 0,     /* /NO-KERBEROS4 */
  12078.     "/no-krb4",          KRB_I_NK4, CM_INV,/* /NO-KERBEROS4 */
  12079.     "/not-forwardable",  KRB_I_NFW, 0,       /* /NOT-FORWARDABLE */
  12080.     "/not-proxiable",    KRB_I_NPR, 0,     /* /NOT-PROXIABLE   */
  12081.     "/password",         KRB_I_PW,  CM_ARG, /* /PASSWORD:   */
  12082. #ifdef OS2
  12083.     "/popup",            KRB_I_POP, 0,     /* /POPUP       */
  12084. #endif /* OS2 */
  12085.     "/postdate",         KRB_I_PD, CM_ARG, /* /POSTDATE:   */
  12086.     "/pr",               KRB_I_PR, CM_INV|CM_ABR, /* to allow for */
  12087.     "/pro",              KRB_I_PR, CM_INV|CM_ABR, /* different spellings */
  12088.     "/prox",             KRB_I_PR, CM_INV|CM_ABR,
  12089.     "/proxiable",        KRB_I_PR, 0,      /* /PROXIABLE   */
  12090.     "/proxyable",        KRB_I_PR, CM_INV, /* /PROXYABLE   */
  12091.     "/realm",            KRB_I_RL, CM_ARG, /* /REALM:      */
  12092.     "/renew",            KRB_I_RN, 0,       /* /RENEW       */
  12093.     "/renewable",        KRB_I_RB, CM_ARG, /* /RENEWABLE:  */
  12094.     "/service",          KRB_I_SR, CM_ARG, /* /SERVICE:    */
  12095.     "/validate",         KRB_I_VA, 0,        /* /VALIDATE    */
  12096.     "", 0, 0
  12097. };
  12098. static int krb5_i_n = sizeof(krb5_i_tbl)/sizeof(struct keytab) - 1;
  12099.  
  12100. static struct keytab klctab[] = {    /* List Credentials switches*/
  12101.     "/addresses",  XYKLCAD, 0,
  12102.     "/encryption", XYKLCEN, 0,
  12103.     "/flags",      XYKLCFL, 0
  12104. };
  12105. static int nklctab = sizeof(klctab)/sizeof(struct keytab);
  12106.  
  12107. extern int krb_action;
  12108. extern struct krb_op_data krb_op;
  12109.  
  12110. extern struct krb5_list_cred_data krb5_lc;
  12111. extern struct krb5_init_data krb5_init;
  12112. extern char * krb5_d_principal;        /* Default principal */
  12113. extern char * krb5_d_instance;
  12114. extern char * krb5_d_realm;        /* Default realm */
  12115. extern char * krb5_d_cc;        /* Default credentials cache */
  12116. extern char * krb5_d_srv;               /* Default service name */
  12117. extern int    krb5_d_lifetime;          /* Default lifetime */
  12118. extern int    krb5_d_forwardable;
  12119. extern int    krb5_d_proxiable;
  12120. extern int    krb5_d_renewable;
  12121. extern int    krb5_autoget;
  12122. extern int    krb5_autodel;
  12123. extern int    krb5_d_getk4;
  12124. extern int    krb5_checkaddrs;
  12125.  
  12126. extern struct krb4_init_data krb4_init;
  12127. extern char * krb4_d_principal;        /* Default principal */
  12128. extern char * krb4_d_realm;        /* Default realm */
  12129. extern char * krb4_d_srv;               /* Default service name */
  12130. extern int    krb4_d_lifetime;          /* Default lifetime */
  12131. extern int    krb4_d_preauth;
  12132. extern char * krb4_d_instance;
  12133. extern int    krb4_autoget;
  12134. extern int    krb4_autodel;
  12135. extern int    krb4_checkaddrs;
  12136. #endif /* CK_KERBEROS */
  12137.  
  12138. #ifndef NOSHOW
  12139. #ifdef CK_AUTHENTICATION
  12140. int
  12141. sho_auth(cx) int cx; {
  12142.     extern int auth_type_user[];
  12143.     int i;
  12144.     char * p;
  12145.     int kv = 0, all = 0;
  12146.  
  12147. #ifdef IKSD
  12148.     if (inserver) {
  12149.         printf("?Sorry, command disabled.\r\n");
  12150.         return(success = 0);
  12151.     }
  12152. #endif /* IKSD */
  12153.     if (cx) {
  12154.         kv = cx;
  12155.     } else if (auth_type_user[0] != AUTHTYPE_AUTO) {
  12156.         kv = auth_type_user[0];
  12157.     } else {
  12158.         all = 1;
  12159.         kv = AUTHTYPE_KERBEROS_V4;
  12160.     }
  12161.     while (kv) {
  12162.         switch (kv) {
  12163.       case AUTHTYPE_KERBEROS_V4:
  12164.             kv = all ? AUTHTYPE_KERBEROS_V5 : 0;
  12165.             if (ck_krb4_is_installed())
  12166.           printf(" Authentication:      Kerberos 4\n");
  12167.             else {
  12168.                 printf(" Authentication:      Kerberos 4 (not installed)\n");
  12169.                 continue;
  12170.             }
  12171. #ifdef CK_KERBEROS
  12172.             if (krb_action < 0) {
  12173.                 p = "(none)";
  12174.             } else {
  12175.                 for (p = "", i = 0; i < krb_a_n; i++) {
  12176.                     if (krb_action == krb_a_tbl[i].kwval) {
  12177.                         p = krb_a_tbl[i].kwd;
  12178.                         break;
  12179.                     }
  12180.                 }
  12181.             }
  12182.             printf(" Action:              %s\n", p);
  12183.             printf(" Default lifetime     %d\n",krb4_d_lifetime);
  12184.             printf(" Lifetime:            %d (minutes)\n",krb4_init.lifetime);
  12185.             printf(" Default preauth:     %d\n",krb4_d_preauth);
  12186.             printf(" Preauth:             %d\n",krb4_init.preauth);
  12187.             printf(" Default principal:   \"%s\"\n",
  12188.                     krb4_d_principal ? krb4_d_principal : "");
  12189.             printf(" Principal:           \"%s\"\n",
  12190.                     krb4_init.principal ? krb4_init.principal : "");
  12191.             printf(" Default realm:       \"%s\"\n",
  12192.                     krb4_d_realm ? krb4_d_realm : "");
  12193.             printf(" Realm:               \"%s\"\n",
  12194.                     krb4_init.realm ? krb4_init.realm : "");
  12195.             printf(" Default instance:    \"%s\"\n",
  12196.                     krb4_d_instance ? krb4_d_instance : "");
  12197.             printf(" Instance:            \"%s\"\n",
  12198.                     krb4_init.instance ? krb4_init.instance : "");
  12199.             printf(" Auto-Get TGTs:       %d\n",krb4_autoget);
  12200.             printf(" Auto-Destroy TGTs:   %s\n",
  12201.                     krb4_autodel==KRB_DEL_NO?"never":
  12202.                     krb4_autodel==KRB_DEL_CL?"on-close":"on-exit");
  12203.             printf(" Check IP Addresses:  %d\n",krb4_checkaddrs);
  12204. #ifdef COMMENT
  12205.             printf(" Password:    \"%s\"\n",
  12206.                     krb4_init.password  ? krb4_init.password  : "");
  12207. #endif /* COMMENT */
  12208. #endif /* CK_KERBEROS */
  12209.             printf("\n");
  12210.             break;
  12211.       case AUTHTYPE_KERBEROS_V5:
  12212.             kv = all ? AUTHTYPE_SSL : 0;
  12213.             if (ck_krb5_is_installed())
  12214.           printf(" Authentication:      Kerberos 5\n");
  12215.             else {
  12216.                 printf(" Authentication:      Kerberos 5 (not installed)\n");
  12217.                 continue;
  12218.             }
  12219.  
  12220. #ifdef CK_KERBEROS
  12221.             printf(" Cache file:          %s\n",
  12222.                     krb_op.cache ? krb_op.cache : "(none)");
  12223.             printf(" Default cache:       %s\n",
  12224.                     krb5_d_cc ? krb5_d_cc : "(none)");
  12225.             if (krb_action < 0) {
  12226.                 p = "(none)";
  12227.             } else  {
  12228.                 for (p = "", i = 0; i < krb_a_n; i++) {
  12229.                     if (krb_action == krb_a_tbl[i].kwval) {
  12230.                         p = krb_a_tbl[i].kwd;
  12231.                         break;
  12232.                     }
  12233.                 }
  12234.             }
  12235.             printf(" Action:              %s\n", p);
  12236.  
  12237.             printf(" Default forwardable  %d\n",krb5_d_forwardable);
  12238.             printf(" Forwardable:         %d\n",krb5_init.forwardable);
  12239.             printf(" Default lifetime     %d\n",krb5_d_lifetime);
  12240.             printf(" Lifetime:            %d (minutes)\n",krb5_init.lifetime);
  12241.             printf(" Postdate:            \"%s\"\n",
  12242.                     krb5_init.postdate ? krb5_init.postdate: "");
  12243.             printf(" Default proxiable:   %d\n",krb5_d_proxiable);
  12244.             printf(" Proxiable:           %d\n",krb5_init.proxiable);
  12245.             printf(" Renew:               %d\n",krb5_init.renew);
  12246.             printf(" Default renewable:   %d (minutes)\n",krb5_d_renewable);
  12247.             printf(" Renewable:           %d (minutes)\n",krb5_init.renewable);
  12248.             printf(" Service:             \"%s\"\n",
  12249.                     krb5_init.service ? krb5_init.service : "");
  12250.             printf(" Validate:            %d\n",krb5_init.validate);
  12251.             printf(" Default principal:   \"%s\"\n",
  12252.                     krb5_d_principal ? krb5_d_principal : "");
  12253.             printf(" Principal:           \"%s\"\n",
  12254.                     krb5_init.principal ? krb5_init.principal : "");
  12255.             printf(" Default instance:    \"%s\"\n",
  12256.                     krb5_d_instance ? krb5_d_instance : "");
  12257.             printf(" Default realm:       \"%s\"\n",
  12258.                     krb5_d_realm ? krb5_d_realm : "");
  12259.             printf(" Realm:               \"%s\"\n",
  12260.                     krb5_init.realm ? krb5_init.realm : "");
  12261.             printf(" Auto-Get TGTs:       %d\n",krb5_autoget);
  12262.             printf(" Auto-Destroy TGTs:   %s\n",
  12263.                     krb5_autodel==KRB_DEL_NO?"never":
  12264.                     krb5_autodel==KRB_DEL_CL?"on-close":"on-exit");
  12265.             printf(" Default get K4 TGTs: %d\n",krb5_d_getk4);
  12266.             printf(" Get K4 TGTs: %d\n",krb5_init.getk4);
  12267.             printf(" Check IP Addresses:  %d\n",krb5_checkaddrs);
  12268.             printf(" IP-Addresses:        ");
  12269.             if (krb5_init.addrs) {
  12270.                 for (i = 0; krb5_init.addrs[i]; i++) {
  12271.                     if (i)
  12272.               printf(",");
  12273.                     printf("%s",krb5_init.addrs[i]);
  12274.                 }
  12275.                 printf("\n");
  12276.             } else
  12277.           printf("(use default)\n");
  12278. #ifdef COMMENT
  12279.             printf(" Password:            \"%s\"\n",
  12280.                     krb5_init.password  ? krb5_init.password  : "");
  12281. #endif /* COMMENT */
  12282. #endif /* CK_KERBEROS */
  12283.             printf("\n");
  12284.             break;
  12285.       case AUTHTYPE_SSL:
  12286.             kv = 0;
  12287.             if (ck_ssleay_is_installed())
  12288.           printf(" Authentication:      SSL/TLS\n");
  12289.             else {
  12290.                 printf(" Authentication:      SSL/TLS (not installed)\n");
  12291.                 continue;
  12292.             }
  12293.  
  12294. #ifdef CK_SSL
  12295.             printf(" RSA Certs file: %s\n",ssl_rsa_cert_file?
  12296.                   ssl_rsa_cert_file:"(none)");
  12297.             printf(" RSA Key file: %s\n",ssl_rsa_key_file?
  12298.                   ssl_rsa_key_file:"(none)");
  12299.             printf(" DSA Certs file: %s\n",ssl_dsa_cert_file?
  12300.                   ssl_dsa_cert_file:"(none)");
  12301.             printf(" DH Key file: %s\n",ssl_dh_key_file?
  12302.                   ssl_dh_key_file:"(none)");
  12303.             printf(" DH Param file: %s\n",ssl_dh_param_file?
  12304.                   ssl_dh_param_file:"(none)");
  12305.             printf(" CRL file: %s\n",ssl_crl_file?
  12306.                   ssl_crl_file:"(none)");
  12307.             printf(" CRL dir: %s\n",ssl_crl_dir?
  12308.                     ssl_crl_dir:"(none)");
  12309.             printf(" Verify file: %s\n",ssl_verify_file?
  12310.                   ssl_verify_file:"(none)");
  12311.             printf(" Verify dir: %s\n",ssl_verify_dir?
  12312.                   ssl_verify_dir:"(none)");
  12313.             printf(" Cipher list:\n");
  12314.         if (ssl_con == NULL) {
  12315.         SSL_library_init();
  12316.         ssl_ctx = (SSL_CTX *)
  12317.           SSL_CTX_new((SSL_METHOD *)TLSv1_method());
  12318.         if (ssl_ctx != NULL)
  12319.           ssl_con= (SSL *) SSL_new(ssl_ctx);
  12320.         }
  12321.         if (ssl_con != NULL) {
  12322.         CHAR * p = NULL;
  12323.         int i;
  12324.  
  12325.         for (i = 0; ; i++) {
  12326.             p = (CHAR *) SSL_get_cipher_list(ssl_con,i);
  12327.             if (p == NULL)
  12328.               break;
  12329.             printf("    %s\n",p);
  12330.         }
  12331.         }
  12332.             printf(" Certs OK? %s\n",ssl_certsok_flag? "yes" : "no");
  12333.             printf(" Debug mode: %s\n", ssl_debug_flag ? "on" : "off");
  12334.             printf(" Verbose mode: %s\n", ssl_verbose_flag ? "on" : "off");
  12335.             printf(" Verify mode: %s\n",
  12336.                     ssl_verify_flag == SSL_VERIFY_NONE ? "none" :
  12337.                     ssl_verify_flag == SSL_VERIFY_PEER ? "peer-cert" :
  12338.                     "fail-if-no-peer-cert");
  12339.             printf(" SSL only? %s\n", ssl_only_flag ? "yes" : "no");
  12340.             printf(" TLS only? %s\n", tls_only_flag ? "yes" : "no");
  12341. #endif /* CK_SSL */
  12342.             break;
  12343.       case AUTHTYPE_NTLM:
  12344.             kv = 0;
  12345.             if (ck_ntlm_is_installed()) {
  12346.                 printf(" Authentication:      NTLM\n");
  12347.                 printf(" No options\n");
  12348.             } else {
  12349.                 printf(" Authentication:      NTLM (not installed)\n");
  12350.                 continue;
  12351.             }
  12352.             printf("\n");
  12353.             break;
  12354.       case AUTHTYPE_SRP:
  12355.             kv = 0;
  12356.             if (ck_srp_is_installed()) {
  12357.                 printf(" Authentication:      SRP\n");
  12358.                 printf(" No options\n");
  12359.             } else {
  12360.                 printf(" Authentication:      SRP (not installed)\n");
  12361.                 continue;
  12362.             }
  12363.             printf("\n");
  12364.             break;
  12365.         }
  12366.     }
  12367.     return(success = 1);
  12368. }
  12369. #endif /* CK_AUTHENTICATION */
  12370. #endif /* NOSHOW */
  12371.  
  12372. #ifdef CK_KERBEROS
  12373.  
  12374. /*  C P _ A U T H  --  AUTHENTICATE command parsing  */
  12375.  
  12376. int
  12377. cp_auth() {                /* Command_Parse AUTHENTICATE */
  12378.     int c, i, n;            /* Workers */
  12379.     int rc = 0;                /* Return code */
  12380.     int getval;                /* Parsing helpers */
  12381.     int tmpauth = 0;            /* Temporary authentication type */
  12382.     int kv = 0;                /* Temporary Kerberos version */
  12383.     int tmp_action = -1;        /* Temporary Kerberos action */
  12384.     int tmp_klc = 0;            /* Temporary list-credentials */
  12385.     char tmphlp[256];            /* For building help message */
  12386.     char * p;
  12387.     char * tmppswd  = NULL;        /* Password */
  12388.     char * tmpprinz = NULL;        /* Principal */
  12389.     char * tmprealm = NULL;             /* Realm */
  12390.     char * tmpcache = NULL;        /* Cache file */
  12391.     char * tmpinst  = NULL;             /* K4 Instance */
  12392.     char * tmpaddrs[KRB5_NUM_OF_ADDRS];
  12393. #ifdef CK_RECALL
  12394.     int sv_recall;            /* For turning off command recall */
  12395.     extern int on_recall;        /* around Password prompting */
  12396. #endif /* CK_RECALL */
  12397.     struct stringint {            /* Temporary array for switch values */
  12398.     char * sval;            /* String value */
  12399.     int ival;            /* Integer value */
  12400.     } pv[KRB_I_MAX+1];            /* This many */
  12401.     struct FDB kw, sw, fl;        /* FDBs for each parse function */
  12402.  
  12403.     krb_action = -1;            /* Initialize Kerberos action. */
  12404.     tmp_action = -1;            /* And our local copy. */
  12405.     for (i = 0; i < KRB5_NUM_OF_ADDRS; i++)
  12406.       tmpaddrs[i] = NULL;
  12407.  
  12408.     if ((y = cmkey(kerbtab,kerbtabn,"authentication type","",xxstring)) < 0)
  12409.       {
  12410.       if (y == -3)
  12411.         printf("?Authentication type not specified - nothing happens\n");
  12412.       return(y);
  12413.       }
  12414.     tmpauth = y;
  12415.     debug(F101,"kerberos authentication","",tmpauth);
  12416.     switch (tmpauth) {
  12417.       case AUTH_KRB4: kv = 4; break;    /* Don't assume values are the same */
  12418.       case AUTH_KRB5: kv = 5; break;
  12419.       default:
  12420.     printf("?Authentication type not supported: \"%s\"\n",atmbuf);
  12421.     return(-9);
  12422.     }
  12423.  
  12424.     /* From here down is Kerberos */
  12425.     ini_kerb();                /* Reset Init data to defaults */
  12426.  
  12427.     if (kv == 4) {            /* Set K4 defaults */
  12428.         if (krb4_d_realm)
  12429.       makestr(&tmprealm,krb4_d_realm);
  12430.         if (krb4_d_principal)
  12431.       makestr(&tmpprinz,krb4_d_principal);
  12432.         if (krb4_d_instance)
  12433.       makestr(&tmpinst,krb4_d_instance);
  12434.     } else if (kv == 5) {        /* Set K5 defaults */
  12435.         if (krb5_d_cc)
  12436.       makestr(&tmpcache,krb5_d_cc);
  12437.         if (krb5_d_realm)
  12438.       makestr(&tmprealm,krb5_d_realm);
  12439.         if (krb5_d_principal)
  12440.       makestr(&tmpprinz,krb5_d_principal);
  12441.         if (krb5_d_instance)
  12442.       makestr(&tmpinst,krb5_d_instance);
  12443.     }
  12444.  
  12445.     for (i = 0; i <= KRB_I_MAX; i++) {    /* Initialize switch values */
  12446.     pv[i].sval = NULL;        /* to null pointers */
  12447.     pv[i].ival = 0;            /* and 0 int values */
  12448.     }
  12449.  
  12450.     if (kv == 4) {            /* Kerberos 4 */
  12451.         pv[KRB_I_LF].ival = krb4_d_lifetime;
  12452.         pv[KRB_I_PA].ival = krb4_d_preauth;
  12453.  
  12454.     if ((n = cmkey(krb_a_tbl,krb_a_n,"Kerberos 4 action","",xxstring)) < 0)
  12455.       {
  12456.           if (n == -3)
  12457.         printf("?Action not specified - nothing happens.\n");
  12458.           return(n);
  12459.       }
  12460.     } else if (kv == 5) {        /* Kerberos 5 */
  12461.         pv[KRB_I_FW].ival = krb5_d_forwardable;
  12462.         pv[KRB_I_PR].ival = krb5_d_proxiable;
  12463.         pv[KRB_I_LF].ival = krb5_d_lifetime;
  12464.         pv[KRB_I_RB].ival = krb5_d_renewable;
  12465.         pv[KRB_I_K4].ival = krb5_d_getk4;
  12466.  
  12467.     /* Make help message that shows switches and action keywords */
  12468.     strcpy(tmphlp,"Kerberos 5 action, one of the following:\n ");
  12469.     for (i = 0; i < krb_a_n; i++) {
  12470.         strcat(tmphlp,krb_a_tbl[i].kwd);
  12471.         if (i == krb_a_n - 1)
  12472.           strcat(tmphlp,"\nor switch");
  12473.         else
  12474.       strcat(tmphlp,"   ");
  12475.     }
  12476.     /* Set up first set of chained FDB's */
  12477.  
  12478.     cmfdbi(&sw,            /* First FDB - command switches */
  12479.            _CMKEY,            /* fcode */
  12480.            tmphlp,            /* hlpmsg */
  12481.            "",            /* default (none) */
  12482.            "",            /* addtl string data */
  12483.            krb_s_n,            /* Switch table size */
  12484.            4,            /* addtl numeric data 2: 4 = cmswi */
  12485.            xxstring,        /* Processing function */
  12486.            krb_s_tbl,        /* Switch table */
  12487.            &kw            /* Pointer to next FDB */
  12488.            );
  12489.     cmfdbi(&kw,            /* Second FDB - action keywords */
  12490.            _CMKEY,            /* fcode */
  12491.            "Kerberos action",    /* hlpmsg */
  12492.            "",            /* default (none) */
  12493.            "",            /* addtl string data */
  12494.            krb_a_n,            /* Switch table size */
  12495.            0,            /* addtl num data (0 = NOT switch) */
  12496.            xxstring,        /* Processing function */
  12497.            krb_a_tbl,        /* Keyword table */
  12498.            NULL            /* Pointer to next FDB (none) */
  12499.            );
  12500.  
  12501.     /* Parse */
  12502.  
  12503.     while (1) {            /* Parse 0 or more switches */
  12504.         rc = cmfdb(&sw);        /* Parse something */
  12505.         debug(F101,"kerberos cmfdb 1 rc","",rc);
  12506.         if (rc < 0) {            /* Error */
  12507.         if (rc == -3)
  12508.           printf("?Action not specified - nothing happens.\n");
  12509.         return(rc);        /* or reparse needed */
  12510.         }
  12511.         if (cmresult.fdbaddr != &sw) /* Break out if not a switch */
  12512.           break;
  12513.         c = cmgbrk();        /* Have switch - get break character */
  12514.         getval = (c == ':' || c == '='); /* Must parse an agument? */
  12515.         if (getval && !(cmresult.kflags & CM_ARG)) {
  12516.         printf("?This switch does not take arguments\n");
  12517.         return(-9);        /* OK because nothing malloc'd yet */
  12518.         }
  12519.         if (!getval && (cmgkwflgs() & CM_ARG)) {
  12520.         printf("?This switch requires an argument\n");
  12521.         return(-9);
  12522.         }
  12523.         n = cmresult.nresult;    /* Numeric result = switch value */
  12524.         debug(F101,"kerberos command switch","",n);
  12525.  
  12526.         switch (n) {        /* Handle the switch */
  12527.           case KRB_S_CA:        /* /CACHE:<filename> */
  12528.         p = krb5_d_cc ? krb5_d_cc : "";
  12529.         if ((y = cmofi("Name of cache file",p,&s,xxstring)) < 0) {
  12530.             if (y == -3)
  12531.               s = NULL;
  12532.             else
  12533.               return(y);
  12534.         }
  12535.         makestr(&tmpcache,s);
  12536.         break;
  12537.           default:
  12538.         printf("?Unexpected switch value - internal error\n");
  12539.         return(-9);        /* (if) nothing malloc'd yet. */
  12540.         }
  12541.     }
  12542.     if (cmresult.fdbaddr != &kw) {    /* Checking... */
  12543.         printf("?Unexpected result - internal error\n");
  12544.         return(-9);            /* Nothing malloc'd yet. */
  12545.     }
  12546.     n = cmresult.nresult;        /* Get keyword value */
  12547.     } else {
  12548.     printf("?Unexpected Kerberos version - Internal error\n");
  12549.     return(-9);
  12550.     }
  12551.     debug(F101,"kerberos action","",n);
  12552.     switch (n) {
  12553.       case KRB_A_IN:            /* INITIALIZE */
  12554.       case KRB_A_DE:            /* DESTROY */
  12555.       case KRB_A_LC:            /* LIST-CREDENTIALS */
  12556.     tmp_action = n;            /* OK, set */
  12557.     break;
  12558.       default:                /* Not OK, punt. */
  12559.     printf("?Unexpected action - internal error\n");
  12560.     return(-9);
  12561.     }
  12562.     if (tmp_action == KRB_A_IN) {    /* Action is INITIALIZE */
  12563.     int x;
  12564.     cmfdbi(&sw,            /* INITIALIZE switches */
  12565.            _CMKEY,            /* fcode */
  12566.            "Principal,\n or optional INITIALIZE switch(es)", /* hlpmsg */
  12567.            "",            /* default (none) */
  12568.            "",            /* addtl string data */
  12569.            kv == 4 ?  krb4_i_n : krb5_i_n, /* Switch table size */
  12570.            4,            /* addtl numeric data 2: 4 = cmswi */
  12571.            xxstring,        /* Processing function */
  12572.            kv == 4 ?  krb4_i_tbl : krb5_i_tbl,    /* Switch table */
  12573.            &fl            /* Pointer to next FDB */
  12574.            );
  12575.     cmfdbi(&fl,            /* 3rd FDB - command to send from */
  12576.            _CMFLD,            /* fcode */
  12577.            "Principal",        /* hlpmsg */
  12578.            kv == 4 ? krb4_d_principal : krb5_d_principal, /* principal */
  12579.            "",            /* addtl string data */
  12580.            0,            /* addtl numeric data 1 */
  12581.            0,            /* addtl numeric data 2 */
  12582.            xxstring,
  12583.            NULL,
  12584.            NULL
  12585.            );
  12586.     while (1) {            /* Parse INIT switches or principal */
  12587.         rc = cmfdb(&sw);
  12588.         debug(F101,"kerberos cmfdb 2 rc","",rc);
  12589.         if (rc < 0) {
  12590.         if (rc == -3)
  12591.           printf("?Principal name required\n");
  12592.         goto kerbx;
  12593.         }
  12594.         debug(F101,"kerberos cmfdb 2 fcode","",cmresult.fcode);
  12595.         if (cmresult.fcode != _CMKEY) /* Not a switch, quit switch loop */
  12596.           break;
  12597.         c = cmgbrk();        /* Switch - get break character */
  12598.         debug(F101,"kerberos cmfdb 2 cmgbrk","",c);
  12599.         getval = (c == ':' || c == '=');
  12600.         if (getval && !(cmresult.kflags & CM_ARG)) {
  12601.         printf("?This switch does not take arguments\n");
  12602.         return(-9);        /* OK because nothing malloc'd yet */
  12603.         }
  12604.         if (!getval && (cmgkwflgs() & CM_ARG)) {
  12605.         printf("?This switch requires an argument\n");
  12606.         return(-9);
  12607.         }
  12608.         n = cmresult.nresult;    /* Numeric result = switch value */
  12609.         switch (n) {
  12610.           /* These don't take args... */
  12611.               case KRB_I_PA:            /* /PREAUTH */
  12612.           case KRB_I_FW:        /* /FORWARDABLE */
  12613.           case KRB_I_PR:        /* /PROXIABLE */
  12614.               case KRB_I_RN:        /* /RENEW */
  12615.           case KRB_I_VA:        /* /VALIDATE */
  12616.               case KRB_I_NPA:           /* /NOT-PREAUTH */
  12617.               case KRB_I_NFW:        /* /NOT-FORWARDABLE */
  12618.               case KRB_I_NPR:        /* /NOT-PROXIABLE */
  12619.               case KRB_I_VB:            /* /VERBOSE */
  12620.               case KRB_I_BR:            /* /BRIEF */
  12621.               case KRB_I_K4:            /* /KERBEROS4 */
  12622.               case KRB_I_NK4:           /* /NO-KERBEROS4 */
  12623.               case KRB_I_POP:           /* /POPUP */
  12624.         if (getval) {
  12625.             printf("?This switch does not take a value\n");
  12626.             rc = -9;
  12627.             goto kerbx;
  12628.         }
  12629.                 switch (n) {
  12630.           case KRB_I_NPA:
  12631.                     pv[KRB_I_PA].ival = 0;
  12632.                     break;
  12633.           case KRB_I_NFW:
  12634.                     pv[KRB_I_FW].ival = 0;
  12635.                     break;
  12636.           case KRB_I_NPR:
  12637.                     pv[KRB_I_PR].ival = 0;
  12638.                     break;
  12639.           case KRB_I_VB:
  12640.                     pv[KRB_I_BR].ival = 0;
  12641.                     break;
  12642.                   case KRB_I_NK4:
  12643.                     pv[KRB_I_K4].ival = 0;
  12644.                     break;
  12645.           default:
  12646.                     pv[n].ival = 1;
  12647.                 }
  12648.         break;
  12649.  
  12650.         /* These do take arguments */
  12651.  
  12652.           case KRB_I_RB:        /* /RENEWABLE:<minutes> */
  12653.         pv[n].ival = 0;
  12654.         if (!getval) break;
  12655.         if ((rc = cmnum("Minutes",ckitoa(krb5_init.renewable),
  12656.                 10,&y, xxstring)) < 0)
  12657.           goto kerbx;
  12658.         pv[n].ival = y;
  12659.         break;
  12660.  
  12661.           case KRB_I_LF:        /* /LIFETIME:<minutes> */
  12662.         pv[n].ival = 0;
  12663.         sprintf(tmpbuf,"%d",    /* Default is previous value */
  12664.             kv == 4 ?
  12665.             krb4_init.lifetime :
  12666.             krb5_init.lifetime
  12667.             );
  12668.         if (!getval) break;
  12669.         if ((rc = cmnum("Minutes",tmpbuf,10,&y, xxstring)) < 0)
  12670.           goto kerbx;
  12671.         pv[n].ival = y;
  12672.         break;
  12673.  
  12674.           case KRB_I_PD:        /* /POSTDATE:<timestamp> */
  12675.         if (pv[n].sval) {
  12676.             free(pv[n].sval);
  12677.             pv[n].sval = NULL;
  12678.         }
  12679.         if (!getval) break;
  12680.         if ((rc = cmdate("date-time","",&s,0,xxstring)) < 0)
  12681.           goto kerbx;
  12682.         makestr(&(pv[n].sval),s);
  12683.         break;
  12684.  
  12685.           case KRB_I_SR:        /* /SERVICE:<name> */
  12686.         if (pv[n].sval) {
  12687.             free(pv[n].sval);
  12688.             pv[n].sval = NULL;
  12689.         }
  12690.         if (!getval) break;
  12691.         if ((rc = cmfld("Service-name","",&s,xxstring)) < 0)
  12692.           goto kerbx;
  12693.         makestr(&(pv[n].sval),s);
  12694.         break;
  12695.  
  12696.               case KRB_I_RL:        /* /REALM:<name> */
  12697.         if (pv[n].sval) {
  12698.             free(pv[n].sval);
  12699.             pv[n].sval = NULL;
  12700.         }
  12701.         if (!getval) break;
  12702.         if (kv == 4)
  12703.           p = krb4_d_realm ? krb4_d_realm : "";
  12704.         else
  12705.           p = krb5_d_realm ? krb5_d_realm : "";
  12706.         if ((rc = cmfld("Realm",p,&s,xxstring)) < 0)
  12707.           goto kerbx;
  12708.         makestr(&(pv[n].sval),s);
  12709.         break;
  12710.  
  12711.           case KRB_I_IN:        /* /INSTANCE:<name> */
  12712.         if (pv[n].sval) {
  12713.             free(pv[n].sval);
  12714.             pv[n].sval = NULL;
  12715.         }
  12716.         if (!getval) break;
  12717.                 if (kv == 4)
  12718.                     p = krb4_d_instance ? krb4_d_instance : "";
  12719.                 else
  12720.                     p = krb5_d_instance ? krb5_d_instance : "";
  12721.         if ((rc = cmfld("Instance",p,&s,xxstring)) < 0)
  12722.           goto kerbx;
  12723.         makestr(&(pv[n].sval),s);
  12724.         break;
  12725.  
  12726.           case KRB_I_PW:        /* /PASSWORD:<password> */
  12727.         if (pv[n].sval) {
  12728.             free(pv[n].sval);
  12729.             pv[n].sval = NULL;
  12730.         }
  12731.         if (!getval) break;
  12732.         if ((rc = cmfld("Password","",&s,xxstring)) < 0)
  12733.           goto kerbx;
  12734.         makestr(&(pv[n].sval),s);
  12735.         break;
  12736.  
  12737.               case KRB_I_ADR:        /* /ADDRESSES:{<address-list>} */
  12738.         if (pv[n].sval) {
  12739.             free(pv[n].sval);
  12740.             pv[n].sval = NULL;
  12741.         }
  12742.         if (!getval) break;
  12743.         if ((rc = cmfld("List of IP addresses","",&s,xxstring)) < 0)
  12744.           goto kerbx;
  12745.         makelist(s,tmpaddrs,KRB5_NUM_OF_ADDRS);
  12746.         for (i = 0; i < KRB5_NUM_OF_ADDRS && tmpaddrs[i]; i++) {
  12747.             if (inet_addr(tmpaddrs[i]) == 0xffffffff) {
  12748.             printf("invalid ip address: %s\n",tmpaddrs[i]);
  12749.             rc = -9;
  12750.             goto kerbx;
  12751.             }
  12752.         }
  12753.         break;
  12754.  
  12755.           default:
  12756.         printf("?Unexpected switch value - internal error\n");
  12757.         rc = -9;
  12758.         goto kerbx;
  12759.         }
  12760.     }
  12761.     if (cmresult.fcode != _CMFLD) {
  12762.         printf("?Unexected result - internal error\n");
  12763.         rc = -9;
  12764.         goto kerbx;
  12765.     }
  12766.         /* cmresult.sresult may be of the form PRINCIPAL@REALM */
  12767.         i = ckindex("@",cmresult.sresult,0,0,0);
  12768.         if (i != 0) {
  12769.             makestr(&tmprealm,&cmresult.sresult[i]);
  12770.             cmresult.sresult[i-1] = '\0';
  12771.         }
  12772.     makestr(&tmpprinz,cmresult.sresult); /* Principal (user) */
  12773.  
  12774.     if ((rc = cmcfm()) < 0)    {    /* Now get confirmation */
  12775.             if (rc == -3) {
  12776. #ifdef IKSD
  12777.         if (inserver) {
  12778.             printf("?Sorry, command disabled\r\n");
  12779.             return(success = 0);
  12780.         }
  12781. #endif /* IKSD */
  12782.         printf("?Principal name required\n");
  12783.             }
  12784.             goto kerbx;
  12785.         }
  12786. #ifdef IKSD
  12787.         if (inserver) {
  12788.             printf("?Sorry, command disabled\r\n");
  12789.             return(success = 0);
  12790.         }
  12791. #endif /* IKSD */
  12792.         if (!tmpprinz || !tmpprinz[0]) {
  12793.             printf("?Principal name required\n");
  12794.             goto kerbx;
  12795.         }
  12796.         if (!pv[KRB_I_RN].ival && !pv[KRB_I_VA].ival) {
  12797.             /* Don't use a password if Validating or Renewing */
  12798.         if (pv[KRB_I_PW].sval) {    /* If they gave a /PASSWORD switch */
  12799.         makestr(&tmppswd,pv[KRB_I_PW].sval); /* use this value */
  12800.         } else {            /* Otherwise must prompt for it */
  12801.         char prmpt[80];
  12802.                 if (pv[KRB_I_RL].sval)
  12803.           sprintf(prmpt,"%s@%s's Password: ",
  12804.               tmpprinz,pv[KRB_I_RL].sval);
  12805.                 else if (tmprealm)
  12806.           sprintf(prmpt,"%s@%s's Password: ",
  12807.               tmpprinz,tmprealm);
  12808.                 else
  12809.           sprintf(prmpt,"%s's Password: ",tmpprinz);
  12810. #ifdef OS2
  12811.                 if (pv[KRB_I_POP].ival) {
  12812.                     char passwd[80]="";
  12813.                     readpass(prmpt,passwd,80);
  12814.                     makestr(&tmppswd,passwd);
  12815.                     memset(passwd,0,80);
  12816.                 } else {
  12817. #endif /* OS2 */
  12818. #ifdef CK_RECALL
  12819.             sv_recall = on_recall; /* Save & turn off command recall */
  12820.             on_recall = 0;
  12821. #endif /* CK_RECALL */
  12822.             cmsavp(psave,PROMPTL); /* Save old prompt */
  12823.             cmsetp(prmpt);    /* Make new prompt */
  12824.             concb((char)escape); /* Put console in cbreak mode */
  12825.             cmini(0);        /* and no-echo mode */
  12826.             /* Issue prompt if at top level */
  12827.             if (pflag) prompt(xxstring);
  12828.             cmres();        /* Reset the parser */
  12829.             for (rc = -1; rc < 0; ) { /* Prompt till they answer */
  12830.             /* Get a literal line of text */
  12831.             rc = cmtxt("","",&s,NULL);
  12832.             cmres();    /* Reset the parser again */
  12833.             }
  12834.             makestr(&tmppswd,s);
  12835. #ifdef CK_RECALL
  12836.             on_recall = sv_recall; /* Restore command recall */
  12837. #endif /* CK_RECALL */
  12838.             printf("\n");    /* Echo a CRLF */
  12839.             cmsetp(psave);    /* Restore original prompt */
  12840. #ifdef OS2
  12841.                 }
  12842. #endif /* OS2 */
  12843.         }
  12844.         x = 0;            /* Check for password */
  12845.         if (tmppswd)
  12846.           if (*tmppswd)
  12847.         x = 1;
  12848.         if (!x) {
  12849.         printf("?Password required\n");
  12850.         goto kerbx;
  12851.         }
  12852.         }
  12853.     } else if (kv == 5 && tmp_action == KRB_A_LC) { /* LIST-CREDENTIALS */
  12854.     tmp_klc = 0;
  12855.     while (1) {
  12856.         if ((x = cmkey(klctab,nklctab,"Switch","",xxstring)) < 0) {
  12857.         if (x == -3) {
  12858.             if ((rc = cmcfm()) < 0)
  12859.               goto kerbx;
  12860.             else
  12861.               break;
  12862.         } else {
  12863.             rc = x;
  12864.             goto kerbx;
  12865.         }
  12866.         }
  12867.         tmp_klc |= x;
  12868.     }
  12869.     } else if ((rc = cmcfm()) < 0)    /* DESTROY, just confirm */
  12870.     goto kerbx;
  12871.  
  12872. /* Done - Move confirmed data to final locations */
  12873.  
  12874.     krb_action = tmp_action;        /* Action requested */
  12875.     krb_op.version = kv;        /* Kerberos version */
  12876.     krb_op.cache = tmpcache;        /* Cache file */
  12877.     tmpcache = NULL;            /* So we don't free it */
  12878.  
  12879.     switch (krb_action) {
  12880.       case KRB_A_IN:            /* INITIALIZE */
  12881.         if (kv == 5) {
  12882.             krb5_init.forwardable = pv[KRB_I_FW].ival;
  12883.             krb5_init.proxiable   = pv[KRB_I_PR].ival;
  12884.             krb5_init.lifetime    = pv[KRB_I_LF].ival;
  12885.             krb5_init.renew       = pv[KRB_I_RN].ival;
  12886.             krb5_init.renewable   = pv[KRB_I_RB].ival;
  12887.             krb5_init.validate    = pv[KRB_I_VA].ival;
  12888.  
  12889.             /* Here we just reassign the pointers and then set them to NULL */
  12890.             /* so they won't be freed below. */
  12891.  
  12892.             krb5_init.postdate = pv[KRB_I_PD].sval; pv[KRB_I_PD].sval = NULL;
  12893.             krb5_init.service  = pv[KRB_I_SR].sval; pv[KRB_I_SR].sval = NULL;
  12894.         if (pv[KRB_I_RL].sval) {
  12895.         krb5_init.realm  = pv[KRB_I_RL].sval; pv[KRB_I_RL].sval = NULL;
  12896.             } else if (tmprealm) {
  12897.                 krb5_init.realm = tmprealm; tmprealm = NULL;
  12898.             }
  12899.             if (pv[KRB_I_IN].sval) {
  12900.                 krb5_init.instance = pv[KRB_I_IN].sval;
  12901.         pv[KRB_I_IN].sval = NULL;
  12902.             } else if ( tmpinst ) {
  12903.                 krb5_init.instance = tmpinst;
  12904.         tmpinst = NULL;
  12905.             }
  12906.             if (tmpprinz) {
  12907.                 krb5_init.principal = tmpprinz;
  12908.                 tmpprinz = NULL;
  12909.             }
  12910.             krb5_init.password = tmppswd;
  12911.             tmppswd = NULL;
  12912.  
  12913.             krb5_init.getk4 = pv[KRB_I_K4].ival;
  12914.             if (krb5_init.getk4) {
  12915.                 krb4_init.lifetime = pv[KRB_I_LF].ival;
  12916.                 if (krb5_init.realm)
  12917.                     makestr(&krb4_init.realm,krb5_init.realm);
  12918.                 krb4_init.preauth  = krb4_d_preauth;
  12919.                 krb4_init.verbose  = pv[KRB_I_BR].ival ? 0 : 1;
  12920.                 if (krb5_init.principal)
  12921.                     makestr(&krb4_init.principal,krb5_init.principal);
  12922.                 if (krb5_init.principal)
  12923.                     makestr(&krb4_init.password,krb5_init.password);
  12924.             }
  12925.         for (i = 0; i < KRB5_NUM_OF_ADDRS; i++) {
  12926.                 krb5_init.addrs[i] = tmpaddrs[i];
  12927.                 tmpaddrs[i] = NULL;
  12928.             }
  12929.     } else if (kv == 4) {        /* Same deal for Kerberos 4 */
  12930.             krb4_init.lifetime = pv[KRB_I_LF].ival;
  12931.         if (pv[KRB_I_RL].sval) {
  12932.         krb4_init.realm  = pv[KRB_I_RL].sval;
  12933.         pv[KRB_I_RL].sval = NULL;
  12934.             } else if ( tmprealm ) {
  12935.                 krb4_init.realm  = tmprealm;
  12936.         tmprealm = NULL;
  12937.             }
  12938.             if (pv[KRB_I_IN].sval) {
  12939.                 krb4_init.instance = pv[KRB_I_IN].sval;
  12940.         pv[KRB_I_IN].sval = NULL;
  12941.             } else if ( tmpinst ) {
  12942.                 krb4_init.instance = tmpinst;
  12943.         tmpinst = NULL;
  12944.             }
  12945.             krb4_init.preauth  = pv[KRB_I_PA].ival;
  12946.             krb4_init.verbose  = pv[KRB_I_BR].ival ? 0 : 1;
  12947.  
  12948.             if (tmpprinz) {
  12949.                 krb4_init.principal = tmpprinz;
  12950.                 tmpprinz = NULL;
  12951.             }
  12952.             krb4_init.password = tmppswd;
  12953.             tmppswd = NULL;
  12954.         }
  12955.     break;
  12956.       case KRB_A_LC:            /* List Credentials */
  12957.     krb5_lc.encryption = tmp_klc & XYKLCEN;
  12958.     krb5_lc.flags = tmp_klc & XYKLCFL;
  12959.     krb5_lc.addr  = tmp_klc & XYKLCAD;
  12960.     break;
  12961.     }
  12962.  
  12963. /* Common exit - Free temporary storage */
  12964.  
  12965.   kerbx:
  12966.     for (i = 0; i <= KRB_I_MAX; i++) {    /* Free malloc'd switch data */
  12967.     if (pv[i].sval)
  12968.       free(pv[i].sval);
  12969.     }
  12970.     for (i = 0; i < KRB5_NUM_OF_ADDRS; i++) {
  12971.         if (tmpaddrs[i])
  12972.       free(tmpaddrs[i]);
  12973.     }
  12974.     if (tmpprinz) free(tmpprinz);    /* And these too. */
  12975.     if (tmppswd)  free(tmppswd);
  12976.     if (tmpcache) free(tmpcache);
  12977.     if (tmprealm) free(tmprealm);
  12978.     if (tmpinst)  free(tmpinst);
  12979.  
  12980.     return(rc);                /* Return the return code */
  12981. }
  12982. #endif /* CK_KERBEROS */
  12983.  
  12984. #ifdef CK_LOGIN
  12985. int
  12986. #ifdef CK_ANSIC
  12987. ckxlogin(CHAR * userid, CHAR * passwd, CHAR * acct, int promptok)
  12988. #else /* CK_ANSIC */
  12989. ckxlogin(userid, passwd, acct, promptok)
  12990.   CHAR * userid; CHAR * passwd; CHAR * acct; int promptok;
  12991. #endif /* CK_ANSIC */
  12992. /* ckxlogin */ {
  12993. #ifdef CK_RECALL
  12994.     int sv_recall;            /* For turning off command recall */
  12995.     extern int on_recall;        /* around Password prompting */
  12996. #endif /* CK_RECALL */
  12997. #ifdef CK_PAM
  12998.     extern int guest;
  12999. #endif /* CK_PAM */
  13000.     int rprompt = 0;            /* Restore prompt */
  13001. #ifdef CKSYSLOG
  13002.     int savlog;
  13003. #endif /* CKSYSLOG */
  13004.  
  13005.     extern int what, srvcdmsg;
  13006.  
  13007.     int x = 0, ok = 0, rc = 0;
  13008.     CHAR * _u = NULL, * _p = NULL, * _a = NULL;
  13009.  
  13010.     debug(F111,"ckxlogin userid",userid,promptok);
  13011.     debug(F110,"ckxlogin passwd",passwd,0);
  13012.  
  13013.     isguest = 0;            /* Global "anonymous" flag */
  13014.  
  13015.     if (!userid) userid = (CHAR *)"";
  13016.     if (!passwd) passwd = (CHAR *)"";
  13017.  
  13018.     debug(F111,"ckxlogin userid",userid,what);
  13019.  
  13020. #ifdef CK_RECALL
  13021.     sv_recall = on_recall;        /* Save and turn off command recall */
  13022.     on_recall = 0;
  13023. #endif /* CK_RECALL */
  13024.  
  13025. #ifdef CKSYSLOG
  13026.     savlog = ckxsyslog;            /* Save and turn off syslogging */
  13027. #endif /* CKSYSLOG */
  13028.  
  13029.     if ((!*userid || !*passwd) &&    /* Need to prompt for missing info */
  13030.     promptok) {
  13031.         cmsavp(psave,PROMPTL);        /* Save old prompt */
  13032.     debug(F110,"ckxlogin saved",psave,0);
  13033.     rprompt = 1;
  13034.     }
  13035.     if (!*userid) {
  13036.     if (!promptok)
  13037.       return(0);
  13038.         cmsetp("Username: ");            /* Make new prompt */
  13039.         concb((char)escape);        /* Put console in cbreak mode */
  13040.         cmini(1);
  13041.  
  13042. /* Flush typeahead */
  13043.  
  13044. #ifdef IKS_OPTION
  13045.     debug(F101,
  13046.           "ckxlogin TELOPT_SB(TELOPT_KERMIT).kermit.me_start",
  13047.           "",
  13048.           TELOPT_SB(TELOPT_KERMIT).kermit.me_start
  13049.           );
  13050. #endif /* IKS_OPTION */
  13051.  
  13052.     while (ttchk() > 0) {
  13053.         x = ttinc(0);
  13054.         debug(F101,"ckxlogin flush user x","",x);
  13055. #ifdef TNCODE
  13056.         if (sstelnet) {
  13057.         if (x == IAC) {
  13058.             x = tn_doop((CHAR)(x & 0xff),ckxech,ttinc);
  13059.             debug(F101,"ckxlogin user tn_doop","",x);
  13060. #ifdef IKS_OPTION
  13061.             debug(F101,
  13062.               "ckxlogin user TELOPT_SB(TELOPT_KERMIT).kermit.me_start",
  13063.               "",
  13064.               TELOPT_SB(TELOPT_KERMIT).kermit.me_start
  13065.               );
  13066. #endif /* IKS_OPTION */
  13067.  
  13068.             if (x < 0)
  13069.               goto XCKXLOG;
  13070.             switch (x) {
  13071.               case 1: ckxech = 1; break; /* Turn on echoing */
  13072.               case 2: ckxech = 0; break; /* Turn off echoing */
  13073. #ifdef IKS_OPTION
  13074.               case 4:             /* IKS event */
  13075.             if (!TELOPT_SB(TELOPT_KERMIT).kermit.me_start)
  13076.               break;         /* else fall thru... */
  13077. #endif /* IKS_OPTION */
  13078.               case 6:             /* Logout */
  13079.             goto XCKXLOG;
  13080.             }
  13081.         }
  13082.         }
  13083. #endif /* TNCODE */
  13084.     }
  13085.         if (pflag) prompt(xxstring);    /* Issue prompt if at top level */
  13086.         cmres();            /* Reset the parser */
  13087.         for (x = -1; x < 0;) {        /* Prompt till they answer */
  13088.         /* Get a literal line of text */
  13089.             x=cmtxt("Your username, or \"ftp\", or \"anonymous\"","",&s,NULL);
  13090.             if (x == -4 || x == -10) {
  13091.                 printf("\r\nLogin cancelled\n");
  13092. #ifdef CKSYSLOG
  13093.         ckxsyslog = savlog;
  13094. #endif /* CKSYSLOG */
  13095.                 doexit(GOOD_EXIT,0);
  13096.             }
  13097.         if (sstate)            /* Did a packet come instead? */
  13098.           goto XCKXLOG;
  13099.             cmres();            /* Reset the parser again */
  13100.         }
  13101.         if ((_u = (CHAR *)malloc((int)strlen(s) + 1)) == NULL) {
  13102.             printf("?Internal error: malloc\n");
  13103.         goto XCKXLOG;
  13104.         } else {
  13105.             strcpy((char *)_u,s);
  13106.             userid = _u;
  13107.         }
  13108.     }
  13109.     ok = zvuser((char *)userid);    /* Verify username */
  13110.     debug(F111,"ckxlogin zvuser",userid,ok);
  13111.  
  13112.     if (!*passwd && promptok
  13113. #ifdef CK_PAM
  13114.     && guest
  13115. #endif /* CK_PAM */
  13116.     ) {
  13117.         char prmpt[80];
  13118.  
  13119. #ifdef CKSYSLOG
  13120.         savlog = ckxsyslog;        /* Save and turn off syslogging */
  13121.         ckxsyslog = 0;
  13122. #endif /* CKSYSLOG */
  13123.  
  13124. /* Flush typeahead again */
  13125.  
  13126.     while (ttchk() > 0) {
  13127.         x = ttinc(0);
  13128.         debug(F101,"ckxlogin flush user x","",x);
  13129. #ifdef TNCODE
  13130.         if (sstelnet) {
  13131.         if (x == IAC) {
  13132.             x = tn_doop((CHAR)(x & 0xff),ckxech,ttinc);
  13133.             debug(F101,"ckxlogin pass tn_doop","",x);
  13134. #ifdef IKS_OPTION
  13135.             debug(F101,
  13136.               "ckxlogin pass TELOPT_SB(TELOPT_KERMIT).kermit.me_start",
  13137.               "",
  13138.               TELOPT_SB(TELOPT_KERMIT).kermit.me_start
  13139.               );
  13140. #endif /* IKS_OPTION */
  13141.             if (x < 0)
  13142.               goto XCKXLOG;
  13143.             switch (x) {
  13144.               case 1: ckxech = 1; break; /* Turn on echoing */
  13145.               case 2: ckxech = 0; break; /* Turn off echoing */
  13146.               case 4:             /* IKS event */
  13147.             if (!TELOPT_SB(TELOPT_KERMIT).kermit.me_start)
  13148.               break;         /* else fall thru... */
  13149.               case 6:             /* Logout */
  13150.             goto XCKXLOG;
  13151.             }
  13152.         }
  13153.         }
  13154. #endif /* TNCODE */
  13155.     }
  13156.         if (!strcmp((char *)userid,"anonymous") ||
  13157.         !strcmp((char *)userid,"ftp") )
  13158.       sprintf(prmpt,"Enter e-mail address as Password: ");
  13159.         else if (*userid && strlen((char *)userid) < 60) {
  13160. #ifdef NT
  13161.             extern CHAR * pReferenceDomainName;
  13162.             if (pReferenceDomainName)
  13163.           sprintf(prmpt,"Enter %s\\\\%s's Password: ",
  13164.               pReferenceDomainName,userid);
  13165.             else
  13166. #endif /* NT */
  13167.           sprintf(prmpt,"Enter %s's Password: ",userid);
  13168.         } else
  13169.       sprintf(prmpt,"Enter Password: ");
  13170.     cmsetp(prmpt);            /* Make new prompt */
  13171.     concb((char)escape);        /* Put console in cbreak mode */
  13172.         if (strcmp((char *)userid,"anonymous") &&
  13173.         strcmp((char *)userid,"ftp") ) /* and if not anonymous */
  13174.       cmini(0);            /* and no-echo mode */
  13175.     else
  13176.       cmini(1);
  13177.     if (pflag) prompt(xxstring);    /* Issue prompt if at top level */
  13178.     cmres();            /* Reset the parser */
  13179.     for (x = -1; x < 0;) {        /* Prompt till they answer */
  13180.         x = cmtxt("","",&s,NULL);    /* Get a literal line of text */
  13181.             if (x == -4 || x == -10) {
  13182.                 printf("\r\nLogin cancelled\r\n");
  13183. #ifdef CKSYSLOG
  13184.         ckxsyslog = savlog;
  13185. #endif /* CKSYSLOG */
  13186.                 doexit(GOOD_EXIT,0);
  13187.             }
  13188.         if (sstate)            /* In case of a Kermit packet */
  13189.           goto XCKXLOG;
  13190.         cmres();            /* Reset the parser again */
  13191.     }
  13192.     printf("\r\n");            /* Echo a CRLF */
  13193.     if ((_p = (CHAR *)malloc((int)strlen(s) + 1)) == NULL) {
  13194.         printf("?Internal error: malloc\n");
  13195.         goto XCKXLOG;
  13196.     } else {
  13197.         strcpy((char *)_p,s);
  13198.         passwd = _p;
  13199.     }
  13200.     }
  13201. #ifdef CK_PAM
  13202.     else {
  13203.     cmres();            /* Reset the parser */
  13204.  
  13205.     /* We restore the prompt now because the PAM engine will call  */
  13206.     /* readpass() which will overwrite psave. */
  13207.     if (rprompt) {
  13208.         cmsetp(psave);        /* Restore original prompt */
  13209.         debug(F110,"ckxlogin restored",psave,0);
  13210.         rprompt = 0;
  13211.     }
  13212.     }
  13213. #endif /* CK_PAM */
  13214.  
  13215. #ifdef CKSYSLOG
  13216.     ckxsyslog = savlog;
  13217. #endif /* CKSYSLOG */
  13218.  
  13219.     if (ok) {
  13220.     ok = zvpass((char *)passwd);    /* Check password */
  13221.     debug(F101,"ckxlogin zvpass","",ok);
  13222.     }
  13223.  
  13224.     if (ok > 0 && isguest) {
  13225. #ifndef NOPUSH
  13226.     nopush = 1;
  13227. #endif /* NOPUSH */
  13228.     srvcdmsg = 1;
  13229.     }
  13230.     rc = ok;                /* Set the return code */
  13231.     if ((char *)uidbuf != (char *)userid)
  13232.       ckstrncpy(uidbuf,(char *)userid,UIDBUFLEN); /* Remember username */
  13233.  
  13234.   XCKXLOG:                /* Common exit */
  13235. #ifdef CK_RECALL
  13236.     on_recall = sv_recall;        /* Restore command recall */
  13237. #endif /* CK_RECALL */
  13238. #ifdef CKSYSLOG
  13239.     ckxsyslog = savlog;            /* In case of GOTO above */
  13240. #endif /* CKSYSLOG */
  13241.     if (rprompt) {
  13242.     cmsetp(psave);            /* Restore original prompt */
  13243.     debug(F110,"ckxlogin restored",psave,0);
  13244.     }
  13245.     if (_u || _p || _a) {
  13246.         if (_u) free(_u);
  13247.         if (_p) free(_p);
  13248.         if (_a) free(_a);
  13249.     }
  13250.     return(rc);
  13251. }
  13252.  
  13253. int
  13254. ckxlogout() {
  13255.     /* zvlogout(); */
  13256.     doexit(GOOD_EXIT,0);        /* doexit calls zvlogout */
  13257.     return(0);                /* not reached */
  13258. }
  13259. #endif /* CK_LOGIN */
  13260. #endif /* NOICP */
  13261.