home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / cku209.tar / ckuus7.c < prev    next >
C/C++ Source or Header  |  2003-02-27  |  505KB  |  14,843 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, 2003,
  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.     { "line-spacing",  XYTLSP,    CM_INV },
  972.     { "local-character-set", XYTLCS,  0 },
  973. #else
  974.     { "line-spacing",  XYTLSP,    0 },
  975.     { "local-character-set", XYTLCS,  CM_INV },
  976. #endif /* KUI */
  977. #else
  978.     { "local-character-set", XYTLCS,  CM_INV },
  979. #endif /* OS2 */
  980. #endif /* NOCSETS */
  981.     { "locking-shift", XYTSO,     0 },
  982. #ifdef OS2
  983.     { "margin-bell",   XYTMBEL,   0 },
  984. #endif /* OS2 */
  985. #ifdef OS2MOUSE
  986.     { "mouse",         XYTMOU,    CM_INV },
  987. #endif /* OS2MOUSE */
  988.     { "newline-mode",  XYTNL,     0 },
  989. #ifdef OS2
  990.     { "output-pacing", XYTPAC,    0 },
  991. #ifdef PCTERM
  992.     { "pcterm",        XYTPCTERM, 0 },
  993. #endif /* PCTERM */
  994. #endif /* OS2 */
  995. #ifdef OS2ORUNIX
  996.     { "print",         XYTPRN,    0 },
  997. #endif /* OS2ORUNIX */
  998. #ifndef NOCSETS
  999. #ifdef OS2
  1000.     { "remote-character-set", XYTRCS,  0 },
  1001. #else
  1002.     { "remote-character-set", XYTRCS,  CM_INV },
  1003. #endif /* OS2 */
  1004. #endif /* NOCSETS */
  1005. #ifdef OS2
  1006.     { "roll-mode",       XYTROL, 0 },
  1007.     { "s",               XYTUPD, CM_ABR|CM_INV },
  1008.     { "sc",              XYTUPD, CM_ABR|CM_INV },
  1009.     { "scr",             XYTUPD, CM_ABR|CM_INV },
  1010.     { "scree",           XYTUPD, CM_ABR|CM_INV },
  1011.     { "screen",          XYTUPD, CM_ABR|CM_INV },
  1012.     { "screen-",         XYTUPD, CM_ABR|CM_INV },
  1013.     { "screen-mode",     XYTSCNM,   0 },
  1014.     { "screen-optimize", XYTOPTI,   0 },
  1015.     { "screen-update",   XYTUPD,    0 },
  1016.     { "scrollback",      XYSCRS,    0 },
  1017.     { "send-data",         XYTSEND, 0 },
  1018.     { "send-end-of-block", XYTSEOB, 0 },
  1019.     { "sgr-colors",            XYTSGRC,  0 },
  1020.     { "sni-ch.code",           XYTSNICC, 0 },
  1021.     { "sni-firmware-versions", XYTSNIFV, 0 },
  1022.     { "sni-language",          XYTVTLNG, 0 },
  1023.     { "sni-pagemode",          XYTSNIPM, CM_INV },
  1024.     { "sni-scrollmode",              XYTSNISM, CM_INV },
  1025.     { "spacing-attribute-character", XYTSAC,   CM_INV },
  1026.     { "statusline",                  XYTSTAT,  0 },
  1027.     { "tra",                         XYTCTS,   CM_INV|CM_ABR },
  1028.     { "transmit-timeout",            XYTCTS,   0 },
  1029. #endif /* OS2 */
  1030.  
  1031. #ifdef OS2ORUNIX
  1032.     { "transparent-print", XYTPRN,   CM_INV },
  1033. #endif /* OS2ORUNIX */
  1034.  
  1035. #ifdef CK_TRIGGER
  1036.     { "trigger",           XYTRIGGER,0 },
  1037. #endif /* CK_TRIGGER */
  1038. #ifdef OS2
  1039.     { "type",              XYTTYP,   0 },
  1040. #else
  1041.     { "type",              XYTTYP,   CM_INV },
  1042. #endif /* OS2 */
  1043.  
  1044. #ifndef NOCSETS
  1045. #ifdef UNICODE
  1046. #ifdef CKOUNI
  1047.     { "unicode",           XYTUNI,   CM_INV },
  1048. #endif /* CKOUNI */
  1049. #endif /* UNICODE */
  1050. #endif /* NOCSETS */
  1051. #ifdef OS2
  1052.     { "unix-mode",         XYTUNX,   CM_INV },
  1053.     { "url-highlight",     XYTURLHI, 0 },
  1054. #ifdef NT
  1055.     { "video-change",      XYTVCH,   0 },
  1056. #endif /* NT */
  1057.     { "vt-language",       XYTVTLNG, 0 },
  1058.     { "vt-nrc-mode",       XYTVTNRC, 0 },
  1059. #endif /* OS2 */
  1060.     { "width",             XYTWID,   0 },
  1061. #ifdef OS2
  1062.     { "wrap",              XYTWRP,   0 },
  1063. #endif /* OS2 */
  1064.     { "", 0, 0 }
  1065. };
  1066. int ntrm = (sizeof(trmtab) / sizeof(struct keytab)) - 1;
  1067.  
  1068. #ifdef OS2
  1069. struct keytab termctrl[] = {    /* SET TERM CONTROLS */
  1070.     { "7",      7, 0 },
  1071.     { "8",      8, 0 }
  1072. };
  1073. int ntermctrl = (sizeof(termctrl) / sizeof(struct keytab));
  1074.  
  1075. struct keytab curontab[] = {    /* SET TERM CURSOR */
  1076. #ifdef KUI
  1077.     { "noblink", 2, 0 },
  1078. #else
  1079.     { "noblink", 2, CM_INV },
  1080. #endif /* KUI */
  1081.     { "off",     0, 0 },
  1082.     { "on",      1, 0 }
  1083. };
  1084. int ncuron = (sizeof(curontab) / sizeof(struct keytab));
  1085.  
  1086. struct keytab rolltab[] = {   /* Set TERM Roll Options */
  1087.     { "insert",    TTR_INSERT, 0      },
  1088.     { "keystrokes",TTR_KEYS,   0      },
  1089.     { "off",       TTR_OVER,   CM_INV },
  1090.     { "on",        TTR_INSERT, CM_INV },
  1091.     { "overwrite", TTR_OVER,   0      }
  1092. };
  1093. int nroll = (sizeof(rolltab) / sizeof(struct keytab));
  1094.  
  1095. struct keytab rollkeytab[] = {        /* Set TERM ROLL KEYSTROKES */
  1096.     { "ignore",            TTRK_IGN, 0 },
  1097.     { "restore-and-send",  TTRK_RST, 0 },
  1098.     { "send",              TTRK_SND, 0 }
  1099. };
  1100. int nrollkey = (sizeof(rollkeytab) / sizeof(struct keytab));
  1101.  
  1102. #define TT_GR_ALL 4
  1103. #define TT_GR_G0  0
  1104. #define TT_GR_G1  1
  1105. #define TT_GR_G2  2
  1106. #define TT_GR_G3  3
  1107. #define TT_GR_KBD 4
  1108. struct keytab graphsettab[] = {  /* DEC VT Graphic Sets */
  1109.     { "all",      TT_GR_ALL, 0 },
  1110.     { "g0",       TT_GR_G0,  0 },
  1111.     { "g1",       TT_GR_G1,  0 },
  1112.     { "g2",       TT_GR_G2,  0 },
  1113.     { "g3",       TT_GR_G3,  0 },
  1114.     { "keyboard", TT_GR_KBD, 0 }
  1115. };
  1116. int ngraphset = (sizeof(graphsettab) / sizeof(struct keytab));
  1117. #endif /* OS2 */
  1118.  
  1119. struct keytab adltab[] = {              /* Autodownload Options */
  1120.     { "ask",     TAD_ASK, 0 },
  1121.     { "error",   TAD_ERR, 0 },
  1122. #ifdef OS2
  1123.     { "kermit",  TAD_K,   0 },
  1124. #endif /* OS2 */
  1125.     { "off",     TAD_OFF, 0 },
  1126.     { "on",      TAD_ON,  0 },
  1127. #ifdef OS2
  1128.     { "zmodem",  TAD_Z,   0 },
  1129. #endif /* OS2 */
  1130.     { "", 0, 0 }
  1131. };
  1132. int nadltab = (sizeof(adltab) / sizeof(struct keytab)) - 1;
  1133.  
  1134. struct keytab adlerrtab[] = {           /* Autodownload Error Options */
  1135.     { "continue", 0, 0 },
  1136.     { "go",       0, CM_INV },
  1137.     { "stop",     1, 0 }
  1138. };
  1139. int nadlerrtab = (sizeof(adlerrtab) / sizeof(struct keytab));
  1140.  
  1141. #ifdef OS2
  1142. struct keytab adlxtab[] = {             /* Autodownload Options */
  1143.     { "c0-conflicts",     TAD_X_C0,     0 },
  1144.     { "detection-method", TAD_X_DETECT, 0 },
  1145.     { "string",           TAD_X_STR,    0 }
  1146. };
  1147. int nadlxtab = (sizeof(adlxtab) / sizeof(struct keytab));
  1148.  
  1149. struct keytab adldtab[] = {             /* Auto-dl Detection Methods */
  1150.     { "packet",           ADL_PACK,     0 },
  1151.     { "string",           ADL_STR,      0 }
  1152. };
  1153. int nadldtab = (sizeof(adldtab) / sizeof(struct keytab));
  1154.  
  1155. struct keytab adlc0tab[] = {            /* Auto-dl Detection Methods */
  1156.     { "ignored-by-emulator",    0,      0 },
  1157.     { "processed-by-emulator",  1,      0 }
  1158. };
  1159. int nadlc0tab = (sizeof(adlc0tab) / sizeof(struct keytab));
  1160.  
  1161. #ifndef NOCSETS
  1162. struct keytab vtlangtab[] = {
  1163.     { "belgian",        VTL_BELGIAN , 0 },
  1164.     { "british",        VTL_BRITISH , 0 },
  1165.     { "canadian",       VTL_CANADIAN, 0 },
  1166.     { "czech",          VTL_CZECH   , 0 },
  1167.     { "danish",         VTL_DANISH  , 0 },
  1168.     { "dutch",          VTL_DUTCH   , 0 },
  1169.     { "finnish",        VTL_FINNISH , 0 },
  1170.     { "french",         VTL_FRENCH  , 0 },
  1171.     { "french-canadian",VTL_FR_CAN  , 0 },
  1172.     { "german",         VTL_GERMAN  , 0 },
  1173.     { "greek",          VTL_GREEK   , 0 },
  1174.     { "hebrew",         VTL_HEBREW  , 0 },
  1175.     { "hungarian",      VTL_HUNGARIA, 0 },
  1176.     { "italian",        VTL_ITALIAN , 0 },
  1177.     { "latin-american", VTL_LATIN_AM, 0 },
  1178.     { "north-american", VTL_NORTH_AM, 0 },
  1179.     { "norwegian",      VTL_NORWEGIA, 0 },
  1180.     { "polish",         VTL_POLISH  , 0 },
  1181.     { "portugese",      VTL_PORTUGES, 0 },
  1182.     { "romanian",       VTL_ROMANIAN, 0 },
  1183.     { "russian",        VTL_RUSSIAN , 0 },
  1184.     { "scs",            VTL_SCS     , CM_INV },
  1185.     { "slovak",         VTL_SLOVAK  , 0 },
  1186.     { "spanish",        VTL_SPANISH , 0 },
  1187.     { "swedish",        VTL_SWEDISH , 0 },
  1188.     { "swiss-french",   VTL_SW_FR   , 0 },
  1189.     { "swiss-german",   VTL_SW_GR   , 0 },
  1190.     { "turkish-f",      VTL_TURK_F  , CM_INV },
  1191.     { "turkish-q",      VTL_TURK_Q  , CM_INV }
  1192. };
  1193. int nvtlangtab = (sizeof(vtlangtab) / sizeof(struct keytab));
  1194. #endif /* NOCSETS */
  1195. #endif /* OS2 */
  1196.  
  1197. struct keytab crdtab[] = {              /* Carriage-return display */
  1198.     { "crlf",        1, 0 },
  1199.     { "normal",      0, 0 }
  1200. };
  1201. extern int tt_crd;                      /* Carriage-return display variable */
  1202.  
  1203. #ifdef CK_APC
  1204. extern int apcstatus, apcactive;
  1205. static struct keytab apctab[] = {       /* Terminal APC parameters */
  1206.     {  "no-input", APC_ON|APC_NOINP,0 },
  1207.     { "off",       APC_OFF,  0 },
  1208.     { "on",        APC_ON,   0 },
  1209.     { "unchecked", APC_ON|APC_UNCH, 0 },
  1210.     { "unchecked-no-input", APC_ON|APC_NOINP|APC_UNCH, 0 }
  1211. };
  1212. int napctab = (sizeof(apctab) / sizeof(struct keytab));
  1213. #endif /* CK_APC */
  1214. #endif /* NOLOCAL */
  1215.  
  1216. extern int autodl, adl_err, adl_ask;
  1217.  
  1218. struct keytab beltab[] = {              /* Terminal bell mode */
  1219. #ifdef OS2
  1220.     { "audible", XYB_AUD,  0 },
  1221.     { "none",    XYB_NONE, 0 },
  1222. #else
  1223.     { "audible", XYB_AUD,  CM_INV },
  1224.     { "none",    XYB_NONE, CM_INV },
  1225. #endif /* OS2 */
  1226. #ifdef OS2
  1227.     { "off",     XYB_NONE, CM_INV },
  1228.     { "on",      XYB_AUD,  CM_INV },
  1229. #else
  1230.     { "off",     XYB_NONE, 0 },
  1231.     { "on",      XYB_AUD,  0 },
  1232. #endif /* OS2 */
  1233. #ifdef OS2
  1234.     { "visible", XYB_VIS,  0 },
  1235. #endif /* OS2 */
  1236.     { "", 0, 0 }
  1237. };
  1238. int nbeltab = sizeof(beltab)/sizeof(struct keytab) - 1;
  1239.  
  1240. int tt_unicode = 1;                     /* Use Unicode if possible */
  1241. #ifdef CKTIDLE
  1242. int tt_idlesnd_tmo = 0;                 /* Idle Send Timeout, disabled */
  1243. char * tt_idlesnd_str = NULL;           /* Idle Send String, none */
  1244. char * tt_idlestr = NULL;
  1245. extern int tt_idleact, tt_idlelimit;
  1246. #endif /* CKTIDLE */
  1247.  
  1248. #ifdef OS2
  1249. #ifndef NOLOCAL
  1250. /*
  1251.   OS/2 serial communication devices.
  1252. */
  1253. struct keytab os2devtab[] = {
  1254.     { "1",    1, CM_INV },                      /* Invisible synonyms, like */
  1255.     { "2",    2, CM_INV },                      /* "set port 1" */
  1256.     { "3",    3, CM_INV },
  1257.     { "4",    4, CM_INV },
  1258.     { "5",    5, CM_INV },
  1259.     { "6",    6, CM_INV },
  1260.     { "7",    7, CM_INV },
  1261.     { "8",    8, CM_INV },
  1262.     { "com1", 1, 0 },                   /* Real device names */
  1263.     { "com2", 2, 0 },
  1264.     { "com3", 3, 0 },
  1265.     { "com4", 4, 0 },
  1266.     { "com5", 5, 0 },
  1267.     { "com6", 6, 0 },
  1268.     { "com7", 7, 0 },
  1269.     { "com8", 8, 0 },
  1270. #ifdef OS2ONLY
  1271.     { "slipcom1", 1, 0 },                       /* For use with SLIP driver */
  1272.     { "slipcom2", 2, 0 },                       /* shared access */
  1273.     { "slipcom3", 3, 0 },
  1274.     { "slipcom4", 4, 0 },
  1275.     { "slipcom5", 5, 0 },
  1276.     { "slipcom6", 6, 0 },
  1277.     { "slipcom7", 7, 0 },
  1278.     { "slipcom8", 8, 0 },
  1279.     { "pppcom1", 1, 0 },                        /* For use with PPP driver */
  1280.     { "pppcom2", 2, 0 },                        /* shared access */
  1281.     { "pppcom3", 3, 0 },
  1282.     { "pppcom4", 4, 0 },
  1283.     { "pppcom5", 5, 0 },
  1284.     { "pppcom6", 6, 0 },
  1285.     { "pppcom7", 7, 0 },
  1286.     { "pppcom8", 8, 0 }
  1287. #endif /* OS2ONLY */
  1288. };
  1289. int nos2dev = (sizeof(os2devtab) / sizeof(struct keytab)) - 1;
  1290.  
  1291. #ifdef OS2ONLY
  1292. struct keytab os2ppptab[] = {
  1293.     { "0",    0, CM_INV },
  1294.     { "1",    1, CM_INV },                      /* Invisible synonyms, like */
  1295.     { "2",    2, CM_INV },                      /* "set port 1" */
  1296.     { "3",    3, CM_INV },
  1297.     { "4",    4, CM_INV },
  1298.     { "5",    5, CM_INV },
  1299.     { "6",    6, CM_INV },
  1300.     { "7",    7, CM_INV },
  1301.     { "8",    8, CM_INV },
  1302.     { "9",    9, CM_INV },
  1303.     { "ppp0", 0, 0 },
  1304.     { "ppp1", 1, 0 },                   /* For use with PPP driver */
  1305.     { "ppp2", 2, 0 },                   /* shared access */
  1306.     { "ppp3", 3, 0 },
  1307.     { "ppp4", 4, 0 },
  1308.     { "ppp5", 5, 0 },
  1309.     { "ppp6", 6, 0 },
  1310.     { "ppp7", 7, 0 },
  1311.     { "ppp8", 8, 0 },
  1312.     { "ppp9", 9, 0 }
  1313. };
  1314. int nos2ppp = (sizeof(os2ppptab) / sizeof(struct keytab));
  1315. #endif /* OS2ONLY */
  1316.  
  1317. /*
  1318.   Terminal parameters that can be set by SET commands.
  1319.   Used by the ck?con.c terminal emulator code.
  1320.   For now, only used for #ifdef OS2.  Should add these for Macintosh.
  1321. */
  1322. int tt_arrow = TTK_NORM;                /* Arrow key mode: normal (cursor) */
  1323. int tt_keypad = TTK_NORM;               /* Keypad mode: normal (numeric) */
  1324. int tt_shift_keypad = 0;                /* Keypad Shift mode: Off */
  1325. int tt_wrap = 1;                        /* Terminal wrap, 1 = On */
  1326. int tt_type = TT_VT320;                 /* Terminal type, initially VT320 */
  1327. int tt_type_mode = TT_VT320;            /* Terminal type set by host command */
  1328. int tt_cursor = 0;                      /* Terminal cursor, 0 = Underline */
  1329. int tt_cursor_usr = 0;                  /* Users Terminal cursor type */
  1330. int tt_cursorena_usr = 1;               /* Users Terminal cursor enabled */
  1331. int tt_cursor_blink = 1;                /* Terminal Cursor Blink */
  1332. int tt_answer = 0;                      /* Terminal answerback (disabled) */
  1333. int tt_scrsize[VNUM] = {512,512,512,1}; /* Terminal scrollback buffer size */
  1334. int tt_roll[VNUM] = {1,1,1,1};          /* Terminal roll (on) */
  1335. int tt_rkeys[VNUM] = {1,1,1,1};        /* Terminal roll keys (send) */
  1336. int tt_pacing = 0;                      /* Terminal output-pacing (none) */
  1337. int tt_ctstmo = 15;                     /* Terminal transmit-timeout */
  1338. int tt_codepage = -1;                   /* Terminal code-page */
  1339. int tt_update = 100;                    /* Terminal screen-update interval */
  1340. int tt_updmode = TTU_FAST;              /* Terminal screen-update mode FAST */
  1341. extern int updmode;
  1342. #ifndef KUI
  1343. int tt_status[VNUM] = {1,1,0,0};        /* Terminal status line displayed */
  1344. int tt_status_usr[VNUM] = {1,1,0,0};
  1345. #else  /* KUI */
  1346. extern CKFLOAT floatval;
  1347. CKFLOAT tt_linespacing[VNUM] = {1.0,1.0,1.0,1.0};
  1348. #ifdef K95G
  1349. int tt_status[VNUM] = {1,1,0,0};        /* Terminal status line displayed */
  1350. int tt_status_usr[VNUM] = {1,1,0,0};
  1351. #else /* K95G */
  1352. int tt_status[VNUM] = {0,0,0,0};        /* Terminal status line displayed */
  1353. int tt_status_usr[VNUM] = {0,0,0,0};
  1354. #endif /* K95G */
  1355. #endif /* KUI */
  1356. int tt_senddata = 0;                    /* Let host read terminal data */
  1357. extern int wy_blockend;                 /* Terminal Send Data EOB type */
  1358. int tt_hidattr = 1;                     /* Attributes are hidden */
  1359.  
  1360. extern unsigned char colornormal, colorselect,
  1361. colorunderline, colorstatus, colorhelp, colorborder,
  1362. colorgraphic, colordebug, colorreverse, coloritalic;
  1363.  
  1364. extern int trueblink, trueunderline, truereverse, trueitalic, truedim;
  1365.  
  1366. extern int bgi, fgi;
  1367. extern int scrninitialized[];
  1368.  
  1369. struct keytab audibletab[] = {          /* Terminal Bell Audible mode */
  1370.     { "beep",          XYB_BEEP, 0 },   /* Values ORd with bell mode */
  1371.     { "system-sounds", XYB_SYS,  0 }
  1372. };
  1373. int naudibletab = sizeof(audibletab)/sizeof(struct keytab);
  1374.  
  1375. struct keytab akmtab[] = {              /* Arrow key mode */
  1376.     { "application", TTK_APPL, 0 },
  1377.     { "cursor",      TTK_NORM, 0 }
  1378. };
  1379. struct keytab kpmtab[] = {              /* Keypad mode */
  1380.     { "application", TTK_APPL, 0 },
  1381.     { "numeric",     TTK_NORM, 0 }
  1382. };
  1383.  
  1384. struct keytab ttcolmodetab[] = {
  1385.     { "current-color", 0, 0 },
  1386.     { "default-color", 1, 0 }
  1387. };
  1388. int ncolmode = sizeof(ttcolmodetab)/sizeof(struct keytab);
  1389.  
  1390. #define TTCOLNOR  0
  1391. #define TTCOLREV  1
  1392. #define TTCOLUND  2
  1393. #define TTCOLSTA  3
  1394. #define TTCOLHLP  4
  1395. #define TTCOLBOR  5
  1396. #define TTCOLSEL  6
  1397. #define TTCOLDEB  7
  1398. #define TTCOLGRP  8
  1399. #define TTCOLITA  9
  1400. #define TTCOLRES  10
  1401. #define TTCOLERA  11
  1402.  
  1403. struct keytab ttycoltab[] = {                   /* Terminal Screen coloring */
  1404.     { "border",             TTCOLBOR, 0 },      /* Screen border color */
  1405.     { "debug-terminal",     TTCOLDEB, 0 },      /* Debug color */
  1406.     { "erase",              TTCOLERA, 0 },      /* Erase mode */
  1407.     { "graphic",            TTCOLGRP, 0 },      /* Graphic Color */
  1408.     { "help-text",          TTCOLHLP, 0 },      /* Help screens */
  1409.     { "italic",             TTCOLITA, 0 },      /* Italic Color */
  1410.     { "normal",             TTCOLNOR, CM_INV }, /* Normal screen text */
  1411.     { "reset-on-esc[0m",    TTCOLRES, 0 },      /* Reset on ESC [ 0 m */
  1412.     { "reverse-video",      TTCOLREV, 0 },      /* Reverse video */
  1413.     { "status-line",        TTCOLSTA, 0 },      /* Status line */
  1414.     { "selection",          TTCOLSEL, 0 },      /* Selection color */
  1415.     { "terminal-screen",    TTCOLNOR, 0 },      /* Better name than "normal" */
  1416.     { "underlined-text",    TTCOLUND, 0 }       /* Underlined text */
  1417. };
  1418. int ncolors = (sizeof(ttycoltab) / sizeof(struct keytab));
  1419.  
  1420. #define TTATTNOR  0
  1421. #define TTATTBLI  1
  1422. #define TTATTREV  2
  1423. #define TTATTUND  3
  1424. #define TTATTPRO  4
  1425. #define TTATTBLD  5
  1426. #define TTATTDIM  6
  1427. #define TTATTINV  7
  1428. #define TTATTITA  8
  1429. #define TTATTDONE 9
  1430.  
  1431. struct keytab ttyattrtab[] = {
  1432.     { "blink",     TTATTBLI, 0 },
  1433.     { "dim",       TTATTDIM, 0 },
  1434.     { "italic",    TTATTITA, 0 },
  1435.     { "protected", TTATTPRO, 0 },
  1436.     { "reverse",   TTATTREV, 0 },
  1437.     { "underline", TTATTUND, 0 }
  1438. };
  1439. int nattrib = (sizeof(ttyattrtab) / sizeof(struct keytab));
  1440.  
  1441. struct keytab ttyprotab[] = {
  1442.     { "blink",       TTATTBLI,  0 },
  1443.     { "bold",        TTATTBLD,  0 },
  1444.     { "dim",         TTATTDIM,  0 },
  1445.     { "done",        TTATTDONE, CM_INV },
  1446.     { "invisible",   TTATTINV,  0 },
  1447.     { "italic",      TTATTITA,  0 },
  1448.     { "normal",      TTATTNOR,  0 },
  1449.     { "reverse",     TTATTREV,  0 },
  1450.     { "underlined",  TTATTUND,  0 }
  1451.  
  1452. };
  1453. int nprotect = (sizeof(ttyprotab) / sizeof(struct keytab));
  1454.  
  1455. struct keytab ttyseobtab[] = {
  1456.     { "crlf_etx",  1, 0 },
  1457.     { "us_cr",     0, 0 }
  1458. };
  1459.  
  1460. struct keytab ttyclrtab[] = {           /* Colors */
  1461.     { "black",         0, 0      },
  1462.     { "blue",          1, 0      },
  1463.     { "brown",         6, 0      },
  1464.     { "cyan",          3, 0      },
  1465.     { "darkgray",      8, CM_INV },
  1466.     { "dgray",         8, 0      },
  1467.     { "green",         2, 0      },
  1468.     { "lblue",         9, CM_INV },
  1469.     { "lcyan",        11, CM_INV },
  1470.     { "lgray",         7, CM_INV },
  1471.     { "lgreen",       10, CM_INV },
  1472.     { "lightblue",     9, 0      },
  1473.     { "lightcyan",    11, 0      },
  1474.     { "lightgray",     7, 0      },
  1475.     { "lightgreen",   10, 0      },
  1476.     { "lightmagenta", 13, 0      },
  1477.     { "lightred",     12, 0      },
  1478.     { "lmagenta",     13, CM_INV },
  1479.     { "lred",         12, CM_INV },
  1480.     { "magenta",       5, 0      },
  1481.     { "red",           4, 0      },
  1482.     { "white",        15, 0      },
  1483.     { "yellow",       14, 0      }
  1484. };
  1485. int nclrs = (sizeof (ttyclrtab) / sizeof (struct keytab));
  1486.  
  1487. struct keytab ttycurtab[] = {
  1488.     { "full",        TTC_BLOCK, 0 },
  1489.     { "half",        TTC_HALF,  0 },
  1490.     { "underline",   TTC_ULINE, 0 }
  1491. };
  1492. int ncursors = 3;
  1493.  
  1494. struct keytab ttyptab[] = {
  1495.     { "aaa",      TT_AAA,     CM_INV },     /* AnnArbor */
  1496.     { "adm3a",    TT_ADM3A,   0 },          /* LSI ADM-3A */
  1497.     { "aixterm",  TT_AIXTERM, 0 },          /* IBM AIXterm */
  1498.     { "annarbor", TT_AAA,     0 },          /* AnnArbor */
  1499.     { "ansi-bbs", TT_ANSI,    0 },          /* ANSI.SYS (BBS) */
  1500.     { "at386",    TT_AT386,   0 },          /* Unixware ANSI */
  1501.     { "avatar/0+",TT_ANSI,    0 },          /* AVATAR/0+ */
  1502.     { "ba80",     TT_BA80,    0 },          /* Nixdorf BA80 */
  1503.     { "be",       TT_BEOS,    CM_INV|CM_ABR },
  1504.     { "beos-ansi",TT_BEOS,    CM_INV },     /* BeOS ANSI */
  1505.     { "beterm",   TT_BEOS,    0 },          /* BeOS Terminal (as of PR2 ) */
  1506.     { "d200",     TT_DG200,   CM_INV|CM_ABR }, /* Data General DASHER 200 */
  1507.     { "d210",     TT_DG210,   CM_INV|CM_ABR }, /* Data General DASHER 210 */
  1508.     { "d217",     TT_DG217,   CM_INV|CM_ABR }, /* Data General DASHER 217 */
  1509.     { "dg200",    TT_DG200,   0 },          /* Data General DASHER 200 */
  1510.     { "dg210",    TT_DG210,   0 },          /* Data General DASHER 210 */
  1511.     { "dg217",    TT_DG217,   0 },          /* Data General DASHER 217 */
  1512.     { "h1500",    TT_HZL1500, CM_INV },     /* Hazeltine 1500 */
  1513.     { "h19",      TT_H19,     CM_INV },     /* Heath-19 */
  1514.     { "heath19",  TT_H19,     0 },          /* Heath-19 */
  1515.     { "hft",      TT_HFT,     0 },          /* IBM High Function Terminal */
  1516.     { "hp2621a",  TT_HP2621,  0 },          /* HP 2621A */
  1517.     { "hpterm",   TT_HPTERM,  0 },          /* HP TERM */
  1518.     { "hz1500",   TT_HZL1500, 0 },          /* Hazeltine 1500 */
  1519.     { "ibm3151",  TT_IBM31,   0 },          /* IBM 3101-xx,3161 */
  1520.     { "linux",    TT_LINUX,   0 },          /* Linux */
  1521.     { "qansi",    TT_QANSI,   0 },          /* QNX ANSI */
  1522.     { "qnx",      TT_QNX,     0 },          /* QNX Console */
  1523.     { "scoansi",  TT_SCOANSI, 0 },          /* SCO ANSI */
  1524.     { "sni-97801",TT_97801,   0 },          /* SNI 97801 */
  1525.     { "sun",      TT_SUN,     0 },          /* SUN Console */
  1526. /*
  1527.   The idea of NONE is to let the console driver handle the escape sequences,
  1528.   which, in theory at least, would give not only ANSI emulation, but also any
  1529.   other kind of emulation that might be provided by alternative console
  1530.   drivers, if any existed.
  1531.  
  1532.   For this to work, ckocon.c would need to be modified to make higher-level
  1533.   calls, like VioWrtTTY(), DosWrite(), or (simply) write(), rather than
  1534.   VioWrt*Cell() and similar, and it would also have to give up its rollback
  1535.   feature, and its status line and help screens would also have to be
  1536.   forgotten or else done in an ANSI way.
  1537.  
  1538.   As matters stand, we already have perfectly good ANSI emulation built in,
  1539.   and there are no alternative console drivers available, so there is no point
  1540.   in having a terminal type of NONE, so it is commented out.  However, should
  1541.   you uncomment it, it will work like a "glass tty" -- no escape sequence
  1542.   interpretation at all; somewhat similar to debug mode, except without the
  1543.   debugging (no highlighting of control chars or escape sequences); help
  1544.   screens, status line, and rollback will still work.
  1545. */
  1546. #ifdef OS2PM
  1547. #ifdef COMMENT
  1548.     { "tek4014", TT_TEK40,  0 },
  1549. #endif /* COMMENT */
  1550. #endif /* OS2PM */
  1551.     { "tty",     TT_NONE,   0 },
  1552.     { "tvi910+", TT_TVI910, 0 },
  1553.     { "tvi925",  TT_TVI925, 0 },
  1554.     { "tvi950",  TT_TVI950, 0 },
  1555.     { "vc404",   TT_VC4404, 0 },
  1556.     { "vc4404",  TT_VC4404, CM_INV },
  1557.     { "vip7809", TT_VIP7809,0 },
  1558.     { "vt100",   TT_VT100,  0 },
  1559.     { "vt102",   TT_VT102,  0 },
  1560.     { "vt220",   TT_VT220,  0 },
  1561.     { "vt220pc", TT_VT220PC,0 },
  1562.     { "vt320",   TT_VT320,  0 },
  1563.     { "vt320pc", TT_VT320PC,0 },
  1564.     { "vt52",    TT_VT52,   0 },
  1565. #ifdef NT
  1566.     { "vtnt",    TT_VTNT,   0 },
  1567. #else /* NT */
  1568.     { "vtnt",    TT_VTNT,  CM_INV },
  1569. #endif /* NT */
  1570.     { "wy160",   TT_WY160,  0 },
  1571.     { "wy30",    TT_WY30,   0 },
  1572.     { "wy370",   TT_WY370,  0 },
  1573.     { "wy50",    TT_WY50,   0 },
  1574.     { "wy60",    TT_WY60,   0 },
  1575.     { "wyse30",  TT_WY30,   CM_INV },
  1576.     { "wyse370", TT_WY370,  CM_INV },
  1577.     { "wyse50",  TT_WY50,   CM_INV },
  1578.     { "wyse60",  TT_WY60,   CM_INV }
  1579. };
  1580. int nttyp = (sizeof(ttyptab) / sizeof(struct keytab));
  1581.  
  1582. struct keytab ttkeytab[] = {
  1583.     { "aaa",       TT_AAA,        CM_INV },        /* AnnArbor */
  1584.     { "adm3a",     TT_ADM3A,      0 },             /* LSI ADM-3A */
  1585.     { "aixterm",   TT_AIXTERM,    0 },             /* IBM AIXterm */
  1586.     { "annarbor",  TT_AAA,        0 },             /* AnnArbor */
  1587.     { "ansi-bbs",  TT_ANSI,       0 },             /* ANSI.SYS (BBS) */
  1588.     { "at386",     TT_AT386,      0 },             /* Unixware ANSI */
  1589.     { "avatar/0+", TT_ANSI,       0 },             /* AVATAR/0+ */
  1590.     { "ba80",      TT_BA80,       0 },             /* Nixdorf BA80 */
  1591.     { "be",        TT_BEOS,       CM_INV|CM_ABR },
  1592.     { "beos-ansi", TT_BEOS,       CM_INV },        /* BeOS ANSI */
  1593.     { "beterm",    TT_BEOS,       0 },             /* BeOS Terminal (DR2) */
  1594.     { "d200",      TT_DG200,      CM_INV|CM_ABR }, /* DG DASHER 200 */
  1595.     { "d210",      TT_DG210,      CM_INV|CM_ABR }, /* DG DASHER 210 */
  1596.     { "d217",      TT_DG217,      CM_INV|CM_ABR }, /* DG DASHER 217 */
  1597.     { "dg200",     TT_DG200,      0 },             /* DG DASHER 200 */
  1598.     { "dg210",     TT_DG210,      0 },             /* DG DASHER 210 */
  1599.     { "dg217",     TT_DG217,      0 },             /* DG DASHER 217 */
  1600.     { "emacs",     TT_KBM_EMACS,  0 },             /* Emacs mode */
  1601.     { "h19",       TT_H19,        CM_INV },        /* Heath-19 */
  1602.     { "heath19",   TT_H19,        0 },             /* Heath-19 */
  1603.     { "hebrew",    TT_KBM_HEBREW, 0 },             /* Hebrew mode */
  1604.     { "hft",       TT_HFT,        0 },             /* IBM High Function Term */
  1605.     { "hp2621a",   TT_HP2621,     0 },             /* HP 2621A */
  1606.     { "hpterm",    TT_HPTERM,     0 },             /* HP TERM */
  1607.     { "hz1500",    TT_HZL1500,    0 },             /* Hazeltine 1500 */
  1608.     { "ibm3151",   TT_IBM31,      0 },             /* IBM 3101-xx,3161 */
  1609.     { "linux",     TT_LINUX,      0 },             /* Linux */
  1610.     { "qansi",     TT_QANSI,      0 },             /* QNX ANSI */
  1611.     { "qnx",       TT_QNX,        0 },             /* QNX */
  1612.     { "russian",   TT_KBM_RUSSIAN,0 },             /* Russian mode */
  1613.     { "scoansi",   TT_SCOANSI,    0 },             /* SCO ANSI */
  1614.     { "sni-97801", TT_97801,      0 },             /* SNI 97801 */
  1615.     { "sun",       TT_SUN,        0 },             /* SUN Console */
  1616. #ifdef OS2PM
  1617. #ifdef COMMENT
  1618.     { "tek4014",   TT_TEK40,      0 },
  1619. #endif /* COMMENT */
  1620. #endif /* OS2PM */
  1621.     { "tty",       TT_NONE,       0 },
  1622.     { "tvi910+",   TT_TVI910,     0 },
  1623.     { "tvi925",    TT_TVI925,     0 },
  1624.     { "tvi950",    TT_TVI950,     0 },
  1625.     { "vc404",     TT_VC4404,     0 },
  1626.     { "vc4404",    TT_VC4404,     CM_INV },
  1627.     { "vip7809",   TT_VIP7809,    0 },
  1628.     { "vt100",     TT_VT100,      0 },
  1629.     { "vt102",     TT_VT102,      0 },
  1630.     { "vt220",     TT_VT220,      0 },
  1631.     { "vt220pc",   TT_VT220PC,    0 },
  1632.     { "vt320",     TT_VT320,      0 },
  1633.     { "vt320pc",   TT_VT320PC,    0 },
  1634.     { "vt52",      TT_VT52,       0 },
  1635.     { "vtnt",      TT_VTNT,       CM_INV },
  1636.     { "wp",        TT_KBM_WP,     0 },             /* Word Perfect mode */
  1637.     { "wy160",     TT_WY160,      0 },
  1638.     { "wy30",      TT_WY30,       0 },
  1639.     { "wy370",     TT_WY370,      0 },
  1640.     { "wy50",      TT_WY50,       0 },
  1641.     { "wy60",      TT_WY60,       0 },
  1642.     { "wyse30",    TT_WY30,       CM_INV },
  1643.     { "wyse370",   TT_WY370,      CM_INV },
  1644.     { "wyse50",    TT_WY50,       CM_INV },
  1645.     { "wyse60",    TT_WY60,       CM_INV }
  1646. };
  1647. int nttkey = (sizeof(ttkeytab) / sizeof(struct keytab));
  1648.  
  1649. #ifndef NOSETKEY
  1650. struct keytab kbmodtab[] = {
  1651.     { "emacs",   KBM_EM, 0      },
  1652.     { "english", KBM_EN, CM_INV },
  1653.     { "hebrew",  KBM_HE, 0      },
  1654.     { "normal",  KBM_EN, 0      },
  1655.     { "none",    KBM_EN, CM_INV },
  1656.     { "russian", KBM_RU, 0      },
  1657.     { "wp",      KBM_WP, 0      }
  1658. };
  1659. int nkbmodtab = (sizeof(kbmodtab) / sizeof(struct keytab));
  1660. #endif /* NOSETKEY */
  1661. #endif /* NOLOCAL */
  1662.  
  1663. int tt_inpacing = 0;                    /* input-pacing (none) */
  1664.  
  1665. struct keytab prtytab[] = { /* OS/2 Priority Levels */
  1666.     { "foreground-server", XYP_SRV, 0       },
  1667.     { "idle",              XYP_IDLE, CM_INV },
  1668.     { "regular",           XYP_REG, 0       },
  1669.     { "time-critical",     XYP_RTP, 0       }
  1670. };
  1671. int nprty = (sizeof(prtytab) / sizeof(struct keytab));
  1672. #endif /* OS2 */
  1673.  
  1674. #ifdef NT
  1675. struct keytab win95tab[] = { /* Win95 work-arounds */
  1676.     { "8.3-filenames",         XYW8_3,    0 },
  1677.     { "alt-gr",                XYWAGR,    0 },
  1678.     { "horizontal-scan-line-substitutions", XYWHSL, 0 },
  1679.     { "keyboard-translation",  XYWKEY,    0 },
  1680.     { "lucida-substitutions",  XYWLUC,    0 },
  1681.     { "overlapped-io",         XYWOIO,    0 },
  1682.     { "popups",                XYWPOPUP,  0 },
  1683.     { "select-bug",            XYWSELECT, 0 }
  1684. };
  1685. int nwin95 = (sizeof(win95tab) / sizeof(struct keytab));
  1686. #endif /* NT */
  1687.  
  1688. #ifdef OS2MOUSE
  1689. extern int wideresult;
  1690. int tt_mouse = 1;                       /* Terminal mouse on/off */
  1691.  
  1692. struct keytab mousetab[] = {            /* Mouse items */
  1693.     { "activate", XYM_ON,     0 },
  1694.     { "button",   XYM_BUTTON, 0 },
  1695.     { "clear",    XYM_CLEAR,  0 },
  1696.     { "debug",    XYM_DEBUG,  0 }
  1697. };
  1698. int nmtab = (sizeof(mousetab)/sizeof(struct keytab));
  1699.  
  1700. struct keytab mousebuttontab[] = {      /* event button */
  1701.     { "1",             XYM_B1, 0 },
  1702.     { "2",             XYM_B2, 0 },
  1703.     { "3",             XYM_B3, 0 },
  1704.     { "one",           XYM_B1, CM_INV },
  1705.     { "three",         XYM_B3, CM_INV },
  1706.     { "two",           XYM_B2, CM_INV }
  1707. };
  1708. int nmbtab = (sizeof(mousebuttontab) / sizeof(struct keytab));
  1709.  
  1710. struct keytab mousemodtab[] = {         /* event button key modifier */
  1711.     { "alt",              XYM_ALT,   0 },
  1712.     { "alt-shift",        XYM_SHIFT|XYM_ALT, 0 },
  1713.     { "ctrl",             XYM_CTRL,  0 },
  1714.     { "ctrl-alt",         XYM_CTRL|XYM_ALT, 0 },
  1715.     { "ctrl-alt-shift",   XYM_CTRL|XYM_SHIFT|XYM_ALT, 0 },
  1716.     { "ctrl-shift",       XYM_CTRL|XYM_SHIFT, 0 },
  1717.     { "none",             0, 0 },
  1718.     { "shift",            XYM_SHIFT, 0 }
  1719. };
  1720. int nmmtab = (sizeof(mousemodtab) / sizeof(struct keytab));
  1721.  
  1722. struct keytab mclicktab[] = {           /* event button click modifier */
  1723.     { "click",        XYM_C1,   0 },
  1724.     { "drag",         XYM_DRAG, 0 },
  1725.     { "double-click", XYM_C2,   0 }
  1726. };
  1727. int nmctab = (sizeof(mclicktab) / sizeof(struct keytab));
  1728.  
  1729. #ifndef NOKVERBS
  1730. extern int nkverbs;
  1731. extern struct keytab kverbs[];
  1732. #endif /* NOKVERBS */
  1733. #endif /* OS2MOUSE */
  1734.  
  1735. /* #ifdef VMS */
  1736. struct keytab fbtab[] = {               /* Binary record types for VMS */
  1737.     { "fixed",     XYFT_B, 0 },         /* Fixed is normal for binary */
  1738.     { "undefined", XYFT_U, 0 }          /* Undefined if they ask for it */
  1739. };
  1740. int nfbtyp = (sizeof(fbtab) / sizeof(struct keytab));
  1741. /* #endif */
  1742.  
  1743. #ifdef VMS
  1744. struct keytab lbltab[] = {              /* Labeled File info */
  1745.     { "acl",         LBL_ACL, 0 },
  1746.     { "backup-date", LBL_BCK, 0 },
  1747.     { "name",        LBL_NAM, 0 },
  1748.     { "owner",       LBL_OWN, 0 },
  1749.     { "path",        LBL_PTH, 0 }
  1750. };
  1751. int nlblp = (sizeof(lbltab) / sizeof(struct keytab));
  1752. #else
  1753. #ifdef OS2
  1754. struct keytab lbltab[] = {              /* Labeled File info */
  1755.     { "archive",   LBL_ARC, 0 },
  1756.     { "extended",  LBL_EXT, 0 },
  1757.     { "hidden",    LBL_HID, 0 },
  1758.     { "read-only", LBL_RO,  0 },
  1759.     { "system",    LBL_SYS, 0 }
  1760. };
  1761. int nlblp = (sizeof(lbltab) / sizeof(struct keytab));
  1762. #endif /* OS2 */
  1763. #endif /* VMS */
  1764.  
  1765. #ifdef CK_CURSES
  1766. #ifdef CK_PCT_BAR
  1767. static struct keytab fdftab[] = {       /* SET FILE DISPLAY FULL options */
  1768.     { "thermometer",    1, 0, },
  1769.     { "no-thermometer", 0, 0  }
  1770. };
  1771. extern int thermometer;
  1772. #endif /* CK_PCT_BAR */
  1773. #endif /* CK_CURSES */
  1774.  
  1775. static struct keytab fdtab[] = {        /* SET FILE DISPLAY options */
  1776. #ifdef MAC                              /* Macintosh */
  1777.     { "fullscreen", XYFD_R,      0 },   /* Full-screen but not curses */
  1778.     { "none",       XYFD_N,      0 },
  1779.     { "off",        XYFD_N, CM_INV },
  1780.     { "on",         XYFD_R, CM_INV },
  1781.     { "quiet",      XYFD_N, CM_INV },
  1782. #else                                   /* Not Mac */
  1783.     { "brief", XYFD_B, 0 },             /* Brief */
  1784.     { "crt", XYFD_S, 0 },               /* CRT display */
  1785. #ifdef CK_CURSES
  1786. #ifdef COMMENT
  1787.     { "curses",     XYFD_C,  CM_INV },  /* Full-screen, curses */
  1788. #endif /* COMMENT */
  1789.     { "fullscreen", XYFD_C,  0 },       /* Full-screen, whatever the method */
  1790. #endif /* CK_CURSES */
  1791. #ifdef KUI
  1792.     { "gui",    XYFD_G, 0 },            /* GUI */
  1793. #endif /* KUI */        
  1794.     { "none",   XYFD_N, 0      },       /* No display */
  1795.     { "off",    XYFD_N, CM_INV },       /* Ditto */
  1796.     { "on",     XYFD_R, CM_INV },       /* On = Serial */
  1797.     { "quiet",  XYFD_N, CM_INV },       /* No display */
  1798.     { "serial", XYFD_R, 0      },       /* Serial */
  1799. #endif /* MAC */
  1800.     { "", 0, 0 }
  1801. };
  1802. int nfdtab = (sizeof(fdtab) / sizeof(struct keytab)) - 1;
  1803.  
  1804. struct keytab rsrtab[] = {              /* For REMOTE SET RECEIVE */
  1805.     { "packet-length", XYLEN,  0 },
  1806.     { "timeout",       XYTIMO, 0 }
  1807. };
  1808. int nrsrtab = (sizeof(rsrtab) / sizeof(struct keytab));
  1809.  
  1810. /* Send/Receive Parameters */
  1811.  
  1812. struct keytab srtab[] = {
  1813.     { "backup", XYBUP, 0 },
  1814. #ifndef NOCSETS
  1815.     { "character-set-selection", XYCSET, 0 },
  1816. #endif /* NOCSETS */
  1817.     { "control-prefix", XYQCTL, 0 },
  1818. #ifdef CKXXCHAR
  1819.     { "double-character", XYDBL, 0 },
  1820. #endif /* CKXXCHAR */
  1821.     { "end-of-packet", XYEOL, 0 },
  1822. #ifdef PIPESEND
  1823.     { "filter", XYFLTR, 0 },
  1824. #endif /* PIPESEND */
  1825. #ifdef CKXXCHAR
  1826.     { "ignore-character", XYIGN, 0 },
  1827. #endif /* CKXXCHAR */
  1828.     { "i-packets", 993, 0 },
  1829.     { "move-to", XYMOVE, 0 },
  1830.     { "negotiation-string-max-length", XYINIL, CM_INV },
  1831.     { "packet-length", XYLEN, 0 },
  1832.     { "pad-character", XYPADC, 0 },
  1833.     { "padding", XYNPAD, 0 },
  1834.     { "pathnames", XYFPATH, 0 },
  1835.     { "pause", XYPAUS, 0 },
  1836. #ifdef CK_PERMS
  1837.     { "permissions", 994, 0},        /* 206 */
  1838. #endif /* CK_PERMS */
  1839.     { "quote", XYQCTL, CM_INV },        /* = CONTROL-PREFIX */
  1840.     { "rename-to", XYRENAME, 0 },
  1841.     { "start-of-packet", XYMARK, 0 },
  1842.     { "timeout", XYTIMO, 0 },
  1843. #ifdef VMS
  1844.     { "version-numbers", 887, 0 },      /* VMS version numbers */
  1845. #endif /* VMS */
  1846.     { "", 0, 0 }
  1847. };
  1848. int nsrtab = (sizeof(srtab) / sizeof(struct keytab)) - 1;
  1849.  
  1850. #ifdef UNICODE
  1851. #define UCS_BOM 1
  1852. #define UCS_BYT 2
  1853. static struct keytab ucstab[] = {
  1854.     { "bom",        UCS_BOM, 0 },
  1855.     { "byte-order", UCS_BYT, 0 },
  1856.     { "", 0, 0 }
  1857. };
  1858. int nucstab = (sizeof(ucstab) / sizeof(struct keytab)) - 1;
  1859.  
  1860. static struct keytab botab[] = {
  1861.     { "big-endian",    0, 0 },
  1862.     { "little-endian", 1, 0 }
  1863. };
  1864. static int nbotab = 2;
  1865. #endif /* UNICODE */
  1866.  
  1867. /* REMOTE SET */
  1868.  
  1869. struct keytab rmstab[] = {
  1870.     { "attributes",  XYATTR, 0      },
  1871.     { "block-check", XYCHKT, 0      },
  1872.     { "file",        XYFILE, 0      },
  1873.     { "incomplete",  XYIFD,  CM_INV },  /* = REMOTE SET FILE INCOMPLETE */
  1874.     { "match",       XYMATCH,0      },
  1875.     { "receive",     XYRECV, 0      },
  1876.     { "retry",       XYRETR, 0      },
  1877.     { "server",      XYSERV, 0      },
  1878.     { "transfer",    XYXFER, 0      },
  1879.     { "window",      XYWIND, 0      },
  1880.     { "xfer",        XYXFER, CM_INV }
  1881. };
  1882. int nrms = (sizeof(rmstab) / sizeof(struct keytab));
  1883.  
  1884. struct keytab attrtab[] = {
  1885. #ifdef STRATUS
  1886.     { "account",       AT_ACCT, 0 },
  1887. #endif /* STRATUS */
  1888.     { "all",           AT_XALL, 0 },
  1889. #ifdef COMMENT
  1890.     { "blocksize",     AT_BLKS, 0 },    /* (not used) */
  1891. #endif /* COMMENT */
  1892. #ifndef NOCSETS
  1893.     { "character-set", AT_ENCO, 0 },
  1894. #endif /* NOCSETS */
  1895. #ifdef STRATUS
  1896.     { "creator",       AT_CREA, 0 },
  1897. #endif /* STRATUS */
  1898.     { "date",          AT_DATE, 0 },
  1899.     { "disposition",   AT_DISP, 0 },
  1900.     { "encoding",      AT_ENCO, CM_INV },
  1901.     { "format",        AT_RECF, CM_INV },
  1902.     { "length",        AT_LENK, 0 },
  1903.     { "off",           AT_ALLN, 0 },
  1904.     { "on",            AT_ALLY, 0 },
  1905. #ifdef COMMENT
  1906.     { "os-specific",   AT_SYSP, 0 },    /* (not used by UNIX or VMS) */
  1907. #endif /* COMMENT */
  1908. #ifdef CK_PERMS
  1909.     { "protection",    AT_LPRO, 0 },
  1910.     { "permissions",   AT_LPRO, CM_INV },
  1911. #endif /* CK_PERMS */
  1912.     { "record-format", AT_RECF, 0 },
  1913.     { "system-id",     AT_SYSI, 0 },
  1914.     { "type",          AT_FTYP, 0 }
  1915. };
  1916. int natr = (sizeof(attrtab) / sizeof(struct keytab)); /* how many attributes */
  1917.  
  1918. #ifdef CKTIDLE
  1919. struct keytab idlacts[] = {
  1920.     { "exit",       IDLE_EXIT, 0 },
  1921.     { "hangup",     IDLE_HANG, 0 },
  1922.     { "output",     IDLE_OUT,  0 },
  1923.     { "return",     IDLE_RET,  0 },
  1924. #ifdef TNCODE
  1925.     { "telnet-nop", IDLE_TNOP, 0 },
  1926.     { "telnet-ayt", IDLE_TAYT, 0 },
  1927. #endif /* TNCODE */
  1928.     { "", 0, 0 }
  1929. };
  1930. int nidlacts = (sizeof(idlacts) / sizeof(struct keytab)) - 1;
  1931. #endif /* CKTIDLE */
  1932.  
  1933. #ifndef NOSPL
  1934. extern int indef, inecho, insilence, inbufsize, inautodl, inintr;
  1935. extern char * inpbuf, * inpbp;
  1936. #ifdef OS2
  1937. extern int interm;
  1938. #endif /* OS2 */
  1939. struct keytab inptab[] = {              /* SET INPUT parameters */
  1940. #ifdef CK_AUTODL
  1941.     { "autodownload",    IN_ADL, 0 },
  1942. #endif /* CK_AUTODL */
  1943.     { "buffer-length",   IN_BUF, 0 },
  1944.     { "cancellation",    IN_CAN, 0 },
  1945.     { "case",            IN_CAS, 0 },
  1946.     { "default-timeout", IN_DEF, CM_INV }, /* There is no default timeout */
  1947.     { "echo",            IN_ECH, 0 },
  1948. #ifdef OS2
  1949.     { "pacing",          IN_PAC, CM_INV },
  1950. #endif /* OS2 */
  1951.     { "silence",         IN_SIL, 0 },
  1952. #ifdef OS2
  1953.     { "terminal",        IN_TRM, 0 },
  1954. #endif /* OS2 */
  1955.     { "timeout-action",  IN_TIM, 0 }
  1956. };
  1957. int ninp = (sizeof(inptab) / sizeof(struct keytab));
  1958.  
  1959. struct keytab intimt[] = {              /* SET INPUT TIMEOUT parameters */
  1960.     { "proceed", 0, 0 },                /* 0 = proceed */
  1961.     { "quit",    1, 0 }                 /* 1 = quit */
  1962. };
  1963.  
  1964. struct keytab incast[] = {              /* SET INPUT CASE parameters */
  1965.     { "ignore",  0, 0 },                /* 0 = ignore */
  1966.     { "observe", 1, 0 }                 /* 1 = observe */
  1967. };
  1968. #endif /* NOSPL */
  1969.  
  1970. struct keytab nabltab[] = {             /* For any command that needs */
  1971.     { "disabled", 0, 0 },
  1972.     { "enabled",  1, 0 },
  1973.     { "off",      0, CM_INV },          /* these keywords... */
  1974.     { "on",       1, CM_INV }
  1975. };
  1976. int nnabltab = sizeof(nabltab) / sizeof(struct keytab);
  1977.  
  1978. #ifdef OS2
  1979. struct keytab tvctab[] = {              /* SET TERM VIDEO-CHANGE */
  1980.     { "disabled",     TVC_DIS, 0 },
  1981.     { "enabled",      TVC_ENA, 0 },
  1982. #ifdef NT
  1983.     { "win95-safe",   TVC_W95, 0 },
  1984. #endif /* NT */
  1985.     { "", 0, 0 }
  1986. };
  1987. int ntvctab = (sizeof(tvctab) / sizeof(struct keytab)) - 1;
  1988.  
  1989. struct keytab msktab[] = { /* SET MS-DOS KERMIT compatibilities */
  1990. #ifdef COMMENT
  1991.     { "color",    MSK_COLOR,  0 },
  1992. #endif /* COMMENT */
  1993.     { "keycodes", MSK_KEYS,   0 }
  1994. };
  1995. int nmsk = (sizeof(msktab) / sizeof(struct keytab));
  1996.  
  1997. struct keytab scrnupd[] = {             /* SET TERMINAL SCREEN-UPDATE */
  1998.     { "fast",   TTU_FAST,   0 },
  1999.     { "smooth", TTU_SMOOTH, 0 }
  2000. };
  2001. int nscrnupd = (sizeof(scrnupd) / sizeof(struct keytab));
  2002.  
  2003. #ifdef PCFONTS
  2004. /* This definition of the term_font[] table is only for     */
  2005. /* the OS/2 Full Screen Session and is not used on Windows */
  2006. struct keytab term_font[] = {           /* SET TERMINAL FONT */
  2007. #ifdef COMMENT
  2008.     { "cp111", TTF_111, 0 },
  2009.     { "cp112", TTF_112, 0 },
  2010.     { "cp113", TTF_113, 0 },
  2011. #endif /* COMMENT */
  2012.     { "cp437", TTF_437, 0 },
  2013.     { "cp850", TTF_850, 0 },
  2014. #ifdef COMMENT
  2015.     { "cp851", TTF_851, 0 },
  2016. #endif /* COMMENT */
  2017.     { "cp852", TTF_852, 0 },
  2018. #ifdef COMMENT
  2019.     { "cp853", TTF_853, 0 },
  2020.     { "cp860", TTF_860, 0 },
  2021.     { "cp861", TTF_861, 0 },
  2022. #endif /* COMMENT */
  2023.     { "cp862", TTF_862, 0 },
  2024. #ifdef COMMENT
  2025.     { "cp863", TTF_863, 0 },
  2026.     { "cp864", TTF_864, 0 },
  2027.     { "cp865", TTF_865, 0 },
  2028. #endif /* COMMENT */
  2029.     { "cp866", TTF_866, 0 },
  2030. #ifdef COMMENT
  2031.     { "cp880", TTF_880, 0 },
  2032.     { "cp881", TTF_881, 0 },
  2033.     { "cp882", TTF_882, 0 },
  2034.     { "cp883", TTF_883, 0 },
  2035.     { "cp884", TTF_884, 0 },
  2036.     { "cp885", TTF_885, 0 },
  2037. #endif /* COMMENT */
  2038.     { "default",TTF_ROM,0 }
  2039. };
  2040. int ntermfont = (sizeof(term_font) / sizeof(struct keytab));
  2041. int tt_font = TTF_ROM;                  /* Terminal screen font */
  2042. #else /* PCFONTS */
  2043. #ifdef NT
  2044. #ifdef KUI
  2045. struct keytab * term_font = NULL;
  2046. struct keytab * _term_font = NULL;
  2047. char * tt_facename = NULL;
  2048. int ntermfont = 0;
  2049. int tt_font = 0;
  2050. int tt_font_size = 0;
  2051. #endif /* KUI */
  2052. #endif /* NT */
  2053. #endif /* PCFONTS */
  2054.  
  2055. struct keytab anbktab[] = {             /* For any command that needs */
  2056.     { "message", 2, 0 },                /* these keywords... */
  2057.     { "off",     0, 0 },
  2058.     { "on",      1, 0 },
  2059.     { "unsafe-messag0", 99, CM_INV },
  2060.     { "unsafe-message", 3,  CM_INV }
  2061. };
  2062. int nansbk = (sizeof(anbktab) / sizeof(struct keytab));
  2063.  
  2064. int win95_popup = 1;
  2065. #ifdef NT
  2066. #ifdef KUI
  2067. int win95lucida = 0;
  2068. int win95hsl = 1;
  2069. #else /* KUI */
  2070. int win95lucida = 1;
  2071. int win95hsl = 1;
  2072. #endif /* KUI */
  2073. #else /* NT */
  2074. int win95lucida = 0;
  2075. int win95hsl = 1;
  2076. #endif /* NT */
  2077. #ifdef NT
  2078. int win95altgr  = 0;
  2079. extern int win95selectbug;
  2080. extern int win95_8_3;
  2081.  
  2082. #ifdef COMMENT
  2083. extern CHAR (*xlr[MAXTCSETS+1][MAXFCSETS+1])(CHAR);
  2084. extern struct keytab tcstab[];
  2085. extern int ntcs;
  2086. #endif /* COMMENT */
  2087. extern int maxow, maxow_usr; owwait;    /* Overlapped I/O variables */
  2088. #endif /* NT */
  2089. #endif /* OS2 */
  2090.  
  2091.  
  2092. /* The following routines broken out of doprm() to give compilers a break. */
  2093.  
  2094. /*  S E T O N  --  Parse on/off (default on), set parameter to result  */
  2095.  
  2096. int
  2097. seton(prm) int *prm; {
  2098.     int x, y;
  2099.     if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  2100.     if ((x = cmcfm()) < 0) return(x);
  2101.     *prm = y;
  2102.     return(1);
  2103. }
  2104.  
  2105. /*  S E T O N A U T O --  Parse on/off/auto (default auto) & set result */
  2106.  
  2107. struct keytab onoffaut[] = {
  2108.     { "auto", SET_AUTO, 0 },            /* 2 */
  2109.     { "off",  SET_OFF,  0 },            /* 0 */
  2110.     { "on",   SET_ON,   0 }             /* 1 */
  2111. };
  2112.  
  2113. int
  2114. setonaut(prm) int *prm; {
  2115.     int x, y;
  2116.     if ((y = cmkey(onoffaut,3,"","auto",xxstring)) < 0) return(y);
  2117.     if ((x = cmcfm()) < 0) return(x);
  2118.     *prm = y;
  2119.     return(1);
  2120. }
  2121.  
  2122. /*  S E T N U M  --  Set parameter to result of cmnum() parse.  */
  2123. /*
  2124.  Call with pointer to integer variable to be set,
  2125.    x = number from cnum parse, y = return code from cmnum,
  2126.    max = maximum value to accept, -1 if no maximum.
  2127.  Returns -9 on failure, after printing a message, or 1 on success.
  2128. */
  2129. int
  2130. setnum(prm,x,y,max) int x, y, *prm, max; {
  2131.     debug(F101,"setnum","",y);
  2132.     if (y == -3) {
  2133.         printf("\n?Value required\n");
  2134.         return(-9);
  2135.     }
  2136.     if (y == -2) {
  2137.         printf("%s?Not a number: %s\n",cmflgs == 1 ? "" : "\n", atxbuf);
  2138.         return(-9);
  2139.     }
  2140.     if (y < 0) return(y);
  2141.     if (max > -1 && x > max) {
  2142.         printf("?Sorry, %d is the maximum\n",max);
  2143.         return(-9);
  2144.     }
  2145.     if ((y = cmcfm()) < 0) return(y);
  2146.     *prm = x;
  2147.     return(1);
  2148. }
  2149.  
  2150. /*  S E T C C  --  Set parameter var to an ASCII control character value.  */
  2151. /*
  2152.   Parses a number, or a literal control character, or a caret (^) followed
  2153.   by an ASCII character whose value is 63-95 or 97-122, then gets confirmation,
  2154.   then sets the parameter to the code value of the character given.  If there
  2155.   are any parse errors, they are returned, otherwise on success 1 is returned.
  2156. */
  2157. int
  2158. setcc(dflt,var) char *dflt; int *var; {
  2159.     int x, y;
  2160.     unsigned int c;
  2161.     char *hlpmsg = "Control character,\n\
  2162.  numeric ASCII value,\n\
  2163.  or in ^X notation,\n\
  2164.  or preceded by a backslash and entered literally";
  2165.  
  2166.     /* This is a hack to turn off complaints from expression evaluator. */
  2167.     x_ifnum = 1;
  2168.     y = cmnum(hlpmsg, dflt, 10, &x, xxstring); /* Parse a number */
  2169.     x_ifnum = 0;                               /* Allow complaints again */
  2170.     if (y < 0) {                        /* Parse failed */
  2171.         if (y != -2)                    /* Reparse needed or somesuch */
  2172.           return(y);                    /* Pass failure back up the chain */
  2173.     }
  2174.     /* Real control character or literal 8-bit character... */
  2175.  
  2176.     for (c = strlen(atmbuf) - 1; c > 0; c--) /* Trim */
  2177.       if (atmbuf[c] == SP) atmbuf[c] = NUL;
  2178.  
  2179.     if (y < 0) {                        /* It was not a number */
  2180.         if (((c = atmbuf[0])) && !atmbuf[1]) { /* Literal character? */
  2181.             c &= 0xff;
  2182.             if (((c > 31) && (c < 127)) || (c > 255)) {
  2183.                 printf("\n?%d: Out of range - must be 0-31 or 127-255\n",c);
  2184.                 return(-9);
  2185.             } else {
  2186.                 if ((y = cmcfm()) < 0)  /* Confirm */
  2187.                   return(y);
  2188.                 *var = c;               /* Set the variable */
  2189.                 return(1);
  2190.             }
  2191.         } else if (atmbuf[0] == '^' && !atmbuf[2]) { /* Or ^X notation? */
  2192.             c = atmbuf[1];
  2193.             if (islower((char) c))      /* Uppercase lowercase letters */
  2194.               c = toupper(c);
  2195.             if (c > 62 && c < 96) {     /* Check range */
  2196.                 if ((y = cmcfm()) < 0)
  2197.                   return(y);
  2198.                 *var = ctl(c);          /* OK */
  2199.                 return(1);
  2200.             } else {
  2201.                 printf("?Not a control character - %s\n", atmbuf);
  2202.                 return(-9);
  2203.             }
  2204.         } else {                        /* Something illegal was typed */
  2205.             printf("?Invalid - %s\n", atmbuf);
  2206.             return(-9);
  2207.         }
  2208.     }
  2209.     if (((x > 31) && (x < 127)) || (x > 255)) { /* They typed a number */
  2210.         printf("\n?%d: Out of range - must be 0-31 or 127-255\n",x);
  2211.         return(-9);
  2212.     }
  2213.     if ((y = cmcfm()) < 0)              /* In range, confirm */
  2214.       return(y);
  2215.     *var = x;                           /* Set variable */
  2216.     return(1);
  2217. }
  2218.  
  2219. #ifndef NOSPL                           /* The SORT command... */
  2220.  
  2221. static struct keytab srtswtab[] = {     /* SORT command switches */
  2222.     { "/case",    SRT_CAS, CM_ARG },
  2223.     { "/key",     SRT_KEY, CM_ARG },
  2224.     { "/numeric", SRT_NUM, 0 },
  2225.     { "/range",   SRT_RNG, CM_ARG },
  2226.     { "/reverse", SRT_REV, 0 }
  2227. };
  2228. static int nsrtswtab = sizeof(srtswtab)/sizeof(struct keytab);
  2229.  
  2230. extern char **a_ptr[];                  /* Array pointers */
  2231. extern int a_dim[];                     /* Array dimensions */
  2232.  
  2233. int
  2234. dosort() {                              /* Do the SORT command */
  2235.     char c, *p = NULL, ** ap, ** xp = NULL;
  2236.     struct FDB sw, fl, cm;
  2237.     int hi, lo;
  2238.     int xn = 0, xr = -1, xk = -1, xc = -1, xs = 0;
  2239.     int getval = 0, range[2], confirmed = 0;
  2240.  
  2241.     cmfdbi(&sw,                         /* First FDB - command switches */
  2242.            _CMKEY,                      /* fcode */
  2243.            "Array name or switch",
  2244.            "",                          /* default */
  2245.            "",                          /* addtl string data */
  2246.            nsrtswtab,                   /* addtl numeric data 1: tbl size */
  2247.            4,                           /* addtl numeric data 2: 4 = cmswi */
  2248.            NULL,                        /* Processing function */
  2249.            srtswtab,                    /* Keyword table */
  2250.            &fl                          /* Pointer to next FDB */
  2251.            );
  2252.     cmfdbi(&fl,                         /* Anything that doesn't match */
  2253.            _CMFLD,                      /* fcode */
  2254.            "Array name",                /* hlpmsg */
  2255.            "",                          /* default */
  2256.            "",                          /* addtl string data */
  2257.            0,                           /* addtl numeric data 1 */
  2258.            0,                           /* addtl numeric data 2 */
  2259.            NULL,
  2260.            NULL,
  2261.            &cm
  2262.            );
  2263.     cmfdbi(&cm,                         /* Or premature confirmation */
  2264.            _CMCFM,                      /* fcode */
  2265.            "",                          /* hlpmsg */
  2266.            "",                          /* default */
  2267.            "",                          /* addtl string data */
  2268.            0,                           /* addtl numeric data 1 */
  2269.            0,                           /* addtl numeric data 2 */
  2270.            NULL,
  2271.            NULL,
  2272.            NULL
  2273.            );
  2274.  
  2275.     range[0] = -1;
  2276.     range[1] = -1;
  2277.  
  2278.     while (1) {                         /* Parse 0 or more switches */
  2279.         x = cmfdb(&sw);
  2280.         if (x < 0)
  2281.           return(x);
  2282.         if (cmresult.fcode != _CMKEY)   /* Break out if not a switch */
  2283.           break;
  2284.         c = cmgbrk();
  2285.         getval = (c == ':' || c == '=');
  2286.         if (getval && !(cmresult.kflags & CM_ARG)) {
  2287.             printf("?This switch does not take arguments\n");
  2288.             return(-9);
  2289.         }
  2290.         switch (cmresult.nresult) {
  2291.           case SRT_REV:
  2292.             xr = 1;
  2293.             break;
  2294.           case SRT_KEY:
  2295.             if (getval) {
  2296.                 if ((y = cmnum("Column for comparison (1-based)",
  2297.                                "1",10,&x,xxstring)) < 0)
  2298.                   return(y);
  2299.                 xk = x - 1;
  2300.             } else
  2301.               xk = 0;
  2302.             break;
  2303.           case SRT_CAS:
  2304.             if (getval) {
  2305.                 if ((y = cmkey(onoff,2,"","on",xxstring)) < 0)
  2306.                   return(y);
  2307.                 xc = y;
  2308.             } else
  2309.               xc = 1;
  2310.             break;
  2311.           case SRT_RNG:                 /* /RANGE */
  2312.             if (getval) {
  2313.                 char buf[32];
  2314.                 char buf2[16];
  2315.                 int i;
  2316.                 char * p, * q;
  2317.                 if ((y = cmfld("low:high element","1",&s,NULL)) < 0)
  2318.                   return(y);
  2319.                 s = brstrip(s);
  2320.                 ckstrncpy(buf,s,32);
  2321.                 p = buf;
  2322.                 for (i = 0; *p && i < 2; i++) { /* Get low and high */
  2323.                     q = p;              /* Start of this piece */
  2324.                     while (*p) {        /* Find end of this piece */
  2325.                         if (*p == ':') {
  2326.                             *p = NUL;
  2327.                             p++;
  2328.                             break;
  2329.                         }
  2330.                         p++;
  2331.                     }
  2332.                     y = 15;             /* Evaluate this piece */
  2333.                     s = buf2;
  2334.                     zzstring(q,&s,&y);
  2335.                     s = evalx(buf2);
  2336.                     if (s) if (*s) ckstrncpy(buf2,s,16);
  2337.                     if (!rdigits(buf2)) {
  2338.                         printf("?Not numeric: %s\n",buf2);
  2339.                         return(-9);
  2340.                     }
  2341.                     range[i] = atoi(buf2);
  2342.                 }
  2343.             }
  2344.             break;
  2345.           case SRT_NUM:                 /* /NUMERIC */
  2346.             xn = 1;
  2347.             break;
  2348.           default:
  2349.             return(-2);
  2350.         }
  2351.     }
  2352.     switch (cmresult.fcode) {
  2353.       case _CMCFM:
  2354.         confirmed = 1;
  2355.         break;
  2356.       case _CMFLD:
  2357.         ckstrncpy(line,cmresult.sresult,LINBUFSIZ); /* Safe copy of name */
  2358.         s = line;
  2359.         break;
  2360.       default:
  2361.         printf("?Unexpected function code: %d\n",cmresult.fcode);
  2362.         return(-9);
  2363.     }
  2364.     if (confirmed) {
  2365.         printf("?Array name required\n");
  2366.         return(-9);
  2367.     }
  2368.     ckmakmsg(tmpbuf,TMPBUFSIZ,
  2369.              "Second array to sort according to ",s,NULL,NULL);
  2370.     if ((x = cmfld(tmpbuf,"",&p,NULL)) < 0)
  2371.       if (x != -3)
  2372.         return(x);
  2373.     tmpbuf[0] = NUL;
  2374.     ckstrncpy(tmpbuf,p,TMPBUFSIZ);
  2375.     p = tmpbuf;
  2376.     if ((x = cmcfm()) < 0)              /* Get confirmation */
  2377.       return(x);
  2378.  
  2379.     x = arraybounds(s,&lo,&hi);         /* Get array index & bounds */
  2380.     if (x < 0) {                        /* Check */
  2381.         printf("?Bad array name: %s\n",s);
  2382.         return(-9);
  2383.     }
  2384.     if (lo > -1) range[0] = lo;         /* Set range */
  2385.     if (hi > -1) range[1] = hi;
  2386.     ap = a_ptr[x];                      /* Get pointer to array element list */
  2387.     if (!ap) {                          /* Check */
  2388.         printf("?Array not declared: %s\n", s);
  2389.         return(-9);
  2390.     }
  2391.     if (range[0] < 0)                   /* Starting element */
  2392.       range[0] = 1;
  2393.     if (range[1] < 0)                   /* Final element */
  2394.       range[1] = a_dim[x];
  2395.     if (range[1] > a_dim[x]) {
  2396.         printf("?range %d:%d exceeds array dimension %d\n",
  2397.                range[0],range[1],a_dim[x]
  2398.                );
  2399.         return(-9);
  2400.     }
  2401.     ap += range[0];
  2402.     xs = range[1] - range[0] + 1;       /* Number of elements to sort */
  2403.     if (xs < 1) {                       /* Check */
  2404.         printf("?Bad range: %d:%d\n",range[0],range[1]);
  2405.         return(-9);
  2406.     }
  2407.     if (xk < 0) xk = 0;                 /* Key position */
  2408.     if (xr < 0) xr = 0;                 /* Reverse flag */
  2409.     if (xn)                             /* Numeric flag */
  2410.       xc = 2;
  2411.     else if (xc < 0)                    /* Not numeric */
  2412.       xc = inpcas[cmdlvl];              /* so alpha case option */
  2413.  
  2414.     if (*p) {                           /* Parallel array given? */
  2415.         y = xarray(p);                  /* Yes, get its index. */
  2416.         if (y < 0) {
  2417.             printf("?Bad array name: %s\n", p);
  2418.             return(-9);
  2419.         }
  2420.         if (y != x) {                   /* If the 2 arrays are different  */
  2421.             xp = a_ptr[y];              /* Pointer to 2nd array element list */
  2422.             if (!xp) {
  2423.                 printf("?Array not declared: %s\n", p);
  2424.                 return(-9);
  2425.             }
  2426.             if (a_dim[y] < range[1]) {
  2427.                 printf("?Array %s smaller than %s\n", p, s);
  2428.                 return(-9);
  2429.             }
  2430.             xp += range[0];             /* Set base to same as 1st array */
  2431.         }
  2432.     }
  2433.     sh_sort(ap,xp,xs,xk,xr,xc);         /* Sort the array(s) */
  2434.     return(success = 1);                /* Always succeeds */
  2435. }
  2436. #endif /* NOSPL */
  2437.  
  2438. static struct keytab purgtab[] = {      /* PURGE command switches */
  2439.     { "/after",        PU_AFT,  CM_ARG },
  2440.     { "/ask",          PU_ASK,  0 },
  2441.     { "/before",       PU_BEF,  CM_ARG },
  2442.     { "/delete",       PU_DELE, CM_INV },
  2443. #ifdef UNIXOROSK
  2444.     { "/dotfiles",     PU_DOT,  0 },
  2445. #endif /* UNIXOROSK */
  2446.     { "/except",       PU_EXC,  CM_ARG },
  2447.     { "/heading",      PU_HDG,  0 },
  2448.     { "/keep",         PU_KEEP, CM_ARG },
  2449.     { "/larger-than",  PU_LAR,  CM_ARG },
  2450.     { "/list",         PU_LIST, 0 },
  2451.     { "/log",          PU_LIST, CM_INV },
  2452.     { "/noask",        PU_NASK, 0 },
  2453.     { "/nodelete",     PU_NODE, CM_INV },
  2454. #ifdef UNIXOROSK
  2455.     { "/nodotfiles",   PU_NODOT,0 },
  2456. #endif /* UNIXOROSK */
  2457.     { "/noheading",    PU_NOH,  0 },
  2458.     { "/nol",          PU_NOLI, CM_INV|CM_ABR },
  2459.     { "/nolist",       PU_NOLI, 0 },
  2460.     { "/nolog",        PU_NOLI, CM_INV },
  2461. #ifdef CK_TTGWSIZ
  2462.     { "/nopage",       PU_NOPA, 0 },
  2463. #endif /* CK_TTGWSIZ */
  2464.     { "/not-after",    PU_NAF,  CM_ARG },
  2465.     { "/not-before",   PU_NBF,  CM_ARG },
  2466.     { "/not-since",    PU_NAF,  CM_INV|CM_ARG },
  2467. #ifdef CK_TTGWSIZ
  2468.     { "/page",         PU_PAGE, 0 },
  2469. #endif /* CK_TTGWSIZ */
  2470.     { "/quiet",        PU_QUIE, CM_INV },
  2471. #ifdef RECURSIVE
  2472.     { "/recursive",    PU_RECU, 0 },
  2473. #endif /* RECURSIVE */
  2474.     { "/since",        PU_AFT,  CM_ARG|CM_INV },
  2475.     { "/simulate",     PU_NODE, 0 },
  2476.     { "/smaller-than", PU_SMA,  CM_ARG },
  2477.     { "/verbose",      PU_VERB, CM_INV }
  2478. };
  2479. static int npurgtab = sizeof(purgtab)/sizeof(struct keytab);
  2480.  
  2481.  
  2482.  
  2483.  
  2484.  
  2485. int
  2486. bkupnum(s,i) char * s; int *i; {
  2487.     int k = 0, pos = 0;
  2488.     char * p = NULL, *q;
  2489.     *i = pos;
  2490.     if (!s) s = "";
  2491.     if (!*s)
  2492.       return(-1);
  2493.     if ((k = strlen(s)) < 5)
  2494.       return(-1);
  2495.  
  2496.     if (s[k-1] != '~')
  2497.       return(-1);
  2498.     pos = k - 2;
  2499.     q = s + pos;
  2500.     while (q >= s && isdigit(*q)) {
  2501.         p = q--;
  2502.         pos--;
  2503.     }
  2504.     if (!p)
  2505.       return(-1);
  2506.     if (q < s+2)
  2507.       return(-1);
  2508.     if (*q != '~' || *(q-1) != '.')
  2509.       return(-1);
  2510.     pos--;
  2511.     *i = pos;
  2512.     debug(F111,"bkupnum",s+pos,pos);
  2513.     return(atoi(p));
  2514. }
  2515.  
  2516. #ifdef CKPURGE
  2517. /* Presently only for UNIX because we need direct access to the file array. */
  2518. /* Not needed for VMS anyway, because we don't make backup files there. */
  2519.  
  2520. #define MAXKEEP 32                      /* Biggest /KEEP: value */
  2521.  
  2522. static int
  2523.   pu_keep = 0, pu_list = 0, pu_dot = 0, pu_ask = 0, pu_hdg = 0;
  2524.  
  2525. #ifdef CK_TTGWSIZ
  2526. static int pu_page = -1;
  2527. #else
  2528. static int pu_page = 0;
  2529. #endif /* CK_TTGWSIZ */
  2530.  
  2531. #ifndef NOSHOW
  2532. VOID
  2533. showpurgopts() {                        /* SHOW PURGE command options */
  2534.     int x = 0;
  2535.     extern int optlines;
  2536.     prtopt(&optlines,"PURGE");
  2537.     if (pu_ask > -1) {
  2538.         x++;
  2539.         prtopt(&optlines, pu_ask ? "/ASK" : "/NOASK");
  2540.     }
  2541. #ifdef UNIXOROSK
  2542.     if (pu_dot > -1) {
  2543.         x++;
  2544.         prtopt(&optlines, pu_dot ? "/DOTFILES" : "/NODOTFILES");
  2545.     }
  2546. #endif /* UNIXOROSK */
  2547.     if (pu_keep > -1) {
  2548.         x++;
  2549.         ckmakmsg(tmpbuf,TMPBUFSIZ,"/KEEP:",ckitoa(pu_keep),NULL,NULL);
  2550.         prtopt(&optlines,tmpbuf);
  2551.     }
  2552.     if (pu_list > -1) {
  2553.         x++;
  2554.         prtopt(&optlines, pu_list ? "/LIST" : "/NOLIST");
  2555.     }
  2556.     if (pu_hdg > -1) {
  2557.         x++;
  2558.         prtopt(&optlines, pu_hdg ? "/HEADING" : "/NOHEADING");
  2559.     }
  2560. #ifdef CK_TTGWSIZ
  2561.     if (pu_page > -1) {
  2562.         x++;
  2563.         prtopt(&optlines, pu_page ? "/PAGE" : "/NOPAGE");
  2564.     }
  2565. #endif /* CK_TTGWSIZ */
  2566.     if (!x) prtopt(&optlines,"(no options set)");
  2567.     prtopt(&optlines,"");
  2568. }
  2569. #endif /* NOSHOW */
  2570.  
  2571. int
  2572. setpurgopts() {                         /* Set PURGE command options */
  2573.     int c, z, getval = 0;
  2574.     int
  2575.       x_keep  = -1, x_list = -1, x_page = -1,
  2576.       x_hdg   = -1, x_ask  = -1, x_dot  = -1;
  2577.  
  2578.     while (1) {
  2579.         if ((y = cmswi(purgtab,npurgtab,"Switch","",xxstring)) < 0) {
  2580.             if (y == -3)
  2581.               break;
  2582.             else
  2583.               return(y);
  2584.         }
  2585.         c = cmgbrk();
  2586.         if ((getval = (c == ':' || c == '=')) && !(cmgkwflgs() & CM_ARG)) {
  2587.             printf("?This switch does not take an argument\n");
  2588.             return(-9);
  2589.         }
  2590.         if (!getval && (cmgkwflgs() & CM_ARG)) {
  2591.             printf("?This switch requires an argument\n");
  2592.             return(-9);
  2593.         }
  2594.         switch (y) {
  2595.           case PU_KEEP:
  2596.             z = 1;
  2597.             if (c == ':' || c == '=')
  2598.               if ((y = cmnum("How many backup files to keep",
  2599.                              "1",10,&z,xxstring)) < 0)
  2600.                 return(y);
  2601.             if (z < 0 || z > MAXKEEP) {
  2602.                 printf("?Please specify a number between 0 and %d\n",
  2603.                        MAXKEEP
  2604.                        );
  2605.                 return(-9);
  2606.             }
  2607.             x_keep = z;
  2608.             break;
  2609.           case PU_LIST:
  2610.           case PU_VERB:
  2611.             x_list = 1;
  2612.             break;
  2613.           case PU_QUIE:
  2614.           case PU_NOLI:
  2615.             x_list = 0;
  2616.             break;
  2617. #ifdef CK_TTGWSIZ
  2618.           case PU_PAGE:
  2619.             x_page = 1;
  2620.             break;
  2621.           case PU_NOPA:
  2622.             x_page = 0;
  2623.             break;
  2624. #endif /* CK_TTGWSIZ */
  2625.           case PU_HDG:
  2626.             x_hdg = 1;
  2627.             break;
  2628.           case PU_NOH:
  2629.             x_hdg = 0;
  2630.             break;
  2631.           case PU_ASK:
  2632.             x_ask = 1;
  2633.             break;
  2634.           case PU_NASK:
  2635.             x_ask = 0;
  2636.             break;
  2637. #ifdef UNIXOROSK
  2638.           case PU_DOT:
  2639.             x_dot = 1;
  2640.             break;
  2641.           case PU_NODOT:
  2642.             x_dot = 0;
  2643.             break;
  2644. #endif /* UNIXOROSK */
  2645.           default:
  2646.             printf("?This option can not be set\n");
  2647.             return(-9);
  2648.         }
  2649.     }
  2650.     if ((x = cmcfm()) < 0)              /* Get confirmation */
  2651.       return(x);
  2652.     if (x_keep > -1)                    /* Set PURGE defaults. */
  2653.       pu_keep = x_keep;
  2654.     if (x_list > -1)
  2655.       pu_list = x_list;
  2656. #ifdef CK_TTGWSIZ
  2657.     if (x_page > -1)
  2658.       pu_page = x_page;
  2659. #endif /* CK_TTGWSIZ */
  2660.     if (x_hdg > -1)
  2661.       pu_hdg = x_hdg;
  2662.     if (x_ask > -1)
  2663.       pu_ask = x_ask;
  2664.     if (x_dot > -1)
  2665.       pu_dot = x_dot;
  2666.     return(success = 1);
  2667. }
  2668.  
  2669. int
  2670. dopurge() {                             /* Do the PURGE command */
  2671.     extern char ** mtchs;
  2672.     extern int xaskmore, cmd_rows, recursive;
  2673.     int simulate = 0, asking = 0;
  2674.     int listing = 0, paging = -1, lines = 0, deleting = 1, errors = 0;
  2675.     struct FDB sw, sf, cm;
  2676.     int g, i, j, k, m = 0, n, x, y, z, done = 0, count = 0, flags = 0;
  2677.     int tokeep = 0, getval = 0, havename = 0, confirmed = 0;
  2678.     int xx[MAXKEEP+1];                  /* Array of numbers to keep */
  2679.     int min = -1;
  2680.     int x_hdg = 0, fs = 0, rc = 0;
  2681.     long minsize = -1L, maxsize = -1L;
  2682.     char namebuf[CKMAXPATH+4];
  2683.     char basebuf[CKMAXPATH+4];
  2684.     char
  2685.       * pu_aft = NULL,
  2686.       * pu_bef = NULL,
  2687.       * pu_naf = NULL,
  2688.       * pu_nbf = NULL,
  2689.       * pu_exc = NULL;
  2690.     char * pxlist[8];                   /* Exception list */
  2691.  
  2692.     if (pu_keep > -1)                   /* Set PURGE defaults. */
  2693.       tokeep = pu_keep;
  2694.     if (pu_list > -1)
  2695.       listing = pu_list;
  2696. #ifdef CK_TTGWSIZ
  2697.     if (pu_page > -1)
  2698.       paging = pu_page;
  2699. #endif /* CK_TTGWSIZ */
  2700.  
  2701.     for (i = 0; i <= MAXKEEP; i++)      /* Clear this number buffer */
  2702.       xx[i] = 0;
  2703.     for (i = 0; i < 8; i++)             /* Initialize these... */
  2704.       pxlist[i] = NULL;
  2705.  
  2706.     g_matchdot = matchdot;              /* Save these... */
  2707.  
  2708.     cmfdbi(&sw,                         /* 1st FDB - PURGE switches */
  2709.            _CMKEY,                      /* fcode */
  2710.            "Filename or switch",        /* hlpmsg */
  2711.            "",                          /* default */
  2712.            "",                          /* addtl string data */
  2713.            npurgtab,                    /* addtl numeric data 1: tbl size */
  2714.            4,                           /* addtl numeric data 2: 4 = cmswi */
  2715.            xxstring,                    /* Processing function */
  2716.            purgtab,                     /* Keyword table */
  2717.            &sf                          /* Pointer to next FDB */
  2718.            );
  2719.     cmfdbi(&sf,                         /* 2nd FDB - filespec to purge */
  2720.            _CMIFI,                      /* fcode */
  2721.            "",
  2722.            "",                          /* default */
  2723.            "",                          /* addtl string data */
  2724.            0,                           /* addtl numeric data 1 */
  2725.            0,                           /* addtl numeric data 2 */
  2726.            xxstring,
  2727.            NULL,
  2728.            &cm
  2729.            );
  2730.     cmfdbi(&cm,                         /* Or premature confirmation */
  2731.            _CMCFM,                      /* fcode */
  2732.            "",                          /* hlpmsg */
  2733.            "",                          /* default */
  2734.            "",                          /* addtl string data */
  2735.            0,                           /* addtl numeric data 1 */
  2736.            0,                           /* addtl numeric data 2 */
  2737.            NULL,
  2738.            NULL,
  2739.            NULL
  2740.            );
  2741.  
  2742.     while (!havename && !confirmed) {
  2743.         x = cmfdb(&sw);                 /* Parse something */
  2744.         if (x < 0) {                    /* Error */
  2745.             rc = x;
  2746.             goto xpurge;
  2747.         } else if (cmresult.fcode == _CMKEY) {
  2748.             char c;
  2749.             c = cmgbrk();
  2750.             if ((getval = (c == ':' || c == '=')) && !(cmgkwflgs() & CM_ARG)) {
  2751.                 printf("?This switch does not take an argument\n");
  2752.                 rc = -9;
  2753.                 goto xpurge;
  2754.             }
  2755.             if (!getval && (cmgkwflgs() & CM_ARG)) {
  2756.                 printf("?This switch requires an argument\n");
  2757.                 rc = -9;
  2758.                 goto xpurge;
  2759.             }
  2760.             switch (k = cmresult.nresult) {
  2761.               case PU_KEEP:
  2762.                 z = 1;
  2763.                 if (c == ':' || c == '=') {
  2764.                     if ((y = cmnum("How many backup files to keep",
  2765.                                    "1",10,&z,xxstring)) < 0) {
  2766.                         rc = y;
  2767.                         goto xpurge;
  2768.                     }
  2769.                 }
  2770.                 if (z < 0 || z > MAXKEEP) {
  2771.                     printf("?Please specify a number between 0 and %d\n",
  2772.                            MAXKEEP
  2773.                            );
  2774.                     rc = -9;
  2775.                     goto xpurge;
  2776.                 }
  2777.                 tokeep = z;
  2778.                 break;
  2779.               case PU_LIST:
  2780.                 listing = 1;
  2781.                 break;
  2782.               case PU_NOLI:
  2783.                 listing = 0;
  2784.                 break;
  2785. #ifdef CK_TTGWSIZ
  2786.               case PU_PAGE:
  2787.                 paging = 1;
  2788.                 break;
  2789.               case PU_NOPA:
  2790.                 paging = 0;
  2791.                 break;
  2792. #endif /* CK_TTGWSIZ */
  2793.               case PU_DELE:
  2794.                 deleting = 1;
  2795.                 break;
  2796.               case PU_NODE:
  2797.                 deleting = 0;
  2798.                 simulate = 1;
  2799.                 listing = 1;
  2800.                 break;
  2801.               case PU_ASK:
  2802.                 asking = 1;
  2803.                 break;
  2804.               case PU_NASK:
  2805.                 asking = 0;
  2806.                 break;
  2807.               case PU_AFT:
  2808.               case PU_BEF:
  2809.               case PU_NAF:
  2810.               case PU_NBF:
  2811.                 if ((x = cmdate("File-time","",&s,0,xxstring)) < 0) {
  2812.                     if (x == -3) {
  2813.                         printf("?Date-time required\n");
  2814.                         rc = -9;
  2815.                     } else
  2816.                       rc = x;
  2817.                     goto xpurge;
  2818.                 }
  2819.                 fs++;
  2820.                 switch (k) {
  2821.                   case PU_AFT: makestr(&pu_aft,s); break;
  2822.                   case PU_BEF: makestr(&pu_bef,s); break;
  2823.                   case PU_NAF: makestr(&pu_naf,s); break;
  2824.                   case PU_NBF: makestr(&pu_nbf,s); break;
  2825.                 }
  2826.                 break;
  2827.               case PU_SMA:
  2828.               case PU_LAR:
  2829.                 if ((x = cmnum("File size in bytes","0",10,&y,xxstring)) < 0) {
  2830.                     rc = x;
  2831.                     goto xpurge;
  2832.                 }
  2833.                 fs++;
  2834.                 switch (cmresult.nresult) {
  2835.                   case PU_SMA: minsize = y; break;
  2836.                   case PU_LAR: maxsize = y; break;
  2837.                 }
  2838.                 break;
  2839.               case PU_DOT:
  2840.                 matchdot = 1;
  2841.                 break;
  2842.               case PU_NODOT:
  2843.                 matchdot = 0;
  2844.                 break;
  2845.               case PU_EXC:
  2846.                 if ((x = cmfld("Pattern","",&s,xxstring)) < 0) {
  2847.                     if (x == -3) {
  2848.                         printf("?Pattern required\n");
  2849.                         rc = -9;
  2850.                     } else
  2851.                       rc = x;
  2852.                     goto xpurge;
  2853.                 }
  2854.                 fs++;
  2855.                 makestr(&pu_exc,s);
  2856.                 break;
  2857.               case PU_HDG:
  2858.                 x_hdg = 1;
  2859.                 break;
  2860. #ifdef RECURSIVE
  2861.               case PU_RECU:             /* /RECURSIVE */
  2862.                 recursive = 2;
  2863.                 break;
  2864. #endif /* RECURSIVE */
  2865.               default:
  2866.                 printf("?Not implemented yet - \"%s\"\n",atmbuf);
  2867.                 rc = -9;
  2868.                 goto xpurge;
  2869.             }
  2870.         } else if (cmresult.fcode == _CMIFI) {
  2871.             havename = 1;
  2872.         } else if (cmresult.fcode == _CMCFM) {
  2873.             confirmed = 1;
  2874.         } else {
  2875.             rc = -2;
  2876.             goto xpurge;
  2877.         }
  2878.     }
  2879.     if (havename) {
  2880. #ifdef CKREGEX
  2881.         ckmakmsg(line,LINBUFSIZ,cmresult.sresult,".~[1-9]*~",NULL,NULL);
  2882. #else
  2883.         ckmakmsg(line,LINBUFSIZ,cmresult.sresult,".~*~",NULL,NULL);
  2884. #endif /* CKREGEX */
  2885.     } else {
  2886. #ifdef CKREGEX
  2887.         ckstrncpy(line,"*.~[1-9]*~",LINBUFSIZ);
  2888. #else
  2889.         ckstrncpy(line,"*.~*~",LINBUFSIZ);
  2890. #endif /* CKREGEX */
  2891.     }
  2892.     if (!confirmed) {
  2893.         if ((x = cmcfm()) < 0) {
  2894.             rc = x;
  2895.             goto xpurge;
  2896.         }
  2897.     }
  2898.     /* Parse finished - now action */
  2899.  
  2900. #ifdef CK_LOGIN
  2901.     if (isguest) {
  2902.         printf("?File deletion by guests not permitted.\n");
  2903.         rc = -9;
  2904.         goto xpurge;
  2905.     }
  2906. #endif /* CK_LOGIN */
  2907.  
  2908. #ifdef CK_TTGWSIZ
  2909.     if (paging < 0)                     /* /[NO]PAGE not given */
  2910.       paging = xaskmore;                /* so use prevailing */
  2911. #endif /* CK_TTGWSIZ */
  2912.  
  2913.     lines = 0;
  2914.     if (x_hdg > 0) {
  2915.         printf("Purging %s, keeping %d...%s\n",
  2916.                s,
  2917.                tokeep,
  2918.                simulate ? " (SIMULATION)" : "");
  2919.         lines += 2;
  2920.     }
  2921.     flags = ZX_FILONLY;
  2922.     if (recursive) flags |= ZX_RECURSE;
  2923.     n = nzxpand(line,flags);            /* Get list of backup files */
  2924.     if (tokeep < 1) {                   /* Deleting all of them... */
  2925.         for (i = 0; i < n; i++) {
  2926.             if (fs) if (fileselect(mtchs[i],
  2927.                                    pu_aft,pu_bef,pu_naf,pu_nbf,
  2928.                                    minsize,maxsize,0,8,pxlist) < 1) {
  2929.                 if (listing > 0) {
  2930.                     printf(" %s (SKIPPED)\n",mtchs[i]);
  2931. #ifdef CK_TTGWSIZ
  2932.                     if (paging)
  2933.                       if (++lines > cmd_rows - 3) {
  2934.                           if (!askmore()) goto xpurge; else lines = 0;
  2935.                       }
  2936. #endif /* CK_TTGWSIZ */
  2937.                 }
  2938.                 continue;
  2939.             }
  2940.             if (asking) {
  2941.                 int x;
  2942.                 ckmakmsg(tmpbuf,TMPBUFSIZ," Delete ",mtchs[i],"?",NULL);
  2943.                 x = getyesno(tmpbuf,1);
  2944.                 switch (x) {
  2945.                   case 0: continue;
  2946.                   case 1: break;
  2947.                   case 2: goto xpurge;
  2948.                 }
  2949.             }
  2950.             x = deleting ? zdelet(mtchs[i]) : 0;
  2951.             if (x > -1) {
  2952.                 if (listing)
  2953.                   printf(" %s (%s)\n", mtchs[i],deleting ? "OK" : "SELECTED");
  2954.                 count++;
  2955.             } else {
  2956.                 errors++;
  2957.                 if (listing)
  2958.                   printf(" %s (FAILED)\n", mtchs[i]);
  2959.             }
  2960. #ifdef CK_TTGWSIZ
  2961.             if (listing && paging)
  2962.               if (++lines > cmd_rows - 3) {
  2963.                   if (!askmore()) goto xpurge; else lines = 0;
  2964.               }
  2965. #endif /* CK_TTGWSIZ */
  2966.         }
  2967.         goto xpurge;
  2968.     }
  2969.     if (n < tokeep) {                   /* Not deleting any */
  2970.         count = 0;
  2971.         if (listing)
  2972.           printf(" Matches = %d: Not enough to purge.\n");
  2973.         goto xpurge;
  2974.     }
  2975.  
  2976.     /* General case - delete some but not others */
  2977.  
  2978.     sh_sort(mtchs,NULL,n,0,0,filecase); /* Alphabetize the list (ESSENTIAL) */
  2979.  
  2980.     g = 0;                              /* Start of current group */
  2981.     for (i = 0; i < n; i++) {           /* Go thru sorted file list */
  2982.         x = znext(namebuf);             /* Get next file */
  2983.         if (x < 1 || !namebuf[0] || i == n - 1) /* No more? */
  2984.           done = 1;                     /* NOTE: 'done' must be 0 or 1 only */
  2985.         if (fs) if (fileselect(namebuf,
  2986.                                pu_aft,pu_bef,pu_naf,pu_nbf,
  2987.                                minsize,maxsize,0,8,pxlist) < 1) {
  2988.             if (listing > 0) {
  2989.                 printf(" %s (SKIPPED)\n",namebuf);
  2990.                 if (++lines > cmd_rows - 3)
  2991.                   if (!askmore()) goto xpurge; else lines = 0;
  2992.             }
  2993.             continue;
  2994.         }
  2995.         if (x > 0)
  2996.           if ((m = bkupnum(namebuf,&z)) < 0) /* This file's backup number. */
  2997.             continue;
  2998.         for (j = 0; j < tokeep; j++) {  /* Insert in list. */
  2999.             if (m > xx[j]) {
  3000.                 for (k = tokeep - 1; k > j; k--)
  3001.                   xx[k] = xx[k-1];
  3002.                 xx[j] = m;
  3003.                 break;
  3004.             }
  3005.         }
  3006.         /* New group? */
  3007.         if (done || (i > 0 && ckstrcmp(namebuf,basebuf,z,1))) {
  3008.             if (i + done - g > tokeep) { /* Do we have enough to purge? */
  3009.                 min = xx[tokeep-1];     /* Yes, lowest backup number to keep */
  3010.                 debug(F111,"dopurge group",basebuf,min);
  3011.                 for (j = g; j < i + done; j++) { /* Go through this group */
  3012.                     x = bkupnum(mtchs[j],&z);    /* Get file backup number */
  3013.                     if (x > 0 && x < min) {      /* Below minimum? */
  3014.                         x = deleting ? zdelet(mtchs[j]) : 0;
  3015.                         if (x < 0) errors++;
  3016.                         if (listing)
  3017.                           printf(" %s (%s)\n",
  3018.                                  mtchs[j],
  3019.                                  ((x < 0) ? "ERROR" :
  3020.                                   (deleting ? "DELETED" : "SELECTED"))
  3021.                                  );
  3022.                         count++;
  3023.                     } else if (listing) /* Not below minimum - keep this one */
  3024.                       printf(" %s (KEPT)\n",mtchs[j]);
  3025. #ifdef CK_TTGWSIZ
  3026.                     if (listing && paging)
  3027.                       if (++lines > cmd_rows - 3) {
  3028.                           if (!askmore()) goto xpurge; else lines = 0;
  3029.                       }
  3030. #endif /* CK_TTGWSIZ */
  3031.                 }
  3032.             } else if (listing && paging) { /* Not enough to purge */
  3033.                 printf(" %s.~*~ (KEPT)\n",basebuf);
  3034. #ifdef CK_TTGWSIZ
  3035.                 if (++lines > cmd_rows - 3) {
  3036.                     if (!askmore()) goto xpurge; else lines = 0;
  3037.                 }
  3038. #endif /* CK_TTGWSIZ */
  3039.             }
  3040.             for (j = 0; j < tokeep; j++) /* Clear the backup number list */
  3041.               xx[j] = 0;
  3042.             g = i;                      /* Reset the group pointer */
  3043.         }
  3044.         if (done)                       /* No more files, done. */
  3045.           break;
  3046.         strncpy(basebuf,namebuf,z);     /* Set basename of this file */
  3047.         basebuf[z] = NUL;
  3048.     }
  3049.   xpurge:                               /* Common exit point */
  3050.     if (g_matchdot > -1) {
  3051.         matchdot = g_matchdot;          /* Restore these... */
  3052.         g_matchdot = -1;
  3053.     }
  3054.     if (rc < 0) return(rc);             /* Parse error */
  3055.     if (x_hdg)
  3056.       printf("Files purged: %d%s\n",
  3057.              count,
  3058.              deleting ? "" : " (not really)"
  3059.              );
  3060.     return(success = count > 0 ? 1 : (errors > 0) ? 0 : 1);
  3061. }
  3062. #endif /* CKPURGE */
  3063.  
  3064. #ifndef NOXFER
  3065. #ifndef NOLOCAL
  3066. int
  3067. doxdis(which) int which; {        /* 1 = Kermit, 2 = FTP */
  3068.     extern int nolocal;
  3069.     int x, y = 0, z;
  3070. #ifdef NEWFTP
  3071.     extern int ftp_dis;
  3072. #endif /* NEWFTP */
  3073.  
  3074. #ifdef COMMENT
  3075.     char *s;
  3076. #endif /* COMMENT */
  3077.  
  3078.     if ((x = cmkey(fdtab,nfdtab,"file transfer display style","",
  3079.                    xxstring)) < 0)
  3080.       return(x);
  3081. #ifdef CK_PCT_BAR
  3082.     if ((y = cmkey(fdftab,2,"","thermometer",xxstring)) < 0)
  3083.       return(y);
  3084. #endif /* CK_PCT_BAR */
  3085.     if ((z = cmcfm()) < 0) return(z);
  3086. #ifdef CK_CURSES
  3087.     if (x == XYFD_C) {                  /* FULLSCREEN */
  3088. #ifdef COMMENT
  3089. #ifndef MYCURSES
  3090.         extern char * trmbuf;           /* Real curses */
  3091.         int z;
  3092. #endif /* MYCURSES */
  3093. #endif /* COMMENT */
  3094.  
  3095.         if (nolocal)                    /* Nothing to do in this case */
  3096.       return(success = 1);
  3097.  
  3098. #ifdef COMMENT
  3099. #ifndef MYCURSES
  3100. #ifndef VMS
  3101.         s = getenv("TERM");
  3102.         debug(F110,"doxdis TERM",s,0);
  3103.         if (!s) s = "";
  3104.         fxdinit(x);
  3105.         if (*s && trmbuf) {             /* Don't call tgetent */
  3106.             z = tgetent(trmbuf,s);      /* if trmbuf not allocated */
  3107.             debug(F111,"doxdis tgetent",s,z);
  3108.         } else {
  3109.             z = 0;
  3110.             debug(F110,"doxdis tgetent skipped",s,0);
  3111.         }
  3112.         if (z < 1) {
  3113.             printf("Sorry, terminal type unknown: \"%s\"\n",s);
  3114.             return(success = 0);
  3115.         }
  3116. #endif /* VMS */
  3117. #endif /* MYCURSES */
  3118. #else
  3119.         fxdinit(x);
  3120. #endif /* COMMENT */
  3121.  
  3122. #ifdef CK_PCT_BAR
  3123.         thermometer = y;
  3124. #endif /* CK_PCT_BAR */
  3125.  
  3126.         line[0] = '\0';                 /* (What's this for?) */
  3127.     }
  3128. #endif /* CK_CURSES */
  3129.     if (which == 1)            /* It's OK. */
  3130.       fdispla = x;
  3131. #ifdef NEWFTP
  3132.     else
  3133.       ftp_dis = x;
  3134. #endif /* NEWFTP */
  3135.     return(success = 1);
  3136. }
  3137. #endif /* NOLOCAL */
  3138. #endif /* NOXFER */
  3139.  
  3140. int
  3141. setfil(rmsflg) int rmsflg; {
  3142. #ifdef COMMENT
  3143.     extern int en_del;
  3144. #endif /* COMMENT */
  3145. #ifndef NOXFER
  3146.     if (rmsflg) {
  3147.         if ((y = cmkey(rfiltab,nrfilp,"Remote file parameter","",
  3148.                        xxstring)) < 0) {
  3149.             if (y == -3) {
  3150.                 printf("?Remote file parameter required\n");
  3151.                 return(-9);
  3152.             } else return(y);
  3153.         }
  3154.     } else {
  3155. #endif /* NOXFER */
  3156.         if ((y = cmkey(filtab,nfilp,"File parameter","",xxstring)) < 0)
  3157.           return(y);
  3158. #ifndef NOXFER
  3159.     }
  3160. #endif /* NOXFER */
  3161.     switch (y) {
  3162. #ifdef COMMENT                          /* Not needed */
  3163.       case XYFILB:                      /* Blocksize */
  3164.         if ((y = cmnum("file block size",ckitoa(DBLKSIZ),10,&z,xxstring)) < 0)
  3165.           return(y);
  3166.         if ((x = cmcfm()) < 0) return(x);
  3167.         if (rmsflg) {
  3168.             sstate = setgen('S', "311", ckitoa(z), "");
  3169.             return((int) sstate);
  3170.         } else {
  3171.             fblksiz = z;
  3172.             return(success = 1);
  3173.         }
  3174. #endif /* COMMENT */
  3175.  
  3176. #ifndef NOXFER
  3177.       case XYFILS:                      /* Byte size */
  3178.         if ((y = cmnum("file byte size (7 or 8)","8",10,&z,xxstring)) < 0)
  3179.           return(y);
  3180.         if (z != 7 && z != 8) {
  3181.             printf("\n?The choices are 7 and 8\n");
  3182.             return(0);
  3183.         }
  3184.         if ((y = cmcfm()) < 0) return(y);
  3185.         if (z == 7) fmask = 0177;
  3186.         else if (z == 8) fmask = 0377;
  3187.         return(success = 1);
  3188.  
  3189. #ifndef NOCSETS
  3190.       case XYFILC: {                    /* Character set */
  3191.           char * csetname = NULL;
  3192.           extern int
  3193.             r_cset, s_cset, afcset[];   /* SEND CHARACTER-SET AUTO or MANUAL */
  3194.  
  3195.           struct FDB kw, fl;
  3196.           cmfdbi(&kw,                   /* First FDB - command switches */
  3197.                  _CMKEY,                /* fcode */
  3198.                  rmsflg ? "server character-set name" : "",  /* help */
  3199.                  "",                    /* default */
  3200.                  "",                    /* addtl string data */
  3201.                  nfilc,                 /* addtl numeric data 1: tbl size */
  3202.                  0,                     /* addtl numeric data 2: 0 = keyword */
  3203.                  xxstring,              /* Processing function */
  3204.                  fcstab,                /* Keyword table */
  3205.                  rmsflg ? &fl : NULL    /* Pointer to next FDB */
  3206.            );
  3207.           cmfdbi(&fl,                   /* Anything that doesn't match */
  3208.                  _CMFLD,                /* fcode */
  3209.                  "",                    /* hlpmsg */
  3210.                  "",                    /* default */
  3211.                  "",                    /* addtl string data */
  3212.                  0,                     /* addtl numeric data 1 */
  3213.                  0,                     /* addtl numeric data 2 */
  3214.                  xxstring,
  3215.                  NULL,
  3216.                  NULL
  3217.                  );
  3218.           if ((x = cmfdb(&kw)) < 0)
  3219.             return(x);
  3220.           if (cmresult.fcode == _CMKEY) {
  3221.               x = cmresult.nresult;
  3222.               csetname = fcsinfo[x].keyword;
  3223.           } else {
  3224.               ckstrncpy(line,cmresult.sresult,LINBUFSIZ);
  3225.               csetname = line;
  3226.           }
  3227.           if ((z = cmcfm()) < 0) return(z);
  3228.           if (rmsflg) {
  3229.               sstate = setgen('S', "320", csetname, "");
  3230.               return((int) sstate);
  3231.           }
  3232.           fcharset = x;
  3233.           if (s_cset == XMODE_A)        /* If SEND CHARACTER-SET is AUTO */
  3234.             if (x > -1 && x <= MAXFCSETS)
  3235.               if (afcset[x] > -1 && afcset[x] <= MAXTCSETS)
  3236.                 tcharset = afcset[x]; /* Pick corresponding xfer charset */
  3237.           setxlatype(tcharset,fcharset); /* Translation type */
  3238.           /* If I say SET FILE CHARACTER-SET blah, I want to be blah! */
  3239.           r_cset = XMODE_M;             /* Don't switch incoming set! */
  3240.           x = fcsinfo[fcharset].size;   /* Also set default x-bit charset */
  3241.           if (x == 128)                 /* 7-bit... */
  3242.             dcset7 = fcharset;
  3243.           else if (x == 256)            /* 8-bit... */
  3244.             dcset8 = fcharset;
  3245.           return(success = 1);
  3246.       }
  3247. #endif /* NOCSETS */
  3248.  
  3249. #ifndef NOLOCAL
  3250.       case XYFILD:                      /* Display */
  3251.         return(doxdis(1));        /* 1 == kermit */
  3252. #endif /* NOLOCAL */
  3253. #endif /* NOXFER */
  3254.  
  3255.       case XYFILA:                      /* End-of-line */
  3256. #ifdef NLCHAR
  3257.         s = "";
  3258.         if (NLCHAR == 015)
  3259.           s = "cr";
  3260.         else if (NLCHAR == 012)
  3261.           s = "lf";
  3262.         if ((x = cmkey(eoltab, neoltab,
  3263.                        "local text-file line terminator",s,xxstring)) < 0)
  3264.           return(x);
  3265. #else
  3266.         if ((x = cmkey(eoltab, neoltab,
  3267.                        "local text-file line terminator","crlf",xxstring)) < 0)
  3268.           return(x);
  3269. #endif /* NLCHAR */
  3270.         if ((z = cmcfm()) < 0) return(z);
  3271.         feol = (CHAR) x;
  3272.         return(success = 1);
  3273.  
  3274. #ifndef NOXFER
  3275.       case XYFILN:                      /* Names */
  3276.         if ((x = cmkey(fntab,nfntab,"how to handle filenames","converted",
  3277.                        xxstring)) < 0)
  3278.           return(x);
  3279.         if ((z = cmcfm()) < 0) return(z);
  3280.         if (rmsflg) {
  3281.             sstate = setgen('S', "301", ckitoa(1 - x), "");
  3282.             return((int) sstate);
  3283.         } else {
  3284.             ptab[protocol].fncn = x;    /* Set structure */
  3285.             fncnv = x;                  /* Set variable */
  3286.             f_save = x;                 /* And set "permanent" variable */
  3287.             return(success = 1);
  3288.         }
  3289.  
  3290.       case XYFILR:                      /* Record length */
  3291.         if ((y = cmnum("file record length",
  3292.                        ckitoa(DLRECL),10,&z,xxstring)) < 0)
  3293.           return(y);
  3294.         if ((x = cmcfm()) < 0) return(x);
  3295.         if (rmsflg) {
  3296.             sstate = setgen('S', "312", ckitoa(z), "");
  3297.             return((int) sstate);
  3298.         } else {
  3299.             frecl = z;
  3300.             return(success = 1);
  3301.         }
  3302.  
  3303. #ifdef COMMENT
  3304.       case XYFILO:                      /* Organization */
  3305.         if ((x = cmkey(forgtab,nforg,"file organization","sequential",
  3306.                        xxstring)) < 0)
  3307.           return(x);
  3308.         if ((y = cmcfm()) < 0) return(y);
  3309.         if (rmsflg) {
  3310.             sstate = setgen('S', "314", ckitoa(x), "");
  3311.             return((int) sstate);
  3312.         } else {
  3313.             forg = x;
  3314.             return(success = 1);
  3315.         }
  3316. #endif /* COMMENT */
  3317.  
  3318. #ifdef COMMENT                          /* Not needed */
  3319.       case XYFILF:                      /* Format */
  3320.         if ((x = cmkey(frectab,nfrec,"file record format","stream",
  3321.                        xxstring)) < 0)
  3322.           return(x);
  3323.         if ((y = cmcfm()) < 0) return(y);
  3324.         if (rmsflg) {
  3325.             sstate = setgen('S', "313", ckitoa(x), "");
  3326.             return((int) sstate);
  3327.         } else {
  3328.             frecfm = x;
  3329.             return(success = 1);
  3330.         }
  3331. #endif /* COMMENT */
  3332.  
  3333. #ifdef COMMENT
  3334.       case XYFILP:                      /* Printer carriage control */
  3335.         if ((x = cmkey(fcctab,nfcc,"file carriage control","newline",
  3336.                        xxstring)) < 0)
  3337.           return(x);
  3338.         if ((y = cmcfm()) < 0) return(y);
  3339.         if (rmsflg) {
  3340.             sstate = setgen('S', "315", ckitoa(x), "");
  3341.             return((int) sstate);
  3342.         } else {
  3343.             fcctrl = x;
  3344.             return(success = 1);
  3345.         }
  3346. #endif /* COMMENT */
  3347. #endif /* NOXFER */
  3348.  
  3349.       case XYFILT:                      /* Type */
  3350.         if ((x = cmkey(rmsflg ? rfttab  : fttab,
  3351.                        rmsflg ? nrfttyp : nfttyp,
  3352.                        "type of file transfer","text",xxstring)) < 0)
  3353.           return(x);
  3354.  
  3355. #ifdef VMS
  3356.         /* Allow VMS users to choose record format for binary files */
  3357.         if ((x == XYFT_B) && (rmsflg == 0)) {
  3358.             if ((x = cmkey(fbtab,nfbtyp,"VMS record format","fixed",
  3359.                            xxstring)) < 0)
  3360.               return(x);
  3361.         }
  3362. #endif /* VMS */
  3363.         if ((y = cmcfm()) < 0) return(y);
  3364.         binary = x;
  3365.         b_save = x;
  3366. #ifdef MAC
  3367.         (void) mac_setfildflg(binary);
  3368. #endif /* MAC */
  3369. #ifndef NOXFER
  3370.         if (rmsflg) {
  3371.             /* Allow for LABELED in VMS & OS/2 */
  3372.             sstate = setgen('S', "300", ckitoa(x), "");
  3373.             return((int) sstate);
  3374.         } else {
  3375. #endif /* NOXFER */
  3376.             return(success = 1);
  3377. #ifndef NOXFER
  3378.         }
  3379. #endif /* NOXFER */
  3380.  
  3381. #ifndef NOXFER
  3382.       case XYFILX:                      /* Collision Action */
  3383.         if ((x = cmkey(colxtab,ncolx,"Filename collision action","backup",
  3384.                        xxstring)) < 0)
  3385.           return(x);
  3386.         if ((y = cmcfm()) < 0) return(y);
  3387. #ifdef CK_LOGIN
  3388.         if (isguest) {
  3389.             /* Don't let guests change existing files */
  3390.             printf("?This command not valid for guests\n");
  3391.             return(-9);
  3392.         }
  3393. #endif /* CK_LOGIN */
  3394. #ifdef COMMENT
  3395.         /* Not appropriate - DISABLE DELETE only refers to server */
  3396.         if ((x == XYFX_X || x == XYFX_B || x == XYFX_U || x == XYFX_A) &&
  3397.             (!ENABLED(en_del))) {
  3398.             printf("?Sorry, file deletion is disabled.\n");
  3399.             return(-9);
  3400.         }
  3401. #endif /* COMMENT */
  3402.         fncact = x;
  3403.         ptab[protocol].fnca = x;
  3404.         if (rmsflg) {
  3405.             sstate = setgen('S', "302", ckitoa(fncact), "");
  3406.             return((int) sstate);
  3407.         } else {
  3408.             if (fncact == XYFX_R) ckwarn = 1; /* FILE WARNING implications */
  3409.             if (fncact == XYFX_X) ckwarn = 0; /* ... */
  3410.             return(success = 1);
  3411.         }
  3412.  
  3413.       case XYFILW:                      /* Warning/Write-Protect */
  3414.         if ((x = seton(&ckwarn)) < 0) return(x);
  3415.         if (ckwarn)
  3416.           fncact = XYFX_R;
  3417.         else
  3418.           fncact = XYFX_X;
  3419.         return(success = 1);
  3420.  
  3421. #ifdef CK_LABELED
  3422.       case XYFILL:                      /* LABELED FILE parameters */
  3423.         if ((x = cmkey(lbltab,nlblp,"Labeled file feature","",
  3424.                        xxstring)) < 0)
  3425.           return(x);
  3426.         if ((success = seton(&y)) < 0)
  3427.           return(success);
  3428.         if (y)                          /* Set or reset the selected bit */
  3429.           lf_opts |= x;                 /* in the options bitmask. */
  3430.         else
  3431.           lf_opts &= ~x;
  3432.         return(success);
  3433. #endif /* CK_LABELED */
  3434.  
  3435.       case XYFILI: {                    /* INCOMPLETE */
  3436.           extern struct keytab ifdatab[];
  3437.           extern int keep;
  3438.           if ((y = cmkey(ifdatab,3,"","auto",xxstring)) < 0) return(y);
  3439.           if ((x = cmcfm()) < 0) return(x);
  3440.           if (rmsflg) {
  3441.               sstate = setgen('S',
  3442.                               "310",
  3443.                               y == 0 ? "0" : (y == 1 ? "1" : "2"),
  3444.                               ""
  3445.                               );
  3446.               return((int) sstate);
  3447.           } else {
  3448.               keep = y;
  3449.               return(success = 1);
  3450.           }
  3451.       }
  3452.  
  3453. #ifdef CK_TMPDIR
  3454.       case XYFILG: {                    /* Download directory */
  3455.           int x;
  3456.           char *s;
  3457. #ifdef ZFNQFP
  3458.           struct zfnfp * fnp;
  3459. #endif /* ZFNQFP */
  3460. #ifdef MAC
  3461.           char temp[34];
  3462. #endif /* MAC */
  3463.  
  3464. #ifdef GEMDOS
  3465.           if ((x = cmdir("Name of local directory, or carriage return",
  3466.                          "",&s,
  3467.                          NULL)) < 0 ) {
  3468.               if (x != -3)
  3469.                 return(x);
  3470.           }
  3471. #else
  3472. #ifdef OS2
  3473.           if ((x = cmdir("Name of PC disk and/or directory,\n\
  3474.        or press the Enter key to use current directory",
  3475.                          "",&s,xxstring)) < 0 ) {
  3476.               if (x != -3)
  3477.                 return(x);
  3478.           }
  3479. #else
  3480. #ifdef MAC
  3481.           x = ckstrncpy(temp,zhome(),32);
  3482.           if (x > 0) if (temp[x-1] != ':') { temp[x] = ':'; temp[x+1] = NUL; }
  3483.           if ((x = cmtxt("Name of Macintosh volume and/or folder,\n\
  3484.  or press the Return key for the desktop on the boot disk",
  3485.                          temp,&s, xxstring)) < 0 )
  3486.             return(x);
  3487. #else
  3488.           if ((x = cmdir("Name of local directory, or carriage return",
  3489.                          "", &s, xxstring)) < 0 ) {
  3490.               if (x != -3)
  3491.                 return(x);
  3492.           }
  3493. #endif /* MAC */
  3494. #endif /* OS2 */
  3495. #endif /* GEMDOS */
  3496.           debug(F110,"download dir",s,0);
  3497.  
  3498. #ifndef MAC
  3499.           if (x == 2) {
  3500.               printf("?Wildcards not allowed in directory name\n");
  3501.               return(-9);
  3502.           }
  3503. #endif /* MAC */
  3504.  
  3505. #ifdef ZFNQFP
  3506.           if ((fnp = zfnqfp(s,TMPBUFSIZ - 1,tmpbuf))) {
  3507.               if (fnp->fpath)
  3508.                 if ((int) strlen(fnp->fpath) > 0)
  3509.                   s = fnp->fpath;
  3510.           }
  3511.           debug(F110,"download zfnqfp",s,0);
  3512. #endif /* ZFNQFP */
  3513.  
  3514.           ckstrncpy(line,s,LINBUFSIZ);  /* Make a safe copy */
  3515. #ifndef MAC
  3516.           if ((x = cmcfm()) < 0)        /* Get confirmation */
  3517.             return(x);
  3518. #endif /* MAC */
  3519.  
  3520. #ifdef CK_LOGIN
  3521.         if (isguest) {
  3522.             /* Don't let guests change existing files */
  3523.             printf("?This command not valid for guests\n");
  3524.             return(-9);
  3525.         }
  3526. #endif /* CK_LOGIN */
  3527.           x = strlen(s);
  3528.  
  3529.           if (x) {
  3530. #ifdef datageneral            /* AOS/VS */
  3531.               if (s[x-1] == ':')        /* homdir ends in colon, */
  3532.                 s[x-1] = NUL;           /* and "dir" doesn't like that... */
  3533. #else
  3534. #ifdef OS2ORUNIX            /* Unix or K-95... */
  3535.           if ((x < (LINBUFSIZ - 2)) && /* Add trailing dirsep */
  3536.           (s[x-1] != '/')) {    /* if none present.  */
  3537.           s[x] = '/';        /* Note that Windows path has */
  3538.           s[x+1] = NUL;        /* been canonicalized to forward */
  3539.           }                        /* slashes at this point. */
  3540. #endif /* OS2ORUNIX */
  3541. #endif /* datageneral */
  3542.               makestr(&dldir,s);
  3543.           } else
  3544.             makestr(&dldir,NULL);       /* dldir is NULL when not assigned */
  3545.  
  3546.           return(success = 1);
  3547.       }
  3548. #endif /* CK_TMPDIR */
  3549.       case XYFILY:
  3550.         return(setdest());
  3551. #endif /* NOXFER */
  3552.  
  3553. #ifdef CK_CTRLZ
  3554.       case XYFILV: {                    /* EOF */
  3555.           extern int eofmethod;
  3556.           if ((x = cmkey(eoftab,3,"end-of-file detection method","",
  3557.                          xxstring)) < 0)
  3558.             return(x);
  3559.           if ((y = cmcfm()) < 0)
  3560.             return(y);
  3561.           eofmethod = x;
  3562.           return(success = 1);
  3563.       }
  3564. #endif /* CK_CTRLZ */
  3565.  
  3566. #ifndef NOXFER
  3567. #ifdef UNIX
  3568.       case XYFILH: {                    /* OUTPUT */
  3569.           extern int zofbuffer, zobufsize, zofblock;
  3570. #ifdef DYNAMIC
  3571.           extern char * zoutbuffer;
  3572. #endif /* DYNAMIC */
  3573.  
  3574.           if ((x = cmkey(zoftab,nzoftab,"output file writing method","",
  3575.                          xxstring)) < 0)
  3576.             return(x);
  3577.           if (x == ZOF_BUF || x == ZOF_NBUF) {
  3578.               if ((y = cmnum("output buffer size","32768",10,&z,xxstring)) < 0)
  3579.                 return(y);
  3580.               if (z < 1) {
  3581.                   printf("?Bad size - %d\n", z);
  3582.                   return(-9);
  3583.               }
  3584.           }
  3585.           if ((y = cmcfm()) < 0) return(y);
  3586.           switch (x) {
  3587.             case ZOF_BUF:
  3588.             case ZOF_NBUF:
  3589.               zofbuffer = (x == ZOF_BUF);
  3590.               zobufsize = z;
  3591.               break;
  3592.             case ZOF_BLK:
  3593.             case ZOF_NBLK:
  3594.               zofblock = (x == ZOF_BLK);
  3595.               break;
  3596.           }
  3597. #ifdef DYNAMIC
  3598.           if (zoutbuffer) free(zoutbuffer);
  3599.           if (!(zoutbuffer = (char *)malloc(z))) {
  3600.               printf("MEMORY ALLOCATION ERROR - FATAL\n");
  3601.               doexit(BAD_EXIT,-1);
  3602.           } else
  3603.             zobufsize = z;
  3604. #else
  3605.           if (z <= OBUFSIZE) {
  3606.               zobufsize = z;
  3607.           } else {
  3608.               printf("?Sorry, %d is too big - %d is the maximum\n",z,OBUFSIZE);
  3609.               return(-9);
  3610.           }
  3611. #endif /* DYNAMIC */
  3612.           return(success = 1);
  3613.       }
  3614. #endif /* UNIX */
  3615.  
  3616. #ifdef PATTERNS
  3617.       case XYFIBP:                      /* BINARY-PATTERN */
  3618.       case XYFITP: {                    /* TEXT-PATTERN */
  3619.           char * tmp[FTPATTERNS];
  3620.           int i, n = 0;
  3621.           while (n < FTPATTERNS) {
  3622.               tmp[n] = NULL;
  3623.               if ((x = cmfld("Pattern","",&s,xxstring)) < 0)
  3624.                 break;
  3625.               ckstrncpy(line,s,LINBUFSIZ);
  3626.               s = brstrip(line);
  3627.               makestr(&(tmp[n++]),s);
  3628.           }
  3629.           if (x == -3) x = cmcfm();
  3630.           for (i = 0; i <= n; i++) {
  3631.               if (x > -1) {
  3632.                   if (y == XYFIBP)
  3633.                     makestr(&(binpatterns[i]),tmp[i]);
  3634.                   else
  3635.                     makestr(&(txtpatterns[i]),tmp[i]);
  3636.               }
  3637.               free(tmp[i]);
  3638.           }
  3639.           if (y == XYFIBP)              /* Null-terminate the list */
  3640.             makestr(&(binpatterns[i]),NULL);
  3641.           else
  3642.             makestr(&(txtpatterns[i]),NULL);
  3643.           return(x);
  3644.       }
  3645.  
  3646.       case XYFIPA:                      /* PATTERNS */
  3647.         if ((x = setonaut(&patterns)) < 0)
  3648.           return(x);
  3649.         return(success = 1);
  3650. #endif /* PATTERNS */
  3651. #endif /* NOXFER */
  3652.  
  3653. #ifdef UNICODE
  3654.       case XYFILU: {                    /* UCS */
  3655.           extern int ucsorder, ucsbom, byteorder;
  3656.           if ((x = cmkey(ucstab,nucstab,"","",xxstring)) < 0)
  3657.             return(x);
  3658.           switch (x) {
  3659.             case UCS_BYT:
  3660.               if ((y = cmkey(botab,nbotab,
  3661.                              "Byte order",
  3662.                              byteorder ? "little-endian" : "big-endian",
  3663.                              xxstring
  3664.                              )
  3665.                    ) < 0)
  3666.                 return(y);
  3667.               if ((x = cmcfm()) < 0)
  3668.                 return(x);
  3669.               ucsorder = y;
  3670.               return(success = 1);
  3671.             case UCS_BOM:
  3672.               if ((y = cmkey(onoff,2,"","on",xxstring)) < 0)
  3673.                 return(y);
  3674.               if ((x = cmcfm()) < 0)
  3675.                 return(x);
  3676.               ucsbom = y;
  3677.               return(success = 1);
  3678.             default:
  3679.               return(-2);
  3680.           }
  3681.       }
  3682. #endif /* UNICODE */
  3683.  
  3684. #ifndef datageneral
  3685.       case XYF_INSP: {                  /* SCAN (INSPECTION) */
  3686.           extern int filepeek, nscanfile;
  3687.           if ((x = cmkey(onoff,2,"","on",xxstring)) < 0)
  3688.             return(x);
  3689.           if (y) {
  3690.               if ((y = cmnum("How much to scan",ckitoa(SCANFILEBUF),
  3691.                              10,&z,xxstring)) < 0)
  3692.                 return(y);
  3693.           }
  3694.           if ((y = cmcfm()) < 0)
  3695.             return(y);
  3696. #ifdef VMS
  3697.           filepeek = 0;
  3698.           nscanfile = 0;
  3699.           return(success = 0);
  3700. #else
  3701.           filepeek = x;
  3702.           nscanfile = z;
  3703.           return(success = 1);
  3704. #endif /* VMS */
  3705.       }
  3706. #endif /* datageneral */
  3707.  
  3708.       case XYF_DFLT:
  3709.         y = 0;
  3710. #ifndef NOCSETS
  3711.         if ((y = cmkey(fdfltab,nfdflt,"","",xxstring)) < 0)
  3712.           return(y);
  3713.         if (y == 7 || y == 8) {
  3714.             if (y == 7)
  3715.               s = fcsinfo[dcset7].keyword;
  3716.             else
  3717.               s = fcsinfo[dcset8].keyword;
  3718.             if ((x = cmkey(fcstab,nfilc,"character-set",s,xxstring)) < 0)
  3719.               return(x);
  3720.         }
  3721.         ckstrncpy(line,fcsinfo[x].keyword,LINBUFSIZ);
  3722.         s = line;
  3723. #endif /* NOCSETS */
  3724.         if ((z = cmcfm()) < 0)
  3725.           return(z);
  3726.         switch (y) {
  3727. #ifndef NOCSETS
  3728.           case 7:
  3729.             if (fcsinfo[x].size != 128) {
  3730.                 printf("%s - Not a 7-bit set\n",s);
  3731.                 return(-9);
  3732.             }
  3733.             dcset7 = x;
  3734.             break;
  3735.           case 8:
  3736.             if (fcsinfo[x].size != 256) {
  3737.                 printf("%s - Not an 8-bit set\n",s);
  3738.                 return(-9);
  3739.             }
  3740.             dcset8 = x;
  3741.             break;
  3742. #endif /* NOCSETS */
  3743.           default:
  3744.             return(-2);
  3745.         }
  3746.         return(success = 1);
  3747.  
  3748. #ifndef NOXFER
  3749.       case 9997:                        /* FASTLOOKUPS */
  3750.         return(success = seton(&stathack));
  3751. #endif /* NOXFER */
  3752.  
  3753. #ifdef UNIX
  3754. #ifdef DYNAMIC
  3755.       case XYF_LSIZ: {                  /* LISTSIZE */
  3756.           int zz;
  3757.           y = cmnum("Maximum number of filenames","",10,&x,xxstring);
  3758.           if ((x = setnum(&zz,x,y,-1)) < 0)
  3759.             return(x);
  3760.           if (zsetfil(zz,3) < 0) {
  3761.               printf("?Memory allocation failure\n");
  3762.               return(-9);
  3763.           }
  3764.           return(success = 1);
  3765.       }
  3766.       case XYF_SSPA: {                  /* STRINGSPACE */
  3767.           int zz;
  3768.           y = cmnum("Number of characters for filename list",
  3769.                     "",10,&x,xxstring);
  3770.           if ((x = setnum(&zz,x,y,-1)) < 0)
  3771.             return(x);
  3772.           if (zsetfil(zz,1) < 0) {
  3773.               printf("?Memory allocation failure\n");
  3774.               return(-9);
  3775.           }
  3776.           return(success = 1);
  3777.       }
  3778.  
  3779. #endif /* DYNAMIC */
  3780. #endif /* UNIX */
  3781.  
  3782.       default:
  3783.         printf("?unexpected file parameter\n");
  3784.         return(-2);
  3785.     }
  3786. }
  3787.  
  3788. #ifndef NOLOCAL
  3789. #ifdef OS2
  3790. /* MS-DOS KERMIT compatibility modes */
  3791. int
  3792. setmsk() {
  3793.     if ((y = cmkey(msktab,nmsk,"MS-DOS Kermit compatibility mode",
  3794.                     "keycodes",xxstring)) < 0) return(y);
  3795.  
  3796.     switch ( y ) {
  3797. #ifdef COMMENT
  3798.       case MSK_COLOR:
  3799.         return(seton(&mskcolors));
  3800. #endif /* COMMENT */
  3801.       case MSK_KEYS:
  3802.         return(seton(&mskkeys));
  3803.       default:                          /* Shouldn't get here. */
  3804.         return(-2);
  3805.     }
  3806. }
  3807. #endif /* OS2 */
  3808.  
  3809. int
  3810. settrmtyp() {
  3811. #ifdef OS2
  3812. #ifdef TNCODE
  3813.     extern int ttnum;                    /* Last Telnet Terminal Type sent */
  3814.     extern int ttnumend;                 /* Has end of list been found */
  3815. #endif /* TNCODE */
  3816.     if ((x = cmkey(ttyptab,nttyp,"","vt320",xxstring)) < 0)
  3817.       return(x);
  3818.     if ((y = cmcfm()) < 0)
  3819.       return(y);
  3820.     settermtype(x,1);
  3821. #ifdef TNCODE
  3822.     /* So we send the correct terminal name to the host if it asks for it */
  3823.     ttnum = -1;                         /* Last Telnet Terminal Type sent */
  3824.     ttnumend = 0;                       /* end of list not found */
  3825. #endif /* TNCODE */
  3826.     return(success = 1);
  3827. #else  /* Not OS2 */
  3828.     printf(
  3829. "\n Sorry, this version of C-Kermit does not support the SET TERMINAL TYPE\n");
  3830.     printf(
  3831. " command.  Type \"help set terminal\" for further information.\n");
  3832. #endif /* OS2 */
  3833.     return(success = 0);
  3834. }
  3835.  
  3836. #ifdef CKTIDLE
  3837. static char iactbuf[132];
  3838.  
  3839. char *
  3840. getiact() {
  3841.     switch (tt_idleact) {
  3842.       case IDLE_RET:  return("return");
  3843.       case IDLE_EXIT: return("exit");
  3844.       case IDLE_HANG: return("hangup");
  3845. #ifdef TNCODE
  3846.       case IDLE_TNOP: return("Telnet NOP");
  3847.       case IDLE_TAYT: return("Telnet AYT");
  3848. #endif /* TNCODE */
  3849.  
  3850.       case IDLE_OUT: {
  3851.           int c, k, n;
  3852.           char * p, * q, * t;
  3853.           k = ckstrncpy(iactbuf,"output ",132);
  3854.           n = k;
  3855.           q = &iactbuf[k];
  3856.           p = tt_idlestr;
  3857.           if (!p) p = "";
  3858.           if (!*p) return("output (nothing)");
  3859.           while ((c = *p++) && n < 131) {
  3860.               c &= 0xff;
  3861.               if (c == '\\') {
  3862.                   if (n > 130) break;
  3863.                   *q++ = '\\';
  3864.                   *q++ = '\\';
  3865.                   *q = NUL;
  3866.                   n += 2;
  3867.               } else if ((c > 31 && c < 127) || c > 159) {
  3868.                   *q++ = c;
  3869.                   *q = NUL;
  3870.                   n++;
  3871.               } else {
  3872.                   if (n > (131 - 6))
  3873.                     break;
  3874.                   sprintf(q,"\\{%d}",c);
  3875.                   k = strlen(q);
  3876.                   q += k;
  3877.                   n += k;
  3878.                   *q = NUL;
  3879.               }
  3880.           }
  3881.           *q = NUL;
  3882. #ifdef OS2
  3883.           k = tt_cols[VTERM];
  3884. #else
  3885.           k = tt_cols;
  3886. #endif /* OS2 */
  3887.           if (n > k - 52) {
  3888.               n = k - 52;
  3889.               iactbuf[n-2] = '.';
  3890.               iactbuf[n-1] = '.';
  3891.               iactbuf[n] = NUL;
  3892.           }
  3893.           return(iactbuf);
  3894.       }
  3895.       default: return("unknown");
  3896.     }
  3897. }
  3898. #endif /* CKTIDLE */
  3899.  
  3900. #ifndef NOCSETS
  3901. VOID
  3902. setlclcharset(x) int x; {
  3903.     int i;
  3904.     tcsl = y;                   /* Local character set */
  3905. #ifdef OS2
  3906.     for (i = 0; i < 4; i++) {
  3907.         G[i].init = TRUE;
  3908.         x = G[i].designation;
  3909.         G[i].c1 = (x != tcsl) && cs_is_std(x);
  3910.         x = G[i].def_designation;
  3911.         G[i].def_c1 = (x != tcsl) && cs_is_std(x);
  3912.     }
  3913. #endif /* OS2 */
  3914. }
  3915.  
  3916. VOID
  3917. setremcharset(x, z) int x, z; {
  3918.     int i;
  3919.  
  3920. #ifdef KUI
  3921.     KuiSetProperty( KUI_TERM_REMCHARSET, (long) x, (long) z ) ;
  3922. #endif /* KUI */
  3923. #ifdef UNICODE
  3924.     if (x == TX_TRANSP)
  3925. #else /* UNICODE */
  3926.     if (x == FC_TRANSP)
  3927. #endif /* UNICODE */
  3928.     {                           /* TRANSPARENT? */
  3929. #ifndef OS2
  3930.         tcsr = tcsl;            /* Make both sets the same */
  3931. #else /* OS2 */
  3932. #ifdef CKOUNI
  3933.         tt_utf8 = 0;            /* Turn off UTF8 flag */
  3934.         tcsr = tcsl = dec_kbd = TX_TRANSP; /* No translation */
  3935.         tcs_transp = 1;
  3936.  
  3937.         if (!cs_is_nrc(tcsl)) {
  3938.             G[0].def_designation = G[0].designation = TX_ASCII;
  3939.             G[0].init = TRUE;
  3940.             G[0].def_c1 = G[0].c1 = FALSE;
  3941.             G[0].size = cs94;
  3942.             G[0].national = FALSE;
  3943.         }
  3944.         for (i = cs_is_nrc(tcsl) ? 0 : 1; i < 4; i++) {
  3945.             G[i].def_designation = G[i].designation = tcsl;
  3946.             G[i].init = TRUE;
  3947.             G[i].def_c1 = G[i].c1 = FALSE;
  3948.             switch (cs_size(G[i].designation)) { /* 94, 96, or 128 */
  3949.             case 128:
  3950.             case 96:
  3951.                 G[i].size = G[i].def_size = cs96;
  3952.                 break;
  3953.             case 94:
  3954.                 G[i].size = G[i].def_size = cs94;
  3955.                 break;
  3956.             default:
  3957.                 G[i].size = G[i].def_size = csmb;
  3958.                 break;
  3959.             }
  3960.             G[i].national = cs_is_nrc(x);
  3961.         }
  3962. #else /* CKOUNI */
  3963.         tcsr = tcsl;            /* Make both sets the same */
  3964.         for (i = 0; i < 4; i++) {
  3965.             G[i].def_designation = G[i].designation = FC_TRANSP;
  3966.             G[i].init = FALSE;
  3967.             G[i].size = G[i].def_size = cs96;
  3968.             G[i].c1 = G[i].def_c1 = FALSE;
  3969.             G[i].rtoi = NULL;
  3970.             G[i].itol = NULL;
  3971.             G[i].ltoi = NULL;
  3972.             G[i].itor = NULL;
  3973.             G[i].national = FALSE;
  3974.         }
  3975. #endif /* CKOUNI */
  3976. #endif /* OS2 */
  3977.         return;
  3978.     }
  3979. #ifdef OS2
  3980. #ifdef CKOUNI
  3981.     else if (x == TX_UTF8) {
  3982.         tcs_transp = 0;
  3983.         tt_utf8 = 1;            /* Turn it on if we are UTF8 */
  3984.         return;
  3985.     }
  3986. #endif /* CKOUNI */
  3987.     else {
  3988.         tcs_transp = 0;
  3989.         tcsr = x;                       /* Remote character set */
  3990. #ifdef CKOUNI
  3991.         tt_utf8 = 0;                    /* Turn off UTF8 flag */
  3992. #endif /* CKOUNI */
  3993.  
  3994.         if (z == TT_GR_ALL) {
  3995.             int i;
  3996. #ifdef UNICODE
  3997.             dec_kbd = x;
  3998. #endif /* UNICODE */
  3999.             for (i = 0; i < 4; i++) {
  4000.                 G[i].init = TRUE;
  4001.                 if ( i == 0 && !cs_is_nrc(x) ) {
  4002.                     G[0].designation = G[0].def_designation = FC_USASCII;
  4003.                     G[0].size = G[0].def_size = cs94;
  4004.                     G[0].national = 1;
  4005.                 } else {
  4006.                     G[i].def_designation = G[i].designation = x;
  4007.                     switch (cs_size(x)) {       /* 94, 96, or 128 */
  4008.                     case 128:
  4009.                     case 96:
  4010.                         G[i].size = G[i].def_size = cs96;
  4011.                         break;
  4012.                     case 94:
  4013.                         G[i].size = G[i].def_size = cs94;
  4014.                         break;
  4015.                     default:
  4016.                         G[i].size = G[i].def_size = csmb;
  4017.                         break;
  4018.                     }
  4019.                     G[i].national = cs_is_nrc(x);
  4020.                 }
  4021.                 G[i].c1 = G[i].def_c1 = x != tcsl && cs_is_std(x);
  4022.             }
  4023. #ifdef UNICODE
  4024.         } else if (z == TT_GR_KBD) {    /* Keyboard only */
  4025.             dec_kbd = x;
  4026. #endif /* UNICODE */
  4027.         } else {                        /* Specific Gn */
  4028.             G[z].def_designation = G[z].designation = x;
  4029.             G[z].init = TRUE;
  4030.             switch (cs_size(x)) {       /* 94, 96, or 128 */
  4031.             case 128:
  4032.             case 96:
  4033.                 G[z].size = G[z].def_size = cs96;
  4034.                 break;
  4035.             case 94:
  4036.                 G[z].size = G[z].def_size = cs94;
  4037.                 break;
  4038.             default:
  4039.                 G[z].size = G[z].def_size = csmb;
  4040.                 break;
  4041.             }
  4042.             G[z].c1 = G[z].def_c1 = x != tcsl && cs_is_std(x);
  4043.             G[z].national = cs_is_nrc(x);
  4044.         }
  4045.     }
  4046. #else /* not OS2 */
  4047.     tcsr = x;                   /* Remote character set */
  4048. #endif /* OS2 */
  4049. }
  4050. #endif /* NOCSETS */
  4051.  
  4052. VOID
  4053. setcmask(x) int x; {
  4054.     if (x == 7) {
  4055.         cmask = 0177;
  4056.     } else if (x == 8) {
  4057.         cmask = 0377;
  4058.         parity = 0;
  4059.     }
  4060. #ifdef KUI      
  4061.     KuiSetProperty(KUI_TERM_CMASK,x,0);
  4062. #endif /* KUI */
  4063. }
  4064.  
  4065. #ifdef CK_AUTODL
  4066. VOID
  4067. setautodl(x,y) int x,y; {
  4068.     autodl = x;
  4069.     adl_ask = y;
  4070. #ifdef KUI      
  4071.     KuiSetProperty(KUI_TERM_AUTODOWNLOAD,x?(y?2:1):0,0);
  4072. #endif /* KUI */
  4073. }
  4074. #endif /* CK_AUTODL */
  4075.  
  4076. #ifdef OS2
  4077. VOID
  4078. seturlhl(int x) {
  4079.     tt_url_hilite = x;
  4080. #ifdef KUI      
  4081.     KuiSetProperty(KUI_TERM_URL_HIGHLIGHT,x,0);
  4082. #endif /* KUI */
  4083. }
  4084.  
  4085. VOID
  4086. setaprint(int x) {
  4087.     extern int aprint;
  4088.     aprint = x;
  4089. #ifdef KUI
  4090.     KuiSetProperty(KUI_TERM_PRINTERCOPY,x,0);
  4091. #endif /* KUI */
  4092. }
  4093. #endif /* OS2 */
  4094.  
  4095. int
  4096. settrm() {
  4097.     int i = 0;
  4098. #ifdef OS2
  4099.     extern int colorreset, user_erasemode;
  4100. #endif /* OS2 */
  4101.     if ((y = cmkey(trmtab,ntrm,"", "",xxstring)) < 0) return(y);
  4102. #ifdef MAC
  4103.     printf("\n?Sorry, not implemented yet.  Please use the Settings menu.\n");
  4104.     return(-9);
  4105. #else
  4106. #ifdef IKSD
  4107.     if (inserver) {
  4108.         if ((y = cmcfm()) < 0) return(y);
  4109.         printf("?Sorry, command disabled.\r\n");
  4110.         return(success = 0);
  4111.     }
  4112. #endif /* IKSD */
  4113.  
  4114.     switch (y) {
  4115.       case XYTBYT:                      /* SET TERMINAL BYTESIZE */
  4116.         if ((y = cmnum("bytesize for terminal connection","8",10,&x,
  4117.                        xxstring)) < 0)
  4118.           return(y);
  4119.         if (x != 7 && x != 8) {
  4120.             printf("\n?The choices are 7 and 8\n");
  4121.             return(success = 0);
  4122.         }
  4123.         if ((y = cmcfm()) < 0) return(y);
  4124.         setcmask(x);
  4125. #ifdef OS2
  4126.         if (IS97801(tt_type_mode))
  4127.           SNI_bitmode(x);
  4128. #endif /* OS2 */
  4129.         return(success = 1);
  4130.  
  4131.       case XYTSO:                       /* SET TERMINAL LOCKING-SHIFT */
  4132.         return(seton(&sosi));
  4133.  
  4134.       case XYTNL:                       /* SET TERMINAL NEWLINE-MODE */
  4135.         return(seton(&tnlm));
  4136.  
  4137. #ifdef OS2
  4138.       case XYTCOL:
  4139.         if ((x = cmkey(ttycoltab,ncolors,"","terminal",xxstring)) < 0)
  4140.           return(x);
  4141.         else if (x == TTCOLRES) {
  4142.             if ((y = cmkey(ttcolmodetab,ncolmode,
  4143.                            "","default-color",xxstring)) < 0)
  4144.               return(y);
  4145.             if ((z = cmcfm()) < 0)
  4146.               return(z);
  4147.             colorreset = y;
  4148.             return(success = 1);
  4149.         } else if (x == TTCOLERA) {
  4150.             if ((y = cmkey(ttcolmodetab,ncolmode,"",
  4151.                            "current-color",xxstring)) < 0)
  4152.               return(y);
  4153.             if ((z = cmcfm()) < 0)
  4154.               return(z);
  4155.             user_erasemode = y;
  4156.             return(success=1);
  4157.         } else {                        /* No parse error */
  4158.             int fg = 0, bg = 0;
  4159.             fg = cmkey(ttyclrtab, nclrs,
  4160.                        (x == TTCOLBOR ?
  4161.                         "color for screen border" :
  4162.                         "foreground color and then background color"),
  4163.                        "lgray", xxstring);
  4164.             if (fg < 0)
  4165.               return(fg);
  4166.             if (x != TTCOLBOR) {
  4167.                 if ((bg = cmkey(ttyclrtab,nclrs,
  4168.                                 "background color","blue",xxstring)) < 0)
  4169.                   return(bg);
  4170.             }
  4171.             if ((y = cmcfm()) < 0)
  4172.               return(y);
  4173.             switch (x) {
  4174.               case TTCOLNOR:
  4175.                 colornormal = fg | bg << 4;
  4176.                 fgi = fg & 0x08;
  4177.                 bgi = bg & 0x08;
  4178.                 break;
  4179.               case TTCOLREV:
  4180.                 colorreverse = fg | bg << 4;
  4181.                 break;
  4182.               case TTCOLITA:
  4183.                 coloritalic = fg | bg << 4;
  4184.                 break;
  4185.               case TTCOLUND:
  4186.                 colorunderline = fg | bg << 4;
  4187.                 break;
  4188.               case TTCOLGRP:
  4189.                 colorgraphic = fg | bg << 4;
  4190.                 break;
  4191.               case TTCOLDEB:
  4192.                 colordebug = fg | bg << 4;
  4193.                 break;
  4194.               case TTCOLSTA:
  4195.                 colorstatus = fg | bg << 4;
  4196.                 break;
  4197.               case TTCOLHLP:
  4198.                 colorhelp = fg | bg << 4;
  4199.                 break;
  4200.               case TTCOLBOR:
  4201.                 colorborder = fg;
  4202.                 break;
  4203.               case TTCOLSEL:
  4204.                 colorselect = fg | bg << 4;
  4205.                 break;
  4206.               default:
  4207.                 printf("%s - invalid\n",cmdbuf);
  4208.                 return(-9);
  4209.                 break;
  4210.             }
  4211.             scrninitialized[VTERM] = 0;
  4212.             VscrnInit(VTERM);
  4213.         }
  4214.         return(success = 1);
  4215.  
  4216.       case XYTCUR: {                    /* SET TERMINAL CURSOR */
  4217.           extern int cursorena[];
  4218.           extern int cursoron[] ;       /* Cursor state on/off       */
  4219.           if ((x = cmkey(ttycurtab,ncursors,"","underline",xxstring)) < 0)
  4220.             return(x);
  4221.           if ((z = cmkey(curontab,ncuron,"","on",xxstring)) < 0)
  4222.             return(z);
  4223.           if ((y = cmcfm()) < 0) return(y);
  4224.           tt_cursor = tt_cursor_usr = x;
  4225.           if ( z == 2 ) {
  4226.               cursorena[VTERM] = tt_cursorena_usr = 1;
  4227.               tt_cursor_blink = 0;
  4228.           } else {
  4229.               cursorena[VTERM] = tt_cursorena_usr = z;/* turn cursor on/off */
  4230.               tt_cursor_blink = 1;
  4231.           }
  4232.           cursoron[VTERM] = FALSE; /* Force newcursor to restore the cursor */
  4233.           return(success = 1);
  4234.       }
  4235. #endif /* OS2 */
  4236.  
  4237.       case XYTTYP:                      /* SET TERMINAL TYPE */
  4238.         return(settrmtyp());
  4239.  
  4240. #ifdef OS2
  4241.       case XYTARR:                      /* SET TERMINAL ARROW-KEYS */
  4242.         if ((x = cmkey(akmtab,2,"","",xxstring)) < 0) return(x);
  4243.         if ((y = cmcfm()) < 0) return(y);
  4244.         tt_arrow = x;                   /* TTK_NORM / TTK_APPL; see ckuusr.h */
  4245.         return(success = 1);
  4246.  
  4247.       case XYTKPD:                      /* SET TERMINAL KEYPAD-MODE */
  4248.         if ((x = cmkey(kpmtab,2,"","",xxstring)) < 0) return(x);
  4249.         if ((y = cmcfm()) < 0) return(y);
  4250.         tt_keypad = x;                  /* TTK_NORM / TTK_APPL; see ckuusr.h */
  4251.         return(success = 1);
  4252.  
  4253.       case XYTUNX: {                    /* SET TERM UNIX-MODE (DG) */
  4254.         extern int dgunix,dgunix_usr;
  4255.         x = seton(&dgunix);
  4256.         dgunix_usr = dgunix;
  4257.         return(x);
  4258.       }
  4259.       case XYTKBMOD: {                  /* SET TERM KEYBOARD MODE */
  4260.           extern int tt_kb_mode;
  4261.           if ((x = cmkey(kbmodtab,
  4262.                          nkbmodtab,
  4263.                          "normal",
  4264.                          "special keyboard mode for terminal emulation",
  4265.                          xxstring)
  4266.                ) < 0)
  4267.             return(x);
  4268.           if ((y = cmcfm()) < 0) return(y);
  4269.           tt_kb_mode = x;
  4270.           return(success = 1);
  4271.       }
  4272.  
  4273.       case XYTWRP:                      /* SET TERMINAL WRAP */
  4274.         return(seton(&tt_wrap));
  4275.  
  4276.       case XYSCRS:
  4277.         if ((y = cmnum("CONNECT scrollback buffer size, lines","2000",10,&x,
  4278.                        xxstring)) < 0)
  4279.           return(y);
  4280.         /* The max number of lines is the RAM  */
  4281.         /* we can actually dedicate to a       */
  4282.         /* scrollback buffer given the maximum */
  4283.         /* process memory space of 512MB       */
  4284.         if (x < 256 || x > 2000000L) {
  4285.             printf("\n?The size must be between 256 and 2,000,000.\n");
  4286.             return(success = 0);
  4287.         }
  4288.         if ((y = cmcfm()) < 0) return(y);
  4289.         tt_scrsize[VTERM] = x;
  4290.         VscrnInit(VTERM);
  4291.         return(success = 1);
  4292. #endif /* OS2 */
  4293.  
  4294. #ifndef NOCSETS
  4295.       case XYTCS: {                     /* SET TERMINAL CHARACTER-SET */
  4296.         int eol;
  4297.           /* set terminal character-set <remote> <local> */
  4298.         if ((x = cmkey(
  4299. #ifdef CKOUNI
  4300.                        txrtab,ntxrtab,
  4301. #else  /* CKOUNI */
  4302.                        ttcstab,ntermc,
  4303. #endif /* CKOUNI */
  4304.                        "remote terminal character-set","",xxstring)) < 0)
  4305.           return(x);
  4306.  
  4307. #ifdef UNICODE
  4308.         if (x == TX_TRANSP
  4309. #ifdef CKOUNI
  4310.             || x == TX_UTF8
  4311. #endif /* CKOUNI */
  4312.            ) {
  4313.               if ((y = cmcfm()) < 0)    /* Confirm the command */
  4314.                   return(y);
  4315. #ifdef OS2
  4316.             if ( isunicode() && x == TX_TRANSP ) {
  4317.                 /* If we are in unicode display mode then transparent
  4318.                  * only affects the output direction.  We need to know
  4319.                  * the actual remote character set in order to perform
  4320.                  * the tcsr -> ucs2 translation for display.
  4321.                  */
  4322.                 x = y = tcsl;
  4323.             } else
  4324. #endif /* OS2 */
  4325.                 y = x;
  4326.         }
  4327. #else /* UNICODE */
  4328.         if (x == FC_TRANSP) {
  4329.             if ((y = cmcfm()) < 0)      /* Confirm the command */
  4330.                 return(y);
  4331.             y = x;
  4332.         }
  4333. #endif /* UNICODE */
  4334.  
  4335.         /* Not transparent or UTF8, so get local set to translate it into */
  4336.         s = "";
  4337. #ifdef OS2
  4338.         y = os2getcp();                 /* Default is current code page */
  4339.         switch (y) {
  4340.           case 437: s = "cp437"; break;
  4341.           case 850: s = "cp850"; break;
  4342.           case 852: s = "cp852"; break;
  4343.           case 857: s = "cp857"; break;
  4344.           case 858: s = "cp858"; break;
  4345.           case 862: s = "cp862"; break;
  4346.           case 866: s = "cp866"; break;
  4347.           case 869: s = "cp869"; break;
  4348.           case 1250: s = "cp1250"; break;
  4349.           case 1251: s = "cp1251"; break;
  4350.           case 1252: s = "cp1252"; break;
  4351.           case 1253: s = "cp1253"; break;
  4352.           case 1254: s = "cp1254"; break;
  4353.           case 1255: s = "cp1255"; break;
  4354.           case 1256: s = "cp1256"; break;
  4355.           case 1257: s = "cp1257"; break;
  4356.           case 1258: s = "cp1258"; break;
  4357.         }
  4358. #ifdef PCFONTS
  4359. /*
  4360.    If the user has loaded a font with SET TERMINAL FONT then we want
  4361.    to change the default code page to the font that was loaded.
  4362. */
  4363.         if (tt_font != TTF_ROM) {
  4364.             for (y = 0; y < ntermfont; y++ ) {
  4365.                 if (term_font[y].kwval == tt_font) {
  4366.                     s = term_font[y].kwd;
  4367.                     break;
  4368.                 }
  4369.             }
  4370.         }
  4371. #endif /* PCFONTS */
  4372. #else  /* Not K95... */
  4373.         s = fcsinfo[fcharset].keyword;
  4374. #endif /* OS2 */
  4375.  
  4376.         if ((y = cmkey(
  4377. #ifdef CKOUNI
  4378.                        txrtab,ntxrtab,
  4379. #else /* CKOUNI */
  4380.                        ttcstab,ntermc,
  4381. #endif /* CKOUNI */
  4382.                        "local character-set",s,xxstring)) < 0)
  4383.           return(y);
  4384.  
  4385. #ifdef UNICODE
  4386.         if (y == TX_UTF8) {
  4387.             printf("?UTF8 may not be used as a local character set.\r\n");
  4388.             return(-9);
  4389.         }
  4390. #endif /* UNICODE */
  4391. #ifdef OS2
  4392.         if ((z = cmkey(graphsettab,ngraphset,
  4393.                        "DEC VT intermediate graphic set","all",xxstring)) < 0)
  4394.             return(z);
  4395. #endif /* OS2 */
  4396.         if ((eol = cmcfm()) < 0)
  4397.             return(eol); /* Confirm the command */
  4398.  
  4399.         /* End of command parsing - actions begin */
  4400.         setlclcharset(y);
  4401.         setremcharset(x,z);
  4402.         return(success = 1);
  4403.       }
  4404. #endif /* NOCSETS */
  4405.  
  4406. #ifndef NOCSETS
  4407.       case XYTLCS:                      /* SET TERMINAL LOCAL-CHARACTER-SET */
  4408.         /* set terminal character-set <local> */
  4409.         s = getdcset();                 /* Get display character-set name */
  4410.         if ((y = cmkey(
  4411. #ifdef CKOUNI
  4412.                        txrtab,ntxrtab,
  4413. #else /* CKOUNI */
  4414.                        fcstab,nfilc,
  4415. #endif /* CKOUNI */
  4416.                        "local character-set",s,xxstring)) < 0)
  4417.           return(y);
  4418.  
  4419. #ifdef UNICODE
  4420.           if (y == TX_UTF8) {
  4421.               printf("?UTF8 may not be used as a local character set.\r\n");
  4422.               return(-9);
  4423.           }
  4424. #endif /* UNICODE */
  4425.           if ((z = cmcfm()) < 0) return(z); /* Confirm the command */
  4426.  
  4427.           /* End of command parsing - action begins */
  4428.  
  4429.         setlclcharset(y);
  4430.         return(success = 1);
  4431. #endif /* NOCSETS */
  4432.  
  4433. #ifndef NOCSETS
  4434. #ifdef UNICODE
  4435.       case XYTUNI:                      /* SET TERMINAL UNICODE */
  4436.         return(seton(&tt_unicode));
  4437. #endif /* UNICODE */
  4438.  
  4439.       case XYTRCS:                      /* SET TERMINAL REMOTE-CHARACTER-SET */
  4440.         /* set terminal character-set <remote> <Graphic-set> */
  4441.         if ((x = cmkey(
  4442. #ifdef CKOUNI
  4443.                 txrtab, ntxrtab,
  4444. #else /* CKOUNI */
  4445.                 ttcstab,ntermc,
  4446. #endif /* CKOUNI */
  4447.                        "remote terminal character-set","",xxstring)) < 0)
  4448.           return(x);
  4449.  
  4450. #ifdef UNICODE
  4451.         if (x == TX_TRANSP
  4452. #ifdef CKOUNI
  4453.             || x == TX_UTF8
  4454. #endif /* CKOUNI */
  4455.            ) {
  4456.               if ((y = cmcfm()) < 0)    /* Confirm the command */
  4457.                   return(y);
  4458. #ifdef OS2
  4459.             if ( isunicode() && x == TX_TRANSP ) {
  4460.                 /* If we are in unicode display mode then transparent
  4461.                  * only affects the output direction.  We need to know
  4462.                  * the actual remote character set in order to perform
  4463.                  * the tcsr -> ucs2 translation for display.
  4464.                  */
  4465.                 x = tcsl;
  4466.             }
  4467. #endif /* OS2 */
  4468.         }
  4469. #else /* UNICODE */
  4470.         if (x == FC_TRANSP) {
  4471.           if ((y = cmcfm()) < 0)        /* Confirm the command */
  4472.             return(y);
  4473.         }
  4474. #endif /* UNICODE */
  4475.         else {
  4476. #ifdef OS2
  4477.           if ((z = cmkey(graphsettab,ngraphset,
  4478.                       "DEC VT intermediate graphic set","all",xxstring)) < 0)
  4479.             return(z);
  4480. #endif /* OS2 */
  4481.           if ((y = cmcfm()) < 0)        /* Confirm the command */
  4482.             return(y);
  4483.         }
  4484.         /* Command parsing ends here */
  4485.  
  4486.         setremcharset(x,z);
  4487.         return(success = 1);
  4488. #endif /* NOCSETS */
  4489.  
  4490.       case XYTEC:                       /* SET TERMINAL ECHO */
  4491.         if ((x = cmkey(rltab,nrlt,"which side echos during CONNECT",
  4492.                        "remote", xxstring)) < 0) return(x);
  4493.         if ((y = cmcfm()) < 0) return(y);
  4494. #ifdef NETCONN
  4495.         oldplex = x;
  4496. #endif /* NETCONN */
  4497.         duplex = x;
  4498.         return(success = 1);
  4499.  
  4500.       case XYTESC:                      /* SET TERM ESC */
  4501.         if ((x = cmkey(nabltab,nnabltab,"","enabled",xxstring)) < 0)
  4502.           return(x);
  4503.         if ((y = cmcfm()) < 0) return(y);
  4504.         tt_escape = x;
  4505.         return(1);
  4506.  
  4507.       case XYTCRD:                      /* SET TERMINAL CR-DISPLAY */
  4508.         if ((x = cmkey(crdtab,2,"", "normal", xxstring)) < 0) return(x);
  4509.         if ((y = cmcfm()) < 0) return(y);
  4510.         tt_crd = x;
  4511.         return(success = 1);
  4512.  
  4513. #ifdef OS2
  4514.       case XYTANS: {                    /* SET TERMINAL ANSWERBACK */
  4515. /*
  4516.   NOTE: We let them enable and disable the answerback sequence, but we
  4517.   do NOT let them change it, and we definitely do not let the host set it.
  4518.   This is a security feature.
  4519.  
  4520.   As of 1.1.8 we allow the SET TERM ANSWERBACK MESSAGE <string> to be
  4521.   used just as MS-DOS Kermit does.  C0 and C1 controls as well as DEL
  4522.   are not allowed to be used as characters.  They are translated to
  4523.   underscore.  This may not be set by APC.
  4524. */
  4525.           if ((x = cmkey(anbktab,nansbk,"", "off", xxstring)) < 0)
  4526.             return(x);
  4527.           if (x < 2) {
  4528.               if ((y = cmcfm()) < 0)
  4529.                 return(y);
  4530.               tt_answer = x;
  4531.               return(success = 1);
  4532.           } else if ( x == 2 || x == 3) {
  4533.               int len = 0;
  4534.               extern int safeanswerbk;
  4535.               extern char useranswerbk[];
  4536.               if ((y = cmtxt("Answerback extension","",&s,xxstring)) < 0)
  4537.                 return(y);
  4538.               if (apcactive == APC_LOCAL ||
  4539.                   (apcactive == APC_REMOTE && !(apcstatus & APC_UNCH)))
  4540.                 return(success = 0);
  4541.               len = strlen(s);
  4542.               if (x == 2) {
  4543.                   /* Safe Answerback's don't have C0/C1 chars */
  4544.                   for (z = 0; z < len; z++) {
  4545.                       if ((s[z] & 0x7F) <= SP || (s[z] & 0x7F) == DEL)
  4546.                         useranswerbk[z] = '_';
  4547.                       else
  4548.                         useranswerbk[z] = s[z];
  4549.                   }
  4550.                   useranswerbk[z] = '\0';
  4551.                   safeanswerbk = 1 ;    /* TRUE */
  4552.               } else {
  4553.                   ckstrncpy(useranswerbk,s,60); /* (see ckocon.c) */
  4554.                   safeanswerbk = 0;     /* FALSE */
  4555.               }
  4556.               updanswerbk();
  4557.               return(success = 1);
  4558.           } else
  4559.             return(success = 0);
  4560.       }
  4561. #endif /* OS2 */
  4562.  
  4563. #ifdef CK_APC
  4564.       case XYTAPC:
  4565.         if ((y = cmkey(apctab,napctab,
  4566.                        "application program command execution","",
  4567.                        xxstring)) < 0)
  4568.           return(y);
  4569.         if ((x = cmcfm()) < 0)
  4570.           return(x);
  4571.         if (apcactive == APC_LOCAL ||
  4572.             (apcactive == APC_REMOTE && !(apcstatus & APC_UNCH)))
  4573.           return(success = 0);
  4574.         apcstatus = y;
  4575.         return(success = 1);
  4576.  
  4577. #ifdef CK_AUTODL
  4578.       case XYTAUTODL:                   /* AUTODOWNLOAD */
  4579.         if ((y = cmkey(adltab,nadltab,"Auto-download options","",
  4580.                        xxstring)) < 0)
  4581.           return(y);
  4582.         switch (y) {
  4583.           case TAD_ON:
  4584.           case TAD_OFF:
  4585.             if ((x = cmcfm()) < 0)
  4586.               return(x);
  4587.             setautodl(y,0);
  4588.             break;
  4589.           case TAD_ASK:
  4590.             if ((x = cmcfm()) < 0)
  4591.               return(x);
  4592.             setautodl(TAD_ON,1);
  4593.             break;
  4594.           case TAD_ERR:
  4595.             if ((y = cmkey(adlerrtab,nadlerrtab,"","", xxstring)) < 0)
  4596.               return(y);
  4597.             if ((x = cmcfm()) < 0)
  4598.               return(x);
  4599.             adl_err = y;
  4600.             break;
  4601. #ifdef OS2
  4602.           case TAD_K:
  4603.             if ((y = cmkey(adlxtab,nadlxtab,"","", xxstring)) < 0)
  4604.               return(y);
  4605.             switch (y) {
  4606.               case TAD_X_C0:
  4607.                 if ((y = cmkey(adlc0tab,nadlc0tab,"",
  4608.                                "processed-by-emulator",xxstring)) < 0)
  4609.                   return(y);
  4610.                 if ((x = cmcfm()) < 0)
  4611.                   return(x);
  4612.                 adl_kc0 = y;
  4613.                 break;
  4614.               case TAD_X_DETECT:
  4615.                 if ((y = cmkey(adldtab,nadldtab,"","packet",xxstring)) < 0)
  4616.                   return(y);
  4617.                 if ((x = cmcfm()) < 0)
  4618.                   return(x);
  4619.                 adl_kmode = y;
  4620.                 break;
  4621.               case TAD_X_STR:
  4622.                 if ((y = cmtxt("Kermit start string","KERMIT READY TO SEND...",
  4623.                                &s,xxstring)) < 0)
  4624.                   return(y);
  4625.                 free(adl_kstr);
  4626.                 adl_kstr = strdup(s);
  4627.                 break;
  4628.             }
  4629.             break;
  4630.  
  4631.           case TAD_Z:
  4632.             if ((y = cmkey(adlxtab,nadlxtab,"","",xxstring)) < 0)
  4633.               return(y);
  4634.             switch (y) {
  4635.               case TAD_X_C0:
  4636.                 if ((y = cmkey(adlc0tab,nadlc0tab,"",
  4637.                                "processed-by-emulator",xxstring)) < 0)
  4638.                   return(y);
  4639.                 if ((x = cmcfm()) < 0)
  4640.                   return(x);
  4641.                 adl_zc0 = y;
  4642.                 break;
  4643.               case TAD_X_DETECT:
  4644.                 if ((y = cmkey(adldtab,nadldtab,"","packet",xxstring)) < 0)
  4645.                   return(y);
  4646.                 if ((x = cmcfm()) < 0)
  4647.                   return(x);
  4648.                 adl_zmode = y;
  4649.                 break;
  4650.               case TAD_X_STR:
  4651.                 if ((y = cmtxt("","rz\\{13}",&s,xxstring)) < 0)
  4652.                   return(y);
  4653.                 free(adl_zstr);
  4654.                 adl_zstr = strdup(s);
  4655.                 break;
  4656.             }
  4657.             break;
  4658. #endif /* OS2 */
  4659.         }
  4660.         return(success = 1);
  4661.  
  4662. #endif /* CK_AUTODL */
  4663. #endif /* CK_APC */
  4664.  
  4665. #ifdef OS2
  4666.       case XYTBEL:
  4667.         return(success = setbell());
  4668.  
  4669.       case XYTMBEL:                     /* MARGIN-BELL */
  4670.         if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  4671.         if (y) {                        /* ON */
  4672.             if ((z = cmnum("Column at which to set margin bell",
  4673.                            "72",10,&x,xxstring)) < 0)
  4674.               return(z);
  4675.         }
  4676.         if ((z = cmcfm()) < 0) return(z);
  4677.         marginbell = y;
  4678.         marginbellcol = x;
  4679.         return(success = 1);
  4680. #endif /* OS2 */
  4681.  
  4682. #ifdef CKTIDLE
  4683.       case XYTIDLE:                     /* IDLE-SEND */
  4684.       case XYTITMO:                     /* IDLE-TIMEOUT */
  4685.         if ((z = cmnum("seconds of idle time to wait, or 0 to disable",
  4686.                        "0",10,&x,xxstring)) < 0)
  4687.           return(z);
  4688.         if (y == XYTIDLE) {
  4689.             if ((y = cmtxt("string to send, may contain kverbs and variables",
  4690.                            "\\v(newline)",&s,xxstring)) < 0)
  4691.               return(y);
  4692.             tt_idlesnd_tmo = x;         /* (old) */
  4693.             tt_idlelimit = x;           /* (new) */
  4694.             makestr(&tt_idlestr,brstrip(s)); /* (new) */
  4695.             tt_idlesnd_str = tt_idlestr; /* (old) */
  4696.             tt_idleact = IDLE_OUT;      /* (new) */
  4697.         } else {
  4698.             if ((y = cmcfm()) < 0)
  4699.               return(y);
  4700.             tt_idlelimit = x;
  4701.         }
  4702. #ifdef OS2
  4703.         puterror(VTERM);
  4704. #endif /* OS2 */
  4705.         return(success = 1);
  4706.  
  4707.       case XYTIACT: {                   /* SET TERM IDLE-ACTION */
  4708.           if ((y = cmkey(idlacts,nidlacts,"","",xxstring)) < 0)
  4709.             return(y);
  4710.           if (y == IDLE_OUT) {
  4711.               if ((x = cmtxt("string to send, may contain kverbs and variables"
  4712.                              , "\\v(newline)",&s,xxstring)) < 0)
  4713.                 return(x);
  4714.               makestr(&tt_idlestr,brstrip(s)); /* (new) */
  4715.               tt_idlesnd_str = tt_idlestr; /* (old) */
  4716.           } else {
  4717.               if ((x = cmcfm()) < 0)
  4718.                 return(x);
  4719.           }
  4720.           tt_idleact = y;
  4721.           return(success = 1);
  4722.       }
  4723. #endif /* CKTIDLE */
  4724.  
  4725.       case XYTDEB:                      /* TERMINAL DEBUG */
  4726.         y = seton(&x);                  /* Go parse ON or OFF */
  4727.         if (y > 0)                      /* Command succeeded? */
  4728.           setdebses(z);
  4729.         return(y);
  4730.  
  4731. #ifdef OS2
  4732.       case XYTASCRL:                    /* SET TERMINAL AUTOSCROLL */
  4733.           y = seton(&autoscroll);
  4734.           return(y);
  4735.  
  4736.       case XYTAPAGE:                    /* SET TERMINAL AUTOPAGE */
  4737.           y = seton(&wy_autopage);
  4738.           return(y);
  4739.  
  4740.       case XYTROL:                      /* SET TERMINAL ROLL */
  4741.         if ((y = cmkey(rolltab,nroll,"scrollback mode","insert",xxstring))<0)
  4742.       return(y);
  4743.     if (y == TTR_KEYS) {
  4744.         if ((x = cmkey(rollkeytab,nrollkey,"","send",xxstring))<0)
  4745.           return(x);
  4746.         if ((z = cmcfm()) < 0) return(z);
  4747.         tt_rkeys[VTERM] = x;
  4748.     } else {
  4749.         if ((x = cmcfm()) < 0) return(x);
  4750.         tt_roll[VTERM] = y;
  4751.     }
  4752.         return(success = 1);
  4753.  
  4754.       case XYTCTS:                      /* SET TERMINAL TRANSMIT-TIMEOUT */
  4755.         y = cmnum("Maximum seconds to allow CTS off during CONNECT",
  4756.                   "5",10,&x,xxstring);
  4757.         return(setnum(&tt_ctstmo,x,y,10000));
  4758.  
  4759.       case XYTCPG: {                    /* SET TERMINAL CODE-PAGE */
  4760.         int i;
  4761.         int cp = -1;
  4762.         y = cmnum("PC code page to use during terminal emulation",
  4763.                   ckitoa(os2getcp()),10,&x,xxstring);
  4764.         if ((x = setnum(&cp,x,y,11000)) < 0) return(x);
  4765.         if (os2setcp(cp) != 1) {
  4766. #ifdef NT
  4767.             if (isWin95())
  4768.               printf(
  4769.                  "Sorry, Windows 95 does not support code page switching\n");
  4770.             else
  4771. #endif /* NT */
  4772.               printf(
  4773.                  "Sorry, %d is not a valid code page for this system.\n",cp);
  4774.             return(-9);
  4775.         }
  4776.     /* Force the terminal character-sets conversions to be updated */
  4777.         for ( i = 0; i < 4; i++ )
  4778.           G[i].init = TRUE;
  4779.         return(1);
  4780.     }
  4781.  
  4782.       case XYTPAC:                      /* SET TERMINAL OUTPUT-PACING */
  4783.         y = cmnum(
  4784.            "Pause between sending each character during CONNECT, milliseconds",
  4785.                   "-1",10,&x,xxstring);
  4786.         return(setnum(&tt_pacing,x,y,10000));
  4787.  
  4788. #ifdef OS2MOUSE
  4789.       case XYTMOU: {                    /* SET TERMINAL MOUSE */
  4790.           int old_mou = tt_mouse;
  4791.           if ((x = seton(&tt_mouse)) < 0)
  4792.             return(x);
  4793.           if (tt_mouse != old_mou)
  4794.             if (tt_mouse)
  4795.               os2_mouseon();
  4796.             else
  4797.               os2_mouseoff();
  4798.           return(1);
  4799.       }
  4800. #endif /* OS2MOUSE */
  4801. #endif /* OS2 */
  4802.  
  4803.       case XYTWID: {
  4804.           if ((y = cmnum(
  4805. #ifdef OS2
  4806.                          "number of columns in display window during CONNECT",
  4807. #else
  4808.                          "number of columns on your screen",
  4809. #endif /* OS2 */
  4810.                          "80",10,&x,xxstring)) < 0)
  4811.             return(y);
  4812.           if ((y = cmcfm()) < 0) return(y);
  4813. #ifdef OS2
  4814.           return(success = os2_settermwidth(x));
  4815. #else  /* Not OS/2 */
  4816.           tt_cols = x;
  4817.           return(success = 1);
  4818. #endif /* OS2 */
  4819.       }
  4820.  
  4821.       case XYTHIG:
  4822.         if ((y = cmnum(
  4823. #ifdef OS2
  4824.  "number of rows in display window during CONNECT, not including status line",
  4825.  tt_status[VTERM]?"24":"25",
  4826. #else
  4827.  "24","number of rows on your screen",
  4828. #endif /* OS2 */
  4829.                        10,&x,xxstring)) < 0)
  4830.           return(y);
  4831.         if ((y = cmcfm()) < 0) return(y);
  4832.  
  4833. #ifdef OS2
  4834.         return (success = os2_settermheight(x));
  4835. #else  /* Not OS/2 */
  4836.         tt_rows = x;
  4837.         return(success = 1);
  4838. #endif /* OS2 */
  4839.  
  4840. #ifdef OS2
  4841.       case XYTPRN: {                    /* Print Mode */
  4842.           extern bool xprint, aprint, cprint, uprint;
  4843.           if ((y = cmkey(prnmtab,nprnmtab,"","off", xxstring)) < 0) return(y);
  4844.           if ((x = cmcfm()) < 0) return(x);
  4845.           switch (y) {
  4846.             case 0:
  4847.               if (cprint || uprint || aprint || xprint)
  4848.                 printeroff();
  4849.               cprint = xprint = uprint = 0;
  4850.               setaprint(0);
  4851.               break;
  4852.             case 1:
  4853.               if (!(cprint || uprint || aprint || xprint))
  4854.                 printeron();
  4855.               setaprint(1);
  4856.               cprint = xprint = uprint = 0;
  4857.               break;
  4858.             case 2:
  4859.               if (!(cprint || uprint || aprint || xprint))
  4860.                 printeron();
  4861.               cprint = 1;
  4862.               setaprint(0);
  4863.           xprint = uprint = 0;
  4864.               break;
  4865.             case 3:
  4866.               if (!(cprint || uprint || aprint || xprint))
  4867.                 printeron();
  4868.               uprint = 1;
  4869.               setaprint(0);
  4870.               xprint = cprint = 0;
  4871.               break;
  4872.           }
  4873.           return(1);
  4874.       }
  4875. #else
  4876. #ifdef XPRINT
  4877.       case XYTPRN: {
  4878.           extern int tt_print;
  4879.           if ((x = seton(&tt_print)) < 0)
  4880.             return(x);
  4881.           return(success = 1);
  4882.       }
  4883. #endif /* XPRINT */
  4884. #endif /* OS2 */
  4885.  
  4886. #ifdef OS2
  4887.       case XYTSCNM: {
  4888.           extern int decscnm, decscnm_usr;
  4889.           if ((y = cmkey(normrev,4,"",
  4890.                          decscnm_usr?"reverse":"normal",
  4891.                          xxstring)
  4892.                ) < 0)
  4893.             return(y);
  4894.           if ((x = cmcfm()) < 0) return(x);
  4895.           decscnm_usr = y;
  4896.           if (decscnm != decscnm_usr)
  4897.             flipscreen(VTERM);
  4898.           return(1);
  4899.     }
  4900.     case XYTOPTI:
  4901.         if ((y = cmkey(onoff,2,"",tt_diff_upd?"on":"off",
  4902.                         xxstring)) < 0) return(y);
  4903.         if ((x = cmcfm()) < 0) return(x);
  4904.         tt_diff_upd = y;
  4905.         return(1);
  4906.     case XYTUPD: {
  4907.         int mode, delay;
  4908.         if ((mode = cmkey(scrnupd,nscrnupd,"","fast",xxstring)) < 0) {
  4909.             return(mode);
  4910.         } else {
  4911.             y = cmnum(
  4912.             "Pause between FAST screen updates in CONNECT mode, milliseconds",
  4913.                       "100",10,&x,xxstring
  4914.                       );
  4915.             if (x < 0 || x > 1000 ) {
  4916.                 printf(
  4917.             "\n?The update rate must be between 0 and 1000 milliseconds.\n"
  4918.                        );
  4919.                 return(success = 0);
  4920.             }
  4921.             if ((y = cmcfm()) < 0) return(y);
  4922.  
  4923.             updmode = tt_updmode = mode;
  4924.             return(setnum(&tt_update,x,y,10000));
  4925.         }
  4926.     }
  4927.     case XYTCTRL:
  4928.           if ((x = cmkey(termctrl,ntermctrl,"","7",xxstring)) < 0) {
  4929.               return(x);
  4930.           } else {
  4931.               if ((y = cmcfm()) < 0)
  4932.                   return(y);
  4933.               switch ( x ) {
  4934.               case 8:
  4935.                   send_c1 = send_c1_usr = TRUE;
  4936.                   break;
  4937.               case 7:
  4938.               default:
  4939.                   send_c1 = send_c1_usr = FALSE;
  4940.                   break;
  4941.               }
  4942.           }
  4943.           return(success = TRUE);
  4944.           break;
  4945.  
  4946. #ifdef PCFONTS
  4947.       case XYTFON:
  4948.         if ( !IsOS2FullScreen() ) {
  4949.             printf(
  4950.         "\n?SET TERMINAL FONT is only supported in Full Screen sessions.\n");
  4951.             return(success = FALSE);
  4952.         }
  4953.  
  4954.         if ((x = cmkey(term_font,ntermfont,"","default",xxstring)) < 0) {
  4955.             return(x);
  4956.         } else {
  4957.             if ((y = cmcfm()) < 0) return(y);
  4958.             if ( !os2LoadPCFonts() ) {
  4959.                 tt_font = x;
  4960.                 return(success = TRUE);
  4961.             } else {
  4962.                 printf(
  4963.       "\n?PCFONTS.DLL is not available in CKERMIT executable directory.\n");
  4964.                 return(success = FALSE);
  4965.             }
  4966.         }
  4967.         break;
  4968. #else /* PCFONTS */
  4969. #ifdef NT
  4970. #ifdef KUI
  4971.     case XYTFON:
  4972.         return(setguifont());           /* ckuus3.c */
  4973. #endif /* KUI */
  4974. #endif /* NT */
  4975. #endif /* PCFONTS */
  4976.  
  4977.       case XYTVCH: {
  4978.           extern int pheight, marginbot, cmd_rows, cmd_cols;
  4979.           if ((x = cmkey(tvctab,ntvctab,"",isWin95()?"win95-safe":"enabled",
  4980.                          xxstring)) < 0)
  4981.             return(x);
  4982.           if ((y = cmcfm()) < 0) return(y);
  4983. #ifndef KUI
  4984.           if (x != tt_modechg) {
  4985.               switch (x) {
  4986.                 case TVC_DIS:
  4987.                   /* When disabled the heights of all of the virtual screens */
  4988.                   /* must be equal to the physical height of the console     */
  4989.                   /* window and may not be changed.                          */
  4990.                   /* The width of the window may not be altered.             */
  4991.                   tt_modechg = TVC_ENA;                 /* Temporary */
  4992.                   if (marginbot > pheight-(tt_status[VTERM]?1:0))
  4993.                     marginbot = pheight-(tt_status[VTERM]?1:0);
  4994.                   tt_szchng[VCMD] = 1 ;
  4995.                   tt_rows[VCMD] = pheight;
  4996.                   VscrnInit(VCMD);
  4997.                   SetCols(VCMD);
  4998.                   cmd_rows = y;
  4999.  
  5000.                   tt_szchng[VTERM] = 2 ;
  5001.                   tt_rows[VTERM] = pheight - (tt_status[VTERM]?1:0);
  5002.                   VscrnInit(VTERM);
  5003.  
  5004.                   break;
  5005.  
  5006.                 case TVC_ENA:
  5007.                   /* When enabled the physical height of the console windows */
  5008.                   /* should be adjusted to the height of the virtual screen  */
  5009.                   /* The width may be set to anything.                       */
  5010.                   /* nothing to do                                           */
  5011.                   break;
  5012.  
  5013.               case TVC_W95:
  5014.                   /* Win95-safe mode allows the physical height to change    */
  5015.                   /* but restricts it to a width of 80 and a height equal to */
  5016.                   /* 25, 43, or 50.  Must be adjusted now.                   */
  5017.                   /* The virtual heights must be equal to the above.         */
  5018.                   if (pheight != 25 && pheight != 43 && pheight != 50) {
  5019.                       if (pheight < 25)
  5020.                         y = 25;
  5021.                       else if (pheight < 43)
  5022.                         y = 43;
  5023.                       else
  5024.                         y = 50;
  5025.                   } else
  5026.                     y = pheight;
  5027.  
  5028.                   tt_modechg = TVC_ENA; /* Temporary */
  5029.  
  5030.                   tt_szchng[VCMD] = 1;
  5031.                   tt_rows[VCMD] = y;
  5032.                   tt_cols[VCMD] = 80;
  5033.                   VscrnInit(VCMD);
  5034.                   SetCols(VCMD);
  5035.                   cmd_rows = y;
  5036.                   cmd_cols = 80;
  5037.  
  5038.                   marginbot = y-(tt_status[VTERM]?1:0);
  5039.                   tt_szchng[VTERM] = 2;
  5040.                   tt_rows[VTERM] = y - (tt_status[VTERM]?1:0);
  5041.                   tt_cols[VTERM] = 80;
  5042.                   VscrnInit(VTERM);
  5043.                   break;
  5044.               }
  5045.               tt_modechg = x;
  5046.           }
  5047.           return(success = 1);
  5048. #else
  5049.           return(success = 0);
  5050. #endif /* KUI */
  5051.       }
  5052.       case XYTSTAT: {
  5053.           extern int marginbot;
  5054.           if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5055.           if ((x = cmcfm()) < 0) return(x);
  5056.           if (y != tt_status[VTERM] || y != tt_status_usr[VTERM]) {
  5057.               /* Might need to fixup the margins */
  5058.               if ( marginbot == VscrnGetHeight(VTERM)-(tt_status[VTERM]?1:0) )
  5059.                 if (y) {
  5060.                     marginbot--;
  5061.                 } else {
  5062.                     marginbot++;
  5063.                 }
  5064.               tt_status_usr[VTERM] = tt_status[VTERM] = y;
  5065.               if (y) {
  5066.                     tt_szchng[VTERM] = 2;
  5067.                     tt_rows[VTERM]--;
  5068.                     VscrnInit(VTERM);  /* Height set here */
  5069. #ifdef TNCODE
  5070.                     if (TELOPT_ME(TELOPT_NAWS))
  5071.                       tn_snaws();
  5072. #endif /* TNCODE */
  5073. #ifdef RLOGCODE
  5074.                     if (TELOPT_ME(TELOPT_NAWS))
  5075.                       rlog_naws();
  5076. #endif /* RLOGCODE */
  5077. #ifdef SSHBUILTIN
  5078.                     if (TELOPT_ME(TELOPT_NAWS))
  5079.                       ssh_snaws();
  5080. #endif /* SSHBUILTIN */
  5081.               } else {
  5082.                   tt_szchng[VTERM] = 1;
  5083.                   tt_rows[VTERM]++;
  5084.                   VscrnInit(VTERM);     /* Height set here */
  5085. #ifdef TNCODE
  5086.                   if (TELOPT_ME(TELOPT_NAWS))
  5087.                     tn_snaws();
  5088. #endif /* TNCODE */
  5089. #ifdef RLOGCODE
  5090.                   if (TELOPT_ME(TELOPT_NAWS))
  5091.                     rlog_naws();
  5092. #endif /* RLOGCODE */
  5093. #ifdef SSHBUILTIN
  5094.                   if (TELOPT_ME(TELOPT_NAWS))
  5095.                     ssh_snaws();
  5096. #endif /* SSHBUILTIN */
  5097.               }
  5098.           }
  5099.           return(1);
  5100.       }
  5101. #endif /* OS2 */
  5102.  
  5103. #ifdef NT
  5104.       case XYTATTBUG:
  5105.         if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5106.         if ((x = cmcfm()) < 0) return(x);
  5107.         tt_attr_bug = y;
  5108.         return(1);
  5109. #endif /* NT */
  5110.  
  5111. #ifdef OS2
  5112.       case XYTSGRC:
  5113.         if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5114.         if ((x = cmcfm()) < 0) return(x);
  5115.         sgrcolors = y;
  5116.         return(1);
  5117.  
  5118.       case XYTSEND:
  5119.           if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5120.           if ((x = cmcfm()) < 0) return(x);
  5121.           tt_senddata = y;
  5122.           return(1);
  5123.  
  5124.       case XYTSEOB:
  5125.           if ((y = cmkey(ttyseobtab,2,"","us_cr",xxstring)) < 0) return(y);
  5126.           if ((x = cmcfm()) < 0) return(x);
  5127.           wy_blockend = y;
  5128.           return(1);
  5129.  
  5130.       case XYTURLHI: {
  5131.           int done = 0, attr = VT_CHAR_ATTR_NORMAL;
  5132.  
  5133.           if ((x = cmkey(onoff,2,"","on",xxstring)) < 0)
  5134.             return(x);
  5135.           if (x) {
  5136.               z = 0;
  5137.               while (!done) {
  5138.                   if ((y = cmkey(ttyprotab,nprotect,"",
  5139.                                  z?"done":"reverse",xxstring)) < 0)
  5140.                     return(y);
  5141.                   switch (y) {
  5142.                     case TTATTDONE:
  5143.                       done = TRUE;
  5144.                       break;
  5145.                     case TTATTBLI:
  5146.                       attr |= VT_CHAR_ATTR_BLINK;
  5147.                       break;
  5148.                     case TTATTREV:
  5149.                       attr |= VT_CHAR_ATTR_REVERSE;
  5150.                       break;
  5151.                     case TTATTITA:
  5152.                       attr |= VT_CHAR_ATTR_ITALIC;
  5153.                       break;
  5154.                     case TTATTUND:
  5155.                       attr |= VT_CHAR_ATTR_UNDERLINE;
  5156.                       break;
  5157.                     case TTATTBLD:
  5158.                       attr |= VT_CHAR_ATTR_BOLD;
  5159.                       break;
  5160.                     case TTATTDIM:
  5161.                       attr |= VT_CHAR_ATTR_DIM;
  5162.                       break;
  5163.                     case TTATTINV:
  5164.                       attr |= VT_CHAR_ATTR_INVISIBLE;
  5165.                       break;
  5166.                     case TTATTNOR:
  5167.                       break;
  5168.                   }
  5169.                   z = 1;                /* One attribute has been chosen */
  5170.               }
  5171.           }
  5172.           if ((z = cmcfm()) < 0) return(z);
  5173.           seturlhl(x);
  5174.           if (x)
  5175.             tt_url_hilite_attr = attr;
  5176.           return(1);
  5177.       }
  5178.       case XYTATTR:
  5179.         if ((x = cmkey(ttyattrtab,nattrib,"","underline",xxstring)) < 0)
  5180.           return(x);
  5181.         switch (x) {
  5182.           case TTATTBLI:
  5183.             if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5184.             if ((x = cmcfm()) < 0) return(x);
  5185.             trueblink = y;
  5186. #ifndef KUI
  5187.             if ( !trueblink && trueunderline ) {
  5188.                 trueunderline = 0;
  5189.                 printf("Warning: Underline being simulated by color.\n");
  5190.             }
  5191.  
  5192. #endif /* KUI */
  5193.             break;
  5194.  
  5195.           case TTATTDIM:
  5196.             if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5197.             if ((x = cmcfm()) < 0) return(x);
  5198.             truedim = y;
  5199.             break;
  5200.  
  5201.           case TTATTREV:
  5202.             if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5203.             if ((x = cmcfm()) < 0) return(x);
  5204.             truereverse = y;
  5205.             break;
  5206.  
  5207.           case TTATTUND:
  5208.             if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5209.             if ((x = cmcfm()) < 0) return(x);
  5210.             trueunderline = y;
  5211. #ifndef KUI
  5212.             if (!trueblink && trueunderline) {
  5213.                 trueblink = 1;
  5214.                 printf("Warning: True blink mode is active.\n");
  5215.             }
  5216. #endif /* KUI */
  5217.             break;
  5218.  
  5219.           case TTATTITA:
  5220.               if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5221.               if ((x = cmcfm()) < 0) return(x);
  5222.               trueitalic = y;
  5223.             break;
  5224.  
  5225.           case TTATTPRO: {      /* Set default Protected Character attribute */
  5226.               extern vtattrib WPattrib;    /* current WP Mode Attrib */
  5227.               extern vtattrib defWPattrib; /* default WP Mode Attrib */
  5228.               vtattrib wpa = {0,0,0,0,0,1,0,0,0};       /* Protected */
  5229.               int done = 0;
  5230.  
  5231.               x = 0;
  5232.               while (!done) {
  5233.                   if ((y = cmkey(ttyprotab,nprotect,"",
  5234.                                  x?"done":"dim",xxstring)) < 0)
  5235.                     return(y);
  5236.                   switch (y) {
  5237.                     case TTATTNOR:
  5238.                       break;
  5239.                     case TTATTBLI:      /* Blinking doesn't work */
  5240.                       wpa.blinking = TRUE;
  5241.                       break;
  5242.                     case TTATTREV:
  5243.                       wpa.reversed = TRUE;
  5244.                       break;
  5245.                     case TTATTITA:
  5246.                       wpa.italic = TRUE;
  5247.                       break;
  5248.                     case TTATTUND:
  5249.                       wpa.underlined = TRUE;
  5250.                       break;
  5251.                     case TTATTBLD:
  5252.                       wpa.bold = TRUE;
  5253.                       break;
  5254.                     case TTATTDIM:
  5255.                       wpa.dim = TRUE;
  5256.                       break;
  5257.                     case TTATTINV:
  5258.                       wpa.invisible = TRUE ;
  5259.                       break;
  5260.                     case TTATTDONE:
  5261.                       done = TRUE;
  5262.                       break;
  5263.                   }
  5264.                   x = 1;                /* One attribute has been chosen */
  5265.               }
  5266.               if ((x = cmcfm()) < 0) return(x);
  5267.               WPattrib = defWPattrib = wpa;
  5268.               break;
  5269.           }
  5270.         }
  5271.         return(1);
  5272.  
  5273.       case XYTKEY: {                    /* SET TERMINAL KEY */
  5274.           int t, x, y;
  5275.           int clear = 0, deflt = 0;
  5276.           int confirmed = 0;
  5277.           int flag = 0;
  5278.           int kc = -1;                  /* Key code */
  5279.           int litstr = 0;               /* Literal String? */
  5280.           char *s = NULL;               /* Key binding */
  5281. #ifndef NOKVERBS
  5282.           char *p = NULL;               /* Worker */
  5283. #endif /* NOKVERBS */
  5284.           con_event defevt;
  5285.           extern int os2gks;
  5286.           extern int mskkeys;
  5287.           extern int initvik;
  5288.           struct FDB kw,sw,nu,cm;
  5289.  
  5290.           defevt.type = error;
  5291.  
  5292.           if ((t = cmkey(ttkeytab,nttkey,"","",xxstring)) < 0)
  5293.             return(t);
  5294.           cmfdbi(&nu,                   /* First FDB - command switches */
  5295.                  _CMNUM,                /* fcode */
  5296.                  "/literal, keycode, or action",
  5297.                  "",                    /* default */
  5298.                  "",                    /* addtl string data */
  5299.                  10,                    /* addtl numeric data 1: radix */
  5300.                  0,                     /* addtl numeric data 2: 0 */
  5301.                  xxstring,              /* Processing function */
  5302.                  NULL,                  /* Keyword table */
  5303.                  &sw                    /* Pointer to next FDB */
  5304.                  );                     /*  */
  5305.           cmfdbi(&sw,                   /* Second FDB - switches */
  5306.                  _CMKEY,                /* fcode */
  5307.                  "",
  5308.                  "",                    /* default */
  5309.                  "",                    /* addtl string data */
  5310.                  nstrmswitab,           /* addtl numeric data 1: tbl size */
  5311.                  4,                     /* addtl numeric data 2: 4 = cmswi */
  5312.                  xxstring,              /* Processing function */
  5313.                  strmswitab,            /* Keyword table */
  5314.                  &kw                    /* Pointer to next FDB */
  5315.                  );
  5316.           cmfdbi(&kw,                   /* Third FDB - command switches */
  5317.                  _CMKEY,                /* fcode */
  5318.                  "/literal, keycode, or action",
  5319.                  "",                    /* default */
  5320.                  "",                    /* addtl string data */
  5321.                  nstrmkeytab,           /* addtl numeric data 1: tbl size */
  5322.                  0,                     /* addtl numeric data 2 */
  5323.                  xxstring,              /* Processing function */
  5324.                  strmkeytab,            /* Keyword table */
  5325.                  &cm                    /* Pointer to next FDB */
  5326.                  );
  5327.           cmfdbi(&cm,                   /* Final FDB - Confirmation */
  5328.                  _CMCFM,                /* fcode */
  5329.                  "",
  5330.                  "",                    /* default */
  5331.                  "",                    /* addtl string data */
  5332.                  0,                     /* addtl numeric data 1: tbl size */
  5333.                  0,                     /* addtl numeric data 2: 4 = cmswi */
  5334.                  xxstring,              /* Processing function */
  5335.                  NULL,                  /* Keyword table */
  5336.                  NULL                   /* Pointer to next FDB */
  5337.                  );
  5338.           while (kc < 0) {
  5339.               x = cmfdb(&nu);           /* Parse something */
  5340.               if (x < 0)
  5341.                 return(x);
  5342.  
  5343.               switch (cmresult.fcode) {
  5344.                 case _CMCFM:
  5345.                   printf(" Press key to be defined: ");
  5346.                   conbin((char)escape); /* Put terminal in binary mode */
  5347.                   os2gks = 0;           /* Turn off Kverb preprocessing */
  5348.                   kc = congks(0);       /* Get character or scan code */
  5349.                   os2gks = 1;           /* Turn on Kverb preprocessing */
  5350.                   concb((char)escape);  /* Restore terminal to cbreak mode */
  5351.                   if (kc < 0) {         /* Check for error */
  5352.                       printf("?Error reading key\n");
  5353.                       return(0);
  5354.                   }
  5355.                   shokeycode(kc,t);     /* Show current definition */
  5356.                   flag = 1;             /* Remember it's a multiline command */
  5357.                   break;
  5358.                 case _CMNUM:
  5359.                   kc = cmresult.nresult;
  5360.                   break;
  5361.                 case _CMKEY:
  5362.                   if (cmresult.fdbaddr == &sw) { /* Switch */
  5363.                       if (cmresult.nresult == 0)
  5364.                         litstr = 1;
  5365.                   } else if (cmresult.fdbaddr == &kw) { /* Keyword */
  5366.                       if (cmresult.nresult == 0)
  5367.                         clear = 1;
  5368.                       else
  5369.                         deflt = 1;
  5370.                       if ((x = cmcfm()) < 0)
  5371.                         return(x);
  5372.                       if (clear)
  5373.                         clearkeymap(t);
  5374.                       else if (deflt)
  5375.                         defaultkeymap(t);
  5376.                       initvik = 1;
  5377.                       return(1);
  5378.                   }
  5379.               }
  5380.           }
  5381.  
  5382.     /* Normal SET TERMINAL KEY <terminal> <scancode> <value> command... */
  5383.  
  5384.           if (mskkeys)
  5385.             kc = msktock(kc);
  5386.  
  5387.           if (kc < 0 || kc >= KMSIZE) {
  5388.               printf("?key code must be between 0 and %d\n", KMSIZE - 1);
  5389.               return(-9);
  5390.           }
  5391.           if (kc == escape) {
  5392.               printf("Sorry, %d is the CONNECT-mode escape character\n",kc);
  5393.               return(-9);
  5394.           }
  5395.           wideresult = -1;
  5396.           if (flag) {
  5397.               cmsavp(psave,PROMPTL);
  5398.               cmsetp(" Enter new definition: ");
  5399.               cmini(ckxech);
  5400.           }
  5401.         def_again:
  5402.           if (flag) prompt(NULL);
  5403.           if ((y = cmtxt("key definition,\n\
  5404.  or Ctrl-C to cancel this command,\n\
  5405.  or Enter to restore default definition",
  5406.                          "",&s,NULL)) < 0) {
  5407.               if (flag)                 /* Handle parse errors */
  5408.                 goto def_again;
  5409.               else
  5410.                 return(y);
  5411.           }
  5412.           s = brstrip(s);
  5413. #ifndef NOKVERBS
  5414.           p = s;                        /* Save this place */
  5415. #endif /* NOKVERBS */
  5416. /*
  5417.   If the definition included any \Kverbs, quote the backslash so the \Kverb
  5418.   will still be in the definition when the key is pressed.  We don't do this
  5419.   in zzstring(), because \Kverbs are valid only in this context and nowhere
  5420.   else.
  5421.  
  5422.   We use this code active for all versions that support SET KEY, even if they
  5423.   don't support \Kverbs, because otherwise \K would behave differently for
  5424.   different versions.
  5425. */
  5426.           for (x = 0, y = 0; s[x]; x++, y++) { /* Convert \K to \\K */
  5427.               if ((x > 0) &&
  5428.                   (s[x] == 'K' || s[x] == 'k')
  5429.                   ) {                   /* Have K */
  5430.  
  5431.                   if ((x == 1 && s[x-1] == CMDQ) ||
  5432.                       (x > 1 && s[x-1] == CMDQ && s[x-2] != CMDQ)) {
  5433.                       line[y++] = CMDQ; /* Make it \\K */
  5434.                   }
  5435.                   if (x > 1 && s[x-1] == '{' && s[x-2] == CMDQ) {
  5436.                       line[y-1] = CMDQ; /* Have \{K */
  5437.                       line[y++] = '{';  /* Make it \\{K */
  5438.                   }
  5439.               }
  5440.               line[y] = s[x];
  5441.           }
  5442.           line[y++] = NUL;              /* Terminate */
  5443.           s = line + y + 1;             /* Point to after it */
  5444.           x = LINBUFSIZ - (int) strlen(line) - 1; /* Get remaining space */
  5445.           if ((x < (LINBUFSIZ / 2)) ||
  5446.               (zzstring(line, &s, &x) < 0)) { /* Expand variables, etc. */
  5447.               printf("?Key definition too long\n");
  5448.               if (flag) cmsetp(psave);
  5449.               return(-9);
  5450.           }
  5451.           s = line + y + 1;             /* Point to result. */
  5452.  
  5453. #ifndef NOKVERBS
  5454. /*
  5455.   Special case: see if the definition starts with a \Kverb.
  5456.   If it does, point to it with p, otherwise set p to NULL.
  5457. */
  5458.           p = s;
  5459.           if (*p++ == CMDQ) {
  5460.               if (*p == '{') p++;
  5461.               p = (*p == 'k' || *p == 'K') ? p + 1 : NULL;
  5462.           }
  5463. #endif /* NOKVERBS */
  5464.  
  5465.           switch (strlen(s)) {          /* Action depends on length */
  5466.             case 0:                     /* Clear individual key def */
  5467.               deletekeymap(t,kc);
  5468.               break;
  5469.             case 1:
  5470.               if (!litstr) {
  5471.                   defevt.type = key;    /* Single character */
  5472.                   defevt.key.scancode = *s;
  5473.                   break;
  5474.               }
  5475.             default:                    /* Character string */
  5476. #ifndef NOKVERBS
  5477.               if (p) {
  5478.                   y = xlookup(kverbs,p,nkverbs,&x); /* Look it up */
  5479.                   /* Need exact match */
  5480.                   debug(F101,"set key kverb lookup",0,y);
  5481.                   if (y > -1) {
  5482.                       defevt.type = kverb;
  5483.                       defevt.kverb.id = y;
  5484.                       break;
  5485.                   }
  5486.               }
  5487. #endif /* NOKVERBS */
  5488.               if (litstr) {
  5489.                   defevt.type = literal;
  5490.                   defevt.literal.string = (char *) malloc(strlen(s)+1);
  5491.                   if (defevt.literal.string)
  5492.                     strcpy(defevt.literal.string, s); /* safe */
  5493.               } else {
  5494.                   defevt.type = macro;
  5495.                   defevt.macro.string = (char *) malloc(strlen(s)+1);
  5496.                   if (defevt.macro.string)
  5497.                     strcpy(defevt.macro.string, s); /* safe */
  5498.               }
  5499.               break;
  5500.           }
  5501.           insertkeymap(t, kc, defevt);
  5502.           if (flag)
  5503.             cmsetp(psave);
  5504.           initvik = 1;                  /* Update VIK table */
  5505.           return(1);
  5506.       }
  5507.  
  5508. #ifdef PCTERM
  5509.       case XYTPCTERM:                   /* PCTERM Keyboard Mode */
  5510.         if ((x = seton(&tt_pcterm)) < 0) return(x);
  5511.         return(success = 1);
  5512. #endif /* PCTERM */
  5513. #endif /* OS2 */
  5514.  
  5515. #ifdef CK_TRIGGER
  5516.       case XYTRIGGER:
  5517.         if ((y = cmtxt("String to trigger automatic return to command mode",
  5518.                        "",&s,xxstring)) < 0)
  5519.           return(y);
  5520.         makelist(s,tt_trigger,TRIGGERS);
  5521.         return(1);
  5522. #endif /* CK_TRIGGER */
  5523.  
  5524. #ifdef OS2
  5525.       case XYTSAC:
  5526.         if ((y = cmnum("ASCII value to use for spacing attributes",
  5527.                        "32",10,&x,xxstring)) < 0)
  5528.           return(y);
  5529.         if ((y = cmcfm()) < 0) return(y);
  5530.         tt_sac = x;
  5531.         return(success = 1);
  5532.  
  5533.       case XYTKBDGL: {      /* SET TERM KBD-FOLLOWS-GL/GR */
  5534.           extern int tt_kb_glgr;        /* from ckoco3.c */
  5535.           if ((x = seton(&tt_kb_glgr)) < 0)
  5536.               return(x);
  5537.           return(success = 1);
  5538.       }
  5539. #ifndef NOCSETS
  5540.       case XYTVTLNG:        /* SET TERM DEC-LANGUAGE */
  5541.         if ((y = cmkey(vtlangtab,nvtlangtab,"VT language",
  5542.                        IS97801(tt_type_mode)?"german":"north-american",
  5543.                        xxstring)) < 0)
  5544.           return(y);
  5545.         if ((x = cmcfm()) < 0) return(x);
  5546.  
  5547.         /* A real VT terminal would use the language to set the   */
  5548.         /* default keyboard language for both 8-bit multinational */
  5549.         /* and 7-bit national modes.  For 8-bit mode it would     */
  5550.         /* set the terminal character-set to the ISO set if it    */
  5551.         /* is not already set.                                    */
  5552.         /* Latin-1 can be replaced by DEC Multinational           */
  5553.         switch (y) {
  5554.           case VTL_NORTH_AM:  /* North American */
  5555.             /* Multinational: Latin-1   */
  5556.             /* National:      US_ASCII  */
  5557.             dec_lang = y;
  5558.             dec_nrc = TX_ASCII;
  5559.             dec_kbd = TX_8859_1;
  5560.             break;
  5561.           case VTL_BRITISH :
  5562.             /* Multinational: Latin-1   */
  5563.             /* National:      UK_ASCII  */
  5564.             dec_lang = y;
  5565.             dec_nrc = TX_BRITISH;
  5566.             dec_kbd = TX_8859_1;
  5567.             break;
  5568.           case VTL_FRENCH  :
  5569.           case VTL_BELGIAN :
  5570.           case VTL_CANADIAN:
  5571.             /* Multinational: Latin-1   */
  5572.             /* National:      FR_ASCII  */
  5573.             dec_lang = y;
  5574.             dec_nrc = TX_FRENCH;
  5575.             dec_kbd = TX_8859_1;
  5576.             break;
  5577.           case VTL_FR_CAN  :
  5578.             /* Multinational: Latin-1   */
  5579.             /* National:      FC_ASCII  */
  5580.             dec_lang = y;
  5581.             dec_nrc = TX_CN_FRENCH;
  5582.             dec_kbd = TX_8859_1;
  5583.             break;
  5584.           case VTL_DANISH  :
  5585.           case VTL_NORWEGIA:
  5586.             /* Multinational: Latin-1   */
  5587.             /* National:      NO_ASCII  */
  5588.             dec_lang = y;
  5589.             dec_nrc = TX_NORWEGIAN;
  5590.             dec_kbd = TX_8859_1;
  5591.             break;
  5592.           case VTL_FINNISH :
  5593.             /* Multinational: Latin-1   */
  5594.             /* National:      FI_ASCII  */
  5595.             dec_lang = y;
  5596.             dec_nrc = TX_FINNISH;
  5597.             dec_kbd = TX_8859_1;
  5598.             break;
  5599.           case VTL_GERMAN  :
  5600.             /* Multinational: Latin-1   */
  5601.             /* National:      GR_ASCII  */
  5602.             dec_lang = y;
  5603.             dec_nrc = TX_GERMAN;
  5604.             dec_kbd = TX_8859_1;
  5605.             break;
  5606.           case VTL_DUTCH   :
  5607.             /* Multinational: Latin-1   */
  5608.             /* National:      DU_ASCII  */
  5609.             dec_lang = y;
  5610.             dec_nrc = TX_DUTCH;
  5611.             dec_kbd = TX_8859_1;
  5612.             break;
  5613.           case VTL_ITALIAN :
  5614.             /* Multinational: Latin-1   */
  5615.             /* National:      IT_ASCII  */
  5616.             dec_lang = y;
  5617.             dec_nrc = TX_ITALIAN;
  5618.             dec_kbd = TX_8859_1;
  5619.             break;
  5620.           case VTL_SW_FR   :
  5621.           case VTL_SW_GR   :
  5622.             /* Multinational: Latin-1   */
  5623.             /* National:      CH_ASCII  */
  5624.             dec_lang = y;
  5625.             dec_nrc = TX_SWISS;
  5626.             dec_kbd = TX_8859_1;
  5627.             break;
  5628.           case VTL_SWEDISH :
  5629.             /* Multinational: Latin-1   */
  5630.             /* National:      SW_ASCII  */
  5631.             dec_lang = y;
  5632.             dec_nrc = TX_SWEDISH;
  5633.             dec_kbd = TX_8859_1;
  5634.             break;
  5635.           case VTL_SPANISH :
  5636.             /* Multinational: Latin-1   */
  5637.             /* National:      SP_ASCII  */
  5638.             dec_lang = y;
  5639.             dec_nrc = TX_SPANISH;
  5640.             dec_kbd = TX_8859_1;
  5641.             break;
  5642.           case VTL_PORTUGES:
  5643.             /* Multinational: Latin-1   */
  5644.             /* National:      Portugese ASCII  */
  5645.             dec_lang = y;
  5646.             dec_nrc = TX_PORTUGUESE;
  5647.             dec_kbd = TX_8859_1;
  5648.             break;
  5649.           case VTL_HEBREW  :
  5650.             /* Multinational: Latin-Hebrew / DEC-Hebrew  */
  5651.             /* National:      DEC 7-bit Hebrew  */
  5652.             dec_lang = y;
  5653.             dec_nrc = TX_HE7;
  5654.             dec_kbd = TX_8859_8;
  5655.             break;
  5656.           case VTL_GREEK   :
  5657.             /* Multinational: Latin-Greek / DEC-Greek   */
  5658.             /* National:      DEC Greek NRC             */
  5659.             /* is ELOT927 equivalent to DEC Greek????   */
  5660.             dec_lang = y;
  5661.             dec_nrc = TX_ELOT927;
  5662.             dec_kbd = TX_8859_7;
  5663.             break;
  5664. #ifdef COMMENT
  5665.           case VTL_TURK_Q  :
  5666.           case VTL_TURK_F  :
  5667.             /* Multinational: Latin-Turkish / DEC-Turkish   */
  5668.             /* National:      DEC 7-bit Turkish             */
  5669.             break;
  5670. #endif /* COMMENT */
  5671.           case VTL_HUNGARIA:
  5672.             /* Multinational: Latin-2   */
  5673.             /* National:      no national mode  */
  5674.             dec_lang = y;
  5675.             dec_nrc = TX_HUNGARIAN;
  5676.             dec_kbd = TX_8859_2;
  5677.             break;
  5678.           case VTL_SLOVAK  :
  5679.           case VTL_CZECH   :
  5680.           case VTL_POLISH  :
  5681.           case VTL_ROMANIAN:
  5682.             /* Multinational: Latin-2   */
  5683.             /* National:      no national mode  */
  5684.             dec_lang = y;
  5685.             dec_nrc = TX_ASCII;
  5686.             dec_kbd = TX_8859_2;
  5687.             break;
  5688.           case VTL_RUSSIAN :
  5689.             /* Multinational: Latin-Cyrillic / KOI-8   */
  5690.             /* National:      DEC Russian NRC  */
  5691.             dec_lang = y;
  5692.             dec_nrc = TX_KOI7;
  5693.             dec_kbd = TX_8859_5;
  5694.             break;
  5695.           case VTL_LATIN_AM:
  5696.             /* Multinational: not listed in table   */
  5697.             /* National:      not listed in table  */
  5698.             dec_lang = y;
  5699.             dec_nrc = TX_ASCII;
  5700.             dec_kbd = TX_8859_1;
  5701.             break;
  5702. #ifdef COMMENT
  5703.           case VTL_SCS     :
  5704.             /* Multinational: Latin-2   */
  5705.             /* National:      SCS NRC   */
  5706.             break;
  5707. #endif /* COMMENT */
  5708.           default:
  5709.             return(success = 0);
  5710.         }
  5711.         if (IS97801(tt_type_mode)) {
  5712.             SNI_bitmode(cmask == 0377 ? 8 : 7);
  5713.         }
  5714.         return(success = 1);
  5715. #endif /* NOCSETS */
  5716.  
  5717.       case XYTVTNRC: {                  /* SET TERM DEC-NRC-MODE */
  5718.           extern int decnrcm_usr, decnrcm;        /* from ckoco3.c */
  5719.           if ((x = seton(&decnrcm_usr)) < 0)
  5720.             return(x);
  5721.           decnrcm = decnrcm_usr;
  5722.           return(success = 1);
  5723.       }
  5724.       case XYTSNIPM: {                  /* SET TERM SNI-PAGEMODE */
  5725.           extern int sni_pagemode, sni_pagemode_usr;
  5726.           if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5727.           if ((x = cmcfm()) < 0) return(x);
  5728.           sni_pagemode_usr = sni_pagemode = y;
  5729.           return(success = 1);
  5730.       }
  5731.       case XYTSNISM: {                  /* SET TERM SNI-SCROLLMODE */
  5732.           extern int sni_scroll_mode, sni_scroll_mode_usr;
  5733.           if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5734.           if ((x = cmcfm()) < 0) return(x);
  5735.           sni_scroll_mode_usr = sni_scroll_mode = y;
  5736.           return(success = 1);
  5737.       }
  5738.       case XYTSNICC: {  /* SET TERM SNI-CH.CODE */
  5739.           extern int sni_chcode_usr;
  5740.           if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5741.           if ((x = cmcfm()) < 0) return(x);
  5742.           sni_chcode_usr = y;
  5743.           SNI_chcode(y);
  5744.           return(success = 1);
  5745.       }
  5746.       case XYTSNIFV: {  /* SET TERM SNI-FIRMWARE-VERSIONS */
  5747.           extern CHAR sni_kbd_firmware[], sni_term_firmware[];
  5748.           CHAR kbd[7],term[7];
  5749.  
  5750.           if ((x = cmfld("Keyboard Firmware Version",sni_kbd_firmware,
  5751.                          &s, xxstring)) < 0)
  5752.             return(x);
  5753.           if ((int)strlen(s) != 6) {
  5754.               printf("?Sorry - the firmware version must be 6 digits long\n");
  5755.               return(-9);
  5756.           }
  5757.           for (i = 0; i < 6; i++) {
  5758.               if (!isdigit(s[i])) {
  5759.    printf("?Sorry - the firmware version can only contain digits [0-9]\n");
  5760.                   return(-9);
  5761.               }
  5762.           }
  5763.           ckstrncpy(kbd,s,7);
  5764.  
  5765.           if ((x = cmfld("Terminal Firmware Version",sni_term_firmware,
  5766.                          &s, xxstring)) < 0)
  5767.             return(x);
  5768.           if ((int)strlen(s) != 6) {
  5769.               printf("?Sorry - the firmware version must be 6 digits long\n");
  5770.               return(-9);
  5771.           }
  5772.           for (i = 0; i < 6; i++) {
  5773.               if (!isdigit(s[i])) {
  5774.    printf("?Sorry - the firmware version can only contain digits [0-9]\n");
  5775.                    return(-9);
  5776.               }
  5777.           }
  5778.           ckstrncpy(term,s,7);
  5779.           if ((x = cmcfm()) < 0) return(x);
  5780.  
  5781.           ckstrncpy(sni_kbd_firmware,kbd,7);
  5782.           ckstrncpy(sni_term_firmware,term,7);
  5783.           return(success = 1);
  5784.     }
  5785.  
  5786.     case XYTLSP: {              /* SET TERM LINE-SPACING */
  5787.         if ((x = cmfld("Line Spacing","1",&s, xxstring)) < 0)
  5788.           return(x);
  5789.         if (isfloat(s,0) < 1) {        /* (sets floatval) */
  5790.             printf("?Integer or floating-point number required\n");
  5791.             return(-9);
  5792.         }
  5793.         if (floatval < 1.0 || floatval > 3.0) {
  5794.             printf("?Value must within the range 1.0 and 3.0 (inclusive)\n");
  5795.             return(-9);
  5796.         }
  5797.         if ((x = cmcfm()) < 0) return(x);
  5798. #ifdef KUI
  5799.         tt_linespacing[VCMD] = tt_linespacing[VTERM] = floatval;
  5800.         return(success = 1);
  5801. #else /* KUI */
  5802.         printf("?Sorry, Line-spacing is only supported in K95G.EXE.\n");
  5803.         return(success = 0);
  5804. #endif /* KUI */
  5805.     }
  5806. #endif /* OS2 */
  5807.  
  5808.       default:                          /* Shouldn't get here. */
  5809.         return(-2);
  5810.     }
  5811. #endif /* MAC */
  5812. #ifdef COMMENT
  5813.     /*
  5814.       This was supposed to shut up picky compilers but instead it makes
  5815.       most compilers complain about "statement not reached".
  5816.     */
  5817.     return(-2);
  5818. #endif /* COMMENT */
  5819. #ifdef OS2
  5820. return(-2);
  5821. #endif /* OS2 */
  5822. }
  5823.  
  5824. #ifdef OS2
  5825. int
  5826. settitle(void) {
  5827.     extern char usertitle[];
  5828.     if ((y = cmtxt("title text","",&s,xxstring)) < 0)
  5829.       return(y);
  5830. #ifdef IKSD
  5831.     if (inserver) {
  5832.         printf("?Sorry, command disabled.\r\n");
  5833.         return(success = 0);
  5834.     }
  5835. #endif /* IKSD */
  5836.  
  5837.     ckstrncpy(usertitle,s,64);
  5838.     os2settitle("",1);
  5839.     return(1);
  5840. }
  5841.  
  5842. static struct keytab dialertab[] = {    /* K95 Dialer types */
  5843.     "backspace",        0, 0,
  5844.     "enter",            1, 0
  5845. };
  5846. static int ndialer = 2;
  5847.  
  5848. int
  5849. setdialer(void) {
  5850.     int t, x, y;
  5851.     int clear = 0, deflt = 0;
  5852.     int kc;                             /* Key code */
  5853.     char *s = NULL;                     /* Key binding */
  5854. #ifndef NOKVERBS
  5855.     char *p = NULL;                     /* Worker */
  5856. #endif /* NOKVERBS */
  5857.     con_event defevt;
  5858.     extern int os2gks;
  5859.     extern int mskkeys;
  5860.     extern int initvik;
  5861.  
  5862.     defevt.type = error;
  5863.  
  5864.     if (( x = cmkey(dialertab, ndialer,
  5865.                     "Kermit-95 dialer work-arounds",
  5866.                     "", xxstring)) < 0 )
  5867.       return(x);
  5868.     switch (x) {
  5869.       case 0:                           /* Backspace */
  5870.         kc = 264;
  5871.         break;
  5872.       case 1:                           /* Enter */
  5873.         kc = 269;
  5874.         break;
  5875.       default:
  5876.         printf("Illegal value in setdialer()\n");
  5877.         return(-9);
  5878.     }
  5879.     if ((y = cmtxt("Key definition","",&s,xxstring)) < 0)
  5880.       return(y);
  5881.  
  5882. #ifdef IKSD
  5883.     if (inserver) {
  5884.         printf("?Sorry, command disabled.\r\n");
  5885.         return(success = 0);
  5886.     }
  5887. #endif /* IKSD */
  5888.     s = brstrip(s);
  5889. #ifndef NOKVERBS
  5890.     p = s;                              /* Save this place */
  5891. #endif /* NOKVERBS */
  5892. /*
  5893.   If the definition included any \Kverbs, quote the backslash so the \Kverb
  5894.   will still be in the definition when the key is pressed.  We don't do this
  5895.   in zzstring(), because \Kverbs are valid only in this context and nowhere
  5896.   else.
  5897.  
  5898.   We use this code active for all versions that support SET KEY, even if they
  5899.   don't support \Kverbs, because otherwise \K would behave differently for
  5900.   different versions.
  5901. */
  5902.     for (x = 0, y = 0; s[x]; x++, y++) { /* Convert \K to \\K */
  5903.         if ((x > 0) &&
  5904.             (s[x] == 'K' || s[x] == 'k')
  5905.             ) {                         /* Have K */
  5906.  
  5907.             if ((x == 1 && s[x-1] == CMDQ) ||
  5908.                 (x > 1 && s[x-1] == CMDQ && s[x-2] != CMDQ)) {
  5909.                 line[y++] = CMDQ;       /* Make it \\K */
  5910.             }
  5911.             if (x > 1 && s[x-1] == '{' && s[x-2] == CMDQ) {
  5912.                 line[y-1] = CMDQ;       /* Have \{K */
  5913.                 line[y++] = '{';        /* Make it \\{K */
  5914.             }
  5915.         }
  5916.         line[y] = s[x];
  5917.     }
  5918.     line[y++] = NUL;                    /* Terminate */
  5919.     s = line + y + 1;                   /* Point to after it */
  5920.     x = LINBUFSIZ - (int) strlen(line) - 1; /* Calculate remaining space */
  5921.     if ((x < (LINBUFSIZ / 2)) ||
  5922.         (zzstring(line, &s, &x) < 0)) { /* Expand variables, etc. */
  5923.         printf("?Key definition too long\n");
  5924.         return(-9);
  5925.     }
  5926.     s = line + y + 1;                   /* Point to result. */
  5927.  
  5928. #ifndef NOKVERBS
  5929. /*
  5930.   Special case: see if the definition starts with a \Kverb.
  5931.   If it does, point to it with p, otherwise set p to NULL.
  5932. */
  5933.     p = s;
  5934.     if (*p++ == CMDQ) {
  5935.         if (*p == '{') p++;
  5936.         p = (*p == 'k' || *p == 'K') ? p + 1 : NULL;
  5937.     }
  5938. #endif /* NOKVERBS */
  5939.  
  5940.     /* Now reprogram the default value for all terminal types */
  5941.     /* remember to treat Wyse and Televideo terminals special */
  5942.     /* because of their use of Kverbs for Backspace and Enter */
  5943.     for (t = 0; t <= TT_MAX; t++) {
  5944.         if ( ISDG200(t) && kc == 264) {
  5945.             extern char * udkfkeys[] ;
  5946.             if (kc == 264) {            /* \Kdgbs */
  5947.                 if (udkfkeys[83])
  5948.                   free(udkfkeys[83]);
  5949.                 udkfkeys[83] = strdup(s);
  5950.             }
  5951.         } else if (ISWYSE(t) || ISTVI(t)) {
  5952.             extern char * udkfkeys[] ;
  5953.             if (kc == 264) {            /* \Kwybs or \Ktvibs */
  5954.                 if (udkfkeys[32])
  5955.                   free(udkfkeys[32]);
  5956.                 udkfkeys[32] = strdup(s);
  5957.             }
  5958.             if (kc == 269) {            /* \Kwyenter and \Kwyreturn */
  5959.                 if (udkfkeys[39])       /* \Ktvienter and \Ktvireturn */
  5960.                   free(udkfkeys[39]);
  5961.                 udkfkeys[39] = strdup(s);
  5962.                 if (udkfkeys[49])
  5963.                   free(udkfkeys[49]);
  5964.                 udkfkeys[49] = strdup(s);
  5965.             }
  5966.         } else {
  5967.             switch (strlen(s)) {        /* Action depends on length */
  5968.               case 0:                   /* Clear individual key def */
  5969.                 deletekeymap(t,kc);
  5970.                 break;
  5971.               case 1:
  5972.                 defevt.type = key;      /* Single character */
  5973.                 defevt.key.scancode = *s;
  5974.                 break;
  5975.               default:                  /* Character string */
  5976. #ifndef NOKVERBS
  5977.                 if (p) {
  5978.                     y = xlookup(kverbs,p,nkverbs,&x); /* Look it up */
  5979.                     /* Exact match req'd */
  5980.                     debug(F101,"set key kverb lookup",0,y);
  5981.                     if (y > -1) {
  5982.                         defevt.type = kverb;
  5983.                         defevt.kverb.id = y;
  5984.                         break;
  5985.                     }
  5986.                 }
  5987. #endif /* NOKVERBS */
  5988.                 defevt.type = macro;
  5989.                 defevt.macro.string = (char *) malloc(strlen(s)+1);
  5990.                 if (defevt.macro.string)
  5991.                   strcpy(defevt.macro.string, s); /* safe */
  5992.                 break;
  5993.             }
  5994.             insertkeymap( t, kc, defevt ) ;
  5995.             initvik = 1;                /* Update VIK table */
  5996.         }
  5997.     }
  5998.     return(1);
  5999. }
  6000. #endif /* OS2 */
  6001.  
  6002. #ifdef NT
  6003. int
  6004. setwin95( void ) {
  6005.     int x, y, z;
  6006.  
  6007.     if (( y = cmkey(win95tab, nwin95,
  6008.                     "Windows 95 specific work-arounds",
  6009.                     "keyboard-translation",
  6010.                     xxstring)) < 0 )
  6011.         return (y);
  6012.     switch (y) {
  6013.       case XYWPOPUP:
  6014.         if ((y = cmkey(onoff,2,"popups are used to prompt the user for data",
  6015.                        "on",xxstring)) < 0)
  6016.           return(y);
  6017.         if ((x = cmcfm()) < 0) return(x);
  6018.         win95_popup = y;
  6019.         return(1);
  6020.  
  6021.       case XYW8_3:
  6022.         if ((y = cmkey(onoff,2,"8.3 FAT file names","off",xxstring)) < 0)
  6023.           return(y);
  6024.         if ((x = cmcfm()) < 0) return(x);
  6025.         win95_8_3 = y;
  6026.         return(1);
  6027.  
  6028.       case XYWSELECT:
  6029.         if ((y = cmkey(onoff,2,"\"select()\" fails on write","off",
  6030.              xxstring)) < 0)
  6031.           return(y);
  6032.         if ((x = cmcfm()) < 0) return(x);
  6033.         win95selectbug = y;
  6034.         return(1);
  6035.  
  6036.       case XYWAGR:
  6037.         if ((y = cmkey(onoff,2,"Right-Alt is Alt-Gr","off",xxstring)) < 0)
  6038.           return(y);
  6039.         if ((x = cmcfm()) < 0) return(x);
  6040.         win95altgr = y;
  6041.         return(1);
  6042.  
  6043.       case XYWOIO:
  6044.         if ((y = cmkey(onoff,2,"Use Overlapped I/O","on",xxstring)) < 0)
  6045.           return(y);
  6046.         if (y) {
  6047.             if ((x = cmnum("Maximum number of outstanding I/O requests",
  6048.                            "10",10,&z,xxstring)) < 0)
  6049.               return(x);
  6050.             if (z < 1 || z > 30) {
  6051.                 printf(
  6052. "?Maximum outstanding I/O requests must be between 1 and 30.\n");
  6053.                 return(-9);
  6054.             }
  6055.         } else
  6056.           z = 1;
  6057.         if ((x = cmcfm()) < 0) return(x);
  6058.         owwait = !y;
  6059.         maxow = maxow_usr = z;
  6060.         return(1);
  6061.  
  6062.       case XYWKEY:
  6063. #ifndef COMMENT
  6064.         printf("\n?\"Keyboard-Translation\" is no longer required.\n");
  6065.         return(-9);
  6066. #else /* COMMENT */
  6067.         if (( z = cmkey(tcstab, ntcs,
  6068.                         "Keyboard Character Set",
  6069.                         "latin1-iso",
  6070.                         xxstring)) < 0)
  6071.           return (z);
  6072.         if ((x = cmcfm()) < 0)
  6073.           return(x);
  6074.  
  6075.         win95kcsi = z;
  6076.         win95kl2 = (win95kcsi == TC_2LATIN);
  6077.  
  6078.         if (win95kcsi == TC_TRANSP) {
  6079.             win95kcs = NULL;
  6080.         } else {
  6081. #ifdef UNICODE
  6082.             win95kcs = xlr[win95kcsi][tx2fc(tcsl)];
  6083. #else /* UNICODE */
  6084.             win95kcs = xlr[win95kcsi][tcsl];
  6085. #endif /* UNICODE */
  6086.         }
  6087.         return(1);
  6088. #endif /* COMMENT */
  6089.  
  6090.       case XYWLUC:
  6091.         if ((y = cmkey(onoff,2,"Unicode-to-Lucida-Console substitutions",
  6092.                        "on",xxstring)) < 0)
  6093.           return(y);
  6094.         if ((x = cmcfm()) < 0) return(x);
  6095.         win95lucida = y;
  6096.         return(1);
  6097.  
  6098.       case XYWHSL:
  6099.     if ((y = cmkey(onoff,2,"Horizontal Scan Line substitutions",
  6100.                "on",xxstring)) < 0)
  6101.       return(y);
  6102.     if ((x = cmcfm()) < 0) return(x);
  6103.     win95hsl = y;
  6104.     return(1);
  6105.  
  6106.       default:
  6107.         printf("Illegal value in setwin95()\n");
  6108.         return(-9);
  6109.     }
  6110. }
  6111. #endif /* NT */
  6112.  
  6113. #ifdef OS2
  6114. int
  6115. setprty (
  6116. #ifdef CK_ANSIC
  6117.     void
  6118. #endif /* CK_ANSIC */
  6119. /* setprty */ ) {
  6120.     int x, y, z;
  6121.  
  6122.     if (( y = cmkey(prtytab, nprty,
  6123.                     "priority level of terminal and communication threads",
  6124.                     "foreground-server",
  6125.                     xxstring)) < 0 )
  6126.       return (y);
  6127.  
  6128.     if ((x = cmcfm()) < 0)
  6129.       return (x);
  6130. #ifdef IKSD
  6131.     if (inserver &&
  6132. #ifdef IKSDCONF
  6133.          iksdcf
  6134. #else
  6135.          1
  6136. #endif /* IKSDCONF */
  6137.     ) {
  6138.         if ((y = cmcfm()) < 0) return(y);
  6139.         printf("?Sorry, command disabled.\r\n");
  6140.         return(success = 0);
  6141.     }
  6142. #endif /* IKSD */
  6143.     priority = y;
  6144.     return(TRUE);
  6145. }
  6146. #endif /* OS2 */
  6147.  
  6148. int
  6149. setbell() {
  6150.     int y, x;
  6151. #ifdef OS2
  6152.     int z;
  6153. #endif /* OS2 */
  6154.  
  6155.     if ((y = cmkey(beltab,nbeltab,
  6156. #ifdef OS2
  6157.         "how console and terminal bells should\nbe generated", "audible",
  6158. #else
  6159.         "Whether Kermit should ring the terminal bell (beep)", "on",
  6160. #endif /* OS2 */
  6161.                    xxstring)) < 0)
  6162.           return(y);
  6163.  
  6164. #ifdef IKSD
  6165.     if (inserver) {
  6166.         if ((y = cmcfm()) < 0) return(y);
  6167.         printf("?Sorry, command disabled.\r\n");
  6168.         return(success = 0);
  6169.     }
  6170. #endif /* IKSD */
  6171.  
  6172.     switch (y) {                        /* SET BELL */
  6173.       case XYB_NONE:
  6174. #ifdef OS2
  6175.       case XYB_VIS:
  6176. #endif /* OS2 */
  6177.         if ((x = cmcfm()) < 0)
  6178.           return(x);
  6179. #ifdef OS2
  6180.         tt_bell = y;
  6181. #else
  6182.         tt_bell = 0;
  6183. #endif /* OS2 */
  6184.         break;
  6185.  
  6186.       case XYB_AUD:
  6187. #ifdef OS2
  6188.         if ((x = cmkey(audibletab, naudibletab,
  6189.                "how audible console and terminal\nbells should be generated",
  6190.                        "beep",xxstring))<0)
  6191.           return(x);
  6192.         if ((z = cmcfm()) < 0)
  6193.           return(z);
  6194.         tt_bell = y | x;
  6195. #else
  6196.         /* This lets C-Kermit accept but ignore trailing K95 keywords */
  6197.         if ((x = cmtxt("Confirm with carriage return","",&s,xxstring)) < 0)
  6198.           return(x);
  6199.         tt_bell = 1;
  6200. #endif /* OS2 */
  6201.         break;
  6202.     }
  6203.     return(1);
  6204. }
  6205.  
  6206. #ifdef OS2MOUSE
  6207. int
  6208. setmou(
  6209. #ifdef CK_ANSIC
  6210.        void
  6211. #endif /* CK_ANSIC */
  6212.  /* setmou */ ) {
  6213.     extern int initvik;
  6214.     int button = 0, event = 0;
  6215.     char * p;
  6216.  
  6217.     if ((y = cmkey(mousetab,nmtab,"","",xxstring)) < 0)
  6218.       return(y);
  6219.  
  6220. #ifdef IKSD
  6221.     if (inserver) {
  6222.         if ((y = cmcfm()) < 0) return(y);
  6223.         printf("?Sorry, command disabled.\r\n");
  6224.         return(success = 0);
  6225.     }
  6226. #endif /* IKSD */
  6227.  
  6228.     if (y == XYM_ON) {                  /* MOUSE ACTIVATION */
  6229.         int old_mou = tt_mouse;
  6230.         if ((x = seton(&tt_mouse)) < 0)
  6231.             return(x);
  6232.         if (tt_mouse != old_mou)
  6233.           if (tt_mouse)
  6234.             os2_mouseon();
  6235.           else
  6236.             os2_mouseoff();
  6237.         return(1);
  6238.     }
  6239.  
  6240.     if (y == XYM_DEBUG) {               /* MOUSE DEBUG */
  6241.         extern int MouseDebug;
  6242.         if ((x = seton(&MouseDebug)) < 0)
  6243.             return(x);
  6244.         return(1);
  6245.     }
  6246.  
  6247.     if (y == XYM_CLEAR) {               /* Reset Mouse Defaults */
  6248.         if ((x = cmcfm()) < 0) return(x);
  6249.         mousemapinit(-1,-1);
  6250.         initvik = 1;                    /* Update VIK Table */
  6251.         return 1;
  6252.     }
  6253.     if (y != XYM_BUTTON) {              /* Shouldn't happen. */
  6254.         printf("Internal parsing error\n");
  6255.         return(-9);
  6256.     }
  6257.  
  6258.     /* MOUSE EVENT ... */
  6259.  
  6260.     if ((button = cmkey(mousebuttontab,nmbtab,
  6261.                         "Button number","1",
  6262.                         xxstring)) < 0)
  6263.       return(button);
  6264.  
  6265.     if ((y =  cmkey(mousemodtab,nmmtab,
  6266.                     "Keyboard modifier","none",
  6267.                     xxstring)) < 0)
  6268.       return(y);
  6269.  
  6270.     event |= y;                         /* OR in the bits */
  6271.  
  6272.     if ((y =  cmkey(mclicktab,nmctab,"","click",xxstring)) < 0)
  6273.       return(y);
  6274.  
  6275.     /* Two bits are assigned, if neither are set then it is button one */
  6276.  
  6277.     event |= y;                 /* OR in the bit */
  6278.  
  6279.     wideresult = -1;
  6280.  
  6281.     if ((y = cmtxt("definition,\n\
  6282. or Ctrl-C to cancel this command,\n\
  6283. or Enter to restore default definition",
  6284.                    "",&s,NULL)) < 0) {
  6285.         return(y);
  6286.     }
  6287.     s = brstrip(s);
  6288.     p = s;                              /* Save this place */
  6289. /*
  6290.   If the definition included any \Kverbs, quote the backslash so the \Kverb
  6291.   will still be in the definition when the key is pressed.  We don't do this
  6292.   in zzstring(), because \Kverbs are valid only in this context and nowhere
  6293.   else.  This code copied from SET KEY, q.v. for addt'l commentary.
  6294. */
  6295.     for (x = 0, y = 0; s[x]; x++, y++) { /* Convert \K to \\K */
  6296.         if ((x > 0) &&
  6297.             (s[x] == 'K' || s[x] == 'k')
  6298.             ) {                         /* Have K */
  6299.  
  6300.             if ((x == 1 && s[x-1] == CMDQ) ||
  6301.                 (x > 1 && s[x-1] == CMDQ && s[x-2] != CMDQ)) {
  6302.                 line[y++] = CMDQ;       /* Make it \\K */
  6303.             }
  6304.             if (x > 1 && s[x-1] == '{' && s[x-2] == CMDQ) {
  6305.                 line[y-1] = CMDQ;       /* Have \{K */
  6306.                 line[y++] = '{';        /* Make it \\{K */
  6307.             }
  6308.         }
  6309.         line[y] = s[x];
  6310.     }
  6311.     line[y++] = NUL;                    /* Terminate */
  6312.     s = line + y + 1;                   /* Point to after it */
  6313.     x = LINBUFSIZ - (int) strlen(line) - 1; /* Calculate remaining space */
  6314.     if ((x < (LINBUFSIZ / 2)) ||
  6315.         (zzstring(line, &s, &x) < 0)) { /* Expand variables, etc. */
  6316.         printf("?Key definition too long\n");
  6317.         return(-9);
  6318.     }
  6319.     s = line + y + 1;                   /* Point to result. */
  6320.  
  6321. #ifndef NOKVERBS
  6322. /*
  6323.   Special case: see if the definition starts with a \Kverb.
  6324.   If it does, point to it with p, otherwise set p to NULL.
  6325. */
  6326.     p = s;
  6327.     if (*p++ == CMDQ) {
  6328.         if (*p == '{') p++;
  6329.         p = (*p == 'k' || *p == 'K') ? p + 1 : NULL;
  6330.     }
  6331. #else
  6332.     p = NULL;
  6333. #endif /* NOKVERBS */
  6334.  
  6335.     /* free the old definition if necessary */
  6336.     if (mousemap[button][event].type == macro) {
  6337.         free( mousemap[button][event].macro.string);
  6338.         mousemap[button][event].macro.string = NULL;
  6339.     }
  6340.     switch (strlen(s)) {                /* Action depends on length */
  6341.       case 0:                           /* Reset to default binding */
  6342.         mousemapinit( button, event );
  6343.         break;
  6344.       case 1:                           /* Single character */
  6345.             mousemap[button][event].type = key;
  6346.         mousemap[button][event].key.scancode = *s;
  6347.         break;
  6348.       default:                          /* Character string */
  6349. #ifndef NOKVERBS
  6350.         if (p) {
  6351.             y = xlookup(kverbs,p,nkverbs,&x); /* Look it up */
  6352.             debug(F101,"set mouse kverb lookup",0,y); /* need exact match */
  6353.             if (y > -1) {
  6354.             /* Assign the kverb to the event */
  6355.             mousemap[button][event].type = kverb;
  6356.             mousemap[button][event].kverb.id = F_KVERB | y;
  6357.             break;
  6358.             }
  6359.         }
  6360. #endif /* NOKVERBS */
  6361.  
  6362.        /* Otherwise, it's a macro, so assign the macro to the event */
  6363.        mousemap[button][event].type = macro;
  6364.        mousemap[button][event].macro.string = (MACRO) malloc(strlen(s)+1);
  6365.        if (mousemap[button][event].macro.string)
  6366.          strcpy((char *) mousemap[button][event].macro.string, s); /* safe */
  6367.         break;
  6368.     }
  6369.     initvik = 1;                        /* Update VIK Table */
  6370.     if ( (button == XYM_B3) && (mousebuttoncount() < 3) && !quiet )
  6371.     {
  6372.         printf("?Warning: this machine does not have a three button mouse.\n");
  6373.         return(0);
  6374.     }
  6375.     return(1);
  6376. }
  6377. #endif /* OS2MOUSE */
  6378. #endif /* NOLOCAL */
  6379.  
  6380. #ifndef NOXFER
  6381. int                                     /* SET SEND/RECEIVE */
  6382. setsr(xx, rmsflg) int xx; int rmsflg; {
  6383.     if (xx == XYRECV)
  6384.       ckstrncpy(line,"Parameter for inbound packets",LINBUFSIZ);
  6385.     else
  6386.       ckstrncpy(line,"Parameter for outbound packets",LINBUFSIZ);
  6387.  
  6388.     if (rmsflg) {
  6389.         if ((y = cmkey(rsrtab,nrsrtab,line,"",xxstring)) < 0) {
  6390.             if (y == -3) {
  6391.                 printf("?Remote receive parameter required\n");
  6392.                 return(-9);
  6393.             } else return(y);
  6394.         }
  6395.     } else {
  6396.         if ((y = cmkey(srtab,nsrtab,line,"",xxstring)) < 0) return(y);
  6397.     }
  6398.     switch (y) {
  6399.       case XYQCTL:                      /* CONTROL-PREFIX */
  6400.         if ((x = cmnum("ASCII value of control prefix","",10,&y,xxstring)) < 0)
  6401.           return(x);
  6402.         if ((x = cmcfm()) < 0) return(x);
  6403.         if ((y > 32 && y < 63) || (y > 95 && y < 127)) {
  6404.             if (xx == XYRECV)
  6405.               ctlq = (CHAR) y;          /* RECEIVE prefix, use with caution! */
  6406.             else
  6407.               myctlq = (CHAR) y;        /* SEND prefix, OK to change */
  6408.             return(success = 1);
  6409.         } else {
  6410.             printf("?Illegal value for prefix character\n");
  6411.             return(-9);
  6412.         }
  6413.  
  6414.       case XYEOL:
  6415.         if ((y = setcc("13",&z)) < 0)
  6416.             return(y);
  6417.         if (z > 31) {
  6418.             printf("Sorry, the legal values are 0-31\n");
  6419.             return(-9);
  6420.         }
  6421.         if (xx == XYRECV)
  6422.           eol = (CHAR) z;
  6423.         else
  6424.           seol = (CHAR) z;
  6425.         return(success = y);
  6426.  
  6427.       case XYLEN:
  6428.         y = cmnum("Maximum number of characters in a packet","90",10,&x,
  6429.                   xxstring);
  6430.         if (xx == XYRECV) {             /* Receive... */
  6431.             if ((y = setnum(&z,x,y,maxrps)) < 0)
  6432.               return(y);
  6433.             if (protocol != PROTO_K) {
  6434.                 printf("?Sorry, this command does not apply to %s protocol.\n",
  6435.                        ptab[protocol].p_name
  6436.                        );
  6437.                 printf("Use SET SEND PACKET-LENGTH for XYZMODEM\n");
  6438.                 return(-9);
  6439.             }
  6440.             if (z < 10) {
  6441.                 printf("Sorry, 10 is the minimum\n");
  6442.                 return(-9);
  6443.             }
  6444.             if (rmsflg) {
  6445.                 sstate = setgen('S', "401", ckitoa(z), "");
  6446.                 return((int) sstate);
  6447.             } else {
  6448.                 if (protocol == PROTO_K) {
  6449.                     if (z > MAXRP) z = MAXRP;
  6450.                     y = adjpkl(z,wslotr,bigrbsiz);
  6451.                     if (y != z) {
  6452.                         urpsiz = y;
  6453.                         if (!xcmdsrc)
  6454.                           if (msgflg) printf(
  6455. " Adjusting receive packet-length to %d for %d window slots\n",
  6456.                                              y, wslotr);
  6457.                     }
  6458.                     urpsiz = y;
  6459.                     ptab[protocol].rpktlen = urpsiz;
  6460.                     rpsiz =  (y > 94) ? 94 : y;
  6461.                 } else {
  6462. #ifdef CK_XYZ
  6463.                     if ((protocol == PROTO_X || protocol == PROTO_XC) &&
  6464.                          z != 128 && z != 1024) {
  6465.                         printf("Sorry, bad packet length for XMODEM.\n");
  6466.                         printf("Please use 128 or 1024.\n");
  6467.                         return(-9);
  6468.                     }
  6469. #endif /* CK_XYZ */
  6470.                     urpsiz = rpsiz = z;
  6471.                 }
  6472.             }
  6473.         } else {                        /* Send... */
  6474.             if ((y = setnum(&z,x,y,maxsps)) < 0)
  6475.               return(y);
  6476.             if (z < 10) {
  6477.                 printf("Sorry, 10 is the minimum\n");
  6478.                 return(-9);
  6479.             }
  6480.             if (protocol == PROTO_K) {
  6481.                 if (z > MAXSP) z = MAXSP;
  6482.                 spsiz = z;              /* Set it */
  6483.                 y = adjpkl(spsiz,wslotr,bigsbsiz);
  6484.                 if (y != spsiz && !xcmdsrc)
  6485.                   if (msgflg)
  6486.                     printf("Adjusting packet size to %d for %d window slots\n",
  6487.                            y,wslotr);
  6488.             } else
  6489.               y = z;
  6490. #ifdef CK_XYZ
  6491.             if ((protocol == PROTO_X || protocol == PROTO_XC) &&
  6492.                  z != 128 && z != 1024) {
  6493.                 printf("Sorry, bad packet length for XMODEM.\n");
  6494.                 printf("Please use 128 or 1024.\n");
  6495.                 return(-9);
  6496.             }
  6497. #endif /* CK_XYZ */
  6498.             spsiz = spmax = spsizr = y; /* Set it and flag that it was set */
  6499.             spsizf = 1;                 /* to allow overriding Send-Init. */
  6500.             ptab[protocol].spktflg = spsizf;
  6501.             ptab[protocol].spktlen = spsiz;
  6502.         }
  6503.         if (pflag && protocol == PROTO_K && !xcmdsrc) {
  6504.             if (z > 94 && !reliable && msgflg) {
  6505.                 /* printf("Extended-length packets requested.\n"); */
  6506.                 if (bctr < 2 && z > 200) printf("\
  6507. Remember to SET BLOCK 2 or 3 for long packets.\n");
  6508.             }
  6509.             if (speed <= 0L) speed = ttgspd();
  6510. #ifdef COMMENT
  6511. /*
  6512.   Kermit does this now itself.
  6513. */
  6514.             if (speed <= 0L && z > 200 && msgflg) {
  6515.                 printf("\
  6516. Make sure your timeout interval is long enough for %d-byte packets.\n",z);
  6517.             }
  6518. #endif /* COMMENT */
  6519.         }
  6520.         return(success = y);
  6521.  
  6522.       case XYMARK:
  6523. #ifdef DOOMSDAY
  6524. /*
  6525.   Printable start-of-packet works for UNIX and VMS only!
  6526. */
  6527.         x_ifnum = 1;
  6528.         y = cmnum("Code for packet-start character","1",10,&x,xxstring);
  6529.         x_ifnum = 0;
  6530.         if ((y = setnum(&z,x,y,126)) < 0) return(y);
  6531. #else
  6532.         if ((y = setcc("1",&z)) < 0)
  6533.             return(y);
  6534. #endif /* DOOMSDAY */
  6535.         if (xx == XYRECV)
  6536.           stchr = (CHAR) z;
  6537.         else {
  6538.             mystch = (CHAR) z;
  6539. #ifdef IKS_OPTION
  6540.             /* If IKS negotiation in use   */
  6541.             if (TELOPT_U(TELOPT_KERMIT) || TELOPT_ME(TELOPT_KERMIT))
  6542.               tn_siks(KERMIT_SOP);      /* Report change to other side */
  6543. #endif /* IKS_OPTION */
  6544.         }
  6545.         return(success = y);
  6546.  
  6547.       case XYNPAD:                      /* PADDING */
  6548.         y = cmnum("How many padding characters for inbound packets","0",10,&x,
  6549.                   xxstring);
  6550.         if ((y = setnum(&z,x,y,94)) < 0) return(y);
  6551.         if (xx == XYRECV)
  6552.           mypadn = (CHAR) z;
  6553.         else
  6554.           npad = (CHAR) z;
  6555.         return(success = y);
  6556.  
  6557.       case XYPADC:                      /* PAD-CHARACTER */
  6558.         if ((y = setcc("0",&z)) < 0) return(y);
  6559.         if (xx == XYRECV) mypadc = z; else padch = z;
  6560.         return(success = y);
  6561.  
  6562.       case XYTIMO:                      /* TIMEOUT */
  6563.         if (xx == XYRECV) {
  6564.             y = cmnum("Packet timeout interval",ckitoa(URTIME),10,&x,xxstring);
  6565.             if ((y = setnum(&z,x,y,94)) < 0) return(y);
  6566.  
  6567.             if (rmsflg) {               /* REMOTE SET RECEIVE TIMEOUT */
  6568.                 sstate = setgen('S', "402", ckitoa(z), "");
  6569.                 return((int) sstate);
  6570.             } else {                    /* SET RECEIVE TIMEOUT */
  6571.                 pkttim = z;             /*   Value to put in my negotiation */
  6572.             }                           /*   packet for other Kermit to use */
  6573.  
  6574.         } else {                        /* SET SEND TIMEOUT */
  6575. #ifdef CK_TIMERS
  6576.             extern int rttflg, mintime, maxtime;
  6577.             int tmin = 0, tmax = 0;
  6578. #endif /* CK_TIMERS */
  6579.             y = cmnum("Packet timeout interval",ckitoa(DMYTIM),10,&x,xxstring);
  6580.             if (y == -3) {              /* They cancelled a previous */
  6581.                 x = DMYTIM;             /* SET SEND command, so restore */
  6582.                 timef = 0;              /* and turn off the override flag */
  6583.                 y = cmcfm();
  6584.             }
  6585. #ifdef CK_TIMERS
  6586.             if (y < 0) return(y);
  6587.             if (x < 0) {
  6588.                 printf("?Out of range - %d\n",x);
  6589.                 return(-9);
  6590.             }
  6591.             if ((z = cmkey(timotab,2,"","dynamic",xxstring)) < 0) return(z);
  6592.             if (z) {
  6593.                 if ((y = cmnum("Minimum timeout to allow",
  6594.                                "1",10,&tmin,xxstring)) < 0)
  6595.                   return(y);
  6596.                 if (tmin < 1) {
  6597.                     printf("?Out of range - %d\n",tmin);
  6598.                     return(-9);
  6599.                 }
  6600.                 if ((y = cmnum("Maximum timeout to allow",
  6601.                                "0",10,&tmax,xxstring)) < 0)
  6602.                   return(y);
  6603.                 /* 0 means let Kermit choose, < 0 means no maximum */
  6604.             }
  6605.             if ((y = cmcfm()) < 0)
  6606.               return(y);
  6607.             rttflg = z;                 /* Round-trip timer flag */
  6608.             z = x;
  6609. #else
  6610.             if ((y = setnum(&z,x,y,94)) < 0)
  6611.               return(y);
  6612. #endif /* CK_TIMERS */
  6613.             timef = 1;                  /* Turn on the override flag */
  6614.             timint = rtimo = z;         /* Override value for me to use */
  6615. #ifdef CK_TIMERS
  6616.             if (rttflg) {               /* Lower and upper bounds */
  6617.                 mintime = tmin;
  6618.                 maxtime = tmax;
  6619.             }
  6620. #endif /* CK_TIMERS */
  6621.         }
  6622.         return(success = 1);
  6623.  
  6624.       case XYFPATH:                     /* PATHNAMES */
  6625.         if (xx == XYRECV) {
  6626.             y = cmkey(rpathtab,nrpathtab,"","auto",xxstring);
  6627.         } else {
  6628.             y = cmkey(pathtab,npathtab,"","off",xxstring);
  6629.         }
  6630.         if (y < 0) return(y);
  6631.  
  6632.         if ((x = cmcfm()) < 0) return(x);
  6633.         if (xx == XYRECV) {             /* SET RECEIVE PATHNAMES */
  6634.             fnrpath = y;
  6635.             ptab[protocol].fnrp = fnrpath;
  6636.         } else {                        /* SET SEND PATHNAMES */
  6637.             fnspath = y;
  6638.             ptab[protocol].fnsp = fnspath;
  6639.         }
  6640.         return(success = 1);            /* Note: 0 = ON, 1 = OFF */
  6641.         /* In other words, ON = leave pathnames ON, OFF = take them off. */
  6642.  
  6643.       case XYPAUS:                      /* SET SEND/RECEIVE PAUSE */
  6644.         y = cmnum("Milliseconds to pause between packets","0",10,&x,xxstring);
  6645.         if ((y = setnum(&z,x,y,15000)) < 0)
  6646.           return(y);
  6647.         pktpaus = z;
  6648.         return(success = 1);
  6649.  
  6650. #ifdef CKXXCHAR                         /* SET SEND/RECEIVE IGNORE/DOUBLE */
  6651.       case XYIGN:
  6652.       case XYDBL: {
  6653.           int i, zz;
  6654.           short *p;
  6655.           extern short dblt[];
  6656.           extern int dblflag, ignflag;
  6657.  
  6658.           /* Make space for a temporary copy of the ignore/double table */
  6659.  
  6660.           zz = y;
  6661. #ifdef COMMENT
  6662.           if (zz == XYIGN && xx == XYSEND) {
  6663.               blah blah who cares
  6664.           }
  6665.           if (zz == XYDBL && xx == XYRECV) {
  6666.               blah blah
  6667.           }
  6668. #endif /* COMMENT */
  6669.           p = (short *)malloc(256 * sizeof(short));
  6670.           if (!p) {
  6671.               printf("?Internal error - malloc failure\n");
  6672.               return(-9);
  6673.           }
  6674.           for (i = 0; i < 256; i++) p[i] = dblt[i]; /* Copy current table */
  6675.  
  6676.           while (1) {                   /* Collect a list of numbers */
  6677. #ifndef NOSPL
  6678.               x_ifnum = 1;              /* Turn off complaints from eval() */
  6679. #endif /* NOSPL */
  6680.               if ((x = cmnum(zz == XYDBL ?
  6681.                              "Character to double" :
  6682.                              "Character to ignore",
  6683.                              "",10,&y,xxstring
  6684.                              )) < 0) {
  6685. #ifndef NOSPL
  6686.                   x_ifnum = 0;
  6687. #endif /* NOSPL */
  6688.                   if (x == -3)          /* Done */
  6689.                     break;
  6690.                   if (x == -2) {
  6691.                       if (p) { free(p); p = NULL; }
  6692.                       debug(F110,"SET S/R DOUBLE/IGNORE atmbuf",atmbuf,0);
  6693.                       if (!ckstrcmp(atmbuf,"none",4,0) ||
  6694.                           !ckstrcmp(atmbuf,"non",3,0) ||
  6695.                           !ckstrcmp(atmbuf,"no",2,0) ||
  6696.                           !ckstrcmp(atmbuf,"n",1,0)) {
  6697.                           if ((x = cmcfm()) < 0) /* Get confirmation */
  6698.                             return(x);
  6699.                           for (y = 0; y < 256; y++)
  6700.                             dblt[y] &= (zz == XYDBL) ? 1 : 2;
  6701.                           if (zz == XYDBL) dblflag = 0;
  6702.                           if (zz == XYIGN) ignflag = 0;
  6703.                           return(success = 1);
  6704.                       } else {
  6705.                           printf(
  6706.                             "?Please specify a number or the word NONE\n");
  6707.                           return(-9);
  6708.                       }
  6709.                   } else {
  6710.                       free(p);
  6711.                       p = NULL;
  6712.                       return(x);
  6713.                   }
  6714.               }
  6715. #ifndef NOSPL
  6716.               x_ifnum = 0;
  6717. #endif /* NOSPL */
  6718.               if (y < 0 || y > 255) {
  6719.                   printf("?Please enter a character code in range 0-255\n");
  6720.                   free(p);
  6721.                   p = NULL;
  6722.                   return(-9);
  6723.               }
  6724.               p[y] |= (zz == XYDBL) ? 2 : 1;
  6725.               if (zz == XYDBL) dblflag = 1;
  6726.               if (zz == XYIGN) ignflag = 1;
  6727.           } /* End of while loop */
  6728.  
  6729.           if ((x = cmcfm()) < 0) return(x);
  6730. /*
  6731.   Get here only if they have made no mistakes.  Copy temporary table back to
  6732.   permanent one, then free temporary table and return successfully.
  6733. */
  6734.           if (p) {
  6735.               for (i = 0; i < 256; i++) dblt[i] = p[i];
  6736.               free(p);
  6737.               p = NULL;
  6738.           }
  6739.           return(success = 1);
  6740.       }
  6741. #endif /* CKXXCHAR */
  6742.  
  6743. #ifdef PIPESEND
  6744.       case XYFLTR: {                    /* SET { SEND, RECEIVE } FILTER */
  6745.           if ((y = cmtxt((xx == XYSEND) ?
  6746.                 "Filter program for sending files -\n\
  6747.  use \\v(filename) to substitute filename" :
  6748.                 "Filter program for receiving files -\n\
  6749.  use \\v(filename) to substitute filename",
  6750.                          "",&s,NULL)) < 0)
  6751.             return(y);
  6752.           if (!*s) {                    /* Removing a filter... */
  6753.               if (xx == XYSEND && sndfilter) {
  6754.                   makestr(&g_sfilter,NULL);
  6755.                   makestr(&sndfilter,NULL);
  6756.               } else if (rcvfilter) {
  6757.                   makestr(&g_rfilter,NULL);
  6758.                   makestr(&rcvfilter,NULL);
  6759.               }
  6760.               return(success = 1);
  6761.           }                             /* Adding a filter... */
  6762.           s = brstrip(s);               /* Strip any braces */
  6763.           y = strlen(s);
  6764.           if (xx == XYSEND) {           /* For SEND filter... */
  6765.               for (x = 0; x < y; x++) { /* make sure they included "\v(...)" */
  6766.                   if (s[x] != '\\') continue;
  6767.                   if (s[x+1] == 'v') break;
  6768.               }
  6769.               if (x == y) {
  6770.                   printf(
  6771.               "?Filter must contain a replacement variable for filename.\n"
  6772.                          );
  6773.                   return(-9);
  6774.               }
  6775.           }
  6776.           if (xx == XYSEND) {
  6777.               makestr(&sndfilter,s);
  6778.               makestr(&g_sfilter,s);
  6779.           } else {
  6780.               makestr(&rcvfilter,s);
  6781.               makestr(&g_rfilter,s);
  6782.           }
  6783.           return(success = 1);
  6784.       }
  6785. #endif /* PIPESEND */
  6786.  
  6787.       case XYINIL:
  6788.         y = cmnum("Max length for protocol init string","-1",10,&x,xxstring);
  6789.         if ((y = setnum(&z,x,y,-1)) < 0)
  6790.           return(y);
  6791.         if (xx == XYSEND)
  6792.           sprmlen = z;
  6793.         else
  6794.           rprmlen = z;
  6795.         return(success = 1);
  6796.  
  6797.       case 993: {
  6798.           extern int sendipkts;
  6799.           if (xx == XYSEND) {
  6800.               if ((x = seton(&sendipkts)) < 0)
  6801.                 return(x);
  6802.           }
  6803.           return(1);
  6804.       }
  6805. #ifdef CK_PERMS
  6806.       case 994:
  6807.     switch(xx) {
  6808.       case XYSEND:
  6809.         if ((x = seton(&atlpro)) < 0) return(x);
  6810.         atgpro = atlpro;
  6811.         return(1);
  6812.       case XYRECV:
  6813.         if ((x = seton(&atlpri)) < 0) return(x);
  6814.         atgpri = atlpri;
  6815.         return(1);
  6816.       default:
  6817.         return(-2);
  6818.     }
  6819. #endif /* CK_PERMS */
  6820.  
  6821. #ifndef NOCSETS
  6822.       case XYCSET: {                    /* CHARACTER-SET-SELECTION */
  6823.           extern struct keytab xfrmtab[];
  6824.           extern int r_cset, s_cset;
  6825.           if ((y = cmkey(xfrmtab,2,"","automatic",xxstring)) < 0)
  6826.             return(y);
  6827.           if ((x = cmcfm()) < 0)
  6828.             return(x);
  6829.           if (xx == XYSEND)
  6830.             s_cset = y;
  6831.           else
  6832.             r_cset = y;
  6833.           return(success = 1);
  6834.       }
  6835. #endif /* NOCSETS */
  6836.  
  6837.       case XYBUP:
  6838.         if ((y = cmkey(onoff,2,"","on",xxstring)) < 0)
  6839.           return(y);
  6840.         if ((x = cmcfm()) < 0) return(x);
  6841.         if (xx == XYSEND) {
  6842.             extern int skipbup;
  6843.             skipbup = (y == 0) ? 1 : 0;
  6844.             return(success = 1);
  6845.         } else {
  6846.             printf(
  6847. "?Please use SET FILE COLLISION to choose the desired action\n");
  6848.             return(-9);
  6849.         }
  6850.  
  6851.       case XYMOVE:
  6852.         y = cmdir("Directory to move file(s) to after successful transfer",
  6853.                   "",&s,xxstring);
  6854.         if (y < 0 && y != -3)
  6855.           return(y);
  6856.         ckstrncpy(line,s,LINBUFSIZ);
  6857.         s = brstrip(line);
  6858.         if ((x = cmcfm()) < 0)
  6859.           return(x);
  6860.         if (xx == XYSEND) {
  6861.             if (*s) {
  6862.                 zfnqfp(s,LINBUFSIZ,line);
  6863.                 makestr(&snd_move,line);
  6864.                 makestr(&g_snd_move,line);
  6865.             } else {
  6866.                 makestr(&snd_move,NULL);
  6867.                 makestr(&g_snd_move,NULL);
  6868.             }
  6869.         } else {
  6870.             if (*s) {
  6871.                 zfnqfp(s,LINBUFSIZ,line);
  6872.                 makestr(&rcv_move,line);
  6873.                 makestr(&g_rcv_move,line);
  6874.             } else {
  6875.                 makestr(&rcv_move,NULL);
  6876.                 makestr(&g_rcv_move,NULL);
  6877.             }
  6878.         }
  6879.         return(success = 1);
  6880.  
  6881.       case XYRENAME:
  6882.         y = cmdir("Template to rename file(s) to after successful transfer",
  6883.                   "",&s,NULL);
  6884.         if (y < 0 && y != -3)
  6885.           return(y);
  6886.         ckstrncpy(line,s,LINBUFSIZ);
  6887.         s = brstrip(line);
  6888.         if ((x = cmcfm()) < 0)
  6889.           return(x);
  6890.         if (xx == XYSEND) {
  6891.             if (*s) {
  6892.                 makestr(&snd_rename,s);
  6893.                 makestr(&g_snd_rename,s);
  6894.             } else {
  6895.                 makestr(&snd_rename,NULL);
  6896.                 makestr(&g_snd_rename,NULL);
  6897.             }
  6898.         } else {
  6899.             if (*s) {
  6900.                 makestr(&rcv_rename,s);
  6901.                 makestr(&g_rcv_rename,s);
  6902.             } else {
  6903.                 makestr(&rcv_rename,NULL);
  6904.                 makestr(&g_rcv_rename,NULL);
  6905.             }
  6906.         }
  6907.         return(success = 1);
  6908.  
  6909. #ifdef VMS
  6910.       case 887:                 /* VERSION-NUMBERS */
  6911.         if (xx == XYSEND) {
  6912.             extern int vmssversions;
  6913.             return(seton(&vmssversions));
  6914.         } else {
  6915.             extern int vmsrversions;
  6916.             return(seton(&vmsrversions));
  6917.         }
  6918. #endif /* VMS */
  6919.  
  6920.       default:
  6921.         return(-2);
  6922.     }                                   /* End of SET SEND/RECEIVE... */
  6923. }
  6924. #endif /* NOXFER */
  6925.  
  6926. #ifndef NOXMIT
  6927. int
  6928. setxmit() {
  6929.     if ((y = cmkey(xmitab,nxmit,"","",xxstring)) < 0) return(y);
  6930.     switch (y) {
  6931.       case XMITE:                       /* EOF */
  6932.         y = cmtxt("Characters to send at end of file,\n\
  6933.  Use backslash codes for control characters","",&s,xxstring);
  6934.         if (y < 0) return(y);
  6935.         if ((int)strlen(s) > XMBUFL) {
  6936.             printf("?Too many characters, %d maximum\n",XMBUFL);
  6937.             return(-2);
  6938.         }
  6939.         ckstrncpy(xmitbuf,s,XMBUFL);
  6940.         return(success = 1);
  6941.  
  6942.       case XMITF:                       /* Fill */
  6943.         y = cmnum("Numeric code for blank-line fill character","0",10,&x,
  6944.                   xxstring);
  6945.         if ((y = setnum(&z,x,y,127)) < 0) return(y);
  6946.         xmitf = z;
  6947.         return(success = 1);
  6948.       case XMITL:                       /* Linefeed */
  6949.         return(seton(&xmitl));
  6950.       case XMITS:                       /* Locking-Shift */
  6951.         return(seton(&xmits));
  6952.       case XMITP:                       /* Prompt */
  6953.         y = cmnum("Numeric code for host's prompt character, 0 for none",
  6954.                   "10",10,&x,xxstring);
  6955.         if ((y = setnum(&z,x,y,127)) < 0) return(y);
  6956.         xmitp = z;
  6957.         return(success = 1);
  6958.       case XMITX:                       /* Echo */
  6959.         return(seton(&xmitx));
  6960.       case XMITW:                       /* Pause */
  6961.         y = cmnum("Number of milliseconds to pause between binary characters\n\
  6962. or text lines during transmission","0",10,&x,xxstring);
  6963.         if ((y = setnum(&z,x,y,1000)) < 0) return(y);
  6964.         xmitw = z;
  6965.         return(success = 1);
  6966.       case XMITT:                       /* Timeout */
  6967.         y = cmnum("Seconds to wait for each character to echo",
  6968.                   "1",10,&x,xxstring);
  6969.         if ((y = setnum(&z,x,y,1000)) < 0) return(y);
  6970.         xmitt = z;
  6971.         return(success = 1);
  6972.       default:
  6973.         return(-2);
  6974.     }
  6975. }
  6976. #endif /* NOXMIT */
  6977.  
  6978. #ifndef NOXFER
  6979. /*  D O R M T  --  Do a remote command  */
  6980.  
  6981. VOID
  6982. rmsg() {
  6983.     if (pflag && !quiet && fdispla != XYFD_N)
  6984.       printf(
  6985. #ifdef CK_NEED_SIG
  6986.        " Type your escape character, %s, followed by X or E to cancel.\n",
  6987.        dbchr(escape)
  6988. #else
  6989.        " Press the X or E key to cancel.\n"
  6990. #endif /* CK_NEED_SIG */
  6991.       );
  6992. }
  6993.  
  6994. static int xzcmd = 0;                   /* Global copy of REMOTE cmd index */
  6995.  
  6996. /*  R E M C F M  --  Confirm a REMOTE command  */
  6997. /*
  6998.   Like cmcfm(), but allows for a redirection indicator on the end,
  6999.   like "> filename" or "| command".  Returns what cmcfm() would have
  7000.   returned: -1 if reparse needed, etc etc blah blah.  On success,
  7001.   returns 1 with:
  7002.  
  7003.     char * remdest containing the name of the file or command.
  7004.     int remfile set to 1 if there is to be any redirection.
  7005.     int remappd set to 1 if output file is to be appended to.
  7006.     int rempipe set to 1 if remdest is a command, 0 if it is a file.
  7007. */
  7008. static int
  7009. remcfm() {
  7010.     int x;
  7011.     char *s;
  7012.     char c;
  7013.  
  7014.     remfile = 0;
  7015.     rempipe = 0;
  7016.     remappd = 0;
  7017.  
  7018.     if ((x = cmtxt(
  7019.              "> filename, | command,\n\
  7020. or type carriage return to confirm the command",
  7021.                    "",&s,xxstring)) < 0)
  7022.       return(x);
  7023.     if (remdest) {
  7024.         free(remdest);
  7025.         remdest = NULL;
  7026.     }
  7027.     debug(F101,"remcfm local","",local);
  7028.     debug(F110,"remcfm s",s,0);
  7029.     debug(F101,"remcfm cmd","",xzcmd);
  7030.  
  7031.     if (!*s) {                          /* No redirection indicator */
  7032.         if (!local &&
  7033.             (xzcmd == XZDIR || xzcmd == XZTYP ||
  7034.              xzcmd == XZXIT || xzcmd == XZSPA ||
  7035.              xzcmd == XZHLP || xzcmd == XZPWD ||
  7036.              xzcmd == XZLGI || xzcmd == XZLGO ||
  7037.              xzcmd == XZWHO || xzcmd == XZHOS)) {
  7038.             printf("?\"%s\" has no effect in remote mode\n",cmdbuf);
  7039.             return(-9);
  7040.         } else
  7041.           return(1);
  7042.     }
  7043.     c = *s;                             /* We have something */
  7044.     if (c != '>' && c != '|') {         /* Is it > or | ? */
  7045.         printf("?Not confirmed\n");     /* No */
  7046.         return(-9);
  7047.     }
  7048.     s++;                                /* See what follows */
  7049.     if (c == '>' && *s == '>') {        /* Allow for ">>" too */
  7050.         s++;
  7051.         remappd = 1;                    /* Append to output file */
  7052.     }
  7053.     while (*s == SP || *s == HT) s++;   /* Strip intervening whitespace */
  7054.     if (!*s) {
  7055.         printf("?%s missing\n", c == '>' ? "Filename" : "Command");
  7056.         return(-9);
  7057.     }
  7058.     if (c == '>' && zchko(s) < 0) {     /* Check accessibility */
  7059.         printf("?Access denied - %s\n", s);
  7060.         return(-9);
  7061.     }
  7062.     remfile = 1;                        /* Set global results */
  7063.     rempipe = (c == '|');
  7064.     if (rempipe
  7065. #ifndef NOPUSH
  7066.         && nopush
  7067. #endif /* NOPUSH */
  7068.         ) {
  7069.         printf("?Sorry, access to external commands is disabled.\n");
  7070.         return(-9);
  7071.     }
  7072.     makestr(&remdest,s);
  7073. #ifndef NODEBUG
  7074.     if (deblog) {
  7075.         debug(F101,"remcfm remfile","",remfile);
  7076.         debug(F101,"remcfm remappd","",remappd);
  7077.         debug(F101,"remcfm rempipe","",rempipe);
  7078.         debug(F110,"remcfm remdest",remdest, 0);
  7079.     }
  7080. #endif /* NODEBUG */
  7081.     return(1);
  7082. }
  7083.  
  7084. /*  R E M T X T  --  Like remcfm()...  */
  7085. /*
  7086.    ... but for REMOTE commands that end with cmtxt().
  7087.    Here we must decipher braces to discover whether the trailing
  7088.    redirection indicator is intended for local use, or to be sent out
  7089.    to the server, as in:
  7090.  
  7091.      remote host blah blah > file                 This end
  7092.      remote host { blah blah } > file             This end
  7093.      remote host { blah blah > file }             That end
  7094.      remote host { blah blah > file } > file      Both ends
  7095.  
  7096.    Pipes too:
  7097.  
  7098.      remote host blah blah | cmd                  This end
  7099.      remote host { blah blah } | cmd              This end
  7100.      remote host { blah blah | cmd }              That end
  7101.      remote host { blah blah | cmd } | cmd        Both ends
  7102.  
  7103.    Or both:
  7104.  
  7105.      remote host blah blah | cmd > file           This end, etc etc...
  7106.  
  7107.    Note: this really only makes sense for REMOTE HOST, but why be picky?
  7108.    Call after calling cmtxt(), with pointer to string that cmtxt() parsed,
  7109.    as in "remtxt(&s);".
  7110.  
  7111.    Returns:
  7112.     1 on success with braces & redirection things removed & pointer updated,
  7113.    -9 on failure (bad indirection), after printing error message.
  7114. */
  7115. int
  7116. remtxt(p) char ** p; {
  7117.     int i, x, bpos, ppos;
  7118.     char c, *s, *q;
  7119.  
  7120.     remfile = 0;                        /* Initialize global results */
  7121.     rempipe = 0;
  7122.     remappd = 0;
  7123.     if (remdest) {
  7124.         free(remdest);
  7125.         remdest = NULL;
  7126.     }
  7127.     s = *p;
  7128.     if (!s)                             /* No redirection indicator */
  7129.       s = "";
  7130.     if (!*s) {                          /* Ditto */
  7131.         if (!local &&
  7132.             (xzcmd == XZDIR || xzcmd == XZTYP ||
  7133.              xzcmd == XZXIT || xzcmd == XZSPA ||
  7134.              xzcmd == XZHLP || xzcmd == XZPWD ||
  7135.              xzcmd == XZLGI || xzcmd == XZLGO ||
  7136.              xzcmd == XZWHO || xzcmd == XZHOS)) {
  7137.             printf("?\"%s\" has no effect in remote mode\n",cmdbuf);
  7138.             if (hints) {
  7139.                 printf("Hint: Try again with an output redirector.\n");
  7140.             }
  7141.             return(-9);
  7142.         } else
  7143.           return(1);
  7144.     }
  7145.     bpos = -1;                          /* Position of > (bracket) */
  7146.     ppos = -1;                          /* Position of | (pipe) */
  7147.     x = strlen(s);                      /* Length of cmtxt() string */
  7148.  
  7149.     for (i = x-1; i >= 0; i--) {        /* Search right to left. */
  7150.         c = s[i];
  7151.         if (c == '}')                   /* Break on first right brace */
  7152.           break;                        /* Don't look at contents of braces */
  7153.         else if (c == '>')              /* Record position of > */
  7154.           bpos = i;
  7155.         else if (c == '|')              /* and of | */
  7156.           ppos = i;
  7157.     }
  7158.     if (bpos < 0 && ppos < 0) {         /* No redirectors. */
  7159.         if (!local &&
  7160.             (xzcmd == XZDIR || xzcmd == XZTYP ||
  7161.              xzcmd == XZXIT || xzcmd == XZSPA ||
  7162.              xzcmd == XZHLP || xzcmd == XZPWD ||
  7163.              xzcmd == XZLGI || xzcmd == XZLGO ||
  7164.              xzcmd == XZWHO || xzcmd == XZHOS)) {
  7165.             printf("?\"%s\" has no effect in remote mode\n",cmdbuf);
  7166.             if (hints) {
  7167.                 printf("Hint: Try again with an output redirector.\n");
  7168.             }
  7169.             return(-9);
  7170.         }
  7171.         s = brstrip(s);                 /* Remove outer braces if any. */
  7172.         *p = s;                         /* Point to result */
  7173.         return(1);                      /* and return. */
  7174.     }
  7175.     remfile = 1;                        /* It's | or > */
  7176.     i = -1;                             /* Get leftmost symbol */
  7177.     if (bpos > -1)                      /* Bracket */
  7178.       i = bpos;
  7179.     if (ppos > -1 && (ppos < bpos || bpos < 0)) { /* or pipe */
  7180.         i = ppos;
  7181.         rempipe = 1;
  7182.     }
  7183.     if (rempipe
  7184. #ifndef NOPUSH
  7185.         && nopush
  7186. #endif /* NOPUSH */
  7187.         ) {
  7188.         printf("?Sorry, access to external commands is disabled.\n");
  7189.         return(-9);
  7190.     }
  7191.     c = s[i];                           /* Copy of symbol */
  7192.  
  7193.     if (c == '>' && s[i+1] == '>')      /* ">>" for append? */
  7194.       remappd = 1;                     /* It's not just a flag it's a number */
  7195.  
  7196.     q = s + i + 1 + remappd;            /* Point past symbol in string */
  7197.     while (*q == SP || *q == HT) q++;   /* and any intervening whitespace */
  7198.     if (!*q) {
  7199.         printf("?%s missing\n", c == '>' ? "Filename" : "Command");
  7200.         return(-9);
  7201.     }
  7202.     if (c == '>' && zchko(q) < 0) {     /* (Doesn't work for | cmd > file) */
  7203.         printf("?Access denied - %s\n", q);
  7204.         return(-9);
  7205.     }
  7206.     makestr(&remdest,q);                /* Create the destination string */
  7207.     q = s + i - 1;                      /* Point before symbol */
  7208.     while (q > s && (*q == SP || *q == HT)) /* Strip trailing whitespace */
  7209.       q--;
  7210.     *(q+1) = NUL;                       /* Terminate the string. */
  7211.     s = brstrip(s);                     /* Remove any braces */
  7212.     *p = s;                             /* Set return value */
  7213.  
  7214. #ifndef NODEBUG
  7215.     if (deblog) {
  7216.         debug(F101,"remtxt remfile","",remfile);
  7217.         debug(F101,"remtxt remappd","",remappd);
  7218.         debug(F101,"remtxt rempipe","",rempipe);
  7219.         debug(F110,"remtxt remdest",remdest, 0);
  7220.         debug(F110,"remtxt command",s,0);
  7221.     }
  7222. #endif /* NODEBUG */
  7223.  
  7224.     return(1);
  7225. }
  7226.  
  7227. int
  7228. plogin(xx) int xx; {
  7229.     char *p1 = NULL, *p2 = NULL, *p3 = NULL;
  7230.     int psaved = 0, rc = 0;
  7231. #ifdef CK_RECALL
  7232.     extern int on_recall;               /* around Password prompting */
  7233. #endif /* CK_RECALL */
  7234.     debug(F101,"plogin local","",local);
  7235.  
  7236.     if (!local || (network && ttchk() < 0)) {
  7237.         printf("?No connection\n");
  7238.         return(-9);
  7239.     }
  7240.     if ((x = cmfld("User ID","",&s,xxstring)) < 0) { /* Get User ID */
  7241.         if (x != -3) return(x);
  7242.     }
  7243.     y = strlen(s);
  7244.     if (y > 0) {
  7245.         if ((p1 = malloc(y + 1)) == NULL) {
  7246.             printf("?Internal error: malloc\n");
  7247.             rc = -9;
  7248.             goto XZXLGI;
  7249.         } else
  7250.           strcpy(p1,s);                 /* safe */
  7251.         if ((rc = cmfld("Password","",&s,xxstring)) < 0)
  7252.           if (rc != -3) goto XZXLGI;
  7253.         y = strlen(s);
  7254.         if (y > 0) {
  7255.             if ((p2 = malloc(y + 1)) == NULL) {
  7256.                 printf("?Internal error: malloc\n");
  7257.                 rc = -9;
  7258.                 goto XZXLGI;
  7259.             } else
  7260.               strcpy(p2,s);             /* safe */
  7261.             if ((rc = cmfld("Account","",&s,xxstring)) < 0)
  7262.               if (rc != -3) goto XZXLGI;
  7263.             y = strlen(s);
  7264.             if (y > 0) {
  7265.                 if ((p3 = malloc(y + 1)) == NULL) {
  7266.                     printf("?Internal error: malloc\n");
  7267.                     rc = -9;
  7268.                     goto XZXLGI;
  7269.                 } else
  7270.                   strcpy(p3,s);         /* safe */
  7271.             }
  7272.         }
  7273.     }
  7274.     if ((rc = remtxt(&s)) < 0)          /* Confirm & handle redirectors */
  7275.       goto XZXLGI;
  7276.  
  7277.     if (!p1) {                          /* No Userid specified... */
  7278.         debok = 0;                      /* Don't log this */
  7279.         /* Prompt for username, password, and account */
  7280. #ifdef CK_RECALL
  7281.         on_recall = 0;
  7282. #endif /* CK_RECALL */
  7283.         cmsavp(psave,PROMPTL);          /* Save old prompt */
  7284.         psaved = 1;
  7285.         debug(F110,"REMOTE LOGIN saved",psave,0);
  7286.  
  7287.         cmsetp("Username: ");           /* Make new prompt */
  7288.         concb((char)escape);            /* Put console in cbreak mode */
  7289.         cmini(1);
  7290.         prompt(xxstring);
  7291.         rc = -9;
  7292.         for (x = -1; x < 0; ) {         /* Prompt till they answer */
  7293.             cmres();                    /* Reset the parser */
  7294.             x = cmtxt("","",&s,NULL);   /* Get a literal line of text */
  7295.         }
  7296.         y = strlen(s);
  7297.         if (y < 1) {
  7298.             printf("?Canceled\n");
  7299.             goto XZXLGI;
  7300.         }
  7301.         if ((p1 = malloc(y + 1)) == NULL) {
  7302.             printf("?Internal error: malloc\n");
  7303.             goto XZXLGI;
  7304.         } else
  7305.           strcpy(p1,s);                 /* safe */
  7306.  
  7307.         cmsetp("Password: ");           /* Make new prompt */
  7308.         concb((char)escape);            /* Put console in cbreak mode */
  7309.         cmini(0);                       /* No echo */
  7310.         prompt(xxstring);
  7311.         debok = 0;
  7312.         for (x = -1; x < 0 && x != -3; ) { /* Get answer */
  7313.             cmres();                    /* Reset the parser */
  7314.             x = cmtxt("","",&s,NULL);   /* Get literal line of text */
  7315.         }
  7316.         if ((p2 = malloc((int)strlen(s) + 1)) == NULL) {
  7317.             printf("?Internal error: malloc\n");
  7318.             goto XZXLGI;
  7319.         } else
  7320.           strcpy(p2,s);                 /* safe */
  7321.         printf("\r\n");
  7322.         if ((rc = cmcfm()) < 0)
  7323.           goto XZXLGI;
  7324.     }
  7325.     sstate = setgen('I',p1,p2,p3);      /* Get here with at least user ID */
  7326.     rc = 0;
  7327.  
  7328.   XZXLGI:                               /* Common exit point */
  7329.     if (psaved)
  7330.       cmsetp(psave);                    /* Restore original prompt */
  7331.     if (p3) { free(p3); p3 = NULL; }    /* Free malloc'd storage */
  7332.     if (p2) { free(p2); p2 = NULL; }
  7333.     if (p1) { free(p1); p1 = NULL; }
  7334.     if (rc > -1) {
  7335.         if (local && rc > -1)           /* If local, flush tty input buffer */
  7336.           ttflui();
  7337.     }
  7338.     return(rc);
  7339. }
  7340.  
  7341. #ifdef OS2
  7342. #ifndef NOLOCAL
  7343. int
  7344. dormt(xx) int xx; {
  7345.     int rc = 0;
  7346.     extern int term_io;
  7347.     int term_io_sav = term_io;
  7348. #ifdef NEWFTP
  7349.     extern int ftpget, ftpisopen();
  7350.     if ((ftpget == 1) || ((ftpget == 2) && ftpisopen()))
  7351.       return(doftprmt(xx,0));
  7352. #endif /* NEWFTP */
  7353.     term_io = 0;
  7354.     rc = xxdormt(xx);
  7355.     term_io = term_io_sav;
  7356.     return rc;
  7357. }
  7358.  
  7359.  
  7360. int
  7361. xxdormt(xx) int xx;
  7362. #else /* NOLOCAL */
  7363. int
  7364. dormt(xx) int xx;
  7365. #endif /* NOLOCAL */
  7366. #else /* OS2 */
  7367. int
  7368. dormt(xx) int xx;
  7369. #endif /* OS2 */
  7370. {                                       /* REMOTE commands */
  7371.     int x, y, retcode;
  7372.     char *s, sbuf[50], *s2;
  7373.  
  7374. #ifdef NEWFTP
  7375.     extern int ftpget, ftpisopen();
  7376.     if ((ftpget == 1) || ((ftpget == 2) && ftpisopen()))
  7377.       return(doftprmt(xx,0));
  7378. #endif /* NEWFTP */
  7379.  
  7380.     remfile = 0;                        /* Clear these */
  7381.     rempipe = 0;
  7382.     remappd = 0;
  7383.  
  7384.     if (xx < 0) return(xx);             /* REMOTE what? */
  7385.  
  7386.     xzcmd = xx;                         /* Make global copy of arg */
  7387.  
  7388.     if (xx == XZSET) {                  /* REMOTE SET */
  7389.         if ((y = cmkey(rmstab,nrms,"","",xxstring)) < 0) {
  7390.             if (y == -3) {
  7391.                 printf("?Parameter name required\n");
  7392.                 return(-9);
  7393.             } else return(y);
  7394.         }
  7395.         return(doprm(y,1));
  7396.     }
  7397.  
  7398.     switch (xx) {                       /* Others... */
  7399.  
  7400.       case XZCDU:
  7401.         if ((x = cmcfm()) < 0) return(x);
  7402.         printf("?Sorry, REMOTE CDUP not supported yet\n");
  7403.         return(-9);
  7404.  
  7405.       case XZCWD:                       /* CWD (CD) */
  7406.         if ((x = cmtxt("Remote directory name","",&s,xxstring)) < 0)
  7407.           return(x);
  7408.         if ((x = remtxt(&s)) < 0)
  7409.           return(x);
  7410.         debug(F111,"XZCWD: ",s,x);
  7411.         *sbuf = NUL;
  7412.         s2 = sbuf;
  7413. /*
  7414.   The following is commented out because since the disappearance of the
  7415.   DECSYSTEM-20 from the planet, no known computer requires a password for
  7416.   changing directory.
  7417. */
  7418. #ifdef DIRPWDPR
  7419.         if (*s != NUL) {                /* If directory name given, */
  7420.                                         /* get password on separate line. */
  7421.             if (tlevel > -1) {          /* From take file... */
  7422.  
  7423.                 if (fgets(sbuf,50,tfile[tlevel]) == NULL)
  7424.                   fatal("take file ends prematurely in 'remote cwd'");
  7425.                 debug(F110," pswd from take file",s2,0);
  7426.                 for (x = (int)strlen(sbuf);
  7427.                      x > 0 && (sbuf[x-1] == NL || sbuf[x-1] == CR);
  7428.                      x--)
  7429.                   sbuf[x-1] = '\0';
  7430.  
  7431.             } else {                    /* From terminal... */
  7432.  
  7433.                 printf(" Password: ");  /* get a password */
  7434. #ifdef IKSD
  7435.                 if (!local && inserver) {
  7436.                     x = coninc(0);
  7437.                 } else
  7438. #endif /* IKSD */
  7439. #ifdef OS2
  7440.                   x = is_a_tty(0) ? coninc(0) : /* with no echo ... */
  7441.                     getchar();
  7442. #else /* OS2 */
  7443.                 x = getchar();
  7444. #endif /* OS2 */
  7445.                 while ((x != NL) && (x != CR)) {
  7446.                     if ((x &= 0177) == '?') {
  7447.                         printf("? Password of remote directory\n Password: ");
  7448.                         s2 = sbuf;
  7449.                         *sbuf = NUL;
  7450.                     } else if (x == ESC) /* Mini command line editor... */
  7451.                       bleep(BP_WARN);
  7452.                     else if (x == BS || x == 0177)
  7453.                       s2--;
  7454.                     else if (x == 025) {        /* Ctrl-U */
  7455.                         s2 = sbuf;
  7456.                         *sbuf = NUL;
  7457.                     } else
  7458.                       *s2++ = x;
  7459.  
  7460.                     /* Get the next character */
  7461. #ifdef IKSD
  7462.                     if (!local && inserver) {
  7463.                         x = coninc(0);
  7464.                     } else
  7465. #endif /* IKSD */
  7466. #ifdef OS2
  7467.                     x = is_a_tty(0) ? coninc(0) : /* with no echo ... */
  7468.                       getchar();
  7469. #else /* OS2 */
  7470.                     x = getchar();
  7471. #endif /* OS2 */
  7472.                 }
  7473.                 *s2 = NUL;
  7474.                 putchar('\n');
  7475.             }
  7476.             s2 = sbuf;
  7477.         } else s2 = "";
  7478. #endif /* DIRPWDPR */
  7479.  
  7480.         debug(F110," password",s2,0);
  7481.     rcdactive = 1;
  7482.         sstate = setgen('C',s,s2,"");
  7483.         retcode = 0;
  7484.         break;
  7485.  
  7486.       case XZDEL:                               /* Delete */
  7487.         if ((x = cmtxt("Name of remote file(s) to delete",
  7488.                        "",&s,xxstring)) < 0) {
  7489.             if (x == -3) {
  7490.                 printf("?Name of remote file(s) required\n");
  7491.                 return(-9);
  7492.             } else return(x);
  7493.         }
  7494.         if ((x = remtxt(&s)) < 0)
  7495.           return(x);
  7496.         if (local) ttflui();            /* If local, flush tty input buffer */
  7497.         retcode = sstate = rfilop(s,'E');
  7498.         break;
  7499.  
  7500.       case XZDIR:                       /* Directory */
  7501.         if ((x = cmtxt("Remote directory or file specification","",&s,
  7502.                        xxstring)) < 0)
  7503.           return(x);
  7504.         if ((x = remtxt(&s)) < 0)
  7505.           return(x);
  7506.         if (local) ttflui();            /* If local, flush tty input buffer */
  7507.         rmsg();
  7508.         retcode = sstate = setgen('D',s,"","");
  7509.         break;
  7510.  
  7511.       case XZHLP:                       /* Help */
  7512.         if ((x = remcfm()) < 0) return(x);
  7513.         sstate = setgen('H',"","","");
  7514.         retcode = 0;
  7515.         break;
  7516.  
  7517.       case XZHOS:                       /* Host */
  7518.         if ((x = cmtxt("Command for remote system","",&s,xxstring)) < 0)
  7519.           return(x);
  7520.         if ((x = remtxt(&s)) < 0)
  7521.           return(x);
  7522.         if ((y = (int)strlen(s)) < 1)
  7523.           return(x);
  7524.         ckstrncpy(line,s,LINBUFSIZ);
  7525.         cmarg = line;
  7526.         rmsg();
  7527.         retcode = sstate = 'c';
  7528.         break;
  7529.  
  7530. #ifndef NOFRILLS
  7531.       case XZKER:
  7532.         if ((x = cmtxt("Command for remote Kermit","",&s,xxstring)) < 0)
  7533.           return(x);
  7534.         if ((x = remtxt(&s)) < 0)
  7535.           return(x);
  7536.         if ((int)strlen(s) < 1)  {
  7537.             if (x == -3) {
  7538.                 printf("?Remote Kermit command required\n");
  7539.                 return(-9);
  7540.             } else return(x);
  7541.         }
  7542.         ckstrncpy(line,s,LINBUFSIZ);
  7543.         cmarg = line;
  7544.         retcode = sstate = 'k';
  7545.         rmsg();
  7546.         break;
  7547.  
  7548.       case XZLGI:                       /* Login */
  7549.     rcdactive = 1;            /* Suppress "Logged in" msg if quiet */
  7550.         return(plogin(XXREM));
  7551.  
  7552.       case XZLGO: {                     /* Logout */
  7553.           extern int bye_active;
  7554.           if ((x = remcfm()) < 0) return(x);
  7555.           sstate = setgen('I',"","","");
  7556.           retcode = 0;
  7557.           bye_active = 1;               /* Close connection when done */
  7558.           break;
  7559.       }
  7560.  
  7561.       case XZPRI:                       /* Print */
  7562.         if (!atdiso || !atcapr) {       /* Disposition attribute off? */
  7563.             printf("?Disposition Attribute is Off\n");
  7564.             return(-2);
  7565.         }
  7566.         cmarg = "";
  7567.         cmarg2 = "";
  7568.         if ((x = cmifi("Local file(s) to print on remote printer","",&s,&y,
  7569.                        xxstring)) < 0) {
  7570.             if (x == -3) {
  7571.                 printf("?Name of local file(s) required\n");
  7572.                 return(-9);
  7573.             }
  7574.             return(x);
  7575.         }
  7576.         ckstrncpy(line,s,LINBUFSIZ);    /* Make a safe copy of filename */
  7577.         *optbuf = NUL;                  /* Wipe out any old options */
  7578.         if ((x = cmtxt("Options for remote print command","",&s,xxstring)) < 0)
  7579.           return(x);
  7580.         if ((x = remtxt(&s)) < 0)
  7581.           return(x);
  7582.         if ((int)strlen(optbuf) > 94) { /* Make sure this is legal */
  7583.             printf("?Option string too long\n");
  7584.             return(-9);
  7585.         }
  7586.         ckstrncpy(optbuf,s,OPTBUFLEN);  /* Make a safe copy of options */
  7587.         nfils = -1;                     /* Expand file list internally */
  7588.         cmarg = line;                   /* Point to file list. */
  7589.         rprintf = 1;                    /* REMOTE PRINT modifier for SEND */
  7590.         sstate = 's';                   /* Set start state to SEND */
  7591.         if (local) displa = 1;
  7592.         retcode = 0;
  7593.         break;
  7594. #endif /* NOFRILLS */
  7595.  
  7596.       case XZSPA:                       /* Space */
  7597.         if ((x = cmtxt("Confirm, or remote directory name",
  7598.                        "",&s,xxstring)) < 0)
  7599.           return(x);
  7600.         if ((x = remtxt(&s)) < 0)
  7601.           return(x);
  7602.         retcode = sstate = setgen('U',s,"","");
  7603.         break;
  7604.  
  7605. #ifndef NOFRILLS
  7606.       case XZTYP:                       /* Type */
  7607.         if ((x = cmtxt("Remote file specification","",&s,xxstring)) < 0)
  7608.           return(x);
  7609.         if ((int)strlen(s) < 1) {
  7610.             printf("?Remote filename required\n");
  7611.             return(-9);
  7612.         }
  7613.         if ((x = remtxt(&s)) < 0)
  7614.           return(x);
  7615.         rmsg();
  7616.         retcode = sstate = rfilop(s,'T');
  7617.         break;
  7618. #endif /* NOFRILLS */
  7619.  
  7620. #ifndef NOFRILLS
  7621.       case XZWHO:
  7622.         if ((x = cmtxt("Remote user name, or carriage return",
  7623.                        "",&s,xxstring)) < 0)
  7624.           return(x);
  7625.         if ((x = remtxt(&s)) < 0)
  7626.           return(x);
  7627.         retcode = sstate = setgen('W',s,"","");
  7628.         break;
  7629. #endif /* NOFRILLS */
  7630.  
  7631.       case XZPWD:                       /* PWD */
  7632.         if ((x = remcfm()) < 0) return(x);
  7633.         sstate = setgen('A',"","","");
  7634.         retcode = 0;
  7635.         break;
  7636.  
  7637. #ifndef NOSPL
  7638.       case XZQUE: {                     /* Query */
  7639.           char buf[2];
  7640.           extern char querybuf[], * qbufp;
  7641.           extern int qbufn;
  7642.           if ((y = cmkey(vartyp,nvartyp,"","",xxstring)) < 0)
  7643.             return(y);
  7644.           if ((x = cmtxt(y == 'F' ? "Remote function invocation" :
  7645.                          ('K' ? "Remote variable name or function":
  7646.                          "Remote variable name"),
  7647.                          "",
  7648.                          &s,
  7649.                          (y == 'K') ? xxstring : NULL
  7650.                          )) < 0)        /* Don't evaluate */
  7651.             return(x);
  7652.           if ((x = remtxt(&s)) < 0)
  7653.             return(x);
  7654.           query = 1;                    /* QUERY is active */
  7655.           qbufp = querybuf;             /* Initialize query response buffer */
  7656.           qbufn = 0;
  7657.           querybuf[0] = NUL;
  7658.           buf[0] = (char) (y & 127);
  7659.           buf[1] = NUL;
  7660.           retcode = sstate = setgen('V',"Q",(char *)buf,s);
  7661.           break;
  7662.       }
  7663.  
  7664.       case XZASG: {                     /* Assign */
  7665.           char buf[VNAML];
  7666.           if ((y = cmfld("Remote variable name","",&s,NULL)) < 0) /* No eval */
  7667.             return(y);
  7668.           if ((int)strlen(s) >= VNAML) {
  7669.               printf("?Too long\n");
  7670.               return(-9);
  7671.           }
  7672.           ckstrncpy(buf,s,VNAML);
  7673.           if ((x = cmtxt("Assignment for remote variable",
  7674.                    "",&s,xxstring)) < 0) /* Evaluate this one */
  7675.             return(x);
  7676.           if ((x = remtxt(&s)) < 0)
  7677.             return(x);
  7678. #ifdef COMMENT
  7679. /*
  7680.   Server commands can't be long packets.  In principle there's no reason
  7681.   why they shouldn't be, except that we don't know at this point if the
  7682.   server is capable of accepting long packets because we haven't started
  7683.   the protocol yet.  In practice, allowing a long packet here breaks a lot
  7684.   of assumptions, causes buffer overruns and crashes, etc.  To be fixed
  7685.   later.  (But since this is commented out, evidently I fixed it later...)
  7686. */
  7687.           if ((int)strlen(s) > 85) {    /* Allow for encoding expansion */
  7688.               printf("?Sorry, value is too long - 85 characters max\n");
  7689.               return(-9);
  7690.           }
  7691. #endif /* COMMENT */
  7692.           retcode = sstate = setgen('V',"S",(char *)buf,s);
  7693.           break;
  7694.       }
  7695. #endif /* NOSPL */
  7696.  
  7697.       case XZCPY: {                     /* COPY */
  7698.           char buf[TMPBUFSIZ];
  7699.           buf[TMPBUFSIZ-1] = '\0';
  7700.           if ((x = cmfld("Name of remote file to copy","",&s,xxstring)) < 0) {
  7701.               if (x == -3) {
  7702.                   printf("?Name of remote file required\n");
  7703.                   return(-9);
  7704.               }
  7705.               else
  7706.                 return(x);
  7707.           }
  7708.           ckstrncpy(buf,s,TMPBUFSIZ);
  7709.           if ((x = cmfld("Name of remote destination file or directory",
  7710.                          "",&s, xxstring)) < 0) {
  7711.               if (x == -3) {
  7712.                   printf("?Name of remote file or directory required\n");
  7713.                   return(-9);
  7714.               } else return(x);
  7715.           }
  7716.           ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  7717.           if ((x = remcfm()) < 0)
  7718.             return(x);
  7719.           if (local) ttflui();          /* If local, flush tty input buffer */
  7720.           retcode = sstate = setgen('K',buf,tmpbuf,"");
  7721.           break;
  7722.       }
  7723.       case XZREN: {                     /* Rename */
  7724.           char buf[TMPBUFSIZ];
  7725.           buf[TMPBUFSIZ-1] = '\0';
  7726.           if ((x = cmfld("Name of remote file to rename",
  7727.                          "",&s,xxstring)) < 0) {
  7728.               if (x == -3) {
  7729.                   printf("?Name of remote file required\n");
  7730.                   return(-9);
  7731.               } else return(x);
  7732.           }
  7733.           ckstrncpy(buf,s,TMPBUFSIZ);
  7734.           if ((x = cmfld("New name of remote file","",&s, xxstring)) < 0) {
  7735.               if (x == -3) {
  7736.                   printf("?Name of remote file required\n");
  7737.                   return(-9);
  7738.               } else return(x);
  7739.           }
  7740.           ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  7741.           if ((x = remcfm()) < 0)
  7742.             return(x);
  7743.           if (local) ttflui();          /* If local, flush device buffer */
  7744.           retcode = sstate = setgen('R',buf,tmpbuf,"");
  7745.           break;
  7746.       }
  7747.       case XZMKD:                       /* mkdir */
  7748.       case XZRMD:                       /* rmdir */
  7749.         if ((x = cmtxt((xx == XZMKD) ?
  7750.                        "Name of remote directory to create" :
  7751.                        "Name of remote directory to delete",
  7752.                        "",
  7753.                        &s,
  7754.                        xxstring
  7755.                        )) < 0) {
  7756.             if (x == -3) {
  7757.                 printf("?Name required\n");
  7758.                 return(-9);
  7759.             } else return(x);
  7760.         }
  7761.         if ((x = remtxt(&s)) < 0)
  7762.           return(x);
  7763.         if (local) ttflui();            /* If local, flush tty input buffer */
  7764.         retcode = sstate = rfilop(s, (char)(xx == XZMKD ? 'm' : 'd'));
  7765.         break;
  7766.  
  7767.       case XZXIT:                       /* Exit */
  7768.         if ((x = remcfm()) < 0) return(x);
  7769.         sstate = setgen('X',"","","");
  7770.         retcode = 0;
  7771.         break;
  7772.  
  7773.       default:
  7774.         if ((x = remcfm()) < 0) return(x);
  7775.         printf("?Not implemented - %s\n",cmdbuf);
  7776.         return(-2);
  7777.     }
  7778.     if (local && retcode > -1)          /* If local, flush tty input buffer */
  7779.       ttflui();
  7780.     return(retcode);
  7781. }
  7782.  
  7783.  
  7784. /*  R F I L O P  --  Remote File Operation  */
  7785.  
  7786. CHAR
  7787. #ifdef CK_ANSIC
  7788. rfilop(char * s, char t)
  7789. #else
  7790. rfilop(s,t) char *s, t;
  7791. #endif /* CK_ANSIC */
  7792. /* rfilop */ {
  7793.     if (*s == NUL) {
  7794.         printf("?File specification required\n");
  7795.         return((CHAR) 0);
  7796.     }
  7797.     debug(F111,"rfilop",s,t);
  7798.     return(setgen(t,s,"",""));
  7799. }
  7800. #endif /* NOXFER */
  7801.  
  7802. #ifdef ANYX25
  7803. int
  7804. setx25() {
  7805.     if ((y = cmkey(x25tab,nx25,"X.25 call options","",xxstring)) < 0)
  7806.       return(y);
  7807.     switch (y) {
  7808.       case XYUDAT:
  7809.         if ((z = cmkey(onoff,2,"X.25 call user data","",xxstring))
  7810.             < 0) return(z);
  7811.         if (z == 0) {
  7812.             if ((z = cmcfm()) < 0) return(z);
  7813.             cudata = 0;             /* disable call user data */
  7814.             return (success = 1);
  7815.         }
  7816.         if ((x = cmtxt("X.25 call user data string","",&s,xxstring)) < 0)
  7817.           return(x);
  7818.         if ((int)strlen(s) == 0) {
  7819.             return (-3);
  7820.         } else if ((int)strlen(s) > MAXCUDATA) {
  7821.             printf("?The length must be > 0 and <= %d\n",MAXCUDATA);
  7822.             return(-2);
  7823.         }
  7824.         if ((y = cmcfm()) < 0) return(y);
  7825.         ckstrncpy(udata,s,MAXCUDATA);
  7826.         cudata = 1;                     /* X.25 call user data specified */
  7827.         return (success = 1);
  7828.       case XYCLOS:
  7829.         if ((z = cmkey(onoff,2,"X.25 closed user group call","",xxstring))
  7830.             < 0) return(z);
  7831.         if (z == 0) {
  7832.             if ((z = cmcfm()) < 0) return(z);
  7833.             closgr = -1;                /* disable closed user group */
  7834.             return (success = 1);
  7835.         }
  7836.         if ((y = cmnum("0 <= cug index >= 99","",10,&x,xxstring)) < 0)
  7837.           return(y);
  7838.         if (x < 0 || x > 99) {
  7839.             printf("?The choices are 0 <= cug index >= 99\n");
  7840.             return(-2);
  7841.         }
  7842.         if ((y = cmcfm()) < 0) return(y);
  7843.         closgr = x;                     /* closed user group selected */
  7844.         return (success = 1);
  7845.  
  7846.       case XYREVC:
  7847.         if((z = cmkey(onoff,2,"X.25 reverse charge call","",xxstring)) < 0)
  7848.           return(z);
  7849.         if ((x = cmcfm()) < 0) return(x);
  7850.         revcall = z;
  7851.         return (success = 1);
  7852.     }
  7853. }
  7854.  
  7855. #ifndef IBMX25
  7856. int
  7857. setpadp() {
  7858.     if ((y = cmkey(padx3tab,npadx3,"PAD X.3 parameter name","",xxstring)) < 0)
  7859.       return(y);
  7860.     x = y;
  7861.     switch (x) {
  7862.       case PAD_BREAK_CHARACTER:
  7863.         if ((y = cmnum("PAD break character value","",10,&z,xxstring)) < 0)
  7864.           return(y);
  7865.         if ((y = cmcfm()) < 0) return(y);
  7866.         break;
  7867.       case PAD_ESCAPE:
  7868.         if ((y = cmnum("PAD escape","",10,&z,xxstring)) < 0) return(y);
  7869.         if (z != 0 && z != 1) {
  7870.             printf("?The choices are 0 or 1\n");
  7871.             return(-2);
  7872.         }
  7873.         if ((y = cmcfm()) < 0) return(y);
  7874.         break;
  7875.       case PAD_ECHO:
  7876.         if ((y = cmnum("PAD echo","",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.       case PAD_DATA_FORWARD_CHAR:
  7884.         if ((y = cmnum("PAD data forward char","",10,&z,xxstring)) < 0)
  7885.           return(y);
  7886.         if (z != 0 && z != 2) {
  7887.             printf("?The choices are 0 or 2\n");
  7888.             return(-2);
  7889.         }
  7890.         if ((y = cmcfm()) < 0) return(y);
  7891.         break;
  7892.       case PAD_DATA_FORWARD_TIMEOUT:
  7893.         if ((y = cmnum("PAD data forward timeout","",10,&z,xxstring)) < 0)
  7894.             return(y);
  7895.         if (z < 0 || z > 255) {
  7896.             printf("?The choices are 0 or 1 <= timeout <= 255\n");
  7897.             return(-2);
  7898.         }
  7899.         if ((y = cmcfm()) < 0) return(y);
  7900.         break;
  7901.       case PAD_FLOW_CONTROL_BY_PAD:
  7902.         if ((y = cmnum("PAD pad flow control","",10,&z,xxstring)) < 0)
  7903.           return(y);
  7904.         if (z != 0 && z != 1) {
  7905.             printf("?The choices are 0 or 1\n");
  7906.             return(-2);
  7907.         }
  7908.         if ((y = cmcfm()) < 0) return(y);
  7909.         break;
  7910.       case PAD_SUPPRESSION_OF_SIGNALS:
  7911.         if ((y = cmnum("PAD service","",10,&z,xxstring)) < 0) return(y);
  7912.         if (z != 0 && z != 1) {
  7913.             printf("?The choices are 0 or 1\n");
  7914.             return(-2);
  7915.         }
  7916.         if ((y = cmcfm()) < 0) return(y);
  7917.         break;
  7918.  
  7919.       case PAD_BREAK_ACTION:
  7920.         if ((y = cmnum("PAD break action","",10,&z,xxstring)) < 0) return(y);
  7921.         if (z != 0 && z != 1 && z != 2 && z != 5 && z != 8 && z != 21) {
  7922.             printf("?The choices are 0, 1, 2, 5, 8 or 21\n");
  7923.             return(-2);
  7924.         }
  7925.         if ((y = cmcfm()) < 0) return(y);
  7926.         break;
  7927.  
  7928.       case PAD_SUPPRESSION_OF_DATA:
  7929.         if ((y = cmnum("PAD data delivery","",10,&z,xxstring)) < 0) return(y);
  7930.         if (z != 0 && z != 1) {
  7931.             printf("?The choices are 0 or 1\n");
  7932.             return(-2);
  7933.         }
  7934.         if ((y = cmcfm()) < 0) return(y);
  7935.         break;
  7936.  
  7937.       case PAD_PADDING_AFTER_CR:
  7938.         if ((y = cmnum("PAD crpad","",10,&z,xxstring)) < 0) return(y);
  7939.         if (z < 0 || z > 7) {
  7940.             printf("?The choices are 0 or 1 <= crpad <= 7\n");
  7941.             return(-2);
  7942.         }
  7943.         if ((y = cmcfm()) < 0) return(y);
  7944.         break;
  7945.  
  7946.       case PAD_LINE_FOLDING:
  7947.         if ((y = cmnum("PAD linefold","",10,&z,xxstring)) < 0) return(y);
  7948.         if (z < 0 || z > 255) {
  7949.             printf("?The choices are 0 or 1 <= linefold <= 255\n");
  7950.             return(-2);
  7951.         }
  7952.         if ((y = cmcfm()) < 0) return(y);
  7953.         break;
  7954.  
  7955.       case PAD_LINE_SPEED:
  7956.         if ((y = cmnum("PAD baudrate","",10,&z,xxstring)) < 0) return(y);
  7957.         if (z < 0 || z > 18) {
  7958.             printf("?The choices are 0 <= baudrate <= 18\n");
  7959.             return(-2);
  7960.         }
  7961.         if ((y = cmcfm()) < 0) return(y);
  7962.         break;
  7963.  
  7964.       case PAD_FLOW_CONTROL_BY_USER:
  7965.         if ((y = cmnum("PAD terminal flow control","",10,&z,xxstring)) < 0)
  7966.             return(y);
  7967.         if (z != 0 && z != 1) {
  7968.             printf("?The choices are 0 or 1\n");
  7969.             return(-2);
  7970.         }
  7971.         if ((y = cmcfm()) < 0) return(y);
  7972.         break;
  7973.  
  7974.       case PAD_LF_AFTER_CR:
  7975.         if ((y = cmnum("PAD crpad","",10,&z,xxstring)) < 0) return(y);
  7976.         if (z < 0 || z == 3 || z > 7) {
  7977.             printf("?The choices are 0, 1, 2, 4, 5, 6 or 7\n");
  7978.             return(-2);
  7979.         }
  7980.         if ((y = cmcfm()) < 0) return(y);
  7981.         break;
  7982.  
  7983.       case PAD_PADDING_AFTER_LF:
  7984.         if ((y = cmnum("PAD lfpad","",10,&z,xxstring)) < 0) return(y);
  7985.         if (z < 0 || z > 7) {
  7986.             printf("?The choices are 0 or 1 <= lfpad <= 7\n");
  7987.             return(-2);
  7988.         }
  7989.         if ((y = cmcfm()) < 0) return(y);
  7990.         break;
  7991.  
  7992.       case PAD_EDITING:
  7993.         if ((y = cmnum("PAD edit control","",10,&z,xxstring)) < 0) return(y);
  7994.         if (z != 0 && z != 1) {
  7995.             printf("?The choices are 0 or 1\n");
  7996.             return(-2);
  7997.         }
  7998.         if ((y = cmcfm()) < 0) return(y);
  7999.         break;
  8000.  
  8001.       case PAD_CHAR_DELETE_CHAR:
  8002.         if ((y = cmnum("PAD char delete char","",10,&z,xxstring)) < 0)
  8003.             return(y);
  8004.         if (z < 0 || z > 127) {
  8005.             printf("?The choices are 0 or 1 <= chardelete <= 127\n");
  8006.             return(-2);
  8007.         }
  8008.         if ((y = cmcfm()) < 0) return(y);
  8009.         break;
  8010.  
  8011.       case PAD_BUFFER_DELETE_CHAR:
  8012.         if ((y = cmnum("PAD buffer delete char","",10,&z,xxstring)) < 0)
  8013.             return(y);
  8014.         if (z < 0 || z > 127) {
  8015.             printf("?The choices are 0 or 1 <= bufferdelete <= 127\n");
  8016.             return(-2);
  8017.         }
  8018.         if ((y = cmcfm()) < 0) return(y);
  8019.         break;
  8020.  
  8021.       case PAD_BUFFER_DISPLAY_CHAR:
  8022.         if ((y = cmnum("PAD display line char","",10,&z,xxstring)) < 0)
  8023.             return(y);
  8024.         if (z < 0 || z > 127) {
  8025.             printf("?The choices are 0 or 1 <= displayline <= 127\n");
  8026.             return(-2);
  8027.         }
  8028.         if ((y = cmcfm()) < 0) return(y);
  8029.         break;
  8030.     }
  8031.     padparms[x] = z;
  8032.     return(success = 1);
  8033. }
  8034. #endif /* IBMX25 */
  8035. #endif /* ANYX25 */
  8036.  
  8037. #ifndef NOXFER
  8038. int
  8039. setat(rmsflg) int rmsflg; {
  8040.     int xx;
  8041.     if ((y = cmkey(attrtab,natr,"File Attribute packets","",xxstring)) < 0)
  8042.       return(y);
  8043.     if (y == AT_XALL) {                 /* ATTRIBUTES ALL ON or ALL OFF */
  8044.         if ((z = seton(&xx)) < 0) return(z);
  8045.         if (rmsflg) {
  8046.             printf("Sorry, command not available\n");
  8047.             return(-9);
  8048.         } else {
  8049.             atenci = xx;                /* Encoding in */
  8050.             atenco = xx;                /* Encoding out */
  8051.             atdati = xx;                /* Date in */
  8052.             atdato = xx;                /* Date out */
  8053.             atdisi = xx;                /* Disposition in/out */
  8054.             atdiso = xx;
  8055.             atleni = xx;                /* Length in/out (both kinds) */
  8056.             atleno = xx;
  8057.             atblki = xx;                /* Blocksize in/out */
  8058.             atblko = xx;
  8059.             attypi = xx;                /* File type in/out */
  8060.             attypo = xx;
  8061.             atsidi = xx;                /* System ID in/out */
  8062.             atsido = xx;
  8063.             atsysi = xx;                /* System-dependent params in/out */
  8064.             atsyso = xx;
  8065. #ifdef CK_PERMS                         /* Protection */
  8066.             atlpri = xx;                /* Local in */
  8067.             atlpro = xx;                /* Local out */
  8068.             atgpri = xx;                /* Generic in */
  8069.             atgpro = xx;                /* Generic out */
  8070. #endif /* CK_PERMS */
  8071. #ifdef STRATUS
  8072.             atfrmi = xx;                /* Format in/out */
  8073.             atfrmo = xx;
  8074.             atcrei = xx;                /* Creator id in/out */
  8075.             atcreo = xx;
  8076.             atacti = xx;                /* Account in/out */
  8077.             atacto = xx;
  8078. #endif /* STRATUS */
  8079.         }
  8080.         return(z);
  8081.     } else if (y == AT_ALLY || y == AT_ALLN) { /* ATTRIBUTES ON or OFF */
  8082.         if ((x = cmcfm()) < 0) return(x);
  8083.         atcapr = (y == AT_ALLY) ? 1 : 0;
  8084.         if (rmsflg) {
  8085.             sstate = setgen('S', "132", atcapr ? "1" : "0", "");
  8086.             return((int) sstate);
  8087.         } else return(success = 1);
  8088.     }
  8089.     /* Otherwise, it's an individual attribute that wants turning off/on */
  8090.  
  8091.     if ((z = cmkey(onoff,2,"","",xxstring)) < 0) return(z);
  8092.     if ((x = cmcfm()) < 0) return(x);
  8093.  
  8094. /* There are better ways to do this... */
  8095. /* The real problem is that we're not separating the in and out cases */
  8096. /* and so we have to arbitrarily pick the "in" case, i.e tell the remote */
  8097. /* server to ignore incoming attributes of the specified type, rather */
  8098. /* than telling it not to send them.  The protocol does not (yet) define */
  8099. /* codes for "in-and-out-at-the-same-time". */
  8100.  
  8101.     switch (y) {
  8102. #ifdef CK_PERMS
  8103. /* We're lumping local and generic protection together for now... */
  8104.       case AT_LPRO:
  8105.       case AT_GPRO:
  8106.         if (rmsflg) {
  8107.             sstate = setgen('S', "143", z ? "1" : "0", "");
  8108.             return((int) sstate);
  8109.         }
  8110.         atlpri = atlpro = atgpri = atgpro = z; break;
  8111. #endif /* CK_PERMS */
  8112.       case AT_DISP:
  8113.         if (rmsflg) {
  8114.             sstate = setgen('S', "142", z ? "1" : "0", "");
  8115.             return((int) sstate);
  8116.         }
  8117.         atdisi = atdiso = z; break;
  8118.       case AT_ENCO:
  8119.         if (rmsflg) {
  8120.             sstate = setgen('S', "141", z ? "1" : "0", "");
  8121.             return((int) sstate);
  8122.         }
  8123.         atenci = atenco = z; break;
  8124.       case AT_DATE:
  8125.         if (rmsflg) {
  8126.             sstate = setgen('S', "135", z ? "1" : "0", "");
  8127.             return((int) sstate);
  8128.         }
  8129.         atdati = atdato = z; break;
  8130.       case AT_LENB:
  8131.       case AT_LENK:
  8132.         if (rmsflg) {
  8133.             sstate = setgen('S', "133", z ? "1" : "0", "");
  8134.             return((int) sstate);
  8135.         }
  8136.         atleni = atleno = z; break;
  8137.       case AT_BLKS:
  8138.         if (rmsflg) {
  8139.             sstate = setgen('S', "139", z ? "1" : "0", "");
  8140.             return((int) sstate);
  8141.         }
  8142.         atblki = atblko = z; break;
  8143.       case AT_FTYP:
  8144.         if (rmsflg) {
  8145.             sstate = setgen('S', "134", z ? "1" : "0", "");
  8146.             return((int) sstate);
  8147.         }
  8148.         attypi = attypo = z; break;
  8149. #ifdef STRATUS
  8150.       case AT_CREA:
  8151.         if (rmsflg) {
  8152.             sstate = setgen('S', "136", z ? "1" : "0", "");
  8153.             return((int) sstate);
  8154.         }
  8155.         atcrei = atcreo = z; break;
  8156.       case AT_ACCT:
  8157.         if (rmsflg) {
  8158.             sstate = setgen('S', "137", z ? "1" : "0", "");
  8159.             return((int) sstate);
  8160.         }
  8161.         atacti = atacto = z; break;
  8162. #endif /* STRATUS */
  8163.       case AT_SYSI:
  8164.         if (rmsflg) {
  8165.             sstate = setgen('S', "145", z ? "1" : "0", "");
  8166.             return((int) sstate);
  8167.         }
  8168.         atsidi = atsido = z; break;
  8169.       case AT_RECF:
  8170.         if (rmsflg) {
  8171.             sstate = setgen('S', "146", z ? "1" : "0", "");
  8172.             return((int) sstate);
  8173.         }
  8174.         atfrmi = atfrmo = z; break;
  8175.       case AT_SYSP:
  8176.         if (rmsflg) {
  8177.             sstate = setgen('S', "147", z ? "1" : "0", "");
  8178.             return((int) sstate);
  8179.         }
  8180.         atsysi = atsyso = z; break;
  8181.       default:
  8182.         printf("?Not available\n");
  8183.         return(-2);
  8184.     }
  8185.     return(1);
  8186. }
  8187. #endif /* NOXFER */
  8188.  
  8189. #ifndef NOSPL
  8190. int
  8191. setinp() {
  8192.     if ((y = cmkey(inptab,ninp,"","",xxstring)) < 0) return(y);
  8193.     switch (y) {
  8194. #ifdef OS2
  8195.       case IN_PAC:                      /* SET INPUT PACING */
  8196.         z = cmnum("milliseconds","0",10,&x,xxstring);
  8197.         return(setnum(&tt_inpacing,x,z,1000));
  8198.       case IN_TRM:                      /* SET INPUT TERMINAL */
  8199.         return(seton(&interm));
  8200. #endif /* OS2 */
  8201.       case IN_DEF:                      /* SET INPUT DEFAULT-TIMEOUT */
  8202.         z = cmnum("Positive number","",10,&x,xxstring);
  8203.         return(setnum(&indef,x,z,94));
  8204.       case IN_TIM:                      /* SET INPUT TIMEOUT-ACTION */
  8205.         if ((z = cmkey(intimt,2,"","",xxstring)) < 0) return(z);
  8206.         if ((x = cmcfm()) < 0) return(x);
  8207.         intime[cmdlvl] = z;
  8208.         return(success = 1);
  8209.       case IN_CAS:                      /* SET INPUT CASE */
  8210.         if ((z = cmkey(incast,2,"","",xxstring)) < 0) return(z);
  8211.         if ((x = cmcfm()) < 0) return(x);
  8212.         inpcas[cmdlvl] = z;
  8213.         return(success = 1);
  8214.       case IN_ECH:                      /* SET INPUT ECHO */
  8215.         return(seton(&inecho));
  8216.       case IN_SIL:                      /* SET INPUT SILENCE */
  8217.         z = cmnum("Seconds of inactivity before INPUT fails","",10,&x,
  8218.                   xxstring);
  8219.         return(setnum(&insilence,x,z,-1));
  8220.  
  8221.       case IN_BUF:                      /* SET INPUT BUFFER-SIZE */
  8222.         if ((z = cmnum("Number of bytes in INPUT buffer",
  8223.                        ckitoa(INPBUFSIZ),10,&x, xxstring)) < 0)
  8224.           return(z);
  8225.         if ((y = cmcfm()) < 0) return(y);
  8226.         inbufsize = 0;
  8227.         if (inpbuf) {
  8228.             free(inpbuf);
  8229.             inpbuf = NULL;
  8230.             inpbp = NULL;
  8231.         }
  8232.         if (!(s = (char *)malloc(x + 1)))
  8233.           return(0);
  8234.         inpbuf = s;
  8235.         inpbp = s;
  8236.         inbufsize = x;
  8237.         for (x = 0; x <= inbufsize; x++)
  8238.           inpbuf[x] = NUL;
  8239.         return(success = 1);
  8240.  
  8241. #ifdef CK_AUTODL
  8242.       case IN_ADL:                      /* AUTODOWNLOAD */
  8243.         return(seton(&inautodl));
  8244. #endif /* CK_AUTODL */
  8245.  
  8246.       case IN_CAN:                      /* SET INPUT INTERRUPTS */
  8247.         return(seton(&inintr));
  8248.     }
  8249.     return(0);
  8250. }
  8251. #endif /* NOSPL */
  8252.  
  8253. #ifdef NETCONN
  8254. VOID
  8255. ndreset() {
  8256. #ifndef NODIAL                          /* This depends on DIAL... */
  8257.     int i=0, j=0;
  8258.     if (!ndinited)                      /* Don't free garbage... */
  8259.       return;
  8260.     for (i = 0; i < nhcount; i++) {     /* Clean out previous list */
  8261.         if (nh_p[i])
  8262.           free(nh_p[i]);
  8263.         nh_p[i] = NULL;
  8264.         if (nh_p2[i])
  8265.           free(nh_p2[i]);
  8266.         nh_p2[i] = NULL;
  8267.         for (j = 0; j < 4; j++) {
  8268.             if (nh_px[j][i])
  8269.               free(nh_px[j][i]);
  8270.             nh_px[j][i] = NULL;
  8271.         }
  8272.     }
  8273. #endif /* NODIAL */
  8274. }
  8275.  
  8276. VOID
  8277. ndinit() {                              /* Net directory pointers */
  8278. #ifndef NODIAL                          /* This depends on DIAL... */
  8279.     int i, j;
  8280.     if (ndinited++)                     /* Don't do this more than once. */
  8281.       return;
  8282.     for (i = 0; i < MAXDDIR; i++) {     /* Init all pointers to NULL */
  8283.         netdir[i] = NULL;
  8284.     }
  8285.     for (i = 0; i < MAXDNUMS; i++) {
  8286.         nh_p[i] = NULL;
  8287.         nh_p2[i] = NULL;
  8288.         for (j = 0; j < 4; j++)
  8289.           nh_px[j][i] = NULL;
  8290.     }
  8291. #endif /* NODIAL */
  8292. }
  8293.  
  8294. #ifndef NODIAL
  8295. #ifdef NETCONN
  8296. VOID                                    /* Get net defaults from environment */
  8297. getnetenv() {
  8298.     char *p = NULL;
  8299.  
  8300.     makestr(&p,getenv("K_NET_DIRECTORY")); /* Dialing directories */
  8301.     if (p) {
  8302.         int i;
  8303.         xwords(p,MAXDDIR,netdir,0);
  8304.         for (i = 0; i < MAXDDIR; i++) { /* Fill in any gaps... */
  8305.             if (!netdir[i+1])
  8306.               break;
  8307.             else
  8308.               netdir[i] = netdir[i+1];
  8309.             debug(F111,"netdir[i]",netdir[i],i);
  8310.         }
  8311.         nnetdir = i;
  8312.     }
  8313. }
  8314. #endif /* NETCONN */
  8315. #endif /* NODIAL */
  8316.  
  8317. int
  8318. #ifdef CK_ANSIC
  8319. lunet(char *s)                          /* s = name to look up   */
  8320. #else
  8321. lunet(s) char *s;
  8322. #endif /* CK_ANSIC */
  8323. /* lunet */ {
  8324. #ifndef NODIAL                          /* This depends on DIAL... */
  8325.     int n, n1, t, dd = 0;
  8326.     int ambiguous = 0;
  8327.     FILE * f;
  8328.     char *line = NULL;
  8329.     extern int dialdpy;
  8330.     int netdpy = dialdpy;
  8331.     char *info[8];
  8332.  
  8333.     nhcount = 0;                        /* Set this before returning */
  8334.  
  8335.     if (!s || nnetdir < 1)              /* Validate arguments */
  8336.       return(-1);
  8337.  
  8338.     if (isdigit(*s) || *s == '*' || *s == '.')
  8339.       return(0);
  8340.  
  8341.     if ((n1 = (int) strlen(s)) < 1)     /* Length of string to look up */
  8342.       return(-1);
  8343.  
  8344.     if (!(line = malloc(1024)))         /* Allocate input buffer */
  8345.       return(-1);
  8346.  
  8347.   lu_again:
  8348.     f = NULL;                           /* Network directory file descriptor */
  8349.     t = nhcount = 0;                    /* Match count */
  8350.     dd = 0;                             /* Directory counter */
  8351.  
  8352.     dirline = 0;
  8353.     while (1) {                         /* We make one pass */
  8354.         if (!f) {                       /* Directory not open */
  8355.             if (dd >= nnetdir)          /* No directories left? */
  8356.               break;                    /* Done. */
  8357.             if ((f = fopen(netdir[dd],"r")) == NULL) { /* Open it */
  8358.                 perror(netdir[dd]);     /* Can't, print message saying why */
  8359.                 dd++;
  8360.                 continue;               /* But go on to next one. */
  8361.             }
  8362.             if (netdpy)
  8363.               printf("Opening %s...\n",netdir[dd]);
  8364.             dd++;
  8365.         }
  8366.         line[0] = NUL;
  8367.         if (getnct(line,1023,f,1) < 0) { /* Read a line */
  8368.             if (f) {                    /* f can be clobbered! */
  8369.                 fclose(f);              /* Close the file */
  8370.                 f = NULL;               /* Indicate next one needs opening */
  8371.             }
  8372.             continue;
  8373.         }
  8374.         if (!line[0])                   /* Empty line */
  8375.           continue;
  8376.  
  8377.         xwords(line,7,info,0);          /* Parse it */
  8378.  
  8379.         if (!info[1] || !info[2] || !info[3]) /* Required fields */
  8380.           continue;
  8381.         if (*info[1] == ';')            /* Full-line comment */
  8382.           continue;
  8383.         if ((n = (int) strlen(info[1])) < 1) /* Length of name-tag */
  8384.           continue;
  8385.         if (n < n1)                     /* Search name is longer */
  8386.           continue;                     /* Can't possibly match */
  8387.         if (ambiguous && n != n1)
  8388.           continue;
  8389.         if (ckstrcmp(s,info[1],n1,0))   /* Compare using length of */
  8390.           continue;                     /* search string s. */
  8391.  
  8392.         /* Have a match */
  8393.  
  8394.         makestr(&(nh_p[nhcount]), info[3]);    /* address */
  8395.         makestr(&(nh_p2[nhcount]),info[2]);    /* net type */
  8396.         makestr(&(nh_px[0][nhcount]),info[4]); /* net-specific stuff... */
  8397.         makestr(&(nh_px[1][nhcount]),info[5]);
  8398.         makestr(&(nh_px[2][nhcount]),info[6]);
  8399.         makestr(&(nh_px[3][nhcount]),info[7]);
  8400.  
  8401.         nhcount++;                      /* Count this match */
  8402.         if (nhcount > MAXDNUMS) {       /* Watch out for too many */
  8403.             printf("Warning: %d matches found, %d max\n",
  8404.                    nhcount,
  8405.                    MAXDNUMS
  8406.                    );
  8407.             nhcount = MAXDNUMS;
  8408.             break;
  8409.         }
  8410.         if (nhcount == 1) {             /* First one - save entry name */
  8411.             if (n_name) {               /* Free the one from before if any */
  8412.                 free(n_name);
  8413.                 n_name = NULL;
  8414.             }
  8415.             if (!(n_name = (char *)malloc(n + 1))) { /* Allocate new storage */
  8416.                 printf("?memory allocation error - lunet:3\n");
  8417.                 if (line) {
  8418.                     free(line);
  8419.                     line = NULL;
  8420.                 }
  8421.                 nhcount = 0;
  8422.                 return(-1);
  8423.             }
  8424.             t = n;                      /* Remember its length */
  8425.             strcpy(n_name,info[1]);     /* safe */
  8426.         } else {                        /* Second or subsequent one */
  8427.             if ((int) strlen(info[1]) == t) /* Lengths compare */
  8428.               if (!ckstrcmp(n_name,info[1],t,0)) /* Caseless compare OK */
  8429.                 continue;
  8430.  
  8431.             /* Name given by user matches entries with different names */
  8432.  
  8433.             if (ambiguous)              /* Been here before */
  8434.               break;
  8435.  
  8436.             ambiguous = 1;              /* Now an exact match is required */
  8437.             ndreset();                  /* Clear out previous list */
  8438.             goto lu_again;              /* Do it all over again. */
  8439.         }
  8440.     }
  8441.     if (line) {
  8442.         free(line);
  8443.         line = NULL;
  8444.     }
  8445.     if (nhcount == 0 && ambiguous)
  8446.       printf("?\"%s\" - ambiguous in network directory\n",s);
  8447. #else
  8448.     nhcount = 0;
  8449. #endif /* NODIAL */
  8450.     return(nhcount);
  8451. }
  8452. #endif /* NETCONN */
  8453.  
  8454. #ifndef NOLOCAL
  8455. /*  C L S C O N N X  --  Close connection  */
  8456.  
  8457. int
  8458. clsconnx(ask) int ask; {
  8459.     int x, rc = 0;
  8460. #ifdef NEWFTP
  8461.     extern int ftpget, ftpisopen(), ftpbye();
  8462.     if ((ftpget == 1) || ((ftpget == 2) && !local && ftpisopen()))
  8463.       return(success = ftpbye());
  8464. #endif /* NEWFTP */
  8465.     debug(F101,"clsconnx local","",local);
  8466.     if (local) {
  8467.         x = ask ? hupok(1) : 1;         /* Make sure it's OK to close */
  8468.         if (!x) {
  8469.             rc = -1;
  8470.             debug(F101,"clsconnx hupok says no","",rc);
  8471.             return(rc);
  8472.         }
  8473.         ttflui();                       /* Clear away buffered up junk */
  8474. #ifndef NODIAL
  8475. #ifdef OS2ONLY
  8476. /* Don't hangup a line that is shared with the SLIP or PPP driver */
  8477.         if (!ttslip && !ttppp)
  8478. #endif /* OS2ONLY */
  8479.           mdmhup();
  8480. #endif /* NODIAL */
  8481.         if (network && msgflg)
  8482.           printf(" Closing connection\n");
  8483.         ttclos(0);                      /* Close old connection, if any */
  8484.         rc = 1;
  8485.         {
  8486.             extern int wasclosed, whyclosed;
  8487.             if (wasclosed) {
  8488.                 whyclosed = WC_CLOS;
  8489. #ifndef NOSPL
  8490.                 if (nmac) {             /* Any macros defined? */
  8491.                     int k;              /* Yes */
  8492.                     /* printf("ON_CLOSE CLSCONNX\n"); */
  8493.                     wasclosed = 0;
  8494.                     k = mlook(mactab,"on_close",nmac);  /* Look this up */
  8495.                     if (k >= 0) {                       /* If found, */
  8496.                         if (dodo(k,ckitoa(whyclosed),0) > -1) /* set it up, */
  8497.                           parser(1);                    /* and execute it */
  8498.                     }
  8499.                 }
  8500. #endif /* NOSPL */
  8501.                 whyclosed = WC_REMO;
  8502.                 wasclosed = 0;
  8503.             }
  8504.         }
  8505.     }
  8506. #ifdef VMS                              /* Or maybe #ifndef UNIX? */
  8507.     else {                              /* Need to do this in VMS to */
  8508.         ttclos(0);                      /* free the tty channel number */
  8509.         rc = 1;                         /* obtained in ttopen() or else */
  8510.     }                                   /* subsequent ttopen's won't work */
  8511. #endif /* VMS */
  8512.     dologend();
  8513.     haveline = 0;
  8514.     if (mdmtyp < 0) {                   /* Switching from net to async? */
  8515.         if (mdmsav > -1)                /* Restore modem type from last */
  8516.           mdmtyp = mdmsav;              /* SET MODEM command, if any. */
  8517.         else
  8518.           mdmtyp = 0;
  8519.         mdmsav = -1;
  8520.     }
  8521.     if (network)
  8522.       network = 0;
  8523. #ifdef NETCONN
  8524.     if (oldplex > -1) {                 /* Restore previous duplex setting. */
  8525.         duplex = oldplex;
  8526.         oldplex = -1;
  8527.     }
  8528. #endif /* NETCONN */
  8529. #ifndef MAC
  8530.     ckstrncpy(ttname,dftty,TTNAMLEN);   /* Restore default communication */
  8531. #endif /* MAC */
  8532.     local = dfloc;                      /* device and local/remote status */
  8533.     if (local) {
  8534.         cxtype = CXT_DIRECT;            /* Something reasonable */
  8535.         speed = ttgspd();               /* Get the current speed */
  8536.     } else {
  8537.         cxtype = CXT_REMOTE;
  8538.         speed = -1L;
  8539.     }
  8540. #ifndef NOXFER
  8541.     if (xreliable > -1 && !setreliable) {
  8542.         reliable = xreliable;
  8543.         debug(F101,"clsconnx reliable A","",reliable);
  8544.     } else if (!setreliable) {
  8545.         reliable = SET_AUTO;
  8546.         debug(F101,"clsconnx reliable B","",reliable);
  8547.     }
  8548. #endif /* NOXFER */
  8549.     setflow();                          /* Revert flow control */
  8550.     return(rc);
  8551. }
  8552.  
  8553. int
  8554. clskconnx(x) int x; {                   /* Close Kermit connection only */
  8555.     int t, rc;                          /* (not FTP) */
  8556. #ifdef NEWFTP
  8557.     extern int ftpget;
  8558.     t = ftpget;
  8559.     ftpget = 0;
  8560. #endif /* NEWFTP */
  8561.     rc = clsconnx(x);
  8562. #ifdef NEWFTP
  8563.     ftpget = t;
  8564. #endif /* NEWFTP */
  8565.     return(rc);
  8566. }
  8567.  
  8568. /* May 2002: setlin() decomposition starts here ... */
  8569.  
  8570. #ifdef OS2
  8571. #define SRVBUFSIZ PIPENAML
  8572. #else /* OS2 */
  8573. #define SRVBUFSIZ 63
  8574. #endif /* OS2 */
  8575. #define HOSTNAMLEN 15*65
  8576.  
  8577. int netsave = -1;
  8578. static char * tmpstring = NULL;
  8579. static char * tmpusrid = NULL;
  8580.  
  8581. #ifdef SSHCMD
  8582. char * sshcmd = NULL;
  8583. char * defsshcmd = "ssh -e none";
  8584. #else
  8585. #ifdef SSHBUILTIN
  8586. char * sshrcmd = NULL;
  8587. char * sshtmpcmd = NULL;
  8588. #endif /* SSHBUILTIN */
  8589. #endif /* SSHCMD */
  8590.  
  8591. /* c x _ f a i l  --  Common error exit routine for cx_net, cx_line */
  8592.  
  8593. int
  8594. cx_fail(msg, text) int msg; char * text; {
  8595.     makestr(&slmsg,text);        /* For the record (or GUI) */
  8596.     if (msg)                /* Not GUI, not quiet, etc */
  8597.       printf("?%s\n",text);        /* Print error message */
  8598.     slrestor();                /* Restore LINE/HOST to known state */
  8599.     return(msg ? -9 : (success = 0));    /* Return appropriate code */
  8600. }
  8601.  
  8602. #ifdef NETCONN
  8603. /* c x _ n e t  --  Make a network connection */
  8604.  
  8605. /*
  8606.   Call with:
  8607.     net      = network type
  8608.     protocol = protocol type
  8609.     host     = string pointer to host name.
  8610.     svc      = string pointer to service or port on host.
  8611.     username = username for connection
  8612.     password = password for connection
  8613.     command  = command to execute
  8614.     param1   = Telnet: Authentication type
  8615.                SSH:    Version
  8616.     param2   = Telnet: Encryption type
  8617.                SSH:    Command as Subsystem
  8618.     param3   = Telnet: 1 to wait for negotiations, 0 otherwise
  8619.                SSH:    X11 Forwarding
  8620.     cx       = 1 to automatically enter Connect mode, 0 otherwise.
  8621.     sx       = 1 to automatically enter Server mode, 0 otherwise.
  8622.     flag     = if no host name given, 1 = close current connection, 0 = resume
  8623.     gui      = 1 if called from GUI dialog, 0 otherwise.
  8624.   Returns:
  8625.     1 on success
  8626.     0 on failure and no message printed, slmsg set to failure message.
  8627.    -9 on failure and message printed, ditto.
  8628. */
  8629. int
  8630. #ifdef CK_ANSIC
  8631. cx_net( int net, int protocol, char * xhost, char * svc, 
  8632.         char * username, char * password, char * command,
  8633.         int param1, int param2, int param3, int cx, int sx, int flag, int gui)
  8634. #else /* CK_ANSIC */
  8635. cx_net(net, protocol, xhost, svc,
  8636.        username, password, command,
  8637.        param1, param2, param3, cx, sx, flag, gui)
  8638.     char * xhost, * svc, * username, *password, *command; 
  8639.     int net, protocol, cx, sx, flag, param1, param2, param3, gui; 
  8640. #endif /* CK_ANSIC */
  8641. /* cx_net */ {
  8642.  
  8643.     int i, n, x, msg;
  8644.     int _local = -1;
  8645.  
  8646.     extern char pwbuf[], * g_pswd;
  8647.     extern int pwflg, pwcrypt, g_pflg, g_pcpt, nolocal;
  8648.  
  8649.     char srvbuf[SRVBUFSIZ+1];        /* Service */
  8650.     char hostbuf[HOSTNAMLEN];        /* Host buffer to manipulate */
  8651.     char hostname[HOSTNAMLEN];        /* Copy of host parameter */
  8652.     char * host = hostbuf;        /* Pointer to copy of host param */
  8653.  
  8654.     if (!xhost) xhost = "";        /* Watch out for null pointers */
  8655.     if (!svc) svc = "";
  8656.     ckstrncpy(host,xhost,HOSTNAMLEN);    /* Avoid buffer confusion */
  8657.  
  8658.     debug(F110,"cx_net host",host,0);
  8659.     debug(F111,"cx_net service",svc,SRVBUFSIZ);
  8660.     debug(F101,"cx_net network type","",net);
  8661.  
  8662.     msg = (gui == 0) && msgflg;        /* Whether to print messages */
  8663.  
  8664. #ifndef NODIAL
  8665.     debug(F101,"cx_net nnetdir","",nnetdir);
  8666.     x = 0;                /* Look up in network directory */
  8667.     if (*host == '=') {            /* If number starts with = sign */
  8668.     host++;                /* strip it */
  8669.     while (*host == SP) host++;    /* and any leading spaces */
  8670.     debug(F110,"cx_net host 2",host,0);
  8671.     nhcount = 0;
  8672.     } else if (*host) {            /* We want to look it up. */
  8673.     if (nnetdir > 0)        /* If there is a directory... */
  8674.       x = lunet(host);        /* (sets nhcount) */
  8675.     else                /* otherwise */
  8676.       nhcount = 0;            /* we didn't find any there */
  8677.     if (x < 0)            /* Internal error? */
  8678.       return(cx_fail(msg,"Network directory lookup error"));
  8679.     debug(F111,"cx_net lunet nhcount",host,nhcount);
  8680.     }
  8681. #endif /* NODIAL */
  8682.  
  8683.     /* New connection wanted.  Make a copy of the host name/address... */
  8684.  
  8685.     if (clskconnx(1) < 0)        /* Close current Kermit connection */
  8686.       return(cx_fail(msg,"Error closing previous connection"));
  8687.  
  8688.     if (*host) {            /* They gave a hostname */
  8689.     _local = 1;            /* Network connection always local */
  8690.     if (mdmsav < 0)
  8691.       mdmsav = mdmtyp;        /* Remember old modem type */
  8692.     mdmtyp = -net;            /* Special code for network */
  8693.     } else {                /* They just said "set host" */
  8694.     host = dftty;            /* So go back to normal */
  8695.     _local = dfloc;            /* default tty, location, */
  8696.     if (flag) {            /* Close current connection */
  8697.         setflow();            /* Maybe change flow control */
  8698.         haveline = 1;        /* (* is this right? *) */
  8699.         dologend();
  8700. #ifndef NODIAL
  8701.         dialsta = DIA_UNK;
  8702. #endif /* NODIAL */
  8703. #ifdef LOCUS
  8704.         if (autolocus) {
  8705.         setlocus(1,1);
  8706.         }
  8707. #endif /* LOCUS */
  8708.             /* XXX - Is this right? */
  8709.         /* Should we be returning without doing anything ? */
  8710.         /* Yes it's right -- we closed the old connection just above. */
  8711.         return(success = 1);        
  8712.     }
  8713.     }
  8714.     success = 0;
  8715.     if (host != line)                   /* line[] is a global */
  8716.       ckstrncpy(line,host,LINBUFSIZ);
  8717.     ckstrncpy(hostname,host,HOSTNAMLEN);
  8718.     ckstrncpy(srvbuf,svc,SRVBUFSIZ+1);
  8719.  
  8720. #ifndef NODIAL
  8721.     if ((nhcount > 1) && msg) {
  8722.     int k;
  8723.     printf("%d entr%s found for \"%s\"%s\n",
  8724.            nhcount,
  8725.            (nhcount == 1) ? "y" : "ies",
  8726.            s,
  8727.            (nhcount > 0) ? ":" : "."
  8728.            );
  8729.     for (i = 0; i < nhcount; i++) {
  8730.         printf("%3d. %-12s => %-9s %s",
  8731.                i+1,n_name,nh_p2[i],nh_p[i]);
  8732.         for (k = 0; k < 4; k++) { /* Also list net-specific items */
  8733.         if (nh_px[k][i])      /* free format... */
  8734.           printf(" %s",nh_px[k][i]);
  8735.         else
  8736.           break;
  8737.         }
  8738.         printf("\n");
  8739.     }
  8740.     }
  8741.     if (nhcount == 0)
  8742.       n = 1;
  8743.     else
  8744.       n = nhcount;
  8745. #else
  8746.     n = 1;
  8747.     nhcount = 0;
  8748. #endif /* NODIAL */
  8749.  
  8750.     for (i = 0; i < n; i++) {        /* Loop for each entry found */
  8751.     debug(F101,"cx_net loop i","",i);
  8752. #ifndef NODIAL
  8753.     if (nhcount > 0) {        /* If we found at least one entry... */
  8754.         ckstrncpy(line,nh_p[i],LINBUFSIZ); /* Copy current entry */
  8755.         if (lookup(netcmd,nh_p2[i],nnets,&x) > -1) { /* Net type */
  8756.         int xx;
  8757.         xx = netcmd[x].kwval;
  8758.         /* User specified SSH so don't let net directory override */
  8759.         if (net != NET_SSH || xx != NET_TCPB) {
  8760.             net = xx;
  8761.             mdmtyp  = 0 - net;
  8762.         }
  8763.         } else {
  8764.         makestr(&slmsg,"Network type not supported");
  8765.         if (msg)
  8766.           printf("Error - network type \"%s\" not supported\n",
  8767.              nh_p2[i]
  8768.                  );
  8769.         continue;
  8770.         }
  8771.         switch (net) {        /* Net-specific directory things */
  8772. #ifdef SSHBUILTIN
  8773.           case NET_SSH:        /* SSH */
  8774.                 /* Any SSH specific network directory stuff? */
  8775.                 break;                  /* NET_SSH */
  8776. #endif /* SSHBUILTIN */
  8777.  
  8778.           case NET_TCPB: {        /* TCP/IP TELNET,RLOGIN,... */
  8779. #ifdef TCPSOCKET
  8780.           char *q;
  8781.           int flag = 0;
  8782.  
  8783.           /* Extract ":service", if any, from host string */
  8784.           debug(F110,"cx_net service 1",line,0);
  8785.           for (q = line; (*q != '\0') && (*q != ':'); q++)
  8786.             ;
  8787.           if (*q == ':') { *q++ = NUL; flag = 1; }
  8788.           debug(F111,"cx_net service 2",line,flag);
  8789.  
  8790.           /* Get service, if any, from directory entry */
  8791.  
  8792.           if (!*srvbuf) {
  8793.               if (nh_px[0][i]) {
  8794.               ckstrncpy(srvbuf,nh_px[0][i],SRVBUFSIZ);
  8795.               debug(F110,"cx_net service 3",srvbuf,0);
  8796.               }
  8797.               if (flag) {
  8798.               ckstrncpy(srvbuf,q,SRVBUFSIZ);
  8799.               debug(F110,"cx_net service 4",srvbuf,0);
  8800.               }
  8801.           }
  8802.           ckstrncpy(hostname,line,HOSTNAMLEN);
  8803.  
  8804.           /* If we have a service, append to host name/address */
  8805.           if (*srvbuf) {
  8806.               ckstrncat(line, ":", LINBUFSIZ);
  8807.               ckstrncat(line, srvbuf, LINBUFSIZ);
  8808.               debug(F110,"cx_net service 5",line,0);
  8809.           }
  8810. #ifdef RLOGCODE
  8811.           /* If no service given but command was RLOGIN */
  8812.           else if (ttnproto == NP_RLOGIN) { /* add this... */
  8813.               ckstrncat(line, ":login",LINBUFSIZ);
  8814.               debug(F110,"cx_net service 6",line,0);
  8815.           }
  8816. #ifdef CK_AUTHENTICATION
  8817. #ifdef CK_KERBEROS
  8818.           else if (ttnproto == NP_K4LOGIN ||
  8819.                ttnproto == NP_K5LOGIN) { /* add this... */
  8820.               ckstrncat(line, ":klogin",LINBUFSIZ);
  8821.               debug(F110,"cx_net service 7",line,0);
  8822.           }
  8823.           else if (ttnproto == NP_EK4LOGIN ||
  8824.                ttnproto == NP_EK5LOGIN) { /* add this... */
  8825.               ckstrncat(line, ":eklogin",LINBUFSIZ);
  8826.               debug(F110,"cx_net service 8",line,0);
  8827.           }
  8828. #endif /* CK_KERBEROS */
  8829. #endif /* CK_AUTHENTICATION */
  8830. #endif /* RLOGCODE */
  8831.           else {        /* Otherwise, add ":telnet". */
  8832.               ckstrncat(line, ":telnet", LINBUFSIZ);
  8833.               debug(F110,"cx_net service 9",line,0);
  8834.           }
  8835.           if (username) {    /* This is a parameter... */
  8836.               ckstrncpy(uidbuf,username,UIDBUFLEN);
  8837.               uidflag = 1;
  8838.           }
  8839.           /* Fifth field, if any, is user ID (for rlogin) */
  8840.  
  8841.           if (nh_px[1][i] && !uidflag)
  8842.             ckstrncpy(uidbuf,username,UIDBUFLEN);
  8843. #ifdef RLOGCODE
  8844.           if (IS_RLOGIN() && !uidbuf[0])
  8845.             return(cx_fail(msg,"Username required"));
  8846. #endif /* RLOGCODE */
  8847. #endif /* TCPSOCKET */
  8848.           break;
  8849.           }
  8850.           case NET_PIPE:        /* Pipe */
  8851. #ifdef NPIPE
  8852.         if (!pipename[0]) { /* User didn't give a pipename */
  8853.             if (nh_px[0][i]) { /* But directory entry has one */
  8854.             if (strcmp(pipename,"\\pipe\\")) {
  8855.                 ckstrncpy(pipename,"\\pipe\\",LINBUFSIZ);
  8856.                 ckstrncat(srvbuf,nh_px[0][i],PIPENAML-6);
  8857.             } else {
  8858.                 ckstrncpy(pipename,nh_px[0][i],PIPENAML);
  8859.             }
  8860.             debug(F110,"cx_net pipeneme",pipename,0);
  8861.             }
  8862.         }
  8863. #endif /* NPIPE */
  8864.         break;
  8865.  
  8866.           case NET_SLAT:            /* LAT / CTERM */
  8867. #ifdef SUPERLAT
  8868.         if (!slat_pwd[0]) { /* User didn't give a password */
  8869.             if (nh_px[0][i]) { /* But directory entry has one */
  8870.             ckstrncpy(slat_pwd,nh_px[0][i],18);
  8871.             debug(F110,"cx_net SuperLAT password",slat_pwd,0);
  8872.             }
  8873.         }
  8874. #endif /* SUPERLAT */
  8875.         break;
  8876.  
  8877.           case NET_SX25:        /* X.25 keyword parameters */
  8878.           case NET_IX25:
  8879.           case NET_VX25: {
  8880. #ifdef ANYX25
  8881.           int k;            /* Cycle through the four fields */
  8882.           for (k = 0; k < 4; k++) {
  8883.               if (!nh_px[k][i]) /* Bail out if none left */
  8884.             break;
  8885.               if (!ckstrcmp(nh_px[k][i],"cug=",4,0)) {
  8886.               closgr = atoi(nh_px[k][i]+4);
  8887.               debug(F101,"X25 CUG","",closgr);
  8888.               } else if (!ckstrcmp(nh_px[k][i],"cud=",4,0)) {
  8889.               cudata = 1;
  8890.               ckstrncpy(udata,nh_px[k][i]+4,MAXCUDATA);
  8891.               debug(F110,"X25 CUD",cudata,0);
  8892.               } else if (!ckstrcmp(nh_px[k][i],"rev=",4,0)) {
  8893.               revcall = !ckstrcmp(nh_px[k][i]+4,"=on",3,0);
  8894.               debug(F101,"X25 REV","",revcall);
  8895. #ifndef IBMX25
  8896.               } else if (!ckstrcmp(nh_px[k][i],"pad=",4,0)) {
  8897.               int x3par, x3val;
  8898.               char *s1, *s2;
  8899.               s1 = s2 = nh_px[k][i]+4; /* PAD parameters */
  8900.               while (*s2) {            /* Pick them apart */
  8901.                   if (*s2 == ':') {
  8902.                   *s2 = NUL;
  8903.                   x3par = atoi(s1);
  8904.                   s1 = ++s2;
  8905.                   continue;
  8906.                   } else if (*s2 == ',') {
  8907.                   *s2 = NUL;
  8908.                   x3val = atoi(s1);
  8909.                   s1 = ++s2;
  8910.                   debug(F111,"X25 PAD",x3par,x3val);
  8911.                   if (x3par > -1 &&
  8912.                       x3par <= MAXPADPARMS)
  8913.                     padparms[x3par] = x3val;
  8914.                   continue;
  8915.                   } else
  8916.                 s2++;
  8917.               }
  8918. #endif /* IBMX25 */
  8919.               }
  8920.           }
  8921. #endif /* ANYX25 */
  8922.           break;
  8923.           }
  8924.           default:            /* Nothing special for other nets */
  8925.         break;
  8926.         }
  8927.     } else
  8928. #endif /* NODIAL */
  8929.     {                /* No directory entries found. */
  8930.         ckstrncpy(line,hostname,LINBUFSIZ); /* Put this back... */
  8931.         /* If the user gave a TCP service */
  8932.         if (net == NET_TCPB || net == NET_SSH)
  8933.           if (*srvbuf) {        /* Append it to host name/address */
  8934.           ckstrncat(line, ":", LINBUFSIZ);
  8935.           ckstrncat(line, srvbuf,LINBUFSIZ);
  8936.           }
  8937.     }
  8938.     /*
  8939.        Get here with host name/address and all net-specific
  8940.        parameters set, ready to open the connection.
  8941.     */
  8942.     mdmtyp = -net;            /* This should have been done */
  8943.                     /* already but just in case ... */
  8944.  
  8945.     debug(F110,"cx_net net line[] before ttopen",line,0);
  8946.     debug(F101,"cx_net net mdmtyp before ttopen","",mdmtyp);
  8947.     debug(F101,"cx_net net ttnproto","",ttnproto);
  8948.  
  8949. #ifdef SSHBUILTIN
  8950.         if (net == NET_SSH) {
  8951.             makestr(&ssh_hst,hostname);        /* Stash everything */
  8952.             if (username) {
  8953.                 if (!sl_uid_saved) {
  8954.                     ckstrncpy(sl_uidbuf,uidbuf,UIDBUFLEN);
  8955.                     sl_uid_saved = 1;
  8956.                 }
  8957.                 ckstrncpy(uidbuf,username,UIDBUFLEN);
  8958.             }
  8959.             if (srvbuf[0]) {
  8960.                 makestr(&ssh_prt,srvbuf);
  8961.             } else
  8962.                 makestr(&ssh_prt,NULL);
  8963.  
  8964.             if (command) {
  8965.                 makestr(&ssh_cmd,brstrip(command));
  8966.                 ssh_cas = param2;
  8967.             } else
  8968.                 makestr(&ssh_cmd,NULL);
  8969.  
  8970.             if (param1 > -1) {
  8971. #ifndef SSHTEST
  8972.                 if (!sl_ssh_ver_saved) {
  8973.                     sl_ssh_ver = ssh_ver;
  8974.                     sl_ssh_ver_saved = 1;
  8975.                 }
  8976. #endif /* SSHTEST */
  8977.                 ssh_ver = param1;
  8978.             }
  8979.             if (param3 > -1) {
  8980. #ifndef SSHTEST
  8981.                 if (!sl_ssh_xfw_saved) {
  8982.                     sl_ssh_xfw = ssh_xfw;
  8983.                     sl_ssh_xfw_saved = 1;
  8984.                 }
  8985. #endif /* SSHTEST */
  8986.                 ssh_xfw = param3;
  8987.             }
  8988.         } else                          /* NET_SSH */
  8989. #endif /* SSHBUILTIN */
  8990. #ifdef TCPSOCKET
  8991.       if (net == NET_TCPB) {
  8992.             switch (protocol) {
  8993. #ifdef CK_SSL
  8994.           case NP_SSL:
  8995.                 ttnproto = protocol;
  8996.                 ssl_only_flag = 1;
  8997.                 tls_only_flag = 0;
  8998.                 break;
  8999.  
  9000.           case NP_TLS:
  9001.                 ttnproto = protocol;
  9002.                 ssl_only_flag = 0;
  9003.                 tls_only_flag = 1;
  9004.                 break;
  9005.  
  9006.           case NP_SSL_TELNET:
  9007.                 ttnproto = NP_TELNET;
  9008.                 ssl_only_flag = 1;
  9009.                 tls_only_flag = 0;
  9010.                 break;
  9011.  
  9012.           case NP_TLS_TELNET:
  9013.                 ttnproto = NP_TELNET;
  9014.                 ssl_only_flag = 0;
  9015.                 tls_only_flag = 1;
  9016.                 break;
  9017. #endif /* CK_SSL */
  9018.           case NP_NONE:
  9019.           case NP_TCPRAW:
  9020.           case NP_RLOGIN:
  9021.           case NP_K4LOGIN:
  9022.           case NP_K5LOGIN:
  9023.           case NP_EK4LOGIN:
  9024.           case NP_EK5LOGIN:
  9025.           case NP_TELNET:
  9026.           case NP_KERMIT:
  9027.           default:
  9028.                 ttnproto = protocol;
  9029. #ifdef CK_SSL
  9030.                 ssl_only_flag = 0;
  9031.                 tls_only_flag = 0;
  9032. #endif /* CK_SSL */
  9033.                 break;
  9034.             }
  9035. #ifdef CK_AUTHENTICATION
  9036.             if ((ttnproto == NP_TELNET || ttnproto == NP_KERMIT) &&
  9037.         param1 > -1) {
  9038.         if (!sl_auth_saved) {
  9039.         int x;
  9040.         for (x = 0; x < AUTHTYPLSTSZ; x++)
  9041.           sl_auth_type_user[x] = auth_type_user[x];
  9042.         sl_auth_saved = 1;
  9043.         }
  9044.         if (!sl_topt_a_s_saved) {
  9045.         sl_topt_a_su = TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION);
  9046.         sl_topt_a_s_saved = 1;
  9047.         }
  9048.         if (!sl_topt_a_c_saved) {
  9049.         sl_topt_a_cm = TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION);
  9050.         sl_topt_a_c_saved = 1;
  9051.         }
  9052.         switch (param1) {
  9053.           case AUTHTYPE_AUTO:
  9054.         auth_type_user[0] = AUTHTYPE_AUTO;
  9055.         TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_RQ;
  9056.         TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_RQ;
  9057.         break;
  9058.           case AUTHTYPE_NULL:
  9059.         auth_type_user[0] = AUTHTYPE_NULL;
  9060.         TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_RF;
  9061.         TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_RF;
  9062.         break;
  9063. #ifdef CK_SRP
  9064.           case AUTHTYPE_SRP:
  9065.         auth_type_user[0] = AUTHTYPE_SRP;
  9066.         auth_type_user[1] = AUTHTYPE_NULL;
  9067.         TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  9068.         TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  9069.         break;
  9070. #endif /* CK_SRP */
  9071. #ifdef CK_SSL
  9072.           case AUTHTYPE_SSL:
  9073.         auth_type_user[0] = AUTHTYPE_SSL;
  9074.         auth_type_user[1] = AUTHTYPE_NULL;
  9075.         TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  9076.         TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  9077.         break;
  9078. #endif /* CK_SSL */
  9079. #ifdef NT
  9080.           case AUTHTYPE_NTLM:
  9081.         auth_type_user[0] = AUTHTYPE_NTLM;
  9082.         auth_type_user[1] = AUTHTYPE_NULL;
  9083.         TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  9084.         TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  9085.         break;
  9086. #endif /* NT */
  9087. #ifdef CK_KERBEROS
  9088.           case AUTHTYPE_KERBEROS_V4:
  9089.         auth_type_user[0] = AUTHTYPE_KERBEROS_V4;
  9090.         auth_type_user[1] = AUTHTYPE_NULL;
  9091.         TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  9092.         TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  9093.         break;
  9094.  
  9095.           case AUTHTYPE_KERBEROS_V5:
  9096.         auth_type_user[0] = AUTHTYPE_KERBEROS_V5;
  9097.         auth_type_user[1] = AUTHTYPE_NULL;
  9098.         TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  9099.         TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  9100.         break;
  9101. #endif /* CK_KERBEROS */
  9102.         }
  9103.     }
  9104.     /*
  9105.        If the user requires a particular type of Kerberos connection,
  9106.        make sure we have a valid TGT.
  9107.     */
  9108.     makestr(&slmsg,"Authentication failure");
  9109.     if ((ttnproto == NP_TELNET || ttnproto == NP_KERMIT) &&
  9110.         (line[0] == '*' &&
  9111.          TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) == TN_NG_MU ||
  9112.          line[0] != '*' &&
  9113.          TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) == TN_NG_MU)
  9114.         ) {
  9115. #ifdef CK_KERBEROS
  9116.         if ( auth_type_user[0] == AUTHTYPE_KERBEROS_V4 ) {
  9117.         extern int krb4_autoget;
  9118.         if (!ck_krb4_is_installed())
  9119.           return(cx_fail(msg,
  9120.           "Required authentication method (Kerberos 4) is not installed"));
  9121. #ifdef COMMENT
  9122.         /* This code results in false failures when using */
  9123.         /* kerberos to machines in realms other than the  */
  9124.         /* default since we don't know the realm of the   */
  9125.         /* other machine until perform the reverse DNS    */
  9126.         /* lookup.                                        */
  9127.         else if (line[0] != '*' && !ck_krb4_is_tgt_valid() &&
  9128.                (!krb4_autoget ||
  9129.                 krb4_autoget && !ck_krb4_autoget_TGT(NULL))) {
  9130.             return(cx_fail(msg,
  9131.                "Kerberos 4: Ticket Getting Ticket not valid"));
  9132.         }
  9133. #endif /* COMMENT */
  9134.         } else if (auth_type_user[0] == AUTHTYPE_KERBEROS_V5) {
  9135.         extern int krb5_autoget;
  9136.         if (!ck_krb5_is_installed()) {
  9137.             return(cx_fail(msg,
  9138.        "Required authentication method (Kerberos 5) is not installed"));
  9139.         }
  9140. #ifdef COMMENT
  9141.         /* This code results in false failures when using */
  9142.         /* kerberos to machines in realms other than the  */
  9143.         /* default since we don't know the realm of the   */
  9144.         /* other machine until perform the reverse DNS    */
  9145.         /* lookup.                                        */
  9146.         else if (line[0] != '*' && !ck_krb5_is_tgt_valid() &&
  9147.                (!krb5_autoget ||
  9148.                 krb5_autoget && !ck_krb5_autoget_TGT(NULL))) {
  9149.             return(cx_fail(msg,
  9150.              "Kerberos 5: Ticket Getting Ticket not valid."));
  9151.         }
  9152. #endif /* COMMENT */
  9153.         }
  9154. #endif /* CK_KERBEROS */
  9155. #ifdef NT
  9156.         if (auth_type_user[0] == AUTHTYPE_NTLM) {
  9157.         if (!ck_ntlm_is_installed()) {
  9158.             return(cx_fail(msg,
  9159.            "Required authentication method (NTLM) is not installed"));
  9160.         } else if (line[0] != '*' && !ck_ntlm_is_valid(0)) {
  9161.             return(cx_fail(msg,"NTLM: Credentials are unavailable."));
  9162.         }
  9163.         }
  9164. #endif /* NT */
  9165. #ifdef CK_SSL
  9166.         if (auth_type_user[0] == AUTHTYPE_SSL) {
  9167.         if (!ck_ssleay_is_installed()) {
  9168.             return(cx_fail(msg,
  9169.              "Required authentication method (SSL) is not installed"));
  9170.         }
  9171.         }
  9172. #endif /* CK_SSL */
  9173. #ifdef CK_SRP
  9174.         if (auth_type_user[0] == AUTHTYPE_SRP) {
  9175.         if (!ck_srp_is_installed()) {
  9176.             return(cx_fail(msg,
  9177.              "Required authentication method (SRP) is not installed"));
  9178.         }
  9179.         }
  9180. #endif /* CK_SRP */
  9181.     }
  9182. #endif /* CK_AUTHENTICATION */
  9183. #ifdef CK_ENCRYPTION
  9184.     if ((ttnproto == NP_TELNET || ttnproto == NP_KERMIT) &&
  9185.          param2 > -1) {
  9186.         if (!sl_cx_saved) {
  9187.         sl_cx_type = cx_type;
  9188.         sl_cx_saved = 1;
  9189.         }
  9190.         if (!sl_topt_e_s_saved) {
  9191.         sl_topt_e_su = TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION);
  9192.         sl_topt_e_sm = TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION);
  9193.         sl_topt_e_s_saved = 1;
  9194.         }
  9195.         if (!sl_topt_e_c_saved) {
  9196.         sl_topt_e_cu = TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION);
  9197.         sl_topt_e_cm = TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION);
  9198.         sl_topt_e_c_saved = 1;
  9199.         }
  9200.         cx_type = param2;
  9201.         if (cx_type == CX_AUTO) {
  9202.         TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION) = TN_NG_RQ;
  9203.         TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_RQ;
  9204.         TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION) = TN_NG_RQ;
  9205.         TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_RQ;
  9206.         } else if (cx_type == CX_NONE) {
  9207.         TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION) = TN_NG_RF;
  9208.         TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_RF;
  9209.         TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION) = TN_NG_RF;
  9210.         TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_RF;
  9211.         } else {
  9212.         TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION) = TN_NG_MU;
  9213.         TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_MU;
  9214.         TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION) = TN_NG_MU;
  9215.         TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_MU;
  9216.         }
  9217.     }
  9218.     if (ttnproto == NP_EK4LOGIN || ttnproto == NP_EK5LOGIN ||
  9219.         (ttnproto == NP_TELNET || ttnproto == NP_KERMIT) &&
  9220.         ((line[0] == '*' &&
  9221.           TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION) == TN_NG_MU &&
  9222.           TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION) == TN_NG_MU) ||
  9223.          (line[0] != '*' &&
  9224.           TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION) == TN_NG_MU &&
  9225.           TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION) == TN_NG_MU))
  9226.         ) {
  9227.         if (!ck_crypt_is_installed()) {
  9228.         return(cx_fail(msg,
  9229.           "Required Encryption methods are not installed"));
  9230.         }
  9231.     }
  9232. #endif /* CK_ENCRYPTION */
  9233. #ifdef RLOGCODE
  9234. #ifdef CK_KERBEROS
  9235. #ifdef KRB4
  9236.     if (ttnproto == NP_K4LOGIN || ttnproto == NP_EK4LOGIN) {
  9237.         extern int krb4_autoget;
  9238.         char tgt[256];
  9239.         char * realm;
  9240.  
  9241.         /* We don't have the full hostname at yet so  */
  9242.         /* we do a DNS lookup before calling ttopen() */ 
  9243.  
  9244.         realm = ck_krb4_realmofhost(ckgetfqhostname(hostname));
  9245.         ckmakmsg(tgt,256,"krbtgt.",realm,"@",realm);
  9246.         if (!ck_krb4_is_installed()) {
  9247.         return(cx_fail(msg,
  9248.          "Required authentication method (Kerberos 4) is not installed"
  9249.                    ));
  9250.         } else {
  9251.         if ((ck_krb4_tkt_isvalid(tgt) <= 0) &&
  9252.             (!krb4_autoget ||
  9253.              krb4_autoget && !ck_krb4_autoget_TGT(realm))) {
  9254.             return(cx_fail(msg,
  9255.                "Kerberos 4: Ticket Getting Ticket not valid"));
  9256.         }
  9257.         }
  9258.     }
  9259. #endif /* KRB4 */
  9260. #ifdef KRB5
  9261.     if (ttnproto == NP_K5LOGIN || ttnproto == NP_EK5LOGIN ||
  9262.         ttnproto == NP_K5U2U)
  9263.     {
  9264.         extern int krb5_autoget;
  9265.         char tgt[256];
  9266.         char * realm;
  9267.  
  9268.         /* Must get full hostname before calling ttopen() */
  9269.  
  9270.         realm = ck_krb5_realmofhost(ckgetfqhostname(hostname));
  9271.         ckmakmsg(tgt,256,"krbtgt/",realm,"@",realm);
  9272.  
  9273.         if (!ck_krb5_is_installed()) {
  9274.         return(cx_fail(msg,
  9275.                  "Required authentication method (Kerberos 5) not installed"));
  9276.         } else if (!((ck_krb5_tkt_isvalid(NULL,tgt) > 0) ||
  9277.               ck_krb5_is_tgt_valid()) &&
  9278.                (!krb5_autoget ||
  9279.             krb5_autoget && !ck_krb5_autoget_TGT(realm))) {
  9280.         return(cx_fail(msg,
  9281.                "Kerberos 5: Ticket Getting Ticket not valid."));
  9282.         }
  9283.     }
  9284. #endif /* KRB5 */
  9285. #endif /* CK_KERBEROS */
  9286. #endif /* RLOGCODE */
  9287.  
  9288. #ifndef NOSPL
  9289. #ifdef RLOGCODE
  9290.     if (username) {
  9291.         if (!sl_uid_saved) {
  9292.         ckstrncpy(sl_uidbuf,uidbuf,UIDBUFLEN);
  9293.         sl_uid_saved = 1;
  9294.         }
  9295.         ckstrncpy(uidbuf,username,UIDBUFLEN);
  9296.         uidflag = 1;
  9297.     }
  9298. #endif /* RLOGCODE */
  9299. #ifdef TNCODE
  9300.     if (!sl_tn_saved) {
  9301.         sl_tn_wait = tn_wait_flg;
  9302.         sl_tn_saved = 1;
  9303.     }
  9304.     tn_wait_flg = param3;
  9305. #endif /* TNCODE */
  9306. #endif /* NOSPL */
  9307.     } /* if (net == NET_TCPB) */
  9308. #endif /* TCPSOCKET */
  9309.  
  9310. #ifndef NOSPL
  9311. #ifdef CK_SECURITY
  9312.     if (password) {
  9313.         if (password[0]) {
  9314.         ckstrncpy(pwbuf,password,PWBUFL+1);
  9315.         pwflg = 1;
  9316.         pwcrypt = 0;
  9317.         } else
  9318.         pwflg = 0;
  9319.     }
  9320. #endif /* CK_SECURITY */
  9321. #endif /* NOSPL */
  9322.  
  9323.     /* Try to open - network */
  9324.     y = ttopen(line, &_local, mdmtyp, 0 );
  9325.  
  9326. #ifndef NOHTTP
  9327.     /*  If the connection failed and we are using an HTTP Proxy
  9328.      *  and the reason for the failure was an authentication
  9329.      *  error, then we need to give the user to ability to
  9330.      *  enter a username and password, just like a browser.
  9331.      *
  9332.      *  I tried to do all of this within the netopen() call
  9333.      *  but it is much too much work.
  9334.      */
  9335.     while (y < 0 && tcp_http_proxy != NULL ) {
  9336.  
  9337.         if (tcp_http_proxy_errno == 401 ||
  9338.         tcp_http_proxy_errno == 407 ) {
  9339.         char uid[UIDBUFLEN];
  9340.         char pwd[256];
  9341.                 struct txtbox tb[2];
  9342.                 int ok;
  9343.  
  9344.                 tb[0].t_buf = uid;
  9345.                 tb[0].t_len = UIDBUFLEN;
  9346.                 tb[0].t_lbl = "Proxy Userid: ";
  9347.                 tb[0].t_dflt = NULL;
  9348.                 tb[0].t_echo = 1;
  9349.                 tb[1].t_buf = pwd;
  9350.                 tb[1].t_len = 256;
  9351.                 tb[1].t_lbl = "Proxy Passphrase: ";
  9352.                 tb[1].t_dflt = NULL;
  9353.                 tb[1].t_echo = 2;
  9354.  
  9355.                 ok = uq_mtxt("Proxy Server Authentication Required\n",
  9356.                               NULL, 2, tb);
  9357.  
  9358.         if (ok && uid[0]) {
  9359.             char * proxy_user, * proxy_pwd;
  9360.  
  9361.             proxy_user = tcp_http_proxy_user;
  9362.             proxy_pwd  = tcp_http_proxy_pwd;
  9363.  
  9364.             tcp_http_proxy_user = uid;
  9365.             tcp_http_proxy_pwd = pwd;
  9366.  
  9367.             y = ttopen(line, &_local, mdmtyp, 0);
  9368.             memset(pwd,0,sizeof(pwd));
  9369.             tcp_http_proxy_user = proxy_user;
  9370.             tcp_http_proxy_pwd = proxy_pwd;
  9371.         } else
  9372.           break;
  9373.         } else
  9374.           break;
  9375.     }
  9376. #endif /* NOHTTP */
  9377.     if (y < 0) {
  9378.         slrestor();
  9379.         makestr(&slmsg,"Network connection failure");
  9380. #ifdef VMS
  9381.         if (msg && hints && !xcmdsrc && IS_RLOGIN()) {
  9382.         makestr(&slmsg,"RLOGIN failure");
  9383.         if  (socket_errno == EACCES) {
  9384.             printf("*************************\n");
  9385.             printf(
  9386.        "Hint: RLOGIN requires privileges to open an outbound port.\n");
  9387.             printf(
  9388.             "(Use SET HINTS OFF to suppress future hints.)\n");
  9389.             printf("*************************\n");
  9390.         }
  9391.         }
  9392. #else  /* Not VMS... */
  9393.         if (errno) {
  9394.         int x;
  9395.         debug(F111,"set host line, errno","",errno);
  9396.         makestr(&slmsg,ck_errstr());
  9397.         if (msg) {
  9398. #ifdef OS2
  9399.             printf("Can't connect to %s\n",line);
  9400. #else /* OS2 */
  9401. #ifdef UNIX
  9402.             if (hints && !xcmdsrc && IS_RLOGIN()) {
  9403.             makestr(&slmsg,"RLOGIN failure");
  9404.             printf("*************************\n");
  9405.             printf(
  9406.      "Hint: RLOGIN requires privileges to open an outbound port.\n");
  9407.             printf(
  9408.      "(Use SET HINTS OFF to suppress future hints.)\n");
  9409.             printf("*************************\n");
  9410.             }
  9411. #endif /* UNIX */
  9412. #endif /* OS2 */
  9413.         } else printf("Can't connect to %s\n",line);
  9414.         } else
  9415. #endif /* VMS */
  9416.           if (msg) printf("Can't open connection to %s\n",line);
  9417.         continue;
  9418.     } else {
  9419.         success = 1;
  9420. #ifndef NODIAL
  9421.         dialsta = DIA_UNK;
  9422. #endif /* NODIAL */
  9423.         switch (net) {
  9424.           case NET_TCPA:
  9425.           case NET_TCPB:
  9426.         cxtype = CXT_TCPIP;
  9427. #ifdef COMMENT
  9428. /* This works but it messes up interactive anonymous login */
  9429. #ifndef NOXFER
  9430. #ifdef IKS_OPTION
  9431.         /* If we have connected to an Internet Kermit service */
  9432.         /* and a /USER: switch was given, then log in. */
  9433.  
  9434.         if (TELOPT_U(TELOPT_KERMIT) || TELOPT_ME(TELOPT_KERMIT)) {
  9435.             debug(F111,"cx_net IKSD /USER:",uidbuf,haveuser);
  9436.             if (haveuser /* && cx == 0 */ ) { /* /USER: given */
  9437.             char * psw = pwbuf; /* Do we have a password? */
  9438.             if (!*psw) {        /* No... */
  9439.                 if (!strcmp(uidbuf,"anonymous") ||
  9440.                 !strcmp(uidbuf,"ftp")) {
  9441.                 extern char myhost[];
  9442.                 char * u = (char *)sl_uidbuf;
  9443.                 char * h = (char *)myhost;
  9444.                 if (!*u) u = "nobody";
  9445.                 if (!*h) h = "nowhere";
  9446.                 ckmakmsg(tmpbuf,TMPBUFSIZ,u,"@",h,NULL);
  9447.                 psw = tmpbuf;
  9448.                 debug(F110,"cx_net IKSD anon",psw,0);
  9449.                 } else {
  9450.                 readpass(" Password: ",pwbuf,PWBUFL);
  9451.                 }
  9452.             }
  9453.             sstate = setgen('I',uidbuf,psw,"");
  9454.             }
  9455.         }
  9456. #endif /* IKS_OPTION */
  9457. #endif /* NOXFER */
  9458. #endif /* COMMENT */
  9459.         break;
  9460.           case NET_SSH:
  9461.         cxtype = CXT_SSH;
  9462.         duplex = 0;         /* Remote echo */
  9463.         break;
  9464.           case NET_SLAT:
  9465.         cxtype = CXT_LAT;
  9466.         break;
  9467.           case NET_SX25:
  9468.           case NET_IX25:
  9469.           case NET_HX25:
  9470.           case NET_VX25:
  9471.         cxtype = CXT_X25;
  9472.         break;
  9473.           case NET_BIOS:
  9474.         cxtype = CXT_NETBIOS;
  9475.         break;
  9476.           case NET_FILE:
  9477.           case NET_PIPE:
  9478.           case NET_CMD:
  9479.           case NET_DLL:
  9480.           case NET_PTY:
  9481.         cxtype = CXT_PIPE;
  9482.         break;
  9483.           default:
  9484.         cxtype = CXT_PIPE;
  9485.         break;
  9486.         }
  9487.         break;
  9488.     }
  9489.     } /* for-loop */
  9490.     s = line;
  9491.  
  9492.     debug(F101,"cx_net post ttopen success","",success);
  9493.     if (!success) {
  9494.         local = dfloc;                  /* Go back to normal */
  9495. #ifndef MAC
  9496.         ckstrncpy(ttname,dftty,TTNAMLEN); /* Restore default tty name */
  9497. #endif /* MAC */
  9498.         speed = ttgspd();
  9499.         network = 0;                    /* No network connection active */
  9500.         haveline = 0;
  9501.         if (mdmtyp < 0) {               /* Switching from net to async? */
  9502.             if (mdmsav > -1)            /* Restore modem type from last */
  9503.               mdmtyp = mdmsav;          /* SET MODEM command, if any. */
  9504.             else
  9505.               mdmtyp = 0;
  9506.             mdmsav = -1;
  9507.         }
  9508.         return(0);                      /* Return failure */
  9509.     }
  9510.     if (_local > -1) local = _local;    /* Opened ok, set local/remote. */
  9511.     makestr(&slmsg,NULL);
  9512.     network = (mdmtyp < 0);             /* Remember connection type. */
  9513.     ckstrncpy(ttname,s,TTNAMLEN);       /* Copy name into real place. */
  9514.     debug(F110,"cx_net ok",ttname,0);
  9515.     debug(F101,"cx_net network","",network);
  9516. #ifndef NOXFER
  9517.     if ((reliable != SET_OFF || !setreliable)) /* Assume not reliable. */
  9518.       reliable = SET_OFF;
  9519. #endif /* NOXFER */
  9520.     if (!network || istncomport())    
  9521.       speed = ttgspd();                 /* Get the current speed. */
  9522.     debug(F101,"cx_net local","",local);
  9523.     if (network) {
  9524.         debug(F101,"cx_net net","",net);
  9525. #ifndef NOXFER
  9526.         /* Force prefixing of 255 on TCP/IP connections... */
  9527.         if (net == NET_TCPB
  9528. #ifdef SSHBUILTIN
  9529.              || net == NET_SSH
  9530. #endif /* SSHBUILTIN */
  9531.              ) {
  9532.             debug(F101,"cx_net reliable A","",reliable);
  9533. #ifdef CK_SPEED
  9534.             ctlp[(unsigned)255] = 1;
  9535. #endif /* CK_SPEED */
  9536.             if ((reliable != SET_OFF || !setreliable)) {
  9537. #ifdef TN_COMPORT
  9538.                 if (istncomport()) {    /* Telnet communication port */
  9539.                     reliable = SET_OFF; /* Transport is not reliable */
  9540.                     debug(F101,"cx_net reliable istncomport()","",1);
  9541.                 } else {
  9542.                     reliable = SET_ON;  /* Transport is reliable end to end */
  9543.                     debug(F101,"cx_net reliable istncomport()","",0);
  9544.                 }
  9545. #else
  9546.                 reliable = SET_ON;      /* Transport is reliable end to end */
  9547. #endif /* ifdef TN_COMPORT */
  9548.             }
  9549.             debug(F101,"cx_net reliable B","",reliable);
  9550.         } else if (net == NET_SX25 ||
  9551.                    net == NET_VX25 ||
  9552.                    net == NET_IX25 ||
  9553.                    net == NET_HX25) {
  9554.             duplex = 1;                 /* Local echo for X.25 */
  9555.             if (reliable != SET_OFF || !setreliable)
  9556.               reliable = SET_ON;        /* Transport is reliable end to end */
  9557.         }
  9558. #endif /* NOXFER */
  9559.     }
  9560. #ifndef NOXFER
  9561.     debug(F101,"cx_net reliable","",reliable);
  9562. #endif /* NOXFER */
  9563. #ifdef OS2
  9564.     if (mdmtyp <= 0)                    /* Network or Direct Connection */
  9565.       DialerSend(OPT_KERMIT_CONNECT, 0);
  9566. #endif /* OS2 */
  9567.  
  9568.   xcx_net:
  9569.  
  9570.     setflow();                          /* Set appropriate flow control */
  9571.  
  9572.     haveline = 1;
  9573. #ifdef CKLOGDIAL
  9574.     dolognet();
  9575. #endif /* CKLOGDIAL */
  9576.  
  9577. #ifndef NOSPL
  9578.     if (local) {
  9579.         if (nmac) {                     /* Any macros defined? */
  9580.             int k;                      /* Yes */
  9581.             k = mlook(mactab,"on_open",nmac);   /* Look this up */
  9582.             if (k >= 0) {                       /* If found, */
  9583.                 if (dodo(k,ttname,0) > -1)      /* set it up, */
  9584.                   parser(1);                    /* and execute it */
  9585.             }
  9586.         }
  9587.     }
  9588. #endif /* NOSPL */
  9589.  
  9590.     if (local && (cx || sx)) {          /* /CONNECT or /SERVER switch given */
  9591.         if (cx) {                       /* /CONNECT */
  9592.         if (!gui) {
  9593.         /* Command was confirmed so we can pre-pop command level.  */
  9594.         /* This is so CONNECT module won't think we're executing a */
  9595.         /* script if CONNECT was the final command in the script.  */
  9596.         if (cmdlvl > 0)
  9597.           prepop();
  9598.         }
  9599. #ifndef NODIAL
  9600.             dialsta = DIA_UNK;
  9601. #endif /* NODIAL */
  9602. #ifdef LOCUS
  9603.             if (autolocus) {
  9604.         setlocus(1,1);
  9605.             }
  9606. #endif /* LOCUS */
  9607.             success = doconect(0, cmdlvl == 0 ? 1 : 0);
  9608.             if (ttchk() < 0)
  9609.               dologend();
  9610.         debug(F101,"cx_net post doconect success","",success);
  9611.             return(success);
  9612. #ifndef NOXFER
  9613.         } else if (sx) {                /* /SERVER */
  9614.             sstate = 'x';
  9615. #ifdef MAC
  9616.             what = W_RECV;
  9617.             scrcreate();
  9618. #endif /* MAC */
  9619.             if (local) displa = 1;
  9620. #ifdef AMIGA
  9621.             reqoff();                   /* No DOS requestors while server */
  9622. #endif /* AMIGA */
  9623. #endif /* NOXFER */
  9624.         }
  9625.     }
  9626. #ifndef NODIAL
  9627.     dialsta = DIA_UNK;
  9628. #endif /* NODIAL */
  9629. #ifdef LOCUS
  9630.     if (autolocus) {
  9631.         setlocus(1,1);
  9632.     }
  9633. #endif /* LOCUS */
  9634.     return(success = 1);
  9635. }
  9636. #endif /* NETCONN */
  9637.  
  9638. /* c x _ s e r i a l  --  Make a serial connection */
  9639.  
  9640. /*
  9641.   Call with:
  9642.     device  = string pointer to device name.
  9643.     cx      = 1 to automatically enter Connect mode, 0 otherwise.
  9644.     sx      = 1 to automatically enter Server mode, 0 otherwise.
  9645.     shr     = 1 if device should be opened in shareable mode, 0 otherwise.
  9646.     flag    = if no dev name given: 1 = close current connection, 0 = resume.
  9647.     gui     = 1 if called from GUI dialog, 0 otherwise.
  9648.   Returns:
  9649.     1 on success
  9650.     0 on failure and no message printed, slmsg set to failure message.
  9651.    -9 on failure and message printed, ditto.
  9652. */
  9653.  
  9654. /* these are bit flags */
  9655. #define CX_TAPI 1
  9656. #define CX_PPP  2
  9657. #define CX_SLIP 4
  9658.  
  9659. int
  9660. #ifdef CK_ANSIC
  9661. cx_serial(char *device, 
  9662.           int cx, int sx, int shr, int flag, int gui, int special)
  9663. #else /* CK_ANSIC */
  9664. cx_serial(device, cx, sx, shr, flag, gui, special)
  9665.     char * device; int cx, sx, shr, flag, gui, special; 
  9666. #endif /* CK_ANSIC */
  9667. /* cx_serial */ {
  9668.     int i, n, x, y, msg;
  9669.     int _local = -1;
  9670.     char *s;
  9671.  
  9672.     debug(F110,"cx_serial device",device,0);
  9673.     s = device;
  9674.     msg = (gui == 0) && msgflg;        /* Whether to print messages */
  9675.     success = 0;
  9676.  
  9677. #ifndef NODIAL
  9678.     dialsta = DIA_UNK;
  9679. #endif /* NODIAL */
  9680.     debug(F101,"cx_serial mdmtyp","",mdmtyp);
  9681.     if (clskconnx(1) < 0)        /* Close the Kermit connection */
  9682.       return(success = 0);
  9683.     if (*s) {                /* They gave a device name */
  9684.     _local = -1;            /* Let ttopen decide about it */
  9685.     } else {                /* They just said "set line" */
  9686.     s = dftty;            /* so go back to normal tty */
  9687.     _local = dfloc;            /* and mode. */
  9688.     }
  9689. #ifdef VMS
  9690.     {
  9691.     extern int ok_to_share;
  9692.     ok_to_share = shr;
  9693.     }
  9694. #endif /* VMS */
  9695.  
  9696. #ifdef OS2                              /* Must wait until after ttclos() */
  9697. #ifdef NT                               /* to change these settings       */
  9698. #ifdef CK_TAPI
  9699.     tttapi = special & CX_TAPI;
  9700. #endif /* CK_TAPI */
  9701. #else
  9702.     ttslip = special & CX_SLIP;
  9703.     ttppp  = special & CX_PPP;
  9704. #endif /* NT */
  9705.     ttshare = shr;            /* Shareable device ? */
  9706.     debug(F110,"OS2 SET PORT final s",s,"");
  9707. #endif /* OS2 */
  9708.  
  9709.     /* Open the new line */        
  9710.     if ((y = ttopen(s,&_local,mdmtyp,cdtimo)) > -1) {
  9711.     cxtype = (mdmtyp > 0) ? CXT_MODEM : CXT_DIRECT;
  9712. #ifndef NODIAL
  9713.     dialsta = DIA_UNK;
  9714. #endif /* NODIAL */
  9715.     success = 1;
  9716. #ifdef CK_TAPI
  9717.     /* if the line is a tapi device, then we need to auto-execute */
  9718.     /* SET MODEM TYPE TAPI - which we do the equivalent of here.  */
  9719.     if (tttapi) {
  9720.         extern int usermdm;
  9721.         usermdm = 0;
  9722.         initmdm(38);        /* From ckudia.c n_TAPI == 38 */
  9723.     }
  9724. #endif /* CK_TAPI */
  9725.     } else {                /* Failed */
  9726. #ifdef OS2ONLY
  9727.     if (!strcmp(s,dftty))   /* Do not generate an error with dftty */
  9728.       ;
  9729.     else if (y == -6 && ttslip) {
  9730.         makestr(&slmsg,"Can't access SLIP driver");
  9731.         if (msg) printf("?%s\n",slmsg);
  9732.     } else if (y == -6 && ttppp) {
  9733.         makestr(&slmsg,"Can't access PPP driver");
  9734.         if (msg) printf("?%s\n",slmsg);
  9735.     } else
  9736. #endif /* OS2ONLY */
  9737.       if (y == -2) {
  9738.           makestr(&slmsg,"Timed out - no carrier");
  9739.           if (msg) {
  9740.           printf("?%s\n",slmsg);
  9741.           if (hints) {
  9742.               printf("\n*************************\n");
  9743.               printf(
  9744.                "HINT (Use SET HINTS OFF to suppress future hints):\n");
  9745.               printf(
  9746.               "Try SET CARRIER OFF and SET LINE again, or else\n");
  9747.               printf("SET MODEM, SET LINE, and then DIAL.\n");
  9748.               printf("*************************\n\n");
  9749.           }
  9750.           }
  9751.       } else if (y == -3) {
  9752.           makestr(&slmsg,"Access to lock denied");
  9753.           if (msg) {
  9754. #ifdef UNIX
  9755.           printf(
  9756.            "Sorry, write access to UUCP lockfile directory denied.\n");
  9757. #ifndef NOHINTS
  9758.           if (hints) {
  9759.               printf("\n*************************\n");
  9760.               printf(
  9761.                "HINT (Use SET HINTS OFF to suppress future hints):\n");
  9762.               printf(
  9763.       "Please read the installation instructions file, %sckuins.txt,\n",
  9764.                          k_info_dir ? k_info_dir : ""
  9765.                              );
  9766.               printf(
  9767.       "or the UNIX appendix of the manual, \"Using C-Kermit\"\n"
  9768.                              );
  9769.               printf(
  9770.           "or visit http://www.columbia.edu/kermit/ckuins.html \n"
  9771.                              );
  9772.               printf("*************************\n\n");
  9773.           }
  9774. #endif /* NOHINTS */
  9775. #else
  9776.           printf("Sorry, access to lock denied: %s\n",s);
  9777. #endif /* UNIX */
  9778.           }
  9779.       } else if (y == -4) {
  9780.           makestr(&slmsg,"Access to device denied");
  9781.           if (msg) {
  9782.           printf("Sorry, access to device denied: %s\n",s);
  9783. #ifdef UNIX
  9784. #ifndef NOHINTS
  9785.           if (hints) {
  9786.               printf("\n*************************\n");
  9787.               printf(
  9788.               "HINT (Use SET HINTS OFF to suppress future hints):\n");
  9789.               printf(
  9790.         "Please read the installation instructions file, %sckuins.txt,\n",
  9791.                              k_info_dir ? k_info_dir : ""
  9792.                              );
  9793.               printf(
  9794.         "or the UNIX appendix of the manual, \"Using C-Kermit\".\n"
  9795.                              );
  9796.               printf("*************************\n\n");
  9797.           }
  9798. #endif /* NOHINTS */
  9799. #endif /* UNIX */
  9800.           }
  9801.       } else if (y == -5) {
  9802.           makestr(&slmsg,"Device is in use or unavailable");
  9803.           if (msg)
  9804. #ifdef VMS
  9805.         printf(
  9806.           "Sorry, device is in use or otherwise unavailable: %s\n",s);
  9807. #else
  9808.           printf("Sorry, device is in use: %s\n",s);
  9809. #endif /* VMS */
  9810.       } else {            /* Other error. */
  9811.           makestr(&slmsg,"Device open failed");
  9812.           if (
  9813. #ifdef VMS
  9814.           1
  9815. #else
  9816.           errno
  9817. #endif /* VMS */
  9818.           ) {
  9819.           int x;        /* Find a safe, long buffer */
  9820.           makestr(&slmsg,ck_errstr());
  9821. #ifndef VMS
  9822.           debug(F111,"cx_serial serial errno",slmsg,errno);
  9823. #endif /* VMS */
  9824.           if (msg)
  9825.             printf("Connection to %s failed: %s\n",s,slmsg);
  9826.           } else if (msg)
  9827.         printf("Sorry, can't open connection: %s\n",s);
  9828.       }
  9829.     }
  9830.     network = 0;            /* No network connection active */
  9831.     speed = ttgspd();
  9832.     if (!success) {
  9833.         local = dfloc;                  /* Go back to normal */
  9834. #ifndef MAC
  9835.         ckstrncpy(ttname,dftty,TTNAMLEN); /* Restore default tty name */
  9836. #endif /* MAC */
  9837.         haveline = 0;
  9838.         if (mdmtyp < 0) {               /* Switching from net to async? */
  9839.             if (mdmsav > -1)            /* Restore modem type from last */
  9840.               mdmtyp = mdmsav;          /* SET MODEM command, if any. */
  9841.             else
  9842.               mdmtyp = 0;
  9843.             mdmsav = -1;
  9844.         }
  9845.         return(msg ? -9 : 0);        /* Return failure */
  9846.     }
  9847.     if (_local > -1)
  9848.       local = _local;            /* Opened ok, set local/remote. */
  9849.     makestr(&slmsg,NULL);        /* Erase SET LINE message */
  9850.     ckstrncpy(ttname,s,TTNAMLEN);       /* Copy name into real place. */
  9851.     debug(F110,"cx_serial ok",ttname,0);
  9852. #ifndef NOXFER
  9853.     if ((reliable != SET_OFF || !setreliable)) /* Assume not reliable. */
  9854.       reliable = SET_OFF;
  9855. #endif /* NOXFER */
  9856.  
  9857.   xcx_serial:
  9858.     setflow();                          /* Set appropriate flow control */
  9859.     haveline = 1;
  9860. #ifdef CKLOGDIAL
  9861.       dologline();
  9862. #endif /* CKLOGDIAL */
  9863.  
  9864. #ifndef NOSPL
  9865.     if (local) {
  9866.         if (nmac) {                     /* Any macros defined? */
  9867.             int k;                      /* Yes */
  9868.             k = mlook(mactab,"on_open",nmac);   /* Look this up */
  9869.             if (k >= 0) {                       /* If found, */
  9870.                 if (dodo(k,ttname,0) > -1)      /* set it up, */
  9871.                   parser(1);                    /* and execute it */
  9872.             }
  9873.         }
  9874.     }
  9875. #endif /* NOSPL */
  9876.  
  9877.     if (local && (cx || sx)) {          /* /CONNECT or /SERVER switch given */
  9878.         extern int carrier;
  9879.         if (carrier != CAR_OFF) {    /* Looking for carrier? */
  9880.             /* Open() turns on DTR -- wait up to a second for CD to come up */
  9881.             int i, x;
  9882.             for (i = 0; i < 10; i++) {  /* WAIT 1 CD... */
  9883.                 x = ttgmdm();
  9884.                 if (x < 0 || x & BM_DCD)
  9885.                   break;
  9886.                 msleep(100);
  9887.             }
  9888.         }
  9889.         if (cx) {                       /* /CONNECT */
  9890.             /* Command was confirmed so we can pre-pop command level. */
  9891.             /* This is so CONNECT module won't think we're executing a */
  9892.             /* script if CONNECT was the final command in the script. */
  9893.  
  9894.             if (cmdlvl > 0)
  9895.               prepop();
  9896. #ifndef NODIAL
  9897.             dialsta = DIA_UNK;
  9898. #endif /* NODIAL */
  9899. #ifdef LOCUS
  9900.             if (autolocus) {
  9901.                 setlocus(1,1);
  9902.             }
  9903. #endif /* LOCUS */
  9904.             success = doconect(0, cmdlvl == 0 ? 1 : 0);
  9905.             if (ttchk() < 0)
  9906.               dologend();
  9907.             return(success);
  9908. #ifndef NOXFER
  9909.         } else if (sx) {                /* /SERVER */
  9910.             sstate = 'x';
  9911. #ifdef MAC
  9912.             what = W_RECV;
  9913.             scrcreate();
  9914. #endif /* MAC */
  9915.             if (local) displa = 1;
  9916. #ifdef AMIGA
  9917.             reqoff();                   /* No DOS requestors while server */
  9918. #endif /* AMIGA */
  9919. #endif /* NOXFER */
  9920.         }
  9921.     }
  9922. #ifndef NODIAL
  9923.     dialsta = DIA_UNK;
  9924. #endif /* NODIAL */
  9925. #ifdef LOCUS
  9926.     if (autolocus) {
  9927.         setlocus(1,1);
  9928.     }
  9929. #endif /* LOCUS */
  9930.     return(success = 1);
  9931. }
  9932.  
  9933.  
  9934. /* S E T L I N -- parse name of and then open communication device. */
  9935. /*
  9936.   Call with:
  9937.     xx == XYLINE for a serial (tty) line, XYHOST for a network host,
  9938.     zz == 0 means if user doesn't give a device name, continue current
  9939.             active connection (if any);
  9940.     zz != 0 means if user doesn't give a device name, then close the
  9941.             current connection and restore the default communication device.
  9942.     fc == 0 to just make the connection, 1 to also CONNECT (e.g. "telnet").
  9943. */
  9944. int
  9945. setlin(xx, zz, fc) 
  9946.     int xx, zz, fc; 
  9947. {
  9948.     extern char pwbuf[], * g_pswd;
  9949.     extern int pwflg, pwcrypt, g_pflg, g_pcpt, nolocal;
  9950.     int wait;
  9951.     /* int tn_wait_sv; */
  9952.     int mynet;
  9953.     int _local = -1;
  9954.     int c, i, haveswitch = 0;
  9955.     int haveuser = 0;
  9956.     int getval = 0;
  9957.     int wild = 0;                       /* Filespec has wildcards */
  9958.     int cx = 0;                         /* Connect after */
  9959.     int sx = 0;                         /* Become server after */
  9960.     int a_type = -1;                    /* Authentication type */
  9961.     int e_type = -1;                    /* Telnet /ENCRYPT type */
  9962. #ifdef CK_ENCRYPTION
  9963.     int encrypt = 0;                    /* Encrypted? */
  9964. #endif /* CK_ENCRYPTION */
  9965.     int shr = 0;                        /* Share serial device */
  9966.     int confirmed = 0;                  /* Command has been entered */
  9967.     struct FDB sw, tx, nx;
  9968. #ifdef OS2
  9969.     struct FDB fl;
  9970. #endif /* OS2 */
  9971.  
  9972.     char * ss;
  9973. #ifdef TCPSOCKET
  9974.     int rawflg = 0;
  9975. #endif /* TCPSOCKET */
  9976.  
  9977.     char srvbuf[SRVBUFSIZ+1];
  9978.  
  9979. #ifdef OS2
  9980. #ifdef NT
  9981.     int xxtapi = 0;
  9982. #else
  9983.     int xxslip = 0, xxppp = 0;
  9984. #endif /* NT */
  9985. #endif /* OS2 */
  9986.  
  9987.     int dossh = 0;
  9988.  
  9989.     debug(F101,"setlin fc","",fc);
  9990.     debug(F101,"setlin zz","",zz);
  9991.     debug(F101,"setlin xx","",xx);
  9992.  
  9993. #ifdef SSHCMD
  9994.     if (xx == XXSSH) {                  /* SSH becomes PTY SSH ... */
  9995.         dossh = 1;
  9996.         xx = XYHOST;
  9997.     }
  9998. #endif /* SSHCMD */
  9999.  
  10000. #ifdef TNCODE
  10001.     /* tn_wait_sv = tn_wait_flg; */
  10002.     wait = tn_wait_flg;
  10003. #else
  10004.     /* tn_wait_sv = 0; */
  10005.     wait = 0;
  10006. #endif /* TNCODE */
  10007.  
  10008.     mynet = nettype;
  10009.  
  10010.     if (nolocal) {
  10011.         makestr(&slmsg,"Making connections is disabled");
  10012.         printf("?Sorry, making connections is disabled\n");
  10013.         return(-9);
  10014.     }
  10015.     if (netsave > -1)
  10016.       nettype = netsave;
  10017.  
  10018.     if (fc != 0 || zz == 0)             /* Preset /CONNECT switch */
  10019.       cx = 1;
  10020.  
  10021.     debug(F101,"setlin cx","",cx);
  10022.  
  10023.     *srvbuf = NUL;
  10024.  
  10025.     line[0] = NUL;
  10026.     s = line;
  10027.  
  10028. #ifdef NETCONN
  10029. #ifdef CK_SECURITY
  10030.     if (tmpstring)
  10031.         makestr(&tmpstring,NULL);
  10032. #endif /* CK_SECURITY */
  10033.     if (tmpusrid)
  10034.         makestr(&tmpusrid,NULL);
  10035. #endif /* NETCONN */
  10036.  
  10037.     autoflow = 1;                       /* Enable automatic flow setting */
  10038.  
  10039.     if (xx == XYHOST) {                 /* SET HOST <hostname> */
  10040. #ifndef NETCONN
  10041.         makestr(&slmsg,"Network connections not supported");
  10042.         printf("?%s\n",slmsg);
  10043.         return(-9);
  10044. #else /* NETCONN */
  10045. #ifndef NOPUSH
  10046.         if ((mynet == NET_CMD || mynet == NET_PTY || dossh) && nopush) {
  10047.             makestr(&slmsg,"Access to external commands is disabled");
  10048.             printf("?Sorry, access to external commands is disabled\n");
  10049.             return(-9);
  10050.         }
  10051. #endif /* NOPUSH */
  10052.  
  10053. #ifdef SSHCMD
  10054.         if (dossh) {                    /* SSH connection via pty */
  10055.             int k;
  10056.             k = ckstrncpy(line, sshcmd ? sshcmd : defsshcmd, LINBUFSIZ);
  10057.             debug(F111,"setlin sshcmd 1",line,k);
  10058.             if ((x = cmtxt("Optional switches and hostname","",&s,xxstring))<0)
  10059.               return(x);
  10060.             if (!*s) {
  10061.                 printf("?SSH to where?\n");
  10062.                 return(-9);
  10063.             }
  10064.             if (k < LINBUFSIZ) {
  10065.                 line[k++] = SP;
  10066.                 line[k] = NUL;
  10067.                 debug(F111,"setlin sshcmd 2",line,k);
  10068.             } if (k < LINBUFSIZ) {
  10069.                 ckstrncpy(&line[k],s,LINBUFSIZ-k);
  10070.                 debug(F111,"setlin sshcmd 3",line,k);
  10071.             } else {
  10072.                 printf("?Too long\n");
  10073.                 return(-9);
  10074.             }
  10075.         x = cx_net( NET_PTY,                /* network type */
  10076.                         0,                      /* protocol (not used) */
  10077.                         line,                   /* host */
  10078.                         NULL,                   /* service (not used) */
  10079.                         NULL,                   /* username (not used) */
  10080.                         NULL,                   /* password (not used) */
  10081.                         NULL,                   /* command (not used) */
  10082.                         -1,-1,-1,               /* params 1-3 (not used) */
  10083.                         1,                      /* connect immediately */
  10084.                         sx,                     /* server? */
  10085.                         zz,                     /* close current? */
  10086.                         0);                     /* not gui */
  10087.         debug(F111,"setlin cx_net",line,x);
  10088.         return(x);
  10089.         }
  10090. #endif /* SSHCMD */
  10091.  
  10092. /*
  10093.   Here we parse optional switches and then the hostname or whatever,
  10094.   which depends on the network type.  The tricky part is, the network type
  10095.   can be set by a switch.
  10096. */
  10097. #ifndef NOSPL
  10098.         makestr(&g_pswd,pwbuf);         /* Save global pwbuf */
  10099.         g_pflg = pwflg;                 /* and flag */
  10100.         g_pcpt = pwcrypt;
  10101. #endif /* NOSPL */
  10102.  
  10103.         confirmed = 0;
  10104.         haveswitch = 0;
  10105. #ifdef NETFILE
  10106.         if (mynet != NET_FILE) {
  10107. #endif /* NETFILE */
  10108.             ss = (mynet == NET_CMD || mynet == NET_PTY) ?
  10109.               "Command, or switch" :
  10110.                 (mynet == NET_TCPA || mynet == NET_TCPB
  10111.                   || mynet == NET_SSH) ?
  10112.                   "Hostname, ip-address, or switch" :
  10113.                     "Host or switch";
  10114.             if (fc) {
  10115.                 if (mynet == NET_TCPB &&
  10116.                     (ttnproto == NP_TELNET || ttnproto == NP_KERMIT)) {
  10117.                     if (nshteltab) {
  10118.                         haveswitch++;
  10119.                         cmfdbi(&sw,_CMKEY,ss,"","",nshteltab,4,xxstring,
  10120.                              shteltab,&nx);
  10121.                     }
  10122.                 }
  10123. #ifdef RLOGCODE
  10124.                 else if (mynet == NET_TCPB && ttnproto == NP_RLOGIN) {
  10125.                     if (nshrlgtab) {
  10126.                         haveswitch++;
  10127.                         cmfdbi(&sw,_CMKEY,ss,"","",nshrlgtab,4,xxstring,
  10128.                                shrlgtab,&nx);
  10129.                     }
  10130.                 }
  10131. #endif /* RLOGCODE */
  10132.             } else {
  10133.                 haveswitch++;
  10134.                 cmfdbi(&sw,_CMKEY,ss,"","",nshtab,4,xxstring,shtab,&nx);
  10135.             }
  10136. #ifdef NETFILE
  10137.         }
  10138. #endif /* NETFILE */
  10139.         if (mynet == NET_TCPB || mynet == NET_SLAT ||
  10140.         mynet == NET_SSH  || mynet == NET_DEC) {
  10141.             cmfdbi(&nx,_CMFLD,"Host","","",0,0,xxstring,NULL,NULL);
  10142. #ifdef NETFILE
  10143.         } else if (mynet == NET_FILE) {
  10144.             cmfdbi(&nx,_CMIFI,"Filename","","",0,0,xxstring,NULL,NULL);
  10145. #endif /* NETFILE */
  10146. #ifdef PTYORPIPE
  10147.         } else if (mynet == NET_CMD || mynet == NET_PTY) {
  10148.             cmfdbi(&nx,_CMTXT,"Command","","",0,0,xxstring,NULL,NULL);
  10149. #endif /* PTYORPIPE */
  10150.         } else {
  10151.             cmfdbi(&nx,_CMTXT,"Host","","",0,0,xxstring,NULL,NULL);
  10152.         }
  10153.         while (1) {
  10154.             x = cmfdb(haveswitch ? &sw : &nx);
  10155.             debug(F101,"setlin cmfdb","",x);
  10156.             if (x < 0)
  10157.               if (x != -3)
  10158.                 return(x);
  10159.             if (x == -3) {
  10160.                 if ((x = cmcfm()) < 0) {
  10161.                     return(x);
  10162.                 } else {
  10163.                     confirmed = 1;
  10164.                     break;
  10165.                 }
  10166.             }
  10167.             if (cmresult.fcode != _CMKEY) {    /* Not a switch */
  10168.                 ckstrncpy(line,cmresult.sresult,LINBUFSIZ); /* Save the data */
  10169.                 s = line;                      /* that was parsed... */
  10170.                 if (cmresult.fcode == _CMIFI) {
  10171.                     wild = cmresult.nresult;
  10172.                 } else if (cmresult.fcode == _CMTXT) {
  10173.                     confirmed = 1;
  10174.                 }
  10175.                 break;                  /* and break out of this loop */
  10176.             }
  10177.             c = cmgbrk();               /* Have switch - get break character */
  10178.             getval = (c == ':' || c == '='); /* Must parse an agument? */
  10179.             if (getval && !(cmresult.kflags & CM_ARG)) {
  10180.                 printf("?This switch does not take arguments\n");
  10181.                 return(-9);
  10182.             }
  10183.             if (!getval && (cmgkwflgs() & CM_ARG)) {
  10184.                 printf("?This switch requires an argument\n");
  10185.                 return(-9);
  10186.             }
  10187.             switch (cmresult.nresult) { /* It's a switch.. */
  10188.               case SL_CNX:              /* /CONNECT */
  10189.                 cx = 1;
  10190.                 sx = 0;
  10191.                 break;
  10192.               case SL_SRV:              /* /SERVER */
  10193.                 cx = 0;
  10194.                 sx = 1;
  10195.                 break;
  10196. #ifdef NETCMD
  10197.               case SL_CMD:              /* /COMMAND */
  10198.                 netsave = mynet;
  10199.                 mynet = NET_CMD;
  10200.                 break;
  10201. #endif /* NETCMD */
  10202. #ifdef NETPTY
  10203.               case SL_PTY:              /* /PTY */
  10204.                 netsave = mynet;
  10205.                 mynet = NET_PTY;
  10206.                 break;
  10207. #endif /* NETPTY */
  10208.               case SL_NET:              /* /NETWORK-TYPE */
  10209.                 if ((x = cmkey(netcmd,nnets,"","",xxstring)) < 0)
  10210.                   return(x);
  10211.                 mynet = x;
  10212.                 break;
  10213.  
  10214. #ifdef CK_SECURITY
  10215.               case SL_PSW:              /* /PASSWORD: */
  10216.                 if (!getval)
  10217.                   break;
  10218.                 debok = 0;
  10219.                 if ((x = cmfld("Password","",&s,xxstring)) < 0) {
  10220.                     if (x == -3) {
  10221.                         makestr(&tmpstring,"");
  10222.                     } else {
  10223.                         return(x);
  10224.                     }
  10225.                 } else {
  10226.                     s = brstrip(s);
  10227.                     if ((x = (int)strlen(s)) > PWBUFL) {
  10228.                         makestr(&slmsg,"Internal error");
  10229.                         printf("?Sorry, too long - max = %d\n",PWBUFL);
  10230.                         return(-9);
  10231.                     }
  10232.                     makestr(&tmpstring,s);
  10233.                 }
  10234.                 break;
  10235. #endif /* CK_SECURITY */
  10236.  
  10237.               case SL_UID:              /* /USERID: */
  10238.                 if (!getval)
  10239.                   break;
  10240.                 if ((x = cmfld("Userid","",&s,xxstring)) < 0) {
  10241.                     if (x == -3) {
  10242.                         makestr(&tmpusrid,"");
  10243.                     } else {
  10244.                         return(x);
  10245.                     }
  10246.                 } else {
  10247.                     s = brstrip(s);
  10248.                     if ((x = (int)strlen(s)) > 63) {
  10249.                         makestr(&slmsg,"Internal error");
  10250.                         printf("?Sorry, too long - max = %d\n",63);
  10251.                         return(-9);
  10252.                     }
  10253.                     makestr(&tmpusrid,s);
  10254.                     haveuser = 1;
  10255.                 }
  10256.                 break;
  10257.  
  10258. #ifdef CK_AUTHENTICATION
  10259. #ifdef CK_SRP
  10260.               case SL_SRP:
  10261.                 a_type = AUTHTYPE_SRP;
  10262.                 break;
  10263. #endif /* CK_SRP */
  10264. #ifdef CK_SSL
  10265.               case SL_SSL:
  10266.                 a_type = AUTHTYPE_SSL;
  10267.                 break;
  10268. #endif /* CK_SSL */
  10269. #ifdef NT
  10270.               case SL_NTLM:
  10271.                 a_type = AUTHTYPE_NTLM;
  10272.                 break;
  10273. #endif /* NT */
  10274. #ifdef CK_KERBEROS
  10275.               case SL_KRB4:
  10276.                 a_type = AUTHTYPE_KERBEROS_V4;
  10277.                 if (ttnproto == NP_RLOGIN)
  10278.                   ttnproto =
  10279. #ifdef CK_ENCRYPTION
  10280.                     encrypt ? NP_EK4LOGIN :
  10281. #endif /* CK_ENCRYPTION */
  10282.                       NP_K4LOGIN;
  10283.                 else if (ttnproto == NP_K5LOGIN)
  10284.                   ttnproto = NP_K4LOGIN;
  10285. #ifdef CK_ENCRYPTION
  10286.                 else if (ttnproto == NP_EK5LOGIN)
  10287.                   ttnproto = NP_EK4LOGIN;
  10288. #endif /* CK_ENCRYPTION */
  10289.                 break;
  10290.               case SL_KRB5:
  10291.                 a_type = AUTHTYPE_KERBEROS_V5;
  10292.                 if (ttnproto == NP_RLOGIN)
  10293.                   ttnproto =
  10294. #ifdef CK_ENCRYPTION
  10295.                     encrypt ? NP_EK5LOGIN :
  10296. #endif /* CK_ENCRYPTION */
  10297.                       NP_K5LOGIN;
  10298.                 else if (ttnproto == NP_K4LOGIN)
  10299.                   ttnproto = NP_K5LOGIN;
  10300. #ifdef CK_ENCRYPTION
  10301.                 else if (ttnproto == NP_EK4LOGIN)
  10302.                   ttnproto = NP_EK5LOGIN;
  10303. #endif /* CK_ENCRYPTION */
  10304.                 break;
  10305. #endif /* CK_KERBEROS */
  10306.               case SL_AUTH: {
  10307.                   extern struct keytab autyptab[];
  10308.                   extern int nautyp;
  10309.                   if ((x = cmkey(autyptab,nautyp,"type of authentication",
  10310.                                  "automatic",xxstring)) < 0)
  10311.                     return(x);
  10312.                   a_type = x;
  10313.                   break;
  10314.               }
  10315. #endif /* CK_AUTHENTICATION */
  10316. #ifdef CK_ENCRYPTION
  10317.               case SL_ENC:
  10318.                 switch (ttnproto) {
  10319.                   case NP_K4LOGIN:
  10320.                     ttnproto = NP_EK4LOGIN;
  10321.                     encrypt = 1;
  10322.                     break;
  10323.                   case NP_K5LOGIN:
  10324.                     ttnproto = NP_EK5LOGIN;
  10325.                     encrypt = 1;
  10326.                     break;
  10327.                   case NP_KERMIT:
  10328.                   case NP_TELNET: {
  10329.                       static struct keytab * tnetbl = NULL;
  10330.                       static int ntnetbl = 0;
  10331.                       x = ck_get_crypt_table(&tnetbl,&ntnetbl);
  10332.                       debug(F101,"ck_get_crypt_table x","",x);
  10333.                       debug(F101,"ck_get_crypt_table n","",ntnetbl);
  10334.                       if (x < 1 || !tnetbl || ntnetbl < 1) /* Didn't get it */
  10335.                         x = 0;
  10336.                       if (!x) {
  10337.                           makestr(&slmsg,"Internal error");
  10338.                           printf("?Oops, types not loaded\n");
  10339.                           return(-9);
  10340.                       }
  10341.                       if ((x = cmkey(tnetbl,ntnetbl,"type of encryption",
  10342.                                      "automatic",xxstring)) < 0)
  10343.                         return(x);
  10344.                       e_type = x;
  10345.                       break;
  10346.                   }
  10347.                 }
  10348.                 break;
  10349. #endif /* CK_ENCRYPTION */
  10350.               case SL_WAIT:
  10351.                 wait = 1;
  10352.                 break;
  10353.               case SL_NOWAIT:
  10354.                 wait = 0;
  10355.                 break;
  10356.             }
  10357.         }
  10358.  
  10359. #ifdef NETFILE
  10360.         if (mynet == NET_FILE) {        /* Parsed by cmifi() */
  10361.         if ((x = cmcfm()) < 0)    /* Needs confirmation */
  10362.           return(x);
  10363.         x = cx_net(mynet,        /* nettype */
  10364.                0,        /* protocol (not used) */
  10365.                line,        /* host */
  10366.                "",        /* port */
  10367.                NULL,        /* alternate username */
  10368.                NULL,        /* password */
  10369.                NULL,        /* command to execute */
  10370.                0,        /* param1 */
  10371.                0,        /* param2 */
  10372.                0,        /* param3 */
  10373.                cx,        /* enter CONNECT mode */
  10374.                sx,        /* enter SERVER mode */
  10375.                zz,        /* close connection if open */
  10376.                0        /* gui */
  10377.                );
  10378.         }
  10379. #endif /* NETFILE */
  10380.  
  10381. #ifdef NETCMD
  10382.         if (mynet == NET_CMD || mynet == NET_PTY) {
  10383.             char *p = NULL;
  10384.             if (!confirmed) {
  10385.                 if ((x = cmtxt("Rest of command","",&s,xxstring)) < 0)
  10386.                   return(x);
  10387.                 if (*s) {
  10388.                     strncat(line," ",LINBUFSIZ);
  10389.                     strncat(line,s,LINBUFSIZ);
  10390.                 }
  10391.                 s = line;
  10392.             }
  10393.             /* s == line - so we must protect the line buffer */
  10394.             s = brstrip(s);
  10395.             makestr(&p,s);
  10396.             ckstrncpy(line,p,LINBUFSIZ);
  10397.             makestr(&p,NULL);
  10398.  
  10399.             x = cx_net( mynet,                  /* nettype */
  10400.                         0,                      /* protocol (not used) */
  10401.                         line,                   /* host */
  10402.                         "",                     /* port */
  10403.                         NULL,                   /* alternate username */
  10404.                         NULL,                   /* password */
  10405.                         NULL,                   /* command to execute */
  10406.                         0,                      /* param1 */
  10407.                         0,                      /* param2 */
  10408.                         0,                      /* param3 */
  10409.                         cx,                     /* enter CONNECT mode */
  10410.                         sx,                     /* enter SERVER mode */
  10411.                         zz,                     /* close connection if open */
  10412.                         0                       /* gui */
  10413.                         );
  10414.         }
  10415. #endif /* NETCMD */
  10416.  
  10417. #ifdef NPIPE                            /* Named pipe */
  10418.         if (mynet == NET_PIPE) {        /* Needs backslash twiddling */
  10419.             if (line[0]) {
  10420.                 if (strcmp(line,"*")) {    /* If remote, begin with */
  10421.                     char * p = NULL;
  10422.                     makestr(&p,line);      
  10423.                     ckstrncpy(line,"\\\\",LINBUFSIZ); /* server name */
  10424.                     ckstrncat(line,p,LINBUFSIZ);
  10425.                     makestr(&p,NULL);      
  10426.                 } else {
  10427.                     line[0]='\0';
  10428.                 }
  10429.                 ckstrncat(line,"\\pipe\\", LINBUFSIZ); /* Make pipe name */
  10430.                 ckstrncat(line,pipename, LINBUFSIZ); /* Add name of pipe */
  10431.  
  10432.                 x = cx_net(mynet,    /* nettype */
  10433.                0,        /* protocol (not used) */
  10434.                line,    /* host */
  10435.                "",        /* port */
  10436.                NULL,    /* alternate username */
  10437.                NULL,    /* password */
  10438.                NULL,    /* command to execute */
  10439.                0,        /* param1 */
  10440.                0,        /* param2 */
  10441.                0,        /* param3 */
  10442.                cx,        /* enter CONNECT mode */
  10443.                sx,        /* enter SERVER mode */
  10444.                zz,        /* close connection if open */
  10445.                0        /* gui */
  10446.                );
  10447.             }
  10448.         }
  10449. #endif /* NPIPE */
  10450.  
  10451. #ifdef SUPERLAT
  10452.         if (mynet == NET_SLAT) {        /* Needs password, etc. */
  10453.             slat_pwd[0] = NUL;          /* Erase any previous password */
  10454.             debok = 0;
  10455.             if (*line) {        /* If they gave a host name... */
  10456.                 if ((x = cmfld(
  10457.                      "password,\n or carriage return if no password required",
  10458.                                "",
  10459.                                &s,
  10460.                                xxstring
  10461.                                )) < 0 && x != -3)
  10462.                   return(x);
  10463.                 ckstrncpy(slat_pwd,s,18); /* Set the password, if any */
  10464.             }
  10465.             if ((x = cmcfm()) < 0) return(x); /* Confirm the command */
  10466.  
  10467.             x = cx_net(mynet,        /* nettype */
  10468.                        0,        /* protocol (not used) */
  10469.                        line,        /* host */
  10470.                        "",        /* port */
  10471.                        NULL,        /* alternate username */
  10472.                        NULL,        /* password */
  10473.                        NULL,        /* command to execute */
  10474.                        0,        /* param1 */
  10475.                        0,        /* param2 */
  10476.                        0,        /* param3 */
  10477.                        cx,        /* enter CONNECT mode */
  10478.                        sx,        /* enter SERVER mode */
  10479.                        zz,        /* close connection if open */
  10480.                        0        /* gui */
  10481.                        );
  10482.         }
  10483. #endif /* SUPERLAT */
  10484.  
  10485. #ifdef DECNET
  10486.         if (mynet == NET_DEC) {  
  10487.             if (!line[0]) {                   /* If they gave a host name... */
  10488.                 printf("?hostname required\n");
  10489.                 return(-3);
  10490.             }
  10491.             if ((x = cmcfm()) < 0) return(x); /* Confirm the command */
  10492.  
  10493.             x = cx_net(mynet,        /* nettype */
  10494.                        0,        /* protocol (not used) */
  10495.                        line,        /* host */
  10496.                        "",        /* port */
  10497.                        NULL,        /* alternate username */
  10498.                        NULL,        /* password */
  10499.                        NULL,        /* command to execute */
  10500.                        0,        /* param1 */
  10501.                        0,        /* param2 */
  10502.                        0,        /* param3 */
  10503.                        cx,        /* enter CONNECT mode */
  10504.                        sx,        /* enter SERVER mode */
  10505.                        zz,        /* close connection if open */
  10506.                        0        /* gui */
  10507.                        );
  10508.         }
  10509. #endif /* DECNET */
  10510.  
  10511. #ifdef SSHBUILTIN
  10512.         if (mynet == NET_SSH) {        /* SSH connection */
  10513.             int k, havehost = 0, trips = 0;
  10514.             int    tmpver = -1, tmpxfw = -1, tmpssh_cas;
  10515. #ifndef SSHTEST
  10516.             extern int sl_ssh_xfw, sl_ssh_xfw_saved;
  10517.             extern int sl_ssh_ver, sl_ssh_ver_saved;
  10518. #endif /* SSHTEST */
  10519.             extern struct keytab sshopnsw[];
  10520.             extern int nsshopnsw;
  10521.             extern char *ssh_tmpcmd, *ssh_tmpport;
  10522.             struct FDB sw, kw, fl;
  10523.  
  10524.             debug(F110,"setlin SSH service 0",srvbuf,0);
  10525.             debug(F110,"setlin SSH host s 2",s,0);
  10526.             if (*s) {           /* If they gave a host name... */
  10527.                 debug(F110,"setlin SSH host s 1",s,0);
  10528.                 if (*s == '*') {
  10529.                     makestr(&slmsg,"Incoming connections not supported");
  10530.                     printf(
  10531.      "?Sorry, incoming connections not supported for SSH.\n"
  10532.                            );
  10533.                     return(-9);
  10534.                 }
  10535.                 ckstrncpy(line,s,LINBUFSIZ);
  10536.             } else {
  10537.                 printf("?hostname required\n");
  10538.                 return(-3);
  10539.             }
  10540.  
  10541.             /* Parse [ port ] [ switches ] */
  10542.             cmfdbi(&kw,                 /* Switches */
  10543.                     _CMKEY,
  10544.                     "Port number or service name,\nor switch",
  10545.                     "",
  10546.                     "",
  10547.                     nsshopnsw,
  10548.                     4,
  10549.                     xxstring,
  10550.                     sshopnsw,
  10551.                     &fl
  10552.                     );
  10553.             cmfdbi(&fl,                 /* Port number or service name */
  10554.                     _CMFLD,
  10555.                     "",
  10556.                     "",
  10557.                     "",
  10558.                     0,
  10559.                     0,
  10560.                     xxstring,
  10561.                     NULL,
  10562.                     NULL
  10563.                     );
  10564.             trips = 0;                  /* Explained below */
  10565.             while (1) {                 /* Parse port and switches */
  10566.                 y = cmfdb(&kw);         /* Get a field */
  10567.                 if (y == -3)            /* User typed CR so quit from loop */
  10568.                     break;
  10569.                 if (y < 0)              /* Other parse error, pass it back */
  10570.                     return(y);
  10571.                 switch (cmresult.fcode) { /* Field or Keyword? */
  10572.                 case _CMFLD:              /* Field */
  10573.                     ckstrncpy(srvbuf,cmresult.sresult,SRVBUFSIZ);
  10574.                     break;
  10575.                 case _CMKEY:            /* Keyword */
  10576.                     switch (cmresult.nresult) { /* Which one? */
  10577.                     case SSHSW_PWD:
  10578.                         if (!cmgbrk()) {
  10579.                             printf("?This switch requires an argument\n");
  10580.                             return(-9);
  10581.                         }
  10582.                         debok = 0;
  10583.                         if ((y = cmfld("Password","",&s,xxstring)) < 0) {
  10584.                             if (y == -3) {
  10585.                                 makestr(&tmpstring,"");
  10586.                             } else {
  10587.                                 return(y);
  10588.                             }
  10589.                         } else {
  10590.                             s = brstrip(s);
  10591.                             if ((y = (int)strlen(s)) > PWBUFL) {
  10592.                                 makestr(&slmsg,"Internal error");
  10593.                                 printf("?Sorry, too long - max = %d\n",PWBUFL);
  10594.                                 return(-9);
  10595.                             }
  10596.                             makestr(&tmpstring,s);
  10597.                         }
  10598.                         break;
  10599.                     case SSHSW_USR:             /* /USER: */
  10600.                         if (!cmgbrk()) {
  10601.                             printf("?This switch requires an argument\n");
  10602.                             return(-9);
  10603.                         }
  10604.                         if ((y = cmfld("Username","",&s,xxstring)) < 0)
  10605.                             return(y);
  10606.                         s = brstrip(s);
  10607.                         makestr(&tmpusrid,s);
  10608.                         break;
  10609.                     case SSHSW_VER:
  10610.                         if ((y = cmnum("Number","",10,&z,xxstring)) < 0)
  10611.                             return(y);
  10612.                         if (z < 1 || z > 2) {
  10613.                             printf("?Out of range: %d\n",z);
  10614.                             return(-9);
  10615.                         }
  10616.                         tmpver = z;
  10617.                         break;
  10618.                     case SSHSW_CMD:
  10619.                     case SSHSW_SUB:
  10620.                         if ((y = cmfld("Text","",&s,xxstring)) < 0)
  10621.                           return(y);
  10622.                         makestr(&ssh_tmpcmd,s);
  10623.                         tmpssh_cas = (cmresult.nresult == SSHSW_SUB);
  10624.                         break;
  10625.                     case SSHSW_X11:
  10626.                         if ((y = cmkey(onoff,2,"","on",xxstring)) < 0)
  10627.                             return(y);
  10628.                         tmpxfw = y;
  10629.                         break;
  10630.                     default:
  10631.                         return(-2);
  10632.                     }
  10633.                 }
  10634.                 if (trips++ == 0) {     /* After first time through */
  10635.                     cmfdbi(&kw,         /* only parse switches, not port. */
  10636.                             _CMKEY,
  10637.                             "Switch",
  10638.                             "",
  10639.                             "",
  10640.                             nsshopnsw,
  10641.                             4,
  10642.                             xxstring,
  10643.                             sshopnsw,
  10644.                             NULL
  10645.                             );
  10646.                 }
  10647.             }
  10648.             if ((y = cmcfm()) < 0)      /* Get confirmation */
  10649.                 return(y);
  10650.  
  10651.             debug(F110,"setlin pre-cx_net line",line,0);
  10652.             debug(F110,"setlin pre-cx_net srvbuf",srvbuf,0);
  10653.             x = cx_net( mynet,                  /* nettype */
  10654.                         0,                      /* protocol (not used) */
  10655.                         line,                   /* host */
  10656.                         srvbuf,                 /* port */
  10657.                         tmpusrid,               /* alternate username */
  10658.                         tmpstring,              /* password */
  10659.                         ssh_tmpcmd,             /* command to execute */
  10660.                         tmpver,                 /* param1 - ssh version */
  10661.                         tmpssh_cas,             /* param2 - ssh cas  */
  10662.                         tmpxfw,                 /* param3 - ssh x11fwd */
  10663.                         cx,                     /* enter CONNECT mode */
  10664.                         sx,                     /* enter SERVER mode */
  10665.                         zz,                     /* close connection if open */
  10666.                         0                       /* gui */
  10667.                         );
  10668.             if (tmpusrid)
  10669.                 makestr(&tmpusrid,NULL);
  10670.             if (ssh_tmpcmd)
  10671.                 makestr(&ssh_tmpcmd,NULL);
  10672.         }
  10673. #endif /* SSHBUILTIN */
  10674.  
  10675. #ifdef TCPSOCKET
  10676.         if (mynet == NET_TCPB) {        /* TCP/IP connection */
  10677.             debug(F110,"setlin service 0",srvbuf,0);
  10678.             debug(F110,"setlin host s 2",s,0);
  10679.             if (*s) {            /* If they gave a host name... */
  10680.                 debug(F110,"setlin host s 1",s,0);
  10681. #ifdef NOLISTEN
  10682.                 if (*s == '*') {
  10683.                     makestr(&slmsg,"Incoming connections not supported");
  10684.                     printf(
  10685.      "?Sorry, incoming connections not supported in this version of Kermit.\n"
  10686.                            );
  10687.                     return(-9);
  10688.                 }
  10689. #endif /* NOLISTEN */
  10690. #ifdef RLOGCODE
  10691.                 /* Allow a username if rlogin is requested */
  10692.                 if (mynet == NET_TCPB &&
  10693.                     (ttnproto == NP_RLOGIN || ttnproto == NP_K5LOGIN ||
  10694.                      ttnproto == NP_EK5LOGIN || ttnproto == NP_K4LOGIN ||
  10695.                      ttnproto == NP_EK4LOGIN
  10696.                     )) {
  10697.                     int y;
  10698.                     uidflag = 0;
  10699.                     /* Check for "host:service" */
  10700.                     for ( ; (*s != '\0') && (*s != ':'); s++) ;
  10701.                     if (*s) {   /* Service, save it */
  10702.                         *s = NUL;
  10703.                         ckstrncpy(srvbuf,++s,SRVBUFSIZ);
  10704.                     } else {            /* No :service, then use default. */
  10705. #ifdef VMS
  10706.                         switch (ttnproto) {
  10707.                           case NP_RLOGIN:
  10708.                             ckstrncpy(srvbuf,"513",SRVBUFSIZ); /* "login" */
  10709.                             break;
  10710.                           case NP_K4LOGIN:
  10711.                           case NP_K5LOGIN:
  10712.                             ckstrncpy(srvbuf,"543",SRVBUFSIZ); /* "klogin" */
  10713.                             break;
  10714.                           case NP_EK4LOGIN:
  10715.                           case NP_EK5LOGIN:
  10716.                             ckstrncpy(srvbuf,"2105",SRVBUFSIZ); /* "eklogin" */
  10717.                             break;
  10718.                         }
  10719. #else /* VMS */
  10720.                         switch (ttnproto) {
  10721.                           case NP_RLOGIN:
  10722.                             ckstrncpy(srvbuf,"login",SRVBUFSIZ);
  10723.                             break;
  10724.                           case NP_K4LOGIN:
  10725.                           case NP_K5LOGIN:
  10726.                             ckstrncpy(srvbuf,"klogin",SRVBUFSIZ);
  10727.                             break;
  10728.                           case NP_EK4LOGIN:
  10729.                           case NP_EK5LOGIN:
  10730.                             ckstrncpy(srvbuf,"eklogin",SRVBUFSIZ);
  10731.                             break;
  10732.                         }
  10733. #endif /* VMS */
  10734.                     }
  10735.                     if (!confirmed) {
  10736.                         y = cmfld("Userid on remote system",
  10737.                                   uidbuf,&s,xxstring);
  10738.                         if (y < 0 && y != -3)
  10739.                           return(y);
  10740.                         if ((int)strlen(s) > 63) {
  10741.                             makestr(&slmsg,"Internal error");
  10742.                             printf("Sorry, too long\n");
  10743.                             return(-9);
  10744.                         }
  10745.                         makestr(&tmpusrid,s);
  10746.                     }
  10747.                 } else {        /* TELNET or SET HOST */
  10748. #endif /* RLOGCODE */
  10749.                     /* Check for "host:service" */
  10750.                     for ( ; (*s != '\0') && (*s != ':'); s++) ;
  10751.                     if (*s) {   /* Service, save it */
  10752.                         *s = NUL;
  10753.                         ckstrncpy(srvbuf,++s,SRVBUFSIZ);
  10754.                     } else if (!confirmed) {
  10755.                         /* No :service, let them type one. */
  10756.                         if (*line != '*') { /* Not incoming */
  10757.                             if (mynet == NET_TCPB && ttnproto == NP_KERMIT) {
  10758.                                 if ((x = cmfld(
  10759.                                                "TCP service name or number",
  10760.                                                "kermit",&s,xxstring)
  10761.                                      ) < 0 && x != -3)
  10762.                                   return(x);
  10763. #ifdef RLOGCODE
  10764.                             } else if (mynet == NET_TCPB &&
  10765.                                        ttnproto == NP_RLOGIN) {
  10766.                                 if ((x = cmfld(
  10767.   "TCP service name or number,\n or carriage return for rlogin (513)",
  10768.                                                "login",&s,xxstring)
  10769.                                      ) < 0 && x != -3)
  10770.                                   return(x);
  10771. #ifdef CK_AUTHENTICATION
  10772. #ifdef CK_KERBEROS
  10773.                             } else if (mynet == NET_TCPB &&
  10774.                                        (ttnproto == NP_K4LOGIN ||
  10775.                                        ttnproto == NP_K5LOGIN)) {
  10776.                                 if ((x = cmfld(
  10777.   "TCP service name or number,\n or carriage return for klogin (543)",
  10778.                                                "klogin",&s,xxstring)
  10779.                                      ) < 0 && x != -3)
  10780.                                   return(x);
  10781.                             } else if (mynet == NET_TCPB &&
  10782.                                        (ttnproto == NP_EK4LOGIN ||
  10783.                                         ttnproto == NP_EK5LOGIN)) {
  10784.                                 if ((x = cmfld(
  10785.   "TCP service name or number,\n or carriage return for eklogin (2105)",
  10786.                                                "eklogin",&s,xxstring)
  10787.                                      ) < 0 && x != -3)
  10788.                                   return(x);
  10789. #endif /* CK_KERBEROS */
  10790. #endif /* CK_AUTHENTICATION */
  10791. #endif /* RLOGCODE */
  10792.                             } else {
  10793.                                 /* Do not set a default value in this call */
  10794.                                 /* If you do then it will prevent entries  */
  10795.                                 /* in the network directory from accessing */
  10796.                                 /* alternate ports.                        */
  10797.  
  10798.                                 if ((x = cmfld(
  10799.                                                "TCP service name or number",
  10800.                                                "",&s,xxstring)
  10801.                                      ) < 0 && x != -3)
  10802.                                   return(x);
  10803.                             }
  10804.                         } else { /* Incoming connection */
  10805.                             if ((x = cmfld("TCP service name or number",
  10806.                                            "",&s,xxstring)
  10807.                                  ) < 0 && x != -3)
  10808.                               return(x);
  10809.                         }
  10810.                         if (*s)         /* If they gave a service, */
  10811.                           ckstrncpy(srvbuf,s,SRVBUFSIZ); /* copy it */
  10812.                         debug(F110,"setlin service 0.5",srvbuf,0);
  10813.                     }
  10814. #ifdef RLOGCODE
  10815.                 }
  10816. #endif /* RLOGCODE */
  10817.                 if (!confirmed) {
  10818.                     char * defproto;
  10819.                     switch (ttnproto) {
  10820.                       case NP_RLOGIN:
  10821.                         defproto = "/rlogin";
  10822.                         break;
  10823.                       case NP_K4LOGIN:
  10824.                         defproto = "/k4login";
  10825.                         break;
  10826.                       case NP_K5LOGIN:
  10827.                         defproto = "/k5login";
  10828.                         break;
  10829.                       case NP_EK4LOGIN:
  10830.                         defproto = "/ek4login";
  10831.                         break;
  10832.                       case NP_EK5LOGIN:
  10833.                         defproto = "/ek5login";
  10834.                         break;
  10835.                       case NP_KERMIT:
  10836.                       case NP_TELNET:
  10837.                         defproto = "/telnet";
  10838.                         break;
  10839.                       default:
  10840.                         defproto = "/default";
  10841.                     }
  10842.                     if ((x = cmkey(tcprawtab,ntcpraw,"Switch",defproto,
  10843.                                    xxstring)) < 0) {
  10844.                         if (x != -3)
  10845.                           return(x);
  10846.                         else if ((x = cmcfm()) < 0)
  10847.                           return(x);
  10848.                     } else {
  10849.                         rawflg = x;
  10850.                         if ((x = cmcfm()) < 0)
  10851.                           return(x);
  10852.                     }
  10853.                 }
  10854.             }
  10855.             debug(F110,"setlin pre-cx_net line",line,0);
  10856.             debug(F110,"setlin pre-cx_net srvbuf",srvbuf,0);
  10857.             x = cx_net( mynet,                  /* nettype */
  10858.                         rawflg                  /* protocol */,
  10859.                         line,                   /* host */
  10860.                         srvbuf,                 /* port */
  10861.                         tmpusrid,               /* alternate username */
  10862.                         tmpstring,              /* password */
  10863.                         NULL,                   /* command to execute */
  10864.                         a_type,                 /* param1 - telnet authtype */
  10865.                         e_type,                 /* param2 - telnet enctype  */
  10866.                         wait,                   /* param3 - telnet wait */
  10867.                         cx,                     /* enter CONNECT mode */
  10868.                         sx,                     /* enter SERVER mode */
  10869.                         zz,                     /* close connection if open */
  10870.                         0                       /* gui */
  10871.                         );
  10872.         }
  10873. #endif /* TCPSOCKET */
  10874.  
  10875. #ifdef CK_SECURITY
  10876.         if (tmpstring)
  10877.             makestr(&tmpstring,NULL);
  10878. #endif /* CK_SECURITY */
  10879.         if (tmpusrid)
  10880.             makestr(&tmpusrid,NULL);
  10881.     debug(F111,"setlin cx_net",line,x);
  10882.     return(x);
  10883. #endif /* NETCONN */
  10884.     }
  10885.  
  10886. /* Serial tty device, possibly modem, connection... */
  10887.  
  10888. #ifdef OS2
  10889. /*
  10890.   User can type:
  10891.     COM1..COM8 = Regular COM port
  10892.     1..8       = Synonym for COM1..COM8, is translated to COM1..COM8
  10893.     _n         = (n is a number) = open file handle
  10894.     string     = any text string = name of some other kind of device,
  10895.                  taken literally, as given.
  10896. */
  10897.     s = "Communication device name";
  10898.  
  10899. #ifdef CK_TAPI
  10900.     if (TAPIAvail)
  10901.       cktapiBuildLineTable(&tapilinetab, &_tapilinetab, &ntapiline);
  10902.     if (!(tapilinetab && _tapilinetab && ntapiline > 0) &&
  10903.     xx == XYTAPI_LIN ) {
  10904.     makestr(&slmsg,"TAPI device not configured");
  10905.     printf("\nNo TAPI Line Devices are configured for this system\n");
  10906.     return(-9);
  10907.     }
  10908.     if (xx == XYTAPI_LIN) {        /* Default (first) TAPI line */
  10909.     s = "tapi";            /* (whatever it is) */
  10910.     } else {                /* Query the user */
  10911. #endif /* CK_TAPI */
  10912.  
  10913. /* Now parse optional switches and then device name */
  10914.  
  10915.     confirmed = 0;
  10916.     cmfdbi(&sw,_CMKEY,"Device name, or switch",
  10917.            "","",npsltab,4,xxstring,psltab,&fl);
  10918.     cmfdbi(&fl,_CMFLD,"",dftty,"",0,0,xxstring,NULL,NULL);
  10919.     while (1) {
  10920.         x = cmfdb(&sw);
  10921.         debug(F101,"setlin cmfdb","",x);
  10922.         if (x < 0)
  10923.           if (x != -3)
  10924.         return(x);
  10925.         if (x == -3) {
  10926.         if ((x = cmcfm()) < 0) {
  10927.             return(x);
  10928.         } else {
  10929.             confirmed = 1;
  10930.             break;
  10931.         }
  10932.         }
  10933.         if (cmresult.fcode == _CMFLD) {
  10934.         s = cmresult.sresult;
  10935.         break;
  10936.         } else if (cmresult.fcode == _CMKEY) {
  10937.         switch (cmresult.nresult) {
  10938.           case SL_CNX:        /* /CONNECT */
  10939.             cx = 1;
  10940.             sx = 0;
  10941.             break;
  10942.           case SL_SRV:        /* /SERVER */
  10943.             cx = 0;
  10944.             sx = 1;
  10945.             break;
  10946.           case SL_SHR:        /* /SHARE */
  10947.             shr = 1;
  10948.             break;
  10949.           case SL_NSH:        /* /NOSHARE */
  10950.             shr = 0;
  10951.             break;
  10952.         }
  10953.         }
  10954.     }
  10955. #ifdef CK_TAPI
  10956.     }
  10957. #endif /* CK_TAPI */
  10958.  
  10959.     debug(F110,"OS2 SET PORT s",s,0);
  10960.     y = lookup(os2devtab,s,nos2dev,&x); /* Look up in keyword table */
  10961.     debug(F101,"OS2 SET PORT x","",x);
  10962.     debug(F101,"OS2 SET PORT y","",y);
  10963.     if ((y > -1) && (x >= 0 && x < 8)) { /* User typed a digit 1..8 */
  10964.     s = os2devtab[x+8].kwd;        /* Substitite its real name */
  10965. #ifdef NT
  10966.     xxtapi = 0;
  10967. #else /* NT */
  10968.     xxslip = xxppp = 0;
  10969. #endif /* NT */
  10970.     debug(F110,"OS2 SET PORT subst s",s,"");
  10971. #ifndef NT
  10972.     } else if ((y >-1) && (x >= 16 && x < 24)) { /* SLIP access */
  10973.     s = os2devtab[x-8].kwd;        /* Substitite its real name */
  10974.     debug(F110,"OS2 SET PORT SLIP subst s",s,"");
  10975.     xxslip = 1;
  10976.     xxppp  = 0;
  10977.     } else if ((y >-1) && (x >= 24 && x < 32)) { /* PPP access */
  10978.     s = os2devtab[x-16].kwd;    /* Substitite its real name */
  10979.     debug(F110,"OS2 SET PORT PPP subst s",s,"");
  10980.     xxppp = 1;
  10981.     xxslip = 0;
  10982.     if ((y = cmkey(os2ppptab,
  10983.                nos2ppp,
  10984.                "PPP driver interface",
  10985.                "ppp0",
  10986.                xxstring)
  10987.          ) < 0)
  10988.       return(y);
  10989.     debug(F101,"OS2 SET PORT PPP INTERFACE y","",y);
  10990.     xxppp = (y % 10) + 1;
  10991. #endif /* NT */
  10992.     } else if (*s == '_') {        /* User used "_" prefix */
  10993.     s++;                /* Remove it */
  10994.     /* Rest must be numeric */
  10995.     debug(F110,"OS2 SET PORT HANDLE _subst s",s,0);
  10996.     if (!rdigits(s)) {
  10997.         makestr(&slmsg,"Invalid file handle");
  10998.         printf("?Invalid format for file handle\n");
  10999.         return(-9);
  11000.     }
  11001. #ifdef NT
  11002.     xxtapi = 0;
  11003. #else /* NT */
  11004.     xxslip = xxppp = 0;
  11005. #endif /* NT */
  11006.     } else {                /* A normal COMx port or a string */
  11007.     s = brstrip(s);            /* Strip braces if any */
  11008. #ifdef NT
  11009. #ifdef CK_TAPI
  11010.     /* Windows TAPI support - Look up in keyword table */
  11011.     if (tapilinetab && _tapilinetab && ntapiline > 0) {
  11012.         if (!ckstrcmp(s,"tapi",4,0)) {
  11013.  
  11014.         /* Find out what the lowest numbered TAPI device is */
  11015.         /* and use it as the default.                       */
  11016.         int j = 9999, k = -1;
  11017.         for (i = 0; i < ntapiline; i++) {
  11018.             if (tapilinetab[i].kwval < j) {
  11019.             j = tapilinetab[i].kwval;
  11020.             k = i;
  11021.             }
  11022.         }
  11023.         if (k >= 0)
  11024.           s = _tapilinetab[k].kwd;
  11025.         else
  11026.           s = "";
  11027.  
  11028.         if ((y = cmkey(_tapilinetab,ntapiline,
  11029.                    "TAPI device name",s,xxstring)) < 0)
  11030.           return(y);
  11031.  
  11032.         xxtapi = 1;
  11033.  
  11034.         /* Get the non Underscored string */
  11035.         for (i = 0; i < ntapiline; i++ ) {
  11036.             if (tapilinetab[i].kwval == y) {
  11037.             s = tapilinetab[i].kwd;
  11038.             break;
  11039.             }
  11040.         }
  11041.         } else
  11042.           xxtapi = 0;
  11043.     }
  11044. #endif /* CK_TAPI */
  11045. #else /* NT */
  11046.     /* not OS/2 SLIP or PPP */
  11047.     xxslip = xxppp = 0;
  11048. #endif /* NT */
  11049.     }
  11050.     ckstrncpy(tmpbuf,s,TMPBUFSIZ);    /* Copy to a safe place */
  11051.     s = tmpbuf;
  11052.     if ((x = cmcfm()) < 0)
  11053.       return(x);
  11054.  
  11055. #else /* !OS2 */
  11056.  
  11057.     cmfdbi(&sw,_CMKEY,"Device name, or switch",
  11058.        "","",npsltab,4,xxstring,psltab,&tx);
  11059.     cmfdbi(&tx,_CMTXT,"",dftty,"",0,0,xxstring,NULL,NULL);
  11060.     while (!confirmed) {
  11061.     x = cmfdb(&sw);
  11062.     debug(F101,"setlin cmfdb","",x);
  11063.     if (x < 0)
  11064.       if (x != -3)
  11065.         return(x);
  11066.     if (x == -3) {
  11067.         if ((x = cmcfm()) < 0) {
  11068.         return(x);
  11069.         } else {
  11070.         confirmed = 1;
  11071.         break;
  11072.         }
  11073.     }
  11074.     switch (cmresult.fcode) {
  11075.       case _CMTXT:
  11076.         ckstrncpy(tmpbuf,cmresult.sresult,TMPBUFSIZ);
  11077.         s = tmpbuf;
  11078.         debug(F110,"setlin CMTXT",tmpbuf,0);
  11079.         confirmed = 1;
  11080.         break;
  11081.       case _CMKEY:            /* Switch */
  11082.         debug(F101,"setlin CMKEY",tmpbuf,cmresult.nresult);
  11083.         switch (cmresult.nresult) {
  11084.           case SL_CNX:        /* /CONNECT */
  11085.         cx = 1;
  11086.         sx = 0;
  11087.         break;
  11088.           case SL_SRV:        /* /SERVER */
  11089.         cx = 0;
  11090.         sx = 1;
  11091.         break;
  11092. #ifdef VMS
  11093.           case SL_SHR:        /* /SHARE */
  11094.         shr = 1;
  11095.         break;
  11096.           case SL_NSH:        /* /NOSHARE */
  11097.         shr = 0;
  11098.         break;
  11099. #endif /* VMS */
  11100.         }
  11101.         continue;
  11102.       default:
  11103.         debug(F101,"setlin bad cmfdb result","",cmresult.fcode);
  11104.         makestr(&slmsg,"Internal error");
  11105.         printf("?Internal parsing error\n");
  11106.         return(-9);
  11107.     }
  11108.     }
  11109. #endif /* OS2 */
  11110.     if (!confirmed)
  11111.       if ((x = cmcfm()) < 0)
  11112.     return(x);
  11113.  
  11114.     debug(F110,"setlin pre-cx_serial s",s,0);
  11115.     debug(F110,"setlin pre-cx_serial line",line,0);
  11116.     x = cx_serial(s,cx,sx,shr,zz,0,
  11117. #ifdef OS2
  11118. #ifdef NT
  11119.                    (xxtapi ? CX_TAPI : 0)
  11120. #else
  11121.                    (xxslip ? CX_SLIP : 0) | (xxppp ? CX_PPP : 0)
  11122. #endif /* NT */
  11123. #else /* OS2 */
  11124.                    0
  11125. #endif /* OS2 */
  11126.                    );
  11127.     debug(F111,"setlin cx_serial",line,x);
  11128.     return(x);
  11129. }
  11130. #endif /* NOLOCAL */
  11131.  
  11132. #ifdef CKCHANNELIO
  11133. /*
  11134.   C-Library based file-i/o package for scripts.  This should be portable to
  11135.   all C-Kermit versions since it uses the same APIs we have always used for
  11136.   processing command files.  The entire channel i/o package is contained
  11137.   herein, apart from some keyword table entries in the main keyword table
  11138.   and the help text in the HELP command module.
  11139.  
  11140.   On platforms like VMS and VOS, this package handles only UNIX-style
  11141.   stream files.  If desired, it can be replaced for those platforms by
  11142.   <#>ifdef'ing out this code and adding the equivalent replacement routines
  11143.   to the ck?fio.c module, e.g. for RMS-based file i/o in ckvfio.c.
  11144. */
  11145.  
  11146. /* Define NOSTAT if the <#>include causes trouble. */
  11147.  
  11148. #ifndef NOSTAT
  11149. #ifdef VMS
  11150. #ifdef VAXC                             /* As it does in VAX C */
  11151. #define NOSTAT
  11152. #endif /* VAXC */
  11153. #endif /* VMS */
  11154. #endif /* NOSTAT */
  11155.  
  11156. #ifndef NOSTAT
  11157. #include <sys/stat.h>
  11158. #endif /* NOSTAT */
  11159.  
  11160. #ifdef NLCHAR
  11161. static int z_lt = 1;                    /* Length of line terminator */
  11162. #else
  11163. static int z_lt = 2;
  11164. #endif /* NLCHAR */
  11165.  
  11166. struct ckz_file {                       /* C-Kermit file struct */
  11167.     FILE * z_fp;                        /* Includes the C-Lib file struct */
  11168.     unsigned int z_flags;               /* Plus C-Kermit mode flags, */
  11169.     long z_nline;                       /* current line number if known, */
  11170.     char z_name[CKMAXPATH+2];           /* and the file's name. */
  11171. };
  11172. static struct ckz_file * z_file = NULL; /* Array of C-Kermit file structs */
  11173. static int z_inited = 0;                /* Flag for array initialized */
  11174. int z_maxchan = Z_MAXCHAN;              /* Max number of C-Kermit channels */
  11175. int z_openmax = CKMAXOPEN;              /* Max number of open files overall */
  11176. int z_nopen = 0;                        /* How many channels presently open */
  11177. int z_error = 0;                        /* Most recent error */
  11178. int z_filcount = -1;                    /* Most recent FILE COUNT result */
  11179.  
  11180. #define RD_LINE 0                       /* FILE READ options */
  11181. #define RD_CHAR 1
  11182. #define RD_SIZE 2
  11183.  
  11184. #define WR_LINE RD_LINE                 /* FILE WRITE options */
  11185. #define WR_CHAR RD_CHAR
  11186. #define WR_SIZE RD_SIZE
  11187. #define WR_STRI 3
  11188. #define WR_LPAD 4
  11189. #define WR_RPAD 5
  11190.  
  11191. #ifdef UNIX
  11192. extern int ckmaxfiles;                  /* Filled in by sysinit(). */
  11193. #endif /* UNIX */
  11194.  
  11195. /* See ckcker.h for error numbers */
  11196. /* See ckcdeb.h for Z_MAXCHAN and CKMAXOPEN definitions */
  11197. /* NOTE: For VMS we might be able to fill in ckmaxfiles */
  11198. /* from FILLM and CHANNELCNT -- find out about these... */
  11199.  
  11200. static char * fopnargs[] = {            /* Mode combinations for fopen() */
  11201. #ifdef COMMENT
  11202.     /* All combinations of rwa */
  11203.     "",  "r",  "w",  "rw",  "a",  "ra",  "wa",  "rwa", /* Text mode */
  11204.     "b", "rb", "wb", "rwb", "ab", "rab", "wab", "rwab" /* Binary mode */
  11205. #else
  11206.     /* Combinations and syntax permitted by C libraries... */
  11207.     "",  "r",  "w",  "r+",  "a",  "",   "a",  "", /* Text mode */
  11208. #ifdef OS2
  11209.     "",  "rb", "wb", "r+b", "ab", "",   "ab", "" /* Binary modes for K95 */
  11210. #else
  11211. #ifdef VMS
  11212.     "",  "rb", "wb", "r+b", "ab", "",   "ab", "" /* Binary modes for VMS */
  11213. #else
  11214.     "",  "r",   "w", "r+",  "a",  "",   "a",  "" /* Binary modes for UNIX */
  11215. #endif /* VMS */
  11216. #endif /* OS2 */
  11217. #endif /* COMMENT */
  11218. };
  11219. static int nfopnargs = sizeof(fopnargs) / sizeof(char *);
  11220.  
  11221. char *                                  /* Error messages */
  11222. ckferror(n) int n; {
  11223.     switch (n) {
  11224.       case FX_NER: return("No error");
  11225.       case FX_SYS: return(ck_errstr());
  11226.       case FX_EOF: return("End of file");
  11227.       case FX_NOP: return("File not open");
  11228.       case FX_CHN: return("Channel out of range");
  11229.       case FX_RNG: return("Parameter out of range");
  11230.       case FX_NMF: return("Too many files open");
  11231.       case FX_FOP: return("Operation conflicts with OPEN mode");
  11232.       case FX_NYI: return("OPEN mode not supported");
  11233.       case FX_BOM: return("Illegal combination of OPEN modes");
  11234.       case FX_ACC: return("Access denied");
  11235.       case FX_FNF: return("File not found");
  11236.       case FX_OFL: return("Buffer overflow");
  11237.       case FX_LNU: return("Current line number unknown");
  11238.       case FX_ROO: return("Off limits");
  11239.       case FX_UNK: return("Operation fails - reason unknown");
  11240.       default: return("Error number out of range");
  11241.     }
  11242. }
  11243.  
  11244. /*
  11245.   Z _ O P E N --  Open a file for the requested type of access.
  11246.  
  11247.   Call with:
  11248.     name:  Name of file to be opened.
  11249.     flags: Any combination of FM_xxx values except FM_EOF (ckcker.h).
  11250.   Returns:
  11251.     >= 0 on success: The assigned channel number
  11252.     <  0 on failure: A negative FX_xxx error code (ckcker.h).
  11253. */
  11254. int
  11255. z_open(name, flags) char * name; int flags; {
  11256.     int i, n;
  11257.     FILE * t;
  11258.     char * mode;
  11259.     debug(F111,"z_open",name,flags);
  11260.     if (!name) name = "";               /* Check name argument */
  11261.     if (!name[0])
  11262.       return(z_error = FX_BFN);
  11263.     if (flags & FM_CMD)                 /* Opening pipes not implemented yet */
  11264.       return(z_error = FX_NYI);         /* (and not portable either) */
  11265.     debug(F101,"z_open nfopnargs","",nfopnargs);
  11266.     if (flags < 0 || flags >= nfopnargs) /* Range check flags */
  11267.       return(z_error = FX_RNG);
  11268.     mode = fopnargs[flags];             /* Get fopen() arg */
  11269.     debug(F111,"z_open fopen args",mode,flags);
  11270.     if (!mode[0])                       /* Check for illegal combinations */
  11271.       return(z_error = FX_BOM);
  11272.     if (!z_inited) {                    /* If file structs not inited */
  11273.         debug(F101,"z_open z_maxchan 1","",z_maxchan);
  11274. #ifdef UNIX
  11275.         debug(F101,"z_open ckmaxfiles","",ckmaxfiles);
  11276.         if (ckmaxfiles > 0) {           /* Set in ck?tio.c: sysinit() */
  11277.             int x;
  11278.             x = ckmaxfiles - ZNFILS - 5;
  11279.             if (x > z_maxchan)          /* sysconf() value greater than */
  11280.               z_maxchan = x;            /* value from header files. */
  11281.             debug(F101,"z_open z_maxchan 2","",z_maxchan);
  11282.         }
  11283. #endif /* UNIX */
  11284.         if (z_maxchan < Z_MINCHAN)      /* Allocate at least this many. */
  11285.           z_maxchan = Z_MINCHAN;
  11286.         debug(F101,"z_open z_maxchan 3","",z_maxchan);
  11287.         /* Note: This could be a pretty big chunk of memory */
  11288.         /* if z_maxchan is a big number.  If this becomes a problem */
  11289.         /* we'll need to malloc and free each element at open/close time */
  11290.         if (!(z_file = (struct ckz_file *)
  11291.               malloc(sizeof(struct ckz_file) * (z_maxchan + 1))))
  11292.           return(z_error = FX_NMF);
  11293.         for (i = 0; i < z_maxchan; i++) {
  11294.             z_file[i].z_fp = NULL;
  11295.             z_file[i].z_flags = 0;
  11296.             z_file[i].z_nline = 0;
  11297.             *(z_file[i].z_name) = '\0';
  11298.         }
  11299.         z_inited = 1;                   /* Remember we did */
  11300.     }
  11301.     for (n = -1, i = 0; i < z_maxchan; i++) {
  11302.         if (!z_file[i].z_fp) {
  11303.             n = i;
  11304.             break;
  11305.         }
  11306.     }
  11307.     if (n < 0 || n >= z_maxchan)        /* Any free channels? */
  11308.       return(z_error = FX_NMF);         /* No, fail. */
  11309.     errno = 0;
  11310.  
  11311.     z_file[n].z_flags = 0;              /* In case of failure... */
  11312.  
  11313.     t = fopen(name, mode);              /* Try to open the file. */
  11314.     if (!t) {                           /* Failed... */
  11315.         debug(F111,"z_open error",name,errno);
  11316. #ifdef EMFILE
  11317.         if (errno == EMFILE)
  11318.           return(z_error = FX_NMF);
  11319. #endif /* EMFILE */
  11320.         return(z_error = (errno ?  FX_SYS : FX_UNK)); /* Return error code */
  11321.     }
  11322. #ifdef NT
  11323. #ifdef O_SEQUENTIAL
  11324.     if (t)                              /* Caching hint for NT */
  11325.       _setmode(_fileno(t),O_SEQUENTIAL);
  11326. #endif /* O_SEQUENTIAL */
  11327. #endif /* NT */
  11328.     z_nopen++;                          /* Open, count it. */
  11329.     z_file[n].z_fp = t;                 /* Stash the file pointer */
  11330.     z_file[n].z_flags = flags;          /* and the flags */
  11331.     z_error = 0;
  11332.     zfnqfp(name,CKMAXPATH,z_file[n].z_name); /* and the file's full name */
  11333.     return(n);                          /* Return the channel number */
  11334. }
  11335.  
  11336. int
  11337. z_close(channel) int channel; {         /* Close file on given channel */
  11338.     int x;
  11339.     FILE * t;
  11340.     if (!z_inited)                      /* Called before any files are open? */
  11341.       return(z_error = FX_NOP);
  11342.     if (channel >= z_maxchan)           /* Channel out of range? */
  11343.       return(z_error = FX_CHN);
  11344.     if (!(t = z_file[channel].z_fp))    /* Channel wasn't open? */
  11345.       return(z_error = FX_NOP);
  11346.     errno = 0;                          /* Set errno 0 to get a good reading */
  11347.     x = fclose(t);                      /* Try to close */
  11348.     if (x == EOF)                       /* On failure */
  11349.       return(z_error = FX_SYS);         /* indicate system error. */
  11350.     z_nopen--;                          /* Closed OK, decrement open count */
  11351.     z_file[channel].z_fp = NULL;        /* Set file pointer to NULL */
  11352.     z_file[channel].z_nline = 0;        /* Current line number is 0 */
  11353.     z_file[channel].z_flags = 0;        /* Set flags to 0 */
  11354.     *(z_file[channel].z_name) = '\0';   /* Clear name */
  11355.     return(z_error = 0);
  11356. }
  11357.  
  11358. /*
  11359.   Z _ O U T  --  Output string to channel.
  11360.  
  11361.   Call with:
  11362.     channel:     Channel number to write to.
  11363.     s:           String to write.
  11364.     length > -1: How many characters of s to write.
  11365.     length < 0:  Write entire NUL-terminated string.
  11366.     flags == 0:  Supply line termination.
  11367.     flags >  0:  Don't supply line termination.
  11368.     flags <  0:  Write 'length' NUL characters.
  11369.   Special case:
  11370.     If flags > -1 and s is empty or NULL and length == 1, write 1 NUL.
  11371.   Returns:
  11372.     Number of characters written to channel on success, or
  11373.     negative FX_xxx error code on failure.
  11374. */
  11375. int
  11376. z_out(channel,s,length,flags) int channel, flags, length; char * s; {
  11377.     FILE * t;
  11378.     int x, n;
  11379.     char c = '\0';
  11380.  
  11381.     if (!s) s = "";                     /* Guard against null pointer */
  11382. #ifdef DEBUG
  11383.     if (deblog) {
  11384.         debug(F111,"z_out",s,channel);
  11385.         debug(F101,"z_out length","",length);
  11386.         debug(F101,"z_out flags","",flags);
  11387.     }
  11388. #endif /* DEBUG */
  11389.     if (!z_inited)                      /* File i/o inited? */
  11390.       return(z_error = FX_NOP);
  11391.     if (channel >= z_maxchan)           /* Channel in range? */
  11392.       return(z_error = FX_CHN);
  11393.     if (!(t = z_file[channel].z_fp))    /* File open? */
  11394.       return(z_error = FX_NOP);
  11395.     if (!((z_file[channel].z_flags) & (FM_WRI|FM_APP))) /* In write mode? */
  11396.       return(z_error = FX_FOP);
  11397.     n = length;                         /* Length of string to write */
  11398.     if (n < 0) {                        /* Negative means get it ourselves */
  11399.         if (flags < 0)                  /* Except when told to write NULs in */
  11400.           return(z_error = FX_RNG);     /* which case args are inconsistent */
  11401.         n = strlen(s);                  /* Get length of string arg */
  11402.     }
  11403.     errno = 0;                          /* Reset errno */
  11404.     debug(F101,"z_out n","",n);
  11405.     if (flags < 0) {                    /* Writing NULs... */
  11406.         int i;
  11407.         for (i = 0; i < n; i++) {
  11408.             x = fwrite(&c,1,1,t);
  11409.             if (x < 1)
  11410.               return(z_error = (errno ? FX_SYS : FX_UNK));
  11411.         }
  11412.         z_file[channel].z_nline = -1;   /* Current line no longer known */
  11413.         z_error = 0;
  11414.         return(i);
  11415.     } else {                            /* Writing string arg */
  11416.         if (n == 1 && !s[0])            /* Writing one char but it's NUL */
  11417.           x = fwrite(&c,1,1,t);
  11418.         else                            /* Writing non-NUL char or string */
  11419.           x = fwrite(s,1,n,t);
  11420.         debug(F101,"z_out fwrite",ckitoa(x),errno);
  11421.         if (x < n)                      /* Failure to write requested amount */
  11422.           return(z_error = (errno ? FX_SYS : FX_UNK)); /* Return error */
  11423.         if (flags == 0) {               /* If supplying line termination */
  11424.             if (fwrite("\n",1,1,t))     /* do that  */
  11425.               x += z_lt;                /* count the terminator */
  11426.             if (z_file[channel].z_nline > -1) /* count this line */
  11427.               z_file[channel].z_nline++;
  11428.         } else {
  11429.             z_file[channel].z_nline = -1; /* Current line no longer known */
  11430.         }
  11431.     }
  11432.     z_error = 0;
  11433.     return(x);
  11434. }
  11435.  
  11436. #define Z_INBUFLEN 64
  11437.  
  11438. /*
  11439.   Z _ I N  --  Multichannel i/o file input function.
  11440.  
  11441.   Call with:
  11442.     channel number to read from.
  11443.     s = address of destination buffer.
  11444.     buflen = destination buffer length.
  11445.     length = Number of bytes to read, must be < buflen.
  11446.     flags: 0 = read a line; nonzero = read the given number of bytes.
  11447.   Returns:
  11448.     Number of bytes read into buffer or a negative error code.
  11449.     A terminating NUL is deposited after the last byte that was read.
  11450. */
  11451. int
  11452. z_in(channel,s,buflen,length,flags)
  11453.  int channel, buflen, length, flags; char * s;
  11454. /* z_in */ {
  11455.     int i, j, x;
  11456.     FILE * t;
  11457.     char * p;
  11458.  
  11459.     if (!z_inited)                      /* Check everything... */
  11460.       return(z_error = FX_NOP);
  11461.     if (channel >= z_maxchan)
  11462.       return(z_error = FX_CHN);
  11463.     if (!(t = z_file[channel].z_fp))
  11464.       return(z_error = FX_NOP);
  11465.     if (!((z_file[channel].z_flags) & FM_REA))
  11466.       return(z_error = FX_FOP);
  11467.     if (!s)                             /* Check destination */
  11468.      return(z_error = FX_RNG);
  11469.     s[0] = NUL;
  11470.     if (length == 0)                    /* Read 0 bytes - easy. */
  11471.       return(z_error = 0);
  11472.     debug(F101,"z_in channel","",channel);
  11473.     debug(F101,"z_in buflen","",buflen);
  11474.     debug(F101,"z_in length","",length);
  11475.     debug(F101,"z_in flags","",flags);
  11476.     if (length < 0 || buflen < 0)       /* Check length args */
  11477.       return(z_error = FX_RNG);
  11478.     if (buflen <= length)
  11479.       return(z_error = FX_RNG);
  11480.     errno = 0;                          /* Reset errno */
  11481.     if (flags) {                        /* Read block or byte */
  11482.         i = fread(s,1,length,t);
  11483. #ifdef DEBUG
  11484.         if (deblog) {
  11485.             debug(F111,"z_in block",s,i);
  11486.             debug(F101,"z_in block errno","",errno);
  11487.             debug(F101,"z_in block ferror","",ferror(t));
  11488.             debug(F101,"z_in block feof","",feof(t));
  11489.         }
  11490. #endif /* DEBUG */
  11491.         z_file[channel].z_nline = -1;   /* Current line no longer known */
  11492.     } else {                            /* Read line */
  11493. #ifndef COMMENT
  11494.         /* This method is used because it's simpler than the others */
  11495.         /* and also marginally faster. */
  11496.         debug(F101,"z_in getc loop","",ftell(t));
  11497.         for (i = 0; i < length; i++) {
  11498.             if ((x = getc(t)) == EOF) {
  11499.                 debug(F101,"z_in getc error","",ftell(t));
  11500.                 s[i] = '\0';
  11501.                 break;
  11502.             }
  11503.             s[i] = x;
  11504.             if (s[i] == '\n') {
  11505.                 s[i] = '\0';
  11506.                 break;
  11507.             }
  11508.         }
  11509.         debug(F111,"z_in line byte loop",ckitoa(errno),i);
  11510.         debug(F111,"z_in line got",s,z_file[channel].z_nline);
  11511.         if (z_file[channel].z_nline > -1)
  11512.           z_file[channel].z_nline++;
  11513. #else
  11514. #ifdef COMMENT2
  11515.         /* Straightforward but strlen() slows it down. */
  11516.         s[0] = '\0';
  11517.         i = 0;
  11518.         if (fgets(s,length,t)) {
  11519.             i = strlen(s);
  11520.             if (i > 0 && s[i-1] == '\n') i--;
  11521.         }
  11522.         debug(F111,"z_in line fgets",ckitoa(errno),i);
  11523.         if (z_file[channel].z_nline > -1)
  11524.           z_file[channel].z_nline++;
  11525. #else
  11526.         /* This is a do-it-yourself fgets() with its own readahead and */
  11527.         /* putback.  It's a bit faster than real fgets() but not enough */
  11528.         /* to justify the added complexity or the risk of the ftell() and */
  11529.         /* fseek() calls failing. */
  11530.         int k, flag = 0;
  11531.         long pos;
  11532.         for (i = 0; !flag && i <= (length - Z_INBUFLEN); i += Z_INBUFLEN) {
  11533.             k = ((length - i) < Z_INBUFLEN) ? length - i : Z_INBUFLEN;
  11534.             if ((x = fread(s+i,1,k,t)) < 1)
  11535.               break;
  11536.             s[i+x] = '\0';
  11537.             for (j = 0; j < x; j++) {
  11538.                 if (s[i+j] == '\n') {
  11539.                     s[i+j] = '\0';
  11540.                     flag ++;
  11541.                     pos = ftell(t);
  11542.                     if (pos > -1) {
  11543.                         pos -= (x - j - 1);
  11544.                         x = fseek(t, pos, 0);
  11545.                         i += j;
  11546.                         break;
  11547.                     } else
  11548.                       return(z_error = FX_SYS);
  11549.                 }
  11550.             }
  11551.         }
  11552.         if (z_file[channel].z_nline > -1)
  11553.           z_file[channel].z_nline++;
  11554.         debug(F111,"z_in line chunk loop",ckitoa(errno),i);
  11555. #endif /* COMMENT2 */
  11556. #endif /* COMMENT */
  11557.     }
  11558.     debug(F111,"z_in i",ckitoa(errno),i);
  11559.     if (i < 0) i = 0;                   /* NUL-terminate result */
  11560.     s[i] = '\0';
  11561.     if (i > 0) {
  11562.         z_error = 0;
  11563.         return(i);
  11564.     }
  11565.     if (i == 0 && feof(t))              /* EOF on reading? */
  11566.       return(z_error = FX_EOF);         /* Return EOF code */
  11567.     return(errno ? (z_error = -1) : i); /* Return length or system error */
  11568. }
  11569.  
  11570. int
  11571. z_flush(channel) int channel; {         /* Flush output channel */
  11572.     FILE * t;
  11573.     int x;
  11574.     if (!z_inited)                      /* Regular checks */
  11575.       return(z_error = FX_NOP);
  11576.     if (channel >= z_maxchan)
  11577.       return(z_error = FX_CHN);
  11578.     if (!(t = z_file[channel].z_fp))
  11579.       return(z_error = FX_NOP);
  11580.     if (!((z_file[channel].z_flags) & (FM_WRI|FM_APP))) /* Write access? */
  11581.       return(z_error = FX_FOP);
  11582.     errno = 0;                          /* Reset errno */
  11583.     x = fflush(t);                      /* Try to flush */
  11584.     return(x ? (z_error = FX_SYS) : 0); /* Return system error or 0 if OK */
  11585. }
  11586.  
  11587. int
  11588. #ifdef CK_ANSIC
  11589. z_seek(int channel, long pos)           /* Move file pointer to byte */
  11590. #else
  11591. z_seek(channel,pos) int channel; long pos; /* (seek to given position) */
  11592. #endif /* CK_ANSIC */
  11593. {
  11594.     int i, x = 0, rc;
  11595.     FILE * t;
  11596.     if (!z_inited)                      /* Check... */
  11597.       return(z_error = FX_NOP);
  11598.     if (channel >= z_maxchan)
  11599.       return(z_error = FX_CHN);
  11600.     if (!(t = z_file[channel].z_fp))
  11601.       return(z_error = FX_NOP);
  11602.     if (pos < 0L) {
  11603.         x = 2;
  11604.         pos = (pos == -2) ? -1L : 0L;
  11605.     }
  11606.     errno = 0;
  11607.     rc = fseek(t,pos,x);                /* Try to seek */
  11608.     debug(F111,"z_seek",ckitoa(errno),rc);
  11609.     if (rc < 0)                         /* OK? */
  11610.       return(z_error = FX_SYS); /* No. */
  11611.     z_file[channel].z_nline = ((pos || x) ? -1 : 0);
  11612.     return(z_error = 0);
  11613. }
  11614.  
  11615. int
  11616. #ifdef CK_ANSIC
  11617. z_line(int channel, long pos)           /* Move file pointer to line */
  11618. #else
  11619. z_line(channel,pos) int channel; long pos; /* (seek to given position) */
  11620. #endif /* CK_ANSIC */
  11621. {
  11622.     int i, len, x = 0;
  11623.     long current = 0L, prev = -1L, old = -1L;
  11624.     FILE * t;
  11625.     char tmpbuf[256];
  11626.     if (!z_inited)                      /* Check... */
  11627.       return(z_error = FX_NOP);
  11628.     if (channel >= z_maxchan)
  11629.       return(z_error = FX_CHN);
  11630.     if (!(t = z_file[channel].z_fp))
  11631.       return(z_error = FX_NOP);
  11632.     debug(F101,"z_line pos","",pos);
  11633.     if (pos < 0L) {                     /* EOF wanted */
  11634.         long n;
  11635.         n = z_file[channel].z_nline;
  11636.         debug(F101,"z_line n","",n);
  11637.         if (n < 0 || pos < 0) {
  11638.             rewind(t);
  11639.             n = 0;
  11640.         }
  11641.         while (1) {                     /* This could take a while... */
  11642.             if ((x = getc(t)) == EOF)
  11643.               break;
  11644.             if (x == '\n') {
  11645.                 n++;
  11646.                 if (pos == -2) {
  11647.                     old = prev;
  11648.                     prev = ftell(t);
  11649.                 }
  11650.             }
  11651.         }
  11652.         debug(F101,"z_line old","",old);
  11653.         debug(F101,"z_line prev","",prev);
  11654.         if (pos == -2) {
  11655.             if ((x = z_seek(channel,old)) < 0)
  11656.               return(z_error = x);
  11657.             else
  11658.               n--;
  11659.         }
  11660.         z_file[channel].z_nline = n;
  11661.         return(z_error = 0);
  11662.     }
  11663.     if (pos == 0L) {                    /* Rewind wanted */
  11664.         z_file[channel].z_nline = 0L;
  11665.         rewind(t);
  11666.         debug(F100,"z_line rewind","",0);
  11667.         return(0L);
  11668.     }
  11669.     tmpbuf[255] = NUL;                  /* Make sure buf is NUL terminated */
  11670.     current = z_file[channel].z_nline;  /* Current line */
  11671.     /*
  11672.       If necessary the following could be optimized, e.g. for positioning
  11673.       to a previous line in a large file without starting over.
  11674.     */
  11675.     if (current < 0 || pos < current) { /* Not known or behind us... */
  11676.         debug(F101,"z_line rewinding","",pos);
  11677.         if ((x = z_seek(channel, 0L)) < 0) /* Rewind */
  11678.           return(z_error = x);
  11679.         if (pos == 0)                   /* If 0th line wanted we're done */
  11680.           return(z_error = 0);
  11681.         current = 0;
  11682.     }
  11683.     while (current < pos) {             /* Search for specified line */
  11684.         if (fgets(tmpbuf,255,t)) {
  11685.             len = strlen(tmpbuf);
  11686.             if (len > 0 && tmpbuf[len-1] == '\n') {
  11687.                 current++;
  11688.                 debug(F111,"z_line read",ckitoa(len),current);
  11689.             } else if (len == 0) {
  11690.                 return(z_error = FX_UNK);
  11691.             }
  11692.         } else {
  11693.             z_file[channel].z_nline = -1L;
  11694.             debug(F101,"z_line premature EOF","",current);
  11695.             return(z_error = FX_EOF);
  11696.         }
  11697.     }
  11698.     z_file[channel].z_nline = current;
  11699.     debug(F101,"z_line result","",current);
  11700.     z_error = 0;
  11701.     return(current);
  11702. }
  11703.  
  11704. char *
  11705. z_getname(channel) int channel; {       /* Return name of file on channel */
  11706.     FILE * t;
  11707.     if (!z_inited) {
  11708.         z_error = FX_NOP;
  11709.         return(NULL);
  11710.     }
  11711.     if (channel >= z_maxchan) {
  11712.         z_error = FX_CHN;
  11713.         return(NULL);
  11714.     }
  11715.     if (!(t = z_file[channel].z_fp)) {
  11716.         z_error = FX_NOP;
  11717.         return(NULL);
  11718.     }
  11719.     return((char *)(z_file[channel].z_name));
  11720. }
  11721.  
  11722. int
  11723. z_getmode(channel) int channel; {       /* Return OPEN modes of channel */
  11724.     FILE * t;                           /* 0 if file not open */
  11725. #ifndef NOSTAT
  11726. #ifdef NT
  11727.     struct _stat statbuf;
  11728. #else /* NT */
  11729.     struct stat statbuf;
  11730. #endif /* NT */
  11731. #endif /* NOSTAT */
  11732.     int x;
  11733.     if (!z_inited)
  11734.       return(0);
  11735.     if (channel >= z_maxchan)
  11736.       return(z_error = FX_CHN);
  11737.     if (!(t = z_file[channel].z_fp))
  11738.       return(0);
  11739.     x = z_file[channel].z_flags;
  11740.     if (feof(t)) {                      /* This might not work for */
  11741.         x |= FM_EOF;                    /* output files */
  11742. #ifndef NOSTAT
  11743.     /* But this does if we can use it. */
  11744.     } else if (stat(z_file[channel].z_name,&statbuf) > -1) {
  11745.         if (ftell(t) == statbuf.st_size)
  11746.           x |= FM_EOF;
  11747. #endif /* NOSTAT */
  11748.     }
  11749.     return(x);
  11750. }
  11751.  
  11752. long
  11753. z_getpos(channel) int channel; {        /* Get file pointer position */
  11754.     FILE * t;                           /* on this channel */
  11755.     long x;
  11756.     if (!z_inited)
  11757.       return(z_error = FX_NOP);
  11758.     if (channel >= z_maxchan)
  11759.       return(z_error = FX_CHN);
  11760.     if (!(t = z_file[channel].z_fp))
  11761.       return(z_error = FX_NOP);
  11762.     x = ftell(t);
  11763.     return((x < 0L) ? (z_error = FX_SYS) : x);
  11764. }
  11765.  
  11766. long
  11767. z_getline(channel) int channel; {       /* Get current line number */
  11768.     FILE * t;                           /* in file on this channel */
  11769.     long rc;
  11770.     if (!z_inited)
  11771.       return(z_error = FX_NOP);
  11772.     if (channel >= z_maxchan)
  11773.       return(z_error = FX_CHN);
  11774.     if (!(t = z_file[channel].z_fp))
  11775.       return(z_error = FX_NOP);
  11776.     debug(F101,"z_getline","",z_file[channel].z_nline);
  11777.     rc = z_file[channel].z_nline;
  11778.     return((rc < 0) ? (z_error = FX_LNU) : rc);
  11779. }
  11780.  
  11781. int
  11782. z_getfnum(channel) int channel; {       /* Get file number / handle */
  11783.     FILE * t;                           /* for file on this channel */
  11784.     if (!z_inited)
  11785.       return(z_error = FX_NOP);
  11786.     if (channel >= z_maxchan)
  11787.       return(z_error = FX_CHN);
  11788.     if (!(t = z_file[channel].z_fp))
  11789.       return(z_error = FX_NOP);
  11790.     z_error = 0;
  11791.     return(fileno(t));
  11792. }
  11793.  
  11794. /*
  11795.   Line-oriented counts and seeks are as dumb as they can be at the moment.
  11796.   Later we can speed them up by building little indexes.
  11797. */
  11798. long
  11799. z_count(channel, what) int channel, what; { /* Count bytes or lines in file */
  11800.     FILE * t;
  11801.     int i, x;
  11802.     long pos, count = 0L;
  11803.     if (!z_inited)                      /* Check stuff... */
  11804.       return(z_error = FX_NOP);
  11805.     if (channel >= z_maxchan)
  11806.       return(z_error = FX_CHN);
  11807.     if (!(t = z_file[channel].z_fp))
  11808.       return(z_error = FX_NOP);
  11809.     pos = ftell(t);                     /* Save current file pointer */
  11810.     errno = 0;
  11811.     z_error = 0;
  11812.     if (what == RD_CHAR) {              /* Size in bytes requested */
  11813.         if (!fseek(t,0L,2)) {           /* Seek to end */
  11814.             count = ftell(t);           /* Get file pointer */
  11815.             fseek(t,pos,0);             /* Restore file file pointer */
  11816.             return(count);
  11817.         } else                          /* Fallback in case seek fails */
  11818.           return(zgetfs(z_file[channel].z_name));
  11819.     }
  11820.     rewind(t);                          /* Line count requested - rewind. */
  11821.     while (1) {                         /* Count lines. */
  11822.         if ((x = getc(t)) == EOF)       /* Stupid byte loop */
  11823.           break;                        /* but it works as well as anything */
  11824.         if (x == '\n')                  /* else... */
  11825.           count++;
  11826.     }
  11827.     x = fseek(t,pos,0);                 /* Restore file pointer */
  11828.     return(count);
  11829. }
  11830.  
  11831. /* User interface for generalized channel-oriented file i/o */
  11832.  
  11833. struct keytab fctab[] = {               /* FILE subcommands */
  11834.     { "close",      FIL_CLS, 0 },
  11835.     { "count",      FIL_COU, 0 },
  11836.     { "flush",      FIL_FLU, 0 },
  11837.     { "list",       FIL_LIS, 0 },
  11838.     { "open",       FIL_OPN, 0 },
  11839.     { "read",       FIL_REA, 0 },
  11840.     { "rewind",     FIL_REW, 0 },
  11841.     { "seek",       FIL_SEE, 0 },
  11842.     { "status",     FIL_STA, 0 },
  11843.     { "write",      FIL_WRI, 0 }
  11844. };
  11845. int nfctab = (sizeof (fctab) / sizeof (struct keytab));
  11846.  
  11847. static struct keytab fcswtab[] = {      /* OPEN modes */
  11848.     { "/append",    FM_APP,  0 },
  11849.     { "/binary",    FM_BIN,  0 },
  11850. #ifdef COMMENT
  11851.     { "/command",   FM_CMD,  0 },       /* Not implemented */
  11852. #endif /* COMMENT */
  11853.     { "/read",      FM_REA,  0 },
  11854.     { "/write",     FM_WRI,  0 }
  11855. };
  11856. static int nfcswtab = (sizeof (fcswtab) / sizeof (struct keytab));
  11857.  
  11858. static struct keytab fclkwtab[] = {     /* CLOSE options */
  11859.     { "all",        1,       0 }
  11860. };
  11861.  
  11862. static struct keytab fsekwtab[] = {     /* SEEK symbols */
  11863.     { "eof",        1,       0 },
  11864.     { "last",       2,       0 }
  11865. };
  11866. static int nfsekwtab = (sizeof (fsekwtab) / sizeof (struct keytab));
  11867.  
  11868. #define SEE_LINE  RD_LINE               /* SEEK options */
  11869. #define SEE_CHAR  RD_CHAR
  11870. #define SEE_REL   3
  11871. #define SEE_ABS   4
  11872.  
  11873. static struct keytab fskswtab[] = {
  11874.     { "/absolute",  SEE_ABS,  0 },
  11875.     { "/byte",      SEE_CHAR, 0 },
  11876.     { "/character", SEE_CHAR, CM_INV },
  11877.     { "/line",      SEE_LINE, 0 },
  11878.     { "/relative",  SEE_REL,  0 }
  11879. };
  11880. static int nfskswtab = (sizeof (fskswtab) / sizeof (struct keytab));
  11881.  
  11882. #define COU_LINE  RD_LINE               /* COUNT options */
  11883. #define COU_CHAR  RD_CHAR
  11884. #define COU_LIS   3
  11885. #define COU_NOL   4
  11886.  
  11887. static struct keytab fcoswtab[] = {
  11888.     { "/bytes",     COU_CHAR, 0      },
  11889.     { "/characters",COU_CHAR, CM_INV },
  11890.     { "/lines",     COU_LINE, 0      },
  11891.     { "/list",      COU_LIS,  0      },
  11892.     { "/nolist",    COU_NOL,  0      },
  11893.     { "/quiet",     COU_NOL,  CM_INV }
  11894. };
  11895. static int nfcoswtab = (sizeof (fcoswtab) / sizeof (struct keytab));
  11896.  
  11897. static struct keytab frdtab[] = {       /* READ types */
  11898.     { "/block",     RD_SIZE, CM_INV|CM_ARG },
  11899.     { "/byte",      RD_CHAR, CM_INV },
  11900.     { "/character", RD_CHAR, 0      },
  11901.     { "/line",      RD_LINE, 0      },
  11902.     { "/size",      RD_SIZE, CM_ARG }
  11903. };
  11904. static int nfrdtab = (sizeof (frdtab) / sizeof (struct keytab));
  11905.  
  11906. static struct keytab fwrtab[] = {       /* WRITE types */
  11907.     { "/block",     WR_SIZE, CM_INV|CM_ARG },
  11908.     { "/byte",      WR_CHAR, CM_INV },
  11909.     { "/character", WR_CHAR, 0      },
  11910.     { "/line",      WR_LINE, 0      },
  11911.     { "/lpad",      WR_LPAD, CM_ARG },
  11912.     { "/rpad",      WR_RPAD, CM_ARG },
  11913.     { "/size",      WR_SIZE, CM_ARG },
  11914.     { "/string",    WR_STRI, 0      }
  11915. };
  11916. static int nfwrtab = (sizeof (fwrtab) / sizeof (struct keytab));
  11917.  
  11918. static char blanks[] = "\040\040\040\040"; /* Some blanks for formatting */
  11919.  
  11920. int
  11921. dofile(op) int op; {                    /* Do the FILE command */
  11922.     char vnambuf[VNAML];                /* Buffer for variable names */
  11923.     char *vnp = NULL;                   /* Pointer to same */
  11924.     char zfilnam[CKMAXPATH+2];
  11925.     char * p;
  11926.     struct FDB fl, sw, nu;
  11927.     long z;
  11928.     int rsize, filmode = 0, relative = -1, eofflg = 0;
  11929.     int rc, x, y, cx, n, getval, dummy, confirmed, listing = -1;
  11930.     int charflag = 0, sizeflag = 0;
  11931.     int pad = 32, wr_lpad = 0, wr_rpad = 0;
  11932.  
  11933.     if (op == XXFILE) {                 /* FILE command was given */
  11934.         /* Get subcommand */
  11935.         if ((cx = cmkey(fctab,nfctab,"Operation","",xxstring)) < 0) {
  11936.             if (cx == -3) {
  11937.                 printf("?File operation required\n");
  11938.                 x = -9;
  11939.             }
  11940.             return(cx);
  11941.         }
  11942.     } else {                            /* Shorthand command was given */
  11943.         switch (op) {
  11944.           case XXF_CL: cx = FIL_CLS; break; /* FCLOSE */
  11945.           case XXF_FL: cx = FIL_FLU; break; /* FFLUSH */
  11946.           case XXF_LI: cx = FIL_LIS; break; /* FLIST */
  11947.           case XXF_OP: cx = FIL_OPN; break; /* etc... */
  11948.           case XXF_RE: cx = FIL_REA; break;
  11949.           case XXF_RW: cx = FIL_REW; break;
  11950.           case XXF_SE: cx = FIL_SEE; break;
  11951.           case XXF_ST: cx = FIL_STA; break;
  11952.           case XXF_WR: cx = FIL_WRI; break;
  11953.           case XXF_CO: cx = FIL_COU; break;
  11954.           default: return(-2);
  11955.         }
  11956.     }
  11957.     switch (cx) {                       /* Do requested subcommand */
  11958.       case FIL_OPN:                     /* OPEN */
  11959.         cmfdbi(&sw,                     /* Switches */
  11960.                _CMKEY,                  /* fcode */
  11961.                "Variable or switch",    /* hlpmsg */
  11962.                "",                      /* default */
  11963.                "",                      /* addtl string data */
  11964.                nfcswtab,                /* addtl numeric data 1: tbl size */
  11965.                4,                       /* addtl numeric data 2: 4 = cmswi */
  11966.                xxstring,                /* Processing function */
  11967.                fcswtab,                 /* Keyword table */
  11968.                &fl                      /* Pointer to next FDB */
  11969.                );
  11970.         cmfdbi(&fl,                     /* Anything that doesn't match */
  11971.                _CMFLD,                  /* fcode */
  11972.                "Variable",              /* hlpmsg */
  11973.                "",
  11974.                "",
  11975.                0,
  11976.                0,
  11977.                NULL,
  11978.                NULL,
  11979.                NULL
  11980.                );
  11981.         while (1) {
  11982.             x = cmfdb(&sw);             /* Parse something */
  11983.             if (x < 0) {
  11984.                 if (x == -3) {
  11985.                     printf("?Variable name and file name required\n");
  11986.                     x = -9;
  11987.                 }
  11988.                 return(x);
  11989.             }
  11990.             if (cmresult.fcode == _CMFLD)
  11991.               break;
  11992.             else if (cmresult.fcode == _CMKEY) {
  11993.                 char c;
  11994.                 c = cmgbrk();
  11995.                 if ((getval =
  11996.                      (c == ':' || c == '=')) && !(cmgkwflgs() & CM_ARG)) {
  11997.                     printf("?This switch does not take an argument\n");
  11998.                     return(-9);
  11999.                 }
  12000. #ifdef COMMENT
  12001.                 /* Uncomment if we add any switches ere that take args */
  12002.                 if (!getval && (cmgkwflgs() & CM_ARG)) {
  12003.                     printf("?This switch requires an argument\n");
  12004.                     return(-9);         /* (none do...) */
  12005.                 }
  12006. #endif /* COMMENT */
  12007.                 filmode |= cmresult.nresult; /* OR in the file mode */
  12008.             } else
  12009.               return(-2);
  12010.         }
  12011.         /* Not a switch - get the string */
  12012.         ckstrncpy(vnambuf,cmresult.sresult,VNAML);
  12013.         if (!vnambuf[0] || chknum(vnambuf)) { /* (if there is one...) */
  12014.             printf("?Variable name required\n");
  12015.             return(-9);
  12016.         }
  12017.         vnp = vnambuf;                  /* Check variable-name syntax */
  12018.         if (vnambuf[0] == CMDQ &&
  12019.             (vnambuf[1] == '%' || vnambuf[1] == '&'))
  12020.           vnp++;
  12021.         y = 0;
  12022.         if (*vnp == '%' || *vnp == '&') {
  12023.             if ((y = parsevar(vnp,&x,&dummy)) < 0) {
  12024.                 printf("?Syntax error in variable name\n");
  12025.                 return(-9);
  12026.             }
  12027.         }
  12028.         if (!(filmode & FM_RWA))        /* If no access mode specified */
  12029.           filmode |= FM_REA;            /* default to /READ. */
  12030.  
  12031.         y = 0;                          /* Now parse the filename */
  12032.         if ((filmode & FM_RWA) == FM_WRI)
  12033.           x = cmofi("Name of new file","",&s,xxstring);
  12034.         else if ((filmode & FM_RWA) == FM_REA)
  12035.           x = cmifi("Name of existing file","",&s,&y,xxstring);
  12036.         else {
  12037.             x = cmiofi("Filename","",&s,&y,xxstring);
  12038.             debug(F101,"fopen /append x","",x);
  12039.         }
  12040.         if (x == -9) {
  12041.             if (zchko(s) < 0) {
  12042.                 printf("Can't create \"%s\"\n",s);
  12043.                 return(x);
  12044.             }
  12045.         } else if (x < 0) {
  12046.             if (x == -3) {
  12047.                 printf("?Filename required\n");
  12048.                 x = -9;
  12049.             }
  12050.             return(x);
  12051.         }
  12052.         if (y) {                        /* No wildcards */
  12053.             printf("?Wildcards not allowed here\n");
  12054.             return(-9);
  12055.         }
  12056.         if (filmode & (FM_APP|FM_WRI)) { /* Check output access */
  12057. #ifndef VMS
  12058.             if (zchko(s) < 0) {          /* and set error code if denied */
  12059.                 z_error = FX_ACC;
  12060.                 printf("?Write access denied - \"%s\"\n",s);
  12061.                 return(-9);
  12062.             }
  12063. #endif /* VMS */
  12064.         }
  12065.         ckstrncpy(zfilnam,s,CKMAXPATH); /* Is OK - make safe copy */
  12066.         if ((x = cmcfm()) < 0)          /* Get confirmation of command */
  12067.           return(x);
  12068.         if ((n = z_open(zfilnam,filmode)) < 0) {
  12069.             printf("?OPEN failed - %s: %s\n",zfilnam,ckferror(n));
  12070.             return(-9);
  12071.         }
  12072.         addmac(vnambuf,ckitoa(n));      /* Assign channel number to variable */
  12073.         return(success = 1);
  12074.  
  12075.       case FIL_REW:                     /* REWIND */
  12076.         if ((x = cmnum("Channel number","",10,&n, xxstring)) < 0) {
  12077.             if (x == -3) {
  12078.                 printf("?Channel number required\n");
  12079.                 x = -9;
  12080.             }
  12081.             return(x);
  12082.         }
  12083.         if ((x = cmcfm()) < 0)
  12084.           return(x);
  12085.         if ((rc = z_seek(n,0L)) < 0) {
  12086.             printf("?REWIND failed - Channel %d: %s\n",n,ckferror(rc));
  12087.             return(-9);
  12088.         }
  12089.         return(success = 1);
  12090.  
  12091.       case FIL_CLS:                     /* CLOSE */
  12092.           cmfdbi(&sw,                   /* Second FDB - switches */
  12093.                  _CMKEY,                /* fcode */
  12094.                  "Channel number; or keyword",
  12095.                  "",
  12096.                  "",                    /* addtl string data */
  12097.                  1,                     /* addtl numeric data 1: tbl size */
  12098.                  0,                     /* addtl numeric data 2: 4 = cmswi */
  12099.                  xxstring,              /* Processing function */
  12100.                  fclkwtab,              /* Keyword table */
  12101.                  &nu                    /* Pointer to next FDB */
  12102.                  );
  12103.           cmfdbi(&nu,                   /* First FDB - command switches */
  12104.                  _CMNUM,                /* fcode */
  12105.                  "",
  12106.                  "",                    /* default */
  12107.                  "",                    /* addtl string data */
  12108.                  10,                    /* addtl numeric data 1: radix */
  12109.                  0,                     /* addtl numeric data 2: 0 */
  12110.                  xxstring,              /* Processing function */
  12111.                  NULL,                  /* Keyword table */
  12112.                  NULL                   /* Pointer to next FDB */
  12113.                  );                     /*  */
  12114.         x = cmfdb(&sw);                 /* Parse something */
  12115.         if (x < 0) {
  12116.             if (x == -3) {
  12117.                 printf("?Channel number or ALL required\n");
  12118.                 x = -9;
  12119.             }
  12120.             return(x);
  12121.         }
  12122.         if (cmresult.fcode == _CMNUM)
  12123.           n = cmresult.nresult;
  12124.         else if (cmresult.fcode == _CMKEY)
  12125.           n = -1;
  12126.         if ((x = cmcfm()) < 0)
  12127.           return(x);
  12128.         rc = 1;
  12129.         if (n < 0) {
  12130.             int count = 0;
  12131.             int i;
  12132.             for (i = 0; i < z_maxchan; i++) {
  12133.                 x = z_close(i);
  12134.                 if (x == FX_SYS) {
  12135.                     printf("?CLOSE failed - Channel %d: %s\n",n,ckferror(x));
  12136.                     rc = 0;
  12137.                 } else if (x > -1)
  12138.                   count++;
  12139.             }
  12140.             debug(F101,"FILE CLOSE ALL","",count);
  12141.         } else if ((x = z_close(n)) < 0) {
  12142.             printf("?CLOSE failed - Channel %d: %s\n",n,ckferror(x));
  12143.             return(-9);
  12144.         }
  12145.         return(success = rc);
  12146.  
  12147.       case FIL_REA:                     /* READ */
  12148.       case FIL_WRI:                     /* WRITE */
  12149.         rsize = 0;
  12150.         cmfdbi(&sw,                     /* Switches */
  12151.                _CMKEY,                  /* fcode */
  12152.                "Channel or switch",     /* hlpmsg */
  12153.                "",                      /* default */
  12154.                "",                      /* addtl string data */
  12155.                (cx == FIL_REA) ? nfrdtab : nfwrtab,
  12156.                4,                       /* addtl numeric data 2: 4 = cmswi */
  12157.                xxstring,                /* Processing function */
  12158.                (cx == FIL_REA) ? frdtab : fwrtab, /* Keyword table */
  12159.                &nu                      /* Pointer to next FDB */
  12160.                );
  12161.         cmfdbi(&nu,                     /* Channel number */
  12162.                _CMNUM,                  /* fcode */
  12163.                "Channel",
  12164.                "",                      /* default */
  12165.                "",                      /* addtl string data */
  12166.                10,                      /* addtl numeric data 1: radix */
  12167.                0,                       /* addtl numeric data 2: 0 */
  12168.                xxstring,                /* Processing function */
  12169.                NULL,                    /* Keyword table */
  12170.                NULL                     /* Pointer to next FDB */
  12171.                );
  12172.         do {
  12173.             x = cmfdb(&sw);             /* Parse something */
  12174.             if (x < 0) {
  12175.                 if (x == -3) {
  12176.                     printf("?Channel number required\n");
  12177.                     x = -9;
  12178.                 }
  12179.                 return(x);
  12180.             }
  12181.             if (cmresult.fcode == _CMNUM) /* Channel number */
  12182.               break;
  12183.             else if (cmresult.fcode == _CMKEY) { /* Switch */
  12184.                 char c;
  12185.                 c = cmgbrk();
  12186.                 if ((getval =
  12187.                      (c == ':' || c == '=')) && !(cmgkwflgs() & CM_ARG)) {
  12188.                     printf("?This switch does not take an argument\n");
  12189.                     return(-9);
  12190.                 }
  12191.                 if (!getval && (cmgkwflgs() & CM_ARG)) {
  12192.                     printf("?This switch requires an argument\n");
  12193.                     return(-9);
  12194.                 }
  12195.                 switch (cmresult.nresult) {
  12196.                   case WR_LINE:
  12197.                     charflag = 0;
  12198.                     sizeflag = 0;
  12199.                     rsize = 0;
  12200.                     break;
  12201.                   case WR_CHAR:
  12202.                     rsize = 1;
  12203.                     charflag = 1;
  12204.                     sizeflag = 1;
  12205.                     break;
  12206.                   case WR_SIZE:
  12207.                     if ((x = cmnum("Bytes","",10,&rsize, xxstring)) < 0) {
  12208.                         if (x == -3) {
  12209.                             printf("?Number required\n");
  12210.                             x = -9;
  12211.                         }
  12212.                         return(x);
  12213.                     }
  12214.                     charflag = 0;
  12215.                     sizeflag = 1;
  12216.                     break;
  12217.                   case WR_STRI:
  12218.                     rsize = 1;
  12219.                     charflag = 0;
  12220.                     sizeflag = 0;
  12221.                     break;
  12222.                   case WR_LPAD:
  12223.                   case WR_RPAD:
  12224.                     if ((x = cmnum("Numeric ASCII character value",
  12225.                                    "32",10,&pad, xxstring)) < 0)
  12226.                       return(x);
  12227.                     if (cmresult.nresult == WR_LPAD)
  12228.                       wr_lpad = 1;
  12229.                     else
  12230.                       wr_rpad = 1;
  12231.                     break;
  12232.                 }
  12233.                 debug(F101,"FILE READ rsize 2","",rsize);
  12234.             } else
  12235.               return(-2);
  12236.         } while
  12237.           (cmresult.fcode == _CMKEY);
  12238.  
  12239.         n = cmresult.nresult;           /* Channel */
  12240.         debug(F101,"FILE READ/WRITE channel","",n);
  12241.  
  12242.         if (cx == FIL_WRI) {            /* WRITE */
  12243.             int len = 0;
  12244.             if ((x = cmtxt("Text","",&s,xxstring)) < 0)
  12245.               return(x);
  12246.             ckstrncpy(line,s,LINBUFSIZ); /* Make a safe copy */
  12247.             s = line;
  12248.             s = brstrip(s);             /* Strip braces */
  12249.             if (charflag) {             /* Write one char */
  12250.                 len = 1;                /* So length = 1 */
  12251.                 rsize = 1;              /* Don't supply terminator */
  12252.             } else if (!sizeflag) {     /* Write a string */
  12253.                 len = -1;               /* So length is unspecified */
  12254.             } else {                    /* Write a block of given size */
  12255.                 int i, k, xx;
  12256.                 if (rsize > TMPBUFSIZ) {
  12257.                     z_error = FX_OFL;
  12258.                     printf("?Buffer overflow\n");
  12259.                     return(-9);
  12260.                 }
  12261.                 len = rsize;            /* rsize is really length */
  12262.                 rsize = 1;              /* Don't supply a terminator */
  12263.                 xx = strlen(s);         /* Size of given string */
  12264.                 if (xx >= len) {        /* Bigger or equal */
  12265.                     s[len] = NUL;
  12266.                 } else if (wr_lpad) {   /* Smaller, left-padding requested */
  12267.                     for (i = 0; i < len - xx; i++) /* Must make a copy */
  12268.                       tmpbuf[i] = pad;
  12269.                     ckstrncpy(tmpbuf+i,s,TMPBUFSIZ-i);
  12270.                     tmpbuf[len] = NUL;
  12271.                     s = tmpbuf;         /* Redirect write source */
  12272.                 } else if (wr_rpad) {   /* Smaller with right-padding */
  12273.                     for (i = xx; i < len; i++)
  12274.                       s[i] = pad;
  12275.                     s[len] = NUL;
  12276.                 }
  12277.             }
  12278.             if ((rc = z_out(n,s,len,rsize)) < 0) { /* Try to write */
  12279.                 printf("?Channel %d WRITE error: %s\n",n,ckferror(rc));
  12280.                 return(-9);
  12281.             }
  12282.         } else {                        /* FIL_REA READ */
  12283.             confirmed = 0;
  12284.             vnambuf[0] = NUL;
  12285.             x = cmfld("Variable name","",&s,NULL);
  12286.             debug(F111,"FILE READ cmfld",s,x);
  12287.             if (x < 0) {
  12288.                 if (x == -3 || !*s) {
  12289.                     if ((x = cmcfm()) < 0)
  12290.                       return(x);
  12291.                     else
  12292.                       confirmed++;
  12293.                 } else
  12294.                   return(x);
  12295.             }
  12296.             ckstrncpy(vnambuf,s,VNAML);
  12297.             debug(F111,"FILE READ vnambuf",vnambuf,confirmed);
  12298.             if (vnambuf[0]) {           /* Variable name given, check it */
  12299.                 if (!confirmed) {
  12300.                     x = cmcfm();
  12301.                     if (x < 0)
  12302.                       return(x);
  12303.                     else
  12304.                       confirmed++;
  12305.                 }
  12306.                 vnp = vnambuf;
  12307.                 if (vnambuf[0] == CMDQ &&
  12308.                     (vnambuf[1] == '%' || vnambuf[1] == '&'))
  12309.                   vnp++;
  12310.                 y = 0;
  12311.                 if (*vnp == '%' || *vnp == '&') {
  12312.                     if ((y = parsevar(vnp,&x,&dummy)) < 0) {
  12313.                         printf("?Syntax error in variable name\n");
  12314.                         return(-9);
  12315.                     }
  12316.                 }
  12317.             }
  12318.             debug(F111,"FILE READ variable",vnambuf,confirmed);
  12319.  
  12320.             if (!confirmed)
  12321.               if ((x = cmcfm()) < 0)
  12322.                 return(x);
  12323.  
  12324.             line[0] = NUL;              /* Clear destination buffer */
  12325.             if (rsize >= LINBUFSIZ)     /* Don't overrun it */
  12326.               rsize = LINBUFSIZ - 1;
  12327.  
  12328.             if (rsize == 0)             /* Read a line */
  12329.               rc = z_in(n,line,LINBUFSIZ,LINBUFSIZ-1,0);
  12330.             else
  12331.               rc = z_in(n,line,LINBUFSIZ,rsize,1); /* Read a block */
  12332.             if (rc < 0) {               /* Error... */
  12333.                 debug(F101,"FILE READ error","",rc);
  12334.                 debug(F101,"FILE READ errno","",errno);
  12335.                 if (rc == FX_EOF) {     /* EOF - fail but no error message */
  12336.                     return(success = 0);
  12337.                 } else {                /* Other error - fail and print msg */
  12338.                     printf("?READ error: %s\n",ckferror(rc));
  12339.                     return(-9);
  12340.                 }
  12341.             }
  12342.             debug(F110,"FILE READ data",line,0);
  12343.             if (vnambuf[0])             /* Read OK - If variable name given */
  12344.               addmac(vnambuf,line);     /* Assign result to variable */
  12345.             else                        /* otherwise */
  12346.               printf("%s\n",line);      /* just print it */
  12347.         }
  12348.         return(success = 1);
  12349.  
  12350.       case FIL_SEE:                     /* SEEK */
  12351.       case FIL_COU:                     /* COUNT */
  12352.         rsize = RD_CHAR;                /* Defaults to /BYTE */
  12353.         cmfdbi(&sw,                     /* Switches */
  12354.                _CMKEY,                  /* fcode */
  12355.                "Channel or switch",     /* hlpmsg */
  12356.                "",                      /* default */
  12357.                "",                      /* addtl string data */
  12358.                ((cx == FIL_SEE) ? nfskswtab : nfcoswtab),
  12359.                4,                       /* addtl numeric data 2: 4 = cmswi */
  12360.                xxstring,                /* Processing function */
  12361.                ((cx == FIL_SEE) ? fskswtab : fcoswtab),
  12362.                &nu                      /* Pointer to next FDB */
  12363.                );
  12364.         cmfdbi(&nu,                     /* Channel number */
  12365.                _CMNUM,                  /* fcode */
  12366.                "Channel",
  12367.                "",                      /* default */
  12368.                "",                      /* addtl string data */
  12369.                10,                      /* addtl numeric data 1: radix */
  12370.                0,                       /* addtl numeric data 2: 0 */
  12371.                xxstring,                /* Processing function */
  12372.                NULL,                    /* Keyword table */
  12373.                NULL                     /* Pointer to next FDB */
  12374.                );
  12375.         do {
  12376.             x = cmfdb(&sw);             /* Parse something */
  12377.             if (x < 0) {
  12378.                 if (x == -3) {
  12379.                     printf("?Channel number required\n");
  12380.                     x = -9;
  12381.                 }
  12382.                 return(x);
  12383.             }
  12384.             if (cmresult.fcode == _CMNUM) /* Channel number */
  12385.               break;
  12386.             else if (cmresult.fcode == _CMKEY) { /* Switch */
  12387.                 char c;
  12388.                 c = cmgbrk();
  12389.                 if ((getval =
  12390.                      (c == ':' || c == '=')) && !(cmgkwflgs() & CM_ARG)) {
  12391.                     printf("?This switch does not take an argument\n");
  12392.                     return(-9);
  12393.                 }
  12394.                 if (cx == FIL_SEE) {
  12395.                     switch (cmresult.nresult) {
  12396.                       case SEE_REL: relative = 1; break;
  12397.                       case SEE_ABS: relative = 0; break;
  12398.                       default: rsize = cmresult.nresult;
  12399.                     }
  12400.                 } else if (cx == FIL_COU) {
  12401.                     switch (cmresult.nresult) {
  12402.                       case COU_LIS: listing = 1; break;
  12403.                       case COU_NOL: listing = 0; break;
  12404.                       default: rsize = cmresult.nresult;
  12405.                     }
  12406.                 }
  12407.             }
  12408.         } while
  12409.           (cmresult.fcode == _CMKEY);
  12410.  
  12411.         n = cmresult.nresult;           /* Channel */
  12412.         debug(F101,"FILE SEEK/COUNT channel","",n);
  12413.         if (cx == FIL_COU) {
  12414.             if ((x = cmcfm()) < 0)
  12415.               return(x);
  12416.             z_filcount = z_count(n,rsize);
  12417.             if (z_filcount < 0) {
  12418.                 rc = z_filcount;
  12419.                 printf("?COUNT error: %s\n",ckferror(rc));
  12420.                 return(-9);
  12421.             }
  12422.             if (listing < 0)
  12423.               listing = !xcmdsrc;
  12424.             if (listing)
  12425.               printf(" %ld %s%s\n",
  12426.                      z_filcount,
  12427.                      ((rsize == RD_CHAR) ? "byte" : "line"),
  12428.                      ((z_filcount == 1L) ? "" : "s")
  12429.                      );
  12430.             return(success = (z_filcount > -1) ? 1 : 0);
  12431.         }
  12432.         cmfdbi(&sw,                     /* SEEK symbolic targets (EOF) */
  12433.                _CMKEY,                  /* fcode */
  12434.                "Channel number;\n or keyword",
  12435.                "",
  12436.                "",                      /* addtl string data */
  12437.                nfsekwtab,               /* addtl numeric data 1: table size */
  12438.                0,                       /* addtl numeric data 2: 4 = cmswi */
  12439.                xxstring,                /* Processing function */
  12440.                fsekwtab,                /* Keyword table */
  12441.                &nu                      /* Pointer to next FDB */
  12442.                );
  12443.         cmfdbi(&nu,                     /* Channel number */
  12444.                _CMNUM,                  /* fcode */
  12445.                "",
  12446.                "",                      /* default */
  12447.                "",                      /* addtl string data */
  12448.                10,                      /* addtl numeric data 1: radix */
  12449.                0,                       /* addtl numeric data 2: 0 */
  12450.                xxstring,                /* Processing function */
  12451.                NULL,                    /* Keyword table */
  12452.                NULL                     /* Pointer to next FDB */
  12453.                );
  12454.         x = cmfdb(&sw);                 /* Parse something */
  12455.         if (x < 0) {
  12456.             if (x == -3) {
  12457.                 printf("?Channel number or EOF required\n");
  12458.                 x = -9;
  12459.             }
  12460.             return(x);
  12461.         }
  12462.         if (cmresult.fcode == _CMNUM) {
  12463.             y = cmresult.nresult;
  12464.             debug(F110,"FILE SEEK atmbuf",atmbuf,0);
  12465.             if (relative < 0) {
  12466.                 if (cx == FIL_SEE && (atmbuf[0] == '+' || atmbuf[0] == '-'))
  12467.                   relative = 1;
  12468.                 else
  12469.                   relative = 0;
  12470.             }
  12471.         } else if (cmresult.fcode == _CMKEY) {
  12472.             eofflg = cmresult.nresult;
  12473.             relative = 0;
  12474.             y = 0 - eofflg;
  12475.         }
  12476.         if ((x = cmcfm()) < 0)
  12477.           return(x);
  12478.         z = y;                          /* Convert to long */
  12479.         y = 1;                          /* Recycle this */
  12480.         z_flush(n);
  12481.         debug(F101,"FILE SEEK relative","",relative);
  12482.         debug(F101,"FILE SEEK rsize","",rsize);
  12483.  
  12484.         if (rsize == RD_CHAR) {         /* Seek to byte position */
  12485.             if (relative > 0) {
  12486.                 long pos;
  12487.                 pos = z_getpos(n);
  12488.                 if (pos < 0L) {
  12489.                     rc = pos;
  12490.                     printf("?Relative SEEK failed: %s\n",ckferror(rc));
  12491.                     return(-9);
  12492.                 }
  12493.                 z += pos;
  12494.             } else {
  12495.                 if (z < 0 && !eofflg) { /* Negative arg but not relative */
  12496.                     y = 0;              /* Remember this was bad */
  12497.                     z = 0;              /* but substitute 0 */
  12498.                 }
  12499.             }
  12500.             debug(F101,"FILE SEEK /CHAR z","",z);
  12501.             if (z < 0 && !eofflg) {
  12502.                 z_error = FX_RNG;
  12503.                 return(success = 0);
  12504.             }
  12505.             if ((rc = z_seek(n,z)) < 0) {
  12506.                 if (rc == FX_EOF) return(success = 0);
  12507.                 printf("?SEEK /BYTE failed - Channel %d: %s\n",n,ckferror(rc));
  12508.                 return(-9);
  12509.             }
  12510.         } else {                        /* Seek to line */
  12511.             if (relative > 0) {
  12512.                 long pos;
  12513.                 pos = z_getline(n);
  12514.                 debug(F101,"FILE SEEK /LINE pos","",pos);
  12515.                 if (pos < 0L) {
  12516.                     rc = pos;
  12517.                     printf("?Relative SEEK failed: %s\n",ckferror(rc));
  12518.                     return(-9);
  12519.                 }
  12520.                 z += pos;
  12521.             }
  12522.             debug(F101,"FILE SEEK /LINE z","",z);
  12523.             debug(F101,"FILE SEEK /LINE eofflg","",eofflg);
  12524.             if (z < 0 && !eofflg) {
  12525.                 z_error = FX_RNG;
  12526.                 return(success = 0);
  12527.             }
  12528.             if ((rc = z_line(n,z)) < 0) {
  12529.                 if (rc == FX_EOF) return(success = 0);
  12530.                 printf("?SEEK /LINE failed - Channel %d: %s\n",n,ckferror(rc));
  12531.                 return(-9);
  12532.             }
  12533.         }
  12534.         return(success = y);
  12535.  
  12536.       case FIL_LIS: {                   /* LIST open files */
  12537. #ifdef CK_TTGWSIZ
  12538.           extern int cmd_rows, cmd_cols;
  12539. #endif /* CK_TTGWSIZ */
  12540.           extern int xaskmore;
  12541.           int i, x, n = 0, paging = 0;
  12542.           char * s;
  12543.  
  12544.           if ((x = cmcfm()) < 0)
  12545.             return(x);
  12546.  
  12547. #ifdef CK_TTGWSIZ
  12548.           if (cmd_rows > 0 && cmd_cols > 0)
  12549. #endif /* CK_TTGWSIZ */
  12550.             paging = xaskmore;
  12551.  
  12552.           printf("System open file limit: %4d\n", z_openmax);
  12553.           printf("Maximum for FILE OPEN:  %4d\n", z_maxchan);
  12554.           printf("Files currently open:   %4d\n\n", z_nopen);
  12555.           n = 4;
  12556.           for (i = 0; i < z_maxchan; i++) {
  12557.               s = z_getname(i);         /* Got one? */
  12558.               if (s) {                  /* Yes */
  12559.                   char m[8];
  12560.                   m[0] = NUL;
  12561.                   printf("%2d. %s",i,s); /* Print name */
  12562.                   n++;                   /* Count it */
  12563.                   x = z_getmode(i);      /* Get modes & print them */
  12564.                   if (x > -1) {
  12565.                       if (x & FM_REA) ckstrncat(m,"R",8);
  12566.                       if (x & FM_WRI) ckstrncat(m,"W",8);
  12567.                       if (x & FM_APP) ckstrncat(m,"A",8);
  12568.                       if (x & FM_BIN) ckstrncat(m,"B",8);
  12569.                       if (m[0])
  12570.                         printf(" (%s)",m);
  12571.                       if (x & FM_EOF)
  12572.                         printf(" [EOF]");
  12573.                       else
  12574.                         printf(" %ld",z_getpos(i)); /* And file position too */
  12575.                   }
  12576.                   printf("\n");
  12577. #ifdef CK_TTGWSIZ
  12578.                   if (paging > 0) {     /* Pause at end of screen */
  12579.                       if (n > cmd_rows - 3) {
  12580.                           if (!askmore())
  12581.                             break;
  12582.                           else
  12583.                             n = 0;
  12584.                       }
  12585.                   }
  12586. #endif /* CK_TTGWSIZ */
  12587.               }
  12588.           }
  12589.           return(success = 1);
  12590.       }
  12591.  
  12592.       case FIL_FLU:                     /* FLUSH */
  12593.         if ((x = cmnum("Channel number","",10,&n, xxstring)) < 0) {
  12594.             if (x == -3) {
  12595.                 printf("?Channel number required\n");
  12596.                 x = -9;
  12597.             }
  12598.             return(x);
  12599.         }
  12600.         if ((x = cmcfm()) < 0)
  12601.           return(x);
  12602.         if ((rc = z_flush(n)) < 0) {
  12603.             printf("?FLUSH failed - Channel %d: %s\n",n,ckferror(rc));
  12604.             return(-9);
  12605.         }
  12606.         return(success = 1);
  12607.  
  12608.       case FIL_STA:                     /* STATUS */
  12609.         if ((x = cmnum("Channel number","",10,&n, xxstring)) < 0) {
  12610.             if (x == -3) {
  12611.                 printf("?Channel number required\n");
  12612.                 x = -9;
  12613.             }
  12614.             return(x);
  12615.         }
  12616.         if ((x = cmcfm()) < 0)
  12617.           return(x);
  12618.         p = blanks + 3;                 /* Tricky formatting... */
  12619.         if (n < 1000) p--;
  12620.         if (n < 100) p--;
  12621.         if (n < 10) p--;
  12622.         if ((rc = z_getmode(n)) < 0) {
  12623.             printf("Channel %d:%s%s\n",n,p,ckferror(rc));
  12624.             return(success = 0);
  12625.         } else if (!rc) {
  12626.             printf("Channel %d:%sNot open\n",n,p);
  12627.             return(success = 0);
  12628.         } else {
  12629.             long xx;
  12630.             s = z_getname(n);
  12631.             if (!s) s = "(name unknown)";
  12632.             printf("Channel %d:%sOpen\n",n,p);
  12633.             printf(" File:        %s\n Modes:      ",s);
  12634.             if (rc & FM_REA) printf(" /READ");
  12635.             if (rc & FM_WRI) printf(" /WRITE");
  12636.             if (rc & FM_APP) printf(" /APPEND");
  12637.             if (rc & FM_BIN) printf(" /BINARY");
  12638.             if (rc & FM_CMD) printf(" /COMMAND");
  12639.             if (rc & FM_EOF) printf(" [EOF]");
  12640.             printf("\n Size:        %ld\n",z_count(n,RD_CHAR));
  12641.             printf(" At byte:     %ld\n",z_getpos(n));
  12642.             xx = z_getline(n);
  12643.             if (xx > -1)
  12644.               printf(" At line:     %ld\n",xx);
  12645.             return(success = 1);
  12646.         }
  12647.       default:
  12648.         return(-2);
  12649.     }
  12650. }
  12651. #endif /* CKCHANNELIO */
  12652.  
  12653. #ifndef NOSETKEY
  12654. /* Save Key maps and in OS/2 Mouse maps */
  12655. int
  12656. savkeys(name,disp) char * name; int disp; {
  12657.     char *tp;
  12658.     static struct filinfo xx;
  12659.     int savfil, i, j, k;
  12660.     char buf[1024];
  12661.  
  12662.     zclose(ZMFILE);
  12663.  
  12664.     if (disp) {
  12665.         xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  12666.         xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = "";
  12667.         xx.lblopts = 0;
  12668.         savfil = zopeno(ZMFILE,name,NULL,&xx);
  12669.     } else savfil = zopeno(ZMFILE,name,NULL,NULL);
  12670.  
  12671.     if (savfil) {
  12672. #ifdef OS2
  12673.         ztime(&tp);
  12674.         zsout(ZMFILE, "; Kermit 95 SAVE KEYMAP file: ");
  12675.         zsoutl(ZMFILE,tp);
  12676.         if (mskkeys) {
  12677.             zsoutl(ZMFILE,
  12678.          "if eq \"\\v(program)\" \"C-Kermit\" set mskermit keycodes on");
  12679.         } else {
  12680.             zsoutl(ZMFILE,
  12681.          "if NOT eq \"\\v(program)\" \"C-Kermit\" stop 1 C-Kermit required.");
  12682.             zsoutl(ZMFILE,"set mskermit keycodes off");
  12683.         }
  12684.         zsoutl(ZMFILE,"");
  12685. #else /* OS2 */
  12686.         ztime(&tp);
  12687.         zsout(ZMFILE, "; C-Kermit SAVE KEYMAP file: ");
  12688.         zsoutl(ZMFILE,tp);
  12689. #endif /* OS2 */
  12690.  
  12691.         zsoutl(ZMFILE,"; Clear previous keyboard mappings ");
  12692.         zsoutl(ZMFILE,"set key clear");
  12693. #ifdef OS2
  12694.         for (k = 0; k < nttkey; k++) {
  12695.             if (!ttkeytab[k].flgs) {
  12696.                 ckmakmsg(buf,1024,
  12697.                          "set terminal key ",
  12698.                          ttkeytab[k].kwd,
  12699.                          " clear",
  12700.                          NULL
  12701.                          );
  12702.                 zsoutl(ZMFILE,buf);
  12703.             }
  12704.         }
  12705. #endif /* OS2 */
  12706.         zsoutl(ZMFILE,"");
  12707.  
  12708.         for (i = 0; i < KMSIZE; i++) {
  12709.             if (macrotab[i]) {
  12710.                 int len = strlen((char *)macrotab[i]);
  12711. #ifdef OS2
  12712.                 ckmakmsg(buf,
  12713.                          1024,
  12714.                          "set key \\",
  12715.                          ckitoa(mskkeys ? cktomsk(i) : i),
  12716.                          " ",
  12717.                          NULL
  12718.                          );
  12719. #else /* OS2 */
  12720.                 ckmakmsg(buf,
  12721.                          1024,
  12722.                          "set key \\",
  12723.                          ckitoa(i),
  12724.                          NULL,NULL
  12725.                          );
  12726. #endif /* OS2 */
  12727.                 zsout(ZMFILE,buf);
  12728.  
  12729.                 for (j = 0; j < len; j++) {
  12730.                     char ch = macrotab[i][j];
  12731.                     if (ch <= SP || ch >= DEL ||
  12732.                          ch == '-' || ch == ',' ||
  12733.                          ch == '{' || ch == '}' ||
  12734.                          ch == ';' || ch == '?' ||
  12735.                          ch == '.' || ch == '\'' ||
  12736.                          ch == '\\' || ch == '/' ||
  12737.                          ch == '#') {
  12738.                         ckmakmsg(buf,1024,"\\{",ckitoa((int)ch),"}",NULL);
  12739.                         zsout(ZMFILE,buf);
  12740.                     } else {
  12741.                         ckmakmsg(buf,1024,ckctoa((char)ch),NULL,NULL,NULL);
  12742.                         zsout(ZMFILE,buf);
  12743.                     }
  12744.                 }
  12745. #ifdef OS2
  12746.                 ckmakmsg(buf,1024,"\t; ",keyname(i),NULL,NULL);
  12747.                 zsoutl(ZMFILE,buf);
  12748. #else
  12749.                 zsoutl(ZMFILE,"");
  12750. #endif /* OS2 */
  12751.             } else if ( keymap[i] != i ) {
  12752. #ifndef NOKVERBS
  12753.                 if (IS_KVERB(keymap[i])) {
  12754.                     for (j = 0; j < nkverbs; j++)
  12755.                       if (kverbs[j].kwval == (keymap[i] & ~F_KVERB))
  12756.                         break;
  12757.                     if (j != nkverbs) {
  12758. #ifdef OS2
  12759. #ifdef COMMENT
  12760.                         sprintf(buf, "set key \\%d \\K%s\t; %s",
  12761.                                 mskkeys ? cktomsk(i) : i,
  12762.                                 kverbs[j].kwd, keyname(i)
  12763.                                 );
  12764. #else
  12765.                         ckmakxmsg(buf,  /* 12 string args */
  12766.                                   1024,
  12767.                                   "set key \\",
  12768.                                   ckitoa(mskkeys ? cktomsk(i) : i),
  12769.                                   " \\K",
  12770.                                   kverbs[j].kwd,
  12771.                                   "\t; ",
  12772.                                   keyname(i),
  12773.                                   NULL, NULL, NULL, NULL, NULL, NULL);
  12774. #endif /* COMMENT */
  12775.                         zsoutl(ZMFILE,buf);
  12776. #else
  12777. #ifdef COMMENT
  12778.                         sprintf(buf, "set key \\%d \\K%s", i, kverbs[j].kwd);
  12779. #else
  12780.                         ckmakmsg(buf,1024,
  12781.                                  "set key \\",
  12782.                                  ckitoa(i),
  12783.                                  " \\K",
  12784.                                  kverbs[j].kwd
  12785.                                  );
  12786. #endif /* COMMENT */
  12787.                         zsoutl(ZMFILE,buf);
  12788. #endif
  12789.                     }
  12790.                 } else
  12791. #endif /* NOKVERBS */
  12792.                   {
  12793. #ifdef OS2
  12794. #ifdef COMMENT
  12795.                       sprintf(buf, "set key \\%d \\{%d}\t; %s",
  12796.                               mskkeys ? cktomsk(i) : i,
  12797.                               keymap[i],
  12798.                               keyname(i)
  12799.                               );
  12800. #else
  12801.                       ckmakxmsg(buf,    /* 8 string args */
  12802.                                 1024,
  12803.                                 "set key \\",
  12804.                                 ckitoa(mskkeys ? cktomsk(i) : i),
  12805.                                 " \\{",
  12806.                                 ckitoa(keymap[i]),
  12807.                                 "}\t; ",
  12808.                                 keyname(i),
  12809.                                 NULL,NULL,NULL,NULL,NULL,NULL);
  12810. #endif /* COMMENT */
  12811.                       zsoutl(ZMFILE,buf);
  12812. #else
  12813. #ifdef COMMENT
  12814.                       sprintf(buf, "set key \\%d \\{%d}", i, keymap[i]);
  12815. #else
  12816.                       ckmakxmsg(buf,1024,
  12817.                                "set key \\",
  12818.                                ckitoa(i),
  12819.                                " \\{",
  12820.                                ckitoa(keymap[i]),
  12821.                                "}",
  12822.                                NULL,NULL,NULL,NULL,NULL,NULL,NULL);
  12823. #endif /* COMMENT */
  12824.                       zsoutl(ZMFILE,buf);
  12825. #endif /* OS2 */
  12826.                   }
  12827.             }
  12828.         }
  12829. #ifdef OS2
  12830.         /* OS/2 also has the SET TERMINAL KEY <termtype> defines */
  12831.         for (k = 0; k < nttkey; k++) {
  12832.             extern struct keynode * ttkeymap[];
  12833.             struct keynode * pnode = NULL;
  12834.  
  12835.             if (ttkeytab[k].flgs)       /* Don't process CM_INV or CM_ABR */
  12836.               continue;
  12837.  
  12838.             zsoutl(ZMFILE,"");
  12839.             ckmakmsg(buf,1024,"; SET TERMINAL KEY ",ttkeytab[k].kwd,NULL,NULL);
  12840.             zsoutl(ZMFILE,buf);
  12841.  
  12842.             for (pnode = ttkeymap[ttkeytab[k].kwval];
  12843.                  pnode;
  12844.                  pnode = pnode->next
  12845.                  ) {
  12846.                 switch (pnode->def.type) {
  12847.                   case key:
  12848. #ifdef COMMENT
  12849.                     sprintf(buf, "set terminal key %s \\%d \\{%d}\t; %s",
  12850.                             ttkeytab[k].kwd,
  12851.                             mskkeys ? cktomsk(pnode->key) : pnode->key,
  12852.                             pnode->def.key.scancode,
  12853.                             keyname(pnode->key)
  12854.                             );
  12855. #else
  12856.                     ckmakxmsg(buf,
  12857.                               1024,
  12858.                               "set terminal key ",
  12859.                               ttkeytab[k].kwd,
  12860.                               " \\",
  12861.                               ckitoa(mskkeys ?
  12862.                                      cktomsk(pnode->key) :
  12863.                                      pnode->key),
  12864.                               " \\{",
  12865.                               ckitoa(pnode->def.key.scancode),
  12866.                               "}\t; ",
  12867.                               keyname(pnode->key),
  12868.                               NULL,NULL,NULL,NULL
  12869.                               );
  12870. #endif /* COMMENT */
  12871.                     zsoutl(ZMFILE,buf);
  12872.                     break;
  12873.                   case kverb:
  12874.                     for (j = 0; j < nkverbs; j++)
  12875.                       if (kverbs[j].kwval == (pnode->def.kverb.id & ~F_KVERB))
  12876.                         break;
  12877.                     if (j != nkverbs) {
  12878. #ifdef COMMENT
  12879.                         sprintf(buf, "set terminal key %s \\%d \\K%s\t; %s",
  12880.                                 ttkeytab[k].kwd,
  12881.                                 mskkeys ? cktomsk(pnode->key) : pnode->key,
  12882.                                 kverbs[j].kwd, keyname(pnode->key)
  12883.                                 );
  12884. #else
  12885.                         ckmakxmsg(buf,
  12886.                                   1024,
  12887.                                   "set terminal key ",
  12888.                                   ttkeytab[k].kwd,
  12889.                                   " \\",
  12890.                                   ckitoa(mskkeys ?
  12891.                                          cktomsk(pnode->key) :
  12892.                                          pnode->key),
  12893.                                   " \\K",
  12894.                                   kverbs[j].kwd,
  12895.                                   "\t; ",
  12896.                                   keyname(pnode->key),
  12897.                                   NULL,NULL,NULL,NULL
  12898.                                   );
  12899. #endif /* COMMENT */
  12900.                         zsoutl(ZMFILE,buf);
  12901.                     }
  12902.                     break;
  12903.                   case macro: {
  12904.                       int len = strlen((char *)pnode->def.macro.string);
  12905. #ifdef COMMENT
  12906.                       sprintf(buf,"set terminal key %s \\%d ",
  12907.                               ttkeytab[k].kwd,
  12908.                               mskkeys ? cktomsk(pnode->key) : pnode->key);
  12909. #else
  12910.                       ckmakxmsg(buf,
  12911.                                1024,
  12912.                                "set terminal key ",
  12913.                                ttkeytab[k].kwd,
  12914.                                " \\",
  12915.                                ckitoa(mskkeys ?
  12916.                                       cktomsk(pnode->key) :
  12917.                                       pnode->key),
  12918.                                " ",
  12919.                                NULL,NULL,NULL,NULL,NULL,NULL,NULL
  12920.                               );
  12921. #endif /* COMMENT */
  12922.                       zsout(ZMFILE,buf);
  12923.  
  12924.                       for (j = 0; j < len; j++) {
  12925.                           char ch = pnode->def.macro.string[j];
  12926.                           if (ch <= SP || ch >= DEL ||
  12927.                                ch == '-' || ch == ',' ||
  12928.                                ch == '{' || ch == '}' ||
  12929.                                ch == ';' || ch == '?' ||
  12930.                                ch == '.' || ch == '\'' ||
  12931.                                ch == '\\' || ch == '/' ||
  12932.                                ch == '#') {
  12933.                               ckmakmsg(buf,1024,
  12934.                                        "\\{",ckitoa((int)ch),"}",NULL);
  12935.                               zsout(ZMFILE,buf);
  12936.                           } else {
  12937.                               ckmakmsg(buf,1024,
  12938.                                        ckctoa((char)ch),NULL,NULL,NULL);
  12939.                               zsout(ZMFILE,buf);
  12940.                           }
  12941.                       }
  12942.                       ckmakmsg(buf,1024,"\t; ",keyname(pnode->key),NULL,NULL);
  12943.                       zsoutl(ZMFILE,buf);
  12944.                       break;
  12945.                   }
  12946.                   case literal: {
  12947.                       int len = strlen((char *)pnode->def.literal.string);
  12948. #ifdef COMMENT
  12949.                       sprintf(buf,"set terminal key %s /literal \\%d ",
  12950.                               ttkeytab[k].kwd,
  12951.                               mskkeys ? cktomsk(pnode->key) : pnode->key);
  12952. #else
  12953.                       ckmakxmsg(buf,
  12954.                                1024,
  12955.                                "set terminal key ",
  12956.                                ttkeytab[k].kwd,
  12957.                                " /literal \\",
  12958.                                ckitoa(mskkeys ?
  12959.                                       cktomsk(pnode->key) :
  12960.                                       pnode->key),
  12961.                                " ",
  12962.                                NULL,NULL,NULL,NULL,NULL,NULL,NULL);
  12963. #endif /* COMMENT */
  12964.                       zsout(ZMFILE,buf);
  12965.  
  12966.                       for (j = 0; j < len; j++) {
  12967.                           char ch = pnode->def.literal.string[j];
  12968.                           if (ch <= SP || ch >= DEL ||
  12969.                                ch == '-' || ch == ',' ||
  12970.                                ch == '{' || ch == '}' ||
  12971.                                ch == ';' || ch == '?' ||
  12972.                                ch == '.' || ch == '\'' ||
  12973.                                ch == '\\' || ch == '/' ||
  12974.                                ch == '#') {
  12975.                               ckmakmsg(buf,1024,
  12976.                                        "\\{",ckitoa((int)ch),"}",NULL);
  12977.                               zsout(ZMFILE,buf);
  12978.                           } else {
  12979.                               ckmakmsg(buf,1024,
  12980.                                        ckctoa((char)ch),NULL,NULL,NULL);
  12981.                               zsout(ZMFILE,buf);
  12982.                           }
  12983.                       }
  12984.                       ckmakmsg(buf,1024,"\t; ",keyname(pnode->key),NULL,NULL);
  12985.                       zsoutl(ZMFILE,buf);
  12986.                       break;
  12987.                   }
  12988.                   case esc:
  12989. #ifdef COMMENT
  12990.                     sprintf(buf,
  12991.                        "set terminal key %s /literal \\%d \\{%d}\\{%d}\t; %s",
  12992.                             ttkeytab[k].kwd,
  12993.                             mskkeys ? cktomsk(pnode->key) : pnode->key,
  12994.                             ISDG200(ttkeytab[k].kwval) ? 30 : 27,
  12995.                             pnode->def.esc.key & ~F_ESC,
  12996.                             keyname(pnode->key)
  12997.                             );
  12998. #else
  12999.                     ckmakxmsg(buf,
  13000.                               1024,
  13001.                               "set terminal key ",
  13002.                               ttkeytab[k].kwd,
  13003.                               " /literal \\",
  13004.                               ckitoa(mskkeys ?
  13005.                                      cktomsk(pnode->key) :
  13006.                                      pnode->key),
  13007.                               " \\{",
  13008.                               ckitoa(ISDG200(ttkeytab[k].kwval) ? 30 : 27),
  13009.                               "}\\{",
  13010.                               ckitoa(pnode->def.esc.key & ~F_ESC),
  13011.                               "}\t; ",
  13012.                               keyname(pnode->key),
  13013.                               NULL,NULL
  13014.                               );
  13015. #endif /* COMMENT */
  13016.                     zsoutl(ZMFILE,buf);
  13017.                     break;
  13018.                   case csi:
  13019. #ifdef COMMENT
  13020.                     sprintf(buf,
  13021.                        "set terminal key %s /literal \\%d \\{27}[\\{%d}\t; %s",
  13022.                             ttkeytab[k].kwd,
  13023.                             mskkeys ? cktomsk(pnode->key) : pnode->key,
  13024.                             pnode->def.csi.key & ~F_CSI,
  13025.                             keyname(pnode->key)
  13026.                             );
  13027. #else
  13028.                     ckmakxmsg(buf,
  13029.                               1024,
  13030.                               "set terminal key ",
  13031.                               ttkeytab[k].kwd,
  13032.                               " /literal \\",
  13033.                               ckitoa(mskkeys ?
  13034.                                      cktomsk(pnode->key) :
  13035.                                      pnode->key),
  13036.                               " \\{27}[\\{",
  13037.                               ckitoa(pnode->def.csi.key & ~F_CSI),
  13038.                               "}\t; ",
  13039.                               keyname(pnode->key),
  13040.                               NULL,NULL,NULL,NULL
  13041.                               );
  13042. #endif /* COMMENT */
  13043.                     zsoutl(ZMFILE,buf);
  13044.                     break;
  13045.                   default:
  13046.                     continue;
  13047.                 }
  13048.             }
  13049.         }
  13050. #endif /* OS2 */
  13051.  
  13052.         zsoutl(ZMFILE,"");
  13053.         zsoutl(ZMFILE,"; End");
  13054.         zclose(ZMFILE);
  13055.         return(success = 1);
  13056.     } else {
  13057.         return(success = 0);
  13058.     }
  13059. }
  13060. #endif /* NOSETKEY */
  13061.  
  13062. #define SV_SCRL 0
  13063. #define SV_HIST 1
  13064.  
  13065. #ifdef OS2
  13066. #ifndef NOLOCAL
  13067. static struct keytab trmtrmopt[] = {
  13068.     { "scrollback", SV_SCRL, 0 }
  13069. };
  13070. #endif /* NOLOCAL */
  13071. #endif /* OS2 */
  13072.  
  13073. static struct keytab cmdtrmopt[] = {
  13074. #ifdef CK_RECALL
  13075.     { "history",    SV_HIST, 0 },
  13076. #endif /* CK_RECALL */
  13077. #ifdef OS2
  13078. #ifndef NOLOCAL
  13079.     { "scrollback", SV_SCRL, 0 },
  13080. #endif /* NOLOCAL */
  13081. #endif /* OS2 */
  13082.     { "", 0, 0 }
  13083. };
  13084. static int ncmdtrmopt = (sizeof (cmdtrmopt) / sizeof (struct keytab)) - 1;
  13085.  
  13086. #ifdef OS2
  13087. #ifndef NOLOCAL
  13088. _PROTOTYP(int savscrbk, (int, char *, int));
  13089. #endif /* NOLOCAL */
  13090. #endif /* OS2 */
  13091.  
  13092. #ifdef CK_RECALL
  13093. _PROTOTYP(int savhistory, (char *, int));
  13094. #endif /* CK_RECALL */
  13095.  
  13096. int
  13097. dosave(xx) int xx; {
  13098.     int x, y = 0, disp;
  13099.     char * s = NULL;
  13100.     extern struct keytab disptb[];
  13101. #ifdef ZFNQFP
  13102.     struct zfnfp * fnp;
  13103. #endif /* ZFNQFP */
  13104.  
  13105. #ifndef NOSETKEY
  13106.     if (xx == XSKEY) {                  /* SAVE KEYMAP.. */
  13107.         z = cmofi("Name of Kermit command file","keymap.ksc",&s,xxstring);
  13108.     } else {
  13109. #endif /* NOSETKEY */
  13110.         switch (xx) {
  13111.           case XSCMD:                   /* SAVE COMMAND.. */
  13112.             if ((y = cmkey(cmdtrmopt, ncmdtrmopt, "What to save",
  13113. #ifdef OS2
  13114.                            "scrollback",
  13115. #else
  13116.                            "history",
  13117. #endif /* OS2 */
  13118.                            xxstring)) < 0)
  13119.               return(y);
  13120.             break;
  13121. #ifdef OS2
  13122. #ifndef NOLOCAL
  13123.           case XSTERM:                  /* SAVE TERMINAL.. */
  13124.             if ((y = cmkey(trmtrmopt,1,
  13125.                            "What to save","scrollback",xxstring)) < 0)
  13126.               return(y);
  13127.             break;
  13128. #endif /* NOLOCAL */
  13129. #endif /* OS2 */
  13130.         }
  13131.         z = cmofi("Filename",
  13132.                   ((y == SV_SCRL) ? "scrollbk.txt" : "history.txt"),
  13133.                   &s,
  13134.                   xxstring
  13135.                   );
  13136. #ifndef NOSETKEY
  13137.     }
  13138. #endif /* NOSETKEY */
  13139.     if (z < 0)                          /* Check output-file parse results */
  13140.       return(z);
  13141.     if (z == 2) {
  13142.         printf("?Sorry, %s is a directory name\n",s);
  13143.         return(-9);
  13144.     }
  13145. #ifdef ZFNQFP
  13146.     if ((fnp = zfnqfp(s,TMPBUFSIZ - 1,tmpbuf))) {/* Convert to full pathname */
  13147.         if (fnp->fpath)
  13148.           if ((int) strlen(fnp->fpath) > 0)
  13149.             s = fnp->fpath;
  13150.     }
  13151. #endif /* ZFNQFP */
  13152.  
  13153.     ckstrncpy(line,s,LINBUFSIZ);        /* Make safe copy of pathname */
  13154.     s = line;
  13155. #ifdef MAC
  13156.     z = 0;
  13157. #else
  13158.     /* Get NEW/APPEND disposition */
  13159.     if ((z = cmkey(disptb,2,"Disposition","new",xxstring)) < 0)
  13160.       return(z);
  13161. #endif /* MAC */
  13162.     disp = z;
  13163.     if ((x = cmcfm()) < 0)              /* Get confirmation */
  13164.       return(x);
  13165.  
  13166.     switch (xx) {                       /* Do action.. */
  13167. #ifndef NOSETKEY
  13168.       case XSKEY:                       /* SAVE KEYMAP */
  13169.         return (savkeys(s,disp));
  13170. #endif /* NOSETKEY */
  13171.  
  13172.       case XSCMD:                       /* SAVE COMMAND.. */
  13173. #ifdef OS2
  13174. #ifndef NOLOCAL
  13175.         if (y == SV_SCRL)               /* .. SCROLLBACK */
  13176.           return(success = savscrbk(VCMD,s,disp));
  13177. #endif /* NOLOCAL */
  13178. #endif /* OS2 */
  13179. #ifndef NORECALL
  13180.         if (y == SV_HIST)               /* .. HISTORY */
  13181.           return(success = savhistory(s,disp));
  13182.         break;
  13183. #endif /* NORECALL */
  13184.  
  13185. #ifdef OS2
  13186. #ifndef NOLOCAL
  13187.       case XSTERM:                      /* SAVE TERMINAL SCROLLBACK */
  13188.         return(success = savscrbk(VTERM,s,disp));
  13189. #endif /* NOLOCAL */
  13190. #endif /* OS2 */
  13191.     }
  13192.     success = 0;
  13193.     return(-2);
  13194. }
  13195.  
  13196. /*
  13197.   R E A D T E X T
  13198.  
  13199.   Read text with a custom prompt into given buffer using command parser but
  13200.   with no echoing or entry into recall buffer.
  13201. */
  13202. int
  13203. readtext(prmpt, buffer, bufsiz) char * prmpt; char * buffer; int bufsiz; {
  13204. #ifdef CK_RECALL
  13205.     extern int on_recall;               /* Around Password prompting */
  13206. #endif /* CK_RECALL */
  13207.     int rc;
  13208. #ifndef NOLOCAL
  13209. #ifdef OS2
  13210.     extern int vmode;
  13211.     extern int startflags;
  13212.     int vmode_sav = vmode;
  13213.  
  13214.     if (!prmpt) prmpt = "";
  13215.  
  13216.     if (win95_popup && !(startflags & 96)
  13217. #ifdef IKSD
  13218.          && !inserver
  13219. #endif /* IKSD */
  13220.          )
  13221.       return(popup_readtext(vmode,NULL,prmpt,buffer,bufsiz,0));
  13222.  
  13223.     if (vmode == VTERM) {
  13224.         vmode = VCMD;
  13225.         VscrnIsDirty(VTERM);
  13226.         VscrnIsDirty(VCMD);
  13227.     }
  13228. #endif /* OS2 */
  13229. #endif /* NOLOCAL */
  13230.  
  13231. #ifdef CK_RECALL
  13232.     on_recall = 0;
  13233. #endif /* CK_RECALL */
  13234.     cmsavp(psave,PROMPTL);              /* Save old prompt */
  13235.     cmsetp(prmpt);                      /* Make new prompt */
  13236.     concb((char)escape);                /* Put console in cbreak mode */
  13237.     cmini(1);                           /* and echo mode */
  13238.     if (pflag) prompt(xxstring);        /* Issue prompt if at top level */
  13239.     cmres();                            /* Reset the parser */
  13240.     for (rc = -1; rc < 0; ) {           /* Prompt till they answer */
  13241.         rc = cmtxt("","",&s,NULL);      /* Get a literal line of text */
  13242.         cmres();                        /* Reset the parser again */
  13243.     }
  13244.     ckstrncpy(buffer,s,bufsiz);
  13245.     cmsetp(psave);                      /* Restore original prompt */
  13246.  
  13247. #ifndef NOLOCAL
  13248. #ifdef OS2
  13249.     if (vmode != vmode_sav) {
  13250.         vmode = VTERM;
  13251.         VscrnIsDirty(VCMD);
  13252.         VscrnIsDirty(VTERM);
  13253.     }
  13254. #endif /* OS2 */
  13255. #endif /* NOLOCAL */
  13256.     return(0);
  13257. }
  13258. #endif /* NOICP */
  13259.  
  13260. /* A general function to allow a Password or other information  */
  13261. /* to be read from the command prompt without it going into     */
  13262. /* the recall buffer or being echo'd.                           */
  13263.  
  13264. int
  13265. readpass(prmpt, buffer, bufsiz) char * prmpt; char * buffer; int bufsiz; {
  13266.     int x;
  13267. #ifdef NOICP
  13268.     if (!prmpt) prmpt = "";
  13269.     printf("%s", prmpt);
  13270. #ifdef COMMENT
  13271.     /* Some linkers won't allow this because it's unsafe */
  13272.     gets(buffer);
  13273. #else  /* COMMENT */
  13274.     {
  13275.         int c, i; char * p;
  13276.         p = buffer;
  13277.         for (i = 0; i < bufsiz-1; i++) {
  13278.             if ((c = getchar()) == EOF)
  13279.               break;
  13280.             if (c < SP)
  13281.               break;
  13282.             buffer[i] = c;
  13283.         }
  13284.         buffer[i] = NUL;
  13285.     }
  13286. #endif /* COMMENT */
  13287.     return(1);
  13288. #else  /* NOICP */
  13289. #ifdef CK_RECALL
  13290.     extern int on_recall;               /* around Password prompting */
  13291. #endif /* CK_RECALL */
  13292.     int rc;
  13293. #ifndef NOLOCAL
  13294. #ifdef OS2
  13295.     extern int vmode;
  13296.     extern int startflags;
  13297.     int vmode_sav = vmode;
  13298. #endif /* OS2 */
  13299. #endif /* NOLOCAL */
  13300. #ifdef CKSYSLOG
  13301.     int savlog;
  13302. #endif /* CKSYSLOG */
  13303.     if (!prmpt) prmpt = "";
  13304. #ifndef NOLOCAL
  13305.     debok = 0;                          /* Don't log */
  13306. #ifdef OS2
  13307.     if (win95_popup && !(startflags & 96)
  13308. #ifdef IKSD
  13309.          && !inserver
  13310. #endif /* IKSD */
  13311.          ) {
  13312.         x = popup_readpass(vmode,NULL,prmpt,buffer,bufsiz,0);
  13313.         debok = 1;
  13314.         return(x);
  13315.     }
  13316. #endif /* OS2 */
  13317. #endif /* NOLOCAL */
  13318.  
  13319. #ifdef CKSYSLOG
  13320.     savlog = ckxsyslog;                 /* Save and turn off syslogging */
  13321.     ckxsyslog = 0;
  13322. #endif /* CKSYSLOG */
  13323. #ifndef NOLOCAL
  13324. #ifdef OS2
  13325.     if (vmode == VTERM) {
  13326.         vmode = VCMD;
  13327.         VscrnIsDirty(VTERM);
  13328.         VscrnIsDirty(VCMD);
  13329.     }
  13330. #endif /* OS2 */
  13331. #endif /* NOLOCAL */
  13332. #ifdef CK_RECALL
  13333.     on_recall = 0;
  13334. #endif /* CK_RECALL */
  13335.     cmsavp(psave,PROMPTL);              /* Save old prompt */
  13336.     cmsetp(prmpt);                      /* Make new prompt */
  13337.     concb((char)escape);                /* Put console in cbreak mode */
  13338.     cmini(0);                           /* and no-echo mode */
  13339.     if (pflag) prompt(xxstring);        /* Issue prompt if at top level */
  13340.     cmres();                            /* Reset the parser */
  13341.     for (rc = -1; rc < 0; ) {           /* Prompt till they answer */
  13342.         rc = cmtxt("","",&s,NULL);      /* Get a literal line of text */
  13343.         cmres();                        /* Reset the parser again */
  13344.     }
  13345.     ckstrncpy(buffer,s,bufsiz);
  13346.     printf("\r\n");                     /* Echo a CRLF */
  13347.     cmsetp(psave);                      /* Restore original prompt */
  13348.     cmini(1);                           /* Restore echo mode */
  13349. #ifndef NOLOCAL
  13350. #ifdef OS2
  13351.     if (vmode != vmode_sav) {
  13352.         vmode = VTERM;
  13353.         VscrnIsDirty(VCMD);
  13354.         VscrnIsDirty(VTERM);
  13355.     }
  13356. #endif /* OS2 */
  13357. #endif /* NOLOCAL */
  13358. #ifdef CKSYSLOG
  13359.     ckxsyslog = savlog;                 /* Restore syslogging */
  13360. #endif /* CKSYSLOG */
  13361.     debok = 1;
  13362.     return(0);
  13363. #endif /* NOICP */
  13364. }
  13365.  
  13366. #ifndef NOICP
  13367. struct keytab authtab[] = {             /* Available authentication types */
  13368. #ifdef CK_KERBEROS
  13369.     { "k4",        AUTH_KRB4, CM_INV },
  13370.     { "k5",        AUTH_KRB5, CM_INV },
  13371.     { "kerberos4", AUTH_KRB4, 0      },
  13372.     { "kerberos5", AUTH_KRB5, 0      },
  13373.     { "krb4",      AUTH_KRB4, CM_INV },
  13374.     { "krb5",      AUTH_KRB5, CM_INV },
  13375. #endif /* CK_KERBEROS */
  13376. #ifdef NT
  13377.     { "ntlm",      AUTH_NTLM, 0 },
  13378. #endif /* NT */
  13379. #ifdef CK_SRP
  13380.     { "srp",       AUTH_SRP,  0 },
  13381. #endif /* CK_SRP */
  13382. #ifdef CK_SSL
  13383.     { "ssl",       AUTH_SSL,  0 },
  13384. #endif /* CK_SSL */
  13385.     { "",          0,         0 }
  13386. };
  13387. int authtabn = sizeof(authtab)/sizeof(struct keytab)-1;
  13388.  
  13389. #ifdef CK_KERBEROS
  13390. struct keytab kerbtab[] = {             /* Kerberos authentication types */
  13391.     { "k4",        AUTH_KRB4, CM_INV },
  13392.     { "k5",        AUTH_KRB5, CM_INV },
  13393.     { "kerberos4", AUTH_KRB4, 0      },
  13394.     { "kerberos5", AUTH_KRB5, 0      },
  13395.     { "krb4",      AUTH_KRB4, CM_INV },
  13396.     { "krb5",      AUTH_KRB5, CM_INV }
  13397. };
  13398. int kerbtabn = sizeof(kerbtab)/sizeof(struct keytab);
  13399.  
  13400. static struct keytab krb_s_tbl[] = {    /* AUTHENTICATE command switches: */
  13401.     { "/cache",   KRB_S_CA, CM_ARG }
  13402. };
  13403. static int krb_s_n = sizeof(krb_s_tbl)/sizeof(struct keytab);
  13404.  
  13405. static struct keytab krb_v_tbl[] = {    /* KERBEROS version values: */
  13406.     { "4",    4, 0 },
  13407.     { "5",    5, 0 },                   /* (add others as needed...) */
  13408.     { "auto", 0, 0 }                    /* Note: 0 = auto */
  13409. };
  13410. static int krb_v_n = sizeof(krb_v_tbl)/sizeof(struct keytab);
  13411.  
  13412. static struct keytab krb_a_tbl[] = {    /* KERBEROS actions: */
  13413.     { "destroy",           KRB_A_DE, 0 },
  13414.     { "initialize",        KRB_A_IN, 0 },
  13415.     { "list-credentials",  KRB_A_LC, 0 }
  13416. };
  13417. static int krb_a_n = sizeof(krb_a_tbl)/sizeof(struct keytab);
  13418.  
  13419. static struct keytab krb4_i_tbl[] = {   /* KERBEROS 4 INITIALIZE switches: */
  13420.     { "/brief",            KRB_I_BR, 0 },      /* /BRIEF       */
  13421.     { "/instance",         KRB_I_IN, CM_ARG }, /* /INSTANCE:   */
  13422.     { "/lifetime",         KRB_I_LF, CM_ARG }, /* /LIFETIME:   */
  13423.     { "/not-preauth",      KRB_I_NPA, 0 },     /* /NOT-PREAUTH */
  13424.     { "/password",         KRB_I_PW, CM_ARG }, /* /PASSWORD:   */
  13425. #ifdef OS2
  13426.     { "/popup",            KRB_I_POP, 0 },     /* /POPUP       */
  13427. #endif /* OS2 */
  13428.     { "/preauth",          KRB_I_PA, 0 },      /* /PREAUTH     */
  13429.     { "/realm",            KRB_I_RL, CM_ARG }, /* /REALM:      */
  13430.     { "/verbose",          KRB_I_VB, 0 },      /* /VERBOSE     */
  13431.     { "", 0, 0 }
  13432. };
  13433. static int krb4_i_n = sizeof(krb4_i_tbl)/sizeof(struct keytab) - 1;
  13434.  
  13435. static struct keytab krb5_i_tbl[] = {   /* KERBEROS 5 INITIALIZE switches: */
  13436.     { "/addresses",        KRB_I_ADR, CM_ARG },
  13437.     { "/forwardable",      KRB_I_FW,  0 },         /* /FORWARDABLE */
  13438.     { "/instance",         KRB_I_IN, CM_ARG }, /* /INSTANCE:   */
  13439.     { "/k4",               KRB_I_K4,  CM_INV }, /* /KERBEROS4   */
  13440.     { "/kerberos4",        KRB_I_K4,  0 },      /* /KERBEROS4   */
  13441.     { "/krb4",             KRB_I_K4,  CM_INV }, /* /KERBEROS4   */
  13442.     { "/lifetime",         KRB_I_LF,  CM_ARG }, /* /LIFETIME:   */
  13443.     { "/no-addresses",     KRB_I_NAD, 0 },      /* /NO-ADDRESSES */
  13444.     { "/no-k4",            KRB_I_NK4, CM_INV },/* /NO-KERBEROS4 */
  13445.     { "/no-kerberos4",     KRB_I_NK4, 0 },     /* /NO-KERBEROS4 */
  13446.     { "/no-krb4",          KRB_I_NK4, CM_INV },/* /NO-KERBEROS4 */
  13447.     { "/not-forwardable",  KRB_I_NFW, 0 },         /* /NOT-FORWARDABLE */
  13448.     { "/not-proxiable",    KRB_I_NPR, 0 },     /* /NOT-PROXIABLE   */
  13449.     { "/password",         KRB_I_PW,  CM_ARG }, /* /PASSWORD:   */
  13450. #ifdef OS2
  13451.     { "/popup",            KRB_I_POP, 0 },     /* /POPUP       */
  13452. #endif /* OS2 */
  13453.     { "/postdate",         KRB_I_PD, CM_ARG }, /* /POSTDATE:   */
  13454.     { "/pr",               KRB_I_PR, CM_INV|CM_ABR }, /* to allow for */
  13455.     { "/pro",              KRB_I_PR, CM_INV|CM_ABR }, /* different spellings */
  13456.     { "/prox",             KRB_I_PR, CM_INV|CM_ABR },
  13457.     { "/proxiable",        KRB_I_PR, 0 },      /* /PROXIABLE   */
  13458.     { "/proxyable",        KRB_I_PR, CM_INV }, /* /PROXYABLE   */
  13459.     { "/realm",            KRB_I_RL, CM_ARG }, /* /REALM:      */
  13460.     { "/renew",            KRB_I_RN, 0 },          /* /RENEW       */
  13461.     { "/renewable",        KRB_I_RB, CM_ARG }, /* /RENEWABLE:  */
  13462.     { "/service",          KRB_I_SR, CM_ARG }, /* /SERVICE:    */
  13463.     { "/validate",         KRB_I_VA, 0 },          /* /VALIDATE    */
  13464.     { "", 0, 0 }
  13465. };
  13466. static int krb5_i_n = sizeof(krb5_i_tbl)/sizeof(struct keytab) - 1;
  13467.  
  13468. static struct keytab klctab[] = {       /* List Credentials switches*/
  13469.     { "/addresses",  XYKLCAD, 0 },
  13470.     { "/encryption", XYKLCEN, 0 },
  13471.     { "/flags",      XYKLCFL, 0 }
  13472. };
  13473. static int nklctab = sizeof(klctab)/sizeof(struct keytab);
  13474.  
  13475. extern int krb_action;
  13476. extern struct krb_op_data krb_op;
  13477.  
  13478. extern struct krb5_list_cred_data krb5_lc;
  13479. extern struct krb5_init_data krb5_init;
  13480. extern char * krb5_d_principal;         /* Default principal */
  13481. extern char * krb5_d_instance;
  13482. extern char * krb5_d_realm;             /* Default realm */
  13483. extern char * krb5_d_cc;                /* Default credentials cache */
  13484. extern char * krb5_d_srv;               /* Default service name */
  13485. extern int    krb5_d_lifetime;          /* Default lifetime */
  13486. extern int    krb5_d_forwardable;
  13487. extern int    krb5_d_proxiable;
  13488. extern int    krb5_d_renewable;
  13489. extern int    krb5_autoget;
  13490. extern int    krb5_autodel;
  13491. extern int    krb5_d_getk4;
  13492. extern int    krb5_d_no_addresses;
  13493. extern int    krb5_checkaddrs;
  13494. extern char * krb5_d_addrs[];
  13495. extern char * k5_keytab;                /* Keytab file */
  13496.  
  13497. extern struct krb4_init_data krb4_init;
  13498. extern char * krb4_d_principal;         /* Default principal */
  13499. extern char * krb4_d_realm;             /* Default realm */
  13500. extern char * krb4_d_srv;               /* Default service name */
  13501. extern int    krb4_d_lifetime;          /* Default lifetime */
  13502. extern int    krb4_d_preauth;
  13503. extern char * krb4_d_instance;
  13504. extern int    krb4_autoget;
  13505. extern int    krb4_autodel;
  13506. extern int    krb4_checkaddrs;
  13507. extern char * k4_keytab;                /* Keytab file */
  13508. #endif /* CK_KERBEROS */
  13509.  
  13510. #ifndef NOSHOW
  13511. int
  13512. sho_iks() {
  13513. #ifdef IKSDCONF
  13514. #ifdef CK_LOGIN
  13515.     extern int ckxsyslog, ckxwtmp, ckxanon;
  13516. #ifdef UNIX
  13517.     extern int ckxpriv;
  13518. #endif /* UNIX */
  13519. #ifdef CK_PERMS
  13520.     extern int ckxperms;
  13521. #endif /* CK_PERMS */
  13522.     extern char * anonfile, * userfile, * anonroot;
  13523. #ifdef OS2
  13524.     extern char * anonacct;
  13525. #endif /* OS2 */
  13526. #ifdef NT
  13527.     extern char * iks_domain;
  13528. #endif /* NT */
  13529. #endif /* CK_LOGIN */
  13530. #ifdef CKWTMP
  13531.     extern char * wtmpfile;
  13532. #endif /* CKWTMP */
  13533. #ifdef IKSDB
  13534.     extern char * dbfile;
  13535.     extern int dbenabled;
  13536. #endif /* IKSDB */
  13537. #ifdef CK_LOGIN
  13538.     extern int logintimo;
  13539. #endif /* CK_LOGIN */
  13540.     extern int srvcdmsg, success, iksdcf, noinit, arg_x;
  13541.     extern char * cdmsgfile[], * cdmsgstr, *kermrc;
  13542.     char * bannerfile = NULL;
  13543.     char * helpfile = NULL;
  13544.     extern int xferlog;
  13545.     extern char * xferfile;
  13546.     int i;
  13547.  
  13548.     if (isguest) {
  13549.         printf("?Command disabled\r\n");
  13550.         return(success = 0);
  13551.     }
  13552.  
  13553.     printf("IKS Settings\r\n");
  13554. #ifdef CK_LOGIN
  13555. #ifdef OS2
  13556.     printf("  Anonymous Account:   %s\r\n",anonacct?anonacct:"<none>");
  13557. #endif /* OS2 */
  13558.     printf("  Anonymous Initfile:  %s\r\n",anonfile?anonfile:"<none>");
  13559.     printf("  Anonymous Login:     %d\r\n",ckxanon);
  13560.     printf("  Anonymous Root:      %s\r\n",anonroot?anonroot:"<none>");
  13561. #endif /* CK_LOGIN */
  13562.     printf("  Bannerfile:          %s\r\n",bannerfile?bannerfile:"<none>");
  13563.     printf("  CDfile:              %s\r\n",cdmsgfile[0]?cdmsgfile[0]:"<none>");
  13564.     for ( i=1;i<16 && cdmsgfile[i];i++ )
  13565.         printf("  CDfile:              %s\r\n",cdmsgfile[i]);
  13566.     printf("  CDMessage:           %d\r\n",srvcdmsg);
  13567. #ifdef IKSDB
  13568.     printf("  DBfile:              %s\r\n",dbfile?dbfile:"<none>");
  13569.     printf("  DBenabled:           %d\r\n",dbenabled);
  13570. #endif /* IKSDB */
  13571. #ifdef CK_LOGIN
  13572. #ifdef NT
  13573.     printf("  Default-domain:      %s\r\n",iks_domain?iks_domain:".");
  13574. #endif /* NT */
  13575. #endif /* CK_LOGIN */
  13576.     printf("  Helpfile:            %s\r\n",helpfile?helpfile:"<none>");
  13577.     printf("  Initfile:            %s\r\n",kermrc?kermrc:"<none>");
  13578.     printf("  No-Initfile:         %d\r\n",noinit);
  13579. #ifdef CK_LOGIN
  13580. #ifdef CK_PERM
  13581.     printf("  Permission code:     %0d\r\n",ckxperms);
  13582. #endif /* CK_PERM */
  13583. #ifdef UNIX
  13584.     printf("  Privileged Login:    %d\r\n",ckxpriv);
  13585. #endif /* UNIX */
  13586. #endif /* CK_LOGIN */
  13587.     printf("  Server-only:         %d\r\n",arg_x);
  13588.     printf("  Syslog:              %d\r\n",ckxsyslog);
  13589.     printf("  Timeout (seconds):   %d\r\n",logintimo);
  13590.     printf("  Userfile:            %s\r\n",userfile?userfile:"<none>");
  13591. #ifdef CK_LOGIN
  13592. #ifdef CKWTMP
  13593.     printf("  Wtmplog:             %d\r\n",ckxwtmp);
  13594.     printf("  Wtmpfile:            %s\r\n",wtmpfile?wtmpfile:"<none>");
  13595. #endif /* CKWTMP */
  13596. #endif /* CK_LOGIN */
  13597.     printf("  Xferfile:            %s\r\n",xferfile?xferfile:"<none>");
  13598.     printf("  Xferlog:             %d\r\n",xferlog);
  13599. #else /* IKSDCONF */
  13600.     printf("?Nothing to show.\r\n");
  13601. #endif /* IKSDCONF */
  13602.     return(success = 1);
  13603. }
  13604.  
  13605. #ifdef CK_AUTHENTICATION
  13606. int
  13607. sho_auth(cx) int cx; {
  13608.     extern int auth_type_user[], cmd_rows;
  13609.     int i;
  13610.     char * p;
  13611.     int kv = 0, all = 0, n = 0;
  13612.  
  13613. #ifdef IKSD
  13614.     if (inserver && isguest) {
  13615.         printf("?Sorry, command disabled.\r\n");
  13616.         return(success = 0);
  13617.     }
  13618. #endif /* IKSD */
  13619.     if (cx) {
  13620.         kv = cx;
  13621.     } else if (auth_type_user[0] != AUTHTYPE_AUTO) {
  13622.         kv = auth_type_user[0];
  13623.     } else {
  13624.         all = 1;
  13625.         kv = AUTHTYPE_KERBEROS_V4;
  13626.     }
  13627.     while (kv) {
  13628.         switch (kv) {
  13629.           case AUTHTYPE_KERBEROS_V4:
  13630.             kv = all ? AUTHTYPE_KERBEROS_V5 : 0;
  13631.             if (ck_krb4_is_installed()) {
  13632.                 printf(" Authentication:      Kerberos 4\n");
  13633.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13634.             } else {
  13635.                 printf(" Authentication:      Kerberos 4 (not installed)\n");
  13636.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13637.                 continue;
  13638.             }
  13639. #ifdef CK_KERBEROS
  13640.             printf(" Keytab file:         %s\n",
  13641.                       k4_keytab ? k4_keytab : "(none)");
  13642.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13643.             if (krb_action < 0) {
  13644.                 p = "(none)";
  13645.             } else {
  13646.                 for (p = "", i = 0; i < krb_a_n; i++) {
  13647.                     if (krb_action == krb_a_tbl[i].kwval) {
  13648.                         p = krb_a_tbl[i].kwd;
  13649.                         break;
  13650.                     }
  13651.                 }
  13652.             }
  13653.             printf(" Action:              %s\n", p);
  13654.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13655.             printf(" Default lifetime     %d\n",krb4_d_lifetime);
  13656.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13657.             printf(" Lifetime:            %d (minutes)\n",krb4_init.lifetime);
  13658.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13659.             printf(" Default preauth:     %d\n",krb4_d_preauth);
  13660.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13661.             printf(" Preauth:             %d\n",krb4_init.preauth);
  13662.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13663.             printf(" Default principal:   \"%s\"\n",
  13664.                     krb4_d_principal ? krb4_d_principal : "");
  13665.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13666.             printf(" Principal:           \"%s\"\n",
  13667.                     krb4_init.principal ? krb4_init.principal : "");
  13668.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13669.             printf(" Default realm:       \"%s\"\n",
  13670.                     krb4_d_realm ? krb4_d_realm : "");
  13671.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13672.             printf(" Realm:               \"%s\"\n",
  13673.                     krb4_init.realm ? krb4_init.realm : "");
  13674.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13675.             printf(" Default instance:    \"%s\"\n",
  13676.                     krb4_d_instance ? krb4_d_instance : "");
  13677.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13678.             printf(" Instance:            \"%s\"\n",
  13679.                     krb4_init.instance ? krb4_init.instance : "");
  13680.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13681.             printf(" Auto-Get TGTs:       %d\n",krb4_autoget);
  13682.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13683.             printf(" Auto-Destroy TGTs:   %s\n",
  13684.                     krb4_autodel==KRB_DEL_NO?"never":
  13685.                     krb4_autodel==KRB_DEL_CL?"on-close":"on-exit");
  13686.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13687.             printf(" Check IP Addresses:  %d\n",krb4_checkaddrs);
  13688.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13689. #ifdef COMMENT
  13690.             printf(" Password:    \"%s\"\n",
  13691.                     krb4_init.password  ? krb4_init.password  : "");
  13692.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13693. #endif /* COMMENT */
  13694. #endif /* CK_KERBEROS */
  13695.             printf("\n");
  13696.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13697.             break;
  13698.         case AUTHTYPE_KERBEROS_V5:
  13699.             kv = all ? AUTHTYPE_SSL : 0;
  13700.             if (ck_krb5_is_installed()) {
  13701.                 if (ck_gssapi_is_installed())
  13702.                     printf(" Authentication:      Kerberos 5 plus GSSAPI\n");
  13703.                 else
  13704.                     printf(" Authentication:      Kerberos 5\n");
  13705.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13706.             } else {
  13707.                 printf(" Authentication:      Kerberos 5 (not installed)\n");
  13708.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13709.                 continue;
  13710.             }
  13711.  
  13712. #ifdef CK_KERBEROS
  13713.             printf(" Cache file:          %s\n",
  13714.                     krb_op.cache ? krb_op.cache : "(none)");
  13715.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13716.             printf(" Default cache:       %s\n",
  13717.                     krb5_d_cc ? krb5_d_cc : "(none)");
  13718.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13719.             printf(" Keytab file:         %s\n",
  13720.                       k5_keytab ? k5_keytab : "(none)");
  13721.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13722.             if (krb_action < 0) {
  13723.                 p = "(none)";
  13724.             } else  {
  13725.                 for (p = "", i = 0; i < krb_a_n; i++) {
  13726.                     if (krb_action == krb_a_tbl[i].kwval) {
  13727.                         p = krb_a_tbl[i].kwd;
  13728.                         break;
  13729.                     }
  13730.                 }
  13731.             }
  13732.             printf(" Action:              %s\n", p);
  13733.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13734.  
  13735.             printf(" Default forwardable  %d\n",krb5_d_forwardable);
  13736.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13737.             printf(" Forwardable:         %d\n",krb5_init.forwardable);
  13738.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13739.             printf(" Default lifetime     %d\n",krb5_d_lifetime);
  13740.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13741.             printf(" Lifetime:            %d (minutes)\n",krb5_init.lifetime);
  13742.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13743.             printf(" Postdate:            \"%s\"\n",
  13744.                     krb5_init.postdate ? krb5_init.postdate: "");
  13745.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13746.             printf(" Default proxiable:   %d\n",krb5_d_proxiable);
  13747.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13748.             printf(" Proxiable:           %d\n",krb5_init.proxiable);
  13749.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13750.             printf(" Renew:               %d\n",krb5_init.renew);
  13751.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13752.             printf(" Default renewable:   %d (minutes)\n",krb5_d_renewable);
  13753.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13754.             printf(" Renewable:           %d (minutes)\n",krb5_init.renewable);
  13755.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13756.             printf(" Service:             \"%s\"\n",
  13757.                     krb5_init.service ? krb5_init.service : "");
  13758.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13759.             printf(" Validate:            %d\n",krb5_init.validate);
  13760.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13761.             printf(" Default principal:   \"%s\"\n",
  13762.                     krb5_d_principal ? krb5_d_principal : "");
  13763.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13764.             printf(" Principal:           \"%s\"\n",
  13765.                     krb5_init.principal ? krb5_init.principal : "");
  13766.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13767.             printf(" Default instance:    \"%s\"\n",
  13768.                     krb5_d_instance ? krb5_d_instance : "");
  13769.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13770.             printf(" Default realm:       \"%s\"\n",
  13771.                     krb5_d_realm ? krb5_d_realm : "");
  13772.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13773.             printf(" Realm:               \"%s\"\n",
  13774.                     krb5_init.realm ? krb5_init.realm : "");
  13775.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13776.             printf(" Auto-Get TGTs:       %d\n",krb5_autoget);
  13777.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13778.             printf(" Auto-Destroy TGTs:   %s\n",
  13779.                     krb5_autodel==KRB_DEL_NO?"never":
  13780.                     krb5_autodel==KRB_DEL_CL?"on-close":"on-exit");
  13781.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13782.             printf(" Default get K4 TGTs: %d\n",krb5_d_getk4);
  13783.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13784.             printf(" Get K4 TGTs: %d\n",krb5_init.getk4);
  13785.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13786.             printf(" Check IP Addresses:  %d\n",krb5_checkaddrs);
  13787.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13788.             printf(" No IP Addresses:  %d\n",krb5_d_no_addresses);
  13789.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13790.             printf(" IP-Addresses:        ");
  13791.             if (krb5_init.addrs && krb5_init.addrs[0]) {
  13792.                 for (i = 0; krb5_init.addrs[i]; i++) {
  13793.                     if (i)
  13794.                       printf(",");
  13795.                     printf("%s",krb5_init.addrs[i]);
  13796.                 }
  13797.             } else if (krb5_d_addrs[0]) {
  13798.                 for (i = 0;i < KRB5_NUM_OF_ADDRS && krb5_d_addrs[i];i++) {
  13799.                     if (i)
  13800.                       printf(",");
  13801.                     printf("%s",krb5_d_addrs[i]);
  13802.                 }
  13803.             } else {
  13804.                 printf("(use default)");
  13805.             }
  13806.             printf("\n");
  13807.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13808. #ifdef COMMENT
  13809.             printf(" Password:            \"%s\"\n",
  13810.                     krb5_init.password  ? krb5_init.password  : "");
  13811.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13812. #endif /* COMMENT */
  13813. #endif /* CK_KERBEROS */
  13814.             printf("\n");
  13815.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13816.             break;
  13817.           case AUTHTYPE_SSL:
  13818.             kv = all ? AUTHTYPE_SRP : 0;
  13819.             if (ck_ssleay_is_installed()) {
  13820.                 printf(" Authentication:      SSL/TLS\n");
  13821.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13822.             } else {
  13823.                 printf(" Authentication:      SSL/TLS (not installed)\n");
  13824.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13825.                 continue;
  13826.             }
  13827.  
  13828. #ifdef CK_SSL
  13829.             printf(" RSA Certs file: %s\n",ssl_rsa_cert_file?
  13830.                   ssl_rsa_cert_file:"(none)");
  13831.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13832.             printf(" RSA Certs Chain file: %s\n",ssl_rsa_cert_chain_file?
  13833.                   ssl_rsa_cert_chain_file:"(none)");
  13834.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13835.             printf(" RSA Key file: %s\n",ssl_rsa_key_file?
  13836.                   ssl_rsa_key_file:"(none)");
  13837.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13838.             printf(" DSA Certs file: %s\n",ssl_dsa_cert_file?
  13839.                   ssl_dsa_cert_file:"(none)");
  13840.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13841.             printf(" DSA Certs Chain file: %s\n",ssl_dsa_cert_chain_file?
  13842.                   ssl_dsa_cert_chain_file:"(none)");
  13843.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13844.             printf(" DH Key file: %s\n",ssl_dh_key_file?
  13845.                   ssl_dh_key_file:"(none)");
  13846.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13847.             printf(" DH Param file: %s\n",ssl_dh_param_file?
  13848.                   ssl_dh_param_file:"(none)");
  13849.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13850.             printf(" CRL file: %s\n",ssl_crl_file?
  13851.                   ssl_crl_file:"(none)");
  13852.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13853.             printf(" CRL dir: %s\n",ssl_crl_dir?
  13854.                     ssl_crl_dir:"(none)");
  13855.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13856.             printf(" Random file: %s\n",ssl_rnd_file?
  13857.                   ssl_rnd_file:"(none)");
  13858.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13859.             printf(" Verify file: %s\n",ssl_verify_file?
  13860.                   ssl_verify_file:"(none)");
  13861.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13862.             printf(" Verify dir: %s\n",ssl_verify_dir?
  13863.                   ssl_verify_dir:"(none)");
  13864.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13865.             printf(" Cipher list: %s\n",ssl_cipher_list ? ssl_cipher_list : 
  13866.             DEFAULT_CIPHER_LIST);
  13867.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13868.             if (ssl_con == NULL) {
  13869.                 SSL_library_init();
  13870.                 ssl_ctx = (SSL_CTX *)
  13871.                   SSL_CTX_new((SSL_METHOD *)TLSv1_method());
  13872.                 if (ssl_ctx != NULL)
  13873.                   ssl_con= (SSL *) SSL_new(ssl_ctx);
  13874.             }
  13875.             if (ssl_con != NULL) {
  13876.                 CHAR * p = NULL;
  13877.                 int i;
  13878.  
  13879.                 for (i = 0; ; i++) {
  13880.                     p = (CHAR *) SSL_get_cipher_list(ssl_con,i);
  13881.                     if (p == NULL)
  13882.                       break;
  13883.                     printf("    %s\n",p);
  13884.                     if (++n > cmd_rows - 3)
  13885.                         if (!askmore()) return(0); else n = 0;
  13886.                 }
  13887.             }
  13888.             printf(" Certs OK? %s\n",ssl_certsok_flag? "yes" : "no");
  13889.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13890.             printf(" Debug mode: %s\n", ssl_debug_flag ? "on" : "off");
  13891.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13892.             printf(" Verbose mode: %s\n", ssl_verbose_flag ? "on" : "off");
  13893.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13894.             printf(" Verify mode: %s\n",
  13895.                     ssl_verify_flag == SSL_VERIFY_NONE ? "none" :
  13896.                     ssl_verify_flag == SSL_VERIFY_PEER ? "peer-cert" :
  13897.                     "fail-if-no-peer-cert");
  13898.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13899.             printf(" SSL only? %s\n", ssl_only_flag ? "yes" : "no");
  13900.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13901.             printf(" TLS only? %s\n", tls_only_flag ? "yes" : "no");
  13902.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13903. #endif /* CK_SSL */
  13904.             break;
  13905.           case AUTHTYPE_NTLM:
  13906.             kv = 0;
  13907.             if (ck_ntlm_is_installed()) {
  13908.                 printf(" Authentication:      NTLM\n");
  13909.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13910.                 printf(" No options\n");
  13911.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13912.             } else {
  13913.                 printf(" Authentication:      NTLM (not installed)\n");
  13914.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13915.                 continue;
  13916.             }
  13917.             printf("\n");
  13918.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13919.             break;
  13920.           case AUTHTYPE_SRP:
  13921.             kv = all ? AUTHTYPE_NTLM : 0;
  13922.             if (ck_srp_is_installed()) {
  13923.                 if (ck_krypto_is_installed())
  13924.                     printf(" Authentication:      SRP plus Krypto API\n");
  13925.                 else
  13926.                     printf(" Authentication:      SRP\n");
  13927.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13928.                 printf(" No options\n");
  13929.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13930.             } else {
  13931.                 printf(" Authentication:      SRP (not installed)\n");
  13932.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13933.                 continue;
  13934.             }
  13935.             printf("\n");
  13936.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13937.             break;
  13938.         }
  13939.     }
  13940.     return(success = 1);
  13941. }
  13942. #endif /* CK_AUTHENTICATION */
  13943. #endif /* NOSHOW */
  13944.  
  13945. #ifdef CK_KERBEROS
  13946.  
  13947. /*  C P _ A U T H  --  AUTHENTICATE command parsing  */
  13948.  
  13949. int
  13950. cp_auth() {                             /* Command_Parse AUTHENTICATE */
  13951.     int c, i, n;                        /* Workers */
  13952.     int rc = 0;                         /* Return code */
  13953.     int getval;                         /* Parsing helpers */
  13954.     int tmpauth = 0;                    /* Temporary authentication type */
  13955.     int kv = 0;                         /* Temporary Kerberos version */
  13956.     int tmp_action = -1;                /* Temporary Kerberos action */
  13957.     int tmp_klc = 0;                    /* Temporary list-credentials */
  13958.     char tmphlp[256];                   /* For building help message */
  13959.     char * p;
  13960.     char * tmppswd  = NULL;             /* Password */
  13961.     char * tmpprinz = NULL;             /* Principal */
  13962.     char * tmprealm = NULL;             /* Realm */
  13963.     char * tmpcache = NULL;             /* Cache file */
  13964.     char * tmpinst  = NULL;             /* K4 Instance */
  13965.     char * tmpaddrs[KRB5_NUM_OF_ADDRS];
  13966. #ifdef CK_RECALL
  13967.     extern int on_recall;               /* around Password prompting */
  13968. #endif /* CK_RECALL */
  13969.     struct stringint {                  /* Temporary array for switch values */
  13970.         char * sval;                    /* String value */
  13971.         int ival;                       /* Integer value */
  13972.     } pv[KRB_I_MAX+1];                  /* This many */
  13973.     struct FDB kw, sw, fl;              /* FDBs for each parse function */
  13974.  
  13975.     krb_action = -1;                    /* Initialize Kerberos action. */
  13976.     tmp_action = -1;                    /* And our local copy. */
  13977.     for (i = 0; i < KRB5_NUM_OF_ADDRS; i++)
  13978.       tmpaddrs[i] = NULL;
  13979.  
  13980.     if ((y = cmkey(kerbtab,kerbtabn,"authentication type","",xxstring)) < 0)
  13981.       {
  13982.           if (y == -3)
  13983.             printf("?Authentication type not specified - nothing happens\n");
  13984.           return(y);
  13985.       }
  13986.     tmpauth = y;
  13987.     debug(F101,"kerberos authentication","",tmpauth);
  13988.     switch (tmpauth) {
  13989.       case AUTH_KRB4: kv = 4; break;    /* Don't assume values are the same */
  13990.       case AUTH_KRB5: kv = 5; break;
  13991.       default:
  13992.         printf("?Authentication type not supported: \"%s\"\n",atmbuf);
  13993.         return(-9);
  13994.     }
  13995.  
  13996.     /* From here down is Kerberos */
  13997.     ini_kerb();                         /* Reset Init data to defaults */
  13998.  
  13999.     if (kv == 4) {                      /* Set K4 defaults */
  14000.         if (krb4_d_realm)
  14001.           makestr(&tmprealm,krb4_d_realm);
  14002.         if (krb4_d_principal)
  14003.           makestr(&tmpprinz,krb4_d_principal);
  14004.         if (krb4_d_instance)
  14005.           makestr(&tmpinst,krb4_d_instance);
  14006.     } else if (kv == 5) {               /* Set K5 defaults */
  14007.         if (krb5_d_cc)
  14008.           makestr(&tmpcache,krb5_d_cc);
  14009.         if (krb5_d_realm)
  14010.           makestr(&tmprealm,krb5_d_realm);
  14011.         if (krb5_d_principal)
  14012.           makestr(&tmpprinz,krb5_d_principal);
  14013.         if (krb5_d_instance)
  14014.           makestr(&tmpinst,krb5_d_instance);
  14015.     }
  14016.  
  14017.     for (i = 0; i <= KRB_I_MAX; i++) {  /* Initialize switch values */
  14018.         pv[i].sval = NULL;              /* to null pointers */
  14019.         pv[i].ival = 0;                 /* and 0 int values */
  14020.     }
  14021.  
  14022.     if (kv == 4) {                      /* Kerberos 4 */
  14023.         pv[KRB_I_LF].ival = krb4_d_lifetime;
  14024.         pv[KRB_I_PA].ival = krb4_d_preauth;
  14025.  
  14026.         if ((n = cmkey(krb_a_tbl,krb_a_n,"Kerberos 4 action","",xxstring)) < 0)
  14027.           {
  14028.               if (n == -3)
  14029.                 printf("?Action not specified - nothing happens.\n");
  14030.               return(n);
  14031.           }
  14032.     } else if (kv == 5) {               /* Kerberos 5 */
  14033.         pv[KRB_I_FW].ival = krb5_d_forwardable;
  14034.         pv[KRB_I_PR].ival = krb5_d_proxiable;
  14035.         pv[KRB_I_LF].ival = krb5_d_lifetime;
  14036.         pv[KRB_I_RB].ival = krb5_d_renewable;
  14037.         pv[KRB_I_K4].ival = krb5_d_getk4;
  14038.         pv[KRB_I_NAD].ival = krb5_d_no_addresses;
  14039.  
  14040.         /* Make help message that shows switches and action keywords */
  14041.         ckstrncpy(tmphlp,"Kerberos 5 action, one of the following:\n ",256);
  14042.         for (i = 0; i < krb_a_n; i++) {
  14043.             ckstrncat(tmphlp,krb_a_tbl[i].kwd,sizeof(tmphlp));
  14044.             if (i == krb_a_n - 1)
  14045.               ckstrncat(tmphlp,"\nor switch",sizeof(tmphlp));
  14046.             else
  14047.               ckstrncat(tmphlp,"   ",sizeof(tmphlp));
  14048.         }
  14049.         /* Set up first set of chained FDB's */
  14050.  
  14051.         cmfdbi(&sw,                     /* First FDB - command switches */
  14052.                _CMKEY,                  /* fcode */
  14053.                tmphlp,                  /* hlpmsg */
  14054.                "",                      /* default (none) */
  14055.                "",                      /* addtl string data */
  14056.                krb_s_n,                 /* Switch table size */
  14057.                4,                       /* addtl numeric data 2: 4 = cmswi */
  14058.                xxstring,                /* Processing function */
  14059.                krb_s_tbl,               /* Switch table */
  14060.                &kw                      /* Pointer to next FDB */
  14061.                );
  14062.         cmfdbi(&kw,                     /* Second FDB - action keywords */
  14063.                _CMKEY,                  /* fcode */
  14064.                "Kerberos action",       /* hlpmsg */
  14065.                "",                      /* default (none) */
  14066.                "",                      /* addtl string data */
  14067.                krb_a_n,                 /* Switch table size */
  14068.                0,                       /* addtl num data (0 = NOT switch) */
  14069.                xxstring,                /* Processing function */
  14070.                krb_a_tbl,               /* Keyword table */
  14071.                NULL                     /* Pointer to next FDB (none) */
  14072.                );
  14073.  
  14074.         /* Parse */
  14075.  
  14076.         while (1) {                     /* Parse 0 or more switches */
  14077.             rc = cmfdb(&sw);            /* Parse something */
  14078.             debug(F101,"kerberos cmfdb 1 rc","",rc);
  14079.             if (rc < 0) {                       /* Error */
  14080.                 if (rc == -3)
  14081.                   printf("?Action not specified - nothing happens.\n");
  14082.                 return(rc);             /* or reparse needed */
  14083.             }
  14084.             if (cmresult.fdbaddr != &sw) /* Break out if not a switch */
  14085.               break;
  14086.             c = cmgbrk();               /* Have switch - get break character */
  14087.             getval = (c == ':' || c == '='); /* Must parse an agument? */
  14088.             if (getval && !(cmresult.kflags & CM_ARG)) {
  14089.                 printf("?This switch does not take arguments\n");
  14090.                 return(-9);             /* OK because nothing malloc'd yet */
  14091.             }
  14092.             if (!getval && (cmgkwflgs() & CM_ARG)) {
  14093.                 printf("?This switch requires an argument\n");
  14094.                 return(-9);
  14095.             }
  14096.             n = cmresult.nresult;       /* Numeric result = switch value */
  14097.             debug(F101,"kerberos command switch","",n);
  14098.  
  14099.             switch (n) {                /* Handle the switch */
  14100.               case KRB_S_CA:            /* /CACHE:<filename> */
  14101.                 p = krb5_d_cc ? krb5_d_cc : "";
  14102.                 if ((y = cmofi("Name of cache file",p,&s,xxstring)) < 0) {
  14103.                     if (y == -3)
  14104.                       s = NULL;
  14105.                     else
  14106.                       return(y);
  14107.                 }
  14108.                 makestr(&tmpcache,s);
  14109.                 break;
  14110.               default:
  14111.                 printf("?Unexpected switch value - internal error\n");
  14112.                 return(-9);             /* (if) nothing malloc'd yet. */
  14113.             }
  14114.         }
  14115.         if (cmresult.fdbaddr != &kw) {  /* Checking... */
  14116.             printf("?Unexpected result - internal error\n");
  14117.             return(-9);                 /* Nothing malloc'd yet. */
  14118.         }
  14119.         n = cmresult.nresult;           /* Get keyword value */
  14120.     } else {
  14121.         printf("?Unexpected Kerberos version - Internal error\n");
  14122.         return(-9);
  14123.     }
  14124.     debug(F101,"kerberos action","",n);
  14125.     switch (n) {
  14126.       case KRB_A_IN:                    /* INITIALIZE */
  14127.       case KRB_A_DE:                    /* DESTROY */
  14128.       case KRB_A_LC:                    /* LIST-CREDENTIALS */
  14129.         tmp_action = n;                 /* OK, set */
  14130.         break;
  14131.       default:                          /* Not OK, punt. */
  14132.         printf("?Unexpected action - internal error\n");
  14133.         return(-9);
  14134.     }
  14135.     if (tmp_action == KRB_A_IN) {       /* Action is INITIALIZE */
  14136.         int x;
  14137.         cmfdbi(&sw,                     /* INITIALIZE switches */
  14138.                _CMKEY,                  /* fcode */
  14139.                "Principal,\n or optional INITIALIZE switch(es)", /* hlpmsg */
  14140.                "",                      /* default (none) */
  14141.                "",                      /* addtl string data */
  14142.                kv == 4 ?  krb4_i_n : krb5_i_n, /* Switch table size */
  14143.                4,                       /* addtl numeric data 2: 4 = cmswi */
  14144.                xxstring,                /* Processing function */
  14145.                kv == 4 ?  krb4_i_tbl : krb5_i_tbl,      /* Switch table */
  14146.                &fl                      /* Pointer to next FDB */
  14147.                );
  14148.         cmfdbi(&fl,                     /* 3rd FDB - command to send from */
  14149.                _CMFLD,                  /* fcode */
  14150.                "Principal",             /* hlpmsg */
  14151.                kv == 4 ? krb4_d_principal : krb5_d_principal, /* principal */
  14152.                "",                      /* addtl string data */
  14153.                0,                       /* addtl numeric data 1 */
  14154.                0,                       /* addtl numeric data 2 */
  14155.                xxstring,
  14156.                NULL,
  14157.                NULL
  14158.                );
  14159.         while (1) {                     /* Parse INIT switches or principal */
  14160.             rc = cmfdb(&sw);
  14161.             debug(F101,"kerberos cmfdb 2 rc","",rc);
  14162.             if (rc < 0) {
  14163.                 if (rc == -3)
  14164.                   printf("?Principal name required\n");
  14165.                 goto kerbx;
  14166.             }
  14167.             debug(F101,"kerberos cmfdb 2 fcode","",cmresult.fcode);
  14168.             if (cmresult.fcode != _CMKEY) /* Not a switch, quit switch loop */
  14169.               break;
  14170.             c = cmgbrk();               /* Switch - get break character */
  14171.             debug(F101,"kerberos cmfdb 2 cmgbrk","",c);
  14172.             getval = (c == ':' || c == '=');
  14173.             if (getval && !(cmresult.kflags & CM_ARG)) {
  14174.                 printf("?This switch does not take arguments\n");
  14175.                 return(-9);             /* OK because nothing malloc'd yet */
  14176.             }
  14177.             if (!getval && (cmgkwflgs() & CM_ARG)) {
  14178.                 printf("?This switch requires an argument\n");
  14179.                 return(-9);
  14180.             }
  14181.             n = cmresult.nresult;       /* Numeric result = switch value */
  14182.             switch (n) {
  14183.               /* These don't take args... */
  14184.               case KRB_I_PA:            /* /PREAUTH */
  14185.               case KRB_I_FW:            /* /FORWARDABLE */
  14186.               case KRB_I_PR:            /* /PROXIABLE */
  14187.               case KRB_I_RN:            /* /RENEW */
  14188.               case KRB_I_VA:            /* /VALIDATE */
  14189.               case KRB_I_NPA:           /* /NOT-PREAUTH */
  14190.               case KRB_I_NFW:           /* /NOT-FORWARDABLE */
  14191.               case KRB_I_NPR:           /* /NOT-PROXIABLE */
  14192.               case KRB_I_VB:            /* /VERBOSE */
  14193.               case KRB_I_BR:            /* /BRIEF */
  14194.               case KRB_I_K4:            /* /KERBEROS4 */
  14195.               case KRB_I_NK4:           /* /NO-KERBEROS4 */
  14196.               case KRB_I_POP:           /* /POPUP */
  14197.               case KRB_I_NAD:           /* /NO-ADDRESSES */
  14198.                 if (getval) {
  14199.                     printf("?This switch does not take a value\n");
  14200.                     rc = -9;
  14201.                     goto kerbx;
  14202.                 }
  14203.                 switch (n) {
  14204.                   case KRB_I_NPA:
  14205.                     pv[KRB_I_PA].ival = 0;
  14206.                     break;
  14207.                   case KRB_I_NFW:
  14208.                     pv[KRB_I_FW].ival = 0;
  14209.                     break;
  14210.                   case KRB_I_NPR:
  14211.                     pv[KRB_I_PR].ival = 0;
  14212.                     break;
  14213.                   case KRB_I_VB:
  14214.                     pv[KRB_I_BR].ival = 0;
  14215.                     break;
  14216.                   case KRB_I_NK4:
  14217.                     pv[KRB_I_K4].ival = 0;
  14218.                     break;
  14219.                   default:
  14220.                     pv[n].ival = 1;
  14221.                 }
  14222.                 break;
  14223.  
  14224.                 /* These do take arguments */
  14225.  
  14226.               case KRB_I_RB:            /* /RENEWABLE:<minutes> */
  14227.                 pv[n].ival = 0;
  14228.                 if (!getval) break;
  14229.                 if ((rc = cmnum("Minutes",ckitoa(krb5_init.renewable),
  14230.                                 10,&y, xxstring)) < 0)
  14231.                   goto kerbx;
  14232.                 pv[n].ival = y;
  14233.                 break;
  14234.  
  14235.               case KRB_I_LF:            /* /LIFETIME:<minutes> */
  14236.                 pv[n].ival = 0;
  14237.                 /* Default is previous value */
  14238.                 sprintf(tmpbuf,"%d",    /* SAFE */
  14239.                         kv == 4 ?
  14240.                         krb4_init.lifetime :
  14241.                         krb5_init.lifetime
  14242.                         );
  14243.                 if (!getval) break;
  14244.                 if ((rc = cmnum("Minutes",tmpbuf,10,&y, xxstring)) < 0)
  14245.                   goto kerbx;
  14246.                 pv[n].ival = y;
  14247.                 break;
  14248.  
  14249.               case KRB_I_PD:            /* /POSTDATE:<timestamp> */
  14250.                 if (pv[n].sval) {
  14251.                     free(pv[n].sval);
  14252.                     pv[n].sval = NULL;
  14253.                 }
  14254.                 if (!getval) break;
  14255.                 if ((rc = cmdate("date-time","",&s,0,xxstring)) < 0)
  14256.                   goto kerbx;
  14257.                 makestr(&(pv[n].sval),s);
  14258.                 break;
  14259.  
  14260.               case KRB_I_SR:            /* /SERVICE:<name> */
  14261.                 if (pv[n].sval) {
  14262.                     free(pv[n].sval);
  14263.                     pv[n].sval = NULL;
  14264.                 }
  14265.                 if (!getval) break;
  14266.                 if ((rc = cmfld("Service-name","",&s,xxstring)) < 0)
  14267.                   goto kerbx;
  14268.                 makestr(&(pv[n].sval),s);
  14269.                 break;
  14270.  
  14271.               case KRB_I_RL:            /* /REALM:<name> */
  14272.                 if (pv[n].sval) {
  14273.                     free(pv[n].sval);
  14274.                     pv[n].sval = NULL;
  14275.                 }
  14276.                 if (!getval) break;
  14277.                 if (kv == 4)
  14278.                   p = krb4_d_realm ? krb4_d_realm : "";
  14279.                 else
  14280.                   p = krb5_d_realm ? krb5_d_realm : "";
  14281.                 if ((rc = cmfld("Realm",p,&s,xxstring)) < 0)
  14282.                   goto kerbx;
  14283.                 makestr(&(pv[n].sval),s);
  14284.                 break;
  14285.  
  14286.               case KRB_I_IN:            /* /INSTANCE:<name> */
  14287.                 if (pv[n].sval) {
  14288.                     free(pv[n].sval);
  14289.                     pv[n].sval = NULL;
  14290.                 }
  14291.                 if (!getval) break;
  14292.                 if (kv == 4)
  14293.                     p = krb4_d_instance ? krb4_d_instance : "";
  14294.                 else
  14295.                     p = krb5_d_instance ? krb5_d_instance : "";
  14296.                 if ((rc = cmfld("Instance",p,&s,xxstring)) < 0)
  14297.                   goto kerbx;
  14298.                 makestr(&(pv[n].sval),s);
  14299.                 break;
  14300.  
  14301.               case KRB_I_PW:            /* /PASSWORD:<password> */
  14302.                 debok = 0;
  14303.                 if (pv[n].sval) {
  14304.                     free(pv[n].sval);
  14305.                     pv[n].sval = NULL;
  14306.                 }
  14307.                 if (!getval) break;
  14308.                 if ((rc = cmfld("Password","",&s,xxstring)) < 0)
  14309.                   if (rc != -3)
  14310.                     goto kerbx;
  14311.                 makestr(&(pv[n].sval),s);
  14312.                 break;
  14313.  
  14314.               case KRB_I_ADR:           /* /ADDRESSES:{<address-list>} */
  14315.                 if (pv[n].sval) {
  14316.                     free(pv[n].sval);
  14317.                     pv[n].sval = NULL;
  14318.                 }
  14319.                 if (!getval) break;
  14320.                 if ((rc = cmfld("List of IP addresses","",&s,xxstring)) < 0)
  14321.                   goto kerbx;
  14322.                 makelist(s,tmpaddrs,KRB5_NUM_OF_ADDRS);
  14323.                 for (i = 0; i < KRB5_NUM_OF_ADDRS && tmpaddrs[i]; i++) {
  14324.                     if (inet_addr(tmpaddrs[i]) == 0xffffffff) {
  14325.                         printf("invalid ip address: %s\n",tmpaddrs[i]);
  14326.                         rc = -9;
  14327.                         goto kerbx;
  14328.                     }
  14329.                 }
  14330.                 pv[KRB_I_NAD].ival = 0;
  14331.                 break;
  14332.  
  14333.               default:
  14334.                 printf("?Unexpected switch value - internal error\n");
  14335.                 rc = -9;
  14336.                 goto kerbx;
  14337.             }
  14338.         }
  14339.         if (cmresult.fcode != _CMFLD) {
  14340.             printf("?Unexected result - internal error\n");
  14341.             rc = -9;
  14342.             goto kerbx;
  14343.         }
  14344.         /* cmresult.sresult may be of the form PRINCIPAL@REALM */
  14345.         i = ckindex("@",cmresult.sresult,0,0,0);
  14346.         if (i != 0) {
  14347.             makestr(&tmprealm,&cmresult.sresult[i]);
  14348.             cmresult.sresult[i-1] = '\0';
  14349.         }
  14350.         makestr(&tmpprinz,cmresult.sresult); /* Principal (user) */
  14351.  
  14352.         if ((rc = cmcfm()) < 0) {       /* Now get confirmation */
  14353.             if (rc == -3) {
  14354.                 printf("?Principal name required\n");
  14355.             }
  14356.             goto kerbx;
  14357.         }
  14358.         if (!tmpprinz || !tmpprinz[0]) {
  14359.             printf("?Principal name required\n");
  14360.             goto kerbx;
  14361.         }
  14362.         if (!pv[KRB_I_RN].ival && !pv[KRB_I_VA].ival) {
  14363.             /* Don't use a password if Validating or Renewing */
  14364.             if (pv[KRB_I_PW].sval) {    /* If they gave a /PASSWORD switch */
  14365.                 makestr(&tmppswd,pv[KRB_I_PW].sval); /* use this value */
  14366.             }
  14367. #ifdef COMMENT
  14368.             /* Password prompting has been moved to ck_krb[45]_initTGT() */
  14369.             else {                      /* Otherwise must prompt for it */
  14370.                 char prmpt[80];
  14371.                 if (pv[KRB_I_RL].sval)
  14372.                   sprintf(prmpt,"%s@%s's Password: ",
  14373.                           tmpprinz,pv[KRB_I_RL].sval);
  14374.                 else if (tmprealm)
  14375.                   sprintf(prmpt,"%s@%s's Password: ",
  14376.                           tmpprinz,tmprealm);
  14377.                 else
  14378.                   sprintf(prmpt,"%s's Password: ",tmpprinz);
  14379. #ifdef OS2
  14380.                 if (pv[KRB_I_POP].ival) {
  14381.                     char passwd[80]="";
  14382.                     readpass(prmpt,passwd,80);
  14383.                     makestr(&tmppswd,passwd);
  14384.                     memset(passwd,0,80);
  14385.                 } else
  14386. #endif /* OS2 */
  14387.                 {
  14388. #ifdef CK_RECALL
  14389.                     on_recall = 0;
  14390. #endif /* CK_RECALL */
  14391.                     cmsavp(psave,PROMPTL); /* Save old prompt */
  14392.                     cmsetp(prmpt);      /* Make new prompt */
  14393.                     concb((char)escape); /* Put console in cbreak mode */
  14394.                     cmini(0);           /* and no-echo mode */
  14395.                     /* Issue prompt if at top level */
  14396.                     if (pflag) prompt(xxstring);
  14397.                     cmres();            /* Reset the parser */
  14398.                     for (rc = -1; rc < 0; ) { /* Prompt till they answer */
  14399.                         /* Get a literal line of text */
  14400.                         rc = cmtxt("","",&s,NULL);
  14401.                         cmres();        /* Reset the parser again */
  14402.                     }
  14403.                     makestr(&tmppswd,s);
  14404.                     printf("\n");       /* Echo a CRLF */
  14405.                     cmsetp(psave);      /* Restore original prompt */
  14406.                 }
  14407.             }
  14408.             x = 0;                      /* Check for password */
  14409.             if (tmppswd)
  14410.               if (*tmppswd)
  14411.                 x = 1;
  14412.             if (!x) {
  14413.                 printf("?Password required\n");
  14414.                 goto kerbx;
  14415.             }
  14416. #endif /* COMMENT */
  14417.         }
  14418.     } else if (kv == 5 && tmp_action == KRB_A_LC) { /* LIST-CREDENTIALS */
  14419.         tmp_klc = 0;
  14420.         while (1) {
  14421.             if ((x = cmkey(klctab,nklctab,"Switch","",xxstring)) < 0) {
  14422.                 if (x == -3) {
  14423.                     if ((rc = cmcfm()) < 0)
  14424.                       goto kerbx;
  14425.                     else
  14426.                       break;
  14427.                 } else {
  14428.                     rc = x;
  14429.                     goto kerbx;
  14430.                 }
  14431.             }
  14432.             tmp_klc |= x;
  14433.         }
  14434.     } else if ((rc = cmcfm()) < 0)      /* DESTROY, just confirm */
  14435.         goto kerbx;
  14436.  
  14437. /* Done - Move confirmed data to final locations */
  14438.  
  14439.     krb_action = tmp_action;            /* Action requested */
  14440.     krb_op.version = kv;                /* Kerberos version */
  14441.     krb_op.cache = tmpcache;            /* Cache file */
  14442.     tmpcache = NULL;                    /* So we don't free it */
  14443.  
  14444.     switch (krb_action) {
  14445.       case KRB_A_IN:                    /* INITIALIZE */
  14446.         if (kv == 5) {
  14447.             krb5_init.forwardable = pv[KRB_I_FW].ival;
  14448.             krb5_init.proxiable   = pv[KRB_I_PR].ival;
  14449.             krb5_init.lifetime    = pv[KRB_I_LF].ival;
  14450.             krb5_init.renew       = pv[KRB_I_RN].ival;
  14451.             krb5_init.renewable   = pv[KRB_I_RB].ival;
  14452.             krb5_init.validate    = pv[KRB_I_VA].ival;
  14453.  
  14454.             /* Here we just reassign the pointers and then set them to NULL */
  14455.             /* so they won't be freed below. */
  14456.  
  14457.             krb5_init.postdate = pv[KRB_I_PD].sval; pv[KRB_I_PD].sval = NULL;
  14458.             krb5_init.service  = pv[KRB_I_SR].sval; pv[KRB_I_SR].sval = NULL;
  14459.             if (pv[KRB_I_RL].sval) {
  14460.                 krb5_init.realm  = pv[KRB_I_RL].sval; pv[KRB_I_RL].sval = NULL;
  14461.             } else if (tmprealm) {
  14462.                 krb5_init.realm = tmprealm; tmprealm = NULL;
  14463.             }
  14464.             if (pv[KRB_I_IN].sval) {
  14465.                 krb5_init.instance = pv[KRB_I_IN].sval;
  14466.                 pv[KRB_I_IN].sval = NULL;
  14467.             } else if ( tmpinst ) {
  14468.                 krb5_init.instance = tmpinst;
  14469.                 tmpinst = NULL;
  14470.             }
  14471.             if (tmpprinz) {
  14472.                 krb5_init.principal = tmpprinz;
  14473.                 tmpprinz = NULL;
  14474.             }
  14475.             krb5_init.password = tmppswd;
  14476.             tmppswd = NULL;
  14477.  
  14478.             krb5_init.getk4 = pv[KRB_I_K4].ival;
  14479.             if (krb5_init.getk4) {
  14480.                 krb4_init.lifetime = pv[KRB_I_LF].ival;
  14481.                 if (krb5_init.realm)
  14482.                     makestr(&krb4_init.realm,krb5_init.realm);
  14483.                 krb4_init.preauth  = krb4_d_preauth;
  14484.                 krb4_init.verbose  = pv[KRB_I_BR].ival ? 0 : 1;
  14485.                 if (krb5_init.principal)
  14486.                     makestr(&krb4_init.principal,krb5_init.principal);
  14487.                 if (krb5_init.principal)
  14488.                     makestr(&krb4_init.password,krb5_init.password);
  14489.             }
  14490.             krb5_init.no_addresses = pv[KRB_I_NAD].ival;
  14491.             if (tmpaddrs[0]) {
  14492.                 for (i = 0; i < KRB5_NUM_OF_ADDRS; i++) {
  14493.                     if (krb5_init.addrs[i]) {
  14494.                         free(krb5_init.addrs[i]);
  14495.                         krb5_init.addrs[i] = NULL;
  14496.                     }
  14497.                     krb5_init.addrs[i] = tmpaddrs[i];
  14498.                     tmpaddrs[i] = NULL;
  14499.                 }
  14500.             }
  14501.         } else if (kv == 4) {           /* Same deal for Kerberos 4 */
  14502.             krb4_init.lifetime = pv[KRB_I_LF].ival;
  14503.             if (pv[KRB_I_RL].sval) {
  14504.                 krb4_init.realm  = pv[KRB_I_RL].sval;
  14505.                 pv[KRB_I_RL].sval = NULL;
  14506.             } else if ( tmprealm ) {
  14507.                 krb4_init.realm  = tmprealm;
  14508.                 tmprealm = NULL;
  14509.             }
  14510.             if (pv[KRB_I_IN].sval) {
  14511.                 krb4_init.instance = pv[KRB_I_IN].sval;
  14512.                 pv[KRB_I_IN].sval = NULL;
  14513.             } else if ( tmpinst ) {
  14514.                 krb4_init.instance = tmpinst;
  14515.                 tmpinst = NULL;
  14516.             }
  14517.             krb4_init.preauth  = pv[KRB_I_PA].ival;
  14518.             krb4_init.verbose  = pv[KRB_I_BR].ival ? 0 : 1;
  14519.  
  14520.             if (tmpprinz) {
  14521.                 krb4_init.principal = tmpprinz;
  14522.                 tmpprinz = NULL;
  14523.             }
  14524.             krb4_init.password = tmppswd;
  14525.             tmppswd = NULL;
  14526.         }
  14527.         break;
  14528.       case KRB_A_LC:                    /* List Credentials */
  14529.         krb5_lc.encryption = tmp_klc & XYKLCEN;
  14530.         krb5_lc.flags = tmp_klc & XYKLCFL;
  14531.         krb5_lc.addr  = tmp_klc & XYKLCAD;
  14532.         break;
  14533.     }
  14534.  
  14535. /* Common exit - Free temporary storage */
  14536.  
  14537.   kerbx:
  14538.     for (i = 0; i <= KRB_I_MAX; i++) {  /* Free malloc'd switch data */
  14539.         if (pv[i].sval)
  14540.           free(pv[i].sval);
  14541.     }
  14542.     for (i = 0; i < KRB5_NUM_OF_ADDRS; i++) {
  14543.         if (tmpaddrs[i])
  14544.           free(tmpaddrs[i]);
  14545.     }
  14546.     if (tmpprinz) free(tmpprinz);       /* And these too. */
  14547.     if (tmppswd)  free(tmppswd);
  14548.     if (tmpcache) free(tmpcache);
  14549.     if (tmprealm) free(tmprealm);
  14550.     if (tmpinst)  free(tmpinst);
  14551.  
  14552.     return(rc);                         /* Return the return code */
  14553. }
  14554. #endif /* CK_KERBEROS */
  14555.  
  14556. #ifdef CK_LOGIN
  14557. int
  14558. #ifdef CK_ANSIC
  14559. ckxlogin(CHAR * userid, CHAR * passwd, CHAR * acct, int promptok)
  14560. #else /* CK_ANSIC */
  14561. ckxlogin(userid, passwd, acct, promptok)
  14562.   CHAR * userid; CHAR * passwd; CHAR * acct; int promptok;
  14563. #endif /* CK_ANSIC */
  14564. /* ckxlogin */ {
  14565. #ifdef CK_RECALL
  14566.     extern int on_recall;               /* around Password prompting */
  14567. #endif /* CK_RECALL */
  14568. #ifdef CK_PAM
  14569.     extern int guest;
  14570. #endif /* CK_PAM */
  14571.     int rprompt = 0;                    /* Restore prompt */
  14572. #ifdef CKSYSLOG
  14573.     int savlog;
  14574. #endif /* CKSYSLOG */
  14575.  
  14576.     extern int what, srvcdmsg;
  14577.  
  14578.     int x = 0, ok = 0, rc = 0;
  14579.     CHAR * _u = NULL, * _p = NULL, * _a = NULL;
  14580.  
  14581.     debug(F111,"ckxlogin userid",userid,promptok);
  14582.     debug(F110,"ckxlogin passwd",passwd,0);
  14583.  
  14584.     isguest = 0;                        /* Global "anonymous" flag */
  14585.  
  14586.     if (!userid) userid = (CHAR *)"";
  14587.     if (!passwd) passwd = (CHAR *)"";
  14588.  
  14589.     debug(F111,"ckxlogin userid",userid,what);
  14590.  
  14591. #ifdef CK_RECALL
  14592.     on_recall = 0;
  14593. #endif /* CK_RECALL */
  14594.  
  14595. #ifdef CKSYSLOG
  14596.     savlog = ckxsyslog;                 /* Save and turn off syslogging */
  14597. #endif /* CKSYSLOG */
  14598.  
  14599.     if ((!*userid || !*passwd) &&       /* Need to prompt for missing info */
  14600.         promptok) {
  14601.         cmsavp(psave,PROMPTL);          /* Save old prompt */
  14602.         debug(F110,"ckxlogin saved",psave,0);
  14603.         rprompt = 1;
  14604.     }
  14605.     if (!*userid) {
  14606.         if (!promptok)
  14607.           return(0);
  14608.         cmsetp("Username: ");           /* Make new prompt */
  14609.         concb((char)escape);            /* Put console in cbreak mode */
  14610.         cmini(1);
  14611.  
  14612. /* Flush typeahead */
  14613.  
  14614. #ifdef IKS_OPTION
  14615.         debug(F101,
  14616.               "ckxlogin TELOPT_SB(TELOPT_KERMIT).kermit.me_start",
  14617.               "",
  14618.               TELOPT_SB(TELOPT_KERMIT).kermit.me_start
  14619.               );
  14620. #endif /* IKS_OPTION */
  14621.  
  14622.         while (ttchk() > 0) {
  14623.             x = ttinc(0);
  14624.             debug(F101,"ckxlogin flush user x","",x);
  14625.             if (x < 0)
  14626.               doexit(GOOD_EXIT,0);      /* Connection lost */
  14627. #ifdef TNCODE
  14628.             if (sstelnet) {
  14629.                 if (x == IAC) {
  14630.                     x = tn_doop((CHAR)(x & 0xff),ckxech,ttinc);
  14631.                     debug(F101,"ckxlogin user tn_doop","",x);
  14632. #ifdef IKS_OPTION
  14633.                     debug(F101,
  14634.                       "ckxlogin user TELOPT_SB(TELOPT_KERMIT).kermit.me_start",
  14635.                       "",
  14636.                       TELOPT_SB(TELOPT_KERMIT).kermit.me_start
  14637.                       );
  14638. #endif /* IKS_OPTION */
  14639.  
  14640.                     if (x < 0)
  14641.                       goto XCKXLOG;
  14642.                     switch (x) {
  14643.                       case 1: ckxech = 1; break; /* Turn on echoing */
  14644.                       case 2: ckxech = 0; break; /* Turn off echoing */
  14645. #ifdef IKS_OPTION
  14646.                       case 4:                    /* IKS event */
  14647.                         if (!TELOPT_SB(TELOPT_KERMIT).kermit.me_start)
  14648.                           break;                 /* else fall thru... */
  14649. #endif /* IKS_OPTION */
  14650.                       case 6:                    /* Logout */
  14651.                         goto XCKXLOG;
  14652.                     }
  14653.                 }
  14654.             }
  14655. #endif /* TNCODE */
  14656.         }
  14657.         if (pflag) prompt(xxstring);    /* Issue prompt if at top level */
  14658.         cmres();                        /* Reset the parser */
  14659.         for (x = -1; x < 0;) {          /* Prompt till they answer */
  14660.             /* Get a literal line of text */
  14661.             x=cmtxt("Your username, or \"ftp\", or \"anonymous\"","",&s,NULL);
  14662.             if (x == -4 || x == -10) {
  14663.                 printf("\r\n%sLogin cancelled\n",
  14664.                x == -10 ? "Timed out: " : "");
  14665. #ifdef CKSYSLOG
  14666.                 ckxsyslog = savlog;
  14667. #endif /* CKSYSLOG */
  14668.                 doexit(GOOD_EXIT,0);
  14669.             }
  14670.             if (sstate)                 /* Did a packet come instead? */
  14671.               goto XCKXLOG;
  14672.             cmres();                    /* Reset the parser again */
  14673.         }
  14674.         if ((_u = (CHAR *)malloc((int)strlen(s) + 1)) == NULL) {
  14675.             printf("?Internal error: malloc\n");
  14676.             goto XCKXLOG;
  14677.         } else {
  14678.             strcpy((char *)_u,s);       /* safe */
  14679.             userid = _u;
  14680.         }
  14681.     }
  14682.     ok = zvuser((char *)userid);        /* Verify username */
  14683.     debug(F111,"ckxlogin zvuser",userid,ok);
  14684.  
  14685.     if (!*passwd && promptok
  14686. #ifdef CK_PAM
  14687.         && guest
  14688. #endif /* CK_PAM */
  14689.         ) {
  14690.         char prmpt[80];
  14691.  
  14692. #ifdef CKSYSLOG
  14693.         savlog = ckxsyslog;             /* Save and turn off syslogging */
  14694.         ckxsyslog = 0;
  14695. #endif /* CKSYSLOG */
  14696.  
  14697. /* Flush typeahead again */
  14698.  
  14699.         while (ttchk() > 0) {
  14700.             x = ttinc(0);
  14701.             debug(F101,"ckxlogin flush user x","",x);
  14702. #ifdef TNCODE
  14703.             if (sstelnet) {
  14704.                 if (x == IAC) {
  14705.                     x = tn_doop((CHAR)(x & 0xff),ckxech,ttinc);
  14706.                     debug(F101,"ckxlogin pass tn_doop","",x);
  14707. #ifdef IKS_OPTION
  14708.                     debug(F101,
  14709.                       "ckxlogin pass TELOPT_SB(TELOPT_KERMIT).kermit.me_start",
  14710.                       "",
  14711.                       TELOPT_SB(TELOPT_KERMIT).kermit.me_start
  14712.                       );
  14713. #endif /* IKS_OPTION */
  14714.                     if (x < 0)
  14715.                       goto XCKXLOG;
  14716.                     switch (x) {
  14717.                       case 1: ckxech = 1; break; /* Turn on echoing */
  14718.                       case 2: ckxech = 0; break; /* Turn off echoing */
  14719.                       case 4:                    /* IKS event */
  14720.                         if (!TELOPT_SB(TELOPT_KERMIT).kermit.me_start)
  14721.                           break;                 /* else fall thru... */
  14722.                       case 6:                    /* Logout */
  14723.                         goto XCKXLOG;
  14724.                     }
  14725.                 }
  14726.             }
  14727. #endif /* TNCODE */
  14728.         }
  14729.         if (!strcmp((char *)userid,"anonymous") ||
  14730.             !strcmp((char *)userid,"ftp")) {
  14731.             if (!ok)
  14732.               goto XCKXLOG;
  14733.             ckstrncpy(prmpt,"Enter e-mail address as Password: ",80);
  14734.         } else if (*userid && strlen((char *)userid) < 60) {
  14735. #ifdef NT
  14736.             extern CHAR * pReferenceDomainName;
  14737.             if (pReferenceDomainName)
  14738.               ckmakxmsg(prmpt,
  14739.                        80,
  14740.                        "Enter ",
  14741.                        pReferenceDomainName,
  14742.                        "\\\\",
  14743.                        userid,
  14744.                        "'s Password: ",
  14745.                        NULL,NULL,NULL,NULL,NULL,NULL,NULL
  14746.                        );
  14747.             else
  14748. #endif /* NT */
  14749.               ckmakmsg(prmpt,80,"Enter ",(char *)userid,"'s Password: ",NULL);
  14750.         } else
  14751.           ckstrncpy(prmpt,"Enter Password: ",80);
  14752.         cmsetp(prmpt);                  /* Make new prompt */
  14753.         concb((char)escape);            /* Put console in cbreak mode */
  14754.         if (strcmp((char *)userid,"anonymous") &&
  14755.             strcmp((char *)userid,"ftp")) { /* and if not anonymous */
  14756.             debok = 0;
  14757.             cmini(0);                   /* and no-echo mode */
  14758.         } else {
  14759.             cmini(1);
  14760.         }
  14761.         if (pflag) prompt(xxstring);    /* Issue prompt if at top level */
  14762.         cmres();                        /* Reset the parser */
  14763.         for (x = -1; x < 0;) {          /* Prompt till they answer */
  14764.             x = cmtxt("","",&s,NULL);   /* Get a literal line of text */
  14765.             if (x == -4 || x == -10) {
  14766.                 printf("\r\n%sLogin cancelled\n",
  14767.                x == -10 ? "Timed out: " : "");
  14768. #ifdef CKSYSLOG
  14769.                 ckxsyslog = savlog;
  14770. #endif /* CKSYSLOG */
  14771.                 doexit(GOOD_EXIT,0);
  14772.             }
  14773.             if (sstate)                 /* In case of a Kermit packet */
  14774.               goto XCKXLOG;
  14775.             cmres();                    /* Reset the parser again */
  14776.         }
  14777.         printf("\r\n");                 /* Echo a CRLF */
  14778.         if ((_p = (CHAR *)malloc((int)strlen(s) + 1)) == NULL) {
  14779.             printf("?Internal error: malloc\n");
  14780.             goto XCKXLOG;
  14781.         } else {
  14782.             strcpy((char *)_p,s);       /* safe */
  14783.             passwd = _p;
  14784.         }
  14785.     }
  14786. #ifdef CK_PAM
  14787.     else {
  14788.         cmres();                        /* Reset the parser */
  14789.  
  14790.         /* We restore the prompt now because the PAM engine will call  */
  14791.         /* readpass() which will overwrite psave. */
  14792.         if (rprompt) {
  14793.             cmsetp(psave);              /* Restore original prompt */
  14794.             debug(F110,"ckxlogin restored",psave,0);
  14795.             rprompt = 0;
  14796.         }
  14797.     }
  14798. #endif /* CK_PAM */
  14799.  
  14800. #ifdef CKSYSLOG
  14801.     ckxsyslog = savlog;
  14802. #endif /* CKSYSLOG */
  14803.  
  14804.     if (ok) {
  14805.         ok = zvpass((char *)passwd);    /* Check password */
  14806.         debug(F101,"ckxlogin zvpass","",ok);
  14807.     }
  14808.  
  14809.     if (ok > 0 && isguest) {
  14810. #ifndef NOPUSH
  14811.         nopush = 1;
  14812. #endif /* NOPUSH */
  14813.         srvcdmsg = 1;
  14814.     }
  14815.     rc = ok;                            /* Set the return code */
  14816.     if ((char *)uidbuf != (char *)userid)
  14817.       ckstrncpy(uidbuf,(char *)userid,UIDBUFLEN); /* Remember username */
  14818.  
  14819.   XCKXLOG:                              /* Common exit */
  14820. #ifdef CKSYSLOG
  14821.     ckxsyslog = savlog;                 /* In case of GOTO above */
  14822. #endif /* CKSYSLOG */
  14823.     if (rprompt) {
  14824.         cmsetp(psave);                  /* Restore original prompt */
  14825.         debug(F110,"ckxlogin restored",psave,0);
  14826.     }
  14827.     if (_u || _p || _a) {
  14828.         if (_u) free(_u);
  14829.         if (_p) free(_p);
  14830.         if (_a) free(_a);
  14831.     }
  14832.     return(rc);
  14833. }
  14834.  
  14835. int
  14836. ckxlogout() {
  14837.     doexit(GOOD_EXIT,0);                /* doexit calls zvlogout */
  14838.     return(0);                          /* not reached */
  14839. }
  14840. #endif /* CK_LOGIN */
  14841.  
  14842. #endif /* NOICP */
  14843.