home *** CD-ROM | disk | FTP | other *** search
/ kermit.columbia.edu / kermit.columbia.edu.tar / kermit.columbia.edu / tmp4 / ckuus7.c < prev    next >
C/C++ Source or Header  |  2009-11-15  |  532KB  |  15,276 lines

  1. #include "ckcsym.h"
  2.  
  3. /*  C K U U S 7 --  "User Interface" for C-Kermit, part 7  */
  4.  
  5. /*
  6.   Authors:
  7.     Frank da Cruz <fdc@columbia.edu>,
  8.       The Kermit Project, Columbia University, New York City
  9.     Jeffrey E Altman <jaltman@secure-endpoints.com>
  10.       Secure Endpoints Inc., New York City
  11.  
  12.   Copyright (C) 1985, 2009,
  13.     Trustees of Columbia University in the City of New York.
  14.     All rights reserved.  See the C-Kermit COPYING.TXT file or the
  15.     copyright text in the ckcmai.c module for disclaimer and permissions.
  16. */
  17.  
  18. /*
  19.   This file created from parts of ckuus3.c, which became too big for
  20.   Mark Williams Coherent compiler to handle.
  21. */
  22.  
  23. /*
  24.   Definitions here supersede those from system include files.
  25. */
  26. #include "ckcdeb.h"                     /* Debugging & compiler things */
  27. #include "ckcasc.h"                     /* ASCII character symbols */
  28. #include "ckcker.h"                     /* Kermit application definitions */
  29. #include "ckcxla.h"                     /* Character set translation */
  30. #include "ckcnet.h"                     /* Network symbols */
  31. #include "ckuusr.h"                     /* User interface symbols */
  32. #include "ckucmd.h"
  33. #include "ckclib.h"
  34.  
  35. #ifdef VMS
  36. #ifndef TCPSOCKET
  37. #include <errno.h>
  38. #endif /* TCPSOCKET */
  39. #endif /* VMS */
  40.  
  41. #ifdef OS2
  42. #ifndef NT
  43. #define INCL_NOPM
  44. #define INCL_VIO                        /* Needed for ckocon.h */
  45. #define INCL_DOSMODULEMGR
  46. #include <os2.h>
  47. #undef COMMENT
  48. #else /* NT */
  49. #define APIRET ULONG
  50. #include <windows.h>
  51. #include <tapi.h>
  52. #include "cknwin.h"
  53. #include "ckntap.h"
  54. #endif /* NT */
  55. #include "ckowin.h"
  56. #include "ckocon.h"
  57. #include "ckodir.h"
  58. #ifdef OS2MOUSE
  59. #include "ckokey.h"
  60. #endif /* OS2MOUSE */
  61. #ifdef KUI
  62. #include "ikui.h"
  63. #endif /* KUI */
  64. #ifdef putchar
  65. #undef putchar
  66. #endif /* putchar */
  67. #define putchar(x) conoc(x)
  68. extern int mskkeys;
  69. extern int mskrename;
  70. #endif /* OS2 */
  71.  
  72. #ifdef CK_AUTHENTICATION
  73. #include "ckuath.h"
  74. #endif /* CK_AUTHENTICATION */
  75. #ifdef CK_SSL
  76. #include "ck_ssl.h"
  77. #endif /* CK_SSL */
  78. #ifdef SSHBUILTIN
  79. #include "ckossh.h"
  80. #endif /* SSHBUILTIN */
  81. #ifdef STRATUS                          /* Stratus Computer, Inc.  VOS */
  82. #ifdef putchar
  83. #undef putchar
  84. #endif /* putchar */
  85. #define putchar(x) conoc(x)
  86. #ifdef getchar
  87. #undef getchar
  88. #endif /* getchar */
  89. #define getchar(x) coninc(0)
  90. #endif /* STRATUS */
  91.  
  92. char * slmsg = NULL;
  93.  
  94. static int x, y = 0, z;
  95. static char *s;
  96.  
  97. extern CHAR feol;
  98. extern int g_matchdot, hints, xcmdsrc, rcdactive;
  99.  
  100. extern char * k_info_dir;
  101.  
  102. #ifndef NOSPL
  103. extern int nmac;
  104. extern struct mtab *mactab;
  105. #endif /* NOSPL */
  106.  
  107. #ifndef NOXFER
  108. #ifdef CK_SPEED
  109. extern short ctlp[];                    /* Control-char prefixing table */
  110. #endif /* CK_SPEED */
  111.  
  112. #ifdef PIPESEND
  113. extern char * sndfilter, * g_sfilter;
  114. extern char * rcvfilter, * g_rfilter;
  115. #endif /* PIPESEND */
  116.  
  117. extern char * snd_move;
  118. extern char * snd_rename;
  119. extern char * g_snd_move;
  120. extern char * g_snd_rename;
  121. extern char * rcv_move;
  122. extern char * rcv_rename;
  123. extern char * g_rcv_move;
  124. extern char * g_rcv_rename;
  125.  
  126. #ifdef PATTERNS
  127. extern char *binpatterns[], *txtpatterns[];
  128. extern int patterns;
  129. #endif /* PATTERNS */
  130.  
  131. extern char * remdest;
  132. #ifdef CK_TMPDIR
  133. char * dldir = NULL;
  134. #endif /* CK_TMPDIR */
  135.  
  136. extern struct ck_p ptab[];
  137.  
  138. extern int protocol, remfile, rempipe, remappd, reliable, xreliable, fmask,
  139.   fncnv, frecl, maxrps, wslotr, bigsbsiz, bigrbsiz, urpsiz, rpsiz, spsiz,
  140.   bctr, npad, timef, timint, spsizr, spsizf, maxsps, spmax, nfils, displa,
  141.   atcapr, pkttim, rtimo, fncact, mypadn, fdispla, f_save, pktpaus, setreliable,
  142.   fnrpath, fnspath, atenci, atenco, atdati, atdato, atleni, atleno, atblki,
  143.   atblko, attypi, attypo, atsidi, atsido, atsysi, atsyso, atdisi, atdiso;
  144.  
  145. extern int stathack;
  146.  
  147. extern int atfrmi, atfrmo;
  148. #ifdef STRATUS
  149. extern int atcrei, atcreo, atacti, atacto;
  150. #endif /* STRATUS */
  151. #ifdef CK_PERMS
  152. extern int atlpri, atlpro, atgpri, atgpro;
  153. #endif /* CK_PERMS */
  154.  
  155. extern CHAR
  156.   sstate, eol, seol, stchr, mystch, mypadc, padch, ctlq, myctlq;
  157.  
  158. #ifdef IKSD
  159. extern int inserver;
  160. #ifdef IKSDCONF
  161. extern int iksdcf;
  162. #endif /* IKSDCONF */
  163. #endif /* IKSD */
  164.  
  165. extern char *cmarg, *cmarg2;
  166.  
  167. #ifndef NOFRILLS
  168. extern char optbuf[];                   /* Buffer for MAIL or PRINT options */
  169. extern int rprintf;                     /* REMOTE PRINT flag */
  170. #endif /* NOFRILLS */
  171. #endif /* NOXFER */
  172.  
  173. #ifdef CK_TRIGGER
  174. extern char * tt_trigger[];
  175. #endif /* CK_TRIGGER */
  176.  
  177. extern int tcs_transp;
  178. #ifdef PCTERM
  179. extern int tt_pcterm;
  180. #endif /* PCTERM */
  181. #ifdef NT
  182. extern int tt_vtnt;
  183. #endif /* NT */
  184.  
  185. #ifdef SSHBUILTIN
  186. int sl_ssh_xfw = 0;
  187. int sl_ssh_xfw_saved = 0;
  188. int sl_ssh_ver = 0;
  189. int sl_ssh_ver_saved = 0;
  190. #endif /* SSHBUILTIN */
  191.  
  192. #ifdef CK_AUTHENTICATION
  193. extern int auth_type_user[];
  194. int sl_auth_type_user[AUTHTYPLSTSZ] = {AUTHTYPE_NULL, AUTHTYPE_NULL};
  195. int sl_auth_saved = 0;
  196. int sl_topt_a_su = 0;
  197. int sl_topt_a_s_saved = 0;
  198. int sl_topt_a_cm = 0;
  199. int sl_topt_a_c_saved = 0;
  200. #endif /* CK_AUTHENTICATION */
  201. #ifdef CK_ENCRYPTION
  202. extern int cx_type;
  203. int sl_cx_type = 0;
  204. int sl_cx_saved = 0;
  205. int sl_topt_e_su = 0;
  206. int sl_topt_e_sm = 0;
  207. int sl_topt_e_s_saved = 0;
  208. int sl_topt_e_cu = 0;
  209. int sl_topt_e_cm = 0;
  210. int sl_topt_e_c_saved = 0;
  211. #endif /* CK_ENCRYPTION */
  212. extern char uidbuf[];
  213. static int uidflag = 0;
  214. char sl_uidbuf[UIDBUFLEN] = { NUL, NUL };
  215. int  sl_uid_saved = 0;
  216. #ifdef TNCODE
  217. int  sl_tn_wait = 0;
  218. int  sl_tn_saved = 0;
  219. #endif /* TNCODE */
  220.  
  221. #ifdef TNCODE
  222. extern int tn_wait_flg;
  223. #endif /* TNCODE */
  224.  
  225. VOID
  226. slrestor() {
  227. #ifdef CK_AUTHENTICATION
  228.     int x;
  229.     if (sl_auth_saved) {
  230.         for (x = 0; x < AUTHTYPLSTSZ; x++)
  231.           auth_type_user[x] = sl_auth_type_user[x];
  232.         sl_auth_saved = 0;
  233.     }
  234.     if (sl_topt_a_s_saved) {
  235.         TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = sl_topt_a_su;
  236.         sl_topt_a_s_saved = 0;
  237.     }
  238.     if (sl_topt_a_c_saved) {
  239.         TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = sl_topt_a_cm;
  240.         sl_topt_a_c_saved = 0;
  241.     }
  242. #endif /* CK_AUTHENTICATION */
  243. #ifdef CK_ENCRYPTION
  244.     if (sl_cx_saved) {
  245.         cx_type = sl_cx_type;
  246.         sl_cx_saved = 0;
  247.     }
  248.     if (sl_topt_e_s_saved) {
  249.         TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION)  = sl_topt_e_su;
  250.         TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION) = sl_topt_e_sm;
  251.         sl_topt_e_s_saved = 0;
  252.     }
  253.     if (sl_topt_e_c_saved) {
  254.         TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION)  = sl_topt_e_cu;
  255.         TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION) = sl_topt_e_cm;
  256.         sl_topt_e_c_saved = 0;
  257.     }
  258. #endif /* CK_ENCRYPTION */
  259.     if (sl_uid_saved) {
  260.         ckstrncpy(uidbuf,sl_uidbuf,UIDBUFLEN);
  261.         sl_uid_saved = 0;
  262.     }
  263. #ifdef TNCODE
  264.     if (sl_tn_saved) {
  265.         tn_wait_flg = sl_tn_wait;
  266.         sl_tn_saved = 0;
  267.     }
  268. #endif /* TNCODE */
  269. #ifdef SSHBUILTIN
  270.     if (sl_ssh_xfw_saved) {
  271.         ssh_xfw = sl_ssh_xfw;
  272.         sl_ssh_xfw_saved = 0;
  273.     }
  274.     if (sl_ssh_ver_saved) {
  275.         ssh_ver = sl_ssh_ver;
  276.         sl_ssh_ver_saved = 0;
  277.     }
  278. #endif /* SSHBUILTIN */
  279. }
  280.  
  281. int oldplex = -1;                       /* Duplex holder around network */
  282.  
  283. #ifndef NOICP
  284. #ifdef LOCUS
  285. extern int locus, autolocus;
  286. #endif /* LOCUS */
  287. #ifndef NODIAL
  288. extern int dialsta;
  289. #endif /* NODIAL */
  290.  
  291. /* Note: gcc -Wall wants braces around each keyword table entry. */
  292.  
  293. static struct keytab psltab[] = {       /* SET LINE/PORT command options */
  294.     { "/connect", SL_CNX, 0 },
  295. #ifdef OS2ORVMS
  296.     { "/noshare", SL_NSH, 0 },
  297. #endif /* OS2ORVMS */
  298.     { "/server",  SL_SRV, 0 },
  299. #ifdef OS2ORVMS
  300.     { "/share",   SL_SHR, 0 },
  301. #endif /* OS2ORVMS */
  302.     { "", 0, 0 }
  303. };
  304. static int npsltab = sizeof(psltab)/sizeof(struct keytab) - 1;
  305.  
  306. #ifdef NETCONN
  307. static struct keytab shtab[] = {        /* SET HOST command options */
  308. #ifdef NETCMD
  309.     /* (COMMAND is also a network type) */
  310.     { "/command",      SL_CMD,    CM_INV },
  311. #endif /* NETCMD */
  312.     { "/connect",      SL_CNX,    0 },
  313.     { "/network-type", SL_NET,    CM_ARG },
  314.     { "/nowait",       SL_NOWAIT, 0 },
  315. #ifndef NOSPL
  316. #ifdef CK_AUTHENTICATION
  317.     { "/password",     SL_PSW,    CM_ARG },
  318. #endif /* CK_AUTHENTICATION */
  319. #endif /* NOSPL */
  320. #ifdef NETCMD
  321.     { "/pipe",         SL_CMD,    0 },
  322. #endif /* NETCMD */
  323. #ifdef NETPTY
  324.     { "/pty",          SL_PTY,    0 },
  325. #endif /* NETPTY */
  326.     { "/server",       SL_SRV,    0 },
  327.     { "/timeout",      SL_TMO,    CM_ARG },
  328.     { "/userid",       SL_UID,    CM_ARG },
  329.     { "/wait",         SL_WAIT,   0 },
  330.     { "", 0, 0 }
  331. };
  332. static int nshtab = sizeof(shtab)/sizeof(struct keytab) - 1;
  333.  
  334. static struct keytab shteltab[] = {     /* TELNET command options */
  335. #ifdef CK_AUTHENTICATION
  336.     { "/auth",         SL_AUTH,   CM_ARG },
  337. #endif /* CK_AUTHENTICATION */
  338. #ifdef CK_ENCRYPTION
  339.     { "/encrypt",      SL_ENC,    CM_ARG },
  340. #endif /* CK_ENCRYPTION */
  341.     { "/nowait",       SL_NOWAIT, 0 },
  342. #ifndef NOSPL
  343. #ifdef CK_AUTHENTICATION
  344.     { "/password",     SL_PSW,    CM_ARG },
  345. #endif /* CK_AUTHENTICATION */
  346. #endif /* NOSPL */
  347.     { "/timeout",      SL_TMO,    CM_ARG },
  348.     { "/userid",       SL_UID,    CM_ARG },
  349.     { "/wait",         SL_WAIT,   0 },
  350.     { "", 0 ,0 }
  351. };
  352. static int nshteltab = sizeof(shteltab)/sizeof(struct keytab) - 1;
  353.  
  354. #ifdef RLOGCODE
  355. static struct keytab shrlgtab[] = {     /* SET HOST RLOGIN command options */
  356. #ifdef CK_KERBEROS
  357. #ifdef CK_ENCRYPTION
  358.     { "/encrypt",      SL_ENC, 0 },
  359. #endif /* CK_ENCRYPTION */
  360.     { "/k4",           SL_KRB4, CM_INV },
  361.     { "/k5",           SL_KRB5, CM_INV },
  362.     { "/kerberos4",    SL_KRB4, 0 },
  363.     { "/kerberos5",    SL_KRB5, 0 },
  364.     { "/kerberos_iv",  SL_KRB4, CM_INV },
  365.     { "/kerberos_v",   SL_KRB5, CM_INV },
  366.     { "/krb4",         SL_KRB4, CM_INV },
  367.     { "/krb5",         SL_KRB5, CM_INV },
  368. #endif /* CK_KERBEROS */
  369.     { "", 0 ,0 }
  370. };
  371. static int nshrlgtab = sizeof(shrlgtab)/sizeof(struct keytab)-1;
  372. #endif /* RLOGCODE */
  373.  
  374. extern struct keytab netcmd[];
  375. extern int nnets;
  376. #ifndef NODIAL
  377. extern int dirline;
  378. extern int nnetdir;                     /* Network services directory */
  379. extern char *netdir[];
  380. _PROTOTYP( VOID ndreset, (void) );
  381. char *nh_p[MAXDNUMS + 1];               /* Network directory entry pointers */
  382. char *nh_p2[MAXDNUMS + 1];              /* Network directory entry nettype */
  383. char *nh_px[4][MAXDNUMS + 1];           /* Network-specific stuff... */
  384. #endif /* NODIAL */
  385. int nhcount = 0;
  386. int ndinited = 0;
  387. char * n_name = NULL;                   /* Network name pointer */
  388. #endif /* NETCONN */
  389.  
  390. _PROTOTYP(int remtxt, (char **) );
  391. _PROTOTYP(VOID rmsg, (void) );
  392. _PROTOTYP(static int remcfm, (void) );
  393.  
  394. extern int nopush;
  395.  
  396. int mdmsav = -1;                        /* Save modem type around network */
  397. extern int isguest;                     /* Global flag for anonymous login */
  398.  
  399. extern xx_strp xxstring;
  400.  
  401. extern int success, binary, b_save, ckwarn, msgflg, quiet, cmask, pflag, local,
  402.   nettype, escape, mdmtyp, duplex, dfloc, network, cdtimo, autoflow, tnlm,
  403.   sosi, tlevel, lf_opts, backgrd, flow, debses, parity, ttnproto, ckxech,
  404.   x_ifnum, cmflgs, haveline, cxtype, cxflow[], maclvl;
  405.  
  406. #ifdef DCMDBUF
  407. extern struct cmdptr *cmdstk;           /* The command stack itself */
  408. #else
  409. extern struct cmdptr cmdstk[];          /* The command stack itself */
  410. #endif /* DCMDBUF */
  411. extern FILE * tfile[];
  412. extern char * macp[];
  413.  
  414. extern char psave[];                    /* For saving & restoring prompt */
  415. extern int sprmlen, rprmlen;
  416.  
  417. #ifdef OS2
  418. static struct keytab strmkeytab[] = {
  419.     { "clear",   0, 0 },
  420.     { "default", 1, 0 }
  421. };
  422. static int nstrmkeytab = sizeof(strmkeytab)/sizeof(struct keytab);
  423.  
  424. static struct keytab strmswitab[] = {
  425.     { "/literal", 0, 0 }
  426. };
  427. static int nstrmswitab = sizeof(strmswitab)/sizeof(struct keytab);
  428.  
  429. static struct keytab normrev[] = {
  430.     { "dark-display", 0, 0 },
  431.     { "light-display", 1, 0 },
  432.     { "normal",   0, 0 },
  433.     { "reverse",  1, 0 }
  434. };
  435.  
  436. static struct keytab prnmtab[] = {
  437.     { "auto", 1, 0 },
  438.     { "copy", 2, 0 },
  439.     { "off",  0, 0 },
  440.     { "on",   1, CM_INV },              /* Compatibility with XPRINT version */
  441.     { "user", 3, 0 },
  442.     { "transparent", 3, CM_INV }        /* not really transparent */
  443. };
  444. static int nprnmtab = sizeof(prnmtab)/sizeof(struct keytab);
  445.  
  446. extern int tt_diff_upd;
  447.  
  448. #ifdef NT
  449. #define stricmp _stricmp
  450. extern int tt_attr_bug;
  451. #endif /* NT */
  452. extern int tt_rows[], tt_cols[];
  453. extern int tt_cols_usr;
  454. extern int tt_szchng[VNUM];
  455. int tt_modechg = TVC_ENA;
  456. extern int tt_url_hilite, tt_url_hilite_attr;
  457. extern struct _vtG G[4];
  458. extern int priority;
  459. extern bool send_c1;
  460. int send_c1_usr = FALSE;
  461. extern int sgrcolors;
  462. extern int marginbell, marginbellcol;
  463. extern int autoscroll, wy_autopage;
  464. extern int tt_sac;
  465. extern int dec_nrc, dec_lang, dec_kbd;
  466. #else /* OS2 */
  467. extern int tt_rows, tt_cols;
  468. #endif /*  OS2 */
  469.  
  470. extern int tt_escape;
  471. extern long speed;
  472.  
  473. extern char *dftty;
  474.  
  475. extern char *tp, *lp;                   /* Temporary buffer & pointers */
  476. extern char ttname[];
  477.  
  478. #ifdef CK_TAPI
  479. int tttapi = 0;                         /* is Line TAPI? */
  480. struct keytab * tapilinetab = NULL;
  481. struct keytab * _tapilinetab = NULL;
  482. int ntapiline = 0;
  483. #endif /* CK_TAPI */
  484.  
  485. #ifdef NETCONN                          /* Network items */
  486.  
  487. #ifdef ANYX25
  488. extern int revcall, closgr, cudata, nx25;
  489. extern char udata[];
  490. extern struct keytab x25tab[];
  491. #ifndef IBMX25
  492. extern int npadx3;
  493. extern CHAR padparms[];
  494. extern struct keytab padx3tab[];
  495. #endif /* IBMX25 */
  496. #endif /* ANYX25 */
  497.  
  498. #ifdef OS2
  499. extern bool ttshare;
  500. #ifndef NT
  501. extern bool ttslip,ttppp;
  502. #endif /* NT */
  503. #endif /* OS2 */
  504. #ifdef NPIPE
  505. extern char pipename[];
  506. #endif /* NPIPE */
  507.  
  508. #ifdef TCPSOCKET
  509. static struct keytab tcprawtab[] = {    /* SET HOST options */
  510.     { "/default",    NP_DEFAULT,    CM_INV },
  511. #ifdef CK_AUTHENTICATION
  512. #ifdef CK_KERBEROS
  513. #ifdef RLOGCODE
  514.     { "/ek4login",    NP_EK4LOGIN,    0 },
  515.     { "/ek5login",    NP_EK5LOGIN,    0 },
  516.     { "/k4login",     NP_K4LOGIN,     0 },
  517.     { "/k5login",     NP_K5LOGIN,     0 },
  518. #endif /* RLOGCODE */
  519. #ifdef KRB5_U2U
  520.     { "/k5user2user", NP_K5U2U,       0 },
  521. #endif /* KRB5_U2U */
  522. #endif /* CK_KERBEROS */
  523. #endif /* CK_AUTHENTICATION */
  524.     { "/no-telnet-init", NP_NONE,   0 },
  525.     { "/none",       NP_NONE,   CM_INV },
  526.     { "/raw-socket", NP_TCPRAW, 0 },
  527. #ifdef RLOGCODE
  528.     { "/rlogin",     NP_RLOGIN, 0 },
  529. #endif /* RLOGCODE */
  530. #ifdef CK_SSL
  531.     { "/ssl",        NP_SSL,    0 },
  532.     { "/ssl-raw",    NP_SSL_RAW, 0 },
  533.     { "/ssl-telnet", NP_SSL_TELNET, 0 },
  534. #endif /* CK_SSL */
  535.     { "/telnet",     NP_TELNET, 0 },
  536. #ifdef CK_SSL
  537.     { "/tls",        NP_TLS,    0 },
  538.     { "/tls-raw",    NP_TLS_RAW, 0 },
  539.     { "/tls-telnet", NP_TLS_TELNET, 0 },
  540. #endif /* CK_SSL */
  541.     { "", 0, 0 }
  542. };
  543. static int ntcpraw = (sizeof(tcprawtab) / sizeof(struct keytab)) - 1;
  544.  
  545. #ifdef RLOGCODE
  546. _PROTOTYP( int rlog_naws, (void) );
  547. #endif /* RLOGCODE */
  548. #endif /* TCPSOCKET */
  549.  
  550. #ifdef SUPERLAT
  551. extern char slat_pwd[18];
  552. #endif /* SUPERLAT */
  553. #endif /* NETCONN */
  554.  
  555. #ifdef COMMENT
  556. #ifndef NOSETKEY
  557. extern KEY *keymap;
  558. #ifndef OS2
  559. #define mapkey(x) keymap[x]
  560. #endif /* OS2 */
  561. extern MACRO *macrotab;
  562. #ifndef NOKVERBS
  563. extern struct keytab kverbs[];
  564. extern int nkverbs;
  565. #endif /* NOKVERBS */
  566. #endif /* NOSETKEY */
  567. #else
  568. #ifndef NOSETKEY
  569. extern KEY *keymap;
  570. extern MACRO *macrotab;
  571. #ifndef NOKVERBS
  572. extern struct keytab kverbs[];
  573. extern int nkverbs;
  574. #endif /* NOKVERBS */
  575. #endif /* NOSETKEY */
  576. #endif /* COMMENT */
  577.  
  578. #ifdef OS2                              /* AUTODOWNLOAD parameters */
  579. extern int    adl_kmode, adl_zmode;     /* Match Packet to signal download */
  580. extern char * adl_kstr;                 /* KERMIT Download String */
  581. extern char * adl_zstr;                 /* ZMODEM Download String */
  582. extern int adl_kc0, adl_zc0;            /* Process ADL C0s in emulation */
  583. #endif /* OS2 */
  584.  
  585. /* Keyword tables ... */
  586.  
  587. extern struct keytab onoff[], rltab[];
  588. extern int nrlt;
  589.  
  590. #ifndef NOCSETS
  591. static struct keytab fdfltab[] = {
  592.     { "7bit-character-set", 7, 0 },
  593.     { "8bit-character-set", 8, 0 }
  594. };
  595. static int nfdflt = (sizeof(fdfltab) / sizeof(struct keytab));
  596. #endif /* NOCSETS */
  597.  
  598. /* SET FILE parameters */
  599.  
  600. static struct keytab filtab[] = {
  601. #ifndef NOXFER
  602. #ifdef PATTERNS
  603.     { "binary-patterns",   XYFIBP,  0 },
  604. #endif /* PATTERNS */
  605.     { "bytesize",         XYFILS,   0 },
  606. #ifndef NOCSETS
  607.     { "character-set",    XYFILC,   0 },
  608. #endif /* NOCSETS */
  609.     { "collision",        XYFILX,   0 },
  610.     { "default",          XYF_DFLT, 0 },
  611.     { "destination",      XYFILY,   0 },
  612.     { "display",          XYFILD,   CM_INV },
  613. #ifdef CK_TMPDIR
  614.     { "download-directory", XYFILG, 0 },
  615. #endif /* CK_TMPDIR */
  616. #endif /* NOXFER */
  617.     { "end-of-line",      XYFILA,   0 },
  618.     { "eol",              XYFILA,   CM_INV },
  619. #ifdef CK_CTRLZ
  620.     { "eof",              XYFILV,   0 },
  621. #endif /* CK_CTRLZ */
  622. #ifndef NOXFER
  623.     { "fastlookups",      9997,     CM_INV },
  624.     { "incomplete",       XYFILI,   0 },
  625. #ifndef datageneral
  626.     { "inspection",       XYF_INSP, CM_INV },
  627. #endif /* datageneral */
  628. #ifdef CK_LABELED
  629.     { "label",            XYFILL, 0 },
  630. #endif /* CK_LABELED */
  631.  
  632. #ifdef UNIX
  633. #ifdef DYNAMIC
  634.     { "listsize",         XYF_LSIZ, 0 },
  635. #endif /* DYNAMIC */
  636. #endif /* UNIX */
  637.  
  638.     { "names",            XYFILN, 0 },
  639. #ifdef UNIX
  640.     { "output",           XYFILH, 0 },
  641. #endif /* UNIX */
  642. #ifdef PATTERNS
  643.     { "patterns",         XYFIPA, 0 },
  644. #endif /* PATTERNS */
  645. #ifdef COMMENT /* Not implemented (but see CHMOD) */
  646.     { "permissions",      XYF_PRM, CM_INV },
  647.     { "protection",       XYF_PRM, 0 },
  648. #endif /* COMMENt */
  649. #ifdef VMS
  650.     { "record-length",    XYFILR, 0 },
  651. #endif /* VMS */
  652. #ifndef datageneral
  653.     { "scan",             XYF_INSP, 0 },
  654. #endif /* datageneral */
  655.  
  656. #ifdef UNIX
  657. #ifdef DYNAMIC
  658.     { "stringspace",      XYF_SSPA, 0 },
  659. #endif /* DYNAMIC */
  660. #endif /* UNIX */
  661.  
  662. #ifdef PATTERNS
  663.     { "t",                XYFILT, CM_INV|CM_ABR },
  664.     { "text-patterns",    XYFITP, 0 },
  665. #endif /* PATTERNS */
  666. #endif /* NOXFER */
  667.     { "type",             XYFILT, 0 },
  668. #ifdef UNICODE
  669.     { "ucs",              XYFILU, 0 },
  670. #endif /* UNICODE */
  671. #ifndef NOXFER
  672.     { "warning",          XYFILW, CM_INV }
  673. #endif /* NOXFER */
  674. };
  675. static int nfilp = (sizeof(filtab) / sizeof(struct keytab));
  676.  
  677. struct keytab pathtab[] = {
  678.     { "absolute",  PATH_ABS,  0      },
  679.     { "none",      PATH_OFF,  CM_INV },
  680.     { "off",       PATH_OFF,  0      },
  681.     { "on",        PATH_ABS,  CM_INV },
  682.     { "relative",  PATH_REL,  0      }
  683. };
  684. int npathtab = (sizeof(pathtab) / sizeof(struct keytab));
  685.  
  686. struct keytab rpathtab[] = {
  687.     { "absolute",  PATH_ABS,  0      },
  688.     { "auto",      PATH_AUTO, 0      },
  689.     { "none",      PATH_OFF,  CM_INV },
  690.     { "off",       PATH_OFF,  0      },
  691.     { "on",        PATH_ABS,  CM_INV },
  692.     { "relative",  PATH_REL,  0      }
  693. };
  694. int nrpathtab = (sizeof(rpathtab) / sizeof(struct keytab));
  695.  
  696. #ifdef CK_CTRLZ
  697. struct keytab eoftab[] = {              /* EOF detection method */
  698.     { "ctrl-z",          1, 0      },
  699.     { "length",          0, 0      },
  700.     { "noctrl-z",        0, CM_INV }
  701. };
  702. #endif /* CK_CTRLZ */
  703.  
  704. struct keytab fttab[] = {               /* File types for SET FILE TYPE */
  705.     { "ascii",     XYFT_T, CM_INV },
  706. #ifdef VMS
  707.     { "b",         XYFT_B, CM_INV|CM_ABR },
  708. #endif /* VMS */
  709.     { "binary",    XYFT_B, 0 },
  710. #ifdef VMS
  711.     { "block",     XYFT_I, CM_INV },
  712.     { "image",     XYFT_I, 0 },
  713. #endif /* VMS */
  714. #ifdef CK_LABELED
  715.     { "labeled",   XYFT_L, 0 },
  716. #endif /* CK_LABELED */
  717. #ifdef MAC
  718.     { "macbinary", XYFT_M, 0 },
  719. #endif /* MAC */
  720.     { "text",      XYFT_T, 0 }
  721. };
  722. int nfttyp = (sizeof(fttab) / sizeof(struct keytab));
  723.  
  724. static struct keytab rfttab[] = {       /* File types for REMOTE SET FILE */
  725.     { "ascii",     XYFT_T, CM_INV },
  726.     { "binary",    XYFT_B, 0 },
  727. #ifdef VMS
  728.     { "labeled",   XYFT_L, 0 },
  729. #else
  730. #ifdef OS2
  731.     { "labeled",   XYFT_L, 0 },
  732. #endif /* OS2 */
  733. #endif /* VMS */
  734.     { "text",      XYFT_T, 0 }
  735. };
  736. static int nrfttyp = (sizeof(rfttab) / sizeof(struct keytab));
  737.  
  738. #ifdef OS2ORUNIX
  739. #define ZOF_BLK  0
  740. #define ZOF_NBLK 1
  741. #define ZOF_BUF  2
  742. #define ZOF_NBUF 3
  743. static struct keytab zoftab[] = {
  744.     { "blocking",    ZOF_BLK,  0 },
  745.     { "buffered",    ZOF_BUF,  0 },
  746.     { "nonblocking", ZOF_NBLK, 0 },
  747.     { "unbuffered",  ZOF_NBUF, 0 }
  748. };
  749. static int nzoftab = (sizeof(zoftab) / sizeof(struct keytab));
  750. #endif /* OS2ORUNIX */
  751.  
  752. extern int query;                       /* Global flag for QUERY active */
  753.  
  754. #ifndef NOSPL
  755. #ifndef NOXFER
  756. static struct keytab vartyp[] = {       /* Variable types for REMOTE QUERY */
  757.     { "global",   (int) 'G', CM_INV },
  758.     { "kermit",   (int) 'K', 0 },
  759.     { "system",   (int) 'S', 0 },
  760.     { "user",     (int) 'G', 0 }
  761. };
  762. static int nvartyp = (sizeof(vartyp) / sizeof(struct keytab));
  763. #endif /* NOXFER */
  764. #endif /* NOSPL */
  765.  
  766. #ifdef CK_TIMERS
  767. static struct keytab timotab[] = {      /* Timer types */
  768.     { "dynamic", 1, 0 },
  769.     { "fixed",   0, 0 }
  770. };
  771. #endif /* CK_TIMERS */
  772.  
  773. #ifdef DCMDBUF
  774. extern char *atxbuf, *atmbuf;           /* Atom buffer */
  775. extern char *cmdbuf;                    /* Command buffer */
  776. extern char *line, *tmpbuf;             /* Character buffers for anything */
  777. extern int *intime;                     /* INPUT TIMEOUT */
  778.  
  779. #else  /* Not DCMDBUF ... */
  780.  
  781. extern char atxbuf[], atmbuf[];         /* Atom buffer */
  782. extern char cmdbuf[];                   /* Command buffer */
  783. extern char line[], tmpbuf[];           /* Character buffer for anything */
  784. extern int intime[];
  785.  
  786. #endif /* DCMDBUF */
  787.  
  788. #ifndef NOCSETS
  789. extern struct keytab fcstab[];          /* For SET FILE CHARACTER-SET */
  790. extern struct csinfo fcsinfo[];         /* File character set info. */
  791. extern struct keytab ttcstab[];
  792. extern int nfilc, fcharset, tcharset, ntermc, tcsr, tcsl, dcset7, dcset8;
  793. #ifdef CKOUNI
  794. extern int tt_utf8;
  795. #endif /* CKOUNI */
  796. #ifdef OS2
  797. _PROTOTYP( int os2setcp, (int) );
  798. _PROTOTYP( int os2getcp, (void) );
  799. _PROTOTYP( void os2debugoff, (void) );
  800. #endif /* OS2 */
  801. #endif /* NOCSETS */
  802.  
  803. extern int cmdlvl;                      /* Overall command level */
  804.  
  805. #ifndef NOSPL
  806. #ifdef DCMDBUF
  807. extern int *inpcas;                     /* INPUT CASE setting on cmd stack */
  808. #else
  809. extern int inpcas[];
  810. #endif /* DCMDBUF */
  811. #endif /* NOSPL */
  812.  
  813. #ifdef CK_CURSES
  814. #ifndef VMS
  815. _PROTOTYP(int tgetent,(char *, char *));
  816. #else
  817. #ifdef __DECC
  818. _PROTOTYP(int tgetent,(char *, char *));
  819. #endif /* __DECC */
  820. #endif /* VMS */
  821. #endif /* CK_CURSES */
  822.  
  823. #ifndef NOXMIT
  824. #define XMITF 0                         /* SET TRANSMIT values */
  825. #define XMITL 1                         /* (Local to this module) */
  826. #define XMITP 2
  827. #define XMITE 3
  828. #define XMITX 4
  829. #define XMITS 5
  830. #define XMITW 6
  831. #define XMITT 7
  832.  
  833. #define XMBUFL 50
  834. extern int xmitf, xmitl, xmitp, xmitx, xmits, xmitw, xmitt;
  835. char xmitbuf[XMBUFL+1] = { NUL };       /* TRANSMIT eof string */
  836.  
  837. struct keytab xmitab[] = {              /* SET TRANSMIT */
  838.     { "echo",          XMITX, 0 },
  839.     { "eof",           XMITE, 0 },
  840.     { "fill",          XMITF, 0 },
  841.     { "linefeed",      XMITL, 0 },
  842.     { "locking-shift", XMITS, 0 },
  843.     { "pause",         XMITW, 0 },
  844.     { "prompt",        XMITP, 0 },
  845.     { "timeout",       XMITT, 0 }
  846. };
  847. int nxmit = (sizeof(xmitab) / sizeof(struct keytab));
  848. #endif /* NOXMIT */
  849.  
  850. /* For SET FILE COLLISION */
  851. /* Some of the following may be possible for some C-Kermit implementations */
  852. /* but not others.  Those that are not possible for your implementation */
  853. /* should be ifdef'd out. */
  854.  
  855. struct keytab colxtab[] = { /* SET FILE COLLISION options */
  856. #ifndef MAC
  857.     { "append",    XYFX_A, 0 },         /* append to old file */
  858. #endif /* MAC */
  859. #ifdef COMMENT
  860.     { "ask",       XYFX_Q, 0 },         /* ask what to do (not implemented) */
  861. #endif
  862.     { "backup",    XYFX_B, 0 },         /* rename old file */
  863. #ifndef MAC
  864.     /* This crashes Mac Kermit. */
  865.     { "discard",   XYFX_D, CM_INV },    /* don't accept new file */
  866.     { "no-supersede", XYFX_D, CM_INV }, /* ditto (MSK compatibility) */
  867. #endif /* MAC */
  868.     { "overwrite", XYFX_X, 0 },         /* overwrite the old file */
  869.     { "reject",    XYFX_D, 0 },        /* (better word than discard) */
  870.     { "rename",    XYFX_R, 0 },         /* rename the incoming file */
  871. #ifndef MAC                             /* This crashes Mac Kermit. */
  872.     { "update",    XYFX_U, 0 },         /* replace if newer */
  873. #endif /* MAC */
  874.     { "", 0, 0 }
  875. };
  876. int ncolx = (sizeof(colxtab) / sizeof(struct keytab)) - 1;
  877.  
  878. static struct keytab rfiltab[] = {      /* for REMOTE SET FILE */
  879. #ifndef NOCSETS
  880.     { "character-set", XYFILC, 0 },
  881. #endif /* NOCSETS */
  882.     { "collision",     XYFILX, 0 },
  883.     { "incomplete",    XYFILI, 0 },
  884.     { "names",         XYFILN, 0 },
  885.     { "record-length", XYFILR, 0 },
  886.     { "type",          XYFILT, 0 }
  887. };
  888. int nrfilp = (sizeof(rfiltab) / sizeof(struct keytab));
  889.  
  890. struct keytab eoltab[] = {              /* File eof delimiters */
  891.     { "cr",        XYFA_C, 0 },
  892.     { "crlf",      XYFA_2, 0 },
  893.     { "lf",        XYFA_L, 0 }
  894. };
  895. static int neoltab = (sizeof(eoltab) / sizeof(struct keytab));
  896.  
  897. struct keytab fntab[] = {               /* File naming */
  898.     { "converted", XYFN_C, 0      },
  899.     { "literal",   XYFN_L, 0      },
  900.     { "standard",  XYFN_C, CM_INV }
  901. };
  902. int nfntab = (sizeof(fntab) / sizeof(struct keytab));
  903.  
  904. #ifndef NOLOCAL
  905. /* Terminal parameters table */
  906. static struct keytab trmtab[] = {
  907. #ifdef OS2
  908.     { "answerback",    XYTANS,    0 },
  909. #endif /* OS2 */
  910. #ifdef CK_APC
  911.     { "apc",           XYTAPC,    0 },
  912. #endif /* CK_APC */
  913. #ifdef OS2
  914.     { "arrow-keys",    XYTARR,    0 },
  915. #endif /* OS2 */
  916. #ifdef NT
  917.     { "at",            XYTATTR,   CM_INV|CM_ABR },
  918.     { "att",           XYTATTR,   CM_INV|CM_ABR },
  919.     { "attr",          XYTATTR,   CM_INV|CM_ABR },
  920.     { "attr-bug",      XYTATTBUG, CM_INV },
  921. #endif /* NT */
  922. #ifdef OS2
  923.     { "attribute",     XYTATTR,   0 },
  924. #endif /* OS2 */
  925. #ifdef CK_APC
  926. #ifdef CK_AUTODL
  927.    { "autodownload",   XYTAUTODL, 0, },
  928. #endif /* CK_AUTODL */
  929. #endif /* CK_APC */
  930. #ifdef OS2
  931.     { "autopage",      XYTAPAGE,  0 },
  932.     { "autoscroll",    XYTASCRL,  0 },
  933.     { "bell",          XYTBEL,    CM_INV },
  934. #endif /* OS2 */
  935.     { "bytesize",      XYTBYT,    0 },
  936. #ifndef NOCSETS
  937.     { "character-set", XYTCS,     0 },
  938. #endif /* NOCSETS */
  939. #ifdef OS2
  940.     { "code-page",     XYTCPG,    0 },
  941.     { "color",         XYTCOL,    0 },
  942.     { "controls",      XYTCTRL,   0 },
  943. #endif /* OS2 */
  944.     { "cr-display",    XYTCRD,    0 },
  945. #ifdef OS2
  946.     { "cursor",        XYTCUR,    0 },
  947. #endif /* OS2 */
  948.     { "debug",         XYTDEB,    0 },
  949. #ifdef OS2
  950.     { "dg-unix-mode",  XYTUNX,    0 },
  951. #endif /* OS2 */
  952.     { "echo",          XYTEC,     0 },
  953.     { "escape-character", XYTESC, 0 },
  954. #ifdef OS2
  955. #ifdef PCFONTS
  956.     { "font",          XYTFON,    0 },
  957. #else
  958. #ifdef KUI
  959.     { "font",          XYTFON,    0 },
  960. #endif /* KUI */
  961. #endif /* PCFONTS */
  962. #endif /* OS2 */
  963.     { "height",        XYTHIG,    0 },
  964. #ifdef CKTIDLE
  965.     { "idle-action",   XYTIACT,   0 },
  966.     { "idle-limit",    XYTITMO,   CM_INV },
  967.     { "idle-send",     XYTIDLE,   CM_INV },
  968.     { "idle-timeout",  XYTITMO,   0 },
  969. #endif /* CKTIDLE */
  970. #ifdef OS2
  971. #ifndef NOCSETS
  972.     { "kbd-follows-gl/gr", XYTKBDGL, 0 },
  973. #endif /* NOCSETS */
  974.     { "key",           XYTKEY,    0 },
  975.     { "keyboard-mode", XYTKBMOD,  0 },
  976.     { "keypad-mode",   XYTKPD,    0 },
  977. #endif /* OS2 */
  978.     { "lf-display",    XYTLFD,    0 },
  979. #ifndef NOCSETS
  980. #ifdef OS2
  981. #ifndef KUI
  982.     { "line-spacing",  XYTLSP,    CM_INV },
  983.     { "local-character-set", XYTLCS,  0 },
  984. #else
  985.     { "line-spacing",  XYTLSP,    0 },
  986.     { "local-character-set", XYTLCS,  CM_INV },
  987. #endif /* KUI */
  988. #else
  989.     { "local-character-set", XYTLCS,  CM_INV },
  990. #endif /* OS2 */
  991. #endif /* NOCSETS */
  992.     { "locking-shift", XYTSO,     0 },
  993. #ifdef OS2
  994.     { "margin-bell",   XYTMBEL,   0 },
  995. #endif /* OS2 */
  996. #ifdef OS2MOUSE
  997.     { "mouse",         XYTMOU,    CM_INV },
  998. #endif /* OS2MOUSE */
  999.     { "newline-mode",  XYTNL,     0 },
  1000. #ifdef OS2
  1001.     { "output-pacing", XYTPAC,    0 },
  1002. #ifdef PCTERM
  1003.     { "pcterm",        XYTPCTERM, 0 },
  1004. #endif /* PCTERM */
  1005. #endif /* OS2 */
  1006. #ifdef OS2ORUNIX
  1007.     { "print",         XYTPRN,    0 },
  1008. #endif /* OS2ORUNIX */
  1009. #ifndef NOCSETS
  1010. #ifdef OS2
  1011.     { "remote-character-set", XYTRCS,  0 },
  1012. #else
  1013.     { "remote-character-set", XYTRCS,  CM_INV },
  1014. #endif /* OS2 */
  1015. #endif /* NOCSETS */
  1016. #ifdef OS2
  1017.     { "roll-mode",       XYTROL, 0 },
  1018.     { "s",               XYTUPD, CM_ABR|CM_INV },
  1019.     { "sc",              XYTUPD, CM_ABR|CM_INV },
  1020.     { "scr",             XYTUPD, CM_ABR|CM_INV },
  1021.     { "scree",           XYTUPD, CM_ABR|CM_INV },
  1022.     { "screen",          XYTUPD, CM_ABR|CM_INV },
  1023.     { "screen-",         XYTUPD, CM_ABR|CM_INV },
  1024.     { "screen-mode",     XYTSCNM,   0 },
  1025.     { "screen-optimize", XYTOPTI,   0 },
  1026.     { "screen-update",   XYTUPD,    0 },
  1027.     { "scrollback",      XYSCRS,    0 },
  1028.     { "send-data",         XYTSEND, 0 },
  1029.     { "send-end-of-block", XYTSEOB, 0 },
  1030.     { "sgr-colors",            XYTSGRC,  0 },
  1031.     { "sni-ch.code",           XYTSNICC, 0 },
  1032.     { "sni-firmware-versions", XYTSNIFV, 0 },
  1033.     { "sni-language",          XYTVTLNG, 0 },
  1034.     { "sni-pagemode",          XYTSNIPM, CM_INV },
  1035.     { "sni-scrollmode",              XYTSNISM, CM_INV },
  1036.     { "spacing-attribute-character", XYTSAC,   CM_INV },
  1037.     { "statusline",                  XYTSTAT,  0 },
  1038.     { "tra",                         XYTCTS,   CM_INV|CM_ABR },
  1039.     { "transmit-timeout",            XYTCTS,   0 },
  1040. #endif /* OS2 */
  1041.  
  1042. #ifdef OS2ORUNIX
  1043.     { "transparent-print", XYTPRN,   CM_INV },
  1044. #endif /* OS2ORUNIX */
  1045.  
  1046. #ifdef CK_TRIGGER
  1047.     { "trigger",           XYTRIGGER,0 },
  1048. #endif /* CK_TRIGGER */
  1049. #ifdef OS2
  1050.     { "type",              XYTTYP,   0 },
  1051. #else
  1052.     { "type",              XYTTYP,   CM_INV },
  1053. #endif /* OS2 */
  1054.  
  1055. #ifndef NOCSETS
  1056. #ifdef UNICODE
  1057. #ifdef CKOUNI
  1058.     { "unicode",           XYTUNI,   CM_INV },
  1059. #endif /* CKOUNI */
  1060. #endif /* UNICODE */
  1061. #endif /* NOCSETS */
  1062. #ifdef OS2
  1063.     { "unix-mode",         XYTUNX,   CM_INV },
  1064.     { "url-highlight",     XYTURLHI, 0 },
  1065. #ifdef NT
  1066.     { "video-change",      XYTVCH,   0 },
  1067. #endif /* NT */
  1068.     { "vt-language",       XYTVTLNG, 0 },
  1069.     { "vt-nrc-mode",       XYTVTNRC, 0 },
  1070. #endif /* OS2 */
  1071.     { "width",             XYTWID,   0 },
  1072. #ifdef OS2
  1073.     { "wrap",              XYTWRP,   0 },
  1074. #endif /* OS2 */
  1075.     { "", 0, 0 }
  1076. };
  1077. int ntrm = (sizeof(trmtab) / sizeof(struct keytab)) - 1;
  1078.  
  1079. #ifdef OS2
  1080. struct keytab termctrl[] = {    /* SET TERM CONTROLS */
  1081.     { "7",      7, 0 },
  1082.     { "8",      8, 0 }
  1083. };
  1084. int ntermctrl = (sizeof(termctrl) / sizeof(struct keytab));
  1085.  
  1086. struct keytab curontab[] = {    /* SET TERM CURSOR */
  1087. #ifdef KUI
  1088.     { "noblink", 2, 0 },
  1089. #else
  1090.     { "noblink", 2, CM_INV },
  1091. #endif /* KUI */
  1092.     { "off",     0, 0 },
  1093.     { "on",      1, 0 }
  1094. };
  1095. int ncuron = (sizeof(curontab) / sizeof(struct keytab));
  1096.  
  1097. struct keytab rolltab[] = {   /* Set TERM Roll Options */
  1098.     { "insert",    TTR_INSERT, 0      },
  1099.     { "keystrokes",TTR_KEYS,   0      },
  1100.     { "off",       TTR_OVER,   CM_INV },
  1101.     { "on",        TTR_INSERT, CM_INV },
  1102.     { "overwrite", TTR_OVER,   0      }
  1103. };
  1104. int nroll = (sizeof(rolltab) / sizeof(struct keytab));
  1105.  
  1106. struct keytab rollkeytab[] = {        /* Set TERM ROLL KEYSTROKES */
  1107.     { "ignore",            TTRK_IGN, 0 },
  1108.     { "restore-and-send",  TTRK_RST, 0 },
  1109.     { "send",              TTRK_SND, 0 }
  1110. };
  1111. int nrollkey = (sizeof(rollkeytab) / sizeof(struct keytab));
  1112.  
  1113. #define TT_GR_ALL 4
  1114. #define TT_GR_G0  0
  1115. #define TT_GR_G1  1
  1116. #define TT_GR_G2  2
  1117. #define TT_GR_G3  3
  1118. #define TT_GR_KBD 4
  1119. struct keytab graphsettab[] = {  /* DEC VT Graphic Sets */
  1120.     { "all",      TT_GR_ALL, 0 },
  1121.     { "g0",       TT_GR_G0,  0 },
  1122.     { "g1",       TT_GR_G1,  0 },
  1123.     { "g2",       TT_GR_G2,  0 },
  1124.     { "g3",       TT_GR_G3,  0 },
  1125.     { "keyboard", TT_GR_KBD, 0 }
  1126. };
  1127. int ngraphset = (sizeof(graphsettab) / sizeof(struct keytab));
  1128. #endif /* OS2 */
  1129.  
  1130. struct keytab adltab[] = {              /* Autodownload Options */
  1131.     { "ask",     TAD_ASK, 0 },
  1132.     { "error",   TAD_ERR, 0 },
  1133. #ifdef OS2
  1134.     { "kermit",  TAD_K,   0 },
  1135. #endif /* OS2 */
  1136.     { "off",     TAD_OFF, 0 },
  1137.     { "on",      TAD_ON,  0 },
  1138. #ifdef OS2
  1139.     { "zmodem",  TAD_Z,   0 },
  1140. #endif /* OS2 */
  1141.     { "", 0, 0 }
  1142. };
  1143. int nadltab = (sizeof(adltab) / sizeof(struct keytab)) - 1;
  1144.  
  1145. struct keytab adlerrtab[] = {           /* Autodownload Error Options */
  1146.     { "continue", 0, 0 },
  1147.     { "go",       0, CM_INV },
  1148.     { "stop",     1, 0 }
  1149. };
  1150. int nadlerrtab = (sizeof(adlerrtab) / sizeof(struct keytab));
  1151.  
  1152. #ifdef OS2
  1153. struct keytab adlxtab[] = {             /* Autodownload Options */
  1154.     { "c0-conflicts",     TAD_X_C0,     0 },
  1155.     { "detection-method", TAD_X_DETECT, 0 },
  1156.     { "string",           TAD_X_STR,    0 }
  1157. };
  1158. int nadlxtab = (sizeof(adlxtab) / sizeof(struct keytab));
  1159.  
  1160. struct keytab adldtab[] = {             /* Auto-dl Detection Methods */
  1161.     { "packet",           ADL_PACK,     0 },
  1162.     { "string",           ADL_STR,      0 }
  1163. };
  1164. int nadldtab = (sizeof(adldtab) / sizeof(struct keytab));
  1165.  
  1166. struct keytab adlc0tab[] = {            /* Auto-dl Detection Methods */
  1167.     { "ignored-by-emulator",    0,      0 },
  1168.     { "processed-by-emulator",  1,      0 }
  1169. };
  1170. int nadlc0tab = (sizeof(adlc0tab) / sizeof(struct keytab));
  1171.  
  1172. #ifndef NOCSETS
  1173. struct keytab vtlangtab[] = {
  1174.     { "belgian",        VTL_BELGIAN , 0 },
  1175.     { "british",        VTL_BRITISH , 0 },
  1176.     { "canadian",       VTL_CANADIAN, 0 },
  1177.     { "czech",          VTL_CZECH   , 0 },
  1178.     { "danish",         VTL_DANISH  , 0 },
  1179.     { "dutch",          VTL_DUTCH   , 0 },
  1180.     { "finnish",        VTL_FINNISH , 0 },
  1181.     { "french",         VTL_FRENCH  , 0 },
  1182.     { "french-canadian",VTL_FR_CAN  , 0 },
  1183.     { "german",         VTL_GERMAN  , 0 },
  1184.     { "greek",          VTL_GREEK   , 0 },
  1185.     { "hebrew",         VTL_HEBREW  , 0 },
  1186.     { "hungarian",      VTL_HUNGARIA, 0 },
  1187.     { "italian",        VTL_ITALIAN , 0 },
  1188.     { "latin-american", VTL_LATIN_AM, 0 },
  1189.     { "north-american", VTL_NORTH_AM, 0 },
  1190.     { "norwegian",      VTL_NORWEGIA, 0 },
  1191.     { "polish",         VTL_POLISH  , 0 },
  1192.     { "portugese",      VTL_PORTUGES, 0 },
  1193.     { "romanian",       VTL_ROMANIAN, 0 },
  1194.     { "russian",        VTL_RUSSIAN , 0 },
  1195.     { "scs",            VTL_SCS     , CM_INV },
  1196.     { "slovak",         VTL_SLOVAK  , 0 },
  1197.     { "spanish",        VTL_SPANISH , 0 },
  1198.     { "swedish",        VTL_SWEDISH , 0 },
  1199.     { "swiss-french",   VTL_SW_FR   , 0 },
  1200.     { "swiss-german",   VTL_SW_GR   , 0 },
  1201.     { "turkish-f",      VTL_TURK_F  , CM_INV },
  1202.     { "turkish-q",      VTL_TURK_Q  , CM_INV }
  1203. };
  1204. int nvtlangtab = (sizeof(vtlangtab) / sizeof(struct keytab));
  1205. #endif /* NOCSETS */
  1206. #endif /* OS2 */
  1207.  
  1208. struct keytab crdtab[] = {              /* Carriage-return display */
  1209.     { "crlf",        1, 0 },
  1210.     { "normal",      0, 0 }
  1211. };
  1212. extern int tt_crd;                      /* Carriage-return display variable */
  1213. extern int tt_lfd;            /* Linefeed display variable */
  1214.  
  1215. #ifdef CK_APC
  1216. extern int apcstatus, apcactive;
  1217. static struct keytab apctab[] = {       /* Terminal APC parameters */
  1218.     {  "no-input", APC_ON|APC_NOINP,0 },
  1219.     { "off",       APC_OFF,  0 },
  1220.     { "on",        APC_ON,   0 },
  1221.     { "unchecked", APC_ON|APC_UNCH, 0 },
  1222.     { "unchecked-no-input", APC_ON|APC_NOINP|APC_UNCH, 0 }
  1223. };
  1224. int napctab = (sizeof(apctab) / sizeof(struct keytab));
  1225. #endif /* CK_APC */
  1226. #endif /* NOLOCAL */
  1227.  
  1228. extern int autodl, adl_err, adl_ask;
  1229.  
  1230. struct keytab beltab[] = {              /* Terminal bell mode */
  1231. #ifdef OS2
  1232.     { "audible", XYB_AUD,  0 },
  1233.     { "none",    XYB_NONE, 0 },
  1234. #else
  1235.     { "audible", XYB_AUD,  CM_INV },
  1236.     { "none",    XYB_NONE, CM_INV },
  1237. #endif /* OS2 */
  1238. #ifdef OS2
  1239.     { "off",     XYB_NONE, CM_INV },
  1240.     { "on",      XYB_AUD,  CM_INV },
  1241. #else
  1242.     { "off",     XYB_NONE, 0 },
  1243.     { "on",      XYB_AUD,  0 },
  1244. #endif /* OS2 */
  1245. #ifdef OS2
  1246.     { "visible", XYB_VIS,  0 },
  1247. #endif /* OS2 */
  1248.     { "", 0, 0 }
  1249. };
  1250. int nbeltab = sizeof(beltab)/sizeof(struct keytab) - 1;
  1251.  
  1252. int tt_unicode = 1;                     /* Use Unicode if possible */
  1253. #ifdef CKTIDLE
  1254. int tt_idlesnd_tmo = 0;                 /* Idle Send Timeout, disabled */
  1255. char * tt_idlesnd_str = NULL;           /* Idle Send String, none */
  1256. char * tt_idlestr = NULL;
  1257. extern int tt_idleact, tt_idlelimit;
  1258. #endif /* CKTIDLE */
  1259.  
  1260. #ifdef OS2
  1261. #ifndef NOLOCAL
  1262. /*
  1263.   OS/2 serial communication devices.
  1264. */
  1265. struct keytab os2devtab[] = {
  1266.     { "1",    1, CM_INV },                      /* Invisible synonyms, like */
  1267.     { "2",    2, CM_INV },                      /* "set port 1" */
  1268.     { "3",    3, CM_INV },
  1269.     { "4",    4, CM_INV },
  1270.     { "5",    5, CM_INV },
  1271.     { "6",    6, CM_INV },
  1272.     { "7",    7, CM_INV },
  1273.     { "8",    8, CM_INV },
  1274.     { "com1", 1, 0 },                   /* Real device names */
  1275.     { "com2", 2, 0 },
  1276.     { "com3", 3, 0 },
  1277.     { "com4", 4, 0 },
  1278.     { "com5", 5, 0 },
  1279.     { "com6", 6, 0 },
  1280.     { "com7", 7, 0 },
  1281.     { "com8", 8, 0 },
  1282. #ifdef OS2ONLY
  1283.     { "slipcom1", 1, 0 },                       /* For use with SLIP driver */
  1284.     { "slipcom2", 2, 0 },                       /* shared access */
  1285.     { "slipcom3", 3, 0 },
  1286.     { "slipcom4", 4, 0 },
  1287.     { "slipcom5", 5, 0 },
  1288.     { "slipcom6", 6, 0 },
  1289.     { "slipcom7", 7, 0 },
  1290.     { "slipcom8", 8, 0 },
  1291.     { "pppcom1", 1, 0 },                        /* For use with PPP driver */
  1292.     { "pppcom2", 2, 0 },                        /* shared access */
  1293.     { "pppcom3", 3, 0 },
  1294.     { "pppcom4", 4, 0 },
  1295.     { "pppcom5", 5, 0 },
  1296.     { "pppcom6", 6, 0 },
  1297.     { "pppcom7", 7, 0 },
  1298.     { "pppcom8", 8, 0 }
  1299. #endif /* OS2ONLY */
  1300. };
  1301. int nos2dev = (sizeof(os2devtab) / sizeof(struct keytab)) - 1;
  1302.  
  1303. #ifdef OS2ONLY
  1304. struct keytab os2ppptab[] = {
  1305.     { "0",    0, CM_INV },
  1306.     { "1",    1, CM_INV },                      /* Invisible synonyms, like */
  1307.     { "2",    2, CM_INV },                      /* "set port 1" */
  1308.     { "3",    3, CM_INV },
  1309.     { "4",    4, CM_INV },
  1310.     { "5",    5, CM_INV },
  1311.     { "6",    6, CM_INV },
  1312.     { "7",    7, CM_INV },
  1313.     { "8",    8, CM_INV },
  1314.     { "9",    9, CM_INV },
  1315.     { "ppp0", 0, 0 },
  1316.     { "ppp1", 1, 0 },                   /* For use with PPP driver */
  1317.     { "ppp2", 2, 0 },                   /* shared access */
  1318.     { "ppp3", 3, 0 },
  1319.     { "ppp4", 4, 0 },
  1320.     { "ppp5", 5, 0 },
  1321.     { "ppp6", 6, 0 },
  1322.     { "ppp7", 7, 0 },
  1323.     { "ppp8", 8, 0 },
  1324.     { "ppp9", 9, 0 }
  1325. };
  1326. int nos2ppp = (sizeof(os2ppptab) / sizeof(struct keytab));
  1327. #endif /* OS2ONLY */
  1328.  
  1329. /*
  1330.   Terminal parameters that can be set by SET commands.
  1331.   Used by the ck?con.c terminal emulator code.
  1332.   For now, only used for #ifdef OS2.  Should add these for Macintosh.
  1333. */
  1334. int tt_arrow = TTK_NORM;                /* Arrow key mode: normal (cursor) */
  1335. int tt_keypad = TTK_NORM;               /* Keypad mode: normal (numeric) */
  1336. int tt_shift_keypad = 0;                /* Keypad Shift mode: Off */
  1337. int tt_wrap = 1;                        /* Terminal wrap, 1 = On */
  1338. int tt_type = TT_VT220;                 /* Terminal type, initially VT220 */
  1339. int tt_type_mode = TT_VT220;            /* Terminal type set by host command */
  1340. int tt_cursor = 0;                      /* Terminal cursor, 0 = Underline */
  1341. int tt_cursor_usr = 0;                  /* Users Terminal cursor type */
  1342. int tt_cursorena_usr = 1;               /* Users Terminal cursor enabled */
  1343. int tt_cursor_blink = 1;                /* Terminal Cursor Blink */
  1344. int tt_answer = 0;                      /* Terminal answerback (disabled) */
  1345. int tt_scrsize[VNUM] = {512,512,512,1}; /* Terminal scrollback buffer size */
  1346. int tt_roll[VNUM] = {1,1,1,1};          /* Terminal roll (on) */
  1347. int tt_rkeys[VNUM] = {1,1,1,1};        /* Terminal roll keys (send) */
  1348. int tt_pacing = 0;                      /* Terminal output-pacing (none) */
  1349. int tt_ctstmo = 15;                     /* Terminal transmit-timeout */
  1350. int tt_codepage = -1;                   /* Terminal code-page */
  1351. int tt_update = 100;                    /* Terminal screen-update interval */
  1352. int tt_updmode = TTU_FAST;              /* Terminal screen-update mode FAST */
  1353. extern int updmode;
  1354. #ifndef KUI
  1355. int tt_status[VNUM] = {1,1,0,0};        /* Terminal status line displayed */
  1356. int tt_status_usr[VNUM] = {1,1,0,0};
  1357. #else  /* KUI */
  1358. extern CKFLOAT floatval;
  1359. CKFLOAT tt_linespacing[VNUM] = {1.0,1.0,1.0,1.0};
  1360. #ifdef K95G
  1361. int tt_status[VNUM] = {1,1,0,0};        /* Terminal status line displayed */
  1362. int tt_status_usr[VNUM] = {1,1,0,0};
  1363. #else /* K95G */
  1364. int tt_status[VNUM] = {0,0,0,0};        /* Terminal status line displayed */
  1365. int tt_status_usr[VNUM] = {0,0,0,0};
  1366. #endif /* K95G */
  1367. #endif /* KUI */
  1368. int tt_senddata = 0;                    /* Let host read terminal data */
  1369. extern int wy_blockend;                 /* Terminal Send Data EOB type */
  1370. int tt_hidattr = 1;                     /* Attributes are hidden */
  1371.  
  1372. extern unsigned char colornormal, colorselect,
  1373. colorunderline, colorstatus, colorhelp, colorborder,
  1374. colorgraphic, colordebug, colorreverse, coloritalic;
  1375.  
  1376. extern int trueblink, trueunderline, truereverse, trueitalic, truedim;
  1377.  
  1378. extern int bgi, fgi;
  1379. extern int scrninitialized[];
  1380.  
  1381. struct keytab audibletab[] = {          /* Terminal Bell Audible mode */
  1382.     { "beep",          XYB_BEEP, 0 },   /* Values ORd with bell mode */
  1383.     { "system-sounds", XYB_SYS,  0 }
  1384. };
  1385. int naudibletab = sizeof(audibletab)/sizeof(struct keytab);
  1386.  
  1387. struct keytab akmtab[] = {              /* Arrow key mode */
  1388.     { "application", TTK_APPL, 0 },
  1389.     { "cursor",      TTK_NORM, 0 }
  1390. };
  1391. struct keytab kpmtab[] = {              /* Keypad mode */
  1392.     { "application", TTK_APPL, 0 },
  1393.     { "numeric",     TTK_NORM, 0 }
  1394. };
  1395.  
  1396. struct keytab ttcolmodetab[] = {
  1397.     { "current-color", 0, 0 },
  1398.     { "default-color", 1, 0 }
  1399. };
  1400. int ncolmode = sizeof(ttcolmodetab)/sizeof(struct keytab);
  1401.  
  1402. #define TTCOLNOR  0
  1403. #define TTCOLREV  1
  1404. #define TTCOLUND  2
  1405. #define TTCOLSTA  3
  1406. #define TTCOLHLP  4
  1407. #define TTCOLBOR  5
  1408. #define TTCOLSEL  6
  1409. #define TTCOLDEB  7
  1410. #define TTCOLGRP  8
  1411. #define TTCOLITA  9
  1412. #define TTCOLRES  10
  1413. #define TTCOLERA  11
  1414.  
  1415. struct keytab ttycoltab[] = {                   /* Terminal Screen coloring */
  1416.     { "border",             TTCOLBOR, 0 },      /* Screen border color */
  1417.     { "debug-terminal",     TTCOLDEB, 0 },      /* Debug color */
  1418.     { "erase",              TTCOLERA, 0 },      /* Erase mode */
  1419.     { "graphic",            TTCOLGRP, 0 },      /* Graphic Color */
  1420.     { "help-text",          TTCOLHLP, 0 },      /* Help screens */
  1421.     { "italic",             TTCOLITA, 0 },      /* Italic Color */
  1422.     { "normal",             TTCOLNOR, CM_INV }, /* Normal screen text */
  1423.     { "reset-on-esc[0m",    TTCOLRES, 0 },      /* Reset on ESC [ 0 m */
  1424.     { "reverse-video",      TTCOLREV, 0 },      /* Reverse video */
  1425.     { "status-line",        TTCOLSTA, 0 },      /* Status line */
  1426.     { "selection",          TTCOLSEL, 0 },      /* Selection color */
  1427.     { "terminal-screen",    TTCOLNOR, 0 },      /* Better name than "normal" */
  1428.     { "underlined-text",    TTCOLUND, 0 }       /* Underlined text */
  1429. };
  1430. int ncolors = (sizeof(ttycoltab) / sizeof(struct keytab));
  1431.  
  1432. #define TTATTNOR  0
  1433. #define TTATTBLI  1
  1434. #define TTATTREV  2
  1435. #define TTATTUND  3
  1436. #define TTATTPRO  4
  1437. #define TTATTBLD  5
  1438. #define TTATTDIM  6
  1439. #define TTATTINV  7
  1440. #define TTATTITA  8
  1441. #define TTATTDONE 9
  1442.  
  1443. struct keytab ttyattrtab[] = {
  1444.     { "blink",     TTATTBLI, 0 },
  1445.     { "dim",       TTATTDIM, 0 },
  1446.     { "italic",    TTATTITA, 0 },
  1447.     { "protected", TTATTPRO, 0 },
  1448.     { "reverse",   TTATTREV, 0 },
  1449.     { "underline", TTATTUND, 0 }
  1450. };
  1451. int nattrib = (sizeof(ttyattrtab) / sizeof(struct keytab));
  1452.  
  1453. struct keytab ttyprotab[] = {
  1454.     { "blink",       TTATTBLI,  0 },
  1455.     { "bold",        TTATTBLD,  0 },
  1456.     { "dim",         TTATTDIM,  0 },
  1457.     { "done",        TTATTDONE, CM_INV },
  1458.     { "invisible",   TTATTINV,  0 },
  1459.     { "italic",      TTATTITA,  0 },
  1460.     { "normal",      TTATTNOR,  0 },
  1461.     { "reverse",     TTATTREV,  0 },
  1462.     { "underlined",  TTATTUND,  0 }
  1463.  
  1464. };
  1465. int nprotect = (sizeof(ttyprotab) / sizeof(struct keytab));
  1466.  
  1467. struct keytab ttyseobtab[] = {
  1468.     { "crlf_etx",  1, 0 },
  1469.     { "us_cr",     0, 0 }
  1470. };
  1471.  
  1472. struct keytab ttyclrtab[] = {           /* Colors */
  1473.     { "black",         0, 0      },
  1474.     { "blue",          1, 0      },
  1475.     { "brown",         6, 0      },
  1476.     { "cyan",          3, 0      },
  1477.     { "darkgray",      8, CM_INV },
  1478.     { "dgray",         8, 0      },
  1479.     { "green",         2, 0      },
  1480.     { "lblue",         9, CM_INV },
  1481.     { "lcyan",        11, CM_INV },
  1482.     { "lgray",         7, CM_INV },
  1483.     { "lgreen",       10, CM_INV },
  1484.     { "lightblue",     9, 0      },
  1485.     { "lightcyan",    11, 0      },
  1486.     { "lightgray",     7, 0      },
  1487.     { "lightgreen",   10, 0      },
  1488.     { "lightmagenta", 13, 0      },
  1489.     { "lightred",     12, 0      },
  1490.     { "lmagenta",     13, CM_INV },
  1491.     { "lred",         12, CM_INV },
  1492.     { "magenta",       5, 0      },
  1493.     { "red",           4, 0      },
  1494.     { "white",        15, 0      },
  1495.     { "yellow",       14, 0      }
  1496. };
  1497. int nclrs = (sizeof (ttyclrtab) / sizeof (struct keytab));
  1498.  
  1499. struct keytab ttycurtab[] = {
  1500.     { "full",        TTC_BLOCK, 0 },
  1501.     { "half",        TTC_HALF,  0 },
  1502.     { "underline",   TTC_ULINE, 0 }
  1503. };
  1504. int ncursors = 3;
  1505.  
  1506. struct keytab ttyptab[] = {
  1507.     { "aaa",      TT_AAA,     CM_INV },     /* AnnArbor */
  1508.     { "adm3a",    TT_ADM3A,   0 },          /* LSI ADM-3A */
  1509.     { "adm5",     TT_ADM5,    0 },          /* LSI ADM-5 */
  1510.     { "aixterm",  TT_AIXTERM, 0 },          /* IBM AIXterm */
  1511.     { "annarbor", TT_AAA,     0 },          /* AnnArbor */
  1512.     { "ansi-bbs", TT_ANSI,    0 },          /* ANSI.SYS (BBS) */
  1513.     { "at386",    TT_AT386,   0 },          /* Unixware ANSI */
  1514.     { "avatar/0+",TT_ANSI,    0 },          /* AVATAR/0+ */
  1515.     { "ba80",     TT_BA80,    0 },          /* Nixdorf BA80 */
  1516.     { "be",       TT_BEOS,    CM_INV|CM_ABR },
  1517.     { "beos-ansi",TT_BEOS,    CM_INV },     /* BeOS ANSI */
  1518.     { "beterm",   TT_BEOS,    0 },          /* BeOS Terminal (as of PR2 ) */
  1519.     { "d200",     TT_DG200,   CM_INV|CM_ABR }, /* Data General DASHER 200 */
  1520.     { "d210",     TT_DG210,   CM_INV|CM_ABR }, /* Data General DASHER 210 */
  1521.     { "d217",     TT_DG217,   CM_INV|CM_ABR }, /* Data General DASHER 217 */
  1522.     { "dg200",    TT_DG200,   0 },          /* Data General DASHER 200 */
  1523.     { "dg210",    TT_DG210,   0 },          /* Data General DASHER 210 */
  1524.     { "dg217",    TT_DG217,   0 },          /* Data General DASHER 217 */
  1525.     { "h1500",    TT_HZL1500, CM_INV },     /* Hazeltine 1500 */
  1526.     { "h19",      TT_H19,     CM_INV },     /* Heath-19 */
  1527.     { "heath19",  TT_H19,     0 },          /* Heath-19 */
  1528.     { "hft",      TT_HFT,     0 },          /* IBM High Function Terminal */
  1529.     { "hp2621a",  TT_HP2621,  0 },          /* HP 2621A */
  1530.     { "hpterm",   TT_HPTERM,  0 },          /* HP TERM */
  1531.     { "hz1500",   TT_HZL1500, 0 },          /* Hazeltine 1500 */
  1532.     { "ibm3151",  TT_IBM31,   0 },          /* IBM 3101-xx,3161 */
  1533.     { "linux",    TT_LINUX,   0 },          /* Linux */
  1534.     { "qansi",    TT_QANSI,   0 },          /* QNX ANSI */
  1535.     { "qnx",      TT_QNX,     0 },          /* QNX Console */
  1536.     { "scoansi",  TT_SCOANSI, 0 },          /* SCO ANSI */
  1537.     { "sni-97801",TT_97801,   0 },          /* SNI 97801 */
  1538.     { "sun",      TT_SUN,     0 },          /* SUN Console */
  1539. /*
  1540.   The idea of NONE is to let the console driver handle the escape sequences,
  1541.   which, in theory at least, would give not only ANSI emulation, but also any
  1542.   other kind of emulation that might be provided by alternative console
  1543.   drivers, if any existed.
  1544.  
  1545.   For this to work, ckocon.c would need to be modified to make higher-level
  1546.   calls, like VioWrtTTY(), DosWrite(), or (simply) write(), rather than
  1547.   VioWrt*Cell() and similar, and it would also have to give up its rollback
  1548.   feature, and its status line and help screens would also have to be
  1549.   forgotten or else done in an ANSI way.
  1550.  
  1551.   As matters stand, we already have perfectly good ANSI emulation built in,
  1552.   and there are no alternative console drivers available, so there is no point
  1553.   in having a terminal type of NONE, so it is commented out.  However, should
  1554.   you uncomment it, it will work like a "glass tty" -- no escape sequence
  1555.   interpretation at all; somewhat similar to debug mode, except without the
  1556.   debugging (no highlighting of control chars or escape sequences); help
  1557.   screens, status line, and rollback will still work.
  1558. */
  1559. #ifdef OS2PM
  1560. #ifdef COMMENT
  1561.     { "tek4014", TT_TEK40,  0 },
  1562. #endif /* COMMENT */
  1563. #endif /* OS2PM */
  1564.     { "tty",     TT_NONE,   0 },
  1565.     { "tvi910+", TT_TVI910, 0 },
  1566.     { "tvi925",  TT_TVI925, 0 },
  1567.     { "tvi950",  TT_TVI950, 0 },
  1568.     { "vc404",   TT_VC4404, 0 },
  1569.     { "vc4404",  TT_VC4404, CM_INV },
  1570.     { "vip7809", TT_VIP7809,0 },
  1571.     { "vt100",   TT_VT100,  0 },
  1572.     { "vt102",   TT_VT102,  0 },
  1573.     { "vt220",   TT_VT220,  0 },
  1574.     { "vt220pc", TT_VT220PC,0 },
  1575.     { "vt320",   TT_VT320,  0 },
  1576.     { "vt320pc", TT_VT320PC,0 },
  1577.     { "vt52",    TT_VT52,   0 },
  1578. #ifdef NT
  1579.     { "vtnt",    TT_VTNT,   0 },
  1580. #else /* NT */
  1581.     { "vtnt",    TT_VTNT,  CM_INV },
  1582. #endif /* NT */
  1583.     { "wy160",   TT_WY160,  0 },
  1584.     { "wy30",    TT_WY30,   0 },
  1585.     { "wy370",   TT_WY370,  0 },
  1586.     { "wy50",    TT_WY50,   0 },
  1587.     { "wy60",    TT_WY60,   0 },
  1588.     { "wyse30",  TT_WY30,   CM_INV },
  1589.     { "wyse370", TT_WY370,  CM_INV },
  1590.     { "wyse50",  TT_WY50,   CM_INV },
  1591.     { "wyse60",  TT_WY60,   CM_INV }
  1592. };
  1593. int nttyp = (sizeof(ttyptab) / sizeof(struct keytab));
  1594.  
  1595. struct keytab ttkeytab[] = {
  1596.     { "aaa",       TT_AAA,        CM_INV },        /* AnnArbor */
  1597.     { "adm3a",     TT_ADM3A,      0 },             /* LSI ADM-3A */
  1598.     { "adm5",      TT_ADM5,       0 },             /* LSI ADM-5 */
  1599.     { "aixterm",   TT_AIXTERM,    0 },             /* IBM AIXterm */
  1600.     { "annarbor",  TT_AAA,        0 },             /* AnnArbor */
  1601.     { "ansi-bbs",  TT_ANSI,       0 },             /* ANSI.SYS (BBS) */
  1602.     { "at386",     TT_AT386,      0 },             /* Unixware ANSI */
  1603.     { "avatar/0+", TT_ANSI,       0 },             /* AVATAR/0+ */
  1604.     { "ba80",      TT_BA80,       0 },             /* Nixdorf BA80 */
  1605.     { "be",        TT_BEOS,       CM_INV|CM_ABR },
  1606.     { "beos-ansi", TT_BEOS,       CM_INV },        /* BeOS ANSI */
  1607.     { "beterm",    TT_BEOS,       0 },             /* BeOS Terminal (DR2) */
  1608.     { "d200",      TT_DG200,      CM_INV|CM_ABR }, /* DG DASHER 200 */
  1609.     { "d210",      TT_DG210,      CM_INV|CM_ABR }, /* DG DASHER 210 */
  1610.     { "d217",      TT_DG217,      CM_INV|CM_ABR }, /* DG DASHER 217 */
  1611.     { "dg200",     TT_DG200,      0 },             /* DG DASHER 200 */
  1612.     { "dg210",     TT_DG210,      0 },             /* DG DASHER 210 */
  1613.     { "dg217",     TT_DG217,      0 },             /* DG DASHER 217 */
  1614.     { "emacs",     TT_KBM_EMACS,  0 },             /* Emacs mode */
  1615.     { "h19",       TT_H19,        CM_INV },        /* Heath-19 */
  1616.     { "heath19",   TT_H19,        0 },             /* Heath-19 */
  1617.     { "hebrew",    TT_KBM_HEBREW, 0 },             /* Hebrew mode */
  1618.     { "hft",       TT_HFT,        0 },             /* IBM High Function Term */
  1619.     { "hp2621a",   TT_HP2621,     0 },             /* HP 2621A */
  1620.     { "hpterm",    TT_HPTERM,     0 },             /* HP TERM */
  1621.     { "hz1500",    TT_HZL1500,    0 },             /* Hazeltine 1500 */
  1622.     { "ibm3151",   TT_IBM31,      0 },             /* IBM 3101-xx,3161 */
  1623.     { "linux",     TT_LINUX,      0 },             /* Linux */
  1624.     { "qansi",     TT_QANSI,      0 },             /* QNX ANSI */
  1625.     { "qnx",       TT_QNX,        0 },             /* QNX */
  1626.     { "russian",   TT_KBM_RUSSIAN,0 },             /* Russian mode */
  1627.     { "scoansi",   TT_SCOANSI,    0 },             /* SCO ANSI */
  1628.     { "sni-97801", TT_97801,      0 },             /* SNI 97801 */
  1629.     { "sun",       TT_SUN,        0 },             /* SUN Console */
  1630. #ifdef OS2PM
  1631. #ifdef COMMENT
  1632.     { "tek4014",   TT_TEK40,      0 },
  1633. #endif /* COMMENT */
  1634. #endif /* OS2PM */
  1635.     { "tty",       TT_NONE,       0 },
  1636.     { "tvi910+",   TT_TVI910,     0 },
  1637.     { "tvi925",    TT_TVI925,     0 },
  1638.     { "tvi950",    TT_TVI950,     0 },
  1639.     { "vc404",     TT_VC4404,     0 },
  1640.     { "vc4404",    TT_VC4404,     CM_INV },
  1641.     { "vip7809",   TT_VIP7809,    0 },
  1642.     { "vt100",     TT_VT100,      0 },
  1643.     { "vt102",     TT_VT102,      0 },
  1644.     { "vt220",     TT_VT220,      0 },
  1645.     { "vt220pc",   TT_VT220PC,    0 },
  1646.     { "vt320",     TT_VT320,      0 },
  1647.     { "vt320pc",   TT_VT320PC,    0 },
  1648.     { "vt52",      TT_VT52,       0 },
  1649.     { "vtnt",      TT_VTNT,       CM_INV },
  1650.     { "wp",        TT_KBM_WP,     0 },             /* Word Perfect mode */
  1651.     { "wy160",     TT_WY160,      0 },
  1652.     { "wy30",      TT_WY30,       0 },
  1653.     { "wy370",     TT_WY370,      0 },
  1654.     { "wy50",      TT_WY50,       0 },
  1655.     { "wy60",      TT_WY60,       0 },
  1656.     { "wyse30",    TT_WY30,       CM_INV },
  1657.     { "wyse370",   TT_WY370,      CM_INV },
  1658.     { "wyse50",    TT_WY50,       CM_INV },
  1659.     { "wyse60",    TT_WY60,       CM_INV }
  1660. };
  1661. int nttkey = (sizeof(ttkeytab) / sizeof(struct keytab));
  1662.  
  1663. #ifndef NOSETKEY
  1664. struct keytab kbmodtab[] = {
  1665.     { "emacs",   KBM_EM, 0      },
  1666.     { "english", KBM_EN, CM_INV },
  1667.     { "hebrew",  KBM_HE, 0      },
  1668.     { "normal",  KBM_EN, 0      },
  1669.     { "none",    KBM_EN, CM_INV },
  1670.     { "russian", KBM_RU, 0      },
  1671.     { "wp",      KBM_WP, 0      }
  1672. };
  1673. int nkbmodtab = (sizeof(kbmodtab) / sizeof(struct keytab));
  1674. #endif /* NOSETKEY */
  1675. #endif /* NOLOCAL */
  1676.  
  1677. int tt_inpacing = 0;                    /* input-pacing (none) */
  1678.  
  1679. struct keytab prtytab[] = { /* OS/2 Priority Levels */
  1680.     { "foreground-server", XYP_SRV, 0       },
  1681.     { "idle",              XYP_IDLE, CM_INV },
  1682.     { "regular",           XYP_REG, 0       },
  1683.     { "time-critical",     XYP_RTP, 0       }
  1684. };
  1685. int nprty = (sizeof(prtytab) / sizeof(struct keytab));
  1686. #endif /* OS2 */
  1687.  
  1688. #ifdef NT
  1689. struct keytab win95tab[] = { /* Win95 work-arounds */
  1690.     { "8.3-filenames",         XYW8_3,    0 },
  1691.     { "alt-gr",                XYWAGR,    0 },
  1692.     { "horizontal-scan-line-substitutions", XYWHSL, 0 },
  1693.     { "keyboard-translation",  XYWKEY,    0 },
  1694.     { "lucida-substitutions",  XYWLUC,    0 },
  1695.     { "overlapped-io",         XYWOIO,    0 },
  1696.     { "popups",                XYWPOPUP,  0 },
  1697.     { "select-bug",            XYWSELECT, 0 }
  1698. };
  1699. int nwin95 = (sizeof(win95tab) / sizeof(struct keytab));
  1700. #endif /* NT */
  1701.  
  1702. #ifdef OS2MOUSE
  1703. extern int wideresult;
  1704. int tt_mouse = 1;                       /* Terminal mouse on/off */
  1705.  
  1706. struct keytab mousetab[] = {            /* Mouse items */
  1707.     { "activate", XYM_ON,     0 },
  1708.     { "button",   XYM_BUTTON, 0 },
  1709.     { "clear",    XYM_CLEAR,  0 },
  1710.     { "debug",    XYM_DEBUG,  0 }
  1711. };
  1712. int nmtab = (sizeof(mousetab)/sizeof(struct keytab));
  1713.  
  1714. struct keytab mousebuttontab[] = {      /* event button */
  1715.     { "1",             XYM_B1, 0 },
  1716.     { "2",             XYM_B2, 0 },
  1717.     { "3",             XYM_B3, 0 },
  1718.     { "one",           XYM_B1, CM_INV },
  1719.     { "three",         XYM_B3, CM_INV },
  1720.     { "two",           XYM_B2, CM_INV }
  1721. };
  1722. int nmbtab = (sizeof(mousebuttontab) / sizeof(struct keytab));
  1723.  
  1724. struct keytab mousemodtab[] = {         /* event button key modifier */
  1725.     { "alt",              XYM_ALT,   0 },
  1726.     { "alt-shift",        XYM_SHIFT|XYM_ALT, 0 },
  1727.     { "ctrl",             XYM_CTRL,  0 },
  1728.     { "ctrl-alt",         XYM_CTRL|XYM_ALT, 0 },
  1729.     { "ctrl-alt-shift",   XYM_CTRL|XYM_SHIFT|XYM_ALT, 0 },
  1730.     { "ctrl-shift",       XYM_CTRL|XYM_SHIFT, 0 },
  1731.     { "none",             0, 0 },
  1732.     { "shift",            XYM_SHIFT, 0 }
  1733. };
  1734. int nmmtab = (sizeof(mousemodtab) / sizeof(struct keytab));
  1735.  
  1736. struct keytab mclicktab[] = {           /* event button click modifier */
  1737.     { "click",        XYM_C1,   0 },
  1738.     { "drag",         XYM_DRAG, 0 },
  1739.     { "double-click", XYM_C2,   0 }
  1740. };
  1741. int nmctab = (sizeof(mclicktab) / sizeof(struct keytab));
  1742.  
  1743. #ifndef NOKVERBS
  1744. extern int nkverbs;
  1745. extern struct keytab kverbs[];
  1746. #endif /* NOKVERBS */
  1747. #endif /* OS2MOUSE */
  1748.  
  1749. /* #ifdef VMS */
  1750. struct keytab fbtab[] = {               /* Binary record types for VMS */
  1751.     { "fixed",     XYFT_B, 0 },         /* Fixed is normal for binary */
  1752.     { "undefined", XYFT_U, 0 }          /* Undefined if they ask for it */
  1753. };
  1754. int nfbtyp = (sizeof(fbtab) / sizeof(struct keytab));
  1755. /* #endif */
  1756.  
  1757. #ifdef VMS
  1758. struct keytab lbltab[] = {              /* Labeled File info */
  1759.     { "acl",         LBL_ACL, 0 },
  1760.     { "backup-date", LBL_BCK, 0 },
  1761.     { "name",        LBL_NAM, 0 },
  1762.     { "owner",       LBL_OWN, 0 },
  1763.     { "path",        LBL_PTH, 0 }
  1764. };
  1765. int nlblp = (sizeof(lbltab) / sizeof(struct keytab));
  1766. #else
  1767. #ifdef OS2
  1768. struct keytab lbltab[] = {              /* Labeled File info */
  1769.     { "archive",   LBL_ARC, 0 },
  1770.     { "extended",  LBL_EXT, 0 },
  1771.     { "hidden",    LBL_HID, 0 },
  1772.     { "read-only", LBL_RO,  0 },
  1773.     { "system",    LBL_SYS, 0 }
  1774. };
  1775. int nlblp = (sizeof(lbltab) / sizeof(struct keytab));
  1776. #endif /* OS2 */
  1777. #endif /* VMS */
  1778.  
  1779. #ifdef CK_CURSES
  1780. #ifdef CK_PCT_BAR
  1781. static struct keytab fdftab[] = {       /* SET FILE DISPLAY FULL options */
  1782.     { "thermometer",    1, 0, },
  1783.     { "no-thermometer", 0, 0  }
  1784. };
  1785. extern int thermometer;
  1786. #endif /* CK_PCT_BAR */
  1787. #endif /* CK_CURSES */
  1788.  
  1789. static struct keytab fdtab[] = {        /* SET FILE DISPLAY options */
  1790. #ifdef MAC                              /* Macintosh */
  1791.     { "fullscreen", XYFD_R,      0 },   /* Full-screen but not curses */
  1792.     { "none",       XYFD_N,      0 },
  1793.     { "off",        XYFD_N, CM_INV },
  1794.     { "on",         XYFD_R, CM_INV },
  1795.     { "quiet",      XYFD_N, CM_INV },
  1796. #else                                   /* Not Mac */
  1797.     { "brief", XYFD_B, 0 },             /* Brief */
  1798.     { "crt", XYFD_S, 0 },               /* CRT display */
  1799. #ifdef CK_CURSES
  1800. #ifdef COMMENT
  1801.     { "curses",     XYFD_C,  CM_INV },  /* Full-screen, curses */
  1802. #endif /* COMMENT */
  1803.     { "fullscreen", XYFD_C,  0 },       /* Full-screen, whatever the method */
  1804. #endif /* CK_CURSES */
  1805. #ifdef KUI
  1806.     { "gui",    XYFD_G, 0 },            /* GUI */
  1807. #endif /* KUI */        
  1808.     { "none",   XYFD_N, 0      },       /* No display */
  1809.     { "off",    XYFD_N, CM_INV },       /* Ditto */
  1810.     { "on",     XYFD_R, CM_INV },       /* On = Serial */
  1811.     { "quiet",  XYFD_N, CM_INV },       /* No display */
  1812.     { "serial", XYFD_R, 0      },       /* Serial */
  1813. #endif /* MAC */
  1814.     { "", 0, 0 }
  1815. };
  1816. int nfdtab = (sizeof(fdtab) / sizeof(struct keytab)) - 1;
  1817.  
  1818. struct keytab rsrtab[] = {              /* For REMOTE SET RECEIVE */
  1819.     { "packet-length", XYLEN,  0 },
  1820.     { "timeout",       XYTIMO, 0 }
  1821. };
  1822. int nrsrtab = (sizeof(rsrtab) / sizeof(struct keytab));
  1823.  
  1824. /* Send/Receive Parameters */
  1825.  
  1826. struct keytab srtab[] = {
  1827.     { "backup", XYBUP, 0 },
  1828. #ifndef NOCSETS
  1829.     { "character-set-selection", XYCSET, 0 },
  1830. #endif /* NOCSETS */
  1831.     { "control-prefix", XYQCTL, 0 },
  1832. #ifdef CKXXCHAR
  1833.     { "double-character", XYDBL, 0 },
  1834. #endif /* CKXXCHAR */
  1835.     { "end-of-packet", XYEOL, 0 },
  1836. #ifdef PIPESEND
  1837.     { "filter", XYFLTR, 0 },
  1838. #endif /* PIPESEND */
  1839. #ifdef CKXXCHAR
  1840.     { "ignore-character", XYIGN, 0 },
  1841. #endif /* CKXXCHAR */
  1842.     { "i-packets", 993, 0 },
  1843.     { "move-to", XYMOVE, 0 },
  1844.     { "negotiation-string-max-length", XYINIL, CM_INV },
  1845.     { "packet-length", XYLEN, 0 },
  1846.     { "pad-character", XYPADC, 0 },
  1847.     { "padding", XYNPAD, 0 },
  1848.     { "pathnames", XYFPATH, 0 },
  1849.     { "pause", XYPAUS, 0 },
  1850. #ifdef CK_PERMS
  1851.     { "permissions", 994, 0},        /* 206 */
  1852. #endif /* CK_PERMS */
  1853.     { "quote", XYQCTL, CM_INV },        /* = CONTROL-PREFIX */
  1854.     { "rename-to", XYRENAME, 0 },
  1855.     { "start-of-packet", XYMARK, 0 },
  1856.     { "timeout", XYTIMO, 0 },
  1857. #ifdef VMS
  1858.     { "version-numbers", 887, 0 },      /* VMS version numbers */
  1859. #endif /* VMS */
  1860.     { "", 0, 0 }
  1861. };
  1862. int nsrtab = (sizeof(srtab) / sizeof(struct keytab)) - 1;
  1863.  
  1864. #ifdef UNICODE
  1865. #define UCS_BOM 1
  1866. #define UCS_BYT 2
  1867. static struct keytab ucstab[] = {
  1868.     { "bom",        UCS_BOM, 0 },
  1869.     { "byte-order", UCS_BYT, 0 },
  1870.     { "", 0, 0 }
  1871. };
  1872. int nucstab = (sizeof(ucstab) / sizeof(struct keytab)) - 1;
  1873.  
  1874. static struct keytab botab[] = {
  1875.     { "big-endian",    0, 0 },
  1876.     { "little-endian", 1, 0 }
  1877. };
  1878. static int nbotab = 2;
  1879. #endif /* UNICODE */
  1880.  
  1881. /* REMOTE SET */
  1882.  
  1883. struct keytab rmstab[] = {
  1884.     { "attributes",  XYATTR, 0      },
  1885.     { "block-check", XYCHKT, 0      },
  1886.     { "file",        XYFILE, 0      },
  1887.     { "incomplete",  XYIFD,  CM_INV },  /* = REMOTE SET FILE INCOMPLETE */
  1888.     { "match",       XYMATCH,0      },
  1889.     { "receive",     XYRECV, 0      },
  1890.     { "retry",       XYRETR, 0      },
  1891.     { "server",      XYSERV, 0      },
  1892.     { "transfer",    XYXFER, 0      },
  1893.     { "window",      XYWIND, 0      },
  1894.     { "xfer",        XYXFER, CM_INV }
  1895. };
  1896. int nrms = (sizeof(rmstab) / sizeof(struct keytab));
  1897.  
  1898. struct keytab attrtab[] = {
  1899. #ifdef STRATUS
  1900.     { "account",       AT_ACCT, 0 },
  1901. #endif /* STRATUS */
  1902.     { "all",           AT_XALL, 0 },
  1903. #ifdef COMMENT
  1904.     { "blocksize",     AT_BLKS, 0 },    /* (not used) */
  1905. #endif /* COMMENT */
  1906. #ifndef NOCSETS
  1907.     { "character-set", AT_ENCO, 0 },
  1908. #endif /* NOCSETS */
  1909. #ifdef STRATUS
  1910.     { "creator",       AT_CREA, 0 },
  1911. #endif /* STRATUS */
  1912.     { "date",          AT_DATE, 0 },
  1913.     { "disposition",   AT_DISP, 0 },
  1914.     { "encoding",      AT_ENCO, CM_INV },
  1915.     { "format",        AT_RECF, CM_INV },
  1916.     { "length",        AT_LENK, 0 },
  1917.     { "off",           AT_ALLN, 0 },
  1918.     { "on",            AT_ALLY, 0 },
  1919. #ifdef COMMENT
  1920.     { "os-specific",   AT_SYSP, 0 },    /* (not used by UNIX or VMS) */
  1921. #endif /* COMMENT */
  1922. #ifdef CK_PERMS
  1923.     { "protection",    AT_LPRO, 0 },
  1924.     { "permissions",   AT_LPRO, CM_INV },
  1925. #endif /* CK_PERMS */
  1926.     { "record-format", AT_RECF, 0 },
  1927.     { "system-id",     AT_SYSI, 0 },
  1928.     { "type",          AT_FTYP, 0 }
  1929. };
  1930. int natr = (sizeof(attrtab) / sizeof(struct keytab)); /* how many attributes */
  1931.  
  1932. #ifdef CKTIDLE
  1933. struct keytab idlacts[] = {
  1934.     { "exit",       IDLE_EXIT, 0 },
  1935.     { "hangup",     IDLE_HANG, 0 },
  1936.     { "output",     IDLE_OUT,  0 },
  1937.     { "return",     IDLE_RET,  0 },
  1938. #ifdef TNCODE
  1939.     { "telnet-nop", IDLE_TNOP, 0 },
  1940.     { "telnet-ayt", IDLE_TAYT, 0 },
  1941. #endif /* TNCODE */
  1942.     { "", 0, 0 }
  1943. };
  1944. int nidlacts = (sizeof(idlacts) / sizeof(struct keytab)) - 1;
  1945. #endif /* CKTIDLE */
  1946.  
  1947. #ifndef NOSPL
  1948. extern int indef, inecho, insilence, inbufsize, inautodl, inintr;
  1949. #ifdef CKFLOAT
  1950. extern CKFLOAT inscale;
  1951. #endif    /* CKFLOAT */
  1952. extern char * inpbuf, * inpbp;
  1953. #ifdef OS2
  1954. extern int interm;
  1955. #endif /* OS2 */
  1956. struct keytab inptab[] = {              /* SET INPUT parameters */
  1957. #ifdef CK_AUTODL
  1958.     { "autodownload",    IN_ADL, 0 },
  1959. #endif /* CK_AUTODL */
  1960.     { "buffer-length",   IN_BUF, 0 },
  1961.     { "cancellation",    IN_CAN, 0 },
  1962.     { "case",            IN_CAS, 0 },
  1963.     { "default-timeout", IN_DEF, CM_INV }, /* There is no default timeout */
  1964.     { "echo",            IN_ECH, 0 },
  1965. #ifdef OS2
  1966.     { "pacing",          IN_PAC, CM_INV },
  1967. #endif /* OS2 */
  1968.     { "scale-factor",    IN_SCA, 0 },
  1969.     { "silence",         IN_SIL, 0 },
  1970. #ifdef OS2
  1971.     { "terminal",        IN_TRM, 0 },
  1972. #endif /* OS2 */
  1973.     { "timeout-action",  IN_TIM, 0 }
  1974. };
  1975. int ninp = (sizeof(inptab) / sizeof(struct keytab));
  1976.  
  1977. struct keytab intimt[] = {              /* SET INPUT TIMEOUT parameters */
  1978.     { "proceed", 0, 0 },                /* 0 = proceed */
  1979.     { "quit",    1, 0 }                 /* 1 = quit */
  1980. };
  1981.  
  1982. struct keytab incast[] = {              /* SET INPUT CASE parameters */
  1983.     { "ignore",  0, 0 },                /* 0 = ignore */
  1984.     { "observe", 1, 0 }                 /* 1 = observe */
  1985. };
  1986. #endif /* NOSPL */
  1987.  
  1988. struct keytab nabltab[] = {             /* For any command that needs */
  1989.     { "disabled", 0, 0 },
  1990.     { "enabled",  1, 0 },
  1991.     { "off",      0, CM_INV },          /* these keywords... */
  1992.     { "on",       1, CM_INV }
  1993. };
  1994. int nnabltab = sizeof(nabltab) / sizeof(struct keytab);
  1995.  
  1996. #ifdef OS2
  1997. struct keytab tvctab[] = {              /* SET TERM VIDEO-CHANGE */
  1998.     { "disabled",     TVC_DIS, 0 },
  1999.     { "enabled",      TVC_ENA, 0 },
  2000. #ifdef NT
  2001.     { "win95-safe",   TVC_W95, 0 },
  2002. #endif /* NT */
  2003.     { "", 0, 0 }
  2004. };
  2005. int ntvctab = (sizeof(tvctab) / sizeof(struct keytab)) - 1;
  2006.  
  2007. struct keytab msktab[] = { /* SET MS-DOS KERMIT compatibilities */
  2008. #ifdef COMMENT
  2009.     { "color",    MSK_COLOR,  0 },
  2010. #endif /* COMMENT */
  2011.     { "file-renaming", MSK_REN, 0 },
  2012.     { "keycodes", MSK_KEYS,   0 }
  2013. };
  2014. int nmsk = (sizeof(msktab) / sizeof(struct keytab));
  2015.  
  2016. struct keytab scrnupd[] = {             /* SET TERMINAL SCREEN-UPDATE */
  2017.     { "fast",   TTU_FAST,   0 },
  2018.     { "smooth", TTU_SMOOTH, 0 }
  2019. };
  2020. int nscrnupd = (sizeof(scrnupd) / sizeof(struct keytab));
  2021.  
  2022. #ifdef PCFONTS
  2023. /* This definition of the term_font[] table is only for     */
  2024. /* the OS/2 Full Screen Session and is not used on Windows */
  2025. struct keytab term_font[] = {           /* SET TERMINAL FONT */
  2026. #ifdef COMMENT
  2027.     { "cp111", TTF_111, 0 },
  2028.     { "cp112", TTF_112, 0 },
  2029.     { "cp113", TTF_113, 0 },
  2030. #endif /* COMMENT */
  2031.     { "cp437", TTF_437, 0 },
  2032.     { "cp850", TTF_850, 0 },
  2033. #ifdef COMMENT
  2034.     { "cp851", TTF_851, 0 },
  2035. #endif /* COMMENT */
  2036.     { "cp852", TTF_852, 0 },
  2037. #ifdef COMMENT
  2038.     { "cp853", TTF_853, 0 },
  2039.     { "cp860", TTF_860, 0 },
  2040.     { "cp861", TTF_861, 0 },
  2041. #endif /* COMMENT */
  2042.     { "cp862", TTF_862, 0 },
  2043. #ifdef COMMENT
  2044.     { "cp863", TTF_863, 0 },
  2045.     { "cp864", TTF_864, 0 },
  2046.     { "cp865", TTF_865, 0 },
  2047. #endif /* COMMENT */
  2048.     { "cp866", TTF_866, 0 },
  2049. #ifdef COMMENT
  2050.     { "cp880", TTF_880, 0 },
  2051.     { "cp881", TTF_881, 0 },
  2052.     { "cp882", TTF_882, 0 },
  2053.     { "cp883", TTF_883, 0 },
  2054.     { "cp884", TTF_884, 0 },
  2055.     { "cp885", TTF_885, 0 },
  2056. #endif /* COMMENT */
  2057.     { "default",TTF_ROM,0 }
  2058. };
  2059. int ntermfont = (sizeof(term_font) / sizeof(struct keytab));
  2060. int tt_font = TTF_ROM;                  /* Terminal screen font */
  2061. #else /* PCFONTS */
  2062. #ifdef NT
  2063. #ifdef KUI
  2064. struct keytab * term_font = NULL;
  2065. struct keytab * _term_font = NULL;
  2066. char * tt_facename = NULL;
  2067. int ntermfont = 0;
  2068. int tt_font = 0;
  2069. int tt_font_size = 0;
  2070. #endif /* KUI */
  2071. #endif /* NT */
  2072. #endif /* PCFONTS */
  2073.  
  2074. struct keytab anbktab[] = {             /* For any command that needs */
  2075.     { "message", 2, 0 },                /* these keywords... */
  2076.     { "off",     0, 0 },
  2077.     { "on",      1, 0 },
  2078.     { "unsafe-messag0", 99, CM_INV },
  2079.     { "unsafe-message", 3,  CM_INV }
  2080. };
  2081. int nansbk = (sizeof(anbktab) / sizeof(struct keytab));
  2082.  
  2083. int win95_popup = 1;
  2084. #ifdef NT
  2085. #ifdef KUI
  2086. int win95lucida = 0;
  2087. int win95hsl = 1;
  2088. #else /* KUI */
  2089. int win95lucida = 1;
  2090. int win95hsl = 1;
  2091. #endif /* KUI */
  2092. #else /* NT */
  2093. int win95lucida = 0;
  2094. int win95hsl = 1;
  2095. #endif /* NT */
  2096. #ifdef NT
  2097. int win95altgr  = 0;
  2098. extern int win95selectbug;
  2099. extern int win95_8_3;
  2100.  
  2101. #ifdef COMMENT
  2102. extern CHAR (*xlr[MAXTCSETS+1][MAXFCSETS+1])(CHAR);
  2103. extern struct keytab tcstab[];
  2104. extern int ntcs;
  2105. #endif /* COMMENT */
  2106. extern int maxow, maxow_usr; owwait;    /* Overlapped I/O variables */
  2107. #endif /* NT */
  2108. #endif /* OS2 */
  2109.  
  2110.  
  2111. /* The following routines broken out of doprm() to give compilers a break. */
  2112.  
  2113. /*  S E T O N  --  Parse on/off (default on), set parameter to result  */
  2114.  
  2115. int
  2116. seton(prm) int *prm; {
  2117.     int x, y;
  2118.     if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  2119.     if ((x = cmcfm()) < 0) return(x);
  2120.     *prm = y;
  2121.     return(1);
  2122. }
  2123.  
  2124. /*  S E T O N A U T O --  Parse on/off/auto (default auto) & set result */
  2125.  
  2126. struct keytab onoffaut[] = {
  2127.     { "auto", SET_AUTO, 0 },            /* 2 */
  2128.     { "off",  SET_OFF,  0 },            /* 0 */
  2129.     { "on",   SET_ON,   0 }             /* 1 */
  2130. };
  2131.  
  2132. int
  2133. setonaut(prm) int *prm; {
  2134.     int x, y;
  2135.     if ((y = cmkey(onoffaut,3,"","auto",xxstring)) < 0) return(y);
  2136.     if ((x = cmcfm()) < 0) return(x);
  2137.     *prm = y;
  2138.     return(1);
  2139. }
  2140.  
  2141. /*  S E T N U M  --  Set parameter to result of cmnum() parse.  */
  2142. /*
  2143.  Call with pointer to integer variable to be set,
  2144.    x = number from cnum parse, y = return code from cmnum,
  2145.    max = maximum value to accept, -1 if no maximum.
  2146.  Returns -9 on failure, after printing a message, or 1 on success.
  2147. */
  2148. int
  2149. setnum(prm,x,y,max) int x, y, *prm, max; {
  2150.     debug(F101,"setnum","",y);
  2151.     if (y == -3) {
  2152.         printf("\n?Value required\n");
  2153.         return(-9);
  2154.     }
  2155.     if (y == -2) {
  2156.         printf("%s?Not a number: %s\n",cmflgs == 1 ? "" : "\n", atxbuf);
  2157.         return(-9);
  2158.     }
  2159.     if (y < 0) return(y);
  2160.     if (max > -1 && x > max) {
  2161.         printf("?Sorry, %d is the maximum\n",max);
  2162.         return(-9);
  2163.     }
  2164.     if ((y = cmcfm()) < 0) return(y);
  2165.     *prm = x;
  2166.     return(1);
  2167. }
  2168.  
  2169. /*  S E T C C  --  Set parameter var to an ASCII control character value.  */
  2170. /*
  2171.   Parses a number, or a literal control character, or a caret (^) followed
  2172.   by an ASCII character whose value is 63-95 or 97-122, then gets confirmation,
  2173.   then sets the parameter to the code value of the character given.  If there
  2174.   are any parse errors, they are returned, otherwise on success 1 is returned.
  2175. */
  2176. int
  2177. setcc(dflt,var) char *dflt; int *var; {
  2178.     int x, y;
  2179.     unsigned int c;
  2180.     char *hlpmsg = "Control character,\n\
  2181.  numeric ASCII value,\n\
  2182.  or in ^X notation,\n\
  2183.  or preceded by a backslash and entered literally";
  2184.  
  2185.     /* This is a hack to turn off complaints from expression evaluator. */
  2186.     x_ifnum = 1;
  2187.     y = cmnum(hlpmsg, dflt, 10, &x, xxstring); /* Parse a number */
  2188.     x_ifnum = 0;                               /* Allow complaints again */
  2189.     if (y < 0) {                        /* Parse failed */
  2190.         if (y != -2)                    /* Reparse needed or somesuch */
  2191.           return(y);                    /* Pass failure back up the chain */
  2192.     }
  2193.     /* Real control character or literal 8-bit character... */
  2194.  
  2195.     for (c = strlen(atmbuf) - 1; c > 0; c--) /* Trim */
  2196.       if (atmbuf[c] == SP) atmbuf[c] = NUL;
  2197.  
  2198.     if (y < 0) {                        /* It was not a number */
  2199.         if (((c = atmbuf[0])) && !atmbuf[1]) { /* Literal character? */
  2200.             c &= 0xff;
  2201.             if (((c > 31) && (c < 127)) || (c > 255)) {
  2202.                 printf("\n?%d: Out of range - must be 0-31 or 127-255\n",c);
  2203.                 return(-9);
  2204.             } else {
  2205.                 if ((y = cmcfm()) < 0)  /* Confirm */
  2206.                   return(y);
  2207.                 *var = c;               /* Set the variable */
  2208.                 return(1);
  2209.             }
  2210.         } else if (atmbuf[0] == '^' && !atmbuf[2]) { /* Or ^X notation? */
  2211.             c = atmbuf[1];
  2212.             if (islower((char) c))      /* Uppercase lowercase letters */
  2213.               c = toupper(c);
  2214.             if (c > 62 && c < 96) {     /* Check range */
  2215.                 if ((y = cmcfm()) < 0)
  2216.                   return(y);
  2217.                 *var = ctl(c);          /* OK */
  2218.                 return(1);
  2219.             } else {
  2220.                 printf("?Not a control character - %s\n", atmbuf);
  2221.                 return(-9);
  2222.             }
  2223.         } else {                        /* Something illegal was typed */
  2224.             printf("?Invalid - %s\n", atmbuf);
  2225.             return(-9);
  2226.         }
  2227.     }
  2228.     if (((x > 31) && (x < 127)) || (x > 255)) { /* They typed a number */
  2229.         printf("\n?%d: Out of range - must be 0-31 or 127-255\n",x);
  2230.         return(-9);
  2231.     }
  2232.     if ((y = cmcfm()) < 0)              /* In range, confirm */
  2233.       return(y);
  2234.     *var = x;                           /* Set variable */
  2235.     return(1);
  2236. }
  2237.  
  2238. #ifndef NOSPL                           /* The SORT command... */
  2239.  
  2240. static struct keytab srtswtab[] = {     /* SORT command switches */
  2241.     { "/case",    SRT_CAS, CM_ARG },
  2242.     { "/key",     SRT_KEY, CM_ARG },
  2243.     { "/numeric", SRT_NUM, 0 },
  2244.     { "/range",   SRT_RNG, CM_ARG },
  2245.     { "/reverse", SRT_REV, 0 }
  2246. };
  2247. static int nsrtswtab = sizeof(srtswtab)/sizeof(struct keytab);
  2248.  
  2249. extern char **a_ptr[];                  /* Array pointers */
  2250. extern int a_dim[];                     /* Array dimensions */
  2251.  
  2252. int
  2253. dosort() {                              /* Do the SORT command */
  2254.     char c, *p = NULL, ** ap, ** xp = NULL;
  2255.     struct FDB sw, fl, cm;
  2256.     int hi, lo;
  2257.     int xn = 0, xr = -1, xk = -1, xc = -1, xs = 0;
  2258.     int getval = 0, range[2], confirmed = 0;
  2259.  
  2260.     cmfdbi(&sw,                         /* First FDB - command switches */
  2261.            _CMKEY,                      /* fcode */
  2262.            "Array name or switch",
  2263.            "",                          /* default */
  2264.            "",                          /* addtl string data */
  2265.            nsrtswtab,                   /* addtl numeric data 1: tbl size */
  2266.            4,                           /* addtl numeric data 2: 4 = cmswi */
  2267.            NULL,                        /* Processing function */
  2268.            srtswtab,                    /* Keyword table */
  2269.            &fl                          /* Pointer to next FDB */
  2270.            );
  2271.     cmfdbi(&fl,                         /* Anything that doesn't match */
  2272.            _CMFLD,                      /* fcode */
  2273.            "Array name",                /* hlpmsg */
  2274.            "",                          /* default */
  2275.            "",                          /* addtl string data */
  2276.            0,                           /* addtl numeric data 1 */
  2277.            0,                           /* addtl numeric data 2 */
  2278.            NULL,
  2279.            NULL,
  2280.            &cm
  2281.            );
  2282.     cmfdbi(&cm,                         /* Or premature confirmation */
  2283.            _CMCFM,                      /* fcode */
  2284.            "",                          /* hlpmsg */
  2285.            "",                          /* default */
  2286.            "",                          /* addtl string data */
  2287.            0,                           /* addtl numeric data 1 */
  2288.            0,                           /* addtl numeric data 2 */
  2289.            NULL,
  2290.            NULL,
  2291.            NULL
  2292.            );
  2293.  
  2294.     range[0] = -1;
  2295.     range[1] = -1;
  2296.  
  2297.     while (1) {                         /* Parse 0 or more switches */
  2298.         x = cmfdb(&sw);
  2299.         if (x < 0)
  2300.           return(x);
  2301.         if (cmresult.fcode != _CMKEY)   /* Break out if not a switch */
  2302.           break;
  2303.         c = cmgbrk();
  2304.         getval = (c == ':' || c == '=');
  2305.         if (getval && !(cmresult.kflags & CM_ARG)) {
  2306.             printf("?This switch does not take arguments\n");
  2307.             return(-9);
  2308.         }
  2309.         switch (cmresult.nresult) {
  2310.           case SRT_REV:
  2311.             xr = 1;
  2312.             break;
  2313.           case SRT_KEY:
  2314.             if (getval) {
  2315.                 if ((y = cmnum("Column for comparison (1-based)",
  2316.                                "1",10,&x,xxstring)) < 0)
  2317.                   return(y);
  2318.                 xk = x - 1;
  2319.             } else
  2320.               xk = 0;
  2321.             break;
  2322.           case SRT_CAS:
  2323.             if (getval) {
  2324.                 if ((y = cmkey(onoff,2,"","on",xxstring)) < 0)
  2325.                   return(y);
  2326.                 xc = y;
  2327.             } else
  2328.               xc = 1;
  2329.             break;
  2330.           case SRT_RNG:                 /* /RANGE */
  2331.             if (getval) {
  2332.                 char buf[32];
  2333.                 char buf2[16];
  2334.                 int i;
  2335.                 char * p, * q;
  2336.                 if ((y = cmfld("low:high element","1",&s,NULL)) < 0)
  2337.                   return(y);
  2338.                 s = brstrip(s);
  2339.                 ckstrncpy(buf,s,32);
  2340.                 p = buf;
  2341.                 for (i = 0; *p && i < 2; i++) { /* Get low and high */
  2342.                     q = p;              /* Start of this piece */
  2343.                     while (*p) {        /* Find end of this piece */
  2344.                         if (*p == ':') {
  2345.                             *p = NUL;
  2346.                             p++;
  2347.                             break;
  2348.                         }
  2349.                         p++;
  2350.                     }
  2351.                     y = 15;             /* Evaluate this piece */
  2352.                     s = buf2;
  2353.                     zzstring(q,&s,&y);
  2354.                     s = evalx(buf2);
  2355.                     if (s) if (*s) ckstrncpy(buf2,s,16);
  2356.                     if (!rdigits(buf2)) {
  2357.                         printf("?Not numeric: %s\n",buf2);
  2358.                         return(-9);
  2359.                     }
  2360.                     range[i] = atoi(buf2);
  2361.                 }
  2362.             }
  2363.             break;
  2364.           case SRT_NUM:                 /* /NUMERIC */
  2365.             xn = 1;
  2366.             break;
  2367.           default:
  2368.             return(-2);
  2369.         }
  2370.     }
  2371.     switch (cmresult.fcode) {
  2372.       case _CMCFM:
  2373.         confirmed = 1;
  2374.         break;
  2375.       case _CMFLD:
  2376.         ckstrncpy(line,cmresult.sresult,LINBUFSIZ); /* Safe copy of name */
  2377.         s = line;
  2378.         break;
  2379.       default:
  2380.         printf("?Unexpected function code: %d\n",cmresult.fcode);
  2381.         return(-9);
  2382.     }
  2383.     if (confirmed) {
  2384.         printf("?Array name required\n");
  2385.         return(-9);
  2386.     }
  2387.     ckmakmsg(tmpbuf,TMPBUFSIZ,
  2388.              "Second array to sort according to ",s,NULL,NULL);
  2389.     if ((x = cmfld(tmpbuf,"",&p,NULL)) < 0)
  2390.       if (x != -3)
  2391.         return(x);
  2392.     tmpbuf[0] = NUL;
  2393.     ckstrncpy(tmpbuf,p,TMPBUFSIZ);
  2394.     p = tmpbuf;
  2395.     if ((x = cmcfm()) < 0)              /* Get confirmation */
  2396.       return(x);
  2397.  
  2398.     x = arraybounds(s,&lo,&hi);         /* Get array index & bounds */
  2399.     if (x < 0) {                        /* Check */
  2400.         printf("?Bad array name: %s\n",s);
  2401.         return(-9);
  2402.     }
  2403.     if (lo > -1) range[0] = lo;         /* Set range */
  2404.     if (hi > -1) range[1] = hi;
  2405.     ap = a_ptr[x];                      /* Get pointer to array element list */
  2406.     if (!ap) {                          /* Check */
  2407.         printf("?Array not declared: %s\n", s);
  2408.         return(-9);
  2409.     }
  2410.     if (range[0] < 0)                   /* Starting element */
  2411.       range[0] = 1;
  2412.     if (range[1] < 0)                   /* Final element */
  2413.       range[1] = a_dim[x];
  2414.     if (range[1] > a_dim[x]) {
  2415.         printf("?range %d:%d exceeds array dimension %d\n",
  2416.                range[0],range[1],a_dim[x]
  2417.                );
  2418.         return(-9);
  2419.     }
  2420.     ap += range[0];
  2421.     xs = range[1] - range[0] + 1;       /* Number of elements to sort */
  2422.     if (xs < 1) {                       /* Check */
  2423.         printf("?Bad range: %d:%d\n",range[0],range[1]);
  2424.         return(-9);
  2425.     }
  2426.     if (xk < 0) xk = 0;                 /* Key position */
  2427.     if (xr < 0) xr = 0;                 /* Reverse flag */
  2428.     if (xn)                             /* Numeric flag */
  2429.       xc = 2;
  2430.     else if (xc < 0)                    /* Not numeric */
  2431.       xc = inpcas[cmdlvl];              /* so alpha case option */
  2432.  
  2433.     if (*p) {                           /* Parallel array given? */
  2434.         y = xarray(p);                  /* Yes, get its index. */
  2435.         if (y < 0) {
  2436.             printf("?Bad array name: %s\n", p);
  2437.             return(-9);
  2438.         }
  2439.         if (y != x) {                   /* If the 2 arrays are different  */
  2440.             xp = a_ptr[y];              /* Pointer to 2nd array element list */
  2441.             if (!xp) {
  2442.                 printf("?Array not declared: %s\n", p);
  2443.                 return(-9);
  2444.             }
  2445.             if (a_dim[y] < range[1]) {
  2446.                 printf("?Array %s smaller than %s\n", p, s);
  2447.                 return(-9);
  2448.             }
  2449.             xp += range[0];             /* Set base to same as 1st array */
  2450.         }
  2451.     }
  2452.     sh_sort(ap,xp,xs,xk,xr,xc);         /* Sort the array(s) */
  2453.     return(success = 1);                /* Always succeeds */
  2454. }
  2455. #endif /* NOSPL */
  2456.  
  2457. static struct keytab purgtab[] = {      /* PURGE command switches */
  2458.     { "/after",        PU_AFT,  CM_ARG },
  2459.     { "/ask",          PU_ASK,  0 },
  2460.     { "/before",       PU_BEF,  CM_ARG },
  2461.     { "/delete",       PU_DELE, CM_INV },
  2462. #ifdef UNIXOROSK
  2463.     { "/dotfiles",     PU_DOT,  0 },
  2464. #endif /* UNIXOROSK */
  2465.     { "/except",       PU_EXC,  CM_ARG },
  2466.     { "/heading",      PU_HDG,  0 },
  2467.     { "/keep",         PU_KEEP, CM_ARG },
  2468.     { "/larger-than",  PU_LAR,  CM_ARG },
  2469.     { "/list",         PU_LIST, 0 },
  2470.     { "/log",          PU_LIST, CM_INV },
  2471.     { "/noask",        PU_NASK, 0 },
  2472.     { "/nodelete",     PU_NODE, CM_INV },
  2473. #ifdef UNIXOROSK
  2474.     { "/nodotfiles",   PU_NODOT,0 },
  2475. #endif /* UNIXOROSK */
  2476.     { "/noheading",    PU_NOH,  0 },
  2477.     { "/nol",          PU_NOLI, CM_INV|CM_ABR },
  2478.     { "/nolist",       PU_NOLI, 0 },
  2479.     { "/nolog",        PU_NOLI, CM_INV },
  2480. #ifdef CK_TTGWSIZ
  2481.     { "/nopage",       PU_NOPA, 0 },
  2482. #endif /* CK_TTGWSIZ */
  2483.     { "/not-after",    PU_NAF,  CM_ARG },
  2484.     { "/not-before",   PU_NBF,  CM_ARG },
  2485.     { "/not-since",    PU_NAF,  CM_INV|CM_ARG },
  2486. #ifdef CK_TTGWSIZ
  2487.     { "/page",         PU_PAGE, 0 },
  2488. #endif /* CK_TTGWSIZ */
  2489.     { "/quiet",        PU_QUIE, CM_INV },
  2490. #ifdef RECURSIVE
  2491.     { "/recursive",    PU_RECU, 0 },
  2492. #endif /* RECURSIVE */
  2493.     { "/since",        PU_AFT,  CM_ARG|CM_INV },
  2494.     { "/simulate",     PU_NODE, 0 },
  2495.     { "/smaller-than", PU_SMA,  CM_ARG },
  2496.     { "/verbose",      PU_VERB, CM_INV }
  2497. };
  2498. static int npurgtab = sizeof(purgtab)/sizeof(struct keytab);
  2499.  
  2500.  
  2501.  
  2502.  
  2503.  
  2504. int
  2505. bkupnum(s,i) char * s; int *i; {
  2506.     int k = 0, pos = 0;
  2507.     char * p = NULL, *q;
  2508.     *i = pos;
  2509.     if (!s) s = "";
  2510.     if (!*s)
  2511.       return(-1);
  2512.     if ((k = strlen(s)) < 5)
  2513.       return(-1);
  2514.  
  2515.     if (s[k-1] != '~')
  2516.       return(-1);
  2517.     pos = k - 2;
  2518.     q = s + pos;
  2519.     while (q >= s && isdigit(*q)) {
  2520.         p = q--;
  2521.         pos--;
  2522.     }
  2523.     if (!p)
  2524.       return(-1);
  2525.     if (q < s+2)
  2526.       return(-1);
  2527.     if (*q != '~' || *(q-1) != '.')
  2528.       return(-1);
  2529.     pos--;
  2530.     *i = pos;
  2531.     debug(F111,"bkupnum",s+pos,pos);
  2532.     return(atoi(p));
  2533. }
  2534.  
  2535. #ifdef CKPURGE
  2536. /* Presently only for UNIX because we need direct access to the file array. */
  2537. /* Not needed for VMS anyway, because we don't make backup files there. */
  2538.  
  2539. #define MAXKEEP 32                      /* Biggest /KEEP: value */
  2540.  
  2541. static int
  2542.   pu_keep = 0, pu_list = 0, pu_dot = 0, pu_ask = 0, pu_hdg = 0;
  2543.  
  2544. #ifdef CK_TTGWSIZ
  2545. static int pu_page = -1;
  2546. #else
  2547. static int pu_page = 0;
  2548. #endif /* CK_TTGWSIZ */
  2549.  
  2550. #ifndef NOSHOW
  2551. VOID
  2552. showpurgopts() {                        /* SHOW PURGE command options */
  2553.     int x = 0;
  2554.     extern int optlines;
  2555.     prtopt(&optlines,"PURGE");
  2556.     if (pu_ask > -1) {
  2557.         x++;
  2558.         prtopt(&optlines, pu_ask ? "/ASK" : "/NOASK");
  2559.     }
  2560. #ifdef UNIXOROSK
  2561.     if (pu_dot > -1) {
  2562.         x++;
  2563.         prtopt(&optlines, pu_dot ? "/DOTFILES" : "/NODOTFILES");
  2564.     }
  2565. #endif /* UNIXOROSK */
  2566.     if (pu_keep > -1) {
  2567.         x++;
  2568.         ckmakmsg(tmpbuf,TMPBUFSIZ,"/KEEP:",ckitoa(pu_keep),NULL,NULL);
  2569.         prtopt(&optlines,tmpbuf);
  2570.     }
  2571.     if (pu_list > -1) {
  2572.         x++;
  2573.         prtopt(&optlines, pu_list ? "/LIST" : "/NOLIST");
  2574.     }
  2575.     if (pu_hdg > -1) {
  2576.         x++;
  2577.         prtopt(&optlines, pu_hdg ? "/HEADING" : "/NOHEADING");
  2578.     }
  2579. #ifdef CK_TTGWSIZ
  2580.     if (pu_page > -1) {
  2581.         x++;
  2582.         prtopt(&optlines, pu_page ? "/PAGE" : "/NOPAGE");
  2583.     }
  2584. #endif /* CK_TTGWSIZ */
  2585.     if (!x) prtopt(&optlines,"(no options set)");
  2586.     prtopt(&optlines,"");
  2587. }
  2588. #endif /* NOSHOW */
  2589.  
  2590. int
  2591. setpurgopts() {                         /* Set PURGE command options */
  2592.     int c, z, getval = 0;
  2593.     int
  2594.       x_keep  = -1, x_list = -1, x_page = -1,
  2595.       x_hdg   = -1, x_ask  = -1, x_dot  = -1;
  2596.  
  2597.     while (1) {
  2598.         if ((y = cmswi(purgtab,npurgtab,"Switch","",xxstring)) < 0) {
  2599.             if (y == -3)
  2600.               break;
  2601.             else
  2602.               return(y);
  2603.         }
  2604.         c = cmgbrk();
  2605.         if ((getval = (c == ':' || c == '=')) && !(cmgkwflgs() & CM_ARG)) {
  2606.             printf("?This switch does not take an argument\n");
  2607.             return(-9);
  2608.         }
  2609.         if (!getval && (cmgkwflgs() & CM_ARG)) {
  2610.             printf("?This switch requires an argument\n");
  2611.             return(-9);
  2612.         }
  2613.         switch (y) {
  2614.           case PU_KEEP:
  2615.             z = 1;
  2616.             if (c == ':' || c == '=')
  2617.               if ((y = cmnum("How many backup files to keep",
  2618.                              "1",10,&z,xxstring)) < 0)
  2619.                 return(y);
  2620.             if (z < 0 || z > MAXKEEP) {
  2621.                 printf("?Please specify a number between 0 and %d\n",
  2622.                        MAXKEEP
  2623.                        );
  2624.                 return(-9);
  2625.             }
  2626.             x_keep = z;
  2627.             break;
  2628.           case PU_LIST:
  2629.           case PU_VERB:
  2630.             x_list = 1;
  2631.             break;
  2632.           case PU_QUIE:
  2633.           case PU_NOLI:
  2634.             x_list = 0;
  2635.             break;
  2636. #ifdef CK_TTGWSIZ
  2637.           case PU_PAGE:
  2638.             x_page = 1;
  2639.             break;
  2640.           case PU_NOPA:
  2641.             x_page = 0;
  2642.             break;
  2643. #endif /* CK_TTGWSIZ */
  2644.           case PU_HDG:
  2645.             x_hdg = 1;
  2646.             break;
  2647.           case PU_NOH:
  2648.             x_hdg = 0;
  2649.             break;
  2650.           case PU_ASK:
  2651.             x_ask = 1;
  2652.             break;
  2653.           case PU_NASK:
  2654.             x_ask = 0;
  2655.             break;
  2656. #ifdef UNIXOROSK
  2657.           case PU_DOT:
  2658.             x_dot = 1;
  2659.             break;
  2660.           case PU_NODOT:
  2661.             x_dot = 0;
  2662.             break;
  2663. #endif /* UNIXOROSK */
  2664.           default:
  2665.             printf("?This option can not be set\n");
  2666.             return(-9);
  2667.         }
  2668.     }
  2669.     if ((x = cmcfm()) < 0)              /* Get confirmation */
  2670.       return(x);
  2671.     if (x_keep > -1)                    /* Set PURGE defaults. */
  2672.       pu_keep = x_keep;
  2673.     if (x_list > -1)
  2674.       pu_list = x_list;
  2675. #ifdef CK_TTGWSIZ
  2676.     if (x_page > -1)
  2677.       pu_page = x_page;
  2678. #endif /* CK_TTGWSIZ */
  2679.     if (x_hdg > -1)
  2680.       pu_hdg = x_hdg;
  2681.     if (x_ask > -1)
  2682.       pu_ask = x_ask;
  2683.     if (x_dot > -1)
  2684.       pu_dot = x_dot;
  2685.     return(success = 1);
  2686. }
  2687.  
  2688. int
  2689. dopurge() {                             /* Do the PURGE command */
  2690.     extern char ** mtchs;
  2691.     extern int xaskmore, cmd_rows, recursive;
  2692.     int simulate = 0, asking = 0;
  2693.     int listing = 0, paging = -1, lines = 0, deleting = 1, errors = 0;
  2694.     struct FDB sw, sf, cm;
  2695.     int g, i, j, k, m = 0, n, x, y, z, done = 0, count = 0, flags = 0;
  2696.     int tokeep = 0, getval = 0, havename = 0, confirmed = 0;
  2697.     int xx[MAXKEEP+1];                  /* Array of numbers to keep */
  2698.     int min = -1;
  2699.     int x_hdg = 0, fs = 0, rc = 0;
  2700.     CK_OFF_T minsize = -1L, maxsize = -1L;
  2701.     char namebuf[CKMAXPATH+4];
  2702.     char basebuf[CKMAXPATH+4];
  2703.     char
  2704.       * pu_aft = NULL,
  2705.       * pu_bef = NULL,
  2706.       * pu_naf = NULL,
  2707.       * pu_nbf = NULL,
  2708.       * pu_exc = NULL;
  2709.     char * pxlist[8];                   /* Exception list */
  2710.  
  2711.     if (pu_keep > -1)                   /* Set PURGE defaults. */
  2712.       tokeep = pu_keep;
  2713.     if (pu_list > -1)
  2714.       listing = pu_list;
  2715. #ifdef CK_TTGWSIZ
  2716.     if (pu_page > -1)
  2717.       paging = pu_page;
  2718. #endif /* CK_TTGWSIZ */
  2719.  
  2720.     for (i = 0; i <= MAXKEEP; i++)      /* Clear this number buffer */
  2721.       xx[i] = 0;
  2722.     for (i = 0; i < 8; i++)             /* Initialize these... */
  2723.       pxlist[i] = NULL;
  2724.  
  2725.     g_matchdot = matchdot;              /* Save these... */
  2726.  
  2727.     cmfdbi(&sw,                         /* 1st FDB - PURGE switches */
  2728.            _CMKEY,                      /* fcode */
  2729.            "Filename or switch",        /* hlpmsg */
  2730.            "",                          /* default */
  2731.            "",                          /* addtl string data */
  2732.            npurgtab,                    /* addtl numeric data 1: tbl size */
  2733.            4,                           /* addtl numeric data 2: 4 = cmswi */
  2734.            xxstring,                    /* Processing function */
  2735.            purgtab,                     /* Keyword table */
  2736.            &sf                          /* Pointer to next FDB */
  2737.            );
  2738.     cmfdbi(&sf,                         /* 2nd FDB - filespec to purge */
  2739.            _CMIFI,                      /* fcode */
  2740.            "",
  2741.            "",                          /* default */
  2742.            "",                          /* addtl string data */
  2743.            0,                           /* addtl numeric data 1 */
  2744.            0,                           /* addtl numeric data 2 */
  2745.            xxstring,
  2746.            NULL,
  2747.            &cm
  2748.            );
  2749.     cmfdbi(&cm,                         /* Or premature confirmation */
  2750.            _CMCFM,                      /* fcode */
  2751.            "",                          /* hlpmsg */
  2752.            "",                          /* default */
  2753.            "",                          /* addtl string data */
  2754.            0,                           /* addtl numeric data 1 */
  2755.            0,                           /* addtl numeric data 2 */
  2756.            NULL,
  2757.            NULL,
  2758.            NULL
  2759.            );
  2760.  
  2761.     while (!havename && !confirmed) {
  2762.         x = cmfdb(&sw);                 /* Parse something */
  2763.         if (x < 0) {                    /* Error */
  2764.             rc = x;
  2765.             goto xpurge;
  2766.         } else if (cmresult.fcode == _CMKEY) {
  2767.             char c;
  2768.             c = cmgbrk();
  2769.             if ((getval = (c == ':' || c == '=')) && !(cmgkwflgs() & CM_ARG)) {
  2770.                 printf("?This switch does not take an argument\n");
  2771.                 rc = -9;
  2772.                 goto xpurge;
  2773.             }
  2774.             if (!getval && (cmgkwflgs() & CM_ARG)) {
  2775.                 printf("?This switch requires an argument\n");
  2776.                 rc = -9;
  2777.                 goto xpurge;
  2778.             }
  2779.             switch (k = cmresult.nresult) {
  2780.               case PU_KEEP:
  2781.                 z = 1;
  2782.                 if (c == ':' || c == '=') {
  2783.                     if ((y = cmnum("How many backup files to keep",
  2784.                                    "1",10,&z,xxstring)) < 0) {
  2785.                         rc = y;
  2786.                         goto xpurge;
  2787.                     }
  2788.                 }
  2789.                 if (z < 0 || z > MAXKEEP) {
  2790.                     printf("?Please specify a number between 0 and %d\n",
  2791.                            MAXKEEP
  2792.                            );
  2793.                     rc = -9;
  2794.                     goto xpurge;
  2795.                 }
  2796.                 tokeep = z;
  2797.                 break;
  2798.               case PU_LIST:
  2799.                 listing = 1;
  2800.                 break;
  2801.               case PU_NOLI:
  2802.                 listing = 0;
  2803.                 break;
  2804. #ifdef CK_TTGWSIZ
  2805.               case PU_PAGE:
  2806.                 paging = 1;
  2807.                 break;
  2808.               case PU_NOPA:
  2809.                 paging = 0;
  2810.                 break;
  2811. #endif /* CK_TTGWSIZ */
  2812.               case PU_DELE:
  2813.                 deleting = 1;
  2814.                 break;
  2815.               case PU_NODE:
  2816.                 deleting = 0;
  2817.                 simulate = 1;
  2818.                 listing = 1;
  2819.                 break;
  2820.               case PU_ASK:
  2821.                 asking = 1;
  2822.                 break;
  2823.               case PU_NASK:
  2824.                 asking = 0;
  2825.                 break;
  2826.               case PU_AFT:
  2827.               case PU_BEF:
  2828.               case PU_NAF:
  2829.               case PU_NBF:
  2830.                 if ((x = cmdate("File-time","",&s,0,xxstring)) < 0) {
  2831.                     if (x == -3) {
  2832.                         printf("?Date-time required\n");
  2833.                         rc = -9;
  2834.                     } else
  2835.                       rc = x;
  2836.                     goto xpurge;
  2837.                 }
  2838.                 fs++;
  2839.                 switch (k) {
  2840.                   case PU_AFT: makestr(&pu_aft,s); break;
  2841.                   case PU_BEF: makestr(&pu_bef,s); break;
  2842.                   case PU_NAF: makestr(&pu_naf,s); break;
  2843.                   case PU_NBF: makestr(&pu_nbf,s); break;
  2844.                 }
  2845.                 break;
  2846.               case PU_SMA:
  2847.               case PU_LAR:
  2848.                 if ((x = cmnum("File size in bytes","0",10,&y,xxstring)) < 0) {
  2849.                     rc = x;
  2850.                     goto xpurge;
  2851.                 }
  2852.                 fs++;
  2853.                 switch (cmresult.nresult) {
  2854.                   case PU_SMA: minsize = y; break;
  2855.                   case PU_LAR: maxsize = y; break;
  2856.                 }
  2857.                 break;
  2858.               case PU_DOT:
  2859.                 matchdot = 1;
  2860.                 break;
  2861.               case PU_NODOT:
  2862.                 matchdot = 0;
  2863.                 break;
  2864.               case PU_EXC:
  2865.                 if ((x = cmfld("Pattern","",&s,xxstring)) < 0) {
  2866.                     if (x == -3) {
  2867.                         printf("?Pattern required\n");
  2868.                         rc = -9;
  2869.                     } else
  2870.                       rc = x;
  2871.                     goto xpurge;
  2872.                 }
  2873.                 fs++;
  2874.                 makestr(&pu_exc,s);
  2875.                 break;
  2876.               case PU_HDG:
  2877.                 x_hdg = 1;
  2878.                 break;
  2879. #ifdef RECURSIVE
  2880.               case PU_RECU:             /* /RECURSIVE */
  2881.                 recursive = 2;
  2882.                 break;
  2883. #endif /* RECURSIVE */
  2884.               default:
  2885.                 printf("?Not implemented yet - \"%s\"\n",atmbuf);
  2886.                 rc = -9;
  2887.                 goto xpurge;
  2888.             }
  2889.         } else if (cmresult.fcode == _CMIFI) {
  2890.             havename = 1;
  2891.         } else if (cmresult.fcode == _CMCFM) {
  2892.             confirmed = 1;
  2893.         } else {
  2894.             rc = -2;
  2895.             goto xpurge;
  2896.         }
  2897.     }
  2898.     if (havename) {
  2899. #ifdef CKREGEX
  2900.         ckmakmsg(line,LINBUFSIZ,cmresult.sresult,".~[1-9]*~",NULL,NULL);
  2901. #else
  2902.         ckmakmsg(line,LINBUFSIZ,cmresult.sresult,".~*~",NULL,NULL);
  2903. #endif /* CKREGEX */
  2904.     } else {
  2905. #ifdef CKREGEX
  2906.         ckstrncpy(line,"*.~[1-9]*~",LINBUFSIZ);
  2907. #else
  2908.         ckstrncpy(line,"*.~*~",LINBUFSIZ);
  2909. #endif /* CKREGEX */
  2910.     }
  2911.     if (!confirmed) {
  2912.         if ((x = cmcfm()) < 0) {
  2913.             rc = x;
  2914.             goto xpurge;
  2915.         }
  2916.     }
  2917.     /* Parse finished - now action */
  2918.  
  2919. #ifdef CK_LOGIN
  2920.     if (isguest) {
  2921.         printf("?File deletion by guests not permitted.\n");
  2922.         rc = -9;
  2923.         goto xpurge;
  2924.     }
  2925. #endif /* CK_LOGIN */
  2926.  
  2927. #ifdef CK_TTGWSIZ
  2928.     if (paging < 0)                     /* /[NO]PAGE not given */
  2929.       paging = xaskmore;                /* so use prevailing */
  2930. #endif /* CK_TTGWSIZ */
  2931.  
  2932.     lines = 0;
  2933.     if (x_hdg > 0) {
  2934.         printf("Purging %s, keeping %d...%s\n",
  2935.                s,
  2936.                tokeep,
  2937.                simulate ? " (SIMULATION)" : "");
  2938.         lines += 2;
  2939.     }
  2940.     flags = ZX_FILONLY;
  2941.     if (recursive) flags |= ZX_RECURSE;
  2942.     n = nzxpand(line,flags);            /* Get list of backup files */
  2943.     if (tokeep < 1) {                   /* Deleting all of them... */
  2944.         for (i = 0; i < n; i++) {
  2945.             if (fs) if (fileselect(mtchs[i],
  2946.                                    pu_aft,pu_bef,pu_naf,pu_nbf,
  2947.                                    minsize,maxsize,0,8,pxlist) < 1) {
  2948.                 if (listing > 0) {
  2949.                     printf(" %s (SKIPPED)\n",mtchs[i]);
  2950. #ifdef CK_TTGWSIZ
  2951.                     if (paging)
  2952.                       if (++lines > cmd_rows - 3) {
  2953.                           if (!askmore()) goto xpurge; else lines = 0;
  2954.                       }
  2955. #endif /* CK_TTGWSIZ */
  2956.                 }
  2957.                 continue;
  2958.             }
  2959.             if (asking) {
  2960.                 int x;
  2961.                 ckmakmsg(tmpbuf,TMPBUFSIZ," Delete ",mtchs[i],"?",NULL);
  2962.                 x = getyesno(tmpbuf,1);
  2963.                 switch (x) {
  2964.                   case 0: continue;
  2965.                   case 1: break;
  2966.                   case 2: goto xpurge;
  2967.                 }
  2968.             }
  2969.             x = deleting ? zdelet(mtchs[i]) : 0;
  2970.             if (x > -1) {
  2971.                 if (listing)
  2972.                   printf(" %s (%s)\n", mtchs[i],deleting ? "OK" : "SELECTED");
  2973.                 count++;
  2974.             } else {
  2975.                 errors++;
  2976.                 if (listing)
  2977.                   printf(" %s (FAILED)\n", mtchs[i]);
  2978.             }
  2979. #ifdef CK_TTGWSIZ
  2980.             if (listing && paging)
  2981.               if (++lines > cmd_rows - 3) {
  2982.                   if (!askmore()) goto xpurge; else lines = 0;
  2983.               }
  2984. #endif /* CK_TTGWSIZ */
  2985.         }
  2986.         goto xpurge;
  2987.     }
  2988.     if (n < tokeep) {                   /* Not deleting any */
  2989.         count = 0;
  2990.         if (listing)
  2991.           printf(" Matches = %d: Not enough to purge.\n",n);
  2992.         goto xpurge;
  2993.     }
  2994.  
  2995.     /* General case - delete some but not others */
  2996.  
  2997.     sh_sort(mtchs,NULL,n,0,0,filecase); /* Alphabetize the list (ESSENTIAL) */
  2998.  
  2999.     g = 0;                              /* Start of current group */
  3000.     for (i = 0; i < n; i++) {           /* Go thru sorted file list */
  3001.         x = znext(namebuf);             /* Get next file */
  3002.         if (x < 1 || !namebuf[0] || i == n - 1) /* No more? */
  3003.           done = 1;                     /* NOTE: 'done' must be 0 or 1 only */
  3004.         if (fs) if (fileselect(namebuf,
  3005.                                pu_aft,pu_bef,pu_naf,pu_nbf,
  3006.                                minsize,maxsize,0,8,pxlist) < 1) {
  3007.             if (listing > 0) {
  3008.                 printf(" %s (SKIPPED)\n",namebuf);
  3009.                 if (++lines > cmd_rows - 3)
  3010.                   if (!askmore()) goto xpurge; else lines = 0;
  3011.             }
  3012.             continue;
  3013.         }
  3014.         if (x > 0)
  3015.           if ((m = bkupnum(namebuf,&z)) < 0) /* This file's backup number. */
  3016.             continue;
  3017.         for (j = 0; j < tokeep; j++) {  /* Insert in list. */
  3018.             if (m > xx[j]) {
  3019.                 for (k = tokeep - 1; k > j; k--)
  3020.                   xx[k] = xx[k-1];
  3021.                 xx[j] = m;
  3022.                 break;
  3023.             }
  3024.         }
  3025.         /* New group? */
  3026.         if (done || (i > 0 && ckstrcmp(namebuf,basebuf,z,1))) {
  3027.             if (i + done - g > tokeep) { /* Do we have enough to purge? */
  3028.                 min = xx[tokeep-1];     /* Yes, lowest backup number to keep */
  3029.                 debug(F111,"dopurge group",basebuf,min);
  3030.                 for (j = g; j < i + done; j++) { /* Go through this group */
  3031.                     x = bkupnum(mtchs[j],&z);    /* Get file backup number */
  3032.                     if (x > 0 && x < min) {      /* Below minimum? */
  3033.                         x = deleting ? zdelet(mtchs[j]) : 0;
  3034.                         if (x < 0) errors++;
  3035.                         if (listing)
  3036.                           printf(" %s (%s)\n",
  3037.                                  mtchs[j],
  3038.                                  ((x < 0) ? "ERROR" :
  3039.                                   (deleting ? "DELETED" : "SELECTED"))
  3040.                                  );
  3041.                         count++;
  3042.                     } else if (listing) /* Not below minimum - keep this one */
  3043.                       printf(" %s (KEPT)\n",mtchs[j]);
  3044. #ifdef CK_TTGWSIZ
  3045.                     if (listing && paging)
  3046.                       if (++lines > cmd_rows - 3) {
  3047.                           if (!askmore()) goto xpurge; else lines = 0;
  3048.                       }
  3049. #endif /* CK_TTGWSIZ */
  3050.                 }
  3051.             } else if (listing && paging) { /* Not enough to purge */
  3052.                 printf(" %s.~*~ (KEPT)\n",basebuf);
  3053. #ifdef CK_TTGWSIZ
  3054.                 if (++lines > cmd_rows - 3) {
  3055.                     if (!askmore()) goto xpurge; else lines = 0;
  3056.                 }
  3057. #endif /* CK_TTGWSIZ */
  3058.             }
  3059.             for (j = 0; j < tokeep; j++) /* Clear the backup number list */
  3060.               xx[j] = 0;
  3061.             g = i;                      /* Reset the group pointer */
  3062.         }
  3063.         if (done)                       /* No more files, done. */
  3064.           break;
  3065.         strncpy(basebuf,namebuf,z);     /* Set basename of this file */
  3066.         basebuf[z] = NUL;
  3067.     }
  3068.   xpurge:                               /* Common exit point */
  3069.     if (g_matchdot > -1) {
  3070.         matchdot = g_matchdot;          /* Restore these... */
  3071.         g_matchdot = -1;
  3072.     }
  3073.     if (rc < 0) return(rc);             /* Parse error */
  3074.     if (x_hdg)
  3075.       printf("Files purged: %d%s\n",
  3076.              count,
  3077.              deleting ? "" : " (not really)"
  3078.              );
  3079.     return(success = count > 0 ? 1 : (errors > 0) ? 0 : 1);
  3080. }
  3081. #endif /* CKPURGE */
  3082.  
  3083. #ifndef NOXFER
  3084. #ifndef NOLOCAL
  3085. int
  3086. doxdis(which) int which; {        /* 1 = Kermit, 2 = FTP */
  3087.     extern int nolocal;
  3088.     int x, y = 0, z;
  3089. #ifdef NEWFTP
  3090.     extern int ftp_dis;
  3091. #endif /* NEWFTP */
  3092.  
  3093. #ifdef COMMENT
  3094.     char *s;
  3095. #endif /* COMMENT */
  3096.  
  3097.     if ((x = cmkey(fdtab,nfdtab,"file transfer display style","",
  3098.                    xxstring)) < 0)
  3099.       return(x);
  3100. #ifdef CK_PCT_BAR
  3101.     if ((y = cmkey(fdftab,2,"","thermometer",xxstring)) < 0)
  3102.       return(y);
  3103. #endif /* CK_PCT_BAR */
  3104.     if ((z = cmcfm()) < 0) return(z);
  3105. #ifdef CK_CURSES
  3106.     if (x == XYFD_C) {                  /* FULLSCREEN */
  3107. #ifdef COMMENT
  3108. #ifndef MYCURSES
  3109.         extern char * trmbuf;           /* Real curses */
  3110.         int z;
  3111. #endif /* MYCURSES */
  3112. #endif /* COMMENT */
  3113.  
  3114.         if (nolocal)                    /* Nothing to do in this case */
  3115.       return(success = 1);
  3116.  
  3117. #ifdef COMMENT
  3118. #ifndef MYCURSES
  3119. #ifndef VMS
  3120.         s = getenv("TERM");
  3121.         debug(F110,"doxdis TERM",s,0);
  3122.         if (!s) s = "";
  3123.         fxdinit(x);
  3124.         if (*s && trmbuf) {             /* Don't call tgetent */
  3125.             z = tgetent(trmbuf,s);      /* if trmbuf not allocated */
  3126.             debug(F111,"doxdis tgetent",s,z);
  3127.         } else {
  3128.             z = 0;
  3129.             debug(F110,"doxdis tgetent skipped",s,0);
  3130.         }
  3131.         if (z < 1) {
  3132.             printf("Sorry, terminal type unknown: \"%s\"\n",s);
  3133.             return(success = 0);
  3134.         }
  3135. #endif /* VMS */
  3136. #endif /* MYCURSES */
  3137. #else
  3138.         fxdinit(x);
  3139. #endif /* COMMENT */
  3140.  
  3141. #ifdef CK_PCT_BAR
  3142.         thermometer = y;
  3143. #endif /* CK_PCT_BAR */
  3144.  
  3145.         line[0] = '\0';                 /* (What's this for?) */
  3146.     }
  3147. #endif /* CK_CURSES */
  3148.     if (which == 1)            /* It's OK. */
  3149.       fdispla = x;
  3150. #ifdef NEWFTP
  3151.     else if (which == 2)
  3152.       ftp_dis = x;
  3153. #endif /* NEWFTP */
  3154.     return(success = 1);
  3155. }
  3156. #endif /* NOLOCAL */
  3157. #endif /* NOXFER */
  3158.  
  3159. int
  3160. setfil(rmsflg) int rmsflg; {
  3161. #ifdef COMMENT
  3162.     extern int en_del;
  3163. #endif /* COMMENT */
  3164. #ifndef NOXFER
  3165.     if (rmsflg) {
  3166.         if ((y = cmkey(rfiltab,nrfilp,"Remote file parameter","",
  3167.                        xxstring)) < 0) {
  3168.             if (y == -3) {
  3169.                 printf("?Remote file parameter required\n");
  3170.                 return(-9);
  3171.             } else return(y);
  3172.         }
  3173.     } else {
  3174. #endif /* NOXFER */
  3175.         if ((y = cmkey(filtab,nfilp,"File parameter","",xxstring)) < 0)
  3176.           return(y);
  3177. #ifndef NOXFER
  3178.     }
  3179. #endif /* NOXFER */
  3180.     switch (y) {
  3181. #ifdef COMMENT                          /* Not needed */
  3182.       case XYFILB:                      /* Blocksize */
  3183.         if ((y = cmnum("file block size",ckitoa(DBLKSIZ),10,&z,xxstring)) < 0)
  3184.           return(y);
  3185.         if ((x = cmcfm()) < 0) return(x);
  3186.         if (rmsflg) {
  3187.             sstate = setgen('S', "311", ckitoa(z), "");
  3188.             return((int) sstate);
  3189.         } else {
  3190.             fblksiz = z;
  3191.             return(success = 1);
  3192.         }
  3193. #endif /* COMMENT */
  3194.  
  3195. #ifndef NOXFER
  3196.       case XYFILS:                      /* Byte size */
  3197.         if ((y = cmnum("file byte size (7 or 8)","8",10,&z,xxstring)) < 0)
  3198.           return(y);
  3199.         if (z != 7 && z != 8) {
  3200.             printf("\n?The choices are 7 and 8\n");
  3201.             return(0);
  3202.         }
  3203.         if ((y = cmcfm()) < 0) return(y);
  3204.         if (z == 7) fmask = 0177;
  3205.         else if (z == 8) fmask = 0377;
  3206.         return(success = 1);
  3207.  
  3208. #ifndef NOCSETS
  3209.       case XYFILC: {                    /* Character set */
  3210.           char * csetname = NULL;
  3211.           extern int
  3212.             r_cset, s_cset, afcset[];   /* SEND CHARACTER-SET AUTO or MANUAL */
  3213.  
  3214.           struct FDB kw, fl;
  3215.           cmfdbi(&kw,                   /* First FDB - command switches */
  3216.                  _CMKEY,                /* fcode */
  3217.                  rmsflg ? "server character-set name" : "",  /* help */
  3218.                  "",                    /* default */
  3219.                  "",                    /* addtl string data */
  3220.                  nfilc,                 /* addtl numeric data 1: tbl size */
  3221.                  0,                     /* addtl numeric data 2: 0 = keyword */
  3222.                  xxstring,              /* Processing function */
  3223.                  fcstab,                /* Keyword table */
  3224.                  rmsflg ? &fl : NULL    /* Pointer to next FDB */
  3225.            );
  3226.           cmfdbi(&fl,                   /* Anything that doesn't match */
  3227.                  _CMFLD,                /* fcode */
  3228.                  "",                    /* hlpmsg */
  3229.                  "",                    /* default */
  3230.                  "",                    /* addtl string data */
  3231.                  0,                     /* addtl numeric data 1 */
  3232.                  0,                     /* addtl numeric data 2 */
  3233.                  xxstring,
  3234.                  NULL,
  3235.                  NULL
  3236.                  );
  3237.           if ((x = cmfdb(&kw)) < 0)
  3238.             return(x);
  3239.           if (cmresult.fcode == _CMKEY) {
  3240.               x = cmresult.nresult;
  3241.               csetname = fcsinfo[x].keyword;
  3242.           } else {
  3243.               ckstrncpy(line,cmresult.sresult,LINBUFSIZ);
  3244.               csetname = line;
  3245.           }
  3246.           if ((z = cmcfm()) < 0) return(z);
  3247.           if (rmsflg) {
  3248.               sstate = setgen('S', "320", csetname, "");
  3249.               return((int) sstate);
  3250.           }
  3251.           fcharset = x;
  3252.           if (s_cset == XMODE_A)        /* If SEND CHARACTER-SET is AUTO */
  3253.             if (x > -1 && x <= MAXFCSETS)
  3254.               if (afcset[x] > -1 && afcset[x] <= MAXTCSETS)
  3255.                 tcharset = afcset[x]; /* Pick corresponding xfer charset */
  3256.           setxlatype(tcharset,fcharset); /* Translation type */
  3257.           /* If I say SET FILE CHARACTER-SET blah, I want to be blah! */
  3258.           r_cset = XMODE_M;             /* Don't switch incoming set! */
  3259.           x = fcsinfo[fcharset].size;   /* Also set default x-bit charset */
  3260.           if (x == 128)                 /* 7-bit... */
  3261.             dcset7 = fcharset;
  3262.           else if (x == 256)            /* 8-bit... */
  3263.             dcset8 = fcharset;
  3264.           return(success = 1);
  3265.       }
  3266. #endif /* NOCSETS */
  3267.  
  3268. #ifndef NOLOCAL
  3269.       case XYFILD:                      /* Display */
  3270.         return(doxdis(1));        /* 1 == kermit */
  3271. #endif /* NOLOCAL */
  3272. #endif /* NOXFER */
  3273.  
  3274.       case XYFILA:                      /* End-of-line */
  3275. #ifdef NLCHAR
  3276.         s = "";
  3277.         if (NLCHAR == 015)
  3278.           s = "cr";
  3279.         else if (NLCHAR == 012)
  3280.           s = "lf";
  3281.         if ((x = cmkey(eoltab, neoltab,
  3282.                        "local text-file line terminator",s,xxstring)) < 0)
  3283.           return(x);
  3284. #else
  3285.         if ((x = cmkey(eoltab, neoltab,
  3286.                        "local text-file line terminator","crlf",xxstring)) < 0)
  3287.           return(x);
  3288. #endif /* NLCHAR */
  3289.         if ((z = cmcfm()) < 0) return(z);
  3290.         feol = (CHAR) x;
  3291.         return(success = 1);
  3292.  
  3293. #ifndef NOXFER
  3294.       case XYFILN:                      /* Names */
  3295.         if ((x = cmkey(fntab,nfntab,"how to handle filenames","converted",
  3296.                        xxstring)) < 0)
  3297.           return(x);
  3298.         if ((z = cmcfm()) < 0) return(z);
  3299.         if (rmsflg) {
  3300.             sstate = setgen('S', "301", ckitoa(1 - x), "");
  3301.             return((int) sstate);
  3302.         } else {
  3303.             ptab[protocol].fncn = x;    /* Set structure */
  3304.             fncnv = x;                  /* Set variable */
  3305.             f_save = x;                 /* And set "permanent" variable */
  3306.             return(success = 1);
  3307.         }
  3308.  
  3309.       case XYFILR:                      /* Record length */
  3310.         if ((y = cmnum("file record length",
  3311.                        ckitoa(DLRECL),10,&z,xxstring)) < 0)
  3312.           return(y);
  3313.         if ((x = cmcfm()) < 0) return(x);
  3314.         if (rmsflg) {
  3315.             sstate = setgen('S', "312", ckitoa(z), "");
  3316.             return((int) sstate);
  3317.         } else {
  3318.             frecl = z;
  3319.             return(success = 1);
  3320.         }
  3321.  
  3322. #ifdef COMMENT
  3323.       case XYFILO:                      /* Organization */
  3324.         if ((x = cmkey(forgtab,nforg,"file organization","sequential",
  3325.                        xxstring)) < 0)
  3326.           return(x);
  3327.         if ((y = cmcfm()) < 0) return(y);
  3328.         if (rmsflg) {
  3329.             sstate = setgen('S', "314", ckitoa(x), "");
  3330.             return((int) sstate);
  3331.         } else {
  3332.             forg = x;
  3333.             return(success = 1);
  3334.         }
  3335. #endif /* COMMENT */
  3336.  
  3337. #ifdef COMMENT                          /* Not needed */
  3338.       case XYFILF:                      /* Format */
  3339.         if ((x = cmkey(frectab,nfrec,"file record format","stream",
  3340.                        xxstring)) < 0)
  3341.           return(x);
  3342.         if ((y = cmcfm()) < 0) return(y);
  3343.         if (rmsflg) {
  3344.             sstate = setgen('S', "313", ckitoa(x), "");
  3345.             return((int) sstate);
  3346.         } else {
  3347.             frecfm = x;
  3348.             return(success = 1);
  3349.         }
  3350. #endif /* COMMENT */
  3351.  
  3352. #ifdef COMMENT
  3353.       case XYFILP:                      /* Printer carriage control */
  3354.         if ((x = cmkey(fcctab,nfcc,"file carriage control","newline",
  3355.                        xxstring)) < 0)
  3356.           return(x);
  3357.         if ((y = cmcfm()) < 0) return(y);
  3358.         if (rmsflg) {
  3359.             sstate = setgen('S', "315", ckitoa(x), "");
  3360.             return((int) sstate);
  3361.         } else {
  3362.             fcctrl = x;
  3363.             return(success = 1);
  3364.         }
  3365. #endif /* COMMENT */
  3366. #endif /* NOXFER */
  3367.  
  3368.       case XYFILT:                      /* Type */
  3369.         if ((x = cmkey(rmsflg ? rfttab  : fttab,
  3370.                        rmsflg ? nrfttyp : nfttyp,
  3371.                        "type of file transfer","text",xxstring)) < 0)
  3372.           return(x);
  3373.  
  3374. #ifdef VMS
  3375.         /* Allow VMS users to choose record format for binary files */
  3376.         if ((x == XYFT_B) && (rmsflg == 0)) {
  3377.             if ((x = cmkey(fbtab,nfbtyp,"VMS record format","fixed",
  3378.                            xxstring)) < 0)
  3379.               return(x);
  3380.         }
  3381. #endif /* VMS */
  3382.         if ((y = cmcfm()) < 0) return(y);
  3383.         binary = x;
  3384.         b_save = x;
  3385. #ifdef MAC
  3386.         (void) mac_setfildflg(binary);
  3387. #endif /* MAC */
  3388. #ifndef NOXFER
  3389.         if (rmsflg) {
  3390.             /* Allow for LABELED in VMS & OS/2 */
  3391.             sstate = setgen('S', "300", ckitoa(x), "");
  3392.             return((int) sstate);
  3393.         } else {
  3394. #endif /* NOXFER */
  3395.             return(success = 1);
  3396. #ifndef NOXFER
  3397.         }
  3398. #endif /* NOXFER */
  3399.  
  3400. #ifndef NOXFER
  3401.       case XYFILX:                      /* Collision Action */
  3402.         if ((x = cmkey(colxtab,ncolx,"Filename collision action","backup",
  3403.                        xxstring)) < 0)
  3404.           return(x);
  3405.         if ((y = cmcfm()) < 0) return(y);
  3406. #ifdef CK_LOGIN
  3407.         if (isguest) {
  3408.             /* Don't let guests change existing files */
  3409.             printf("?This command not valid for guests\n");
  3410.             return(-9);
  3411.         }
  3412. #endif /* CK_LOGIN */
  3413. #ifdef COMMENT
  3414.         /* Not appropriate - DISABLE DELETE only refers to server */
  3415.         if ((x == XYFX_X || x == XYFX_B || x == XYFX_U || x == XYFX_A) &&
  3416.             (!ENABLED(en_del))) {
  3417.             printf("?Sorry, file deletion is disabled.\n");
  3418.             return(-9);
  3419.         }
  3420. #endif /* COMMENT */
  3421.         fncact = x;
  3422.         ptab[protocol].fnca = x;
  3423.         if (rmsflg) {
  3424.             sstate = setgen('S', "302", ckitoa(fncact), "");
  3425.             return((int) sstate);
  3426.         } else {
  3427.             if (fncact == XYFX_R) ckwarn = 1; /* FILE WARNING implications */
  3428.             if (fncact == XYFX_X) ckwarn = 0; /* ... */
  3429.             return(success = 1);
  3430.         }
  3431.  
  3432.       case XYFILW:                      /* Warning/Write-Protect */
  3433.         if ((x = seton(&ckwarn)) < 0) return(x);
  3434.         if (ckwarn)
  3435.           fncact = XYFX_R;
  3436.         else
  3437.           fncact = XYFX_X;
  3438.         return(success = 1);
  3439.  
  3440. #ifdef CK_LABELED
  3441.       case XYFILL:                      /* LABELED FILE parameters */
  3442.         if ((x = cmkey(lbltab,nlblp,"Labeled file feature","",
  3443.                        xxstring)) < 0)
  3444.           return(x);
  3445.         if ((success = seton(&y)) < 0)
  3446.           return(success);
  3447.         if (y)                          /* Set or reset the selected bit */
  3448.           lf_opts |= x;                 /* in the options bitmask. */
  3449.         else
  3450.           lf_opts &= ~x;
  3451.         return(success);
  3452. #endif /* CK_LABELED */
  3453.  
  3454.       case XYFILI: {                    /* INCOMPLETE */
  3455.           extern struct keytab ifdatab[];
  3456.           extern int keep;
  3457.           if ((y = cmkey(ifdatab,3,"","auto",xxstring)) < 0) return(y);
  3458.           if ((x = cmcfm()) < 0) return(x);
  3459.           if (rmsflg) {
  3460.               sstate = setgen('S',
  3461.                               "310",
  3462.                               y == 0 ? "0" : (y == 1 ? "1" : "2"),
  3463.                               ""
  3464.                               );
  3465.               return((int) sstate);
  3466.           } else {
  3467.               keep = y;
  3468.               return(success = 1);
  3469.           }
  3470.       }
  3471.  
  3472. #ifdef CK_TMPDIR
  3473.       case XYFILG: {                    /* Download directory */
  3474.           int x;
  3475.           char *s;
  3476. #ifdef ZFNQFP
  3477.           struct zfnfp * fnp;
  3478. #endif /* ZFNQFP */
  3479. #ifdef MAC
  3480.           char temp[34];
  3481. #endif /* MAC */
  3482.  
  3483. #ifdef GEMDOS
  3484.           if ((x = cmdir("Name of local directory, or carriage return",
  3485.                          "",&s,
  3486.                          NULL)) < 0 ) {
  3487.               if (x != -3)
  3488.                 return(x);
  3489.           }
  3490. #else
  3491. #ifdef OS2
  3492.           if ((x = cmdir("Name of PC disk and/or directory,\n\
  3493.        or press the Enter key to use current directory",
  3494.                          "",&s,xxstring)) < 0 ) {
  3495.               if (x != -3)
  3496.                 return(x);
  3497.           }
  3498. #else
  3499. #ifdef MAC
  3500.           x = ckstrncpy(temp,zhome(),32);
  3501.           if (x > 0) if (temp[x-1] != ':') { temp[x] = ':'; temp[x+1] = NUL; }
  3502.           if ((x = cmtxt("Name of Macintosh volume and/or folder,\n\
  3503.  or press the Return key for the desktop on the boot disk",
  3504.                          temp,&s, xxstring)) < 0 )
  3505.             return(x);
  3506. #else
  3507.           if ((x = cmdir("Name of local directory, or carriage return",
  3508.                          "", &s, xxstring)) < 0 ) {
  3509.               if (x != -3)
  3510.                 return(x);
  3511.           }
  3512. #endif /* MAC */
  3513. #endif /* OS2 */
  3514. #endif /* GEMDOS */
  3515.           debug(F110,"download dir",s,0);
  3516.  
  3517. #ifndef MAC
  3518.           if (x == 2) {
  3519.               printf("?Wildcards not allowed in directory name\n");
  3520.               return(-9);
  3521.           }
  3522. #endif /* MAC */
  3523.  
  3524. #ifdef ZFNQFP
  3525.           if ((fnp = zfnqfp(s,TMPBUFSIZ - 1,tmpbuf))) {
  3526.               if (fnp->fpath)
  3527.                 if ((int) strlen(fnp->fpath) > 0)
  3528.                   s = fnp->fpath;
  3529.           }
  3530.           debug(F110,"download zfnqfp",s,0);
  3531. #endif /* ZFNQFP */
  3532.  
  3533.           ckstrncpy(line,s,LINBUFSIZ);  /* Make a safe copy */
  3534. #ifndef MAC
  3535.           if ((x = cmcfm()) < 0)        /* Get confirmation */
  3536.             return(x);
  3537. #endif /* MAC */
  3538.  
  3539. #ifdef CK_LOGIN
  3540.         if (isguest) {
  3541.             /* Don't let guests change existing files */
  3542.             printf("?This command not valid for guests\n");
  3543.             return(-9);
  3544.         }
  3545. #endif /* CK_LOGIN */
  3546.           x = strlen(s);
  3547.  
  3548.           if (x) {
  3549. #ifdef datageneral            /* AOS/VS */
  3550.               if (s[x-1] == ':')        /* homdir ends in colon, */
  3551.                 s[x-1] = NUL;           /* and "dir" doesn't like that... */
  3552. #else
  3553. #ifdef OS2ORUNIX            /* Unix or K-95... */
  3554.           if ((x < (LINBUFSIZ - 2)) && /* Add trailing dirsep */
  3555.           (s[x-1] != '/')) {    /* if none present.  */
  3556.           s[x] = '/';        /* Note that Windows path has */
  3557.           s[x+1] = NUL;        /* been canonicalized to forward */
  3558.           }                        /* slashes at this point. */
  3559. #endif /* OS2ORUNIX */
  3560. #endif /* datageneral */
  3561.               makestr(&dldir,s);
  3562.           } else
  3563.             makestr(&dldir,NULL);       /* dldir is NULL when not assigned */
  3564.  
  3565.           return(success = 1);
  3566.       }
  3567. #endif /* CK_TMPDIR */
  3568.       case XYFILY:
  3569.         return(setdest());
  3570. #endif /* NOXFER */
  3571.  
  3572. #ifdef CK_CTRLZ
  3573.       case XYFILV: {                    /* EOF */
  3574.           extern int eofmethod;
  3575.           if ((x = cmkey(eoftab,3,"end-of-file detection method","",
  3576.                          xxstring)) < 0)
  3577.             return(x);
  3578.           if ((y = cmcfm()) < 0)
  3579.             return(y);
  3580.           eofmethod = x;
  3581.           return(success = 1);
  3582.       }
  3583. #endif /* CK_CTRLZ */
  3584.  
  3585. #ifndef NOXFER
  3586. #ifdef UNIX
  3587.       case XYFILH: {                    /* OUTPUT */
  3588.           extern int zofbuffer, zobufsize, zofblock;
  3589. #ifdef DYNAMIC
  3590.           extern char * zoutbuffer;
  3591. #endif /* DYNAMIC */
  3592.  
  3593.           if ((x = cmkey(zoftab,nzoftab,"output file writing method","",
  3594.                          xxstring)) < 0)
  3595.             return(x);
  3596.           if (x == ZOF_BUF || x == ZOF_NBUF) {
  3597.               if ((y = cmnum("output buffer size","32768",10,&z,xxstring)) < 0)
  3598.                 return(y);
  3599.               if (z < 1) {
  3600.                   printf("?Bad size - %d\n", z);
  3601.                   return(-9);
  3602.               }
  3603.           }
  3604.           if ((y = cmcfm()) < 0) return(y);
  3605.           switch (x) {
  3606.             case ZOF_BUF:
  3607.             case ZOF_NBUF:
  3608.               zofbuffer = (x == ZOF_BUF);
  3609.               zobufsize = z;
  3610.               break;
  3611.             case ZOF_BLK:
  3612.             case ZOF_NBLK:
  3613.               zofblock = (x == ZOF_BLK);
  3614.               break;
  3615.           }
  3616. #ifdef DYNAMIC
  3617.           if (zoutbuffer) free(zoutbuffer);
  3618.           if (!(zoutbuffer = (char *)malloc(z))) {
  3619.               printf("MEMORY ALLOCATION ERROR - FATAL\n");
  3620.               doexit(BAD_EXIT,-1);
  3621.           } else
  3622.             zobufsize = z;
  3623. #else
  3624.           if (z <= OBUFSIZE) {
  3625.               zobufsize = z;
  3626.           } else {
  3627.               printf("?Sorry, %d is too big - %d is the maximum\n",z,OBUFSIZE);
  3628.               return(-9);
  3629.           }
  3630. #endif /* DYNAMIC */
  3631.           return(success = 1);
  3632.       }
  3633. #endif /* UNIX */
  3634.  
  3635. #ifdef PATTERNS
  3636.       case XYFIBP:                      /* BINARY-PATTERN */
  3637.       case XYFITP: {                    /* TEXT-PATTERN */
  3638.           char * tmp[FTPATTERNS];
  3639.           int i, n = 0;
  3640.           while (n < FTPATTERNS) {
  3641.               tmp[n] = NULL;
  3642.               if ((x = cmfld("Pattern","",&s,xxstring)) < 0)
  3643.                 break;
  3644.               ckstrncpy(line,s,LINBUFSIZ);
  3645.               s = brstrip(line);
  3646.               makestr(&(tmp[n++]),s);
  3647.           }
  3648.           if (x == -3) x = cmcfm();
  3649.           for (i = 0; i <= n; i++) {
  3650.               if (x > -1) {
  3651.                   if (y == XYFIBP)
  3652.                     makestr(&(binpatterns[i]),tmp[i]);
  3653.                   else
  3654.                     makestr(&(txtpatterns[i]),tmp[i]);
  3655.               }
  3656.               free(tmp[i]);
  3657.           }
  3658.           if (y == XYFIBP)              /* Null-terminate the list */
  3659.             makestr(&(binpatterns[i]),NULL);
  3660.           else
  3661.             makestr(&(txtpatterns[i]),NULL);
  3662.           return(x);
  3663.       }
  3664.  
  3665.       case XYFIPA:                      /* PATTERNS */
  3666.         if ((x = setonaut(&patterns)) < 0)
  3667.           return(x);
  3668.         return(success = 1);
  3669. #endif /* PATTERNS */
  3670. #endif /* NOXFER */
  3671.  
  3672. #ifdef UNICODE
  3673.       case XYFILU: {                    /* UCS */
  3674.           extern int ucsorder, ucsbom, byteorder;
  3675.           if ((x = cmkey(ucstab,nucstab,"","",xxstring)) < 0)
  3676.             return(x);
  3677.           switch (x) {
  3678.             case UCS_BYT:
  3679.               if ((y = cmkey(botab,nbotab,
  3680.                              "Byte order",
  3681.                              byteorder ? "little-endian" : "big-endian",
  3682.                              xxstring
  3683.                              )
  3684.                    ) < 0)
  3685.                 return(y);
  3686.               if ((x = cmcfm()) < 0)
  3687.                 return(x);
  3688.               ucsorder = y;
  3689.               return(success = 1);
  3690.             case UCS_BOM:
  3691.               if ((y = cmkey(onoff,2,"","on",xxstring)) < 0)
  3692.                 return(y);
  3693.               if ((x = cmcfm()) < 0)
  3694.                 return(x);
  3695.               ucsbom = y;
  3696.               return(success = 1);
  3697.             default:
  3698.               return(-2);
  3699.           }
  3700.       }
  3701. #endif /* UNICODE */
  3702.  
  3703. #ifndef datageneral
  3704.       case XYF_INSP: {                  /* SCAN (INSPECTION) */
  3705.           extern int filepeek, nscanfile;
  3706.           if ((x = cmkey(onoff,2,"","on",xxstring)) < 0)
  3707.             return(x);
  3708.           if (y) {
  3709.               if ((y = cmnum("How much to scan",ckitoa(SCANFILEBUF),
  3710.                              10,&z,xxstring)) < 0)
  3711.                 return(y);
  3712.           }
  3713.           if ((y = cmcfm()) < 0)
  3714.             return(y);
  3715. #ifdef VMS
  3716.           filepeek = 0;
  3717.           nscanfile = 0;
  3718.           return(success = 0);
  3719. #else
  3720.           filepeek = x;
  3721.           nscanfile = z;
  3722.           return(success = 1);
  3723. #endif /* VMS */
  3724.       }
  3725. #endif /* datageneral */
  3726.  
  3727.       case XYF_DFLT:
  3728.         y = 0;
  3729. #ifndef NOCSETS
  3730.         if ((y = cmkey(fdfltab,nfdflt,"","",xxstring)) < 0)
  3731.           return(y);
  3732.         if (y == 7 || y == 8) {
  3733.             if (y == 7)
  3734.               s = fcsinfo[dcset7].keyword;
  3735.             else
  3736.               s = fcsinfo[dcset8].keyword;
  3737.             if ((x = cmkey(fcstab,nfilc,"character-set",s,xxstring)) < 0)
  3738.               return(x);
  3739.         }
  3740.         ckstrncpy(line,fcsinfo[x].keyword,LINBUFSIZ);
  3741.         s = line;
  3742. #endif /* NOCSETS */
  3743.         if ((z = cmcfm()) < 0)
  3744.           return(z);
  3745.         switch (y) {
  3746. #ifndef NOCSETS
  3747.           case 7:
  3748.             if (fcsinfo[x].size != 128) {
  3749.                 printf("%s - Not a 7-bit set\n",s);
  3750.                 return(-9);
  3751.             }
  3752.             dcset7 = x;
  3753.             break;
  3754.           case 8:
  3755.             if (fcsinfo[x].size != 256) {
  3756.                 printf("%s - Not an 8-bit set\n",s);
  3757.                 return(-9);
  3758.             }
  3759.             dcset8 = x;
  3760.             break;
  3761. #endif /* NOCSETS */
  3762.           default:
  3763.             return(-2);
  3764.         }
  3765.         return(success = 1);
  3766.  
  3767. #ifndef NOXFER
  3768.       case 9997:                        /* FASTLOOKUPS */
  3769.         return(success = seton(&stathack));
  3770. #endif /* NOXFER */
  3771.  
  3772. #ifdef UNIX
  3773. #ifdef DYNAMIC
  3774.       case XYF_LSIZ: {                  /* LISTSIZE */
  3775.           int zz;
  3776.           y = cmnum("Maximum number of filenames","",10,&x,xxstring);
  3777.           if ((x = setnum(&zz,x,y,-1)) < 0)
  3778.             return(x);
  3779.           if (zsetfil(zz,3) < 0) {
  3780.               printf("?Memory allocation failure\n");
  3781.               return(-9);
  3782.           }
  3783.           return(success = 1);
  3784.       }
  3785.       case XYF_SSPA: {                  /* STRINGSPACE */
  3786.           int zz;
  3787.           y = cmnum("Number of characters for filename list",
  3788.                     "",10,&x,xxstring);
  3789.           if ((x = setnum(&zz,x,y,-1)) < 0)
  3790.             return(x);
  3791.           if (zsetfil(zz,1) < 0) {
  3792.               printf("?Memory allocation failure\n");
  3793.               return(-9);
  3794.           }
  3795.           return(success = 1);
  3796.       }
  3797.  
  3798. #endif /* DYNAMIC */
  3799. #endif /* UNIX */
  3800.  
  3801.       default:
  3802.         printf("?unexpected file parameter\n");
  3803.         return(-2);
  3804.     }
  3805. }
  3806.  
  3807. #ifdef UNIX
  3808. #ifndef NOPUTENV
  3809. #ifdef BIGBUFOK
  3810. #define NPUTENVS 4096
  3811. #else
  3812. #define NPUTENVS 128
  3813. #endif    /* BIGBUFOK */
  3814. /* environment variables must be static, not automatic */
  3815.  
  3816. static char * putenvs[NPUTENVS];    /* Array of environment var strings */
  3817. static int nputenvs = -1;        /* Pointer into array */
  3818. /*
  3819.   If anyone ever notices the limitation on the number of PUTENVs, the list
  3820.   can be made dynamic, we can recycle entries with the same name, etc.
  3821. */
  3822. int
  3823. doputenv(s1, s2) char * s1; char * s2; {
  3824.     char * s, * t = tmpbuf;        /* Create or alter environment var */
  3825.  
  3826.     if (nputenvs == -1) {        /* Table not used yet */
  3827.     int i;                /* Initialize the pointers */
  3828.     for (i = 0; i < NPUTENVS; i++)
  3829.       putenvs[i] = NULL;
  3830.     nputenvs = 0;
  3831.     }
  3832.     if (!s1) return(1);            /* Nothing to do */
  3833.     if (!*s1) return(1);        /* ditto */
  3834.  
  3835.     if (ckindex("=",s1,0,0,0)) {    /* Does the name contain an '='? */
  3836.     printf(                /* putenv() does not allow this. */
  3837.      /* This also catches the 'putenv name=value' case */
  3838.          "?PUTENV - Equal sign in variable name - 'help putenv' for info.\n");
  3839.         return(-9);
  3840.     }
  3841.     nputenvs++;                /* Point to next free string */
  3842.  
  3843.     debug(F111,"doputenv s1",s1,nputenvs);
  3844.     debug(F111,"doputenv s2",s2,nputenvs);
  3845.  
  3846.     if (nputenvs > NPUTENVS - 1) {    /* Notice the end */
  3847.     printf("?PUTENV - static buffer space exhausted\n");
  3848.     return(-9);
  3849.     }
  3850.     /* Quotes are not needed but we allow them for familiarity */
  3851.     /* but then we strip them, so syntax is same as for Unix shell */
  3852.  
  3853.     if (s2) {
  3854.     s2 = brstrip(s2);
  3855.     } else {
  3856.     s2 = (char *)"";
  3857.     }
  3858.     ckmakmsg(t,TMPBUFSIZ,s1,"=",s2,NULL);
  3859.     debug(F111,"doputenv",t,nputenvs);
  3860.     (VOID) makestr(&(putenvs[nputenvs]),t); /* Make a safe permananent copy */
  3861.     if (!putenvs[nputenvs]) {
  3862.     printf("?PUTENV - memory allocation failure\n");
  3863.     return(-9);
  3864.     }
  3865.     if (putenv(putenvs[nputenvs])) {
  3866.     printf("?PUTENV - %s\n",ck_errstr());
  3867.     return(-9);
  3868.     } else return(success = 1);
  3869. }
  3870. #endif    /* NOPUTENV */
  3871. #endif    /* UNIX */
  3872.  
  3873. int
  3874. settrmtyp() {
  3875. #ifdef OS2
  3876. #ifdef TNCODE
  3877.     extern int ttnum;                    /* Last Telnet Terminal Type sent */
  3878.     extern int ttnumend;                 /* Has end of list been found */
  3879. #endif /* TNCODE */
  3880.     if ((x = cmkey(ttyptab,nttyp,"","vt220",xxstring)) < 0)
  3881.       return(x);
  3882.     if ((y = cmcfm()) < 0)
  3883.       return(y);
  3884.     settermtype(x,1);
  3885. #ifdef TNCODE
  3886.     /* So we send the correct terminal name to the host if it asks for it */
  3887.     ttnum = -1;                         /* Last Telnet Terminal Type sent */
  3888.     ttnumend = 0;                       /* end of list not found */
  3889. #endif /* TNCODE */
  3890.     return(success = 1);
  3891. #else  /* Not OS2 */
  3892. #ifdef UNIX
  3893.     extern int fxd_inited;
  3894.     x = cmtxt("Terminal type name, case sensitive","",&s,NULL);
  3895. #ifdef NOPUTENV
  3896.     success = 1;
  3897. #else
  3898.     success = doputenv("TERM",s);    /* Set the TERM variable */
  3899. #ifdef CK_CURSES
  3900.     fxd_inited = 0;           /* Force reinitialization of curses database */
  3901.     (void)doxdis(0);             /* Re-initialize file transfer display */
  3902.     concb((char)escape);        /* Fix command terminal */
  3903. #endif    /* CK_CURSES */
  3904. #endif    /* NOPUTENV */
  3905.     return(success);
  3906. #else
  3907.     printf(
  3908. "\n Sorry, this version of C-Kermit does not support the SET TERMINAL TYPE\n");
  3909.     printf(
  3910. " command.  Type \"help set terminal\" for further information.\n");
  3911.     return(success = 0);
  3912. #endif    /* UNIX */
  3913. #endif /* OS2 */
  3914. }
  3915.  
  3916. #ifndef NOLOCAL
  3917. #ifdef OS2
  3918. /* MS-DOS KERMIT compatibility modes */
  3919. int
  3920. setmsk() {
  3921.     if ((y = cmkey(msktab,nmsk,"MS-DOS Kermit compatibility mode",
  3922.                     "keycodes",xxstring)) < 0) return(y);
  3923.  
  3924.     switch ( y ) {
  3925. #ifdef COMMENT
  3926.       case MSK_COLOR:
  3927.         return(seton(&mskcolors));
  3928. #endif /* COMMENT */
  3929.       case MSK_KEYS:
  3930.         return(seton(&mskkeys));
  3931.       case MSK_REN:
  3932.         return(seton(&mskrename));
  3933.       default:                          /* Shouldn't get here. */
  3934.         return(-2);
  3935.     }
  3936. }
  3937. #endif /* OS2 */
  3938.  
  3939. #ifdef CKTIDLE
  3940. static char iactbuf[132];
  3941.  
  3942. char *
  3943. getiact() {
  3944.     switch (tt_idleact) {
  3945.       case IDLE_RET:  return("return");
  3946.       case IDLE_EXIT: return("exit");
  3947.       case IDLE_HANG: return("hangup");
  3948. #ifdef TNCODE
  3949.       case IDLE_TNOP: return("Telnet NOP");
  3950.       case IDLE_TAYT: return("Telnet AYT");
  3951. #endif /* TNCODE */
  3952.  
  3953.       case IDLE_OUT: {
  3954.           int c, k, n;
  3955.           char * p, * q, * t;
  3956.           k = ckstrncpy(iactbuf,"output ",132);
  3957.           n = k;
  3958.           q = &iactbuf[k];
  3959.           p = tt_idlestr;
  3960.           if (!p) p = "";
  3961.           if (!*p) return("output NUL");
  3962.           while ((c = *p++) && n < 131) {
  3963.               c &= 0xff;
  3964.               if (c == '\\') {
  3965.                   if (n > 130) break;
  3966.                   *q++ = '\\';
  3967.                   *q++ = '\\';
  3968.                   *q = NUL;
  3969.                   n += 2;
  3970.               } else if ((c > 32 && c < 127) || c > 159) {
  3971.                   *q++ = c;
  3972.                   *q = NUL;
  3973.                   n++;
  3974.               } else {
  3975.                   if (n > (131 - 6))
  3976.                     break;
  3977.                   sprintf(q,"\\{%d}",c);
  3978.                   k = strlen(q);
  3979.                   q += k;
  3980.                   n += k;
  3981.                   *q = NUL;
  3982.               }
  3983.           }
  3984.           *q = NUL;
  3985. #ifdef OS2
  3986.           k = tt_cols[VTERM];
  3987. #else
  3988.           k = tt_cols;
  3989. #endif /* OS2 */
  3990.           if (n > k - 52) {
  3991.               n = k - 52;
  3992.               iactbuf[n-2] = '.';
  3993.               iactbuf[n-1] = '.';
  3994.               iactbuf[n] = NUL;
  3995.           }
  3996.           return(iactbuf);
  3997.       }
  3998.       default: return("unknown");
  3999.     }
  4000. }
  4001. #endif /* CKTIDLE */
  4002.  
  4003. #ifndef NOCSETS
  4004. VOID
  4005. setlclcharset(x) int x; {
  4006.     int i;
  4007.     tcsl = y;                   /* Local character set */
  4008. #ifdef OS2
  4009.     for (i = 0; i < 4; i++) {
  4010.         G[i].init = TRUE;
  4011.         x = G[i].designation;
  4012.         G[i].c1 = (x != tcsl) && cs_is_std(x);
  4013.         x = G[i].def_designation;
  4014.         G[i].def_c1 = (x != tcsl) && cs_is_std(x);
  4015.     }
  4016. #endif /* OS2 */
  4017. }
  4018.  
  4019. VOID
  4020. setremcharset(x, z) int x, z; {
  4021.     int i;
  4022.  
  4023. #ifdef KUI
  4024.     KuiSetProperty( KUI_TERM_REMCHARSET, (long) x, (long) z ) ;
  4025. #endif /* KUI */
  4026. #ifdef UNICODE
  4027.     if (x == TX_TRANSP)
  4028. #else /* UNICODE */
  4029.     if (x == FC_TRANSP)
  4030. #endif /* UNICODE */
  4031.     {                           /* TRANSPARENT? */
  4032. #ifndef OS2
  4033.         tcsr = tcsl;            /* Make both sets the same */
  4034. #else /* OS2 */
  4035. #ifdef CKOUNI
  4036.         tt_utf8 = 0;            /* Turn off UTF8 flag */
  4037.         tcsr = tcsl = dec_kbd = TX_TRANSP; /* No translation */
  4038.         tcs_transp = 1;
  4039.  
  4040.         if (!cs_is_nrc(tcsl)) {
  4041.             G[0].def_designation = G[0].designation = TX_ASCII;
  4042.             G[0].init = TRUE;
  4043.             G[0].def_c1 = G[0].c1 = FALSE;
  4044.             G[0].size = cs94;
  4045.             G[0].national = FALSE;
  4046.         }
  4047.         for (i = cs_is_nrc(tcsl) ? 0 : 1; i < 4; i++) {
  4048.             G[i].def_designation = G[i].designation = tcsl;
  4049.             G[i].init = TRUE;
  4050.             G[i].def_c1 = G[i].c1 = FALSE;
  4051.             switch (cs_size(G[i].designation)) { /* 94, 96, or 128 */
  4052.             case 128:
  4053.             case 96:
  4054.                 G[i].size = G[i].def_size = cs96;
  4055.                 break;
  4056.             case 94:
  4057.                 G[i].size = G[i].def_size = cs94;
  4058.                 break;
  4059.             default:
  4060.                 G[i].size = G[i].def_size = csmb;
  4061.                 break;
  4062.             }
  4063.             G[i].national = cs_is_nrc(x);
  4064.         }
  4065. #else /* CKOUNI */
  4066.         tcsr = tcsl;            /* Make both sets the same */
  4067.         for (i = 0; i < 4; i++) {
  4068.             G[i].def_designation = G[i].designation = FC_TRANSP;
  4069.             G[i].init = FALSE;
  4070.             G[i].size = G[i].def_size = cs96;
  4071.             G[i].c1 = G[i].def_c1 = FALSE;
  4072.             G[i].rtoi = NULL;
  4073.             G[i].itol = NULL;
  4074.             G[i].ltoi = NULL;
  4075.             G[i].itor = NULL;
  4076.             G[i].national = FALSE;
  4077.         }
  4078. #endif /* CKOUNI */
  4079. #endif /* OS2 */
  4080.         return;
  4081.     }
  4082. #ifdef OS2
  4083. #ifdef CKOUNI
  4084.     else if (x == TX_UTF8) {
  4085.         tcs_transp = 0;
  4086.         tt_utf8 = 1;            /* Turn it on if we are UTF8 */
  4087.         return;
  4088.     }
  4089. #endif /* CKOUNI */
  4090.     else {
  4091.         tcs_transp = 0;
  4092.         tcsr = x;                       /* Remote character set */
  4093. #ifdef CKOUNI
  4094.         tt_utf8 = 0;                    /* Turn off UTF8 flag */
  4095. #endif /* CKOUNI */
  4096.  
  4097.         if (z == TT_GR_ALL) {
  4098.             int i;
  4099. #ifdef UNICODE
  4100.             dec_kbd = x;
  4101. #endif /* UNICODE */
  4102.             for (i = 0; i < 4; i++) {
  4103.                 G[i].init = TRUE;
  4104.                 if ( i == 0 && !cs_is_nrc(x) ) {
  4105.                     G[0].designation = G[0].def_designation = FC_USASCII;
  4106.                     G[0].size = G[0].def_size = cs94;
  4107.                     G[0].national = 1;
  4108.                 } else {
  4109.                     G[i].def_designation = G[i].designation = x;
  4110.                     switch (cs_size(x)) {       /* 94, 96, or 128 */
  4111.                     case 128:
  4112.                     case 96:
  4113.                         G[i].size = G[i].def_size = cs96;
  4114.                         break;
  4115.                     case 94:
  4116.                         G[i].size = G[i].def_size = cs94;
  4117.                         break;
  4118.                     default:
  4119.                         G[i].size = G[i].def_size = csmb;
  4120.                         break;
  4121.                     }
  4122.                     G[i].national = cs_is_nrc(x);
  4123.                 }
  4124.                 G[i].c1 = G[i].def_c1 = x != tcsl && cs_is_std(x);
  4125.             }
  4126. #ifdef UNICODE
  4127.         } else if (z == TT_GR_KBD) {    /* Keyboard only */
  4128.             dec_kbd = x;
  4129. #endif /* UNICODE */
  4130.         } else {                        /* Specific Gn */
  4131.             G[z].def_designation = G[z].designation = x;
  4132.             G[z].init = TRUE;
  4133.             switch (cs_size(x)) {       /* 94, 96, or 128 */
  4134.             case 128:
  4135.             case 96:
  4136.                 G[z].size = G[z].def_size = cs96;
  4137.                 break;
  4138.             case 94:
  4139.                 G[z].size = G[z].def_size = cs94;
  4140.                 break;
  4141.             default:
  4142.                 G[z].size = G[z].def_size = csmb;
  4143.                 break;
  4144.             }
  4145.             G[z].c1 = G[z].def_c1 = x != tcsl && cs_is_std(x);
  4146.             G[z].national = cs_is_nrc(x);
  4147.         }
  4148.     }
  4149. #else /* not OS2 */
  4150.     tcsr = x;                   /* Remote character set */
  4151. #endif /* OS2 */
  4152. }
  4153. #endif /* NOCSETS */
  4154.  
  4155. VOID
  4156. setcmask(x) int x; {
  4157.     if (x == 7) {
  4158.         cmask = 0177;
  4159.     } else if (x == 8) {
  4160.         cmask = 0377;
  4161.         parity = 0;
  4162.     }
  4163. #ifdef KUI      
  4164.     KuiSetProperty(KUI_TERM_CMASK,x,0);
  4165. #endif /* KUI */
  4166. }
  4167.  
  4168. #ifdef CK_AUTODL
  4169. VOID
  4170. setautodl(x,y) int x,y; {
  4171.     autodl = x;
  4172.     adl_ask = y;
  4173. #ifdef KUI      
  4174.     KuiSetProperty(KUI_TERM_AUTODOWNLOAD,x?(y?2:1):0,0);
  4175. #endif /* KUI */
  4176. }
  4177. #endif /* CK_AUTODL */
  4178.  
  4179. #ifdef OS2
  4180. VOID
  4181. seturlhl(int x) {
  4182.     tt_url_hilite = x;
  4183. #ifdef KUI      
  4184.     KuiSetProperty(KUI_TERM_URL_HIGHLIGHT,x,0);
  4185. #endif /* KUI */
  4186. }
  4187.  
  4188. VOID
  4189. setaprint(int x) {
  4190.     extern int aprint;
  4191.     aprint = x;
  4192. #ifdef KUI
  4193.     KuiSetProperty(KUI_TERM_PRINTERCOPY,x,0);
  4194. #endif /* KUI */
  4195. }
  4196. #endif /* OS2 */
  4197.  
  4198. int
  4199. settrm() {
  4200.     int i = 0;
  4201. #ifdef OS2
  4202.     extern int colorreset, user_erasemode;
  4203. #endif /* OS2 */
  4204.     if ((y = cmkey(trmtab,ntrm,"", "",xxstring)) < 0) return(y);
  4205. #ifdef MAC
  4206.     printf("\n?Sorry, not implemented yet.  Please use the Settings menu.\n");
  4207.     return(-9);
  4208. #else
  4209. #ifdef IKSD
  4210.     if (inserver) {
  4211.         if ((y = cmcfm()) < 0) return(y);
  4212.         printf("?Sorry, command disabled.\r\n");
  4213.         return(success = 0);
  4214.     }
  4215. #endif /* IKSD */
  4216.  
  4217.     switch (y) {
  4218.       case XYTBYT:                      /* SET TERMINAL BYTESIZE */
  4219.         if ((y = cmnum("bytesize for terminal connection","8",10,&x,
  4220.                        xxstring)) < 0)
  4221.           return(y);
  4222.         if (x != 7 && x != 8) {
  4223.             printf("\n?The choices are 7 and 8\n");
  4224.             return(success = 0);
  4225.         }
  4226.         if ((y = cmcfm()) < 0) return(y);
  4227.         setcmask(x);
  4228. #ifdef OS2
  4229.         if (IS97801(tt_type_mode))
  4230.           SNI_bitmode(x);
  4231. #endif /* OS2 */
  4232.         return(success = 1);
  4233.  
  4234.       case XYTSO:                       /* SET TERMINAL LOCKING-SHIFT */
  4235.         return(seton(&sosi));
  4236.  
  4237.       case XYTNL:                       /* SET TERMINAL NEWLINE-MODE */
  4238.         return(seton(&tnlm));
  4239.  
  4240. #ifdef OS2
  4241.       case XYTCOL:
  4242.         if ((x = cmkey(ttycoltab,ncolors,"","terminal",xxstring)) < 0)
  4243.           return(x);
  4244.         else if (x == TTCOLRES) {
  4245.             if ((y = cmkey(ttcolmodetab,ncolmode,
  4246.                            "","default-color",xxstring)) < 0)
  4247.               return(y);
  4248.             if ((z = cmcfm()) < 0)
  4249.               return(z);
  4250.             colorreset = y;
  4251.             return(success = 1);
  4252.         } else if (x == TTCOLERA) {
  4253.             if ((y = cmkey(ttcolmodetab,ncolmode,"",
  4254.                            "current-color",xxstring)) < 0)
  4255.               return(y);
  4256.             if ((z = cmcfm()) < 0)
  4257.               return(z);
  4258.             user_erasemode = y;
  4259.             return(success=1);
  4260.         } else {                        /* No parse error */
  4261.             int fg = 0, bg = 0;
  4262.             fg = cmkey(ttyclrtab, nclrs,
  4263.                        (x == TTCOLBOR ?
  4264.                         "color for screen border" :
  4265.                         "foreground color and then background color"),
  4266.                        "lgray", xxstring);
  4267.             if (fg < 0)
  4268.               return(fg);
  4269.             if (x != TTCOLBOR) {
  4270.                 if ((bg = cmkey(ttyclrtab,nclrs,
  4271.                                 "background color","blue",xxstring)) < 0)
  4272.                   return(bg);
  4273.             }
  4274.             if ((y = cmcfm()) < 0)
  4275.               return(y);
  4276.             switch (x) {
  4277.               case TTCOLNOR:
  4278.                 colornormal = fg | bg << 4;
  4279.                 fgi = fg & 0x08;
  4280.                 bgi = bg & 0x08;
  4281.                 break;
  4282.               case TTCOLREV:
  4283.                 colorreverse = fg | bg << 4;
  4284.                 break;
  4285.               case TTCOLITA:
  4286.                 coloritalic = fg | bg << 4;
  4287.                 break;
  4288.               case TTCOLUND:
  4289.                 colorunderline = fg | bg << 4;
  4290.                 break;
  4291.               case TTCOLGRP:
  4292.                 colorgraphic = fg | bg << 4;
  4293.                 break;
  4294.               case TTCOLDEB:
  4295.                 colordebug = fg | bg << 4;
  4296.                 break;
  4297.               case TTCOLSTA:
  4298.                 colorstatus = fg | bg << 4;
  4299.                 break;
  4300.               case TTCOLHLP:
  4301.                 colorhelp = fg | bg << 4;
  4302.                 break;
  4303.               case TTCOLBOR:
  4304.                 colorborder = fg;
  4305.                 break;
  4306.               case TTCOLSEL:
  4307.                 colorselect = fg | bg << 4;
  4308.                 break;
  4309.               default:
  4310.                 printf("%s - invalid\n",cmdbuf);
  4311.                 return(-9);
  4312.                 break;
  4313.             }
  4314.             scrninitialized[VTERM] = 0;
  4315.             VscrnInit(VTERM);
  4316.         }
  4317.         return(success = 1);
  4318.  
  4319.       case XYTCUR: {                    /* SET TERMINAL CURSOR */
  4320.           extern int cursorena[];
  4321.           extern int cursoron[] ;       /* Cursor state on/off       */
  4322.           if ((x = cmkey(ttycurtab,ncursors,"","underline",xxstring)) < 0)
  4323.             return(x);
  4324.           if ((z = cmkey(curontab,ncuron,"","on",xxstring)) < 0)
  4325.             return(z);
  4326.           if ((y = cmcfm()) < 0) return(y);
  4327.           tt_cursor = tt_cursor_usr = x;
  4328.           if ( z == 2 ) {
  4329.               cursorena[VTERM] = tt_cursorena_usr = 1;
  4330.               tt_cursor_blink = 0;
  4331.           } else {
  4332.               cursorena[VTERM] = tt_cursorena_usr = z;/* turn cursor on/off */
  4333.               tt_cursor_blink = 1;
  4334.           }
  4335.           cursoron[VTERM] = FALSE; /* Force newcursor to restore the cursor */
  4336.           return(success = 1);
  4337.       }
  4338. #endif /* OS2 */
  4339.  
  4340.       case XYTTYP:                      /* SET TERMINAL TYPE */
  4341.         return(settrmtyp());
  4342.  
  4343. #ifdef OS2
  4344.       case XYTARR:                      /* SET TERMINAL ARROW-KEYS */
  4345.         if ((x = cmkey(akmtab,2,"","",xxstring)) < 0) return(x);
  4346.         if ((y = cmcfm()) < 0) return(y);
  4347.         tt_arrow = x;                   /* TTK_NORM / TTK_APPL; see ckuusr.h */
  4348.         return(success = 1);
  4349.  
  4350.       case XYTKPD:                      /* SET TERMINAL KEYPAD-MODE */
  4351.         if ((x = cmkey(kpmtab,2,"","",xxstring)) < 0) return(x);
  4352.         if ((y = cmcfm()) < 0) return(y);
  4353.         tt_keypad = x;                  /* TTK_NORM / TTK_APPL; see ckuusr.h */
  4354.         return(success = 1);
  4355.  
  4356.       case XYTUNX: {                    /* SET TERM UNIX-MODE (DG) */
  4357.         extern int dgunix,dgunix_usr;
  4358.         x = seton(&dgunix);
  4359.         dgunix_usr = dgunix;
  4360.         return(x);
  4361.       }
  4362.       case XYTKBMOD: {                  /* SET TERM KEYBOARD MODE */
  4363.           extern int tt_kb_mode;
  4364.           if ((x = cmkey(kbmodtab,
  4365.                          nkbmodtab,
  4366.                          "normal",
  4367.                          "special keyboard mode for terminal emulation",
  4368.                          xxstring)
  4369.                ) < 0)
  4370.             return(x);
  4371.           if ((y = cmcfm()) < 0) return(y);
  4372.           tt_kb_mode = x;
  4373.           return(success = 1);
  4374.       }
  4375.  
  4376.       case XYTWRP:                      /* SET TERMINAL WRAP */
  4377.         return(seton(&tt_wrap));
  4378.  
  4379.       case XYSCRS:
  4380.         if ((y = cmnum("CONNECT scrollback buffer size, lines","2000",10,&x,
  4381.                        xxstring)) < 0)
  4382.           return(y);
  4383.         /* The max number of lines is the RAM  */
  4384.         /* we can actually dedicate to a       */
  4385.         /* scrollback buffer given the maximum */
  4386.         /* process memory space of 512MB       */
  4387.         if (x < 256 || x > 2000000L) {
  4388.             printf("\n?The size must be between 256 and 2,000,000.\n");
  4389.             return(success = 0);
  4390.         }
  4391.         if ((y = cmcfm()) < 0) return(y);
  4392.         tt_scrsize[VTERM] = x;
  4393.         VscrnInit(VTERM);
  4394.         return(success = 1);
  4395. #endif /* OS2 */
  4396.  
  4397. #ifndef NOCSETS
  4398.       case XYTCS: {                     /* SET TERMINAL CHARACTER-SET */
  4399.         int eol;
  4400.           /* set terminal character-set <remote> <local> */
  4401.         if ((x = cmkey(
  4402. #ifdef CKOUNI
  4403.                        txrtab,ntxrtab,
  4404. #else  /* CKOUNI */
  4405.                        ttcstab,ntermc,
  4406. #endif /* CKOUNI */
  4407.                        "remote terminal character-set","",xxstring)) < 0)
  4408.           return(x);
  4409.  
  4410. #ifdef UNICODE
  4411.         if (x == TX_TRANSP
  4412. #ifdef CKOUNI
  4413.             || x == TX_UTF8
  4414. #endif /* CKOUNI */
  4415.            ) {
  4416.               if ((y = cmcfm()) < 0)    /* Confirm the command */
  4417.                   return(y);
  4418. #ifdef OS2
  4419.             if ( isunicode() && x == TX_TRANSP ) {
  4420.                 /* If we are in unicode display mode then transparent
  4421.                  * only affects the output direction.  We need to know
  4422.                  * the actual remote character set in order to perform
  4423.                  * the tcsr -> ucs2 translation for display.
  4424.                  */
  4425.                 x = y = tcsl;
  4426.             } else
  4427. #endif /* OS2 */
  4428.                 y = x;
  4429.         }
  4430. #else /* UNICODE */
  4431.         if (x == FC_TRANSP) {
  4432.             if ((y = cmcfm()) < 0)      /* Confirm the command */
  4433.                 return(y);
  4434.             y = x;
  4435.         }
  4436. #endif /* UNICODE */
  4437.  
  4438.         /* Not transparent or UTF8, so get local set to translate it into */
  4439.         s = "";
  4440. #ifdef OS2
  4441.         y = os2getcp();                 /* Default is current code page */
  4442.         switch (y) {
  4443.           case 437: s = "cp437"; break;
  4444.           case 850: s = "cp850"; break;
  4445.           case 852: s = "cp852"; break;
  4446.           case 857: s = "cp857"; break;
  4447.           case 858: s = "cp858"; break;
  4448.           case 862: s = "cp862"; break;
  4449.           case 866: s = "cp866"; break;
  4450.           case 869: s = "cp869"; break;
  4451.           case 1250: s = "cp1250"; break;
  4452.           case 1251: s = "cp1251"; break;
  4453.           case 1252: s = "cp1252"; break;
  4454.           case 1253: s = "cp1253"; break;
  4455.           case 1254: s = "cp1254"; break;
  4456.           case 1255: s = "cp1255"; break;
  4457.           case 1256: s = "cp1256"; break;
  4458.           case 1257: s = "cp1257"; break;
  4459.           case 1258: s = "cp1258"; break;
  4460.         }
  4461. #ifdef PCFONTS
  4462. /*
  4463.    If the user has loaded a font with SET TERMINAL FONT then we want
  4464.    to change the default code page to the font that was loaded.
  4465. */
  4466.         if (tt_font != TTF_ROM) {
  4467.             for (y = 0; y < ntermfont; y++ ) {
  4468.                 if (term_font[y].kwval == tt_font) {
  4469.                     s = term_font[y].kwd;
  4470.                     break;
  4471.                 }
  4472.             }
  4473.         }
  4474. #endif /* PCFONTS */
  4475. #else  /* Not K95... */
  4476.         s = fcsinfo[fcharset].keyword;
  4477. #endif /* OS2 */
  4478.  
  4479.         if ((y = cmkey(
  4480. #ifdef CKOUNI
  4481.                        txrtab,ntxrtab,
  4482. #else /* CKOUNI */
  4483.                        ttcstab,ntermc,
  4484. #endif /* CKOUNI */
  4485.                        "local character-set",s,xxstring)) < 0)
  4486.           return(y);
  4487.  
  4488. #ifdef UNICODE
  4489.         if (y == TX_UTF8) {
  4490.             printf("?UTF8 may not be used as a local character set.\r\n");
  4491.             return(-9);
  4492.         }
  4493. #endif /* UNICODE */
  4494. #ifdef OS2
  4495.         if ((z = cmkey(graphsettab,ngraphset,
  4496.                        "DEC VT intermediate graphic set","all",xxstring)) < 0)
  4497.             return(z);
  4498. #endif /* OS2 */
  4499.         if ((eol = cmcfm()) < 0)
  4500.             return(eol); /* Confirm the command */
  4501.  
  4502.         /* End of command parsing - actions begin */
  4503.         setlclcharset(y);
  4504.         setremcharset(x,z);
  4505.         return(success = 1);
  4506.       }
  4507. #endif /* NOCSETS */
  4508.  
  4509. #ifndef NOCSETS
  4510.       case XYTLCS:                      /* SET TERMINAL LOCAL-CHARACTER-SET */
  4511.         /* set terminal character-set <local> */
  4512.         s = getdcset();                 /* Get display character-set name */
  4513.         if ((y = cmkey(
  4514. #ifdef CKOUNI
  4515.                        txrtab,ntxrtab,
  4516. #else /* CKOUNI */
  4517.                        fcstab,nfilc,
  4518. #endif /* CKOUNI */
  4519.                        "local character-set",s,xxstring)) < 0)
  4520.           return(y);
  4521.  
  4522. #ifdef UNICODE
  4523.           if (y == TX_UTF8) {
  4524.               printf("?UTF8 may not be used as a local character set.\r\n");
  4525.               return(-9);
  4526.           }
  4527. #endif /* UNICODE */
  4528.           if ((z = cmcfm()) < 0) return(z); /* Confirm the command */
  4529.  
  4530.           /* End of command parsing - action begins */
  4531.  
  4532.         setlclcharset(y);
  4533.         return(success = 1);
  4534. #endif /* NOCSETS */
  4535.  
  4536. #ifndef NOCSETS
  4537. #ifdef UNICODE
  4538.       case XYTUNI:                      /* SET TERMINAL UNICODE */
  4539.         return(seton(&tt_unicode));
  4540. #endif /* UNICODE */
  4541.  
  4542.       case XYTRCS:                      /* SET TERMINAL REMOTE-CHARACTER-SET */
  4543.         /* set terminal character-set <remote> <Graphic-set> */
  4544.         if ((x = cmkey(
  4545. #ifdef CKOUNI
  4546.                 txrtab, ntxrtab,
  4547. #else /* CKOUNI */
  4548.                 ttcstab,ntermc,
  4549. #endif /* CKOUNI */
  4550.                        "remote terminal character-set","",xxstring)) < 0)
  4551.           return(x);
  4552.  
  4553. #ifdef UNICODE
  4554.         if (x == TX_TRANSP
  4555. #ifdef CKOUNI
  4556.             || x == TX_UTF8
  4557. #endif /* CKOUNI */
  4558.            ) {
  4559.               if ((y = cmcfm()) < 0)    /* Confirm the command */
  4560.                   return(y);
  4561. #ifdef OS2
  4562.             if ( isunicode() && x == TX_TRANSP ) {
  4563.                 /* If we are in unicode display mode then transparent
  4564.                  * only affects the output direction.  We need to know
  4565.                  * the actual remote character set in order to perform
  4566.                  * the tcsr -> ucs2 translation for display.
  4567.                  */
  4568.                 x = tcsl;
  4569.             }
  4570. #endif /* OS2 */
  4571.         }
  4572. #else /* UNICODE */
  4573.         if (x == FC_TRANSP) {
  4574.           if ((y = cmcfm()) < 0)        /* Confirm the command */
  4575.             return(y);
  4576.         }
  4577. #endif /* UNICODE */
  4578.         else {
  4579. #ifdef OS2
  4580.           if ((z = cmkey(graphsettab,ngraphset,
  4581.                       "DEC VT intermediate graphic set","all",xxstring)) < 0)
  4582.             return(z);
  4583. #endif /* OS2 */
  4584.           if ((y = cmcfm()) < 0)        /* Confirm the command */
  4585.             return(y);
  4586.         }
  4587.         /* Command parsing ends here */
  4588.  
  4589.         setremcharset(x,z);
  4590.         return(success = 1);
  4591. #endif /* NOCSETS */
  4592.  
  4593.       case XYTEC:                       /* SET TERMINAL ECHO */
  4594.         if ((x = cmkey(rltab,nrlt,"which side echos during CONNECT",
  4595.                        "remote", xxstring)) < 0) return(x);
  4596.         if ((y = cmcfm()) < 0) return(y);
  4597. #ifdef NETCONN
  4598.         oldplex = x;
  4599. #endif /* NETCONN */
  4600.         duplex = x;
  4601.         return(success = 1);
  4602.  
  4603.       case XYTESC:                      /* SET TERM ESC */
  4604.         if ((x = cmkey(nabltab,nnabltab,"","enabled",xxstring)) < 0)
  4605.           return(x);
  4606.         if ((y = cmcfm()) < 0) return(y);
  4607.         tt_escape = x;
  4608.         return(1);
  4609.  
  4610.       case XYTCRD:                      /* SET TERMINAL CR-DISPLAY */
  4611.         if ((x = cmkey(crdtab,2,"", "normal", xxstring)) < 0) return(x);
  4612.         if ((y = cmcfm()) < 0) return(y);
  4613.         tt_crd = x;
  4614.         return(success = 1);
  4615.  
  4616.       case XYTLFD:                      /* SET TERMINAL LF-DISPLAY */
  4617.         if ((x = cmkey(crdtab,2,"", "normal", xxstring)) < 0) return(x);
  4618.         if ((y = cmcfm()) < 0) return(y);
  4619.         tt_lfd = x;
  4620.         return(success = 1);
  4621.  
  4622. #ifdef OS2
  4623.       case XYTANS: {                    /* SET TERMINAL ANSWERBACK */
  4624. /*
  4625.   NOTE: We let them enable and disable the answerback sequence, but we
  4626.   do NOT let them change it, and we definitely do not let the host set it.
  4627.   This is a security feature.
  4628.  
  4629.   As of 1.1.8 we allow the SET TERM ANSWERBACK MESSAGE <string> to be
  4630.   used just as MS-DOS Kermit does.  C0 and C1 controls as well as DEL
  4631.   are not allowed to be used as characters.  They are translated to
  4632.   underscore.  This may not be set by APC.
  4633. */
  4634.           if ((x = cmkey(anbktab,nansbk,"", "off", xxstring)) < 0)
  4635.             return(x);
  4636.           if (x < 2) {
  4637.               if ((y = cmcfm()) < 0)
  4638.                 return(y);
  4639.               tt_answer = x;
  4640.               return(success = 1);
  4641.           } else if ( x == 2 || x == 3) {
  4642.               int len = 0;
  4643.               extern int safeanswerbk;
  4644.               extern char useranswerbk[];
  4645.               if ((y = cmtxt("Answerback extension","",&s,xxstring)) < 0)
  4646.                 return(y);
  4647.               if (apcactive == APC_LOCAL ||
  4648.                   (apcactive == APC_REMOTE && !(apcstatus & APC_UNCH)))
  4649.                 return(success = 0);
  4650.               len = strlen(s);
  4651.               if (x == 2) {
  4652.                   /* Safe Answerback's don't have C0/C1 chars */
  4653.                   for (z = 0; z < len; z++) {
  4654.                       if ((s[z] & 0x7F) <= SP || (s[z] & 0x7F) == DEL)
  4655.                         useranswerbk[z] = '_';
  4656.                       else
  4657.                         useranswerbk[z] = s[z];
  4658.                   }
  4659.                   useranswerbk[z] = '\0';
  4660.                   safeanswerbk = 1 ;    /* TRUE */
  4661.               } else {
  4662.                   ckstrncpy(useranswerbk,s,60); /* (see ckocon.c) */
  4663.                   safeanswerbk = 0;     /* FALSE */
  4664.               }
  4665.               updanswerbk();
  4666.               return(success = 1);
  4667.           } else
  4668.             return(success = 0);
  4669.       }
  4670. #endif /* OS2 */
  4671.  
  4672. #ifdef CK_APC
  4673.       case XYTAPC:
  4674.         if ((y = cmkey(apctab,napctab,
  4675.                        "application program command execution","",
  4676.                        xxstring)) < 0)
  4677.           return(y);
  4678.         if ((x = cmcfm()) < 0)
  4679.           return(x);
  4680.         if (apcactive == APC_LOCAL ||
  4681.             (apcactive == APC_REMOTE && !(apcstatus & APC_UNCH)))
  4682.           return(success = 0);
  4683.         apcstatus = y;
  4684.         return(success = 1);
  4685.  
  4686. #ifdef CK_AUTODL
  4687.       case XYTAUTODL:                   /* AUTODOWNLOAD */
  4688.         if ((y = cmkey(adltab,nadltab,"Auto-download options","",
  4689.                        xxstring)) < 0)
  4690.           return(y);
  4691.         switch (y) {
  4692.           case TAD_ON:
  4693.           case TAD_OFF:
  4694.             if ((x = cmcfm()) < 0)
  4695.               return(x);
  4696.             setautodl(y,0);
  4697.             break;
  4698.           case TAD_ASK:
  4699.             if ((x = cmcfm()) < 0)
  4700.               return(x);
  4701.             setautodl(TAD_ON,1);
  4702.             break;
  4703.           case TAD_ERR:
  4704.             if ((y = cmkey(adlerrtab,nadlerrtab,"","", xxstring)) < 0)
  4705.               return(y);
  4706.             if ((x = cmcfm()) < 0)
  4707.               return(x);
  4708.             adl_err = y;
  4709.             break;
  4710. #ifdef OS2
  4711.           case TAD_K:
  4712.             if ((y = cmkey(adlxtab,nadlxtab,"","", xxstring)) < 0)
  4713.               return(y);
  4714.             switch (y) {
  4715.               case TAD_X_C0:
  4716.                 if ((y = cmkey(adlc0tab,nadlc0tab,"",
  4717.                                "processed-by-emulator",xxstring)) < 0)
  4718.                   return(y);
  4719.                 if ((x = cmcfm()) < 0)
  4720.                   return(x);
  4721.                 adl_kc0 = y;
  4722.                 break;
  4723.               case TAD_X_DETECT:
  4724.                 if ((y = cmkey(adldtab,nadldtab,"","packet",xxstring)) < 0)
  4725.                   return(y);
  4726.                 if ((x = cmcfm()) < 0)
  4727.                   return(x);
  4728.                 adl_kmode = y;
  4729.                 break;
  4730.               case TAD_X_STR:
  4731.                 if ((y = cmtxt("Kermit start string","KERMIT READY TO SEND...",
  4732.                                &s,xxstring)) < 0)
  4733.                   return(y);
  4734.                 free(adl_kstr);
  4735.                 adl_kstr = strdup(s);
  4736.                 break;
  4737.             }
  4738.             break;
  4739.  
  4740.           case TAD_Z:
  4741.             if ((y = cmkey(adlxtab,nadlxtab,"","",xxstring)) < 0)
  4742.               return(y);
  4743.             switch (y) {
  4744.               case TAD_X_C0:
  4745.                 if ((y = cmkey(adlc0tab,nadlc0tab,"",
  4746.                                "processed-by-emulator",xxstring)) < 0)
  4747.                   return(y);
  4748.                 if ((x = cmcfm()) < 0)
  4749.                   return(x);
  4750.                 adl_zc0 = y;
  4751.                 break;
  4752.               case TAD_X_DETECT:
  4753.                 if ((y = cmkey(adldtab,nadldtab,"","packet",xxstring)) < 0)
  4754.                   return(y);
  4755.                 if ((x = cmcfm()) < 0)
  4756.                   return(x);
  4757.                 adl_zmode = y;
  4758.                 break;
  4759.               case TAD_X_STR:
  4760.                 if ((y = cmtxt("","rz\\{13}",&s,xxstring)) < 0)
  4761.                   return(y);
  4762.                 free(adl_zstr);
  4763.                 adl_zstr = strdup(s);
  4764.                 break;
  4765.             }
  4766.             break;
  4767. #endif /* OS2 */
  4768.         }
  4769.         return(success = 1);
  4770.  
  4771. #endif /* CK_AUTODL */
  4772. #endif /* CK_APC */
  4773.  
  4774. #ifdef OS2
  4775.       case XYTBEL:
  4776.         return(success = setbell());
  4777.  
  4778.       case XYTMBEL:                     /* MARGIN-BELL */
  4779.         if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  4780.         if (y) {                        /* ON */
  4781.             if ((z = cmnum("Column at which to set margin bell",
  4782.                            "72",10,&x,xxstring)) < 0)
  4783.               return(z);
  4784.         }
  4785.         if ((z = cmcfm()) < 0) return(z);
  4786.         marginbell = y;
  4787.         marginbellcol = x;
  4788.         return(success = 1);
  4789. #endif /* OS2 */
  4790.  
  4791. #ifdef CKTIDLE
  4792.       case XYTIDLE:                     /* IDLE-SEND */
  4793.       case XYTITMO:                     /* IDLE-TIMEOUT */
  4794.         if ((z = cmnum("seconds of idle time to wait, or 0 to disable",
  4795.                        "0",10,&x,xxstring)) < 0)
  4796.           return(z);
  4797.         if (y == XYTIDLE) {
  4798.             if ((y = cmtxt("string to send, may contain kverbs and variables",
  4799.                            "\\v(newline)",&s,xxstring)) < 0)
  4800.               return(y);
  4801.             tt_idlesnd_tmo = x;         /* (old) */
  4802.             tt_idlelimit = x;           /* (new) */
  4803.             makestr(&tt_idlestr,brstrip(s)); /* (new) */
  4804.             tt_idlesnd_str = tt_idlestr; /* (old) */
  4805.             tt_idleact = IDLE_OUT;      /* (new) */
  4806.         } else {
  4807.             if ((y = cmcfm()) < 0)
  4808.               return(y);
  4809.             tt_idlelimit = x;
  4810.         }
  4811. #ifdef OS2
  4812.         puterror(VTERM);
  4813. #endif /* OS2 */
  4814.         return(success = 1);
  4815.  
  4816.       case XYTIACT: {                   /* SET TERM IDLE-ACTION */
  4817.           if ((y = cmkey(idlacts,nidlacts,"","",xxstring)) < 0)
  4818.             return(y);
  4819.           if (y == IDLE_OUT) {
  4820.               if ((x = cmtxt("string to send, may contain kverbs and variables"
  4821.                              , "",&s,xxstring)) < 0)
  4822.                 return(x);
  4823.               makestr(&tt_idlestr,brstrip(s)); /* (new) */
  4824.               tt_idlesnd_str = tt_idlestr; /* (old) */
  4825.           } else {
  4826.               if ((x = cmcfm()) < 0)
  4827.                 return(x);
  4828.           }
  4829.           tt_idleact = y;
  4830.           return(success = 1);
  4831.       }
  4832. #endif /* CKTIDLE */
  4833.  
  4834.       case XYTDEB:                      /* TERMINAL DEBUG */
  4835.         y = seton(&x);                  /* Go parse ON or OFF */
  4836.         if (y > 0)                      /* Command succeeded? */
  4837.           setdebses(x);
  4838.         return(y);
  4839.  
  4840. #ifdef OS2
  4841.       case XYTASCRL:                    /* SET TERMINAL AUTOSCROLL */
  4842.           y = seton(&autoscroll);
  4843.           return(y);
  4844.  
  4845.       case XYTAPAGE:                    /* SET TERMINAL AUTOPAGE */
  4846.           y = seton(&wy_autopage);
  4847.           return(y);
  4848.  
  4849.       case XYTROL:                      /* SET TERMINAL ROLL */
  4850.         if ((y = cmkey(rolltab,nroll,"scrollback mode","insert",xxstring))<0)
  4851.       return(y);
  4852.     if (y == TTR_KEYS) {
  4853.         if ((x = cmkey(rollkeytab,nrollkey,"","send",xxstring))<0)
  4854.           return(x);
  4855.         if ((z = cmcfm()) < 0) return(z);
  4856.         tt_rkeys[VTERM] = x;
  4857.     } else {
  4858.         if ((x = cmcfm()) < 0) return(x);
  4859.         tt_roll[VTERM] = y;
  4860.     }
  4861.         return(success = 1);
  4862.  
  4863.       case XYTCTS:                      /* SET TERMINAL TRANSMIT-TIMEOUT */
  4864.         y = cmnum("Maximum seconds to allow CTS off during CONNECT",
  4865.                   "5",10,&x,xxstring);
  4866.         return(setnum(&tt_ctstmo,x,y,10000));
  4867.  
  4868.       case XYTCPG: {                    /* SET TERMINAL CODE-PAGE */
  4869.         int i;
  4870.         int cp = -1;
  4871.         y = cmnum("PC code page to use during terminal emulation",
  4872.                   ckitoa(os2getcp()),10,&x,xxstring);
  4873.         if ((x = setnum(&cp,x,y,11000)) < 0) return(x);
  4874.         if (os2setcp(cp) != 1) {
  4875. #ifdef NT
  4876.             if (isWin95())
  4877.               printf(
  4878.                  "Sorry, Windows 95 does not support code page switching\n");
  4879.             else
  4880. #endif /* NT */
  4881.               printf(
  4882.                  "Sorry, %d is not a valid code page for this system.\n",cp);
  4883.             return(-9);
  4884.         }
  4885.     /* Force the terminal character-sets conversions to be updated */
  4886.         for ( i = 0; i < 4; i++ )
  4887.           G[i].init = TRUE;
  4888.         return(1);
  4889.     }
  4890.  
  4891.       case XYTPAC:                      /* SET TERMINAL OUTPUT-PACING */
  4892.         y = cmnum(
  4893.            "Pause between sending each character during CONNECT, milliseconds",
  4894.                   "-1",10,&x,xxstring);
  4895.         return(setnum(&tt_pacing,x,y,10000));
  4896.  
  4897. #ifdef OS2MOUSE
  4898.       case XYTMOU: {                    /* SET TERMINAL MOUSE */
  4899.           int old_mou = tt_mouse;
  4900.           if ((x = seton(&tt_mouse)) < 0)
  4901.             return(x);
  4902.           if (tt_mouse != old_mou)
  4903.             if (tt_mouse)
  4904.               os2_mouseon();
  4905.             else
  4906.               os2_mouseoff();
  4907.           return(1);
  4908.       }
  4909. #endif /* OS2MOUSE */
  4910. #endif /* OS2 */
  4911.  
  4912.       case XYTWID: {
  4913.           if ((y = cmnum(
  4914. #ifdef OS2
  4915.                          "number of columns in display window during CONNECT",
  4916. #else
  4917.                          "number of columns on your screen",
  4918. #endif /* OS2 */
  4919.                          "80",10,&x,xxstring)) < 0)
  4920.             return(y);
  4921.           if ((y = cmcfm()) < 0) return(y);
  4922. #ifdef OS2
  4923.           return(success = os2_settermwidth(x));
  4924. #else  /* Not OS/2 */
  4925.           tt_cols = x;
  4926.           return(success = 1);
  4927. #endif /* OS2 */
  4928.       }
  4929.  
  4930.       case XYTHIG:
  4931.         if ((y = cmnum(
  4932. #ifdef OS2
  4933.  "number of rows in display window during CONNECT, not including status line",
  4934.  tt_status[VTERM]?"24":"25",
  4935. #else
  4936.  "24","number of rows on your screen",
  4937. #endif /* OS2 */
  4938.                        10,&x,xxstring)) < 0)
  4939.           return(y);
  4940.         if ((y = cmcfm()) < 0) return(y);
  4941.  
  4942. #ifdef OS2
  4943.         return (success = os2_settermheight(x));
  4944. #else  /* Not OS/2 */
  4945.         tt_rows = x;
  4946.         return(success = 1);
  4947. #endif /* OS2 */
  4948.  
  4949. #ifdef OS2
  4950.       case XYTPRN: {                    /* Print Mode */
  4951.           extern bool xprint, aprint, cprint, uprint;
  4952.           if ((y = cmkey(prnmtab,nprnmtab,"","off", xxstring)) < 0) return(y);
  4953.           if ((x = cmcfm()) < 0) return(x);
  4954.           switch (y) {
  4955.             case 0:
  4956.               if (cprint || uprint || aprint || xprint)
  4957.                 printeroff();
  4958.               cprint = xprint = uprint = 0;
  4959.               setaprint(0);
  4960.               break;
  4961.             case 1:
  4962.               if (!(cprint || uprint || aprint || xprint))
  4963.                 printeron();
  4964.               setaprint(1);
  4965.               cprint = xprint = uprint = 0;
  4966.               break;
  4967.             case 2:
  4968.               if (!(cprint || uprint || aprint || xprint))
  4969.                 printeron();
  4970.               cprint = 1;
  4971.               setaprint(0);
  4972.           xprint = uprint = 0;
  4973.               break;
  4974.             case 3:
  4975.               if (!(cprint || uprint || aprint || xprint))
  4976.                 printeron();
  4977.               uprint = 1;
  4978.               setaprint(0);
  4979.               xprint = cprint = 0;
  4980.               break;
  4981.           }
  4982.           return(1);
  4983.       }
  4984. #else
  4985. #ifdef XPRINT
  4986.       case XYTPRN: {
  4987.           extern int tt_print;
  4988.           if ((x = seton(&tt_print)) < 0)
  4989.             return(x);
  4990.           return(success = 1);
  4991.       }
  4992. #endif /* XPRINT */
  4993. #endif /* OS2 */
  4994.  
  4995. #ifdef OS2
  4996.       case XYTSCNM: {
  4997.           extern int decscnm, decscnm_usr;
  4998.           if ((y = cmkey(normrev,4,"",
  4999.                          decscnm_usr?"reverse":"normal",
  5000.                          xxstring)
  5001.                ) < 0)
  5002.             return(y);
  5003.           if ((x = cmcfm()) < 0) return(x);
  5004.           decscnm_usr = y;
  5005.           if (decscnm != decscnm_usr)
  5006.             flipscreen(VTERM);
  5007.           return(1);
  5008.     }
  5009.     case XYTOPTI:
  5010.         if ((y = cmkey(onoff,2,"",tt_diff_upd?"on":"off",
  5011.                         xxstring)) < 0) return(y);
  5012.         if ((x = cmcfm()) < 0) return(x);
  5013.         tt_diff_upd = y;
  5014.         return(1);
  5015.     case XYTUPD: {
  5016.         int mode, delay;
  5017.         if ((mode = cmkey(scrnupd,nscrnupd,"","fast",xxstring)) < 0) {
  5018.             return(mode);
  5019.         } else {
  5020.             y = cmnum(
  5021.             "Pause between FAST screen updates in CONNECT mode, milliseconds",
  5022.                       "100",10,&x,xxstring
  5023.                       );
  5024.             if (x < 0 || x > 1000 ) {
  5025.                 printf(
  5026.             "\n?The update rate must be between 0 and 1000 milliseconds.\n"
  5027.                        );
  5028.                 return(success = 0);
  5029.             }
  5030.             if ((y = cmcfm()) < 0) return(y);
  5031.  
  5032.             updmode = tt_updmode = mode;
  5033.             return(setnum(&tt_update,x,y,10000));
  5034.         }
  5035.     }
  5036.     case XYTCTRL:
  5037.           if ((x = cmkey(termctrl,ntermctrl,"","7",xxstring)) < 0) {
  5038.               return(x);
  5039.           } else {
  5040.               if ((y = cmcfm()) < 0)
  5041.                   return(y);
  5042.               switch ( x ) {
  5043.               case 8:
  5044.                   send_c1 = send_c1_usr = TRUE;
  5045.                   break;
  5046.               case 7:
  5047.               default:
  5048.                   send_c1 = send_c1_usr = FALSE;
  5049.                   break;
  5050.               }
  5051.           }
  5052.           return(success = TRUE);
  5053.           break;
  5054.  
  5055. #ifdef PCFONTS
  5056.       case XYTFON:
  5057.         if ( !IsOS2FullScreen() ) {
  5058.             printf(
  5059.         "\n?SET TERMINAL FONT is only supported in Full Screen sessions.\n");
  5060.             return(success = FALSE);
  5061.         }
  5062.  
  5063.         if ((x = cmkey(term_font,ntermfont,"","default",xxstring)) < 0) {
  5064.             return(x);
  5065.         } else {
  5066.             if ((y = cmcfm()) < 0) return(y);
  5067.             if ( !os2LoadPCFonts() ) {
  5068.                 tt_font = x;
  5069.                 return(success = TRUE);
  5070.             } else {
  5071.                 printf(
  5072.       "\n?PCFONTS.DLL is not available in CKERMIT executable directory.\n");
  5073.                 return(success = FALSE);
  5074.             }
  5075.         }
  5076.         break;
  5077. #else /* PCFONTS */
  5078. #ifdef NT
  5079. #ifdef KUI
  5080.     case XYTFON:
  5081.         return(setguifont());           /* ckuus3.c */
  5082. #endif /* KUI */
  5083. #endif /* NT */
  5084. #endif /* PCFONTS */
  5085.  
  5086.       case XYTVCH: {
  5087.           extern int pheight, marginbot, cmd_rows, cmd_cols;
  5088.           if ((x = cmkey(tvctab,ntvctab,"",isWin95()?"win95-safe":"enabled",
  5089.                          xxstring)) < 0)
  5090.             return(x);
  5091.           if ((y = cmcfm()) < 0) return(y);
  5092. #ifndef KUI
  5093.           if (x != tt_modechg) {
  5094.               switch (x) {
  5095.                 case TVC_DIS:
  5096.                   /* When disabled the heights of all of the virtual screens */
  5097.                   /* must be equal to the physical height of the console     */
  5098.                   /* window and may not be changed.                          */
  5099.                   /* The width of the window may not be altered.             */
  5100.                   tt_modechg = TVC_ENA;                 /* Temporary */
  5101.                   if (marginbot > pheight-(tt_status[VTERM]?1:0))
  5102.                     marginbot = pheight-(tt_status[VTERM]?1:0);
  5103.                   tt_szchng[VCMD] = 1 ;
  5104.                   tt_rows[VCMD] = pheight;
  5105.                   VscrnInit(VCMD);
  5106.                   SetCols(VCMD);
  5107.                   cmd_rows = y;
  5108.  
  5109.                   tt_szchng[VTERM] = 2 ;
  5110.                   tt_rows[VTERM] = pheight - (tt_status[VTERM]?1:0);
  5111.                   VscrnInit(VTERM);
  5112.  
  5113.                   break;
  5114.  
  5115.                 case TVC_ENA:
  5116.                   /* When enabled the physical height of the console windows */
  5117.                   /* should be adjusted to the height of the virtual screen  */
  5118.                   /* The width may be set to anything.                       */
  5119.                   /* nothing to do                                           */
  5120.                   break;
  5121.  
  5122.               case TVC_W95:
  5123.                   /* Win95-safe mode allows the physical height to change    */
  5124.                   /* but restricts it to a width of 80 and a height equal to */
  5125.                   /* 25, 43, or 50.  Must be adjusted now.                   */
  5126.                   /* The virtual heights must be equal to the above.         */
  5127.                   if (pheight != 25 && pheight != 43 && pheight != 50) {
  5128.                       if (pheight < 25)
  5129.                         y = 25;
  5130.                       else if (pheight < 43)
  5131.                         y = 43;
  5132.                       else
  5133.                         y = 50;
  5134.                   } else
  5135.                     y = pheight;
  5136.  
  5137.                   tt_modechg = TVC_ENA; /* Temporary */
  5138.  
  5139.                   tt_szchng[VCMD] = 1;
  5140.                   tt_rows[VCMD] = y;
  5141.                   tt_cols[VCMD] = 80;
  5142.                   VscrnInit(VCMD);
  5143.                   SetCols(VCMD);
  5144.                   cmd_rows = y;
  5145.                   cmd_cols = 80;
  5146.  
  5147.                   marginbot = y-(tt_status[VTERM]?1:0);
  5148.                   tt_szchng[VTERM] = 2;
  5149.                   tt_rows[VTERM] = y - (tt_status[VTERM]?1:0);
  5150.                   tt_cols[VTERM] = 80;
  5151.                   VscrnInit(VTERM);
  5152.                   break;
  5153.               }
  5154.               tt_modechg = x;
  5155.           }
  5156.           return(success = 1);
  5157. #else
  5158.           return(success = 0);
  5159. #endif /* KUI */
  5160.       }
  5161.       case XYTSTAT: {
  5162.           extern int marginbot;
  5163.           if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5164.           if ((x = cmcfm()) < 0) return(x);
  5165.           if (y != tt_status[VTERM] || y != tt_status_usr[VTERM]) {
  5166.               /* Might need to fixup the margins */
  5167.               if ( marginbot == VscrnGetHeight(VTERM)-(tt_status[VTERM]?1:0) )
  5168.                 if (y) {
  5169.                     marginbot--;
  5170.                 } else {
  5171.                     marginbot++;
  5172.                 }
  5173.               tt_status_usr[VTERM] = tt_status[VTERM] = y;
  5174.               if (y) {
  5175.                     tt_szchng[VTERM] = 2;
  5176.                     tt_rows[VTERM]--;
  5177.                     VscrnInit(VTERM);  /* Height set here */
  5178. #ifdef TNCODE
  5179.                     if (TELOPT_ME(TELOPT_NAWS))
  5180.                       tn_snaws();
  5181. #endif /* TNCODE */
  5182. #ifdef RLOGCODE
  5183.                     if (TELOPT_ME(TELOPT_NAWS))
  5184.                       rlog_naws();
  5185. #endif /* RLOGCODE */
  5186. #ifdef SSHBUILTIN
  5187.                     if (TELOPT_ME(TELOPT_NAWS))
  5188.                       ssh_snaws();
  5189. #endif /* SSHBUILTIN */
  5190.               } else {
  5191.                   tt_szchng[VTERM] = 1;
  5192.                   tt_rows[VTERM]++;
  5193.                   VscrnInit(VTERM);     /* Height set here */
  5194. #ifdef TNCODE
  5195.                   if (TELOPT_ME(TELOPT_NAWS))
  5196.                     tn_snaws();
  5197. #endif /* TNCODE */
  5198. #ifdef RLOGCODE
  5199.                   if (TELOPT_ME(TELOPT_NAWS))
  5200.                     rlog_naws();
  5201. #endif /* RLOGCODE */
  5202. #ifdef SSHBUILTIN
  5203.                   if (TELOPT_ME(TELOPT_NAWS))
  5204.                     ssh_snaws();
  5205. #endif /* SSHBUILTIN */
  5206.               }
  5207.           }
  5208.           return(1);
  5209.       }
  5210. #endif /* OS2 */
  5211.  
  5212. #ifdef NT
  5213.       case XYTATTBUG:
  5214.         if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5215.         if ((x = cmcfm()) < 0) return(x);
  5216.         tt_attr_bug = y;
  5217.         return(1);
  5218. #endif /* NT */
  5219.  
  5220. #ifdef OS2
  5221.       case XYTSGRC:
  5222.         if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5223.         if ((x = cmcfm()) < 0) return(x);
  5224.         sgrcolors = y;
  5225.         return(1);
  5226.  
  5227.       case XYTSEND:
  5228.           if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5229.           if ((x = cmcfm()) < 0) return(x);
  5230.           tt_senddata = y;
  5231.           return(1);
  5232.  
  5233.       case XYTSEOB:
  5234.           if ((y = cmkey(ttyseobtab,2,"","us_cr",xxstring)) < 0) return(y);
  5235.           if ((x = cmcfm()) < 0) return(x);
  5236.           wy_blockend = y;
  5237.           return(1);
  5238.  
  5239.       case XYTURLHI: {
  5240.           int done = 0, attr = VT_CHAR_ATTR_NORMAL;
  5241.  
  5242.           if ((x = cmkey(onoff,2,"","on",xxstring)) < 0)
  5243.             return(x);
  5244.           if (x) {
  5245.               z = 0;
  5246.               while (!done) {
  5247.                   if ((y = cmkey(ttyprotab,nprotect,"",
  5248.                                  z?"done":"reverse",xxstring)) < 0)
  5249.                     return(y);
  5250.                   switch (y) {
  5251.                     case TTATTDONE:
  5252.                       done = TRUE;
  5253.                       break;
  5254.                     case TTATTBLI:
  5255.                       attr |= VT_CHAR_ATTR_BLINK;
  5256.                       break;
  5257.                     case TTATTREV:
  5258.                       attr |= VT_CHAR_ATTR_REVERSE;
  5259.                       break;
  5260.                     case TTATTITA:
  5261.                       attr |= VT_CHAR_ATTR_ITALIC;
  5262.                       break;
  5263.                     case TTATTUND:
  5264.                       attr |= VT_CHAR_ATTR_UNDERLINE;
  5265.                       break;
  5266.                     case TTATTBLD:
  5267.                       attr |= VT_CHAR_ATTR_BOLD;
  5268.                       break;
  5269.                     case TTATTDIM:
  5270.                       attr |= VT_CHAR_ATTR_DIM;
  5271.                       break;
  5272.                     case TTATTINV:
  5273.                       attr |= VT_CHAR_ATTR_INVISIBLE;
  5274.                       break;
  5275.                     case TTATTNOR:
  5276.                       break;
  5277.                   }
  5278.                   z = 1;                /* One attribute has been chosen */
  5279.               }
  5280.           }
  5281.           if ((z = cmcfm()) < 0) return(z);
  5282.           seturlhl(x);
  5283.           if (x)
  5284.             tt_url_hilite_attr = attr;
  5285.           return(1);
  5286.       }
  5287.       case XYTATTR:
  5288.         if ((x = cmkey(ttyattrtab,nattrib,"","underline",xxstring)) < 0)
  5289.           return(x);
  5290.         switch (x) {
  5291.           case TTATTBLI:
  5292.             if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5293.             if ((x = cmcfm()) < 0) return(x);
  5294.             trueblink = y;
  5295. #ifndef KUI
  5296.             if ( !trueblink && trueunderline ) {
  5297.                 trueunderline = 0;
  5298.                 printf("Warning: Underline being simulated by color.\n");
  5299.             }
  5300.  
  5301. #endif /* KUI */
  5302.             break;
  5303.  
  5304.           case TTATTDIM:
  5305.             if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5306.             if ((x = cmcfm()) < 0) return(x);
  5307.             truedim = y;
  5308.             break;
  5309.  
  5310.           case TTATTREV:
  5311.             if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5312.             if ((x = cmcfm()) < 0) return(x);
  5313.             truereverse = y;
  5314.             break;
  5315.  
  5316.           case TTATTUND:
  5317.             if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5318.             if ((x = cmcfm()) < 0) return(x);
  5319.             trueunderline = y;
  5320. #ifndef KUI
  5321.             if (!trueblink && trueunderline) {
  5322.                 trueblink = 1;
  5323.                 printf("Warning: True blink mode is active.\n");
  5324.             }
  5325. #endif /* KUI */
  5326.             break;
  5327.  
  5328.           case TTATTITA:
  5329.               if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5330.               if ((x = cmcfm()) < 0) return(x);
  5331.               trueitalic = y;
  5332.             break;
  5333.  
  5334.           case TTATTPRO: {      /* Set default Protected Character attribute */
  5335.               extern vtattrib WPattrib;    /* current WP Mode Attrib */
  5336.               extern vtattrib defWPattrib; /* default WP Mode Attrib */
  5337.               vtattrib wpa = {0,0,0,0,0,1,0,0,0,0,0};   /* Protected */
  5338.               int done = 0;
  5339.  
  5340.               x = 0;
  5341.               while (!done) {
  5342.                   if ((y = cmkey(ttyprotab,nprotect,"",
  5343.                                  x?"done":"dim",xxstring)) < 0)
  5344.                     return(y);
  5345.                   switch (y) {
  5346.                     case TTATTNOR:
  5347.                       break;
  5348.                     case TTATTBLI:      /* Blinking doesn't work */
  5349.                       wpa.blinking = TRUE;
  5350.                       break;
  5351.                     case TTATTREV:
  5352.                       wpa.reversed = TRUE;
  5353.                       break;
  5354.                     case TTATTITA:
  5355.                       wpa.italic = TRUE;
  5356.                       break;
  5357.                     case TTATTUND:
  5358.                       wpa.underlined = TRUE;
  5359.                       break;
  5360.                     case TTATTBLD:
  5361.                       wpa.bold = TRUE;
  5362.                       break;
  5363.                     case TTATTDIM:
  5364.                       wpa.dim = TRUE;
  5365.                       break;
  5366.                     case TTATTINV:
  5367.                       wpa.invisible = TRUE ;
  5368.                       break;
  5369.                     case TTATTDONE:
  5370.                       done = TRUE;
  5371.                       break;
  5372.                   }
  5373.                   x = 1;                /* One attribute has been chosen */
  5374.               }
  5375.               if ((x = cmcfm()) < 0) return(x);
  5376.               WPattrib = defWPattrib = wpa;
  5377.               break;
  5378.           }
  5379.         }
  5380.         return(1);
  5381.  
  5382.       case XYTKEY: {                    /* SET TERMINAL KEY */
  5383.           int t, x, y;
  5384.           int clear = 0, deflt = 0;
  5385.           int confirmed = 0;
  5386.           int flag = 0;
  5387.           int kc = -1;                  /* Key code */
  5388.           int litstr = 0;               /* Literal String? */
  5389.           char *s = NULL;               /* Key binding */
  5390. #ifndef NOKVERBS
  5391.           char *p = NULL;               /* Worker */
  5392. #endif /* NOKVERBS */
  5393.           con_event defevt;
  5394.           extern int os2gks;
  5395.           extern int mskkeys;
  5396.           extern int initvik;
  5397.           struct FDB kw,sw,nu,cm;
  5398.  
  5399.           defevt.type = error;
  5400.  
  5401.           if ((t = cmkey(ttkeytab,nttkey,"","",xxstring)) < 0)
  5402.             return(t);
  5403.           cmfdbi(&nu,                   /* First FDB - command switches */
  5404.                  _CMNUM,                /* fcode */
  5405.                  "/literal, keycode, or action",
  5406.                  "",                    /* default */
  5407.                  "",                    /* addtl string data */
  5408.                  10,                    /* addtl numeric data 1: radix */
  5409.                  0,                     /* addtl numeric data 2: 0 */
  5410.                  xxstring,              /* Processing function */
  5411.                  NULL,                  /* Keyword table */
  5412.                  &sw                    /* Pointer to next FDB */
  5413.                  );                     /*  */
  5414.           cmfdbi(&sw,                   /* Second FDB - switches */
  5415.                  _CMKEY,                /* fcode */
  5416.                  "",
  5417.                  "",                    /* default */
  5418.                  "",                    /* addtl string data */
  5419.                  nstrmswitab,           /* addtl numeric data 1: tbl size */
  5420.                  4,                     /* addtl numeric data 2: 4 = cmswi */
  5421.                  xxstring,              /* Processing function */
  5422.                  strmswitab,            /* Keyword table */
  5423.                  &kw                    /* Pointer to next FDB */
  5424.                  );
  5425.           cmfdbi(&kw,                   /* Third FDB - command switches */
  5426.                  _CMKEY,                /* fcode */
  5427.                  "/literal, keycode, or action",
  5428.                  "",                    /* default */
  5429.                  "",                    /* addtl string data */
  5430.                  nstrmkeytab,           /* addtl numeric data 1: tbl size */
  5431.                  0,                     /* addtl numeric data 2 */
  5432.                  xxstring,              /* Processing function */
  5433.                  strmkeytab,            /* Keyword table */
  5434.                  &cm                    /* Pointer to next FDB */
  5435.                  );
  5436.           cmfdbi(&cm,                   /* Final FDB - Confirmation */
  5437.                  _CMCFM,                /* fcode */
  5438.                  "",
  5439.                  "",                    /* default */
  5440.                  "",                    /* addtl string data */
  5441.                  0,                     /* addtl numeric data 1: tbl size */
  5442.                  0,                     /* addtl numeric data 2: 4 = cmswi */
  5443.                  xxstring,              /* Processing function */
  5444.                  NULL,                  /* Keyword table */
  5445.                  NULL                   /* Pointer to next FDB */
  5446.                  );
  5447.           while (kc < 0) {
  5448.               x = cmfdb(&nu);           /* Parse something */
  5449.               if (x < 0)
  5450.                 return(x);
  5451.  
  5452.               switch (cmresult.fcode) {
  5453.                 case _CMCFM:
  5454.                   printf(" Press key to be defined: ");
  5455.                   conbin((char)escape); /* Put terminal in binary mode */
  5456.                   os2gks = 0;           /* Turn off Kverb preprocessing */
  5457.                   kc = congks(0);       /* Get character or scan code */
  5458.                   os2gks = 1;           /* Turn on Kverb preprocessing */
  5459.                   concb((char)escape);  /* Restore terminal to cbreak mode */
  5460.                   if (kc < 0) {         /* Check for error */
  5461.                       printf("?Error reading key\n");
  5462.                       return(0);
  5463.                   }
  5464.                   shokeycode(kc,t);     /* Show current definition */
  5465.                   flag = 1;             /* Remember it's a multiline command */
  5466.                   break;
  5467.                 case _CMNUM:
  5468.                   kc = cmresult.nresult;
  5469.                   break;
  5470.                 case _CMKEY:
  5471.                   if (cmresult.fdbaddr == &sw) { /* Switch */
  5472.                       if (cmresult.nresult == 0)
  5473.                         litstr = 1;
  5474.                   } else if (cmresult.fdbaddr == &kw) { /* Keyword */
  5475.                       if (cmresult.nresult == 0)
  5476.                         clear = 1;
  5477.                       else
  5478.                         deflt = 1;
  5479.                       if ((x = cmcfm()) < 0)
  5480.                         return(x);
  5481.                       if (clear)
  5482.                         clearkeymap(t);
  5483.                       else if (deflt)
  5484.                         defaultkeymap(t);
  5485.                       initvik = 1;
  5486.                       return(1);
  5487.                   }
  5488.               }
  5489.           }
  5490.  
  5491.     /* Normal SET TERMINAL KEY <terminal> <scancode> <value> command... */
  5492.  
  5493.           if (mskkeys)
  5494.             kc = msktock(kc);
  5495.  
  5496.           if (kc < 0 || kc >= KMSIZE) {
  5497.               printf("?key code must be between 0 and %d\n", KMSIZE - 1);
  5498.               return(-9);
  5499.           }
  5500.           if (kc == escape) {
  5501.               printf("Sorry, %d is the CONNECT-mode escape character\n",kc);
  5502.               return(-9);
  5503.           }
  5504.           wideresult = -1;
  5505.           if (flag) {
  5506.               cmsavp(psave,PROMPTL);
  5507.               cmsetp(" Enter new definition: ");
  5508.               cmini(ckxech);
  5509.           }
  5510.         def_again:
  5511.           if (flag) prompt(NULL);
  5512.           if ((y = cmtxt("key definition,\n\
  5513.  or Ctrl-C to cancel this command,\n\
  5514.  or Enter to restore default definition",
  5515.                          "",&s,NULL)) < 0) {
  5516.               if (flag)                 /* Handle parse errors */
  5517.                 goto def_again;
  5518.               else
  5519.                 return(y);
  5520.           }
  5521.           s = brstrip(s);
  5522. #ifndef NOKVERBS
  5523.           p = s;                        /* Save this place */
  5524. #endif /* NOKVERBS */
  5525. /*
  5526.   If the definition included any \Kverbs, quote the backslash so the \Kverb
  5527.   will still be in the definition when the key is pressed.  We don't do this
  5528.   in zzstring(), because \Kverbs are valid only in this context and nowhere
  5529.   else.
  5530.  
  5531.   We use this code active for all versions that support SET KEY, even if they
  5532.   don't support \Kverbs, because otherwise \K would behave differently for
  5533.   different versions.
  5534. */
  5535.           for (x = 0, y = 0; s[x]; x++, y++) { /* Convert \K to \\K */
  5536.               if ((x > 0) &&
  5537.                   (s[x] == 'K' || s[x] == 'k')
  5538.                   ) {                   /* Have K */
  5539.  
  5540.                   if ((x == 1 && s[x-1] == CMDQ) ||
  5541.                       (x > 1 && s[x-1] == CMDQ && s[x-2] != CMDQ)) {
  5542.                       line[y++] = CMDQ; /* Make it \\K */
  5543.                   }
  5544.                   if (x > 1 && s[x-1] == '{' && s[x-2] == CMDQ) {
  5545.                       line[y-1] = CMDQ; /* Have \{K */
  5546.                       line[y++] = '{';  /* Make it \\{K */
  5547.                   }
  5548.               }
  5549.               line[y] = s[x];
  5550.           }
  5551.           line[y++] = NUL;              /* Terminate */
  5552.           s = line + y + 1;             /* Point to after it */
  5553.           x = LINBUFSIZ - (int) strlen(line) - 1; /* Get remaining space */
  5554.           if ((x < (LINBUFSIZ / 2)) ||
  5555.               (zzstring(line, &s, &x) < 0)) { /* Expand variables, etc. */
  5556.               printf("?Key definition too long\n");
  5557.               if (flag) cmsetp(psave);
  5558.               return(-9);
  5559.           }
  5560.           s = line + y + 1;             /* Point to result. */
  5561.  
  5562. #ifndef NOKVERBS
  5563. /*
  5564.   Special case: see if the definition starts with a \Kverb.
  5565.   If it does, point to it with p, otherwise set p to NULL.
  5566. */
  5567.           p = s;
  5568.           if (*p++ == CMDQ) {
  5569.               if (*p == '{') p++;
  5570.               p = (*p == 'k' || *p == 'K') ? p + 1 : NULL;
  5571.           }
  5572. #endif /* NOKVERBS */
  5573.  
  5574.           switch (strlen(s)) {          /* Action depends on length */
  5575.             case 0:                     /* Clear individual key def */
  5576.               deletekeymap(t,kc);
  5577.               break;
  5578.             case 1:
  5579.               if (!litstr) {
  5580.                   defevt.type = key;    /* Single character */
  5581.                   defevt.key.scancode = *s;
  5582.                   break;
  5583.               }
  5584.             default:                    /* Character string */
  5585. #ifndef NOKVERBS
  5586.               if (p) {
  5587.                   y = xlookup(kverbs,p,nkverbs,&x); /* Look it up */
  5588.                   /* Need exact match */
  5589.                   debug(F101,"set key kverb lookup",0,y);
  5590.                   if (y > -1) {
  5591.                       defevt.type = kverb;
  5592.                       defevt.kverb.id = y;
  5593.                       break;
  5594.                   }
  5595.               }
  5596. #endif /* NOKVERBS */
  5597.               if (litstr) {
  5598.                   defevt.type = literal;
  5599.                   defevt.literal.string = (char *) malloc(strlen(s)+1);
  5600.                   if (defevt.literal.string)
  5601.                     strcpy(defevt.literal.string, s); /* safe */
  5602.               } else {
  5603.                   defevt.type = macro;
  5604.                   defevt.macro.string = (char *) malloc(strlen(s)+1);
  5605.                   if (defevt.macro.string)
  5606.                     strcpy(defevt.macro.string, s); /* safe */
  5607.               }
  5608.               break;
  5609.           }
  5610.           insertkeymap(t, kc, defevt);
  5611.           if (flag)
  5612.             cmsetp(psave);
  5613.           initvik = 1;                  /* Update VIK table */
  5614.           return(1);
  5615.       }
  5616.  
  5617. #ifdef PCTERM
  5618.       case XYTPCTERM:                   /* PCTERM Keyboard Mode */
  5619.         if ((x = seton(&tt_pcterm)) < 0) return(x);
  5620.         return(success = 1);
  5621. #endif /* PCTERM */
  5622. #endif /* OS2 */
  5623.  
  5624. #ifdef CK_TRIGGER
  5625.       case XYTRIGGER:
  5626.         if ((y = cmtxt("String to trigger automatic return to command mode",
  5627.                        "",&s,xxstring)) < 0)
  5628.           return(y);
  5629.         makelist(s,tt_trigger,TRIGGERS);
  5630.         return(1);
  5631. #endif /* CK_TRIGGER */
  5632.  
  5633. #ifdef OS2
  5634.       case XYTSAC:
  5635.         if ((y = cmnum("ASCII value to use for spacing attributes",
  5636.                        "32",10,&x,xxstring)) < 0)
  5637.           return(y);
  5638.         if ((y = cmcfm()) < 0) return(y);
  5639.         tt_sac = x;
  5640.         return(success = 1);
  5641.  
  5642.       case XYTKBDGL: {      /* SET TERM KBD-FOLLOWS-GL/GR */
  5643.           extern int tt_kb_glgr;        /* from ckoco3.c */
  5644.           if ((x = seton(&tt_kb_glgr)) < 0)
  5645.               return(x);
  5646.           return(success = 1);
  5647.       }
  5648. #ifndef NOCSETS
  5649.       case XYTVTLNG:        /* SET TERM DEC-LANGUAGE */
  5650.         if ((y = cmkey(vtlangtab,nvtlangtab,"VT language",
  5651.                        IS97801(tt_type_mode)?"german":"north-american",
  5652.                        xxstring)) < 0)
  5653.           return(y);
  5654.         if ((x = cmcfm()) < 0) return(x);
  5655.  
  5656.         /* A real VT terminal would use the language to set the   */
  5657.         /* default keyboard language for both 8-bit multinational */
  5658.         /* and 7-bit national modes.  For 8-bit mode it would     */
  5659.         /* set the terminal character-set to the ISO set if it    */
  5660.         /* is not already set.                                    */
  5661.         /* Latin-1 can be replaced by DEC Multinational           */
  5662.         switch (y) {
  5663.           case VTL_NORTH_AM:  /* North American */
  5664.             /* Multinational: Latin-1   */
  5665.             /* National:      US_ASCII  */
  5666.             dec_lang = y;
  5667.             dec_nrc = TX_ASCII;
  5668.             dec_kbd = TX_8859_1;
  5669.             break;
  5670.           case VTL_BRITISH :
  5671.             /* Multinational: Latin-1   */
  5672.             /* National:      UK_ASCII  */
  5673.             dec_lang = y;
  5674.             dec_nrc = TX_BRITISH;
  5675.             dec_kbd = TX_8859_1;
  5676.             break;
  5677.           case VTL_FRENCH  :
  5678.           case VTL_BELGIAN :
  5679.           case VTL_CANADIAN:
  5680.             /* Multinational: Latin-1   */
  5681.             /* National:      FR_ASCII  */
  5682.             dec_lang = y;
  5683.             dec_nrc = TX_FRENCH;
  5684.             dec_kbd = TX_8859_1;
  5685.             break;
  5686.           case VTL_FR_CAN  :
  5687.             /* Multinational: Latin-1   */
  5688.             /* National:      FC_ASCII  */
  5689.             dec_lang = y;
  5690.             dec_nrc = TX_CN_FRENCH;
  5691.             dec_kbd = TX_8859_1;
  5692.             break;
  5693.           case VTL_DANISH  :
  5694.           case VTL_NORWEGIA:
  5695.             /* Multinational: Latin-1   */
  5696.             /* National:      NO_ASCII  */
  5697.             dec_lang = y;
  5698.             dec_nrc = TX_NORWEGIAN;
  5699.             dec_kbd = TX_8859_1;
  5700.             break;
  5701.           case VTL_FINNISH :
  5702.             /* Multinational: Latin-1   */
  5703.             /* National:      FI_ASCII  */
  5704.             dec_lang = y;
  5705.             dec_nrc = TX_FINNISH;
  5706.             dec_kbd = TX_8859_1;
  5707.             break;
  5708.           case VTL_GERMAN  :
  5709.             /* Multinational: Latin-1   */
  5710.             /* National:      GR_ASCII  */
  5711.             dec_lang = y;
  5712.             dec_nrc = TX_GERMAN;
  5713.             dec_kbd = TX_8859_1;
  5714.             break;
  5715.           case VTL_DUTCH   :
  5716.             /* Multinational: Latin-1   */
  5717.             /* National:      DU_ASCII  */
  5718.             dec_lang = y;
  5719.             dec_nrc = TX_DUTCH;
  5720.             dec_kbd = TX_8859_1;
  5721.             break;
  5722.           case VTL_ITALIAN :
  5723.             /* Multinational: Latin-1   */
  5724.             /* National:      IT_ASCII  */
  5725.             dec_lang = y;
  5726.             dec_nrc = TX_ITALIAN;
  5727.             dec_kbd = TX_8859_1;
  5728.             break;
  5729.           case VTL_SW_FR   :
  5730.           case VTL_SW_GR   :
  5731.             /* Multinational: Latin-1   */
  5732.             /* National:      CH_ASCII  */
  5733.             dec_lang = y;
  5734.             dec_nrc = TX_SWISS;
  5735.             dec_kbd = TX_8859_1;
  5736.             break;
  5737.           case VTL_SWEDISH :
  5738.             /* Multinational: Latin-1   */
  5739.             /* National:      SW_ASCII  */
  5740.             dec_lang = y;
  5741.             dec_nrc = TX_SWEDISH;
  5742.             dec_kbd = TX_8859_1;
  5743.             break;
  5744.           case VTL_SPANISH :
  5745.             /* Multinational: Latin-1   */
  5746.             /* National:      SP_ASCII  */
  5747.             dec_lang = y;
  5748.             dec_nrc = TX_SPANISH;
  5749.             dec_kbd = TX_8859_1;
  5750.             break;
  5751.           case VTL_PORTUGES:
  5752.             /* Multinational: Latin-1   */
  5753.             /* National:      Portugese ASCII  */
  5754.             dec_lang = y;
  5755.             dec_nrc = TX_PORTUGUESE;
  5756.             dec_kbd = TX_8859_1;
  5757.             break;
  5758.           case VTL_HEBREW  :
  5759.             /* Multinational: Latin-Hebrew / DEC-Hebrew  */
  5760.             /* National:      DEC 7-bit Hebrew  */
  5761.             dec_lang = y;
  5762.             dec_nrc = TX_HE7;
  5763.             dec_kbd = TX_8859_8;
  5764.             break;
  5765.           case VTL_GREEK   :
  5766.             /* Multinational: Latin-Greek / DEC-Greek   */
  5767.             /* National:      DEC Greek NRC             */
  5768.             /* is ELOT927 equivalent to DEC Greek????   */
  5769.             dec_lang = y;
  5770.             dec_nrc = TX_ELOT927;
  5771.             dec_kbd = TX_8859_7;
  5772.             break;
  5773. #ifdef COMMENT
  5774.           case VTL_TURK_Q  :
  5775.           case VTL_TURK_F  :
  5776.             /* Multinational: Latin-Turkish / DEC-Turkish   */
  5777.             /* National:      DEC 7-bit Turkish             */
  5778.             break;
  5779. #endif /* COMMENT */
  5780.           case VTL_HUNGARIA:
  5781.             /* Multinational: Latin-2   */
  5782.             /* National:      no national mode  */
  5783.             dec_lang = y;
  5784.             dec_nrc = TX_HUNGARIAN;
  5785.             dec_kbd = TX_8859_2;
  5786.             break;
  5787.           case VTL_SLOVAK  :
  5788.           case VTL_CZECH   :
  5789.           case VTL_POLISH  :
  5790.           case VTL_ROMANIAN:
  5791.             /* Multinational: Latin-2   */
  5792.             /* National:      no national mode  */
  5793.             dec_lang = y;
  5794.             dec_nrc = TX_ASCII;
  5795.             dec_kbd = TX_8859_2;
  5796.             break;
  5797.           case VTL_RUSSIAN :
  5798.             /* Multinational: Latin-Cyrillic / KOI-8   */
  5799.             /* National:      DEC Russian NRC  */
  5800.             dec_lang = y;
  5801.             dec_nrc = TX_KOI7;
  5802.             dec_kbd = TX_8859_5;
  5803.             break;
  5804.           case VTL_LATIN_AM:
  5805.             /* Multinational: not listed in table   */
  5806.             /* National:      not listed in table  */
  5807.             dec_lang = y;
  5808.             dec_nrc = TX_ASCII;
  5809.             dec_kbd = TX_8859_1;
  5810.             break;
  5811. #ifdef COMMENT
  5812.           case VTL_SCS     :
  5813.             /* Multinational: Latin-2   */
  5814.             /* National:      SCS NRC   */
  5815.             break;
  5816. #endif /* COMMENT */
  5817.           default:
  5818.             return(success = 0);
  5819.         }
  5820.         if (IS97801(tt_type_mode)) {
  5821.             SNI_bitmode(cmask == 0377 ? 8 : 7);
  5822.         }
  5823.         return(success = 1);
  5824. #endif /* NOCSETS */
  5825.  
  5826.       case XYTVTNRC: {                  /* SET TERM DEC-NRC-MODE */
  5827.           extern int decnrcm_usr, decnrcm;        /* from ckoco3.c */
  5828.           if ((x = seton(&decnrcm_usr)) < 0)
  5829.             return(x);
  5830.           decnrcm = decnrcm_usr;
  5831.           return(success = 1);
  5832.       }
  5833.       case XYTSNIPM: {                  /* SET TERM SNI-PAGEMODE */
  5834.           extern int sni_pagemode, sni_pagemode_usr;
  5835.           if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5836.           if ((x = cmcfm()) < 0) return(x);
  5837.           sni_pagemode_usr = sni_pagemode = y;
  5838.           return(success = 1);
  5839.       }
  5840.       case XYTSNISM: {                  /* SET TERM SNI-SCROLLMODE */
  5841.           extern int sni_scroll_mode, sni_scroll_mode_usr;
  5842.           if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5843.           if ((x = cmcfm()) < 0) return(x);
  5844.           sni_scroll_mode_usr = sni_scroll_mode = y;
  5845.           return(success = 1);
  5846.       }
  5847.       case XYTSNICC: {  /* SET TERM SNI-CH.CODE */
  5848.           extern int sni_chcode_usr;
  5849.           if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5850.           if ((x = cmcfm()) < 0) return(x);
  5851.           sni_chcode_usr = y;
  5852.           SNI_chcode(y);
  5853.           return(success = 1);
  5854.       }
  5855.       case XYTSNIFV: {  /* SET TERM SNI-FIRMWARE-VERSIONS */
  5856.           extern CHAR sni_kbd_firmware[], sni_term_firmware[];
  5857.           CHAR kbd[7],term[7];
  5858.  
  5859.           if ((x = cmfld("Keyboard Firmware Version",sni_kbd_firmware,
  5860.                          &s, xxstring)) < 0)
  5861.             return(x);
  5862.           if ((int)strlen(s) != 6) {
  5863.               printf("?Sorry - the firmware version must be 6 digits long\n");
  5864.               return(-9);
  5865.           }
  5866.           for (i = 0; i < 6; i++) {
  5867.               if (!isdigit(s[i])) {
  5868.    printf("?Sorry - the firmware version can only contain digits [0-9]\n");
  5869.                   return(-9);
  5870.               }
  5871.           }
  5872.           ckstrncpy(kbd,s,7);
  5873.  
  5874.           if ((x = cmfld("Terminal Firmware Version",sni_term_firmware,
  5875.                          &s, xxstring)) < 0)
  5876.             return(x);
  5877.           if ((int)strlen(s) != 6) {
  5878.               printf("?Sorry - the firmware version must be 6 digits long\n");
  5879.               return(-9);
  5880.           }
  5881.           for (i = 0; i < 6; i++) {
  5882.               if (!isdigit(s[i])) {
  5883.    printf("?Sorry - the firmware version can only contain digits [0-9]\n");
  5884.                    return(-9);
  5885.               }
  5886.           }
  5887.           ckstrncpy(term,s,7);
  5888.           if ((x = cmcfm()) < 0) return(x);
  5889.  
  5890.           ckstrncpy(sni_kbd_firmware,kbd,7);
  5891.           ckstrncpy(sni_term_firmware,term,7);
  5892.           return(success = 1);
  5893.     }
  5894.  
  5895.     case XYTLSP: {              /* SET TERM LINE-SPACING */
  5896.         if ((x = cmfld("Line Spacing","1",&s, xxstring)) < 0)
  5897.           return(x);
  5898.         if (isfloat(s,0) < 1) {        /* (sets floatval) */
  5899.             printf("?Integer or floating-point number required\n");
  5900.             return(-9);
  5901.         }
  5902.         if (floatval < 1.0 || floatval > 3.0) {
  5903.             printf("?Value must within the range 1.0 and 3.0 (inclusive)\n");
  5904.             return(-9);
  5905.         }
  5906.         if ((x = cmcfm()) < 0) return(x);
  5907. #ifdef KUI
  5908.         tt_linespacing[VCMD] = tt_linespacing[VTERM] = floatval;
  5909.         return(success = 1);
  5910. #else /* KUI */
  5911.         printf("?Sorry, Line-spacing is only supported in K95G.EXE.\n");
  5912.         return(success = 0);
  5913. #endif /* KUI */
  5914.     }
  5915. #endif /* OS2 */
  5916.  
  5917.       default:                          /* Shouldn't get here. */
  5918.         return(-2);
  5919.     }
  5920. #endif /* MAC */
  5921. #ifdef COMMENT
  5922.     /*
  5923.       This was supposed to shut up picky compilers but instead it makes
  5924.       most compilers complain about "statement not reached".
  5925.     */
  5926.     return(-2);
  5927. #endif /* COMMENT */
  5928. #ifdef OS2
  5929. return(-2);
  5930. #endif /* OS2 */
  5931. }
  5932.  
  5933. #ifdef OS2
  5934. int
  5935. settitle(void) {
  5936.     extern char usertitle[];
  5937.     if ((y = cmtxt("title text","",&s,xxstring)) < 0)
  5938.       return(y);
  5939. #ifdef IKSD
  5940.     if (inserver) {
  5941.         printf("?Sorry, command disabled.\r\n");
  5942.         return(success = 0);
  5943.     }
  5944. #endif /* IKSD */
  5945.     s = brstrip(s);
  5946.     ckstrncpy(usertitle,s,64);
  5947.     os2settitle("",1);
  5948.     return(1);
  5949. }
  5950.  
  5951. static struct keytab dialertab[] = {    /* K95 Dialer types */
  5952.     "backspace",        0, 0,
  5953.     "enter",            1, 0
  5954. };
  5955. static int ndialer = 2;
  5956.  
  5957. int
  5958. setdialer(void) {
  5959.     int t, x, y;
  5960.     int clear = 0, deflt = 0;
  5961.     int kc;                             /* Key code */
  5962.     char *s = NULL;                     /* Key binding */
  5963. #ifndef NOKVERBS
  5964.     char *p = NULL;                     /* Worker */
  5965. #endif /* NOKVERBS */
  5966.     con_event defevt;
  5967.     extern int os2gks;
  5968.     extern int mskkeys;
  5969.     extern int initvik;
  5970.  
  5971.     defevt.type = error;
  5972.  
  5973.     if (( x = cmkey(dialertab, ndialer,
  5974.                     "Kermit-95 dialer work-arounds",
  5975.                     "", xxstring)) < 0 )
  5976.       return(x);
  5977.     switch (x) {
  5978.       case 0:                           /* Backspace */
  5979.         kc = 264;
  5980.         break;
  5981.       case 1:                           /* Enter */
  5982.         kc = 269;
  5983.         break;
  5984.       default:
  5985.         printf("Illegal value in setdialer()\n");
  5986.         return(-9);
  5987.     }
  5988.     if ((y = cmtxt("Key definition","",&s,xxstring)) < 0)
  5989.       return(y);
  5990.  
  5991. #ifdef IKSD
  5992.     if (inserver) {
  5993.         printf("?Sorry, command disabled.\r\n");
  5994.         return(success = 0);
  5995.     }
  5996. #endif /* IKSD */
  5997.     s = brstrip(s);
  5998. #ifndef NOKVERBS
  5999.     p = s;                              /* Save this place */
  6000. #endif /* NOKVERBS */
  6001. /*
  6002.   If the definition included any \Kverbs, quote the backslash so the \Kverb
  6003.   will still be in the definition when the key is pressed.  We don't do this
  6004.   in zzstring(), because \Kverbs are valid only in this context and nowhere
  6005.   else.
  6006.  
  6007.   We use this code active for all versions that support SET KEY, even if they
  6008.   don't support \Kverbs, because otherwise \K would behave differently for
  6009.   different versions.
  6010. */
  6011.     for (x = 0, y = 0; s[x]; x++, y++) { /* Convert \K to \\K */
  6012.         if ((x > 0) &&
  6013.             (s[x] == 'K' || s[x] == 'k')
  6014.             ) {                         /* Have K */
  6015.  
  6016.             if ((x == 1 && s[x-1] == CMDQ) ||
  6017.                 (x > 1 && s[x-1] == CMDQ && s[x-2] != CMDQ)) {
  6018.                 line[y++] = CMDQ;       /* Make it \\K */
  6019.             }
  6020.             if (x > 1 && s[x-1] == '{' && s[x-2] == CMDQ) {
  6021.                 line[y-1] = CMDQ;       /* Have \{K */
  6022.                 line[y++] = '{';        /* Make it \\{K */
  6023.             }
  6024.         }
  6025.         line[y] = s[x];
  6026.     }
  6027.     line[y++] = NUL;                    /* Terminate */
  6028.     s = line + y + 1;                   /* Point to after it */
  6029.     x = LINBUFSIZ - (int) strlen(line) - 1; /* Calculate remaining space */
  6030.     if ((x < (LINBUFSIZ / 2)) ||
  6031.         (zzstring(line, &s, &x) < 0)) { /* Expand variables, etc. */
  6032.         printf("?Key definition too long\n");
  6033.         return(-9);
  6034.     }
  6035.     s = line + y + 1;                   /* Point to result. */
  6036.  
  6037. #ifndef NOKVERBS
  6038. /*
  6039.   Special case: see if the definition starts with a \Kverb.
  6040.   If it does, point to it with p, otherwise set p to NULL.
  6041. */
  6042.     p = s;
  6043.     if (*p++ == CMDQ) {
  6044.         if (*p == '{') p++;
  6045.         p = (*p == 'k' || *p == 'K') ? p + 1 : NULL;
  6046.     }
  6047. #endif /* NOKVERBS */
  6048.  
  6049.     /* Clear the definition for SET KEY */
  6050.     if (macrotab[kc]) {                 /* Possibly free old macro from key. */
  6051.         free((char *)macrotab[kc]);
  6052.         macrotab[kc] = NULL;
  6053.     }
  6054.     keymap[kc] = (KEY) kc;
  6055.  
  6056.     /* Now reprogram the default value for all terminal types */
  6057.     /* remember to treat Wyse and Televideo terminals special */
  6058.     /* because of their use of Kverbs for Backspace and Enter */
  6059.     for (t = 0; t <= TT_MAX; t++) {
  6060.         if ( ISDG200(t) && kc == 264) {
  6061.             extern char * udkfkeys[] ;
  6062.             if (kc == 264) {            /* \Kdgbs */
  6063.                 if (udkfkeys[83])
  6064.                   free(udkfkeys[83]);
  6065.                 udkfkeys[83] = strdup(s);
  6066.             }
  6067.         } else if (ISWYSE(t) || ISTVI(t)) {
  6068.             extern char * udkfkeys[] ;
  6069.             if (kc == 264) {            /* \Kwybs or \Ktvibs */
  6070.                 if (udkfkeys[32])
  6071.                   free(udkfkeys[32]);
  6072.                 udkfkeys[32] = strdup(s);
  6073.             }
  6074.             if (kc == 269) {            /* \Kwyenter and \Kwyreturn */
  6075.                 if (udkfkeys[39])       /* \Ktvienter and \Ktvireturn */
  6076.                   free(udkfkeys[39]);
  6077.                 udkfkeys[39] = strdup(s);
  6078.                 if (udkfkeys[49])
  6079.                   free(udkfkeys[49]);
  6080.                 udkfkeys[49] = strdup(s);
  6081.             }
  6082.         } else {
  6083.             switch (strlen(s)) {        /* Action depends on length */
  6084.               case 0:                   /* Clear individual key def */
  6085.                 deletekeymap(t,kc);
  6086.                 break;
  6087.               case 1:
  6088.                 defevt.type = key;      /* Single character */
  6089.                 defevt.key.scancode = *s;
  6090.                 break;
  6091.               default:                  /* Character string */
  6092. #ifndef NOKVERBS
  6093.                 if (p) {
  6094.                     y = xlookup(kverbs,p,nkverbs,&x); /* Look it up */
  6095.                     /* Exact match req'd */
  6096.                     debug(F101,"set key kverb lookup",0,y);
  6097.                     if (y > -1) {
  6098.                         defevt.type = kverb;
  6099.                         defevt.kverb.id = y;
  6100.                         break;
  6101.                     }
  6102.                 }
  6103. #endif /* NOKVERBS */
  6104.                 defevt.type = macro;
  6105.                 defevt.macro.string = (char *) malloc(strlen(s)+1);
  6106.                 if (defevt.macro.string)
  6107.                   strcpy(defevt.macro.string, s); /* safe */
  6108.                 break;
  6109.             }
  6110.             insertkeymap( t, kc, defevt ) ;
  6111.             initvik = 1;                /* Update VIK table */
  6112.         }
  6113.     }
  6114.     return(1);
  6115. }
  6116. #endif /* OS2 */
  6117.  
  6118. #ifdef NT
  6119. int
  6120. setwin95( void ) {
  6121.     int x, y, z;
  6122.  
  6123.     if (( y = cmkey(win95tab, nwin95,
  6124.                     "Windows 95 specific work-arounds",
  6125.                     "keyboard-translation",
  6126.                     xxstring)) < 0 )
  6127.         return (y);
  6128.     switch (y) {
  6129.       case XYWPOPUP:
  6130.         if ((y = cmkey(onoff,2,"popups are used to prompt the user for data",
  6131.                        "on",xxstring)) < 0)
  6132.           return(y);
  6133.         if ((x = cmcfm()) < 0) return(x);
  6134.         win95_popup = y;
  6135.         return(1);
  6136.  
  6137.       case XYW8_3:
  6138.         if ((y = cmkey(onoff,2,"8.3 FAT file names","off",xxstring)) < 0)
  6139.           return(y);
  6140.         if ((x = cmcfm()) < 0) return(x);
  6141.         win95_8_3 = y;
  6142.         return(1);
  6143.  
  6144.       case XYWSELECT:
  6145.         if ((y = cmkey(onoff,2,"\"select()\" fails on write","off",
  6146.              xxstring)) < 0)
  6147.           return(y);
  6148.         if ((x = cmcfm()) < 0) return(x);
  6149.         win95selectbug = y;
  6150.         return(1);
  6151.  
  6152.       case XYWAGR:
  6153.         if ((y = cmkey(onoff,2,"Right-Alt is Alt-Gr","off",xxstring)) < 0)
  6154.           return(y);
  6155.         if ((x = cmcfm()) < 0) return(x);
  6156.         win95altgr = y;
  6157.         return(1);
  6158.  
  6159.       case XYWOIO:
  6160.         if ((y = cmkey(onoff,2,"Use Overlapped I/O","on",xxstring)) < 0)
  6161.           return(y);
  6162.         if (y) {
  6163.             if ((x = cmnum("Maximum number of outstanding I/O requests",
  6164.                            "10",10,&z,xxstring)) < 0)
  6165.               return(x);
  6166.             if (z < 1 || z > 7) {
  6167.                 printf(
  6168. "?Maximum outstanding I/O requests must be between 1 and 7.\n");
  6169.                 return(-9);
  6170.             }
  6171.         } else
  6172.           z = 1;
  6173.         if ((x = cmcfm()) < 0) return(x);
  6174.         owwait = !y;
  6175.         maxow = maxow_usr = z;
  6176.         return(1);
  6177.  
  6178.       case XYWKEY:
  6179. #ifndef COMMENT
  6180.         printf("\n?\"Keyboard-Translation\" is no longer required.\n");
  6181.         return(-9);
  6182. #else /* COMMENT */
  6183.         if (( z = cmkey(tcstab, ntcs,
  6184.                         "Keyboard Character Set",
  6185.                         "latin1-iso",
  6186.                         xxstring)) < 0)
  6187.           return (z);
  6188.         if ((x = cmcfm()) < 0)
  6189.           return(x);
  6190.  
  6191.         win95kcsi = z;
  6192.         win95kl2 = (win95kcsi == TC_2LATIN);
  6193.  
  6194.         if (win95kcsi == TC_TRANSP) {
  6195.             win95kcs = NULL;
  6196.         } else {
  6197. #ifdef UNICODE
  6198.             win95kcs = xlr[win95kcsi][tx2fc(tcsl)];
  6199. #else /* UNICODE */
  6200.             win95kcs = xlr[win95kcsi][tcsl];
  6201. #endif /* UNICODE */
  6202.         }
  6203.         return(1);
  6204. #endif /* COMMENT */
  6205.  
  6206.       case XYWLUC:
  6207.         if ((y = cmkey(onoff,2,"Unicode-to-Lucida-Console substitutions",
  6208.                        "on",xxstring)) < 0)
  6209.           return(y);
  6210.         if ((x = cmcfm()) < 0) return(x);
  6211.         win95lucida = y;
  6212.         return(1);
  6213.  
  6214.       case XYWHSL:
  6215.     if ((y = cmkey(onoff,2,"Horizontal Scan Line substitutions",
  6216.                "on",xxstring)) < 0)
  6217.       return(y);
  6218.     if ((x = cmcfm()) < 0) return(x);
  6219.     win95hsl = y;
  6220.     return(1);
  6221.  
  6222.       default:
  6223.         printf("Illegal value in setwin95()\n");
  6224.         return(-9);
  6225.     }
  6226. }
  6227. #endif /* NT */
  6228.  
  6229. #ifdef OS2
  6230. int
  6231. setprty (
  6232. #ifdef CK_ANSIC
  6233.     void
  6234. #endif /* CK_ANSIC */
  6235. /* setprty */ ) {
  6236.     int x, y, z;
  6237.  
  6238.     if (( y = cmkey(prtytab, nprty,
  6239.                     "priority level of terminal and communication threads",
  6240.                     "foreground-server",
  6241.                     xxstring)) < 0 )
  6242.       return (y);
  6243.  
  6244.     if ((x = cmcfm()) < 0)
  6245.       return (x);
  6246. #ifdef IKSD
  6247.     if (inserver &&
  6248. #ifdef IKSDCONF
  6249.          iksdcf
  6250. #else
  6251.          1
  6252. #endif /* IKSDCONF */
  6253.     ) {
  6254.         if ((y = cmcfm()) < 0) return(y);
  6255.         printf("?Sorry, command disabled.\r\n");
  6256.         return(success = 0);
  6257.     }
  6258. #endif /* IKSD */
  6259.     priority = y;
  6260.     return(TRUE);
  6261. }
  6262. #endif /* OS2 */
  6263.  
  6264. int
  6265. setbell() {
  6266.     int y, x;
  6267. #ifdef OS2
  6268.     int z;
  6269. #endif /* OS2 */
  6270.  
  6271.     if ((y = cmkey(beltab,nbeltab,
  6272. #ifdef OS2
  6273.         "how console and terminal bells should\nbe generated", "audible",
  6274. #else
  6275.         "Whether Kermit should ring the terminal bell (beep)", "on",
  6276. #endif /* OS2 */
  6277.                    xxstring)) < 0)
  6278.           return(y);
  6279.  
  6280. #ifdef IKSD
  6281.     if (inserver) {
  6282.         if ((y = cmcfm()) < 0) return(y);
  6283.         printf("?Sorry, command disabled.\r\n");
  6284.         return(success = 0);
  6285.     }
  6286. #endif /* IKSD */
  6287.  
  6288.     switch (y) {                        /* SET BELL */
  6289.       case XYB_NONE:
  6290. #ifdef OS2
  6291.       case XYB_VIS:
  6292. #endif /* OS2 */
  6293.         if ((x = cmcfm()) < 0)
  6294.           return(x);
  6295. #ifdef OS2
  6296.         tt_bell = y;
  6297. #else
  6298.         tt_bell = 0;
  6299. #endif /* OS2 */
  6300.         break;
  6301.  
  6302.       case XYB_AUD:
  6303. #ifdef OS2
  6304.         if ((x = cmkey(audibletab, naudibletab,
  6305.                "how audible console and terminal\nbells should be generated",
  6306.                        "beep",xxstring))<0)
  6307.           return(x);
  6308.         if ((z = cmcfm()) < 0)
  6309.           return(z);
  6310.         tt_bell = y | x;
  6311. #else
  6312.         /* This lets C-Kermit accept but ignore trailing K95 keywords */
  6313.         if ((x = cmtxt("Confirm with carriage return","",&s,xxstring)) < 0)
  6314.           return(x);
  6315.         tt_bell = 1;
  6316. #endif /* OS2 */
  6317.         break;
  6318.     }
  6319.     return(1);
  6320. }
  6321.  
  6322. #ifdef OS2MOUSE
  6323. int
  6324. setmou(
  6325. #ifdef CK_ANSIC
  6326.        void
  6327. #endif /* CK_ANSIC */
  6328.  /* setmou */ ) {
  6329.     extern int initvik;
  6330.     int button = 0, event = 0;
  6331.     char * p;
  6332.  
  6333.     if ((y = cmkey(mousetab,nmtab,"","",xxstring)) < 0)
  6334.       return(y);
  6335.  
  6336. #ifdef IKSD
  6337.     if (inserver) {
  6338.         if ((y = cmcfm()) < 0) return(y);
  6339.         printf("?Sorry, command disabled.\r\n");
  6340.         return(success = 0);
  6341.     }
  6342. #endif /* IKSD */
  6343.  
  6344.     if (y == XYM_ON) {                  /* MOUSE ACTIVATION */
  6345.         int old_mou = tt_mouse;
  6346.         if ((x = seton(&tt_mouse)) < 0)
  6347.             return(x);
  6348.         if (tt_mouse != old_mou)
  6349.           if (tt_mouse)
  6350.             os2_mouseon();
  6351.           else
  6352.             os2_mouseoff();
  6353.         return(1);
  6354.     }
  6355.  
  6356.     if (y == XYM_DEBUG) {               /* MOUSE DEBUG */
  6357.         extern int MouseDebug;
  6358.         if ((x = seton(&MouseDebug)) < 0)
  6359.             return(x);
  6360.         return(1);
  6361.     }
  6362.  
  6363.     if (y == XYM_CLEAR) {               /* Reset Mouse Defaults */
  6364.         if ((x = cmcfm()) < 0) return(x);
  6365.         mousemapinit(-1,-1);
  6366.         initvik = 1;                    /* Update VIK Table */
  6367.         return 1;
  6368.     }
  6369.     if (y != XYM_BUTTON) {              /* Shouldn't happen. */
  6370.         printf("Internal parsing error\n");
  6371.         return(-9);
  6372.     }
  6373.  
  6374.     /* MOUSE EVENT ... */
  6375.  
  6376.     if ((button = cmkey(mousebuttontab,nmbtab,
  6377.                         "Button number","1",
  6378.                         xxstring)) < 0)
  6379.       return(button);
  6380.  
  6381.     if ((y =  cmkey(mousemodtab,nmmtab,
  6382.                     "Keyboard modifier","none",
  6383.                     xxstring)) < 0)
  6384.       return(y);
  6385.  
  6386.     event |= y;                         /* OR in the bits */
  6387.  
  6388.     if ((y =  cmkey(mclicktab,nmctab,"","click",xxstring)) < 0)
  6389.       return(y);
  6390.  
  6391.     /* Two bits are assigned, if neither are set then it is button one */
  6392.  
  6393.     event |= y;                 /* OR in the bit */
  6394.  
  6395.     wideresult = -1;
  6396.  
  6397.     if ((y = cmtxt("definition,\n\
  6398. or Ctrl-C to cancel this command,\n\
  6399. or Enter to restore default definition",
  6400.                    "",&s,NULL)) < 0) {
  6401.         return(y);
  6402.     }
  6403.     s = brstrip(s);
  6404.     p = s;                              /* Save this place */
  6405. /*
  6406.   If the definition included any \Kverbs, quote the backslash so the \Kverb
  6407.   will still be in the definition when the key is pressed.  We don't do this
  6408.   in zzstring(), because \Kverbs are valid only in this context and nowhere
  6409.   else.  This code copied from SET KEY, q.v. for addt'l commentary.
  6410. */
  6411.     for (x = 0, y = 0; s[x]; x++, y++) { /* Convert \K to \\K */
  6412.         if ((x > 0) &&
  6413.             (s[x] == 'K' || s[x] == 'k')
  6414.             ) {                         /* Have K */
  6415.  
  6416.             if ((x == 1 && s[x-1] == CMDQ) ||
  6417.                 (x > 1 && s[x-1] == CMDQ && s[x-2] != CMDQ)) {
  6418.                 line[y++] = CMDQ;       /* Make it \\K */
  6419.             }
  6420.             if (x > 1 && s[x-1] == '{' && s[x-2] == CMDQ) {
  6421.                 line[y-1] = CMDQ;       /* Have \{K */
  6422.                 line[y++] = '{';        /* Make it \\{K */
  6423.             }
  6424.         }
  6425.         line[y] = s[x];
  6426.     }
  6427.     line[y++] = NUL;                    /* Terminate */
  6428.     s = line + y + 1;                   /* Point to after it */
  6429.     x = LINBUFSIZ - (int) strlen(line) - 1; /* Calculate remaining space */
  6430.     if ((x < (LINBUFSIZ / 2)) ||
  6431.         (zzstring(line, &s, &x) < 0)) { /* Expand variables, etc. */
  6432.         printf("?Key definition too long\n");
  6433.         return(-9);
  6434.     }
  6435.     s = line + y + 1;                   /* Point to result. */
  6436.  
  6437. #ifndef NOKVERBS
  6438. /*
  6439.   Special case: see if the definition starts with a \Kverb.
  6440.   If it does, point to it with p, otherwise set p to NULL.
  6441. */
  6442.     p = s;
  6443.     if (*p++ == CMDQ) {
  6444.         if (*p == '{') p++;
  6445.         p = (*p == 'k' || *p == 'K') ? p + 1 : NULL;
  6446.     }
  6447. #else
  6448.     p = NULL;
  6449. #endif /* NOKVERBS */
  6450.  
  6451.     /* free the old definition if necessary */
  6452.     if (mousemap[button][event].type == macro) {
  6453.         free( mousemap[button][event].macro.string);
  6454.         mousemap[button][event].macro.string = NULL;
  6455.     }
  6456.     switch (strlen(s)) {                /* Action depends on length */
  6457.       case 0:                           /* Reset to default binding */
  6458.         mousemapinit( button, event );
  6459.         break;
  6460.       case 1:                           /* Single character */
  6461.             mousemap[button][event].type = key;
  6462.         mousemap[button][event].key.scancode = *s;
  6463.         break;
  6464.       default:                          /* Character string */
  6465. #ifndef NOKVERBS
  6466.         if (p) {
  6467.             y = xlookup(kverbs,p,nkverbs,&x); /* Look it up */
  6468.             debug(F101,"set mouse kverb lookup",0,y); /* need exact match */
  6469.             if (y > -1) {
  6470.             /* Assign the kverb to the event */
  6471.             mousemap[button][event].type = kverb;
  6472.             mousemap[button][event].kverb.id = F_KVERB | y;
  6473.             break;
  6474.             }
  6475.         }
  6476. #endif /* NOKVERBS */
  6477.  
  6478.        /* Otherwise, it's a macro, so assign the macro to the event */
  6479.        mousemap[button][event].type = macro;
  6480.        mousemap[button][event].macro.string = (MACRO) malloc(strlen(s)+1);
  6481.        if (mousemap[button][event].macro.string)
  6482.          strcpy((char *) mousemap[button][event].macro.string, s); /* safe */
  6483.         break;
  6484.     }
  6485.     initvik = 1;                        /* Update VIK Table */
  6486.     if ( (button == XYM_B3) && (mousebuttoncount() < 3) && !quiet )
  6487.     {
  6488.         printf("?Warning: this machine does not have a three button mouse.\n");
  6489.         return(0);
  6490.     }
  6491.     return(1);
  6492. }
  6493. #endif /* OS2MOUSE */
  6494. #endif /* NOLOCAL */
  6495.  
  6496. #ifndef NOXFER
  6497. int                                     /* SET SEND/RECEIVE */
  6498. setsr(xx, rmsflg) int xx; int rmsflg; {
  6499.     if (xx == XYRECV)
  6500.       ckstrncpy(line,"Parameter for inbound packets",LINBUFSIZ);
  6501.     else
  6502.       ckstrncpy(line,"Parameter for outbound packets",LINBUFSIZ);
  6503.  
  6504.     if (rmsflg) {
  6505.         if ((y = cmkey(rsrtab,nrsrtab,line,"",xxstring)) < 0) {
  6506.             if (y == -3) {
  6507.                 printf("?Remote receive parameter required\n");
  6508.                 return(-9);
  6509.             } else return(y);
  6510.         }
  6511.     } else {
  6512.         if ((y = cmkey(srtab,nsrtab,line,"",xxstring)) < 0) return(y);
  6513.     }
  6514.     switch (y) {
  6515.       case XYQCTL:                      /* CONTROL-PREFIX */
  6516.         if ((x = cmnum("ASCII value of control prefix","",10,&y,xxstring)) < 0)
  6517.           return(x);
  6518.         if ((x = cmcfm()) < 0) return(x);
  6519.         if ((y > 32 && y < 63) || (y > 95 && y < 127)) {
  6520.             if (xx == XYRECV)
  6521.               ctlq = (CHAR) y;          /* RECEIVE prefix, use with caution! */
  6522.             else
  6523.               myctlq = (CHAR) y;        /* SEND prefix, OK to change */
  6524.             return(success = 1);
  6525.         } else {
  6526.             printf("?Illegal value for prefix character\n");
  6527.             return(-9);
  6528.         }
  6529.  
  6530.       case XYEOL:
  6531.         if ((y = setcc("13",&z)) < 0)
  6532.             return(y);
  6533.         if (z > 31) {
  6534.             printf("Sorry, the legal values are 0-31\n");
  6535.             return(-9);
  6536.         }
  6537.         if (xx == XYRECV)
  6538.           eol = (CHAR) z;
  6539.         else
  6540.           seol = (CHAR) z;
  6541.         return(success = y);
  6542.  
  6543.       case XYLEN:
  6544.         y = cmnum("Maximum number of characters in a packet","90",10,&x,
  6545.                   xxstring);
  6546.         if (xx == XYRECV) {             /* Receive... */
  6547.             if ((y = setnum(&z,x,y,maxrps)) < 0)
  6548.               return(y);
  6549.             if (protocol != PROTO_K) {
  6550.                 printf("?Sorry, this command does not apply to %s protocol.\n",
  6551.                        ptab[protocol].p_name
  6552.                        );
  6553.                 printf("Use SET SEND PACKET-LENGTH for XYZMODEM\n");
  6554.                 return(-9);
  6555.             }
  6556.             if (z < 10) {
  6557.                 printf("Sorry, 10 is the minimum\n");
  6558.                 return(-9);
  6559.             }
  6560.             if (rmsflg) {
  6561.                 sstate = setgen('S', "401", ckitoa(z), "");
  6562.                 return((int) sstate);
  6563.             } else {
  6564.                 if (protocol == PROTO_K) {
  6565.                     if (z > MAXRP) z = MAXRP;
  6566.                     y = adjpkl(z,wslotr,bigrbsiz);
  6567.                     if (y != z) {
  6568.                         urpsiz = y;
  6569.                         if (!xcmdsrc)
  6570.                           if (msgflg) printf(
  6571. " Adjusting receive packet-length to %d for %d window slots\n",
  6572.                                              y, wslotr);
  6573.                     }
  6574.                     urpsiz = y;
  6575.                     ptab[protocol].rpktlen = urpsiz;
  6576.                     rpsiz =  (y > 94) ? 94 : y;
  6577.                 } else {
  6578. #ifdef CK_XYZ
  6579.                     if ((protocol == PROTO_X || protocol == PROTO_XC) &&
  6580.                          z != 128 && z != 1024) {
  6581.                         printf("Sorry, bad packet length for XMODEM.\n");
  6582.                         printf("Please use 128 or 1024.\n");
  6583.                         return(-9);
  6584.                     }
  6585. #endif /* CK_XYZ */
  6586.                     urpsiz = rpsiz = z;
  6587.                 }
  6588.             }
  6589.         } else {                        /* Send... */
  6590.             if ((y = setnum(&z,x,y,maxsps)) < 0)
  6591.               return(y);
  6592.             if (z < 10) {
  6593.                 printf("Sorry, 10 is the minimum\n");
  6594.                 return(-9);
  6595.             }
  6596.             if (protocol == PROTO_K) {
  6597.                 if (z > MAXSP) z = MAXSP;
  6598.                 spsiz = z;              /* Set it */
  6599.                 y = adjpkl(spsiz,wslotr,bigsbsiz);
  6600.                 if (y != spsiz && !xcmdsrc)
  6601.                   if (msgflg)
  6602.                     printf("Adjusting packet size to %d for %d window slots\n",
  6603.                            y,wslotr);
  6604.             } else
  6605.               y = z;
  6606. #ifdef CK_XYZ
  6607.             if ((protocol == PROTO_X || protocol == PROTO_XC) &&
  6608.                  z != 128 && z != 1024) {
  6609.                 printf("Sorry, bad packet length for XMODEM.\n");
  6610.                 printf("Please use 128 or 1024.\n");
  6611.                 return(-9);
  6612.             }
  6613. #endif /* CK_XYZ */
  6614.             spsiz = spmax = spsizr = y; /* Set it and flag that it was set */
  6615.             spsizf = 1;                 /* to allow overriding Send-Init. */
  6616.             ptab[protocol].spktflg = spsizf;
  6617.             ptab[protocol].spktlen = spsiz;
  6618.         }
  6619.         if (pflag && protocol == PROTO_K && !xcmdsrc) {
  6620.             if (z > 94 && !reliable && msgflg) {
  6621.                 /* printf("Extended-length packets requested.\n"); */
  6622.                 if (bctr < 2 && z > 200) printf("\
  6623. Remember to SET BLOCK 2 or 3 for long packets.\n");
  6624.             }
  6625.             if (speed <= 0L) speed = ttgspd();
  6626. #ifdef COMMENT
  6627. /*
  6628.   Kermit does this now itself.
  6629. */
  6630.             if (speed <= 0L && z > 200 && msgflg) {
  6631.                 printf("\
  6632. Make sure your timeout interval is long enough for %d-byte packets.\n",z);
  6633.             }
  6634. #endif /* COMMENT */
  6635.         }
  6636.         return(success = y);
  6637.  
  6638.       case XYMARK:
  6639. #ifdef DOOMSDAY
  6640. /*
  6641.   Printable start-of-packet works for UNIX and VMS only!
  6642. */
  6643.         x_ifnum = 1;
  6644.         y = cmnum("Code for packet-start character","1",10,&x,xxstring);
  6645.         x_ifnum = 0;
  6646.         if ((y = setnum(&z,x,y,126)) < 0) return(y);
  6647. #else
  6648.         if ((y = setcc("1",&z)) < 0)
  6649.             return(y);
  6650. #endif /* DOOMSDAY */
  6651.         if (xx == XYRECV)
  6652.           stchr = (CHAR) z;
  6653.         else {
  6654.             mystch = (CHAR) z;
  6655. #ifdef IKS_OPTION
  6656.             /* If IKS negotiation in use   */
  6657.             if (TELOPT_U(TELOPT_KERMIT) || TELOPT_ME(TELOPT_KERMIT))
  6658.               tn_siks(KERMIT_SOP);      /* Report change to other side */
  6659. #endif /* IKS_OPTION */
  6660.         }
  6661.         return(success = y);
  6662.  
  6663.       case XYNPAD:                      /* PADDING */
  6664.         y = cmnum("How many padding characters for inbound packets","0",10,&x,
  6665.                   xxstring);
  6666.         if ((y = setnum(&z,x,y,94)) < 0) return(y);
  6667.         if (xx == XYRECV)
  6668.           mypadn = (CHAR) z;
  6669.         else
  6670.           npad = (CHAR) z;
  6671.         return(success = y);
  6672.  
  6673.       case XYPADC:                      /* PAD-CHARACTER */
  6674.         if ((y = setcc("0",&z)) < 0) return(y);
  6675.         if (xx == XYRECV) mypadc = z; else padch = z;
  6676.         return(success = y);
  6677.  
  6678.       case XYTIMO:                      /* TIMEOUT */
  6679.         if (xx == XYRECV) {
  6680.             y = cmnum("Packet timeout interval",ckitoa(URTIME),10,&x,xxstring);
  6681.             if ((y = setnum(&z,x,y,94)) < 0) return(y);
  6682.  
  6683.             if (rmsflg) {               /* REMOTE SET RECEIVE TIMEOUT */
  6684.                 sstate = setgen('S', "402", ckitoa(z), "");
  6685.                 return((int) sstate);
  6686.             } else {                    /* SET RECEIVE TIMEOUT */
  6687.                 pkttim = z;             /*   Value to put in my negotiation */
  6688.             }                           /*   packet for other Kermit to use */
  6689.  
  6690.         } else {                        /* SET SEND TIMEOUT */
  6691. #ifdef CK_TIMERS
  6692.             extern int rttflg, mintime, maxtime;
  6693.             int tmin = 0, tmax = 0;
  6694. #endif /* CK_TIMERS */
  6695.             y = cmnum("Packet timeout interval",ckitoa(DMYTIM),10,&x,xxstring);
  6696.             if (y == -3) {              /* They cancelled a previous */
  6697.                 x = DMYTIM;             /* SET SEND command, so restore */
  6698.                 timef = 0;              /* and turn off the override flag */
  6699.                 y = cmcfm();
  6700.             }
  6701. #ifdef CK_TIMERS
  6702.             if (y < 0) return(y);
  6703.             if (x < 0) {
  6704.                 printf("?Out of range - %d\n",x);
  6705.                 return(-9);
  6706.             }
  6707.             if ((z = cmkey(timotab,2,"","dynamic",xxstring)) < 0) return(z);
  6708.             if (z) {
  6709.                 if ((y = cmnum("Minimum timeout to allow",
  6710.                                "1",10,&tmin,xxstring)) < 0)
  6711.                   return(y);
  6712.                 if (tmin < 1) {
  6713.                     printf("?Out of range - %d\n",tmin);
  6714.                     return(-9);
  6715.                 }
  6716.                 if ((y = cmnum("Maximum timeout to allow",
  6717.                                "0",10,&tmax,xxstring)) < 0)
  6718.                   return(y);
  6719.                 /* 0 means let Kermit choose, < 0 means no maximum */
  6720.             }
  6721.             if ((y = cmcfm()) < 0)
  6722.               return(y);
  6723.             rttflg = z;                 /* Round-trip timer flag */
  6724.             z = x;
  6725. #else
  6726.             if ((y = setnum(&z,x,y,94)) < 0)
  6727.               return(y);
  6728. #endif /* CK_TIMERS */
  6729.             timef = 1;                  /* Turn on the override flag */
  6730.             timint = rtimo = z;         /* Override value for me to use */
  6731. #ifdef CK_TIMERS
  6732.             if (rttflg) {               /* Lower and upper bounds */
  6733.                 mintime = tmin;
  6734.                 maxtime = tmax;
  6735.             }
  6736. #endif /* CK_TIMERS */
  6737.         }
  6738.         return(success = 1);
  6739.  
  6740.       case XYFPATH:                     /* PATHNAMES */
  6741.         if (xx == XYRECV) {
  6742.             y = cmkey(rpathtab,nrpathtab,"","auto",xxstring);
  6743.         } else {
  6744.             y = cmkey(pathtab,npathtab,"","off",xxstring);
  6745.         }
  6746.         if (y < 0) return(y);
  6747.  
  6748.         if ((x = cmcfm()) < 0) return(x);
  6749.         if (xx == XYRECV) {             /* SET RECEIVE PATHNAMES */
  6750.             fnrpath = y;
  6751.             ptab[protocol].fnrp = fnrpath;
  6752.         } else {                        /* SET SEND PATHNAMES */
  6753.             fnspath = y;
  6754.             ptab[protocol].fnsp = fnspath;
  6755.         }
  6756.         return(success = 1);            /* Note: 0 = ON, 1 = OFF */
  6757.         /* In other words, ON = leave pathnames ON, OFF = take them off. */
  6758.  
  6759.       case XYPAUS:                      /* SET SEND/RECEIVE PAUSE */
  6760.         y = cmnum("Milliseconds to pause between packets","0",10,&x,xxstring);
  6761.         if ((y = setnum(&z,x,y,15000)) < 0)
  6762.           return(y);
  6763.         pktpaus = z;
  6764.         return(success = 1);
  6765.  
  6766. #ifdef CKXXCHAR                         /* SET SEND/RECEIVE IGNORE/DOUBLE */
  6767.       case XYIGN:
  6768.       case XYDBL: {
  6769.           int i, zz;
  6770.           short *p;
  6771.           extern short dblt[];
  6772.           extern int dblflag, ignflag;
  6773.  
  6774.           /* Make space for a temporary copy of the ignore/double table */
  6775.  
  6776.           zz = y;
  6777. #ifdef COMMENT
  6778.           if (zz == XYIGN && xx == XYSEND) {
  6779.               blah blah who cares
  6780.           }
  6781.           if (zz == XYDBL && xx == XYRECV) {
  6782.               blah blah
  6783.           }
  6784. #endif /* COMMENT */
  6785.           p = (short *)malloc(256 * sizeof(short));
  6786.           if (!p) {
  6787.               printf("?Internal error - malloc failure\n");
  6788.               return(-9);
  6789.           }
  6790.           for (i = 0; i < 256; i++) p[i] = dblt[i]; /* Copy current table */
  6791.  
  6792.           while (1) {                   /* Collect a list of numbers */
  6793. #ifndef NOSPL
  6794.               x_ifnum = 1;              /* Turn off complaints from eval() */
  6795. #endif /* NOSPL */
  6796.               if ((x = cmnum(zz == XYDBL ?
  6797.                              "Character to double" :
  6798.                              "Character to ignore",
  6799.                              "",10,&y,xxstring
  6800.                              )) < 0) {
  6801. #ifndef NOSPL
  6802.                   x_ifnum = 0;
  6803. #endif /* NOSPL */
  6804.                   if (x == -3)          /* Done */
  6805.                     break;
  6806.                   if (x == -2) {
  6807.                       if (p) { free(p); p = NULL; }
  6808.                       debug(F110,"SET S/R DOUBLE/IGNORE atmbuf",atmbuf,0);
  6809.                       if (!ckstrcmp(atmbuf,"none",4,0) ||
  6810.                           !ckstrcmp(atmbuf,"non",3,0) ||
  6811.                           !ckstrcmp(atmbuf,"no",2,0) ||
  6812.                           !ckstrcmp(atmbuf,"n",1,0)) {
  6813.                           if ((x = cmcfm()) < 0) /* Get confirmation */
  6814.                             return(x);
  6815.                           for (y = 0; y < 256; y++)
  6816.                             dblt[y] &= (zz == XYDBL) ? 1 : 2;
  6817.                           if (zz == XYDBL) dblflag = 0;
  6818.                           if (zz == XYIGN) ignflag = 0;
  6819.                           return(success = 1);
  6820.                       } else {
  6821.                           printf(
  6822.                             "?Please specify a number or the word NONE\n");
  6823.                           return(-9);
  6824.                       }
  6825.                   } else {
  6826.                       free(p);
  6827.                       p = NULL;
  6828.                       return(x);
  6829.                   }
  6830.               }
  6831. #ifndef NOSPL
  6832.               x_ifnum = 0;
  6833. #endif /* NOSPL */
  6834.               if (y < 0 || y > 255) {
  6835.                   printf("?Please enter a character code in range 0-255\n");
  6836.                   free(p);
  6837.                   p = NULL;
  6838.                   return(-9);
  6839.               }
  6840.               p[y] |= (zz == XYDBL) ? 2 : 1;
  6841.               if (zz == XYDBL) dblflag = 1;
  6842.               if (zz == XYIGN) ignflag = 1;
  6843.           } /* End of while loop */
  6844.  
  6845.           if ((x = cmcfm()) < 0) return(x);
  6846. /*
  6847.   Get here only if they have made no mistakes.  Copy temporary table back to
  6848.   permanent one, then free temporary table and return successfully.
  6849. */
  6850.           if (p) {
  6851.               for (i = 0; i < 256; i++) dblt[i] = p[i];
  6852.               free(p);
  6853.               p = NULL;
  6854.           }
  6855.           return(success = 1);
  6856.       }
  6857. #endif /* CKXXCHAR */
  6858.  
  6859. #ifdef PIPESEND
  6860.       case XYFLTR: {                    /* SET { SEND, RECEIVE } FILTER */
  6861.           if ((y = cmtxt((xx == XYSEND) ?
  6862.                 "Filter program for sending files -\n\
  6863.  use \\v(filename) to substitute filename" :
  6864.                 "Filter program for receiving files -\n\
  6865.  use \\v(filename) to substitute filename",
  6866.                          "",&s,NULL)) < 0)
  6867.             return(y);
  6868.           if (!*s) {                    /* Removing a filter... */
  6869.               if (xx == XYSEND && sndfilter) {
  6870.                   makestr(&g_sfilter,NULL);
  6871.                   makestr(&sndfilter,NULL);
  6872.               } else if (rcvfilter) {
  6873.                   makestr(&g_rfilter,NULL);
  6874.                   makestr(&rcvfilter,NULL);
  6875.               }
  6876.               return(success = 1);
  6877.           }                             /* Adding a filter... */
  6878.           s = brstrip(s);               /* Strip any braces */
  6879.           y = strlen(s);
  6880.           if (xx == XYSEND) {           /* For SEND filter... */
  6881.               for (x = 0; x < y; x++) { /* make sure they included "\v(...)" */
  6882.                   if (s[x] != '\\') continue;
  6883.                   if (s[x+1] == 'v') break;
  6884.               }
  6885.               if (x == y) {
  6886.                   printf(
  6887.               "?Filter must contain a replacement variable for filename.\n"
  6888.                          );
  6889.                   return(-9);
  6890.               }
  6891.           }
  6892.           if (xx == XYSEND) {
  6893.               makestr(&sndfilter,s);
  6894.               makestr(&g_sfilter,s);
  6895.           } else {
  6896.               makestr(&rcvfilter,s);
  6897.               makestr(&g_rfilter,s);
  6898.           }
  6899.           return(success = 1);
  6900.       }
  6901. #endif /* PIPESEND */
  6902.  
  6903.       case XYINIL:
  6904.         y = cmnum("Max length for protocol init string","-1",10,&x,xxstring);
  6905.         if ((y = setnum(&z,x,y,-1)) < 0)
  6906.           return(y);
  6907.         if (xx == XYSEND)
  6908.           sprmlen = z;
  6909.         else
  6910.           rprmlen = z;
  6911.         return(success = 1);
  6912.  
  6913.       case 993: {
  6914.           extern int sendipkts;
  6915.           if (xx == XYSEND) {
  6916.               if ((x = seton(&sendipkts)) < 0)
  6917.                 return(x);
  6918.           }
  6919.           return(1);
  6920.       }
  6921. #ifdef CK_PERMS
  6922.       case 994:
  6923.     switch(xx) {
  6924.       case XYSEND:
  6925.         if ((x = seton(&atlpro)) < 0) return(x);
  6926.         atgpro = atlpro;
  6927.         return(1);
  6928.       case XYRECV:
  6929.         if ((x = seton(&atlpri)) < 0) return(x);
  6930.         atgpri = atlpri;
  6931.         return(1);
  6932.       default:
  6933.         return(-2);
  6934.     }
  6935. #endif /* CK_PERMS */
  6936.  
  6937. #ifndef NOCSETS
  6938.       case XYCSET: {                    /* CHARACTER-SET-SELECTION */
  6939.           extern struct keytab xfrmtab[];
  6940.           extern int r_cset, s_cset;
  6941.           if ((y = cmkey(xfrmtab,2,"","automatic",xxstring)) < 0)
  6942.             return(y);
  6943.           if ((x = cmcfm()) < 0)
  6944.             return(x);
  6945.           if (xx == XYSEND)
  6946.             s_cset = y;
  6947.           else
  6948.             r_cset = y;
  6949.           return(success = 1);
  6950.       }
  6951. #endif /* NOCSETS */
  6952.  
  6953.       case XYBUP:
  6954.         if ((y = cmkey(onoff,2,"","on",xxstring)) < 0)
  6955.           return(y);
  6956.         if ((x = cmcfm()) < 0) return(x);
  6957.         if (xx == XYSEND) {
  6958.             extern int skipbup;
  6959.             skipbup = (y == 0) ? 1 : 0;
  6960.             return(success = 1);
  6961.         } else {
  6962.             printf(
  6963. "?Please use SET FILE COLLISION to choose the desired action\n");
  6964.             return(-9);
  6965.         }
  6966.  
  6967.       case XYMOVE:
  6968. #ifdef COMMENT
  6969.         y = cmdir("Directory to move file(s) to after successful transfer",
  6970.                   "",&s,xxstring);
  6971. #else
  6972.         y = cmtxt("Directory to move file(s) to after successful transfer",
  6973.           "",&s,xxstring);
  6974. #endif /* COMMENT */
  6975.  
  6976.         if (y < 0 && y != -3)
  6977.           return(y);
  6978.         ckstrncpy(line,s,LINBUFSIZ);
  6979.         s = brstrip(line);
  6980.  
  6981. #ifdef COMMENT
  6982.     /* Only needed for cmdir() */
  6983.         if ((x = cmcfm()) < 0)
  6984.           return(x);
  6985. #endif /* COMMENT */
  6986.     
  6987.     /* Check directory existence if absolute */
  6988.     /* THIS MEANS IT CAN'T INCLUDE ANY DEFERRED VARIABLES! */
  6989.     if (s) if (*s) {
  6990.         if (isabsolute(s) && !isdir(s)) {
  6991.         printf("?Directory does not exist - %s\n",s);
  6992.         return(-9);
  6993.         }
  6994.     }
  6995.         if (xx == XYSEND) {
  6996.             if (*s) {
  6997. #ifdef COMMENT
  6998.         /* Allow it to be relative */
  6999.                 zfnqfp(s,LINBUFSIZ,line);
  7000. #endif /* COMMENT */
  7001.                 makestr(&snd_move,line);
  7002.                 makestr(&g_snd_move,line);
  7003.             } else {
  7004.                 makestr(&snd_move,NULL);
  7005.                 makestr(&g_snd_move,NULL);
  7006.             }
  7007.         } else {
  7008.             if (*s) {
  7009. #ifdef COMMENT
  7010.         /* Allow it to be relative */
  7011.                 zfnqfp(s,LINBUFSIZ,line);
  7012. #endif /* COMMENT */
  7013.                 makestr(&rcv_move,line);
  7014.                 makestr(&g_rcv_move,line);
  7015.             } else {
  7016.                 makestr(&rcv_move,NULL);
  7017.                 makestr(&g_rcv_move,NULL);
  7018.             }
  7019.         }
  7020.         return(success = 1);
  7021.  
  7022.       case XYRENAME:
  7023.         y = cmtxt("Template to rename file(s) to after successful transfer",
  7024.                   "",&s,NULL);        /* NOTE: no xxstring */
  7025.         if (y < 0 && y != -3)        /* Evaluation is deferred */
  7026.           return(y);
  7027.         ckstrncpy(line,s,LINBUFSIZ);
  7028.         s = brstrip(line);
  7029.         if ((x = cmcfm()) < 0)
  7030.           return(x);
  7031.         if (xx == XYSEND) {
  7032.             if (*s) {
  7033.                 makestr(&snd_rename,s);
  7034.                 makestr(&g_snd_rename,s);
  7035.             } else {
  7036.                 makestr(&snd_rename,NULL);
  7037.                 makestr(&g_snd_rename,NULL);
  7038.             }
  7039.         } else {
  7040.             if (*s) {
  7041.                 makestr(&rcv_rename,s);
  7042.                 makestr(&g_rcv_rename,s);
  7043.             } else {
  7044.                 makestr(&rcv_rename,NULL);
  7045.                 makestr(&g_rcv_rename,NULL);
  7046.             }
  7047.         }
  7048.         return(success = 1);
  7049.  
  7050. #ifdef VMS
  7051.       case 887:                /* VERSION-NUMBERS */
  7052.         if (xx == XYSEND) {
  7053.             extern int vmssversions;
  7054.             return(seton(&vmssversions));
  7055.         } else {
  7056.             extern int vmsrversions;
  7057.             return(seton(&vmsrversions));
  7058.         }
  7059. #endif /* VMS */
  7060.  
  7061.       default:
  7062.         return(-2);
  7063.     }                                   /* End of SET SEND/RECEIVE... */
  7064. }
  7065. #endif /* NOXFER */
  7066.  
  7067. #ifndef NOXMIT
  7068. int
  7069. setxmit() {
  7070.     if ((y = cmkey(xmitab,nxmit,"","",xxstring)) < 0) return(y);
  7071.     switch (y) {
  7072.       case XMITE:                       /* EOF */
  7073.         y = cmtxt("Characters to send at end of file,\n\
  7074.  Use backslash codes for control characters","",&s,xxstring);
  7075.         if (y < 0) return(y);
  7076.         if ((int)strlen(s) > XMBUFL) {
  7077.             printf("?Too many characters, %d maximum\n",XMBUFL);
  7078.             return(-2);
  7079.         }
  7080.         ckstrncpy(xmitbuf,s,XMBUFL);
  7081.         return(success = 1);
  7082.  
  7083.       case XMITF:                       /* Fill */
  7084.         y = cmnum("Numeric code for blank-line fill character","0",10,&x,
  7085.                   xxstring);
  7086.         if ((y = setnum(&z,x,y,127)) < 0) return(y);
  7087.         xmitf = z;
  7088.         return(success = 1);
  7089.       case XMITL:                       /* Linefeed */
  7090.         return(seton(&xmitl));
  7091.       case XMITS:                       /* Locking-Shift */
  7092.         return(seton(&xmits));
  7093.       case XMITP:                       /* Prompt */
  7094.         y = cmnum("Numeric code for host's prompt character, 0 for none",
  7095.                   "10",10,&x,xxstring);
  7096.         if ((y = setnum(&z,x,y,127)) < 0) return(y);
  7097.         xmitp = z;
  7098.         return(success = 1);
  7099.       case XMITX:                       /* Echo */
  7100.         return(seton(&xmitx));
  7101.       case XMITW:                       /* Pause */
  7102.         y = cmnum("Number of milliseconds to pause between binary characters\n\
  7103. or text lines during transmission","0",10,&x,xxstring);
  7104.         if ((y = setnum(&z,x,y,1000)) < 0) return(y);
  7105.         xmitw = z;
  7106.         return(success = 1);
  7107.       case XMITT:                       /* Timeout */
  7108.         y = cmnum("Seconds to wait for each character to echo",
  7109.                   "1",10,&x,xxstring);
  7110.         if ((y = setnum(&z,x,y,1000)) < 0) return(y);
  7111.         xmitt = z;
  7112.         return(success = 1);
  7113.       default:
  7114.         return(-2);
  7115.     }
  7116. }
  7117. #endif /* NOXMIT */
  7118.  
  7119. #ifndef NOXFER
  7120. /*  D O R M T  --  Do a remote command  */
  7121.  
  7122. VOID
  7123. rmsg() {
  7124.     if (pflag && !quiet && fdispla != XYFD_N)
  7125.       printf(
  7126. #ifdef CK_NEED_SIG
  7127.        " Type your escape character, %s, followed by X or E to cancel.\n",
  7128.        dbchr(escape)
  7129. #else
  7130.        " Press the X or E key to cancel.\n"
  7131. #endif /* CK_NEED_SIG */
  7132.       );
  7133. }
  7134.  
  7135. static int xzcmd = 0;                   /* Global copy of REMOTE cmd index */
  7136.  
  7137. /*  R E M C F M  --  Confirm a REMOTE command  */
  7138. /*
  7139.   Like cmcfm(), but allows for a redirection indicator on the end,
  7140.   like "> filename" or "| command".  Returns what cmcfm() would have
  7141.   returned: -1 if reparse needed, etc etc blah blah.  On success,
  7142.   returns 1 with:
  7143.  
  7144.     char * remdest containing the name of the file or command.
  7145.     int remfile set to 1 if there is to be any redirection.
  7146.     int remappd set to 1 if output file is to be appended to.
  7147.     int rempipe set to 1 if remdest is a command, 0 if it is a file.
  7148. */
  7149. static int
  7150. remcfm() {
  7151.     int x;
  7152.     char *s;
  7153.     char c;
  7154.  
  7155.     remfile = 0;
  7156.     rempipe = 0;
  7157.     remappd = 0;
  7158.  
  7159.     if ((x = cmtxt(
  7160.              "> filename, | command,\n\
  7161. or type carriage return to confirm the command",
  7162.                    "",&s,xxstring)) < 0)
  7163.       return(x);
  7164.     if (remdest) {
  7165.         free(remdest);
  7166.         remdest = NULL;
  7167.     }
  7168.     debug(F101,"remcfm local","",local);
  7169.     debug(F110,"remcfm s",s,0);
  7170.     debug(F101,"remcfm cmd","",xzcmd);
  7171.  
  7172.     if (!*s) {                          /* No redirection indicator */
  7173.         if (!local &&
  7174.             (xzcmd == XZDIR || xzcmd == XZTYP ||
  7175.              xzcmd == XZXIT || xzcmd == XZSPA ||
  7176.              xzcmd == XZHLP || xzcmd == XZPWD ||
  7177.              xzcmd == XZLGI || xzcmd == XZLGO ||
  7178.              xzcmd == XZWHO || xzcmd == XZHOS)) {
  7179.             printf("?\"%s\" has no effect in remote mode\n",cmdbuf);
  7180.             return(-9);
  7181.         } else
  7182.           return(1);
  7183.     }
  7184.     c = *s;                             /* We have something */
  7185.     if (c != '>' && c != '|') {         /* Is it > or | ? */
  7186.         printf("?Not confirmed\n");     /* No */
  7187.         return(-9);
  7188.     }
  7189.     s++;                                /* See what follows */
  7190.     if (c == '>' && *s == '>') {        /* Allow for ">>" too */
  7191.         s++;
  7192.         remappd = 1;                    /* Append to output file */
  7193.     }
  7194.     while (*s == SP || *s == HT) s++;   /* Strip intervening whitespace */
  7195.     if (!*s) {
  7196.         printf("?%s missing\n", c == '>' ? "Filename" : "Command");
  7197.         return(-9);
  7198.     }
  7199.     if (c == '>' && zchko(s) < 0) {     /* Check accessibility */
  7200.         printf("?Access denied - %s\n", s);
  7201.         return(-9);
  7202.     }
  7203.     remfile = 1;                        /* Set global results */
  7204.     rempipe = (c == '|');
  7205.     if (rempipe
  7206. #ifndef NOPUSH
  7207.         && nopush
  7208. #endif /* NOPUSH */
  7209.         ) {
  7210.         printf("?Sorry, access to external commands is disabled.\n");
  7211.         return(-9);
  7212.     }
  7213.     makestr(&remdest,s);
  7214. #ifndef NODEBUG
  7215.     if (deblog) {
  7216.         debug(F101,"remcfm remfile","",remfile);
  7217.         debug(F101,"remcfm remappd","",remappd);
  7218.         debug(F101,"remcfm rempipe","",rempipe);
  7219.         debug(F110,"remcfm remdest",remdest, 0);
  7220.     }
  7221. #endif /* NODEBUG */
  7222.     return(1);
  7223. }
  7224.  
  7225. /*  R E M T X T  --  Like remcfm()...  */
  7226. /*
  7227.    ... but for REMOTE commands that end with cmtxt().
  7228.    Here we must decipher braces to discover whether the trailing
  7229.    redirection indicator is intended for local use, or to be sent out
  7230.    to the server, as in:
  7231.  
  7232.      remote host blah blah > file                 This end
  7233.      remote host { blah blah } > file             This end
  7234.      remote host { blah blah > file }             That end
  7235.      remote host { blah blah > file } > file      Both ends
  7236.  
  7237.    Pipes too:
  7238.  
  7239.      remote host blah blah | cmd                  This end
  7240.      remote host { blah blah } | cmd              This end
  7241.      remote host { blah blah | cmd }              That end
  7242.      remote host { blah blah | cmd } | cmd        Both ends
  7243.  
  7244.    Or both:
  7245.  
  7246.      remote host blah blah | cmd > file           This end, etc etc...
  7247.  
  7248.    Note: this really only makes sense for REMOTE HOST, but why be picky?
  7249.    Call after calling cmtxt(), with pointer to string that cmtxt() parsed,
  7250.    as in "remtxt(&s);".
  7251.  
  7252.    Returns:
  7253.     1 on success with braces & redirection things removed & pointer updated,
  7254.    -9 on failure (bad indirection), after printing error message.
  7255. */
  7256. int
  7257. remtxt(p) char ** p; {
  7258.     int i, x, bpos, ppos;
  7259.     char c, *s, *q;
  7260.  
  7261.     remfile = 0;                        /* Initialize global results */
  7262.     rempipe = 0;
  7263.     remappd = 0;
  7264.     if (remdest) {
  7265.         free(remdest);
  7266.         remdest = NULL;
  7267.     }
  7268.     s = *p;
  7269.     if (!s)                             /* No redirection indicator */
  7270.       s = "";
  7271.     if (!*s) {                          /* Ditto */
  7272.         if (!local &&
  7273.             (xzcmd == XZDIR || xzcmd == XZTYP ||
  7274.              xzcmd == XZXIT || xzcmd == XZSPA ||
  7275.              xzcmd == XZHLP || xzcmd == XZPWD ||
  7276.              xzcmd == XZLGI || xzcmd == XZLGO ||
  7277.              xzcmd == XZWHO || xzcmd == XZHOS)) {
  7278.             printf("?\"%s\" has no effect in remote mode\n",cmdbuf);
  7279.             if (hints) {
  7280.                 printf("Hint: Try again with an output redirector.\n");
  7281.             }
  7282.             return(-9);
  7283.         } else
  7284.           return(1);
  7285.     }
  7286.     bpos = -1;                          /* Position of > (bracket) */
  7287.     ppos = -1;                          /* Position of | (pipe) */
  7288.     x = strlen(s);                      /* Length of cmtxt() string */
  7289.  
  7290.     for (i = x-1; i >= 0; i--) {        /* Search right to left. */
  7291.         c = s[i];
  7292.         if (c == '}')                   /* Break on first right brace */
  7293.           break;                        /* Don't look at contents of braces */
  7294.         else if (c == '>')              /* Record position of > */
  7295.           bpos = i;
  7296.         else if (c == '|')              /* and of | */
  7297.           ppos = i;
  7298.     }
  7299.     if (bpos < 0 && ppos < 0) {         /* No redirectors. */
  7300.         if (!local &&
  7301.             (xzcmd == XZDIR || xzcmd == XZTYP ||
  7302.              xzcmd == XZXIT || xzcmd == XZSPA ||
  7303.              xzcmd == XZHLP || xzcmd == XZPWD ||
  7304.              xzcmd == XZLGI || xzcmd == XZLGO ||
  7305.              xzcmd == XZWHO || xzcmd == XZHOS)) {
  7306.             printf("?\"%s\" has no effect in remote mode\n",cmdbuf);
  7307.             if (hints) {
  7308.                 printf("Hint: Try again with an output redirector.\n");
  7309.             }
  7310.             return(-9);
  7311.         }
  7312.         s = brstrip(s);                 /* Remove outer braces if any. */
  7313.         *p = s;                         /* Point to result */
  7314.         return(1);                      /* and return. */
  7315.     }
  7316.     remfile = 1;                        /* It's | or > */
  7317.     i = -1;                             /* Get leftmost symbol */
  7318.     if (bpos > -1)                      /* Bracket */
  7319.       i = bpos;
  7320.     if (ppos > -1 && (ppos < bpos || bpos < 0)) { /* or pipe */
  7321.         i = ppos;
  7322.         rempipe = 1;
  7323.     }
  7324.     if (rempipe
  7325. #ifndef NOPUSH
  7326.         && nopush
  7327. #endif /* NOPUSH */
  7328.         ) {
  7329.         printf("?Sorry, access to external commands is disabled.\n");
  7330.         return(-9);
  7331.     }
  7332.     c = s[i];                           /* Copy of symbol */
  7333.  
  7334.     if (c == '>' && s[i+1] == '>')      /* ">>" for append? */
  7335.       remappd = 1;                     /* It's not just a flag it's a number */
  7336.  
  7337.     q = s + i + 1 + remappd;            /* Point past symbol in string */
  7338.     while (*q == SP || *q == HT) q++;   /* and any intervening whitespace */
  7339.     if (!*q) {
  7340.         printf("?%s missing\n", c == '>' ? "Filename" : "Command");
  7341.         return(-9);
  7342.     }
  7343.     if (c == '>' && zchko(q) < 0) {     /* (Doesn't work for | cmd > file) */
  7344.         printf("?Access denied - %s\n", q);
  7345.         return(-9);
  7346.     }
  7347.     makestr(&remdest,q);                /* Create the destination string */
  7348.     q = s + i - 1;                      /* Point before symbol */
  7349.     while (q > s && (*q == SP || *q == HT)) /* Strip trailing whitespace */
  7350.       q--;
  7351.     *(q+1) = NUL;                       /* Terminate the string. */
  7352.     s = brstrip(s);                     /* Remove any braces */
  7353.     *p = s;                             /* Set return value */
  7354.  
  7355. #ifndef NODEBUG
  7356.     if (deblog) {
  7357.         debug(F101,"remtxt remfile","",remfile);
  7358.         debug(F101,"remtxt remappd","",remappd);
  7359.         debug(F101,"remtxt rempipe","",rempipe);
  7360.         debug(F110,"remtxt remdest",remdest, 0);
  7361.         debug(F110,"remtxt command",s,0);
  7362.     }
  7363. #endif /* NODEBUG */
  7364.  
  7365.     return(1);
  7366. }
  7367.  
  7368. int
  7369. plogin(xx) int xx; {
  7370.     char *p1 = NULL, *p2 = NULL, *p3 = NULL;
  7371.     int psaved = 0, rc = 0;
  7372. #ifdef CK_RECALL
  7373.     extern int on_recall;               /* around Password prompting */
  7374. #endif /* CK_RECALL */
  7375.     debug(F101,"plogin local","",local);
  7376.  
  7377.     if (!local || (network && ttchk() < 0)) {
  7378.         printf("?No connection\n");
  7379.         return(-9);
  7380.     }
  7381.     if ((x = cmfld("User ID","",&s,xxstring)) < 0) { /* Get User ID */
  7382.         if (x != -3) return(x);
  7383.     }
  7384.     y = strlen(s);
  7385.     if (y > 0) {
  7386.         if ((p1 = malloc(y + 1)) == NULL) {
  7387.             printf("?Internal error: malloc\n");
  7388.             rc = -9;
  7389.             goto XZXLGI;
  7390.         } else
  7391.           strcpy(p1,s);                 /* safe */
  7392.         if ((rc = cmfld("Password","",&s,xxstring)) < 0)
  7393.           if (rc != -3) goto XZXLGI;
  7394.         y = strlen(s);
  7395.         if (y > 0) {
  7396.             if ((p2 = malloc(y + 1)) == NULL) {
  7397.                 printf("?Internal error: malloc\n");
  7398.                 rc = -9;
  7399.                 goto XZXLGI;
  7400.             } else
  7401.               strcpy(p2,s);             /* safe */
  7402.             if ((rc = cmfld("Account","",&s,xxstring)) < 0)
  7403.               if (rc != -3) goto XZXLGI;
  7404.             y = strlen(s);
  7405.             if (y > 0) {
  7406.                 if ((p3 = malloc(y + 1)) == NULL) {
  7407.                     printf("?Internal error: malloc\n");
  7408.                     rc = -9;
  7409.                     goto XZXLGI;
  7410.                 } else
  7411.                   strcpy(p3,s);         /* safe */
  7412.             }
  7413.         }
  7414.     }
  7415.     if ((rc = remtxt(&s)) < 0)          /* Confirm & handle redirectors */
  7416.       goto XZXLGI;
  7417.  
  7418.     if (!p1) {                          /* No Userid specified... */
  7419.         debok = 0;                      /* Don't log this */
  7420.         /* Prompt for username, password, and account */
  7421. #ifdef CK_RECALL
  7422.         on_recall = 0;
  7423. #endif /* CK_RECALL */
  7424.         cmsavp(psave,PROMPTL);          /* Save old prompt */
  7425.         psaved = 1;
  7426.         debug(F110,"REMOTE LOGIN saved",psave,0);
  7427.  
  7428.         cmsetp("Username: ");           /* Make new prompt */
  7429.         concb((char)escape);            /* Put console in cbreak mode */
  7430.         cmini(1);
  7431.         prompt(xxstring);
  7432.         rc = -9;
  7433.         for (x = -1; x < 0; ) {         /* Prompt till they answer */
  7434.             cmres();                    /* Reset the parser */
  7435.             x = cmtxt("","",&s,NULL);   /* Get a literal line of text */
  7436.         }
  7437.         y = strlen(s);
  7438.         if (y < 1) {
  7439.             printf("?Canceled\n");
  7440.             goto XZXLGI;
  7441.         }
  7442.         if ((p1 = malloc(y + 1)) == NULL) {
  7443.             printf("?Internal error: malloc\n");
  7444.             goto XZXLGI;
  7445.         } else
  7446.           strcpy(p1,s);                 /* safe */
  7447.  
  7448.         cmsetp("Password: ");           /* Make new prompt */
  7449.         concb((char)escape);            /* Put console in cbreak mode */
  7450.         cmini(0);                       /* No echo */
  7451.         prompt(xxstring);
  7452.         debok = 0;
  7453.         for (x = -1; x < 0 && x != -3; ) { /* Get answer */
  7454.             cmres();                    /* Reset the parser */
  7455.             x = cmtxt("","",&s,NULL);   /* Get literal line of text */
  7456.         }
  7457.         if ((p2 = malloc((int)strlen(s) + 1)) == NULL) {
  7458.             printf("?Internal error: malloc\n");
  7459.             goto XZXLGI;
  7460.         } else
  7461.           strcpy(p2,s);                 /* safe */
  7462.         printf("\r\n");
  7463.         if ((rc = cmcfm()) < 0)
  7464.           goto XZXLGI;
  7465.     }
  7466.     sstate = setgen('I',p1,p2,p3);      /* Get here with at least user ID */
  7467.     rc = 0;
  7468.  
  7469.   XZXLGI:                               /* Common exit point */
  7470.     if (psaved)
  7471.       cmsetp(psave);                    /* Restore original prompt */
  7472.     if (p3) { free(p3); p3 = NULL; }    /* Free malloc'd storage */
  7473.     if (p2) { free(p2); p2 = NULL; }
  7474.     if (p1) { free(p1); p1 = NULL; }
  7475.     if (rc > -1) {
  7476.         if (local && rc > -1)           /* If local, flush tty input buffer */
  7477.           ttflui();
  7478.     }
  7479.     return(rc);
  7480. }
  7481.  
  7482. #ifdef OS2
  7483. #ifndef NOLOCAL
  7484. int
  7485. dormt(xx) int xx; {
  7486.     int rc = 0;
  7487.     extern int term_io;
  7488.     int term_io_sav = term_io;
  7489. #ifdef NEWFTP
  7490.     extern int ftpget, ftpisopen();
  7491.     if ((ftpget == 1) || ((ftpget == 2) && ftpisopen()))
  7492.       return(doftprmt(xx,0));
  7493. #endif /* NEWFTP */
  7494.     term_io = 0;
  7495.     rc = xxdormt(xx);
  7496.     term_io = term_io_sav;
  7497.     return rc;
  7498. }
  7499.  
  7500.  
  7501. int
  7502. xxdormt(xx) int xx;
  7503. #else /* NOLOCAL */
  7504. int
  7505. dormt(xx) int xx;
  7506. #endif /* NOLOCAL */
  7507. #else /* OS2 */
  7508. int
  7509. dormt(xx) int xx;
  7510. #endif /* OS2 */
  7511. {                                       /* REMOTE commands */
  7512.     int x, y, retcode;
  7513.     char *s, sbuf[50], *s2;
  7514.  
  7515. #ifdef NEWFTP
  7516.     extern int ftpget, ftpisopen();
  7517.     if ((ftpget == 1) || ((ftpget == 2) && ftpisopen()))
  7518.       return(doftprmt(xx,0));
  7519. #endif /* NEWFTP */
  7520.  
  7521.     remfile = 0;                        /* Clear these */
  7522.     rempipe = 0;
  7523.     remappd = 0;
  7524.  
  7525.     if (xx < 0) return(xx);             /* REMOTE what? */
  7526.  
  7527.     xzcmd = xx;                         /* Make global copy of arg */
  7528.  
  7529.     if (xx == XZSET) {                  /* REMOTE SET */
  7530.         if ((y = cmkey(rmstab,nrms,"","",xxstring)) < 0) {
  7531.             if (y == -3) {
  7532.                 printf("?Parameter name required\n");
  7533.                 return(-9);
  7534.             } else return(y);
  7535.         }
  7536.         return(doprm(y,1));
  7537.     }
  7538.  
  7539.     switch (xx) {                       /* Others... */
  7540.  
  7541.       case XZCDU:
  7542.         if ((x = cmcfm()) < 0) return(x);
  7543.         printf("?Sorry, REMOTE CDUP not supported yet\n");
  7544.         return(-9);
  7545.  
  7546.       case XZCWD:                       /* CWD (CD) */
  7547.         if ((x = cmtxt("Remote directory name","",&s,xxstring)) < 0)
  7548.           return(x);
  7549.         if ((x = remtxt(&s)) < 0)
  7550.           return(x);
  7551.         debug(F111,"XZCWD: ",s,x);
  7552.         *sbuf = NUL;
  7553.         s2 = sbuf;
  7554. /*
  7555.   The following is commented out because since the disappearance of the
  7556.   DECSYSTEM-20 from the planet, no known computer requires a password for
  7557.   changing directory.
  7558. */
  7559. #ifdef DIRPWDPR
  7560.         if (*s != NUL) {                /* If directory name given, */
  7561.                                         /* get password on separate line. */
  7562.             if (tlevel > -1) {          /* From take file... */
  7563.  
  7564.                 if (fgets(sbuf,50,tfile[tlevel]) == NULL)
  7565.                   fatal("take file ends prematurely in 'remote cwd'");
  7566.                 debug(F110," pswd from take file",s2,0);
  7567.                 for (x = (int)strlen(sbuf);
  7568.                      x > 0 && (sbuf[x-1] == NL || sbuf[x-1] == CR);
  7569.                      x--)
  7570.                   sbuf[x-1] = '\0';
  7571.  
  7572.             } else {                    /* From terminal... */
  7573.  
  7574.                 printf(" Password: ");  /* get a password */
  7575. #ifdef IKSD
  7576.                 if (!local && inserver) {
  7577.                     x = coninc(0);
  7578.                 } else
  7579. #endif /* IKSD */
  7580. #ifdef OS2
  7581.                   x = is_a_tty(0) ? coninc(0) : /* with no echo ... */
  7582.                     getchar();
  7583. #else /* OS2 */
  7584.                 x = getchar();
  7585. #endif /* OS2 */
  7586.                 while ((x != NL) && (x != CR)) {
  7587.                     if ((x &= 0177) == '?') {
  7588.                         printf("? Password of remote directory\n Password: ");
  7589.                         s2 = sbuf;
  7590.                         *sbuf = NUL;
  7591.                     } else if (x == ESC) /* Mini command line editor... */
  7592.                       bleep(BP_WARN);
  7593.                     else if (x == BS || x == 0177)
  7594.                       s2--;
  7595.                     else if (x == 025) {        /* Ctrl-U */
  7596.                         s2 = sbuf;
  7597.                         *sbuf = NUL;
  7598.                     } else
  7599.                       *s2++ = x;
  7600.  
  7601.                     /* Get the next character */
  7602. #ifdef IKSD
  7603.                     if (!local && inserver) {
  7604.                         x = coninc(0);
  7605.                     } else
  7606. #endif /* IKSD */
  7607. #ifdef OS2
  7608.                     x = is_a_tty(0) ? coninc(0) : /* with no echo ... */
  7609.                       getchar();
  7610. #else /* OS2 */
  7611.                     x = getchar();
  7612. #endif /* OS2 */
  7613.                 }
  7614.                 *s2 = NUL;
  7615.                 putchar('\n');
  7616.             }
  7617.             s2 = sbuf;
  7618.         } else s2 = "";
  7619. #endif /* DIRPWDPR */
  7620.  
  7621.         debug(F110," password",s2,0);
  7622.     rcdactive = 1;
  7623.         sstate = setgen('C',s,s2,"");
  7624.         retcode = 0;
  7625.         break;
  7626.  
  7627.       case XZDEL:                               /* Delete */
  7628.         if ((x = cmtxt("Name of remote file(s) to delete",
  7629.                        "",&s,xxstring)) < 0) {
  7630.             if (x == -3) {
  7631.                 printf("?Name of remote file(s) required\n");
  7632.                 return(-9);
  7633.             } else return(x);
  7634.         }
  7635.         if ((x = remtxt(&s)) < 0)
  7636.           return(x);
  7637.         if (local) ttflui();            /* If local, flush tty input buffer */
  7638.         retcode = sstate = rfilop(s,'E');
  7639.         break;
  7640.  
  7641.       case XZDIR:                       /* Directory */
  7642.         if ((x = cmtxt("Remote directory or file specification","",&s,
  7643.                        xxstring)) < 0)
  7644.           return(x);
  7645.         if ((x = remtxt(&s)) < 0)
  7646.           return(x);
  7647.         if (local) ttflui();            /* If local, flush tty input buffer */
  7648.         rmsg();
  7649.         retcode = sstate = setgen('D',s,"","");
  7650.         break;
  7651.  
  7652.       case XZHLP:                       /* Help */
  7653.         if ((x = remcfm()) < 0) return(x);
  7654.         sstate = setgen('H',"","","");
  7655.         retcode = 0;
  7656.         break;
  7657.  
  7658.       case XZHOS:                       /* Host */
  7659.         if ((x = cmtxt("Command for remote system","",&s,xxstring)) < 0)
  7660.           return(x);
  7661.         if ((x = remtxt(&s)) < 0)
  7662.           return(x);
  7663.         if ((y = (int)strlen(s)) < 1)
  7664.           return(x);
  7665.         ckstrncpy(line,s,LINBUFSIZ);
  7666.         cmarg = line;
  7667.         rmsg();
  7668.         retcode = sstate = 'c';
  7669.         break;
  7670.  
  7671. #ifndef NOFRILLS
  7672.       case XZKER:
  7673.         if ((x = cmtxt("Command for remote Kermit","",&s,xxstring)) < 0)
  7674.           return(x);
  7675.         if ((x = remtxt(&s)) < 0)
  7676.           return(x);
  7677.         if ((int)strlen(s) < 1)  {
  7678.             if (x == -3) {
  7679.                 printf("?Remote Kermit command required\n");
  7680.                 return(-9);
  7681.             } else return(x);
  7682.         }
  7683.         ckstrncpy(line,s,LINBUFSIZ);
  7684.         cmarg = line;
  7685.         retcode = sstate = 'k';
  7686.         rmsg();
  7687.         break;
  7688.  
  7689.       case XZLGI:                       /* Login */
  7690.     rcdactive = 1;            /* Suppress "Logged in" msg if quiet */
  7691.         return(plogin(XXREM));
  7692.  
  7693.       case XZLGO: {                     /* Logout */
  7694.           extern int bye_active;
  7695.           if ((x = remcfm()) < 0) return(x);
  7696.           sstate = setgen('I',"","","");
  7697.           retcode = 0;
  7698.           bye_active = 1;               /* Close connection when done */
  7699.           break;
  7700.       }
  7701.  
  7702.       case XZPRI:                       /* Print */
  7703.         if (!atdiso || !atcapr) {       /* Disposition attribute off? */
  7704.             printf("?Disposition Attribute is Off\n");
  7705.             return(-2);
  7706.         }
  7707.         cmarg = "";
  7708.         cmarg2 = "";
  7709.         if ((x = cmifi("Local file(s) to print on remote printer","",&s,&y,
  7710.                        xxstring)) < 0) {
  7711.             if (x == -3) {
  7712.                 printf("?Name of local file(s) required\n");
  7713.                 return(-9);
  7714.             }
  7715.             return(x);
  7716.         }
  7717.         ckstrncpy(line,s,LINBUFSIZ);    /* Make a safe copy of filename */
  7718.         *optbuf = NUL;                  /* Wipe out any old options */
  7719.         if ((x = cmtxt("Options for remote print command","",&s,xxstring)) < 0)
  7720.           return(x);
  7721.         if ((x = remtxt(&s)) < 0)
  7722.           return(x);
  7723.         if ((int)strlen(optbuf) > 94) { /* Make sure this is legal */
  7724.             printf("?Option string too long\n");
  7725.             return(-9);
  7726.         }
  7727.         ckstrncpy(optbuf,s,OPTBUFLEN);  /* Make a safe copy of options */
  7728.         nfils = -1;                     /* Expand file list internally */
  7729.         cmarg = line;                   /* Point to file list. */
  7730.         rprintf = 1;                    /* REMOTE PRINT modifier for SEND */
  7731.         sstate = 's';                   /* Set start state to SEND */
  7732.         if (local) displa = 1;
  7733.         retcode = 0;
  7734.         break;
  7735. #endif /* NOFRILLS */
  7736.  
  7737.       case XZSPA:                       /* Space */
  7738.         if ((x = cmtxt("Confirm, or remote directory name",
  7739.                        "",&s,xxstring)) < 0)
  7740.           return(x);
  7741.         if ((x = remtxt(&s)) < 0)
  7742.           return(x);
  7743.         retcode = sstate = setgen('U',s,"","");
  7744.         break;
  7745.  
  7746.       case XZMSG:                       /* Message */
  7747.         if ((x = cmtxt("Short text message for server","",&s,xxstring)) < 0)
  7748.           return(x);
  7749.         if ((x = remtxt(&s)) < 0)
  7750.           return(x);
  7751.         retcode = sstate = setgen('M',s,"","");
  7752.         break;
  7753.  
  7754. #ifndef NOFRILLS
  7755.       case XZTYP:                       /* Type */
  7756.         if ((x = cmtxt("Remote file specification","",&s,xxstring)) < 0)
  7757.           return(x);
  7758.         if ((int)strlen(s) < 1) {
  7759.             printf("?Remote filename required\n");
  7760.             return(-9);
  7761.         }
  7762.         if ((x = remtxt(&s)) < 0)
  7763.           return(x);
  7764.         rmsg();
  7765.         retcode = sstate = rfilop(s,'T');
  7766.         break;
  7767. #endif /* NOFRILLS */
  7768.  
  7769. #ifndef NOFRILLS
  7770.       case XZWHO:
  7771.         if ((x = cmtxt("Remote user name, or carriage return",
  7772.                        "",&s,xxstring)) < 0)
  7773.           return(x);
  7774.         if ((x = remtxt(&s)) < 0)
  7775.           return(x);
  7776.         retcode = sstate = setgen('W',s,"","");
  7777.         break;
  7778. #endif /* NOFRILLS */
  7779.  
  7780.       case XZPWD:                       /* PWD */
  7781.         if ((x = remcfm()) < 0) return(x);
  7782.         sstate = setgen('A',"","","");
  7783.         retcode = 0;
  7784.         break;
  7785.  
  7786. #ifndef NOSPL
  7787.       case XZQUE: {                     /* Query */
  7788.           char buf[2];
  7789.           extern char querybuf[], * qbufp;
  7790.           extern int qbufn;
  7791.           if ((y = cmkey(vartyp,nvartyp,"","",xxstring)) < 0)
  7792.             return(y);
  7793.           if ((x = cmtxt(y == 'F' ? "Remote function invocation" :
  7794.                          ('K' ? "Remote variable name or function":
  7795.                          "Remote variable name"),
  7796.                          "",
  7797.                          &s,
  7798.                          (y == 'K') ? xxstring : NULL
  7799.                          )) < 0)        /* Don't evaluate */
  7800.             return(x);
  7801.           if ((x = remtxt(&s)) < 0)
  7802.             return(x);
  7803.           query = 1;                    /* QUERY is active */
  7804.           qbufp = querybuf;             /* Initialize query response buffer */
  7805.           qbufn = 0;
  7806.           querybuf[0] = NUL;
  7807.           buf[0] = (char) (y & 127);
  7808.           buf[1] = NUL;
  7809.           retcode = sstate = setgen('V',"Q",(char *)buf,s);
  7810.           break;
  7811.       }
  7812.  
  7813.       case XZASG: {                     /* Assign */
  7814.           char buf[VNAML];
  7815.           if ((y = cmfld("Remote variable name","",&s,NULL)) < 0) /* No eval */
  7816.             return(y);
  7817.           if ((int)strlen(s) >= VNAML) {
  7818.               printf("?Too long\n");
  7819.               return(-9);
  7820.           }
  7821.           ckstrncpy(buf,s,VNAML);
  7822.           if ((x = cmtxt("Assignment for remote variable",
  7823.                    "",&s,xxstring)) < 0) /* Evaluate this one */
  7824.             return(x);
  7825.           if ((x = remtxt(&s)) < 0)
  7826.             return(x);
  7827. #ifdef COMMENT
  7828. /*
  7829.   Server commands can't be long packets.  In principle there's no reason
  7830.   why they shouldn't be, except that we don't know at this point if the
  7831.   server is capable of accepting long packets because we haven't started
  7832.   the protocol yet.  In practice, allowing a long packet here breaks a lot
  7833.   of assumptions, causes buffer overruns and crashes, etc.  To be fixed
  7834.   later.  (But since this is commented out, evidently I fixed it later...)
  7835. */
  7836.           if ((int)strlen(s) > 85) {    /* Allow for encoding expansion */
  7837.               printf("?Sorry, value is too long - 85 characters max\n");
  7838.               return(-9);
  7839.           }
  7840. #endif /* COMMENT */
  7841.           retcode = sstate = setgen('V',"S",(char *)buf,s);
  7842.           break;
  7843.       }
  7844. #endif /* NOSPL */
  7845.  
  7846.       case XZCPY: {                     /* COPY */
  7847.           char buf[TMPBUFSIZ];
  7848.           buf[TMPBUFSIZ-1] = '\0';
  7849.           if ((x = cmfld("Name of remote file to copy","",&s,xxstring)) < 0) {
  7850.               if (x == -3) {
  7851.                   printf("?Name of remote file required\n");
  7852.                   return(-9);
  7853.               }
  7854.               else
  7855.                 return(x);
  7856.           }
  7857.           ckstrncpy(buf,s,TMPBUFSIZ);
  7858.           if ((x = cmfld("Name of remote destination file or directory",
  7859.                          "",&s, xxstring)) < 0) {
  7860.               if (x == -3) {
  7861.                   printf("?Name of remote file or directory required\n");
  7862.                   return(-9);
  7863.               } else return(x);
  7864.           }
  7865.           ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  7866.           if ((x = remcfm()) < 0)
  7867.             return(x);
  7868.           if (local) ttflui();          /* If local, flush tty input buffer */
  7869.           retcode = sstate = setgen('K',buf,tmpbuf,"");
  7870.           break;
  7871.       }
  7872.       case XZREN: {                     /* Rename */
  7873.           char buf[TMPBUFSIZ];
  7874.           buf[TMPBUFSIZ-1] = '\0';
  7875.           if ((x = cmfld("Name of remote file to rename",
  7876.                          "",&s,xxstring)) < 0) {
  7877.               if (x == -3) {
  7878.                   printf("?Name of remote file required\n");
  7879.                   return(-9);
  7880.               } else return(x);
  7881.           }
  7882.           ckstrncpy(buf,s,TMPBUFSIZ);
  7883.           if ((x = cmfld("New name of remote file","",&s, xxstring)) < 0) {
  7884.               if (x == -3) {
  7885.                   printf("?Name of remote file required\n");
  7886.                   return(-9);
  7887.               } else return(x);
  7888.           }
  7889.           ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  7890.           if ((x = remcfm()) < 0)
  7891.             return(x);
  7892.           if (local) ttflui();          /* If local, flush device buffer */
  7893.           retcode = sstate = setgen('R',buf,tmpbuf,"");
  7894.           break;
  7895.       }
  7896.       case XZMKD:                       /* mkdir */
  7897.       case XZRMD:                       /* rmdir */
  7898.         if ((x = cmtxt((xx == XZMKD) ?
  7899.                        "Name of remote directory to create" :
  7900.                        "Name of remote directory to delete",
  7901.                        "",
  7902.                        &s,
  7903.                        xxstring
  7904.                        )) < 0) {
  7905.             if (x == -3) {
  7906.                 printf("?Name required\n");
  7907.                 return(-9);
  7908.             } else return(x);
  7909.         }
  7910.         if ((x = remtxt(&s)) < 0)
  7911.           return(x);
  7912.         if (local) ttflui();            /* If local, flush tty input buffer */
  7913.         retcode = sstate = rfilop(s, (char)(xx == XZMKD ? 'm' : 'd'));
  7914.         break;
  7915.  
  7916.       case XZXIT:                       /* Exit */
  7917.         if ((x = remcfm()) < 0) return(x);
  7918.         sstate = setgen('X',"","","");
  7919.         retcode = 0;
  7920.         break;
  7921.  
  7922.       default:
  7923.         if ((x = remcfm()) < 0) return(x);
  7924.         printf("?Not implemented - %s\n",cmdbuf);
  7925.         return(-2);
  7926.     }
  7927.     if (local && retcode > -1)          /* If local, flush tty input buffer */
  7928.       ttflui();
  7929.     return(retcode);
  7930. }
  7931.  
  7932.  
  7933. /*  R F I L O P  --  Remote File Operation  */
  7934.  
  7935. CHAR
  7936. #ifdef CK_ANSIC
  7937. rfilop(char * s, char t)
  7938. #else
  7939. rfilop(s,t) char *s, t;
  7940. #endif /* CK_ANSIC */
  7941. /* rfilop */ {
  7942.     if (*s == NUL) {
  7943.         printf("?File specification required\n");
  7944.         return((CHAR) 0);
  7945.     }
  7946.     debug(F111,"rfilop",s,t);
  7947.     return(setgen(t,s,"",""));
  7948. }
  7949. #endif /* NOXFER */
  7950.  
  7951. #ifdef ANYX25
  7952. int
  7953. setx25() {
  7954.     if ((y = cmkey(x25tab,nx25,"X.25 call options","",xxstring)) < 0)
  7955.       return(y);
  7956.     switch (y) {
  7957.       case XYUDAT:
  7958.         if ((z = cmkey(onoff,2,"X.25 call user data","",xxstring))
  7959.             < 0) return(z);
  7960.         if (z == 0) {
  7961.             if ((z = cmcfm()) < 0) return(z);
  7962.             cudata = 0;             /* disable call user data */
  7963.             return (success = 1);
  7964.         }
  7965.         if ((x = cmtxt("X.25 call user data string","",&s,xxstring)) < 0)
  7966.           return(x);
  7967.         if ((int)strlen(s) == 0) {
  7968.             return (-3);
  7969.         } else if ((int)strlen(s) > MAXCUDATA) {
  7970.             printf("?The length must be > 0 and <= %d\n",MAXCUDATA);
  7971.             return(-2);
  7972.         }
  7973.         if ((y = cmcfm()) < 0) return(y);
  7974.         ckstrncpy(udata,s,MAXCUDATA);
  7975.         cudata = 1;                     /* X.25 call user data specified */
  7976.         return (success = 1);
  7977.       case XYCLOS:
  7978.         if ((z = cmkey(onoff,2,"X.25 closed user group call","",xxstring))
  7979.             < 0) return(z);
  7980.         if (z == 0) {
  7981.             if ((z = cmcfm()) < 0) return(z);
  7982.             closgr = -1;                /* disable closed user group */
  7983.             return (success = 1);
  7984.         }
  7985.         if ((y = cmnum("0 <= cug index >= 99","",10,&x,xxstring)) < 0)
  7986.           return(y);
  7987.         if (x < 0 || x > 99) {
  7988.             printf("?The choices are 0 <= cug index >= 99\n");
  7989.             return(-2);
  7990.         }
  7991.         if ((y = cmcfm()) < 0) return(y);
  7992.         closgr = x;                     /* closed user group selected */
  7993.         return (success = 1);
  7994.  
  7995.       case XYREVC:
  7996.         if((z = cmkey(onoff,2,"X.25 reverse charge call","",xxstring)) < 0)
  7997.           return(z);
  7998.         if ((x = cmcfm()) < 0) return(x);
  7999.         revcall = z;
  8000.         return (success = 1);
  8001.     }
  8002. }
  8003.  
  8004. #ifndef IBMX25
  8005. int
  8006. setpadp() {
  8007.     if ((y = cmkey(padx3tab,npadx3,"PAD X.3 parameter name","",xxstring)) < 0)
  8008.       return(y);
  8009.     x = y;
  8010.     switch (x) {
  8011.       case PAD_BREAK_CHARACTER:
  8012.         if ((y = cmnum("PAD break character value","",10,&z,xxstring)) < 0)
  8013.           return(y);
  8014.         if ((y = cmcfm()) < 0) return(y);
  8015.         break;
  8016.       case PAD_ESCAPE:
  8017.         if ((y = cmnum("PAD escape","",10,&z,xxstring)) < 0) return(y);
  8018.         if (z != 0 && z != 1) {
  8019.             printf("?The choices are 0 or 1\n");
  8020.             return(-2);
  8021.         }
  8022.         if ((y = cmcfm()) < 0) return(y);
  8023.         break;
  8024.       case PAD_ECHO:
  8025.         if ((y = cmnum("PAD echo","",10,&z,xxstring)) < 0) return(y);
  8026.         if (z != 0 && z != 1) {
  8027.             printf("?The choices are 0 or 1\n");
  8028.             return(-2);
  8029.         }
  8030.         if ((y = cmcfm()) < 0) return(y);
  8031.         break;
  8032.       case PAD_DATA_FORWARD_CHAR:
  8033.         if ((y = cmnum("PAD data forward char","",10,&z,xxstring)) < 0)
  8034.           return(y);
  8035.         if (z != 0 && z != 2) {
  8036.             printf("?The choices are 0 or 2\n");
  8037.             return(-2);
  8038.         }
  8039.         if ((y = cmcfm()) < 0) return(y);
  8040.         break;
  8041.       case PAD_DATA_FORWARD_TIMEOUT:
  8042.         if ((y = cmnum("PAD data forward timeout","",10,&z,xxstring)) < 0)
  8043.             return(y);
  8044.         if (z < 0 || z > 255) {
  8045.             printf("?The choices are 0 or 1 <= timeout <= 255\n");
  8046.             return(-2);
  8047.         }
  8048.         if ((y = cmcfm()) < 0) return(y);
  8049.         break;
  8050.       case PAD_FLOW_CONTROL_BY_PAD:
  8051.         if ((y = cmnum("PAD pad flow control","",10,&z,xxstring)) < 0)
  8052.           return(y);
  8053.         if (z != 0 && z != 1) {
  8054.             printf("?The choices are 0 or 1\n");
  8055.             return(-2);
  8056.         }
  8057.         if ((y = cmcfm()) < 0) return(y);
  8058.         break;
  8059.       case PAD_SUPPRESSION_OF_SIGNALS:
  8060.         if ((y = cmnum("PAD service","",10,&z,xxstring)) < 0) return(y);
  8061.         if (z != 0 && z != 1) {
  8062.             printf("?The choices are 0 or 1\n");
  8063.             return(-2);
  8064.         }
  8065.         if ((y = cmcfm()) < 0) return(y);
  8066.         break;
  8067.  
  8068.       case PAD_BREAK_ACTION:
  8069.         if ((y = cmnum("PAD break action","",10,&z,xxstring)) < 0) return(y);
  8070.         if (z != 0 && z != 1 && z != 2 && z != 5 && z != 8 && z != 21) {
  8071.             printf("?The choices are 0, 1, 2, 5, 8 or 21\n");
  8072.             return(-2);
  8073.         }
  8074.         if ((y = cmcfm()) < 0) return(y);
  8075.         break;
  8076.  
  8077.       case PAD_SUPPRESSION_OF_DATA:
  8078.         if ((y = cmnum("PAD data delivery","",10,&z,xxstring)) < 0) return(y);
  8079.         if (z != 0 && z != 1) {
  8080.             printf("?The choices are 0 or 1\n");
  8081.             return(-2);
  8082.         }
  8083.         if ((y = cmcfm()) < 0) return(y);
  8084.         break;
  8085.  
  8086.       case PAD_PADDING_AFTER_CR:
  8087.         if ((y = cmnum("PAD crpad","",10,&z,xxstring)) < 0) return(y);
  8088.         if (z < 0 || z > 7) {
  8089.             printf("?The choices are 0 or 1 <= crpad <= 7\n");
  8090.             return(-2);
  8091.         }
  8092.         if ((y = cmcfm()) < 0) return(y);
  8093.         break;
  8094.  
  8095.       case PAD_LINE_FOLDING:
  8096.         if ((y = cmnum("PAD linefold","",10,&z,xxstring)) < 0) return(y);
  8097.         if (z < 0 || z > 255) {
  8098.             printf("?The choices are 0 or 1 <= linefold <= 255\n");
  8099.             return(-2);
  8100.         }
  8101.         if ((y = cmcfm()) < 0) return(y);
  8102.         break;
  8103.  
  8104.       case PAD_LINE_SPEED:
  8105.         if ((y = cmnum("PAD baudrate","",10,&z,xxstring)) < 0) return(y);
  8106.         if (z < 0 || z > 18) {
  8107.             printf("?The choices are 0 <= baudrate <= 18\n");
  8108.             return(-2);
  8109.         }
  8110.         if ((y = cmcfm()) < 0) return(y);
  8111.         break;
  8112.  
  8113.       case PAD_FLOW_CONTROL_BY_USER:
  8114.         if ((y = cmnum("PAD terminal flow control","",10,&z,xxstring)) < 0)
  8115.             return(y);
  8116.         if (z != 0 && z != 1) {
  8117.             printf("?The choices are 0 or 1\n");
  8118.             return(-2);
  8119.         }
  8120.         if ((y = cmcfm()) < 0) return(y);
  8121.         break;
  8122.  
  8123.       case PAD_LF_AFTER_CR:
  8124.         if ((y = cmnum("PAD crpad","",10,&z,xxstring)) < 0) return(y);
  8125.         if (z < 0 || z == 3 || z > 7) {
  8126.             printf("?The choices are 0, 1, 2, 4, 5, 6 or 7\n");
  8127.             return(-2);
  8128.         }
  8129.         if ((y = cmcfm()) < 0) return(y);
  8130.         break;
  8131.  
  8132.       case PAD_PADDING_AFTER_LF:
  8133.         if ((y = cmnum("PAD lfpad","",10,&z,xxstring)) < 0) return(y);
  8134.         if (z < 0 || z > 7) {
  8135.             printf("?The choices are 0 or 1 <= lfpad <= 7\n");
  8136.             return(-2);
  8137.         }
  8138.         if ((y = cmcfm()) < 0) return(y);
  8139.         break;
  8140.  
  8141.       case PAD_EDITING:
  8142.         if ((y = cmnum("PAD edit control","",10,&z,xxstring)) < 0) return(y);
  8143.         if (z != 0 && z != 1) {
  8144.             printf("?The choices are 0 or 1\n");
  8145.             return(-2);
  8146.         }
  8147.         if ((y = cmcfm()) < 0) return(y);
  8148.         break;
  8149.  
  8150.       case PAD_CHAR_DELETE_CHAR:
  8151.         if ((y = cmnum("PAD char delete char","",10,&z,xxstring)) < 0)
  8152.             return(y);
  8153.         if (z < 0 || z > 127) {
  8154.             printf("?The choices are 0 or 1 <= chardelete <= 127\n");
  8155.             return(-2);
  8156.         }
  8157.         if ((y = cmcfm()) < 0) return(y);
  8158.         break;
  8159.  
  8160.       case PAD_BUFFER_DELETE_CHAR:
  8161.         if ((y = cmnum("PAD buffer delete char","",10,&z,xxstring)) < 0)
  8162.             return(y);
  8163.         if (z < 0 || z > 127) {
  8164.             printf("?The choices are 0 or 1 <= bufferdelete <= 127\n");
  8165.             return(-2);
  8166.         }
  8167.         if ((y = cmcfm()) < 0) return(y);
  8168.         break;
  8169.  
  8170.       case PAD_BUFFER_DISPLAY_CHAR:
  8171.         if ((y = cmnum("PAD display line char","",10,&z,xxstring)) < 0)
  8172.             return(y);
  8173.         if (z < 0 || z > 127) {
  8174.             printf("?The choices are 0 or 1 <= displayline <= 127\n");
  8175.             return(-2);
  8176.         }
  8177.         if ((y = cmcfm()) < 0) return(y);
  8178.         break;
  8179.     }
  8180.     padparms[x] = z;
  8181.     return(success = 1);
  8182. }
  8183. #endif /* IBMX25 */
  8184. #endif /* ANYX25 */
  8185.  
  8186. #ifndef NOXFER
  8187. int
  8188. setat(rmsflg) int rmsflg; {
  8189.     int xx;
  8190.     if ((y = cmkey(attrtab,natr,"File Attribute packets","",xxstring)) < 0)
  8191.       return(y);
  8192.     if (y == AT_XALL) {                 /* ATTRIBUTES ALL ON or ALL OFF */
  8193.         if ((z = seton(&xx)) < 0) return(z);
  8194.         if (rmsflg) {
  8195.             printf("Sorry, command not available\n");
  8196.             return(-9);
  8197.         } else {
  8198.             atenci = xx;                /* Encoding in */
  8199.             atenco = xx;                /* Encoding out */
  8200.             atdati = xx;                /* Date in */
  8201.             atdato = xx;                /* Date out */
  8202.             atdisi = xx;                /* Disposition in/out */
  8203.             atdiso = xx;
  8204.             atleni = xx;                /* Length in/out (both kinds) */
  8205.             atleno = xx;
  8206.             atblki = xx;                /* Blocksize in/out */
  8207.             atblko = xx;
  8208.             attypi = xx;                /* File type in/out */
  8209.             attypo = xx;
  8210.             atsidi = xx;                /* System ID in/out */
  8211.             atsido = xx;
  8212.             atsysi = xx;                /* System-dependent params in/out */
  8213.             atsyso = xx;
  8214. #ifdef CK_PERMS                         /* Protection */
  8215.             atlpri = xx;                /* Local in */
  8216.             atlpro = xx;                /* Local out */
  8217.             atgpri = xx;                /* Generic in */
  8218.             atgpro = xx;                /* Generic out */
  8219. #endif /* CK_PERMS */
  8220. #ifdef STRATUS
  8221.             atfrmi = xx;                /* Format in/out */
  8222.             atfrmo = xx;
  8223.             atcrei = xx;                /* Creator id in/out */
  8224.             atcreo = xx;
  8225.             atacti = xx;                /* Account in/out */
  8226.             atacto = xx;
  8227. #endif /* STRATUS */
  8228.         }
  8229.         return(z);
  8230.     } else if (y == AT_ALLY || y == AT_ALLN) { /* ATTRIBUTES ON or OFF */
  8231.         if ((x = cmcfm()) < 0) return(x);
  8232.         atcapr = (y == AT_ALLY) ? 1 : 0;
  8233.         if (rmsflg) {
  8234.             sstate = setgen('S', "132", atcapr ? "1" : "0", "");
  8235.             return((int) sstate);
  8236.         } else return(success = 1);
  8237.     }
  8238.     /* Otherwise, it's an individual attribute that wants turning off/on */
  8239.  
  8240.     if ((z = cmkey(onoff,2,"","",xxstring)) < 0) return(z);
  8241.     if ((x = cmcfm()) < 0) return(x);
  8242.  
  8243. /* There are better ways to do this... */
  8244. /* The real problem is that we're not separating the in and out cases */
  8245. /* and so we have to arbitrarily pick the "in" case, i.e tell the remote */
  8246. /* server to ignore incoming attributes of the specified type, rather */
  8247. /* than telling it not to send them.  The protocol does not (yet) define */
  8248. /* codes for "in-and-out-at-the-same-time". */
  8249.  
  8250.     switch (y) {
  8251. #ifdef CK_PERMS
  8252. /* We're lumping local and generic protection together for now... */
  8253.       case AT_LPRO:
  8254.       case AT_GPRO:
  8255.         if (rmsflg) {
  8256.             sstate = setgen('S', "143", z ? "1" : "0", "");
  8257.             return((int) sstate);
  8258.         }
  8259.         atlpri = atlpro = atgpri = atgpro = z; break;
  8260. #endif /* CK_PERMS */
  8261.       case AT_DISP:
  8262.         if (rmsflg) {
  8263.             sstate = setgen('S', "142", z ? "1" : "0", "");
  8264.             return((int) sstate);
  8265.         }
  8266.         atdisi = atdiso = z; break;
  8267.       case AT_ENCO:
  8268.         if (rmsflg) {
  8269.             sstate = setgen('S', "141", z ? "1" : "0", "");
  8270.             return((int) sstate);
  8271.         }
  8272.         atenci = atenco = z; break;
  8273.       case AT_DATE:
  8274.         if (rmsflg) {
  8275.             sstate = setgen('S', "135", z ? "1" : "0", "");
  8276.             return((int) sstate);
  8277.         }
  8278.         atdati = atdato = z; break;
  8279.       case AT_LENB:
  8280.       case AT_LENK:
  8281.         if (rmsflg) {
  8282.             sstate = setgen('S', "133", z ? "1" : "0", "");
  8283.             return((int) sstate);
  8284.         }
  8285.         atleni = atleno = z; break;
  8286.       case AT_BLKS:
  8287.         if (rmsflg) {
  8288.             sstate = setgen('S', "139", z ? "1" : "0", "");
  8289.             return((int) sstate);
  8290.         }
  8291.         atblki = atblko = z; break;
  8292.       case AT_FTYP:
  8293.         if (rmsflg) {
  8294.             sstate = setgen('S', "134", z ? "1" : "0", "");
  8295.             return((int) sstate);
  8296.         }
  8297.         attypi = attypo = z; break;
  8298. #ifdef STRATUS
  8299.       case AT_CREA:
  8300.         if (rmsflg) {
  8301.             sstate = setgen('S', "136", z ? "1" : "0", "");
  8302.             return((int) sstate);
  8303.         }
  8304.         atcrei = atcreo = z; break;
  8305.       case AT_ACCT:
  8306.         if (rmsflg) {
  8307.             sstate = setgen('S', "137", z ? "1" : "0", "");
  8308.             return((int) sstate);
  8309.         }
  8310.         atacti = atacto = z; break;
  8311. #endif /* STRATUS */
  8312.       case AT_SYSI:
  8313.         if (rmsflg) {
  8314.             sstate = setgen('S', "145", z ? "1" : "0", "");
  8315.             return((int) sstate);
  8316.         }
  8317.         atsidi = atsido = z; break;
  8318.       case AT_RECF:
  8319.         if (rmsflg) {
  8320.             sstate = setgen('S', "146", z ? "1" : "0", "");
  8321.             return((int) sstate);
  8322.         }
  8323.         atfrmi = atfrmo = z; break;
  8324.       case AT_SYSP:
  8325.         if (rmsflg) {
  8326.             sstate = setgen('S', "147", z ? "1" : "0", "");
  8327.             return((int) sstate);
  8328.         }
  8329.         atsysi = atsyso = z; break;
  8330.       default:
  8331.         printf("?Not available\n");
  8332.         return(-2);
  8333.     }
  8334.     return(1);
  8335. }
  8336. #endif /* NOXFER */
  8337.  
  8338. #ifndef NOSPL
  8339. int
  8340. setinp() {
  8341.     if ((y = cmkey(inptab,ninp,"","",xxstring)) < 0) return(y);
  8342.     switch (y) {
  8343. #ifdef OS2
  8344.       case IN_PAC:                      /* SET INPUT PACING */
  8345.         z = cmnum("milliseconds","0",10,&x,xxstring);
  8346.         return(setnum(&tt_inpacing,x,z,1000));
  8347.       case IN_TRM:                      /* SET INPUT TERMINAL */
  8348.         return(seton(&interm));
  8349. #endif /* OS2 */
  8350.       case IN_DEF:                      /* SET INPUT DEFAULT-TIMEOUT */
  8351.         z = cmnum("Positive number","",10,&x,xxstring);
  8352.         return(setnum(&indef,x,z,94));
  8353. #ifdef CKFLOAT
  8354.       case IN_SCA:                      /* SET INPUT SCALE-FACTOR */
  8355.     if ((x = cmfld("Number such as 2 or 0.5","1.0",&s, xxstring)) < 0)
  8356.       return(x);
  8357.         if (isfloat(s,0)) {        /* A floating-point number? */
  8358.             extern char * inpscale;
  8359.         inscale = floatval;        /* Yes, get its value */
  8360.         makestr(&inpscale,s);    /* Save it as \v(inscale) */
  8361.         return(success = 1);
  8362.     } else {
  8363.         return(-2);
  8364.     }
  8365. #endif    /* CKFLOAT */
  8366.       case IN_TIM:                      /* SET INPUT TIMEOUT-ACTION */
  8367.         if ((z = cmkey(intimt,2,"","",xxstring)) < 0) return(z);
  8368.         if ((x = cmcfm()) < 0) return(x);
  8369.         intime[cmdlvl] = z;
  8370.         return(success = 1);
  8371.       case IN_CAS:                      /* SET INPUT CASE */
  8372.         if ((z = cmkey(incast,2,"","",xxstring)) < 0) return(z);
  8373.         if ((x = cmcfm()) < 0) return(x);
  8374.         inpcas[cmdlvl] = z;
  8375.         return(success = 1);
  8376.       case IN_ECH:                      /* SET INPUT ECHO */
  8377.         return(seton(&inecho));
  8378.       case IN_SIL:                      /* SET INPUT SILENCE */
  8379.         z = cmnum("Seconds of inactivity before INPUT fails","",10,&x,
  8380.                   xxstring);
  8381.         return(setnum(&insilence,x,z,-1));
  8382.  
  8383.       case IN_BUF:                      /* SET INPUT BUFFER-SIZE */
  8384.         if ((z = cmnum("Number of bytes in INPUT buffer",
  8385.                        ckitoa(INPBUFSIZ),10,&x, xxstring)) < 0)
  8386.           return(z);
  8387.         if ((y = cmcfm()) < 0) return(y);
  8388.         inbufsize = 0;
  8389.         if (inpbuf) {
  8390.             free(inpbuf);
  8391.             inpbuf = NULL;
  8392.             inpbp = NULL;
  8393.         }
  8394.         if (!(s = (char *)malloc(x + 1)))
  8395.           return(0);
  8396.         inpbuf = s;
  8397.         inpbp = s;
  8398.         inbufsize = x;
  8399.         for (x = 0; x <= inbufsize; x++)
  8400.           inpbuf[x] = NUL;
  8401.         return(success = 1);
  8402.  
  8403. #ifdef CK_AUTODL
  8404.       case IN_ADL:                      /* AUTODOWNLOAD */
  8405.         return(seton(&inautodl));
  8406. #endif /* CK_AUTODL */
  8407.  
  8408.       case IN_CAN:                      /* SET INPUT INTERRUPTS */
  8409.         return(seton(&inintr));
  8410.     }
  8411.     return(0);
  8412. }
  8413. #endif /* NOSPL */
  8414.  
  8415. #ifdef NETCONN
  8416. VOID
  8417. ndreset() {
  8418. #ifndef NODIAL                          /* This depends on DIAL... */
  8419.     int i=0, j=0;
  8420.     if (!ndinited)                      /* Don't free garbage... */
  8421.       return;
  8422.     for (i = 0; i < nhcount; i++) {     /* Clean out previous list */
  8423.         if (nh_p[i])
  8424.           free(nh_p[i]);
  8425.         nh_p[i] = NULL;
  8426.         if (nh_p2[i])
  8427.           free(nh_p2[i]);
  8428.         nh_p2[i] = NULL;
  8429.         for (j = 0; j < 4; j++) {
  8430.             if (nh_px[j][i])
  8431.               free(nh_px[j][i]);
  8432.             nh_px[j][i] = NULL;
  8433.         }
  8434.     }
  8435. #endif /* NODIAL */
  8436. }
  8437.  
  8438. VOID
  8439. ndinit() {                              /* Net directory pointers */
  8440. #ifndef NODIAL                          /* This depends on DIAL... */
  8441.     int i, j;
  8442.     if (ndinited++)                     /* Don't do this more than once. */
  8443.       return;
  8444.     for (i = 0; i < MAXDDIR; i++) {     /* Init all pointers to NULL */
  8445.         netdir[i] = NULL;
  8446.     }
  8447.     for (i = 0; i < MAXDNUMS; i++) {
  8448.         nh_p[i] = NULL;
  8449.         nh_p2[i] = NULL;
  8450.         for (j = 0; j < 4; j++)
  8451.           nh_px[j][i] = NULL;
  8452.     }
  8453. #endif /* NODIAL */
  8454. }
  8455.  
  8456. #ifndef NODIAL
  8457. #ifdef NETCONN
  8458. VOID                                    /* Get net defaults from environment */
  8459. getnetenv() {
  8460.     char *p = NULL;
  8461.  
  8462.     makestr(&p,getenv("K_NET_DIRECTORY")); /* Dialing directories */
  8463.     if (p) {
  8464.         int i;
  8465.         xwords(p,MAXDDIR,netdir,0);
  8466.         for (i = 0; i < MAXDDIR; i++) { /* Fill in any gaps... */
  8467.             if (!netdir[i+1])
  8468.               break;
  8469.             else
  8470.               netdir[i] = netdir[i+1];
  8471.             debug(F111,"netdir[i]",netdir[i],i);
  8472.         }
  8473.         nnetdir = i;
  8474.     }
  8475. }
  8476. #endif /* NETCONN */
  8477. #endif /* NODIAL */
  8478.  
  8479. int
  8480. #ifdef CK_ANSIC
  8481. lunet(char *s)                          /* s = name to look up   */
  8482. #else
  8483. lunet(s) char *s;
  8484. #endif /* CK_ANSIC */
  8485. /* lunet */ {
  8486. #ifndef NODIAL                          /* This depends on DIAL... */
  8487.     int n, n1, t, dd = 0;
  8488.     int ambiguous = 0;
  8489.     FILE * f;
  8490.     char *line = NULL;
  8491.     extern int dialdpy;
  8492.     int netdpy = dialdpy;
  8493.     char *info[8];
  8494.  
  8495.     nhcount = 0;                        /* Set this before returning */
  8496.  
  8497.     if (!s || nnetdir < 1)              /* Validate arguments */
  8498.       return(-1);
  8499.  
  8500.     if (isdigit(*s) || *s == '*' || *s == '.')
  8501.       return(0);
  8502.  
  8503.     if ((n1 = (int) strlen(s)) < 1)     /* Length of string to look up */
  8504.       return(-1);
  8505.  
  8506.     if (!(line = malloc(1024)))         /* Allocate input buffer */
  8507.       return(-1);
  8508.  
  8509.   lu_again:
  8510.     f = NULL;                           /* Network directory file descriptor */
  8511.     t = nhcount = 0;                    /* Match count */
  8512.     dd = 0;                             /* Directory counter */
  8513.  
  8514.     dirline = 0;
  8515.     while (1) {                         /* We make one pass */
  8516.         if (!f) {                       /* Directory not open */
  8517.             if (dd >= nnetdir)          /* No directories left? */
  8518.               break;                    /* Done. */
  8519.             if ((f = fopen(netdir[dd],"r")) == NULL) { /* Open it */
  8520.                 perror(netdir[dd]);     /* Can't, print message saying why */
  8521.                 dd++;
  8522.                 continue;               /* But go on to next one. */
  8523.             }
  8524.             if (netdpy)
  8525.               printf("Opening %s...\n",netdir[dd]);
  8526.             dd++;
  8527.         }
  8528.         line[0] = NUL;
  8529.         if (getnct(line,1023,f,1) < 0) { /* Read a line */
  8530.             if (f) {                    /* f can be clobbered! */
  8531.                 fclose(f);              /* Close the file */
  8532.                 f = NULL;               /* Indicate next one needs opening */
  8533.             }
  8534.             continue;
  8535.         }
  8536.         if (!line[0])                   /* Empty line */
  8537.           continue;
  8538.  
  8539.         xwords(line,7,info,0);          /* Parse it */
  8540.  
  8541.         if (!info[1] || !info[2] || !info[3]) /* Required fields */
  8542.           continue;
  8543.         if (*info[1] == ';')            /* Full-line comment */
  8544.           continue;
  8545.         if ((n = (int) strlen(info[1])) < 1) /* Length of name-tag */
  8546.           continue;
  8547.         if (n < n1)                     /* Search name is longer */
  8548.           continue;                     /* Can't possibly match */
  8549.         if (ambiguous && n != n1)
  8550.           continue;
  8551.         if (ckstrcmp(s,info[1],n1,0))   /* Compare using length of */
  8552.           continue;                     /* search string s. */
  8553.  
  8554.         /* Have a match */
  8555.  
  8556.         makestr(&(nh_p[nhcount]), info[3]);    /* address */
  8557.         makestr(&(nh_p2[nhcount]),info[2]);    /* net type */
  8558.         makestr(&(nh_px[0][nhcount]),info[4]); /* net-specific stuff... */
  8559.         makestr(&(nh_px[1][nhcount]),info[5]);
  8560.         makestr(&(nh_px[2][nhcount]),info[6]);
  8561.         makestr(&(nh_px[3][nhcount]),info[7]);
  8562.  
  8563.         nhcount++;                      /* Count this match */
  8564.         if (nhcount > MAXDNUMS) {       /* Watch out for too many */
  8565.             printf("Warning: %d matches found, %d max\n",
  8566.                    nhcount,
  8567.                    MAXDNUMS
  8568.                    );
  8569.             nhcount = MAXDNUMS;
  8570.             break;
  8571.         }
  8572.         if (nhcount == 1) {             /* First one - save entry name */
  8573.             if (n_name) {               /* Free the one from before if any */
  8574.                 free(n_name);
  8575.                 n_name = NULL;
  8576.             }
  8577.             if (!(n_name = (char *)malloc(n + 1))) { /* Allocate new storage */
  8578.                 printf("?memory allocation error - lunet:3\n");
  8579.                 if (line) {
  8580.                     free(line);
  8581.                     line = NULL;
  8582.                 }
  8583.                 nhcount = 0;
  8584.                 return(-1);
  8585.             }
  8586.             t = n;                      /* Remember its length */
  8587.             strcpy(n_name,info[1]);     /* safe */
  8588.         } else {                        /* Second or subsequent one */
  8589.             if ((int) strlen(info[1]) == t) /* Lengths compare */
  8590.               if (!ckstrcmp(n_name,info[1],t,0)) /* Caseless compare OK */
  8591.                 continue;
  8592.  
  8593.             /* Name given by user matches entries with different names */
  8594.  
  8595.             if (ambiguous)              /* Been here before */
  8596.               break;
  8597.  
  8598.             ambiguous = 1;              /* Now an exact match is required */
  8599.             ndreset();                  /* Clear out previous list */
  8600.             goto lu_again;              /* Do it all over again. */
  8601.         }
  8602.     }
  8603.     if (line) {
  8604.         free(line);
  8605.         line = NULL;
  8606.     }
  8607.     if (nhcount == 0 && ambiguous)
  8608.       printf("?\"%s\" - ambiguous in network directory\n",s);
  8609. #else
  8610.     nhcount = 0;
  8611. #endif /* NODIAL */
  8612.     return(nhcount);
  8613. }
  8614. #endif /* NETCONN */
  8615.  
  8616. #ifndef NOLOCAL
  8617. /*  C L S C O N N X  --  Close connection  */
  8618.  
  8619. int
  8620. clsconnx(ask) int ask; {
  8621.     int x, rc = 0;
  8622. #ifdef NEWFTP
  8623.     extern int ftpget, ftpisopen();
  8624.     if ((ftpget == 1) || ((ftpget == 2) && !local && ftpisopen()))
  8625.       return(success = ftpbye());
  8626. #endif /* NEWFTP */
  8627.     debug(F101,"clsconnx local","",local);
  8628.     if (local) {
  8629.         x = ask ? hupok(1) : 1;         /* Make sure it's OK to close */
  8630.         if (!x) {
  8631.             rc = -1;
  8632.             debug(F101,"clsconnx hupok says no","",rc);
  8633.             return(rc);
  8634.         }
  8635.         ttflui();                       /* Clear away buffered up junk */
  8636. #ifndef NODIAL
  8637. #ifdef OS2ONLY
  8638. /* Don't hangup a line that is shared with the SLIP or PPP driver */
  8639.         if (!ttslip && !ttppp)
  8640. #endif /* OS2ONLY */
  8641.           mdmhup();
  8642. #endif /* NODIAL */
  8643.         if (network && msgflg)
  8644.           printf(" Closing connection\n");
  8645.         ttclos(0);                      /* Close old connection, if any */
  8646.         rc = 1;
  8647.         {
  8648.             extern int wasclosed, whyclosed;
  8649.             if (wasclosed) {
  8650.                 whyclosed = WC_CLOS;
  8651. #ifndef NOSPL
  8652.                 if (nmac) {             /* Any macros defined? */
  8653.                     int k;              /* Yes */
  8654.                     /* printf("ON_CLOSE CLSCONNX\n"); */
  8655.                     wasclosed = 0;
  8656.                     k = mlook(mactab,"on_close",nmac);  /* Look this up */
  8657.                     if (k >= 0) {                       /* If found, */
  8658.                         if (dodo(k,ckitoa(whyclosed),0) > -1) /* set it up, */
  8659.                           parser(1);                    /* and execute it */
  8660.                     }
  8661.                 }
  8662. #endif /* NOSPL */
  8663.                 whyclosed = WC_REMO;
  8664.                 wasclosed = 0;
  8665.             }
  8666.         }
  8667.     }
  8668. #ifdef VMS                              /* Or maybe #ifndef UNIX? */
  8669.     else {                              /* Need to do this in VMS to */
  8670.         ttclos(0);                      /* free the tty channel number */
  8671.         rc = 1;                         /* obtained in ttopen() or else */
  8672.     }                                   /* subsequent ttopen's won't work */
  8673. #endif /* VMS */
  8674.     dologend();
  8675.     haveline = 0;
  8676.     if (mdmtyp < 0) {                   /* Switching from net to async? */
  8677.         if (mdmsav > -1)                /* Restore modem type from last */
  8678.           mdmtyp = mdmsav;              /* SET MODEM command, if any. */
  8679.         else
  8680.           mdmtyp = 0;
  8681.         mdmsav = -1;
  8682.     }
  8683.     if (network)
  8684.       network = 0;
  8685. #ifdef NETCONN
  8686.     if (oldplex > -1) {                 /* Restore previous duplex setting. */
  8687.         duplex = oldplex;
  8688.         oldplex = -1;
  8689.     }
  8690. #endif /* NETCONN */
  8691. #ifndef MAC
  8692.     ckstrncpy(ttname,dftty,TTNAMLEN);   /* Restore default communication */
  8693. #endif /* MAC */
  8694.     local = dfloc;                      /* device and local/remote status */
  8695.     if (local) {
  8696.         cxtype = CXT_DIRECT;            /* Something reasonable */
  8697.         speed = ttgspd();               /* Get the current speed */
  8698.     } else {
  8699.         cxtype = CXT_REMOTE;
  8700.         speed = -1L;
  8701.     }
  8702. #ifndef NOXFER
  8703.     if (xreliable > -1 && !setreliable) {
  8704.         reliable = xreliable;
  8705.         debug(F101,"clsconnx reliable A","",reliable);
  8706.     } else if (!setreliable) {
  8707.         reliable = SET_AUTO;
  8708.         debug(F101,"clsconnx reliable B","",reliable);
  8709.     }
  8710. #endif /* NOXFER */
  8711.     setflow();                          /* Revert flow control */
  8712.     return(rc);
  8713. }
  8714.  
  8715. int
  8716. clskconnx(x) int x; {                   /* Close Kermit connection only */
  8717.     int t, rc;                          /* (not FTP) */
  8718. #ifdef NEWFTP
  8719.     extern int ftpget;
  8720.     t = ftpget;
  8721.     ftpget = 0;
  8722. #endif /* NEWFTP */
  8723.     rc = clsconnx(x);
  8724. #ifdef NEWFTP
  8725.     ftpget = t;
  8726. #endif /* NEWFTP */
  8727.     return(rc);
  8728. }
  8729.  
  8730. /* May 2002: setlin() decomposition starts here ... */
  8731.  
  8732. #ifdef OS2
  8733. #define SRVBUFSIZ PIPENAML
  8734. #else /* OS2 */
  8735. #define SRVBUFSIZ 63
  8736. #endif /* OS2 */
  8737. #define HOSTNAMLEN 15*65
  8738.  
  8739. int netsave = -1;
  8740. static char * tmpstring = NULL;
  8741. static char * tmpusrid = NULL;
  8742.  
  8743. #ifdef SSHCMD
  8744. char * sshcmd = NULL;
  8745. char * defsshcmd = "ssh -e none";
  8746. #else
  8747. #ifdef SSHBUILTIN
  8748. char * sshrcmd = NULL;
  8749. char * sshtmpcmd = NULL;
  8750. #endif /* SSHBUILTIN */
  8751. #endif /* SSHCMD */
  8752.  
  8753. /* c x _ f a i l  --  Common error exit routine for cx_net, cx_line */
  8754.  
  8755. int
  8756. cx_fail(msg, text) int msg; char * text; {
  8757.     makestr(&slmsg,text);        /* For the record (or GUI) */
  8758.     if (msg)                /* Not GUI, not quiet, etc */
  8759.       printf("?%s\n",text);        /* Print error message */
  8760.     slrestor();                /* Restore LINE/HOST to known state */
  8761.     return(msg ? -9 : (success = 0));    /* Return appropriate code */
  8762. }
  8763.  
  8764. #ifdef NETCONN
  8765. /* c x _ n e t  --  Make a network connection */
  8766.  
  8767. /*
  8768.   Call with:
  8769.     net      = network type
  8770.     protocol = protocol type
  8771.     host     = string pointer to host name.
  8772.     svc      = string pointer to service or port on host.
  8773.     username = username for connection
  8774.     password = password for connection
  8775.     command  = command to execute
  8776.     param1   = Telnet: Authentication type
  8777.                SSH:    Version
  8778.     param2   = Telnet: Encryption type
  8779.                SSH:    Command as Subsystem
  8780.     param3   = Telnet: 1 to wait for negotiations, 0 otherwise
  8781.                SSH:    X11 Forwarding
  8782.     cx       = 1 to automatically enter Connect mode, 0 otherwise.
  8783.     sx       = 1 to automatically enter Server mode, 0 otherwise.
  8784.     flag     = if no host name given, 1 = close current connection, 0 = resume
  8785.     gui      = 1 if called from GUI dialog, 0 otherwise.
  8786.   Returns:
  8787.     1 on success
  8788.     0 on failure and no message printed, slmsg set to failure message.
  8789.    -9 on failure and message printed, ditto.
  8790. */
  8791. int
  8792. #ifdef CK_ANSIC
  8793. cx_net( int net, int protocol, char * xhost, char * svc, 
  8794.         char * username, char * password, char * command,
  8795.         int param1, int param2, int param3, int cx, int sx, int flag, int gui)
  8796. #else /* CK_ANSIC */
  8797. cx_net(net, protocol, xhost, svc,
  8798.        username, password, command,
  8799.        param1, param2, param3, cx, sx, flag, gui)
  8800.     char * xhost, * svc, * username, *password, *command; 
  8801.     int net, protocol, cx, sx, flag, param1, param2, param3, gui; 
  8802. #endif /* CK_ANSIC */
  8803. /* cx_net */ {
  8804.  
  8805.     int i, n, x, msg;
  8806.     int _local = -1;
  8807.  
  8808.     extern char pwbuf[], * g_pswd;
  8809.     extern int pwflg, pwcrypt, g_pflg, g_pcpt, nolocal;
  8810.  
  8811.     char srvbuf[SRVBUFSIZ+1];        /* Service */
  8812.     char hostbuf[HOSTNAMLEN];        /* Host buffer to manipulate */
  8813.     char hostname[HOSTNAMLEN];        /* Copy of host parameter */
  8814.     char * host = hostbuf;        /* Pointer to copy of host param */
  8815.  
  8816.     if (!xhost) xhost = "";        /* Watch out for null pointers */
  8817.     if (!svc) svc = "";
  8818.     ckstrncpy(host,xhost,HOSTNAMLEN);    /* Avoid buffer confusion */
  8819.  
  8820.     debug(F110,"cx_net host",host,0);
  8821.     debug(F111,"cx_net service",svc,SRVBUFSIZ);
  8822.     debug(F101,"cx_net network type","",net);
  8823.  
  8824.     msg = (gui == 0) && msgflg;        /* Whether to print messages */
  8825.  
  8826. #ifndef NODIAL
  8827.     debug(F101,"cx_net nnetdir","",nnetdir);
  8828.     x = 0;                /* Look up in network directory */
  8829.     if (*host == '=') {            /* If number starts with = sign */
  8830.     host++;                /* strip it */
  8831.     while (*host == SP) host++;    /* and any leading spaces */
  8832.     debug(F110,"cx_net host 2",host,0);
  8833.     nhcount = 0;
  8834.     } else if (*host) {            /* We want to look it up. */
  8835.     if (nnetdir > 0)        /* If there is a directory... */
  8836.       x = lunet(host);        /* (sets nhcount) */
  8837.     else                /* otherwise */
  8838.       nhcount = 0;            /* we didn't find any there */
  8839.     if (x < 0)            /* Internal error? */
  8840.       return(cx_fail(msg,"Network directory lookup error"));
  8841.     debug(F111,"cx_net lunet nhcount",host,nhcount);
  8842.     }
  8843. #endif /* NODIAL */
  8844.  
  8845.     /* New connection wanted.  Make a copy of the host name/address... */
  8846.  
  8847.     if (clskconnx(1) < 0)        /* Close current Kermit connection */
  8848.       return(cx_fail(msg,"Error closing previous connection"));
  8849.  
  8850.     if (*host) {            /* They gave a hostname */
  8851.     _local = 1;            /* Network connection always local */
  8852.     if (mdmsav < 0)
  8853.       mdmsav = mdmtyp;        /* Remember old modem type */
  8854.     mdmtyp = -net;            /* Special code for network */
  8855.     } else {                /* They just said "set host" */
  8856.     host = dftty;            /* So go back to normal */
  8857.     _local = dfloc;            /* default tty, location, */
  8858.     if (flag) {            /* Close current connection */
  8859.         setflow();            /* Maybe change flow control */
  8860.         haveline = 1;        /* (* is this right? *) */
  8861.         dologend();
  8862. #ifndef NODIAL
  8863.         dialsta = DIA_UNK;
  8864. #endif /* NODIAL */
  8865. #ifdef LOCUS
  8866.         if (autolocus) {
  8867.         setlocus(1,1);
  8868.         }
  8869. #endif /* LOCUS */
  8870.             /* XXX - Is this right? */
  8871.         /* Should we be returning without doing anything ? */
  8872.         /* Yes it's right -- we closed the old connection just above. */
  8873.         return(success = 1);        
  8874.     }
  8875.     }
  8876.     success = 0;
  8877.     if (host != line)                   /* line[] is a global */
  8878.       ckstrncpy(line,host,LINBUFSIZ);
  8879.     ckstrncpy(hostname,host,HOSTNAMLEN);
  8880.     ckstrncpy(srvbuf,svc,SRVBUFSIZ+1);
  8881.  
  8882. #ifndef NODIAL
  8883.     if ((nhcount > 1) && msg) {
  8884.     int k;
  8885.     printf("%d entr%s found for \"%s\"%s\n",
  8886.            nhcount,
  8887.            (nhcount == 1) ? "y" : "ies",
  8888.            s,
  8889.            (nhcount > 0) ? ":" : "."
  8890.            );
  8891.     for (i = 0; i < nhcount; i++) {
  8892.         printf("%3d. %-12s => %-9s %s",
  8893.                i+1,n_name,nh_p2[i],nh_p[i]);
  8894.         for (k = 0; k < 4; k++) { /* Also list net-specific items */
  8895.         if (nh_px[k][i])      /* free format... */
  8896.           printf(" %s",nh_px[k][i]);
  8897.         else
  8898.           break;
  8899.         }
  8900.         printf("\n");
  8901.     }
  8902.     }
  8903.     if (nhcount == 0)
  8904.       n = 1;
  8905.     else
  8906.       n = nhcount;
  8907. #else
  8908.     n = 1;
  8909.     nhcount = 0;
  8910. #endif /* NODIAL */
  8911.  
  8912.     for (i = 0; i < n; i++) {        /* Loop for each entry found */
  8913.     debug(F101,"cx_net loop i","",i);
  8914. #ifndef NODIAL
  8915.     if (nhcount > 0) {        /* If we found at least one entry... */
  8916.         ckstrncpy(line,nh_p[i],LINBUFSIZ); /* Copy current entry */
  8917.         if (lookup(netcmd,nh_p2[i],nnets,&x) > -1) { /* Net type */
  8918.         int xx;
  8919.         xx = netcmd[x].kwval;
  8920.         /* User specified SSH so don't let net directory override */
  8921.         if (net != NET_SSH || xx != NET_TCPB) {
  8922.             net = xx;
  8923.             mdmtyp  = 0 - net;
  8924.         }
  8925.         } else {
  8926.         makestr(&slmsg,"Network type not supported");
  8927.         if (msg)
  8928.           printf("Error - network type \"%s\" not supported\n",
  8929.              nh_p2[i]
  8930.                  );
  8931.         continue;
  8932.         }
  8933.         switch (net) {        /* Net-specific directory things */
  8934. #ifdef SSHBUILTIN
  8935.           case NET_SSH:        /* SSH */
  8936.                 /* Any SSH specific network directory stuff? */
  8937.                 break;                  /* NET_SSH */
  8938. #endif /* SSHBUILTIN */
  8939.  
  8940.           case NET_TCPB: {        /* TCP/IP TELNET,RLOGIN,... */
  8941. #ifdef TCPSOCKET
  8942.           char *q;
  8943.           int flag = 0;
  8944.  
  8945.           /* Extract ":service", if any, from host string */
  8946.           debug(F110,"cx_net service 1",line,0);
  8947.           for (q = line; (*q != '\0') && (*q != ':'); q++)
  8948.             ;
  8949.           if (*q == ':') { *q++ = NUL; flag = 1; }
  8950.           debug(F111,"cx_net service 2",line,flag);
  8951.  
  8952.           /* Get service, if any, from directory entry */
  8953.  
  8954.           if (!*srvbuf) {
  8955.               if (nh_px[0][i]) {
  8956.               ckstrncpy(srvbuf,nh_px[0][i],SRVBUFSIZ);
  8957.               debug(F110,"cx_net service 3",srvbuf,0);
  8958.               }
  8959.               if (flag) {
  8960.               ckstrncpy(srvbuf,q,SRVBUFSIZ);
  8961.               debug(F110,"cx_net service 4",srvbuf,0);
  8962.               }
  8963.           }
  8964.           ckstrncpy(hostname,line,HOSTNAMLEN);
  8965.  
  8966.           /* If we have a service, append to host name/address */
  8967.           if (*srvbuf) {
  8968.               ckstrncat(line, ":", LINBUFSIZ);
  8969.               ckstrncat(line, srvbuf, LINBUFSIZ);
  8970.               debug(F110,"cx_net service 5",line,0);
  8971.           }
  8972. #ifdef RLOGCODE
  8973.           /* If no service given but command was RLOGIN */
  8974.           else if (ttnproto == NP_RLOGIN) { /* add this... */
  8975.               ckstrncat(line, ":login",LINBUFSIZ);
  8976.               debug(F110,"cx_net service 6",line,0);
  8977.           }
  8978. #ifdef CK_AUTHENTICATION
  8979. #ifdef CK_KERBEROS
  8980.           else if (ttnproto == NP_K4LOGIN ||
  8981.                ttnproto == NP_K5LOGIN) { /* add this... */
  8982.               ckstrncat(line, ":klogin",LINBUFSIZ);
  8983.               debug(F110,"cx_net service 7",line,0);
  8984.           }
  8985.           else if (ttnproto == NP_EK4LOGIN ||
  8986.                ttnproto == NP_EK5LOGIN) { /* add this... */
  8987.               ckstrncat(line, ":eklogin",LINBUFSIZ);
  8988.               debug(F110,"cx_net service 8",line,0);
  8989.           }
  8990. #endif /* CK_KERBEROS */
  8991. #endif /* CK_AUTHENTICATION */
  8992. #endif /* RLOGCODE */
  8993.           else {        /* Otherwise, add ":telnet". */
  8994.               ckstrncat(line, ":telnet", LINBUFSIZ);
  8995.               debug(F110,"cx_net service 9",line,0);
  8996.           }
  8997.           if (username) {    /* This is a parameter... */
  8998.               ckstrncpy(uidbuf,username,UIDBUFLEN);
  8999.               uidflag = 1;
  9000.           }
  9001.           /* Fifth field, if any, is user ID (for rlogin) */
  9002.  
  9003.           if (nh_px[1][i] && !uidflag)
  9004.             ckstrncpy(uidbuf,username,UIDBUFLEN);
  9005. #ifdef RLOGCODE
  9006.           if (IS_RLOGIN() && !uidbuf[0])
  9007.             return(cx_fail(msg,"Username required"));
  9008. #endif /* RLOGCODE */
  9009. #endif /* TCPSOCKET */
  9010.           break;
  9011.           }
  9012.           case NET_PIPE:        /* Pipe */
  9013. #ifdef NPIPE
  9014.         if (!pipename[0]) { /* User didn't give a pipename */
  9015.             if (nh_px[0][i]) { /* But directory entry has one */
  9016.             if (strcmp(pipename,"\\pipe\\")) {
  9017.                 ckstrncpy(pipename,"\\pipe\\",LINBUFSIZ);
  9018.                 ckstrncat(srvbuf,nh_px[0][i],PIPENAML-6);
  9019.             } else {
  9020.                 ckstrncpy(pipename,nh_px[0][i],PIPENAML);
  9021.             }
  9022.             debug(F110,"cx_net pipeneme",pipename,0);
  9023.             }
  9024.         }
  9025. #endif /* NPIPE */
  9026.         break;
  9027.  
  9028.           case NET_SLAT:            /* LAT / CTERM */
  9029. #ifdef SUPERLAT
  9030.         if (!slat_pwd[0]) { /* User didn't give a password */
  9031.             if (nh_px[0][i]) { /* But directory entry has one */
  9032.             ckstrncpy(slat_pwd,nh_px[0][i],18);
  9033.             debug(F110,"cx_net SuperLAT password",slat_pwd,0);
  9034.             }
  9035.         }
  9036. #endif /* SUPERLAT */
  9037.         break;
  9038.  
  9039.           case NET_SX25:        /* X.25 keyword parameters */
  9040.           case NET_IX25:
  9041.           case NET_VX25: {
  9042. #ifdef ANYX25
  9043.           int k;            /* Cycle through the four fields */
  9044.           for (k = 0; k < 4; k++) {
  9045.               if (!nh_px[k][i]) /* Bail out if none left */
  9046.             break;
  9047.               if (!ckstrcmp(nh_px[k][i],"cug=",4,0)) {
  9048.               closgr = atoi(nh_px[k][i]+4);
  9049.               debug(F101,"X25 CUG","",closgr);
  9050.               } else if (!ckstrcmp(nh_px[k][i],"cud=",4,0)) {
  9051.               cudata = 1;
  9052.               ckstrncpy(udata,nh_px[k][i]+4,MAXCUDATA);
  9053.               debug(F110,"X25 CUD",cudata,0);
  9054.               } else if (!ckstrcmp(nh_px[k][i],"rev=",4,0)) {
  9055.               revcall = !ckstrcmp(nh_px[k][i]+4,"=on",3,0);
  9056.               debug(F101,"X25 REV","",revcall);
  9057. #ifndef IBMX25
  9058.               } else if (!ckstrcmp(nh_px[k][i],"pad=",4,0)) {
  9059.               int x3par, x3val;
  9060.               char *s1, *s2;
  9061.               s1 = s2 = nh_px[k][i]+4; /* PAD parameters */
  9062.               while (*s2) {            /* Pick them apart */
  9063.                   if (*s2 == ':') {
  9064.                   *s2 = NUL;
  9065.                   x3par = atoi(s1);
  9066.                   s1 = ++s2;
  9067.                   continue;
  9068.                   } else if (*s2 == ',') {
  9069.                   *s2 = NUL;
  9070.                   x3val = atoi(s1);
  9071.                   s1 = ++s2;
  9072.                   debug(F111,"X25 PAD",x3par,x3val);
  9073.                   if (x3par > -1 &&
  9074.                       x3par <= MAXPADPARMS)
  9075.                     padparms[x3par] = x3val;
  9076.                   continue;
  9077.                   } else
  9078.                 s2++;
  9079.               }
  9080. #endif /* IBMX25 */
  9081.               }
  9082.           }
  9083. #endif /* ANYX25 */
  9084.           break;
  9085.           }
  9086.           default:            /* Nothing special for other nets */
  9087.         break;
  9088.         }
  9089.     } else
  9090. #endif /* NODIAL */
  9091.     {                /* No directory entries found. */
  9092.         ckstrncpy(line,hostname,LINBUFSIZ); /* Put this back... */
  9093.         /* If the user gave a TCP service */
  9094.         if (net == NET_TCPB || net == NET_SSH)
  9095.           if (*srvbuf) {        /* Append it to host name/address */
  9096.           ckstrncat(line, ":", LINBUFSIZ);
  9097.           ckstrncat(line, srvbuf,LINBUFSIZ);
  9098.           }
  9099.     }
  9100.     /*
  9101.        Get here with host name/address and all net-specific
  9102.        parameters set, ready to open the connection.
  9103.     */
  9104.     mdmtyp = -net;            /* This should have been done */
  9105.                     /* already but just in case ... */
  9106.  
  9107.     debug(F110,"cx_net net line[] before ttopen",line,0);
  9108.     debug(F101,"cx_net net mdmtyp before ttopen","",mdmtyp);
  9109.     debug(F101,"cx_net net ttnproto","",ttnproto);
  9110.  
  9111. #ifdef SSHBUILTIN
  9112.         if (net == NET_SSH) {
  9113.             makestr(&ssh_hst,hostname);        /* Stash everything */
  9114.             if (username) {
  9115.                 if (!sl_uid_saved) {
  9116.                     ckstrncpy(sl_uidbuf,uidbuf,UIDBUFLEN);
  9117.                     sl_uid_saved = 1;
  9118.                 }
  9119.                 ckstrncpy(uidbuf,username,UIDBUFLEN);
  9120.             }
  9121.             if (srvbuf[0]) {
  9122.                 makestr(&ssh_prt,srvbuf);
  9123.             } else
  9124.                 makestr(&ssh_prt,NULL);
  9125.  
  9126.             if (command) {
  9127.                 makestr(&ssh_cmd,brstrip(command));
  9128.                 ssh_cas = param2;
  9129.             } else
  9130.                 makestr(&ssh_cmd,NULL);
  9131.  
  9132.             if (param1 > -1) {
  9133. #ifndef SSHTEST
  9134.                 if (!sl_ssh_ver_saved) {
  9135.                     sl_ssh_ver = ssh_ver;
  9136.                     sl_ssh_ver_saved = 1;
  9137.                 }
  9138. #endif /* SSHTEST */
  9139.                 ssh_ver = param1;
  9140.             }
  9141.             if (param3 > -1) {
  9142. #ifndef SSHTEST
  9143.                 if (!sl_ssh_xfw_saved) {
  9144.                     sl_ssh_xfw = ssh_xfw;
  9145.                     sl_ssh_xfw_saved = 1;
  9146.                 }
  9147. #endif /* SSHTEST */
  9148.                 ssh_xfw = param3;
  9149.             }
  9150.         } else                          /* NET_SSH */
  9151. #endif /* SSHBUILTIN */
  9152. #ifdef TCPSOCKET
  9153.       if (net == NET_TCPB) {
  9154.             switch (protocol) {
  9155. #ifdef CK_SSL
  9156. #ifdef COMMENT
  9157. /*
  9158.   Jeff's version from 30 Dec 2006 - doesn't work - SSL/TLS_RAW still
  9159.   start Telnet negotions if a 0xff byte comes in.
  9160. */
  9161.           case NP_SSL_RAW:
  9162.                 ttnproto = NP_SSL_RAW;
  9163.         debug(F101,"NP_SSL_RAW ttnproto","",ttnproto);
  9164.                 ssl_only_flag = 1;
  9165.                 tls_only_flag = 0;
  9166.                 break;
  9167.  
  9168.           case NP_TLS_RAW:
  9169.           ttnproto = NP_TLS_RAW;
  9170.           debug(F101,"NP_TLS_RAW ttnproto","",ttnproto);
  9171.           ssl_only_flag = 0;
  9172.           tls_only_flag = 1;
  9173.           break;
  9174.  
  9175.           case NP_SSL:
  9176.                 ttnproto = NP_SSL;
  9177.         debug(F101,"NP_SSL ttnproto","",ttnproto);
  9178.                 ssl_only_flag = 1;
  9179.                 tls_only_flag = 0;
  9180.                 break;
  9181.  
  9182.           case NP_TLS:
  9183.                 ttnproto = NP_TLS;
  9184.         debug(F101,"NP_TLS ttnproto","",ttnproto);
  9185.                 ssl_only_flag = 0;
  9186.                 tls_only_flag = 1;
  9187.                 break;
  9188.  
  9189.           case NP_SSL_TELNET:
  9190.                 ttnproto = NP_TELNET;
  9191.         debug(F101,"NP_SSL_TELNET ttnproto","",ttnproto);
  9192.                 ssl_only_flag = 1;
  9193.                 tls_only_flag = 0;
  9194.                 break;
  9195.  
  9196.           case NP_TLS_TELNET:
  9197.                 ttnproto = NP_TELNET;
  9198.         debug(F101,"NP_TLS_TELNET ttnproto","",ttnproto);
  9199.                 ssl_only_flag = 0;
  9200.                 tls_only_flag = 1;
  9201.                 break;
  9202. #else
  9203. /* fdc version of 4 Dec 2006 works OK */
  9204.           case NP_SSL_RAW:
  9205.           case NP_SSL:
  9206.         ssl_raw_flag = (protocol == NP_SSL_RAW) ? 1 : 0;
  9207.                 ttnproto = protocol;
  9208.         debug(F101,protocol==NP_SSL ?
  9209.               "NP_SSL ttnproto" :
  9210.               "NP_SSL_RAW ttnproto",
  9211.               "",ttnproto);
  9212.                 ssl_only_flag = 1;
  9213.                 tls_only_flag = 0;
  9214.                 break;
  9215.  
  9216.           case NP_TLS:
  9217.           case NP_TLS_RAW:
  9218.         tls_raw_flag = (protocol == NP_SSL_RAW) ? 1 : 0;
  9219.                 ttnproto = protocol;
  9220.         debug(F101,protocol==NP_TLS ?
  9221.               "NP_TLS ttnproto" :
  9222.               "NP_TLS_RAW ttnproto",
  9223.               "",ttnproto);
  9224.                 ssl_only_flag = 0;
  9225.                 tls_only_flag = 1;
  9226.                 break;
  9227.  
  9228.           case NP_SSL_TELNET:
  9229.         ssl_raw_flag = 0;
  9230.                 ttnproto = NP_TELNET;
  9231.         debug(F101,"NP_SSL_TELNET ttnproto","",ttnproto);
  9232.                 ssl_only_flag = 1;
  9233.                 tls_only_flag = 0;
  9234.                 break;
  9235.  
  9236.           case NP_TLS_TELNET:
  9237.         tls_raw_flag = 0;
  9238.                 ttnproto = NP_TELNET;
  9239.         debug(F101,"NP_TLS_TELNET ttnproto","",ttnproto);
  9240.                 ssl_only_flag = 0;
  9241.                 tls_only_flag = 1;
  9242.                 break;
  9243. #endif    /* COMMENT */
  9244. #endif /* CK_SSL */
  9245.  
  9246.           case NP_NONE:
  9247.           case NP_TCPRAW:
  9248.           case NP_RLOGIN:
  9249.           case NP_K4LOGIN:
  9250.           case NP_K5LOGIN:
  9251.           case NP_EK4LOGIN:
  9252.           case NP_EK5LOGIN:
  9253.           case NP_TELNET:
  9254.           case NP_KERMIT:
  9255.           default:
  9256.                 ttnproto = protocol;
  9257. #ifdef CK_SSL
  9258. #ifdef COMMENT
  9259.         /* Jeff version from 30 Dec 2006 */
  9260.                 ssl_only_flag = 0;
  9261.                 tls_only_flag = 0;
  9262. #else
  9263.         /* fdc version from 4 Dec 2006 */
  9264.         ssl_raw_flag = 0;
  9265.         tls_raw_flag = 0;
  9266.                 ssl_only_flag = 0;
  9267.                 tls_only_flag = 0;
  9268. #endif    /* COMMENT */
  9269. #endif /* CK_SSL */
  9270.                 break;
  9271.             }
  9272. #ifdef CK_AUTHENTICATION
  9273.             if ((ttnproto == NP_TELNET || ttnproto == NP_KERMIT) &&
  9274.         param1 > -1) {
  9275.         if (!sl_auth_saved) {
  9276.         int x;
  9277.         for (x = 0; x < AUTHTYPLSTSZ; x++)
  9278.           sl_auth_type_user[x] = auth_type_user[x];
  9279.         sl_auth_saved = 1;
  9280.         }
  9281.         if (!sl_topt_a_s_saved) {
  9282.         sl_topt_a_su = TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION);
  9283.         sl_topt_a_s_saved = 1;
  9284.         }
  9285.         if (!sl_topt_a_c_saved) {
  9286.         sl_topt_a_cm = TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION);
  9287.         sl_topt_a_c_saved = 1;
  9288.         }
  9289.         switch (param1) {
  9290.           case AUTHTYPE_AUTO:
  9291.         auth_type_user[0] = AUTHTYPE_AUTO;
  9292.         TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_RQ;
  9293.         TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_RQ;
  9294.         break;
  9295.           case AUTHTYPE_NULL:
  9296.         auth_type_user[0] = AUTHTYPE_NULL;
  9297.         TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_RF;
  9298.         TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_RF;
  9299.         break;
  9300. #ifdef CK_SRP
  9301.           case AUTHTYPE_SRP:
  9302.         auth_type_user[0] = AUTHTYPE_SRP;
  9303.         auth_type_user[1] = AUTHTYPE_NULL;
  9304.         TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  9305.         TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  9306.         break;
  9307. #endif /* CK_SRP */
  9308. #ifdef CK_SSL
  9309.           case AUTHTYPE_SSL:
  9310.         auth_type_user[0] = AUTHTYPE_SSL;
  9311.         auth_type_user[1] = AUTHTYPE_NULL;
  9312.         TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  9313.         TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  9314.         break;
  9315. #endif /* CK_SSL */
  9316. #ifdef NT
  9317.           case AUTHTYPE_NTLM:
  9318.         auth_type_user[0] = AUTHTYPE_NTLM;
  9319.         auth_type_user[1] = AUTHTYPE_NULL;
  9320.         TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  9321.         TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  9322.         break;
  9323. #endif /* NT */
  9324. #ifdef CK_KERBEROS
  9325.           case AUTHTYPE_KERBEROS_V4:
  9326.         auth_type_user[0] = AUTHTYPE_KERBEROS_V4;
  9327.         auth_type_user[1] = AUTHTYPE_NULL;
  9328.         TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  9329.         TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  9330.         break;
  9331.  
  9332.           case AUTHTYPE_KERBEROS_V5:
  9333.         auth_type_user[0] = AUTHTYPE_KERBEROS_V5;
  9334.         auth_type_user[1] = AUTHTYPE_NULL;
  9335.         TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  9336.         TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  9337.         break;
  9338. #endif /* CK_KERBEROS */
  9339.         }
  9340.     }
  9341.     /*
  9342.        If the user requires a particular type of Kerberos connection,
  9343.        make sure we have a valid TGT.
  9344.     */
  9345.     makestr(&slmsg,"Authentication failure");
  9346.     if ((ttnproto == NP_TELNET || ttnproto == NP_KERMIT) &&
  9347.         (line[0] == '*' &&
  9348.          TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) == TN_NG_MU ||
  9349.          line[0] != '*' &&
  9350.          TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) == TN_NG_MU)
  9351.         ) {
  9352. #ifdef CK_KERBEROS
  9353.         if ( auth_type_user[0] == AUTHTYPE_KERBEROS_V4 ) {
  9354.         extern int krb4_autoget;
  9355.         if (!ck_krb4_is_installed())
  9356.           return(cx_fail(msg,
  9357.           "Required authentication method (Kerberos 4) is not installed"));
  9358. #ifdef COMMENT
  9359.         /* This code results in false failures when using */
  9360.         /* kerberos to machines in realms other than the  */
  9361.         /* default since we don't know the realm of the   */
  9362.         /* other machine until perform the reverse DNS    */
  9363.         /* lookup.                                        */
  9364.         else if (line[0] != '*' && !ck_krb4_is_tgt_valid() &&
  9365.                (!krb4_autoget ||
  9366.                 krb4_autoget && !ck_krb4_autoget_TGT(NULL))) {
  9367.             return(cx_fail(msg,
  9368.                "Kerberos 4: Ticket Getting Ticket not valid"));
  9369.         }
  9370. #endif /* COMMENT */
  9371.         } else if (auth_type_user[0] == AUTHTYPE_KERBEROS_V5) {
  9372.         extern int krb5_autoget;
  9373.         if (!ck_krb5_is_installed()) {
  9374.             return(cx_fail(msg,
  9375.        "Required authentication method (Kerberos 5) is not installed"));
  9376.         }
  9377. #ifdef COMMENT
  9378.         /* This code results in false failures when using */
  9379.         /* kerberos to machines in realms other than the  */
  9380.         /* default since we don't know the realm of the   */
  9381.         /* other machine until perform the reverse DNS    */
  9382.         /* lookup.                                        */
  9383.         else if (line[0] != '*' && !ck_krb5_is_tgt_valid() &&
  9384.                (!krb5_autoget ||
  9385.                 krb5_autoget && !ck_krb5_autoget_TGT(NULL))) {
  9386.             return(cx_fail(msg,
  9387.              "Kerberos 5: Ticket Getting Ticket not valid."));
  9388.         }
  9389. #endif /* COMMENT */
  9390.         }
  9391. #endif /* CK_KERBEROS */
  9392. #ifdef NT
  9393.         if (auth_type_user[0] == AUTHTYPE_NTLM) {
  9394.         if (!ck_ntlm_is_installed()) {
  9395.             return(cx_fail(msg,
  9396.            "Required authentication method (NTLM) is not installed"));
  9397.         } else if (line[0] != '*' && !ck_ntlm_is_valid(0)) {
  9398.             return(cx_fail(msg,"NTLM: Credentials are unavailable."));
  9399.         }
  9400.         }
  9401. #endif /* NT */
  9402. #ifdef CK_SSL
  9403.         if (auth_type_user[0] == AUTHTYPE_SSL) {
  9404.         if (!ck_ssleay_is_installed()) {
  9405.             return(cx_fail(msg,
  9406.              "Required authentication method (SSL) is not installed"));
  9407.         }
  9408.         }
  9409. #endif /* CK_SSL */
  9410. #ifdef CK_SRP
  9411.         if (auth_type_user[0] == AUTHTYPE_SRP) {
  9412.         if (!ck_srp_is_installed()) {
  9413.             return(cx_fail(msg,
  9414.              "Required authentication method (SRP) is not installed"));
  9415.         }
  9416.         }
  9417. #endif /* CK_SRP */
  9418.     }
  9419. #endif /* CK_AUTHENTICATION */
  9420. #ifdef CK_ENCRYPTION
  9421.     if ((ttnproto == NP_TELNET || ttnproto == NP_KERMIT) &&
  9422.          param2 > -1) {
  9423.         if (!sl_cx_saved) {
  9424.         sl_cx_type = cx_type;
  9425.         sl_cx_saved = 1;
  9426.         }
  9427.         if (!sl_topt_e_s_saved) {
  9428.         sl_topt_e_su = TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION);
  9429.         sl_topt_e_sm = TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION);
  9430.         sl_topt_e_s_saved = 1;
  9431.         }
  9432.         if (!sl_topt_e_c_saved) {
  9433.         sl_topt_e_cu = TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION);
  9434.         sl_topt_e_cm = TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION);
  9435.         sl_topt_e_c_saved = 1;
  9436.         }
  9437.         cx_type = param2;
  9438.         if (cx_type == CX_AUTO) {
  9439.         TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION) = TN_NG_RQ;
  9440.         TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_RQ;
  9441.         TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION) = TN_NG_RQ;
  9442.         TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_RQ;
  9443.         } else if (cx_type == CX_NONE) {
  9444.         TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION) = TN_NG_RF;
  9445.         TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_RF;
  9446.         TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION) = TN_NG_RF;
  9447.         TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_RF;
  9448.         } else {
  9449.         TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION) = TN_NG_MU;
  9450.         TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_MU;
  9451.         TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION) = TN_NG_MU;
  9452.         TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_MU;
  9453.         }
  9454.     }
  9455.     if (ttnproto == NP_EK4LOGIN || ttnproto == NP_EK5LOGIN ||
  9456.         (ttnproto == NP_TELNET || ttnproto == NP_KERMIT) &&
  9457.         ((line[0] == '*' &&
  9458.           TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION) == TN_NG_MU &&
  9459.           TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION) == TN_NG_MU) ||
  9460.          (line[0] != '*' &&
  9461.           TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION) == TN_NG_MU &&
  9462.           TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION) == TN_NG_MU))
  9463.         ) {
  9464.         if (!ck_crypt_is_installed()) {
  9465.         return(cx_fail(msg,
  9466.           "Required Encryption methods are not installed"));
  9467.         }
  9468.     }
  9469. #endif /* CK_ENCRYPTION */
  9470. #ifdef RLOGCODE
  9471. #ifdef CK_KERBEROS
  9472. #ifdef KRB4
  9473.     if (ttnproto == NP_K4LOGIN || ttnproto == NP_EK4LOGIN) {
  9474.         extern int krb4_autoget;
  9475.         char tgt[256];
  9476.         char * realm;
  9477.  
  9478.         /* We don't have the full hostname at yet so  */
  9479.         /* we do a DNS lookup before calling ttopen() */ 
  9480.  
  9481.         realm = ck_krb4_realmofhost(ckgetfqhostname(hostname));
  9482.         ckmakmsg(tgt,256,"krbtgt.",realm,"@",realm);
  9483.         if (!ck_krb4_is_installed()) {
  9484.         return(cx_fail(msg,
  9485.          "Required authentication method (Kerberos 4) is not installed"
  9486.                    ));
  9487.         } else {
  9488.         if ((ck_krb4_tkt_isvalid(tgt) <= 0) &&
  9489.             (!krb4_autoget ||
  9490.              krb4_autoget && !ck_krb4_autoget_TGT(realm))) {
  9491.             return(cx_fail(msg,
  9492.                "Kerberos 4: Ticket Getting Ticket not valid"));
  9493.         }
  9494.         }
  9495.     }
  9496. #endif /* KRB4 */
  9497. #ifdef KRB5
  9498.     if (ttnproto == NP_K5LOGIN || ttnproto == NP_EK5LOGIN ||
  9499.         ttnproto == NP_K5U2U)
  9500.     {
  9501.         extern int krb5_autoget;
  9502.         char tgt[256];
  9503.         char * realm;
  9504.  
  9505.         /* Must get full hostname before calling ttopen() */
  9506.  
  9507.         realm = ck_krb5_realmofhost(ckgetfqhostname(hostname));
  9508.         ckmakmsg(tgt,256,"krbtgt/",realm,"@",realm);
  9509.  
  9510.         if (!ck_krb5_is_installed()) {
  9511.         return(cx_fail(msg,
  9512.                  "Required authentication method (Kerberos 5) not installed"));
  9513.         } else if (!((ck_krb5_tkt_isvalid(NULL,tgt) > 0) ||
  9514.               ck_krb5_is_tgt_valid()) &&
  9515.                (!krb5_autoget ||
  9516.             krb5_autoget && !ck_krb5_autoget_TGT(realm))) {
  9517.         return(cx_fail(msg,
  9518.                "Kerberos 5: Ticket Getting Ticket not valid."));
  9519.         }
  9520.     }
  9521. #endif /* KRB5 */
  9522. #endif /* CK_KERBEROS */
  9523. #endif /* RLOGCODE */
  9524.  
  9525. #ifndef NOSPL
  9526. #ifdef RLOGCODE
  9527.     if (username) {
  9528.         if (!sl_uid_saved) {
  9529.         ckstrncpy(sl_uidbuf,uidbuf,UIDBUFLEN);
  9530.         sl_uid_saved = 1;
  9531.         }
  9532.         ckstrncpy(uidbuf,username,UIDBUFLEN);
  9533.         uidflag = 1;
  9534.     }
  9535. #endif /* RLOGCODE */
  9536. #ifdef TNCODE
  9537.     if (!sl_tn_saved) {
  9538.         sl_tn_wait = tn_wait_flg;
  9539.         sl_tn_saved = 1;
  9540.     }
  9541.     tn_wait_flg = param3;
  9542. #endif /* TNCODE */
  9543. #endif /* NOSPL */
  9544.     } /* if (net == NET_TCPB) */
  9545. #endif /* TCPSOCKET */
  9546.  
  9547. #ifndef NOSPL
  9548. #ifdef CK_SECURITY
  9549.     if (password) {
  9550.         if (password[0]) {
  9551.         ckstrncpy(pwbuf,password,PWBUFL+1);
  9552.         pwflg = 1;
  9553.         pwcrypt = 0;
  9554.         } else
  9555.         pwflg = 0;
  9556.     }
  9557. #endif /* CK_SECURITY */
  9558. #endif /* NOSPL */
  9559.  
  9560.     /* Try to open - network */
  9561.     ckstrncpy(ttname,line,TTNAMLEN);
  9562.     y = ttopen(line, &_local, mdmtyp, 0 );
  9563.  
  9564. #ifndef NOHTTP
  9565.     /*  If the connection failed and we are using an HTTP Proxy
  9566.      *  and the reason for the failure was an authentication
  9567.      *  error, then we need to give the user to ability to
  9568.      *  enter a username and password, just like a browser.
  9569.      *
  9570.      *  I tried to do all of this within the netopen() call
  9571.      *  but it is much too much work.
  9572.      */
  9573.     while (y < 0 && tcp_http_proxy != NULL ) {
  9574.  
  9575.         if (tcp_http_proxy_errno == 401 ||
  9576.         tcp_http_proxy_errno == 407 ) {
  9577.         char uid[UIDBUFLEN];
  9578.         char pwd[256];
  9579.                 struct txtbox tb[2];
  9580.                 int ok;
  9581.  
  9582.                 tb[0].t_buf = uid;
  9583.                 tb[0].t_len = UIDBUFLEN;
  9584.                 tb[0].t_lbl = "Proxy Userid: ";
  9585.                 tb[0].t_dflt = NULL;
  9586.                 tb[0].t_echo = 1;
  9587.                 tb[1].t_buf = pwd;
  9588.                 tb[1].t_len = 256;
  9589.                 tb[1].t_lbl = "Proxy Passphrase: ";
  9590.                 tb[1].t_dflt = NULL;
  9591.                 tb[1].t_echo = 2;
  9592.  
  9593.                 ok = uq_mtxt("Proxy Server Authentication Required\n",
  9594.                               NULL, 2, tb);
  9595.  
  9596.         if (ok && uid[0]) {
  9597.             char * proxy_user, * proxy_pwd;
  9598.  
  9599.             proxy_user = tcp_http_proxy_user;
  9600.             proxy_pwd  = tcp_http_proxy_pwd;
  9601.  
  9602.             tcp_http_proxy_user = uid;
  9603.             tcp_http_proxy_pwd = pwd;
  9604.  
  9605.             ckstrncpy(ttname,line,TTNAMLEN);
  9606.             y = ttopen(line, &_local, mdmtyp, 0);
  9607.             memset(pwd,0,sizeof(pwd));
  9608.             tcp_http_proxy_user = proxy_user;
  9609.             tcp_http_proxy_pwd = proxy_pwd;
  9610.         } else
  9611.           break;
  9612.         } else
  9613.           break;
  9614.     }
  9615. #endif /* NOHTTP */
  9616.     if (y < 0) {
  9617.         slrestor();
  9618.         makestr(&slmsg,"Network connection failure");
  9619. #ifdef VMS
  9620.         if (msg && hints && !xcmdsrc && IS_RLOGIN()) {
  9621.         makestr(&slmsg,"RLOGIN failure");
  9622.         if  (socket_errno == EACCES) {
  9623.             printf("*************************\n");
  9624.             printf(
  9625.        "Hint: RLOGIN requires privileges to open an outbound port.\n");
  9626.             printf(
  9627.             "(Use SET HINTS OFF to suppress future hints.)\n");
  9628.             printf("*************************\n");
  9629.         }
  9630.         }
  9631. #else  /* Not VMS... */
  9632.         if (errno) {
  9633.         int x;
  9634.         debug(F111,"set host line, errno","",errno);
  9635.         makestr(&slmsg,ck_errstr());
  9636.         if (msg) {
  9637. #ifdef OS2
  9638.             printf("Can't connect to %s\n",line);
  9639. #else /* OS2 */
  9640. #ifdef UNIX
  9641.             if (hints && !xcmdsrc && IS_RLOGIN()) {
  9642.             makestr(&slmsg,"RLOGIN failure");
  9643.             printf("*************************\n");
  9644.             printf(
  9645.      "Hint: RLOGIN requires privileges to open an outbound port.\n");
  9646.             printf(
  9647.      "(Use SET HINTS OFF to suppress future hints.)\n");
  9648.             printf("*************************\n");
  9649.             }
  9650. #endif /* UNIX */
  9651. #endif /* OS2 */
  9652.         } else printf("Can't connect to %s\n",line);
  9653.         } else
  9654. #endif /* VMS */
  9655.           if (msg) printf("Can't open connection to %s\n",line);
  9656.         continue;
  9657.     } else {
  9658.         success = 1;
  9659. #ifndef NODIAL
  9660.         dialsta = DIA_UNK;
  9661. #endif /* NODIAL */
  9662.         switch (net) {
  9663.           case NET_TCPA:
  9664.           case NET_TCPB:
  9665.         cxtype = CXT_TCPIP;
  9666. #ifdef COMMENT
  9667. /* This works but it messes up interactive anonymous login */
  9668. #ifndef NOXFER
  9669. #ifdef IKS_OPTION
  9670.         /* If we have connected to an Internet Kermit service */
  9671.         /* and a /USER: switch was given, then log in. */
  9672.  
  9673.         if (TELOPT_U(TELOPT_KERMIT) || TELOPT_ME(TELOPT_KERMIT)) {
  9674.             debug(F111,"cx_net IKSD /USER:",uidbuf,haveuser);
  9675.             if (haveuser /* && cx == 0 */ ) { /* /USER: given */
  9676.             char * psw = pwbuf; /* Do we have a password? */
  9677.             if (!*psw) {        /* No... */
  9678.                 if (!strcmp(uidbuf,"anonymous") ||
  9679.                 !strcmp(uidbuf,"ftp")) {
  9680.                 extern char myhost[];
  9681.                 char * u = (char *)sl_uidbuf;
  9682.                 char * h = (char *)myhost;
  9683.                 if (!*u) u = "nobody";
  9684.                 if (!*h) h = "nowhere";
  9685.                 ckmakmsg(tmpbuf,TMPBUFSIZ,u,"@",h,NULL);
  9686.                 psw = tmpbuf;
  9687.                 debug(F110,"cx_net IKSD anon",psw,0);
  9688.                 } else {
  9689.                 readpass(" Password: ",pwbuf,PWBUFL);
  9690.                 }
  9691.             }
  9692.             sstate = setgen('I',uidbuf,psw,"");
  9693.             }
  9694.         }
  9695. #endif /* IKS_OPTION */
  9696. #endif /* NOXFER */
  9697. #endif /* COMMENT */
  9698.         break;
  9699.           case NET_SSH:
  9700.         cxtype = CXT_SSH;
  9701.         duplex = 0;         /* Remote echo */
  9702.         break;
  9703.           case NET_SLAT:
  9704.         cxtype = CXT_LAT;
  9705.         break;
  9706.           case NET_SX25:
  9707.           case NET_IX25:
  9708.           case NET_HX25:
  9709.           case NET_VX25:
  9710.         cxtype = CXT_X25;
  9711.         break;
  9712.           case NET_BIOS:
  9713.         cxtype = CXT_NETBIOS;
  9714.         break;
  9715.           case NET_FILE:
  9716.           case NET_PIPE:
  9717.           case NET_CMD:
  9718.           case NET_DLL:
  9719.           case NET_PTY:
  9720.         cxtype = CXT_PIPE;
  9721.         break;
  9722.           default:
  9723.         cxtype = CXT_PIPE;
  9724.         break;
  9725.         }
  9726.         break;
  9727.     }
  9728.     } /* for-loop */
  9729.     s = line;
  9730.  
  9731.     debug(F101,"cx_net post ttopen success","",success);
  9732.     if (!success) {
  9733.         local = dfloc;                  /* Go back to normal */
  9734. #ifndef MAC
  9735.         ckstrncpy(ttname,dftty,TTNAMLEN); /* Restore default tty name */
  9736. #endif /* MAC */
  9737.         speed = ttgspd();
  9738.         network = 0;                    /* No network connection active */
  9739.         haveline = 0;
  9740.         if (mdmtyp < 0) {               /* Switching from net to async? */
  9741.             if (mdmsav > -1)            /* Restore modem type from last */
  9742.               mdmtyp = mdmsav;          /* SET MODEM command, if any. */
  9743.             else
  9744.               mdmtyp = 0;
  9745.             mdmsav = -1;
  9746.         }
  9747.         return(0);                      /* Return failure */
  9748.     }
  9749.     if (_local > -1) local = _local;    /* Opened ok, set local/remote. */
  9750.     makestr(&slmsg,NULL);
  9751.     network = (mdmtyp < 0);             /* Remember connection type. */
  9752.     ckstrncpy(ttname,s,TTNAMLEN);       /* Copy name into real place. */
  9753.     debug(F110,"cx_net ok",ttname,0);
  9754.     debug(F101,"cx_net network","",network);
  9755. #ifndef NOXFER
  9756.     if ((reliable != SET_OFF || !setreliable)) /* Assume not reliable. */
  9757.       reliable = SET_OFF;
  9758. #endif /* NOXFER */
  9759.     if (!network || istncomport())    
  9760.       speed = ttgspd();                 /* Get the current speed. */
  9761.     debug(F101,"cx_net local","",local);
  9762.     if (network) {
  9763.         debug(F101,"cx_net net","",net);
  9764. #ifndef NOXFER
  9765.         /* Force prefixing of 255 on TCP/IP connections... */
  9766.         if (net == NET_TCPB
  9767. #ifdef SSHBUILTIN
  9768.              || net == NET_SSH
  9769. #endif /* SSHBUILTIN */
  9770.              ) {
  9771.             debug(F101,"cx_net reliable A","",reliable);
  9772. #ifdef CK_SPEED
  9773.             ctlp[(unsigned)255] = 1;
  9774. #endif /* CK_SPEED */
  9775.             if ((reliable != SET_OFF || !setreliable)) {
  9776. #ifdef TN_COMPORT
  9777.                 if (istncomport()) {    /* Telnet communication port */
  9778.                     reliable = SET_OFF; /* Transport is not reliable */
  9779.                     debug(F101,"cx_net reliable istncomport()","",1);
  9780.                 } else {
  9781.                     reliable = SET_ON;  /* Transport is reliable end to end */
  9782.                     debug(F101,"cx_net reliable istncomport()","",0);
  9783.                 }
  9784. #else
  9785.                 reliable = SET_ON;      /* Transport is reliable end to end */
  9786. #endif /* ifdef TN_COMPORT */
  9787.             }
  9788.             debug(F101,"cx_net reliable B","",reliable);
  9789.         } else if (net == NET_SX25 ||
  9790.                    net == NET_VX25 ||
  9791.                    net == NET_IX25 ||
  9792.                    net == NET_HX25) {
  9793.             duplex = 1;                 /* Local echo for X.25 */
  9794.             if (reliable != SET_OFF || !setreliable)
  9795.               reliable = SET_ON;        /* Transport is reliable end to end */
  9796.         }
  9797. #endif /* NOXFER */
  9798.     }
  9799. #ifndef NOXFER
  9800.     debug(F101,"cx_net reliable","",reliable);
  9801. #endif /* NOXFER */
  9802. #ifdef OS2
  9803.     if (mdmtyp <= 0)                    /* Network or Direct Connection */
  9804.       DialerSend(OPT_KERMIT_CONNECT, 0);
  9805. #endif /* OS2 */
  9806.  
  9807.   xcx_net:
  9808.  
  9809.     setflow();                          /* Set appropriate flow control */
  9810.  
  9811.     haveline = 1;
  9812. #ifdef CKLOGDIAL
  9813.     dolognet();
  9814. #endif /* CKLOGDIAL */
  9815.  
  9816. #ifndef NOSPL
  9817.     if (local) {
  9818.         if (nmac) {                     /* Any macros defined? */
  9819.             int k;                      /* Yes */
  9820.             k = mlook(mactab,"on_open",nmac);   /* Look this up */
  9821.             if (k >= 0) {                       /* If found, */
  9822.                 if (dodo(k,ttname,0) > -1)      /* set it up, */
  9823.                   parser(1);                    /* and execute it */
  9824.             }
  9825.         }
  9826.     }
  9827. #endif /* NOSPL */
  9828.  
  9829.     if (local && (cx || sx)) {          /* /CONNECT or /SERVER switch given */
  9830.         if (cx) {                       /* /CONNECT */
  9831.         if (!gui) {
  9832.         /* Command was confirmed so we can pre-pop command level.  */
  9833.         /* This is so CONNECT module won't think we're executing a */
  9834.         /* script if CONNECT was the final command in the script.  */
  9835.         if (cmdlvl > 0)
  9836.           prepop();
  9837.         }
  9838. #ifndef NODIAL
  9839.             dialsta = DIA_UNK;
  9840. #endif /* NODIAL */
  9841. #ifdef LOCUS
  9842.             if (autolocus) {
  9843.         setlocus(1,1);
  9844.             }
  9845. #endif /* LOCUS */
  9846.             success = doconect(0, cmdlvl == 0 ? 1 : 0);
  9847.             if (ttchk() < 0)
  9848.               dologend();
  9849.         debug(F101,"cx_net post doconect success","",success);
  9850.             return(success);
  9851. #ifndef NOXFER
  9852.         } else if (sx) {                /* /SERVER */
  9853.             sstate = 'x';
  9854. #ifdef MAC
  9855.             what = W_RECV;
  9856.             scrcreate();
  9857. #endif /* MAC */
  9858.             if (local) displa = 1;
  9859. #ifdef AMIGA
  9860.             reqoff();                   /* No DOS requestors while server */
  9861. #endif /* AMIGA */
  9862. #endif /* NOXFER */
  9863.         }
  9864.     }
  9865. #ifndef NODIAL
  9866.     dialsta = DIA_UNK;
  9867. #endif /* NODIAL */
  9868. #ifdef LOCUS
  9869.     if (autolocus) {
  9870.         setlocus(1,1);
  9871.     }
  9872. #endif /* LOCUS */
  9873.     return(success = 1);
  9874. }
  9875. #endif /* NETCONN */
  9876.  
  9877. /* c x _ s e r i a l  --  Make a serial connection */
  9878.  
  9879. /*
  9880.   Call with:
  9881.     device  = string pointer to device name.
  9882.     cx      = 1 to automatically enter Connect mode, 0 otherwise.
  9883.     sx      = 1 to automatically enter Server mode, 0 otherwise.
  9884.     shr     = 1 if device should be opened in shareable mode, 0 otherwise.
  9885.     flag    = if no dev name given: 1 = close current connection, 0 = resume.
  9886.     gui     = 1 if called from GUI dialog, 0 otherwise.
  9887.   Returns:
  9888.     1 on success
  9889.     0 on failure and no message printed, slmsg set to failure message.
  9890.    -9 on failure and message printed, ditto.
  9891. */
  9892.  
  9893. /* these are bit flags */
  9894. #define CX_TAPI 1
  9895. #define CX_PPP  2
  9896. #define CX_SLIP 4
  9897.  
  9898. int
  9899. #ifdef CK_ANSIC
  9900. cx_serial(char *device, 
  9901.           int cx, int sx, int shr, int flag, int gui, int special)
  9902. #else /* CK_ANSIC */
  9903. cx_serial(device, cx, sx, shr, flag, gui, special)
  9904.     char * device; int cx, sx, shr, flag, gui, special; 
  9905. #endif /* CK_ANSIC */
  9906. /* cx_serial */ {
  9907.     int i, n, x, y, msg;
  9908.     int _local = -1;
  9909.     char *s;
  9910.  
  9911.     debug(F110,"cx_serial device",device,0);
  9912.     s = device;
  9913.     msg = (gui == 0) && msgflg;        /* Whether to print messages */
  9914.     success = 0;
  9915.  
  9916. #ifndef NODIAL
  9917.     dialsta = DIA_UNK;
  9918. #endif /* NODIAL */
  9919.     debug(F101,"cx_serial mdmtyp","",mdmtyp);
  9920.     if (clskconnx(1) < 0)        /* Close the Kermit connection */
  9921.       return(success = 0);
  9922.     if (*s) {                /* They gave a device name */
  9923.     _local = -1;            /* Let ttopen decide about it */
  9924.     } else {                /* They just said "set line" */
  9925.     s = dftty;            /* so go back to normal tty */
  9926.     _local = dfloc;            /* and mode. */
  9927.     }
  9928. #ifdef VMS
  9929.     {
  9930.     extern int ok_to_share;
  9931.     ok_to_share = shr;
  9932.     }
  9933. #endif /* VMS */
  9934.  
  9935. #ifdef OS2                              /* Must wait until after ttclos() */
  9936. #ifdef NT                               /* to change these settings       */
  9937. #ifdef CK_TAPI
  9938.     tttapi = special & CX_TAPI;
  9939. #endif /* CK_TAPI */
  9940. #else
  9941.     ttslip = special & CX_SLIP;
  9942.     ttppp  = special & CX_PPP;
  9943. #endif /* NT */
  9944.     ttshare = shr;            /* Shareable device ? */
  9945.     debug(F110,"OS2 SET PORT final s",s,"");
  9946. #endif /* OS2 */
  9947.  
  9948.     /* Open the new line */        
  9949.  
  9950.     ckstrncpy(ttname,s,TTNAMLEN);
  9951.     if ((y = ttopen(s,&_local,mdmtyp,cdtimo)) > -1) {
  9952.     cxtype = (mdmtyp > 0) ? CXT_MODEM : CXT_DIRECT;
  9953. #ifndef NODIAL
  9954.     dialsta = DIA_UNK;
  9955. #ifdef CK_TAPI
  9956.     /* if the line is a tapi device, then we need to auto-execute */
  9957.     /* SET MODEM TYPE TAPI - which we do the equivalent of here.  */
  9958.     if (tttapi) {
  9959.         extern int usermdm;
  9960.         usermdm = 0;
  9961.         initmdm(38);        /* From ckudia.c n_TAPI == 38 */
  9962.     }
  9963. #endif /* CK_TAPI */
  9964. #endif /* NODIAL */
  9965.     success = 1;
  9966.     } else {                /* Failed */
  9967. #ifdef OS2ONLY
  9968.     if (!strcmp(s,dftty))   /* Do not generate an error with dftty */
  9969.       ;
  9970.     else if (y == -6 && ttslip) {
  9971.         makestr(&slmsg,"Can't access SLIP driver");
  9972.         if (msg) printf("?%s\n",slmsg);
  9973.     } else if (y == -6 && ttppp) {
  9974.         makestr(&slmsg,"Can't access PPP driver");
  9975.         if (msg) printf("?%s\n",slmsg);
  9976.     } else
  9977. #endif /* OS2ONLY */
  9978.       if (y == -2) {
  9979.           makestr(&slmsg,"Timed out - no carrier");
  9980.           if (msg) {
  9981.           printf("?%s\n",slmsg);
  9982.           if (hints) {
  9983.               printf("\n*************************\n");
  9984.               printf(
  9985.                "HINT (Use SET HINTS OFF to suppress future hints):\n");
  9986.               printf(
  9987.               "Try SET CARRIER OFF and SET LINE again, or else\n");
  9988.               printf("SET MODEM, SET LINE, and then DIAL.\n");
  9989.               printf("*************************\n\n");
  9990.           }
  9991.           }
  9992.       } else if (y == -3) {
  9993.           makestr(&slmsg,"Access to lock denied");
  9994.           if (msg) {
  9995. #ifdef UNIX
  9996.           printf(
  9997.            "Sorry, write access to UUCP lockfile directory denied.\n");
  9998. #ifndef NOHINTS
  9999.           if (hints) {
  10000.               printf("\n*************************\n");
  10001.               printf(
  10002.                "HINT (Use SET HINTS OFF to suppress future hints):\n");
  10003.               printf(
  10004.       "Please read the installation instructions file, %sckuins.txt,\n",
  10005.                          k_info_dir ? k_info_dir : ""
  10006.                              );
  10007.               printf(
  10008.       "or the UNIX appendix of the manual, \"Using C-Kermit\"\n"
  10009.                              );
  10010.               printf(
  10011.           "or visit http://www.columbia.edu/kermit/ckuins.html \n"
  10012.                              );
  10013.               printf("*************************\n\n");
  10014.           }
  10015. #endif /* NOHINTS */
  10016. #else
  10017.           printf("Sorry, access to lock denied: %s\n",s);
  10018. #endif /* UNIX */
  10019.           }
  10020.       } else if (y == -4) {
  10021.           makestr(&slmsg,"Access to device denied");
  10022.           if (msg) {
  10023.           printf("Sorry, access to device denied: %s\n",s);
  10024. #ifdef UNIX
  10025. #ifndef NOHINTS
  10026.           if (hints) {
  10027.               printf("\n*************************\n");
  10028.               printf(
  10029.               "HINT (Use SET HINTS OFF to suppress future hints):\n");
  10030.               printf(
  10031.         "Please read the installation instructions file, %sckuins.txt,\n",
  10032.                              k_info_dir ? k_info_dir : ""
  10033.                              );
  10034.               printf(
  10035.         "or the UNIX appendix of the manual, \"Using C-Kermit\".\n"
  10036.                              );
  10037.               printf("*************************\n\n");
  10038.           }
  10039. #endif /* NOHINTS */
  10040. #endif /* UNIX */
  10041.           }
  10042.       } else if (y == -5) {
  10043.           makestr(&slmsg,"Device is in use or unavailable");
  10044.           if (msg)
  10045. #ifdef VMS
  10046.         printf(
  10047.           "Sorry, device is in use or otherwise unavailable: %s\n",s);
  10048. #else
  10049.           printf("Sorry, device is in use: %s\n",s);
  10050. #endif /* VMS */
  10051.       } else {            /* Other error. */
  10052.           makestr(&slmsg,"Device open failed");
  10053.           if (
  10054. #ifdef VMS
  10055.           1
  10056. #else
  10057.           errno
  10058. #endif /* VMS */
  10059.           ) {
  10060.           int x;        /* Find a safe, long buffer */
  10061.           makestr(&slmsg,ck_errstr());
  10062. #ifndef VMS
  10063.           debug(F111,"cx_serial serial errno",slmsg,errno);
  10064. #endif /* VMS */
  10065.           if (msg)
  10066.             printf("Connection to %s failed: %s\n",s,slmsg);
  10067.           } else if (msg)
  10068.         printf("Sorry, can't open connection: %s\n",s);
  10069.       }
  10070.     }
  10071.     network = 0;            /* No network connection active */
  10072.     speed = ttgspd();
  10073.     if (!success) {
  10074.         local = dfloc;                  /* Go back to normal */
  10075. #ifndef MAC
  10076.         ckstrncpy(ttname,dftty,TTNAMLEN); /* Restore default tty name */
  10077. #endif /* MAC */
  10078.         haveline = 0;
  10079.         if (mdmtyp < 0) {               /* Switching from net to async? */
  10080.             if (mdmsav > -1)            /* Restore modem type from last */
  10081.               mdmtyp = mdmsav;          /* SET MODEM command, if any. */
  10082.             else
  10083.               mdmtyp = 0;
  10084.             mdmsav = -1;
  10085.         }
  10086.         return(msg ? -9 : 0);        /* Return failure */
  10087.     }
  10088.     if (_local > -1)
  10089.       local = _local;            /* Opened ok, set local/remote. */
  10090.     makestr(&slmsg,NULL);        /* Erase SET LINE message */
  10091.     ckstrncpy(ttname,s,TTNAMLEN);       /* Copy name into real place. */
  10092.     debug(F110,"cx_serial ok",ttname,0);
  10093. #ifndef NOXFER
  10094.     if ((reliable != SET_OFF || !setreliable)) /* Assume not reliable. */
  10095.       reliable = SET_OFF;
  10096. #endif /* NOXFER */
  10097.  
  10098.   xcx_serial:
  10099.     setflow();                          /* Set appropriate flow control */
  10100.     haveline = 1;
  10101. #ifdef CKLOGDIAL
  10102.       dologline();
  10103. #endif /* CKLOGDIAL */
  10104.  
  10105. #ifndef NOSPL
  10106.     if (local) {
  10107.         if (nmac) {                     /* Any macros defined? */
  10108.             int k;                      /* Yes */
  10109.             k = mlook(mactab,"on_open",nmac);   /* Look this up */
  10110.             if (k >= 0) {                       /* If found, */
  10111.                 if (dodo(k,ttname,0) > -1)      /* set it up, */
  10112.                   parser(1);                    /* and execute it */
  10113.             }
  10114.         }
  10115.     }
  10116. #endif /* NOSPL */
  10117.  
  10118.     if (local && (cx || sx)) {          /* /CONNECT or /SERVER switch given */
  10119.         extern int carrier;
  10120.         if (carrier != CAR_OFF) {    /* Looking for carrier? */
  10121.             /* Open() turns on DTR -- wait up to a second for CD to come up */
  10122.             int i, x;
  10123.             for (i = 0; i < 10; i++) {  /* WAIT 1 CD... */
  10124.                 x = ttgmdm();
  10125.                 if (x < 0 || x & BM_DCD)
  10126.                   break;
  10127.                 msleep(100);
  10128.             }
  10129.         }
  10130.         if (cx) {                       /* /CONNECT */
  10131.             /* Command was confirmed so we can pre-pop command level. */
  10132.             /* This is so CONNECT module won't think we're executing a */
  10133.             /* script if CONNECT was the final command in the script. */
  10134.  
  10135.             if (cmdlvl > 0)
  10136.               prepop();
  10137. #ifndef NODIAL
  10138.             dialsta = DIA_UNK;
  10139. #endif /* NODIAL */
  10140. #ifdef LOCUS
  10141.             if (autolocus) {
  10142.                 setlocus(1,1);
  10143.             }
  10144. #endif /* LOCUS */
  10145.             success = doconect(0, cmdlvl == 0 ? 1 : 0);
  10146.             if (ttchk() < 0)
  10147.               dologend();
  10148.             return(success);
  10149. #ifndef NOXFER
  10150.         } else if (sx) {                /* /SERVER */
  10151.             sstate = 'x';
  10152. #ifdef MAC
  10153.             what = W_RECV;
  10154.             scrcreate();
  10155. #endif /* MAC */
  10156.             if (local) displa = 1;
  10157. #ifdef AMIGA
  10158.             reqoff();                   /* No DOS requestors while server */
  10159. #endif /* AMIGA */
  10160. #endif /* NOXFER */
  10161.         }
  10162.     }
  10163. #ifndef NODIAL
  10164.     dialsta = DIA_UNK;
  10165. #endif /* NODIAL */
  10166. #ifdef LOCUS
  10167.     if (autolocus) {
  10168.         setlocus(1,1);
  10169.     }
  10170. #endif /* LOCUS */
  10171.     return(success = 1);
  10172. }
  10173.  
  10174.  
  10175. /* S E T L I N -- parse name of and then open communication device. */
  10176. /*
  10177.   Call with:
  10178.     xx == XYLINE for a serial (tty) line, XYHOST for a network host,
  10179.     zz == 0 means if user doesn't give a device name, continue current
  10180.             active connection (if any);
  10181.     zz != 0 means if user doesn't give a device name, then close the
  10182.             current connection and restore the default communication device.
  10183.     fc == 0 to just make the connection, 1 to also CONNECT (e.g. "telnet").
  10184. */
  10185. int
  10186. setlin(xx, zz, fc) 
  10187.     int xx, zz, fc; 
  10188. {
  10189.     extern char pwbuf[], * g_pswd;
  10190.     extern int pwflg, pwcrypt, g_pflg, g_pcpt, nolocal;
  10191.     int wait;
  10192.     /* int tn_wait_sv; */
  10193.     int mynet;
  10194.     int _local = -1;
  10195.     int c, i, haveswitch = 0;
  10196.     int haveuser = 0;
  10197.     int getval = 0;
  10198.     int wild = 0;                       /* Filespec has wildcards */
  10199.     int cx = 0;                         /* Connect after */
  10200.     int sx = 0;                         /* Become server after */
  10201.     int a_type = -1;                    /* Authentication type */
  10202.     int e_type = -1;                    /* Telnet /ENCRYPT type */
  10203. #ifdef CK_ENCRYPTION
  10204.     int encrypt = 0;                    /* Encrypted? */
  10205. #endif /* CK_ENCRYPTION */
  10206.     int shr = 0;                        /* Share serial device */
  10207.     int confirmed = 0;                  /* Command has been entered */
  10208.     struct FDB sw, tx, nx;
  10209. #ifdef OS2
  10210.     struct FDB fl;
  10211. #endif /* OS2 */
  10212.  
  10213.     char * ss;
  10214. #ifdef TCPSOCKET
  10215.     int rawflg = 0;
  10216. #endif /* TCPSOCKET */
  10217.  
  10218.     char srvbuf[SRVBUFSIZ+1];
  10219.  
  10220. #ifdef OS2
  10221. #ifdef NT
  10222.     int xxtapi = 0;
  10223. #else
  10224.     int xxslip = 0, xxppp = 0;
  10225. #endif /* NT */
  10226. #endif /* OS2 */
  10227.  
  10228.     int dossh = 0;
  10229.  
  10230.     debug(F101,"setlin fc","",fc);
  10231.     debug(F101,"setlin zz","",zz);
  10232.     debug(F101,"setlin xx","",xx);
  10233.  
  10234. #ifdef SSHCMD
  10235.     if (xx == XXSSH) {                  /* SSH becomes PTY SSH ... */
  10236.         dossh = 1;
  10237.         xx = XYHOST;
  10238.     }
  10239. #endif /* SSHCMD */
  10240.  
  10241. #ifdef TNCODE
  10242.     /* tn_wait_sv = tn_wait_flg; */
  10243.     wait = tn_wait_flg;
  10244. #else
  10245.     /* tn_wait_sv = 0; */
  10246.     wait = 0;
  10247. #endif /* TNCODE */
  10248.  
  10249.     mynet = nettype;
  10250.  
  10251.     if (nolocal) {
  10252.         makestr(&slmsg,"Making connections is disabled");
  10253.         printf("?Sorry, making connections is disabled\n");
  10254.         return(-9);
  10255.     }
  10256.     if (netsave > -1)
  10257.       nettype = netsave;
  10258.  
  10259.     if (fc != 0 || zz == 0)             /* Preset /CONNECT switch */
  10260.       cx = 1;
  10261.  
  10262.     debug(F101,"setlin cx","",cx);
  10263.  
  10264.     *srvbuf = NUL;
  10265.  
  10266.     line[0] = NUL;
  10267.     s = line;
  10268.  
  10269. #ifdef NETCONN
  10270. #ifdef CK_SECURITY
  10271.     if (tmpstring)
  10272.         makestr(&tmpstring,NULL);
  10273. #endif /* CK_SECURITY */
  10274.     if (tmpusrid)
  10275.         makestr(&tmpusrid,NULL);
  10276. #endif /* NETCONN */
  10277.  
  10278.     autoflow = 1;                       /* Enable automatic flow setting */
  10279.  
  10280.     if (xx == XYHOST) {                 /* SET HOST <hostname> */
  10281. #ifndef NETCONN
  10282.         makestr(&slmsg,"Network connections not supported");
  10283.         printf("?%s\n",slmsg);
  10284.         return(-9);
  10285. #else /* NETCONN */
  10286. #ifndef NOPUSH
  10287.         if ((mynet == NET_CMD || mynet == NET_PTY || dossh) && nopush) {
  10288.             makestr(&slmsg,"Access to external commands is disabled");
  10289.             printf("?Sorry, access to external commands is disabled\n");
  10290.             return(-9);
  10291.         }
  10292. #endif /* NOPUSH */
  10293.  
  10294. #ifdef SSHCMD
  10295.         if (dossh) {                    /* SSH connection via pty */
  10296.             int k;
  10297.             k = ckstrncpy(line, sshcmd ? sshcmd : defsshcmd, LINBUFSIZ);
  10298.             debug(F111,"setlin sshcmd 1",line,k);
  10299.             if ((x = cmtxt("Optional switches and hostname","",&s,xxstring))<0)
  10300.               return(x);
  10301.             if (!*s) {
  10302.                 printf("?SSH to where?\n");
  10303.                 return(-9);
  10304.             }
  10305.             if (k < LINBUFSIZ) {
  10306.                 line[k++] = SP;
  10307.                 line[k] = NUL;
  10308.                 debug(F111,"setlin sshcmd 2",line,k);
  10309.             } if (k < LINBUFSIZ) {
  10310.                 ckstrncpy(&line[k],s,LINBUFSIZ-k);
  10311.                 debug(F111,"setlin sshcmd 3",line,k);
  10312.             } else {
  10313.                 printf("?Too long\n");
  10314.                 return(-9);
  10315.             }
  10316.         x = cx_net( NET_PTY,                /* network type */
  10317.                         0,                      /* protocol (not used) */
  10318.                         line,                   /* host */
  10319.                         NULL,                   /* service (not used) */
  10320.                         NULL,                   /* username (not used) */
  10321.                         NULL,                   /* password (not used) */
  10322.                         NULL,                   /* command (not used) */
  10323.                         -1,-1,-1,               /* params 1-3 (not used) */
  10324.                         1,                      /* connect immediately */
  10325.                         sx,                     /* server? */
  10326.                         zz,                     /* close current? */
  10327.                         0);                     /* not gui */
  10328.         debug(F111,"setlin cx_net",line,x);
  10329.         return(x);
  10330.         }
  10331. #endif /* SSHCMD */
  10332.  
  10333. /*
  10334.   Here we parse optional switches and then the hostname or whatever,
  10335.   which depends on the network type.  The tricky part is, the network type
  10336.   can be set by a switch.
  10337. */
  10338. #ifndef NOSPL
  10339.         makestr(&g_pswd,pwbuf);         /* Save global pwbuf */
  10340.         g_pflg = pwflg;                 /* and flag */
  10341.         g_pcpt = pwcrypt;
  10342. #endif /* NOSPL */
  10343.  
  10344.         confirmed = 0;
  10345.         haveswitch = 0;
  10346. #ifdef NETFILE
  10347.         if (mynet != NET_FILE) {
  10348. #endif /* NETFILE */
  10349.             ss = (mynet == NET_CMD || mynet == NET_PTY) ?
  10350.               "Command, or switch" :
  10351.                 (mynet == NET_TCPA || mynet == NET_TCPB
  10352.                   || mynet == NET_SSH) ?
  10353.                   "Hostname, ip-address, or switch" :
  10354.                     "Host or switch";
  10355.             if (fc) {
  10356.                 if (mynet == NET_TCPB &&
  10357.                     (ttnproto == NP_TELNET || ttnproto == NP_KERMIT)) {
  10358.                     if (nshteltab) {
  10359.                         haveswitch++;
  10360.                         cmfdbi(&sw,_CMKEY,ss,"","",nshteltab,4,xxstring,
  10361.                              shteltab,&nx);
  10362.                     }
  10363.                 }
  10364. #ifdef RLOGCODE
  10365.                 else if (mynet == NET_TCPB && ttnproto == NP_RLOGIN) {
  10366.                     if (nshrlgtab) {
  10367.                         haveswitch++;
  10368.                         cmfdbi(&sw,_CMKEY,ss,"","",nshrlgtab,4,xxstring,
  10369.                                shrlgtab,&nx);
  10370.                     }
  10371.                 }
  10372. #endif /* RLOGCODE */
  10373.             } else {
  10374.                 haveswitch++;
  10375.                 cmfdbi(&sw,_CMKEY,ss,"","",nshtab,4,xxstring,shtab,&nx);
  10376.             }
  10377. #ifdef NETFILE
  10378.         }
  10379. #endif /* NETFILE */
  10380.         if (mynet == NET_TCPB || mynet == NET_SLAT ||
  10381.         mynet == NET_SSH  || mynet == NET_DEC) {
  10382.             cmfdbi(&nx,_CMFLD,"Host","","",0,0,xxstring,NULL,NULL);
  10383. #ifdef NETFILE
  10384.         } else if (mynet == NET_FILE) {
  10385.             cmfdbi(&nx,_CMIFI,"Filename","","",0,0,xxstring,NULL,NULL);
  10386. #endif /* NETFILE */
  10387. #ifdef PTYORPIPE
  10388.         } else if (mynet == NET_CMD || mynet == NET_PTY) {
  10389.             cmfdbi(&nx,_CMTXT,"Command","","",0,0,xxstring,NULL,NULL);
  10390. #endif /* PTYORPIPE */
  10391.         } else {
  10392.             cmfdbi(&nx,_CMTXT,"Host","","",0,0,xxstring,NULL,NULL);
  10393.         }
  10394.         while (1) {
  10395.             x = cmfdb(haveswitch ? &sw : &nx);
  10396.             debug(F101,"setlin cmfdb","",x);
  10397.             if (x < 0)
  10398.               if (x != -3)
  10399.                 return(x);
  10400.             if (x == -3) {
  10401.                 if ((x = cmcfm()) < 0) {
  10402.                     return(x);
  10403.                 } else {
  10404.                     confirmed = 1;
  10405.                     break;
  10406.                 }
  10407.             }
  10408.             if (cmresult.fcode != _CMKEY) {    /* Not a switch */
  10409.                 ckstrncpy(line,cmresult.sresult,LINBUFSIZ); /* Save the data */
  10410.                 s = line;                      /* that was parsed... */
  10411.                 if (cmresult.fcode == _CMIFI) {
  10412.                     wild = cmresult.nresult;
  10413.                 } else if (cmresult.fcode == _CMTXT) {
  10414.                     confirmed = 1;
  10415.                 }
  10416.                 break;                  /* and break out of this loop */
  10417.             }
  10418.             c = cmgbrk();               /* Have switch - get break character */
  10419.             getval = (c == ':' || c == '='); /* Must parse an agument? */
  10420.             if (getval && !(cmresult.kflags & CM_ARG)) {
  10421.                 printf("?This switch does not take arguments\n");
  10422.                 return(-9);
  10423.             }
  10424.             if (!getval && (cmgkwflgs() & CM_ARG)) {
  10425.                 printf("?This switch requires an argument\n");
  10426.                 return(-9);
  10427.             }
  10428.             switch (cmresult.nresult) { /* It's a switch.. */
  10429.               case SL_CNX:              /* /CONNECT */
  10430.                 cx = 1;
  10431.                 sx = 0;
  10432.                 break;
  10433.               case SL_SRV:              /* /SERVER */
  10434.                 cx = 0;
  10435.                 sx = 1;
  10436.                 break;
  10437. #ifdef NETCMD
  10438.               case SL_CMD:              /* /COMMAND */
  10439.                 netsave = mynet;
  10440.                 mynet = NET_CMD;
  10441.                 break;
  10442. #endif /* NETCMD */
  10443. #ifdef NETPTY
  10444.               case SL_PTY:              /* /PTY */
  10445.                 netsave = mynet;
  10446.                 mynet = NET_PTY;
  10447.                 break;
  10448. #endif /* NETPTY */
  10449.               case SL_NET:              /* /NETWORK-TYPE */
  10450.                 if ((x = cmkey(netcmd,nnets,"","",xxstring)) < 0)
  10451.                   return(x);
  10452.                 mynet = x;
  10453.                 break;
  10454.  
  10455. #ifdef CK_SECURITY
  10456.               case SL_PSW:              /* /PASSWORD: */
  10457.                 if (!getval)
  10458.                   break;
  10459.                 debok = 0;
  10460.                 if ((x = cmfld("Password","",&s,xxstring)) < 0) {
  10461.                     if (x == -3) {
  10462.                         makestr(&tmpstring,"");
  10463.                     } else {
  10464.                         return(x);
  10465.                     }
  10466.                 } else {
  10467.                     s = brstrip(s);
  10468.                     if ((x = (int)strlen(s)) > PWBUFL) {
  10469.                         makestr(&slmsg,"Internal error");
  10470.                         printf("?Sorry, too long - max = %d\n",PWBUFL);
  10471.                         return(-9);
  10472.                     }
  10473.                     makestr(&tmpstring,s);
  10474.                 }
  10475.                 break;
  10476. #endif /* CK_SECURITY */
  10477.  
  10478.               case SL_UID:              /* /USERID: */
  10479.                 if (!getval)
  10480.                   break;
  10481.                 if ((x = cmfld("Userid","",&s,xxstring)) < 0) {
  10482.                     if (x == -3) {
  10483.                         makestr(&tmpusrid,"");
  10484.                     } else {
  10485.                         return(x);
  10486.                     }
  10487.                 } else {
  10488.                     s = brstrip(s);
  10489.                     if ((x = (int)strlen(s)) > 63) {
  10490.                         makestr(&slmsg,"Internal error");
  10491.                         printf("?Sorry, too long - max = %d\n",63);
  10492.                         return(-9);
  10493.                     }
  10494.                     makestr(&tmpusrid,s);
  10495.                     haveuser = 1;
  10496.                 }
  10497.                 break;
  10498.  
  10499. #ifdef CK_AUTHENTICATION
  10500. #ifdef CK_SRP
  10501.               case SL_SRP:
  10502.                 a_type = AUTHTYPE_SRP;
  10503.                 break;
  10504. #endif /* CK_SRP */
  10505. #ifdef CK_SSL
  10506.               case SL_SSL:
  10507.                 a_type = AUTHTYPE_SSL;
  10508.                 break;
  10509. #endif /* CK_SSL */
  10510. #ifdef NT
  10511.               case SL_NTLM:
  10512.                 a_type = AUTHTYPE_NTLM;
  10513.                 break;
  10514. #endif /* NT */
  10515. #ifdef CK_KERBEROS
  10516.               case SL_KRB4:
  10517.                 a_type = AUTHTYPE_KERBEROS_V4;
  10518.                 if (ttnproto == NP_RLOGIN)
  10519.                   ttnproto =
  10520. #ifdef CK_ENCRYPTION
  10521.                     encrypt ? NP_EK4LOGIN :
  10522. #endif /* CK_ENCRYPTION */
  10523.                       NP_K4LOGIN;
  10524.                 else if (ttnproto == NP_K5LOGIN)
  10525.                   ttnproto = NP_K4LOGIN;
  10526. #ifdef CK_ENCRYPTION
  10527.                 else if (ttnproto == NP_EK5LOGIN)
  10528.                   ttnproto = NP_EK4LOGIN;
  10529. #endif /* CK_ENCRYPTION */
  10530.                 break;
  10531.               case SL_KRB5:
  10532.                 a_type = AUTHTYPE_KERBEROS_V5;
  10533.                 if (ttnproto == NP_RLOGIN)
  10534.                   ttnproto =
  10535. #ifdef CK_ENCRYPTION
  10536.                     encrypt ? NP_EK5LOGIN :
  10537. #endif /* CK_ENCRYPTION */
  10538.                       NP_K5LOGIN;
  10539.                 else if (ttnproto == NP_K4LOGIN)
  10540.                   ttnproto = NP_K5LOGIN;
  10541. #ifdef CK_ENCRYPTION
  10542.                 else if (ttnproto == NP_EK4LOGIN)
  10543.                   ttnproto = NP_EK5LOGIN;
  10544. #endif /* CK_ENCRYPTION */
  10545.                 break;
  10546. #endif /* CK_KERBEROS */
  10547.               case SL_AUTH: {
  10548.                   extern struct keytab autyptab[];
  10549.                   extern int nautyp;
  10550.                   if ((x = cmkey(autyptab,nautyp,"type of authentication",
  10551.                                  "automatic",xxstring)) < 0)
  10552.                     return(x);
  10553.                   a_type = x;
  10554.                   break;
  10555.               }
  10556. #endif /* CK_AUTHENTICATION */
  10557. #ifdef CK_ENCRYPTION
  10558.               case SL_ENC:
  10559.                 switch (ttnproto) {
  10560.                   case NP_K4LOGIN:
  10561.                     ttnproto = NP_EK4LOGIN;
  10562.                     encrypt = 1;
  10563.                     break;
  10564.                   case NP_K5LOGIN:
  10565.                     ttnproto = NP_EK5LOGIN;
  10566.                     encrypt = 1;
  10567.                     break;
  10568.                   case NP_KERMIT:
  10569.                   case NP_TELNET: {
  10570.                       static struct keytab * tnetbl = NULL;
  10571.                       static int ntnetbl = 0;
  10572.                       x = ck_get_crypt_table(&tnetbl,&ntnetbl);
  10573.                       debug(F101,"ck_get_crypt_table x","",x);
  10574.                       debug(F101,"ck_get_crypt_table n","",ntnetbl);
  10575.                       if (x < 1 || !tnetbl || ntnetbl < 1) /* Didn't get it */
  10576.                         x = 0;
  10577.                       if (!x) {
  10578.                           makestr(&slmsg,"Internal error");
  10579.                           printf("?Oops, types not loaded\n");
  10580.                           return(-9);
  10581.                       }
  10582.                       if ((x = cmkey(tnetbl,ntnetbl,"type of encryption",
  10583.                                      "automatic",xxstring)) < 0)
  10584.                         return(x);
  10585.                       e_type = x;
  10586.                       break;
  10587.                   }
  10588.                 }
  10589.                 break;
  10590. #endif /* CK_ENCRYPTION */
  10591.               case SL_WAIT:
  10592.                 wait = 1;
  10593.                 break;
  10594.               case SL_NOWAIT:
  10595.                 wait = 0;
  10596.                 break;
  10597.             }
  10598.         }
  10599.  
  10600. #ifdef NETFILE
  10601.         if (mynet == NET_FILE) {        /* Parsed by cmifi() */
  10602.         if ((x = cmcfm()) < 0)    /* Needs confirmation */
  10603.           return(x);
  10604.         x = cx_net(mynet,        /* nettype */
  10605.                0,        /* protocol (not used) */
  10606.                line,        /* host */
  10607.                "",        /* port */
  10608.                NULL,        /* alternate username */
  10609.                NULL,        /* password */
  10610.                NULL,        /* command to execute */
  10611.                0,        /* param1 */
  10612.                0,        /* param2 */
  10613.                0,        /* param3 */
  10614.                cx,        /* enter CONNECT mode */
  10615.                sx,        /* enter SERVER mode */
  10616.                zz,        /* close connection if open */
  10617.                0        /* gui */
  10618.                );
  10619.         }
  10620. #endif /* NETFILE */
  10621.  
  10622. #ifdef NETCMD
  10623.         if (mynet == NET_CMD || mynet == NET_PTY) {
  10624.             char *p = NULL;
  10625.             if (!confirmed) {
  10626.                 if ((x = cmtxt("Rest of command","",&s,xxstring)) < 0)
  10627.                   return(x);
  10628.                 if (*s) {
  10629.                     ckstrncat(line," ",LINBUFSIZ);
  10630.                     ckstrncat(line,s,LINBUFSIZ);
  10631.                 }
  10632.                 s = line;
  10633.             }
  10634.             /* s == line - so we must protect the line buffer */
  10635.             s = brstrip(s);
  10636.             makestr(&p,s);
  10637.             ckstrncpy(line,p,LINBUFSIZ);
  10638.             makestr(&p,NULL);
  10639.  
  10640.             x = cx_net( mynet,                  /* nettype */
  10641.                         0,                      /* protocol (not used) */
  10642.                         line,                   /* host */
  10643.                         "",                     /* port */
  10644.                         NULL,                   /* alternate username */
  10645.                         NULL,                   /* password */
  10646.                         NULL,                   /* command to execute */
  10647.                         0,                      /* param1 */
  10648.                         0,                      /* param2 */
  10649.                         0,                      /* param3 */
  10650.                         cx,                     /* enter CONNECT mode */
  10651.                         sx,                     /* enter SERVER mode */
  10652.                         zz,                     /* close connection if open */
  10653.                         0                       /* gui */
  10654.                         );
  10655.         }
  10656. #endif /* NETCMD */
  10657.  
  10658. #ifdef NPIPE                            /* Named pipe */
  10659.         if (mynet == NET_PIPE) {        /* Needs backslash twiddling */
  10660.             if (line[0]) {
  10661.                 if (strcmp(line,"*")) {    /* If remote, begin with */
  10662.                     char * p = NULL;
  10663.                     makestr(&p,line);      
  10664.                     ckstrncpy(line,"\\\\",LINBUFSIZ); /* server name */
  10665.                     ckstrncat(line,p,LINBUFSIZ);
  10666.                     makestr(&p,NULL);      
  10667.                 } else {
  10668.                     line[0]='\0';
  10669.                 }
  10670.                 ckstrncat(line,"\\pipe\\", LINBUFSIZ); /* Make pipe name */
  10671.                 ckstrncat(line,pipename, LINBUFSIZ); /* Add name of pipe */
  10672.  
  10673.                 x = cx_net(mynet,    /* nettype */
  10674.                0,        /* protocol (not used) */
  10675.                line,    /* host */
  10676.                "",        /* port */
  10677.                NULL,    /* alternate username */
  10678.                NULL,    /* password */
  10679.                NULL,    /* command to execute */
  10680.                0,        /* param1 */
  10681.                0,        /* param2 */
  10682.                0,        /* param3 */
  10683.                cx,        /* enter CONNECT mode */
  10684.                sx,        /* enter SERVER mode */
  10685.                zz,        /* close connection if open */
  10686.                0        /* gui */
  10687.                );
  10688.             }
  10689.         }
  10690. #endif /* NPIPE */
  10691.  
  10692. #ifdef SUPERLAT
  10693.         if (mynet == NET_SLAT) {        /* Needs password, etc. */
  10694.             slat_pwd[0] = NUL;          /* Erase any previous password */
  10695.             debok = 0;
  10696.             if (*line) {        /* If they gave a host name... */
  10697.                 if ((x = cmfld(
  10698.                      "password,\n or carriage return if no password required",
  10699.                                "",
  10700.                                &s,
  10701.                                xxstring
  10702.                                )) < 0 && x != -3)
  10703.                   return(x);
  10704.                 ckstrncpy(slat_pwd,s,18); /* Set the password, if any */
  10705.             }
  10706.             if ((x = cmcfm()) < 0) return(x); /* Confirm the command */
  10707.  
  10708.             x = cx_net(mynet,        /* nettype */
  10709.                        0,        /* protocol (not used) */
  10710.                        line,        /* host */
  10711.                        "",        /* port */
  10712.                        NULL,        /* alternate username */
  10713.                        NULL,        /* password */
  10714.                        NULL,        /* command to execute */
  10715.                        0,        /* param1 */
  10716.                        0,        /* param2 */
  10717.                        0,        /* param3 */
  10718.                        cx,        /* enter CONNECT mode */
  10719.                        sx,        /* enter SERVER mode */
  10720.                        zz,        /* close connection if open */
  10721.                        0        /* gui */
  10722.                        );
  10723.         }
  10724. #endif /* SUPERLAT */
  10725.  
  10726. #ifdef DECNET
  10727.         if (mynet == NET_DEC) {  
  10728.             if (!line[0]) {                   /* If they gave a host name... */
  10729.                 printf("?hostname required\n");
  10730.                 return(-3);
  10731.             }
  10732.             if ((x = cmcfm()) < 0) return(x); /* Confirm the command */
  10733.  
  10734.             x = cx_net(mynet,        /* nettype */
  10735.                        0,        /* protocol (not used) */
  10736.                        line,        /* host */
  10737.                        "",        /* port */
  10738.                        NULL,        /* alternate username */
  10739.                        NULL,        /* password */
  10740.                        NULL,        /* command to execute */
  10741.                        0,        /* param1 */
  10742.                        0,        /* param2 */
  10743.                        0,        /* param3 */
  10744.                        cx,        /* enter CONNECT mode */
  10745.                        sx,        /* enter SERVER mode */
  10746.                        zz,        /* close connection if open */
  10747.                        0        /* gui */
  10748.                        );
  10749.         }
  10750. #endif /* DECNET */
  10751.  
  10752. #ifdef SSHBUILTIN
  10753.         if (mynet == NET_SSH) {        /* SSH connection */
  10754.             int k, havehost = 0, trips = 0;
  10755.             int    tmpver = -1, tmpxfw = -1, tmpssh_cas;
  10756. #ifndef SSHTEST
  10757.             extern int sl_ssh_xfw, sl_ssh_xfw_saved;
  10758.             extern int sl_ssh_ver, sl_ssh_ver_saved;
  10759. #endif /* SSHTEST */
  10760.             extern struct keytab sshopnsw[];
  10761.             extern int nsshopnsw;
  10762.             extern char *ssh_tmpcmd, *ssh_tmpport;
  10763.             struct FDB sw, kw, fl;
  10764.  
  10765.             debug(F110,"setlin SSH service 0",srvbuf,0);
  10766.             debug(F110,"setlin SSH host s 2",s,0);
  10767.             if (*s) {           /* If they gave a host name... */
  10768.                 debug(F110,"setlin SSH host s 1",s,0);
  10769.                 if (*s == '*') {
  10770.                     makestr(&slmsg,"Incoming connections not supported");
  10771.                     printf(
  10772.      "?Sorry, incoming connections not supported for SSH.\n"
  10773.                            );
  10774.                     return(-9);
  10775.                 }
  10776.                 ckstrncpy(line,s,LINBUFSIZ);
  10777.             } else {
  10778.                 printf("?hostname required\n");
  10779.                 return(-3);
  10780.             }
  10781.  
  10782.             /* Parse [ port ] [ switches ] */
  10783.             cmfdbi(&kw,                 /* Switches */
  10784.                     _CMKEY,
  10785.                     "Port number or service name,\nor switch",
  10786.                     "",
  10787.                     "",
  10788.                     nsshopnsw,
  10789.                     4,
  10790.                     xxstring,
  10791.                     sshopnsw,
  10792.                     &fl
  10793.                     );
  10794.             cmfdbi(&fl,                 /* Port number or service name */
  10795.                     _CMFLD,
  10796.                     "",
  10797.                     "",
  10798.                     "",
  10799.                     0,
  10800.                     0,
  10801.                     xxstring,
  10802.                     NULL,
  10803.                     NULL
  10804.                     );
  10805.             trips = 0;                  /* Explained below */
  10806.             while (1) {                 /* Parse port and switches */
  10807.                 y = cmfdb(&kw);         /* Get a field */
  10808.                 if (y == -3)            /* User typed CR so quit from loop */
  10809.                     break;
  10810.                 if (y < 0)              /* Other parse error, pass it back */
  10811.                     return(y);
  10812.                 switch (cmresult.fcode) { /* Field or Keyword? */
  10813.                 case _CMFLD:              /* Field */
  10814.                     ckstrncpy(srvbuf,cmresult.sresult,SRVBUFSIZ);
  10815.                     break;
  10816.                 case _CMKEY:            /* Keyword */
  10817.                     switch (cmresult.nresult) { /* Which one? */
  10818.                     case SSHSW_PWD:
  10819.                         if (!cmgbrk()) {
  10820.                             printf("?This switch requires an argument\n");
  10821.                             return(-9);
  10822.                         }
  10823.                         debok = 0;
  10824.                         if ((y = cmfld("Password","",&s,xxstring)) < 0) {
  10825.                             if (y == -3) {
  10826.                                 makestr(&tmpstring,"");
  10827.                             } else {
  10828.                                 return(y);
  10829.                             }
  10830.                         } else {
  10831.                             s = brstrip(s);
  10832.                             if ((y = (int)strlen(s)) > PWBUFL) {
  10833.                                 makestr(&slmsg,"Internal error");
  10834.                                 printf("?Sorry, too long - max = %d\n",PWBUFL);
  10835.                                 return(-9);
  10836.                             }
  10837.                             makestr(&tmpstring,s);
  10838.                         }
  10839.                         break;
  10840.                     case SSHSW_USR:             /* /USER: */
  10841.                         if (!cmgbrk()) {
  10842.                             printf("?This switch requires an argument\n");
  10843.                             return(-9);
  10844.                         }
  10845.                         if ((y = cmfld("Username","",&s,xxstring)) < 0)
  10846.                             return(y);
  10847.                         s = brstrip(s);
  10848.                         makestr(&tmpusrid,s);
  10849.                         break;
  10850.                     case SSHSW_VER:
  10851.                         if ((y = cmnum("Number","",10,&z,xxstring)) < 0)
  10852.                             return(y);
  10853.                         if (z < 1 || z > 2) {
  10854.                             printf("?Out of range: %d\n",z);
  10855.                             return(-9);
  10856.                         }
  10857.                         tmpver = z;
  10858.                         break;
  10859.                     case SSHSW_CMD:
  10860.                     case SSHSW_SUB:
  10861.                         if ((y = cmfld("Text","",&s,xxstring)) < 0)
  10862.                           return(y);
  10863.                         makestr(&ssh_tmpcmd,s);
  10864.                         tmpssh_cas = (cmresult.nresult == SSHSW_SUB);
  10865.                         break;
  10866.                     case SSHSW_X11:
  10867.                         if ((y = cmkey(onoff,2,"","on",xxstring)) < 0)
  10868.                             return(y);
  10869.                         tmpxfw = y;
  10870.                         break;
  10871.                     default:
  10872.                         return(-2);
  10873.                     }
  10874.                 }
  10875.                 if (trips++ == 0) {     /* After first time through */
  10876.                     cmfdbi(&kw,         /* only parse switches, not port. */
  10877.                             _CMKEY,
  10878.                             "Switch",
  10879.                             "",
  10880.                             "",
  10881.                             nsshopnsw,
  10882.                             4,
  10883.                             xxstring,
  10884.                             sshopnsw,
  10885.                             NULL
  10886.                             );
  10887.                 }
  10888.             }
  10889.             if ((y = cmcfm()) < 0)      /* Get confirmation */
  10890.                 return(y);
  10891.  
  10892.             debug(F110,"setlin pre-cx_net line",line,0);
  10893.             debug(F110,"setlin pre-cx_net srvbuf",srvbuf,0);
  10894.             x = cx_net( mynet,                  /* nettype */
  10895.                         0,                      /* protocol (not used) */
  10896.                         line,                   /* host */
  10897.                         srvbuf,                 /* port */
  10898.                         tmpusrid,               /* alternate username */
  10899.                         tmpstring,              /* password */
  10900.                         ssh_tmpcmd,             /* command to execute */
  10901.                         tmpver,                 /* param1 - ssh version */
  10902.                         tmpssh_cas,             /* param2 - ssh cas  */
  10903.                         tmpxfw,                 /* param3 - ssh x11fwd */
  10904.                         cx,                     /* enter CONNECT mode */
  10905.                         sx,                     /* enter SERVER mode */
  10906.                         zz,                     /* close connection if open */
  10907.                         0                       /* gui */
  10908.                         );
  10909.             if (tmpusrid)
  10910.                 makestr(&tmpusrid,NULL);
  10911.             if (ssh_tmpcmd)
  10912.                 makestr(&ssh_tmpcmd,NULL);
  10913.         }
  10914. #endif /* SSHBUILTIN */
  10915.  
  10916. #ifdef TCPSOCKET
  10917.         if (mynet == NET_TCPB) {        /* TCP/IP connection */
  10918.             debug(F110,"setlin service 0",srvbuf,0);
  10919.             debug(F110,"setlin host s 2",s,0);
  10920.             if (*s) {            /* If they gave a host name... */
  10921.                 debug(F110,"setlin host s 1",s,0);
  10922. #ifdef NOLISTEN
  10923.                 if (*s == '*') {
  10924.                     makestr(&slmsg,"Incoming connections not supported");
  10925.                     printf(
  10926.      "?Sorry, incoming connections not supported in this version of Kermit.\n"
  10927.                            );
  10928.                     return(-9);
  10929.                 }
  10930. #endif /* NOLISTEN */
  10931. #ifdef RLOGCODE
  10932.                 /* Allow a username if rlogin is requested */
  10933.                 if (mynet == NET_TCPB &&
  10934.                     (ttnproto == NP_RLOGIN || ttnproto == NP_K5LOGIN ||
  10935.                      ttnproto == NP_EK5LOGIN || ttnproto == NP_K4LOGIN ||
  10936.                      ttnproto == NP_EK4LOGIN
  10937.                     )) {
  10938.                     int y;
  10939.                     uidflag = 0;
  10940.                     /* Check for "host:service" */
  10941.                     for ( ; (*s != '\0') && (*s != ':'); s++) ;
  10942.                     if (*s) {   /* Service, save it */
  10943.                         *s = NUL;
  10944.                         ckstrncpy(srvbuf,++s,SRVBUFSIZ);
  10945.                     } else {            /* No :service, then use default. */
  10946. #ifdef VMS
  10947.                         switch (ttnproto) {
  10948.                           case NP_RLOGIN:
  10949.                             ckstrncpy(srvbuf,"513",SRVBUFSIZ); /* "login" */
  10950.                             break;
  10951.                           case NP_K4LOGIN:
  10952.                           case NP_K5LOGIN:
  10953.                             ckstrncpy(srvbuf,"543",SRVBUFSIZ); /* "klogin" */
  10954.                             break;
  10955.                           case NP_EK4LOGIN:
  10956.                           case NP_EK5LOGIN:
  10957.                             ckstrncpy(srvbuf,"2105",SRVBUFSIZ); /* "eklogin" */
  10958.                             break;
  10959.                         }
  10960. #else /* VMS */
  10961.                         switch (ttnproto) {
  10962.                           case NP_RLOGIN:
  10963.                             ckstrncpy(srvbuf,"login",SRVBUFSIZ);
  10964.                             break;
  10965.                           case NP_K4LOGIN:
  10966.                           case NP_K5LOGIN:
  10967.                             ckstrncpy(srvbuf,"klogin",SRVBUFSIZ);
  10968.                             break;
  10969.                           case NP_EK4LOGIN:
  10970.                           case NP_EK5LOGIN:
  10971.                             ckstrncpy(srvbuf,"eklogin",SRVBUFSIZ);
  10972.                             break;
  10973.                         }
  10974. #endif /* VMS */
  10975.                     }
  10976.                     if (!confirmed) {
  10977.                         y = cmfld("Userid on remote system",
  10978.                                   uidbuf,&s,xxstring);
  10979.                         if (y < 0 && y != -3)
  10980.                           return(y);
  10981.                         if ((int)strlen(s) > 63) {
  10982.                             makestr(&slmsg,"Internal error");
  10983.                             printf("Sorry, too long\n");
  10984.                             return(-9);
  10985.                         }
  10986.                         makestr(&tmpusrid,s);
  10987.                     }
  10988.                 } else {        /* TELNET or SET HOST */
  10989. #endif /* RLOGCODE */
  10990.                     /* Check for "host:service" */
  10991.                     for ( ; (*s != '\0') && (*s != ':'); s++) ;
  10992.                     if (*s) {   /* Service, save it */
  10993.                         *s = NUL;
  10994.                         ckstrncpy(srvbuf,++s,SRVBUFSIZ);
  10995.                     } else if (!confirmed) {
  10996.                         /* No :service, let them type one. */
  10997.                         if (*line != '*') { /* Not incoming */
  10998.                             if (mynet == NET_TCPB && ttnproto == NP_KERMIT) {
  10999.                                 if ((x = cmfld(
  11000.                                                "TCP service name or number",
  11001.                                                "kermit",&s,xxstring)
  11002.                                      ) < 0 && x != -3)
  11003.                                   return(x);
  11004. #ifdef RLOGCODE
  11005.                             } else if (mynet == NET_TCPB &&
  11006.                                        ttnproto == NP_RLOGIN) {
  11007.                                 if ((x = cmfld(
  11008.   "TCP service name or number,\n or carriage return for rlogin (513)",
  11009.                                                "login",&s,xxstring)
  11010.                                      ) < 0 && x != -3)
  11011.                                   return(x);
  11012. #ifdef CK_AUTHENTICATION
  11013. #ifdef CK_KERBEROS
  11014.                             } else if (mynet == NET_TCPB &&
  11015.                                        (ttnproto == NP_K4LOGIN ||
  11016.                                        ttnproto == NP_K5LOGIN)) {
  11017.                                 if ((x = cmfld(
  11018.   "TCP service name or number,\n or carriage return for klogin (543)",
  11019.                                                "klogin",&s,xxstring)
  11020.                                      ) < 0 && x != -3)
  11021.                                   return(x);
  11022.                             } else if (mynet == NET_TCPB &&
  11023.                                        (ttnproto == NP_EK4LOGIN ||
  11024.                                         ttnproto == NP_EK5LOGIN)) {
  11025.                                 if ((x = cmfld(
  11026.   "TCP service name or number,\n or carriage return for eklogin (2105)",
  11027.                                                "eklogin",&s,xxstring)
  11028.                                      ) < 0 && x != -3)
  11029.                                   return(x);
  11030. #endif /* CK_KERBEROS */
  11031. #endif /* CK_AUTHENTICATION */
  11032. #endif /* RLOGCODE */
  11033.                             } else {
  11034.                                 /* Do not set a default value in this call */
  11035.                                 /* If you do then it will prevent entries  */
  11036.                                 /* in the network directory from accessing */
  11037.                                 /* alternate ports.                        */
  11038.  
  11039.                                 if ((x = cmfld(
  11040.                                                "TCP service name or number",
  11041.                                                "",&s,xxstring)
  11042.                                      ) < 0 && x != -3)
  11043.                                   return(x);
  11044.                             }
  11045.                         } else { /* Incoming connection */
  11046.                             if ((x = cmfld("TCP service name or number",
  11047.                                            "",&s,xxstring)
  11048.                                  ) < 0 && x != -3)
  11049.                               return(x);
  11050.                         }
  11051.                         if (*s)         /* If they gave a service, */
  11052.                           ckstrncpy(srvbuf,s,SRVBUFSIZ); /* copy it */
  11053.                         debug(F110,"setlin service 0.5",srvbuf,0);
  11054.                     }
  11055. #ifdef RLOGCODE
  11056.                 }
  11057. #endif /* RLOGCODE */
  11058.                 if (!confirmed) {
  11059.                     char * defproto;
  11060.                     switch (ttnproto) {
  11061.                       case NP_RLOGIN:
  11062.                         defproto = "/rlogin";
  11063.                         break;
  11064.                       case NP_K4LOGIN:
  11065.                         defproto = "/k4login";
  11066.                         break;
  11067.                       case NP_K5LOGIN:
  11068.                         defproto = "/k5login";
  11069.                         break;
  11070.                       case NP_EK4LOGIN:
  11071.                         defproto = "/ek4login";
  11072.                         break;
  11073.                       case NP_EK5LOGIN:
  11074.                         defproto = "/ek5login";
  11075.                         break;
  11076.                       case NP_KERMIT:
  11077.                       case NP_TELNET:
  11078.                         defproto = "/telnet";
  11079.                         break;
  11080.                       default:
  11081.                         defproto = "/default";
  11082.                     }
  11083.                     if ((x = cmkey(tcprawtab,ntcpraw,"Switch",defproto,
  11084.                                    xxstring)) < 0) {
  11085.                         if (x != -3)
  11086.                           return(x);
  11087.                         else if ((x = cmcfm()) < 0)
  11088.                           return(x);
  11089.                     } else {
  11090.                         rawflg = x;
  11091.                         if ((x = cmcfm()) < 0)
  11092.                           return(x);
  11093.                     }
  11094.                 }
  11095.             }
  11096.             debug(F110,"setlin pre-cx_net line",line,0);
  11097.             debug(F110,"setlin pre-cx_net srvbuf",srvbuf,0);
  11098.             x = cx_net( mynet,                  /* nettype */
  11099.                         rawflg                  /* protocol */,
  11100.                         line,                   /* host */
  11101.                         srvbuf,                 /* port */
  11102.                         tmpusrid,               /* alternate username */
  11103.                         tmpstring,              /* password */
  11104.                         NULL,                   /* command to execute */
  11105.                         a_type,                 /* param1 - telnet authtype */
  11106.                         e_type,                 /* param2 - telnet enctype  */
  11107.                         wait,                   /* param3 - telnet wait */
  11108.                         cx,                     /* enter CONNECT mode */
  11109.                         sx,                     /* enter SERVER mode */
  11110.                         zz,                     /* close connection if open */
  11111.                         0                       /* gui */
  11112.                         );
  11113.         }
  11114. #endif /* TCPSOCKET */
  11115.  
  11116. #ifdef CK_SECURITY
  11117.         if (tmpstring)
  11118.             makestr(&tmpstring,NULL);
  11119. #endif /* CK_SECURITY */
  11120.         if (tmpusrid)
  11121.             makestr(&tmpusrid,NULL);
  11122.     debug(F111,"setlin cx_net",line,x);
  11123.     return(x);
  11124. #endif /* NETCONN */
  11125.     }
  11126.  
  11127. /* Serial tty device, possibly modem, connection... */
  11128.  
  11129. #ifdef OS2
  11130. /*
  11131.   User can type:
  11132.     COM1..COM8 = Regular COM port
  11133.     1..8       = Synonym for COM1..COM8, is translated to COM1..COM8
  11134.     _n         = (n is a number) = open file handle
  11135.     string     = any text string = name of some other kind of device,
  11136.                  taken literally, as given.
  11137. */
  11138.     s = "Communication device name";
  11139.  
  11140. #ifdef CK_TAPI
  11141.     if (TAPIAvail)
  11142.       cktapiBuildLineTable(&tapilinetab, &_tapilinetab, &ntapiline);
  11143.     if (!(tapilinetab && _tapilinetab && ntapiline > 0) &&
  11144.     xx == XYTAPI_LIN ) {
  11145.     makestr(&slmsg,"TAPI device not configured");
  11146.     printf("\nNo TAPI Line Devices are configured for this system\n");
  11147.     return(-9);
  11148.     }
  11149.     if (xx == XYTAPI_LIN) {        /* Default (first) TAPI line */
  11150.     s = "tapi";            /* (whatever it is) */
  11151.     } else {                /* Query the user */
  11152. #endif /* CK_TAPI */
  11153.  
  11154. /* Now parse optional switches and then device name */
  11155.  
  11156.     confirmed = 0;
  11157.     cmfdbi(&sw,_CMKEY,"Device name, or switch",
  11158.            "","",npsltab,4,xxstring,psltab,&fl);
  11159.     cmfdbi(&fl,_CMFLD,"",dftty,"",0,0,xxstring,NULL,NULL);
  11160.     while (1) {
  11161.         x = cmfdb(&sw);
  11162.         debug(F101,"setlin cmfdb","",x);
  11163.         if (x < 0)
  11164.           if (x != -3)
  11165.         return(x);
  11166.         if (x == -3) {
  11167.         if ((x = cmcfm()) < 0) {
  11168.             return(x);
  11169.         } else {
  11170.             confirmed = 1;
  11171.             break;
  11172.         }
  11173.         }
  11174.         if (cmresult.fcode == _CMFLD) {
  11175.         s = cmresult.sresult;
  11176.         break;
  11177.         } else if (cmresult.fcode == _CMKEY) {
  11178.         switch (cmresult.nresult) {
  11179.           case SL_CNX:        /* /CONNECT */
  11180.             cx = 1;
  11181.             sx = 0;
  11182.             break;
  11183.           case SL_SRV:        /* /SERVER */
  11184.             cx = 0;
  11185.             sx = 1;
  11186.             break;
  11187.           case SL_SHR:        /* /SHARE */
  11188.             shr = 1;
  11189.             break;
  11190.           case SL_NSH:        /* /NOSHARE */
  11191.             shr = 0;
  11192.             break;
  11193.         }
  11194.         }
  11195.     }
  11196. #ifdef CK_TAPI
  11197.     }
  11198. #endif /* CK_TAPI */
  11199.  
  11200.     debug(F110,"OS2 SET PORT s",s,0);
  11201.     y = lookup(os2devtab,s,nos2dev,&x); /* Look up in keyword table */
  11202.     debug(F101,"OS2 SET PORT x","",x);
  11203.     debug(F101,"OS2 SET PORT y","",y);
  11204.     if ((y > -1) && (x >= 0 && x < 8)) { /* User typed a digit 1..8 */
  11205.     s = os2devtab[x+8].kwd;        /* Substitite its real name */
  11206. #ifdef NT
  11207.     xxtapi = 0;
  11208. #else /* NT */
  11209.     xxslip = xxppp = 0;
  11210. #endif /* NT */
  11211.     debug(F110,"OS2 SET PORT subst s",s,"");
  11212. #ifndef NT
  11213.     } else if ((y >-1) && (x >= 16 && x < 24)) { /* SLIP access */
  11214.     s = os2devtab[x-8].kwd;        /* Substitite its real name */
  11215.     debug(F110,"OS2 SET PORT SLIP subst s",s,"");
  11216.     xxslip = 1;
  11217.     xxppp  = 0;
  11218.     } else if ((y >-1) && (x >= 24 && x < 32)) { /* PPP access */
  11219.     s = os2devtab[x-16].kwd;    /* Substitite its real name */
  11220.     debug(F110,"OS2 SET PORT PPP subst s",s,"");
  11221.     xxppp = 1;
  11222.     xxslip = 0;
  11223.     if ((y = cmkey(os2ppptab,
  11224.                nos2ppp,
  11225.                "PPP driver interface",
  11226.                "ppp0",
  11227.                xxstring)
  11228.          ) < 0)
  11229.       return(y);
  11230.     debug(F101,"OS2 SET PORT PPP INTERFACE y","",y);
  11231.     xxppp = (y % 10) + 1;
  11232. #endif /* NT */
  11233.     } else if (*s == '_') {        /* User used "_" prefix */
  11234.     s++;                /* Remove it */
  11235.     /* Rest must be numeric */
  11236.     debug(F110,"OS2 SET PORT HANDLE _subst s",s,0);
  11237.     if (!rdigits(s)) {
  11238.         makestr(&slmsg,"Invalid file handle");
  11239.         printf("?Invalid format for file handle\n");
  11240.         return(-9);
  11241.     }
  11242. #ifdef NT
  11243.     xxtapi = 0;
  11244. #else /* NT */
  11245.     xxslip = xxppp = 0;
  11246. #endif /* NT */
  11247.     } else {                /* A normal COMx port or a string */
  11248.     s = brstrip(s);            /* Strip braces if any */
  11249. #ifdef NT
  11250. #ifdef CK_TAPI
  11251.     /* Windows TAPI support - Look up in keyword table */
  11252.     if (tapilinetab && _tapilinetab && ntapiline > 0) {
  11253.         if (!ckstrcmp(s,"tapi",4,0)) {
  11254.  
  11255.         /* Find out what the lowest numbered TAPI device is */
  11256.         /* and use it as the default.                       */
  11257.         int j = 9999, k = -1;
  11258.         for (i = 0; i < ntapiline; i++) {
  11259.             if (tapilinetab[i].kwval < j) {
  11260.             j = tapilinetab[i].kwval;
  11261.             k = i;
  11262.             }
  11263.         }
  11264.         if (k >= 0)
  11265.           s = _tapilinetab[k].kwd;
  11266.         else
  11267.           s = "";
  11268.  
  11269.         if ((y = cmkey(_tapilinetab,ntapiline,
  11270.                    "TAPI device name",s,xxstring)) < 0)
  11271.           return(y);
  11272.  
  11273.         xxtapi = 1;
  11274.  
  11275.         /* Get the non Underscored string */
  11276.         for (i = 0; i < ntapiline; i++ ) {
  11277.             if (tapilinetab[i].kwval == y) {
  11278.             s = tapilinetab[i].kwd;
  11279.             break;
  11280.             }
  11281.         }
  11282.         } else
  11283.           xxtapi = 0;
  11284.     }
  11285. #endif /* CK_TAPI */
  11286. #else /* NT */
  11287.     /* not OS/2 SLIP or PPP */
  11288.     xxslip = xxppp = 0;
  11289. #endif /* NT */
  11290.     }
  11291.     ckstrncpy(tmpbuf,s,TMPBUFSIZ);    /* Copy to a safe place */
  11292.     s = tmpbuf;
  11293.     if ((x = cmcfm()) < 0)
  11294.       return(x);
  11295.  
  11296. #else /* !OS2 */
  11297.  
  11298.     cmfdbi(&sw,_CMKEY,"Device name, or switch",
  11299.        "","",npsltab,4,xxstring,psltab,&tx);
  11300.     cmfdbi(&tx,_CMTXT,"",dftty,"",0,0,xxstring,NULL,NULL);
  11301.     while (!confirmed) {
  11302.     x = cmfdb(&sw);
  11303.     debug(F101,"setlin cmfdb","",x);
  11304.     if (x < 0)
  11305.       if (x != -3)
  11306.         return(x);
  11307.     if (x == -3) {
  11308.         if ((x = cmcfm()) < 0) {
  11309.         return(x);
  11310.         } else {
  11311.         confirmed = 1;
  11312.         break;
  11313.         }
  11314.     }
  11315.     switch (cmresult.fcode) {
  11316.       case _CMTXT:
  11317.         ckstrncpy(tmpbuf,cmresult.sresult,TMPBUFSIZ);
  11318.         s = tmpbuf;
  11319.         debug(F110,"setlin CMTXT",tmpbuf,0);
  11320.         confirmed = 1;
  11321.         break;
  11322.       case _CMKEY:            /* Switch */
  11323.         debug(F101,"setlin CMKEY",tmpbuf,cmresult.nresult);
  11324.         switch (cmresult.nresult) {
  11325.           case SL_CNX:        /* /CONNECT */
  11326.         cx = 1;
  11327.         sx = 0;
  11328.         break;
  11329.           case SL_SRV:        /* /SERVER */
  11330.         cx = 0;
  11331.         sx = 1;
  11332.         break;
  11333. #ifdef VMS
  11334.           case SL_SHR:        /* /SHARE */
  11335.         shr = 1;
  11336.         break;
  11337.           case SL_NSH:        /* /NOSHARE */
  11338.         shr = 0;
  11339.         break;
  11340. #endif /* VMS */
  11341.         }
  11342.         continue;
  11343.       default:
  11344.         debug(F101,"setlin bad cmfdb result","",cmresult.fcode);
  11345.         makestr(&slmsg,"Internal error");
  11346.         printf("?Internal parsing error\n");
  11347.         return(-9);
  11348.     }
  11349.     }
  11350. #endif /* OS2 */
  11351.     if (!confirmed)
  11352.       if ((x = cmcfm()) < 0)
  11353.     return(x);
  11354.  
  11355.     debug(F110,"setlin pre-cx_serial s",s,0);
  11356.     debug(F110,"setlin pre-cx_serial line",line,0);
  11357.     x = cx_serial(s,cx,sx,shr,zz,0,
  11358. #ifdef OS2
  11359. #ifdef NT
  11360.                    (xxtapi ? CX_TAPI : 0)
  11361. #else
  11362.                    (xxslip ? CX_SLIP : 0) | (xxppp ? CX_PPP : 0)
  11363. #endif /* NT */
  11364. #else /* OS2 */
  11365.                    0
  11366. #endif /* OS2 */
  11367.                    );
  11368.     debug(F111,"setlin cx_serial",line,x);
  11369.     return(x);
  11370. }
  11371. #endif /* NOLOCAL */
  11372.  
  11373. #ifdef CKCHANNELIO
  11374. /*
  11375.   C-Library based file-i/o package for scripts.  This should be portable to
  11376.   all C-Kermit versions since it uses the same APIs we have always used for
  11377.   processing command files.  The entire channel i/o package is contained
  11378.   herein, apart from some keyword table entries in the main keyword table
  11379.   and the help text in the HELP command module.
  11380.  
  11381.   On platforms like VMS and VOS, this package handles only UNIX-style
  11382.   stream files.  If desired, it can be replaced for those platforms by
  11383.   <#>ifdef'ing out this code and adding the equivalent replacement routines
  11384.   to the ck?fio.c module, e.g. for RMS-based file i/o in ckvfio.c.
  11385. */
  11386.  
  11387. /* Define NOSTAT if the <#>include causes trouble. */
  11388.  
  11389. #ifndef NOSTAT
  11390. #ifdef VMS
  11391. #ifdef VAXC                             /* As it does in VAX C */
  11392. #define NOSTAT
  11393. #endif /* VAXC */
  11394. #endif /* VMS */
  11395. #endif /* NOSTAT */
  11396.  
  11397. #ifndef NOSTAT
  11398. #include <sys/stat.h>
  11399. #endif /* NOSTAT */
  11400.  
  11401. #ifdef NLCHAR
  11402. static int z_lt = 1;                    /* Length of line terminator */
  11403. #else
  11404. static int z_lt = 2;
  11405. #endif /* NLCHAR */
  11406.  
  11407. struct ckz_file {                       /* C-Kermit file struct */
  11408.     FILE * z_fp;                        /* Includes the C-Lib file struct */
  11409.     unsigned int z_flags;               /* Plus C-Kermit mode flags, */
  11410.     CK_OFF_T z_nline;            /* current line number if known, */
  11411.     char z_name[CKMAXPATH+2];           /* and the file's name. */
  11412. };
  11413. static struct ckz_file ** z_file = NULL; /* Array of C-Kermit file structs */
  11414. static int z_inited = 0;                /* Flag for array initialized */
  11415. int z_maxchan = Z_MAXCHAN;              /* Max number of C-Kermit channels */
  11416. int z_openmax = CKMAXOPEN;              /* Max number of open files overall */
  11417. int z_nopen = 0;                        /* How many channels presently open */
  11418. int z_error = 0;                        /* Most recent error */
  11419. int z_filcount = -1;                    /* Most recent FILE COUNT result */
  11420.  
  11421. #define RD_LINE 0                       /* FILE READ options */
  11422. #define RD_CHAR 1
  11423. #define RD_SIZE 2
  11424. #define RD_TRIM 8            /* Like Snobol &TRIM = 1 */
  11425. #define RD_UNTA 9            /* Untabify */
  11426.  
  11427. #define WR_LINE RD_LINE                 /* FILE WRITE options */
  11428. #define WR_CHAR RD_CHAR
  11429. #define WR_SIZE RD_SIZE
  11430. #define WR_STRI 3
  11431. #define WR_LPAD 4
  11432. #define WR_RPAD 5
  11433.  
  11434. #ifdef UNIX
  11435. extern int ckmaxfiles;                  /* Filled in by sysinit(). */
  11436. #endif /* UNIX */
  11437.  
  11438. /* See ckcker.h for error numbers */
  11439. /* See ckcdeb.h for Z_MAXCHAN and CKMAXOPEN definitions */
  11440. /* NOTE: For VMS we might be able to fill in ckmaxfiles */
  11441. /* from FILLM and CHANNELCNT -- find out about these... */
  11442.  
  11443. static char * fopnargs[] = {            /* Mode combinations for fopen() */
  11444. #ifdef COMMENT
  11445.     /* All combinations of rwa */
  11446.     "",  "r",  "w",  "rw",  "a",  "ra",  "wa",  "rwa", /* Text mode */
  11447.     "b", "rb", "wb", "rwb", "ab", "rab", "wab", "rwab" /* Binary mode */
  11448. #else
  11449.     /* Combinations and syntax permitted by C libraries... */
  11450.     "",  "r",  "w",  "r+",  "a",  "",   "a",  "", /* Text mode */
  11451. #ifdef OS2
  11452.     "",  "rb", "wb", "r+b", "ab", "",   "ab", "" /* Binary modes for K95 */
  11453. #else
  11454. #ifdef VMS
  11455.     "",  "rb", "wb", "r+b", "ab", "",   "ab", "" /* Binary modes for VMS */
  11456. #else
  11457.     "",  "r",   "w", "r+",  "a",  "",   "a",  "" /* Binary modes for UNIX */
  11458. #endif /* VMS */
  11459. #endif /* OS2 */
  11460. #endif /* COMMENT */
  11461. };
  11462. static int nfopnargs = sizeof(fopnargs) / sizeof(char *);
  11463.  
  11464. char *                                  /* Error messages */
  11465. ckferror(n) int n; {
  11466.     switch (n) {
  11467.       case FX_NER: return("No error");
  11468.       case FX_SYS: return(ck_errstr());
  11469.       case FX_EOF: return("End of file");
  11470.       case FX_NOP: return("File not open");
  11471.       case FX_CHN: return("Channel out of range");
  11472.       case FX_RNG: return("Parameter out of range");
  11473.       case FX_NMF: return("Too many files open");
  11474.       case FX_FOP: return("Operation conflicts with OPEN mode");
  11475.       case FX_NYI: return("OPEN mode not supported");
  11476.       case FX_BOM: return("Illegal combination of OPEN modes");
  11477.       case FX_ACC: return("Access denied");
  11478.       case FX_FNF: return("File not found");
  11479.       case FX_OFL: return("Buffer overflow");
  11480.       case FX_LNU: return("Current line number unknown");
  11481.       case FX_ROO: return("Off limits");
  11482.       case FX_UNK: return("Operation fails - reason unknown");
  11483.       default: return("Error number out of range");
  11484.     }
  11485. }
  11486.  
  11487. /*
  11488.   Z _ O P E N --  Open a file for the requested type of access.
  11489.  
  11490.   Call with:
  11491.     name:  Name of file to be opened.
  11492.     flags: Any combination of FM_xxx values except FM_EOF (ckcker.h).
  11493.   Returns:
  11494.     >= 0 on success: The assigned channel number
  11495.     <  0 on failure: A negative FX_xxx error code (ckcker.h).
  11496. */
  11497. int
  11498. z_open(name, flags) char * name; int flags; {
  11499.     int i, n;
  11500.     FILE * t;
  11501.     char * mode;
  11502.     debug(F111,"z_open",name,flags);
  11503.     if (!name) name = "";               /* Check name argument */
  11504.     if (!name[0])
  11505.       return(z_error = FX_BFN);
  11506.     if (flags & FM_CMD)                 /* Opening pipes not implemented yet */
  11507.       return(z_error = FX_NYI);         /* (and not portable either) */
  11508.     debug(F101,"z_open nfopnargs","",nfopnargs);
  11509.     if (flags < 0 || flags >= nfopnargs) /* Range check flags */
  11510.       return(z_error = FX_RNG);
  11511.     mode = fopnargs[flags];             /* Get fopen() arg */
  11512.     debug(F111,"z_open fopen args",mode,flags);
  11513.     if (!mode[0])                       /* Check for illegal combinations */
  11514.       return(z_error = FX_BOM);
  11515.     if (!z_inited) {                    /* If file structs not inited */
  11516.         debug(F101,"z_open z_maxchan 1","",z_maxchan);
  11517. #ifdef UNIX
  11518.         debug(F101,"z_open ckmaxfiles","",ckmaxfiles);
  11519.         if (ckmaxfiles > 0) {           /* Set in ck?tio.c: sysinit() */
  11520.             int x;
  11521.             x = ckmaxfiles - ZNFILS - 5;
  11522.             if (x > z_maxchan)          /* sysconf() value greater than */
  11523.               z_maxchan = x;            /* value from header files. */
  11524.             debug(F101,"z_open z_maxchan 2","",z_maxchan);
  11525.         }
  11526. #endif /* UNIX */
  11527.         if (z_maxchan < Z_MINCHAN)      /* Allocate at least this many. */
  11528.           z_maxchan = Z_MINCHAN;
  11529.         debug(F101,"z_open z_maxchan 3","",z_maxchan);
  11530.         /* Note: This could be a pretty big chunk of memory */
  11531.         /* if z_maxchan is a big number.  If this becomes a problem */
  11532.         /* we'll need to malloc and free each element at open/close time */
  11533. #ifdef COMMENT
  11534.     /* May 2006 - it's time - in current Linux this about 3MB */
  11535.         if (!(z_file = (struct ckz_file *)
  11536.               malloc(sizeof(struct ckz_file) * (z_maxchan + 1))))
  11537.           return(z_error = FX_NMF);
  11538.         for (i = 0; i < z_maxchan; i++) {
  11539.             z_file[i].z_fp = NULL;
  11540.             z_file[i].z_flags = 0;
  11541.             z_file[i].z_nline = 0;
  11542.             *(z_file[i].z_name) = '\0';
  11543.         }
  11544. #else
  11545.     /* New economical way, allocate storage for each channel as needed */
  11546.     if (!z_file) {
  11547.         z_file = (struct ckz_file **)malloc((z_maxchan + 1) *
  11548.                         sizeof(struct ckz_file *));
  11549.         if (!z_file)
  11550.           return(z_error = FX_NMF);
  11551.         for (i = 0; i < z_maxchan; i++)
  11552.           z_file[i] = NULL;
  11553.     }
  11554. #endif    /* COMMENT */
  11555.         z_inited = 1;                   /* Remember we initialized */
  11556.     }
  11557.     for (n = -1, i = 0; i < z_maxchan; i++) { /* Find a free channel */
  11558. #ifdef COMMENT
  11559.         if (!z_file[i].z_fp) {
  11560.             n = i;
  11561.             break;
  11562.         }
  11563. #else
  11564.         if (!z_file[i]) {
  11565.         z_file[i] = (struct ckz_file *) malloc(sizeof(struct ckz_file));
  11566.         if (!z_file[i])
  11567.           return(z_error = FX_NMF);
  11568.             n = i;
  11569.             break;
  11570.         }
  11571. #endif    /* COMMENT */
  11572.  
  11573.     }
  11574.     if (n < 0 || n >= z_maxchan)        /* Any free channels? */
  11575.       return(z_error = FX_NMF);         /* No, fail. */
  11576.     errno = 0;
  11577.  
  11578.     z_file[n]->z_flags = 0;        /* In case of failure... */
  11579.     z_file[n]->z_fp = NULL;        /* Set file pointer to NULL */
  11580.  
  11581.     t = fopen(name, mode);              /* Try to open the file. */
  11582.     if (!t) {                           /* Failed... */
  11583.         debug(F111,"z_open error",name,errno);
  11584. #ifdef EMFILE
  11585.         if (errno == EMFILE)
  11586.           return(z_error = FX_NMF);
  11587. #endif /* EMFILE */
  11588.     free(z_file[n]);
  11589.     z_file[n] = NULL;
  11590.         return(z_error = (errno ?  FX_SYS : FX_UNK)); /* Return error code */
  11591.     }
  11592. #ifdef NT
  11593. #ifdef O_SEQUENTIAL
  11594.     if (t)                              /* Caching hint for NT */
  11595.       _setmode(_fileno(t),O_SEQUENTIAL);
  11596. #endif /* O_SEQUENTIAL */
  11597. #endif /* NT */
  11598.     z_nopen++;                          /* Open, count it. */
  11599.     z_file[n]->z_fp = t;        /* Stash the file pointer */
  11600.     z_file[n]->z_flags = flags;        /* and the flags */
  11601.     z_file[n]->z_nline = 0;        /* Current line number is 0 */
  11602.     z_error = 0;
  11603.     zfnqfp(name,CKMAXPATH,z_file[n]->z_name); /* and the file's full name */
  11604.     return(n);                          /* Return the channel number */
  11605. }
  11606.  
  11607. int
  11608. z_close(channel) int channel; {         /* Close file on given channel */
  11609.     int x;
  11610.     FILE * t;
  11611.     if (!z_inited)                      /* Called before any files are open? */
  11612.       return(z_error = FX_NOP);
  11613.     if (channel >= z_maxchan)           /* Channel out of range? */
  11614.       return(z_error = FX_CHN);
  11615.     if (!z_file[channel])
  11616.       return(z_error = FX_NOP);
  11617.     if (!(t = z_file[channel]->z_fp))    /* Channel wasn't open? */
  11618.       return(z_error = FX_NOP);
  11619.     errno = 0;                          /* Set errno 0 to get a good reading */
  11620.     x = fclose(t);                      /* Try to close */
  11621.     if (x == EOF)                       /* On failure */
  11622.       return(z_error = FX_SYS);         /* indicate system error. */
  11623.     z_nopen--;                          /* Closed OK, decrement open count */
  11624.     z_file[channel]->z_fp = NULL;    /* Set file pointer to NULL */
  11625.     z_file[channel]->z_nline = 0;    /* Current line number is 0 */
  11626.     z_file[channel]->z_flags = 0;    /* Set flags to 0 */
  11627.     *(z_file[channel]->z_name) = '\0';    /* Clear name */
  11628.     free(z_file[channel]);
  11629.     z_file[channel] = NULL;
  11630.     return(z_error = 0);
  11631. }
  11632.  
  11633. /*
  11634.   Z _ O U T  --  Output string to channel.
  11635.  
  11636.   Call with:
  11637.     channel:     Channel number to write to.
  11638.     s:           String to write.
  11639.     length > -1: How many characters of s to write.
  11640.     length < 0:  Write entire NUL-terminated string.
  11641.     flags == 0:  Supply line termination.
  11642.     flags >  0:  Don't supply line termination.
  11643.     flags <  0:  Write 'length' NUL characters.
  11644.   Special case:
  11645.     If flags > -1 and s is empty or NULL and length == 1, write 1 NUL.
  11646.   Returns:
  11647.     Number of characters written to channel on success, or
  11648.     negative FX_xxx error code on failure.
  11649. */
  11650. int
  11651. z_out(channel,s,length,flags) int channel, flags, length; char * s; {
  11652.     FILE * t;
  11653.     int x, n;
  11654.     char c = '\0';
  11655.  
  11656.     if (!s) s = "";                     /* Guard against null pointer */
  11657. #ifdef DEBUG
  11658.     if (deblog) {
  11659.         debug(F111,"z_out",s,channel);
  11660.         debug(F101,"z_out length","",length);
  11661.         debug(F101,"z_out flags","",flags);
  11662.     }
  11663. #endif /* DEBUG */
  11664.     if (!z_inited)                      /* File i/o inited? */
  11665.       return(z_error = FX_NOP);
  11666.     if (channel >= z_maxchan)           /* Channel in range? */
  11667.       return(z_error = FX_CHN);
  11668.     if (!z_file[channel])
  11669.       return(z_error = FX_NOP);
  11670.     if (!(t = z_file[channel]->z_fp))    /* File open? */
  11671.       return(z_error = FX_NOP);
  11672.     if (!((z_file[channel]->z_flags) & (FM_WRI|FM_APP))) /* In write mode? */
  11673.       return(z_error = FX_FOP);
  11674.     n = length;                         /* Length of string to write */
  11675.     if (n < 0) {                        /* Negative means get it ourselves */
  11676.         if (flags < 0)                  /* Except when told to write NULs in */
  11677.           return(z_error = FX_RNG);     /* which case args are inconsistent */
  11678.         n = strlen(s);                  /* Get length of string arg */
  11679.     }
  11680.     errno = 0;                          /* Reset errno */
  11681.     debug(F101,"z_out n","",n);
  11682.     if (flags < 0) {                    /* Writing NULs... */
  11683.         int i;
  11684.         for (i = 0; i < n; i++) {
  11685.             x = fwrite(&c,1,1,t);
  11686.             if (x < 1)
  11687.               return(z_error = (errno ? FX_SYS : FX_UNK));
  11688.         }
  11689.         z_file[channel]->z_nline = -1;   /* Current line no longer known */
  11690.         z_error = 0;
  11691.         return(i);
  11692.     } else {                            /* Writing string arg */
  11693.         if (n == 1 && !s[0])            /* Writing one char but it's NUL */
  11694.           x = fwrite(&c,1,1,t);
  11695.         else                            /* Writing non-NUL char or string */
  11696.           x = fwrite(s,1,n,t);
  11697.         debug(F101,"z_out fwrite",ckitoa(x),errno);
  11698.         if (x < n)                      /* Failure to write requested amount */
  11699.           return(z_error = (errno ? FX_SYS : FX_UNK)); /* Return error */
  11700.         if (flags == 0) {               /* If supplying line termination */
  11701.             if (fwrite("\n",1,1,t))     /* do that  */
  11702.               x += z_lt;                /* count the terminator */
  11703.             if (z_file[channel]->z_nline > -1) /* count this line */
  11704.               z_file[channel]->z_nline++;
  11705.         } else {
  11706.             z_file[channel]->z_nline = -1; /* Current line no longer known */
  11707.         }
  11708.     }
  11709.     z_error = 0;
  11710.     return(x);
  11711. }
  11712.  
  11713. #define Z_INBUFLEN 64
  11714.  
  11715. /*
  11716.   Z _ I N  --  Multichannel i/o file input function.
  11717.  
  11718.   Call with:
  11719.     channel number to read from.
  11720.     s = address of destination buffer.
  11721.     buflen = destination buffer length.
  11722.     length = Number of bytes to read, must be < buflen.
  11723.     flags: 0 = read a line; nonzero = read the given number of bytes.
  11724.   Returns:
  11725.     Number of bytes read into buffer or a negative error code.
  11726.     A terminating NUL is deposited after the last byte that was read.
  11727. */
  11728. int
  11729. z_in(channel,s,buflen,length,flags)
  11730.  int channel, buflen, length, flags; char * s;
  11731. /* z_in */ {
  11732.     int i, j, x;
  11733.     FILE * t;
  11734.     char * p;
  11735.  
  11736.     if (!z_inited)                      /* Check everything... */
  11737.       return(z_error = FX_NOP);
  11738.     if (channel >= z_maxchan)
  11739.       return(z_error = FX_CHN);
  11740.     if (!z_file[channel])
  11741.       return(z_error = FX_NOP);
  11742.     if (!(t = z_file[channel]->z_fp))
  11743.       return(z_error = FX_NOP);
  11744.     if (!((z_file[channel]->z_flags) & FM_REA))
  11745.       return(z_error = FX_FOP);
  11746.     if (!s)                             /* Check destination */
  11747.      return(z_error = FX_RNG);
  11748.     s[0] = NUL;
  11749.     if (length == 0)                    /* Read 0 bytes - easy. */
  11750.       return(z_error = 0);
  11751.     debug(F101,"z_in channel","",channel);
  11752.     debug(F101,"z_in buflen","",buflen);
  11753.     debug(F101,"z_in length","",length);
  11754.     debug(F101,"z_in flags","",flags);
  11755.     if (length < 0 || buflen < 0)       /* Check length args */
  11756.       return(z_error = FX_RNG);
  11757.     if (buflen <= length)
  11758.       return(z_error = FX_RNG);
  11759.     errno = 0;                          /* Reset errno */
  11760.     if (flags) {                        /* Read block or byte */
  11761.     int n;                /* 20050912 */
  11762.     n = length;            /* 20050912 */
  11763.     i = 0;                /* 20050912 */
  11764.     while (n > 0) {            /* 20050912 */
  11765.         i = fread(s,1,n,t);        /* 20050912 */
  11766. #ifdef DEBUG
  11767.         if (deblog) {
  11768.         debug(F111,"z_in block",s,i);
  11769.         debug(F101,"z_in block errno","",errno);
  11770.         debug(F101,"z_in block ferror","",ferror(t));
  11771.         debug(F101,"z_in block feof","",feof(t));
  11772.         }
  11773. #endif /* DEBUG */
  11774.         if (i == 0) break;        /* 20050912 */
  11775.         s += i;            /* 20050912 */
  11776.         n -= i;            /* 20050912 */
  11777.     }
  11778.     /* Current line no longer known */
  11779.         z_file[channel]->z_nline = (CK_OFF_T)-1;
  11780.     } else {                            /* Read line */
  11781. #ifndef COMMENT
  11782.         /* This method is used because it's simpler than the others */
  11783.         /* and also marginally faster. */
  11784.         debug(F101,"z_in getc loop","",CKFTELL(t));
  11785.         for (i = 0; i < length; i++) {
  11786.             if ((x = getc(t)) == EOF) {
  11787.                 debug(F101,"z_in getc error","",CKFTELL(t));
  11788.                 s[i] = '\0';
  11789.                 break;
  11790.             }
  11791.             s[i] = x;
  11792.             if (s[i] == '\n') {
  11793.                 s[i] = '\0';
  11794.                 break;
  11795.             }
  11796.         }
  11797.         debug(F111,"z_in line byte loop",ckitoa(errno),i);
  11798.         debug(F111,"z_in line got",s,z_file[channel]->z_nline);
  11799.         if (z_file[channel]->z_nline > -1)
  11800.           z_file[channel]->z_nline++;
  11801. #else
  11802. #ifdef COMMENT2
  11803.         /* Straightforward but strlen() slows it down. */
  11804.         s[0] = '\0';
  11805.         i = 0;
  11806.         if (fgets(s,length,t)) {
  11807.             i = strlen(s);
  11808.             if (i > 0 && s[i-1] == '\n') i--;
  11809.         }
  11810.         debug(F111,"z_in line fgets",ckitoa(errno),i);
  11811.         if (z_file[channel]->z_nline > -1)
  11812.           z_file[channel]->z_nline++;
  11813. #else
  11814.         /* This is a do-it-yourself fgets() with its own readahead and */
  11815.         /* putback.  It's a bit faster than real fgets() but not enough */
  11816.         /* to justify the added complexity or the risk of the ftell() and */
  11817.         /* fseek() calls failing. */
  11818.         int k, flag = 0;
  11819.         CK_OFF_T pos;
  11820.         for (i = 0; !flag && i <= (length - Z_INBUFLEN); i += Z_INBUFLEN) {
  11821.             k = ((length - i) < Z_INBUFLEN) ? length - i : Z_INBUFLEN;
  11822.             if ((x = fread(s+i,1,k,t)) < 1)
  11823.               break;
  11824.             s[i+x] = '\0';
  11825.             for (j = 0; j < x; j++) {
  11826.                 if (s[i+j] == '\n') {
  11827.                     s[i+j] = '\0';
  11828.                     flag ++;
  11829.                     pos = CKFTELL(t);
  11830.                     if (pos > -1) {
  11831.                         pos -= (x - j - 1);
  11832.                         x = CKFSEEK(t, pos, 0);
  11833.                         i += j;
  11834.                         break;
  11835.                     } else
  11836.                       return(z_error = FX_SYS);
  11837.                 }
  11838.             }
  11839.         }
  11840.         if (z_file[channel]->z_nline > -1)
  11841.           z_file[channel]->z_nline++;
  11842.         debug(F111,"z_in line chunk loop",ckitoa(errno),i);
  11843. #endif /* COMMENT2 */
  11844. #endif /* COMMENT */
  11845.     }
  11846.     debug(F111,"z_in i",ckitoa(errno),i);
  11847.     if (i < 0) i = 0;                   /* NUL-terminate result */
  11848.     s[i] = '\0';
  11849.     if (i > 0) {
  11850.         z_error = 0;
  11851.         return(i);
  11852.     }
  11853.     if (i == 0 && feof(t))              /* EOF on reading? */
  11854.       return(z_error = FX_EOF);         /* Return EOF code */
  11855.     return(errno ? (z_error = -1) : i); /* Return length or system error */
  11856. }
  11857.  
  11858. int
  11859. z_flush(channel) int channel; {         /* Flush output channel */
  11860.     FILE * t;
  11861.     int x;
  11862.     if (!z_inited)                      /* Regular checks */
  11863.       return(z_error = FX_NOP);
  11864.     if (channel >= z_maxchan)
  11865.       return(z_error = FX_CHN);
  11866.     if (!z_file[channel])
  11867.       return(z_error = FX_NOP);
  11868.     if (!(t = z_file[channel]->z_fp))
  11869.       return(z_error = FX_NOP);
  11870.     if (!((z_file[channel]->z_flags) & (FM_WRI|FM_APP))) /* Write access? */
  11871.       return(z_error = FX_FOP);
  11872.     errno = 0;                          /* Reset errno */
  11873.     x = fflush(t);                      /* Try to flush */
  11874.     return(x ? (z_error = FX_SYS) : 0); /* Return system error or 0 if OK */
  11875. }
  11876.  
  11877. int
  11878. #ifdef CK_ANSIC
  11879. z_seek(int channel, CK_OFF_T pos)    /* Move file pointer to byte */
  11880. #else
  11881. z_seek(channel,pos) int channel; CK_OFF_T pos; /* (seek to given position) */
  11882. #endif /* CK_ANSIC */
  11883. {
  11884.     int i, x = 0, rc;
  11885.     FILE * t;
  11886.     if (!z_inited)                      /* Check... */
  11887.       return(z_error = FX_NOP);
  11888.     if (channel >= z_maxchan)
  11889.       return(z_error = FX_CHN);
  11890.     if (!z_file[channel])
  11891.       return(z_error = FX_NOP);
  11892.     if (!(t = z_file[channel]->z_fp))
  11893.       return(z_error = FX_NOP);
  11894.     if (pos < 0L) {
  11895.         x = 2;
  11896.         pos = (pos == -2) ? -1L : 0L;
  11897.     }
  11898.     errno = 0;
  11899.     rc = CKFSEEK(t,pos,x);        /* Try to seek */
  11900.     debug(F111,"z_seek",ckitoa(errno),rc);
  11901.     if (rc < 0)                         /* OK? */
  11902.       return(z_error = FX_SYS); /* No. */
  11903.     z_file[channel]->z_nline = ((pos || x) ? -1 : 0);
  11904.     return(z_error = 0);
  11905. }
  11906.  
  11907. int
  11908. #ifdef CK_ANSIC
  11909. z_line(int channel, CK_OFF_T pos)           /* Move file pointer to line */
  11910. #else
  11911. z_line(channel,pos) int channel; CK_OFF_T pos; /* (seek to given position) */
  11912. #endif /* CK_ANSIC */
  11913. {
  11914.     int i, len, x = 0;
  11915.     CK_OFF_T current = (CK_OFF_T)0, prev = (CK_OFF_T)-1, old = (CK_OFF_T)-1;
  11916.     FILE * t;
  11917.     char tmpbuf[256];
  11918.     if (!z_inited)                      /* Check... */
  11919.       return(z_error = FX_NOP);
  11920.     if (channel >= z_maxchan)
  11921.       return(z_error = FX_CHN);
  11922.     if (!z_file[channel])
  11923.       return(z_error = FX_NOP);
  11924.     if (!(t = z_file[channel]->z_fp))
  11925.       return(z_error = FX_NOP);
  11926.     debug(F101,"z_line pos","",pos);
  11927.     if (pos < 0L) {                     /* EOF wanted */
  11928.         CK_OFF_T n;
  11929.         n = z_file[channel]->z_nline;
  11930.         debug(F101,"z_line n","",n);
  11931.         if (n < 0 || pos < 0) {
  11932.             rewind(t);
  11933.             n = 0;
  11934.         }
  11935.         while (1) {                     /* This could take a while... */
  11936.             if ((x = getc(t)) == EOF)
  11937.               break;
  11938.             if (x == '\n') {
  11939.                 n++;
  11940.                 if (pos == -2) {
  11941.                     old = prev;
  11942.                     prev = CKFTELL(t);
  11943.                 }
  11944.             }
  11945.         }
  11946.         debug(F101,"z_line old","",old);
  11947.         debug(F101,"z_line prev","",prev);
  11948.         if (pos == -2) {
  11949.             if ((x = z_seek(channel,old)) < 0)
  11950.               return(z_error = x);
  11951.             else
  11952.               n--;
  11953.         }
  11954.         z_file[channel]->z_nline = n;
  11955.         return(z_error = 0);
  11956.     }
  11957.     if (pos == 0L) {                    /* Rewind wanted */
  11958.         z_file[channel]->z_nline = 0L;
  11959.         rewind(t);
  11960.         debug(F100,"z_line rewind","",0);
  11961.         return(0L);
  11962.     }
  11963.     tmpbuf[255] = NUL;                  /* Make sure buf is NUL terminated */
  11964.     current = z_file[channel]->z_nline;  /* Current line */
  11965.     /*
  11966.       If necessary the following could be optimized, e.g. for positioning
  11967.       to a previous line in a large file without starting over.
  11968.     */
  11969.     if (current < 0 || pos < current) { /* Not known or behind us... */
  11970.         debug(F101,"z_line rewinding","",pos);
  11971.         if ((x = z_seek(channel, 0L)) < 0) /* Rewind */
  11972.           return(z_error = x);
  11973.         if (pos == 0)                   /* If 0th line wanted we're done */
  11974.           return(z_error = 0);
  11975.         current = 0;
  11976.     }
  11977.     while (current < pos) {             /* Search for specified line */
  11978.         if (fgets(tmpbuf,255,t)) {
  11979.             len = strlen(tmpbuf);
  11980.             if (len > 0 && tmpbuf[len-1] == '\n') {
  11981.                 current++;
  11982.                 debug(F111,"z_line read",ckitoa(len),current);
  11983.             } else if (len == 0) {
  11984.                 return(z_error = FX_UNK);
  11985.             }
  11986.         } else {
  11987.             z_file[channel]->z_nline = -1L;
  11988.             debug(F101,"z_line premature EOF","",current);
  11989.             return(z_error = FX_EOF);
  11990.         }
  11991.     }
  11992.     z_file[channel]->z_nline = current;
  11993.     debug(F101,"z_line result","",current);
  11994.     z_error = 0;
  11995.     return(current);
  11996. }
  11997.  
  11998. char *
  11999. z_getname(channel) int channel; {       /* Return name of file on channel */
  12000.     FILE * t;
  12001.     if (!z_inited) {
  12002.         z_error = FX_NOP;
  12003.         return(NULL);
  12004.     }
  12005.     if (channel >= z_maxchan) {
  12006.         z_error = FX_CHN;
  12007.         return(NULL);
  12008.     }
  12009.     if (!z_file[channel]) {
  12010.         z_error = FX_NOP;
  12011.         return(NULL);
  12012.     }
  12013.     if (!(t = z_file[channel]->z_fp)) {
  12014.         z_error = FX_NOP;
  12015.         return(NULL);
  12016.     }
  12017.     return((char *)(z_file[channel]->z_name));
  12018. }
  12019.  
  12020. int
  12021. z_getmode(channel) int channel; {       /* Return OPEN modes of channel */
  12022.     FILE * t;                           /* 0 if file not open */
  12023. #ifndef NOSTAT
  12024. #ifdef NT
  12025.     struct _stat statbuf;
  12026. #else /* NT */
  12027.     struct stat statbuf;
  12028. #endif /* NT */
  12029. #endif /* NOSTAT */
  12030.     int x;
  12031.     if (!z_inited)
  12032.       return(0);
  12033.     if (channel >= z_maxchan)
  12034.       return(z_error = FX_CHN);
  12035.     if (!z_file[channel])
  12036.       return(0);
  12037.     if (!(t = z_file[channel]->z_fp))
  12038.       return(0);
  12039.     x = z_file[channel]->z_flags;
  12040.     if (feof(t)) {                      /* This might not work for */
  12041.         x |= FM_EOF;                    /* output files */
  12042. #ifndef NOSTAT
  12043.     /* But this does if we can use it. */
  12044.     } else if (stat(z_file[channel]->z_name,&statbuf) > -1) {
  12045.         if (CKFTELL(t) == statbuf.st_size)
  12046.           x |= FM_EOF;
  12047. #endif /* NOSTAT */
  12048.     }
  12049.     return(x);
  12050. }
  12051.  
  12052. CK_OFF_T
  12053. z_getpos(channel) int channel; {        /* Get file pointer position */
  12054.     FILE * t;                           /* on this channel */
  12055.     CK_OFF_T x;
  12056.     if (!z_inited)
  12057.       return(z_error = FX_NOP);
  12058.     if (channel >= z_maxchan)
  12059.       return(z_error = FX_CHN);
  12060.     if (!z_file[channel])
  12061.       return(z_error = FX_NOP);
  12062.     if (!(t = z_file[channel]->z_fp))
  12063.       return(z_error = FX_NOP);
  12064.     x = CKFTELL(t);
  12065.     return((x < 0L) ? (z_error = FX_SYS) : x);
  12066. }
  12067.  
  12068. CK_OFF_T
  12069. z_getline(channel) int channel; {       /* Get current line number */
  12070.     FILE * t;                           /* in file on this channel */
  12071.     CK_OFF_T rc;
  12072.     if (!z_inited)
  12073.       return(z_error = FX_NOP);
  12074.     if (channel >= z_maxchan)
  12075.       return(z_error = FX_CHN);
  12076.     if (!z_file[channel])
  12077.       return(z_error = FX_NOP);
  12078.     if (!(t = z_file[channel]->z_fp))
  12079.       return(z_error = FX_NOP);
  12080.     debug(F101,"z_getline","",z_file[channel]->z_nline);
  12081.     rc = z_file[channel]->z_nline;
  12082.     return((rc < 0) ? (z_error = FX_LNU) : rc);
  12083. }
  12084.  
  12085. int
  12086. z_getfnum(channel) int channel; {       /* Get file number / handle */
  12087.     FILE * t;                           /* for file on this channel */
  12088.     if (!z_inited)
  12089.       return(z_error = FX_NOP);
  12090.     if (channel >= z_maxchan)
  12091.       return(z_error = FX_CHN);
  12092.     if (!z_file[channel])
  12093.       return(z_error = FX_NOP);
  12094.     if (!(t = z_file[channel]->z_fp))
  12095.       return(z_error = FX_NOP);
  12096.     z_error = 0;
  12097.     return(fileno(t));
  12098. }
  12099.  
  12100. /*
  12101.   Line-oriented counts and seeks are as dumb as they can be at the moment.
  12102.   Later we can speed them up by building little indexes.
  12103. */
  12104. CK_OFF_T
  12105. z_count(channel, what) int channel, what; { /* Count bytes or lines in file */
  12106.     FILE * t;
  12107.     int i, x;
  12108.     CK_OFF_T pos, count = (CK_OFF_T)0;
  12109.     if (!z_inited)                      /* Check stuff... */
  12110.       return(z_error = FX_NOP);
  12111.     if (channel >= z_maxchan)
  12112.       return(z_error = FX_CHN);
  12113.     if (!z_file[channel])
  12114.       return(z_error = FX_NOP);
  12115.     if (!(t = z_file[channel]->z_fp))
  12116.       return(z_error = FX_NOP);
  12117.     pos = CKFTELL(t);            /* Save current file pointer */
  12118.     errno = 0;
  12119.     z_error = 0;
  12120.     if (what == RD_CHAR) {              /* Size in bytes requested */
  12121. #ifdef COMMENT
  12122.         if (!CKFSEEK(t,0L,2)) {        /* Seek to end */
  12123.             count = CKFTELL(t);        /* Get file pointer */
  12124.             CKFSEEK(t,pos,0);        /* Restore file file pointer */
  12125.             return(count);
  12126.         } else                          /* Fallback in case seek fails */
  12127. #endif    /* COMMENT */
  12128.           return(zgetfs(z_file[channel]->z_name));
  12129.     }
  12130.     rewind(t);                          /* Line count requested - rewind. */
  12131.     while (1) {                         /* Count lines. */
  12132.         if ((x = getc(t)) == EOF)       /* Stupid byte loop */
  12133.           break;                        /* but it works as well as anything */
  12134.         if (x == '\n')                  /* else... */
  12135.           count++;
  12136.     }
  12137.     x = CKFSEEK(t,pos,0);        /* Restore file pointer */
  12138.     return(count);
  12139. }
  12140.  
  12141. /* User interface for generalized channel-oriented file i/o */
  12142.  
  12143. struct keytab fctab[] = {               /* FILE subcommands */
  12144.     { "close",      FIL_CLS, 0 },
  12145.     { "count",      FIL_COU, 0 },
  12146.     { "flush",      FIL_FLU, 0 },
  12147.     { "list",       FIL_LIS, 0 },
  12148.     { "open",       FIL_OPN, 0 },
  12149.     { "read",       FIL_REA, 0 },
  12150.     { "rewind",     FIL_REW, 0 },
  12151.     { "seek",       FIL_SEE, 0 },
  12152.     { "status",     FIL_STA, 0 },
  12153.     { "write",      FIL_WRI, 0 }
  12154. };
  12155. int nfctab = (sizeof (fctab) / sizeof (struct keytab));
  12156.  
  12157. static struct keytab fcswtab[] = {      /* OPEN modes */
  12158.     { "/append",    FM_APP,  0 },
  12159.     { "/binary",    FM_BIN,  0 },
  12160. #ifdef COMMENT
  12161.     { "/command",   FM_CMD,  0 },       /* Not implemented */
  12162. #endif /* COMMENT */
  12163.     { "/read",      FM_REA,  0 },
  12164.     { "/write",     FM_WRI,  0 }
  12165. };
  12166. static int nfcswtab = (sizeof (fcswtab) / sizeof (struct keytab));
  12167.  
  12168. static struct keytab fclkwtab[] = {     /* CLOSE options */
  12169.     { "all",        1,       0 }
  12170. };
  12171.  
  12172. static struct keytab fsekwtab[] = {     /* SEEK symbols */
  12173.     { "eof",        1,       0 },
  12174.     { "last",       2,       0 }
  12175. };
  12176. static int nfsekwtab = (sizeof (fsekwtab) / sizeof (struct keytab));
  12177.  
  12178. #define SEE_LINE  RD_LINE               /* SEEK options */
  12179. #define SEE_CHAR  RD_CHAR
  12180. #define SEE_REL   3
  12181. #define SEE_ABS   4
  12182. #define SEE_FIND  5
  12183.  
  12184. static struct keytab fskswtab[] = {
  12185.     { "/absolute",  SEE_ABS,  0 },
  12186.     { "/byte",      SEE_CHAR, 0 },
  12187.     { "/character", SEE_CHAR, CM_INV },
  12188.     { "/find",      SEE_FIND, CM_ARG },
  12189.     { "/line",      SEE_LINE, 0 },
  12190.     { "/relative",  SEE_REL,  0 }
  12191. };
  12192. static int nfskswtab = (sizeof (fskswtab) / sizeof (struct keytab));
  12193.  
  12194. #define COU_LINE  RD_LINE               /* COUNT options */
  12195. #define COU_CHAR  RD_CHAR
  12196. #define COU_LIS   3
  12197. #define COU_NOL   4
  12198.  
  12199. static struct keytab fcoswtab[] = {
  12200.     { "/bytes",     COU_CHAR, 0      },
  12201.     { "/characters",COU_CHAR, CM_INV },
  12202.     { "/lines",     COU_LINE, 0      },
  12203.     { "/list",      COU_LIS,  0      },
  12204.     { "/nolist",    COU_NOL,  0      },
  12205.     { "/quiet",     COU_NOL,  CM_INV }
  12206. };
  12207. static int nfcoswtab = (sizeof (fcoswtab) / sizeof (struct keytab));
  12208.  
  12209. static struct keytab frdtab[] = {       /* READ types */
  12210.     { "/block",     RD_SIZE, CM_INV|CM_ARG },
  12211.     { "/byte",      RD_CHAR, CM_INV },
  12212.     { "/character", RD_CHAR, 0      },
  12213.     { "/line",      RD_LINE, 0      },
  12214.     { "/size",      RD_SIZE, CM_ARG },
  12215.     { "/trim",      RD_TRIM, 0      },
  12216.     { "/untabify",  RD_UNTA, 0      }
  12217. };
  12218. static int nfrdtab = (sizeof (frdtab) / sizeof (struct keytab));
  12219.  
  12220. static struct keytab fwrtab[] = {       /* WRITE types */
  12221.     { "/block",     WR_SIZE, CM_INV|CM_ARG },
  12222.     { "/byte",      WR_CHAR, CM_INV },
  12223.     { "/character", WR_CHAR, 0      },
  12224.     { "/line",      WR_LINE, 0      },
  12225.     { "/lpad",      WR_LPAD, CM_ARG },
  12226.     { "/rpad",      WR_RPAD, CM_ARG },
  12227.     { "/size",      WR_SIZE, CM_ARG },
  12228.     { "/string",    WR_STRI, 0      }
  12229. };
  12230. static int nfwrtab = (sizeof (fwrtab) / sizeof (struct keytab));
  12231.  
  12232. static char blanks[] = "\040\040\040\040"; /* Some blanks for formatting */
  12233. static char * seek_target = NULL;
  12234.  
  12235. int
  12236. dofile(op) int op; {                    /* Do the FILE command */
  12237.     char vnambuf[VNAML];                /* Buffer for variable names */
  12238.     char *vnp = NULL;                   /* Pointer to same */
  12239.     char zfilnam[CKMAXPATH+2];
  12240.     char * p, * m;
  12241.     struct FDB fl, sw, nu;
  12242.     CK_OFF_T z;
  12243.     int rsize, filmode = 0, relative = -1, eofflg = 0;
  12244.     int rc, x, y, cx, n, getval, dummy, confirmed, listing = -1;
  12245.     int charflag = 0, sizeflag = 0;
  12246.     int pad = 32, wr_lpad = 0, wr_rpad = 0, rd_trim = 0, rd_untab = 0;
  12247.  
  12248.     makestr(&seek_target,NULL);
  12249.  
  12250.     if (op == XXFILE) {                 /* FILE command was given */
  12251.         /* Get subcommand */
  12252.         if ((cx = cmkey(fctab,nfctab,"Operation","",xxstring)) < 0) {
  12253.             if (cx == -3) {
  12254.                 printf("?File operation required\n");
  12255.                 x = -9;
  12256.             }
  12257.             return(cx);
  12258.         }
  12259.     } else {                            /* Shorthand command was given */
  12260.         switch (op) {
  12261.           case XXF_CL: cx = FIL_CLS; break; /* FCLOSE */
  12262.           case XXF_FL: cx = FIL_FLU; break; /* FFLUSH */
  12263.           case XXF_LI: cx = FIL_LIS; break; /* FLIST */
  12264.           case XXF_OP: cx = FIL_OPN; break; /* etc... */
  12265.           case XXF_RE: cx = FIL_REA; break;
  12266.           case XXF_RW: cx = FIL_REW; break;
  12267.           case XXF_SE: cx = FIL_SEE; break;
  12268.           case XXF_ST: cx = FIL_STA; break;
  12269.           case XXF_WR: cx = FIL_WRI; break;
  12270.           case XXF_CO: cx = FIL_COU; break;
  12271.           default: return(-2);
  12272.         }
  12273.     }
  12274.     switch (cx) {                       /* Do requested subcommand */
  12275.       case FIL_OPN:                     /* OPEN */
  12276.         cmfdbi(&sw,                     /* Switches */
  12277.                _CMKEY,                  /* fcode */
  12278.                "Variable or switch",    /* hlpmsg */
  12279.                "",                      /* default */
  12280.                "",                      /* addtl string data */
  12281.                nfcswtab,                /* addtl numeric data 1: tbl size */
  12282.                4,                       /* addtl numeric data 2: 4 = cmswi */
  12283.                xxstring,                /* Processing function */
  12284.                fcswtab,                 /* Keyword table */
  12285.                &fl                      /* Pointer to next FDB */
  12286.                );
  12287.         cmfdbi(&fl,                     /* Anything that doesn't match */
  12288.                _CMFLD,                  /* fcode */
  12289.                "Variable",              /* hlpmsg */
  12290.                "",
  12291.                "",
  12292.                0,
  12293.                0,
  12294.                NULL,
  12295.                NULL,
  12296.                NULL
  12297.                );
  12298.         while (1) {
  12299.             x = cmfdb(&sw);             /* Parse something */
  12300.             if (x < 0) {
  12301.                 if (x == -3) {
  12302.                     printf("?Variable name and file name required\n");
  12303.                     x = -9;
  12304.                 }
  12305.                 return(x);
  12306.             }
  12307.             if (cmresult.fcode == _CMFLD)
  12308.               break;
  12309.             else if (cmresult.fcode == _CMKEY) {
  12310.                 char c;
  12311.                 c = cmgbrk();
  12312.                 if ((getval =
  12313.                      (c == ':' || c == '=')) && !(cmgkwflgs() & CM_ARG)) {
  12314.                     printf("?This switch does not take an argument\n");
  12315.                     return(-9);
  12316.                 }
  12317. #ifdef COMMENT
  12318.                 /* Uncomment if we add any switches here that take args */
  12319.                 if (!getval && (cmgkwflgs() & CM_ARG)) {
  12320.                     printf("?This switch requires an argument\n");
  12321.                     return(-9);         /* (none do...) */
  12322.                 }
  12323. #endif /* COMMENT */
  12324.                 filmode |= cmresult.nresult; /* OR in the file mode */
  12325.             } else
  12326.               return(-2);
  12327.         }
  12328.         /* Not a switch - get the string */
  12329.         ckstrncpy(vnambuf,cmresult.sresult,VNAML);
  12330.         if (!vnambuf[0] || chknum(vnambuf)) { /* (if there is one...) */
  12331.             printf("?Variable name required\n");
  12332.             return(-9);
  12333.         }
  12334.         vnp = vnambuf;                  /* Check variable-name syntax */
  12335.         if (vnambuf[0] == CMDQ &&
  12336.             (vnambuf[1] == '%' || vnambuf[1] == '&'))
  12337.           vnp++;
  12338.         y = 0;
  12339.         if (*vnp == '%' || *vnp == '&') {
  12340.             if ((y = parsevar(vnp,&x,&dummy)) < 0) {
  12341.                 printf("?Syntax error in variable name\n");
  12342.                 return(-9);
  12343.             }
  12344.         }
  12345.     /* Assign a negative channel number in case we fail */
  12346.     addmac(vnambuf,"-1");
  12347.  
  12348.         if (!(filmode & FM_RWA))        /* If no access mode specified */
  12349.           filmode |= FM_REA;            /* default to /READ. */
  12350.  
  12351.         y = 0;                          /* Now parse the filename */
  12352.         if ((filmode & FM_RWA) == FM_WRI) {
  12353.         x = cmofi("Name of new file","",&s,xxstring);
  12354.     } else if ((filmode & FM_RWA) == FM_REA) {
  12355.         x = cmifi("Name of existing file","",&s,&y,xxstring);
  12356.     } else {
  12357.             x = cmiofi("Filename","",&s,&y,xxstring);
  12358.             debug(F111,"fopen /append x",s,x);
  12359.     }
  12360.         if (x < 0) {
  12361.             if (x == -3) {
  12362.                 printf("?Filename required\n");
  12363.                 x = -9;
  12364.             }
  12365.             return(x);
  12366.         }
  12367.         if (y) {                        /* No wildcards */
  12368.             printf("?Wildcards not allowed here\n");
  12369.             return(-9);
  12370.         }
  12371.         if (filmode & (FM_APP|FM_WRI)) { /* Check output access */
  12372. #ifndef VMS
  12373.             if (zchko(s) < 0) {          /* and set error code if denied */
  12374.                 z_error = FX_ACC;
  12375.                 printf("?Write access denied - \"%s\"\n",s);
  12376.                 return(-9);
  12377.             }
  12378. #endif /* VMS */
  12379.         }
  12380.         ckstrncpy(zfilnam,s,CKMAXPATH); /* Is OK - make safe copy */
  12381.         if ((x = cmcfm()) < 0)          /* Get confirmation of command */
  12382.           return(x);
  12383.         if ((n = z_open(zfilnam,filmode)) < 0) {
  12384.             printf("?OPEN failed - %s: %s\n",zfilnam,ckferror(n));
  12385.             return(-9);
  12386.         }
  12387.         addmac(vnambuf,ckitoa(n));      /* Assign channel number to variable */
  12388.         return(success = 1);
  12389.  
  12390.       case FIL_REW:                     /* REWIND */
  12391.         if ((x = cmnum("Channel number","",10,&n, xxstring)) < 0) {
  12392.             if (x == -3) {
  12393.                 printf("?Channel number required\n");
  12394.                 x = -9;
  12395.             }
  12396.             return(x);
  12397.         }
  12398.         if ((x = cmcfm()) < 0)
  12399.           return(x);
  12400.     if (n == -9) return(success = 0);
  12401.     if (n == -8) return(success = 1);
  12402.  
  12403.         if ((rc = z_seek(n,0L)) < 0) {
  12404.             printf("?REWIND failed - Channel %d: %s\n",n,ckferror(rc));
  12405.             return(-9);
  12406.         }
  12407.         return(success = 1);
  12408.  
  12409.       case FIL_CLS:                     /* CLOSE */
  12410.          {
  12411.         int i, j, k;        /* Supply default if only one open */
  12412.         s = "";
  12413.         for (k = 0, j = 0, i = 0; i < z_maxchan; i++) {
  12414.         if (z_file)
  12415.           if (z_file[i])
  12416.             if (z_file[i]->z_fp) { k++; j = i; }
  12417.         }
  12418.         if (k == 1) s = ckitoa(j);
  12419.      }
  12420.           cmfdbi(&nu,                   /* Second FDB - channel number */
  12421.                  _CMNUM,                /* fcode */
  12422.                  "Channel number or ALL", /* Help message */
  12423.                  s,            /* default */
  12424.                  "",                    /* addtl string data */
  12425.                  10,                    /* addtl numeric data 1: radix */
  12426.                  0,                     /* addtl numeric data 2: 0 */
  12427.                  xxstring,              /* Processing function */
  12428.                  NULL,                  /* Keyword table */
  12429.                  &sw            /* Pointer to next FDB */
  12430.                  );                     /* Pointer to next FDB */
  12431.      cmfdbi(&sw,            /* First FDB - command switches */
  12432.                  _CMKEY,                /* fcode */
  12433.                  "",            /* help message */
  12434.          "",            /* Default */
  12435.          "",            /* No addtl string data */
  12436.                  1,                     /* addtl numeric data 1: tbl size */
  12437.                  0,                     /* addtl numeric data 2: 4 = cmswi */
  12438.                  xxstring,              /* Processing function */
  12439.                  fclkwtab,              /* Keyword table */
  12440.          NULL            /* Last in chain */
  12441.                  );
  12442.         x = cmfdb(&nu);                 /* Parse something */
  12443.         if (x < 0) {
  12444.             if (x == -3) {
  12445.                 printf("?Channel number or ALL required\n");
  12446.                 x = -9;
  12447.             }
  12448.             return(x);
  12449.         }
  12450.         if (cmresult.fcode == _CMNUM)
  12451.           n = cmresult.nresult;
  12452.         else if (cmresult.fcode == _CMKEY)
  12453.           n = -1;
  12454.         if ((x = cmcfm()) < 0)
  12455.           return(x);
  12456.     if (n == -9) return(success = 0);
  12457.     if (n == -8) return(success = 1);
  12458.  
  12459.         rc = 1;
  12460.         if (n < 0) {
  12461.             int count = 0;
  12462.             int i;
  12463.             for (i = 0; i < z_maxchan; i++) {
  12464.                 x = z_close(i);
  12465.                 if (x == FX_SYS) {
  12466.                     printf("?CLOSE failed - Channel %d: %s\n",n,ckferror(x));
  12467.                     rc = 0;
  12468.                 } else if (x > -1)
  12469.                   count++;
  12470.             }
  12471.             debug(F101,"FILE CLOSE ALL","",count);
  12472.         } else if ((x = z_close(n)) < 0) {
  12473.             printf("?CLOSE failed - Channel %d: %s\n",n,ckferror(x));
  12474.             return(-9);
  12475.         }
  12476.         return(success = rc);
  12477.  
  12478.       case FIL_REA:                     /* READ */
  12479.       case FIL_WRI:                     /* WRITE */
  12480.         rsize = 0;
  12481.         cmfdbi(&sw,                     /* Switches */
  12482.                _CMKEY,                  /* fcode */
  12483.                "Channel or switch",     /* hlpmsg */
  12484.                "",                      /* default */
  12485.                "",                      /* addtl string data */
  12486.                (cx == FIL_REA) ? nfrdtab : nfwrtab,
  12487.                4,                       /* addtl numeric data 2: 4 = cmswi */
  12488.                xxstring,                /* Processing function */
  12489.                (cx == FIL_REA) ? frdtab : fwrtab, /* Keyword table */
  12490.                &nu                      /* Pointer to next FDB */
  12491.                );
  12492.         cmfdbi(&nu,                     /* Channel number */
  12493.                _CMNUM,                  /* fcode */
  12494.                "Channel",
  12495.                "",                      /* default */
  12496.                "",                      /* addtl string data */
  12497.                10,                      /* addtl numeric data 1: radix */
  12498.                0,                       /* addtl numeric data 2: 0 */
  12499.                xxstring,                /* Processing function */
  12500.                NULL,                    /* Keyword table */
  12501.                NULL                     /* Pointer to next FDB */
  12502.                );
  12503.         do {
  12504.             x = cmfdb(&sw);             /* Parse something */
  12505.             if (x < 0) {
  12506.                 if (x == -3) {
  12507.                     printf("?Channel number required\n");
  12508.                     x = -9;
  12509.                 }
  12510.                 return(x);
  12511.             }
  12512.             if (cmresult.fcode == _CMNUM) /* Channel number */
  12513.               break;
  12514.             else if (cmresult.fcode == _CMKEY) { /* Switch */
  12515.                 char c;
  12516.                 c = cmgbrk();
  12517.                 if ((getval =
  12518.                      (c == ':' || c == '=')) && !(cmgkwflgs() & CM_ARG)) {
  12519.                     printf("?This switch does not take an argument\n");
  12520.                     return(-9);
  12521.                 }
  12522.                 if (!getval && (cmgkwflgs() & CM_ARG)) {
  12523.                     printf("?This switch requires an argument\n");
  12524.                     return(-9);
  12525.                 }
  12526.                 switch (cmresult.nresult) {
  12527.                   case WR_LINE:
  12528.                     charflag = 0;
  12529.                     sizeflag = 0;
  12530.                     rsize = 0;
  12531.                     break;
  12532.                   case WR_CHAR:
  12533.                     rsize = 1;
  12534.                     charflag = 1;
  12535.                     sizeflag = 1;
  12536.                     break;
  12537.                   case WR_SIZE:
  12538.                     if ((x = cmnum("Bytes","",10,&rsize, xxstring)) < 0) {
  12539.                         if (x == -3) {
  12540.                             printf("?Number required\n");
  12541.                             x = -9;
  12542.                         }
  12543.                         return(x);
  12544.                     }
  12545.             if (rsize > LINBUFSIZ) {
  12546.             printf("?Maximum FREAD/FWRITE size is %d\n",LINBUFSIZ);
  12547.             rsize = 0;
  12548.             return(-9);
  12549.             }
  12550.                     charflag = 0;
  12551.                     sizeflag = 1;
  12552.                     break;
  12553.                   case WR_STRI:
  12554.                     rsize = 1;
  12555.                     charflag = 0;
  12556.                     sizeflag = 0;
  12557.                     break;
  12558.                   case WR_LPAD:
  12559.                   case WR_RPAD:
  12560.                     if ((x = cmnum("Numeric ASCII character value",
  12561.                                    "32",10,&pad, xxstring)) < 0)
  12562.                       return(x);
  12563.                     if (cmresult.nresult == WR_LPAD)
  12564.                       wr_lpad = 1;
  12565.                     else
  12566.                       wr_rpad = 1;
  12567.                     break;
  12568.           case RD_TRIM:
  12569.             rd_trim = 1;
  12570.             break;
  12571.           case RD_UNTA:
  12572.             rd_untab = 1;
  12573.             break;
  12574.                 }
  12575.                 debug(F101,"FILE READ rsize 2","",rsize);
  12576.             } else
  12577.               return(-2);
  12578.         } while
  12579.           (cmresult.fcode == _CMKEY);
  12580.  
  12581.         n = cmresult.nresult;           /* Channel */
  12582.         debug(F101,"FILE READ/WRITE channel","",n);
  12583.  
  12584.         if (cx == FIL_WRI) {            /* WRITE */
  12585.             int len = 0;
  12586.             if ((x = cmtxt("Text","",&s,xxstring)) < 0)
  12587.               return(x);
  12588.         if (n == -9) return(success = 0);
  12589.         if (n == -8) return(success = 1);
  12590.  
  12591.             ckstrncpy(line,s,LINBUFSIZ); /* Make a safe copy */
  12592.             s = line;
  12593.             s = brstrip(s);             /* Strip braces */
  12594.             if (charflag) {             /* Write one char */
  12595.                 len = 1;                /* So length = 1 */
  12596.                 rsize = 1;              /* Don't supply terminator */
  12597.             } else if (!sizeflag) {     /* Write a string */
  12598.                 len = -1;               /* So length is unspecified */
  12599.             } else {                    /* Write a block of given size */
  12600.                 int i, k, xx;
  12601.                 if (rsize > TMPBUFSIZ) {
  12602.                     z_error = FX_OFL;
  12603.                     printf("?Buffer overflow\n");
  12604.                     return(-9);
  12605.                 }
  12606.                 len = rsize;            /* rsize is really length */
  12607.                 rsize = 1;              /* Don't supply a terminator */
  12608.                 xx = strlen(s);         /* Size of given string */
  12609.                 if (xx >= len) {        /* Bigger or equal */
  12610.                     s[len] = NUL;
  12611.                 } else if (wr_lpad) {   /* Smaller, left-padding requested */
  12612.                     for (i = 0; i < len - xx; i++) /* Must make a copy */
  12613.                       tmpbuf[i] = pad;
  12614.                     ckstrncpy(tmpbuf+i,s,TMPBUFSIZ-i);
  12615.                     tmpbuf[len] = NUL;
  12616.                     s = tmpbuf;         /* Redirect write source */
  12617.                 } else if (wr_rpad) {   /* Smaller with right-padding */
  12618.                     for (i = xx; i < len; i++)
  12619.                       s[i] = pad;
  12620.                     s[len] = NUL;
  12621.                 }
  12622.             }
  12623.             if ((rc = z_out(n,s,len,rsize)) < 0) { /* Try to write */
  12624.                 printf("?Channel %d WRITE error: %s\n",n,ckferror(rc));
  12625.                 return(-9);
  12626.             }
  12627.         } else {                        /* FIL_REA READ */
  12628.             confirmed = 0;
  12629.             vnambuf[0] = NUL;
  12630.             x = cmfld("Variable name","",&s,NULL);
  12631.             debug(F111,"FILE READ cmfld",s,x);
  12632.             if (x < 0) {
  12633.                 if (x == -3 || !*s) {
  12634.                     if ((x = cmcfm()) < 0)
  12635.                       return(x);
  12636.                     else
  12637.                       confirmed++;
  12638.                 } else
  12639.                   return(x);
  12640.             }
  12641.             ckstrncpy(vnambuf,s,VNAML);
  12642.             debug(F111,"FILE READ vnambuf",vnambuf,confirmed);
  12643.             if (vnambuf[0]) {           /* Variable name given, check it */
  12644.                 if (!confirmed) {
  12645.                     x = cmcfm();
  12646.                     if (x < 0)
  12647.                       return(x);
  12648.                     else
  12649.                       confirmed++;
  12650.                 }
  12651.                 vnp = vnambuf;
  12652.                 if (vnambuf[0] == CMDQ &&
  12653.                     (vnambuf[1] == '%' || vnambuf[1] == '&'))
  12654.                   vnp++;
  12655.                 y = 0;
  12656.                 if (*vnp == '%' || *vnp == '&') {
  12657.                     if ((y = parsevar(vnp,&x,&dummy)) < 0) {
  12658.                         printf("?Syntax error in variable name\n");
  12659.                         return(-9);
  12660.                     }
  12661.                 }
  12662.             }
  12663.             debug(F111,"FILE READ variable",vnambuf,confirmed);
  12664.  
  12665.             if (!confirmed)
  12666.               if ((x = cmcfm()) < 0)
  12667.                 return(x);
  12668.  
  12669.         if (n == -9) return(success = 0);
  12670.         if (n == -8) return(success = 1);
  12671.  
  12672.             line[0] = NUL;              /* Clear destination buffer */
  12673. #ifdef COMMENT
  12674.             if (rsize >= LINBUFSIZ)     /* Don't overrun it */
  12675.               rsize = LINBUFSIZ - 1;
  12676. #endif    /* COMMENT */
  12677.  
  12678.             if (rsize == 0) {        /* Read a line */
  12679.         rc = z_in(n,line,LINBUFSIZ,LINBUFSIZ-1,0);
  12680.             } else {
  12681.         rc = z_in(n,line,LINBUFSIZ,rsize,1); /* Read a block */
  12682.         }
  12683.             if (rc < 0) {               /* Error... */
  12684.                 debug(F101,"FILE READ error","",rc);
  12685.                 debug(F101,"FILE READ errno","",errno);
  12686.                 if (rc == FX_EOF) {     /* EOF - fail but no error message */
  12687.                     return(success = 0);
  12688.                 } else {                /* Other error - fail and print msg */
  12689.                     printf("?READ error: %s\n",ckferror(rc));
  12690.                     return(-9);
  12691.                 }
  12692.             }
  12693.         if (rsize == 0) {        /* FREAD /LINE postprocessing */
  12694.         if (rd_trim) {        /* Trim */
  12695.             int i, k;
  12696.             k = strlen(line);
  12697.             if (k > 0) {
  12698.             for (i = k-1; i > 0; i--) {
  12699.                 if (line[i] == SP || line[i] == '\t')
  12700.                   line[i] = NUL;
  12701.                 else
  12702.                   break;
  12703.             }
  12704.             }
  12705.         }
  12706.         if (rd_untab) {        /* Untabify */
  12707.             if (untabify(line,tmpbuf,TMPBUFSIZ) > -1)
  12708.               ckstrncpy(line,tmpbuf,LINBUFSIZ);
  12709.         }
  12710.         }
  12711.             debug(F110,"FILE READ data",line,0);
  12712.             if (vnambuf[0])             /* Read OK - If variable name given */
  12713.               addmac(vnambuf,line);     /* Assign result to variable */
  12714.             else                        /* otherwise */
  12715.               printf("%s\n",line);      /* just print it */
  12716.         }
  12717.         return(success = 1);
  12718.  
  12719.       case FIL_SEE:                     /* SEEK */
  12720.       case FIL_COU:                     /* COUNT */
  12721.         rsize = RD_CHAR;                /* Defaults to /BYTE */
  12722.         cmfdbi(&sw,                     /* Switches */
  12723.                _CMKEY,                  /* fcode */
  12724.                "Channel or switch",     /* hlpmsg */
  12725.                "",                      /* default */
  12726.                "",                      /* addtl string data */
  12727.                ((cx == FIL_SEE) ? nfskswtab : nfcoswtab),
  12728.                4,                       /* addtl numeric data 2: 4 = cmswi */
  12729.                xxstring,                /* Processing function */
  12730.                ((cx == FIL_SEE) ? fskswtab : fcoswtab),
  12731.                &nu                      /* Pointer to next FDB */
  12732.                );
  12733.         cmfdbi(&nu,                     /* Channel number */
  12734.                _CMNUM,                  /* fcode */
  12735.                "Channel",
  12736.                "",                      /* default */
  12737.                "",                      /* addtl string data */
  12738.                10,                      /* addtl numeric data 1: radix */
  12739.                0,                       /* addtl numeric data 2: 0 */
  12740.                xxstring,                /* Processing function */
  12741.                NULL,                    /* Keyword table */
  12742.                NULL                     /* Pointer to next FDB */
  12743.                );
  12744.         do {
  12745.             x = cmfdb(&sw);             /* Parse something */
  12746.             if (x < 0) {
  12747.                 if (x == -3) {
  12748.                     printf("?Channel number required\n");
  12749.                     x = -9;
  12750.                 }
  12751.                 return(x);
  12752.             }
  12753.             if (cmresult.fcode == _CMNUM) /* Channel number */
  12754.               break;
  12755.             else if (cmresult.fcode == _CMKEY) { /* Switch */
  12756.                 char c;
  12757.                 c = cmgbrk();
  12758.                 if ((getval =
  12759.                      (c == ':' || c == '=')) && !(cmgkwflgs() & CM_ARG)) {
  12760.                     printf("?This switch does not take an argument\n");
  12761.                     return(-9);
  12762.                 }
  12763.                 if (cx == FIL_SEE) {
  12764.                     switch (cmresult.nresult) {
  12765.                       case SEE_REL: relative = 1; break;
  12766.                       case SEE_ABS: relative = 0; break;
  12767.               case SEE_FIND: {
  12768.               if (getval) {
  12769.                   y = cmfld("string or pattern","",&s,xxstring);
  12770.                   if (y < 0)
  12771.                 return(y);
  12772.                   makestr(&seek_target,brstrip(s));
  12773.                   break;
  12774.               }
  12775.               }
  12776.                       default: rsize = cmresult.nresult;
  12777.                     }
  12778.                 } else if (cx == FIL_COU) {
  12779.                     switch (cmresult.nresult) {
  12780.                       case COU_LIS: listing = 1; break;
  12781.                       case COU_NOL: listing = 0; break;
  12782.                       default: rsize = cmresult.nresult;
  12783.                     }
  12784.                 }
  12785.             }
  12786.         } while
  12787.           (cmresult.fcode == _CMKEY);
  12788.  
  12789.         n = cmresult.nresult;           /* Channel */
  12790.         debug(F101,"FILE SEEK/COUNT channel","",n);
  12791.         if (cx == FIL_COU) {
  12792.             if ((x = cmcfm()) < 0)
  12793.               return(x);
  12794.         if (n == -9) return(success = 0);
  12795.         if (n == -8) return(success = 1);
  12796.  
  12797.             z_filcount = z_count(n,rsize);
  12798.             if (z_filcount < 0) {
  12799.                 rc = z_filcount;
  12800.                 printf("?COUNT error: %s\n",ckferror(rc));
  12801.                 return(-9);
  12802.             }
  12803.             if (listing < 0)
  12804.               listing = !xcmdsrc;
  12805.             if (listing)
  12806.               printf(" %ld %s%s\n",
  12807.                      z_filcount,
  12808.                      ((rsize == RD_CHAR) ? "byte" : "line"),
  12809.                      ((z_filcount == 1L) ? "" : "s")
  12810.                      );
  12811.             return(success = (z_filcount > -1) ? 1 : 0);
  12812.         }
  12813.     m = (rsize == RD_CHAR) ?
  12814.         "Number of bytes;\n or keyword" :
  12815.         "Number of lines;\n or keyword";
  12816.         cmfdbi(&sw,                     /* SEEK symbolic targets (EOF) */
  12817.                _CMKEY,                  /* fcode */
  12818.                m,
  12819.                "",
  12820.                "",                      /* addtl string data */
  12821.                nfsekwtab,               /* addtl numeric data 1: table size */
  12822.                0,                       /* addtl numeric data 2: 4 = cmswi */
  12823.                xxstring,                /* Processing function */
  12824.                fsekwtab,                /* Keyword table */
  12825.                &nu                      /* Pointer to next FDB */
  12826.                );
  12827.         cmfdbi(&nu,                     /* Byte or line number */
  12828.                _CMNUW,                  /* fcode */
  12829.                "",
  12830.                "",                      /* default */
  12831.                "",                      /* addtl string data */
  12832.                10,                      /* addtl numeric data 1: radix */
  12833.                0,                       /* addtl numeric data 2: 0 */
  12834.                xxstring,                /* Processing function */
  12835.                NULL,                    /* Keyword table */
  12836.                NULL                     /* Pointer to next FDB */
  12837.                );
  12838.         x = cmfdb(&sw);                 /* Parse something */
  12839.         if (x < 0) {
  12840.             if (x == -3) {
  12841.                 printf("?Channel number or EOF required\n");
  12842.                 x = -9;
  12843.             }
  12844.             return(x);
  12845.         }
  12846.         if (cmresult.fcode == _CMNUW) {
  12847.             z = cmresult.wresult;
  12848.             debug(F110,"FILE SEEK atmbuf",atmbuf,0);
  12849.             if (relative < 0) {
  12850.                 if (cx == FIL_SEE && (atmbuf[0] == '+' || atmbuf[0] == '-'))
  12851.                   relative = 1;
  12852.                 else
  12853.                   relative = 0;
  12854.             }
  12855.         } else if (cmresult.fcode == _CMKEY) {
  12856.             eofflg = cmresult.nresult;
  12857.             relative = 0;
  12858.             y = 0 - eofflg;
  12859.         }
  12860.         if ((x = cmcfm()) < 0)
  12861.           return(x);
  12862.     if (n == -9) return(success = 0);
  12863.     if (n == -8) return(success = 1);
  12864.         y = 1;                          /* Recycle this */
  12865.         z_flush(n);
  12866.         debug(F101,"FILE SEEK relative","",relative);
  12867.         debug(F101,"FILE SEEK rsize","",rsize);
  12868.  
  12869.         if (rsize == RD_CHAR) {         /* Seek to byte position */
  12870.             if (relative > 0) {
  12871.                 CK_OFF_T pos;
  12872.                 pos = z_getpos(n);
  12873.                 if (pos < (CK_OFF_T)0) {
  12874.                     rc = pos;
  12875.                     printf("?Relative SEEK failed: %s\n",ckferror(rc));
  12876.                     return(-9);
  12877.                 }
  12878.                 z += pos;
  12879.             } else {
  12880.                 if (z < 0 && !eofflg) { /* Negative arg but not relative */
  12881.                     y = 0;              /* Remember this was bad */
  12882.                     z = 0;              /* but substitute 0 */
  12883.                 }
  12884.             }
  12885.             debug(F101,"FILE SEEK /CHAR z","",z);
  12886.             if (z < 0 && !eofflg) {
  12887.                 z_error = FX_RNG;
  12888.                 return(success = 0);
  12889.             }
  12890.             if ((rc = z_seek(n,z)) < 0) {
  12891.                 if (rc == FX_EOF) return(success = 0);
  12892.                 printf("?SEEK /BYTE failed - Channel %d: %s\n",n,ckferror(rc));
  12893.                 return(-9);
  12894.             }
  12895.         } else {                        /* Seek to line */
  12896.             if (relative > 0) {
  12897.                 CK_OFF_T pos;
  12898.                 pos = z_getline(n);
  12899.                 debug(F101,"FILE SEEK /LINE pos","",pos);
  12900.                 if (pos < 0) {
  12901.                     rc = pos;
  12902.                     printf("?Relative SEEK failed: %s\n",ckferror(rc));
  12903.                     return(-9);
  12904.                 }
  12905.                 z += pos;
  12906.             }
  12907.             debug(F101,"FILE SEEK /LINE z","",z);
  12908.             debug(F101,"FILE SEEK /LINE eofflg","",eofflg);
  12909.             if (z < 0 && !eofflg) {
  12910.                 z_error = FX_RNG;
  12911.                 return(success = 0);
  12912.             }
  12913.             if ((rc = z_line(n,z)) < 0) {
  12914.                 if (rc == FX_EOF) return(success = 0);
  12915.                 printf("?SEEK /LINE failed - Channel %d: %s\n",n,ckferror(rc));
  12916.                 return(-9);
  12917.             }
  12918.         }
  12919.     /*
  12920.       Now, having sought to the desired starting spot, if a /FIND:
  12921.       target was specified, look for it now.
  12922.     */
  12923.     if (seek_target) {
  12924.         int flag = 0, ispat = 0, matchresult = 0;
  12925.         while (!flag) {
  12926.         y = z_in(n,line,LINBUFSIZ,LINBUFSIZ-1,0);
  12927.         if (y < 0) {
  12928.             y = 0;
  12929.             break;
  12930.         }
  12931.         if (ispattern(seek_target)) {
  12932.             matchresult = ckmatch(seek_target,line,1,1+4); 
  12933.         } else {
  12934.             /* This is faster */
  12935.             matchresult = ckindex(seek_target,line,0,0,1);
  12936.         }
  12937.         if (matchresult) {
  12938.             flag = 1;
  12939.             break;
  12940.         }
  12941.         }
  12942.         if (flag) {
  12943.         /* Back up to beginning of line where target found */
  12944.         if ((y = z_line(n,z_getline(n)-1)) < 0) {
  12945.             if (rc == FX_EOF) return(success = 0);
  12946.             printf("?SEEK /LINE failed - Channel %d: %s\n",
  12947.                n,ckferror(rc));
  12948.             return(-9);
  12949.         }
  12950.         }
  12951.     }
  12952.         return(success = y);
  12953.  
  12954.       case FIL_LIS: {                   /* LIST open files */
  12955. #ifdef CK_TTGWSIZ
  12956.           extern int cmd_rows, cmd_cols;
  12957. #endif /* CK_TTGWSIZ */
  12958.           extern int xaskmore;
  12959.           int i, x, n = 0, paging = 0;
  12960.           char * s;
  12961.  
  12962.           if ((x = cmcfm()) < 0)
  12963.             return(x);
  12964.  
  12965. #ifdef CK_TTGWSIZ
  12966.           if (cmd_rows > 0 && cmd_cols > 0)
  12967. #endif /* CK_TTGWSIZ */
  12968.             paging = xaskmore;
  12969.  
  12970.           printf("System open file limit:%5d\n", z_openmax);
  12971.           printf("Maximum for FILE OPEN: %5d\n", z_maxchan);
  12972.           printf("Files currently open:  %5d\n\n", z_nopen);
  12973.           n = 4;
  12974.           for (i = 0; i < z_maxchan; i++) {
  12975.               s = z_getname(i);         /* Got one? */
  12976.               if (s) {                  /* Yes */
  12977.                   char m[8];
  12978.                   m[0] = NUL;
  12979.                   printf("%2d. %s",i,s); /* Print name */
  12980.                   n++;                   /* Count it */
  12981.                   x = z_getmode(i);      /* Get modes & print them */
  12982.                   if (x > 0) {
  12983.                       if (x & FM_REA) ckstrncat(m,"R",8);
  12984.                       if (x & FM_WRI) ckstrncat(m,"W",8);
  12985.                       if (x & FM_APP) ckstrncat(m,"A",8);
  12986.                       if (x & FM_BIN) ckstrncat(m,"B",8);
  12987.                       if (m[0])
  12988.                         printf(" (%s)",m);
  12989.                       if (x & FM_EOF)
  12990.                         printf(" [EOF]");
  12991.                       else        /* And file position too */
  12992.                         printf(" %s",ckfstoa(z_getpos(i)));
  12993.                   }
  12994.                   printf("\n");
  12995. #ifdef CK_TTGWSIZ
  12996.                   if (paging > 0) {     /* Pause at end of screen */
  12997.                       if (n > cmd_rows - 3) {
  12998.                           if (!askmore())
  12999.                             break;
  13000.                           else
  13001.                             n = 0;
  13002.                       }
  13003.                   }
  13004. #endif /* CK_TTGWSIZ */
  13005.               }
  13006.           }
  13007.           return(success = 1);
  13008.       }
  13009.  
  13010.       case FIL_FLU:                     /* FLUSH */
  13011.         if ((x = cmnum("Channel number","",10,&n, xxstring)) < 0) {
  13012.             if (x == -3) {
  13013.                 printf("?Channel number required\n");
  13014.                 x = -9;
  13015.             }
  13016.             return(x);
  13017.         }
  13018.         if ((x = cmcfm()) < 0)
  13019.           return(x);
  13020.     if (n == -9) return(success = 0);
  13021.     if (n == -8) return(success = 1);
  13022.         if ((rc = z_flush(n)) < 0) {
  13023.             printf("?FLUSH failed - Channel %d: %s\n",n,ckferror(rc));
  13024.             return(-9);
  13025.         }
  13026.         return(success = 1);
  13027.  
  13028.       case FIL_STA:                     /* STATUS */
  13029.     {
  13030.         int i, j, k;        /* Supply default if only one open */
  13031.         s = "";
  13032.         for (k = 0, j = 0, i = 0; i < z_maxchan; i++) {
  13033.         if (z_file)
  13034.           if (z_file[i])
  13035.             if (z_file[i]->z_fp) { k++; j = i; }
  13036.         }
  13037.         if (k == 1) s = ckitoa(j);
  13038.     }
  13039.         if ((x = cmnum("Channel number",s,10,&n, xxstring)) < 0) {
  13040.             if (x == -3) {
  13041.         if (z_nopen > 1) {
  13042.             printf("?%d files open - please supply channel number\n",
  13043.                z_nopen);
  13044.             return(-9);
  13045.         }
  13046.             } else
  13047.           return(x);
  13048.         }
  13049.         if ((y = cmcfm()) < 0)
  13050.           return(y);
  13051.     if ((!z_file || z_nopen == 0) && x == -3) {
  13052.         printf("No files open\n");
  13053.         return(success = 1);
  13054.     }
  13055.         p = blanks + 3;                 /* Tricky formatting... */
  13056.         if (n < 1000) p--;
  13057.         if (n < 100) p--;
  13058.         if (n < 10) p--;
  13059.         if ((rc = z_getmode(n)) < 0) {
  13060.             printf("Channel %d:%s%s\n",n,p,ckferror(rc));
  13061.             return(success = 0);
  13062.         } else if (!rc) {
  13063.             printf("Channel %d:%sNot open\n",n,p);
  13064.             return(success = 0);
  13065.         } else {
  13066.             CK_OFF_T xx;
  13067.             s = z_getname(n);
  13068.             if (!s) s = "(name unknown)";
  13069.             printf("Channel %d:%sOpen\n",n,p);
  13070.             printf(" File:        %s\n Modes:      ",s);
  13071.             if (rc & FM_REA) printf(" /READ");
  13072.             if (rc & FM_WRI) printf(" /WRITE");
  13073.             if (rc & FM_APP) printf(" /APPEND");
  13074.             if (rc & FM_BIN) printf(" /BINARY");
  13075.             if (rc & FM_CMD) printf(" /COMMAND");
  13076.             if (rc & FM_EOF) printf(" [EOF]");
  13077.             printf("\n Size:        %s\n",ckfstoa(z_count(n,RD_CHAR)));
  13078.             printf(" At byte:     %s\n",ckfstoa(z_getpos(n)));
  13079.             xx = z_getline(n);
  13080.             if (xx > (CK_OFF_T)-1)
  13081.               printf(" At line:     %s\n",ckfstoa(xx));
  13082.             return(success = 1);
  13083.         }
  13084.       default:
  13085.         return(-2);
  13086.     }
  13087. }
  13088. #endif /* CKCHANNELIO */
  13089.  
  13090. #ifndef NOSETKEY
  13091. /* Save Key maps and in OS/2 Mouse maps */
  13092. int
  13093. savkeys(name,disp) char * name; int disp; {
  13094.     char *tp;
  13095.     static struct filinfo xx;
  13096.     int savfil, i, j, k;
  13097.     char buf[1024];
  13098.  
  13099.     zclose(ZMFILE);
  13100.  
  13101.     if (disp) {
  13102.         xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  13103.         xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = "";
  13104.         xx.lblopts = 0;
  13105.         savfil = zopeno(ZMFILE,name,NULL,&xx);
  13106.     } else savfil = zopeno(ZMFILE,name,NULL,NULL);
  13107.  
  13108.     if (savfil) {
  13109. #ifdef OS2
  13110.         ztime(&tp);
  13111.         zsout(ZMFILE, "; Kermit 95 SAVE KEYMAP file: ");
  13112.         zsoutl(ZMFILE,tp);
  13113.         if (mskkeys) {
  13114.             zsoutl(ZMFILE,
  13115.          "if eq \"\\v(program)\" \"C-Kermit\" set mskermit keycodes on");
  13116.         } else {
  13117.             zsoutl(ZMFILE,
  13118.          "if NOT eq \"\\v(program)\" \"C-Kermit\" stop 1 C-Kermit required.");
  13119.             zsoutl(ZMFILE,"set mskermit keycodes off");
  13120.         }
  13121.         zsoutl(ZMFILE,"");
  13122. #else /* OS2 */
  13123.         ztime(&tp);
  13124.         zsout(ZMFILE, "; C-Kermit SAVE KEYMAP file: ");
  13125.         zsoutl(ZMFILE,tp);
  13126. #endif /* OS2 */
  13127.  
  13128.         zsoutl(ZMFILE,"; Clear previous keyboard mappings ");
  13129.         zsoutl(ZMFILE,"set key clear");
  13130. #ifdef OS2
  13131.         for (k = 0; k < nttkey; k++) {
  13132.             if (!ttkeytab[k].flgs) {
  13133.                 ckmakmsg(buf,1024,
  13134.                          "set terminal key ",
  13135.                          ttkeytab[k].kwd,
  13136.                          " clear",
  13137.                          NULL
  13138.                          );
  13139.                 zsoutl(ZMFILE,buf);
  13140.             }
  13141.         }
  13142. #endif /* OS2 */
  13143.         zsoutl(ZMFILE,"");
  13144.  
  13145.         for (i = 0; i < KMSIZE; i++) {
  13146.             if (macrotab[i]) {
  13147.                 int len = strlen((char *)macrotab[i]);
  13148. #ifdef OS2
  13149.                 ckmakmsg(buf,
  13150.                          1024,
  13151.                          "set key \\",
  13152.                          ckitoa(mskkeys ? cktomsk(i) : i),
  13153.                          " ",
  13154.                          NULL
  13155.                          );
  13156. #else /* OS2 */
  13157.                 ckmakmsg(buf,
  13158.                          1024,
  13159.                          "set key \\",
  13160.                          ckitoa(i),
  13161.                          NULL,NULL
  13162.                          );
  13163. #endif /* OS2 */
  13164.                 zsout(ZMFILE,buf);
  13165.  
  13166.                 for (j = 0; j < len; j++) {
  13167.                     char ch = macrotab[i][j];
  13168.                     if (ch <= SP || ch >= DEL ||
  13169.                          ch == '-' || ch == ',' ||
  13170.                          ch == '{' || ch == '}' ||
  13171.                          ch == ';' || ch == '?' ||
  13172.                          ch == '.' || ch == '\'' ||
  13173.                          ch == '\\' || ch == '/' ||
  13174.                          ch == '#') {
  13175.                         ckmakmsg(buf,1024,"\\{",ckitoa((int)ch),"}",NULL);
  13176.                         zsout(ZMFILE,buf);
  13177.                     } else {
  13178.                         ckmakmsg(buf,1024,ckctoa((char)ch),NULL,NULL,NULL);
  13179.                         zsout(ZMFILE,buf);
  13180.                     }
  13181.                 }
  13182. #ifdef OS2
  13183.                 ckmakmsg(buf,1024,"\t; ",keyname(i),NULL,NULL);
  13184.                 zsoutl(ZMFILE,buf);
  13185. #else
  13186.                 zsoutl(ZMFILE,"");
  13187. #endif /* OS2 */
  13188.             } else if ( keymap[i] != i ) {
  13189. #ifndef NOKVERBS
  13190.                 if (IS_KVERB(keymap[i])) {
  13191.                     for (j = 0; j < nkverbs; j++)
  13192.                       if (kverbs[j].kwval == (keymap[i] & ~F_KVERB))
  13193.                         break;
  13194.                     if (j != nkverbs) {
  13195. #ifdef OS2
  13196. #ifdef COMMENT
  13197.                         sprintf(buf, "set key \\%d \\K%s\t; %s",
  13198.                                 mskkeys ? cktomsk(i) : i,
  13199.                                 kverbs[j].kwd, keyname(i)
  13200.                                 );
  13201. #else
  13202.                         ckmakxmsg(buf,  /* 12 string args */
  13203.                                   1024,
  13204.                                   "set key \\",
  13205.                                   ckitoa(mskkeys ? cktomsk(i) : i),
  13206.                                   " \\K",
  13207.                                   kverbs[j].kwd,
  13208.                                   "\t; ",
  13209.                                   keyname(i),
  13210.                                   NULL, NULL, NULL, NULL, NULL, NULL);
  13211. #endif /* COMMENT */
  13212.                         zsoutl(ZMFILE,buf);
  13213. #else
  13214. #ifdef COMMENT
  13215.                         sprintf(buf, "set key \\%d \\K%s", i, kverbs[j].kwd);
  13216. #else
  13217.                         ckmakmsg(buf,1024,
  13218.                                  "set key \\",
  13219.                                  ckitoa(i),
  13220.                                  " \\K",
  13221.                                  kverbs[j].kwd
  13222.                                  );
  13223. #endif /* COMMENT */
  13224.                         zsoutl(ZMFILE,buf);
  13225. #endif
  13226.                     }
  13227.                 } else
  13228. #endif /* NOKVERBS */
  13229.                   {
  13230. #ifdef OS2
  13231. #ifdef COMMENT
  13232.                       sprintf(buf, "set key \\%d \\{%d}\t; %s",
  13233.                               mskkeys ? cktomsk(i) : i,
  13234.                               keymap[i],
  13235.                               keyname(i)
  13236.                               );
  13237. #else
  13238.                       ckmakxmsg(buf,    /* 8 string args */
  13239.                                 1024,
  13240.                                 "set key \\",
  13241.                                 ckitoa(mskkeys ? cktomsk(i) : i),
  13242.                                 " \\{",
  13243.                                 ckitoa(keymap[i]),
  13244.                                 "}\t; ",
  13245.                                 keyname(i),
  13246.                                 NULL,NULL,NULL,NULL,NULL,NULL);
  13247. #endif /* COMMENT */
  13248.                       zsoutl(ZMFILE,buf);
  13249. #else
  13250. #ifdef COMMENT
  13251.                       sprintf(buf, "set key \\%d \\{%d}", i, keymap[i]);
  13252. #else
  13253.                       ckmakxmsg(buf,1024,
  13254.                                "set key \\",
  13255.                                ckitoa(i),
  13256.                                " \\{",
  13257.                                ckitoa(keymap[i]),
  13258.                                "}",
  13259.                                NULL,NULL,NULL,NULL,NULL,NULL,NULL);
  13260. #endif /* COMMENT */
  13261.                       zsoutl(ZMFILE,buf);
  13262. #endif /* OS2 */
  13263.                   }
  13264.             }
  13265.         }
  13266. #ifdef OS2
  13267.         /* OS/2 also has the SET TERMINAL KEY <termtype> defines */
  13268.         for (k = 0; k < nttkey; k++) {
  13269.             extern struct keynode * ttkeymap[];
  13270.             struct keynode * pnode = NULL;
  13271.  
  13272.             if (ttkeytab[k].flgs)       /* Don't process CM_INV or CM_ABR */
  13273.               continue;
  13274.  
  13275.             zsoutl(ZMFILE,"");
  13276.             ckmakmsg(buf,1024,"; SET TERMINAL KEY ",ttkeytab[k].kwd,NULL,NULL);
  13277.             zsoutl(ZMFILE,buf);
  13278.  
  13279.             for (pnode = ttkeymap[ttkeytab[k].kwval];
  13280.                  pnode;
  13281.                  pnode = pnode->next
  13282.                  ) {
  13283.                 switch (pnode->def.type) {
  13284.                   case key:
  13285. #ifdef COMMENT
  13286.                     sprintf(buf, "set terminal key %s \\%d \\{%d}\t; %s",
  13287.                             ttkeytab[k].kwd,
  13288.                             mskkeys ? cktomsk(pnode->key) : pnode->key,
  13289.                             pnode->def.key.scancode,
  13290.                             keyname(pnode->key)
  13291.                             );
  13292. #else
  13293.                     ckmakxmsg(buf,
  13294.                               1024,
  13295.                               "set terminal key ",
  13296.                               ttkeytab[k].kwd,
  13297.                               " \\",
  13298.                               ckitoa(mskkeys ?
  13299.                                      cktomsk(pnode->key) :
  13300.                                      pnode->key),
  13301.                               " \\{",
  13302.                               ckitoa(pnode->def.key.scancode),
  13303.                               "}\t; ",
  13304.                               keyname(pnode->key),
  13305.                               NULL,NULL,NULL,NULL
  13306.                               );
  13307. #endif /* COMMENT */
  13308.                     zsoutl(ZMFILE,buf);
  13309.                     break;
  13310.                   case kverb:
  13311.                     for (j = 0; j < nkverbs; j++)
  13312.                       if (kverbs[j].kwval == (pnode->def.kverb.id & ~F_KVERB))
  13313.                         break;
  13314.                     if (j != nkverbs) {
  13315. #ifdef COMMENT
  13316.                         sprintf(buf, "set terminal key %s \\%d \\K%s\t; %s",
  13317.                                 ttkeytab[k].kwd,
  13318.                                 mskkeys ? cktomsk(pnode->key) : pnode->key,
  13319.                                 kverbs[j].kwd, keyname(pnode->key)
  13320.                                 );
  13321. #else
  13322.                         ckmakxmsg(buf,
  13323.                                   1024,
  13324.                                   "set terminal key ",
  13325.                                   ttkeytab[k].kwd,
  13326.                                   " \\",
  13327.                                   ckitoa(mskkeys ?
  13328.                                          cktomsk(pnode->key) :
  13329.                                          pnode->key),
  13330.                                   " \\K",
  13331.                                   kverbs[j].kwd,
  13332.                                   "\t; ",
  13333.                                   keyname(pnode->key),
  13334.                                   NULL,NULL,NULL,NULL
  13335.                                   );
  13336. #endif /* COMMENT */
  13337.                         zsoutl(ZMFILE,buf);
  13338.                     }
  13339.                     break;
  13340.                   case macro: {
  13341.                       int len = strlen((char *)pnode->def.macro.string);
  13342. #ifdef COMMENT
  13343.                       sprintf(buf,"set terminal key %s \\%d ",
  13344.                               ttkeytab[k].kwd,
  13345.                               mskkeys ? cktomsk(pnode->key) : pnode->key);
  13346. #else
  13347.                       ckmakxmsg(buf,
  13348.                                1024,
  13349.                                "set terminal key ",
  13350.                                ttkeytab[k].kwd,
  13351.                                " \\",
  13352.                                ckitoa(mskkeys ?
  13353.                                       cktomsk(pnode->key) :
  13354.                                       pnode->key),
  13355.                                " ",
  13356.                                NULL,NULL,NULL,NULL,NULL,NULL,NULL
  13357.                               );
  13358. #endif /* COMMENT */
  13359.                       zsout(ZMFILE,buf);
  13360.  
  13361.                       for (j = 0; j < len; j++) {
  13362.                           char ch = pnode->def.macro.string[j];
  13363.                           if (ch <= SP || ch >= DEL ||
  13364.                                ch == '-' || ch == ',' ||
  13365.                                ch == '{' || ch == '}' ||
  13366.                                ch == ';' || ch == '?' ||
  13367.                                ch == '.' || ch == '\'' ||
  13368.                                ch == '\\' || ch == '/' ||
  13369.                                ch == '#') {
  13370.                               ckmakmsg(buf,1024,
  13371.                                        "\\{",ckitoa((int)ch),"}",NULL);
  13372.                               zsout(ZMFILE,buf);
  13373.                           } else {
  13374.                               ckmakmsg(buf,1024,
  13375.                                        ckctoa((char)ch),NULL,NULL,NULL);
  13376.                               zsout(ZMFILE,buf);
  13377.                           }
  13378.                       }
  13379.                       ckmakmsg(buf,1024,"\t; ",keyname(pnode->key),NULL,NULL);
  13380.                       zsoutl(ZMFILE,buf);
  13381.                       break;
  13382.                   }
  13383.                   case literal: {
  13384.                       int len = strlen((char *)pnode->def.literal.string);
  13385. #ifdef COMMENT
  13386.                       sprintf(buf,"set terminal key %s /literal \\%d ",
  13387.                               ttkeytab[k].kwd,
  13388.                               mskkeys ? cktomsk(pnode->key) : pnode->key);
  13389. #else
  13390.                       ckmakxmsg(buf,
  13391.                                1024,
  13392.                                "set terminal key ",
  13393.                                ttkeytab[k].kwd,
  13394.                                " /literal \\",
  13395.                                ckitoa(mskkeys ?
  13396.                                       cktomsk(pnode->key) :
  13397.                                       pnode->key),
  13398.                                " ",
  13399.                                NULL,NULL,NULL,NULL,NULL,NULL,NULL);
  13400. #endif /* COMMENT */
  13401.                       zsout(ZMFILE,buf);
  13402.  
  13403.                       for (j = 0; j < len; j++) {
  13404.                           char ch = pnode->def.literal.string[j];
  13405.                           if (ch <= SP || ch >= DEL ||
  13406.                                ch == '-' || ch == ',' ||
  13407.                                ch == '{' || ch == '}' ||
  13408.                                ch == ';' || ch == '?' ||
  13409.                                ch == '.' || ch == '\'' ||
  13410.                                ch == '\\' || ch == '/' ||
  13411.                                ch == '#') {
  13412.                               ckmakmsg(buf,1024,
  13413.                                        "\\{",ckitoa((int)ch),"}",NULL);
  13414.                               zsout(ZMFILE,buf);
  13415.                           } else {
  13416.                               ckmakmsg(buf,1024,
  13417.                                        ckctoa((char)ch),NULL,NULL,NULL);
  13418.                               zsout(ZMFILE,buf);
  13419.                           }
  13420.                       }
  13421.                       ckmakmsg(buf,1024,"\t; ",keyname(pnode->key),NULL,NULL);
  13422.                       zsoutl(ZMFILE,buf);
  13423.                       break;
  13424.                   }
  13425.                   case esc:
  13426. #ifdef COMMENT
  13427.                     sprintf(buf,
  13428.                        "set terminal key %s /literal \\%d \\{%d}\\{%d}\t; %s",
  13429.                             ttkeytab[k].kwd,
  13430.                             mskkeys ? cktomsk(pnode->key) : pnode->key,
  13431.                             ISDG200(ttkeytab[k].kwval) ? 30 : 27,
  13432.                             pnode->def.esc.key & ~F_ESC,
  13433.                             keyname(pnode->key)
  13434.                             );
  13435. #else
  13436.                     ckmakxmsg(buf,
  13437.                               1024,
  13438.                               "set terminal key ",
  13439.                               ttkeytab[k].kwd,
  13440.                               " /literal \\",
  13441.                               ckitoa(mskkeys ?
  13442.                                      cktomsk(pnode->key) :
  13443.                                      pnode->key),
  13444.                               " \\{",
  13445.                               ckitoa(ISDG200(ttkeytab[k].kwval) ? 30 : 27),
  13446.                               "}\\{",
  13447.                               ckitoa(pnode->def.esc.key & ~F_ESC),
  13448.                               "}\t; ",
  13449.                               keyname(pnode->key),
  13450.                               NULL,NULL
  13451.                               );
  13452. #endif /* COMMENT */
  13453.                     zsoutl(ZMFILE,buf);
  13454.                     break;
  13455.                   case csi:
  13456. #ifdef COMMENT
  13457.                     sprintf(buf,
  13458.                        "set terminal key %s /literal \\%d \\{27}[\\{%d}\t; %s",
  13459.                             ttkeytab[k].kwd,
  13460.                             mskkeys ? cktomsk(pnode->key) : pnode->key,
  13461.                             pnode->def.csi.key & ~F_CSI,
  13462.                             keyname(pnode->key)
  13463.                             );
  13464. #else
  13465.                     ckmakxmsg(buf,
  13466.                               1024,
  13467.                               "set terminal key ",
  13468.                               ttkeytab[k].kwd,
  13469.                               " /literal \\",
  13470.                               ckitoa(mskkeys ?
  13471.                                      cktomsk(pnode->key) :
  13472.                                      pnode->key),
  13473.                               " \\{27}[\\{",
  13474.                               ckitoa(pnode->def.csi.key & ~F_CSI),
  13475.                               "}\t; ",
  13476.                               keyname(pnode->key),
  13477.                               NULL,NULL,NULL,NULL
  13478.                               );
  13479. #endif /* COMMENT */
  13480.                     zsoutl(ZMFILE,buf);
  13481.                     break;
  13482.                   default:
  13483.                     continue;
  13484.                 }
  13485.             }
  13486.         }
  13487. #endif /* OS2 */
  13488.  
  13489.         zsoutl(ZMFILE,"");
  13490.         zsoutl(ZMFILE,"; End");
  13491.         zclose(ZMFILE);
  13492.         return(success = 1);
  13493.     } else {
  13494.         return(success = 0);
  13495.     }
  13496. }
  13497. #endif /* NOSETKEY */
  13498.  
  13499. #define SV_SCRL 0
  13500. #define SV_HIST 1
  13501.  
  13502. #ifdef OS2
  13503. #ifndef NOLOCAL
  13504. static struct keytab trmtrmopt[] = {
  13505.     { "scrollback", SV_SCRL, 0 }
  13506. };
  13507. #endif /* NOLOCAL */
  13508. #endif /* OS2 */
  13509.  
  13510. static struct keytab cmdtrmopt[] = {
  13511. #ifdef CK_RECALL
  13512.     { "history",    SV_HIST, 0 },
  13513. #endif /* CK_RECALL */
  13514. #ifdef OS2
  13515. #ifndef NOLOCAL
  13516.     { "scrollback", SV_SCRL, 0 },
  13517. #endif /* NOLOCAL */
  13518. #endif /* OS2 */
  13519.     { "", 0, 0 }
  13520. };
  13521. static int ncmdtrmopt = (sizeof (cmdtrmopt) / sizeof (struct keytab)) - 1;
  13522.  
  13523. #ifdef OS2
  13524. #ifndef NOLOCAL
  13525. _PROTOTYP(int savscrbk, (int, char *, int));
  13526. #endif /* NOLOCAL */
  13527. #endif /* OS2 */
  13528.  
  13529. #ifdef CK_RECALL
  13530. _PROTOTYP(int savhistory, (char *, int));
  13531. #endif /* CK_RECALL */
  13532.  
  13533. int
  13534. dosave(xx) int xx; {
  13535.     int x, y = 0, disp;
  13536.     char * s = NULL;
  13537.     extern struct keytab disptb[];
  13538. #ifdef ZFNQFP
  13539.     struct zfnfp * fnp;
  13540. #endif /* ZFNQFP */
  13541.  
  13542. #ifndef NOSETKEY
  13543.     if (xx == XSKEY) {                  /* SAVE KEYMAP.. */
  13544.         z = cmofi("Name of Kermit command file","keymap.ksc",&s,xxstring);
  13545.     } else {
  13546. #endif /* NOSETKEY */
  13547.         switch (xx) {
  13548.           case XSCMD:                   /* SAVE COMMAND.. */
  13549.             if ((y = cmkey(cmdtrmopt, ncmdtrmopt, "What to save",
  13550. #ifdef OS2
  13551.                            "scrollback",
  13552. #else
  13553.                            "history",
  13554. #endif /* OS2 */
  13555.                            xxstring)) < 0)
  13556.               return(y);
  13557.             break;
  13558. #ifdef OS2
  13559. #ifndef NOLOCAL
  13560.           case XSTERM:                  /* SAVE TERMINAL.. */
  13561.             if ((y = cmkey(trmtrmopt,1,
  13562.                            "What to save","scrollback",xxstring)) < 0)
  13563.               return(y);
  13564.             break;
  13565. #endif /* NOLOCAL */
  13566. #endif /* OS2 */
  13567.         }
  13568.         z = cmofi("Filename",
  13569.                   ((y == SV_SCRL) ? "scrollbk.txt" : "history.txt"),
  13570.                   &s,
  13571.                   xxstring
  13572.                   );
  13573. #ifndef NOSETKEY
  13574.     }
  13575. #endif /* NOSETKEY */
  13576.     if (z < 0)                          /* Check output-file parse results */
  13577.       return(z);
  13578.     if (z == 2) {
  13579.         printf("?Sorry, %s is a directory name\n",s);
  13580.         return(-9);
  13581.     }
  13582. #ifdef ZFNQFP
  13583.     if ((fnp = zfnqfp(s,TMPBUFSIZ - 1,tmpbuf))) {/* Convert to full pathname */
  13584.         if (fnp->fpath)
  13585.           if ((int) strlen(fnp->fpath) > 0)
  13586.             s = fnp->fpath;
  13587.     }
  13588. #endif /* ZFNQFP */
  13589.  
  13590.     ckstrncpy(line,s,LINBUFSIZ);        /* Make safe copy of pathname */
  13591.     s = line;
  13592. #ifdef MAC
  13593.     z = 0;
  13594. #else
  13595.     /* Get NEW/APPEND disposition */
  13596.     if ((z = cmkey(disptb,2,"Disposition","new",xxstring)) < 0)
  13597.       return(z);
  13598. #endif /* MAC */
  13599.     disp = z;
  13600.     if ((x = cmcfm()) < 0)              /* Get confirmation */
  13601.       return(x);
  13602.  
  13603.     switch (xx) {                       /* Do action.. */
  13604. #ifndef NOSETKEY
  13605.       case XSKEY:                       /* SAVE KEYMAP */
  13606.         return (savkeys(s,disp));
  13607. #endif /* NOSETKEY */
  13608.  
  13609.       case XSCMD:                       /* SAVE COMMAND.. */
  13610. #ifdef OS2
  13611. #ifndef NOLOCAL
  13612.         if (y == SV_SCRL)               /* .. SCROLLBACK */
  13613.           return(success = savscrbk(VCMD,s,disp));
  13614. #endif /* NOLOCAL */
  13615. #endif /* OS2 */
  13616. #ifndef NORECALL
  13617.         if (y == SV_HIST)               /* .. HISTORY */
  13618.           return(success = savhistory(s,disp));
  13619. #endif /* NORECALL */
  13620.         break;
  13621.  
  13622. #ifdef OS2
  13623. #ifndef NOLOCAL
  13624.       case XSTERM:                      /* SAVE TERMINAL SCROLLBACK */
  13625.         return(success = savscrbk(VTERM,s,disp));
  13626. #endif /* NOLOCAL */
  13627. #endif /* OS2 */
  13628.     }
  13629.     success = 0;
  13630.     return(-2);
  13631. }
  13632.  
  13633. /*
  13634.   R E A D T E X T
  13635.  
  13636.   Read text with a custom prompt into given buffer using command parser but
  13637.   with no echoing or entry into recall buffer.
  13638. */
  13639. int
  13640. readtext(prmpt, buffer, bufsiz) char * prmpt; char * buffer; int bufsiz; {
  13641. #ifdef CK_RECALL
  13642.     extern int on_recall;               /* Around Password prompting */
  13643. #endif /* CK_RECALL */
  13644.     int rc;
  13645. #ifndef NOLOCAL
  13646. #ifdef OS2
  13647.     extern int vmode;
  13648.     extern int startflags;
  13649.     int vmode_sav = vmode;
  13650.  
  13651.     if (!prmpt) prmpt = "";
  13652.  
  13653.     if (win95_popup && !(startflags & 96)
  13654. #ifdef IKSD
  13655.          && !inserver
  13656. #endif /* IKSD */
  13657.          )
  13658.       return(popup_readtext(vmode,NULL,prmpt,buffer,bufsiz,0));
  13659.  
  13660.     if (vmode == VTERM) {
  13661.         vmode = VCMD;
  13662.         VscrnIsDirty(VTERM);
  13663.         VscrnIsDirty(VCMD);
  13664.     }
  13665. #endif /* OS2 */
  13666. #endif /* NOLOCAL */
  13667.  
  13668. #ifdef CK_RECALL
  13669.     on_recall = 0;
  13670. #endif /* CK_RECALL */
  13671.     cmsavp(psave,PROMPTL);              /* Save old prompt */
  13672.     cmsetp(prmpt);                      /* Make new prompt */
  13673.     concb((char)escape);                /* Put console in cbreak mode */
  13674.     cmini(1);                           /* and echo mode */
  13675.     if (pflag) prompt(xxstring);        /* Issue prompt if at top level */
  13676.     cmres();                            /* Reset the parser */
  13677.     for (rc = -1; rc < 0; ) {           /* Prompt till they answer */
  13678.         rc = cmtxt("","",&s,NULL);      /* Get a literal line of text */
  13679.         cmres();                        /* Reset the parser again */
  13680.     }
  13681.     ckstrncpy(buffer,s,bufsiz);
  13682.     cmsetp(psave);                      /* Restore original prompt */
  13683.  
  13684. #ifndef NOLOCAL
  13685. #ifdef OS2
  13686.     if (vmode != vmode_sav) {
  13687.         vmode = VTERM;
  13688.         VscrnIsDirty(VCMD);
  13689.         VscrnIsDirty(VTERM);
  13690.     }
  13691. #endif /* OS2 */
  13692. #endif /* NOLOCAL */
  13693.     return(0);
  13694. }
  13695. #endif /* NOICP */
  13696.  
  13697. /* A general function to allow a Password or other information  */
  13698. /* to be read from the command prompt without it going into     */
  13699. /* the recall buffer or being echo'd.                           */
  13700.  
  13701. int
  13702. readpass(prmpt, buffer, bufsiz) char * prmpt; char * buffer; int bufsiz; {
  13703.     int x;
  13704. #ifdef NOICP
  13705.     if (!prmpt) prmpt = "";
  13706.     printf("%s", prmpt);
  13707. #ifdef COMMENT
  13708.     /* Some linkers won't allow this because it's unsafe */
  13709.     gets(buffer);
  13710. #else  /* COMMENT */
  13711.     {
  13712.         int c, i; char * p;
  13713.         p = buffer;
  13714.         for (i = 0; i < bufsiz-1; i++) {
  13715.             if ((c = getchar()) == EOF)
  13716.               break;
  13717.             if (c < SP)
  13718.               break;
  13719.             buffer[i] = c;
  13720.         }
  13721.         buffer[i] = NUL;
  13722.     }
  13723. #endif /* COMMENT */
  13724.     return(1);
  13725. #else  /* NOICP */
  13726. #ifdef CK_RECALL
  13727.     extern int on_recall;               /* around Password prompting */
  13728. #endif /* CK_RECALL */
  13729.     int rc;
  13730. #ifndef NOLOCAL
  13731. #ifdef OS2
  13732.     extern int vmode;
  13733.     extern int startflags;
  13734.     int vmode_sav = vmode;
  13735. #endif /* OS2 */
  13736. #endif /* NOLOCAL */
  13737. #ifdef CKSYSLOG
  13738.     int savlog;
  13739. #endif /* CKSYSLOG */
  13740.     if (!prmpt) prmpt = "";
  13741. #ifndef NOLOCAL
  13742.     debok = 0;                          /* Don't log */
  13743. #ifdef OS2
  13744.     if (win95_popup && !(startflags & 96)
  13745. #ifdef IKSD
  13746.          && !inserver
  13747. #endif /* IKSD */
  13748.          ) {
  13749.         x = popup_readpass(vmode,NULL,prmpt,buffer,bufsiz,0);
  13750.         debok = 1;
  13751.         return(x);
  13752.     }
  13753. #endif /* OS2 */
  13754. #endif /* NOLOCAL */
  13755.  
  13756. #ifdef CKSYSLOG
  13757.     savlog = ckxsyslog;                 /* Save and turn off syslogging */
  13758.     ckxsyslog = 0;
  13759. #endif /* CKSYSLOG */
  13760. #ifndef NOLOCAL
  13761. #ifdef OS2
  13762.     if (vmode == VTERM) {
  13763.         vmode = VCMD;
  13764.         VscrnIsDirty(VTERM);
  13765.         VscrnIsDirty(VCMD);
  13766.     }
  13767. #endif /* OS2 */
  13768. #endif /* NOLOCAL */
  13769. #ifdef CK_RECALL
  13770.     on_recall = 0;
  13771. #endif /* CK_RECALL */
  13772.     cmsavp(psave,PROMPTL);              /* Save old prompt */
  13773.     cmsetp(prmpt);                      /* Make new prompt */
  13774.     concb((char)escape);                /* Put console in cbreak mode */
  13775.     cmini(0);                           /* and no-echo mode */
  13776.     if (pflag) prompt(xxstring);        /* Issue prompt if at top level */
  13777.     cmres();                            /* Reset the parser */
  13778.     for (rc = -1; rc < 0; ) {           /* Prompt till they answer */
  13779.         rc = cmtxt("","",&s,NULL);      /* Get a literal line of text */
  13780.         cmres();                        /* Reset the parser again */
  13781.     }
  13782.     ckstrncpy(buffer,s,bufsiz);
  13783.     printf("\r\n");                     /* Echo a CRLF */
  13784.     cmsetp(psave);                      /* Restore original prompt */
  13785.     cmini(1);                           /* Restore echo mode */
  13786. #ifndef NOLOCAL
  13787. #ifdef OS2
  13788.     if (vmode != vmode_sav) {
  13789.         vmode = VTERM;
  13790.         VscrnIsDirty(VCMD);
  13791.         VscrnIsDirty(VTERM);
  13792.     }
  13793. #endif /* OS2 */
  13794. #endif /* NOLOCAL */
  13795. #ifdef CKSYSLOG
  13796.     ckxsyslog = savlog;                 /* Restore syslogging */
  13797. #endif /* CKSYSLOG */
  13798.     debok = 1;
  13799.     return(0);
  13800. #endif /* NOICP */
  13801. }
  13802.  
  13803. #ifndef NOICP
  13804. struct keytab authtab[] = {             /* Available authentication types */
  13805. #ifdef CK_KERBEROS
  13806.     { "k4",        AUTH_KRB4, CM_INV },
  13807.     { "k5",        AUTH_KRB5, CM_INV },
  13808.     { "kerberos4", AUTH_KRB4, 0      },
  13809.     { "kerberos5", AUTH_KRB5, 0      },
  13810.     { "krb4",      AUTH_KRB4, CM_INV },
  13811.     { "krb5",      AUTH_KRB5, CM_INV },
  13812. #endif /* CK_KERBEROS */
  13813. #ifdef NT
  13814.     { "ntlm",      AUTH_NTLM, 0 },
  13815. #endif /* NT */
  13816. #ifdef CK_SRP
  13817.     { "srp",       AUTH_SRP,  0 },
  13818. #endif /* CK_SRP */
  13819. #ifdef CK_SSL
  13820.     { "ssl",       AUTH_SSL,  0 },
  13821. #endif /* CK_SSL */
  13822.     { "",          0,         0 }
  13823. };
  13824. int authtabn = sizeof(authtab)/sizeof(struct keytab)-1;
  13825.  
  13826. #ifdef CK_KERBEROS
  13827. struct keytab kerbtab[] = {             /* Kerberos authentication types */
  13828.     { "k4",        AUTH_KRB4, CM_INV },
  13829.     { "k5",        AUTH_KRB5, CM_INV },
  13830.     { "kerberos4", AUTH_KRB4, 0      },
  13831.     { "kerberos5", AUTH_KRB5, 0      },
  13832.     { "krb4",      AUTH_KRB4, CM_INV },
  13833.     { "krb5",      AUTH_KRB5, CM_INV }
  13834. };
  13835. int kerbtabn = sizeof(kerbtab)/sizeof(struct keytab);
  13836.  
  13837. static struct keytab krb_s_tbl[] = {    /* AUTHENTICATE command switches: */
  13838.     { "/cache",   KRB_S_CA, CM_ARG }
  13839. };
  13840. static int krb_s_n = sizeof(krb_s_tbl)/sizeof(struct keytab);
  13841.  
  13842. static struct keytab krb_v_tbl[] = {    /* KERBEROS version values: */
  13843.     { "4",    4, 0 },
  13844.     { "5",    5, 0 },                   /* (add others as needed...) */
  13845.     { "auto", 0, 0 }                    /* Note: 0 = auto */
  13846. };
  13847. static int krb_v_n = sizeof(krb_v_tbl)/sizeof(struct keytab);
  13848.  
  13849. static struct keytab krb_a_tbl[] = {    /* KERBEROS actions: */
  13850.     { "destroy",           KRB_A_DE, 0 },
  13851.     { "initialize",        KRB_A_IN, 0 },
  13852.     { "list-credentials",  KRB_A_LC, 0 }
  13853. };
  13854. static int krb_a_n = sizeof(krb_a_tbl)/sizeof(struct keytab);
  13855.  
  13856. static struct keytab krb4_i_tbl[] = {   /* KERBEROS 4 INITIALIZE switches: */
  13857.     { "/brief",            KRB_I_BR, 0 },      /* /BRIEF       */
  13858.     { "/instance",         KRB_I_IN, CM_ARG }, /* /INSTANCE:   */
  13859.     { "/lifetime",         KRB_I_LF, CM_ARG }, /* /LIFETIME:   */
  13860.     { "/not-preauth",      KRB_I_NPA, 0 },     /* /NOT-PREAUTH */
  13861.     { "/password",         KRB_I_PW, CM_ARG }, /* /PASSWORD:   */
  13862. #ifdef OS2
  13863.     { "/popup",            KRB_I_POP, 0 },     /* /POPUP       */
  13864. #endif /* OS2 */
  13865.     { "/preauth",          KRB_I_PA, 0 },      /* /PREAUTH     */
  13866.     { "/realm",            KRB_I_RL, CM_ARG }, /* /REALM:      */
  13867.     { "/verbose",          KRB_I_VB, 0 },      /* /VERBOSE     */
  13868.     { "", 0, 0 }
  13869. };
  13870. static int krb4_i_n = sizeof(krb4_i_tbl)/sizeof(struct keytab) - 1;
  13871.  
  13872. static struct keytab krb5_i_tbl[] = {   /* KERBEROS 5 INITIALIZE switches: */
  13873.     { "/addresses",        KRB_I_ADR, CM_ARG },
  13874.     { "/forwardable",      KRB_I_FW,  0 },         /* /FORWARDABLE */
  13875.     { "/instance",         KRB_I_IN, CM_ARG }, /* /INSTANCE:   */
  13876.     { "/k4",               KRB_I_K4,  CM_INV }, /* /KERBEROS4   */
  13877.     { "/kerberos4",        KRB_I_K4,  0 },      /* /KERBEROS4   */
  13878.     { "/krb4",             KRB_I_K4,  CM_INV }, /* /KERBEROS4   */
  13879.     { "/lifetime",         KRB_I_LF,  CM_ARG }, /* /LIFETIME:   */
  13880.     { "/no-addresses",     KRB_I_NAD, 0 },      /* /NO-ADDRESSES */
  13881.     { "/no-k4",            KRB_I_NK4, CM_INV },/* /NO-KERBEROS4 */
  13882.     { "/no-kerberos4",     KRB_I_NK4, 0 },     /* /NO-KERBEROS4 */
  13883.     { "/no-krb4",          KRB_I_NK4, CM_INV },/* /NO-KERBEROS4 */
  13884.     { "/not-forwardable",  KRB_I_NFW, 0 },         /* /NOT-FORWARDABLE */
  13885.     { "/not-proxiable",    KRB_I_NPR, 0 },     /* /NOT-PROXIABLE   */
  13886.     { "/password",         KRB_I_PW,  CM_ARG }, /* /PASSWORD:   */
  13887. #ifdef OS2
  13888.     { "/popup",            KRB_I_POP, 0 },     /* /POPUP       */
  13889. #endif /* OS2 */
  13890.     { "/postdate",         KRB_I_PD, CM_ARG }, /* /POSTDATE:   */
  13891.     { "/pr",               KRB_I_PR, CM_INV|CM_ABR }, /* to allow for */
  13892.     { "/pro",              KRB_I_PR, CM_INV|CM_ABR }, /* different spellings */
  13893.     { "/prox",             KRB_I_PR, CM_INV|CM_ABR },
  13894.     { "/proxiable",        KRB_I_PR, 0 },      /* /PROXIABLE   */
  13895.     { "/proxyable",        KRB_I_PR, CM_INV }, /* /PROXYABLE   */
  13896.     { "/realm",            KRB_I_RL, CM_ARG }, /* /REALM:      */
  13897.     { "/renew",            KRB_I_RN, 0 },          /* /RENEW       */
  13898.     { "/renewable",        KRB_I_RB, CM_ARG }, /* /RENEWABLE:  */
  13899.     { "/service",          KRB_I_SR, CM_ARG }, /* /SERVICE:    */
  13900.     { "/validate",         KRB_I_VA, 0 },          /* /VALIDATE    */
  13901.     { "", 0, 0 }
  13902. };
  13903. static int krb5_i_n = sizeof(krb5_i_tbl)/sizeof(struct keytab) - 1;
  13904.  
  13905. static struct keytab klctab[] = {       /* List Credentials switches*/
  13906.     { "/addresses",  XYKLCAD, 0 },
  13907.     { "/encryption", XYKLCEN, 0 },
  13908.     { "/flags",      XYKLCFL, 0 }
  13909. };
  13910. static int nklctab = sizeof(klctab)/sizeof(struct keytab);
  13911.  
  13912. extern int krb_action;
  13913. extern struct krb_op_data krb_op;
  13914.  
  13915. extern struct krb5_list_cred_data krb5_lc;
  13916. extern struct krb5_init_data krb5_init;
  13917. extern char * krb5_d_principal;         /* Default principal */
  13918. extern char * krb5_d_instance;
  13919. extern char * krb5_d_realm;             /* Default realm */
  13920. extern char * krb5_d_cc;                /* Default credentials cache */
  13921. extern char * krb5_d_srv;               /* Default service name */
  13922. extern int    krb5_d_lifetime;          /* Default lifetime */
  13923. extern int    krb5_d_forwardable;
  13924. extern int    krb5_d_proxiable;
  13925. extern int    krb5_d_renewable;
  13926. extern int    krb5_autoget;
  13927. extern int    krb5_autodel;
  13928. extern int    krb5_d_getk4;
  13929. extern int    krb5_d_no_addresses;
  13930. extern int    krb5_checkaddrs;
  13931. extern char * krb5_d_addrs[];
  13932. extern char * k5_keytab;                /* Keytab file */
  13933.  
  13934. extern struct krb4_init_data krb4_init;
  13935. extern char * krb4_d_principal;         /* Default principal */
  13936. extern char * krb4_d_realm;             /* Default realm */
  13937. extern char * krb4_d_srv;               /* Default service name */
  13938. extern int    krb4_d_lifetime;          /* Default lifetime */
  13939. extern int    krb4_d_preauth;
  13940. extern char * krb4_d_instance;
  13941. extern int    krb4_autoget;
  13942. extern int    krb4_autodel;
  13943. extern int    krb4_checkaddrs;
  13944. extern char * k4_keytab;                /* Keytab file */
  13945. #endif /* CK_KERBEROS */
  13946.  
  13947. #ifndef NOSHOW
  13948. int
  13949. sho_iks() {
  13950. #ifdef IKSDCONF
  13951. #ifdef CK_LOGIN
  13952.     extern int ckxsyslog, ckxwtmp, ckxanon;
  13953. #ifdef UNIX
  13954.     extern int ckxpriv;
  13955. #endif /* UNIX */
  13956. #ifdef CK_PERMS
  13957.     extern int ckxperms;
  13958. #endif /* CK_PERMS */
  13959.     extern char * anonfile, * userfile, * anonroot;
  13960. #ifdef OS2
  13961.     extern char * anonacct;
  13962. #endif /* OS2 */
  13963. #ifdef NT
  13964.     extern char * iks_domain;
  13965. #endif /* NT */
  13966. #endif /* CK_LOGIN */
  13967. #ifdef CKWTMP
  13968.     extern char * wtmpfile;
  13969. #endif /* CKWTMP */
  13970. #ifdef IKSDB
  13971.     extern char * dbfile;
  13972.     extern int dbenabled;
  13973. #endif /* IKSDB */
  13974. #ifdef CK_LOGIN
  13975.     extern int logintimo;
  13976. #endif /* CK_LOGIN */
  13977.     extern int srvcdmsg, success, iksdcf, noinit, arg_x;
  13978.     extern char * cdmsgfile[], * cdmsgstr, *kermrc;
  13979.     char * bannerfile = NULL;
  13980.     char * helpfile = NULL;
  13981.     extern int xferlog;
  13982.     extern char * xferfile;
  13983.     int i;
  13984.  
  13985.     if (isguest) {
  13986.         printf("?Command disabled\r\n");
  13987.         return(success = 0);
  13988.     }
  13989.  
  13990.     printf("IKS Settings\r\n");
  13991. #ifdef CK_LOGIN
  13992. #ifdef OS2
  13993.     printf("  Anonymous Account:   %s\r\n",anonacct?anonacct:"<none>");
  13994. #endif /* OS2 */
  13995.     printf("  Anonymous Initfile:  %s\r\n",anonfile?anonfile:"<none>");
  13996.     printf("  Anonymous Login:     %d\r\n",ckxanon);
  13997.     printf("  Anonymous Root:      %s\r\n",anonroot?anonroot:"<none>");
  13998. #endif /* CK_LOGIN */
  13999.     printf("  Bannerfile:          %s\r\n",bannerfile?bannerfile:"<none>");
  14000.     printf("  CDfile:              %s\r\n",cdmsgfile[0]?cdmsgfile[0]:"<none>");
  14001.     for ( i=1;i<16 && cdmsgfile[i];i++ )
  14002.         printf("  CDfile:              %s\r\n",cdmsgfile[i]);
  14003.     printf("  CDMessage:           %d\r\n",srvcdmsg);
  14004. #ifdef IKSDB
  14005.     printf("  DBfile:              %s\r\n",dbfile?dbfile:"<none>");
  14006.     printf("  DBenabled:           %d\r\n",dbenabled);
  14007. #endif /* IKSDB */
  14008. #ifdef CK_LOGIN
  14009. #ifdef NT
  14010.     printf("  Default-domain:      %s\r\n",iks_domain?iks_domain:".");
  14011. #endif /* NT */
  14012. #endif /* CK_LOGIN */
  14013.     printf("  Helpfile:            %s\r\n",helpfile?helpfile:"<none>");
  14014.     printf("  Initfile:            %s\r\n",kermrc?kermrc:"<none>");
  14015.     printf("  No-Initfile:         %d\r\n",noinit);
  14016. #ifdef CK_LOGIN
  14017. #ifdef CK_PERM
  14018.     printf("  Permission code:     %0d\r\n",ckxperms);
  14019. #endif /* CK_PERM */
  14020. #ifdef UNIX
  14021.     printf("  Privileged Login:    %d\r\n",ckxpriv);
  14022. #endif /* UNIX */
  14023. #endif /* CK_LOGIN */
  14024.     printf("  Server-only:         %d\r\n",arg_x);
  14025.     printf("  Syslog:              %d\r\n",ckxsyslog);
  14026.     printf("  Timeout (seconds):   %d\r\n",logintimo);
  14027.     printf("  Userfile:            %s\r\n",userfile?userfile:"<none>");
  14028. #ifdef CK_LOGIN
  14029. #ifdef CKWTMP
  14030.     printf("  Wtmplog:             %d\r\n",ckxwtmp);
  14031.     printf("  Wtmpfile:            %s\r\n",wtmpfile?wtmpfile:"<none>");
  14032. #endif /* CKWTMP */
  14033. #endif /* CK_LOGIN */
  14034.     printf("  Xferfile:            %s\r\n",xferfile?xferfile:"<none>");
  14035.     printf("  Xferlog:             %d\r\n",xferlog);
  14036. #else /* IKSDCONF */
  14037.     printf("?Nothing to show.\r\n");
  14038. #endif /* IKSDCONF */
  14039.     return(success = 1);
  14040. }
  14041.  
  14042. #ifdef CK_AUTHENTICATION
  14043. int
  14044. sho_auth(cx) int cx; {
  14045.     extern int auth_type_user[], cmd_rows;
  14046.     int i;
  14047.     char * p;
  14048.     int kv = 0, all = 0, n = 0;
  14049.  
  14050. #ifdef IKSD
  14051.     if (inserver && isguest) {
  14052.         printf("?Sorry, command disabled.\r\n");
  14053.         return(success = 0);
  14054.     }
  14055. #endif /* IKSD */
  14056.     if (cx) {
  14057.         kv = cx;
  14058.     } else if (auth_type_user[0] != AUTHTYPE_AUTO) {
  14059.         kv = auth_type_user[0];
  14060.     } else {
  14061.         all = 1;
  14062.         kv = AUTHTYPE_KERBEROS_V4;
  14063.     }
  14064.     while (kv) {
  14065.         switch (kv) {
  14066.           case AUTHTYPE_KERBEROS_V4:
  14067.             kv = all ? AUTHTYPE_KERBEROS_V5 : 0;
  14068.             if (ck_krb4_is_installed()) {
  14069.                 printf(" Authentication:      Kerberos 4\n");
  14070.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14071.             } else {
  14072.                 printf(" Authentication:      Kerberos 4 (not installed)\n");
  14073.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14074.                 continue;
  14075.             }
  14076. #ifdef CK_KERBEROS
  14077.             printf(" Keytab file:         %s\n",
  14078.                       k4_keytab ? k4_keytab : "(none)");
  14079.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14080.             if (krb_action < 0) {
  14081.                 p = "(none)";
  14082.             } else {
  14083.                 for (p = "", i = 0; i < krb_a_n; i++) {
  14084.                     if (krb_action == krb_a_tbl[i].kwval) {
  14085.                         p = krb_a_tbl[i].kwd;
  14086.                         break;
  14087.                     }
  14088.                 }
  14089.             }
  14090.             printf(" Action:              %s\n", p);
  14091.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14092.             printf(" Default lifetime     %d\n",krb4_d_lifetime);
  14093.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14094.             printf(" Lifetime:            %d (minutes)\n",krb4_init.lifetime);
  14095.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14096.             printf(" Default preauth:     %d\n",krb4_d_preauth);
  14097.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14098.             printf(" Preauth:             %d\n",krb4_init.preauth);
  14099.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14100.             printf(" Default principal:   \"%s\"\n",
  14101.                     krb4_d_principal ? krb4_d_principal : "");
  14102.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14103.             printf(" Principal:           \"%s\"\n",
  14104.                     krb4_init.principal ? krb4_init.principal : "");
  14105.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14106.             printf(" Default realm:       \"%s\"\n",
  14107.                     krb4_d_realm ? krb4_d_realm : "");
  14108.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14109.             printf(" Realm:               \"%s\"\n",
  14110.                     krb4_init.realm ? krb4_init.realm : "");
  14111.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14112.             printf(" Default instance:    \"%s\"\n",
  14113.                     krb4_d_instance ? krb4_d_instance : "");
  14114.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14115.             printf(" Instance:            \"%s\"\n",
  14116.                     krb4_init.instance ? krb4_init.instance : "");
  14117.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14118.             printf(" Auto-Get TGTs:       %d\n",krb4_autoget);
  14119.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14120.             printf(" Auto-Destroy TGTs:   %s\n",
  14121.                     krb4_autodel==KRB_DEL_NO?"never":
  14122.                     krb4_autodel==KRB_DEL_CL?"on-close":"on-exit");
  14123.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14124.             printf(" Check IP Addresses:  %d\n",krb4_checkaddrs);
  14125.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14126. #ifdef COMMENT
  14127.             printf(" Password:    \"%s\"\n",
  14128.                     krb4_init.password  ? krb4_init.password  : "");
  14129.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14130. #endif /* COMMENT */
  14131. #endif /* CK_KERBEROS */
  14132.             printf("\n");
  14133.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14134.             break;
  14135.         case AUTHTYPE_KERBEROS_V5:
  14136.             kv = all ? AUTHTYPE_SSL : 0;
  14137.             if (ck_krb5_is_installed()) {
  14138.                 if (ck_gssapi_is_installed())
  14139.                     printf(" Authentication:      Kerberos 5 plus GSSAPI\n");
  14140.                 else
  14141.                     printf(" Authentication:      Kerberos 5\n");
  14142.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14143.             } else {
  14144.                 printf(" Authentication:      Kerberos 5 (not installed)\n");
  14145.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14146.                 continue;
  14147.             }
  14148.  
  14149. #ifdef CK_KERBEROS
  14150.             printf(" Cache file:          %s\n",
  14151.                     krb_op.cache ? krb_op.cache : "(none)");
  14152.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14153.             printf(" Default cache:       %s\n",
  14154.                     krb5_d_cc ? krb5_d_cc : "(none)");
  14155.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14156.             printf(" Keytab file:         %s\n",
  14157.                       k5_keytab ? k5_keytab : "(none)");
  14158.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14159.             if (krb_action < 0) {
  14160.                 p = "(none)";
  14161.             } else  {
  14162.                 for (p = "", i = 0; i < krb_a_n; i++) {
  14163.                     if (krb_action == krb_a_tbl[i].kwval) {
  14164.                         p = krb_a_tbl[i].kwd;
  14165.                         break;
  14166.                     }
  14167.                 }
  14168.             }
  14169.             printf(" Action:              %s\n", p);
  14170.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14171.  
  14172.             printf(" Default forwardable  %d\n",krb5_d_forwardable);
  14173.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14174.             printf(" Forwardable:         %d\n",krb5_init.forwardable);
  14175.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14176.             printf(" Default lifetime     %d\n",krb5_d_lifetime);
  14177.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14178.             printf(" Lifetime:            %d (minutes)\n",krb5_init.lifetime);
  14179.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14180.             printf(" Postdate:            \"%s\"\n",
  14181.                     krb5_init.postdate ? krb5_init.postdate: "");
  14182.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14183.             printf(" Default proxiable:   %d\n",krb5_d_proxiable);
  14184.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14185.             printf(" Proxiable:           %d\n",krb5_init.proxiable);
  14186.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14187.             printf(" Renew:               %d\n",krb5_init.renew);
  14188.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14189.             printf(" Default renewable:   %d (minutes)\n",krb5_d_renewable);
  14190.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14191.             printf(" Renewable:           %d (minutes)\n",krb5_init.renewable);
  14192.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14193.             printf(" Service:             \"%s\"\n",
  14194.                     krb5_init.service ? krb5_init.service : "");
  14195.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14196.             printf(" Validate:            %d\n",krb5_init.validate);
  14197.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14198.             printf(" Default principal:   \"%s\"\n",
  14199.                     krb5_d_principal ? krb5_d_principal : "");
  14200.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14201.             printf(" Principal:           \"%s\"\n",
  14202.                     krb5_init.principal ? krb5_init.principal : "");
  14203.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14204.             printf(" Default instance:    \"%s\"\n",
  14205.                     krb5_d_instance ? krb5_d_instance : "");
  14206.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14207.             printf(" Default realm:       \"%s\"\n",
  14208.                     krb5_d_realm ? krb5_d_realm : "");
  14209.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14210.             printf(" Realm:               \"%s\"\n",
  14211.                     krb5_init.realm ? krb5_init.realm : "");
  14212.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14213.             printf(" Auto-Get TGTs:       %d\n",krb5_autoget);
  14214.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14215.             printf(" Auto-Destroy TGTs:   %s\n",
  14216.                     krb5_autodel==KRB_DEL_NO?"never":
  14217.                     krb5_autodel==KRB_DEL_CL?"on-close":"on-exit");
  14218.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14219.             printf(" Default get K4 TGTs: %d\n",krb5_d_getk4);
  14220.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14221.             printf(" Get K4 TGTs: %d\n",krb5_init.getk4);
  14222.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14223.             printf(" Check IP Addresses:  %d\n",krb5_checkaddrs);
  14224.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14225.             printf(" No IP Addresses:  %d\n",krb5_d_no_addresses);
  14226.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14227.             printf(" IP-Addresses:        ");
  14228.             if (krb5_init.addrs && krb5_init.addrs[0]) {
  14229.                 for (i = 0; krb5_init.addrs[i]; i++) {
  14230.                     if (i)
  14231.                       printf(",");
  14232.                     printf("%s",krb5_init.addrs[i]);
  14233.                 }
  14234.             } else if (krb5_d_addrs[0]) {
  14235.                 for (i = 0;i < KRB5_NUM_OF_ADDRS && krb5_d_addrs[i];i++) {
  14236.                     if (i)
  14237.                       printf(",");
  14238.                     printf("%s",krb5_d_addrs[i]);
  14239.                 }
  14240.             } else {
  14241.                 printf("(use default)");
  14242.             }
  14243.             printf("\n");
  14244.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14245. #ifdef COMMENT
  14246.             printf(" Password:            \"%s\"\n",
  14247.                     krb5_init.password  ? krb5_init.password  : "");
  14248.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14249. #endif /* COMMENT */
  14250. #endif /* CK_KERBEROS */
  14251.             printf("\n");
  14252.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14253.             break;
  14254. #ifdef CK_SSL
  14255.           case AUTHTYPE_SSL:
  14256.             kv = all ? AUTHTYPE_SRP : 0;
  14257.             if (ck_ssleay_is_installed()) {
  14258.                 printf(" Authentication:      SSL/TLS (%s)\n",
  14259.                         SSLeay_version(SSLEAY_VERSION));
  14260.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14261.             } else {
  14262.                 printf(" Authentication:      SSL/TLS (not installed)\n");
  14263.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14264.                 continue;
  14265.             }
  14266.             printf(" RSA Certs file: %s\n",ssl_rsa_cert_file?
  14267.                   ssl_rsa_cert_file:"(none)");
  14268.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14269.             printf(" RSA Certs Chain file: %s\n",ssl_rsa_cert_chain_file?
  14270.                   ssl_rsa_cert_chain_file:"(none)");
  14271.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14272.             printf(" RSA Key file: %s\n",ssl_rsa_key_file?
  14273.                   ssl_rsa_key_file:"(none)");
  14274.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14275.             printf(" DSA Certs file: %s\n",ssl_dsa_cert_file?
  14276.                   ssl_dsa_cert_file:"(none)");
  14277.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14278.             printf(" DSA Certs Chain file: %s\n",ssl_dsa_cert_chain_file?
  14279.                   ssl_dsa_cert_chain_file:"(none)");
  14280.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14281.             printf(" DH Key file: %s\n",ssl_dh_key_file?
  14282.                   ssl_dh_key_file:"(none)");
  14283.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14284.             printf(" DH Param file: %s\n",ssl_dh_param_file?
  14285.                   ssl_dh_param_file:"(none)");
  14286.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14287.             printf(" CRL file: %s\n",ssl_crl_file?
  14288.                   ssl_crl_file:"(none)");
  14289.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14290.             printf(" CRL dir: %s\n",ssl_crl_dir?
  14291.                     ssl_crl_dir:"(none)");
  14292.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14293.             printf(" Random file: %s\n",ssl_rnd_file?
  14294.                   ssl_rnd_file:"(none)");
  14295.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14296.             printf(" Verify file: %s\n",ssl_verify_file?
  14297.                   ssl_verify_file:"(none)");
  14298.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14299.             printf(" Verify dir: %s\n",ssl_verify_dir?
  14300.                   ssl_verify_dir:"(none)");
  14301.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14302.             printf(" Cipher list: %s\n",ssl_cipher_list ? ssl_cipher_list : 
  14303.             DEFAULT_CIPHER_LIST);
  14304.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14305.             if (ssl_con == NULL) {
  14306.                 SSL_library_init();
  14307.                 ssl_ctx = (SSL_CTX *)
  14308.                   SSL_CTX_new((SSL_METHOD *)TLSv1_method());
  14309.                 if (ssl_ctx != NULL)
  14310.                   ssl_con= (SSL *) SSL_new(ssl_ctx);
  14311.             }
  14312.             if (ssl_con != NULL) {
  14313.                 CHAR * p = NULL;
  14314.                 int i;
  14315.  
  14316.                 for (i = 0; ; i++) {
  14317.                     p = (CHAR *) SSL_get_cipher_list(ssl_con,i);
  14318.                     if (p == NULL)
  14319.                       break;
  14320.                     printf("    %s\n",p);
  14321.                     if (++n > cmd_rows - 3)
  14322.                         if (!askmore()) return(0); else n = 0;
  14323.                 }
  14324.             }
  14325.             printf(" Certs OK? %s\n",ssl_certsok_flag? "yes" : "no");
  14326.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14327.             printf(" Debug mode: %s\n", ssl_debug_flag ? "on" : "off");
  14328.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14329.             printf(" Verbose mode: %s\n", ssl_verbose_flag ? "on" : "off");
  14330.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14331.             printf(" Verify mode: %s\n",
  14332.                     ssl_verify_flag == SSL_VERIFY_NONE ? "none" :
  14333.                     ssl_verify_flag == SSL_VERIFY_PEER ? "peer-cert" :
  14334.                     "fail-if-no-peer-cert");
  14335.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14336.             printf(" SSL only? %s\n", ssl_only_flag ? "yes" : "no");
  14337.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14338.             printf(" TLS only? %s\n", tls_only_flag ? "yes" : "no");
  14339.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14340. #endif /* CK_SSL */
  14341.             break;
  14342.           case AUTHTYPE_NTLM:
  14343.             kv = 0;
  14344.             if (ck_ntlm_is_installed()) {
  14345.                 printf(" Authentication:      NTLM\n");
  14346.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14347.                 printf(" No options\n");
  14348.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14349.             } else {
  14350.                 printf(" Authentication:      NTLM (not installed)\n");
  14351.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14352.                 continue;
  14353.             }
  14354.             printf("\n");
  14355.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14356.             break;
  14357.           case AUTHTYPE_SRP:
  14358.             kv = all ? AUTHTYPE_NTLM : 0;
  14359.             if (ck_srp_is_installed()) {
  14360.                 if (ck_krypto_is_installed())
  14361.                     printf(" Authentication:      SRP plus Krypto API\n");
  14362.                 else
  14363.                     printf(" Authentication:      SRP\n");
  14364.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14365.                 printf(" No options\n");
  14366.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14367.             } else {
  14368.                 printf(" Authentication:      SRP (not installed)\n");
  14369.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14370.                 continue;
  14371.             }
  14372.             printf("\n");
  14373.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  14374.             break;
  14375.         }
  14376.     }
  14377.     return(success = 1);
  14378. }
  14379. #endif /* CK_AUTHENTICATION */
  14380. #endif /* NOSHOW */
  14381.  
  14382. #ifdef CK_KERBEROS
  14383.  
  14384. /*  C P _ A U T H  --  AUTHENTICATE command parsing  */
  14385.  
  14386. int
  14387. cp_auth() {                             /* Command_Parse AUTHENTICATE */
  14388.     int c, i, n;                        /* Workers */
  14389.     int rc = 0;                         /* Return code */
  14390.     int getval;                         /* Parsing helpers */
  14391.     int tmpauth = 0;                    /* Temporary authentication type */
  14392.     int kv = 0;                         /* Temporary Kerberos version */
  14393.     int tmp_action = -1;                /* Temporary Kerberos action */
  14394.     int tmp_klc = 0;                    /* Temporary list-credentials */
  14395.     char tmphlp[256];                   /* For building help message */
  14396.     char * p;
  14397.     char * tmppswd  = NULL;             /* Password */
  14398.     char * tmpprinz = NULL;             /* Principal */
  14399.     char * tmprealm = NULL;             /* Realm */
  14400.     char * tmpcache = NULL;             /* Cache file */
  14401.     char * tmpinst  = NULL;             /* K4 Instance */
  14402.     char * tmpaddrs[KRB5_NUM_OF_ADDRS];
  14403. #ifdef CK_RECALL
  14404.     extern int on_recall;               /* around Password prompting */
  14405. #endif /* CK_RECALL */
  14406.     struct stringint pv[KRB_I_MAX+1];   /* Temporary array for switch values */
  14407.     struct FDB kw, sw, fl;              /* FDBs for each parse function */
  14408.  
  14409.     krb_action = -1;                    /* Initialize Kerberos action. */
  14410.     tmp_action = -1;                    /* And our local copy. */
  14411.     for (i = 0; i < KRB5_NUM_OF_ADDRS; i++)
  14412.       tmpaddrs[i] = NULL;
  14413.  
  14414.     if ((y = cmkey(kerbtab,kerbtabn,"authentication type","",xxstring)) < 0)
  14415.       {
  14416.           if (y == -3)
  14417.             printf("?Authentication type not specified - nothing happens\n");
  14418.           return(y);
  14419.       }
  14420.     tmpauth = y;
  14421.     debug(F101,"kerberos authentication","",tmpauth);
  14422.     switch (tmpauth) {
  14423.       case AUTH_KRB4: kv = 4; break;    /* Don't assume values are the same */
  14424.       case AUTH_KRB5: kv = 5; break;
  14425.       default:
  14426.         printf("?Authentication type not supported: \"%s\"\n",atmbuf);
  14427.         return(-9);
  14428.     }
  14429.  
  14430.     /* From here down is Kerberos */
  14431.     ini_kerb();                         /* Reset Init data to defaults */
  14432.  
  14433.     if (kv == 4) {                      /* Set K4 defaults */
  14434.         if (krb4_d_realm)
  14435.           makestr(&tmprealm,krb4_d_realm);
  14436.         if (krb4_d_principal)
  14437.           makestr(&tmpprinz,krb4_d_principal);
  14438.         if (krb4_d_instance)
  14439.           makestr(&tmpinst,krb4_d_instance);
  14440.     } else if (kv == 5) {               /* Set K5 defaults */
  14441.         if (krb5_d_cc)
  14442.           makestr(&tmpcache,krb5_d_cc);
  14443.         if (krb5_d_realm)
  14444.           makestr(&tmprealm,krb5_d_realm);
  14445.         if (krb5_d_principal)
  14446.           makestr(&tmpprinz,krb5_d_principal);
  14447.         if (krb5_d_instance)
  14448.           makestr(&tmpinst,krb5_d_instance);
  14449.     }
  14450.     for (i = 0; i <= KRB_I_MAX; i++) {  /* Initialize switch values */
  14451.         pv[i].sval = NULL;              /* to null pointers */
  14452.         pv[i].ival = 0;                 /* and 0 int values */
  14453.         pv[i].wval = (CK_OFF_T)-1;    /* and -1 wide values */
  14454.     }
  14455.     if (kv == 4) {                      /* Kerberos 4 */
  14456.         pv[KRB_I_LF].ival = krb4_d_lifetime;
  14457.         pv[KRB_I_PA].ival = krb4_d_preauth;
  14458.  
  14459.         if ((n = cmkey(krb_a_tbl,krb_a_n,"Kerberos 4 action","",xxstring)) < 0)
  14460.           {
  14461.               if (n == -3)
  14462.                 printf("?Action not specified - nothing happens.\n");
  14463.               return(n);
  14464.           }
  14465.     } else if (kv == 5) {               /* Kerberos 5 */
  14466.         pv[KRB_I_FW].ival = krb5_d_forwardable;
  14467.         pv[KRB_I_PR].ival = krb5_d_proxiable;
  14468.         pv[KRB_I_LF].ival = krb5_d_lifetime;
  14469.         pv[KRB_I_RB].ival = krb5_d_renewable;
  14470.         pv[KRB_I_K4].ival = krb5_d_getk4;
  14471.         pv[KRB_I_NAD].ival = krb5_d_no_addresses;
  14472.  
  14473.         /* Make help message that shows switches and action keywords */
  14474.         ckstrncpy(tmphlp,"Kerberos 5 action, one of the following:\n ",256);
  14475.         for (i = 0; i < krb_a_n; i++) {
  14476.             ckstrncat(tmphlp,krb_a_tbl[i].kwd,sizeof(tmphlp));
  14477.             if (i == krb_a_n - 1)
  14478.               ckstrncat(tmphlp,"\nor switch",sizeof(tmphlp));
  14479.             else
  14480.               ckstrncat(tmphlp,"   ",sizeof(tmphlp));
  14481.         }
  14482.         /* Set up first set of chained FDB's */
  14483.  
  14484.         cmfdbi(&sw,                     /* First FDB - command switches */
  14485.                _CMKEY,                  /* fcode */
  14486.                tmphlp,                  /* hlpmsg */
  14487.                "",                      /* default (none) */
  14488.                "",                      /* addtl string data */
  14489.                krb_s_n,                 /* Switch table size */
  14490.                4,                       /* addtl numeric data 2: 4 = cmswi */
  14491.                xxstring,                /* Processing function */
  14492.                krb_s_tbl,               /* Switch table */
  14493.                &kw                      /* Pointer to next FDB */
  14494.                );
  14495.         cmfdbi(&kw,                     /* Second FDB - action keywords */
  14496.                _CMKEY,                  /* fcode */
  14497.                "Kerberos action",       /* hlpmsg */
  14498.                "",                      /* default (none) */
  14499.                "",                      /* addtl string data */
  14500.                krb_a_n,                 /* Switch table size */
  14501.                0,                       /* addtl num data (0 = NOT switch) */
  14502.                xxstring,                /* Processing function */
  14503.                krb_a_tbl,               /* Keyword table */
  14504.                NULL                     /* Pointer to next FDB (none) */
  14505.                );
  14506.  
  14507.         /* Parse */
  14508.  
  14509.         while (1) {                     /* Parse 0 or more switches */
  14510.             rc = cmfdb(&sw);            /* Parse something */
  14511.             debug(F101,"kerberos cmfdb 1 rc","",rc);
  14512.             if (rc < 0) {                       /* Error */
  14513.                 if (rc == -3)
  14514.                   printf("?Action not specified - nothing happens.\n");
  14515.                 return(rc);             /* or reparse needed */
  14516.             }
  14517.             if (cmresult.fdbaddr != &sw) /* Break out if not a switch */
  14518.               break;
  14519.             c = cmgbrk();               /* Have switch - get break character */
  14520.             getval = (c == ':' || c == '='); /* Must parse an agument? */
  14521.             if (getval && !(cmresult.kflags & CM_ARG)) {
  14522.                 printf("?This switch does not take arguments\n");
  14523.                 return(-9);             /* OK because nothing malloc'd yet */
  14524.             }
  14525.             if (!getval && (cmgkwflgs() & CM_ARG)) {
  14526.                 printf("?This switch requires an argument\n");
  14527.                 return(-9);
  14528.             }
  14529.             n = cmresult.nresult;       /* Numeric result = switch value */
  14530.             debug(F101,"kerberos command switch","",n);
  14531.  
  14532.             switch (n) {                /* Handle the switch */
  14533.               case KRB_S_CA:            /* /CACHE:<filename> */
  14534.                 p = krb5_d_cc ? krb5_d_cc : "";
  14535.                 if ((y = cmofi("Name of cache file",p,&s,xxstring)) < 0) {
  14536.                     if (y == -3)
  14537.                       s = NULL;
  14538.                     else
  14539.                       return(y);
  14540.                 }
  14541.                 makestr(&tmpcache,s);
  14542.                 break;
  14543.               default:
  14544.                 printf("?Unexpected switch value - internal error\n");
  14545.                 return(-9);             /* (if) nothing malloc'd yet. */
  14546.             }
  14547.         }
  14548.         if (cmresult.fdbaddr != &kw) {  /* Checking... */
  14549.             printf("?Unexpected result - internal error\n");
  14550.             return(-9);                 /* Nothing malloc'd yet. */
  14551.         }
  14552.         n = cmresult.nresult;           /* Get keyword value */
  14553.     } else {
  14554.         printf("?Unexpected Kerberos version - Internal error\n");
  14555.         return(-9);
  14556.     }
  14557.     debug(F101,"kerberos action","",n);
  14558.     switch (n) {
  14559.       case KRB_A_IN:                    /* INITIALIZE */
  14560.       case KRB_A_DE:                    /* DESTROY */
  14561.       case KRB_A_LC:                    /* LIST-CREDENTIALS */
  14562.         tmp_action = n;                 /* OK, set */
  14563.         break;
  14564.       default:                          /* Not OK, punt. */
  14565.         printf("?Unexpected action - internal error\n");
  14566.         return(-9);
  14567.     }
  14568.     if (tmp_action == KRB_A_IN) {       /* Action is INITIALIZE */
  14569.         int x;
  14570.         cmfdbi(&sw,                     /* INITIALIZE switches */
  14571.                _CMKEY,                  /* fcode */
  14572.                "Principal,\n or optional INITIALIZE switch(es)", /* hlpmsg */
  14573.                "",                      /* default (none) */
  14574.                "",                      /* addtl string data */
  14575.                kv == 4 ?  krb4_i_n : krb5_i_n, /* Switch table size */
  14576.                4,                       /* addtl numeric data 2: 4 = cmswi */
  14577.                xxstring,                /* Processing function */
  14578.                kv == 4 ?  krb4_i_tbl : krb5_i_tbl,      /* Switch table */
  14579.                &fl                      /* Pointer to next FDB */
  14580.                );
  14581.         cmfdbi(&fl,                     /* 3rd FDB - command to send from */
  14582.                _CMFLD,                  /* fcode */
  14583.                "Principal",             /* hlpmsg */
  14584.                kv == 4 ? krb4_d_principal : krb5_d_principal, /* principal */
  14585.                "",                      /* addtl string data */
  14586.                0,                       /* addtl numeric data 1 */
  14587.                0,                       /* addtl numeric data 2 */
  14588.                xxstring,
  14589.                NULL,
  14590.                NULL
  14591.                );
  14592.         while (1) {                     /* Parse INIT switches or principal */
  14593.             rc = cmfdb(&sw);
  14594.             debug(F101,"kerberos cmfdb 2 rc","",rc);
  14595.             if (rc < 0) {
  14596.                 if (rc == -3)
  14597.                   printf("?Principal name required\n");
  14598.                 goto kerbx;
  14599.             }
  14600.             debug(F101,"kerberos cmfdb 2 fcode","",cmresult.fcode);
  14601.             if (cmresult.fcode != _CMKEY) /* Not a switch, quit switch loop */
  14602.               break;
  14603.             c = cmgbrk();               /* Switch - get break character */
  14604.             debug(F101,"kerberos cmfdb 2 cmgbrk","",c);
  14605.             getval = (c == ':' || c == '=');
  14606.             if (getval && !(cmresult.kflags & CM_ARG)) {
  14607.                 printf("?This switch does not take arguments\n");
  14608.                 return(-9);             /* OK because nothing malloc'd yet */
  14609.             }
  14610.             if (!getval && (cmgkwflgs() & CM_ARG)) {
  14611.                 printf("?This switch requires an argument\n");
  14612.                 return(-9);
  14613.             }
  14614.             n = cmresult.nresult;       /* Numeric result = switch value */
  14615.             switch (n) {
  14616.               /* These don't take args... */
  14617.               case KRB_I_PA:            /* /PREAUTH */
  14618.               case KRB_I_FW:            /* /FORWARDABLE */
  14619.               case KRB_I_PR:            /* /PROXIABLE */
  14620.               case KRB_I_RN:            /* /RENEW */
  14621.               case KRB_I_VA:            /* /VALIDATE */
  14622.               case KRB_I_NPA:           /* /NOT-PREAUTH */
  14623.               case KRB_I_NFW:           /* /NOT-FORWARDABLE */
  14624.               case KRB_I_NPR:           /* /NOT-PROXIABLE */
  14625.               case KRB_I_VB:            /* /VERBOSE */
  14626.               case KRB_I_BR:            /* /BRIEF */
  14627.               case KRB_I_K4:            /* /KERBEROS4 */
  14628.               case KRB_I_NK4:           /* /NO-KERBEROS4 */
  14629.               case KRB_I_POP:           /* /POPUP */
  14630.               case KRB_I_NAD:           /* /NO-ADDRESSES */
  14631.                 if (getval) {
  14632.                     printf("?This switch does not take a value\n");
  14633.                     rc = -9;
  14634.                     goto kerbx;
  14635.                 }
  14636.                 switch (n) {
  14637.                   case KRB_I_NPA:
  14638.                     pv[KRB_I_PA].ival = 0;
  14639.                     break;
  14640.                   case KRB_I_NFW:
  14641.                     pv[KRB_I_FW].ival = 0;
  14642.                     break;
  14643.                   case KRB_I_NPR:
  14644.                     pv[KRB_I_PR].ival = 0;
  14645.                     break;
  14646.                   case KRB_I_VB:
  14647.                     pv[KRB_I_BR].ival = 0;
  14648.                     break;
  14649.                   case KRB_I_NK4:
  14650.                     pv[KRB_I_K4].ival = 0;
  14651.                     break;
  14652.                   default:
  14653.                     pv[n].ival = 1;
  14654.                 }
  14655.                 break;
  14656.  
  14657.                 /* These do take arguments */
  14658.  
  14659.               case KRB_I_RB:            /* /RENEWABLE:<minutes> */
  14660.                 pv[n].ival = 0;
  14661.                 if (!getval) break;
  14662.                 if ((rc = cmnum("Minutes",ckitoa(krb5_init.renewable),
  14663.                                 10,&y, xxstring)) < 0)
  14664.                   goto kerbx;
  14665.                 pv[n].ival = y;
  14666.                 break;
  14667.  
  14668.               case KRB_I_LF:            /* /LIFETIME:<minutes> */
  14669.                 pv[n].ival = 0;
  14670.                 /* Default is previous value */
  14671.                 sprintf(tmpbuf,"%d",    /* SAFE */
  14672.                         kv == 4 ?
  14673.                         krb4_init.lifetime :
  14674.                         krb5_init.lifetime
  14675.                         );
  14676.                 if (!getval) break;
  14677.                 if ((rc = cmnum("Minutes",tmpbuf,10,&y, xxstring)) < 0)
  14678.                   goto kerbx;
  14679.                 pv[n].ival = y;
  14680.                 break;
  14681.  
  14682.               case KRB_I_PD:            /* /POSTDATE:<timestamp> */
  14683.                 if (pv[n].sval) {
  14684.                     free(pv[n].sval);
  14685.                     pv[n].sval = NULL;
  14686.                 }
  14687.                 if (!getval) break;
  14688.                 if ((rc = cmdate("date-time","",&s,0,xxstring)) < 0)
  14689.                   goto kerbx;
  14690.                 makestr(&(pv[n].sval),s);
  14691.                 break;
  14692.  
  14693.               case KRB_I_SR:            /* /SERVICE:<name> */
  14694.                 if (pv[n].sval) {
  14695.                     free(pv[n].sval);
  14696.                     pv[n].sval = NULL;
  14697.                 }
  14698.                 if (!getval) break;
  14699.                 if ((rc = cmfld("Service-name","",&s,xxstring)) < 0)
  14700.                   goto kerbx;
  14701.                 makestr(&(pv[n].sval),s);
  14702.                 break;
  14703.  
  14704.               case KRB_I_RL:            /* /REALM:<name> */
  14705.                 if (pv[n].sval) {
  14706.                     free(pv[n].sval);
  14707.                     pv[n].sval = NULL;
  14708.                 }
  14709.                 if (!getval) break;
  14710.                 if (kv == 4)
  14711.                   p = krb4_d_realm ? krb4_d_realm : "";
  14712.                 else
  14713.                   p = krb5_d_realm ? krb5_d_realm : "";
  14714.                 if ((rc = cmfld("Realm",p,&s,xxstring)) < 0)
  14715.                   goto kerbx;
  14716.                 makestr(&(pv[n].sval),s);
  14717.                 break;
  14718.  
  14719.               case KRB_I_IN:            /* /INSTANCE:<name> */
  14720.                 if (pv[n].sval) {
  14721.                     free(pv[n].sval);
  14722.                     pv[n].sval = NULL;
  14723.                 }
  14724.                 if (!getval) break;
  14725.                 if (kv == 4)
  14726.                     p = krb4_d_instance ? krb4_d_instance : "";
  14727.                 else
  14728.                     p = krb5_d_instance ? krb5_d_instance : "";
  14729.                 if ((rc = cmfld("Instance",p,&s,xxstring)) < 0)
  14730.                   goto kerbx;
  14731.                 makestr(&(pv[n].sval),s);
  14732.                 break;
  14733.  
  14734.               case KRB_I_PW:            /* /PASSWORD:<password> */
  14735.                 debok = 0;
  14736.                 if (pv[n].sval) {
  14737.                     free(pv[n].sval);
  14738.                     pv[n].sval = NULL;
  14739.                 }
  14740.                 if (!getval) break;
  14741.                 if ((rc = cmfld("Password","",&s,xxstring)) < 0)
  14742.                   if (rc != -3)
  14743.                     goto kerbx;
  14744.                 makestr(&(pv[n].sval),s);
  14745.                 break;
  14746.  
  14747.               case KRB_I_ADR:           /* /ADDRESSES:{<address-list>} */
  14748.                 if (pv[n].sval) {
  14749.                     free(pv[n].sval);
  14750.                     pv[n].sval = NULL;
  14751.                 }
  14752.                 if (!getval) break;
  14753.                 if ((rc = cmfld("List of IP addresses","",&s,xxstring)) < 0)
  14754.                   goto kerbx;
  14755.                 makelist(s,tmpaddrs,KRB5_NUM_OF_ADDRS);
  14756.                 for (i = 0; i < KRB5_NUM_OF_ADDRS && tmpaddrs[i]; i++) {
  14757.                     if (inet_addr(tmpaddrs[i]) == 0xffffffff) {
  14758.                         printf("invalid ip address: %s\n",tmpaddrs[i]);
  14759.                         rc = -9;
  14760.                         goto kerbx;
  14761.                     }
  14762.                 }
  14763.                 pv[KRB_I_NAD].ival = 0;
  14764.                 break;
  14765.  
  14766.               default:
  14767.                 printf("?Unexpected switch value - internal error\n");
  14768.                 rc = -9;
  14769.                 goto kerbx;
  14770.             }
  14771.         }
  14772.         if (cmresult.fcode != _CMFLD) {
  14773.             printf("?Unexected result - internal error\n");
  14774.             rc = -9;
  14775.             goto kerbx;
  14776.         }
  14777.         /* cmresult.sresult may be of the form PRINCIPAL@REALM */
  14778.         i = ckindex("@",cmresult.sresult,0,0,0);
  14779.         if (i != 0) {
  14780.             makestr(&tmprealm,&cmresult.sresult[i]);
  14781.             cmresult.sresult[i-1] = '\0';
  14782.         }
  14783.         makestr(&tmpprinz,cmresult.sresult); /* Principal (user) */
  14784.  
  14785.         if ((rc = cmcfm()) < 0) {       /* Now get confirmation */
  14786.             if (rc == -3) {
  14787.                 printf("?Principal name required\n");
  14788.             }
  14789.             goto kerbx;
  14790.         }
  14791.         if (!tmpprinz || !tmpprinz[0]) {
  14792.             printf("?Principal name required\n");
  14793.             goto kerbx;
  14794.         }
  14795.         if (!pv[KRB_I_RN].ival && !pv[KRB_I_VA].ival) {
  14796.             /* Don't use a password if Validating or Renewing */
  14797.             if (pv[KRB_I_PW].sval) {    /* If they gave a /PASSWORD switch */
  14798.                 makestr(&tmppswd,pv[KRB_I_PW].sval); /* use this value */
  14799.             }
  14800. #ifdef COMMENT
  14801.             /* Password prompting has been moved to ck_krb[45]_initTGT() */
  14802.             else {                      /* Otherwise must prompt for it */
  14803.                 char prmpt[80];
  14804.                 if (pv[KRB_I_RL].sval)
  14805.                   sprintf(prmpt,"%s@%s's Password: ",
  14806.                           tmpprinz,pv[KRB_I_RL].sval);
  14807.                 else if (tmprealm)
  14808.                   sprintf(prmpt,"%s@%s's Password: ",
  14809.                           tmpprinz,tmprealm);
  14810.                 else
  14811.                   sprintf(prmpt,"%s's Password: ",tmpprinz);
  14812. #ifdef OS2
  14813.                 if (pv[KRB_I_POP].ival) {
  14814.                     char passwd[80]="";
  14815.                     readpass(prmpt,passwd,80);
  14816.                     makestr(&tmppswd,passwd);
  14817.                     memset(passwd,0,80);
  14818.                 } else
  14819. #endif /* OS2 */
  14820.                 {
  14821. #ifdef CK_RECALL
  14822.                     on_recall = 0;
  14823. #endif /* CK_RECALL */
  14824.                     cmsavp(psave,PROMPTL); /* Save old prompt */
  14825.                     cmsetp(prmpt);      /* Make new prompt */
  14826.                     concb((char)escape); /* Put console in cbreak mode */
  14827.                     cmini(0);           /* and no-echo mode */
  14828.                     /* Issue prompt if at top level */
  14829.                     if (pflag) prompt(xxstring);
  14830.                     cmres();            /* Reset the parser */
  14831.                     for (rc = -1; rc < 0; ) { /* Prompt till they answer */
  14832.                         /* Get a literal line of text */
  14833.                         rc = cmtxt("","",&s,NULL);
  14834.                         cmres();        /* Reset the parser again */
  14835.                     }
  14836.                     makestr(&tmppswd,s);
  14837.                     printf("\n");       /* Echo a CRLF */
  14838.                     cmsetp(psave);      /* Restore original prompt */
  14839.                 }
  14840.             }
  14841.             x = 0;                      /* Check for password */
  14842.             if (tmppswd)
  14843.               if (*tmppswd)
  14844.                 x = 1;
  14845.             if (!x) {
  14846.                 printf("?Password required\n");
  14847.                 goto kerbx;
  14848.             }
  14849. #endif /* COMMENT */
  14850.         }
  14851.     } else if (kv == 5 && tmp_action == KRB_A_LC) { /* LIST-CREDENTIALS */
  14852.         tmp_klc = 0;
  14853.         while (1) {
  14854.             if ((x = cmkey(klctab,nklctab,"Switch","",xxstring)) < 0) {
  14855.                 if (x == -3) {
  14856.                     if ((rc = cmcfm()) < 0)
  14857.                       goto kerbx;
  14858.                     else
  14859.                       break;
  14860.                 } else {
  14861.                     rc = x;
  14862.                     goto kerbx;
  14863.                 }
  14864.             }
  14865.             tmp_klc |= x;
  14866.         }
  14867.     } else if ((rc = cmcfm()) < 0)      /* DESTROY, just confirm */
  14868.         goto kerbx;
  14869.  
  14870. /* Done - Move confirmed data to final locations */
  14871.  
  14872.     krb_action = tmp_action;            /* Action requested */
  14873.     krb_op.version = kv;                /* Kerberos version */
  14874.     krb_op.cache = tmpcache;            /* Cache file */
  14875.     tmpcache = NULL;                    /* So we don't free it */
  14876.  
  14877.     switch (krb_action) {
  14878.       case KRB_A_IN:                    /* INITIALIZE */
  14879.         if (kv == 5) {
  14880.             krb5_init.forwardable = pv[KRB_I_FW].ival;
  14881.             krb5_init.proxiable   = pv[KRB_I_PR].ival;
  14882.             krb5_init.lifetime    = pv[KRB_I_LF].ival;
  14883.             krb5_init.renew       = pv[KRB_I_RN].ival;
  14884.             krb5_init.renewable   = pv[KRB_I_RB].ival;
  14885.             krb5_init.validate    = pv[KRB_I_VA].ival;
  14886.  
  14887.             /* Here we just reassign the pointers and then set them to NULL */
  14888.             /* so they won't be freed below. */
  14889.  
  14890.             krb5_init.postdate = pv[KRB_I_PD].sval; pv[KRB_I_PD].sval = NULL;
  14891.             krb5_init.service  = pv[KRB_I_SR].sval; pv[KRB_I_SR].sval = NULL;
  14892.             if (pv[KRB_I_RL].sval) {
  14893.                 krb5_init.realm  = pv[KRB_I_RL].sval; pv[KRB_I_RL].sval = NULL;
  14894.             } else if (tmprealm) {
  14895.                 krb5_init.realm = tmprealm; tmprealm = NULL;
  14896.             }
  14897.             if (pv[KRB_I_IN].sval) {
  14898.                 krb5_init.instance = pv[KRB_I_IN].sval;
  14899.                 pv[KRB_I_IN].sval = NULL;
  14900.             } else if ( tmpinst ) {
  14901.                 krb5_init.instance = tmpinst;
  14902.                 tmpinst = NULL;
  14903.             }
  14904.             if (tmpprinz) {
  14905.                 krb5_init.principal = tmpprinz;
  14906.                 tmpprinz = NULL;
  14907.             }
  14908.             krb5_init.password = tmppswd;
  14909.             tmppswd = NULL;
  14910.  
  14911.             krb5_init.getk4 = pv[KRB_I_K4].ival;
  14912.             if (krb5_init.getk4) {
  14913.                 krb4_init.lifetime = pv[KRB_I_LF].ival;
  14914.                 if (krb5_init.realm)
  14915.                     makestr(&krb4_init.realm,krb5_init.realm);
  14916.                 krb4_init.preauth  = krb4_d_preauth;
  14917.                 krb4_init.verbose  = pv[KRB_I_BR].ival ? 0 : 1;
  14918.                 if (krb5_init.principal)
  14919.                     makestr(&krb4_init.principal,krb5_init.principal);
  14920.                 if (krb5_init.principal)
  14921.                     makestr(&krb4_init.password,krb5_init.password);
  14922.             }
  14923.             krb5_init.no_addresses = pv[KRB_I_NAD].ival;
  14924.             if (tmpaddrs[0]) {
  14925.                 for (i = 0; i < KRB5_NUM_OF_ADDRS; i++) {
  14926.                     if (krb5_init.addrs[i]) {
  14927.                         free(krb5_init.addrs[i]);
  14928.                         krb5_init.addrs[i] = NULL;
  14929.                     }
  14930.                     krb5_init.addrs[i] = tmpaddrs[i];
  14931.                     tmpaddrs[i] = NULL;
  14932.                 }
  14933.             }
  14934.         } else if (kv == 4) {           /* Same deal for Kerberos 4 */
  14935.             krb4_init.lifetime = pv[KRB_I_LF].ival;
  14936.             if (pv[KRB_I_RL].sval) {
  14937.                 krb4_init.realm  = pv[KRB_I_RL].sval;
  14938.                 pv[KRB_I_RL].sval = NULL;
  14939.             } else if ( tmprealm ) {
  14940.                 krb4_init.realm  = tmprealm;
  14941.                 tmprealm = NULL;
  14942.             }
  14943.             if (pv[KRB_I_IN].sval) {
  14944.                 krb4_init.instance = pv[KRB_I_IN].sval;
  14945.                 pv[KRB_I_IN].sval = NULL;
  14946.             } else if ( tmpinst ) {
  14947.                 krb4_init.instance = tmpinst;
  14948.                 tmpinst = NULL;
  14949.             }
  14950.             krb4_init.preauth  = pv[KRB_I_PA].ival;
  14951.             krb4_init.verbose  = pv[KRB_I_BR].ival ? 0 : 1;
  14952.  
  14953.             if (tmpprinz) {
  14954.                 krb4_init.principal = tmpprinz;
  14955.                 tmpprinz = NULL;
  14956.             }
  14957.             krb4_init.password = tmppswd;
  14958.             tmppswd = NULL;
  14959.         }
  14960.         break;
  14961.       case KRB_A_LC:                    /* List Credentials */
  14962.         krb5_lc.encryption = tmp_klc & XYKLCEN;
  14963.         krb5_lc.flags = tmp_klc & XYKLCFL;
  14964.         krb5_lc.addr  = tmp_klc & XYKLCAD;
  14965.         break;
  14966.     }
  14967.  
  14968. /* Common exit - Free temporary storage */
  14969.  
  14970.   kerbx:
  14971.     for (i = 0; i <= KRB_I_MAX; i++) {  /* Free malloc'd switch data */
  14972.         if (pv[i].sval)
  14973.           free(pv[i].sval);
  14974.     }
  14975.     for (i = 0; i < KRB5_NUM_OF_ADDRS; i++) {
  14976.         if (tmpaddrs[i])
  14977.           free(tmpaddrs[i]);
  14978.     }
  14979.     if (tmpprinz) free(tmpprinz);       /* And these too. */
  14980.     if (tmppswd)  free(tmppswd);
  14981.     if (tmpcache) free(tmpcache);
  14982.     if (tmprealm) free(tmprealm);
  14983.     if (tmpinst)  free(tmpinst);
  14984.  
  14985.     return(rc);                         /* Return the return code */
  14986. }
  14987. #endif /* CK_KERBEROS */
  14988.  
  14989. #ifdef CK_LOGIN
  14990. int
  14991. #ifdef CK_ANSIC
  14992. ckxlogin(CHAR * userid, CHAR * passwd, CHAR * acct, int promptok)
  14993. #else /* CK_ANSIC */
  14994. ckxlogin(userid, passwd, acct, promptok)
  14995.   CHAR * userid; CHAR * passwd; CHAR * acct; int promptok;
  14996. #endif /* CK_ANSIC */
  14997. /* ckxlogin */ {
  14998. #ifdef CK_RECALL
  14999.     extern int on_recall;               /* around Password prompting */
  15000. #endif /* CK_RECALL */
  15001. #ifdef CK_PAM
  15002.     extern int guest;
  15003. #endif /* CK_PAM */
  15004.     int rprompt = 0;                    /* Restore prompt */
  15005. #ifdef CKSYSLOG
  15006.     int savlog;
  15007. #endif /* CKSYSLOG */
  15008.  
  15009.     extern int what, srvcdmsg;
  15010.  
  15011.     int x = 0, ok = 0, rc = 0;
  15012.     CHAR * _u = NULL, * _p = NULL, * _a = NULL;
  15013.  
  15014.     debug(F111,"ckxlogin userid",userid,promptok);
  15015.     debug(F110,"ckxlogin passwd",passwd,0);
  15016.  
  15017.     isguest = 0;                        /* Global "anonymous" flag */
  15018.  
  15019.     if (!userid) userid = (CHAR *)"";
  15020.     if (!passwd) passwd = (CHAR *)"";
  15021.  
  15022.     debug(F111,"ckxlogin userid",userid,what);
  15023.  
  15024. #ifdef CK_RECALL
  15025.     on_recall = 0;
  15026. #endif /* CK_RECALL */
  15027.  
  15028. #ifdef CKSYSLOG
  15029.     savlog = ckxsyslog;                 /* Save and turn off syslogging */
  15030. #endif /* CKSYSLOG */
  15031.  
  15032.     if ((!*userid || !*passwd) &&       /* Need to prompt for missing info */
  15033.         promptok) {
  15034.         cmsavp(psave,PROMPTL);          /* Save old prompt */
  15035.         debug(F110,"ckxlogin saved",psave,0);
  15036.         rprompt = 1;
  15037.     }
  15038.     if (!*userid) {
  15039.         if (!promptok)
  15040.           return(0);
  15041.         cmsetp("Username: ");           /* Make new prompt */
  15042.         concb((char)escape);            /* Put console in cbreak mode */
  15043.         cmini(1);
  15044.  
  15045. /* Flush typeahead */
  15046.  
  15047. #ifdef IKS_OPTION
  15048.         debug(F101,
  15049.               "ckxlogin TELOPT_SB(TELOPT_KERMIT).kermit.me_start",
  15050.               "",
  15051.               TELOPT_SB(TELOPT_KERMIT).kermit.me_start
  15052.               );
  15053. #endif /* IKS_OPTION */
  15054.  
  15055.         while (ttchk() > 0) {
  15056.             x = ttinc(0);
  15057.             debug(F101,"ckxlogin flush user x","",x);
  15058.             if (x < 0)
  15059.               doexit(GOOD_EXIT,0);      /* Connection lost */
  15060. #ifdef TNCODE
  15061.             if (sstelnet) {
  15062.                 if (x == IAC) {
  15063.                     x = tn_doop((CHAR)(x & 0xff),ckxech,ttinc);
  15064.                     debug(F101,"ckxlogin user tn_doop","",x);
  15065. #ifdef IKS_OPTION
  15066.                     debug(F101,
  15067.                       "ckxlogin user TELOPT_SB(TELOPT_KERMIT).kermit.me_start",
  15068.                       "",
  15069.                       TELOPT_SB(TELOPT_KERMIT).kermit.me_start
  15070.                       );
  15071. #endif /* IKS_OPTION */
  15072.  
  15073.                     if (x < 0)
  15074.                       goto XCKXLOG;
  15075.                     switch (x) {
  15076.                       case 1: ckxech = 1; break; /* Turn on echoing */
  15077.                       case 2: ckxech = 0; break; /* Turn off echoing */
  15078. #ifdef IKS_OPTION
  15079.                       case 4:                    /* IKS event */
  15080.                         if (!TELOPT_SB(TELOPT_KERMIT).kermit.me_start)
  15081.                           break;                 /* else fall thru... */
  15082. #endif /* IKS_OPTION */
  15083.                       case 6:                    /* Logout */
  15084.                         goto XCKXLOG;
  15085.                     }
  15086.                 }
  15087.             }
  15088. #endif /* TNCODE */
  15089.         }
  15090.         if (pflag) prompt(xxstring);    /* Issue prompt if at top level */
  15091.         cmres();                        /* Reset the parser */
  15092.         for (x = -1; x < 0;) {          /* Prompt till they answer */
  15093.             /* Get a literal line of text */
  15094.             x=cmtxt("Your username, or \"ftp\", or \"anonymous\"","",&s,NULL);
  15095.             if (x == -4 || x == -10) {
  15096.                 printf("\r\n%sLogin cancelled\n",
  15097.                x == -10 ? "Timed out: " : "");
  15098. #ifdef CKSYSLOG
  15099.                 ckxsyslog = savlog;
  15100. #endif /* CKSYSLOG */
  15101.                 doexit(GOOD_EXIT,0);
  15102.             }
  15103.             if (sstate)                 /* Did a packet come instead? */
  15104.               goto XCKXLOG;
  15105.             cmres();                    /* Reset the parser again */
  15106.         }
  15107.         if ((_u = (CHAR *)malloc((int)strlen(s) + 1)) == NULL) {
  15108.             printf("?Internal error: malloc\n");
  15109.             goto XCKXLOG;
  15110.         } else {
  15111.             strcpy((char *)_u,s);       /* safe */
  15112.             userid = _u;
  15113.         }
  15114.     }
  15115.     ok = zvuser((char *)userid);        /* Verify username */
  15116.     debug(F111,"ckxlogin zvuser",userid,ok);
  15117.  
  15118.     if (!*passwd && promptok
  15119. #ifdef CK_PAM
  15120.         && guest
  15121. #endif /* CK_PAM */
  15122.         ) {
  15123.         char prmpt[80];
  15124.  
  15125. #ifdef CKSYSLOG
  15126.         savlog = ckxsyslog;             /* Save and turn off syslogging */
  15127.         ckxsyslog = 0;
  15128. #endif /* CKSYSLOG */
  15129.  
  15130. /* Flush typeahead again */
  15131.  
  15132.         while (ttchk() > 0) {
  15133.             x = ttinc(0);
  15134.             debug(F101,"ckxlogin flush user x","",x);
  15135. #ifdef TNCODE
  15136.             if (sstelnet) {
  15137.                 if (x == IAC) {
  15138.                     x = tn_doop((CHAR)(x & 0xff),ckxech,ttinc);
  15139.                     debug(F101,"ckxlogin pass tn_doop","",x);
  15140. #ifdef IKS_OPTION
  15141.                     debug(F101,
  15142.                       "ckxlogin pass TELOPT_SB(TELOPT_KERMIT).kermit.me_start",
  15143.                       "",
  15144.                       TELOPT_SB(TELOPT_KERMIT).kermit.me_start
  15145.                       );
  15146. #endif /* IKS_OPTION */
  15147.                     if (x < 0)
  15148.                       goto XCKXLOG;
  15149.                     switch (x) {
  15150.                       case 1: ckxech = 1; break; /* Turn on echoing */
  15151.                       case 2: ckxech = 0; break; /* Turn off echoing */
  15152.                       case 4:                    /* IKS event */
  15153.                         if (!TELOPT_SB(TELOPT_KERMIT).kermit.me_start)
  15154.                           break;                 /* else fall thru... */
  15155.                       case 6:                    /* Logout */
  15156.                         goto XCKXLOG;
  15157.                     }
  15158.                 }
  15159.             }
  15160. #endif /* TNCODE */
  15161.         }
  15162.         if (!strcmp((char *)userid,"anonymous") ||
  15163.             !strcmp((char *)userid,"ftp")) {
  15164.             if (!ok)
  15165.               goto XCKXLOG;
  15166.             ckstrncpy(prmpt,"Enter e-mail address as Password: ",80);
  15167.         } else if (*userid && strlen((char *)userid) < 60) {
  15168. #ifdef NT
  15169.             extern CHAR * pReferenceDomainName;
  15170.             if (pReferenceDomainName)
  15171.               ckmakxmsg(prmpt,
  15172.                        80,
  15173.                        "Enter ",
  15174.                        pReferenceDomainName,
  15175.                        "\\\\",
  15176.                        userid,
  15177.                        "'s Password: ",
  15178.                        NULL,NULL,NULL,NULL,NULL,NULL,NULL
  15179.                        );
  15180.             else
  15181. #endif /* NT */
  15182.               ckmakmsg(prmpt,80,"Enter ",(char *)userid,"'s Password: ",NULL);
  15183.         } else
  15184.           ckstrncpy(prmpt,"Enter Password: ",80);
  15185.         cmsetp(prmpt);                  /* Make new prompt */
  15186.         concb((char)escape);            /* Put console in cbreak mode */
  15187.         if (strcmp((char *)userid,"anonymous") &&
  15188.             strcmp((char *)userid,"ftp")) { /* and if not anonymous */
  15189.             debok = 0;
  15190.             cmini(0);                   /* and no-echo mode */
  15191.         } else {
  15192.             cmini(1);
  15193.         }
  15194.         if (pflag) prompt(xxstring);    /* Issue prompt if at top level */
  15195.         cmres();                        /* Reset the parser */
  15196.         for (x = -1; x < 0;) {          /* Prompt till they answer */
  15197.             x = cmtxt("","",&s,NULL);   /* Get a literal line of text */
  15198.             if (x == -4 || x == -10) {
  15199.                 printf("\r\n%sLogin cancelled\n",
  15200.                x == -10 ? "Timed out: " : "");
  15201. #ifdef CKSYSLOG
  15202.                 ckxsyslog = savlog;
  15203. #endif /* CKSYSLOG */
  15204.                 doexit(GOOD_EXIT,0);
  15205.             }
  15206.             if (sstate)                 /* In case of a Kermit packet */
  15207.               goto XCKXLOG;
  15208.             cmres();                    /* Reset the parser again */
  15209.         }
  15210.         printf("\r\n");                 /* Echo a CRLF */
  15211.         if ((_p = (CHAR *)malloc((int)strlen(s) + 1)) == NULL) {
  15212.             printf("?Internal error: malloc\n");
  15213.             goto XCKXLOG;
  15214.         } else {
  15215.             strcpy((char *)_p,s);       /* safe */
  15216.             passwd = _p;
  15217.         }
  15218.     }
  15219. #ifdef CK_PAM
  15220.     else {
  15221.         cmres();                        /* Reset the parser */
  15222.  
  15223.         /* We restore the prompt now because the PAM engine will call  */
  15224.         /* readpass() which will overwrite psave. */
  15225.         if (rprompt) {
  15226.             cmsetp(psave);              /* Restore original prompt */
  15227.             debug(F110,"ckxlogin restored",psave,0);
  15228.             rprompt = 0;
  15229.         }
  15230.     }
  15231. #endif /* CK_PAM */
  15232.  
  15233. #ifdef CKSYSLOG
  15234.     ckxsyslog = savlog;
  15235. #endif /* CKSYSLOG */
  15236.  
  15237.     if (ok) {
  15238.         ok = zvpass((char *)passwd);    /* Check password */
  15239.         debug(F101,"ckxlogin zvpass","",ok);
  15240.     }
  15241.  
  15242.     if (ok > 0 && isguest) {
  15243. #ifndef NOPUSH
  15244.         nopush = 1;
  15245. #endif /* NOPUSH */
  15246.         srvcdmsg = 1;
  15247.     }
  15248.     rc = ok;                            /* Set the return code */
  15249.     if ((char *)uidbuf != (char *)userid)
  15250.       ckstrncpy(uidbuf,(char *)userid,UIDBUFLEN); /* Remember username */
  15251.  
  15252.   XCKXLOG:                              /* Common exit */
  15253. #ifdef CKSYSLOG
  15254.     ckxsyslog = savlog;                 /* In case of GOTO above */
  15255. #endif /* CKSYSLOG */
  15256.     if (rprompt) {
  15257.         cmsetp(psave);                  /* Restore original prompt */
  15258.         debug(F110,"ckxlogin restored",psave,0);
  15259.     }
  15260.     if (_u || _p || _a) {
  15261.         if (_u) free(_u);
  15262.         if (_p) free(_p);
  15263.         if (_a) free(_a);
  15264.     }
  15265.     return(rc);
  15266. }
  15267.  
  15268. int
  15269. ckxlogout() {
  15270.     doexit(GOOD_EXIT,0);                /* doexit calls zvlogout */
  15271.     return(0);                          /* not reached */
  15272. }
  15273. #endif /* CK_LOGIN */
  15274.  
  15275. #endif /* NOICP */
  15276.