home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / cku201.zip / ckuus7.c < prev    next >
C/C++ Source or Header  |  2002-01-31  |  519KB  |  14,424 lines

  1. #include "ckcsym.h"
  2.  
  3. /*  C K U U S 7 --  "User Interface" for C-Kermit, part 7  */
  4.  
  5. /*
  6.   Author: Frank da Cruz <fdc@columbia.edu>,
  7.   Columbia University Academic Information Systems, New York City.
  8.  
  9.   Copyright (C) 1985, 2002,
  10.     Trustees of Columbia University in the City of New York.
  11.     All rights reserved.  See the C-Kermit COPYING.TXT file or the
  12.     copyright text in the ckcmai.c module for disclaimer and permissions.
  13. */
  14.  
  15. /*
  16.   This file created from parts of ckuus3.c, which became too big for
  17.   Mark Williams Coherent compiler to handle.
  18. */
  19.  
  20. /*
  21.   Definitions here supersede those from system include files.
  22. */
  23. #include "ckcdeb.h"                     /* Debugging & compiler things */
  24. #include "ckcasc.h"                     /* ASCII character symbols */
  25. #include "ckcker.h"                     /* Kermit application definitions */
  26. #include "ckcxla.h"                     /* Character set translation */
  27. #include "ckcnet.h"                     /* Network symbols */
  28. #include "ckuusr.h"                     /* User interface symbols */
  29. #include "ckucmd.h"
  30.  
  31. #ifdef VMS
  32. #ifndef TCPSOCKET
  33. #include <errno.h>
  34. #endif /* TCPSOCKET */
  35. #endif /* VMS */
  36.  
  37. #ifdef OS2
  38. #ifndef NT
  39. #define INCL_NOPM
  40. #define INCL_VIO                        /* Needed for ckocon.h */
  41. #define INCL_DOSMODULEMGR
  42. #include <os2.h>
  43. #undef COMMENT
  44. #else /* NT */
  45. #define APIRET ULONG
  46. #include <windows.h>
  47. #include <tapi.h>
  48. #include "cknwin.h"
  49. #include "ckntap.h"
  50. #endif /* NT */
  51. #include "ckowin.h"
  52. #include "ckocon.h"
  53. #include "ckodir.h"
  54. #ifdef OS2MOUSE
  55. #include "ckokey.h"
  56. #endif /* OS2MOUSE */
  57. #ifdef KUI
  58. #include "ikui.h"
  59. #endif /* KUI */
  60. #ifdef putchar
  61. #undef putchar
  62. #endif /* putchar */
  63. #define putchar(x) conoc(x)
  64. extern int mskkeys;
  65. #endif /* OS2 */
  66.  
  67. #ifdef CK_AUTHENTICATION
  68. #include "ckuath.h"
  69. #endif /* CK_AUTHENTICATION */
  70. #ifdef CK_SSL
  71. #include "ck_ssl.h"
  72. #endif /* CK_SSL */
  73. #ifdef SSHBUILTIN
  74. #include "ckossh.h"
  75. #endif /* SSHBUILTIN */
  76. #ifdef STRATUS                          /* Stratus Computer, Inc.  VOS */
  77. #ifdef putchar
  78. #undef putchar
  79. #endif /* putchar */
  80. #define putchar(x) conoc(x)
  81. #ifdef getchar
  82. #undef getchar
  83. #endif /* getchar */
  84. #define getchar(x) coninc(0)
  85. #endif /* STRATUS */
  86.  
  87. char * slmsg = NULL;
  88.  
  89. static int x, y = 0, z;
  90. static char *s;
  91.  
  92. extern CHAR feol;
  93. extern int g_matchdot, hints, xcmdsrc;
  94.  
  95. extern char * k_info_dir;
  96.  
  97. #ifndef NOSPL
  98. extern int nmac;
  99. extern struct mtab *mactab;
  100. #endif /* NOSPL */
  101.  
  102. #ifndef NOXFER
  103. #ifdef CK_SPEED
  104. extern short ctlp[];                    /* Control-char prefixing table */
  105. #endif /* CK_SPEED */
  106.  
  107. #ifdef PIPESEND
  108. extern char * sndfilter, * g_sfilter;
  109. extern char * rcvfilter, * g_rfilter;
  110. #endif /* PIPESEND */
  111.  
  112. extern char * snd_move;
  113. extern char * snd_rename;
  114. extern char * g_snd_move;
  115. extern char * g_snd_rename;
  116. extern char * rcv_move;
  117. extern char * rcv_rename;
  118. extern char * g_rcv_move;
  119. extern char * g_rcv_rename;
  120.  
  121. #ifdef PATTERNS
  122. extern char *binpatterns[], *txtpatterns[];
  123. extern int patterns;
  124. #endif /* PATTERNS */
  125.  
  126. extern char * remdest;
  127. #ifdef CK_TMPDIR
  128. char * dldir = NULL;
  129. #endif /* CK_TMPDIR */
  130.  
  131. extern struct ck_p ptab[];
  132.  
  133. extern int protocol, remfile, rempipe, remappd, reliable, xreliable, fmask,
  134.   fncnv, frecl, maxrps, wslotr, bigsbsiz, bigrbsiz, urpsiz, rpsiz, spsiz,
  135.   bctr, npad, timef, timint, spsizr, spsizf, maxsps, spmax, nfils, displa,
  136.   atcapr, pkttim, rtimo, fncact, mypadn, fdispla, f_save, pktpaus, setreliable,
  137.   fnrpath, fnspath, atenci, atenco, atdati, atdato, atleni, atleno, atblki,
  138.   atblko, attypi, attypo, atsidi, atsido, atsysi, atsyso, atdisi, atdiso;
  139.  
  140. extern int stathack;
  141.  
  142. extern int atfrmi, atfrmo;
  143. #ifdef STRATUS
  144. extern int atcrei, atcreo, atacti, atacto;
  145. #endif /* STRATUS */
  146. #ifdef CK_PERMS
  147. extern int atlpri, atlpro, atgpri, atgpro;
  148. #endif /* CK_PERMS */
  149.  
  150. extern CHAR
  151.   sstate, eol, seol, stchr, mystch, mypadc, padch, ctlq, myctlq;
  152.  
  153. #ifdef IKSD
  154. extern int inserver;
  155. #ifdef IKSDCONF
  156. extern int iksdcf;
  157. #endif /* IKSDCONF */
  158. #endif /* IKSD */
  159.  
  160. extern char *cmarg, *cmarg2;
  161.  
  162. #ifndef NOFRILLS
  163. extern char optbuf[];                   /* Buffer for MAIL or PRINT options */
  164. extern int rprintf;                     /* REMOTE PRINT flag */
  165. #endif /* NOFRILLS */
  166. #endif /* NOXFER */
  167.  
  168. #ifdef CK_TRIGGER
  169. extern char * tt_trigger[];
  170. #endif /* CK_TRIGGER */
  171.  
  172. extern int tcs_transp;
  173. #ifdef PCTERM
  174. extern int tt_pcterm;
  175. #endif /* PCTERM */
  176. #ifdef NT
  177. extern int tt_vtnt;
  178. #endif /* NT */
  179.  
  180. #ifdef SSHBUILTIN
  181. int sl_ssh_xfw = 0;
  182. int sl_ssh_xfw_saved = 0;
  183. int sl_ssh_ver = 0;
  184. int sl_ssh_ver_saved = 0;
  185. #endif /* SSHBUILTIN */
  186.  
  187. #ifdef CK_AUTHENTICATION
  188. extern int auth_type_user[];
  189. int sl_auth_type_user[AUTHTYPLSTSZ] = {AUTHTYPE_NULL, AUTHTYPE_NULL};
  190. int sl_auth_saved = 0;
  191. int sl_topt_a_su = 0;
  192. int sl_topt_a_s_saved = 0;
  193. int sl_topt_a_cm = 0;
  194. int sl_topt_a_c_saved = 0;
  195. #endif /* CK_AUTHENTICATION */
  196. #ifdef CK_ENCRYPTION
  197. extern int cx_type;
  198. int sl_cx_type = 0;
  199. int sl_cx_saved = 0;
  200. int sl_topt_e_su = 0;
  201. int sl_topt_e_sm = 0;
  202. int sl_topt_e_s_saved = 0;
  203. int sl_topt_e_cu = 0;
  204. int sl_topt_e_cm = 0;
  205. int sl_topt_e_c_saved = 0;
  206. #endif /* CK_ENCRYPTION */
  207. extern char uidbuf[];
  208. static int uidflag = 0;
  209. char sl_uidbuf[UIDBUFLEN] = { NUL, NUL };
  210. int  sl_uid_saved = 0;
  211. #ifdef TNCODE
  212. int  sl_tn_wait = 0;
  213. int  sl_tn_saved = 0;
  214. #endif /* TNCODE */
  215.  
  216. #ifdef TNCODE
  217. extern int tn_wait_flg;
  218. #endif /* TNCODE */
  219.  
  220. VOID
  221. slrestor() {
  222. #ifdef CK_AUTHENTICATION
  223.     int x;
  224.     if (sl_auth_saved) {
  225.         for (x = 0; x < AUTHTYPLSTSZ; x++)
  226.           auth_type_user[x] = sl_auth_type_user[x];
  227.         sl_auth_saved = 0;
  228.     }
  229.     if (sl_topt_a_s_saved) {
  230.         TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = sl_topt_a_su;
  231.         sl_topt_a_s_saved = 0;
  232.     }
  233.     if (sl_topt_a_c_saved) {
  234.         TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = sl_topt_a_cm;
  235.         sl_topt_a_c_saved = 0;
  236.     }
  237. #endif /* CK_AUTHENTICATION */
  238. #ifdef CK_ENCRYPTION
  239.     if (sl_cx_saved) {
  240.         cx_type = sl_cx_type;
  241.         sl_cx_saved = 0;
  242.     }
  243.     if (sl_topt_e_s_saved) {
  244.         TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION)  = sl_topt_e_su;
  245.         TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION) = sl_topt_e_sm;
  246.         sl_topt_e_s_saved = 0;
  247.     }
  248.     if (sl_topt_e_c_saved) {
  249.         TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION)  = sl_topt_e_cu;
  250.         TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION) = sl_topt_e_cm;
  251.         sl_topt_e_c_saved = 0;
  252.     }
  253. #endif /* CK_ENCRYPTION */
  254.     if (sl_uid_saved) {
  255.         ckstrncpy(uidbuf,sl_uidbuf,UIDBUFLEN);
  256.         sl_uid_saved = 0;
  257.     }
  258. #ifdef TNCODE
  259.     if (sl_tn_saved) {
  260.         tn_wait_flg = sl_tn_wait;
  261.         sl_tn_saved = 0;
  262.     }
  263. #endif /* TNCODE */
  264. #ifdef SSHBUILTIN
  265.     if (sl_ssh_xfw_saved) {
  266.         ssh_xfw = sl_ssh_xfw;
  267.         sl_ssh_xfw_saved = 0;
  268.     }
  269.     if (sl_ssh_ver_saved) {
  270.         ssh_ver = sl_ssh_ver;
  271.         sl_ssh_ver_saved = 0;
  272.     }
  273. #endif /* SSHBUILTIN */
  274. }
  275.  
  276. int oldplex = -1;                       /* Duplex holder around network */
  277.  
  278. #ifndef NOICP
  279.  
  280. /* Note: gcc -Wall wants braces around each keyword table entry. */
  281.  
  282. static struct keytab psltab[] = {       /* SET LINE/PORT command options */
  283.     { "/connect", SL_CNX, 0 },
  284. #ifdef OS2ORVMS
  285.     { "/noshare", SL_NSH, 0 },
  286. #endif /* OS2ORVMS */
  287.     { "/server",  SL_SRV, 0 },
  288. #ifdef OS2ORVMS
  289.     { "/share",   SL_SHR, 0 },
  290. #endif /* OS2ORVMS */
  291.     { "", 0, 0 }
  292. };
  293. static int npsltab = sizeof(psltab)/sizeof(struct keytab) - 1;
  294.  
  295. #ifdef NETCONN
  296. static struct keytab shtab[] = {        /* SET HOST command options */
  297. #ifdef NETCMD
  298.     /* (COMMAND is also a network type) */
  299.     { "/command",      SL_CMD,    CM_INV },
  300. #endif /* NETCMD */
  301.     { "/connect",      SL_CNX,    0 },
  302.     { "/network-type", SL_NET,    CM_ARG },
  303.     { "/nowait",       SL_NOWAIT, 0 },
  304. #ifndef NOSPL
  305. #ifdef CK_AUTHENTICATION
  306.     { "/password",     SL_PSW,    CM_ARG },
  307. #endif /* CK_AUTHENTICATION */
  308. #endif /* NOSPL */
  309. #ifdef NETCMD
  310.     { "/pipe",         SL_CMD,    0 },
  311. #endif /* NETCMD */
  312. #ifdef NETPTY
  313.     { "/pty",          SL_PTY,    0 },
  314. #endif /* NETPTY */
  315.     { "/server",       SL_SRV,    0 },
  316.     { "/timeout",      SL_TMO,    CM_ARG },
  317.     { "/userid",       SL_UID,    CM_ARG },
  318.     { "/wait",         SL_WAIT,   0 },
  319.     { "", 0, 0 }
  320. };
  321. static int nshtab = sizeof(shtab)/sizeof(struct keytab) - 1;
  322.  
  323. static struct keytab shteltab[] = {     /* TELNET command options */
  324. #ifdef CK_AUTHENTICATION
  325.     { "/auth",         SL_AUTH,   CM_ARG },
  326. #endif /* CK_AUTHENTICATION */
  327. #ifdef CK_ENCRYPTION
  328.     { "/encrypt",      SL_ENC,    CM_ARG },
  329. #endif /* CK_ENCRYPTION */
  330.     { "/nowait",       SL_NOWAIT, 0 },
  331. #ifndef NOSPL
  332. #ifdef CK_AUTHENTICATION
  333.     { "/password",     SL_PSW,    CM_ARG },
  334. #endif /* CK_AUTHENTICATION */
  335. #endif /* NOSPL */
  336.     { "/timeout",      SL_TMO,    CM_ARG },
  337.     { "/userid",       SL_UID,    CM_ARG },
  338.     { "/wait",         SL_WAIT,   0 },
  339.     { "", 0 ,0 }
  340. };
  341. static int nshteltab = sizeof(shteltab)/sizeof(struct keytab) - 1;
  342.  
  343. #ifdef RLOGCODE
  344. static struct keytab shrlgtab[] = {     /* SET HOST RLOGIN command options */
  345. #ifdef CK_KERBEROS
  346. #ifdef CK_ENCRYPTION
  347.     { "/encrypt",      SL_ENC, 0 },
  348. #endif /* CK_ENCRYPTION */
  349.     { "/k4",           SL_KRB4, CM_INV },
  350.     { "/k5",           SL_KRB5, CM_INV },
  351.     { "/kerberos4",    SL_KRB4, 0 },
  352.     { "/kerberos5",    SL_KRB5, 0 },
  353.     { "/kerberos_iv",  SL_KRB4, CM_INV },
  354.     { "/kerberos_v",   SL_KRB5, CM_INV },
  355.     { "/krb4",         SL_KRB4, CM_INV },
  356.     { "/krb5",         SL_KRB5, CM_INV },
  357. #endif /* CK_KERBEROS */
  358.     { "", 0 ,0 }
  359. };
  360. static int nshrlgtab = sizeof(shrlgtab)/sizeof(struct keytab)-1;
  361. #endif /* RLOGCODE */
  362.  
  363. extern struct keytab netcmd[];
  364. extern int nnets;
  365. #ifndef NODIAL
  366. extern int dirline;
  367. extern int nnetdir;                     /* Network services directory */
  368. extern char *netdir[];
  369. _PROTOTYP( VOID ndreset, (void) );
  370. char *nh_p[MAXDNUMS + 1];               /* Network directory entry pointers */
  371. char *nh_p2[MAXDNUMS + 1];              /* Network directory entry nettype */
  372. char *nh_px[4][MAXDNUMS + 1];           /* Network-specific stuff... */
  373. #endif /* NODIAL */
  374. int nhcount = 0;
  375. int ndinited = 0;
  376. char * n_name = NULL;                   /* Network name pointer */
  377. #endif /* NETCONN */
  378.  
  379. _PROTOTYP(int remtxt, (char **) );
  380. _PROTOTYP(VOID rmsg, (void) );
  381. _PROTOTYP(static int remcfm, (void) );
  382.  
  383. extern int nopush;
  384.  
  385. int mdmsav = -1;                        /* Save modem type around network */
  386. extern int isguest;                     /* Global flag for anonymous login */
  387.  
  388. extern xx_strp xxstring;
  389.  
  390. extern int success, binary, b_save, ckwarn, msgflg, quiet, cmask, pflag, local,
  391.   nettype, escape, mdmtyp, duplex, dfloc, network, cdtimo, autoflow, tnlm,
  392.   sosi, tlevel, lf_opts, backgrd, flow, debses, parity, ttnproto, ckxech,
  393.   x_ifnum, cmflgs, haveline, cxtype, cxflow[], maclvl;
  394.  
  395. #ifdef DCMDBUF
  396. extern struct cmdptr *cmdstk;           /* The command stack itself */
  397. #else
  398. extern struct cmdptr cmdstk[];          /* The command stack itself */
  399. #endif /* DCMDBUF */
  400. extern FILE * tfile[];
  401. extern char * macp[];
  402.  
  403. extern char psave[];                    /* For saving & restoring prompt */
  404. extern int sprmlen, rprmlen;
  405.  
  406. #ifdef OS2
  407. static struct keytab strmkeytab[] = {
  408.     { "clear",   0, 0 },
  409.     { "default", 1, 0 }
  410. };
  411. static int nstrmkeytab = sizeof(strmkeytab)/sizeof(struct keytab);
  412.  
  413. static struct keytab strmswitab[] = {
  414.     { "/literal", 0, 0 }
  415. };
  416. static int nstrmswitab = sizeof(strmswitab)/sizeof(struct keytab);
  417.  
  418. static struct keytab normrev[] = {
  419.     { "dark-display", 0, 0 },
  420.     { "light-display", 1, 0 },
  421.     { "normal",   0, 0 },
  422.     { "reverse",  1, 0 }
  423. };
  424.  
  425. static struct keytab prnmtab[] = {
  426.     { "auto", 1, 0 },
  427.     { "copy", 2, 0 },
  428.     { "off",  0, 0 },
  429.     { "on",   1, CM_INV },              /* Compatibility with XPRINT version */
  430.     { "user", 3, 0 },
  431.     { "transparent", 3, CM_INV }        /* not really transparent */
  432. };
  433. static int nprnmtab = sizeof(prnmtab)/sizeof(struct keytab);
  434.  
  435. extern int tt_diff_upd;
  436.  
  437. #ifdef NT
  438. #define stricmp _stricmp
  439. extern int tt_attr_bug;
  440. #endif /* NT */
  441. extern int tt_rows[], tt_cols[];
  442. extern int tt_cols_usr;
  443. extern int tt_szchng[VNUM];
  444. int tt_modechg = TVC_ENA;
  445. extern int tt_url_hilite, tt_url_hilite_attr;
  446. extern struct _vtG G[4];
  447. extern int priority;
  448. extern bool send_c1;
  449. int send_c1_usr = FALSE;
  450. extern int sgrcolors;
  451. extern int marginbell, marginbellcol;
  452. extern int autoscroll, wy_autopage;
  453. extern int tt_sac;
  454. extern int dec_nrc, dec_lang, dec_kbd;
  455. #else /* OS2 */
  456. extern int tt_rows, tt_cols;
  457. #endif /*  OS2 */
  458.  
  459. extern int tt_escape;
  460. extern long speed;
  461.  
  462. extern char *dftty;
  463.  
  464. extern char *tp, *lp;                   /* Temporary buffer & pointers */
  465. extern char ttname[];
  466.  
  467. int tttapi = 0;                         /* is Line TAPI? */
  468. struct keytab * tapilinetab = NULL;
  469. struct keytab * _tapilinetab = NULL;
  470. int ntapiline = 0;
  471.  
  472. #ifdef NETCONN                          /* Network items */
  473.  
  474. #ifdef ANYX25
  475. extern int revcall, closgr, cudata, nx25;
  476. extern char udata[];
  477. extern struct keytab x25tab[];
  478. #ifndef IBMX25
  479. extern int npadx3;
  480. extern CHAR padparms[];
  481. extern struct keytab padx3tab[];
  482. #endif /* IBMX25 */
  483. #endif /* ANYX25 */
  484.  
  485. #ifdef OS2
  486. extern bool ttshare;
  487. #ifndef NT
  488. extern bool ttslip,ttppp;
  489. #endif /* NT */
  490. #endif /* OS2 */
  491. #ifdef NPIPE
  492. extern char pipename[];
  493. #endif /* NPIPE */
  494.  
  495. #ifdef TCPSOCKET
  496. static struct keytab tcprawtab[] = {    /* SET HOST options */
  497.     { "/default",    NP_DEFAULT,    CM_INV },
  498. #ifdef CK_AUTHENTICATION
  499. #ifdef CK_KERBEROS
  500. #ifdef RLOGCODE
  501.     { "/ek4login",    NP_EK4LOGIN,    0 },
  502.     { "/ek5login",    NP_EK5LOGIN,    0 },
  503.     { "/k4login",     NP_K4LOGIN,     0 },
  504.     { "/k5login",     NP_K5LOGIN,     0 },
  505. #endif /* RLOGCODE */
  506. #ifdef KRB5_U2U
  507.     { "/k5user2user", NP_K5U2U,       0 },
  508. #endif /* KRB5_U2U */
  509. #endif /* CK_KERBEROS */
  510. #endif /* CK_AUTHENTICATION */
  511.     { "/no-telnet-init", NP_NONE,   0 },
  512.     { "/none",       NP_NONE,   CM_INV },
  513.     { "/raw-socket", NP_TCPRAW, 0 },
  514. #ifdef RLOGCODE
  515.     { "/rlogin",     NP_RLOGIN, 0 },
  516. #endif /* RLOGCODE */
  517. #ifdef CK_SSL
  518.     { "/ssl",        NP_SSL,    0 },
  519.     { "/ssl-telnet", NP_SSL_TELNET, 0 },
  520. #endif /* CK_SSL */
  521.     { "/telnet",     NP_TELNET, 0 },
  522. #ifdef CK_SSL
  523.     { "/tls",        NP_TLS,    0 },
  524.     { "/tls-telnet", NP_TLS_TELNET, 0 },
  525. #endif /* CK_SSL */
  526.     { "", 0, 0 }
  527. };
  528. static int ntcpraw = (sizeof(tcprawtab) / sizeof(struct keytab)) - 1;
  529.  
  530. #ifdef RLOGCODE
  531. _PROTOTYP( int rlog_naws, (void) );
  532. #endif /* RLOGCODE */
  533. #endif /* TCPSOCKET */
  534.  
  535. #ifdef SUPERLAT
  536. extern char slat_pwd[18];
  537. #endif /* SUPERLAT */
  538. #endif /* NETCONN */
  539.  
  540. #ifdef COMMENT
  541. #ifndef NOSETKEY
  542. extern KEY *keymap;
  543. #ifndef OS2
  544. #define mapkey(x) keymap[x]
  545. #endif /* OS2 */
  546. extern MACRO *macrotab;
  547. #ifndef NOKVERBS
  548. extern struct keytab kverbs[];
  549. extern int nkverbs;
  550. #endif /* NOKVERBS */
  551. #endif /* NOSETKEY */
  552. #else
  553. #ifndef NOSETKEY
  554. extern KEY *keymap;
  555. extern MACRO *macrotab;
  556. #ifndef NOKVERBS
  557. extern struct keytab kverbs[];
  558. extern int nkverbs;
  559. #endif /* NOKVERBS */
  560. #endif /* NOSETKEY */
  561. #endif /* COMMENT */
  562.  
  563. #ifdef OS2                              /* AUTODOWNLOAD parameters */
  564. extern int    adl_kmode, adl_zmode;     /* Match Packet to signal download */
  565. extern char * adl_kstr;                 /* KERMIT Download String */
  566. extern char * adl_zstr;                 /* ZMODEM Download String */
  567. extern int adl_kc0, adl_zc0;            /* Process ADL C0s in emulation */
  568. #endif /* OS2 */
  569.  
  570. /* Keyword tables ... */
  571.  
  572. extern struct keytab onoff[], rltab[];
  573. extern int nrlt;
  574.  
  575. #ifndef NOCSETS
  576. static struct keytab fdfltab[] = {
  577.     { "7bit-character-set", 7, 0 },
  578.     { "8bit-character-set", 8, 0 }
  579. };
  580. static int nfdflt = (sizeof(fdfltab) / sizeof(struct keytab));
  581. #endif /* NOCSETS */
  582.  
  583. /* SET FILE parameters */
  584.  
  585. static struct keytab filtab[] = {
  586. #ifndef NOXFER
  587. #ifdef PATTERNS
  588.     { "binary-patterns",   XYFIBP,  0 },
  589. #endif /* PATTERNS */
  590.     { "bytesize",         XYFILS,   0 },
  591. #ifndef NOCSETS
  592.     { "character-set",    XYFILC,   0 },
  593. #endif /* NOCSETS */
  594.     { "collision",        XYFILX,   0 },
  595.     { "default",          XYF_DFLT, 0 },
  596.     { "destination",      XYFILY,   0 },
  597.     { "display",          XYFILD,   CM_INV },
  598. #ifdef CK_TMPDIR
  599.     { "download-directory", XYFILG, 0 },
  600. #endif /* CK_TMPDIR */
  601. #endif /* NOXFER */
  602.     { "end-of-line",      XYFILA,   0 },
  603.     { "eol",              XYFILA,   CM_INV },
  604. #ifdef CK_CTRLZ
  605.     { "eof",              XYFILV,   0 },
  606. #endif /* CK_CTRLZ */
  607. #ifndef NOXFER
  608.     { "fastlookups",      9997,     CM_INV },
  609.     { "incomplete",       XYFILI,   0 },
  610. #ifndef datageneral
  611.     { "inspection",       XYF_INSP, CM_INV },
  612. #endif /* datageneral */
  613. #ifdef CK_LABELED
  614.     { "label",            XYFILL, 0 },
  615. #endif /* CK_LABELED */
  616.  
  617. #ifdef UNIX
  618. #ifdef DYNAMIC
  619.     { "listsize",         XYF_LSIZ, 0 },
  620. #endif /* DYNAMIC */
  621. #endif /* UNIX */
  622.  
  623.     { "names",            XYFILN, 0 },
  624. #ifdef UNIX
  625.     { "output",           XYFILH, 0 },
  626. #endif /* UNIX */
  627. #ifdef PATTERNS
  628.     { "patterns",         XYFIPA, 0 },
  629. #endif /* PATTERNS */
  630.     { "permissions",      XYF_PRM, CM_INV },
  631.     { "protection",       XYF_PRM, 0 },
  632. #ifdef VMS
  633.     { "record-length",    XYFILR, 0 },
  634. #endif /* VMS */
  635. #ifndef datageneral
  636.     { "scan",             XYF_INSP, 0 },
  637. #endif /* datageneral */
  638.  
  639. #ifdef UNIX
  640. #ifdef DYNAMIC
  641.     { "stringspace",      XYF_SSPA, 0 },
  642. #endif /* DYNAMIC */
  643. #endif /* UNIX */
  644.  
  645. #ifdef PATTERNS
  646.     { "t",                XYFILT, CM_INV|CM_ABR },
  647.     { "text-patterns",    XYFITP, 0 },
  648. #endif /* PATTERNS */
  649. #endif /* NOXFER */
  650.     { "type",             XYFILT, 0 },
  651. #ifdef UNICODE
  652.     { "ucs",              XYFILU, 0 },
  653. #endif /* UNICODE */
  654. #ifndef NOXFER
  655.     { "warning",          XYFILW, CM_INV }
  656. #endif /* NOXFER */
  657. };
  658. static int nfilp = (sizeof(filtab) / sizeof(struct keytab));
  659.  
  660. struct keytab pathtab[] = {
  661.     { "absolute",  PATH_ABS,  0      },
  662.     { "none",      PATH_OFF,  CM_INV },
  663.     { "off",       PATH_OFF,  0      },
  664.     { "on",        PATH_ABS,  CM_INV },
  665.     { "relative",  PATH_REL,  0      }
  666. };
  667. int npathtab = (sizeof(pathtab) / sizeof(struct keytab));
  668.  
  669. struct keytab rpathtab[] = {
  670.     { "absolute",  PATH_ABS,  0      },
  671.     { "auto",      PATH_AUTO, 0      },
  672.     { "none",      PATH_OFF,  CM_INV },
  673.     { "off",       PATH_OFF,  0      },
  674.     { "on",        PATH_ABS,  CM_INV },
  675.     { "relative",  PATH_REL,  0      }
  676. };
  677. int nrpathtab = (sizeof(rpathtab) / sizeof(struct keytab));
  678.  
  679. #ifdef CK_CTRLZ
  680. struct keytab eoftab[] = {              /* EOF detection method */
  681.     { "ctrl-z",          1, 0      },
  682.     { "length",          0, 0      },
  683.     { "noctrl-z",        0, CM_INV }
  684. };
  685. #endif /* CK_CTRLZ */
  686.  
  687. struct keytab fttab[] = {               /* File types for SET FILE TYPE */
  688.     { "ascii",     XYFT_T, CM_INV },
  689. #ifdef VMS
  690.     { "b",         XYFT_B, CM_INV|CM_ABR },
  691. #endif /* VMS */
  692.     { "binary",    XYFT_B, 0 },
  693. #ifdef VMS
  694.     { "block",     XYFT_I, CM_INV },
  695.     { "image",     XYFT_I, 0 },
  696. #endif /* VMS */
  697. #ifdef CK_LABELED
  698.     { "labeled",   XYFT_L, 0 },
  699. #endif /* CK_LABELED */
  700. #ifdef MAC
  701.     { "macbinary", XYFT_M, 0 },
  702. #endif /* MAC */
  703.     { "text",      XYFT_T, 0 }
  704. };
  705. int nfttyp = (sizeof(fttab) / sizeof(struct keytab));
  706.  
  707. static struct keytab rfttab[] = {       /* File types for REMOTE SET FILE */
  708.     { "ascii",     XYFT_T, CM_INV },
  709.     { "binary",    XYFT_B, 0 },
  710. #ifdef VMS
  711.     { "labeled",   XYFT_L, 0 },
  712. #else
  713. #ifdef OS2
  714.     { "labeled",   XYFT_L, 0 },
  715. #endif /* OS2 */
  716. #endif /* VMS */
  717.     { "text",      XYFT_T, 0 }
  718. };
  719. static int nrfttyp = (sizeof(rfttab) / sizeof(struct keytab));
  720.  
  721. #ifdef OS2ORUNIX
  722. #define ZOF_BLK  0
  723. #define ZOF_NBLK 1
  724. #define ZOF_BUF  2
  725. #define ZOF_NBUF 3
  726. static struct keytab zoftab[] = {
  727.     { "blocking",    ZOF_BLK,  0 },
  728.     { "buffered",    ZOF_BUF,  0 },
  729.     { "nonblocking", ZOF_NBLK, 0 },
  730.     { "unbuffered",  ZOF_NBUF, 0 }
  731. };
  732. static int nzoftab = (sizeof(zoftab) / sizeof(struct keytab));
  733. #endif /* OS2ORUNIX */
  734.  
  735. extern int query;                       /* Global flag for QUERY active */
  736.  
  737. #ifndef NOSPL
  738. #ifndef NOXFER
  739. static struct keytab vartyp[] = {       /* Variable types for REMOTE QUERY */
  740.     { "global",   (int) 'G', CM_INV },
  741.     { "kermit",   (int) 'K', 0 },
  742.     { "system",   (int) 'S', 0 },
  743.     { "user",     (int) 'G', 0 }
  744. };
  745. static int nvartyp = (sizeof(vartyp) / sizeof(struct keytab));
  746. #endif /* NOXFER */
  747. #endif /* NOSPL */
  748.  
  749. #ifdef CK_TIMERS
  750. static struct keytab timotab[] = {      /* Timer types */
  751.     { "dynamic", 1, 0 },
  752.     { "fixed",   0, 0 }
  753. };
  754. #endif /* CK_TIMERS */
  755.  
  756. #ifdef DCMDBUF
  757. extern char *atxbuf, *atmbuf;           /* Atom buffer */
  758. extern char *cmdbuf;                    /* Command buffer */
  759. extern char *line, *tmpbuf;             /* Character buffers for anything */
  760. extern int *intime;                     /* INPUT TIMEOUT */
  761.  
  762. #else  /* Not DCMDBUF ... */
  763.  
  764. extern char atxbuf[], atmbuf[];         /* Atom buffer */
  765. extern char cmdbuf[];                   /* Command buffer */
  766. extern char line[], tmpbuf[];           /* Character buffer for anything */
  767. extern int intime[];
  768.  
  769. #endif /* DCMDBUF */
  770.  
  771. #ifndef NOCSETS
  772. extern struct keytab fcstab[];          /* For SET FILE CHARACTER-SET */
  773. extern struct csinfo fcsinfo[];         /* File character set info. */
  774. extern struct keytab ttcstab[];
  775. extern int nfilc, fcharset, tcharset, ntermc, tcsr, tcsl, dcset7, dcset8;
  776. #ifdef CKOUNI
  777. extern int tt_utf8;
  778. #endif /* CKOUNI */
  779. #ifdef OS2
  780. _PROTOTYP( int os2setcp, (int) );
  781. _PROTOTYP( int os2getcp, (void) );
  782. _PROTOTYP( void os2debugoff, (void) );
  783. #endif /* OS2 */
  784. #endif /* NOCSETS */
  785.  
  786. extern int cmdlvl;                      /* Overall command level */
  787.  
  788. #ifndef NOSPL
  789. #ifdef DCMDBUF
  790. extern int *inpcas;                     /* INPUT CASE setting on cmd stack */
  791. #else
  792. extern int inpcas[];
  793. #endif /* DCMDBUF */
  794. #endif /* NOSPL */
  795.  
  796. #ifdef CK_CURSES
  797. #ifndef VMS
  798. _PROTOTYP(int tgetent,(char *, char *));
  799. #else
  800. #ifdef __DECC
  801. _PROTOTYP(int tgetent,(char *, char *));
  802. #endif /* __DECC */
  803. #endif /* VMS */
  804. #endif /* CK_CURSES */
  805.  
  806. #ifndef NOXMIT
  807. #define XMITF 0                         /* SET TRANSMIT values */
  808. #define XMITL 1                         /* (Local to this module) */
  809. #define XMITP 2
  810. #define XMITE 3
  811. #define XMITX 4
  812. #define XMITS 5
  813. #define XMITW 6
  814. #define XMITT 7
  815.  
  816. #define XMBUFL 50
  817. extern int xmitf, xmitl, xmitp, xmitx, xmits, xmitw, xmitt;
  818. char xmitbuf[XMBUFL+1] = { NUL };       /* TRANSMIT eof string */
  819.  
  820. struct keytab xmitab[] = {              /* SET TRANSMIT */
  821.     { "echo",          XMITX, 0 },
  822.     { "eof",           XMITE, 0 },
  823.     { "fill",          XMITF, 0 },
  824.     { "linefeed",      XMITL, 0 },
  825.     { "locking-shift", XMITS, 0 },
  826.     { "pause",         XMITW, 0 },
  827.     { "prompt",        XMITP, 0 },
  828.     { "timeout",       XMITT, 0 }
  829. };
  830. int nxmit = (sizeof(xmitab) / sizeof(struct keytab));
  831. #endif /* NOXMIT */
  832.  
  833. /* For SET FILE COLLISION */
  834. /* Some of the following may be possible for some C-Kermit implementations */
  835. /* but not others.  Those that are not possible for your implementation */
  836. /* should be ifdef'd out. */
  837.  
  838. struct keytab colxtab[] = { /* SET FILE COLLISION options */
  839. #ifndef MAC
  840.     { "append",    XYFX_A, 0 },         /* append to old file */
  841. #endif /* MAC */
  842. #ifdef COMMENT
  843.     { "ask",       XYFX_Q, 0 },         /* ask what to do (not implemented) */
  844. #endif
  845.     { "backup",    XYFX_B, 0 },         /* rename old file */
  846. #ifndef MAC
  847.     /* This crashes Mac Kermit. */
  848.     { "discard",   XYFX_D, 0 },         /* don't accept new file */
  849.     { "no-supersede", XYFX_D, CM_INV }, /* ditto (MSK compatibility) */
  850. #endif /* MAC */
  851.     { "overwrite", XYFX_X, 0 },         /* overwrite the old file */
  852.     { "rename",    XYFX_R, 0 },         /* rename the incoming file */
  853. #ifndef MAC                             /* This crashes Mac Kermit. */
  854.     { "update",    XYFX_U, 0 },         /* replace if newer */
  855. #endif /* MAC */
  856.     { "", 0, 0 }
  857. };
  858. int ncolx = (sizeof(colxtab) / sizeof(struct keytab)) - 1;
  859.  
  860. static struct keytab rfiltab[] = {      /* for REMOTE SET FILE */
  861. #ifndef NOCSETS
  862.     { "character-set", XYFILC, 0 },
  863. #endif /* NOCSETS */
  864.     { "collision",     XYFILX, 0 },
  865.     { "incomplete",    XYFILI, 0 },
  866.     { "names",         XYFILN, 0 },
  867.     { "record-length", XYFILR, 0 },
  868.     { "type",          XYFILT, 0 }
  869. };
  870. int nrfilp = (sizeof(rfiltab) / sizeof(struct keytab));
  871.  
  872. struct keytab eoltab[] = {              /* File eof delimiters */
  873.     { "cr",        XYFA_C, 0 },
  874.     { "crlf",      XYFA_2, 0 },
  875.     { "lf",        XYFA_L, 0 }
  876. };
  877. static int neoltab = (sizeof(eoltab) / sizeof(struct keytab));
  878.  
  879. struct keytab fntab[] = {               /* File naming */
  880.     { "converted", XYFN_C, 0      },
  881.     { "literal",   XYFN_L, 0      },
  882.     { "standard",  XYFN_C, CM_INV }
  883. };
  884. int nfntab = (sizeof(fntab) / sizeof(struct keytab));
  885.  
  886. #ifndef NOLOCAL
  887. /* Terminal parameters table */
  888. static struct keytab trmtab[] = {
  889. #ifdef OS2
  890.     { "answerback",    XYTANS,    0 },
  891. #endif /* OS2 */
  892. #ifdef CK_APC
  893.     { "apc",           XYTAPC,    0 },
  894. #endif /* CK_APC */
  895. #ifdef OS2
  896.     { "arrow-keys",    XYTARR,    0 },
  897. #endif /* OS2 */
  898. #ifdef NT
  899.     { "at",            XYTATTR,   CM_INV|CM_ABR },
  900.     { "att",           XYTATTR,   CM_INV|CM_ABR },
  901.     { "attr",          XYTATTR,   CM_INV|CM_ABR },
  902.     { "attr-bug",      XYTATTBUG, CM_INV },
  903. #endif /* NT */
  904. #ifdef OS2
  905.     { "attribute",     XYTATTR,   0 },
  906. #endif /* OS2 */
  907. #ifdef CK_APC
  908. #ifdef CK_AUTODL
  909.    { "autodownload",   XYTAUTODL, 0, },
  910. #endif /* CK_AUTODL */
  911. #endif /* CK_APC */
  912. #ifdef OS2
  913.     { "autopage",      XYTAPAGE,  0 },
  914.     { "autoscroll",    XYTASCRL,  0 },
  915.     { "bell",          XYTBEL,    CM_INV },
  916. #endif /* OS2 */
  917.     { "bytesize",      XYTBYT,    0 },
  918. #ifndef NOCSETS
  919.     { "character-set", XYTCS,     0 },
  920. #endif /* NOCSETS */
  921. #ifdef OS2
  922.     { "code-page",     XYTCPG,    0 },
  923.     { "color",         XYTCOL,    0 },
  924.     { "controls",      XYTCTRL,   0 },
  925. #endif /* OS2 */
  926.     { "cr-display",    XYTCRD,    0 },
  927. #ifdef OS2
  928.     { "cursor",        XYTCUR,    0 },
  929. #endif /* OS2 */
  930.     { "debug",         XYTDEB,    0 },
  931. #ifdef OS2
  932.     { "dg-unix-mode",  XYTUNX,    0 },
  933. #endif /* OS2 */
  934.     { "echo",          XYTEC,     0 },
  935.     { "escape-character", XYTESC, 0 },
  936. #ifdef OS2
  937. #ifdef PCFONTS
  938.     { "font",          XYTFON,    0 },
  939. #else
  940. #ifdef KUI
  941.     { "font",          XYTFON,    0 },
  942. #endif /* KUI */
  943. #endif /* PCFONTS */
  944. #endif /* OS2 */
  945.     { "height",        XYTHIG,    0 },
  946. #ifdef CKTIDLE
  947.     { "idle-action",   XYTIACT,   0 },
  948.     { "idle-limit",    XYTITMO,   CM_INV },
  949.     { "idle-send",     XYTIDLE,   CM_INV },
  950.     { "idle-timeout",  XYTITMO,   0 },
  951. #endif /* CKTIDLE */
  952. #ifdef OS2
  953. #ifndef NOCSETS
  954.     { "kbd-follows-gl/gr", XYTKBDGL, 0 },
  955. #endif /* NOCSETS */
  956.     { "key",           XYTKEY,    0 },
  957.     { "keyboard-mode", XYTKBMOD,  0 },
  958.     { "keypad-mode",   XYTKPD,    0 },
  959. #endif /* OS2 */
  960. #ifndef NOCSETS
  961. #ifdef OS2
  962. #ifndef KUI
  963.     { "local-character-set", XYTLCS,  0 },
  964. #else
  965.     { "local-character-set", XYTLCS,  CM_INV },
  966. #endif /* KUI */
  967. #else
  968.     { "local-character-set", XYTLCS,  CM_INV },
  969. #endif /* OS2 */
  970. #endif /* NOCSETS */
  971.     { "locking-shift", XYTSO,     0 },
  972. #ifdef OS2
  973.     { "margin-bell",   XYTMBEL,   0 },
  974. #endif /* OS2 */
  975. #ifdef OS2MOUSE
  976.     { "mouse",         XYTMOU,    CM_INV },
  977. #endif /* OS2MOUSE */
  978.     { "newline-mode",  XYTNL,     0 },
  979. #ifdef OS2
  980.     { "output-pacing", XYTPAC,    0 },
  981. #ifdef PCTERM
  982.     { "pcterm",        XYTPCTERM, 0 },
  983. #endif /* PCTERM */
  984. #endif /* OS2 */
  985. #ifdef OS2ORUNIX
  986.     { "print",         XYTPRN,    0 },
  987. #endif /* OS2ORUNIX */
  988. #ifndef NOCSETS
  989. #ifdef OS2
  990.     { "remote-character-set", XYTRCS,  0 },
  991. #else
  992.     { "remote-character-set", XYTRCS,  CM_INV },
  993. #endif /* OS2 */
  994. #endif /* NOCSETS */
  995. #ifdef OS2
  996.     { "roll-mode",       XYTROL, 0 },
  997.     { "s",               XYTUPD, CM_ABR|CM_INV },
  998.     { "sc",              XYTUPD, CM_ABR|CM_INV },
  999.     { "scr",             XYTUPD, CM_ABR|CM_INV },
  1000.     { "scree",           XYTUPD, CM_ABR|CM_INV },
  1001.     { "screen",          XYTUPD, CM_ABR|CM_INV },
  1002.     { "screen-",         XYTUPD, CM_ABR|CM_INV },
  1003.     { "screen-mode",     XYTSCNM,   0 },
  1004.     { "screen-optimize", XYTOPTI,   0 },
  1005.     { "screen-update",   XYTUPD,    0 },
  1006.     { "scrollback",      XYSCRS,    0 },
  1007.     { "send-data",         XYTSEND, 0 },
  1008.     { "send-end-of-block", XYTSEOB, 0 },
  1009.     { "sgr-colors",            XYTSGRC,  0 },
  1010.     { "sni-ch.code",           XYTSNICC, 0 },
  1011.     { "sni-firmware-versions", XYTSNIFV, 0 },
  1012.     { "sni-language",          XYTVTLNG, 0 },
  1013.     { "sni-pagemode",          XYTSNIPM, CM_INV },
  1014.     { "sni-scrollmode",              XYTSNISM, CM_INV },
  1015.     { "spacing-attribute-character", XYTSAC,   CM_INV },
  1016.     { "statusline",                  XYTSTAT,  0 },
  1017.     { "tra",                         XYTCTS,   CM_INV|CM_ABR },
  1018.     { "transmit-timeout",            XYTCTS,   0 },
  1019. #endif /* OS2 */
  1020.  
  1021. #ifdef OS2ORUNIX
  1022.     { "transparent-print", XYTPRN,   CM_INV },
  1023. #endif /* OS2ORUNIX */
  1024.  
  1025. #ifdef CK_TRIGGER
  1026.     { "trigger",           XYTRIGGER,0 },
  1027. #endif /* CK_TRIGGER */
  1028. #ifdef OS2
  1029.     { "type",              XYTTYP,   0 },
  1030. #else
  1031.     { "type",              XYTTYP,   CM_INV },
  1032. #endif /* OS2 */
  1033.  
  1034. #ifndef NOCSETS
  1035. #ifdef UNICODE
  1036. #ifdef CKOUNI
  1037.     { "unicode",           XYTUNI,   CM_INV },
  1038. #endif /* CKOUNI */
  1039. #endif /* UNICODE */
  1040. #endif /* NOCSETS */
  1041. #ifdef OS2
  1042.     { "unix-mode",         XYTUNX,   CM_INV },
  1043.     { "url-highlight",     XYTURLHI, 0 },
  1044. #ifdef NT
  1045.     { "video-change",      XYTVCH,   0 },
  1046. #endif /* NT */
  1047.     { "vt-language",       XYTVTLNG, 0 },
  1048.     { "vt-nrc-mode",       XYTVTNRC, 0 },
  1049. #endif /* OS2 */
  1050.     { "width",             XYTWID,   0 },
  1051. #ifdef OS2
  1052.     { "wrap",              XYTWRP,   0 },
  1053. #endif /* OS2 */
  1054.     { "", 0, 0 }
  1055. };
  1056. int ntrm = (sizeof(trmtab) / sizeof(struct keytab)) - 1;
  1057.  
  1058. #ifdef OS2
  1059. struct keytab termctrl[] = {    /* SET TERM CONTROLS */
  1060.     { "7",      7, 0 },
  1061.     { "8",      8, 0 }
  1062. };
  1063. int ntermctrl = (sizeof(termctrl) / sizeof(struct keytab));
  1064.  
  1065. struct keytab rolltab[] = {   /* Set TERM Roll Options */
  1066.     { "insert",    TTR_INSERT, 0      },
  1067.     { "off",       TTR_OVER,   CM_INV },
  1068.     { "on",        TTR_INSERT, CM_INV },
  1069.     { "overwrite", TTR_OVER,   0      }
  1070. };
  1071. int nroll = (sizeof(rolltab) / sizeof(struct keytab));
  1072.  
  1073. #define TT_GR_ALL 4
  1074. #define TT_GR_G0  0
  1075. #define TT_GR_G1  1
  1076. #define TT_GR_G2  2
  1077. #define TT_GR_G3  3
  1078. #define TT_GR_KBD 4
  1079. struct keytab graphsettab[] = {  /* DEC VT Graphic Sets */
  1080.     { "all",      TT_GR_ALL, 0 },
  1081.     { "g0",       TT_GR_G0,  0 },
  1082.     { "g1",       TT_GR_G1,  0 },
  1083.     { "g2",       TT_GR_G2,  0 },
  1084.     { "g3",       TT_GR_G3,  0 },
  1085.     { "keyboard", TT_GR_KBD, 0 }
  1086. };
  1087. int ngraphset = (sizeof(graphsettab) / sizeof(struct keytab));
  1088. #endif /* OS2 */
  1089.  
  1090. struct keytab adltab[] = {              /* Autodownload Options */
  1091.     { "error",   TAD_ERR, 0 },
  1092. #ifdef OS2
  1093.     { "kermit",  TAD_K,   0 },
  1094. #endif /* OS2 */
  1095.     { "off",     TAD_OFF, 0 },
  1096.     { "on",      TAD_ON,  0 },
  1097. #ifdef OS2
  1098.     { "zmodem",  TAD_Z,   0 },
  1099. #endif /* OS2 */
  1100.     { "", 0, 0 }
  1101. };
  1102. int nadltab = (sizeof(adltab) / sizeof(struct keytab)) - 1;
  1103.  
  1104. struct keytab adlerrtab[] = {           /* Autodownload Error Options */
  1105.     { "continue", 0, 0 },
  1106.     { "go",       0, CM_INV },
  1107.     { "stop",     1, 0 }
  1108. };
  1109. int nadlerrtab = (sizeof(adlerrtab) / sizeof(struct keytab));
  1110.  
  1111. #ifdef OS2
  1112. struct keytab adlxtab[] = {             /* Autodownload Options */
  1113.     { "c0-conflicts",     TAD_X_C0,     0 },
  1114.     { "detection-method", TAD_X_DETECT, 0 },
  1115.     { "string",           TAD_X_STR,    0 }
  1116. };
  1117. int nadlxtab = (sizeof(adlxtab) / sizeof(struct keytab));
  1118.  
  1119. struct keytab adldtab[] = {             /* Auto-dl Detection Methods */
  1120.     { "packet",           ADL_PACK,     0 },
  1121.     { "string",           ADL_STR,      0 }
  1122. };
  1123. int nadldtab = (sizeof(adldtab) / sizeof(struct keytab));
  1124.  
  1125. struct keytab adlc0tab[] = {            /* Auto-dl Detection Methods */
  1126.     { "ignored-by-emulator",    0,      0 },
  1127.     { "processed-by-emulator",  1,      0 }
  1128. };
  1129. int nadlc0tab = (sizeof(adlc0tab) / sizeof(struct keytab));
  1130.  
  1131. #ifndef NOCSETS
  1132. struct keytab vtlangtab[] = {
  1133.     { "belgian",        VTL_BELGIAN , 0 },
  1134.     { "british",        VTL_BRITISH , 0 },
  1135.     { "canadian",       VTL_CANADIAN, 0 },
  1136.     { "czech",          VTL_CZECH   , 0 },
  1137.     { "danish",         VTL_DANISH  , 0 },
  1138.     { "dutch",          VTL_DUTCH   , 0 },
  1139.     { "finnish",        VTL_FINNISH , 0 },
  1140.     { "french",         VTL_FRENCH  , 0 },
  1141.     { "french-canadian",VTL_FR_CAN  , 0 },
  1142.     { "german",         VTL_GERMAN  , 0 },
  1143.     { "greek",          VTL_GREEK   , 0 },
  1144.     { "hebrew",         VTL_HEBREW  , 0 },
  1145.     { "hungarian",      VTL_HUNGARIA, 0 },
  1146.     { "italian",        VTL_ITALIAN , 0 },
  1147.     { "latin-american", VTL_LATIN_AM, 0 },
  1148.     { "north-american", VTL_NORTH_AM, 0 },
  1149.     { "norwegian",      VTL_NORWEGIA, 0 },
  1150.     { "polish",         VTL_POLISH  , 0 },
  1151.     { "portugese",      VTL_PORTUGES, 0 },
  1152.     { "romanian",       VTL_ROMANIAN, 0 },
  1153.     { "russian",        VTL_RUSSIAN , 0 },
  1154.     { "scs",            VTL_SCS     , CM_INV },
  1155.     { "slovak",         VTL_SLOVAK  , 0 },
  1156.     { "spanish",        VTL_SPANISH , 0 },
  1157.     { "swedish",        VTL_SWEDISH , 0 },
  1158.     { "swiss-french",   VTL_SW_FR   , 0 },
  1159.     { "swiss-german",   VTL_SW_GR   , 0 },
  1160.     { "turkish-f",      VTL_TURK_F  , CM_INV },
  1161.     { "turkish-q",      VTL_TURK_Q  , CM_INV }
  1162. };
  1163. int nvtlangtab = (sizeof(vtlangtab) / sizeof(struct keytab));
  1164. #endif /* NOCSETS */
  1165. #endif /* OS2 */
  1166.  
  1167. struct keytab crdtab[] = {              /* Carriage-return display */
  1168.     { "crlf",        1, 0 },
  1169.     { "normal",      0, 0 }
  1170. };
  1171. extern int tt_crd;                      /* Carriage-return display variable */
  1172.  
  1173. #ifdef CK_APC
  1174. extern int apcstatus, apcactive;
  1175. static struct keytab apctab[] = {       /* Terminal APC parameters */
  1176.     {  "no-input", APC_ON|APC_NOINP,0 },
  1177.     { "off",       APC_OFF,  0 },
  1178.     { "on",        APC_ON,   0 },
  1179.     { "unchecked", APC_ON|APC_UNCH, 0 },
  1180.     { "unchecked-no-input", APC_ON|APC_NOINP|APC_UNCH, 0 }
  1181. };
  1182. int napctab = (sizeof(apctab) / sizeof(struct keytab));
  1183. #endif /* CK_APC */
  1184. #endif /* NOLOCAL */
  1185.  
  1186. extern int autodl, adl_err;
  1187.  
  1188. struct keytab beltab[] = {              /* Terminal bell mode */
  1189. #ifdef OS2
  1190.     { "audible", XYB_AUD,  0 },
  1191.     { "none",    XYB_NONE, 0 },
  1192. #else
  1193.     { "audible", XYB_AUD,  CM_INV },
  1194.     { "none",    XYB_NONE, CM_INV },
  1195. #endif /* OS2 */
  1196. #ifdef OS2
  1197.     { "off",     XYB_NONE, CM_INV },
  1198.     { "on",      XYB_AUD,  CM_INV },
  1199. #else
  1200.     { "off",     XYB_NONE, 0 },
  1201.     { "on",      XYB_AUD,  0 },
  1202. #endif /* OS2 */
  1203. #ifdef OS2
  1204.     { "visible", XYB_VIS,  0 },
  1205. #endif /* OS2 */
  1206.     { "", 0, 0 }
  1207. };
  1208. int nbeltab = sizeof(beltab)/sizeof(struct keytab) - 1;
  1209.  
  1210. int tt_unicode = 1;                     /* Use Unicode if possible */
  1211. #ifdef CKTIDLE
  1212. int tt_idlesnd_tmo = 0;                 /* Idle Send Timeout, disabled */
  1213. char * tt_idlesnd_str = NULL;           /* Idle Send String, none */
  1214. char * tt_idlestr = NULL;
  1215. extern int tt_idleact, tt_idlelimit;
  1216. #endif /* CKTIDLE */
  1217.  
  1218. #ifdef OS2
  1219. #ifndef NOLOCAL
  1220. /*
  1221.   OS/2 serial communication devices.
  1222. */
  1223. struct keytab os2devtab[] = {
  1224.     { "1",    1, CM_INV },                      /* Invisible synonyms, like */
  1225.     { "2",    2, CM_INV },                      /* "set port 1" */
  1226.     { "3",    3, CM_INV },
  1227.     { "4",    4, CM_INV },
  1228.     { "5",    5, CM_INV },
  1229.     { "6",    6, CM_INV },
  1230.     { "7",    7, CM_INV },
  1231.     { "8",    8, CM_INV },
  1232.     { "com1", 1, 0 },                   /* Real device names */
  1233.     { "com2", 2, 0 },
  1234.     { "com3", 3, 0 },
  1235.     { "com4", 4, 0 },
  1236.     { "com5", 5, 0 },
  1237.     { "com6", 6, 0 },
  1238.     { "com7", 7, 0 },
  1239.     { "com8", 8, 0 },
  1240. #ifdef OS2ONLY
  1241.     { "slipcom1", 1, 0 },                       /* For use with SLIP driver */
  1242.     { "slipcom2", 2, 0 },                       /* shared access */
  1243.     { "slipcom3", 3, 0 },
  1244.     { "slipcom4", 4, 0 },
  1245.     { "slipcom5", 5, 0 },
  1246.     { "slipcom6", 6, 0 },
  1247.     { "slipcom7", 7, 0 },
  1248.     { "slipcom8", 8, 0 },
  1249.     { "pppcom1", 1, 0 },                        /* For use with PPP driver */
  1250.     { "pppcom2", 2, 0 },                        /* shared access */
  1251.     { "pppcom3", 3, 0 },
  1252.     { "pppcom4", 4, 0 },
  1253.     { "pppcom5", 5, 0 },
  1254.     { "pppcom6", 6, 0 },
  1255.     { "pppcom7", 7, 0 },
  1256.     { "pppcom8", 8, 0 }
  1257. #endif /* OS2ONLY */
  1258. };
  1259. int nos2dev = (sizeof(os2devtab) / sizeof(struct keytab)) - 1;
  1260.  
  1261. #ifdef OS2ONLY
  1262. struct keytab os2ppptab[] = {
  1263.     { "0",    0, CM_INV },
  1264.     { "1",    1, CM_INV },                      /* Invisible synonyms, like */
  1265.     { "2",    2, CM_INV },                      /* "set port 1" */
  1266.     { "3",    3, CM_INV },
  1267.     { "4",    4, CM_INV },
  1268.     { "5",    5, CM_INV },
  1269.     { "6",    6, CM_INV },
  1270.     { "7",    7, CM_INV },
  1271.     { "8",    8, CM_INV },
  1272.     { "9",    9, CM_INV },
  1273.     { "ppp0", 0, 0 },
  1274.     { "ppp1", 1, 0 },                   /* For use with PPP driver */
  1275.     { "ppp2", 2, 0 },                   /* shared access */
  1276.     { "ppp3", 3, 0 },
  1277.     { "ppp4", 4, 0 },
  1278.     { "ppp5", 5, 0 },
  1279.     { "ppp6", 6, 0 },
  1280.     { "ppp7", 7, 0 },
  1281.     { "ppp8", 8, 0 },
  1282.     { "ppp9", 9, 0 }
  1283. };
  1284. int nos2ppp = (sizeof(os2ppptab) / sizeof(struct keytab));
  1285. #endif /* OS2ONLY */
  1286.  
  1287. /*
  1288.   Terminal parameters that can be set by SET commands.
  1289.   Used by the ck?con.c terminal emulator code.
  1290.   For now, only used for #ifdef OS2.  Should add these for Macintosh.
  1291. */
  1292. int tt_arrow = TTK_NORM;                /* Arrow key mode: normal (cursor) */
  1293. int tt_keypad = TTK_NORM;               /* Keypad mode: normal (numeric) */
  1294. int tt_shift_keypad = 0;                /* Keypad Shift mode: Off */
  1295. int tt_wrap = 1;                        /* Terminal wrap, 1 = On */
  1296. int tt_type = TT_VT320;                 /* Terminal type, initially VT320 */
  1297. int tt_type_mode = TT_VT320;            /* Terminal type set by host command */
  1298. int tt_cursor = 0;                      /* Terminal cursor, 0 = Underline */
  1299. int tt_cursor_usr = 0;                  /* Users Terminal cursor type */
  1300. int tt_cursorena_usr = 1;               /* Users Terminal cursor enabled */
  1301. int tt_answer = 0;                      /* Terminal answerback (disabled) */
  1302. int tt_scrsize[VNUM] = {512,512,512,1}; /* Terminal scrollback buffer size */
  1303. int tt_roll[VNUM] = {1,1,1,1};          /* Terminal roll (on) */
  1304. int tt_pacing = 0;                      /* Terminal output-pacing (none) */
  1305. int tt_ctstmo = 15;                     /* Terminal transmit-timeout */
  1306. int tt_codepage = -1;                   /* Terminal code-page */
  1307. int tt_update = 100;                    /* Terminal screen-update interval */
  1308. int tt_updmode = TTU_FAST;              /* Terminal screen-update mode FAST */
  1309. extern int updmode;
  1310. #ifndef KUI
  1311. int tt_status[VNUM] = {1,1,0,0};        /* Terminal status line displayed */
  1312. int tt_status_usr[VNUM] = {1,1,0,0};
  1313. #else  /* KUI */
  1314. #ifdef K95G
  1315. int tt_status[VNUM] = {1,1,0,0};        /* Terminal status line displayed */
  1316. int tt_status_usr[VNUM] = {1,1,0,0};
  1317. #else /* K95G */
  1318. int tt_status[VNUM] = {0,0,0,0};        /* Terminal status line displayed */
  1319. int tt_status_usr[VNUM] = {0,0,0,0};
  1320. #endif /* K95G */
  1321. #endif /* KUI */
  1322. int tt_senddata = 0;                    /* Let host read terminal data */
  1323. extern int wy_blockend;                 /* Terminal Send Data EOB type */
  1324. int tt_hidattr = 1;                     /* Attributes are hidden */
  1325.  
  1326. extern unsigned char colornormal, colorselect,
  1327. colorunderline, colorstatus, colorhelp, colorborder,
  1328. colorgraphic, colordebug, colorreverse;
  1329.  
  1330. extern int trueblink, trueunderline, truereverse;
  1331.  
  1332. extern int bgi, fgi;
  1333. extern int scrninitialized[];
  1334.  
  1335. struct keytab audibletab[] = {          /* Terminal Bell Audible mode */
  1336.     { "beep",          XYB_BEEP, 0 },   /* Values ORd with bell mode */
  1337.     { "system-sounds", XYB_SYS,  0 }
  1338. };
  1339. int naudibletab = sizeof(audibletab)/sizeof(struct keytab);
  1340.  
  1341. struct keytab akmtab[] = {              /* Arrow key mode */
  1342.     { "application", TTK_APPL, 0 },
  1343.     { "cursor",      TTK_NORM, 0 }
  1344. };
  1345. struct keytab kpmtab[] = {              /* Keypad mode */
  1346.     { "application", TTK_APPL, 0 },
  1347.     { "numeric",     TTK_NORM, 0 }
  1348. };
  1349.  
  1350. struct keytab ttcolmodetab[] = {
  1351.     { "current-color", 0, 0 },
  1352.     { "default-color", 1, 0 }
  1353. };
  1354. int ncolmode = sizeof(ttcolmodetab)/sizeof(struct keytab);
  1355.  
  1356. #define TTCOLNOR  0
  1357. #define TTCOLREV  1
  1358. #define TTCOLUND  2
  1359. #define TTCOLSTA  3
  1360. #define TTCOLHLP  4
  1361. #define TTCOLBOR  5
  1362. #define TTCOLSEL  6
  1363. #define TTCOLDEB  7
  1364. #define TTCOLGRP  8
  1365.  
  1366. #define TTCOLRES  10
  1367. #define TTCOLERA  11
  1368.  
  1369. struct keytab ttycoltab[] = {                   /* Terminal Screen coloring */
  1370.     { "border",             TTCOLBOR, 0 },      /* Screen border color */
  1371.     { "debug-terminal",     TTCOLDEB, 0 },      /* Debug color */
  1372.     { "erase",              TTCOLERA, 0 },      /* Erase mode */
  1373.     { "graphic",            TTCOLGRP, 0 },      /* Graphic Color */
  1374.     { "help-text",          TTCOLHLP, 0 },      /* Help screens */
  1375.     { "normal",             TTCOLNOR, CM_INV }, /* Normal screen text */
  1376.     { "reset-on-esc[0m",    TTCOLRES, 0 },      /* Reset on ESC [ 0 m */
  1377.     { "reverse-video",      TTCOLREV, 0 },      /* Reverse video */
  1378.     { "status-line",        TTCOLSTA, 0 },      /* Status line */
  1379.     { "selection",          TTCOLSEL, 0 },      /* Selection color */
  1380.     { "terminal-screen",    TTCOLNOR, 0 },      /* Better name than "normal" */
  1381.     { "underlined-text",    TTCOLUND, 0 }       /* Underlined text */
  1382. };
  1383. int ncolors = (sizeof(ttycoltab) / sizeof(struct keytab));
  1384.  
  1385. #define TTATTNOR  0
  1386. #define TTATTBLI  1
  1387. #define TTATTREV  2
  1388. #define TTATTUND  3
  1389. #define TTATTPRO  4
  1390. #define TTATTBLD  5
  1391. #define TTATTDIM  6
  1392. #define TTATTINV  7
  1393. #define TTATTDONE 8
  1394.  
  1395. struct keytab ttyattrtab[] = {
  1396.     { "blink",     TTATTBLI, 0 },
  1397.     { "protected", TTATTPRO, 0 },
  1398.     { "reverse",   TTATTREV, 0 },
  1399.     { "underline", TTATTUND, 0 }
  1400. };
  1401. int nattrib = (sizeof(ttyattrtab) / sizeof(struct keytab));
  1402.  
  1403. struct keytab ttyprotab[] = {
  1404.     { "blink",       TTATTBLI,  0 },
  1405.     { "bold",        TTATTBLD,  0 },
  1406.     { "dim",         TTATTDIM,  0 },
  1407.     { "done",        TTATTDONE, CM_INV },
  1408.     { "invisible",   TTATTINV,  0 },
  1409.     { "normal",      TTATTNOR,  0 },
  1410.     { "reverse",     TTATTREV,  0 },
  1411.     { "underlined",  TTATTUND,  0 }
  1412.  
  1413. };
  1414. int nprotect = (sizeof(ttyprotab) / sizeof(struct keytab));
  1415.  
  1416. struct keytab ttyseobtab[] = {
  1417.     { "crlf_etx",  1, 0 },
  1418.     { "us_cr",     0, 0 }
  1419. };
  1420.  
  1421. struct keytab ttyclrtab[] = {           /* Colors */
  1422.     { "black",         0, 0      },
  1423.     { "blue",          1, 0      },
  1424.     { "brown",         6, 0      },
  1425.     { "cyan",          3, 0      },
  1426.     { "darkgray",      8, CM_INV },
  1427.     { "dgray",         8, 0      },
  1428.     { "green",         2, 0      },
  1429.     { "lblue",         9, CM_INV },
  1430.     { "lcyan",        11, CM_INV },
  1431.     { "lgray",         7, CM_INV },
  1432.     { "lgreen",       10, CM_INV },
  1433.     { "lightblue",     9, 0      },
  1434.     { "lightcyan",    11, 0      },
  1435.     { "lightgray",     7, 0      },
  1436.     { "lightgreen",   10, 0      },
  1437.     { "lightmagenta", 13, 0      },
  1438.     { "lightred",     12, 0      },
  1439.     { "lmagenta",     13, CM_INV },
  1440.     { "lred",         12, CM_INV },
  1441.     { "magenta",       5, 0      },
  1442.     { "red",           4, 0      },
  1443.     { "white",        15, 0      },
  1444.     { "yellow",       14, 0      }
  1445. };
  1446. int nclrs = (sizeof (ttyclrtab) / sizeof (struct keytab));
  1447.  
  1448. struct keytab ttycurtab[] = {
  1449.     { "full",        TTC_BLOCK, 0 },
  1450.     { "half",        TTC_HALF,  0 },
  1451.     { "underline",   TTC_ULINE, 0 }
  1452. };
  1453. int ncursors = 3;
  1454.  
  1455. struct keytab ttyptab[] = {
  1456.     { "adm3a",    TT_ADM3A,   0 },          /* LSI ADM-3A */
  1457.     { "aixterm",  TT_AIXTERM, 0 },          /* IBM AIXterm */
  1458.     { "ansi-bbs", TT_ANSI,    0 },          /* ANSI.SYS (BBS) */
  1459.     { "at386",    TT_AT386,   0 },          /* Unixware ANSI */
  1460.     { "avatar/0+",TT_ANSI,    0 },          /* AVATAR/0+ */
  1461.     { "ba80",     TT_BA80,    0 },          /* Nixdorf BA80 */
  1462.     { "be",       TT_BEOS,    CM_INV|CM_ABR },
  1463.     { "beos-ansi",TT_BEOS,    CM_INV },     /* BeOS ANSI */
  1464.     { "beterm",   TT_BEOS,    0 },          /* BeOS Terminal (as of PR2 ) */
  1465.     { "d200",     TT_DG200,   CM_INV|CM_ABR }, /* Data General DASHER 200 */
  1466.     { "d210",     TT_DG210,   CM_INV|CM_ABR }, /* Data General DASHER 210 */
  1467.     { "d217",     TT_DG217,   CM_INV|CM_ABR }, /* Data General DASHER 217 */
  1468.     { "dg200",    TT_DG200,   0 },          /* Data General DASHER 200 */
  1469.     { "dg210",    TT_DG210,   0 },          /* Data General DASHER 210 */
  1470.     { "dg217",    TT_DG217,   0 },          /* Data General DASHER 217 */
  1471.     { "h1500",    TT_HZL1500, CM_INV },     /* Hazeltine 1500 */
  1472.     { "h19",      TT_H19,     CM_INV },     /* Heath-19 */
  1473.     { "heath19",  TT_H19,     0 },          /* Heath-19 */
  1474.     { "hft",      TT_HFT,     0 },          /* IBM High Function Terminal */
  1475.     { "hp2621a",  TT_HP2621,  0 },          /* HP 2621A */
  1476.     { "hpterm",   TT_HPTERM,  0 },          /* HP TERM */
  1477.     { "hz1500",   TT_HZL1500, 0 },          /* Hazeltine 1500 */
  1478.     { "ibm3151",  TT_IBM31,   0 },          /* IBM 3101-xx,3161 */
  1479.     { "linux",    TT_LINUX,   0 },          /* Linux */
  1480.     { "qansi",    TT_QANSI,   0 },          /* QNX ANSI */
  1481.     { "qnx",      TT_QNX,     0 },          /* QNX Console */
  1482.     { "scoansi",  TT_SCOANSI, 0 },          /* SCO ANSI */
  1483.     { "sni-97801",TT_97801,   0 },          /* SNI 97801 */
  1484. /*
  1485.   The idea of NONE is to let the console driver handle the escape sequences,
  1486.   which, in theory at least, would give not only ANSI emulation, but also any
  1487.   other kind of emulation that might be provided by alternative console
  1488.   drivers, if any existed.
  1489.  
  1490.   For this to work, ckocon.c would need to be modified to make higher-level
  1491.   calls, like VioWrtTTY(), DosWrite(), or (simply) write(), rather than
  1492.   VioWrt*Cell() and similar, and it would also have to give up its rollback
  1493.   feature, and its status line and help screens would also have to be
  1494.   forgotten or else done in an ANSI way.
  1495.  
  1496.   As matters stand, we already have perfectly good ANSI emulation built in,
  1497.   and there are no alternative console drivers available, so there is no point
  1498.   in having a terminal type of NONE, so it is commented out.  However, should
  1499.   you uncomment it, it will work like a "glass tty" -- no escape sequence
  1500.   interpretation at all; somewhat similar to debug mode, except without the
  1501.   debugging (no highlighting of control chars or escape sequences); help
  1502.   screens, status line, and rollback will still work.
  1503. */
  1504. #ifdef OS2PM
  1505. #ifdef COMMENT
  1506.     { "tek4014", TT_TEK40,  0 },
  1507. #endif /* COMMENT */
  1508. #endif /* OS2PM */
  1509.     { "tty",     TT_NONE,   0 },
  1510.     { "tvi910+", TT_TVI910, 0 },
  1511.     { "tvi925",  TT_TVI925, 0 },
  1512.     { "tvi950",  TT_TVI950, 0 },
  1513.     { "vc404",   TT_VC4404, 0 },
  1514.     { "vc4404",  TT_VC4404, CM_INV },
  1515.     { "vip7809", TT_VIP7809,0 },
  1516.     { "vt100",   TT_VT100,  0 },
  1517.     { "vt102",   TT_VT102,  0 },
  1518.     { "vt220",   TT_VT220,  0 },
  1519.     { "vt220pc", TT_VT220PC,0 },
  1520.     { "vt320",   TT_VT320,  0 },
  1521.     { "vt320pc", TT_VT320PC,0 },
  1522.     { "vt52",    TT_VT52,   0 },
  1523. #ifdef NT
  1524.     { "vtnt",    TT_VTNT,   0 },
  1525. #else /* NT */
  1526.     { "vtnt",    TT_VTNT,  CM_INV },
  1527. #endif /* NT */
  1528.     { "wy160",   TT_WY160,  0 },
  1529.     { "wy30",    TT_WY30,   0 },
  1530.     { "wy370",   TT_WY370,  0 },
  1531.     { "wy50",    TT_WY50,   0 },
  1532.     { "wy60",    TT_WY60,   0 },
  1533.     { "wyse30",  TT_WY30,   CM_INV },
  1534.     { "wyse370", TT_WY370,  CM_INV },
  1535.     { "wyse50",  TT_WY50,   CM_INV },
  1536.     { "wyse60",  TT_WY60,   CM_INV }
  1537. };
  1538. int nttyp = (sizeof(ttyptab) / sizeof(struct keytab));
  1539.  
  1540. struct keytab ttkeytab[] = {
  1541.     { "adm3a",     TT_ADM3A,      0 },             /* LSI ADM-3A */
  1542.     { "aixterm",   TT_AIXTERM,    0 },             /* IBM AIXterm */
  1543.     { "ansi-bbs",  TT_ANSI,       0 },             /* ANSI.SYS (BBS) */
  1544.     { "at386",     TT_AT386,      0 },             /* Unixware ANSI */
  1545.     { "avatar/0+", TT_ANSI,       0 },             /* AVATAR/0+ */
  1546.     { "ba80",      TT_BA80,       0 },             /* Nixdorf BA80 */
  1547.     { "be",        TT_BEOS,       CM_INV|CM_ABR },
  1548.     { "beos-ansi", TT_BEOS,       CM_INV },        /* BeOS ANSI */
  1549.     { "beterm",    TT_BEOS,       0 },             /* BeOS Terminal (DR2) */
  1550.     { "d200",      TT_DG200,      CM_INV|CM_ABR }, /* DG DASHER 200 */
  1551.     { "d210",      TT_DG210,      CM_INV|CM_ABR }, /* DG DASHER 210 */
  1552.     { "d217",      TT_DG217,      CM_INV|CM_ABR }, /* DG DASHER 217 */
  1553.     { "dg200",     TT_DG200,      0 },             /* DG DASHER 200 */
  1554.     { "dg210",     TT_DG210,      0 },             /* DG DASHER 210 */
  1555.     { "dg217",     TT_DG217,      0 },             /* DG DASHER 217 */
  1556.     { "emacs",     TT_KBM_EMACS,  0 },             /* Emacs mode */
  1557.     { "h19",       TT_H19,        CM_INV },        /* Heath-19 */
  1558.     { "heath19",   TT_H19,        0 },             /* Heath-19 */
  1559.     { "hebrew",    TT_KBM_HEBREW, 0 },             /* Hebrew mode */
  1560.     { "hft",       TT_HFT,        0 },             /* IBM High Function Term */
  1561.     { "hp2621a",   TT_HP2621,     0 },             /* HP 2621A */
  1562.     { "hpterm",    TT_HPTERM,     0 },             /* HP TERM */
  1563.     { "hz1500",    TT_HZL1500,    0 },             /* Hazeltine 1500 */
  1564.     { "ibm3151",   TT_IBM31,      0 },             /* IBM 3101-xx,3161 */
  1565.     { "linux",     TT_LINUX,      0 },             /* Linux */
  1566.     { "qansi",     TT_QANSI,      0 },             /* QNX ANSI */
  1567.     { "qnx",       TT_QNX,        0 },             /* QNX */
  1568.     { "russian",   TT_KBM_RUSSIAN,0 },             /* Russian mode */
  1569.     { "scoansi",   TT_SCOANSI,    0 },             /* SCO ANSI */
  1570.     { "sni-97801", TT_97801,      0 },             /* SNI 97801 */
  1571. #ifdef OS2PM
  1572. #ifdef COMMENT
  1573.     { "tek4014",   TT_TEK40,      0 },
  1574. #endif /* COMMENT */
  1575. #endif /* OS2PM */
  1576.     { "tty",       TT_NONE,       0 },
  1577.     { "tvi910+",   TT_TVI910,     0 },
  1578.     { "tvi925",    TT_TVI925,     0 },
  1579.     { "tvi950",    TT_TVI950,     0 },
  1580.     { "vc404",     TT_VC4404,     0 },
  1581.     { "vc4404",    TT_VC4404,     CM_INV },
  1582.     { "vip7809",   TT_VIP7809,    0 },
  1583.     { "vt100",     TT_VT100,      0 },
  1584.     { "vt102",     TT_VT102,      0 },
  1585.     { "vt220",     TT_VT220,      0 },
  1586.     { "vt220pc",   TT_VT220PC,    0 },
  1587.     { "vt320",     TT_VT320,      0 },
  1588.     { "vt320pc",   TT_VT320PC,    0 },
  1589.     { "vt52",      TT_VT52,       0 },
  1590.     { "vtnt",      TT_VTNT,       CM_INV },
  1591.     { "wp",        TT_KBM_WP,     0 },             /* Word Perfect mode */
  1592.     { "wy160",     TT_WY160,      0 },
  1593.     { "wy30",      TT_WY30,       0 },
  1594.     { "wy370",     TT_WY370,      0 },
  1595.     { "wy50",      TT_WY50,       0 },
  1596.     { "wy60",      TT_WY60,       0 },
  1597.     { "wyse30",    TT_WY30,       CM_INV },
  1598.     { "wyse370",   TT_WY370,      CM_INV },
  1599.     { "wyse50",    TT_WY50,       CM_INV },
  1600.     { "wyse60",    TT_WY60,       CM_INV }
  1601. };
  1602. int nttkey = (sizeof(ttkeytab) / sizeof(struct keytab));
  1603.  
  1604. #ifndef NOSETKEY
  1605. struct keytab kbmodtab[] = {
  1606.     { "emacs",   KBM_EM, 0      },
  1607.     { "english", KBM_EN, CM_INV },
  1608.     { "hebrew",  KBM_HE, 0      },
  1609.     { "normal",  KBM_EN, 0      },
  1610.     { "none",    KBM_EN, CM_INV },
  1611.     { "russian", KBM_RU, 0      },
  1612.     { "wp",      KBM_WP, 0      }
  1613. };
  1614. int nkbmodtab = (sizeof(kbmodtab) / sizeof(struct keytab));
  1615. #endif /* NOSETKEY */
  1616. #endif /* NOLOCAL */
  1617.  
  1618. int tt_inpacing = 0;                    /* input-pacing (none) */
  1619.  
  1620. struct keytab prtytab[] = { /* OS/2 Priority Levels */
  1621.     { "foreground-server", XYP_SRV, 0       },
  1622.     { "idle",              XYP_IDLE, CM_INV },
  1623.     { "regular",           XYP_REG, 0       },
  1624.     { "time-critical",     XYP_RTP, 0       }
  1625. };
  1626. int nprty = (sizeof(prtytab) / sizeof(struct keytab));
  1627. #endif /* OS2 */
  1628.  
  1629. #ifdef NT
  1630. struct keytab win95tab[] = { /* Win95 work-arounds */
  1631.     { "8.3-filenames",         XYW8_3,    0 },
  1632.     { "alt-gr",                XYWAGR,    0 },
  1633.     { "keyboard-translation",  XYWKEY,    0 },
  1634.     { "lucida-substitutions",  XYWLUC,    0 },
  1635.     { "overlapped-io",         XYWOIO,    0 },
  1636.     { "popups",                XYWPOPUP,  0 },
  1637.     { "select-bug",            XYWSELECT, 0 }
  1638. };
  1639. int nwin95 = (sizeof(win95tab) / sizeof(struct keytab));
  1640. #endif /* NT */
  1641.  
  1642. #ifdef OS2MOUSE
  1643. extern int wideresult;
  1644. int tt_mouse = 1;                       /* Terminal mouse on/off */
  1645.  
  1646. struct keytab mousetab[] = {            /* Mouse items */
  1647.     { "activate", XYM_ON,     0 },
  1648.     { "button",   XYM_BUTTON, 0 },
  1649.     { "clear",    XYM_CLEAR,  0 },
  1650.     { "debug",    XYM_DEBUG,  0 }
  1651. };
  1652. int nmtab = (sizeof(mousetab)/sizeof(struct keytab));
  1653.  
  1654. struct keytab mousebuttontab[] = {      /* event button */
  1655.     { "1",             XYM_B1, 0 },
  1656.     { "2",             XYM_B2, 0 },
  1657.     { "3",             XYM_B3, 0 },
  1658.     { "one",           XYM_B1, CM_INV },
  1659.     { "three",         XYM_B3, CM_INV },
  1660.     { "two",           XYM_B2, CM_INV }
  1661. };
  1662. int nmbtab = (sizeof(mousebuttontab) / sizeof(struct keytab));
  1663.  
  1664. struct keytab mousemodtab[] = {         /* event button key modifier */
  1665.     { "alt",              XYM_ALT,   0 },
  1666.     { "alt-shift",        XYM_SHIFT|XYM_ALT, 0 },
  1667.     { "ctrl",             XYM_CTRL,  0 },
  1668.     { "ctrl-alt",         XYM_CTRL|XYM_ALT, 0 },
  1669.     { "ctrl-alt-shift",   XYM_CTRL|XYM_SHIFT|XYM_ALT, 0 },
  1670.     { "ctrl-shift",       XYM_CTRL|XYM_SHIFT, 0 },
  1671.     { "none",             0, 0 },
  1672.     { "shift",            XYM_SHIFT, 0 }
  1673. };
  1674. int nmmtab = (sizeof(mousemodtab) / sizeof(struct keytab));
  1675.  
  1676. struct keytab mclicktab[] = {           /* event button click modifier */
  1677.     { "click",        XYM_C1,   0 },
  1678.     { "drag",         XYM_DRAG, 0 },
  1679.     { "double-click", XYM_C2,   0 }
  1680. };
  1681. int nmctab = (sizeof(mclicktab) / sizeof(struct keytab));
  1682.  
  1683. #ifndef NOKVERBS
  1684. extern int nkverbs;
  1685. extern struct keytab kverbs[];
  1686. #endif /* NOKVERBS */
  1687. #endif /* OS2MOUSE */
  1688.  
  1689. /* #ifdef VMS */
  1690. struct keytab fbtab[] = {               /* Binary record types for VMS */
  1691.     { "fixed",     XYFT_B, 0 },         /* Fixed is normal for binary */
  1692.     { "undefined", XYFT_U, 0 }          /* Undefined if they ask for it */
  1693. };
  1694. int nfbtyp = (sizeof(fbtab) / sizeof(struct keytab));
  1695. /* #endif */
  1696.  
  1697. #ifdef VMS
  1698. struct keytab lbltab[] = {              /* Labeled File info */
  1699.     { "acl",         LBL_ACL, 0 },
  1700.     { "backup-date", LBL_BCK, 0 },
  1701.     { "name",        LBL_NAM, 0 },
  1702.     { "owner",       LBL_OWN, 0 },
  1703.     { "path",        LBL_PTH, 0 }
  1704. };
  1705. int nlblp = (sizeof(lbltab) / sizeof(struct keytab));
  1706. #else
  1707. #ifdef OS2
  1708. struct keytab lbltab[] = {              /* Labeled File info */
  1709.     { "archive",   LBL_ARC, 0 },
  1710.     { "extended",  LBL_EXT, 0 },
  1711.     { "hidden",    LBL_HID, 0 },
  1712.     { "read-only", LBL_RO,  0 },
  1713.     { "system",    LBL_SYS, 0 }
  1714. };
  1715. int nlblp = (sizeof(lbltab) / sizeof(struct keytab));
  1716. #endif /* OS2 */
  1717. #endif /* VMS */
  1718.  
  1719. #ifdef CK_CURSES
  1720. #ifdef CK_PCT_BAR
  1721. static struct keytab fdftab[] = {       /* SET FILE DISPLAY FULL options */
  1722.     { "thermometer",    1, 0, },
  1723.     { "no-thermometer", 0, 0  }
  1724. };
  1725. extern int thermometer;
  1726. #endif /* CK_PCT_BAR */
  1727. #endif /* CK_CURSES */
  1728.  
  1729. static struct keytab fdtab[] = {        /* SET FILE DISPLAY options */
  1730. #ifdef MAC                              /* Macintosh */
  1731.     { "fullscreen", XYFD_R,      0 },   /* Full-screen but not curses */
  1732.     { "none",       XYFD_N,      0 },
  1733.     { "off",        XYFD_N, CM_INV },
  1734.     { "on",         XYFD_R, CM_INV },
  1735.     { "quiet",      XYFD_N, CM_INV },
  1736. #else                                   /* Not Mac */
  1737.     { "brief", XYFD_B, 0 },             /* Brief */
  1738.     { "crt", XYFD_S, 0 },               /* CRT display */
  1739. #ifdef CK_CURSES
  1740. #ifdef COMMENT
  1741.     { "curses",     XYFD_C,  CM_INV },  /* Full-screen, curses */
  1742. #endif /* COMMENT */
  1743.     { "fullscreen", XYFD_C,  0 },       /* Full-screen, whatever the method */
  1744. #endif /* CK_CURSES */
  1745.     { "none",   XYFD_N, 0      },       /* No display */
  1746.     { "off",    XYFD_N, CM_INV },       /* Ditto */
  1747.     { "on",     XYFD_R, CM_INV },       /* On = Serial */
  1748.     { "quiet",  XYFD_N, CM_INV },       /* No display */
  1749.     { "serial", XYFD_R, 0      },       /* Serial */
  1750. #endif /* MAC */
  1751.     { "", 0, 0 }
  1752. };
  1753. int nfdtab = (sizeof(fdtab) / sizeof(struct keytab)) - 1;
  1754.  
  1755. struct keytab rsrtab[] = {              /* For REMOTE SET RECEIVE */
  1756.     { "packet-length", XYLEN,  0 },
  1757.     { "timeout",       XYTIMO, 0 }
  1758. };
  1759. int nrsrtab = (sizeof(rsrtab) / sizeof(struct keytab));
  1760.  
  1761. /* Send/Receive Parameters */
  1762.  
  1763. struct keytab srtab[] = {
  1764.     { "backup", XYBUP, 0 },
  1765. #ifndef NOCSETS
  1766.     { "character-set-selection", XYCSET, 0 },
  1767. #endif /* NOCSETS */
  1768.     { "control-prefix", XYQCTL, 0 },
  1769. #ifdef CKXXCHAR
  1770.     { "double-character", XYDBL, 0 },
  1771. #endif /* CKXXCHAR */
  1772.     { "end-of-packet", XYEOL, 0 },
  1773. #ifdef PIPESEND
  1774.     { "filter", XYFLTR, 0 },
  1775. #endif /* PIPESEND */
  1776. #ifdef CKXXCHAR
  1777.     { "ignore-character", XYIGN, 0 },
  1778. #endif /* CKXXCHAR */
  1779.     { "i-packets", 993, 0 },
  1780.     { "move-to", XYMOVE, 0 },
  1781.     { "negotiation-string-max-length", XYINIL, CM_INV },
  1782.     { "packet-length", XYLEN, 0 },
  1783.     { "pad-character", XYPADC, 0 },
  1784.     { "padding", XYNPAD, 0 },
  1785.     { "pathnames", XYFPATH, 0 },
  1786.     { "pause", XYPAUS, 0 },
  1787.     { "quote", XYQCTL, CM_INV },        /* = CONTROL-PREFIX */
  1788.     { "rename-to", XYRENAME, 0 },
  1789.     { "start-of-packet", XYMARK, 0 },
  1790.     { "timeout", XYTIMO, 0 },
  1791. #ifdef VMS
  1792.     { "version-numbers", 887, 0 },      /* VMS version numbers */
  1793. #endif /* VMS */
  1794.     { "", 0, 0 }
  1795. };
  1796. int nsrtab = (sizeof(srtab) / sizeof(struct keytab)) - 1;
  1797.  
  1798. #ifdef UNICODE
  1799. #define UCS_BOM 1
  1800. #define UCS_BYT 2
  1801. static struct keytab ucstab[] = {
  1802.     { "bom",        UCS_BOM, 0 },
  1803.     { "byte-order", UCS_BYT, 0 },
  1804.     { "", 0, 0 }
  1805. };
  1806. int nucstab = (sizeof(ucstab) / sizeof(struct keytab)) - 1;
  1807.  
  1808. static struct keytab botab[] = {
  1809.     { "big-endian",    0, 0 },
  1810.     { "little-endian", 1, 0 }
  1811. };
  1812. static int nbotab = 2;
  1813. #endif /* UNICODE */
  1814.  
  1815. /* REMOTE SET */
  1816.  
  1817. struct keytab rmstab[] = {
  1818.     { "attributes",  XYATTR, 0      },
  1819.     { "block-check", XYCHKT, 0      },
  1820.     { "file",        XYFILE, 0      },
  1821.     { "incomplete",  XYIFD,  CM_INV },  /* = REMOTE SET FILE INCOMPLETE */
  1822.     { "receive",     XYRECV, 0      },
  1823.     { "retry",       XYRETR, 0      },
  1824.     { "server",      XYSERV, 0      },
  1825.     { "transfer",    XYXFER, 0      },
  1826.     { "window",      XYWIND, 0      },
  1827.     { "xfer",        XYXFER, CM_INV }
  1828. };
  1829. int nrms = (sizeof(rmstab) / sizeof(struct keytab));
  1830.  
  1831. struct keytab attrtab[] = {
  1832. #ifdef STRATUS
  1833.     { "account",       AT_ACCT, 0 },
  1834. #endif /* STRATUS */
  1835.     { "all",           AT_XALL, 0 },
  1836. #ifdef COMMENT
  1837.     { "blocksize",     AT_BLKS, 0 },    /* (not used) */
  1838. #endif /* COMMENT */
  1839. #ifndef NOCSETS
  1840.     { "character-set", AT_ENCO, 0 },
  1841. #endif /* NOCSETS */
  1842. #ifdef STRATUS
  1843.     { "creator",       AT_CREA, 0 },
  1844. #endif /* STRATUS */
  1845.     { "date",          AT_DATE, 0 },
  1846.     { "disposition",   AT_DISP, 0 },
  1847.     { "encoding",      AT_ENCO, CM_INV },
  1848.     { "format",        AT_RECF, CM_INV },
  1849.     { "length",        AT_LENK, 0 },
  1850.     { "off",           AT_ALLN, 0 },
  1851.     { "on",            AT_ALLY, 0 },
  1852. #ifdef COMMENT
  1853.     { "os-specific",   AT_SYSP, 0 },    /* (not used by UNIX or VMS) */
  1854. #endif /* COMMENT */
  1855. #ifdef CK_PERMS
  1856.     { "protection",    AT_LPRO, 0 },
  1857.     { "permissions",   AT_LPRO, CM_INV },
  1858. #endif /* CK_PERMS */
  1859.     { "record-format", AT_RECF, 0 },
  1860.     { "system-id",     AT_SYSI, 0 },
  1861.     { "type",          AT_FTYP, 0 }
  1862. };
  1863. int natr = (sizeof(attrtab) / sizeof(struct keytab)); /* how many attributes */
  1864.  
  1865. #ifdef CKTIDLE
  1866. struct keytab idlacts[] = {
  1867.     { "exit",       IDLE_EXIT, 0 },
  1868.     { "hangup",     IDLE_HANG, 0 },
  1869.     { "output",     IDLE_OUT,  0 },
  1870.     { "return",     IDLE_RET,  0 },
  1871. #ifdef TNCODE
  1872.     { "telnet-nop", IDLE_TNOP, 0 },
  1873.     { "telnet-ayt", IDLE_TAYT, 0 },
  1874. #endif /* TNCODE */
  1875.     { "", 0, 0 }
  1876. };
  1877. int nidlacts = (sizeof(idlacts) / sizeof(struct keytab)) - 1;
  1878. #endif /* CKTIDLE */
  1879.  
  1880. #ifndef NOSPL
  1881. extern int indef, inecho, insilence, inbufsize, inautodl, inintr;
  1882. extern char * inpbuf, * inpbp;
  1883. #ifdef OS2
  1884. extern int interm;
  1885. #endif /* OS2 */
  1886. struct keytab inptab[] = {              /* SET INPUT parameters */
  1887. #ifdef CK_AUTODL
  1888.     { "autodownload",    IN_ADL, 0 },
  1889. #endif /* CK_AUTODL */
  1890.     { "buffer-length",   IN_BUF, 0 },
  1891.     { "cancellation",    IN_CAN, 0 },
  1892.     { "case",            IN_CAS, 0 },
  1893.     { "default-timeout", IN_DEF, CM_INV }, /* There is no default timeout */
  1894.     { "echo",            IN_ECH, 0 },
  1895. #ifdef OS2
  1896.     { "pacing",          IN_PAC, CM_INV },
  1897. #endif /* OS2 */
  1898.     { "silence",         IN_SIL, 0 },
  1899. #ifdef OS2
  1900.     { "terminal",        IN_TRM, 0 },
  1901. #endif /* OS2 */
  1902.     { "timeout-action",  IN_TIM, 0 }
  1903. };
  1904. int ninp = (sizeof(inptab) / sizeof(struct keytab));
  1905.  
  1906. struct keytab intimt[] = {              /* SET INPUT TIMEOUT parameters */
  1907.     { "proceed", 0, 0 },                /* 0 = proceed */
  1908.     { "quit",    1, 0 }                 /* 1 = quit */
  1909. };
  1910.  
  1911. struct keytab incast[] = {              /* SET INPUT CASE parameters */
  1912.     { "ignore",  0, 0 },                /* 0 = ignore */
  1913.     { "observe", 1, 0 }                 /* 1 = observe */
  1914. };
  1915. #endif /* NOSPL */
  1916.  
  1917. struct keytab nabltab[] = {             /* For any command that needs */
  1918.     { "disabled", 0, 0 },
  1919.     { "enabled",  1, 0 },
  1920.     { "off",      0, CM_INV },          /* these keywords... */
  1921.     { "on",       1, CM_INV }
  1922. };
  1923. int nnabltab = sizeof(nabltab) / sizeof(struct keytab);
  1924.  
  1925. #ifdef OS2
  1926. struct keytab tvctab[] = {              /* SET TERM VIDEO-CHANGE */
  1927.     { "disabled",     TVC_DIS, 0 },
  1928.     { "enabled",      TVC_ENA, 0 },
  1929. #ifdef NT
  1930.     { "win95-safe",   TVC_W95, 0 },
  1931. #endif /* NT */
  1932.     { "", 0, 0 }
  1933. };
  1934. int ntvctab = (sizeof(tvctab) / sizeof(struct keytab)) - 1;
  1935.  
  1936. struct keytab msktab[] = { /* SET MS-DOS KERMIT compatibilities */
  1937. #ifdef COMMENT
  1938.     { "color",    MSK_COLOR,  0 },
  1939. #endif /* COMMENT */
  1940.     { "keycodes", MSK_KEYS,   0 }
  1941. };
  1942. int nmsk = (sizeof(msktab) / sizeof(struct keytab));
  1943.  
  1944. struct keytab scrnupd[] = {             /* SET TERMINAL SCREEN-UPDATE */
  1945.     { "fast",   TTU_FAST,   0 },
  1946.     { "smooth", TTU_SMOOTH, 0 }
  1947. };
  1948. int nscrnupd = (sizeof(scrnupd) / sizeof(struct keytab));
  1949.  
  1950. #ifdef PCFONTS
  1951. /* This definition of the term_font[] table is only for     */
  1952. /* the OS/2 Full Screen Session and is not used on Windows */
  1953. struct keytab term_font[] = {           /* SET TERMINAL FONT */
  1954. #ifdef COMMENT
  1955.     { "cp111", TTF_111, 0 },
  1956.     { "cp112", TTF_112, 0 },
  1957.     { "cp113", TTF_113, 0 },
  1958. #endif /* COMMENT */
  1959.     { "cp437", TTF_437, 0 },
  1960.     { "cp850", TTF_850, 0 },
  1961. #ifdef COMMENT
  1962.     { "cp851", TTF_851, 0 },
  1963. #endif /* COMMENT */
  1964.     { "cp852", TTF_852, 0 },
  1965. #ifdef COMMENT
  1966.     { "cp853", TTF_853, 0 },
  1967.     { "cp860", TTF_860, 0 },
  1968.     { "cp861", TTF_861, 0 },
  1969. #endif /* COMMENT */
  1970.     { "cp862", TTF_862, 0 },
  1971. #ifdef COMMENT
  1972.     { "cp863", TTF_863, 0 },
  1973.     { "cp864", TTF_864, 0 },
  1974.     { "cp865", TTF_865, 0 },
  1975. #endif /* COMMENT */
  1976.     { "cp866", TTF_866, 0 },
  1977. #ifdef COMMENT
  1978.     { "cp880", TTF_880, 0 },
  1979.     { "cp881", TTF_881, 0 },
  1980.     { "cp882", TTF_882, 0 },
  1981.     { "cp883", TTF_883, 0 },
  1982.     { "cp884", TTF_884, 0 },
  1983.     { "cp885", TTF_885, 0 },
  1984. #endif /* COMMENT */
  1985.     { "default",TTF_ROM,0 }
  1986. };
  1987. int ntermfont = (sizeof(term_font) / sizeof(struct keytab));
  1988. int tt_font = TTF_ROM;                  /* Terminal screen font */
  1989. #else /* PCFONTS */
  1990. #ifdef NT
  1991. #ifdef KUI
  1992. struct keytab * term_font = NULL;
  1993. struct keytab * _term_font = NULL;
  1994. char * tt_facename = NULL;
  1995. int ntermfont = 0;
  1996. int tt_font = 0;
  1997. int tt_font_size = 0;
  1998. #endif /* KUI */
  1999. #endif /* NT */
  2000. #endif /* PCFONTS */
  2001.  
  2002. struct keytab anbktab[] = {             /* For any command that needs */
  2003.     { "message", 2, 0 },                /* these keywords... */
  2004.     { "off",     0, 0 },
  2005.     { "on",      1, 0 },
  2006.     { "unsafe-messag0", 99, CM_INV },
  2007.     { "unsafe-message", 3,  CM_INV }
  2008. };
  2009. int nansbk = (sizeof(anbktab) / sizeof(struct keytab));
  2010.  
  2011. int win95_popup = 1;
  2012. #ifdef NT
  2013. int win95altgr  = 0;
  2014. #ifdef KUI
  2015. int win95lucida = 0;
  2016. #else /* KUI */
  2017. int win95lucida = 1;
  2018. #endif /* KUI */
  2019. extern int win95selectbug;
  2020. extern int win95_8_3;
  2021.  
  2022. #ifdef COMMENT
  2023. extern CHAR (*xlr[MAXTCSETS+1][MAXFCSETS+1])(CHAR);
  2024. extern struct keytab tcstab[];
  2025. extern int ntcs;
  2026. #endif /* COMMENT */
  2027. extern int maxow, maxow_usr; owwait;    /* Overlapped I/O variables */
  2028. #endif /* NT */
  2029. #endif /* OS2 */
  2030.  
  2031.  
  2032. /* The following routines broken out of doprm() to give compilers a break. */
  2033.  
  2034. /*  S E T O N  --  Parse on/off (default on), set parameter to result  */
  2035.  
  2036. int
  2037. seton(prm) int *prm; {
  2038.     int x, y;
  2039.     if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  2040.     if ((x = cmcfm()) < 0) return(x);
  2041.     *prm = y;
  2042.     return(1);
  2043. }
  2044.  
  2045. /*  S E T O N A U T O --  Parse on/off/auto (default auto) & set result */
  2046.  
  2047. struct keytab onoffaut[] = {
  2048.     { "auto", SET_AUTO, 0 },            /* 2 */
  2049.     { "off",  SET_OFF,  0 },            /* 0 */
  2050.     { "on",   SET_ON,   0 }             /* 1 */
  2051. };
  2052.  
  2053. int
  2054. setonaut(prm) int *prm; {
  2055.     int x, y;
  2056.     if ((y = cmkey(onoffaut,3,"","auto",xxstring)) < 0) return(y);
  2057.     if ((x = cmcfm()) < 0) return(x);
  2058.     *prm = y;
  2059.     return(1);
  2060. }
  2061.  
  2062. /*  S E T N U M  --  Set parameter to result of cmnum() parse.  */
  2063. /*
  2064.  Call with pointer to integer variable to be set,
  2065.    x = number from cnum parse, y = return code from cmnum,
  2066.    max = maximum value to accept, -1 if no maximum.
  2067.  Returns -9 on failure, after printing a message, or 1 on success.
  2068. */
  2069. int
  2070. setnum(prm,x,y,max) int x, y, *prm, max; {
  2071.     debug(F101,"setnum","",y);
  2072.     if (y == -3) {
  2073.         printf("\n?Value required\n");
  2074.         return(-9);
  2075.     }
  2076.     if (y == -2) {
  2077.         printf("%s?Not a number: %s\n",cmflgs == 1 ? "" : "\n", atxbuf);
  2078.         return(-9);
  2079.     }
  2080.     if (y < 0) return(y);
  2081.     if (max > -1 && x > max) {
  2082.         printf("?Sorry, %d is the maximum\n",max);
  2083.         return(-9);
  2084.     }
  2085.     if ((y = cmcfm()) < 0) return(y);
  2086.     *prm = x;
  2087.     return(1);
  2088. }
  2089.  
  2090. /*  S E T C C  --  Set parameter var to an ASCII control character value.  */
  2091. /*
  2092.   Parses a number, or a literal control character, or a caret (^) followed
  2093.   by an ASCII character whose value is 63-95 or 97-122, then gets confirmation,
  2094.   then sets the parameter to the code value of the character given.  If there
  2095.   are any parse errors, they are returned, otherwise on success 1 is returned.
  2096. */
  2097. int
  2098. setcc(dflt,var) char *dflt; int *var; {
  2099.     int x, y;
  2100.     unsigned int c;
  2101.     char *hlpmsg = "Control character,\n\
  2102.  numeric ASCII value,\n\
  2103.  or in ^X notation,\n\
  2104.  or preceded by a backslash and entered literally";
  2105.  
  2106.     /* This is a hack to turn off complaints from expression evaluator. */
  2107.     x_ifnum = 1;
  2108.     y = cmnum(hlpmsg, dflt, 10, &x, xxstring); /* Parse a number */
  2109.     x_ifnum = 0;                               /* Allow complaints again */
  2110.     if (y < 0) {                        /* Parse failed */
  2111.         if (y != -2)                    /* Reparse needed or somesuch */
  2112.           return(y);                    /* Pass failure back up the chain */
  2113.     }
  2114.     /* Real control character or literal 8-bit character... */
  2115.  
  2116.     for (c = strlen(atmbuf) - 1; c > 0; c--) /* Trim */
  2117.       if (atmbuf[c] == SP) atmbuf[c] = NUL;
  2118.  
  2119.     if (y < 0) {                        /* It was not a number */
  2120.         if (((c = atmbuf[0])) && !atmbuf[1]) { /* Literal character? */
  2121.             c &= 0xff;
  2122.             if (((c > 31) && (c < 127)) || (c > 255)) {
  2123.                 printf("\n?%d: Out of range - must be 0-31 or 127-255\n",c);
  2124.                 return(-9);
  2125.             } else {
  2126.                 if ((y = cmcfm()) < 0)  /* Confirm */
  2127.                   return(y);
  2128.                 *var = c;               /* Set the variable */
  2129.                 return(1);
  2130.             }
  2131.         } else if (atmbuf[0] == '^' && !atmbuf[2]) { /* Or ^X notation? */
  2132.             c = atmbuf[1];
  2133.             if (islower((char) c))      /* Uppercase lowercase letters */
  2134.               c = toupper(c);
  2135.             if (c > 62 && c < 96) {     /* Check range */
  2136.                 if ((y = cmcfm()) < 0)
  2137.                   return(y);
  2138.                 *var = ctl(c);          /* OK */
  2139.                 return(1);
  2140.             } else {
  2141.                 printf("?Not a control character - %s\n", atmbuf);
  2142.                 return(-9);
  2143.             }
  2144.         } else {                        /* Something illegal was typed */
  2145.             printf("?Invalid - %s\n", atmbuf);
  2146.             return(-9);
  2147.         }
  2148.     }
  2149.     if (((x > 31) && (x < 127)) || (x > 255)) { /* They typed a number */
  2150.         printf("\n?%d: Out of range - must be 0-31 or 127-255\n",x);
  2151.         return(-9);
  2152.     }
  2153.     if ((y = cmcfm()) < 0)              /* In range, confirm */
  2154.       return(y);
  2155.     *var = x;                           /* Set variable */
  2156.     return(1);
  2157. }
  2158.  
  2159. #ifndef NOSPL                           /* The SORT command... */
  2160.  
  2161. static struct keytab srtswtab[] = {     /* SORT command switches */
  2162.     { "/case",    SRT_CAS, CM_ARG },
  2163.     { "/key",     SRT_KEY, CM_ARG },
  2164.     { "/numeric", SRT_NUM, 0 },
  2165.     { "/range",   SRT_RNG, CM_ARG },
  2166.     { "/reverse", SRT_REV, 0 }
  2167. };
  2168. static int nsrtswtab = sizeof(srtswtab)/sizeof(struct keytab);
  2169.  
  2170. extern char **a_ptr[];                  /* Array pointers */
  2171. extern int a_dim[];                     /* Array dimensions */
  2172.  
  2173. int
  2174. dosort() {                              /* Do the SORT command */
  2175.     char c, *p = NULL, ** ap, ** xp = NULL;
  2176.     struct FDB sw, fl, cm;
  2177.     int hi, lo;
  2178.     int xn = 0, xr = -1, xk = -1, xc = -1, xs = 0;
  2179.     int getval = 0, range[2], confirmed = 0;
  2180.  
  2181.     cmfdbi(&sw,                         /* First FDB - command switches */
  2182.            _CMKEY,                      /* fcode */
  2183.            "Array name or switch",
  2184.            "",                          /* default */
  2185.            "",                          /* addtl string data */
  2186.            nsrtswtab,                   /* addtl numeric data 1: tbl size */
  2187.            4,                           /* addtl numeric data 2: 4 = cmswi */
  2188.            NULL,                        /* Processing function */
  2189.            srtswtab,                    /* Keyword table */
  2190.            &fl                          /* Pointer to next FDB */
  2191.            );
  2192.     cmfdbi(&fl,                         /* Anything that doesn't match */
  2193.            _CMFLD,                      /* fcode */
  2194.            "Array name",                /* hlpmsg */
  2195.            "",                          /* default */
  2196.            "",                          /* addtl string data */
  2197.            0,                           /* addtl numeric data 1 */
  2198.            0,                           /* addtl numeric data 2 */
  2199.            NULL,
  2200.            NULL,
  2201.            &cm
  2202.            );
  2203.     cmfdbi(&cm,                         /* Or premature confirmation */
  2204.            _CMCFM,                      /* fcode */
  2205.            "",                          /* hlpmsg */
  2206.            "",                          /* default */
  2207.            "",                          /* addtl string data */
  2208.            0,                           /* addtl numeric data 1 */
  2209.            0,                           /* addtl numeric data 2 */
  2210.            NULL,
  2211.            NULL,
  2212.            NULL
  2213.            );
  2214.  
  2215.     range[0] = -1;
  2216.     range[1] = -1;
  2217.  
  2218.     while (1) {                         /* Parse 0 or more switches */
  2219.         x = cmfdb(&sw);
  2220.         if (x < 0)
  2221.           return(x);
  2222.         if (cmresult.fcode != _CMKEY)   /* Break out if not a switch */
  2223.           break;
  2224.         c = cmgbrk();
  2225.         getval = (c == ':' || c == '=');
  2226.         if (getval && !(cmresult.kflags & CM_ARG)) {
  2227.             printf("?This switch does not take arguments\n");
  2228.             return(-9);
  2229.         }
  2230.         switch (cmresult.nresult) {
  2231.           case SRT_REV:
  2232.             xr = 1;
  2233.             break;
  2234.           case SRT_KEY:
  2235.             if (getval) {
  2236.                 if ((y = cmnum("Column for comparison (1-based)",
  2237.                                "1",10,&x,xxstring)) < 0)
  2238.                   return(y);
  2239.                 xk = x - 1;
  2240.             } else
  2241.               xk = 0;
  2242.             break;
  2243.           case SRT_CAS:
  2244.             if (getval) {
  2245.                 if ((y = cmkey(onoff,2,"","on",xxstring)) < 0)
  2246.                   return(y);
  2247.                 xc = y;
  2248.             } else
  2249.               xc = 1;
  2250.             break;
  2251.           case SRT_RNG:                 /* /RANGE */
  2252.             if (getval) {
  2253.                 char buf[32];
  2254.                 char buf2[16];
  2255.                 int i;
  2256.                 char * p, * q;
  2257.                 if ((y = cmfld("low:high element","1",&s,NULL)) < 0)
  2258.                   return(y);
  2259.                 s = brstrip(s);
  2260.                 ckstrncpy(buf,s,32);
  2261.                 p = buf;
  2262.                 for (i = 0; *p && i < 2; i++) { /* Get low and high */
  2263.                     q = p;              /* Start of this piece */
  2264.                     while (*p) {        /* Find end of this piece */
  2265.                         if (*p == ':') {
  2266.                             *p = NUL;
  2267.                             p++;
  2268.                             break;
  2269.                         }
  2270.                         p++;
  2271.                     }
  2272.                     y = 15;             /* Evaluate this piece */
  2273.                     s = buf2;
  2274.                     zzstring(q,&s,&y);
  2275.                     s = evalx(buf2);
  2276.                     if (s) if (*s) ckstrncpy(buf2,s,16);
  2277.                     if (!rdigits(buf2)) {
  2278.                         printf("?Not numeric: %s\n",buf2);
  2279.                         return(-9);
  2280.                     }
  2281.                     range[i] = atoi(buf2);
  2282.                 }
  2283.             }
  2284.             break;
  2285.           case SRT_NUM:                 /* /NUMERIC */
  2286.             xn = 1;
  2287.             break;
  2288.           default:
  2289.             return(-2);
  2290.         }
  2291.     }
  2292.     switch (cmresult.fcode) {
  2293.       case _CMCFM:
  2294.         confirmed = 1;
  2295.         break;
  2296.       case _CMFLD:
  2297.         ckstrncpy(line,cmresult.sresult,LINBUFSIZ); /* Safe copy of name */
  2298.         s = line;
  2299.         break;
  2300.       default:
  2301.         printf("?Unexpected function code: %d\n",cmresult.fcode);
  2302.         return(-9);
  2303.     }
  2304.     if (confirmed) {
  2305.         printf("?Array name required\n");
  2306.         return(-9);
  2307.     }
  2308.     ckmakmsg(tmpbuf,TMPBUFSIZ,
  2309.              "Second array to sort according to ",s,NULL,NULL);
  2310.     if ((x = cmfld(tmpbuf,"",&p,NULL)) < 0)
  2311.       if (x != -3)
  2312.         return(x);
  2313.     tmpbuf[0] = NUL;
  2314.     ckstrncpy(tmpbuf,p,TMPBUFSIZ);
  2315.     p = tmpbuf;
  2316.     if ((x = cmcfm()) < 0)              /* Get confirmation */
  2317.       return(x);
  2318.  
  2319.     x = arraybounds(s,&lo,&hi);         /* Get array index & bounds */
  2320.     if (x < 0) {                        /* Check */
  2321.         printf("?Bad array name: %s\n",s);
  2322.         return(-9);
  2323.     }
  2324.     if (lo > -1) range[0] = lo;         /* Set range */
  2325.     if (hi > -1) range[1] = hi;
  2326.     ap = a_ptr[x];                      /* Get pointer to array element list */
  2327.     if (!ap) {                          /* Check */
  2328.         printf("?Array not declared: %s\n", s);
  2329.         return(-9);
  2330.     }
  2331.     if (range[0] < 0)                   /* Starting element */
  2332.       range[0] = 1;
  2333.     if (range[1] < 0)                   /* Final element */
  2334.       range[1] = a_dim[x];
  2335.     if (range[1] > a_dim[x]) {
  2336.         printf("?range %d:%d exceeds array dimension %d\n",
  2337.                range[0],range[1],a_dim[x]
  2338.                );
  2339.         return(-9);
  2340.     }
  2341.     ap += range[0];
  2342.     xs = range[1] - range[0] + 1;       /* Number of elements to sort */
  2343.     if (xs < 1) {                       /* Check */
  2344.         printf("?Bad range: %d:%d\n",range[0],range[1]);
  2345.         return(-9);
  2346.     }
  2347.     if (xk < 0) xk = 0;                 /* Key position */
  2348.     if (xr < 0) xr = 0;                 /* Reverse flag */
  2349.     if (xn)                             /* Numeric flag */
  2350.       xc = 2;
  2351.     else if (xc < 0)                    /* Not numeric */
  2352.       xc = inpcas[cmdlvl];              /* so alpha case option */
  2353.  
  2354.     if (*p) {                           /* Parallel array given? */
  2355.         y = xarray(p);                  /* Yes, get its index. */
  2356.         if (y < 0) {
  2357.             printf("?Bad array name: %s\n", p);
  2358.             return(-9);
  2359.         }
  2360.         if (y != x) {                   /* If the 2 arrays are different  */
  2361.             xp = a_ptr[y];              /* Pointer to 2nd array element list */
  2362.             if (!xp) {
  2363.                 printf("?Array not declared: %s\n", p);
  2364.                 return(-9);
  2365.             }
  2366.             if (a_dim[y] < range[1]) {
  2367.                 printf("?Array %s smaller than %s\n", p, s);
  2368.                 return(-9);
  2369.             }
  2370.             xp += range[0];             /* Set base to same as 1st array */
  2371.         }
  2372.     }
  2373.     sh_sort(ap,xp,xs,xk,xr,xc);         /* Sort the array(s) */
  2374.     return(success = 1);                /* Always succeeds */
  2375. }
  2376. #endif /* NOSPL */
  2377.  
  2378. static struct keytab purgtab[] = {      /* PURGE command switches */
  2379.     { "/after",        PU_AFT,  CM_ARG },
  2380.     { "/ask",          PU_ASK,  0 },
  2381.     { "/before",       PU_BEF,  CM_ARG },
  2382.     { "/delete",       PU_DELE, CM_INV },
  2383. #ifdef UNIXOROSK
  2384.     { "/dotfiles",     PU_DOT,  0 },
  2385. #endif /* UNIXOROSK */
  2386.     { "/except",       PU_EXC,  CM_ARG },
  2387.     { "/heading",      PU_HDG,  0 },
  2388.     { "/keep",         PU_KEEP, CM_ARG },
  2389.     { "/larger-than",  PU_LAR,  CM_ARG },
  2390.     { "/list",         PU_LIST, 0 },
  2391.     { "/log",          PU_LIST, CM_INV },
  2392.     { "/noask",        PU_NASK, 0 },
  2393.     { "/nodelete",     PU_NODE, CM_INV },
  2394. #ifdef UNIXOROSK
  2395.     { "/nodotfiles",   PU_NODOT,0 },
  2396. #endif /* UNIXOROSK */
  2397.     { "/noheading",    PU_NOH,  0 },
  2398.     { "/nol",          PU_NOLI, CM_INV|CM_ABR },
  2399.     { "/nolist",       PU_NOLI, 0 },
  2400.     { "/nolog",        PU_NOLI, CM_INV },
  2401. #ifdef CK_TTGWSIZ
  2402.     { "/nopage",       PU_NOPA, 0 },
  2403. #endif /* CK_TTGWSIZ */
  2404.     { "/not-after",    PU_NAF,  CM_ARG },
  2405.     { "/not-before",   PU_NBF,  CM_ARG },
  2406.     { "/not-since",    PU_NAF,  CM_INV|CM_ARG },
  2407. #ifdef CK_TTGWSIZ
  2408.     { "/page",         PU_PAGE, 0 },
  2409. #endif /* CK_TTGWSIZ */
  2410.     { "/quiet",        PU_QUIE, CM_INV },
  2411. #ifdef RECURSIVE
  2412.     { "/recursive",    PU_RECU, 0 },
  2413. #endif /* RECURSIVE */
  2414.     { "/since",        PU_AFT,  CM_ARG|CM_INV },
  2415.     { "/simulate",     PU_NODE, 0 },
  2416.     { "/smaller-than", PU_SMA,  CM_ARG },
  2417.     { "/verbose",      PU_VERB, CM_INV }
  2418. };
  2419. static int npurgtab = sizeof(purgtab)/sizeof(struct keytab);
  2420.  
  2421.  
  2422.  
  2423.  
  2424.  
  2425. int
  2426. bkupnum(s,i) char * s; int *i; {
  2427.     int k = 0, pos = 0;
  2428.     char * p = NULL, *q;
  2429.     *i = pos;
  2430.     if (!s) s = "";
  2431.     if (!*s)
  2432.       return(-1);
  2433.     if ((k = strlen(s)) < 5)
  2434.       return(-1);
  2435.  
  2436.     if (s[k-1] != '~')
  2437.       return(-1);
  2438.     pos = k - 2;
  2439.     q = s + pos;
  2440.     while (q >= s && isdigit(*q)) {
  2441.         p = q--;
  2442.         pos--;
  2443.     }
  2444.     if (!p)
  2445.       return(-1);
  2446.     if (q < s+2)
  2447.       return(-1);
  2448.     if (*q != '~' || *(q-1) != '.')
  2449.       return(-1);
  2450.     pos--;
  2451.     *i = pos;
  2452.     debug(F111,"bkupnum",s+pos,pos);
  2453.     return(atoi(p));
  2454. }
  2455.  
  2456. #ifdef CKPURGE
  2457. /* Presently only for UNIX because we need direct access to the file array. */
  2458. /* Not needed for VMS anyway, because we don't make backup files there. */
  2459.  
  2460. #define MAXKEEP 32                      /* Biggest /KEEP: value */
  2461.  
  2462. static int
  2463.   pu_keep = 0, pu_list = 0, pu_dot = 0, pu_ask = 0, pu_hdg = 0;
  2464.  
  2465. #ifdef CK_TTGWSIZ
  2466. static int pu_page = -1;
  2467. #else
  2468. static int pu_page = 0;
  2469. #endif /* CK_TTGWSIZ */
  2470.  
  2471. #ifndef NOSHOW
  2472. VOID
  2473. showpurgopts() {                        /* SHOW PURGE command options */
  2474.     int x = 0;
  2475.     extern int optlines;
  2476.     prtopt(&optlines,"PURGE");
  2477.     if (pu_ask > -1) {
  2478.         x++;
  2479.         prtopt(&optlines, pu_ask ? "/ASK" : "/NOASK");
  2480.     }
  2481. #ifdef UNIXOROSK
  2482.     if (pu_dot > -1) {
  2483.         x++;
  2484.         prtopt(&optlines, pu_dot ? "/DOTFILES" : "/NODOTFILES");
  2485.     }
  2486. #endif /* UNIXOROSK */
  2487.     if (pu_keep > -1) {
  2488.         x++;
  2489.         ckmakmsg(tmpbuf,TMPBUFSIZ,"/KEEP:",ckitoa(pu_keep),NULL,NULL);
  2490.         prtopt(&optlines,tmpbuf);
  2491.     }
  2492.     if (pu_list > -1) {
  2493.         x++;
  2494.         prtopt(&optlines, pu_list ? "/LIST" : "/NOLIST");
  2495.     }
  2496.     if (pu_hdg > -1) {
  2497.         x++;
  2498.         prtopt(&optlines, pu_hdg ? "/HEADING" : "/NOHEADING");
  2499.     }
  2500. #ifdef CK_TTGWSIZ
  2501.     if (pu_page > -1) {
  2502.         x++;
  2503.         prtopt(&optlines, pu_page ? "/PAGE" : "/NOPAGE");
  2504.     }
  2505. #endif /* CK_TTGWSIZ */
  2506.     if (!x) prtopt(&optlines,"(no options set)");
  2507.     prtopt(&optlines,"");
  2508. }
  2509. #endif /* NOSHOW */
  2510.  
  2511. int
  2512. setpurgopts() {                         /* Set PURGE command options */
  2513.     int c, z, getval = 0;
  2514.     int
  2515.       x_keep  = -1, x_list = -1, x_page = -1,
  2516.       x_hdg   = -1, x_ask  = -1, x_dot  = -1;
  2517.  
  2518.     while (1) {
  2519.         if ((y = cmswi(purgtab,npurgtab,"Switch","",xxstring)) < 0) {
  2520.             if (y == -3)
  2521.               break;
  2522.             else
  2523.               return(y);
  2524.         }
  2525.         c = cmgbrk();
  2526.         if ((getval = (c == ':' || c == '=')) && !(cmgkwflgs() & CM_ARG)) {
  2527.             printf("?This switch does not take an argument\n");
  2528.             return(-9);
  2529.         }
  2530.         if (!getval && (cmgkwflgs() & CM_ARG)) {
  2531.             printf("?This switch requires an argument\n");
  2532.             return(-9);
  2533.         }
  2534.         switch (y) {
  2535.           case PU_KEEP:
  2536.             z = 1;
  2537.             if (c == ':' || c == '=')
  2538.               if ((y = cmnum("How many backup files to keep",
  2539.                              "1",10,&z,xxstring)) < 0)
  2540.                 return(y);
  2541.             if (z < 0 || z > MAXKEEP) {
  2542.                 printf("?Please specify a number between 0 and %d\n",
  2543.                        MAXKEEP
  2544.                        );
  2545.                 return(-9);
  2546.             }
  2547.             x_keep = z;
  2548.             break;
  2549.           case PU_LIST:
  2550.           case PU_VERB:
  2551.             x_list = 1;
  2552.             break;
  2553.           case PU_QUIE:
  2554.           case PU_NOLI:
  2555.             x_list = 0;
  2556.             break;
  2557. #ifdef CK_TTGWSIZ
  2558.           case PU_PAGE:
  2559.             x_page = 1;
  2560.             break;
  2561.           case PU_NOPA:
  2562.             x_page = 0;
  2563.             break;
  2564. #endif /* CK_TTGWSIZ */
  2565.           case PU_HDG:
  2566.             x_hdg = 1;
  2567.             break;
  2568.           case PU_NOH:
  2569.             x_hdg = 0;
  2570.             break;
  2571.           case PU_ASK:
  2572.             x_ask = 1;
  2573.             break;
  2574.           case PU_NASK:
  2575.             x_ask = 0;
  2576.             break;
  2577. #ifdef UNIXOROSK
  2578.           case PU_DOT:
  2579.             x_dot = 1;
  2580.             break;
  2581.           case PU_NODOT:
  2582.             x_dot = 0;
  2583.             break;
  2584. #endif /* UNIXOROSK */
  2585.           default:
  2586.             printf("?This option can not be set\n");
  2587.             return(-9);
  2588.         }
  2589.     }
  2590.     if ((x = cmcfm()) < 0)              /* Get confirmation */
  2591.       return(x);
  2592.     if (x_keep > -1)                    /* Set PURGE defaults. */
  2593.       pu_keep = x_keep;
  2594.     if (x_list > -1)
  2595.       pu_list = x_list;
  2596. #ifdef CK_TTGWSIZ
  2597.     if (x_page > -1)
  2598.       pu_page = x_page;
  2599. #endif /* CK_TTGWSIZ */
  2600.     if (x_hdg > -1)
  2601.       pu_hdg = x_hdg;
  2602.     if (x_ask > -1)
  2603.       pu_ask = x_ask;
  2604.     if (x_dot > -1)
  2605.       pu_dot = x_dot;
  2606.     return(success = 1);
  2607. }
  2608.  
  2609. int
  2610. dopurge() {                             /* Do the PURGE command */
  2611.     extern char ** mtchs;
  2612.     extern int xaskmore, cmd_rows, recursive;
  2613.     int simulate = 0, asking = 0;
  2614.     int listing = 0, paging = -1, lines = 0, deleting = 1, errors = 0;
  2615.     struct FDB sw, sf, cm;
  2616.     int g, i, j, k, m = 0, n, x, y, z, done = 0, count = 0, flags = 0;
  2617.     int tokeep = 0, getval = 0, havename = 0, confirmed = 0;
  2618.     int xx[MAXKEEP+1];                  /* Array of numbers to keep */
  2619.     int min = -1;
  2620.     int x_hdg = 0, fs = 0, rc = 0;
  2621.     long minsize = -1L, maxsize = -1L;
  2622.     char namebuf[CKMAXPATH+4];
  2623.     char basebuf[CKMAXPATH+4];
  2624.     char
  2625.       * pu_aft = NULL,
  2626.       * pu_bef = NULL,
  2627.       * pu_naf = NULL,
  2628.       * pu_nbf = NULL,
  2629.       * pu_exc = NULL;
  2630.     char * pxlist[8];                   /* Exception list */
  2631.  
  2632.     if (pu_keep > -1)                   /* Set PURGE defaults. */
  2633.       tokeep = pu_keep;
  2634.     if (pu_list > -1)
  2635.       listing = pu_list;
  2636. #ifdef CK_TTGWSIZ
  2637.     if (pu_page > -1)
  2638.       paging = pu_page;
  2639. #endif /* CK_TTGWSIZ */
  2640.  
  2641.     for (i = 0; i <= MAXKEEP; i++)      /* Clear this number buffer */
  2642.       xx[i] = 0;
  2643.     for (i = 0; i < 8; i++)             /* Initialize these... */
  2644.       pxlist[i] = NULL;
  2645.  
  2646.     g_matchdot = matchdot;              /* Save these... */
  2647.  
  2648.     cmfdbi(&sw,                         /* 1st FDB - PURGE switches */
  2649.            _CMKEY,                      /* fcode */
  2650.            "Filename or switch",        /* hlpmsg */
  2651.            "",                          /* default */
  2652.            "",                          /* addtl string data */
  2653.            npurgtab,                    /* addtl numeric data 1: tbl size */
  2654.            4,                           /* addtl numeric data 2: 4 = cmswi */
  2655.            xxstring,                    /* Processing function */
  2656.            purgtab,                     /* Keyword table */
  2657.            &sf                          /* Pointer to next FDB */
  2658.            );
  2659.     cmfdbi(&sf,                         /* 2nd FDB - filespec to purge */
  2660.            _CMIFI,                      /* fcode */
  2661.            "",
  2662.            "",                          /* default */
  2663.            "",                          /* addtl string data */
  2664.            0,                           /* addtl numeric data 1 */
  2665.            0,                           /* addtl numeric data 2 */
  2666.            xxstring,
  2667.            NULL,
  2668.            &cm
  2669.            );
  2670.     cmfdbi(&cm,                         /* Or premature confirmation */
  2671.            _CMCFM,                      /* fcode */
  2672.            "",                          /* hlpmsg */
  2673.            "",                          /* default */
  2674.            "",                          /* addtl string data */
  2675.            0,                           /* addtl numeric data 1 */
  2676.            0,                           /* addtl numeric data 2 */
  2677.            NULL,
  2678.            NULL,
  2679.            NULL
  2680.            );
  2681.  
  2682.     while (!havename && !confirmed) {
  2683.         x = cmfdb(&sw);                 /* Parse something */
  2684.         if (x < 0) {                    /* Error */
  2685.             rc = x;
  2686.             goto xpurge;
  2687.         } else if (cmresult.fcode == _CMKEY) {
  2688.             char c;
  2689.             c = cmgbrk();
  2690.             if ((getval = (c == ':' || c == '=')) && !(cmgkwflgs() & CM_ARG)) {
  2691.                 printf("?This switch does not take an argument\n");
  2692.                 rc = -9;
  2693.                 goto xpurge;
  2694.             }
  2695.             if (!getval && (cmgkwflgs() & CM_ARG)) {
  2696.                 printf("?This switch requires an argument\n");
  2697.                 rc = -9;
  2698.                 goto xpurge;
  2699.             }
  2700.             switch (k = cmresult.nresult) {
  2701.               case PU_KEEP:
  2702.                 z = 1;
  2703.                 if (c == ':' || c == '=') {
  2704.                     if ((y = cmnum("How many backup files to keep",
  2705.                                    "1",10,&z,xxstring)) < 0) {
  2706.                         rc = y;
  2707.                         goto xpurge;
  2708.                     }
  2709.                 }
  2710.                 if (z < 0 || z > MAXKEEP) {
  2711.                     printf("?Please specify a number between 0 and %d\n",
  2712.                            MAXKEEP
  2713.                            );
  2714.                     rc = -9;
  2715.                     goto xpurge;
  2716.                 }
  2717.                 tokeep = z;
  2718.                 break;
  2719.               case PU_LIST:
  2720.                 listing = 1;
  2721.                 break;
  2722.               case PU_NOLI:
  2723.                 listing = 0;
  2724.                 break;
  2725. #ifdef CK_TTGWSIZ
  2726.               case PU_PAGE:
  2727.                 paging = 1;
  2728.                 break;
  2729.               case PU_NOPA:
  2730.                 paging = 0;
  2731.                 break;
  2732. #endif /* CK_TTGWSIZ */
  2733.               case PU_DELE:
  2734.                 deleting = 1;
  2735.                 break;
  2736.               case PU_NODE:
  2737.                 deleting = 0;
  2738.                 simulate = 1;
  2739.                 listing = 1;
  2740.                 break;
  2741.               case PU_ASK:
  2742.                 asking = 1;
  2743.                 break;
  2744.               case PU_NASK:
  2745.                 asking = 0;
  2746.                 break;
  2747.               case PU_AFT:
  2748.               case PU_BEF:
  2749.               case PU_NAF:
  2750.               case PU_NBF:
  2751.                 if ((x = cmdate("File-time","",&s,0,xxstring)) < 0) {
  2752.                     if (x == -3) {
  2753.                         printf("?Date-time required\n");
  2754.                         rc = -9;
  2755.                     } else
  2756.                       rc = x;
  2757.                     goto xpurge;
  2758.                 }
  2759.                 fs++;
  2760.                 switch (k) {
  2761.                   case PU_AFT: makestr(&pu_aft,s); break;
  2762.                   case PU_BEF: makestr(&pu_bef,s); break;
  2763.                   case PU_NAF: makestr(&pu_naf,s); break;
  2764.                   case PU_NBF: makestr(&pu_nbf,s); break;
  2765.                 }
  2766.                 break;
  2767.               case PU_SMA:
  2768.               case PU_LAR:
  2769.                 if ((x = cmnum("File size in bytes","0",10,&y,xxstring)) < 0) {
  2770.                     rc = x;
  2771.                     goto xpurge;
  2772.                 }
  2773.                 fs++;
  2774.                 switch (cmresult.nresult) {
  2775.                   case PU_SMA: minsize = y; break;
  2776.                   case PU_LAR: maxsize = y; break;
  2777.                 }
  2778.                 break;
  2779.               case PU_DOT:
  2780.                 matchdot = 1;
  2781.                 break;
  2782.               case PU_NODOT:
  2783.                 matchdot = 0;
  2784.                 break;
  2785.               case PU_EXC:
  2786.                 if ((x = cmfld("Pattern","",&s,xxstring)) < 0) {
  2787.                     if (x == -3) {
  2788.                         printf("?Pattern required\n");
  2789.                         rc = -9;
  2790.                     } else
  2791.                       rc = x;
  2792.                     goto xpurge;
  2793.                 }
  2794.                 fs++;
  2795.                 makestr(&pu_exc,s);
  2796.                 break;
  2797.               case PU_HDG:
  2798.                 x_hdg = 1;
  2799.                 break;
  2800. #ifdef RECURSIVE
  2801.               case PU_RECU:             /* /RECURSIVE */
  2802.                 recursive = 2;
  2803.                 break;
  2804. #endif /* RECURSIVE */
  2805.               default:
  2806.                 printf("?Not implemented yet - \"%s\"\n",atmbuf);
  2807.                 rc = -9;
  2808.                 goto xpurge;
  2809.             }
  2810.         } else if (cmresult.fcode == _CMIFI) {
  2811.             havename = 1;
  2812.         } else if (cmresult.fcode == _CMCFM) {
  2813.             confirmed = 1;
  2814.         } else {
  2815.             rc = -2;
  2816.             goto xpurge;
  2817.         }
  2818.     }
  2819.     if (havename) {
  2820. #ifdef CKREGEX
  2821.         ckmakmsg(line,LINBUFSIZ,cmresult.sresult,".~[1-9]*~",NULL,NULL);
  2822. #else
  2823.         ckmakmsg(line,LINBUFSIZ,cmresult.sresult,".~*~",NULL,NULL);
  2824. #endif /* CKREGEX */
  2825.     } else {
  2826. #ifdef CKREGEX
  2827.         ckstrncpy(line,"*.~[1-9]*~",LINBUFSIZ);
  2828. #else
  2829.         ckstrncpy(line,"*.~*~",LINBUFSIZ);
  2830. #endif /* CKREGEX */
  2831.     }
  2832.     if (!confirmed) {
  2833.         if ((x = cmcfm()) < 0) {
  2834.             rc = x;
  2835.             goto xpurge;
  2836.         }
  2837.     }
  2838.     /* Parse finished - now action */
  2839.  
  2840. #ifdef CK_LOGIN
  2841.     if (isguest) {
  2842.         printf("?File deletion by guests not permitted.\n");
  2843.         rc = -9;
  2844.         goto xpurge;
  2845.     }
  2846. #endif /* CK_LOGIN */
  2847.  
  2848. #ifdef CK_TTGWSIZ
  2849.     if (paging < 0)                     /* /[NO]PAGE not given */
  2850.       paging = xaskmore;                /* so use prevailing */
  2851. #endif /* CK_TTGWSIZ */
  2852.  
  2853.     lines = 0;
  2854.     if (x_hdg > 0) {
  2855.         printf("Purging %s, keeping %d...%s\n",
  2856.                s,
  2857.                tokeep,
  2858.                simulate ? " (SIMULATION)" : "");
  2859.         lines += 2;
  2860.     }
  2861.     flags = ZX_FILONLY;
  2862.     if (recursive) flags |= ZX_RECURSE;
  2863.     n = nzxpand(line,flags);            /* Get list of backup files */
  2864.     if (tokeep < 1) {                   /* Deleting all of them... */
  2865.         for (i = 0; i < n; i++) {
  2866.             if (fs) if (fileselect(mtchs[i],
  2867.                                    pu_aft,pu_bef,pu_naf,pu_nbf,
  2868.                                    minsize,maxsize,0,8,pxlist) < 1) {
  2869.                 if (listing > 0) {
  2870.                     printf(" %s (SKIPPED)\n",mtchs[i]);
  2871. #ifdef CK_TTGWSIZ
  2872.                     if (paging)
  2873.                       if (++lines > cmd_rows - 3) {
  2874.                           if (!askmore()) goto xpurge; else lines = 0;
  2875.                       }
  2876. #endif /* CK_TTGWSIZ */
  2877.                 }
  2878.                 continue;
  2879.             }
  2880.             if (asking) {
  2881.                 int x;
  2882.                 ckmakmsg(tmpbuf,TMPBUFSIZ," Delete ",mtchs[i],"?",NULL);
  2883.                 x = getyesno(tmpbuf,1);
  2884.                 switch (x) {
  2885.                   case 0: continue;
  2886.                   case 1: break;
  2887.                   case 2: goto xpurge;
  2888.                 }
  2889.             }
  2890.             x = deleting ? zdelet(mtchs[i]) : 0;
  2891.             if (x > -1) {
  2892.                 if (listing)
  2893.                   printf(" %s (%s)\n", mtchs[i],deleting ? "OK" : "SELECTED");
  2894.                 count++;
  2895.             } else {
  2896.                 errors++;
  2897.                 if (listing)
  2898.                   printf(" %s (FAILED)\n", mtchs[i]);
  2899.             }
  2900. #ifdef CK_TTGWSIZ
  2901.             if (listing && paging)
  2902.               if (++lines > cmd_rows - 3) {
  2903.                   if (!askmore()) goto xpurge; else lines = 0;
  2904.               }
  2905. #endif /* CK_TTGWSIZ */
  2906.         }
  2907.         goto xpurge;
  2908.     }
  2909.     if (n < tokeep) {                   /* Not deleting any */
  2910.         count = 0;
  2911.         if (listing)
  2912.           printf(" Matches = %d: Not enough to purge.\n");
  2913.         goto xpurge;
  2914.     }
  2915.  
  2916.     /* General case - delete some but not others */
  2917.  
  2918.     sh_sort(mtchs,NULL,n,0,0,filecase); /* Alphabetize the list (ESSENTIAL) */
  2919.  
  2920.     g = 0;                              /* Start of current group */
  2921.     for (i = 0; i < n; i++) {           /* Go thru sorted file list */
  2922.         x = znext(namebuf);             /* Get next file */
  2923.         if (x < 1 || !namebuf[0] || i == n - 1) /* No more? */
  2924.           done = 1;                     /* NOTE: 'done' must be 0 or 1 only */
  2925.         if (fs) if (fileselect(namebuf,
  2926.                                pu_aft,pu_bef,pu_naf,pu_nbf,
  2927.                                minsize,maxsize,0,8,pxlist) < 1) {
  2928.             if (listing > 0) {
  2929.                 printf(" %s (SKIPPED)\n",namebuf);
  2930.                 if (++lines > cmd_rows - 3)
  2931.                   if (!askmore()) goto xpurge; else lines = 0;
  2932.             }
  2933.             continue;
  2934.         }
  2935.         if (x > 0)
  2936.           if ((m = bkupnum(namebuf,&z)) < 0) /* This file's backup number. */
  2937.             continue;
  2938.         for (j = 0; j < tokeep; j++) {  /* Insert in list. */
  2939.             if (m > xx[j]) {
  2940.                 for (k = tokeep - 1; k > j; k--)
  2941.                   xx[k] = xx[k-1];
  2942.                 xx[j] = m;
  2943.                 break;
  2944.             }
  2945.         }
  2946.         /* New group? */
  2947.         if (done || (i > 0 && ckstrcmp(namebuf,basebuf,z,1))) {
  2948.             if (i + done - g > tokeep) { /* Do we have enough to purge? */
  2949.                 min = xx[tokeep-1];     /* Yes, lowest backup number to keep */
  2950.                 debug(F111,"dopurge group",basebuf,min);
  2951.                 for (j = g; j < i + done; j++) { /* Go through this group */
  2952.                     x = bkupnum(mtchs[j],&z);    /* Get file backup number */
  2953.                     if (x > 0 && x < min) {      /* Below minimum? */
  2954.                         x = deleting ? zdelet(mtchs[j]) : 0;
  2955.                         if (x < 0) errors++;
  2956.                         if (listing)
  2957.                           printf(" %s (%s)\n",
  2958.                                  mtchs[j],
  2959.                                  ((x < 0) ? "ERROR" :
  2960.                                   (deleting ? "DELETED" : "SELECTED"))
  2961.                                  );
  2962.                         count++;
  2963.                     } else if (listing) /* Not below minimum - keep this one */
  2964.                       printf(" %s (KEPT)\n",mtchs[j]);
  2965. #ifdef CK_TTGWSIZ
  2966.                     if (listing && paging)
  2967.                       if (++lines > cmd_rows - 3) {
  2968.                           if (!askmore()) goto xpurge; else lines = 0;
  2969.                       }
  2970. #endif /* CK_TTGWSIZ */
  2971.                 }
  2972.             } else if (listing && paging) { /* Not enough to purge */
  2973.                 printf(" %s.~*~ (KEPT)\n",basebuf);
  2974. #ifdef CK_TTGWSIZ
  2975.                 if (++lines > cmd_rows - 3) {
  2976.                     if (!askmore()) goto xpurge; else lines = 0;
  2977.                 }
  2978. #endif /* CK_TTGWSIZ */
  2979.             }
  2980.             for (j = 0; j < tokeep; j++) /* Clear the backup number list */
  2981.               xx[j] = 0;
  2982.             g = i;                      /* Reset the group pointer */
  2983.         }
  2984.         if (done)                       /* No more files, done. */
  2985.           break;
  2986.         strncpy(basebuf,namebuf,z);     /* Set basename of this file */
  2987.         basebuf[z] = NUL;
  2988.     }
  2989.   xpurge:                               /* Common exit point */
  2990.     if (g_matchdot > -1) {
  2991.         matchdot = g_matchdot;          /* Restore these... */
  2992.         g_matchdot = -1;
  2993.     }
  2994.     if (rc < 0) return(rc);             /* Parse error */
  2995.     if (x_hdg)
  2996.       printf("Files purged: %d%s\n",
  2997.              count,
  2998.              deleting ? "" : " (not really)"
  2999.              );
  3000.     return(success = count > 0 ? 1 : (errors > 0) ? 0 : 1);
  3001. }
  3002. #endif /* CKPURGE */
  3003.  
  3004. #ifndef NOXFER
  3005. #ifndef NOLOCAL
  3006. int
  3007. doxdis() {
  3008.     extern int nolocal;
  3009.     int x, y = 0, z;
  3010. #ifdef COMMENT
  3011.     char *s;
  3012. #endif /* COMMENT */
  3013.  
  3014.     if ((x = cmkey(fdtab,nfdtab,"file transfer display style","",
  3015.                    xxstring)) < 0)
  3016.       return(x);
  3017. #ifdef CK_PCT_BAR
  3018.     if ((y = cmkey(fdftab,2,"","thermometer",xxstring)) < 0)
  3019.       return(y);
  3020. #endif /* CK_PCT_BAR */
  3021.     if ((z = cmcfm()) < 0) return(z);
  3022. #ifdef CK_CURSES
  3023.     if (x == XYFD_C) {                  /* FULLSCREEN */
  3024. #ifdef COMMENT
  3025. #ifndef MYCURSES
  3026.         extern char * trmbuf;           /* Real curses */
  3027.         int z;
  3028. #endif /* MYCURSES */
  3029. #endif /* COMMENT */
  3030.  
  3031.         if (nolocal)                    /* Nothing to do in this case */
  3032.             return(success = 1);
  3033.  
  3034. #ifdef COMMENT
  3035. #ifndef MYCURSES
  3036. #ifndef VMS
  3037.         s = getenv("TERM");
  3038.         debug(F110,"doxdis TERM",s,0);
  3039.         if (!s) s = "";
  3040.         fxdinit(x);
  3041.         if (*s && trmbuf) {             /* Don't call tgetent */
  3042.             z = tgetent(trmbuf,s);      /* if trmbuf not allocated */
  3043.             debug(F111,"doxdis tgetent",s,z);
  3044.         } else {
  3045.             z = 0;
  3046.             debug(F110,"doxdis tgetent skipped",s,0);
  3047.         }
  3048.         if (z < 1) {
  3049.             printf("Sorry, terminal type unknown: \"%s\"\n",s);
  3050.             return(success = 0);
  3051.         }
  3052. #endif /* VMS */
  3053. #endif /* MYCURSES */
  3054. #else
  3055.         fxdinit(x);
  3056. #endif /* COMMENT */
  3057.  
  3058. #ifdef CK_PCT_BAR
  3059.         thermometer = y;
  3060. #endif /* CK_PCT_BAR */
  3061.  
  3062.         line[0] = '\0';                 /* (What's this for?) */
  3063.     }
  3064. #endif /* CK_CURSES */
  3065.     fdispla = x;                        /* It's OK. */
  3066.     return(success = 1);
  3067. }
  3068. #endif /* NOLOCAL */
  3069. #endif /* NOXFER */
  3070.  
  3071. int
  3072. setfil(rmsflg) int rmsflg; {
  3073. #ifdef COMMENT
  3074.     extern int en_del;
  3075. #endif /* COMMENT */
  3076. #ifndef NOXFER
  3077.     if (rmsflg) {
  3078.         if ((y = cmkey(rfiltab,nrfilp,"Remote file parameter","",
  3079.                        xxstring)) < 0) {
  3080.             if (y == -3) {
  3081.                 printf("?Remote file parameter required\n");
  3082.                 return(-9);
  3083.             } else return(y);
  3084.         }
  3085.     } else {
  3086. #endif /* NOXFER */
  3087.         if ((y = cmkey(filtab,nfilp,"File parameter","",xxstring)) < 0)
  3088.           return(y);
  3089. #ifndef NOXFER
  3090.     }
  3091. #endif /* NOXFER */
  3092.     switch (y) {
  3093. #ifdef COMMENT                          /* Not needed */
  3094.       case XYFILB:                      /* Blocksize */
  3095.         if ((y = cmnum("file block size",ckitoa(DBLKSIZ),10,&z,xxstring)) < 0)
  3096.           return(y);
  3097.         if ((x = cmcfm()) < 0) return(x);
  3098.         if (rmsflg) {
  3099.             sstate = setgen('S', "311", ckitoa(z), "");
  3100.             return((int) sstate);
  3101.         } else {
  3102.             fblksiz = z;
  3103.             return(success = 1);
  3104.         }
  3105. #endif /* COMMENT */
  3106.  
  3107. #ifndef NOXFER
  3108.       case XYFILS:                      /* Byte size */
  3109.         if ((y = cmnum("file byte size (7 or 8)","8",10,&z,xxstring)) < 0)
  3110.           return(y);
  3111.         if (z != 7 && z != 8) {
  3112.             printf("\n?The choices are 7 and 8\n");
  3113.             return(0);
  3114.         }
  3115.         if ((y = cmcfm()) < 0) return(y);
  3116.         if (z == 7) fmask = 0177;
  3117.         else if (z == 8) fmask = 0377;
  3118.         return(success = 1);
  3119.  
  3120. #ifndef NOCSETS
  3121.       case XYFILC: {                    /* Character set */
  3122.           char * csetname = NULL;
  3123.           extern int
  3124.             r_cset, s_cset, afcset[];   /* SEND CHARACTER-SET AUTO or MANUAL */
  3125.  
  3126.           struct FDB kw, fl;
  3127.           cmfdbi(&kw,                   /* First FDB - command switches */
  3128.                  _CMKEY,                /* fcode */
  3129.                  rmsflg ? "server character-set name" : "",  /* help */
  3130.                  "",                    /* default */
  3131.                  "",                    /* addtl string data */
  3132.                  nfilc,                 /* addtl numeric data 1: tbl size */
  3133.                  0,                     /* addtl numeric data 2: 0 = keyword */
  3134.                  xxstring,              /* Processing function */
  3135.                  fcstab,                /* Keyword table */
  3136.                  rmsflg ? &fl : NULL    /* Pointer to next FDB */
  3137.            );
  3138.           cmfdbi(&fl,                   /* Anything that doesn't match */
  3139.                  _CMFLD,                /* fcode */
  3140.                  "",                    /* hlpmsg */
  3141.                  "",                    /* default */
  3142.                  "",                    /* addtl string data */
  3143.                  0,                     /* addtl numeric data 1 */
  3144.                  0,                     /* addtl numeric data 2 */
  3145.                  xxstring,
  3146.                  NULL,
  3147.                  NULL
  3148.                  );
  3149.           if ((x = cmfdb(&kw)) < 0)
  3150.             return(x);
  3151.           if (cmresult.fcode == _CMKEY) {
  3152.               x = cmresult.nresult;
  3153.               csetname = fcsinfo[x].keyword;
  3154.           } else {
  3155.               ckstrncpy(line,cmresult.sresult,LINBUFSIZ);
  3156.               csetname = line;
  3157.           }
  3158.           if ((z = cmcfm()) < 0) return(z);
  3159.           if (rmsflg) {
  3160.               sstate = setgen('S', "320", csetname, "");
  3161.               return((int) sstate);
  3162.           }
  3163.           fcharset = x;
  3164.           if (s_cset == XMODE_A)        /* If SEND CHARACTER-SET is AUTO */
  3165.             if (x > -1 && x <= MAXFCSETS)
  3166.               if (afcset[x] > -1 && afcset[x] <= MAXTCSETS)
  3167.                 tcharset = afcset[x]; /* Pick corresponding xfer charset */
  3168.           setxlatype(tcharset,fcharset); /* Translation type */
  3169.           /* If I say SET FILE CHARACTER-SET blah, I want to be blah! */
  3170.           r_cset = XMODE_M;             /* Don't switch incoming set! */
  3171.           x = fcsinfo[fcharset].size;   /* Also set default x-bit charset */
  3172.           if (x == 128)                 /* 7-bit... */
  3173.             dcset7 = fcharset;
  3174.           else if (x == 256)            /* 8-bit... */
  3175.             dcset8 = fcharset;
  3176.           return(success = 1);
  3177.       }
  3178. #endif /* NOCSETS */
  3179.  
  3180. #ifndef NOLOCAL
  3181.       case XYFILD:                      /* Display */
  3182.         return(doxdis());
  3183. #endif /* NOLOCAL */
  3184. #endif /* NOXFER */
  3185.  
  3186.       case XYFILA:                      /* End-of-line */
  3187. #ifdef NLCHAR
  3188.         s = "";
  3189.         if (NLCHAR == 015)
  3190.           s = "cr";
  3191.         else if (NLCHAR == 012)
  3192.           s = "lf";
  3193.         if ((x = cmkey(eoltab, neoltab,
  3194.                        "local text-file line terminator",s,xxstring)) < 0)
  3195.           return(x);
  3196. #else
  3197.         if ((x = cmkey(eoltab, neoltab,
  3198.                        "local text-file line terminator","crlf",xxstring)) < 0)
  3199.           return(x);
  3200. #endif /* NLCHAR */
  3201.         if ((z = cmcfm()) < 0) return(z);
  3202.         feol = (CHAR) x;
  3203.         return(success = 1);
  3204.  
  3205. #ifndef NOXFER
  3206.       case XYFILN:                      /* Names */
  3207.         if ((x = cmkey(fntab,nfntab,"how to handle filenames","converted",
  3208.                        xxstring)) < 0)
  3209.           return(x);
  3210.         if ((z = cmcfm()) < 0) return(z);
  3211.         if (rmsflg) {
  3212.             sstate = setgen('S', "301", ckitoa(1 - x), "");
  3213.             return((int) sstate);
  3214.         } else {
  3215.             ptab[protocol].fncn = x;    /* Set structure */
  3216.             fncnv = x;                  /* Set variable */
  3217.             f_save = x;                 /* And set "permanent" variable */
  3218.             return(success = 1);
  3219.         }
  3220.  
  3221.       case XYFILR:                      /* Record length */
  3222.         if ((y = cmnum("file record length",
  3223.                        ckitoa(DLRECL),10,&z,xxstring)) < 0)
  3224.           return(y);
  3225.         if ((x = cmcfm()) < 0) return(x);
  3226.         if (rmsflg) {
  3227.             sstate = setgen('S', "312", ckitoa(z), "");
  3228.             return((int) sstate);
  3229.         } else {
  3230.             frecl = z;
  3231.             return(success = 1);
  3232.         }
  3233.  
  3234. #ifdef COMMENT
  3235.       case XYFILO:                      /* Organization */
  3236.         if ((x = cmkey(forgtab,nforg,"file organization","sequential",
  3237.                        xxstring)) < 0)
  3238.           return(x);
  3239.         if ((y = cmcfm()) < 0) return(y);
  3240.         if (rmsflg) {
  3241.             sstate = setgen('S', "314", ckitoa(x), "");
  3242.             return((int) sstate);
  3243.         } else {
  3244.             forg = x;
  3245.             return(success = 1);
  3246.         }
  3247. #endif /* COMMENT */
  3248.  
  3249. #ifdef COMMENT                          /* Not needed */
  3250.       case XYFILF:                      /* Format */
  3251.         if ((x = cmkey(frectab,nfrec,"file record format","stream",
  3252.                        xxstring)) < 0)
  3253.           return(x);
  3254.         if ((y = cmcfm()) < 0) return(y);
  3255.         if (rmsflg) {
  3256.             sstate = setgen('S', "313", ckitoa(x), "");
  3257.             return((int) sstate);
  3258.         } else {
  3259.             frecfm = x;
  3260.             return(success = 1);
  3261.         }
  3262. #endif /* COMMENT */
  3263.  
  3264. #ifdef COMMENT
  3265.       case XYFILP:                      /* Printer carriage control */
  3266.         if ((x = cmkey(fcctab,nfcc,"file carriage control","newline",
  3267.                        xxstring)) < 0)
  3268.           return(x);
  3269.         if ((y = cmcfm()) < 0) return(y);
  3270.         if (rmsflg) {
  3271.             sstate = setgen('S', "315", ckitoa(x), "");
  3272.             return((int) sstate);
  3273.         } else {
  3274.             fcctrl = x;
  3275.             return(success = 1);
  3276.         }
  3277. #endif /* COMMENT */
  3278. #endif /* NOXFER */
  3279.  
  3280.       case XYFILT:                      /* Type */
  3281.         if ((x = cmkey(rmsflg ? rfttab  : fttab,
  3282.                        rmsflg ? nrfttyp : nfttyp,
  3283.                        "type of file transfer","text",xxstring)) < 0)
  3284.           return(x);
  3285.  
  3286. #ifdef VMS
  3287.         /* Allow VMS users to choose record format for binary files */
  3288.         if ((x == XYFT_B) && (rmsflg == 0)) {
  3289.             if ((x = cmkey(fbtab,nfbtyp,"VMS record format","fixed",
  3290.                            xxstring)) < 0)
  3291.               return(x);
  3292.         }
  3293. #endif /* VMS */
  3294.         if ((y = cmcfm()) < 0) return(y);
  3295.         binary = x;
  3296.         b_save = x;
  3297. #ifdef MAC
  3298.         (void) mac_setfildflg(binary);
  3299. #endif /* MAC */
  3300. #ifndef NOXFER
  3301.         if (rmsflg) {
  3302.             /* Allow for LABELED in VMS & OS/2 */
  3303.             sstate = setgen('S', "300", ckitoa(x), "");
  3304.             return((int) sstate);
  3305.         } else {
  3306. #endif /* NOXFER */
  3307.             return(success = 1);
  3308. #ifndef NOXFER
  3309.         }
  3310. #endif /* NOXFER */
  3311.  
  3312. #ifndef NOXFER
  3313.       case XYFILX:                      /* Collision Action */
  3314.         if ((x = cmkey(colxtab,ncolx,"Filename collision action","backup",
  3315.                        xxstring)) < 0)
  3316.           return(x);
  3317.         if ((y = cmcfm()) < 0) return(y);
  3318. #ifdef CK_LOGIN
  3319.         if (isguest) {
  3320.             /* Don't let guests change existing files */
  3321.             printf("?This command not valid for guests\n");
  3322.             return(-9);
  3323.         }
  3324. #endif /* CK_LOGIN */
  3325. #ifdef COMMENT
  3326.         /* Not appropriate - DISABLE DELETE only refers to server */
  3327.         if ((x == XYFX_X || x == XYFX_B || x == XYFX_U || x == XYFX_A) &&
  3328.             (!ENABLED(en_del))) {
  3329.             printf("?Sorry, file deletion is disabled.\n");
  3330.             return(-9);
  3331.         }
  3332. #endif /* COMMENT */
  3333.         fncact = x;
  3334.         ptab[protocol].fnca = x;
  3335.         if (rmsflg) {
  3336.             sstate = setgen('S', "302", ckitoa(fncact), "");
  3337.             return((int) sstate);
  3338.         } else {
  3339.             if (fncact == XYFX_R) ckwarn = 1; /* FILE WARNING implications */
  3340.             if (fncact == XYFX_X) ckwarn = 0; /* ... */
  3341.             return(success = 1);
  3342.         }
  3343.  
  3344.       case XYFILW:                      /* Warning/Write-Protect */
  3345.         if ((x = seton(&ckwarn)) < 0) return(x);
  3346.         if (ckwarn)
  3347.           fncact = XYFX_R;
  3348.         else
  3349.           fncact = XYFX_X;
  3350.         return(success = 1);
  3351.  
  3352. #ifdef CK_LABELED
  3353.       case XYFILL:                      /* LABELED FILE parameters */
  3354.         if ((x = cmkey(lbltab,nlblp,"Labeled file feature","",
  3355.                        xxstring)) < 0)
  3356.           return(x);
  3357.         if ((success = seton(&y)) < 0)
  3358.           return(success);
  3359.         if (y)                          /* Set or reset the selected bit */
  3360.           lf_opts |= x;                 /* in the options bitmask. */
  3361.         else
  3362.           lf_opts &= ~x;
  3363.         return(success);
  3364. #endif /* CK_LABELED */
  3365.  
  3366.       case XYFILI: {                    /* INCOMPLETE */
  3367.           extern struct keytab ifdatab[];
  3368.           extern int keep;
  3369.           if ((y = cmkey(ifdatab,3,"","auto",xxstring)) < 0) return(y);
  3370.           if ((x = cmcfm()) < 0) return(x);
  3371.           if (rmsflg) {
  3372.               sstate = setgen('S',
  3373.                               "310",
  3374.                               y == 0 ? "0" : (y == 1 ? "1" : "2"),
  3375.                               ""
  3376.                               );
  3377.               return((int) sstate);
  3378.           } else {
  3379.               keep = y;
  3380.               return(success = 1);
  3381.           }
  3382.       }
  3383.  
  3384. #ifdef CK_TMPDIR
  3385.       case XYFILG: {                    /* Download directory */
  3386.           int x;
  3387.           char *s;
  3388. #ifdef ZFNQFP
  3389.           struct zfnfp * fnp;
  3390. #endif /* ZFNQFP */
  3391. #ifdef MAC
  3392.           char temp[34];
  3393. #endif /* MAC */
  3394.  
  3395. #ifdef GEMDOS
  3396.           if ((x = cmdir("Name of local directory, or carriage return",
  3397.                          "",&s,
  3398.                          NULL)) < 0 ) {
  3399.               if (x != -3)
  3400.                 return(x);
  3401.           }
  3402. #else
  3403. #ifdef OS2
  3404.           if ((x = cmdir("Name of PC disk and/or directory,\n\
  3405.        or press the Enter key to use current directory",
  3406.                          "",&s,xxstring)) < 0 ) {
  3407.               if (x != -3)
  3408.                 return(x);
  3409.           }
  3410. #else
  3411. #ifdef MAC
  3412.           x = ckstrncpy(temp,zhome(),32);
  3413.           if (x > 0) if (temp[x-1] != ':') { temp[x] = ':'; temp[x+1] = NUL; }
  3414.           if ((x = cmtxt("Name of Macintosh volume and/or folder,\n\
  3415.  or press the Return key for the desktop on the boot disk",
  3416.                          temp,&s, xxstring)) < 0 )
  3417.             return(x);
  3418. #else
  3419.           if ((x = cmdir("Name of local directory, or carriage return",
  3420.                          "", &s, xxstring)) < 0 ) {
  3421.               if (x != -3)
  3422.                 return(x);
  3423.           }
  3424. #endif /* MAC */
  3425. #endif /* OS2 */
  3426. #endif /* GEMDOS */
  3427.           debug(F110,"download dir",s,0);
  3428.  
  3429. #ifndef MAC
  3430.           if (x == 2) {
  3431.               printf("?Wildcards not allowed in directory name\n");
  3432.               return(-9);
  3433.           }
  3434. #endif /* MAC */
  3435.  
  3436. #ifdef ZFNQFP
  3437.           if ((fnp = zfnqfp(s,TMPBUFSIZ - 1,tmpbuf))) {
  3438.               if (fnp->fpath)
  3439.                 if ((int) strlen(fnp->fpath) > 0)
  3440.                   s = fnp->fpath;
  3441.           }
  3442.           debug(F110,"download zfnqfp",s,0);
  3443. #endif /* ZFNQFP */
  3444.  
  3445.           ckstrncpy(line,s,LINBUFSIZ);  /* Make a safe copy */
  3446. #ifndef MAC
  3447.           if ((x = cmcfm()) < 0)        /* Get confirmation */
  3448.             return(x);
  3449. #endif /* MAC */
  3450.  
  3451. #ifdef CK_LOGIN
  3452.         if (isguest) {
  3453.             /* Don't let guests change existing files */
  3454.             printf("?This command not valid for guests\n");
  3455.             return(-9);
  3456.         }
  3457. #endif /* CK_LOGIN */
  3458.           x = strlen(s);
  3459.  
  3460.           if (x) {
  3461. #ifdef datageneral
  3462.               if (s[x-1] == ':')        /* homdir ends in colon, */
  3463.                 s[x-1] = NUL;           /* and "dir" doesn't like that... */
  3464. #endif /* datageneral */
  3465.               makestr(&dldir,s);
  3466.           } else
  3467.             makestr(&dldir,NULL);       /* dldir is NULL when not assigned */
  3468.  
  3469.           return(success = 1);
  3470.       }
  3471. #endif /* CK_TMPDIR */
  3472.       case XYFILY:
  3473.         return(setdest());
  3474. #endif /* NOXFER */
  3475.  
  3476. #ifdef CK_CTRLZ
  3477.       case XYFILV: {                    /* EOF */
  3478.           extern int eofmethod;
  3479.           if ((x = cmkey(eoftab,3,"end-of-file detection method","",
  3480.                          xxstring)) < 0)
  3481.             return(x);
  3482.           if ((y = cmcfm()) < 0)
  3483.             return(y);
  3484.           eofmethod = x;
  3485.           return(success = 1);
  3486.       }
  3487. #endif /* CK_CTRLZ */
  3488.  
  3489. #ifndef NOXFER
  3490. #ifdef UNIX
  3491.       case XYFILH: {                    /* OUTPUT */
  3492.           extern int zofbuffer, zobufsize, zofblock;
  3493. #ifdef DYNAMIC
  3494.           extern char * zoutbuffer;
  3495. #endif /* DYNAMIC */
  3496.  
  3497.           if ((x = cmkey(zoftab,nzoftab,"output file writing method","",
  3498.                          xxstring)) < 0)
  3499.             return(x);
  3500.           if (x == ZOF_BUF || x == ZOF_NBUF) {
  3501.               if ((y = cmnum("output buffer size","32768",10,&z,xxstring)) < 0)
  3502.                 return(y);
  3503.               if (z < 1) {
  3504.                   printf("?Bad size - %d\n", z);
  3505.                   return(-9);
  3506.               }
  3507.           }
  3508.           if ((y = cmcfm()) < 0) return(y);
  3509.           switch (x) {
  3510.             case ZOF_BUF:
  3511.             case ZOF_NBUF:
  3512.               zofbuffer = (x == ZOF_BUF);
  3513.               zobufsize = z;
  3514.               break;
  3515.             case ZOF_BLK:
  3516.             case ZOF_NBLK:
  3517.               zofblock = (x == ZOF_BLK);
  3518.               break;
  3519.           }
  3520. #ifdef DYNAMIC
  3521.           if (zoutbuffer) free(zoutbuffer);
  3522.           if (!(zoutbuffer = (char *)malloc(z))) {
  3523.               printf("MEMORY ALLOCATION ERROR - FATAL\n");
  3524.               doexit(BAD_EXIT,-1);
  3525.           } else
  3526.             zobufsize = z;
  3527. #else
  3528.           if (z <= OBUFSIZE) {
  3529.               zobufsize = z;
  3530.           } else {
  3531.               printf("?Sorry, %d is too big - %d is the maximum\n",z,OBUFSIZE);
  3532.               return(-9);
  3533.           }
  3534. #endif /* DYNAMIC */
  3535.           return(success = 1);
  3536.       }
  3537. #endif /* UNIX */
  3538.  
  3539. #ifdef PATTERNS
  3540.       case XYFIBP:                      /* BINARY-PATTERN */
  3541.       case XYFITP: {                    /* TEXT-PATTERN */
  3542.           char * tmp[FTPATTERNS];
  3543.           int i, n = 0;
  3544.           while (n < FTPATTERNS) {
  3545.               tmp[n] = NULL;
  3546.               if ((x = cmfld("Pattern","",&s,xxstring)) < 0)
  3547.                 break;
  3548.               ckstrncpy(line,s,LINBUFSIZ);
  3549.               s = brstrip(line);
  3550.               makestr(&(tmp[n++]),s);
  3551.           }
  3552.           if (x == -3) x = cmcfm();
  3553.           for (i = 0; i <= n; i++) {
  3554.               if (x > -1) {
  3555.                   if (y == XYFIBP)
  3556.                     makestr(&(binpatterns[i]),tmp[i]);
  3557.                   else
  3558.                     makestr(&(txtpatterns[i]),tmp[i]);
  3559.               }
  3560.               free(tmp[i]);
  3561.           }
  3562.           if (y == XYFIBP)              /* Null-terminate the list */
  3563.             makestr(&(binpatterns[i]),NULL);
  3564.           else
  3565.             makestr(&(txtpatterns[i]),NULL);
  3566.           return(x);
  3567.       }
  3568.  
  3569.       case XYFIPA:                      /* PATTERNS */
  3570.         if ((x = setonaut(&patterns)) < 0)
  3571.           return(x);
  3572.         return(success = 1);
  3573. #endif /* PATTERNS */
  3574. #endif /* NOXFER */
  3575.  
  3576. #ifdef UNICODE
  3577.       case XYFILU: {                    /* UCS */
  3578.           extern int ucsorder, ucsbom, byteorder;
  3579.           if ((x = cmkey(ucstab,nucstab,"","",xxstring)) < 0)
  3580.             return(x);
  3581.           switch (x) {
  3582.             case UCS_BYT:
  3583.               if ((y = cmkey(botab,nbotab,
  3584.                              "Byte order",
  3585.                              byteorder ? "little-endian" : "big-endian",
  3586.                              xxstring
  3587.                              )
  3588.                    ) < 0)
  3589.                 return(y);
  3590.               if ((x = cmcfm()) < 0)
  3591.                 return(x);
  3592.               ucsorder = y;
  3593.               return(success = 1);
  3594.             case UCS_BOM:
  3595.               if ((y = cmkey(onoff,2,"","on",xxstring)) < 0)
  3596.                 return(y);
  3597.               if ((x = cmcfm()) < 0)
  3598.                 return(x);
  3599.               ucsbom = y;
  3600.               return(success = 1);
  3601.             default:
  3602.               return(-2);
  3603.           }
  3604.       }
  3605. #endif /* UNICODE */
  3606.  
  3607. #ifndef datageneral
  3608.       case XYF_INSP: {                  /* SCAN (INSPECTION) */
  3609.           extern int filepeek, nscanfile;
  3610.           if ((x = cmkey(onoff,2,"","on",xxstring)) < 0)
  3611.             return(x);
  3612.           if (y) {
  3613.               if ((y = cmnum("How much to scan",ckitoa(SCANFILEBUF),
  3614.                              10,&z,xxstring)) < 0)
  3615.                 return(y);
  3616.           }
  3617.           if ((y = cmcfm()) < 0)
  3618.             return(y);
  3619. #ifdef VMS
  3620.           filepeek = 0;
  3621.           nscanfile = 0;
  3622.           return(success = 0);
  3623. #else
  3624.           filepeek = x;
  3625.           nscanfile = z;
  3626.           return(success = 1);
  3627. #endif /* VMS */
  3628.       }
  3629. #endif /* datageneral */
  3630.  
  3631.       case XYF_DFLT:
  3632.         y = 0;
  3633. #ifndef NOCSETS
  3634.         if ((y = cmkey(fdfltab,nfdflt,"","",xxstring)) < 0)
  3635.           return(y);
  3636.         if (y == 7 || y == 8) {
  3637.             if (y == 7)
  3638.               s = fcsinfo[dcset7].keyword;
  3639.             else
  3640.               s = fcsinfo[dcset8].keyword;
  3641.             if ((x = cmkey(fcstab,nfilc,"character-set",s,xxstring)) < 0)
  3642.               return(x);
  3643.         }
  3644.         ckstrncpy(line,fcsinfo[x].keyword,LINBUFSIZ);
  3645.         s = line;
  3646. #endif /* NOCSETS */
  3647.         if ((z = cmcfm()) < 0)
  3648.           return(z);
  3649.         switch (y) {
  3650. #ifndef NOCSETS
  3651.           case 7:
  3652.             if (fcsinfo[x].size != 128) {
  3653.                 printf("%s - Not a 7-bit set\n",s);
  3654.                 return(-9);
  3655.             }
  3656.             dcset7 = x;
  3657.             break;
  3658.           case 8:
  3659.             if (fcsinfo[x].size != 256) {
  3660.                 printf("%s - Not an 8-bit set\n",s);
  3661.                 return(-9);
  3662.             }
  3663.             dcset8 = x;
  3664.             break;
  3665. #endif /* NOCSETS */
  3666.           default:
  3667.             return(-2);
  3668.         }
  3669.         return(success = 1);
  3670.  
  3671. #ifndef NOXFER
  3672.       case 9997:                        /* FASTLOOKUPS */
  3673.         return(success = seton(&stathack));
  3674. #endif /* NOXFER */
  3675.  
  3676. #ifdef UNIX
  3677. #ifdef DYNAMIC
  3678.       case XYF_LSIZ: {                  /* LISTSIZE */
  3679.           int zz;
  3680.           y = cmnum("Maximum number of filenames","",10,&x,xxstring);
  3681.           if ((x = setnum(&zz,x,y,-1)) < 0)
  3682.             return(x);
  3683.           if (zsetfil(zz,3) < 0) {
  3684.               printf("?Memory allocation failure\n");
  3685.               return(-9);
  3686.           }
  3687.           return(success = 1);
  3688.       }
  3689.       case XYF_SSPA: {                  /* STRINGSPACE */
  3690.           int zz;
  3691.           y = cmnum("Number of characters for filename list",
  3692.                     "",10,&x,xxstring);
  3693.           if ((x = setnum(&zz,x,y,-1)) < 0)
  3694.             return(x);
  3695.           if (zsetfil(zz,1) < 0) {
  3696.               printf("?Memory allocation failure\n");
  3697.               return(-9);
  3698.           }
  3699.           return(success = 1);
  3700.       }
  3701.  
  3702. #endif /* DYNAMIC */
  3703. #endif /* UNIX */
  3704.  
  3705.       default:
  3706.         printf("?unexpected file parameter\n");
  3707.         return(-2);
  3708.     }
  3709. }
  3710.  
  3711. #ifndef NOLOCAL
  3712. #ifdef OS2
  3713. /* MS-DOS KERMIT compatibility modes */
  3714. int
  3715. setmsk() {
  3716.     if ((y = cmkey(msktab,nmsk,"MS-DOS Kermit compatibility mode",
  3717.                     "keycodes",xxstring)) < 0) return(y);
  3718.  
  3719.     switch ( y ) {
  3720. #ifdef COMMENT
  3721.       case MSK_COLOR:
  3722.         return(seton(&mskcolors));
  3723. #endif /* COMMENT */
  3724.       case MSK_KEYS:
  3725.         return(seton(&mskkeys));
  3726.       default:                          /* Shouldn't get here. */
  3727.         return(-2);
  3728.     }
  3729. }
  3730. #endif /* OS2 */
  3731.  
  3732. int
  3733. settrmtyp() {
  3734. #ifdef OS2
  3735. #ifdef TNCODE
  3736.     extern int ttnum;                    /* Last Telnet Terminal Type sent */
  3737.     extern int ttnumend;                 /* Has end of list been found */
  3738. #endif /* TNCODE */
  3739.     if ((x = cmkey(ttyptab,nttyp,"","vt320",xxstring)) < 0)
  3740.       return(x);
  3741.     if ((y = cmcfm()) < 0)
  3742.       return(y);
  3743.     settermtype(x,1);
  3744. #ifdef TNCODE
  3745.     /* So we send the correct terminal name to the host if it asks for it */
  3746.     ttnum = -1;                         /* Last Telnet Terminal Type sent */
  3747.     ttnumend = 0;                       /* end of list not found */
  3748. #endif /* TNCODE */
  3749.     return(success = 1);
  3750. #else  /* Not OS2 */
  3751.     printf(
  3752. "\n Sorry, this version of C-Kermit does not support the SET TERMINAL TYPE\n");
  3753.     printf(
  3754. " command.  Type \"help set terminal\" for further information.\n");
  3755. #endif /* OS2 */
  3756.     return(success = 0);
  3757. }
  3758.  
  3759. #ifdef CKTIDLE
  3760. static char iactbuf[132];
  3761.  
  3762. char *
  3763. getiact() {
  3764.     switch (tt_idleact) {
  3765.       case IDLE_RET:  return("return");
  3766.       case IDLE_EXIT: return("exit");
  3767.       case IDLE_HANG: return("hangup");
  3768. #ifdef TNCODE
  3769.       case IDLE_TNOP: return("Telnet NOP");
  3770.       case IDLE_TAYT: return("Telnet AYT");
  3771. #endif /* TNCODE */
  3772.  
  3773.       case IDLE_OUT: {
  3774.           int c, k, n;
  3775.           char * p, * q, * t;
  3776.           k = ckstrncpy(iactbuf,"output ",132);
  3777.           n = k;
  3778.           q = &iactbuf[k];
  3779.           p = tt_idlestr;
  3780.           if (!p) p = "";
  3781.           if (!*p) return("output (nothing)");
  3782.           while ((c = *p++) && n < 131) {
  3783.               c &= 0xff;
  3784.               if (c == '\\') {
  3785.                   if (n > 130) break;
  3786.                   *q++ = '\\';
  3787.                   *q++ = '\\';
  3788.                   *q = NUL;
  3789.                   n += 2;
  3790.               } else if ((c > 31 && c < 127) || c > 159) {
  3791.                   *q++ = c;
  3792.                   *q = NUL;
  3793.                   n++;
  3794.               } else {
  3795.                   if (n > (131 - 6))
  3796.                     break;
  3797.                   sprintf(q,"\\{%d}",c);
  3798.                   k = strlen(q);
  3799.                   q += k;
  3800.                   n += k;
  3801.                   *q = NUL;
  3802.               }
  3803.           }
  3804.           *q = NUL;
  3805. #ifdef OS2
  3806.           k = tt_cols[VTERM];
  3807. #else
  3808.           k = tt_cols;
  3809. #endif /* OS2 */
  3810.           if (n > k - 52) {
  3811.               n = k - 52;
  3812.               iactbuf[n-2] = '.';
  3813.               iactbuf[n-1] = '.';
  3814.               iactbuf[n] = NUL;
  3815.           }
  3816.           return(iactbuf);
  3817.       }
  3818.       default: return("unknown");
  3819.     }
  3820. }
  3821. #endif /* CKTIDLE */
  3822.  
  3823. #ifndef NOCSETS
  3824. VOID
  3825. setlclcharset(x) int x; {
  3826.     int i;
  3827.     tcsl = y;                   /* Local character set */
  3828. #ifdef OS2
  3829.     for (i = 0; i < 4; i++) {
  3830.         G[i].init = TRUE;
  3831.         x = G[i].designation;
  3832.         G[i].c1 = (x != tcsl) && cs_is_std(x);
  3833.         x = G[i].def_designation;
  3834.         G[i].def_c1 = (x != tcsl) && cs_is_std(x);
  3835.     }
  3836. #endif /* OS2 */
  3837. }
  3838.  
  3839. VOID
  3840. setremcharset(x, z) int x, z; {
  3841.     int i;
  3842.  
  3843.     /* KUI can't have a Transparent Character Set */
  3844. #ifdef UNICODE
  3845.     if (x == TX_TRANSP)
  3846. #else /* UNICODE */
  3847.     if (x == FC_TRANSP)
  3848. #endif /* UNICODE */
  3849.     {                           /* TRANSPARENT? */
  3850. #ifndef OS2
  3851.         tcsr = tcsl;            /* Make both sets the same */
  3852. #else /* OS2 */
  3853. #ifdef CKOUNI
  3854.         tt_utf8 = 0;            /* Turn off UTF8 flag */
  3855.         tcsr = tcsl = dec_kbd = TX_TRANSP; /* No translation */
  3856.         tcs_transp = 1;
  3857.  
  3858.         if (!cs_is_nrc(tcsl)) {
  3859.             G[0].def_designation = G[0].designation = TX_ASCII;
  3860.             G[0].init = TRUE;
  3861.             G[0].def_c1 = G[0].c1 = FALSE;
  3862.             G[0].size = cs94;
  3863.             G[0].national = FALSE;
  3864.         }
  3865.         for (i = cs_is_nrc(tcsl) ? 0 : 1; i < 4; i++) {
  3866.             G[i].def_designation = G[i].designation = tcsl;
  3867.             G[i].init = TRUE;
  3868.             G[i].def_c1 = G[i].c1 = FALSE;
  3869.             switch (cs_size(G[i].designation)) { /* 94, 96, or 128 */
  3870.             case 128:
  3871.             case 96:
  3872.                 G[i].size = G[i].def_size = cs96;
  3873.                 break;
  3874.             case 94:
  3875.                 G[i].size = G[i].def_size = cs94;
  3876.                 break;
  3877.             default:
  3878.                 G[i].size = G[i].def_size = csmb;
  3879.                 break;
  3880.             }
  3881.             G[i].national = cs_is_nrc(x);
  3882.         }
  3883. #else /* CKOUNI */
  3884.         tcsr = tcsl;            /* Make both sets the same */
  3885.         for (i = 0; i < 4; i++) {
  3886.             G[i].def_designation = G[i].designation = FC_TRANSP;
  3887.             G[i].init = FALSE;
  3888.             G[i].size = G[i].def_size = cs96;
  3889.             G[i].c1 = G[i].def_c1 = FALSE;
  3890.             G[i].rtoi = NULL;
  3891.             G[i].itol = NULL;
  3892.             G[i].ltoi = NULL;
  3893.             G[i].itor = NULL;
  3894.             G[i].national = FALSE;
  3895.         }
  3896. #endif /* CKOUNI */
  3897. #endif /* OS2 */
  3898.         return;
  3899.     }
  3900. #ifdef OS2
  3901. #ifdef CKOUNI
  3902.     else if (x == TX_UTF8) {
  3903.         tcs_transp = 0;
  3904.         tt_utf8 = 1;            /* Turn it on if we are UTF8 */
  3905.         return;
  3906.     }
  3907. #endif /* CKOUNI */
  3908.     else {
  3909.         tcs_transp = 0;
  3910.         tcsr = x;                       /* Remote character set */
  3911. #ifdef CKOUNI
  3912.         tt_utf8 = 0;                    /* Turn off UTF8 flag */
  3913. #endif /* CKOUNI */
  3914.  
  3915.         if (z == TT_GR_ALL) {
  3916.             int i;
  3917. #ifdef UNICODE
  3918.             dec_kbd = x;
  3919. #endif /* UNICODE */
  3920.             for (i = 0; i < 4; i++) {
  3921.                 G[i].init = TRUE;
  3922.                 if ( i == 0 && !cs_is_nrc(x) ) {
  3923.                     G[0].designation = G[0].def_designation = FC_USASCII;
  3924.                     G[0].size = G[0].def_size = cs94;
  3925.                     G[0].national = 1;
  3926.                 } else {
  3927.                     G[i].def_designation = G[i].designation = x;
  3928.                     switch (cs_size(x)) {       /* 94, 96, or 128 */
  3929.                     case 128:
  3930.                     case 96:
  3931.                         G[i].size = G[i].def_size = cs96;
  3932.                         break;
  3933.                     case 94:
  3934.                         G[i].size = G[i].def_size = cs94;
  3935.                         break;
  3936.                     default:
  3937.                         G[i].size = G[i].def_size = csmb;
  3938.                         break;
  3939.                     }
  3940.                     G[i].national = cs_is_nrc(x);
  3941.                 }
  3942.                 G[i].c1 = G[i].def_c1 = x != tcsl && cs_is_std(x);
  3943.             }
  3944. #ifdef UNICODE
  3945.         } else if (z == TT_GR_KBD) {    /* Keyboard only */
  3946.             dec_kbd = x;
  3947. #endif /* UNICODE */
  3948.         } else {                        /* Specific Gn */
  3949.             G[z].def_designation = G[z].designation = x;
  3950.             G[z].init = TRUE;
  3951.             switch (cs_size(x)) {       /* 94, 96, or 128 */
  3952.             case 128:
  3953.             case 96:
  3954.                 G[z].size = G[z].def_size = cs96;
  3955.                 break;
  3956.             case 94:
  3957.                 G[z].size = G[z].def_size = cs94;
  3958.                 break;
  3959.             default:
  3960.                 G[z].size = G[z].def_size = csmb;
  3961.                 break;
  3962.             }
  3963.             G[z].c1 = G[z].def_c1 = x != tcsl && cs_is_std(x);
  3964.             G[z].national = cs_is_nrc(x);
  3965.         }
  3966.     }
  3967. #else /* not OS2 */
  3968.     tcsr = x;                   /* Remote character set */
  3969. #endif /* OS2 */
  3970. }
  3971. #endif /* NOCSETS */
  3972.  
  3973. int
  3974. settrm() {
  3975.     int i = 0;
  3976. #ifdef OS2
  3977.     extern int colorreset, user_erasemode;
  3978. #endif /* OS2 */
  3979.     if ((y = cmkey(trmtab,ntrm,"", "",xxstring)) < 0) return(y);
  3980. #ifdef MAC
  3981.     printf("\n?Sorry, not implemented yet.  Please use the Settings menu.\n");
  3982.     return(-9);
  3983. #else
  3984. #ifdef IKSD
  3985.     if (inserver) {
  3986.         if ((y = cmcfm()) < 0) return(y);
  3987.         printf("?Sorry, command disabled.\r\n");
  3988.         return(success = 0);
  3989.     }
  3990. #endif /* IKSD */
  3991.  
  3992.     switch (y) {
  3993.       case XYTBYT:                      /* SET TERMINAL BYTESIZE */
  3994.         if ((y = cmnum("bytesize for terminal connection","8",10,&x,
  3995.                        xxstring)) < 0)
  3996.           return(y);
  3997.         if (x != 7 && x != 8) {
  3998.             printf("\n?The choices are 7 and 8\n");
  3999.             return(success = 0);
  4000.         }
  4001.         if ((y = cmcfm()) < 0) return(y);
  4002.         if (x == 7) cmask = 0177;
  4003.         else if (x == 8) {
  4004.             cmask = 0377;
  4005.             parity = 0;
  4006.         }
  4007. #ifdef OS2
  4008.         if (IS97801(tt_type_mode))
  4009.           SNI_bitmode(x);
  4010. #endif /* OS2 */
  4011.         return(success = 1);
  4012.  
  4013.       case XYTSO:                       /* SET TERMINAL LOCKING-SHIFT */
  4014.         return(seton(&sosi));
  4015.  
  4016.       case XYTNL:                       /* SET TERMINAL NEWLINE-MODE */
  4017.         return(seton(&tnlm));
  4018.  
  4019. #ifdef OS2
  4020.       case XYTCOL:
  4021.         if ((x = cmkey(ttycoltab,ncolors,"","terminal",xxstring)) < 0)
  4022.           return(x);
  4023.         else if (x == TTCOLRES) {
  4024.             if ((y = cmkey(ttcolmodetab,ncolmode,
  4025.                            "","default-color",xxstring)) < 0)
  4026.               return(y);
  4027.             if ((z = cmcfm()) < 0)
  4028.               return(z);
  4029.             colorreset = y;
  4030.             return(success = 1);
  4031.         } else if (x == TTCOLERA) {
  4032.             if ((y = cmkey(ttcolmodetab,ncolmode,"",
  4033.                            "current-color",xxstring)) < 0)
  4034.               return(y);
  4035.             if ((z = cmcfm()) < 0)
  4036.               return(z);
  4037.             user_erasemode = y;
  4038.             return(success=1);
  4039.         } else {                        /* No parse error */
  4040.             int fg = 0, bg = 0;
  4041.             fg = cmkey(ttyclrtab, nclrs,
  4042.                        (x == TTCOLBOR ?
  4043.                         "color for screen border" :
  4044.                         "foreground color and then background color"),
  4045.                        "lgray", xxstring);
  4046.             if (fg < 0)
  4047.               return(fg);
  4048.             if (x != TTCOLBOR) {
  4049.                 if ((bg = cmkey(ttyclrtab,nclrs,
  4050.                                 "background color","blue",xxstring)) < 0)
  4051.                   return(bg);
  4052.             }
  4053.             if ((y = cmcfm()) < 0)
  4054.               return(y);
  4055.             switch (x) {
  4056.               case TTCOLNOR:
  4057.                 colornormal = fg | bg << 4;
  4058.                 fgi = fg & 0x08;
  4059.                 bgi = bg & 0x08;
  4060.                 break;
  4061.               case TTCOLREV:
  4062.                 colorreverse = fg | bg << 4;
  4063.                 break;
  4064.               case TTCOLUND:
  4065.                 colorunderline = fg | bg << 4;
  4066.                 break;
  4067.               case TTCOLGRP:
  4068.                 colorgraphic = fg | bg << 4;
  4069.                 break;
  4070.               case TTCOLDEB:
  4071.                 colordebug = fg | bg << 4;
  4072.                 break;
  4073.               case TTCOLSTA:
  4074.                 colorstatus = fg | bg << 4;
  4075.                 break;
  4076.               case TTCOLHLP:
  4077.                 colorhelp = fg | bg << 4;
  4078.                 break;
  4079.               case TTCOLBOR:
  4080.                 colorborder = fg;
  4081.                 break;
  4082.               case TTCOLSEL:
  4083.                 colorselect = fg | bg << 4;
  4084.                 break;
  4085.               default:
  4086.                 printf("%s - invalid\n",cmdbuf);
  4087.                 return(-9);
  4088.                 break;
  4089.             }
  4090.             scrninitialized[VTERM] = 0;
  4091.             VscrnInit(VTERM);
  4092.         }
  4093.         return(success = 1);
  4094.  
  4095.       case XYTCUR: {                    /* SET TERMINAL CURSOR */
  4096.           extern int cursorena[];
  4097.           extern int cursoron[] ;       /* Cursor state on/off       */
  4098.           if ((x = cmkey(ttycurtab,ncursors,"","underline",xxstring)) < 0)
  4099.             return(x);
  4100.           if ((z = cmkey(onoff,2,"","on",xxstring)) < 0)
  4101.             return(z);
  4102.           if ((y = cmcfm()) < 0) return(y);
  4103.           tt_cursor = tt_cursor_usr = x;
  4104.           cursorena[VTERM] = tt_cursorena_usr = z;/* turn cursor on/off */
  4105.           cursoron[VTERM] = FALSE; /* Force newcursor to restore the cursor */
  4106.           return(success = 1);
  4107.       }
  4108. #endif /* OS2 */
  4109.  
  4110.       case XYTTYP:                      /* SET TERMINAL TYPE */
  4111.         return(settrmtyp());
  4112.  
  4113. #ifdef OS2
  4114.       case XYTARR:                      /* SET TERMINAL ARROW-KEYS */
  4115.         if ((x = cmkey(akmtab,2,"","",xxstring)) < 0) return(x);
  4116.         if ((y = cmcfm()) < 0) return(y);
  4117.         tt_arrow = x;                   /* TTK_NORM / TTK_APPL; see ckuusr.h */
  4118.         return(success = 1);
  4119.  
  4120.       case XYTKPD:                      /* SET TERMINAL KEYPAD-MODE */
  4121.         if ((x = cmkey(kpmtab,2,"","",xxstring)) < 0) return(x);
  4122.         if ((y = cmcfm()) < 0) return(y);
  4123.         tt_keypad = x;                  /* TTK_NORM / TTK_APPL; see ckuusr.h */
  4124.         return(success = 1);
  4125.  
  4126.       case XYTUNX: {                    /* SET TERM UNIX-MODE (DG) */
  4127.         extern int dgunix,dgunix_usr;
  4128.         x = seton(&dgunix);
  4129.         dgunix_usr = dgunix;
  4130.         return(x);
  4131.       }
  4132.       case XYTKBMOD: {                  /* SET TERM KEYBOARD MODE */
  4133.           extern int tt_kb_mode;
  4134.           if ((x = cmkey(kbmodtab,
  4135.                          nkbmodtab,
  4136.                          "normal",
  4137.                          "special keyboard mode for terminal emulation",
  4138.                          xxstring)
  4139.                ) < 0)
  4140.             return(x);
  4141.           if ((y = cmcfm()) < 0) return(y);
  4142.           tt_kb_mode = x;
  4143.           return(success = 1);
  4144.       }
  4145.  
  4146.       case XYTWRP:                      /* SET TERMINAL WRAP */
  4147.         return(seton(&tt_wrap));
  4148.  
  4149.       case XYSCRS:
  4150.         if ((y = cmnum("CONNECT scrollback buffer size, lines","2000",10,&x,
  4151.                        xxstring)) < 0)
  4152.           return(y);
  4153.         /* The max number of lines is the RAM  */
  4154.         /* we can actually dedicate to a       */
  4155.         /* scrollback buffer given the maximum */
  4156.         /* process memory space of 512MB       */
  4157.         if (x < 256 || x > 2000000L) {
  4158.             printf("\n?The size must be between 256 and 2,000,000.\n");
  4159.             return(success = 0);
  4160.         }
  4161.         if ((y = cmcfm()) < 0) return(y);
  4162.         tt_scrsize[VTERM] = x;
  4163.         VscrnInit(VTERM);
  4164.         return(success = 1);
  4165. #endif /* OS2 */
  4166.  
  4167. #ifndef NOCSETS
  4168.       case XYTCS: {                     /* SET TERMINAL CHARACTER-SET */
  4169.         int eol;
  4170.           /* set terminal character-set <remote> <local> */
  4171.         if ((x = cmkey(
  4172. #ifdef CKOUNI
  4173.                        txrtab,ntxrtab,
  4174. #else  /* CKOUNI */
  4175.                        ttcstab,ntermc,
  4176. #endif /* CKOUNI */
  4177.                        "remote terminal character-set","",xxstring)) < 0)
  4178.           return(x);
  4179.  
  4180. #ifdef UNICODE
  4181.         if (x == TX_TRANSP
  4182. #ifdef CKOUNI
  4183.             || x == TX_UTF8
  4184. #endif /* CKOUNI */
  4185.            ) {
  4186.               if ((y = cmcfm()) < 0)    /* Confirm the command */
  4187.                   return(y);
  4188. #ifdef OS2
  4189.             if ( isunicode() && x == TX_TRANSP ) {
  4190.                 /* If we are in unicode display mode then transparent
  4191.                  * only affects the output direction.  We need to know
  4192.                  * the actual remote character set in order to perform
  4193.                  * the tcsr -> ucs2 translation for display.
  4194.                  */
  4195.                 x = y = tcsl;
  4196.             } else
  4197. #endif /* OS2 */
  4198.                 y = x;
  4199.         }
  4200. #else /* UNICODE */
  4201.         if (x == FC_TRANSP) {
  4202.             if ((y = cmcfm()) < 0)      /* Confirm the command */
  4203.                 return(y);
  4204.             y = x;
  4205.         }
  4206. #endif /* UNICODE */
  4207.  
  4208.         /* Not transparent or UTF8, so get local set to translate it into */
  4209.         s = "";
  4210. #ifdef OS2
  4211.         y = os2getcp();                 /* Default is current code page */
  4212.         switch (y) {
  4213.           case 437: s = "cp437"; break;
  4214.           case 850: s = "cp850"; break;
  4215.           case 852: s = "cp852"; break;
  4216.           case 857: s = "cp857"; break;
  4217.           case 858: s = "cp858"; break;
  4218.           case 862: s = "cp862"; break;
  4219.           case 866: s = "cp866"; break;
  4220.           case 869: s = "cp869"; break;
  4221.           case 1250: s = "cp1250"; break;
  4222.           case 1251: s = "cp1251"; break;
  4223.           case 1252: s = "cp1252"; break;
  4224.           case 1253: s = "cp1253"; break;
  4225.           case 1254: s = "cp1254"; break;
  4226.           case 1255: s = "cp1255"; break;
  4227.           case 1256: s = "cp1256"; break;
  4228.           case 1257: s = "cp1257"; break;
  4229.           case 1258: s = "cp1258"; break;
  4230.         }
  4231. #ifdef PCFONTS
  4232. /*
  4233.    If the user has loaded a font with SET TERMINAL FONT then we want
  4234.    to change the default code page to the font that was loaded.
  4235. */
  4236.         if (tt_font != TTF_ROM) {
  4237.             for (y = 0; y < ntermfont; y++ ) {
  4238.                 if (term_font[y].kwval == tt_font) {
  4239.                     s = term_font[y].kwd;
  4240.                     break;
  4241.                 }
  4242.             }
  4243.         }
  4244. #endif /* PCFONTS */
  4245. #else  /* Not K95... */
  4246.         s = fcsinfo[fcharset].keyword;
  4247. #endif /* OS2 */
  4248.  
  4249.         if ((y = cmkey(
  4250. #ifdef CKOUNI
  4251.                        txrtab,ntxrtab,
  4252. #else /* CKOUNI */
  4253.                        ttcstab,ntermc,
  4254. #endif /* CKOUNI */
  4255.                        "local character-set",s,xxstring)) < 0)
  4256.           return(y);
  4257.  
  4258. #ifdef UNICODE
  4259.         if (y == TX_UTF8) {
  4260.             printf("?UTF8 may not be used as a local character set.\r\n");
  4261.             return(-9);
  4262.         }
  4263. #endif /* UNICODE */
  4264. #ifdef OS2
  4265.         if ((z = cmkey(graphsettab,ngraphset,
  4266.                        "DEC VT intermediate graphic set","all",xxstring)) < 0)
  4267.             return(z);
  4268. #endif /* OS2 */
  4269.         if ((eol = cmcfm()) < 0)
  4270.             return(eol); /* Confirm the command */
  4271.  
  4272.         /* End of command parsing - actions begin */
  4273.         setlclcharset(y);
  4274.         setremcharset(x,z);
  4275.         return(success = 1);
  4276.       }
  4277. #endif /* NOCSETS */
  4278.  
  4279. #ifndef NOCSETS
  4280.       case XYTLCS:                      /* SET TERMINAL LOCAL-CHARACTER-SET */
  4281.         /* set terminal character-set <local> */
  4282.         s = getdcset();                 /* Get display character-set name */
  4283.         if ((y = cmkey(
  4284. #ifdef CKOUNI
  4285.                        txrtab,ntxrtab,
  4286. #else /* CKOUNI */
  4287.                        fcstab,nfilc,
  4288. #endif /* CKOUNI */
  4289.                        "local character-set",s,xxstring)) < 0)
  4290.           return(y);
  4291.  
  4292. #ifdef UNICODE
  4293.           if (y == TX_UTF8) {
  4294.               printf("?UTF8 may not be used as a local character set.\r\n");
  4295.               return(-9);
  4296.           }
  4297. #endif /* UNICODE */
  4298.           if ((z = cmcfm()) < 0) return(z); /* Confirm the command */
  4299.  
  4300.           /* End of command parsing - action begins */
  4301.  
  4302.         setlclcharset(y);
  4303.         return(success = 1);
  4304. #endif /* NOCSETS */
  4305.  
  4306. #ifndef NOCSETS
  4307. #ifdef UNICODE
  4308.       case XYTUNI:                      /* SET TERMINAL UNICODE */
  4309.         return(seton(&tt_unicode));
  4310. #endif /* UNICODE */
  4311.  
  4312.       case XYTRCS:                      /* SET TERMINAL REMOTE-CHARACTER-SET */
  4313.         /* set terminal character-set <remote> <Graphic-set> */
  4314.         if ((x = cmkey(
  4315. #ifdef CKOUNI
  4316.                 txrtab, ntxrtab,
  4317. #else /* CKOUNI */
  4318.                 ttcstab,ntermc,
  4319. #endif /* CKOUNI */
  4320.                        "remote terminal character-set","",xxstring)) < 0)
  4321.           return(x);
  4322.  
  4323. #ifdef UNICODE
  4324.         if (x == TX_TRANSP
  4325. #ifdef CKOUNI
  4326.             || x == TX_UTF8
  4327. #endif /* CKOUNI */
  4328.            ) {
  4329.               if ((y = cmcfm()) < 0)    /* Confirm the command */
  4330.                   return(y);
  4331. #ifdef OS2
  4332.             if ( isunicode() && x == TX_TRANSP ) {
  4333.                 /* If we are in unicode display mode then transparent
  4334.                  * only affects the output direction.  We need to know
  4335.                  * the actual remote character set in order to perform
  4336.                  * the tcsr -> ucs2 translation for display.
  4337.                  */
  4338.                 x = tcsl;
  4339.             }
  4340. #endif /* OS2 */
  4341.         }
  4342. #else /* UNICODE */
  4343.         if (x == FC_TRANSP) {
  4344.           if ((y = cmcfm()) < 0)        /* Confirm the command */
  4345.             return(y);
  4346.         }
  4347. #endif /* UNICODE */
  4348.         else {
  4349. #ifdef OS2
  4350.           if ((z = cmkey(graphsettab,ngraphset,
  4351.                       "DEC VT intermediate graphic set","all",xxstring)) < 0)
  4352.             return(z);
  4353. #endif /* OS2 */
  4354.           if ((y = cmcfm()) < 0)        /* Confirm the command */
  4355.             return(y);
  4356.         }
  4357.         /* Command parsing ends here */
  4358.  
  4359.         setremcharset(x,z);
  4360.         return(success = 1);
  4361. #endif /* NOCSETS */
  4362.  
  4363.       case XYTEC:                       /* SET TERMINAL ECHO */
  4364.         if ((x = cmkey(rltab,nrlt,"which side echos during CONNECT",
  4365.                        "remote", xxstring)) < 0) return(x);
  4366.         if ((y = cmcfm()) < 0) return(y);
  4367. #ifdef NETCONN
  4368.         oldplex = x;
  4369. #endif /* NETCONN */
  4370.         duplex = x;
  4371.         return(success = 1);
  4372.  
  4373.       case XYTESC:                      /* SET TERM ESC */
  4374.         if ((x = cmkey(nabltab,nnabltab,"","enabled",xxstring)) < 0)
  4375.           return(x);
  4376.         if ((y = cmcfm()) < 0) return(y);
  4377.         tt_escape = x;
  4378.         return(1);
  4379.  
  4380.       case XYTCRD:                      /* SET TERMINAL CR-DISPLAY */
  4381.         if ((x = cmkey(crdtab,2,"", "normal", xxstring)) < 0) return(x);
  4382.         if ((y = cmcfm()) < 0) return(y);
  4383.         tt_crd = x;
  4384.         return(success = 1);
  4385.  
  4386. #ifdef OS2
  4387.       case XYTANS: {                    /* SET TERMINAL ANSWERBACK */
  4388. /*
  4389.   NOTE: We let them enable and disable the answerback sequence, but we
  4390.   do NOT let them change it, and we definitely do not let the host set it.
  4391.   This is a security feature.
  4392.  
  4393.   As of 1.1.8 we allow the SET TERM ANSWERBACK MESSAGE <string> to be
  4394.   used just as MS-DOS Kermit does.  C0 and C1 controls as well as DEL
  4395.   are not allowed to be used as characters.  They are translated to
  4396.   underscore.  This may not be set by APC.
  4397. */
  4398.           if ((x = cmkey(anbktab,nansbk,"", "off", xxstring)) < 0)
  4399.             return(x);
  4400.           if (x < 2) {
  4401.               if ((y = cmcfm()) < 0)
  4402.                 return(y);
  4403.               tt_answer = x;
  4404.               return(success = 1);
  4405.           } else if ( x == 2 || x == 3) {
  4406.               int len = 0;
  4407.               extern int safeanswerbk;
  4408.               extern char useranswerbk[];
  4409.               if ((y = cmtxt("Answerback extension","",&s,xxstring)) < 0)
  4410.                 return(y);
  4411.               if (apcactive == APC_LOCAL ||
  4412.                   (apcactive == APC_REMOTE && !(apcstatus & APC_UNCH)))
  4413.                 return(success = 0);
  4414.               len = strlen(s);
  4415.               if (x == 2) {
  4416.                   /* Safe Answerback's don't have C0/C1 chars */
  4417.                   for (z = 0; z < len; z++) {
  4418.                       if ((s[z] & 0x7F) <= SP || (s[z] & 0x7F) == DEL)
  4419.                         useranswerbk[z] = '_';
  4420.                       else
  4421.                         useranswerbk[z] = s[z];
  4422.                   }
  4423.                   useranswerbk[z] = '\0';
  4424.                   safeanswerbk = 1 ;    /* TRUE */
  4425.               } else {
  4426.                   ckstrncpy(useranswerbk,s,60); /* (see ckocon.c) */
  4427.                   safeanswerbk = 0;     /* FALSE */
  4428.               }
  4429.               updanswerbk();
  4430.               return(success = 1);
  4431.           } else
  4432.             return(success = 0);
  4433.       }
  4434. #endif /* OS2 */
  4435.  
  4436. #ifdef CK_APC
  4437.       case XYTAPC:
  4438.         if ((y = cmkey(apctab,napctab,
  4439.                        "application program command execution","",
  4440.                        xxstring)) < 0)
  4441.           return(y);
  4442.         if ((x = cmcfm()) < 0)
  4443.           return(x);
  4444.         if (apcactive == APC_LOCAL ||
  4445.             (apcactive == APC_REMOTE && !(apcstatus & APC_UNCH)))
  4446.           return(success = 0);
  4447.         apcstatus = y;
  4448.         return(success = 1);
  4449.  
  4450. #ifdef CK_AUTODL
  4451.       case XYTAUTODL:                   /* AUTODOWNLOAD */
  4452.         if ((y = cmkey(adltab,nadltab,"Auto-download options","",
  4453.                        xxstring)) < 0)
  4454.           return(y);
  4455.         switch (y) {
  4456.           case TAD_ON:
  4457.           case TAD_OFF:
  4458.             if ((x = cmcfm()) < 0)
  4459.               return(x);
  4460.             autodl = y;
  4461.             break;
  4462.           case TAD_ERR:
  4463.             if ((y = cmkey(adlerrtab,nadlerrtab,"","", xxstring)) < 0)
  4464.               return(y);
  4465.             if ((x = cmcfm()) < 0)
  4466.               return(x);
  4467.             adl_err = y;
  4468.             break;
  4469. #ifdef OS2
  4470.           case TAD_K:
  4471.             if ((y = cmkey(adlxtab,nadlxtab,"","", xxstring)) < 0)
  4472.               return(y);
  4473.             switch (y) {
  4474.               case TAD_X_C0:
  4475.                 if ((y = cmkey(adlc0tab,nadlc0tab,"",
  4476.                                "processed-by-emulator",xxstring)) < 0)
  4477.                   return(y);
  4478.                 if ((x = cmcfm()) < 0)
  4479.                   return(x);
  4480.                 adl_kc0 = y;
  4481.                 break;
  4482.               case TAD_X_DETECT:
  4483.                 if ((y = cmkey(adldtab,nadldtab,"","packet",xxstring)) < 0)
  4484.                   return(y);
  4485.                 if ((x = cmcfm()) < 0)
  4486.                   return(x);
  4487.                 adl_kmode = y;
  4488.                 break;
  4489.               case TAD_X_STR:
  4490.                 if ((y = cmtxt("Kermit start string","KERMIT READY TO SEND...",
  4491.                                &s,xxstring)) < 0)
  4492.                   return(y);
  4493.                 free(adl_kstr);
  4494.                 adl_kstr = strdup(s);
  4495.                 break;
  4496.             }
  4497.             break;
  4498.  
  4499.           case TAD_Z:
  4500.             if ((y = cmkey(adlxtab,nadlxtab,"","",xxstring)) < 0)
  4501.               return(y);
  4502.             switch (y) {
  4503.               case TAD_X_C0:
  4504.                 if ((y = cmkey(adlc0tab,nadlc0tab,"",
  4505.                                "processed-by-emulator",xxstring)) < 0)
  4506.                   return(y);
  4507.                 if ((x = cmcfm()) < 0)
  4508.                   return(x);
  4509.                 adl_zc0 = y;
  4510.                 break;
  4511.               case TAD_X_DETECT:
  4512.                 if ((y = cmkey(adldtab,nadldtab,"","packet",xxstring)) < 0)
  4513.                   return(y);
  4514.                 if ((x = cmcfm()) < 0)
  4515.                   return(x);
  4516.                 adl_zmode = y;
  4517.                 break;
  4518.               case TAD_X_STR:
  4519.                 if ((y = cmtxt("","rz\\{13}",&s,xxstring)) < 0)
  4520.                   return(y);
  4521.                 free(adl_zstr);
  4522.                 adl_zstr = strdup(s);
  4523.                 break;
  4524.             }
  4525.             break;
  4526. #endif /* OS2 */
  4527.         }
  4528.         return(success = 1);
  4529.  
  4530. #endif /* CK_AUTODL */
  4531. #endif /* CK_APC */
  4532.  
  4533. #ifdef OS2
  4534.       case XYTBEL:
  4535.         return(success = setbell());
  4536.  
  4537.       case XYTMBEL:                     /* MARGIN-BELL */
  4538.         if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  4539.         if (y) {                        /* ON */
  4540.             if ((z = cmnum("Column at which to set margin bell",
  4541.                            "72",10,&x,xxstring)) < 0)
  4542.               return(z);
  4543.         }
  4544.         if ((z = cmcfm()) < 0) return(z);
  4545.         marginbell = y;
  4546.         marginbellcol = x;
  4547.         return(success = 1);
  4548. #endif /* OS2 */
  4549.  
  4550. #ifdef CKTIDLE
  4551.       case XYTIDLE:                     /* IDLE-SEND */
  4552.       case XYTITMO:                     /* IDLE-TIMEOUT */
  4553.         if ((z = cmnum("seconds of idle time to wait, or 0 to disable",
  4554.                        "0",10,&x,xxstring)) < 0)
  4555.           return(z);
  4556.         if (y == XYTIDLE) {
  4557.             if ((y = cmtxt("string to send, may contain kverbs and variables",
  4558.                            "\\v(newline)",&s,xxstring)) < 0)
  4559.               return(y);
  4560.             tt_idlesnd_tmo = x;         /* (old) */
  4561.             tt_idlelimit = x;           /* (new) */
  4562.             makestr(&tt_idlestr,brstrip(s)); /* (new) */
  4563.             tt_idlesnd_str = tt_idlestr; /* (old) */
  4564.             tt_idleact = IDLE_OUT;      /* (new) */
  4565.         } else {
  4566.             if ((y = cmcfm()) < 0)
  4567.               return(y);
  4568.             tt_idlelimit = x;
  4569.         }
  4570. #ifdef OS2
  4571.         puterror(VTERM);
  4572. #endif /* OS2 */
  4573.         return(success = 1);
  4574.  
  4575.       case XYTIACT: {                   /* SET TERM IDLE-ACTION */
  4576.           if ((y = cmkey(idlacts,nidlacts,"","",xxstring)) < 0)
  4577.             return(y);
  4578.           if (y == IDLE_OUT) {
  4579.               if ((x = cmtxt("string to send, may contain kverbs and variables"
  4580.                              , "\\v(newline)",&s,xxstring)) < 0)
  4581.                 return(x);
  4582.               makestr(&tt_idlestr,brstrip(s)); /* (new) */
  4583.               tt_idlesnd_str = tt_idlestr; /* (old) */
  4584.           } else {
  4585.               if ((x = cmcfm()) < 0)
  4586.                 return(x);
  4587.           }
  4588.           tt_idleact = y;
  4589.           return(success = 1);
  4590.       }
  4591. #endif /* CKTIDLE */
  4592.  
  4593.       case XYTDEB:                      /* TERMINAL DEBUG */
  4594.         x = debses;                     /* What it was before */
  4595.         y = seton(&debses);             /* Go parse ON or OFF */
  4596. #ifdef OS2
  4597.         if (y > 0)                      /* Command succeeded? */
  4598.           if ((x != 0) && (debses == 0)) /* It was on and we turned it off? */
  4599.             os2debugoff();              /* Fix OS/2 coloration */
  4600. #endif /* OS2 */
  4601.         return(y);
  4602.  
  4603. #ifdef OS2
  4604.       case XYTASCRL:                    /* SET TERMINAL AUTOSCROLL */
  4605.           y = seton(&autoscroll);
  4606.           return(y);
  4607.  
  4608.       case XYTAPAGE:                    /* SET TERMINAL AUTOPAGE */
  4609.           y = seton(&wy_autopage);
  4610.           return(y);
  4611.  
  4612.       case XYTROL:                      /* SET TERMINAL ROLL */
  4613.         if ((y = cmkey(rolltab,nroll,"scrollback mode","insert",xxstring))<0)
  4614.             return(y);
  4615.         if ((x = cmcfm()) < 0) return(x);
  4616.         tt_roll[VTERM] = y;
  4617.         return(success = 1);
  4618.  
  4619.       case XYTCTS:                      /* SET TERMINAL TRANSMIT-TIMEOUT */
  4620.         y = cmnum("Maximum seconds to allow CTS off during CONNECT",
  4621.                   "5",10,&x,xxstring);
  4622.         return(setnum(&tt_ctstmo,x,y,10000));
  4623.  
  4624.       case XYTCPG: {                    /* SET TERMINAL CODE-PAGE */
  4625.         int i;
  4626.         int cp = -1;
  4627.         y = cmnum("PC code page to use during terminal emulation",
  4628.                   ckitoa(os2getcp()),10,&x,xxstring);
  4629.         if ((x = setnum(&cp,x,y,11000)) < 0) return(x);
  4630.         if (os2setcp(cp) != 1) {
  4631. #ifdef NT
  4632.             if (isWin95())
  4633.               printf(
  4634.                  "Sorry, Windows 95 does not support code page switching\n");
  4635.             else
  4636. #endif /* NT */
  4637.               printf(
  4638.                  "Sorry, %d is not a valid code page for this system.\n",cp);
  4639.             return(-9);
  4640.         }
  4641.     /* Force the terminal character-sets conversions to be updated */
  4642.         for ( i = 0; i < 4; i++ )
  4643.           G[i].init = TRUE;
  4644.         return(1);
  4645.     }
  4646.  
  4647.       case XYTPAC:                      /* SET TERMINAL OUTPUT-PACING */
  4648.         y = cmnum(
  4649.            "Pause between sending each character during CONNECT, milliseconds",
  4650.                   "-1",10,&x,xxstring);
  4651.         return(setnum(&tt_pacing,x,y,10000));
  4652.  
  4653. #ifdef OS2MOUSE
  4654.       case XYTMOU: {                    /* SET TERMINAL MOUSE */
  4655.           int old_mou = tt_mouse;
  4656.           if ((x = seton(&tt_mouse)) < 0)
  4657.             return(x);
  4658.           if (tt_mouse != old_mou)
  4659.             if (tt_mouse)
  4660.               os2_mouseon();
  4661.             else
  4662.               os2_mouseoff();
  4663.           return(1);
  4664.       }
  4665. #endif /* OS2MOUSE */
  4666. #endif /* OS2 */
  4667.  
  4668.       case XYTWID: {
  4669.           if ((y = cmnum(
  4670. #ifdef OS2
  4671.                          "number of columns in display window during CONNECT",
  4672. #else
  4673.                          "number of columns on your screen",
  4674. #endif /* OS2 */
  4675.                          "80",10,&x,xxstring)) < 0)
  4676.             return(y);
  4677.           if ((y = cmcfm()) < 0) return(y);
  4678. #ifdef OS2
  4679.           return(success = os2_settermwidth(x));
  4680. #else  /* Not OS/2 */
  4681.           tt_cols = x;
  4682.           return(success = 1);
  4683. #endif /* OS2 */
  4684.       }
  4685.  
  4686.       case XYTHIG:
  4687.         if ((y = cmnum(
  4688. #ifdef OS2
  4689.  "number of rows in display window during CONNECT, not including status line",
  4690.  tt_status[VTERM]?"24":"25",
  4691. #else
  4692.  "24","number of rows on your screen",
  4693. #endif /* OS2 */
  4694.                        10,&x,xxstring)) < 0)
  4695.           return(y);
  4696.         if ((y = cmcfm()) < 0) return(y);
  4697.  
  4698. #ifdef OS2
  4699.         return (success = os2_settermheight(x));
  4700. #else  /* Not OS/2 */
  4701.         tt_rows = x;
  4702.         return(success = 1);
  4703. #endif /* OS2 */
  4704.  
  4705. #ifdef OS2
  4706.       case XYTPRN: {                    /* Print Mode */
  4707.           extern bool xprint, cprint, aprint, uprint;
  4708.           if ((y = cmkey(prnmtab,nprnmtab,"","off", xxstring)) < 0) return(y);
  4709.           if ((x = cmcfm()) < 0) return(x);
  4710.           switch (y) {
  4711.             case 0:
  4712.               if (cprint || uprint || aprint || xprint)
  4713.                 printeroff();
  4714.               cprint = xprint = uprint = aprint = 0;
  4715.               break;
  4716.             case 1:
  4717.               if (!(cprint || uprint || aprint || xprint))
  4718.                 printeron();
  4719.               aprint = 1;
  4720.               cprint = xprint = uprint = 0;
  4721.               break;
  4722.             case 2:
  4723.               if (!(cprint || uprint || aprint || xprint))
  4724.                 printeron();
  4725.               cprint = 1;
  4726.               aprint = xprint = uprint = 0;
  4727.               break;
  4728.             case 3:
  4729.               if (!(cprint || uprint || aprint || xprint))
  4730.                 printeron();
  4731.               uprint = 1;
  4732.               aprint = xprint = cprint = 0;
  4733.               break;
  4734.           }
  4735.           return(1);
  4736.       }
  4737. #else
  4738. #ifdef XPRINT
  4739.       case XYTPRN: {
  4740.           extern int tt_print;
  4741.           if ((x = seton(&tt_print)) < 0)
  4742.             return(x);
  4743.           return(success = 1);
  4744.       }
  4745. #endif /* XPRINT */
  4746. #endif /* OS2 */
  4747.  
  4748. #ifdef OS2
  4749.       case XYTSCNM: {
  4750.           extern int decscnm, decscnm_usr;
  4751.           if ((y = cmkey(normrev,4,"",
  4752.                          decscnm_usr?"reverse":"normal",
  4753.                          xxstring)
  4754.                ) < 0)
  4755.             return(y);
  4756.           if ((x = cmcfm()) < 0) return(x);
  4757.           decscnm_usr = y;
  4758.           if (decscnm != decscnm_usr)
  4759.             flipscreen(VTERM);
  4760.           return(1);
  4761.     }
  4762.     case XYTOPTI:
  4763.         if ((y = cmkey(onoff,2,"",tt_diff_upd?"on":"off",
  4764.                         xxstring)) < 0) return(y);
  4765.         if ((x = cmcfm()) < 0) return(x);
  4766.         tt_diff_upd = y;
  4767.         return(1);
  4768.     case XYTUPD: {
  4769.         int mode, delay;
  4770.         if ((mode = cmkey(scrnupd,nscrnupd,"","fast",xxstring)) < 0) {
  4771.             return(mode);
  4772.         } else {
  4773.             y = cmnum(
  4774.             "Pause between FAST screen updates in CONNECT mode, milliseconds",
  4775.                       "100",10,&x,xxstring
  4776.                       );
  4777.             if (x < 0 || x > 1000 ) {
  4778.                 printf(
  4779.             "\n?The update rate must be between 0 and 1000 milliseconds.\n"
  4780.                        );
  4781.                 return(success = 0);
  4782.             }
  4783.             if ((y = cmcfm()) < 0) return(y);
  4784.  
  4785.             updmode = tt_updmode = mode;
  4786.             return(setnum(&tt_update,x,y,10000));
  4787.         }
  4788.     }
  4789.     case XYTCTRL:
  4790.           if ((x = cmkey(termctrl,ntermctrl,"","7",xxstring)) < 0) {
  4791.               return(x);
  4792.           } else {
  4793.               if ((y = cmcfm()) < 0)
  4794.                   return(y);
  4795.               switch ( x ) {
  4796.               case 8:
  4797.                   send_c1 = send_c1_usr = TRUE;
  4798.                   break;
  4799.               case 7:
  4800.               default:
  4801.                   send_c1 = send_c1_usr = FALSE;
  4802.                   break;
  4803.               }
  4804.           }
  4805.           return(success = TRUE);
  4806.           break;
  4807.  
  4808. #ifdef PCFONTS
  4809.       case XYTFON:
  4810.         if ( !IsOS2FullScreen() ) {
  4811.             printf(
  4812.         "\n?SET TERMINAL FONT is only supported in Full Screen sessions.\n");
  4813.             return(success = FALSE);
  4814.         }
  4815.  
  4816.         if ((x = cmkey(term_font,ntermfont,"","default",xxstring)) < 0) {
  4817.             return(x);
  4818.         } else {
  4819.             if ((y = cmcfm()) < 0) return(y);
  4820.             if ( !os2LoadPCFonts() ) {
  4821.                 tt_font = x;
  4822.                 return(success = TRUE);
  4823.             } else {
  4824.                 printf(
  4825.       "\n?PCFONTS.DLL is not available in CKERMIT executable directory.\n");
  4826.                 return(success = FALSE);
  4827.             }
  4828.         }
  4829.         break;
  4830. #else /* PCFONTS */
  4831. #ifdef NT
  4832. #ifdef KUI
  4833.     case XYTFON:
  4834. #ifndef COMMENT
  4835.         return(setguifont());           /* ckuus3.c */
  4836. #else  /* COMMENT */
  4837.         if (ntermfont == 0)
  4838.             BuildFontTable(&term_font, &_term_font, &ntermfont);
  4839.         if (!(term_font && _term_font && ntermfont > 0)) {
  4840.             printf("\nUnable to enumerate fonts.\n");
  4841.             return(-9);
  4842.         }
  4843.         if ((x = cmkey(_term_font,ntermfont,"","",xxstring)) < 0) {
  4844.             return(x);
  4845.         }
  4846.         if ((z = cmnum("Height of Font",
  4847.                         "12",10,&y,xxstring)) < 0)
  4848.               return(z);
  4849.         if ((z = cmcfm()) < 0) return(z);
  4850.         tt_font = x;
  4851.         tt_font_size = y;
  4852.         KuiSetProperty( KUI_TERM_FONT, (long) tt_font, (long) tt_font_size ) ;
  4853.         return(success = TRUE);
  4854. #endif /* COMMENT */
  4855. #endif /* KUI */
  4856. #endif /* NT */
  4857. #endif /* PCFONTS */
  4858.  
  4859.       case XYTVCH: {
  4860.           extern int pheight, marginbot, cmd_rows, cmd_cols;
  4861.           if ((x = cmkey(tvctab,ntvctab,"",isWin95()?"win95-safe":"enabled",
  4862.                          xxstring)) < 0)
  4863.             return(x);
  4864.           if ((y = cmcfm()) < 0) return(y);
  4865.           if (x != tt_modechg) {
  4866.               switch (x) {
  4867.                 case TVC_DIS:
  4868.                   /* When disabled the heights of all of the virtual screens */
  4869.                   /* must be equal to the physical height of the console     */
  4870.                   /* window and may not be changed.                          */
  4871.                   /* The width of the window may not be altered.             */
  4872.                   tt_modechg = TVC_ENA;                 /* Temporary */
  4873.                   if (marginbot > pheight-(tt_status[VTERM]?1:0))
  4874.                     marginbot = pheight-(tt_status[VTERM]?1:0);
  4875.                   tt_szchng[VCMD] = 1 ;
  4876.                   tt_rows[VCMD] = pheight;
  4877.                   VscrnInit(VCMD);
  4878.                   SetCols(VCMD);
  4879.                   cmd_rows = y;
  4880.  
  4881.                   tt_szchng[VTERM] = 2 ;
  4882.                   tt_rows[VTERM] = pheight - (tt_status[VTERM]?1:0);
  4883.                   VscrnInit(VTERM);
  4884.  
  4885.                   break;
  4886.  
  4887.                 case TVC_ENA:
  4888.                   /* When enabled the physical height of the console windows */
  4889.                   /* should be adjusted to the height of the virtual screen  */
  4890.                   /* The width may be set to anything.                       */
  4891.                   /* nothing to do                                           */
  4892.                   break;
  4893.  
  4894.               case TVC_W95:
  4895.                   /* Win95-safe mode allows the physical height to change    */
  4896.                   /* but restricts it to a width of 80 and a height equal to */
  4897.                   /* 25, 43, or 50.  Must be adjusted now.                   */
  4898.                   /* The virtual heights must be equal to the above.         */
  4899.                   if (pheight != 25 && pheight != 43 && pheight != 50) {
  4900.                       if (pheight < 25)
  4901.                         y = 25;
  4902.                       else if (pheight < 43)
  4903.                         y = 43;
  4904.                       else
  4905.                         y = 50;
  4906.                   } else
  4907.                     y = pheight;
  4908.  
  4909.                   tt_modechg = TVC_ENA; /* Temporary */
  4910.  
  4911.                   tt_szchng[VCMD] = 1;
  4912.                   tt_rows[VCMD] = y;
  4913.                   tt_cols[VCMD] = 80;
  4914.                   VscrnInit(VCMD);
  4915.                   SetCols(VCMD);
  4916.                   cmd_rows = y;
  4917.                   cmd_cols = 80;
  4918.  
  4919.                   marginbot = y-(tt_status[VTERM]?1:0);
  4920.                   tt_szchng[VTERM] = 2;
  4921.                   tt_rows[VTERM] = y - (tt_status[VTERM]?1:0);
  4922.                   tt_cols[VTERM] = 80;
  4923.                   VscrnInit(VTERM);
  4924.                   break;
  4925.               }
  4926.               tt_modechg = x;
  4927.           }
  4928.           return(1);
  4929.       }
  4930.       case XYTSTAT: {
  4931.           extern int marginbot;
  4932.           if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  4933.           if ((x = cmcfm()) < 0) return(x);
  4934.           if (y != tt_status[VTERM] || y != tt_status_usr[VTERM]) {
  4935.               /* Might need to fixup the margins */
  4936.               if ( marginbot == VscrnGetHeight(VTERM)-(tt_status[VTERM]?1:0) )
  4937.                 if (y) {
  4938.                     marginbot--;
  4939.                 } else {
  4940.                     marginbot++;
  4941.                 }
  4942.               tt_status_usr[VTERM] = tt_status[VTERM] = y;
  4943.               if (y) {
  4944.                     tt_szchng[VTERM] = 2;
  4945.                     tt_rows[VTERM]--;
  4946.                     VscrnInit(VTERM);  /* Height set here */
  4947. #ifdef TNCODE
  4948.                     if (TELOPT_ME(TELOPT_NAWS))
  4949.                       tn_snaws();
  4950. #endif /* TNCODE */
  4951. #ifdef RLOGCODE
  4952.                     if (TELOPT_ME(TELOPT_NAWS))
  4953.                       rlog_naws();
  4954. #endif /* RLOGCODE */
  4955. #ifdef SSHBUILTIN
  4956.                     if (TELOPT_ME(TELOPT_NAWS))
  4957.                       ssh_snaws();
  4958. #endif /* SSHBUILTIN */
  4959.               } else {
  4960.                   tt_szchng[VTERM] = 1;
  4961.                   tt_rows[VTERM]++;
  4962.                   VscrnInit(VTERM);     /* Height set here */
  4963. #ifdef TNCODE
  4964.                   if (TELOPT_ME(TELOPT_NAWS))
  4965.                     tn_snaws();
  4966. #endif /* TNCODE */
  4967. #ifdef RLOGCODE
  4968.                   if (TELOPT_ME(TELOPT_NAWS))
  4969.                     rlog_naws();
  4970. #endif /* RLOGCODE */
  4971. #ifdef SSHBUILTIN
  4972.                   if (TELOPT_ME(TELOPT_NAWS))
  4973.                     ssh_snaws();
  4974. #endif /* SSHBUILTIN */
  4975.               }
  4976.           }
  4977.           return(1);
  4978.       }
  4979. #endif /* OS2 */
  4980.  
  4981. #ifdef NT
  4982.       case XYTATTBUG:
  4983.         if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  4984.         if ((x = cmcfm()) < 0) return(x);
  4985.         tt_attr_bug = y;
  4986.         return(1);
  4987. #endif /* NT */
  4988.  
  4989. #ifdef OS2
  4990.       case XYTSGRC:
  4991.         if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  4992.         if ((x = cmcfm()) < 0) return(x);
  4993.         sgrcolors = y;
  4994.         return(1);
  4995.  
  4996.       case XYTSEND:
  4997.           if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  4998.           if ((x = cmcfm()) < 0) return(x);
  4999.           tt_senddata = y;
  5000.           return(1);
  5001.  
  5002.       case XYTSEOB:
  5003.           if ((y = cmkey(ttyseobtab,2,"","us_cr",xxstring)) < 0) return(y);
  5004.           if ((x = cmcfm()) < 0) return(x);
  5005.           wy_blockend = y;
  5006.           return(1);
  5007.  
  5008.       case XYTURLHI: {
  5009.           int done = 0, attr = VT_CHAR_ATTR_NORMAL;
  5010.  
  5011.           if ((x = cmkey(onoff,2,"","on",xxstring)) < 0)
  5012.             return(x);
  5013.           if (x) {
  5014.               z = 0;
  5015.               while (!done) {
  5016.                   if ((y = cmkey(ttyprotab,nprotect,"",
  5017.                                  z?"done":"reverse",xxstring)) < 0)
  5018.                     return(y);
  5019.                   switch (y) {
  5020.                     case TTATTDONE:
  5021.                       done = TRUE;
  5022.                       break;
  5023.                     case TTATTBLI:
  5024.                       attr |= VT_CHAR_ATTR_BLINK;
  5025.                       break;
  5026.                     case TTATTREV:
  5027.                       attr |= VT_CHAR_ATTR_REVERSE;
  5028.                       break;
  5029.                     case TTATTUND:
  5030.                       attr |= VT_CHAR_ATTR_UNDERLINE;
  5031.                       break;
  5032.                     case TTATTBLD:
  5033.                       attr |= VT_CHAR_ATTR_BOLD;
  5034.                       break;
  5035.                     case TTATTDIM:
  5036.                       attr |= VT_CHAR_ATTR_DIM;
  5037.                       break;
  5038.                     case TTATTINV:
  5039.                       attr |= VT_CHAR_ATTR_INVISIBLE;
  5040.                       break;
  5041.                     case TTATTNOR:
  5042.                       break;
  5043.                   }
  5044.                   z = 1;                /* One attribute has been chosen */
  5045.               }
  5046.           }
  5047.           if ((z = cmcfm()) < 0) return(z);
  5048.  
  5049.           tt_url_hilite = x;
  5050.           if (x)
  5051.             tt_url_hilite_attr = attr;
  5052.           return(1);
  5053.       }
  5054.       case XYTATTR:
  5055.         if ((x = cmkey(ttyattrtab,nattrib,"","underline",xxstring)) < 0)
  5056.           return(x);
  5057.         switch (x) {
  5058.           case TTATTBLI:
  5059.             if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5060.             if ((x = cmcfm()) < 0) return(x);
  5061.             trueblink = y;
  5062. #ifndef KUI
  5063.             if ( !trueblink && trueunderline ) {
  5064.                 trueunderline = 0;
  5065.                 printf("Warning: Underline being simulated by color.\n");
  5066.             }
  5067.  
  5068. #endif /* KUI */
  5069.             break;
  5070.  
  5071.           case TTATTREV:
  5072.             if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5073.             if ((x = cmcfm()) < 0) return(x);
  5074.             truereverse = y;
  5075.             break;
  5076.  
  5077.           case TTATTUND:
  5078.             if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5079.             if ((x = cmcfm()) < 0) return(x);
  5080.             trueunderline = y;
  5081. #ifndef KUI
  5082.             if (!trueblink && trueunderline) {
  5083.                 trueblink = 1;
  5084.                 printf("Warning: True blink mode is active.\n");
  5085.             }
  5086. #endif /* KUI */
  5087.             break;
  5088.  
  5089.           case TTATTPRO: {      /* Set default Protected Character attribute */
  5090.               extern vtattrib WPattrib;    /* current WP Mode Attrib */
  5091.               extern vtattrib defWPattrib; /* default WP Mode Attrib */
  5092.               vtattrib wpa = {0,0,0,0,0,1,0,0,0};       /* Protected */
  5093.               int done = 0;
  5094.  
  5095.               x = 0;
  5096.               while (!done) {
  5097.                   if ((y = cmkey(ttyprotab,nprotect,"",
  5098.                                  x?"done":"dim",xxstring)) < 0)
  5099.                     return(y);
  5100.                   switch (y) {
  5101.                     case TTATTNOR:
  5102.                       break;
  5103.                     case TTATTBLI:      /* Blinking doesn't work */
  5104.                       wpa.blinking = TRUE;
  5105.                       break;
  5106.                     case TTATTREV:
  5107.                       wpa.reversed = TRUE;
  5108.                       break;
  5109.                     case TTATTUND:
  5110.                       wpa.underlined = TRUE;
  5111.                       break;
  5112.                     case TTATTBLD:
  5113.                       wpa.bold = TRUE;
  5114.                       break;
  5115.                     case TTATTDIM:
  5116.                       wpa.dim = TRUE;
  5117.                       break;
  5118.                     case TTATTINV:
  5119.                       wpa.invisible = TRUE ;
  5120.                       break;
  5121.                     case TTATTDONE:
  5122.                       done = TRUE;
  5123.                       break;
  5124.                   }
  5125.                   x = 1;                /* One attribute has been chosen */
  5126.               }
  5127.               if ((x = cmcfm()) < 0) return(x);
  5128.               WPattrib = defWPattrib = wpa;
  5129.               break;
  5130.           }
  5131.         }
  5132.         return(1);
  5133.  
  5134.       case XYTKEY: {                    /* SET TERMINAL KEY */
  5135.           int t, x, y;
  5136.           int clear = 0, deflt = 0;
  5137.           int confirmed = 0;
  5138.           int flag = 0;
  5139.           int kc = -1;                  /* Key code */
  5140.           int litstr = 0;               /* Literal String? */
  5141.           char *s = NULL;               /* Key binding */
  5142. #ifndef NOKVERBS
  5143.           char *p = NULL;               /* Worker */
  5144. #endif /* NOKVERBS */
  5145.           con_event defevt;
  5146.           extern int os2gks;
  5147.           extern int mskkeys;
  5148.           extern int initvik;
  5149.           struct FDB kw,sw,nu,cm;
  5150.  
  5151.           defevt.type = error;
  5152.  
  5153.           if ((t = cmkey(ttkeytab,nttkey,"","",xxstring)) < 0)
  5154.             return(t);
  5155.           cmfdbi(&nu,                   /* First FDB - command switches */
  5156.                  _CMNUM,                /* fcode */
  5157.                  "/literal, keycode, or action",
  5158.                  "",                    /* default */
  5159.                  "",                    /* addtl string data */
  5160.                  10,                    /* addtl numeric data 1: radix */
  5161.                  0,                     /* addtl numeric data 2: 0 */
  5162.                  xxstring,              /* Processing function */
  5163.                  NULL,                  /* Keyword table */
  5164.                  &sw                    /* Pointer to next FDB */
  5165.                  );                     /*  */
  5166.           cmfdbi(&sw,                   /* Second FDB - switches */
  5167.                  _CMKEY,                /* fcode */
  5168.                  "",
  5169.                  "",                    /* default */
  5170.                  "",                    /* addtl string data */
  5171.                  nstrmswitab,           /* addtl numeric data 1: tbl size */
  5172.                  4,                     /* addtl numeric data 2: 4 = cmswi */
  5173.                  xxstring,              /* Processing function */
  5174.                  strmswitab,            /* Keyword table */
  5175.                  &kw                    /* Pointer to next FDB */
  5176.                  );
  5177.           cmfdbi(&kw,                   /* Third FDB - command switches */
  5178.                  _CMKEY,                /* fcode */
  5179.                  "/literal, keycode, or action",
  5180.                  "",                    /* default */
  5181.                  "",                    /* addtl string data */
  5182.                  nstrmkeytab,           /* addtl numeric data 1: tbl size */
  5183.                  0,                     /* addtl numeric data 2 */
  5184.                  xxstring,              /* Processing function */
  5185.                  strmkeytab,            /* Keyword table */
  5186.                  &cm                    /* Pointer to next FDB */
  5187.                  );
  5188.           cmfdbi(&cm,                   /* Final FDB - Confirmation */
  5189.                  _CMCFM,                /* fcode */
  5190.                  "",
  5191.                  "",                    /* default */
  5192.                  "",                    /* addtl string data */
  5193.                  0,                     /* addtl numeric data 1: tbl size */
  5194.                  0,                     /* addtl numeric data 2: 4 = cmswi */
  5195.                  xxstring,              /* Processing function */
  5196.                  NULL,                  /* Keyword table */
  5197.                  NULL                   /* Pointer to next FDB */
  5198.                  );
  5199.           while (kc < 0) {
  5200.               x = cmfdb(&nu);           /* Parse something */
  5201.               if (x < 0)
  5202.                 return(x);
  5203.  
  5204.               switch (cmresult.fcode) {
  5205.                 case _CMCFM:
  5206.                   printf(" Press key to be defined: ");
  5207.                   conbin((char)escape); /* Put terminal in binary mode */
  5208.                   os2gks = 0;           /* Turn off Kverb preprocessing */
  5209.                   kc = congks(0);       /* Get character or scan code */
  5210.                   os2gks = 1;           /* Turn on Kverb preprocessing */
  5211.                   concb((char)escape);  /* Restore terminal to cbreak mode */
  5212.                   if (kc < 0) {         /* Check for error */
  5213.                       printf("?Error reading key\n");
  5214.                       return(0);
  5215.                   }
  5216.                   shokeycode(kc,t);     /* Show current definition */
  5217.                   flag = 1;             /* Remember it's a multiline command */
  5218.                   break;
  5219.                 case _CMNUM:
  5220.                   kc = cmresult.nresult;
  5221.                   break;
  5222.                 case _CMKEY:
  5223.                   if (cmresult.fdbaddr == &sw) { /* Switch */
  5224.                       if (cmresult.nresult == 0)
  5225.                         litstr = 1;
  5226.                   } else if (cmresult.fdbaddr == &kw) { /* Keyword */
  5227.                       if (cmresult.nresult == 0)
  5228.                         clear = 1;
  5229.                       else
  5230.                         deflt = 1;
  5231.                       if ((x = cmcfm()) < 0)
  5232.                         return(x);
  5233.                       if (clear)
  5234.                         clearkeymap(t);
  5235.                       else if (deflt)
  5236.                         defaultkeymap(t);
  5237.                       initvik = 1;
  5238.                       return(1);
  5239.                   }
  5240.               }
  5241.           }
  5242.  
  5243.     /* Normal SET TERMINAL KEY <terminal> <scancode> <value> command... */
  5244.  
  5245.           if (mskkeys)
  5246.             kc = msktock(kc);
  5247.  
  5248.           if (kc < 0 || kc >= KMSIZE) {
  5249.               printf("?key code must be between 0 and %d\n", KMSIZE - 1);
  5250.               return(-9);
  5251.           }
  5252.           if (kc == escape) {
  5253.               printf("Sorry, %d is the CONNECT-mode escape character\n",kc);
  5254.               return(-9);
  5255.           }
  5256.           wideresult = -1;
  5257.           if (flag) {
  5258.               cmsavp(psave,PROMPTL);
  5259.               cmsetp(" Enter new definition: ");
  5260.               cmini(ckxech);
  5261.           }
  5262.         def_again:
  5263.           if (flag) prompt(NULL);
  5264.           if ((y = cmtxt("key definition,\n\
  5265.  or Ctrl-C to cancel this command,\n\
  5266.  or Enter to restore default definition",
  5267.                          "",&s,NULL)) < 0) {
  5268.               if (flag)                 /* Handle parse errors */
  5269.                 goto def_again;
  5270.               else
  5271.                 return(y);
  5272.           }
  5273.           s = brstrip(s);
  5274. #ifndef NOKVERBS
  5275.           p = s;                        /* Save this place */
  5276. #endif /* NOKVERBS */
  5277. /*
  5278.   If the definition included any \Kverbs, quote the backslash so the \Kverb
  5279.   will still be in the definition when the key is pressed.  We don't do this
  5280.   in zzstring(), because \Kverbs are valid only in this context and nowhere
  5281.   else.
  5282.  
  5283.   We use this code active for all versions that support SET KEY, even if they
  5284.   don't support \Kverbs, because otherwise \K would behave differently for
  5285.   different versions.
  5286. */
  5287.           for (x = 0, y = 0; s[x]; x++, y++) { /* Convert \K to \\K */
  5288.               if ((x > 0) &&
  5289.                   (s[x] == 'K' || s[x] == 'k')
  5290.                   ) {                   /* Have K */
  5291.  
  5292.                   if ((x == 1 && s[x-1] == CMDQ) ||
  5293.                       (x > 1 && s[x-1] == CMDQ && s[x-2] != CMDQ)) {
  5294.                       line[y++] = CMDQ; /* Make it \\K */
  5295.                   }
  5296.                   if (x > 1 && s[x-1] == '{' && s[x-2] == CMDQ) {
  5297.                       line[y-1] = CMDQ; /* Have \{K */
  5298.                       line[y++] = '{';  /* Make it \\{K */
  5299.                   }
  5300.               }
  5301.               line[y] = s[x];
  5302.           }
  5303.           line[y++] = NUL;              /* Terminate */
  5304.           s = line + y + 1;             /* Point to after it */
  5305.           x = LINBUFSIZ - (int) strlen(line) - 1; /* Get remaining space */
  5306.           if ((x < (LINBUFSIZ / 2)) ||
  5307.               (zzstring(line, &s, &x) < 0)) { /* Expand variables, etc. */
  5308.               printf("?Key definition too long\n");
  5309.               if (flag) cmsetp(psave);
  5310.               return(-9);
  5311.           }
  5312.           s = line + y + 1;             /* Point to result. */
  5313.  
  5314. #ifndef NOKVERBS
  5315. /*
  5316.   Special case: see if the definition starts with a \Kverb.
  5317.   If it does, point to it with p, otherwise set p to NULL.
  5318. */
  5319.           p = s;
  5320.           if (*p++ == CMDQ) {
  5321.               if (*p == '{') p++;
  5322.               p = (*p == 'k' || *p == 'K') ? p + 1 : NULL;
  5323.           }
  5324. #endif /* NOKVERBS */
  5325.  
  5326.           switch (strlen(s)) {          /* Action depends on length */
  5327.             case 0:                     /* Clear individual key def */
  5328.               deletekeymap(t,kc);
  5329.               break;
  5330.             case 1:
  5331.               if (!litstr) {
  5332.                   defevt.type = key;    /* Single character */
  5333.                   defevt.key.scancode = *s;
  5334.                   break;
  5335.               }
  5336.             default:                    /* Character string */
  5337. #ifndef NOKVERBS
  5338.               if (p) {
  5339.                   y = xlookup(kverbs,p,nkverbs,&x); /* Look it up */
  5340.                   /* Need exact match */
  5341.                   debug(F101,"set key kverb lookup",0,y);
  5342.                   if (y > -1) {
  5343.                       defevt.type = kverb;
  5344.                       defevt.kverb.id = y;
  5345.                       break;
  5346.                   }
  5347.               }
  5348. #endif /* NOKVERBS */
  5349.               if (litstr) {
  5350.                   defevt.type = literal;
  5351.                   defevt.literal.string = (char *) malloc(strlen(s)+1);
  5352.                   if (defevt.literal.string)
  5353.                     strcpy(defevt.literal.string, s); /* safe */
  5354.               } else {
  5355.                   defevt.type = macro;
  5356.                   defevt.macro.string = (char *) malloc(strlen(s)+1);
  5357.                   if (defevt.macro.string)
  5358.                     strcpy(defevt.macro.string, s); /* safe */
  5359.               }
  5360.               break;
  5361.           }
  5362.           insertkeymap(t, kc, defevt);
  5363.           if (flag)
  5364.             cmsetp(psave);
  5365.           initvik = 1;                  /* Update VIK table */
  5366.           return(1);
  5367.       }
  5368.  
  5369. #ifdef PCTERM
  5370.       case XYTPCTERM:                   /* PCTERM Keyboard Mode */
  5371.         if ((x = seton(&tt_pcterm)) < 0) return(x);
  5372.         return(success = 1);
  5373. #endif /* PCTERM */
  5374. #endif /* OS2 */
  5375.  
  5376. #ifdef CK_TRIGGER
  5377.       case XYTRIGGER:
  5378.         if ((y = cmtxt("String to trigger automatic return to command mode",
  5379.                        "",&s,xxstring)) < 0)
  5380.           return(y);
  5381.         makelist(s,tt_trigger,TRIGGERS);
  5382.         return(1);
  5383. #endif /* CK_TRIGGER */
  5384.  
  5385. #ifdef OS2
  5386.       case XYTSAC:
  5387.         if ((y = cmnum("ASCII value to use for spacing attributes",
  5388.                        "32",10,&x,xxstring)) < 0)
  5389.           return(y);
  5390.         if ((y = cmcfm()) < 0) return(y);
  5391.         tt_sac = x;
  5392.         return(success = 1);
  5393.  
  5394.       case XYTKBDGL: {      /* SET TERM KBD-FOLLOWS-GL/GR */
  5395.           extern int tt_kb_glgr;        /* from ckoco3.c */
  5396.           if ((x = seton(&tt_kb_glgr)) < 0)
  5397.               return(x);
  5398.           return(success = 1);
  5399.       }
  5400. #ifndef NOCSETS
  5401.       case XYTVTLNG:        /* SET TERM DEC-LANGUAGE */
  5402.         if ((y = cmkey(vtlangtab,nvtlangtab,"VT language",
  5403.                        IS97801(tt_type_mode)?"german":"north-american",
  5404.                        xxstring)) < 0)
  5405.           return(y);
  5406.         if ((x = cmcfm()) < 0) return(x);
  5407.  
  5408.         /* A real VT terminal would use the language to set the   */
  5409.         /* default keyboard language for both 8-bit multinational */
  5410.         /* and 7-bit national modes.  For 8-bit mode it would     */
  5411.         /* set the terminal character-set to the ISO set if it    */
  5412.         /* is not already set.                                    */
  5413.         /* Latin-1 can be replaced by DEC Multinational           */
  5414.         switch (y) {
  5415.           case VTL_NORTH_AM:  /* North American */
  5416.             /* Multinational: Latin-1   */
  5417.             /* National:      US_ASCII  */
  5418.             dec_lang = y;
  5419.             dec_nrc = TX_ASCII;
  5420.             dec_kbd = TX_8859_1;
  5421.             break;
  5422.           case VTL_BRITISH :
  5423.             /* Multinational: Latin-1   */
  5424.             /* National:      UK_ASCII  */
  5425.             dec_lang = y;
  5426.             dec_nrc = TX_BRITISH;
  5427.             dec_kbd = TX_8859_1;
  5428.             break;
  5429.           case VTL_FRENCH  :
  5430.           case VTL_BELGIAN :
  5431.           case VTL_CANADIAN:
  5432.             /* Multinational: Latin-1   */
  5433.             /* National:      FR_ASCII  */
  5434.             dec_lang = y;
  5435.             dec_nrc = TX_FRENCH;
  5436.             dec_kbd = TX_8859_1;
  5437.             break;
  5438.           case VTL_FR_CAN  :
  5439.             /* Multinational: Latin-1   */
  5440.             /* National:      FC_ASCII  */
  5441.             dec_lang = y;
  5442.             dec_nrc = TX_CN_FRENCH;
  5443.             dec_kbd = TX_8859_1;
  5444.             break;
  5445.           case VTL_DANISH  :
  5446.           case VTL_NORWEGIA:
  5447.             /* Multinational: Latin-1   */
  5448.             /* National:      NO_ASCII  */
  5449.             dec_lang = y;
  5450.             dec_nrc = TX_NORWEGIAN;
  5451.             dec_kbd = TX_8859_1;
  5452.             break;
  5453.           case VTL_FINNISH :
  5454.             /* Multinational: Latin-1   */
  5455.             /* National:      FI_ASCII  */
  5456.             dec_lang = y;
  5457.             dec_nrc = TX_FINNISH;
  5458.             dec_kbd = TX_8859_1;
  5459.             break;
  5460.           case VTL_GERMAN  :
  5461.             /* Multinational: Latin-1   */
  5462.             /* National:      GR_ASCII  */
  5463.             dec_lang = y;
  5464.             dec_nrc = TX_GERMAN;
  5465.             dec_kbd = TX_8859_1;
  5466.             break;
  5467.           case VTL_DUTCH   :
  5468.             /* Multinational: Latin-1   */
  5469.             /* National:      DU_ASCII  */
  5470.             dec_lang = y;
  5471.             dec_nrc = TX_DUTCH;
  5472.             dec_kbd = TX_8859_1;
  5473.             break;
  5474.           case VTL_ITALIAN :
  5475.             /* Multinational: Latin-1   */
  5476.             /* National:      IT_ASCII  */
  5477.             dec_lang = y;
  5478.             dec_nrc = TX_ITALIAN;
  5479.             dec_kbd = TX_8859_1;
  5480.             break;
  5481.           case VTL_SW_FR   :
  5482.           case VTL_SW_GR   :
  5483.             /* Multinational: Latin-1   */
  5484.             /* National:      CH_ASCII  */
  5485.             dec_lang = y;
  5486.             dec_nrc = TX_SWISS;
  5487.             dec_kbd = TX_8859_1;
  5488.             break;
  5489.           case VTL_SWEDISH :
  5490.             /* Multinational: Latin-1   */
  5491.             /* National:      SW_ASCII  */
  5492.             dec_lang = y;
  5493.             dec_nrc = TX_SWEDISH;
  5494.             dec_kbd = TX_8859_1;
  5495.             break;
  5496.           case VTL_SPANISH :
  5497.             /* Multinational: Latin-1   */
  5498.             /* National:      SP_ASCII  */
  5499.             dec_lang = y;
  5500.             dec_nrc = TX_SPANISH;
  5501.             dec_kbd = TX_8859_1;
  5502.             break;
  5503.           case VTL_PORTUGES:
  5504.             /* Multinational: Latin-1   */
  5505.             /* National:      Portugese ASCII  */
  5506.             dec_lang = y;
  5507.             dec_nrc = TX_PORTUGUESE;
  5508.             dec_kbd = TX_8859_1;
  5509.             break;
  5510.           case VTL_HEBREW  :
  5511.             /* Multinational: Latin-Hebrew / DEC-Hebrew  */
  5512.             /* National:      DEC 7-bit Hebrew  */
  5513.             dec_lang = y;
  5514.             dec_nrc = TX_HE7;
  5515.             dec_kbd = TX_8859_8;
  5516.             break;
  5517.           case VTL_GREEK   :
  5518.             /* Multinational: Latin-Greek / DEC-Greek   */
  5519.             /* National:      DEC Greek NRC             */
  5520.             /* is ELOT927 equivalent to DEC Greek????   */
  5521.             dec_lang = y;
  5522.             dec_nrc = TX_ELOT927;
  5523.             dec_kbd = TX_8859_7;
  5524.             break;
  5525. #ifdef COMMENT
  5526.           case VTL_TURK_Q  :
  5527.           case VTL_TURK_F  :
  5528.             /* Multinational: Latin-Turkish / DEC-Turkish   */
  5529.             /* National:      DEC 7-bit Turkish             */
  5530.             break;
  5531. #endif /* COMMENT */
  5532.           case VTL_HUNGARIA:
  5533.             /* Multinational: Latin-2   */
  5534.             /* National:      no national mode  */
  5535.             dec_lang = y;
  5536.             dec_nrc = TX_HUNGARIAN;
  5537.             dec_kbd = TX_8859_2;
  5538.             break;
  5539.           case VTL_SLOVAK  :
  5540.           case VTL_CZECH   :
  5541.           case VTL_POLISH  :
  5542.           case VTL_ROMANIAN:
  5543.             /* Multinational: Latin-2   */
  5544.             /* National:      no national mode  */
  5545.             dec_lang = y;
  5546.             dec_nrc = TX_ASCII;
  5547.             dec_kbd = TX_8859_2;
  5548.             break;
  5549.           case VTL_RUSSIAN :
  5550.             /* Multinational: Latin-Cyrillic / KOI-8   */
  5551.             /* National:      DEC Russian NRC  */
  5552.             dec_lang = y;
  5553.             dec_nrc = TX_KOI7;
  5554.             dec_kbd = TX_8859_5;
  5555.             break;
  5556.           case VTL_LATIN_AM:
  5557.             /* Multinational: not listed in table   */
  5558.             /* National:      not listed in table  */
  5559.             dec_lang = y;
  5560.             dec_nrc = TX_ASCII;
  5561.             dec_kbd = TX_8859_1;
  5562.             break;
  5563. #ifdef COMMENT
  5564.           case VTL_SCS     :
  5565.             /* Multinational: Latin-2   */
  5566.             /* National:      SCS NRC   */
  5567.             break;
  5568. #endif /* COMMENT */
  5569.           default:
  5570.             return(success = 0);
  5571.         }
  5572.         if (IS97801(tt_type_mode)) {
  5573.             SNI_bitmode(cmask == 0377 ? 8 : 7);
  5574.         }
  5575.         return(success = 1);
  5576. #endif /* NOCSETS */
  5577.  
  5578.       case XYTVTNRC: {                  /* SET TERM DEC-NRC-MODE */
  5579.           extern int decnrcm_usr, decnrcm;        /* from ckoco3.c */
  5580.           if ((x = seton(&decnrcm_usr)) < 0)
  5581.             return(x);
  5582.           decnrcm = decnrcm_usr;
  5583.           return(success = 1);
  5584.       }
  5585.       case XYTSNIPM: {                  /* SET TERM SNI-PAGEMODE */
  5586.           extern int sni_pagemode, sni_pagemode_usr;
  5587.           if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5588.           if ((x = cmcfm()) < 0) return(x);
  5589.           sni_pagemode_usr = sni_pagemode = y;
  5590.           return(success = 1);
  5591.       }
  5592.       case XYTSNISM: {                  /* SET TERM SNI-SCROLLMODE */
  5593.           extern int sni_scroll_mode, sni_scroll_mode_usr;
  5594.           if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5595.           if ((x = cmcfm()) < 0) return(x);
  5596.           sni_scroll_mode_usr = sni_scroll_mode = y;
  5597.           return(success = 1);
  5598.       }
  5599.       case XYTSNICC: {  /* SET TERM SNI-CH.CODE */
  5600.           extern int sni_chcode_usr;
  5601.           if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5602.           if ((x = cmcfm()) < 0) return(x);
  5603.           sni_chcode_usr = y;
  5604.           SNI_chcode(y);
  5605.           return(success = 1);
  5606.       }
  5607.       case XYTSNIFV: {  /* SET TERM SNI-FIRMWARE-VERSIONS */
  5608.           extern CHAR sni_kbd_firmware[], sni_term_firmware[];
  5609.           CHAR kbd[7],term[7];
  5610.  
  5611.           if ((x = cmfld("Keyboard Firmware Version",sni_kbd_firmware,
  5612.                          &s, xxstring)) < 0)
  5613.             return(x);
  5614.           if ((int)strlen(s) != 6) {
  5615.               printf("?Sorry - the firmware version must be 6 digits long\n");
  5616.               return(-9);
  5617.           }
  5618.           for (i = 0; i < 6; i++) {
  5619.               if (!isdigit(s[i])) {
  5620.    printf("?Sorry - the firmware version can only contain digits [0-9]\n");
  5621.                   return(-9);
  5622.               }
  5623.           }
  5624.           ckstrncpy(kbd,s,7);
  5625.  
  5626.           if ((x = cmfld("Terminal Firmware Version",sni_term_firmware,
  5627.                          &s, xxstring)) < 0)
  5628.             return(x);
  5629.           if ((int)strlen(s) != 6) {
  5630.               printf("?Sorry - the firmware version must be 6 digits long\n");
  5631.               return(-9);
  5632.           }
  5633.           for (i = 0; i < 6; i++) {
  5634.               if (!isdigit(s[i])) {
  5635.    printf("?Sorry - the firmware version can only contain digits [0-9]\n");
  5636.                    return(-9);
  5637.               }
  5638.           }
  5639.           ckstrncpy(term,s,7);
  5640.           if ((x = cmcfm()) < 0) return(x);
  5641.  
  5642.           ckstrncpy(sni_kbd_firmware,kbd,7);
  5643.           ckstrncpy(sni_term_firmware,term,7);
  5644.           return(success = 1);
  5645.     }
  5646. #endif /* OS2 */
  5647.  
  5648.       default:                          /* Shouldn't get here. */
  5649.         return(-2);
  5650.     }
  5651. #endif /* MAC */
  5652. #ifdef COMMENT
  5653.     /*
  5654.       This was supposed to shut up picky compilers but instead it makes
  5655.       most compilers complain about "statement not reached".
  5656.     */
  5657.     return(-2);
  5658. #endif /* COMMENT */
  5659. #ifdef OS2
  5660. return(-2);
  5661. #endif /* OS2 */
  5662. }
  5663.  
  5664. #ifdef OS2
  5665. int
  5666. settitle(void) {
  5667.     extern char usertitle[];
  5668.     if ((y = cmtxt("title text","",&s,xxstring)) < 0)
  5669.       return(y);
  5670. #ifdef IKSD
  5671.     if (inserver) {
  5672.         printf("?Sorry, command disabled.\r\n");
  5673.         return(success = 0);
  5674.     }
  5675. #endif /* IKSD */
  5676.  
  5677.     ckstrncpy(usertitle,s,64);
  5678.     os2settitle("",1);
  5679.     return(1);
  5680. }
  5681.  
  5682. static struct keytab dialertab[] = {    /* K95 Dialer types */
  5683.     "backspace",        0, 0,
  5684.     "enter",            1, 0
  5685. };
  5686. static int ndialer = 2;
  5687.  
  5688. int
  5689. setdialer(void) {
  5690.     int t, x, y;
  5691.     int clear = 0, deflt = 0;
  5692.     int kc;                             /* Key code */
  5693.     char *s = NULL;                     /* Key binding */
  5694. #ifndef NOKVERBS
  5695.     char *p = NULL;                     /* Worker */
  5696. #endif /* NOKVERBS */
  5697.     con_event defevt;
  5698.     extern int os2gks;
  5699.     extern int mskkeys;
  5700.     extern int initvik;
  5701.  
  5702.     defevt.type = error;
  5703.  
  5704.     if (( x = cmkey(dialertab, ndialer,
  5705.                     "Kermit-95 dialer work-arounds",
  5706.                     "", xxstring)) < 0 )
  5707.       return(x);
  5708.     switch (x) {
  5709.       case 0:                           /* Backspace */
  5710.         kc = 264;
  5711.         break;
  5712.       case 1:                           /* Enter */
  5713.         kc = 269;
  5714.         break;
  5715.       default:
  5716.         printf("Illegal value in setdialer()\n");
  5717.         return(-9);
  5718.     }
  5719.     if ((y = cmtxt("Key definition","",&s,xxstring)) < 0)
  5720.       return(y);
  5721.  
  5722. #ifdef IKSD
  5723.     if (inserver) {
  5724.         printf("?Sorry, command disabled.\r\n");
  5725.         return(success = 0);
  5726.     }
  5727. #endif /* IKSD */
  5728.     s = brstrip(s);
  5729. #ifndef NOKVERBS
  5730.     p = s;                              /* Save this place */
  5731. #endif /* NOKVERBS */
  5732. /*
  5733.   If the definition included any \Kverbs, quote the backslash so the \Kverb
  5734.   will still be in the definition when the key is pressed.  We don't do this
  5735.   in zzstring(), because \Kverbs are valid only in this context and nowhere
  5736.   else.
  5737.  
  5738.   We use this code active for all versions that support SET KEY, even if they
  5739.   don't support \Kverbs, because otherwise \K would behave differently for
  5740.   different versions.
  5741. */
  5742.     for (x = 0, y = 0; s[x]; x++, y++) { /* Convert \K to \\K */
  5743.         if ((x > 0) &&
  5744.             (s[x] == 'K' || s[x] == 'k')
  5745.             ) {                         /* Have K */
  5746.  
  5747.             if ((x == 1 && s[x-1] == CMDQ) ||
  5748.                 (x > 1 && s[x-1] == CMDQ && s[x-2] != CMDQ)) {
  5749.                 line[y++] = CMDQ;       /* Make it \\K */
  5750.             }
  5751.             if (x > 1 && s[x-1] == '{' && s[x-2] == CMDQ) {
  5752.                 line[y-1] = CMDQ;       /* Have \{K */
  5753.                 line[y++] = '{';        /* Make it \\{K */
  5754.             }
  5755.         }
  5756.         line[y] = s[x];
  5757.     }
  5758.     line[y++] = NUL;                    /* Terminate */
  5759.     s = line + y + 1;                   /* Point to after it */
  5760.     x = LINBUFSIZ - (int) strlen(line) - 1; /* Calculate remaining space */
  5761.     if ((x < (LINBUFSIZ / 2)) ||
  5762.         (zzstring(line, &s, &x) < 0)) { /* Expand variables, etc. */
  5763.         printf("?Key definition too long\n");
  5764.         return(-9);
  5765.     }
  5766.     s = line + y + 1;                   /* Point to result. */
  5767.  
  5768. #ifndef NOKVERBS
  5769. /*
  5770.   Special case: see if the definition starts with a \Kverb.
  5771.   If it does, point to it with p, otherwise set p to NULL.
  5772. */
  5773.     p = s;
  5774.     if (*p++ == CMDQ) {
  5775.         if (*p == '{') p++;
  5776.         p = (*p == 'k' || *p == 'K') ? p + 1 : NULL;
  5777.     }
  5778. #endif /* NOKVERBS */
  5779.  
  5780.     /* Now reprogram the default value for all terminal types */
  5781.     /* remember to treat Wyse and Televideo terminals special */
  5782.     /* because of their use of Kverbs for Backspace and Enter */
  5783.     for (t = 0; t <= TT_MAX; t++) {
  5784.         if ( ISDG200(t) && kc == 264) {
  5785.             extern char * udkfkeys[] ;
  5786.             if (kc == 264) {            /* \Kdgbs */
  5787.                 if (udkfkeys[83])
  5788.                   free(udkfkeys[83]);
  5789.                 udkfkeys[83] = strdup(s);
  5790.             }
  5791.         } else if (ISWYSE(t) || ISTVI(t)) {
  5792.             extern char * udkfkeys[] ;
  5793.             if (kc == 264) {            /* \Kwybs or \Ktvibs */
  5794.                 if (udkfkeys[32])
  5795.                   free(udkfkeys[32]);
  5796.                 udkfkeys[32] = strdup(s);
  5797.             }
  5798.             if (kc == 269) {            /* \Kwyenter and \Kwyreturn */
  5799.                 if (udkfkeys[39])       /* \Ktvienter and \Ktvireturn */
  5800.                   free(udkfkeys[39]);
  5801.                 udkfkeys[39] = strdup(s);
  5802.                 if (udkfkeys[49])
  5803.                   free(udkfkeys[49]);
  5804.                 udkfkeys[49] = strdup(s);
  5805.             }
  5806.         } else {
  5807.             switch (strlen(s)) {        /* Action depends on length */
  5808.               case 0:                   /* Clear individual key def */
  5809.                 deletekeymap(t,kc);
  5810.                 break;
  5811.               case 1:
  5812.                 defevt.type = key;      /* Single character */
  5813.                 defevt.key.scancode = *s;
  5814.                 break;
  5815.               default:                  /* Character string */
  5816. #ifndef NOKVERBS
  5817.                 if (p) {
  5818.                     y = xlookup(kverbs,p,nkverbs,&x); /* Look it up */
  5819.                     /* Exact match req'd */
  5820.                     debug(F101,"set key kverb lookup",0,y);
  5821.                     if (y > -1) {
  5822.                         defevt.type = kverb;
  5823.                         defevt.kverb.id = y;
  5824.                         break;
  5825.                     }
  5826.                 }
  5827. #endif /* NOKVERBS */
  5828.                 defevt.type = macro;
  5829.                 defevt.macro.string = (char *) malloc(strlen(s)+1);
  5830.                 if (defevt.macro.string)
  5831.                   strcpy(defevt.macro.string, s); /* safe */
  5832.                 break;
  5833.             }
  5834.             insertkeymap( t, kc, defevt ) ;
  5835.             initvik = 1;                /* Update VIK table */
  5836.         }
  5837.     }
  5838.     return(1);
  5839. }
  5840. #endif /* OS2 */
  5841.  
  5842. #ifdef NT
  5843. int
  5844. setwin95( void ) {
  5845.     int x, y, z;
  5846.  
  5847.     if (( y = cmkey(win95tab, nwin95,
  5848.                     "Windows 95 specific work-arounds",
  5849.                     "keyboard-translation",
  5850.                     xxstring)) < 0 )
  5851.         return (y);
  5852.     switch (y) {
  5853.       case XYWPOPUP:
  5854.         if ((y = cmkey(onoff,2,"popups are used to prompt the user for data",
  5855.                        "on",xxstring)) < 0)
  5856.           return(y);
  5857.         if ((x = cmcfm()) < 0) return(x);
  5858.         win95_popup = y;
  5859.         return(1);
  5860.  
  5861.       case XYW8_3:
  5862.         if ((y = cmkey(onoff,2,"8.3 FAT file names","off",xxstring)) < 0)
  5863.           return(y);
  5864.         if ((x = cmcfm()) < 0) return(x);
  5865.         win95_8_3 = y;
  5866.         return(1);
  5867.  
  5868.       case XYWSELECT:
  5869.         if ((y = cmkey(onoff,2,"\"select()\" fails on write","off",
  5870.              xxstring)) < 0)
  5871.           return(y);
  5872.         if ((x = cmcfm()) < 0) return(x);
  5873.         win95selectbug = y;
  5874.         return(1);
  5875.  
  5876.       case XYWAGR:
  5877.         if ((y = cmkey(onoff,2,"Right-Alt is Alt-Gr","off",xxstring)) < 0)
  5878.           return(y);
  5879.         if ((x = cmcfm()) < 0) return(x);
  5880.         win95altgr = y;
  5881.         return(1);
  5882.  
  5883.       case XYWOIO:
  5884.         if ((y = cmkey(onoff,2,"Use Overlapped I/O","on",xxstring)) < 0)
  5885.           return(y);
  5886.         if (y) {
  5887.             if ((x = cmnum("Maximum number of outstanding I/O requests",
  5888.                            "10",10,&z,xxstring)) < 0)
  5889.               return(x);
  5890.             if (z < 1 || z > 30) {
  5891.                 printf(
  5892. "?Maximum outstanding I/O requests must be between 1 and 30.\n");
  5893.                 return(-9);
  5894.             }
  5895.         } else
  5896.           z = 1;
  5897.         if ((x = cmcfm()) < 0) return(x);
  5898.         owwait = !y;
  5899.         maxow = maxow_usr = z;
  5900.         return(1);
  5901.  
  5902.       case XYWKEY:
  5903. #ifndef COMMENT
  5904.         printf("\n?\"Keyboard-Translation\" is no longer required.\n");
  5905.         return(-9);
  5906. #else /* COMMENT */
  5907.         if (( z = cmkey(tcstab, ntcs,
  5908.                         "Keyboard Character Set",
  5909.                         "latin1-iso",
  5910.                         xxstring)) < 0)
  5911.           return (z);
  5912.         if ((x = cmcfm()) < 0)
  5913.           return(x);
  5914.  
  5915.         win95kcsi = z;
  5916.         win95kl2 = (win95kcsi == TC_2LATIN);
  5917.  
  5918.         if (win95kcsi == TC_TRANSP) {
  5919.             win95kcs = NULL;
  5920.         } else {
  5921. #ifdef UNICODE
  5922.             win95kcs = xlr[win95kcsi][tx2fc(tcsl)];
  5923. #else /* UNICODE */
  5924.             win95kcs = xlr[win95kcsi][tcsl];
  5925. #endif /* UNICODE */
  5926.         }
  5927.         return(1);
  5928. #endif /* COMMENT */
  5929.  
  5930.       case XYWLUC:
  5931.         if ((y = cmkey(onoff,2,"Unicode-to-Lucida-Console substitutions",
  5932.                        "on",xxstring)) < 0)
  5933.           return(y);
  5934.         if ((x = cmcfm()) < 0) return(x);
  5935.         win95lucida = y;
  5936.         return(1);
  5937.  
  5938.       default:
  5939.         printf("Illegal value in setwin95()\n");
  5940.         return(-9);
  5941.     }
  5942. }
  5943. #endif /* NT */
  5944.  
  5945. #ifdef OS2
  5946. int
  5947. setprty (
  5948. #ifdef CK_ANSIC
  5949.     void
  5950. #endif /* CK_ANSIC */
  5951. /* setprty */ ) {
  5952.     int x, y, z;
  5953.  
  5954.     if (( y = cmkey(prtytab, nprty,
  5955.                     "priority level of terminal and communication threads",
  5956.                     "foreground-server",
  5957.                     xxstring)) < 0 )
  5958.       return (y);
  5959.  
  5960.     if ((x = cmcfm()) < 0)
  5961.       return (x);
  5962. #ifdef IKSD
  5963.     if (inserver &&
  5964. #ifdef IKSDCONF
  5965.          iksdcf
  5966. #else
  5967.          1
  5968. #endif /* IKSDCONF */
  5969.     ) {
  5970.         if ((y = cmcfm()) < 0) return(y);
  5971.         printf("?Sorry, command disabled.\r\n");
  5972.         return(success = 0);
  5973.     }
  5974. #endif /* IKSD */
  5975.     priority = y;
  5976.     return(TRUE);
  5977. }
  5978. #endif /* OS2 */
  5979.  
  5980. int
  5981. setbell() {
  5982.     int y, x;
  5983. #ifdef OS2
  5984.     int z;
  5985. #endif /* OS2 */
  5986.  
  5987.     if ((y = cmkey(beltab,nbeltab,
  5988. #ifdef OS2
  5989.         "how console and terminal bells should\nbe generated", "audible",
  5990. #else
  5991.         "Whether Kermit should ring the terminal bell (beep)", "on",
  5992. #endif /* OS2 */
  5993.                    xxstring)) < 0)
  5994.           return(y);
  5995.  
  5996. #ifdef IKSD
  5997.     if (inserver) {
  5998.         if ((y = cmcfm()) < 0) return(y);
  5999.         printf("?Sorry, command disabled.\r\n");
  6000.         return(success = 0);
  6001.     }
  6002. #endif /* IKSD */
  6003.  
  6004.     switch (y) {                        /* SET BELL */
  6005.       case XYB_NONE:
  6006. #ifdef OS2
  6007.       case XYB_VIS:
  6008. #endif /* OS2 */
  6009.         if ((x = cmcfm()) < 0)
  6010.           return(x);
  6011. #ifdef OS2
  6012.         tt_bell = y;
  6013. #else
  6014.         tt_bell = 0;
  6015. #endif /* OS2 */
  6016.         break;
  6017.  
  6018.       case XYB_AUD:
  6019. #ifdef OS2
  6020.         if ((x = cmkey(audibletab, naudibletab,
  6021.                "how audible console and terminal\nbells should be generated",
  6022.                        "beep",xxstring))<0)
  6023.           return(x);
  6024.         if ((z = cmcfm()) < 0)
  6025.           return(z);
  6026.         tt_bell = y | x;
  6027. #else
  6028.         /* This lets C-Kermit accept but ignore trailing K95 keywords */
  6029.         if ((x = cmtxt("Confirm with carriage return","",&s,xxstring)) < 0)
  6030.           return(x);
  6031.         tt_bell = 1;
  6032. #endif /* OS2 */
  6033.         break;
  6034.     }
  6035.     return(1);
  6036. }
  6037.  
  6038. #ifdef OS2MOUSE
  6039. int
  6040. setmou(
  6041. #ifdef CK_ANSIC
  6042.        void
  6043. #endif /* CK_ANSIC */
  6044.  /* setmou */ ) {
  6045.     extern int initvik;
  6046.     int button = 0, event = 0;
  6047.     char * p;
  6048.  
  6049.     if ((y = cmkey(mousetab,nmtab,"","",xxstring)) < 0)
  6050.       return(y);
  6051.  
  6052. #ifdef IKSD
  6053.     if (inserver) {
  6054.         if ((y = cmcfm()) < 0) return(y);
  6055.         printf("?Sorry, command disabled.\r\n");
  6056.         return(success = 0);
  6057.     }
  6058. #endif /* IKSD */
  6059.  
  6060.     if (y == XYM_ON) {                  /* MOUSE ACTIVATION */
  6061.         int old_mou = tt_mouse;
  6062.         if ((x = seton(&tt_mouse)) < 0)
  6063.             return(x);
  6064.         if (tt_mouse != old_mou)
  6065.           if (tt_mouse)
  6066.             os2_mouseon();
  6067.           else
  6068.             os2_mouseoff();
  6069.         return(1);
  6070.     }
  6071.  
  6072.     if (y == XYM_DEBUG) {               /* MOUSE DEBUG */
  6073.         extern int MouseDebug;
  6074.         if ((x = seton(&MouseDebug)) < 0)
  6075.             return(x);
  6076.         return(1);
  6077.     }
  6078.  
  6079.     if (y == XYM_CLEAR) {               /* Reset Mouse Defaults */
  6080.         if ((x = cmcfm()) < 0) return(x);
  6081.         mousemapinit(-1,-1);
  6082.         initvik = 1;                    /* Update VIK Table */
  6083.         return 1;
  6084.     }
  6085.     if (y != XYM_BUTTON) {              /* Shouldn't happen. */
  6086.         printf("Internal parsing error\n");
  6087.         return(-9);
  6088.     }
  6089.  
  6090.     /* MOUSE EVENT ... */
  6091.  
  6092.     if ((button = cmkey(mousebuttontab,nmbtab,
  6093.                         "Button number","1",
  6094.                         xxstring)) < 0)
  6095.       return(button);
  6096.  
  6097.     if ((y =  cmkey(mousemodtab,nmmtab,
  6098.                     "Keyboard modifier","none",
  6099.                     xxstring)) < 0)
  6100.       return(y);
  6101.  
  6102.     event |= y;                         /* OR in the bits */
  6103.  
  6104.     if ((y =  cmkey(mclicktab,nmctab,"","click",xxstring)) < 0)
  6105.       return(y);
  6106.  
  6107.     /* Two bits are assigned, if neither are set then it is button one */
  6108.  
  6109.     event |= y;                 /* OR in the bit */
  6110.  
  6111.     wideresult = -1;
  6112.  
  6113.     if ((y = cmtxt("definition,\n\
  6114. or Ctrl-C to cancel this command,\n\
  6115. or Enter to restore default definition",
  6116.                    "",&s,NULL)) < 0) {
  6117.         return(y);
  6118.     }
  6119.     s = brstrip(s);
  6120.     p = s;                              /* Save this place */
  6121. /*
  6122.   If the definition included any \Kverbs, quote the backslash so the \Kverb
  6123.   will still be in the definition when the key is pressed.  We don't do this
  6124.   in zzstring(), because \Kverbs are valid only in this context and nowhere
  6125.   else.  This code copied from SET KEY, q.v. for addt'l commentary.
  6126. */
  6127.     for (x = 0, y = 0; s[x]; x++, y++) { /* Convert \K to \\K */
  6128.         if ((x > 0) &&
  6129.             (s[x] == 'K' || s[x] == 'k')
  6130.             ) {                         /* Have K */
  6131.  
  6132.             if ((x == 1 && s[x-1] == CMDQ) ||
  6133.                 (x > 1 && s[x-1] == CMDQ && s[x-2] != CMDQ)) {
  6134.                 line[y++] = CMDQ;       /* Make it \\K */
  6135.             }
  6136.             if (x > 1 && s[x-1] == '{' && s[x-2] == CMDQ) {
  6137.                 line[y-1] = CMDQ;       /* Have \{K */
  6138.                 line[y++] = '{';        /* Make it \\{K */
  6139.             }
  6140.         }
  6141.         line[y] = s[x];
  6142.     }
  6143.     line[y++] = NUL;                    /* Terminate */
  6144.     s = line + y + 1;                   /* Point to after it */
  6145.     x = LINBUFSIZ - (int) strlen(line) - 1; /* Calculate remaining space */
  6146.     if ((x < (LINBUFSIZ / 2)) ||
  6147.         (zzstring(line, &s, &x) < 0)) { /* Expand variables, etc. */
  6148.         printf("?Key definition too long\n");
  6149.         return(-9);
  6150.     }
  6151.     s = line + y + 1;                   /* Point to result. */
  6152.  
  6153. #ifndef NOKVERBS
  6154. /*
  6155.   Special case: see if the definition starts with a \Kverb.
  6156.   If it does, point to it with p, otherwise set p to NULL.
  6157. */
  6158.     p = s;
  6159.     if (*p++ == CMDQ) {
  6160.         if (*p == '{') p++;
  6161.         p = (*p == 'k' || *p == 'K') ? p + 1 : NULL;
  6162.     }
  6163. #else
  6164.     p = NULL;
  6165. #endif /* NOKVERBS */
  6166.  
  6167.     /* free the old definition if necessary */
  6168.     if (mousemap[button][event].type == macro) {
  6169.         free( mousemap[button][event].macro.string);
  6170.         mousemap[button][event].macro.string = NULL;
  6171.     }
  6172.     switch (strlen(s)) {                /* Action depends on length */
  6173.       case 0:                           /* Reset to default binding */
  6174.         mousemapinit( button, event );
  6175.         break;
  6176.       case 1:                           /* Single character */
  6177.             mousemap[button][event].type = key;
  6178.         mousemap[button][event].key.scancode = *s;
  6179.         break;
  6180.       default:                          /* Character string */
  6181. #ifndef NOKVERBS
  6182.         if (p) {
  6183.             y = xlookup(kverbs,p,nkverbs,&x); /* Look it up */
  6184.             debug(F101,"set mouse kverb lookup",0,y); /* need exact match */
  6185.             if (y > -1) {
  6186.             /* Assign the kverb to the event */
  6187.             mousemap[button][event].type = kverb;
  6188.             mousemap[button][event].kverb.id = F_KVERB | y;
  6189.             break;
  6190.             }
  6191.         }
  6192. #endif /* NOKVERBS */
  6193.  
  6194.        /* Otherwise, it's a macro, so assign the macro to the event */
  6195.        mousemap[button][event].type = macro;
  6196.        mousemap[button][event].macro.string = (MACRO) malloc(strlen(s)+1);
  6197.        if (mousemap[button][event].macro.string)
  6198.          strcpy((char *) mousemap[button][event].macro.string, s); /* safe */
  6199.         break;
  6200.     }
  6201.     initvik = 1;                        /* Update VIK Table */
  6202.     if ( (button == XYM_B3) && (mousebuttoncount() < 3) && !quiet )
  6203.     {
  6204.         printf("?Warning: this machine does not have a three button mouse.\n");
  6205.         return(0);
  6206.     }
  6207.     return(1);
  6208. }
  6209. #endif /* OS2MOUSE */
  6210. #endif /* NOLOCAL */
  6211.  
  6212. #ifndef NOXFER
  6213. int                                     /* SET SEND/RECEIVE */
  6214. setsr(xx, rmsflg) int xx; int rmsflg; {
  6215.     if (xx == XYRECV)
  6216.       ckstrncpy(line,"Parameter for inbound packets",LINBUFSIZ);
  6217.     else
  6218.       ckstrncpy(line,"Parameter for outbound packets",LINBUFSIZ);
  6219.  
  6220.     if (rmsflg) {
  6221.         if ((y = cmkey(rsrtab,nrsrtab,line,"",xxstring)) < 0) {
  6222.             if (y == -3) {
  6223.                 printf("?Remote receive parameter required\n");
  6224.                 return(-9);
  6225.             } else return(y);
  6226.         }
  6227.     } else {
  6228.         if ((y = cmkey(srtab,nsrtab,line,"",xxstring)) < 0) return(y);
  6229.     }
  6230.     switch (y) {
  6231.       case XYQCTL:                      /* CONTROL-PREFIX */
  6232.         if ((x = cmnum("ASCII value of control prefix","",10,&y,xxstring)) < 0)
  6233.           return(x);
  6234.         if ((x = cmcfm()) < 0) return(x);
  6235.         if ((y > 32 && y < 63) || (y > 95 && y < 127)) {
  6236.             if (xx == XYRECV)
  6237.               ctlq = (CHAR) y;          /* RECEIVE prefix, use with caution! */
  6238.             else
  6239.               myctlq = (CHAR) y;        /* SEND prefix, OK to change */
  6240.             return(success = 1);
  6241.         } else {
  6242.             printf("?Illegal value for prefix character\n");
  6243.             return(-9);
  6244.         }
  6245.  
  6246.       case XYEOL:
  6247.         if ((y = setcc("13",&z)) < 0)
  6248.             return(y);
  6249.         if (z > 31) {
  6250.             printf("Sorry, the legal values are 0-31\n");
  6251.             return(-9);
  6252.         }
  6253.         if (xx == XYRECV)
  6254.           eol = (CHAR) z;
  6255.         else
  6256.           seol = (CHAR) z;
  6257.         return(success = y);
  6258.  
  6259.       case XYLEN:
  6260.         y = cmnum("Maximum number of characters in a packet","90",10,&x,
  6261.                   xxstring);
  6262.         if (xx == XYRECV) {             /* Receive... */
  6263.             if ((y = setnum(&z,x,y,maxrps)) < 0)
  6264.               return(y);
  6265.             if (protocol != PROTO_K) {
  6266.                 printf("?Sorry, this command does not apply to %s protocol.\n",
  6267.                        ptab[protocol].p_name
  6268.                        );
  6269.                 printf("Use SET SEND PACKET-LENGTH for XYZMODEM\n");
  6270.                 return(-9);
  6271.             }
  6272.             if (z < 10) {
  6273.                 printf("Sorry, 10 is the minimum\n");
  6274.                 return(-9);
  6275.             }
  6276.             if (rmsflg) {
  6277.                 sstate = setgen('S', "401", ckitoa(z), "");
  6278.                 return((int) sstate);
  6279.             } else {
  6280.                 if (protocol == PROTO_K) {
  6281.                     if (z > MAXRP) z = MAXRP;
  6282.                     y = adjpkl(z,wslotr,bigrbsiz);
  6283.                     if (y != z) {
  6284.                         urpsiz = y;
  6285.                         if (!xcmdsrc)
  6286.                           if (msgflg) printf(
  6287. " Adjusting receive packet-length to %d for %d window slots\n",
  6288.                                              y, wslotr);
  6289.                     }
  6290.                     urpsiz = y;
  6291.                     ptab[protocol].rpktlen = urpsiz;
  6292.                     rpsiz =  (y > 94) ? 94 : y;
  6293.                 } else {
  6294. #ifdef CK_XYZ
  6295.                     if ((protocol == PROTO_X || protocol == PROTO_XC) &&
  6296.                          z != 128 && z != 1024) {
  6297.                         printf("Sorry, bad packet length for XMODEM.\n");
  6298.                         printf("Please use 128 or 1024.\n");
  6299.                         return(-9);
  6300.                     }
  6301. #endif /* CK_XYZ */
  6302.                     urpsiz = rpsiz = z;
  6303.                 }
  6304.             }
  6305.         } else {                        /* Send... */
  6306.             if ((y = setnum(&z,x,y,maxsps)) < 0)
  6307.               return(y);
  6308.             if (z < 10) {
  6309.                 printf("Sorry, 10 is the minimum\n");
  6310.                 return(-9);
  6311.             }
  6312.             if (protocol == PROTO_K) {
  6313.                 if (z > MAXSP) z = MAXSP;
  6314.                 spsiz = z;              /* Set it */
  6315.                 y = adjpkl(spsiz,wslotr,bigsbsiz);
  6316.                 if (y != spsiz && !xcmdsrc)
  6317.                   if (msgflg)
  6318.                     printf("Adjusting packet size to %d for %d window slots\n",
  6319.                            y,wslotr);
  6320.             } else
  6321.               y = z;
  6322. #ifdef CK_XYZ
  6323.             if ((protocol == PROTO_X || protocol == PROTO_XC) &&
  6324.                  z != 128 && z != 1024) {
  6325.                 printf("Sorry, bad packet length for XMODEM.\n");
  6326.                 printf("Please use 128 or 1024.\n");
  6327.                 return(-9);
  6328.             }
  6329. #endif /* CK_XYZ */
  6330.             spsiz = spmax = spsizr = y; /* Set it and flag that it was set */
  6331.             spsizf = 1;                 /* to allow overriding Send-Init. */
  6332.             ptab[protocol].spktflg = spsizf;
  6333.             ptab[protocol].spktlen = spsiz;
  6334.         }
  6335.         if (pflag && protocol == PROTO_K && !xcmdsrc) {
  6336.             if (z > 94 && !reliable && msgflg) {
  6337.                 /* printf("Extended-length packets requested.\n"); */
  6338.                 if (bctr < 2 && z > 200) printf("\
  6339. Remember to SET BLOCK 2 or 3 for long packets.\n");
  6340.             }
  6341.             if (speed <= 0L) speed = ttgspd();
  6342. #ifdef COMMENT
  6343. /*
  6344.   Kermit does this now itself.
  6345. */
  6346.             if (speed <= 0L && z > 200 && msgflg) {
  6347.                 printf("\
  6348. Make sure your timeout interval is long enough for %d-byte packets.\n",z);
  6349.             }
  6350. #endif /* COMMENT */
  6351.         }
  6352.         return(success = y);
  6353.  
  6354.       case XYMARK:
  6355. #ifdef DOOMSDAY
  6356. /*
  6357.   Printable start-of-packet works for UNIX and VMS only!
  6358. */
  6359.         x_ifnum = 1;
  6360.         y = cmnum("Code for packet-start character","1",10,&x,xxstring);
  6361.         x_ifnum = 0;
  6362.         if ((y = setnum(&z,x,y,126)) < 0) return(y);
  6363. #else
  6364.         if ((y = setcc("1",&z)) < 0)
  6365.             return(y);
  6366. #endif /* DOOMSDAY */
  6367.         if (xx == XYRECV)
  6368.           stchr = (CHAR) z;
  6369.         else {
  6370.             mystch = (CHAR) z;
  6371. #ifdef IKS_OPTION
  6372.             /* If IKS negotiation in use   */
  6373.             if (TELOPT_U(TELOPT_KERMIT) || TELOPT_ME(TELOPT_KERMIT))
  6374.               tn_siks(KERMIT_SOP);      /* Report change to other side */
  6375. #endif /* IKS_OPTION */
  6376.         }
  6377.         return(success = y);
  6378.  
  6379.       case XYNPAD:                      /* PADDING */
  6380.         y = cmnum("How many padding characters for inbound packets","0",10,&x,
  6381.                   xxstring);
  6382.         if ((y = setnum(&z,x,y,94)) < 0) return(y);
  6383.         if (xx == XYRECV)
  6384.           mypadn = (CHAR) z;
  6385.         else
  6386.           npad = (CHAR) z;
  6387.         return(success = y);
  6388.  
  6389.       case XYPADC:                      /* PAD-CHARACTER */
  6390.         if ((y = setcc("0",&z)) < 0) return(y);
  6391.         if (xx == XYRECV) mypadc = z; else padch = z;
  6392.         return(success = y);
  6393.  
  6394.       case XYTIMO:                      /* TIMEOUT */
  6395.         if (xx == XYRECV) {
  6396.             y = cmnum("Packet timeout interval",ckitoa(URTIME),10,&x,xxstring);
  6397.             if ((y = setnum(&z,x,y,94)) < 0) return(y);
  6398.  
  6399.             if (rmsflg) {               /* REMOTE SET RECEIVE TIMEOUT */
  6400.                 sstate = setgen('S', "402", ckitoa(z), "");
  6401.                 return((int) sstate);
  6402.             } else {                    /* SET RECEIVE TIMEOUT */
  6403.                 pkttim = z;             /*   Value to put in my negotiation */
  6404.             }                           /*   packet for other Kermit to use */
  6405.  
  6406.         } else {                        /* SET SEND TIMEOUT */
  6407. #ifdef CK_TIMERS
  6408.             extern int rttflg, mintime, maxtime;
  6409.             int tmin = 0, tmax = 0;
  6410. #endif /* CK_TIMERS */
  6411.             y = cmnum("Packet timeout interval",ckitoa(DMYTIM),10,&x,xxstring);
  6412.             if (y == -3) {              /* They cancelled a previous */
  6413.                 x = DMYTIM;             /* SET SEND command, so restore */
  6414.                 timef = 0;              /* and turn off the override flag */
  6415.                 y = cmcfm();
  6416.             }
  6417. #ifdef CK_TIMERS
  6418.             if (y < 0) return(y);
  6419.             if (x < 0) {
  6420.                 printf("?Out of range - %d\n",x);
  6421.                 return(-9);
  6422.             }
  6423.             if ((z = cmkey(timotab,2,"","dynamic",xxstring)) < 0) return(z);
  6424.             if (z) {
  6425.                 if ((y = cmnum("Minimum timeout to allow",
  6426.                                "1",10,&tmin,xxstring)) < 0)
  6427.                   return(y);
  6428.                 if (tmin < 1) {
  6429.                     printf("?Out of range - %d\n",tmin);
  6430.                     return(-9);
  6431.                 }
  6432.                 if ((y = cmnum("Maximum timeout to allow",
  6433.                                "0",10,&tmax,xxstring)) < 0)
  6434.                   return(y);
  6435.                 /* 0 means let Kermit choose, < 0 means no maximum */
  6436.             }
  6437.             if ((y = cmcfm()) < 0)
  6438.               return(y);
  6439.             rttflg = z;                 /* Round-trip timer flag */
  6440.             z = x;
  6441. #else
  6442.             if ((y = setnum(&z,x,y,94)) < 0)
  6443.               return(y);
  6444. #endif /* CK_TIMERS */
  6445.             timef = 1;                  /* Turn on the override flag */
  6446.             timint = rtimo = z;         /* Override value for me to use */
  6447. #ifdef CK_TIMERS
  6448.             if (rttflg) {               /* Lower and upper bounds */
  6449.                 mintime = tmin;
  6450.                 maxtime = tmax;
  6451.             }
  6452. #endif /* CK_TIMERS */
  6453.         }
  6454.         return(success = 1);
  6455.  
  6456.       case XYFPATH:                     /* PATHNAMES */
  6457.         if (xx == XYRECV) {
  6458.             y = cmkey(rpathtab,nrpathtab,"","auto",xxstring);
  6459.         } else {
  6460.             y = cmkey(pathtab,npathtab,"","off",xxstring);
  6461.         }
  6462.         if (y < 0) return(y);
  6463.  
  6464.         if ((x = cmcfm()) < 0) return(x);
  6465.         if (xx == XYRECV) {             /* SET RECEIVE PATHNAMES */
  6466.             fnrpath = y;
  6467.             ptab[protocol].fnrp = fnrpath;
  6468.         } else {                        /* SET SEND PATHNAMES */
  6469.             fnspath = y;
  6470.             ptab[protocol].fnsp = fnspath;
  6471.         }
  6472.         return(success = 1);            /* Note: 0 = ON, 1 = OFF */
  6473.         /* In other words, ON = leave pathnames ON, OFF = take them off. */
  6474.  
  6475.       case XYPAUS:                      /* SET SEND/RECEIVE PAUSE */
  6476.         y = cmnum("Milliseconds to pause between packets","0",10,&x,xxstring);
  6477.         if ((y = setnum(&z,x,y,15000)) < 0)
  6478.           return(y);
  6479.         pktpaus = z;
  6480.         return(success = 1);
  6481.  
  6482. #ifdef CKXXCHAR                         /* SET SEND/RECEIVE IGNORE/DOUBLE */
  6483.       case XYIGN:
  6484.       case XYDBL: {
  6485.           int i, zz;
  6486.           short *p;
  6487.           extern short dblt[];
  6488.           extern int dblflag, ignflag;
  6489.  
  6490.           /* Make space for a temporary copy of the ignore/double table */
  6491.  
  6492.           zz = y;
  6493. #ifdef COMMENT
  6494.           if (zz == XYIGN && xx == XYSEND) {
  6495.               blah blah who cares
  6496.           }
  6497.           if (zz == XYDBL && xx == XYRECV) {
  6498.               blah blah
  6499.           }
  6500. #endif /* COMMENT */
  6501.           p = (short *)malloc(256 * sizeof(short));
  6502.           if (!p) {
  6503.               printf("?Internal error - malloc failure\n");
  6504.               return(-9);
  6505.           }
  6506.           for (i = 0; i < 256; i++) p[i] = dblt[i]; /* Copy current table */
  6507.  
  6508.           while (1) {                   /* Collect a list of numbers */
  6509. #ifndef NOSPL
  6510.               x_ifnum = 1;              /* Turn off complaints from eval() */
  6511. #endif /* NOSPL */
  6512.               if ((x = cmnum(zz == XYDBL ?
  6513.                              "Character to double" :
  6514.                              "Character to ignore",
  6515.                              "",10,&y,xxstring
  6516.                              )) < 0) {
  6517. #ifndef NOSPL
  6518.                   x_ifnum = 0;
  6519. #endif /* NOSPL */
  6520.                   if (x == -3)          /* Done */
  6521.                     break;
  6522.                   if (x == -2) {
  6523.                       if (p) { free(p); p = NULL; }
  6524.                       debug(F110,"SET S/R DOUBLE/IGNORE atmbuf",atmbuf,0);
  6525.                       if (!ckstrcmp(atmbuf,"none",4,0) ||
  6526.                           !ckstrcmp(atmbuf,"non",3,0) ||
  6527.                           !ckstrcmp(atmbuf,"no",2,0) ||
  6528.                           !ckstrcmp(atmbuf,"n",1,0)) {
  6529.                           if ((x = cmcfm()) < 0) /* Get confirmation */
  6530.                             return(x);
  6531.                           for (y = 0; y < 256; y++)
  6532.                             dblt[y] &= (zz == XYDBL) ? 1 : 2;
  6533.                           if (zz == XYDBL) dblflag = 0;
  6534.                           if (zz == XYIGN) ignflag = 0;
  6535.                           return(success = 1);
  6536.                       } else {
  6537.                           printf(
  6538.                             "?Please specify a number or the word NONE\n");
  6539.                           return(-9);
  6540.                       }
  6541.                   } else {
  6542.                       free(p);
  6543.                       p = NULL;
  6544.                       return(x);
  6545.                   }
  6546.               }
  6547. #ifndef NOSPL
  6548.               x_ifnum = 0;
  6549. #endif /* NOSPL */
  6550.               if (y < 0 || y > 255) {
  6551.                   printf("?Please enter a character code in range 0-255\n");
  6552.                   free(p);
  6553.                   p = NULL;
  6554.                   return(-9);
  6555.               }
  6556.               p[y] |= (zz == XYDBL) ? 2 : 1;
  6557.               if (zz == XYDBL) dblflag = 1;
  6558.               if (zz == XYIGN) ignflag = 1;
  6559.           } /* End of while loop */
  6560.  
  6561.           if ((x = cmcfm()) < 0) return(x);
  6562. /*
  6563.   Get here only if they have made no mistakes.  Copy temporary table back to
  6564.   permanent one, then free temporary table and return successfully.
  6565. */
  6566.           if (p) {
  6567.               for (i = 0; i < 256; i++) dblt[i] = p[i];
  6568.               free(p);
  6569.               p = NULL;
  6570.           }
  6571.           return(success = 1);
  6572.       }
  6573. #endif /* CKXXCHAR */
  6574.  
  6575. #ifdef PIPESEND
  6576.       case XYFLTR: {                    /* SET { SEND, RECEIVE } FILTER */
  6577.           if ((y = cmtxt((xx == XYSEND) ?
  6578.                 "Filter program for sending files -\n\
  6579.  use \\v(filename) to substitute filename" :
  6580.                 "Filter program for receiving files -\n\
  6581.  use \\v(filename) to substitute filename",
  6582.                          "",&s,NULL)) < 0)
  6583.             return(y);
  6584.           if (!*s) {                    /* Removing a filter... */
  6585.               if (xx == XYSEND && sndfilter) {
  6586.                   makestr(&g_sfilter,NULL);
  6587.                   makestr(&sndfilter,NULL);
  6588.               } else if (rcvfilter) {
  6589.                   makestr(&g_rfilter,NULL);
  6590.                   makestr(&rcvfilter,NULL);
  6591.               }
  6592.               return(success = 1);
  6593.           }                             /* Adding a filter... */
  6594.           s = brstrip(s);               /* Strip any braces */
  6595.           y = strlen(s);
  6596.           if (xx == XYSEND) {           /* For SEND filter... */
  6597.               for (x = 0; x < y; x++) { /* make sure they included "\v(...)" */
  6598.                   if (s[x] != '\\') continue;
  6599.                   if (s[x+1] == 'v') break;
  6600.               }
  6601.               if (x == y) {
  6602.                   printf(
  6603.               "?Filter must contain a replacement variable for filename.\n"
  6604.                          );
  6605.                   return(-9);
  6606.               }
  6607.           }
  6608.           if (xx == XYSEND) {
  6609.               makestr(&sndfilter,s);
  6610.               makestr(&g_sfilter,s);
  6611.           } else {
  6612.               makestr(&rcvfilter,s);
  6613.               makestr(&g_rfilter,s);
  6614.           }
  6615.           return(success = 1);
  6616.       }
  6617. #endif /* PIPESEND */
  6618.  
  6619.       case XYINIL:
  6620.         y = cmnum("Max length for protocol init string","-1",10,&x,xxstring);
  6621.         if ((y = setnum(&z,x,y,-1)) < 0)
  6622.           return(y);
  6623.         if (xx == XYSEND)
  6624.           sprmlen = z;
  6625.         else
  6626.           rprmlen = z;
  6627.         return(success = 1);
  6628.  
  6629.       case 993: {
  6630.           extern int sendipkts;
  6631.           if (xx == XYSEND) {
  6632.               if ((x = seton(&sendipkts)) < 0)
  6633.                 return(x);
  6634.           }
  6635.           return(1);
  6636.       }
  6637.  
  6638. #ifndef NOCSETS
  6639.       case XYCSET: {                    /* CHARACTER-SET-SELECTION */
  6640.           extern struct keytab xfrmtab[];
  6641.           extern int r_cset, s_cset;
  6642.           if ((y = cmkey(xfrmtab,2,"","automatic",xxstring)) < 0)
  6643.             return(y);
  6644.           if ((x = cmcfm()) < 0)
  6645.             return(x);
  6646.           if (xx == XYSEND)
  6647.             s_cset = y;
  6648.           else
  6649.             r_cset = y;
  6650.           return(success = 1);
  6651.       }
  6652. #endif /* NOCSETS */
  6653.  
  6654.       case XYBUP:
  6655.         if ((y = cmkey(onoff,2,"","on",xxstring)) < 0)
  6656.           return(y);
  6657.         if ((x = cmcfm()) < 0) return(x);
  6658.         if (xx == XYSEND) {
  6659.             extern int skipbup;
  6660.             skipbup = (y == 0) ? 1 : 0;
  6661.             return(success = 1);
  6662.         } else {
  6663.             printf(
  6664. "?Please use SET FILE COLLISION to choose the desired action\n");
  6665.             return(-9);
  6666.         }
  6667.  
  6668.       case XYMOVE:
  6669.         y = cmdir("Directory to move file(s) to after successful transfer",
  6670.                   "",&s,xxstring);
  6671.         if (y < 0 && y != -3)
  6672.           return(y);
  6673.         ckstrncpy(line,s,LINBUFSIZ);
  6674.         s = brstrip(line);
  6675.         if ((x = cmcfm()) < 0)
  6676.           return(x);
  6677.         if (xx == XYSEND) {
  6678.             if (*s) {
  6679.                 makestr(&snd_move,s);
  6680.                 makestr(&g_snd_move,s);
  6681.             } else {
  6682.                 makestr(&snd_move,NULL);
  6683.                 makestr(&g_snd_move,NULL);
  6684.             }
  6685.         } else {
  6686.             if (*s) {
  6687.                 makestr(&rcv_move,s);
  6688.                 makestr(&g_rcv_move,s);
  6689.             } else {
  6690.                 makestr(&rcv_move,NULL);
  6691.                 makestr(&g_rcv_move,NULL);
  6692.             }
  6693.         }
  6694.         return(success = 1);
  6695.  
  6696.       case XYRENAME:
  6697.         y = cmdir("Template to rename file(s) to after successful transfer",
  6698.                   "",&s,NULL);
  6699.         if (y < 0 && y != -3)
  6700.           return(y);
  6701.         ckstrncpy(line,s,LINBUFSIZ);
  6702.         s = brstrip(line);
  6703.         if ((x = cmcfm()) < 0)
  6704.           return(x);
  6705.         if (xx == XYSEND) {
  6706.             if (*s) {
  6707.                 makestr(&snd_rename,s);
  6708.                 makestr(&g_snd_rename,s);
  6709.             } else {
  6710.                 makestr(&snd_rename,NULL);
  6711.                 makestr(&g_snd_rename,NULL);
  6712.             }
  6713.         } else {
  6714.             if (*s) {
  6715.                 makestr(&rcv_rename,s);
  6716.                 makestr(&g_rcv_rename,s);
  6717.             } else {
  6718.                 makestr(&rcv_rename,NULL);
  6719.                 makestr(&g_rcv_rename,NULL);
  6720.             }
  6721.         }
  6722.         return(success = 1);
  6723.  
  6724. #ifdef VMS
  6725.       case 887:                 /* VERSION-NUMBERS */
  6726.         if (xx == XYSEND) {
  6727.             extern int vmssversions;
  6728.             return(seton(&vmssversions));
  6729.         } else {
  6730.             extern int vmsrversions;
  6731.             return(seton(&vmsrversions));
  6732.         }
  6733. #endif /* VMS */
  6734.  
  6735.       default:
  6736.         return(-2);
  6737.     }                                   /* End of SET SEND/RECEIVE... */
  6738. }
  6739. #endif /* NOXFER */
  6740.  
  6741. #ifndef NOXMIT
  6742. int
  6743. setxmit() {
  6744.     if ((y = cmkey(xmitab,nxmit,"","",xxstring)) < 0) return(y);
  6745.     switch (y) {
  6746.       case XMITE:                       /* EOF */
  6747.         y = cmtxt("Characters to send at end of file,\n\
  6748.  Use backslash codes for control characters","",&s,xxstring);
  6749.         if (y < 0) return(y);
  6750.         if ((int)strlen(s) > XMBUFL) {
  6751.             printf("?Too many characters, %d maximum\n",XMBUFL);
  6752.             return(-2);
  6753.         }
  6754.         ckstrncpy(xmitbuf,s,XMBUFL);
  6755.         return(success = 1);
  6756.  
  6757.       case XMITF:                       /* Fill */
  6758.         y = cmnum("Numeric code for blank-line fill character","0",10,&x,
  6759.                   xxstring);
  6760.         if ((y = setnum(&z,x,y,127)) < 0) return(y);
  6761.         xmitf = z;
  6762.         return(success = 1);
  6763.       case XMITL:                       /* Linefeed */
  6764.         return(seton(&xmitl));
  6765.       case XMITS:                       /* Locking-Shift */
  6766.         return(seton(&xmits));
  6767.       case XMITP:                       /* Prompt */
  6768.         y = cmnum("Numeric code for host's prompt character, 0 for none",
  6769.                   "10",10,&x,xxstring);
  6770.         if ((y = setnum(&z,x,y,127)) < 0) return(y);
  6771.         xmitp = z;
  6772.         return(success = 1);
  6773.       case XMITX:                       /* Echo */
  6774.         return(seton(&xmitx));
  6775.       case XMITW:                       /* Pause */
  6776.         y = cmnum("Number of milliseconds to pause between binary characters\n\
  6777. or text lines during transmission","0",10,&x,xxstring);
  6778.         if ((y = setnum(&z,x,y,1000)) < 0) return(y);
  6779.         xmitw = z;
  6780.         return(success = 1);
  6781.       case XMITT:                       /* Timeout */
  6782.         y = cmnum("Seconds to wait for each character to echo",
  6783.                   "1",10,&x,xxstring);
  6784.         if ((y = setnum(&z,x,y,1000)) < 0) return(y);
  6785.         xmitt = z;
  6786.         return(success = 1);
  6787.       default:
  6788.         return(-2);
  6789.     }
  6790. }
  6791. #endif /* NOXMIT */
  6792.  
  6793. /*  D O R M T  --  Do a remote command  */
  6794.  
  6795. VOID
  6796. rmsg() {
  6797.     if (pflag)
  6798.       printf(
  6799. #ifdef CK_NEED_SIG
  6800.        " Type your escape character, %s, followed by X or E to cancel.\n",
  6801.        dbchr(escape)
  6802. #else
  6803.        " Press the X or E key to cancel.\n"
  6804. #endif /* CK_NEED_SIG */
  6805.       );
  6806. }
  6807.  
  6808. #ifndef NOXFER
  6809. static int xzcmd = 0;                   /* Global copy of REMOTE cmd index */
  6810.  
  6811. /*  R E M C F M  --  Confirm a REMOTE command  */
  6812. /*
  6813.   Like cmcfm(), but allows for a redirection indicator on the end,
  6814.   like "> filename" or "| command".  Returns what cmcfm() would have
  6815.   returned: -1 if reparse needed, etc etc blah blah.  On success,
  6816.   returns 1 with:
  6817.  
  6818.     char * remdest containing the name of the file or command.
  6819.     int remfile set to 1 if there is to be any redirection.
  6820.     int remappd set to 1 if output file is to be appended to.
  6821.     int rempipe set to 1 if remdest is a command, 0 if it is a file.
  6822. */
  6823. static int
  6824. remcfm() {
  6825.     int x;
  6826.     char *s;
  6827.     char c;
  6828.  
  6829.     remfile = 0;
  6830.     rempipe = 0;
  6831.     remappd = 0;
  6832.  
  6833.     if ((x = cmtxt(
  6834.              "> filename, | command,\n\
  6835. or type carriage return to confirm the command",
  6836.                    "",&s,xxstring)) < 0)
  6837.       return(x);
  6838.     if (remdest) {
  6839.         free(remdest);
  6840.         remdest = NULL;
  6841.     }
  6842.     debug(F101,"remcfm local","",local);
  6843.     debug(F110,"remcfm s",s,0);
  6844.     debug(F101,"remcfm cmd","",xzcmd);
  6845.  
  6846.     if (!*s) {                          /* No redirection indicator */
  6847.         if (!local &&
  6848.             (xzcmd == XZDIR || xzcmd == XZTYP ||
  6849.              xzcmd == XZXIT || xzcmd == XZSPA ||
  6850.              xzcmd == XZHLP || xzcmd == XZPWD ||
  6851.              xzcmd == XZLGI || xzcmd == XZLGO ||
  6852.              xzcmd == XZWHO || xzcmd == XZHOS)) {
  6853.             printf("?\"%s\" has no effect in remote mode\n",cmdbuf);
  6854.             return(-9);
  6855.         } else
  6856.           return(1);
  6857.     }
  6858.     c = *s;                             /* We have something */
  6859.     if (c != '>' && c != '|') {         /* Is it > or | ? */
  6860.         printf("?Not confirmed\n");     /* No */
  6861.         return(-9);
  6862.     }
  6863.     s++;                                /* See what follows */
  6864.     if (c == '>' && *s == '>') {        /* Allow for ">>" too */
  6865.         s++;
  6866.         remappd = 1;                    /* Append to output file */
  6867.     }
  6868.     while (*s == SP || *s == HT) s++;   /* Strip intervening whitespace */
  6869.     if (!*s) {
  6870.         printf("?%s missing\n", c == '>' ? "Filename" : "Command");
  6871.         return(-9);
  6872.     }
  6873.     if (c == '>' && zchko(s) < 0) {     /* Check accessibility */
  6874.         printf("?Access denied - %s\n", s);
  6875.         return(-9);
  6876.     }
  6877.     remfile = 1;                        /* Set global results */
  6878.     rempipe = (c == '|');
  6879.     if (rempipe
  6880. #ifndef NOPUSH
  6881.         && nopush
  6882. #endif /* NOPUSH */
  6883.         ) {
  6884.         printf("?Sorry, access to external commands is disabled.\n");
  6885.         return(-9);
  6886.     }
  6887.     makestr(&remdest,s);
  6888. #ifndef NODEBUG
  6889.     if (deblog) {
  6890.         debug(F101,"remcfm remfile","",remfile);
  6891.         debug(F101,"remcfm remappd","",remappd);
  6892.         debug(F101,"remcfm rempipe","",rempipe);
  6893.         debug(F110,"remcfm remdest",remdest, 0);
  6894.     }
  6895. #endif /* NODEBUG */
  6896.     return(1);
  6897. }
  6898.  
  6899. /*  R E M T X T  --  Like remcfm()...  */
  6900. /*
  6901.    ... but for REMOTE commands that end with cmtxt().
  6902.    Here we must decipher braces to discover whether the trailing
  6903.    redirection indicator is intended for local use, or to be sent out
  6904.    to the server, as in:
  6905.  
  6906.      remote host blah blah > file                 This end
  6907.      remote host { blah blah } > file             This end
  6908.      remote host { blah blah > file }             That end
  6909.      remote host { blah blah > file } > file      Both ends
  6910.  
  6911.    Pipes too:
  6912.  
  6913.      remote host blah blah | cmd                  This end
  6914.      remote host { blah blah } | cmd              This end
  6915.      remote host { blah blah | cmd }              That end
  6916.      remote host { blah blah | cmd } | cmd        Both ends
  6917.  
  6918.    Or both:
  6919.  
  6920.      remote host blah blah | cmd > file           This end, etc etc...
  6921.  
  6922.    Note: this really only makes sense for REMOTE HOST, but why be picky?
  6923.    Call after calling cmtxt(), with pointer to string that cmtxt() parsed,
  6924.    as in "remtxt(&s);".
  6925.  
  6926.    Returns:
  6927.     1 on success with braces & redirection things removed & pointer updated,
  6928.    -9 on failure (bad indirection), after printing error message.
  6929. */
  6930. int
  6931. remtxt(p) char ** p; {
  6932.     int i, x, bpos, ppos;
  6933.     char c, *s, *q;
  6934.  
  6935.     remfile = 0;                        /* Initialize global results */
  6936.     rempipe = 0;
  6937.     remappd = 0;
  6938.     if (remdest) {
  6939.         free(remdest);
  6940.         remdest = NULL;
  6941.     }
  6942.     s = *p;
  6943.     if (!s)                             /* No redirection indicator */
  6944.       s = "";
  6945.     if (!*s) {                          /* Ditto */
  6946.         if (!local &&
  6947.             (xzcmd == XZDIR || xzcmd == XZTYP ||
  6948.              xzcmd == XZXIT || xzcmd == XZSPA ||
  6949.              xzcmd == XZHLP || xzcmd == XZPWD ||
  6950.              xzcmd == XZLGI || xzcmd == XZLGO ||
  6951.              xzcmd == XZWHO || xzcmd == XZHOS)) {
  6952.             printf("?\"%s\" has no effect in remote mode\n",cmdbuf);
  6953.             if (hints) {
  6954.                 printf("Hint: Try again with an output redirector.\n");
  6955.             }
  6956.             return(-9);
  6957.         } else
  6958.           return(1);
  6959.     }
  6960.     bpos = -1;                          /* Position of > (bracket) */
  6961.     ppos = -1;                          /* Position of | (pipe) */
  6962.     x = strlen(s);                      /* Length of cmtxt() string */
  6963.  
  6964.     for (i = x-1; i >= 0; i--) {        /* Search right to left. */
  6965.         c = s[i];
  6966.         if (c == '}')                   /* Break on first right brace */
  6967.           break;                        /* Don't look at contents of braces */
  6968.         else if (c == '>')              /* Record position of > */
  6969.           bpos = i;
  6970.         else if (c == '|')              /* and of | */
  6971.           ppos = i;
  6972.     }
  6973.     if (bpos < 0 && ppos < 0) {         /* No redirectors. */
  6974.         if (!local &&
  6975.             (xzcmd == XZDIR || xzcmd == XZTYP ||
  6976.              xzcmd == XZXIT || xzcmd == XZSPA ||
  6977.              xzcmd == XZHLP || xzcmd == XZPWD ||
  6978.              xzcmd == XZLGI || xzcmd == XZLGO ||
  6979.              xzcmd == XZWHO || xzcmd == XZHOS)) {
  6980.             printf("?\"%s\" has no effect in remote mode\n",cmdbuf);
  6981.             if (hints) {
  6982.                 printf("Hint: Try again with an output redirector.\n");
  6983.             }
  6984.             return(-9);
  6985.         }
  6986.         s = brstrip(s);                 /* Remove outer braces if any. */
  6987.         *p = s;                         /* Point to result */
  6988.         return(1);                      /* and return. */
  6989.     }
  6990.     remfile = 1;                        /* It's | or > */
  6991.     i = -1;                             /* Get leftmost symbol */
  6992.     if (bpos > -1)                      /* Bracket */
  6993.       i = bpos;
  6994.     if (ppos > -1 && (ppos < bpos || bpos < 0)) { /* or pipe */
  6995.         i = ppos;
  6996.         rempipe = 1;
  6997.     }
  6998.     if (rempipe
  6999. #ifndef NOPUSH
  7000.         && nopush
  7001. #endif /* NOPUSH */
  7002.         ) {
  7003.         printf("?Sorry, access to external commands is disabled.\n");
  7004.         return(-9);
  7005.     }
  7006.     c = s[i];                           /* Copy of symbol */
  7007.  
  7008.     if (c == '>' && s[i+1] == '>')      /* ">>" for append? */
  7009.       remappd = 1;                     /* It's not just a flag it's a number */
  7010.  
  7011.     q = s + i + 1 + remappd;            /* Point past symbol in string */
  7012.     while (*q == SP || *q == HT) q++;   /* and any intervening whitespace */
  7013.     if (!*q) {
  7014.         printf("?%s missing\n", c == '>' ? "Filename" : "Command");
  7015.         return(-9);
  7016.     }
  7017.     if (c == '>' && zchko(q) < 0) {     /* (Doesn't work for | cmd > file) */
  7018.         printf("?Access denied - %s\n", q);
  7019.         return(-9);
  7020.     }
  7021.     makestr(&remdest,q);                /* Create the destination string */
  7022.     q = s + i - 1;                      /* Point before symbol */
  7023.     while (q > s && (*q == SP || *q == HT)) /* Strip trailing whitespace */
  7024.       q--;
  7025.     *(q+1) = NUL;                       /* Terminate the string. */
  7026.     s = brstrip(s);                     /* Remove any braces */
  7027.     *p = s;                             /* Set return value */
  7028.  
  7029. #ifndef NODEBUG
  7030.     if (deblog) {
  7031.         debug(F101,"remtxt remfile","",remfile);
  7032.         debug(F101,"remtxt remappd","",remappd);
  7033.         debug(F101,"remtxt rempipe","",rempipe);
  7034.         debug(F110,"remtxt remdest",remdest, 0);
  7035.         debug(F110,"remtxt command",s,0);
  7036.     }
  7037. #endif /* NODEBUG */
  7038.  
  7039.     return(1);
  7040. }
  7041.  
  7042. int
  7043. plogin(xx) int xx; {
  7044.     char *p1 = NULL, *p2 = NULL, *p3 = NULL;
  7045.     int psaved = 0, rc = 0;
  7046. #ifdef CK_RECALL
  7047.     extern int on_recall;               /* around Password prompting */
  7048. #endif /* CK_RECALL */
  7049.     debug(F101,"plogin local","",local);
  7050.  
  7051.     if (!local || (network && ttchk() < 0)) {
  7052.         printf("?No connection\n");
  7053.         return(-9);
  7054.     }
  7055.     if ((x = cmfld("User ID","",&s,xxstring)) < 0) { /* Get User ID */
  7056.         if (x != -3) return(x);
  7057.     }
  7058.     y = strlen(s);
  7059.     if (y > 0) {
  7060.         if ((p1 = malloc(y + 1)) == NULL) {
  7061.             printf("?Internal error: malloc\n");
  7062.             rc = -9;
  7063.             goto XZXLGI;
  7064.         } else
  7065.           strcpy(p1,s);                 /* safe */
  7066.         if ((rc = cmfld("Password","",&s,xxstring)) < 0)
  7067.           if (rc != -3) goto XZXLGI;
  7068.         y = strlen(s);
  7069.         if (y > 0) {
  7070.             if ((p2 = malloc(y + 1)) == NULL) {
  7071.                 printf("?Internal error: malloc\n");
  7072.                 rc = -9;
  7073.                 goto XZXLGI;
  7074.             } else
  7075.               strcpy(p2,s);             /* safe */
  7076.             if ((rc = cmfld("Account","",&s,xxstring)) < 0)
  7077.               if (rc != -3) goto XZXLGI;
  7078.             y = strlen(s);
  7079.             if (y > 0) {
  7080.                 if ((p3 = malloc(y + 1)) == NULL) {
  7081.                     printf("?Internal error: malloc\n");
  7082.                     rc = -9;
  7083.                     goto XZXLGI;
  7084.                 } else
  7085.                   strcpy(p3,s);         /* safe */
  7086.             }
  7087.         }
  7088.     }
  7089.     if ((rc = remtxt(&s)) < 0)          /* Confirm & handle redirectors */
  7090.       goto XZXLGI;
  7091.  
  7092.     if (!p1) {                          /* No Userid specified... */
  7093.         debok = 0;                      /* Don't log this */
  7094.         /* Prompt for username, password, and account */
  7095. #ifdef CK_RECALL
  7096.         on_recall = 0;
  7097. #endif /* CK_RECALL */
  7098.         cmsavp(psave,PROMPTL);          /* Save old prompt */
  7099.         psaved = 1;
  7100.         debug(F110,"REMOTE LOGIN saved",psave,0);
  7101.  
  7102.         cmsetp("Username: ");           /* Make new prompt */
  7103.         concb((char)escape);            /* Put console in cbreak mode */
  7104.         cmini(1);
  7105.         prompt(xxstring);
  7106.         rc = -9;
  7107.         for (x = -1; x < 0; ) {         /* Prompt till they answer */
  7108.             cmres();                    /* Reset the parser */
  7109.             x = cmtxt("","",&s,NULL);   /* Get a literal line of text */
  7110.         }
  7111.         y = strlen(s);
  7112.         if (y < 1) {
  7113.             printf("?Canceled\n");
  7114.             goto XZXLGI;
  7115.         }
  7116.         if ((p1 = malloc(y + 1)) == NULL) {
  7117.             printf("?Internal error: malloc\n");
  7118.             goto XZXLGI;
  7119.         } else
  7120.           strcpy(p1,s);                 /* safe */
  7121.  
  7122.         cmsetp("Password: ");           /* Make new prompt */
  7123.         concb((char)escape);            /* Put console in cbreak mode */
  7124.         cmini(0);                       /* No echo */
  7125.         prompt(xxstring);
  7126.         debok = 0;
  7127.         for (x = -1; x < 0 && x != -3; ) { /* Get answer */
  7128.             cmres();                    /* Reset the parser */
  7129.             x = cmtxt("","",&s,NULL);   /* Get literal line of text */
  7130.         }
  7131.         if ((p2 = malloc((int)strlen(s) + 1)) == NULL) {
  7132.             printf("?Internal error: malloc\n");
  7133.             goto XZXLGI;
  7134.         } else
  7135.           strcpy(p2,s);                 /* safe */
  7136.         printf("\r\n");
  7137.         if ((rc = cmcfm()) < 0)
  7138.           goto XZXLGI;
  7139.     }
  7140.     sstate = setgen('I',p1,p2,p3);      /* Get here with at least user ID */
  7141.     rc = 0;
  7142.  
  7143.   XZXLGI:                               /* Common exit point */
  7144.     if (psaved)
  7145.       cmsetp(psave);                    /* Restore original prompt */
  7146.     if (p3) { free(p3); p3 = NULL; }    /* Free malloc'd storage */
  7147.     if (p2) { free(p2); p2 = NULL; }
  7148.     if (p1) { free(p1); p1 = NULL; }
  7149.     if (rc > -1) {
  7150.         if (local && rc > -1)           /* If local, flush tty input buffer */
  7151.           ttflui();
  7152.     }
  7153.     return(rc);
  7154. }
  7155.  
  7156. #ifdef OS2
  7157. #ifndef NOLOCAL
  7158. int
  7159. dormt(xx) int xx; {
  7160.     int rc = 0;
  7161.     extern int term_io;
  7162.     int term_io_sav = term_io;
  7163. #ifdef NEWFTP
  7164.     extern int ftpget, ftpisopen();
  7165.     if ((ftpget == 1) || ((ftpget == 2) && ftpisopen()))
  7166.       return(doftprmt(xx,0));
  7167. #endif /* NEWFTP */
  7168.     term_io = 0;
  7169.     rc = xxdormt(xx);
  7170.     term_io = term_io_sav;
  7171.     return rc;
  7172. }
  7173.  
  7174.  
  7175. int
  7176. xxdormt(xx) int xx;
  7177. #else /* NOLOCAL */
  7178. int
  7179. dormt(xx) int xx;
  7180. #endif /* NOLOCAL */
  7181. #else /* OS2 */
  7182. int
  7183. dormt(xx) int xx;
  7184. #endif /* OS2 */
  7185. {                                       /* REMOTE commands */
  7186.     int x, y, retcode;
  7187.     char *s, sbuf[50], *s2;
  7188.  
  7189. #ifdef NEWFTP
  7190.     extern int ftpget, ftpisopen();
  7191.     if ((ftpget == 1) || ((ftpget == 2) && ftpisopen()))
  7192.       return(doftprmt(xx,0));
  7193. #endif /* NEWFTP */
  7194.  
  7195.     remfile = 0;                        /* Clear these */
  7196.     rempipe = 0;
  7197.     remappd = 0;
  7198.  
  7199.     if (xx < 0) return(xx);             /* REMOTE what? */
  7200.  
  7201.     xzcmd = xx;                         /* Make global copy of arg */
  7202.  
  7203.     if (xx == XZSET) {                  /* REMOTE SET */
  7204.         if ((y = cmkey(rmstab,nrms,"","",xxstring)) < 0) {
  7205.             if (y == -3) {
  7206.                 printf("?Parameter name required\n");
  7207.                 return(-9);
  7208.             } else return(y);
  7209.         }
  7210.         return(doprm(y,1));
  7211.     }
  7212.  
  7213.     switch (xx) {                       /* Others... */
  7214.  
  7215.       case XZCDU:
  7216.         if ((x = cmcfm()) < 0) return(x);
  7217.         printf("?Sorry, REMOTE CDUP not supported yet\n");
  7218.         return(-9);
  7219.  
  7220.       case XZCWD:                       /* CWD (CD) */
  7221.         if ((x = cmtxt("Remote directory name","",&s,xxstring)) < 0)
  7222.           return(x);
  7223.         if ((x = remtxt(&s)) < 0)
  7224.           return(x);
  7225.         debug(F111,"XZCWD: ",s,x);
  7226.         *sbuf = NUL;
  7227.         s2 = sbuf;
  7228. /*
  7229.   The following is commented out because since the disappearance of the
  7230.   DECSYSTEM-20 from the planet, no known computer requires a password for
  7231.   changing directory.
  7232. */
  7233. #ifdef DIRPWDPR
  7234.         if (*s != NUL) {                /* If directory name given, */
  7235.                                         /* get password on separate line. */
  7236.             if (tlevel > -1) {          /* From take file... */
  7237.  
  7238.                 if (fgets(sbuf,50,tfile[tlevel]) == NULL)
  7239.                   fatal("take file ends prematurely in 'remote cwd'");
  7240.                 debug(F110," pswd from take file",s2,0);
  7241.                 for (x = (int)strlen(sbuf);
  7242.                      x > 0 && (sbuf[x-1] == NL || sbuf[x-1] == CR);
  7243.                      x--)
  7244.                   sbuf[x-1] = '\0';
  7245.  
  7246.             } else {                    /* From terminal... */
  7247.  
  7248.                 printf(" Password: ");  /* get a password */
  7249. #ifdef IKSD
  7250.                 if (!local && inserver) {
  7251.                     x = coninc(0);
  7252.                 } else
  7253. #endif /* IKSD */
  7254. #ifdef OS2
  7255.                   x = is_a_tty(0) ? coninc(0) : /* with no echo ... */
  7256.                     getchar();
  7257. #else /* OS2 */
  7258.                 x = getchar();
  7259. #endif /* OS2 */
  7260.                 while ((x != NL) && (x != CR)) {
  7261.                     if ((x &= 0177) == '?') {
  7262.                         printf("? Password of remote directory\n Password: ");
  7263.                         s2 = sbuf;
  7264.                         *sbuf = NUL;
  7265.                     } else if (x == ESC) /* Mini command line editor... */
  7266.                       bleep(BP_WARN);
  7267.                     else if (x == BS || x == 0177)
  7268.                       s2--;
  7269.                     else if (x == 025) {        /* Ctrl-U */
  7270.                         s2 = sbuf;
  7271.                         *sbuf = NUL;
  7272.                     } else
  7273.                       *s2++ = x;
  7274.  
  7275.                     /* Get the next character */
  7276. #ifdef IKSD
  7277.                     if (!local && inserver) {
  7278.                         x = coninc(0);
  7279.                     } else
  7280. #endif /* IKSD */
  7281. #ifdef OS2
  7282.                     x = is_a_tty(0) ? coninc(0) : /* with no echo ... */
  7283.                       getchar();
  7284. #else /* OS2 */
  7285.                     x = getchar();
  7286. #endif /* OS2 */
  7287.                 }
  7288.                 *s2 = NUL;
  7289.                 putchar('\n');
  7290.             }
  7291.             s2 = sbuf;
  7292.         } else s2 = "";
  7293. #endif /* DIRPWDPR */
  7294.  
  7295.         debug(F110," password",s2,0);
  7296.         sstate = setgen('C',s,s2,"");
  7297.         retcode = 0;
  7298.         break;
  7299.  
  7300.       case XZDEL:                               /* Delete */
  7301.         if ((x = cmtxt("Name of remote file(s) to delete",
  7302.                        "",&s,xxstring)) < 0) {
  7303.             if (x == -3) {
  7304.                 printf("?Name of remote file(s) required\n");
  7305.                 return(-9);
  7306.             } else return(x);
  7307.         }
  7308.         if ((x = remtxt(&s)) < 0)
  7309.           return(x);
  7310.         if (local) ttflui();            /* If local, flush tty input buffer */
  7311.         retcode = sstate = rfilop(s,'E');
  7312.         break;
  7313.  
  7314.       case XZDIR:                       /* Directory */
  7315.         if ((x = cmtxt("Remote directory or file specification","",&s,
  7316.                        xxstring)) < 0)
  7317.           return(x);
  7318.         if ((x = remtxt(&s)) < 0)
  7319.           return(x);
  7320.         if (local) ttflui();            /* If local, flush tty input buffer */
  7321.         rmsg();
  7322.         retcode = sstate = setgen('D',s,"","");
  7323.         break;
  7324.  
  7325.       case XZHLP:                       /* Help */
  7326.         if ((x = remcfm()) < 0) return(x);
  7327.         sstate = setgen('H',"","","");
  7328.         retcode = 0;
  7329.         break;
  7330.  
  7331.       case XZHOS:                       /* Host */
  7332.         if ((x = cmtxt("Command for remote system","",&s,xxstring)) < 0)
  7333.           return(x);
  7334.         if ((x = remtxt(&s)) < 0)
  7335.           return(x);
  7336.         if ((y = (int)strlen(s)) < 1)
  7337.           return(x);
  7338.         ckstrncpy(line,s,LINBUFSIZ);
  7339.         cmarg = line;
  7340.         rmsg();
  7341.         retcode = sstate = 'c';
  7342.         break;
  7343.  
  7344. #ifndef NOFRILLS
  7345.       case XZKER:
  7346.         if ((x = cmtxt("Command for remote Kermit","",&s,xxstring)) < 0)
  7347.           return(x);
  7348.         if ((x = remtxt(&s)) < 0)
  7349.           return(x);
  7350.         if ((int)strlen(s) < 1)  {
  7351.             if (x == -3) {
  7352.                 printf("?Remote Kermit command required\n");
  7353.                 return(-9);
  7354.             } else return(x);
  7355.         }
  7356.         ckstrncpy(line,s,LINBUFSIZ);
  7357.         cmarg = line;
  7358.         retcode = sstate = 'k';
  7359.         rmsg();
  7360.         break;
  7361.  
  7362.       case XZLGI:                       /* Login */
  7363.         return(plogin(XXREM));
  7364.  
  7365.       case XZLGO: {                     /* Logout */
  7366.           extern int bye_active;
  7367.           if ((x = remcfm()) < 0) return(x);
  7368.           sstate = setgen('I',"","","");
  7369.           retcode = 0;
  7370.           bye_active = 1;               /* Close connection when done */
  7371.           break;
  7372.       }
  7373.  
  7374.       case XZPRI:                       /* Print */
  7375.         if (!atdiso || !atcapr) {       /* Disposition attribute off? */
  7376.             printf("?Disposition Attribute is Off\n");
  7377.             return(-2);
  7378.         }
  7379.         cmarg = "";
  7380.         cmarg2 = "";
  7381.         if ((x = cmifi("Local file(s) to print on remote printer","",&s,&y,
  7382.                        xxstring)) < 0) {
  7383.             if (x == -3) {
  7384.                 printf("?Name of local file(s) required\n");
  7385.                 return(-9);
  7386.             }
  7387.             return(x);
  7388.         }
  7389.         ckstrncpy(line,s,LINBUFSIZ);    /* Make a safe copy of filename */
  7390.         *optbuf = NUL;                  /* Wipe out any old options */
  7391.         if ((x = cmtxt("Options for remote print command","",&s,xxstring)) < 0)
  7392.           return(x);
  7393.         if ((x = remtxt(&s)) < 0)
  7394.           return(x);
  7395.         if ((int)strlen(optbuf) > 94) { /* Make sure this is legal */
  7396.             printf("?Option string too long\n");
  7397.             return(-9);
  7398.         }
  7399.         ckstrncpy(optbuf,s,OPTBUFLEN);  /* Make a safe copy of options */
  7400.         nfils = -1;                     /* Expand file list internally */
  7401.         cmarg = line;                   /* Point to file list. */
  7402.         rprintf = 1;                    /* REMOTE PRINT modifier for SEND */
  7403.         sstate = 's';                   /* Set start state to SEND */
  7404.         if (local) displa = 1;
  7405.         retcode = 0;
  7406.         break;
  7407. #endif /* NOFRILLS */
  7408.  
  7409.       case XZSPA:                       /* Space */
  7410.         if ((x = cmtxt("Confirm, or remote directory name",
  7411.                        "",&s,xxstring)) < 0)
  7412.           return(x);
  7413.         if ((x = remtxt(&s)) < 0)
  7414.           return(x);
  7415.         retcode = sstate = setgen('U',s,"","");
  7416.         break;
  7417.  
  7418. #ifndef NOFRILLS
  7419.       case XZTYP:                       /* Type */
  7420.         if ((x = cmtxt("Remote file specification","",&s,xxstring)) < 0)
  7421.           return(x);
  7422.         if ((int)strlen(s) < 1) {
  7423.             printf("?Remote filename required\n");
  7424.             return(-9);
  7425.         }
  7426.         if ((x = remtxt(&s)) < 0)
  7427.           return(x);
  7428.         rmsg();
  7429.         retcode = sstate = rfilop(s,'T');
  7430.         break;
  7431. #endif /* NOFRILLS */
  7432.  
  7433. #ifndef NOFRILLS
  7434.       case XZWHO:
  7435.         if ((x = cmtxt("Remote user name, or carriage return",
  7436.                        "",&s,xxstring)) < 0)
  7437.           return(x);
  7438.         if ((x = remtxt(&s)) < 0)
  7439.           return(x);
  7440.         retcode = sstate = setgen('W',s,"","");
  7441.         break;
  7442. #endif /* NOFRILLS */
  7443.  
  7444.       case XZPWD:                       /* PWD */
  7445.         if ((x = remcfm()) < 0) return(x);
  7446.         sstate = setgen('A',"","","");
  7447.         retcode = 0;
  7448.         break;
  7449.  
  7450. #ifndef NOSPL
  7451.       case XZQUE: {                     /* Query */
  7452.           char buf[2];
  7453.           extern char querybuf[], * qbufp;
  7454.           extern int qbufn;
  7455.           if ((y = cmkey(vartyp,nvartyp,"","",xxstring)) < 0)
  7456.             return(y);
  7457.           if ((x = cmtxt(y == 'F' ? "Remote function invocation" :
  7458.                          ('K' ? "Remote variable name or function":
  7459.                          "Remote variable name"),
  7460.                          "",
  7461.                          &s,
  7462.                          (y == 'K') ? xxstring : NULL
  7463.                          )) < 0)        /* Don't evaluate */
  7464.             return(x);
  7465.           if ((x = remtxt(&s)) < 0)
  7466.             return(x);
  7467.           query = 1;                    /* QUERY is active */
  7468.           qbufp = querybuf;             /* Initialize query response buffer */
  7469.           qbufn = 0;
  7470.           querybuf[0] = NUL;
  7471.           buf[0] = (char) (y & 127);
  7472.           buf[1] = NUL;
  7473.           retcode = sstate = setgen('V',"Q",(char *)buf,s);
  7474.           break;
  7475.       }
  7476.  
  7477.       case XZASG: {                     /* Assign */
  7478.           char buf[VNAML];
  7479.           if ((y = cmfld("Remote variable name","",&s,NULL)) < 0) /* No eval */
  7480.             return(y);
  7481.           if ((int)strlen(s) >= VNAML) {
  7482.               printf("?Too long\n");
  7483.               return(-9);
  7484.           }
  7485.           ckstrncpy(buf,s,VNAML);
  7486.           if ((x = cmtxt("Assignment for remote variable",
  7487.                    "",&s,xxstring)) < 0) /* Evaluate this one */
  7488.             return(x);
  7489.           if ((x = remtxt(&s)) < 0)
  7490.             return(x);
  7491. #ifdef COMMENT
  7492. /*
  7493.   Server commands can't be long packets.  In principle there's no reason
  7494.   why they shouldn't be, except that we don't know at this point if the
  7495.   server is capable of accepting long packets because we haven't started
  7496.   the protocol yet.  In practice, allowing a long packet here breaks a lot
  7497.   of assumptions, causes buffer overruns and crashes, etc.  To be fixed
  7498.   later.  (But since this is commented out, evidently I fixed it later...)
  7499. */
  7500.           if ((int)strlen(s) > 85) {    /* Allow for encoding expansion */
  7501.               printf("?Sorry, value is too long - 85 characters max\n");
  7502.               return(-9);
  7503.           }
  7504. #endif /* COMMENT */
  7505.           retcode = sstate = setgen('V',"S",(char *)buf,s);
  7506.           break;
  7507.       }
  7508. #endif /* NOSPL */
  7509.  
  7510.       case XZCPY: {                     /* COPY */
  7511.           char buf[TMPBUFSIZ];
  7512.           buf[TMPBUFSIZ-1] = '\0';
  7513.           if ((x = cmfld("Name of remote file to copy","",&s,xxstring)) < 0) {
  7514.               if (x == -3) {
  7515.                   printf("?Name of remote file required\n");
  7516.                   return(-9);
  7517.               }
  7518.               else
  7519.                 return(x);
  7520.           }
  7521.           ckstrncpy(buf,s,TMPBUFSIZ);
  7522.           if ((x = cmfld("Name of remote destination file or directory",
  7523.                          "",&s, xxstring)) < 0) {
  7524.               if (x == -3) {
  7525.                   printf("?Name of remote file or directory required\n");
  7526.                   return(-9);
  7527.               } else return(x);
  7528.           }
  7529.           ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  7530.           if ((x = remcfm()) < 0)
  7531.             return(x);
  7532.           if (local) ttflui();          /* If local, flush tty input buffer */
  7533.           retcode = sstate = setgen('K',buf,tmpbuf,"");
  7534.           break;
  7535.       }
  7536.       case XZREN: {                     /* Rename */
  7537.           char buf[TMPBUFSIZ];
  7538.           buf[TMPBUFSIZ-1] = '\0';
  7539.           if ((x = cmfld("Name of remote file to rename",
  7540.                          "",&s,xxstring)) < 0) {
  7541.               if (x == -3) {
  7542.                   printf("?Name of remote file required\n");
  7543.                   return(-9);
  7544.               } else return(x);
  7545.           }
  7546.           ckstrncpy(buf,s,TMPBUFSIZ);
  7547.           if ((x = cmfld("New name of remote file","",&s, xxstring)) < 0) {
  7548.               if (x == -3) {
  7549.                   printf("?Name of remote file required\n");
  7550.                   return(-9);
  7551.               } else return(x);
  7552.           }
  7553.           ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  7554.           if ((x = remcfm()) < 0)
  7555.             return(x);
  7556.           if (local) ttflui();          /* If local, flush device buffer */
  7557.           retcode = sstate = setgen('R',buf,tmpbuf,"");
  7558.           break;
  7559.       }
  7560.       case XZMKD:                       /* mkdir */
  7561.       case XZRMD:                       /* rmdir */
  7562.         if ((x = cmtxt((xx == XZMKD) ?
  7563.                        "Name of remote directory to create" :
  7564.                        "Name of remote directory to delete",
  7565.                        "",
  7566.                        &s,
  7567.                        xxstring
  7568.                        )) < 0) {
  7569.             if (x == -3) {
  7570.                 printf("?Name required\n");
  7571.                 return(-9);
  7572.             } else return(x);
  7573.         }
  7574.         if ((x = remtxt(&s)) < 0)
  7575.           return(x);
  7576.         if (local) ttflui();            /* If local, flush tty input buffer */
  7577.         retcode = sstate = rfilop(s, (char)(xx == XZMKD ? 'm' : 'd'));
  7578.         break;
  7579.  
  7580.       case XZXIT:                       /* Exit */
  7581.         if ((x = remcfm()) < 0) return(x);
  7582.         sstate = setgen('X',"","","");
  7583.         retcode = 0;
  7584.         break;
  7585.  
  7586.       default:
  7587.         if ((x = remcfm()) < 0) return(x);
  7588.         printf("?Not implemented - %s\n",cmdbuf);
  7589.         return(-2);
  7590.     }
  7591.     if (local && retcode > -1)          /* If local, flush tty input buffer */
  7592.       ttflui();
  7593.     return(retcode);
  7594. }
  7595.  
  7596.  
  7597. /*  R F I L O P  --  Remote File Operation  */
  7598.  
  7599. CHAR
  7600. #ifdef CK_ANSIC
  7601. rfilop(char * s, char t)
  7602. #else
  7603. rfilop(s,t) char *s, t;
  7604. #endif /* CK_ANSIC */
  7605. /* rfilop */ {
  7606.     if (*s == NUL) {
  7607.         printf("?File specification required\n");
  7608.         return((CHAR) 0);
  7609.     }
  7610.     debug(F111,"rfilop",s,t);
  7611.     return(setgen(t,s,"",""));
  7612. }
  7613. #endif /* NOXFER */
  7614.  
  7615. #ifdef ANYX25
  7616. int
  7617. setx25() {
  7618.     if ((y = cmkey(x25tab,nx25,"X.25 call options","",xxstring)) < 0)
  7619.       return(y);
  7620.     switch (y) {
  7621.       case XYUDAT:
  7622.         if ((z = cmkey(onoff,2,"X.25 call user data","",xxstring))
  7623.             < 0) return(z);
  7624.         if (z == 0) {
  7625.             if ((z = cmcfm()) < 0) return(z);
  7626.             cudata = 0;             /* disable call user data */
  7627.             return (success = 1);
  7628.         }
  7629.         if ((x = cmtxt("X.25 call user data string","",&s,xxstring)) < 0)
  7630.           return(x);
  7631.         if ((int)strlen(s) == 0) {
  7632.             return (-3);
  7633.         } else if ((int)strlen(s) > MAXCUDATA) {
  7634.             printf("?The length must be > 0 and <= %d\n",MAXCUDATA);
  7635.             return(-2);
  7636.         }
  7637.         if ((y = cmcfm()) < 0) return(y);
  7638.         ckstrncpy(udata,s,MAXCUDATA);
  7639.         cudata = 1;                     /* X.25 call user data specified */
  7640.         return (success = 1);
  7641.       case XYCLOS:
  7642.         if ((z = cmkey(onoff,2,"X.25 closed user group call","",xxstring))
  7643.             < 0) return(z);
  7644.         if (z == 0) {
  7645.             if ((z = cmcfm()) < 0) return(z);
  7646.             closgr = -1;                /* disable closed user group */
  7647.             return (success = 1);
  7648.         }
  7649.         if ((y = cmnum("0 <= cug index >= 99","",10,&x,xxstring)) < 0)
  7650.           return(y);
  7651.         if (x < 0 || x > 99) {
  7652.             printf("?The choices are 0 <= cug index >= 99\n");
  7653.             return(-2);
  7654.         }
  7655.         if ((y = cmcfm()) < 0) return(y);
  7656.         closgr = x;                     /* closed user group selected */
  7657.         return (success = 1);
  7658.  
  7659.       case XYREVC:
  7660.         if((z = cmkey(onoff,2,"X.25 reverse charge call","",xxstring)) < 0)
  7661.           return(z);
  7662.         if ((x = cmcfm()) < 0) return(x);
  7663.         revcall = z;
  7664.         return (success = 1);
  7665.     }
  7666. }
  7667.  
  7668. #ifndef IBMX25
  7669. int
  7670. setpadp() {
  7671.     if ((y = cmkey(padx3tab,npadx3,"PAD X.3 parameter name","",xxstring)) < 0)
  7672.       return(y);
  7673.     x = y;
  7674.     switch (x) {
  7675.       case PAD_BREAK_CHARACTER:
  7676.         if ((y = cmnum("PAD break character value","",10,&z,xxstring)) < 0)
  7677.           return(y);
  7678.         if ((y = cmcfm()) < 0) return(y);
  7679.         break;
  7680.       case PAD_ESCAPE:
  7681.         if ((y = cmnum("PAD escape","",10,&z,xxstring)) < 0) return(y);
  7682.         if (z != 0 && z != 1) {
  7683.             printf("?The choices are 0 or 1\n");
  7684.             return(-2);
  7685.         }
  7686.         if ((y = cmcfm()) < 0) return(y);
  7687.         break;
  7688.       case PAD_ECHO:
  7689.         if ((y = cmnum("PAD echo","",10,&z,xxstring)) < 0) return(y);
  7690.         if (z != 0 && z != 1) {
  7691.             printf("?The choices are 0 or 1\n");
  7692.             return(-2);
  7693.         }
  7694.         if ((y = cmcfm()) < 0) return(y);
  7695.         break;
  7696.       case PAD_DATA_FORWARD_CHAR:
  7697.         if ((y = cmnum("PAD data forward char","",10,&z,xxstring)) < 0)
  7698.           return(y);
  7699.         if (z != 0 && z != 2) {
  7700.             printf("?The choices are 0 or 2\n");
  7701.             return(-2);
  7702.         }
  7703.         if ((y = cmcfm()) < 0) return(y);
  7704.         break;
  7705.       case PAD_DATA_FORWARD_TIMEOUT:
  7706.         if ((y = cmnum("PAD data forward timeout","",10,&z,xxstring)) < 0)
  7707.             return(y);
  7708.         if (z < 0 || z > 255) {
  7709.             printf("?The choices are 0 or 1 <= timeout <= 255\n");
  7710.             return(-2);
  7711.         }
  7712.         if ((y = cmcfm()) < 0) return(y);
  7713.         break;
  7714.       case PAD_FLOW_CONTROL_BY_PAD:
  7715.         if ((y = cmnum("PAD pad flow control","",10,&z,xxstring)) < 0)
  7716.           return(y);
  7717.         if (z != 0 && z != 1) {
  7718.             printf("?The choices are 0 or 1\n");
  7719.             return(-2);
  7720.         }
  7721.         if ((y = cmcfm()) < 0) return(y);
  7722.         break;
  7723.       case PAD_SUPPRESSION_OF_SIGNALS:
  7724.         if ((y = cmnum("PAD service","",10,&z,xxstring)) < 0) return(y);
  7725.         if (z != 0 && z != 1) {
  7726.             printf("?The choices are 0 or 1\n");
  7727.             return(-2);
  7728.         }
  7729.         if ((y = cmcfm()) < 0) return(y);
  7730.         break;
  7731.  
  7732.       case PAD_BREAK_ACTION:
  7733.         if ((y = cmnum("PAD break action","",10,&z,xxstring)) < 0) return(y);
  7734.         if (z != 0 && z != 1 && z != 2 && z != 5 && z != 8 && z != 21) {
  7735.             printf("?The choices are 0, 1, 2, 5, 8 or 21\n");
  7736.             return(-2);
  7737.         }
  7738.         if ((y = cmcfm()) < 0) return(y);
  7739.         break;
  7740.  
  7741.       case PAD_SUPPRESSION_OF_DATA:
  7742.         if ((y = cmnum("PAD data delivery","",10,&z,xxstring)) < 0) return(y);
  7743.         if (z != 0 && z != 1) {
  7744.             printf("?The choices are 0 or 1\n");
  7745.             return(-2);
  7746.         }
  7747.         if ((y = cmcfm()) < 0) return(y);
  7748.         break;
  7749.  
  7750.       case PAD_PADDING_AFTER_CR:
  7751.         if ((y = cmnum("PAD crpad","",10,&z,xxstring)) < 0) return(y);
  7752.         if (z < 0 || z > 7) {
  7753.             printf("?The choices are 0 or 1 <= crpad <= 7\n");
  7754.             return(-2);
  7755.         }
  7756.         if ((y = cmcfm()) < 0) return(y);
  7757.         break;
  7758.  
  7759.       case PAD_LINE_FOLDING:
  7760.         if ((y = cmnum("PAD linefold","",10,&z,xxstring)) < 0) return(y);
  7761.         if (z < 0 || z > 255) {
  7762.             printf("?The choices are 0 or 1 <= linefold <= 255\n");
  7763.             return(-2);
  7764.         }
  7765.         if ((y = cmcfm()) < 0) return(y);
  7766.         break;
  7767.  
  7768.       case PAD_LINE_SPEED:
  7769.         if ((y = cmnum("PAD baudrate","",10,&z,xxstring)) < 0) return(y);
  7770.         if (z < 0 || z > 18) {
  7771.             printf("?The choices are 0 <= baudrate <= 18\n");
  7772.             return(-2);
  7773.         }
  7774.         if ((y = cmcfm()) < 0) return(y);
  7775.         break;
  7776.  
  7777.       case PAD_FLOW_CONTROL_BY_USER:
  7778.         if ((y = cmnum("PAD terminal flow control","",10,&z,xxstring)) < 0)
  7779.             return(y);
  7780.         if (z != 0 && z != 1) {
  7781.             printf("?The choices are 0 or 1\n");
  7782.             return(-2);
  7783.         }
  7784.         if ((y = cmcfm()) < 0) return(y);
  7785.         break;
  7786.  
  7787.       case PAD_LF_AFTER_CR:
  7788.         if ((y = cmnum("PAD crpad","",10,&z,xxstring)) < 0) return(y);
  7789.         if (z < 0 || z == 3 || z > 7) {
  7790.             printf("?The choices are 0, 1, 2, 4, 5, 6 or 7\n");
  7791.             return(-2);
  7792.         }
  7793.         if ((y = cmcfm()) < 0) return(y);
  7794.         break;
  7795.  
  7796.       case PAD_PADDING_AFTER_LF:
  7797.         if ((y = cmnum("PAD lfpad","",10,&z,xxstring)) < 0) return(y);
  7798.         if (z < 0 || z > 7) {
  7799.             printf("?The choices are 0 or 1 <= lfpad <= 7\n");
  7800.             return(-2);
  7801.         }
  7802.         if ((y = cmcfm()) < 0) return(y);
  7803.         break;
  7804.  
  7805.       case PAD_EDITING:
  7806.         if ((y = cmnum("PAD edit control","",10,&z,xxstring)) < 0) return(y);
  7807.         if (z != 0 && z != 1) {
  7808.             printf("?The choices are 0 or 1\n");
  7809.             return(-2);
  7810.         }
  7811.         if ((y = cmcfm()) < 0) return(y);
  7812.         break;
  7813.  
  7814.       case PAD_CHAR_DELETE_CHAR:
  7815.         if ((y = cmnum("PAD char delete char","",10,&z,xxstring)) < 0)
  7816.             return(y);
  7817.         if (z < 0 || z > 127) {
  7818.             printf("?The choices are 0 or 1 <= chardelete <= 127\n");
  7819.             return(-2);
  7820.         }
  7821.         if ((y = cmcfm()) < 0) return(y);
  7822.         break;
  7823.  
  7824.       case PAD_BUFFER_DELETE_CHAR:
  7825.         if ((y = cmnum("PAD buffer delete char","",10,&z,xxstring)) < 0)
  7826.             return(y);
  7827.         if (z < 0 || z > 127) {
  7828.             printf("?The choices are 0 or 1 <= bufferdelete <= 127\n");
  7829.             return(-2);
  7830.         }
  7831.         if ((y = cmcfm()) < 0) return(y);
  7832.         break;
  7833.  
  7834.       case PAD_BUFFER_DISPLAY_CHAR:
  7835.         if ((y = cmnum("PAD display line char","",10,&z,xxstring)) < 0)
  7836.             return(y);
  7837.         if (z < 0 || z > 127) {
  7838.             printf("?The choices are 0 or 1 <= displayline <= 127\n");
  7839.             return(-2);
  7840.         }
  7841.         if ((y = cmcfm()) < 0) return(y);
  7842.         break;
  7843.     }
  7844.     padparms[x] = z;
  7845.     return(success = 1);
  7846. }
  7847. #endif /* IBMX25 */
  7848. #endif /* ANYX25 */
  7849.  
  7850. #ifndef NOXFER
  7851. int
  7852. setat(rmsflg) int rmsflg; {
  7853.     int xx;
  7854.     if ((y = cmkey(attrtab,natr,"File Attribute packets","",xxstring)) < 0)
  7855.       return(y);
  7856.     if (y == AT_XALL) {                 /* ATTRIBUTES ALL ON or ALL OFF */
  7857.         if ((z = seton(&xx)) < 0) return(z);
  7858.         if (rmsflg) {
  7859.             printf("Sorry, command not available\n");
  7860.             return(-9);
  7861.         } else {
  7862.             atenci = xx;                /* Encoding in */
  7863.             atenco = xx;                /* Encoding out */
  7864.             atdati = xx;                /* Date in */
  7865.             atdato = xx;                /* Date out */
  7866.             atdisi = xx;                /* Disposition in/out */
  7867.             atdiso = xx;
  7868.             atleni = xx;                /* Length in/out (both kinds) */
  7869.             atleno = xx;
  7870.             atblki = xx;                /* Blocksize in/out */
  7871.             atblko = xx;
  7872.             attypi = xx;                /* File type in/out */
  7873.             attypo = xx;
  7874.             atsidi = xx;                /* System ID in/out */
  7875.             atsido = xx;
  7876.             atsysi = xx;                /* System-dependent params in/out */
  7877.             atsyso = xx;
  7878. #ifdef CK_PERMS                         /* Protection */
  7879.             atlpri = xx;                /* Local in */
  7880.             atlpro = xx;                /* Local out */
  7881.             atgpri = xx;                /* Generic in */
  7882.             atgpro = xx;                /* Generic out */
  7883. #endif /* CK_PERMS */
  7884. #ifdef STRATUS
  7885.             atfrmi = xx;                /* Format in/out */
  7886.             atfrmo = xx;
  7887.             atcrei = xx;                /* Creator id in/out */
  7888.             atcreo = xx;
  7889.             atacti = xx;                /* Account in/out */
  7890.             atacto = xx;
  7891. #endif /* STRATUS */
  7892.         }
  7893.         return(z);
  7894.     } else if (y == AT_ALLY || y == AT_ALLN) { /* ATTRIBUTES ON or OFF */
  7895.         if ((x = cmcfm()) < 0) return(x);
  7896.         atcapr = (y == AT_ALLY) ? 1 : 0;
  7897.         if (rmsflg) {
  7898.             sstate = setgen('S', "132", atcapr ? "1" : "0", "");
  7899.             return((int) sstate);
  7900.         } else return(success = 1);
  7901.     }
  7902.     /* Otherwise, it's an individual attribute that wants turning off/on */
  7903.  
  7904.     if ((z = cmkey(onoff,2,"","",xxstring)) < 0) return(z);
  7905.     if ((x = cmcfm()) < 0) return(x);
  7906.  
  7907. /* There are better ways to do this... */
  7908. /* The real problem is that we're not separating the in and out cases */
  7909. /* and so we have to arbitrarily pick the "in" case, i.e tell the remote */
  7910. /* server to ignore incoming attributes of the specified type, rather */
  7911. /* than telling it not to send them.  The protocol does not (yet) define */
  7912. /* codes for "in-and-out-at-the-same-time". */
  7913.  
  7914.     switch (y) {
  7915. #ifdef CK_PERMS
  7916. /* We're lumping local and generic protection together for now... */
  7917.       case AT_LPRO:
  7918.       case AT_GPRO:
  7919.         if (rmsflg) {
  7920.             sstate = setgen('S', "143", z ? "1" : "0", "");
  7921.             return((int) sstate);
  7922.         }
  7923.         atlpri = atlpro = atgpri = atgpro = z; break;
  7924. #endif /* CK_PERMS */
  7925.       case AT_DISP:
  7926.         if (rmsflg) {
  7927.             sstate = setgen('S', "142", z ? "1" : "0", "");
  7928.             return((int) sstate);
  7929.         }
  7930.         atdisi = atdiso = z; break;
  7931.       case AT_ENCO:
  7932.         if (rmsflg) {
  7933.             sstate = setgen('S', "141", z ? "1" : "0", "");
  7934.             return((int) sstate);
  7935.         }
  7936.         atenci = atenco = z; break;
  7937.       case AT_DATE:
  7938.         if (rmsflg) {
  7939.             sstate = setgen('S', "135", z ? "1" : "0", "");
  7940.             return((int) sstate);
  7941.         }
  7942.         atdati = atdato = z; break;
  7943.       case AT_LENB:
  7944.       case AT_LENK:
  7945.         if (rmsflg) {
  7946.             sstate = setgen('S', "133", z ? "1" : "0", "");
  7947.             return((int) sstate);
  7948.         }
  7949.         atleni = atleno = z; break;
  7950.       case AT_BLKS:
  7951.         if (rmsflg) {
  7952.             sstate = setgen('S', "139", z ? "1" : "0", "");
  7953.             return((int) sstate);
  7954.         }
  7955.         atblki = atblko = z; break;
  7956.       case AT_FTYP:
  7957.         if (rmsflg) {
  7958.             sstate = setgen('S', "134", z ? "1" : "0", "");
  7959.             return((int) sstate);
  7960.         }
  7961.         attypi = attypo = z; break;
  7962. #ifdef STRATUS
  7963.       case AT_CREA:
  7964.         if (rmsflg) {
  7965.             sstate = setgen('S', "136", z ? "1" : "0", "");
  7966.             return((int) sstate);
  7967.         }
  7968.         atcrei = atcreo = z; break;
  7969.       case AT_ACCT:
  7970.         if (rmsflg) {
  7971.             sstate = setgen('S', "137", z ? "1" : "0", "");
  7972.             return((int) sstate);
  7973.         }
  7974.         atacti = atacto = z; break;
  7975. #endif /* STRATUS */
  7976.       case AT_SYSI:
  7977.         if (rmsflg) {
  7978.             sstate = setgen('S', "145", z ? "1" : "0", "");
  7979.             return((int) sstate);
  7980.         }
  7981.         atsidi = atsido = z; break;
  7982.       case AT_RECF:
  7983.         if (rmsflg) {
  7984.             sstate = setgen('S', "146", z ? "1" : "0", "");
  7985.             return((int) sstate);
  7986.         }
  7987.         atfrmi = atfrmo = z; break;
  7988.       case AT_SYSP:
  7989.         if (rmsflg) {
  7990.             sstate = setgen('S', "147", z ? "1" : "0", "");
  7991.             return((int) sstate);
  7992.         }
  7993.         atsysi = atsyso = z; break;
  7994.       default:
  7995.         printf("?Not available\n");
  7996.         return(-2);
  7997.     }
  7998.     return(1);
  7999. }
  8000. #endif /* NOXFER */
  8001.  
  8002. #ifndef NOSPL
  8003. int
  8004. setinp() {
  8005.     if ((y = cmkey(inptab,ninp,"","",xxstring)) < 0) return(y);
  8006.     switch (y) {
  8007. #ifdef OS2
  8008.       case IN_PAC:                      /* SET INPUT PACING */
  8009.         z = cmnum("milliseconds","0",10,&x,xxstring);
  8010.         return(setnum(&tt_inpacing,x,z,1000));
  8011.       case IN_TRM:                      /* SET INPUT TERMINAL */
  8012.         return(seton(&interm));
  8013. #endif /* OS2 */
  8014.       case IN_DEF:                      /* SET INPUT DEFAULT-TIMEOUT */
  8015.         z = cmnum("Positive number","",10,&x,xxstring);
  8016.         return(setnum(&indef,x,z,94));
  8017.       case IN_TIM:                      /* SET INPUT TIMEOUT-ACTION */
  8018.         if ((z = cmkey(intimt,2,"","",xxstring)) < 0) return(z);
  8019.         if ((x = cmcfm()) < 0) return(x);
  8020.         intime[cmdlvl] = z;
  8021.         return(success = 1);
  8022.       case IN_CAS:                      /* SET INPUT CASE */
  8023.         if ((z = cmkey(incast,2,"","",xxstring)) < 0) return(z);
  8024.         if ((x = cmcfm()) < 0) return(x);
  8025.         inpcas[cmdlvl] = z;
  8026.         return(success = 1);
  8027.       case IN_ECH:                      /* SET INPUT ECHO */
  8028.         return(seton(&inecho));
  8029.       case IN_SIL:                      /* SET INPUT SILENCE */
  8030.         z = cmnum("Seconds of inactivity before INPUT fails","",10,&x,
  8031.                   xxstring);
  8032.         return(setnum(&insilence,x,z,-1));
  8033.  
  8034.       case IN_BUF:                      /* SET INPUT BUFFER-SIZE */
  8035.         if ((z = cmnum("Number of bytes in INPUT buffer",
  8036.                        ckitoa(INPBUFSIZ),10,&x, xxstring)) < 0)
  8037.           return(z);
  8038.         if ((y = cmcfm()) < 0) return(y);
  8039.         inbufsize = 0;
  8040.         if (inpbuf) {
  8041.             free(inpbuf);
  8042.             inpbuf = NULL;
  8043.             inpbp = NULL;
  8044.         }
  8045.         if (!(s = (char *)malloc(x + 1)))
  8046.           return(0);
  8047.         inpbuf = s;
  8048.         inpbp = s;
  8049.         inbufsize = x;
  8050.         for (x = 0; x <= inbufsize; x++)
  8051.           inpbuf[x] = NUL;
  8052.         return(success = 1);
  8053.  
  8054. #ifdef CK_AUTODL
  8055.       case IN_ADL:                      /* AUTODOWNLOAD */
  8056.         return(seton(&inautodl));
  8057. #endif /* CK_AUTODL */
  8058.  
  8059.       case IN_CAN:                      /* SET INPUT INTERRUPTS */
  8060.         return(seton(&inintr));
  8061.     }
  8062.     return(0);
  8063. }
  8064. #endif /* NOSPL */
  8065.  
  8066. #ifdef NETCONN
  8067. VOID
  8068. ndreset() {
  8069. #ifndef NODIAL                          /* This depends on DIAL... */
  8070.     int i=0, j=0;
  8071.     if (!ndinited)                      /* Don't free garbage... */
  8072.       return;
  8073.     for (i = 0; i < nhcount; i++) {     /* Clean out previous list */
  8074.         if (nh_p[i])
  8075.           free(nh_p[i]);
  8076.         nh_p[i] = NULL;
  8077.         if (nh_p2[i])
  8078.           free(nh_p2[i]);
  8079.         nh_p2[i] = NULL;
  8080.         for (j = 0; j < 4; j++) {
  8081.             if (nh_px[j][i])
  8082.               free(nh_px[j][i]);
  8083.             nh_px[j][i] = NULL;
  8084.         }
  8085.     }
  8086. #endif /* NODIAL */
  8087. }
  8088.  
  8089. VOID
  8090. ndinit() {                              /* Net directory pointers */
  8091. #ifndef NODIAL                          /* This depends on DIAL... */
  8092.     int i, j;
  8093.     if (ndinited++)                     /* Don't do this more than once. */
  8094.       return;
  8095.     for (i = 0; i < MAXDDIR; i++) {     /* Init all pointers to NULL */
  8096.         netdir[i] = NULL;
  8097.     }
  8098.     for (i = 0; i < MAXDNUMS; i++) {
  8099.         nh_p[i] = NULL;
  8100.         nh_p2[i] = NULL;
  8101.         for (j = 0; j < 4; j++)
  8102.           nh_px[j][i] = NULL;
  8103.     }
  8104. #endif /* NODIAL */
  8105. }
  8106.  
  8107. #ifndef NODIAL
  8108. #ifdef NETCONN
  8109. VOID                                    /* Get net defaults from environment */
  8110. getnetenv() {
  8111.     char *p = NULL;
  8112.  
  8113.     makestr(&p,getenv("K_NET_DIRECTORY")); /* Dialing directories */
  8114.     if (p) {
  8115.         int i;
  8116.         xwords(p,MAXDDIR,netdir,0);
  8117.         for (i = 0; i < MAXDDIR; i++) { /* Fill in any gaps... */
  8118.             if (!netdir[i+1])
  8119.               break;
  8120.             else
  8121.               netdir[i] = netdir[i+1];
  8122.             debug(F111,"netdir[i]",netdir[i],i);
  8123.         }
  8124.         nnetdir = i;
  8125.     }
  8126. }
  8127. #endif /* NETCONN */
  8128. #endif /* NODIAL */
  8129.  
  8130. int
  8131. #ifdef CK_ANSIC
  8132. lunet(char *s)                          /* s = name to look up   */
  8133. #else
  8134. lunet(s) char *s;
  8135. #endif /* CK_ANSIC */
  8136. /* lunet */ {
  8137. #ifndef NODIAL                          /* This depends on DIAL... */
  8138.     int n, n1, t, dd = 0;
  8139.     int ambiguous = 0;
  8140.     FILE * f;
  8141.     char *line = NULL;
  8142.     extern int dialdpy;
  8143.     int netdpy = dialdpy;
  8144.     char *info[8];
  8145.  
  8146.     nhcount = 0;                        /* Set this before returning */
  8147.  
  8148.     if (!s || nnetdir < 1)              /* Validate arguments */
  8149.       return(-1);
  8150.  
  8151.     if (isdigit(*s) || *s == '*' || *s == '.')
  8152.       return(0);
  8153.  
  8154.     if ((n1 = (int) strlen(s)) < 1)     /* Length of string to look up */
  8155.       return(-1);
  8156.  
  8157.     if (!(line = malloc(1024)))         /* Allocate input buffer */
  8158.       return(-1);
  8159.  
  8160.   lu_again:
  8161.     f = NULL;                           /* Network directory file descriptor */
  8162.     t = nhcount = 0;                    /* Match count */
  8163.     dd = 0;                             /* Directory counter */
  8164.  
  8165.     dirline = 0;
  8166.     while (1) {                         /* We make one pass */
  8167.         if (!f) {                       /* Directory not open */
  8168.             if (dd >= nnetdir)          /* No directories left? */
  8169.               break;                    /* Done. */
  8170.             if ((f = fopen(netdir[dd],"r")) == NULL) { /* Open it */
  8171.                 perror(netdir[dd]);     /* Can't, print message saying why */
  8172.                 dd++;
  8173.                 continue;               /* But go on to next one. */
  8174.             }
  8175.             if (netdpy)
  8176.               printf("Opening %s...\n",netdir[dd]);
  8177.             dd++;
  8178.         }
  8179.         line[0] = NUL;
  8180.         if (getnct(line,1023,f,1) < 0) { /* Read a line */
  8181.             if (f) {                    /* f can be clobbered! */
  8182.                 fclose(f);              /* Close the file */
  8183.                 f = NULL;               /* Indicate next one needs opening */
  8184.             }
  8185.             continue;
  8186.         }
  8187.         if (!line[0])                   /* Empty line */
  8188.           continue;
  8189.  
  8190.         xwords(line,7,info,0);          /* Parse it */
  8191.  
  8192.         if (!info[1] || !info[2] || !info[3]) /* Required fields */
  8193.           continue;
  8194.         if (*info[1] == ';')            /* Full-line comment */
  8195.           continue;
  8196.         if ((n = (int) strlen(info[1])) < 1) /* Length of name-tag */
  8197.           continue;
  8198.         if (n < n1)                     /* Search name is longer */
  8199.           continue;                     /* Can't possibly match */
  8200.         if (ambiguous && n != n1)
  8201.           continue;
  8202.         if (ckstrcmp(s,info[1],n1,0))   /* Compare using length of */
  8203.           continue;                     /* search string s. */
  8204.  
  8205.         /* Have a match */
  8206.  
  8207.         makestr(&(nh_p[nhcount]), info[3]);    /* address */
  8208.         makestr(&(nh_p2[nhcount]),info[2]);    /* net type */
  8209.         makestr(&(nh_px[0][nhcount]),info[4]); /* net-specific stuff... */
  8210.         makestr(&(nh_px[1][nhcount]),info[5]);
  8211.         makestr(&(nh_px[2][nhcount]),info[6]);
  8212.         makestr(&(nh_px[3][nhcount]),info[7]);
  8213.  
  8214.         nhcount++;                      /* Count this match */
  8215.         if (nhcount > MAXDNUMS) {       /* Watch out for too many */
  8216.             printf("Warning: %d matches found, %d max\n",
  8217.                    nhcount,
  8218.                    MAXDNUMS
  8219.                    );
  8220.             nhcount = MAXDNUMS;
  8221.             break;
  8222.         }
  8223.         if (nhcount == 1) {             /* First one - save entry name */
  8224.             if (n_name) {               /* Free the one from before if any */
  8225.                 free(n_name);
  8226.                 n_name = NULL;
  8227.             }
  8228.             if (!(n_name = (char *)malloc(n + 1))) { /* Allocate new storage */
  8229.                 printf("?memory allocation error - lunet:3\n");
  8230.                 if (line) {
  8231.                     free(line);
  8232.                     line = NULL;
  8233.                 }
  8234.                 nhcount = 0;
  8235.                 return(-1);
  8236.             }
  8237.             t = n;                      /* Remember its length */
  8238.             strcpy(n_name,info[1]);     /* safe */
  8239.         } else {                        /* Second or subsequent one */
  8240.             if ((int) strlen(info[1]) == t) /* Lengths compare */
  8241.               if (!ckstrcmp(n_name,info[1],t,0)) /* Caseless compare OK */
  8242.                 continue;
  8243.  
  8244.             /* Name given by user matches entries with different names */
  8245.  
  8246.             if (ambiguous)              /* Been here before */
  8247.               break;
  8248.  
  8249.             ambiguous = 1;              /* Now an exact match is required */
  8250.             ndreset();                  /* Clear out previous list */
  8251.             goto lu_again;              /* Do it all over again. */
  8252.         }
  8253.     }
  8254.     if (line) {
  8255.         free(line);
  8256.         line = NULL;
  8257.     }
  8258.     if (nhcount == 0 && ambiguous)
  8259.       printf("?\"%s\" - ambiguous in network directory\n",s);
  8260. #else
  8261.     nhcount = 0;
  8262. #endif /* NODIAL */
  8263.     return(nhcount);
  8264. }
  8265. #endif /* NETCONN */
  8266.  
  8267. #ifndef NOLOCAL
  8268. /*  C L S C O N N X  --  Close connection  */
  8269.  
  8270. int
  8271. clsconnx(ask) int ask; {
  8272.     int x, rc = 0;
  8273. #ifdef NEWFTP
  8274.     extern int ftpget, ftpisopen(), ftpbye();
  8275.     if ((ftpget == 1) || ((ftpget == 2) && !local && ftpisopen()))
  8276.       return(success = ftpbye());
  8277. #endif /* NEWFTP */
  8278.     debug(F101,"clsconnx local","",local);
  8279.     if (local) {
  8280.         x = ask ? hupok(1) : 1;         /* Make sure it's OK to close */
  8281.         if (!x) {
  8282.             rc = -1;
  8283.             debug(F101,"clsconnx hupok says no","",rc);
  8284.             return(rc);
  8285.         }
  8286.         ttflui();                       /* Clear away buffered up junk */
  8287. #ifndef NODIAL
  8288. #ifdef OS2ONLY
  8289. /* Don't hangup a line that is shared with the SLIP or PPP driver */
  8290.         if (!ttslip && !ttppp)
  8291. #endif /* OS2ONLY */
  8292.           mdmhup();
  8293. #endif /* NODIAL */
  8294.         if (network && msgflg)
  8295.           printf(" Closing connection\n");
  8296.         ttclos(0);                      /* Close old connection, if any */
  8297.         rc = 1;
  8298.         {
  8299.             extern int wasclosed, whyclosed;
  8300.             if (wasclosed) {
  8301.                 whyclosed = WC_CLOS;
  8302. #ifndef NOSPL
  8303.                 if (nmac) {             /* Any macros defined? */
  8304.                     int k;              /* Yes */
  8305.                     /* printf("ON_CLOSE CLSCONNX\n"); */
  8306.                     wasclosed = 0;
  8307.                     k = mlook(mactab,"on_close",nmac);  /* Look this up */
  8308.                     if (k >= 0) {                       /* If found, */
  8309.                         if (dodo(k,ckitoa(whyclosed),0) > -1) /* set it up, */
  8310.                           parser(1);                    /* and execute it */
  8311.                     }
  8312.                 }
  8313. #endif /* NOSPL */
  8314.                 whyclosed = WC_REMO;
  8315.                 wasclosed = 0;
  8316.             }
  8317.         }
  8318.     }
  8319. #ifdef VMS                              /* Or maybe #ifndef UNIX? */
  8320.     else {                              /* Need to do this in VMS to */
  8321.         ttclos(0);                      /* free the tty channel number */
  8322.         rc = 1;                         /* obtained in ttopen() or else */
  8323.     }                                   /* subsequent ttopen's won't work */
  8324. #endif /* VMS */
  8325.     dologend();
  8326.     haveline = 0;
  8327.     if (mdmtyp < 0) {                   /* Switching from net to async? */
  8328.         if (mdmsav > -1)                /* Restore modem type from last */
  8329.           mdmtyp = mdmsav;              /* SET MODEM command, if any. */
  8330.         else
  8331.           mdmtyp = 0;
  8332.         mdmsav = -1;
  8333.     }
  8334.     if (network)
  8335.       network = 0;
  8336. #ifdef NETCONN
  8337.     if (oldplex > -1) {                 /* Restore previous duplex setting. */
  8338.         duplex = oldplex;
  8339.         oldplex = -1;
  8340.     }
  8341. #endif /* NETCONN */
  8342. #ifndef MAC
  8343.     ckstrncpy(ttname,dftty,TTNAMLEN);   /* Restore default communication */
  8344. #endif /* MAC */
  8345.     local = dfloc;                      /* device and local/remote status */
  8346.     if (local) {
  8347.         cxtype = CXT_DIRECT;            /* Something reasonable */
  8348.         speed = ttgspd();               /* Get the current speed */
  8349.     } else {
  8350.         cxtype = CXT_REMOTE;
  8351.         speed = -1L;
  8352.     }
  8353. #ifndef NOXFER
  8354.     if (xreliable > -1 && !setreliable) {
  8355.         reliable = xreliable;
  8356.         debug(F101,"clsconnx reliable A","",reliable);
  8357.     } else if (!setreliable) {
  8358.         reliable = SET_AUTO;
  8359.         debug(F101,"clsconnx reliable B","",reliable);
  8360.     }
  8361. #endif /* NOXFER */
  8362.     setflow();                          /* Revert flow control */
  8363.     return(rc);
  8364. }
  8365.  
  8366. int
  8367. clskconnx(x) int x; {                   /* Close Kermit connection only */
  8368.     int t, rc;                          /* (not FTP) */
  8369. #ifdef NEWFTP
  8370.     extern int ftpget;
  8371.     t = ftpget;
  8372.     ftpget = 0;
  8373. #endif /* NEWFTP */
  8374.     rc = clsconnx(x);
  8375. #ifdef NEWFTP
  8376.     ftpget = t;
  8377. #endif /* NEWFTP */
  8378.     return(rc);
  8379. }
  8380.  
  8381.  
  8382. /* S E T L I N -- parse name of and then open communication device. */
  8383. /*
  8384.   Call with:
  8385.     xx == XYLINE for a serial (tty) line, XYHOST for a network host,
  8386.     zz == 0 means if user doesn't give a device name, continue current
  8387.             active connection (if any);
  8388.     zz != 0 means if user doesn't give a device name, then close the
  8389.             current connection and restore the default communication device.
  8390.     fc == 0 to just make the connection, 1 to also CONNECT (e.g. "telnet").
  8391. */
  8392. int netsave = -1;
  8393.  
  8394. static char * tmpstring = NULL;
  8395. static char * tmpusrid = NULL;
  8396.  
  8397. #define HOSTNAMLEN 15*65
  8398.  
  8399. #ifdef SSHCMD
  8400. char * sshcmd = NULL;
  8401. char * defsshcmd = "ssh -e none";
  8402. #else
  8403. #ifdef SSHBUILTIN
  8404. char * sshrcmd = NULL;
  8405. char * sshtmpcmd = NULL;
  8406. #endif /* SSHBUILTIN */
  8407. #endif /* SSHCMD */
  8408.  
  8409. int
  8410. setlin(xx, zz, fc) int xx, zz, fc; {
  8411.     extern char pwbuf[], * g_pswd;
  8412.     extern int pwflg, pwcrypt, g_pflg, g_pcpt, nolocal;
  8413. #ifdef LOCUS
  8414.     extern int locus, autolocus;
  8415. #endif /* LOCUS */
  8416. #ifndef NODIAL
  8417.     extern int dialsta;
  8418. #endif /* NODIAL */
  8419.     int wait;
  8420.     /* int tn_wait_sv; */
  8421.     int mynet;
  8422.     int _local = -1;
  8423.     int c, i, haveswitch = 0;
  8424.     int haveuser = 0;
  8425.     int getval = 0;
  8426.     int wild = 0;                       /* Filespec has wildcards */
  8427.     int cx = 0;                         /* Connect after */
  8428.     int sx = 0;                         /* Become server after */
  8429. #ifdef CK_ENCRYPTION
  8430.     int encrypt = 0;                    /* Encrypted? */
  8431.     int e_type = -1;                    /* Telnet /ENCRYPT type */
  8432. #endif /* CK_ENCRYPTION */
  8433. #ifdef CK_AUTHENTICATION
  8434.     int a_type = -1;                    /* Authentication type */
  8435. #endif /* CK_AUTHENTICATION */
  8436. #ifdef OS2ORVMS
  8437.     int shr = 0;                        /* Share serial device */
  8438. #endif /* OS2ORVMS */
  8439.     int confirmed = 0;                  /* Command has been entered */
  8440.     struct FDB sw, tx, nx;
  8441. #ifdef OS2
  8442.     struct FDB fl;
  8443. #endif /* OS2 */
  8444.  
  8445.     char * ss;
  8446. #ifdef TCPSOCKET
  8447.     int rawflg = 0;
  8448. #endif /* TCPSOCKET */
  8449.  
  8450. #ifdef OS2
  8451. #define SRVBUFSIZ PIPENAML
  8452. #else /* OS2 */
  8453. #define SRVBUFSIZ 63
  8454. #endif /* OS2 */
  8455.  
  8456.     char srvbuf[SRVBUFSIZ+1];
  8457.     char hostname[HOSTNAMLEN];
  8458.  
  8459. #ifdef OS2
  8460. #ifdef NT
  8461.     int xxtapi = 0;
  8462. #else
  8463.     int xxslip = 0, xxppp = 0;
  8464. #endif /* NT */
  8465. #endif /* OS2 */
  8466.  
  8467.     int dossh = 0;
  8468.  
  8469.     debug(F101,"setlin fc","",fc);
  8470.     debug(F101,"setlin zz","",zz);
  8471.     debug(F101,"setlin xx","",xx);
  8472.  
  8473. #ifdef SSHCMD
  8474.     if (xx == XXSSH) {                  /* SSH becomes PTY SSH ... */
  8475.         dossh = 1;
  8476.         xx = XYHOST;
  8477.     }
  8478. #endif /* SSHCMD */
  8479.  
  8480. #ifdef TNCODE
  8481.     /* tn_wait_sv = tn_wait_flg; */
  8482.     wait = tn_wait_flg;
  8483. #else
  8484.     /* tn_wait_sv = 0; */
  8485.     wait = 0;
  8486. #endif /* TNCODE */
  8487.  
  8488.     mynet = nettype;
  8489.  
  8490.     if (nolocal) {
  8491.         makestr(&slmsg,"Making connections is disabled");
  8492.         printf("?Sorry, making connections is disabled\n");
  8493.         return(-9);
  8494.     }
  8495.     if (netsave > -1)
  8496.       nettype = netsave;
  8497.  
  8498.     if (fc != 0 || zz == 0)             /* Preset /CONNECT switch */
  8499.       cx = 1;
  8500.  
  8501.     debug(F101,"setlin cx","",cx);
  8502.  
  8503.     *srvbuf = NUL;
  8504.  
  8505.     line[0] = NUL;
  8506.     s = line;
  8507.  
  8508. #ifdef NETCONN
  8509. #ifdef CK_SECURITY
  8510.     if (tmpstring)
  8511.         makestr(&tmpstring,NULL);
  8512. #endif /* CK_SECURITY */
  8513. #ifdef RLOGCODE
  8514.     if (tmpusrid)
  8515.         makestr(&tmpusrid,NULL);
  8516. #endif /* RLOGCODE */
  8517. #endif /* NETCONN */
  8518.  
  8519.     autoflow = 1;                       /* Enable automatic flow setting */
  8520.  
  8521.     if (xx == XYHOST) {                 /* SET HOST <hostname> */
  8522. #ifndef NETCONN
  8523.         makestr(&slmsg,"Network connections not supported");
  8524.         printf("?%s\n",slmsg);
  8525.         return(-9);
  8526. #else /* NETCONN */
  8527. #ifndef NOPUSH
  8528.         if ((mynet == NET_CMD || mynet == NET_PTY) && nopush) {
  8529.             makestr(&slmsg,"Access to external commands is disabled");
  8530.             printf("?Sorry, access to external commands is disabled\n");
  8531.             return(-9);
  8532.         }
  8533. #endif /* NOPUSH */
  8534.  
  8535. #ifdef SSHCMD
  8536.         if (dossh) {                    /* SSH connection via pty */
  8537.             int k;
  8538.             k = ckstrncpy(line, sshcmd ? sshcmd : defsshcmd, LINBUFSIZ);
  8539.             debug(F111,"sshcmd 1",line,k);
  8540.             if ((x = cmtxt("Optional switches and hostname","",&s,xxstring))<0)
  8541.               return(x);
  8542.             if (!*s) {
  8543.                 printf("?SSH to where?\n");
  8544.                 return(-9);
  8545.             }
  8546.             if (k < LINBUFSIZ) {
  8547.                 line[k++] = SP;
  8548.                 line[k] = NUL;
  8549.                 debug(F111,"sshcmd 2",line,k);
  8550.             } if (k < LINBUFSIZ) {
  8551.                 ckstrncpy(&line[k],s,LINBUFSIZ-k);
  8552.                 debug(F111,"sshcmd 3",line,k);
  8553.             } else {
  8554.                 printf("?Too long\n");
  8555.                 return(-9);
  8556.             }
  8557.             mdmtyp = 0 - NET_PTY;
  8558.             x = 1;
  8559.             errno = 0;
  8560.             k = ttopen(line, &x, mdmtyp, 0); /* Open the connection */
  8561.             debug(F111,"sshcmd ttopen",line,k);
  8562.             if (k < 0) {
  8563.                 if (errno)
  8564.                   printf("?%s\n",ck_errstr());
  8565.                 else
  8566.                   printf("?Sorry, pseudoterminal open failed\n");
  8567.                 return(success = 0);
  8568.             }
  8569.             ckstrncpy(ttname,line,TTNAMLEN); /* Record the command */
  8570.             debug(F110,"ssh ttname",ttname,0);
  8571.             cxtype = CXT_PIPE;          /* Connection type = pipe */
  8572.             makestr(&slmsg,NULL);       /* No SET LINE error message */
  8573. #ifndef NODIAL
  8574.             dialsta = DIA_UNK;
  8575. #endif /* NODIAL */
  8576.             success = 1;                /* SET LINE succeeded */
  8577.             network = 1;                /* Network connection (not serial) */
  8578.             local = 1;                  /* Local mode (not remote) */
  8579.             cx = 1;                     /* Enter CONNECT mode automatically */
  8580.             goto xsetlin;               /* Go take common exit */
  8581.         }
  8582. #endif /* SSHCMD */
  8583.  
  8584. /*
  8585.   Here we parse optional switches and then the hostname or whatever,
  8586.   which depends on the network type.  The tricky part is, the network type
  8587.   can be set by a switch.
  8588. */
  8589. #ifndef NOSPL
  8590.         makestr(&g_pswd,pwbuf);         /* Save global pwbuf */
  8591.         g_pflg = pwflg;                 /* and flag */
  8592.         g_pcpt = pwcrypt;
  8593. #endif /* NOSPL */
  8594.  
  8595.         confirmed = 0;
  8596.         haveswitch = 0;
  8597. #ifdef NETFILE
  8598.         if (mynet != NET_FILE) {
  8599. #endif /* NETFILE */
  8600.             ss = (mynet == NET_CMD || mynet == NET_PTY) ?
  8601.               "Command, or switch" :
  8602.                 (mynet == NET_TCPA || mynet == NET_TCPB
  8603.                   || mynet == NET_SSH) ?
  8604.                   "Hostname, ip-address, or switch" :
  8605.                     "Host or switch";
  8606.             if (fc) {
  8607.                 if (mynet == NET_TCPB &&
  8608.                     (ttnproto == NP_TELNET || ttnproto == NP_KERMIT)) {
  8609.                     if (nshteltab) {
  8610.                         haveswitch++;
  8611.                         cmfdbi(&sw,_CMKEY,ss,"","",nshteltab,4,xxstring,
  8612.                              shteltab,&nx);
  8613.                     }
  8614.                 }
  8615. #ifdef RLOGCODE
  8616.                 else if (mynet == NET_TCPB && ttnproto == NP_RLOGIN) {
  8617.                     if (nshrlgtab) {
  8618.                         haveswitch++;
  8619.                         cmfdbi(&sw,_CMKEY,ss,"","",nshrlgtab,4,xxstring,
  8620.                                shrlgtab,&nx);
  8621.                     }
  8622.                 }
  8623. #endif /* RLOGCODE */
  8624.             } else {
  8625.                 haveswitch++;
  8626.                 cmfdbi(&sw,_CMKEY,ss,"","",nshtab,4,xxstring,shtab,&nx);
  8627.             }
  8628. #ifdef NETFILE
  8629.         }
  8630. #endif /* NETFILE */
  8631.         if (mynet == NET_TCPB || mynet == NET_SLAT || mynet == NET_SSH) {
  8632.             cmfdbi(&nx,_CMFLD,"Host","","",0,0,xxstring,NULL,NULL);
  8633. #ifdef NETFILE
  8634.         } else if (mynet == NET_FILE) {
  8635.             cmfdbi(&nx,_CMIFI,"Filename","","",0,0,xxstring,NULL,NULL);
  8636. #endif /* NETFILE */
  8637. #ifdef PTYORPIPE
  8638.         } else if (mynet == NET_CMD || mynet == NET_PTY) {
  8639.             cmfdbi(&nx,_CMTXT,"Command","","",0,0,xxstring,NULL,NULL);
  8640. #endif /* PTYORPIPE */
  8641.         } else {
  8642.             cmfdbi(&nx,_CMTXT,"Host","","",0,0,xxstring,NULL,NULL);
  8643.         }
  8644.         while (1) {
  8645.             x = cmfdb(haveswitch ? &sw : &nx);
  8646.             debug(F101,"setlin cmfdb","",x);
  8647.             if (x < 0)
  8648.               if (x != -3)
  8649.                 return(x);
  8650.             if (x == -3) {
  8651.                 if ((x = cmcfm()) < 0) {
  8652.                     return(x);
  8653.                 } else {
  8654.                     confirmed = 1;
  8655.                     break;
  8656.                 }
  8657.             }
  8658.             if (cmresult.fcode != _CMKEY) {    /* Not a switch */
  8659.                 ckstrncpy(line,cmresult.sresult,LINBUFSIZ); /* Save the data */
  8660.                 s = line;                      /* that was parsed... */
  8661.                 if (cmresult.fcode == _CMIFI) {
  8662.                     wild = cmresult.nresult;
  8663.                 } else if (cmresult.fcode == _CMTXT) {
  8664.                     confirmed = 1;
  8665.                 }
  8666.                 break;                  /* and break out of this loop */
  8667.             }
  8668.             c = cmgbrk();               /* Have switch - get break character */
  8669.             getval = (c == ':' || c == '='); /* Must parse an agument? */
  8670.             if (getval && !(cmresult.kflags & CM_ARG)) {
  8671.                 printf("?This switch does not take arguments\n");
  8672.                 return(-9);
  8673.             }
  8674.             if (!getval && (cmgkwflgs() & CM_ARG)) {
  8675.                 printf("?This switch requires an argument\n");
  8676.                 return(-9);
  8677.             }
  8678.             switch (cmresult.nresult) { /* It's a switch.. */
  8679.               case SL_CNX:              /* /CONNECT */
  8680.                 cx = 1;
  8681.                 sx = 0;
  8682.                 break;
  8683.               case SL_SRV:              /* /SERVER */
  8684.                 cx = 0;
  8685.                 sx = 1;
  8686.                 break;
  8687. #ifdef NETCMD
  8688.               case SL_CMD:              /* /COMMAND */
  8689.                 netsave = mynet;
  8690.                 mynet = NET_CMD;
  8691.                 break;
  8692. #endif /* NETCMD */
  8693. #ifdef NETPTY
  8694.               case SL_PTY:              /* /PTY */
  8695.                 netsave = mynet;
  8696.                 mynet = NET_PTY;
  8697.                 break;
  8698. #endif /* NETPTY */
  8699.               case SL_NET:              /* /NETWORK-TYPE */
  8700.                 if ((x = cmkey(netcmd,nnets,"","",xxstring)) < 0)
  8701.                   return(x);
  8702.                 mynet = x;
  8703.                 break;
  8704.  
  8705. #ifdef CK_SECURITY
  8706.               case SL_PSW:              /* /PASSWORD: */
  8707.                 if (!getval)
  8708.                   break;
  8709.                 debok = 0;
  8710.                 if ((x = cmfld("Password","",&s,xxstring)) < 0) {
  8711.                     if (x == -3) {
  8712.                         makestr(&tmpstring,"");
  8713.                     } else {
  8714.                         return(x);
  8715.                     }
  8716.                 } else {
  8717.                     s = brstrip(s);
  8718.                     if ((x = (int)strlen(s)) > PWBUFL) {
  8719.                         makestr(&slmsg,"Internal error");
  8720.                         printf("?Sorry, too long - max = %d\n",PWBUFL);
  8721.                         return(-9);
  8722.                     }
  8723.                     makestr(&tmpstring,s);
  8724.                 }
  8725.                 break;
  8726. #endif /* CK_SECURITY */
  8727.  
  8728.               case SL_UID:              /* /USERID: */
  8729.                 if (!getval)
  8730.                   break;
  8731.                 if ((x = cmfld("Userid","",&s,xxstring)) < 0) {
  8732.                     if (x == -3) {
  8733.                         makestr(&tmpusrid,"");
  8734.                     } else {
  8735.                         return(x);
  8736.                     }
  8737.                 } else {
  8738.                     s = brstrip(s);
  8739.                     if ((x = (int)strlen(s)) > 63) {
  8740.                         makestr(&slmsg,"Internal error");
  8741.                         printf("?Sorry, too long - max = %d\n",63);
  8742.                         return(-9);
  8743.                     }
  8744.                     makestr(&tmpusrid,s);
  8745.                     haveuser = 1;
  8746.                 }
  8747.                 break;
  8748.  
  8749. #ifdef CK_AUTHENTICATION
  8750. #ifdef CK_SRP
  8751.               case SL_SRP:
  8752.                 a_type = AUTHTYPE_SRP;
  8753.                 break;
  8754. #endif /* CK_SRP */
  8755. #ifdef CK_SSL
  8756.               case SL_SSL:
  8757.                 a_type = AUTHTYPE_SSL;
  8758.                 break;
  8759. #endif /* CK_SSL */
  8760. #ifdef NT
  8761.               case SL_NTLM:
  8762.                 a_type = AUTHTYPE_NTLM;
  8763.                 break;
  8764. #endif /* NT */
  8765. #ifdef CK_KERBEROS
  8766.               case SL_KRB4:
  8767.                 a_type = AUTHTYPE_KERBEROS_V4;
  8768.                 if (ttnproto == NP_RLOGIN)
  8769.                   ttnproto =
  8770. #ifdef CK_ENCRYPTION
  8771.                     encrypt ? NP_EK4LOGIN :
  8772. #endif /* CK_ENCRYPTION */
  8773.                       NP_K4LOGIN;
  8774.                 else if (ttnproto == NP_K5LOGIN)
  8775.                   ttnproto = NP_K4LOGIN;
  8776. #ifdef CK_ENCRYPTION
  8777.                 else if (ttnproto == NP_EK5LOGIN)
  8778.                   ttnproto = NP_EK4LOGIN;
  8779. #endif /* CK_ENCRYPTION */
  8780.                 break;
  8781.               case SL_KRB5:
  8782.                 a_type = AUTHTYPE_KERBEROS_V5;
  8783.                 if (ttnproto == NP_RLOGIN)
  8784.                   ttnproto =
  8785. #ifdef CK_ENCRYPTION
  8786.                     encrypt ? NP_EK5LOGIN :
  8787. #endif /* CK_ENCRYPTION */
  8788.                       NP_K5LOGIN;
  8789.                 else if (ttnproto == NP_K4LOGIN)
  8790.                   ttnproto = NP_K5LOGIN;
  8791. #ifdef CK_ENCRYPTION
  8792.                 else if (ttnproto == NP_EK4LOGIN)
  8793.                   ttnproto = NP_EK5LOGIN;
  8794. #endif /* CK_ENCRYPTION */
  8795.                 break;
  8796. #endif /* CK_KERBEROS */
  8797.               case SL_AUTH: {
  8798.                   extern struct keytab autyptab[];
  8799.                   extern int nautyp;
  8800.                   if ((x = cmkey(autyptab,nautyp,"type of authentication",
  8801.                                  "automatic",xxstring)) < 0)
  8802.                     return(x);
  8803.                   a_type = x;
  8804.                   break;
  8805.               }
  8806. #endif /* CK_AUTHENTICATION */
  8807. #ifdef CK_ENCRYPTION
  8808.               case SL_ENC:
  8809.                 switch (ttnproto) {
  8810.                   case NP_K4LOGIN:
  8811.                     ttnproto = NP_EK4LOGIN;
  8812.                     encrypt = 1;
  8813.                     break;
  8814.                   case NP_K5LOGIN:
  8815.                     ttnproto = NP_EK5LOGIN;
  8816.                     encrypt = 1;
  8817.                     break;
  8818.                   case NP_KERMIT:
  8819.                   case NP_TELNET: {
  8820.                       static struct keytab * tnetbl = NULL;
  8821.                       static int ntnetbl = 0;
  8822.                       x = ck_get_crypt_table(&tnetbl,&ntnetbl);
  8823.                       debug(F101,"ck_get_crypt_table x","",x);
  8824.                       debug(F101,"ck_get_crypt_table n","",ntnetbl);
  8825.                       if (x < 1 || !tnetbl || ntnetbl < 1) /* Didn't get it */
  8826.                         x = 0;
  8827.                       if (!x) {
  8828.                           makestr(&slmsg,"Internal error");
  8829.                           printf("?Oops, types not loaded\n");
  8830.                           return(-9);
  8831.                       }
  8832.                       if ((x = cmkey(tnetbl,ntnetbl,"type of encryption",
  8833.                                      "automatic",xxstring)) < 0)
  8834.                         return(x);
  8835.                       e_type = x;
  8836.                       break;
  8837.                   }
  8838.                 }
  8839.                 break;
  8840. #endif /* CK_ENCRYPTION */
  8841.               case SL_WAIT:
  8842.                 wait = 1;
  8843.                 break;
  8844.               case SL_NOWAIT:
  8845.                 wait = 0;
  8846.                 break;
  8847.             }
  8848.         }
  8849.  
  8850. #ifdef NETFILE
  8851.         if (mynet == NET_FILE)          /* Parsed by cmifi() */
  8852.           if ((x = cmcfm()) < 0)        /* Needs confirmation */
  8853.             return(x);
  8854. #endif /* NETFILE */
  8855.  
  8856. #ifdef NETCMD
  8857.         if (mynet == NET_CMD || mynet == NET_PTY) {
  8858.             char *p = NULL;
  8859.             if (!confirmed) {
  8860.                 if ((x = cmtxt("Rest of command","",&s,xxstring)) < 0)
  8861.                   return(x);
  8862.                 if (*s) {
  8863.                     strncat(line," ",LINBUFSIZ);
  8864.                     strncat(line,s,LINBUFSIZ);
  8865.                 }
  8866.                 s = line;
  8867.             }
  8868.             s = brstrip(s);
  8869.             makestr(&p,s);              /* what's all this then? */
  8870.             ckstrncpy(line,p,LINBUFSIZ);
  8871.             makestr(&p,NULL);
  8872.             s = line;
  8873.         }
  8874.         debug(F110,"SUNDAY 2",line,0);
  8875. #endif /* NETCMD */
  8876.  
  8877. #ifdef NPIPE                            /* Named pipe */
  8878.         if (mynet == NET_PIPE) {        /* Needs backslash twiddling */
  8879.             if (*s) {
  8880.                 if (strcmp(s,"*")) {    /* If remote, begin with */
  8881.                     ckstrncpy(line,"\\\\",LINBUFSIZ); /* server name */
  8882.                     ckstrncat(line,s,LINBUFSIZ);
  8883.                 } else {
  8884.                     line[0]='\0';
  8885.                 }
  8886.                 ckstrncat(line,"\\pipe\\", LINBUFSIZ); /* Make pipe name */
  8887.                 ckstrncat(line,pipename, LINBUFSIZ); /* Add name of pipe */
  8888.                 s = line;
  8889.             }
  8890.         }
  8891. #endif /* NPIPE */
  8892.  
  8893. #ifdef SUPERLAT
  8894.         if (mynet == NET_SLAT) {        /* Needs password, etc. */
  8895.             slat_pwd[0] = NUL;          /* Erase any previous password */
  8896.             debok = 0;
  8897.             if (*s) {                   /* If they gave a host name... */
  8898.                 if ((x = cmfld(
  8899.                      "password,\n or carriage return if no password required",
  8900.                                "",
  8901.                                &s,
  8902.                                xxstring
  8903.                                )) < 0 && x != -3)
  8904.                   return(x);
  8905.                 ckstrncpy(slat_pwd,s,18); /* Set the password, if any */
  8906.             }
  8907.             if ((x = cmcfm()) < 0) return(x); /* Confirm the command */
  8908.             s = line;
  8909.         }
  8910. #endif /* SUPERLAT */
  8911.  
  8912. #ifdef SSHBUILTIN
  8913.         if (mynet == NET_SSH) { /* SSH connection */
  8914.             int k, x, havehost = 0, trips = 0;
  8915.             int    tmpver = -1, tmpxfw = -1;
  8916. #ifndef SSHTEST
  8917.             extern int sl_ssh_xfw, sl_ssh_xfw_saved;
  8918.             extern int sl_ssh_ver, sl_ssh_ver_saved;
  8919. #endif /* SSHTEST */
  8920.             extern int mdmtyp, mdmsav, cxtype, sl_uid_saved;
  8921.             extern char * slmsg;
  8922.             extern char uidbuf[], sl_uidbuf[];
  8923.             extern struct keytab sshopnsw[];
  8924.             extern int nsshopnsw;
  8925.             extern char * ssh_tmpuid, *ssh_tmpcmd, *ssh_tmpport;
  8926.             struct FDB sw, kw, fl;
  8927.  
  8928.             debug(F110,"setlin SSH service 0",srvbuf,0);
  8929.             debug(F110,"setlin SSH host s 2",s,0);
  8930.             if (*s) {           /* If they gave a host name... */
  8931.                 debug(F110,"setlin SSH host s 1",s,0);
  8932.                 if (*s == '*') {
  8933.                     makestr(&slmsg,"Incoming connections not supported");
  8934.                     printf(
  8935.      "?Sorry, incoming connections not supported for SSH.\n"
  8936.                            );
  8937.                     return(-9);
  8938.                 }
  8939.                 ckstrncpy(line,s,LINBUFSIZ);
  8940.             } else {
  8941.                 printf("?hostname required\n");
  8942.                 return(-3);
  8943.             }
  8944.  
  8945.             /* Parse [ port ] [ switches ] */
  8946.             cmfdbi(&kw,                 /* Switches */
  8947.                     _CMKEY,
  8948.                     "Port number or service name,\nor switch",
  8949.                     "",
  8950.                     "",
  8951.                     nsshopnsw,
  8952.                     4,
  8953.                     xxstring,
  8954.                     sshopnsw,
  8955.                     &fl
  8956.                     );
  8957.             cmfdbi(&fl,                 /* Port number or service name */
  8958.                     _CMFLD,
  8959.                     "",
  8960.                     "",
  8961.                     "",
  8962.                     0,
  8963.                     0,
  8964.                     xxstring,
  8965.                     NULL,
  8966.                     NULL
  8967.                     );
  8968.             trips = 0;                  /* Explained below */
  8969.             while (1) {                 /* Parse port and switches */
  8970.                 x = cmfdb(&kw);         /* Get a field */
  8971.                 if (x == -3)            /* User typed CR so quit from loop */
  8972.                     break;
  8973.                 if (x < 0)              /* Other parse error, pass it back */
  8974.                     return(x);
  8975.                 switch (cmresult.fcode) { /* Field or Keyword? */
  8976.                 case _CMFLD:              /* Field */
  8977.                     makestr(&ssh_tmpport,cmresult.sresult);
  8978.                     break;
  8979.                 case _CMKEY:            /* Keyword */
  8980.                     switch (cmresult.nresult) { /* Which one? */
  8981.                     case SSHSW_PWD:
  8982.                         if (!cmgbrk()) {
  8983.                             printf("?This switch requires an argument\n");
  8984.                             return(-9);
  8985.                         }
  8986.                         debok = 0;
  8987.                         if ((x = cmfld("Password","",&s,xxstring)) < 0) {
  8988.                             if (x == -3) {
  8989.                                 makestr(&tmpstring,"");
  8990.                             } else {
  8991.                                 return(x);
  8992.                             }
  8993.                         } else {
  8994.                             s = brstrip(s);
  8995.                             if ((x = (int)strlen(s)) > PWBUFL) {
  8996.                                 makestr(&slmsg,"Internal error");
  8997.                                 printf("?Sorry, too long - max = %d\n",PWBUFL);
  8998.                                 return(-9);
  8999.                             }
  9000.                             makestr(&tmpstring,s);
  9001.                         }
  9002.                         break;
  9003.                     case SSHSW_USR:             /* /USER: */
  9004.                         if (!cmgbrk()) {
  9005.                             printf("?This switch requires an argument\n");
  9006.                             return(-9);
  9007.                         }
  9008.                         if ((y = cmfld("Username","",&s,xxstring)) < 0)
  9009.                             return(y);
  9010.                         s = brstrip(s);
  9011.                         makestr(&ssh_tmpuid,s);
  9012.                         break;
  9013.                     case SSHSW_VER:
  9014.                         if ((x = cmnum("Number","",10,&z,xxstring)) < 0)
  9015.                             return(x);
  9016.                         if (z < 1 || z > 2) {
  9017.                             printf("?Out of range: %d\n",z);
  9018.                             return(-9);
  9019.                         }
  9020.                         tmpver = z;
  9021.                         break;
  9022.                     case SSHSW_CMD:
  9023.                     case SSHSW_SUB:
  9024.                         if ((x = cmfld("Text","",&s,xxstring)) < 0)
  9025.                           return(x);
  9026.                         makestr(&ssh_tmpcmd,s);
  9027.                         ssh_cas = (cmresult.nresult == SSHSW_SUB);
  9028.                         break;
  9029.                     case SSHSW_X11:
  9030.                         if ((x = cmkey(onoff,2,"","on",xxstring)) < 0)
  9031.                             return(x);
  9032.                         tmpxfw = x;
  9033.                         break;
  9034.                     default:
  9035.                         return(-2);
  9036.                     }
  9037.                 }
  9038.                 if (trips++ == 0) {     /* After first time through */
  9039.                     cmfdbi(&kw,         /* only parse switches, not port. */
  9040.                             _CMKEY,
  9041.                             "Switch",
  9042.                             "",
  9043.                             "",
  9044.                             nsshopnsw,
  9045.                             4,
  9046.                             xxstring,
  9047.                             sshopnsw,
  9048.                             NULL
  9049.                             );
  9050.                 }
  9051.             }
  9052.             if ((x = cmcfm()) < 0)      /* Get confirmation */
  9053.                 return(x);
  9054.             makestr(&ssh_hst,line);        /* Stash everything */
  9055.             if (ssh_tmpuid) {
  9056.                 if (!sl_uid_saved) {
  9057.                     ckstrncpy(sl_uidbuf,uidbuf,UIDBUFLEN);
  9058.                     sl_uid_saved = 1;
  9059.                 }
  9060.                 ckstrncpy(uidbuf,ssh_tmpuid,UIDBUFLEN);
  9061.                 makestr(&ssh_tmpuid,NULL);
  9062.             }
  9063.             if (ssh_tmpport) {
  9064.                 makestr(&ssh_prt,ssh_tmpport);
  9065.                 makestr(&ssh_tmpport,NULL);
  9066.             } else
  9067.                 makestr(&ssh_prt,NULL);
  9068.  
  9069.             if (ssh_tmpcmd) {
  9070.                 makestr(&ssh_cmd,brstrip(ssh_tmpcmd));
  9071.                 makestr(&ssh_tmpcmd,NULL);
  9072.             } else
  9073.                 makestr(&ssh_cmd,NULL);
  9074.  
  9075.             if (tmpver > -1) {
  9076. #ifndef SSHTEST
  9077.                 if (!sl_ssh_ver_saved) {
  9078.                     sl_ssh_ver = ssh_ver;
  9079.                     sl_ssh_ver_saved = 1;
  9080.                 }
  9081. #endif /* SSHTEST */
  9082.                 ssh_ver = tmpver;
  9083.             }
  9084.             if (tmpxfw > -1) {
  9085. #ifndef SSHTEST
  9086.                 if (!sl_ssh_xfw_saved) {
  9087.                     sl_ssh_xfw = ssh_xfw;
  9088.                     sl_ssh_xfw_saved = 1;
  9089.                 }
  9090. #endif /* SSHTEST */
  9091.                 ssh_xfw = tmpxfw;
  9092.             }
  9093.             s = ssh_hst;
  9094.         }
  9095. #endif /* SSHBUILTIN */
  9096.  
  9097. #ifdef TCPSOCKET
  9098.         if (mynet == NET_TCPB) {        /* TCP/IP connection */
  9099.             debug(F110,"setlin service 0",srvbuf,0);
  9100.             debug(F110,"setlin host s 2",s,0);
  9101.             if (*s) {           /* If they gave a host name... */
  9102.                 debug(F110,"setlin host s 1",s,0);
  9103. #ifdef NOLISTEN
  9104.                 if (*s == '*') {
  9105.                     makestr(&slmsg,"Incoming connections not supported");
  9106.                     printf(
  9107.      "?Sorry, incoming connections not supported in this version of Kermit.\n"
  9108.                            );
  9109.                     return(-9);
  9110.                 }
  9111. #endif /* NOLISTEN */
  9112. #ifdef RLOGCODE
  9113.                 /* Allow a username if rlogin is requested */
  9114.                 if (mynet == NET_TCPB &&
  9115.                     (ttnproto == NP_RLOGIN || ttnproto == NP_K5LOGIN ||
  9116.                      ttnproto == NP_EK5LOGIN || ttnproto == NP_K4LOGIN ||
  9117.                      ttnproto == NP_EK4LOGIN
  9118.                     )) {
  9119.                     int y;
  9120.                     uidflag = 0;
  9121.                     /* Check for "host:service" */
  9122.                     for ( ; (*s != '\0') && (*s != ':'); s++) ;
  9123.                     if (*s) {   /* Service, save it */
  9124.                         *s = NUL;
  9125.                         ckstrncpy(srvbuf,++s,SRVBUFSIZ);
  9126.                     } else {            /* No :service, then use default. */
  9127. #ifdef VMS
  9128.                         switch (ttnproto) {
  9129.                           case NP_RLOGIN:
  9130.                             ckstrncpy(srvbuf,"513",SRVBUFSIZ); /* "login" */
  9131.                             break;
  9132.                           case NP_K4LOGIN:
  9133.                           case NP_K5LOGIN:
  9134.                             ckstrncpy(srvbuf,"543",SRVBUFSIZ); /* "klogin" */
  9135.                             break;
  9136.                           case NP_EK4LOGIN:
  9137.                           case NP_EK5LOGIN:
  9138.                             ckstrncpy(srvbuf,"2105",SRVBUFSIZ); /* "eklogin" */
  9139.                             break;
  9140.                         }
  9141. #else /* VMS */
  9142.                         switch (ttnproto) {
  9143.                           case NP_RLOGIN:
  9144.                             ckstrncpy(srvbuf,"login",SRVBUFSIZ);
  9145.                             break;
  9146.                           case NP_K4LOGIN:
  9147.                           case NP_K5LOGIN:
  9148.                             ckstrncpy(srvbuf,"klogin",SRVBUFSIZ);
  9149.                             break;
  9150.                           case NP_EK4LOGIN:
  9151.                           case NP_EK5LOGIN:
  9152.                             ckstrncpy(srvbuf,"eklogin",SRVBUFSIZ);
  9153.                             break;
  9154.                         }
  9155. #endif /* VMS */
  9156.                     }
  9157.                     if (!confirmed) {
  9158.                         y = cmfld("Userid on remote system",
  9159.                                   uidbuf,&s,xxstring);
  9160.                         if (y < 0 && y != -3)
  9161.                           return(y);
  9162.                         if ((int)strlen(s) > 63) {
  9163.                             makestr(&slmsg,"Internal error");
  9164.                             printf("Sorry, too long\n");
  9165.                             return(-9);
  9166.                         }
  9167.                         makestr(&tmpusrid,s);
  9168.                     }
  9169.                 } else {        /* TELNET or SET HOST */
  9170. #endif /* RLOGCODE */
  9171.                     /* s = line; */
  9172.                     /* Check for "host:service" */
  9173.                     for ( ; (*s != '\0') && (*s != ':'); s++) ;
  9174.                     if (*s) {   /* Service, save it */
  9175.                         *s = NUL;
  9176.                         ckstrncpy(srvbuf,++s,SRVBUFSIZ);
  9177.                     } else if (!confirmed) {
  9178.                         /* No :service, let them type one. */
  9179.                         if (*line != '*') { /* Not incoming */
  9180.                             if (mynet == NET_TCPB && ttnproto == NP_KERMIT) {
  9181.                                 if ((x = cmfld(
  9182.                                                "TCP service name or number",
  9183.                                                "kermit",&s,xxstring)
  9184.                                      ) < 0 && x != -3)
  9185.                                   return(x);
  9186. #ifdef RLOGCODE
  9187.                             } else if (mynet == NET_TCPB &&
  9188.                                        ttnproto == NP_RLOGIN) {
  9189.                                 if ((x = cmfld(
  9190.   "TCP service name or number,\n or carriage return for rlogin (513)",
  9191.                                                "login",&s,xxstring)
  9192.                                      ) < 0 && x != -3)
  9193.                                   return(x);
  9194. #ifdef CK_AUTHENTICATION
  9195. #ifdef CK_KERBEROS
  9196.                             } else if (mynet == NET_TCPB &&
  9197.                                        (ttnproto == NP_K4LOGIN ||
  9198.                                        ttnproto == NP_K5LOGIN)) {
  9199.                                 if ((x = cmfld(
  9200.   "TCP service name or number,\n or carriage return for klogin (543)",
  9201.                                                "klogin",&s,xxstring)
  9202.                                      ) < 0 && x != -3)
  9203.                                   return(x);
  9204.                             } else if (mynet == NET_TCPB &&
  9205.                                        (ttnproto == NP_EK4LOGIN ||
  9206.                                         ttnproto == NP_EK5LOGIN)) {
  9207.                                 if ((x = cmfld(
  9208.   "TCP service name or number,\n or carriage return for eklogin (2105)",
  9209.                                                "eklogin",&s,xxstring)
  9210.                                      ) < 0 && x != -3)
  9211.                                   return(x);
  9212. #endif /* CK_KERBEROS */
  9213. #endif /* CK_AUTHENTICATION */
  9214. #endif /* RLOGCODE */
  9215.                             } else {
  9216.                                 /* Do not set a default value in this call */
  9217.                                 /* If you do then it will prevent entries  */
  9218.                                 /* in the network directory from accessing */
  9219.                                 /* alternate ports.                        */
  9220.  
  9221.                                 if ((x = cmfld(
  9222.                                                "TCP service name or number",
  9223.                                                "",&s,xxstring)
  9224.                                      ) < 0 && x != -3)
  9225.                                   return(x);
  9226.                             }
  9227.                         } else { /* Incoming connection */
  9228.                             if ((x = cmfld("TCP service name or number",
  9229.                                            "",&s,xxstring)
  9230.                                  ) < 0 && x != -3)
  9231.                               return(x);
  9232.                         }
  9233.                         if (*s)         /* If they gave a service, */
  9234.                           ckstrncpy(srvbuf,s,SRVBUFSIZ); /* copy it */
  9235.                         debug(F110,"setlin service 0.5",srvbuf,0);
  9236.                     }
  9237. #ifdef RLOGCODE
  9238.                 }
  9239. #endif /* RLOGCODE */
  9240.                 if (!confirmed) {
  9241.                     char * defproto;
  9242.                     switch (ttnproto) {
  9243.                       case NP_RLOGIN:
  9244.                         defproto = "/rlogin";
  9245.                         break;
  9246.                       case NP_K4LOGIN:
  9247.                         defproto = "/k4login";
  9248.                         break;
  9249.                       case NP_K5LOGIN:
  9250.                         defproto = "/k5login";
  9251.                         break;
  9252.                       case NP_EK4LOGIN:
  9253.                         defproto = "/ek4login";
  9254.                         break;
  9255.                       case NP_EK5LOGIN:
  9256.                         defproto = "/ek5login";
  9257.                         break;
  9258.                       case NP_KERMIT:
  9259.                       case NP_TELNET:
  9260.                         defproto = "/telnet";
  9261.                         break;
  9262.                       default:
  9263.                         defproto = "/default";
  9264.                     }
  9265.                     if ((x = cmkey(tcprawtab,ntcpraw,"Switch",defproto,
  9266.                                    xxstring)) < 0) {
  9267.                         if (x != -3)
  9268.                           return(x);
  9269.                         else if ((x = cmcfm()) < 0)
  9270.                           return(x);
  9271.                     } else {
  9272.                         rawflg = x;
  9273.                         if ((x = cmcfm()) < 0)
  9274.                           return(x);
  9275.                         switch (rawflg) {
  9276. #ifdef CK_SSL
  9277.                           case NP_SSL:
  9278.                             ttnproto = rawflg;
  9279.                             ssl_only_flag = 1;
  9280.                             tls_only_flag = 0;
  9281.                             break;
  9282.  
  9283.                           case NP_TLS:
  9284.                             ttnproto = rawflg;
  9285.                             ssl_only_flag = 0;
  9286.                             tls_only_flag = 1;
  9287.                             break;
  9288.  
  9289.                           case NP_SSL_TELNET:
  9290.                             ttnproto = NP_TELNET;
  9291.                             ssl_only_flag = 1;
  9292.                             tls_only_flag = 0;
  9293.                             break;
  9294.  
  9295.                           case NP_TLS_TELNET:
  9296.                             ttnproto = NP_TELNET;
  9297.                             ssl_only_flag = 0;
  9298.                             tls_only_flag = 1;
  9299.                             break;
  9300. #endif /* CK_SSL */
  9301.                           case NP_NONE:
  9302.                           case NP_TCPRAW:
  9303.                           case NP_RLOGIN:
  9304.                           case NP_K4LOGIN:
  9305.                           case NP_K5LOGIN:
  9306.                           case NP_EK4LOGIN:
  9307.                           case NP_EK5LOGIN:
  9308.                           case NP_TELNET:
  9309.                           case NP_KERMIT:
  9310.                           default:
  9311.                             ttnproto = rawflg;
  9312. #ifdef CK_SSL
  9313.                             ssl_only_flag = 0;
  9314.                             tls_only_flag = 0;
  9315. #endif /* CK_SSL */
  9316.                             break;
  9317.                         }
  9318.                     }
  9319.                 }
  9320.             }
  9321.             s = line;
  9322.         }
  9323. #endif /* TCPSOCKET */
  9324.  
  9325.         if (!*s) {
  9326.             if (!network) {
  9327.                 makestr(&slmsg,"Hostname or address required");
  9328.                 printf("?%s\n",slmsg);
  9329.                 return(-9);
  9330.             } else if (!zz) { /* No hostname given */
  9331. #ifdef CKLOGDIAL
  9332. #ifdef NETCONN
  9333.                 dolognet();
  9334. #endif /* NETCONN */
  9335. #endif /* CKLOGDIAL */
  9336. #ifdef LOCUS
  9337.                 if (autolocus) {
  9338.                     if (!locus && msgflg)
  9339.                       printf(
  9340.                     "Switching LOCUS for file-management commands to LOCAL.\n"
  9341.                              );
  9342.                     locus = 1;
  9343.                 }
  9344. #endif /* LOCUS */
  9345.                 if (cx) {
  9346.                   /* Command was confirmed so we can pre-pop command level. */
  9347.                   /* This is so CONNECT module won't think we're executing a */
  9348.                   /* script if CONNECT was the final command in the script. */
  9349.  
  9350.                     if (cmdlvl > 0)
  9351.                       prepop();
  9352. #ifndef NODIAL
  9353.                     dialsta = DIA_UNK;
  9354. #endif /* NODIAL */
  9355.                     success = doconect(0,cmdlvl == 0 ? 1 : 0);
  9356.                     if (ttchk() < 0)
  9357.                       dologend();
  9358.                     return(success);
  9359.                 } else
  9360.                   return(1);
  9361.             }
  9362.         }
  9363.  
  9364. #ifndef NODIAL
  9365.         /* Look up in network directory */
  9366.         x = 0;
  9367.         debug(F101,"setlin mynet 1","",mynet);
  9368.         debug(F111,"setlin nnetdir",s,nnetdir);
  9369.         if (*s == '=') {                /* If number starts with = sign */
  9370.             s++;                        /* strip it */
  9371.             while (*s == SP) s++;       /* and any leading spaces */
  9372.             ckstrncpy(line,s,LINBUFSIZ); /* Do this again. */
  9373.             s = line;
  9374.             debug(F110,"setlin host s 3",s,0);
  9375.             nhcount = 0;
  9376.         } else if (*s) {                /* We want to look it up. */
  9377.             if (nnetdir > 0)            /* If there is a directory... */
  9378.               x = lunet(line);          /* (sets nhcount) */
  9379.             else                        /* otherwise */
  9380.               nhcount = 0;              /* we didn't find any there */
  9381.             if (x < 0) {                /* Internal error? */
  9382.                 makestr(&slmsg,"Network directory lookup error");
  9383.                 printf("?Fatal network directory lookup error - %s\n",line);
  9384.                 return(-9);
  9385.             }
  9386.             debug(F111,"setlin lunet nhcount",line,nhcount);
  9387.         }
  9388. #endif /* NODIAL */
  9389.  
  9390.         /* New connection wanted.  Make a copy of the host name/address... */
  9391.  
  9392.         ckstrncpy(tmpbuf,s,TMPBUFSIZ);  /* Because we are reusing line[] */
  9393.         s = tmpbuf;                     /* for net directory entries...  */
  9394.         debug(F111,"setlin host s 5",s,mdmtyp);
  9395.         if (clskconnx(1) < 0)           /* Close current Kermit connection */
  9396.           return(success = 0);
  9397.         if (*s) {                       /* They gave a hostname */
  9398.             _local = 1;                 /* Network connection always local */
  9399.             if (mdmsav < 0)
  9400.               mdmsav = mdmtyp;          /* Remember old modem type */
  9401.             mdmtyp = -mynet;            /* Special code for network */
  9402.         } else {                        /* They just said "set host" */
  9403.             s = dftty;                  /* So go back to normal */
  9404.             _local = dfloc;             /* default tty, location, */
  9405.             if (zz) {
  9406.                 setflow();              /* Maybe change flow control */
  9407.                 haveline = 1;           /* (* is this right? *) */
  9408.                 dologend();
  9409. #ifndef NODIAL
  9410.                 dialsta = DIA_UNK;
  9411. #endif /* NODIAL */
  9412. #ifdef LOCUS
  9413.                 if (autolocus) {
  9414.                     if (!locus && msgflg)
  9415.                       printf(
  9416.                     "Switching LOCUS for file-management commands to LOCAL.\n"
  9417.                              );
  9418.                     locus = 1;
  9419.                 }
  9420. #endif /* LOCUS */
  9421.                 return(success = 1);
  9422.             }
  9423.         }
  9424. #endif /* NETCONN */
  9425.     }
  9426.  
  9427. /* Serial tty device, possibly modem, connection... */
  9428.  
  9429.     if (xx == XYLINE                    /* SET LINE or SET PORT */
  9430. #ifdef CK_TAPI
  9431.         || xx == XYTAPI_LIN             /* SET TAPI LINE */
  9432. #endif /* CK_TAPI */
  9433.         ) {
  9434. #ifdef OS2
  9435. /*
  9436.   User can type:
  9437.     COM1..COM8 = Regular COM port
  9438.     1..8       = Synonym for COM1..COM8, is translated to COM1..COM8
  9439.     _n         = (n is a number) = open file handle
  9440.     string     = any text string = name of some other kind of device,
  9441.                  taken literally, as given.
  9442. */
  9443.         s = "Communication device name";
  9444. #ifdef CK_TAPI
  9445.         if (TAPIAvail)
  9446.           cktapiBuildLineTable(&tapilinetab, &_tapilinetab, &ntapiline);
  9447.         if (!(tapilinetab && _tapilinetab && ntapiline > 0) &&
  9448.             xx == XYTAPI_LIN ) {
  9449.             makestr(&slmsg,"TAPI device not configured");
  9450.             printf("\nNo TAPI Line Devices are configured for this system\n");
  9451.             return(-9);
  9452.         }
  9453.         if (xx == XYTAPI_LIN) {         /* Default (first) TAPI line */
  9454.             s = "tapi";                 /* (whatever it is) */
  9455.         } else {                        /* Query the user */
  9456. #endif /* CK_TAPI */
  9457.  
  9458. /* Now parse optional switches and then device name */
  9459.  
  9460.             confirmed = 0;
  9461.             cmfdbi(&sw,_CMKEY,"Device name, or switch",
  9462.                    "","",npsltab,4,xxstring,psltab,&fl);
  9463.             cmfdbi(&fl,_CMFLD,"",dftty,"",0,0,xxstring,NULL,NULL);
  9464.             while (1) {
  9465.                 x = cmfdb(&sw);
  9466.                 debug(F101,"setlin cmfdb","",x);
  9467.                 if (x < 0)
  9468.                   if (x != -3)
  9469.                     return(x);
  9470.                 if (x == -3) {
  9471.                     if ((x = cmcfm()) < 0) {
  9472.                         return(x);
  9473.                     } else {
  9474.                         confirmed = 1;
  9475.                         break;
  9476.                     }
  9477.                 }
  9478.                 if (cmresult.fcode == _CMFLD) {
  9479.                     s = cmresult.sresult;
  9480.                     break;
  9481.                 } else if (cmresult.fcode == _CMKEY) {
  9482.                     switch (cmresult.nresult) {
  9483.                       case SL_CNX:      /* /CONNECT */
  9484.                         cx = 1;
  9485.                         sx = 0;
  9486.                         break;
  9487.                       case SL_SRV:      /* /SERVER */
  9488.                         cx = 0;
  9489.                         sx = 1;
  9490.                         break;
  9491.                       case SL_SHR:      /* /SHARE */
  9492.                         shr = 1;
  9493.                         break;
  9494.                       case SL_NSH:      /* /NOSHARE */
  9495.                         shr = 0;
  9496.                         break;
  9497.                     }
  9498.                 }
  9499.             }
  9500. #ifdef CK_TAPI
  9501.         }
  9502. #endif /* CK_TAPI */
  9503.  
  9504.         debug(F110,"OS2 SET PORT s",s,0);
  9505.         y = lookup(os2devtab,s,nos2dev,&x); /* Look up in keyword table */
  9506.         debug(F101,"OS2 SET PORT x","",x);
  9507.         debug(F101,"OS2 SET PORT y","",y);
  9508.         if ((y > -1) && (x >= 0 && x < 8)) { /* User typed a digit 1..8 */
  9509.             s = os2devtab[x+8].kwd;     /* Substitite its real name */
  9510. #ifdef NT
  9511.             xxtapi = 0;
  9512. #else /* NT */
  9513.             xxslip = xxppp = 0;
  9514. #endif /* NT */
  9515.             debug(F110,"OS2 SET PORT subst s",s,"");
  9516. #ifndef NT
  9517.         } else if ((y >-1) && (x >= 16 && x < 24)) { /* SLIP access */
  9518.             s = os2devtab[x-8].kwd;     /* Substitite its real name */
  9519.             debug(F110,"OS2 SET PORT SLIP subst s",s,"");
  9520.             xxslip = 1;
  9521.             xxppp  = 0;
  9522.         } else if ((y >-1) && (x >= 24 && x < 32)) { /* PPP access */
  9523.             s = os2devtab[x-16].kwd;    /* Substitite its real name */
  9524.             debug(F110,"OS2 SET PORT PPP subst s",s,"");
  9525.             xxppp = 1;
  9526.             xxslip = 0;
  9527.             if ((y = cmkey(os2ppptab,
  9528.                            nos2ppp,
  9529.                            "PPP driver interface",
  9530.                            "ppp0",
  9531.                            xxstring)
  9532.                  ) < 0)
  9533.                 return(y);
  9534.             debug(F101,"OS2 SET PORT PPP INTERFACE y","",y);
  9535.             xxppp = (y % 10) + 1;
  9536. #endif /* NT */
  9537.         } else if (*s == '_') {         /* User used "_" prefix */
  9538.             s++;                        /* Remove it */
  9539.             /* Rest must be numeric */
  9540.             debug(F110,"OS2 SET PORT HANDLE _subst s",s,0);
  9541.             if (!rdigits(s)) {
  9542.                 makestr(&slmsg,"Invalid file handle");
  9543.                 printf("?Invalid format for file handle\n");
  9544.                 return(-9);
  9545.             }
  9546. #ifdef NT
  9547.             xxtapi = 0;
  9548. #else /* NT */
  9549.             xxslip = xxppp = 0;
  9550. #endif /* NT */
  9551.         } else {                        /* A normal COMx port or a string */
  9552.             s = brstrip(s);             /* Strip braces if any */
  9553. #ifdef NT
  9554. #ifdef CK_TAPI
  9555.             /* Windows TAPI support - Look up in keyword table */
  9556.             if (tapilinetab && _tapilinetab && ntapiline > 0) {
  9557.                 if (!ckstrcmp(s,"tapi",4,0)) {
  9558.  
  9559.                     /* Find out what the lowest numbered TAPI device is */
  9560.                     /* and use it as the default.                       */
  9561.                     int j = 9999, k = -1;
  9562.                     for (i = 0; i < ntapiline; i++) {
  9563.                         if (tapilinetab[i].kwval < j) {
  9564.                             j = tapilinetab[i].kwval;
  9565.                             k = i;
  9566.                         }
  9567.                     }
  9568.                     if (k >= 0)
  9569.                       s = _tapilinetab[k].kwd;
  9570.                     else
  9571.                       s = "";
  9572.  
  9573.                     if ((y = cmkey(_tapilinetab,ntapiline,
  9574.                                    "TAPI device name",s,xxstring)) < 0)
  9575.                       return(y);
  9576.  
  9577.                     xxtapi = 1;
  9578.  
  9579.                     /* Get the non Underscored string */
  9580.                     for (i = 0; i < ntapiline; i++ ) {
  9581.                         if (tapilinetab[i].kwval == y) {
  9582.                             s = tapilinetab[i].kwd;
  9583.                             break;
  9584.                         }
  9585.                     }
  9586.                 } else
  9587.                   xxtapi = 0;
  9588.             }
  9589. #endif /* CK_TAPI */
  9590. #else /* NT */
  9591.             /* not OS/2 SLIP or PPP */
  9592.             xxslip = xxppp = 0;
  9593. #endif /* NT */
  9594.         }
  9595.         ckstrncpy(tmpbuf,s,TMPBUFSIZ);  /* Copy to a safe place */
  9596.         s = tmpbuf;
  9597.         if ((x = cmcfm()) < 0)
  9598.           return(x);
  9599.  
  9600. #else /* !OS2 */
  9601.  
  9602.         cmfdbi(&sw,_CMKEY,"Device name, or switch",
  9603.                "","",npsltab,4,xxstring,psltab,&tx);
  9604.         cmfdbi(&tx,_CMTXT,"",dftty,"",0,0,xxstring,NULL,NULL);
  9605.         while (!confirmed) {
  9606.             x = cmfdb(&sw);
  9607.             debug(F101,"setlin cmfdb","",x);
  9608.             if (x < 0)
  9609.               if (x != -3)
  9610.                 return(x);
  9611.             if (x == -3) {
  9612.                 if ((x = cmcfm()) < 0) {
  9613.                     return(x);
  9614.                 } else {
  9615.                     confirmed = 1;
  9616.                     break;
  9617.                 }
  9618.             }
  9619.             switch (cmresult.fcode) {
  9620.               case _CMTXT:
  9621.                 ckstrncpy(tmpbuf,cmresult.sresult,TMPBUFSIZ);
  9622.                 s = tmpbuf;
  9623.                 debug(F110,"setlin CMTXT",tmpbuf,0);
  9624.                 confirmed = 1;
  9625.                 break;
  9626.               case _CMKEY:              /* Switch */
  9627.                 debug(F101,"setlin CMKEY",tmpbuf,cmresult.nresult);
  9628.                 switch (cmresult.nresult) {
  9629.                   case SL_CNX:          /* /CONNECT */
  9630.                     cx = 1;
  9631.                     sx = 0;
  9632.                     break;
  9633.                   case SL_SRV:          /* /SERVER */
  9634.                     cx = 0;
  9635.                     sx = 1;
  9636.                     break;
  9637. #ifdef VMS
  9638.                   case SL_SHR:          /* /SHARE */
  9639.                     shr = 1;
  9640.                     break;
  9641.                   case SL_NSH:          /* /NOSHARE */
  9642.                     shr = 0;
  9643.                     break;
  9644. #endif /* VMS */
  9645.                 }
  9646.                 continue;
  9647.               default:
  9648.                 debug(F101,"setlin bad cmfdb result","",cmresult.fcode);
  9649.                 makestr(&slmsg,"Internal error");
  9650.                 printf("?Internal parsing error\n");
  9651.                 return(-9);
  9652.             }
  9653.         }
  9654. #endif /* OS2 */
  9655.         if (!confirmed)
  9656.           if ((x = cmcfm()) < 0)
  9657.             return(x);
  9658. #ifndef NODIAL
  9659.         dialsta = DIA_UNK;
  9660. #endif /* NODIAL */
  9661.         debug(F101,"setlin confirmed mdmtyp","",mdmtyp);
  9662.         if (clskconnx(1) < 0)           /* Close the Kermit connection */
  9663.           return(success = 0);
  9664.         if (*s) {                       /* They gave a device name */
  9665.             _local = -1;                /* Let ttopen decide about it */
  9666.         } else {                        /* They just said "set line" */
  9667.             s = dftty;                  /* so go back to normal tty */
  9668.             _local = dfloc;             /* and mode. */
  9669.         }
  9670. #ifdef VMS
  9671.         {
  9672.             extern int ok_to_share;
  9673.             ok_to_share = shr;
  9674.         }
  9675. #endif /* VMS */
  9676.  
  9677. #ifdef OS2                              /* Must wait until after ttclos() */
  9678. #ifdef NT                               /* to change these settings       */
  9679. #ifdef CK_TAPI
  9680.         tttapi = xxtapi;
  9681. #endif /* CK_TAPI */
  9682. #else
  9683.         ttslip = xxslip;
  9684.         ttppp  = xxppp;
  9685. #endif /* NT */
  9686.         ttshare = shr;                  /* shareable device ? */
  9687.         debug(F110,"OS2 SET PORT final s",s,"");
  9688. #endif /* OS2 */
  9689.     }
  9690.     success = 0;
  9691.     if (mdmtyp > -1) {                  /* Serial connections... */
  9692.         /* Open the new line */
  9693.         if ((y = ttopen(s,&_local,mdmtyp,cdtimo)) > -1) {
  9694.             cxtype = (mdmtyp > 0) ? CXT_MODEM : CXT_DIRECT;
  9695. #ifdef COMMENT
  9696.             flow = cxflow[cxtype];      /* Set connection type and flow */
  9697. #else
  9698.             setflow();                  /* Only if autoflow()! */
  9699. #endif /* COMMENT */
  9700. #ifndef NODIAL
  9701.             dialsta = DIA_UNK;
  9702. #endif /* NODIAL */
  9703.             success = 1;
  9704. #ifdef CK_TAPI
  9705.             /* if the line is a tapi device, then we need to auto-execute */
  9706.             /* SET MODEM TYPE TAPI - which we do the equivalent of here.  */
  9707.             if (xxtapi) {
  9708.                 extern int usermdm;
  9709.                 usermdm = 0;
  9710.                 initmdm(38);            /* From ckudia.c n_TAPI == 38 */
  9711.             }
  9712. #endif /* CK_TAPI */
  9713.  
  9714.         } else {
  9715. #ifdef OS2ONLY
  9716.             if (!strcmp(s,dftty))   /* Do not generate an error with dftty */
  9717.               ;
  9718.             else if (y == -6 && ttslip) {
  9719.                 makestr(&slmsg,"Can't access SLIP driver");
  9720.                 if (!quiet || xcmdsrc == 0)
  9721.                   printf("?Unable to access SLIP driver.\n");
  9722.             } else if (y == -6 && ttppp) {
  9723.                 if (!quiet || xcmdsrc == 0)
  9724.                   makestr(&slmsg,"Can't access PPP driver");
  9725.                 printf("?Unable to access PPP driver (wrong interface?)\n");
  9726.             } else
  9727. #endif /* OS2ONLY */
  9728.               if (y == -2) {
  9729.                   makestr(&slmsg,"Timed out - no carrier");
  9730.                   if (!quiet || xcmdsrc == 0) {
  9731.                       printf("?Timed out, no carrier.\n");
  9732.                       printf(
  9733.                         "Try SET CARRIER OFF and SET LINE again, or else\n");
  9734.                       printf("SET MODEM, SET LINE, and then DIAL.\n");
  9735.                   }
  9736.               } else if (y == -3) {
  9737.                   makestr(&slmsg,"Access to lock denied");
  9738.                   if (!quiet || xcmdsrc == 0) {
  9739. #ifdef UNIX
  9740.                       printf(
  9741. "Sorry, write access to UUCP lockfile directory denied.\n");
  9742. #ifndef NOHINTS
  9743.                       if (hints) {
  9744.                           printf("\n*************************\n");
  9745.                           printf(
  9746. "HINT (Use SET HINTS OFF to suppress future hints):\n");
  9747.                           printf(
  9748. "Please read the installation instructions file, %sckuins.txt,\n",
  9749.                                  k_info_dir ? k_info_dir : ""
  9750.                                  );
  9751.                           printf(
  9752. "or the UNIX appendix of the manual, \"Using C-Kermit\".\n"
  9753.                                  );
  9754.                           printf("*************************\n\n");
  9755.                       }
  9756. #endif /* NOHINTS */
  9757. #else
  9758.                       printf("Sorry, access to lock denied: %s\n",s);
  9759. #endif /* UNIX */
  9760.                   }
  9761.               } else if (y == -4) {
  9762.                   makestr(&slmsg,"Access to device denied");
  9763.                   if (!quiet || xcmdsrc == 0) {
  9764.                       printf("Sorry, access to device denied: %s\n",s);
  9765. #ifdef UNIX
  9766. #ifndef NOHINTS
  9767.                       if (hints) {
  9768.                           printf("\n*************************\n");
  9769.                           printf(
  9770. "HINT (Use SET HINTS OFF to suppress future hints):\n");
  9771.                           printf(
  9772. "Please read the installation instructions file, %sckuins.txt,\n",
  9773.                                  k_info_dir ? k_info_dir : ""
  9774.                                  );
  9775.                           printf(
  9776. "or the UNIX appendix of the manual, \"Using C-Kermit\".\n"
  9777.                                  );
  9778.                           printf("*************************\n\n");
  9779.                       }
  9780. #endif /* NOHINTS */
  9781. #endif /* UNIX */
  9782.                   }
  9783.               } else if (y == -5) {
  9784.                   makestr(&slmsg,"Device is in use or unavailable");
  9785.                   if (!quiet || xcmdsrc == 0)
  9786. #ifdef VMS
  9787.                     printf(
  9788.                    "Sorry, device is in use or otherwise unavailable: %s\n",s);
  9789. #else
  9790.                     printf("Sorry, device is in use: %s\n",s);
  9791. #endif /* VMS */
  9792.               } else {                  /* Other error. */
  9793.                   makestr(&slmsg,"Device open failed");
  9794.                   if (
  9795. #ifdef VMS
  9796.                       1
  9797. #else
  9798.                       errno
  9799. #endif /* VMS */
  9800.                       ) {
  9801.                       int x;            /* Find a safe, long buffer */
  9802.                       makestr(&slmsg,ck_errstr());
  9803. #ifndef VMS
  9804.                       debug(F111,"setlin serial errno",slmsg,errno);
  9805. #endif /* VMS */
  9806.                       if (!quiet || xcmdsrc == 0)
  9807.                         printf("Connection to %s failed: %s\n",s,slmsg);
  9808.                   } else if (!quiet || xcmdsrc == 0)
  9809.                     printf("Sorry, can't open connection: %s\n",s);
  9810.               }
  9811.         }
  9812.     }
  9813. #ifdef NETCONN
  9814.     else {                              /* mdmtyp < 0: Network connection */
  9815.         char *p;
  9816.         int i, n;
  9817. #ifndef NODIAL
  9818.         debug(F101,"setlin mynet 3","",mynet);
  9819.         debug(F101,"setlin nhcount","",nhcount);
  9820.         if ((nhcount > 1) && !quiet && !backgrd) {
  9821.             int k;
  9822.             printf("%d entr%s found for \"%s\"%s\n",
  9823.                    nhcount,
  9824.                    (nhcount == 1) ? "y" : "ies",
  9825.                    s,
  9826.                    (nhcount > 0) ? ":" : "."
  9827.                    );
  9828.             for (i = 0; i < nhcount; i++) {
  9829.                     printf("%3d. %-12s => %-9s %s",
  9830.                            i+1,n_name,nh_p2[i],nh_p[i]);
  9831.                 for (k = 0; k < 4; k++) { /* Also list net-specific items */
  9832.                     if (nh_px[k][i])      /* free format... */
  9833.                       printf(" %s",nh_px[k][i]);
  9834.                     else
  9835.                       break;
  9836.                 }
  9837.                 printf("\n");
  9838.             }
  9839.         }
  9840.         if (nhcount == 0)
  9841.           n = 1;
  9842.         else
  9843.           n = nhcount;
  9844. #else
  9845.         n = 1;
  9846.         nhcount = 0;
  9847. #endif /* NODIAL */
  9848.         for (i = 0; i < n; i++) {       /* Loop for each entry found */
  9849.             debug(F101,"setlin loop i","",i);
  9850. #ifndef NODIAL
  9851.             if (nhcount > 0) {          /* If we found at least one entry... */
  9852.                 ckstrncpy(line,nh_p[i],LINBUFSIZ); /* Copy current entry */
  9853.                 if (lookup(netcmd,nh_p2[i],nnets,&x) > -1) { /* Net type */
  9854.                     mynet = netcmd[x].kwval;
  9855.                     mdmtyp  = 0 - mynet;
  9856.                     debug(F101,"setlin mynet 4","",mynet);
  9857.                 } else {
  9858.                     makestr(&slmsg,"Network type not supported");
  9859.                     printf("Error - network type \"%s\" not supported\n",
  9860.                            nh_p2[i]
  9861.                            );
  9862.                     continue;
  9863.                 }
  9864.  
  9865.                 switch (mynet) {        /* Net-specific things */
  9866.  
  9867. #ifdef SSHBUILTIN
  9868.                 case NET_SSH: {
  9869.                     /* What goes here? */
  9870.                     break;
  9871.                 }
  9872. #endif /* SSHBUILTIN */
  9873.  
  9874.                   case NET_TCPB: {      /* TCP/IP */
  9875. #ifdef TCPSOCKET
  9876.                       char *q;
  9877.                       int flag = 0;
  9878.  
  9879.                       /* Extract ":service", if any, from host string */
  9880.                       debug(F110,"setlin service 1",line,0);
  9881.                       for (q = line; (*q != '\0') && (*q != ':'); q++)
  9882.                         ;
  9883.                       if (*q == ':') { *q++ = NUL; flag = 1; }
  9884.                       debug(F111,"setlin service 2",line,flag);
  9885.  
  9886.                       /* Get service, if any, from directory entry */
  9887.  
  9888.                       if (!*srvbuf) {
  9889.                           if (nh_px[0][i]) {
  9890.                               ckstrncpy(srvbuf,nh_px[0][i],SRVBUFSIZ);
  9891.                               debug(F110,"setlin service 3",srvbuf,0);
  9892.                           }
  9893.                           if (flag) {
  9894.                               ckstrncpy(srvbuf,q,SRVBUFSIZ);
  9895.                               debug(F110,"setlin service 4",srvbuf,0);
  9896.                           }
  9897.                       }
  9898.  
  9899.                       /* Save the hostname */
  9900.                       ckstrncpy(hostname,line,HOSTNAMLEN);
  9901.  
  9902.                       /* If we have a service, append to host name/address */
  9903.                       if (*srvbuf) {
  9904.                           ckstrncat(line, ":", LINBUFSIZ);
  9905.                           ckstrncat(line, srvbuf, LINBUFSIZ);
  9906.                           debug(F110,"setlin service 5",line,0);
  9907.                       }
  9908. #ifdef RLOGCODE
  9909.                       /* If no service given but command was RLOGIN */
  9910.                       else if (ttnproto == NP_RLOGIN) { /* add this... */
  9911.                           ckstrncat(line, ":login",LINBUFSIZ);
  9912.                           debug(F110,"setlin service 6",line,0);
  9913.                       }
  9914. #ifdef CK_AUTHENTICATION
  9915. #ifdef CK_KERBEROS
  9916.                       else if (ttnproto == NP_K4LOGIN ||
  9917.                                ttnproto == NP_K5LOGIN) { /* add this... */
  9918.                           ckstrncat(line, ":klogin",LINBUFSIZ);
  9919.                           debug(F110,"setlin service 7",line,0);
  9920.                       }
  9921.                       else if (ttnproto == NP_EK4LOGIN ||
  9922.                                ttnproto == NP_EK5LOGIN) { /* add this... */
  9923.                           ckstrncat(line, ":eklogin",LINBUFSIZ);
  9924.                           debug(F110,"setlin service 8",line,0);
  9925.                       }
  9926. #endif /* CK_KERBEROS */
  9927. #endif /* CK_AUTHENTICATION */
  9928. #endif /* RLOGCODE */
  9929.                       else {            /* Otherwise, add ":telnet". */
  9930.                           ckstrncat(line, ":telnet", LINBUFSIZ);
  9931.                           debug(F110,"setlin service 9",line,0);
  9932.                       }
  9933.  
  9934.                       if (tmpusrid) {
  9935.                           ckstrncpy(uidbuf,tmpusrid,UIDBUFLEN);
  9936.                           makestr(&tmpusrid,NULL);
  9937.                           uidflag = 1;
  9938.                       }
  9939.  
  9940.                       /* Fifth field, if any, is user ID (for rlogin) */
  9941.  
  9942.                       if (nh_px[1][i] && !uidflag)
  9943.                         ckstrncpy(uidbuf,tmpusrid,UIDBUFLEN);
  9944. #ifdef RLOGCODE
  9945.                       if (IS_RLOGIN() && !uidbuf[0]) {
  9946.                           makestr(&slmsg,"Username required");
  9947.                           printf("Username required for rlogin\n");
  9948.                           return(-9);
  9949.                       }
  9950. #endif /* RLOGCODE */
  9951. #endif /* TCPSOCKET */
  9952.                       break;
  9953.                   }
  9954.  
  9955.  
  9956.                   case NET_PIPE:
  9957. #ifdef NPIPE
  9958.                     if (!pipename[0]) { /* User didn't give a pipename */
  9959.                         if (nh_px[0][i]) { /* But directory entry has one */
  9960.                             if (strcmp(pipename,"\\pipe\\")) {
  9961.                                 ckstrncpy(pipename,"\\pipe\\",LINBUFSIZ);
  9962.                                 ckstrncat(srvbuf,nh_px[0][i],PIPENAML-6);
  9963.                             } else {
  9964.                                 ckstrncpy(pipename,nh_px[0][i],PIPENAML);
  9965.                             }
  9966.                             debug(F110,"setlin pipeneme",pipename,0);
  9967.                         }
  9968.                     }
  9969. #endif /* NPIPE */
  9970.                     break;
  9971.  
  9972.                   case NET_SLAT:
  9973. #ifdef SUPERLAT
  9974.                     if (!slat_pwd[0]) { /* User didn't give a password */
  9975.                         if (nh_px[0][i]) { /* But directory entry has one */
  9976.                             ckstrncpy(slat_pwd,nh_px[0][i],18);
  9977.                             debug(F110,"setlin SuperLAT password",slat_pwd,0);
  9978.                         }
  9979.                     }
  9980. #endif /* SUPERLAT */
  9981.                     break;
  9982.  
  9983.                   case NET_SX25:        /* X.25 keyword parameters */
  9984.                   case NET_IX25:
  9985.                   case NET_VX25: {
  9986. #ifdef ANYX25
  9987.                       int k;            /* Cycle through the four fields */
  9988.                       for (k = 0; k < 4; k++) {
  9989.                           if (!nh_px[k][i]) /* Bail out if none left */
  9990.                             break;
  9991.                           if (!ckstrcmp(nh_px[k][i],"cug=",4,0)) {
  9992.                               closgr = atoi(nh_px[k][i]+4);
  9993.                               debug(F101,"X25 CUG","",closgr);
  9994.                           } else if (!ckstrcmp(nh_px[k][i],"cud=",4,0)) {
  9995.                               cudata = 1;
  9996.                               ckstrncpy(udata,nh_px[k][i]+4,MAXCUDATA);
  9997.                               debug(F110,"X25 CUD",cudata,0);
  9998.                           } else if (!ckstrcmp(nh_px[k][i],"rev=",4,0)) {
  9999.                               revcall = !ckstrcmp(nh_px[k][i]+4,"=on",3,0);
  10000.                               debug(F101,"X25 REV","",revcall);
  10001. #ifndef IBMX25
  10002.                           } else if (!ckstrcmp(nh_px[k][i],"pad=",4,0)) {
  10003.                               int x3par, x3val;
  10004.                               char *s1, *s2;
  10005.                               s1 = s2 = nh_px[k][i]+4; /* PAD parameters */
  10006.                               while (*s2) {            /* Pick them apart */
  10007.                                   if (*s2 == ':') {
  10008.                                       *s2 = NUL;
  10009.                                       x3par = atoi(s1);
  10010.                                       s1 = ++s2;
  10011.                                       continue;
  10012.                                   } else if (*s2 == ',') {
  10013.                                       *s2 = NUL;
  10014.                                       x3val = atoi(s1);
  10015.                                       s1 = ++s2;
  10016.                                       debug(F111,"X25 PAD",x3par,x3val);
  10017.                                       if (x3par > -1 &&
  10018.                                           x3par <= MAXPADPARMS)
  10019.                                         padparms[x3par] = x3val;
  10020.                                       continue;
  10021.                                   } else
  10022.                                     s2++;
  10023.                               }
  10024. #endif /* IBMX25 */
  10025.                           }
  10026.                       }
  10027. #endif /* ANYX25 */
  10028.                       break;
  10029.                   }
  10030.  
  10031.                   default:              /* Nothing special for other nets */
  10032.                     break;
  10033.                 }
  10034.             } else
  10035. #endif /* NODIAL */
  10036.             {                           /* No directory entries found. */
  10037.                 ckstrncpy(line,tmpbuf,LINBUFSIZ); /* Put this back... */
  10038.                 /* If the user gave a TCP service */
  10039.                 if (mynet == NET_TCPB || mynet == NET_SSH)
  10040.                   ckstrncpy(hostname,line,HOSTNAMLEN);
  10041.                   if (*srvbuf) {        /* append it to host name/address */
  10042.                       ckstrncat(line, ":", LINBUFSIZ);
  10043.                       ckstrncat(line, srvbuf,LINBUFSIZ);
  10044.                   }
  10045.             }
  10046.             /*
  10047.                Get here with host name/address and all net-specific
  10048.                parameters set, ready to open the connection.
  10049.             */
  10050.             mdmtyp = -mynet;            /* This should have been done */
  10051.                                         /* already but just in case ... */
  10052.  
  10053.             debug(F110,"setlin net line[] before ttopen",line,0);
  10054.             debug(F101,"setlin net mdmtyp before ttopen","",mdmtyp);
  10055.             debug(F101,"setlin net ttnproto","",ttnproto);
  10056.  
  10057. #ifdef TCPSOCKET
  10058.             if (mynet == NET_TCPB) {
  10059. #ifdef CK_AUTHENTICATION
  10060.             if ((ttnproto == NP_TELNET || ttnproto == NP_KERMIT) &&
  10061.                  a_type > -1) {
  10062.                 if (!sl_auth_saved) {
  10063.                     int x;
  10064.                     for (x = 0; x < AUTHTYPLSTSZ; x++)
  10065.                       sl_auth_type_user[x] = auth_type_user[x];
  10066.                     sl_auth_saved = 1;
  10067.                 }
  10068.                 if (!sl_topt_a_s_saved) {
  10069.                     sl_topt_a_su = TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION);
  10070.                     sl_topt_a_s_saved = 1;
  10071.                 }
  10072.                 if (!sl_topt_a_c_saved) {
  10073.                     sl_topt_a_cm = TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION);
  10074.                     sl_topt_a_c_saved = 1;
  10075.                 }
  10076.                 switch (a_type) {
  10077.                   case AUTHTYPE_AUTO:
  10078.                     auth_type_user[0] = AUTHTYPE_AUTO;
  10079.                     TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_RQ;
  10080.                     TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_RQ;
  10081.                     break;
  10082.                   case AUTHTYPE_NULL:
  10083.                     auth_type_user[0] = AUTHTYPE_NULL;
  10084.                     TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_RF;
  10085.                     TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_RF;
  10086.                     break;
  10087. #ifdef CK_SRP
  10088.                   case AUTHTYPE_SRP:
  10089.                     auth_type_user[0] = AUTHTYPE_SRP;
  10090.                     auth_type_user[1] = AUTHTYPE_NULL;
  10091.                     TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  10092.                     TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  10093.                     break;
  10094. #endif /* CK_SRP */
  10095. #ifdef CK_SSL
  10096.                   case AUTHTYPE_SSL:
  10097.                     auth_type_user[0] = AUTHTYPE_SSL;
  10098.                     auth_type_user[1] = AUTHTYPE_NULL;
  10099.                     TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  10100.                     TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  10101.                     break;
  10102. #endif /* CK_SSL */
  10103. #ifdef NT
  10104.                   case AUTHTYPE_NTLM:
  10105.                     auth_type_user[0] = AUTHTYPE_NTLM;
  10106.                     auth_type_user[1] = AUTHTYPE_NULL;
  10107.                     TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  10108.                     TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  10109.                     break;
  10110. #endif /* NT */
  10111. #ifdef CK_KERBEROS
  10112.                   case AUTHTYPE_KERBEROS_V4:
  10113.                     auth_type_user[0] = AUTHTYPE_KERBEROS_V4;
  10114.                     auth_type_user[1] = AUTHTYPE_NULL;
  10115.                     TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  10116.                     TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  10117.                     break;
  10118.  
  10119.                   case AUTHTYPE_KERBEROS_V5:
  10120.                     auth_type_user[0] = AUTHTYPE_KERBEROS_V5;
  10121.                     auth_type_user[1] = AUTHTYPE_NULL;
  10122.                     TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  10123.                     TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  10124.                     break;
  10125. #endif /* CK_KERBEROS */
  10126.                 }
  10127.             }
  10128.  
  10129.             /*
  10130.                If the user is going to require a Kerberos connection
  10131.                of a particular type, let's make sure we have a valid TGT.
  10132.             */
  10133.             makestr(&slmsg,"Authentication failure");
  10134.             if ((ttnproto == NP_TELNET || ttnproto == NP_KERMIT) &&
  10135.                 (line[0] == '*' &&
  10136.                  TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) == TN_NG_MU ||
  10137.                  line[0] != '*' &&
  10138.                  TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) == TN_NG_MU)
  10139.                 ) {
  10140. #ifdef CK_KERBEROS
  10141.                 if ( auth_type_user[0] == AUTHTYPE_KERBEROS_V4 ) {
  10142.                     extern int krb4_autoget;
  10143.                     if (!ck_krb4_is_installed()) {
  10144.                         printf(
  10145.         "?Required authentication method (Kerberos 4) is not installed\n"
  10146.                                );
  10147.                         slrestor();
  10148.                         return(success = 0);
  10149.                     }
  10150. #ifdef COMMENT
  10151.                     /* This code results in false failures when using */
  10152.                     /* kerberos to machines in realms other than the  */
  10153.                     /* default since we don't know the realm of the   */
  10154.                     /* other machine until perform the reverse DNS    */
  10155.                     /* lookup.                                        */
  10156.                     else if (line[0] != '*' && !ck_krb4_is_tgt_valid() &&
  10157.                                (!krb4_autoget ||
  10158.                                 krb4_autoget && !ck_krb4_autoget_TGT(NULL))) {
  10159.                         printf(
  10160.         "?Kerberos 4: Ticket Getting Ticket not valid.\n"
  10161.                                );
  10162.                         slrestor();
  10163.                         return(success = 0);
  10164.                     }
  10165. #endif /* COMMENT */
  10166.                 } else if (auth_type_user[0] == AUTHTYPE_KERBEROS_V5) {
  10167.                     extern int krb5_autoget;
  10168.                     if (!ck_krb5_is_installed()) {
  10169.                         printf(
  10170.         "?Required authentication method (Kerberos 5) is not installed\n"
  10171.                                );
  10172.                         slrestor();
  10173.                         return(success = 0);
  10174.                     }
  10175. #ifdef COMMENT
  10176.                     /* This code results in false failures when using */
  10177.                     /* kerberos to machines in realms other than the  */
  10178.                     /* default since we don't know the realm of the   */
  10179.                     /* other machine until perform the reverse DNS    */
  10180.                     /* lookup.                                        */
  10181.                     else if (line[0] != '*' && !ck_krb5_is_tgt_valid() &&
  10182.                                (!krb5_autoget ||
  10183.                                 krb5_autoget && !ck_krb5_autoget_TGT(NULL))) {
  10184.                         printf(
  10185.         "?Kerberos 5: Ticket Getting Ticket not valid.\n"
  10186.                                );
  10187.                         slrestor();
  10188.                         return(success = 0);
  10189.                     }
  10190. #endif /* COMMENT */
  10191.                 }
  10192. #endif /* CK_KERBEROS */
  10193. #ifdef NT
  10194.                 if (auth_type_user[0] == AUTHTYPE_NTLM) {
  10195.                     if (!ck_ntlm_is_installed()) {
  10196.                         printf(
  10197.         "?Required authentication method (NTLM) is not installed\n"
  10198.                                );
  10199.                         slrestor();
  10200.                         return(success = 0);
  10201.                     } else if (line[0] != '*' && !ck_ntlm_is_valid(0)) {
  10202.                         printf("?NTLM: Credentials are unavailable.\n");
  10203.                         slrestor();
  10204.                         return(success = 0);
  10205.                     }
  10206.                 }
  10207. #endif /* NT */
  10208. #ifdef CK_SSL
  10209.                 if (auth_type_user[0] == AUTHTYPE_SSL) {
  10210.                     if (!ck_ssleay_is_installed()) {
  10211.                         printf(
  10212.         "?Required authentication method (SSL) is not installed\n"
  10213.                                );
  10214.                         slrestor();
  10215.                         return(success = 0);
  10216.                     }
  10217.                 }
  10218. #endif /* CK_SSL */
  10219. #ifdef CK_SRP
  10220.                 if (auth_type_user[0] == AUTHTYPE_SRP) {
  10221.                     if (!ck_srp_is_installed()) {
  10222.                         printf(
  10223.         "?Required authentication method (SRP) is not installed\n"
  10224.                                );
  10225.                         slrestor();
  10226.                         return(success = 0);
  10227.                     }
  10228.                 }
  10229. #endif /* CK_SRP */
  10230.             }
  10231. #endif /* CK_AUTHENTICATION */
  10232. #ifdef CK_ENCRYPTION
  10233.             if ((ttnproto == NP_TELNET || ttnproto == NP_KERMIT) &&
  10234.                  e_type > -1) {
  10235.                 if (!sl_cx_saved) {
  10236.                     sl_cx_type = cx_type;
  10237.                     sl_cx_saved = 1;
  10238.                 }
  10239.                 if (!sl_topt_e_s_saved) {
  10240.                     sl_topt_e_su = TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION);
  10241.                     sl_topt_e_sm = TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION);
  10242.                     sl_topt_e_s_saved = 1;
  10243.                 }
  10244.                 if (!sl_topt_e_c_saved) {
  10245.                     sl_topt_e_cu = TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION);
  10246.                     sl_topt_e_cm = TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION);
  10247.                     sl_topt_e_c_saved = 1;
  10248.                 }
  10249.                 cx_type = e_type;
  10250.                 if (cx_type == CX_AUTO) {
  10251.                     TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION) = TN_NG_RQ;
  10252.                     TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_RQ;
  10253.                     TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION) = TN_NG_RQ;
  10254.                     TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_RQ;
  10255.                 } else if (cx_type == CX_NONE) {
  10256.                     TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION) = TN_NG_RF;
  10257.                     TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_RF;
  10258.                     TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION) = TN_NG_RF;
  10259.                     TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_RF;
  10260.                 } else {
  10261.                     TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION) = TN_NG_MU;
  10262.                     TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_MU;
  10263.                     TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION) = TN_NG_MU;
  10264.                     TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_MU;
  10265.                 }
  10266.             }
  10267.             if (ttnproto == NP_EK4LOGIN || ttnproto == NP_EK5LOGIN ||
  10268.                 (ttnproto == NP_TELNET || ttnproto == NP_KERMIT) &&
  10269.                 ((line[0] == '*' &&
  10270.                   TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION) == TN_NG_MU &&
  10271.                   TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION) == TN_NG_MU) ||
  10272.                  (line[0] != '*' &&
  10273.                   TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION) == TN_NG_MU &&
  10274.                   TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION) == TN_NG_MU))
  10275.                 ) {
  10276.                 if (!ck_crypt_is_installed()) {
  10277.                     makestr(&slmsg,"Encryption failure");
  10278.                     printf("?Required Encryption methods are not installed\n");
  10279.                     slrestor();
  10280.                     return(success = 0);
  10281.                 }
  10282.             }
  10283. #endif /* CK_ENCRYPTION */
  10284. #ifdef RLOGCODE
  10285. #ifdef CK_KERBEROS
  10286. #ifdef KRB4
  10287.             if (ttnproto == NP_K4LOGIN || ttnproto == NP_EK4LOGIN) {
  10288.                 extern int krb4_autoget;
  10289.                 char tgt[256];
  10290.                 char * realm;
  10291.  
  10292.                 /* this is fine except for one huge problem         */
  10293.                 /* we don't have the full hostname at this point    */
  10294.                 /* so we really need to perform a DNS lookup before */
  10295.                 /* calling ttopen().                                */
  10296.  
  10297.                 realm = ck_krb4_realmofhost(ckgetfqhostname(hostname));
  10298.                 ckmakmsg(tgt,256,"krbtgt.",realm,"@",realm);
  10299.                 if (!ck_krb4_is_installed()) {
  10300.                     printf(
  10301.         "?Required authentication method (Kerberos 4) is not installed\n"
  10302.                            );
  10303.                     slrestor();
  10304.                     return(success = 0);
  10305.                 } else {
  10306.                     if ((ck_krb4_tkt_isvalid(tgt) <= 0) &&
  10307.                         (!krb4_autoget ||
  10308.                          krb4_autoget && !ck_krb4_autoget_TGT(realm))) {
  10309.                         printf(
  10310.                            "?Kerberos 4: Ticket Getting Ticket not valid.\n");
  10311.                         slrestor();
  10312.                         return(success = 0);
  10313.                     }
  10314.                 }
  10315.             }
  10316. #endif /* KRB4 */
  10317. #ifdef KRB5
  10318.             if (ttnproto == NP_K5LOGIN || ttnproto == NP_EK5LOGIN ||
  10319.                 ttnproto == NP_K5U2U)
  10320.             {
  10321.                 extern int krb5_autoget;
  10322.                 char tgt[256];
  10323.                 char * realm;
  10324.  
  10325.                 /* this is fine except for one huge problem         */
  10326.                 /* we don't have the full hostname at this point    */
  10327.                 /* so we really need to perform a DNS lookup before */
  10328.                 /* calling ttopen().                                */
  10329.  
  10330.                 realm = ck_krb5_realmofhost(ckgetfqhostname(hostname));
  10331.                 ckmakmsg(tgt,256,"krbtgt/",realm,"@",realm);
  10332.  
  10333.                 if (!ck_krb5_is_installed()) {
  10334.                     printf(
  10335.         "?Required authentication method (Kerberos 5) is not installed\n"
  10336.                            );
  10337.                     slrestor();
  10338.                     return(success = 0);
  10339.                 } else if (!((ck_krb5_tkt_isvalid(NULL,tgt) > 0) ||
  10340.                               ck_krb5_is_tgt_valid()) &&
  10341.                            (!krb5_autoget ||
  10342.                             krb5_autoget && !ck_krb5_autoget_TGT(realm))) {
  10343.                     printf("?Kerberos 5: Ticket Getting Ticket not valid.\n");
  10344.                     slrestor();
  10345.                     return(success = 0);
  10346.                 }
  10347.             }
  10348. #endif /* KRB5 */
  10349. #endif /* CK_KERBEROS */
  10350. #endif /* RLOGCODE */
  10351.  
  10352. #ifndef NOSPL
  10353. #ifdef RLOGCODE
  10354.             if (tmpusrid) {
  10355.                 if (!sl_uid_saved) {
  10356.                     ckstrncpy(sl_uidbuf,uidbuf,UIDBUFLEN);
  10357.                     sl_uid_saved = 1;
  10358.                 }
  10359.                 ckstrncpy(uidbuf,tmpusrid,UIDBUFLEN);
  10360.                 makestr(&tmpusrid,NULL);
  10361.                 uidflag = 1;
  10362.             }
  10363. #endif /* RLOGCODE */
  10364. #ifdef TNCODE
  10365.             if (!sl_tn_saved) {
  10366.                 sl_tn_wait = tn_wait_flg;
  10367.                 sl_tn_saved = 1;
  10368.             }
  10369.             tn_wait_flg = wait;
  10370. #endif /* TNCODE */
  10371. #endif /* NOSPL */
  10372.             } /* if (mynet == NET_TCPB) */
  10373. #endif /* TCPSOCKET */
  10374.  
  10375. #ifndef NOSPL
  10376. #ifdef CK_SECURITY
  10377.             if (tmpstring) {
  10378.                 if (tmpstring[0]) {
  10379.                     ckstrncpy(pwbuf,tmpstring,PWBUFL+1);
  10380.                     pwflg = 1;
  10381.                     pwcrypt = 0;
  10382.                 } else
  10383.                     pwflg = 0;
  10384.                 makestr(&tmpstring,NULL);
  10385.             }
  10386. #endif /* CK_SECURITY */
  10387. #endif /* NOSPL */
  10388.  
  10389.             /* Try to open - network */
  10390.             y = ttopen(line, &_local, mdmtyp, 0 );
  10391.  
  10392. #ifndef NOHTTP
  10393.             /*  If the connection failed and we are using an HTTP Proxy
  10394.              *  and the reason for the failure was an authentication
  10395.              *  error, then we need to give the user to ability to
  10396.              *  enter a username and password, just like a browser.
  10397.              *
  10398.              *  I tried to do all of this within the netopen() call
  10399.              *  but it is much too much work.
  10400.              */
  10401.             while (y < 0 && tcp_http_proxy != NULL ) {
  10402.  
  10403.                 if (tcp_http_proxy_errno == 401 ||
  10404.                     tcp_http_proxy_errno == 407 ) {
  10405.                     char uid[UIDBUFLEN];
  10406.                     char pwd[256];
  10407.  
  10408.                     readtext("Proxy Userid: ",uid,UIDBUFLEN);
  10409.                     if (uid[0]) {
  10410.                         char * proxy_user, * proxy_pwd;
  10411.  
  10412.                         readpass("Proxy Password: ",pwd,256);
  10413.  
  10414.                         proxy_user = tcp_http_proxy_user;
  10415.                         proxy_pwd  = tcp_http_proxy_pwd;
  10416.  
  10417.                         tcp_http_proxy_user = uid;
  10418.                         tcp_http_proxy_pwd = pwd;
  10419.  
  10420.                         y = ttopen(line, &_local, mdmtyp, 0);
  10421.                         memset(pwd,0,sizeof(pwd));
  10422.                         tcp_http_proxy_user = proxy_user;
  10423.                         tcp_http_proxy_pwd = proxy_pwd;
  10424.                     } else
  10425.                       break;
  10426.                 } else
  10427.                   break;
  10428.             }
  10429. #endif /* NOHTTP */
  10430.             if (y < 0) {
  10431.                 slrestor();
  10432.                 makestr(&slmsg,"Network connection failure");
  10433. #ifdef VMS
  10434.                 if (hints && !xcmdsrc && IS_RLOGIN()) {
  10435.                     makestr(&slmsg,"RLOGIN failure");
  10436.                     if  (socket_errno == EACCES) {
  10437.                         printf("*************************\n");
  10438.                         printf(
  10439.                "Hint: RLOGIN requires privileges to open an outbound port.\n");
  10440.                         printf(
  10441.                         "(Use SET HINTS OFF to suppress future hints.)\n");
  10442.                         printf("*************************\n");
  10443.                     }
  10444.                 }
  10445. #else  /* Not VMS... */
  10446.                 if (errno) {
  10447.                     int x;
  10448.                     debug(F111,"set host line, errno","",errno);
  10449.                     makestr(&slmsg,ck_errstr());
  10450.                     x = strlen(line) + 2;
  10451.                     if (LINBUFSIZ - x > 100) {
  10452.                         tp = line + x;
  10453. #ifdef OS2
  10454.                         printf("Can't connect to %s\n",line);
  10455. #else /* OS2 */
  10456. #ifdef UNIX
  10457.                         if (hints && !xcmdsrc && IS_RLOGIN()) {
  10458.                             makestr(&slmsg,"RLOGIN failure");
  10459.                             printf("*************************\n");
  10460.                             printf(
  10461.              "Hint: RLOGIN requires privileges to open an outbound port.\n");
  10462.                             printf(
  10463.              "(Use SET HINTS OFF to suppress future hints.)\n");
  10464.                             printf("*************************\n");
  10465.                         }
  10466. #endif /* UNIX */
  10467. #endif /* OS2 */
  10468.                     } else printf("Can't connect to %s\n",line);
  10469.                 } else
  10470. #endif /* VMS */
  10471.                   printf("Can't open connection to %s\n",line);
  10472.                 continue;
  10473.             } else {
  10474.                 success = 1;
  10475. #ifndef NODIAL
  10476.                 dialsta = DIA_UNK;
  10477. #endif /* NODIAL */
  10478.                 switch (mynet) {
  10479.                   case NET_TCPA:
  10480.                   case NET_TCPB:
  10481.                     cxtype = CXT_TCPIP;
  10482. #ifdef COMMENT
  10483. /* This works but it messes up interactive anonymous login */
  10484. #ifndef NOXFER
  10485. #ifdef IKS_OPTION
  10486.                     /* If we have connected to an Internet Kermit service */
  10487.                     /* and a /USER: swtich was given, then log in. */
  10488.  
  10489.                     if (TELOPT_U(TELOPT_KERMIT) || TELOPT_ME(TELOPT_KERMIT)) {
  10490.                         debug(F111,"setlin IKSD /USER:",uidbuf,haveuser);
  10491.                         if (haveuser /* && cx == 0 */ ) { /* /USER: given */
  10492.                             char * psw = pwbuf; /* Do we have a password? */
  10493.                             if (!*psw) {        /* No... */
  10494.                                 if (!strcmp(uidbuf,"anonymous") ||
  10495.                                     !strcmp(uidbuf,"ftp")) {
  10496.                                     extern char myhost[];
  10497.                                     char * u = (char *)sl_uidbuf;
  10498.                                     char * h = (char *)myhost;
  10499.                                     if (!*u) u = "nobody";
  10500.                                     if (!*h) h = "nowhere";
  10501.                                     ckmakmsg(tmpbuf,TMPBUFSIZ,u,"@",h,NULL);
  10502.                                     psw = tmpbuf;
  10503.                                     debug(F110,"setlin IKSD anon",psw,0);
  10504.                                 } else {
  10505.                                     readpass(" Password: ",pwbuf,PWBUFL);
  10506.                                 }
  10507.                             }
  10508.                             sstate = setgen('I',uidbuf,psw,"");
  10509.                         }
  10510.                     }
  10511. #endif /* IKS_OPTION */
  10512. #endif /* NOXFER */
  10513. #endif /* COMMENT */
  10514.                     break;
  10515.                   case NET_SSH:
  10516.                     cxtype = CXT_SSH;
  10517.                     duplex = 0;         /* Remote echo */
  10518.                     break;
  10519.                   case NET_SLAT:
  10520.                     cxtype = CXT_LAT;
  10521.                     break;
  10522.                   case NET_SX25:
  10523.                   case NET_IX25:
  10524.                   case NET_HX25:
  10525.                   case NET_VX25:
  10526.                     cxtype = CXT_X25;
  10527.                     break;
  10528.                   case NET_BIOS:
  10529.                     cxtype = CXT_NETBIOS;
  10530.                     break;
  10531.                   case NET_FILE:
  10532.                   case NET_PIPE:
  10533.                   case NET_CMD:
  10534.                   case NET_DLL:
  10535.                   case NET_PTY:
  10536.                     cxtype = CXT_PIPE;
  10537.                     break;
  10538.                   default:
  10539.                     cxtype = CXT_PIPE;
  10540.                     break;
  10541.                 }
  10542.                 break;
  10543.             }
  10544.         } /* for-loop */
  10545.         s = line;
  10546.     } /* network connection */
  10547. #endif /* NETCONN */
  10548. /*
  10549.   NOTE:
  10550.   The following will fail if Kermit is running as a daemon with no
  10551.   controlling tty.  Needs research.
  10552. */
  10553.     if (!success) {
  10554.         local = dfloc;                  /* Go back to normal */
  10555. #ifndef MAC
  10556.         ckstrncpy(ttname,dftty,TTNAMLEN); /* Restore default tty name */
  10557. #endif /* MAC */
  10558.         speed = ttgspd();
  10559.         network = 0;                    /* No network connection active */
  10560.         haveline = 0;
  10561.         if (mdmtyp < 0) {               /* Switching from net to async? */
  10562.             if (mdmsav > -1)            /* Restore modem type from last */
  10563.               mdmtyp = mdmsav;          /* SET MODEM command, if any. */
  10564.             else
  10565.               mdmtyp = 0;
  10566.             mdmsav = -1;
  10567.         }
  10568.         return(0);                      /* Return failure */
  10569.     }
  10570.     if (_local > -1) local = _local;    /* Opened ok, set local/remote. */
  10571.     makestr(&slmsg,NULL);
  10572.     network = (mdmtyp < 0);             /* Remember connection type. */
  10573.     ckstrncpy(ttname,s,TTNAMLEN);       /* Copy name into real place. */
  10574.     debug(F110,"setlin ok",ttname,0);
  10575.     debug(F101,"setlin network","",network);
  10576. #ifndef NOXFER
  10577.     if ((reliable != SET_OFF || !setreliable)) /* Assume not reliable. */
  10578.       reliable = SET_OFF;
  10579. #endif /* NOXFER */
  10580.     if (!network)
  10581.       speed = ttgspd();                 /* Get the current speed. */
  10582.     debug(F101,"setlin local","",local);
  10583. #ifdef NETCONN
  10584.     if (network) {
  10585.         debug(F101,"setlin mynet","",mynet);
  10586. #ifndef NOXFER
  10587.         /* Force prefixing of 255 on TCP/IP connections... */
  10588.         if (mynet == NET_TCPB
  10589. #ifdef SSHBUILTIN
  10590.              || mynet == NET_SSH
  10591. #endif /* SSHBUILTIN */
  10592.              ) {
  10593.             debug(F101,"setlin reliable A","",reliable);
  10594. #ifdef CK_SPEED
  10595.             ctlp[(unsigned)255] = 1;
  10596. #endif /* CK_SPEED */
  10597.             if ((reliable != SET_OFF || !setreliable)) {
  10598. #ifdef TN_COMPORT
  10599.                 if (istncomport()) {    /* Telnet communication port */
  10600.                     reliable = SET_OFF; /* Transport is not reliable */
  10601.                     debug(F101,"setlin reliable istncomport()","",1);
  10602.                 } else {
  10603.                     reliable = SET_ON;  /* Transport is reliable end to end */
  10604.                     debug(F101,"setlin reliable istncomport()","",0);
  10605.                 }
  10606. #else
  10607.                 reliable = SET_ON;      /* Transport is reliable end to end */
  10608. #endif /* ifdef TN_COMPORT */
  10609.             }
  10610.             debug(F101,"setlin reliable B","",reliable);
  10611.         } else if (mynet == NET_SX25 ||
  10612.                    mynet == NET_VX25 ||
  10613.                    mynet == NET_IX25 ||
  10614.                    mynet == NET_HX25) {
  10615.             duplex = 1;                 /* Local echo for X.25 */
  10616.             if (reliable != SET_OFF || !setreliable)
  10617.               reliable = SET_ON;        /* Transport is reliable end to end */
  10618.         }
  10619. #endif /* NOXFER */
  10620.     }
  10621. #endif /* NETCONN */
  10622. #ifndef NOXFER
  10623.     debug(F101,"setlin reliable","",reliable);
  10624. #endif /* NOXFER */
  10625. #ifdef OS2
  10626.     if (mdmtyp <= 0)                    /* Network or Direct Connection */
  10627.       DialerSend(OPT_KERMIT_CONNECT, 0);
  10628. #endif /* OS2 */
  10629.  
  10630.   xsetlin:
  10631.  
  10632.     setflow();                          /* Set appropriate flow control */
  10633.  
  10634.     haveline = 1;
  10635. #ifdef CKLOGDIAL
  10636. #ifdef NETCONN
  10637.     if (network)                        /* Start connection log record */
  10638.       dolognet();
  10639.     else
  10640. #endif /* NETCONN */
  10641.       dologline();
  10642. #endif /* CKLOGDIAL */
  10643.  
  10644. #ifndef NOSPL
  10645.     if (local) {
  10646.         if (nmac) {                     /* Any macros defined? */
  10647.             int k;                      /* Yes */
  10648.             k = mlook(mactab,"on_open",nmac);   /* Look this up */
  10649.             if (k >= 0) {                       /* If found, */
  10650.                 if (dodo(k,ttname,0) > -1)      /* set it up, */
  10651.                   parser(1);                    /* and execute it */
  10652.             }
  10653.         }
  10654.     }
  10655. #endif /* NOSPL */
  10656.  
  10657.     if (local && (cx || sx)) {          /* /CONNECT or /SERVER switch given */
  10658.         extern int carrier;
  10659.         if (xx == XYLINE && carrier != CAR_OFF) { /* on serial connection... */
  10660.             /* Open() turns on DTR -- wait up to a second for CD to come up */
  10661.             int i, x;
  10662.             for (i = 0; i < 10; i++) {  /* WAIT 1 CD... */
  10663.                 x = ttgmdm();
  10664.                 if (x < 0 || x & BM_DCD)
  10665.                   break;
  10666.                 msleep(100);
  10667.             }
  10668.         }
  10669.         if (cx) {                       /* /CONNECT */
  10670.             /* Command was confirmed so we can pre-pop command level. */
  10671.             /* This is so CONNECT module won't think we're executing a */
  10672.             /* script if CONNECT was the final command in the script. */
  10673.  
  10674.             if (cmdlvl > 0)
  10675.               prepop();
  10676. #ifndef NODIAL
  10677.             dialsta = DIA_UNK;
  10678. #endif /* NODIAL */
  10679. #ifdef LOCUS
  10680.             if (autolocus) {
  10681.                 if (!locus && msgflg)
  10682.                   printf(
  10683.                     "Switching LOCUS for file-management commands to LOCAL.\n"
  10684.                          );
  10685.                 locus = 1;
  10686.             }
  10687. #endif /* LOCUS */
  10688.             success = doconect(0, cmdlvl == 0 ? 1 : 0);
  10689.             if (ttchk() < 0)
  10690.               dologend();
  10691.             return(success);
  10692. #ifndef NOXFER
  10693.         } else if (sx) {                /* /SERVER */
  10694.             sstate = 'x';
  10695. #ifdef MAC
  10696.             what = W_RECV;
  10697.             scrcreate();
  10698. #endif /* MAC */
  10699.             if (local) displa = 1;
  10700. #ifdef AMIGA
  10701.             reqoff();                   /* No DOS requestors while server */
  10702. #endif /* AMIGA */
  10703. #endif /* NOXFER */
  10704.         }
  10705.     }
  10706. #ifndef NODIAL
  10707.     dialsta = DIA_UNK;
  10708. #endif /* NODIAL */
  10709. #ifdef LOCUS
  10710.     if (autolocus) {
  10711.         if (!locus && msgflg)
  10712.           printf("Switching LOCUS for file-management commands to LOCAL.\n");
  10713.         locus = 1;
  10714.     }
  10715. #endif /* LOCUS */
  10716.     return(success = 1);
  10717. }
  10718. #endif /* NOLOCAL */
  10719.  
  10720. #ifdef CKCHANNELIO
  10721. /*
  10722.   C-Library based file-i/o package for scripts.  This should be portable to
  10723.   all C-Kermit versions since it uses the same APIs we have always used for
  10724.   processing command files.  The entire channel i/o package is contained
  10725.   herein, apart from some keyword table entries in the main keyword table
  10726.   and the help text in the HELP command module.
  10727.  
  10728.   On platforms like VMS and VOS, this package handles only UNIX-style
  10729.   stream files.  If desired, it can be replaced for those platforms by
  10730.   <#>ifdef'ing out this code and adding the equivalent replacement routines
  10731.   to the ck?fio.c module, e.g. for RMS-based file i/o in ckvfio.c.
  10732. */
  10733.  
  10734. /* Define NOSTAT if the <#>include causes trouble. */
  10735.  
  10736. #ifndef NOSTAT
  10737. #ifdef VMS
  10738. #ifdef VAXC                             /* As it does in VAX C */
  10739. #define NOSTAT
  10740. #endif /* VAXC */
  10741. #endif /* VMS */
  10742. #endif /* NOSTAT */
  10743.  
  10744. #ifndef NOSTAT
  10745. #include <sys/stat.h>
  10746. #endif /* NOSTAT */
  10747.  
  10748. #ifdef NLCHAR
  10749. static int z_lt = 1;                    /* Length of line terminator */
  10750. #else
  10751. static int z_lt = 2;
  10752. #endif /* NLCHAR */
  10753.  
  10754. struct ckz_file {                       /* C-Kermit file struct */
  10755.     FILE * z_fp;                        /* Includes the C-Lib file struct */
  10756.     unsigned int z_flags;               /* Plus C-Kermit mode flags, */
  10757.     long z_nline;                       /* current line number if known, */
  10758.     char z_name[CKMAXPATH+2];           /* and the file's name. */
  10759. };
  10760. static struct ckz_file * z_file = NULL; /* Array of C-Kermit file structs */
  10761. static int z_inited = 0;                /* Flag for array initialized */
  10762. int z_maxchan = Z_MAXCHAN;              /* Max number of C-Kermit channels */
  10763. int z_openmax = CKMAXOPEN;              /* Max number of open files overall */
  10764. int z_nopen = 0;                        /* How many channels presently open */
  10765. int z_error = 0;                        /* Most recent error */
  10766. int z_filcount = -1;                    /* Most recent FILE COUNT result */
  10767.  
  10768. #define RD_LINE 0                       /* FILE READ options */
  10769. #define RD_CHAR 1
  10770. #define RD_SIZE 2
  10771.  
  10772. #define WR_LINE RD_LINE                 /* FILE WRITE options */
  10773. #define WR_CHAR RD_CHAR
  10774. #define WR_SIZE RD_SIZE
  10775. #define WR_STRI 3
  10776. #define WR_LPAD 4
  10777. #define WR_RPAD 5
  10778.  
  10779. #ifdef UNIX
  10780. extern int ckmaxfiles;                  /* Filled in by sysinit(). */
  10781. #endif /* UNIX */
  10782.  
  10783. /* See ckcker.h for error numbers */
  10784. /* See ckcdeb.h for Z_MAXCHAN and CKMAXOPEN definitions */
  10785. /* NOTE: For VMS we might be able to fill in ckmaxfiles */
  10786. /* from FILLM and CHANNELCNT -- find out about these... */
  10787.  
  10788. static char * fopnargs[] = {            /* Mode combinations for fopen() */
  10789. #ifdef COMMENT
  10790.     /* All combinations of rwa */
  10791.     "",  "r",  "w",  "rw",  "a",  "ra",  "wa",  "rwa", /* Text mode */
  10792.     "b", "rb", "wb", "rwb", "ab", "rab", "wab", "rwab" /* Binary mode */
  10793. #else
  10794.     /* Combinations and syntax permitted by C libraries... */
  10795.     "",  "r",  "w",  "r+",  "a",  "",   "a",  "", /* Text mode */
  10796. #ifdef OS2
  10797.     "",  "rb", "wb", "r+b", "ab", "",   "ab", "" /* Binary modes for K95 */
  10798. #else
  10799. #ifdef VMS
  10800.     "",  "rb", "wb", "r+b", "ab", "",   "ab", "" /* Binary modes for VMS */
  10801. #else
  10802.     "",  "r",   "w", "r+",  "a",  "",   "a",  "" /* Binary modes for UNIX */
  10803. #endif /* VMS */
  10804. #endif /* OS2 */
  10805. #endif /* COMMENT */
  10806. };
  10807. static int nfopnargs = sizeof(fopnargs) / sizeof(char *);
  10808.  
  10809. char *                                  /* Error messages */
  10810. ckferror(n) int n; {
  10811.     switch (n) {
  10812.       case FX_NER: return("No error");
  10813.       case FX_SYS: return(ck_errstr());
  10814.       case FX_EOF: return("End of file");
  10815.       case FX_NOP: return("File not open");
  10816.       case FX_CHN: return("Channel out of range");
  10817.       case FX_RNG: return("Parameter out of range");
  10818.       case FX_NMF: return("Too many files open");
  10819.       case FX_FOP: return("Operation conflicts with OPEN mode");
  10820.       case FX_NYI: return("OPEN mode not supported");
  10821.       case FX_BOM: return("Illegal combination of OPEN modes");
  10822.       case FX_ACC: return("Access denied");
  10823.       case FX_FNF: return("File not found");
  10824.       case FX_OFL: return("Buffer overflow");
  10825.       case FX_LNU: return("Current line number unknown");
  10826.       case FX_ROO: return("Off limits");
  10827.       case FX_UNK: return("Operation fails - reason unknown");
  10828.       default: return("Error number out of range");
  10829.     }
  10830. }
  10831.  
  10832. /*
  10833.   Z _ O P E N --  Open a file for the requested type of access.
  10834.  
  10835.   Call with:
  10836.     name:  Name of file to be opened.
  10837.     flags: Any combination of FM_xxx values except FM_EOF (ckcker.h).
  10838.   Returns:
  10839.     >= 0 on success: The assigned channel number
  10840.     <  0 on failure: A negative FX_xxx error code (ckcker.h).
  10841. */
  10842. int
  10843. z_open(name, flags) char * name; int flags; {
  10844.     int i, n;
  10845.     FILE * t;
  10846.     char * mode;
  10847.     debug(F111,"z_open",name,flags);
  10848.     if (!name) name = "";               /* Check name argument */
  10849.     if (!name[0])
  10850.       return(z_error = FX_BFN);
  10851.     if (flags & FM_CMD)                 /* Opening pipes not implemented yet */
  10852.       return(z_error = FX_NYI);         /* (and not portable either) */
  10853.     debug(F101,"z_open nfopnargs","",nfopnargs);
  10854.     if (flags < 0 || flags >= nfopnargs) /* Range check flags */
  10855.       return(z_error = FX_RNG);
  10856.     mode = fopnargs[flags];             /* Get fopen() arg */
  10857.     debug(F111,"z_open fopen args",mode,flags);
  10858.     if (!mode[0])                       /* Check for illegal combinations */
  10859.       return(z_error = FX_BOM);
  10860.     if (!z_inited) {                    /* If file structs not inited */
  10861.         debug(F101,"z_open z_maxchan 1","",z_maxchan);
  10862. #ifdef UNIX
  10863.         debug(F101,"z_open ckmaxfiles","",ckmaxfiles);
  10864.         if (ckmaxfiles > 0) {           /* Set in ck?tio.c: sysinit() */
  10865.             int x;
  10866.             x = ckmaxfiles - ZNFILS - 5;
  10867.             if (x > z_maxchan)          /* sysconf() value greater than */
  10868.               z_maxchan = x;            /* value from header files. */
  10869.             debug(F101,"z_open z_maxchan 2","",z_maxchan);
  10870.         }
  10871. #endif /* UNIX */
  10872.         if (z_maxchan < Z_MINCHAN)      /* Allocate at least this many. */
  10873.           z_maxchan = Z_MINCHAN;
  10874.         debug(F101,"z_open z_maxchan 3","",z_maxchan);
  10875.         /* Note: This could be a pretty big chunk of memory */
  10876.         /* if z_maxchan is a big number.  If this becomes a problem */
  10877.         /* we'll need to malloc and free each element at open/close time */
  10878.         if (!(z_file = (struct ckz_file *)
  10879.               malloc(sizeof(struct ckz_file) * (z_maxchan + 1))))
  10880.           return(z_error = FX_NMF);
  10881.         for (i = 0; i < z_maxchan; i++) {
  10882.             z_file[i].z_fp = NULL;
  10883.             z_file[i].z_flags = 0;
  10884.             z_file[i].z_nline = 0;
  10885.             *(z_file[i].z_name) = '\0';
  10886.         }
  10887.         z_inited = 1;                   /* Remember we did */
  10888.     }
  10889.     for (n = -1, i = 0; i < z_maxchan; i++) {
  10890.         if (!z_file[i].z_fp) {
  10891.             n = i;
  10892.             break;
  10893.         }
  10894.     }
  10895.     if (n < 0 || n >= z_maxchan)        /* Any free channels? */
  10896.       return(z_error = FX_NMF);         /* No, fail. */
  10897.     errno = 0;
  10898.  
  10899.     z_file[n].z_flags = 0;              /* In case of failure... */
  10900.  
  10901.     t = fopen(name, mode);              /* Try to open the file. */
  10902.     if (!t) {                           /* Failed... */
  10903.         debug(F111,"z_open error",name,errno);
  10904. #ifdef EMFILE
  10905.         if (errno == EMFILE)
  10906.           return(z_error = FX_NMF);
  10907. #endif /* EMFILE */
  10908.         return(z_error = (errno ?  FX_SYS : FX_UNK)); /* Return error code */
  10909.     }
  10910. #ifdef NT
  10911. #ifdef O_SEQUENTIAL
  10912.     if (t)                              /* Caching hint for NT */
  10913.       _setmode(_fileno(t),O_SEQUENTIAL);
  10914. #endif /* O_SEQUENTIAL */
  10915. #endif /* NT */
  10916.     z_nopen++;                          /* Open, count it. */
  10917.     z_file[n].z_fp = t;                 /* Stash the file pointer */
  10918.     z_file[n].z_flags = flags;          /* and the flags */
  10919.     z_error = 0;
  10920.     zfnqfp(name,CKMAXPATH,z_file[n].z_name); /* and the file's full name */
  10921.     return(n);                          /* Return the channel number */
  10922. }
  10923.  
  10924. int
  10925. z_close(channel) int channel; {         /* Close file on given channel */
  10926.     int x;
  10927.     FILE * t;
  10928.     if (!z_inited)                      /* Called before any files are open? */
  10929.       return(z_error = FX_NOP);
  10930.     if (channel >= z_maxchan)           /* Channel out of range? */
  10931.       return(z_error = FX_CHN);
  10932.     if (!(t = z_file[channel].z_fp))    /* Channel wasn't open? */
  10933.       return(z_error = FX_NOP);
  10934.     errno = 0;                          /* Set errno 0 to get a good reading */
  10935.     x = fclose(t);                      /* Try to close */
  10936.     if (x == EOF)                       /* On failure */
  10937.       return(z_error = FX_SYS);         /* indicate system error. */
  10938.     z_nopen--;                          /* Closed OK, decrement open count */
  10939.     z_file[channel].z_fp = NULL;        /* Set file pointer to NULL */
  10940.     z_file[channel].z_nline = 0;        /* Current line number is 0 */
  10941.     z_file[channel].z_flags = 0;        /* Set flags to 0 */
  10942.     *(z_file[channel].z_name) = '\0';   /* Clear name */
  10943.     return(z_error = 0);
  10944. }
  10945.  
  10946. /*
  10947.   Z _ O U T  --  Output string to channel.
  10948.  
  10949.   Call with:
  10950.     channel:     Channel number to write to.
  10951.     s:           String to write.
  10952.     length > -1: How many characters of s to write.
  10953.     length < 0:  Write entire NUL-terminated string.
  10954.     flags == 0:  Supply line termination.
  10955.     flags >  0:  Don't supply line termination.
  10956.     flags <  0:  Write 'length' NUL characters.
  10957.   Special case:
  10958.     If flags > -1 and s is empty or NULL and length == 1, write 1 NUL.
  10959.   Returns:
  10960.     Number of characters written to channel on success, or
  10961.     negative FX_xxx error code on failure.
  10962. */
  10963. int
  10964. z_out(channel,s,length,flags) int channel, flags, length; char * s; {
  10965.     FILE * t;
  10966.     int x, n;
  10967.     char c = '\0';
  10968.  
  10969.     if (!s) s = "";                     /* Guard against null pointer */
  10970. #ifdef DEBUG
  10971.     if (deblog) {
  10972.         debug(F111,"z_out",s,channel);
  10973.         debug(F101,"z_out length","",length);
  10974.         debug(F101,"z_out flags","",flags);
  10975.     }
  10976. #endif /* DEBUG */
  10977.     if (!z_inited)                      /* File i/o inited? */
  10978.       return(z_error = FX_NOP);
  10979.     if (channel >= z_maxchan)           /* Channel in range? */
  10980.       return(z_error = FX_CHN);
  10981.     if (!(t = z_file[channel].z_fp))    /* File open? */
  10982.       return(z_error = FX_NOP);
  10983.     if (!((z_file[channel].z_flags) & (FM_WRI|FM_APP))) /* In write mode? */
  10984.       return(z_error = FX_FOP);
  10985.     n = length;                         /* Length of string to write */
  10986.     if (n < 0) {                        /* Negative means get it ourselves */
  10987.         if (flags < 0)                  /* Except when told to write NULs in */
  10988.           return(z_error = FX_RNG);     /* which case args are inconsistent */
  10989.         n = strlen(s);                  /* Get length of string arg */
  10990.     }
  10991.     errno = 0;                          /* Reset errno */
  10992.     debug(F101,"z_out n","",n);
  10993.     if (flags < 0) {                    /* Writing NULs... */
  10994.         int i;
  10995.         for (i = 0; i < n; i++) {
  10996.             x = fwrite(&c,1,1,t);
  10997.             if (x < 1)
  10998.               return(z_error = (errno ? FX_SYS : FX_UNK));
  10999.         }
  11000.         z_file[channel].z_nline = -1;   /* Current line no longer known */
  11001.         z_error = 0;
  11002.         return(i);
  11003.     } else {                            /* Writing string arg */
  11004.         if (n == 1 && !s[0])            /* Writing one char but it's NUL */
  11005.           x = fwrite(&c,1,1,t);
  11006.         else                            /* Writing non-NUL char or string */
  11007.           x = fwrite(s,1,n,t);
  11008.         debug(F101,"z_out fwrite",ckitoa(x),errno);
  11009.         if (x < n)                      /* Failure to write requested amount */
  11010.           return(z_error = (errno ? FX_SYS : FX_UNK)); /* Return error */
  11011.         if (flags == 0) {               /* If supplying line termination */
  11012.             if (fwrite("\n",1,1,t))     /* do that  */
  11013.               x += z_lt;                /* count the terminator */
  11014.             if (z_file[channel].z_nline > -1) /* count this line */
  11015.               z_file[channel].z_nline++;
  11016.         } else {
  11017.             z_file[channel].z_nline = -1; /* Current line no longer known */
  11018.         }
  11019.     }
  11020.     z_error = 0;
  11021.     return(x);
  11022. }
  11023.  
  11024. #define Z_INBUFLEN 64
  11025.  
  11026. /*
  11027.   Z _ I N  --  Multichannel i/o file input function.
  11028.  
  11029.   Call with:
  11030.     channel number to read from.
  11031.     s = address of destination buffer.
  11032.     buflen = destination buffer length.
  11033.     length = Number of bytes to read, must be < buflen.
  11034.     flags: 0 = read a line; nonzero = read the given number of bytes.
  11035.   Returns:
  11036.     Number of bytes read into buffer or a negative error code.
  11037.     A terminating NUL is deposited after the last byte that was read.
  11038. */
  11039. int
  11040. z_in(channel,s,buflen,length,flags)
  11041.  int channel, buflen, length, flags; char * s;
  11042. /* z_in */ {
  11043.     int i, j, x;
  11044.     FILE * t;
  11045.     char * p;
  11046.  
  11047.     if (!z_inited)                      /* Check everything... */
  11048.       return(z_error = FX_NOP);
  11049.     if (channel >= z_maxchan)
  11050.       return(z_error = FX_CHN);
  11051.     if (!(t = z_file[channel].z_fp))
  11052.       return(z_error = FX_NOP);
  11053.     if (!((z_file[channel].z_flags) & FM_REA))
  11054.       return(z_error = FX_FOP);
  11055.     if (!s)                             /* Check destination */
  11056.      return(z_error = FX_RNG);
  11057.     s[0] = NUL;
  11058.     if (length == 0)                    /* Read 0 bytes - easy. */
  11059.       return(z_error = 0);
  11060.     debug(F101,"z_in channel","",channel);
  11061.     debug(F101,"z_in buflen","",buflen);
  11062.     debug(F101,"z_in length","",length);
  11063.     debug(F101,"z_in flags","",flags);
  11064.     if (length < 0 || buflen < 0)       /* Check length args */
  11065.       return(z_error = FX_RNG);
  11066.     if (buflen <= length)
  11067.       return(z_error = FX_RNG);
  11068.     errno = 0;                          /* Reset errno */
  11069.     if (flags) {                        /* Read block or byte */
  11070.         i = fread(s,1,length,t);
  11071. #ifdef DEBUG
  11072.         if (deblog) {
  11073.             debug(F111,"z_in block",s,i);
  11074.             debug(F101,"z_in block errno","",errno);
  11075.             debug(F101,"z_in block ferror","",ferror(t));
  11076.             debug(F101,"z_in block feof","",feof(t));
  11077.         }
  11078. #endif /* DEBUG */
  11079.         z_file[channel].z_nline = -1;   /* Current line no longer known */
  11080.     } else {                            /* Read line */
  11081. #ifndef COMMENT
  11082.         /* This method is used because it's simpler than the others */
  11083.         /* and also marginally faster. */
  11084.         debug(F101,"z_in getc loop","",ftell(t));
  11085.         for (i = 0; i < length; i++) {
  11086.             if ((x = getc(t)) == EOF) {
  11087.                 debug(F101,"z_in getc error","",ftell(t));
  11088.                 s[i] = '\0';
  11089.                 break;
  11090.             }
  11091.             s[i] = x;
  11092.             if (s[i] == '\n') {
  11093.                 s[i] = '\0';
  11094.                 break;
  11095.             }
  11096.         }
  11097.         debug(F111,"z_in line byte loop",ckitoa(errno),i);
  11098.         debug(F111,"z_in line got",s,z_file[channel].z_nline);
  11099.         if (z_file[channel].z_nline > -1)
  11100.           z_file[channel].z_nline++;
  11101. #else
  11102. #ifdef COMMENT2
  11103.         /* Straightforward but strlen() slows it down. */
  11104.         s[0] = '\0';
  11105.         i = 0;
  11106.         if (fgets(s,length,t)) {
  11107.             i = strlen(s);
  11108.             if (i > 0 && s[i-1] == '\n') i--;
  11109.         }
  11110.         debug(F111,"z_in line fgets",ckitoa(errno),i);
  11111.         if (z_file[channel].z_nline > -1)
  11112.           z_file[channel].z_nline++;
  11113. #else
  11114.         /* This is a do-it-yourself fgets() with its own readahead and */
  11115.         /* putback.  It's a bit faster than real fgets() but not enough */
  11116.         /* to justify the added complexity or the risk of the ftell() and */
  11117.         /* fseek() calls failing. */
  11118.         int k, flag = 0;
  11119.         long pos;
  11120.         for (i = 0; !flag && i <= (length - Z_INBUFLEN); i += Z_INBUFLEN) {
  11121.             k = ((length - i) < Z_INBUFLEN) ? length - i : Z_INBUFLEN;
  11122.             if ((x = fread(s+i,1,k,t)) < 1)
  11123.               break;
  11124.             s[i+x] = '\0';
  11125.             for (j = 0; j < x; j++) {
  11126.                 if (s[i+j] == '\n') {
  11127.                     s[i+j] = '\0';
  11128.                     flag ++;
  11129.                     pos = ftell(t);
  11130.                     if (pos > -1) {
  11131.                         pos -= (x - j - 1);
  11132.                         x = fseek(t, pos, 0);
  11133.                         i += j;
  11134.                         break;
  11135.                     } else
  11136.                       return(z_error = FX_SYS);
  11137.                 }
  11138.             }
  11139.         }
  11140.         if (z_file[channel].z_nline > -1)
  11141.           z_file[channel].z_nline++;
  11142.         debug(F111,"z_in line chunk loop",ckitoa(errno),i);
  11143. #endif /* COMMENT2 */
  11144. #endif /* COMMENT */
  11145.     }
  11146.     debug(F111,"z_in i",ckitoa(errno),i);
  11147.     if (i < 0) i = 0;                   /* NUL-terminate result */
  11148.     s[i] = '\0';
  11149.     if (i > 0) {
  11150.         z_error = 0;
  11151.         return(i);
  11152.     }
  11153.     if (i == 0 && feof(t))              /* EOF on reading? */
  11154.       return(z_error = FX_EOF);         /* Return EOF code */
  11155.     return(errno ? (z_error = -1) : i); /* Return length or system error */
  11156. }
  11157.  
  11158. int
  11159. z_flush(channel) int channel; {         /* Flush output channel */
  11160.     FILE * t;
  11161.     int x;
  11162.     if (!z_inited)                      /* Regular checks */
  11163.       return(z_error = FX_NOP);
  11164.     if (channel >= z_maxchan)
  11165.       return(z_error = FX_CHN);
  11166.     if (!(t = z_file[channel].z_fp))
  11167.       return(z_error = FX_NOP);
  11168.     if (!((z_file[channel].z_flags) & (FM_WRI|FM_APP))) /* Write access? */
  11169.       return(z_error = FX_FOP);
  11170.     errno = 0;                          /* Reset errno */
  11171.     x = fflush(t);                      /* Try to flush */
  11172.     return(x ? (z_error = FX_SYS) : 0); /* Return system error or 0 if OK */
  11173. }
  11174.  
  11175. int
  11176. #ifdef CK_ANSIC
  11177. z_seek(int channel, long pos)           /* Move file pointer to byte */
  11178. #else
  11179. z_seek(channel,pos) int channel; long pos; /* (seek to given position) */
  11180. #endif /* CK_ANSIC */
  11181. {
  11182.     int i, x = 0, rc;
  11183.     FILE * t;
  11184.     if (!z_inited)                      /* Check... */
  11185.       return(z_error = FX_NOP);
  11186.     if (channel >= z_maxchan)
  11187.       return(z_error = FX_CHN);
  11188.     if (!(t = z_file[channel].z_fp))
  11189.       return(z_error = FX_NOP);
  11190.     if (pos < 0L) {
  11191.         x = 2;
  11192.         pos = (pos == -2) ? -1L : 0L;
  11193.     }
  11194.     errno = 0;
  11195.     rc = fseek(t,pos,x);                /* Try to seek */
  11196.     debug(F111,"z_seek",ckitoa(errno),rc);
  11197.     if (rc < 0)                         /* OK? */
  11198.       return(z_error = FX_SYS); /* No. */
  11199.     z_file[channel].z_nline = ((pos || x) ? -1 : 0);
  11200.     return(z_error = 0);
  11201. }
  11202.  
  11203. int
  11204. #ifdef CK_ANSIC
  11205. z_line(int channel, long pos)           /* Move file pointer to line */
  11206. #else
  11207. z_line(channel,pos) int channel; long pos; /* (seek to given position) */
  11208. #endif /* CK_ANSIC */
  11209. {
  11210.     int i, len, x = 0;
  11211.     long current = 0L, prev = -1L, old = -1L;
  11212.     FILE * t;
  11213.     char tmpbuf[256];
  11214.     if (!z_inited)                      /* Check... */
  11215.       return(z_error = FX_NOP);
  11216.     if (channel >= z_maxchan)
  11217.       return(z_error = FX_CHN);
  11218.     if (!(t = z_file[channel].z_fp))
  11219.       return(z_error = FX_NOP);
  11220.     debug(F101,"z_line pos","",pos);
  11221.     if (pos < 0L) {                     /* EOF wanted */
  11222.         long n;
  11223.         n = z_file[channel].z_nline;
  11224.         debug(F101,"z_line n","",n);
  11225.         if (n < 0 || pos < 0) {
  11226.             rewind(t);
  11227.             n = 0;
  11228.         }
  11229.         while (1) {                     /* This could take a while... */
  11230.             if ((x = getc(t)) == EOF)
  11231.               break;
  11232.             if (x == '\n') {
  11233.                 n++;
  11234.                 if (pos == -2) {
  11235.                     old = prev;
  11236.                     prev = ftell(t);
  11237.                 }
  11238.             }
  11239.         }
  11240.         debug(F101,"z_line old","",old);
  11241.         debug(F101,"z_line prev","",prev);
  11242.         if (pos == -2) {
  11243.             if ((x = z_seek(channel,old)) < 0)
  11244.               return(z_error = x);
  11245.             else
  11246.               n--;
  11247.         }
  11248.         z_file[channel].z_nline = n;
  11249.         return(z_error = 0);
  11250.     }
  11251.     if (pos == 0L) {                    /* Rewind wanted */
  11252.         z_file[channel].z_nline = 0L;
  11253.         rewind(t);
  11254.         debug(F100,"z_line rewind","",0);
  11255.         return(0L);
  11256.     }
  11257.     tmpbuf[255] = NUL;                  /* Make sure buf is NUL terminated */
  11258.     current = z_file[channel].z_nline;  /* Current line */
  11259.     /*
  11260.       If necessary the following could be optimized, e.g. for positioning
  11261.       to a previous line in a large file without starting over.
  11262.     */
  11263.     if (current < 0 || pos < current) { /* Not known or behind us... */
  11264.         debug(F101,"z_line rewinding","",pos);
  11265.         if ((x = z_seek(channel, 0L)) < 0) /* Rewind */
  11266.           return(z_error = x);
  11267.         if (pos == 0)                   /* If 0th line wanted we're done */
  11268.           return(z_error = 0);
  11269.         current = 0;
  11270.     }
  11271.     while (current < pos) {             /* Search for specified line */
  11272.         if (fgets(tmpbuf,255,t)) {
  11273.             len = strlen(tmpbuf);
  11274.             if (len > 0 && tmpbuf[len-1] == '\n') {
  11275.                 current++;
  11276.                 debug(F111,"z_line read",ckitoa(len),current);
  11277.             } else if (len == 0) {
  11278.                 return(z_error = FX_UNK);
  11279.             }
  11280.         } else {
  11281.             z_file[channel].z_nline = -1L;
  11282.             debug(F101,"z_line premature EOF","",current);
  11283.             return(z_error = FX_EOF);
  11284.         }
  11285.     }
  11286.     z_file[channel].z_nline = current;
  11287.     debug(F101,"z_line result","",current);
  11288.     z_error = 0;
  11289.     return(current);
  11290. }
  11291.  
  11292. char *
  11293. z_getname(channel) int channel; {       /* Return name of file on channel */
  11294.     FILE * t;
  11295.     if (!z_inited) {
  11296.         z_error = FX_NOP;
  11297.         return(NULL);
  11298.     }
  11299.     if (channel >= z_maxchan) {
  11300.         z_error = FX_CHN;
  11301.         return(NULL);
  11302.     }
  11303.     if (!(t = z_file[channel].z_fp)) {
  11304.         z_error = FX_NOP;
  11305.         return(NULL);
  11306.     }
  11307.     return((char *)(z_file[channel].z_name));
  11308. }
  11309.  
  11310. int
  11311. z_getmode(channel) int channel; {       /* Return OPEN modes of channel */
  11312.     FILE * t;                           /* 0 if file not open */
  11313. #ifndef NOSTAT
  11314. #ifdef NT
  11315.     struct _stat statbuf;
  11316. #else /* NT */
  11317.     struct stat statbuf;
  11318. #endif /* NT */
  11319. #endif /* NOSTAT */
  11320.     int x;
  11321.     if (!z_inited)
  11322.       return(0);
  11323.     if (channel >= z_maxchan)
  11324.       return(z_error = FX_CHN);
  11325.     if (!(t = z_file[channel].z_fp))
  11326.       return(0);
  11327.     x = z_file[channel].z_flags;
  11328.     if (feof(t)) {                      /* This might not work for */
  11329.         x |= FM_EOF;                    /* output files */
  11330. #ifndef NOSTAT
  11331.     /* But this does if we can use it. */
  11332.     } else if (stat(z_file[channel].z_name,&statbuf) > -1) {
  11333.         if (ftell(t) == statbuf.st_size)
  11334.           x |= FM_EOF;
  11335. #endif /* NOSTAT */
  11336.     }
  11337.     return(x);
  11338. }
  11339.  
  11340. long
  11341. z_getpos(channel) int channel; {        /* Get file pointer position */
  11342.     FILE * t;                           /* on this channel */
  11343.     long x;
  11344.     if (!z_inited)
  11345.       return(z_error = FX_NOP);
  11346.     if (channel >= z_maxchan)
  11347.       return(z_error = FX_CHN);
  11348.     if (!(t = z_file[channel].z_fp))
  11349.       return(z_error = FX_NOP);
  11350.     x = ftell(t);
  11351.     return((x < 0L) ? (z_error = FX_SYS) : x);
  11352. }
  11353.  
  11354. long
  11355. z_getline(channel) int channel; {       /* Get current line number */
  11356.     FILE * t;                           /* in file on this channel */
  11357.     long rc;
  11358.     if (!z_inited)
  11359.       return(z_error = FX_NOP);
  11360.     if (channel >= z_maxchan)
  11361.       return(z_error = FX_CHN);
  11362.     if (!(t = z_file[channel].z_fp))
  11363.       return(z_error = FX_NOP);
  11364.     debug(F101,"z_getline","",z_file[channel].z_nline);
  11365.     rc = z_file[channel].z_nline;
  11366.     return((rc < 0) ? (z_error = FX_LNU) : rc);
  11367. }
  11368.  
  11369. int
  11370. z_getfnum(channel) int channel; {       /* Get file number / handle */
  11371.     FILE * t;                           /* for file on this channel */
  11372.     if (!z_inited)
  11373.       return(z_error = FX_NOP);
  11374.     if (channel >= z_maxchan)
  11375.       return(z_error = FX_CHN);
  11376.     if (!(t = z_file[channel].z_fp))
  11377.       return(z_error = FX_NOP);
  11378.     z_error = 0;
  11379.     return(fileno(t));
  11380. }
  11381.  
  11382. /*
  11383.   Line-oriented counts and seeks are as dumb as they can be at the moment.
  11384.   Later we can speed them up by building little indexes.
  11385. */
  11386. long
  11387. z_count(channel, what) int channel, what; { /* Count bytes or lines in file */
  11388.     FILE * t;
  11389.     int i, x;
  11390.     long pos, count = 0L;
  11391.     if (!z_inited)                      /* Check stuff... */
  11392.       return(z_error = FX_NOP);
  11393.     if (channel >= z_maxchan)
  11394.       return(z_error = FX_CHN);
  11395.     if (!(t = z_file[channel].z_fp))
  11396.       return(z_error = FX_NOP);
  11397.     pos = ftell(t);                     /* Save current file pointer */
  11398.     errno = 0;
  11399.     z_error = 0;
  11400.     if (what == RD_CHAR) {              /* Size in bytes requested */
  11401.         if (!fseek(t,0L,2)) {           /* Seek to end */
  11402.             count = ftell(t);           /* Get file pointer */
  11403.             fseek(t,pos,0);             /* Restore file file pointer */
  11404.             return(count);
  11405.         } else                          /* Fallback in case seek fails */
  11406.           return(zgetfs(z_file[channel].z_name));
  11407.     }
  11408.     rewind(t);                          /* Line count requested - rewind. */
  11409.     while (1) {                         /* Count lines. */
  11410.         if ((x = getc(t)) == EOF)       /* Stupid byte loop */
  11411.           break;                        /* but it works as well as anything */
  11412.         if (x == '\n')                  /* else... */
  11413.           count++;
  11414.     }
  11415.     x = fseek(t,pos,0);                 /* Restore file pointer */
  11416.     return(count);
  11417. }
  11418.  
  11419. /* User interface for generalized channel-oriented file i/o */
  11420.  
  11421. struct keytab fctab[] = {               /* FILE subcommands */
  11422.     { "close",      FIL_CLS, 0 },
  11423.     { "count",      FIL_COU, 0 },
  11424.     { "flush",      FIL_FLU, 0 },
  11425.     { "list",       FIL_LIS, 0 },
  11426.     { "open",       FIL_OPN, 0 },
  11427.     { "read",       FIL_REA, 0 },
  11428.     { "rewind",     FIL_REW, 0 },
  11429.     { "seek",       FIL_SEE, 0 },
  11430.     { "status",     FIL_STA, 0 },
  11431.     { "write",      FIL_WRI, 0 }
  11432. };
  11433. int nfctab = (sizeof (fctab) / sizeof (struct keytab));
  11434.  
  11435. static struct keytab fcswtab[] = {      /* OPEN modes */
  11436.     { "/append",    FM_APP,  0 },
  11437.     { "/binary",    FM_BIN,  0 },
  11438. #ifdef COMMENT
  11439.     { "/command",   FM_CMD,  0 },       /* Not implemented */
  11440. #endif /* COMMENT */
  11441.     { "/read",      FM_REA,  0 },
  11442.     { "/write",     FM_WRI,  0 }
  11443. };
  11444. static int nfcswtab = (sizeof (fcswtab) / sizeof (struct keytab));
  11445.  
  11446. static struct keytab fclkwtab[] = {     /* CLOSE options */
  11447.     { "all",        1,       0 }
  11448. };
  11449.  
  11450. static struct keytab fsekwtab[] = {     /* SEEK symbols */
  11451.     { "eof",        1,       0 },
  11452.     { "last",       2,       0 }
  11453. };
  11454. static int nfsekwtab = (sizeof (fsekwtab) / sizeof (struct keytab));
  11455.  
  11456. #define SEE_LINE  RD_LINE               /* SEEK options */
  11457. #define SEE_CHAR  RD_CHAR
  11458. #define SEE_REL   3
  11459. #define SEE_ABS   4
  11460.  
  11461. static struct keytab fskswtab[] = {
  11462.     { "/absolute",  SEE_ABS,  0 },
  11463.     { "/byte",      SEE_CHAR, 0 },
  11464.     { "/character", SEE_CHAR, CM_INV },
  11465.     { "/line",      SEE_LINE, 0 },
  11466.     { "/relative",  SEE_REL,  0 }
  11467. };
  11468. static int nfskswtab = (sizeof (fskswtab) / sizeof (struct keytab));
  11469.  
  11470. #define COU_LINE  RD_LINE               /* COUNT options */
  11471. #define COU_CHAR  RD_CHAR
  11472. #define COU_LIS   3
  11473. #define COU_NOL   4
  11474.  
  11475. static struct keytab fcoswtab[] = {
  11476.     { "/bytes",     COU_CHAR, 0      },
  11477.     { "/characters",COU_CHAR, CM_INV },
  11478.     { "/lines",     COU_LINE, 0      },
  11479.     { "/list",      COU_LIS,  0      },
  11480.     { "/nolist",    COU_NOL,  0      },
  11481.     { "/quiet",     COU_NOL,  CM_INV }
  11482. };
  11483. static int nfcoswtab = (sizeof (fcoswtab) / sizeof (struct keytab));
  11484.  
  11485. static struct keytab frdtab[] = {       /* READ types */
  11486.     { "/block",     RD_SIZE, CM_INV|CM_ARG },
  11487.     { "/byte",      RD_CHAR, CM_INV },
  11488.     { "/character", RD_CHAR, 0      },
  11489.     { "/line",      RD_LINE, 0      },
  11490.     { "/size",      RD_SIZE, CM_ARG }
  11491. };
  11492. static int nfrdtab = (sizeof (frdtab) / sizeof (struct keytab));
  11493.  
  11494. static struct keytab fwrtab[] = {       /* WRITE types */
  11495.     { "/block",     WR_SIZE, CM_INV|CM_ARG },
  11496.     { "/byte",      WR_CHAR, CM_INV },
  11497.     { "/character", WR_CHAR, 0      },
  11498.     { "/line",      WR_LINE, 0      },
  11499.     { "/lpad",      WR_LPAD, CM_ARG },
  11500.     { "/rpad",      WR_RPAD, CM_ARG },
  11501.     { "/size",      WR_SIZE, CM_ARG },
  11502.     { "/string",    WR_STRI, 0      }
  11503. };
  11504. static int nfwrtab = (sizeof (fwrtab) / sizeof (struct keytab));
  11505.  
  11506. static char blanks[] = "\040\040\040\040"; /* Some blanks for formatting */
  11507.  
  11508. int
  11509. dofile(op) int op; {                    /* Do the FILE command */
  11510.     char vnambuf[VNAML];                /* Buffer for variable names */
  11511.     char *vnp = NULL;                   /* Pointer to same */
  11512.     char zfilnam[CKMAXPATH+2];
  11513.     char * p;
  11514.     struct FDB fl, sw, nu;
  11515.     long z;
  11516.     int rsize, filmode = 0, relative = -1, eofflg = 0;
  11517.     int rc, x, y, cx, n, getval, dummy, confirmed, listing = -1;
  11518.     int charflag = 0, sizeflag = 0;
  11519.     int pad = 32, wr_lpad = 0, wr_rpad = 0;
  11520.  
  11521.     if (op == XXFILE) {                 /* FILE command was given */
  11522.         /* Get subcommand */
  11523.         if ((cx = cmkey(fctab,nfctab,"Operation","",xxstring)) < 0) {
  11524.             if (cx == -3) {
  11525.                 printf("?File operation required\n");
  11526.                 x = -9;
  11527.             }
  11528.             return(cx);
  11529.         }
  11530.     } else {                            /* Shorthand command was given */
  11531.         switch (op) {
  11532.           case XXF_CL: cx = FIL_CLS; break; /* FCLOSE */
  11533.           case XXF_FL: cx = FIL_FLU; break; /* FFLUSH */
  11534.           case XXF_LI: cx = FIL_LIS; break; /* FLIST */
  11535.           case XXF_OP: cx = FIL_OPN; break; /* etc... */
  11536.           case XXF_RE: cx = FIL_REA; break;
  11537.           case XXF_RW: cx = FIL_REW; break;
  11538.           case XXF_SE: cx = FIL_SEE; break;
  11539.           case XXF_ST: cx = FIL_STA; break;
  11540.           case XXF_WR: cx = FIL_WRI; break;
  11541.           case XXF_CO: cx = FIL_COU; break;
  11542.           default: return(-2);
  11543.         }
  11544.     }
  11545.     switch (cx) {                       /* Do requested subcommand */
  11546.       case FIL_OPN:                     /* OPEN */
  11547.         cmfdbi(&sw,                     /* Switches */
  11548.                _CMKEY,                  /* fcode */
  11549.                "Variable or switch",    /* hlpmsg */
  11550.                "",                      /* default */
  11551.                "",                      /* addtl string data */
  11552.                nfcswtab,                /* addtl numeric data 1: tbl size */
  11553.                4,                       /* addtl numeric data 2: 4 = cmswi */
  11554.                xxstring,                /* Processing function */
  11555.                fcswtab,                 /* Keyword table */
  11556.                &fl                      /* Pointer to next FDB */
  11557.                );
  11558.         cmfdbi(&fl,                     /* Anything that doesn't match */
  11559.                _CMFLD,                  /* fcode */
  11560.                "Variable",              /* hlpmsg */
  11561.                "",
  11562.                "",
  11563.                0,
  11564.                0,
  11565.                NULL,
  11566.                NULL,
  11567.                NULL
  11568.                );
  11569.         while (1) {
  11570.             x = cmfdb(&sw);             /* Parse something */
  11571.             if (x < 0) {
  11572.                 if (x == -3) {
  11573.                     printf("?Variable name and file name required\n");
  11574.                     x = -9;
  11575.                 }
  11576.                 return(x);
  11577.             }
  11578.             if (cmresult.fcode == _CMFLD)
  11579.               break;
  11580.             else if (cmresult.fcode == _CMKEY) {
  11581.                 char c;
  11582.                 c = cmgbrk();
  11583.                 if ((getval =
  11584.                      (c == ':' || c == '=')) && !(cmgkwflgs() & CM_ARG)) {
  11585.                     printf("?This switch does not take an argument\n");
  11586.                     return(-9);
  11587.                 }
  11588. #ifdef COMMENT
  11589.                 /* Uncomment if we add any switches ere that take args */
  11590.                 if (!getval && (cmgkwflgs() & CM_ARG)) {
  11591.                     printf("?This switch requires an argument\n");
  11592.                     return(-9);         /* (none do...) */
  11593.                 }
  11594. #endif /* COMMENT */
  11595.                 filmode |= cmresult.nresult; /* OR in the file mode */
  11596.             } else
  11597.               return(-2);
  11598.         }
  11599.         /* Not a switch - get the string */
  11600.         ckstrncpy(vnambuf,cmresult.sresult,VNAML);
  11601.         if (!vnambuf[0] || chknum(vnambuf)) { /* (if there is one...) */
  11602.             printf("?Variable name required\n");
  11603.             return(-9);
  11604.         }
  11605.         vnp = vnambuf;                  /* Check variable-name syntax */
  11606.         if (vnambuf[0] == CMDQ &&
  11607.             (vnambuf[1] == '%' || vnambuf[1] == '&'))
  11608.           vnp++;
  11609.         y = 0;
  11610.         if (*vnp == '%' || *vnp == '&') {
  11611.             if ((y = parsevar(vnp,&x,&dummy)) < 0) {
  11612.                 printf("?Syntax error in variable name\n");
  11613.                 return(-9);
  11614.             }
  11615.         }
  11616.         if (!(filmode & FM_RWA))        /* If no access mode specified */
  11617.           filmode |= FM_REA;            /* default to /READ. */
  11618.  
  11619.         y = 0;                          /* Now parse the filename */
  11620.         if ((filmode & FM_RWA) == FM_WRI)
  11621.           x = cmofi("Name of new file","",&s,xxstring);
  11622.         else if ((filmode & FM_RWA) == FM_REA)
  11623.           x = cmifi("Name of existing file","",&s,&y,xxstring);
  11624.         else {
  11625.             x = cmiofi("Filename","",&s,&y,xxstring);
  11626.             debug(F101,"fopen /append x","",x);
  11627.         }
  11628.         if (x == -9) {
  11629.             if (zchko(s) < 0) {
  11630.                 printf("Can't create \"%s\"\n",s);
  11631.                 return(x);
  11632.             }
  11633.         } else if (x < 0) {
  11634.             if (x == -3) {
  11635.                 printf("?Filename required\n");
  11636.                 x = -9;
  11637.             }
  11638.             return(x);
  11639.         }
  11640.         if (y) {                        /* No wildcards */
  11641.             printf("?Wildcards not allowed here\n");
  11642.             return(-9);
  11643.         }
  11644.         if (filmode & (FM_APP|FM_WRI)) { /* Check output access */
  11645. #ifndef VMS
  11646.             if (zchko(s) < 0) {          /* and set error code if denied */
  11647.                 z_error = FX_ACC;
  11648.                 printf("?Write access denied - \"%s\"\n",s);
  11649.                 return(-9);
  11650.             }
  11651. #endif /* VMS */
  11652.         }
  11653.         ckstrncpy(zfilnam,s,CKMAXPATH); /* Is OK - make safe copy */
  11654.         if ((x = cmcfm()) < 0)          /* Get confirmation of command */
  11655.           return(x);
  11656.         if ((n = z_open(zfilnam,filmode)) < 0) {
  11657.             printf("?OPEN failed - %s: %s\n",zfilnam,ckferror(n));
  11658.             return(-9);
  11659.         }
  11660.         addmac(vnambuf,ckitoa(n));      /* Assign channel number to variable */
  11661.         return(success = 1);
  11662.  
  11663.       case FIL_REW:                     /* REWIND */
  11664.         if ((x = cmnum("Channel number","",10,&n, xxstring)) < 0) {
  11665.             if (x == -3) {
  11666.                 printf("?Channel number required\n");
  11667.                 x = -9;
  11668.             }
  11669.             return(x);
  11670.         }
  11671.         if ((x = cmcfm()) < 0)
  11672.           return(x);
  11673.         if ((rc = z_seek(n,0L)) < 0) {
  11674.             printf("?REWIND failed - Channel %d: %s\n",n,ckferror(rc));
  11675.             return(-9);
  11676.         }
  11677.         return(success = 1);
  11678.  
  11679.       case FIL_CLS:                     /* CLOSE */
  11680.           cmfdbi(&sw,                   /* Second FDB - switches */
  11681.                  _CMKEY,                /* fcode */
  11682.                  "Channel number; or keyword",
  11683.                  "",
  11684.                  "",                    /* addtl string data */
  11685.                  1,                     /* addtl numeric data 1: tbl size */
  11686.                  0,                     /* addtl numeric data 2: 4 = cmswi */
  11687.                  xxstring,              /* Processing function */
  11688.                  fclkwtab,              /* Keyword table */
  11689.                  &nu                    /* Pointer to next FDB */
  11690.                  );
  11691.           cmfdbi(&nu,                   /* First FDB - command switches */
  11692.                  _CMNUM,                /* fcode */
  11693.                  "",
  11694.                  "",                    /* default */
  11695.                  "",                    /* addtl string data */
  11696.                  10,                    /* addtl numeric data 1: radix */
  11697.                  0,                     /* addtl numeric data 2: 0 */
  11698.                  xxstring,              /* Processing function */
  11699.                  NULL,                  /* Keyword table */
  11700.                  NULL                   /* Pointer to next FDB */
  11701.                  );                     /*  */
  11702.         x = cmfdb(&sw);                 /* Parse something */
  11703.         if (x < 0) {
  11704.             if (x == -3) {
  11705.                 printf("?Channel number or ALL required\n");
  11706.                 x = -9;
  11707.             }
  11708.             return(x);
  11709.         }
  11710.         if (cmresult.fcode == _CMNUM)
  11711.           n = cmresult.nresult;
  11712.         else if (cmresult.fcode == _CMKEY)
  11713.           n = -1;
  11714.         if ((x = cmcfm()) < 0)
  11715.           return(x);
  11716.         rc = 1;
  11717.         if (n < 0) {
  11718.             int count = 0;
  11719.             int i;
  11720.             for (i = 0; i < z_maxchan; i++) {
  11721.                 x = z_close(i);
  11722.                 if (x == FX_SYS) {
  11723.                     printf("?CLOSE failed - Channel %d: %s\n",n,ckferror(x));
  11724.                     rc = 0;
  11725.                 } else if (x > -1)
  11726.                   count++;
  11727.             }
  11728.             debug(F101,"FILE CLOSE ALL","",count);
  11729.         } else if ((x = z_close(n)) < 0) {
  11730.             printf("?CLOSE failed - Channel %d: %s\n",n,ckferror(x));
  11731.             return(-9);
  11732.         }
  11733.         return(success = rc);
  11734.  
  11735.       case FIL_REA:                     /* READ */
  11736.       case FIL_WRI:                     /* WRITE */
  11737.         rsize = 0;
  11738.         cmfdbi(&sw,                     /* Switches */
  11739.                _CMKEY,                  /* fcode */
  11740.                "Channel or switch",     /* hlpmsg */
  11741.                "",                      /* default */
  11742.                "",                      /* addtl string data */
  11743.                (cx == FIL_REA) ? nfrdtab : nfwrtab,
  11744.                4,                       /* addtl numeric data 2: 4 = cmswi */
  11745.                xxstring,                /* Processing function */
  11746.                (cx == FIL_REA) ? frdtab : fwrtab, /* Keyword table */
  11747.                &nu                      /* Pointer to next FDB */
  11748.                );
  11749.         cmfdbi(&nu,                     /* Channel number */
  11750.                _CMNUM,                  /* fcode */
  11751.                "Channel",
  11752.                "",                      /* default */
  11753.                "",                      /* addtl string data */
  11754.                10,                      /* addtl numeric data 1: radix */
  11755.                0,                       /* addtl numeric data 2: 0 */
  11756.                xxstring,                /* Processing function */
  11757.                NULL,                    /* Keyword table */
  11758.                NULL                     /* Pointer to next FDB */
  11759.                );
  11760.         do {
  11761.             x = cmfdb(&sw);             /* Parse something */
  11762.             if (x < 0) {
  11763.                 if (x == -3) {
  11764.                     printf("?Channel number required\n");
  11765.                     x = -9;
  11766.                 }
  11767.                 return(x);
  11768.             }
  11769.             if (cmresult.fcode == _CMNUM) /* Channel number */
  11770.               break;
  11771.             else if (cmresult.fcode == _CMKEY) { /* Switch */
  11772.                 char c;
  11773.                 c = cmgbrk();
  11774.                 if ((getval =
  11775.                      (c == ':' || c == '=')) && !(cmgkwflgs() & CM_ARG)) {
  11776.                     printf("?This switch does not take an argument\n");
  11777.                     return(-9);
  11778.                 }
  11779.                 if (!getval && (cmgkwflgs() & CM_ARG)) {
  11780.                     printf("?This switch requires an argument\n");
  11781.                     return(-9);
  11782.                 }
  11783.                 switch (cmresult.nresult) {
  11784.                   case WR_LINE:
  11785.                     charflag = 0;
  11786.                     sizeflag = 0;
  11787.                     rsize = 0;
  11788.                     break;
  11789.                   case WR_CHAR:
  11790.                     rsize = 1;
  11791.                     charflag = 1;
  11792.                     sizeflag = 1;
  11793.                     break;
  11794.                   case WR_SIZE:
  11795.                     if ((x = cmnum("Bytes","",10,&rsize, xxstring)) < 0) {
  11796.                         if (x == -3) {
  11797.                             printf("?Number required\n");
  11798.                             x = -9;
  11799.                         }
  11800.                         return(x);
  11801.                     }
  11802.                     charflag = 0;
  11803.                     sizeflag = 1;
  11804.                     break;
  11805.                   case WR_STRI:
  11806.                     rsize = 1;
  11807.                     charflag = 0;
  11808.                     sizeflag = 0;
  11809.                     break;
  11810.                   case WR_LPAD:
  11811.                   case WR_RPAD:
  11812.                     if ((x = cmnum("Numeric ASCII character value",
  11813.                                    "32",10,&pad, xxstring)) < 0)
  11814.                       return(x);
  11815.                     if (cmresult.nresult == WR_LPAD)
  11816.                       wr_lpad = 1;
  11817.                     else
  11818.                       wr_rpad = 1;
  11819.                     break;
  11820.                 }
  11821.                 debug(F101,"FILE READ rsize 2","",rsize);
  11822.             } else
  11823.               return(-2);
  11824.         } while
  11825.           (cmresult.fcode == _CMKEY);
  11826.  
  11827.         n = cmresult.nresult;           /* Channel */
  11828.         debug(F101,"FILE READ/WRITE channel","",n);
  11829.  
  11830.         if (cx == FIL_WRI) {            /* WRITE */
  11831.             int len = 0;
  11832.             if ((x = cmtxt("Text","",&s,xxstring)) < 0)
  11833.               return(x);
  11834.             ckstrncpy(line,s,LINBUFSIZ); /* Make a safe copy */
  11835.             s = line;
  11836.             s = brstrip(s);             /* Strip braces */
  11837.             if (charflag) {             /* Write one char */
  11838.                 len = 1;                /* So length = 1 */
  11839.                 rsize = 1;              /* Don't supply terminator */
  11840.             } else if (!sizeflag) {     /* Write a string */
  11841.                 len = -1;               /* So length is unspecified */
  11842.             } else {                    /* Write a block of given size */
  11843.                 int i, k, xx;
  11844.                 if (rsize > TMPBUFSIZ) {
  11845.                     z_error = FX_OFL;
  11846.                     printf("?Buffer overflow\n");
  11847.                     return(-9);
  11848.                 }
  11849.                 len = rsize;            /* rsize is really length */
  11850.                 rsize = 1;              /* Don't supply a terminator */
  11851.                 xx = strlen(s);         /* Size of given string */
  11852.                 if (xx >= len) {        /* Bigger or equal */
  11853.                     s[len] = NUL;
  11854.                 } else if (wr_lpad) {   /* Smaller, left-padding requested */
  11855.                     for (i = 0; i < len - xx; i++) /* Must make a copy */
  11856.                       tmpbuf[i] = pad;
  11857.                     ckstrncpy(tmpbuf+i,s,TMPBUFSIZ-i);
  11858.                     tmpbuf[len] = NUL;
  11859.                     s = tmpbuf;         /* Redirect write source */
  11860.                 } else if (wr_rpad) {   /* Smaller with right-padding */
  11861.                     for (i = xx; i < len; i++)
  11862.                       s[i] = pad;
  11863.                     s[len] = NUL;
  11864.                 }
  11865.             }
  11866.             if ((rc = z_out(n,s,len,rsize)) < 0) { /* Try to write */
  11867.                 printf("?Channel %d WRITE error: %s\n",n,ckferror(rc));
  11868.                 return(-9);
  11869.             }
  11870.         } else {                        /* FIL_REA READ */
  11871.             confirmed = 0;
  11872.             vnambuf[0] = NUL;
  11873.             x = cmfld("Variable name","",&s,NULL);
  11874.             debug(F111,"FILE READ cmfld",s,x);
  11875.             if (x < 0) {
  11876.                 if (x == -3 || !*s) {
  11877.                     if ((x = cmcfm()) < 0)
  11878.                       return(x);
  11879.                     else
  11880.                       confirmed++;
  11881.                 } else
  11882.                   return(x);
  11883.             }
  11884.             ckstrncpy(vnambuf,s,VNAML);
  11885.             debug(F111,"FILE READ vnambuf",vnambuf,confirmed);
  11886.             if (vnambuf[0]) {           /* Variable name given, check it */
  11887.                 if (!confirmed) {
  11888.                     x = cmcfm();
  11889.                     if (x < 0)
  11890.                       return(x);
  11891.                     else
  11892.                       confirmed++;
  11893.                 }
  11894.                 vnp = vnambuf;
  11895.                 if (vnambuf[0] == CMDQ &&
  11896.                     (vnambuf[1] == '%' || vnambuf[1] == '&'))
  11897.                   vnp++;
  11898.                 y = 0;
  11899.                 if (*vnp == '%' || *vnp == '&') {
  11900.                     if ((y = parsevar(vnp,&x,&dummy)) < 0) {
  11901.                         printf("?Syntax error in variable name\n");
  11902.                         return(-9);
  11903.                     }
  11904.                 }
  11905.             }
  11906.             debug(F111,"FILE READ variable",vnambuf,confirmed);
  11907.  
  11908.             if (!confirmed)
  11909.               if ((x = cmcfm()) < 0)
  11910.                 return(x);
  11911.  
  11912.             line[0] = NUL;              /* Clear destination buffer */
  11913.             if (rsize >= LINBUFSIZ)     /* Don't overrun it */
  11914.               rsize = LINBUFSIZ - 1;
  11915.  
  11916.             if (rsize == 0)             /* Read a line */
  11917.               rc = z_in(n,line,LINBUFSIZ,LINBUFSIZ-1,0);
  11918.             else
  11919.               rc = z_in(n,line,LINBUFSIZ,rsize,1); /* Read a block */
  11920.             if (rc < 0) {               /* Error... */
  11921.                 debug(F101,"FILE READ error","",rc);
  11922.                 debug(F101,"FILE READ errno","",errno);
  11923.                 if (rc == FX_EOF) {     /* EOF - fail but no error message */
  11924.                     return(success = 0);
  11925.                 } else {                /* Other error - fail and print msg */
  11926.                     printf("?READ error: %s\n",ckferror(rc));
  11927.                     return(-9);
  11928.                 }
  11929.             }
  11930.             debug(F110,"FILE READ data",line,0);
  11931.             if (vnambuf[0])             /* Read OK - If variable name given */
  11932.               addmac(vnambuf,line);     /* Assign result to variable */
  11933.             else                        /* otherwise */
  11934.               printf("%s\n",line);      /* just print it */
  11935.         }
  11936.         return(success = 1);
  11937.  
  11938.       case FIL_SEE:                     /* SEEK */
  11939.       case FIL_COU:                     /* COUNT */
  11940.         rsize = RD_CHAR;                /* Defaults to /BYTE */
  11941.         cmfdbi(&sw,                     /* Switches */
  11942.                _CMKEY,                  /* fcode */
  11943.                "Channel or switch",     /* hlpmsg */
  11944.                "",                      /* default */
  11945.                "",                      /* addtl string data */
  11946.                ((cx == FIL_SEE) ? nfskswtab : nfcoswtab),
  11947.                4,                       /* addtl numeric data 2: 4 = cmswi */
  11948.                xxstring,                /* Processing function */
  11949.                ((cx == FIL_SEE) ? fskswtab : fcoswtab),
  11950.                &nu                      /* Pointer to next FDB */
  11951.                );
  11952.         cmfdbi(&nu,                     /* Channel number */
  11953.                _CMNUM,                  /* fcode */
  11954.                "Channel",
  11955.                "",                      /* default */
  11956.                "",                      /* addtl string data */
  11957.                10,                      /* addtl numeric data 1: radix */
  11958.                0,                       /* addtl numeric data 2: 0 */
  11959.                xxstring,                /* Processing function */
  11960.                NULL,                    /* Keyword table */
  11961.                NULL                     /* Pointer to next FDB */
  11962.                );
  11963.         do {
  11964.             x = cmfdb(&sw);             /* Parse something */
  11965.             if (x < 0) {
  11966.                 if (x == -3) {
  11967.                     printf("?Channel number required\n");
  11968.                     x = -9;
  11969.                 }
  11970.                 return(x);
  11971.             }
  11972.             if (cmresult.fcode == _CMNUM) /* Channel number */
  11973.               break;
  11974.             else if (cmresult.fcode == _CMKEY) { /* Switch */
  11975.                 char c;
  11976.                 c = cmgbrk();
  11977.                 if ((getval =
  11978.                      (c == ':' || c == '=')) && !(cmgkwflgs() & CM_ARG)) {
  11979.                     printf("?This switch does not take an argument\n");
  11980.                     return(-9);
  11981.                 }
  11982.                 if (cx == FIL_SEE) {
  11983.                     switch (cmresult.nresult) {
  11984.                       case SEE_REL: relative = 1; break;
  11985.                       case SEE_ABS: relative = 0; break;
  11986.                       default: rsize = cmresult.nresult;
  11987.                     }
  11988.                 } else if (cx == FIL_COU) {
  11989.                     switch (cmresult.nresult) {
  11990.                       case COU_LIS: listing = 1; break;
  11991.                       case COU_NOL: listing = 0; break;
  11992.                       default: rsize = cmresult.nresult;
  11993.                     }
  11994.                 }
  11995.             }
  11996.         } while
  11997.           (cmresult.fcode == _CMKEY);
  11998.  
  11999.         n = cmresult.nresult;           /* Channel */
  12000.         debug(F101,"FILE SEEK/COUNT channel","",n);
  12001.         if (cx == FIL_COU) {
  12002.             if ((x = cmcfm()) < 0)
  12003.               return(x);
  12004.             z_filcount = z_count(n,rsize);
  12005.             if (z_filcount < 0) {
  12006.                 rc = z_filcount;
  12007.                 printf("?COUNT error: %s\n",ckferror(rc));
  12008.                 return(-9);
  12009.             }
  12010.             if (listing < 0)
  12011.               listing = !xcmdsrc;
  12012.             if (listing)
  12013.               printf(" %ld %s%s\n",
  12014.                      z_filcount,
  12015.                      ((rsize == RD_CHAR) ? "byte" : "line"),
  12016.                      ((z_filcount == 1L) ? "" : "s")
  12017.                      );
  12018.             return(success = (z_filcount > -1) ? 1 : 0);
  12019.         }
  12020.         cmfdbi(&sw,                     /* SEEK symbolic targets (EOF) */
  12021.                _CMKEY,                  /* fcode */
  12022.                "Channel number;\n or keyword",
  12023.                "",
  12024.                "",                      /* addtl string data */
  12025.                nfsekwtab,               /* addtl numeric data 1: table size */
  12026.                0,                       /* addtl numeric data 2: 4 = cmswi */
  12027.                xxstring,                /* Processing function */
  12028.                fsekwtab,                /* Keyword table */
  12029.                &nu                      /* Pointer to next FDB */
  12030.                );
  12031.         cmfdbi(&nu,                     /* Channel number */
  12032.                _CMNUM,                  /* fcode */
  12033.                "",
  12034.                "",                      /* default */
  12035.                "",                      /* addtl string data */
  12036.                10,                      /* addtl numeric data 1: radix */
  12037.                0,                       /* addtl numeric data 2: 0 */
  12038.                xxstring,                /* Processing function */
  12039.                NULL,                    /* Keyword table */
  12040.                NULL                     /* Pointer to next FDB */
  12041.                );
  12042.         x = cmfdb(&sw);                 /* Parse something */
  12043.         if (x < 0) {
  12044.             if (x == -3) {
  12045.                 printf("?Channel number or EOF required\n");
  12046.                 x = -9;
  12047.             }
  12048.             return(x);
  12049.         }
  12050.         if (cmresult.fcode == _CMNUM) {
  12051.             y = cmresult.nresult;
  12052.             debug(F110,"FILE SEEK atmbuf",atmbuf,0);
  12053.             if (relative < 0) {
  12054.                 if (cx == FIL_SEE && (atmbuf[0] == '+' || atmbuf[0] == '-'))
  12055.                   relative = 1;
  12056.                 else
  12057.                   relative = 0;
  12058.             }
  12059.         } else if (cmresult.fcode == _CMKEY) {
  12060.             eofflg = cmresult.nresult;
  12061.             relative = 0;
  12062.             y = 0 - eofflg;
  12063.         }
  12064.         if ((x = cmcfm()) < 0)
  12065.           return(x);
  12066.         z = y;                          /* Convert to long */
  12067.         y = 1;                          /* Recycle this */
  12068.         z_flush(n);
  12069.         debug(F101,"FILE SEEK relative","",relative);
  12070.         debug(F101,"FILE SEEK rsize","",rsize);
  12071.  
  12072.         if (rsize == RD_CHAR) {         /* Seek to byte position */
  12073.             if (relative > 0) {
  12074.                 long pos;
  12075.                 pos = z_getpos(n);
  12076.                 if (pos < 0L) {
  12077.                     rc = pos;
  12078.                     printf("?Relative SEEK failed: %s\n",ckferror(rc));
  12079.                     return(-9);
  12080.                 }
  12081.                 z += pos;
  12082.             } else {
  12083.                 if (z < 0 && !eofflg) { /* Negative arg but not relative */
  12084.                     y = 0;              /* Remember this was bad */
  12085.                     z = 0;              /* but substitute 0 */
  12086.                 }
  12087.             }
  12088.             debug(F101,"FILE SEEK /CHAR z","",z);
  12089.             if (z < 0 && !eofflg) {
  12090.                 z_error = FX_RNG;
  12091.                 return(success = 0);
  12092.             }
  12093.             if ((rc = z_seek(n,z)) < 0) {
  12094.                 if (rc == FX_EOF) return(success = 0);
  12095.                 printf("?SEEK /BYTE failed - Channel %d: %s\n",n,ckferror(rc));
  12096.                 return(-9);
  12097.             }
  12098.         } else {                        /* Seek to line */
  12099.             if (relative > 0) {
  12100.                 long pos;
  12101.                 pos = z_getline(n);
  12102.                 debug(F101,"FILE SEEK /LINE pos","",pos);
  12103.                 if (pos < 0L) {
  12104.                     rc = pos;
  12105.                     printf("?Relative SEEK failed: %s\n",ckferror(rc));
  12106.                     return(-9);
  12107.                 }
  12108.                 z += pos;
  12109.             }
  12110.             debug(F101,"FILE SEEK /LINE z","",z);
  12111.             debug(F101,"FILE SEEK /LINE eofflg","",eofflg);
  12112.             if (z < 0 && !eofflg) {
  12113.                 z_error = FX_RNG;
  12114.                 return(success = 0);
  12115.             }
  12116.             if ((rc = z_line(n,z)) < 0) {
  12117.                 if (rc == FX_EOF) return(success = 0);
  12118.                 printf("?SEEK /LINE failed - Channel %d: %s\n",n,ckferror(rc));
  12119.                 return(-9);
  12120.             }
  12121.         }
  12122.         return(success = y);
  12123.  
  12124.       case FIL_LIS: {                   /* LIST open files */
  12125. #ifdef CK_TTGWSIZ
  12126.           extern int cmd_rows, cmd_cols;
  12127. #endif /* CK_TTGWSIZ */
  12128.           extern int xaskmore;
  12129.           int i, x, n = 0, paging = 0;
  12130.           char * s;
  12131.  
  12132.           if ((x = cmcfm()) < 0)
  12133.             return(x);
  12134.  
  12135. #ifdef CK_TTGWSIZ
  12136.           if (cmd_rows > 0 && cmd_cols > 0)
  12137. #endif /* CK_TTGWSIZ */
  12138.             paging = xaskmore;
  12139.  
  12140.           printf("System open file limit: %4d\n", z_openmax);
  12141.           printf("Maximum for FILE OPEN:  %4d\n", z_maxchan);
  12142.           printf("Files currently open:   %4d\n\n", z_nopen);
  12143.           n = 4;
  12144.           for (i = 0; i < z_maxchan; i++) {
  12145.               s = z_getname(i);         /* Got one? */
  12146.               if (s) {                  /* Yes */
  12147.                   char m[8];
  12148.                   m[0] = NUL;
  12149.                   printf("%2d. %s",i,s); /* Print name */
  12150.                   n++;                   /* Count it */
  12151.                   x = z_getmode(i);      /* Get modes & print them */
  12152.                   if (x > -1) {
  12153.                       if (x & FM_REA) ckstrncat(m,"R",8);
  12154.                       if (x & FM_WRI) ckstrncat(m,"W",8);
  12155.                       if (x & FM_APP) ckstrncat(m,"A",8);
  12156.                       if (x & FM_BIN) ckstrncat(m,"B",8);
  12157.                       if (m[0])
  12158.                         printf(" (%s)",m);
  12159.                       if (x & FM_EOF)
  12160.                         printf(" [EOF]");
  12161.                       else
  12162.                         printf(" %ld",z_getpos(i)); /* And file position too */
  12163.                   }
  12164.                   printf("\n");
  12165. #ifdef CK_TTGWSIZ
  12166.                   if (paging > 0) {     /* Pause at end of screen */
  12167.                       if (n > cmd_rows - 3) {
  12168.                           if (!askmore())
  12169.                             break;
  12170.                           else
  12171.                             n = 0;
  12172.                       }
  12173.                   }
  12174. #endif /* CK_TTGWSIZ */
  12175.               }
  12176.           }
  12177.           return(success = 1);
  12178.       }
  12179.  
  12180.       case FIL_FLU:                     /* FLUSH */
  12181.         if ((x = cmnum("Channel number","",10,&n, xxstring)) < 0) {
  12182.             if (x == -3) {
  12183.                 printf("?Channel number required\n");
  12184.                 x = -9;
  12185.             }
  12186.             return(x);
  12187.         }
  12188.         if ((x = cmcfm()) < 0)
  12189.           return(x);
  12190.         if ((rc = z_flush(n)) < 0) {
  12191.             printf("?FLUSH failed - Channel %d: %s\n",n,ckferror(rc));
  12192.             return(-9);
  12193.         }
  12194.         return(success = 1);
  12195.  
  12196.       case FIL_STA:                     /* STATUS */
  12197.         if ((x = cmnum("Channel number","",10,&n, xxstring)) < 0) {
  12198.             if (x == -3) {
  12199.                 printf("?Channel number required\n");
  12200.                 x = -9;
  12201.             }
  12202.             return(x);
  12203.         }
  12204.         if ((x = cmcfm()) < 0)
  12205.           return(x);
  12206.         p = blanks + 3;                 /* Tricky formatting... */
  12207.         if (n < 1000) p--;
  12208.         if (n < 100) p--;
  12209.         if (n < 10) p--;
  12210.         if ((rc = z_getmode(n)) < 0) {
  12211.             printf("Channel %d:%s%s\n",n,p,ckferror(rc));
  12212.             return(success = 0);
  12213.         } else if (!rc) {
  12214.             printf("Channel %d:%sNot open\n",n,p);
  12215.             return(success = 0);
  12216.         } else {
  12217.             long xx;
  12218.             s = z_getname(n);
  12219.             if (!s) s = "(name unknown)";
  12220.             printf("Channel %d:%sOpen\n",n,p);
  12221.             printf(" File:        %s\n Modes:      ",s);
  12222.             if (rc & FM_REA) printf(" /READ");
  12223.             if (rc & FM_WRI) printf(" /WRITE");
  12224.             if (rc & FM_APP) printf(" /APPEND");
  12225.             if (rc & FM_BIN) printf(" /BINARY");
  12226.             if (rc & FM_CMD) printf(" /COMMAND");
  12227.             if (rc & FM_EOF) printf(" [EOF]");
  12228.             printf("\n Size:        %ld\n",z_count(n,RD_CHAR));
  12229.             printf(" At byte:     %ld\n",z_getpos(n));
  12230.             xx = z_getline(n);
  12231.             if (xx > -1)
  12232.               printf(" At line:     %ld\n",xx);
  12233.             return(success = 1);
  12234.         }
  12235.       default:
  12236.         return(-2);
  12237.     }
  12238. }
  12239. #endif /* CKCHANNELIO */
  12240.  
  12241. #ifndef NOSETKEY
  12242. /* Save Key maps and in OS/2 Mouse maps */
  12243. int
  12244. savkeys(name,disp) char * name; int disp; {
  12245.     char *tp;
  12246.     static struct filinfo xx;
  12247.     int savfil, i, j, k;
  12248.     char buf[1024];
  12249.  
  12250.     zclose(ZMFILE);
  12251.  
  12252.     if (disp) {
  12253.         xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  12254.         xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = "";
  12255.         xx.lblopts = 0;
  12256.         savfil = zopeno(ZMFILE,name,NULL,&xx);
  12257.     } else savfil = zopeno(ZMFILE,name,NULL,NULL);
  12258.  
  12259.     if (savfil) {
  12260. #ifdef OS2
  12261.         ztime(&tp);
  12262.         zsout(ZMFILE, "; Kermit 95 SAVE KEYMAP file: ");
  12263.         zsoutl(ZMFILE,tp);
  12264.         if (mskkeys) {
  12265.             zsoutl(ZMFILE,
  12266.          "if eq \"\\v(program)\" \"C-Kermit\" set mskermit keycodes on");
  12267.         } else {
  12268.             zsoutl(ZMFILE,
  12269.          "if NOT eq \"\\v(program)\" \"C-Kermit\" stop 1 C-Kermit required.");
  12270.             zsoutl(ZMFILE,"set mskermit keycodes off");
  12271.         }
  12272.         zsoutl(ZMFILE,"");
  12273. #else /* OS2 */
  12274.         ztime(&tp);
  12275.         zsout(ZMFILE, "; C-Kermit SAVE KEYMAP file: ");
  12276.         zsoutl(ZMFILE,tp);
  12277. #endif /* OS2 */
  12278.  
  12279.         zsoutl(ZMFILE,"; Clear previous keyboard mappings ");
  12280.         zsoutl(ZMFILE,"set key clear");
  12281. #ifdef OS2
  12282.         for (k = 0; k < nttkey; k++) {
  12283.             if (!ttkeytab[k].flgs) {
  12284.                 ckmakmsg(buf,1024,
  12285.                          "set terminal key ",
  12286.                          ttkeytab[k].kwd,
  12287.                          " clear",
  12288.                          NULL
  12289.                          );
  12290.                 zsoutl(ZMFILE,buf);
  12291.             }
  12292.         }
  12293. #endif /* OS2 */
  12294.         zsoutl(ZMFILE,"");
  12295.  
  12296.         for (i = 0; i < KMSIZE; i++) {
  12297.             if (macrotab[i]) {
  12298.                 int len = strlen((char *)macrotab[i]);
  12299. #ifdef OS2
  12300.                 ckmakmsg(buf,
  12301.                          1024,
  12302.                          "set key \\",
  12303.                          ckitoa(mskkeys ? cktomsk(i) : i),
  12304.                          " ",
  12305.                          NULL
  12306.                          );
  12307. #else /* OS2 */
  12308.                 ckmakmsg(buf,
  12309.                          1024,
  12310.                          "set key \\",
  12311.                          ckitoa(i),
  12312.                          NULL,NULL
  12313.                          );
  12314. #endif /* OS2 */
  12315.                 zsout(ZMFILE,buf);
  12316.  
  12317.                 for (j = 0; j < len; j++) {
  12318.                     char ch = macrotab[i][j];
  12319.                     if (ch <= SP || ch >= DEL ||
  12320.                          ch == '-' || ch == ',' ||
  12321.                          ch == '{' || ch == '}' ||
  12322.                          ch == ';' || ch == '?' ||
  12323.                          ch == '.' || ch == '\'' ||
  12324.                          ch == '\\' || ch == '/' ||
  12325.                          ch == '#') {
  12326.                         ckmakmsg(buf,1024,"\\{",ckitoa((int)ch),"}",NULL);
  12327.                         zsout(ZMFILE,buf);
  12328.                     } else {
  12329.                         ckmakmsg(buf,1024,ckctoa((char)ch),NULL,NULL,NULL);
  12330.                         zsout(ZMFILE,buf);
  12331.                     }
  12332.                 }
  12333. #ifdef OS2
  12334.                 ckmakmsg(buf,1024,"\t; ",keyname(i),NULL,NULL);
  12335.                 zsoutl(ZMFILE,buf);
  12336. #else
  12337.                 zsoutl(ZMFILE,"");
  12338. #endif /* OS2 */
  12339.             } else if ( keymap[i] != i ) {
  12340. #ifndef NOKVERBS
  12341.                 if (IS_KVERB(keymap[i])) {
  12342.                     for (j = 0; j < nkverbs; j++)
  12343.                       if (kverbs[j].kwval == (keymap[i] & ~F_KVERB))
  12344.                         break;
  12345.                     if (j != nkverbs) {
  12346. #ifdef OS2
  12347. #ifdef COMMENT
  12348.                         sprintf(buf, "set key \\%d \\K%s\t; %s",
  12349.                                 mskkeys ? cktomsk(i) : i,
  12350.                                 kverbs[j].kwd, keyname(i)
  12351.                                 );
  12352. #else
  12353.                         ckmakxmsg(buf,  /* 12 string args */
  12354.                                   1024,
  12355.                                   "set key \\",
  12356.                                   ckitoa(mskkeys ? cktomsk(i) : i),
  12357.                                   " \\K",
  12358.                                   kverbs[j].kwd,
  12359.                                   "\t; ",
  12360.                                   keyname(i),
  12361.                                   NULL, NULL, NULL, NULL, NULL, NULL);
  12362. #endif /* COMMENT */
  12363.                         zsoutl(ZMFILE,buf);
  12364. #else
  12365. #ifdef COMMENT
  12366.                         sprintf(buf, "set key \\%d \\K%s", i, kverbs[j].kwd);
  12367. #else
  12368.                         ckmakmsg(buf,1024,
  12369.                                  "set key \\",
  12370.                                  ckitoa(i),
  12371.                                  " \\K",
  12372.                                  kverbs[j].kwd
  12373.                                  );
  12374. #endif /* COMMENT */
  12375.                         zsoutl(ZMFILE,buf);
  12376. #endif
  12377.                     }
  12378.                 } else
  12379. #endif /* NOKVERBS */
  12380.                   {
  12381. #ifdef OS2
  12382. #ifdef COMMENT
  12383.                       sprintf(buf, "set key \\%d \\{%d}\t; %s",
  12384.                               mskkeys ? cktomsk(i) : i,
  12385.                               keymap[i],
  12386.                               keyname(i)
  12387.                               );
  12388. #else
  12389.                       ckmakxmsg(buf,    /* 8 string args */
  12390.                                 1024,
  12391.                                 "set key \\",
  12392.                                 ckitoa(mskkeys ? cktomsk(i) : i),
  12393.                                 " \\{",
  12394.                                 ckitoa(keymap[i]),
  12395.                                 "}\t; ",
  12396.                                 keyname(i),
  12397.                                 NULL,NULL,NULL,NULL,NULL,NULL);
  12398. #endif /* COMMENT */
  12399.                       zsoutl(ZMFILE,buf);
  12400. #else
  12401. #ifdef COMMENT
  12402.                       sprintf(buf, "set key \\%d \\{%d}", i, keymap[i]);
  12403. #else
  12404.                       ckmakxmsg(buf,1024,
  12405.                                "set key \\",
  12406.                                ckitoa(i),
  12407.                                " \\{",
  12408.                                ckitoa(keymap[i]),
  12409.                                "}",
  12410.                                NULL,NULL,NULL,NULL,NULL,NULL,NULL);
  12411. #endif /* COMMENT */
  12412.                       zsoutl(ZMFILE,buf);
  12413. #endif /* OS2 */
  12414.                   }
  12415.             }
  12416.         }
  12417. #ifdef OS2
  12418.         /* OS/2 also has the SET TERMINAL KEY <termtype> defines */
  12419.         for (k = 0; k < nttkey; k++) {
  12420.             extern struct keynode * ttkeymap[];
  12421.             struct keynode * pnode = NULL;
  12422.  
  12423.             if (ttkeytab[k].flgs)       /* Don't process CM_INV or CM_ABR */
  12424.               continue;
  12425.  
  12426.             zsoutl(ZMFILE,"");
  12427.             ckmakmsg(buf,1024,"; SET TERMINAL KEY ",ttkeytab[k].kwd,NULL,NULL);
  12428.             zsoutl(ZMFILE,buf);
  12429.  
  12430.             for (pnode = ttkeymap[ttkeytab[k].kwval];
  12431.                  pnode;
  12432.                  pnode = pnode->next
  12433.                  ) {
  12434.                 switch (pnode->def.type) {
  12435.                   case key:
  12436. #ifdef COMMENT
  12437.                     sprintf(buf, "set terminal key %s \\%d \\{%d}\t; %s",
  12438.                             ttkeytab[k].kwd,
  12439.                             mskkeys ? cktomsk(pnode->key) : pnode->key,
  12440.                             pnode->def.key.scancode,
  12441.                             keyname(pnode->key)
  12442.                             );
  12443. #else
  12444.                     ckmakxmsg(buf,
  12445.                               1024,
  12446.                               "set terminal key ",
  12447.                               ttkeytab[k].kwd,
  12448.                               " \\",
  12449.                               ckitoa(mskkeys ?
  12450.                                      cktomsk(pnode->key) :
  12451.                                      pnode->key),
  12452.                               " \\{",
  12453.                               ckitoa(pnode->def.key.scancode),
  12454.                               "}\t; ",
  12455.                               keyname(pnode->key),
  12456.                               NULL,NULL,NULL,NULL
  12457.                               );
  12458. #endif /* COMMENT */
  12459.                     zsoutl(ZMFILE,buf);
  12460.                     break;
  12461.                   case kverb:
  12462.                     for (j = 0; j < nkverbs; j++)
  12463.                       if (kverbs[j].kwval == (pnode->def.kverb.id & ~F_KVERB))
  12464.                         break;
  12465.                     if (j != nkverbs) {
  12466. #ifdef COMMENT
  12467.                         sprintf(buf, "set terminal key %s \\%d \\K%s\t; %s",
  12468.                                 ttkeytab[k].kwd,
  12469.                                 mskkeys ? cktomsk(pnode->key) : pnode->key,
  12470.                                 kverbs[j].kwd, keyname(pnode->key)
  12471.                                 );
  12472. #else
  12473.                         ckmakxmsg(buf,
  12474.                                   1024,
  12475.                                   "set terminal key ",
  12476.                                   ttkeytab[k].kwd,
  12477.                                   " \\",
  12478.                                   ckitoa(mskkeys ?
  12479.                                          cktomsk(pnode->key) :
  12480.                                          pnode->key),
  12481.                                   " \\K",
  12482.                                   kverbs[j].kwd,
  12483.                                   "\t; ",
  12484.                                   keyname(pnode->key),
  12485.                                   NULL,NULL,NULL,NULL
  12486.                                   );
  12487. #endif /* COMMENT */
  12488.                         zsoutl(ZMFILE,buf);
  12489.                     }
  12490.                     break;
  12491.                   case macro: {
  12492.                       int len = strlen((char *)pnode->def.macro.string);
  12493. #ifdef COMMENT
  12494.                       sprintf(buf,"set terminal key %s \\%d ",
  12495.                               ttkeytab[k].kwd,
  12496.                               mskkeys ? cktomsk(pnode->key) : pnode->key);
  12497. #else
  12498.                       ckmakxmsg(buf,
  12499.                                1024,
  12500.                                "set terminal key ",
  12501.                                ttkeytab[k].kwd,
  12502.                                " \\",
  12503.                                ckitoa(mskkeys ?
  12504.                                       cktomsk(pnode->key) :
  12505.                                       pnode->key),
  12506.                                " ",
  12507.                                NULL,NULL,NULL,NULL,NULL,NULL,NULL
  12508.                               );
  12509. #endif /* COMMENT */
  12510.                       zsout(ZMFILE,buf);
  12511.  
  12512.                       for (j = 0; j < len; j++) {
  12513.                           char ch = pnode->def.macro.string[j];
  12514.                           if (ch <= SP || ch >= DEL ||
  12515.                                ch == '-' || ch == ',' ||
  12516.                                ch == '{' || ch == '}' ||
  12517.                                ch == ';' || ch == '?' ||
  12518.                                ch == '.' || ch == '\'' ||
  12519.                                ch == '\\' || ch == '/' ||
  12520.                                ch == '#') {
  12521.                               ckmakmsg(buf,1024,
  12522.                                        "\\{",ckitoa((int)ch),"}",NULL);
  12523.                               zsout(ZMFILE,buf);
  12524.                           } else {
  12525.                               ckmakmsg(buf,1024,
  12526.                                        ckctoa((char)ch),NULL,NULL,NULL);
  12527.                               zsout(ZMFILE,buf);
  12528.                           }
  12529.                       }
  12530.                       ckmakmsg(buf,1024,"\t; ",keyname(pnode->key),NULL,NULL);
  12531.                       zsoutl(ZMFILE,buf);
  12532.                       break;
  12533.                   }
  12534.                   case literal: {
  12535.                       int len = strlen((char *)pnode->def.literal.string);
  12536. #ifdef COMMENT
  12537.                       sprintf(buf,"set terminal key %s /literal \\%d ",
  12538.                               ttkeytab[k].kwd,
  12539.                               mskkeys ? cktomsk(pnode->key) : pnode->key);
  12540. #else
  12541.                       ckmakxmsg(buf,
  12542.                                1024,
  12543.                                "set terminal key ",
  12544.                                ttkeytab[k].kwd,
  12545.                                " /literal \\",
  12546.                                ckitoa(mskkeys ?
  12547.                                       cktomsk(pnode->key) :
  12548.                                       pnode->key),
  12549.                                " ",
  12550.                                NULL,NULL,NULL,NULL,NULL,NULL,NULL);
  12551. #endif /* COMMENT */
  12552.                       zsout(ZMFILE,buf);
  12553.  
  12554.                       for (j = 0; j < len; j++) {
  12555.                           char ch = pnode->def.literal.string[j];
  12556.                           if (ch <= SP || ch >= DEL ||
  12557.                                ch == '-' || ch == ',' ||
  12558.                                ch == '{' || ch == '}' ||
  12559.                                ch == ';' || ch == '?' ||
  12560.                                ch == '.' || ch == '\'' ||
  12561.                                ch == '\\' || ch == '/' ||
  12562.                                ch == '#') {
  12563.                               ckmakmsg(buf,1024,
  12564.                                        "\\{",ckitoa((int)ch),"}",NULL);
  12565.                               zsout(ZMFILE,buf);
  12566.                           } else {
  12567.                               ckmakmsg(buf,1024,
  12568.                                        ckctoa((char)ch),NULL,NULL,NULL);
  12569.                               zsout(ZMFILE,buf);
  12570.                           }
  12571.                       }
  12572.                       ckmakmsg(buf,1024,"\t; ",keyname(pnode->key),NULL,NULL);
  12573.                       zsoutl(ZMFILE,buf);
  12574.                       break;
  12575.                   }
  12576.                   case esc:
  12577. #ifdef COMMENT
  12578.                     sprintf(buf,
  12579.                        "set terminal key %s /literal \\%d \\{%d}\\{%d}\t; %s",
  12580.                             ttkeytab[k].kwd,
  12581.                             mskkeys ? cktomsk(pnode->key) : pnode->key,
  12582.                             ISDG200(ttkeytab[k].kwval) ? 30 : 27,
  12583.                             pnode->def.esc.key & ~F_ESC,
  12584.                             keyname(pnode->key)
  12585.                             );
  12586. #else
  12587.                     ckmakxmsg(buf,
  12588.                               1024,
  12589.                               "set terminal key ",
  12590.                               ttkeytab[k].kwd,
  12591.                               " /literal \\",
  12592.                               ckitoa(mskkeys ?
  12593.                                      cktomsk(pnode->key) :
  12594.                                      pnode->key),
  12595.                               " \\{",
  12596.                               ckitoa(ISDG200(ttkeytab[k].kwval) ? 30 : 27),
  12597.                               "}\\{",
  12598.                               ckitoa(pnode->def.esc.key & ~F_ESC),
  12599.                               "}\t; ",
  12600.                               keyname(pnode->key),
  12601.                               NULL,NULL
  12602.                               );
  12603. #endif /* COMMENT */
  12604.                     zsoutl(ZMFILE,buf);
  12605.                     break;
  12606.                   case csi:
  12607. #ifdef COMMENT
  12608.                     sprintf(buf,
  12609.                        "set terminal key %s /literal \\%d \\{27}[\\{%d}\t; %s",
  12610.                             ttkeytab[k].kwd,
  12611.                             mskkeys ? cktomsk(pnode->key) : pnode->key,
  12612.                             pnode->def.csi.key & ~F_CSI,
  12613.                             keyname(pnode->key)
  12614.                             );
  12615. #else
  12616.                     ckmakxmsg(buf,
  12617.                               1024,
  12618.                               "set terminal key ",
  12619.                               ttkeytab[k].kwd,
  12620.                               " /literal \\",
  12621.                               ckitoa(mskkeys ?
  12622.                                      cktomsk(pnode->key) :
  12623.                                      pnode->key),
  12624.                               " \\{27}[\\{",
  12625.                               ckitoa(pnode->def.csi.key & ~F_CSI),
  12626.                               "}\t; ",
  12627.                               keyname(pnode->key),
  12628.                               NULL,NULL,NULL,NULL
  12629.                               );
  12630. #endif /* COMMENT */
  12631.                     zsoutl(ZMFILE,buf);
  12632.                     break;
  12633.                   default:
  12634.                     continue;
  12635.                 }
  12636.             }
  12637.         }
  12638. #endif /* OS2 */
  12639.  
  12640.         zsoutl(ZMFILE,"");
  12641.         zsoutl(ZMFILE,"; End");
  12642.         zclose(ZMFILE);
  12643.         return(success = 1);
  12644.     } else {
  12645.         return(success = 0);
  12646.     }
  12647. }
  12648. #endif /* NOSETKEY */
  12649.  
  12650. #define SV_SCRL 0
  12651. #define SV_HIST 1
  12652.  
  12653. #ifdef OS2
  12654. #ifndef NOLOCAL
  12655. static struct keytab trmtrmopt[] = {
  12656.     { "scrollback", SV_SCRL, 0 }
  12657. };
  12658. #endif /* NOLOCAL */
  12659. #endif /* OS2 */
  12660.  
  12661. static struct keytab cmdtrmopt[] = {
  12662. #ifdef CK_RECALL
  12663.     { "history",    SV_HIST, 0 },
  12664. #endif /* CK_RECALL */
  12665. #ifdef OS2
  12666. #ifndef NOLOCAL
  12667.     { "scrollback", SV_SCRL, 0 },
  12668. #endif /* NOLOCAL */
  12669. #endif /* OS2 */
  12670.     { "", 0, 0 }
  12671. };
  12672. static int ncmdtrmopt = (sizeof (cmdtrmopt) / sizeof (struct keytab)) - 1;
  12673.  
  12674. #ifdef OS2
  12675. #ifndef NOLOCAL
  12676. _PROTOTYP(int savscrbk, (int, char *, int));
  12677. #endif /* NOLOCAL */
  12678. #endif /* OS2 */
  12679.  
  12680. #ifdef CK_RECALL
  12681. _PROTOTYP(int savhistory, (char *, int));
  12682. #endif /* CK_RECALL */
  12683.  
  12684. int
  12685. dosave(xx) int xx; {
  12686.     int x, y = 0, disp;
  12687.     char * s = NULL;
  12688.     extern struct keytab disptb[];
  12689. #ifdef ZFNQFP
  12690.     struct zfnfp * fnp;
  12691. #endif /* ZFNQFP */
  12692.  
  12693. #ifndef NOSETKEY
  12694.     if (xx == XSKEY) {                  /* SAVE KEYMAP.. */
  12695.         z = cmofi("Name of Kermit command file","keymap.ksc",&s,xxstring);
  12696.     } else {
  12697. #endif /* NOSETKEY */
  12698.         switch (xx) {
  12699.           case XSCMD:                   /* SAVE COMMAND.. */
  12700.             if ((y = cmkey(cmdtrmopt, ncmdtrmopt, "What to save",
  12701. #ifdef OS2
  12702.                            "scrollback",
  12703. #else
  12704.                            "history",
  12705. #endif /* OS2 */
  12706.                            xxstring)) < 0)
  12707.               return(y);
  12708.             break;
  12709. #ifdef OS2
  12710. #ifndef NOLOCAL
  12711.           case XSTERM:                  /* SAVE TERMINAL.. */
  12712.             if ((y = cmkey(trmtrmopt,1,
  12713.                            "What to save","scrollback",xxstring)) < 0)
  12714.               return(y);
  12715.             break;
  12716. #endif /* NOLOCAL */
  12717. #endif /* OS2 */
  12718.         }
  12719.         z = cmofi("Filename",
  12720.                   ((y == SV_SCRL) ? "scrollbk.txt" : "history.txt"),
  12721.                   &s,
  12722.                   xxstring
  12723.                   );
  12724. #ifndef NOSETKEY
  12725.     }
  12726. #endif /* NOSETKEY */
  12727.     if (z < 0)                          /* Check output-file parse results */
  12728.       return(z);
  12729.     if (z == 2) {
  12730.         printf("?Sorry, %s is a directory name\n",s);
  12731.         return(-9);
  12732.     }
  12733. #ifdef ZFNQFP
  12734.     if ((fnp = zfnqfp(s,TMPBUFSIZ - 1,tmpbuf))) {/* Convert to full pathname */
  12735.         if (fnp->fpath)
  12736.           if ((int) strlen(fnp->fpath) > 0)
  12737.             s = fnp->fpath;
  12738.     }
  12739. #endif /* ZFNQFP */
  12740.  
  12741.     ckstrncpy(line,s,LINBUFSIZ);        /* Make safe copy of pathname */
  12742.     s = line;
  12743. #ifdef MAC
  12744.     z = 0;
  12745. #else
  12746.     /* Get NEW/APPEND disposition */
  12747.     if ((z = cmkey(disptb,2,"Disposition","new",xxstring)) < 0)
  12748.       return(z);
  12749. #endif /* MAC */
  12750.     disp = z;
  12751.     if ((x = cmcfm()) < 0)              /* Get confirmation */
  12752.       return(x);
  12753.  
  12754.     switch (xx) {                       /* Do action.. */
  12755. #ifndef NOSETKEY
  12756.       case XSKEY:                       /* SAVE KEYMAP */
  12757.         return (savkeys(s,disp));
  12758. #endif /* NOSETKEY */
  12759.  
  12760.       case XSCMD:                       /* SAVE COMMAND.. */
  12761. #ifdef OS2
  12762. #ifndef NOLOCAL
  12763.         if (y == SV_SCRL)               /* .. SCROLLBACK */
  12764.           return(success = savscrbk(VCMD,s,disp));
  12765. #endif /* NOLOCAL */
  12766. #endif /* OS2 */
  12767. #ifndef NORECALL
  12768.         if (y == SV_HIST)               /* .. HISTORY */
  12769.           return(success = savhistory(s,disp));
  12770.         break;
  12771. #endif /* NORECALL */
  12772.  
  12773. #ifdef OS2
  12774. #ifndef NOLOCAL
  12775.       case XSTERM:                      /* SAVE TERMINAL SCROLLBACK */
  12776.         return(success = savscrbk(VTERM,s,disp));
  12777. #endif /* NOLOCAL */
  12778. #endif /* OS2 */
  12779.     }
  12780.     success = 0;
  12781.     return(-2);
  12782. }
  12783.  
  12784. /*
  12785.   R E A D T E X T
  12786.  
  12787.   Read text with a custom prompt into given buffer using command parser but
  12788.   with no echoing or entry into recall buffer.
  12789. */
  12790. int
  12791. readtext(prmpt, buffer, bufsiz) char * prmpt; char * buffer; int bufsiz; {
  12792. #ifdef CK_RECALL
  12793.     extern int on_recall;               /* Around Password prompting */
  12794. #endif /* CK_RECALL */
  12795.     int rc;
  12796. #ifndef NOLOCAL
  12797. #ifdef OS2
  12798.     extern int vmode;
  12799.     extern int startflags;
  12800.     int vmode_sav = vmode;
  12801.  
  12802.     if (win95_popup && !(startflags & 96)
  12803. #ifdef IKSD
  12804.          && !inserver
  12805. #endif /* IKSD */
  12806.          )
  12807.       return(popup_readtext(vmode,prmpt,buffer,bufsiz,0));
  12808.  
  12809.     if (vmode == VTERM) {
  12810.         vmode = VCMD;
  12811.         VscrnIsDirty(VTERM);
  12812.         VscrnIsDirty(VCMD);
  12813.     }
  12814. #endif /* OS2 */
  12815. #endif /* NOLOCAL */
  12816.  
  12817. #ifdef CK_RECALL
  12818.     on_recall = 0;
  12819. #endif /* CK_RECALL */
  12820.     cmsavp(psave,PROMPTL);              /* Save old prompt */
  12821.     cmsetp(prmpt);                      /* Make new prompt */
  12822.     concb((char)escape);                /* Put console in cbreak mode */
  12823.     cmini(1);                           /* and echo mode */
  12824.     if (pflag) prompt(xxstring);        /* Issue prompt if at top level */
  12825.     cmres();                            /* Reset the parser */
  12826.     for (rc = -1; rc < 0; ) {           /* Prompt till they answer */
  12827.         rc = cmtxt("","",&s,NULL);      /* Get a literal line of text */
  12828.         cmres();                        /* Reset the parser again */
  12829.     }
  12830.     ckstrncpy(buffer,s,bufsiz);
  12831.     cmsetp(psave);                      /* Restore original prompt */
  12832.  
  12833. #ifndef NOLOCAL
  12834. #ifdef OS2
  12835.     if (vmode != vmode_sav) {
  12836.         vmode = VTERM;
  12837.         VscrnIsDirty(VCMD);
  12838.         VscrnIsDirty(VTERM);
  12839.     }
  12840. #endif /* OS2 */
  12841. #endif /* NOLOCAL */
  12842.     return(0);
  12843. }
  12844. #endif /* NOICP */
  12845.  
  12846. /* A general function to allow a Password or other information  */
  12847. /* to be read from the command prompt without it going into     */
  12848. /* the recall buffer or being echo'd.                           */
  12849.  
  12850. int
  12851. readpass(prmpt, buffer, bufsiz) char * prmpt; char * buffer; int bufsiz; {
  12852.     int x;
  12853. #ifdef NOICP
  12854.     printf("%s", prmpt);
  12855. #ifdef COMMENT
  12856.     /* Some linkers won't allow this because it's unsafe */
  12857.     gets(buffer);
  12858. #else
  12859.     {
  12860.         int c, i; char * p;
  12861.         p = buffer;
  12862.         for (i = 0; i < bufsiz-1; i++) {
  12863.             if ((c = getchar()) == EOF)
  12864.               break;
  12865.             if (c < SP)
  12866.               break;
  12867.             buffer[i] = c;
  12868.         }
  12869.         buffer[i] = NUL;
  12870.     }
  12871. #endif /* COMMENT */
  12872.     return(1);
  12873. #else  /* NOICP */
  12874. #ifdef CK_RECALL
  12875.     extern int on_recall;               /* around Password prompting */
  12876. #endif /* CK_RECALL */
  12877.     int rc;
  12878. #ifndef NOLOCAL
  12879. #ifdef OS2
  12880.     extern int vmode;
  12881.     extern int startflags;
  12882.     int vmode_sav = vmode;
  12883. #endif /* OS2 */
  12884. #endif /* NOLOCAL */
  12885. #ifdef CKSYSLOG
  12886.     int savlog;
  12887. #endif /* CKSYSLOG */
  12888. #ifndef NOLOCAL
  12889.     debok = 0;                          /* Don't log */
  12890. #ifdef OS2
  12891.     if (win95_popup && !(startflags & 96)
  12892. #ifdef IKSD
  12893.          && !inserver
  12894. #endif /* IKSD */
  12895.          ) {
  12896.         x = popup_readpass(vmode,prmpt,buffer,bufsiz,0);
  12897.         debok = 1;
  12898.         return(x);
  12899.     }
  12900. #endif /* OS2 */
  12901. #endif /* NOLOCAL */
  12902.  
  12903. #ifdef CKSYSLOG
  12904.     savlog = ckxsyslog;                 /* Save and turn off syslogging */
  12905.     ckxsyslog = 0;
  12906. #endif /* CKSYSLOG */
  12907. #ifndef NOLOCAL
  12908. #ifdef OS2
  12909.     if (vmode == VTERM) {
  12910.         vmode = VCMD;
  12911.         VscrnIsDirty(VTERM);
  12912.         VscrnIsDirty(VCMD);
  12913.     }
  12914. #endif /* OS2 */
  12915. #endif /* NOLOCAL */
  12916. #ifdef CK_RECALL
  12917.     on_recall = 0;
  12918. #endif /* CK_RECALL */
  12919.     cmsavp(psave,PROMPTL);              /* Save old prompt */
  12920.     cmsetp(prmpt);                      /* Make new prompt */
  12921.     concb((char)escape);                /* Put console in cbreak mode */
  12922.     cmini(0);                           /* and no-echo mode */
  12923.     if (pflag) prompt(xxstring);        /* Issue prompt if at top level */
  12924.     cmres();                            /* Reset the parser */
  12925.     for (rc = -1; rc < 0; ) {           /* Prompt till they answer */
  12926.         rc = cmtxt("","",&s,NULL);      /* Get a literal line of text */
  12927.         cmres();                        /* Reset the parser again */
  12928.     }
  12929.     ckstrncpy(buffer,s,bufsiz);
  12930.     printf("\r\n");                     /* Echo a CRLF */
  12931.     cmsetp(psave);                      /* Restore original prompt */
  12932.     cmini(1);                           /* Restore echo mode */
  12933. #ifndef NOLOCAL
  12934. #ifdef OS2
  12935.     if (vmode != vmode_sav) {
  12936.         vmode = VTERM;
  12937.         VscrnIsDirty(VCMD);
  12938.         VscrnIsDirty(VTERM);
  12939.     }
  12940. #endif /* OS2 */
  12941. #endif /* NOLOCAL */
  12942. #ifdef CKSYSLOG
  12943.     ckxsyslog = savlog;                 /* Restore syslogging */
  12944. #endif /* CKSYSLOG */
  12945.     debok = 1;
  12946.     return(0);
  12947. #endif /* NOICP */
  12948. }
  12949.  
  12950. #ifndef NOICP
  12951. struct keytab authtab[] = {             /* Available authentication types */
  12952. #ifdef CK_KERBEROS
  12953.     { "k4",        AUTH_KRB4, CM_INV },
  12954.     { "k5",        AUTH_KRB5, CM_INV },
  12955.     { "kerberos4", AUTH_KRB4, 0      },
  12956.     { "kerberos5", AUTH_KRB5, 0      },
  12957.     { "krb4",      AUTH_KRB4, CM_INV },
  12958.     { "krb5",      AUTH_KRB5, CM_INV },
  12959. #endif /* CK_KERBEROS */
  12960. #ifdef NT
  12961.     { "ntlm",      AUTH_NTLM, 0 },
  12962. #endif /* NT */
  12963. #ifdef CK_SRP
  12964.     { "srp",       AUTH_SRP,  0 },
  12965. #endif /* CK_SRP */
  12966. #ifdef CK_SSL
  12967.     { "ssl",       AUTH_SSL,  0 },
  12968. #endif /* CK_SSL */
  12969.     { "",          0,         0 }
  12970. };
  12971. int authtabn = sizeof(authtab)/sizeof(struct keytab)-1;
  12972.  
  12973. #ifdef CK_KERBEROS
  12974. struct keytab kerbtab[] = {             /* Kerberos authentication types */
  12975.     { "k4",        AUTH_KRB4, CM_INV },
  12976.     { "k5",        AUTH_KRB5, CM_INV },
  12977.     { "kerberos4", AUTH_KRB4, 0      },
  12978.     { "kerberos5", AUTH_KRB5, 0      },
  12979.     { "krb4",      AUTH_KRB4, CM_INV },
  12980.     { "krb5",      AUTH_KRB5, CM_INV }
  12981. };
  12982. int kerbtabn = sizeof(kerbtab)/sizeof(struct keytab);
  12983.  
  12984. static struct keytab krb_s_tbl[] = {    /* AUTHENTICATE command switches: */
  12985.     { "/cache",   KRB_S_CA, CM_ARG }
  12986. };
  12987. static int krb_s_n = sizeof(krb_s_tbl)/sizeof(struct keytab);
  12988.  
  12989. static struct keytab krb_v_tbl[] = {    /* KERBEROS version values: */
  12990.     { "4",    4, 0 },
  12991.     { "5",    5, 0 },                   /* (add others as needed...) */
  12992.     { "auto", 0, 0 }                    /* Note: 0 = auto */
  12993. };
  12994. static int krb_v_n = sizeof(krb_v_tbl)/sizeof(struct keytab);
  12995.  
  12996. static struct keytab krb_a_tbl[] = {    /* KERBEROS actions: */
  12997.     { "destroy",           KRB_A_DE, 0 },
  12998.     { "initialize",        KRB_A_IN, 0 },
  12999.     { "list-credentials",  KRB_A_LC, 0 }
  13000. };
  13001. static int krb_a_n = sizeof(krb_a_tbl)/sizeof(struct keytab);
  13002.  
  13003. static struct keytab krb4_i_tbl[] = {   /* KERBEROS 4 INITIALIZE switches: */
  13004.     { "/brief",            KRB_I_BR, 0 },      /* /BRIEF       */
  13005.     { "/instance",         KRB_I_IN, CM_ARG }, /* /INSTANCE:   */
  13006.     { "/lifetime",         KRB_I_LF, CM_ARG }, /* /LIFETIME:   */
  13007.     { "/not-preauth",      KRB_I_NPA, 0 },     /* /NOT-PREAUTH */
  13008.     { "/password",         KRB_I_PW, CM_ARG }, /* /PASSWORD:   */
  13009. #ifdef OS2
  13010.     { "/popup",            KRB_I_POP, 0 },     /* /POPUP       */
  13011. #endif /* OS2 */
  13012.     { "/preauth",          KRB_I_PA, 0 },      /* /PREAUTH     */
  13013.     { "/realm",            KRB_I_RL, CM_ARG }, /* /REALM:      */
  13014.     { "/verbose",          KRB_I_VB, 0 },      /* /VERBOSE     */
  13015.     { "", 0, 0 }
  13016. };
  13017. static int krb4_i_n = sizeof(krb4_i_tbl)/sizeof(struct keytab) - 1;
  13018.  
  13019. static struct keytab krb5_i_tbl[] = {   /* KERBEROS 5 INITIALIZE switches: */
  13020.     { "/addresses",        KRB_I_ADR, CM_ARG },
  13021.     { "/forwardable",      KRB_I_FW,  0 },         /* /FORWARDABLE */
  13022.     { "/instance",         KRB_I_IN, CM_ARG }, /* /INSTANCE:   */
  13023.     { "/k4",               KRB_I_K4,  CM_INV }, /* /KERBEROS4   */
  13024.     { "/kerberos4",        KRB_I_K4,  0 },      /* /KERBEROS4   */
  13025.     { "/krb4",             KRB_I_K4,  CM_INV }, /* /KERBEROS4   */
  13026.     { "/lifetime",         KRB_I_LF,  CM_ARG }, /* /LIFETIME:   */
  13027.     { "/no-addresses",     KRB_I_NAD, 0 },      /* /NO-ADDRESSES */
  13028.     { "/no-k4",            KRB_I_NK4, CM_INV },/* /NO-KERBEROS4 */
  13029.     { "/no-kerberos4",     KRB_I_NK4, 0 },     /* /NO-KERBEROS4 */
  13030.     { "/no-krb4",          KRB_I_NK4, CM_INV },/* /NO-KERBEROS4 */
  13031.     { "/not-forwardable",  KRB_I_NFW, 0 },         /* /NOT-FORWARDABLE */
  13032.     { "/not-proxiable",    KRB_I_NPR, 0 },     /* /NOT-PROXIABLE   */
  13033.     { "/password",         KRB_I_PW,  CM_ARG }, /* /PASSWORD:   */
  13034. #ifdef OS2
  13035.     { "/popup",            KRB_I_POP, 0 },     /* /POPUP       */
  13036. #endif /* OS2 */
  13037.     { "/postdate",         KRB_I_PD, CM_ARG }, /* /POSTDATE:   */
  13038.     { "/pr",               KRB_I_PR, CM_INV|CM_ABR }, /* to allow for */
  13039.     { "/pro",              KRB_I_PR, CM_INV|CM_ABR }, /* different spellings */
  13040.     { "/prox",             KRB_I_PR, CM_INV|CM_ABR },
  13041.     { "/proxiable",        KRB_I_PR, 0 },      /* /PROXIABLE   */
  13042.     { "/proxyable",        KRB_I_PR, CM_INV }, /* /PROXYABLE   */
  13043.     { "/realm",            KRB_I_RL, CM_ARG }, /* /REALM:      */
  13044.     { "/renew",            KRB_I_RN, 0 },          /* /RENEW       */
  13045.     { "/renewable",        KRB_I_RB, CM_ARG }, /* /RENEWABLE:  */
  13046.     { "/service",          KRB_I_SR, CM_ARG }, /* /SERVICE:    */
  13047.     { "/validate",         KRB_I_VA, 0 },          /* /VALIDATE    */
  13048.     { "", 0, 0 }
  13049. };
  13050. static int krb5_i_n = sizeof(krb5_i_tbl)/sizeof(struct keytab) - 1;
  13051.  
  13052. static struct keytab klctab[] = {       /* List Credentials switches*/
  13053.     { "/addresses",  XYKLCAD, 0 },
  13054.     { "/encryption", XYKLCEN, 0 },
  13055.     { "/flags",      XYKLCFL, 0 }
  13056. };
  13057. static int nklctab = sizeof(klctab)/sizeof(struct keytab);
  13058.  
  13059. extern int krb_action;
  13060. extern struct krb_op_data krb_op;
  13061.  
  13062. extern struct krb5_list_cred_data krb5_lc;
  13063. extern struct krb5_init_data krb5_init;
  13064. extern char * krb5_d_principal;         /* Default principal */
  13065. extern char * krb5_d_instance;
  13066. extern char * krb5_d_realm;             /* Default realm */
  13067. extern char * krb5_d_cc;                /* Default credentials cache */
  13068. extern char * krb5_d_srv;               /* Default service name */
  13069. extern int    krb5_d_lifetime;          /* Default lifetime */
  13070. extern int    krb5_d_forwardable;
  13071. extern int    krb5_d_proxiable;
  13072. extern int    krb5_d_renewable;
  13073. extern int    krb5_autoget;
  13074. extern int    krb5_autodel;
  13075. extern int    krb5_d_getk4;
  13076. extern int    krb5_d_no_addresses;
  13077. extern int    krb5_checkaddrs;
  13078. extern char * krb5_d_addrs[];
  13079. extern char * k5_keytab;                /* Keytab file */
  13080.  
  13081. extern struct krb4_init_data krb4_init;
  13082. extern char * krb4_d_principal;         /* Default principal */
  13083. extern char * krb4_d_realm;             /* Default realm */
  13084. extern char * krb4_d_srv;               /* Default service name */
  13085. extern int    krb4_d_lifetime;          /* Default lifetime */
  13086. extern int    krb4_d_preauth;
  13087. extern char * krb4_d_instance;
  13088. extern int    krb4_autoget;
  13089. extern int    krb4_autodel;
  13090. extern int    krb4_checkaddrs;
  13091. extern char * k4_keytab;                /* Keytab file */
  13092. #endif /* CK_KERBEROS */
  13093.  
  13094. #ifndef NOSHOW
  13095. int
  13096. sho_iks() {
  13097. #ifdef IKSDCONF
  13098. #ifdef CK_LOGIN
  13099.     extern int ckxsyslog, ckxwtmp, ckxanon;
  13100. #ifdef UNIX
  13101.     extern int ckxpriv;
  13102. #endif /* UNIX */
  13103. #ifdef CK_PERMS
  13104.     extern int ckxperms;
  13105. #endif /* CK_PERMS */
  13106.     extern char * anonfile, * userfile, * anonroot;
  13107. #ifdef OS2
  13108.     extern char * anonacct;
  13109. #endif /* OS2 */
  13110. #ifdef NT
  13111.     extern char * iks_domain;
  13112. #endif /* NT */
  13113. #endif /* CK_LOGIN */
  13114. #ifdef CKWTMP
  13115.     extern char * wtmpfile;
  13116. #endif /* CKWTMP */
  13117. #ifdef IKSDB
  13118.     extern char * dbfile;
  13119.     extern int dbenabled;
  13120. #endif /* IKSDB */
  13121. #ifdef CK_LOGIN
  13122.     extern int logintimo;
  13123. #endif /* CK_LOGIN */
  13124.     extern int srvcdmsg, success, iksdcf, noinit, arg_x;
  13125.     extern char * cdmsgfile[], * cdmsgstr, *kermrc;
  13126.     char * bannerfile = NULL;
  13127.     char * helpfile = NULL;
  13128.     extern int xferlog;
  13129.     extern char * xferfile;
  13130.     int i;
  13131.  
  13132.     if (isguest) {
  13133.         printf("?Command disabled\r\n");
  13134.         return(success = 0);
  13135.     }
  13136.  
  13137.     printf("IKS Settings\r\n");
  13138. #ifdef CK_LOGIN
  13139. #ifdef OS2
  13140.     printf("  Anonymous Account:   %s\r\n",anonacct?anonacct:"<none>");
  13141. #endif /* OS2 */
  13142.     printf("  Anonymous Initfile:  %s\r\n",anonfile?anonfile:"<none>");
  13143.     printf("  Anonymous Login:     %d\r\n",ckxanon);
  13144.     printf("  Anonymous Root:      %s\r\n",anonroot?anonroot:"<none>");
  13145. #endif /* CK_LOGIN */
  13146.     printf("  Bannerfile:          %s\r\n",bannerfile?bannerfile:"<none>");
  13147.     printf("  CDfile:              %s\r\n",cdmsgfile[0]?cdmsgfile[0]:"<none>");
  13148.     for ( i=1;i<16 && cdmsgfile[i];i++ )
  13149.         printf("  CDfile:              %s\r\n",cdmsgfile[i]);
  13150.     printf("  CDMessage:           %d\r\n",srvcdmsg);
  13151. #ifdef IKSDB
  13152.     printf("  DBfile:              %s\r\n",dbfile?dbfile:"<none>");
  13153.     printf("  DBenabled:           %d\r\n",dbenabled);
  13154. #endif /* IKSDB */
  13155. #ifdef CK_LOGIN
  13156. #ifdef NT
  13157.     printf("  Default-domain:      %s\r\n",iks_domain?iks_domain:".");
  13158. #endif /* NT */
  13159. #endif /* CK_LOGIN */
  13160.     printf("  Helpfile:            %s\r\n",helpfile?helpfile:"<none>");
  13161.     printf("  Initfile:            %s\r\n",kermrc?kermrc:"<none>");
  13162.     printf("  No-Initfile:         %d\r\n",noinit);
  13163. #ifdef CK_LOGIN
  13164. #ifdef CK_PERM
  13165.     printf("  Permission code:     %0d\r\n",ckxperms);
  13166. #endif /* CK_PERM */
  13167. #ifdef UNIX
  13168.     printf("  Privileged Login:    %d\r\n",ckxpriv);
  13169. #endif /* UNIX */
  13170. #endif /* CK_LOGIN */
  13171.     printf("  Server-only:         %d\r\n",arg_x);
  13172.     printf("  Syslog:              %d\r\n",ckxsyslog);
  13173.     printf("  Timeout (seconds):   %d\r\n",logintimo);
  13174.     printf("  Userfile:            %s\r\n",userfile?userfile:"<none>");
  13175. #ifdef CK_LOGIN
  13176. #ifdef CKWTMP
  13177.     printf("  Wtmplog:             %d\r\n",ckxwtmp);
  13178.     printf("  Wtmpfile:            %s\r\n",wtmpfile?wtmpfile:"<none>");
  13179. #endif /* CKWTMP */
  13180. #endif /* CK_LOGIN */
  13181.     printf("  Xferfile:            %s\r\n",xferfile?xferfile:"<none>");
  13182.     printf("  Xferlog:             %d\r\n",xferlog);
  13183. #else /* IKSDCONF */
  13184.     printf("?Nothing to show.\r\n");
  13185. #endif /* IKSDCONF */
  13186.     return(success = 1);
  13187. }
  13188.  
  13189. #ifdef CK_AUTHENTICATION
  13190. int
  13191. sho_auth(cx) int cx; {
  13192.     extern int auth_type_user[], cmd_rows;
  13193.     int i;
  13194.     char * p;
  13195.     int kv = 0, all = 0, n = 0;
  13196.  
  13197. #ifdef IKSD
  13198.     if (inserver && isguest) {
  13199.         printf("?Sorry, command disabled.\r\n");
  13200.         return(success = 0);
  13201.     }
  13202. #endif /* IKSD */
  13203.     if (cx) {
  13204.         kv = cx;
  13205.     } else if (auth_type_user[0] != AUTHTYPE_AUTO) {
  13206.         kv = auth_type_user[0];
  13207.     } else {
  13208.         all = 1;
  13209.         kv = AUTHTYPE_KERBEROS_V4;
  13210.     }
  13211.     while (kv) {
  13212.         switch (kv) {
  13213.           case AUTHTYPE_KERBEROS_V4:
  13214.             kv = all ? AUTHTYPE_KERBEROS_V5 : 0;
  13215.             if (ck_krb4_is_installed()) {
  13216.                 printf(" Authentication:      Kerberos 4\n");
  13217.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13218.             } else {
  13219.                 printf(" Authentication:      Kerberos 4 (not installed)\n");
  13220.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13221.                 continue;
  13222.             }
  13223. #ifdef CK_KERBEROS
  13224.             printf(" Keytab file:         %s\n",
  13225.                       k4_keytab ? k4_keytab : "(none)");
  13226.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13227.             if (krb_action < 0) {
  13228.                 p = "(none)";
  13229.             } else {
  13230.                 for (p = "", i = 0; i < krb_a_n; i++) {
  13231.                     if (krb_action == krb_a_tbl[i].kwval) {
  13232.                         p = krb_a_tbl[i].kwd;
  13233.                         break;
  13234.                     }
  13235.                 }
  13236.             }
  13237.             printf(" Action:              %s\n", p);
  13238.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13239.             printf(" Default lifetime     %d\n",krb4_d_lifetime);
  13240.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13241.             printf(" Lifetime:            %d (minutes)\n",krb4_init.lifetime);
  13242.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13243.             printf(" Default preauth:     %d\n",krb4_d_preauth);
  13244.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13245.             printf(" Preauth:             %d\n",krb4_init.preauth);
  13246.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13247.             printf(" Default principal:   \"%s\"\n",
  13248.                     krb4_d_principal ? krb4_d_principal : "");
  13249.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13250.             printf(" Principal:           \"%s\"\n",
  13251.                     krb4_init.principal ? krb4_init.principal : "");
  13252.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13253.             printf(" Default realm:       \"%s\"\n",
  13254.                     krb4_d_realm ? krb4_d_realm : "");
  13255.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13256.             printf(" Realm:               \"%s\"\n",
  13257.                     krb4_init.realm ? krb4_init.realm : "");
  13258.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13259.             printf(" Default instance:    \"%s\"\n",
  13260.                     krb4_d_instance ? krb4_d_instance : "");
  13261.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13262.             printf(" Instance:            \"%s\"\n",
  13263.                     krb4_init.instance ? krb4_init.instance : "");
  13264.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13265.             printf(" Auto-Get TGTs:       %d\n",krb4_autoget);
  13266.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13267.             printf(" Auto-Destroy TGTs:   %s\n",
  13268.                     krb4_autodel==KRB_DEL_NO?"never":
  13269.                     krb4_autodel==KRB_DEL_CL?"on-close":"on-exit");
  13270.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13271.             printf(" Check IP Addresses:  %d\n",krb4_checkaddrs);
  13272.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13273. #ifdef COMMENT
  13274.             printf(" Password:    \"%s\"\n",
  13275.                     krb4_init.password  ? krb4_init.password  : "");
  13276.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13277. #endif /* COMMENT */
  13278. #endif /* CK_KERBEROS */
  13279.             printf("\n");
  13280.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13281.             break;
  13282.         case AUTHTYPE_KERBEROS_V5:
  13283.             kv = all ? AUTHTYPE_SSL : 0;
  13284.             if (ck_krb5_is_installed()) {
  13285.                 if (ck_gssapi_is_installed())
  13286.                     printf(" Authentication:      Kerberos 5 plus GSSAPI\n");
  13287.                 else
  13288.                     printf(" Authentication:      Kerberos 5\n");
  13289.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13290.             } else {
  13291.                 printf(" Authentication:      Kerberos 5 (not installed)\n");
  13292.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13293.                 continue;
  13294.             }
  13295.  
  13296. #ifdef CK_KERBEROS
  13297.             printf(" Cache file:          %s\n",
  13298.                     krb_op.cache ? krb_op.cache : "(none)");
  13299.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13300.             printf(" Default cache:       %s\n",
  13301.                     krb5_d_cc ? krb5_d_cc : "(none)");
  13302.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13303.             printf(" Keytab file:         %s\n",
  13304.                       k5_keytab ? k5_keytab : "(none)");
  13305.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13306.             if (krb_action < 0) {
  13307.                 p = "(none)";
  13308.             } else  {
  13309.                 for (p = "", i = 0; i < krb_a_n; i++) {
  13310.                     if (krb_action == krb_a_tbl[i].kwval) {
  13311.                         p = krb_a_tbl[i].kwd;
  13312.                         break;
  13313.                     }
  13314.                 }
  13315.             }
  13316.             printf(" Action:              %s\n", p);
  13317.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13318.  
  13319.             printf(" Default forwardable  %d\n",krb5_d_forwardable);
  13320.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13321.             printf(" Forwardable:         %d\n",krb5_init.forwardable);
  13322.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13323.             printf(" Default lifetime     %d\n",krb5_d_lifetime);
  13324.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13325.             printf(" Lifetime:            %d (minutes)\n",krb5_init.lifetime);
  13326.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13327.             printf(" Postdate:            \"%s\"\n",
  13328.                     krb5_init.postdate ? krb5_init.postdate: "");
  13329.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13330.             printf(" Default proxiable:   %d\n",krb5_d_proxiable);
  13331.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13332.             printf(" Proxiable:           %d\n",krb5_init.proxiable);
  13333.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13334.             printf(" Renew:               %d\n",krb5_init.renew);
  13335.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13336.             printf(" Default renewable:   %d (minutes)\n",krb5_d_renewable);
  13337.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13338.             printf(" Renewable:           %d (minutes)\n",krb5_init.renewable);
  13339.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13340.             printf(" Service:             \"%s\"\n",
  13341.                     krb5_init.service ? krb5_init.service : "");
  13342.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13343.             printf(" Validate:            %d\n",krb5_init.validate);
  13344.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13345.             printf(" Default principal:   \"%s\"\n",
  13346.                     krb5_d_principal ? krb5_d_principal : "");
  13347.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13348.             printf(" Principal:           \"%s\"\n",
  13349.                     krb5_init.principal ? krb5_init.principal : "");
  13350.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13351.             printf(" Default instance:    \"%s\"\n",
  13352.                     krb5_d_instance ? krb5_d_instance : "");
  13353.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13354.             printf(" Default realm:       \"%s\"\n",
  13355.                     krb5_d_realm ? krb5_d_realm : "");
  13356.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13357.             printf(" Realm:               \"%s\"\n",
  13358.                     krb5_init.realm ? krb5_init.realm : "");
  13359.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13360.             printf(" Auto-Get TGTs:       %d\n",krb5_autoget);
  13361.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13362.             printf(" Auto-Destroy TGTs:   %s\n",
  13363.                     krb5_autodel==KRB_DEL_NO?"never":
  13364.                     krb5_autodel==KRB_DEL_CL?"on-close":"on-exit");
  13365.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13366.             printf(" Default get K4 TGTs: %d\n",krb5_d_getk4);
  13367.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13368.             printf(" Get K4 TGTs: %d\n",krb5_init.getk4);
  13369.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13370.             printf(" Check IP Addresses:  %d\n",krb5_checkaddrs);
  13371.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13372.             printf(" No IP Addresses:  %d\n",krb5_d_no_addresses);
  13373.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13374.             printf(" IP-Addresses:        ");
  13375.             if (krb5_init.addrs && krb5_init.addrs[0]) {
  13376.                 for (i = 0; krb5_init.addrs[i]; i++) {
  13377.                     if (i)
  13378.                       printf(",");
  13379.                     printf("%s",krb5_init.addrs[i]);
  13380.                 }
  13381.             } else if (krb5_d_addrs[0]) {
  13382.                 for (i = 0;i < KRB5_NUM_OF_ADDRS && krb5_d_addrs[i];i++) {
  13383.                     if (i)
  13384.                       printf(",");
  13385.                     printf("%s",krb5_d_addrs[i]);
  13386.                 }
  13387.             } else {
  13388.                 printf("(use default)");
  13389.             }
  13390.             printf("\n");
  13391.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13392. #ifdef COMMENT
  13393.             printf(" Password:            \"%s\"\n",
  13394.                     krb5_init.password  ? krb5_init.password  : "");
  13395.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13396. #endif /* COMMENT */
  13397. #endif /* CK_KERBEROS */
  13398.             printf("\n");
  13399.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13400.             break;
  13401.           case AUTHTYPE_SSL:
  13402.             kv = all ? AUTHTYPE_SRP : 0;
  13403.             if (ck_ssleay_is_installed()) {
  13404.                 printf(" Authentication:      SSL/TLS\n");
  13405.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13406.             } else {
  13407.                 printf(" Authentication:      SSL/TLS (not installed)\n");
  13408.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13409.                 continue;
  13410.             }
  13411.  
  13412. #ifdef CK_SSL
  13413.             printf(" RSA Certs file: %s\n",ssl_rsa_cert_file?
  13414.                   ssl_rsa_cert_file:"(none)");
  13415.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13416.             printf(" RSA Certs Chain file: %s\n",ssl_rsa_cert_chain_file?
  13417.                   ssl_rsa_cert_chain_file:"(none)");
  13418.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13419.             printf(" RSA Key file: %s\n",ssl_rsa_key_file?
  13420.                   ssl_rsa_key_file:"(none)");
  13421.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13422.             printf(" DSA Certs file: %s\n",ssl_dsa_cert_file?
  13423.                   ssl_dsa_cert_file:"(none)");
  13424.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13425.             printf(" DSA Certs Chain file: %s\n",ssl_dsa_cert_chain_file?
  13426.                   ssl_dsa_cert_chain_file:"(none)");
  13427.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13428.             printf(" DH Key file: %s\n",ssl_dh_key_file?
  13429.                   ssl_dh_key_file:"(none)");
  13430.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13431.             printf(" DH Param file: %s\n",ssl_dh_param_file?
  13432.                   ssl_dh_param_file:"(none)");
  13433.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13434.             printf(" CRL file: %s\n",ssl_crl_file?
  13435.                   ssl_crl_file:"(none)");
  13436.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13437.             printf(" CRL dir: %s\n",ssl_crl_dir?
  13438.                     ssl_crl_dir:"(none)");
  13439.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13440.             printf(" Random file: %s\n",ssl_rnd_file?
  13441.                   ssl_rnd_file:"(none)");
  13442.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13443.             printf(" Verify file: %s\n",ssl_verify_file?
  13444.                   ssl_verify_file:"(none)");
  13445.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13446.             printf(" Verify dir: %s\n",ssl_verify_dir?
  13447.                   ssl_verify_dir:"(none)");
  13448.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13449.             printf(" Cipher list:\n");
  13450.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13451.             if (ssl_con == NULL) {
  13452.                 SSL_library_init();
  13453.                 ssl_ctx = (SSL_CTX *)
  13454.                   SSL_CTX_new((SSL_METHOD *)TLSv1_method());
  13455.                 if (ssl_ctx != NULL)
  13456.                   ssl_con= (SSL *) SSL_new(ssl_ctx);
  13457.             }
  13458.             if (ssl_con != NULL) {
  13459.                 CHAR * p = NULL;
  13460.                 int i;
  13461.  
  13462.                 for (i = 0; ; i++) {
  13463.                     p = (CHAR *) SSL_get_cipher_list(ssl_con,i);
  13464.                     if (p == NULL)
  13465.                       break;
  13466.                     printf("    %s\n",p);
  13467.                     if (++n > cmd_rows - 3)
  13468.                         if (!askmore()) return(0); else n = 0;
  13469.                 }
  13470.             }
  13471.             printf(" Certs OK? %s\n",ssl_certsok_flag? "yes" : "no");
  13472.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13473.             printf(" Debug mode: %s\n", ssl_debug_flag ? "on" : "off");
  13474.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13475.             printf(" Verbose mode: %s\n", ssl_verbose_flag ? "on" : "off");
  13476.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13477.             printf(" Verify mode: %s\n",
  13478.                     ssl_verify_flag == SSL_VERIFY_NONE ? "none" :
  13479.                     ssl_verify_flag == SSL_VERIFY_PEER ? "peer-cert" :
  13480.                     "fail-if-no-peer-cert");
  13481.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13482.             printf(" SSL only? %s\n", ssl_only_flag ? "yes" : "no");
  13483.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13484.             printf(" TLS only? %s\n", tls_only_flag ? "yes" : "no");
  13485.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13486. #endif /* CK_SSL */
  13487.             break;
  13488.           case AUTHTYPE_NTLM:
  13489.             kv = 0;
  13490.             if (ck_ntlm_is_installed()) {
  13491.                 printf(" Authentication:      NTLM\n");
  13492.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13493.                 printf(" No options\n");
  13494.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13495.             } else {
  13496.                 printf(" Authentication:      NTLM (not installed)\n");
  13497.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13498.                 continue;
  13499.             }
  13500.             printf("\n");
  13501.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13502.             break;
  13503.           case AUTHTYPE_SRP:
  13504.             kv = all ? AUTHTYPE_NTLM : 0;
  13505.             if (ck_srp_is_installed()) {
  13506.                 if (ck_krypto_is_installed())
  13507.                     printf(" Authentication:      SRP plus Krypto API\n");
  13508.                 else
  13509.                     printf(" Authentication:      SRP\n");
  13510.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13511.                 printf(" No options\n");
  13512.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13513.             } else {
  13514.                 printf(" Authentication:      SRP (not installed)\n");
  13515.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13516.                 continue;
  13517.             }
  13518.             printf("\n");
  13519.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13520.             break;
  13521.         }
  13522.     }
  13523.     return(success = 1);
  13524. }
  13525. #endif /* CK_AUTHENTICATION */
  13526. #endif /* NOSHOW */
  13527.  
  13528. #ifdef CK_KERBEROS
  13529.  
  13530. /*  C P _ A U T H  --  AUTHENTICATE command parsing  */
  13531.  
  13532. int
  13533. cp_auth() {                             /* Command_Parse AUTHENTICATE */
  13534.     int c, i, n;                        /* Workers */
  13535.     int rc = 0;                         /* Return code */
  13536.     int getval;                         /* Parsing helpers */
  13537.     int tmpauth = 0;                    /* Temporary authentication type */
  13538.     int kv = 0;                         /* Temporary Kerberos version */
  13539.     int tmp_action = -1;                /* Temporary Kerberos action */
  13540.     int tmp_klc = 0;                    /* Temporary list-credentials */
  13541.     char tmphlp[256];                   /* For building help message */
  13542.     char * p;
  13543.     char * tmppswd  = NULL;             /* Password */
  13544.     char * tmpprinz = NULL;             /* Principal */
  13545.     char * tmprealm = NULL;             /* Realm */
  13546.     char * tmpcache = NULL;             /* Cache file */
  13547.     char * tmpinst  = NULL;             /* K4 Instance */
  13548.     char * tmpaddrs[KRB5_NUM_OF_ADDRS];
  13549. #ifdef CK_RECALL
  13550.     extern int on_recall;               /* around Password prompting */
  13551. #endif /* CK_RECALL */
  13552.     struct stringint {                  /* Temporary array for switch values */
  13553.         char * sval;                    /* String value */
  13554.         int ival;                       /* Integer value */
  13555.     } pv[KRB_I_MAX+1];                  /* This many */
  13556.     struct FDB kw, sw, fl;              /* FDBs for each parse function */
  13557.  
  13558.     krb_action = -1;                    /* Initialize Kerberos action. */
  13559.     tmp_action = -1;                    /* And our local copy. */
  13560.     for (i = 0; i < KRB5_NUM_OF_ADDRS; i++)
  13561.       tmpaddrs[i] = NULL;
  13562.  
  13563.     if ((y = cmkey(kerbtab,kerbtabn,"authentication type","",xxstring)) < 0)
  13564.       {
  13565.           if (y == -3)
  13566.             printf("?Authentication type not specified - nothing happens\n");
  13567.           return(y);
  13568.       }
  13569.     tmpauth = y;
  13570.     debug(F101,"kerberos authentication","",tmpauth);
  13571.     switch (tmpauth) {
  13572.       case AUTH_KRB4: kv = 4; break;    /* Don't assume values are the same */
  13573.       case AUTH_KRB5: kv = 5; break;
  13574.       default:
  13575.         printf("?Authentication type not supported: \"%s\"\n",atmbuf);
  13576.         return(-9);
  13577.     }
  13578.  
  13579.     /* From here down is Kerberos */
  13580.     ini_kerb();                         /* Reset Init data to defaults */
  13581.  
  13582.     if (kv == 4) {                      /* Set K4 defaults */
  13583.         if (krb4_d_realm)
  13584.           makestr(&tmprealm,krb4_d_realm);
  13585.         if (krb4_d_principal)
  13586.           makestr(&tmpprinz,krb4_d_principal);
  13587.         if (krb4_d_instance)
  13588.           makestr(&tmpinst,krb4_d_instance);
  13589.     } else if (kv == 5) {               /* Set K5 defaults */
  13590.         if (krb5_d_cc)
  13591.           makestr(&tmpcache,krb5_d_cc);
  13592.         if (krb5_d_realm)
  13593.           makestr(&tmprealm,krb5_d_realm);
  13594.         if (krb5_d_principal)
  13595.           makestr(&tmpprinz,krb5_d_principal);
  13596.         if (krb5_d_instance)
  13597.           makestr(&tmpinst,krb5_d_instance);
  13598.     }
  13599.  
  13600.     for (i = 0; i <= KRB_I_MAX; i++) {  /* Initialize switch values */
  13601.         pv[i].sval = NULL;              /* to null pointers */
  13602.         pv[i].ival = 0;                 /* and 0 int values */
  13603.     }
  13604.  
  13605.     if (kv == 4) {                      /* Kerberos 4 */
  13606.         pv[KRB_I_LF].ival = krb4_d_lifetime;
  13607.         pv[KRB_I_PA].ival = krb4_d_preauth;
  13608.  
  13609.         if ((n = cmkey(krb_a_tbl,krb_a_n,"Kerberos 4 action","",xxstring)) < 0)
  13610.           {
  13611.               if (n == -3)
  13612.                 printf("?Action not specified - nothing happens.\n");
  13613.               return(n);
  13614.           }
  13615.     } else if (kv == 5) {               /* Kerberos 5 */
  13616.         pv[KRB_I_FW].ival = krb5_d_forwardable;
  13617.         pv[KRB_I_PR].ival = krb5_d_proxiable;
  13618.         pv[KRB_I_LF].ival = krb5_d_lifetime;
  13619.         pv[KRB_I_RB].ival = krb5_d_renewable;
  13620.         pv[KRB_I_K4].ival = krb5_d_getk4;
  13621.         pv[KRB_I_NAD].ival = krb5_d_no_addresses;
  13622.  
  13623.         /* Make help message that shows switches and action keywords */
  13624.         ckstrncpy(tmphlp,"Kerberos 5 action, one of the following:\n ",256);
  13625.         for (i = 0; i < krb_a_n; i++) {
  13626.             ckstrncat(tmphlp,krb_a_tbl[i].kwd,sizeof(tmphlp));
  13627.             if (i == krb_a_n - 1)
  13628.               ckstrncat(tmphlp,"\nor switch",sizeof(tmphlp));
  13629.             else
  13630.               ckstrncat(tmphlp,"   ",sizeof(tmphlp));
  13631.         }
  13632.         /* Set up first set of chained FDB's */
  13633.  
  13634.         cmfdbi(&sw,                     /* First FDB - command switches */
  13635.                _CMKEY,                  /* fcode */
  13636.                tmphlp,                  /* hlpmsg */
  13637.                "",                      /* default (none) */
  13638.                "",                      /* addtl string data */
  13639.                krb_s_n,                 /* Switch table size */
  13640.                4,                       /* addtl numeric data 2: 4 = cmswi */
  13641.                xxstring,                /* Processing function */
  13642.                krb_s_tbl,               /* Switch table */
  13643.                &kw                      /* Pointer to next FDB */
  13644.                );
  13645.         cmfdbi(&kw,                     /* Second FDB - action keywords */
  13646.                _CMKEY,                  /* fcode */
  13647.                "Kerberos action",       /* hlpmsg */
  13648.                "",                      /* default (none) */
  13649.                "",                      /* addtl string data */
  13650.                krb_a_n,                 /* Switch table size */
  13651.                0,                       /* addtl num data (0 = NOT switch) */
  13652.                xxstring,                /* Processing function */
  13653.                krb_a_tbl,               /* Keyword table */
  13654.                NULL                     /* Pointer to next FDB (none) */
  13655.                );
  13656.  
  13657.         /* Parse */
  13658.  
  13659.         while (1) {                     /* Parse 0 or more switches */
  13660.             rc = cmfdb(&sw);            /* Parse something */
  13661.             debug(F101,"kerberos cmfdb 1 rc","",rc);
  13662.             if (rc < 0) {                       /* Error */
  13663.                 if (rc == -3)
  13664.                   printf("?Action not specified - nothing happens.\n");
  13665.                 return(rc);             /* or reparse needed */
  13666.             }
  13667.             if (cmresult.fdbaddr != &sw) /* Break out if not a switch */
  13668.               break;
  13669.             c = cmgbrk();               /* Have switch - get break character */
  13670.             getval = (c == ':' || c == '='); /* Must parse an agument? */
  13671.             if (getval && !(cmresult.kflags & CM_ARG)) {
  13672.                 printf("?This switch does not take arguments\n");
  13673.                 return(-9);             /* OK because nothing malloc'd yet */
  13674.             }
  13675.             if (!getval && (cmgkwflgs() & CM_ARG)) {
  13676.                 printf("?This switch requires an argument\n");
  13677.                 return(-9);
  13678.             }
  13679.             n = cmresult.nresult;       /* Numeric result = switch value */
  13680.             debug(F101,"kerberos command switch","",n);
  13681.  
  13682.             switch (n) {                /* Handle the switch */
  13683.               case KRB_S_CA:            /* /CACHE:<filename> */
  13684.                 p = krb5_d_cc ? krb5_d_cc : "";
  13685.                 if ((y = cmofi("Name of cache file",p,&s,xxstring)) < 0) {
  13686.                     if (y == -3)
  13687.                       s = NULL;
  13688.                     else
  13689.                       return(y);
  13690.                 }
  13691.                 makestr(&tmpcache,s);
  13692.                 break;
  13693.               default:
  13694.                 printf("?Unexpected switch value - internal error\n");
  13695.                 return(-9);             /* (if) nothing malloc'd yet. */
  13696.             }
  13697.         }
  13698.         if (cmresult.fdbaddr != &kw) {  /* Checking... */
  13699.             printf("?Unexpected result - internal error\n");
  13700.             return(-9);                 /* Nothing malloc'd yet. */
  13701.         }
  13702.         n = cmresult.nresult;           /* Get keyword value */
  13703.     } else {
  13704.         printf("?Unexpected Kerberos version - Internal error\n");
  13705.         return(-9);
  13706.     }
  13707.     debug(F101,"kerberos action","",n);
  13708.     switch (n) {
  13709.       case KRB_A_IN:                    /* INITIALIZE */
  13710.       case KRB_A_DE:                    /* DESTROY */
  13711.       case KRB_A_LC:                    /* LIST-CREDENTIALS */
  13712.         tmp_action = n;                 /* OK, set */
  13713.         break;
  13714.       default:                          /* Not OK, punt. */
  13715.         printf("?Unexpected action - internal error\n");
  13716.         return(-9);
  13717.     }
  13718.     if (tmp_action == KRB_A_IN) {       /* Action is INITIALIZE */
  13719.         int x;
  13720.         cmfdbi(&sw,                     /* INITIALIZE switches */
  13721.                _CMKEY,                  /* fcode */
  13722.                "Principal,\n or optional INITIALIZE switch(es)", /* hlpmsg */
  13723.                "",                      /* default (none) */
  13724.                "",                      /* addtl string data */
  13725.                kv == 4 ?  krb4_i_n : krb5_i_n, /* Switch table size */
  13726.                4,                       /* addtl numeric data 2: 4 = cmswi */
  13727.                xxstring,                /* Processing function */
  13728.                kv == 4 ?  krb4_i_tbl : krb5_i_tbl,      /* Switch table */
  13729.                &fl                      /* Pointer to next FDB */
  13730.                );
  13731.         cmfdbi(&fl,                     /* 3rd FDB - command to send from */
  13732.                _CMFLD,                  /* fcode */
  13733.                "Principal",             /* hlpmsg */
  13734.                kv == 4 ? krb4_d_principal : krb5_d_principal, /* principal */
  13735.                "",                      /* addtl string data */
  13736.                0,                       /* addtl numeric data 1 */
  13737.                0,                       /* addtl numeric data 2 */
  13738.                xxstring,
  13739.                NULL,
  13740.                NULL
  13741.                );
  13742.         while (1) {                     /* Parse INIT switches or principal */
  13743.             rc = cmfdb(&sw);
  13744.             debug(F101,"kerberos cmfdb 2 rc","",rc);
  13745.             if (rc < 0) {
  13746.                 if (rc == -3)
  13747.                   printf("?Principal name required\n");
  13748.                 goto kerbx;
  13749.             }
  13750.             debug(F101,"kerberos cmfdb 2 fcode","",cmresult.fcode);
  13751.             if (cmresult.fcode != _CMKEY) /* Not a switch, quit switch loop */
  13752.               break;
  13753.             c = cmgbrk();               /* Switch - get break character */
  13754.             debug(F101,"kerberos cmfdb 2 cmgbrk","",c);
  13755.             getval = (c == ':' || c == '=');
  13756.             if (getval && !(cmresult.kflags & CM_ARG)) {
  13757.                 printf("?This switch does not take arguments\n");
  13758.                 return(-9);             /* OK because nothing malloc'd yet */
  13759.             }
  13760.             if (!getval && (cmgkwflgs() & CM_ARG)) {
  13761.                 printf("?This switch requires an argument\n");
  13762.                 return(-9);
  13763.             }
  13764.             n = cmresult.nresult;       /* Numeric result = switch value */
  13765.             switch (n) {
  13766.               /* These don't take args... */
  13767.               case KRB_I_PA:            /* /PREAUTH */
  13768.               case KRB_I_FW:            /* /FORWARDABLE */
  13769.               case KRB_I_PR:            /* /PROXIABLE */
  13770.               case KRB_I_RN:            /* /RENEW */
  13771.               case KRB_I_VA:            /* /VALIDATE */
  13772.               case KRB_I_NPA:           /* /NOT-PREAUTH */
  13773.               case KRB_I_NFW:           /* /NOT-FORWARDABLE */
  13774.               case KRB_I_NPR:           /* /NOT-PROXIABLE */
  13775.               case KRB_I_VB:            /* /VERBOSE */
  13776.               case KRB_I_BR:            /* /BRIEF */
  13777.               case KRB_I_K4:            /* /KERBEROS4 */
  13778.               case KRB_I_NK4:           /* /NO-KERBEROS4 */
  13779.               case KRB_I_POP:           /* /POPUP */
  13780.               case KRB_I_NAD:           /* /NO-ADDRESSES */
  13781.                 if (getval) {
  13782.                     printf("?This switch does not take a value\n");
  13783.                     rc = -9;
  13784.                     goto kerbx;
  13785.                 }
  13786.                 switch (n) {
  13787.                   case KRB_I_NPA:
  13788.                     pv[KRB_I_PA].ival = 0;
  13789.                     break;
  13790.                   case KRB_I_NFW:
  13791.                     pv[KRB_I_FW].ival = 0;
  13792.                     break;
  13793.                   case KRB_I_NPR:
  13794.                     pv[KRB_I_PR].ival = 0;
  13795.                     break;
  13796.                   case KRB_I_VB:
  13797.                     pv[KRB_I_BR].ival = 0;
  13798.                     break;
  13799.                   case KRB_I_NK4:
  13800.                     pv[KRB_I_K4].ival = 0;
  13801.                     break;
  13802.                   default:
  13803.                     pv[n].ival = 1;
  13804.                 }
  13805.                 break;
  13806.  
  13807.                 /* These do take arguments */
  13808.  
  13809.               case KRB_I_RB:            /* /RENEWABLE:<minutes> */
  13810.                 pv[n].ival = 0;
  13811.                 if (!getval) break;
  13812.                 if ((rc = cmnum("Minutes",ckitoa(krb5_init.renewable),
  13813.                                 10,&y, xxstring)) < 0)
  13814.                   goto kerbx;
  13815.                 pv[n].ival = y;
  13816.                 break;
  13817.  
  13818.               case KRB_I_LF:            /* /LIFETIME:<minutes> */
  13819.                 pv[n].ival = 0;
  13820.                 /* Default is previous value */
  13821.                 sprintf(tmpbuf,"%d",    /* SAFE */
  13822.                         kv == 4 ?
  13823.                         krb4_init.lifetime :
  13824.                         krb5_init.lifetime
  13825.                         );
  13826.                 if (!getval) break;
  13827.                 if ((rc = cmnum("Minutes",tmpbuf,10,&y, xxstring)) < 0)
  13828.                   goto kerbx;
  13829.                 pv[n].ival = y;
  13830.                 break;
  13831.  
  13832.               case KRB_I_PD:            /* /POSTDATE:<timestamp> */
  13833.                 if (pv[n].sval) {
  13834.                     free(pv[n].sval);
  13835.                     pv[n].sval = NULL;
  13836.                 }
  13837.                 if (!getval) break;
  13838.                 if ((rc = cmdate("date-time","",&s,0,xxstring)) < 0)
  13839.                   goto kerbx;
  13840.                 makestr(&(pv[n].sval),s);
  13841.                 break;
  13842.  
  13843.               case KRB_I_SR:            /* /SERVICE:<name> */
  13844.                 if (pv[n].sval) {
  13845.                     free(pv[n].sval);
  13846.                     pv[n].sval = NULL;
  13847.                 }
  13848.                 if (!getval) break;
  13849.                 if ((rc = cmfld("Service-name","",&s,xxstring)) < 0)
  13850.                   goto kerbx;
  13851.                 makestr(&(pv[n].sval),s);
  13852.                 break;
  13853.  
  13854.               case KRB_I_RL:            /* /REALM:<name> */
  13855.                 if (pv[n].sval) {
  13856.                     free(pv[n].sval);
  13857.                     pv[n].sval = NULL;
  13858.                 }
  13859.                 if (!getval) break;
  13860.                 if (kv == 4)
  13861.                   p = krb4_d_realm ? krb4_d_realm : "";
  13862.                 else
  13863.                   p = krb5_d_realm ? krb5_d_realm : "";
  13864.                 if ((rc = cmfld("Realm",p,&s,xxstring)) < 0)
  13865.                   goto kerbx;
  13866.                 makestr(&(pv[n].sval),s);
  13867.                 break;
  13868.  
  13869.               case KRB_I_IN:            /* /INSTANCE:<name> */
  13870.                 if (pv[n].sval) {
  13871.                     free(pv[n].sval);
  13872.                     pv[n].sval = NULL;
  13873.                 }
  13874.                 if (!getval) break;
  13875.                 if (kv == 4)
  13876.                     p = krb4_d_instance ? krb4_d_instance : "";
  13877.                 else
  13878.                     p = krb5_d_instance ? krb5_d_instance : "";
  13879.                 if ((rc = cmfld("Instance",p,&s,xxstring)) < 0)
  13880.                   goto kerbx;
  13881.                 makestr(&(pv[n].sval),s);
  13882.                 break;
  13883.  
  13884.               case KRB_I_PW:            /* /PASSWORD:<password> */
  13885.                 debok = 0;
  13886.                 if (pv[n].sval) {
  13887.                     free(pv[n].sval);
  13888.                     pv[n].sval = NULL;
  13889.                 }
  13890.                 if (!getval) break;
  13891.                 if ((rc = cmfld("Password","",&s,xxstring)) < 0)
  13892.                   if (rc != -3)
  13893.                     goto kerbx;
  13894.                 makestr(&(pv[n].sval),s);
  13895.                 break;
  13896.  
  13897.               case KRB_I_ADR:           /* /ADDRESSES:{<address-list>} */
  13898.                 if (pv[n].sval) {
  13899.                     free(pv[n].sval);
  13900.                     pv[n].sval = NULL;
  13901.                 }
  13902.                 if (!getval) break;
  13903.                 if ((rc = cmfld("List of IP addresses","",&s,xxstring)) < 0)
  13904.                   goto kerbx;
  13905.                 makelist(s,tmpaddrs,KRB5_NUM_OF_ADDRS);
  13906.                 for (i = 0; i < KRB5_NUM_OF_ADDRS && tmpaddrs[i]; i++) {
  13907.                     if (inet_addr(tmpaddrs[i]) == 0xffffffff) {
  13908.                         printf("invalid ip address: %s\n",tmpaddrs[i]);
  13909.                         rc = -9;
  13910.                         goto kerbx;
  13911.                     }
  13912.                 }
  13913.                 pv[KRB_I_NAD].ival = 0;
  13914.                 break;
  13915.  
  13916.               default:
  13917.                 printf("?Unexpected switch value - internal error\n");
  13918.                 rc = -9;
  13919.                 goto kerbx;
  13920.             }
  13921.         }
  13922.         if (cmresult.fcode != _CMFLD) {
  13923.             printf("?Unexected result - internal error\n");
  13924.             rc = -9;
  13925.             goto kerbx;
  13926.         }
  13927.         /* cmresult.sresult may be of the form PRINCIPAL@REALM */
  13928.         i = ckindex("@",cmresult.sresult,0,0,0);
  13929.         if (i != 0) {
  13930.             makestr(&tmprealm,&cmresult.sresult[i]);
  13931.             cmresult.sresult[i-1] = '\0';
  13932.         }
  13933.         makestr(&tmpprinz,cmresult.sresult); /* Principal (user) */
  13934.  
  13935.         if ((rc = cmcfm()) < 0) {       /* Now get confirmation */
  13936.             if (rc == -3) {
  13937.                 printf("?Principal name required\n");
  13938.             }
  13939.             goto kerbx;
  13940.         }
  13941.         if (!tmpprinz || !tmpprinz[0]) {
  13942.             printf("?Principal name required\n");
  13943.             goto kerbx;
  13944.         }
  13945.         if (!pv[KRB_I_RN].ival && !pv[KRB_I_VA].ival) {
  13946.             /* Don't use a password if Validating or Renewing */
  13947.             if (pv[KRB_I_PW].sval) {    /* If they gave a /PASSWORD switch */
  13948.                 makestr(&tmppswd,pv[KRB_I_PW].sval); /* use this value */
  13949.             }
  13950. #ifdef COMMENT
  13951.             /* Password prompting has been moved to ck_krb[45]_initTGT() */
  13952.             else {                      /* Otherwise must prompt for it */
  13953.                 char prmpt[80];
  13954.                 if (pv[KRB_I_RL].sval)
  13955.                   sprintf(prmpt,"%s@%s's Password: ",
  13956.                           tmpprinz,pv[KRB_I_RL].sval);
  13957.                 else if (tmprealm)
  13958.                   sprintf(prmpt,"%s@%s's Password: ",
  13959.                           tmpprinz,tmprealm);
  13960.                 else
  13961.                   sprintf(prmpt,"%s's Password: ",tmpprinz);
  13962. #ifdef OS2
  13963.                 if (pv[KRB_I_POP].ival) {
  13964.                     char passwd[80]="";
  13965.                     readpass(prmpt,passwd,80);
  13966.                     makestr(&tmppswd,passwd);
  13967.                     memset(passwd,0,80);
  13968.                 } else
  13969. #endif /* OS2 */
  13970.                 {
  13971. #ifdef CK_RECALL
  13972.                     on_recall = 0;
  13973. #endif /* CK_RECALL */
  13974.                     cmsavp(psave,PROMPTL); /* Save old prompt */
  13975.                     cmsetp(prmpt);      /* Make new prompt */
  13976.                     concb((char)escape); /* Put console in cbreak mode */
  13977.                     cmini(0);           /* and no-echo mode */
  13978.                     /* Issue prompt if at top level */
  13979.                     if (pflag) prompt(xxstring);
  13980.                     cmres();            /* Reset the parser */
  13981.                     for (rc = -1; rc < 0; ) { /* Prompt till they answer */
  13982.                         /* Get a literal line of text */
  13983.                         rc = cmtxt("","",&s,NULL);
  13984.                         cmres();        /* Reset the parser again */
  13985.                     }
  13986.                     makestr(&tmppswd,s);
  13987.                     printf("\n");       /* Echo a CRLF */
  13988.                     cmsetp(psave);      /* Restore original prompt */
  13989.                 }
  13990.             }
  13991.             x = 0;                      /* Check for password */
  13992.             if (tmppswd)
  13993.               if (*tmppswd)
  13994.                 x = 1;
  13995.             if (!x) {
  13996.                 printf("?Password required\n");
  13997.                 goto kerbx;
  13998.             }
  13999. #endif /* COMMENT */
  14000.         }
  14001.     } else if (kv == 5 && tmp_action == KRB_A_LC) { /* LIST-CREDENTIALS */
  14002.         tmp_klc = 0;
  14003.         while (1) {
  14004.             if ((x = cmkey(klctab,nklctab,"Switch","",xxstring)) < 0) {
  14005.                 if (x == -3) {
  14006.                     if ((rc = cmcfm()) < 0)
  14007.                       goto kerbx;
  14008.                     else
  14009.                       break;
  14010.                 } else {
  14011.                     rc = x;
  14012.                     goto kerbx;
  14013.                 }
  14014.             }
  14015.             tmp_klc |= x;
  14016.         }
  14017.     } else if ((rc = cmcfm()) < 0)      /* DESTROY, just confirm */
  14018.         goto kerbx;
  14019.  
  14020. /* Done - Move confirmed data to final locations */
  14021.  
  14022.     krb_action = tmp_action;            /* Action requested */
  14023.     krb_op.version = kv;                /* Kerberos version */
  14024.     krb_op.cache = tmpcache;            /* Cache file */
  14025.     tmpcache = NULL;                    /* So we don't free it */
  14026.  
  14027.     switch (krb_action) {
  14028.       case KRB_A_IN:                    /* INITIALIZE */
  14029.         if (kv == 5) {
  14030.             krb5_init.forwardable = pv[KRB_I_FW].ival;
  14031.             krb5_init.proxiable   = pv[KRB_I_PR].ival;
  14032.             krb5_init.lifetime    = pv[KRB_I_LF].ival;
  14033.             krb5_init.renew       = pv[KRB_I_RN].ival;
  14034.             krb5_init.renewable   = pv[KRB_I_RB].ival;
  14035.             krb5_init.validate    = pv[KRB_I_VA].ival;
  14036.  
  14037.             /* Here we just reassign the pointers and then set them to NULL */
  14038.             /* so they won't be freed below. */
  14039.  
  14040.             krb5_init.postdate = pv[KRB_I_PD].sval; pv[KRB_I_PD].sval = NULL;
  14041.             krb5_init.service  = pv[KRB_I_SR].sval; pv[KRB_I_SR].sval = NULL;
  14042.             if (pv[KRB_I_RL].sval) {
  14043.                 krb5_init.realm  = pv[KRB_I_RL].sval; pv[KRB_I_RL].sval = NULL;
  14044.             } else if (tmprealm) {
  14045.                 krb5_init.realm = tmprealm; tmprealm = NULL;
  14046.             }
  14047.             if (pv[KRB_I_IN].sval) {
  14048.                 krb5_init.instance = pv[KRB_I_IN].sval;
  14049.                 pv[KRB_I_IN].sval = NULL;
  14050.             } else if ( tmpinst ) {
  14051.                 krb5_init.instance = tmpinst;
  14052.                 tmpinst = NULL;
  14053.             }
  14054.             if (tmpprinz) {
  14055.                 krb5_init.principal = tmpprinz;
  14056.                 tmpprinz = NULL;
  14057.             }
  14058.             krb5_init.password = tmppswd;
  14059.             tmppswd = NULL;
  14060.  
  14061.             krb5_init.getk4 = pv[KRB_I_K4].ival;
  14062.             if (krb5_init.getk4) {
  14063.                 krb4_init.lifetime = pv[KRB_I_LF].ival;
  14064.                 if (krb5_init.realm)
  14065.                     makestr(&krb4_init.realm,krb5_init.realm);
  14066.                 krb4_init.preauth  = krb4_d_preauth;
  14067.                 krb4_init.verbose  = pv[KRB_I_BR].ival ? 0 : 1;
  14068.                 if (krb5_init.principal)
  14069.                     makestr(&krb4_init.principal,krb5_init.principal);
  14070.                 if (krb5_init.principal)
  14071.                     makestr(&krb4_init.password,krb5_init.password);
  14072.             }
  14073.             krb5_init.no_addresses = pv[KRB_I_NAD].ival;
  14074.             if (tmpaddrs[0]) {
  14075.                 for (i = 0; i < KRB5_NUM_OF_ADDRS; i++) {
  14076.                     if (krb5_init.addrs[i]) {
  14077.                         free(krb5_init.addrs[i]);
  14078.                         krb5_init.addrs[i] = NULL;
  14079.                     }
  14080.                     krb5_init.addrs[i] = tmpaddrs[i];
  14081.                     tmpaddrs[i] = NULL;
  14082.                 }
  14083.             }
  14084.         } else if (kv == 4) {           /* Same deal for Kerberos 4 */
  14085.             krb4_init.lifetime = pv[KRB_I_LF].ival;
  14086.             if (pv[KRB_I_RL].sval) {
  14087.                 krb4_init.realm  = pv[KRB_I_RL].sval;
  14088.                 pv[KRB_I_RL].sval = NULL;
  14089.             } else if ( tmprealm ) {
  14090.                 krb4_init.realm  = tmprealm;
  14091.                 tmprealm = NULL;
  14092.             }
  14093.             if (pv[KRB_I_IN].sval) {
  14094.                 krb4_init.instance = pv[KRB_I_IN].sval;
  14095.                 pv[KRB_I_IN].sval = NULL;
  14096.             } else if ( tmpinst ) {
  14097.                 krb4_init.instance = tmpinst;
  14098.                 tmpinst = NULL;
  14099.             }
  14100.             krb4_init.preauth  = pv[KRB_I_PA].ival;
  14101.             krb4_init.verbose  = pv[KRB_I_BR].ival ? 0 : 1;
  14102.  
  14103.             if (tmpprinz) {
  14104.                 krb4_init.principal = tmpprinz;
  14105.                 tmpprinz = NULL;
  14106.             }
  14107.             krb4_init.password = tmppswd;
  14108.             tmppswd = NULL;
  14109.         }
  14110.         break;
  14111.       case KRB_A_LC:                    /* List Credentials */
  14112.         krb5_lc.encryption = tmp_klc & XYKLCEN;
  14113.         krb5_lc.flags = tmp_klc & XYKLCFL;
  14114.         krb5_lc.addr  = tmp_klc & XYKLCAD;
  14115.         break;
  14116.     }
  14117.  
  14118. /* Common exit - Free temporary storage */
  14119.  
  14120.   kerbx:
  14121.     for (i = 0; i <= KRB_I_MAX; i++) {  /* Free malloc'd switch data */
  14122.         if (pv[i].sval)
  14123.           free(pv[i].sval);
  14124.     }
  14125.     for (i = 0; i < KRB5_NUM_OF_ADDRS; i++) {
  14126.         if (tmpaddrs[i])
  14127.           free(tmpaddrs[i]);
  14128.     }
  14129.     if (tmpprinz) free(tmpprinz);       /* And these too. */
  14130.     if (tmppswd)  free(tmppswd);
  14131.     if (tmpcache) free(tmpcache);
  14132.     if (tmprealm) free(tmprealm);
  14133.     if (tmpinst)  free(tmpinst);
  14134.  
  14135.     return(rc);                         /* Return the return code */
  14136. }
  14137. #endif /* CK_KERBEROS */
  14138.  
  14139. #ifdef CK_LOGIN
  14140. int
  14141. #ifdef CK_ANSIC
  14142. ckxlogin(CHAR * userid, CHAR * passwd, CHAR * acct, int promptok)
  14143. #else /* CK_ANSIC */
  14144. ckxlogin(userid, passwd, acct, promptok)
  14145.   CHAR * userid; CHAR * passwd; CHAR * acct; int promptok;
  14146. #endif /* CK_ANSIC */
  14147. /* ckxlogin */ {
  14148. #ifdef CK_RECALL
  14149.     extern int on_recall;               /* around Password prompting */
  14150. #endif /* CK_RECALL */
  14151. #ifdef CK_PAM
  14152.     extern int guest;
  14153. #endif /* CK_PAM */
  14154.     int rprompt = 0;                    /* Restore prompt */
  14155. #ifdef CKSYSLOG
  14156.     int savlog;
  14157. #endif /* CKSYSLOG */
  14158.  
  14159.     extern int what, srvcdmsg;
  14160.  
  14161.     int x = 0, ok = 0, rc = 0;
  14162.     CHAR * _u = NULL, * _p = NULL, * _a = NULL;
  14163.  
  14164.     debug(F111,"ckxlogin userid",userid,promptok);
  14165.     debug(F110,"ckxlogin passwd",passwd,0);
  14166.  
  14167.     isguest = 0;                        /* Global "anonymous" flag */
  14168.  
  14169.     if (!userid) userid = (CHAR *)"";
  14170.     if (!passwd) passwd = (CHAR *)"";
  14171.  
  14172.     debug(F111,"ckxlogin userid",userid,what);
  14173.  
  14174. #ifdef CK_RECALL
  14175.     on_recall = 0;
  14176. #endif /* CK_RECALL */
  14177.  
  14178. #ifdef CKSYSLOG
  14179.     savlog = ckxsyslog;                 /* Save and turn off syslogging */
  14180. #endif /* CKSYSLOG */
  14181.  
  14182.     if ((!*userid || !*passwd) &&       /* Need to prompt for missing info */
  14183.         promptok) {
  14184.         cmsavp(psave,PROMPTL);          /* Save old prompt */
  14185.         debug(F110,"ckxlogin saved",psave,0);
  14186.         rprompt = 1;
  14187.     }
  14188.     if (!*userid) {
  14189.         if (!promptok)
  14190.           return(0);
  14191.         cmsetp("Username: ");           /* Make new prompt */
  14192.         concb((char)escape);            /* Put console in cbreak mode */
  14193.         cmini(1);
  14194.  
  14195. /* Flush typeahead */
  14196.  
  14197. #ifdef IKS_OPTION
  14198.         debug(F101,
  14199.               "ckxlogin TELOPT_SB(TELOPT_KERMIT).kermit.me_start",
  14200.               "",
  14201.               TELOPT_SB(TELOPT_KERMIT).kermit.me_start
  14202.               );
  14203. #endif /* IKS_OPTION */
  14204.  
  14205.         while (ttchk() > 0) {
  14206.             x = ttinc(0);
  14207.             debug(F101,"ckxlogin flush user x","",x);
  14208.             if (x < 0)
  14209.               doexit(GOOD_EXIT,0);      /* Connection lost */
  14210. #ifdef TNCODE
  14211.             if (sstelnet) {
  14212.                 if (x == IAC) {
  14213.                     x = tn_doop((CHAR)(x & 0xff),ckxech,ttinc);
  14214.                     debug(F101,"ckxlogin user tn_doop","",x);
  14215. #ifdef IKS_OPTION
  14216.                     debug(F101,
  14217.                       "ckxlogin user TELOPT_SB(TELOPT_KERMIT).kermit.me_start",
  14218.                       "",
  14219.                       TELOPT_SB(TELOPT_KERMIT).kermit.me_start
  14220.                       );
  14221. #endif /* IKS_OPTION */
  14222.  
  14223.                     if (x < 0)
  14224.                       goto XCKXLOG;
  14225.                     switch (x) {
  14226.                       case 1: ckxech = 1; break; /* Turn on echoing */
  14227.                       case 2: ckxech = 0; break; /* Turn off echoing */
  14228. #ifdef IKS_OPTION
  14229.                       case 4:                    /* IKS event */
  14230.                         if (!TELOPT_SB(TELOPT_KERMIT).kermit.me_start)
  14231.                           break;                 /* else fall thru... */
  14232. #endif /* IKS_OPTION */
  14233.                       case 6:                    /* Logout */
  14234.                         goto XCKXLOG;
  14235.                     }
  14236.                 }
  14237.             }
  14238. #endif /* TNCODE */
  14239.         }
  14240.         if (pflag) prompt(xxstring);    /* Issue prompt if at top level */
  14241.         cmres();                        /* Reset the parser */
  14242.         for (x = -1; x < 0;) {          /* Prompt till they answer */
  14243.             /* Get a literal line of text */
  14244.             x=cmtxt("Your username, or \"ftp\", or \"anonymous\"","",&s,NULL);
  14245.             if (x == -4 || x == -10) {
  14246.                 printf("\r\nLogin cancelled\n");
  14247. #ifdef CKSYSLOG
  14248.                 ckxsyslog = savlog;
  14249. #endif /* CKSYSLOG */
  14250.                 doexit(GOOD_EXIT,0);
  14251.             }
  14252.             if (sstate)                 /* Did a packet come instead? */
  14253.               goto XCKXLOG;
  14254.             cmres();                    /* Reset the parser again */
  14255.         }
  14256.         if ((_u = (CHAR *)malloc((int)strlen(s) + 1)) == NULL) {
  14257.             printf("?Internal error: malloc\n");
  14258.             goto XCKXLOG;
  14259.         } else {
  14260.             strcpy((char *)_u,s);       /* safe */
  14261.             userid = _u;
  14262.         }
  14263.     }
  14264.     ok = zvuser((char *)userid);        /* Verify username */
  14265.     debug(F111,"ckxlogin zvuser",userid,ok);
  14266.  
  14267.     if (!*passwd && promptok
  14268. #ifdef CK_PAM
  14269.         && guest
  14270. #endif /* CK_PAM */
  14271.         ) {
  14272.         char prmpt[80];
  14273.  
  14274. #ifdef CKSYSLOG
  14275.         savlog = ckxsyslog;             /* Save and turn off syslogging */
  14276.         ckxsyslog = 0;
  14277. #endif /* CKSYSLOG */
  14278.  
  14279. /* Flush typeahead again */
  14280.  
  14281.         while (ttchk() > 0) {
  14282.             x = ttinc(0);
  14283.             debug(F101,"ckxlogin flush user x","",x);
  14284. #ifdef TNCODE
  14285.             if (sstelnet) {
  14286.                 if (x == IAC) {
  14287.                     x = tn_doop((CHAR)(x & 0xff),ckxech,ttinc);
  14288.                     debug(F101,"ckxlogin pass tn_doop","",x);
  14289. #ifdef IKS_OPTION
  14290.                     debug(F101,
  14291.                       "ckxlogin pass TELOPT_SB(TELOPT_KERMIT).kermit.me_start",
  14292.                       "",
  14293.                       TELOPT_SB(TELOPT_KERMIT).kermit.me_start
  14294.                       );
  14295. #endif /* IKS_OPTION */
  14296.                     if (x < 0)
  14297.                       goto XCKXLOG;
  14298.                     switch (x) {
  14299.                       case 1: ckxech = 1; break; /* Turn on echoing */
  14300.                       case 2: ckxech = 0; break; /* Turn off echoing */
  14301.                       case 4:                    /* IKS event */
  14302.                         if (!TELOPT_SB(TELOPT_KERMIT).kermit.me_start)
  14303.                           break;                 /* else fall thru... */
  14304.                       case 6:                    /* Logout */
  14305.                         goto XCKXLOG;
  14306.                     }
  14307.                 }
  14308.             }
  14309. #endif /* TNCODE */
  14310.         }
  14311.         if (!strcmp((char *)userid,"anonymous") ||
  14312.             !strcmp((char *)userid,"ftp")) {
  14313.             if (!ok)
  14314.               goto XCKXLOG;
  14315.             ckstrncpy(prmpt,"Enter e-mail address as Password: ",80);
  14316.         } else if (*userid && strlen((char *)userid) < 60) {
  14317. #ifdef NT
  14318.             extern CHAR * pReferenceDomainName;
  14319.             if (pReferenceDomainName)
  14320.               ckmakxmsg(prmpt,
  14321.                        80,
  14322.                        "Enter ",
  14323.                        pReferenceDomainName,
  14324.                        "\\\\",
  14325.                        userid,
  14326.                        "'s Password: ",
  14327.                        NULL,NULL,NULL,NULL,NULL,NULL,NULL
  14328.                        );
  14329.             else
  14330. #endif /* NT */
  14331.               ckmakmsg(prmpt,80,"Enter ",(char *)userid,"'s Password: ",NULL);
  14332.         } else
  14333.           ckstrncpy(prmpt,"Enter Password: ",80);
  14334.         cmsetp(prmpt);                  /* Make new prompt */
  14335.         concb((char)escape);            /* Put console in cbreak mode */
  14336.         if (strcmp((char *)userid,"anonymous") &&
  14337.             strcmp((char *)userid,"ftp")) { /* and if not anonymous */
  14338.             debok = 0;
  14339.             cmini(0);                   /* and no-echo mode */
  14340.         } else {
  14341.             cmini(1);
  14342.         }
  14343.         if (pflag) prompt(xxstring);    /* Issue prompt if at top level */
  14344.         cmres();                        /* Reset the parser */
  14345.         for (x = -1; x < 0;) {          /* Prompt till they answer */
  14346.             x = cmtxt("","",&s,NULL);   /* Get a literal line of text */
  14347.             if (x == -4 || x == -10) {
  14348.                 printf("\r\nLogin cancelled\r\n");
  14349. #ifdef CKSYSLOG
  14350.                 ckxsyslog = savlog;
  14351. #endif /* CKSYSLOG */
  14352.                 doexit(GOOD_EXIT,0);
  14353.             }
  14354.             if (sstate)                 /* In case of a Kermit packet */
  14355.               goto XCKXLOG;
  14356.             cmres();                    /* Reset the parser again */
  14357.         }
  14358.         printf("\r\n");                 /* Echo a CRLF */
  14359.         if ((_p = (CHAR *)malloc((int)strlen(s) + 1)) == NULL) {
  14360.             printf("?Internal error: malloc\n");
  14361.             goto XCKXLOG;
  14362.         } else {
  14363.             strcpy((char *)_p,s);       /* safe */
  14364.             passwd = _p;
  14365.         }
  14366.     }
  14367. #ifdef CK_PAM
  14368.     else {
  14369.         cmres();                        /* Reset the parser */
  14370.  
  14371.         /* We restore the prompt now because the PAM engine will call  */
  14372.         /* readpass() which will overwrite psave. */
  14373.         if (rprompt) {
  14374.             cmsetp(psave);              /* Restore original prompt */
  14375.             debug(F110,"ckxlogin restored",psave,0);
  14376.             rprompt = 0;
  14377.         }
  14378.     }
  14379. #endif /* CK_PAM */
  14380.  
  14381. #ifdef CKSYSLOG
  14382.     ckxsyslog = savlog;
  14383. #endif /* CKSYSLOG */
  14384.  
  14385.     if (ok) {
  14386.         ok = zvpass((char *)passwd);    /* Check password */
  14387.         debug(F101,"ckxlogin zvpass","",ok);
  14388.     }
  14389.  
  14390.     if (ok > 0 && isguest) {
  14391. #ifndef NOPUSH
  14392.         nopush = 1;
  14393. #endif /* NOPUSH */
  14394.         srvcdmsg = 1;
  14395.     }
  14396.     rc = ok;                            /* Set the return code */
  14397.     if ((char *)uidbuf != (char *)userid)
  14398.       ckstrncpy(uidbuf,(char *)userid,UIDBUFLEN); /* Remember username */
  14399.  
  14400.   XCKXLOG:                              /* Common exit */
  14401. #ifdef CKSYSLOG
  14402.     ckxsyslog = savlog;                 /* In case of GOTO above */
  14403. #endif /* CKSYSLOG */
  14404.     if (rprompt) {
  14405.         cmsetp(psave);                  /* Restore original prompt */
  14406.         debug(F110,"ckxlogin restored",psave,0);
  14407.     }
  14408.     if (_u || _p || _a) {
  14409.         if (_u) free(_u);
  14410.         if (_p) free(_p);
  14411.         if (_a) free(_a);
  14412.     }
  14413.     return(rc);
  14414. }
  14415.  
  14416. int
  14417. ckxlogout() {
  14418.     doexit(GOOD_EXIT,0);                /* doexit calls zvlogout */
  14419.     return(0);                          /* not reached */
  14420. }
  14421. #endif /* CK_LOGIN */
  14422.  
  14423. #endif /* NOICP */
  14424.