home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / cku206.zip / ckuus7.c < prev    next >
C/C++ Source or Header  |  2002-10-24  |  518KB  |  14,789 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, rcdactive;
  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. #ifdef LOCUS
  280. extern int locus, autolocus;
  281. #endif /* LOCUS */
  282. #ifndef NODIAL
  283. extern int dialsta;
  284. #endif /* NODIAL */
  285.  
  286. /* Note: gcc -Wall wants braces around each keyword table entry. */
  287.  
  288. static struct keytab psltab[] = {       /* SET LINE/PORT command options */
  289.     { "/connect", SL_CNX, 0 },
  290. #ifdef OS2ORVMS
  291.     { "/noshare", SL_NSH, 0 },
  292. #endif /* OS2ORVMS */
  293.     { "/server",  SL_SRV, 0 },
  294. #ifdef OS2ORVMS
  295.     { "/share",   SL_SHR, 0 },
  296. #endif /* OS2ORVMS */
  297.     { "", 0, 0 }
  298. };
  299. static int npsltab = sizeof(psltab)/sizeof(struct keytab) - 1;
  300.  
  301. #ifdef NETCONN
  302. static struct keytab shtab[] = {        /* SET HOST command options */
  303. #ifdef NETCMD
  304.     /* (COMMAND is also a network type) */
  305.     { "/command",      SL_CMD,    CM_INV },
  306. #endif /* NETCMD */
  307.     { "/connect",      SL_CNX,    0 },
  308.     { "/network-type", SL_NET,    CM_ARG },
  309.     { "/nowait",       SL_NOWAIT, 0 },
  310. #ifndef NOSPL
  311. #ifdef CK_AUTHENTICATION
  312.     { "/password",     SL_PSW,    CM_ARG },
  313. #endif /* CK_AUTHENTICATION */
  314. #endif /* NOSPL */
  315. #ifdef NETCMD
  316.     { "/pipe",         SL_CMD,    0 },
  317. #endif /* NETCMD */
  318. #ifdef NETPTY
  319.     { "/pty",          SL_PTY,    0 },
  320. #endif /* NETPTY */
  321.     { "/server",       SL_SRV,    0 },
  322.     { "/timeout",      SL_TMO,    CM_ARG },
  323.     { "/userid",       SL_UID,    CM_ARG },
  324.     { "/wait",         SL_WAIT,   0 },
  325.     { "", 0, 0 }
  326. };
  327. static int nshtab = sizeof(shtab)/sizeof(struct keytab) - 1;
  328.  
  329. static struct keytab shteltab[] = {     /* TELNET command options */
  330. #ifdef CK_AUTHENTICATION
  331.     { "/auth",         SL_AUTH,   CM_ARG },
  332. #endif /* CK_AUTHENTICATION */
  333. #ifdef CK_ENCRYPTION
  334.     { "/encrypt",      SL_ENC,    CM_ARG },
  335. #endif /* CK_ENCRYPTION */
  336.     { "/nowait",       SL_NOWAIT, 0 },
  337. #ifndef NOSPL
  338. #ifdef CK_AUTHENTICATION
  339.     { "/password",     SL_PSW,    CM_ARG },
  340. #endif /* CK_AUTHENTICATION */
  341. #endif /* NOSPL */
  342.     { "/timeout",      SL_TMO,    CM_ARG },
  343.     { "/userid",       SL_UID,    CM_ARG },
  344.     { "/wait",         SL_WAIT,   0 },
  345.     { "", 0 ,0 }
  346. };
  347. static int nshteltab = sizeof(shteltab)/sizeof(struct keytab) - 1;
  348.  
  349. #ifdef RLOGCODE
  350. static struct keytab shrlgtab[] = {     /* SET HOST RLOGIN command options */
  351. #ifdef CK_KERBEROS
  352. #ifdef CK_ENCRYPTION
  353.     { "/encrypt",      SL_ENC, 0 },
  354. #endif /* CK_ENCRYPTION */
  355.     { "/k4",           SL_KRB4, CM_INV },
  356.     { "/k5",           SL_KRB5, CM_INV },
  357.     { "/kerberos4",    SL_KRB4, 0 },
  358.     { "/kerberos5",    SL_KRB5, 0 },
  359.     { "/kerberos_iv",  SL_KRB4, CM_INV },
  360.     { "/kerberos_v",   SL_KRB5, CM_INV },
  361.     { "/krb4",         SL_KRB4, CM_INV },
  362.     { "/krb5",         SL_KRB5, CM_INV },
  363. #endif /* CK_KERBEROS */
  364.     { "", 0 ,0 }
  365. };
  366. static int nshrlgtab = sizeof(shrlgtab)/sizeof(struct keytab)-1;
  367. #endif /* RLOGCODE */
  368.  
  369. extern struct keytab netcmd[];
  370. extern int nnets;
  371. #ifndef NODIAL
  372. extern int dirline;
  373. extern int nnetdir;                     /* Network services directory */
  374. extern char *netdir[];
  375. _PROTOTYP( VOID ndreset, (void) );
  376. char *nh_p[MAXDNUMS + 1];               /* Network directory entry pointers */
  377. char *nh_p2[MAXDNUMS + 1];              /* Network directory entry nettype */
  378. char *nh_px[4][MAXDNUMS + 1];           /* Network-specific stuff... */
  379. #endif /* NODIAL */
  380. int nhcount = 0;
  381. int ndinited = 0;
  382. char * n_name = NULL;                   /* Network name pointer */
  383. #endif /* NETCONN */
  384.  
  385. _PROTOTYP(int remtxt, (char **) );
  386. _PROTOTYP(VOID rmsg, (void) );
  387. _PROTOTYP(static int remcfm, (void) );
  388.  
  389. extern int nopush;
  390.  
  391. int mdmsav = -1;                        /* Save modem type around network */
  392. extern int isguest;                     /* Global flag for anonymous login */
  393.  
  394. extern xx_strp xxstring;
  395.  
  396. extern int success, binary, b_save, ckwarn, msgflg, quiet, cmask, pflag, local,
  397.   nettype, escape, mdmtyp, duplex, dfloc, network, cdtimo, autoflow, tnlm,
  398.   sosi, tlevel, lf_opts, backgrd, flow, debses, parity, ttnproto, ckxech,
  399.   x_ifnum, cmflgs, haveline, cxtype, cxflow[], maclvl;
  400.  
  401. #ifdef DCMDBUF
  402. extern struct cmdptr *cmdstk;           /* The command stack itself */
  403. #else
  404. extern struct cmdptr cmdstk[];          /* The command stack itself */
  405. #endif /* DCMDBUF */
  406. extern FILE * tfile[];
  407. extern char * macp[];
  408.  
  409. extern char psave[];                    /* For saving & restoring prompt */
  410. extern int sprmlen, rprmlen;
  411.  
  412. #ifdef OS2
  413. static struct keytab strmkeytab[] = {
  414.     { "clear",   0, 0 },
  415.     { "default", 1, 0 }
  416. };
  417. static int nstrmkeytab = sizeof(strmkeytab)/sizeof(struct keytab);
  418.  
  419. static struct keytab strmswitab[] = {
  420.     { "/literal", 0, 0 }
  421. };
  422. static int nstrmswitab = sizeof(strmswitab)/sizeof(struct keytab);
  423.  
  424. static struct keytab normrev[] = {
  425.     { "dark-display", 0, 0 },
  426.     { "light-display", 1, 0 },
  427.     { "normal",   0, 0 },
  428.     { "reverse",  1, 0 }
  429. };
  430.  
  431. static struct keytab prnmtab[] = {
  432.     { "auto", 1, 0 },
  433.     { "copy", 2, 0 },
  434.     { "off",  0, 0 },
  435.     { "on",   1, CM_INV },              /* Compatibility with XPRINT version */
  436.     { "user", 3, 0 },
  437.     { "transparent", 3, CM_INV }        /* not really transparent */
  438. };
  439. static int nprnmtab = sizeof(prnmtab)/sizeof(struct keytab);
  440.  
  441. extern int tt_diff_upd;
  442.  
  443. #ifdef NT
  444. #define stricmp _stricmp
  445. extern int tt_attr_bug;
  446. #endif /* NT */
  447. extern int tt_rows[], tt_cols[];
  448. extern int tt_cols_usr;
  449. extern int tt_szchng[VNUM];
  450. int tt_modechg = TVC_ENA;
  451. extern int tt_url_hilite, tt_url_hilite_attr;
  452. extern struct _vtG G[4];
  453. extern int priority;
  454. extern bool send_c1;
  455. int send_c1_usr = FALSE;
  456. extern int sgrcolors;
  457. extern int marginbell, marginbellcol;
  458. extern int autoscroll, wy_autopage;
  459. extern int tt_sac;
  460. extern int dec_nrc, dec_lang, dec_kbd;
  461. #else /* OS2 */
  462. extern int tt_rows, tt_cols;
  463. #endif /*  OS2 */
  464.  
  465. extern int tt_escape;
  466. extern long speed;
  467.  
  468. extern char *dftty;
  469.  
  470. extern char *tp, *lp;                   /* Temporary buffer & pointers */
  471. extern char ttname[];
  472.  
  473. int tttapi = 0;                         /* is Line TAPI? */
  474. struct keytab * tapilinetab = NULL;
  475. struct keytab * _tapilinetab = NULL;
  476. int ntapiline = 0;
  477.  
  478. #ifdef NETCONN                          /* Network items */
  479.  
  480. #ifdef ANYX25
  481. extern int revcall, closgr, cudata, nx25;
  482. extern char udata[];
  483. extern struct keytab x25tab[];
  484. #ifndef IBMX25
  485. extern int npadx3;
  486. extern CHAR padparms[];
  487. extern struct keytab padx3tab[];
  488. #endif /* IBMX25 */
  489. #endif /* ANYX25 */
  490.  
  491. #ifdef OS2
  492. extern bool ttshare;
  493. #ifndef NT
  494. extern bool ttslip,ttppp;
  495. #endif /* NT */
  496. #endif /* OS2 */
  497. #ifdef NPIPE
  498. extern char pipename[];
  499. #endif /* NPIPE */
  500.  
  501. #ifdef TCPSOCKET
  502. static struct keytab tcprawtab[] = {    /* SET HOST options */
  503.     { "/default",    NP_DEFAULT,    CM_INV },
  504. #ifdef CK_AUTHENTICATION
  505. #ifdef CK_KERBEROS
  506. #ifdef RLOGCODE
  507.     { "/ek4login",    NP_EK4LOGIN,    0 },
  508.     { "/ek5login",    NP_EK5LOGIN,    0 },
  509.     { "/k4login",     NP_K4LOGIN,     0 },
  510.     { "/k5login",     NP_K5LOGIN,     0 },
  511. #endif /* RLOGCODE */
  512. #ifdef KRB5_U2U
  513.     { "/k5user2user", NP_K5U2U,       0 },
  514. #endif /* KRB5_U2U */
  515. #endif /* CK_KERBEROS */
  516. #endif /* CK_AUTHENTICATION */
  517.     { "/no-telnet-init", NP_NONE,   0 },
  518.     { "/none",       NP_NONE,   CM_INV },
  519.     { "/raw-socket", NP_TCPRAW, 0 },
  520. #ifdef RLOGCODE
  521.     { "/rlogin",     NP_RLOGIN, 0 },
  522. #endif /* RLOGCODE */
  523. #ifdef CK_SSL
  524.     { "/ssl",        NP_SSL,    0 },
  525.     { "/ssl-telnet", NP_SSL_TELNET, 0 },
  526. #endif /* CK_SSL */
  527.     { "/telnet",     NP_TELNET, 0 },
  528. #ifdef CK_SSL
  529.     { "/tls",        NP_TLS,    0 },
  530.     { "/tls-telnet", NP_TLS_TELNET, 0 },
  531. #endif /* CK_SSL */
  532.     { "", 0, 0 }
  533. };
  534. static int ntcpraw = (sizeof(tcprawtab) / sizeof(struct keytab)) - 1;
  535.  
  536. #ifdef RLOGCODE
  537. _PROTOTYP( int rlog_naws, (void) );
  538. #endif /* RLOGCODE */
  539. #endif /* TCPSOCKET */
  540.  
  541. #ifdef SUPERLAT
  542. extern char slat_pwd[18];
  543. #endif /* SUPERLAT */
  544. #endif /* NETCONN */
  545.  
  546. #ifdef COMMENT
  547. #ifndef NOSETKEY
  548. extern KEY *keymap;
  549. #ifndef OS2
  550. #define mapkey(x) keymap[x]
  551. #endif /* OS2 */
  552. extern MACRO *macrotab;
  553. #ifndef NOKVERBS
  554. extern struct keytab kverbs[];
  555. extern int nkverbs;
  556. #endif /* NOKVERBS */
  557. #endif /* NOSETKEY */
  558. #else
  559. #ifndef NOSETKEY
  560. extern KEY *keymap;
  561. extern MACRO *macrotab;
  562. #ifndef NOKVERBS
  563. extern struct keytab kverbs[];
  564. extern int nkverbs;
  565. #endif /* NOKVERBS */
  566. #endif /* NOSETKEY */
  567. #endif /* COMMENT */
  568.  
  569. #ifdef OS2                              /* AUTODOWNLOAD parameters */
  570. extern int    adl_kmode, adl_zmode;     /* Match Packet to signal download */
  571. extern char * adl_kstr;                 /* KERMIT Download String */
  572. extern char * adl_zstr;                 /* ZMODEM Download String */
  573. extern int adl_kc0, adl_zc0;            /* Process ADL C0s in emulation */
  574. #endif /* OS2 */
  575.  
  576. /* Keyword tables ... */
  577.  
  578. extern struct keytab onoff[], rltab[];
  579. extern int nrlt;
  580.  
  581. #ifndef NOCSETS
  582. static struct keytab fdfltab[] = {
  583.     { "7bit-character-set", 7, 0 },
  584.     { "8bit-character-set", 8, 0 }
  585. };
  586. static int nfdflt = (sizeof(fdfltab) / sizeof(struct keytab));
  587. #endif /* NOCSETS */
  588.  
  589. /* SET FILE parameters */
  590.  
  591. static struct keytab filtab[] = {
  592. #ifndef NOXFER
  593. #ifdef PATTERNS
  594.     { "binary-patterns",   XYFIBP,  0 },
  595. #endif /* PATTERNS */
  596.     { "bytesize",         XYFILS,   0 },
  597. #ifndef NOCSETS
  598.     { "character-set",    XYFILC,   0 },
  599. #endif /* NOCSETS */
  600.     { "collision",        XYFILX,   0 },
  601.     { "default",          XYF_DFLT, 0 },
  602.     { "destination",      XYFILY,   0 },
  603.     { "display",          XYFILD,   CM_INV },
  604. #ifdef CK_TMPDIR
  605.     { "download-directory", XYFILG, 0 },
  606. #endif /* CK_TMPDIR */
  607. #endif /* NOXFER */
  608.     { "end-of-line",      XYFILA,   0 },
  609.     { "eol",              XYFILA,   CM_INV },
  610. #ifdef CK_CTRLZ
  611.     { "eof",              XYFILV,   0 },
  612. #endif /* CK_CTRLZ */
  613. #ifndef NOXFER
  614.     { "fastlookups",      9997,     CM_INV },
  615.     { "incomplete",       XYFILI,   0 },
  616. #ifndef datageneral
  617.     { "inspection",       XYF_INSP, CM_INV },
  618. #endif /* datageneral */
  619. #ifdef CK_LABELED
  620.     { "label",            XYFILL, 0 },
  621. #endif /* CK_LABELED */
  622.  
  623. #ifdef UNIX
  624. #ifdef DYNAMIC
  625.     { "listsize",         XYF_LSIZ, 0 },
  626. #endif /* DYNAMIC */
  627. #endif /* UNIX */
  628.  
  629.     { "names",            XYFILN, 0 },
  630. #ifdef UNIX
  631.     { "output",           XYFILH, 0 },
  632. #endif /* UNIX */
  633. #ifdef PATTERNS
  634.     { "patterns",         XYFIPA, 0 },
  635. #endif /* PATTERNS */
  636. #ifdef COMMENT /* Not implemented (but see CHMOD) */
  637.     { "permissions",      XYF_PRM, CM_INV },
  638.     { "protection",       XYF_PRM, 0 },
  639. #endif /* COMMENt */
  640. #ifdef VMS
  641.     { "record-length",    XYFILR, 0 },
  642. #endif /* VMS */
  643. #ifndef datageneral
  644.     { "scan",             XYF_INSP, 0 },
  645. #endif /* datageneral */
  646.  
  647. #ifdef UNIX
  648. #ifdef DYNAMIC
  649.     { "stringspace",      XYF_SSPA, 0 },
  650. #endif /* DYNAMIC */
  651. #endif /* UNIX */
  652.  
  653. #ifdef PATTERNS
  654.     { "t",                XYFILT, CM_INV|CM_ABR },
  655.     { "text-patterns",    XYFITP, 0 },
  656. #endif /* PATTERNS */
  657. #endif /* NOXFER */
  658.     { "type",             XYFILT, 0 },
  659. #ifdef UNICODE
  660.     { "ucs",              XYFILU, 0 },
  661. #endif /* UNICODE */
  662. #ifndef NOXFER
  663.     { "warning",          XYFILW, CM_INV }
  664. #endif /* NOXFER */
  665. };
  666. static int nfilp = (sizeof(filtab) / sizeof(struct keytab));
  667.  
  668. struct keytab pathtab[] = {
  669.     { "absolute",  PATH_ABS,  0      },
  670.     { "none",      PATH_OFF,  CM_INV },
  671.     { "off",       PATH_OFF,  0      },
  672.     { "on",        PATH_ABS,  CM_INV },
  673.     { "relative",  PATH_REL,  0      }
  674. };
  675. int npathtab = (sizeof(pathtab) / sizeof(struct keytab));
  676.  
  677. struct keytab rpathtab[] = {
  678.     { "absolute",  PATH_ABS,  0      },
  679.     { "auto",      PATH_AUTO, 0      },
  680.     { "none",      PATH_OFF,  CM_INV },
  681.     { "off",       PATH_OFF,  0      },
  682.     { "on",        PATH_ABS,  CM_INV },
  683.     { "relative",  PATH_REL,  0      }
  684. };
  685. int nrpathtab = (sizeof(rpathtab) / sizeof(struct keytab));
  686.  
  687. #ifdef CK_CTRLZ
  688. struct keytab eoftab[] = {              /* EOF detection method */
  689.     { "ctrl-z",          1, 0      },
  690.     { "length",          0, 0      },
  691.     { "noctrl-z",        0, CM_INV }
  692. };
  693. #endif /* CK_CTRLZ */
  694.  
  695. struct keytab fttab[] = {               /* File types for SET FILE TYPE */
  696.     { "ascii",     XYFT_T, CM_INV },
  697. #ifdef VMS
  698.     { "b",         XYFT_B, CM_INV|CM_ABR },
  699. #endif /* VMS */
  700.     { "binary",    XYFT_B, 0 },
  701. #ifdef VMS
  702.     { "block",     XYFT_I, CM_INV },
  703.     { "image",     XYFT_I, 0 },
  704. #endif /* VMS */
  705. #ifdef CK_LABELED
  706.     { "labeled",   XYFT_L, 0 },
  707. #endif /* CK_LABELED */
  708. #ifdef MAC
  709.     { "macbinary", XYFT_M, 0 },
  710. #endif /* MAC */
  711.     { "text",      XYFT_T, 0 }
  712. };
  713. int nfttyp = (sizeof(fttab) / sizeof(struct keytab));
  714.  
  715. static struct keytab rfttab[] = {       /* File types for REMOTE SET FILE */
  716.     { "ascii",     XYFT_T, CM_INV },
  717.     { "binary",    XYFT_B, 0 },
  718. #ifdef VMS
  719.     { "labeled",   XYFT_L, 0 },
  720. #else
  721. #ifdef OS2
  722.     { "labeled",   XYFT_L, 0 },
  723. #endif /* OS2 */
  724. #endif /* VMS */
  725.     { "text",      XYFT_T, 0 }
  726. };
  727. static int nrfttyp = (sizeof(rfttab) / sizeof(struct keytab));
  728.  
  729. #ifdef OS2ORUNIX
  730. #define ZOF_BLK  0
  731. #define ZOF_NBLK 1
  732. #define ZOF_BUF  2
  733. #define ZOF_NBUF 3
  734. static struct keytab zoftab[] = {
  735.     { "blocking",    ZOF_BLK,  0 },
  736.     { "buffered",    ZOF_BUF,  0 },
  737.     { "nonblocking", ZOF_NBLK, 0 },
  738.     { "unbuffered",  ZOF_NBUF, 0 }
  739. };
  740. static int nzoftab = (sizeof(zoftab) / sizeof(struct keytab));
  741. #endif /* OS2ORUNIX */
  742.  
  743. extern int query;                       /* Global flag for QUERY active */
  744.  
  745. #ifndef NOSPL
  746. #ifndef NOXFER
  747. static struct keytab vartyp[] = {       /* Variable types for REMOTE QUERY */
  748.     { "global",   (int) 'G', CM_INV },
  749.     { "kermit",   (int) 'K', 0 },
  750.     { "system",   (int) 'S', 0 },
  751.     { "user",     (int) 'G', 0 }
  752. };
  753. static int nvartyp = (sizeof(vartyp) / sizeof(struct keytab));
  754. #endif /* NOXFER */
  755. #endif /* NOSPL */
  756.  
  757. #ifdef CK_TIMERS
  758. static struct keytab timotab[] = {      /* Timer types */
  759.     { "dynamic", 1, 0 },
  760.     { "fixed",   0, 0 }
  761. };
  762. #endif /* CK_TIMERS */
  763.  
  764. #ifdef DCMDBUF
  765. extern char *atxbuf, *atmbuf;           /* Atom buffer */
  766. extern char *cmdbuf;                    /* Command buffer */
  767. extern char *line, *tmpbuf;             /* Character buffers for anything */
  768. extern int *intime;                     /* INPUT TIMEOUT */
  769.  
  770. #else  /* Not DCMDBUF ... */
  771.  
  772. extern char atxbuf[], atmbuf[];         /* Atom buffer */
  773. extern char cmdbuf[];                   /* Command buffer */
  774. extern char line[], tmpbuf[];           /* Character buffer for anything */
  775. extern int intime[];
  776.  
  777. #endif /* DCMDBUF */
  778.  
  779. #ifndef NOCSETS
  780. extern struct keytab fcstab[];          /* For SET FILE CHARACTER-SET */
  781. extern struct csinfo fcsinfo[];         /* File character set info. */
  782. extern struct keytab ttcstab[];
  783. extern int nfilc, fcharset, tcharset, ntermc, tcsr, tcsl, dcset7, dcset8;
  784. #ifdef CKOUNI
  785. extern int tt_utf8;
  786. #endif /* CKOUNI */
  787. #ifdef OS2
  788. _PROTOTYP( int os2setcp, (int) );
  789. _PROTOTYP( int os2getcp, (void) );
  790. _PROTOTYP( void os2debugoff, (void) );
  791. #endif /* OS2 */
  792. #endif /* NOCSETS */
  793.  
  794. extern int cmdlvl;                      /* Overall command level */
  795.  
  796. #ifndef NOSPL
  797. #ifdef DCMDBUF
  798. extern int *inpcas;                     /* INPUT CASE setting on cmd stack */
  799. #else
  800. extern int inpcas[];
  801. #endif /* DCMDBUF */
  802. #endif /* NOSPL */
  803.  
  804. #ifdef CK_CURSES
  805. #ifndef VMS
  806. _PROTOTYP(int tgetent,(char *, char *));
  807. #else
  808. #ifdef __DECC
  809. _PROTOTYP(int tgetent,(char *, char *));
  810. #endif /* __DECC */
  811. #endif /* VMS */
  812. #endif /* CK_CURSES */
  813.  
  814. #ifndef NOXMIT
  815. #define XMITF 0                         /* SET TRANSMIT values */
  816. #define XMITL 1                         /* (Local to this module) */
  817. #define XMITP 2
  818. #define XMITE 3
  819. #define XMITX 4
  820. #define XMITS 5
  821. #define XMITW 6
  822. #define XMITT 7
  823.  
  824. #define XMBUFL 50
  825. extern int xmitf, xmitl, xmitp, xmitx, xmits, xmitw, xmitt;
  826. char xmitbuf[XMBUFL+1] = { NUL };       /* TRANSMIT eof string */
  827.  
  828. struct keytab xmitab[] = {              /* SET TRANSMIT */
  829.     { "echo",          XMITX, 0 },
  830.     { "eof",           XMITE, 0 },
  831.     { "fill",          XMITF, 0 },
  832.     { "linefeed",      XMITL, 0 },
  833.     { "locking-shift", XMITS, 0 },
  834.     { "pause",         XMITW, 0 },
  835.     { "prompt",        XMITP, 0 },
  836.     { "timeout",       XMITT, 0 }
  837. };
  838. int nxmit = (sizeof(xmitab) / sizeof(struct keytab));
  839. #endif /* NOXMIT */
  840.  
  841. /* For SET FILE COLLISION */
  842. /* Some of the following may be possible for some C-Kermit implementations */
  843. /* but not others.  Those that are not possible for your implementation */
  844. /* should be ifdef'd out. */
  845.  
  846. struct keytab colxtab[] = { /* SET FILE COLLISION options */
  847. #ifndef MAC
  848.     { "append",    XYFX_A, 0 },         /* append to old file */
  849. #endif /* MAC */
  850. #ifdef COMMENT
  851.     { "ask",       XYFX_Q, 0 },         /* ask what to do (not implemented) */
  852. #endif
  853.     { "backup",    XYFX_B, 0 },         /* rename old file */
  854. #ifndef MAC
  855.     /* This crashes Mac Kermit. */
  856.     { "discard",   XYFX_D, 0 },         /* don't accept new file */
  857.     { "no-supersede", XYFX_D, CM_INV }, /* ditto (MSK compatibility) */
  858. #endif /* MAC */
  859.     { "overwrite", XYFX_X, 0 },         /* overwrite the old file */
  860.     { "rename",    XYFX_R, 0 },         /* rename the incoming file */
  861. #ifndef MAC                             /* This crashes Mac Kermit. */
  862.     { "update",    XYFX_U, 0 },         /* replace if newer */
  863. #endif /* MAC */
  864.     { "", 0, 0 }
  865. };
  866. int ncolx = (sizeof(colxtab) / sizeof(struct keytab)) - 1;
  867.  
  868. static struct keytab rfiltab[] = {      /* for REMOTE SET FILE */
  869. #ifndef NOCSETS
  870.     { "character-set", XYFILC, 0 },
  871. #endif /* NOCSETS */
  872.     { "collision",     XYFILX, 0 },
  873.     { "incomplete",    XYFILI, 0 },
  874.     { "names",         XYFILN, 0 },
  875.     { "record-length", XYFILR, 0 },
  876.     { "type",          XYFILT, 0 }
  877. };
  878. int nrfilp = (sizeof(rfiltab) / sizeof(struct keytab));
  879.  
  880. struct keytab eoltab[] = {              /* File eof delimiters */
  881.     { "cr",        XYFA_C, 0 },
  882.     { "crlf",      XYFA_2, 0 },
  883.     { "lf",        XYFA_L, 0 }
  884. };
  885. static int neoltab = (sizeof(eoltab) / sizeof(struct keytab));
  886.  
  887. struct keytab fntab[] = {               /* File naming */
  888.     { "converted", XYFN_C, 0      },
  889.     { "literal",   XYFN_L, 0      },
  890.     { "standard",  XYFN_C, CM_INV }
  891. };
  892. int nfntab = (sizeof(fntab) / sizeof(struct keytab));
  893.  
  894. #ifndef NOLOCAL
  895. /* Terminal parameters table */
  896. static struct keytab trmtab[] = {
  897. #ifdef OS2
  898.     { "answerback",    XYTANS,    0 },
  899. #endif /* OS2 */
  900. #ifdef CK_APC
  901.     { "apc",           XYTAPC,    0 },
  902. #endif /* CK_APC */
  903. #ifdef OS2
  904.     { "arrow-keys",    XYTARR,    0 },
  905. #endif /* OS2 */
  906. #ifdef NT
  907.     { "at",            XYTATTR,   CM_INV|CM_ABR },
  908.     { "att",           XYTATTR,   CM_INV|CM_ABR },
  909.     { "attr",          XYTATTR,   CM_INV|CM_ABR },
  910.     { "attr-bug",      XYTATTBUG, CM_INV },
  911. #endif /* NT */
  912. #ifdef OS2
  913.     { "attribute",     XYTATTR,   0 },
  914. #endif /* OS2 */
  915. #ifdef CK_APC
  916. #ifdef CK_AUTODL
  917.    { "autodownload",   XYTAUTODL, 0, },
  918. #endif /* CK_AUTODL */
  919. #endif /* CK_APC */
  920. #ifdef OS2
  921.     { "autopage",      XYTAPAGE,  0 },
  922.     { "autoscroll",    XYTASCRL,  0 },
  923.     { "bell",          XYTBEL,    CM_INV },
  924. #endif /* OS2 */
  925.     { "bytesize",      XYTBYT,    0 },
  926. #ifndef NOCSETS
  927.     { "character-set", XYTCS,     0 },
  928. #endif /* NOCSETS */
  929. #ifdef OS2
  930.     { "code-page",     XYTCPG,    0 },
  931.     { "color",         XYTCOL,    0 },
  932.     { "controls",      XYTCTRL,   0 },
  933. #endif /* OS2 */
  934.     { "cr-display",    XYTCRD,    0 },
  935. #ifdef OS2
  936.     { "cursor",        XYTCUR,    0 },
  937. #endif /* OS2 */
  938.     { "debug",         XYTDEB,    0 },
  939. #ifdef OS2
  940.     { "dg-unix-mode",  XYTUNX,    0 },
  941. #endif /* OS2 */
  942.     { "echo",          XYTEC,     0 },
  943.     { "escape-character", XYTESC, 0 },
  944. #ifdef OS2
  945. #ifdef PCFONTS
  946.     { "font",          XYTFON,    0 },
  947. #else
  948. #ifdef KUI
  949.     { "font",          XYTFON,    0 },
  950. #endif /* KUI */
  951. #endif /* PCFONTS */
  952. #endif /* OS2 */
  953.     { "height",        XYTHIG,    0 },
  954. #ifdef CKTIDLE
  955.     { "idle-action",   XYTIACT,   0 },
  956.     { "idle-limit",    XYTITMO,   CM_INV },
  957.     { "idle-send",     XYTIDLE,   CM_INV },
  958.     { "idle-timeout",  XYTITMO,   0 },
  959. #endif /* CKTIDLE */
  960. #ifdef OS2
  961. #ifndef NOCSETS
  962.     { "kbd-follows-gl/gr", XYTKBDGL, 0 },
  963. #endif /* NOCSETS */
  964.     { "key",           XYTKEY,    0 },
  965.     { "keyboard-mode", XYTKBMOD,  0 },
  966.     { "keypad-mode",   XYTKPD,    0 },
  967. #endif /* OS2 */
  968. #ifndef NOCSETS
  969. #ifdef OS2
  970. #ifndef KUI
  971.     { "local-character-set", XYTLCS,  0 },
  972. #else
  973.     { "local-character-set", XYTLCS,  CM_INV },
  974. #endif /* KUI */
  975. #else
  976.     { "local-character-set", XYTLCS,  CM_INV },
  977. #endif /* OS2 */
  978. #endif /* NOCSETS */
  979.     { "locking-shift", XYTSO,     0 },
  980. #ifdef OS2
  981.     { "margin-bell",   XYTMBEL,   0 },
  982. #endif /* OS2 */
  983. #ifdef OS2MOUSE
  984.     { "mouse",         XYTMOU,    CM_INV },
  985. #endif /* OS2MOUSE */
  986.     { "newline-mode",  XYTNL,     0 },
  987. #ifdef OS2
  988.     { "output-pacing", XYTPAC,    0 },
  989. #ifdef PCTERM
  990.     { "pcterm",        XYTPCTERM, 0 },
  991. #endif /* PCTERM */
  992. #endif /* OS2 */
  993. #ifdef OS2ORUNIX
  994.     { "print",         XYTPRN,    0 },
  995. #endif /* OS2ORUNIX */
  996. #ifndef NOCSETS
  997. #ifdef OS2
  998.     { "remote-character-set", XYTRCS,  0 },
  999. #else
  1000.     { "remote-character-set", XYTRCS,  CM_INV },
  1001. #endif /* OS2 */
  1002. #endif /* NOCSETS */
  1003. #ifdef OS2
  1004.     { "roll-mode",       XYTROL, 0 },
  1005.     { "s",               XYTUPD, CM_ABR|CM_INV },
  1006.     { "sc",              XYTUPD, CM_ABR|CM_INV },
  1007.     { "scr",             XYTUPD, CM_ABR|CM_INV },
  1008.     { "scree",           XYTUPD, CM_ABR|CM_INV },
  1009.     { "screen",          XYTUPD, CM_ABR|CM_INV },
  1010.     { "screen-",         XYTUPD, CM_ABR|CM_INV },
  1011.     { "screen-mode",     XYTSCNM,   0 },
  1012.     { "screen-optimize", XYTOPTI,   0 },
  1013.     { "screen-update",   XYTUPD,    0 },
  1014.     { "scrollback",      XYSCRS,    0 },
  1015.     { "send-data",         XYTSEND, 0 },
  1016.     { "send-end-of-block", XYTSEOB, 0 },
  1017.     { "sgr-colors",            XYTSGRC,  0 },
  1018.     { "sni-ch.code",           XYTSNICC, 0 },
  1019.     { "sni-firmware-versions", XYTSNIFV, 0 },
  1020.     { "sni-language",          XYTVTLNG, 0 },
  1021.     { "sni-pagemode",          XYTSNIPM, CM_INV },
  1022.     { "sni-scrollmode",              XYTSNISM, CM_INV },
  1023.     { "spacing-attribute-character", XYTSAC,   CM_INV },
  1024.     { "statusline",                  XYTSTAT,  0 },
  1025.     { "tra",                         XYTCTS,   CM_INV|CM_ABR },
  1026.     { "transmit-timeout",            XYTCTS,   0 },
  1027. #endif /* OS2 */
  1028.  
  1029. #ifdef OS2ORUNIX
  1030.     { "transparent-print", XYTPRN,   CM_INV },
  1031. #endif /* OS2ORUNIX */
  1032.  
  1033. #ifdef CK_TRIGGER
  1034.     { "trigger",           XYTRIGGER,0 },
  1035. #endif /* CK_TRIGGER */
  1036. #ifdef OS2
  1037.     { "type",              XYTTYP,   0 },
  1038. #else
  1039.     { "type",              XYTTYP,   CM_INV },
  1040. #endif /* OS2 */
  1041.  
  1042. #ifndef NOCSETS
  1043. #ifdef UNICODE
  1044. #ifdef CKOUNI
  1045.     { "unicode",           XYTUNI,   CM_INV },
  1046. #endif /* CKOUNI */
  1047. #endif /* UNICODE */
  1048. #endif /* NOCSETS */
  1049. #ifdef OS2
  1050.     { "unix-mode",         XYTUNX,   CM_INV },
  1051.     { "url-highlight",     XYTURLHI, 0 },
  1052. #ifdef NT
  1053.     { "video-change",      XYTVCH,   0 },
  1054. #endif /* NT */
  1055.     { "vt-language",       XYTVTLNG, 0 },
  1056.     { "vt-nrc-mode",       XYTVTNRC, 0 },
  1057. #endif /* OS2 */
  1058.     { "width",             XYTWID,   0 },
  1059. #ifdef OS2
  1060.     { "wrap",              XYTWRP,   0 },
  1061. #endif /* OS2 */
  1062.     { "", 0, 0 }
  1063. };
  1064. int ntrm = (sizeof(trmtab) / sizeof(struct keytab)) - 1;
  1065.  
  1066. #ifdef OS2
  1067. struct keytab termctrl[] = {    /* SET TERM CONTROLS */
  1068.     { "7",      7, 0 },
  1069.     { "8",      8, 0 }
  1070. };
  1071. int ntermctrl = (sizeof(termctrl) / sizeof(struct keytab));
  1072.  
  1073. struct keytab rolltab[] = {   /* Set TERM Roll Options */
  1074.     { "insert",    TTR_INSERT, 0      },
  1075.     { "keystrokes",TTR_KEYS,   0      },
  1076.     { "off",       TTR_OVER,   CM_INV },
  1077.     { "on",        TTR_INSERT, CM_INV },
  1078.     { "overwrite", TTR_OVER,   0      }
  1079. };
  1080. int nroll = (sizeof(rolltab) / sizeof(struct keytab));
  1081.  
  1082. struct keytab rollkeytab[] = {        /* Set TERM ROLL KEYSTROKES */
  1083.     { "ignore",            TTRK_IGN, 0 },
  1084.     { "restore-and-send",  TTRK_RST, 0 },
  1085.     { "send",              TTRK_SND, 0 }
  1086. };
  1087. int nrollkey = (sizeof(rollkeytab) / sizeof(struct keytab));
  1088.  
  1089. #define TT_GR_ALL 4
  1090. #define TT_GR_G0  0
  1091. #define TT_GR_G1  1
  1092. #define TT_GR_G2  2
  1093. #define TT_GR_G3  3
  1094. #define TT_GR_KBD 4
  1095. struct keytab graphsettab[] = {  /* DEC VT Graphic Sets */
  1096.     { "all",      TT_GR_ALL, 0 },
  1097.     { "g0",       TT_GR_G0,  0 },
  1098.     { "g1",       TT_GR_G1,  0 },
  1099.     { "g2",       TT_GR_G2,  0 },
  1100.     { "g3",       TT_GR_G3,  0 },
  1101.     { "keyboard", TT_GR_KBD, 0 }
  1102. };
  1103. int ngraphset = (sizeof(graphsettab) / sizeof(struct keytab));
  1104. #endif /* OS2 */
  1105.  
  1106. struct keytab adltab[] = {              /* Autodownload Options */
  1107.     { "ask",     TAD_ASK, 0 },
  1108.     { "error",   TAD_ERR, 0 },
  1109. #ifdef OS2
  1110.     { "kermit",  TAD_K,   0 },
  1111. #endif /* OS2 */
  1112.     { "off",     TAD_OFF, 0 },
  1113.     { "on",      TAD_ON,  0 },
  1114. #ifdef OS2
  1115.     { "zmodem",  TAD_Z,   0 },
  1116. #endif /* OS2 */
  1117.     { "", 0, 0 }
  1118. };
  1119. int nadltab = (sizeof(adltab) / sizeof(struct keytab)) - 1;
  1120.  
  1121. struct keytab adlerrtab[] = {           /* Autodownload Error Options */
  1122.     { "continue", 0, 0 },
  1123.     { "go",       0, CM_INV },
  1124.     { "stop",     1, 0 }
  1125. };
  1126. int nadlerrtab = (sizeof(adlerrtab) / sizeof(struct keytab));
  1127.  
  1128. #ifdef OS2
  1129. struct keytab adlxtab[] = {             /* Autodownload Options */
  1130.     { "c0-conflicts",     TAD_X_C0,     0 },
  1131.     { "detection-method", TAD_X_DETECT, 0 },
  1132.     { "string",           TAD_X_STR,    0 }
  1133. };
  1134. int nadlxtab = (sizeof(adlxtab) / sizeof(struct keytab));
  1135.  
  1136. struct keytab adldtab[] = {             /* Auto-dl Detection Methods */
  1137.     { "packet",           ADL_PACK,     0 },
  1138.     { "string",           ADL_STR,      0 }
  1139. };
  1140. int nadldtab = (sizeof(adldtab) / sizeof(struct keytab));
  1141.  
  1142. struct keytab adlc0tab[] = {            /* Auto-dl Detection Methods */
  1143.     { "ignored-by-emulator",    0,      0 },
  1144.     { "processed-by-emulator",  1,      0 }
  1145. };
  1146. int nadlc0tab = (sizeof(adlc0tab) / sizeof(struct keytab));
  1147.  
  1148. #ifndef NOCSETS
  1149. struct keytab vtlangtab[] = {
  1150.     { "belgian",        VTL_BELGIAN , 0 },
  1151.     { "british",        VTL_BRITISH , 0 },
  1152.     { "canadian",       VTL_CANADIAN, 0 },
  1153.     { "czech",          VTL_CZECH   , 0 },
  1154.     { "danish",         VTL_DANISH  , 0 },
  1155.     { "dutch",          VTL_DUTCH   , 0 },
  1156.     { "finnish",        VTL_FINNISH , 0 },
  1157.     { "french",         VTL_FRENCH  , 0 },
  1158.     { "french-canadian",VTL_FR_CAN  , 0 },
  1159.     { "german",         VTL_GERMAN  , 0 },
  1160.     { "greek",          VTL_GREEK   , 0 },
  1161.     { "hebrew",         VTL_HEBREW  , 0 },
  1162.     { "hungarian",      VTL_HUNGARIA, 0 },
  1163.     { "italian",        VTL_ITALIAN , 0 },
  1164.     { "latin-american", VTL_LATIN_AM, 0 },
  1165.     { "north-american", VTL_NORTH_AM, 0 },
  1166.     { "norwegian",      VTL_NORWEGIA, 0 },
  1167.     { "polish",         VTL_POLISH  , 0 },
  1168.     { "portugese",      VTL_PORTUGES, 0 },
  1169.     { "romanian",       VTL_ROMANIAN, 0 },
  1170.     { "russian",        VTL_RUSSIAN , 0 },
  1171.     { "scs",            VTL_SCS     , CM_INV },
  1172.     { "slovak",         VTL_SLOVAK  , 0 },
  1173.     { "spanish",        VTL_SPANISH , 0 },
  1174.     { "swedish",        VTL_SWEDISH , 0 },
  1175.     { "swiss-french",   VTL_SW_FR   , 0 },
  1176.     { "swiss-german",   VTL_SW_GR   , 0 },
  1177.     { "turkish-f",      VTL_TURK_F  , CM_INV },
  1178.     { "turkish-q",      VTL_TURK_Q  , CM_INV }
  1179. };
  1180. int nvtlangtab = (sizeof(vtlangtab) / sizeof(struct keytab));
  1181. #endif /* NOCSETS */
  1182. #endif /* OS2 */
  1183.  
  1184. struct keytab crdtab[] = {              /* Carriage-return display */
  1185.     { "crlf",        1, 0 },
  1186.     { "normal",      0, 0 }
  1187. };
  1188. extern int tt_crd;                      /* Carriage-return display variable */
  1189.  
  1190. #ifdef CK_APC
  1191. extern int apcstatus, apcactive;
  1192. static struct keytab apctab[] = {       /* Terminal APC parameters */
  1193.     {  "no-input", APC_ON|APC_NOINP,0 },
  1194.     { "off",       APC_OFF,  0 },
  1195.     { "on",        APC_ON,   0 },
  1196.     { "unchecked", APC_ON|APC_UNCH, 0 },
  1197.     { "unchecked-no-input", APC_ON|APC_NOINP|APC_UNCH, 0 }
  1198. };
  1199. int napctab = (sizeof(apctab) / sizeof(struct keytab));
  1200. #endif /* CK_APC */
  1201. #endif /* NOLOCAL */
  1202.  
  1203. extern int autodl, adl_err, adl_ask;
  1204.  
  1205. struct keytab beltab[] = {              /* Terminal bell mode */
  1206. #ifdef OS2
  1207.     { "audible", XYB_AUD,  0 },
  1208.     { "none",    XYB_NONE, 0 },
  1209. #else
  1210.     { "audible", XYB_AUD,  CM_INV },
  1211.     { "none",    XYB_NONE, CM_INV },
  1212. #endif /* OS2 */
  1213. #ifdef OS2
  1214.     { "off",     XYB_NONE, CM_INV },
  1215.     { "on",      XYB_AUD,  CM_INV },
  1216. #else
  1217.     { "off",     XYB_NONE, 0 },
  1218.     { "on",      XYB_AUD,  0 },
  1219. #endif /* OS2 */
  1220. #ifdef OS2
  1221.     { "visible", XYB_VIS,  0 },
  1222. #endif /* OS2 */
  1223.     { "", 0, 0 }
  1224. };
  1225. int nbeltab = sizeof(beltab)/sizeof(struct keytab) - 1;
  1226.  
  1227. int tt_unicode = 1;                     /* Use Unicode if possible */
  1228. #ifdef CKTIDLE
  1229. int tt_idlesnd_tmo = 0;                 /* Idle Send Timeout, disabled */
  1230. char * tt_idlesnd_str = NULL;           /* Idle Send String, none */
  1231. char * tt_idlestr = NULL;
  1232. extern int tt_idleact, tt_idlelimit;
  1233. #endif /* CKTIDLE */
  1234.  
  1235. #ifdef OS2
  1236. #ifndef NOLOCAL
  1237. /*
  1238.   OS/2 serial communication devices.
  1239. */
  1240. struct keytab os2devtab[] = {
  1241.     { "1",    1, CM_INV },                      /* Invisible synonyms, like */
  1242.     { "2",    2, CM_INV },                      /* "set port 1" */
  1243.     { "3",    3, CM_INV },
  1244.     { "4",    4, CM_INV },
  1245.     { "5",    5, CM_INV },
  1246.     { "6",    6, CM_INV },
  1247.     { "7",    7, CM_INV },
  1248.     { "8",    8, CM_INV },
  1249.     { "com1", 1, 0 },                   /* Real device names */
  1250.     { "com2", 2, 0 },
  1251.     { "com3", 3, 0 },
  1252.     { "com4", 4, 0 },
  1253.     { "com5", 5, 0 },
  1254.     { "com6", 6, 0 },
  1255.     { "com7", 7, 0 },
  1256.     { "com8", 8, 0 },
  1257. #ifdef OS2ONLY
  1258.     { "slipcom1", 1, 0 },                       /* For use with SLIP driver */
  1259.     { "slipcom2", 2, 0 },                       /* shared access */
  1260.     { "slipcom3", 3, 0 },
  1261.     { "slipcom4", 4, 0 },
  1262.     { "slipcom5", 5, 0 },
  1263.     { "slipcom6", 6, 0 },
  1264.     { "slipcom7", 7, 0 },
  1265.     { "slipcom8", 8, 0 },
  1266.     { "pppcom1", 1, 0 },                        /* For use with PPP driver */
  1267.     { "pppcom2", 2, 0 },                        /* shared access */
  1268.     { "pppcom3", 3, 0 },
  1269.     { "pppcom4", 4, 0 },
  1270.     { "pppcom5", 5, 0 },
  1271.     { "pppcom6", 6, 0 },
  1272.     { "pppcom7", 7, 0 },
  1273.     { "pppcom8", 8, 0 }
  1274. #endif /* OS2ONLY */
  1275. };
  1276. int nos2dev = (sizeof(os2devtab) / sizeof(struct keytab)) - 1;
  1277.  
  1278. #ifdef OS2ONLY
  1279. struct keytab os2ppptab[] = {
  1280.     { "0",    0, CM_INV },
  1281.     { "1",    1, CM_INV },                      /* Invisible synonyms, like */
  1282.     { "2",    2, CM_INV },                      /* "set port 1" */
  1283.     { "3",    3, CM_INV },
  1284.     { "4",    4, CM_INV },
  1285.     { "5",    5, CM_INV },
  1286.     { "6",    6, CM_INV },
  1287.     { "7",    7, CM_INV },
  1288.     { "8",    8, CM_INV },
  1289.     { "9",    9, CM_INV },
  1290.     { "ppp0", 0, 0 },
  1291.     { "ppp1", 1, 0 },                   /* For use with PPP driver */
  1292.     { "ppp2", 2, 0 },                   /* shared access */
  1293.     { "ppp3", 3, 0 },
  1294.     { "ppp4", 4, 0 },
  1295.     { "ppp5", 5, 0 },
  1296.     { "ppp6", 6, 0 },
  1297.     { "ppp7", 7, 0 },
  1298.     { "ppp8", 8, 0 },
  1299.     { "ppp9", 9, 0 }
  1300. };
  1301. int nos2ppp = (sizeof(os2ppptab) / sizeof(struct keytab));
  1302. #endif /* OS2ONLY */
  1303.  
  1304. /*
  1305.   Terminal parameters that can be set by SET commands.
  1306.   Used by the ck?con.c terminal emulator code.
  1307.   For now, only used for #ifdef OS2.  Should add these for Macintosh.
  1308. */
  1309. int tt_arrow = TTK_NORM;                /* Arrow key mode: normal (cursor) */
  1310. int tt_keypad = TTK_NORM;               /* Keypad mode: normal (numeric) */
  1311. int tt_shift_keypad = 0;                /* Keypad Shift mode: Off */
  1312. int tt_wrap = 1;                        /* Terminal wrap, 1 = On */
  1313. int tt_type = TT_VT320;                 /* Terminal type, initially VT320 */
  1314. int tt_type_mode = TT_VT320;            /* Terminal type set by host command */
  1315. int tt_cursor = 0;                      /* Terminal cursor, 0 = Underline */
  1316. int tt_cursor_usr = 0;                  /* Users Terminal cursor type */
  1317. int tt_cursorena_usr = 1;               /* Users Terminal cursor enabled */
  1318. int tt_answer = 0;                      /* Terminal answerback (disabled) */
  1319. int tt_scrsize[VNUM] = {512,512,512,1}; /* Terminal scrollback buffer size */
  1320. int tt_roll[VNUM] = {1,1,1,1};          /* Terminal roll (on) */
  1321. int tt_rkeys[VNUM] = {1,1,1,1};        /* Terminal roll keys (send) */
  1322. int tt_pacing = 0;                      /* Terminal output-pacing (none) */
  1323. int tt_ctstmo = 15;                     /* Terminal transmit-timeout */
  1324. int tt_codepage = -1;                   /* Terminal code-page */
  1325. int tt_update = 100;                    /* Terminal screen-update interval */
  1326. int tt_updmode = TTU_FAST;              /* Terminal screen-update mode FAST */
  1327. extern int updmode;
  1328. #ifndef KUI
  1329. int tt_status[VNUM] = {1,1,0,0};        /* Terminal status line displayed */
  1330. int tt_status_usr[VNUM] = {1,1,0,0};
  1331. #else  /* KUI */
  1332. #ifdef K95G
  1333. int tt_status[VNUM] = {1,1,0,0};        /* Terminal status line displayed */
  1334. int tt_status_usr[VNUM] = {1,1,0,0};
  1335. #else /* K95G */
  1336. int tt_status[VNUM] = {0,0,0,0};        /* Terminal status line displayed */
  1337. int tt_status_usr[VNUM] = {0,0,0,0};
  1338. #endif /* K95G */
  1339. #endif /* KUI */
  1340. int tt_senddata = 0;                    /* Let host read terminal data */
  1341. extern int wy_blockend;                 /* Terminal Send Data EOB type */
  1342. int tt_hidattr = 1;                     /* Attributes are hidden */
  1343.  
  1344. extern unsigned char colornormal, colorselect,
  1345. colorunderline, colorstatus, colorhelp, colorborder,
  1346. colorgraphic, colordebug, colorreverse, coloritalic;
  1347.  
  1348. extern int trueblink, trueunderline, truereverse, trueitalic, truedim;
  1349.  
  1350. extern int bgi, fgi;
  1351. extern int scrninitialized[];
  1352.  
  1353. struct keytab audibletab[] = {          /* Terminal Bell Audible mode */
  1354.     { "beep",          XYB_BEEP, 0 },   /* Values ORd with bell mode */
  1355.     { "system-sounds", XYB_SYS,  0 }
  1356. };
  1357. int naudibletab = sizeof(audibletab)/sizeof(struct keytab);
  1358.  
  1359. struct keytab akmtab[] = {              /* Arrow key mode */
  1360.     { "application", TTK_APPL, 0 },
  1361.     { "cursor",      TTK_NORM, 0 }
  1362. };
  1363. struct keytab kpmtab[] = {              /* Keypad mode */
  1364.     { "application", TTK_APPL, 0 },
  1365.     { "numeric",     TTK_NORM, 0 }
  1366. };
  1367.  
  1368. struct keytab ttcolmodetab[] = {
  1369.     { "current-color", 0, 0 },
  1370.     { "default-color", 1, 0 }
  1371. };
  1372. int ncolmode = sizeof(ttcolmodetab)/sizeof(struct keytab);
  1373.  
  1374. #define TTCOLNOR  0
  1375. #define TTCOLREV  1
  1376. #define TTCOLUND  2
  1377. #define TTCOLSTA  3
  1378. #define TTCOLHLP  4
  1379. #define TTCOLBOR  5
  1380. #define TTCOLSEL  6
  1381. #define TTCOLDEB  7
  1382. #define TTCOLGRP  8
  1383. #define TTCOLITA  9
  1384. #define TTCOLRES  10
  1385. #define TTCOLERA  11
  1386.  
  1387. struct keytab ttycoltab[] = {                   /* Terminal Screen coloring */
  1388.     { "border",             TTCOLBOR, 0 },      /* Screen border color */
  1389.     { "debug-terminal",     TTCOLDEB, 0 },      /* Debug color */
  1390.     { "erase",              TTCOLERA, 0 },      /* Erase mode */
  1391.     { "graphic",            TTCOLGRP, 0 },      /* Graphic Color */
  1392.     { "help-text",          TTCOLHLP, 0 },      /* Help screens */
  1393.     { "italic",             TTCOLITA, 0 },      /* Italic Color */
  1394.     { "normal",             TTCOLNOR, CM_INV }, /* Normal screen text */
  1395.     { "reset-on-esc[0m",    TTCOLRES, 0 },      /* Reset on ESC [ 0 m */
  1396.     { "reverse-video",      TTCOLREV, 0 },      /* Reverse video */
  1397.     { "status-line",        TTCOLSTA, 0 },      /* Status line */
  1398.     { "selection",          TTCOLSEL, 0 },      /* Selection color */
  1399.     { "terminal-screen",    TTCOLNOR, 0 },      /* Better name than "normal" */
  1400.     { "underlined-text",    TTCOLUND, 0 }       /* Underlined text */
  1401. };
  1402. int ncolors = (sizeof(ttycoltab) / sizeof(struct keytab));
  1403.  
  1404. #define TTATTNOR  0
  1405. #define TTATTBLI  1
  1406. #define TTATTREV  2
  1407. #define TTATTUND  3
  1408. #define TTATTPRO  4
  1409. #define TTATTBLD  5
  1410. #define TTATTDIM  6
  1411. #define TTATTINV  7
  1412. #define TTATTITA  8
  1413. #define TTATTDONE 9
  1414.  
  1415. struct keytab ttyattrtab[] = {
  1416.     { "blink",     TTATTBLI, 0 },
  1417.     { "dim",       TTATTDIM, 0 },
  1418.     { "italic",    TTATTITA, 0 },
  1419.     { "protected", TTATTPRO, 0 },
  1420.     { "reverse",   TTATTREV, 0 },
  1421.     { "underline", TTATTUND, 0 }
  1422. };
  1423. int nattrib = (sizeof(ttyattrtab) / sizeof(struct keytab));
  1424.  
  1425. struct keytab ttyprotab[] = {
  1426.     { "blink",       TTATTBLI,  0 },
  1427.     { "bold",        TTATTBLD,  0 },
  1428.     { "dim",         TTATTDIM,  0 },
  1429.     { "done",        TTATTDONE, CM_INV },
  1430.     { "invisible",   TTATTINV,  0 },
  1431.     { "italic",      TTATTITA,  0 },
  1432.     { "normal",      TTATTNOR,  0 },
  1433.     { "reverse",     TTATTREV,  0 },
  1434.     { "underlined",  TTATTUND,  0 }
  1435.  
  1436. };
  1437. int nprotect = (sizeof(ttyprotab) / sizeof(struct keytab));
  1438.  
  1439. struct keytab ttyseobtab[] = {
  1440.     { "crlf_etx",  1, 0 },
  1441.     { "us_cr",     0, 0 }
  1442. };
  1443.  
  1444. struct keytab ttyclrtab[] = {           /* Colors */
  1445.     { "black",         0, 0      },
  1446.     { "blue",          1, 0      },
  1447.     { "brown",         6, 0      },
  1448.     { "cyan",          3, 0      },
  1449.     { "darkgray",      8, CM_INV },
  1450.     { "dgray",         8, 0      },
  1451.     { "green",         2, 0      },
  1452.     { "lblue",         9, CM_INV },
  1453.     { "lcyan",        11, CM_INV },
  1454.     { "lgray",         7, CM_INV },
  1455.     { "lgreen",       10, CM_INV },
  1456.     { "lightblue",     9, 0      },
  1457.     { "lightcyan",    11, 0      },
  1458.     { "lightgray",     7, 0      },
  1459.     { "lightgreen",   10, 0      },
  1460.     { "lightmagenta", 13, 0      },
  1461.     { "lightred",     12, 0      },
  1462.     { "lmagenta",     13, CM_INV },
  1463.     { "lred",         12, CM_INV },
  1464.     { "magenta",       5, 0      },
  1465.     { "red",           4, 0      },
  1466.     { "white",        15, 0      },
  1467.     { "yellow",       14, 0      }
  1468. };
  1469. int nclrs = (sizeof (ttyclrtab) / sizeof (struct keytab));
  1470.  
  1471. struct keytab ttycurtab[] = {
  1472.     { "full",        TTC_BLOCK, 0 },
  1473.     { "half",        TTC_HALF,  0 },
  1474.     { "underline",   TTC_ULINE, 0 }
  1475. };
  1476. int ncursors = 3;
  1477.  
  1478. struct keytab ttyptab[] = {
  1479.     { "aaa",      TT_AAA,     CM_INV },     /* AnnArbor */
  1480.     { "adm3a",    TT_ADM3A,   0 },          /* LSI ADM-3A */
  1481.     { "aixterm",  TT_AIXTERM, 0 },          /* IBM AIXterm */
  1482.     { "annarbor", TT_AAA,     0 },          /* AnnArbor */
  1483.     { "ansi-bbs", TT_ANSI,    0 },          /* ANSI.SYS (BBS) */
  1484.     { "at386",    TT_AT386,   0 },          /* Unixware ANSI */
  1485.     { "avatar/0+",TT_ANSI,    0 },          /* AVATAR/0+ */
  1486.     { "ba80",     TT_BA80,    0 },          /* Nixdorf BA80 */
  1487.     { "be",       TT_BEOS,    CM_INV|CM_ABR },
  1488.     { "beos-ansi",TT_BEOS,    CM_INV },     /* BeOS ANSI */
  1489.     { "beterm",   TT_BEOS,    0 },          /* BeOS Terminal (as of PR2 ) */
  1490.     { "d200",     TT_DG200,   CM_INV|CM_ABR }, /* Data General DASHER 200 */
  1491.     { "d210",     TT_DG210,   CM_INV|CM_ABR }, /* Data General DASHER 210 */
  1492.     { "d217",     TT_DG217,   CM_INV|CM_ABR }, /* Data General DASHER 217 */
  1493.     { "dg200",    TT_DG200,   0 },          /* Data General DASHER 200 */
  1494.     { "dg210",    TT_DG210,   0 },          /* Data General DASHER 210 */
  1495.     { "dg217",    TT_DG217,   0 },          /* Data General DASHER 217 */
  1496.     { "h1500",    TT_HZL1500, CM_INV },     /* Hazeltine 1500 */
  1497.     { "h19",      TT_H19,     CM_INV },     /* Heath-19 */
  1498.     { "heath19",  TT_H19,     0 },          /* Heath-19 */
  1499.     { "hft",      TT_HFT,     0 },          /* IBM High Function Terminal */
  1500.     { "hp2621a",  TT_HP2621,  0 },          /* HP 2621A */
  1501.     { "hpterm",   TT_HPTERM,  0 },          /* HP TERM */
  1502.     { "hz1500",   TT_HZL1500, 0 },          /* Hazeltine 1500 */
  1503.     { "ibm3151",  TT_IBM31,   0 },          /* IBM 3101-xx,3161 */
  1504.     { "linux",    TT_LINUX,   0 },          /* Linux */
  1505.     { "qansi",    TT_QANSI,   0 },          /* QNX ANSI */
  1506.     { "qnx",      TT_QNX,     0 },          /* QNX Console */
  1507.     { "scoansi",  TT_SCOANSI, 0 },          /* SCO ANSI */
  1508.     { "sni-97801",TT_97801,   0 },          /* SNI 97801 */
  1509.     { "sun",      TT_SUN,     0 },          /* SUN Console */
  1510. /*
  1511.   The idea of NONE is to let the console driver handle the escape sequences,
  1512.   which, in theory at least, would give not only ANSI emulation, but also any
  1513.   other kind of emulation that might be provided by alternative console
  1514.   drivers, if any existed.
  1515.  
  1516.   For this to work, ckocon.c would need to be modified to make higher-level
  1517.   calls, like VioWrtTTY(), DosWrite(), or (simply) write(), rather than
  1518.   VioWrt*Cell() and similar, and it would also have to give up its rollback
  1519.   feature, and its status line and help screens would also have to be
  1520.   forgotten or else done in an ANSI way.
  1521.  
  1522.   As matters stand, we already have perfectly good ANSI emulation built in,
  1523.   and there are no alternative console drivers available, so there is no point
  1524.   in having a terminal type of NONE, so it is commented out.  However, should
  1525.   you uncomment it, it will work like a "glass tty" -- no escape sequence
  1526.   interpretation at all; somewhat similar to debug mode, except without the
  1527.   debugging (no highlighting of control chars or escape sequences); help
  1528.   screens, status line, and rollback will still work.
  1529. */
  1530. #ifdef OS2PM
  1531. #ifdef COMMENT
  1532.     { "tek4014", TT_TEK40,  0 },
  1533. #endif /* COMMENT */
  1534. #endif /* OS2PM */
  1535.     { "tty",     TT_NONE,   0 },
  1536.     { "tvi910+", TT_TVI910, 0 },
  1537.     { "tvi925",  TT_TVI925, 0 },
  1538.     { "tvi950",  TT_TVI950, 0 },
  1539.     { "vc404",   TT_VC4404, 0 },
  1540.     { "vc4404",  TT_VC4404, CM_INV },
  1541.     { "vip7809", TT_VIP7809,0 },
  1542.     { "vt100",   TT_VT100,  0 },
  1543.     { "vt102",   TT_VT102,  0 },
  1544.     { "vt220",   TT_VT220,  0 },
  1545.     { "vt220pc", TT_VT220PC,0 },
  1546.     { "vt320",   TT_VT320,  0 },
  1547.     { "vt320pc", TT_VT320PC,0 },
  1548.     { "vt52",    TT_VT52,   0 },
  1549. #ifdef NT
  1550.     { "vtnt",    TT_VTNT,   0 },
  1551. #else /* NT */
  1552.     { "vtnt",    TT_VTNT,  CM_INV },
  1553. #endif /* NT */
  1554.     { "wy160",   TT_WY160,  0 },
  1555.     { "wy30",    TT_WY30,   0 },
  1556.     { "wy370",   TT_WY370,  0 },
  1557.     { "wy50",    TT_WY50,   0 },
  1558.     { "wy60",    TT_WY60,   0 },
  1559.     { "wyse30",  TT_WY30,   CM_INV },
  1560.     { "wyse370", TT_WY370,  CM_INV },
  1561.     { "wyse50",  TT_WY50,   CM_INV },
  1562.     { "wyse60",  TT_WY60,   CM_INV }
  1563. };
  1564. int nttyp = (sizeof(ttyptab) / sizeof(struct keytab));
  1565.  
  1566. struct keytab ttkeytab[] = {
  1567.     { "aaa",       TT_AAA,        CM_INV },        /* AnnArbor */
  1568.     { "adm3a",     TT_ADM3A,      0 },             /* LSI ADM-3A */
  1569.     { "aixterm",   TT_AIXTERM,    0 },             /* IBM AIXterm */
  1570.     { "annarbor",  TT_AAA,        0 },             /* AnnArbor */
  1571.     { "ansi-bbs",  TT_ANSI,       0 },             /* ANSI.SYS (BBS) */
  1572.     { "at386",     TT_AT386,      0 },             /* Unixware ANSI */
  1573.     { "avatar/0+", TT_ANSI,       0 },             /* AVATAR/0+ */
  1574.     { "ba80",      TT_BA80,       0 },             /* Nixdorf BA80 */
  1575.     { "be",        TT_BEOS,       CM_INV|CM_ABR },
  1576.     { "beos-ansi", TT_BEOS,       CM_INV },        /* BeOS ANSI */
  1577.     { "beterm",    TT_BEOS,       0 },             /* BeOS Terminal (DR2) */
  1578.     { "d200",      TT_DG200,      CM_INV|CM_ABR }, /* DG DASHER 200 */
  1579.     { "d210",      TT_DG210,      CM_INV|CM_ABR }, /* DG DASHER 210 */
  1580.     { "d217",      TT_DG217,      CM_INV|CM_ABR }, /* DG DASHER 217 */
  1581.     { "dg200",     TT_DG200,      0 },             /* DG DASHER 200 */
  1582.     { "dg210",     TT_DG210,      0 },             /* DG DASHER 210 */
  1583.     { "dg217",     TT_DG217,      0 },             /* DG DASHER 217 */
  1584.     { "emacs",     TT_KBM_EMACS,  0 },             /* Emacs mode */
  1585.     { "h19",       TT_H19,        CM_INV },        /* Heath-19 */
  1586.     { "heath19",   TT_H19,        0 },             /* Heath-19 */
  1587.     { "hebrew",    TT_KBM_HEBREW, 0 },             /* Hebrew mode */
  1588.     { "hft",       TT_HFT,        0 },             /* IBM High Function Term */
  1589.     { "hp2621a",   TT_HP2621,     0 },             /* HP 2621A */
  1590.     { "hpterm",    TT_HPTERM,     0 },             /* HP TERM */
  1591.     { "hz1500",    TT_HZL1500,    0 },             /* Hazeltine 1500 */
  1592.     { "ibm3151",   TT_IBM31,      0 },             /* IBM 3101-xx,3161 */
  1593.     { "linux",     TT_LINUX,      0 },             /* Linux */
  1594.     { "qansi",     TT_QANSI,      0 },             /* QNX ANSI */
  1595.     { "qnx",       TT_QNX,        0 },             /* QNX */
  1596.     { "russian",   TT_KBM_RUSSIAN,0 },             /* Russian mode */
  1597.     { "scoansi",   TT_SCOANSI,    0 },             /* SCO ANSI */
  1598.     { "sni-97801", TT_97801,      0 },             /* SNI 97801 */
  1599.     { "sun",       TT_SUN,        0 },             /* SUN Console */
  1600. #ifdef OS2PM
  1601. #ifdef COMMENT
  1602.     { "tek4014",   TT_TEK40,      0 },
  1603. #endif /* COMMENT */
  1604. #endif /* OS2PM */
  1605.     { "tty",       TT_NONE,       0 },
  1606.     { "tvi910+",   TT_TVI910,     0 },
  1607.     { "tvi925",    TT_TVI925,     0 },
  1608.     { "tvi950",    TT_TVI950,     0 },
  1609.     { "vc404",     TT_VC4404,     0 },
  1610.     { "vc4404",    TT_VC4404,     CM_INV },
  1611.     { "vip7809",   TT_VIP7809,    0 },
  1612.     { "vt100",     TT_VT100,      0 },
  1613.     { "vt102",     TT_VT102,      0 },
  1614.     { "vt220",     TT_VT220,      0 },
  1615.     { "vt220pc",   TT_VT220PC,    0 },
  1616.     { "vt320",     TT_VT320,      0 },
  1617.     { "vt320pc",   TT_VT320PC,    0 },
  1618.     { "vt52",      TT_VT52,       0 },
  1619.     { "vtnt",      TT_VTNT,       CM_INV },
  1620.     { "wp",        TT_KBM_WP,     0 },             /* Word Perfect mode */
  1621.     { "wy160",     TT_WY160,      0 },
  1622.     { "wy30",      TT_WY30,       0 },
  1623.     { "wy370",     TT_WY370,      0 },
  1624.     { "wy50",      TT_WY50,       0 },
  1625.     { "wy60",      TT_WY60,       0 },
  1626.     { "wyse30",    TT_WY30,       CM_INV },
  1627.     { "wyse370",   TT_WY370,      CM_INV },
  1628.     { "wyse50",    TT_WY50,       CM_INV },
  1629.     { "wyse60",    TT_WY60,       CM_INV }
  1630. };
  1631. int nttkey = (sizeof(ttkeytab) / sizeof(struct keytab));
  1632.  
  1633. #ifndef NOSETKEY
  1634. struct keytab kbmodtab[] = {
  1635.     { "emacs",   KBM_EM, 0      },
  1636.     { "english", KBM_EN, CM_INV },
  1637.     { "hebrew",  KBM_HE, 0      },
  1638.     { "normal",  KBM_EN, 0      },
  1639.     { "none",    KBM_EN, CM_INV },
  1640.     { "russian", KBM_RU, 0      },
  1641.     { "wp",      KBM_WP, 0      }
  1642. };
  1643. int nkbmodtab = (sizeof(kbmodtab) / sizeof(struct keytab));
  1644. #endif /* NOSETKEY */
  1645. #endif /* NOLOCAL */
  1646.  
  1647. int tt_inpacing = 0;                    /* input-pacing (none) */
  1648.  
  1649. struct keytab prtytab[] = { /* OS/2 Priority Levels */
  1650.     { "foreground-server", XYP_SRV, 0       },
  1651.     { "idle",              XYP_IDLE, CM_INV },
  1652.     { "regular",           XYP_REG, 0       },
  1653.     { "time-critical",     XYP_RTP, 0       }
  1654. };
  1655. int nprty = (sizeof(prtytab) / sizeof(struct keytab));
  1656. #endif /* OS2 */
  1657.  
  1658. #ifdef NT
  1659. struct keytab win95tab[] = { /* Win95 work-arounds */
  1660.     { "8.3-filenames",         XYW8_3,    0 },
  1661.     { "alt-gr",                XYWAGR,    0 },
  1662.     { "horizontal-scan-line-substitutions", XYWHSL, 0 },
  1663.     { "keyboard-translation",  XYWKEY,    0 },
  1664.     { "lucida-substitutions",  XYWLUC,    0 },
  1665.     { "overlapped-io",         XYWOIO,    0 },
  1666.     { "popups",                XYWPOPUP,  0 },
  1667.     { "select-bug",            XYWSELECT, 0 }
  1668. };
  1669. int nwin95 = (sizeof(win95tab) / sizeof(struct keytab));
  1670. #endif /* NT */
  1671.  
  1672. #ifdef OS2MOUSE
  1673. extern int wideresult;
  1674. int tt_mouse = 1;                       /* Terminal mouse on/off */
  1675.  
  1676. struct keytab mousetab[] = {            /* Mouse items */
  1677.     { "activate", XYM_ON,     0 },
  1678.     { "button",   XYM_BUTTON, 0 },
  1679.     { "clear",    XYM_CLEAR,  0 },
  1680.     { "debug",    XYM_DEBUG,  0 }
  1681. };
  1682. int nmtab = (sizeof(mousetab)/sizeof(struct keytab));
  1683.  
  1684. struct keytab mousebuttontab[] = {      /* event button */
  1685.     { "1",             XYM_B1, 0 },
  1686.     { "2",             XYM_B2, 0 },
  1687.     { "3",             XYM_B3, 0 },
  1688.     { "one",           XYM_B1, CM_INV },
  1689.     { "three",         XYM_B3, CM_INV },
  1690.     { "two",           XYM_B2, CM_INV }
  1691. };
  1692. int nmbtab = (sizeof(mousebuttontab) / sizeof(struct keytab));
  1693.  
  1694. struct keytab mousemodtab[] = {         /* event button key modifier */
  1695.     { "alt",              XYM_ALT,   0 },
  1696.     { "alt-shift",        XYM_SHIFT|XYM_ALT, 0 },
  1697.     { "ctrl",             XYM_CTRL,  0 },
  1698.     { "ctrl-alt",         XYM_CTRL|XYM_ALT, 0 },
  1699.     { "ctrl-alt-shift",   XYM_CTRL|XYM_SHIFT|XYM_ALT, 0 },
  1700.     { "ctrl-shift",       XYM_CTRL|XYM_SHIFT, 0 },
  1701.     { "none",             0, 0 },
  1702.     { "shift",            XYM_SHIFT, 0 }
  1703. };
  1704. int nmmtab = (sizeof(mousemodtab) / sizeof(struct keytab));
  1705.  
  1706. struct keytab mclicktab[] = {           /* event button click modifier */
  1707.     { "click",        XYM_C1,   0 },
  1708.     { "drag",         XYM_DRAG, 0 },
  1709.     { "double-click", XYM_C2,   0 }
  1710. };
  1711. int nmctab = (sizeof(mclicktab) / sizeof(struct keytab));
  1712.  
  1713. #ifndef NOKVERBS
  1714. extern int nkverbs;
  1715. extern struct keytab kverbs[];
  1716. #endif /* NOKVERBS */
  1717. #endif /* OS2MOUSE */
  1718.  
  1719. /* #ifdef VMS */
  1720. struct keytab fbtab[] = {               /* Binary record types for VMS */
  1721.     { "fixed",     XYFT_B, 0 },         /* Fixed is normal for binary */
  1722.     { "undefined", XYFT_U, 0 }          /* Undefined if they ask for it */
  1723. };
  1724. int nfbtyp = (sizeof(fbtab) / sizeof(struct keytab));
  1725. /* #endif */
  1726.  
  1727. #ifdef VMS
  1728. struct keytab lbltab[] = {              /* Labeled File info */
  1729.     { "acl",         LBL_ACL, 0 },
  1730.     { "backup-date", LBL_BCK, 0 },
  1731.     { "name",        LBL_NAM, 0 },
  1732.     { "owner",       LBL_OWN, 0 },
  1733.     { "path",        LBL_PTH, 0 }
  1734. };
  1735. int nlblp = (sizeof(lbltab) / sizeof(struct keytab));
  1736. #else
  1737. #ifdef OS2
  1738. struct keytab lbltab[] = {              /* Labeled File info */
  1739.     { "archive",   LBL_ARC, 0 },
  1740.     { "extended",  LBL_EXT, 0 },
  1741.     { "hidden",    LBL_HID, 0 },
  1742.     { "read-only", LBL_RO,  0 },
  1743.     { "system",    LBL_SYS, 0 }
  1744. };
  1745. int nlblp = (sizeof(lbltab) / sizeof(struct keytab));
  1746. #endif /* OS2 */
  1747. #endif /* VMS */
  1748.  
  1749. #ifdef CK_CURSES
  1750. #ifdef CK_PCT_BAR
  1751. static struct keytab fdftab[] = {       /* SET FILE DISPLAY FULL options */
  1752.     { "thermometer",    1, 0, },
  1753.     { "no-thermometer", 0, 0  }
  1754. };
  1755. extern int thermometer;
  1756. #endif /* CK_PCT_BAR */
  1757. #endif /* CK_CURSES */
  1758.  
  1759. static struct keytab fdtab[] = {        /* SET FILE DISPLAY options */
  1760. #ifdef MAC                              /* Macintosh */
  1761.     { "fullscreen", XYFD_R,      0 },   /* Full-screen but not curses */
  1762.     { "none",       XYFD_N,      0 },
  1763.     { "off",        XYFD_N, CM_INV },
  1764.     { "on",         XYFD_R, CM_INV },
  1765.     { "quiet",      XYFD_N, CM_INV },
  1766. #else                                   /* Not Mac */
  1767.     { "brief", XYFD_B, 0 },             /* Brief */
  1768.     { "crt", XYFD_S, 0 },               /* CRT display */
  1769. #ifdef CK_CURSES
  1770. #ifdef COMMENT
  1771.     { "curses",     XYFD_C,  CM_INV },  /* Full-screen, curses */
  1772. #endif /* COMMENT */
  1773.     { "fullscreen", XYFD_C,  0 },       /* Full-screen, whatever the method */
  1774. #endif /* CK_CURSES */
  1775. #ifdef KUI
  1776.     { "gui",    XYFD_G, 0 },            /* GUI */
  1777. #endif /* KUI */        
  1778.     { "none",   XYFD_N, 0      },       /* No display */
  1779.     { "off",    XYFD_N, CM_INV },       /* Ditto */
  1780.     { "on",     XYFD_R, CM_INV },       /* On = Serial */
  1781.     { "quiet",  XYFD_N, CM_INV },       /* No display */
  1782.     { "serial", XYFD_R, 0      },       /* Serial */
  1783. #endif /* MAC */
  1784.     { "", 0, 0 }
  1785. };
  1786. int nfdtab = (sizeof(fdtab) / sizeof(struct keytab)) - 1;
  1787.  
  1788. struct keytab rsrtab[] = {              /* For REMOTE SET RECEIVE */
  1789.     { "packet-length", XYLEN,  0 },
  1790.     { "timeout",       XYTIMO, 0 }
  1791. };
  1792. int nrsrtab = (sizeof(rsrtab) / sizeof(struct keytab));
  1793.  
  1794. /* Send/Receive Parameters */
  1795.  
  1796. struct keytab srtab[] = {
  1797.     { "backup", XYBUP, 0 },
  1798. #ifndef NOCSETS
  1799.     { "character-set-selection", XYCSET, 0 },
  1800. #endif /* NOCSETS */
  1801.     { "control-prefix", XYQCTL, 0 },
  1802. #ifdef CKXXCHAR
  1803.     { "double-character", XYDBL, 0 },
  1804. #endif /* CKXXCHAR */
  1805.     { "end-of-packet", XYEOL, 0 },
  1806. #ifdef PIPESEND
  1807.     { "filter", XYFLTR, 0 },
  1808. #endif /* PIPESEND */
  1809. #ifdef CKXXCHAR
  1810.     { "ignore-character", XYIGN, 0 },
  1811. #endif /* CKXXCHAR */
  1812.     { "i-packets", 993, 0 },
  1813.     { "move-to", XYMOVE, 0 },
  1814.     { "negotiation-string-max-length", XYINIL, CM_INV },
  1815.     { "packet-length", XYLEN, 0 },
  1816.     { "pad-character", XYPADC, 0 },
  1817.     { "padding", XYNPAD, 0 },
  1818.     { "pathnames", XYFPATH, 0 },
  1819.     { "pause", XYPAUS, 0 },
  1820. #ifdef CK_PERMS
  1821.     { "permissions", 994, 0},        /* 206 */
  1822. #endif /* CK_PERMS */
  1823.     { "quote", XYQCTL, CM_INV },        /* = CONTROL-PREFIX */
  1824.     { "rename-to", XYRENAME, 0 },
  1825.     { "start-of-packet", XYMARK, 0 },
  1826.     { "timeout", XYTIMO, 0 },
  1827. #ifdef VMS
  1828.     { "version-numbers", 887, 0 },      /* VMS version numbers */
  1829. #endif /* VMS */
  1830.     { "", 0, 0 }
  1831. };
  1832. int nsrtab = (sizeof(srtab) / sizeof(struct keytab)) - 1;
  1833.  
  1834. #ifdef UNICODE
  1835. #define UCS_BOM 1
  1836. #define UCS_BYT 2
  1837. static struct keytab ucstab[] = {
  1838.     { "bom",        UCS_BOM, 0 },
  1839.     { "byte-order", UCS_BYT, 0 },
  1840.     { "", 0, 0 }
  1841. };
  1842. int nucstab = (sizeof(ucstab) / sizeof(struct keytab)) - 1;
  1843.  
  1844. static struct keytab botab[] = {
  1845.     { "big-endian",    0, 0 },
  1846.     { "little-endian", 1, 0 }
  1847. };
  1848. static int nbotab = 2;
  1849. #endif /* UNICODE */
  1850.  
  1851. /* REMOTE SET */
  1852.  
  1853. struct keytab rmstab[] = {
  1854.     { "attributes",  XYATTR, 0      },
  1855.     { "block-check", XYCHKT, 0      },
  1856.     { "file",        XYFILE, 0      },
  1857.     { "incomplete",  XYIFD,  CM_INV },  /* = REMOTE SET FILE INCOMPLETE */
  1858.     { "match",       XYMATCH,0      },
  1859.     { "receive",     XYRECV, 0      },
  1860.     { "retry",       XYRETR, 0      },
  1861.     { "server",      XYSERV, 0      },
  1862.     { "transfer",    XYXFER, 0      },
  1863.     { "window",      XYWIND, 0      },
  1864.     { "xfer",        XYXFER, CM_INV }
  1865. };
  1866. int nrms = (sizeof(rmstab) / sizeof(struct keytab));
  1867.  
  1868. struct keytab attrtab[] = {
  1869. #ifdef STRATUS
  1870.     { "account",       AT_ACCT, 0 },
  1871. #endif /* STRATUS */
  1872.     { "all",           AT_XALL, 0 },
  1873. #ifdef COMMENT
  1874.     { "blocksize",     AT_BLKS, 0 },    /* (not used) */
  1875. #endif /* COMMENT */
  1876. #ifndef NOCSETS
  1877.     { "character-set", AT_ENCO, 0 },
  1878. #endif /* NOCSETS */
  1879. #ifdef STRATUS
  1880.     { "creator",       AT_CREA, 0 },
  1881. #endif /* STRATUS */
  1882.     { "date",          AT_DATE, 0 },
  1883.     { "disposition",   AT_DISP, 0 },
  1884.     { "encoding",      AT_ENCO, CM_INV },
  1885.     { "format",        AT_RECF, CM_INV },
  1886.     { "length",        AT_LENK, 0 },
  1887.     { "off",           AT_ALLN, 0 },
  1888.     { "on",            AT_ALLY, 0 },
  1889. #ifdef COMMENT
  1890.     { "os-specific",   AT_SYSP, 0 },    /* (not used by UNIX or VMS) */
  1891. #endif /* COMMENT */
  1892. #ifdef CK_PERMS
  1893.     { "protection",    AT_LPRO, 0 },
  1894.     { "permissions",   AT_LPRO, CM_INV },
  1895. #endif /* CK_PERMS */
  1896.     { "record-format", AT_RECF, 0 },
  1897.     { "system-id",     AT_SYSI, 0 },
  1898.     { "type",          AT_FTYP, 0 }
  1899. };
  1900. int natr = (sizeof(attrtab) / sizeof(struct keytab)); /* how many attributes */
  1901.  
  1902. #ifdef CKTIDLE
  1903. struct keytab idlacts[] = {
  1904.     { "exit",       IDLE_EXIT, 0 },
  1905.     { "hangup",     IDLE_HANG, 0 },
  1906.     { "output",     IDLE_OUT,  0 },
  1907.     { "return",     IDLE_RET,  0 },
  1908. #ifdef TNCODE
  1909.     { "telnet-nop", IDLE_TNOP, 0 },
  1910.     { "telnet-ayt", IDLE_TAYT, 0 },
  1911. #endif /* TNCODE */
  1912.     { "", 0, 0 }
  1913. };
  1914. int nidlacts = (sizeof(idlacts) / sizeof(struct keytab)) - 1;
  1915. #endif /* CKTIDLE */
  1916.  
  1917. #ifndef NOSPL
  1918. extern int indef, inecho, insilence, inbufsize, inautodl, inintr;
  1919. extern char * inpbuf, * inpbp;
  1920. #ifdef OS2
  1921. extern int interm;
  1922. #endif /* OS2 */
  1923. struct keytab inptab[] = {              /* SET INPUT parameters */
  1924. #ifdef CK_AUTODL
  1925.     { "autodownload",    IN_ADL, 0 },
  1926. #endif /* CK_AUTODL */
  1927.     { "buffer-length",   IN_BUF, 0 },
  1928.     { "cancellation",    IN_CAN, 0 },
  1929.     { "case",            IN_CAS, 0 },
  1930.     { "default-timeout", IN_DEF, CM_INV }, /* There is no default timeout */
  1931.     { "echo",            IN_ECH, 0 },
  1932. #ifdef OS2
  1933.     { "pacing",          IN_PAC, CM_INV },
  1934. #endif /* OS2 */
  1935.     { "silence",         IN_SIL, 0 },
  1936. #ifdef OS2
  1937.     { "terminal",        IN_TRM, 0 },
  1938. #endif /* OS2 */
  1939.     { "timeout-action",  IN_TIM, 0 }
  1940. };
  1941. int ninp = (sizeof(inptab) / sizeof(struct keytab));
  1942.  
  1943. struct keytab intimt[] = {              /* SET INPUT TIMEOUT parameters */
  1944.     { "proceed", 0, 0 },                /* 0 = proceed */
  1945.     { "quit",    1, 0 }                 /* 1 = quit */
  1946. };
  1947.  
  1948. struct keytab incast[] = {              /* SET INPUT CASE parameters */
  1949.     { "ignore",  0, 0 },                /* 0 = ignore */
  1950.     { "observe", 1, 0 }                 /* 1 = observe */
  1951. };
  1952. #endif /* NOSPL */
  1953.  
  1954. struct keytab nabltab[] = {             /* For any command that needs */
  1955.     { "disabled", 0, 0 },
  1956.     { "enabled",  1, 0 },
  1957.     { "off",      0, CM_INV },          /* these keywords... */
  1958.     { "on",       1, CM_INV }
  1959. };
  1960. int nnabltab = sizeof(nabltab) / sizeof(struct keytab);
  1961.  
  1962. #ifdef OS2
  1963. struct keytab tvctab[] = {              /* SET TERM VIDEO-CHANGE */
  1964.     { "disabled",     TVC_DIS, 0 },
  1965.     { "enabled",      TVC_ENA, 0 },
  1966. #ifdef NT
  1967.     { "win95-safe",   TVC_W95, 0 },
  1968. #endif /* NT */
  1969.     { "", 0, 0 }
  1970. };
  1971. int ntvctab = (sizeof(tvctab) / sizeof(struct keytab)) - 1;
  1972.  
  1973. struct keytab msktab[] = { /* SET MS-DOS KERMIT compatibilities */
  1974. #ifdef COMMENT
  1975.     { "color",    MSK_COLOR,  0 },
  1976. #endif /* COMMENT */
  1977.     { "keycodes", MSK_KEYS,   0 }
  1978. };
  1979. int nmsk = (sizeof(msktab) / sizeof(struct keytab));
  1980.  
  1981. struct keytab scrnupd[] = {             /* SET TERMINAL SCREEN-UPDATE */
  1982.     { "fast",   TTU_FAST,   0 },
  1983.     { "smooth", TTU_SMOOTH, 0 }
  1984. };
  1985. int nscrnupd = (sizeof(scrnupd) / sizeof(struct keytab));
  1986.  
  1987. #ifdef PCFONTS
  1988. /* This definition of the term_font[] table is only for     */
  1989. /* the OS/2 Full Screen Session and is not used on Windows */
  1990. struct keytab term_font[] = {           /* SET TERMINAL FONT */
  1991. #ifdef COMMENT
  1992.     { "cp111", TTF_111, 0 },
  1993.     { "cp112", TTF_112, 0 },
  1994.     { "cp113", TTF_113, 0 },
  1995. #endif /* COMMENT */
  1996.     { "cp437", TTF_437, 0 },
  1997.     { "cp850", TTF_850, 0 },
  1998. #ifdef COMMENT
  1999.     { "cp851", TTF_851, 0 },
  2000. #endif /* COMMENT */
  2001.     { "cp852", TTF_852, 0 },
  2002. #ifdef COMMENT
  2003.     { "cp853", TTF_853, 0 },
  2004.     { "cp860", TTF_860, 0 },
  2005.     { "cp861", TTF_861, 0 },
  2006. #endif /* COMMENT */
  2007.     { "cp862", TTF_862, 0 },
  2008. #ifdef COMMENT
  2009.     { "cp863", TTF_863, 0 },
  2010.     { "cp864", TTF_864, 0 },
  2011.     { "cp865", TTF_865, 0 },
  2012. #endif /* COMMENT */
  2013.     { "cp866", TTF_866, 0 },
  2014. #ifdef COMMENT
  2015.     { "cp880", TTF_880, 0 },
  2016.     { "cp881", TTF_881, 0 },
  2017.     { "cp882", TTF_882, 0 },
  2018.     { "cp883", TTF_883, 0 },
  2019.     { "cp884", TTF_884, 0 },
  2020.     { "cp885", TTF_885, 0 },
  2021. #endif /* COMMENT */
  2022.     { "default",TTF_ROM,0 }
  2023. };
  2024. int ntermfont = (sizeof(term_font) / sizeof(struct keytab));
  2025. int tt_font = TTF_ROM;                  /* Terminal screen font */
  2026. #else /* PCFONTS */
  2027. #ifdef NT
  2028. #ifdef KUI
  2029. struct keytab * term_font = NULL;
  2030. struct keytab * _term_font = NULL;
  2031. char * tt_facename = NULL;
  2032. int ntermfont = 0;
  2033. int tt_font = 0;
  2034. int tt_font_size = 0;
  2035. #endif /* KUI */
  2036. #endif /* NT */
  2037. #endif /* PCFONTS */
  2038.  
  2039. struct keytab anbktab[] = {             /* For any command that needs */
  2040.     { "message", 2, 0 },                /* these keywords... */
  2041.     { "off",     0, 0 },
  2042.     { "on",      1, 0 },
  2043.     { "unsafe-messag0", 99, CM_INV },
  2044.     { "unsafe-message", 3,  CM_INV }
  2045. };
  2046. int nansbk = (sizeof(anbktab) / sizeof(struct keytab));
  2047.  
  2048. int win95_popup = 1;
  2049. #ifdef NT
  2050. #ifdef KUI
  2051. int win95lucida = 0;
  2052. int win95hsl = 1;
  2053. #else /* KUI */
  2054. int win95lucida = 1;
  2055. int win95hsl = 1;
  2056. #endif /* KUI */
  2057. #else /* NT */
  2058. int win95lucida = 0;
  2059. int win95hsl = 1;
  2060. #endif /* NT */
  2061. #ifdef NT
  2062. int win95altgr  = 0;
  2063. extern int win95selectbug;
  2064. extern int win95_8_3;
  2065.  
  2066. #ifdef COMMENT
  2067. extern CHAR (*xlr[MAXTCSETS+1][MAXFCSETS+1])(CHAR);
  2068. extern struct keytab tcstab[];
  2069. extern int ntcs;
  2070. #endif /* COMMENT */
  2071. extern int maxow, maxow_usr; owwait;    /* Overlapped I/O variables */
  2072. #endif /* NT */
  2073. #endif /* OS2 */
  2074.  
  2075.  
  2076. /* The following routines broken out of doprm() to give compilers a break. */
  2077.  
  2078. /*  S E T O N  --  Parse on/off (default on), set parameter to result  */
  2079.  
  2080. int
  2081. seton(prm) int *prm; {
  2082.     int x, y;
  2083.     if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  2084.     if ((x = cmcfm()) < 0) return(x);
  2085.     *prm = y;
  2086.     return(1);
  2087. }
  2088.  
  2089. /*  S E T O N A U T O --  Parse on/off/auto (default auto) & set result */
  2090.  
  2091. struct keytab onoffaut[] = {
  2092.     { "auto", SET_AUTO, 0 },            /* 2 */
  2093.     { "off",  SET_OFF,  0 },            /* 0 */
  2094.     { "on",   SET_ON,   0 }             /* 1 */
  2095. };
  2096.  
  2097. int
  2098. setonaut(prm) int *prm; {
  2099.     int x, y;
  2100.     if ((y = cmkey(onoffaut,3,"","auto",xxstring)) < 0) return(y);
  2101.     if ((x = cmcfm()) < 0) return(x);
  2102.     *prm = y;
  2103.     return(1);
  2104. }
  2105.  
  2106. /*  S E T N U M  --  Set parameter to result of cmnum() parse.  */
  2107. /*
  2108.  Call with pointer to integer variable to be set,
  2109.    x = number from cnum parse, y = return code from cmnum,
  2110.    max = maximum value to accept, -1 if no maximum.
  2111.  Returns -9 on failure, after printing a message, or 1 on success.
  2112. */
  2113. int
  2114. setnum(prm,x,y,max) int x, y, *prm, max; {
  2115.     debug(F101,"setnum","",y);
  2116.     if (y == -3) {
  2117.         printf("\n?Value required\n");
  2118.         return(-9);
  2119.     }
  2120.     if (y == -2) {
  2121.         printf("%s?Not a number: %s\n",cmflgs == 1 ? "" : "\n", atxbuf);
  2122.         return(-9);
  2123.     }
  2124.     if (y < 0) return(y);
  2125.     if (max > -1 && x > max) {
  2126.         printf("?Sorry, %d is the maximum\n",max);
  2127.         return(-9);
  2128.     }
  2129.     if ((y = cmcfm()) < 0) return(y);
  2130.     *prm = x;
  2131.     return(1);
  2132. }
  2133.  
  2134. /*  S E T C C  --  Set parameter var to an ASCII control character value.  */
  2135. /*
  2136.   Parses a number, or a literal control character, or a caret (^) followed
  2137.   by an ASCII character whose value is 63-95 or 97-122, then gets confirmation,
  2138.   then sets the parameter to the code value of the character given.  If there
  2139.   are any parse errors, they are returned, otherwise on success 1 is returned.
  2140. */
  2141. int
  2142. setcc(dflt,var) char *dflt; int *var; {
  2143.     int x, y;
  2144.     unsigned int c;
  2145.     char *hlpmsg = "Control character,\n\
  2146.  numeric ASCII value,\n\
  2147.  or in ^X notation,\n\
  2148.  or preceded by a backslash and entered literally";
  2149.  
  2150.     /* This is a hack to turn off complaints from expression evaluator. */
  2151.     x_ifnum = 1;
  2152.     y = cmnum(hlpmsg, dflt, 10, &x, xxstring); /* Parse a number */
  2153.     x_ifnum = 0;                               /* Allow complaints again */
  2154.     if (y < 0) {                        /* Parse failed */
  2155.         if (y != -2)                    /* Reparse needed or somesuch */
  2156.           return(y);                    /* Pass failure back up the chain */
  2157.     }
  2158.     /* Real control character or literal 8-bit character... */
  2159.  
  2160.     for (c = strlen(atmbuf) - 1; c > 0; c--) /* Trim */
  2161.       if (atmbuf[c] == SP) atmbuf[c] = NUL;
  2162.  
  2163.     if (y < 0) {                        /* It was not a number */
  2164.         if (((c = atmbuf[0])) && !atmbuf[1]) { /* Literal character? */
  2165.             c &= 0xff;
  2166.             if (((c > 31) && (c < 127)) || (c > 255)) {
  2167.                 printf("\n?%d: Out of range - must be 0-31 or 127-255\n",c);
  2168.                 return(-9);
  2169.             } else {
  2170.                 if ((y = cmcfm()) < 0)  /* Confirm */
  2171.                   return(y);
  2172.                 *var = c;               /* Set the variable */
  2173.                 return(1);
  2174.             }
  2175.         } else if (atmbuf[0] == '^' && !atmbuf[2]) { /* Or ^X notation? */
  2176.             c = atmbuf[1];
  2177.             if (islower((char) c))      /* Uppercase lowercase letters */
  2178.               c = toupper(c);
  2179.             if (c > 62 && c < 96) {     /* Check range */
  2180.                 if ((y = cmcfm()) < 0)
  2181.                   return(y);
  2182.                 *var = ctl(c);          /* OK */
  2183.                 return(1);
  2184.             } else {
  2185.                 printf("?Not a control character - %s\n", atmbuf);
  2186.                 return(-9);
  2187.             }
  2188.         } else {                        /* Something illegal was typed */
  2189.             printf("?Invalid - %s\n", atmbuf);
  2190.             return(-9);
  2191.         }
  2192.     }
  2193.     if (((x > 31) && (x < 127)) || (x > 255)) { /* They typed a number */
  2194.         printf("\n?%d: Out of range - must be 0-31 or 127-255\n",x);
  2195.         return(-9);
  2196.     }
  2197.     if ((y = cmcfm()) < 0)              /* In range, confirm */
  2198.       return(y);
  2199.     *var = x;                           /* Set variable */
  2200.     return(1);
  2201. }
  2202.  
  2203. #ifndef NOSPL                           /* The SORT command... */
  2204.  
  2205. static struct keytab srtswtab[] = {     /* SORT command switches */
  2206.     { "/case",    SRT_CAS, CM_ARG },
  2207.     { "/key",     SRT_KEY, CM_ARG },
  2208.     { "/numeric", SRT_NUM, 0 },
  2209.     { "/range",   SRT_RNG, CM_ARG },
  2210.     { "/reverse", SRT_REV, 0 }
  2211. };
  2212. static int nsrtswtab = sizeof(srtswtab)/sizeof(struct keytab);
  2213.  
  2214. extern char **a_ptr[];                  /* Array pointers */
  2215. extern int a_dim[];                     /* Array dimensions */
  2216.  
  2217. int
  2218. dosort() {                              /* Do the SORT command */
  2219.     char c, *p = NULL, ** ap, ** xp = NULL;
  2220.     struct FDB sw, fl, cm;
  2221.     int hi, lo;
  2222.     int xn = 0, xr = -1, xk = -1, xc = -1, xs = 0;
  2223.     int getval = 0, range[2], confirmed = 0;
  2224.  
  2225.     cmfdbi(&sw,                         /* First FDB - command switches */
  2226.            _CMKEY,                      /* fcode */
  2227.            "Array name or switch",
  2228.            "",                          /* default */
  2229.            "",                          /* addtl string data */
  2230.            nsrtswtab,                   /* addtl numeric data 1: tbl size */
  2231.            4,                           /* addtl numeric data 2: 4 = cmswi */
  2232.            NULL,                        /* Processing function */
  2233.            srtswtab,                    /* Keyword table */
  2234.            &fl                          /* Pointer to next FDB */
  2235.            );
  2236.     cmfdbi(&fl,                         /* Anything that doesn't match */
  2237.            _CMFLD,                      /* fcode */
  2238.            "Array name",                /* hlpmsg */
  2239.            "",                          /* default */
  2240.            "",                          /* addtl string data */
  2241.            0,                           /* addtl numeric data 1 */
  2242.            0,                           /* addtl numeric data 2 */
  2243.            NULL,
  2244.            NULL,
  2245.            &cm
  2246.            );
  2247.     cmfdbi(&cm,                         /* Or premature confirmation */
  2248.            _CMCFM,                      /* fcode */
  2249.            "",                          /* hlpmsg */
  2250.            "",                          /* default */
  2251.            "",                          /* addtl string data */
  2252.            0,                           /* addtl numeric data 1 */
  2253.            0,                           /* addtl numeric data 2 */
  2254.            NULL,
  2255.            NULL,
  2256.            NULL
  2257.            );
  2258.  
  2259.     range[0] = -1;
  2260.     range[1] = -1;
  2261.  
  2262.     while (1) {                         /* Parse 0 or more switches */
  2263.         x = cmfdb(&sw);
  2264.         if (x < 0)
  2265.           return(x);
  2266.         if (cmresult.fcode != _CMKEY)   /* Break out if not a switch */
  2267.           break;
  2268.         c = cmgbrk();
  2269.         getval = (c == ':' || c == '=');
  2270.         if (getval && !(cmresult.kflags & CM_ARG)) {
  2271.             printf("?This switch does not take arguments\n");
  2272.             return(-9);
  2273.         }
  2274.         switch (cmresult.nresult) {
  2275.           case SRT_REV:
  2276.             xr = 1;
  2277.             break;
  2278.           case SRT_KEY:
  2279.             if (getval) {
  2280.                 if ((y = cmnum("Column for comparison (1-based)",
  2281.                                "1",10,&x,xxstring)) < 0)
  2282.                   return(y);
  2283.                 xk = x - 1;
  2284.             } else
  2285.               xk = 0;
  2286.             break;
  2287.           case SRT_CAS:
  2288.             if (getval) {
  2289.                 if ((y = cmkey(onoff,2,"","on",xxstring)) < 0)
  2290.                   return(y);
  2291.                 xc = y;
  2292.             } else
  2293.               xc = 1;
  2294.             break;
  2295.           case SRT_RNG:                 /* /RANGE */
  2296.             if (getval) {
  2297.                 char buf[32];
  2298.                 char buf2[16];
  2299.                 int i;
  2300.                 char * p, * q;
  2301.                 if ((y = cmfld("low:high element","1",&s,NULL)) < 0)
  2302.                   return(y);
  2303.                 s = brstrip(s);
  2304.                 ckstrncpy(buf,s,32);
  2305.                 p = buf;
  2306.                 for (i = 0; *p && i < 2; i++) { /* Get low and high */
  2307.                     q = p;              /* Start of this piece */
  2308.                     while (*p) {        /* Find end of this piece */
  2309.                         if (*p == ':') {
  2310.                             *p = NUL;
  2311.                             p++;
  2312.                             break;
  2313.                         }
  2314.                         p++;
  2315.                     }
  2316.                     y = 15;             /* Evaluate this piece */
  2317.                     s = buf2;
  2318.                     zzstring(q,&s,&y);
  2319.                     s = evalx(buf2);
  2320.                     if (s) if (*s) ckstrncpy(buf2,s,16);
  2321.                     if (!rdigits(buf2)) {
  2322.                         printf("?Not numeric: %s\n",buf2);
  2323.                         return(-9);
  2324.                     }
  2325.                     range[i] = atoi(buf2);
  2326.                 }
  2327.             }
  2328.             break;
  2329.           case SRT_NUM:                 /* /NUMERIC */
  2330.             xn = 1;
  2331.             break;
  2332.           default:
  2333.             return(-2);
  2334.         }
  2335.     }
  2336.     switch (cmresult.fcode) {
  2337.       case _CMCFM:
  2338.         confirmed = 1;
  2339.         break;
  2340.       case _CMFLD:
  2341.         ckstrncpy(line,cmresult.sresult,LINBUFSIZ); /* Safe copy of name */
  2342.         s = line;
  2343.         break;
  2344.       default:
  2345.         printf("?Unexpected function code: %d\n",cmresult.fcode);
  2346.         return(-9);
  2347.     }
  2348.     if (confirmed) {
  2349.         printf("?Array name required\n");
  2350.         return(-9);
  2351.     }
  2352.     ckmakmsg(tmpbuf,TMPBUFSIZ,
  2353.              "Second array to sort according to ",s,NULL,NULL);
  2354.     if ((x = cmfld(tmpbuf,"",&p,NULL)) < 0)
  2355.       if (x != -3)
  2356.         return(x);
  2357.     tmpbuf[0] = NUL;
  2358.     ckstrncpy(tmpbuf,p,TMPBUFSIZ);
  2359.     p = tmpbuf;
  2360.     if ((x = cmcfm()) < 0)              /* Get confirmation */
  2361.       return(x);
  2362.  
  2363.     x = arraybounds(s,&lo,&hi);         /* Get array index & bounds */
  2364.     if (x < 0) {                        /* Check */
  2365.         printf("?Bad array name: %s\n",s);
  2366.         return(-9);
  2367.     }
  2368.     if (lo > -1) range[0] = lo;         /* Set range */
  2369.     if (hi > -1) range[1] = hi;
  2370.     ap = a_ptr[x];                      /* Get pointer to array element list */
  2371.     if (!ap) {                          /* Check */
  2372.         printf("?Array not declared: %s\n", s);
  2373.         return(-9);
  2374.     }
  2375.     if (range[0] < 0)                   /* Starting element */
  2376.       range[0] = 1;
  2377.     if (range[1] < 0)                   /* Final element */
  2378.       range[1] = a_dim[x];
  2379.     if (range[1] > a_dim[x]) {
  2380.         printf("?range %d:%d exceeds array dimension %d\n",
  2381.                range[0],range[1],a_dim[x]
  2382.                );
  2383.         return(-9);
  2384.     }
  2385.     ap += range[0];
  2386.     xs = range[1] - range[0] + 1;       /* Number of elements to sort */
  2387.     if (xs < 1) {                       /* Check */
  2388.         printf("?Bad range: %d:%d\n",range[0],range[1]);
  2389.         return(-9);
  2390.     }
  2391.     if (xk < 0) xk = 0;                 /* Key position */
  2392.     if (xr < 0) xr = 0;                 /* Reverse flag */
  2393.     if (xn)                             /* Numeric flag */
  2394.       xc = 2;
  2395.     else if (xc < 0)                    /* Not numeric */
  2396.       xc = inpcas[cmdlvl];              /* so alpha case option */
  2397.  
  2398.     if (*p) {                           /* Parallel array given? */
  2399.         y = xarray(p);                  /* Yes, get its index. */
  2400.         if (y < 0) {
  2401.             printf("?Bad array name: %s\n", p);
  2402.             return(-9);
  2403.         }
  2404.         if (y != x) {                   /* If the 2 arrays are different  */
  2405.             xp = a_ptr[y];              /* Pointer to 2nd array element list */
  2406.             if (!xp) {
  2407.                 printf("?Array not declared: %s\n", p);
  2408.                 return(-9);
  2409.             }
  2410.             if (a_dim[y] < range[1]) {
  2411.                 printf("?Array %s smaller than %s\n", p, s);
  2412.                 return(-9);
  2413.             }
  2414.             xp += range[0];             /* Set base to same as 1st array */
  2415.         }
  2416.     }
  2417.     sh_sort(ap,xp,xs,xk,xr,xc);         /* Sort the array(s) */
  2418.     return(success = 1);                /* Always succeeds */
  2419. }
  2420. #endif /* NOSPL */
  2421.  
  2422. static struct keytab purgtab[] = {      /* PURGE command switches */
  2423.     { "/after",        PU_AFT,  CM_ARG },
  2424.     { "/ask",          PU_ASK,  0 },
  2425.     { "/before",       PU_BEF,  CM_ARG },
  2426.     { "/delete",       PU_DELE, CM_INV },
  2427. #ifdef UNIXOROSK
  2428.     { "/dotfiles",     PU_DOT,  0 },
  2429. #endif /* UNIXOROSK */
  2430.     { "/except",       PU_EXC,  CM_ARG },
  2431.     { "/heading",      PU_HDG,  0 },
  2432.     { "/keep",         PU_KEEP, CM_ARG },
  2433.     { "/larger-than",  PU_LAR,  CM_ARG },
  2434.     { "/list",         PU_LIST, 0 },
  2435.     { "/log",          PU_LIST, CM_INV },
  2436.     { "/noask",        PU_NASK, 0 },
  2437.     { "/nodelete",     PU_NODE, CM_INV },
  2438. #ifdef UNIXOROSK
  2439.     { "/nodotfiles",   PU_NODOT,0 },
  2440. #endif /* UNIXOROSK */
  2441.     { "/noheading",    PU_NOH,  0 },
  2442.     { "/nol",          PU_NOLI, CM_INV|CM_ABR },
  2443.     { "/nolist",       PU_NOLI, 0 },
  2444.     { "/nolog",        PU_NOLI, CM_INV },
  2445. #ifdef CK_TTGWSIZ
  2446.     { "/nopage",       PU_NOPA, 0 },
  2447. #endif /* CK_TTGWSIZ */
  2448.     { "/not-after",    PU_NAF,  CM_ARG },
  2449.     { "/not-before",   PU_NBF,  CM_ARG },
  2450.     { "/not-since",    PU_NAF,  CM_INV|CM_ARG },
  2451. #ifdef CK_TTGWSIZ
  2452.     { "/page",         PU_PAGE, 0 },
  2453. #endif /* CK_TTGWSIZ */
  2454.     { "/quiet",        PU_QUIE, CM_INV },
  2455. #ifdef RECURSIVE
  2456.     { "/recursive",    PU_RECU, 0 },
  2457. #endif /* RECURSIVE */
  2458.     { "/since",        PU_AFT,  CM_ARG|CM_INV },
  2459.     { "/simulate",     PU_NODE, 0 },
  2460.     { "/smaller-than", PU_SMA,  CM_ARG },
  2461.     { "/verbose",      PU_VERB, CM_INV }
  2462. };
  2463. static int npurgtab = sizeof(purgtab)/sizeof(struct keytab);
  2464.  
  2465.  
  2466.  
  2467.  
  2468.  
  2469. int
  2470. bkupnum(s,i) char * s; int *i; {
  2471.     int k = 0, pos = 0;
  2472.     char * p = NULL, *q;
  2473.     *i = pos;
  2474.     if (!s) s = "";
  2475.     if (!*s)
  2476.       return(-1);
  2477.     if ((k = strlen(s)) < 5)
  2478.       return(-1);
  2479.  
  2480.     if (s[k-1] != '~')
  2481.       return(-1);
  2482.     pos = k - 2;
  2483.     q = s + pos;
  2484.     while (q >= s && isdigit(*q)) {
  2485.         p = q--;
  2486.         pos--;
  2487.     }
  2488.     if (!p)
  2489.       return(-1);
  2490.     if (q < s+2)
  2491.       return(-1);
  2492.     if (*q != '~' || *(q-1) != '.')
  2493.       return(-1);
  2494.     pos--;
  2495.     *i = pos;
  2496.     debug(F111,"bkupnum",s+pos,pos);
  2497.     return(atoi(p));
  2498. }
  2499.  
  2500. #ifdef CKPURGE
  2501. /* Presently only for UNIX because we need direct access to the file array. */
  2502. /* Not needed for VMS anyway, because we don't make backup files there. */
  2503.  
  2504. #define MAXKEEP 32                      /* Biggest /KEEP: value */
  2505.  
  2506. static int
  2507.   pu_keep = 0, pu_list = 0, pu_dot = 0, pu_ask = 0, pu_hdg = 0;
  2508.  
  2509. #ifdef CK_TTGWSIZ
  2510. static int pu_page = -1;
  2511. #else
  2512. static int pu_page = 0;
  2513. #endif /* CK_TTGWSIZ */
  2514.  
  2515. #ifndef NOSHOW
  2516. VOID
  2517. showpurgopts() {                        /* SHOW PURGE command options */
  2518.     int x = 0;
  2519.     extern int optlines;
  2520.     prtopt(&optlines,"PURGE");
  2521.     if (pu_ask > -1) {
  2522.         x++;
  2523.         prtopt(&optlines, pu_ask ? "/ASK" : "/NOASK");
  2524.     }
  2525. #ifdef UNIXOROSK
  2526.     if (pu_dot > -1) {
  2527.         x++;
  2528.         prtopt(&optlines, pu_dot ? "/DOTFILES" : "/NODOTFILES");
  2529.     }
  2530. #endif /* UNIXOROSK */
  2531.     if (pu_keep > -1) {
  2532.         x++;
  2533.         ckmakmsg(tmpbuf,TMPBUFSIZ,"/KEEP:",ckitoa(pu_keep),NULL,NULL);
  2534.         prtopt(&optlines,tmpbuf);
  2535.     }
  2536.     if (pu_list > -1) {
  2537.         x++;
  2538.         prtopt(&optlines, pu_list ? "/LIST" : "/NOLIST");
  2539.     }
  2540.     if (pu_hdg > -1) {
  2541.         x++;
  2542.         prtopt(&optlines, pu_hdg ? "/HEADING" : "/NOHEADING");
  2543.     }
  2544. #ifdef CK_TTGWSIZ
  2545.     if (pu_page > -1) {
  2546.         x++;
  2547.         prtopt(&optlines, pu_page ? "/PAGE" : "/NOPAGE");
  2548.     }
  2549. #endif /* CK_TTGWSIZ */
  2550.     if (!x) prtopt(&optlines,"(no options set)");
  2551.     prtopt(&optlines,"");
  2552. }
  2553. #endif /* NOSHOW */
  2554.  
  2555. int
  2556. setpurgopts() {                         /* Set PURGE command options */
  2557.     int c, z, getval = 0;
  2558.     int
  2559.       x_keep  = -1, x_list = -1, x_page = -1,
  2560.       x_hdg   = -1, x_ask  = -1, x_dot  = -1;
  2561.  
  2562.     while (1) {
  2563.         if ((y = cmswi(purgtab,npurgtab,"Switch","",xxstring)) < 0) {
  2564.             if (y == -3)
  2565.               break;
  2566.             else
  2567.               return(y);
  2568.         }
  2569.         c = cmgbrk();
  2570.         if ((getval = (c == ':' || c == '=')) && !(cmgkwflgs() & CM_ARG)) {
  2571.             printf("?This switch does not take an argument\n");
  2572.             return(-9);
  2573.         }
  2574.         if (!getval && (cmgkwflgs() & CM_ARG)) {
  2575.             printf("?This switch requires an argument\n");
  2576.             return(-9);
  2577.         }
  2578.         switch (y) {
  2579.           case PU_KEEP:
  2580.             z = 1;
  2581.             if (c == ':' || c == '=')
  2582.               if ((y = cmnum("How many backup files to keep",
  2583.                              "1",10,&z,xxstring)) < 0)
  2584.                 return(y);
  2585.             if (z < 0 || z > MAXKEEP) {
  2586.                 printf("?Please specify a number between 0 and %d\n",
  2587.                        MAXKEEP
  2588.                        );
  2589.                 return(-9);
  2590.             }
  2591.             x_keep = z;
  2592.             break;
  2593.           case PU_LIST:
  2594.           case PU_VERB:
  2595.             x_list = 1;
  2596.             break;
  2597.           case PU_QUIE:
  2598.           case PU_NOLI:
  2599.             x_list = 0;
  2600.             break;
  2601. #ifdef CK_TTGWSIZ
  2602.           case PU_PAGE:
  2603.             x_page = 1;
  2604.             break;
  2605.           case PU_NOPA:
  2606.             x_page = 0;
  2607.             break;
  2608. #endif /* CK_TTGWSIZ */
  2609.           case PU_HDG:
  2610.             x_hdg = 1;
  2611.             break;
  2612.           case PU_NOH:
  2613.             x_hdg = 0;
  2614.             break;
  2615.           case PU_ASK:
  2616.             x_ask = 1;
  2617.             break;
  2618.           case PU_NASK:
  2619.             x_ask = 0;
  2620.             break;
  2621. #ifdef UNIXOROSK
  2622.           case PU_DOT:
  2623.             x_dot = 1;
  2624.             break;
  2625.           case PU_NODOT:
  2626.             x_dot = 0;
  2627.             break;
  2628. #endif /* UNIXOROSK */
  2629.           default:
  2630.             printf("?This option can not be set\n");
  2631.             return(-9);
  2632.         }
  2633.     }
  2634.     if ((x = cmcfm()) < 0)              /* Get confirmation */
  2635.       return(x);
  2636.     if (x_keep > -1)                    /* Set PURGE defaults. */
  2637.       pu_keep = x_keep;
  2638.     if (x_list > -1)
  2639.       pu_list = x_list;
  2640. #ifdef CK_TTGWSIZ
  2641.     if (x_page > -1)
  2642.       pu_page = x_page;
  2643. #endif /* CK_TTGWSIZ */
  2644.     if (x_hdg > -1)
  2645.       pu_hdg = x_hdg;
  2646.     if (x_ask > -1)
  2647.       pu_ask = x_ask;
  2648.     if (x_dot > -1)
  2649.       pu_dot = x_dot;
  2650.     return(success = 1);
  2651. }
  2652.  
  2653. int
  2654. dopurge() {                             /* Do the PURGE command */
  2655.     extern char ** mtchs;
  2656.     extern int xaskmore, cmd_rows, recursive;
  2657.     int simulate = 0, asking = 0;
  2658.     int listing = 0, paging = -1, lines = 0, deleting = 1, errors = 0;
  2659.     struct FDB sw, sf, cm;
  2660.     int g, i, j, k, m = 0, n, x, y, z, done = 0, count = 0, flags = 0;
  2661.     int tokeep = 0, getval = 0, havename = 0, confirmed = 0;
  2662.     int xx[MAXKEEP+1];                  /* Array of numbers to keep */
  2663.     int min = -1;
  2664.     int x_hdg = 0, fs = 0, rc = 0;
  2665.     long minsize = -1L, maxsize = -1L;
  2666.     char namebuf[CKMAXPATH+4];
  2667.     char basebuf[CKMAXPATH+4];
  2668.     char
  2669.       * pu_aft = NULL,
  2670.       * pu_bef = NULL,
  2671.       * pu_naf = NULL,
  2672.       * pu_nbf = NULL,
  2673.       * pu_exc = NULL;
  2674.     char * pxlist[8];                   /* Exception list */
  2675.  
  2676.     if (pu_keep > -1)                   /* Set PURGE defaults. */
  2677.       tokeep = pu_keep;
  2678.     if (pu_list > -1)
  2679.       listing = pu_list;
  2680. #ifdef CK_TTGWSIZ
  2681.     if (pu_page > -1)
  2682.       paging = pu_page;
  2683. #endif /* CK_TTGWSIZ */
  2684.  
  2685.     for (i = 0; i <= MAXKEEP; i++)      /* Clear this number buffer */
  2686.       xx[i] = 0;
  2687.     for (i = 0; i < 8; i++)             /* Initialize these... */
  2688.       pxlist[i] = NULL;
  2689.  
  2690.     g_matchdot = matchdot;              /* Save these... */
  2691.  
  2692.     cmfdbi(&sw,                         /* 1st FDB - PURGE switches */
  2693.            _CMKEY,                      /* fcode */
  2694.            "Filename or switch",        /* hlpmsg */
  2695.            "",                          /* default */
  2696.            "",                          /* addtl string data */
  2697.            npurgtab,                    /* addtl numeric data 1: tbl size */
  2698.            4,                           /* addtl numeric data 2: 4 = cmswi */
  2699.            xxstring,                    /* Processing function */
  2700.            purgtab,                     /* Keyword table */
  2701.            &sf                          /* Pointer to next FDB */
  2702.            );
  2703.     cmfdbi(&sf,                         /* 2nd FDB - filespec to purge */
  2704.            _CMIFI,                      /* fcode */
  2705.            "",
  2706.            "",                          /* default */
  2707.            "",                          /* addtl string data */
  2708.            0,                           /* addtl numeric data 1 */
  2709.            0,                           /* addtl numeric data 2 */
  2710.            xxstring,
  2711.            NULL,
  2712.            &cm
  2713.            );
  2714.     cmfdbi(&cm,                         /* Or premature confirmation */
  2715.            _CMCFM,                      /* fcode */
  2716.            "",                          /* hlpmsg */
  2717.            "",                          /* default */
  2718.            "",                          /* addtl string data */
  2719.            0,                           /* addtl numeric data 1 */
  2720.            0,                           /* addtl numeric data 2 */
  2721.            NULL,
  2722.            NULL,
  2723.            NULL
  2724.            );
  2725.  
  2726.     while (!havename && !confirmed) {
  2727.         x = cmfdb(&sw);                 /* Parse something */
  2728.         if (x < 0) {                    /* Error */
  2729.             rc = x;
  2730.             goto xpurge;
  2731.         } else if (cmresult.fcode == _CMKEY) {
  2732.             char c;
  2733.             c = cmgbrk();
  2734.             if ((getval = (c == ':' || c == '=')) && !(cmgkwflgs() & CM_ARG)) {
  2735.                 printf("?This switch does not take an argument\n");
  2736.                 rc = -9;
  2737.                 goto xpurge;
  2738.             }
  2739.             if (!getval && (cmgkwflgs() & CM_ARG)) {
  2740.                 printf("?This switch requires an argument\n");
  2741.                 rc = -9;
  2742.                 goto xpurge;
  2743.             }
  2744.             switch (k = cmresult.nresult) {
  2745.               case PU_KEEP:
  2746.                 z = 1;
  2747.                 if (c == ':' || c == '=') {
  2748.                     if ((y = cmnum("How many backup files to keep",
  2749.                                    "1",10,&z,xxstring)) < 0) {
  2750.                         rc = y;
  2751.                         goto xpurge;
  2752.                     }
  2753.                 }
  2754.                 if (z < 0 || z > MAXKEEP) {
  2755.                     printf("?Please specify a number between 0 and %d\n",
  2756.                            MAXKEEP
  2757.                            );
  2758.                     rc = -9;
  2759.                     goto xpurge;
  2760.                 }
  2761.                 tokeep = z;
  2762.                 break;
  2763.               case PU_LIST:
  2764.                 listing = 1;
  2765.                 break;
  2766.               case PU_NOLI:
  2767.                 listing = 0;
  2768.                 break;
  2769. #ifdef CK_TTGWSIZ
  2770.               case PU_PAGE:
  2771.                 paging = 1;
  2772.                 break;
  2773.               case PU_NOPA:
  2774.                 paging = 0;
  2775.                 break;
  2776. #endif /* CK_TTGWSIZ */
  2777.               case PU_DELE:
  2778.                 deleting = 1;
  2779.                 break;
  2780.               case PU_NODE:
  2781.                 deleting = 0;
  2782.                 simulate = 1;
  2783.                 listing = 1;
  2784.                 break;
  2785.               case PU_ASK:
  2786.                 asking = 1;
  2787.                 break;
  2788.               case PU_NASK:
  2789.                 asking = 0;
  2790.                 break;
  2791.               case PU_AFT:
  2792.               case PU_BEF:
  2793.               case PU_NAF:
  2794.               case PU_NBF:
  2795.                 if ((x = cmdate("File-time","",&s,0,xxstring)) < 0) {
  2796.                     if (x == -3) {
  2797.                         printf("?Date-time required\n");
  2798.                         rc = -9;
  2799.                     } else
  2800.                       rc = x;
  2801.                     goto xpurge;
  2802.                 }
  2803.                 fs++;
  2804.                 switch (k) {
  2805.                   case PU_AFT: makestr(&pu_aft,s); break;
  2806.                   case PU_BEF: makestr(&pu_bef,s); break;
  2807.                   case PU_NAF: makestr(&pu_naf,s); break;
  2808.                   case PU_NBF: makestr(&pu_nbf,s); break;
  2809.                 }
  2810.                 break;
  2811.               case PU_SMA:
  2812.               case PU_LAR:
  2813.                 if ((x = cmnum("File size in bytes","0",10,&y,xxstring)) < 0) {
  2814.                     rc = x;
  2815.                     goto xpurge;
  2816.                 }
  2817.                 fs++;
  2818.                 switch (cmresult.nresult) {
  2819.                   case PU_SMA: minsize = y; break;
  2820.                   case PU_LAR: maxsize = y; break;
  2821.                 }
  2822.                 break;
  2823.               case PU_DOT:
  2824.                 matchdot = 1;
  2825.                 break;
  2826.               case PU_NODOT:
  2827.                 matchdot = 0;
  2828.                 break;
  2829.               case PU_EXC:
  2830.                 if ((x = cmfld("Pattern","",&s,xxstring)) < 0) {
  2831.                     if (x == -3) {
  2832.                         printf("?Pattern required\n");
  2833.                         rc = -9;
  2834.                     } else
  2835.                       rc = x;
  2836.                     goto xpurge;
  2837.                 }
  2838.                 fs++;
  2839.                 makestr(&pu_exc,s);
  2840.                 break;
  2841.               case PU_HDG:
  2842.                 x_hdg = 1;
  2843.                 break;
  2844. #ifdef RECURSIVE
  2845.               case PU_RECU:             /* /RECURSIVE */
  2846.                 recursive = 2;
  2847.                 break;
  2848. #endif /* RECURSIVE */
  2849.               default:
  2850.                 printf("?Not implemented yet - \"%s\"\n",atmbuf);
  2851.                 rc = -9;
  2852.                 goto xpurge;
  2853.             }
  2854.         } else if (cmresult.fcode == _CMIFI) {
  2855.             havename = 1;
  2856.         } else if (cmresult.fcode == _CMCFM) {
  2857.             confirmed = 1;
  2858.         } else {
  2859.             rc = -2;
  2860.             goto xpurge;
  2861.         }
  2862.     }
  2863.     if (havename) {
  2864. #ifdef CKREGEX
  2865.         ckmakmsg(line,LINBUFSIZ,cmresult.sresult,".~[1-9]*~",NULL,NULL);
  2866. #else
  2867.         ckmakmsg(line,LINBUFSIZ,cmresult.sresult,".~*~",NULL,NULL);
  2868. #endif /* CKREGEX */
  2869.     } else {
  2870. #ifdef CKREGEX
  2871.         ckstrncpy(line,"*.~[1-9]*~",LINBUFSIZ);
  2872. #else
  2873.         ckstrncpy(line,"*.~*~",LINBUFSIZ);
  2874. #endif /* CKREGEX */
  2875.     }
  2876.     if (!confirmed) {
  2877.         if ((x = cmcfm()) < 0) {
  2878.             rc = x;
  2879.             goto xpurge;
  2880.         }
  2881.     }
  2882.     /* Parse finished - now action */
  2883.  
  2884. #ifdef CK_LOGIN
  2885.     if (isguest) {
  2886.         printf("?File deletion by guests not permitted.\n");
  2887.         rc = -9;
  2888.         goto xpurge;
  2889.     }
  2890. #endif /* CK_LOGIN */
  2891.  
  2892. #ifdef CK_TTGWSIZ
  2893.     if (paging < 0)                     /* /[NO]PAGE not given */
  2894.       paging = xaskmore;                /* so use prevailing */
  2895. #endif /* CK_TTGWSIZ */
  2896.  
  2897.     lines = 0;
  2898.     if (x_hdg > 0) {
  2899.         printf("Purging %s, keeping %d...%s\n",
  2900.                s,
  2901.                tokeep,
  2902.                simulate ? " (SIMULATION)" : "");
  2903.         lines += 2;
  2904.     }
  2905.     flags = ZX_FILONLY;
  2906.     if (recursive) flags |= ZX_RECURSE;
  2907.     n = nzxpand(line,flags);            /* Get list of backup files */
  2908.     if (tokeep < 1) {                   /* Deleting all of them... */
  2909.         for (i = 0; i < n; i++) {
  2910.             if (fs) if (fileselect(mtchs[i],
  2911.                                    pu_aft,pu_bef,pu_naf,pu_nbf,
  2912.                                    minsize,maxsize,0,8,pxlist) < 1) {
  2913.                 if (listing > 0) {
  2914.                     printf(" %s (SKIPPED)\n",mtchs[i]);
  2915. #ifdef CK_TTGWSIZ
  2916.                     if (paging)
  2917.                       if (++lines > cmd_rows - 3) {
  2918.                           if (!askmore()) goto xpurge; else lines = 0;
  2919.                       }
  2920. #endif /* CK_TTGWSIZ */
  2921.                 }
  2922.                 continue;
  2923.             }
  2924.             if (asking) {
  2925.                 int x;
  2926.                 ckmakmsg(tmpbuf,TMPBUFSIZ," Delete ",mtchs[i],"?",NULL);
  2927.                 x = getyesno(tmpbuf,1);
  2928.                 switch (x) {
  2929.                   case 0: continue;
  2930.                   case 1: break;
  2931.                   case 2: goto xpurge;
  2932.                 }
  2933.             }
  2934.             x = deleting ? zdelet(mtchs[i]) : 0;
  2935.             if (x > -1) {
  2936.                 if (listing)
  2937.                   printf(" %s (%s)\n", mtchs[i],deleting ? "OK" : "SELECTED");
  2938.                 count++;
  2939.             } else {
  2940.                 errors++;
  2941.                 if (listing)
  2942.                   printf(" %s (FAILED)\n", mtchs[i]);
  2943.             }
  2944. #ifdef CK_TTGWSIZ
  2945.             if (listing && paging)
  2946.               if (++lines > cmd_rows - 3) {
  2947.                   if (!askmore()) goto xpurge; else lines = 0;
  2948.               }
  2949. #endif /* CK_TTGWSIZ */
  2950.         }
  2951.         goto xpurge;
  2952.     }
  2953.     if (n < tokeep) {                   /* Not deleting any */
  2954.         count = 0;
  2955.         if (listing)
  2956.           printf(" Matches = %d: Not enough to purge.\n");
  2957.         goto xpurge;
  2958.     }
  2959.  
  2960.     /* General case - delete some but not others */
  2961.  
  2962.     sh_sort(mtchs,NULL,n,0,0,filecase); /* Alphabetize the list (ESSENTIAL) */
  2963.  
  2964.     g = 0;                              /* Start of current group */
  2965.     for (i = 0; i < n; i++) {           /* Go thru sorted file list */
  2966.         x = znext(namebuf);             /* Get next file */
  2967.         if (x < 1 || !namebuf[0] || i == n - 1) /* No more? */
  2968.           done = 1;                     /* NOTE: 'done' must be 0 or 1 only */
  2969.         if (fs) if (fileselect(namebuf,
  2970.                                pu_aft,pu_bef,pu_naf,pu_nbf,
  2971.                                minsize,maxsize,0,8,pxlist) < 1) {
  2972.             if (listing > 0) {
  2973.                 printf(" %s (SKIPPED)\n",namebuf);
  2974.                 if (++lines > cmd_rows - 3)
  2975.                   if (!askmore()) goto xpurge; else lines = 0;
  2976.             }
  2977.             continue;
  2978.         }
  2979.         if (x > 0)
  2980.           if ((m = bkupnum(namebuf,&z)) < 0) /* This file's backup number. */
  2981.             continue;
  2982.         for (j = 0; j < tokeep; j++) {  /* Insert in list. */
  2983.             if (m > xx[j]) {
  2984.                 for (k = tokeep - 1; k > j; k--)
  2985.                   xx[k] = xx[k-1];
  2986.                 xx[j] = m;
  2987.                 break;
  2988.             }
  2989.         }
  2990.         /* New group? */
  2991.         if (done || (i > 0 && ckstrcmp(namebuf,basebuf,z,1))) {
  2992.             if (i + done - g > tokeep) { /* Do we have enough to purge? */
  2993.                 min = xx[tokeep-1];     /* Yes, lowest backup number to keep */
  2994.                 debug(F111,"dopurge group",basebuf,min);
  2995.                 for (j = g; j < i + done; j++) { /* Go through this group */
  2996.                     x = bkupnum(mtchs[j],&z);    /* Get file backup number */
  2997.                     if (x > 0 && x < min) {      /* Below minimum? */
  2998.                         x = deleting ? zdelet(mtchs[j]) : 0;
  2999.                         if (x < 0) errors++;
  3000.                         if (listing)
  3001.                           printf(" %s (%s)\n",
  3002.                                  mtchs[j],
  3003.                                  ((x < 0) ? "ERROR" :
  3004.                                   (deleting ? "DELETED" : "SELECTED"))
  3005.                                  );
  3006.                         count++;
  3007.                     } else if (listing) /* Not below minimum - keep this one */
  3008.                       printf(" %s (KEPT)\n",mtchs[j]);
  3009. #ifdef CK_TTGWSIZ
  3010.                     if (listing && paging)
  3011.                       if (++lines > cmd_rows - 3) {
  3012.                           if (!askmore()) goto xpurge; else lines = 0;
  3013.                       }
  3014. #endif /* CK_TTGWSIZ */
  3015.                 }
  3016.             } else if (listing && paging) { /* Not enough to purge */
  3017.                 printf(" %s.~*~ (KEPT)\n",basebuf);
  3018. #ifdef CK_TTGWSIZ
  3019.                 if (++lines > cmd_rows - 3) {
  3020.                     if (!askmore()) goto xpurge; else lines = 0;
  3021.                 }
  3022. #endif /* CK_TTGWSIZ */
  3023.             }
  3024.             for (j = 0; j < tokeep; j++) /* Clear the backup number list */
  3025.               xx[j] = 0;
  3026.             g = i;                      /* Reset the group pointer */
  3027.         }
  3028.         if (done)                       /* No more files, done. */
  3029.           break;
  3030.         strncpy(basebuf,namebuf,z);     /* Set basename of this file */
  3031.         basebuf[z] = NUL;
  3032.     }
  3033.   xpurge:                               /* Common exit point */
  3034.     if (g_matchdot > -1) {
  3035.         matchdot = g_matchdot;          /* Restore these... */
  3036.         g_matchdot = -1;
  3037.     }
  3038.     if (rc < 0) return(rc);             /* Parse error */
  3039.     if (x_hdg)
  3040.       printf("Files purged: %d%s\n",
  3041.              count,
  3042.              deleting ? "" : " (not really)"
  3043.              );
  3044.     return(success = count > 0 ? 1 : (errors > 0) ? 0 : 1);
  3045. }
  3046. #endif /* CKPURGE */
  3047.  
  3048. #ifndef NOXFER
  3049. #ifndef NOLOCAL
  3050. int
  3051. doxdis(which) int which; {        /* 1 = Kermit, 2 = FTP */
  3052.     extern int nolocal;
  3053.     int x, y = 0, z;
  3054. #ifdef NEWFTP
  3055.     extern int ftp_dis;
  3056. #endif /* NEWFTP */
  3057.  
  3058. #ifdef COMMENT
  3059.     char *s;
  3060. #endif /* COMMENT */
  3061.  
  3062.     if ((x = cmkey(fdtab,nfdtab,"file transfer display style","",
  3063.                    xxstring)) < 0)
  3064.       return(x);
  3065. #ifdef CK_PCT_BAR
  3066.     if ((y = cmkey(fdftab,2,"","thermometer",xxstring)) < 0)
  3067.       return(y);
  3068. #endif /* CK_PCT_BAR */
  3069.     if ((z = cmcfm()) < 0) return(z);
  3070. #ifdef CK_CURSES
  3071.     if (x == XYFD_C) {                  /* FULLSCREEN */
  3072. #ifdef COMMENT
  3073. #ifndef MYCURSES
  3074.         extern char * trmbuf;           /* Real curses */
  3075.         int z;
  3076. #endif /* MYCURSES */
  3077. #endif /* COMMENT */
  3078.  
  3079.         if (nolocal)                    /* Nothing to do in this case */
  3080.       return(success = 1);
  3081.  
  3082. #ifdef COMMENT
  3083. #ifndef MYCURSES
  3084. #ifndef VMS
  3085.         s = getenv("TERM");
  3086.         debug(F110,"doxdis TERM",s,0);
  3087.         if (!s) s = "";
  3088.         fxdinit(x);
  3089.         if (*s && trmbuf) {             /* Don't call tgetent */
  3090.             z = tgetent(trmbuf,s);      /* if trmbuf not allocated */
  3091.             debug(F111,"doxdis tgetent",s,z);
  3092.         } else {
  3093.             z = 0;
  3094.             debug(F110,"doxdis tgetent skipped",s,0);
  3095.         }
  3096.         if (z < 1) {
  3097.             printf("Sorry, terminal type unknown: \"%s\"\n",s);
  3098.             return(success = 0);
  3099.         }
  3100. #endif /* VMS */
  3101. #endif /* MYCURSES */
  3102. #else
  3103.         fxdinit(x);
  3104. #endif /* COMMENT */
  3105.  
  3106. #ifdef CK_PCT_BAR
  3107.         thermometer = y;
  3108. #endif /* CK_PCT_BAR */
  3109.  
  3110.         line[0] = '\0';                 /* (What's this for?) */
  3111.     }
  3112. #endif /* CK_CURSES */
  3113.     if (which == 1)            /* It's OK. */
  3114.       fdispla = x;
  3115. #ifdef NEWFTP
  3116.     else
  3117.       ftp_dis = x;
  3118. #endif /* NEWFTP */
  3119.     return(success = 1);
  3120. }
  3121. #endif /* NOLOCAL */
  3122. #endif /* NOXFER */
  3123.  
  3124. int
  3125. setfil(rmsflg) int rmsflg; {
  3126. #ifdef COMMENT
  3127.     extern int en_del;
  3128. #endif /* COMMENT */
  3129. #ifndef NOXFER
  3130.     if (rmsflg) {
  3131.         if ((y = cmkey(rfiltab,nrfilp,"Remote file parameter","",
  3132.                        xxstring)) < 0) {
  3133.             if (y == -3) {
  3134.                 printf("?Remote file parameter required\n");
  3135.                 return(-9);
  3136.             } else return(y);
  3137.         }
  3138.     } else {
  3139. #endif /* NOXFER */
  3140.         if ((y = cmkey(filtab,nfilp,"File parameter","",xxstring)) < 0)
  3141.           return(y);
  3142. #ifndef NOXFER
  3143.     }
  3144. #endif /* NOXFER */
  3145.     switch (y) {
  3146. #ifdef COMMENT                          /* Not needed */
  3147.       case XYFILB:                      /* Blocksize */
  3148.         if ((y = cmnum("file block size",ckitoa(DBLKSIZ),10,&z,xxstring)) < 0)
  3149.           return(y);
  3150.         if ((x = cmcfm()) < 0) return(x);
  3151.         if (rmsflg) {
  3152.             sstate = setgen('S', "311", ckitoa(z), "");
  3153.             return((int) sstate);
  3154.         } else {
  3155.             fblksiz = z;
  3156.             return(success = 1);
  3157.         }
  3158. #endif /* COMMENT */
  3159.  
  3160. #ifndef NOXFER
  3161.       case XYFILS:                      /* Byte size */
  3162.         if ((y = cmnum("file byte size (7 or 8)","8",10,&z,xxstring)) < 0)
  3163.           return(y);
  3164.         if (z != 7 && z != 8) {
  3165.             printf("\n?The choices are 7 and 8\n");
  3166.             return(0);
  3167.         }
  3168.         if ((y = cmcfm()) < 0) return(y);
  3169.         if (z == 7) fmask = 0177;
  3170.         else if (z == 8) fmask = 0377;
  3171.         return(success = 1);
  3172.  
  3173. #ifndef NOCSETS
  3174.       case XYFILC: {                    /* Character set */
  3175.           char * csetname = NULL;
  3176.           extern int
  3177.             r_cset, s_cset, afcset[];   /* SEND CHARACTER-SET AUTO or MANUAL */
  3178.  
  3179.           struct FDB kw, fl;
  3180.           cmfdbi(&kw,                   /* First FDB - command switches */
  3181.                  _CMKEY,                /* fcode */
  3182.                  rmsflg ? "server character-set name" : "",  /* help */
  3183.                  "",                    /* default */
  3184.                  "",                    /* addtl string data */
  3185.                  nfilc,                 /* addtl numeric data 1: tbl size */
  3186.                  0,                     /* addtl numeric data 2: 0 = keyword */
  3187.                  xxstring,              /* Processing function */
  3188.                  fcstab,                /* Keyword table */
  3189.                  rmsflg ? &fl : NULL    /* Pointer to next FDB */
  3190.            );
  3191.           cmfdbi(&fl,                   /* Anything that doesn't match */
  3192.                  _CMFLD,                /* fcode */
  3193.                  "",                    /* hlpmsg */
  3194.                  "",                    /* default */
  3195.                  "",                    /* addtl string data */
  3196.                  0,                     /* addtl numeric data 1 */
  3197.                  0,                     /* addtl numeric data 2 */
  3198.                  xxstring,
  3199.                  NULL,
  3200.                  NULL
  3201.                  );
  3202.           if ((x = cmfdb(&kw)) < 0)
  3203.             return(x);
  3204.           if (cmresult.fcode == _CMKEY) {
  3205.               x = cmresult.nresult;
  3206.               csetname = fcsinfo[x].keyword;
  3207.           } else {
  3208.               ckstrncpy(line,cmresult.sresult,LINBUFSIZ);
  3209.               csetname = line;
  3210.           }
  3211.           if ((z = cmcfm()) < 0) return(z);
  3212.           if (rmsflg) {
  3213.               sstate = setgen('S', "320", csetname, "");
  3214.               return((int) sstate);
  3215.           }
  3216.           fcharset = x;
  3217.           if (s_cset == XMODE_A)        /* If SEND CHARACTER-SET is AUTO */
  3218.             if (x > -1 && x <= MAXFCSETS)
  3219.               if (afcset[x] > -1 && afcset[x] <= MAXTCSETS)
  3220.                 tcharset = afcset[x]; /* Pick corresponding xfer charset */
  3221.           setxlatype(tcharset,fcharset); /* Translation type */
  3222.           /* If I say SET FILE CHARACTER-SET blah, I want to be blah! */
  3223.           r_cset = XMODE_M;             /* Don't switch incoming set! */
  3224.           x = fcsinfo[fcharset].size;   /* Also set default x-bit charset */
  3225.           if (x == 128)                 /* 7-bit... */
  3226.             dcset7 = fcharset;
  3227.           else if (x == 256)            /* 8-bit... */
  3228.             dcset8 = fcharset;
  3229.           return(success = 1);
  3230.       }
  3231. #endif /* NOCSETS */
  3232.  
  3233. #ifndef NOLOCAL
  3234.       case XYFILD:                      /* Display */
  3235.         return(doxdis(1));        /* 1 == kermit */
  3236. #endif /* NOLOCAL */
  3237. #endif /* NOXFER */
  3238.  
  3239.       case XYFILA:                      /* End-of-line */
  3240. #ifdef NLCHAR
  3241.         s = "";
  3242.         if (NLCHAR == 015)
  3243.           s = "cr";
  3244.         else if (NLCHAR == 012)
  3245.           s = "lf";
  3246.         if ((x = cmkey(eoltab, neoltab,
  3247.                        "local text-file line terminator",s,xxstring)) < 0)
  3248.           return(x);
  3249. #else
  3250.         if ((x = cmkey(eoltab, neoltab,
  3251.                        "local text-file line terminator","crlf",xxstring)) < 0)
  3252.           return(x);
  3253. #endif /* NLCHAR */
  3254.         if ((z = cmcfm()) < 0) return(z);
  3255.         feol = (CHAR) x;
  3256.         return(success = 1);
  3257.  
  3258. #ifndef NOXFER
  3259.       case XYFILN:                      /* Names */
  3260.         if ((x = cmkey(fntab,nfntab,"how to handle filenames","converted",
  3261.                        xxstring)) < 0)
  3262.           return(x);
  3263.         if ((z = cmcfm()) < 0) return(z);
  3264.         if (rmsflg) {
  3265.             sstate = setgen('S', "301", ckitoa(1 - x), "");
  3266.             return((int) sstate);
  3267.         } else {
  3268.             ptab[protocol].fncn = x;    /* Set structure */
  3269.             fncnv = x;                  /* Set variable */
  3270.             f_save = x;                 /* And set "permanent" variable */
  3271.             return(success = 1);
  3272.         }
  3273.  
  3274.       case XYFILR:                      /* Record length */
  3275.         if ((y = cmnum("file record length",
  3276.                        ckitoa(DLRECL),10,&z,xxstring)) < 0)
  3277.           return(y);
  3278.         if ((x = cmcfm()) < 0) return(x);
  3279.         if (rmsflg) {
  3280.             sstate = setgen('S', "312", ckitoa(z), "");
  3281.             return((int) sstate);
  3282.         } else {
  3283.             frecl = z;
  3284.             return(success = 1);
  3285.         }
  3286.  
  3287. #ifdef COMMENT
  3288.       case XYFILO:                      /* Organization */
  3289.         if ((x = cmkey(forgtab,nforg,"file organization","sequential",
  3290.                        xxstring)) < 0)
  3291.           return(x);
  3292.         if ((y = cmcfm()) < 0) return(y);
  3293.         if (rmsflg) {
  3294.             sstate = setgen('S', "314", ckitoa(x), "");
  3295.             return((int) sstate);
  3296.         } else {
  3297.             forg = x;
  3298.             return(success = 1);
  3299.         }
  3300. #endif /* COMMENT */
  3301.  
  3302. #ifdef COMMENT                          /* Not needed */
  3303.       case XYFILF:                      /* Format */
  3304.         if ((x = cmkey(frectab,nfrec,"file record format","stream",
  3305.                        xxstring)) < 0)
  3306.           return(x);
  3307.         if ((y = cmcfm()) < 0) return(y);
  3308.         if (rmsflg) {
  3309.             sstate = setgen('S', "313", ckitoa(x), "");
  3310.             return((int) sstate);
  3311.         } else {
  3312.             frecfm = x;
  3313.             return(success = 1);
  3314.         }
  3315. #endif /* COMMENT */
  3316.  
  3317. #ifdef COMMENT
  3318.       case XYFILP:                      /* Printer carriage control */
  3319.         if ((x = cmkey(fcctab,nfcc,"file carriage control","newline",
  3320.                        xxstring)) < 0)
  3321.           return(x);
  3322.         if ((y = cmcfm()) < 0) return(y);
  3323.         if (rmsflg) {
  3324.             sstate = setgen('S', "315", ckitoa(x), "");
  3325.             return((int) sstate);
  3326.         } else {
  3327.             fcctrl = x;
  3328.             return(success = 1);
  3329.         }
  3330. #endif /* COMMENT */
  3331. #endif /* NOXFER */
  3332.  
  3333.       case XYFILT:                      /* Type */
  3334.         if ((x = cmkey(rmsflg ? rfttab  : fttab,
  3335.                        rmsflg ? nrfttyp : nfttyp,
  3336.                        "type of file transfer","text",xxstring)) < 0)
  3337.           return(x);
  3338.  
  3339. #ifdef VMS
  3340.         /* Allow VMS users to choose record format for binary files */
  3341.         if ((x == XYFT_B) && (rmsflg == 0)) {
  3342.             if ((x = cmkey(fbtab,nfbtyp,"VMS record format","fixed",
  3343.                            xxstring)) < 0)
  3344.               return(x);
  3345.         }
  3346. #endif /* VMS */
  3347.         if ((y = cmcfm()) < 0) return(y);
  3348.         binary = x;
  3349.         b_save = x;
  3350. #ifdef MAC
  3351.         (void) mac_setfildflg(binary);
  3352. #endif /* MAC */
  3353. #ifndef NOXFER
  3354.         if (rmsflg) {
  3355.             /* Allow for LABELED in VMS & OS/2 */
  3356.             sstate = setgen('S', "300", ckitoa(x), "");
  3357.             return((int) sstate);
  3358.         } else {
  3359. #endif /* NOXFER */
  3360.             return(success = 1);
  3361. #ifndef NOXFER
  3362.         }
  3363. #endif /* NOXFER */
  3364.  
  3365. #ifndef NOXFER
  3366.       case XYFILX:                      /* Collision Action */
  3367.         if ((x = cmkey(colxtab,ncolx,"Filename collision action","backup",
  3368.                        xxstring)) < 0)
  3369.           return(x);
  3370.         if ((y = cmcfm()) < 0) return(y);
  3371. #ifdef CK_LOGIN
  3372.         if (isguest) {
  3373.             /* Don't let guests change existing files */
  3374.             printf("?This command not valid for guests\n");
  3375.             return(-9);
  3376.         }
  3377. #endif /* CK_LOGIN */
  3378. #ifdef COMMENT
  3379.         /* Not appropriate - DISABLE DELETE only refers to server */
  3380.         if ((x == XYFX_X || x == XYFX_B || x == XYFX_U || x == XYFX_A) &&
  3381.             (!ENABLED(en_del))) {
  3382.             printf("?Sorry, file deletion is disabled.\n");
  3383.             return(-9);
  3384.         }
  3385. #endif /* COMMENT */
  3386.         fncact = x;
  3387.         ptab[protocol].fnca = x;
  3388.         if (rmsflg) {
  3389.             sstate = setgen('S', "302", ckitoa(fncact), "");
  3390.             return((int) sstate);
  3391.         } else {
  3392.             if (fncact == XYFX_R) ckwarn = 1; /* FILE WARNING implications */
  3393.             if (fncact == XYFX_X) ckwarn = 0; /* ... */
  3394.             return(success = 1);
  3395.         }
  3396.  
  3397.       case XYFILW:                      /* Warning/Write-Protect */
  3398.         if ((x = seton(&ckwarn)) < 0) return(x);
  3399.         if (ckwarn)
  3400.           fncact = XYFX_R;
  3401.         else
  3402.           fncact = XYFX_X;
  3403.         return(success = 1);
  3404.  
  3405. #ifdef CK_LABELED
  3406.       case XYFILL:                      /* LABELED FILE parameters */
  3407.         if ((x = cmkey(lbltab,nlblp,"Labeled file feature","",
  3408.                        xxstring)) < 0)
  3409.           return(x);
  3410.         if ((success = seton(&y)) < 0)
  3411.           return(success);
  3412.         if (y)                          /* Set or reset the selected bit */
  3413.           lf_opts |= x;                 /* in the options bitmask. */
  3414.         else
  3415.           lf_opts &= ~x;
  3416.         return(success);
  3417. #endif /* CK_LABELED */
  3418.  
  3419.       case XYFILI: {                    /* INCOMPLETE */
  3420.           extern struct keytab ifdatab[];
  3421.           extern int keep;
  3422.           if ((y = cmkey(ifdatab,3,"","auto",xxstring)) < 0) return(y);
  3423.           if ((x = cmcfm()) < 0) return(x);
  3424.           if (rmsflg) {
  3425.               sstate = setgen('S',
  3426.                               "310",
  3427.                               y == 0 ? "0" : (y == 1 ? "1" : "2"),
  3428.                               ""
  3429.                               );
  3430.               return((int) sstate);
  3431.           } else {
  3432.               keep = y;
  3433.               return(success = 1);
  3434.           }
  3435.       }
  3436.  
  3437. #ifdef CK_TMPDIR
  3438.       case XYFILG: {                    /* Download directory */
  3439.           int x;
  3440.           char *s;
  3441. #ifdef ZFNQFP
  3442.           struct zfnfp * fnp;
  3443. #endif /* ZFNQFP */
  3444. #ifdef MAC
  3445.           char temp[34];
  3446. #endif /* MAC */
  3447.  
  3448. #ifdef GEMDOS
  3449.           if ((x = cmdir("Name of local directory, or carriage return",
  3450.                          "",&s,
  3451.                          NULL)) < 0 ) {
  3452.               if (x != -3)
  3453.                 return(x);
  3454.           }
  3455. #else
  3456. #ifdef OS2
  3457.           if ((x = cmdir("Name of PC disk and/or directory,\n\
  3458.        or press the Enter key to use current directory",
  3459.                          "",&s,xxstring)) < 0 ) {
  3460.               if (x != -3)
  3461.                 return(x);
  3462.           }
  3463. #else
  3464. #ifdef MAC
  3465.           x = ckstrncpy(temp,zhome(),32);
  3466.           if (x > 0) if (temp[x-1] != ':') { temp[x] = ':'; temp[x+1] = NUL; }
  3467.           if ((x = cmtxt("Name of Macintosh volume and/or folder,\n\
  3468.  or press the Return key for the desktop on the boot disk",
  3469.                          temp,&s, xxstring)) < 0 )
  3470.             return(x);
  3471. #else
  3472.           if ((x = cmdir("Name of local directory, or carriage return",
  3473.                          "", &s, xxstring)) < 0 ) {
  3474.               if (x != -3)
  3475.                 return(x);
  3476.           }
  3477. #endif /* MAC */
  3478. #endif /* OS2 */
  3479. #endif /* GEMDOS */
  3480.           debug(F110,"download dir",s,0);
  3481.  
  3482. #ifndef MAC
  3483.           if (x == 2) {
  3484.               printf("?Wildcards not allowed in directory name\n");
  3485.               return(-9);
  3486.           }
  3487. #endif /* MAC */
  3488.  
  3489. #ifdef ZFNQFP
  3490.           if ((fnp = zfnqfp(s,TMPBUFSIZ - 1,tmpbuf))) {
  3491.               if (fnp->fpath)
  3492.                 if ((int) strlen(fnp->fpath) > 0)
  3493.                   s = fnp->fpath;
  3494.           }
  3495.           debug(F110,"download zfnqfp",s,0);
  3496. #endif /* ZFNQFP */
  3497.  
  3498.           ckstrncpy(line,s,LINBUFSIZ);  /* Make a safe copy */
  3499. #ifndef MAC
  3500.           if ((x = cmcfm()) < 0)        /* Get confirmation */
  3501.             return(x);
  3502. #endif /* MAC */
  3503.  
  3504. #ifdef CK_LOGIN
  3505.         if (isguest) {
  3506.             /* Don't let guests change existing files */
  3507.             printf("?This command not valid for guests\n");
  3508.             return(-9);
  3509.         }
  3510. #endif /* CK_LOGIN */
  3511.           x = strlen(s);
  3512.  
  3513.           if (x) {
  3514. #ifdef datageneral
  3515.               if (s[x-1] == ':')        /* homdir ends in colon, */
  3516.                 s[x-1] = NUL;           /* and "dir" doesn't like that... */
  3517. #endif /* datageneral */
  3518.               makestr(&dldir,s);
  3519.           } else
  3520.             makestr(&dldir,NULL);       /* dldir is NULL when not assigned */
  3521.  
  3522.           return(success = 1);
  3523.       }
  3524. #endif /* CK_TMPDIR */
  3525.       case XYFILY:
  3526.         return(setdest());
  3527. #endif /* NOXFER */
  3528.  
  3529. #ifdef CK_CTRLZ
  3530.       case XYFILV: {                    /* EOF */
  3531.           extern int eofmethod;
  3532.           if ((x = cmkey(eoftab,3,"end-of-file detection method","",
  3533.                          xxstring)) < 0)
  3534.             return(x);
  3535.           if ((y = cmcfm()) < 0)
  3536.             return(y);
  3537.           eofmethod = x;
  3538.           return(success = 1);
  3539.       }
  3540. #endif /* CK_CTRLZ */
  3541.  
  3542. #ifndef NOXFER
  3543. #ifdef UNIX
  3544.       case XYFILH: {                    /* OUTPUT */
  3545.           extern int zofbuffer, zobufsize, zofblock;
  3546. #ifdef DYNAMIC
  3547.           extern char * zoutbuffer;
  3548. #endif /* DYNAMIC */
  3549.  
  3550.           if ((x = cmkey(zoftab,nzoftab,"output file writing method","",
  3551.                          xxstring)) < 0)
  3552.             return(x);
  3553.           if (x == ZOF_BUF || x == ZOF_NBUF) {
  3554.               if ((y = cmnum("output buffer size","32768",10,&z,xxstring)) < 0)
  3555.                 return(y);
  3556.               if (z < 1) {
  3557.                   printf("?Bad size - %d\n", z);
  3558.                   return(-9);
  3559.               }
  3560.           }
  3561.           if ((y = cmcfm()) < 0) return(y);
  3562.           switch (x) {
  3563.             case ZOF_BUF:
  3564.             case ZOF_NBUF:
  3565.               zofbuffer = (x == ZOF_BUF);
  3566.               zobufsize = z;
  3567.               break;
  3568.             case ZOF_BLK:
  3569.             case ZOF_NBLK:
  3570.               zofblock = (x == ZOF_BLK);
  3571.               break;
  3572.           }
  3573. #ifdef DYNAMIC
  3574.           if (zoutbuffer) free(zoutbuffer);
  3575.           if (!(zoutbuffer = (char *)malloc(z))) {
  3576.               printf("MEMORY ALLOCATION ERROR - FATAL\n");
  3577.               doexit(BAD_EXIT,-1);
  3578.           } else
  3579.             zobufsize = z;
  3580. #else
  3581.           if (z <= OBUFSIZE) {
  3582.               zobufsize = z;
  3583.           } else {
  3584.               printf("?Sorry, %d is too big - %d is the maximum\n",z,OBUFSIZE);
  3585.               return(-9);
  3586.           }
  3587. #endif /* DYNAMIC */
  3588.           return(success = 1);
  3589.       }
  3590. #endif /* UNIX */
  3591.  
  3592. #ifdef PATTERNS
  3593.       case XYFIBP:                      /* BINARY-PATTERN */
  3594.       case XYFITP: {                    /* TEXT-PATTERN */
  3595.           char * tmp[FTPATTERNS];
  3596.           int i, n = 0;
  3597.           while (n < FTPATTERNS) {
  3598.               tmp[n] = NULL;
  3599.               if ((x = cmfld("Pattern","",&s,xxstring)) < 0)
  3600.                 break;
  3601.               ckstrncpy(line,s,LINBUFSIZ);
  3602.               s = brstrip(line);
  3603.               makestr(&(tmp[n++]),s);
  3604.           }
  3605.           if (x == -3) x = cmcfm();
  3606.           for (i = 0; i <= n; i++) {
  3607.               if (x > -1) {
  3608.                   if (y == XYFIBP)
  3609.                     makestr(&(binpatterns[i]),tmp[i]);
  3610.                   else
  3611.                     makestr(&(txtpatterns[i]),tmp[i]);
  3612.               }
  3613.               free(tmp[i]);
  3614.           }
  3615.           if (y == XYFIBP)              /* Null-terminate the list */
  3616.             makestr(&(binpatterns[i]),NULL);
  3617.           else
  3618.             makestr(&(txtpatterns[i]),NULL);
  3619.           return(x);
  3620.       }
  3621.  
  3622.       case XYFIPA:                      /* PATTERNS */
  3623.         if ((x = setonaut(&patterns)) < 0)
  3624.           return(x);
  3625.         return(success = 1);
  3626. #endif /* PATTERNS */
  3627. #endif /* NOXFER */
  3628.  
  3629. #ifdef UNICODE
  3630.       case XYFILU: {                    /* UCS */
  3631.           extern int ucsorder, ucsbom, byteorder;
  3632.           if ((x = cmkey(ucstab,nucstab,"","",xxstring)) < 0)
  3633.             return(x);
  3634.           switch (x) {
  3635.             case UCS_BYT:
  3636.               if ((y = cmkey(botab,nbotab,
  3637.                              "Byte order",
  3638.                              byteorder ? "little-endian" : "big-endian",
  3639.                              xxstring
  3640.                              )
  3641.                    ) < 0)
  3642.                 return(y);
  3643.               if ((x = cmcfm()) < 0)
  3644.                 return(x);
  3645.               ucsorder = y;
  3646.               return(success = 1);
  3647.             case UCS_BOM:
  3648.               if ((y = cmkey(onoff,2,"","on",xxstring)) < 0)
  3649.                 return(y);
  3650.               if ((x = cmcfm()) < 0)
  3651.                 return(x);
  3652.               ucsbom = y;
  3653.               return(success = 1);
  3654.             default:
  3655.               return(-2);
  3656.           }
  3657.       }
  3658. #endif /* UNICODE */
  3659.  
  3660. #ifndef datageneral
  3661.       case XYF_INSP: {                  /* SCAN (INSPECTION) */
  3662.           extern int filepeek, nscanfile;
  3663.           if ((x = cmkey(onoff,2,"","on",xxstring)) < 0)
  3664.             return(x);
  3665.           if (y) {
  3666.               if ((y = cmnum("How much to scan",ckitoa(SCANFILEBUF),
  3667.                              10,&z,xxstring)) < 0)
  3668.                 return(y);
  3669.           }
  3670.           if ((y = cmcfm()) < 0)
  3671.             return(y);
  3672. #ifdef VMS
  3673.           filepeek = 0;
  3674.           nscanfile = 0;
  3675.           return(success = 0);
  3676. #else
  3677.           filepeek = x;
  3678.           nscanfile = z;
  3679.           return(success = 1);
  3680. #endif /* VMS */
  3681.       }
  3682. #endif /* datageneral */
  3683.  
  3684.       case XYF_DFLT:
  3685.         y = 0;
  3686. #ifndef NOCSETS
  3687.         if ((y = cmkey(fdfltab,nfdflt,"","",xxstring)) < 0)
  3688.           return(y);
  3689.         if (y == 7 || y == 8) {
  3690.             if (y == 7)
  3691.               s = fcsinfo[dcset7].keyword;
  3692.             else
  3693.               s = fcsinfo[dcset8].keyword;
  3694.             if ((x = cmkey(fcstab,nfilc,"character-set",s,xxstring)) < 0)
  3695.               return(x);
  3696.         }
  3697.         ckstrncpy(line,fcsinfo[x].keyword,LINBUFSIZ);
  3698.         s = line;
  3699. #endif /* NOCSETS */
  3700.         if ((z = cmcfm()) < 0)
  3701.           return(z);
  3702.         switch (y) {
  3703. #ifndef NOCSETS
  3704.           case 7:
  3705.             if (fcsinfo[x].size != 128) {
  3706.                 printf("%s - Not a 7-bit set\n",s);
  3707.                 return(-9);
  3708.             }
  3709.             dcset7 = x;
  3710.             break;
  3711.           case 8:
  3712.             if (fcsinfo[x].size != 256) {
  3713.                 printf("%s - Not an 8-bit set\n",s);
  3714.                 return(-9);
  3715.             }
  3716.             dcset8 = x;
  3717.             break;
  3718. #endif /* NOCSETS */
  3719.           default:
  3720.             return(-2);
  3721.         }
  3722.         return(success = 1);
  3723.  
  3724. #ifndef NOXFER
  3725.       case 9997:                        /* FASTLOOKUPS */
  3726.         return(success = seton(&stathack));
  3727. #endif /* NOXFER */
  3728.  
  3729. #ifdef UNIX
  3730. #ifdef DYNAMIC
  3731.       case XYF_LSIZ: {                  /* LISTSIZE */
  3732.           int zz;
  3733.           y = cmnum("Maximum number of filenames","",10,&x,xxstring);
  3734.           if ((x = setnum(&zz,x,y,-1)) < 0)
  3735.             return(x);
  3736.           if (zsetfil(zz,3) < 0) {
  3737.               printf("?Memory allocation failure\n");
  3738.               return(-9);
  3739.           }
  3740.           return(success = 1);
  3741.       }
  3742.       case XYF_SSPA: {                  /* STRINGSPACE */
  3743.           int zz;
  3744.           y = cmnum("Number of characters for filename list",
  3745.                     "",10,&x,xxstring);
  3746.           if ((x = setnum(&zz,x,y,-1)) < 0)
  3747.             return(x);
  3748.           if (zsetfil(zz,1) < 0) {
  3749.               printf("?Memory allocation failure\n");
  3750.               return(-9);
  3751.           }
  3752.           return(success = 1);
  3753.       }
  3754.  
  3755. #endif /* DYNAMIC */
  3756. #endif /* UNIX */
  3757.  
  3758.       default:
  3759.         printf("?unexpected file parameter\n");
  3760.         return(-2);
  3761.     }
  3762. }
  3763.  
  3764. #ifndef NOLOCAL
  3765. #ifdef OS2
  3766. /* MS-DOS KERMIT compatibility modes */
  3767. int
  3768. setmsk() {
  3769.     if ((y = cmkey(msktab,nmsk,"MS-DOS Kermit compatibility mode",
  3770.                     "keycodes",xxstring)) < 0) return(y);
  3771.  
  3772.     switch ( y ) {
  3773. #ifdef COMMENT
  3774.       case MSK_COLOR:
  3775.         return(seton(&mskcolors));
  3776. #endif /* COMMENT */
  3777.       case MSK_KEYS:
  3778.         return(seton(&mskkeys));
  3779.       default:                          /* Shouldn't get here. */
  3780.         return(-2);
  3781.     }
  3782. }
  3783. #endif /* OS2 */
  3784.  
  3785. int
  3786. settrmtyp() {
  3787. #ifdef OS2
  3788. #ifdef TNCODE
  3789.     extern int ttnum;                    /* Last Telnet Terminal Type sent */
  3790.     extern int ttnumend;                 /* Has end of list been found */
  3791. #endif /* TNCODE */
  3792.     if ((x = cmkey(ttyptab,nttyp,"","vt320",xxstring)) < 0)
  3793.       return(x);
  3794.     if ((y = cmcfm()) < 0)
  3795.       return(y);
  3796.     settermtype(x,1);
  3797. #ifdef TNCODE
  3798.     /* So we send the correct terminal name to the host if it asks for it */
  3799.     ttnum = -1;                         /* Last Telnet Terminal Type sent */
  3800.     ttnumend = 0;                       /* end of list not found */
  3801. #endif /* TNCODE */
  3802.     return(success = 1);
  3803. #else  /* Not OS2 */
  3804.     printf(
  3805. "\n Sorry, this version of C-Kermit does not support the SET TERMINAL TYPE\n");
  3806.     printf(
  3807. " command.  Type \"help set terminal\" for further information.\n");
  3808. #endif /* OS2 */
  3809.     return(success = 0);
  3810. }
  3811.  
  3812. #ifdef CKTIDLE
  3813. static char iactbuf[132];
  3814.  
  3815. char *
  3816. getiact() {
  3817.     switch (tt_idleact) {
  3818.       case IDLE_RET:  return("return");
  3819.       case IDLE_EXIT: return("exit");
  3820.       case IDLE_HANG: return("hangup");
  3821. #ifdef TNCODE
  3822.       case IDLE_TNOP: return("Telnet NOP");
  3823.       case IDLE_TAYT: return("Telnet AYT");
  3824. #endif /* TNCODE */
  3825.  
  3826.       case IDLE_OUT: {
  3827.           int c, k, n;
  3828.           char * p, * q, * t;
  3829.           k = ckstrncpy(iactbuf,"output ",132);
  3830.           n = k;
  3831.           q = &iactbuf[k];
  3832.           p = tt_idlestr;
  3833.           if (!p) p = "";
  3834.           if (!*p) return("output (nothing)");
  3835.           while ((c = *p++) && n < 131) {
  3836.               c &= 0xff;
  3837.               if (c == '\\') {
  3838.                   if (n > 130) break;
  3839.                   *q++ = '\\';
  3840.                   *q++ = '\\';
  3841.                   *q = NUL;
  3842.                   n += 2;
  3843.               } else if ((c > 31 && c < 127) || c > 159) {
  3844.                   *q++ = c;
  3845.                   *q = NUL;
  3846.                   n++;
  3847.               } else {
  3848.                   if (n > (131 - 6))
  3849.                     break;
  3850.                   sprintf(q,"\\{%d}",c);
  3851.                   k = strlen(q);
  3852.                   q += k;
  3853.                   n += k;
  3854.                   *q = NUL;
  3855.               }
  3856.           }
  3857.           *q = NUL;
  3858. #ifdef OS2
  3859.           k = tt_cols[VTERM];
  3860. #else
  3861.           k = tt_cols;
  3862. #endif /* OS2 */
  3863.           if (n > k - 52) {
  3864.               n = k - 52;
  3865.               iactbuf[n-2] = '.';
  3866.               iactbuf[n-1] = '.';
  3867.               iactbuf[n] = NUL;
  3868.           }
  3869.           return(iactbuf);
  3870.       }
  3871.       default: return("unknown");
  3872.     }
  3873. }
  3874. #endif /* CKTIDLE */
  3875.  
  3876. #ifndef NOCSETS
  3877. VOID
  3878. setlclcharset(x) int x; {
  3879.     int i;
  3880.     tcsl = y;                   /* Local character set */
  3881. #ifdef OS2
  3882.     for (i = 0; i < 4; i++) {
  3883.         G[i].init = TRUE;
  3884.         x = G[i].designation;
  3885.         G[i].c1 = (x != tcsl) && cs_is_std(x);
  3886.         x = G[i].def_designation;
  3887.         G[i].def_c1 = (x != tcsl) && cs_is_std(x);
  3888.     }
  3889. #endif /* OS2 */
  3890. }
  3891.  
  3892. VOID
  3893. setremcharset(x, z) int x, z; {
  3894.     int i;
  3895.  
  3896. #ifdef KUI
  3897.     KuiSetProperty( KUI_TERM_REMCHARSET, (long) x, (long) z ) ;
  3898. #endif /* KUI */
  3899. #ifdef UNICODE
  3900.     if (x == TX_TRANSP)
  3901. #else /* UNICODE */
  3902.     if (x == FC_TRANSP)
  3903. #endif /* UNICODE */
  3904.     {                           /* TRANSPARENT? */
  3905. #ifndef OS2
  3906.         tcsr = tcsl;            /* Make both sets the same */
  3907. #else /* OS2 */
  3908. #ifdef CKOUNI
  3909.         tt_utf8 = 0;            /* Turn off UTF8 flag */
  3910.         tcsr = tcsl = dec_kbd = TX_TRANSP; /* No translation */
  3911.         tcs_transp = 1;
  3912.  
  3913.         if (!cs_is_nrc(tcsl)) {
  3914.             G[0].def_designation = G[0].designation = TX_ASCII;
  3915.             G[0].init = TRUE;
  3916.             G[0].def_c1 = G[0].c1 = FALSE;
  3917.             G[0].size = cs94;
  3918.             G[0].national = FALSE;
  3919.         }
  3920.         for (i = cs_is_nrc(tcsl) ? 0 : 1; i < 4; i++) {
  3921.             G[i].def_designation = G[i].designation = tcsl;
  3922.             G[i].init = TRUE;
  3923.             G[i].def_c1 = G[i].c1 = FALSE;
  3924.             switch (cs_size(G[i].designation)) { /* 94, 96, or 128 */
  3925.             case 128:
  3926.             case 96:
  3927.                 G[i].size = G[i].def_size = cs96;
  3928.                 break;
  3929.             case 94:
  3930.                 G[i].size = G[i].def_size = cs94;
  3931.                 break;
  3932.             default:
  3933.                 G[i].size = G[i].def_size = csmb;
  3934.                 break;
  3935.             }
  3936.             G[i].national = cs_is_nrc(x);
  3937.         }
  3938. #else /* CKOUNI */
  3939.         tcsr = tcsl;            /* Make both sets the same */
  3940.         for (i = 0; i < 4; i++) {
  3941.             G[i].def_designation = G[i].designation = FC_TRANSP;
  3942.             G[i].init = FALSE;
  3943.             G[i].size = G[i].def_size = cs96;
  3944.             G[i].c1 = G[i].def_c1 = FALSE;
  3945.             G[i].rtoi = NULL;
  3946.             G[i].itol = NULL;
  3947.             G[i].ltoi = NULL;
  3948.             G[i].itor = NULL;
  3949.             G[i].national = FALSE;
  3950.         }
  3951. #endif /* CKOUNI */
  3952. #endif /* OS2 */
  3953.         return;
  3954.     }
  3955. #ifdef OS2
  3956. #ifdef CKOUNI
  3957.     else if (x == TX_UTF8) {
  3958.         tcs_transp = 0;
  3959.         tt_utf8 = 1;            /* Turn it on if we are UTF8 */
  3960.         return;
  3961.     }
  3962. #endif /* CKOUNI */
  3963.     else {
  3964.         tcs_transp = 0;
  3965.         tcsr = x;                       /* Remote character set */
  3966. #ifdef CKOUNI
  3967.         tt_utf8 = 0;                    /* Turn off UTF8 flag */
  3968. #endif /* CKOUNI */
  3969.  
  3970.         if (z == TT_GR_ALL) {
  3971.             int i;
  3972. #ifdef UNICODE
  3973.             dec_kbd = x;
  3974. #endif /* UNICODE */
  3975.             for (i = 0; i < 4; i++) {
  3976.                 G[i].init = TRUE;
  3977.                 if ( i == 0 && !cs_is_nrc(x) ) {
  3978.                     G[0].designation = G[0].def_designation = FC_USASCII;
  3979.                     G[0].size = G[0].def_size = cs94;
  3980.                     G[0].national = 1;
  3981.                 } else {
  3982.                     G[i].def_designation = G[i].designation = x;
  3983.                     switch (cs_size(x)) {       /* 94, 96, or 128 */
  3984.                     case 128:
  3985.                     case 96:
  3986.                         G[i].size = G[i].def_size = cs96;
  3987.                         break;
  3988.                     case 94:
  3989.                         G[i].size = G[i].def_size = cs94;
  3990.                         break;
  3991.                     default:
  3992.                         G[i].size = G[i].def_size = csmb;
  3993.                         break;
  3994.                     }
  3995.                     G[i].national = cs_is_nrc(x);
  3996.                 }
  3997.                 G[i].c1 = G[i].def_c1 = x != tcsl && cs_is_std(x);
  3998.             }
  3999. #ifdef UNICODE
  4000.         } else if (z == TT_GR_KBD) {    /* Keyboard only */
  4001.             dec_kbd = x;
  4002. #endif /* UNICODE */
  4003.         } else {                        /* Specific Gn */
  4004.             G[z].def_designation = G[z].designation = x;
  4005.             G[z].init = TRUE;
  4006.             switch (cs_size(x)) {       /* 94, 96, or 128 */
  4007.             case 128:
  4008.             case 96:
  4009.                 G[z].size = G[z].def_size = cs96;
  4010.                 break;
  4011.             case 94:
  4012.                 G[z].size = G[z].def_size = cs94;
  4013.                 break;
  4014.             default:
  4015.                 G[z].size = G[z].def_size = csmb;
  4016.                 break;
  4017.             }
  4018.             G[z].c1 = G[z].def_c1 = x != tcsl && cs_is_std(x);
  4019.             G[z].national = cs_is_nrc(x);
  4020.         }
  4021.     }
  4022. #else /* not OS2 */
  4023.     tcsr = x;                   /* Remote character set */
  4024. #endif /* OS2 */
  4025. }
  4026. #endif /* NOCSETS */
  4027.  
  4028. VOID
  4029. setcmask(x) int x; {
  4030.     if (x == 7) {
  4031.         cmask = 0177;
  4032.     } else if (x == 8) {
  4033.         cmask = 0377;
  4034.         parity = 0;
  4035.     }
  4036. #ifdef KUI      
  4037.     KuiSetProperty(KUI_TERM_CMASK,x,0);
  4038. #endif /* KUI */
  4039. }
  4040.  
  4041. #ifdef CK_AUTODL
  4042. VOID
  4043. setautodl(x,y) int x,y; {
  4044.     autodl = x;
  4045.     adl_ask = y;
  4046. #ifdef KUI      
  4047.     KuiSetProperty(KUI_TERM_AUTODOWNLOAD,x?(y?2:1):0,0);
  4048. #endif /* KUI */
  4049. }
  4050. #endif /* CK_AUTODL */
  4051.  
  4052. #ifdef OS2
  4053. VOID
  4054. seturlhl(int x) {
  4055.     tt_url_hilite = x;
  4056. #ifdef KUI      
  4057.     KuiSetProperty(KUI_TERM_URL_HIGHLIGHT,x,0);
  4058. #endif /* KUI */
  4059. }
  4060.  
  4061. VOID
  4062. setaprint(int x) {
  4063.     extern int aprint;
  4064.     aprint = x;
  4065. #ifdef KUI
  4066.     KuiSetProperty(KUI_TERM_PRINTERCOPY,x,0);
  4067. #endif /* KUI */
  4068. }
  4069. #endif /* OS2 */
  4070.  
  4071. int
  4072. settrm() {
  4073.     int i = 0;
  4074. #ifdef OS2
  4075.     extern int colorreset, user_erasemode;
  4076. #endif /* OS2 */
  4077.     if ((y = cmkey(trmtab,ntrm,"", "",xxstring)) < 0) return(y);
  4078. #ifdef MAC
  4079.     printf("\n?Sorry, not implemented yet.  Please use the Settings menu.\n");
  4080.     return(-9);
  4081. #else
  4082. #ifdef IKSD
  4083.     if (inserver) {
  4084.         if ((y = cmcfm()) < 0) return(y);
  4085.         printf("?Sorry, command disabled.\r\n");
  4086.         return(success = 0);
  4087.     }
  4088. #endif /* IKSD */
  4089.  
  4090.     switch (y) {
  4091.       case XYTBYT:                      /* SET TERMINAL BYTESIZE */
  4092.         if ((y = cmnum("bytesize for terminal connection","8",10,&x,
  4093.                        xxstring)) < 0)
  4094.           return(y);
  4095.         if (x != 7 && x != 8) {
  4096.             printf("\n?The choices are 7 and 8\n");
  4097.             return(success = 0);
  4098.         }
  4099.         if ((y = cmcfm()) < 0) return(y);
  4100.         setcmask(x);
  4101. #ifdef OS2
  4102.         if (IS97801(tt_type_mode))
  4103.           SNI_bitmode(x);
  4104. #endif /* OS2 */
  4105.         return(success = 1);
  4106.  
  4107.       case XYTSO:                       /* SET TERMINAL LOCKING-SHIFT */
  4108.         return(seton(&sosi));
  4109.  
  4110.       case XYTNL:                       /* SET TERMINAL NEWLINE-MODE */
  4111.         return(seton(&tnlm));
  4112.  
  4113. #ifdef OS2
  4114.       case XYTCOL:
  4115.         if ((x = cmkey(ttycoltab,ncolors,"","terminal",xxstring)) < 0)
  4116.           return(x);
  4117.         else if (x == TTCOLRES) {
  4118.             if ((y = cmkey(ttcolmodetab,ncolmode,
  4119.                            "","default-color",xxstring)) < 0)
  4120.               return(y);
  4121.             if ((z = cmcfm()) < 0)
  4122.               return(z);
  4123.             colorreset = y;
  4124.             return(success = 1);
  4125.         } else if (x == TTCOLERA) {
  4126.             if ((y = cmkey(ttcolmodetab,ncolmode,"",
  4127.                            "current-color",xxstring)) < 0)
  4128.               return(y);
  4129.             if ((z = cmcfm()) < 0)
  4130.               return(z);
  4131.             user_erasemode = y;
  4132.             return(success=1);
  4133.         } else {                        /* No parse error */
  4134.             int fg = 0, bg = 0;
  4135.             fg = cmkey(ttyclrtab, nclrs,
  4136.                        (x == TTCOLBOR ?
  4137.                         "color for screen border" :
  4138.                         "foreground color and then background color"),
  4139.                        "lgray", xxstring);
  4140.             if (fg < 0)
  4141.               return(fg);
  4142.             if (x != TTCOLBOR) {
  4143.                 if ((bg = cmkey(ttyclrtab,nclrs,
  4144.                                 "background color","blue",xxstring)) < 0)
  4145.                   return(bg);
  4146.             }
  4147.             if ((y = cmcfm()) < 0)
  4148.               return(y);
  4149.             switch (x) {
  4150.               case TTCOLNOR:
  4151.                 colornormal = fg | bg << 4;
  4152.                 fgi = fg & 0x08;
  4153.                 bgi = bg & 0x08;
  4154.                 break;
  4155.               case TTCOLREV:
  4156.                 colorreverse = fg | bg << 4;
  4157.                 break;
  4158.               case TTCOLITA:
  4159.                 coloritalic = fg | bg << 4;
  4160.                 break;
  4161.               case TTCOLUND:
  4162.                 colorunderline = fg | bg << 4;
  4163.                 break;
  4164.               case TTCOLGRP:
  4165.                 colorgraphic = fg | bg << 4;
  4166.                 break;
  4167.               case TTCOLDEB:
  4168.                 colordebug = fg | bg << 4;
  4169.                 break;
  4170.               case TTCOLSTA:
  4171.                 colorstatus = fg | bg << 4;
  4172.                 break;
  4173.               case TTCOLHLP:
  4174.                 colorhelp = fg | bg << 4;
  4175.                 break;
  4176.               case TTCOLBOR:
  4177.                 colorborder = fg;
  4178.                 break;
  4179.               case TTCOLSEL:
  4180.                 colorselect = fg | bg << 4;
  4181.                 break;
  4182.               default:
  4183.                 printf("%s - invalid\n",cmdbuf);
  4184.                 return(-9);
  4185.                 break;
  4186.             }
  4187.             scrninitialized[VTERM] = 0;
  4188.             VscrnInit(VTERM);
  4189.         }
  4190.         return(success = 1);
  4191.  
  4192.       case XYTCUR: {                    /* SET TERMINAL CURSOR */
  4193.           extern int cursorena[];
  4194.           extern int cursoron[] ;       /* Cursor state on/off       */
  4195.           if ((x = cmkey(ttycurtab,ncursors,"","underline",xxstring)) < 0)
  4196.             return(x);
  4197.           if ((z = cmkey(onoff,2,"","on",xxstring)) < 0)
  4198.             return(z);
  4199.           if ((y = cmcfm()) < 0) return(y);
  4200.           tt_cursor = tt_cursor_usr = x;
  4201.           cursorena[VTERM] = tt_cursorena_usr = z;/* turn cursor on/off */
  4202.           cursoron[VTERM] = FALSE; /* Force newcursor to restore the cursor */
  4203.           return(success = 1);
  4204.       }
  4205. #endif /* OS2 */
  4206.  
  4207.       case XYTTYP:                      /* SET TERMINAL TYPE */
  4208.         return(settrmtyp());
  4209.  
  4210. #ifdef OS2
  4211.       case XYTARR:                      /* SET TERMINAL ARROW-KEYS */
  4212.         if ((x = cmkey(akmtab,2,"","",xxstring)) < 0) return(x);
  4213.         if ((y = cmcfm()) < 0) return(y);
  4214.         tt_arrow = x;                   /* TTK_NORM / TTK_APPL; see ckuusr.h */
  4215.         return(success = 1);
  4216.  
  4217.       case XYTKPD:                      /* SET TERMINAL KEYPAD-MODE */
  4218.         if ((x = cmkey(kpmtab,2,"","",xxstring)) < 0) return(x);
  4219.         if ((y = cmcfm()) < 0) return(y);
  4220.         tt_keypad = x;                  /* TTK_NORM / TTK_APPL; see ckuusr.h */
  4221.         return(success = 1);
  4222.  
  4223.       case XYTUNX: {                    /* SET TERM UNIX-MODE (DG) */
  4224.         extern int dgunix,dgunix_usr;
  4225.         x = seton(&dgunix);
  4226.         dgunix_usr = dgunix;
  4227.         return(x);
  4228.       }
  4229.       case XYTKBMOD: {                  /* SET TERM KEYBOARD MODE */
  4230.           extern int tt_kb_mode;
  4231.           if ((x = cmkey(kbmodtab,
  4232.                          nkbmodtab,
  4233.                          "normal",
  4234.                          "special keyboard mode for terminal emulation",
  4235.                          xxstring)
  4236.                ) < 0)
  4237.             return(x);
  4238.           if ((y = cmcfm()) < 0) return(y);
  4239.           tt_kb_mode = x;
  4240.           return(success = 1);
  4241.       }
  4242.  
  4243.       case XYTWRP:                      /* SET TERMINAL WRAP */
  4244.         return(seton(&tt_wrap));
  4245.  
  4246.       case XYSCRS:
  4247.         if ((y = cmnum("CONNECT scrollback buffer size, lines","2000",10,&x,
  4248.                        xxstring)) < 0)
  4249.           return(y);
  4250.         /* The max number of lines is the RAM  */
  4251.         /* we can actually dedicate to a       */
  4252.         /* scrollback buffer given the maximum */
  4253.         /* process memory space of 512MB       */
  4254.         if (x < 256 || x > 2000000L) {
  4255.             printf("\n?The size must be between 256 and 2,000,000.\n");
  4256.             return(success = 0);
  4257.         }
  4258.         if ((y = cmcfm()) < 0) return(y);
  4259.         tt_scrsize[VTERM] = x;
  4260.         VscrnInit(VTERM);
  4261.         return(success = 1);
  4262. #endif /* OS2 */
  4263.  
  4264. #ifndef NOCSETS
  4265.       case XYTCS: {                     /* SET TERMINAL CHARACTER-SET */
  4266.         int eol;
  4267.           /* set terminal character-set <remote> <local> */
  4268.         if ((x = cmkey(
  4269. #ifdef CKOUNI
  4270.                        txrtab,ntxrtab,
  4271. #else  /* CKOUNI */
  4272.                        ttcstab,ntermc,
  4273. #endif /* CKOUNI */
  4274.                        "remote terminal character-set","",xxstring)) < 0)
  4275.           return(x);
  4276.  
  4277. #ifdef UNICODE
  4278.         if (x == TX_TRANSP
  4279. #ifdef CKOUNI
  4280.             || x == TX_UTF8
  4281. #endif /* CKOUNI */
  4282.            ) {
  4283.               if ((y = cmcfm()) < 0)    /* Confirm the command */
  4284.                   return(y);
  4285. #ifdef OS2
  4286.             if ( isunicode() && x == TX_TRANSP ) {
  4287.                 /* If we are in unicode display mode then transparent
  4288.                  * only affects the output direction.  We need to know
  4289.                  * the actual remote character set in order to perform
  4290.                  * the tcsr -> ucs2 translation for display.
  4291.                  */
  4292.                 x = y = tcsl;
  4293.             } else
  4294. #endif /* OS2 */
  4295.                 y = x;
  4296.         }
  4297. #else /* UNICODE */
  4298.         if (x == FC_TRANSP) {
  4299.             if ((y = cmcfm()) < 0)      /* Confirm the command */
  4300.                 return(y);
  4301.             y = x;
  4302.         }
  4303. #endif /* UNICODE */
  4304.  
  4305.         /* Not transparent or UTF8, so get local set to translate it into */
  4306.         s = "";
  4307. #ifdef OS2
  4308.         y = os2getcp();                 /* Default is current code page */
  4309.         switch (y) {
  4310.           case 437: s = "cp437"; break;
  4311.           case 850: s = "cp850"; break;
  4312.           case 852: s = "cp852"; break;
  4313.           case 857: s = "cp857"; break;
  4314.           case 858: s = "cp858"; break;
  4315.           case 862: s = "cp862"; break;
  4316.           case 866: s = "cp866"; break;
  4317.           case 869: s = "cp869"; break;
  4318.           case 1250: s = "cp1250"; break;
  4319.           case 1251: s = "cp1251"; break;
  4320.           case 1252: s = "cp1252"; break;
  4321.           case 1253: s = "cp1253"; break;
  4322.           case 1254: s = "cp1254"; break;
  4323.           case 1255: s = "cp1255"; break;
  4324.           case 1256: s = "cp1256"; break;
  4325.           case 1257: s = "cp1257"; break;
  4326.           case 1258: s = "cp1258"; break;
  4327.         }
  4328. #ifdef PCFONTS
  4329. /*
  4330.    If the user has loaded a font with SET TERMINAL FONT then we want
  4331.    to change the default code page to the font that was loaded.
  4332. */
  4333.         if (tt_font != TTF_ROM) {
  4334.             for (y = 0; y < ntermfont; y++ ) {
  4335.                 if (term_font[y].kwval == tt_font) {
  4336.                     s = term_font[y].kwd;
  4337.                     break;
  4338.                 }
  4339.             }
  4340.         }
  4341. #endif /* PCFONTS */
  4342. #else  /* Not K95... */
  4343.         s = fcsinfo[fcharset].keyword;
  4344. #endif /* OS2 */
  4345.  
  4346.         if ((y = cmkey(
  4347. #ifdef CKOUNI
  4348.                        txrtab,ntxrtab,
  4349. #else /* CKOUNI */
  4350.                        ttcstab,ntermc,
  4351. #endif /* CKOUNI */
  4352.                        "local character-set",s,xxstring)) < 0)
  4353.           return(y);
  4354.  
  4355. #ifdef UNICODE
  4356.         if (y == TX_UTF8) {
  4357.             printf("?UTF8 may not be used as a local character set.\r\n");
  4358.             return(-9);
  4359.         }
  4360. #endif /* UNICODE */
  4361. #ifdef OS2
  4362.         if ((z = cmkey(graphsettab,ngraphset,
  4363.                        "DEC VT intermediate graphic set","all",xxstring)) < 0)
  4364.             return(z);
  4365. #endif /* OS2 */
  4366.         if ((eol = cmcfm()) < 0)
  4367.             return(eol); /* Confirm the command */
  4368.  
  4369.         /* End of command parsing - actions begin */
  4370.         setlclcharset(y);
  4371.         setremcharset(x,z);
  4372.         return(success = 1);
  4373.       }
  4374. #endif /* NOCSETS */
  4375.  
  4376. #ifndef NOCSETS
  4377.       case XYTLCS:                      /* SET TERMINAL LOCAL-CHARACTER-SET */
  4378.         /* set terminal character-set <local> */
  4379.         s = getdcset();                 /* Get display character-set name */
  4380.         if ((y = cmkey(
  4381. #ifdef CKOUNI
  4382.                        txrtab,ntxrtab,
  4383. #else /* CKOUNI */
  4384.                        fcstab,nfilc,
  4385. #endif /* CKOUNI */
  4386.                        "local character-set",s,xxstring)) < 0)
  4387.           return(y);
  4388.  
  4389. #ifdef UNICODE
  4390.           if (y == TX_UTF8) {
  4391.               printf("?UTF8 may not be used as a local character set.\r\n");
  4392.               return(-9);
  4393.           }
  4394. #endif /* UNICODE */
  4395.           if ((z = cmcfm()) < 0) return(z); /* Confirm the command */
  4396.  
  4397.           /* End of command parsing - action begins */
  4398.  
  4399.         setlclcharset(y);
  4400.         return(success = 1);
  4401. #endif /* NOCSETS */
  4402.  
  4403. #ifndef NOCSETS
  4404. #ifdef UNICODE
  4405.       case XYTUNI:                      /* SET TERMINAL UNICODE */
  4406.         return(seton(&tt_unicode));
  4407. #endif /* UNICODE */
  4408.  
  4409.       case XYTRCS:                      /* SET TERMINAL REMOTE-CHARACTER-SET */
  4410.         /* set terminal character-set <remote> <Graphic-set> */
  4411.         if ((x = cmkey(
  4412. #ifdef CKOUNI
  4413.                 txrtab, ntxrtab,
  4414. #else /* CKOUNI */
  4415.                 ttcstab,ntermc,
  4416. #endif /* CKOUNI */
  4417.                        "remote terminal character-set","",xxstring)) < 0)
  4418.           return(x);
  4419.  
  4420. #ifdef UNICODE
  4421.         if (x == TX_TRANSP
  4422. #ifdef CKOUNI
  4423.             || x == TX_UTF8
  4424. #endif /* CKOUNI */
  4425.            ) {
  4426.               if ((y = cmcfm()) < 0)    /* Confirm the command */
  4427.                   return(y);
  4428. #ifdef OS2
  4429.             if ( isunicode() && x == TX_TRANSP ) {
  4430.                 /* If we are in unicode display mode then transparent
  4431.                  * only affects the output direction.  We need to know
  4432.                  * the actual remote character set in order to perform
  4433.                  * the tcsr -> ucs2 translation for display.
  4434.                  */
  4435.                 x = tcsl;
  4436.             }
  4437. #endif /* OS2 */
  4438.         }
  4439. #else /* UNICODE */
  4440.         if (x == FC_TRANSP) {
  4441.           if ((y = cmcfm()) < 0)        /* Confirm the command */
  4442.             return(y);
  4443.         }
  4444. #endif /* UNICODE */
  4445.         else {
  4446. #ifdef OS2
  4447.           if ((z = cmkey(graphsettab,ngraphset,
  4448.                       "DEC VT intermediate graphic set","all",xxstring)) < 0)
  4449.             return(z);
  4450. #endif /* OS2 */
  4451.           if ((y = cmcfm()) < 0)        /* Confirm the command */
  4452.             return(y);
  4453.         }
  4454.         /* Command parsing ends here */
  4455.  
  4456.         setremcharset(x,z);
  4457.         return(success = 1);
  4458. #endif /* NOCSETS */
  4459.  
  4460.       case XYTEC:                       /* SET TERMINAL ECHO */
  4461.         if ((x = cmkey(rltab,nrlt,"which side echos during CONNECT",
  4462.                        "remote", xxstring)) < 0) return(x);
  4463.         if ((y = cmcfm()) < 0) return(y);
  4464. #ifdef NETCONN
  4465.         oldplex = x;
  4466. #endif /* NETCONN */
  4467.         duplex = x;
  4468.         return(success = 1);
  4469.  
  4470.       case XYTESC:                      /* SET TERM ESC */
  4471.         if ((x = cmkey(nabltab,nnabltab,"","enabled",xxstring)) < 0)
  4472.           return(x);
  4473.         if ((y = cmcfm()) < 0) return(y);
  4474.         tt_escape = x;
  4475.         return(1);
  4476.  
  4477.       case XYTCRD:                      /* SET TERMINAL CR-DISPLAY */
  4478.         if ((x = cmkey(crdtab,2,"", "normal", xxstring)) < 0) return(x);
  4479.         if ((y = cmcfm()) < 0) return(y);
  4480.         tt_crd = x;
  4481.         return(success = 1);
  4482.  
  4483. #ifdef OS2
  4484.       case XYTANS: {                    /* SET TERMINAL ANSWERBACK */
  4485. /*
  4486.   NOTE: We let them enable and disable the answerback sequence, but we
  4487.   do NOT let them change it, and we definitely do not let the host set it.
  4488.   This is a security feature.
  4489.  
  4490.   As of 1.1.8 we allow the SET TERM ANSWERBACK MESSAGE <string> to be
  4491.   used just as MS-DOS Kermit does.  C0 and C1 controls as well as DEL
  4492.   are not allowed to be used as characters.  They are translated to
  4493.   underscore.  This may not be set by APC.
  4494. */
  4495.           if ((x = cmkey(anbktab,nansbk,"", "off", xxstring)) < 0)
  4496.             return(x);
  4497.           if (x < 2) {
  4498.               if ((y = cmcfm()) < 0)
  4499.                 return(y);
  4500.               tt_answer = x;
  4501.               return(success = 1);
  4502.           } else if ( x == 2 || x == 3) {
  4503.               int len = 0;
  4504.               extern int safeanswerbk;
  4505.               extern char useranswerbk[];
  4506.               if ((y = cmtxt("Answerback extension","",&s,xxstring)) < 0)
  4507.                 return(y);
  4508.               if (apcactive == APC_LOCAL ||
  4509.                   (apcactive == APC_REMOTE && !(apcstatus & APC_UNCH)))
  4510.                 return(success = 0);
  4511.               len = strlen(s);
  4512.               if (x == 2) {
  4513.                   /* Safe Answerback's don't have C0/C1 chars */
  4514.                   for (z = 0; z < len; z++) {
  4515.                       if ((s[z] & 0x7F) <= SP || (s[z] & 0x7F) == DEL)
  4516.                         useranswerbk[z] = '_';
  4517.                       else
  4518.                         useranswerbk[z] = s[z];
  4519.                   }
  4520.                   useranswerbk[z] = '\0';
  4521.                   safeanswerbk = 1 ;    /* TRUE */
  4522.               } else {
  4523.                   ckstrncpy(useranswerbk,s,60); /* (see ckocon.c) */
  4524.                   safeanswerbk = 0;     /* FALSE */
  4525.               }
  4526.               updanswerbk();
  4527.               return(success = 1);
  4528.           } else
  4529.             return(success = 0);
  4530.       }
  4531. #endif /* OS2 */
  4532.  
  4533. #ifdef CK_APC
  4534.       case XYTAPC:
  4535.         if ((y = cmkey(apctab,napctab,
  4536.                        "application program command execution","",
  4537.                        xxstring)) < 0)
  4538.           return(y);
  4539.         if ((x = cmcfm()) < 0)
  4540.           return(x);
  4541.         if (apcactive == APC_LOCAL ||
  4542.             (apcactive == APC_REMOTE && !(apcstatus & APC_UNCH)))
  4543.           return(success = 0);
  4544.         apcstatus = y;
  4545.         return(success = 1);
  4546.  
  4547. #ifdef CK_AUTODL
  4548.       case XYTAUTODL:                   /* AUTODOWNLOAD */
  4549.         if ((y = cmkey(adltab,nadltab,"Auto-download options","",
  4550.                        xxstring)) < 0)
  4551.           return(y);
  4552.         switch (y) {
  4553.           case TAD_ON:
  4554.           case TAD_OFF:
  4555.             if ((x = cmcfm()) < 0)
  4556.               return(x);
  4557.             setautodl(y,0);
  4558.             break;
  4559.           case TAD_ASK:
  4560.             if ((x = cmcfm()) < 0)
  4561.               return(x);
  4562.             setautodl(TAD_ON,1);
  4563.             break;
  4564.           case TAD_ERR:
  4565.             if ((y = cmkey(adlerrtab,nadlerrtab,"","", xxstring)) < 0)
  4566.               return(y);
  4567.             if ((x = cmcfm()) < 0)
  4568.               return(x);
  4569.             adl_err = y;
  4570.             break;
  4571. #ifdef OS2
  4572.           case TAD_K:
  4573.             if ((y = cmkey(adlxtab,nadlxtab,"","", xxstring)) < 0)
  4574.               return(y);
  4575.             switch (y) {
  4576.               case TAD_X_C0:
  4577.                 if ((y = cmkey(adlc0tab,nadlc0tab,"",
  4578.                                "processed-by-emulator",xxstring)) < 0)
  4579.                   return(y);
  4580.                 if ((x = cmcfm()) < 0)
  4581.                   return(x);
  4582.                 adl_kc0 = y;
  4583.                 break;
  4584.               case TAD_X_DETECT:
  4585.                 if ((y = cmkey(adldtab,nadldtab,"","packet",xxstring)) < 0)
  4586.                   return(y);
  4587.                 if ((x = cmcfm()) < 0)
  4588.                   return(x);
  4589.                 adl_kmode = y;
  4590.                 break;
  4591.               case TAD_X_STR:
  4592.                 if ((y = cmtxt("Kermit start string","KERMIT READY TO SEND...",
  4593.                                &s,xxstring)) < 0)
  4594.                   return(y);
  4595.                 free(adl_kstr);
  4596.                 adl_kstr = strdup(s);
  4597.                 break;
  4598.             }
  4599.             break;
  4600.  
  4601.           case TAD_Z:
  4602.             if ((y = cmkey(adlxtab,nadlxtab,"","",xxstring)) < 0)
  4603.               return(y);
  4604.             switch (y) {
  4605.               case TAD_X_C0:
  4606.                 if ((y = cmkey(adlc0tab,nadlc0tab,"",
  4607.                                "processed-by-emulator",xxstring)) < 0)
  4608.                   return(y);
  4609.                 if ((x = cmcfm()) < 0)
  4610.                   return(x);
  4611.                 adl_zc0 = y;
  4612.                 break;
  4613.               case TAD_X_DETECT:
  4614.                 if ((y = cmkey(adldtab,nadldtab,"","packet",xxstring)) < 0)
  4615.                   return(y);
  4616.                 if ((x = cmcfm()) < 0)
  4617.                   return(x);
  4618.                 adl_zmode = y;
  4619.                 break;
  4620.               case TAD_X_STR:
  4621.                 if ((y = cmtxt("","rz\\{13}",&s,xxstring)) < 0)
  4622.                   return(y);
  4623.                 free(adl_zstr);
  4624.                 adl_zstr = strdup(s);
  4625.                 break;
  4626.             }
  4627.             break;
  4628. #endif /* OS2 */
  4629.         }
  4630.         return(success = 1);
  4631.  
  4632. #endif /* CK_AUTODL */
  4633. #endif /* CK_APC */
  4634.  
  4635. #ifdef OS2
  4636.       case XYTBEL:
  4637.         return(success = setbell());
  4638.  
  4639.       case XYTMBEL:                     /* MARGIN-BELL */
  4640.         if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  4641.         if (y) {                        /* ON */
  4642.             if ((z = cmnum("Column at which to set margin bell",
  4643.                            "72",10,&x,xxstring)) < 0)
  4644.               return(z);
  4645.         }
  4646.         if ((z = cmcfm()) < 0) return(z);
  4647.         marginbell = y;
  4648.         marginbellcol = x;
  4649.         return(success = 1);
  4650. #endif /* OS2 */
  4651.  
  4652. #ifdef CKTIDLE
  4653.       case XYTIDLE:                     /* IDLE-SEND */
  4654.       case XYTITMO:                     /* IDLE-TIMEOUT */
  4655.         if ((z = cmnum("seconds of idle time to wait, or 0 to disable",
  4656.                        "0",10,&x,xxstring)) < 0)
  4657.           return(z);
  4658.         if (y == XYTIDLE) {
  4659.             if ((y = cmtxt("string to send, may contain kverbs and variables",
  4660.                            "\\v(newline)",&s,xxstring)) < 0)
  4661.               return(y);
  4662.             tt_idlesnd_tmo = x;         /* (old) */
  4663.             tt_idlelimit = x;           /* (new) */
  4664.             makestr(&tt_idlestr,brstrip(s)); /* (new) */
  4665.             tt_idlesnd_str = tt_idlestr; /* (old) */
  4666.             tt_idleact = IDLE_OUT;      /* (new) */
  4667.         } else {
  4668.             if ((y = cmcfm()) < 0)
  4669.               return(y);
  4670.             tt_idlelimit = x;
  4671.         }
  4672. #ifdef OS2
  4673.         puterror(VTERM);
  4674. #endif /* OS2 */
  4675.         return(success = 1);
  4676.  
  4677.       case XYTIACT: {                   /* SET TERM IDLE-ACTION */
  4678.           if ((y = cmkey(idlacts,nidlacts,"","",xxstring)) < 0)
  4679.             return(y);
  4680.           if (y == IDLE_OUT) {
  4681.               if ((x = cmtxt("string to send, may contain kverbs and variables"
  4682.                              , "\\v(newline)",&s,xxstring)) < 0)
  4683.                 return(x);
  4684.               makestr(&tt_idlestr,brstrip(s)); /* (new) */
  4685.               tt_idlesnd_str = tt_idlestr; /* (old) */
  4686.           } else {
  4687.               if ((x = cmcfm()) < 0)
  4688.                 return(x);
  4689.           }
  4690.           tt_idleact = y;
  4691.           return(success = 1);
  4692.       }
  4693. #endif /* CKTIDLE */
  4694.  
  4695.       case XYTDEB:                      /* TERMINAL DEBUG */
  4696.         y = seton(&x);                  /* Go parse ON or OFF */
  4697.         if (y > 0)                      /* Command succeeded? */
  4698.           setdebses(z);
  4699.         return(y);
  4700.  
  4701. #ifdef OS2
  4702.       case XYTASCRL:                    /* SET TERMINAL AUTOSCROLL */
  4703.           y = seton(&autoscroll);
  4704.           return(y);
  4705.  
  4706.       case XYTAPAGE:                    /* SET TERMINAL AUTOPAGE */
  4707.           y = seton(&wy_autopage);
  4708.           return(y);
  4709.  
  4710.       case XYTROL:                      /* SET TERMINAL ROLL */
  4711.         if ((y = cmkey(rolltab,nroll,"scrollback mode","insert",xxstring))<0)
  4712.       return(y);
  4713.     if (y == TTR_KEYS) {
  4714.         if ((x = cmkey(rollkeytab,nrollkey,"","send",xxstring))<0)
  4715.           return(x);
  4716.         if ((z = cmcfm()) < 0) return(z);
  4717.         tt_rkeys[VTERM] = x;
  4718.     } else {
  4719.         if ((x = cmcfm()) < 0) return(x);
  4720.         tt_roll[VTERM] = y;
  4721.     }
  4722.         return(success = 1);
  4723.  
  4724.       case XYTCTS:                      /* SET TERMINAL TRANSMIT-TIMEOUT */
  4725.         y = cmnum("Maximum seconds to allow CTS off during CONNECT",
  4726.                   "5",10,&x,xxstring);
  4727.         return(setnum(&tt_ctstmo,x,y,10000));
  4728.  
  4729.       case XYTCPG: {                    /* SET TERMINAL CODE-PAGE */
  4730.         int i;
  4731.         int cp = -1;
  4732.         y = cmnum("PC code page to use during terminal emulation",
  4733.                   ckitoa(os2getcp()),10,&x,xxstring);
  4734.         if ((x = setnum(&cp,x,y,11000)) < 0) return(x);
  4735.         if (os2setcp(cp) != 1) {
  4736. #ifdef NT
  4737.             if (isWin95())
  4738.               printf(
  4739.                  "Sorry, Windows 95 does not support code page switching\n");
  4740.             else
  4741. #endif /* NT */
  4742.               printf(
  4743.                  "Sorry, %d is not a valid code page for this system.\n",cp);
  4744.             return(-9);
  4745.         }
  4746.     /* Force the terminal character-sets conversions to be updated */
  4747.         for ( i = 0; i < 4; i++ )
  4748.           G[i].init = TRUE;
  4749.         return(1);
  4750.     }
  4751.  
  4752.       case XYTPAC:                      /* SET TERMINAL OUTPUT-PACING */
  4753.         y = cmnum(
  4754.            "Pause between sending each character during CONNECT, milliseconds",
  4755.                   "-1",10,&x,xxstring);
  4756.         return(setnum(&tt_pacing,x,y,10000));
  4757.  
  4758. #ifdef OS2MOUSE
  4759.       case XYTMOU: {                    /* SET TERMINAL MOUSE */
  4760.           int old_mou = tt_mouse;
  4761.           if ((x = seton(&tt_mouse)) < 0)
  4762.             return(x);
  4763.           if (tt_mouse != old_mou)
  4764.             if (tt_mouse)
  4765.               os2_mouseon();
  4766.             else
  4767.               os2_mouseoff();
  4768.           return(1);
  4769.       }
  4770. #endif /* OS2MOUSE */
  4771. #endif /* OS2 */
  4772.  
  4773.       case XYTWID: {
  4774.           if ((y = cmnum(
  4775. #ifdef OS2
  4776.                          "number of columns in display window during CONNECT",
  4777. #else
  4778.                          "number of columns on your screen",
  4779. #endif /* OS2 */
  4780.                          "80",10,&x,xxstring)) < 0)
  4781.             return(y);
  4782.           if ((y = cmcfm()) < 0) return(y);
  4783. #ifdef OS2
  4784.           return(success = os2_settermwidth(x));
  4785. #else  /* Not OS/2 */
  4786.           tt_cols = x;
  4787.           return(success = 1);
  4788. #endif /* OS2 */
  4789.       }
  4790.  
  4791.       case XYTHIG:
  4792.         if ((y = cmnum(
  4793. #ifdef OS2
  4794.  "number of rows in display window during CONNECT, not including status line",
  4795.  tt_status[VTERM]?"24":"25",
  4796. #else
  4797.  "24","number of rows on your screen",
  4798. #endif /* OS2 */
  4799.                        10,&x,xxstring)) < 0)
  4800.           return(y);
  4801.         if ((y = cmcfm()) < 0) return(y);
  4802.  
  4803. #ifdef OS2
  4804.         return (success = os2_settermheight(x));
  4805. #else  /* Not OS/2 */
  4806.         tt_rows = x;
  4807.         return(success = 1);
  4808. #endif /* OS2 */
  4809.  
  4810. #ifdef OS2
  4811.       case XYTPRN: {                    /* Print Mode */
  4812.           extern bool xprint, aprint, cprint, uprint;
  4813.           if ((y = cmkey(prnmtab,nprnmtab,"","off", xxstring)) < 0) return(y);
  4814.           if ((x = cmcfm()) < 0) return(x);
  4815.           switch (y) {
  4816.             case 0:
  4817.               if (cprint || uprint || aprint || xprint)
  4818.                 printeroff();
  4819.               cprint = xprint = uprint = 0;
  4820.               setaprint(0);
  4821.               break;
  4822.             case 1:
  4823.               if (!(cprint || uprint || aprint || xprint))
  4824.                 printeron();
  4825.               setaprint(1);
  4826.               cprint = xprint = uprint = 0;
  4827.               break;
  4828.             case 2:
  4829.               if (!(cprint || uprint || aprint || xprint))
  4830.                 printeron();
  4831.               cprint = 1;
  4832.               setaprint(0);
  4833.           xprint = uprint = 0;
  4834.               break;
  4835.             case 3:
  4836.               if (!(cprint || uprint || aprint || xprint))
  4837.                 printeron();
  4838.               uprint = 1;
  4839.               setaprint(0);
  4840.               xprint = cprint = 0;
  4841.               break;
  4842.           }
  4843.           return(1);
  4844.       }
  4845. #else
  4846. #ifdef XPRINT
  4847.       case XYTPRN: {
  4848.           extern int tt_print;
  4849.           if ((x = seton(&tt_print)) < 0)
  4850.             return(x);
  4851.           return(success = 1);
  4852.       }
  4853. #endif /* XPRINT */
  4854. #endif /* OS2 */
  4855.  
  4856. #ifdef OS2
  4857.       case XYTSCNM: {
  4858.           extern int decscnm, decscnm_usr;
  4859.           if ((y = cmkey(normrev,4,"",
  4860.                          decscnm_usr?"reverse":"normal",
  4861.                          xxstring)
  4862.                ) < 0)
  4863.             return(y);
  4864.           if ((x = cmcfm()) < 0) return(x);
  4865.           decscnm_usr = y;
  4866.           if (decscnm != decscnm_usr)
  4867.             flipscreen(VTERM);
  4868.           return(1);
  4869.     }
  4870.     case XYTOPTI:
  4871.         if ((y = cmkey(onoff,2,"",tt_diff_upd?"on":"off",
  4872.                         xxstring)) < 0) return(y);
  4873.         if ((x = cmcfm()) < 0) return(x);
  4874.         tt_diff_upd = y;
  4875.         return(1);
  4876.     case XYTUPD: {
  4877.         int mode, delay;
  4878.         if ((mode = cmkey(scrnupd,nscrnupd,"","fast",xxstring)) < 0) {
  4879.             return(mode);
  4880.         } else {
  4881.             y = cmnum(
  4882.             "Pause between FAST screen updates in CONNECT mode, milliseconds",
  4883.                       "100",10,&x,xxstring
  4884.                       );
  4885.             if (x < 0 || x > 1000 ) {
  4886.                 printf(
  4887.             "\n?The update rate must be between 0 and 1000 milliseconds.\n"
  4888.                        );
  4889.                 return(success = 0);
  4890.             }
  4891.             if ((y = cmcfm()) < 0) return(y);
  4892.  
  4893.             updmode = tt_updmode = mode;
  4894.             return(setnum(&tt_update,x,y,10000));
  4895.         }
  4896.     }
  4897.     case XYTCTRL:
  4898.           if ((x = cmkey(termctrl,ntermctrl,"","7",xxstring)) < 0) {
  4899.               return(x);
  4900.           } else {
  4901.               if ((y = cmcfm()) < 0)
  4902.                   return(y);
  4903.               switch ( x ) {
  4904.               case 8:
  4905.                   send_c1 = send_c1_usr = TRUE;
  4906.                   break;
  4907.               case 7:
  4908.               default:
  4909.                   send_c1 = send_c1_usr = FALSE;
  4910.                   break;
  4911.               }
  4912.           }
  4913.           return(success = TRUE);
  4914.           break;
  4915.  
  4916. #ifdef PCFONTS
  4917.       case XYTFON:
  4918.         if ( !IsOS2FullScreen() ) {
  4919.             printf(
  4920.         "\n?SET TERMINAL FONT is only supported in Full Screen sessions.\n");
  4921.             return(success = FALSE);
  4922.         }
  4923.  
  4924.         if ((x = cmkey(term_font,ntermfont,"","default",xxstring)) < 0) {
  4925.             return(x);
  4926.         } else {
  4927.             if ((y = cmcfm()) < 0) return(y);
  4928.             if ( !os2LoadPCFonts() ) {
  4929.                 tt_font = x;
  4930.                 return(success = TRUE);
  4931.             } else {
  4932.                 printf(
  4933.       "\n?PCFONTS.DLL is not available in CKERMIT executable directory.\n");
  4934.                 return(success = FALSE);
  4935.             }
  4936.         }
  4937.         break;
  4938. #else /* PCFONTS */
  4939. #ifdef NT
  4940. #ifdef KUI
  4941.     case XYTFON:
  4942.         return(setguifont());           /* ckuus3.c */
  4943. #endif /* KUI */
  4944. #endif /* NT */
  4945. #endif /* PCFONTS */
  4946.  
  4947.       case XYTVCH: {
  4948.           extern int pheight, marginbot, cmd_rows, cmd_cols;
  4949.           if ((x = cmkey(tvctab,ntvctab,"",isWin95()?"win95-safe":"enabled",
  4950.                          xxstring)) < 0)
  4951.             return(x);
  4952.           if ((y = cmcfm()) < 0) return(y);
  4953. #ifndef KUI
  4954.           if (x != tt_modechg) {
  4955.               switch (x) {
  4956.                 case TVC_DIS:
  4957.                   /* When disabled the heights of all of the virtual screens */
  4958.                   /* must be equal to the physical height of the console     */
  4959.                   /* window and may not be changed.                          */
  4960.                   /* The width of the window may not be altered.             */
  4961.                   tt_modechg = TVC_ENA;                 /* Temporary */
  4962.                   if (marginbot > pheight-(tt_status[VTERM]?1:0))
  4963.                     marginbot = pheight-(tt_status[VTERM]?1:0);
  4964.                   tt_szchng[VCMD] = 1 ;
  4965.                   tt_rows[VCMD] = pheight;
  4966.                   VscrnInit(VCMD);
  4967.                   SetCols(VCMD);
  4968.                   cmd_rows = y;
  4969.  
  4970.                   tt_szchng[VTERM] = 2 ;
  4971.                   tt_rows[VTERM] = pheight - (tt_status[VTERM]?1:0);
  4972.                   VscrnInit(VTERM);
  4973.  
  4974.                   break;
  4975.  
  4976.                 case TVC_ENA:
  4977.                   /* When enabled the physical height of the console windows */
  4978.                   /* should be adjusted to the height of the virtual screen  */
  4979.                   /* The width may be set to anything.                       */
  4980.                   /* nothing to do                                           */
  4981.                   break;
  4982.  
  4983.               case TVC_W95:
  4984.                   /* Win95-safe mode allows the physical height to change    */
  4985.                   /* but restricts it to a width of 80 and a height equal to */
  4986.                   /* 25, 43, or 50.  Must be adjusted now.                   */
  4987.                   /* The virtual heights must be equal to the above.         */
  4988.                   if (pheight != 25 && pheight != 43 && pheight != 50) {
  4989.                       if (pheight < 25)
  4990.                         y = 25;
  4991.                       else if (pheight < 43)
  4992.                         y = 43;
  4993.                       else
  4994.                         y = 50;
  4995.                   } else
  4996.                     y = pheight;
  4997.  
  4998.                   tt_modechg = TVC_ENA; /* Temporary */
  4999.  
  5000.                   tt_szchng[VCMD] = 1;
  5001.                   tt_rows[VCMD] = y;
  5002.                   tt_cols[VCMD] = 80;
  5003.                   VscrnInit(VCMD);
  5004.                   SetCols(VCMD);
  5005.                   cmd_rows = y;
  5006.                   cmd_cols = 80;
  5007.  
  5008.                   marginbot = y-(tt_status[VTERM]?1:0);
  5009.                   tt_szchng[VTERM] = 2;
  5010.                   tt_rows[VTERM] = y - (tt_status[VTERM]?1:0);
  5011.                   tt_cols[VTERM] = 80;
  5012.                   VscrnInit(VTERM);
  5013.                   break;
  5014.               }
  5015.               tt_modechg = x;
  5016.           }
  5017.           return(success = 1);
  5018. #else /* KUI */
  5019.           return(success = 0);
  5020. #endif /* KUI */
  5021.       }
  5022.       case XYTSTAT: {
  5023.           extern int marginbot;
  5024.           if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5025.           if ((x = cmcfm()) < 0) return(x);
  5026.           if (y != tt_status[VTERM] || y != tt_status_usr[VTERM]) {
  5027.               /* Might need to fixup the margins */
  5028.               if ( marginbot == VscrnGetHeight(VTERM)-(tt_status[VTERM]?1:0) )
  5029.                 if (y) {
  5030.                     marginbot--;
  5031.                 } else {
  5032.                     marginbot++;
  5033.                 }
  5034.               tt_status_usr[VTERM] = tt_status[VTERM] = y;
  5035.               if (y) {
  5036.                     tt_szchng[VTERM] = 2;
  5037.                     tt_rows[VTERM]--;
  5038.                     VscrnInit(VTERM);  /* Height set here */
  5039. #ifdef TNCODE
  5040.                     if (TELOPT_ME(TELOPT_NAWS))
  5041.                       tn_snaws();
  5042. #endif /* TNCODE */
  5043. #ifdef RLOGCODE
  5044.                     if (TELOPT_ME(TELOPT_NAWS))
  5045.                       rlog_naws();
  5046. #endif /* RLOGCODE */
  5047. #ifdef SSHBUILTIN
  5048.                     if (TELOPT_ME(TELOPT_NAWS))
  5049.                       ssh_snaws();
  5050. #endif /* SSHBUILTIN */
  5051.               } else {
  5052.                   tt_szchng[VTERM] = 1;
  5053.                   tt_rows[VTERM]++;
  5054.                   VscrnInit(VTERM);     /* Height set here */
  5055. #ifdef TNCODE
  5056.                   if (TELOPT_ME(TELOPT_NAWS))
  5057.                     tn_snaws();
  5058. #endif /* TNCODE */
  5059. #ifdef RLOGCODE
  5060.                   if (TELOPT_ME(TELOPT_NAWS))
  5061.                     rlog_naws();
  5062. #endif /* RLOGCODE */
  5063. #ifdef SSHBUILTIN
  5064.                   if (TELOPT_ME(TELOPT_NAWS))
  5065.                     ssh_snaws();
  5066. #endif /* SSHBUILTIN */
  5067.               }
  5068.           }
  5069.           return(1);
  5070.       }
  5071. #endif /* OS2 */
  5072.  
  5073. #ifdef NT
  5074.       case XYTATTBUG:
  5075.         if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5076.         if ((x = cmcfm()) < 0) return(x);
  5077.         tt_attr_bug = y;
  5078.         return(1);
  5079. #endif /* NT */
  5080.  
  5081. #ifdef OS2
  5082.       case XYTSGRC:
  5083.         if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5084.         if ((x = cmcfm()) < 0) return(x);
  5085.         sgrcolors = y;
  5086.         return(1);
  5087.  
  5088.       case XYTSEND:
  5089.           if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5090.           if ((x = cmcfm()) < 0) return(x);
  5091.           tt_senddata = y;
  5092.           return(1);
  5093.  
  5094.       case XYTSEOB:
  5095.           if ((y = cmkey(ttyseobtab,2,"","us_cr",xxstring)) < 0) return(y);
  5096.           if ((x = cmcfm()) < 0) return(x);
  5097.           wy_blockend = y;
  5098.           return(1);
  5099.  
  5100.       case XYTURLHI: {
  5101.           int done = 0, attr = VT_CHAR_ATTR_NORMAL;
  5102.  
  5103.           if ((x = cmkey(onoff,2,"","on",xxstring)) < 0)
  5104.             return(x);
  5105.           if (x) {
  5106.               z = 0;
  5107.               while (!done) {
  5108.                   if ((y = cmkey(ttyprotab,nprotect,"",
  5109.                                  z?"done":"reverse",xxstring)) < 0)
  5110.                     return(y);
  5111.                   switch (y) {
  5112.                     case TTATTDONE:
  5113.                       done = TRUE;
  5114.                       break;
  5115.                     case TTATTBLI:
  5116.                       attr |= VT_CHAR_ATTR_BLINK;
  5117.                       break;
  5118.                     case TTATTREV:
  5119.                       attr |= VT_CHAR_ATTR_REVERSE;
  5120.                       break;
  5121.                     case TTATTITA:
  5122.                       attr |= VT_CHAR_ATTR_ITALIC;
  5123.                       break;
  5124.                     case TTATTUND:
  5125.                       attr |= VT_CHAR_ATTR_UNDERLINE;
  5126.                       break;
  5127.                     case TTATTBLD:
  5128.                       attr |= VT_CHAR_ATTR_BOLD;
  5129.                       break;
  5130.                     case TTATTDIM:
  5131.                       attr |= VT_CHAR_ATTR_DIM;
  5132.                       break;
  5133.                     case TTATTINV:
  5134.                       attr |= VT_CHAR_ATTR_INVISIBLE;
  5135.                       break;
  5136.                     case TTATTNOR:
  5137.                       break;
  5138.                   }
  5139.                   z = 1;                /* One attribute has been chosen */
  5140.               }
  5141.           }
  5142.           if ((z = cmcfm()) < 0) return(z);
  5143.           seturlhl(x);
  5144.           if (x)
  5145.             tt_url_hilite_attr = attr;
  5146.           return(1);
  5147.       }
  5148.       case XYTATTR:
  5149.         if ((x = cmkey(ttyattrtab,nattrib,"","underline",xxstring)) < 0)
  5150.           return(x);
  5151.         switch (x) {
  5152.           case TTATTBLI:
  5153.             if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5154.             if ((x = cmcfm()) < 0) return(x);
  5155.             trueblink = y;
  5156. #ifndef KUI
  5157.             if ( !trueblink && trueunderline ) {
  5158.                 trueunderline = 0;
  5159.                 printf("Warning: Underline being simulated by color.\n");
  5160.             }
  5161.  
  5162. #endif /* KUI */
  5163.             break;
  5164.  
  5165.           case TTATTDIM:
  5166.             if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5167.             if ((x = cmcfm()) < 0) return(x);
  5168.             truedim = y;
  5169.             break;
  5170.  
  5171.           case TTATTREV:
  5172.             if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5173.             if ((x = cmcfm()) < 0) return(x);
  5174.             truereverse = y;
  5175.             break;
  5176.  
  5177.           case TTATTUND:
  5178.             if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5179.             if ((x = cmcfm()) < 0) return(x);
  5180.             trueunderline = y;
  5181. #ifndef KUI
  5182.             if (!trueblink && trueunderline) {
  5183.                 trueblink = 1;
  5184.                 printf("Warning: True blink mode is active.\n");
  5185.             }
  5186. #endif /* KUI */
  5187.             break;
  5188.  
  5189.           case TTATTITA:
  5190.               if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5191.               if ((x = cmcfm()) < 0) return(x);
  5192.               trueitalic = y;
  5193.             break;
  5194.  
  5195.           case TTATTPRO: {      /* Set default Protected Character attribute */
  5196.               extern vtattrib WPattrib;    /* current WP Mode Attrib */
  5197.               extern vtattrib defWPattrib; /* default WP Mode Attrib */
  5198.               vtattrib wpa = {0,0,0,0,0,1,0,0,0};       /* Protected */
  5199.               int done = 0;
  5200.  
  5201.               x = 0;
  5202.               while (!done) {
  5203.                   if ((y = cmkey(ttyprotab,nprotect,"",
  5204.                                  x?"done":"dim",xxstring)) < 0)
  5205.                     return(y);
  5206.                   switch (y) {
  5207.                     case TTATTNOR:
  5208.                       break;
  5209.                     case TTATTBLI:      /* Blinking doesn't work */
  5210.                       wpa.blinking = TRUE;
  5211.                       break;
  5212.                     case TTATTREV:
  5213.                       wpa.reversed = TRUE;
  5214.                       break;
  5215.                     case TTATTITA:
  5216.                       wpa.italic = TRUE;
  5217.                       break;
  5218.                     case TTATTUND:
  5219.                       wpa.underlined = TRUE;
  5220.                       break;
  5221.                     case TTATTBLD:
  5222.                       wpa.bold = TRUE;
  5223.                       break;
  5224.                     case TTATTDIM:
  5225.                       wpa.dim = TRUE;
  5226.                       break;
  5227.                     case TTATTINV:
  5228.                       wpa.invisible = TRUE ;
  5229.                       break;
  5230.                     case TTATTDONE:
  5231.                       done = TRUE;
  5232.                       break;
  5233.                   }
  5234.                   x = 1;                /* One attribute has been chosen */
  5235.               }
  5236.               if ((x = cmcfm()) < 0) return(x);
  5237.               WPattrib = defWPattrib = wpa;
  5238.               break;
  5239.           }
  5240.         }
  5241.         return(1);
  5242.  
  5243.       case XYTKEY: {                    /* SET TERMINAL KEY */
  5244.           int t, x, y;
  5245.           int clear = 0, deflt = 0;
  5246.           int confirmed = 0;
  5247.           int flag = 0;
  5248.           int kc = -1;                  /* Key code */
  5249.           int litstr = 0;               /* Literal String? */
  5250.           char *s = NULL;               /* Key binding */
  5251. #ifndef NOKVERBS
  5252.           char *p = NULL;               /* Worker */
  5253. #endif /* NOKVERBS */
  5254.           con_event defevt;
  5255.           extern int os2gks;
  5256.           extern int mskkeys;
  5257.           extern int initvik;
  5258.           struct FDB kw,sw,nu,cm;
  5259.  
  5260.           defevt.type = error;
  5261.  
  5262.           if ((t = cmkey(ttkeytab,nttkey,"","",xxstring)) < 0)
  5263.             return(t);
  5264.           cmfdbi(&nu,                   /* First FDB - command switches */
  5265.                  _CMNUM,                /* fcode */
  5266.                  "/literal, keycode, or action",
  5267.                  "",                    /* default */
  5268.                  "",                    /* addtl string data */
  5269.                  10,                    /* addtl numeric data 1: radix */
  5270.                  0,                     /* addtl numeric data 2: 0 */
  5271.                  xxstring,              /* Processing function */
  5272.                  NULL,                  /* Keyword table */
  5273.                  &sw                    /* Pointer to next FDB */
  5274.                  );                     /*  */
  5275.           cmfdbi(&sw,                   /* Second FDB - switches */
  5276.                  _CMKEY,                /* fcode */
  5277.                  "",
  5278.                  "",                    /* default */
  5279.                  "",                    /* addtl string data */
  5280.                  nstrmswitab,           /* addtl numeric data 1: tbl size */
  5281.                  4,                     /* addtl numeric data 2: 4 = cmswi */
  5282.                  xxstring,              /* Processing function */
  5283.                  strmswitab,            /* Keyword table */
  5284.                  &kw                    /* Pointer to next FDB */
  5285.                  );
  5286.           cmfdbi(&kw,                   /* Third FDB - command switches */
  5287.                  _CMKEY,                /* fcode */
  5288.                  "/literal, keycode, or action",
  5289.                  "",                    /* default */
  5290.                  "",                    /* addtl string data */
  5291.                  nstrmkeytab,           /* addtl numeric data 1: tbl size */
  5292.                  0,                     /* addtl numeric data 2 */
  5293.                  xxstring,              /* Processing function */
  5294.                  strmkeytab,            /* Keyword table */
  5295.                  &cm                    /* Pointer to next FDB */
  5296.                  );
  5297.           cmfdbi(&cm,                   /* Final FDB - Confirmation */
  5298.                  _CMCFM,                /* fcode */
  5299.                  "",
  5300.                  "",                    /* default */
  5301.                  "",                    /* addtl string data */
  5302.                  0,                     /* addtl numeric data 1: tbl size */
  5303.                  0,                     /* addtl numeric data 2: 4 = cmswi */
  5304.                  xxstring,              /* Processing function */
  5305.                  NULL,                  /* Keyword table */
  5306.                  NULL                   /* Pointer to next FDB */
  5307.                  );
  5308.           while (kc < 0) {
  5309.               x = cmfdb(&nu);           /* Parse something */
  5310.               if (x < 0)
  5311.                 return(x);
  5312.  
  5313.               switch (cmresult.fcode) {
  5314.                 case _CMCFM:
  5315.                   printf(" Press key to be defined: ");
  5316.                   conbin((char)escape); /* Put terminal in binary mode */
  5317.                   os2gks = 0;           /* Turn off Kverb preprocessing */
  5318.                   kc = congks(0);       /* Get character or scan code */
  5319.                   os2gks = 1;           /* Turn on Kverb preprocessing */
  5320.                   concb((char)escape);  /* Restore terminal to cbreak mode */
  5321.                   if (kc < 0) {         /* Check for error */
  5322.                       printf("?Error reading key\n");
  5323.                       return(0);
  5324.                   }
  5325.                   shokeycode(kc,t);     /* Show current definition */
  5326.                   flag = 1;             /* Remember it's a multiline command */
  5327.                   break;
  5328.                 case _CMNUM:
  5329.                   kc = cmresult.nresult;
  5330.                   break;
  5331.                 case _CMKEY:
  5332.                   if (cmresult.fdbaddr == &sw) { /* Switch */
  5333.                       if (cmresult.nresult == 0)
  5334.                         litstr = 1;
  5335.                   } else if (cmresult.fdbaddr == &kw) { /* Keyword */
  5336.                       if (cmresult.nresult == 0)
  5337.                         clear = 1;
  5338.                       else
  5339.                         deflt = 1;
  5340.                       if ((x = cmcfm()) < 0)
  5341.                         return(x);
  5342.                       if (clear)
  5343.                         clearkeymap(t);
  5344.                       else if (deflt)
  5345.                         defaultkeymap(t);
  5346.                       initvik = 1;
  5347.                       return(1);
  5348.                   }
  5349.               }
  5350.           }
  5351.  
  5352.     /* Normal SET TERMINAL KEY <terminal> <scancode> <value> command... */
  5353.  
  5354.           if (mskkeys)
  5355.             kc = msktock(kc);
  5356.  
  5357.           if (kc < 0 || kc >= KMSIZE) {
  5358.               printf("?key code must be between 0 and %d\n", KMSIZE - 1);
  5359.               return(-9);
  5360.           }
  5361.           if (kc == escape) {
  5362.               printf("Sorry, %d is the CONNECT-mode escape character\n",kc);
  5363.               return(-9);
  5364.           }
  5365.           wideresult = -1;
  5366.           if (flag) {
  5367.               cmsavp(psave,PROMPTL);
  5368.               cmsetp(" Enter new definition: ");
  5369.               cmini(ckxech);
  5370.           }
  5371.         def_again:
  5372.           if (flag) prompt(NULL);
  5373.           if ((y = cmtxt("key definition,\n\
  5374.  or Ctrl-C to cancel this command,\n\
  5375.  or Enter to restore default definition",
  5376.                          "",&s,NULL)) < 0) {
  5377.               if (flag)                 /* Handle parse errors */
  5378.                 goto def_again;
  5379.               else
  5380.                 return(y);
  5381.           }
  5382.           s = brstrip(s);
  5383. #ifndef NOKVERBS
  5384.           p = s;                        /* Save this place */
  5385. #endif /* NOKVERBS */
  5386. /*
  5387.   If the definition included any \Kverbs, quote the backslash so the \Kverb
  5388.   will still be in the definition when the key is pressed.  We don't do this
  5389.   in zzstring(), because \Kverbs are valid only in this context and nowhere
  5390.   else.
  5391.  
  5392.   We use this code active for all versions that support SET KEY, even if they
  5393.   don't support \Kverbs, because otherwise \K would behave differently for
  5394.   different versions.
  5395. */
  5396.           for (x = 0, y = 0; s[x]; x++, y++) { /* Convert \K to \\K */
  5397.               if ((x > 0) &&
  5398.                   (s[x] == 'K' || s[x] == 'k')
  5399.                   ) {                   /* Have K */
  5400.  
  5401.                   if ((x == 1 && s[x-1] == CMDQ) ||
  5402.                       (x > 1 && s[x-1] == CMDQ && s[x-2] != CMDQ)) {
  5403.                       line[y++] = CMDQ; /* Make it \\K */
  5404.                   }
  5405.                   if (x > 1 && s[x-1] == '{' && s[x-2] == CMDQ) {
  5406.                       line[y-1] = CMDQ; /* Have \{K */
  5407.                       line[y++] = '{';  /* Make it \\{K */
  5408.                   }
  5409.               }
  5410.               line[y] = s[x];
  5411.           }
  5412.           line[y++] = NUL;              /* Terminate */
  5413.           s = line + y + 1;             /* Point to after it */
  5414.           x = LINBUFSIZ - (int) strlen(line) - 1; /* Get remaining space */
  5415.           if ((x < (LINBUFSIZ / 2)) ||
  5416.               (zzstring(line, &s, &x) < 0)) { /* Expand variables, etc. */
  5417.               printf("?Key definition too long\n");
  5418.               if (flag) cmsetp(psave);
  5419.               return(-9);
  5420.           }
  5421.           s = line + y + 1;             /* Point to result. */
  5422.  
  5423. #ifndef NOKVERBS
  5424. /*
  5425.   Special case: see if the definition starts with a \Kverb.
  5426.   If it does, point to it with p, otherwise set p to NULL.
  5427. */
  5428.           p = s;
  5429.           if (*p++ == CMDQ) {
  5430.               if (*p == '{') p++;
  5431.               p = (*p == 'k' || *p == 'K') ? p + 1 : NULL;
  5432.           }
  5433. #endif /* NOKVERBS */
  5434.  
  5435.           switch (strlen(s)) {          /* Action depends on length */
  5436.             case 0:                     /* Clear individual key def */
  5437.               deletekeymap(t,kc);
  5438.               break;
  5439.             case 1:
  5440.               if (!litstr) {
  5441.                   defevt.type = key;    /* Single character */
  5442.                   defevt.key.scancode = *s;
  5443.                   break;
  5444.               }
  5445.             default:                    /* Character string */
  5446. #ifndef NOKVERBS
  5447.               if (p) {
  5448.                   y = xlookup(kverbs,p,nkverbs,&x); /* Look it up */
  5449.                   /* Need exact match */
  5450.                   debug(F101,"set key kverb lookup",0,y);
  5451.                   if (y > -1) {
  5452.                       defevt.type = kverb;
  5453.                       defevt.kverb.id = y;
  5454.                       break;
  5455.                   }
  5456.               }
  5457. #endif /* NOKVERBS */
  5458.               if (litstr) {
  5459.                   defevt.type = literal;
  5460.                   defevt.literal.string = (char *) malloc(strlen(s)+1);
  5461.                   if (defevt.literal.string)
  5462.                     strcpy(defevt.literal.string, s); /* safe */
  5463.               } else {
  5464.                   defevt.type = macro;
  5465.                   defevt.macro.string = (char *) malloc(strlen(s)+1);
  5466.                   if (defevt.macro.string)
  5467.                     strcpy(defevt.macro.string, s); /* safe */
  5468.               }
  5469.               break;
  5470.           }
  5471.           insertkeymap(t, kc, defevt);
  5472.           if (flag)
  5473.             cmsetp(psave);
  5474.           initvik = 1;                  /* Update VIK table */
  5475.           return(1);
  5476.       }
  5477.  
  5478. #ifdef PCTERM
  5479.       case XYTPCTERM:                   /* PCTERM Keyboard Mode */
  5480.         if ((x = seton(&tt_pcterm)) < 0) return(x);
  5481.         return(success = 1);
  5482. #endif /* PCTERM */
  5483. #endif /* OS2 */
  5484.  
  5485. #ifdef CK_TRIGGER
  5486.       case XYTRIGGER:
  5487.         if ((y = cmtxt("String to trigger automatic return to command mode",
  5488.                        "",&s,xxstring)) < 0)
  5489.           return(y);
  5490.         makelist(s,tt_trigger,TRIGGERS);
  5491.         return(1);
  5492. #endif /* CK_TRIGGER */
  5493.  
  5494. #ifdef OS2
  5495.       case XYTSAC:
  5496.         if ((y = cmnum("ASCII value to use for spacing attributes",
  5497.                        "32",10,&x,xxstring)) < 0)
  5498.           return(y);
  5499.         if ((y = cmcfm()) < 0) return(y);
  5500.         tt_sac = x;
  5501.         return(success = 1);
  5502.  
  5503.       case XYTKBDGL: {      /* SET TERM KBD-FOLLOWS-GL/GR */
  5504.           extern int tt_kb_glgr;        /* from ckoco3.c */
  5505.           if ((x = seton(&tt_kb_glgr)) < 0)
  5506.               return(x);
  5507.           return(success = 1);
  5508.       }
  5509. #ifndef NOCSETS
  5510.       case XYTVTLNG:        /* SET TERM DEC-LANGUAGE */
  5511.         if ((y = cmkey(vtlangtab,nvtlangtab,"VT language",
  5512.                        IS97801(tt_type_mode)?"german":"north-american",
  5513.                        xxstring)) < 0)
  5514.           return(y);
  5515.         if ((x = cmcfm()) < 0) return(x);
  5516.  
  5517.         /* A real VT terminal would use the language to set the   */
  5518.         /* default keyboard language for both 8-bit multinational */
  5519.         /* and 7-bit national modes.  For 8-bit mode it would     */
  5520.         /* set the terminal character-set to the ISO set if it    */
  5521.         /* is not already set.                                    */
  5522.         /* Latin-1 can be replaced by DEC Multinational           */
  5523.         switch (y) {
  5524.           case VTL_NORTH_AM:  /* North American */
  5525.             /* Multinational: Latin-1   */
  5526.             /* National:      US_ASCII  */
  5527.             dec_lang = y;
  5528.             dec_nrc = TX_ASCII;
  5529.             dec_kbd = TX_8859_1;
  5530.             break;
  5531.           case VTL_BRITISH :
  5532.             /* Multinational: Latin-1   */
  5533.             /* National:      UK_ASCII  */
  5534.             dec_lang = y;
  5535.             dec_nrc = TX_BRITISH;
  5536.             dec_kbd = TX_8859_1;
  5537.             break;
  5538.           case VTL_FRENCH  :
  5539.           case VTL_BELGIAN :
  5540.           case VTL_CANADIAN:
  5541.             /* Multinational: Latin-1   */
  5542.             /* National:      FR_ASCII  */
  5543.             dec_lang = y;
  5544.             dec_nrc = TX_FRENCH;
  5545.             dec_kbd = TX_8859_1;
  5546.             break;
  5547.           case VTL_FR_CAN  :
  5548.             /* Multinational: Latin-1   */
  5549.             /* National:      FC_ASCII  */
  5550.             dec_lang = y;
  5551.             dec_nrc = TX_CN_FRENCH;
  5552.             dec_kbd = TX_8859_1;
  5553.             break;
  5554.           case VTL_DANISH  :
  5555.           case VTL_NORWEGIA:
  5556.             /* Multinational: Latin-1   */
  5557.             /* National:      NO_ASCII  */
  5558.             dec_lang = y;
  5559.             dec_nrc = TX_NORWEGIAN;
  5560.             dec_kbd = TX_8859_1;
  5561.             break;
  5562.           case VTL_FINNISH :
  5563.             /* Multinational: Latin-1   */
  5564.             /* National:      FI_ASCII  */
  5565.             dec_lang = y;
  5566.             dec_nrc = TX_FINNISH;
  5567.             dec_kbd = TX_8859_1;
  5568.             break;
  5569.           case VTL_GERMAN  :
  5570.             /* Multinational: Latin-1   */
  5571.             /* National:      GR_ASCII  */
  5572.             dec_lang = y;
  5573.             dec_nrc = TX_GERMAN;
  5574.             dec_kbd = TX_8859_1;
  5575.             break;
  5576.           case VTL_DUTCH   :
  5577.             /* Multinational: Latin-1   */
  5578.             /* National:      DU_ASCII  */
  5579.             dec_lang = y;
  5580.             dec_nrc = TX_DUTCH;
  5581.             dec_kbd = TX_8859_1;
  5582.             break;
  5583.           case VTL_ITALIAN :
  5584.             /* Multinational: Latin-1   */
  5585.             /* National:      IT_ASCII  */
  5586.             dec_lang = y;
  5587.             dec_nrc = TX_ITALIAN;
  5588.             dec_kbd = TX_8859_1;
  5589.             break;
  5590.           case VTL_SW_FR   :
  5591.           case VTL_SW_GR   :
  5592.             /* Multinational: Latin-1   */
  5593.             /* National:      CH_ASCII  */
  5594.             dec_lang = y;
  5595.             dec_nrc = TX_SWISS;
  5596.             dec_kbd = TX_8859_1;
  5597.             break;
  5598.           case VTL_SWEDISH :
  5599.             /* Multinational: Latin-1   */
  5600.             /* National:      SW_ASCII  */
  5601.             dec_lang = y;
  5602.             dec_nrc = TX_SWEDISH;
  5603.             dec_kbd = TX_8859_1;
  5604.             break;
  5605.           case VTL_SPANISH :
  5606.             /* Multinational: Latin-1   */
  5607.             /* National:      SP_ASCII  */
  5608.             dec_lang = y;
  5609.             dec_nrc = TX_SPANISH;
  5610.             dec_kbd = TX_8859_1;
  5611.             break;
  5612.           case VTL_PORTUGES:
  5613.             /* Multinational: Latin-1   */
  5614.             /* National:      Portugese ASCII  */
  5615.             dec_lang = y;
  5616.             dec_nrc = TX_PORTUGUESE;
  5617.             dec_kbd = TX_8859_1;
  5618.             break;
  5619.           case VTL_HEBREW  :
  5620.             /* Multinational: Latin-Hebrew / DEC-Hebrew  */
  5621.             /* National:      DEC 7-bit Hebrew  */
  5622.             dec_lang = y;
  5623.             dec_nrc = TX_HE7;
  5624.             dec_kbd = TX_8859_8;
  5625.             break;
  5626.           case VTL_GREEK   :
  5627.             /* Multinational: Latin-Greek / DEC-Greek   */
  5628.             /* National:      DEC Greek NRC             */
  5629.             /* is ELOT927 equivalent to DEC Greek????   */
  5630.             dec_lang = y;
  5631.             dec_nrc = TX_ELOT927;
  5632.             dec_kbd = TX_8859_7;
  5633.             break;
  5634. #ifdef COMMENT
  5635.           case VTL_TURK_Q  :
  5636.           case VTL_TURK_F  :
  5637.             /* Multinational: Latin-Turkish / DEC-Turkish   */
  5638.             /* National:      DEC 7-bit Turkish             */
  5639.             break;
  5640. #endif /* COMMENT */
  5641.           case VTL_HUNGARIA:
  5642.             /* Multinational: Latin-2   */
  5643.             /* National:      no national mode  */
  5644.             dec_lang = y;
  5645.             dec_nrc = TX_HUNGARIAN;
  5646.             dec_kbd = TX_8859_2;
  5647.             break;
  5648.           case VTL_SLOVAK  :
  5649.           case VTL_CZECH   :
  5650.           case VTL_POLISH  :
  5651.           case VTL_ROMANIAN:
  5652.             /* Multinational: Latin-2   */
  5653.             /* National:      no national mode  */
  5654.             dec_lang = y;
  5655.             dec_nrc = TX_ASCII;
  5656.             dec_kbd = TX_8859_2;
  5657.             break;
  5658.           case VTL_RUSSIAN :
  5659.             /* Multinational: Latin-Cyrillic / KOI-8   */
  5660.             /* National:      DEC Russian NRC  */
  5661.             dec_lang = y;
  5662.             dec_nrc = TX_KOI7;
  5663.             dec_kbd = TX_8859_5;
  5664.             break;
  5665.           case VTL_LATIN_AM:
  5666.             /* Multinational: not listed in table   */
  5667.             /* National:      not listed in table  */
  5668.             dec_lang = y;
  5669.             dec_nrc = TX_ASCII;
  5670.             dec_kbd = TX_8859_1;
  5671.             break;
  5672. #ifdef COMMENT
  5673.           case VTL_SCS     :
  5674.             /* Multinational: Latin-2   */
  5675.             /* National:      SCS NRC   */
  5676.             break;
  5677. #endif /* COMMENT */
  5678.           default:
  5679.             return(success = 0);
  5680.         }
  5681.         if (IS97801(tt_type_mode)) {
  5682.             SNI_bitmode(cmask == 0377 ? 8 : 7);
  5683.         }
  5684.         return(success = 1);
  5685. #endif /* NOCSETS */
  5686.  
  5687.       case XYTVTNRC: {                  /* SET TERM DEC-NRC-MODE */
  5688.           extern int decnrcm_usr, decnrcm;        /* from ckoco3.c */
  5689.           if ((x = seton(&decnrcm_usr)) < 0)
  5690.             return(x);
  5691.           decnrcm = decnrcm_usr;
  5692.           return(success = 1);
  5693.       }
  5694.       case XYTSNIPM: {                  /* SET TERM SNI-PAGEMODE */
  5695.           extern int sni_pagemode, sni_pagemode_usr;
  5696.           if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5697.           if ((x = cmcfm()) < 0) return(x);
  5698.           sni_pagemode_usr = sni_pagemode = y;
  5699.           return(success = 1);
  5700.       }
  5701.       case XYTSNISM: {                  /* SET TERM SNI-SCROLLMODE */
  5702.           extern int sni_scroll_mode, sni_scroll_mode_usr;
  5703.           if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5704.           if ((x = cmcfm()) < 0) return(x);
  5705.           sni_scroll_mode_usr = sni_scroll_mode = y;
  5706.           return(success = 1);
  5707.       }
  5708.       case XYTSNICC: {  /* SET TERM SNI-CH.CODE */
  5709.           extern int sni_chcode_usr;
  5710.           if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5711.           if ((x = cmcfm()) < 0) return(x);
  5712.           sni_chcode_usr = y;
  5713.           SNI_chcode(y);
  5714.           return(success = 1);
  5715.       }
  5716.       case XYTSNIFV: {  /* SET TERM SNI-FIRMWARE-VERSIONS */
  5717.           extern CHAR sni_kbd_firmware[], sni_term_firmware[];
  5718.           CHAR kbd[7],term[7];
  5719.  
  5720.           if ((x = cmfld("Keyboard Firmware Version",sni_kbd_firmware,
  5721.                          &s, xxstring)) < 0)
  5722.             return(x);
  5723.           if ((int)strlen(s) != 6) {
  5724.               printf("?Sorry - the firmware version must be 6 digits long\n");
  5725.               return(-9);
  5726.           }
  5727.           for (i = 0; i < 6; i++) {
  5728.               if (!isdigit(s[i])) {
  5729.    printf("?Sorry - the firmware version can only contain digits [0-9]\n");
  5730.                   return(-9);
  5731.               }
  5732.           }
  5733.           ckstrncpy(kbd,s,7);
  5734.  
  5735.           if ((x = cmfld("Terminal Firmware Version",sni_term_firmware,
  5736.                          &s, xxstring)) < 0)
  5737.             return(x);
  5738.           if ((int)strlen(s) != 6) {
  5739.               printf("?Sorry - the firmware version must be 6 digits long\n");
  5740.               return(-9);
  5741.           }
  5742.           for (i = 0; i < 6; i++) {
  5743.               if (!isdigit(s[i])) {
  5744.    printf("?Sorry - the firmware version can only contain digits [0-9]\n");
  5745.                    return(-9);
  5746.               }
  5747.           }
  5748.           ckstrncpy(term,s,7);
  5749.           if ((x = cmcfm()) < 0) return(x);
  5750.  
  5751.           ckstrncpy(sni_kbd_firmware,kbd,7);
  5752.           ckstrncpy(sni_term_firmware,term,7);
  5753.           return(success = 1);
  5754.     }
  5755. #endif /* OS2 */
  5756.  
  5757.       default:                          /* Shouldn't get here. */
  5758.         return(-2);
  5759.     }
  5760. #endif /* MAC */
  5761. #ifdef COMMENT
  5762.     /*
  5763.       This was supposed to shut up picky compilers but instead it makes
  5764.       most compilers complain about "statement not reached".
  5765.     */
  5766.     return(-2);
  5767. #endif /* COMMENT */
  5768. #ifdef OS2
  5769. return(-2);
  5770. #endif /* OS2 */
  5771. }
  5772.  
  5773. #ifdef OS2
  5774. int
  5775. settitle(void) {
  5776.     extern char usertitle[];
  5777.     if ((y = cmtxt("title text","",&s,xxstring)) < 0)
  5778.       return(y);
  5779. #ifdef IKSD
  5780.     if (inserver) {
  5781.         printf("?Sorry, command disabled.\r\n");
  5782.         return(success = 0);
  5783.     }
  5784. #endif /* IKSD */
  5785.  
  5786.     ckstrncpy(usertitle,s,64);
  5787.     os2settitle("",1);
  5788.     return(1);
  5789. }
  5790.  
  5791. static struct keytab dialertab[] = {    /* K95 Dialer types */
  5792.     "backspace",        0, 0,
  5793.     "enter",            1, 0
  5794. };
  5795. static int ndialer = 2;
  5796.  
  5797. int
  5798. setdialer(void) {
  5799.     int t, x, y;
  5800.     int clear = 0, deflt = 0;
  5801.     int kc;                             /* Key code */
  5802.     char *s = NULL;                     /* Key binding */
  5803. #ifndef NOKVERBS
  5804.     char *p = NULL;                     /* Worker */
  5805. #endif /* NOKVERBS */
  5806.     con_event defevt;
  5807.     extern int os2gks;
  5808.     extern int mskkeys;
  5809.     extern int initvik;
  5810.  
  5811.     defevt.type = error;
  5812.  
  5813.     if (( x = cmkey(dialertab, ndialer,
  5814.                     "Kermit-95 dialer work-arounds",
  5815.                     "", xxstring)) < 0 )
  5816.       return(x);
  5817.     switch (x) {
  5818.       case 0:                           /* Backspace */
  5819.         kc = 264;
  5820.         break;
  5821.       case 1:                           /* Enter */
  5822.         kc = 269;
  5823.         break;
  5824.       default:
  5825.         printf("Illegal value in setdialer()\n");
  5826.         return(-9);
  5827.     }
  5828.     if ((y = cmtxt("Key definition","",&s,xxstring)) < 0)
  5829.       return(y);
  5830.  
  5831. #ifdef IKSD
  5832.     if (inserver) {
  5833.         printf("?Sorry, command disabled.\r\n");
  5834.         return(success = 0);
  5835.     }
  5836. #endif /* IKSD */
  5837.     s = brstrip(s);
  5838. #ifndef NOKVERBS
  5839.     p = s;                              /* Save this place */
  5840. #endif /* NOKVERBS */
  5841. /*
  5842.   If the definition included any \Kverbs, quote the backslash so the \Kverb
  5843.   will still be in the definition when the key is pressed.  We don't do this
  5844.   in zzstring(), because \Kverbs are valid only in this context and nowhere
  5845.   else.
  5846.  
  5847.   We use this code active for all versions that support SET KEY, even if they
  5848.   don't support \Kverbs, because otherwise \K would behave differently for
  5849.   different versions.
  5850. */
  5851.     for (x = 0, y = 0; s[x]; x++, y++) { /* Convert \K to \\K */
  5852.         if ((x > 0) &&
  5853.             (s[x] == 'K' || s[x] == 'k')
  5854.             ) {                         /* Have K */
  5855.  
  5856.             if ((x == 1 && s[x-1] == CMDQ) ||
  5857.                 (x > 1 && s[x-1] == CMDQ && s[x-2] != CMDQ)) {
  5858.                 line[y++] = CMDQ;       /* Make it \\K */
  5859.             }
  5860.             if (x > 1 && s[x-1] == '{' && s[x-2] == CMDQ) {
  5861.                 line[y-1] = CMDQ;       /* Have \{K */
  5862.                 line[y++] = '{';        /* Make it \\{K */
  5863.             }
  5864.         }
  5865.         line[y] = s[x];
  5866.     }
  5867.     line[y++] = NUL;                    /* Terminate */
  5868.     s = line + y + 1;                   /* Point to after it */
  5869.     x = LINBUFSIZ - (int) strlen(line) - 1; /* Calculate remaining space */
  5870.     if ((x < (LINBUFSIZ / 2)) ||
  5871.         (zzstring(line, &s, &x) < 0)) { /* Expand variables, etc. */
  5872.         printf("?Key definition too long\n");
  5873.         return(-9);
  5874.     }
  5875.     s = line + y + 1;                   /* Point to result. */
  5876.  
  5877. #ifndef NOKVERBS
  5878. /*
  5879.   Special case: see if the definition starts with a \Kverb.
  5880.   If it does, point to it with p, otherwise set p to NULL.
  5881. */
  5882.     p = s;
  5883.     if (*p++ == CMDQ) {
  5884.         if (*p == '{') p++;
  5885.         p = (*p == 'k' || *p == 'K') ? p + 1 : NULL;
  5886.     }
  5887. #endif /* NOKVERBS */
  5888.  
  5889.     /* Now reprogram the default value for all terminal types */
  5890.     /* remember to treat Wyse and Televideo terminals special */
  5891.     /* because of their use of Kverbs for Backspace and Enter */
  5892.     for (t = 0; t <= TT_MAX; t++) {
  5893.         if ( ISDG200(t) && kc == 264) {
  5894.             extern char * udkfkeys[] ;
  5895.             if (kc == 264) {            /* \Kdgbs */
  5896.                 if (udkfkeys[83])
  5897.                   free(udkfkeys[83]);
  5898.                 udkfkeys[83] = strdup(s);
  5899.             }
  5900.         } else if (ISWYSE(t) || ISTVI(t)) {
  5901.             extern char * udkfkeys[] ;
  5902.             if (kc == 264) {            /* \Kwybs or \Ktvibs */
  5903.                 if (udkfkeys[32])
  5904.                   free(udkfkeys[32]);
  5905.                 udkfkeys[32] = strdup(s);
  5906.             }
  5907.             if (kc == 269) {            /* \Kwyenter and \Kwyreturn */
  5908.                 if (udkfkeys[39])       /* \Ktvienter and \Ktvireturn */
  5909.                   free(udkfkeys[39]);
  5910.                 udkfkeys[39] = strdup(s);
  5911.                 if (udkfkeys[49])
  5912.                   free(udkfkeys[49]);
  5913.                 udkfkeys[49] = strdup(s);
  5914.             }
  5915.         } else {
  5916.             switch (strlen(s)) {        /* Action depends on length */
  5917.               case 0:                   /* Clear individual key def */
  5918.                 deletekeymap(t,kc);
  5919.                 break;
  5920.               case 1:
  5921.                 defevt.type = key;      /* Single character */
  5922.                 defevt.key.scancode = *s;
  5923.                 break;
  5924.               default:                  /* Character string */
  5925. #ifndef NOKVERBS
  5926.                 if (p) {
  5927.                     y = xlookup(kverbs,p,nkverbs,&x); /* Look it up */
  5928.                     /* Exact match req'd */
  5929.                     debug(F101,"set key kverb lookup",0,y);
  5930.                     if (y > -1) {
  5931.                         defevt.type = kverb;
  5932.                         defevt.kverb.id = y;
  5933.                         break;
  5934.                     }
  5935.                 }
  5936. #endif /* NOKVERBS */
  5937.                 defevt.type = macro;
  5938.                 defevt.macro.string = (char *) malloc(strlen(s)+1);
  5939.                 if (defevt.macro.string)
  5940.                   strcpy(defevt.macro.string, s); /* safe */
  5941.                 break;
  5942.             }
  5943.             insertkeymap( t, kc, defevt ) ;
  5944.             initvik = 1;                /* Update VIK table */
  5945.         }
  5946.     }
  5947.     return(1);
  5948. }
  5949. #endif /* OS2 */
  5950.  
  5951. #ifdef NT
  5952. int
  5953. setwin95( void ) {
  5954.     int x, y, z;
  5955.  
  5956.     if (( y = cmkey(win95tab, nwin95,
  5957.                     "Windows 95 specific work-arounds",
  5958.                     "keyboard-translation",
  5959.                     xxstring)) < 0 )
  5960.         return (y);
  5961.     switch (y) {
  5962.       case XYWPOPUP:
  5963.         if ((y = cmkey(onoff,2,"popups are used to prompt the user for data",
  5964.                        "on",xxstring)) < 0)
  5965.           return(y);
  5966.         if ((x = cmcfm()) < 0) return(x);
  5967.         win95_popup = y;
  5968.         return(1);
  5969.  
  5970.       case XYW8_3:
  5971.         if ((y = cmkey(onoff,2,"8.3 FAT file names","off",xxstring)) < 0)
  5972.           return(y);
  5973.         if ((x = cmcfm()) < 0) return(x);
  5974.         win95_8_3 = y;
  5975.         return(1);
  5976.  
  5977.       case XYWSELECT:
  5978.         if ((y = cmkey(onoff,2,"\"select()\" fails on write","off",
  5979.              xxstring)) < 0)
  5980.           return(y);
  5981.         if ((x = cmcfm()) < 0) return(x);
  5982.         win95selectbug = y;
  5983.         return(1);
  5984.  
  5985.       case XYWAGR:
  5986.         if ((y = cmkey(onoff,2,"Right-Alt is Alt-Gr","off",xxstring)) < 0)
  5987.           return(y);
  5988.         if ((x = cmcfm()) < 0) return(x);
  5989.         win95altgr = y;
  5990.         return(1);
  5991.  
  5992.       case XYWOIO:
  5993.         if ((y = cmkey(onoff,2,"Use Overlapped I/O","on",xxstring)) < 0)
  5994.           return(y);
  5995.         if (y) {
  5996.             if ((x = cmnum("Maximum number of outstanding I/O requests",
  5997.                            "10",10,&z,xxstring)) < 0)
  5998.               return(x);
  5999.             if (z < 1 || z > 30) {
  6000.                 printf(
  6001. "?Maximum outstanding I/O requests must be between 1 and 30.\n");
  6002.                 return(-9);
  6003.             }
  6004.         } else
  6005.           z = 1;
  6006.         if ((x = cmcfm()) < 0) return(x);
  6007.         owwait = !y;
  6008.         maxow = maxow_usr = z;
  6009.         return(1);
  6010.  
  6011.       case XYWKEY:
  6012. #ifndef COMMENT
  6013.         printf("\n?\"Keyboard-Translation\" is no longer required.\n");
  6014.         return(-9);
  6015. #else /* COMMENT */
  6016.         if (( z = cmkey(tcstab, ntcs,
  6017.                         "Keyboard Character Set",
  6018.                         "latin1-iso",
  6019.                         xxstring)) < 0)
  6020.           return (z);
  6021.         if ((x = cmcfm()) < 0)
  6022.           return(x);
  6023.  
  6024.         win95kcsi = z;
  6025.         win95kl2 = (win95kcsi == TC_2LATIN);
  6026.  
  6027.         if (win95kcsi == TC_TRANSP) {
  6028.             win95kcs = NULL;
  6029.         } else {
  6030. #ifdef UNICODE
  6031.             win95kcs = xlr[win95kcsi][tx2fc(tcsl)];
  6032. #else /* UNICODE */
  6033.             win95kcs = xlr[win95kcsi][tcsl];
  6034. #endif /* UNICODE */
  6035.         }
  6036.         return(1);
  6037. #endif /* COMMENT */
  6038.  
  6039.       case XYWLUC:
  6040.         if ((y = cmkey(onoff,2,"Unicode-to-Lucida-Console substitutions",
  6041.                        "on",xxstring)) < 0)
  6042.           return(y);
  6043.         if ((x = cmcfm()) < 0) return(x);
  6044.         win95lucida = y;
  6045.         return(1);
  6046.  
  6047.       case XYWHSL:
  6048.     if ((y = cmkey(onoff,2,"Horizontal Scan Line substitutions",
  6049.                "on",xxstring)) < 0)
  6050.       return(y);
  6051.     if ((x = cmcfm()) < 0) return(x);
  6052.     win95hsl = y;
  6053.     return(1);
  6054.  
  6055.       default:
  6056.         printf("Illegal value in setwin95()\n");
  6057.         return(-9);
  6058.     }
  6059. }
  6060. #endif /* NT */
  6061.  
  6062. #ifdef OS2
  6063. int
  6064. setprty (
  6065. #ifdef CK_ANSIC
  6066.     void
  6067. #endif /* CK_ANSIC */
  6068. /* setprty */ ) {
  6069.     int x, y, z;
  6070.  
  6071.     if (( y = cmkey(prtytab, nprty,
  6072.                     "priority level of terminal and communication threads",
  6073.                     "foreground-server",
  6074.                     xxstring)) < 0 )
  6075.       return (y);
  6076.  
  6077.     if ((x = cmcfm()) < 0)
  6078.       return (x);
  6079. #ifdef IKSD
  6080.     if (inserver &&
  6081. #ifdef IKSDCONF
  6082.          iksdcf
  6083. #else
  6084.          1
  6085. #endif /* IKSDCONF */
  6086.     ) {
  6087.         if ((y = cmcfm()) < 0) return(y);
  6088.         printf("?Sorry, command disabled.\r\n");
  6089.         return(success = 0);
  6090.     }
  6091. #endif /* IKSD */
  6092.     priority = y;
  6093.     return(TRUE);
  6094. }
  6095. #endif /* OS2 */
  6096.  
  6097. int
  6098. setbell() {
  6099.     int y, x;
  6100. #ifdef OS2
  6101.     int z;
  6102. #endif /* OS2 */
  6103.  
  6104.     if ((y = cmkey(beltab,nbeltab,
  6105. #ifdef OS2
  6106.         "how console and terminal bells should\nbe generated", "audible",
  6107. #else
  6108.         "Whether Kermit should ring the terminal bell (beep)", "on",
  6109. #endif /* OS2 */
  6110.                    xxstring)) < 0)
  6111.           return(y);
  6112.  
  6113. #ifdef IKSD
  6114.     if (inserver) {
  6115.         if ((y = cmcfm()) < 0) return(y);
  6116.         printf("?Sorry, command disabled.\r\n");
  6117.         return(success = 0);
  6118.     }
  6119. #endif /* IKSD */
  6120.  
  6121.     switch (y) {                        /* SET BELL */
  6122.       case XYB_NONE:
  6123. #ifdef OS2
  6124.       case XYB_VIS:
  6125. #endif /* OS2 */
  6126.         if ((x = cmcfm()) < 0)
  6127.           return(x);
  6128. #ifdef OS2
  6129.         tt_bell = y;
  6130. #else
  6131.         tt_bell = 0;
  6132. #endif /* OS2 */
  6133.         break;
  6134.  
  6135.       case XYB_AUD:
  6136. #ifdef OS2
  6137.         if ((x = cmkey(audibletab, naudibletab,
  6138.                "how audible console and terminal\nbells should be generated",
  6139.                        "beep",xxstring))<0)
  6140.           return(x);
  6141.         if ((z = cmcfm()) < 0)
  6142.           return(z);
  6143.         tt_bell = y | x;
  6144. #else
  6145.         /* This lets C-Kermit accept but ignore trailing K95 keywords */
  6146.         if ((x = cmtxt("Confirm with carriage return","",&s,xxstring)) < 0)
  6147.           return(x);
  6148.         tt_bell = 1;
  6149. #endif /* OS2 */
  6150.         break;
  6151.     }
  6152.     return(1);
  6153. }
  6154.  
  6155. #ifdef OS2MOUSE
  6156. int
  6157. setmou(
  6158. #ifdef CK_ANSIC
  6159.        void
  6160. #endif /* CK_ANSIC */
  6161.  /* setmou */ ) {
  6162.     extern int initvik;
  6163.     int button = 0, event = 0;
  6164.     char * p;
  6165.  
  6166.     if ((y = cmkey(mousetab,nmtab,"","",xxstring)) < 0)
  6167.       return(y);
  6168.  
  6169. #ifdef IKSD
  6170.     if (inserver) {
  6171.         if ((y = cmcfm()) < 0) return(y);
  6172.         printf("?Sorry, command disabled.\r\n");
  6173.         return(success = 0);
  6174.     }
  6175. #endif /* IKSD */
  6176.  
  6177.     if (y == XYM_ON) {                  /* MOUSE ACTIVATION */
  6178.         int old_mou = tt_mouse;
  6179.         if ((x = seton(&tt_mouse)) < 0)
  6180.             return(x);
  6181.         if (tt_mouse != old_mou)
  6182.           if (tt_mouse)
  6183.             os2_mouseon();
  6184.           else
  6185.             os2_mouseoff();
  6186.         return(1);
  6187.     }
  6188.  
  6189.     if (y == XYM_DEBUG) {               /* MOUSE DEBUG */
  6190.         extern int MouseDebug;
  6191.         if ((x = seton(&MouseDebug)) < 0)
  6192.             return(x);
  6193.         return(1);
  6194.     }
  6195.  
  6196.     if (y == XYM_CLEAR) {               /* Reset Mouse Defaults */
  6197.         if ((x = cmcfm()) < 0) return(x);
  6198.         mousemapinit(-1,-1);
  6199.         initvik = 1;                    /* Update VIK Table */
  6200.         return 1;
  6201.     }
  6202.     if (y != XYM_BUTTON) {              /* Shouldn't happen. */
  6203.         printf("Internal parsing error\n");
  6204.         return(-9);
  6205.     }
  6206.  
  6207.     /* MOUSE EVENT ... */
  6208.  
  6209.     if ((button = cmkey(mousebuttontab,nmbtab,
  6210.                         "Button number","1",
  6211.                         xxstring)) < 0)
  6212.       return(button);
  6213.  
  6214.     if ((y =  cmkey(mousemodtab,nmmtab,
  6215.                     "Keyboard modifier","none",
  6216.                     xxstring)) < 0)
  6217.       return(y);
  6218.  
  6219.     event |= y;                         /* OR in the bits */
  6220.  
  6221.     if ((y =  cmkey(mclicktab,nmctab,"","click",xxstring)) < 0)
  6222.       return(y);
  6223.  
  6224.     /* Two bits are assigned, if neither are set then it is button one */
  6225.  
  6226.     event |= y;                 /* OR in the bit */
  6227.  
  6228.     wideresult = -1;
  6229.  
  6230.     if ((y = cmtxt("definition,\n\
  6231. or Ctrl-C to cancel this command,\n\
  6232. or Enter to restore default definition",
  6233.                    "",&s,NULL)) < 0) {
  6234.         return(y);
  6235.     }
  6236.     s = brstrip(s);
  6237.     p = s;                              /* Save this place */
  6238. /*
  6239.   If the definition included any \Kverbs, quote the backslash so the \Kverb
  6240.   will still be in the definition when the key is pressed.  We don't do this
  6241.   in zzstring(), because \Kverbs are valid only in this context and nowhere
  6242.   else.  This code copied from SET KEY, q.v. for addt'l commentary.
  6243. */
  6244.     for (x = 0, y = 0; s[x]; x++, y++) { /* Convert \K to \\K */
  6245.         if ((x > 0) &&
  6246.             (s[x] == 'K' || s[x] == 'k')
  6247.             ) {                         /* Have K */
  6248.  
  6249.             if ((x == 1 && s[x-1] == CMDQ) ||
  6250.                 (x > 1 && s[x-1] == CMDQ && s[x-2] != CMDQ)) {
  6251.                 line[y++] = CMDQ;       /* Make it \\K */
  6252.             }
  6253.             if (x > 1 && s[x-1] == '{' && s[x-2] == CMDQ) {
  6254.                 line[y-1] = CMDQ;       /* Have \{K */
  6255.                 line[y++] = '{';        /* Make it \\{K */
  6256.             }
  6257.         }
  6258.         line[y] = s[x];
  6259.     }
  6260.     line[y++] = NUL;                    /* Terminate */
  6261.     s = line + y + 1;                   /* Point to after it */
  6262.     x = LINBUFSIZ - (int) strlen(line) - 1; /* Calculate remaining space */
  6263.     if ((x < (LINBUFSIZ / 2)) ||
  6264.         (zzstring(line, &s, &x) < 0)) { /* Expand variables, etc. */
  6265.         printf("?Key definition too long\n");
  6266.         return(-9);
  6267.     }
  6268.     s = line + y + 1;                   /* Point to result. */
  6269.  
  6270. #ifndef NOKVERBS
  6271. /*
  6272.   Special case: see if the definition starts with a \Kverb.
  6273.   If it does, point to it with p, otherwise set p to NULL.
  6274. */
  6275.     p = s;
  6276.     if (*p++ == CMDQ) {
  6277.         if (*p == '{') p++;
  6278.         p = (*p == 'k' || *p == 'K') ? p + 1 : NULL;
  6279.     }
  6280. #else
  6281.     p = NULL;
  6282. #endif /* NOKVERBS */
  6283.  
  6284.     /* free the old definition if necessary */
  6285.     if (mousemap[button][event].type == macro) {
  6286.         free( mousemap[button][event].macro.string);
  6287.         mousemap[button][event].macro.string = NULL;
  6288.     }
  6289.     switch (strlen(s)) {                /* Action depends on length */
  6290.       case 0:                           /* Reset to default binding */
  6291.         mousemapinit( button, event );
  6292.         break;
  6293.       case 1:                           /* Single character */
  6294.             mousemap[button][event].type = key;
  6295.         mousemap[button][event].key.scancode = *s;
  6296.         break;
  6297.       default:                          /* Character string */
  6298. #ifndef NOKVERBS
  6299.         if (p) {
  6300.             y = xlookup(kverbs,p,nkverbs,&x); /* Look it up */
  6301.             debug(F101,"set mouse kverb lookup",0,y); /* need exact match */
  6302.             if (y > -1) {
  6303.             /* Assign the kverb to the event */
  6304.             mousemap[button][event].type = kverb;
  6305.             mousemap[button][event].kverb.id = F_KVERB | y;
  6306.             break;
  6307.             }
  6308.         }
  6309. #endif /* NOKVERBS */
  6310.  
  6311.        /* Otherwise, it's a macro, so assign the macro to the event */
  6312.        mousemap[button][event].type = macro;
  6313.        mousemap[button][event].macro.string = (MACRO) malloc(strlen(s)+1);
  6314.        if (mousemap[button][event].macro.string)
  6315.          strcpy((char *) mousemap[button][event].macro.string, s); /* safe */
  6316.         break;
  6317.     }
  6318.     initvik = 1;                        /* Update VIK Table */
  6319.     if ( (button == XYM_B3) && (mousebuttoncount() < 3) && !quiet )
  6320.     {
  6321.         printf("?Warning: this machine does not have a three button mouse.\n");
  6322.         return(0);
  6323.     }
  6324.     return(1);
  6325. }
  6326. #endif /* OS2MOUSE */
  6327. #endif /* NOLOCAL */
  6328.  
  6329. #ifndef NOXFER
  6330. int                                     /* SET SEND/RECEIVE */
  6331. setsr(xx, rmsflg) int xx; int rmsflg; {
  6332.     if (xx == XYRECV)
  6333.       ckstrncpy(line,"Parameter for inbound packets",LINBUFSIZ);
  6334.     else
  6335.       ckstrncpy(line,"Parameter for outbound packets",LINBUFSIZ);
  6336.  
  6337.     if (rmsflg) {
  6338.         if ((y = cmkey(rsrtab,nrsrtab,line,"",xxstring)) < 0) {
  6339.             if (y == -3) {
  6340.                 printf("?Remote receive parameter required\n");
  6341.                 return(-9);
  6342.             } else return(y);
  6343.         }
  6344.     } else {
  6345.         if ((y = cmkey(srtab,nsrtab,line,"",xxstring)) < 0) return(y);
  6346.     }
  6347.     switch (y) {
  6348.       case XYQCTL:                      /* CONTROL-PREFIX */
  6349.         if ((x = cmnum("ASCII value of control prefix","",10,&y,xxstring)) < 0)
  6350.           return(x);
  6351.         if ((x = cmcfm()) < 0) return(x);
  6352.         if ((y > 32 && y < 63) || (y > 95 && y < 127)) {
  6353.             if (xx == XYRECV)
  6354.               ctlq = (CHAR) y;          /* RECEIVE prefix, use with caution! */
  6355.             else
  6356.               myctlq = (CHAR) y;        /* SEND prefix, OK to change */
  6357.             return(success = 1);
  6358.         } else {
  6359.             printf("?Illegal value for prefix character\n");
  6360.             return(-9);
  6361.         }
  6362.  
  6363.       case XYEOL:
  6364.         if ((y = setcc("13",&z)) < 0)
  6365.             return(y);
  6366.         if (z > 31) {
  6367.             printf("Sorry, the legal values are 0-31\n");
  6368.             return(-9);
  6369.         }
  6370.         if (xx == XYRECV)
  6371.           eol = (CHAR) z;
  6372.         else
  6373.           seol = (CHAR) z;
  6374.         return(success = y);
  6375.  
  6376.       case XYLEN:
  6377.         y = cmnum("Maximum number of characters in a packet","90",10,&x,
  6378.                   xxstring);
  6379.         if (xx == XYRECV) {             /* Receive... */
  6380.             if ((y = setnum(&z,x,y,maxrps)) < 0)
  6381.               return(y);
  6382.             if (protocol != PROTO_K) {
  6383.                 printf("?Sorry, this command does not apply to %s protocol.\n",
  6384.                        ptab[protocol].p_name
  6385.                        );
  6386.                 printf("Use SET SEND PACKET-LENGTH for XYZMODEM\n");
  6387.                 return(-9);
  6388.             }
  6389.             if (z < 10) {
  6390.                 printf("Sorry, 10 is the minimum\n");
  6391.                 return(-9);
  6392.             }
  6393.             if (rmsflg) {
  6394.                 sstate = setgen('S', "401", ckitoa(z), "");
  6395.                 return((int) sstate);
  6396.             } else {
  6397.                 if (protocol == PROTO_K) {
  6398.                     if (z > MAXRP) z = MAXRP;
  6399.                     y = adjpkl(z,wslotr,bigrbsiz);
  6400.                     if (y != z) {
  6401.                         urpsiz = y;
  6402.                         if (!xcmdsrc)
  6403.                           if (msgflg) printf(
  6404. " Adjusting receive packet-length to %d for %d window slots\n",
  6405.                                              y, wslotr);
  6406.                     }
  6407.                     urpsiz = y;
  6408.                     ptab[protocol].rpktlen = urpsiz;
  6409.                     rpsiz =  (y > 94) ? 94 : y;
  6410.                 } else {
  6411. #ifdef CK_XYZ
  6412.                     if ((protocol == PROTO_X || protocol == PROTO_XC) &&
  6413.                          z != 128 && z != 1024) {
  6414.                         printf("Sorry, bad packet length for XMODEM.\n");
  6415.                         printf("Please use 128 or 1024.\n");
  6416.                         return(-9);
  6417.                     }
  6418. #endif /* CK_XYZ */
  6419.                     urpsiz = rpsiz = z;
  6420.                 }
  6421.             }
  6422.         } else {                        /* Send... */
  6423.             if ((y = setnum(&z,x,y,maxsps)) < 0)
  6424.               return(y);
  6425.             if (z < 10) {
  6426.                 printf("Sorry, 10 is the minimum\n");
  6427.                 return(-9);
  6428.             }
  6429.             if (protocol == PROTO_K) {
  6430.                 if (z > MAXSP) z = MAXSP;
  6431.                 spsiz = z;              /* Set it */
  6432.                 y = adjpkl(spsiz,wslotr,bigsbsiz);
  6433.                 if (y != spsiz && !xcmdsrc)
  6434.                   if (msgflg)
  6435.                     printf("Adjusting packet size to %d for %d window slots\n",
  6436.                            y,wslotr);
  6437.             } else
  6438.               y = z;
  6439. #ifdef CK_XYZ
  6440.             if ((protocol == PROTO_X || protocol == PROTO_XC) &&
  6441.                  z != 128 && z != 1024) {
  6442.                 printf("Sorry, bad packet length for XMODEM.\n");
  6443.                 printf("Please use 128 or 1024.\n");
  6444.                 return(-9);
  6445.             }
  6446. #endif /* CK_XYZ */
  6447.             spsiz = spmax = spsizr = y; /* Set it and flag that it was set */
  6448.             spsizf = 1;                 /* to allow overriding Send-Init. */
  6449.             ptab[protocol].spktflg = spsizf;
  6450.             ptab[protocol].spktlen = spsiz;
  6451.         }
  6452.         if (pflag && protocol == PROTO_K && !xcmdsrc) {
  6453.             if (z > 94 && !reliable && msgflg) {
  6454.                 /* printf("Extended-length packets requested.\n"); */
  6455.                 if (bctr < 2 && z > 200) printf("\
  6456. Remember to SET BLOCK 2 or 3 for long packets.\n");
  6457.             }
  6458.             if (speed <= 0L) speed = ttgspd();
  6459. #ifdef COMMENT
  6460. /*
  6461.   Kermit does this now itself.
  6462. */
  6463.             if (speed <= 0L && z > 200 && msgflg) {
  6464.                 printf("\
  6465. Make sure your timeout interval is long enough for %d-byte packets.\n",z);
  6466.             }
  6467. #endif /* COMMENT */
  6468.         }
  6469.         return(success = y);
  6470.  
  6471.       case XYMARK:
  6472. #ifdef DOOMSDAY
  6473. /*
  6474.   Printable start-of-packet works for UNIX and VMS only!
  6475. */
  6476.         x_ifnum = 1;
  6477.         y = cmnum("Code for packet-start character","1",10,&x,xxstring);
  6478.         x_ifnum = 0;
  6479.         if ((y = setnum(&z,x,y,126)) < 0) return(y);
  6480. #else
  6481.         if ((y = setcc("1",&z)) < 0)
  6482.             return(y);
  6483. #endif /* DOOMSDAY */
  6484.         if (xx == XYRECV)
  6485.           stchr = (CHAR) z;
  6486.         else {
  6487.             mystch = (CHAR) z;
  6488. #ifdef IKS_OPTION
  6489.             /* If IKS negotiation in use   */
  6490.             if (TELOPT_U(TELOPT_KERMIT) || TELOPT_ME(TELOPT_KERMIT))
  6491.               tn_siks(KERMIT_SOP);      /* Report change to other side */
  6492. #endif /* IKS_OPTION */
  6493.         }
  6494.         return(success = y);
  6495.  
  6496.       case XYNPAD:                      /* PADDING */
  6497.         y = cmnum("How many padding characters for inbound packets","0",10,&x,
  6498.                   xxstring);
  6499.         if ((y = setnum(&z,x,y,94)) < 0) return(y);
  6500.         if (xx == XYRECV)
  6501.           mypadn = (CHAR) z;
  6502.         else
  6503.           npad = (CHAR) z;
  6504.         return(success = y);
  6505.  
  6506.       case XYPADC:                      /* PAD-CHARACTER */
  6507.         if ((y = setcc("0",&z)) < 0) return(y);
  6508.         if (xx == XYRECV) mypadc = z; else padch = z;
  6509.         return(success = y);
  6510.  
  6511.       case XYTIMO:                      /* TIMEOUT */
  6512.         if (xx == XYRECV) {
  6513.             y = cmnum("Packet timeout interval",ckitoa(URTIME),10,&x,xxstring);
  6514.             if ((y = setnum(&z,x,y,94)) < 0) return(y);
  6515.  
  6516.             if (rmsflg) {               /* REMOTE SET RECEIVE TIMEOUT */
  6517.                 sstate = setgen('S', "402", ckitoa(z), "");
  6518.                 return((int) sstate);
  6519.             } else {                    /* SET RECEIVE TIMEOUT */
  6520.                 pkttim = z;             /*   Value to put in my negotiation */
  6521.             }                           /*   packet for other Kermit to use */
  6522.  
  6523.         } else {                        /* SET SEND TIMEOUT */
  6524. #ifdef CK_TIMERS
  6525.             extern int rttflg, mintime, maxtime;
  6526.             int tmin = 0, tmax = 0;
  6527. #endif /* CK_TIMERS */
  6528.             y = cmnum("Packet timeout interval",ckitoa(DMYTIM),10,&x,xxstring);
  6529.             if (y == -3) {              /* They cancelled a previous */
  6530.                 x = DMYTIM;             /* SET SEND command, so restore */
  6531.                 timef = 0;              /* and turn off the override flag */
  6532.                 y = cmcfm();
  6533.             }
  6534. #ifdef CK_TIMERS
  6535.             if (y < 0) return(y);
  6536.             if (x < 0) {
  6537.                 printf("?Out of range - %d\n",x);
  6538.                 return(-9);
  6539.             }
  6540.             if ((z = cmkey(timotab,2,"","dynamic",xxstring)) < 0) return(z);
  6541.             if (z) {
  6542.                 if ((y = cmnum("Minimum timeout to allow",
  6543.                                "1",10,&tmin,xxstring)) < 0)
  6544.                   return(y);
  6545.                 if (tmin < 1) {
  6546.                     printf("?Out of range - %d\n",tmin);
  6547.                     return(-9);
  6548.                 }
  6549.                 if ((y = cmnum("Maximum timeout to allow",
  6550.                                "0",10,&tmax,xxstring)) < 0)
  6551.                   return(y);
  6552.                 /* 0 means let Kermit choose, < 0 means no maximum */
  6553.             }
  6554.             if ((y = cmcfm()) < 0)
  6555.               return(y);
  6556.             rttflg = z;                 /* Round-trip timer flag */
  6557.             z = x;
  6558. #else
  6559.             if ((y = setnum(&z,x,y,94)) < 0)
  6560.               return(y);
  6561. #endif /* CK_TIMERS */
  6562.             timef = 1;                  /* Turn on the override flag */
  6563.             timint = rtimo = z;         /* Override value for me to use */
  6564. #ifdef CK_TIMERS
  6565.             if (rttflg) {               /* Lower and upper bounds */
  6566.                 mintime = tmin;
  6567.                 maxtime = tmax;
  6568.             }
  6569. #endif /* CK_TIMERS */
  6570.         }
  6571.         return(success = 1);
  6572.  
  6573.       case XYFPATH:                     /* PATHNAMES */
  6574.         if (xx == XYRECV) {
  6575.             y = cmkey(rpathtab,nrpathtab,"","auto",xxstring);
  6576.         } else {
  6577.             y = cmkey(pathtab,npathtab,"","off",xxstring);
  6578.         }
  6579.         if (y < 0) return(y);
  6580.  
  6581.         if ((x = cmcfm()) < 0) return(x);
  6582.         if (xx == XYRECV) {             /* SET RECEIVE PATHNAMES */
  6583.             fnrpath = y;
  6584.             ptab[protocol].fnrp = fnrpath;
  6585.         } else {                        /* SET SEND PATHNAMES */
  6586.             fnspath = y;
  6587.             ptab[protocol].fnsp = fnspath;
  6588.         }
  6589.         return(success = 1);            /* Note: 0 = ON, 1 = OFF */
  6590.         /* In other words, ON = leave pathnames ON, OFF = take them off. */
  6591.  
  6592.       case XYPAUS:                      /* SET SEND/RECEIVE PAUSE */
  6593.         y = cmnum("Milliseconds to pause between packets","0",10,&x,xxstring);
  6594.         if ((y = setnum(&z,x,y,15000)) < 0)
  6595.           return(y);
  6596.         pktpaus = z;
  6597.         return(success = 1);
  6598.  
  6599. #ifdef CKXXCHAR                         /* SET SEND/RECEIVE IGNORE/DOUBLE */
  6600.       case XYIGN:
  6601.       case XYDBL: {
  6602.           int i, zz;
  6603.           short *p;
  6604.           extern short dblt[];
  6605.           extern int dblflag, ignflag;
  6606.  
  6607.           /* Make space for a temporary copy of the ignore/double table */
  6608.  
  6609.           zz = y;
  6610. #ifdef COMMENT
  6611.           if (zz == XYIGN && xx == XYSEND) {
  6612.               blah blah who cares
  6613.           }
  6614.           if (zz == XYDBL && xx == XYRECV) {
  6615.               blah blah
  6616.           }
  6617. #endif /* COMMENT */
  6618.           p = (short *)malloc(256 * sizeof(short));
  6619.           if (!p) {
  6620.               printf("?Internal error - malloc failure\n");
  6621.               return(-9);
  6622.           }
  6623.           for (i = 0; i < 256; i++) p[i] = dblt[i]; /* Copy current table */
  6624.  
  6625.           while (1) {                   /* Collect a list of numbers */
  6626. #ifndef NOSPL
  6627.               x_ifnum = 1;              /* Turn off complaints from eval() */
  6628. #endif /* NOSPL */
  6629.               if ((x = cmnum(zz == XYDBL ?
  6630.                              "Character to double" :
  6631.                              "Character to ignore",
  6632.                              "",10,&y,xxstring
  6633.                              )) < 0) {
  6634. #ifndef NOSPL
  6635.                   x_ifnum = 0;
  6636. #endif /* NOSPL */
  6637.                   if (x == -3)          /* Done */
  6638.                     break;
  6639.                   if (x == -2) {
  6640.                       if (p) { free(p); p = NULL; }
  6641.                       debug(F110,"SET S/R DOUBLE/IGNORE atmbuf",atmbuf,0);
  6642.                       if (!ckstrcmp(atmbuf,"none",4,0) ||
  6643.                           !ckstrcmp(atmbuf,"non",3,0) ||
  6644.                           !ckstrcmp(atmbuf,"no",2,0) ||
  6645.                           !ckstrcmp(atmbuf,"n",1,0)) {
  6646.                           if ((x = cmcfm()) < 0) /* Get confirmation */
  6647.                             return(x);
  6648.                           for (y = 0; y < 256; y++)
  6649.                             dblt[y] &= (zz == XYDBL) ? 1 : 2;
  6650.                           if (zz == XYDBL) dblflag = 0;
  6651.                           if (zz == XYIGN) ignflag = 0;
  6652.                           return(success = 1);
  6653.                       } else {
  6654.                           printf(
  6655.                             "?Please specify a number or the word NONE\n");
  6656.                           return(-9);
  6657.                       }
  6658.                   } else {
  6659.                       free(p);
  6660.                       p = NULL;
  6661.                       return(x);
  6662.                   }
  6663.               }
  6664. #ifndef NOSPL
  6665.               x_ifnum = 0;
  6666. #endif /* NOSPL */
  6667.               if (y < 0 || y > 255) {
  6668.                   printf("?Please enter a character code in range 0-255\n");
  6669.                   free(p);
  6670.                   p = NULL;
  6671.                   return(-9);
  6672.               }
  6673.               p[y] |= (zz == XYDBL) ? 2 : 1;
  6674.               if (zz == XYDBL) dblflag = 1;
  6675.               if (zz == XYIGN) ignflag = 1;
  6676.           } /* End of while loop */
  6677.  
  6678.           if ((x = cmcfm()) < 0) return(x);
  6679. /*
  6680.   Get here only if they have made no mistakes.  Copy temporary table back to
  6681.   permanent one, then free temporary table and return successfully.
  6682. */
  6683.           if (p) {
  6684.               for (i = 0; i < 256; i++) dblt[i] = p[i];
  6685.               free(p);
  6686.               p = NULL;
  6687.           }
  6688.           return(success = 1);
  6689.       }
  6690. #endif /* CKXXCHAR */
  6691.  
  6692. #ifdef PIPESEND
  6693.       case XYFLTR: {                    /* SET { SEND, RECEIVE } FILTER */
  6694.           if ((y = cmtxt((xx == XYSEND) ?
  6695.                 "Filter program for sending files -\n\
  6696.  use \\v(filename) to substitute filename" :
  6697.                 "Filter program for receiving files -\n\
  6698.  use \\v(filename) to substitute filename",
  6699.                          "",&s,NULL)) < 0)
  6700.             return(y);
  6701.           if (!*s) {                    /* Removing a filter... */
  6702.               if (xx == XYSEND && sndfilter) {
  6703.                   makestr(&g_sfilter,NULL);
  6704.                   makestr(&sndfilter,NULL);
  6705.               } else if (rcvfilter) {
  6706.                   makestr(&g_rfilter,NULL);
  6707.                   makestr(&rcvfilter,NULL);
  6708.               }
  6709.               return(success = 1);
  6710.           }                             /* Adding a filter... */
  6711.           s = brstrip(s);               /* Strip any braces */
  6712.           y = strlen(s);
  6713.           if (xx == XYSEND) {           /* For SEND filter... */
  6714.               for (x = 0; x < y; x++) { /* make sure they included "\v(...)" */
  6715.                   if (s[x] != '\\') continue;
  6716.                   if (s[x+1] == 'v') break;
  6717.               }
  6718.               if (x == y) {
  6719.                   printf(
  6720.               "?Filter must contain a replacement variable for filename.\n"
  6721.                          );
  6722.                   return(-9);
  6723.               }
  6724.           }
  6725.           if (xx == XYSEND) {
  6726.               makestr(&sndfilter,s);
  6727.               makestr(&g_sfilter,s);
  6728.           } else {
  6729.               makestr(&rcvfilter,s);
  6730.               makestr(&g_rfilter,s);
  6731.           }
  6732.           return(success = 1);
  6733.       }
  6734. #endif /* PIPESEND */
  6735.  
  6736.       case XYINIL:
  6737.         y = cmnum("Max length for protocol init string","-1",10,&x,xxstring);
  6738.         if ((y = setnum(&z,x,y,-1)) < 0)
  6739.           return(y);
  6740.         if (xx == XYSEND)
  6741.           sprmlen = z;
  6742.         else
  6743.           rprmlen = z;
  6744.         return(success = 1);
  6745.  
  6746.       case 993: {
  6747.           extern int sendipkts;
  6748.           if (xx == XYSEND) {
  6749.               if ((x = seton(&sendipkts)) < 0)
  6750.                 return(x);
  6751.           }
  6752.           return(1);
  6753.       }
  6754. #ifdef CK_PERMS
  6755.       case 994:
  6756.     switch(xx) {
  6757.       case XYSEND:
  6758.         if ((x = seton(&atlpro)) < 0) return(x);
  6759.         atgpro = atlpro;
  6760.         return(1);
  6761.       case XYRECV:
  6762.         if ((x = seton(&atlpri)) < 0) return(x);
  6763.         atgpri = atlpri;
  6764.         return(1);
  6765.       default:
  6766.         return(-2);
  6767.     }
  6768. #endif /* CK_PERMS */
  6769.  
  6770. #ifndef NOCSETS
  6771.       case XYCSET: {                    /* CHARACTER-SET-SELECTION */
  6772.           extern struct keytab xfrmtab[];
  6773.           extern int r_cset, s_cset;
  6774.           if ((y = cmkey(xfrmtab,2,"","automatic",xxstring)) < 0)
  6775.             return(y);
  6776.           if ((x = cmcfm()) < 0)
  6777.             return(x);
  6778.           if (xx == XYSEND)
  6779.             s_cset = y;
  6780.           else
  6781.             r_cset = y;
  6782.           return(success = 1);
  6783.       }
  6784. #endif /* NOCSETS */
  6785.  
  6786.       case XYBUP:
  6787.         if ((y = cmkey(onoff,2,"","on",xxstring)) < 0)
  6788.           return(y);
  6789.         if ((x = cmcfm()) < 0) return(x);
  6790.         if (xx == XYSEND) {
  6791.             extern int skipbup;
  6792.             skipbup = (y == 0) ? 1 : 0;
  6793.             return(success = 1);
  6794.         } else {
  6795.             printf(
  6796. "?Please use SET FILE COLLISION to choose the desired action\n");
  6797.             return(-9);
  6798.         }
  6799.  
  6800.       case XYMOVE:
  6801.         y = cmdir("Directory to move file(s) to after successful transfer",
  6802.                   "",&s,xxstring);
  6803.         if (y < 0 && y != -3)
  6804.           return(y);
  6805.         ckstrncpy(line,s,LINBUFSIZ);
  6806.         s = brstrip(line);
  6807.         if ((x = cmcfm()) < 0)
  6808.           return(x);
  6809.         if (xx == XYSEND) {
  6810.             if (*s) {
  6811.                 makestr(&snd_move,s);
  6812.                 makestr(&g_snd_move,s);
  6813.             } else {
  6814.                 makestr(&snd_move,NULL);
  6815.                 makestr(&g_snd_move,NULL);
  6816.             }
  6817.         } else {
  6818.             if (*s) {
  6819.                 makestr(&rcv_move,s);
  6820.                 makestr(&g_rcv_move,s);
  6821.             } else {
  6822.                 makestr(&rcv_move,NULL);
  6823.                 makestr(&g_rcv_move,NULL);
  6824.             }
  6825.         }
  6826.         return(success = 1);
  6827.  
  6828.       case XYRENAME:
  6829.         y = cmdir("Template to rename file(s) to after successful transfer",
  6830.                   "",&s,NULL);
  6831.         if (y < 0 && y != -3)
  6832.           return(y);
  6833.         ckstrncpy(line,s,LINBUFSIZ);
  6834.         s = brstrip(line);
  6835.         if ((x = cmcfm()) < 0)
  6836.           return(x);
  6837.         if (xx == XYSEND) {
  6838.             if (*s) {
  6839.                 makestr(&snd_rename,s);
  6840.                 makestr(&g_snd_rename,s);
  6841.             } else {
  6842.                 makestr(&snd_rename,NULL);
  6843.                 makestr(&g_snd_rename,NULL);
  6844.             }
  6845.         } else {
  6846.             if (*s) {
  6847.                 makestr(&rcv_rename,s);
  6848.                 makestr(&g_rcv_rename,s);
  6849.             } else {
  6850.                 makestr(&rcv_rename,NULL);
  6851.                 makestr(&g_rcv_rename,NULL);
  6852.             }
  6853.         }
  6854.         return(success = 1);
  6855.  
  6856. #ifdef VMS
  6857.       case 887:                 /* VERSION-NUMBERS */
  6858.         if (xx == XYSEND) {
  6859.             extern int vmssversions;
  6860.             return(seton(&vmssversions));
  6861.         } else {
  6862.             extern int vmsrversions;
  6863.             return(seton(&vmsrversions));
  6864.         }
  6865. #endif /* VMS */
  6866.  
  6867.       default:
  6868.         return(-2);
  6869.     }                                   /* End of SET SEND/RECEIVE... */
  6870. }
  6871. #endif /* NOXFER */
  6872.  
  6873. #ifndef NOXMIT
  6874. int
  6875. setxmit() {
  6876.     if ((y = cmkey(xmitab,nxmit,"","",xxstring)) < 0) return(y);
  6877.     switch (y) {
  6878.       case XMITE:                       /* EOF */
  6879.         y = cmtxt("Characters to send at end of file,\n\
  6880.  Use backslash codes for control characters","",&s,xxstring);
  6881.         if (y < 0) return(y);
  6882.         if ((int)strlen(s) > XMBUFL) {
  6883.             printf("?Too many characters, %d maximum\n",XMBUFL);
  6884.             return(-2);
  6885.         }
  6886.         ckstrncpy(xmitbuf,s,XMBUFL);
  6887.         return(success = 1);
  6888.  
  6889.       case XMITF:                       /* Fill */
  6890.         y = cmnum("Numeric code for blank-line fill character","0",10,&x,
  6891.                   xxstring);
  6892.         if ((y = setnum(&z,x,y,127)) < 0) return(y);
  6893.         xmitf = z;
  6894.         return(success = 1);
  6895.       case XMITL:                       /* Linefeed */
  6896.         return(seton(&xmitl));
  6897.       case XMITS:                       /* Locking-Shift */
  6898.         return(seton(&xmits));
  6899.       case XMITP:                       /* Prompt */
  6900.         y = cmnum("Numeric code for host's prompt character, 0 for none",
  6901.                   "10",10,&x,xxstring);
  6902.         if ((y = setnum(&z,x,y,127)) < 0) return(y);
  6903.         xmitp = z;
  6904.         return(success = 1);
  6905.       case XMITX:                       /* Echo */
  6906.         return(seton(&xmitx));
  6907.       case XMITW:                       /* Pause */
  6908.         y = cmnum("Number of milliseconds to pause between binary characters\n\
  6909. or text lines during transmission","0",10,&x,xxstring);
  6910.         if ((y = setnum(&z,x,y,1000)) < 0) return(y);
  6911.         xmitw = z;
  6912.         return(success = 1);
  6913.       case XMITT:                       /* Timeout */
  6914.         y = cmnum("Seconds to wait for each character to echo",
  6915.                   "1",10,&x,xxstring);
  6916.         if ((y = setnum(&z,x,y,1000)) < 0) return(y);
  6917.         xmitt = z;
  6918.         return(success = 1);
  6919.       default:
  6920.         return(-2);
  6921.     }
  6922. }
  6923. #endif /* NOXMIT */
  6924.  
  6925. #ifndef NOXFER
  6926. /*  D O R M T  --  Do a remote command  */
  6927.  
  6928. VOID
  6929. rmsg() {
  6930.     if (pflag && !quiet && fdispla != XYFD_N)
  6931.       printf(
  6932. #ifdef CK_NEED_SIG
  6933.        " Type your escape character, %s, followed by X or E to cancel.\n",
  6934.        dbchr(escape)
  6935. #else
  6936.        " Press the X or E key to cancel.\n"
  6937. #endif /* CK_NEED_SIG */
  6938.       );
  6939. }
  6940.  
  6941. static int xzcmd = 0;                   /* Global copy of REMOTE cmd index */
  6942.  
  6943. /*  R E M C F M  --  Confirm a REMOTE command  */
  6944. /*
  6945.   Like cmcfm(), but allows for a redirection indicator on the end,
  6946.   like "> filename" or "| command".  Returns what cmcfm() would have
  6947.   returned: -1 if reparse needed, etc etc blah blah.  On success,
  6948.   returns 1 with:
  6949.  
  6950.     char * remdest containing the name of the file or command.
  6951.     int remfile set to 1 if there is to be any redirection.
  6952.     int remappd set to 1 if output file is to be appended to.
  6953.     int rempipe set to 1 if remdest is a command, 0 if it is a file.
  6954. */
  6955. static int
  6956. remcfm() {
  6957.     int x;
  6958.     char *s;
  6959.     char c;
  6960.  
  6961.     remfile = 0;
  6962.     rempipe = 0;
  6963.     remappd = 0;
  6964.  
  6965.     if ((x = cmtxt(
  6966.              "> filename, | command,\n\
  6967. or type carriage return to confirm the command",
  6968.                    "",&s,xxstring)) < 0)
  6969.       return(x);
  6970.     if (remdest) {
  6971.         free(remdest);
  6972.         remdest = NULL;
  6973.     }
  6974.     debug(F101,"remcfm local","",local);
  6975.     debug(F110,"remcfm s",s,0);
  6976.     debug(F101,"remcfm cmd","",xzcmd);
  6977.  
  6978.     if (!*s) {                          /* No redirection indicator */
  6979.         if (!local &&
  6980.             (xzcmd == XZDIR || xzcmd == XZTYP ||
  6981.              xzcmd == XZXIT || xzcmd == XZSPA ||
  6982.              xzcmd == XZHLP || xzcmd == XZPWD ||
  6983.              xzcmd == XZLGI || xzcmd == XZLGO ||
  6984.              xzcmd == XZWHO || xzcmd == XZHOS)) {
  6985.             printf("?\"%s\" has no effect in remote mode\n",cmdbuf);
  6986.             return(-9);
  6987.         } else
  6988.           return(1);
  6989.     }
  6990.     c = *s;                             /* We have something */
  6991.     if (c != '>' && c != '|') {         /* Is it > or | ? */
  6992.         printf("?Not confirmed\n");     /* No */
  6993.         return(-9);
  6994.     }
  6995.     s++;                                /* See what follows */
  6996.     if (c == '>' && *s == '>') {        /* Allow for ">>" too */
  6997.         s++;
  6998.         remappd = 1;                    /* Append to output file */
  6999.     }
  7000.     while (*s == SP || *s == HT) s++;   /* Strip intervening whitespace */
  7001.     if (!*s) {
  7002.         printf("?%s missing\n", c == '>' ? "Filename" : "Command");
  7003.         return(-9);
  7004.     }
  7005.     if (c == '>' && zchko(s) < 0) {     /* Check accessibility */
  7006.         printf("?Access denied - %s\n", s);
  7007.         return(-9);
  7008.     }
  7009.     remfile = 1;                        /* Set global results */
  7010.     rempipe = (c == '|');
  7011.     if (rempipe
  7012. #ifndef NOPUSH
  7013.         && nopush
  7014. #endif /* NOPUSH */
  7015.         ) {
  7016.         printf("?Sorry, access to external commands is disabled.\n");
  7017.         return(-9);
  7018.     }
  7019.     makestr(&remdest,s);
  7020. #ifndef NODEBUG
  7021.     if (deblog) {
  7022.         debug(F101,"remcfm remfile","",remfile);
  7023.         debug(F101,"remcfm remappd","",remappd);
  7024.         debug(F101,"remcfm rempipe","",rempipe);
  7025.         debug(F110,"remcfm remdest",remdest, 0);
  7026.     }
  7027. #endif /* NODEBUG */
  7028.     return(1);
  7029. }
  7030.  
  7031. /*  R E M T X T  --  Like remcfm()...  */
  7032. /*
  7033.    ... but for REMOTE commands that end with cmtxt().
  7034.    Here we must decipher braces to discover whether the trailing
  7035.    redirection indicator is intended for local use, or to be sent out
  7036.    to the server, as in:
  7037.  
  7038.      remote host blah blah > file                 This end
  7039.      remote host { blah blah } > file             This end
  7040.      remote host { blah blah > file }             That end
  7041.      remote host { blah blah > file } > file      Both ends
  7042.  
  7043.    Pipes too:
  7044.  
  7045.      remote host blah blah | cmd                  This end
  7046.      remote host { blah blah } | cmd              This end
  7047.      remote host { blah blah | cmd }              That end
  7048.      remote host { blah blah | cmd } | cmd        Both ends
  7049.  
  7050.    Or both:
  7051.  
  7052.      remote host blah blah | cmd > file           This end, etc etc...
  7053.  
  7054.    Note: this really only makes sense for REMOTE HOST, but why be picky?
  7055.    Call after calling cmtxt(), with pointer to string that cmtxt() parsed,
  7056.    as in "remtxt(&s);".
  7057.  
  7058.    Returns:
  7059.     1 on success with braces & redirection things removed & pointer updated,
  7060.    -9 on failure (bad indirection), after printing error message.
  7061. */
  7062. int
  7063. remtxt(p) char ** p; {
  7064.     int i, x, bpos, ppos;
  7065.     char c, *s, *q;
  7066.  
  7067.     remfile = 0;                        /* Initialize global results */
  7068.     rempipe = 0;
  7069.     remappd = 0;
  7070.     if (remdest) {
  7071.         free(remdest);
  7072.         remdest = NULL;
  7073.     }
  7074.     s = *p;
  7075.     if (!s)                             /* No redirection indicator */
  7076.       s = "";
  7077.     if (!*s) {                          /* Ditto */
  7078.         if (!local &&
  7079.             (xzcmd == XZDIR || xzcmd == XZTYP ||
  7080.              xzcmd == XZXIT || xzcmd == XZSPA ||
  7081.              xzcmd == XZHLP || xzcmd == XZPWD ||
  7082.              xzcmd == XZLGI || xzcmd == XZLGO ||
  7083.              xzcmd == XZWHO || xzcmd == XZHOS)) {
  7084.             printf("?\"%s\" has no effect in remote mode\n",cmdbuf);
  7085.             if (hints) {
  7086.                 printf("Hint: Try again with an output redirector.\n");
  7087.             }
  7088.             return(-9);
  7089.         } else
  7090.           return(1);
  7091.     }
  7092.     bpos = -1;                          /* Position of > (bracket) */
  7093.     ppos = -1;                          /* Position of | (pipe) */
  7094.     x = strlen(s);                      /* Length of cmtxt() string */
  7095.  
  7096.     for (i = x-1; i >= 0; i--) {        /* Search right to left. */
  7097.         c = s[i];
  7098.         if (c == '}')                   /* Break on first right brace */
  7099.           break;                        /* Don't look at contents of braces */
  7100.         else if (c == '>')              /* Record position of > */
  7101.           bpos = i;
  7102.         else if (c == '|')              /* and of | */
  7103.           ppos = i;
  7104.     }
  7105.     if (bpos < 0 && ppos < 0) {         /* No redirectors. */
  7106.         if (!local &&
  7107.             (xzcmd == XZDIR || xzcmd == XZTYP ||
  7108.              xzcmd == XZXIT || xzcmd == XZSPA ||
  7109.              xzcmd == XZHLP || xzcmd == XZPWD ||
  7110.              xzcmd == XZLGI || xzcmd == XZLGO ||
  7111.              xzcmd == XZWHO || xzcmd == XZHOS)) {
  7112.             printf("?\"%s\" has no effect in remote mode\n",cmdbuf);
  7113.             if (hints) {
  7114.                 printf("Hint: Try again with an output redirector.\n");
  7115.             }
  7116.             return(-9);
  7117.         }
  7118.         s = brstrip(s);                 /* Remove outer braces if any. */
  7119.         *p = s;                         /* Point to result */
  7120.         return(1);                      /* and return. */
  7121.     }
  7122.     remfile = 1;                        /* It's | or > */
  7123.     i = -1;                             /* Get leftmost symbol */
  7124.     if (bpos > -1)                      /* Bracket */
  7125.       i = bpos;
  7126.     if (ppos > -1 && (ppos < bpos || bpos < 0)) { /* or pipe */
  7127.         i = ppos;
  7128.         rempipe = 1;
  7129.     }
  7130.     if (rempipe
  7131. #ifndef NOPUSH
  7132.         && nopush
  7133. #endif /* NOPUSH */
  7134.         ) {
  7135.         printf("?Sorry, access to external commands is disabled.\n");
  7136.         return(-9);
  7137.     }
  7138.     c = s[i];                           /* Copy of symbol */
  7139.  
  7140.     if (c == '>' && s[i+1] == '>')      /* ">>" for append? */
  7141.       remappd = 1;                     /* It's not just a flag it's a number */
  7142.  
  7143.     q = s + i + 1 + remappd;            /* Point past symbol in string */
  7144.     while (*q == SP || *q == HT) q++;   /* and any intervening whitespace */
  7145.     if (!*q) {
  7146.         printf("?%s missing\n", c == '>' ? "Filename" : "Command");
  7147.         return(-9);
  7148.     }
  7149.     if (c == '>' && zchko(q) < 0) {     /* (Doesn't work for | cmd > file) */
  7150.         printf("?Access denied - %s\n", q);
  7151.         return(-9);
  7152.     }
  7153.     makestr(&remdest,q);                /* Create the destination string */
  7154.     q = s + i - 1;                      /* Point before symbol */
  7155.     while (q > s && (*q == SP || *q == HT)) /* Strip trailing whitespace */
  7156.       q--;
  7157.     *(q+1) = NUL;                       /* Terminate the string. */
  7158.     s = brstrip(s);                     /* Remove any braces */
  7159.     *p = s;                             /* Set return value */
  7160.  
  7161. #ifndef NODEBUG
  7162.     if (deblog) {
  7163.         debug(F101,"remtxt remfile","",remfile);
  7164.         debug(F101,"remtxt remappd","",remappd);
  7165.         debug(F101,"remtxt rempipe","",rempipe);
  7166.         debug(F110,"remtxt remdest",remdest, 0);
  7167.         debug(F110,"remtxt command",s,0);
  7168.     }
  7169. #endif /* NODEBUG */
  7170.  
  7171.     return(1);
  7172. }
  7173.  
  7174. int
  7175. plogin(xx) int xx; {
  7176.     char *p1 = NULL, *p2 = NULL, *p3 = NULL;
  7177.     int psaved = 0, rc = 0;
  7178. #ifdef CK_RECALL
  7179.     extern int on_recall;               /* around Password prompting */
  7180. #endif /* CK_RECALL */
  7181.     debug(F101,"plogin local","",local);
  7182.  
  7183.     if (!local || (network && ttchk() < 0)) {
  7184.         printf("?No connection\n");
  7185.         return(-9);
  7186.     }
  7187.     if ((x = cmfld("User ID","",&s,xxstring)) < 0) { /* Get User ID */
  7188.         if (x != -3) return(x);
  7189.     }
  7190.     y = strlen(s);
  7191.     if (y > 0) {
  7192.         if ((p1 = malloc(y + 1)) == NULL) {
  7193.             printf("?Internal error: malloc\n");
  7194.             rc = -9;
  7195.             goto XZXLGI;
  7196.         } else
  7197.           strcpy(p1,s);                 /* safe */
  7198.         if ((rc = cmfld("Password","",&s,xxstring)) < 0)
  7199.           if (rc != -3) goto XZXLGI;
  7200.         y = strlen(s);
  7201.         if (y > 0) {
  7202.             if ((p2 = malloc(y + 1)) == NULL) {
  7203.                 printf("?Internal error: malloc\n");
  7204.                 rc = -9;
  7205.                 goto XZXLGI;
  7206.             } else
  7207.               strcpy(p2,s);             /* safe */
  7208.             if ((rc = cmfld("Account","",&s,xxstring)) < 0)
  7209.               if (rc != -3) goto XZXLGI;
  7210.             y = strlen(s);
  7211.             if (y > 0) {
  7212.                 if ((p3 = malloc(y + 1)) == NULL) {
  7213.                     printf("?Internal error: malloc\n");
  7214.                     rc = -9;
  7215.                     goto XZXLGI;
  7216.                 } else
  7217.                   strcpy(p3,s);         /* safe */
  7218.             }
  7219.         }
  7220.     }
  7221.     if ((rc = remtxt(&s)) < 0)          /* Confirm & handle redirectors */
  7222.       goto XZXLGI;
  7223.  
  7224.     if (!p1) {                          /* No Userid specified... */
  7225.         debok = 0;                      /* Don't log this */
  7226.         /* Prompt for username, password, and account */
  7227. #ifdef CK_RECALL
  7228.         on_recall = 0;
  7229. #endif /* CK_RECALL */
  7230.         cmsavp(psave,PROMPTL);          /* Save old prompt */
  7231.         psaved = 1;
  7232.         debug(F110,"REMOTE LOGIN saved",psave,0);
  7233.  
  7234.         cmsetp("Username: ");           /* Make new prompt */
  7235.         concb((char)escape);            /* Put console in cbreak mode */
  7236.         cmini(1);
  7237.         prompt(xxstring);
  7238.         rc = -9;
  7239.         for (x = -1; x < 0; ) {         /* Prompt till they answer */
  7240.             cmres();                    /* Reset the parser */
  7241.             x = cmtxt("","",&s,NULL);   /* Get a literal line of text */
  7242.         }
  7243.         y = strlen(s);
  7244.         if (y < 1) {
  7245.             printf("?Canceled\n");
  7246.             goto XZXLGI;
  7247.         }
  7248.         if ((p1 = malloc(y + 1)) == NULL) {
  7249.             printf("?Internal error: malloc\n");
  7250.             goto XZXLGI;
  7251.         } else
  7252.           strcpy(p1,s);                 /* safe */
  7253.  
  7254.         cmsetp("Password: ");           /* Make new prompt */
  7255.         concb((char)escape);            /* Put console in cbreak mode */
  7256.         cmini(0);                       /* No echo */
  7257.         prompt(xxstring);
  7258.         debok = 0;
  7259.         for (x = -1; x < 0 && x != -3; ) { /* Get answer */
  7260.             cmres();                    /* Reset the parser */
  7261.             x = cmtxt("","",&s,NULL);   /* Get literal line of text */
  7262.         }
  7263.         if ((p2 = malloc((int)strlen(s) + 1)) == NULL) {
  7264.             printf("?Internal error: malloc\n");
  7265.             goto XZXLGI;
  7266.         } else
  7267.           strcpy(p2,s);                 /* safe */
  7268.         printf("\r\n");
  7269.         if ((rc = cmcfm()) < 0)
  7270.           goto XZXLGI;
  7271.     }
  7272.     sstate = setgen('I',p1,p2,p3);      /* Get here with at least user ID */
  7273.     rc = 0;
  7274.  
  7275.   XZXLGI:                               /* Common exit point */
  7276.     if (psaved)
  7277.       cmsetp(psave);                    /* Restore original prompt */
  7278.     if (p3) { free(p3); p3 = NULL; }    /* Free malloc'd storage */
  7279.     if (p2) { free(p2); p2 = NULL; }
  7280.     if (p1) { free(p1); p1 = NULL; }
  7281.     if (rc > -1) {
  7282.         if (local && rc > -1)           /* If local, flush tty input buffer */
  7283.           ttflui();
  7284.     }
  7285.     return(rc);
  7286. }
  7287.  
  7288. #ifdef OS2
  7289. #ifndef NOLOCAL
  7290. int
  7291. dormt(xx) int xx; {
  7292.     int rc = 0;
  7293.     extern int term_io;
  7294.     int term_io_sav = term_io;
  7295. #ifdef NEWFTP
  7296.     extern int ftpget, ftpisopen();
  7297.     if ((ftpget == 1) || ((ftpget == 2) && ftpisopen()))
  7298.       return(doftprmt(xx,0));
  7299. #endif /* NEWFTP */
  7300.     term_io = 0;
  7301.     rc = xxdormt(xx);
  7302.     term_io = term_io_sav;
  7303.     return rc;
  7304. }
  7305.  
  7306.  
  7307. int
  7308. xxdormt(xx) int xx;
  7309. #else /* NOLOCAL */
  7310. int
  7311. dormt(xx) int xx;
  7312. #endif /* NOLOCAL */
  7313. #else /* OS2 */
  7314. int
  7315. dormt(xx) int xx;
  7316. #endif /* OS2 */
  7317. {                                       /* REMOTE commands */
  7318.     int x, y, retcode;
  7319.     char *s, sbuf[50], *s2;
  7320.  
  7321. #ifdef NEWFTP
  7322.     extern int ftpget, ftpisopen();
  7323.     if ((ftpget == 1) || ((ftpget == 2) && ftpisopen()))
  7324.       return(doftprmt(xx,0));
  7325. #endif /* NEWFTP */
  7326.  
  7327.     remfile = 0;                        /* Clear these */
  7328.     rempipe = 0;
  7329.     remappd = 0;
  7330.  
  7331.     if (xx < 0) return(xx);             /* REMOTE what? */
  7332.  
  7333.     xzcmd = xx;                         /* Make global copy of arg */
  7334.  
  7335.     if (xx == XZSET) {                  /* REMOTE SET */
  7336.         if ((y = cmkey(rmstab,nrms,"","",xxstring)) < 0) {
  7337.             if (y == -3) {
  7338.                 printf("?Parameter name required\n");
  7339.                 return(-9);
  7340.             } else return(y);
  7341.         }
  7342.         return(doprm(y,1));
  7343.     }
  7344.  
  7345.     switch (xx) {                       /* Others... */
  7346.  
  7347.       case XZCDU:
  7348.         if ((x = cmcfm()) < 0) return(x);
  7349.         printf("?Sorry, REMOTE CDUP not supported yet\n");
  7350.         return(-9);
  7351.  
  7352.       case XZCWD:                       /* CWD (CD) */
  7353.         if ((x = cmtxt("Remote directory name","",&s,xxstring)) < 0)
  7354.           return(x);
  7355.         if ((x = remtxt(&s)) < 0)
  7356.           return(x);
  7357.         debug(F111,"XZCWD: ",s,x);
  7358.         *sbuf = NUL;
  7359.         s2 = sbuf;
  7360. /*
  7361.   The following is commented out because since the disappearance of the
  7362.   DECSYSTEM-20 from the planet, no known computer requires a password for
  7363.   changing directory.
  7364. */
  7365. #ifdef DIRPWDPR
  7366.         if (*s != NUL) {                /* If directory name given, */
  7367.                                         /* get password on separate line. */
  7368.             if (tlevel > -1) {          /* From take file... */
  7369.  
  7370.                 if (fgets(sbuf,50,tfile[tlevel]) == NULL)
  7371.                   fatal("take file ends prematurely in 'remote cwd'");
  7372.                 debug(F110," pswd from take file",s2,0);
  7373.                 for (x = (int)strlen(sbuf);
  7374.                      x > 0 && (sbuf[x-1] == NL || sbuf[x-1] == CR);
  7375.                      x--)
  7376.                   sbuf[x-1] = '\0';
  7377.  
  7378.             } else {                    /* From terminal... */
  7379.  
  7380.                 printf(" Password: ");  /* get a password */
  7381. #ifdef IKSD
  7382.                 if (!local && inserver) {
  7383.                     x = coninc(0);
  7384.                 } else
  7385. #endif /* IKSD */
  7386. #ifdef OS2
  7387.                   x = is_a_tty(0) ? coninc(0) : /* with no echo ... */
  7388.                     getchar();
  7389. #else /* OS2 */
  7390.                 x = getchar();
  7391. #endif /* OS2 */
  7392.                 while ((x != NL) && (x != CR)) {
  7393.                     if ((x &= 0177) == '?') {
  7394.                         printf("? Password of remote directory\n Password: ");
  7395.                         s2 = sbuf;
  7396.                         *sbuf = NUL;
  7397.                     } else if (x == ESC) /* Mini command line editor... */
  7398.                       bleep(BP_WARN);
  7399.                     else if (x == BS || x == 0177)
  7400.                       s2--;
  7401.                     else if (x == 025) {        /* Ctrl-U */
  7402.                         s2 = sbuf;
  7403.                         *sbuf = NUL;
  7404.                     } else
  7405.                       *s2++ = x;
  7406.  
  7407.                     /* Get the next character */
  7408. #ifdef IKSD
  7409.                     if (!local && inserver) {
  7410.                         x = coninc(0);
  7411.                     } else
  7412. #endif /* IKSD */
  7413. #ifdef OS2
  7414.                     x = is_a_tty(0) ? coninc(0) : /* with no echo ... */
  7415.                       getchar();
  7416. #else /* OS2 */
  7417.                     x = getchar();
  7418. #endif /* OS2 */
  7419.                 }
  7420.                 *s2 = NUL;
  7421.                 putchar('\n');
  7422.             }
  7423.             s2 = sbuf;
  7424.         } else s2 = "";
  7425. #endif /* DIRPWDPR */
  7426.  
  7427.         debug(F110," password",s2,0);
  7428.     rcdactive = 1;
  7429.         sstate = setgen('C',s,s2,"");
  7430.         retcode = 0;
  7431.         break;
  7432.  
  7433.       case XZDEL:                               /* Delete */
  7434.         if ((x = cmtxt("Name of remote file(s) to delete",
  7435.                        "",&s,xxstring)) < 0) {
  7436.             if (x == -3) {
  7437.                 printf("?Name of remote file(s) required\n");
  7438.                 return(-9);
  7439.             } else return(x);
  7440.         }
  7441.         if ((x = remtxt(&s)) < 0)
  7442.           return(x);
  7443.         if (local) ttflui();            /* If local, flush tty input buffer */
  7444.         retcode = sstate = rfilop(s,'E');
  7445.         break;
  7446.  
  7447.       case XZDIR:                       /* Directory */
  7448.         if ((x = cmtxt("Remote directory or file specification","",&s,
  7449.                        xxstring)) < 0)
  7450.           return(x);
  7451.         if ((x = remtxt(&s)) < 0)
  7452.           return(x);
  7453.         if (local) ttflui();            /* If local, flush tty input buffer */
  7454.         rmsg();
  7455.         retcode = sstate = setgen('D',s,"","");
  7456.         break;
  7457.  
  7458.       case XZHLP:                       /* Help */
  7459.         if ((x = remcfm()) < 0) return(x);
  7460.         sstate = setgen('H',"","","");
  7461.         retcode = 0;
  7462.         break;
  7463.  
  7464.       case XZHOS:                       /* Host */
  7465.         if ((x = cmtxt("Command for remote system","",&s,xxstring)) < 0)
  7466.           return(x);
  7467.         if ((x = remtxt(&s)) < 0)
  7468.           return(x);
  7469.         if ((y = (int)strlen(s)) < 1)
  7470.           return(x);
  7471.         ckstrncpy(line,s,LINBUFSIZ);
  7472.         cmarg = line;
  7473.         rmsg();
  7474.         retcode = sstate = 'c';
  7475.         break;
  7476.  
  7477. #ifndef NOFRILLS
  7478.       case XZKER:
  7479.         if ((x = cmtxt("Command for remote Kermit","",&s,xxstring)) < 0)
  7480.           return(x);
  7481.         if ((x = remtxt(&s)) < 0)
  7482.           return(x);
  7483.         if ((int)strlen(s) < 1)  {
  7484.             if (x == -3) {
  7485.                 printf("?Remote Kermit command required\n");
  7486.                 return(-9);
  7487.             } else return(x);
  7488.         }
  7489.         ckstrncpy(line,s,LINBUFSIZ);
  7490.         cmarg = line;
  7491.         retcode = sstate = 'k';
  7492.         rmsg();
  7493.         break;
  7494.  
  7495.       case XZLGI:                       /* Login */
  7496.     rcdactive = 1;            /* Suppress "Logged in" msg if quiet */
  7497.         return(plogin(XXREM));
  7498.  
  7499.       case XZLGO: {                     /* Logout */
  7500.           extern int bye_active;
  7501.           if ((x = remcfm()) < 0) return(x);
  7502.           sstate = setgen('I',"","","");
  7503.           retcode = 0;
  7504.           bye_active = 1;               /* Close connection when done */
  7505.           break;
  7506.       }
  7507.  
  7508.       case XZPRI:                       /* Print */
  7509.         if (!atdiso || !atcapr) {       /* Disposition attribute off? */
  7510.             printf("?Disposition Attribute is Off\n");
  7511.             return(-2);
  7512.         }
  7513.         cmarg = "";
  7514.         cmarg2 = "";
  7515.         if ((x = cmifi("Local file(s) to print on remote printer","",&s,&y,
  7516.                        xxstring)) < 0) {
  7517.             if (x == -3) {
  7518.                 printf("?Name of local file(s) required\n");
  7519.                 return(-9);
  7520.             }
  7521.             return(x);
  7522.         }
  7523.         ckstrncpy(line,s,LINBUFSIZ);    /* Make a safe copy of filename */
  7524.         *optbuf = NUL;                  /* Wipe out any old options */
  7525.         if ((x = cmtxt("Options for remote print command","",&s,xxstring)) < 0)
  7526.           return(x);
  7527.         if ((x = remtxt(&s)) < 0)
  7528.           return(x);
  7529.         if ((int)strlen(optbuf) > 94) { /* Make sure this is legal */
  7530.             printf("?Option string too long\n");
  7531.             return(-9);
  7532.         }
  7533.         ckstrncpy(optbuf,s,OPTBUFLEN);  /* Make a safe copy of options */
  7534.         nfils = -1;                     /* Expand file list internally */
  7535.         cmarg = line;                   /* Point to file list. */
  7536.         rprintf = 1;                    /* REMOTE PRINT modifier for SEND */
  7537.         sstate = 's';                   /* Set start state to SEND */
  7538.         if (local) displa = 1;
  7539.         retcode = 0;
  7540.         break;
  7541. #endif /* NOFRILLS */
  7542.  
  7543.       case XZSPA:                       /* Space */
  7544.         if ((x = cmtxt("Confirm, or remote directory name",
  7545.                        "",&s,xxstring)) < 0)
  7546.           return(x);
  7547.         if ((x = remtxt(&s)) < 0)
  7548.           return(x);
  7549.         retcode = sstate = setgen('U',s,"","");
  7550.         break;
  7551.  
  7552. #ifndef NOFRILLS
  7553.       case XZTYP:                       /* Type */
  7554.         if ((x = cmtxt("Remote file specification","",&s,xxstring)) < 0)
  7555.           return(x);
  7556.         if ((int)strlen(s) < 1) {
  7557.             printf("?Remote filename required\n");
  7558.             return(-9);
  7559.         }
  7560.         if ((x = remtxt(&s)) < 0)
  7561.           return(x);
  7562.         rmsg();
  7563.         retcode = sstate = rfilop(s,'T');
  7564.         break;
  7565. #endif /* NOFRILLS */
  7566.  
  7567. #ifndef NOFRILLS
  7568.       case XZWHO:
  7569.         if ((x = cmtxt("Remote user name, or carriage return",
  7570.                        "",&s,xxstring)) < 0)
  7571.           return(x);
  7572.         if ((x = remtxt(&s)) < 0)
  7573.           return(x);
  7574.         retcode = sstate = setgen('W',s,"","");
  7575.         break;
  7576. #endif /* NOFRILLS */
  7577.  
  7578.       case XZPWD:                       /* PWD */
  7579.         if ((x = remcfm()) < 0) return(x);
  7580.         sstate = setgen('A',"","","");
  7581.         retcode = 0;
  7582.         break;
  7583.  
  7584. #ifndef NOSPL
  7585.       case XZQUE: {                     /* Query */
  7586.           char buf[2];
  7587.           extern char querybuf[], * qbufp;
  7588.           extern int qbufn;
  7589.           if ((y = cmkey(vartyp,nvartyp,"","",xxstring)) < 0)
  7590.             return(y);
  7591.           if ((x = cmtxt(y == 'F' ? "Remote function invocation" :
  7592.                          ('K' ? "Remote variable name or function":
  7593.                          "Remote variable name"),
  7594.                          "",
  7595.                          &s,
  7596.                          (y == 'K') ? xxstring : NULL
  7597.                          )) < 0)        /* Don't evaluate */
  7598.             return(x);
  7599.           if ((x = remtxt(&s)) < 0)
  7600.             return(x);
  7601.           query = 1;                    /* QUERY is active */
  7602.           qbufp = querybuf;             /* Initialize query response buffer */
  7603.           qbufn = 0;
  7604.           querybuf[0] = NUL;
  7605.           buf[0] = (char) (y & 127);
  7606.           buf[1] = NUL;
  7607.           retcode = sstate = setgen('V',"Q",(char *)buf,s);
  7608.           break;
  7609.       }
  7610.  
  7611.       case XZASG: {                     /* Assign */
  7612.           char buf[VNAML];
  7613.           if ((y = cmfld("Remote variable name","",&s,NULL)) < 0) /* No eval */
  7614.             return(y);
  7615.           if ((int)strlen(s) >= VNAML) {
  7616.               printf("?Too long\n");
  7617.               return(-9);
  7618.           }
  7619.           ckstrncpy(buf,s,VNAML);
  7620.           if ((x = cmtxt("Assignment for remote variable",
  7621.                    "",&s,xxstring)) < 0) /* Evaluate this one */
  7622.             return(x);
  7623.           if ((x = remtxt(&s)) < 0)
  7624.             return(x);
  7625. #ifdef COMMENT
  7626. /*
  7627.   Server commands can't be long packets.  In principle there's no reason
  7628.   why they shouldn't be, except that we don't know at this point if the
  7629.   server is capable of accepting long packets because we haven't started
  7630.   the protocol yet.  In practice, allowing a long packet here breaks a lot
  7631.   of assumptions, causes buffer overruns and crashes, etc.  To be fixed
  7632.   later.  (But since this is commented out, evidently I fixed it later...)
  7633. */
  7634.           if ((int)strlen(s) > 85) {    /* Allow for encoding expansion */
  7635.               printf("?Sorry, value is too long - 85 characters max\n");
  7636.               return(-9);
  7637.           }
  7638. #endif /* COMMENT */
  7639.           retcode = sstate = setgen('V',"S",(char *)buf,s);
  7640.           break;
  7641.       }
  7642. #endif /* NOSPL */
  7643.  
  7644.       case XZCPY: {                     /* COPY */
  7645.           char buf[TMPBUFSIZ];
  7646.           buf[TMPBUFSIZ-1] = '\0';
  7647.           if ((x = cmfld("Name of remote file to copy","",&s,xxstring)) < 0) {
  7648.               if (x == -3) {
  7649.                   printf("?Name of remote file required\n");
  7650.                   return(-9);
  7651.               }
  7652.               else
  7653.                 return(x);
  7654.           }
  7655.           ckstrncpy(buf,s,TMPBUFSIZ);
  7656.           if ((x = cmfld("Name of remote destination file or directory",
  7657.                          "",&s, xxstring)) < 0) {
  7658.               if (x == -3) {
  7659.                   printf("?Name of remote file or directory required\n");
  7660.                   return(-9);
  7661.               } else return(x);
  7662.           }
  7663.           ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  7664.           if ((x = remcfm()) < 0)
  7665.             return(x);
  7666.           if (local) ttflui();          /* If local, flush tty input buffer */
  7667.           retcode = sstate = setgen('K',buf,tmpbuf,"");
  7668.           break;
  7669.       }
  7670.       case XZREN: {                     /* Rename */
  7671.           char buf[TMPBUFSIZ];
  7672.           buf[TMPBUFSIZ-1] = '\0';
  7673.           if ((x = cmfld("Name of remote file to rename",
  7674.                          "",&s,xxstring)) < 0) {
  7675.               if (x == -3) {
  7676.                   printf("?Name of remote file required\n");
  7677.                   return(-9);
  7678.               } else return(x);
  7679.           }
  7680.           ckstrncpy(buf,s,TMPBUFSIZ);
  7681.           if ((x = cmfld("New name of remote file","",&s, xxstring)) < 0) {
  7682.               if (x == -3) {
  7683.                   printf("?Name of remote file required\n");
  7684.                   return(-9);
  7685.               } else return(x);
  7686.           }
  7687.           ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  7688.           if ((x = remcfm()) < 0)
  7689.             return(x);
  7690.           if (local) ttflui();          /* If local, flush device buffer */
  7691.           retcode = sstate = setgen('R',buf,tmpbuf,"");
  7692.           break;
  7693.       }
  7694.       case XZMKD:                       /* mkdir */
  7695.       case XZRMD:                       /* rmdir */
  7696.         if ((x = cmtxt((xx == XZMKD) ?
  7697.                        "Name of remote directory to create" :
  7698.                        "Name of remote directory to delete",
  7699.                        "",
  7700.                        &s,
  7701.                        xxstring
  7702.                        )) < 0) {
  7703.             if (x == -3) {
  7704.                 printf("?Name required\n");
  7705.                 return(-9);
  7706.             } else return(x);
  7707.         }
  7708.         if ((x = remtxt(&s)) < 0)
  7709.           return(x);
  7710.         if (local) ttflui();            /* If local, flush tty input buffer */
  7711.         retcode = sstate = rfilop(s, (char)(xx == XZMKD ? 'm' : 'd'));
  7712.         break;
  7713.  
  7714.       case XZXIT:                       /* Exit */
  7715.         if ((x = remcfm()) < 0) return(x);
  7716.         sstate = setgen('X',"","","");
  7717.         retcode = 0;
  7718.         break;
  7719.  
  7720.       default:
  7721.         if ((x = remcfm()) < 0) return(x);
  7722.         printf("?Not implemented - %s\n",cmdbuf);
  7723.         return(-2);
  7724.     }
  7725.     if (local && retcode > -1)          /* If local, flush tty input buffer */
  7726.       ttflui();
  7727.     return(retcode);
  7728. }
  7729.  
  7730.  
  7731. /*  R F I L O P  --  Remote File Operation  */
  7732.  
  7733. CHAR
  7734. #ifdef CK_ANSIC
  7735. rfilop(char * s, char t)
  7736. #else
  7737. rfilop(s,t) char *s, t;
  7738. #endif /* CK_ANSIC */
  7739. /* rfilop */ {
  7740.     if (*s == NUL) {
  7741.         printf("?File specification required\n");
  7742.         return((CHAR) 0);
  7743.     }
  7744.     debug(F111,"rfilop",s,t);
  7745.     return(setgen(t,s,"",""));
  7746. }
  7747. #endif /* NOXFER */
  7748.  
  7749. #ifdef ANYX25
  7750. int
  7751. setx25() {
  7752.     if ((y = cmkey(x25tab,nx25,"X.25 call options","",xxstring)) < 0)
  7753.       return(y);
  7754.     switch (y) {
  7755.       case XYUDAT:
  7756.         if ((z = cmkey(onoff,2,"X.25 call user data","",xxstring))
  7757.             < 0) return(z);
  7758.         if (z == 0) {
  7759.             if ((z = cmcfm()) < 0) return(z);
  7760.             cudata = 0;             /* disable call user data */
  7761.             return (success = 1);
  7762.         }
  7763.         if ((x = cmtxt("X.25 call user data string","",&s,xxstring)) < 0)
  7764.           return(x);
  7765.         if ((int)strlen(s) == 0) {
  7766.             return (-3);
  7767.         } else if ((int)strlen(s) > MAXCUDATA) {
  7768.             printf("?The length must be > 0 and <= %d\n",MAXCUDATA);
  7769.             return(-2);
  7770.         }
  7771.         if ((y = cmcfm()) < 0) return(y);
  7772.         ckstrncpy(udata,s,MAXCUDATA);
  7773.         cudata = 1;                     /* X.25 call user data specified */
  7774.         return (success = 1);
  7775.       case XYCLOS:
  7776.         if ((z = cmkey(onoff,2,"X.25 closed user group call","",xxstring))
  7777.             < 0) return(z);
  7778.         if (z == 0) {
  7779.             if ((z = cmcfm()) < 0) return(z);
  7780.             closgr = -1;                /* disable closed user group */
  7781.             return (success = 1);
  7782.         }
  7783.         if ((y = cmnum("0 <= cug index >= 99","",10,&x,xxstring)) < 0)
  7784.           return(y);
  7785.         if (x < 0 || x > 99) {
  7786.             printf("?The choices are 0 <= cug index >= 99\n");
  7787.             return(-2);
  7788.         }
  7789.         if ((y = cmcfm()) < 0) return(y);
  7790.         closgr = x;                     /* closed user group selected */
  7791.         return (success = 1);
  7792.  
  7793.       case XYREVC:
  7794.         if((z = cmkey(onoff,2,"X.25 reverse charge call","",xxstring)) < 0)
  7795.           return(z);
  7796.         if ((x = cmcfm()) < 0) return(x);
  7797.         revcall = z;
  7798.         return (success = 1);
  7799.     }
  7800. }
  7801.  
  7802. #ifndef IBMX25
  7803. int
  7804. setpadp() {
  7805.     if ((y = cmkey(padx3tab,npadx3,"PAD X.3 parameter name","",xxstring)) < 0)
  7806.       return(y);
  7807.     x = y;
  7808.     switch (x) {
  7809.       case PAD_BREAK_CHARACTER:
  7810.         if ((y = cmnum("PAD break character value","",10,&z,xxstring)) < 0)
  7811.           return(y);
  7812.         if ((y = cmcfm()) < 0) return(y);
  7813.         break;
  7814.       case PAD_ESCAPE:
  7815.         if ((y = cmnum("PAD escape","",10,&z,xxstring)) < 0) return(y);
  7816.         if (z != 0 && z != 1) {
  7817.             printf("?The choices are 0 or 1\n");
  7818.             return(-2);
  7819.         }
  7820.         if ((y = cmcfm()) < 0) return(y);
  7821.         break;
  7822.       case PAD_ECHO:
  7823.         if ((y = cmnum("PAD echo","",10,&z,xxstring)) < 0) return(y);
  7824.         if (z != 0 && z != 1) {
  7825.             printf("?The choices are 0 or 1\n");
  7826.             return(-2);
  7827.         }
  7828.         if ((y = cmcfm()) < 0) return(y);
  7829.         break;
  7830.       case PAD_DATA_FORWARD_CHAR:
  7831.         if ((y = cmnum("PAD data forward char","",10,&z,xxstring)) < 0)
  7832.           return(y);
  7833.         if (z != 0 && z != 2) {
  7834.             printf("?The choices are 0 or 2\n");
  7835.             return(-2);
  7836.         }
  7837.         if ((y = cmcfm()) < 0) return(y);
  7838.         break;
  7839.       case PAD_DATA_FORWARD_TIMEOUT:
  7840.         if ((y = cmnum("PAD data forward timeout","",10,&z,xxstring)) < 0)
  7841.             return(y);
  7842.         if (z < 0 || z > 255) {
  7843.             printf("?The choices are 0 or 1 <= timeout <= 255\n");
  7844.             return(-2);
  7845.         }
  7846.         if ((y = cmcfm()) < 0) return(y);
  7847.         break;
  7848.       case PAD_FLOW_CONTROL_BY_PAD:
  7849.         if ((y = cmnum("PAD pad flow control","",10,&z,xxstring)) < 0)
  7850.           return(y);
  7851.         if (z != 0 && z != 1) {
  7852.             printf("?The choices are 0 or 1\n");
  7853.             return(-2);
  7854.         }
  7855.         if ((y = cmcfm()) < 0) return(y);
  7856.         break;
  7857.       case PAD_SUPPRESSION_OF_SIGNALS:
  7858.         if ((y = cmnum("PAD service","",10,&z,xxstring)) < 0) return(y);
  7859.         if (z != 0 && z != 1) {
  7860.             printf("?The choices are 0 or 1\n");
  7861.             return(-2);
  7862.         }
  7863.         if ((y = cmcfm()) < 0) return(y);
  7864.         break;
  7865.  
  7866.       case PAD_BREAK_ACTION:
  7867.         if ((y = cmnum("PAD break action","",10,&z,xxstring)) < 0) return(y);
  7868.         if (z != 0 && z != 1 && z != 2 && z != 5 && z != 8 && z != 21) {
  7869.             printf("?The choices are 0, 1, 2, 5, 8 or 21\n");
  7870.             return(-2);
  7871.         }
  7872.         if ((y = cmcfm()) < 0) return(y);
  7873.         break;
  7874.  
  7875.       case PAD_SUPPRESSION_OF_DATA:
  7876.         if ((y = cmnum("PAD data delivery","",10,&z,xxstring)) < 0) return(y);
  7877.         if (z != 0 && z != 1) {
  7878.             printf("?The choices are 0 or 1\n");
  7879.             return(-2);
  7880.         }
  7881.         if ((y = cmcfm()) < 0) return(y);
  7882.         break;
  7883.  
  7884.       case PAD_PADDING_AFTER_CR:
  7885.         if ((y = cmnum("PAD crpad","",10,&z,xxstring)) < 0) return(y);
  7886.         if (z < 0 || z > 7) {
  7887.             printf("?The choices are 0 or 1 <= crpad <= 7\n");
  7888.             return(-2);
  7889.         }
  7890.         if ((y = cmcfm()) < 0) return(y);
  7891.         break;
  7892.  
  7893.       case PAD_LINE_FOLDING:
  7894.         if ((y = cmnum("PAD linefold","",10,&z,xxstring)) < 0) return(y);
  7895.         if (z < 0 || z > 255) {
  7896.             printf("?The choices are 0 or 1 <= linefold <= 255\n");
  7897.             return(-2);
  7898.         }
  7899.         if ((y = cmcfm()) < 0) return(y);
  7900.         break;
  7901.  
  7902.       case PAD_LINE_SPEED:
  7903.         if ((y = cmnum("PAD baudrate","",10,&z,xxstring)) < 0) return(y);
  7904.         if (z < 0 || z > 18) {
  7905.             printf("?The choices are 0 <= baudrate <= 18\n");
  7906.             return(-2);
  7907.         }
  7908.         if ((y = cmcfm()) < 0) return(y);
  7909.         break;
  7910.  
  7911.       case PAD_FLOW_CONTROL_BY_USER:
  7912.         if ((y = cmnum("PAD terminal flow control","",10,&z,xxstring)) < 0)
  7913.             return(y);
  7914.         if (z != 0 && z != 1) {
  7915.             printf("?The choices are 0 or 1\n");
  7916.             return(-2);
  7917.         }
  7918.         if ((y = cmcfm()) < 0) return(y);
  7919.         break;
  7920.  
  7921.       case PAD_LF_AFTER_CR:
  7922.         if ((y = cmnum("PAD crpad","",10,&z,xxstring)) < 0) return(y);
  7923.         if (z < 0 || z == 3 || z > 7) {
  7924.             printf("?The choices are 0, 1, 2, 4, 5, 6 or 7\n");
  7925.             return(-2);
  7926.         }
  7927.         if ((y = cmcfm()) < 0) return(y);
  7928.         break;
  7929.  
  7930.       case PAD_PADDING_AFTER_LF:
  7931.         if ((y = cmnum("PAD lfpad","",10,&z,xxstring)) < 0) return(y);
  7932.         if (z < 0 || z > 7) {
  7933.             printf("?The choices are 0 or 1 <= lfpad <= 7\n");
  7934.             return(-2);
  7935.         }
  7936.         if ((y = cmcfm()) < 0) return(y);
  7937.         break;
  7938.  
  7939.       case PAD_EDITING:
  7940.         if ((y = cmnum("PAD edit control","",10,&z,xxstring)) < 0) return(y);
  7941.         if (z != 0 && z != 1) {
  7942.             printf("?The choices are 0 or 1\n");
  7943.             return(-2);
  7944.         }
  7945.         if ((y = cmcfm()) < 0) return(y);
  7946.         break;
  7947.  
  7948.       case PAD_CHAR_DELETE_CHAR:
  7949.         if ((y = cmnum("PAD char delete char","",10,&z,xxstring)) < 0)
  7950.             return(y);
  7951.         if (z < 0 || z > 127) {
  7952.             printf("?The choices are 0 or 1 <= chardelete <= 127\n");
  7953.             return(-2);
  7954.         }
  7955.         if ((y = cmcfm()) < 0) return(y);
  7956.         break;
  7957.  
  7958.       case PAD_BUFFER_DELETE_CHAR:
  7959.         if ((y = cmnum("PAD buffer delete char","",10,&z,xxstring)) < 0)
  7960.             return(y);
  7961.         if (z < 0 || z > 127) {
  7962.             printf("?The choices are 0 or 1 <= bufferdelete <= 127\n");
  7963.             return(-2);
  7964.         }
  7965.         if ((y = cmcfm()) < 0) return(y);
  7966.         break;
  7967.  
  7968.       case PAD_BUFFER_DISPLAY_CHAR:
  7969.         if ((y = cmnum("PAD display line char","",10,&z,xxstring)) < 0)
  7970.             return(y);
  7971.         if (z < 0 || z > 127) {
  7972.             printf("?The choices are 0 or 1 <= displayline <= 127\n");
  7973.             return(-2);
  7974.         }
  7975.         if ((y = cmcfm()) < 0) return(y);
  7976.         break;
  7977.     }
  7978.     padparms[x] = z;
  7979.     return(success = 1);
  7980. }
  7981. #endif /* IBMX25 */
  7982. #endif /* ANYX25 */
  7983.  
  7984. #ifndef NOXFER
  7985. int
  7986. setat(rmsflg) int rmsflg; {
  7987.     int xx;
  7988.     if ((y = cmkey(attrtab,natr,"File Attribute packets","",xxstring)) < 0)
  7989.       return(y);
  7990.     if (y == AT_XALL) {                 /* ATTRIBUTES ALL ON or ALL OFF */
  7991.         if ((z = seton(&xx)) < 0) return(z);
  7992.         if (rmsflg) {
  7993.             printf("Sorry, command not available\n");
  7994.             return(-9);
  7995.         } else {
  7996.             atenci = xx;                /* Encoding in */
  7997.             atenco = xx;                /* Encoding out */
  7998.             atdati = xx;                /* Date in */
  7999.             atdato = xx;                /* Date out */
  8000.             atdisi = xx;                /* Disposition in/out */
  8001.             atdiso = xx;
  8002.             atleni = xx;                /* Length in/out (both kinds) */
  8003.             atleno = xx;
  8004.             atblki = xx;                /* Blocksize in/out */
  8005.             atblko = xx;
  8006.             attypi = xx;                /* File type in/out */
  8007.             attypo = xx;
  8008.             atsidi = xx;                /* System ID in/out */
  8009.             atsido = xx;
  8010.             atsysi = xx;                /* System-dependent params in/out */
  8011.             atsyso = xx;
  8012. #ifdef CK_PERMS                         /* Protection */
  8013.             atlpri = xx;                /* Local in */
  8014.             atlpro = xx;                /* Local out */
  8015.             atgpri = xx;                /* Generic in */
  8016.             atgpro = xx;                /* Generic out */
  8017. #endif /* CK_PERMS */
  8018. #ifdef STRATUS
  8019.             atfrmi = xx;                /* Format in/out */
  8020.             atfrmo = xx;
  8021.             atcrei = xx;                /* Creator id in/out */
  8022.             atcreo = xx;
  8023.             atacti = xx;                /* Account in/out */
  8024.             atacto = xx;
  8025. #endif /* STRATUS */
  8026.         }
  8027.         return(z);
  8028.     } else if (y == AT_ALLY || y == AT_ALLN) { /* ATTRIBUTES ON or OFF */
  8029.         if ((x = cmcfm()) < 0) return(x);
  8030.         atcapr = (y == AT_ALLY) ? 1 : 0;
  8031.         if (rmsflg) {
  8032.             sstate = setgen('S', "132", atcapr ? "1" : "0", "");
  8033.             return((int) sstate);
  8034.         } else return(success = 1);
  8035.     }
  8036.     /* Otherwise, it's an individual attribute that wants turning off/on */
  8037.  
  8038.     if ((z = cmkey(onoff,2,"","",xxstring)) < 0) return(z);
  8039.     if ((x = cmcfm()) < 0) return(x);
  8040.  
  8041. /* There are better ways to do this... */
  8042. /* The real problem is that we're not separating the in and out cases */
  8043. /* and so we have to arbitrarily pick the "in" case, i.e tell the remote */
  8044. /* server to ignore incoming attributes of the specified type, rather */
  8045. /* than telling it not to send them.  The protocol does not (yet) define */
  8046. /* codes for "in-and-out-at-the-same-time". */
  8047.  
  8048.     switch (y) {
  8049. #ifdef CK_PERMS
  8050. /* We're lumping local and generic protection together for now... */
  8051.       case AT_LPRO:
  8052.       case AT_GPRO:
  8053.         if (rmsflg) {
  8054.             sstate = setgen('S', "143", z ? "1" : "0", "");
  8055.             return((int) sstate);
  8056.         }
  8057.         atlpri = atlpro = atgpri = atgpro = z; break;
  8058. #endif /* CK_PERMS */
  8059.       case AT_DISP:
  8060.         if (rmsflg) {
  8061.             sstate = setgen('S', "142", z ? "1" : "0", "");
  8062.             return((int) sstate);
  8063.         }
  8064.         atdisi = atdiso = z; break;
  8065.       case AT_ENCO:
  8066.         if (rmsflg) {
  8067.             sstate = setgen('S', "141", z ? "1" : "0", "");
  8068.             return((int) sstate);
  8069.         }
  8070.         atenci = atenco = z; break;
  8071.       case AT_DATE:
  8072.         if (rmsflg) {
  8073.             sstate = setgen('S', "135", z ? "1" : "0", "");
  8074.             return((int) sstate);
  8075.         }
  8076.         atdati = atdato = z; break;
  8077.       case AT_LENB:
  8078.       case AT_LENK:
  8079.         if (rmsflg) {
  8080.             sstate = setgen('S', "133", z ? "1" : "0", "");
  8081.             return((int) sstate);
  8082.         }
  8083.         atleni = atleno = z; break;
  8084.       case AT_BLKS:
  8085.         if (rmsflg) {
  8086.             sstate = setgen('S', "139", z ? "1" : "0", "");
  8087.             return((int) sstate);
  8088.         }
  8089.         atblki = atblko = z; break;
  8090.       case AT_FTYP:
  8091.         if (rmsflg) {
  8092.             sstate = setgen('S', "134", z ? "1" : "0", "");
  8093.             return((int) sstate);
  8094.         }
  8095.         attypi = attypo = z; break;
  8096. #ifdef STRATUS
  8097.       case AT_CREA:
  8098.         if (rmsflg) {
  8099.             sstate = setgen('S', "136", z ? "1" : "0", "");
  8100.             return((int) sstate);
  8101.         }
  8102.         atcrei = atcreo = z; break;
  8103.       case AT_ACCT:
  8104.         if (rmsflg) {
  8105.             sstate = setgen('S', "137", z ? "1" : "0", "");
  8106.             return((int) sstate);
  8107.         }
  8108.         atacti = atacto = z; break;
  8109. #endif /* STRATUS */
  8110.       case AT_SYSI:
  8111.         if (rmsflg) {
  8112.             sstate = setgen('S', "145", z ? "1" : "0", "");
  8113.             return((int) sstate);
  8114.         }
  8115.         atsidi = atsido = z; break;
  8116.       case AT_RECF:
  8117.         if (rmsflg) {
  8118.             sstate = setgen('S', "146", z ? "1" : "0", "");
  8119.             return((int) sstate);
  8120.         }
  8121.         atfrmi = atfrmo = z; break;
  8122.       case AT_SYSP:
  8123.         if (rmsflg) {
  8124.             sstate = setgen('S', "147", z ? "1" : "0", "");
  8125.             return((int) sstate);
  8126.         }
  8127.         atsysi = atsyso = z; break;
  8128.       default:
  8129.         printf("?Not available\n");
  8130.         return(-2);
  8131.     }
  8132.     return(1);
  8133. }
  8134. #endif /* NOXFER */
  8135.  
  8136. #ifndef NOSPL
  8137. int
  8138. setinp() {
  8139.     if ((y = cmkey(inptab,ninp,"","",xxstring)) < 0) return(y);
  8140.     switch (y) {
  8141. #ifdef OS2
  8142.       case IN_PAC:                      /* SET INPUT PACING */
  8143.         z = cmnum("milliseconds","0",10,&x,xxstring);
  8144.         return(setnum(&tt_inpacing,x,z,1000));
  8145.       case IN_TRM:                      /* SET INPUT TERMINAL */
  8146.         return(seton(&interm));
  8147. #endif /* OS2 */
  8148.       case IN_DEF:                      /* SET INPUT DEFAULT-TIMEOUT */
  8149.         z = cmnum("Positive number","",10,&x,xxstring);
  8150.         return(setnum(&indef,x,z,94));
  8151.       case IN_TIM:                      /* SET INPUT TIMEOUT-ACTION */
  8152.         if ((z = cmkey(intimt,2,"","",xxstring)) < 0) return(z);
  8153.         if ((x = cmcfm()) < 0) return(x);
  8154.         intime[cmdlvl] = z;
  8155.         return(success = 1);
  8156.       case IN_CAS:                      /* SET INPUT CASE */
  8157.         if ((z = cmkey(incast,2,"","",xxstring)) < 0) return(z);
  8158.         if ((x = cmcfm()) < 0) return(x);
  8159.         inpcas[cmdlvl] = z;
  8160.         return(success = 1);
  8161.       case IN_ECH:                      /* SET INPUT ECHO */
  8162.         return(seton(&inecho));
  8163.       case IN_SIL:                      /* SET INPUT SILENCE */
  8164.         z = cmnum("Seconds of inactivity before INPUT fails","",10,&x,
  8165.                   xxstring);
  8166.         return(setnum(&insilence,x,z,-1));
  8167.  
  8168.       case IN_BUF:                      /* SET INPUT BUFFER-SIZE */
  8169.         if ((z = cmnum("Number of bytes in INPUT buffer",
  8170.                        ckitoa(INPBUFSIZ),10,&x, xxstring)) < 0)
  8171.           return(z);
  8172.         if ((y = cmcfm()) < 0) return(y);
  8173.         inbufsize = 0;
  8174.         if (inpbuf) {
  8175.             free(inpbuf);
  8176.             inpbuf = NULL;
  8177.             inpbp = NULL;
  8178.         }
  8179.         if (!(s = (char *)malloc(x + 1)))
  8180.           return(0);
  8181.         inpbuf = s;
  8182.         inpbp = s;
  8183.         inbufsize = x;
  8184.         for (x = 0; x <= inbufsize; x++)
  8185.           inpbuf[x] = NUL;
  8186.         return(success = 1);
  8187.  
  8188. #ifdef CK_AUTODL
  8189.       case IN_ADL:                      /* AUTODOWNLOAD */
  8190.         return(seton(&inautodl));
  8191. #endif /* CK_AUTODL */
  8192.  
  8193.       case IN_CAN:                      /* SET INPUT INTERRUPTS */
  8194.         return(seton(&inintr));
  8195.     }
  8196.     return(0);
  8197. }
  8198. #endif /* NOSPL */
  8199.  
  8200. #ifdef NETCONN
  8201. VOID
  8202. ndreset() {
  8203. #ifndef NODIAL                          /* This depends on DIAL... */
  8204.     int i=0, j=0;
  8205.     if (!ndinited)                      /* Don't free garbage... */
  8206.       return;
  8207.     for (i = 0; i < nhcount; i++) {     /* Clean out previous list */
  8208.         if (nh_p[i])
  8209.           free(nh_p[i]);
  8210.         nh_p[i] = NULL;
  8211.         if (nh_p2[i])
  8212.           free(nh_p2[i]);
  8213.         nh_p2[i] = NULL;
  8214.         for (j = 0; j < 4; j++) {
  8215.             if (nh_px[j][i])
  8216.               free(nh_px[j][i]);
  8217.             nh_px[j][i] = NULL;
  8218.         }
  8219.     }
  8220. #endif /* NODIAL */
  8221. }
  8222.  
  8223. VOID
  8224. ndinit() {                              /* Net directory pointers */
  8225. #ifndef NODIAL                          /* This depends on DIAL... */
  8226.     int i, j;
  8227.     if (ndinited++)                     /* Don't do this more than once. */
  8228.       return;
  8229.     for (i = 0; i < MAXDDIR; i++) {     /* Init all pointers to NULL */
  8230.         netdir[i] = NULL;
  8231.     }
  8232.     for (i = 0; i < MAXDNUMS; i++) {
  8233.         nh_p[i] = NULL;
  8234.         nh_p2[i] = NULL;
  8235.         for (j = 0; j < 4; j++)
  8236.           nh_px[j][i] = NULL;
  8237.     }
  8238. #endif /* NODIAL */
  8239. }
  8240.  
  8241. #ifndef NODIAL
  8242. #ifdef NETCONN
  8243. VOID                                    /* Get net defaults from environment */
  8244. getnetenv() {
  8245.     char *p = NULL;
  8246.  
  8247.     makestr(&p,getenv("K_NET_DIRECTORY")); /* Dialing directories */
  8248.     if (p) {
  8249.         int i;
  8250.         xwords(p,MAXDDIR,netdir,0);
  8251.         for (i = 0; i < MAXDDIR; i++) { /* Fill in any gaps... */
  8252.             if (!netdir[i+1])
  8253.               break;
  8254.             else
  8255.               netdir[i] = netdir[i+1];
  8256.             debug(F111,"netdir[i]",netdir[i],i);
  8257.         }
  8258.         nnetdir = i;
  8259.     }
  8260. }
  8261. #endif /* NETCONN */
  8262. #endif /* NODIAL */
  8263.  
  8264. int
  8265. #ifdef CK_ANSIC
  8266. lunet(char *s)                          /* s = name to look up   */
  8267. #else
  8268. lunet(s) char *s;
  8269. #endif /* CK_ANSIC */
  8270. /* lunet */ {
  8271. #ifndef NODIAL                          /* This depends on DIAL... */
  8272.     int n, n1, t, dd = 0;
  8273.     int ambiguous = 0;
  8274.     FILE * f;
  8275.     char *line = NULL;
  8276.     extern int dialdpy;
  8277.     int netdpy = dialdpy;
  8278.     char *info[8];
  8279.  
  8280.     nhcount = 0;                        /* Set this before returning */
  8281.  
  8282.     if (!s || nnetdir < 1)              /* Validate arguments */
  8283.       return(-1);
  8284.  
  8285.     if (isdigit(*s) || *s == '*' || *s == '.')
  8286.       return(0);
  8287.  
  8288.     if ((n1 = (int) strlen(s)) < 1)     /* Length of string to look up */
  8289.       return(-1);
  8290.  
  8291.     if (!(line = malloc(1024)))         /* Allocate input buffer */
  8292.       return(-1);
  8293.  
  8294.   lu_again:
  8295.     f = NULL;                           /* Network directory file descriptor */
  8296.     t = nhcount = 0;                    /* Match count */
  8297.     dd = 0;                             /* Directory counter */
  8298.  
  8299.     dirline = 0;
  8300.     while (1) {                         /* We make one pass */
  8301.         if (!f) {                       /* Directory not open */
  8302.             if (dd >= nnetdir)          /* No directories left? */
  8303.               break;                    /* Done. */
  8304.             if ((f = fopen(netdir[dd],"r")) == NULL) { /* Open it */
  8305.                 perror(netdir[dd]);     /* Can't, print message saying why */
  8306.                 dd++;
  8307.                 continue;               /* But go on to next one. */
  8308.             }
  8309.             if (netdpy)
  8310.               printf("Opening %s...\n",netdir[dd]);
  8311.             dd++;
  8312.         }
  8313.         line[0] = NUL;
  8314.         if (getnct(line,1023,f,1) < 0) { /* Read a line */
  8315.             if (f) {                    /* f can be clobbered! */
  8316.                 fclose(f);              /* Close the file */
  8317.                 f = NULL;               /* Indicate next one needs opening */
  8318.             }
  8319.             continue;
  8320.         }
  8321.         if (!line[0])                   /* Empty line */
  8322.           continue;
  8323.  
  8324.         xwords(line,7,info,0);          /* Parse it */
  8325.  
  8326.         if (!info[1] || !info[2] || !info[3]) /* Required fields */
  8327.           continue;
  8328.         if (*info[1] == ';')            /* Full-line comment */
  8329.           continue;
  8330.         if ((n = (int) strlen(info[1])) < 1) /* Length of name-tag */
  8331.           continue;
  8332.         if (n < n1)                     /* Search name is longer */
  8333.           continue;                     /* Can't possibly match */
  8334.         if (ambiguous && n != n1)
  8335.           continue;
  8336.         if (ckstrcmp(s,info[1],n1,0))   /* Compare using length of */
  8337.           continue;                     /* search string s. */
  8338.  
  8339.         /* Have a match */
  8340.  
  8341.         makestr(&(nh_p[nhcount]), info[3]);    /* address */
  8342.         makestr(&(nh_p2[nhcount]),info[2]);    /* net type */
  8343.         makestr(&(nh_px[0][nhcount]),info[4]); /* net-specific stuff... */
  8344.         makestr(&(nh_px[1][nhcount]),info[5]);
  8345.         makestr(&(nh_px[2][nhcount]),info[6]);
  8346.         makestr(&(nh_px[3][nhcount]),info[7]);
  8347.  
  8348.         nhcount++;                      /* Count this match */
  8349.         if (nhcount > MAXDNUMS) {       /* Watch out for too many */
  8350.             printf("Warning: %d matches found, %d max\n",
  8351.                    nhcount,
  8352.                    MAXDNUMS
  8353.                    );
  8354.             nhcount = MAXDNUMS;
  8355.             break;
  8356.         }
  8357.         if (nhcount == 1) {             /* First one - save entry name */
  8358.             if (n_name) {               /* Free the one from before if any */
  8359.                 free(n_name);
  8360.                 n_name = NULL;
  8361.             }
  8362.             if (!(n_name = (char *)malloc(n + 1))) { /* Allocate new storage */
  8363.                 printf("?memory allocation error - lunet:3\n");
  8364.                 if (line) {
  8365.                     free(line);
  8366.                     line = NULL;
  8367.                 }
  8368.                 nhcount = 0;
  8369.                 return(-1);
  8370.             }
  8371.             t = n;                      /* Remember its length */
  8372.             strcpy(n_name,info[1]);     /* safe */
  8373.         } else {                        /* Second or subsequent one */
  8374.             if ((int) strlen(info[1]) == t) /* Lengths compare */
  8375.               if (!ckstrcmp(n_name,info[1],t,0)) /* Caseless compare OK */
  8376.                 continue;
  8377.  
  8378.             /* Name given by user matches entries with different names */
  8379.  
  8380.             if (ambiguous)              /* Been here before */
  8381.               break;
  8382.  
  8383.             ambiguous = 1;              /* Now an exact match is required */
  8384.             ndreset();                  /* Clear out previous list */
  8385.             goto lu_again;              /* Do it all over again. */
  8386.         }
  8387.     }
  8388.     if (line) {
  8389.         free(line);
  8390.         line = NULL;
  8391.     }
  8392.     if (nhcount == 0 && ambiguous)
  8393.       printf("?\"%s\" - ambiguous in network directory\n",s);
  8394. #else
  8395.     nhcount = 0;
  8396. #endif /* NODIAL */
  8397.     return(nhcount);
  8398. }
  8399. #endif /* NETCONN */
  8400.  
  8401. #ifndef NOLOCAL
  8402. /*  C L S C O N N X  --  Close connection  */
  8403.  
  8404. int
  8405. clsconnx(ask) int ask; {
  8406.     int x, rc = 0;
  8407. #ifdef NEWFTP
  8408.     extern int ftpget, ftpisopen(), ftpbye();
  8409.     if ((ftpget == 1) || ((ftpget == 2) && !local && ftpisopen()))
  8410.       return(success = ftpbye());
  8411. #endif /* NEWFTP */
  8412.     debug(F101,"clsconnx local","",local);
  8413.     if (local) {
  8414.         x = ask ? hupok(1) : 1;         /* Make sure it's OK to close */
  8415.         if (!x) {
  8416.             rc = -1;
  8417.             debug(F101,"clsconnx hupok says no","",rc);
  8418.             return(rc);
  8419.         }
  8420.         ttflui();                       /* Clear away buffered up junk */
  8421. #ifndef NODIAL
  8422. #ifdef OS2ONLY
  8423. /* Don't hangup a line that is shared with the SLIP or PPP driver */
  8424.         if (!ttslip && !ttppp)
  8425. #endif /* OS2ONLY */
  8426.           mdmhup();
  8427. #endif /* NODIAL */
  8428.         if (network && msgflg)
  8429.           printf(" Closing connection\n");
  8430.         ttclos(0);                      /* Close old connection, if any */
  8431.         rc = 1;
  8432.         {
  8433.             extern int wasclosed, whyclosed;
  8434.             if (wasclosed) {
  8435.                 whyclosed = WC_CLOS;
  8436. #ifndef NOSPL
  8437.                 if (nmac) {             /* Any macros defined? */
  8438.                     int k;              /* Yes */
  8439.                     /* printf("ON_CLOSE CLSCONNX\n"); */
  8440.                     wasclosed = 0;
  8441.                     k = mlook(mactab,"on_close",nmac);  /* Look this up */
  8442.                     if (k >= 0) {                       /* If found, */
  8443.                         if (dodo(k,ckitoa(whyclosed),0) > -1) /* set it up, */
  8444.                           parser(1);                    /* and execute it */
  8445.                     }
  8446.                 }
  8447. #endif /* NOSPL */
  8448.                 whyclosed = WC_REMO;
  8449.                 wasclosed = 0;
  8450.             }
  8451.         }
  8452.     }
  8453. #ifdef VMS                              /* Or maybe #ifndef UNIX? */
  8454.     else {                              /* Need to do this in VMS to */
  8455.         ttclos(0);                      /* free the tty channel number */
  8456.         rc = 1;                         /* obtained in ttopen() or else */
  8457.     }                                   /* subsequent ttopen's won't work */
  8458. #endif /* VMS */
  8459.     dologend();
  8460.     haveline = 0;
  8461.     if (mdmtyp < 0) {                   /* Switching from net to async? */
  8462.         if (mdmsav > -1)                /* Restore modem type from last */
  8463.           mdmtyp = mdmsav;              /* SET MODEM command, if any. */
  8464.         else
  8465.           mdmtyp = 0;
  8466.         mdmsav = -1;
  8467.     }
  8468.     if (network)
  8469.       network = 0;
  8470. #ifdef NETCONN
  8471.     if (oldplex > -1) {                 /* Restore previous duplex setting. */
  8472.         duplex = oldplex;
  8473.         oldplex = -1;
  8474.     }
  8475. #endif /* NETCONN */
  8476. #ifndef MAC
  8477.     ckstrncpy(ttname,dftty,TTNAMLEN);   /* Restore default communication */
  8478. #endif /* MAC */
  8479.     local = dfloc;                      /* device and local/remote status */
  8480.     if (local) {
  8481.         cxtype = CXT_DIRECT;            /* Something reasonable */
  8482.         speed = ttgspd();               /* Get the current speed */
  8483.     } else {
  8484.         cxtype = CXT_REMOTE;
  8485.         speed = -1L;
  8486.     }
  8487. #ifndef NOXFER
  8488.     if (xreliable > -1 && !setreliable) {
  8489.         reliable = xreliable;
  8490.         debug(F101,"clsconnx reliable A","",reliable);
  8491.     } else if (!setreliable) {
  8492.         reliable = SET_AUTO;
  8493.         debug(F101,"clsconnx reliable B","",reliable);
  8494.     }
  8495. #endif /* NOXFER */
  8496.     setflow();                          /* Revert flow control */
  8497.     return(rc);
  8498. }
  8499.  
  8500. int
  8501. clskconnx(x) int x; {                   /* Close Kermit connection only */
  8502.     int t, rc;                          /* (not FTP) */
  8503. #ifdef NEWFTP
  8504.     extern int ftpget;
  8505.     t = ftpget;
  8506.     ftpget = 0;
  8507. #endif /* NEWFTP */
  8508.     rc = clsconnx(x);
  8509. #ifdef NEWFTP
  8510.     ftpget = t;
  8511. #endif /* NEWFTP */
  8512.     return(rc);
  8513. }
  8514.  
  8515. /* May 2002: setlin() decomposition starts here ... */
  8516.  
  8517. #ifdef OS2
  8518. #define SRVBUFSIZ PIPENAML
  8519. #else /* OS2 */
  8520. #define SRVBUFSIZ 63
  8521. #endif /* OS2 */
  8522. #define HOSTNAMLEN 15*65
  8523.  
  8524. int netsave = -1;
  8525. static char * tmpstring = NULL;
  8526. static char * tmpusrid = NULL;
  8527.  
  8528. #ifdef SSHCMD
  8529. char * sshcmd = NULL;
  8530. char * defsshcmd = "ssh -e none";
  8531. #else
  8532. #ifdef SSHBUILTIN
  8533. char * sshrcmd = NULL;
  8534. char * sshtmpcmd = NULL;
  8535. #endif /* SSHBUILTIN */
  8536. #endif /* SSHCMD */
  8537.  
  8538. /* c x _ f a i l  --  Common error exit routine for cx_net, cx_line */
  8539.  
  8540. int
  8541. cx_fail(msg, text) int msg; char * text; {
  8542.     makestr(&slmsg,text);        /* For the record (or GUI) */
  8543.     if (msg)                /* Not GUI, not quiet, etc */
  8544.       printf("?%s\n",text);        /* Print error message */
  8545.     slrestor();                /* Restore LINE/HOST to known state */
  8546.     return(msg ? -9 : (success = 0));    /* Return appropriate code */
  8547. }
  8548.  
  8549. #ifdef NETCONN
  8550. /* c x _ n e t  --  Make a network connection */
  8551.  
  8552. /*
  8553.   Call with:
  8554.     net      = network type
  8555.     protocol = protocol type
  8556.     host     = string pointer to host name.
  8557.     svc      = string pointer to service or port on host.
  8558.     username = username for connection
  8559.     password = password for connection
  8560.     command  = command to execute
  8561.     param1   = Telnet: Authentication type
  8562.                SSH:    Version
  8563.     param2   = Telnet: Encryption type
  8564.                SSH:    Command as Subsystem
  8565.     param3   = Telnet: 1 to wait for negotiations, 0 otherwise
  8566.                SSH:    X11 Forwarding
  8567.     cx       = 1 to automatically enter Connect mode, 0 otherwise.
  8568.     sx       = 1 to automatically enter Server mode, 0 otherwise.
  8569.     flag     = if no host name given, 1 = close current connection, 0 = resume
  8570.     gui      = 1 if called from GUI dialog, 0 otherwise.
  8571.   Returns:
  8572.     1 on success
  8573.     0 on failure and no message printed, slmsg set to failure message.
  8574.    -9 on failure and message printed, ditto.
  8575. */
  8576. int
  8577. #ifdef CK_ANSIC
  8578. cx_net( int net, int protocol, char * xhost, char * svc, 
  8579.         char * username, char * password, char * command,
  8580.         int param1, int param2, int param3, int cx, int sx, int flag, int gui)
  8581. #else /* CK_ANSIC */
  8582. cx_net(net, protocol, xhost, svc,
  8583.        username, password, command,
  8584.        param1, param2, param3, cx, sx, flag, gui)
  8585.     char * xhost, * svc, * username, *password, *command; 
  8586.     int net, protocol, cx, sx, flag, param1, param2, param3, gui; 
  8587. #endif /* CK_ANSIC */
  8588. /* cx_net */ {
  8589.  
  8590.     int i, n, x, msg;
  8591.     int _local = -1;
  8592.  
  8593.     extern char pwbuf[], * g_pswd;
  8594.     extern int pwflg, pwcrypt, g_pflg, g_pcpt, nolocal;
  8595.  
  8596.     char srvbuf[SRVBUFSIZ+1];        /* Service */
  8597.     char hostbuf[HOSTNAMLEN];        /* Host buffer to manipulate */
  8598.     char hostname[HOSTNAMLEN];        /* Copy of host parameter */
  8599.     char * host = hostbuf;        /* Pointer to copy of host param */
  8600.  
  8601.     if (!xhost) xhost = "";        /* Watch out for null pointers */
  8602.     if (!svc) svc = "";
  8603.     ckstrncpy(host,xhost,HOSTNAMLEN);    /* Avoid buffer confusion */
  8604.  
  8605.     debug(F110,"cx_net host",host,0);
  8606.     debug(F111,"cx_net service",svc,SRVBUFSIZ);
  8607.     debug(F101,"cx_net network type","",net);
  8608.  
  8609.     msg = (gui == 0) && msgflg;        /* Whether to print messages */
  8610.  
  8611. #ifndef NODIAL
  8612.     debug(F101,"cx_net nnetdir","",nnetdir);
  8613.     x = 0;                /* Look up in network directory */
  8614.     if (*host == '=') {            /* If number starts with = sign */
  8615.     host++;                /* strip it */
  8616.     while (*host == SP) host++;    /* and any leading spaces */
  8617.     debug(F110,"cx_net host 2",host,0);
  8618.     nhcount = 0;
  8619.     } else if (*host) {            /* We want to look it up. */
  8620.     if (nnetdir > 0)        /* If there is a directory... */
  8621.       x = lunet(host);        /* (sets nhcount) */
  8622.     else                /* otherwise */
  8623.       nhcount = 0;            /* we didn't find any there */
  8624.     if (x < 0)            /* Internal error? */
  8625.       return(cx_fail(msg,"Network directory lookup error"));
  8626.     debug(F111,"cx_net lunet nhcount",host,nhcount);
  8627.     }
  8628. #endif /* NODIAL */
  8629.  
  8630.     /* New connection wanted.  Make a copy of the host name/address... */
  8631.  
  8632.     if (clskconnx(1) < 0)        /* Close current Kermit connection */
  8633.       return(cx_fail(msg,"Error closing previous connection"));
  8634.  
  8635.     if (*host) {            /* They gave a hostname */
  8636.     _local = 1;            /* Network connection always local */
  8637.     if (mdmsav < 0)
  8638.       mdmsav = mdmtyp;        /* Remember old modem type */
  8639.     mdmtyp = -net;            /* Special code for network */
  8640.     } else {                /* They just said "set host" */
  8641.     host = dftty;            /* So go back to normal */
  8642.     _local = dfloc;            /* default tty, location, */
  8643.     if (flag) {            /* Close current connection */
  8644.         setflow();            /* Maybe change flow control */
  8645.         haveline = 1;        /* (* is this right? *) */
  8646.         dologend();
  8647. #ifndef NODIAL
  8648.         dialsta = DIA_UNK;
  8649. #endif /* NODIAL */
  8650. #ifdef LOCUS
  8651.         if (autolocus) {
  8652.         setlocus(1,1);
  8653.         }
  8654. #endif /* LOCUS */
  8655.             /* XXX - Is this right? */
  8656.         /* Should we be returning without doing anything ? */
  8657.         /* Yes it's right -- we closed the old connection just above. */
  8658.         return(success = 1);        
  8659.     }
  8660.     }
  8661.     success = 0;
  8662.     if (host != line)                   /* line[] is a global */
  8663.       ckstrncpy(line,host,LINBUFSIZ);
  8664.     ckstrncpy(hostname,host,HOSTNAMLEN);
  8665.     ckstrncpy(srvbuf,svc,SRVBUFSIZ+1);
  8666.  
  8667. #ifndef NODIAL
  8668.     if ((nhcount > 1) && msg) {
  8669.     int k;
  8670.     printf("%d entr%s found for \"%s\"%s\n",
  8671.            nhcount,
  8672.            (nhcount == 1) ? "y" : "ies",
  8673.            s,
  8674.            (nhcount > 0) ? ":" : "."
  8675.            );
  8676.     for (i = 0; i < nhcount; i++) {
  8677.         printf("%3d. %-12s => %-9s %s",
  8678.                i+1,n_name,nh_p2[i],nh_p[i]);
  8679.         for (k = 0; k < 4; k++) { /* Also list net-specific items */
  8680.         if (nh_px[k][i])      /* free format... */
  8681.           printf(" %s",nh_px[k][i]);
  8682.         else
  8683.           break;
  8684.         }
  8685.         printf("\n");
  8686.     }
  8687.     }
  8688.     if (nhcount == 0)
  8689.       n = 1;
  8690.     else
  8691.       n = nhcount;
  8692. #else
  8693.     n = 1;
  8694.     nhcount = 0;
  8695. #endif /* NODIAL */
  8696.  
  8697.     for (i = 0; i < n; i++) {        /* Loop for each entry found */
  8698.     debug(F101,"cx_net loop i","",i);
  8699. #ifndef NODIAL
  8700.     if (nhcount > 0) {        /* If we found at least one entry... */
  8701.         ckstrncpy(line,nh_p[i],LINBUFSIZ); /* Copy current entry */
  8702.         if (lookup(netcmd,nh_p2[i],nnets,&x) > -1) { /* Net type */
  8703.         int xx;
  8704.         xx = netcmd[x].kwval;
  8705.         /* User specified SSH so don't let net directory override */
  8706.         if (net != NET_SSH || xx != NET_TCPB) {
  8707.             net = xx;
  8708.             mdmtyp  = 0 - net;
  8709.         }
  8710.         } else {
  8711.         makestr(&slmsg,"Network type not supported");
  8712.         if (msg)
  8713.           printf("Error - network type \"%s\" not supported\n",
  8714.              nh_p2[i]
  8715.                  );
  8716.         continue;
  8717.         }
  8718.         switch (net) {        /* Net-specific directory things */
  8719. #ifdef SSHBUILTIN
  8720.           case NET_SSH:        /* SSH */
  8721.                 /* Any SSH specific network directory stuff? */
  8722.                 break;                  /* NET_SSH */
  8723. #endif /* SSHBUILTIN */
  8724.  
  8725.           case NET_TCPB: {        /* TCP/IP TELNET,RLOGIN,... */
  8726. #ifdef TCPSOCKET
  8727.           char *q;
  8728.           int flag = 0;
  8729.  
  8730.           /* Extract ":service", if any, from host string */
  8731.           debug(F110,"cx_net service 1",line,0);
  8732.           for (q = line; (*q != '\0') && (*q != ':'); q++)
  8733.             ;
  8734.           if (*q == ':') { *q++ = NUL; flag = 1; }
  8735.           debug(F111,"cx_net service 2",line,flag);
  8736.  
  8737.           /* Get service, if any, from directory entry */
  8738.  
  8739.           if (!*srvbuf) {
  8740.               if (nh_px[0][i]) {
  8741.               ckstrncpy(srvbuf,nh_px[0][i],SRVBUFSIZ);
  8742.               debug(F110,"cx_net service 3",srvbuf,0);
  8743.               }
  8744.               if (flag) {
  8745.               ckstrncpy(srvbuf,q,SRVBUFSIZ);
  8746.               debug(F110,"cx_net service 4",srvbuf,0);
  8747.               }
  8748.           }
  8749.           ckstrncpy(hostname,line,HOSTNAMLEN);
  8750.  
  8751.           /* If we have a service, append to host name/address */
  8752.           if (*srvbuf) {
  8753.               ckstrncat(line, ":", LINBUFSIZ);
  8754.               ckstrncat(line, srvbuf, LINBUFSIZ);
  8755.               debug(F110,"cx_net service 5",line,0);
  8756.           }
  8757. #ifdef RLOGCODE
  8758.           /* If no service given but command was RLOGIN */
  8759.           else if (ttnproto == NP_RLOGIN) { /* add this... */
  8760.               ckstrncat(line, ":login",LINBUFSIZ);
  8761.               debug(F110,"cx_net service 6",line,0);
  8762.           }
  8763. #ifdef CK_AUTHENTICATION
  8764. #ifdef CK_KERBEROS
  8765.           else if (ttnproto == NP_K4LOGIN ||
  8766.                ttnproto == NP_K5LOGIN) { /* add this... */
  8767.               ckstrncat(line, ":klogin",LINBUFSIZ);
  8768.               debug(F110,"cx_net service 7",line,0);
  8769.           }
  8770.           else if (ttnproto == NP_EK4LOGIN ||
  8771.                ttnproto == NP_EK5LOGIN) { /* add this... */
  8772.               ckstrncat(line, ":eklogin",LINBUFSIZ);
  8773.               debug(F110,"cx_net service 8",line,0);
  8774.           }
  8775. #endif /* CK_KERBEROS */
  8776. #endif /* CK_AUTHENTICATION */
  8777. #endif /* RLOGCODE */
  8778.           else {        /* Otherwise, add ":telnet". */
  8779.               ckstrncat(line, ":telnet", LINBUFSIZ);
  8780.               debug(F110,"cx_net service 9",line,0);
  8781.           }
  8782.           if (username) {    /* This is a parameter... */
  8783.               ckstrncpy(uidbuf,username,UIDBUFLEN);
  8784.               uidflag = 1;
  8785.           }
  8786.           /* Fifth field, if any, is user ID (for rlogin) */
  8787.  
  8788.           if (nh_px[1][i] && !uidflag)
  8789.             ckstrncpy(uidbuf,username,UIDBUFLEN);
  8790. #ifdef RLOGCODE
  8791.           if (IS_RLOGIN() && !uidbuf[0])
  8792.             return(cx_fail(msg,"Username required"));
  8793. #endif /* RLOGCODE */
  8794. #endif /* TCPSOCKET */
  8795.           break;
  8796.           }
  8797.           case NET_PIPE:        /* Pipe */
  8798. #ifdef NPIPE
  8799.         if (!pipename[0]) { /* User didn't give a pipename */
  8800.             if (nh_px[0][i]) { /* But directory entry has one */
  8801.             if (strcmp(pipename,"\\pipe\\")) {
  8802.                 ckstrncpy(pipename,"\\pipe\\",LINBUFSIZ);
  8803.                 ckstrncat(srvbuf,nh_px[0][i],PIPENAML-6);
  8804.             } else {
  8805.                 ckstrncpy(pipename,nh_px[0][i],PIPENAML);
  8806.             }
  8807.             debug(F110,"cx_net pipeneme",pipename,0);
  8808.             }
  8809.         }
  8810. #endif /* NPIPE */
  8811.         break;
  8812.  
  8813.           case NET_SLAT:            /* LAT / CTERM */
  8814. #ifdef SUPERLAT
  8815.         if (!slat_pwd[0]) { /* User didn't give a password */
  8816.             if (nh_px[0][i]) { /* But directory entry has one */
  8817.             ckstrncpy(slat_pwd,nh_px[0][i],18);
  8818.             debug(F110,"cx_net SuperLAT password",slat_pwd,0);
  8819.             }
  8820.         }
  8821. #endif /* SUPERLAT */
  8822.         break;
  8823.  
  8824.           case NET_SX25:        /* X.25 keyword parameters */
  8825.           case NET_IX25:
  8826.           case NET_VX25: {
  8827. #ifdef ANYX25
  8828.           int k;            /* Cycle through the four fields */
  8829.           for (k = 0; k < 4; k++) {
  8830.               if (!nh_px[k][i]) /* Bail out if none left */
  8831.             break;
  8832.               if (!ckstrcmp(nh_px[k][i],"cug=",4,0)) {
  8833.               closgr = atoi(nh_px[k][i]+4);
  8834.               debug(F101,"X25 CUG","",closgr);
  8835.               } else if (!ckstrcmp(nh_px[k][i],"cud=",4,0)) {
  8836.               cudata = 1;
  8837.               ckstrncpy(udata,nh_px[k][i]+4,MAXCUDATA);
  8838.               debug(F110,"X25 CUD",cudata,0);
  8839.               } else if (!ckstrcmp(nh_px[k][i],"rev=",4,0)) {
  8840.               revcall = !ckstrcmp(nh_px[k][i]+4,"=on",3,0);
  8841.               debug(F101,"X25 REV","",revcall);
  8842. #ifndef IBMX25
  8843.               } else if (!ckstrcmp(nh_px[k][i],"pad=",4,0)) {
  8844.               int x3par, x3val;
  8845.               char *s1, *s2;
  8846.               s1 = s2 = nh_px[k][i]+4; /* PAD parameters */
  8847.               while (*s2) {            /* Pick them apart */
  8848.                   if (*s2 == ':') {
  8849.                   *s2 = NUL;
  8850.                   x3par = atoi(s1);
  8851.                   s1 = ++s2;
  8852.                   continue;
  8853.                   } else if (*s2 == ',') {
  8854.                   *s2 = NUL;
  8855.                   x3val = atoi(s1);
  8856.                   s1 = ++s2;
  8857.                   debug(F111,"X25 PAD",x3par,x3val);
  8858.                   if (x3par > -1 &&
  8859.                       x3par <= MAXPADPARMS)
  8860.                     padparms[x3par] = x3val;
  8861.                   continue;
  8862.                   } else
  8863.                 s2++;
  8864.               }
  8865. #endif /* IBMX25 */
  8866.               }
  8867.           }
  8868. #endif /* ANYX25 */
  8869.           break;
  8870.           }
  8871.           default:            /* Nothing special for other nets */
  8872.         break;
  8873.         }
  8874.     } else
  8875. #endif /* NODIAL */
  8876.     {                /* No directory entries found. */
  8877.         ckstrncpy(line,hostname,LINBUFSIZ); /* Put this back... */
  8878.         /* If the user gave a TCP service */
  8879.         if (net == NET_TCPB || net == NET_SSH)
  8880.           if (*srvbuf) {        /* Append it to host name/address */
  8881.           ckstrncat(line, ":", LINBUFSIZ);
  8882.           ckstrncat(line, srvbuf,LINBUFSIZ);
  8883.           }
  8884.     }
  8885.     /*
  8886.        Get here with host name/address and all net-specific
  8887.        parameters set, ready to open the connection.
  8888.     */
  8889.     mdmtyp = -net;            /* This should have been done */
  8890.                     /* already but just in case ... */
  8891.  
  8892.     debug(F110,"cx_net net line[] before ttopen",line,0);
  8893.     debug(F101,"cx_net net mdmtyp before ttopen","",mdmtyp);
  8894.     debug(F101,"cx_net net ttnproto","",ttnproto);
  8895.  
  8896. #ifdef SSHBUILTIN
  8897.         if (net == NET_SSH) {
  8898.             makestr(&ssh_hst,hostname);        /* Stash everything */
  8899.             if (username) {
  8900.                 if (!sl_uid_saved) {
  8901.                     ckstrncpy(sl_uidbuf,uidbuf,UIDBUFLEN);
  8902.                     sl_uid_saved = 1;
  8903.                 }
  8904.                 ckstrncpy(uidbuf,username,UIDBUFLEN);
  8905.             }
  8906.             if (srvbuf[0]) {
  8907.                 makestr(&ssh_prt,srvbuf);
  8908.             } else
  8909.                 makestr(&ssh_prt,NULL);
  8910.  
  8911.             if (command) {
  8912.                 makestr(&ssh_cmd,brstrip(command));
  8913.                 ssh_cas = param2;
  8914.             } else
  8915.                 makestr(&ssh_cmd,NULL);
  8916.  
  8917.             if (param1 > -1) {
  8918. #ifndef SSHTEST
  8919.                 if (!sl_ssh_ver_saved) {
  8920.                     sl_ssh_ver = ssh_ver;
  8921.                     sl_ssh_ver_saved = 1;
  8922.                 }
  8923. #endif /* SSHTEST */
  8924.                 ssh_ver = param1;
  8925.             }
  8926.             if (param3 > -1) {
  8927. #ifndef SSHTEST
  8928.                 if (!sl_ssh_xfw_saved) {
  8929.                     sl_ssh_xfw = ssh_xfw;
  8930.                     sl_ssh_xfw_saved = 1;
  8931.                 }
  8932. #endif /* SSHTEST */
  8933.                 ssh_xfw = param3;
  8934.             }
  8935.         } else                          /* NET_SSH */
  8936. #endif /* SSHBUILTIN */
  8937. #ifdef TCPSOCKET
  8938.       if (net == NET_TCPB) {
  8939.             switch (protocol) {
  8940. #ifdef CK_SSL
  8941.           case NP_SSL:
  8942.                 ttnproto = protocol;
  8943.                 ssl_only_flag = 1;
  8944.                 tls_only_flag = 0;
  8945.                 break;
  8946.  
  8947.           case NP_TLS:
  8948.                 ttnproto = protocol;
  8949.                 ssl_only_flag = 0;
  8950.                 tls_only_flag = 1;
  8951.                 break;
  8952.  
  8953.           case NP_SSL_TELNET:
  8954.                 ttnproto = NP_TELNET;
  8955.                 ssl_only_flag = 1;
  8956.                 tls_only_flag = 0;
  8957.                 break;
  8958.  
  8959.           case NP_TLS_TELNET:
  8960.                 ttnproto = NP_TELNET;
  8961.                 ssl_only_flag = 0;
  8962.                 tls_only_flag = 1;
  8963.                 break;
  8964. #endif /* CK_SSL */
  8965.           case NP_NONE:
  8966.           case NP_TCPRAW:
  8967.           case NP_RLOGIN:
  8968.           case NP_K4LOGIN:
  8969.           case NP_K5LOGIN:
  8970.           case NP_EK4LOGIN:
  8971.           case NP_EK5LOGIN:
  8972.           case NP_TELNET:
  8973.           case NP_KERMIT:
  8974.           default:
  8975.                 ttnproto = protocol;
  8976. #ifdef CK_SSL
  8977.                 ssl_only_flag = 0;
  8978.                 tls_only_flag = 0;
  8979. #endif /* CK_SSL */
  8980.                 break;
  8981.             }
  8982. #ifdef CK_AUTHENTICATION
  8983.             if ((ttnproto == NP_TELNET || ttnproto == NP_KERMIT) &&
  8984.         param1 > -1) {
  8985.         if (!sl_auth_saved) {
  8986.         int x;
  8987.         for (x = 0; x < AUTHTYPLSTSZ; x++)
  8988.           sl_auth_type_user[x] = auth_type_user[x];
  8989.         sl_auth_saved = 1;
  8990.         }
  8991.         if (!sl_topt_a_s_saved) {
  8992.         sl_topt_a_su = TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION);
  8993.         sl_topt_a_s_saved = 1;
  8994.         }
  8995.         if (!sl_topt_a_c_saved) {
  8996.         sl_topt_a_cm = TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION);
  8997.         sl_topt_a_c_saved = 1;
  8998.         }
  8999.         switch (param1) {
  9000.           case AUTHTYPE_AUTO:
  9001.         auth_type_user[0] = AUTHTYPE_AUTO;
  9002.         TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_RQ;
  9003.         TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_RQ;
  9004.         break;
  9005.           case AUTHTYPE_NULL:
  9006.         auth_type_user[0] = AUTHTYPE_NULL;
  9007.         TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_RF;
  9008.         TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_RF;
  9009.         break;
  9010. #ifdef CK_SRP
  9011.           case AUTHTYPE_SRP:
  9012.         auth_type_user[0] = AUTHTYPE_SRP;
  9013.         auth_type_user[1] = AUTHTYPE_NULL;
  9014.         TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  9015.         TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  9016.         break;
  9017. #endif /* CK_SRP */
  9018. #ifdef CK_SSL
  9019.           case AUTHTYPE_SSL:
  9020.         auth_type_user[0] = AUTHTYPE_SSL;
  9021.         auth_type_user[1] = AUTHTYPE_NULL;
  9022.         TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  9023.         TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  9024.         break;
  9025. #endif /* CK_SSL */
  9026. #ifdef NT
  9027.           case AUTHTYPE_NTLM:
  9028.         auth_type_user[0] = AUTHTYPE_NTLM;
  9029.         auth_type_user[1] = AUTHTYPE_NULL;
  9030.         TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  9031.         TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  9032.         break;
  9033. #endif /* NT */
  9034. #ifdef CK_KERBEROS
  9035.           case AUTHTYPE_KERBEROS_V4:
  9036.         auth_type_user[0] = AUTHTYPE_KERBEROS_V4;
  9037.         auth_type_user[1] = AUTHTYPE_NULL;
  9038.         TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  9039.         TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  9040.         break;
  9041.  
  9042.           case AUTHTYPE_KERBEROS_V5:
  9043.         auth_type_user[0] = AUTHTYPE_KERBEROS_V5;
  9044.         auth_type_user[1] = AUTHTYPE_NULL;
  9045.         TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  9046.         TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  9047.         break;
  9048. #endif /* CK_KERBEROS */
  9049.         }
  9050.     }
  9051.     /*
  9052.        If the user requires a particular type of Kerberos connection,
  9053.        make sure we have a valid TGT.
  9054.     */
  9055.     makestr(&slmsg,"Authentication failure");
  9056.     if ((ttnproto == NP_TELNET || ttnproto == NP_KERMIT) &&
  9057.         (line[0] == '*' &&
  9058.          TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) == TN_NG_MU ||
  9059.          line[0] != '*' &&
  9060.          TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) == TN_NG_MU)
  9061.         ) {
  9062. #ifdef CK_KERBEROS
  9063.         if ( auth_type_user[0] == AUTHTYPE_KERBEROS_V4 ) {
  9064.         extern int krb4_autoget;
  9065.         if (!ck_krb4_is_installed())
  9066.           return(cx_fail(msg,
  9067.           "Required authentication method (Kerberos 4) is not installed"));
  9068. #ifdef COMMENT
  9069.         /* This code results in false failures when using */
  9070.         /* kerberos to machines in realms other than the  */
  9071.         /* default since we don't know the realm of the   */
  9072.         /* other machine until perform the reverse DNS    */
  9073.         /* lookup.                                        */
  9074.         else if (line[0] != '*' && !ck_krb4_is_tgt_valid() &&
  9075.                (!krb4_autoget ||
  9076.                 krb4_autoget && !ck_krb4_autoget_TGT(NULL))) {
  9077.             return(cx_fail(msg,
  9078.                "Kerberos 4: Ticket Getting Ticket not valid"));
  9079.         }
  9080. #endif /* COMMENT */
  9081.         } else if (auth_type_user[0] == AUTHTYPE_KERBEROS_V5) {
  9082.         extern int krb5_autoget;
  9083.         if (!ck_krb5_is_installed()) {
  9084.             return(cx_fail(msg,
  9085.        "Required authentication method (Kerberos 5) is not installed"));
  9086.         }
  9087. #ifdef COMMENT
  9088.         /* This code results in false failures when using */
  9089.         /* kerberos to machines in realms other than the  */
  9090.         /* default since we don't know the realm of the   */
  9091.         /* other machine until perform the reverse DNS    */
  9092.         /* lookup.                                        */
  9093.         else if (line[0] != '*' && !ck_krb5_is_tgt_valid() &&
  9094.                (!krb5_autoget ||
  9095.                 krb5_autoget && !ck_krb5_autoget_TGT(NULL))) {
  9096.             return(cx_fail(msg,
  9097.              "Kerberos 5: Ticket Getting Ticket not valid."));
  9098.         }
  9099. #endif /* COMMENT */
  9100.         }
  9101. #endif /* CK_KERBEROS */
  9102. #ifdef NT
  9103.         if (auth_type_user[0] == AUTHTYPE_NTLM) {
  9104.         if (!ck_ntlm_is_installed()) {
  9105.             return(cx_fail(msg,
  9106.            "Required authentication method (NTLM) is not installed"));
  9107.         } else if (line[0] != '*' && !ck_ntlm_is_valid(0)) {
  9108.             return(cx_fail(msg,"NTLM: Credentials are unavailable."));
  9109.         }
  9110.         }
  9111. #endif /* NT */
  9112. #ifdef CK_SSL
  9113.         if (auth_type_user[0] == AUTHTYPE_SSL) {
  9114.         if (!ck_ssleay_is_installed()) {
  9115.             return(cx_fail(msg,
  9116.              "Required authentication method (SSL) is not installed"));
  9117.         }
  9118.         }
  9119. #endif /* CK_SSL */
  9120. #ifdef CK_SRP
  9121.         if (auth_type_user[0] == AUTHTYPE_SRP) {
  9122.         if (!ck_srp_is_installed()) {
  9123.             return(cx_fail(msg,
  9124.              "Required authentication method (SRP) is not installed"));
  9125.         }
  9126.         }
  9127. #endif /* CK_SRP */
  9128.     }
  9129. #endif /* CK_AUTHENTICATION */
  9130. #ifdef CK_ENCRYPTION
  9131.     if ((ttnproto == NP_TELNET || ttnproto == NP_KERMIT) &&
  9132.          param2 > -1) {
  9133.         if (!sl_cx_saved) {
  9134.         sl_cx_type = cx_type;
  9135.         sl_cx_saved = 1;
  9136.         }
  9137.         if (!sl_topt_e_s_saved) {
  9138.         sl_topt_e_su = TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION);
  9139.         sl_topt_e_sm = TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION);
  9140.         sl_topt_e_s_saved = 1;
  9141.         }
  9142.         if (!sl_topt_e_c_saved) {
  9143.         sl_topt_e_cu = TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION);
  9144.         sl_topt_e_cm = TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION);
  9145.         sl_topt_e_c_saved = 1;
  9146.         }
  9147.         cx_type = param2;
  9148.         if (cx_type == CX_AUTO) {
  9149.         TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION) = TN_NG_RQ;
  9150.         TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_RQ;
  9151.         TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION) = TN_NG_RQ;
  9152.         TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_RQ;
  9153.         } else if (cx_type == CX_NONE) {
  9154.         TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION) = TN_NG_RF;
  9155.         TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_RF;
  9156.         TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION) = TN_NG_RF;
  9157.         TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_RF;
  9158.         } else {
  9159.         TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION) = TN_NG_MU;
  9160.         TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_MU;
  9161.         TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION) = TN_NG_MU;
  9162.         TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_MU;
  9163.         }
  9164.     }
  9165.     if (ttnproto == NP_EK4LOGIN || ttnproto == NP_EK5LOGIN ||
  9166.         (ttnproto == NP_TELNET || ttnproto == NP_KERMIT) &&
  9167.         ((line[0] == '*' &&
  9168.           TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION) == TN_NG_MU &&
  9169.           TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION) == TN_NG_MU) ||
  9170.          (line[0] != '*' &&
  9171.           TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION) == TN_NG_MU &&
  9172.           TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION) == TN_NG_MU))
  9173.         ) {
  9174.         if (!ck_crypt_is_installed()) {
  9175.         return(cx_fail(msg,
  9176.           "Required Encryption methods are not installed"));
  9177.         }
  9178.     }
  9179. #endif /* CK_ENCRYPTION */
  9180. #ifdef RLOGCODE
  9181. #ifdef CK_KERBEROS
  9182. #ifdef KRB4
  9183.     if (ttnproto == NP_K4LOGIN || ttnproto == NP_EK4LOGIN) {
  9184.         extern int krb4_autoget;
  9185.         char tgt[256];
  9186.         char * realm;
  9187.  
  9188.         /* We don't have the full hostname at yet so  */
  9189.         /* we do a DNS lookup before calling ttopen() */ 
  9190.  
  9191.         realm = ck_krb4_realmofhost(ckgetfqhostname(hostname));
  9192.         ckmakmsg(tgt,256,"krbtgt.",realm,"@",realm);
  9193.         if (!ck_krb4_is_installed()) {
  9194.         return(cx_fail(msg,
  9195.          "Required authentication method (Kerberos 4) is not installed"
  9196.                    ));
  9197.         } else {
  9198.         if ((ck_krb4_tkt_isvalid(tgt) <= 0) &&
  9199.             (!krb4_autoget ||
  9200.              krb4_autoget && !ck_krb4_autoget_TGT(realm))) {
  9201.             return(cx_fail(msg,
  9202.                "Kerberos 4: Ticket Getting Ticket not valid"));
  9203.         }
  9204.         }
  9205.     }
  9206. #endif /* KRB4 */
  9207. #ifdef KRB5
  9208.     if (ttnproto == NP_K5LOGIN || ttnproto == NP_EK5LOGIN ||
  9209.         ttnproto == NP_K5U2U)
  9210.     {
  9211.         extern int krb5_autoget;
  9212.         char tgt[256];
  9213.         char * realm;
  9214.  
  9215.         /* Must get full hostname before calling ttopen() */
  9216.  
  9217.         realm = ck_krb5_realmofhost(ckgetfqhostname(hostname));
  9218.         ckmakmsg(tgt,256,"krbtgt/",realm,"@",realm);
  9219.  
  9220.         if (!ck_krb5_is_installed()) {
  9221.         return(cx_fail(msg,
  9222.                  "Required authentication method (Kerberos 5) not installed"));
  9223.         } else if (!((ck_krb5_tkt_isvalid(NULL,tgt) > 0) ||
  9224.               ck_krb5_is_tgt_valid()) &&
  9225.                (!krb5_autoget ||
  9226.             krb5_autoget && !ck_krb5_autoget_TGT(realm))) {
  9227.         return(cx_fail(msg,
  9228.                "Kerberos 5: Ticket Getting Ticket not valid."));
  9229.         }
  9230.     }
  9231. #endif /* KRB5 */
  9232. #endif /* CK_KERBEROS */
  9233. #endif /* RLOGCODE */
  9234.  
  9235. #ifndef NOSPL
  9236. #ifdef RLOGCODE
  9237.     if (username) {
  9238.         if (!sl_uid_saved) {
  9239.         ckstrncpy(sl_uidbuf,uidbuf,UIDBUFLEN);
  9240.         sl_uid_saved = 1;
  9241.         }
  9242.         ckstrncpy(uidbuf,username,UIDBUFLEN);
  9243.         uidflag = 1;
  9244.     }
  9245. #endif /* RLOGCODE */
  9246. #ifdef TNCODE
  9247.     if (!sl_tn_saved) {
  9248.         sl_tn_wait = tn_wait_flg;
  9249.         sl_tn_saved = 1;
  9250.     }
  9251.     tn_wait_flg = param3;
  9252. #endif /* TNCODE */
  9253. #endif /* NOSPL */
  9254.     } /* if (net == NET_TCPB) */
  9255. #endif /* TCPSOCKET */
  9256.  
  9257. #ifndef NOSPL
  9258. #ifdef CK_SECURITY
  9259.     if (password) {
  9260.         if (password[0]) {
  9261.         ckstrncpy(pwbuf,password,PWBUFL+1);
  9262.         pwflg = 1;
  9263.         pwcrypt = 0;
  9264.         } else
  9265.         pwflg = 0;
  9266.     }
  9267. #endif /* CK_SECURITY */
  9268. #endif /* NOSPL */
  9269.  
  9270.     /* Try to open - network */
  9271.     y = ttopen(line, &_local, mdmtyp, 0 );
  9272.  
  9273. #ifndef NOHTTP
  9274.     /*  If the connection failed and we are using an HTTP Proxy
  9275.      *  and the reason for the failure was an authentication
  9276.      *  error, then we need to give the user to ability to
  9277.      *  enter a username and password, just like a browser.
  9278.      *
  9279.      *  I tried to do all of this within the netopen() call
  9280.      *  but it is much too much work.
  9281.      */
  9282.     while (y < 0 && tcp_http_proxy != NULL ) {
  9283.  
  9284.         if (tcp_http_proxy_errno == 401 ||
  9285.         tcp_http_proxy_errno == 407 ) {
  9286.         char uid[UIDBUFLEN];
  9287.         char pwd[256];
  9288.                 struct txtbox tb[2];
  9289.                 int ok;
  9290.  
  9291.                 tb[0].t_buf = uid;
  9292.                 tb[0].t_len = UIDBUFLEN;
  9293.                 tb[0].t_lbl = "Proxy Userid: ";
  9294.                 tb[0].t_dflt = NULL;
  9295.                 tb[0].t_echo = 1;
  9296.                 tb[1].t_buf = pwd;
  9297.                 tb[1].t_len = 256;
  9298.                 tb[1].t_lbl = "Proxy Passphrase: ";
  9299.                 tb[1].t_dflt = NULL;
  9300.                 tb[1].t_echo = 2;
  9301.  
  9302.                 ok = uq_mtxt("Proxy Server Authentication Required\n",
  9303.                               NULL, 2, tb);
  9304.  
  9305.         if (ok && uid[0]) {
  9306.             char * proxy_user, * proxy_pwd;
  9307.  
  9308.             proxy_user = tcp_http_proxy_user;
  9309.             proxy_pwd  = tcp_http_proxy_pwd;
  9310.  
  9311.             tcp_http_proxy_user = uid;
  9312.             tcp_http_proxy_pwd = pwd;
  9313.  
  9314.             y = ttopen(line, &_local, mdmtyp, 0);
  9315.             memset(pwd,0,sizeof(pwd));
  9316.             tcp_http_proxy_user = proxy_user;
  9317.             tcp_http_proxy_pwd = proxy_pwd;
  9318.         } else
  9319.           break;
  9320.         } else
  9321.           break;
  9322.     }
  9323. #endif /* NOHTTP */
  9324.     if (y < 0) {
  9325.         slrestor();
  9326.         makestr(&slmsg,"Network connection failure");
  9327. #ifdef VMS
  9328.         if (msg && hints && !xcmdsrc && IS_RLOGIN()) {
  9329.         makestr(&slmsg,"RLOGIN failure");
  9330.         if  (socket_errno == EACCES) {
  9331.             printf("*************************\n");
  9332.             printf(
  9333.        "Hint: RLOGIN requires privileges to open an outbound port.\n");
  9334.             printf(
  9335.             "(Use SET HINTS OFF to suppress future hints.)\n");
  9336.             printf("*************************\n");
  9337.         }
  9338.         }
  9339. #else  /* Not VMS... */
  9340.         if (errno) {
  9341.         int x;
  9342.         debug(F111,"set host line, errno","",errno);
  9343.         makestr(&slmsg,ck_errstr());
  9344.         if (msg) {
  9345. #ifdef OS2
  9346.             printf("Can't connect to %s\n",line);
  9347. #else /* OS2 */
  9348. #ifdef UNIX
  9349.             if (hints && !xcmdsrc && IS_RLOGIN()) {
  9350.             makestr(&slmsg,"RLOGIN failure");
  9351.             printf("*************************\n");
  9352.             printf(
  9353.      "Hint: RLOGIN requires privileges to open an outbound port.\n");
  9354.             printf(
  9355.      "(Use SET HINTS OFF to suppress future hints.)\n");
  9356.             printf("*************************\n");
  9357.             }
  9358. #endif /* UNIX */
  9359. #endif /* OS2 */
  9360.         } else printf("Can't connect to %s\n",line);
  9361.         } else
  9362. #endif /* VMS */
  9363.           if (msg) printf("Can't open connection to %s\n",line);
  9364.         continue;
  9365.     } else {
  9366.         success = 1;
  9367. #ifndef NODIAL
  9368.         dialsta = DIA_UNK;
  9369. #endif /* NODIAL */
  9370.         switch (net) {
  9371.           case NET_TCPA:
  9372.           case NET_TCPB:
  9373.         cxtype = CXT_TCPIP;
  9374. #ifdef COMMENT
  9375. /* This works but it messes up interactive anonymous login */
  9376. #ifndef NOXFER
  9377. #ifdef IKS_OPTION
  9378.         /* If we have connected to an Internet Kermit service */
  9379.         /* and a /USER: switch was given, then log in. */
  9380.  
  9381.         if (TELOPT_U(TELOPT_KERMIT) || TELOPT_ME(TELOPT_KERMIT)) {
  9382.             debug(F111,"cx_net IKSD /USER:",uidbuf,haveuser);
  9383.             if (haveuser /* && cx == 0 */ ) { /* /USER: given */
  9384.             char * psw = pwbuf; /* Do we have a password? */
  9385.             if (!*psw) {        /* No... */
  9386.                 if (!strcmp(uidbuf,"anonymous") ||
  9387.                 !strcmp(uidbuf,"ftp")) {
  9388.                 extern char myhost[];
  9389.                 char * u = (char *)sl_uidbuf;
  9390.                 char * h = (char *)myhost;
  9391.                 if (!*u) u = "nobody";
  9392.                 if (!*h) h = "nowhere";
  9393.                 ckmakmsg(tmpbuf,TMPBUFSIZ,u,"@",h,NULL);
  9394.                 psw = tmpbuf;
  9395.                 debug(F110,"cx_net IKSD anon",psw,0);
  9396.                 } else {
  9397.                 readpass(" Password: ",pwbuf,PWBUFL);
  9398.                 }
  9399.             }
  9400.             sstate = setgen('I',uidbuf,psw,"");
  9401.             }
  9402.         }
  9403. #endif /* IKS_OPTION */
  9404. #endif /* NOXFER */
  9405. #endif /* COMMENT */
  9406.         break;
  9407.           case NET_SSH:
  9408.         cxtype = CXT_SSH;
  9409.         duplex = 0;         /* Remote echo */
  9410.         break;
  9411.           case NET_SLAT:
  9412.         cxtype = CXT_LAT;
  9413.         break;
  9414.           case NET_SX25:
  9415.           case NET_IX25:
  9416.           case NET_HX25:
  9417.           case NET_VX25:
  9418.         cxtype = CXT_X25;
  9419.         break;
  9420.           case NET_BIOS:
  9421.         cxtype = CXT_NETBIOS;
  9422.         break;
  9423.           case NET_FILE:
  9424.           case NET_PIPE:
  9425.           case NET_CMD:
  9426.           case NET_DLL:
  9427.           case NET_PTY:
  9428.         cxtype = CXT_PIPE;
  9429.         break;
  9430.           default:
  9431.         cxtype = CXT_PIPE;
  9432.         break;
  9433.         }
  9434.         break;
  9435.     }
  9436.     } /* for-loop */
  9437.     s = line;
  9438.  
  9439.     debug(F101,"cx_net post ttopen success","",success);
  9440.     if (!success) {
  9441.         local = dfloc;                  /* Go back to normal */
  9442. #ifndef MAC
  9443.         ckstrncpy(ttname,dftty,TTNAMLEN); /* Restore default tty name */
  9444. #endif /* MAC */
  9445.         speed = ttgspd();
  9446.         network = 0;                    /* No network connection active */
  9447.         haveline = 0;
  9448.         if (mdmtyp < 0) {               /* Switching from net to async? */
  9449.             if (mdmsav > -1)            /* Restore modem type from last */
  9450.               mdmtyp = mdmsav;          /* SET MODEM command, if any. */
  9451.             else
  9452.               mdmtyp = 0;
  9453.             mdmsav = -1;
  9454.         }
  9455.         return(0);                      /* Return failure */
  9456.     }
  9457.     if (_local > -1) local = _local;    /* Opened ok, set local/remote. */
  9458.     makestr(&slmsg,NULL);
  9459.     network = (mdmtyp < 0);             /* Remember connection type. */
  9460.     ckstrncpy(ttname,s,TTNAMLEN);       /* Copy name into real place. */
  9461.     debug(F110,"cx_net ok",ttname,0);
  9462.     debug(F101,"cx_net network","",network);
  9463. #ifndef NOXFER
  9464.     if ((reliable != SET_OFF || !setreliable)) /* Assume not reliable. */
  9465.       reliable = SET_OFF;
  9466. #endif /* NOXFER */
  9467.     if (!network || istncomport())    
  9468.       speed = ttgspd();                 /* Get the current speed. */
  9469.     debug(F101,"cx_net local","",local);
  9470.     if (network) {
  9471.         debug(F101,"cx_net net","",net);
  9472. #ifndef NOXFER
  9473.         /* Force prefixing of 255 on TCP/IP connections... */
  9474.         if (net == NET_TCPB
  9475. #ifdef SSHBUILTIN
  9476.              || net == NET_SSH
  9477. #endif /* SSHBUILTIN */
  9478.              ) {
  9479.             debug(F101,"cx_net reliable A","",reliable);
  9480. #ifdef CK_SPEED
  9481.             ctlp[(unsigned)255] = 1;
  9482. #endif /* CK_SPEED */
  9483.             if ((reliable != SET_OFF || !setreliable)) {
  9484. #ifdef TN_COMPORT
  9485.                 if (istncomport()) {    /* Telnet communication port */
  9486.                     reliable = SET_OFF; /* Transport is not reliable */
  9487.                     debug(F101,"cx_net reliable istncomport()","",1);
  9488.                 } else {
  9489.                     reliable = SET_ON;  /* Transport is reliable end to end */
  9490.                     debug(F101,"cx_net reliable istncomport()","",0);
  9491.                 }
  9492. #else
  9493.                 reliable = SET_ON;      /* Transport is reliable end to end */
  9494. #endif /* ifdef TN_COMPORT */
  9495.             }
  9496.             debug(F101,"cx_net reliable B","",reliable);
  9497.         } else if (net == NET_SX25 ||
  9498.                    net == NET_VX25 ||
  9499.                    net == NET_IX25 ||
  9500.                    net == NET_HX25) {
  9501.             duplex = 1;                 /* Local echo for X.25 */
  9502.             if (reliable != SET_OFF || !setreliable)
  9503.               reliable = SET_ON;        /* Transport is reliable end to end */
  9504.         }
  9505. #endif /* NOXFER */
  9506.     }
  9507. #ifndef NOXFER
  9508.     debug(F101,"cx_net reliable","",reliable);
  9509. #endif /* NOXFER */
  9510. #ifdef OS2
  9511.     if (mdmtyp <= 0)                    /* Network or Direct Connection */
  9512.       DialerSend(OPT_KERMIT_CONNECT, 0);
  9513. #endif /* OS2 */
  9514.  
  9515.   xcx_net:
  9516.  
  9517.     setflow();                          /* Set appropriate flow control */
  9518.  
  9519.     haveline = 1;
  9520. #ifdef CKLOGDIAL
  9521.     dolognet();
  9522. #endif /* CKLOGDIAL */
  9523.  
  9524. #ifndef NOSPL
  9525.     if (local) {
  9526.         if (nmac) {                     /* Any macros defined? */
  9527.             int k;                      /* Yes */
  9528.             k = mlook(mactab,"on_open",nmac);   /* Look this up */
  9529.             if (k >= 0) {                       /* If found, */
  9530.                 if (dodo(k,ttname,0) > -1)      /* set it up, */
  9531.                   parser(1);                    /* and execute it */
  9532.             }
  9533.         }
  9534.     }
  9535. #endif /* NOSPL */
  9536.  
  9537.     if (local && (cx || sx)) {          /* /CONNECT or /SERVER switch given */
  9538.         if (cx) {                       /* /CONNECT */
  9539.         if (!gui) {
  9540.         /* Command was confirmed so we can pre-pop command level.  */
  9541.         /* This is so CONNECT module won't think we're executing a */
  9542.         /* script if CONNECT was the final command in the script.  */
  9543.         if (cmdlvl > 0)
  9544.           prepop();
  9545.         }
  9546. #ifndef NODIAL
  9547.             dialsta = DIA_UNK;
  9548. #endif /* NODIAL */
  9549. #ifdef LOCUS
  9550.             if (autolocus) {
  9551.         setlocus(1,1);
  9552.             }
  9553. #endif /* LOCUS */
  9554.             success = doconect(0, cmdlvl == 0 ? 1 : 0);
  9555.             if (ttchk() < 0)
  9556.               dologend();
  9557.         debug(F101,"cx_net post doconect success","",success);
  9558.             return(success);
  9559. #ifndef NOXFER
  9560.         } else if (sx) {                /* /SERVER */
  9561.             sstate = 'x';
  9562. #ifdef MAC
  9563.             what = W_RECV;
  9564.             scrcreate();
  9565. #endif /* MAC */
  9566.             if (local) displa = 1;
  9567. #ifdef AMIGA
  9568.             reqoff();                   /* No DOS requestors while server */
  9569. #endif /* AMIGA */
  9570. #endif /* NOXFER */
  9571.         }
  9572.     }
  9573. #ifndef NODIAL
  9574.     dialsta = DIA_UNK;
  9575. #endif /* NODIAL */
  9576. #ifdef LOCUS
  9577.     if (autolocus) {
  9578.         setlocus(1,1);
  9579.     }
  9580. #endif /* LOCUS */
  9581.     return(success = 1);
  9582. }
  9583. #endif /* NETCONN */
  9584.  
  9585. /* c x _ s e r i a l  --  Make a serial connection */
  9586.  
  9587. /*
  9588.   Call with:
  9589.     device  = string pointer to device name.
  9590.     cx      = 1 to automatically enter Connect mode, 0 otherwise.
  9591.     sx      = 1 to automatically enter Server mode, 0 otherwise.
  9592.     shr     = 1 if device should be opened in shareable mode, 0 otherwise.
  9593.     flag    = if no dev name given: 1 = close current connection, 0 = resume.
  9594.     gui     = 1 if called from GUI dialog, 0 otherwise.
  9595.   Returns:
  9596.     1 on success
  9597.     0 on failure and no message printed, slmsg set to failure message.
  9598.    -9 on failure and message printed, ditto.
  9599. */
  9600.  
  9601. /* these are bit flags */
  9602. #define CX_TAPI 1
  9603. #define CX_PPP  2
  9604. #define CX_SLIP 4
  9605.  
  9606. int
  9607. #ifdef CK_ANSIC
  9608. cx_serial(char *device, 
  9609.           int cx, int sx, int shr, int flag, int gui, int special)
  9610. #else /* CK_ANSIC */
  9611. cx_serial(device, cx, sx, shr, flag, gui, special)
  9612.     char * device; int cx, sx, shr, flag, gui, special; 
  9613. #endif /* CK_ANSIC */
  9614. /* cx_serial */ {
  9615.     int i, n, x, y, msg;
  9616.     int _local = -1;
  9617.     char *s;
  9618.  
  9619.     debug(F110,"cx_serial device",device,0);
  9620.     s = device;
  9621.     msg = (gui == 0) && msgflg;        /* Whether to print messages */
  9622.     success = 0;
  9623.  
  9624. #ifndef NODIAL
  9625.     dialsta = DIA_UNK;
  9626. #endif /* NODIAL */
  9627.     debug(F101,"cx_serial mdmtyp","",mdmtyp);
  9628.     if (clskconnx(1) < 0)        /* Close the Kermit connection */
  9629.       return(success = 0);
  9630.     if (*s) {                /* They gave a device name */
  9631.     _local = -1;            /* Let ttopen decide about it */
  9632.     } else {                /* They just said "set line" */
  9633.     s = dftty;            /* so go back to normal tty */
  9634.     _local = dfloc;            /* and mode. */
  9635.     }
  9636. #ifdef VMS
  9637.     {
  9638.     extern int ok_to_share;
  9639.     ok_to_share = shr;
  9640.     }
  9641. #endif /* VMS */
  9642.  
  9643. #ifdef OS2                              /* Must wait until after ttclos() */
  9644. #ifdef NT                               /* to change these settings       */
  9645. #ifdef CK_TAPI
  9646.     tttapi = special & CX_TAPI;
  9647. #endif /* CK_TAPI */
  9648. #else
  9649.     ttslip = special & CX_SLIP;
  9650.     ttppp  = special & CX_PPP;
  9651. #endif /* NT */
  9652.     ttshare = shr;            /* Shareable device ? */
  9653.     debug(F110,"OS2 SET PORT final s",s,"");
  9654. #endif /* OS2 */
  9655.  
  9656.     /* Open the new line */        
  9657.     if ((y = ttopen(s,&_local,mdmtyp,cdtimo)) > -1) {
  9658.     cxtype = (mdmtyp > 0) ? CXT_MODEM : CXT_DIRECT;
  9659. #ifndef NODIAL
  9660.     dialsta = DIA_UNK;
  9661. #endif /* NODIAL */
  9662.     success = 1;
  9663. #ifdef CK_TAPI
  9664.     /* if the line is a tapi device, then we need to auto-execute */
  9665.     /* SET MODEM TYPE TAPI - which we do the equivalent of here.  */
  9666.     if (tttapi) {
  9667.         extern int usermdm;
  9668.         usermdm = 0;
  9669.         initmdm(38);        /* From ckudia.c n_TAPI == 38 */
  9670.     }
  9671. #endif /* CK_TAPI */
  9672.     } else {                /* Failed */
  9673. #ifdef OS2ONLY
  9674.     if (!strcmp(s,dftty))   /* Do not generate an error with dftty */
  9675.       ;
  9676.     else if (y == -6 && ttslip) {
  9677.         makestr(&slmsg,"Can't access SLIP driver");
  9678.         if (msg) printf("?%s\n",slmsg);
  9679.     } else if (y == -6 && ttppp) {
  9680.         makestr(&slmsg,"Can't access PPP driver");
  9681.         if (msg) printf("?%s\n",slmsg);
  9682.     } else
  9683. #endif /* OS2ONLY */
  9684.       if (y == -2) {
  9685.           makestr(&slmsg,"Timed out - no carrier");
  9686.           if (msg) {
  9687.           printf("?%s\n",slmsg);
  9688.           if (hints) {
  9689.               printf("\n*************************\n");
  9690.               printf(
  9691.                "HINT (Use SET HINTS OFF to suppress future hints):\n");
  9692.               printf(
  9693.               "Try SET CARRIER OFF and SET LINE again, or else\n");
  9694.               printf("SET MODEM, SET LINE, and then DIAL.\n");
  9695.               printf("*************************\n\n");
  9696.           }
  9697.           }
  9698.       } else if (y == -3) {
  9699.           makestr(&slmsg,"Access to lock denied");
  9700.           if (msg) {
  9701. #ifdef UNIX
  9702.           printf(
  9703.            "Sorry, write access to UUCP lockfile directory denied.\n");
  9704. #ifndef NOHINTS
  9705.           if (hints) {
  9706.               printf("\n*************************\n");
  9707.               printf(
  9708.                "HINT (Use SET HINTS OFF to suppress future hints):\n");
  9709.               printf(
  9710.       "Please read the installation instructions file, %sckuins.txt,\n",
  9711.                          k_info_dir ? k_info_dir : ""
  9712.                              );
  9713.               printf(
  9714.       "or the UNIX appendix of the manual, \"Using C-Kermit\"\n"
  9715.                              );
  9716.               printf(
  9717.           "or visit http://www.columbia.edu/kermit/ckuins.html \n"
  9718.                              );
  9719.               printf("*************************\n\n");
  9720.           }
  9721. #endif /* NOHINTS */
  9722. #else
  9723.           printf("Sorry, access to lock denied: %s\n",s);
  9724. #endif /* UNIX */
  9725.           }
  9726.       } else if (y == -4) {
  9727.           makestr(&slmsg,"Access to device denied");
  9728.           if (msg) {
  9729.           printf("Sorry, access to device denied: %s\n",s);
  9730. #ifdef UNIX
  9731. #ifndef NOHINTS
  9732.           if (hints) {
  9733.               printf("\n*************************\n");
  9734.               printf(
  9735.               "HINT (Use SET HINTS OFF to suppress future hints):\n");
  9736.               printf(
  9737.         "Please read the installation instructions file, %sckuins.txt,\n",
  9738.                              k_info_dir ? k_info_dir : ""
  9739.                              );
  9740.               printf(
  9741.         "or the UNIX appendix of the manual, \"Using C-Kermit\".\n"
  9742.                              );
  9743.               printf("*************************\n\n");
  9744.           }
  9745. #endif /* NOHINTS */
  9746. #endif /* UNIX */
  9747.           }
  9748.       } else if (y == -5) {
  9749.           makestr(&slmsg,"Device is in use or unavailable");
  9750.           if (msg)
  9751. #ifdef VMS
  9752.         printf(
  9753.           "Sorry, device is in use or otherwise unavailable: %s\n",s);
  9754. #else
  9755.           printf("Sorry, device is in use: %s\n",s);
  9756. #endif /* VMS */
  9757.       } else {            /* Other error. */
  9758.           makestr(&slmsg,"Device open failed");
  9759.           if (
  9760. #ifdef VMS
  9761.           1
  9762. #else
  9763.           errno
  9764. #endif /* VMS */
  9765.           ) {
  9766.           int x;        /* Find a safe, long buffer */
  9767.           makestr(&slmsg,ck_errstr());
  9768. #ifndef VMS
  9769.           debug(F111,"cx_serial serial errno",slmsg,errno);
  9770. #endif /* VMS */
  9771.           if (msg)
  9772.             printf("Connection to %s failed: %s\n",s,slmsg);
  9773.           } else if (msg)
  9774.         printf("Sorry, can't open connection: %s\n",s);
  9775.       }
  9776.     }
  9777.     network = 0;            /* No network connection active */
  9778.     speed = ttgspd();
  9779.     if (!success) {
  9780.         local = dfloc;                  /* Go back to normal */
  9781. #ifndef MAC
  9782.         ckstrncpy(ttname,dftty,TTNAMLEN); /* Restore default tty name */
  9783. #endif /* MAC */
  9784.         haveline = 0;
  9785.         if (mdmtyp < 0) {               /* Switching from net to async? */
  9786.             if (mdmsav > -1)            /* Restore modem type from last */
  9787.               mdmtyp = mdmsav;          /* SET MODEM command, if any. */
  9788.             else
  9789.               mdmtyp = 0;
  9790.             mdmsav = -1;
  9791.         }
  9792.         return(msg ? -9 : 0);        /* Return failure */
  9793.     }
  9794.     if (_local > -1)
  9795.       local = _local;            /* Opened ok, set local/remote. */
  9796.     makestr(&slmsg,NULL);        /* Erase SET LINE message */
  9797.     ckstrncpy(ttname,s,TTNAMLEN);       /* Copy name into real place. */
  9798.     debug(F110,"cx_serial ok",ttname,0);
  9799. #ifndef NOXFER
  9800.     if ((reliable != SET_OFF || !setreliable)) /* Assume not reliable. */
  9801.       reliable = SET_OFF;
  9802. #endif /* NOXFER */
  9803.  
  9804.   xcx_serial:
  9805.     setflow();                          /* Set appropriate flow control */
  9806.     haveline = 1;
  9807. #ifdef CKLOGDIAL
  9808.       dologline();
  9809. #endif /* CKLOGDIAL */
  9810.  
  9811. #ifndef NOSPL
  9812.     if (local) {
  9813.         if (nmac) {                     /* Any macros defined? */
  9814.             int k;                      /* Yes */
  9815.             k = mlook(mactab,"on_open",nmac);   /* Look this up */
  9816.             if (k >= 0) {                       /* If found, */
  9817.                 if (dodo(k,ttname,0) > -1)      /* set it up, */
  9818.                   parser(1);                    /* and execute it */
  9819.             }
  9820.         }
  9821.     }
  9822. #endif /* NOSPL */
  9823.  
  9824.     if (local && (cx || sx)) {          /* /CONNECT or /SERVER switch given */
  9825.         extern int carrier;
  9826.         if (carrier != CAR_OFF) {    /* Looking for carrier? */
  9827.             /* Open() turns on DTR -- wait up to a second for CD to come up */
  9828.             int i, x;
  9829.             for (i = 0; i < 10; i++) {  /* WAIT 1 CD... */
  9830.                 x = ttgmdm();
  9831.                 if (x < 0 || x & BM_DCD)
  9832.                   break;
  9833.                 msleep(100);
  9834.             }
  9835.         }
  9836.         if (cx) {                       /* /CONNECT */
  9837.             /* Command was confirmed so we can pre-pop command level. */
  9838.             /* This is so CONNECT module won't think we're executing a */
  9839.             /* script if CONNECT was the final command in the script. */
  9840.  
  9841.             if (cmdlvl > 0)
  9842.               prepop();
  9843. #ifndef NODIAL
  9844.             dialsta = DIA_UNK;
  9845. #endif /* NODIAL */
  9846. #ifdef LOCUS
  9847.             if (autolocus) {
  9848.                 setlocus(1,1);
  9849.             }
  9850. #endif /* LOCUS */
  9851.             success = doconect(0, cmdlvl == 0 ? 1 : 0);
  9852.             if (ttchk() < 0)
  9853.               dologend();
  9854.             return(success);
  9855. #ifndef NOXFER
  9856.         } else if (sx) {                /* /SERVER */
  9857.             sstate = 'x';
  9858. #ifdef MAC
  9859.             what = W_RECV;
  9860.             scrcreate();
  9861. #endif /* MAC */
  9862.             if (local) displa = 1;
  9863. #ifdef AMIGA
  9864.             reqoff();                   /* No DOS requestors while server */
  9865. #endif /* AMIGA */
  9866. #endif /* NOXFER */
  9867.         }
  9868.     }
  9869. #ifndef NODIAL
  9870.     dialsta = DIA_UNK;
  9871. #endif /* NODIAL */
  9872. #ifdef LOCUS
  9873.     if (autolocus) {
  9874.         setlocus(1,1);
  9875.     }
  9876. #endif /* LOCUS */
  9877.     return(success = 1);
  9878. }
  9879.  
  9880.  
  9881. /* S E T L I N -- parse name of and then open communication device. */
  9882. /*
  9883.   Call with:
  9884.     xx == XYLINE for a serial (tty) line, XYHOST for a network host,
  9885.     zz == 0 means if user doesn't give a device name, continue current
  9886.             active connection (if any);
  9887.     zz != 0 means if user doesn't give a device name, then close the
  9888.             current connection and restore the default communication device.
  9889.     fc == 0 to just make the connection, 1 to also CONNECT (e.g. "telnet").
  9890. */
  9891. int
  9892. setlin(xx, zz, fc) 
  9893.     int xx, zz, fc; 
  9894. {
  9895.     extern char pwbuf[], * g_pswd;
  9896.     extern int pwflg, pwcrypt, g_pflg, g_pcpt, nolocal;
  9897.     int wait;
  9898.     /* int tn_wait_sv; */
  9899.     int mynet;
  9900.     int _local = -1;
  9901.     int c, i, haveswitch = 0;
  9902.     int haveuser = 0;
  9903.     int getval = 0;
  9904.     int wild = 0;                       /* Filespec has wildcards */
  9905.     int cx = 0;                         /* Connect after */
  9906.     int sx = 0;                         /* Become server after */
  9907.     int a_type = -1;                    /* Authentication type */
  9908.     int e_type = -1;                    /* Telnet /ENCRYPT type */
  9909. #ifdef CK_ENCRYPTION
  9910.     int encrypt = 0;                    /* Encrypted? */
  9911. #endif /* CK_ENCRYPTION */
  9912.     int shr = 0;                        /* Share serial device */
  9913.     int confirmed = 0;                  /* Command has been entered */
  9914.     struct FDB sw, tx, nx;
  9915. #ifdef OS2
  9916.     struct FDB fl;
  9917. #endif /* OS2 */
  9918.  
  9919.     char * ss;
  9920. #ifdef TCPSOCKET
  9921.     int rawflg = 0;
  9922. #endif /* TCPSOCKET */
  9923.  
  9924.     char srvbuf[SRVBUFSIZ+1];
  9925.  
  9926. #ifdef OS2
  9927. #ifdef NT
  9928.     int xxtapi = 0;
  9929. #else
  9930.     int xxslip = 0, xxppp = 0;
  9931. #endif /* NT */
  9932. #endif /* OS2 */
  9933.  
  9934.     int dossh = 0;
  9935.  
  9936.     debug(F101,"setlin fc","",fc);
  9937.     debug(F101,"setlin zz","",zz);
  9938.     debug(F101,"setlin xx","",xx);
  9939.  
  9940. #ifdef SSHCMD
  9941.     if (xx == XXSSH) {                  /* SSH becomes PTY SSH ... */
  9942.         dossh = 1;
  9943.         xx = XYHOST;
  9944.     }
  9945. #endif /* SSHCMD */
  9946.  
  9947. #ifdef TNCODE
  9948.     /* tn_wait_sv = tn_wait_flg; */
  9949.     wait = tn_wait_flg;
  9950. #else
  9951.     /* tn_wait_sv = 0; */
  9952.     wait = 0;
  9953. #endif /* TNCODE */
  9954.  
  9955.     mynet = nettype;
  9956.  
  9957.     if (nolocal) {
  9958.         makestr(&slmsg,"Making connections is disabled");
  9959.         printf("?Sorry, making connections is disabled\n");
  9960.         return(-9);
  9961.     }
  9962.     if (netsave > -1)
  9963.       nettype = netsave;
  9964.  
  9965.     if (fc != 0 || zz == 0)             /* Preset /CONNECT switch */
  9966.       cx = 1;
  9967.  
  9968.     debug(F101,"setlin cx","",cx);
  9969.  
  9970.     *srvbuf = NUL;
  9971.  
  9972.     line[0] = NUL;
  9973.     s = line;
  9974.  
  9975. #ifdef NETCONN
  9976. #ifdef CK_SECURITY
  9977.     if (tmpstring)
  9978.         makestr(&tmpstring,NULL);
  9979. #endif /* CK_SECURITY */
  9980.     if (tmpusrid)
  9981.         makestr(&tmpusrid,NULL);
  9982. #endif /* NETCONN */
  9983.  
  9984.     autoflow = 1;                       /* Enable automatic flow setting */
  9985.  
  9986.     if (xx == XYHOST) {                 /* SET HOST <hostname> */
  9987. #ifndef NETCONN
  9988.         makestr(&slmsg,"Network connections not supported");
  9989.         printf("?%s\n",slmsg);
  9990.         return(-9);
  9991. #else /* NETCONN */
  9992. #ifndef NOPUSH
  9993.         if ((mynet == NET_CMD || mynet == NET_PTY || dossh) && nopush) {
  9994.             makestr(&slmsg,"Access to external commands is disabled");
  9995.             printf("?Sorry, access to external commands is disabled\n");
  9996.             return(-9);
  9997.         }
  9998. #endif /* NOPUSH */
  9999.  
  10000. #ifdef SSHCMD
  10001.         if (dossh) {                    /* SSH connection via pty */
  10002.             int k;
  10003.             k = ckstrncpy(line, sshcmd ? sshcmd : defsshcmd, LINBUFSIZ);
  10004.             debug(F111,"setlin sshcmd 1",line,k);
  10005.             if ((x = cmtxt("Optional switches and hostname","",&s,xxstring))<0)
  10006.               return(x);
  10007.             if (!*s) {
  10008.                 printf("?SSH to where?\n");
  10009.                 return(-9);
  10010.             }
  10011.             if (k < LINBUFSIZ) {
  10012.                 line[k++] = SP;
  10013.                 line[k] = NUL;
  10014.                 debug(F111,"setlin sshcmd 2",line,k);
  10015.             } if (k < LINBUFSIZ) {
  10016.                 ckstrncpy(&line[k],s,LINBUFSIZ-k);
  10017.                 debug(F111,"setlin sshcmd 3",line,k);
  10018.             } else {
  10019.                 printf("?Too long\n");
  10020.                 return(-9);
  10021.             }
  10022.         x = cx_net( NET_PTY,                /* network type */
  10023.                         0,                      /* protocol (not used) */
  10024.                         line,                   /* host */
  10025.                         NULL,                   /* service (not used) */
  10026.                         NULL,                   /* username (not used) */
  10027.                         NULL,                   /* password (not used) */
  10028.                         NULL,                   /* command (not used) */
  10029.                         -1,-1,-1,               /* params 1-3 (not used) */
  10030.                         1,                      /* connect immediately */
  10031.                         sx,                     /* server? */
  10032.                         zz,                     /* close current? */
  10033.                         0);                     /* not gui */
  10034.         debug(F111,"setlin cx_net",line,x);
  10035.         return(x);
  10036.         }
  10037. #endif /* SSHCMD */
  10038.  
  10039. /*
  10040.   Here we parse optional switches and then the hostname or whatever,
  10041.   which depends on the network type.  The tricky part is, the network type
  10042.   can be set by a switch.
  10043. */
  10044. #ifndef NOSPL
  10045.         makestr(&g_pswd,pwbuf);         /* Save global pwbuf */
  10046.         g_pflg = pwflg;                 /* and flag */
  10047.         g_pcpt = pwcrypt;
  10048. #endif /* NOSPL */
  10049.  
  10050.         confirmed = 0;
  10051.         haveswitch = 0;
  10052. #ifdef NETFILE
  10053.         if (mynet != NET_FILE) {
  10054. #endif /* NETFILE */
  10055.             ss = (mynet == NET_CMD || mynet == NET_PTY) ?
  10056.               "Command, or switch" :
  10057.                 (mynet == NET_TCPA || mynet == NET_TCPB
  10058.                   || mynet == NET_SSH) ?
  10059.                   "Hostname, ip-address, or switch" :
  10060.                     "Host or switch";
  10061.             if (fc) {
  10062.                 if (mynet == NET_TCPB &&
  10063.                     (ttnproto == NP_TELNET || ttnproto == NP_KERMIT)) {
  10064.                     if (nshteltab) {
  10065.                         haveswitch++;
  10066.                         cmfdbi(&sw,_CMKEY,ss,"","",nshteltab,4,xxstring,
  10067.                              shteltab,&nx);
  10068.                     }
  10069.                 }
  10070. #ifdef RLOGCODE
  10071.                 else if (mynet == NET_TCPB && ttnproto == NP_RLOGIN) {
  10072.                     if (nshrlgtab) {
  10073.                         haveswitch++;
  10074.                         cmfdbi(&sw,_CMKEY,ss,"","",nshrlgtab,4,xxstring,
  10075.                                shrlgtab,&nx);
  10076.                     }
  10077.                 }
  10078. #endif /* RLOGCODE */
  10079.             } else {
  10080.                 haveswitch++;
  10081.                 cmfdbi(&sw,_CMKEY,ss,"","",nshtab,4,xxstring,shtab,&nx);
  10082.             }
  10083. #ifdef NETFILE
  10084.         }
  10085. #endif /* NETFILE */
  10086.         if (mynet == NET_TCPB || mynet == NET_SLAT ||
  10087.         mynet == NET_SSH  || mynet == NET_DEC) {
  10088.             cmfdbi(&nx,_CMFLD,"Host","","",0,0,xxstring,NULL,NULL);
  10089. #ifdef NETFILE
  10090.         } else if (mynet == NET_FILE) {
  10091.             cmfdbi(&nx,_CMIFI,"Filename","","",0,0,xxstring,NULL,NULL);
  10092. #endif /* NETFILE */
  10093. #ifdef PTYORPIPE
  10094.         } else if (mynet == NET_CMD || mynet == NET_PTY) {
  10095.             cmfdbi(&nx,_CMTXT,"Command","","",0,0,xxstring,NULL,NULL);
  10096. #endif /* PTYORPIPE */
  10097.         } else {
  10098.             cmfdbi(&nx,_CMTXT,"Host","","",0,0,xxstring,NULL,NULL);
  10099.         }
  10100.         while (1) {
  10101.             x = cmfdb(haveswitch ? &sw : &nx);
  10102.             debug(F101,"setlin cmfdb","",x);
  10103.             if (x < 0)
  10104.               if (x != -3)
  10105.                 return(x);
  10106.             if (x == -3) {
  10107.                 if ((x = cmcfm()) < 0) {
  10108.                     return(x);
  10109.                 } else {
  10110.                     confirmed = 1;
  10111.                     break;
  10112.                 }
  10113.             }
  10114.             if (cmresult.fcode != _CMKEY) {    /* Not a switch */
  10115.                 ckstrncpy(line,cmresult.sresult,LINBUFSIZ); /* Save the data */
  10116.                 s = line;                      /* that was parsed... */
  10117.                 if (cmresult.fcode == _CMIFI) {
  10118.                     wild = cmresult.nresult;
  10119.                 } else if (cmresult.fcode == _CMTXT) {
  10120.                     confirmed = 1;
  10121.                 }
  10122.                 break;                  /* and break out of this loop */
  10123.             }
  10124.             c = cmgbrk();               /* Have switch - get break character */
  10125.             getval = (c == ':' || c == '='); /* Must parse an agument? */
  10126.             if (getval && !(cmresult.kflags & CM_ARG)) {
  10127.                 printf("?This switch does not take arguments\n");
  10128.                 return(-9);
  10129.             }
  10130.             if (!getval && (cmgkwflgs() & CM_ARG)) {
  10131.                 printf("?This switch requires an argument\n");
  10132.                 return(-9);
  10133.             }
  10134.             switch (cmresult.nresult) { /* It's a switch.. */
  10135.               case SL_CNX:              /* /CONNECT */
  10136.                 cx = 1;
  10137.                 sx = 0;
  10138.                 break;
  10139.               case SL_SRV:              /* /SERVER */
  10140.                 cx = 0;
  10141.                 sx = 1;
  10142.                 break;
  10143. #ifdef NETCMD
  10144.               case SL_CMD:              /* /COMMAND */
  10145.                 netsave = mynet;
  10146.                 mynet = NET_CMD;
  10147.                 break;
  10148. #endif /* NETCMD */
  10149. #ifdef NETPTY
  10150.               case SL_PTY:              /* /PTY */
  10151.                 netsave = mynet;
  10152.                 mynet = NET_PTY;
  10153.                 break;
  10154. #endif /* NETPTY */
  10155.               case SL_NET:              /* /NETWORK-TYPE */
  10156.                 if ((x = cmkey(netcmd,nnets,"","",xxstring)) < 0)
  10157.                   return(x);
  10158.                 mynet = x;
  10159.                 break;
  10160.  
  10161. #ifdef CK_SECURITY
  10162.               case SL_PSW:              /* /PASSWORD: */
  10163.                 if (!getval)
  10164.                   break;
  10165.                 debok = 0;
  10166.                 if ((x = cmfld("Password","",&s,xxstring)) < 0) {
  10167.                     if (x == -3) {
  10168.                         makestr(&tmpstring,"");
  10169.                     } else {
  10170.                         return(x);
  10171.                     }
  10172.                 } else {
  10173.                     s = brstrip(s);
  10174.                     if ((x = (int)strlen(s)) > PWBUFL) {
  10175.                         makestr(&slmsg,"Internal error");
  10176.                         printf("?Sorry, too long - max = %d\n",PWBUFL);
  10177.                         return(-9);
  10178.                     }
  10179.                     makestr(&tmpstring,s);
  10180.                 }
  10181.                 break;
  10182. #endif /* CK_SECURITY */
  10183.  
  10184.               case SL_UID:              /* /USERID: */
  10185.                 if (!getval)
  10186.                   break;
  10187.                 if ((x = cmfld("Userid","",&s,xxstring)) < 0) {
  10188.                     if (x == -3) {
  10189.                         makestr(&tmpusrid,"");
  10190.                     } else {
  10191.                         return(x);
  10192.                     }
  10193.                 } else {
  10194.                     s = brstrip(s);
  10195.                     if ((x = (int)strlen(s)) > 63) {
  10196.                         makestr(&slmsg,"Internal error");
  10197.                         printf("?Sorry, too long - max = %d\n",63);
  10198.                         return(-9);
  10199.                     }
  10200.                     makestr(&tmpusrid,s);
  10201.                     haveuser = 1;
  10202.                 }
  10203.                 break;
  10204.  
  10205. #ifdef CK_AUTHENTICATION
  10206. #ifdef CK_SRP
  10207.               case SL_SRP:
  10208.                 a_type = AUTHTYPE_SRP;
  10209.                 break;
  10210. #endif /* CK_SRP */
  10211. #ifdef CK_SSL
  10212.               case SL_SSL:
  10213.                 a_type = AUTHTYPE_SSL;
  10214.                 break;
  10215. #endif /* CK_SSL */
  10216. #ifdef NT
  10217.               case SL_NTLM:
  10218.                 a_type = AUTHTYPE_NTLM;
  10219.                 break;
  10220. #endif /* NT */
  10221. #ifdef CK_KERBEROS
  10222.               case SL_KRB4:
  10223.                 a_type = AUTHTYPE_KERBEROS_V4;
  10224.                 if (ttnproto == NP_RLOGIN)
  10225.                   ttnproto =
  10226. #ifdef CK_ENCRYPTION
  10227.                     encrypt ? NP_EK4LOGIN :
  10228. #endif /* CK_ENCRYPTION */
  10229.                       NP_K4LOGIN;
  10230.                 else if (ttnproto == NP_K5LOGIN)
  10231.                   ttnproto = NP_K4LOGIN;
  10232. #ifdef CK_ENCRYPTION
  10233.                 else if (ttnproto == NP_EK5LOGIN)
  10234.                   ttnproto = NP_EK4LOGIN;
  10235. #endif /* CK_ENCRYPTION */
  10236.                 break;
  10237.               case SL_KRB5:
  10238.                 a_type = AUTHTYPE_KERBEROS_V5;
  10239.                 if (ttnproto == NP_RLOGIN)
  10240.                   ttnproto =
  10241. #ifdef CK_ENCRYPTION
  10242.                     encrypt ? NP_EK5LOGIN :
  10243. #endif /* CK_ENCRYPTION */
  10244.                       NP_K5LOGIN;
  10245.                 else if (ttnproto == NP_K4LOGIN)
  10246.                   ttnproto = NP_K5LOGIN;
  10247. #ifdef CK_ENCRYPTION
  10248.                 else if (ttnproto == NP_EK4LOGIN)
  10249.                   ttnproto = NP_EK5LOGIN;
  10250. #endif /* CK_ENCRYPTION */
  10251.                 break;
  10252. #endif /* CK_KERBEROS */
  10253.               case SL_AUTH: {
  10254.                   extern struct keytab autyptab[];
  10255.                   extern int nautyp;
  10256.                   if ((x = cmkey(autyptab,nautyp,"type of authentication",
  10257.                                  "automatic",xxstring)) < 0)
  10258.                     return(x);
  10259.                   a_type = x;
  10260.                   break;
  10261.               }
  10262. #endif /* CK_AUTHENTICATION */
  10263. #ifdef CK_ENCRYPTION
  10264.               case SL_ENC:
  10265.                 switch (ttnproto) {
  10266.                   case NP_K4LOGIN:
  10267.                     ttnproto = NP_EK4LOGIN;
  10268.                     encrypt = 1;
  10269.                     break;
  10270.                   case NP_K5LOGIN:
  10271.                     ttnproto = NP_EK5LOGIN;
  10272.                     encrypt = 1;
  10273.                     break;
  10274.                   case NP_KERMIT:
  10275.                   case NP_TELNET: {
  10276.                       static struct keytab * tnetbl = NULL;
  10277.                       static int ntnetbl = 0;
  10278.                       x = ck_get_crypt_table(&tnetbl,&ntnetbl);
  10279.                       debug(F101,"ck_get_crypt_table x","",x);
  10280.                       debug(F101,"ck_get_crypt_table n","",ntnetbl);
  10281.                       if (x < 1 || !tnetbl || ntnetbl < 1) /* Didn't get it */
  10282.                         x = 0;
  10283.                       if (!x) {
  10284.                           makestr(&slmsg,"Internal error");
  10285.                           printf("?Oops, types not loaded\n");
  10286.                           return(-9);
  10287.                       }
  10288.                       if ((x = cmkey(tnetbl,ntnetbl,"type of encryption",
  10289.                                      "automatic",xxstring)) < 0)
  10290.                         return(x);
  10291.                       e_type = x;
  10292.                       break;
  10293.                   }
  10294.                 }
  10295.                 break;
  10296. #endif /* CK_ENCRYPTION */
  10297.               case SL_WAIT:
  10298.                 wait = 1;
  10299.                 break;
  10300.               case SL_NOWAIT:
  10301.                 wait = 0;
  10302.                 break;
  10303.             }
  10304.         }
  10305.  
  10306. #ifdef NETFILE
  10307.         if (mynet == NET_FILE) {        /* Parsed by cmifi() */
  10308.         if ((x = cmcfm()) < 0)    /* Needs confirmation */
  10309.           return(x);
  10310.         x = cx_net(mynet,        /* nettype */
  10311.                0,        /* protocol (not used) */
  10312.                line,        /* host */
  10313.                "",        /* port */
  10314.                NULL,        /* alternate username */
  10315.                NULL,        /* password */
  10316.                NULL,        /* command to execute */
  10317.                0,        /* param1 */
  10318.                0,        /* param2 */
  10319.                0,        /* param3 */
  10320.                cx,        /* enter CONNECT mode */
  10321.                sx,        /* enter SERVER mode */
  10322.                zz,        /* close connection if open */
  10323.                0        /* gui */
  10324.                );
  10325.         }
  10326. #endif /* NETFILE */
  10327.  
  10328. #ifdef NETCMD
  10329.         if (mynet == NET_CMD || mynet == NET_PTY) {
  10330.             char *p = NULL;
  10331.             if (!confirmed) {
  10332.                 if ((x = cmtxt("Rest of command","",&s,xxstring)) < 0)
  10333.                   return(x);
  10334.                 if (*s) {
  10335.                     strncat(line," ",LINBUFSIZ);
  10336.                     strncat(line,s,LINBUFSIZ);
  10337.                 }
  10338.                 s = line;
  10339.             }
  10340.             /* s == line - so we must protect the line buffer */
  10341.             s = brstrip(s);
  10342.             makestr(&p,s);
  10343.             ckstrncpy(line,p,LINBUFSIZ);
  10344.             makestr(&p,NULL);
  10345.  
  10346.             x = cx_net( mynet,                  /* nettype */
  10347.                         0,                      /* protocol (not used) */
  10348.                         line,                   /* host */
  10349.                         "",                     /* port */
  10350.                         NULL,                   /* alternate username */
  10351.                         NULL,                   /* password */
  10352.                         NULL,                   /* command to execute */
  10353.                         0,                      /* param1 */
  10354.                         0,                      /* param2 */
  10355.                         0,                      /* param3 */
  10356.                         cx,                     /* enter CONNECT mode */
  10357.                         sx,                     /* enter SERVER mode */
  10358.                         zz,                     /* close connection if open */
  10359.                         0                       /* gui */
  10360.                         );
  10361.         }
  10362. #endif /* NETCMD */
  10363.  
  10364. #ifdef NPIPE                            /* Named pipe */
  10365.         if (mynet == NET_PIPE) {        /* Needs backslash twiddling */
  10366.             if (line[0]) {
  10367.                 if (strcmp(line,"*")) {    /* If remote, begin with */
  10368.                     char * p = NULL;
  10369.                     makestr(&p,line);      
  10370.                     ckstrncpy(line,"\\\\",LINBUFSIZ); /* server name */
  10371.                     ckstrncat(line,p,LINBUFSIZ);
  10372.                     makestr(&p,NULL);      
  10373.                 } else {
  10374.                     line[0]='\0';
  10375.                 }
  10376.                 ckstrncat(line,"\\pipe\\", LINBUFSIZ); /* Make pipe name */
  10377.                 ckstrncat(line,pipename, LINBUFSIZ); /* Add name of pipe */
  10378.  
  10379.                 x = cx_net(mynet,    /* nettype */
  10380.                0,        /* protocol (not used) */
  10381.                line,    /* host */
  10382.                "",        /* port */
  10383.                NULL,    /* alternate username */
  10384.                NULL,    /* password */
  10385.                NULL,    /* command to execute */
  10386.                0,        /* param1 */
  10387.                0,        /* param2 */
  10388.                0,        /* param3 */
  10389.                cx,        /* enter CONNECT mode */
  10390.                sx,        /* enter SERVER mode */
  10391.                zz,        /* close connection if open */
  10392.                0        /* gui */
  10393.                );
  10394.             }
  10395.         }
  10396. #endif /* NPIPE */
  10397.  
  10398. #ifdef SUPERLAT
  10399.         if (mynet == NET_SLAT) {        /* Needs password, etc. */
  10400.             slat_pwd[0] = NUL;          /* Erase any previous password */
  10401.             debok = 0;
  10402.             if (*line) {        /* If they gave a host name... */
  10403.                 if ((x = cmfld(
  10404.                      "password,\n or carriage return if no password required",
  10405.                                "",
  10406.                                &s,
  10407.                                xxstring
  10408.                                )) < 0 && x != -3)
  10409.                   return(x);
  10410.                 ckstrncpy(slat_pwd,s,18); /* Set the password, if any */
  10411.             }
  10412.             if ((x = cmcfm()) < 0) return(x); /* Confirm the command */
  10413.  
  10414.             x = cx_net(mynet,        /* nettype */
  10415.                        0,        /* protocol (not used) */
  10416.                        line,        /* host */
  10417.                        "",        /* port */
  10418.                        NULL,        /* alternate username */
  10419.                        NULL,        /* password */
  10420.                        NULL,        /* command to execute */
  10421.                        0,        /* param1 */
  10422.                        0,        /* param2 */
  10423.                        0,        /* param3 */
  10424.                        cx,        /* enter CONNECT mode */
  10425.                        sx,        /* enter SERVER mode */
  10426.                        zz,        /* close connection if open */
  10427.                        0        /* gui */
  10428.                        );
  10429.         }
  10430. #endif /* SUPERLAT */
  10431.  
  10432. #ifdef DECNET
  10433.         if (mynet == NET_DEC) {  
  10434.             if (!line[0]) {                   /* If they gave a host name... */
  10435.                 printf("?hostname required\n");
  10436.                 return(-3);
  10437.             }
  10438.             if ((x = cmcfm()) < 0) return(x); /* Confirm the command */
  10439.  
  10440.             x = cx_net(mynet,        /* nettype */
  10441.                        0,        /* protocol (not used) */
  10442.                        line,        /* host */
  10443.                        "",        /* port */
  10444.                        NULL,        /* alternate username */
  10445.                        NULL,        /* password */
  10446.                        NULL,        /* command to execute */
  10447.                        0,        /* param1 */
  10448.                        0,        /* param2 */
  10449.                        0,        /* param3 */
  10450.                        cx,        /* enter CONNECT mode */
  10451.                        sx,        /* enter SERVER mode */
  10452.                        zz,        /* close connection if open */
  10453.                        0        /* gui */
  10454.                        );
  10455.         }
  10456. #endif /* DECNET */
  10457.  
  10458. #ifdef SSHBUILTIN
  10459.         if (mynet == NET_SSH) {        /* SSH connection */
  10460.             int k, havehost = 0, trips = 0;
  10461.             int    tmpver = -1, tmpxfw = -1, tmpssh_cas;
  10462. #ifndef SSHTEST
  10463.             extern int sl_ssh_xfw, sl_ssh_xfw_saved;
  10464.             extern int sl_ssh_ver, sl_ssh_ver_saved;
  10465. #endif /* SSHTEST */
  10466.             extern struct keytab sshopnsw[];
  10467.             extern int nsshopnsw;
  10468.             extern char *ssh_tmpcmd, *ssh_tmpport;
  10469.             struct FDB sw, kw, fl;
  10470.  
  10471.             debug(F110,"setlin SSH service 0",srvbuf,0);
  10472.             debug(F110,"setlin SSH host s 2",s,0);
  10473.             if (*s) {           /* If they gave a host name... */
  10474.                 debug(F110,"setlin SSH host s 1",s,0);
  10475.                 if (*s == '*') {
  10476.                     makestr(&slmsg,"Incoming connections not supported");
  10477.                     printf(
  10478.      "?Sorry, incoming connections not supported for SSH.\n"
  10479.                            );
  10480.                     return(-9);
  10481.                 }
  10482.                 ckstrncpy(line,s,LINBUFSIZ);
  10483.             } else {
  10484.                 printf("?hostname required\n");
  10485.                 return(-3);
  10486.             }
  10487.  
  10488.             /* Parse [ port ] [ switches ] */
  10489.             cmfdbi(&kw,                 /* Switches */
  10490.                     _CMKEY,
  10491.                     "Port number or service name,\nor switch",
  10492.                     "",
  10493.                     "",
  10494.                     nsshopnsw,
  10495.                     4,
  10496.                     xxstring,
  10497.                     sshopnsw,
  10498.                     &fl
  10499.                     );
  10500.             cmfdbi(&fl,                 /* Port number or service name */
  10501.                     _CMFLD,
  10502.                     "",
  10503.                     "",
  10504.                     "",
  10505.                     0,
  10506.                     0,
  10507.                     xxstring,
  10508.                     NULL,
  10509.                     NULL
  10510.                     );
  10511.             trips = 0;                  /* Explained below */
  10512.             while (1) {                 /* Parse port and switches */
  10513.                 y = cmfdb(&kw);         /* Get a field */
  10514.                 if (y == -3)            /* User typed CR so quit from loop */
  10515.                     break;
  10516.                 if (y < 0)              /* Other parse error, pass it back */
  10517.                     return(y);
  10518.                 switch (cmresult.fcode) { /* Field or Keyword? */
  10519.                 case _CMFLD:              /* Field */
  10520.                     ckstrncpy(srvbuf,cmresult.sresult,SRVBUFSIZ);
  10521.                     break;
  10522.                 case _CMKEY:            /* Keyword */
  10523.                     switch (cmresult.nresult) { /* Which one? */
  10524.                     case SSHSW_PWD:
  10525.                         if (!cmgbrk()) {
  10526.                             printf("?This switch requires an argument\n");
  10527.                             return(-9);
  10528.                         }
  10529.                         debok = 0;
  10530.                         if ((y = cmfld("Password","",&s,xxstring)) < 0) {
  10531.                             if (y == -3) {
  10532.                                 makestr(&tmpstring,"");
  10533.                             } else {
  10534.                                 return(y);
  10535.                             }
  10536.                         } else {
  10537.                             s = brstrip(s);
  10538.                             if ((y = (int)strlen(s)) > PWBUFL) {
  10539.                                 makestr(&slmsg,"Internal error");
  10540.                                 printf("?Sorry, too long - max = %d\n",PWBUFL);
  10541.                                 return(-9);
  10542.                             }
  10543.                             makestr(&tmpstring,s);
  10544.                         }
  10545.                         break;
  10546.                     case SSHSW_USR:             /* /USER: */
  10547.                         if (!cmgbrk()) {
  10548.                             printf("?This switch requires an argument\n");
  10549.                             return(-9);
  10550.                         }
  10551.                         if ((y = cmfld("Username","",&s,xxstring)) < 0)
  10552.                             return(y);
  10553.                         s = brstrip(s);
  10554.                         makestr(&tmpusrid,s);
  10555.                         break;
  10556.                     case SSHSW_VER:
  10557.                         if ((y = cmnum("Number","",10,&z,xxstring)) < 0)
  10558.                             return(y);
  10559.                         if (z < 1 || z > 2) {
  10560.                             printf("?Out of range: %d\n",z);
  10561.                             return(-9);
  10562.                         }
  10563.                         tmpver = z;
  10564.                         break;
  10565.                     case SSHSW_CMD:
  10566.                     case SSHSW_SUB:
  10567.                         if ((y = cmfld("Text","",&s,xxstring)) < 0)
  10568.                           return(y);
  10569.                         makestr(&ssh_tmpcmd,s);
  10570.                         tmpssh_cas = (cmresult.nresult == SSHSW_SUB);
  10571.                         break;
  10572.                     case SSHSW_X11:
  10573.                         if ((y = cmkey(onoff,2,"","on",xxstring)) < 0)
  10574.                             return(y);
  10575.                         tmpxfw = y;
  10576.                         break;
  10577.                     default:
  10578.                         return(-2);
  10579.                     }
  10580.                 }
  10581.                 if (trips++ == 0) {     /* After first time through */
  10582.                     cmfdbi(&kw,         /* only parse switches, not port. */
  10583.                             _CMKEY,
  10584.                             "Switch",
  10585.                             "",
  10586.                             "",
  10587.                             nsshopnsw,
  10588.                             4,
  10589.                             xxstring,
  10590.                             sshopnsw,
  10591.                             NULL
  10592.                             );
  10593.                 }
  10594.             }
  10595.             if ((y = cmcfm()) < 0)      /* Get confirmation */
  10596.                 return(y);
  10597.  
  10598.             debug(F110,"setlin pre-cx_net line",line,0);
  10599.             debug(F110,"setlin pre-cx_net srvbuf",srvbuf,0);
  10600.             x = cx_net( mynet,                  /* nettype */
  10601.                         0,                      /* protocol (not used) */
  10602.                         line,                   /* host */
  10603.                         srvbuf,                 /* port */
  10604.                         tmpusrid,               /* alternate username */
  10605.                         tmpstring,              /* password */
  10606.                         ssh_tmpcmd,             /* command to execute */
  10607.                         tmpver,                 /* param1 - ssh version */
  10608.                         tmpssh_cas,             /* param2 - ssh cas  */
  10609.                         tmpxfw,                 /* param3 - ssh x11fwd */
  10610.                         cx,                     /* enter CONNECT mode */
  10611.                         sx,                     /* enter SERVER mode */
  10612.                         zz,                     /* close connection if open */
  10613.                         0                       /* gui */
  10614.                         );
  10615.             if (tmpusrid)
  10616.                 makestr(&tmpusrid,NULL);
  10617.             if (ssh_tmpcmd)
  10618.                 makestr(&ssh_tmpcmd,NULL);
  10619.         }
  10620. #endif /* SSHBUILTIN */
  10621.  
  10622. #ifdef TCPSOCKET
  10623.         if (mynet == NET_TCPB) {        /* TCP/IP connection */
  10624.             debug(F110,"setlin service 0",srvbuf,0);
  10625.             debug(F110,"setlin host s 2",s,0);
  10626.             if (*s) {            /* If they gave a host name... */
  10627.                 debug(F110,"setlin host s 1",s,0);
  10628. #ifdef NOLISTEN
  10629.                 if (*s == '*') {
  10630.                     makestr(&slmsg,"Incoming connections not supported");
  10631.                     printf(
  10632.      "?Sorry, incoming connections not supported in this version of Kermit.\n"
  10633.                            );
  10634.                     return(-9);
  10635.                 }
  10636. #endif /* NOLISTEN */
  10637. #ifdef RLOGCODE
  10638.                 /* Allow a username if rlogin is requested */
  10639.                 if (mynet == NET_TCPB &&
  10640.                     (ttnproto == NP_RLOGIN || ttnproto == NP_K5LOGIN ||
  10641.                      ttnproto == NP_EK5LOGIN || ttnproto == NP_K4LOGIN ||
  10642.                      ttnproto == NP_EK4LOGIN
  10643.                     )) {
  10644.                     int y;
  10645.                     uidflag = 0;
  10646.                     /* Check for "host:service" */
  10647.                     for ( ; (*s != '\0') && (*s != ':'); s++) ;
  10648.                     if (*s) {   /* Service, save it */
  10649.                         *s = NUL;
  10650.                         ckstrncpy(srvbuf,++s,SRVBUFSIZ);
  10651.                     } else {            /* No :service, then use default. */
  10652. #ifdef VMS
  10653.                         switch (ttnproto) {
  10654.                           case NP_RLOGIN:
  10655.                             ckstrncpy(srvbuf,"513",SRVBUFSIZ); /* "login" */
  10656.                             break;
  10657.                           case NP_K4LOGIN:
  10658.                           case NP_K5LOGIN:
  10659.                             ckstrncpy(srvbuf,"543",SRVBUFSIZ); /* "klogin" */
  10660.                             break;
  10661.                           case NP_EK4LOGIN:
  10662.                           case NP_EK5LOGIN:
  10663.                             ckstrncpy(srvbuf,"2105",SRVBUFSIZ); /* "eklogin" */
  10664.                             break;
  10665.                         }
  10666. #else /* VMS */
  10667.                         switch (ttnproto) {
  10668.                           case NP_RLOGIN:
  10669.                             ckstrncpy(srvbuf,"login",SRVBUFSIZ);
  10670.                             break;
  10671.                           case NP_K4LOGIN:
  10672.                           case NP_K5LOGIN:
  10673.                             ckstrncpy(srvbuf,"klogin",SRVBUFSIZ);
  10674.                             break;
  10675.                           case NP_EK4LOGIN:
  10676.                           case NP_EK5LOGIN:
  10677.                             ckstrncpy(srvbuf,"eklogin",SRVBUFSIZ);
  10678.                             break;
  10679.                         }
  10680. #endif /* VMS */
  10681.                     }
  10682.                     if (!confirmed) {
  10683.                         y = cmfld("Userid on remote system",
  10684.                                   uidbuf,&s,xxstring);
  10685.                         if (y < 0 && y != -3)
  10686.                           return(y);
  10687.                         if ((int)strlen(s) > 63) {
  10688.                             makestr(&slmsg,"Internal error");
  10689.                             printf("Sorry, too long\n");
  10690.                             return(-9);
  10691.                         }
  10692.                         makestr(&tmpusrid,s);
  10693.                     }
  10694.                 } else {        /* TELNET or SET HOST */
  10695. #endif /* RLOGCODE */
  10696.                     /* Check for "host:service" */
  10697.                     for ( ; (*s != '\0') && (*s != ':'); s++) ;
  10698.                     if (*s) {   /* Service, save it */
  10699.                         *s = NUL;
  10700.                         ckstrncpy(srvbuf,++s,SRVBUFSIZ);
  10701.                     } else if (!confirmed) {
  10702.                         /* No :service, let them type one. */
  10703.                         if (*line != '*') { /* Not incoming */
  10704.                             if (mynet == NET_TCPB && ttnproto == NP_KERMIT) {
  10705.                                 if ((x = cmfld(
  10706.                                                "TCP service name or number",
  10707.                                                "kermit",&s,xxstring)
  10708.                                      ) < 0 && x != -3)
  10709.                                   return(x);
  10710. #ifdef RLOGCODE
  10711.                             } else if (mynet == NET_TCPB &&
  10712.                                        ttnproto == NP_RLOGIN) {
  10713.                                 if ((x = cmfld(
  10714.   "TCP service name or number,\n or carriage return for rlogin (513)",
  10715.                                                "login",&s,xxstring)
  10716.                                      ) < 0 && x != -3)
  10717.                                   return(x);
  10718. #ifdef CK_AUTHENTICATION
  10719. #ifdef CK_KERBEROS
  10720.                             } else if (mynet == NET_TCPB &&
  10721.                                        (ttnproto == NP_K4LOGIN ||
  10722.                                        ttnproto == NP_K5LOGIN)) {
  10723.                                 if ((x = cmfld(
  10724.   "TCP service name or number,\n or carriage return for klogin (543)",
  10725.                                                "klogin",&s,xxstring)
  10726.                                      ) < 0 && x != -3)
  10727.                                   return(x);
  10728.                             } else if (mynet == NET_TCPB &&
  10729.                                        (ttnproto == NP_EK4LOGIN ||
  10730.                                         ttnproto == NP_EK5LOGIN)) {
  10731.                                 if ((x = cmfld(
  10732.   "TCP service name or number,\n or carriage return for eklogin (2105)",
  10733.                                                "eklogin",&s,xxstring)
  10734.                                      ) < 0 && x != -3)
  10735.                                   return(x);
  10736. #endif /* CK_KERBEROS */
  10737. #endif /* CK_AUTHENTICATION */
  10738. #endif /* RLOGCODE */
  10739.                             } else {
  10740.                                 /* Do not set a default value in this call */
  10741.                                 /* If you do then it will prevent entries  */
  10742.                                 /* in the network directory from accessing */
  10743.                                 /* alternate ports.                        */
  10744.  
  10745.                                 if ((x = cmfld(
  10746.                                                "TCP service name or number",
  10747.                                                "",&s,xxstring)
  10748.                                      ) < 0 && x != -3)
  10749.                                   return(x);
  10750.                             }
  10751.                         } else { /* Incoming connection */
  10752.                             if ((x = cmfld("TCP service name or number",
  10753.                                            "",&s,xxstring)
  10754.                                  ) < 0 && x != -3)
  10755.                               return(x);
  10756.                         }
  10757.                         if (*s)         /* If they gave a service, */
  10758.                           ckstrncpy(srvbuf,s,SRVBUFSIZ); /* copy it */
  10759.                         debug(F110,"setlin service 0.5",srvbuf,0);
  10760.                     }
  10761. #ifdef RLOGCODE
  10762.                 }
  10763. #endif /* RLOGCODE */
  10764.                 if (!confirmed) {
  10765.                     char * defproto;
  10766.                     switch (ttnproto) {
  10767.                       case NP_RLOGIN:
  10768.                         defproto = "/rlogin";
  10769.                         break;
  10770.                       case NP_K4LOGIN:
  10771.                         defproto = "/k4login";
  10772.                         break;
  10773.                       case NP_K5LOGIN:
  10774.                         defproto = "/k5login";
  10775.                         break;
  10776.                       case NP_EK4LOGIN:
  10777.                         defproto = "/ek4login";
  10778.                         break;
  10779.                       case NP_EK5LOGIN:
  10780.                         defproto = "/ek5login";
  10781.                         break;
  10782.                       case NP_KERMIT:
  10783.                       case NP_TELNET:
  10784.                         defproto = "/telnet";
  10785.                         break;
  10786.                       default:
  10787.                         defproto = "/default";
  10788.                     }
  10789.                     if ((x = cmkey(tcprawtab,ntcpraw,"Switch",defproto,
  10790.                                    xxstring)) < 0) {
  10791.                         if (x != -3)
  10792.                           return(x);
  10793.                         else if ((x = cmcfm()) < 0)
  10794.                           return(x);
  10795.                     } else {
  10796.                         rawflg = x;
  10797.                         if ((x = cmcfm()) < 0)
  10798.                           return(x);
  10799.                     }
  10800.                 }
  10801.             }
  10802.             debug(F110,"setlin pre-cx_net line",line,0);
  10803.             debug(F110,"setlin pre-cx_net srvbuf",srvbuf,0);
  10804.             x = cx_net( mynet,                  /* nettype */
  10805.                         rawflg                  /* protocol */,
  10806.                         line,                   /* host */
  10807.                         srvbuf,                 /* port */
  10808.                         tmpusrid,               /* alternate username */
  10809.                         tmpstring,              /* password */
  10810.                         NULL,                   /* command to execute */
  10811.                         a_type,                 /* param1 - telnet authtype */
  10812.                         e_type,                 /* param2 - telnet enctype  */
  10813.                         wait,                   /* param3 - telnet wait */
  10814.                         cx,                     /* enter CONNECT mode */
  10815.                         sx,                     /* enter SERVER mode */
  10816.                         zz,                     /* close connection if open */
  10817.                         0                       /* gui */
  10818.                         );
  10819.         }
  10820. #endif /* TCPSOCKET */
  10821.  
  10822. #ifdef CK_SECURITY
  10823.         if (tmpstring)
  10824.             makestr(&tmpstring,NULL);
  10825. #endif /* CK_SECURITY */
  10826.         if (tmpusrid)
  10827.             makestr(&tmpusrid,NULL);
  10828.     debug(F111,"setlin cx_net",line,x);
  10829.     return(x);
  10830. #endif /* NETCONN */
  10831.     }
  10832.  
  10833. /* Serial tty device, possibly modem, connection... */
  10834.  
  10835. #ifdef OS2
  10836. /*
  10837.   User can type:
  10838.     COM1..COM8 = Regular COM port
  10839.     1..8       = Synonym for COM1..COM8, is translated to COM1..COM8
  10840.     _n         = (n is a number) = open file handle
  10841.     string     = any text string = name of some other kind of device,
  10842.                  taken literally, as given.
  10843. */
  10844.     s = "Communication device name";
  10845.  
  10846. #ifdef CK_TAPI
  10847.     if (TAPIAvail)
  10848.       cktapiBuildLineTable(&tapilinetab, &_tapilinetab, &ntapiline);
  10849.     if (!(tapilinetab && _tapilinetab && ntapiline > 0) &&
  10850.     xx == XYTAPI_LIN ) {
  10851.     makestr(&slmsg,"TAPI device not configured");
  10852.     printf("\nNo TAPI Line Devices are configured for this system\n");
  10853.     return(-9);
  10854.     }
  10855.     if (xx == XYTAPI_LIN) {        /* Default (first) TAPI line */
  10856.     s = "tapi";            /* (whatever it is) */
  10857.     } else {                /* Query the user */
  10858. #endif /* CK_TAPI */
  10859.  
  10860. /* Now parse optional switches and then device name */
  10861.  
  10862.     confirmed = 0;
  10863.     cmfdbi(&sw,_CMKEY,"Device name, or switch",
  10864.            "","",npsltab,4,xxstring,psltab,&fl);
  10865.     cmfdbi(&fl,_CMFLD,"",dftty,"",0,0,xxstring,NULL,NULL);
  10866.     while (1) {
  10867.         x = cmfdb(&sw);
  10868.         debug(F101,"setlin cmfdb","",x);
  10869.         if (x < 0)
  10870.           if (x != -3)
  10871.         return(x);
  10872.         if (x == -3) {
  10873.         if ((x = cmcfm()) < 0) {
  10874.             return(x);
  10875.         } else {
  10876.             confirmed = 1;
  10877.             break;
  10878.         }
  10879.         }
  10880.         if (cmresult.fcode == _CMFLD) {
  10881.         s = cmresult.sresult;
  10882.         break;
  10883.         } else if (cmresult.fcode == _CMKEY) {
  10884.         switch (cmresult.nresult) {
  10885.           case SL_CNX:        /* /CONNECT */
  10886.             cx = 1;
  10887.             sx = 0;
  10888.             break;
  10889.           case SL_SRV:        /* /SERVER */
  10890.             cx = 0;
  10891.             sx = 1;
  10892.             break;
  10893.           case SL_SHR:        /* /SHARE */
  10894.             shr = 1;
  10895.             break;
  10896.           case SL_NSH:        /* /NOSHARE */
  10897.             shr = 0;
  10898.             break;
  10899.         }
  10900.         }
  10901.     }
  10902. #ifdef CK_TAPI
  10903.     }
  10904. #endif /* CK_TAPI */
  10905.  
  10906.     debug(F110,"OS2 SET PORT s",s,0);
  10907.     y = lookup(os2devtab,s,nos2dev,&x); /* Look up in keyword table */
  10908.     debug(F101,"OS2 SET PORT x","",x);
  10909.     debug(F101,"OS2 SET PORT y","",y);
  10910.     if ((y > -1) && (x >= 0 && x < 8)) { /* User typed a digit 1..8 */
  10911.     s = os2devtab[x+8].kwd;        /* Substitite its real name */
  10912. #ifdef NT
  10913.     xxtapi = 0;
  10914. #else /* NT */
  10915.     xxslip = xxppp = 0;
  10916. #endif /* NT */
  10917.     debug(F110,"OS2 SET PORT subst s",s,"");
  10918. #ifndef NT
  10919.     } else if ((y >-1) && (x >= 16 && x < 24)) { /* SLIP access */
  10920.     s = os2devtab[x-8].kwd;        /* Substitite its real name */
  10921.     debug(F110,"OS2 SET PORT SLIP subst s",s,"");
  10922.     xxslip = 1;
  10923.     xxppp  = 0;
  10924.     } else if ((y >-1) && (x >= 24 && x < 32)) { /* PPP access */
  10925.     s = os2devtab[x-16].kwd;    /* Substitite its real name */
  10926.     debug(F110,"OS2 SET PORT PPP subst s",s,"");
  10927.     xxppp = 1;
  10928.     xxslip = 0;
  10929.     if ((y = cmkey(os2ppptab,
  10930.                nos2ppp,
  10931.                "PPP driver interface",
  10932.                "ppp0",
  10933.                xxstring)
  10934.          ) < 0)
  10935.       return(y);
  10936.     debug(F101,"OS2 SET PORT PPP INTERFACE y","",y);
  10937.     xxppp = (y % 10) + 1;
  10938. #endif /* NT */
  10939.     } else if (*s == '_') {        /* User used "_" prefix */
  10940.     s++;                /* Remove it */
  10941.     /* Rest must be numeric */
  10942.     debug(F110,"OS2 SET PORT HANDLE _subst s",s,0);
  10943.     if (!rdigits(s)) {
  10944.         makestr(&slmsg,"Invalid file handle");
  10945.         printf("?Invalid format for file handle\n");
  10946.         return(-9);
  10947.     }
  10948. #ifdef NT
  10949.     xxtapi = 0;
  10950. #else /* NT */
  10951.     xxslip = xxppp = 0;
  10952. #endif /* NT */
  10953.     } else {                /* A normal COMx port or a string */
  10954.     s = brstrip(s);            /* Strip braces if any */
  10955. #ifdef NT
  10956. #ifdef CK_TAPI
  10957.     /* Windows TAPI support - Look up in keyword table */
  10958.     if (tapilinetab && _tapilinetab && ntapiline > 0) {
  10959.         if (!ckstrcmp(s,"tapi",4,0)) {
  10960.  
  10961.         /* Find out what the lowest numbered TAPI device is */
  10962.         /* and use it as the default.                       */
  10963.         int j = 9999, k = -1;
  10964.         for (i = 0; i < ntapiline; i++) {
  10965.             if (tapilinetab[i].kwval < j) {
  10966.             j = tapilinetab[i].kwval;
  10967.             k = i;
  10968.             }
  10969.         }
  10970.         if (k >= 0)
  10971.           s = _tapilinetab[k].kwd;
  10972.         else
  10973.           s = "";
  10974.  
  10975.         if ((y = cmkey(_tapilinetab,ntapiline,
  10976.                    "TAPI device name",s,xxstring)) < 0)
  10977.           return(y);
  10978.  
  10979.         xxtapi = 1;
  10980.  
  10981.         /* Get the non Underscored string */
  10982.         for (i = 0; i < ntapiline; i++ ) {
  10983.             if (tapilinetab[i].kwval == y) {
  10984.             s = tapilinetab[i].kwd;
  10985.             break;
  10986.             }
  10987.         }
  10988.         } else
  10989.           xxtapi = 0;
  10990.     }
  10991. #endif /* CK_TAPI */
  10992. #else /* NT */
  10993.     /* not OS/2 SLIP or PPP */
  10994.     xxslip = xxppp = 0;
  10995. #endif /* NT */
  10996.     }
  10997.     ckstrncpy(tmpbuf,s,TMPBUFSIZ);    /* Copy to a safe place */
  10998.     s = tmpbuf;
  10999.     if ((x = cmcfm()) < 0)
  11000.       return(x);
  11001.  
  11002. #else /* !OS2 */
  11003.  
  11004.     cmfdbi(&sw,_CMKEY,"Device name, or switch",
  11005.        "","",npsltab,4,xxstring,psltab,&tx);
  11006.     cmfdbi(&tx,_CMTXT,"",dftty,"",0,0,xxstring,NULL,NULL);
  11007.     while (!confirmed) {
  11008.     x = cmfdb(&sw);
  11009.     debug(F101,"setlin cmfdb","",x);
  11010.     if (x < 0)
  11011.       if (x != -3)
  11012.         return(x);
  11013.     if (x == -3) {
  11014.         if ((x = cmcfm()) < 0) {
  11015.         return(x);
  11016.         } else {
  11017.         confirmed = 1;
  11018.         break;
  11019.         }
  11020.     }
  11021.     switch (cmresult.fcode) {
  11022.       case _CMTXT:
  11023.         ckstrncpy(tmpbuf,cmresult.sresult,TMPBUFSIZ);
  11024.         s = tmpbuf;
  11025.         debug(F110,"setlin CMTXT",tmpbuf,0);
  11026.         confirmed = 1;
  11027.         break;
  11028.       case _CMKEY:            /* Switch */
  11029.         debug(F101,"setlin CMKEY",tmpbuf,cmresult.nresult);
  11030.         switch (cmresult.nresult) {
  11031.           case SL_CNX:        /* /CONNECT */
  11032.         cx = 1;
  11033.         sx = 0;
  11034.         break;
  11035.           case SL_SRV:        /* /SERVER */
  11036.         cx = 0;
  11037.         sx = 1;
  11038.         break;
  11039. #ifdef VMS
  11040.           case SL_SHR:        /* /SHARE */
  11041.         shr = 1;
  11042.         break;
  11043.           case SL_NSH:        /* /NOSHARE */
  11044.         shr = 0;
  11045.         break;
  11046. #endif /* VMS */
  11047.         }
  11048.         continue;
  11049.       default:
  11050.         debug(F101,"setlin bad cmfdb result","",cmresult.fcode);
  11051.         makestr(&slmsg,"Internal error");
  11052.         printf("?Internal parsing error\n");
  11053.         return(-9);
  11054.     }
  11055.     }
  11056. #endif /* OS2 */
  11057.     if (!confirmed)
  11058.       if ((x = cmcfm()) < 0)
  11059.     return(x);
  11060.  
  11061.     debug(F110,"setlin pre-cx_serial s",s,0);
  11062.     debug(F110,"setlin pre-cx_serial line",line,0);
  11063.     x = cx_serial(s,cx,sx,shr,zz,0,
  11064. #ifdef OS2
  11065. #ifdef NT
  11066.                    (xxtapi ? CX_TAPI : 0)
  11067. #else
  11068.                    (xxslip ? CX_SLIP : 0) | (xxppp ? CX_PPP : 0)
  11069. #endif /* NT */
  11070. #else /* OS2 */
  11071.                    0
  11072. #endif /* OS2 */
  11073.                    );
  11074.     debug(F111,"setlin cx_serial",line,x);
  11075.     return(x);
  11076. }
  11077. #endif /* NOLOCAL */
  11078.  
  11079. #ifdef CKCHANNELIO
  11080. /*
  11081.   C-Library based file-i/o package for scripts.  This should be portable to
  11082.   all C-Kermit versions since it uses the same APIs we have always used for
  11083.   processing command files.  The entire channel i/o package is contained
  11084.   herein, apart from some keyword table entries in the main keyword table
  11085.   and the help text in the HELP command module.
  11086.  
  11087.   On platforms like VMS and VOS, this package handles only UNIX-style
  11088.   stream files.  If desired, it can be replaced for those platforms by
  11089.   <#>ifdef'ing out this code and adding the equivalent replacement routines
  11090.   to the ck?fio.c module, e.g. for RMS-based file i/o in ckvfio.c.
  11091. */
  11092.  
  11093. /* Define NOSTAT if the <#>include causes trouble. */
  11094.  
  11095. #ifndef NOSTAT
  11096. #ifdef VMS
  11097. #ifdef VAXC                             /* As it does in VAX C */
  11098. #define NOSTAT
  11099. #endif /* VAXC */
  11100. #endif /* VMS */
  11101. #endif /* NOSTAT */
  11102.  
  11103. #ifndef NOSTAT
  11104. #include <sys/stat.h>
  11105. #endif /* NOSTAT */
  11106.  
  11107. #ifdef NLCHAR
  11108. static int z_lt = 1;                    /* Length of line terminator */
  11109. #else
  11110. static int z_lt = 2;
  11111. #endif /* NLCHAR */
  11112.  
  11113. struct ckz_file {                       /* C-Kermit file struct */
  11114.     FILE * z_fp;                        /* Includes the C-Lib file struct */
  11115.     unsigned int z_flags;               /* Plus C-Kermit mode flags, */
  11116.     long z_nline;                       /* current line number if known, */
  11117.     char z_name[CKMAXPATH+2];           /* and the file's name. */
  11118. };
  11119. static struct ckz_file * z_file = NULL; /* Array of C-Kermit file structs */
  11120. static int z_inited = 0;                /* Flag for array initialized */
  11121. int z_maxchan = Z_MAXCHAN;              /* Max number of C-Kermit channels */
  11122. int z_openmax = CKMAXOPEN;              /* Max number of open files overall */
  11123. int z_nopen = 0;                        /* How many channels presently open */
  11124. int z_error = 0;                        /* Most recent error */
  11125. int z_filcount = -1;                    /* Most recent FILE COUNT result */
  11126.  
  11127. #define RD_LINE 0                       /* FILE READ options */
  11128. #define RD_CHAR 1
  11129. #define RD_SIZE 2
  11130.  
  11131. #define WR_LINE RD_LINE                 /* FILE WRITE options */
  11132. #define WR_CHAR RD_CHAR
  11133. #define WR_SIZE RD_SIZE
  11134. #define WR_STRI 3
  11135. #define WR_LPAD 4
  11136. #define WR_RPAD 5
  11137.  
  11138. #ifdef UNIX
  11139. extern int ckmaxfiles;                  /* Filled in by sysinit(). */
  11140. #endif /* UNIX */
  11141.  
  11142. /* See ckcker.h for error numbers */
  11143. /* See ckcdeb.h for Z_MAXCHAN and CKMAXOPEN definitions */
  11144. /* NOTE: For VMS we might be able to fill in ckmaxfiles */
  11145. /* from FILLM and CHANNELCNT -- find out about these... */
  11146.  
  11147. static char * fopnargs[] = {            /* Mode combinations for fopen() */
  11148. #ifdef COMMENT
  11149.     /* All combinations of rwa */
  11150.     "",  "r",  "w",  "rw",  "a",  "ra",  "wa",  "rwa", /* Text mode */
  11151.     "b", "rb", "wb", "rwb", "ab", "rab", "wab", "rwab" /* Binary mode */
  11152. #else
  11153.     /* Combinations and syntax permitted by C libraries... */
  11154.     "",  "r",  "w",  "r+",  "a",  "",   "a",  "", /* Text mode */
  11155. #ifdef OS2
  11156.     "",  "rb", "wb", "r+b", "ab", "",   "ab", "" /* Binary modes for K95 */
  11157. #else
  11158. #ifdef VMS
  11159.     "",  "rb", "wb", "r+b", "ab", "",   "ab", "" /* Binary modes for VMS */
  11160. #else
  11161.     "",  "r",   "w", "r+",  "a",  "",   "a",  "" /* Binary modes for UNIX */
  11162. #endif /* VMS */
  11163. #endif /* OS2 */
  11164. #endif /* COMMENT */
  11165. };
  11166. static int nfopnargs = sizeof(fopnargs) / sizeof(char *);
  11167.  
  11168. char *                                  /* Error messages */
  11169. ckferror(n) int n; {
  11170.     switch (n) {
  11171.       case FX_NER: return("No error");
  11172.       case FX_SYS: return(ck_errstr());
  11173.       case FX_EOF: return("End of file");
  11174.       case FX_NOP: return("File not open");
  11175.       case FX_CHN: return("Channel out of range");
  11176.       case FX_RNG: return("Parameter out of range");
  11177.       case FX_NMF: return("Too many files open");
  11178.       case FX_FOP: return("Operation conflicts with OPEN mode");
  11179.       case FX_NYI: return("OPEN mode not supported");
  11180.       case FX_BOM: return("Illegal combination of OPEN modes");
  11181.       case FX_ACC: return("Access denied");
  11182.       case FX_FNF: return("File not found");
  11183.       case FX_OFL: return("Buffer overflow");
  11184.       case FX_LNU: return("Current line number unknown");
  11185.       case FX_ROO: return("Off limits");
  11186.       case FX_UNK: return("Operation fails - reason unknown");
  11187.       default: return("Error number out of range");
  11188.     }
  11189. }
  11190.  
  11191. /*
  11192.   Z _ O P E N --  Open a file for the requested type of access.
  11193.  
  11194.   Call with:
  11195.     name:  Name of file to be opened.
  11196.     flags: Any combination of FM_xxx values except FM_EOF (ckcker.h).
  11197.   Returns:
  11198.     >= 0 on success: The assigned channel number
  11199.     <  0 on failure: A negative FX_xxx error code (ckcker.h).
  11200. */
  11201. int
  11202. z_open(name, flags) char * name; int flags; {
  11203.     int i, n;
  11204.     FILE * t;
  11205.     char * mode;
  11206.     debug(F111,"z_open",name,flags);
  11207.     if (!name) name = "";               /* Check name argument */
  11208.     if (!name[0])
  11209.       return(z_error = FX_BFN);
  11210.     if (flags & FM_CMD)                 /* Opening pipes not implemented yet */
  11211.       return(z_error = FX_NYI);         /* (and not portable either) */
  11212.     debug(F101,"z_open nfopnargs","",nfopnargs);
  11213.     if (flags < 0 || flags >= nfopnargs) /* Range check flags */
  11214.       return(z_error = FX_RNG);
  11215.     mode = fopnargs[flags];             /* Get fopen() arg */
  11216.     debug(F111,"z_open fopen args",mode,flags);
  11217.     if (!mode[0])                       /* Check for illegal combinations */
  11218.       return(z_error = FX_BOM);
  11219.     if (!z_inited) {                    /* If file structs not inited */
  11220.         debug(F101,"z_open z_maxchan 1","",z_maxchan);
  11221. #ifdef UNIX
  11222.         debug(F101,"z_open ckmaxfiles","",ckmaxfiles);
  11223.         if (ckmaxfiles > 0) {           /* Set in ck?tio.c: sysinit() */
  11224.             int x;
  11225.             x = ckmaxfiles - ZNFILS - 5;
  11226.             if (x > z_maxchan)          /* sysconf() value greater than */
  11227.               z_maxchan = x;            /* value from header files. */
  11228.             debug(F101,"z_open z_maxchan 2","",z_maxchan);
  11229.         }
  11230. #endif /* UNIX */
  11231.         if (z_maxchan < Z_MINCHAN)      /* Allocate at least this many. */
  11232.           z_maxchan = Z_MINCHAN;
  11233.         debug(F101,"z_open z_maxchan 3","",z_maxchan);
  11234.         /* Note: This could be a pretty big chunk of memory */
  11235.         /* if z_maxchan is a big number.  If this becomes a problem */
  11236.         /* we'll need to malloc and free each element at open/close time */
  11237.         if (!(z_file = (struct ckz_file *)
  11238.               malloc(sizeof(struct ckz_file) * (z_maxchan + 1))))
  11239.           return(z_error = FX_NMF);
  11240.         for (i = 0; i < z_maxchan; i++) {
  11241.             z_file[i].z_fp = NULL;
  11242.             z_file[i].z_flags = 0;
  11243.             z_file[i].z_nline = 0;
  11244.             *(z_file[i].z_name) = '\0';
  11245.         }
  11246.         z_inited = 1;                   /* Remember we did */
  11247.     }
  11248.     for (n = -1, i = 0; i < z_maxchan; i++) {
  11249.         if (!z_file[i].z_fp) {
  11250.             n = i;
  11251.             break;
  11252.         }
  11253.     }
  11254.     if (n < 0 || n >= z_maxchan)        /* Any free channels? */
  11255.       return(z_error = FX_NMF);         /* No, fail. */
  11256.     errno = 0;
  11257.  
  11258.     z_file[n].z_flags = 0;              /* In case of failure... */
  11259.  
  11260.     t = fopen(name, mode);              /* Try to open the file. */
  11261.     if (!t) {                           /* Failed... */
  11262.         debug(F111,"z_open error",name,errno);
  11263. #ifdef EMFILE
  11264.         if (errno == EMFILE)
  11265.           return(z_error = FX_NMF);
  11266. #endif /* EMFILE */
  11267.         return(z_error = (errno ?  FX_SYS : FX_UNK)); /* Return error code */
  11268.     }
  11269. #ifdef NT
  11270. #ifdef O_SEQUENTIAL
  11271.     if (t)                              /* Caching hint for NT */
  11272.       _setmode(_fileno(t),O_SEQUENTIAL);
  11273. #endif /* O_SEQUENTIAL */
  11274. #endif /* NT */
  11275.     z_nopen++;                          /* Open, count it. */
  11276.     z_file[n].z_fp = t;                 /* Stash the file pointer */
  11277.     z_file[n].z_flags = flags;          /* and the flags */
  11278.     z_error = 0;
  11279.     zfnqfp(name,CKMAXPATH,z_file[n].z_name); /* and the file's full name */
  11280.     return(n);                          /* Return the channel number */
  11281. }
  11282.  
  11283. int
  11284. z_close(channel) int channel; {         /* Close file on given channel */
  11285.     int x;
  11286.     FILE * t;
  11287.     if (!z_inited)                      /* Called before any files are open? */
  11288.       return(z_error = FX_NOP);
  11289.     if (channel >= z_maxchan)           /* Channel out of range? */
  11290.       return(z_error = FX_CHN);
  11291.     if (!(t = z_file[channel].z_fp))    /* Channel wasn't open? */
  11292.       return(z_error = FX_NOP);
  11293.     errno = 0;                          /* Set errno 0 to get a good reading */
  11294.     x = fclose(t);                      /* Try to close */
  11295.     if (x == EOF)                       /* On failure */
  11296.       return(z_error = FX_SYS);         /* indicate system error. */
  11297.     z_nopen--;                          /* Closed OK, decrement open count */
  11298.     z_file[channel].z_fp = NULL;        /* Set file pointer to NULL */
  11299.     z_file[channel].z_nline = 0;        /* Current line number is 0 */
  11300.     z_file[channel].z_flags = 0;        /* Set flags to 0 */
  11301.     *(z_file[channel].z_name) = '\0';   /* Clear name */
  11302.     return(z_error = 0);
  11303. }
  11304.  
  11305. /*
  11306.   Z _ O U T  --  Output string to channel.
  11307.  
  11308.   Call with:
  11309.     channel:     Channel number to write to.
  11310.     s:           String to write.
  11311.     length > -1: How many characters of s to write.
  11312.     length < 0:  Write entire NUL-terminated string.
  11313.     flags == 0:  Supply line termination.
  11314.     flags >  0:  Don't supply line termination.
  11315.     flags <  0:  Write 'length' NUL characters.
  11316.   Special case:
  11317.     If flags > -1 and s is empty or NULL and length == 1, write 1 NUL.
  11318.   Returns:
  11319.     Number of characters written to channel on success, or
  11320.     negative FX_xxx error code on failure.
  11321. */
  11322. int
  11323. z_out(channel,s,length,flags) int channel, flags, length; char * s; {
  11324.     FILE * t;
  11325.     int x, n;
  11326.     char c = '\0';
  11327.  
  11328.     if (!s) s = "";                     /* Guard against null pointer */
  11329. #ifdef DEBUG
  11330.     if (deblog) {
  11331.         debug(F111,"z_out",s,channel);
  11332.         debug(F101,"z_out length","",length);
  11333.         debug(F101,"z_out flags","",flags);
  11334.     }
  11335. #endif /* DEBUG */
  11336.     if (!z_inited)                      /* File i/o inited? */
  11337.       return(z_error = FX_NOP);
  11338.     if (channel >= z_maxchan)           /* Channel in range? */
  11339.       return(z_error = FX_CHN);
  11340.     if (!(t = z_file[channel].z_fp))    /* File open? */
  11341.       return(z_error = FX_NOP);
  11342.     if (!((z_file[channel].z_flags) & (FM_WRI|FM_APP))) /* In write mode? */
  11343.       return(z_error = FX_FOP);
  11344.     n = length;                         /* Length of string to write */
  11345.     if (n < 0) {                        /* Negative means get it ourselves */
  11346.         if (flags < 0)                  /* Except when told to write NULs in */
  11347.           return(z_error = FX_RNG);     /* which case args are inconsistent */
  11348.         n = strlen(s);                  /* Get length of string arg */
  11349.     }
  11350.     errno = 0;                          /* Reset errno */
  11351.     debug(F101,"z_out n","",n);
  11352.     if (flags < 0) {                    /* Writing NULs... */
  11353.         int i;
  11354.         for (i = 0; i < n; i++) {
  11355.             x = fwrite(&c,1,1,t);
  11356.             if (x < 1)
  11357.               return(z_error = (errno ? FX_SYS : FX_UNK));
  11358.         }
  11359.         z_file[channel].z_nline = -1;   /* Current line no longer known */
  11360.         z_error = 0;
  11361.         return(i);
  11362.     } else {                            /* Writing string arg */
  11363.         if (n == 1 && !s[0])            /* Writing one char but it's NUL */
  11364.           x = fwrite(&c,1,1,t);
  11365.         else                            /* Writing non-NUL char or string */
  11366.           x = fwrite(s,1,n,t);
  11367.         debug(F101,"z_out fwrite",ckitoa(x),errno);
  11368.         if (x < n)                      /* Failure to write requested amount */
  11369.           return(z_error = (errno ? FX_SYS : FX_UNK)); /* Return error */
  11370.         if (flags == 0) {               /* If supplying line termination */
  11371.             if (fwrite("\n",1,1,t))     /* do that  */
  11372.               x += z_lt;                /* count the terminator */
  11373.             if (z_file[channel].z_nline > -1) /* count this line */
  11374.               z_file[channel].z_nline++;
  11375.         } else {
  11376.             z_file[channel].z_nline = -1; /* Current line no longer known */
  11377.         }
  11378.     }
  11379.     z_error = 0;
  11380.     return(x);
  11381. }
  11382.  
  11383. #define Z_INBUFLEN 64
  11384.  
  11385. /*
  11386.   Z _ I N  --  Multichannel i/o file input function.
  11387.  
  11388.   Call with:
  11389.     channel number to read from.
  11390.     s = address of destination buffer.
  11391.     buflen = destination buffer length.
  11392.     length = Number of bytes to read, must be < buflen.
  11393.     flags: 0 = read a line; nonzero = read the given number of bytes.
  11394.   Returns:
  11395.     Number of bytes read into buffer or a negative error code.
  11396.     A terminating NUL is deposited after the last byte that was read.
  11397. */
  11398. int
  11399. z_in(channel,s,buflen,length,flags)
  11400.  int channel, buflen, length, flags; char * s;
  11401. /* z_in */ {
  11402.     int i, j, x;
  11403.     FILE * t;
  11404.     char * p;
  11405.  
  11406.     if (!z_inited)                      /* Check everything... */
  11407.       return(z_error = FX_NOP);
  11408.     if (channel >= z_maxchan)
  11409.       return(z_error = FX_CHN);
  11410.     if (!(t = z_file[channel].z_fp))
  11411.       return(z_error = FX_NOP);
  11412.     if (!((z_file[channel].z_flags) & FM_REA))
  11413.       return(z_error = FX_FOP);
  11414.     if (!s)                             /* Check destination */
  11415.      return(z_error = FX_RNG);
  11416.     s[0] = NUL;
  11417.     if (length == 0)                    /* Read 0 bytes - easy. */
  11418.       return(z_error = 0);
  11419.     debug(F101,"z_in channel","",channel);
  11420.     debug(F101,"z_in buflen","",buflen);
  11421.     debug(F101,"z_in length","",length);
  11422.     debug(F101,"z_in flags","",flags);
  11423.     if (length < 0 || buflen < 0)       /* Check length args */
  11424.       return(z_error = FX_RNG);
  11425.     if (buflen <= length)
  11426.       return(z_error = FX_RNG);
  11427.     errno = 0;                          /* Reset errno */
  11428.     if (flags) {                        /* Read block or byte */
  11429.         i = fread(s,1,length,t);
  11430. #ifdef DEBUG
  11431.         if (deblog) {
  11432.             debug(F111,"z_in block",s,i);
  11433.             debug(F101,"z_in block errno","",errno);
  11434.             debug(F101,"z_in block ferror","",ferror(t));
  11435.             debug(F101,"z_in block feof","",feof(t));
  11436.         }
  11437. #endif /* DEBUG */
  11438.         z_file[channel].z_nline = -1;   /* Current line no longer known */
  11439.     } else {                            /* Read line */
  11440. #ifndef COMMENT
  11441.         /* This method is used because it's simpler than the others */
  11442.         /* and also marginally faster. */
  11443.         debug(F101,"z_in getc loop","",ftell(t));
  11444.         for (i = 0; i < length; i++) {
  11445.             if ((x = getc(t)) == EOF) {
  11446.                 debug(F101,"z_in getc error","",ftell(t));
  11447.                 s[i] = '\0';
  11448.                 break;
  11449.             }
  11450.             s[i] = x;
  11451.             if (s[i] == '\n') {
  11452.                 s[i] = '\0';
  11453.                 break;
  11454.             }
  11455.         }
  11456.         debug(F111,"z_in line byte loop",ckitoa(errno),i);
  11457.         debug(F111,"z_in line got",s,z_file[channel].z_nline);
  11458.         if (z_file[channel].z_nline > -1)
  11459.           z_file[channel].z_nline++;
  11460. #else
  11461. #ifdef COMMENT2
  11462.         /* Straightforward but strlen() slows it down. */
  11463.         s[0] = '\0';
  11464.         i = 0;
  11465.         if (fgets(s,length,t)) {
  11466.             i = strlen(s);
  11467.             if (i > 0 && s[i-1] == '\n') i--;
  11468.         }
  11469.         debug(F111,"z_in line fgets",ckitoa(errno),i);
  11470.         if (z_file[channel].z_nline > -1)
  11471.           z_file[channel].z_nline++;
  11472. #else
  11473.         /* This is a do-it-yourself fgets() with its own readahead and */
  11474.         /* putback.  It's a bit faster than real fgets() but not enough */
  11475.         /* to justify the added complexity or the risk of the ftell() and */
  11476.         /* fseek() calls failing. */
  11477.         int k, flag = 0;
  11478.         long pos;
  11479.         for (i = 0; !flag && i <= (length - Z_INBUFLEN); i += Z_INBUFLEN) {
  11480.             k = ((length - i) < Z_INBUFLEN) ? length - i : Z_INBUFLEN;
  11481.             if ((x = fread(s+i,1,k,t)) < 1)
  11482.               break;
  11483.             s[i+x] = '\0';
  11484.             for (j = 0; j < x; j++) {
  11485.                 if (s[i+j] == '\n') {
  11486.                     s[i+j] = '\0';
  11487.                     flag ++;
  11488.                     pos = ftell(t);
  11489.                     if (pos > -1) {
  11490.                         pos -= (x - j - 1);
  11491.                         x = fseek(t, pos, 0);
  11492.                         i += j;
  11493.                         break;
  11494.                     } else
  11495.                       return(z_error = FX_SYS);
  11496.                 }
  11497.             }
  11498.         }
  11499.         if (z_file[channel].z_nline > -1)
  11500.           z_file[channel].z_nline++;
  11501.         debug(F111,"z_in line chunk loop",ckitoa(errno),i);
  11502. #endif /* COMMENT2 */
  11503. #endif /* COMMENT */
  11504.     }
  11505.     debug(F111,"z_in i",ckitoa(errno),i);
  11506.     if (i < 0) i = 0;                   /* NUL-terminate result */
  11507.     s[i] = '\0';
  11508.     if (i > 0) {
  11509.         z_error = 0;
  11510.         return(i);
  11511.     }
  11512.     if (i == 0 && feof(t))              /* EOF on reading? */
  11513.       return(z_error = FX_EOF);         /* Return EOF code */
  11514.     return(errno ? (z_error = -1) : i); /* Return length or system error */
  11515. }
  11516.  
  11517. int
  11518. z_flush(channel) int channel; {         /* Flush output channel */
  11519.     FILE * t;
  11520.     int x;
  11521.     if (!z_inited)                      /* Regular checks */
  11522.       return(z_error = FX_NOP);
  11523.     if (channel >= z_maxchan)
  11524.       return(z_error = FX_CHN);
  11525.     if (!(t = z_file[channel].z_fp))
  11526.       return(z_error = FX_NOP);
  11527.     if (!((z_file[channel].z_flags) & (FM_WRI|FM_APP))) /* Write access? */
  11528.       return(z_error = FX_FOP);
  11529.     errno = 0;                          /* Reset errno */
  11530.     x = fflush(t);                      /* Try to flush */
  11531.     return(x ? (z_error = FX_SYS) : 0); /* Return system error or 0 if OK */
  11532. }
  11533.  
  11534. int
  11535. #ifdef CK_ANSIC
  11536. z_seek(int channel, long pos)           /* Move file pointer to byte */
  11537. #else
  11538. z_seek(channel,pos) int channel; long pos; /* (seek to given position) */
  11539. #endif /* CK_ANSIC */
  11540. {
  11541.     int i, x = 0, rc;
  11542.     FILE * t;
  11543.     if (!z_inited)                      /* Check... */
  11544.       return(z_error = FX_NOP);
  11545.     if (channel >= z_maxchan)
  11546.       return(z_error = FX_CHN);
  11547.     if (!(t = z_file[channel].z_fp))
  11548.       return(z_error = FX_NOP);
  11549.     if (pos < 0L) {
  11550.         x = 2;
  11551.         pos = (pos == -2) ? -1L : 0L;
  11552.     }
  11553.     errno = 0;
  11554.     rc = fseek(t,pos,x);                /* Try to seek */
  11555.     debug(F111,"z_seek",ckitoa(errno),rc);
  11556.     if (rc < 0)                         /* OK? */
  11557.       return(z_error = FX_SYS); /* No. */
  11558.     z_file[channel].z_nline = ((pos || x) ? -1 : 0);
  11559.     return(z_error = 0);
  11560. }
  11561.  
  11562. int
  11563. #ifdef CK_ANSIC
  11564. z_line(int channel, long pos)           /* Move file pointer to line */
  11565. #else
  11566. z_line(channel,pos) int channel; long pos; /* (seek to given position) */
  11567. #endif /* CK_ANSIC */
  11568. {
  11569.     int i, len, x = 0;
  11570.     long current = 0L, prev = -1L, old = -1L;
  11571.     FILE * t;
  11572.     char tmpbuf[256];
  11573.     if (!z_inited)                      /* Check... */
  11574.       return(z_error = FX_NOP);
  11575.     if (channel >= z_maxchan)
  11576.       return(z_error = FX_CHN);
  11577.     if (!(t = z_file[channel].z_fp))
  11578.       return(z_error = FX_NOP);
  11579.     debug(F101,"z_line pos","",pos);
  11580.     if (pos < 0L) {                     /* EOF wanted */
  11581.         long n;
  11582.         n = z_file[channel].z_nline;
  11583.         debug(F101,"z_line n","",n);
  11584.         if (n < 0 || pos < 0) {
  11585.             rewind(t);
  11586.             n = 0;
  11587.         }
  11588.         while (1) {                     /* This could take a while... */
  11589.             if ((x = getc(t)) == EOF)
  11590.               break;
  11591.             if (x == '\n') {
  11592.                 n++;
  11593.                 if (pos == -2) {
  11594.                     old = prev;
  11595.                     prev = ftell(t);
  11596.                 }
  11597.             }
  11598.         }
  11599.         debug(F101,"z_line old","",old);
  11600.         debug(F101,"z_line prev","",prev);
  11601.         if (pos == -2) {
  11602.             if ((x = z_seek(channel,old)) < 0)
  11603.               return(z_error = x);
  11604.             else
  11605.               n--;
  11606.         }
  11607.         z_file[channel].z_nline = n;
  11608.         return(z_error = 0);
  11609.     }
  11610.     if (pos == 0L) {                    /* Rewind wanted */
  11611.         z_file[channel].z_nline = 0L;
  11612.         rewind(t);
  11613.         debug(F100,"z_line rewind","",0);
  11614.         return(0L);
  11615.     }
  11616.     tmpbuf[255] = NUL;                  /* Make sure buf is NUL terminated */
  11617.     current = z_file[channel].z_nline;  /* Current line */
  11618.     /*
  11619.       If necessary the following could be optimized, e.g. for positioning
  11620.       to a previous line in a large file without starting over.
  11621.     */
  11622.     if (current < 0 || pos < current) { /* Not known or behind us... */
  11623.         debug(F101,"z_line rewinding","",pos);
  11624.         if ((x = z_seek(channel, 0L)) < 0) /* Rewind */
  11625.           return(z_error = x);
  11626.         if (pos == 0)                   /* If 0th line wanted we're done */
  11627.           return(z_error = 0);
  11628.         current = 0;
  11629.     }
  11630.     while (current < pos) {             /* Search for specified line */
  11631.         if (fgets(tmpbuf,255,t)) {
  11632.             len = strlen(tmpbuf);
  11633.             if (len > 0 && tmpbuf[len-1] == '\n') {
  11634.                 current++;
  11635.                 debug(F111,"z_line read",ckitoa(len),current);
  11636.             } else if (len == 0) {
  11637.                 return(z_error = FX_UNK);
  11638.             }
  11639.         } else {
  11640.             z_file[channel].z_nline = -1L;
  11641.             debug(F101,"z_line premature EOF","",current);
  11642.             return(z_error = FX_EOF);
  11643.         }
  11644.     }
  11645.     z_file[channel].z_nline = current;
  11646.     debug(F101,"z_line result","",current);
  11647.     z_error = 0;
  11648.     return(current);
  11649. }
  11650.  
  11651. char *
  11652. z_getname(channel) int channel; {       /* Return name of file on channel */
  11653.     FILE * t;
  11654.     if (!z_inited) {
  11655.         z_error = FX_NOP;
  11656.         return(NULL);
  11657.     }
  11658.     if (channel >= z_maxchan) {
  11659.         z_error = FX_CHN;
  11660.         return(NULL);
  11661.     }
  11662.     if (!(t = z_file[channel].z_fp)) {
  11663.         z_error = FX_NOP;
  11664.         return(NULL);
  11665.     }
  11666.     return((char *)(z_file[channel].z_name));
  11667. }
  11668.  
  11669. int
  11670. z_getmode(channel) int channel; {       /* Return OPEN modes of channel */
  11671.     FILE * t;                           /* 0 if file not open */
  11672. #ifndef NOSTAT
  11673. #ifdef NT
  11674.     struct _stat statbuf;
  11675. #else /* NT */
  11676.     struct stat statbuf;
  11677. #endif /* NT */
  11678. #endif /* NOSTAT */
  11679.     int x;
  11680.     if (!z_inited)
  11681.       return(0);
  11682.     if (channel >= z_maxchan)
  11683.       return(z_error = FX_CHN);
  11684.     if (!(t = z_file[channel].z_fp))
  11685.       return(0);
  11686.     x = z_file[channel].z_flags;
  11687.     if (feof(t)) {                      /* This might not work for */
  11688.         x |= FM_EOF;                    /* output files */
  11689. #ifndef NOSTAT
  11690.     /* But this does if we can use it. */
  11691.     } else if (stat(z_file[channel].z_name,&statbuf) > -1) {
  11692.         if (ftell(t) == statbuf.st_size)
  11693.           x |= FM_EOF;
  11694. #endif /* NOSTAT */
  11695.     }
  11696.     return(x);
  11697. }
  11698.  
  11699. long
  11700. z_getpos(channel) int channel; {        /* Get file pointer position */
  11701.     FILE * t;                           /* on this channel */
  11702.     long x;
  11703.     if (!z_inited)
  11704.       return(z_error = FX_NOP);
  11705.     if (channel >= z_maxchan)
  11706.       return(z_error = FX_CHN);
  11707.     if (!(t = z_file[channel].z_fp))
  11708.       return(z_error = FX_NOP);
  11709.     x = ftell(t);
  11710.     return((x < 0L) ? (z_error = FX_SYS) : x);
  11711. }
  11712.  
  11713. long
  11714. z_getline(channel) int channel; {       /* Get current line number */
  11715.     FILE * t;                           /* in file on this channel */
  11716.     long rc;
  11717.     if (!z_inited)
  11718.       return(z_error = FX_NOP);
  11719.     if (channel >= z_maxchan)
  11720.       return(z_error = FX_CHN);
  11721.     if (!(t = z_file[channel].z_fp))
  11722.       return(z_error = FX_NOP);
  11723.     debug(F101,"z_getline","",z_file[channel].z_nline);
  11724.     rc = z_file[channel].z_nline;
  11725.     return((rc < 0) ? (z_error = FX_LNU) : rc);
  11726. }
  11727.  
  11728. int
  11729. z_getfnum(channel) int channel; {       /* Get file number / handle */
  11730.     FILE * t;                           /* for file on this channel */
  11731.     if (!z_inited)
  11732.       return(z_error = FX_NOP);
  11733.     if (channel >= z_maxchan)
  11734.       return(z_error = FX_CHN);
  11735.     if (!(t = z_file[channel].z_fp))
  11736.       return(z_error = FX_NOP);
  11737.     z_error = 0;
  11738.     return(fileno(t));
  11739. }
  11740.  
  11741. /*
  11742.   Line-oriented counts and seeks are as dumb as they can be at the moment.
  11743.   Later we can speed them up by building little indexes.
  11744. */
  11745. long
  11746. z_count(channel, what) int channel, what; { /* Count bytes or lines in file */
  11747.     FILE * t;
  11748.     int i, x;
  11749.     long pos, count = 0L;
  11750.     if (!z_inited)                      /* Check stuff... */
  11751.       return(z_error = FX_NOP);
  11752.     if (channel >= z_maxchan)
  11753.       return(z_error = FX_CHN);
  11754.     if (!(t = z_file[channel].z_fp))
  11755.       return(z_error = FX_NOP);
  11756.     pos = ftell(t);                     /* Save current file pointer */
  11757.     errno = 0;
  11758.     z_error = 0;
  11759.     if (what == RD_CHAR) {              /* Size in bytes requested */
  11760.         if (!fseek(t,0L,2)) {           /* Seek to end */
  11761.             count = ftell(t);           /* Get file pointer */
  11762.             fseek(t,pos,0);             /* Restore file file pointer */
  11763.             return(count);
  11764.         } else                          /* Fallback in case seek fails */
  11765.           return(zgetfs(z_file[channel].z_name));
  11766.     }
  11767.     rewind(t);                          /* Line count requested - rewind. */
  11768.     while (1) {                         /* Count lines. */
  11769.         if ((x = getc(t)) == EOF)       /* Stupid byte loop */
  11770.           break;                        /* but it works as well as anything */
  11771.         if (x == '\n')                  /* else... */
  11772.           count++;
  11773.     }
  11774.     x = fseek(t,pos,0);                 /* Restore file pointer */
  11775.     return(count);
  11776. }
  11777.  
  11778. /* User interface for generalized channel-oriented file i/o */
  11779.  
  11780. struct keytab fctab[] = {               /* FILE subcommands */
  11781.     { "close",      FIL_CLS, 0 },
  11782.     { "count",      FIL_COU, 0 },
  11783.     { "flush",      FIL_FLU, 0 },
  11784.     { "list",       FIL_LIS, 0 },
  11785.     { "open",       FIL_OPN, 0 },
  11786.     { "read",       FIL_REA, 0 },
  11787.     { "rewind",     FIL_REW, 0 },
  11788.     { "seek",       FIL_SEE, 0 },
  11789.     { "status",     FIL_STA, 0 },
  11790.     { "write",      FIL_WRI, 0 }
  11791. };
  11792. int nfctab = (sizeof (fctab) / sizeof (struct keytab));
  11793.  
  11794. static struct keytab fcswtab[] = {      /* OPEN modes */
  11795.     { "/append",    FM_APP,  0 },
  11796.     { "/binary",    FM_BIN,  0 },
  11797. #ifdef COMMENT
  11798.     { "/command",   FM_CMD,  0 },       /* Not implemented */
  11799. #endif /* COMMENT */
  11800.     { "/read",      FM_REA,  0 },
  11801.     { "/write",     FM_WRI,  0 }
  11802. };
  11803. static int nfcswtab = (sizeof (fcswtab) / sizeof (struct keytab));
  11804.  
  11805. static struct keytab fclkwtab[] = {     /* CLOSE options */
  11806.     { "all",        1,       0 }
  11807. };
  11808.  
  11809. static struct keytab fsekwtab[] = {     /* SEEK symbols */
  11810.     { "eof",        1,       0 },
  11811.     { "last",       2,       0 }
  11812. };
  11813. static int nfsekwtab = (sizeof (fsekwtab) / sizeof (struct keytab));
  11814.  
  11815. #define SEE_LINE  RD_LINE               /* SEEK options */
  11816. #define SEE_CHAR  RD_CHAR
  11817. #define SEE_REL   3
  11818. #define SEE_ABS   4
  11819.  
  11820. static struct keytab fskswtab[] = {
  11821.     { "/absolute",  SEE_ABS,  0 },
  11822.     { "/byte",      SEE_CHAR, 0 },
  11823.     { "/character", SEE_CHAR, CM_INV },
  11824.     { "/line",      SEE_LINE, 0 },
  11825.     { "/relative",  SEE_REL,  0 }
  11826. };
  11827. static int nfskswtab = (sizeof (fskswtab) / sizeof (struct keytab));
  11828.  
  11829. #define COU_LINE  RD_LINE               /* COUNT options */
  11830. #define COU_CHAR  RD_CHAR
  11831. #define COU_LIS   3
  11832. #define COU_NOL   4
  11833.  
  11834. static struct keytab fcoswtab[] = {
  11835.     { "/bytes",     COU_CHAR, 0      },
  11836.     { "/characters",COU_CHAR, CM_INV },
  11837.     { "/lines",     COU_LINE, 0      },
  11838.     { "/list",      COU_LIS,  0      },
  11839.     { "/nolist",    COU_NOL,  0      },
  11840.     { "/quiet",     COU_NOL,  CM_INV }
  11841. };
  11842. static int nfcoswtab = (sizeof (fcoswtab) / sizeof (struct keytab));
  11843.  
  11844. static struct keytab frdtab[] = {       /* READ types */
  11845.     { "/block",     RD_SIZE, CM_INV|CM_ARG },
  11846.     { "/byte",      RD_CHAR, CM_INV },
  11847.     { "/character", RD_CHAR, 0      },
  11848.     { "/line",      RD_LINE, 0      },
  11849.     { "/size",      RD_SIZE, CM_ARG }
  11850. };
  11851. static int nfrdtab = (sizeof (frdtab) / sizeof (struct keytab));
  11852.  
  11853. static struct keytab fwrtab[] = {       /* WRITE types */
  11854.     { "/block",     WR_SIZE, CM_INV|CM_ARG },
  11855.     { "/byte",      WR_CHAR, CM_INV },
  11856.     { "/character", WR_CHAR, 0      },
  11857.     { "/line",      WR_LINE, 0      },
  11858.     { "/lpad",      WR_LPAD, CM_ARG },
  11859.     { "/rpad",      WR_RPAD, CM_ARG },
  11860.     { "/size",      WR_SIZE, CM_ARG },
  11861.     { "/string",    WR_STRI, 0      }
  11862. };
  11863. static int nfwrtab = (sizeof (fwrtab) / sizeof (struct keytab));
  11864.  
  11865. static char blanks[] = "\040\040\040\040"; /* Some blanks for formatting */
  11866.  
  11867. int
  11868. dofile(op) int op; {                    /* Do the FILE command */
  11869.     char vnambuf[VNAML];                /* Buffer for variable names */
  11870.     char *vnp = NULL;                   /* Pointer to same */
  11871.     char zfilnam[CKMAXPATH+2];
  11872.     char * p;
  11873.     struct FDB fl, sw, nu;
  11874.     long z;
  11875.     int rsize, filmode = 0, relative = -1, eofflg = 0;
  11876.     int rc, x, y, cx, n, getval, dummy, confirmed, listing = -1;
  11877.     int charflag = 0, sizeflag = 0;
  11878.     int pad = 32, wr_lpad = 0, wr_rpad = 0;
  11879.  
  11880.     if (op == XXFILE) {                 /* FILE command was given */
  11881.         /* Get subcommand */
  11882.         if ((cx = cmkey(fctab,nfctab,"Operation","",xxstring)) < 0) {
  11883.             if (cx == -3) {
  11884.                 printf("?File operation required\n");
  11885.                 x = -9;
  11886.             }
  11887.             return(cx);
  11888.         }
  11889.     } else {                            /* Shorthand command was given */
  11890.         switch (op) {
  11891.           case XXF_CL: cx = FIL_CLS; break; /* FCLOSE */
  11892.           case XXF_FL: cx = FIL_FLU; break; /* FFLUSH */
  11893.           case XXF_LI: cx = FIL_LIS; break; /* FLIST */
  11894.           case XXF_OP: cx = FIL_OPN; break; /* etc... */
  11895.           case XXF_RE: cx = FIL_REA; break;
  11896.           case XXF_RW: cx = FIL_REW; break;
  11897.           case XXF_SE: cx = FIL_SEE; break;
  11898.           case XXF_ST: cx = FIL_STA; break;
  11899.           case XXF_WR: cx = FIL_WRI; break;
  11900.           case XXF_CO: cx = FIL_COU; break;
  11901.           default: return(-2);
  11902.         }
  11903.     }
  11904.     switch (cx) {                       /* Do requested subcommand */
  11905.       case FIL_OPN:                     /* OPEN */
  11906.         cmfdbi(&sw,                     /* Switches */
  11907.                _CMKEY,                  /* fcode */
  11908.                "Variable or switch",    /* hlpmsg */
  11909.                "",                      /* default */
  11910.                "",                      /* addtl string data */
  11911.                nfcswtab,                /* addtl numeric data 1: tbl size */
  11912.                4,                       /* addtl numeric data 2: 4 = cmswi */
  11913.                xxstring,                /* Processing function */
  11914.                fcswtab,                 /* Keyword table */
  11915.                &fl                      /* Pointer to next FDB */
  11916.                );
  11917.         cmfdbi(&fl,                     /* Anything that doesn't match */
  11918.                _CMFLD,                  /* fcode */
  11919.                "Variable",              /* hlpmsg */
  11920.                "",
  11921.                "",
  11922.                0,
  11923.                0,
  11924.                NULL,
  11925.                NULL,
  11926.                NULL
  11927.                );
  11928.         while (1) {
  11929.             x = cmfdb(&sw);             /* Parse something */
  11930.             if (x < 0) {
  11931.                 if (x == -3) {
  11932.                     printf("?Variable name and file name required\n");
  11933.                     x = -9;
  11934.                 }
  11935.                 return(x);
  11936.             }
  11937.             if (cmresult.fcode == _CMFLD)
  11938.               break;
  11939.             else if (cmresult.fcode == _CMKEY) {
  11940.                 char c;
  11941.                 c = cmgbrk();
  11942.                 if ((getval =
  11943.                      (c == ':' || c == '=')) && !(cmgkwflgs() & CM_ARG)) {
  11944.                     printf("?This switch does not take an argument\n");
  11945.                     return(-9);
  11946.                 }
  11947. #ifdef COMMENT
  11948.                 /* Uncomment if we add any switches ere that take args */
  11949.                 if (!getval && (cmgkwflgs() & CM_ARG)) {
  11950.                     printf("?This switch requires an argument\n");
  11951.                     return(-9);         /* (none do...) */
  11952.                 }
  11953. #endif /* COMMENT */
  11954.                 filmode |= cmresult.nresult; /* OR in the file mode */
  11955.             } else
  11956.               return(-2);
  11957.         }
  11958.         /* Not a switch - get the string */
  11959.         ckstrncpy(vnambuf,cmresult.sresult,VNAML);
  11960.         if (!vnambuf[0] || chknum(vnambuf)) { /* (if there is one...) */
  11961.             printf("?Variable name required\n");
  11962.             return(-9);
  11963.         }
  11964.         vnp = vnambuf;                  /* Check variable-name syntax */
  11965.         if (vnambuf[0] == CMDQ &&
  11966.             (vnambuf[1] == '%' || vnambuf[1] == '&'))
  11967.           vnp++;
  11968.         y = 0;
  11969.         if (*vnp == '%' || *vnp == '&') {
  11970.             if ((y = parsevar(vnp,&x,&dummy)) < 0) {
  11971.                 printf("?Syntax error in variable name\n");
  11972.                 return(-9);
  11973.             }
  11974.         }
  11975.         if (!(filmode & FM_RWA))        /* If no access mode specified */
  11976.           filmode |= FM_REA;            /* default to /READ. */
  11977.  
  11978.         y = 0;                          /* Now parse the filename */
  11979.         if ((filmode & FM_RWA) == FM_WRI)
  11980.           x = cmofi("Name of new file","",&s,xxstring);
  11981.         else if ((filmode & FM_RWA) == FM_REA)
  11982.           x = cmifi("Name of existing file","",&s,&y,xxstring);
  11983.         else {
  11984.             x = cmiofi("Filename","",&s,&y,xxstring);
  11985.             debug(F101,"fopen /append x","",x);
  11986.         }
  11987.         if (x == -9) {
  11988.             if (zchko(s) < 0) {
  11989.                 printf("Can't create \"%s\"\n",s);
  11990.                 return(x);
  11991.             }
  11992.         } else if (x < 0) {
  11993.             if (x == -3) {
  11994.                 printf("?Filename required\n");
  11995.                 x = -9;
  11996.             }
  11997.             return(x);
  11998.         }
  11999.         if (y) {                        /* No wildcards */
  12000.             printf("?Wildcards not allowed here\n");
  12001.             return(-9);
  12002.         }
  12003.         if (filmode & (FM_APP|FM_WRI)) { /* Check output access */
  12004. #ifndef VMS
  12005.             if (zchko(s) < 0) {          /* and set error code if denied */
  12006.                 z_error = FX_ACC;
  12007.                 printf("?Write access denied - \"%s\"\n",s);
  12008.                 return(-9);
  12009.             }
  12010. #endif /* VMS */
  12011.         }
  12012.         ckstrncpy(zfilnam,s,CKMAXPATH); /* Is OK - make safe copy */
  12013.         if ((x = cmcfm()) < 0)          /* Get confirmation of command */
  12014.           return(x);
  12015.         if ((n = z_open(zfilnam,filmode)) < 0) {
  12016.             printf("?OPEN failed - %s: %s\n",zfilnam,ckferror(n));
  12017.             return(-9);
  12018.         }
  12019.         addmac(vnambuf,ckitoa(n));      /* Assign channel number to variable */
  12020.         return(success = 1);
  12021.  
  12022.       case FIL_REW:                     /* REWIND */
  12023.         if ((x = cmnum("Channel number","",10,&n, xxstring)) < 0) {
  12024.             if (x == -3) {
  12025.                 printf("?Channel number required\n");
  12026.                 x = -9;
  12027.             }
  12028.             return(x);
  12029.         }
  12030.         if ((x = cmcfm()) < 0)
  12031.           return(x);
  12032.         if ((rc = z_seek(n,0L)) < 0) {
  12033.             printf("?REWIND failed - Channel %d: %s\n",n,ckferror(rc));
  12034.             return(-9);
  12035.         }
  12036.         return(success = 1);
  12037.  
  12038.       case FIL_CLS:                     /* CLOSE */
  12039.           cmfdbi(&sw,                   /* Second FDB - switches */
  12040.                  _CMKEY,                /* fcode */
  12041.                  "Channel number; or keyword",
  12042.                  "",
  12043.                  "",                    /* addtl string data */
  12044.                  1,                     /* addtl numeric data 1: tbl size */
  12045.                  0,                     /* addtl numeric data 2: 4 = cmswi */
  12046.                  xxstring,              /* Processing function */
  12047.                  fclkwtab,              /* Keyword table */
  12048.                  &nu                    /* Pointer to next FDB */
  12049.                  );
  12050.           cmfdbi(&nu,                   /* First FDB - command switches */
  12051.                  _CMNUM,                /* fcode */
  12052.                  "",
  12053.                  "",                    /* default */
  12054.                  "",                    /* addtl string data */
  12055.                  10,                    /* addtl numeric data 1: radix */
  12056.                  0,                     /* addtl numeric data 2: 0 */
  12057.                  xxstring,              /* Processing function */
  12058.                  NULL,                  /* Keyword table */
  12059.                  NULL                   /* Pointer to next FDB */
  12060.                  );                     /*  */
  12061.         x = cmfdb(&sw);                 /* Parse something */
  12062.         if (x < 0) {
  12063.             if (x == -3) {
  12064.                 printf("?Channel number or ALL required\n");
  12065.                 x = -9;
  12066.             }
  12067.             return(x);
  12068.         }
  12069.         if (cmresult.fcode == _CMNUM)
  12070.           n = cmresult.nresult;
  12071.         else if (cmresult.fcode == _CMKEY)
  12072.           n = -1;
  12073.         if ((x = cmcfm()) < 0)
  12074.           return(x);
  12075.         rc = 1;
  12076.         if (n < 0) {
  12077.             int count = 0;
  12078.             int i;
  12079.             for (i = 0; i < z_maxchan; i++) {
  12080.                 x = z_close(i);
  12081.                 if (x == FX_SYS) {
  12082.                     printf("?CLOSE failed - Channel %d: %s\n",n,ckferror(x));
  12083.                     rc = 0;
  12084.                 } else if (x > -1)
  12085.                   count++;
  12086.             }
  12087.             debug(F101,"FILE CLOSE ALL","",count);
  12088.         } else if ((x = z_close(n)) < 0) {
  12089.             printf("?CLOSE failed - Channel %d: %s\n",n,ckferror(x));
  12090.             return(-9);
  12091.         }
  12092.         return(success = rc);
  12093.  
  12094.       case FIL_REA:                     /* READ */
  12095.       case FIL_WRI:                     /* WRITE */
  12096.         rsize = 0;
  12097.         cmfdbi(&sw,                     /* Switches */
  12098.                _CMKEY,                  /* fcode */
  12099.                "Channel or switch",     /* hlpmsg */
  12100.                "",                      /* default */
  12101.                "",                      /* addtl string data */
  12102.                (cx == FIL_REA) ? nfrdtab : nfwrtab,
  12103.                4,                       /* addtl numeric data 2: 4 = cmswi */
  12104.                xxstring,                /* Processing function */
  12105.                (cx == FIL_REA) ? frdtab : fwrtab, /* Keyword table */
  12106.                &nu                      /* Pointer to next FDB */
  12107.                );
  12108.         cmfdbi(&nu,                     /* Channel number */
  12109.                _CMNUM,                  /* fcode */
  12110.                "Channel",
  12111.                "",                      /* default */
  12112.                "",                      /* addtl string data */
  12113.                10,                      /* addtl numeric data 1: radix */
  12114.                0,                       /* addtl numeric data 2: 0 */
  12115.                xxstring,                /* Processing function */
  12116.                NULL,                    /* Keyword table */
  12117.                NULL                     /* Pointer to next FDB */
  12118.                );
  12119.         do {
  12120.             x = cmfdb(&sw);             /* Parse something */
  12121.             if (x < 0) {
  12122.                 if (x == -3) {
  12123.                     printf("?Channel number required\n");
  12124.                     x = -9;
  12125.                 }
  12126.                 return(x);
  12127.             }
  12128.             if (cmresult.fcode == _CMNUM) /* Channel number */
  12129.               break;
  12130.             else if (cmresult.fcode == _CMKEY) { /* Switch */
  12131.                 char c;
  12132.                 c = cmgbrk();
  12133.                 if ((getval =
  12134.                      (c == ':' || c == '=')) && !(cmgkwflgs() & CM_ARG)) {
  12135.                     printf("?This switch does not take an argument\n");
  12136.                     return(-9);
  12137.                 }
  12138.                 if (!getval && (cmgkwflgs() & CM_ARG)) {
  12139.                     printf("?This switch requires an argument\n");
  12140.                     return(-9);
  12141.                 }
  12142.                 switch (cmresult.nresult) {
  12143.                   case WR_LINE:
  12144.                     charflag = 0;
  12145.                     sizeflag = 0;
  12146.                     rsize = 0;
  12147.                     break;
  12148.                   case WR_CHAR:
  12149.                     rsize = 1;
  12150.                     charflag = 1;
  12151.                     sizeflag = 1;
  12152.                     break;
  12153.                   case WR_SIZE:
  12154.                     if ((x = cmnum("Bytes","",10,&rsize, xxstring)) < 0) {
  12155.                         if (x == -3) {
  12156.                             printf("?Number required\n");
  12157.                             x = -9;
  12158.                         }
  12159.                         return(x);
  12160.                     }
  12161.                     charflag = 0;
  12162.                     sizeflag = 1;
  12163.                     break;
  12164.                   case WR_STRI:
  12165.                     rsize = 1;
  12166.                     charflag = 0;
  12167.                     sizeflag = 0;
  12168.                     break;
  12169.                   case WR_LPAD:
  12170.                   case WR_RPAD:
  12171.                     if ((x = cmnum("Numeric ASCII character value",
  12172.                                    "32",10,&pad, xxstring)) < 0)
  12173.                       return(x);
  12174.                     if (cmresult.nresult == WR_LPAD)
  12175.                       wr_lpad = 1;
  12176.                     else
  12177.                       wr_rpad = 1;
  12178.                     break;
  12179.                 }
  12180.                 debug(F101,"FILE READ rsize 2","",rsize);
  12181.             } else
  12182.               return(-2);
  12183.         } while
  12184.           (cmresult.fcode == _CMKEY);
  12185.  
  12186.         n = cmresult.nresult;           /* Channel */
  12187.         debug(F101,"FILE READ/WRITE channel","",n);
  12188.  
  12189.         if (cx == FIL_WRI) {            /* WRITE */
  12190.             int len = 0;
  12191.             if ((x = cmtxt("Text","",&s,xxstring)) < 0)
  12192.               return(x);
  12193.             ckstrncpy(line,s,LINBUFSIZ); /* Make a safe copy */
  12194.             s = line;
  12195.             s = brstrip(s);             /* Strip braces */
  12196.             if (charflag) {             /* Write one char */
  12197.                 len = 1;                /* So length = 1 */
  12198.                 rsize = 1;              /* Don't supply terminator */
  12199.             } else if (!sizeflag) {     /* Write a string */
  12200.                 len = -1;               /* So length is unspecified */
  12201.             } else {                    /* Write a block of given size */
  12202.                 int i, k, xx;
  12203.                 if (rsize > TMPBUFSIZ) {
  12204.                     z_error = FX_OFL;
  12205.                     printf("?Buffer overflow\n");
  12206.                     return(-9);
  12207.                 }
  12208.                 len = rsize;            /* rsize is really length */
  12209.                 rsize = 1;              /* Don't supply a terminator */
  12210.                 xx = strlen(s);         /* Size of given string */
  12211.                 if (xx >= len) {        /* Bigger or equal */
  12212.                     s[len] = NUL;
  12213.                 } else if (wr_lpad) {   /* Smaller, left-padding requested */
  12214.                     for (i = 0; i < len - xx; i++) /* Must make a copy */
  12215.                       tmpbuf[i] = pad;
  12216.                     ckstrncpy(tmpbuf+i,s,TMPBUFSIZ-i);
  12217.                     tmpbuf[len] = NUL;
  12218.                     s = tmpbuf;         /* Redirect write source */
  12219.                 } else if (wr_rpad) {   /* Smaller with right-padding */
  12220.                     for (i = xx; i < len; i++)
  12221.                       s[i] = pad;
  12222.                     s[len] = NUL;
  12223.                 }
  12224.             }
  12225.             if ((rc = z_out(n,s,len,rsize)) < 0) { /* Try to write */
  12226.                 printf("?Channel %d WRITE error: %s\n",n,ckferror(rc));
  12227.                 return(-9);
  12228.             }
  12229.         } else {                        /* FIL_REA READ */
  12230.             confirmed = 0;
  12231.             vnambuf[0] = NUL;
  12232.             x = cmfld("Variable name","",&s,NULL);
  12233.             debug(F111,"FILE READ cmfld",s,x);
  12234.             if (x < 0) {
  12235.                 if (x == -3 || !*s) {
  12236.                     if ((x = cmcfm()) < 0)
  12237.                       return(x);
  12238.                     else
  12239.                       confirmed++;
  12240.                 } else
  12241.                   return(x);
  12242.             }
  12243.             ckstrncpy(vnambuf,s,VNAML);
  12244.             debug(F111,"FILE READ vnambuf",vnambuf,confirmed);
  12245.             if (vnambuf[0]) {           /* Variable name given, check it */
  12246.                 if (!confirmed) {
  12247.                     x = cmcfm();
  12248.                     if (x < 0)
  12249.                       return(x);
  12250.                     else
  12251.                       confirmed++;
  12252.                 }
  12253.                 vnp = vnambuf;
  12254.                 if (vnambuf[0] == CMDQ &&
  12255.                     (vnambuf[1] == '%' || vnambuf[1] == '&'))
  12256.                   vnp++;
  12257.                 y = 0;
  12258.                 if (*vnp == '%' || *vnp == '&') {
  12259.                     if ((y = parsevar(vnp,&x,&dummy)) < 0) {
  12260.                         printf("?Syntax error in variable name\n");
  12261.                         return(-9);
  12262.                     }
  12263.                 }
  12264.             }
  12265.             debug(F111,"FILE READ variable",vnambuf,confirmed);
  12266.  
  12267.             if (!confirmed)
  12268.               if ((x = cmcfm()) < 0)
  12269.                 return(x);
  12270.  
  12271.             line[0] = NUL;              /* Clear destination buffer */
  12272.             if (rsize >= LINBUFSIZ)     /* Don't overrun it */
  12273.               rsize = LINBUFSIZ - 1;
  12274.  
  12275.             if (rsize == 0)             /* Read a line */
  12276.               rc = z_in(n,line,LINBUFSIZ,LINBUFSIZ-1,0);
  12277.             else
  12278.               rc = z_in(n,line,LINBUFSIZ,rsize,1); /* Read a block */
  12279.             if (rc < 0) {               /* Error... */
  12280.                 debug(F101,"FILE READ error","",rc);
  12281.                 debug(F101,"FILE READ errno","",errno);
  12282.                 if (rc == FX_EOF) {     /* EOF - fail but no error message */
  12283.                     return(success = 0);
  12284.                 } else {                /* Other error - fail and print msg */
  12285.                     printf("?READ error: %s\n",ckferror(rc));
  12286.                     return(-9);
  12287.                 }
  12288.             }
  12289.             debug(F110,"FILE READ data",line,0);
  12290.             if (vnambuf[0])             /* Read OK - If variable name given */
  12291.               addmac(vnambuf,line);     /* Assign result to variable */
  12292.             else                        /* otherwise */
  12293.               printf("%s\n",line);      /* just print it */
  12294.         }
  12295.         return(success = 1);
  12296.  
  12297.       case FIL_SEE:                     /* SEEK */
  12298.       case FIL_COU:                     /* COUNT */
  12299.         rsize = RD_CHAR;                /* Defaults to /BYTE */
  12300.         cmfdbi(&sw,                     /* Switches */
  12301.                _CMKEY,                  /* fcode */
  12302.                "Channel or switch",     /* hlpmsg */
  12303.                "",                      /* default */
  12304.                "",                      /* addtl string data */
  12305.                ((cx == FIL_SEE) ? nfskswtab : nfcoswtab),
  12306.                4,                       /* addtl numeric data 2: 4 = cmswi */
  12307.                xxstring,                /* Processing function */
  12308.                ((cx == FIL_SEE) ? fskswtab : fcoswtab),
  12309.                &nu                      /* Pointer to next FDB */
  12310.                );
  12311.         cmfdbi(&nu,                     /* Channel number */
  12312.                _CMNUM,                  /* fcode */
  12313.                "Channel",
  12314.                "",                      /* default */
  12315.                "",                      /* addtl string data */
  12316.                10,                      /* addtl numeric data 1: radix */
  12317.                0,                       /* addtl numeric data 2: 0 */
  12318.                xxstring,                /* Processing function */
  12319.                NULL,                    /* Keyword table */
  12320.                NULL                     /* Pointer to next FDB */
  12321.                );
  12322.         do {
  12323.             x = cmfdb(&sw);             /* Parse something */
  12324.             if (x < 0) {
  12325.                 if (x == -3) {
  12326.                     printf("?Channel number required\n");
  12327.                     x = -9;
  12328.                 }
  12329.                 return(x);
  12330.             }
  12331.             if (cmresult.fcode == _CMNUM) /* Channel number */
  12332.               break;
  12333.             else if (cmresult.fcode == _CMKEY) { /* Switch */
  12334.                 char c;
  12335.                 c = cmgbrk();
  12336.                 if ((getval =
  12337.                      (c == ':' || c == '=')) && !(cmgkwflgs() & CM_ARG)) {
  12338.                     printf("?This switch does not take an argument\n");
  12339.                     return(-9);
  12340.                 }
  12341.                 if (cx == FIL_SEE) {
  12342.                     switch (cmresult.nresult) {
  12343.                       case SEE_REL: relative = 1; break;
  12344.                       case SEE_ABS: relative = 0; break;
  12345.                       default: rsize = cmresult.nresult;
  12346.                     }
  12347.                 } else if (cx == FIL_COU) {
  12348.                     switch (cmresult.nresult) {
  12349.                       case COU_LIS: listing = 1; break;
  12350.                       case COU_NOL: listing = 0; break;
  12351.                       default: rsize = cmresult.nresult;
  12352.                     }
  12353.                 }
  12354.             }
  12355.         } while
  12356.           (cmresult.fcode == _CMKEY);
  12357.  
  12358.         n = cmresult.nresult;           /* Channel */
  12359.         debug(F101,"FILE SEEK/COUNT channel","",n);
  12360.         if (cx == FIL_COU) {
  12361.             if ((x = cmcfm()) < 0)
  12362.               return(x);
  12363.             z_filcount = z_count(n,rsize);
  12364.             if (z_filcount < 0) {
  12365.                 rc = z_filcount;
  12366.                 printf("?COUNT error: %s\n",ckferror(rc));
  12367.                 return(-9);
  12368.             }
  12369.             if (listing < 0)
  12370.               listing = !xcmdsrc;
  12371.             if (listing)
  12372.               printf(" %ld %s%s\n",
  12373.                      z_filcount,
  12374.                      ((rsize == RD_CHAR) ? "byte" : "line"),
  12375.                      ((z_filcount == 1L) ? "" : "s")
  12376.                      );
  12377.             return(success = (z_filcount > -1) ? 1 : 0);
  12378.         }
  12379.         cmfdbi(&sw,                     /* SEEK symbolic targets (EOF) */
  12380.                _CMKEY,                  /* fcode */
  12381.                "Channel number;\n or keyword",
  12382.                "",
  12383.                "",                      /* addtl string data */
  12384.                nfsekwtab,               /* addtl numeric data 1: table size */
  12385.                0,                       /* addtl numeric data 2: 4 = cmswi */
  12386.                xxstring,                /* Processing function */
  12387.                fsekwtab,                /* Keyword table */
  12388.                &nu                      /* Pointer to next FDB */
  12389.                );
  12390.         cmfdbi(&nu,                     /* Channel number */
  12391.                _CMNUM,                  /* fcode */
  12392.                "",
  12393.                "",                      /* default */
  12394.                "",                      /* addtl string data */
  12395.                10,                      /* addtl numeric data 1: radix */
  12396.                0,                       /* addtl numeric data 2: 0 */
  12397.                xxstring,                /* Processing function */
  12398.                NULL,                    /* Keyword table */
  12399.                NULL                     /* Pointer to next FDB */
  12400.                );
  12401.         x = cmfdb(&sw);                 /* Parse something */
  12402.         if (x < 0) {
  12403.             if (x == -3) {
  12404.                 printf("?Channel number or EOF required\n");
  12405.                 x = -9;
  12406.             }
  12407.             return(x);
  12408.         }
  12409.         if (cmresult.fcode == _CMNUM) {
  12410.             y = cmresult.nresult;
  12411.             debug(F110,"FILE SEEK atmbuf",atmbuf,0);
  12412.             if (relative < 0) {
  12413.                 if (cx == FIL_SEE && (atmbuf[0] == '+' || atmbuf[0] == '-'))
  12414.                   relative = 1;
  12415.                 else
  12416.                   relative = 0;
  12417.             }
  12418.         } else if (cmresult.fcode == _CMKEY) {
  12419.             eofflg = cmresult.nresult;
  12420.             relative = 0;
  12421.             y = 0 - eofflg;
  12422.         }
  12423.         if ((x = cmcfm()) < 0)
  12424.           return(x);
  12425.         z = y;                          /* Convert to long */
  12426.         y = 1;                          /* Recycle this */
  12427.         z_flush(n);
  12428.         debug(F101,"FILE SEEK relative","",relative);
  12429.         debug(F101,"FILE SEEK rsize","",rsize);
  12430.  
  12431.         if (rsize == RD_CHAR) {         /* Seek to byte position */
  12432.             if (relative > 0) {
  12433.                 long pos;
  12434.                 pos = z_getpos(n);
  12435.                 if (pos < 0L) {
  12436.                     rc = pos;
  12437.                     printf("?Relative SEEK failed: %s\n",ckferror(rc));
  12438.                     return(-9);
  12439.                 }
  12440.                 z += pos;
  12441.             } else {
  12442.                 if (z < 0 && !eofflg) { /* Negative arg but not relative */
  12443.                     y = 0;              /* Remember this was bad */
  12444.                     z = 0;              /* but substitute 0 */
  12445.                 }
  12446.             }
  12447.             debug(F101,"FILE SEEK /CHAR z","",z);
  12448.             if (z < 0 && !eofflg) {
  12449.                 z_error = FX_RNG;
  12450.                 return(success = 0);
  12451.             }
  12452.             if ((rc = z_seek(n,z)) < 0) {
  12453.                 if (rc == FX_EOF) return(success = 0);
  12454.                 printf("?SEEK /BYTE failed - Channel %d: %s\n",n,ckferror(rc));
  12455.                 return(-9);
  12456.             }
  12457.         } else {                        /* Seek to line */
  12458.             if (relative > 0) {
  12459.                 long pos;
  12460.                 pos = z_getline(n);
  12461.                 debug(F101,"FILE SEEK /LINE pos","",pos);
  12462.                 if (pos < 0L) {
  12463.                     rc = pos;
  12464.                     printf("?Relative SEEK failed: %s\n",ckferror(rc));
  12465.                     return(-9);
  12466.                 }
  12467.                 z += pos;
  12468.             }
  12469.             debug(F101,"FILE SEEK /LINE z","",z);
  12470.             debug(F101,"FILE SEEK /LINE eofflg","",eofflg);
  12471.             if (z < 0 && !eofflg) {
  12472.                 z_error = FX_RNG;
  12473.                 return(success = 0);
  12474.             }
  12475.             if ((rc = z_line(n,z)) < 0) {
  12476.                 if (rc == FX_EOF) return(success = 0);
  12477.                 printf("?SEEK /LINE failed - Channel %d: %s\n",n,ckferror(rc));
  12478.                 return(-9);
  12479.             }
  12480.         }
  12481.         return(success = y);
  12482.  
  12483.       case FIL_LIS: {                   /* LIST open files */
  12484. #ifdef CK_TTGWSIZ
  12485.           extern int cmd_rows, cmd_cols;
  12486. #endif /* CK_TTGWSIZ */
  12487.           extern int xaskmore;
  12488.           int i, x, n = 0, paging = 0;
  12489.           char * s;
  12490.  
  12491.           if ((x = cmcfm()) < 0)
  12492.             return(x);
  12493.  
  12494. #ifdef CK_TTGWSIZ
  12495.           if (cmd_rows > 0 && cmd_cols > 0)
  12496. #endif /* CK_TTGWSIZ */
  12497.             paging = xaskmore;
  12498.  
  12499.           printf("System open file limit: %4d\n", z_openmax);
  12500.           printf("Maximum for FILE OPEN:  %4d\n", z_maxchan);
  12501.           printf("Files currently open:   %4d\n\n", z_nopen);
  12502.           n = 4;
  12503.           for (i = 0; i < z_maxchan; i++) {
  12504.               s = z_getname(i);         /* Got one? */
  12505.               if (s) {                  /* Yes */
  12506.                   char m[8];
  12507.                   m[0] = NUL;
  12508.                   printf("%2d. %s",i,s); /* Print name */
  12509.                   n++;                   /* Count it */
  12510.                   x = z_getmode(i);      /* Get modes & print them */
  12511.                   if (x > -1) {
  12512.                       if (x & FM_REA) ckstrncat(m,"R",8);
  12513.                       if (x & FM_WRI) ckstrncat(m,"W",8);
  12514.                       if (x & FM_APP) ckstrncat(m,"A",8);
  12515.                       if (x & FM_BIN) ckstrncat(m,"B",8);
  12516.                       if (m[0])
  12517.                         printf(" (%s)",m);
  12518.                       if (x & FM_EOF)
  12519.                         printf(" [EOF]");
  12520.                       else
  12521.                         printf(" %ld",z_getpos(i)); /* And file position too */
  12522.                   }
  12523.                   printf("\n");
  12524. #ifdef CK_TTGWSIZ
  12525.                   if (paging > 0) {     /* Pause at end of screen */
  12526.                       if (n > cmd_rows - 3) {
  12527.                           if (!askmore())
  12528.                             break;
  12529.                           else
  12530.                             n = 0;
  12531.                       }
  12532.                   }
  12533. #endif /* CK_TTGWSIZ */
  12534.               }
  12535.           }
  12536.           return(success = 1);
  12537.       }
  12538.  
  12539.       case FIL_FLU:                     /* FLUSH */
  12540.         if ((x = cmnum("Channel number","",10,&n, xxstring)) < 0) {
  12541.             if (x == -3) {
  12542.                 printf("?Channel number required\n");
  12543.                 x = -9;
  12544.             }
  12545.             return(x);
  12546.         }
  12547.         if ((x = cmcfm()) < 0)
  12548.           return(x);
  12549.         if ((rc = z_flush(n)) < 0) {
  12550.             printf("?FLUSH failed - Channel %d: %s\n",n,ckferror(rc));
  12551.             return(-9);
  12552.         }
  12553.         return(success = 1);
  12554.  
  12555.       case FIL_STA:                     /* STATUS */
  12556.         if ((x = cmnum("Channel number","",10,&n, xxstring)) < 0) {
  12557.             if (x == -3) {
  12558.                 printf("?Channel number required\n");
  12559.                 x = -9;
  12560.             }
  12561.             return(x);
  12562.         }
  12563.         if ((x = cmcfm()) < 0)
  12564.           return(x);
  12565.         p = blanks + 3;                 /* Tricky formatting... */
  12566.         if (n < 1000) p--;
  12567.         if (n < 100) p--;
  12568.         if (n < 10) p--;
  12569.         if ((rc = z_getmode(n)) < 0) {
  12570.             printf("Channel %d:%s%s\n",n,p,ckferror(rc));
  12571.             return(success = 0);
  12572.         } else if (!rc) {
  12573.             printf("Channel %d:%sNot open\n",n,p);
  12574.             return(success = 0);
  12575.         } else {
  12576.             long xx;
  12577.             s = z_getname(n);
  12578.             if (!s) s = "(name unknown)";
  12579.             printf("Channel %d:%sOpen\n",n,p);
  12580.             printf(" File:        %s\n Modes:      ",s);
  12581.             if (rc & FM_REA) printf(" /READ");
  12582.             if (rc & FM_WRI) printf(" /WRITE");
  12583.             if (rc & FM_APP) printf(" /APPEND");
  12584.             if (rc & FM_BIN) printf(" /BINARY");
  12585.             if (rc & FM_CMD) printf(" /COMMAND");
  12586.             if (rc & FM_EOF) printf(" [EOF]");
  12587.             printf("\n Size:        %ld\n",z_count(n,RD_CHAR));
  12588.             printf(" At byte:     %ld\n",z_getpos(n));
  12589.             xx = z_getline(n);
  12590.             if (xx > -1)
  12591.               printf(" At line:     %ld\n",xx);
  12592.             return(success = 1);
  12593.         }
  12594.       default:
  12595.         return(-2);
  12596.     }
  12597. }
  12598. #endif /* CKCHANNELIO */
  12599.  
  12600. #ifndef NOSETKEY
  12601. /* Save Key maps and in OS/2 Mouse maps */
  12602. int
  12603. savkeys(name,disp) char * name; int disp; {
  12604.     char *tp;
  12605.     static struct filinfo xx;
  12606.     int savfil, i, j, k;
  12607.     char buf[1024];
  12608.  
  12609.     zclose(ZMFILE);
  12610.  
  12611.     if (disp) {
  12612.         xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  12613.         xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = "";
  12614.         xx.lblopts = 0;
  12615.         savfil = zopeno(ZMFILE,name,NULL,&xx);
  12616.     } else savfil = zopeno(ZMFILE,name,NULL,NULL);
  12617.  
  12618.     if (savfil) {
  12619. #ifdef OS2
  12620.         ztime(&tp);
  12621.         zsout(ZMFILE, "; Kermit 95 SAVE KEYMAP file: ");
  12622.         zsoutl(ZMFILE,tp);
  12623.         if (mskkeys) {
  12624.             zsoutl(ZMFILE,
  12625.          "if eq \"\\v(program)\" \"C-Kermit\" set mskermit keycodes on");
  12626.         } else {
  12627.             zsoutl(ZMFILE,
  12628.          "if NOT eq \"\\v(program)\" \"C-Kermit\" stop 1 C-Kermit required.");
  12629.             zsoutl(ZMFILE,"set mskermit keycodes off");
  12630.         }
  12631.         zsoutl(ZMFILE,"");
  12632. #else /* OS2 */
  12633.         ztime(&tp);
  12634.         zsout(ZMFILE, "; C-Kermit SAVE KEYMAP file: ");
  12635.         zsoutl(ZMFILE,tp);
  12636. #endif /* OS2 */
  12637.  
  12638.         zsoutl(ZMFILE,"; Clear previous keyboard mappings ");
  12639.         zsoutl(ZMFILE,"set key clear");
  12640. #ifdef OS2
  12641.         for (k = 0; k < nttkey; k++) {
  12642.             if (!ttkeytab[k].flgs) {
  12643.                 ckmakmsg(buf,1024,
  12644.                          "set terminal key ",
  12645.                          ttkeytab[k].kwd,
  12646.                          " clear",
  12647.                          NULL
  12648.                          );
  12649.                 zsoutl(ZMFILE,buf);
  12650.             }
  12651.         }
  12652. #endif /* OS2 */
  12653.         zsoutl(ZMFILE,"");
  12654.  
  12655.         for (i = 0; i < KMSIZE; i++) {
  12656.             if (macrotab[i]) {
  12657.                 int len = strlen((char *)macrotab[i]);
  12658. #ifdef OS2
  12659.                 ckmakmsg(buf,
  12660.                          1024,
  12661.                          "set key \\",
  12662.                          ckitoa(mskkeys ? cktomsk(i) : i),
  12663.                          " ",
  12664.                          NULL
  12665.                          );
  12666. #else /* OS2 */
  12667.                 ckmakmsg(buf,
  12668.                          1024,
  12669.                          "set key \\",
  12670.                          ckitoa(i),
  12671.                          NULL,NULL
  12672.                          );
  12673. #endif /* OS2 */
  12674.                 zsout(ZMFILE,buf);
  12675.  
  12676.                 for (j = 0; j < len; j++) {
  12677.                     char ch = macrotab[i][j];
  12678.                     if (ch <= SP || ch >= DEL ||
  12679.                          ch == '-' || ch == ',' ||
  12680.                          ch == '{' || ch == '}' ||
  12681.                          ch == ';' || ch == '?' ||
  12682.                          ch == '.' || ch == '\'' ||
  12683.                          ch == '\\' || ch == '/' ||
  12684.                          ch == '#') {
  12685.                         ckmakmsg(buf,1024,"\\{",ckitoa((int)ch),"}",NULL);
  12686.                         zsout(ZMFILE,buf);
  12687.                     } else {
  12688.                         ckmakmsg(buf,1024,ckctoa((char)ch),NULL,NULL,NULL);
  12689.                         zsout(ZMFILE,buf);
  12690.                     }
  12691.                 }
  12692. #ifdef OS2
  12693.                 ckmakmsg(buf,1024,"\t; ",keyname(i),NULL,NULL);
  12694.                 zsoutl(ZMFILE,buf);
  12695. #else
  12696.                 zsoutl(ZMFILE,"");
  12697. #endif /* OS2 */
  12698.             } else if ( keymap[i] != i ) {
  12699. #ifndef NOKVERBS
  12700.                 if (IS_KVERB(keymap[i])) {
  12701.                     for (j = 0; j < nkverbs; j++)
  12702.                       if (kverbs[j].kwval == (keymap[i] & ~F_KVERB))
  12703.                         break;
  12704.                     if (j != nkverbs) {
  12705. #ifdef OS2
  12706. #ifdef COMMENT
  12707.                         sprintf(buf, "set key \\%d \\K%s\t; %s",
  12708.                                 mskkeys ? cktomsk(i) : i,
  12709.                                 kverbs[j].kwd, keyname(i)
  12710.                                 );
  12711. #else
  12712.                         ckmakxmsg(buf,  /* 12 string args */
  12713.                                   1024,
  12714.                                   "set key \\",
  12715.                                   ckitoa(mskkeys ? cktomsk(i) : i),
  12716.                                   " \\K",
  12717.                                   kverbs[j].kwd,
  12718.                                   "\t; ",
  12719.                                   keyname(i),
  12720.                                   NULL, NULL, NULL, NULL, NULL, NULL);
  12721. #endif /* COMMENT */
  12722.                         zsoutl(ZMFILE,buf);
  12723. #else
  12724. #ifdef COMMENT
  12725.                         sprintf(buf, "set key \\%d \\K%s", i, kverbs[j].kwd);
  12726. #else
  12727.                         ckmakmsg(buf,1024,
  12728.                                  "set key \\",
  12729.                                  ckitoa(i),
  12730.                                  " \\K",
  12731.                                  kverbs[j].kwd
  12732.                                  );
  12733. #endif /* COMMENT */
  12734.                         zsoutl(ZMFILE,buf);
  12735. #endif
  12736.                     }
  12737.                 } else
  12738. #endif /* NOKVERBS */
  12739.                   {
  12740. #ifdef OS2
  12741. #ifdef COMMENT
  12742.                       sprintf(buf, "set key \\%d \\{%d}\t; %s",
  12743.                               mskkeys ? cktomsk(i) : i,
  12744.                               keymap[i],
  12745.                               keyname(i)
  12746.                               );
  12747. #else
  12748.                       ckmakxmsg(buf,    /* 8 string args */
  12749.                                 1024,
  12750.                                 "set key \\",
  12751.                                 ckitoa(mskkeys ? cktomsk(i) : i),
  12752.                                 " \\{",
  12753.                                 ckitoa(keymap[i]),
  12754.                                 "}\t; ",
  12755.                                 keyname(i),
  12756.                                 NULL,NULL,NULL,NULL,NULL,NULL);
  12757. #endif /* COMMENT */
  12758.                       zsoutl(ZMFILE,buf);
  12759. #else
  12760. #ifdef COMMENT
  12761.                       sprintf(buf, "set key \\%d \\{%d}", i, keymap[i]);
  12762. #else
  12763.                       ckmakxmsg(buf,1024,
  12764.                                "set key \\",
  12765.                                ckitoa(i),
  12766.                                " \\{",
  12767.                                ckitoa(keymap[i]),
  12768.                                "}",
  12769.                                NULL,NULL,NULL,NULL,NULL,NULL,NULL);
  12770. #endif /* COMMENT */
  12771.                       zsoutl(ZMFILE,buf);
  12772. #endif /* OS2 */
  12773.                   }
  12774.             }
  12775.         }
  12776. #ifdef OS2
  12777.         /* OS/2 also has the SET TERMINAL KEY <termtype> defines */
  12778.         for (k = 0; k < nttkey; k++) {
  12779.             extern struct keynode * ttkeymap[];
  12780.             struct keynode * pnode = NULL;
  12781.  
  12782.             if (ttkeytab[k].flgs)       /* Don't process CM_INV or CM_ABR */
  12783.               continue;
  12784.  
  12785.             zsoutl(ZMFILE,"");
  12786.             ckmakmsg(buf,1024,"; SET TERMINAL KEY ",ttkeytab[k].kwd,NULL,NULL);
  12787.             zsoutl(ZMFILE,buf);
  12788.  
  12789.             for (pnode = ttkeymap[ttkeytab[k].kwval];
  12790.                  pnode;
  12791.                  pnode = pnode->next
  12792.                  ) {
  12793.                 switch (pnode->def.type) {
  12794.                   case key:
  12795. #ifdef COMMENT
  12796.                     sprintf(buf, "set terminal key %s \\%d \\{%d}\t; %s",
  12797.                             ttkeytab[k].kwd,
  12798.                             mskkeys ? cktomsk(pnode->key) : pnode->key,
  12799.                             pnode->def.key.scancode,
  12800.                             keyname(pnode->key)
  12801.                             );
  12802. #else
  12803.                     ckmakxmsg(buf,
  12804.                               1024,
  12805.                               "set terminal key ",
  12806.                               ttkeytab[k].kwd,
  12807.                               " \\",
  12808.                               ckitoa(mskkeys ?
  12809.                                      cktomsk(pnode->key) :
  12810.                                      pnode->key),
  12811.                               " \\{",
  12812.                               ckitoa(pnode->def.key.scancode),
  12813.                               "}\t; ",
  12814.                               keyname(pnode->key),
  12815.                               NULL,NULL,NULL,NULL
  12816.                               );
  12817. #endif /* COMMENT */
  12818.                     zsoutl(ZMFILE,buf);
  12819.                     break;
  12820.                   case kverb:
  12821.                     for (j = 0; j < nkverbs; j++)
  12822.                       if (kverbs[j].kwval == (pnode->def.kverb.id & ~F_KVERB))
  12823.                         break;
  12824.                     if (j != nkverbs) {
  12825. #ifdef COMMENT
  12826.                         sprintf(buf, "set terminal key %s \\%d \\K%s\t; %s",
  12827.                                 ttkeytab[k].kwd,
  12828.                                 mskkeys ? cktomsk(pnode->key) : pnode->key,
  12829.                                 kverbs[j].kwd, keyname(pnode->key)
  12830.                                 );
  12831. #else
  12832.                         ckmakxmsg(buf,
  12833.                                   1024,
  12834.                                   "set terminal key ",
  12835.                                   ttkeytab[k].kwd,
  12836.                                   " \\",
  12837.                                   ckitoa(mskkeys ?
  12838.                                          cktomsk(pnode->key) :
  12839.                                          pnode->key),
  12840.                                   " \\K",
  12841.                                   kverbs[j].kwd,
  12842.                                   "\t; ",
  12843.                                   keyname(pnode->key),
  12844.                                   NULL,NULL,NULL,NULL
  12845.                                   );
  12846. #endif /* COMMENT */
  12847.                         zsoutl(ZMFILE,buf);
  12848.                     }
  12849.                     break;
  12850.                   case macro: {
  12851.                       int len = strlen((char *)pnode->def.macro.string);
  12852. #ifdef COMMENT
  12853.                       sprintf(buf,"set terminal key %s \\%d ",
  12854.                               ttkeytab[k].kwd,
  12855.                               mskkeys ? cktomsk(pnode->key) : pnode->key);
  12856. #else
  12857.                       ckmakxmsg(buf,
  12858.                                1024,
  12859.                                "set terminal key ",
  12860.                                ttkeytab[k].kwd,
  12861.                                " \\",
  12862.                                ckitoa(mskkeys ?
  12863.                                       cktomsk(pnode->key) :
  12864.                                       pnode->key),
  12865.                                " ",
  12866.                                NULL,NULL,NULL,NULL,NULL,NULL,NULL
  12867.                               );
  12868. #endif /* COMMENT */
  12869.                       zsout(ZMFILE,buf);
  12870.  
  12871.                       for (j = 0; j < len; j++) {
  12872.                           char ch = pnode->def.macro.string[j];
  12873.                           if (ch <= SP || ch >= DEL ||
  12874.                                ch == '-' || ch == ',' ||
  12875.                                ch == '{' || ch == '}' ||
  12876.                                ch == ';' || ch == '?' ||
  12877.                                ch == '.' || ch == '\'' ||
  12878.                                ch == '\\' || ch == '/' ||
  12879.                                ch == '#') {
  12880.                               ckmakmsg(buf,1024,
  12881.                                        "\\{",ckitoa((int)ch),"}",NULL);
  12882.                               zsout(ZMFILE,buf);
  12883.                           } else {
  12884.                               ckmakmsg(buf,1024,
  12885.                                        ckctoa((char)ch),NULL,NULL,NULL);
  12886.                               zsout(ZMFILE,buf);
  12887.                           }
  12888.                       }
  12889.                       ckmakmsg(buf,1024,"\t; ",keyname(pnode->key),NULL,NULL);
  12890.                       zsoutl(ZMFILE,buf);
  12891.                       break;
  12892.                   }
  12893.                   case literal: {
  12894.                       int len = strlen((char *)pnode->def.literal.string);
  12895. #ifdef COMMENT
  12896.                       sprintf(buf,"set terminal key %s /literal \\%d ",
  12897.                               ttkeytab[k].kwd,
  12898.                               mskkeys ? cktomsk(pnode->key) : pnode->key);
  12899. #else
  12900.                       ckmakxmsg(buf,
  12901.                                1024,
  12902.                                "set terminal key ",
  12903.                                ttkeytab[k].kwd,
  12904.                                " /literal \\",
  12905.                                ckitoa(mskkeys ?
  12906.                                       cktomsk(pnode->key) :
  12907.                                       pnode->key),
  12908.                                " ",
  12909.                                NULL,NULL,NULL,NULL,NULL,NULL,NULL);
  12910. #endif /* COMMENT */
  12911.                       zsout(ZMFILE,buf);
  12912.  
  12913.                       for (j = 0; j < len; j++) {
  12914.                           char ch = pnode->def.literal.string[j];
  12915.                           if (ch <= SP || ch >= DEL ||
  12916.                                ch == '-' || ch == ',' ||
  12917.                                ch == '{' || ch == '}' ||
  12918.                                ch == ';' || ch == '?' ||
  12919.                                ch == '.' || ch == '\'' ||
  12920.                                ch == '\\' || ch == '/' ||
  12921.                                ch == '#') {
  12922.                               ckmakmsg(buf,1024,
  12923.                                        "\\{",ckitoa((int)ch),"}",NULL);
  12924.                               zsout(ZMFILE,buf);
  12925.                           } else {
  12926.                               ckmakmsg(buf,1024,
  12927.                                        ckctoa((char)ch),NULL,NULL,NULL);
  12928.                               zsout(ZMFILE,buf);
  12929.                           }
  12930.                       }
  12931.                       ckmakmsg(buf,1024,"\t; ",keyname(pnode->key),NULL,NULL);
  12932.                       zsoutl(ZMFILE,buf);
  12933.                       break;
  12934.                   }
  12935.                   case esc:
  12936. #ifdef COMMENT
  12937.                     sprintf(buf,
  12938.                        "set terminal key %s /literal \\%d \\{%d}\\{%d}\t; %s",
  12939.                             ttkeytab[k].kwd,
  12940.                             mskkeys ? cktomsk(pnode->key) : pnode->key,
  12941.                             ISDG200(ttkeytab[k].kwval) ? 30 : 27,
  12942.                             pnode->def.esc.key & ~F_ESC,
  12943.                             keyname(pnode->key)
  12944.                             );
  12945. #else
  12946.                     ckmakxmsg(buf,
  12947.                               1024,
  12948.                               "set terminal key ",
  12949.                               ttkeytab[k].kwd,
  12950.                               " /literal \\",
  12951.                               ckitoa(mskkeys ?
  12952.                                      cktomsk(pnode->key) :
  12953.                                      pnode->key),
  12954.                               " \\{",
  12955.                               ckitoa(ISDG200(ttkeytab[k].kwval) ? 30 : 27),
  12956.                               "}\\{",
  12957.                               ckitoa(pnode->def.esc.key & ~F_ESC),
  12958.                               "}\t; ",
  12959.                               keyname(pnode->key),
  12960.                               NULL,NULL
  12961.                               );
  12962. #endif /* COMMENT */
  12963.                     zsoutl(ZMFILE,buf);
  12964.                     break;
  12965.                   case csi:
  12966. #ifdef COMMENT
  12967.                     sprintf(buf,
  12968.                        "set terminal key %s /literal \\%d \\{27}[\\{%d}\t; %s",
  12969.                             ttkeytab[k].kwd,
  12970.                             mskkeys ? cktomsk(pnode->key) : pnode->key,
  12971.                             pnode->def.csi.key & ~F_CSI,
  12972.                             keyname(pnode->key)
  12973.                             );
  12974. #else
  12975.                     ckmakxmsg(buf,
  12976.                               1024,
  12977.                               "set terminal key ",
  12978.                               ttkeytab[k].kwd,
  12979.                               " /literal \\",
  12980.                               ckitoa(mskkeys ?
  12981.                                      cktomsk(pnode->key) :
  12982.                                      pnode->key),
  12983.                               " \\{27}[\\{",
  12984.                               ckitoa(pnode->def.csi.key & ~F_CSI),
  12985.                               "}\t; ",
  12986.                               keyname(pnode->key),
  12987.                               NULL,NULL,NULL,NULL
  12988.                               );
  12989. #endif /* COMMENT */
  12990.                     zsoutl(ZMFILE,buf);
  12991.                     break;
  12992.                   default:
  12993.                     continue;
  12994.                 }
  12995.             }
  12996.         }
  12997. #endif /* OS2 */
  12998.  
  12999.         zsoutl(ZMFILE,"");
  13000.         zsoutl(ZMFILE,"; End");
  13001.         zclose(ZMFILE);
  13002.         return(success = 1);
  13003.     } else {
  13004.         return(success = 0);
  13005.     }
  13006. }
  13007. #endif /* NOSETKEY */
  13008.  
  13009. #define SV_SCRL 0
  13010. #define SV_HIST 1
  13011.  
  13012. #ifdef OS2
  13013. #ifndef NOLOCAL
  13014. static struct keytab trmtrmopt[] = {
  13015.     { "scrollback", SV_SCRL, 0 }
  13016. };
  13017. #endif /* NOLOCAL */
  13018. #endif /* OS2 */
  13019.  
  13020. static struct keytab cmdtrmopt[] = {
  13021. #ifdef CK_RECALL
  13022.     { "history",    SV_HIST, 0 },
  13023. #endif /* CK_RECALL */
  13024. #ifdef OS2
  13025. #ifndef NOLOCAL
  13026.     { "scrollback", SV_SCRL, 0 },
  13027. #endif /* NOLOCAL */
  13028. #endif /* OS2 */
  13029.     { "", 0, 0 }
  13030. };
  13031. static int ncmdtrmopt = (sizeof (cmdtrmopt) / sizeof (struct keytab)) - 1;
  13032.  
  13033. #ifdef OS2
  13034. #ifndef NOLOCAL
  13035. _PROTOTYP(int savscrbk, (int, char *, int));
  13036. #endif /* NOLOCAL */
  13037. #endif /* OS2 */
  13038.  
  13039. #ifdef CK_RECALL
  13040. _PROTOTYP(int savhistory, (char *, int));
  13041. #endif /* CK_RECALL */
  13042.  
  13043. int
  13044. dosave(xx) int xx; {
  13045.     int x, y = 0, disp;
  13046.     char * s = NULL;
  13047.     extern struct keytab disptb[];
  13048. #ifdef ZFNQFP
  13049.     struct zfnfp * fnp;
  13050. #endif /* ZFNQFP */
  13051.  
  13052. #ifndef NOSETKEY
  13053.     if (xx == XSKEY) {                  /* SAVE KEYMAP.. */
  13054.         z = cmofi("Name of Kermit command file","keymap.ksc",&s,xxstring);
  13055.     } else {
  13056. #endif /* NOSETKEY */
  13057.         switch (xx) {
  13058.           case XSCMD:                   /* SAVE COMMAND.. */
  13059.             if ((y = cmkey(cmdtrmopt, ncmdtrmopt, "What to save",
  13060. #ifdef OS2
  13061.                            "scrollback",
  13062. #else
  13063.                            "history",
  13064. #endif /* OS2 */
  13065.                            xxstring)) < 0)
  13066.               return(y);
  13067.             break;
  13068. #ifdef OS2
  13069. #ifndef NOLOCAL
  13070.           case XSTERM:                  /* SAVE TERMINAL.. */
  13071.             if ((y = cmkey(trmtrmopt,1,
  13072.                            "What to save","scrollback",xxstring)) < 0)
  13073.               return(y);
  13074.             break;
  13075. #endif /* NOLOCAL */
  13076. #endif /* OS2 */
  13077.         }
  13078.         z = cmofi("Filename",
  13079.                   ((y == SV_SCRL) ? "scrollbk.txt" : "history.txt"),
  13080.                   &s,
  13081.                   xxstring
  13082.                   );
  13083. #ifndef NOSETKEY
  13084.     }
  13085. #endif /* NOSETKEY */
  13086.     if (z < 0)                          /* Check output-file parse results */
  13087.       return(z);
  13088.     if (z == 2) {
  13089.         printf("?Sorry, %s is a directory name\n",s);
  13090.         return(-9);
  13091.     }
  13092. #ifdef ZFNQFP
  13093.     if ((fnp = zfnqfp(s,TMPBUFSIZ - 1,tmpbuf))) {/* Convert to full pathname */
  13094.         if (fnp->fpath)
  13095.           if ((int) strlen(fnp->fpath) > 0)
  13096.             s = fnp->fpath;
  13097.     }
  13098. #endif /* ZFNQFP */
  13099.  
  13100.     ckstrncpy(line,s,LINBUFSIZ);        /* Make safe copy of pathname */
  13101.     s = line;
  13102. #ifdef MAC
  13103.     z = 0;
  13104. #else
  13105.     /* Get NEW/APPEND disposition */
  13106.     if ((z = cmkey(disptb,2,"Disposition","new",xxstring)) < 0)
  13107.       return(z);
  13108. #endif /* MAC */
  13109.     disp = z;
  13110.     if ((x = cmcfm()) < 0)              /* Get confirmation */
  13111.       return(x);
  13112.  
  13113.     switch (xx) {                       /* Do action.. */
  13114. #ifndef NOSETKEY
  13115.       case XSKEY:                       /* SAVE KEYMAP */
  13116.         return (savkeys(s,disp));
  13117. #endif /* NOSETKEY */
  13118.  
  13119.       case XSCMD:                       /* SAVE COMMAND.. */
  13120. #ifdef OS2
  13121. #ifndef NOLOCAL
  13122.         if (y == SV_SCRL)               /* .. SCROLLBACK */
  13123.           return(success = savscrbk(VCMD,s,disp));
  13124. #endif /* NOLOCAL */
  13125. #endif /* OS2 */
  13126. #ifndef NORECALL
  13127.         if (y == SV_HIST)               /* .. HISTORY */
  13128.           return(success = savhistory(s,disp));
  13129.         break;
  13130. #endif /* NORECALL */
  13131.  
  13132. #ifdef OS2
  13133. #ifndef NOLOCAL
  13134.       case XSTERM:                      /* SAVE TERMINAL SCROLLBACK */
  13135.         return(success = savscrbk(VTERM,s,disp));
  13136. #endif /* NOLOCAL */
  13137. #endif /* OS2 */
  13138.     }
  13139.     success = 0;
  13140.     return(-2);
  13141. }
  13142.  
  13143. /*
  13144.   R E A D T E X T
  13145.  
  13146.   Read text with a custom prompt into given buffer using command parser but
  13147.   with no echoing or entry into recall buffer.
  13148. */
  13149. int
  13150. readtext(prmpt, buffer, bufsiz) char * prmpt; char * buffer; int bufsiz; {
  13151. #ifdef CK_RECALL
  13152.     extern int on_recall;               /* Around Password prompting */
  13153. #endif /* CK_RECALL */
  13154.     int rc;
  13155. #ifndef NOLOCAL
  13156. #ifdef OS2
  13157.     extern int vmode;
  13158.     extern int startflags;
  13159.     int vmode_sav = vmode;
  13160.  
  13161.     if (!prmpt) prmpt = "";
  13162.  
  13163.     if (win95_popup && !(startflags & 96)
  13164. #ifdef IKSD
  13165.          && !inserver
  13166. #endif /* IKSD */
  13167.          )
  13168.       return(popup_readtext(vmode,NULL,prmpt,buffer,bufsiz,0));
  13169.  
  13170.     if (vmode == VTERM) {
  13171.         vmode = VCMD;
  13172.         VscrnIsDirty(VTERM);
  13173.         VscrnIsDirty(VCMD);
  13174.     }
  13175. #endif /* OS2 */
  13176. #endif /* NOLOCAL */
  13177.  
  13178. #ifdef CK_RECALL
  13179.     on_recall = 0;
  13180. #endif /* CK_RECALL */
  13181.     cmsavp(psave,PROMPTL);              /* Save old prompt */
  13182.     cmsetp(prmpt);                      /* Make new prompt */
  13183.     concb((char)escape);                /* Put console in cbreak mode */
  13184.     cmini(1);                           /* and echo mode */
  13185.     if (pflag) prompt(xxstring);        /* Issue prompt if at top level */
  13186.     cmres();                            /* Reset the parser */
  13187.     for (rc = -1; rc < 0; ) {           /* Prompt till they answer */
  13188.         rc = cmtxt("","",&s,NULL);      /* Get a literal line of text */
  13189.         cmres();                        /* Reset the parser again */
  13190.     }
  13191.     ckstrncpy(buffer,s,bufsiz);
  13192.     cmsetp(psave);                      /* Restore original prompt */
  13193.  
  13194. #ifndef NOLOCAL
  13195. #ifdef OS2
  13196.     if (vmode != vmode_sav) {
  13197.         vmode = VTERM;
  13198.         VscrnIsDirty(VCMD);
  13199.         VscrnIsDirty(VTERM);
  13200.     }
  13201. #endif /* OS2 */
  13202. #endif /* NOLOCAL */
  13203.     return(0);
  13204. }
  13205. #endif /* NOICP */
  13206.  
  13207. /* A general function to allow a Password or other information  */
  13208. /* to be read from the command prompt without it going into     */
  13209. /* the recall buffer or being echo'd.                           */
  13210.  
  13211. int
  13212. readpass(prmpt, buffer, bufsiz) char * prmpt; char * buffer; int bufsiz; {
  13213.     int x;
  13214. #ifdef NOICP
  13215.     if (!prmpt) prmpt = "";
  13216.     printf("%s", prmpt);
  13217. #ifdef COMMENT
  13218.     /* Some linkers won't allow this because it's unsafe */
  13219.     gets(buffer);
  13220. #else  /* COMMENT */
  13221.     {
  13222.         int c, i; char * p;
  13223.         p = buffer;
  13224.         for (i = 0; i < bufsiz-1; i++) {
  13225.             if ((c = getchar()) == EOF)
  13226.               break;
  13227.             if (c < SP)
  13228.               break;
  13229.             buffer[i] = c;
  13230.         }
  13231.         buffer[i] = NUL;
  13232.     }
  13233. #endif /* COMMENT */
  13234.     return(1);
  13235. #else  /* NOICP */
  13236. #ifdef CK_RECALL
  13237.     extern int on_recall;               /* around Password prompting */
  13238. #endif /* CK_RECALL */
  13239.     int rc;
  13240. #ifndef NOLOCAL
  13241. #ifdef OS2
  13242.     extern int vmode;
  13243.     extern int startflags;
  13244.     int vmode_sav = vmode;
  13245. #endif /* OS2 */
  13246. #endif /* NOLOCAL */
  13247. #ifdef CKSYSLOG
  13248.     int savlog;
  13249. #endif /* CKSYSLOG */
  13250.     if (!prmpt) prmpt = "";
  13251. #ifndef NOLOCAL
  13252.     debok = 0;                          /* Don't log */
  13253. #ifdef OS2
  13254.     if (win95_popup && !(startflags & 96)
  13255. #ifdef IKSD
  13256.          && !inserver
  13257. #endif /* IKSD */
  13258.          ) {
  13259.         x = popup_readpass(vmode,NULL,prmpt,buffer,bufsiz,0);
  13260.         debok = 1;
  13261.         return(x);
  13262.     }
  13263. #endif /* OS2 */
  13264. #endif /* NOLOCAL */
  13265.  
  13266. #ifdef CKSYSLOG
  13267.     savlog = ckxsyslog;                 /* Save and turn off syslogging */
  13268.     ckxsyslog = 0;
  13269. #endif /* CKSYSLOG */
  13270. #ifndef NOLOCAL
  13271. #ifdef OS2
  13272.     if (vmode == VTERM) {
  13273.         vmode = VCMD;
  13274.         VscrnIsDirty(VTERM);
  13275.         VscrnIsDirty(VCMD);
  13276.     }
  13277. #endif /* OS2 */
  13278. #endif /* NOLOCAL */
  13279. #ifdef CK_RECALL
  13280.     on_recall = 0;
  13281. #endif /* CK_RECALL */
  13282.     cmsavp(psave,PROMPTL);              /* Save old prompt */
  13283.     cmsetp(prmpt);                      /* Make new prompt */
  13284.     concb((char)escape);                /* Put console in cbreak mode */
  13285.     cmini(0);                           /* and no-echo mode */
  13286.     if (pflag) prompt(xxstring);        /* Issue prompt if at top level */
  13287.     cmres();                            /* Reset the parser */
  13288.     for (rc = -1; rc < 0; ) {           /* Prompt till they answer */
  13289.         rc = cmtxt("","",&s,NULL);      /* Get a literal line of text */
  13290.         cmres();                        /* Reset the parser again */
  13291.     }
  13292.     ckstrncpy(buffer,s,bufsiz);
  13293.     printf("\r\n");                     /* Echo a CRLF */
  13294.     cmsetp(psave);                      /* Restore original prompt */
  13295.     cmini(1);                           /* Restore echo mode */
  13296. #ifndef NOLOCAL
  13297. #ifdef OS2
  13298.     if (vmode != vmode_sav) {
  13299.         vmode = VTERM;
  13300.         VscrnIsDirty(VCMD);
  13301.         VscrnIsDirty(VTERM);
  13302.     }
  13303. #endif /* OS2 */
  13304. #endif /* NOLOCAL */
  13305. #ifdef CKSYSLOG
  13306.     ckxsyslog = savlog;                 /* Restore syslogging */
  13307. #endif /* CKSYSLOG */
  13308.     debok = 1;
  13309.     return(0);
  13310. #endif /* NOICP */
  13311. }
  13312.  
  13313. #ifndef NOICP
  13314. struct keytab authtab[] = {             /* Available authentication types */
  13315. #ifdef CK_KERBEROS
  13316.     { "k4",        AUTH_KRB4, CM_INV },
  13317.     { "k5",        AUTH_KRB5, CM_INV },
  13318.     { "kerberos4", AUTH_KRB4, 0      },
  13319.     { "kerberos5", AUTH_KRB5, 0      },
  13320.     { "krb4",      AUTH_KRB4, CM_INV },
  13321.     { "krb5",      AUTH_KRB5, CM_INV },
  13322. #endif /* CK_KERBEROS */
  13323. #ifdef NT
  13324.     { "ntlm",      AUTH_NTLM, 0 },
  13325. #endif /* NT */
  13326. #ifdef CK_SRP
  13327.     { "srp",       AUTH_SRP,  0 },
  13328. #endif /* CK_SRP */
  13329. #ifdef CK_SSL
  13330.     { "ssl",       AUTH_SSL,  0 },
  13331. #endif /* CK_SSL */
  13332.     { "",          0,         0 }
  13333. };
  13334. int authtabn = sizeof(authtab)/sizeof(struct keytab)-1;
  13335.  
  13336. #ifdef CK_KERBEROS
  13337. struct keytab kerbtab[] = {             /* Kerberos authentication types */
  13338.     { "k4",        AUTH_KRB4, CM_INV },
  13339.     { "k5",        AUTH_KRB5, CM_INV },
  13340.     { "kerberos4", AUTH_KRB4, 0      },
  13341.     { "kerberos5", AUTH_KRB5, 0      },
  13342.     { "krb4",      AUTH_KRB4, CM_INV },
  13343.     { "krb5",      AUTH_KRB5, CM_INV }
  13344. };
  13345. int kerbtabn = sizeof(kerbtab)/sizeof(struct keytab);
  13346.  
  13347. static struct keytab krb_s_tbl[] = {    /* AUTHENTICATE command switches: */
  13348.     { "/cache",   KRB_S_CA, CM_ARG }
  13349. };
  13350. static int krb_s_n = sizeof(krb_s_tbl)/sizeof(struct keytab);
  13351.  
  13352. static struct keytab krb_v_tbl[] = {    /* KERBEROS version values: */
  13353.     { "4",    4, 0 },
  13354.     { "5",    5, 0 },                   /* (add others as needed...) */
  13355.     { "auto", 0, 0 }                    /* Note: 0 = auto */
  13356. };
  13357. static int krb_v_n = sizeof(krb_v_tbl)/sizeof(struct keytab);
  13358.  
  13359. static struct keytab krb_a_tbl[] = {    /* KERBEROS actions: */
  13360.     { "destroy",           KRB_A_DE, 0 },
  13361.     { "initialize",        KRB_A_IN, 0 },
  13362.     { "list-credentials",  KRB_A_LC, 0 }
  13363. };
  13364. static int krb_a_n = sizeof(krb_a_tbl)/sizeof(struct keytab);
  13365.  
  13366. static struct keytab krb4_i_tbl[] = {   /* KERBEROS 4 INITIALIZE switches: */
  13367.     { "/brief",            KRB_I_BR, 0 },      /* /BRIEF       */
  13368.     { "/instance",         KRB_I_IN, CM_ARG }, /* /INSTANCE:   */
  13369.     { "/lifetime",         KRB_I_LF, CM_ARG }, /* /LIFETIME:   */
  13370.     { "/not-preauth",      KRB_I_NPA, 0 },     /* /NOT-PREAUTH */
  13371.     { "/password",         KRB_I_PW, CM_ARG }, /* /PASSWORD:   */
  13372. #ifdef OS2
  13373.     { "/popup",            KRB_I_POP, 0 },     /* /POPUP       */
  13374. #endif /* OS2 */
  13375.     { "/preauth",          KRB_I_PA, 0 },      /* /PREAUTH     */
  13376.     { "/realm",            KRB_I_RL, CM_ARG }, /* /REALM:      */
  13377.     { "/verbose",          KRB_I_VB, 0 },      /* /VERBOSE     */
  13378.     { "", 0, 0 }
  13379. };
  13380. static int krb4_i_n = sizeof(krb4_i_tbl)/sizeof(struct keytab) - 1;
  13381.  
  13382. static struct keytab krb5_i_tbl[] = {   /* KERBEROS 5 INITIALIZE switches: */
  13383.     { "/addresses",        KRB_I_ADR, CM_ARG },
  13384.     { "/forwardable",      KRB_I_FW,  0 },         /* /FORWARDABLE */
  13385.     { "/instance",         KRB_I_IN, CM_ARG }, /* /INSTANCE:   */
  13386.     { "/k4",               KRB_I_K4,  CM_INV }, /* /KERBEROS4   */
  13387.     { "/kerberos4",        KRB_I_K4,  0 },      /* /KERBEROS4   */
  13388.     { "/krb4",             KRB_I_K4,  CM_INV }, /* /KERBEROS4   */
  13389.     { "/lifetime",         KRB_I_LF,  CM_ARG }, /* /LIFETIME:   */
  13390.     { "/no-addresses",     KRB_I_NAD, 0 },      /* /NO-ADDRESSES */
  13391.     { "/no-k4",            KRB_I_NK4, CM_INV },/* /NO-KERBEROS4 */
  13392.     { "/no-kerberos4",     KRB_I_NK4, 0 },     /* /NO-KERBEROS4 */
  13393.     { "/no-krb4",          KRB_I_NK4, CM_INV },/* /NO-KERBEROS4 */
  13394.     { "/not-forwardable",  KRB_I_NFW, 0 },         /* /NOT-FORWARDABLE */
  13395.     { "/not-proxiable",    KRB_I_NPR, 0 },     /* /NOT-PROXIABLE   */
  13396.     { "/password",         KRB_I_PW,  CM_ARG }, /* /PASSWORD:   */
  13397. #ifdef OS2
  13398.     { "/popup",            KRB_I_POP, 0 },     /* /POPUP       */
  13399. #endif /* OS2 */
  13400.     { "/postdate",         KRB_I_PD, CM_ARG }, /* /POSTDATE:   */
  13401.     { "/pr",               KRB_I_PR, CM_INV|CM_ABR }, /* to allow for */
  13402.     { "/pro",              KRB_I_PR, CM_INV|CM_ABR }, /* different spellings */
  13403.     { "/prox",             KRB_I_PR, CM_INV|CM_ABR },
  13404.     { "/proxiable",        KRB_I_PR, 0 },      /* /PROXIABLE   */
  13405.     { "/proxyable",        KRB_I_PR, CM_INV }, /* /PROXYABLE   */
  13406.     { "/realm",            KRB_I_RL, CM_ARG }, /* /REALM:      */
  13407.     { "/renew",            KRB_I_RN, 0 },          /* /RENEW       */
  13408.     { "/renewable",        KRB_I_RB, CM_ARG }, /* /RENEWABLE:  */
  13409.     { "/service",          KRB_I_SR, CM_ARG }, /* /SERVICE:    */
  13410.     { "/validate",         KRB_I_VA, 0 },          /* /VALIDATE    */
  13411.     { "", 0, 0 }
  13412. };
  13413. static int krb5_i_n = sizeof(krb5_i_tbl)/sizeof(struct keytab) - 1;
  13414.  
  13415. static struct keytab klctab[] = {       /* List Credentials switches*/
  13416.     { "/addresses",  XYKLCAD, 0 },
  13417.     { "/encryption", XYKLCEN, 0 },
  13418.     { "/flags",      XYKLCFL, 0 }
  13419. };
  13420. static int nklctab = sizeof(klctab)/sizeof(struct keytab);
  13421.  
  13422. extern int krb_action;
  13423. extern struct krb_op_data krb_op;
  13424.  
  13425. extern struct krb5_list_cred_data krb5_lc;
  13426. extern struct krb5_init_data krb5_init;
  13427. extern char * krb5_d_principal;         /* Default principal */
  13428. extern char * krb5_d_instance;
  13429. extern char * krb5_d_realm;             /* Default realm */
  13430. extern char * krb5_d_cc;                /* Default credentials cache */
  13431. extern char * krb5_d_srv;               /* Default service name */
  13432. extern int    krb5_d_lifetime;          /* Default lifetime */
  13433. extern int    krb5_d_forwardable;
  13434. extern int    krb5_d_proxiable;
  13435. extern int    krb5_d_renewable;
  13436. extern int    krb5_autoget;
  13437. extern int    krb5_autodel;
  13438. extern int    krb5_d_getk4;
  13439. extern int    krb5_d_no_addresses;
  13440. extern int    krb5_checkaddrs;
  13441. extern char * krb5_d_addrs[];
  13442. extern char * k5_keytab;                /* Keytab file */
  13443.  
  13444. extern struct krb4_init_data krb4_init;
  13445. extern char * krb4_d_principal;         /* Default principal */
  13446. extern char * krb4_d_realm;             /* Default realm */
  13447. extern char * krb4_d_srv;               /* Default service name */
  13448. extern int    krb4_d_lifetime;          /* Default lifetime */
  13449. extern int    krb4_d_preauth;
  13450. extern char * krb4_d_instance;
  13451. extern int    krb4_autoget;
  13452. extern int    krb4_autodel;
  13453. extern int    krb4_checkaddrs;
  13454. extern char * k4_keytab;                /* Keytab file */
  13455. #endif /* CK_KERBEROS */
  13456.  
  13457. #ifndef NOSHOW
  13458. int
  13459. sho_iks() {
  13460. #ifdef IKSDCONF
  13461. #ifdef CK_LOGIN
  13462.     extern int ckxsyslog, ckxwtmp, ckxanon;
  13463. #ifdef UNIX
  13464.     extern int ckxpriv;
  13465. #endif /* UNIX */
  13466. #ifdef CK_PERMS
  13467.     extern int ckxperms;
  13468. #endif /* CK_PERMS */
  13469.     extern char * anonfile, * userfile, * anonroot;
  13470. #ifdef OS2
  13471.     extern char * anonacct;
  13472. #endif /* OS2 */
  13473. #ifdef NT
  13474.     extern char * iks_domain;
  13475. #endif /* NT */
  13476. #endif /* CK_LOGIN */
  13477. #ifdef CKWTMP
  13478.     extern char * wtmpfile;
  13479. #endif /* CKWTMP */
  13480. #ifdef IKSDB
  13481.     extern char * dbfile;
  13482.     extern int dbenabled;
  13483. #endif /* IKSDB */
  13484. #ifdef CK_LOGIN
  13485.     extern int logintimo;
  13486. #endif /* CK_LOGIN */
  13487.     extern int srvcdmsg, success, iksdcf, noinit, arg_x;
  13488.     extern char * cdmsgfile[], * cdmsgstr, *kermrc;
  13489.     char * bannerfile = NULL;
  13490.     char * helpfile = NULL;
  13491.     extern int xferlog;
  13492.     extern char * xferfile;
  13493.     int i;
  13494.  
  13495.     if (isguest) {
  13496.         printf("?Command disabled\r\n");
  13497.         return(success = 0);
  13498.     }
  13499.  
  13500.     printf("IKS Settings\r\n");
  13501. #ifdef CK_LOGIN
  13502. #ifdef OS2
  13503.     printf("  Anonymous Account:   %s\r\n",anonacct?anonacct:"<none>");
  13504. #endif /* OS2 */
  13505.     printf("  Anonymous Initfile:  %s\r\n",anonfile?anonfile:"<none>");
  13506.     printf("  Anonymous Login:     %d\r\n",ckxanon);
  13507.     printf("  Anonymous Root:      %s\r\n",anonroot?anonroot:"<none>");
  13508. #endif /* CK_LOGIN */
  13509.     printf("  Bannerfile:          %s\r\n",bannerfile?bannerfile:"<none>");
  13510.     printf("  CDfile:              %s\r\n",cdmsgfile[0]?cdmsgfile[0]:"<none>");
  13511.     for ( i=1;i<16 && cdmsgfile[i];i++ )
  13512.         printf("  CDfile:              %s\r\n",cdmsgfile[i]);
  13513.     printf("  CDMessage:           %d\r\n",srvcdmsg);
  13514. #ifdef IKSDB
  13515.     printf("  DBfile:              %s\r\n",dbfile?dbfile:"<none>");
  13516.     printf("  DBenabled:           %d\r\n",dbenabled);
  13517. #endif /* IKSDB */
  13518. #ifdef CK_LOGIN
  13519. #ifdef NT
  13520.     printf("  Default-domain:      %s\r\n",iks_domain?iks_domain:".");
  13521. #endif /* NT */
  13522. #endif /* CK_LOGIN */
  13523.     printf("  Helpfile:            %s\r\n",helpfile?helpfile:"<none>");
  13524.     printf("  Initfile:            %s\r\n",kermrc?kermrc:"<none>");
  13525.     printf("  No-Initfile:         %d\r\n",noinit);
  13526. #ifdef CK_LOGIN
  13527. #ifdef CK_PERM
  13528.     printf("  Permission code:     %0d\r\n",ckxperms);
  13529. #endif /* CK_PERM */
  13530. #ifdef UNIX
  13531.     printf("  Privileged Login:    %d\r\n",ckxpriv);
  13532. #endif /* UNIX */
  13533. #endif /* CK_LOGIN */
  13534.     printf("  Server-only:         %d\r\n",arg_x);
  13535.     printf("  Syslog:              %d\r\n",ckxsyslog);
  13536.     printf("  Timeout (seconds):   %d\r\n",logintimo);
  13537.     printf("  Userfile:            %s\r\n",userfile?userfile:"<none>");
  13538. #ifdef CK_LOGIN
  13539. #ifdef CKWTMP
  13540.     printf("  Wtmplog:             %d\r\n",ckxwtmp);
  13541.     printf("  Wtmpfile:            %s\r\n",wtmpfile?wtmpfile:"<none>");
  13542. #endif /* CKWTMP */
  13543. #endif /* CK_LOGIN */
  13544.     printf("  Xferfile:            %s\r\n",xferfile?xferfile:"<none>");
  13545.     printf("  Xferlog:             %d\r\n",xferlog);
  13546. #else /* IKSDCONF */
  13547.     printf("?Nothing to show.\r\n");
  13548. #endif /* IKSDCONF */
  13549.     return(success = 1);
  13550. }
  13551.  
  13552. #ifdef CK_AUTHENTICATION
  13553. int
  13554. sho_auth(cx) int cx; {
  13555.     extern int auth_type_user[], cmd_rows;
  13556.     int i;
  13557.     char * p;
  13558.     int kv = 0, all = 0, n = 0;
  13559.  
  13560. #ifdef IKSD
  13561.     if (inserver && isguest) {
  13562.         printf("?Sorry, command disabled.\r\n");
  13563.         return(success = 0);
  13564.     }
  13565. #endif /* IKSD */
  13566.     if (cx) {
  13567.         kv = cx;
  13568.     } else if (auth_type_user[0] != AUTHTYPE_AUTO) {
  13569.         kv = auth_type_user[0];
  13570.     } else {
  13571.         all = 1;
  13572.         kv = AUTHTYPE_KERBEROS_V4;
  13573.     }
  13574.     while (kv) {
  13575.         switch (kv) {
  13576.           case AUTHTYPE_KERBEROS_V4:
  13577.             kv = all ? AUTHTYPE_KERBEROS_V5 : 0;
  13578.             if (ck_krb4_is_installed()) {
  13579.                 printf(" Authentication:      Kerberos 4\n");
  13580.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13581.             } else {
  13582.                 printf(" Authentication:      Kerberos 4 (not installed)\n");
  13583.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13584.                 continue;
  13585.             }
  13586. #ifdef CK_KERBEROS
  13587.             printf(" Keytab file:         %s\n",
  13588.                       k4_keytab ? k4_keytab : "(none)");
  13589.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13590.             if (krb_action < 0) {
  13591.                 p = "(none)";
  13592.             } else {
  13593.                 for (p = "", i = 0; i < krb_a_n; i++) {
  13594.                     if (krb_action == krb_a_tbl[i].kwval) {
  13595.                         p = krb_a_tbl[i].kwd;
  13596.                         break;
  13597.                     }
  13598.                 }
  13599.             }
  13600.             printf(" Action:              %s\n", p);
  13601.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13602.             printf(" Default lifetime     %d\n",krb4_d_lifetime);
  13603.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13604.             printf(" Lifetime:            %d (minutes)\n",krb4_init.lifetime);
  13605.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13606.             printf(" Default preauth:     %d\n",krb4_d_preauth);
  13607.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13608.             printf(" Preauth:             %d\n",krb4_init.preauth);
  13609.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13610.             printf(" Default principal:   \"%s\"\n",
  13611.                     krb4_d_principal ? krb4_d_principal : "");
  13612.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13613.             printf(" Principal:           \"%s\"\n",
  13614.                     krb4_init.principal ? krb4_init.principal : "");
  13615.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13616.             printf(" Default realm:       \"%s\"\n",
  13617.                     krb4_d_realm ? krb4_d_realm : "");
  13618.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13619.             printf(" Realm:               \"%s\"\n",
  13620.                     krb4_init.realm ? krb4_init.realm : "");
  13621.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13622.             printf(" Default instance:    \"%s\"\n",
  13623.                     krb4_d_instance ? krb4_d_instance : "");
  13624.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13625.             printf(" Instance:            \"%s\"\n",
  13626.                     krb4_init.instance ? krb4_init.instance : "");
  13627.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13628.             printf(" Auto-Get TGTs:       %d\n",krb4_autoget);
  13629.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13630.             printf(" Auto-Destroy TGTs:   %s\n",
  13631.                     krb4_autodel==KRB_DEL_NO?"never":
  13632.                     krb4_autodel==KRB_DEL_CL?"on-close":"on-exit");
  13633.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13634.             printf(" Check IP Addresses:  %d\n",krb4_checkaddrs);
  13635.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13636. #ifdef COMMENT
  13637.             printf(" Password:    \"%s\"\n",
  13638.                     krb4_init.password  ? krb4_init.password  : "");
  13639.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13640. #endif /* COMMENT */
  13641. #endif /* CK_KERBEROS */
  13642.             printf("\n");
  13643.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13644.             break;
  13645.         case AUTHTYPE_KERBEROS_V5:
  13646.             kv = all ? AUTHTYPE_SSL : 0;
  13647.             if (ck_krb5_is_installed()) {
  13648.                 if (ck_gssapi_is_installed())
  13649.                     printf(" Authentication:      Kerberos 5 plus GSSAPI\n");
  13650.                 else
  13651.                     printf(" Authentication:      Kerberos 5\n");
  13652.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13653.             } else {
  13654.                 printf(" Authentication:      Kerberos 5 (not installed)\n");
  13655.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13656.                 continue;
  13657.             }
  13658.  
  13659. #ifdef CK_KERBEROS
  13660.             printf(" Cache file:          %s\n",
  13661.                     krb_op.cache ? krb_op.cache : "(none)");
  13662.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13663.             printf(" Default cache:       %s\n",
  13664.                     krb5_d_cc ? krb5_d_cc : "(none)");
  13665.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13666.             printf(" Keytab file:         %s\n",
  13667.                       k5_keytab ? k5_keytab : "(none)");
  13668.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13669.             if (krb_action < 0) {
  13670.                 p = "(none)";
  13671.             } else  {
  13672.                 for (p = "", i = 0; i < krb_a_n; i++) {
  13673.                     if (krb_action == krb_a_tbl[i].kwval) {
  13674.                         p = krb_a_tbl[i].kwd;
  13675.                         break;
  13676.                     }
  13677.                 }
  13678.             }
  13679.             printf(" Action:              %s\n", p);
  13680.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13681.  
  13682.             printf(" Default forwardable  %d\n",krb5_d_forwardable);
  13683.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13684.             printf(" Forwardable:         %d\n",krb5_init.forwardable);
  13685.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13686.             printf(" Default lifetime     %d\n",krb5_d_lifetime);
  13687.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13688.             printf(" Lifetime:            %d (minutes)\n",krb5_init.lifetime);
  13689.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13690.             printf(" Postdate:            \"%s\"\n",
  13691.                     krb5_init.postdate ? krb5_init.postdate: "");
  13692.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13693.             printf(" Default proxiable:   %d\n",krb5_d_proxiable);
  13694.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13695.             printf(" Proxiable:           %d\n",krb5_init.proxiable);
  13696.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13697.             printf(" Renew:               %d\n",krb5_init.renew);
  13698.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13699.             printf(" Default renewable:   %d (minutes)\n",krb5_d_renewable);
  13700.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13701.             printf(" Renewable:           %d (minutes)\n",krb5_init.renewable);
  13702.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13703.             printf(" Service:             \"%s\"\n",
  13704.                     krb5_init.service ? krb5_init.service : "");
  13705.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13706.             printf(" Validate:            %d\n",krb5_init.validate);
  13707.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13708.             printf(" Default principal:   \"%s\"\n",
  13709.                     krb5_d_principal ? krb5_d_principal : "");
  13710.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13711.             printf(" Principal:           \"%s\"\n",
  13712.                     krb5_init.principal ? krb5_init.principal : "");
  13713.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13714.             printf(" Default instance:    \"%s\"\n",
  13715.                     krb5_d_instance ? krb5_d_instance : "");
  13716.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13717.             printf(" Default realm:       \"%s\"\n",
  13718.                     krb5_d_realm ? krb5_d_realm : "");
  13719.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13720.             printf(" Realm:               \"%s\"\n",
  13721.                     krb5_init.realm ? krb5_init.realm : "");
  13722.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13723.             printf(" Auto-Get TGTs:       %d\n",krb5_autoget);
  13724.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13725.             printf(" Auto-Destroy TGTs:   %s\n",
  13726.                     krb5_autodel==KRB_DEL_NO?"never":
  13727.                     krb5_autodel==KRB_DEL_CL?"on-close":"on-exit");
  13728.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13729.             printf(" Default get K4 TGTs: %d\n",krb5_d_getk4);
  13730.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13731.             printf(" Get K4 TGTs: %d\n",krb5_init.getk4);
  13732.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13733.             printf(" Check IP Addresses:  %d\n",krb5_checkaddrs);
  13734.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13735.             printf(" No IP Addresses:  %d\n",krb5_d_no_addresses);
  13736.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13737.             printf(" IP-Addresses:        ");
  13738.             if (krb5_init.addrs && krb5_init.addrs[0]) {
  13739.                 for (i = 0; krb5_init.addrs[i]; i++) {
  13740.                     if (i)
  13741.                       printf(",");
  13742.                     printf("%s",krb5_init.addrs[i]);
  13743.                 }
  13744.             } else if (krb5_d_addrs[0]) {
  13745.                 for (i = 0;i < KRB5_NUM_OF_ADDRS && krb5_d_addrs[i];i++) {
  13746.                     if (i)
  13747.                       printf(",");
  13748.                     printf("%s",krb5_d_addrs[i]);
  13749.                 }
  13750.             } else {
  13751.                 printf("(use default)");
  13752.             }
  13753.             printf("\n");
  13754.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13755. #ifdef COMMENT
  13756.             printf(" Password:            \"%s\"\n",
  13757.                     krb5_init.password  ? krb5_init.password  : "");
  13758.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13759. #endif /* COMMENT */
  13760. #endif /* CK_KERBEROS */
  13761.             printf("\n");
  13762.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13763.             break;
  13764.           case AUTHTYPE_SSL:
  13765.             kv = all ? AUTHTYPE_SRP : 0;
  13766.             if (ck_ssleay_is_installed()) {
  13767.                 printf(" Authentication:      SSL/TLS\n");
  13768.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13769.             } else {
  13770.                 printf(" Authentication:      SSL/TLS (not installed)\n");
  13771.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13772.                 continue;
  13773.             }
  13774.  
  13775. #ifdef CK_SSL
  13776.             printf(" RSA Certs file: %s\n",ssl_rsa_cert_file?
  13777.                   ssl_rsa_cert_file:"(none)");
  13778.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13779.             printf(" RSA Certs Chain file: %s\n",ssl_rsa_cert_chain_file?
  13780.                   ssl_rsa_cert_chain_file:"(none)");
  13781.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13782.             printf(" RSA Key file: %s\n",ssl_rsa_key_file?
  13783.                   ssl_rsa_key_file:"(none)");
  13784.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13785.             printf(" DSA Certs file: %s\n",ssl_dsa_cert_file?
  13786.                   ssl_dsa_cert_file:"(none)");
  13787.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13788.             printf(" DSA Certs Chain file: %s\n",ssl_dsa_cert_chain_file?
  13789.                   ssl_dsa_cert_chain_file:"(none)");
  13790.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13791.             printf(" DH Key file: %s\n",ssl_dh_key_file?
  13792.                   ssl_dh_key_file:"(none)");
  13793.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13794.             printf(" DH Param file: %s\n",ssl_dh_param_file?
  13795.                   ssl_dh_param_file:"(none)");
  13796.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13797.             printf(" CRL file: %s\n",ssl_crl_file?
  13798.                   ssl_crl_file:"(none)");
  13799.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13800.             printf(" CRL dir: %s\n",ssl_crl_dir?
  13801.                     ssl_crl_dir:"(none)");
  13802.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13803.             printf(" Random file: %s\n",ssl_rnd_file?
  13804.                   ssl_rnd_file:"(none)");
  13805.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13806.             printf(" Verify file: %s\n",ssl_verify_file?
  13807.                   ssl_verify_file:"(none)");
  13808.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13809.             printf(" Verify dir: %s\n",ssl_verify_dir?
  13810.                   ssl_verify_dir:"(none)");
  13811.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13812.             printf(" Cipher list:\n");
  13813.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13814.             if (ssl_con == NULL) {
  13815.                 SSL_library_init();
  13816.                 ssl_ctx = (SSL_CTX *)
  13817.                   SSL_CTX_new((SSL_METHOD *)TLSv1_method());
  13818.                 if (ssl_ctx != NULL)
  13819.                   ssl_con= (SSL *) SSL_new(ssl_ctx);
  13820.             }
  13821.             if (ssl_con != NULL) {
  13822.                 CHAR * p = NULL;
  13823.                 int i;
  13824.  
  13825.                 for (i = 0; ; i++) {
  13826.                     p = (CHAR *) SSL_get_cipher_list(ssl_con,i);
  13827.                     if (p == NULL)
  13828.                       break;
  13829.                     printf("    %s\n",p);
  13830.                     if (++n > cmd_rows - 3)
  13831.                         if (!askmore()) return(0); else n = 0;
  13832.                 }
  13833.             }
  13834.             printf(" Certs OK? %s\n",ssl_certsok_flag? "yes" : "no");
  13835.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13836.             printf(" Debug mode: %s\n", ssl_debug_flag ? "on" : "off");
  13837.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13838.             printf(" Verbose mode: %s\n", ssl_verbose_flag ? "on" : "off");
  13839.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13840.             printf(" Verify mode: %s\n",
  13841.                     ssl_verify_flag == SSL_VERIFY_NONE ? "none" :
  13842.                     ssl_verify_flag == SSL_VERIFY_PEER ? "peer-cert" :
  13843.                     "fail-if-no-peer-cert");
  13844.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13845.             printf(" SSL only? %s\n", ssl_only_flag ? "yes" : "no");
  13846.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13847.             printf(" TLS only? %s\n", tls_only_flag ? "yes" : "no");
  13848.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13849. #endif /* CK_SSL */
  13850.             break;
  13851.           case AUTHTYPE_NTLM:
  13852.             kv = 0;
  13853.             if (ck_ntlm_is_installed()) {
  13854.                 printf(" Authentication:      NTLM\n");
  13855.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13856.                 printf(" No options\n");
  13857.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13858.             } else {
  13859.                 printf(" Authentication:      NTLM (not installed)\n");
  13860.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13861.                 continue;
  13862.             }
  13863.             printf("\n");
  13864.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13865.             break;
  13866.           case AUTHTYPE_SRP:
  13867.             kv = all ? AUTHTYPE_NTLM : 0;
  13868.             if (ck_srp_is_installed()) {
  13869.                 if (ck_krypto_is_installed())
  13870.                     printf(" Authentication:      SRP plus Krypto API\n");
  13871.                 else
  13872.                     printf(" Authentication:      SRP\n");
  13873.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13874.                 printf(" No options\n");
  13875.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13876.             } else {
  13877.                 printf(" Authentication:      SRP (not installed)\n");
  13878.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13879.                 continue;
  13880.             }
  13881.             printf("\n");
  13882.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13883.             break;
  13884.         }
  13885.     }
  13886.     return(success = 1);
  13887. }
  13888. #endif /* CK_AUTHENTICATION */
  13889. #endif /* NOSHOW */
  13890.  
  13891. #ifdef CK_KERBEROS
  13892.  
  13893. /*  C P _ A U T H  --  AUTHENTICATE command parsing  */
  13894.  
  13895. int
  13896. cp_auth() {                             /* Command_Parse AUTHENTICATE */
  13897.     int c, i, n;                        /* Workers */
  13898.     int rc = 0;                         /* Return code */
  13899.     int getval;                         /* Parsing helpers */
  13900.     int tmpauth = 0;                    /* Temporary authentication type */
  13901.     int kv = 0;                         /* Temporary Kerberos version */
  13902.     int tmp_action = -1;                /* Temporary Kerberos action */
  13903.     int tmp_klc = 0;                    /* Temporary list-credentials */
  13904.     char tmphlp[256];                   /* For building help message */
  13905.     char * p;
  13906.     char * tmppswd  = NULL;             /* Password */
  13907.     char * tmpprinz = NULL;             /* Principal */
  13908.     char * tmprealm = NULL;             /* Realm */
  13909.     char * tmpcache = NULL;             /* Cache file */
  13910.     char * tmpinst  = NULL;             /* K4 Instance */
  13911.     char * tmpaddrs[KRB5_NUM_OF_ADDRS];
  13912. #ifdef CK_RECALL
  13913.     extern int on_recall;               /* around Password prompting */
  13914. #endif /* CK_RECALL */
  13915.     struct stringint {                  /* Temporary array for switch values */
  13916.         char * sval;                    /* String value */
  13917.         int ival;                       /* Integer value */
  13918.     } pv[KRB_I_MAX+1];                  /* This many */
  13919.     struct FDB kw, sw, fl;              /* FDBs for each parse function */
  13920.  
  13921.     krb_action = -1;                    /* Initialize Kerberos action. */
  13922.     tmp_action = -1;                    /* And our local copy. */
  13923.     for (i = 0; i < KRB5_NUM_OF_ADDRS; i++)
  13924.       tmpaddrs[i] = NULL;
  13925.  
  13926.     if ((y = cmkey(kerbtab,kerbtabn,"authentication type","",xxstring)) < 0)
  13927.       {
  13928.           if (y == -3)
  13929.             printf("?Authentication type not specified - nothing happens\n");
  13930.           return(y);
  13931.       }
  13932.     tmpauth = y;
  13933.     debug(F101,"kerberos authentication","",tmpauth);
  13934.     switch (tmpauth) {
  13935.       case AUTH_KRB4: kv = 4; break;    /* Don't assume values are the same */
  13936.       case AUTH_KRB5: kv = 5; break;
  13937.       default:
  13938.         printf("?Authentication type not supported: \"%s\"\n",atmbuf);
  13939.         return(-9);
  13940.     }
  13941.  
  13942.     /* From here down is Kerberos */
  13943.     ini_kerb();                         /* Reset Init data to defaults */
  13944.  
  13945.     if (kv == 4) {                      /* Set K4 defaults */
  13946.         if (krb4_d_realm)
  13947.           makestr(&tmprealm,krb4_d_realm);
  13948.         if (krb4_d_principal)
  13949.           makestr(&tmpprinz,krb4_d_principal);
  13950.         if (krb4_d_instance)
  13951.           makestr(&tmpinst,krb4_d_instance);
  13952.     } else if (kv == 5) {               /* Set K5 defaults */
  13953.         if (krb5_d_cc)
  13954.           makestr(&tmpcache,krb5_d_cc);
  13955.         if (krb5_d_realm)
  13956.           makestr(&tmprealm,krb5_d_realm);
  13957.         if (krb5_d_principal)
  13958.           makestr(&tmpprinz,krb5_d_principal);
  13959.         if (krb5_d_instance)
  13960.           makestr(&tmpinst,krb5_d_instance);
  13961.     }
  13962.  
  13963.     for (i = 0; i <= KRB_I_MAX; i++) {  /* Initialize switch values */
  13964.         pv[i].sval = NULL;              /* to null pointers */
  13965.         pv[i].ival = 0;                 /* and 0 int values */
  13966.     }
  13967.  
  13968.     if (kv == 4) {                      /* Kerberos 4 */
  13969.         pv[KRB_I_LF].ival = krb4_d_lifetime;
  13970.         pv[KRB_I_PA].ival = krb4_d_preauth;
  13971.  
  13972.         if ((n = cmkey(krb_a_tbl,krb_a_n,"Kerberos 4 action","",xxstring)) < 0)
  13973.           {
  13974.               if (n == -3)
  13975.                 printf("?Action not specified - nothing happens.\n");
  13976.               return(n);
  13977.           }
  13978.     } else if (kv == 5) {               /* Kerberos 5 */
  13979.         pv[KRB_I_FW].ival = krb5_d_forwardable;
  13980.         pv[KRB_I_PR].ival = krb5_d_proxiable;
  13981.         pv[KRB_I_LF].ival = krb5_d_lifetime;
  13982.         pv[KRB_I_RB].ival = krb5_d_renewable;
  13983.         pv[KRB_I_K4].ival = krb5_d_getk4;
  13984.         pv[KRB_I_NAD].ival = krb5_d_no_addresses;
  13985.  
  13986.         /* Make help message that shows switches and action keywords */
  13987.         ckstrncpy(tmphlp,"Kerberos 5 action, one of the following:\n ",256);
  13988.         for (i = 0; i < krb_a_n; i++) {
  13989.             ckstrncat(tmphlp,krb_a_tbl[i].kwd,sizeof(tmphlp));
  13990.             if (i == krb_a_n - 1)
  13991.               ckstrncat(tmphlp,"\nor switch",sizeof(tmphlp));
  13992.             else
  13993.               ckstrncat(tmphlp,"   ",sizeof(tmphlp));
  13994.         }
  13995.         /* Set up first set of chained FDB's */
  13996.  
  13997.         cmfdbi(&sw,                     /* First FDB - command switches */
  13998.                _CMKEY,                  /* fcode */
  13999.                tmphlp,                  /* hlpmsg */
  14000.                "",                      /* default (none) */
  14001.                "",                      /* addtl string data */
  14002.                krb_s_n,                 /* Switch table size */
  14003.                4,                       /* addtl numeric data 2: 4 = cmswi */
  14004.                xxstring,                /* Processing function */
  14005.                krb_s_tbl,               /* Switch table */
  14006.                &kw                      /* Pointer to next FDB */
  14007.                );
  14008.         cmfdbi(&kw,                     /* Second FDB - action keywords */
  14009.                _CMKEY,                  /* fcode */
  14010.                "Kerberos action",       /* hlpmsg */
  14011.                "",                      /* default (none) */
  14012.                "",                      /* addtl string data */
  14013.                krb_a_n,                 /* Switch table size */
  14014.                0,                       /* addtl num data (0 = NOT switch) */
  14015.                xxstring,                /* Processing function */
  14016.                krb_a_tbl,               /* Keyword table */
  14017.                NULL                     /* Pointer to next FDB (none) */
  14018.                );
  14019.  
  14020.         /* Parse */
  14021.  
  14022.         while (1) {                     /* Parse 0 or more switches */
  14023.             rc = cmfdb(&sw);            /* Parse something */
  14024.             debug(F101,"kerberos cmfdb 1 rc","",rc);
  14025.             if (rc < 0) {                       /* Error */
  14026.                 if (rc == -3)
  14027.                   printf("?Action not specified - nothing happens.\n");
  14028.                 return(rc);             /* or reparse needed */
  14029.             }
  14030.             if (cmresult.fdbaddr != &sw) /* Break out if not a switch */
  14031.               break;
  14032.             c = cmgbrk();               /* Have switch - get break character */
  14033.             getval = (c == ':' || c == '='); /* Must parse an agument? */
  14034.             if (getval && !(cmresult.kflags & CM_ARG)) {
  14035.                 printf("?This switch does not take arguments\n");
  14036.                 return(-9);             /* OK because nothing malloc'd yet */
  14037.             }
  14038.             if (!getval && (cmgkwflgs() & CM_ARG)) {
  14039.                 printf("?This switch requires an argument\n");
  14040.                 return(-9);
  14041.             }
  14042.             n = cmresult.nresult;       /* Numeric result = switch value */
  14043.             debug(F101,"kerberos command switch","",n);
  14044.  
  14045.             switch (n) {                /* Handle the switch */
  14046.               case KRB_S_CA:            /* /CACHE:<filename> */
  14047.                 p = krb5_d_cc ? krb5_d_cc : "";
  14048.                 if ((y = cmofi("Name of cache file",p,&s,xxstring)) < 0) {
  14049.                     if (y == -3)
  14050.                       s = NULL;
  14051.                     else
  14052.                       return(y);
  14053.                 }
  14054.                 makestr(&tmpcache,s);
  14055.                 break;
  14056.               default:
  14057.                 printf("?Unexpected switch value - internal error\n");
  14058.                 return(-9);             /* (if) nothing malloc'd yet. */
  14059.             }
  14060.         }
  14061.         if (cmresult.fdbaddr != &kw) {  /* Checking... */
  14062.             printf("?Unexpected result - internal error\n");
  14063.             return(-9);                 /* Nothing malloc'd yet. */
  14064.         }
  14065.         n = cmresult.nresult;           /* Get keyword value */
  14066.     } else {
  14067.         printf("?Unexpected Kerberos version - Internal error\n");
  14068.         return(-9);
  14069.     }
  14070.     debug(F101,"kerberos action","",n);
  14071.     switch (n) {
  14072.       case KRB_A_IN:                    /* INITIALIZE */
  14073.       case KRB_A_DE:                    /* DESTROY */
  14074.       case KRB_A_LC:                    /* LIST-CREDENTIALS */
  14075.         tmp_action = n;                 /* OK, set */
  14076.         break;
  14077.       default:                          /* Not OK, punt. */
  14078.         printf("?Unexpected action - internal error\n");
  14079.         return(-9);
  14080.     }
  14081.     if (tmp_action == KRB_A_IN) {       /* Action is INITIALIZE */
  14082.         int x;
  14083.         cmfdbi(&sw,                     /* INITIALIZE switches */
  14084.                _CMKEY,                  /* fcode */
  14085.                "Principal,\n or optional INITIALIZE switch(es)", /* hlpmsg */
  14086.                "",                      /* default (none) */
  14087.                "",                      /* addtl string data */
  14088.                kv == 4 ?  krb4_i_n : krb5_i_n, /* Switch table size */
  14089.                4,                       /* addtl numeric data 2: 4 = cmswi */
  14090.                xxstring,                /* Processing function */
  14091.                kv == 4 ?  krb4_i_tbl : krb5_i_tbl,      /* Switch table */
  14092.                &fl                      /* Pointer to next FDB */
  14093.                );
  14094.         cmfdbi(&fl,                     /* 3rd FDB - command to send from */
  14095.                _CMFLD,                  /* fcode */
  14096.                "Principal",             /* hlpmsg */
  14097.                kv == 4 ? krb4_d_principal : krb5_d_principal, /* principal */
  14098.                "",                      /* addtl string data */
  14099.                0,                       /* addtl numeric data 1 */
  14100.                0,                       /* addtl numeric data 2 */
  14101.                xxstring,
  14102.                NULL,
  14103.                NULL
  14104.                );
  14105.         while (1) {                     /* Parse INIT switches or principal */
  14106.             rc = cmfdb(&sw);
  14107.             debug(F101,"kerberos cmfdb 2 rc","",rc);
  14108.             if (rc < 0) {
  14109.                 if (rc == -3)
  14110.                   printf("?Principal name required\n");
  14111.                 goto kerbx;
  14112.             }
  14113.             debug(F101,"kerberos cmfdb 2 fcode","",cmresult.fcode);
  14114.             if (cmresult.fcode != _CMKEY) /* Not a switch, quit switch loop */
  14115.               break;
  14116.             c = cmgbrk();               /* Switch - get break character */
  14117.             debug(F101,"kerberos cmfdb 2 cmgbrk","",c);
  14118.             getval = (c == ':' || c == '=');
  14119.             if (getval && !(cmresult.kflags & CM_ARG)) {
  14120.                 printf("?This switch does not take arguments\n");
  14121.                 return(-9);             /* OK because nothing malloc'd yet */
  14122.             }
  14123.             if (!getval && (cmgkwflgs() & CM_ARG)) {
  14124.                 printf("?This switch requires an argument\n");
  14125.                 return(-9);
  14126.             }
  14127.             n = cmresult.nresult;       /* Numeric result = switch value */
  14128.             switch (n) {
  14129.               /* These don't take args... */
  14130.               case KRB_I_PA:            /* /PREAUTH */
  14131.               case KRB_I_FW:            /* /FORWARDABLE */
  14132.               case KRB_I_PR:            /* /PROXIABLE */
  14133.               case KRB_I_RN:            /* /RENEW */
  14134.               case KRB_I_VA:            /* /VALIDATE */
  14135.               case KRB_I_NPA:           /* /NOT-PREAUTH */
  14136.               case KRB_I_NFW:           /* /NOT-FORWARDABLE */
  14137.               case KRB_I_NPR:           /* /NOT-PROXIABLE */
  14138.               case KRB_I_VB:            /* /VERBOSE */
  14139.               case KRB_I_BR:            /* /BRIEF */
  14140.               case KRB_I_K4:            /* /KERBEROS4 */
  14141.               case KRB_I_NK4:           /* /NO-KERBEROS4 */
  14142.               case KRB_I_POP:           /* /POPUP */
  14143.               case KRB_I_NAD:           /* /NO-ADDRESSES */
  14144.                 if (getval) {
  14145.                     printf("?This switch does not take a value\n");
  14146.                     rc = -9;
  14147.                     goto kerbx;
  14148.                 }
  14149.                 switch (n) {
  14150.                   case KRB_I_NPA:
  14151.                     pv[KRB_I_PA].ival = 0;
  14152.                     break;
  14153.                   case KRB_I_NFW:
  14154.                     pv[KRB_I_FW].ival = 0;
  14155.                     break;
  14156.                   case KRB_I_NPR:
  14157.                     pv[KRB_I_PR].ival = 0;
  14158.                     break;
  14159.                   case KRB_I_VB:
  14160.                     pv[KRB_I_BR].ival = 0;
  14161.                     break;
  14162.                   case KRB_I_NK4:
  14163.                     pv[KRB_I_K4].ival = 0;
  14164.                     break;
  14165.                   default:
  14166.                     pv[n].ival = 1;
  14167.                 }
  14168.                 break;
  14169.  
  14170.                 /* These do take arguments */
  14171.  
  14172.               case KRB_I_RB:            /* /RENEWABLE:<minutes> */
  14173.                 pv[n].ival = 0;
  14174.                 if (!getval) break;
  14175.                 if ((rc = cmnum("Minutes",ckitoa(krb5_init.renewable),
  14176.                                 10,&y, xxstring)) < 0)
  14177.                   goto kerbx;
  14178.                 pv[n].ival = y;
  14179.                 break;
  14180.  
  14181.               case KRB_I_LF:            /* /LIFETIME:<minutes> */
  14182.                 pv[n].ival = 0;
  14183.                 /* Default is previous value */
  14184.                 sprintf(tmpbuf,"%d",    /* SAFE */
  14185.                         kv == 4 ?
  14186.                         krb4_init.lifetime :
  14187.                         krb5_init.lifetime
  14188.                         );
  14189.                 if (!getval) break;
  14190.                 if ((rc = cmnum("Minutes",tmpbuf,10,&y, xxstring)) < 0)
  14191.                   goto kerbx;
  14192.                 pv[n].ival = y;
  14193.                 break;
  14194.  
  14195.               case KRB_I_PD:            /* /POSTDATE:<timestamp> */
  14196.                 if (pv[n].sval) {
  14197.                     free(pv[n].sval);
  14198.                     pv[n].sval = NULL;
  14199.                 }
  14200.                 if (!getval) break;
  14201.                 if ((rc = cmdate("date-time","",&s,0,xxstring)) < 0)
  14202.                   goto kerbx;
  14203.                 makestr(&(pv[n].sval),s);
  14204.                 break;
  14205.  
  14206.               case KRB_I_SR:            /* /SERVICE:<name> */
  14207.                 if (pv[n].sval) {
  14208.                     free(pv[n].sval);
  14209.                     pv[n].sval = NULL;
  14210.                 }
  14211.                 if (!getval) break;
  14212.                 if ((rc = cmfld("Service-name","",&s,xxstring)) < 0)
  14213.                   goto kerbx;
  14214.                 makestr(&(pv[n].sval),s);
  14215.                 break;
  14216.  
  14217.               case KRB_I_RL:            /* /REALM:<name> */
  14218.                 if (pv[n].sval) {
  14219.                     free(pv[n].sval);
  14220.                     pv[n].sval = NULL;
  14221.                 }
  14222.                 if (!getval) break;
  14223.                 if (kv == 4)
  14224.                   p = krb4_d_realm ? krb4_d_realm : "";
  14225.                 else
  14226.                   p = krb5_d_realm ? krb5_d_realm : "";
  14227.                 if ((rc = cmfld("Realm",p,&s,xxstring)) < 0)
  14228.                   goto kerbx;
  14229.                 makestr(&(pv[n].sval),s);
  14230.                 break;
  14231.  
  14232.               case KRB_I_IN:            /* /INSTANCE:<name> */
  14233.                 if (pv[n].sval) {
  14234.                     free(pv[n].sval);
  14235.                     pv[n].sval = NULL;
  14236.                 }
  14237.                 if (!getval) break;
  14238.                 if (kv == 4)
  14239.                     p = krb4_d_instance ? krb4_d_instance : "";
  14240.                 else
  14241.                     p = krb5_d_instance ? krb5_d_instance : "";
  14242.                 if ((rc = cmfld("Instance",p,&s,xxstring)) < 0)
  14243.                   goto kerbx;
  14244.                 makestr(&(pv[n].sval),s);
  14245.                 break;
  14246.  
  14247.               case KRB_I_PW:            /* /PASSWORD:<password> */
  14248.                 debok = 0;
  14249.                 if (pv[n].sval) {
  14250.                     free(pv[n].sval);
  14251.                     pv[n].sval = NULL;
  14252.                 }
  14253.                 if (!getval) break;
  14254.                 if ((rc = cmfld("Password","",&s,xxstring)) < 0)
  14255.                   if (rc != -3)
  14256.                     goto kerbx;
  14257.                 makestr(&(pv[n].sval),s);
  14258.                 break;
  14259.  
  14260.               case KRB_I_ADR:           /* /ADDRESSES:{<address-list>} */
  14261.                 if (pv[n].sval) {
  14262.                     free(pv[n].sval);
  14263.                     pv[n].sval = NULL;
  14264.                 }
  14265.                 if (!getval) break;
  14266.                 if ((rc = cmfld("List of IP addresses","",&s,xxstring)) < 0)
  14267.                   goto kerbx;
  14268.                 makelist(s,tmpaddrs,KRB5_NUM_OF_ADDRS);
  14269.                 for (i = 0; i < KRB5_NUM_OF_ADDRS && tmpaddrs[i]; i++) {
  14270.                     if (inet_addr(tmpaddrs[i]) == 0xffffffff) {
  14271.                         printf("invalid ip address: %s\n",tmpaddrs[i]);
  14272.                         rc = -9;
  14273.                         goto kerbx;
  14274.                     }
  14275.                 }
  14276.                 pv[KRB_I_NAD].ival = 0;
  14277.                 break;
  14278.  
  14279.               default:
  14280.                 printf("?Unexpected switch value - internal error\n");
  14281.                 rc = -9;
  14282.                 goto kerbx;
  14283.             }
  14284.         }
  14285.         if (cmresult.fcode != _CMFLD) {
  14286.             printf("?Unexected result - internal error\n");
  14287.             rc = -9;
  14288.             goto kerbx;
  14289.         }
  14290.         /* cmresult.sresult may be of the form PRINCIPAL@REALM */
  14291.         i = ckindex("@",cmresult.sresult,0,0,0);
  14292.         if (i != 0) {
  14293.             makestr(&tmprealm,&cmresult.sresult[i]);
  14294.             cmresult.sresult[i-1] = '\0';
  14295.         }
  14296.         makestr(&tmpprinz,cmresult.sresult); /* Principal (user) */
  14297.  
  14298.         if ((rc = cmcfm()) < 0) {       /* Now get confirmation */
  14299.             if (rc == -3) {
  14300.                 printf("?Principal name required\n");
  14301.             }
  14302.             goto kerbx;
  14303.         }
  14304.         if (!tmpprinz || !tmpprinz[0]) {
  14305.             printf("?Principal name required\n");
  14306.             goto kerbx;
  14307.         }
  14308.         if (!pv[KRB_I_RN].ival && !pv[KRB_I_VA].ival) {
  14309.             /* Don't use a password if Validating or Renewing */
  14310.             if (pv[KRB_I_PW].sval) {    /* If they gave a /PASSWORD switch */
  14311.                 makestr(&tmppswd,pv[KRB_I_PW].sval); /* use this value */
  14312.             }
  14313. #ifdef COMMENT
  14314.             /* Password prompting has been moved to ck_krb[45]_initTGT() */
  14315.             else {                      /* Otherwise must prompt for it */
  14316.                 char prmpt[80];
  14317.                 if (pv[KRB_I_RL].sval)
  14318.                   sprintf(prmpt,"%s@%s's Password: ",
  14319.                           tmpprinz,pv[KRB_I_RL].sval);
  14320.                 else if (tmprealm)
  14321.                   sprintf(prmpt,"%s@%s's Password: ",
  14322.                           tmpprinz,tmprealm);
  14323.                 else
  14324.                   sprintf(prmpt,"%s's Password: ",tmpprinz);
  14325. #ifdef OS2
  14326.                 if (pv[KRB_I_POP].ival) {
  14327.                     char passwd[80]="";
  14328.                     readpass(prmpt,passwd,80);
  14329.                     makestr(&tmppswd,passwd);
  14330.                     memset(passwd,0,80);
  14331.                 } else
  14332. #endif /* OS2 */
  14333.                 {
  14334. #ifdef CK_RECALL
  14335.                     on_recall = 0;
  14336. #endif /* CK_RECALL */
  14337.                     cmsavp(psave,PROMPTL); /* Save old prompt */
  14338.                     cmsetp(prmpt);      /* Make new prompt */
  14339.                     concb((char)escape); /* Put console in cbreak mode */
  14340.                     cmini(0);           /* and no-echo mode */
  14341.                     /* Issue prompt if at top level */
  14342.                     if (pflag) prompt(xxstring);
  14343.                     cmres();            /* Reset the parser */
  14344.                     for (rc = -1; rc < 0; ) { /* Prompt till they answer */
  14345.                         /* Get a literal line of text */
  14346.                         rc = cmtxt("","",&s,NULL);
  14347.                         cmres();        /* Reset the parser again */
  14348.                     }
  14349.                     makestr(&tmppswd,s);
  14350.                     printf("\n");       /* Echo a CRLF */
  14351.                     cmsetp(psave);      /* Restore original prompt */
  14352.                 }
  14353.             }
  14354.             x = 0;                      /* Check for password */
  14355.             if (tmppswd)
  14356.               if (*tmppswd)
  14357.                 x = 1;
  14358.             if (!x) {
  14359.                 printf("?Password required\n");
  14360.                 goto kerbx;
  14361.             }
  14362. #endif /* COMMENT */
  14363.         }
  14364.     } else if (kv == 5 && tmp_action == KRB_A_LC) { /* LIST-CREDENTIALS */
  14365.         tmp_klc = 0;
  14366.         while (1) {
  14367.             if ((x = cmkey(klctab,nklctab,"Switch","",xxstring)) < 0) {
  14368.                 if (x == -3) {
  14369.                     if ((rc = cmcfm()) < 0)
  14370.                       goto kerbx;
  14371.                     else
  14372.                       break;
  14373.                 } else {
  14374.                     rc = x;
  14375.                     goto kerbx;
  14376.                 }
  14377.             }
  14378.             tmp_klc |= x;
  14379.         }
  14380.     } else if ((rc = cmcfm()) < 0)      /* DESTROY, just confirm */
  14381.         goto kerbx;
  14382.  
  14383. /* Done - Move confirmed data to final locations */
  14384.  
  14385.     krb_action = tmp_action;            /* Action requested */
  14386.     krb_op.version = kv;                /* Kerberos version */
  14387.     krb_op.cache = tmpcache;            /* Cache file */
  14388.     tmpcache = NULL;                    /* So we don't free it */
  14389.  
  14390.     switch (krb_action) {
  14391.       case KRB_A_IN:                    /* INITIALIZE */
  14392.         if (kv == 5) {
  14393.             krb5_init.forwardable = pv[KRB_I_FW].ival;
  14394.             krb5_init.proxiable   = pv[KRB_I_PR].ival;
  14395.             krb5_init.lifetime    = pv[KRB_I_LF].ival;
  14396.             krb5_init.renew       = pv[KRB_I_RN].ival;
  14397.             krb5_init.renewable   = pv[KRB_I_RB].ival;
  14398.             krb5_init.validate    = pv[KRB_I_VA].ival;
  14399.  
  14400.             /* Here we just reassign the pointers and then set them to NULL */
  14401.             /* so they won't be freed below. */
  14402.  
  14403.             krb5_init.postdate = pv[KRB_I_PD].sval; pv[KRB_I_PD].sval = NULL;
  14404.             krb5_init.service  = pv[KRB_I_SR].sval; pv[KRB_I_SR].sval = NULL;
  14405.             if (pv[KRB_I_RL].sval) {
  14406.                 krb5_init.realm  = pv[KRB_I_RL].sval; pv[KRB_I_RL].sval = NULL;
  14407.             } else if (tmprealm) {
  14408.                 krb5_init.realm = tmprealm; tmprealm = NULL;
  14409.             }
  14410.             if (pv[KRB_I_IN].sval) {
  14411.                 krb5_init.instance = pv[KRB_I_IN].sval;
  14412.                 pv[KRB_I_IN].sval = NULL;
  14413.             } else if ( tmpinst ) {
  14414.                 krb5_init.instance = tmpinst;
  14415.                 tmpinst = NULL;
  14416.             }
  14417.             if (tmpprinz) {
  14418.                 krb5_init.principal = tmpprinz;
  14419.                 tmpprinz = NULL;
  14420.             }
  14421.             krb5_init.password = tmppswd;
  14422.             tmppswd = NULL;
  14423.  
  14424.             krb5_init.getk4 = pv[KRB_I_K4].ival;
  14425.             if (krb5_init.getk4) {
  14426.                 krb4_init.lifetime = pv[KRB_I_LF].ival;
  14427.                 if (krb5_init.realm)
  14428.                     makestr(&krb4_init.realm,krb5_init.realm);
  14429.                 krb4_init.preauth  = krb4_d_preauth;
  14430.                 krb4_init.verbose  = pv[KRB_I_BR].ival ? 0 : 1;
  14431.                 if (krb5_init.principal)
  14432.                     makestr(&krb4_init.principal,krb5_init.principal);
  14433.                 if (krb5_init.principal)
  14434.                     makestr(&krb4_init.password,krb5_init.password);
  14435.             }
  14436.             krb5_init.no_addresses = pv[KRB_I_NAD].ival;
  14437.             if (tmpaddrs[0]) {
  14438.                 for (i = 0; i < KRB5_NUM_OF_ADDRS; i++) {
  14439.                     if (krb5_init.addrs[i]) {
  14440.                         free(krb5_init.addrs[i]);
  14441.                         krb5_init.addrs[i] = NULL;
  14442.                     }
  14443.                     krb5_init.addrs[i] = tmpaddrs[i];
  14444.                     tmpaddrs[i] = NULL;
  14445.                 }
  14446.             }
  14447.         } else if (kv == 4) {           /* Same deal for Kerberos 4 */
  14448.             krb4_init.lifetime = pv[KRB_I_LF].ival;
  14449.             if (pv[KRB_I_RL].sval) {
  14450.                 krb4_init.realm  = pv[KRB_I_RL].sval;
  14451.                 pv[KRB_I_RL].sval = NULL;
  14452.             } else if ( tmprealm ) {
  14453.                 krb4_init.realm  = tmprealm;
  14454.                 tmprealm = NULL;
  14455.             }
  14456.             if (pv[KRB_I_IN].sval) {
  14457.                 krb4_init.instance = pv[KRB_I_IN].sval;
  14458.                 pv[KRB_I_IN].sval = NULL;
  14459.             } else if ( tmpinst ) {
  14460.                 krb4_init.instance = tmpinst;
  14461.                 tmpinst = NULL;
  14462.             }
  14463.             krb4_init.preauth  = pv[KRB_I_PA].ival;
  14464.             krb4_init.verbose  = pv[KRB_I_BR].ival ? 0 : 1;
  14465.  
  14466.             if (tmpprinz) {
  14467.                 krb4_init.principal = tmpprinz;
  14468.                 tmpprinz = NULL;
  14469.             }
  14470.             krb4_init.password = tmppswd;
  14471.             tmppswd = NULL;
  14472.         }
  14473.         break;
  14474.       case KRB_A_LC:                    /* List Credentials */
  14475.         krb5_lc.encryption = tmp_klc & XYKLCEN;
  14476.         krb5_lc.flags = tmp_klc & XYKLCFL;
  14477.         krb5_lc.addr  = tmp_klc & XYKLCAD;
  14478.         break;
  14479.     }
  14480.  
  14481. /* Common exit - Free temporary storage */
  14482.  
  14483.   kerbx:
  14484.     for (i = 0; i <= KRB_I_MAX; i++) {  /* Free malloc'd switch data */
  14485.         if (pv[i].sval)
  14486.           free(pv[i].sval);
  14487.     }
  14488.     for (i = 0; i < KRB5_NUM_OF_ADDRS; i++) {
  14489.         if (tmpaddrs[i])
  14490.           free(tmpaddrs[i]);
  14491.     }
  14492.     if (tmpprinz) free(tmpprinz);       /* And these too. */
  14493.     if (tmppswd)  free(tmppswd);
  14494.     if (tmpcache) free(tmpcache);
  14495.     if (tmprealm) free(tmprealm);
  14496.     if (tmpinst)  free(tmpinst);
  14497.  
  14498.     return(rc);                         /* Return the return code */
  14499. }
  14500. #endif /* CK_KERBEROS */
  14501.  
  14502. #ifdef CK_LOGIN
  14503. int
  14504. #ifdef CK_ANSIC
  14505. ckxlogin(CHAR * userid, CHAR * passwd, CHAR * acct, int promptok)
  14506. #else /* CK_ANSIC */
  14507. ckxlogin(userid, passwd, acct, promptok)
  14508.   CHAR * userid; CHAR * passwd; CHAR * acct; int promptok;
  14509. #endif /* CK_ANSIC */
  14510. /* ckxlogin */ {
  14511. #ifdef CK_RECALL
  14512.     extern int on_recall;               /* around Password prompting */
  14513. #endif /* CK_RECALL */
  14514. #ifdef CK_PAM
  14515.     extern int guest;
  14516. #endif /* CK_PAM */
  14517.     int rprompt = 0;                    /* Restore prompt */
  14518. #ifdef CKSYSLOG
  14519.     int savlog;
  14520. #endif /* CKSYSLOG */
  14521.  
  14522.     extern int what, srvcdmsg;
  14523.  
  14524.     int x = 0, ok = 0, rc = 0;
  14525.     CHAR * _u = NULL, * _p = NULL, * _a = NULL;
  14526.  
  14527.     debug(F111,"ckxlogin userid",userid,promptok);
  14528.     debug(F110,"ckxlogin passwd",passwd,0);
  14529.  
  14530.     isguest = 0;                        /* Global "anonymous" flag */
  14531.  
  14532.     if (!userid) userid = (CHAR *)"";
  14533.     if (!passwd) passwd = (CHAR *)"";
  14534.  
  14535.     debug(F111,"ckxlogin userid",userid,what);
  14536.  
  14537. #ifdef CK_RECALL
  14538.     on_recall = 0;
  14539. #endif /* CK_RECALL */
  14540.  
  14541. #ifdef CKSYSLOG
  14542.     savlog = ckxsyslog;                 /* Save and turn off syslogging */
  14543. #endif /* CKSYSLOG */
  14544.  
  14545.     if ((!*userid || !*passwd) &&       /* Need to prompt for missing info */
  14546.         promptok) {
  14547.         cmsavp(psave,PROMPTL);          /* Save old prompt */
  14548.         debug(F110,"ckxlogin saved",psave,0);
  14549.         rprompt = 1;
  14550.     }
  14551.     if (!*userid) {
  14552.         if (!promptok)
  14553.           return(0);
  14554.         cmsetp("Username: ");           /* Make new prompt */
  14555.         concb((char)escape);            /* Put console in cbreak mode */
  14556.         cmini(1);
  14557.  
  14558. /* Flush typeahead */
  14559.  
  14560. #ifdef IKS_OPTION
  14561.         debug(F101,
  14562.               "ckxlogin TELOPT_SB(TELOPT_KERMIT).kermit.me_start",
  14563.               "",
  14564.               TELOPT_SB(TELOPT_KERMIT).kermit.me_start
  14565.               );
  14566. #endif /* IKS_OPTION */
  14567.  
  14568.         while (ttchk() > 0) {
  14569.             x = ttinc(0);
  14570.             debug(F101,"ckxlogin flush user x","",x);
  14571.             if (x < 0)
  14572.               doexit(GOOD_EXIT,0);      /* Connection lost */
  14573. #ifdef TNCODE
  14574.             if (sstelnet) {
  14575.                 if (x == IAC) {
  14576.                     x = tn_doop((CHAR)(x & 0xff),ckxech,ttinc);
  14577.                     debug(F101,"ckxlogin user tn_doop","",x);
  14578. #ifdef IKS_OPTION
  14579.                     debug(F101,
  14580.                       "ckxlogin user TELOPT_SB(TELOPT_KERMIT).kermit.me_start",
  14581.                       "",
  14582.                       TELOPT_SB(TELOPT_KERMIT).kermit.me_start
  14583.                       );
  14584. #endif /* IKS_OPTION */
  14585.  
  14586.                     if (x < 0)
  14587.                       goto XCKXLOG;
  14588.                     switch (x) {
  14589.                       case 1: ckxech = 1; break; /* Turn on echoing */
  14590.                       case 2: ckxech = 0; break; /* Turn off echoing */
  14591. #ifdef IKS_OPTION
  14592.                       case 4:                    /* IKS event */
  14593.                         if (!TELOPT_SB(TELOPT_KERMIT).kermit.me_start)
  14594.                           break;                 /* else fall thru... */
  14595. #endif /* IKS_OPTION */
  14596.                       case 6:                    /* Logout */
  14597.                         goto XCKXLOG;
  14598.                     }
  14599.                 }
  14600.             }
  14601. #endif /* TNCODE */
  14602.         }
  14603.         if (pflag) prompt(xxstring);    /* Issue prompt if at top level */
  14604.         cmres();                        /* Reset the parser */
  14605.         for (x = -1; x < 0;) {          /* Prompt till they answer */
  14606.             /* Get a literal line of text */
  14607.             x=cmtxt("Your username, or \"ftp\", or \"anonymous\"","",&s,NULL);
  14608.             if (x == -4 || x == -10) {
  14609.                 printf("\r\n%sLogin cancelled\n",
  14610.                x == -10 ? "Timed out: " : "");
  14611. #ifdef CKSYSLOG
  14612.                 ckxsyslog = savlog;
  14613. #endif /* CKSYSLOG */
  14614.                 doexit(GOOD_EXIT,0);
  14615.             }
  14616.             if (sstate)                 /* Did a packet come instead? */
  14617.               goto XCKXLOG;
  14618.             cmres();                    /* Reset the parser again */
  14619.         }
  14620.         if ((_u = (CHAR *)malloc((int)strlen(s) + 1)) == NULL) {
  14621.             printf("?Internal error: malloc\n");
  14622.             goto XCKXLOG;
  14623.         } else {
  14624.             strcpy((char *)_u,s);       /* safe */
  14625.             userid = _u;
  14626.         }
  14627.     }
  14628.     ok = zvuser((char *)userid);        /* Verify username */
  14629.     debug(F111,"ckxlogin zvuser",userid,ok);
  14630.  
  14631.     if (!*passwd && promptok
  14632. #ifdef CK_PAM
  14633.         && guest
  14634. #endif /* CK_PAM */
  14635.         ) {
  14636.         char prmpt[80];
  14637.  
  14638. #ifdef CKSYSLOG
  14639.         savlog = ckxsyslog;             /* Save and turn off syslogging */
  14640.         ckxsyslog = 0;
  14641. #endif /* CKSYSLOG */
  14642.  
  14643. /* Flush typeahead again */
  14644.  
  14645.         while (ttchk() > 0) {
  14646.             x = ttinc(0);
  14647.             debug(F101,"ckxlogin flush user x","",x);
  14648. #ifdef TNCODE
  14649.             if (sstelnet) {
  14650.                 if (x == IAC) {
  14651.                     x = tn_doop((CHAR)(x & 0xff),ckxech,ttinc);
  14652.                     debug(F101,"ckxlogin pass tn_doop","",x);
  14653. #ifdef IKS_OPTION
  14654.                     debug(F101,
  14655.                       "ckxlogin pass TELOPT_SB(TELOPT_KERMIT).kermit.me_start",
  14656.                       "",
  14657.                       TELOPT_SB(TELOPT_KERMIT).kermit.me_start
  14658.                       );
  14659. #endif /* IKS_OPTION */
  14660.                     if (x < 0)
  14661.                       goto XCKXLOG;
  14662.                     switch (x) {
  14663.                       case 1: ckxech = 1; break; /* Turn on echoing */
  14664.                       case 2: ckxech = 0; break; /* Turn off echoing */
  14665.                       case 4:                    /* IKS event */
  14666.                         if (!TELOPT_SB(TELOPT_KERMIT).kermit.me_start)
  14667.                           break;                 /* else fall thru... */
  14668.                       case 6:                    /* Logout */
  14669.                         goto XCKXLOG;
  14670.                     }
  14671.                 }
  14672.             }
  14673. #endif /* TNCODE */
  14674.         }
  14675.         if (!strcmp((char *)userid,"anonymous") ||
  14676.             !strcmp((char *)userid,"ftp")) {
  14677.             if (!ok)
  14678.               goto XCKXLOG;
  14679.             ckstrncpy(prmpt,"Enter e-mail address as Password: ",80);
  14680.         } else if (*userid && strlen((char *)userid) < 60) {
  14681. #ifdef NT
  14682.             extern CHAR * pReferenceDomainName;
  14683.             if (pReferenceDomainName)
  14684.               ckmakxmsg(prmpt,
  14685.                        80,
  14686.                        "Enter ",
  14687.                        pReferenceDomainName,
  14688.                        "\\\\",
  14689.                        userid,
  14690.                        "'s Password: ",
  14691.                        NULL,NULL,NULL,NULL,NULL,NULL,NULL
  14692.                        );
  14693.             else
  14694. #endif /* NT */
  14695.               ckmakmsg(prmpt,80,"Enter ",(char *)userid,"'s Password: ",NULL);
  14696.         } else
  14697.           ckstrncpy(prmpt,"Enter Password: ",80);
  14698.         cmsetp(prmpt);                  /* Make new prompt */
  14699.         concb((char)escape);            /* Put console in cbreak mode */
  14700.         if (strcmp((char *)userid,"anonymous") &&
  14701.             strcmp((char *)userid,"ftp")) { /* and if not anonymous */
  14702.             debok = 0;
  14703.             cmini(0);                   /* and no-echo mode */
  14704.         } else {
  14705.             cmini(1);
  14706.         }
  14707.         if (pflag) prompt(xxstring);    /* Issue prompt if at top level */
  14708.         cmres();                        /* Reset the parser */
  14709.         for (x = -1; x < 0;) {          /* Prompt till they answer */
  14710.             x = cmtxt("","",&s,NULL);   /* Get a literal line of text */
  14711.             if (x == -4 || x == -10) {
  14712.                 printf("\r\n%sLogin cancelled\n",
  14713.                x == -10 ? "Timed out: " : "");
  14714. #ifdef CKSYSLOG
  14715.                 ckxsyslog = savlog;
  14716. #endif /* CKSYSLOG */
  14717.                 doexit(GOOD_EXIT,0);
  14718.             }
  14719.             if (sstate)                 /* In case of a Kermit packet */
  14720.               goto XCKXLOG;
  14721.             cmres();                    /* Reset the parser again */
  14722.         }
  14723.         printf("\r\n");                 /* Echo a CRLF */
  14724.         if ((_p = (CHAR *)malloc((int)strlen(s) + 1)) == NULL) {
  14725.             printf("?Internal error: malloc\n");
  14726.             goto XCKXLOG;
  14727.         } else {
  14728.             strcpy((char *)_p,s);       /* safe */
  14729.             passwd = _p;
  14730.         }
  14731.     }
  14732. #ifdef CK_PAM
  14733.     else {
  14734.         cmres();                        /* Reset the parser */
  14735.  
  14736.         /* We restore the prompt now because the PAM engine will call  */
  14737.         /* readpass() which will overwrite psave. */
  14738.         if (rprompt) {
  14739.             cmsetp(psave);              /* Restore original prompt */
  14740.             debug(F110,"ckxlogin restored",psave,0);
  14741.             rprompt = 0;
  14742.         }
  14743.     }
  14744. #endif /* CK_PAM */
  14745.  
  14746. #ifdef CKSYSLOG
  14747.     ckxsyslog = savlog;
  14748. #endif /* CKSYSLOG */
  14749.  
  14750.     if (ok) {
  14751.         ok = zvpass((char *)passwd);    /* Check password */
  14752.         debug(F101,"ckxlogin zvpass","",ok);
  14753.     }
  14754.  
  14755.     if (ok > 0 && isguest) {
  14756. #ifndef NOPUSH
  14757.         nopush = 1;
  14758. #endif /* NOPUSH */
  14759.         srvcdmsg = 1;
  14760.     }
  14761.     rc = ok;                            /* Set the return code */
  14762.     if ((char *)uidbuf != (char *)userid)
  14763.       ckstrncpy(uidbuf,(char *)userid,UIDBUFLEN); /* Remember username */
  14764.  
  14765.   XCKXLOG:                              /* Common exit */
  14766. #ifdef CKSYSLOG
  14767.     ckxsyslog = savlog;                 /* In case of GOTO above */
  14768. #endif /* CKSYSLOG */
  14769.     if (rprompt) {
  14770.         cmsetp(psave);                  /* Restore original prompt */
  14771.         debug(F110,"ckxlogin restored",psave,0);
  14772.     }
  14773.     if (_u || _p || _a) {
  14774.         if (_u) free(_u);
  14775.         if (_p) free(_p);
  14776.         if (_a) free(_a);
  14777.     }
  14778.     return(rc);
  14779. }
  14780.  
  14781. int
  14782. ckxlogout() {
  14783.     doexit(GOOD_EXIT,0);                /* doexit calls zvlogout */
  14784.     return(0);                          /* not reached */
  14785. }
  14786. #endif /* CK_LOGIN */
  14787.  
  14788. #endif /* NOICP */
  14789.