home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / cku200.tar / ckuus7.c < prev    next >
C/C++ Source or Header  |  2001-12-07  |  410KB  |  14,324 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, 2001,
  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.  
  74. #ifdef STRATUS                /* Stratus Computer, Inc.  VOS */
  75. #ifdef putchar
  76. #undef putchar
  77. #endif /* putchar */
  78. #define putchar(x) conoc(x)
  79. #ifdef getchar
  80. #undef getchar
  81. #endif /* getchar */
  82. #define getchar(x) coninc(0)
  83. #endif /* STRATUS */
  84.  
  85. char * slmsg = NULL;
  86.  
  87. static int x, y = 0, z;
  88. static char *s;
  89.  
  90. extern CHAR feol;
  91. extern int g_matchdot, hints, xcmdsrc;
  92.  
  93. extern char * k_info_dir;
  94.  
  95. #ifndef NOSPL
  96. extern int nmac;
  97. extern struct mtab *mactab;
  98. #endif /* NOSPL */
  99.  
  100. #ifndef NOXFER
  101. #ifdef CK_SPEED
  102. extern short ctlp[];            /* Control-char prefixing table */
  103. #endif /* CK_SPEED */
  104.  
  105. #ifdef PIPESEND
  106. extern char * sndfilter, * g_sfilter;
  107. extern char * rcvfilter, * g_rfilter;
  108. #endif /* PIPESEND */
  109.  
  110. extern char * snd_move;
  111. extern char * snd_rename;
  112. extern char * g_snd_move;
  113. extern char * g_snd_rename;
  114. extern char * rcv_move;
  115. extern char * rcv_rename;
  116. extern char * g_rcv_move;
  117. extern char * g_rcv_rename;
  118.  
  119. #ifdef PATTERNS
  120. extern char *binpatterns[], *txtpatterns[];
  121. extern int patterns;
  122. #endif /* PATTERNS */
  123.  
  124. extern char * remdest;
  125. #ifdef CK_TMPDIR
  126. char * dldir = NULL;
  127. #endif /* CK_TMPDIR */
  128.  
  129. extern struct ck_p ptab[];
  130.  
  131. extern int protocol, remfile, rempipe, remappd, reliable, xreliable, fmask,
  132.   fncnv, frecl, maxrps, wslotr, bigsbsiz, bigrbsiz, urpsiz, rpsiz, spsiz,
  133.   bctr, npad, timef, timint, spsizr, spsizf, maxsps, spmax, nfils, displa,
  134.   atcapr, pkttim, rtimo, fncact, mypadn, fdispla, f_save, pktpaus, setreliable,
  135.   fnrpath, fnspath, atenci, atenco, atdati, atdato, atleni, atleno, atblki,
  136.   atblko, attypi, attypo, atsidi, atsido, atsysi, atsyso, atdisi, atdiso;
  137.  
  138. extern int stathack;
  139.  
  140. extern int atfrmi, atfrmo;
  141. #ifdef STRATUS
  142. extern int atcrei, atcreo, atacti, atacto;
  143. #endif /* STRATUS */
  144. #ifdef CK_PERMS
  145. extern int atlpri, atlpro, atgpri, atgpro;
  146. #endif /* CK_PERMS */
  147.  
  148. extern CHAR
  149.   sstate, eol, seol, stchr, mystch, mypadc, padch, ctlq, myctlq;
  150.  
  151. #ifdef IKSD
  152. extern int inserver;
  153. #ifdef IKSDCONF
  154. extern int iksdcf;
  155. #endif /* IKSDCONF */
  156. #endif /* IKSD */
  157.  
  158. extern char *cmarg, *cmarg2;
  159.  
  160. #ifndef NOFRILLS
  161. extern char optbuf[];            /* Buffer for MAIL or PRINT options */
  162. extern int rprintf;            /* REMOTE PRINT flag */
  163. #endif /* NOFRILLS */
  164. #endif /* NOXFER */
  165.  
  166. #ifdef CK_TRIGGER
  167. extern char * tt_trigger[];
  168. #endif /* CK_TRIGGER */
  169.  
  170. extern int tcs_transp;
  171. #ifdef PCTERM
  172. extern int tt_pcterm;
  173. #endif /* PCTERM */
  174. #ifdef NT
  175. extern int tt_vtnt;
  176. #endif /* NT */
  177.  
  178. #ifdef CK_AUTHENTICATION
  179. extern int auth_type_user[];
  180. int sl_auth_type_user[AUTHTYPLSTSZ] = {AUTHTYPE_NULL, AUTHTYPE_NULL};
  181. int sl_auth_saved = 0;
  182. int sl_topt_a_su = 0;
  183. int sl_topt_a_s_saved = 0;
  184. int sl_topt_a_cm = 0;
  185. int sl_topt_a_c_saved = 0;
  186. #endif /* CK_AUTHENTICATION */
  187. #ifdef CK_ENCRYPTION
  188. extern int cx_type;
  189. int sl_cx_type = 0;
  190. int sl_cx_saved = 0;
  191. int sl_topt_e_su = 0;
  192. int sl_topt_e_sm = 0;
  193. int sl_topt_e_s_saved = 0;
  194. int sl_topt_e_cu = 0;
  195. int sl_topt_e_cm = 0;
  196. int sl_topt_e_c_saved = 0;
  197. #endif /* CK_ENCRYPTION */
  198. extern char uidbuf[];
  199. static int uidflag = 0;
  200. char sl_uidbuf[UIDBUFLEN] = { NUL, NUL };
  201. int  sl_uid_saved = 0;
  202. #ifdef TNCODE
  203. int  sl_tn_wait = 0;
  204. int  sl_tn_saved = 0;
  205. #endif /* TNCODE */
  206.  
  207. #ifdef TNCODE
  208. extern int tn_wait_flg;
  209. #endif /* TNCODE */
  210.  
  211. VOID
  212. slrestor() {
  213. #ifdef CK_AUTHENTICATION
  214.     int x;
  215.     if (sl_auth_saved) {
  216.         for (x = 0; x < AUTHTYPLSTSZ; x++)
  217.       auth_type_user[x] = sl_auth_type_user[x];
  218.         sl_auth_saved = 0;
  219.     }
  220.     if (sl_topt_a_s_saved) {
  221.         TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = sl_topt_a_su;
  222.         sl_topt_a_s_saved = 0;
  223.     }
  224.     if (sl_topt_a_c_saved) {
  225.         TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = sl_topt_a_cm;
  226.         sl_topt_a_c_saved = 0;
  227.     }
  228. #endif /* CK_AUTHENTICATION */
  229. #ifdef CK_ENCRYPTION
  230.     if (sl_cx_saved) {
  231.         cx_type = sl_cx_type;
  232.         sl_cx_saved = 0;
  233.     }
  234.     if (sl_topt_e_s_saved) {
  235.         TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION)  = sl_topt_e_su;
  236.         TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION) = sl_topt_e_sm;
  237.         sl_topt_e_s_saved = 0;
  238.     }
  239.     if (sl_topt_e_c_saved) {
  240.         TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION)  = sl_topt_e_cu;
  241.         TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION) = sl_topt_e_cm;
  242.         sl_topt_e_c_saved = 0;
  243.     }
  244. #endif /* CK_ENCRYPTION */
  245.     if (sl_uid_saved) {
  246.         ckstrncpy(uidbuf,sl_uidbuf,UIDBUFLEN);
  247.         sl_uid_saved = 0;
  248.     }
  249. #ifdef TNCODE
  250.     if (sl_tn_saved) {
  251.         tn_wait_flg = sl_tn_wait;
  252.         sl_tn_saved = 0;
  253.     }
  254. #endif /* TNCODE */
  255. }
  256.  
  257. int oldplex = -1;            /* Duplex holder around network */
  258.  
  259. #ifndef NOICP
  260.  
  261. /* Note: gcc -Wall wants braces around each keyword table entry. */
  262.  
  263. static struct keytab psltab[] = {    /* SET LINE/PORT command options */
  264.     { "/connect", SL_CNX, 0 },
  265. #ifdef OS2ORVMS
  266.     { "/noshare", SL_NSH, 0 },
  267. #endif /* OS2ORVMS */
  268.     { "/server",  SL_SRV, 0 },
  269. #ifdef OS2ORVMS
  270.     { "/share",   SL_SHR, 0 },
  271. #endif /* OS2ORVMS */
  272.     { "", 0, 0 }
  273. };
  274. static int npsltab = sizeof(psltab)/sizeof(struct keytab) - 1;
  275.  
  276. #ifdef NETCONN
  277. static struct keytab shtab[] = {    /* SET HOST command options */
  278. #ifdef NETCMD
  279.     /* (COMMAND is also a network type) */
  280.     { "/command",      SL_CMD,    CM_INV },
  281. #endif /* NETCMD */
  282.     { "/connect",      SL_CNX,    0 },
  283.     { "/network-type", SL_NET,    CM_ARG },
  284.     { "/nowait",       SL_NOWAIT, 0 },
  285. #ifndef NOSPL
  286.     { "/password",     SL_PSW,    CM_ARG },
  287. #endif /* NOSPL */
  288. #ifdef NETCMD
  289.     { "/pipe",         SL_CMD,    0 },
  290. #endif /* NETCMD */
  291. #ifdef NETPTY
  292.     { "/pty",          SL_PTY,    0 },
  293. #endif /* NETPTY */
  294.     { "/server",       SL_SRV,    0 },
  295.     { "/timeout",      SL_TMO,    CM_ARG },
  296.     { "/userid",       SL_UID,    CM_ARG },
  297.     { "/wait",         SL_WAIT,   0 },
  298.     { "", 0, 0 }
  299. };
  300. static int nshtab = sizeof(shtab)/sizeof(struct keytab) - 1;
  301.  
  302. static struct keytab shteltab[] = {    /* TELNET command options */
  303. #ifdef CK_AUTHENTICATION
  304.     { "/auth",         SL_AUTH,   CM_ARG },
  305. #endif /* CK_AUTHENTICATION */
  306. #ifdef CK_ENCRYPTION
  307.     { "/encrypt",      SL_ENC,    CM_ARG },
  308. #endif /* CK_ENCRYPTION */
  309.     { "/nowait",       SL_NOWAIT, 0 },
  310. #ifndef NOSPL
  311.     { "/password",     SL_PSW,    CM_ARG },
  312. #endif /* NOSPL */
  313.     { "/timeout",      SL_TMO,    CM_ARG },
  314.     { "/userid",       SL_UID,    CM_ARG },
  315.     { "/wait",         SL_WAIT,   0 },
  316.     { "", 0 ,0 }
  317. };
  318. static int nshteltab = sizeof(shteltab)/sizeof(struct keytab) - 1;
  319.  
  320. #ifdef RLOGCODE
  321. static struct keytab shrlgtab[] = {    /* SET HOST RLOGIN command options */
  322. #ifdef CK_KERBEROS
  323. #ifdef CK_ENCRYPTION
  324.     { "/encrypt",      SL_ENC, 0 },
  325. #endif /* CK_ENCRYPTION */
  326.     { "/k4",           SL_KRB4, CM_INV },
  327.     { "/k5",           SL_KRB5, CM_INV },
  328.     { "/kerberos4",    SL_KRB4, 0 },
  329.     { "/kerberos5",    SL_KRB5, 0 },
  330.     { "/kerberos_iv",  SL_KRB4, CM_INV },
  331.     { "/kerberos_v",   SL_KRB5, CM_INV },
  332.     { "/krb4",         SL_KRB4, CM_INV },
  333.     { "/krb5",         SL_KRB5, CM_INV },
  334. #endif /* CK_KERBEROS */
  335.     { "", 0 ,0 }
  336. };
  337. static int nshrlgtab = sizeof(shrlgtab)/sizeof(struct keytab)-1;
  338. #endif /* RLOGCODE */
  339.  
  340. extern struct keytab netcmd[];
  341. extern int nnets;
  342. #ifndef NODIAL
  343. extern int dirline;
  344. extern int nnetdir;            /* Network services directory */
  345. extern char *netdir[];
  346. _PROTOTYP( VOID ndreset, (void) );
  347. char *nh_p[MAXDNUMS + 1];        /* Network directory entry pointers */
  348. char *nh_p2[MAXDNUMS + 1];        /* Network directory entry nettype */
  349. char *nh_px[4][MAXDNUMS + 1];        /* Network-specific stuff... */
  350. #endif /* NODIAL */
  351. int nhcount = 0;
  352. int ndinited = 0;
  353. char * n_name = NULL;            /* Network name pointer */
  354. #endif /* NETCONN */
  355.  
  356. _PROTOTYP(int remtxt, (char **) );
  357. _PROTOTYP(VOID rmsg, (void) );
  358. _PROTOTYP(static int remcfm, (void) );
  359.  
  360. extern int nopush;
  361.  
  362. int mdmsav = -1;            /* Save modem type around network */
  363. extern int isguest;            /* Global flag for anonymous login */
  364.  
  365. extern xx_strp xxstring;
  366.  
  367. extern int success, binary, b_save, ckwarn, msgflg, quiet, cmask, pflag, local,
  368.   nettype, escape, mdmtyp, duplex, dfloc, network, cdtimo, autoflow, tnlm,
  369.   sosi, tlevel, lf_opts, backgrd, flow, debses, parity, ttnproto, ckxech,
  370.   x_ifnum, cmflgs, haveline, cxtype, cxflow[], maclvl;
  371.  
  372. #ifdef DCMDBUF
  373. extern struct cmdptr *cmdstk;        /* The command stack itself */
  374. #else
  375. extern struct cmdptr cmdstk[];        /* The command stack itself */
  376. #endif /* DCMDBUF */
  377. extern FILE * tfile[];
  378. extern char * macp[];
  379.  
  380. extern char psave[];            /* For saving & restoring prompt */
  381. extern int sprmlen, rprmlen;
  382.  
  383. #ifdef OS2
  384. static struct keytab strmkeytab[] = {
  385.     { "clear",   0, 0 },
  386.     { "default", 1, 0 }
  387. };
  388. static int nstrmkeytab = sizeof(strmkeytab)/sizeof(struct keytab);
  389.  
  390. static struct keytab strmswitab[] = {
  391.     { "/literal", 0, 0 }
  392. };
  393. static int nstrmswitab = sizeof(strmswitab)/sizeof(struct keytab);
  394.  
  395. static struct keytab normrev[] = {
  396.     { "dark-display", 0, 0 },
  397.     { "light-display", 1, 0 },
  398.     { "normal",   0, 0 },
  399.     { "reverse",  1, 0 }
  400. };
  401.  
  402. static struct keytab prnmtab[] = {
  403.     { "auto", 1, 0 },
  404.     { "copy", 2, 0 },
  405.     { "off",  0, 0 },
  406.     { "on",   1, CM_INV },        /* Compatibility with XPRINT version */
  407.     { "user", 3, 0 },
  408.     { "transparent", 3, CM_INV }    /* not really transparent */
  409. };
  410. static int nprnmtab = sizeof(prnmtab)/sizeof(struct keytab);
  411.  
  412. extern int tt_diff_upd;
  413.  
  414. #ifdef NT
  415. #define stricmp _stricmp
  416. extern int tt_attr_bug;
  417. #endif /* NT */
  418. extern int tt_rows[], tt_cols[];
  419. extern int tt_cols_usr;
  420. extern int tt_szchng[VNUM];
  421. int tt_modechg = TVC_ENA;
  422. extern int tt_url_hilite, tt_url_hilite_attr;
  423. extern struct _vtG G[4];
  424. extern int priority;
  425. extern bool send_c1;
  426. int send_c1_usr = FALSE;
  427. extern int sgrcolors;
  428. extern int marginbell, marginbellcol;
  429. extern int autoscroll, wy_autopage;
  430. extern int tt_sac;
  431. extern int dec_nrc, dec_lang, dec_kbd;
  432. #else /* OS2 */
  433. extern int tt_rows, tt_cols;
  434. #endif /*  OS2 */
  435.  
  436. extern int tt_escape;
  437. extern long speed;
  438.  
  439. extern char *dftty;
  440.  
  441. extern char *tp, *lp;            /* Temporary buffer & pointers */
  442. extern char ttname[];
  443.  
  444. int tttapi = 0;                /* is Line TAPI? */
  445. struct keytab * tapilinetab = NULL;
  446. struct keytab * _tapilinetab = NULL;
  447. int ntapiline = 0;
  448.  
  449. #ifdef NETCONN                /* Network items */
  450.  
  451. #ifdef ANYX25
  452. extern int revcall, closgr, cudata, nx25;
  453. extern char udata[];
  454. extern struct keytab x25tab[];
  455. #ifndef IBMX25
  456. extern int npadx3;
  457. extern CHAR padparms[];
  458. extern struct keytab padx3tab[];
  459. #endif /* IBMX25 */
  460. #endif /* ANYX25 */
  461.  
  462. #ifdef OS2
  463. extern bool ttshare;
  464. #ifndef NT
  465. extern bool ttslip,ttppp;
  466. #endif /* NT */
  467. #endif /* OS2 */
  468. #ifdef NPIPE
  469. extern char pipename[];
  470. #endif /* NPIPE */
  471.  
  472. #ifdef TCPSOCKET
  473. static struct keytab tcprawtab[] = {    /* SET HOST options */
  474.     { "/default",    NP_DEFAULT,    CM_INV },
  475. #ifdef CK_AUTHENTICATION
  476. #ifdef CK_KERBEROS
  477. #ifdef RLOGCODE
  478.     { "/ek4login",    NP_EK4LOGIN,    0 },
  479.     { "/ek5login",    NP_EK5LOGIN,    0 },
  480.     { "/k4login",     NP_K4LOGIN,     0 },
  481.     { "/k5login",     NP_K5LOGIN,     0 },
  482. #endif /* RLOGCODE */
  483. #ifdef KRB5_U2U
  484.     { "/k5user2user", NP_K5U2U,       0 },
  485. #endif /* KRB5_U2U */
  486. #endif /* CK_KERBEROS */
  487. #endif /* CK_AUTHENTICATION */
  488.     { "/no-telnet-init", NP_NONE,   0 },
  489.     { "/none",       NP_NONE,   CM_INV },
  490.     { "/raw-socket", NP_TCPRAW, 0 },
  491. #ifdef RLOGCODE
  492.     { "/rlogin",     NP_RLOGIN, 0 },
  493. #endif /* RLOGCODE */
  494. #ifdef CK_SSL
  495.     { "/ssl",        NP_SSL,    0 },
  496.     { "/ssl-telnet", NP_SSL_TELNET, 0 },
  497. #endif /* CK_SSL */
  498.     { "/telnet",     NP_TELNET, 0 },
  499. #ifdef CK_SSL
  500.     { "/tls",        NP_TLS,    0 },
  501.     { "/tls-telnet", NP_TLS_TELNET, 0 },
  502. #endif /* CK_SSL */
  503.     { "", 0, 0 }
  504. };
  505. static int ntcpraw = (sizeof(tcprawtab) / sizeof(struct keytab)) - 1;
  506.  
  507. #ifdef RLOGCODE
  508. _PROTOTYP( int rlog_naws, (void) );
  509. #endif /* RLOGCODE */
  510. #endif /* TCPSOCKET */
  511.  
  512. #ifdef SUPERLAT
  513. extern char slat_pwd[18];
  514. #endif /* SUPERLAT */
  515. #endif /* NETCONN */
  516.  
  517. #ifdef COMMENT
  518. #ifndef NOSETKEY
  519. extern KEY *keymap;
  520. #ifndef OS2
  521. #define mapkey(x) keymap[x]
  522. #endif /* OS2 */
  523. extern MACRO *macrotab;
  524. #ifndef NOKVERBS
  525. extern struct keytab kverbs[];
  526. extern int nkverbs;
  527. #endif /* NOKVERBS */
  528. #endif /* NOSETKEY */
  529. #else
  530. #ifndef NOSETKEY
  531. extern KEY *keymap;
  532. extern MACRO *macrotab;
  533. #ifndef NOKVERBS
  534. extern struct keytab kverbs[];
  535. extern int nkverbs;
  536. #endif /* NOKVERBS */
  537. #endif /* NOSETKEY */
  538. #endif /* COMMENT */
  539.  
  540. #ifdef OS2                /* AUTODOWNLOAD parameters */
  541. extern int    adl_kmode, adl_zmode;    /* Match Packet to signal download */
  542. extern char * adl_kstr;            /* KERMIT Download String */
  543. extern char * adl_zstr;            /* ZMODEM Download String */
  544. extern int adl_kc0, adl_zc0;        /* Process ADL C0s in emulation */
  545. #endif /* OS2 */
  546.  
  547. /* Keyword tables ... */
  548.  
  549. extern struct keytab onoff[], rltab[];
  550. extern int nrlt;
  551.  
  552. #ifndef NOCSETS
  553. static struct keytab fdfltab[] = {
  554.     { "7bit-character-set", 7, 0 },
  555.     { "8bit-character-set", 8, 0 }
  556. };
  557. static int nfdflt = (sizeof(fdfltab) / sizeof(struct keytab));
  558. #endif /* NOCSETS */
  559.  
  560. /* SET FILE parameters */
  561.  
  562. static struct keytab filtab[] = {
  563. #ifndef NOXFER
  564. #ifdef PATTERNS
  565.     { "binary-patterns",   XYFIBP,  0 },
  566. #endif /* PATTERNS */
  567.     { "bytesize",         XYFILS,   0 },
  568. #ifndef NOCSETS
  569.     { "character-set",    XYFILC,   0 },
  570. #endif /* NOCSETS */
  571.     { "collision",        XYFILX,   0 },
  572.     { "default",          XYF_DFLT, 0 },
  573.     { "destination",      XYFILY,   0 },
  574.     { "display",          XYFILD,   CM_INV },
  575. #ifdef CK_TMPDIR
  576.     { "download-directory", XYFILG, 0 },
  577. #endif /* CK_TMPDIR */
  578. #endif /* NOXFER */
  579.     { "end-of-line",      XYFILA,   0 },
  580.     { "eol",              XYFILA,   CM_INV },
  581. #ifdef CK_CTRLZ
  582.     { "eof",              XYFILV,   0 },
  583. #endif /* CK_CTRLZ */
  584. #ifndef NOXFER
  585.     { "fastlookups",      9997,     CM_INV },
  586.     { "incomplete",       XYFILI,   0 },
  587. #ifndef datageneral
  588.     { "inspection",       XYF_INSP, CM_INV },
  589. #endif /* datageneral */
  590. #ifdef CK_LABELED
  591.     { "label",            XYFILL, 0 },
  592. #endif /* CK_LABELED */
  593.  
  594. #ifdef UNIX
  595. #ifdef DYNAMIC
  596.     { "listsize",         XYF_LSIZ, 0 },
  597. #endif /* DYNAMIC */
  598. #endif /* UNIX */
  599.  
  600.     { "names",            XYFILN, 0 },
  601. #ifdef UNIX
  602.     { "output",           XYFILH, 0 },
  603. #endif /* UNIX */
  604. #ifdef PATTERNS
  605.     { "patterns",         XYFIPA, 0 },
  606. #endif /* PATTERNS */
  607.     { "permissions",      XYF_PRM, CM_INV },
  608.     { "protection",       XYF_PRM, 0 },
  609. #ifdef VMS
  610.     { "record-length",    XYFILR, 0 },
  611. #endif /* VMS */
  612. #ifndef datageneral
  613.     { "scan",             XYF_INSP, 0 },
  614. #endif /* datageneral */
  615.  
  616. #ifdef UNIX
  617. #ifdef DYNAMIC
  618.     { "stringspace",      XYF_SSPA, 0 },
  619. #endif /* DYNAMIC */
  620. #endif /* UNIX */
  621.  
  622. #ifdef PATTERNS
  623.     { "t",                XYFILT, CM_INV|CM_ABR },
  624.     { "text-patterns",    XYFITP, 0 },
  625. #endif /* PATTERNS */
  626. #endif /* NOXFER */
  627.     { "type",             XYFILT, 0 },
  628. #ifdef UNICODE
  629.     { "ucs",              XYFILU, 0 },
  630. #endif /* UNICODE */
  631. #ifndef NOXFER
  632.     { "warning",          XYFILW, CM_INV }
  633. #endif /* NOXFER */
  634. };
  635. static int nfilp = (sizeof(filtab) / sizeof(struct keytab));
  636.  
  637. struct keytab pathtab[] = {
  638.     { "absolute",  PATH_ABS,  0      },
  639.     { "none",      PATH_OFF,  CM_INV },
  640.     { "off",       PATH_OFF,  0      },
  641.     { "on",        PATH_ABS,  CM_INV },
  642.     { "relative",  PATH_REL,  0      }
  643. };
  644. int npathtab = (sizeof(pathtab) / sizeof(struct keytab));
  645.  
  646. struct keytab rpathtab[] = {
  647.     { "absolute",  PATH_ABS,  0      },
  648.     { "auto",      PATH_AUTO, 0      },
  649.     { "none",      PATH_OFF,  CM_INV },
  650.     { "off",       PATH_OFF,  0      },
  651.     { "on",        PATH_ABS,  CM_INV },
  652.     { "relative",  PATH_REL,  0      }
  653. };
  654. int nrpathtab = (sizeof(rpathtab) / sizeof(struct keytab));
  655.  
  656. #ifdef CK_CTRLZ
  657. struct keytab eoftab[] = {        /* EOF detection method */
  658.     { "ctrl-z",          1, 0      },
  659.     { "length",          0, 0      },
  660.     { "noctrl-z",        0, CM_INV }
  661. };
  662. #endif /* CK_CTRLZ */
  663.  
  664. struct keytab fttab[] = {        /* File types for SET FILE TYPE */
  665.     { "ascii",     XYFT_T, CM_INV },
  666. #ifdef VMS
  667.     { "b",         XYFT_B, CM_INV|CM_ABR },
  668. #endif /* VMS */
  669.     { "binary",    XYFT_B, 0 },
  670. #ifdef VMS
  671.     { "block",     XYFT_I, CM_INV },
  672.     { "image",     XYFT_I, 0 },
  673. #endif /* VMS */
  674. #ifdef CK_LABELED
  675.     { "labeled",   XYFT_L, 0 },
  676. #endif /* CK_LABELED */
  677. #ifdef MAC
  678.     { "macbinary", XYFT_M, 0 },
  679. #endif /* MAC */
  680.     { "text",      XYFT_T, 0 }
  681. };
  682. int nfttyp = (sizeof(fttab) / sizeof(struct keytab));
  683.  
  684. static struct keytab rfttab[] = {    /* File types for REMOTE SET FILE */
  685.     { "ascii",     XYFT_T, CM_INV },
  686.     { "binary",    XYFT_B, 0 },
  687. #ifdef VMS
  688.     { "labeled",   XYFT_L, 0 },
  689. #else
  690. #ifdef OS2
  691.     { "labeled",   XYFT_L, 0 },
  692. #endif /* OS2 */
  693. #endif /* VMS */
  694.     { "text",      XYFT_T, 0 }
  695. };
  696. static int nrfttyp = (sizeof(rfttab) / sizeof(struct keytab));
  697.  
  698. #ifdef OS2ORUNIX
  699. #define ZOF_BLK  0
  700. #define ZOF_NBLK 1
  701. #define ZOF_BUF  2
  702. #define ZOF_NBUF 3
  703. static struct keytab zoftab[] = {
  704.     { "blocking",    ZOF_BLK,  0 },
  705.     { "buffered",    ZOF_BUF,  0 },
  706.     { "nonblocking", ZOF_NBLK, 0 },
  707.     { "unbuffered",  ZOF_NBUF, 0 }
  708. };
  709. static int nzoftab = (sizeof(zoftab) / sizeof(struct keytab));
  710. #endif /* OS2ORUNIX */
  711.  
  712. extern int query;            /* Global flag for QUERY active */
  713.  
  714. #ifndef NOSPL
  715. #ifndef NOXFER
  716. static struct keytab vartyp[] = {    /* Variable types for REMOTE QUERY */
  717.     { "global",   (int) 'G', CM_INV },
  718.     { "kermit",   (int) 'K', 0 },
  719.     { "system",   (int) 'S', 0 },
  720.     { "user",     (int) 'G', 0 }
  721. };
  722. static int nvartyp = (sizeof(vartyp) / sizeof(struct keytab));
  723. #endif /* NOXFER */
  724. #endif /* NOSPL */
  725.  
  726. #ifdef CK_TIMERS
  727. static struct keytab timotab[] = {    /* Timer types */
  728.     { "dynamic", 1, 0 },
  729.     { "fixed",   0, 0 }
  730. };
  731. #endif /* CK_TIMERS */
  732.  
  733. #ifdef DCMDBUF
  734. extern char *atxbuf, *atmbuf;        /* Atom buffer */
  735. extern char *cmdbuf;            /* Command buffer */
  736. extern char *line, *tmpbuf;        /* Character buffers for anything */
  737. extern int *intime;            /* INPUT TIMEOUT */
  738.  
  739. #else  /* Not DCMDBUF ... */
  740.  
  741. extern char atxbuf[], atmbuf[];        /* Atom buffer */
  742. extern char cmdbuf[];            /* Command buffer */
  743. extern char line[], tmpbuf[];        /* Character buffer for anything */
  744. extern int intime[];
  745.  
  746. #endif /* DCMDBUF */
  747.  
  748. #ifndef NOCSETS
  749. extern struct keytab fcstab[];        /* For SET FILE CHARACTER-SET */
  750. extern struct csinfo fcsinfo[];        /* File character set info. */
  751. extern struct keytab ttcstab[];
  752. extern int nfilc, fcharset, tcharset, ntermc, tcsr, tcsl, dcset7, dcset8;
  753. #ifdef CKOUNI
  754. extern int tt_utf8;
  755. #endif /* CKOUNI */
  756. #ifdef OS2
  757. _PROTOTYP( int os2setcp, (int) );
  758. _PROTOTYP( int os2getcp, (void) );
  759. _PROTOTYP( void os2debugoff, (void) );
  760. #endif /* OS2 */
  761. #endif /* NOCSETS */
  762.  
  763. extern int cmdlvl;            /* Overall command level */
  764.  
  765. #ifndef NOSPL
  766. #ifdef DCMDBUF
  767. extern int *inpcas;            /* INPUT CASE setting on cmd stack */
  768. #else
  769. extern int inpcas[];
  770. #endif /* DCMDBUF */
  771. #endif /* NOSPL */
  772.  
  773. #ifdef CK_CURSES
  774. #ifndef VMS
  775. _PROTOTYP(int tgetent,(char *, char *));
  776. #else
  777. #ifdef __DECC
  778. _PROTOTYP(int tgetent,(char *, char *));
  779. #endif /* __DECC */
  780. #endif /* VMS */
  781. #endif /* CK_CURSES */
  782.  
  783. #ifndef NOXMIT
  784. #define XMITF 0                /* SET TRANSMIT values */
  785. #define XMITL 1                /* (Local to this module) */
  786. #define XMITP 2
  787. #define XMITE 3
  788. #define XMITX 4
  789. #define XMITS 5
  790. #define XMITW 6
  791. #define XMITT 7
  792.  
  793. #define XMBUFL 50
  794. extern int xmitf, xmitl, xmitp, xmitx, xmits, xmitw, xmitt;
  795. char xmitbuf[XMBUFL+1] = { NUL };    /* TRANSMIT eof string */
  796.  
  797. struct keytab xmitab[] = {        /* SET TRANSMIT */
  798.     { "echo",          XMITX, 0 },
  799.     { "eof",           XMITE, 0 },
  800.     { "fill",          XMITF, 0 },
  801.     { "linefeed",      XMITL, 0 },
  802.     { "locking-shift", XMITS, 0 },
  803.     { "pause",         XMITW, 0 },
  804.     { "prompt",        XMITP, 0 },
  805.     { "timeout",       XMITT, 0 }
  806. };
  807. int nxmit = (sizeof(xmitab) / sizeof(struct keytab));
  808. #endif /* NOXMIT */
  809.  
  810. /* For SET FILE COLLISION */
  811. /* Some of the following may be possible for some C-Kermit implementations */
  812. /* but not others.  Those that are not possible for your implementation */
  813. /* should be ifdef'd out. */
  814.  
  815. struct keytab colxtab[] = { /* SET FILE COLLISION options */
  816. #ifndef MAC
  817.     { "append",    XYFX_A, 0 },        /* append to old file */
  818. #endif /* MAC */
  819. #ifdef COMMENT
  820.     { "ask",       XYFX_Q, 0 },        /* ask what to do (not implemented) */
  821. #endif
  822.     { "backup",    XYFX_B, 0 },        /* rename old file */
  823. #ifndef MAC
  824.     /* This crashes Mac Kermit. */
  825.     { "discard",   XYFX_D, 0 },        /* don't accept new file */
  826.     { "no-supersede", XYFX_D, CM_INV }, /* ditto (MSK compatibility) */
  827. #endif /* MAC */
  828.     { "overwrite", XYFX_X, 0 },        /* overwrite the old file */
  829.     { "rename",    XYFX_R, 0 },        /* rename the incoming file */
  830. #ifndef MAC                /* This crashes Mac Kermit. */
  831.     { "update",    XYFX_U, 0 },        /* replace if newer */
  832. #endif /* MAC */
  833.     { "", 0, 0 }
  834. };
  835. int ncolx = (sizeof(colxtab) / sizeof(struct keytab)) - 1;
  836.  
  837. static struct keytab rfiltab[] = {    /* for REMOTE SET FILE */
  838. #ifndef NOCSETS
  839.     { "character-set", XYFILC, 0 },
  840. #endif /* NOCSETS */
  841.     { "collision",     XYFILX, 0 },
  842.     { "incomplete",    XYFILI, 0 },
  843.     { "names",         XYFILN, 0 },
  844.     { "record-length", XYFILR, 0 },
  845.     { "type",          XYFILT, 0 }
  846. };
  847. int nrfilp = (sizeof(rfiltab) / sizeof(struct keytab));
  848.  
  849. struct keytab eoltab[] = {           /* File eof delimiters */
  850.     { "cr",        XYFA_C, 0 },
  851.     { "crlf",      XYFA_2, 0 },
  852.     { "lf",        XYFA_L, 0 }
  853. };
  854. static int neoltab = (sizeof(eoltab) / sizeof(struct keytab));
  855.  
  856. struct keytab fntab[] = {           /* File naming */
  857.     { "converted", XYFN_C, 0      },
  858.     { "literal",   XYFN_L, 0      },
  859.     { "standard",  XYFN_C, CM_INV }
  860. };
  861. int nfntab = (sizeof(fntab) / sizeof(struct keytab));
  862.  
  863. #ifndef NOLOCAL
  864. /* Terminal parameters table */
  865. static struct keytab trmtab[] = {
  866. #ifdef OS2
  867.     { "answerback",    XYTANS,    0 },
  868. #endif /* OS2 */
  869. #ifdef CK_APC
  870.     { "apc",           XYTAPC,    0 },
  871. #endif /* CK_APC */
  872. #ifdef OS2
  873.     { "arrow-keys",    XYTARR,    0 },
  874. #endif /* OS2 */
  875. #ifdef NT
  876.     { "at",           XYTATTR,   CM_INV|CM_ABR },
  877.     { "att",           XYTATTR,   CM_INV|CM_ABR },
  878.     { "attr",           XYTATTR,   CM_INV|CM_ABR },
  879.     { "attr-bug",      XYTATTBUG, CM_INV },
  880. #endif /* NT */
  881. #ifdef OS2
  882.     { "attribute",     XYTATTR,   0 },
  883. #endif /* OS2 */
  884. #ifdef CK_APC
  885. #ifdef CK_AUTODL
  886.    { "autodownload",   XYTAUTODL, 0, },
  887. #endif /* CK_AUTODL */
  888. #endif /* CK_APC */
  889. #ifdef OS2
  890.     { "autopage",      XYTAPAGE,  0 },
  891.     { "autoscroll",    XYTASCRL,  0 },
  892.     { "bell",          XYTBEL,    CM_INV },
  893. #endif /* OS2 */
  894.     { "bytesize",      XYTBYT,    0 },
  895. #ifndef NOCSETS
  896. #ifndef KUI
  897. #ifdef OS2
  898.     { "character-set", XYTCS,     CM_INV },
  899. #else /* OS2 */
  900.     { "character-set", XYTCS,     0 },
  901. #endif /* OS2 */
  902. #endif /* KUI */
  903. #endif /* NOCSETS */
  904. #ifdef OS2
  905.     { "code-page",     XYTCPG,    0 },
  906.     { "color",         XYTCOL,    0 },
  907.     { "controls",      XYTCTRL,   0 },
  908. #endif /* OS2 */
  909.     { "cr-display",    XYTCRD,    0 },
  910. #ifdef OS2
  911.     { "cursor",        XYTCUR,    0 },
  912. #endif /* OS2 */
  913.     { "debug",         XYTDEB,    0 },
  914. #ifdef OS2
  915.     { "dg-unix-mode",  XYTUNX,    0 },
  916. #endif /* OS2 */
  917.     { "echo",          XYTEC,     0 },
  918.     { "escape-character", XYTESC, 0 },
  919. #ifdef OS2
  920. #ifdef PCFONTS
  921.     { "font",          XYTFON,    0 },
  922. #else
  923. #ifdef KUI
  924.     { "font",          XYTFON,    0 },
  925. #endif /* KUI */
  926. #endif /* PCFONTS */
  927. #endif /* OS2 */
  928.     { "height",        XYTHIG,    0 },
  929. #ifdef CKTIDLE
  930.     { "idle-action",   XYTIACT,   0 },
  931.     { "idle-limit",    XYTITMO,   CM_INV },
  932.     { "idle-send",     XYTIDLE,   CM_INV },
  933.     { "idle-timeout",  XYTITMO,   0 },
  934. #endif /* CKTIDLE */
  935. #ifdef OS2
  936. #ifndef NOCSETS
  937.     { "kbd-follows-gl/gr", XYTKBDGL, 0 },
  938. #endif /* NOCSETS */
  939.     { "key",           XYTKEY,    0 },
  940.     { "keyboard-mode", XYTKBMOD,  0 },
  941.     { "keypad-mode",   XYTKPD,    0 },
  942. #endif /* OS2 */
  943. #ifndef NOCSETS
  944. #ifdef OS2
  945.     { "local-character-set", XYTLCS,  0 },
  946. #else
  947.     { "local-character-set", XYTLCS,  CM_INV },
  948. #endif /* OS2 */
  949. #endif /* NOCSETS */
  950.     { "locking-shift", XYTSO,     0 },
  951. #ifdef OS2
  952.     { "margin-bell",   XYTMBEL,   0 },
  953. #endif /* OS2 */
  954. #ifdef OS2MOUSE
  955.     { "mouse",         XYTMOU,    CM_INV },
  956. #endif /* OS2MOUSE */
  957.     { "newline-mode",  XYTNL,     0 },
  958. #ifdef OS2
  959.     { "output-pacing", XYTPAC,    0 },
  960. #ifdef PCTERM
  961.     { "pcterm",        XYTPCTERM, 0 },
  962. #endif /* PCTERM */
  963. #endif /* OS2 */
  964. #ifdef OS2ORUNIX
  965.     { "print",         XYTPRN,    0 },
  966. #endif /* OS2ORUNIX */
  967. #ifndef NOCSETS
  968. #ifdef OS2
  969.     { "remote-character-set", XYTRCS,  0 },
  970. #else
  971.     { "remote-character-set", XYTRCS,  CM_INV },
  972. #endif /* OS2 */
  973. #endif /* NOCSETS */
  974. #ifdef OS2
  975.     { "roll-mode",       XYTROL, 0 },
  976.     { "s",               XYTUPD, CM_ABR|CM_INV },
  977.     { "sc",              XYTUPD, CM_ABR|CM_INV },
  978.     { "scr",             XYTUPD, CM_ABR|CM_INV },
  979.     { "scree",           XYTUPD, CM_ABR|CM_INV },
  980.     { "screen",          XYTUPD, CM_ABR|CM_INV },
  981.     { "screen-",         XYTUPD, CM_ABR|CM_INV },
  982.     { "screen-mode",     XYTSCNM,   0 },
  983.     { "screen-optimize", XYTOPTI,   0 },
  984.     { "screen-update",   XYTUPD,    0 },
  985.     { "scrollback",      XYSCRS,    0 },
  986.     { "send-data",         XYTSEND, 0 },
  987.     { "send-end-of-block", XYTSEOB, 0 },
  988.     { "sgr-colors",            XYTSGRC,  0 },
  989.     { "sni-ch.code",           XYTSNICC, 0 },
  990.     { "sni-firmware-versions", XYTSNIFV, 0 },
  991.     { "sni-language",          XYTVTLNG, 0 },
  992.     { "sni-pagemode",          XYTSNIPM, CM_INV },
  993.     { "sni-scrollmode",              XYTSNISM, CM_INV },
  994.     { "spacing-attribute-character", XYTSAC,   CM_INV },
  995.     { "statusline",                  XYTSTAT,  0 },
  996.     { "tra",                         XYTCTS,   CM_INV|CM_ABR },
  997.     { "transmit-timeout",            XYTCTS,   0 },
  998. #endif /* OS2 */
  999.  
  1000. #ifdef OS2ORUNIX
  1001.     { "transparent-print", XYTPRN,   CM_INV },
  1002. #endif /* OS2ORUNIX */
  1003.  
  1004. #ifdef CK_TRIGGER
  1005.     { "trigger",           XYTRIGGER,0 },
  1006. #endif /* CK_TRIGGER */
  1007. #ifdef OS2
  1008.     { "type",              XYTTYP,   0 },
  1009. #else
  1010.     { "type",              XYTTYP,   CM_INV },
  1011. #endif /* OS2 */
  1012.  
  1013. #ifndef NOCSETS
  1014. #ifdef UNICODE
  1015. #ifdef CKOUNI
  1016.     { "unicode",           XYTUNI,   CM_INV },
  1017. #endif /* CKOUNI */
  1018. #endif /* UNICODE */
  1019. #endif /* NOCSETS */
  1020. #ifdef OS2
  1021.     { "unix-mode",         XYTUNX,   CM_INV },
  1022.     { "url-highlight",     XYTURLHI, 0 },
  1023. #ifdef NT
  1024.     { "video-change",      XYTVCH,   0 },
  1025. #endif /* NT */
  1026.     { "vt-language",       XYTVTLNG, 0 },
  1027.     { "vt-nrc-mode",       XYTVTNRC, 0 },
  1028. #endif /* OS2 */
  1029.     { "width",             XYTWID,   0 },
  1030. #ifdef OS2
  1031.     { "wrap",              XYTWRP,   0 },
  1032. #endif /* OS2 */
  1033.     { "", 0, 0 }
  1034. };
  1035. int ntrm = (sizeof(trmtab) / sizeof(struct keytab)) - 1;
  1036.  
  1037. #ifdef OS2
  1038. struct keytab termctrl[] = {     /* SET TERM CONTROLS */
  1039.     { "7",     7, 0 },
  1040.     { "8",     8, 0 }
  1041. };
  1042. int ntermctrl = (sizeof(termctrl) / sizeof(struct keytab));
  1043.  
  1044. struct keytab rolltab[] = {   /* Set TERM Roll Options */
  1045.     { "insert",    TTR_INSERT, 0      },
  1046.     { "off",       TTR_OVER,   CM_INV },
  1047.     { "on",        TTR_INSERT, CM_INV },
  1048.     { "overwrite", TTR_OVER,   0      }
  1049. };
  1050. int nroll = (sizeof(rolltab) / sizeof(struct keytab));
  1051.  
  1052. #define TT_GR_ALL 4
  1053. #define TT_GR_G0  0
  1054. #define TT_GR_G1  1
  1055. #define TT_GR_G2  2
  1056. #define TT_GR_G3  3
  1057. #define TT_GR_KBD 4
  1058. struct keytab graphsettab[] = {  /* DEC VT Graphic Sets */
  1059.     { "all",      TT_GR_ALL, 0 },
  1060.     { "g0",       TT_GR_G0,  0 },
  1061.     { "g1",       TT_GR_G1,  0 },
  1062.     { "g2",       TT_GR_G2,  0 },
  1063.     { "g3",       TT_GR_G3,  0 },
  1064.     { "keyboard", TT_GR_KBD, 0 }
  1065. };
  1066. int ngraphset = (sizeof(graphsettab) / sizeof(struct keytab));
  1067. #endif /* OS2 */
  1068.  
  1069. struct keytab adltab[] = {              /* Autodownload Options */
  1070.     { "error",   TAD_ERR, 0 },
  1071. #ifdef OS2
  1072.     { "kermit",  TAD_K,   0 },
  1073. #endif /* OS2 */
  1074.     { "off",     TAD_OFF, 0 },
  1075.     { "on",      TAD_ON,  0 },
  1076. #ifdef OS2
  1077.     { "zmodem",  TAD_Z,   0 },
  1078. #endif /* OS2 */
  1079.     { "", 0, 0 }
  1080. };
  1081. int nadltab = (sizeof(adltab) / sizeof(struct keytab)) - 1;
  1082.  
  1083. struct keytab adlerrtab[] = {        /* Autodownload Error Options */
  1084.     { "continue", 0, 0 },
  1085.     { "go",       0, CM_INV },
  1086.     { "stop",     1, 0 }
  1087. };
  1088. int nadlerrtab = (sizeof(adlerrtab) / sizeof(struct keytab));
  1089.  
  1090. #ifdef OS2
  1091. struct keytab adlxtab[] = {             /* Autodownload Options */
  1092.     { "c0-conflicts",     TAD_X_C0,     0 },
  1093.     { "detection-method", TAD_X_DETECT, 0 },
  1094.     { "string",           TAD_X_STR,    0 }
  1095. };
  1096. int nadlxtab = (sizeof(adlxtab) / sizeof(struct keytab));
  1097.  
  1098. struct keytab adldtab[] = {        /* Auto-dl Detection Methods */
  1099.     { "packet",              ADL_PACK,    0 },
  1100.     { "string",              ADL_STR,    0 }
  1101. };
  1102. int nadldtab = (sizeof(adldtab) / sizeof(struct keytab));
  1103.  
  1104. struct keytab adlc0tab[] = {        /* Auto-dl Detection Methods */
  1105.     { "ignored-by-emulator",    0,    0 },
  1106.     { "processed-by-emulator",    1,    0 }
  1107. };
  1108. int nadlc0tab = (sizeof(adlc0tab) / sizeof(struct keytab));
  1109.  
  1110. #ifndef NOCSETS
  1111. struct keytab vtlangtab[] = {
  1112.     { "belgian",        VTL_BELGIAN , 0 },
  1113.     { "british",        VTL_BRITISH , 0 },
  1114.     { "canadian",       VTL_CANADIAN, 0 },
  1115.     { "czech",          VTL_CZECH   , 0 },
  1116.     { "danish",         VTL_DANISH  , 0 },
  1117.     { "dutch",          VTL_DUTCH   , 0 },
  1118.     { "finnish",        VTL_FINNISH , 0 },
  1119.     { "french",         VTL_FRENCH  , 0 },
  1120.     { "french-canadian",VTL_FR_CAN  , 0 },
  1121.     { "german",         VTL_GERMAN  , 0 },
  1122.     { "greek",          VTL_GREEK   , 0 },
  1123.     { "hebrew",         VTL_HEBREW  , 0 },
  1124.     { "hungarian",      VTL_HUNGARIA, 0 },
  1125.     { "italian",        VTL_ITALIAN , 0 },
  1126.     { "latin-american", VTL_LATIN_AM, 0 },
  1127.     { "north-american", VTL_NORTH_AM, 0 },
  1128.     { "norwegian",      VTL_NORWEGIA, 0 },
  1129.     { "polish",         VTL_POLISH  , 0 },
  1130.     { "portugese",      VTL_PORTUGES, 0 },
  1131.     { "romanian",       VTL_ROMANIAN, 0 },
  1132.     { "russian",        VTL_RUSSIAN , 0 },
  1133.     { "scs",            VTL_SCS     , CM_INV },
  1134.     { "slovak",         VTL_SLOVAK  , 0 },
  1135.     { "spanish",        VTL_SPANISH , 0 },
  1136.     { "swedish",        VTL_SWEDISH , 0 },
  1137.     { "swiss-french",   VTL_SW_FR   , 0 },
  1138.     { "swiss-german",   VTL_SW_GR   , 0 },
  1139.     { "turkish-f",      VTL_TURK_F  , CM_INV },
  1140.     { "turkish-q",      VTL_TURK_Q  , CM_INV }
  1141. };
  1142. int nvtlangtab = (sizeof(vtlangtab) / sizeof(struct keytab));
  1143. #endif /* NOCSETS */
  1144. #endif /* OS2 */
  1145.  
  1146. struct keytab crdtab[] = {        /* Carriage-return display */
  1147.     { "crlf",        1, 0 },
  1148.     { "normal",      0, 0 }
  1149. };
  1150. extern int tt_crd;            /* Carriage-return display variable */
  1151.  
  1152. #ifdef CK_APC
  1153. extern int apcstatus, apcactive;
  1154. static struct keytab apctab[] = {    /* Terminal APC parameters */
  1155.     {  "no-input", APC_ON|APC_NOINP,0 },
  1156.     { "off",       APC_OFF,  0 },
  1157.     { "on",       APC_ON,   0 },
  1158.     { "unchecked", APC_ON|APC_UNCH, 0 },
  1159.     { "unchecked-no-input", APC_ON|APC_NOINP|APC_UNCH, 0 }
  1160. };
  1161. int napctab = (sizeof(apctab) / sizeof(struct keytab));
  1162. #endif /* CK_APC */
  1163. #endif /* NOLOCAL */
  1164.  
  1165. extern int autodl, adl_err;
  1166.  
  1167. struct keytab beltab[] = {        /* Terminal bell mode */
  1168. #ifdef OS2
  1169.     { "audible", XYB_AUD,  0 },
  1170.     { "none",    XYB_NONE, 0 },
  1171. #else
  1172.     { "audible", XYB_AUD,  CM_INV },
  1173.     { "none",    XYB_NONE, CM_INV },
  1174. #endif /* OS2 */
  1175. #ifdef OS2
  1176.     { "off",     XYB_NONE, CM_INV },
  1177.     { "on",      XYB_AUD,  CM_INV },
  1178. #else
  1179.     { "off",     XYB_NONE, 0 },
  1180.     { "on",      XYB_AUD,  0 },
  1181. #endif /* OS2 */
  1182. #ifdef OS2
  1183.     { "visible", XYB_VIS,  0 },
  1184. #endif /* OS2 */
  1185.     { "", 0, 0 }
  1186. };
  1187. int nbeltab = sizeof(beltab)/sizeof(struct keytab) - 1;
  1188.  
  1189. int tt_unicode = 1;            /* Use Unicode if possible */
  1190. #ifdef CKTIDLE
  1191. int tt_idlesnd_tmo = 0;            /* Idle Send Timeout, disabled */
  1192. char * tt_idlesnd_str = NULL;        /* Idle Send String, none */
  1193. char * tt_idlestr = NULL;
  1194. extern int tt_idleact, tt_idlelimit;
  1195. #endif /* CKTIDLE */
  1196.  
  1197. #ifdef OS2
  1198. #ifndef NOLOCAL
  1199. /*
  1200.   OS/2 serial communication devices.
  1201. */
  1202. struct keytab os2devtab[] = {
  1203.     { "1",    1, CM_INV },            /* Invisible synonyms, like */
  1204.     { "2",    2, CM_INV },            /* "set port 1" */
  1205.     { "3",    3, CM_INV },
  1206.     { "4",    4, CM_INV },
  1207.     { "5",    5, CM_INV },
  1208.     { "6",    6, CM_INV },
  1209.     { "7",    7, CM_INV },
  1210.     { "8",    8, CM_INV },
  1211.     { "com1", 1, 0 },            /* Real device names */
  1212.     { "com2", 2, 0 },
  1213.     { "com3", 3, 0 },
  1214.     { "com4", 4, 0 },
  1215.     { "com5", 5, 0 },
  1216.     { "com6", 6, 0 },
  1217.     { "com7", 7, 0 },
  1218.     { "com8", 8, 0 },
  1219. #ifdef OS2ONLY
  1220.     { "slipcom1", 1, 0 },            /* For use with SLIP driver */
  1221.     { "slipcom2", 2, 0 },            /* shared access */
  1222.     { "slipcom3", 3, 0 },
  1223.     { "slipcom4", 4, 0 },
  1224.     { "slipcom5", 5, 0 },
  1225.     { "slipcom6", 6, 0 },
  1226.     { "slipcom7", 7, 0 },
  1227.     { "slipcom8", 8, 0 },
  1228.     { "pppcom1", 1, 0 },            /* For use with PPP driver */
  1229.     { "pppcom2", 2, 0 },            /* shared access */
  1230.     { "pppcom3", 3, 0 },
  1231.     { "pppcom4", 4, 0 },
  1232.     { "pppcom5", 5, 0 },
  1233.     { "pppcom6", 6, 0 },
  1234.     { "pppcom7", 7, 0 },
  1235.     { "pppcom8", 8, 0 }
  1236. #endif /* OS2ONLY */
  1237. };
  1238. int nos2dev = (sizeof(os2devtab) / sizeof(struct keytab)) - 1;
  1239.  
  1240. #ifdef OS2ONLY
  1241. struct keytab os2ppptab[] = {
  1242.     { "0",    0, CM_INV },
  1243.     { "1",    1, CM_INV },            /* Invisible synonyms, like */
  1244.     { "2",    2, CM_INV },            /* "set port 1" */
  1245.     { "3",    3, CM_INV },
  1246.     { "4",    4, CM_INV },
  1247.     { "5",    5, CM_INV },
  1248.     { "6",    6, CM_INV },
  1249.     { "7",    7, CM_INV },
  1250.     { "8",    8, CM_INV },
  1251.     { "9",    9, CM_INV },
  1252.     { "ppp0", 0, 0 },
  1253.     { "ppp1", 1, 0 },            /* For use with PPP driver */
  1254.     { "ppp2", 2, 0 },            /* shared access */
  1255.     { "ppp3", 3, 0 },
  1256.     { "ppp4", 4, 0 },
  1257.     { "ppp5", 5, 0 },
  1258.     { "ppp6", 6, 0 },
  1259.     { "ppp7", 7, 0 },
  1260.     { "ppp8", 8, 0 },
  1261.     { "ppp9", 9, 0 }
  1262. };
  1263. int nos2ppp = (sizeof(os2ppptab) / sizeof(struct keytab));
  1264. #endif /* OS2ONLY */
  1265.  
  1266. /*
  1267.   Terminal parameters that can be set by SET commands.
  1268.   Used by the ck?con.c terminal emulator code.
  1269.   For now, only used for #ifdef OS2.  Should add these for Macintosh.
  1270. */
  1271. int tt_arrow = TTK_NORM;        /* Arrow key mode: normal (cursor) */
  1272. int tt_keypad = TTK_NORM;        /* Keypad mode: normal (numeric) */
  1273. int tt_shift_keypad = 0;             /* Keypad Shift mode: Off */
  1274. int tt_wrap = 1;            /* Terminal wrap, 1 = On */
  1275. int tt_type = TT_VT320;            /* Terminal type, initially VT320 */
  1276. int tt_type_mode = TT_VT320;        /* Terminal type set by host command */
  1277. int tt_cursor = 0;            /* Terminal cursor, 0 = Underline */
  1278. int tt_cursor_usr = 0;            /* Users Terminal cursor type */
  1279. int tt_cursorena_usr = 1;        /* Users Terminal cursor enabled */
  1280. int tt_answer = 0;            /* Terminal answerback (disabled) */
  1281. int tt_scrsize[VNUM] = {512,512,512,1};    /* Terminal scrollback buffer size */
  1282. int tt_roll[VNUM] = {1,1,1,1};        /* Terminal roll (on) */
  1283. int tt_pacing = 0;            /* Terminal output-pacing (none) */
  1284. int tt_ctstmo = 15;            /* Terminal transmit-timeout */
  1285. int tt_codepage = -1;            /* Terminal code-page */
  1286. int tt_update = 100;            /* Terminal screen-update interval */
  1287. int tt_updmode = TTU_FAST;        /* Terminal screen-update mode FAST */
  1288. extern int updmode;
  1289. #ifndef KUI
  1290. int tt_status[VNUM] = {1,1,0,0};    /* Terminal status line displayed */
  1291. int tt_status_usr[VNUM] = {1,1,0,0};
  1292. #else  /* KUI */
  1293. #ifdef K95G
  1294. int tt_status[VNUM] = {1,1,0,0};    /* Terminal status line displayed */
  1295. int tt_status_usr[VNUM] = {1,1,0,0};
  1296. #else /* K95G */
  1297. int tt_status[VNUM] = {0,0,0,0};    /* Terminal status line displayed */
  1298. int tt_status_usr[VNUM] = {0,0,0,0};
  1299. #endif /* K95G */
  1300. #endif /* KUI */
  1301. int tt_senddata = 0;            /* Let host read terminal data */
  1302. extern int wy_blockend;            /* Terminal Send Data EOB type */
  1303. int tt_hidattr = 1;            /* Attributes are hidden */
  1304.  
  1305. extern unsigned char colornormal, colorselect,
  1306. colorunderline, colorstatus, colorhelp, colorborder,
  1307. colorgraphic, colordebug, colorreverse;
  1308.  
  1309. extern int trueblink, trueunderline, truereverse;
  1310.  
  1311. extern int bgi, fgi;
  1312. extern int scrninitialized[];
  1313.  
  1314. struct keytab audibletab[] = {        /* Terminal Bell Audible mode */
  1315.     { "beep",          XYB_BEEP, 0 },    /* Values ORd with bell mode */
  1316.     { "system-sounds", XYB_SYS,  0 }
  1317. };
  1318. int naudibletab = sizeof(audibletab)/sizeof(struct keytab);
  1319.  
  1320. struct keytab akmtab[] = {        /* Arrow key mode */
  1321.     { "application", TTK_APPL, 0 },
  1322.     { "cursor",      TTK_NORM, 0 }
  1323. };
  1324. struct keytab kpmtab[] = {        /* Keypad mode */
  1325.     { "application", TTK_APPL, 0 },
  1326.     { "numeric",     TTK_NORM, 0 }
  1327. };
  1328.  
  1329. struct keytab ttcolmodetab[] = {
  1330.     { "current-color", 0, 0 },
  1331.     { "default-color", 1, 0 }
  1332. };
  1333. int ncolmode = sizeof(ttcolmodetab)/sizeof(struct keytab);
  1334.  
  1335. #define TTCOLNOR  0
  1336. #define TTCOLREV  1
  1337. #define TTCOLUND  2
  1338. #define TTCOLSTA  3
  1339. #define TTCOLHLP  4
  1340. #define TTCOLBOR  5
  1341. #define TTCOLSEL  6
  1342. #define TTCOLDEB  7
  1343. #define TTCOLGRP  8
  1344.  
  1345. #define TTCOLRES  10
  1346. #define TTCOLERA  11
  1347.  
  1348. struct keytab ttycoltab[] = {                /* Terminal Screen coloring */
  1349.     { "border",             TTCOLBOR, 0 },      /* Screen border color */
  1350.     { "debug-terminal",     TTCOLDEB, 0 },      /* Debug color */
  1351.     { "erase",              TTCOLERA, 0 },      /* Erase mode */
  1352.     { "graphic",            TTCOLGRP, 0 },      /* Graphic Color */
  1353.     { "help-text",          TTCOLHLP, 0 },      /* Help screens */
  1354.     { "normal",             TTCOLNOR, CM_INV },    /* Normal screen text */
  1355.     { "reset-on-esc[0m",    TTCOLRES, 0 },      /* Reset on ESC [ 0 m */
  1356.     { "reverse-video",      TTCOLREV, 0 },      /* Reverse video */
  1357.     { "status-line",        TTCOLSTA, 0 },      /* Status line */
  1358.     { "selection",          TTCOLSEL, 0 },      /* Selection color */
  1359.     { "terminal-screen",    TTCOLNOR, 0 },      /* Better name than "normal" */
  1360.     { "underlined-text",    TTCOLUND, 0 }       /* Underlined text */
  1361. };
  1362. int ncolors = (sizeof(ttycoltab) / sizeof(struct keytab));
  1363.  
  1364. #define TTATTNOR  0
  1365. #define TTATTBLI  1
  1366. #define TTATTREV  2
  1367. #define TTATTUND  3
  1368. #define TTATTPRO  4
  1369. #define TTATTBLD  5
  1370. #define TTATTDIM  6
  1371. #define TTATTINV  7
  1372. #define TTATTDONE 8
  1373.  
  1374. struct keytab ttyattrtab[] = {
  1375.     { "blink",     TTATTBLI, 0 },
  1376.     { "protected", TTATTPRO, 0 },
  1377.     { "reverse",   TTATTREV, 0 },
  1378.     { "underline", TTATTUND, 0 }
  1379. };
  1380. int nattrib = (sizeof(ttyattrtab) / sizeof(struct keytab));
  1381.  
  1382. struct keytab ttyprotab[] = {
  1383.     { "blink",       TTATTBLI,  0 },
  1384.     { "bold",        TTATTBLD,  0 },
  1385.     { "dim",         TTATTDIM,  0 },
  1386.     { "done",        TTATTDONE, CM_INV },
  1387.     { "invisible",   TTATTINV,  0 },
  1388.     { "normal",      TTATTNOR,  0 },
  1389.     { "reverse",     TTATTREV,  0 },
  1390.     { "underlined",  TTATTUND,  0 }
  1391.  
  1392. };
  1393. int nprotect = (sizeof(ttyprotab) / sizeof(struct keytab));
  1394.  
  1395. struct keytab ttyseobtab[] = {
  1396.     { "crlf_etx",  1, 0 },
  1397.     { "us_cr",     0, 0 }
  1398. };
  1399.  
  1400. struct keytab ttyclrtab[] = {           /* Colors */
  1401.     { "black",         0, 0      },
  1402.     { "blue",          1, 0      },
  1403.     { "brown",         6, 0      },
  1404.     { "cyan",          3, 0      },
  1405.     { "darkgray",      8, CM_INV },
  1406.     { "dgray",         8, 0      },
  1407.     { "green",         2, 0      },
  1408.     { "lblue",         9, CM_INV },
  1409.     { "lcyan",        11, CM_INV },
  1410.     { "lgray",         7, CM_INV },
  1411.     { "lgreen",       10, CM_INV },
  1412.     { "lightblue",     9, 0      },
  1413.     { "lightcyan",    11, 0      },
  1414.     { "lightgray",     7, 0      },
  1415.     { "lightgreen",   10, 0      },
  1416.     { "lightmagenta", 13, 0      },
  1417.     { "lightred",     12, 0      },
  1418.     { "lmagenta",     13, CM_INV },
  1419.     { "lred",         12, CM_INV },
  1420.     { "magenta",       5, 0      },
  1421.     { "red",           4, 0      },
  1422.     { "white",        15, 0      },
  1423.     { "yellow",       14, 0      }
  1424. };
  1425. int nclrs = (sizeof (ttyclrtab) / sizeof (struct keytab));
  1426.  
  1427. struct keytab ttycurtab[] = {
  1428.     { "full",        TTC_BLOCK, 0 },
  1429.     { "half",        TTC_HALF,  0 },
  1430.     { "underline",   TTC_ULINE, 0 }
  1431. };
  1432. int ncursors = 3;
  1433.  
  1434. struct keytab ttyptab[] = {
  1435.     { "adm3a",    TT_ADM3A,   0 },          /* LSI ADM-3A */
  1436.     { "aixterm",  TT_AIXTERM, 0 },          /* IBM AIXterm */
  1437.     { "ansi-bbs", TT_ANSI,    0 },          /* ANSI.SYS (BBS) */
  1438.     { "at386",    TT_AT386,   0 },          /* Unixware ANSI */
  1439.     { "avatar/0+",TT_ANSI,    0 },          /* AVATAR/0+ */
  1440.     { "ba80",     TT_BA80,    0 },          /* Nixdorf BA80 */
  1441.     { "be",       TT_BEOS,    CM_INV|CM_ABR },
  1442.     { "beos-ansi",TT_BEOS,    CM_INV },     /* BeOS ANSI */
  1443.     { "beterm",   TT_BEOS,    0 },          /* BeOS Terminal (as of PR2 ) */
  1444.     { "d200",     TT_DG200,   CM_INV|CM_ABR }, /* Data General DASHER 200 */
  1445.     { "d210",     TT_DG210,   CM_INV|CM_ABR }, /* Data General DASHER 210 */
  1446.     { "d217",     TT_DG217,   CM_INV|CM_ABR }, /* Data General DASHER 217 */
  1447.     { "dg200",    TT_DG200,   0 },          /* Data General DASHER 200 */
  1448.     { "dg210",    TT_DG210,   0 },          /* Data General DASHER 210 */
  1449.     { "dg217",    TT_DG217,   0 },          /* Data General DASHER 217 */
  1450.     { "h1500",    TT_HZL1500, CM_INV },     /* Hazeltine 1500 */
  1451.     { "h19",      TT_H19,     CM_INV },     /* Heath-19 */
  1452.     { "heath19",  TT_H19,     0 },          /* Heath-19 */
  1453.     { "hft",      TT_HFT,     0 },          /* IBM High Function Terminal */
  1454.     { "hp2621a",  TT_HP2621,  0 },          /* HP 2621A */
  1455.     { "hpterm",   TT_HPTERM,  0 },          /* HP TERM */
  1456.     { "hz1500",   TT_HZL1500, 0 },          /* Hazeltine 1500 */
  1457.     { "ibm3151",  TT_IBM31,   0 },          /* IBM 3101-xx,3161 */
  1458.     { "linux",    TT_LINUX,   0 },          /* Linux */
  1459.     { "qansi",    TT_QANSI,   0 },          /* QNX ANSI */
  1460.     { "qnx",      TT_QNX,     0 },          /* QNX Console */
  1461.     { "scoansi",  TT_SCOANSI, 0 },          /* SCO ANSI */
  1462.     { "sni-97801",TT_97801,   0 },          /* SNI 97801 */
  1463. /*
  1464.   The idea of NONE is to let the console driver handle the escape sequences,
  1465.   which, in theory at least, would give not only ANSI emulation, but also any
  1466.   other kind of emulation that might be provided by alternative console
  1467.   drivers, if any existed.
  1468.  
  1469.   For this to work, ckocon.c would need to be modified to make higher-level
  1470.   calls, like VioWrtTTY(), DosWrite(), or (simply) write(), rather than
  1471.   VioWrt*Cell() and similar, and it would also have to give up its rollback
  1472.   feature, and its status line and help screens would also have to be
  1473.   forgotten or else done in an ANSI way.
  1474.  
  1475.   As matters stand, we already have perfectly good ANSI emulation built in,
  1476.   and there are no alternative console drivers available, so there is no point
  1477.   in having a terminal type of NONE, so it is commented out.  However, should
  1478.   you uncomment it, it will work like a "glass tty" -- no escape sequence
  1479.   interpretation at all; somewhat similar to debug mode, except without the
  1480.   debugging (no highlighting of control chars or escape sequences); help
  1481.   screens, status line, and rollback will still work.
  1482. */
  1483. #ifdef OS2PM
  1484. #ifdef COMMENT
  1485.     { "tek4014", TT_TEK40,  0 },
  1486. #endif /* COMMENT */
  1487. #endif /* OS2PM */
  1488.     { "tty",     TT_NONE,   0 },
  1489.     { "tvi910+", TT_TVI910, 0 },
  1490.     { "tvi925",  TT_TVI925, 0 },
  1491.     { "tvi950",  TT_TVI950, 0 },
  1492.     { "vc404",   TT_VC4404, 0 },
  1493.     { "vc4404",  TT_VC4404, CM_INV },
  1494.     { "vip7809", TT_VIP7809,0 },
  1495.     { "vt100",   TT_VT100,  0 },
  1496.     { "vt102",   TT_VT102,  0 },
  1497.     { "vt220",   TT_VT220,  0 },
  1498.     { "vt220pc", TT_VT220PC,0 },
  1499.     { "vt320",   TT_VT320,  0 },
  1500.     { "vt320pc", TT_VT320PC,0 },
  1501.     { "vt52",    TT_VT52,   0 },
  1502. #ifdef NT
  1503.     { "vtnt",    TT_VTNT,   0 },
  1504. #else /* NT */
  1505.     { "vtnt",    TT_VTNT,  CM_INV },
  1506. #endif /* NT */
  1507.     { "wy160",   TT_WY160,  0 },
  1508.     { "wy30",    TT_WY30,   0 },
  1509.     { "wy370",   TT_WY370,  0 },
  1510.     { "wy50",    TT_WY50,   0 },
  1511.     { "wy60",    TT_WY60,   0 },
  1512.     { "wyse30",  TT_WY30,   CM_INV },
  1513.     { "wyse370", TT_WY370,  CM_INV },
  1514.     { "wyse50",  TT_WY50,   CM_INV },
  1515.     { "wyse60",  TT_WY60,   CM_INV }
  1516. };
  1517. int nttyp = (sizeof(ttyptab) / sizeof(struct keytab));
  1518.  
  1519. struct keytab ttkeytab[] = {
  1520.     { "adm3a",     TT_ADM3A,      0 },             /* LSI ADM-3A */
  1521.     { "aixterm",   TT_AIXTERM,    0 },             /* IBM AIXterm */
  1522.     { "ansi-bbs",  TT_ANSI,       0 },             /* ANSI.SYS (BBS) */
  1523.     { "at386",     TT_AT386,      0 },             /* Unixware ANSI */
  1524.     { "avatar/0+", TT_ANSI,       0 },             /* AVATAR/0+ */
  1525.     { "ba80",      TT_BA80,       0 },             /* Nixdorf BA80 */
  1526.     { "be",        TT_BEOS,       CM_INV|CM_ABR },
  1527.     { "beos-ansi", TT_BEOS,       CM_INV },        /* BeOS ANSI */
  1528.     { "beterm",    TT_BEOS,       0 },             /* BeOS Terminal (DR2) */
  1529.     { "d200",      TT_DG200,      CM_INV|CM_ABR }, /* DG DASHER 200 */
  1530.     { "d210",      TT_DG210,      CM_INV|CM_ABR }, /* DG DASHER 210 */
  1531.     { "d217",      TT_DG217,      CM_INV|CM_ABR }, /* DG DASHER 217 */
  1532.     { "dg200",     TT_DG200,      0 },             /* DG DASHER 200 */
  1533.     { "dg210",     TT_DG210,      0 },             /* DG DASHER 210 */
  1534.     { "dg217",     TT_DG217,      0 },             /* DG DASHER 217 */
  1535.     { "emacs",     TT_KBM_EMACS,  0 },             /* Emacs mode */
  1536.     { "h19",       TT_H19,        CM_INV },        /* Heath-19 */
  1537.     { "heath19",   TT_H19,        0 },             /* Heath-19 */
  1538.     { "hebrew",    TT_KBM_HEBREW, 0 },             /* Hebrew mode */
  1539.     { "hft",       TT_HFT,        0 },             /* IBM High Function Term */
  1540.     { "hp2621a",   TT_HP2621,     0 },             /* HP 2621A */
  1541.     { "hpterm",    TT_HPTERM,     0 },             /* HP TERM */
  1542.     { "hz1500",    TT_HZL1500,    0 },             /* Hazeltine 1500 */
  1543.     { "ibm3151",   TT_IBM31,      0 },             /* IBM 3101-xx,3161 */
  1544.     { "linux",     TT_LINUX,      0 },             /* Linux */
  1545.     { "qansi",     TT_QANSI,      0 },             /* QNX ANSI */
  1546.     { "qnx",       TT_QNX,        0 },             /* QNX */
  1547.     { "russian",   TT_KBM_RUSSIAN,0 },             /* Russian mode */
  1548.     { "scoansi",   TT_SCOANSI,    0 },             /* SCO ANSI */
  1549.     { "sni-97801", TT_97801,      0 },             /* SNI 97801 */
  1550. #ifdef OS2PM
  1551. #ifdef COMMENT
  1552.     { "tek4014",   TT_TEK40,      0 },
  1553. #endif /* COMMENT */
  1554. #endif /* OS2PM */
  1555.     { "tty",       TT_NONE,       0 },
  1556.     { "tvi910+",   TT_TVI910,     0 },
  1557.     { "tvi925",    TT_TVI925,     0 },
  1558.     { "tvi950",    TT_TVI950,     0 },
  1559.     { "vc404",     TT_VC4404,     0 },
  1560.     { "vc4404",    TT_VC4404,     CM_INV },
  1561.     { "vip7809",   TT_VIP7809,    0 },
  1562.     { "vt100",     TT_VT100,      0 },
  1563.     { "vt102",     TT_VT102,      0 },
  1564.     { "vt220",     TT_VT220,      0 },
  1565.     { "vt220pc",   TT_VT220PC,    0 },
  1566.     { "vt320",     TT_VT320,      0 },
  1567.     { "vt320pc",   TT_VT320PC,    0 },
  1568.     { "vt52",      TT_VT52,       0 },
  1569.     { "vtnt",      TT_VTNT,       CM_INV },
  1570.     { "wp",        TT_KBM_WP,     0 },             /* Word Perfect mode */
  1571.     { "wy160",     TT_WY160,      0 },
  1572.     { "wy30",      TT_WY30,       0 },
  1573.     { "wy370",     TT_WY370,      0 },
  1574.     { "wy50",      TT_WY50,       0 },
  1575.     { "wy60",      TT_WY60,       0 },
  1576.     { "wyse30",    TT_WY30,       CM_INV },
  1577.     { "wyse370",   TT_WY370,      CM_INV },
  1578.     { "wyse50",    TT_WY50,       CM_INV },
  1579.     { "wyse60",    TT_WY60,       CM_INV }
  1580. };
  1581. int nttkey = (sizeof(ttkeytab) / sizeof(struct keytab));
  1582.  
  1583. #ifndef NOSETKEY
  1584. struct keytab kbmodtab[] = {
  1585.     { "emacs",   KBM_EM, 0      },
  1586.     { "english", KBM_EN, CM_INV },
  1587.     { "hebrew",  KBM_HE, 0      },
  1588.     { "normal",  KBM_EN, 0      },
  1589.     { "none",    KBM_EN, CM_INV },
  1590.     { "russian", KBM_RU, 0      },
  1591.     { "wp",      KBM_WP, 0      }
  1592. };
  1593. int nkbmodtab = (sizeof(kbmodtab) / sizeof(struct keytab));
  1594. #endif /* NOSETKEY */
  1595. #endif /* NOLOCAL */
  1596.  
  1597. int tt_inpacing = 0;                    /* input-pacing (none) */
  1598.  
  1599. struct keytab prtytab[] = { /* OS/2 Priority Levels */
  1600.     { "foreground-server", XYP_SRV, 0       },
  1601.     { "idle",              XYP_IDLE, CM_INV },
  1602.     { "regular",           XYP_REG, 0       },
  1603.     { "time-critical",     XYP_RTP, 0       }
  1604. };
  1605. int nprty = (sizeof(prtytab) / sizeof(struct keytab));
  1606. #endif /* OS2 */
  1607.  
  1608. #ifdef NT
  1609. struct keytab win95tab[] = { /* Win95 work-arounds */
  1610.     { "8.3-filenames",         XYW8_3,    0 },
  1611.     { "alt-gr",                XYWAGR,    0 },
  1612.     { "keyboard-translation",  XYWKEY,    0 },
  1613.     { "lucida-substitutions",  XYWLUC,    0 },
  1614.     { "overlapped-io",         XYWOIO,    0 },
  1615.     { "popups",                XYWPOPUP,  0 },
  1616.     { "select-bug",            XYWSELECT, 0 }
  1617. };
  1618. int nwin95 = (sizeof(win95tab) / sizeof(struct keytab));
  1619. #endif /* NT */
  1620.  
  1621. #ifdef OS2MOUSE
  1622. extern int wideresult;
  1623. int tt_mouse = 1;                       /* Terminal mouse on/off */
  1624.  
  1625. struct keytab mousetab[] = {            /* Mouse items */
  1626.     { "activate", XYM_ON,     0 },
  1627.     { "button",   XYM_BUTTON, 0 },
  1628.     { "clear",    XYM_CLEAR,  0 },
  1629.     { "debug",    XYM_DEBUG,  0 }
  1630. };
  1631. int nmtab = (sizeof(mousetab)/sizeof(struct keytab));
  1632.  
  1633. struct keytab mousebuttontab[] = {      /* event button */
  1634.     { "1",             XYM_B1, 0 },
  1635.     { "2",             XYM_B2, 0 },
  1636.     { "3",             XYM_B3, 0 },
  1637.     { "one",           XYM_B1, CM_INV },
  1638.     { "three",         XYM_B3, CM_INV },
  1639.     { "two",           XYM_B2, CM_INV }
  1640. };
  1641. int nmbtab = (sizeof(mousebuttontab) / sizeof(struct keytab));
  1642.  
  1643. struct keytab mousemodtab[] = {         /* event button key modifier */
  1644.     { "alt",              XYM_ALT,   0 },
  1645.     { "alt-shift",        XYM_SHIFT|XYM_ALT, 0 },
  1646.     { "ctrl",             XYM_CTRL,  0 },
  1647.     { "ctrl-alt",         XYM_CTRL|XYM_ALT, 0 },
  1648.     { "ctrl-alt-shift",   XYM_CTRL|XYM_SHIFT|XYM_ALT, 0 },
  1649.     { "ctrl-shift",       XYM_CTRL|XYM_SHIFT, 0 },
  1650.     { "none",             0, 0 },
  1651.     { "shift",            XYM_SHIFT, 0 }
  1652. };
  1653. int nmmtab = (sizeof(mousemodtab) / sizeof(struct keytab));
  1654.  
  1655. struct keytab mclicktab[] = {           /* event button click modifier */
  1656.     { "click",        XYM_C1,   0 },
  1657.     { "drag",         XYM_DRAG, 0 },
  1658.     { "double-click", XYM_C2,   0 }
  1659. };
  1660. int nmctab = (sizeof(mclicktab) / sizeof(struct keytab));
  1661.  
  1662. #ifndef NOKVERBS
  1663. extern int nkverbs;
  1664. extern struct keytab kverbs[];
  1665. #endif /* NOKVERBS */
  1666. #endif /* OS2MOUSE */
  1667.  
  1668. /* #ifdef VMS */
  1669. struct keytab fbtab[] = {               /* Binary record types for VMS */
  1670.     { "fixed",     XYFT_B, 0 },        /* Fixed is normal for binary */
  1671.     { "undefined", XYFT_U, 0 }          /* Undefined if they ask for it */
  1672. };
  1673. int nfbtyp = (sizeof(fbtab) / sizeof(struct keytab));
  1674. /* #endif */
  1675.  
  1676. #ifdef VMS
  1677. struct keytab lbltab[] = {              /* Labeled File info */
  1678.     { "acl",         LBL_ACL, 0 },
  1679.     { "backup-date", LBL_BCK, 0 },
  1680.     { "name",        LBL_NAM, 0 },
  1681.     { "owner",       LBL_OWN, 0 },
  1682.     { "path",        LBL_PTH, 0 }
  1683. };
  1684. int nlblp = (sizeof(lbltab) / sizeof(struct keytab));
  1685. #else
  1686. #ifdef OS2
  1687. struct keytab lbltab[] = {              /* Labeled File info */
  1688.     { "archive",   LBL_ARC, 0 },
  1689.     { "extended",  LBL_EXT, 0 },
  1690.     { "hidden",    LBL_HID, 0 },
  1691.     { "read-only", LBL_RO,  0 },
  1692.     { "system",    LBL_SYS, 0 }
  1693. };
  1694. int nlblp = (sizeof(lbltab) / sizeof(struct keytab));
  1695. #endif /* OS2 */
  1696. #endif /* VMS */
  1697.  
  1698. #ifdef CK_CURSES
  1699. #ifdef CK_PCT_BAR
  1700. static struct keytab fdftab[] = {       /* SET FILE DISPLAY FULL options */
  1701.     { "thermometer",    1, 0, },
  1702.     { "no-thermometer", 0, 0  }
  1703. };
  1704. extern int thermometer;
  1705. #endif /* CK_PCT_BAR */
  1706. #endif /* CK_CURSES */
  1707.  
  1708. static struct keytab fdtab[] = {        /* SET FILE DISPLAY options */
  1709. #ifdef MAC                              /* Macintosh */
  1710.     { "fullscreen", XYFD_R,      0 },    /* Full-screen but not curses */
  1711.     { "none",       XYFD_N,      0 },
  1712.     { "off",        XYFD_N, CM_INV },
  1713.     { "on",         XYFD_R, CM_INV },
  1714.     { "quiet",      XYFD_N, CM_INV },
  1715. #else                                   /* Not Mac */
  1716.     { "brief", XYFD_B, 0 },        /* Brief */
  1717.     { "crt", XYFD_S, 0 },        /* CRT display */
  1718. #ifdef CK_CURSES
  1719. #ifdef COMMENT
  1720.     { "curses",     XYFD_C,  CM_INV },    /* Full-screen, curses */
  1721. #endif /* COMMENT */
  1722.     { "fullscreen", XYFD_C,  0 },    /* Full-screen, whatever the method */
  1723. #endif /* CK_CURSES */
  1724.     { "none",   XYFD_N, 0      },    /* No display */
  1725.     { "off",    XYFD_N, CM_INV },    /* Ditto */
  1726.     { "on",     XYFD_R, CM_INV },    /* On = Serial */
  1727.     { "quiet",  XYFD_N, CM_INV },    /* No display */
  1728.     { "serial", XYFD_R, 0      },    /* Serial */
  1729. #endif /* MAC */
  1730.     { "", 0, 0 }
  1731. };
  1732. int nfdtab = (sizeof(fdtab) / sizeof(struct keytab)) - 1;
  1733.  
  1734. struct keytab rsrtab[] = {              /* For REMOTE SET RECEIVE */
  1735.     { "packet-length", XYLEN,  0 },
  1736.     { "timeout",       XYTIMO, 0 }
  1737. };
  1738. int nrsrtab = (sizeof(rsrtab) / sizeof(struct keytab));
  1739.  
  1740. /* Send/Receive Parameters */
  1741.  
  1742. struct keytab srtab[] = {
  1743.     { "backup", XYBUP, 0 },
  1744. #ifndef NOCSETS
  1745.     { "character-set-selection", XYCSET, 0 },
  1746. #endif /* NOCSETS */
  1747.     { "control-prefix", XYQCTL, 0 },
  1748. #ifdef CKXXCHAR
  1749.     { "double-character", XYDBL, 0 },
  1750. #endif /* CKXXCHAR */
  1751.     { "end-of-packet", XYEOL, 0 },
  1752. #ifdef PIPESEND
  1753.     { "filter", XYFLTR, 0 },
  1754. #endif /* PIPESEND */
  1755. #ifdef CKXXCHAR
  1756.     { "ignore-character", XYIGN, 0 },
  1757. #endif /* CKXXCHAR */
  1758.     { "i-packets", 993, 0 },
  1759.     { "move-to", XYMOVE, 0 },
  1760.     { "negotiation-string-max-length", XYINIL, CM_INV },
  1761.     { "packet-length", XYLEN, 0 },
  1762.     { "pad-character", XYPADC, 0 },
  1763.     { "padding", XYNPAD, 0 },
  1764.     { "pathnames", XYFPATH, 0 },
  1765.     { "pause", XYPAUS, 0 },
  1766.     { "quote", XYQCTL, CM_INV },    /* = CONTROL-PREFIX */
  1767.     { "rename-to", XYRENAME, 0 },
  1768.     { "start-of-packet", XYMARK, 0 },
  1769.     { "timeout", XYTIMO, 0 },
  1770. #ifdef VMS
  1771.     { "version-numbers", 887, 0 },    /* VMS version numbers */
  1772. #endif /* VMS */
  1773.     { "", 0, 0 }
  1774. };
  1775. int nsrtab = (sizeof(srtab) / sizeof(struct keytab)) - 1;
  1776.  
  1777. #ifdef UNICODE
  1778. #define UCS_BOM 1
  1779. #define UCS_BYT 2
  1780. static struct keytab ucstab[] = {
  1781.     { "bom",        UCS_BOM, 0 },
  1782.     { "byte-order", UCS_BYT, 0 },
  1783.     { "", 0, 0 }
  1784. };
  1785. int nucstab = (sizeof(ucstab) / sizeof(struct keytab)) - 1;
  1786.  
  1787. static struct keytab botab[] = {
  1788.     { "big-endian",    0, 0 },
  1789.     { "little-endian", 1, 0 }
  1790. };
  1791. static int nbotab = 2;
  1792. #endif /* UNICODE */
  1793.  
  1794. /* REMOTE SET */
  1795.  
  1796. struct keytab rmstab[] = {
  1797.     { "attributes",  XYATTR, 0      },
  1798.     { "block-check", XYCHKT, 0      },
  1799.     { "file",        XYFILE, 0      },
  1800.     { "incomplete",  XYIFD,  CM_INV },    /* = REMOTE SET FILE INCOMPLETE */
  1801.     { "receive",     XYRECV, 0      },
  1802.     { "retry",       XYRETR, 0      },
  1803.     { "server",      XYSERV, 0      },
  1804.     { "transfer",    XYXFER, 0      },
  1805.     { "window",      XYWIND, 0      },
  1806.     { "xfer",        XYXFER, CM_INV }
  1807. };
  1808. int nrms = (sizeof(rmstab) / sizeof(struct keytab));
  1809.  
  1810. struct keytab attrtab[] = {
  1811. #ifdef STRATUS
  1812.     { "account",       AT_ACCT, 0 },
  1813. #endif /* STRATUS */
  1814.     { "all",           AT_XALL, 0 },
  1815. #ifdef COMMENT
  1816.     { "blocksize",     AT_BLKS, 0 },    /* (not used) */
  1817. #endif /* COMMENT */
  1818. #ifndef NOCSETS
  1819.     { "character-set", AT_ENCO, 0 },
  1820. #endif /* NOCSETS */
  1821. #ifdef STRATUS
  1822.     { "creator",       AT_CREA, 0 },
  1823. #endif /* STRATUS */
  1824.     { "date",          AT_DATE, 0 },
  1825.     { "disposition",   AT_DISP, 0 },
  1826.     { "encoding",      AT_ENCO, CM_INV },
  1827.     { "format",        AT_RECF, CM_INV },
  1828.     { "length",        AT_LENK, 0 },
  1829.     { "off",           AT_ALLN, 0 },
  1830.     { "on",            AT_ALLY, 0 },
  1831. #ifdef COMMENT
  1832.     { "os-specific",   AT_SYSP, 0 },    /* (not used by UNIX or VMS) */
  1833. #endif /* COMMENT */
  1834. #ifdef CK_PERMS
  1835.     { "protection",    AT_LPRO, 0 },
  1836.     { "permissions",   AT_LPRO, CM_INV },
  1837. #endif /* CK_PERMS */
  1838.     { "record-format", AT_RECF, 0 },
  1839.     { "system-id",     AT_SYSI, 0 },
  1840.     { "type",          AT_FTYP, 0 }
  1841. };
  1842. int natr = (sizeof(attrtab) / sizeof(struct keytab)); /* how many attributes */
  1843.  
  1844. #ifdef CKTIDLE
  1845. struct keytab idlacts[] = {
  1846.     { "exit",       IDLE_EXIT, 0 },
  1847.     { "hangup",     IDLE_HANG, 0 },
  1848.     { "output",     IDLE_OUT,  0 },
  1849.     { "return",     IDLE_RET,  0 },
  1850. #ifdef TNCODE
  1851.     { "telnet-nop", IDLE_TNOP, 0 },
  1852.     { "telnet-ayt", IDLE_TAYT, 0 },
  1853. #endif /* TNCODE */
  1854.     { "", 0, 0 }
  1855. };
  1856. int nidlacts = (sizeof(idlacts) / sizeof(struct keytab)) - 1;
  1857. #endif /* CKTIDLE */
  1858.  
  1859. #ifndef NOSPL
  1860. extern int indef, inecho, insilence, inbufsize, inautodl, inintr;
  1861. extern char * inpbuf, * inpbp;
  1862. #ifdef OS2
  1863. extern int interm;
  1864. #endif /* OS2 */
  1865. struct keytab inptab[] = {        /* SET INPUT parameters */
  1866. #ifdef CK_AUTODL
  1867.     { "autodownload",    IN_ADL, 0 },
  1868. #endif /* CK_AUTODL */
  1869.     { "buffer-length",   IN_BUF, 0 },
  1870.     { "cancellation",    IN_CAN, 0 },
  1871.     { "case",            IN_CAS, 0 },
  1872.     { "default-timeout", IN_DEF, CM_INV }, /* There is no default timeout */
  1873.     { "echo",            IN_ECH, 0 },
  1874. #ifdef OS2
  1875.     { "pacing",          IN_PAC, CM_INV },
  1876. #endif /* OS2 */
  1877.     { "silence",         IN_SIL, 0 },
  1878. #ifdef OS2
  1879.     { "terminal",        IN_TRM, 0 },
  1880. #endif /* OS2 */
  1881.     { "timeout-action",  IN_TIM, 0 }
  1882. };
  1883. int ninp = (sizeof(inptab) / sizeof(struct keytab));
  1884.  
  1885. struct keytab intimt[] = {        /* SET INPUT TIMEOUT parameters */
  1886.     { "proceed", 0, 0 },        /* 0 = proceed */
  1887.     { "quit",    1, 0 }            /* 1 = quit */
  1888. };
  1889.  
  1890. struct keytab incast[] = {        /* SET INPUT CASE parameters */
  1891.     { "ignore",  0, 0 },        /* 0 = ignore */
  1892.     { "observe", 1, 0 }            /* 1 = observe */
  1893. };
  1894. #endif /* NOSPL */
  1895.  
  1896. struct keytab nabltab[] = {        /* For any command that needs */
  1897.     { "disabled", 0, 0 },
  1898.     { "enabled",  1, 0 },
  1899.     { "off",      0, CM_INV },        /* these keywords... */
  1900.     { "on",       1, CM_INV }
  1901. };
  1902. int nnabltab = sizeof(nabltab) / sizeof(struct keytab);
  1903.  
  1904. #ifdef OS2
  1905. struct keytab tvctab[] = {        /* SET TERM VIDEO-CHANGE */
  1906.     { "disabled",     TVC_DIS, 0 },
  1907.     { "enabled",      TVC_ENA, 0 },
  1908. #ifdef NT
  1909.     { "win95-safe",   TVC_W95, 0 },
  1910. #endif /* NT */
  1911.     { "", 0, 0 }
  1912. };
  1913. int ntvctab = (sizeof(tvctab) / sizeof(struct keytab)) - 1;
  1914.  
  1915. struct keytab msktab[] = { /* SET MS-DOS KERMIT compatibilities */
  1916. #ifdef COMMENT
  1917.     { "color",    MSK_COLOR,  0 },
  1918. #endif /* COMMENT */
  1919.     { "keycodes", MSK_KEYS,   0 }
  1920. };
  1921. int nmsk = (sizeof(msktab) / sizeof(struct keytab));
  1922.  
  1923. struct keytab scrnupd[] = {        /* SET TERMINAL SCREEN-UPDATE */
  1924.     { "fast",   TTU_FAST,   0 },
  1925.     { "smooth", TTU_SMOOTH, 0 }
  1926. };
  1927. int nscrnupd = (sizeof(scrnupd) / sizeof(struct keytab));
  1928.  
  1929. #ifdef PCFONTS
  1930. /* This definition of the term_font[] table is only for     */
  1931. /* the OS/2 Full Screen Session and is not used on Windows */
  1932. struct keytab term_font[] = {        /* SET TERMINAL FONT */
  1933. #ifdef COMMENT
  1934.     { "cp111", TTF_111, 0 },
  1935.     { "cp112", TTF_112, 0 },
  1936.     { "cp113", TTF_113, 0 },
  1937. #endif /* COMMENT */
  1938.     { "cp437", TTF_437, 0 },
  1939.     { "cp850", TTF_850, 0 },
  1940. #ifdef COMMENT
  1941.     { "cp851", TTF_851, 0 },
  1942. #endif /* COMMENT */
  1943.     { "cp852", TTF_852, 0 },
  1944. #ifdef COMMENT
  1945.     { "cp853", TTF_853, 0 },
  1946.     { "cp860", TTF_860, 0 },
  1947.     { "cp861", TTF_861, 0 },
  1948. #endif /* COMMENT */
  1949.     { "cp862", TTF_862, 0 },
  1950. #ifdef COMMENT
  1951.     { "cp863", TTF_863, 0 },
  1952.     { "cp864", TTF_864, 0 },
  1953.     { "cp865", TTF_865, 0 },
  1954. #endif /* COMMENT */
  1955.     { "cp866", TTF_866, 0 },
  1956. #ifdef COMMENT
  1957.     { "cp880", TTF_880, 0 },
  1958.     { "cp881", TTF_881, 0 },
  1959.     { "cp882", TTF_882, 0 },
  1960.     { "cp883", TTF_883, 0 },
  1961.     { "cp884", TTF_884, 0 },
  1962.     { "cp885", TTF_885, 0 },
  1963. #endif /* COMMENT */
  1964.     { "default",TTF_ROM,0 }
  1965. };
  1966. int ntermfont = (sizeof(term_font) / sizeof(struct keytab));
  1967. int tt_font = TTF_ROM;            /* Terminal screen font */
  1968. #else /* PCFONTS */
  1969. #ifdef NT
  1970. #ifdef KUI
  1971. struct keytab * term_font = NULL;
  1972. struct keytab * _term_font = NULL;
  1973. int ntermfont = 0;
  1974. int tt_font = 0;
  1975. int tt_font_size = 0;
  1976. #endif /* KUI */
  1977. #endif /* NT */
  1978. #endif /* PCFONTS */
  1979.  
  1980. struct keytab anbktab[] = {        /* For any command that needs */
  1981.     { "message", 2, 0 },        /* these keywords... */
  1982.     { "off",     0, 0 },
  1983.     { "on",      1, 0 },
  1984.     { "unsafe-messag0", 99, CM_INV },
  1985.     { "unsafe-message", 3,  CM_INV }
  1986. };
  1987. int nansbk = (sizeof(anbktab) / sizeof(struct keytab));
  1988.  
  1989. int win95_popup = 1;
  1990. #ifdef NT
  1991. int win95altgr  = 0;
  1992. #ifdef KUI
  1993. int win95lucida = 0;
  1994. #else /* KUI */
  1995. int win95lucida = 1;
  1996. #endif /* KUI */
  1997. extern int win95selectbug;
  1998. extern int win95_8_3;
  1999.  
  2000. #ifdef COMMENT
  2001. extern CHAR (*xlr[MAXTCSETS+1][MAXFCSETS+1])(CHAR);
  2002. extern struct keytab tcstab[];
  2003. extern int ntcs;
  2004. #endif /* COMMENT */
  2005. extern int maxow, maxow_usr; owwait;    /* Overlapped I/O variables */
  2006. #endif /* NT */
  2007. #endif /* OS2 */
  2008.  
  2009.  
  2010. /* The following routines broken out of doprm() to give compilers a break. */
  2011.  
  2012. /*  S E T O N  --  Parse on/off (default on), set parameter to result  */
  2013.  
  2014. int
  2015. seton(prm) int *prm; {
  2016.     int x, y;
  2017.     if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  2018.     if ((x = cmcfm()) < 0) return(x);
  2019.     *prm = y;
  2020.     return(1);
  2021. }
  2022.  
  2023. /*  S E T O N A U T O --  Parse on/off/auto (default auto) & set result */
  2024.  
  2025. struct keytab onoffaut[] = {
  2026.     { "auto", SET_AUTO, 0 },        /* 2 */
  2027.     { "off",  SET_OFF,  0 },        /* 0 */
  2028.     { "on",   SET_ON,   0 }        /* 1 */
  2029. };
  2030.  
  2031. int
  2032. setonaut(prm) int *prm; {
  2033.     int x, y;
  2034.     if ((y = cmkey(onoffaut,3,"","auto",xxstring)) < 0) return(y);
  2035.     if ((x = cmcfm()) < 0) return(x);
  2036.     *prm = y;
  2037.     return(1);
  2038. }
  2039.  
  2040. /*  S E T N U M  --  Set parameter to result of cmnum() parse.  */
  2041. /*
  2042.  Call with pointer to integer variable to be set,
  2043.    x = number from cnum parse, y = return code from cmnum,
  2044.    max = maximum value to accept, -1 if no maximum.
  2045.  Returns -9 on failure, after printing a message, or 1 on success.
  2046. */
  2047. int
  2048. setnum(prm,x,y,max) int x, y, *prm, max; {
  2049.     debug(F101,"setnum","",y);
  2050.     if (y == -3) {
  2051.     printf("\n?Value required\n");
  2052.     return(-9);
  2053.     }
  2054.     if (y == -2) {
  2055.     printf("%s?Not a number: %s\n",cmflgs == 1 ? "" : "\n", atxbuf);
  2056.     return(-9);
  2057.     }
  2058.     if (y < 0) return(y);
  2059.     if (max > -1 && x > max) {
  2060.     printf("?Sorry, %d is the maximum\n",max);
  2061.     return(-9);
  2062.     }
  2063.     if ((y = cmcfm()) < 0) return(y);
  2064.     *prm = x;
  2065.     return(1);
  2066. }
  2067.  
  2068. /*  S E T C C  --  Set parameter var to an ASCII control character value.  */
  2069. /*
  2070.   Parses a number, or a literal control character, or a caret (^) followed
  2071.   by an ASCII character whose value is 63-95 or 97-122, then gets confirmation,
  2072.   then sets the parameter to the code value of the character given.  If there
  2073.   are any parse errors, they are returned, otherwise on success 1 is returned.
  2074. */
  2075. int
  2076. setcc(dflt,var) char *dflt; int *var; {
  2077.     int x, y;
  2078.     unsigned int c;
  2079.     char *hlpmsg = "Control character,\n\
  2080.  numeric ASCII value,\n\
  2081.  or in ^X notation,\n\
  2082.  or preceded by a backslash and entered literally";
  2083.  
  2084.     /* This is a hack to turn off complaints from expression evaluator. */
  2085.     x_ifnum = 1;
  2086.     y = cmnum(hlpmsg, dflt, 10, &x, xxstring); /* Parse a number */
  2087.     x_ifnum = 0;                   /* Allow complaints again */
  2088.     if (y < 0) {            /* Parse failed */
  2089.     if (y != -2)            /* Reparse needed or somesuch */
  2090.       return(y);            /* Pass failure back up the chain */
  2091.     }
  2092.     /* Did they type a real control character? */
  2093.  
  2094.     for (c = strlen(atmbuf) - 1; c > 0; c--) /* Trim */
  2095.       if (atmbuf[c] == SP) atmbuf[c] = NUL;
  2096.  
  2097.     if (y < 0) {            /* It was not a number */
  2098.     if ((c = atmbuf[0]) && !atmbuf[1]) { /* Was it a literal Ctrl char? */
  2099.         if ((c > 037) && (c != 0177)) {
  2100.         printf("\n?Not a control character - %d\n",c);
  2101.         return(-9);
  2102.         } else {
  2103.         if ((y = cmcfm()) < 0)    /* Confirm */
  2104.           return(y);
  2105.         *var = c;        /* Set the variable */
  2106.         return(1);
  2107.         }
  2108.     } else if (atmbuf[0] == '^' && !atmbuf[2]) { /* Or ^X notation? */
  2109.         c = atmbuf[1];
  2110.         if (islower((char) c))    /* Uppercase lowercase letters */
  2111.           c = toupper(c);
  2112.         if (c > 62 && c < 96) {    /* Check range */
  2113.         if ((y = cmcfm()) < 0)
  2114.           return(y);
  2115.         *var = ctl(c);        /* OK */
  2116.         return(1);
  2117.         } else {
  2118.         printf("?Not a control character - %s\n", atmbuf);
  2119.         return(-9);
  2120.         }
  2121.     } else {            /* Something illegal was typed */
  2122.         printf("?Invalid - %s\n", atmbuf);
  2123.         return(-9);
  2124.     }
  2125.     }
  2126.     if ((x > 037) && (x != 0177)) {    /* They typed a number */
  2127.     printf("\n?Not in ASCII control range - %d\n",x);
  2128.     return(-9);
  2129.     }
  2130.     if ((y = cmcfm()) < 0)        /* In range, confirm */
  2131.       return(y);
  2132.     *var = x;                /* Set variable */
  2133.     return(1);
  2134. }
  2135.  
  2136. #ifndef NOSPL                /* The SORT command... */
  2137.  
  2138. static struct keytab srtswtab[] = {    /* SORT command switches */
  2139.     { "/case",    SRT_CAS, CM_ARG },
  2140.     { "/key",     SRT_KEY, CM_ARG },
  2141.     { "/numeric", SRT_NUM, 0 },
  2142.     { "/range",   SRT_RNG, CM_ARG },
  2143.     { "/reverse", SRT_REV, 0 }
  2144. };
  2145. static int nsrtswtab = sizeof(srtswtab)/sizeof(struct keytab);
  2146.  
  2147. extern char **a_ptr[];            /* Array pointers */
  2148. extern int a_dim[];            /* Array dimensions */
  2149.  
  2150. int
  2151. dosort() {                /* Do the SORT command */
  2152.     char c, *p = NULL, ** ap, ** xp = NULL;
  2153.     struct FDB sw, fl, cm;
  2154.     int hi, lo;
  2155.     int xn = 0, xr = -1, xk = -1, xc = -1, xs = 0;
  2156.     int getval = 0, range[2], confirmed = 0;
  2157.  
  2158.     cmfdbi(&sw,                /* First FDB - command switches */
  2159.        _CMKEY,            /* fcode */
  2160.        "Array name or switch",
  2161.        "",                /* default */
  2162.        "",                /* addtl string data */
  2163.        nsrtswtab,            /* addtl numeric data 1: tbl size */
  2164.        4,                /* addtl numeric data 2: 4 = cmswi */
  2165.        NULL,            /* Processing function */
  2166.        srtswtab,            /* Keyword table */
  2167.        &fl                /* Pointer to next FDB */
  2168.        );
  2169.     cmfdbi(&fl,                /* Anything that doesn't match */
  2170.        _CMFLD,            /* fcode */
  2171.        "Array name",        /* hlpmsg */
  2172.        "",                /* default */
  2173.        "",                /* addtl string data */
  2174.        0,                /* addtl numeric data 1 */
  2175.        0,                /* addtl numeric data 2 */
  2176.        NULL,
  2177.        NULL,
  2178.        &cm
  2179.        );
  2180.     cmfdbi(&cm,                /* Or premature confirmation */
  2181.        _CMCFM,            /* fcode */
  2182.        "",                /* hlpmsg */
  2183.        "",                /* default */
  2184.        "",                /* addtl string data */
  2185.        0,                /* addtl numeric data 1 */
  2186.        0,                /* addtl numeric data 2 */
  2187.        NULL,
  2188.        NULL,
  2189.        NULL
  2190.        );
  2191.  
  2192.     range[0] = -1;
  2193.     range[1] = -1;
  2194.  
  2195.     while (1) {                /* Parse 0 or more switches */
  2196.     x = cmfdb(&sw);
  2197.     if (x < 0)
  2198.       return(x);
  2199.     if (cmresult.fcode != _CMKEY)    /* Break out if not a switch */
  2200.       break;
  2201.     c = cmgbrk();
  2202.     getval = (c == ':' || c == '=');
  2203.     if (getval && !(cmresult.kflags & CM_ARG)) {
  2204.         printf("?This switch does not take arguments\n");
  2205.         return(-9);
  2206.     }
  2207.     switch (cmresult.nresult) {
  2208.       case SRT_REV:
  2209.         xr = 1;
  2210.         break;
  2211.       case SRT_KEY:
  2212.         if (getval) {
  2213.         if ((y = cmnum("Column for comparison (1-based)",
  2214.                    "1",10,&x,xxstring)) < 0)
  2215.           return(y);
  2216.         xk = x - 1;
  2217.         } else
  2218.           xk = 0;
  2219.         break;
  2220.       case SRT_CAS:
  2221.         if (getval) {
  2222.         if ((y = cmkey(onoff,2,"","on",xxstring)) < 0)
  2223.           return(y);
  2224.         xc = y;
  2225.         } else
  2226.           xc = 1;
  2227.         break;
  2228.       case SRT_RNG:            /* /RANGE */
  2229.         if (getval) {
  2230.         char buf[32];
  2231.         char buf2[16];
  2232.         int i;
  2233.         char * p, * q;
  2234.         if ((y = cmfld("low:high element","1",&s,NULL)) < 0)
  2235.           return(y);
  2236.         s = brstrip(s);
  2237.         ckstrncpy(buf,s,32);
  2238.         p = buf;
  2239.         for (i = 0; *p && i < 2; i++) { /* Get low and high */
  2240.             q = p;        /* Start of this piece */
  2241.             while (*p) {    /* Find end of this piece */
  2242.             if (*p == ':') {
  2243.                 *p = NUL;
  2244.                 p++;
  2245.                 break;
  2246.             }
  2247.             p++;
  2248.             }
  2249.             y = 15;        /* Evaluate this piece */
  2250.             s = buf2;
  2251.             zzstring(q,&s,&y);
  2252.             s = evalx(buf2);
  2253.             if (s) if (*s) ckstrncpy(buf2,s,16);
  2254.             if (!rdigits(buf2)) {
  2255.             printf("?Not numeric: %s\n",buf2);
  2256.             return(-9);
  2257.             }
  2258.             range[i] = atoi(buf2);
  2259.         }
  2260.         }
  2261.         break;
  2262.       case SRT_NUM:            /* /NUMERIC */
  2263.         xn = 1;
  2264.         break;
  2265.       default:
  2266.         return(-2);
  2267.     }
  2268.     }
  2269.     switch (cmresult.fcode) {
  2270.       case _CMCFM:
  2271.     confirmed = 1;
  2272.     break;
  2273.       case _CMFLD:
  2274.     ckstrncpy(line,cmresult.sresult,LINBUFSIZ); /* Safe copy of name */
  2275.     s = line;
  2276.     break;
  2277.       default:
  2278.     printf("?Unexpected function code: %d\n",cmresult.fcode);
  2279.     return(-9);
  2280.     }
  2281.     if (confirmed) {
  2282.     printf("?Array name required\n");
  2283.     return(-9);
  2284.     }
  2285.     ckmakmsg(tmpbuf,TMPBUFSIZ,
  2286.          "Second array to sort according to ",s,NULL,NULL);
  2287.     if ((x = cmfld(tmpbuf,"",&p,NULL)) < 0)
  2288.       if (x != -3)
  2289.     return(x);
  2290.     tmpbuf[0] = NUL;
  2291.     ckstrncpy(tmpbuf,p,TMPBUFSIZ);
  2292.     p = tmpbuf;
  2293.     if ((x = cmcfm()) < 0)        /* Get confirmation */
  2294.       return(x);
  2295.  
  2296.     x = arraybounds(s,&lo,&hi);        /* Get array index & bounds */
  2297.     if (x < 0) {            /* Check */
  2298.     printf("?Bad array name: %s\n",s);
  2299.     return(-9);
  2300.     }
  2301.     if (lo > -1) range[0] = lo;        /* Set range */
  2302.     if (hi > -1) range[1] = hi;
  2303.     ap = a_ptr[x];            /* Get pointer to array element list */
  2304.     if (!ap) {                /* Check */
  2305.     printf("?Array not declared: %s\n", s);
  2306.     return(-9);
  2307.     }
  2308.     if (range[0] < 0)            /* Starting element */
  2309.       range[0] = 1;
  2310.     if (range[1] < 0)            /* Final element */
  2311.       range[1] = a_dim[x];
  2312.     if (range[1] > a_dim[x]) {
  2313.     printf("?range %d:%d exceeds array dimension %d\n",
  2314.            range[0],range[1],a_dim[x]
  2315.            );
  2316.     return(-9);
  2317.     }
  2318.     ap += range[0];
  2319.     xs = range[1] - range[0] + 1;    /* Number of elements to sort */
  2320.     if (xs < 1) {            /* Check */
  2321.     printf("?Bad range: %d:%d\n",range[0],range[1]);
  2322.     return(-9);
  2323.     }
  2324.     if (xk < 0) xk = 0;            /* Key position */
  2325.     if (xr < 0) xr = 0;            /* Reverse flag */
  2326.     if (xn)                /* Numeric flag */
  2327.       xc = 2;
  2328.     else if (xc < 0)            /* Not numeric */
  2329.       xc = inpcas[cmdlvl];        /* so alpha case option */
  2330.  
  2331.     if (*p) {                /* Parallel array given? */
  2332.     y = xarray(p);            /* Yes, get its index. */
  2333.     if (y < 0) {
  2334.         printf("?Bad array name: %s\n", p);
  2335.         return(-9);
  2336.     }
  2337.     if (y != x) {            /* If the 2 arrays are different  */
  2338.         xp = a_ptr[y];        /* Pointer to 2nd array element list */
  2339.         if (!xp) {
  2340.         printf("?Array not declared: %s\n", p);
  2341.         return(-9);
  2342.         }
  2343.         if (a_dim[y] < range[1]) {
  2344.         printf("?Array %s smaller than %s\n", p, s);
  2345.         return(-9);
  2346.         }
  2347.         xp += range[0];        /* Set base to same as 1st array */
  2348.     }
  2349.     }
  2350.     sh_sort(ap,xp,xs,xk,xr,xc);        /* Sort the array(s) */
  2351.     return(success = 1);        /* Always succeeds */
  2352. }
  2353. #endif /* NOSPL */
  2354.  
  2355. static struct keytab purgtab[] = {    /* PURGE command switches */
  2356.     { "/after",        PU_AFT,  CM_ARG },
  2357.     { "/ask",          PU_ASK,  0 },
  2358.     { "/before",       PU_BEF,  CM_ARG },
  2359.     { "/delete",       PU_DELE, CM_INV },
  2360. #ifdef UNIXOROSK
  2361.     { "/dotfiles",     PU_DOT,  0 },
  2362. #endif /* UNIXOROSK */
  2363.     { "/except",       PU_EXC,  CM_ARG },
  2364.     { "/heading",      PU_HDG,  0 },
  2365.     { "/keep",         PU_KEEP, CM_ARG },
  2366.     { "/larger-than",  PU_LAR,  CM_ARG },
  2367.     { "/list",         PU_LIST, 0 },
  2368.     { "/log",          PU_LIST, CM_INV },
  2369.     { "/noask",        PU_NASK, 0 },
  2370.     { "/nodelete",     PU_NODE, CM_INV },
  2371. #ifdef UNIXOROSK
  2372.     { "/nodotfiles",   PU_NODOT,0 },
  2373. #endif /* UNIXOROSK */
  2374.     { "/noheading",    PU_NOH,  0 },
  2375.     { "/nol",          PU_NOLI, CM_INV|CM_ABR },
  2376.     { "/nolist",       PU_NOLI, 0 },
  2377.     { "/nolog",        PU_NOLI, CM_INV },
  2378. #ifdef CK_TTGWSIZ
  2379.     { "/nopage",       PU_NOPA, 0 },
  2380. #endif /* CK_TTGWSIZ */
  2381.     { "/not-after",    PU_NAF,  CM_ARG },
  2382.     { "/not-before",   PU_NBF,  CM_ARG },
  2383.     { "/not-since",    PU_NAF,  CM_INV|CM_ARG },
  2384. #ifdef CK_TTGWSIZ
  2385.     { "/page",         PU_PAGE, 0 },
  2386. #endif /* CK_TTGWSIZ */
  2387.     { "/quiet",        PU_QUIE, CM_INV },
  2388. #ifdef RECURSIVE
  2389.     { "/recursive",    PU_RECU, 0 },
  2390. #endif /* RECURSIVE */
  2391.     { "/since",        PU_AFT,  CM_ARG|CM_INV },
  2392.     { "/simulate",     PU_NODE, 0 },
  2393.     { "/smaller-than", PU_SMA,  CM_ARG },
  2394.     { "/verbose",      PU_VERB, CM_INV }
  2395. };
  2396. static int npurgtab = sizeof(purgtab)/sizeof(struct keytab);
  2397.  
  2398.  
  2399.  
  2400.  
  2401.  
  2402. int
  2403. bkupnum(s,i) char * s; int *i; {
  2404.     int k = 0, pos = 0;
  2405.     char * p = NULL, *q;
  2406.     *i = pos;
  2407.     if (!s) s = "";
  2408.     if (!*s)
  2409.       return(-1);
  2410.     if ((k = strlen(s)) < 5)
  2411.       return(-1);
  2412.  
  2413.     if (s[k-1] != '~')
  2414.       return(-1);
  2415.     pos = k - 2;
  2416.     q = s + pos;
  2417.     while (q >= s && isdigit(*q)) {
  2418.     p = q--;
  2419.     pos--;
  2420.     }
  2421.     if (!p)
  2422.       return(-1);
  2423.     if (q < s+2)
  2424.       return(-1);
  2425.     if (*q != '~' || *(q-1) != '.')
  2426.       return(-1);
  2427.     pos--;
  2428.     *i = pos;
  2429.     debug(F111,"bkupnum",s+pos,pos);
  2430.     return(atoi(p));
  2431. }
  2432.  
  2433. #ifdef CKPURGE
  2434. /* Presently only for UNIX because we need direct access to the file array. */
  2435. /* Not needed for VMS anyway, because we don't make backup files there. */
  2436.  
  2437. #define MAXKEEP 32            /* Biggest /KEEP: value */
  2438.  
  2439. static int
  2440.   pu_keep = 0, pu_list = 0, pu_dot = 0, pu_ask = 0, pu_hdg = 0;
  2441.  
  2442. #ifdef CK_TTGWSIZ
  2443. static int pu_page = -1;
  2444. #else
  2445. static int pu_page = 0;
  2446. #endif /* CK_TTGWSIZ */
  2447.  
  2448. #ifndef NOSHOW
  2449. VOID
  2450. showpurgopts() {            /* SHOW PURGE command options */
  2451.     int x = 0;
  2452.     extern int optlines;
  2453.     prtopt(&optlines,"PURGE");
  2454.     if (pu_ask > -1) {
  2455.     x++;
  2456.     prtopt(&optlines, pu_ask ? "/ASK" : "/NOASK");
  2457.     }
  2458. #ifdef UNIXOROSK
  2459.     if (pu_dot > -1) {
  2460.     x++;
  2461.     prtopt(&optlines, pu_dot ? "/DOTFILES" : "/NODOTFILES");
  2462.     }
  2463. #endif /* UNIXOROSK */
  2464.     if (pu_keep > -1) {
  2465.     x++;
  2466.     ckmakmsg(tmpbuf,TMPBUFSIZ,"/KEEP:",ckitoa(pu_keep),NULL,NULL);
  2467.     prtopt(&optlines,tmpbuf);
  2468.     }
  2469.     if (pu_list > -1) {
  2470.     x++;
  2471.     prtopt(&optlines, pu_list ? "/LIST" : "/NOLIST");
  2472.     }
  2473.     if (pu_hdg > -1) {
  2474.     x++;
  2475.     prtopt(&optlines, pu_hdg ? "/HEADING" : "/NOHEADING");
  2476.     }
  2477. #ifdef CK_TTGWSIZ
  2478.     if (pu_page > -1) {
  2479.     x++;
  2480.     prtopt(&optlines, pu_page ? "/PAGE" : "/NOPAGE");
  2481.     }
  2482. #endif /* CK_TTGWSIZ */
  2483.     if (!x) prtopt(&optlines,"(no options set)");
  2484.     prtopt(&optlines,"");
  2485. }
  2486. #endif /* NOSHOW */
  2487.  
  2488. int
  2489. setpurgopts() {                /* Set PURGE command options */
  2490.     int c, z, getval = 0;
  2491.     int
  2492.       x_keep  = -1, x_list = -1, x_page = -1,
  2493.       x_hdg   = -1, x_ask  = -1, x_dot  = -1;
  2494.  
  2495.     while (1) {
  2496.     if ((y = cmswi(purgtab,npurgtab,"Switch","",xxstring)) < 0) {
  2497.         if (y == -3)
  2498.           break;
  2499.         else
  2500.           return(y);
  2501.     }
  2502.     c = cmgbrk();
  2503.     if ((getval = (c == ':' || c == '=')) && !(cmgkwflgs() & CM_ARG)) {
  2504.         printf("?This switch does not take an argument\n");
  2505.         return(-9);
  2506.     }
  2507.     if (!getval && (cmgkwflgs() & CM_ARG)) {
  2508.         printf("?This switch requires an argument\n");
  2509.         return(-9);
  2510.     }
  2511.     switch (y) {
  2512.       case PU_KEEP:
  2513.         z = 1;
  2514.         if (c == ':' || c == '=')
  2515.           if ((y = cmnum("How many backup files to keep",
  2516.                  "1",10,&z,xxstring)) < 0)
  2517.         return(y);
  2518.         if (z < 0 || z > MAXKEEP) {
  2519.         printf("?Please specify a number between 0 and %d\n",
  2520.                MAXKEEP
  2521.                );
  2522.         return(-9);
  2523.         }
  2524.         x_keep = z;
  2525.         break;
  2526.       case PU_LIST:
  2527.       case PU_VERB:
  2528.         x_list = 1;
  2529.         break;
  2530.       case PU_QUIE:
  2531.       case PU_NOLI:
  2532.         x_list = 0;
  2533.         break;
  2534. #ifdef CK_TTGWSIZ
  2535.       case PU_PAGE:
  2536.         x_page = 1;
  2537.         break;
  2538.       case PU_NOPA:
  2539.         x_page = 0;
  2540.         break;
  2541. #endif /* CK_TTGWSIZ */
  2542.       case PU_HDG:
  2543.         x_hdg = 1;
  2544.         break;
  2545.       case PU_NOH:
  2546.         x_hdg = 0;
  2547.         break;
  2548.       case PU_ASK:
  2549.         x_ask = 1;
  2550.         break;
  2551.       case PU_NASK:
  2552.         x_ask = 0;
  2553.         break;
  2554. #ifdef UNIXOROSK
  2555.       case PU_DOT:
  2556.         x_dot = 1;
  2557.         break;
  2558.       case PU_NODOT:
  2559.         x_dot = 0;
  2560.         break;
  2561. #endif /* UNIXOROSK */
  2562.       default:
  2563.         printf("?This option can not be set\n");
  2564.         return(-9);
  2565.     }
  2566.     }
  2567.     if ((x = cmcfm()) < 0)        /* Get confirmation */
  2568.       return(x);
  2569.     if (x_keep > -1)            /* Set PURGE defaults. */
  2570.       pu_keep = x_keep;
  2571.     if (x_list > -1)
  2572.       pu_list = x_list;
  2573. #ifdef CK_TTGWSIZ
  2574.     if (x_page > -1)
  2575.       pu_page = x_page;
  2576. #endif /* CK_TTGWSIZ */
  2577.     if (x_hdg > -1)
  2578.       pu_hdg = x_hdg;
  2579.     if (x_ask > -1)
  2580.       pu_ask = x_ask;
  2581.     if (x_dot > -1)
  2582.       pu_dot = x_dot;
  2583.     return(success = 1);
  2584. }
  2585.  
  2586. int
  2587. dopurge() {                /* Do the PURGE command */
  2588.     extern char ** mtchs;
  2589.     extern int xaskmore, cmd_rows, recursive;
  2590.     int simulate = 0, asking = 0;
  2591.     int listing = 0, paging = -1, lines = 0, deleting = 1, errors = 0;
  2592.     struct FDB sw, sf, cm;
  2593.     int g, i, j, k, m = 0, n, x, y, z, done = 0, count = 0, flags = 0;
  2594.     int tokeep = 0, getval = 0, havename = 0, confirmed = 0;
  2595.     int xx[MAXKEEP+1];            /* Array of numbers to keep */
  2596.     int min = -1;
  2597.     int x_hdg = 0, fs = 0, rc = 0;
  2598.     long minsize = -1L, maxsize = -1L;
  2599.     char namebuf[CKMAXPATH+4];
  2600.     char basebuf[CKMAXPATH+4];
  2601.     char
  2602.       * pu_aft = NULL,
  2603.       * pu_bef = NULL,
  2604.       * pu_naf = NULL,
  2605.       * pu_nbf = NULL,
  2606.       * pu_exc = NULL;
  2607.     char * pxlist[8];            /* Exception list */
  2608.  
  2609.     if (pu_keep > -1)            /* Set PURGE defaults. */
  2610.       tokeep = pu_keep;
  2611.     if (pu_list > -1)
  2612.       listing = pu_list;
  2613. #ifdef CK_TTGWSIZ
  2614.     if (pu_page > -1)
  2615.       paging = pu_page;
  2616. #endif /* CK_TTGWSIZ */
  2617.  
  2618.     for (i = 0; i <= MAXKEEP; i++)    /* Clear this number buffer */
  2619.       xx[i] = 0;
  2620.     for (i = 0; i < 8; i++)        /* Initialize these... */
  2621.       pxlist[i] = NULL;
  2622.  
  2623.     g_matchdot = matchdot;        /* Save these... */
  2624.  
  2625.     cmfdbi(&sw,                /* 1st FDB - PURGE switches */
  2626.        _CMKEY,            /* fcode */
  2627.        "Filename or switch",    /* hlpmsg */
  2628.        "",                /* default */
  2629.        "",                /* addtl string data */
  2630.        npurgtab,            /* addtl numeric data 1: tbl size */
  2631.        4,                /* addtl numeric data 2: 4 = cmswi */
  2632.        xxstring,            /* Processing function */
  2633.        purgtab,            /* Keyword table */
  2634.        &sf                /* Pointer to next FDB */
  2635.        );
  2636.     cmfdbi(&sf,                /* 2nd FDB - filespec to purge */
  2637.        _CMIFI,            /* fcode */
  2638.        "",
  2639.        "",                /* default */
  2640.        "",                /* addtl string data */
  2641.        0,                /* addtl numeric data 1 */
  2642.        0,                /* addtl numeric data 2 */
  2643.        xxstring,
  2644.        NULL,
  2645.        &cm
  2646.        );
  2647.     cmfdbi(&cm,                /* Or premature confirmation */
  2648.        _CMCFM,            /* fcode */
  2649.        "",                /* hlpmsg */
  2650.        "",                /* default */
  2651.        "",                /* addtl string data */
  2652.        0,                /* addtl numeric data 1 */
  2653.        0,                /* addtl numeric data 2 */
  2654.        NULL,
  2655.        NULL,
  2656.        NULL
  2657.        );
  2658.  
  2659.     while (!havename && !confirmed) {
  2660.     x = cmfdb(&sw);            /* Parse something */
  2661.     if (x < 0) {            /* Error */
  2662.         rc = x;
  2663.         goto xpurge;
  2664.     } else if (cmresult.fcode == _CMKEY) {
  2665.         char c;
  2666.         c = cmgbrk();
  2667.         if ((getval = (c == ':' || c == '=')) && !(cmgkwflgs() & CM_ARG)) {
  2668.         printf("?This switch does not take an argument\n");
  2669.         rc = -9;
  2670.         goto xpurge;
  2671.         }
  2672.         if (!getval && (cmgkwflgs() & CM_ARG)) {
  2673.         printf("?This switch requires an argument\n");
  2674.         rc = -9;
  2675.         goto xpurge;
  2676.         }
  2677.         switch (k = cmresult.nresult) {
  2678.           case PU_KEEP:
  2679.         z = 1;
  2680.         if (c == ':' || c == '=') {
  2681.             if ((y = cmnum("How many backup files to keep",
  2682.                    "1",10,&z,xxstring)) < 0) {
  2683.             rc = y;
  2684.             goto xpurge;
  2685.             }
  2686.         }
  2687.         if (z < 0 || z > MAXKEEP) {
  2688.             printf("?Please specify a number between 0 and %d\n",
  2689.                MAXKEEP
  2690.                );
  2691.             rc = -9;
  2692.             goto xpurge;
  2693.         }
  2694.         tokeep = z;
  2695.         break;
  2696.           case PU_LIST:
  2697.         listing = 1;
  2698.         break;
  2699.           case PU_NOLI:
  2700.         listing = 0;
  2701.         break;
  2702. #ifdef CK_TTGWSIZ
  2703.           case PU_PAGE:
  2704.         paging = 1;
  2705.         break;
  2706.           case PU_NOPA:
  2707.         paging = 0;
  2708.         break;
  2709. #endif /* CK_TTGWSIZ */
  2710.           case PU_DELE:
  2711.         deleting = 1;
  2712.         break;
  2713.           case PU_NODE:
  2714.         deleting = 0;
  2715.         simulate = 1;
  2716.         listing = 1;
  2717.         break;
  2718.           case PU_ASK:
  2719.         asking = 1;
  2720.         break;
  2721.           case PU_NASK:
  2722.         asking = 0;
  2723.         break;
  2724.           case PU_AFT:
  2725.           case PU_BEF:
  2726.           case PU_NAF:
  2727.           case PU_NBF:
  2728.         if ((x = cmdate("File-time","",&s,0,xxstring)) < 0) {
  2729.             if (x == -3) {
  2730.             printf("?Date-time required\n");
  2731.             rc = -9;
  2732.             } else
  2733.               rc = x;
  2734.             goto xpurge;
  2735.         }
  2736.         fs++;
  2737.         switch (k) {
  2738.           case PU_AFT: makestr(&pu_aft,s); break;
  2739.           case PU_BEF: makestr(&pu_bef,s); break;
  2740.           case PU_NAF: makestr(&pu_naf,s); break;
  2741.           case PU_NBF: makestr(&pu_nbf,s); break;
  2742.         }
  2743.         break;
  2744.           case PU_SMA:
  2745.           case PU_LAR:
  2746.         if ((x = cmnum("File size in bytes","0",10,&y,xxstring)) < 0) {
  2747.             rc = x;
  2748.             goto xpurge;
  2749.         }
  2750.         fs++;
  2751.         switch (cmresult.nresult) {
  2752.           case PU_SMA: minsize = y; break;
  2753.           case PU_LAR: maxsize = y; break;
  2754.         }
  2755.         break;
  2756.           case PU_DOT:
  2757.         matchdot = 1;
  2758.         break;
  2759.           case PU_NODOT:
  2760.         matchdot = 0;
  2761.         break;
  2762.           case PU_EXC:
  2763.         if ((x = cmfld("Pattern","",&s,xxstring)) < 0) {
  2764.             if (x == -3) {
  2765.             printf("?Pattern required\n");
  2766.             rc = -9;
  2767.             } else
  2768.               rc = x;
  2769.             goto xpurge;
  2770.         }
  2771.         fs++;
  2772.         makestr(&pu_exc,s);
  2773.         break;
  2774.           case PU_HDG:
  2775.         x_hdg = 1;
  2776.         break;
  2777. #ifdef RECURSIVE
  2778.           case PU_RECU:        /* /RECURSIVE */
  2779.         recursive = 2;
  2780.         break;
  2781. #endif /* RECURSIVE */
  2782.           default:
  2783.         printf("?Not implemented yet - \"%s\"\n",atmbuf);
  2784.         rc = -9;
  2785.         goto xpurge;
  2786.         }
  2787.     } else if (cmresult.fcode == _CMIFI) {
  2788.         havename = 1;
  2789.     } else if (cmresult.fcode == _CMCFM) {
  2790.         confirmed = 1;
  2791.     } else {
  2792.         rc = -2;
  2793.         goto xpurge;
  2794.     }
  2795.     }
  2796.     if (havename) {
  2797. #ifdef CKREGEX
  2798.     ckmakmsg(line,LINBUFSIZ,cmresult.sresult,".~[1-9]*~",NULL,NULL);
  2799. #else
  2800.     ckmakmsg(line,LINBUFSIZ,cmresult.sresult,".~*~",NULL,NULL);
  2801. #endif /* CKREGEX */
  2802.     } else {
  2803. #ifdef CKREGEX
  2804.     ckstrncpy(line,"*.~[1-9]*~",LINBUFSIZ);
  2805. #else
  2806.     ckstrncpy(line,"*.~*~",LINBUFSIZ);
  2807. #endif /* CKREGEX */
  2808.     }
  2809.     if (!confirmed) {
  2810.     if ((x = cmcfm()) < 0) {
  2811.         rc = x;
  2812.         goto xpurge;
  2813.     }
  2814.     }
  2815.     /* Parse finished - now action */
  2816.  
  2817. #ifdef CK_LOGIN
  2818.     if (isguest) {
  2819.     printf("?File deletion by guests not permitted.\n");
  2820.     rc = -9;
  2821.     goto xpurge;
  2822.     }
  2823. #endif /* CK_LOGIN */
  2824.  
  2825. #ifdef CK_TTGWSIZ
  2826.     if (paging < 0)            /* /[NO]PAGE not given */
  2827.       paging = xaskmore;        /* so use prevailing */
  2828. #endif /* CK_TTGWSIZ */
  2829.  
  2830.     lines = 0;
  2831.     if (x_hdg > 0) {
  2832.     printf("Purging %s, keeping %d...%s\n",
  2833.            s,
  2834.            tokeep,
  2835.            simulate ? " (SIMULATION)" : "");
  2836.     lines += 2;
  2837.     }
  2838.     flags = ZX_FILONLY;
  2839.     if (recursive) flags |= ZX_RECURSE;
  2840.     n = nzxpand(line,flags);        /* Get list of backup files */
  2841.     if (tokeep < 1) {            /* Deleting all of them... */
  2842.     for (i = 0; i < n; i++) {
  2843.         if (fs) if (fileselect(mtchs[i],
  2844.                    pu_aft,pu_bef,pu_naf,pu_nbf,
  2845.                    minsize,maxsize,0,8,pxlist) < 1) {
  2846.         if (listing > 0) {
  2847.             printf(" %s (SKIPPED)\n",mtchs[i]);
  2848. #ifdef CK_TTGWSIZ
  2849.             if (paging)
  2850.               if (++lines > cmd_rows - 3) {
  2851.               if (!askmore()) goto xpurge; else lines = 0;
  2852.               }
  2853. #endif /* CK_TTGWSIZ */
  2854.         }
  2855.         continue;
  2856.         }
  2857.         if (asking) {
  2858.         int x;
  2859.         ckmakmsg(tmpbuf,TMPBUFSIZ," Delete ",mtchs[i],"?",NULL);
  2860.         x = getyesno(tmpbuf,1);
  2861.         switch (x) {
  2862.           case 0: continue;
  2863.           case 1: break;
  2864.           case 2: goto xpurge;
  2865.         }
  2866.         }
  2867.         x = deleting ? zdelet(mtchs[i]) : 0;
  2868.         if (x > -1) {
  2869.         if (listing)
  2870.           printf(" %s (%s)\n", mtchs[i],deleting ? "OK" : "SELECTED");
  2871.         count++;
  2872.         } else {
  2873.         errors++;
  2874.         if (listing)
  2875.           printf(" %s (FAILED)\n", mtchs[i]);
  2876.         }
  2877. #ifdef CK_TTGWSIZ
  2878.         if (listing && paging)
  2879.           if (++lines > cmd_rows - 3) {
  2880.           if (!askmore()) goto xpurge; else lines = 0;
  2881.           }
  2882. #endif /* CK_TTGWSIZ */
  2883.     }
  2884.     goto xpurge;
  2885.     }
  2886.     if (n < tokeep) {            /* Not deleting any */
  2887.     count = 0;
  2888.     if (listing)
  2889.       printf(" Matches = %d: Not enough to purge.\n");
  2890.     goto xpurge;
  2891.     }
  2892.  
  2893.     /* General case - delete some but not others */
  2894.  
  2895.     sh_sort(mtchs,NULL,n,0,0,filecase);    /* Alphabetize the list (ESSENTIAL) */
  2896.  
  2897.     g = 0;                /* Start of current group */
  2898.     for (i = 0; i < n; i++) {        /* Go thru sorted file list */
  2899.     x = znext(namebuf);        /* Get next file */
  2900.     if (x < 1 || !namebuf[0] || i == n - 1)    /* No more? */
  2901.       done = 1;            /* NOTE: 'done' must be 0 or 1 only */
  2902.     if (fs) if (fileselect(namebuf,
  2903.                    pu_aft,pu_bef,pu_naf,pu_nbf,
  2904.                    minsize,maxsize,0,8,pxlist) < 1) {
  2905.         if (listing > 0) {
  2906.         printf(" %s (SKIPPED)\n",namebuf);
  2907.         if (++lines > cmd_rows - 3)
  2908.           if (!askmore()) goto xpurge; else lines = 0;
  2909.         }
  2910.         continue;
  2911.     }
  2912.     if (x > 0)
  2913.       if ((m = bkupnum(namebuf,&z)) < 0) /* This file's backup number. */
  2914.         continue;
  2915.     for (j = 0; j < tokeep; j++) {    /* Insert in list. */
  2916.         if (m > xx[j]) {
  2917.         for (k = tokeep - 1; k > j; k--)
  2918.           xx[k] = xx[k-1];
  2919.         xx[j] = m;
  2920.         break;
  2921.         }
  2922.     }
  2923.     /* New group? */
  2924.     if (done || (i > 0 && ckstrcmp(namebuf,basebuf,z,1))) {
  2925.         if (i + done - g > tokeep) { /* Do we have enough to purge? */
  2926.         min = xx[tokeep-1];    /* Yes, lowest backup number to keep */
  2927.         debug(F111,"dopurge group",basebuf,min);
  2928.         for (j = g; j < i + done; j++) { /* Go through this group */
  2929.             x = bkupnum(mtchs[j],&z);    /* Get file backup number */
  2930.             if (x > 0 && x < min) {      /* Below minimum? */
  2931.             x = deleting ? zdelet(mtchs[j]) : 0;
  2932.             if (x < 0) errors++;
  2933.             if (listing)
  2934.               printf(" %s (%s)\n",
  2935.                  mtchs[j],
  2936.                  ((x < 0) ? "ERROR" :
  2937.                   (deleting ? "DELETED" : "SELECTED"))
  2938.                  );
  2939.             count++;
  2940.             } else if (listing)    /* Not below minimum - keep this one */
  2941.               printf(" %s (KEPT)\n",mtchs[j]);
  2942. #ifdef CK_TTGWSIZ
  2943.             if (listing && paging)
  2944.               if (++lines > cmd_rows - 3) {
  2945.               if (!askmore()) goto xpurge; else lines = 0;
  2946.               }
  2947. #endif /* CK_TTGWSIZ */
  2948.         }
  2949.         } else if (listing && paging) { /* Not enough to purge */
  2950.         printf(" %s.~*~ (KEPT)\n",basebuf);
  2951. #ifdef CK_TTGWSIZ
  2952.         if (++lines > cmd_rows - 3) {
  2953.             if (!askmore()) goto xpurge; else lines = 0;
  2954.         }
  2955. #endif /* CK_TTGWSIZ */
  2956.         }
  2957.         for (j = 0; j < tokeep; j++) /* Clear the backup number list */
  2958.           xx[j] = 0;
  2959.         g = i;            /* Reset the group pointer */
  2960.     }
  2961.     if (done)            /* No more files, done. */
  2962.       break;
  2963.     strncpy(basebuf,namebuf,z);    /* Set basename of this file */
  2964.     basebuf[z] = NUL;
  2965.     }
  2966.   xpurge:                /* Common exit point */
  2967.     if (g_matchdot > -1) {
  2968.     matchdot = g_matchdot;        /* Restore these... */
  2969.     g_matchdot = -1;
  2970.     }
  2971.     if (rc < 0) return(rc);        /* Parse error */
  2972.     if (x_hdg)
  2973.       printf("Files purged: %d%s\n",
  2974.          count,
  2975.          deleting ? "" : " (not really)"
  2976.          );
  2977.     return(success = count > 0 ? 1 : (errors > 0) ? 0 : 1);
  2978. }
  2979. #endif /* CKPURGE */
  2980.  
  2981. #ifndef NOXFER
  2982. #ifndef NOLOCAL
  2983. int
  2984. doxdis() {
  2985.     extern int nolocal;
  2986.     int x, y = 0, z;
  2987. #ifdef COMMENT
  2988.     char *s;
  2989. #endif /* COMMENT */
  2990.  
  2991.     if ((x = cmkey(fdtab,nfdtab,"file transfer display style","",
  2992.            xxstring)) < 0)
  2993.       return(x);
  2994. #ifdef CK_PCT_BAR
  2995.     if ((y = cmkey(fdftab,2,"","thermometer",xxstring)) < 0)
  2996.       return(y);
  2997. #endif /* CK_PCT_BAR */
  2998.     if ((z = cmcfm()) < 0) return(z);
  2999. #ifdef CK_CURSES
  3000.     if (x == XYFD_C) {            /* FULLSCREEN */
  3001. #ifdef COMMENT
  3002. #ifndef MYCURSES
  3003.     extern char * trmbuf;        /* Real curses */
  3004.     int z;
  3005. #endif /* MYCURSES */
  3006. #endif /* COMMENT */
  3007.  
  3008.         if (nolocal)            /* Nothing to do in this case */
  3009.             return(success = 1);
  3010.  
  3011. #ifdef COMMENT
  3012. #ifndef MYCURSES
  3013. #ifndef VMS
  3014.     s = getenv("TERM");
  3015.         debug(F110,"doxdis TERM",s,0);
  3016.     if (!s) s = "";
  3017.     fxdinit(x);
  3018.     if (*s && trmbuf) {        /* Don't call tgetent */
  3019.         z = tgetent(trmbuf,s);    /* if trmbuf not allocated */
  3020.         debug(F111,"doxdis tgetent",s,z);
  3021.     } else {
  3022.         z = 0;
  3023.         debug(F110,"doxdis tgetent skipped",s,0);
  3024.     }
  3025.     if (z < 1) {
  3026.         printf("Sorry, terminal type unknown: \"%s\"\n",s);
  3027.         return(success = 0);
  3028.     }
  3029. #endif /* VMS */
  3030. #endif /* MYCURSES */
  3031. #else
  3032.     fxdinit(x);
  3033. #endif /* COMMENT */
  3034.  
  3035. #ifdef CK_PCT_BAR
  3036.     thermometer = y;
  3037. #endif /* CK_PCT_BAR */
  3038.  
  3039.     line[0] = '\0';            /* (What's this for?) */
  3040.     }
  3041. #endif /* CK_CURSES */
  3042.     fdispla = x;            /* It's OK. */
  3043.     return(success = 1);
  3044. }
  3045. #endif /* NOLOCAL */
  3046. #endif /* NOXFER */
  3047.  
  3048. int
  3049. setfil(rmsflg) int rmsflg; {
  3050. #ifdef COMMENT
  3051.     extern int en_del;
  3052. #endif /* COMMENT */
  3053. #ifndef NOXFER
  3054.     if (rmsflg) {
  3055.     if ((y = cmkey(rfiltab,nrfilp,"Remote file parameter","",
  3056.                xxstring)) < 0) {
  3057.         if (y == -3) {
  3058.         printf("?Remote file parameter required\n");
  3059.         return(-9);
  3060.         } else return(y);
  3061.     }
  3062.     } else {
  3063. #endif /* NOXFER */
  3064.     if ((y = cmkey(filtab,nfilp,"File parameter","",xxstring)) < 0)
  3065.       return(y);
  3066. #ifndef NOXFER
  3067.     }
  3068. #endif /* NOXFER */
  3069.     switch (y) {
  3070. #ifdef COMMENT                /* Not needed */
  3071.       case XYFILB:            /* Blocksize */
  3072.     if ((y = cmnum("file block size",ckitoa(DBLKSIZ),10,&z,xxstring)) < 0)
  3073.       return(y);
  3074.     if ((x = cmcfm()) < 0) return(x);
  3075.     if (rmsflg) {
  3076.         sstate = setgen('S', "311", ckitoa(z), "");
  3077.         return((int) sstate);
  3078.     } else {
  3079.         fblksiz = z;
  3080.         return(success = 1);
  3081.     }
  3082. #endif /* COMMENT */
  3083.  
  3084. #ifndef NOXFER
  3085.       case XYFILS:            /* Byte size */
  3086.     if ((y = cmnum("file byte size (7 or 8)","8",10,&z,xxstring)) < 0)
  3087.       return(y);
  3088.     if (z != 7 && z != 8) {
  3089.         printf("\n?The choices are 7 and 8\n");
  3090.         return(0);
  3091.     }
  3092.     if ((y = cmcfm()) < 0) return(y);
  3093.     if (z == 7) fmask = 0177;
  3094.     else if (z == 8) fmask = 0377;
  3095.     return(success = 1);
  3096.  
  3097. #ifndef NOCSETS
  3098.       case XYFILC: {            /* Character set */
  3099.       char * csetname = NULL;
  3100.       extern int
  3101.         r_cset, s_cset, afcset[];    /* SEND CHARACTER-SET AUTO or MANUAL */
  3102.  
  3103.       struct FDB kw, fl;
  3104.       cmfdbi(&kw,            /* First FDB - command switches */
  3105.          _CMKEY,        /* fcode */
  3106.          rmsflg ? "server character-set name" : "",  /* help */
  3107.          "",            /* default */
  3108.          "",            /* addtl string data */
  3109.          nfilc,            /* addtl numeric data 1: tbl size */
  3110.          0,            /* addtl numeric data 2: 0 = keyword */
  3111.          xxstring,        /* Processing function */
  3112.          fcstab,        /* Keyword table */
  3113.          rmsflg ? &fl : NULL    /* Pointer to next FDB */
  3114.        );
  3115.       cmfdbi(&fl,            /* Anything that doesn't match */
  3116.          _CMFLD,        /* fcode */
  3117.          "",            /* hlpmsg */
  3118.          "",            /* default */
  3119.          "",            /* addtl string data */
  3120.          0,            /* addtl numeric data 1 */
  3121.          0,            /* addtl numeric data 2 */
  3122.          xxstring,
  3123.          NULL,
  3124.          NULL
  3125.          );
  3126.       if ((x = cmfdb(&kw)) < 0)
  3127.         return(x);
  3128.       if (cmresult.fcode == _CMKEY) {
  3129.           x = cmresult.nresult;
  3130.           csetname = fcsinfo[x].keyword;
  3131.       } else {
  3132.           ckstrncpy(line,cmresult.sresult,LINBUFSIZ);
  3133.           csetname = line;
  3134.       }
  3135.       if ((z = cmcfm()) < 0) return(z);
  3136.       if (rmsflg) {
  3137.           sstate = setgen('S', "320", csetname, "");
  3138.           return((int) sstate);
  3139.       }
  3140.       fcharset = x;
  3141.       if (s_cset == XMODE_A)    /* If SEND CHARACTER-SET is AUTO */
  3142.         if (x > -1 && x <= MAXFCSETS)
  3143.           if (afcset[x] > -1 && afcset[x] <= MAXTCSETS)
  3144.         tcharset = afcset[x]; /* Pick corresponding xfer charset */
  3145.       setxlatype(tcharset,fcharset); /* Translation type */
  3146.       /* If I say SET FILE CHARACTER-SET blah, I want to be blah! */
  3147.       r_cset = XMODE_M;        /* Don't switch incoming set! */
  3148.       x = fcsinfo[fcharset].size;    /* Also set default x-bit charset */
  3149.       if (x == 128)            /* 7-bit... */
  3150.         dcset7 = fcharset;
  3151.       else if (x == 256)        /* 8-bit... */
  3152.         dcset8 = fcharset;
  3153.       return(success = 1);
  3154.       }
  3155. #endif /* NOCSETS */
  3156.  
  3157. #ifndef NOLOCAL
  3158.       case XYFILD:            /* Display */
  3159.     return(doxdis());
  3160. #endif /* NOLOCAL */
  3161. #endif /* NOXFER */
  3162.  
  3163.       case XYFILA:            /* End-of-line */
  3164. #ifdef NLCHAR
  3165.     s = "";
  3166.     if (NLCHAR == 015)
  3167.       s = "cr";
  3168.     else if (NLCHAR == 012)
  3169.       s = "lf";
  3170.     if ((x = cmkey(eoltab, neoltab,
  3171.                "local text-file line terminator",s,xxstring)) < 0)
  3172.       return(x);
  3173. #else
  3174.     if ((x = cmkey(eoltab, neoltab,
  3175.                "local text-file line terminator","crlf",xxstring)) < 0)
  3176.       return(x);
  3177. #endif /* NLCHAR */
  3178.     if ((z = cmcfm()) < 0) return(z);
  3179.     feol = (CHAR) x;
  3180.     return(success = 1);
  3181.  
  3182. #ifndef NOXFER
  3183.       case XYFILN:            /* Names */
  3184.     if ((x = cmkey(fntab,nfntab,"how to handle filenames","converted",
  3185.                xxstring)) < 0)
  3186.       return(x);
  3187.     if ((z = cmcfm()) < 0) return(z);
  3188.     if (rmsflg) {
  3189.         sstate = setgen('S', "301", ckitoa(1 - x), "");
  3190.         return((int) sstate);
  3191.     } else {
  3192.         ptab[protocol].fncn = x;    /* Set structure */
  3193.         fncnv = x;            /* Set variable */
  3194.         f_save = x;            /* And set "permanent" variable */
  3195.         return(success = 1);
  3196.     }
  3197.  
  3198.       case XYFILR:            /* Record length */
  3199.     if ((y = cmnum("file record length",
  3200.                ckitoa(DLRECL),10,&z,xxstring)) < 0)
  3201.       return(y);
  3202.     if ((x = cmcfm()) < 0) return(x);
  3203.     if (rmsflg) {
  3204.         sstate = setgen('S', "312", ckitoa(z), "");
  3205.         return((int) sstate);
  3206.     } else {
  3207.         frecl = z;
  3208.         return(success = 1);
  3209.     }
  3210.  
  3211. #ifdef COMMENT
  3212.       case XYFILO:            /* Organization */
  3213.     if ((x = cmkey(forgtab,nforg,"file organization","sequential",
  3214.                xxstring)) < 0)
  3215.       return(x);
  3216.     if ((y = cmcfm()) < 0) return(y);
  3217.     if (rmsflg) {
  3218.         sstate = setgen('S', "314", ckitoa(x), "");
  3219.         return((int) sstate);
  3220.     } else {
  3221.         forg = x;
  3222.         return(success = 1);
  3223.     }
  3224. #endif /* COMMENT */
  3225.  
  3226. #ifdef COMMENT                /* Not needed */
  3227.       case XYFILF:            /* Format */
  3228.     if ((x = cmkey(frectab,nfrec,"file record format","stream",
  3229.                xxstring)) < 0)
  3230.       return(x);
  3231.     if ((y = cmcfm()) < 0) return(y);
  3232.     if (rmsflg) {
  3233.         sstate = setgen('S', "313", ckitoa(x), "");
  3234.         return((int) sstate);
  3235.     } else {
  3236.         frecfm = x;
  3237.         return(success = 1);
  3238.     }
  3239. #endif /* COMMENT */
  3240.  
  3241. #ifdef COMMENT
  3242.       case XYFILP:            /* Printer carriage control */
  3243.     if ((x = cmkey(fcctab,nfcc,"file carriage control","newline",
  3244.                xxstring)) < 0)
  3245.       return(x);
  3246.     if ((y = cmcfm()) < 0) return(y);
  3247.     if (rmsflg) {
  3248.         sstate = setgen('S', "315", ckitoa(x), "");
  3249.         return((int) sstate);
  3250.     } else {
  3251.         fcctrl = x;
  3252.         return(success = 1);
  3253.     }
  3254. #endif /* COMMENT */
  3255. #endif /* NOXFER */
  3256.  
  3257.       case XYFILT:            /* Type */
  3258.     if ((x = cmkey(rmsflg ? rfttab  : fttab,
  3259.                rmsflg ? nrfttyp : nfttyp,
  3260.                "type of file transfer","text",xxstring)) < 0)
  3261.       return(x);
  3262.  
  3263. #ifdef VMS
  3264.         /* Allow VMS users to choose record format for binary files */
  3265.         if ((x == XYFT_B) && (rmsflg == 0)) {
  3266.         if ((x = cmkey(fbtab,nfbtyp,"VMS record format","fixed",
  3267.                xxstring)) < 0)
  3268.           return(x);
  3269.     }
  3270. #endif /* VMS */
  3271.     if ((y = cmcfm()) < 0) return(y);
  3272.     binary = x;
  3273.     b_save = x;
  3274. #ifdef MAC
  3275.     (void) mac_setfildflg(binary);
  3276. #endif /* MAC */
  3277. #ifndef NOXFER
  3278.     if (rmsflg) {
  3279.         /* Allow for LABELED in VMS & OS/2 */
  3280.         sstate = setgen('S', "300", ckitoa(x), "");
  3281.         return((int) sstate);
  3282.     } else {
  3283. #endif /* NOXFER */
  3284.         return(success = 1);
  3285. #ifndef NOXFER
  3286.     }
  3287. #endif /* NOXFER */
  3288.  
  3289. #ifndef NOXFER
  3290.       case XYFILX:            /* Collision Action */
  3291.     if ((x = cmkey(colxtab,ncolx,"Filename collision action","backup",
  3292.                xxstring)) < 0)
  3293.       return(x);
  3294.     if ((y = cmcfm()) < 0) return(y);
  3295. #ifdef CK_LOGIN
  3296.     if (isguest) {
  3297.         /* Don't let guests change existing files */
  3298.         printf("?This command not valid for guests\n");
  3299.         return(-9);
  3300.     }
  3301. #endif /* CK_LOGIN */
  3302. #ifdef COMMENT
  3303.     /* Not appropriate - DISABLE DELETE only refers to server */
  3304.     if ((x == XYFX_X || x == XYFX_B || x == XYFX_U || x == XYFX_A) &&
  3305.         (!ENABLED(en_del))) {
  3306.         printf("?Sorry, file deletion is disabled.\n");
  3307.         return(-9);
  3308.     }
  3309. #endif /* COMMENT */
  3310.     fncact = x;
  3311.     ptab[protocol].fnca = x;
  3312.     if (rmsflg) {
  3313.         sstate = setgen('S', "302", ckitoa(fncact), "");
  3314.         return((int) sstate);
  3315.     } else {
  3316.         if (fncact == XYFX_R) ckwarn = 1; /* FILE WARNING implications */
  3317.         if (fncact == XYFX_X) ckwarn = 0; /* ... */
  3318.         return(success = 1);
  3319.     }
  3320.  
  3321.       case XYFILW:            /* Warning/Write-Protect */
  3322.     if ((x = seton(&ckwarn)) < 0) return(x);
  3323.     if (ckwarn)
  3324.       fncact = XYFX_R;
  3325.     else
  3326.       fncact = XYFX_X;
  3327.     return(success = 1);
  3328.  
  3329. #ifdef CK_LABELED
  3330.       case XYFILL:            /* LABELED FILE parameters */
  3331.     if ((x = cmkey(lbltab,nlblp,"Labeled file feature","",
  3332.                xxstring)) < 0)
  3333.       return(x);
  3334.     if ((success = seton(&y)) < 0)
  3335.       return(success);
  3336.     if (y)                /* Set or reset the selected bit */
  3337.       lf_opts |= x;            /* in the options bitmask. */
  3338.     else
  3339.       lf_opts &= ~x;
  3340.     return(success);
  3341. #endif /* CK_LABELED */
  3342.  
  3343.       case XYFILI: {            /* INCOMPLETE */
  3344.       extern struct keytab ifdatab[];
  3345.       extern int keep;
  3346.       if ((y = cmkey(ifdatab,3,"","auto",xxstring)) < 0) return(y);
  3347.       if ((x = cmcfm()) < 0) return(x);
  3348.       if (rmsflg) {
  3349.           sstate = setgen('S',
  3350.                   "310",
  3351.                   y == 0 ? "0" : (y == 1 ? "1" : "2"),
  3352.                   ""
  3353.                   );
  3354.           return((int) sstate);
  3355.       } else {
  3356.           keep = y;
  3357.           return(success = 1);
  3358.       }
  3359.       }
  3360.  
  3361. #ifdef CK_TMPDIR
  3362.       case XYFILG: {            /* Download directory */
  3363.       int x;
  3364.       char *s;
  3365. #ifdef ZFNQFP
  3366.       struct zfnfp * fnp;
  3367. #endif /* ZFNQFP */
  3368. #ifdef MAC
  3369.       char temp[34];
  3370. #endif /* MAC */
  3371.  
  3372. #ifdef GEMDOS
  3373.       if ((x = cmdir("Name of local directory, or carriage return",
  3374.              "",&s,
  3375.              NULL)) < 0 ) {
  3376.           if (x != -3)
  3377.         return(x);
  3378.       }
  3379. #else
  3380. #ifdef OS2
  3381.       if ((x = cmdir("Name of PC disk and/or directory,\n\
  3382.        or press the Enter key to use current directory",
  3383.              "",&s,xxstring)) < 0 ) {
  3384.           if (x != -3)
  3385.         return(x);
  3386.       }
  3387. #else
  3388. #ifdef MAC
  3389.       x = ckstrncpy(temp,zhome(),32);
  3390.       if (x > 0) if (temp[x-1] != ':') { temp[x] = ':'; temp[x+1] = NUL; }
  3391.       if ((x = cmtxt("Name of Macintosh volume and/or folder,\n\
  3392.  or press the Return key for the desktop on the boot disk",
  3393.              temp,&s, xxstring)) < 0 )
  3394.         return(x);
  3395. #else
  3396.       if ((x = cmdir("Name of local directory, or carriage return",
  3397.              "", &s, xxstring)) < 0 ) {
  3398.           if (x != -3)
  3399.         return(x);
  3400.       }
  3401. #endif /* MAC */
  3402. #endif /* OS2 */
  3403. #endif /* GEMDOS */
  3404.       debug(F110,"download dir",s,0);
  3405.  
  3406. #ifndef MAC
  3407.       if (x == 2) {
  3408.           printf("?Wildcards not allowed in directory name\n");
  3409.           return(-9);
  3410.       }
  3411. #endif /* MAC */
  3412.  
  3413. #ifdef ZFNQFP
  3414.       if ((fnp = zfnqfp(s,TMPBUFSIZ - 1,tmpbuf))) {
  3415.           if (fnp->fpath)
  3416.         if ((int) strlen(fnp->fpath) > 0)
  3417.           s = fnp->fpath;
  3418.       }
  3419.       debug(F110,"download zfnqfp",s,0);
  3420. #endif /* ZFNQFP */
  3421.  
  3422.       ckstrncpy(line,s,LINBUFSIZ);    /* Make a safe copy */
  3423. #ifndef MAC
  3424.       if ((x = cmcfm()) < 0)    /* Get confirmation */
  3425.         return(x);
  3426. #endif /* MAC */
  3427.  
  3428. #ifdef CK_LOGIN
  3429.     if (isguest) {
  3430.         /* Don't let guests change existing files */
  3431.         printf("?This command not valid for guests\n");
  3432.         return(-9);
  3433.     }
  3434. #endif /* CK_LOGIN */
  3435.       x = strlen(s);
  3436.  
  3437.           if (x) {
  3438. #ifdef datageneral
  3439.           if (s[x-1] == ':')    /* homdir ends in colon, */
  3440.         s[x-1] = NUL;        /* and "dir" doesn't like that... */
  3441. #endif /* datageneral */
  3442.           makestr(&dldir,s);
  3443.       } else
  3444.         makestr(&dldir,NULL);    /* dldir is NULL when not assigned */
  3445.  
  3446.       return(success = 1);
  3447.       }
  3448. #endif /* CK_TMPDIR */
  3449.       case XYFILY:
  3450.     return(setdest());
  3451. #endif /* NOXFER */
  3452.  
  3453. #ifdef CK_CTRLZ
  3454.       case XYFILV: {            /* EOF */
  3455.       extern int eofmethod;
  3456.       if ((x = cmkey(eoftab,3,"end-of-file detection method","",
  3457.              xxstring)) < 0)
  3458.         return(x);
  3459.       if ((y = cmcfm()) < 0)
  3460.         return(y);
  3461.       eofmethod = x;
  3462.       return(success = 1);
  3463.       }
  3464. #endif /* CK_CTRLZ */
  3465.  
  3466. #ifndef NOXFER
  3467. #ifdef UNIX
  3468.       case XYFILH: {            /* OUTPUT */
  3469.       extern int zofbuffer, zobufsize, zofblock;
  3470. #ifdef DYNAMIC
  3471.       extern char * zoutbuffer;
  3472. #endif /* DYNAMIC */
  3473.  
  3474.       if ((x = cmkey(zoftab,nzoftab,"output file writing method","",
  3475.              xxstring)) < 0)
  3476.         return(x);
  3477.       if (x == ZOF_BUF || x == ZOF_NBUF) {
  3478.           if ((y = cmnum("output buffer size","32768",10,&z,xxstring)) < 0)
  3479.         return(y);
  3480.           if (z < 1) {
  3481.           printf("?Bad size - %d\n", z);
  3482.           return(-9);
  3483.           }
  3484.       }
  3485.       if ((y = cmcfm()) < 0) return(y);
  3486.       switch (x) {
  3487.         case ZOF_BUF:
  3488.         case ZOF_NBUF:
  3489.           zofbuffer = (x == ZOF_BUF);
  3490.           zobufsize = z;
  3491.           break;
  3492.         case ZOF_BLK:
  3493.         case ZOF_NBLK:
  3494.           zofblock = (x == ZOF_BLK);
  3495.           break;
  3496.       }
  3497. #ifdef DYNAMIC
  3498.       if (zoutbuffer) free(zoutbuffer);
  3499.       if (!(zoutbuffer = (char *)malloc(z))) {
  3500.           printf("MEMORY ALLOCATION ERROR - FATAL\n");
  3501.           doexit(BAD_EXIT,-1);
  3502.       } else
  3503.         zobufsize = z;
  3504. #else
  3505.       if (z <= OBUFSIZE) {
  3506.           zobufsize = z;
  3507.       } else {
  3508.           printf("?Sorry, %d is too big - %d is the maximum\n",z,OBUFSIZE);
  3509.           return(-9);
  3510.       }
  3511. #endif /* DYNAMIC */
  3512.       return(success = 1);
  3513.       }
  3514. #endif /* UNIX */
  3515.  
  3516. #ifdef PATTERNS
  3517.       case XYFIBP:            /* BINARY-PATTERN */
  3518.       case XYFITP: {            /* TEXT-PATTERN */
  3519.       char * tmp[FTPATTERNS];
  3520.       int i, n = 0;
  3521.       while (n < FTPATTERNS) {
  3522.           tmp[n] = NULL;
  3523.           if ((x = cmfld("Pattern","",&s,xxstring)) < 0)
  3524.         break;
  3525.           ckstrncpy(line,s,LINBUFSIZ);
  3526.           s = brstrip(line);
  3527.           makestr(&(tmp[n++]),s);
  3528.       }
  3529.       if (x == -3) x = cmcfm();
  3530.       for (i = 0; i <= n; i++) {
  3531.           if (x > -1) {
  3532.           if (y == XYFIBP)
  3533.             makestr(&(binpatterns[i]),tmp[i]);
  3534.           else
  3535.             makestr(&(txtpatterns[i]),tmp[i]);
  3536.           }
  3537.           free(tmp[i]);
  3538.       }
  3539.       if (y == XYFIBP)        /* Null-terminate the list */
  3540.         makestr(&(binpatterns[i]),NULL);
  3541.       else
  3542.         makestr(&(txtpatterns[i]),NULL);
  3543.       return(x);
  3544.       }
  3545.  
  3546.       case XYFIPA:            /* PATTERNS */
  3547.     if ((x = setonaut(&patterns)) < 0)
  3548.       return(x);
  3549.     return(success = 1);
  3550. #endif /* PATTERNS */
  3551. #endif /* NOXFER */
  3552.  
  3553. #ifdef UNICODE
  3554.       case XYFILU: {            /* UCS */
  3555.       extern int ucsorder, ucsbom, byteorder;
  3556.       if ((x = cmkey(ucstab,nucstab,"","",xxstring)) < 0)
  3557.         return(x);
  3558.       switch (x) {
  3559.         case UCS_BYT:
  3560.           if ((y = cmkey(botab,nbotab,
  3561.                  "Byte order",
  3562.                  byteorder ? "little-endian" : "big-endian",
  3563.                  xxstring
  3564.                  )
  3565.            ) < 0)
  3566.         return(y);
  3567.           if ((x = cmcfm()) < 0)
  3568.         return(x);
  3569.           ucsorder = y;
  3570.           return(success = 1);
  3571.         case UCS_BOM:
  3572.           if ((y = cmkey(onoff,2,"","on",xxstring)) < 0)
  3573.         return(y);
  3574.           if ((x = cmcfm()) < 0)
  3575.         return(x);
  3576.           ucsbom = y;
  3577.           return(success = 1);
  3578.         default:
  3579.           return(-2);
  3580.       }
  3581.       }
  3582. #endif /* UNICODE */
  3583.  
  3584. #ifndef datageneral
  3585.       case XYF_INSP: {            /* SCAN (INSPECTION) */
  3586.       extern int filepeek, nscanfile;
  3587.       if ((x = cmkey(onoff,2,"","on",xxstring)) < 0)
  3588.         return(x);
  3589.       if (y) {
  3590.           if ((y = cmnum("How much to scan",ckitoa(SCANFILEBUF),
  3591.                  10,&z,xxstring)) < 0)
  3592.         return(y);
  3593.       }
  3594.       if ((y = cmcfm()) < 0)
  3595.         return(y);
  3596. #ifdef VMS
  3597.       filepeek = 0;
  3598.       nscanfile = 0;
  3599.       return(success = 0);
  3600. #else
  3601.       filepeek = x;
  3602.       nscanfile = z;
  3603.       return(success = 1);
  3604. #endif /* VMS */
  3605.       }
  3606. #endif /* datageneral */
  3607.  
  3608.       case XYF_DFLT:
  3609.     y = 0;
  3610. #ifndef NOCSETS
  3611.     if ((y = cmkey(fdfltab,nfdflt,"","",xxstring)) < 0)
  3612.       return(y);
  3613.     if (y == 7 || y == 8) {
  3614.         if (y == 7)
  3615.           s = fcsinfo[dcset7].keyword;
  3616.         else
  3617.           s = fcsinfo[dcset8].keyword;
  3618.         if ((x = cmkey(fcstab,nfilc,"character-set",s,xxstring)) < 0)
  3619.           return(x);
  3620.     }
  3621.     ckstrncpy(line,fcsinfo[x].keyword,LINBUFSIZ);
  3622.     s = line;
  3623. #endif /* NOCSETS */
  3624.     if ((z = cmcfm()) < 0)
  3625.       return(z);
  3626.     switch (y) {
  3627. #ifndef NOCSETS
  3628.       case 7:
  3629.         if (fcsinfo[x].size != 128) {
  3630.         printf("%s - Not a 7-bit set\n",s);
  3631.         return(-9);
  3632.         }
  3633.         dcset7 = x;
  3634.         break;
  3635.       case 8:
  3636.         if (fcsinfo[x].size != 256) {
  3637.         printf("%s - Not an 8-bit set\n",s);
  3638.         return(-9);
  3639.         }
  3640.         dcset8 = x;
  3641.         break;
  3642. #endif /* NOCSETS */
  3643.       default:
  3644.         return(-2);
  3645.     }
  3646.     return(success = 1);
  3647.  
  3648. #ifndef NOXFER
  3649.       case 9997:            /* FASTLOOKUPS */
  3650.     return(success = seton(&stathack));
  3651. #endif /* NOXFER */
  3652.  
  3653. #ifdef UNIX
  3654. #ifdef DYNAMIC
  3655.       case XYF_LSIZ: {            /* LISTSIZE */
  3656.       int zz;
  3657.       y = cmnum("Maximum number of filenames","",10,&x,xxstring);
  3658.       if ((x = setnum(&zz,x,y,-1)) < 0)
  3659.         return(x);
  3660.       if (zsetfil(zz,3) < 0) {
  3661.           printf("?Memory allocation failure\n");
  3662.           return(-9);
  3663.       }
  3664.       return(success = 1);
  3665.       }
  3666.       case XYF_SSPA: {            /* STRINGSPACE */
  3667.       int zz;
  3668.       y = cmnum("Number of characters for filename list",
  3669.             "",10,&x,xxstring);
  3670.       if ((x = setnum(&zz,x,y,-1)) < 0)
  3671.         return(x);
  3672.       if (zsetfil(zz,1) < 0) {
  3673.           printf("?Memory allocation failure\n");
  3674.           return(-9);
  3675.       }
  3676.       return(success = 1);
  3677.       }
  3678.  
  3679. #endif /* DYNAMIC */
  3680. #endif /* UNIX */
  3681.  
  3682.       default:
  3683.     printf("?unexpected file parameter\n");
  3684.     return(-2);
  3685.     }
  3686. }
  3687.  
  3688. #ifndef NOLOCAL
  3689. #ifdef OS2
  3690. /* MS-DOS KERMIT compatibility modes */
  3691. int
  3692. setmsk() {
  3693.     if ((y = cmkey(msktab,nmsk,"MS-DOS Kermit compatibility mode",
  3694.                     "keycodes",xxstring)) < 0) return(y);
  3695.  
  3696.     switch ( y ) {
  3697. #ifdef COMMENT
  3698.       case MSK_COLOR:
  3699.         return(seton(&mskcolors));
  3700. #endif /* COMMENT */
  3701.       case MSK_KEYS:
  3702.     return(seton(&mskkeys));
  3703.       default:                /* Shouldn't get here. */
  3704.         return(-2);
  3705.     }
  3706. }
  3707. #endif /* OS2 */
  3708.  
  3709. int
  3710. settrmtyp() {
  3711. #ifdef OS2
  3712. #ifdef TNCODE
  3713.     extern int ttnum;             /* Last Telnet Terminal Type sent */
  3714.     extern int ttnumend;         /* Has end of list been found */
  3715. #endif /* TNCODE */
  3716.     if ((x = cmkey(ttyptab,nttyp,"","vt320",xxstring)) < 0)
  3717.       return(x);
  3718.     if ((y = cmcfm()) < 0)
  3719.       return(y);
  3720.     settermtype(x,1);
  3721. #ifdef TNCODE
  3722.     /* So we send the correct terminal name to the host if it asks for it */
  3723.     ttnum = -1;                /* Last Telnet Terminal Type sent */
  3724.     ttnumend = 0;            /* end of list not found */
  3725. #endif /* TNCODE */
  3726.     return(success = 1);
  3727. #else  /* Not OS2 */
  3728.     printf(
  3729. "\n Sorry, this version of C-Kermit does not support the SET TERMINAL TYPE\n");
  3730.     printf(
  3731. " command.  Type \"help set terminal\" for further information.\n");
  3732. #endif /* OS2 */
  3733.     return(success = 0);
  3734. }
  3735.  
  3736. #ifdef CKTIDLE
  3737. static char iactbuf[132];
  3738.  
  3739. char *
  3740. getiact() {
  3741.     switch (tt_idleact) {
  3742.       case IDLE_RET:  return("return");
  3743.       case IDLE_EXIT: return("exit");
  3744.       case IDLE_HANG: return("hangup");
  3745. #ifdef TNCODE
  3746.       case IDLE_TNOP: return("Telnet NOP");
  3747.       case IDLE_TAYT: return("Telnet AYT");
  3748. #endif /* TNCODE */
  3749.  
  3750.       case IDLE_OUT: {
  3751.       int c, k, n;
  3752.       char * p, * q, * t;
  3753.       k = ckstrncpy(iactbuf,"output ",132);
  3754.       n = k;
  3755.       q = &iactbuf[k];
  3756.       p = tt_idlestr;
  3757.       if (!p) p = "";
  3758.       if (!*p) return("output (nothing)");
  3759.       while ((c = *p++) && n < 131) {
  3760.           c &= 0xff;
  3761.           if (c == '\\') {
  3762.           if (n > 130) break;
  3763.           *q++ = '\\';
  3764.           *q++ = '\\';
  3765.           *q = NUL;
  3766.           n += 2;
  3767.           } else if ((c > 31 && c < 127) || c > 159) {
  3768.           *q++ = c;
  3769.           *q = NUL;
  3770.           n++;
  3771.           } else {
  3772.           if (n > (131 - 6))
  3773.             break;
  3774.           sprintf(q,"\\{%d}",c);
  3775.           k = strlen(q);
  3776.           q += k;
  3777.           n += k;
  3778.           *q = NUL;
  3779.           }
  3780.       }
  3781.       *q = NUL;
  3782. #ifdef OS2      
  3783.       k = tt_cols[VTERM];
  3784. #else
  3785.       k = tt_cols;
  3786. #endif /* OS2 */
  3787.       if (n > k - 52) {
  3788.           n = k - 52;
  3789.           iactbuf[n-2] = '.';
  3790.           iactbuf[n-1] = '.';
  3791.           iactbuf[n] = NUL;
  3792.       }
  3793.       return(iactbuf);
  3794.       }
  3795.       default: return("unknown");
  3796.     }
  3797. }
  3798. #endif /* CKTIDLE */
  3799.  
  3800. int
  3801. settrm() {
  3802.     int i = 0;
  3803. #ifdef OS2
  3804.     extern int colorreset, user_erasemode;
  3805. #endif /* OS2 */
  3806.     if ((y = cmkey(trmtab,ntrm,"", "",xxstring)) < 0) return(y);
  3807. #ifdef MAC
  3808.     printf("\n?Sorry, not implemented yet.  Please use the Settings menu.\n");
  3809.     return(-9);
  3810. #else
  3811. #ifdef IKSD
  3812.     if (inserver) {
  3813.     if ((y = cmcfm()) < 0) return(y);
  3814.         printf("?Sorry, command disabled.\r\n");
  3815.         return(success = 0);
  3816.     }
  3817. #endif /* IKSD */
  3818.  
  3819.     switch (y) {
  3820.       case XYTBYT:            /* SET TERMINAL BYTESIZE */
  3821.     if ((y = cmnum("bytesize for terminal connection","8",10,&x,
  3822.                xxstring)) < 0)
  3823.       return(y);
  3824.     if (x != 7 && x != 8) {
  3825.         printf("\n?The choices are 7 and 8\n");
  3826.         return(success = 0);
  3827.     }
  3828.     if ((y = cmcfm()) < 0) return(y);
  3829.     if (x == 7) cmask = 0177;
  3830.     else if (x == 8) {
  3831.         cmask = 0377;
  3832.         parity = 0;
  3833.     }
  3834. #ifdef OS2
  3835.     if (IS97801(tt_type_mode))
  3836.       SNI_bitmode(x);
  3837. #endif /* OS2 */
  3838.         return(success = 1);
  3839.  
  3840.       case XYTSO:            /* SET TERMINAL LOCKING-SHIFT */
  3841.     return(seton(&sosi));
  3842.  
  3843.       case XYTNL:            /* SET TERMINAL NEWLINE-MODE */
  3844.     return(seton(&tnlm));
  3845.  
  3846. #ifdef OS2
  3847.       case XYTCOL:
  3848.     if ((x = cmkey(ttycoltab,ncolors,"","terminal",xxstring)) < 0)
  3849.       return(x);
  3850.     else if (x == TTCOLRES) {
  3851.         if ((y = cmkey(ttcolmodetab,ncolmode,
  3852.                "","default-color",xxstring)) < 0)
  3853.           return(y);
  3854.         if ((z = cmcfm()) < 0)
  3855.           return(z);
  3856.         colorreset = y;
  3857.         return(success = 1);
  3858.     } else if (x == TTCOLERA) {
  3859.         if ((y = cmkey(ttcolmodetab,ncolmode,"",
  3860.                "current-color",xxstring)) < 0)
  3861.           return(y);
  3862.         if ((z = cmcfm()) < 0)
  3863.           return(z);
  3864.         user_erasemode = y;
  3865.         return(success=1);
  3866.     } else {            /* No parse error */
  3867.         int fg = 0, bg = 0;
  3868.         fg = cmkey(ttyclrtab, nclrs,
  3869.                (x == TTCOLBOR ?
  3870.             "color for screen border" :
  3871.             "foreground color and then background color"),
  3872.                "lgray", xxstring);
  3873.         if (fg < 0)
  3874.           return(fg);
  3875.         if (x != TTCOLBOR) {
  3876.         if ((bg = cmkey(ttyclrtab,nclrs,
  3877.                 "background color","blue",xxstring)) < 0)
  3878.           return(bg);
  3879.         }
  3880.         if ((y = cmcfm()) < 0)
  3881.           return(y);
  3882.         switch (x) {
  3883.           case TTCOLNOR:
  3884.         colornormal = fg | bg << 4;
  3885.         fgi = fg & 0x08;
  3886.         bgi = bg & 0x08;
  3887.         break;
  3888.           case TTCOLREV:
  3889.         colorreverse = fg | bg << 4;
  3890.         break;
  3891.           case TTCOLUND:
  3892.         colorunderline = fg | bg << 4;
  3893.         break;
  3894.           case TTCOLGRP:
  3895.         colorgraphic = fg | bg << 4;
  3896.         break;
  3897.           case TTCOLDEB:
  3898.         colordebug = fg | bg << 4;
  3899.         break;
  3900.           case TTCOLSTA:
  3901.         colorstatus = fg | bg << 4;
  3902.         break;
  3903.           case TTCOLHLP:
  3904.         colorhelp = fg | bg << 4;
  3905.         break;
  3906.           case TTCOLBOR:
  3907.         colorborder = fg;
  3908.         break;
  3909.           case TTCOLSEL:
  3910.         colorselect = fg | bg << 4;
  3911.         break;
  3912.           default:
  3913.         printf("%s - invalid\n",cmdbuf);
  3914.         return(-9);
  3915.         break;
  3916.         }
  3917.         scrninitialized[VTERM] = 0;
  3918.         VscrnInit(VTERM);
  3919.     }
  3920.     return(success = 1);
  3921.  
  3922.       case XYTCUR: {            /* SET TERMINAL CURSOR */
  3923.       extern int cursorena[];
  3924.           extern int cursoron[] ;       /* Cursor state on/off       */
  3925.       if ((x = cmkey(ttycurtab,ncursors,"","underline",xxstring)) < 0)
  3926.         return(x);
  3927.       if ((z = cmkey(onoff,2,"","on",xxstring)) < 0)
  3928.         return(z);
  3929.       if ((y = cmcfm()) < 0) return(y);
  3930.       tt_cursor = tt_cursor_usr = x;
  3931.       cursorena[VTERM] = tt_cursorena_usr = z;/* turn cursor on/off */
  3932.           cursoron[VTERM] = FALSE; /* Force newcursor to restore the cursor */
  3933.       return(success = 1);
  3934.       }
  3935. #endif /* OS2 */
  3936.  
  3937.       case XYTTYP:            /* SET TERMINAL TYPE */
  3938.     return(settrmtyp());
  3939.  
  3940. #ifdef OS2
  3941.       case XYTARR:            /* SET TERMINAL ARROW-KEYS */
  3942.     if ((x = cmkey(akmtab,2,"","",xxstring)) < 0) return(x);
  3943.     if ((y = cmcfm()) < 0) return(y);
  3944.     tt_arrow = x;            /* TTK_NORM / TTK_APPL; see ckuusr.h */
  3945.     return(success = 1);
  3946.  
  3947.       case XYTKPD:            /* SET TERMINAL KEYPAD-MODE */
  3948.     if ((x = cmkey(kpmtab,2,"","",xxstring)) < 0) return(x);
  3949.     if ((y = cmcfm()) < 0) return(y);
  3950.     tt_keypad = x;            /* TTK_NORM / TTK_APPL; see ckuusr.h */
  3951.     return(success = 1);
  3952.  
  3953.       case XYTUNX: {            /* SET TERM UNIX-MODE (DG) */
  3954.         extern int dgunix,dgunix_usr;
  3955.     x = seton(&dgunix);
  3956.     dgunix_usr = dgunix;
  3957.     return(x);
  3958.       }
  3959.       case XYTKBMOD: {            /* SET TERM KEYBOARD MODE */
  3960.       extern int tt_kb_mode;
  3961.       if ((x = cmkey(kbmodtab,
  3962.              nkbmodtab,
  3963.              "normal",
  3964.              "special keyboard mode for terminal emulation",
  3965.              xxstring)
  3966.            ) < 0)
  3967.         return(x);
  3968.       if ((y = cmcfm()) < 0) return(y);
  3969.       tt_kb_mode = x;
  3970.       return(success = 1);
  3971.       }
  3972.  
  3973.       case XYTWRP:            /* SET TERMINAL WRAP */
  3974.     return(seton(&tt_wrap));
  3975.  
  3976.       case XYSCRS:
  3977.     if ((y = cmnum("CONNECT scrollback buffer size, lines","2000",10,&x,
  3978.                xxstring)) < 0)
  3979.       return(y);
  3980.     /* The max number of lines is the RAM  */
  3981.     /* we can actually dedicate to a       */
  3982.     /* scrollback buffer given the maximum */
  3983.     /* process memory space of 512MB       */
  3984.     if (x < 256 || x > 2000000L) {
  3985.         printf("\n?The size must be between 256 and 2,000,000.\n");
  3986.         return(success = 0);
  3987.      }
  3988.     if ((y = cmcfm()) < 0) return(y);
  3989.     tt_scrsize[VTERM] = x;
  3990.     VscrnInit(VTERM);
  3991.     return(success = 1);
  3992. #endif /* OS2 */
  3993.  
  3994. #ifndef NOCSETS
  3995. #ifndef KUI
  3996.       case XYTCS:            /* SET TERMINAL CHARACTER-SET */
  3997.       /* set terminal character-set <remote> <local> */
  3998.     if ((x = cmkey(
  3999. #ifdef CKOUNI
  4000.                        txrtab,ntxrtab,
  4001. #else  /* CKOUNI */
  4002.                        ttcstab,ntermc,
  4003. #endif /* CKOUNI */
  4004.                "remote terminal character-set","",xxstring)) < 0)
  4005.       return(x);
  4006.     if (
  4007. #ifdef CKOUNI
  4008.             x == TX_TRANSP
  4009. #else  /* CKOUNI */
  4010.             x == FC_TRANSP
  4011. #endif /* CKOUNI */
  4012.            ) {        /* TRANSPARENT? */
  4013.         if ((x = cmcfm()) < 0) return(x); /* Confirm the command */
  4014. #ifdef CKOUNI
  4015.             tt_utf8 = 0;        /* Turn off the UTF8 flag */
  4016.         tcsr = tcsl = TX_ASCII;    /* Make them both the same */
  4017. #else /* CKOUNI */
  4018.         tcsr = tcsl = FC_USASCII;
  4019. #endif /* CKOUNI */
  4020.         tcs_transp = 1;
  4021. #ifdef OS2
  4022. #ifdef UNICODE
  4023.             dec_kbd = tcsr = tcsl = TX_TRANSP;
  4024. #else /* UNICODE */
  4025.         y = os2getcp();        /* Default is current code page */
  4026.         switch (y) {
  4027.           case 437: tcsr = tcsl = FC_CP437; break;
  4028.           case 850: tcsr = tcsl = FC_CP850; break;
  4029.           case 852: tcsr = tcsl = FC_CP852; break;
  4030.           case 862: tcsr = tcsl = FC_CP862; break;
  4031.           case 866: tcsr = tcsl = FC_CP866; break;
  4032.         }
  4033. #endif /* UNICODE */
  4034.  
  4035. #ifdef UNICODE
  4036.         if (!cs_is_nrc(tcsl)) {
  4037.         G[0].def_designation = G[0].designation = TX_ASCII;
  4038.         G[0].init = TRUE;
  4039.         G[0].def_c1 = G[0].c1 = FALSE;
  4040.         G[0].size = cs94;
  4041.         G[0].national = FALSE;
  4042.                 dec_nrc = TX_ASCII;
  4043.         } else
  4044.           dec_nrc = tcsl;
  4045.  
  4046.         for (i = cs_is_nrc(tcsl) ? 0 : 1; i < 4; i++) {
  4047.         G[i].def_designation = G[i].designation = tcsl;
  4048.         G[i].init = TRUE;
  4049.         G[i].def_c1 = G[i].c1 = FALSE;
  4050.         switch (cs_size(G[i].designation)) { /* 94, 96, or 128 */
  4051.         case 128:
  4052.         case 96:
  4053.             G[i].size = G[i].def_size = cs96;
  4054.             break;
  4055.         case 94:
  4056.             G[i].size = G[i].def_size = cs94;
  4057.             break;
  4058.         default:
  4059.             G[i].size = G[i].def_size = csmb;
  4060.             break;
  4061.         }
  4062.         G[i].national = cs_is_nrc(x);
  4063.         }
  4064. #else /* UNICODE */
  4065.         for (i = 0; i < 4; i++) {
  4066.         G[i].def_designation = G[i].designation = FC_TRANSP;
  4067.         G[i].init = FALSE;
  4068.         G[i].size = G[i].def_size = cs96;
  4069.         G[i].c1 = G[i].def_c1 = FALSE;
  4070.         G[i].national = FALSE;
  4071.         G[i].rtoi = NULL;
  4072.         G[i].itol = NULL;
  4073.         G[i].ltoi = NULL;
  4074.         G[i].itor = NULL;
  4075.             }
  4076. #endif /* UNICODE */
  4077. #endif /* OS2 */
  4078.         return(success = 1);
  4079.     }
  4080.  
  4081. #ifdef CKOUNI
  4082.     if (x == TX_UTF8) {
  4083.         if ((x = cmcfm()) < 0)    /* Confirm the command */
  4084.           return(x);
  4085.         tcs_transp = 0;
  4086.         tt_utf8 = 1;        /* Turn this on if we are UTF8 */
  4087.         return(success = 1);
  4088.     }
  4089. #endif /* CKOUNI */
  4090.  
  4091. /* Not transparent or UTF8, so get local set to translate it into */
  4092.  
  4093.     s = "";
  4094. #ifdef OS2
  4095.      y = os2getcp();            /* Default is current code page */
  4096.     switch (y) {
  4097.       case 437: s = "cp437"; break;
  4098.       case 850: s = "cp850"; break;
  4099.       case 852: s = "cp852"; break;
  4100.       case 857: s = "cp857"; break;
  4101.       case 858: s = "cp858"; break;
  4102.       case 862: s = "cp862"; break;
  4103.       case 866: s = "cp866"; break;
  4104.       case 869: s = "cp869"; break;
  4105.       case 1250: s = "cp1250"; break;
  4106.       case 1251: s = "cp1251"; break;
  4107.       case 1252: s = "cp1252"; break;
  4108.       case 1253: s = "cp1253"; break;
  4109.       case 1254: s = "cp1254"; break;
  4110.       case 1255: s = "cp1255"; break;
  4111.       case 1256: s = "cp1256"; break;
  4112.       case 1257: s = "cp1257"; break;
  4113.       case 1258: s = "cp1258"; break;
  4114.     }
  4115. #ifdef PCFONTS
  4116. /*
  4117.    If the user has loaded a font with SET TERMINAL FONT then we want
  4118.    to change the default code page to the font that was loaded.
  4119. */
  4120.     if (tt_font != TTF_ROM) {
  4121.         for (y = 0; y < ntermfont; y++ ) {
  4122.         if (term_font[y].kwval == tt_font) {
  4123.             s = term_font[y].kwd;
  4124.             break;
  4125.         }
  4126.         }
  4127.     }
  4128. #endif /* PCFONTS */
  4129. #else  /* Not K95... */
  4130.     s = fcsinfo[fcharset].keyword;
  4131. #endif /* OS2 */
  4132.  
  4133.     if ((y = cmkey(
  4134. #ifdef CKOUNI
  4135.                        txrtab,ntxrtab,
  4136. #else /* CKOUNI */
  4137.                        ttcstab,ntermc,
  4138. #endif /* CKOUNI */
  4139.                "local character-set",s,xxstring)) < 0)
  4140.       return(y);
  4141.  
  4142. #ifdef UNICODE
  4143.           if (y == TX_UTF8) {
  4144.               printf("?UTF8 may not be used as a local character set.\r\n");
  4145.               return(-9);
  4146.           }
  4147. #endif /* UNICODE */
  4148. #ifdef OS2
  4149.     if ((z = cmkey(graphsettab,ngraphset,
  4150.                "DEC VT intermediate graphic set","all",xxstring)) < 0)
  4151.       return(z);
  4152.     {
  4153.         int eol;
  4154.         if ((eol = cmcfm()) < 0)
  4155.           return(eol); /* Confirm the command */
  4156.     }
  4157.         tcs_transp = 0;
  4158.     tcsr = x;            /* Remote character set */
  4159.     tcsl = y;            /* Local character set */
  4160. #ifdef CKOUNI
  4161.         tt_utf8 = 0;            /* Turn off UTF8 flag */
  4162. #endif /* CKOUNI */
  4163.  
  4164.     if (z == TT_GR_ALL) {
  4165.         int i;
  4166. #ifdef UNICODE
  4167.             dec_kbd = x;
  4168. #endif /* UNICODE */
  4169.         for (i = 0; i < 4; i++) {
  4170.                 G[i].init = TRUE;
  4171.                 if ( i == 0 && !cs_is_nrc(x) ) {
  4172.                     G[0].designation = G[0].def_designation = FC_USASCII;
  4173.                     G[0].size = G[0].def_size = cs94;
  4174.                     G[0].national = 1;
  4175.                 } else {
  4176.                     G[i].def_designation = G[i].designation = x;
  4177.                     switch (cs_size(x)) {    /* 94, 96, or 128 */
  4178.                     case 128:
  4179.                     case 96:
  4180.                         G[i].size = G[i].def_size = cs96;
  4181.                         break;
  4182.                     case 94:
  4183.                         G[i].size = G[i].def_size = cs94;
  4184.                         break;
  4185.                     default:
  4186.                         G[i].size = G[i].def_size = csmb;
  4187.                         break;
  4188.                     }
  4189.                     G[i].national = cs_is_nrc(x);
  4190.                 }
  4191.         G[i].c1 = G[i].def_c1 = x != tcsl && cs_is_std(x);
  4192.             }
  4193. #ifdef UNICODE
  4194.         } else if (z == TT_GR_KBD) {    /* Keyboard only */
  4195.             dec_kbd = x;
  4196. #endif /* UNICODE */
  4197.         } else {            /* Specific Gn */
  4198.         G[z].def_designation = G[z].designation = x;
  4199.         G[z].init = TRUE;
  4200.         switch (cs_size(x)) {    /* 94, 96, or 128 */
  4201.           case 128:
  4202.           case 96:
  4203.         G[i].size = G[i].def_size = cs96;
  4204.         break;
  4205.           case 94:
  4206.         G[i].size = G[i].def_size = cs94;
  4207.         break;
  4208.           default:
  4209.         G[i].size = G[i].def_size = csmb;
  4210.         break;
  4211.         }
  4212.         G[i].c1 = G[i].def_c1 = x != tcsl && cs_is_std(x);
  4213.         G[i].national = cs_is_nrc(x);
  4214.         }
  4215. #else /* not OS2 */
  4216.     if ((z = cmcfm()) < 0) return(z); /* Confirm the command */
  4217.     tcsr = x;            /* Remote character set */
  4218.     tcsl = y;            /* Local character set */
  4219. #endif /* OS2 */
  4220.     return(success = 1);
  4221. #endif /* UNICODE */
  4222. #endif /* NOCSETS */
  4223.  
  4224. #ifndef NOCSETS
  4225.       case XYTLCS:            /* SET TERMINAL LOCAL-CHARACTER-SET */
  4226.     /* set terminal character-set <local> */
  4227.     s = getdcset();            /* Get display character-set name */
  4228.     if ((y = cmkey(
  4229. #ifdef CKOUNI
  4230.                        txrtab,ntxrtab,
  4231. #else /* CKOUNI */
  4232.                        fcstab,nfilc,
  4233. #endif /* CKOUNI */
  4234.                "local character-set",s,xxstring)) < 0)
  4235.       return(y);
  4236.  
  4237. #ifdef UNICODE
  4238.           if (y == TX_UTF8) {
  4239.               printf("?UTF8 may not be used as a local character set.\r\n");
  4240.               return(-9);
  4241.           }
  4242. #endif /* UNICODE */
  4243.  
  4244. #ifdef OS2
  4245.         if ((z = cmcfm()) < 0) return(z); /* Confirm the command */
  4246.     tcsl = y;            /* Local character set */
  4247.     {
  4248.         int i;
  4249.         for (i = 0; i < 4; i++) {
  4250.         G[i].init = TRUE;
  4251.         x = G[i].designation;
  4252.         G[i].c1 = (x != tcsl) && cs_is_std(x);
  4253.         x = G[i].def_designation;
  4254.         G[i].def_c1 = (x != tcsl) && cs_is_std(x);
  4255.             }
  4256.         }
  4257. #else /* not OS2 */
  4258.     if ((z = cmcfm()) < 0) return(z); /* Confirm the command */
  4259.     tcsl = y;            /* Local character set */
  4260. #endif /* OS2 */
  4261.     return(success = 1);
  4262. #endif /* NOCSETS */
  4263.  
  4264. #ifndef NOCSETS
  4265. #ifdef UNICODE
  4266.       case XYTUNI:            /* SET TERMINAL UNICODE */
  4267.     return(seton(&tt_unicode));
  4268. #endif /* UNICODE */
  4269.  
  4270.       case XYTRCS:            /* SET TERMINAL REMOTE-CHARACTER-SET */
  4271.     /* set terminal character-set <remote> <Graphic-set> */
  4272.     if ((x = cmkey(
  4273. #ifdef CKOUNI
  4274.                 txrtab, ntxrtab,
  4275. #else /* CKOUNI */
  4276.                 ttcstab,ntermc,
  4277. #endif /* CKOUNI */
  4278.                "remote terminal character-set","",xxstring)) < 0)
  4279.       return(x);
  4280.  
  4281.     /* KUI can't have a Transparent Character Set */
  4282. #ifdef UNICODE
  4283.     if (x == TX_TRANSP)
  4284. #else /* UNICODE */
  4285.     if (x == FC_TRANSP)
  4286. #endif /* UNICODE */
  4287.       {                /* TRANSPARENT? */
  4288.           if ((x = cmcfm()) < 0)    /* Confirm the command */
  4289.         return(x);
  4290. #ifndef OS2
  4291.           tcsr = tcsl;        /* Make both sets the same */
  4292. #else
  4293. #ifdef CKOUNI
  4294.               tt_utf8 = 0;        /* Turn off UTF8 flag */
  4295.               tcsr = tcsl = dec_kbd = TX_TRANSP; /* No translation */
  4296.               tcs_transp = 1;
  4297.  
  4298.           if (!cs_is_nrc(tcsl)) {
  4299.           G[0].def_designation = G[i].designation = TX_ASCII;
  4300.           G[0].init = TRUE;
  4301.           G[0].def_c1 = G[i].c1 = FALSE;
  4302.           G[0].size = cs94;
  4303.           G[0].national = FALSE;
  4304.           }
  4305.           for (i = cs_is_nrc(tcsl) ? 0 : 1; i < 4; i++) {
  4306.           G[i].def_designation = G[i].designation = tcsl;
  4307.           G[i].init = TRUE;
  4308.           G[i].def_c1 = G[i].c1 = FALSE;
  4309.           switch (cs_size(G[i].designation)) { /* 94, 96, or 128 */
  4310.             case 128:
  4311.             case 96:
  4312.               G[i].size = G[i].def_size = cs96;
  4313.               break;
  4314.             case 94:
  4315.               G[i].size = G[i].def_size = cs94;
  4316.               break;
  4317.             default:
  4318.               G[i].size = G[i].def_size = csmb;
  4319.               break;
  4320.           }
  4321.           G[i].national = cs_is_nrc(x);
  4322.           }
  4323. #else /* CKOUNI */
  4324.           tcsr = tcsl;        /* Make both sets the same */
  4325.           for (i = 0; i < 4; i++) {
  4326.           G[i].def_designation = G[i].designation = FC_TRANSP;
  4327.           G[i].init = FALSE;
  4328.           G[i].size = G[i].def_size = cs96;
  4329.           G[i].c1 = G[i].def_c1 = FALSE;
  4330.           G[i].rtoi = NULL;
  4331.           G[i].itol = NULL;
  4332.           G[i].ltoi = NULL;
  4333.           G[i].itor = NULL;
  4334.           G[i].national = FALSE;
  4335.           }
  4336. #endif /* CKOUNI */
  4337. #endif /* OS2 */
  4338.           return(success = 1);
  4339.       }
  4340.  
  4341. #ifdef CKOUNI
  4342.     if (x == TX_UTF8) {
  4343.         if ((x = cmcfm()) < 0) return(x); /* Confirm the command */
  4344.         tcs_transp = 0;
  4345.         tt_utf8 = 1;        /* Turn it on if we are UTF8 */
  4346.         return(success = 1);
  4347.     }
  4348. #endif /* CKOUNI */
  4349.  
  4350. #ifdef OS2
  4351.     if ((z = cmkey(graphsettab,ngraphset,
  4352.                "DEC VT intermediate graphic set","all",xxstring)) < 0)
  4353.       return(z);
  4354.     {
  4355.         int eol;
  4356.         if ((eol = cmcfm()) < 0)    /* Confirm the command */
  4357.           return(eol);
  4358.     }
  4359.         tcs_transp = 0;
  4360.     tcsr = x;            /* Remote character set */
  4361. #ifdef CKOUNI
  4362.     tt_utf8 = 0;            /* Turn off UTF8 flag */
  4363. #endif /* CKOUNI */
  4364.  
  4365.     if (z == TT_GR_ALL) {
  4366.         int i;
  4367. #ifdef UNICODE
  4368.             dec_kbd = x;
  4369. #endif /* UNICODE */
  4370.         for (i = 0; i < 4; i++) {
  4371.         G[i].init = TRUE;
  4372.                 if ( i == 0 && !cs_is_nrc(x) ) {
  4373.                     G[0].designation = G[0].def_designation = FC_USASCII;
  4374.                     G[0].size = G[0].def_size = cs94;
  4375.                     G[0].national = 1;
  4376.                 } else {
  4377.                     G[i].def_designation = G[i].designation = x;
  4378.                     switch (cs_size(x)) {    /* 94, 96, or 128 */
  4379.                     case 128:
  4380.                     case 96:
  4381.                         G[i].size = G[i].def_size = cs96;
  4382.                         break;
  4383.                     case 94:
  4384.                         G[i].size = G[i].def_size = cs94;
  4385.                         break;
  4386.                     default:
  4387.                         G[i].size = G[i].def_size = csmb;
  4388.                         break;
  4389.                     }
  4390.                     G[i].national = cs_is_nrc(x);
  4391.                 }
  4392.         G[i].c1 = G[i].def_c1 = x != tcsl && cs_is_std(x);
  4393.             }
  4394. #ifdef UNICODE
  4395.         } else if (z == TT_GR_KBD) {    /* Keyboard only */
  4396.             dec_kbd = x;
  4397. #endif /* UNICODE */
  4398.         } else {            /* Specific Gn */
  4399.         G[z].def_designation = G[z].designation = x;
  4400.         G[z].init = TRUE;
  4401.         switch (cs_size(x)) {    /* 94, 96, or 128 */
  4402.           case 128:
  4403.           case 96:
  4404.         G[i].size = G[i].def_size = cs96;
  4405.         break;
  4406.           case 94:
  4407.         G[i].size = G[i].def_size = cs94;
  4408.         break;
  4409.           default:
  4410.         G[i].size = G[i].def_size = csmb;
  4411.         break;
  4412.         }
  4413.         G[z].c1 = G[z].def_c1 = x != tcsl && cs_is_std(x);
  4414.         G[z].national = cs_is_nrc(x);
  4415.         }
  4416. #else /* not OS2 */
  4417.     if ((z = cmcfm()) < 0) return(z); /* Confirm the command */
  4418.     tcsr = x;            /* Remote character set */
  4419. #endif /* OS2 */
  4420.     return(success = 1);
  4421. #endif /* NOCSETS */
  4422.  
  4423.       case XYTEC:            /* SET TERMINAL ECHO */
  4424.     if ((x = cmkey(rltab,nrlt,"which side echos during CONNECT",
  4425.                "remote", xxstring)) < 0) return(x);
  4426.     if ((y = cmcfm()) < 0) return(y);
  4427. #ifdef NETCONN
  4428.     oldplex = x;
  4429. #endif /* NETCONN */
  4430.     duplex = x;
  4431.     return(success = 1);
  4432.  
  4433.       case XYTESC:            /* SET TERM ESC */
  4434.     if ((x = cmkey(nabltab,nnabltab,"","enabled",xxstring)) < 0)
  4435.       return(x);
  4436.     if ((y = cmcfm()) < 0) return(y);
  4437.     tt_escape = x;
  4438.     return(1);
  4439.  
  4440.       case XYTCRD:            /* SET TERMINAL CR-DISPLAY */
  4441.     if ((x = cmkey(crdtab,2,"", "normal", xxstring)) < 0) return(x);
  4442.     if ((y = cmcfm()) < 0) return(y);
  4443.     tt_crd = x;
  4444.     return(success = 1);
  4445.  
  4446. #ifdef OS2
  4447.       case XYTANS: {            /* SET TERMINAL ANSWERBACK */
  4448. /*
  4449.   NOTE: We let them enable and disable the answerback sequence, but we
  4450.   do NOT let them change it, and we definitely do not let the host set it.
  4451.   This is a security feature.
  4452.  
  4453.   As of 1.1.8 we allow the SET TERM ANSWERBACK MESSAGE <string> to be
  4454.   used just as MS-DOS Kermit does.  C0 and C1 controls as well as DEL
  4455.   are not allowed to be used as characters.  They are translated to
  4456.   underscore.  This may not be set by APC.
  4457. */
  4458.       if ((x = cmkey(anbktab,nansbk,"", "off", xxstring)) < 0)
  4459.         return(x);
  4460.       if (x < 2) {
  4461.           if ((y = cmcfm()) < 0)
  4462.         return(y);
  4463.           tt_answer = x;
  4464.           return(success = 1);
  4465.       } else if ( x == 2 || x == 3) {
  4466.           int len = 0;
  4467.           extern int safeanswerbk;
  4468.           extern char useranswerbk[];
  4469.           if ((y = cmtxt("Answerback extension","",&s,xxstring)) < 0)
  4470.         return(y);
  4471.           if (apcactive == APC_LOCAL ||
  4472.           (apcactive == APC_REMOTE && !(apcstatus & APC_UNCH)))
  4473.         return(success = 0);
  4474.           len = strlen(s);
  4475.           if (x == 2) {
  4476.           /* Safe Answerback's don't have C0/C1 chars */
  4477.           for (z = 0; z < len; z++) {
  4478.               if ((s[z] & 0x7F) <= SP || (s[z] & 0x7F) == DEL)
  4479.             useranswerbk[z] = '_';
  4480.               else
  4481.             useranswerbk[z] = s[z];
  4482.           }
  4483.           useranswerbk[z] = '\0';
  4484.           safeanswerbk = 1 ;    /* TRUE */
  4485.           } else {
  4486.           ckstrncpy(useranswerbk,s,60);    /* (see ckocon.c) */
  4487.           safeanswerbk = 0;    /* FALSE */
  4488.           }
  4489.           updanswerbk();
  4490.           return(success = 1);
  4491.       } else
  4492.         return(success = 0);
  4493.       }
  4494. #endif /* OS2 */
  4495.  
  4496. #ifdef CK_APC
  4497.       case XYTAPC:
  4498.     if ((y = cmkey(apctab,napctab,
  4499.                        "application program command execution","",
  4500.                xxstring)) < 0)
  4501.       return(y);
  4502.     if ((x = cmcfm()) < 0)
  4503.       return(x);
  4504.     if (apcactive == APC_LOCAL ||
  4505.         (apcactive == APC_REMOTE && !(apcstatus & APC_UNCH)))
  4506.       return(success = 0);
  4507.     apcstatus = y;
  4508.     return(success = 1);
  4509.  
  4510. #ifdef CK_AUTODL
  4511.       case XYTAUTODL:            /* AUTODOWNLOAD */
  4512.     if ((y = cmkey(adltab,nadltab,"Auto-download options","",
  4513.                xxstring)) < 0)
  4514.       return(y);
  4515.     switch (y) {
  4516.       case TAD_ON:
  4517.       case TAD_OFF:
  4518.         if ((x = cmcfm()) < 0)
  4519.           return(x);
  4520.         autodl = y;
  4521.         break;
  4522.       case TAD_ERR:
  4523.         if ((y = cmkey(adlerrtab,nadlerrtab,"","", xxstring)) < 0)
  4524.           return(y);
  4525.         if ((x = cmcfm()) < 0)
  4526.           return(x);
  4527.         adl_err = y;
  4528.         break;
  4529. #ifdef OS2
  4530.       case TAD_K:
  4531.         if ((y = cmkey(adlxtab,nadlxtab,"","", xxstring)) < 0)
  4532.           return(y);
  4533.         switch (y) {
  4534.           case TAD_X_C0:
  4535.         if ((y = cmkey(adlc0tab,nadlc0tab,"",
  4536.                    "processed-by-emulator",xxstring)) < 0)
  4537.           return(y);
  4538.         if ((x = cmcfm()) < 0)
  4539.           return(x);
  4540.         adl_kc0 = y;
  4541.         break;
  4542.           case TAD_X_DETECT:
  4543.         if ((y = cmkey(adldtab,nadldtab,"","packet",xxstring)) < 0)
  4544.           return(y);
  4545.         if ((x = cmcfm()) < 0)
  4546.           return(x);
  4547.         adl_kmode = y;
  4548.         break;
  4549.           case TAD_X_STR:
  4550.         if ((y = cmtxt("Kermit start string","KERMIT READY TO SEND...",
  4551.                    &s,xxstring)) < 0)
  4552.           return(y);
  4553.         free(adl_kstr);
  4554.         adl_kstr = strdup(s);
  4555.         break;
  4556.         }
  4557.         break;
  4558.  
  4559.       case TAD_Z:
  4560.         if ((y = cmkey(adlxtab,nadlxtab,"","",xxstring)) < 0)
  4561.           return(y);
  4562.         switch (y) {
  4563.           case TAD_X_C0:
  4564.         if ((y = cmkey(adlc0tab,nadlc0tab,"",
  4565.                    "processed-by-emulator",xxstring)) < 0)
  4566.           return(y);
  4567.         if ((x = cmcfm()) < 0)
  4568.           return(x);
  4569.         adl_zc0 = y;
  4570.         break;
  4571.           case TAD_X_DETECT:
  4572.         if ((y = cmkey(adldtab,nadldtab,"","packet",xxstring)) < 0)
  4573.           return(y);
  4574.         if ((x = cmcfm()) < 0)
  4575.           return(x);
  4576.         adl_zmode = y;
  4577.         break;
  4578.           case TAD_X_STR:
  4579.         if ((y = cmtxt("","rz\\{13}",&s,xxstring)) < 0)
  4580.           return(y);
  4581.         free(adl_zstr);
  4582.         adl_zstr = strdup(s);
  4583.         break;
  4584.         }
  4585.         break;
  4586. #endif /* OS2 */
  4587.     }
  4588.     return(success = 1);
  4589.  
  4590. #endif /* CK_AUTODL */
  4591. #endif /* CK_APC */
  4592.  
  4593. #ifdef OS2
  4594.       case XYTBEL:
  4595.         return(success = setbell());
  4596.  
  4597.       case XYTMBEL:            /* MARGIN-BELL */
  4598.     if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  4599.     if (y) {            /* ON */
  4600.         if ((z = cmnum("Column at which to set margin bell",
  4601.                "72",10,&x,xxstring)) < 0)
  4602.           return(z);
  4603.     }
  4604.     if ((z = cmcfm()) < 0) return(z);
  4605.     marginbell = y;
  4606.     marginbellcol = x;
  4607.     return(success = 1);
  4608. #endif /* OS2 */
  4609.  
  4610. #ifdef CKTIDLE
  4611.       case XYTIDLE:            /* IDLE-SEND */
  4612.       case XYTITMO:            /* IDLE-TIMEOUT */
  4613.     if ((z = cmnum("seconds of idle time to wait, or 0 to disable",
  4614.                "0",10,&x,xxstring)) < 0)
  4615.       return(z);
  4616.     if (y == XYTIDLE) {
  4617.         if ((y = cmtxt("string to send, may contain kverbs and variables",
  4618.                "\\v(newline)",&s,xxstring)) < 0)
  4619.           return(y);
  4620.         tt_idlesnd_tmo = x;        /* (old) */
  4621.         tt_idlelimit = x;        /* (new) */
  4622.         makestr(&tt_idlestr,brstrip(s)); /* (new) */
  4623.         tt_idlesnd_str = tt_idlestr; /* (old) */
  4624.             tt_idleact = IDLE_OUT;      /* (new) */
  4625.     } else {
  4626.         if ((y = cmcfm()) < 0)
  4627.           return(y);
  4628.         tt_idlelimit = x;
  4629.     }
  4630. #ifdef OS2
  4631.     puterror(VTERM);
  4632. #endif /* OS2 */
  4633.     return(success = 1);
  4634.  
  4635.       case XYTIACT: {            /* SET TERM IDLE-ACTION */
  4636.       if ((y = cmkey(idlacts,nidlacts,"","",xxstring)) < 0)
  4637.         return(y);
  4638.       if (y == IDLE_OUT) {
  4639.           if ((x = cmtxt("string to send, may contain kverbs and variables"
  4640.                  , "\\v(newline)",&s,xxstring)) < 0)
  4641.         return(x);
  4642.           makestr(&tt_idlestr,brstrip(s)); /* (new) */
  4643.           tt_idlesnd_str = tt_idlestr; /* (old) */
  4644.       } else {
  4645.           if ((x = cmcfm()) < 0)
  4646.         return(x);
  4647.       }
  4648.       tt_idleact = y;
  4649.       return(success = 1);
  4650.       }
  4651. #endif /* CKTIDLE */
  4652.  
  4653.       case XYTDEB:            /* TERMINAL DEBUG */
  4654.     x = debses;            /* What it was before */
  4655.     y = seton(&debses);        /* Go parse ON or OFF */
  4656. #ifdef OS2
  4657.     if (y > 0)            /* Command succeeded? */
  4658.       if ((x != 0) && (debses == 0)) /* It was on and we turned it off? */
  4659.         os2debugoff();        /* Fix OS/2 coloration */
  4660. #endif /* OS2 */
  4661.     return(y);
  4662.  
  4663. #ifdef OS2
  4664.       case XYTASCRL:                    /* SET TERMINAL AUTOSCROLL */
  4665.           y = seton(&autoscroll);
  4666.           return(y);
  4667.  
  4668.       case XYTAPAGE:                    /* SET TERMINAL AUTOPAGE */
  4669.           y = seton(&wy_autopage);
  4670.           return(y);
  4671.  
  4672.       case XYTROL:            /* SET TERMINAL ROLL */
  4673.         if ((y = cmkey(rolltab,nroll,"scrollback mode","insert",xxstring))<0)
  4674.             return(y);
  4675.         if ((x = cmcfm()) < 0) return(x);
  4676.         tt_roll[VTERM] = y;
  4677.     return(success = 1);
  4678.  
  4679.       case XYTCTS:            /* SET TERMINAL TRANSMIT-TIMEOUT */
  4680.     y = cmnum("Maximum seconds to allow CTS off during CONNECT",
  4681.           "5",10,&x,xxstring);
  4682.     return(setnum(&tt_ctstmo,x,y,10000));
  4683.  
  4684.       case XYTCPG: {            /* SET TERMINAL CODE-PAGE */
  4685.         int i;
  4686.     int cp = -1;
  4687.     y = cmnum("PC code page to use during terminal emulation",
  4688.           ckitoa(os2getcp()),10,&x,xxstring);
  4689.     if ((x = setnum(&cp,x,y,11000)) < 0) return(x);
  4690.     if (os2setcp(cp) != 1) {
  4691. #ifdef NT
  4692.         if (isWin95())
  4693.           printf(
  4694.          "Sorry, Windows 95 does not support code page switching\n");
  4695.         else
  4696. #endif /* NT */
  4697.           printf(
  4698.          "Sorry, %d is not a valid code page for this system.\n",cp);
  4699.         return(-9);
  4700.     }
  4701.     /* Force the terminal character-sets conversions to be updated */
  4702.     for ( i = 0; i < 4; i++ )
  4703.       G[i].init = TRUE;
  4704.     return(1);
  4705.     }
  4706.  
  4707.       case XYTPAC:            /* SET TERMINAL OUTPUT-PACING */
  4708.     y = cmnum(
  4709.        "Pause between sending each character during CONNECT, milliseconds",
  4710.           "-1",10,&x,xxstring);
  4711.     return(setnum(&tt_pacing,x,y,10000));
  4712.  
  4713. #ifdef OS2MOUSE
  4714.       case XYTMOU: {            /* SET TERMINAL MOUSE */
  4715.       int old_mou = tt_mouse;
  4716.       if ((x = seton(&tt_mouse)) < 0)
  4717.         return(x);
  4718.       if (tt_mouse != old_mou)
  4719.         if (tt_mouse)
  4720.           os2_mouseon();
  4721.         else
  4722.           os2_mouseoff();
  4723.       return(1);
  4724.       }
  4725. #endif /* OS2MOUSE */
  4726. #endif /* OS2 */
  4727.  
  4728.       case XYTWID: {
  4729.       if ((y = cmnum(
  4730. #ifdef OS2
  4731.              "number of columns in display window during CONNECT",
  4732. #else
  4733.              "number of columns on your screen",
  4734. #endif /* OS2 */
  4735.              "80",10,&x,xxstring)) < 0)
  4736.             return(y);
  4737.           if ((y = cmcfm()) < 0) return(y);
  4738. #ifdef OS2
  4739.       if (x % 2) {
  4740.           printf("\n?The width must be an even value\n.");
  4741.           return(success = 0);
  4742.       }
  4743.  
  4744.       if ( IsOS2FullScreen() ) {
  4745.           if ( x != 40 && x != 80 && x != 132 ) {
  4746.           printf("\n?The width must be 40, 80,");
  4747. #ifdef NT
  4748.           printf(" or 132 under Windows 95.\n.");
  4749. #else /* NT */
  4750.           printf(" or 132 in a Full Screen session.\n.");
  4751. #endif /* NT */
  4752.           return(success = 0);
  4753.           }
  4754.       } else {
  4755.           if ( !IsWARPed() && x != 80 ) {
  4756.           printf("\n?OS/2 version is pre-WARP: the width must equal ");
  4757.           printf("80 in a Windowed Session\n.");
  4758.           return(success = 0);
  4759.                 }
  4760.           if (x < 20 || x > MAXTERMCOL ) {
  4761.           printf(
  4762.             "\n?The width must be between 20 and %d\n.",MAXTERMCOL);
  4763.           return(success = 0);
  4764.           }
  4765.       }
  4766. #ifndef KUI
  4767.       if (x > 8192/(tt_rows[VTERM]+1)) {
  4768.           printf(
  4769. "\n?The max screen area is 8192 cells: %d(rows) x %d(cols) = %d cells.\n",
  4770.              tt_rows[VTERM]+1,x,x*(tt_rows[VTERM]+1));
  4771.           return(success = 0);
  4772.       }
  4773. #endif /* KUI */
  4774.       os2_settermwidth(x);
  4775. #else  /* Not OS/2 */
  4776.       tt_cols = x;
  4777. #endif /* OS2 */
  4778.       return(success = 1);
  4779.       }
  4780.  
  4781.       case XYTHIG:
  4782.        if ((y = cmnum(
  4783. #ifdef OS2
  4784.  "number of rows in display window during CONNECT, not including status line",
  4785.  tt_status[VTERM]?"24":"25",
  4786. #else
  4787.  "24","number of rows on your screen",
  4788. #endif /* OS2 */
  4789.                10,&x,xxstring)) < 0)
  4790.       return(y);
  4791.     if ((y = cmcfm()) < 0) return(y);
  4792.  
  4793. #ifdef OS2
  4794.     if (tt_modechg == TVC_DIS) {
  4795.         printf("\n?SET TERMINAL VIDEO-CHANGE DISABLED\n");
  4796.         return(success = 0);
  4797.     }
  4798.     if (IsOS2FullScreen()) {
  4799.             if (tt_status[VTERM] && x != 24 && x != 42 && x != 49 && x != 59) {
  4800.                 printf("\n?The height must be 24, 42, 49");
  4801. #ifdef NT
  4802.                 printf(" or 59 under Windows 95.\n.");
  4803. #else /* NT */
  4804.                 printf(" or 59 in a Full Screen session.\n.");
  4805. #endif /* NT */
  4806.                 return(success = 0);
  4807.         } else if (!tt_status[VTERM] &&
  4808.                x != 25 &&
  4809.                x != 43 &&
  4810.                x != 50) {
  4811.                 printf("\n?The height must be 25, 43, 50");
  4812. #ifdef NT
  4813.                 printf(" or 60 under Windows 95.\n.");
  4814. #else /* NT */
  4815.                 printf(" or 60 in a Full Screen session.\n.");
  4816. #endif /* NT */
  4817.                 return(success = 0);
  4818.         }
  4819.     } else if (tt_modechg == TVC_W95) {
  4820.             if (tt_status[VTERM] && x != 24 && x != 42 && x != 49) {
  4821.                 printf("\n?The height must be 24, 42, 49");
  4822. #ifdef NT
  4823.                 printf(" under Windows 95.\n.");
  4824. #else /* NT */
  4825.                 printf(" in a Full Screen session.\n.");
  4826. #endif /* NT */
  4827.                 return(success = 0);
  4828.         } else if (!tt_status[VTERM] &&
  4829.                x != 25 &&
  4830.                x != 43 &&
  4831.                x != 50) {
  4832.                 printf("\n?The height must be 25, 43, 50");
  4833. #ifdef NT
  4834.                 printf(" under Windows 95.\n.");
  4835. #else /* NT */
  4836.                 printf(" in a Full Screen session.\n.");
  4837. #endif /* NT */
  4838.                 return(success = 0);
  4839.         }
  4840.     } else {
  4841.             if (x < 8 || x > MAXTERMROW ) {
  4842.                 printf("\n?The height must be between 8 and %d\n.",MAXTERMROW);
  4843.                 return(success = 0);
  4844.         }
  4845.     }
  4846. #ifndef KUI
  4847.         if (x > 8192/tt_cols[VTERM]) {
  4848.             printf(
  4849.  "\n?The max screen area is 8192 cells: %d(rows) x %d(cols) = %d cells.\n",
  4850.            x,tt_cols[VTERM],x*tt_cols[VTERM]);
  4851.             return(success = 0);
  4852.     }
  4853. #endif /* KUI */
  4854.         os2_settermheight(x);
  4855. #else  /* Not OS/2 */
  4856.     tt_rows = x;
  4857. #endif /* OS2 */
  4858.         return(success = 1);
  4859.  
  4860. #ifdef OS2
  4861.       case XYTPRN: {            /* Print Mode */
  4862.       extern bool xprint, cprint, aprint, uprint;
  4863.       if ((y = cmkey(prnmtab,nprnmtab,"","off", xxstring)) < 0) return(y);
  4864.       if ((x = cmcfm()) < 0) return(x);
  4865.       switch (y) {
  4866.         case 0:
  4867.           if (cprint || uprint || aprint || xprint)
  4868.                 printeroff();
  4869.           cprint = xprint = uprint = aprint = 0;
  4870.           break;
  4871.         case 1:
  4872.           if (!(cprint || uprint || aprint || xprint))
  4873.                 printeron();
  4874.           aprint = 1;
  4875.           cprint = xprint = uprint = 0;
  4876.           break;
  4877.         case 2:
  4878.           if (!(cprint || uprint || aprint || xprint))
  4879.                 printeron();
  4880.           cprint = 1;
  4881.           aprint = xprint = uprint = 0;
  4882.           break;
  4883.         case 3:
  4884.           if (!(cprint || uprint || aprint || xprint))
  4885.                 printeron();
  4886.           uprint = 1;
  4887.           aprint = xprint = cprint = 0;
  4888.           break;
  4889.       }
  4890.       return(1);
  4891.       }
  4892. #else
  4893. #ifdef XPRINT
  4894.       case XYTPRN: {
  4895.       extern int tt_print;
  4896.       if ((x = seton(&tt_print)) < 0)
  4897.         return(x);
  4898.       return(success = 1);
  4899.       }
  4900. #endif /* XPRINT */
  4901. #endif /* OS2 */
  4902.  
  4903. #ifdef OS2
  4904.       case XYTSCNM: {
  4905.       extern int decscnm, decscnm_usr;
  4906.       if ((y = cmkey(normrev,4,"",
  4907.              decscnm_usr?"reverse":"normal",
  4908.              xxstring)
  4909.            ) < 0)
  4910.         return(y);
  4911.       if ((x = cmcfm()) < 0) return(x);
  4912.       decscnm_usr = y;
  4913.       if (decscnm != decscnm_usr)
  4914.             flipscreen(VTERM);
  4915.       return(1);
  4916.     }
  4917.     case XYTOPTI:
  4918.         if ((y = cmkey(onoff,2,"",tt_diff_upd?"on":"off",
  4919.                         xxstring)) < 0) return(y);
  4920.         if ((x = cmcfm()) < 0) return(x);
  4921.         tt_diff_upd = y;
  4922.         return(1);
  4923.     case XYTUPD: {
  4924.     int mode, delay;
  4925.     if ((mode = cmkey(scrnupd,nscrnupd,"","fast",xxstring)) < 0) {
  4926.         return(mode);
  4927.         } else {
  4928.         y = cmnum(
  4929.         "Pause between FAST screen updates in CONNECT mode, milliseconds",
  4930.               "100",10,&x,xxstring
  4931.               );
  4932.         if (x < 0 || x > 1000 ) {
  4933.         printf(
  4934.         "\n?The update rate must be between 0 and 1000 milliseconds.\n"
  4935.                );
  4936.         return(success = 0);
  4937.             }
  4938.             if ((y = cmcfm()) < 0) return(y);
  4939.  
  4940.         updmode = tt_updmode = mode;
  4941.         return(setnum(&tt_update,x,y,10000));
  4942.     }
  4943.     }
  4944.     case XYTCTRL:
  4945.       if ((x = cmkey(termctrl,ntermctrl,"","7",xxstring)) < 0) {
  4946.           return(x);
  4947.       } else {
  4948.           if ((y = cmcfm()) < 0)
  4949.           return(y);
  4950.           switch ( x ) {
  4951.           case 8:
  4952.           send_c1 = send_c1_usr = TRUE;
  4953.           break;
  4954.           case 7:
  4955.           default:
  4956.           send_c1 = send_c1_usr = FALSE;
  4957.           break;
  4958.           }
  4959.       }
  4960.       return(success = TRUE);
  4961.       break;
  4962.  
  4963. #ifdef PCFONTS
  4964.       case XYTFON:
  4965.     if ( !IsOS2FullScreen() ) {
  4966.         printf(
  4967.         "\n?SET TERMINAL FONT is only supported in Full Screen sessions.\n");
  4968.         return(success = FALSE);
  4969.         }
  4970.  
  4971.     if ((x = cmkey(term_font,ntermfont,"","default",xxstring)) < 0) {
  4972.             return(x);
  4973.         } else {
  4974.         if ((y = cmcfm()) < 0) return(y);
  4975.             if ( !os2LoadPCFonts() ) {
  4976.                 tt_font = x;
  4977.         return(success = TRUE);
  4978.         } else {
  4979.         printf(
  4980.       "\n?PCFONTS.DLL is not available in CKERMIT executable directory.\n");
  4981.                 return(success = FALSE);
  4982.         }
  4983.     }
  4984.     break;
  4985. #else /* PCFONTS */
  4986. #ifdef NT
  4987. #ifdef KUI
  4988.     case XYTFON:
  4989.         if (ntermfont == 0)
  4990.             BuildFontTable(&term_font, &_term_font, &ntermfont);
  4991.     if (!(term_font && _term_font && ntermfont > 0)) {
  4992.         printf("\nUnable to enumerate fonts.\n");
  4993.         return(-9);
  4994.     }
  4995.         if ((x = cmkey(_term_font,ntermfont,"","",xxstring)) < 0) {
  4996.             return(x);
  4997.         }
  4998.         if ((z = cmnum("Height of Font",
  4999.                         "12",10,&y,xxstring)) < 0)
  5000.               return(z);
  5001.         if ((z = cmcfm()) < 0) return(z);
  5002.         tt_font = x;
  5003.         tt_font_size = y;
  5004.         KuiSetProperty( KUI_TERM_FONT, (long) tt_font, (long) tt_font_size ) ;
  5005.         return(success = TRUE);
  5006. #endif /* KUI */
  5007. #endif /* NT */
  5008. #endif /* PCFONTS */
  5009.  
  5010.       case XYTVCH: {
  5011.       extern int pheight, marginbot, cmd_rows, cmd_cols;
  5012.       if ((x = cmkey(tvctab,ntvctab,"",isWin95()?"win95-safe":"enabled",
  5013.              xxstring)) < 0)
  5014.         return(x);
  5015.       if ((y = cmcfm()) < 0) return(y);
  5016.       if (x != tt_modechg) {
  5017.           switch (x) {
  5018.         case TVC_DIS:
  5019.           /* When disabled the heights of all of the virtual screens */
  5020.           /* must be equal to the physical height of the console     */
  5021.           /* window and may not be changed.                          */
  5022.           /* The width of the window may not be altered.             */
  5023.           tt_modechg = TVC_ENA;            /* Temporary */
  5024.           if (marginbot > pheight-(tt_status[VTERM]?1:0))
  5025.             marginbot = pheight-(tt_status[VTERM]?1:0);
  5026.           tt_szchng[VCMD] = 1 ;
  5027.           tt_rows[VCMD] = pheight;
  5028.           VscrnInit(VCMD);
  5029.           SetCols(VCMD);
  5030.           cmd_rows = y;
  5031.  
  5032.           tt_szchng[VTERM] = 2 ;
  5033.           tt_rows[VTERM] = pheight - (tt_status[VTERM]?1:0);
  5034.           VscrnInit(VTERM);
  5035.  
  5036.           break;
  5037.  
  5038.         case TVC_ENA:
  5039.           /* When enabled the physical height of the console windows */
  5040.           /* should be adjusted to the height of the virtual screen  */
  5041.           /* The width may be set to anything.                       */
  5042.           /* nothing to do                                           */
  5043.           break;
  5044.  
  5045.           case TVC_W95:
  5046.           /* Win95-safe mode allows the physical height to change    */
  5047.           /* but restricts it to a width of 80 and a height equal to */
  5048.           /* 25, 43, or 50.  Must be adjusted now.                   */
  5049.           /* The virtual heights must be equal to the above.         */
  5050.           if (pheight != 25 && pheight != 43 && pheight != 50) {
  5051.               if (pheight < 25)
  5052.             y = 25;
  5053.               else if (pheight < 43)
  5054.             y = 43;
  5055.               else
  5056.             y = 50;
  5057.           } else
  5058.             y = pheight;
  5059.  
  5060.           tt_modechg = TVC_ENA;    /* Temporary */
  5061.  
  5062.           tt_szchng[VCMD] = 1;
  5063.           tt_rows[VCMD] = y;
  5064.           tt_cols[VCMD] = 80;
  5065.           VscrnInit(VCMD);
  5066.           SetCols(VCMD);
  5067.           cmd_rows = y;
  5068.           cmd_cols = 80;
  5069.  
  5070.           marginbot = y-(tt_status[VTERM]?1:0);
  5071.           tt_szchng[VTERM] = 2;
  5072.           tt_rows[VTERM] = y - (tt_status[VTERM]?1:0);
  5073.           tt_cols[VTERM] = 80;
  5074.           VscrnInit(VTERM);
  5075.           break;
  5076.           }
  5077.           tt_modechg = x;
  5078.       }
  5079.       return(1);
  5080.       }
  5081.       case XYTSTAT: {
  5082.           extern int marginbot;
  5083.           if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5084.           if ((x = cmcfm()) < 0) return(x);
  5085.           if (y != tt_status[VTERM] || y != tt_status_usr[VTERM]) {
  5086.               /* Might need to fixup the margins */
  5087.               if ( marginbot == VscrnGetHeight(VTERM)-(tt_status[VTERM]?1:0) )
  5088.                 if (y) {
  5089.                     marginbot--;
  5090.                 } else {
  5091.                     marginbot++;
  5092.                 }
  5093.               tt_status_usr[VTERM] = tt_status[VTERM] = y;
  5094.               if (y) {
  5095.                     tt_szchng[VTERM] = 2;
  5096.                     tt_rows[VTERM]--;
  5097.                     VscrnInit(VTERM);  /* Height set here */
  5098. #ifdef TNCODE
  5099.             if (TELOPT_ME(TELOPT_NAWS))
  5100.               tn_snaws();
  5101. #endif /* TNCODE */
  5102. #ifdef RLOGCODE
  5103.             if (TELOPT_ME(TELOPT_NAWS))
  5104.               rlog_naws();
  5105. #endif /* RLOGCODE */
  5106.               } else {
  5107.           tt_szchng[VTERM] = 1;
  5108.           tt_rows[VTERM]++;
  5109.           VscrnInit(VTERM);    /* Height set here */
  5110. #ifdef TNCODE
  5111.           if (TELOPT_ME(TELOPT_NAWS))
  5112.             tn_snaws();
  5113. #endif /* TNCODE */
  5114. #ifdef RLOGCODE
  5115.           if (TELOPT_ME(TELOPT_NAWS))
  5116.             rlog_naws();
  5117. #endif /* RLOGCODE */
  5118.               }
  5119.           }
  5120.           return(1);
  5121.       }
  5122. #endif /* OS2 */
  5123.  
  5124. #ifdef NT
  5125.       case XYTATTBUG:
  5126.     if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5127.     if ((x = cmcfm()) < 0) return(x);
  5128.     tt_attr_bug = y;
  5129.     return(1);
  5130. #endif /* NT */
  5131.  
  5132. #ifdef OS2
  5133.       case XYTSGRC:
  5134.     if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5135.     if ((x = cmcfm()) < 0) return(x);
  5136.     sgrcolors = y;
  5137.     return(1);
  5138.  
  5139.       case XYTSEND:
  5140.       if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5141.       if ((x = cmcfm()) < 0) return(x);
  5142.       tt_senddata = y;
  5143.       return(1);
  5144.  
  5145.       case XYTSEOB:
  5146.       if ((y = cmkey(ttyseobtab,2,"","us_cr",xxstring)) < 0) return(y);
  5147.       if ((x = cmcfm()) < 0) return(x);
  5148.       wy_blockend = y;
  5149.       return(1);
  5150.  
  5151.       case XYTURLHI: {
  5152.           int done = 0, attr = VT_CHAR_ATTR_NORMAL;
  5153.  
  5154.       if ((x = cmkey(onoff,2,"","on",xxstring)) < 0)
  5155.         return(x);
  5156.           if (x) {
  5157.               z = 0;
  5158.               while (!done) {
  5159.                   if ((y = cmkey(ttyprotab,nprotect,"",
  5160.                  z?"done":"reverse",xxstring)) < 0)
  5161.             return(y);
  5162.                   switch (y) {
  5163.             case TTATTDONE:
  5164.                       done = TRUE;
  5165.                       break;
  5166.             case TTATTBLI:
  5167.                       attr |= VT_CHAR_ATTR_BLINK;
  5168.                       break;
  5169.             case TTATTREV:
  5170.                       attr |= VT_CHAR_ATTR_REVERSE;
  5171.                       break;
  5172.             case TTATTUND:
  5173.                       attr |= VT_CHAR_ATTR_UNDERLINE;
  5174.                       break;
  5175.             case TTATTBLD:
  5176.                       attr |= VT_CHAR_ATTR_BOLD;
  5177.                       break;
  5178.             case TTATTDIM:
  5179.                       attr |= VT_CHAR_ATTR_DIM;
  5180.                       break;
  5181.             case TTATTINV:
  5182.                       attr |= VT_CHAR_ATTR_INVISIBLE;
  5183.                       break;
  5184.             case TTATTNOR:
  5185.                       break;
  5186.                   }
  5187.                   z = 1;        /* One attribute has been chosen */
  5188.               }
  5189.           }
  5190.           if ((z = cmcfm()) < 0) return(z);
  5191.  
  5192.           tt_url_hilite = x;
  5193.           if (x)
  5194.         tt_url_hilite_attr = attr;
  5195.           return(1);
  5196.       }
  5197.       case XYTATTR:
  5198.     if ((x = cmkey(ttyattrtab,nattrib,"","underline",xxstring)) < 0)
  5199.       return(x);
  5200.     switch (x) {
  5201.       case TTATTBLI:
  5202.         if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5203.         if ((x = cmcfm()) < 0) return(x);
  5204.         trueblink = y;
  5205. #ifndef KUI
  5206.         if ( !trueblink && trueunderline ) {
  5207.         trueunderline = 0;
  5208.         printf("Warning: Underline being simulated by color.\n");
  5209.         }
  5210.  
  5211. #endif /* KUI */
  5212.         break;
  5213.  
  5214.       case TTATTREV:
  5215.         if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5216.         if ((x = cmcfm()) < 0) return(x);
  5217.         truereverse = y;
  5218.         break;
  5219.  
  5220.       case TTATTUND:
  5221.         if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5222.         if ((x = cmcfm()) < 0) return(x);
  5223.         trueunderline = y;
  5224. #ifndef KUI
  5225.         if (!trueblink && trueunderline) {
  5226.         trueblink = 1;
  5227.         printf("Warning: True blink mode is active.\n");
  5228.         }
  5229. #endif /* KUI */
  5230.         break;
  5231.  
  5232.       case TTATTPRO: {    /* Set default Protected Character attribute */
  5233.           extern vtattrib WPattrib;    /* current WP Mode Attrib */
  5234.           extern vtattrib defWPattrib; /* default WP Mode Attrib */
  5235.           vtattrib wpa = {0,0,0,0,0,1,0,0,0};    /* Protected */
  5236.           int done = 0;
  5237.  
  5238.           x = 0;
  5239.           while (!done) {
  5240.           if ((y = cmkey(ttyprotab,nprotect,"",
  5241.                  x?"done":"dim",xxstring)) < 0)
  5242.             return(y);
  5243.           switch (y) {
  5244.             case TTATTNOR:
  5245.               break;
  5246.             case TTATTBLI:    /* Blinking doesn't work */
  5247.               wpa.blinking = TRUE;
  5248.               break;
  5249.             case TTATTREV:
  5250.               wpa.reversed = TRUE;
  5251.               break;
  5252.             case TTATTUND:
  5253.               wpa.underlined = TRUE;
  5254.               break;
  5255.             case TTATTBLD:
  5256.               wpa.bold = TRUE;
  5257.               break;
  5258.             case TTATTDIM:
  5259.               wpa.dim = TRUE;
  5260.               break;
  5261.             case TTATTINV:
  5262.               wpa.invisible = TRUE ;
  5263.               break;
  5264.             case TTATTDONE:
  5265.               done = TRUE;
  5266.               break;
  5267.           }
  5268.           x = 1;        /* One attribute has been chosen */
  5269.           }
  5270.           if ((x = cmcfm()) < 0) return(x);
  5271.           WPattrib = defWPattrib = wpa;
  5272.           break;
  5273.       }
  5274.     }
  5275.     return(1);
  5276.  
  5277.       case XYTKEY: {            /* SET TERMINAL KEY */
  5278.       int t, x, y;
  5279.       int clear = 0, deflt = 0;
  5280.       int confirmed = 0;
  5281.       int flag = 0;
  5282.       int kc = -1;            /* Key code */
  5283.           int litstr = 0;               /* Literal String? */
  5284.       char *s = NULL;        /* Key binding */
  5285. #ifndef NOKVERBS
  5286.       char *p = NULL;        /* Worker */
  5287. #endif /* NOKVERBS */
  5288.       con_event defevt;
  5289.       extern int os2gks;
  5290.       extern int mskkeys;
  5291.       extern int initvik;
  5292.           struct FDB kw,sw,nu,cm;
  5293.  
  5294.           defevt.type = error;
  5295.  
  5296.       if ((t = cmkey(ttkeytab,nttkey,"","",xxstring)) < 0)
  5297.         return(t);
  5298.       cmfdbi(&nu,            /* First FDB - command switches */
  5299.          _CMNUM,        /* fcode */
  5300.          "/literal, keycode, or action",
  5301.          "",            /* default */
  5302.          "",            /* addtl string data */
  5303.          10,            /* addtl numeric data 1: radix */
  5304.          0,            /* addtl numeric data 2: 0 */
  5305.          xxstring,        /* Processing function */
  5306.          NULL,            /* Keyword table */
  5307.          &sw            /* Pointer to next FDB */
  5308.          );            /*  */
  5309.       cmfdbi(&sw,            /* Second FDB - switches */
  5310.          _CMKEY,        /* fcode */
  5311.          "",
  5312.          "",            /* default */
  5313.          "",            /* addtl string data */
  5314.          nstrmswitab,        /* addtl numeric data 1: tbl size */
  5315.          4,            /* addtl numeric data 2: 4 = cmswi */
  5316.          xxstring,        /* Processing function */
  5317.          strmswitab,        /* Keyword table */
  5318.          &kw            /* Pointer to next FDB */
  5319.          );
  5320.       cmfdbi(&kw,            /* Third FDB - command switches */
  5321.          _CMKEY,        /* fcode */
  5322.          "/literal, keycode, or action",
  5323.          "",            /* default */
  5324.          "",            /* addtl string data */
  5325.          nstrmkeytab,        /* addtl numeric data 1: tbl size */
  5326.          0,            /* addtl numeric data 2 */
  5327.          xxstring,        /* Processing function */
  5328.          strmkeytab,        /* Keyword table */
  5329.          &cm            /* Pointer to next FDB */
  5330.          );
  5331.       cmfdbi(&cm,            /* Final FDB - Confirmation */
  5332.          _CMCFM,        /* fcode */
  5333.          "",
  5334.          "",            /* default */
  5335.          "",            /* addtl string data */
  5336.          0,                 /* addtl numeric data 1: tbl size */
  5337.          0,            /* addtl numeric data 2: 4 = cmswi */
  5338.          xxstring,        /* Processing function */
  5339.          NULL,            /* Keyword table */
  5340.          NULL            /* Pointer to next FDB */
  5341.          );
  5342.       while (kc < 0) {
  5343.           x = cmfdb(&nu);        /* Parse something */
  5344.               if (x < 0)
  5345.                 return(x);
  5346.  
  5347.           switch (cmresult.fcode) {
  5348.                 case _CMCFM:
  5349.           printf(" Press key to be defined: ");
  5350.           conbin((char)escape);    /* Put terminal in binary mode */
  5351.           os2gks = 0;        /* Turn off Kverb preprocessing */
  5352.           kc = congks(0);    /* Get character or scan code */
  5353.           os2gks = 1;        /* Turn on Kverb preprocessing */
  5354.           concb((char)escape);    /* Restore terminal to cbreak mode */
  5355.           if (kc < 0) {        /* Check for error */
  5356.               printf("?Error reading key\n");
  5357.               return(0);
  5358.           }
  5359.           shokeycode(kc,t);    /* Show current definition */
  5360.           flag = 1;        /* Remember it's a multiline command */
  5361.                   break;
  5362.         case _CMNUM:
  5363.           kc = cmresult.nresult;
  5364.           break;
  5365.         case _CMKEY:
  5366.           if (cmresult.fdbaddr == &sw) { /* Switch */
  5367.               if (cmresult.nresult == 0)
  5368.             litstr = 1;
  5369.           } else if (cmresult.fdbaddr == &kw) { /* Keyword */
  5370.               if (cmresult.nresult == 0)
  5371.             clear = 1;
  5372.               else
  5373.             deflt = 1;
  5374.               if ((x = cmcfm()) < 0)
  5375.             return(x);
  5376.               if (clear)
  5377.             clearkeymap(t);
  5378.               else if (deflt)
  5379.                 defaultkeymap(t);
  5380.               initvik = 1;
  5381.               return(1);
  5382.           }
  5383.           }
  5384.       }
  5385.  
  5386.     /* Normal SET TERMINAL KEY <terminal> <scancode> <value> command... */
  5387.  
  5388.       if (mskkeys)
  5389.         kc = msktock(kc);
  5390.  
  5391.       if (kc < 0 || kc >= KMSIZE) {
  5392.           printf("?key code must be between 0 and %d\n", KMSIZE - 1);
  5393.           return(-9);
  5394.       }
  5395.       if (kc == escape) {
  5396.           printf("Sorry, %d is the CONNECT-mode escape character\n",kc);
  5397.           return(-9);
  5398.       }
  5399.       wideresult = -1;
  5400.       if (flag) {
  5401.           cmsavp(psave,PROMPTL);
  5402.           cmsetp(" Enter new definition: ");
  5403.           cmini(ckxech);
  5404.       }
  5405.     def_again:
  5406.       if (flag) prompt(NULL);
  5407.       if ((y = cmtxt("key definition,\n\
  5408.  or Ctrl-C to cancel this command,\n\
  5409.  or Enter to restore default definition",
  5410.              "",&s,NULL)) < 0) {
  5411.           if (flag)            /* Handle parse errors */
  5412.         goto def_again;
  5413.           else
  5414.         return(y);
  5415.       }
  5416.       s = brstrip(s);
  5417. #ifndef NOKVERBS
  5418.       p = s;            /* Save this place */
  5419. #endif /* NOKVERBS */
  5420. /*
  5421.   If the definition included any \Kverbs, quote the backslash so the \Kverb
  5422.   will still be in the definition when the key is pressed.  We don't do this
  5423.   in zzstring(), because \Kverbs are valid only in this context and nowhere
  5424.   else.
  5425.  
  5426.   We use this code active for all versions that support SET KEY, even if they
  5427.   don't support \Kverbs, because otherwise \K would behave differently for
  5428.   different versions.
  5429. */
  5430.       for (x = 0, y = 0; s[x]; x++, y++) { /* Convert \K to \\K */
  5431.           if ((x > 0) &&
  5432.           (s[x] == 'K' || s[x] == 'k')
  5433.           ) {            /* Have K */
  5434.  
  5435.           if ((x == 1 && s[x-1] == CMDQ) ||
  5436.               (x > 1 && s[x-1] == CMDQ && s[x-2] != CMDQ)) {
  5437.               line[y++] = CMDQ;    /* Make it \\K */
  5438.           }
  5439.           if (x > 1 && s[x-1] == '{' && s[x-2] == CMDQ) {
  5440.               line[y-1] = CMDQ;    /* Have \{K */
  5441.               line[y++] = '{';    /* Make it \\{K */
  5442.           }
  5443.           }
  5444.           line[y] = s[x];
  5445.       }
  5446.       line[y++] = NUL;        /* Terminate */
  5447.       s = line + y + 1;        /* Point to after it */
  5448.       x = LINBUFSIZ - (int) strlen(line) - 1; /* Get remaining space */
  5449.       if ((x < (LINBUFSIZ / 2)) ||
  5450.           (zzstring(line, &s, &x) < 0)) { /* Expand variables, etc. */
  5451.           printf("?Key definition too long\n");
  5452.           if (flag) cmsetp(psave);
  5453.           return(-9);
  5454.       }
  5455.       s = line + y + 1;        /* Point to result. */
  5456.  
  5457. #ifndef NOKVERBS
  5458. /*
  5459.   Special case: see if the definition starts with a \Kverb.
  5460.   If it does, point to it with p, otherwise set p to NULL.
  5461. */
  5462.       p = s;
  5463.       if (*p++ == CMDQ) {
  5464.           if (*p == '{') p++;
  5465.           p = (*p == 'k' || *p == 'K') ? p + 1 : NULL;
  5466.       }
  5467. #endif /* NOKVERBS */
  5468.  
  5469.       switch (strlen(s)) {        /* Action depends on length */
  5470.         case 0:            /* Clear individual key def */
  5471.           deletekeymap(t,kc);
  5472.           break;
  5473.         case 1:
  5474.               if (!litstr) {
  5475.           defevt.type = key;    /* Single character */
  5476.           defevt.key.scancode = *s;
  5477.           break;
  5478.               }
  5479.         default:            /* Character string */
  5480. #ifndef NOKVERBS
  5481.           if (p) {
  5482.           y = xlookup(kverbs,p,nkverbs,&x); /* Look it up */
  5483.           /* Need exact match */
  5484.           debug(F101,"set key kverb lookup",0,y);
  5485.           if (y > -1) {
  5486.               defevt.type = kverb;
  5487.               defevt.kverb.id = y;
  5488.               break;
  5489.           }
  5490.           }
  5491. #endif /* NOKVERBS */
  5492.               if (litstr) {
  5493.           defevt.type = literal;
  5494.           defevt.literal.string = (char *) malloc(strlen(s)+1);
  5495.           if (defevt.literal.string)
  5496.             strcpy(defevt.literal.string, s); /* safe */
  5497.               } else {
  5498.           defevt.type = macro;
  5499.           defevt.macro.string = (char *) malloc(strlen(s)+1);
  5500.           if (defevt.macro.string)
  5501.             strcpy(defevt.macro.string, s); /* safe */
  5502.               }
  5503.           break;
  5504.       }
  5505.       insertkeymap(t, kc, defevt);
  5506.       if (flag)
  5507.         cmsetp(psave);
  5508.       initvik = 1;            /* Update VIK table */
  5509.       return(1);
  5510.       }
  5511.  
  5512. #ifdef PCTERM
  5513.       case XYTPCTERM:                   /* PCTERM Keyboard Mode */
  5514.         if ((x = seton(&tt_pcterm)) < 0) return(x);
  5515.         return(success = 1);
  5516. #endif /* PCTERM */
  5517. #endif /* OS2 */
  5518.  
  5519. #ifdef CK_TRIGGER
  5520.       case XYTRIGGER:
  5521.     if ((y = cmtxt("String to trigger automatic return to command mode",
  5522.                "",&s,xxstring)) < 0)
  5523.       return(y);
  5524.     makelist(s,tt_trigger,TRIGGERS);
  5525.     return(1);
  5526. #endif /* CK_TRIGGER */
  5527.  
  5528. #ifdef OS2
  5529.       case XYTSAC:
  5530.     if ((y = cmnum("ASCII value to use for spacing attributes",
  5531.                "32",10,&x,xxstring)) < 0)
  5532.           return(y);
  5533.     if ((y = cmcfm()) < 0) return(y);
  5534.     tt_sac = x;
  5535.     return(success = 1);
  5536.  
  5537.       case XYTKBDGL: {      /* SET TERM KBD-FOLLOWS-GL/GR */
  5538.           extern int tt_kb_glgr;        /* from ckoco3.c */
  5539.           if ((x = seton(&tt_kb_glgr)) < 0)
  5540.               return(x);
  5541.           return(success = 1);
  5542.       }
  5543. #ifndef NOCSETS
  5544.       case XYTVTLNG:        /* SET TERM DEC-LANGUAGE */
  5545.     if ((y = cmkey(vtlangtab,nvtlangtab,"VT language",
  5546.                IS97801(tt_type_mode)?"german":"north-american",
  5547.                        xxstring)) < 0)
  5548.       return(y);
  5549.     if ((x = cmcfm()) < 0) return(x);
  5550.  
  5551.     /* A real VT terminal would use the language to set the   */
  5552.     /* default keyboard language for both 8-bit multinational */
  5553.     /* and 7-bit national modes.  For 8-bit mode it would     */
  5554.     /* set the terminal character-set to the ISO set if it    */
  5555.     /* is not already set.                                    */
  5556.     /* Latin-1 can be replaced by DEC Multinational           */
  5557.     switch (y) {
  5558.           case VTL_NORTH_AM:  /* North American */
  5559.         /* Multinational: Latin-1   */
  5560.         /* National:      US_ASCII  */
  5561.         dec_lang = y;
  5562.         dec_nrc = TX_ASCII;
  5563.         dec_kbd = TX_8859_1;
  5564.         break;
  5565.           case VTL_BRITISH :
  5566.         /* Multinational: Latin-1   */
  5567.         /* National:      UK_ASCII  */
  5568.         dec_lang = y;
  5569.         dec_nrc = TX_BRITISH;
  5570.         dec_kbd = TX_8859_1;
  5571.         break;
  5572.           case VTL_FRENCH  :
  5573.           case VTL_BELGIAN :
  5574.           case VTL_CANADIAN:
  5575.         /* Multinational: Latin-1   */
  5576.         /* National:      FR_ASCII  */
  5577.         dec_lang = y;
  5578.         dec_nrc = TX_FRENCH;
  5579.         dec_kbd = TX_8859_1;
  5580.         break;
  5581.           case VTL_FR_CAN  :
  5582.         /* Multinational: Latin-1   */
  5583.         /* National:      FC_ASCII  */
  5584.         dec_lang = y;
  5585.         dec_nrc = TX_CN_FRENCH;
  5586.         dec_kbd = TX_8859_1;
  5587.         break;
  5588.           case VTL_DANISH  :
  5589.           case VTL_NORWEGIA:
  5590.         /* Multinational: Latin-1   */
  5591.         /* National:      NO_ASCII  */
  5592.         dec_lang = y;
  5593.         dec_nrc = TX_NORWEGIAN;
  5594.         dec_kbd = TX_8859_1;
  5595.         break;
  5596.           case VTL_FINNISH :
  5597.         /* Multinational: Latin-1   */
  5598.         /* National:      FI_ASCII  */
  5599.         dec_lang = y;
  5600.         dec_nrc = TX_FINNISH;
  5601.         dec_kbd = TX_8859_1;
  5602.         break;
  5603.           case VTL_GERMAN  :
  5604.         /* Multinational: Latin-1   */
  5605.         /* National:      GR_ASCII  */
  5606.         dec_lang = y;
  5607.         dec_nrc = TX_GERMAN;
  5608.         dec_kbd = TX_8859_1;
  5609.         break;
  5610.           case VTL_DUTCH   :
  5611.         /* Multinational: Latin-1   */
  5612.         /* National:      DU_ASCII  */
  5613.         dec_lang = y;
  5614.         dec_nrc = TX_DUTCH;
  5615.         dec_kbd = TX_8859_1;
  5616.         break;
  5617.           case VTL_ITALIAN :
  5618.         /* Multinational: Latin-1   */
  5619.         /* National:      IT_ASCII  */
  5620.         dec_lang = y;
  5621.         dec_nrc = TX_ITALIAN;
  5622.         dec_kbd = TX_8859_1;
  5623.         break;
  5624.           case VTL_SW_FR   :
  5625.           case VTL_SW_GR   :
  5626.         /* Multinational: Latin-1   */
  5627.         /* National:      CH_ASCII  */
  5628.         dec_lang = y;
  5629.         dec_nrc = TX_SWISS;
  5630.         dec_kbd = TX_8859_1;
  5631.         break;
  5632.           case VTL_SWEDISH :
  5633.         /* Multinational: Latin-1   */
  5634.         /* National:      SW_ASCII  */
  5635.         dec_lang = y;
  5636.         dec_nrc = TX_SWEDISH;
  5637.         dec_kbd = TX_8859_1;
  5638.         break;
  5639.           case VTL_SPANISH :
  5640.         /* Multinational: Latin-1   */
  5641.         /* National:      SP_ASCII  */
  5642.         dec_lang = y;
  5643.         dec_nrc = TX_SPANISH;
  5644.         dec_kbd = TX_8859_1;
  5645.         break;
  5646.           case VTL_PORTUGES:
  5647.         /* Multinational: Latin-1   */
  5648.         /* National:      Portugese ASCII  */
  5649.         dec_lang = y;
  5650.         dec_nrc = TX_PORTUGUESE;
  5651.         dec_kbd = TX_8859_1;
  5652.         break;
  5653.           case VTL_HEBREW  :
  5654.         /* Multinational: Latin-Hebrew / DEC-Hebrew  */
  5655.         /* National:      DEC 7-bit Hebrew  */
  5656.         dec_lang = y;
  5657.         dec_nrc = TX_HE7;
  5658.         dec_kbd = TX_8859_8;
  5659.         break;
  5660.           case VTL_GREEK   :
  5661.         /* Multinational: Latin-Greek / DEC-Greek   */
  5662.         /* National:      DEC Greek NRC             */
  5663.         /* is ELOT927 equivalent to DEC Greek????   */
  5664.         dec_lang = y;
  5665.         dec_nrc = TX_ELOT927;
  5666.         dec_kbd = TX_8859_7;
  5667.         break;
  5668. #ifdef COMMENT
  5669.           case VTL_TURK_Q  :
  5670.           case VTL_TURK_F  :
  5671.         /* Multinational: Latin-Turkish / DEC-Turkish   */
  5672.         /* National:      DEC 7-bit Turkish             */
  5673.         break;
  5674. #endif /* COMMENT */
  5675.           case VTL_HUNGARIA:
  5676.         /* Multinational: Latin-2   */
  5677.         /* National:      no national mode  */
  5678.         dec_lang = y;
  5679.         dec_nrc = TX_HUNGARIAN;
  5680.         dec_kbd = TX_8859_2;
  5681.         break;
  5682.           case VTL_SLOVAK  :
  5683.           case VTL_CZECH   :
  5684.           case VTL_POLISH  :
  5685.           case VTL_ROMANIAN:
  5686.         /* Multinational: Latin-2   */
  5687.         /* National:      no national mode  */
  5688.         dec_lang = y;
  5689.         dec_nrc = TX_ASCII;
  5690.         dec_kbd = TX_8859_2;
  5691.         break;
  5692.           case VTL_RUSSIAN :
  5693.         /* Multinational: Latin-Cyrillic / KOI-8   */
  5694.         /* National:      DEC Russian NRC  */
  5695.         dec_lang = y;
  5696.         dec_nrc = TX_KOI7;
  5697.         dec_kbd = TX_8859_5;
  5698.         break;
  5699.           case VTL_LATIN_AM:
  5700.         /* Multinational: not listed in table   */
  5701.         /* National:      not listed in table  */
  5702.         dec_lang = y;
  5703.         dec_nrc = TX_ASCII;
  5704.         dec_kbd = TX_8859_1;
  5705.         break;
  5706. #ifdef COMMENT
  5707.           case VTL_SCS     :
  5708.         /* Multinational: Latin-2   */
  5709.         /* National:      SCS NRC   */
  5710.         break;
  5711. #endif /* COMMENT */
  5712.           default:
  5713.         return(success = 0);
  5714.     }
  5715.     if (IS97801(tt_type_mode)) {
  5716.         SNI_bitmode(cmask == 0377 ? 8 : 7);
  5717.     }
  5718.     return(success = 1);
  5719. #endif /* NOCSETS */
  5720.  
  5721.       case XYTVTNRC: {            /* SET TERM DEC-NRC-MODE */
  5722.       extern int decnrcm_usr, decnrcm;        /* from ckoco3.c */
  5723.       if ((x = seton(&decnrcm_usr)) < 0)
  5724.             return(x);
  5725.       decnrcm = decnrcm_usr;
  5726.       return(success = 1);
  5727.       }
  5728.       case XYTSNIPM: {                  /* SET TERM SNI-PAGEMODE */
  5729.           extern int sni_pagemode, sni_pagemode_usr;
  5730.           if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5731.           if ((x = cmcfm()) < 0) return(x);
  5732.           sni_pagemode_usr = sni_pagemode = y;
  5733.           return(success = 1);
  5734.       }
  5735.       case XYTSNISM: {                  /* SET TERM SNI-SCROLLMODE */
  5736.           extern int sni_scroll_mode, sni_scroll_mode_usr;
  5737.           if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5738.           if ((x = cmcfm()) < 0) return(x);
  5739.           sni_scroll_mode_usr = sni_scroll_mode = y;
  5740.           return(success = 1);
  5741.       }
  5742.       case XYTSNICC: {  /* SET TERM SNI-CH.CODE */
  5743.       extern int sni_chcode_usr;
  5744.       if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  5745.       if ((x = cmcfm()) < 0) return(x);
  5746.       sni_chcode_usr = y;
  5747.       SNI_chcode(y);
  5748.       return(success = 1);
  5749.       }
  5750.       case XYTSNIFV: {  /* SET TERM SNI-FIRMWARE-VERSIONS */
  5751.       extern CHAR sni_kbd_firmware[], sni_term_firmware[];
  5752.       CHAR kbd[7],term[7];
  5753.  
  5754.       if ((x = cmfld("Keyboard Firmware Version",sni_kbd_firmware,
  5755.              &s, xxstring)) < 0)
  5756.             return(x);
  5757.       if ((int)strlen(s) != 6) {
  5758.           printf("?Sorry - the firmware version must be 6 digits long\n");
  5759.           return(-9);
  5760.       }
  5761.       for (i = 0; i < 6; i++) {
  5762.           if (!isdigit(s[i])) {
  5763.    printf("?Sorry - the firmware version can only contain digits [0-9]\n");
  5764.                   return(-9);
  5765.               }
  5766.       }
  5767.       ckstrncpy(kbd,s,7);
  5768.  
  5769.       if ((x = cmfld("Terminal Firmware Version",sni_term_firmware,
  5770.              &s, xxstring)) < 0)
  5771.             return(x);
  5772.       if ((int)strlen(s) != 6) {
  5773.           printf("?Sorry - the firmware version must be 6 digits long\n");
  5774.           return(-9);
  5775.       }
  5776.       for (i = 0; i < 6; i++) {
  5777.           if (!isdigit(s[i])) {
  5778.    printf("?Sorry - the firmware version can only contain digits [0-9]\n");
  5779.                    return(-9);
  5780.               }
  5781.       }
  5782.       ckstrncpy(term,s,7);
  5783.       if ((x = cmcfm()) < 0) return(x);
  5784.  
  5785.       ckstrncpy(sni_kbd_firmware,kbd,7);
  5786.       ckstrncpy(sni_term_firmware,term,7);
  5787.       return(success = 1);
  5788.     }
  5789. #endif /* OS2 */
  5790.  
  5791.       default:                /* Shouldn't get here. */
  5792.     return(-2);
  5793.     }
  5794. #endif /* MAC */
  5795. #ifdef COMMENT
  5796.     /*
  5797.       This was supposed to shut up picky compilers but instead it makes
  5798.       most compilers complain about "statement not reached".
  5799.     */
  5800.     return(-2);
  5801. #endif /* COMMENT */
  5802. #ifdef OS2
  5803. return(-2);
  5804. #endif /* OS2 */
  5805. }
  5806.  
  5807. #ifdef OS2
  5808. int
  5809. settitle(void) {
  5810.     extern char usertitle[];
  5811.     if ((y = cmtxt("title text","",&s,xxstring)) < 0)
  5812.       return(y);
  5813. #ifdef IKSD
  5814.     if (inserver) {
  5815.         printf("?Sorry, command disabled.\r\n");
  5816.         return(success = 0);
  5817.     }
  5818. #endif /* IKSD */
  5819.  
  5820.     ckstrncpy(usertitle,s,64);
  5821.     os2settitle("",1);
  5822.     return(1);
  5823. }
  5824.  
  5825. static struct keytab dialertab[] = {    /* K95 Dialer types */
  5826.     "backspace",     0, 0,
  5827.     "enter",           1, 0
  5828. };
  5829. static int ndialer = 2;
  5830.  
  5831. int
  5832. setdialer(void) {
  5833.     int t, x, y;
  5834.     int clear = 0, deflt = 0;
  5835.     int kc;                /* Key code */
  5836.     char *s = NULL;            /* Key binding */
  5837. #ifndef NOKVERBS
  5838.     char *p = NULL;            /* Worker */
  5839. #endif /* NOKVERBS */
  5840.     con_event defevt;
  5841.     extern int os2gks;
  5842.     extern int mskkeys;
  5843.     extern int initvik;
  5844.  
  5845.     defevt.type = error;
  5846.  
  5847.     if (( x = cmkey(dialertab, ndialer,
  5848.             "Kermit-95 dialer work-arounds",
  5849.             "", xxstring)) < 0 )
  5850.       return(x);
  5851.     switch (x) {
  5852.       case 0:                /* Backspace */
  5853.     kc = 264;
  5854.     break;
  5855.       case 1:                /* Enter */
  5856.     kc = 269;
  5857.     break;
  5858.       default:
  5859.     printf("Illegal value in setdialer()\n");
  5860.     return(-9);
  5861.     }
  5862.     if ((y = cmtxt("Key definition","",&s,xxstring)) < 0)
  5863.       return(y);
  5864.  
  5865. #ifdef IKSD
  5866.     if (inserver) {
  5867.         printf("?Sorry, command disabled.\r\n");
  5868.         return(success = 0);
  5869.     }
  5870. #endif /* IKSD */
  5871.     s = brstrip(s);
  5872. #ifndef NOKVERBS
  5873.     p = s;                /* Save this place */
  5874. #endif /* NOKVERBS */
  5875. /*
  5876.   If the definition included any \Kverbs, quote the backslash so the \Kverb
  5877.   will still be in the definition when the key is pressed.  We don't do this
  5878.   in zzstring(), because \Kverbs are valid only in this context and nowhere
  5879.   else.
  5880.  
  5881.   We use this code active for all versions that support SET KEY, even if they
  5882.   don't support \Kverbs, because otherwise \K would behave differently for
  5883.   different versions.
  5884. */
  5885.     for (x = 0, y = 0; s[x]; x++, y++) { /* Convert \K to \\K */
  5886.     if ((x > 0) &&
  5887.         (s[x] == 'K' || s[x] == 'k')
  5888.         ) {                /* Have K */
  5889.  
  5890.         if ((x == 1 && s[x-1] == CMDQ) ||
  5891.         (x > 1 && s[x-1] == CMDQ && s[x-2] != CMDQ)) {
  5892.         line[y++] = CMDQ;    /* Make it \\K */
  5893.         }
  5894.         if (x > 1 && s[x-1] == '{' && s[x-2] == CMDQ) {
  5895.           line[y-1] = CMDQ;    /* Have \{K */
  5896.           line[y++] = '{';    /* Make it \\{K */
  5897.         }
  5898.     }
  5899.     line[y] = s[x];
  5900.     }
  5901.     line[y++] = NUL;            /* Terminate */
  5902.     s = line + y + 1;            /* Point to after it */
  5903.     x = LINBUFSIZ - (int) strlen(line) - 1; /* Calculate remaining space */
  5904.     if ((x < (LINBUFSIZ / 2)) ||
  5905.     (zzstring(line, &s, &x) < 0)) { /* Expand variables, etc. */
  5906.     printf("?Key definition too long\n");
  5907.     return(-9);
  5908.     }
  5909.     s = line + y + 1;            /* Point to result. */
  5910.  
  5911. #ifndef NOKVERBS
  5912. /*
  5913.   Special case: see if the definition starts with a \Kverb.
  5914.   If it does, point to it with p, otherwise set p to NULL.
  5915. */
  5916.     p = s;
  5917.     if (*p++ == CMDQ) {
  5918.     if (*p == '{') p++;
  5919.     p = (*p == 'k' || *p == 'K') ? p + 1 : NULL;
  5920.     }
  5921. #endif /* NOKVERBS */
  5922.  
  5923.     /* Now reprogram the default value for all terminal types */
  5924.     /* remember to treat Wyse and Televideo terminals special */
  5925.     /* because of their use of Kverbs for Backspace and Enter */
  5926.     for (t = 0; t <= TT_MAX; t++) {
  5927.         if ( ISDG200(t) && kc == 264) {
  5928.         extern char * udkfkeys[] ;
  5929.         if (kc == 264) {        /* \Kdgbs */
  5930.         if (udkfkeys[83])
  5931.           free(udkfkeys[83]);
  5932.         udkfkeys[83] = strdup(s);
  5933.         }
  5934.     } else if (ISWYSE(t) || ISTVI(t)) {
  5935.         extern char * udkfkeys[] ;
  5936.         if (kc == 264) {        /* \Kwybs or \Ktvibs */
  5937.         if (udkfkeys[32])
  5938.           free(udkfkeys[32]);
  5939.         udkfkeys[32] = strdup(s);
  5940.         }
  5941.         if (kc == 269) {        /* \Kwyenter and \Kwyreturn */
  5942.         if (udkfkeys[39])    /* \Ktvienter and \Ktvireturn */
  5943.           free(udkfkeys[39]);
  5944.         udkfkeys[39] = strdup(s);
  5945.         if (udkfkeys[49])
  5946.           free(udkfkeys[49]);
  5947.         udkfkeys[49] = strdup(s);
  5948.         }
  5949.     } else {
  5950.         switch (strlen(s)) {    /* Action depends on length */
  5951.           case 0:            /* Clear individual key def */
  5952.         deletekeymap(t,kc);
  5953.         break;
  5954.           case 1:
  5955.         defevt.type = key;    /* Single character */
  5956.         defevt.key.scancode = *s;
  5957.         break;
  5958.           default:            /* Character string */
  5959. #ifndef NOKVERBS
  5960.         if (p) {
  5961.             y = xlookup(kverbs,p,nkverbs,&x); /* Look it up */
  5962.             /* Exact match req'd */
  5963.             debug(F101,"set key kverb lookup",0,y);
  5964.             if (y > -1) {
  5965.             defevt.type = kverb;
  5966.             defevt.kverb.id = y;
  5967.             break;
  5968.             }
  5969.         }
  5970. #endif /* NOKVERBS */
  5971.         defevt.type = macro;
  5972.         defevt.macro.string = (char *) malloc(strlen(s)+1);
  5973.         if (defevt.macro.string)
  5974.           strcpy(defevt.macro.string, s); /* safe */
  5975.         break;
  5976.         }
  5977.         insertkeymap( t, kc, defevt ) ;
  5978.         initvik = 1;        /* Update VIK table */
  5979.     }
  5980.     }
  5981.     return(1);
  5982. }
  5983. #endif /* OS2 */
  5984.  
  5985. #ifdef NT
  5986. int
  5987. setwin95( void ) {
  5988.     int x, y, z;
  5989.  
  5990.     if (( y = cmkey(win95tab, nwin95,
  5991.             "Windows 95 specific work-arounds",
  5992.             "keyboard-translation",
  5993.             xxstring)) < 0 )
  5994.     return (y);
  5995.     switch (y) {
  5996.       case XYWPOPUP:
  5997.     if ((y = cmkey(onoff,2,"popups are used to prompt the user for data",
  5998.                "on",xxstring)) < 0)
  5999.       return(y);
  6000.     if ((x = cmcfm()) < 0) return(x);
  6001.     win95_popup = y;
  6002.     return(1);
  6003.  
  6004.       case XYW8_3:
  6005.     if ((y = cmkey(onoff,2,"8.3 FAT file names","off",xxstring)) < 0)
  6006.       return(y);
  6007.     if ((x = cmcfm()) < 0) return(x);
  6008.     win95_8_3 = y;
  6009.     return(1);
  6010.  
  6011.       case XYWSELECT:
  6012.     if ((y = cmkey(onoff,2,"\"select()\" fails on write","off",
  6013.              xxstring)) < 0)
  6014.       return(y);
  6015.     if ((x = cmcfm()) < 0) return(x);
  6016.     win95selectbug = y;
  6017.     return(1);
  6018.  
  6019.       case XYWAGR:
  6020.     if ((y = cmkey(onoff,2,"Right-Alt is Alt-Gr","off",xxstring)) < 0)
  6021.       return(y);
  6022.     if ((x = cmcfm()) < 0) return(x);
  6023.     win95altgr = y;
  6024.     return(1);
  6025.  
  6026.       case XYWOIO:
  6027.     if ((y = cmkey(onoff,2,"Use Overlapped I/O","on",xxstring)) < 0)
  6028.       return(y);
  6029.     if (y) {
  6030.         if ((x = cmnum("Maximum number of outstanding I/O requests",
  6031.                "10",10,&z,xxstring)) < 0)
  6032.           return(x);
  6033.         if (z < 1 || z > 30) {
  6034.         printf(
  6035. "?Maximum outstanding I/O requests must be between 1 and 30.\n");
  6036.         return(-9);
  6037.         }
  6038.     } else
  6039.       z = 1;
  6040.     if ((x = cmcfm()) < 0) return(x);
  6041.     owwait = !y;
  6042.     maxow = maxow_usr = z;
  6043.     return(1);
  6044.  
  6045.       case XYWKEY:
  6046. #ifndef COMMENT
  6047.         printf("\n?\"Keyboard-Translation\" is no longer required.\n");
  6048.         return(-9);
  6049. #else /* COMMENT */
  6050.     if (( z = cmkey(tcstab, ntcs,
  6051.             "Keyboard Character Set",
  6052.             "latin1-iso",
  6053.             xxstring)) < 0)
  6054.       return (z);
  6055.     if ((x = cmcfm()) < 0)
  6056.       return(x);
  6057.  
  6058.     win95kcsi = z;
  6059.     win95kl2 = (win95kcsi == TC_2LATIN);
  6060.  
  6061.     if (win95kcsi == TC_TRANSP) {
  6062.         win95kcs = NULL;
  6063.     } else {
  6064. #ifdef UNICODE
  6065.         win95kcs = xlr[win95kcsi][tx2fc(tcsl)];
  6066. #else /* UNICODE */
  6067.         win95kcs = xlr[win95kcsi][tcsl];
  6068. #endif /* UNICODE */
  6069.     }
  6070.     return(1);
  6071. #endif /* COMMENT */
  6072.  
  6073.       case XYWLUC:
  6074.     if ((y = cmkey(onoff,2,"Unicode-to-Lucida-Console substitutions",
  6075.                "on",xxstring)) < 0)
  6076.       return(y);
  6077.     if ((x = cmcfm()) < 0) return(x);
  6078.     win95lucida = y;
  6079.     return(1);
  6080.  
  6081.       default:
  6082.     printf("Illegal value in setwin95()\n");
  6083.     return(-9);
  6084.     }
  6085. }
  6086. #endif /* NT */
  6087.  
  6088. #ifdef OS2
  6089. int
  6090. setprty (
  6091. #ifdef CK_ANSIC
  6092.     void
  6093. #endif /* CK_ANSIC */
  6094. /* setprty */ ) {
  6095.     int x, y, z;
  6096.  
  6097.     if (( y = cmkey(prtytab, nprty,
  6098.             "priority level of terminal and communication threads",
  6099.             "foreground-server",
  6100.             xxstring)) < 0 )
  6101.       return (y);
  6102.  
  6103.     if ((x = cmcfm()) < 0)
  6104.       return (x);
  6105. #ifdef IKSD
  6106.     if (inserver &&
  6107. #ifdef IKSDCONF
  6108.          iksdcf
  6109. #else
  6110.          1
  6111. #endif /* IKSDCONF */
  6112.     ) {
  6113.     if ((y = cmcfm()) < 0) return(y);
  6114.         printf("?Sorry, command disabled.\r\n");
  6115.         return(success = 0);
  6116.     }
  6117. #endif /* IKSD */
  6118.     priority = y;
  6119.     return(TRUE);
  6120. }
  6121. #endif /* OS2 */
  6122.  
  6123. int
  6124. setbell() {
  6125.     int y, x;
  6126. #ifdef OS2
  6127.     int z;
  6128. #endif /* OS2 */
  6129.  
  6130.     if ((y = cmkey(beltab,nbeltab,
  6131. #ifdef OS2
  6132.         "how console and terminal bells should\nbe generated", "audible",
  6133. #else
  6134.         "Whether Kermit should ring the terminal bell (beep)", "on",
  6135. #endif /* OS2 */
  6136.            xxstring)) < 0)
  6137.       return(y);
  6138.  
  6139. #ifdef IKSD
  6140.     if (inserver) {
  6141.     if ((y = cmcfm()) < 0) return(y);
  6142.         printf("?Sorry, command disabled.\r\n");
  6143.         return(success = 0);
  6144.     }
  6145. #endif /* IKSD */
  6146.  
  6147.     switch (y) {            /* SET BELL */
  6148.       case XYB_NONE:
  6149. #ifdef OS2
  6150.       case XYB_VIS:
  6151. #endif /* OS2 */
  6152.     if ((x = cmcfm()) < 0)
  6153.       return(x);
  6154. #ifdef OS2
  6155.     tt_bell = y;
  6156. #else
  6157.     tt_bell = 0;
  6158. #endif /* OS2 */
  6159.     break;
  6160.  
  6161.       case XYB_AUD:
  6162. #ifdef OS2
  6163.     if ((x = cmkey(audibletab, naudibletab,
  6164.            "how audible console and terminal\nbells should be generated",
  6165.                "beep",xxstring))<0)
  6166.       return(x);
  6167.     if ((z = cmcfm()) < 0)
  6168.       return(z);
  6169.     tt_bell = y | x;
  6170. #else
  6171.     /* This lets C-Kermit accept but ignore trailing K95 keywords */
  6172.     if ((x = cmtxt("Confirm with carriage return","",&s,xxstring)) < 0)
  6173.       return(x);
  6174.     tt_bell = 1;
  6175. #endif /* OS2 */
  6176.     break;
  6177.     }
  6178.     return(1);
  6179. }
  6180.  
  6181. #ifdef OS2MOUSE
  6182. int
  6183. setmou(
  6184. #ifdef CK_ANSIC
  6185.        void
  6186. #endif /* CK_ANSIC */
  6187.  /* setmou */ ) {
  6188.     extern int initvik;
  6189.     int button = 0, event = 0;
  6190.     char * p;
  6191.  
  6192.     if ((y = cmkey(mousetab,nmtab,"","",xxstring)) < 0)
  6193.       return(y);
  6194.  
  6195. #ifdef IKSD
  6196.     if (inserver) {
  6197.     if ((y = cmcfm()) < 0) return(y);
  6198.         printf("?Sorry, command disabled.\r\n");
  6199.         return(success = 0);
  6200.     }
  6201. #endif /* IKSD */
  6202.  
  6203.     if (y == XYM_ON) {            /* MOUSE ACTIVATION */
  6204.         int old_mou = tt_mouse;
  6205.         if ((x = seton(&tt_mouse)) < 0)
  6206.             return(x);
  6207.         if (tt_mouse != old_mou)
  6208.           if (tt_mouse)
  6209.             os2_mouseon();
  6210.           else
  6211.             os2_mouseoff();
  6212.         return(1);
  6213.     }
  6214.  
  6215.     if (y == XYM_DEBUG) {        /* MOUSE DEBUG */
  6216.         extern int MouseDebug;
  6217.         if ((x = seton(&MouseDebug)) < 0)
  6218.             return(x);
  6219.         return(1);
  6220.     }
  6221.  
  6222.     if (y == XYM_CLEAR) {        /* Reset Mouse Defaults */
  6223.     if ((x = cmcfm()) < 0) return(x);
  6224.     mousemapinit(-1,-1);
  6225.     initvik = 1;            /* Update VIK Table */
  6226.     return 1;
  6227.     }
  6228.     if (y != XYM_BUTTON) {        /* Shouldn't happen. */
  6229.     printf("Internal parsing error\n");
  6230.     return(-9);
  6231.     }
  6232.  
  6233.     /* MOUSE EVENT ... */
  6234.  
  6235.     if ((button = cmkey(mousebuttontab,nmbtab,
  6236.             "Button number","1",
  6237.             xxstring)) < 0)
  6238.       return(button);
  6239.  
  6240.     if ((y =  cmkey(mousemodtab,nmmtab,
  6241.             "Keyboard modifier","none",
  6242.             xxstring)) < 0)
  6243.       return(y);
  6244.  
  6245.     event |= y;                /* OR in the bits */
  6246.  
  6247.     if ((y =  cmkey(mclicktab,nmctab,"","click",xxstring)) < 0)
  6248.       return(y);
  6249.  
  6250.     /* Two bits are assigned, if neither are set then it is button one */
  6251.  
  6252.     event |= y;            /* OR in the bit */
  6253.  
  6254.     wideresult = -1;
  6255.  
  6256.     if ((y = cmtxt("definition,\n\
  6257. or Ctrl-C to cancel this command,\n\
  6258. or Enter to restore default definition",
  6259.            "",&s,NULL)) < 0) {
  6260.     return(y);
  6261.     }
  6262.     s = brstrip(s);
  6263.     p = s;                /* Save this place */
  6264. /*
  6265.   If the definition included any \Kverbs, quote the backslash so the \Kverb
  6266.   will still be in the definition when the key is pressed.  We don't do this
  6267.   in zzstring(), because \Kverbs are valid only in this context and nowhere
  6268.   else.  This code copied from SET KEY, q.v. for addt'l commentary.
  6269. */
  6270.     for (x = 0, y = 0; s[x]; x++, y++) { /* Convert \K to \\K */
  6271.     if ((x > 0) &&
  6272.         (s[x] == 'K' || s[x] == 'k')
  6273.         ) {                /* Have K */
  6274.  
  6275.         if ((x == 1 && s[x-1] == CMDQ) ||
  6276.         (x > 1 && s[x-1] == CMDQ && s[x-2] != CMDQ)) {
  6277.         line[y++] = CMDQ;    /* Make it \\K */
  6278.         }
  6279.         if (x > 1 && s[x-1] == '{' && s[x-2] == CMDQ) {
  6280.           line[y-1] = CMDQ;    /* Have \{K */
  6281.           line[y++] = '{';    /* Make it \\{K */
  6282.         }
  6283.     }
  6284.     line[y] = s[x];
  6285.     }
  6286.     line[y++] = NUL;            /* Terminate */
  6287.     s = line + y + 1;            /* Point to after it */
  6288.     x = LINBUFSIZ - (int) strlen(line) - 1; /* Calculate remaining space */
  6289.     if ((x < (LINBUFSIZ / 2)) ||
  6290.     (zzstring(line, &s, &x) < 0)) { /* Expand variables, etc. */
  6291.     printf("?Key definition too long\n");
  6292.     return(-9);
  6293.     }
  6294.     s = line + y + 1;            /* Point to result. */
  6295.  
  6296. #ifndef NOKVERBS
  6297. /*
  6298.   Special case: see if the definition starts with a \Kverb.
  6299.   If it does, point to it with p, otherwise set p to NULL.
  6300. */
  6301.     p = s;
  6302.     if (*p++ == CMDQ) {
  6303.     if (*p == '{') p++;
  6304.     p = (*p == 'k' || *p == 'K') ? p + 1 : NULL;
  6305.     }
  6306. #else
  6307.     p = NULL;
  6308. #endif /* NOKVERBS */
  6309.  
  6310.     /* free the old definition if necessary */
  6311.     if (mousemap[button][event].type == macro) {
  6312.         free( mousemap[button][event].macro.string);
  6313.     mousemap[button][event].macro.string = NULL;
  6314.     }
  6315.     switch (strlen(s)) {        /* Action depends on length */
  6316.       case 0:                /* Reset to default binding */
  6317.         mousemapinit( button, event );
  6318.         break;
  6319.       case 1:                /* Single character */
  6320.           mousemap[button][event].type = key;
  6321.         mousemap[button][event].key.scancode = *s;
  6322.           break;
  6323.       default:                /* Character string */
  6324. #ifndef NOKVERBS
  6325.     if (p) {
  6326.         y = xlookup(kverbs,p,nkverbs,&x); /* Look it up */
  6327.         debug(F101,"set mouse kverb lookup",0,y); /* need exact match */
  6328.         if (y > -1) {
  6329.             /* Assign the kverb to the event */
  6330.             mousemap[button][event].type = kverb;
  6331.             mousemap[button][event].kverb.id = F_KVERB | y;
  6332.             break;
  6333.         }
  6334.     }
  6335. #endif /* NOKVERBS */
  6336.  
  6337.        /* Otherwise, it's a macro, so assign the macro to the event */
  6338.        mousemap[button][event].type = macro;
  6339.        mousemap[button][event].macro.string = (MACRO) malloc(strlen(s)+1);
  6340.        if (mousemap[button][event].macro.string)
  6341.          strcpy((char *) mousemap[button][event].macro.string, s); /* safe */
  6342.         break;
  6343.     }
  6344.     initvik = 1;            /* Update VIK Table */
  6345.     if ( (button == XYM_B3) && (mousebuttoncount() < 3) && !quiet )
  6346.     {
  6347.         printf("?Warning: this machine does not have a three button mouse.\n");
  6348.         return(0);
  6349.     }
  6350.     return(1);
  6351. }
  6352. #endif /* OS2MOUSE */
  6353. #endif /* NOLOCAL */
  6354.  
  6355. #ifndef NOXFER
  6356. int                    /* SET SEND/RECEIVE */
  6357. setsr(xx, rmsflg) int xx; int rmsflg; {
  6358.     if (xx == XYRECV)
  6359.       ckstrncpy(line,"Parameter for inbound packets",LINBUFSIZ);
  6360.     else
  6361.       ckstrncpy(line,"Parameter for outbound packets",LINBUFSIZ);
  6362.  
  6363.     if (rmsflg) {
  6364.     if ((y = cmkey(rsrtab,nrsrtab,line,"",xxstring)) < 0) {
  6365.         if (y == -3) {
  6366.         printf("?Remote receive parameter required\n");
  6367.         return(-9);
  6368.         } else return(y);
  6369.     }
  6370.     } else {
  6371.     if ((y = cmkey(srtab,nsrtab,line,"",xxstring)) < 0) return(y);
  6372.     }
  6373.     switch (y) {
  6374.       case XYQCTL:            /* CONTROL-PREFIX */
  6375.     if ((x = cmnum("ASCII value of control prefix","",10,&y,xxstring)) < 0)
  6376.       return(x);
  6377.     if ((x = cmcfm()) < 0) return(x);
  6378.     if ((y > 32 && y < 63) || (y > 95 && y < 127)) {
  6379.         if (xx == XYRECV)
  6380.           ctlq = (CHAR) y;        /* RECEIVE prefix, use with caution! */
  6381.         else
  6382.           myctlq = (CHAR) y;    /* SEND prefix, OK to change */
  6383.         return(success = 1);
  6384.     } else {
  6385.         printf("?Illegal value for prefix character\n");
  6386.         return(-9);
  6387.     }
  6388.  
  6389.       case XYEOL:
  6390.     if ((y = setcc("13",&z)) < 0)
  6391.         return(y);
  6392.     if (z > 31) {
  6393.         printf("Sorry, the legal values are 0-31\n");
  6394.         return(-9);
  6395.     }
  6396.     if (xx == XYRECV)
  6397.       eol = (CHAR) z;
  6398.     else
  6399.       seol = (CHAR) z;
  6400.     return(success = y);
  6401.  
  6402.       case XYLEN:
  6403.     y = cmnum("Maximum number of characters in a packet","90",10,&x,
  6404.           xxstring);
  6405.     if (xx == XYRECV) {        /* Receive... */
  6406.         if ((y = setnum(&z,x,y,maxrps)) < 0)
  6407.           return(y);
  6408.         if (protocol != PROTO_K) {
  6409.         printf("?Sorry, this command does not apply to %s protocol.\n",
  6410.                ptab[protocol].p_name
  6411.                );
  6412.         printf("Use SET SEND PACKET-LENGTH for XYZMODEM\n");
  6413.         return(-9);
  6414.         }
  6415.         if (z < 10) {
  6416.         printf("Sorry, 10 is the minimum\n");
  6417.         return(-9);
  6418.         }
  6419.         if (rmsflg) {
  6420.         sstate = setgen('S', "401", ckitoa(z), "");
  6421.         return((int) sstate);
  6422.         } else {
  6423.         if (protocol == PROTO_K) {
  6424.             if (z > MAXRP) z = MAXRP;
  6425.             y = adjpkl(z,wslotr,bigrbsiz);
  6426.             if (y != z) {
  6427.             urpsiz = y;
  6428.             if (!xcmdsrc)
  6429.               if (msgflg) printf(
  6430. " Adjusting receive packet-length to %d for %d window slots\n",
  6431.                          y, wslotr);
  6432.             }
  6433.             urpsiz = y;
  6434.             ptab[protocol].rpktlen = urpsiz;
  6435.             rpsiz =  (y > 94) ? 94 : y;
  6436.         } else {
  6437. #ifdef CK_XYZ
  6438.             if ((protocol == PROTO_X || protocol == PROTO_XC) &&
  6439.                          z != 128 && z != 1024) {
  6440.             printf("Sorry, bad packet length for XMODEM.\n");
  6441.             printf("Please use 128 or 1024.\n");
  6442.             return(-9);
  6443.             }
  6444. #endif /* CK_XYZ */
  6445.             urpsiz = rpsiz = z;
  6446.         }
  6447.         }
  6448.     } else {            /* Send... */
  6449.         if ((y = setnum(&z,x,y,maxsps)) < 0)
  6450.           return(y);
  6451.         if (z < 10) {
  6452.         printf("Sorry, 10 is the minimum\n");
  6453.         return(-9);
  6454.         }
  6455.         if (protocol == PROTO_K) {
  6456.         if (z > MAXSP) z = MAXSP;
  6457.         spsiz = z;        /* Set it */
  6458.         y = adjpkl(spsiz,wslotr,bigsbsiz);
  6459.         if (y != spsiz && !xcmdsrc)
  6460.           if (msgflg)
  6461.             printf("Adjusting packet size to %d for %d window slots\n",
  6462.                y,wslotr);
  6463.         } else
  6464.           y = z;
  6465. #ifdef CK_XYZ
  6466.         if ((protocol == PROTO_X || protocol == PROTO_XC) &&
  6467.                  z != 128 && z != 1024) {
  6468.         printf("Sorry, bad packet length for XMODEM.\n");
  6469.         printf("Please use 128 or 1024.\n");
  6470.         return(-9);
  6471.         }
  6472. #endif /* CK_XYZ */
  6473.         spsiz = spmax = spsizr = y;    /* Set it and flag that it was set */
  6474.         spsizf = 1;            /* to allow overriding Send-Init. */
  6475.         ptab[protocol].spktflg = spsizf;
  6476.         ptab[protocol].spktlen = spsiz;
  6477.     }
  6478.     if (pflag && protocol == PROTO_K && !xcmdsrc) {
  6479.         if (z > 94 && !reliable && msgflg) {
  6480.         /* printf("Extended-length packets requested.\n"); */
  6481.         if (bctr < 2 && z > 200) printf("\
  6482. Remember to SET BLOCK 2 or 3 for long packets.\n");
  6483.         }
  6484.         if (speed <= 0L) speed = ttgspd();
  6485. #ifdef COMMENT
  6486. /*
  6487.   Kermit does this now itself.
  6488. */
  6489.         if (speed <= 0L && z > 200 && msgflg) {
  6490.         printf("\
  6491. Make sure your timeout interval is long enough for %d-byte packets.\n",z);
  6492.         }
  6493. #endif /* COMMENT */
  6494.     }
  6495.     return(success = y);
  6496.  
  6497.       case XYMARK:
  6498. #ifdef DOOMSDAY
  6499. /*
  6500.   Printable start-of-packet works for UNIX and VMS only!
  6501. */
  6502.     x_ifnum = 1;
  6503.     y = cmnum("Code for packet-start character","1",10,&x,xxstring);
  6504.     x_ifnum = 0;
  6505.     if ((y = setnum(&z,x,y,126)) < 0) return(y);
  6506. #else
  6507.     if ((y = setcc("1",&z)) < 0)
  6508.         return(y);
  6509. #endif /* DOOMSDAY */
  6510.     if (xx == XYRECV)
  6511.       stchr = (CHAR) z;
  6512.     else {
  6513.         mystch = (CHAR) z;
  6514. #ifdef IKS_OPTION
  6515.         /* If IKS negotiation in use   */
  6516.         if (TELOPT_U(TELOPT_KERMIT) || TELOPT_ME(TELOPT_KERMIT))
  6517.           tn_siks(KERMIT_SOP);    /* Report change to other side */
  6518. #endif /* IKS_OPTION */
  6519.         }
  6520.     return(success = y);
  6521.  
  6522.       case XYNPAD:            /* PADDING */
  6523.     y = cmnum("How many padding characters for inbound packets","0",10,&x,
  6524.           xxstring);
  6525.     if ((y = setnum(&z,x,y,94)) < 0) return(y);
  6526.     if (xx == XYRECV)
  6527.       mypadn = (CHAR) z;
  6528.     else
  6529.       npad = (CHAR) z;
  6530.     return(success = y);
  6531.  
  6532.       case XYPADC:            /* PAD-CHARACTER */
  6533.     if ((y = setcc("0",&z)) < 0) return(y);
  6534.     if (xx == XYRECV) mypadc = z; else padch = z;
  6535.     return(success = y);
  6536.  
  6537.       case XYTIMO:            /* TIMEOUT */
  6538.     if (xx == XYRECV) {
  6539.         y = cmnum("Packet timeout interval",ckitoa(URTIME),10,&x,xxstring);
  6540.         if ((y = setnum(&z,x,y,94)) < 0) return(y);
  6541.  
  6542.         if (rmsflg) {        /* REMOTE SET RECEIVE TIMEOUT */
  6543.         sstate = setgen('S', "402", ckitoa(z), "");
  6544.         return((int) sstate);
  6545.         } else {            /* SET RECEIVE TIMEOUT */
  6546.         pkttim = z;        /*   Value to put in my negotiation */
  6547.         }                /*   packet for other Kermit to use */
  6548.  
  6549.     } else {            /* SET SEND TIMEOUT */
  6550. #ifdef CK_TIMERS
  6551.         extern int rttflg, mintime, maxtime;
  6552.         int tmin = 0, tmax = 0;
  6553. #endif /* CK_TIMERS */
  6554.         y = cmnum("Packet timeout interval",ckitoa(DMYTIM),10,&x,xxstring);
  6555.         if (y == -3) {        /* They cancelled a previous */
  6556.         x = DMYTIM;        /* SET SEND command, so restore */
  6557.         timef = 0;        /* and turn off the override flag */
  6558.         y = cmcfm();
  6559.         }
  6560. #ifdef CK_TIMERS
  6561.         if (y < 0) return(y);
  6562.         if (x < 0) {
  6563.         printf("?Out of range - %d\n",x);
  6564.         return(-9);
  6565.         }
  6566.         if ((z = cmkey(timotab,2,"","dynamic",xxstring)) < 0) return(z);
  6567.         if (z) {
  6568.         if ((y = cmnum("Minimum timeout to allow",
  6569.                    "1",10,&tmin,xxstring)) < 0)
  6570.           return(y);
  6571.         if (tmin < 1) {
  6572.             printf("?Out of range - %d\n",tmin);
  6573.             return(-9);
  6574.         }
  6575.         if ((y = cmnum("Maximum timeout to allow",
  6576.                    "0",10,&tmax,xxstring)) < 0)
  6577.           return(y);
  6578.         /* 0 means let Kermit choose, < 0 means no maximum */
  6579.         }
  6580.         if ((y = cmcfm()) < 0)
  6581.           return(y);
  6582.         rttflg = z;            /* Round-trip timer flag */
  6583.         z = x;
  6584. #else
  6585.         if ((y = setnum(&z,x,y,94)) < 0)
  6586.           return(y);
  6587. #endif /* CK_TIMERS */
  6588.         timef = 1;            /* Turn on the override flag */
  6589.         timint = rtimo = z;        /* Override value for me to use */
  6590. #ifdef CK_TIMERS
  6591.         if (rttflg) {        /* Lower and upper bounds */
  6592.         mintime = tmin;
  6593.         maxtime = tmax;
  6594.         }
  6595. #endif /* CK_TIMERS */
  6596.     }
  6597.     return(success = 1);
  6598.  
  6599.       case XYFPATH:            /* PATHNAMES */
  6600.     if (xx == XYRECV) {
  6601.         y = cmkey(rpathtab,nrpathtab,"","auto",xxstring);
  6602.     } else {
  6603.         y = cmkey(pathtab,npathtab,"","off",xxstring);
  6604.     }
  6605.     if (y < 0) return(y);
  6606.  
  6607.     if ((x = cmcfm()) < 0) return(x);
  6608.     if (xx == XYRECV) {        /* SET RECEIVE PATHNAMES */
  6609.         fnrpath = y;
  6610.         ptab[protocol].fnrp = fnrpath;
  6611.     } else {            /* SET SEND PATHNAMES */
  6612.         fnspath = y;
  6613.         ptab[protocol].fnsp = fnspath;
  6614.     }
  6615.     return(success = 1);        /* Note: 0 = ON, 1 = OFF */
  6616.     /* In other words, ON = leave pathnames ON, OFF = take them off. */
  6617.  
  6618.       case XYPAUS:            /* SET SEND/RECEIVE PAUSE */
  6619.     y = cmnum("Milliseconds to pause between packets","0",10,&x,xxstring);
  6620.     if ((y = setnum(&z,x,y,15000)) < 0)
  6621.       return(y);
  6622.     pktpaus = z;
  6623.     return(success = 1);
  6624.  
  6625. #ifdef CKXXCHAR                /* SET SEND/RECEIVE IGNORE/DOUBLE */
  6626.       case XYIGN:
  6627.       case XYDBL: {
  6628.       int i, zz;
  6629.       short *p;
  6630.       extern short dblt[];
  6631.       extern int dblflag, ignflag;
  6632.  
  6633.       /* Make space for a temporary copy of the ignore/double table */
  6634.  
  6635.       zz = y;
  6636. #ifdef COMMENT
  6637.       if (zz == XYIGN && xx == XYSEND) {
  6638.           blah blah who cares
  6639.       }
  6640.       if (zz == XYDBL && xx == XYRECV) {
  6641.           blah blah
  6642.       }
  6643. #endif /* COMMENT */
  6644.       p = (short *)malloc(256 * sizeof(short));
  6645.       if (!p) {
  6646.           printf("?Internal error - malloc failure\n");
  6647.           return(-9);
  6648.       }
  6649.       for (i = 0; i < 256; i++) p[i] = dblt[i]; /* Copy current table */
  6650.  
  6651.       while (1) {            /* Collect a list of numbers */
  6652. #ifndef NOSPL
  6653.           x_ifnum = 1;        /* Turn off complaints from eval() */
  6654. #endif /* NOSPL */
  6655.           if ((x = cmnum(zz == XYDBL ?
  6656.                  "Character to double" :
  6657.                  "Character to ignore",
  6658.                  "",10,&y,xxstring
  6659.                  )) < 0) {
  6660. #ifndef NOSPL
  6661.           x_ifnum = 0;
  6662. #endif /* NOSPL */
  6663.           if (x == -3)        /* Done */
  6664.             break;
  6665.           if (x == -2) {
  6666.               if (p) { free(p); p = NULL; }
  6667.               debug(F110,"SET S/R DOUBLE/IGNORE atmbuf",atmbuf,0);
  6668.               if (!ckstrcmp(atmbuf,"none",4,0) ||
  6669.               !ckstrcmp(atmbuf,"non",3,0) ||
  6670.               !ckstrcmp(atmbuf,"no",2,0) ||
  6671.               !ckstrcmp(atmbuf,"n",1,0)) {
  6672.               if ((x = cmcfm()) < 0) /* Get confirmation */
  6673.                 return(x);
  6674.               for (y = 0; y < 256; y++)
  6675.                 dblt[y] &= (zz == XYDBL) ? 1 : 2;
  6676.               if (zz == XYDBL) dblflag = 0;
  6677.               if (zz == XYIGN) ignflag = 0;
  6678.               return(success = 1);
  6679.               } else {
  6680.               printf(
  6681.                 "?Please specify a number or the word NONE\n");
  6682.               return(-9);
  6683.               }
  6684.           } else {
  6685.               free(p);
  6686.               p = NULL;
  6687.               return(x);
  6688.           }
  6689.           }
  6690. #ifndef NOSPL
  6691.           x_ifnum = 0;
  6692. #endif /* NOSPL */
  6693.           if (y < 0 || y > 255) {
  6694.           printf("?Please enter a character code in range 0-255\n");
  6695.           free(p);
  6696.           p = NULL;
  6697.           return(-9);
  6698.           }
  6699.           p[y] |= (zz == XYDBL) ? 2 : 1;
  6700.           if (zz == XYDBL) dblflag = 1;
  6701.           if (zz == XYIGN) ignflag = 1;
  6702.       } /* End of while loop */
  6703.  
  6704.       if ((x = cmcfm()) < 0) return(x);
  6705. /*
  6706.   Get here only if they have made no mistakes.  Copy temporary table back to
  6707.   permanent one, then free temporary table and return successfully.
  6708. */
  6709.       if (p) {
  6710.           for (i = 0; i < 256; i++) dblt[i] = p[i];
  6711.           free(p);
  6712.           p = NULL;
  6713.       }
  6714.       return(success = 1);
  6715.       }
  6716. #endif /* CKXXCHAR */
  6717.  
  6718. #ifdef PIPESEND
  6719.       case XYFLTR: {            /* SET { SEND, RECEIVE } FILTER */
  6720.       if ((y = cmtxt((xx == XYSEND) ?
  6721.         "Filter program for sending files -\n\
  6722.  use \\v(filename) to substitute filename" :
  6723.         "Filter program for receiving files -\n\
  6724.  use \\v(filename) to substitute filename",
  6725.              "",&s,NULL)) < 0)
  6726.         return(y);
  6727.       if (!*s) {            /* Removing a filter... */
  6728.           if (xx == XYSEND && sndfilter) {
  6729.           makestr(&g_sfilter,NULL);
  6730.           makestr(&sndfilter,NULL);
  6731.           } else if (rcvfilter) {
  6732.           makestr(&g_rfilter,NULL);
  6733.           makestr(&rcvfilter,NULL);
  6734.           }
  6735.           return(success = 1);
  6736.       }                /* Adding a filter... */
  6737.       s = brstrip(s);        /* Strip any braces */
  6738.       y = strlen(s);
  6739.       if (xx == XYSEND) {        /* For SEND filter... */
  6740.           for (x = 0; x < y; x++) {    /* make sure they included "\v(...)" */
  6741.           if (s[x] != '\\') continue;
  6742.           if (s[x+1] == 'v') break;
  6743.           }
  6744.           if (x == y) {
  6745.           printf(
  6746.           "?Filter must contain a replacement variable for filename.\n"
  6747.              );
  6748.           return(-9);
  6749.           }
  6750.       }
  6751.       if (xx == XYSEND) {
  6752.           makestr(&sndfilter,s);
  6753.           makestr(&g_sfilter,s);
  6754.       } else {
  6755.           makestr(&rcvfilter,s);
  6756.           makestr(&g_rfilter,s);
  6757.       }
  6758.       return(success = 1);
  6759.       }
  6760. #endif /* PIPESEND */
  6761.  
  6762.       case XYINIL:
  6763.     y = cmnum("Max length for protocol init string","-1",10,&x,xxstring);
  6764.     if ((y = setnum(&z,x,y,-1)) < 0)
  6765.       return(y);
  6766.     if (xx == XYSEND)
  6767.       sprmlen = z;
  6768.     else
  6769.       rprmlen = z;
  6770.     return(success = 1);
  6771.  
  6772.       case 993: {
  6773.       extern int sendipkts;
  6774.       if (xx == XYSEND) {
  6775.           if ((x = seton(&sendipkts)) < 0)
  6776.         return(x);
  6777.       }
  6778.       return(1);
  6779.       }
  6780.  
  6781. #ifndef NOCSETS
  6782.       case XYCSET: {            /* CHARACTER-SET-SELECTION */
  6783.       extern struct keytab xfrmtab[];
  6784.       extern int r_cset, s_cset;
  6785.       if ((y = cmkey(xfrmtab,2,"","automatic",xxstring)) < 0)
  6786.         return(y);
  6787.       if ((x = cmcfm()) < 0)
  6788.         return(x);
  6789.       if (xx == XYSEND)
  6790.         s_cset = y;
  6791.       else
  6792.         r_cset = y;
  6793.       return(success = 1);
  6794.       }
  6795. #endif /* NOCSETS */
  6796.  
  6797.       case XYBUP:
  6798.     if ((y = cmkey(onoff,2,"","on",xxstring)) < 0)
  6799.       return(y);
  6800.     if ((x = cmcfm()) < 0) return(x);
  6801.     if (xx == XYSEND) {
  6802.         extern int skipbup;
  6803.         skipbup = (y == 0) ? 1 : 0;
  6804.         return(success = 1);
  6805.     } else {
  6806.         printf(
  6807. "?Please use SET FILE COLLISION to choose the desired action\n");
  6808.         return(-9);
  6809.     }
  6810.  
  6811.       case XYMOVE:
  6812.     y = cmdir("Directory to move file(s) to after successful transfer",
  6813.           "",&s,xxstring);
  6814.     if (y < 0 && y != -3)
  6815.       return(y);
  6816.     ckstrncpy(line,s,LINBUFSIZ);
  6817.     s = brstrip(line);
  6818.     if ((x = cmcfm()) < 0)
  6819.       return(x);
  6820.     if (xx == XYSEND) {
  6821.         if (*s) {
  6822.         makestr(&snd_move,s);
  6823.         makestr(&g_snd_move,s);
  6824.         } else {
  6825.         makestr(&snd_move,NULL);
  6826.         makestr(&g_snd_move,NULL);
  6827.         }
  6828.     } else {
  6829.         if (*s) {
  6830.         makestr(&rcv_move,s);
  6831.         makestr(&g_rcv_move,s);
  6832.         } else {
  6833.         makestr(&rcv_move,NULL);
  6834.         makestr(&g_rcv_move,NULL);
  6835.         }
  6836.     }
  6837.     return(success = 1);
  6838.  
  6839.       case XYRENAME:
  6840.     y = cmdir("Template to rename file(s) to after successful transfer",
  6841.           "",&s,NULL);
  6842.     if (y < 0 && y != -3)
  6843.       return(y);
  6844.     ckstrncpy(line,s,LINBUFSIZ);
  6845.     s = brstrip(line);
  6846.     if ((x = cmcfm()) < 0)
  6847.       return(x);
  6848.     if (xx == XYSEND) {
  6849.         if (*s) {
  6850.         makestr(&snd_rename,s);
  6851.         makestr(&g_snd_rename,s);
  6852.         } else {
  6853.         makestr(&snd_rename,NULL);
  6854.         makestr(&g_snd_rename,NULL);
  6855.         }
  6856.     } else {
  6857.         if (*s) {
  6858.         makestr(&rcv_rename,s);
  6859.         makestr(&g_rcv_rename,s);
  6860.         } else {
  6861.         makestr(&rcv_rename,NULL);
  6862.         makestr(&g_rcv_rename,NULL);
  6863.         }
  6864.     }
  6865.     return(success = 1);
  6866.  
  6867. #ifdef VMS
  6868.       case 887:            /* VERSION-NUMBERS */
  6869.     if (xx == XYSEND) {
  6870.         extern int vmssversions;
  6871.         return(seton(&vmssversions));
  6872.     } else {
  6873.         extern int vmsrversions;
  6874.         return(seton(&vmsrversions));
  6875.     }
  6876. #endif /* VMS */
  6877.  
  6878.       default:
  6879.     return(-2);
  6880.     }                    /* End of SET SEND/RECEIVE... */
  6881. }
  6882. #endif /* NOXFER */
  6883.  
  6884. #ifndef NOXMIT
  6885. int
  6886. setxmit() {
  6887.     if ((y = cmkey(xmitab,nxmit,"","",xxstring)) < 0) return(y);
  6888.     switch (y) {
  6889.       case XMITE:            /* EOF */
  6890.     y = cmtxt("Characters to send at end of file,\n\
  6891.  Use backslash codes for control characters","",&s,xxstring);
  6892.     if (y < 0) return(y);
  6893.     if ((int)strlen(s) > XMBUFL) {
  6894.         printf("?Too many characters, %d maximum\n",XMBUFL);
  6895.         return(-2);
  6896.     }
  6897.     ckstrncpy(xmitbuf,s,XMBUFL);
  6898.     return(success = 1);
  6899.  
  6900.       case XMITF:            /* Fill */
  6901.     y = cmnum("Numeric code for blank-line fill character","0",10,&x,
  6902.           xxstring);
  6903.     if ((y = setnum(&z,x,y,127)) < 0) return(y);
  6904.     xmitf = z;
  6905.     return(success = 1);
  6906.       case XMITL:            /* Linefeed */
  6907.         return(seton(&xmitl));
  6908.       case XMITS:            /* Locking-Shift */
  6909.         return(seton(&xmits));
  6910.       case XMITP:            /* Prompt */
  6911.     y = cmnum("Numeric code for host's prompt character, 0 for none",
  6912.           "10",10,&x,xxstring);
  6913.     if ((y = setnum(&z,x,y,127)) < 0) return(y);
  6914.     xmitp = z;
  6915.     return(success = 1);
  6916.       case XMITX:            /* Echo */
  6917.         return(seton(&xmitx));
  6918.       case XMITW:            /* Pause */
  6919.     y = cmnum("Number of milliseconds to pause between binary characters\n\
  6920. or text lines during transmission","0",10,&x,xxstring);
  6921.     if ((y = setnum(&z,x,y,1000)) < 0) return(y);
  6922.     xmitw = z;
  6923.     return(success = 1);
  6924.       case XMITT:            /* Timeout */
  6925.     y = cmnum("Seconds to wait for each character to echo",
  6926.           "1",10,&x,xxstring);
  6927.     if ((y = setnum(&z,x,y,1000)) < 0) return(y);
  6928.     xmitt = z;
  6929.     return(success = 1);
  6930.       default:
  6931.     return(-2);
  6932.     }
  6933. }
  6934. #endif /* NOXMIT */
  6935.  
  6936. /*  D O R M T  --  Do a remote command  */
  6937.  
  6938. VOID
  6939. rmsg() {
  6940.     if (pflag)
  6941.       printf(
  6942. #ifdef CK_NEED_SIG
  6943.        " Type your escape character, %s, followed by X or E to cancel.\n",
  6944.        dbchr(escape)
  6945. #else
  6946.        " Press the X or E key to cancel.\n"
  6947. #endif /* CK_NEED_SIG */
  6948.       );
  6949. }
  6950.  
  6951. #ifndef NOXFER
  6952. static int xzcmd = 0;            /* Global copy of REMOTE cmd index */
  6953.  
  6954. /*  R E M C F M  --  Confirm a REMOTE command  */
  6955. /*
  6956.   Like cmcfm(), but allows for a redirection indicator on the end,
  6957.   like "> filename" or "| command".  Returns what cmcfm() would have
  6958.   returned: -1 if reparse needed, etc etc blah blah.  On success,
  6959.   returns 1 with:
  6960.  
  6961.     char * remdest containing the name of the file or command.
  6962.     int remfile set to 1 if there is to be any redirection.
  6963.     int remappd set to 1 if output file is to be appended to.
  6964.     int rempipe set to 1 if remdest is a command, 0 if it is a file.
  6965. */
  6966. static int
  6967. remcfm() {
  6968.     int x;
  6969.     char *s;
  6970.     char c;
  6971.  
  6972.     remfile = 0;
  6973.     rempipe = 0;
  6974.     remappd = 0;
  6975.  
  6976.     if ((x = cmtxt(
  6977.          "> filename, | command,\n\
  6978. or type carriage return to confirm the command",
  6979.            "",&s,xxstring)) < 0)
  6980.       return(x);
  6981.     if (remdest) {
  6982.     free(remdest);
  6983.     remdest = NULL;
  6984.     }
  6985.     debug(F101,"remcfm local","",local);
  6986.     debug(F110,"remcfm s",s,0);
  6987.     debug(F101,"remcfm cmd","",xzcmd);
  6988.  
  6989.     if (!*s) {                /* No redirection indicator */
  6990.     if (!local &&
  6991.         (xzcmd == XZDIR || xzcmd == XZTYP ||
  6992.          xzcmd == XZXIT || xzcmd == XZSPA ||
  6993.          xzcmd == XZHLP || xzcmd == XZPWD ||
  6994.          xzcmd == XZLGI || xzcmd == XZLGO ||
  6995.          xzcmd == XZWHO || xzcmd == XZHOS)) {
  6996.         printf("?\"%s\" has no effect in remote mode\n",cmdbuf);
  6997.         return(-9);
  6998.     } else
  6999.       return(1);
  7000.     }
  7001.     c = *s;                /* We have something */
  7002.     if (c != '>' && c != '|') {        /* Is it > or | ? */
  7003.     printf("?Not confirmed\n");    /* No */
  7004.     return(-9);
  7005.     }
  7006.     s++;                /* See what follows */
  7007.     if (c == '>' && *s == '>') {    /* Allow for ">>" too */
  7008.     s++;
  7009.     remappd = 1;            /* Append to output file */
  7010.     }
  7011.     while (*s == SP || *s == HT) s++;    /* Strip intervening whitespace */
  7012.     if (!*s) {
  7013.     printf("?%s missing\n", c == '>' ? "Filename" : "Command");
  7014.     return(-9);
  7015.     }
  7016.     if (c == '>' && zchko(s) < 0) {    /* Check accessibility */
  7017.     printf("?Access denied - %s\n", s);
  7018.     return(-9);
  7019.     }
  7020.     remfile = 1;            /* Set global results */
  7021.     rempipe = (c == '|');
  7022.     if (rempipe
  7023. #ifndef NOPUSH
  7024.     && nopush
  7025. #endif /* NOPUSH */
  7026.     ) {
  7027.     printf("?Sorry, access to external commands is disabled.\n");
  7028.     return(-9);
  7029.     }
  7030.     makestr(&remdest,s);
  7031. #ifndef NODEBUG
  7032.     if (deblog) {
  7033.     debug(F101,"remcfm remfile","",remfile);
  7034.     debug(F101,"remcfm remappd","",remappd);
  7035.     debug(F101,"remcfm rempipe","",rempipe);
  7036.     debug(F110,"remcfm remdest",remdest, 0);
  7037.     }
  7038. #endif /* NODEBUG */
  7039.     return(1);
  7040. }
  7041.  
  7042. /*  R E M T X T  --  Like remcfm()...  */
  7043. /*
  7044.    ... but for REMOTE commands that end with cmtxt().
  7045.    Here we must decipher braces to discover whether the trailing
  7046.    redirection indicator is intended for local use, or to be sent out
  7047.    to the server, as in:
  7048.  
  7049.      remote host blah blah > file                 This end
  7050.      remote host { blah blah } > file             This end
  7051.      remote host { blah blah > file }             That end
  7052.      remote host { blah blah > file } > file      Both ends
  7053.  
  7054.    Pipes too:
  7055.  
  7056.      remote host blah blah | cmd                  This end
  7057.      remote host { blah blah } | cmd              This end
  7058.      remote host { blah blah | cmd }              That end
  7059.      remote host { blah blah | cmd } | cmd        Both ends
  7060.  
  7061.    Or both:
  7062.  
  7063.      remote host blah blah | cmd > file           This end, etc etc...
  7064.  
  7065.    Note: this really only makes sense for REMOTE HOST, but why be picky?
  7066.    Call after calling cmtxt(), with pointer to string that cmtxt() parsed,
  7067.    as in "remtxt(&s);".
  7068.  
  7069.    Returns:
  7070.     1 on success with braces & redirection things removed & pointer updated,
  7071.    -9 on failure (bad indirection), after printing error message.
  7072. */
  7073. int
  7074. remtxt(p) char ** p; {
  7075.     int i, x, bpos, ppos;
  7076.     char c, *s, *q;
  7077.  
  7078.     remfile = 0;            /* Initialize global results */
  7079.     rempipe = 0;
  7080.     remappd = 0;
  7081.     if (remdest) {
  7082.     free(remdest);
  7083.     remdest = NULL;
  7084.     }
  7085.     s = *p;
  7086.     if (!s)                /* No redirection indicator */
  7087.       s = "";
  7088.     if (!*s) {                /* Ditto */
  7089.     if (!local &&
  7090.         (xzcmd == XZDIR || xzcmd == XZTYP ||
  7091.          xzcmd == XZXIT || xzcmd == XZSPA ||
  7092.          xzcmd == XZHLP || xzcmd == XZPWD ||
  7093.          xzcmd == XZLGI || xzcmd == XZLGO ||
  7094.          xzcmd == XZWHO || xzcmd == XZHOS)) {
  7095.         printf("?\"%s\" has no effect in remote mode\n",cmdbuf);
  7096.         if (hints) {
  7097.         printf("Hint: Try again with an output redirector.\n");
  7098.         }
  7099.         return(-9);
  7100.     } else
  7101.       return(1);
  7102.     }
  7103.     bpos = -1;                /* Position of > (bracket) */
  7104.     ppos = -1;                /* Position of | (pipe) */
  7105.     x = strlen(s);            /* Length of cmtxt() string */
  7106.  
  7107.     for (i = x-1; i >= 0; i--) {    /* Search right to left. */
  7108.     c = s[i];
  7109.     if (c == '}')            /* Break on first right brace */
  7110.       break;            /* Don't look at contents of braces */
  7111.     else if (c == '>')        /* Record position of > */
  7112.       bpos = i;
  7113.     else if (c == '|')        /* and of | */
  7114.       ppos = i;
  7115.     }
  7116.     if (bpos < 0 && ppos < 0) {        /* No redirectors. */
  7117.     if (!local &&
  7118.         (xzcmd == XZDIR || xzcmd == XZTYP ||
  7119.          xzcmd == XZXIT || xzcmd == XZSPA ||
  7120.          xzcmd == XZHLP || xzcmd == XZPWD ||
  7121.          xzcmd == XZLGI || xzcmd == XZLGO ||
  7122.          xzcmd == XZWHO || xzcmd == XZHOS)) {
  7123.         printf("?\"%s\" has no effect in remote mode\n",cmdbuf);
  7124.         if (hints) {
  7125.         printf("Hint: Try again with an output redirector.\n");
  7126.         }
  7127.         return(-9);
  7128.     }
  7129.     s = brstrip(s);            /* Remove outer braces if any. */
  7130.     *p = s;                /* Point to result */
  7131.     return(1);            /* and return. */
  7132.     }
  7133.     remfile = 1;            /* It's | or > */
  7134.     i = -1;                /* Get leftmost symbol */
  7135.     if (bpos > -1)            /* Bracket */
  7136.       i = bpos;
  7137.     if (ppos > -1 && (ppos < bpos || bpos < 0)) { /* or pipe */
  7138.     i = ppos;
  7139.     rempipe = 1;
  7140.     }
  7141.     if (rempipe
  7142. #ifndef NOPUSH
  7143.     && nopush
  7144. #endif /* NOPUSH */
  7145.     ) {
  7146.     printf("?Sorry, access to external commands is disabled.\n");
  7147.     return(-9);
  7148.     }
  7149.     c = s[i];                /* Copy of symbol */
  7150.  
  7151.     if (c == '>' && s[i+1] == '>')    /* ">>" for append? */
  7152.       remappd = 1;               /* It's not just a flag it's a number */
  7153.  
  7154.     q = s + i + 1 + remappd;        /* Point past symbol in string */
  7155.     while (*q == SP || *q == HT) q++;    /* and any intervening whitespace */
  7156.     if (!*q) {
  7157.     printf("?%s missing\n", c == '>' ? "Filename" : "Command");
  7158.     return(-9);
  7159.     }
  7160.     if (c == '>' && zchko(q) < 0) {    /* (Doesn't work for | cmd > file) */
  7161.     printf("?Access denied - %s\n", q);
  7162.     return(-9);
  7163.     }
  7164.     makestr(&remdest,q);        /* Create the destination string */
  7165.     q = s + i - 1;            /* Point before symbol */
  7166.     while (q > s && (*q == SP || *q == HT)) /* Strip trailing whitespace */
  7167.       q--;
  7168.     *(q+1) = NUL;            /* Terminate the string. */
  7169.     s = brstrip(s);            /* Remove any braces */
  7170.     *p = s;                /* Set return value */
  7171.  
  7172. #ifndef NODEBUG
  7173.     if (deblog) {
  7174.     debug(F101,"remtxt remfile","",remfile);
  7175.     debug(F101,"remtxt remappd","",remappd);
  7176.     debug(F101,"remtxt rempipe","",rempipe);
  7177.     debug(F110,"remtxt remdest",remdest, 0);
  7178.     debug(F110,"remtxt command",s,0);
  7179.     }
  7180. #endif /* NODEBUG */
  7181.  
  7182.     return(1);
  7183. }
  7184.  
  7185. int
  7186. plogin(xx) int xx; {
  7187.     char *p1 = NULL, *p2 = NULL, *p3 = NULL;
  7188.     int psaved = 0, rc = 0;
  7189. #ifdef CK_RECALL
  7190.     extern int on_recall;        /* around Password prompting */
  7191. #endif /* CK_RECALL */
  7192.     debug(F101,"plogin local","",local);
  7193.  
  7194.     if (!local || (network && ttchk() < 0)) {
  7195.     printf("?No connection\n");
  7196.     return(-9);
  7197.     }
  7198.     if ((x = cmfld("User ID","",&s,xxstring)) < 0) { /* Get User ID */
  7199.     if (x != -3) return(x);
  7200.     }
  7201.     y = strlen(s);
  7202.     if (y > 0) {
  7203.     if ((p1 = malloc(y + 1)) == NULL) {
  7204.         printf("?Internal error: malloc\n");
  7205.         rc = -9;
  7206.         goto XZXLGI;
  7207.     } else
  7208.       strcpy(p1,s);            /* safe */
  7209.     if ((rc = cmfld("Password","",&s,xxstring)) < 0)
  7210.       if (rc != -3) goto XZXLGI;
  7211.     y = strlen(s);
  7212.     if (y > 0) {
  7213.         if ((p2 = malloc(y + 1)) == NULL) {
  7214.         printf("?Internal error: malloc\n");
  7215.         rc = -9;
  7216.         goto XZXLGI;
  7217.         } else
  7218.           strcpy(p2,s);        /* safe */
  7219.         if ((rc = cmfld("Account","",&s,xxstring)) < 0)
  7220.           if (rc != -3) goto XZXLGI;
  7221.         y = strlen(s);
  7222.         if (y > 0) {
  7223.         if ((p3 = malloc(y + 1)) == NULL) {
  7224.             printf("?Internal error: malloc\n");
  7225.             rc = -9;
  7226.             goto XZXLGI;
  7227.         } else
  7228.           strcpy(p3,s);        /* safe */
  7229.         }
  7230.     }
  7231.     }
  7232.     if ((rc = remtxt(&s)) < 0)        /* Confirm & handle redirectors */
  7233.       goto XZXLGI;
  7234.  
  7235.     if (!p1) {                /* No Userid specified... */
  7236.     debok = 0;            /* Don't log this */
  7237.     /* Prompt for username, password, and account */
  7238. #ifdef CK_RECALL
  7239.     on_recall = 0;
  7240. #endif /* CK_RECALL */
  7241.     cmsavp(psave,PROMPTL);        /* Save old prompt */
  7242.     psaved = 1;
  7243.     debug(F110,"REMOTE LOGIN saved",psave,0);
  7244.  
  7245.     cmsetp("Username: ");        /* Make new prompt */
  7246.     concb((char)escape);        /* Put console in cbreak mode */
  7247.     cmini(1);
  7248.     prompt(xxstring);
  7249.     rc = -9;
  7250.     for (x = -1; x < 0; ) {        /* Prompt till they answer */
  7251.         cmres();            /* Reset the parser */
  7252.         x = cmtxt("","",&s,NULL);    /* Get a literal line of text */
  7253.     }
  7254.     y = strlen(s);
  7255.     if (y < 1) {
  7256.         printf("?Canceled\n");
  7257.         goto XZXLGI;
  7258.     }
  7259.     if ((p1 = malloc(y + 1)) == NULL) {
  7260.         printf("?Internal error: malloc\n");
  7261.         goto XZXLGI;
  7262.     } else
  7263.       strcpy(p1,s);            /* safe */
  7264.  
  7265.     cmsetp("Password: ");        /* Make new prompt */
  7266.     concb((char)escape);        /* Put console in cbreak mode */
  7267.     cmini(0);            /* No echo */
  7268.     prompt(xxstring);
  7269.     debok = 0;
  7270.     for (x = -1; x < 0 && x != -3; ) { /* Get answer */
  7271.         cmres();            /* Reset the parser */
  7272.         x = cmtxt("","",&s,NULL);    /* Get literal line of text */
  7273.     }
  7274.     if ((p2 = malloc((int)strlen(s) + 1)) == NULL) {
  7275.         printf("?Internal error: malloc\n");
  7276.         goto XZXLGI;
  7277.     } else
  7278.       strcpy(p2,s);            /* safe */
  7279.     printf("\r\n");
  7280.     if ((rc = cmcfm()) < 0)
  7281.       goto XZXLGI;
  7282.     }
  7283.     sstate = setgen('I',p1,p2,p3);    /* Get here with at least user ID */
  7284.     rc = 0;
  7285.  
  7286.   XZXLGI:                /* Common exit point */
  7287.     if (psaved)
  7288.       cmsetp(psave);            /* Restore original prompt */
  7289.     if (p3) { free(p3); p3 = NULL; }    /* Free malloc'd storage */
  7290.     if (p2) { free(p2); p2 = NULL; }
  7291.     if (p1) { free(p1); p1 = NULL; }
  7292.     if (rc > -1) {
  7293.     if (local && rc > -1)        /* If local, flush tty input buffer */
  7294.       ttflui();
  7295.     }
  7296.     return(rc);
  7297. }
  7298.  
  7299. #ifdef OS2
  7300. #ifndef NOLOCAL
  7301. int
  7302. dormt(xx) int xx; {
  7303.     int rc = 0;
  7304.     extern int term_io;
  7305.     int term_io_sav = term_io;
  7306. #ifdef NEWFTP
  7307.     extern int ftpget, ftpisopen();
  7308.     if ((ftpget == 1) || ((ftpget == 2) && ftpisopen()))
  7309.       return(doftprmt(xx,0));
  7310. #endif /* NEWFTP */
  7311.     term_io = 0;
  7312.     rc = xxdormt(xx);
  7313.     term_io = term_io_sav;
  7314.     return rc;
  7315. }
  7316.  
  7317.  
  7318. int
  7319. xxdormt(xx) int xx;
  7320. #else /* NOLOCAL */
  7321. int
  7322. dormt(xx) int xx;
  7323. #endif /* NOLOCAL */
  7324. #else /* OS2 */
  7325. int
  7326. dormt(xx) int xx;
  7327. #endif /* OS2 */
  7328. {                    /* REMOTE commands */
  7329.     int x, y, retcode;
  7330.     char *s, sbuf[50], *s2;
  7331.  
  7332. #ifdef NEWFTP
  7333.     extern int ftpget, ftpisopen();
  7334.     if ((ftpget == 1) || ((ftpget == 2) && ftpisopen()))
  7335.       return(doftprmt(xx,0));
  7336. #endif /* NEWFTP */
  7337.  
  7338.     remfile = 0;            /* Clear these */
  7339.     rempipe = 0;
  7340.     remappd = 0;
  7341.  
  7342.     if (xx < 0) return(xx);        /* REMOTE what? */
  7343.  
  7344.     xzcmd = xx;                /* Make global copy of arg */
  7345.  
  7346.     if (xx == XZSET) {            /* REMOTE SET */
  7347.     if ((y = cmkey(rmstab,nrms,"","",xxstring)) < 0) {
  7348.         if (y == -3) {
  7349.         printf("?Parameter name required\n");
  7350.         return(-9);
  7351.         } else return(y);
  7352.     }
  7353.     return(doprm(y,1));
  7354.     }
  7355.  
  7356.     switch (xx) {            /* Others... */
  7357.  
  7358.       case XZCDU:
  7359.     if ((x = cmcfm()) < 0) return(x);
  7360.     printf("?Sorry, REMOTE CDUP not supported yet\n");
  7361.     return(-9);
  7362.  
  7363.       case XZCWD:            /* CWD (CD) */
  7364.     if ((x = cmtxt("Remote directory name","",&s,xxstring)) < 0)
  7365.       return(x);
  7366.     if ((x = remtxt(&s)) < 0)
  7367.       return(x);
  7368.     debug(F111,"XZCWD: ",s,x);
  7369.     *sbuf = NUL;
  7370.     s2 = sbuf;
  7371. /*
  7372.   The following is commented out because since the disappearance of the
  7373.   DECSYSTEM-20 from the planet, no known computer requires a password for
  7374.   changing directory.
  7375. */
  7376. #ifdef DIRPWDPR
  7377.     if (*s != NUL) {        /* If directory name given, */
  7378.                     /* get password on separate line. */
  7379.         if (tlevel > -1) {        /* From take file... */
  7380.  
  7381.         if (fgets(sbuf,50,tfile[tlevel]) == NULL)
  7382.           fatal("take file ends prematurely in 'remote cwd'");
  7383.         debug(F110," pswd from take file",s2,0);
  7384.         for (x = (int)strlen(sbuf);
  7385.              x > 0 && (sbuf[x-1] == NL || sbuf[x-1] == CR);
  7386.              x--)
  7387.           sbuf[x-1] = '\0';
  7388.  
  7389.         } else {            /* From terminal... */
  7390.  
  7391.         printf(" Password: ");    /* get a password */
  7392. #ifdef IKSD
  7393.                 if (!local && inserver) {
  7394.                     x = coninc(0);
  7395.                 } else
  7396. #endif /* IKSD */
  7397. #ifdef OS2
  7398.           x = is_a_tty(0) ? coninc(0) : /* with no echo ... */
  7399.                     getchar();
  7400. #else /* OS2 */
  7401.                 x = getchar();
  7402. #endif /* OS2 */
  7403.         while ((x != NL) && (x != CR)) {
  7404.             if ((x &= 0177) == '?') {
  7405.             printf("? Password of remote directory\n Password: ");
  7406.             s2 = sbuf;
  7407.             *sbuf = NUL;
  7408.             } else if (x == ESC) /* Mini command line editor... */
  7409.               bleep(BP_WARN);
  7410.             else if (x == BS || x == 0177)
  7411.               s2--;
  7412.             else if (x == 025) {    /* Ctrl-U */
  7413.             s2 = sbuf;
  7414.             *sbuf = NUL;
  7415.             } else
  7416.               *s2++ = x;
  7417.  
  7418.                     /* Get the next character */
  7419. #ifdef IKSD
  7420.                     if (!local && inserver) {
  7421.                         x = coninc(0);
  7422.                     } else
  7423. #endif /* IKSD */
  7424. #ifdef OS2
  7425.                     x = is_a_tty(0) ? coninc(0) : /* with no echo ... */
  7426.               getchar();
  7427. #else /* OS2 */
  7428.                     x = getchar();
  7429. #endif /* OS2 */
  7430.         }
  7431.         *s2 = NUL;
  7432.         putchar('\n');
  7433.         }
  7434.         s2 = sbuf;
  7435.     } else s2 = "";
  7436. #endif /* DIRPWDPR */
  7437.  
  7438.     debug(F110," password",s2,0);
  7439.     sstate = setgen('C',s,s2,"");
  7440.     retcode = 0;
  7441.     break;
  7442.  
  7443.       case XZDEL:                /* Delete */
  7444.     if ((x = cmtxt("Name of remote file(s) to delete",
  7445.                "",&s,xxstring)) < 0) {
  7446.         if (x == -3) {
  7447.         printf("?Name of remote file(s) required\n");
  7448.         return(-9);
  7449.         } else return(x);
  7450.     }
  7451.     if ((x = remtxt(&s)) < 0)
  7452.       return(x);
  7453.     if (local) ttflui();        /* If local, flush tty input buffer */
  7454.     retcode = sstate = rfilop(s,'E');
  7455.     break;
  7456.  
  7457.       case XZDIR:            /* Directory */
  7458.     if ((x = cmtxt("Remote directory or file specification","",&s,
  7459.                xxstring)) < 0)
  7460.       return(x);
  7461.     if ((x = remtxt(&s)) < 0)
  7462.       return(x);
  7463.     if (local) ttflui();        /* If local, flush tty input buffer */
  7464.     rmsg();
  7465.     retcode = sstate = setgen('D',s,"","");
  7466.     break;
  7467.  
  7468.       case XZHLP:            /* Help */
  7469.     if ((x = remcfm()) < 0) return(x);
  7470.     sstate = setgen('H',"","","");
  7471.     retcode = 0;
  7472.     break;
  7473.  
  7474.       case XZHOS:            /* Host */
  7475.     if ((x = cmtxt("Command for remote system","",&s,xxstring)) < 0)
  7476.       return(x);
  7477.     if ((x = remtxt(&s)) < 0)
  7478.       return(x);
  7479.     if ((y = (int)strlen(s)) < 1)
  7480.       return(x);
  7481.     ckstrncpy(line,s,LINBUFSIZ);
  7482.     cmarg = line;
  7483.     rmsg();
  7484.     retcode = sstate = 'c';
  7485.     break;
  7486.  
  7487. #ifndef NOFRILLS
  7488.       case XZKER:
  7489.     if ((x = cmtxt("Command for remote Kermit","",&s,xxstring)) < 0)
  7490.       return(x);
  7491.     if ((x = remtxt(&s)) < 0)
  7492.       return(x);
  7493.     if ((int)strlen(s) < 1)  {
  7494.         if (x == -3) {
  7495.         printf("?Remote Kermit command required\n");
  7496.         return(-9);
  7497.         } else return(x);
  7498.     }
  7499.     ckstrncpy(line,s,LINBUFSIZ);
  7500.     cmarg = line;
  7501.     retcode = sstate = 'k';
  7502.     rmsg();
  7503.     break;
  7504.  
  7505.       case XZLGI:            /* Login */
  7506.     return(plogin(XXREM));
  7507.  
  7508.       case XZLGO: {            /* Logout */
  7509.       extern int bye_active;
  7510.       if ((x = remcfm()) < 0) return(x);
  7511.       sstate = setgen('I',"","","");
  7512.       retcode = 0;
  7513.       bye_active = 1;        /* Close connection when done */
  7514.       break;
  7515.       }
  7516.  
  7517.       case XZPRI:            /* Print */
  7518.     if (!atdiso || !atcapr) {    /* Disposition attribute off? */
  7519.         printf("?Disposition Attribute is Off\n");
  7520.         return(-2);
  7521.     }
  7522.     cmarg = "";
  7523.     cmarg2 = "";
  7524.     if ((x = cmifi("Local file(s) to print on remote printer","",&s,&y,
  7525.                xxstring)) < 0) {
  7526.         if (x == -3) {
  7527.         printf("?Name of local file(s) required\n");
  7528.         return(-9);
  7529.         }
  7530.         return(x);
  7531.     }
  7532.     ckstrncpy(line,s,LINBUFSIZ);    /* Make a safe copy of filename */
  7533.     *optbuf = NUL;            /* Wipe out any old options */
  7534.     if ((x = cmtxt("Options for remote print command","",&s,xxstring)) < 0)
  7535.       return(x);
  7536.     if ((x = remtxt(&s)) < 0)
  7537.       return(x);
  7538.     if ((int)strlen(optbuf) > 94) {    /* Make sure this is legal */
  7539.         printf("?Option string too long\n");
  7540.         return(-9);
  7541.     }
  7542.     ckstrncpy(optbuf,s,OPTBUFLEN);    /* Make a safe copy of options */
  7543.     nfils = -1;            /* Expand file list internally */
  7544.     cmarg = line;            /* Point to file list. */
  7545.     rprintf = 1;            /* REMOTE PRINT modifier for SEND */
  7546.     sstate = 's';            /* Set start state to SEND */
  7547.     if (local) displa = 1;
  7548.     retcode = 0;
  7549.     break;
  7550. #endif /* NOFRILLS */
  7551.  
  7552.       case XZSPA:            /* Space */
  7553.     if ((x = cmtxt("Confirm, or remote directory name",
  7554.                "",&s,xxstring)) < 0)
  7555.       return(x);
  7556.     if ((x = remtxt(&s)) < 0)
  7557.       return(x);
  7558.     retcode = sstate = setgen('U',s,"","");
  7559.     break;
  7560.  
  7561. #ifndef NOFRILLS
  7562.       case XZTYP:            /* Type */
  7563.     if ((x = cmtxt("Remote file specification","",&s,xxstring)) < 0)
  7564.       return(x);
  7565.     if ((int)strlen(s) < 1) {
  7566.         printf("?Remote filename required\n");
  7567.         return(-9);
  7568.     }
  7569.     if ((x = remtxt(&s)) < 0)
  7570.       return(x);
  7571.     rmsg();
  7572.     retcode = sstate = rfilop(s,'T');
  7573.     break;
  7574. #endif /* NOFRILLS */
  7575.  
  7576. #ifndef NOFRILLS
  7577.       case XZWHO:
  7578.     if ((x = cmtxt("Remote user name, or carriage return",
  7579.                "",&s,xxstring)) < 0)
  7580.       return(x);
  7581.     if ((x = remtxt(&s)) < 0)
  7582.       return(x);
  7583.     retcode = sstate = setgen('W',s,"","");
  7584.     break;
  7585. #endif /* NOFRILLS */
  7586.  
  7587.       case XZPWD:            /* PWD */
  7588.     if ((x = remcfm()) < 0) return(x);
  7589.     sstate = setgen('A',"","","");
  7590.     retcode = 0;
  7591.     break;
  7592.  
  7593. #ifndef NOSPL
  7594.       case XZQUE: {            /* Query */
  7595.       char buf[2];
  7596.       extern char querybuf[], * qbufp;
  7597.       extern int qbufn;
  7598.       if ((y = cmkey(vartyp,nvartyp,"","",xxstring)) < 0)
  7599.         return(y);
  7600.       if ((x = cmtxt(y == 'F' ? "Remote function invocation" :
  7601.              ('K' ? "Remote variable name or function":
  7602.              "Remote variable name"),
  7603.              "",
  7604.              &s,
  7605.              (y == 'K') ? xxstring : NULL
  7606.              )) < 0)    /* Don't evaluate */
  7607.         return(x);
  7608.       if ((x = remtxt(&s)) < 0)
  7609.         return(x);
  7610.       query = 1;            /* QUERY is active */
  7611.       qbufp = querybuf;        /* Initialize query response buffer */
  7612.       qbufn = 0;
  7613.       querybuf[0] = NUL;
  7614.       buf[0] = (char) (y & 127);
  7615.       buf[1] = NUL;
  7616.       retcode = sstate = setgen('V',"Q",(char *)buf,s);
  7617.       break;
  7618.       }
  7619.  
  7620.       case XZASG: {            /* Assign */
  7621.       char buf[VNAML];
  7622.       if ((y = cmfld("Remote variable name","",&s,NULL)) < 0) /* No eval */
  7623.         return(y);
  7624.       if ((int)strlen(s) >= VNAML) {
  7625.           printf("?Too long\n");
  7626.           return(-9);
  7627.       }
  7628.       ckstrncpy(buf,s,VNAML);
  7629.       if ((x = cmtxt("Assignment for remote variable",
  7630.            "",&s,xxstring)) < 0) /* Evaluate this one */
  7631.         return(x);
  7632.       if ((x = remtxt(&s)) < 0)
  7633.         return(x);
  7634. #ifdef COMMENT
  7635. /*
  7636.   Server commands can't be long packets.  In principle there's no reason
  7637.   why they shouldn't be, except that we don't know at this point if the
  7638.   server is capable of accepting long packets because we haven't started
  7639.   the protocol yet.  In practice, allowing a long packet here breaks a lot
  7640.   of assumptions, causes buffer overruns and crashes, etc.  To be fixed
  7641.   later.  (But since this is commented out, evidently I fixed it later...)
  7642. */
  7643.       if ((int)strlen(s) > 85) {    /* Allow for encoding expansion */
  7644.           printf("?Sorry, value is too long - 85 characters max\n");
  7645.           return(-9);
  7646.       }
  7647. #endif /* COMMENT */
  7648.       retcode = sstate = setgen('V',"S",(char *)buf,s);
  7649.       break;
  7650.       }
  7651. #endif /* NOSPL */
  7652.  
  7653.       case XZCPY: {            /* COPY */
  7654.       char buf[TMPBUFSIZ];
  7655.       buf[TMPBUFSIZ-1] = '\0';
  7656.       if ((x = cmfld("Name of remote file to copy","",&s,xxstring)) < 0) {
  7657.           if (x == -3) {
  7658.           printf("?Name of remote file required\n");
  7659.           return(-9);
  7660.           }
  7661.           else
  7662.         return(x);
  7663.       }
  7664.       ckstrncpy(buf,s,TMPBUFSIZ);
  7665.       if ((x = cmfld("Name of remote destination file or directory",
  7666.              "",&s, xxstring)) < 0) {
  7667.           if (x == -3) {
  7668.           printf("?Name of remote file or directory required\n");
  7669.           return(-9);
  7670.           } else return(x);
  7671.       }
  7672.       ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  7673.       if ((x = remcfm()) < 0)
  7674.         return(x);
  7675.       if (local) ttflui();        /* If local, flush tty input buffer */
  7676.       retcode = sstate = setgen('K',buf,tmpbuf,"");
  7677.       break;
  7678.       }
  7679.       case XZREN: {            /* Rename */
  7680.       char buf[TMPBUFSIZ];
  7681.       buf[TMPBUFSIZ-1] = '\0';
  7682.       if ((x = cmfld("Name of remote file to rename",
  7683.              "",&s,xxstring)) < 0) {
  7684.           if (x == -3) {
  7685.           printf("?Name of remote file required\n");
  7686.           return(-9);
  7687.           } else return(x);
  7688.       }
  7689.       ckstrncpy(buf,s,TMPBUFSIZ);
  7690.       if ((x = cmfld("New name of remote file","",&s, xxstring)) < 0) {
  7691.           if (x == -3) {
  7692.           printf("?Name of remote file required\n");
  7693.           return(-9);
  7694.           } else return(x);
  7695.       }
  7696.       ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  7697.       if ((x = remcfm()) < 0)
  7698.         return(x);
  7699.       if (local) ttflui();        /* If local, flush device buffer */
  7700.       retcode = sstate = setgen('R',buf,tmpbuf,"");
  7701.       break;
  7702.       }
  7703.       case XZMKD:            /* mkdir */
  7704.       case XZRMD:            /* rmdir */
  7705.     if ((x = cmtxt((xx == XZMKD) ?
  7706.                "Name of remote directory to create" :
  7707.                "Name of remote directory to delete",
  7708.                "",
  7709.                &s,
  7710.                xxstring
  7711.                )) < 0) {
  7712.         if (x == -3) {
  7713.         printf("?Name required\n");
  7714.         return(-9);
  7715.         } else return(x);
  7716.     }
  7717.     if ((x = remtxt(&s)) < 0)
  7718.       return(x);
  7719.     if (local) ttflui();        /* If local, flush tty input buffer */
  7720.     retcode = sstate = rfilop(s, (char)(xx == XZMKD ? 'm' : 'd'));
  7721.     break;
  7722.  
  7723.       case XZXIT:            /* Exit */
  7724.     if ((x = remcfm()) < 0) return(x);
  7725.     sstate = setgen('X',"","","");
  7726.     retcode = 0;
  7727.     break;
  7728.  
  7729.       default:
  7730.         if ((x = remcfm()) < 0) return(x);
  7731.         printf("?Not implemented - %s\n",cmdbuf);
  7732.         return(-2);
  7733.     }
  7734.     if (local && retcode > -1)        /* If local, flush tty input buffer */
  7735.       ttflui();
  7736.     return(retcode);
  7737. }
  7738.  
  7739.  
  7740. /*  R F I L O P  --  Remote File Operation  */
  7741.  
  7742. CHAR
  7743. #ifdef CK_ANSIC
  7744. rfilop(char * s, char t)
  7745. #else
  7746. rfilop(s,t) char *s, t;
  7747. #endif /* CK_ANSIC */
  7748. /* rfilop */ {
  7749.     if (*s == NUL) {
  7750.     printf("?File specification required\n");
  7751.     return((CHAR) 0);
  7752.     }
  7753.     debug(F111,"rfilop",s,t);
  7754.     return(setgen(t,s,"",""));
  7755. }
  7756. #endif /* NOXFER */
  7757.  
  7758. #ifdef ANYX25
  7759. int
  7760. setx25() {
  7761.     if ((y = cmkey(x25tab,nx25,"X.25 call options","",xxstring)) < 0)
  7762.       return(y);
  7763.     switch (y) {
  7764.       case XYUDAT:
  7765.     if ((z = cmkey(onoff,2,"X.25 call user data","",xxstring))
  7766.         < 0) return(z);
  7767.     if (z == 0) {
  7768.         if ((z = cmcfm()) < 0) return(z);
  7769.         cudata = 0;             /* disable call user data */
  7770.         return (success = 1);
  7771.     }
  7772.     if ((x = cmtxt("X.25 call user data string","",&s,xxstring)) < 0)
  7773.       return(x);
  7774.     if ((int)strlen(s) == 0) {
  7775.         return (-3);
  7776.     } else if ((int)strlen(s) > MAXCUDATA) {
  7777.         printf("?The length must be > 0 and <= %d\n",MAXCUDATA);
  7778.         return(-2);
  7779.     }
  7780.     if ((y = cmcfm()) < 0) return(y);
  7781.     ckstrncpy(udata,s,MAXCUDATA);
  7782.     cudata = 1;            /* X.25 call user data specified */
  7783.     return (success = 1);
  7784.       case XYCLOS:
  7785.     if ((z = cmkey(onoff,2,"X.25 closed user group call","",xxstring))
  7786.         < 0) return(z);
  7787.     if (z == 0) {
  7788.         if ((z = cmcfm()) < 0) return(z);
  7789.         closgr = -1;        /* disable closed user group */
  7790.         return (success = 1);
  7791.     }
  7792.     if ((y = cmnum("0 <= cug index >= 99","",10,&x,xxstring)) < 0)
  7793.       return(y);
  7794.     if (x < 0 || x > 99) {
  7795.         printf("?The choices are 0 <= cug index >= 99\n");
  7796.         return(-2);
  7797.     }
  7798.     if ((y = cmcfm()) < 0) return(y);
  7799.     closgr = x;            /* closed user group selected */
  7800.     return (success = 1);
  7801.  
  7802.       case XYREVC:
  7803.     if((z = cmkey(onoff,2,"X.25 reverse charge call","",xxstring)) < 0)
  7804.       return(z);
  7805.     if ((x = cmcfm()) < 0) return(x);
  7806.     revcall = z;
  7807.     return (success = 1);
  7808.     }
  7809. }
  7810.  
  7811. #ifndef IBMX25
  7812. int
  7813. setpadp() {
  7814.     if ((y = cmkey(padx3tab,npadx3,"PAD X.3 parameter name","",xxstring)) < 0)
  7815.       return(y);
  7816.     x = y;
  7817.     switch (x) {
  7818.       case PAD_BREAK_CHARACTER:
  7819.     if ((y = cmnum("PAD break character value","",10,&z,xxstring)) < 0)
  7820.       return(y);
  7821.     if ((y = cmcfm()) < 0) return(y);
  7822.     break;
  7823.       case PAD_ESCAPE:
  7824.     if ((y = cmnum("PAD escape","",10,&z,xxstring)) < 0) return(y);
  7825.     if (z != 0 && z != 1) {
  7826.         printf("?The choices are 0 or 1\n");
  7827.         return(-2);
  7828.     }
  7829.     if ((y = cmcfm()) < 0) return(y);
  7830.     break;
  7831.       case PAD_ECHO:
  7832.      if ((y = cmnum("PAD echo","",10,&z,xxstring)) < 0) return(y);
  7833.     if (z != 0 && z != 1) {
  7834.         printf("?The choices are 0 or 1\n");
  7835.         return(-2);
  7836.     }
  7837.     if ((y = cmcfm()) < 0) return(y);
  7838.     break;
  7839.       case PAD_DATA_FORWARD_CHAR:
  7840.      if ((y = cmnum("PAD data forward char","",10,&z,xxstring)) < 0)
  7841.       return(y);
  7842.     if (z != 0 && z != 2) {
  7843.         printf("?The choices are 0 or 2\n");
  7844.         return(-2);
  7845.     }
  7846.     if ((y = cmcfm()) < 0) return(y);
  7847.     break;
  7848.       case PAD_DATA_FORWARD_TIMEOUT:
  7849.      if ((y = cmnum("PAD data forward timeout","",10,&z,xxstring)) < 0)
  7850.         return(y);
  7851.     if (z < 0 || z > 255) {
  7852.         printf("?The choices are 0 or 1 <= timeout <= 255\n");
  7853.         return(-2);
  7854.     }
  7855.     if ((y = cmcfm()) < 0) return(y);
  7856.     break;
  7857.       case PAD_FLOW_CONTROL_BY_PAD:
  7858.      if ((y = cmnum("PAD pad flow control","",10,&z,xxstring)) < 0)
  7859.       return(y);
  7860.     if (z != 0 && z != 1) {
  7861.         printf("?The choices are 0 or 1\n");
  7862.         return(-2);
  7863.     }
  7864.     if ((y = cmcfm()) < 0) return(y);
  7865.     break;
  7866.       case PAD_SUPPRESSION_OF_SIGNALS:
  7867.      if ((y = cmnum("PAD service","",10,&z,xxstring)) < 0) return(y);
  7868.     if (z != 0 && z != 1) {
  7869.         printf("?The choices are 0 or 1\n");
  7870.         return(-2);
  7871.     }
  7872.     if ((y = cmcfm()) < 0) return(y);
  7873.     break;
  7874.  
  7875.       case PAD_BREAK_ACTION:
  7876.      if ((y = cmnum("PAD break action","",10,&z,xxstring)) < 0) return(y);
  7877.     if (z != 0 && z != 1 && z != 2 && z != 5 && z != 8 && z != 21) {
  7878.         printf("?The choices are 0, 1, 2, 5, 8 or 21\n");
  7879.         return(-2);
  7880.     }
  7881.     if ((y = cmcfm()) < 0) return(y);
  7882.     break;
  7883.  
  7884.       case PAD_SUPPRESSION_OF_DATA:
  7885.      if ((y = cmnum("PAD data delivery","",10,&z,xxstring)) < 0) return(y);
  7886.     if (z != 0 && z != 1) {
  7887.         printf("?The choices are 0 or 1\n");
  7888.         return(-2);
  7889.     }
  7890.     if ((y = cmcfm()) < 0) return(y);
  7891.     break;
  7892.  
  7893.       case PAD_PADDING_AFTER_CR:
  7894.      if ((y = cmnum("PAD crpad","",10,&z,xxstring)) < 0) return(y);
  7895.     if (z < 0 || z > 7) {
  7896.         printf("?The choices are 0 or 1 <= crpad <= 7\n");
  7897.         return(-2);
  7898.     }
  7899.     if ((y = cmcfm()) < 0) return(y);
  7900.     break;
  7901.  
  7902.       case PAD_LINE_FOLDING:
  7903.      if ((y = cmnum("PAD linefold","",10,&z,xxstring)) < 0) return(y);
  7904.     if (z < 0 || z > 255) {
  7905.         printf("?The choices are 0 or 1 <= linefold <= 255\n");
  7906.         return(-2);
  7907.     }
  7908.     if ((y = cmcfm()) < 0) return(y);
  7909.     break;
  7910.  
  7911.       case PAD_LINE_SPEED:
  7912.      if ((y = cmnum("PAD baudrate","",10,&z,xxstring)) < 0) return(y);
  7913.     if (z < 0 || z > 18) {
  7914.         printf("?The choices are 0 <= baudrate <= 18\n");
  7915.         return(-2);
  7916.     }
  7917.     if ((y = cmcfm()) < 0) return(y);
  7918.     break;
  7919.  
  7920.       case PAD_FLOW_CONTROL_BY_USER:
  7921.      if ((y = cmnum("PAD terminal flow control","",10,&z,xxstring)) < 0)
  7922.         return(y);
  7923.     if (z != 0 && z != 1) {
  7924.         printf("?The choices are 0 or 1\n");
  7925.         return(-2);
  7926.     }
  7927.     if ((y = cmcfm()) < 0) return(y);
  7928.     break;
  7929.  
  7930.       case PAD_LF_AFTER_CR:
  7931.      if ((y = cmnum("PAD crpad","",10,&z,xxstring)) < 0) return(y);
  7932.     if (z < 0 || z == 3 || z > 7) {
  7933.         printf("?The choices are 0, 1, 2, 4, 5, 6 or 7\n");
  7934.         return(-2);
  7935.     }
  7936.     if ((y = cmcfm()) < 0) return(y);
  7937.     break;
  7938.  
  7939.       case PAD_PADDING_AFTER_LF:
  7940.      if ((y = cmnum("PAD lfpad","",10,&z,xxstring)) < 0) return(y);
  7941.     if (z < 0 || z > 7) {
  7942.         printf("?The choices are 0 or 1 <= lfpad <= 7\n");
  7943.         return(-2);
  7944.     }
  7945.     if ((y = cmcfm()) < 0) return(y);
  7946.     break;
  7947.  
  7948.       case PAD_EDITING:
  7949.      if ((y = cmnum("PAD edit control","",10,&z,xxstring)) < 0) return(y);
  7950.     if (z != 0 && z != 1) {
  7951.         printf("?The choices are 0 or 1\n");
  7952.         return(-2);
  7953.     }
  7954.     if ((y = cmcfm()) < 0) return(y);
  7955.     break;
  7956.  
  7957.       case PAD_CHAR_DELETE_CHAR:
  7958.      if ((y = cmnum("PAD char delete char","",10,&z,xxstring)) < 0)
  7959.         return(y);
  7960.     if (z < 0 || z > 127) {
  7961.         printf("?The choices are 0 or 1 <= chardelete <= 127\n");
  7962.         return(-2);
  7963.     }
  7964.     if ((y = cmcfm()) < 0) return(y);
  7965.     break;
  7966.  
  7967.       case PAD_BUFFER_DELETE_CHAR:
  7968.      if ((y = cmnum("PAD buffer delete char","",10,&z,xxstring)) < 0)
  7969.         return(y);
  7970.     if (z < 0 || z > 127) {
  7971.         printf("?The choices are 0 or 1 <= bufferdelete <= 127\n");
  7972.         return(-2);
  7973.     }
  7974.     if ((y = cmcfm()) < 0) return(y);
  7975.     break;
  7976.  
  7977.       case PAD_BUFFER_DISPLAY_CHAR:
  7978.      if ((y = cmnum("PAD display line char","",10,&z,xxstring)) < 0)
  7979.         return(y);
  7980.     if (z < 0 || z > 127) {
  7981.         printf("?The choices are 0 or 1 <= displayline <= 127\n");
  7982.         return(-2);
  7983.     }
  7984.     if ((y = cmcfm()) < 0) return(y);
  7985.     break;
  7986.     }
  7987.     padparms[x] = z;
  7988.     return(success = 1);
  7989. }
  7990. #endif /* IBMX25 */
  7991. #endif /* ANYX25 */
  7992.  
  7993. #ifndef NOXFER
  7994. int
  7995. setat(rmsflg) int rmsflg; {
  7996.     int xx;
  7997.     if ((y = cmkey(attrtab,natr,"File Attribute packets","",xxstring)) < 0)
  7998.       return(y);
  7999.     if (y == AT_XALL) {            /* ATTRIBUTES ALL ON or ALL OFF */
  8000.     if ((z = seton(&xx)) < 0) return(z);
  8001.     if (rmsflg) {
  8002.         printf("Sorry, command not available\n");
  8003.         return(-9);
  8004.     } else {
  8005.         atenci = xx;        /* Encoding in */
  8006.         atenco = xx;        /* Encoding out */
  8007.         atdati = xx;        /* Date in */
  8008.         atdato = xx;        /* Date out */
  8009.         atdisi = xx;        /* Disposition in/out */
  8010.         atdiso = xx;
  8011.         atleni = xx;        /* Length in/out (both kinds) */
  8012.         atleno = xx;
  8013.         atblki = xx;        /* Blocksize in/out */
  8014.         atblko = xx;
  8015.         attypi = xx;        /* File type in/out */
  8016.         attypo = xx;
  8017.         atsidi = xx;        /* System ID in/out */
  8018.         atsido = xx;
  8019.         atsysi = xx;        /* System-dependent params in/out */
  8020.         atsyso = xx;
  8021. #ifdef CK_PERMS                /* Protection */
  8022.         atlpri = xx;        /* Local in */
  8023.         atlpro = xx;        /* Local out */
  8024.         atgpri = xx;        /* Generic in */
  8025.         atgpro = xx;        /* Generic out */
  8026. #endif /* CK_PERMS */
  8027. #ifdef STRATUS
  8028.         atfrmi = xx;        /* Format in/out */
  8029.         atfrmo = xx;
  8030.         atcrei = xx;        /* Creator id in/out */
  8031.         atcreo = xx;
  8032.         atacti = xx;        /* Account in/out */
  8033.         atacto = xx;
  8034. #endif /* STRATUS */
  8035.     }
  8036.     return(z);
  8037.     } else if (y == AT_ALLY || y == AT_ALLN) { /* ATTRIBUTES ON or OFF */
  8038.     if ((x = cmcfm()) < 0) return(x);
  8039.     atcapr = (y == AT_ALLY) ? 1 : 0;
  8040.     if (rmsflg) {
  8041.         sstate = setgen('S', "132", atcapr ? "1" : "0", "");
  8042.         return((int) sstate);
  8043.     } else return(success = 1);
  8044.     }
  8045.     /* Otherwise, it's an individual attribute that wants turning off/on */
  8046.  
  8047.     if ((z = cmkey(onoff,2,"","",xxstring)) < 0) return(z);
  8048.     if ((x = cmcfm()) < 0) return(x);
  8049.  
  8050. /* There are better ways to do this... */
  8051. /* The real problem is that we're not separating the in and out cases */
  8052. /* and so we have to arbitrarily pick the "in" case, i.e tell the remote */
  8053. /* server to ignore incoming attributes of the specified type, rather */
  8054. /* than telling it not to send them.  The protocol does not (yet) define */
  8055. /* codes for "in-and-out-at-the-same-time". */
  8056.  
  8057.     switch (y) {
  8058. #ifdef CK_PERMS
  8059. /* We're lumping local and generic protection together for now... */
  8060.       case AT_LPRO:
  8061.       case AT_GPRO:
  8062.     if (rmsflg) {
  8063.         sstate = setgen('S', "143", z ? "1" : "0", "");
  8064.         return((int) sstate);
  8065.     }
  8066.     atlpri = atlpro = atgpri = atgpro = z; break;
  8067. #endif /* CK_PERMS */
  8068.       case AT_DISP:
  8069.     if (rmsflg) {
  8070.         sstate = setgen('S', "142", z ? "1" : "0", "");
  8071.         return((int) sstate);
  8072.     }
  8073.     atdisi = atdiso = z; break;
  8074.       case AT_ENCO:
  8075.     if (rmsflg) {
  8076.         sstate = setgen('S', "141", z ? "1" : "0", "");
  8077.         return((int) sstate);
  8078.     }
  8079.     atenci = atenco = z; break;
  8080.       case AT_DATE:
  8081.     if (rmsflg) {
  8082.         sstate = setgen('S', "135", z ? "1" : "0", "");
  8083.         return((int) sstate);
  8084.     }
  8085.     atdati = atdato = z; break;
  8086.       case AT_LENB:
  8087.       case AT_LENK:
  8088.     if (rmsflg) {
  8089.         sstate = setgen('S', "133", z ? "1" : "0", "");
  8090.         return((int) sstate);
  8091.     }
  8092.     atleni = atleno = z; break;
  8093.       case AT_BLKS:
  8094.     if (rmsflg) {
  8095.         sstate = setgen('S', "139", z ? "1" : "0", "");
  8096.         return((int) sstate);
  8097.     }
  8098.     atblki = atblko = z; break;
  8099.       case AT_FTYP:
  8100.     if (rmsflg) {
  8101.         sstate = setgen('S', "134", z ? "1" : "0", "");
  8102.         return((int) sstate);
  8103.     }
  8104.     attypi = attypo = z; break;
  8105. #ifdef STRATUS
  8106.       case AT_CREA:
  8107.     if (rmsflg) {
  8108.         sstate = setgen('S', "136", z ? "1" : "0", "");
  8109.         return((int) sstate);
  8110.     }
  8111.     atcrei = atcreo = z; break;
  8112.       case AT_ACCT:
  8113.     if (rmsflg) {
  8114.         sstate = setgen('S', "137", z ? "1" : "0", "");
  8115.         return((int) sstate);
  8116.     }
  8117.     atacti = atacto = z; break;
  8118. #endif /* STRATUS */
  8119.       case AT_SYSI:
  8120.     if (rmsflg) {
  8121.         sstate = setgen('S', "145", z ? "1" : "0", "");
  8122.         return((int) sstate);
  8123.     }
  8124.     atsidi = atsido = z; break;
  8125.       case AT_RECF:
  8126.     if (rmsflg) {
  8127.         sstate = setgen('S', "146", z ? "1" : "0", "");
  8128.         return((int) sstate);
  8129.     }
  8130.         atfrmi = atfrmo = z; break;
  8131.       case AT_SYSP:
  8132.     if (rmsflg) {
  8133.         sstate = setgen('S', "147", z ? "1" : "0", "");
  8134.         return((int) sstate);
  8135.     }
  8136.     atsysi = atsyso = z; break;
  8137.       default:
  8138.     printf("?Not available\n");
  8139.     return(-2);
  8140.     }
  8141.     return(1);
  8142. }
  8143. #endif /* NOXFER */
  8144.  
  8145. #ifndef NOSPL
  8146. int
  8147. setinp() {
  8148.     if ((y = cmkey(inptab,ninp,"","",xxstring)) < 0) return(y);
  8149.     switch (y) {
  8150. #ifdef OS2
  8151.       case IN_PAC:            /* SET INPUT PACING */
  8152.     z = cmnum("milliseconds","0",10,&x,xxstring);
  8153.     return(setnum(&tt_inpacing,x,z,1000));
  8154.       case IN_TRM:            /* SET INPUT TERMINAL */
  8155.     return(seton(&interm));
  8156. #endif /* OS2 */
  8157.       case IN_DEF:            /* SET INPUT DEFAULT-TIMEOUT */
  8158.     z = cmnum("Positive number","",10,&x,xxstring);
  8159.     return(setnum(&indef,x,z,94));
  8160.       case IN_TIM:            /* SET INPUT TIMEOUT-ACTION */
  8161.     if ((z = cmkey(intimt,2,"","",xxstring)) < 0) return(z);
  8162.     if ((x = cmcfm()) < 0) return(x);
  8163.     intime[cmdlvl] = z;
  8164.     return(success = 1);
  8165.       case IN_CAS:            /* SET INPUT CASE */
  8166.     if ((z = cmkey(incast,2,"","",xxstring)) < 0) return(z);
  8167.     if ((x = cmcfm()) < 0) return(x);
  8168.     inpcas[cmdlvl] = z;
  8169.     return(success = 1);
  8170.       case IN_ECH:            /* SET INPUT ECHO */
  8171.     return(seton(&inecho));
  8172.       case IN_SIL:            /* SET INPUT SILENCE */
  8173.     z = cmnum("Seconds of inactivity before INPUT fails","",10,&x,
  8174.           xxstring);
  8175.     return(setnum(&insilence,x,z,-1));
  8176.  
  8177.       case IN_BUF:            /* SET INPUT BUFFER-SIZE */
  8178.     if ((z = cmnum("Number of bytes in INPUT buffer",
  8179.                ckitoa(INPBUFSIZ),10,&x, xxstring)) < 0)
  8180.       return(z);
  8181.     if ((y = cmcfm()) < 0) return(y);
  8182.     inbufsize = 0;
  8183.     if (inpbuf) {
  8184.         free(inpbuf);
  8185.         inpbuf = NULL;
  8186.         inpbp = NULL;
  8187.     }
  8188.     if (!(s = (char *)malloc(x + 1)))
  8189.       return(0);
  8190.     inpbuf = s;
  8191.     inpbp = s;
  8192.     inbufsize = x;
  8193.     for (x = 0; x <= inbufsize; x++)
  8194.       inpbuf[x] = NUL;
  8195.     return(success = 1);
  8196.  
  8197. #ifdef CK_AUTODL
  8198.       case IN_ADL:            /* AUTODOWNLOAD */
  8199.     return(seton(&inautodl));
  8200. #endif /* CK_AUTODL */
  8201.  
  8202.       case IN_CAN:            /* SET INPUT INTERRUPTS */
  8203.     return(seton(&inintr));
  8204.     }
  8205.     return(0);
  8206. }
  8207. #endif /* NOSPL */
  8208.  
  8209. #ifdef NETCONN
  8210. VOID
  8211. ndreset() {
  8212. #ifndef NODIAL                /* This depends on DIAL... */
  8213.     int i=0, j=0;
  8214.     if (!ndinited)            /* Don't free garbage... */
  8215.       return;
  8216.     for (i = 0; i < nhcount; i++) {    /* Clean out previous list */
  8217.     if (nh_p[i])
  8218.       free(nh_p[i]);
  8219.     nh_p[i] = NULL;
  8220.     if (nh_p2[i])
  8221.       free(nh_p2[i]);
  8222.     nh_p2[i] = NULL;
  8223.     for (j = 0; j < 4; j++) {
  8224.         if (nh_px[j][i])
  8225.           free(nh_px[j][i]);
  8226.         nh_px[j][i] = NULL;
  8227.     }
  8228.     }
  8229. #endif /* NODIAL */
  8230. }
  8231.  
  8232. VOID
  8233. ndinit() {                /* Net directory pointers */
  8234. #ifndef NODIAL                /* This depends on DIAL... */
  8235.     int i, j;
  8236.     if (ndinited++)            /* Don't do this more than once. */
  8237.       return;
  8238.     for (i = 0; i < MAXDDIR; i++) {    /* Init all pointers to NULL */
  8239.     netdir[i] = NULL;
  8240.     }
  8241.     for (i = 0; i < MAXDNUMS; i++) {
  8242.     nh_p[i] = NULL;
  8243.     nh_p2[i] = NULL;
  8244.     for (j = 0; j < 4; j++)
  8245.       nh_px[j][i] = NULL;
  8246.     }
  8247. #endif /* NODIAL */
  8248. }
  8249.  
  8250. #ifndef NODIAL
  8251. #ifdef NETCONN
  8252. VOID                    /* Get net defaults from environment */
  8253. getnetenv() {
  8254.     char *p = NULL;
  8255.  
  8256.     makestr(&p,getenv("K_NET_DIRECTORY")); /* Dialing directories */
  8257.     if (p) {
  8258.     int i;
  8259.     xwords(p,MAXDDIR,netdir,0);
  8260.     for (i = 0; i < MAXDDIR; i++) { /* Fill in any gaps... */
  8261.         if (!netdir[i+1])
  8262.           break;
  8263.         else
  8264.           netdir[i] = netdir[i+1];
  8265.             debug(F111,"netdir[i]",netdir[i],i);
  8266.     }
  8267.     nnetdir = i;
  8268.     }
  8269. }
  8270. #endif /* NETCONN */
  8271. #endif /* NODIAL */
  8272.  
  8273. int
  8274. #ifdef CK_ANSIC
  8275. lunet(char *s)                /* s = name to look up   */
  8276. #else
  8277. lunet(s) char *s;
  8278. #endif /* CK_ANSIC */
  8279. /* lunet */ {
  8280. #ifndef NODIAL                /* This depends on DIAL... */
  8281.     int n, n1, t, dd = 0;
  8282.     int ambiguous = 0;
  8283.     FILE * f;
  8284.     char *line = NULL;
  8285.     extern int dialdpy;
  8286.     int netdpy = dialdpy;
  8287.     char *info[8];
  8288.  
  8289.     nhcount = 0;            /* Set this before returning */
  8290.  
  8291.     if (!s || nnetdir < 1)        /* Validate arguments */
  8292.       return(-1);
  8293.  
  8294.     if (isdigit(*s) || *s == '*' || *s == '.')
  8295.       return(0);
  8296.  
  8297.     if ((n1 = (int) strlen(s)) < 1)    /* Length of string to look up */
  8298.       return(-1);
  8299.  
  8300.     if (!(line = malloc(1024)))        /* Allocate input buffer */
  8301.       return(-1);
  8302.  
  8303.   lu_again:
  8304.     f = NULL;                /* Network directory file descriptor */
  8305.     t = nhcount = 0;            /* Match count */
  8306.     dd = 0;                /* Directory counter */
  8307.  
  8308.     dirline = 0;
  8309.     while (1) {                /* We make one pass */
  8310.     if (!f) {            /* Directory not open */
  8311.             if (dd >= nnetdir)        /* No directories left? */
  8312.           break;            /* Done. */
  8313.         if ((f = fopen(netdir[dd],"r")) == NULL) { /* Open it */
  8314.         perror(netdir[dd]);    /* Can't, print message saying why */
  8315.         dd++;
  8316.         continue;        /* But go on to next one. */
  8317.         }
  8318.         if (netdpy)
  8319.           printf("Opening %s...\n",netdir[dd]);
  8320.             dd++;
  8321.     }
  8322.     line[0] = NUL;
  8323.     if (getnct(line,1023,f,1) < 0) { /* Read a line */
  8324.         if (f) {            /* f can be clobbered! */
  8325.         fclose(f);        /* Close the file */
  8326.         f = NULL;        /* Indicate next one needs opening */
  8327.         }
  8328.         continue;
  8329.     }
  8330.     if (!line[0])            /* Empty line */
  8331.       continue;
  8332.  
  8333.     xwords(line,7,info,0);        /* Parse it */
  8334.  
  8335.     if (!info[1] || !info[2] || !info[3]) /* Required fields */
  8336.       continue;
  8337.     if (*info[1] == ';')        /* Full-line comment */
  8338.       continue;
  8339.     if ((n = (int) strlen(info[1])) < 1) /* Length of name-tag */
  8340.       continue;
  8341.     if (n < n1)            /* Search name is longer */
  8342.       continue;            /* Can't possibly match */
  8343.     if (ambiguous && n != n1)
  8344.       continue;
  8345.     if (ckstrcmp(s,info[1],n1,0))    /* Compare using length of */
  8346.       continue;            /* search string s. */
  8347.  
  8348.     /* Have a match */
  8349.  
  8350.     makestr(&(nh_p[nhcount]), info[3]);    /* address */
  8351.     makestr(&(nh_p2[nhcount]),info[2]);    /* net type */
  8352.     makestr(&(nh_px[0][nhcount]),info[4]); /* net-specific stuff... */
  8353.     makestr(&(nh_px[1][nhcount]),info[5]);
  8354.     makestr(&(nh_px[2][nhcount]),info[6]);
  8355.     makestr(&(nh_px[3][nhcount]),info[7]);
  8356.  
  8357.     nhcount++;            /* Count this match */
  8358.     if (nhcount > MAXDNUMS) {    /* Watch out for too many */
  8359.         printf("Warning: %d matches found, %d max\n",
  8360.            nhcount,
  8361.            MAXDNUMS
  8362.            );
  8363.         nhcount = MAXDNUMS;
  8364.         break;
  8365.     }
  8366.     if (nhcount == 1) {        /* First one - save entry name */
  8367.         if (n_name) {        /* Free the one from before if any */
  8368.         free(n_name);
  8369.         n_name = NULL;
  8370.         }
  8371.         if (!(n_name = (char *)malloc(n + 1))) { /* Allocate new storage */
  8372.         printf("?memory allocation error - lunet:3\n");
  8373.         if (line) {
  8374.             free(line);
  8375.             line = NULL;
  8376.         }
  8377.         nhcount = 0;
  8378.         return(-1);
  8379.         }
  8380.         t = n;            /* Remember its length */
  8381.         strcpy(n_name,info[1]);    /* safe */
  8382.     } else {            /* Second or subsequent one */
  8383.         if ((int) strlen(info[1]) == t) /* Lengths compare */
  8384.           if (!ckstrcmp(n_name,info[1],t,0)) /* Caseless compare OK */
  8385.         continue;
  8386.  
  8387.         /* Name given by user matches entries with different names */
  8388.  
  8389.         if (ambiguous)        /* Been here before */
  8390.           break;
  8391.  
  8392.         ambiguous = 1;        /* Now an exact match is required */
  8393.         ndreset();            /* Clear out previous list */
  8394.         goto lu_again;        /* Do it all over again. */
  8395.     }
  8396.     }
  8397.     if (line) {
  8398.     free(line);
  8399.     line = NULL;
  8400.     }
  8401.     if (nhcount == 0 && ambiguous)
  8402.       printf("?\"%s\" - ambiguous in network directory\n",s);
  8403. #else
  8404.     nhcount = 0;
  8405. #endif /* NODIAL */
  8406.     return(nhcount);
  8407. }
  8408. #endif /* NETCONN */
  8409.  
  8410. #ifndef NOLOCAL
  8411. /*  C L S C O N N X  --  Close connection  */
  8412.  
  8413. int
  8414. clsconnx(ask) int ask; {
  8415.     int x, rc = 0;
  8416. #ifdef NEWFTP
  8417.     extern int ftpget, ftpisopen(), ftpbye();
  8418.     if ((ftpget == 1) || ((ftpget == 2) && !local && ftpisopen()))
  8419.       return(success = ftpbye());
  8420. #endif /* NEWFTP */
  8421.     debug(F101,"clsconnx local","",local);
  8422.     if (local) {
  8423.     x = ask ? hupok(1) : 1;        /* Make sure it's OK to close */
  8424.     if (!x) {
  8425.         rc = -1;
  8426.         debug(F101,"clsconnx hupok says no","",rc);
  8427.         return(rc);
  8428.     }
  8429.     ttflui();            /* Clear away buffered up junk */
  8430. #ifndef NODIAL
  8431. #ifdef OS2ONLY
  8432. /* Don't hangup a line that is shared with the SLIP or PPP driver */
  8433.     if (!ttslip && !ttppp)
  8434. #endif /* OS2ONLY */
  8435.       mdmhup();
  8436. #endif /* NODIAL */
  8437.     if (network && msgflg)
  8438.       printf(" Closing connection\n");
  8439.     ttclos(0);            /* Close old connection, if any */
  8440.     rc = 1;
  8441.     {
  8442.         extern int wasclosed, whyclosed;
  8443.         if (wasclosed) {
  8444.         whyclosed = WC_CLOS;
  8445. #ifndef NOSPL
  8446.                 if (nmac) {        /* Any macros defined? */
  8447.             int k;        /* Yes */
  8448.             /* printf("ON_CLOSE CLSCONNX\n"); */
  8449.             wasclosed = 0;
  8450.             k = mlook(mactab,"on_close",nmac);    /* Look this up */
  8451.             if (k >= 0) {            /* If found, */
  8452.             if (dodo(k,ckitoa(whyclosed),0) > -1) /* set it up, */
  8453.               parser(1);            /* and execute it */
  8454.             }
  8455.         }
  8456. #endif /* NOSPL */
  8457.         whyclosed = WC_REMO;
  8458.         wasclosed = 0;
  8459.         }
  8460.     }
  8461.     }
  8462. #ifdef VMS                /* Or maybe #ifndef UNIX? */
  8463.     else {                /* Need to do this in VMS to */
  8464.     ttclos(0);            /* free the tty channel number */
  8465.     rc = 1;                /* obtained in ttopen() or else */
  8466.     }                    /* subsequent ttopen's won't work */
  8467. #endif /* VMS */
  8468. #ifdef CKLOGDIAL
  8469.     dologend();
  8470. #endif /* CKLOGDIAL */
  8471.     haveline = 0;
  8472.     if (mdmtyp < 0) {            /* Switching from net to async? */
  8473.     if (mdmsav > -1)        /* Restore modem type from last */
  8474.       mdmtyp = mdmsav;        /* SET MODEM command, if any. */
  8475.     else
  8476.       mdmtyp = 0;
  8477.     mdmsav = -1;
  8478.     }
  8479.     if (network)
  8480.       network = 0;
  8481. #ifdef NETCONN
  8482.     if (oldplex > -1) {            /* Restore previous duplex setting. */
  8483.     duplex = oldplex;
  8484.     oldplex = -1;
  8485.     }
  8486. #endif /* NETCONN */
  8487. #ifndef MAC
  8488.     ckstrncpy(ttname,dftty,TTNAMLEN);    /* Restore default communication */
  8489. #endif /* MAC */
  8490.     local = dfloc;            /* device and local/remote status */
  8491.     if (local) {
  8492.     cxtype = CXT_DIRECT;        /* Something reasonable */
  8493.     speed = ttgspd();        /* Get the current speed */
  8494.     } else {
  8495.     cxtype = CXT_REMOTE;
  8496.     speed = -1L;
  8497.     }
  8498. #ifndef NOXFER
  8499.     if (xreliable > -1 && !setreliable) {
  8500.     reliable = xreliable;
  8501.     debug(F101,"clsconnx reliable A","",reliable);
  8502.     } else if (!setreliable) {
  8503.     reliable = SET_AUTO;
  8504.     debug(F101,"clsconnx reliable B","",reliable);
  8505.     }
  8506. #endif /* NOXFER */
  8507.     setflow();                /* Revert flow control */
  8508.     return(rc);
  8509. }
  8510.  
  8511. int
  8512. clskconnx(x) int x; {            /* Close Kermit connection only */
  8513.     int t, rc;                /* (not FTP) */
  8514. #ifdef NEWFTP
  8515.     extern int ftpget;
  8516.     t = ftpget;
  8517.     ftpget = 0;
  8518. #endif /* NEWFTP */
  8519.     rc = clsconnx(x);
  8520. #ifdef NEWFTP
  8521.     ftpget = t;
  8522. #endif /* NEWFTP */
  8523.     return(rc);
  8524. }
  8525.  
  8526.  
  8527. /* S E T L I N -- parse name of and then open communication device. */
  8528. /*
  8529.   Call with:
  8530.     xx == XYLINE for a serial (tty) line, XYHOST for a network host,
  8531.     zz == 0 means if user doesn't give a device name, continue current
  8532.             active connection (if any);
  8533.     zz != 0 means if user doesn't give a device name, then close the
  8534.             current connection and restore the default communication device.
  8535.     fc == 0 to just make the connection, 1 to also CONNECT (e.g. "telnet").
  8536. */
  8537. int netsave = -1;
  8538.  
  8539. static char * tmpstring = NULL;
  8540. static char * tmpusrid = NULL;
  8541.  
  8542. #define HOSTNAMLEN 15*65
  8543.  
  8544. #ifdef SSHCMD
  8545. char * sshcmd = NULL;
  8546. char * defsshcmd = "ssh -e none";
  8547. #else
  8548. #ifdef SSHBUILTIN
  8549. char * sshrcmd = NULL;
  8550. char * sshtmpcmd = NULL;
  8551. #endif /* SSHBUILTIN */
  8552. #endif /* SSHCMD */
  8553.  
  8554. int
  8555. setlin(xx, zz, fc) int xx, zz, fc; {
  8556.     extern char pwbuf[], * g_pswd;
  8557.     extern int pwflg, pwcrypt, g_pflg, g_pcpt, nolocal;
  8558. #ifndef NODIAL
  8559.     extern int dialsta;
  8560. #endif /* NODIAL */
  8561.     int wait;
  8562.     /* int tn_wait_sv; */
  8563.     int mynet;
  8564.     int _local = -1;
  8565.     int c, i, haveswitch = 0;
  8566.     int getval = 0;
  8567.     int wild = 0;            /* Filespec has wildcards */
  8568.     int cx = 0;                /* Connect after */
  8569.     int sx = 0;                /* Become server after */
  8570. #ifdef CK_ENCRYPTION
  8571.     int encrypt = 0;                    /* Encrypted? */
  8572.     int e_type = -1;                    /* Telnet /ENCRYPT type */
  8573. #endif /* CK_ENCRYPTION */
  8574. #ifdef CK_AUTHENTICATION
  8575.     int a_type = -1;            /* Authentication type */
  8576. #endif /* CK_AUTHENTICATION */
  8577. #ifdef OS2ORVMS
  8578.     int shr = 0;            /* Share serial device */
  8579. #endif /* OS2ORVMS */
  8580.     int confirmed = 0;            /* Command has been entered */
  8581.     struct FDB sw, tx, nx;
  8582. #ifdef OS2
  8583.     struct FDB fl;
  8584. #endif /* OS2 */
  8585.  
  8586.     char * ss;
  8587. #ifdef TCPSOCKET
  8588.     int rawflg = 0;
  8589. #endif /* TCPSOCKET */
  8590.  
  8591. #ifdef OS2
  8592. #define SRVBUFSIZ PIPENAML
  8593. #else /* OS2 */
  8594. #define SRVBUFSIZ 63
  8595. #endif /* OS2 */
  8596.  
  8597.     char srvbuf[SRVBUFSIZ+1];
  8598.     char hostname[HOSTNAMLEN];
  8599.  
  8600. #ifdef OS2
  8601. #ifdef NT
  8602.     int xxtapi = 0;
  8603. #else
  8604.     int xxslip = 0, xxppp = 0;
  8605. #endif /* NT */
  8606. #endif /* OS2 */
  8607.  
  8608.     int dossh = 0;
  8609.  
  8610.     debug(F101,"setlin fc","",fc);
  8611.     debug(F101,"setlin zz","",zz);
  8612.     debug(F101,"setlin xx","",xx);
  8613.  
  8614. #ifdef SSHCMD
  8615.     if (xx == XXSSH) {            /* SSH becomes PTY SSH ... */
  8616.     dossh = 1;
  8617.     xx = XYHOST;
  8618.     }
  8619. #endif /* SSHCMD */
  8620.  
  8621. #ifdef TNCODE
  8622.     /* tn_wait_sv = tn_wait_flg; */
  8623.     wait = tn_wait_flg;
  8624. #else
  8625.     /* tn_wait_sv = 0; */
  8626.     wait = 0;
  8627. #endif /* TNCODE */
  8628.  
  8629.     mynet = nettype;
  8630.  
  8631.     if (nolocal) {
  8632.     makestr(&slmsg,"Making connections is disabled");
  8633.     printf("?Sorry, making connections is disabled\n");
  8634.     return(-9);
  8635.     }
  8636.     if (netsave > -1)
  8637.       nettype = netsave;
  8638.  
  8639.     if (fc != 0 || zz == 0)        /* Preset /CONNECT switch */
  8640.       cx = 1;
  8641.  
  8642.     debug(F101,"setlin cx","",cx);
  8643.  
  8644.     *srvbuf = NUL;
  8645.  
  8646.     line[0] = NUL;
  8647.     s = line;
  8648.  
  8649. #ifdef NETCONN
  8650. #ifndef NOSPL
  8651. #ifdef CK_SRP
  8652.     if (tmpstring)
  8653.         makestr(&tmpstring,NULL);
  8654. #endif /* CK_SRP */
  8655. #ifdef RLOGCODE
  8656.     if (tmpusrid)
  8657.         makestr(&tmpusrid,NULL);
  8658. #endif /* RLOGCODE */
  8659. #endif /* NOSPL */
  8660. #endif /* NETCONN */
  8661.  
  8662.     autoflow = 1;            /* Enable automatic flow setting */
  8663.  
  8664.     if (xx == XYHOST) {            /* SET HOST <hostname> */
  8665. #ifndef NETCONN
  8666.     makestr(&slmsg,"Network connections not supported");
  8667.         printf("?%s\n",slmsg);
  8668.     return(-9);
  8669. #else /* NETCONN */
  8670. #ifndef NOPUSH
  8671.     if ((mynet == NET_CMD || mynet == NET_PTY) && nopush) {
  8672.         makestr(&slmsg,"Access to external commands is disabled");
  8673.         printf("?Sorry, access to external commands is disabled\n");
  8674.         return(-9);
  8675.     }
  8676. #endif /* NOPUSH */
  8677.  
  8678. #ifdef SSHCMD
  8679.     if (dossh) {            /* SSH connection via pty */
  8680. #ifdef SSHBUILTIN
  8681.             makestr(&slmsg,"Not yet implemented");
  8682.             printf("?Not yet implemented\n");
  8683.             return(-9);
  8684. #else   /* SSHBUILTIN */
  8685.         int k;
  8686.         k = ckstrncpy(line, sshcmd ? sshcmd : defsshcmd, LINBUFSIZ);
  8687.         debug(F111,"sshcmd 1",line,k);
  8688.         if ((x = cmtxt("Optional switches and hostname","",&s,xxstring))<0)
  8689.           return(x);
  8690.         if (!*s) {
  8691.         printf("?SSH to where?\n");
  8692.         return(-9);
  8693.         }
  8694.         if (k < LINBUFSIZ) {
  8695.         line[k++] = SP;
  8696.         line[k] = NUL;
  8697.         debug(F111,"sshcmd 2",line,k);
  8698.         } if (k < LINBUFSIZ) {
  8699.         ckstrncpy(&line[k],s,LINBUFSIZ-k);
  8700.         debug(F111,"sshcmd 3",line,k);
  8701.         } else {
  8702.         printf("?Too long\n");
  8703.         return(-9);
  8704.         }
  8705.         mdmtyp = 0 - NET_PTY;
  8706.         x = 1;
  8707.         errno = 0;
  8708.             k = ttopen(line, &x, mdmtyp, 0); /* Open the connection */
  8709.         debug(F111,"sshcmd ttopen",line,k);
  8710.         if (k < 0) {
  8711.         if (errno)
  8712.           printf("?%s\n",ck_errstr());
  8713.         else
  8714.           printf("?Sorry, pseudoterminal open failed\n");
  8715.         return(success = 0);
  8716.         }
  8717.         ckstrncpy(ttname,line,TTNAMLEN); /* Record the command */
  8718.         debug(F110,"ssh ttname",ttname,0);
  8719.         cxtype = CXT_PIPE;        /* Connection type = pipe */
  8720.         makestr(&slmsg,NULL);    /* No SET LINE error message */
  8721. #ifndef NODIAL
  8722.         dialsta = DIA_UNK;
  8723. #endif /* NODIAL */
  8724.         success = 1;        /* SET LINE succeeded */
  8725.         network = 1;        /* Network connection (not serial) */
  8726.         local = 1;            /* Local mode (not remote) */
  8727.         cx = 1;            /* Enter CONNECT mode automatically */
  8728.         goto xsetlin;        /* Go take common exit */
  8729. #endif /* SSHBUILTIN */
  8730.     }
  8731. #endif /* SSHCMD */
  8732.  
  8733. /*
  8734.   Here we parse optional switches and then the hostname or whatever,
  8735.   which depends on the network type.  The tricky part is, the network type
  8736.   can be set by a switch.
  8737. */
  8738. #ifndef NOSPL
  8739.     makestr(&g_pswd,pwbuf);        /* Save global pwbuf */
  8740.     g_pflg = pwflg;            /* and flag */
  8741.     g_pcpt = pwcrypt;
  8742. #endif /* NOSPL */
  8743.  
  8744.     confirmed = 0;
  8745.     haveswitch = 0;
  8746. #ifdef NETFILE
  8747.     if (mynet != NET_FILE) {
  8748. #endif /* NETFILE */
  8749.         ss = (mynet == NET_CMD || mynet == NET_PTY) ?
  8750.           "Command, or switch" :
  8751.         (mynet == NET_TCPA || mynet == NET_TCPB) ?
  8752.           "Hostname, ip-address, or switch" :
  8753.             "Host or switch";
  8754.         if (fc) {
  8755.                 if (ttnproto == NP_TELNET || ttnproto == NP_KERMIT) {
  8756.                     if (nshteltab) {
  8757.             haveswitch++;
  8758.             cmfdbi(&sw,_CMKEY,ss,"","",nshteltab,4,xxstring,
  8759.                  shteltab,&nx);
  8760.             }
  8761.                 }
  8762. #ifdef RLOGCODE
  8763.                 else if (ttnproto == NP_RLOGIN) {
  8764.                     if (nshrlgtab) {
  8765.             haveswitch++;
  8766.             cmfdbi(&sw,_CMKEY,ss,"","",nshrlgtab,4,xxstring,
  8767.                    shrlgtab,&nx);
  8768.             }
  8769.                 }
  8770. #endif /* RLOGCODE */
  8771.         } else {
  8772.         haveswitch++;
  8773.         cmfdbi(&sw,_CMKEY,ss,"","",nshtab,4,xxstring,shtab,&nx);
  8774.         }
  8775. #ifdef NETFILE
  8776.     }
  8777. #endif /* NETFILE */
  8778.     if (mynet == NET_TCPB || mynet == NET_SLAT) {
  8779.         cmfdbi(&nx,_CMFLD,"Host","","",0,0,xxstring,NULL,NULL);
  8780. #ifdef NETFILE
  8781.     } else if (mynet == NET_FILE) {
  8782.         cmfdbi(&nx,_CMIFI,"Filename","","",0,0,xxstring,NULL,NULL);
  8783. #endif /* NETFILE */
  8784. #ifdef PTYORPIPE
  8785.     } else if (mynet == NET_CMD || mynet == NET_PTY) {
  8786.         cmfdbi(&nx,_CMTXT,"Command","","",0,0,xxstring,NULL,NULL);
  8787. #endif /* PTYORPIPE */
  8788.     } else {
  8789.         cmfdbi(&nx,_CMTXT,"Host","","",0,0,xxstring,NULL,NULL);
  8790.     }
  8791.     while (1) {
  8792.         x = cmfdb(haveswitch ? &sw : &nx);
  8793.         debug(F101,"setlin cmfdb","",x);
  8794.         if (x < 0)
  8795.           if (x != -3)
  8796.         return(x);
  8797.         if (x == -3) {
  8798.         if ((x = cmcfm()) < 0) {
  8799.             return(x);
  8800.         } else {
  8801.             confirmed = 1;
  8802.             break;
  8803.         }
  8804.         }
  8805.         if (cmresult.fcode != _CMKEY) {    /* Not a switch */
  8806.         ckstrncpy(line,cmresult.sresult,LINBUFSIZ); /* Save the data */
  8807.         s = line;               /* that was parsed... */
  8808.         if (cmresult.fcode == _CMIFI) {
  8809.             wild = cmresult.nresult;
  8810.         } else if (cmresult.fcode == _CMTXT) {
  8811.             confirmed = 1;
  8812.         }
  8813.         break;            /* and break out of this loop */
  8814.         }
  8815.         c = cmgbrk();        /* Have switch - get break character */
  8816.         getval = (c == ':' || c == '='); /* Must parse an agument? */
  8817.         if (getval && !(cmresult.kflags & CM_ARG)) {
  8818.         printf("?This switch does not take arguments\n");
  8819.         return(-9);
  8820.         }
  8821.         if (!getval && (cmgkwflgs() & CM_ARG)) {
  8822.         printf("?This switch requires an argument\n");
  8823.         return(-9);
  8824.         }
  8825.         switch (cmresult.nresult) { /* It's a switch.. */
  8826.           case SL_CNX:        /* /CONNECT */
  8827.         cx = 1;
  8828.         sx = 0;
  8829.         break;
  8830.           case SL_SRV:        /* /SERVER */
  8831.         cx = 0;
  8832.         sx = 1;
  8833.         break;
  8834. #ifdef NETCMD
  8835.           case SL_CMD:        /* /COMMAND */
  8836.         netsave = mynet;
  8837.         mynet = NET_CMD;
  8838.         break;
  8839. #endif /* NETCMD */
  8840. #ifdef NETPTY
  8841.           case SL_PTY:        /* /PTY */
  8842.         netsave = mynet;
  8843.         mynet = NET_PTY;
  8844.         break;
  8845. #endif /* NETPTY */
  8846.           case SL_NET:        /* /NETWORK-TYPE */
  8847.         if ((x = cmkey(netcmd,nnets,"","",xxstring)) < 0)
  8848.           return(x);
  8849.         mynet = x;
  8850.         break;
  8851. #ifndef NOSPL
  8852.           case SL_PSW:        /* /PASSWORD: */
  8853.         if (!getval)
  8854.           break;
  8855.         debok = 0;
  8856.                 if ((x = cmfld("Password","",&s,xxstring)) < 0) {
  8857.                     if (x == -3) {
  8858.                         makestr(&tmpstring,"");
  8859.                     } else {
  8860.                         return(x);
  8861.                     }
  8862.                 } else {
  8863.                     s = brstrip(s);
  8864.                     if ((x = (int)strlen(s)) > PWBUFL) {
  8865.             makestr(&slmsg,"Internal error");
  8866.                         printf("?Sorry, too long - max = %d\n",PWBUFL);
  8867.                         return(-9);
  8868.                     }
  8869.                     makestr(&tmpstring,s);
  8870.                 }
  8871.         break;
  8872. #endif /* NOSPL */
  8873.           case SL_UID:        /* /USERID: */
  8874.         if (!getval)
  8875.           break;
  8876.                 if ((x = cmfld("Userid","",&s,xxstring)) < 0) {
  8877.                     if (x == -3) {
  8878.                         makestr(&tmpusrid,"");
  8879.                     } else {
  8880.                         return(x);
  8881.                     }
  8882.                 } else {
  8883.                     s = brstrip(s);
  8884.                     if ((x = (int)strlen(s)) > 63) {
  8885.             makestr(&slmsg,"Internal error");
  8886.                         printf("?Sorry, too long - max = %d\n",63);
  8887.                         return(-9);
  8888.                     }
  8889.                     makestr(&tmpusrid,s);
  8890.                 }
  8891.         break;
  8892. #ifdef CK_AUTHENTICATION
  8893. #ifdef CK_SRP
  8894.               case SL_SRP:
  8895.                 a_type = AUTHTYPE_SRP;
  8896.                 break;
  8897. #endif /* CK_SRP */
  8898. #ifdef CK_SSL
  8899.               case SL_SSL:
  8900.                 a_type = AUTHTYPE_SSL;
  8901.                 break;
  8902. #endif /* CK_SSL */
  8903. #ifdef NT
  8904.               case SL_NTLM:
  8905.                 a_type = AUTHTYPE_NTLM;
  8906.                 break;
  8907. #endif /* NT */
  8908. #ifdef CK_KERBEROS
  8909.               case SL_KRB4:
  8910.                 a_type = AUTHTYPE_KERBEROS_V4;
  8911.                 if (ttnproto == NP_RLOGIN)
  8912.           ttnproto =
  8913. #ifdef CK_ENCRYPTION
  8914.             encrypt ? NP_EK4LOGIN :
  8915. #endif /* CK_ENCRYPTION */
  8916.               NP_K4LOGIN;
  8917.                 else if (ttnproto == NP_K5LOGIN)
  8918.           ttnproto = NP_K4LOGIN;
  8919. #ifdef CK_ENCRYPTION
  8920.                 else if (ttnproto == NP_EK5LOGIN)
  8921.           ttnproto = NP_EK4LOGIN;
  8922. #endif /* CK_ENCRYPTION */
  8923.                 break;
  8924.           case SL_KRB5:
  8925.                 a_type = AUTHTYPE_KERBEROS_V5;
  8926.                 if (ttnproto == NP_RLOGIN)
  8927.           ttnproto =
  8928. #ifdef CK_ENCRYPTION
  8929.             encrypt ? NP_EK5LOGIN :
  8930. #endif /* CK_ENCRYPTION */
  8931.               NP_K5LOGIN;
  8932.         else if (ttnproto == NP_K4LOGIN)
  8933.           ttnproto = NP_K5LOGIN;
  8934. #ifdef CK_ENCRYPTION
  8935.         else if (ttnproto == NP_EK4LOGIN)
  8936.           ttnproto = NP_EK5LOGIN;
  8937. #endif /* CK_ENCRYPTION */
  8938.         break;
  8939. #endif /* CK_KERBEROS */
  8940.           case SL_AUTH: {
  8941.           extern struct keytab autyptab[];
  8942.           extern int nautyp;
  8943.           if ((x = cmkey(autyptab,nautyp,"type of authentication",
  8944.                  "automatic",xxstring)) < 0)
  8945.                     return(x);
  8946.           a_type = x;
  8947.           break;
  8948.           }
  8949. #endif /* CK_AUTHENTICATION */
  8950. #ifdef CK_ENCRYPTION
  8951.               case SL_ENC:
  8952.         switch (ttnproto) {
  8953.           case NP_K4LOGIN:
  8954.                     ttnproto = NP_EK4LOGIN;
  8955.                     encrypt = 1;
  8956.                     break;
  8957.           case NP_K5LOGIN:
  8958.                     ttnproto = NP_EK5LOGIN;
  8959.                     encrypt = 1;
  8960.                     break;
  8961.                   case NP_KERMIT:
  8962.           case NP_TELNET: {
  8963.               static struct keytab * tnetbl = NULL;
  8964.               static int ntnetbl = 0;
  8965.               x = ck_get_crypt_table(&tnetbl,&ntnetbl);
  8966.               debug(F101,"ck_get_crypt_table x","",x);
  8967.               debug(F101,"ck_get_crypt_table n","",ntnetbl);
  8968.               if (x < 1 || !tnetbl || ntnetbl < 1) /* Didn't get it */
  8969.                         x = 0;
  8970.               if (!x) {
  8971.               makestr(&slmsg,"Internal error");
  8972.               printf("?Oops, types not loaded\n");
  8973.               return(-9);
  8974.               }
  8975.               if ((x = cmkey(tnetbl,ntnetbl,"type of encryption",
  8976.                      "automatic",xxstring)) < 0)
  8977.                         return(x);
  8978.               e_type = x;
  8979.               break;
  8980.           }
  8981.         }
  8982.                 break;
  8983. #endif /* CK_ENCRYPTION */
  8984.           case SL_WAIT:
  8985.         wait = 1;
  8986.         break;
  8987.           case SL_NOWAIT:
  8988.         wait = 0;
  8989.         break;
  8990.         }
  8991.     }
  8992.  
  8993. #ifdef NETFILE
  8994.     if (mynet == NET_FILE)        /* Parsed by cmifi() */
  8995.       if ((x = cmcfm()) < 0)    /* Needs confirmation */
  8996.         return(x);
  8997. #endif /* NETFILE */
  8998.  
  8999. #ifdef NETCMD
  9000.     if (mynet == NET_CMD || mynet == NET_PTY) {
  9001.         char *p = NULL;
  9002.         if (!confirmed) {
  9003.         if ((x = cmtxt("Rest of command","",&s,xxstring)) < 0)
  9004.           return(x);
  9005.         if (*s) {
  9006.             strncat(line," ",LINBUFSIZ);
  9007.             strncat(line,s,LINBUFSIZ);
  9008.         }
  9009.         s = line;
  9010.         }
  9011.         s = brstrip(s);
  9012.         makestr(&p,s);        /* what's all this then? */
  9013.         ckstrncpy(line,p,LINBUFSIZ);
  9014.         makestr(&p,NULL);
  9015.         s = line;
  9016.     }
  9017.     debug(F110,"SUNDAY 2",line,0);
  9018. #endif /* NETCMD */
  9019.  
  9020. #ifdef NPIPE                /* Named pipe */
  9021.     if (mynet == NET_PIPE) {    /* Needs backslash twiddling */
  9022.         if (*s) {
  9023.         if (strcmp(s,"*")) {    /* If remote, begin with */
  9024.             ckstrncpy(line,"\\\\",LINBUFSIZ); /* server name */
  9025.             ckstrncat(line,s,LINBUFSIZ);
  9026.         } else {
  9027.             line[0]='\0';
  9028.         }
  9029.         ckstrncat(line,"\\pipe\\", LINBUFSIZ); /* Make pipe name */
  9030.         ckstrncat(line,pipename, LINBUFSIZ); /* Add name of pipe */
  9031.         s = line;
  9032.         }
  9033.     }
  9034. #endif /* NPIPE */
  9035.  
  9036. #ifdef SUPERLAT
  9037.     if (mynet == NET_SLAT) {    /* Needs password, etc. */
  9038.         slat_pwd[0] = NUL;        /* Erase any previous password */
  9039.         debok = 0;
  9040.         if (*s) {            /* If they gave a host name... */
  9041.         if ((x = cmfld(
  9042.              "password,\n or carriage return if no password required",
  9043.                    "",
  9044.                    &s,
  9045.                    xxstring
  9046.                    )) < 0 && x != -3)
  9047.           return(x);
  9048.         ckstrncpy(slat_pwd,s,18); /* Set the password, if any */
  9049.         }
  9050.         if ((x = cmcfm()) < 0) return(x); /* Confirm the command */
  9051.         s = line;
  9052.     }
  9053. #endif /* SUPERLAT */
  9054.  
  9055. #ifdef TCPSOCKET
  9056.     if (mynet == NET_TCPB) {    /* TCP/IP connection */
  9057.         debug(F110,"setlin service 0",srvbuf,0);
  9058.         debug(F110,"setlin host s 2",s,0);
  9059.         if (*s) {        /* If they gave a host name... */
  9060.         debug(F110,"setlin host s 1",s,0);
  9061. #ifdef NOLISTEN
  9062.         if (mynet == NET_TCPB && *s == '*') {
  9063.             makestr(&slmsg,"Incoming connections not supported");
  9064.             printf(
  9065.      "?Sorry, incoming connections not supported in this version of Kermit.\n"
  9066.                );
  9067.             return(-9);
  9068.         }
  9069. #endif /* NOLISTEN */
  9070. #ifdef RLOGCODE
  9071.         /* Allow a username if rlogin is requested */
  9072.         if (ttnproto == NP_RLOGIN
  9073. #ifdef CK_AUTHENTICATION
  9074. #ifdef CK_KERBEROS
  9075.             || ttnproto == NP_K4LOGIN || ttnproto == NP_EK4LOGIN
  9076.             || ttnproto == NP_K5LOGIN || ttnproto == NP_EK5LOGIN
  9077. #endif /* CK_KERBEROS */
  9078. #endif /* CK_AUTHENTICATION */
  9079.              ) {
  9080.             int y;
  9081.             uidflag = 0;
  9082.             /* Check for "host:service" */
  9083.             for ( ; (*s != '\0') && (*s != ':'); s++) ;
  9084.             if (*s) {    /* Service, save it */
  9085.             *s = NUL;
  9086.             ckstrncpy(srvbuf,++s,SRVBUFSIZ);
  9087.             } else {        /* No :service, then use default. */
  9088. #ifdef VMS
  9089.             switch (ttnproto) {
  9090.               case NP_RLOGIN:
  9091.                 ckstrncpy(srvbuf,"513",SRVBUFSIZ); /* "login" */
  9092.                 break;
  9093.                           case NP_K4LOGIN:
  9094.               case NP_K5LOGIN:
  9095.                 ckstrncpy(srvbuf,"543",SRVBUFSIZ); /* "klogin" */
  9096.                 break;
  9097.                           case NP_EK4LOGIN:
  9098.               case NP_EK5LOGIN:
  9099.                 ckstrncpy(srvbuf,"2105",SRVBUFSIZ); /* "eklogin" */
  9100.                 break;
  9101.             }
  9102. #else /* VMS */
  9103.             switch (ttnproto) {
  9104.               case NP_RLOGIN:
  9105.                 ckstrncpy(srvbuf,"login",SRVBUFSIZ);
  9106.                 break;
  9107.                           case NP_K4LOGIN:
  9108.                           case NP_K5LOGIN:
  9109.                 ckstrncpy(srvbuf,"klogin",SRVBUFSIZ);
  9110.                 break;
  9111.                           case NP_EK4LOGIN:
  9112.                           case NP_EK5LOGIN:
  9113.                 ckstrncpy(srvbuf,"eklogin",SRVBUFSIZ);
  9114.                 break;
  9115.             }
  9116. #endif /* VMS */
  9117.             }
  9118.             if (!confirmed) {
  9119.             y = cmfld("Userid on remote system",
  9120.                   uidbuf,&s,xxstring);
  9121.             if (y < 0 && y != -3)
  9122.               return(y);
  9123.             if ((int)strlen(s) > 63) {
  9124.                 makestr(&slmsg,"Internal error");
  9125.                 printf("Sorry, too long\n");
  9126.                 return(-9);
  9127.             }
  9128.                         makestr(&tmpusrid,s);
  9129.             }
  9130.         } else {    /* TELNET or SET HOST */
  9131. #endif /* RLOGCODE */
  9132.             /* s = line; */
  9133.             /* Check for "host:service" */
  9134.             for ( ; (*s != '\0') && (*s != ':'); s++) ;
  9135.             if (*s) {    /* Service, save it */
  9136.             *s = NUL;
  9137.             ckstrncpy(srvbuf,++s,SRVBUFSIZ);
  9138.             } else if (!confirmed) {
  9139.             /* No :service, let them type one. */
  9140.             if (*line != '*') { /* Not incoming */
  9141.                 if (ttnproto == NP_KERMIT) {
  9142.                 if ((x = cmfld(
  9143.                            "TCP service name or number",
  9144.                            "kermit",&s,xxstring)
  9145.                      ) < 0 && x != -3)
  9146.                   return(x);
  9147. #ifdef RLOGCODE
  9148.                 } else if (ttnproto == NP_RLOGIN) {
  9149.                 if ((x = cmfld(
  9150.   "TCP service name or number,\n or carriage return for rlogin (513)",
  9151.                            "login",&s,xxstring)
  9152.                      ) < 0 && x != -3)
  9153.                   return(x);
  9154. #ifdef CK_AUTHENTICATION
  9155. #ifdef CK_KERBEROS
  9156.                 } else if (ttnproto == NP_K4LOGIN ||
  9157.                        ttnproto == NP_K5LOGIN) {
  9158.                 if ((x = cmfld(
  9159.   "TCP service name or number,\n or carriage return for klogin (543)",
  9160.                            "klogin",&s,xxstring)
  9161.                      ) < 0 && x != -3)
  9162.                   return(x);
  9163.                 } else if (ttnproto == NP_EK4LOGIN ||
  9164.                        ttnproto == NP_EK5LOGIN) {
  9165.                 if ((x = cmfld(
  9166.   "TCP service name or number,\n or carriage return for eklogin (2105)",
  9167.                            "eklogin",&s,xxstring)
  9168.                      ) < 0 && x != -3)
  9169.                   return(x);
  9170. #endif /* CK_KERBEROS */
  9171. #endif /* CK_AUTHENTICATION */
  9172. #endif /* RLOGCODE */
  9173.                 } else {
  9174.                                 /* Do not set a default value in this call */
  9175.                                 /* If you do then it will prevent entries  */
  9176.                                 /* in the network directory from accessing */
  9177.                                 /* alternate ports.                        */
  9178.  
  9179.                 if ((x = cmfld(
  9180.                            "TCP service name or number",
  9181.                            "",&s,xxstring)
  9182.                      ) < 0 && x != -3)
  9183.                   return(x);
  9184.                 }
  9185.             } else { /* Incoming connection */
  9186.                 if ((x = cmfld("TCP service name or number",
  9187.                        "",&s,xxstring)
  9188.                  ) < 0 && x != -3)
  9189.                   return(x);
  9190.             }
  9191.             if (*s)        /* If they gave a service, */
  9192.               ckstrncpy(srvbuf,s,SRVBUFSIZ); /* copy it */
  9193.                         debug(F110,"setlin service 0.5",srvbuf,0);
  9194.             }
  9195. #ifdef RLOGCODE
  9196.         }
  9197. #endif /* RLOGCODE */
  9198.         if (!confirmed) {
  9199.                     char * defproto;
  9200.                     switch (ttnproto) {
  9201.               case NP_RLOGIN:
  9202.                         defproto = "/rlogin";
  9203.                         break;
  9204.                 case NP_K4LOGIN:
  9205.                 defproto = "/k4login";
  9206.                 break;
  9207.                       case NP_K5LOGIN:
  9208.                         defproto = "/k5login";
  9209.                         break;
  9210.                       case NP_EK4LOGIN:
  9211.                         defproto = "/ek4login";
  9212.                         break;
  9213.                       case NP_EK5LOGIN:
  9214.                 defproto = "/ek5login";
  9215.                 break;
  9216.               case NP_KERMIT:
  9217.               case NP_TELNET:
  9218.                         defproto = "/telnet";
  9219.                         break;
  9220.               default:
  9221.                         defproto = "/default";
  9222.                     }
  9223.             if ((x = cmkey(tcprawtab,ntcpraw,"Switch",defproto,
  9224.                    xxstring)) < 0) {
  9225.             if (x != -3)
  9226.               return(x);
  9227.             else if ((x = cmcfm()) < 0)
  9228.               return(x);
  9229.             } else {
  9230.             rawflg = x;
  9231.             if ((x = cmcfm()) < 0)
  9232.               return(x);
  9233.             switch (rawflg) {
  9234. #ifdef COMMENT
  9235.                         /* This is wrong.  Needs to be separate from TELNET */
  9236. #ifdef SSHBUILTIN
  9237.               case NP_SSH: {
  9238.                   char c;
  9239.                   c = cmgbrk();
  9240.                   if (c == ':' || c == '=') {
  9241.                   if ((x = cmfld("Command","",&s,NULL)) < 0)
  9242.                     return(x);
  9243.                   makestr(&sshrcmd,NULL);
  9244.                   makestr(&sshtmpcmd, *s ? s : NULL);
  9245.                   /* NOW... after command is confirmed, do: */
  9246.                   /* sshrcmd = sshtmpcmd; */
  9247.                   /* sshtmpcmd = NULL */
  9248.                   /* then use sshrcmd (if any) as command. */
  9249.                   }
  9250.               }
  9251. #endif /* SSHBUILTIN */
  9252. #endif /* COMMENT */
  9253.  
  9254. #ifdef CK_SSL
  9255.                           case NP_SSL:
  9256.                 ttnproto = rawflg;
  9257.                 ssl_only_flag = 1;
  9258.                 tls_only_flag = 0;
  9259.                 break;
  9260.  
  9261.                           case NP_TLS:
  9262.                 ttnproto = rawflg;
  9263.                 ssl_only_flag = 0;
  9264.                 tls_only_flag = 1;
  9265.                 break;
  9266.  
  9267.                           case NP_SSL_TELNET:
  9268.                             ttnproto = NP_TELNET;
  9269.                             ssl_only_flag = 1;
  9270.                             tls_only_flag = 0;
  9271.                             break;
  9272.  
  9273.                           case NP_TLS_TELNET:
  9274.                             ttnproto = NP_TELNET;
  9275.                             ssl_only_flag = 0;
  9276.                             tls_only_flag = 1;
  9277.                             break;
  9278. #endif /* CK_SSL */
  9279.                           case NP_NONE:
  9280.               case NP_TCPRAW:
  9281.                           case NP_RLOGIN:
  9282.                           case NP_K4LOGIN:
  9283.                           case NP_K5LOGIN:
  9284.                           case NP_EK4LOGIN:
  9285.                           case NP_EK5LOGIN:
  9286.               case NP_TELNET:
  9287.               case NP_KERMIT:
  9288.               default:
  9289.                 ttnproto = rawflg;
  9290. #ifdef CK_SSL
  9291.                 ssl_only_flag = 0;
  9292.                 tls_only_flag = 0;
  9293. #endif /* CK_SSL */
  9294.                 break;
  9295.             }
  9296.             }
  9297.         }
  9298.         }
  9299.         s = line;
  9300.     }
  9301. #endif /* TCPSOCKET */
  9302.  
  9303.     if (!*s) {
  9304.         if (!network) {
  9305.         makestr(&slmsg,"Hostname or address required");
  9306.         printf("?%s\n",slmsg);
  9307.         return(-9);
  9308.         } else if (!zz) { /* No hostname given */
  9309. #ifdef CKLOGDIAL
  9310. #ifdef NETCONN
  9311.         dolognet();
  9312. #endif /* NETCONN */
  9313. #endif /* CKLOGDIAL */
  9314.         if (cx) {
  9315.                   /* Command was confirmed so we can pre-pop command level. */
  9316.                   /* This is so CONNECT module won't think we're executing a */
  9317.                   /* script if CONNECT was the final command in the script. */
  9318.  
  9319.             if (cmdlvl > 0)
  9320.               prepop();
  9321. #ifndef NODIAL
  9322.             dialsta = DIA_UNK;
  9323. #endif /* NODIAL */
  9324.             success = doconect(0,cmdlvl == 0 ? 1 : 0);
  9325. #ifdef CKLOGDIAL
  9326.             if (ttchk() < 0)
  9327.               dologend();
  9328. #endif /* CKLOGDIAL */
  9329.             return(success);
  9330.         } else
  9331.           return(1);
  9332.         }
  9333.     }
  9334.  
  9335. #ifndef NODIAL
  9336.     /* Look up in network directory */
  9337.     x = 0;
  9338.     debug(F101,"setlin mynet 1","",mynet);
  9339.     debug(F111,"setlin nnetdir",s,nnetdir);
  9340.     if (*s == '=') {        /* If number starts with = sign */
  9341.         s++;            /* strip it */
  9342.         while (*s == SP) s++;    /* and any leading spaces */
  9343.         ckstrncpy(line,s,LINBUFSIZ); /* Do this again. */
  9344.         s = line;
  9345.         debug(F110,"setlin host s 3",s,0);
  9346.         nhcount = 0;
  9347.     } else if (*s) {        /* We want to look it up. */
  9348.         if (nnetdir > 0)        /* If there is a directory... */
  9349.           x = lunet(line);        /* (sets nhcount) */
  9350.         else            /* otherwise */
  9351.           nhcount = 0;        /* we didn't find any there */
  9352.         if (x < 0) {        /* Internal error? */
  9353.         makestr(&slmsg,"Network directory lookup error");
  9354.         printf("?Fatal network directory lookup error - %s\n",line);
  9355.         return(-9);
  9356.         }
  9357.         debug(F111,"setlin lunet nhcount",line,nhcount);
  9358.     }
  9359. #endif /* NODIAL */
  9360.  
  9361.     /* New connection wanted.  Make a copy of the host name/address... */
  9362.  
  9363.     ckstrncpy(tmpbuf,s,TMPBUFSIZ);    /* Because we are reusing line[] */
  9364.     s = tmpbuf;            /* for net directory entries...  */
  9365.     debug(F111,"setlin host s 5",s,mdmtyp);
  9366.     if (clskconnx(1) < 0)        /* Close current Kermit connection */
  9367.       return(success = 0);
  9368.     if (*s) {            /* They gave a hostname */
  9369.         _local = 1;            /* Network connection always local */
  9370.         if (mdmsav < 0)
  9371.           mdmsav = mdmtyp;        /* Remember old modem type */
  9372.         mdmtyp = -mynet;        /* Special code for network */
  9373.     } else {            /* They just said "set host" */
  9374.         s = dftty;            /* So go back to normal */
  9375.         _local = dfloc;        /* default tty, location, */
  9376.         if (zz) {
  9377.         setflow();        /* Maybe change flow control */
  9378.         haveline = 1;        /* (* is this right? *) */
  9379. #ifdef CKLOGDIAL
  9380.         dologend();
  9381. #endif /* CKLOGDIAL */
  9382. #ifndef NODIAL
  9383.         dialsta = DIA_UNK;
  9384. #endif /* NODIAL */
  9385.         return(success = 1);
  9386.         }
  9387.     }
  9388. #endif /* NETCONN */
  9389.     }
  9390.  
  9391. /* Serial tty device, possibly modem, connection... */
  9392.  
  9393.     if (xx == XYLINE            /* SET LINE or SET PORT */
  9394. #ifdef CK_TAPI
  9395.     || xx == XYTAPI_LIN        /* SET TAPI LINE */
  9396. #endif /* CK_TAPI */
  9397.     ) {
  9398. #ifdef OS2
  9399. /*
  9400.   User can type:
  9401.     COM1..COM8 = Regular COM port
  9402.     1..8       = Synonym for COM1..COM8, is translated to COM1..COM8
  9403.     _n         = (n is a number) = open file handle
  9404.     string     = any text string = name of some other kind of device,
  9405.                  taken literally, as given.
  9406. */
  9407.     s = "Communication device name";
  9408. #ifdef CK_TAPI
  9409.     if (TAPIAvail)
  9410.           cktapiBuildLineTable(&tapilinetab, &_tapilinetab, &ntapiline);
  9411.     if (!(tapilinetab && _tapilinetab && ntapiline > 0) &&
  9412.         xx == XYTAPI_LIN ) {
  9413.         makestr(&slmsg,"TAPI device not configured");
  9414.         printf("\nNo TAPI Line Devices are configured for this system\n");
  9415.         return(-9);
  9416.     }
  9417.     if (xx == XYTAPI_LIN) {        /* Default (first) TAPI line */
  9418.         s = "tapi";            /* (whatever it is) */
  9419.     } else {            /* Query the user */
  9420. #endif /* CK_TAPI */
  9421.  
  9422. /* Now parse optional switches and then device name */
  9423.  
  9424.         confirmed = 0;
  9425.         cmfdbi(&sw,_CMKEY,"Device name, or switch",
  9426.            "","",npsltab,4,xxstring,psltab,&fl);
  9427.         cmfdbi(&fl,_CMFLD,"",dftty,"",0,0,xxstring,NULL,NULL);
  9428.         while (1) {
  9429.         x = cmfdb(&sw);
  9430.         debug(F101,"setlin cmfdb","",x);
  9431.         if (x < 0)
  9432.           if (x != -3)
  9433.             return(x);
  9434.         if (x == -3) {
  9435.             if ((x = cmcfm()) < 0) {
  9436.             return(x);
  9437.             } else {
  9438.             confirmed = 1;
  9439.             break;
  9440.             }
  9441.         }
  9442.         if (cmresult.fcode == _CMFLD) {
  9443.             s = cmresult.sresult;
  9444.             break;
  9445.         } else if (cmresult.fcode == _CMKEY) {
  9446.             switch (cmresult.nresult) {
  9447.               case SL_CNX:    /* /CONNECT */
  9448.             cx = 1;
  9449.             sx = 0;
  9450.             break;
  9451.               case SL_SRV:    /* /SERVER */
  9452.             cx = 0;
  9453.             sx = 1;
  9454.             break;
  9455.                       case SL_SHR:      /* /SHARE */
  9456.                         shr = 1;
  9457.                         break;
  9458.                       case SL_NSH:    /* /NOSHARE */
  9459.                         shr = 0;
  9460.                         break;
  9461.             }
  9462.         }
  9463.         }
  9464. #ifdef CK_TAPI
  9465.     }
  9466. #endif /* CK_TAPI */
  9467.  
  9468.     debug(F110,"OS2 SET PORT s",s,0);
  9469.     y = lookup(os2devtab,s,nos2dev,&x); /* Look up in keyword table */
  9470.     debug(F101,"OS2 SET PORT x","",x);
  9471.     debug(F101,"OS2 SET PORT y","",y);
  9472.     if ((y > -1) && (x >= 0 && x < 8)) { /* User typed a digit 1..8 */
  9473.         s = os2devtab[x+8].kwd;    /* Substitite its real name */
  9474. #ifdef NT
  9475.         xxtapi = 0;
  9476. #else /* NT */
  9477.         xxslip = xxppp = 0;
  9478. #endif /* NT */
  9479.         debug(F110,"OS2 SET PORT subst s",s,"");
  9480. #ifndef NT
  9481.     } else if ((y >-1) && (x >= 16 && x < 24)) { /* SLIP access */
  9482.         s = os2devtab[x-8].kwd;    /* Substitite its real name */
  9483.         debug(F110,"OS2 SET PORT SLIP subst s",s,"");
  9484.         xxslip = 1;
  9485.         xxppp  = 0;
  9486.     } else if ((y >-1) && (x >= 24 && x < 32)) { /* PPP access */
  9487.         s = os2devtab[x-16].kwd;    /* Substitite its real name */
  9488.         debug(F110,"OS2 SET PORT PPP subst s",s,"");
  9489.         xxppp = 1;
  9490.         xxslip = 0;
  9491.         if ((y = cmkey(os2ppptab,
  9492.                nos2ppp,
  9493.                "PPP driver interface",
  9494.                "ppp0",
  9495.                xxstring)
  9496.          ) < 0)
  9497.         return(y);
  9498.         debug(F101,"OS2 SET PORT PPP INTERFACE y","",y);
  9499.         xxppp = (y % 10) + 1;
  9500. #endif /* NT */
  9501.     } else if (*s == '_') {        /* User used "_" prefix */
  9502.         s++;            /* Remove it */
  9503.         /* Rest must be numeric */
  9504.         debug(F110,"OS2 SET PORT HANDLE _subst s",s,0);
  9505.         if (!rdigits(s)) {
  9506.         makestr(&slmsg,"Invalid file handle");
  9507.         printf("?Invalid format for file handle\n");
  9508.         return(-9);
  9509.         }
  9510. #ifdef NT
  9511.         xxtapi = 0;
  9512. #else /* NT */
  9513.         xxslip = xxppp = 0;
  9514. #endif /* NT */
  9515.     } else {            /* A normal COMx port or a string */
  9516.         s = brstrip(s);        /* Strip braces if any */
  9517. #ifdef NT
  9518. #ifdef CK_TAPI
  9519.         /* Windows TAPI support - Look up in keyword table */
  9520.         if (tapilinetab && _tapilinetab && ntapiline > 0) {
  9521.         if (!ckstrcmp(s,"tapi",4,0)) {
  9522.  
  9523.             /* Find out what the lowest numbered TAPI device is */
  9524.             /* and use it as the default.                       */
  9525.             int j = 9999, k = -1;
  9526.             for (i = 0; i < ntapiline; i++) {
  9527.                 if (tapilinetab[i].kwval < j) {
  9528.                 j = tapilinetab[i].kwval;
  9529.                 k = i;
  9530.             }
  9531.             }
  9532.             if (k >= 0)
  9533.               s = _tapilinetab[k].kwd;
  9534.             else
  9535.               s = "";
  9536.  
  9537.             if ((y = cmkey(_tapilinetab,ntapiline,
  9538.                    "TAPI device name",s,xxstring)) < 0)
  9539.               return(y);
  9540.  
  9541.             xxtapi = 1;
  9542.  
  9543.             /* Get the non Underscored string */
  9544.             for (i = 0; i < ntapiline; i++ ) {
  9545.                 if (tapilinetab[i].kwval == y) {
  9546.                 s = tapilinetab[i].kwd;
  9547.                 break;
  9548.             }
  9549.             }
  9550.         } else
  9551.           xxtapi = 0;
  9552.         }
  9553. #endif /* CK_TAPI */
  9554. #else /* NT */
  9555.         /* not OS/2 SLIP or PPP */
  9556.         xxslip = xxppp = 0;
  9557. #endif /* NT */
  9558.         }
  9559.     ckstrncpy(tmpbuf,s,TMPBUFSIZ);    /* Copy to a safe place */
  9560.     s = tmpbuf;
  9561.     if ((x = cmcfm()) < 0)
  9562.       return(x);
  9563.  
  9564. #else /* !OS2 */
  9565.  
  9566.     cmfdbi(&sw,_CMKEY,"Device name, or switch",
  9567.            "","",npsltab,4,xxstring,psltab,&tx);
  9568.     cmfdbi(&tx,_CMTXT,"",dftty,"",0,0,xxstring,NULL,NULL);
  9569.     while (!confirmed) {
  9570.         x = cmfdb(&sw);
  9571.         debug(F101,"setlin cmfdb","",x);
  9572.         if (x < 0)
  9573.           if (x != -3)
  9574.         return(x);
  9575.         if (x == -3) {
  9576.         if ((x = cmcfm()) < 0) {
  9577.             return(x);
  9578.         } else {
  9579.             confirmed = 1;
  9580.             break;
  9581.         }
  9582.         }
  9583.         switch (cmresult.fcode) {
  9584.           case _CMTXT:
  9585.         ckstrncpy(tmpbuf,cmresult.sresult,TMPBUFSIZ);
  9586.         s = tmpbuf;
  9587.         debug(F110,"setlin CMTXT",tmpbuf,0);
  9588.         confirmed = 1;
  9589.         break;
  9590.           case _CMKEY:        /* Switch */
  9591.         debug(F101,"setlin CMKEY",tmpbuf,cmresult.nresult);
  9592.         switch (cmresult.nresult) {
  9593.           case SL_CNX:        /* /CONNECT */
  9594.             cx = 1;
  9595.             sx = 0;
  9596.             break;
  9597.           case SL_SRV:        /* /SERVER */
  9598.             cx = 0;
  9599.             sx = 1;
  9600.             break;
  9601. #ifdef VMS
  9602.           case SL_SHR:        /* /SHARE */
  9603.             shr = 1;
  9604.             break;
  9605.           case SL_NSH:        /* /NOSHARE */
  9606.             shr = 0;
  9607.             break;
  9608. #endif /* VMS */
  9609.         }
  9610.         continue;
  9611.           default:
  9612.         debug(F101,"setlin bad cmfdb result","",cmresult.fcode);
  9613.         makestr(&slmsg,"Internal error");
  9614.         printf("?Internal parsing error\n");
  9615.         return(-9);
  9616.         }
  9617.     }
  9618. #endif /* OS2 */
  9619.     if (!confirmed)
  9620.       if ((x = cmcfm()) < 0)
  9621.         return(x);
  9622. #ifndef NODIAL
  9623.     dialsta = DIA_UNK;
  9624. #endif /* NODIAL */
  9625.     debug(F101,"setlin confirmed mdmtyp","",mdmtyp);
  9626.     if (clskconnx(1) < 0)        /* Close the Kermit connection */
  9627.       return(success = 0);
  9628.     if (*s) {            /* They gave a device name */
  9629.         _local = -1;        /* Let ttopen decide about it */
  9630.     } else {            /* They just said "set line" */
  9631.         s = dftty;            /* so go back to normal tty */
  9632.         _local = dfloc;        /* and mode. */
  9633.     }
  9634. #ifdef VMS
  9635.     {
  9636.         extern int ok_to_share;
  9637.         ok_to_share = shr;
  9638.     }
  9639. #endif /* VMS */
  9640.  
  9641. #ifdef OS2                /* Must wait until after ttclos() */
  9642. #ifdef NT                /* to change these settings       */
  9643. #ifdef CK_TAPI
  9644.     tttapi = xxtapi;
  9645. #endif /* CK_TAPI */
  9646. #else
  9647.     ttslip = xxslip;
  9648.     ttppp  = xxppp;
  9649. #endif /* NT */
  9650.         ttshare = shr;                  /* shareable device ? */
  9651.     debug(F110,"OS2 SET PORT final s",s,"");
  9652. #endif /* OS2 */
  9653.     }
  9654.     success = 0;
  9655.     if (mdmtyp > -1) {            /* Serial connections... */
  9656.     /* Open the new line */
  9657.     if ((y = ttopen(s,&_local,mdmtyp,cdtimo)) > -1) {
  9658.         cxtype = (mdmtyp > 0) ? CXT_MODEM : CXT_DIRECT;
  9659. #ifdef COMMENT
  9660.         flow = cxflow[cxtype];    /* Set connection type and flow */
  9661. #else
  9662.         setflow();            /* Only if autoflow()! */
  9663. #endif /* COMMENT */
  9664. #ifndef NODIAL
  9665.         dialsta = DIA_UNK;
  9666. #endif /* NODIAL */
  9667.         success = 1;
  9668. #ifdef CK_TAPI
  9669.         /* if the line is a tapi device, then we need to auto-execute */
  9670.         /* SET MODEM TYPE TAPI - which we do the equivalent of here.  */
  9671.         if (xxtapi) {
  9672.         extern int usermdm;
  9673.         usermdm = 0;
  9674.         initmdm(38);           /* From ckudia.c n_TAPI == 38 */
  9675.         }
  9676. #endif /* CK_TAPI */
  9677.  
  9678.     } else {
  9679. #ifdef OS2ONLY
  9680.         if (!strcmp(s,dftty))   /* Do not generate an error with dftty */
  9681.           ;
  9682.         else if (y == -6 && ttslip) {
  9683.         makestr(&slmsg,"Can't access SLIP driver");
  9684.         if (!quiet || xcmdsrc == 0)
  9685.           printf("?Unable to access SLIP driver.\n");
  9686.         } else if (y == -6 && ttppp) {
  9687.         if (!quiet || xcmdsrc == 0)
  9688.           makestr(&slmsg,"Can't access PPP driver");
  9689.         printf("?Unable to access PPP driver (wrong interface?)\n");
  9690.         } else
  9691. #endif /* OS2ONLY */
  9692.           if (y == -2) {
  9693.           makestr(&slmsg,"Timed out - no carrier");
  9694.           if (!quiet || xcmdsrc == 0) {
  9695.               printf("?Timed out, no carrier.\n");
  9696.               printf(
  9697.             "Try SET CARRIER OFF and SET LINE again, or else\n");
  9698.               printf("SET MODEM, SET LINE, and then DIAL.\n");
  9699.           }
  9700.           } else if (y == -3) {
  9701.           makestr(&slmsg,"Access to lock denied");
  9702.           if (!quiet || xcmdsrc == 0) {
  9703. #ifdef UNIX
  9704.               printf(
  9705. "Sorry, write access to UUCP lockfile directory denied.\n");
  9706. #ifndef NOHINTS
  9707.               if (hints) {
  9708.               printf("\n*************************\n");
  9709.               printf(
  9710. "HINT (Use SET HINTS OFF to suppress future hints):\n");
  9711.               printf(
  9712. "Please read the installation instructions file, %sckuins.txt,\n",
  9713.                  k_info_dir ? k_info_dir : ""
  9714.                  );
  9715.               printf(
  9716. "or the UNIX appendix of the manual, \"Using C-Kermit\".\n"
  9717.                  );
  9718.               printf("*************************\n\n");
  9719.               }
  9720. #endif /* NOHINTS */
  9721. #else
  9722.               printf("Sorry, access to lock denied: %s\n",s);
  9723. #endif /* UNIX */
  9724.           }
  9725.           } else if (y == -4) {
  9726.           makestr(&slmsg,"Access to device denied");
  9727.           if (!quiet || xcmdsrc == 0) {
  9728.               printf("Sorry, access to device denied: %s\n",s);
  9729. #ifdef UNIX
  9730. #ifndef NOHINTS
  9731.               if (hints) {
  9732.               printf("\n*************************\n");
  9733.               printf(
  9734. "HINT (Use SET HINTS OFF to suppress future hints):\n");
  9735.               printf(
  9736. "Please read the installation instructions file, %sckuins.txt,\n",
  9737.                  k_info_dir ? k_info_dir : ""
  9738.                  );
  9739.               printf(
  9740. "or the UNIX appendix of the manual, \"Using C-Kermit\".\n"
  9741.                  );
  9742.               printf("*************************\n\n");
  9743.               }
  9744. #endif /* NOHINTS */
  9745. #endif /* UNIX */
  9746.           }
  9747.           } else if (y == -5) {
  9748.           makestr(&slmsg,"Device is in use or unavailable");
  9749.           if (!quiet || xcmdsrc == 0)
  9750. #ifdef VMS
  9751.             printf(
  9752.            "Sorry, device is in use or otherwise unavailable: %s\n",s);
  9753. #else
  9754.             printf("Sorry, device is in use: %s\n",s);
  9755. #endif /* VMS */
  9756.           } else {            /* Other error. */
  9757.           makestr(&slmsg,"Device open failed");
  9758.           if (
  9759. #ifdef VMS
  9760.               1
  9761. #else
  9762.               errno
  9763. #endif /* VMS */
  9764.               ) {
  9765.               int x;        /* Find a safe, long buffer */
  9766.               makestr(&slmsg,ck_errstr());
  9767. #ifndef VMS
  9768.               debug(F111,"setlin serial errno",slmsg,errno);
  9769. #endif /* VMS */
  9770.               if (!quiet || xcmdsrc == 0)
  9771.             printf("Connection to %s failed: %s\n",s,slmsg);
  9772.           } else if (!quiet || xcmdsrc == 0)
  9773.             printf("Sorry, can't open connection: %s\n",s);
  9774.           }
  9775.     }
  9776.     }
  9777. #ifdef NETCONN
  9778.     else {                /* mdmtyp < 0: Network connection */
  9779.     char *p;
  9780.     int i, n;
  9781. #ifndef NODIAL
  9782.     debug(F101,"setlin mynet 3","",mynet);
  9783.     debug(F101,"setlin nhcount","",nhcount);
  9784.     if ((nhcount > 1) && !quiet && !backgrd) {
  9785.         int k;
  9786.         printf("%d entr%s found for \"%s\"%s\n",
  9787.            nhcount,
  9788.            (nhcount == 1) ? "y" : "ies",
  9789.            s,
  9790.            (nhcount > 0) ? ":" : "."
  9791.            );
  9792.         for (i = 0; i < nhcount; i++) {
  9793.             printf("%3d. %-12s => %-9s %s",
  9794.                i+1,n_name,nh_p2[i],nh_p[i]);
  9795.         for (k = 0; k < 4; k++) { /* Also list net-specific items */
  9796.             if (nh_px[k][i])      /* free format... */
  9797.               printf(" %s",nh_px[k][i]);
  9798.             else
  9799.               break;
  9800.         }
  9801.         printf("\n");
  9802.         }
  9803.     }
  9804.     if (nhcount == 0)
  9805.       n = 1;
  9806.     else
  9807.       n = nhcount;
  9808. #else
  9809.     n = 1;
  9810.     nhcount = 0;
  9811. #endif /* NODIAL */
  9812.     for (i = 0; i < n; i++) {    /* Loop for each entry found */
  9813.         debug(F101,"setlin loop i","",i);
  9814. #ifndef NODIAL
  9815.         if (nhcount > 0) {        /* If we found at least one entry... */
  9816.         ckstrncpy(line,nh_p[i],LINBUFSIZ); /* Copy current entry */
  9817.         if (lookup(netcmd,nh_p2[i],nnets,&x) > -1) { /* Net type */
  9818.             mynet = netcmd[x].kwval;
  9819.             mdmtyp  = 0 - mynet;
  9820.             debug(F101,"setlin mynet 4","",mynet);
  9821.         } else {
  9822.             makestr(&slmsg,"Network type not supported");
  9823.             printf("Error - network type \"%s\" not supported\n",
  9824.                nh_p2[i]
  9825.                );
  9826.             continue;
  9827.         }
  9828.  
  9829.         switch (mynet) {    /* Net-specific things */
  9830.  
  9831.           case NET_TCPB: {    /* TCP/IP */
  9832. #ifdef TCPSOCKET
  9833.               char *q;
  9834.               int flag = 0;
  9835.  
  9836.               /* Extract ":service", if any, from host string */
  9837.               debug(F110,"setlin service 1",line,0);
  9838.               for (q = line; (*q != '\0') && (*q != ':'); q++)
  9839.             ;
  9840.               if (*q == ':') { *q++ = NUL; flag = 1; }
  9841.               debug(F111,"setlin service 2",line,flag);
  9842.  
  9843.               /* Get service, if any, from directory entry */
  9844.  
  9845.               if (!*srvbuf) {
  9846.               if (nh_px[0][i]) {
  9847.                   ckstrncpy(srvbuf,nh_px[0][i],SRVBUFSIZ);
  9848.                   debug(F110,"setlin service 3",srvbuf,0);
  9849.               }
  9850.               if (flag) {
  9851.                   ckstrncpy(srvbuf,q,SRVBUFSIZ);
  9852.                   debug(F110,"setlin service 4",srvbuf,0);
  9853.               }
  9854.               }
  9855.  
  9856.                       /* Save the hostname */
  9857.                       ckstrncpy(hostname,line,HOSTNAMLEN);
  9858.  
  9859.               /* If we have a service, append to host name/address */
  9860.               if (*srvbuf) {
  9861.               ckstrncat(line, ":", LINBUFSIZ);
  9862.               ckstrncat(line, srvbuf, LINBUFSIZ);
  9863.               debug(F110,"setlin service 5",line,0);
  9864.               }
  9865. #ifdef RLOGCODE
  9866.               /* If no service given but command was RLOGIN */
  9867.               else if (ttnproto == NP_RLOGIN) {    /* add this... */
  9868.               ckstrncat(line, ":login",LINBUFSIZ);
  9869.               debug(F110,"setlin service 6",line,0);
  9870.               }
  9871. #ifdef CK_AUTHENTICATION
  9872. #ifdef CK_KERBEROS
  9873.               else if (ttnproto == NP_K4LOGIN ||
  9874.                    ttnproto == NP_K5LOGIN) { /* add this... */
  9875.               ckstrncat(line, ":klogin",LINBUFSIZ);
  9876.               debug(F110,"setlin service 7",line,0);
  9877.               }
  9878.               else if (ttnproto == NP_EK4LOGIN ||
  9879.                    ttnproto == NP_EK5LOGIN) { /* add this... */
  9880.               ckstrncat(line, ":eklogin",LINBUFSIZ);
  9881.               debug(F110,"setlin service 8",line,0);
  9882.               }
  9883. #endif /* CK_KERBEROS */
  9884. #endif /* CK_AUTHENTICATION */
  9885. #endif /* RLOGCODE */
  9886.               else {        /* Otherwise, add ":telnet". */
  9887.               ckstrncat(line, ":telnet", LINBUFSIZ);
  9888.               debug(F110,"setlin service 9",line,0);
  9889.               }
  9890.  
  9891.                       if (tmpusrid) {
  9892.                           ckstrncpy(uidbuf,tmpusrid,UIDBUFLEN);
  9893.                           makestr(&tmpusrid,NULL);
  9894.                           uidflag = 1;
  9895.                       }
  9896.  
  9897.               /* Fifth field, if any, is user ID (for rlogin) */
  9898.  
  9899.               if (nh_px[1][i] && !uidflag)
  9900.             ckstrncpy(uidbuf,tmpusrid,UIDBUFLEN);
  9901. #ifdef RLOGCODE
  9902.               if ((ttnproto == NP_RLOGIN
  9903. #ifdef CK_AUTHENTICATION
  9904. #ifdef CK_KERBEROS
  9905.                || ttnproto == NP_K4LOGIN || ttnproto == NP_EK4LOGIN
  9906.                || ttnproto == NP_K5LOGIN || ttnproto == NP_EK5LOGIN
  9907. #endif /* CK_KERBEROS */
  9908. #endif /* CK_AUTHENTICATION */
  9909.                ) && !uidbuf[0]) {
  9910.               makestr(&slmsg,"Username required");
  9911.               printf("Username required for rlogin\n");
  9912.               return(-9);
  9913.               }
  9914. #endif /* RLOGCODE */
  9915. #endif /* TCPSOCKET */
  9916.               break;
  9917.           }
  9918.  
  9919.  
  9920.           case NET_PIPE:
  9921. #ifdef NPIPE
  9922.             if (!pipename[0]) {    /* User didn't give a pipename */
  9923.             if (nh_px[0][i]) { /* But directory entry has one */
  9924.                 if (strcmp(pipename,"\\pipe\\")) {
  9925.                 ckstrncpy(pipename,"\\pipe\\",LINBUFSIZ);
  9926.                 ckstrncat(srvbuf,nh_px[0][i],PIPENAML-6);
  9927.                 } else {
  9928.                 ckstrncpy(pipename,nh_px[0][i],PIPENAML);
  9929.                 }
  9930.                 debug(F110,"setlin pipeneme",pipename,0);
  9931.             }
  9932.             }
  9933. #endif /* NPIPE */
  9934.             break;
  9935.  
  9936.           case NET_SLAT:
  9937. #ifdef SUPERLAT
  9938.             if (!slat_pwd[0]) {    /* User didn't give a password */
  9939.             if (nh_px[0][i]) { /* But directory entry has one */
  9940.                 ckstrncpy(slat_pwd,nh_px[0][i],18);
  9941.                 debug(F110,"setlin SuperLAT password",slat_pwd,0);
  9942.             }
  9943.             }
  9944. #endif /* SUPERLAT */
  9945.             break;
  9946.  
  9947.           case NET_SX25:    /* X.25 keyword parameters */
  9948.           case NET_IX25:
  9949.           case NET_VX25: {
  9950. #ifdef ANYX25
  9951.               int k;        /* Cycle through the four fields */
  9952.               for (k = 0; k < 4; k++) {
  9953.               if (!nh_px[k][i]) /* Bail out if none left */
  9954.                 break;
  9955.               if (!ckstrcmp(nh_px[k][i],"cug=",4,0)) {
  9956.                   closgr = atoi(nh_px[k][i]+4);
  9957.                   debug(F101,"X25 CUG","",closgr);
  9958.               } else if (!ckstrcmp(nh_px[k][i],"cud=",4,0)) {
  9959.                   cudata = 1;
  9960.                   ckstrncpy(udata,nh_px[k][i]+4,MAXCUDATA);
  9961.                   debug(F110,"X25 CUD",cudata,0);
  9962.               } else if (!ckstrcmp(nh_px[k][i],"rev=",4,0)) {
  9963.                   revcall = !ckstrcmp(nh_px[k][i]+4,"=on",3,0);
  9964.                   debug(F101,"X25 REV","",revcall);
  9965. #ifndef IBMX25
  9966.               } else if (!ckstrcmp(nh_px[k][i],"pad=",4,0)) {
  9967.                   int x3par, x3val;
  9968.                   char *s1, *s2;
  9969.                   s1 = s2 = nh_px[k][i]+4; /* PAD parameters */
  9970.                   while (*s2) {            /* Pick them apart */
  9971.                   if (*s2 == ':') {
  9972.                       *s2 = NUL;
  9973.                       x3par = atoi(s1);
  9974.                       s1 = ++s2;
  9975.                       continue;
  9976.                   } else if (*s2 == ',') {
  9977.                       *s2 = NUL;
  9978.                       x3val = atoi(s1);
  9979.                       s1 = ++s2;
  9980.                       debug(F111,"X25 PAD",x3par,x3val);
  9981.                       if (x3par > -1 &&
  9982.                       x3par <= MAXPADPARMS)
  9983.                     padparms[x3par] = x3val;
  9984.                       continue;
  9985.                   } else
  9986.                     s2++;
  9987.                   }
  9988. #endif /* IBMX25 */
  9989.               }
  9990.               }
  9991. #endif /* ANYX25 */
  9992.               break;
  9993.           }
  9994.  
  9995.           default:        /* Nothing special for other nets */
  9996.             break;
  9997.         }
  9998.         } else
  9999. #endif /* NODIAL */
  10000.         {                /* No directory entries found. */
  10001.         ckstrncpy(line,tmpbuf,LINBUFSIZ); /* Put this back... */
  10002.         if (mynet == NET_TCPB)    /* If the user gave a TCP service */
  10003.                   ckstrncpy(hostname,line,HOSTNAMLEN);
  10004.           if (*srvbuf) {    /* append it to host name/address */
  10005.               ckstrncat(line, ":", LINBUFSIZ);
  10006.               ckstrncat(line, srvbuf,LINBUFSIZ);
  10007.           }
  10008.         }
  10009.         /*
  10010.            Get here with host name/address and all net-specific
  10011.            parameters set, ready to open the connection.
  10012.         */
  10013.         mdmtyp = -mynet;        /* This should have been done */
  10014.                     /* already but just in case ... */
  10015.  
  10016.         debug(F110,"setlin net line[] before ttopen",line,0);
  10017.         debug(F101,"setlin net mdmtyp before ttopen","",mdmtyp);
  10018.         debug(F101,"setlin net ttnproto","",ttnproto);
  10019.  
  10020. #ifdef CK_AUTHENTICATION
  10021.             if ((ttnproto == NP_TELNET || ttnproto == NP_KERMIT) &&
  10022.                  a_type > -1) {
  10023.                 if (!sl_auth_saved) {
  10024.                     int x;
  10025.                     for (x = 0; x < AUTHTYPLSTSZ; x++)
  10026.               sl_auth_type_user[x] = auth_type_user[x];
  10027.                     sl_auth_saved = 1;
  10028.                 }
  10029.                 if (!sl_topt_a_s_saved) {
  10030.                     sl_topt_a_su = TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION);
  10031.                     sl_topt_a_s_saved = 1;
  10032.                 }
  10033.                 if (!sl_topt_a_c_saved) {
  10034.                     sl_topt_a_cm = TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION);
  10035.                     sl_topt_a_c_saved = 1;
  10036.                 }
  10037.                 switch (a_type) {
  10038.                   case AUTHTYPE_AUTO:
  10039.                     auth_type_user[0] = AUTHTYPE_AUTO;
  10040.                     TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_RQ;
  10041.                     TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_RQ;
  10042.                     break;
  10043.                   case AUTHTYPE_NULL:
  10044.             auth_type_user[0] = AUTHTYPE_NULL;
  10045.             TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_RF;
  10046.             TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_RF;
  10047.             break;
  10048. #ifdef CK_SRP
  10049.           case AUTHTYPE_SRP:
  10050.                     auth_type_user[0] = AUTHTYPE_SRP;
  10051.                     auth_type_user[1] = AUTHTYPE_NULL;
  10052.                     TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  10053.                     TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  10054.                     break;
  10055. #endif /* CK_SRP */
  10056. #ifdef CK_SSL
  10057.           case AUTHTYPE_SSL:
  10058.                     auth_type_user[0] = AUTHTYPE_SSL;
  10059.                     auth_type_user[1] = AUTHTYPE_NULL;
  10060.                     TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  10061.                     TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  10062.                     break;
  10063. #endif /* CK_SSL */
  10064. #ifdef NT
  10065.           case AUTHTYPE_NTLM:
  10066.                     auth_type_user[0] = AUTHTYPE_NTLM;
  10067.                     auth_type_user[1] = AUTHTYPE_NULL;
  10068.                     TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  10069.                     TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  10070.                     break;
  10071. #endif /* NT */
  10072. #ifdef CK_KERBEROS
  10073.           case AUTHTYPE_KERBEROS_V4:
  10074.                     auth_type_user[0] = AUTHTYPE_KERBEROS_V4;
  10075.                     auth_type_user[1] = AUTHTYPE_NULL;
  10076.                     TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  10077.                     TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  10078.                     break;
  10079.  
  10080.           case AUTHTYPE_KERBEROS_V5:
  10081.                     auth_type_user[0] = AUTHTYPE_KERBEROS_V5;
  10082.                     auth_type_user[1] = AUTHTYPE_NULL;
  10083.                     TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  10084.                     TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  10085.                     break;
  10086. #endif /* CK_KERBEROS */
  10087.                 }
  10088.             }
  10089.  
  10090.             /*
  10091.                If the user is going to require a Kerberos connection
  10092.                of a particular type, let's make sure we have a valid TGT.
  10093.             */
  10094.         makestr(&slmsg,"Authentication failure");
  10095.             if ((ttnproto == NP_TELNET || ttnproto == NP_KERMIT) &&
  10096.         (line[0] == '*' &&
  10097.          TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) == TN_NG_MU ||
  10098.          line[0] != '*' &&
  10099.          TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) == TN_NG_MU)
  10100.         ) {
  10101. #ifdef CK_KERBEROS
  10102.                 if ( auth_type_user[0] == AUTHTYPE_KERBEROS_V4 ) {
  10103.                     extern int krb4_autoget;
  10104.                     if (!ck_krb4_is_installed()) {
  10105.             printf(
  10106.         "?Required authentication method (Kerberos 4) is not installed\n"
  10107.                    );
  10108.                         slrestor();
  10109.             return(success = 0);
  10110.                     }
  10111. #ifdef COMMENT
  10112.                     /* This code results in false failures when using */
  10113.                     /* kerberos to machines in realms other than the  */
  10114.                     /* default since we don't know the realm of the   */
  10115.                     /* other machine until perform the reverse DNS    */
  10116.                     /* lookup.                                        */
  10117.             else if (line[0] != '*' && !ck_krb4_is_tgt_valid() &&
  10118.                    (!krb4_autoget ||
  10119.                 krb4_autoget && !ck_krb4_autoget_TGT(NULL))) {
  10120.                         printf(
  10121.         "?Kerberos 4: Ticket Getting Ticket not valid.\n"
  10122.                    );
  10123.                         slrestor();
  10124.                         return(success = 0);
  10125.                     }
  10126. #endif /* COMMENT */
  10127.                 } else if (auth_type_user[0] == AUTHTYPE_KERBEROS_V5) {
  10128.                     extern int krb5_autoget;
  10129.                     if (!ck_krb5_is_installed()) {
  10130.             printf(
  10131.         "?Required authentication method (Kerberos 5) is not installed\n"
  10132.                    );
  10133.                         slrestor();
  10134.                         return(success = 0);
  10135.                     }
  10136. #ifdef COMMENT
  10137.                     /* This code results in false failures when using */
  10138.                     /* kerberos to machines in realms other than the  */
  10139.                     /* default since we don't know the realm of the   */
  10140.                     /* other machine until perform the reverse DNS    */
  10141.                     /* lookup.                                        */
  10142.             else if (line[0] != '*' && !ck_krb5_is_tgt_valid() &&
  10143.                    (!krb5_autoget ||
  10144.                 krb5_autoget && !ck_krb5_autoget_TGT(NULL))) {
  10145.                         printf(
  10146.         "?Kerberos 5: Ticket Getting Ticket not valid.\n"
  10147.                    );
  10148.                         slrestor();
  10149.                         return(success = 0);
  10150.                     }
  10151. #endif /* COMMENT */
  10152.                 }
  10153. #endif /* CK_KERBEROS */
  10154. #ifdef NT
  10155.                 if (auth_type_user[0] == AUTHTYPE_NTLM) {
  10156.                     if (!ck_ntlm_is_installed()) {
  10157.             printf(
  10158.         "?Required authentication method (NTLM) is not installed\n"
  10159.                    );
  10160.                         slrestor();
  10161.                         return(success = 0);
  10162.                     } else if (line[0] != '*' && !ck_ntlm_is_valid(0)) {
  10163.                         printf("?NTLM: Credentials are unavailable.\n");
  10164.                         slrestor();
  10165.                         return(success = 0);
  10166.                     }
  10167.                 }
  10168. #endif /* NT */
  10169. #ifdef CK_SSL
  10170.                 if (auth_type_user[0] == AUTHTYPE_SSL) {
  10171.                     if (!ck_ssleay_is_installed()) {
  10172.             printf(
  10173.         "?Required authentication method (SSL) is not installed\n"
  10174.                    );
  10175.                         slrestor();
  10176.                         return(success = 0);
  10177.                     }
  10178.                 }
  10179. #endif /* CK_SSL */
  10180. #ifdef CK_SRP
  10181.                 if (auth_type_user[0] == AUTHTYPE_SRP) {
  10182.                     if (!ck_srp_is_installed()) {
  10183.             printf(
  10184.         "?Required authentication method (SRP) is not installed\n"
  10185.                    );
  10186.                         slrestor();
  10187.                         return(success = 0);
  10188.                     }
  10189.                 }
  10190. #endif /* CK_SRP */
  10191.             }
  10192. #endif /* CK_AUTHENTICATION */
  10193. #ifdef CK_ENCRYPTION
  10194.             if ((ttnproto == NP_TELNET || ttnproto == NP_KERMIT) &&
  10195.                  e_type > -1) {
  10196.                 if (!sl_cx_saved) {
  10197.                     sl_cx_type = cx_type;
  10198.                     sl_cx_saved = 1;
  10199.                 }
  10200.                 if (!sl_topt_e_s_saved) {
  10201.                     sl_topt_e_su = TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION);
  10202.                     sl_topt_e_sm = TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION);
  10203.                     sl_topt_e_s_saved = 1;
  10204.                 }
  10205.                 if (!sl_topt_e_c_saved) {
  10206.                     sl_topt_e_cu = TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION);
  10207.                     sl_topt_e_cm = TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION);
  10208.                     sl_topt_e_c_saved = 1;
  10209.                 }
  10210.                 cx_type = e_type;
  10211.                 if (cx_type == CX_AUTO) {
  10212.                     TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION) = TN_NG_RQ;
  10213.                     TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_RQ;
  10214.                     TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION) = TN_NG_RQ;
  10215.                     TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_RQ;
  10216.                 } else if (cx_type == CX_NONE) {
  10217.                     TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION) = TN_NG_RF;
  10218.                     TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_RF;
  10219.                     TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION) = TN_NG_RF;
  10220.                     TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_RF;
  10221.                 } else {
  10222.                     TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION) = TN_NG_MU;
  10223.                     TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_MU;
  10224.                     TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION) = TN_NG_MU;
  10225.                     TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_MU;
  10226.                 }
  10227.             }
  10228.             if (ttnproto == NP_EK4LOGIN || ttnproto == NP_EK5LOGIN ||
  10229.         (ttnproto == NP_TELNET || ttnproto == NP_KERMIT) &&
  10230.         ((line[0] == '*' &&
  10231.           TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION) == TN_NG_MU &&
  10232.           TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION) == TN_NG_MU) ||
  10233.          (line[0] != '*' &&
  10234.           TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION) == TN_NG_MU &&
  10235.           TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION) == TN_NG_MU))
  10236.         ) {
  10237.                 if (!ck_crypt_is_installed()) {
  10238.             makestr(&slmsg,"Encryption failure");
  10239.                     printf("?Required Encryption methods are not installed\n");
  10240.                     slrestor();
  10241.                     return(success = 0);
  10242.                 }
  10243.             }
  10244. #endif /* CK_ENCRYPTION */
  10245. #ifdef RLOGCODE
  10246. #ifdef CK_KERBEROS
  10247. #ifdef KRB4
  10248.             if (ttnproto == NP_K4LOGIN || ttnproto == NP_EK4LOGIN) {
  10249.                 extern int krb4_autoget;
  10250.                 char tgt[256];
  10251.                 char * realm;
  10252.  
  10253.                 /* this is fine except for one huge problem         */
  10254.                 /* we don't have the full hostname at this point    */
  10255.                 /* so we really need to perform a DNS lookup before */
  10256.                 /* calling ttopen().                                */
  10257.  
  10258.                 realm = ck_krb4_realmofhost(ckgetfqhostname(hostname));
  10259.         ckmakmsg(tgt,256,"krbtgt.",realm,"@",realm);
  10260.                 if (!ck_krb4_is_installed()) {
  10261.             printf(
  10262.         "?Required authentication method (Kerberos 4) is not installed\n"
  10263.                );
  10264.                     slrestor();
  10265.                     return(success = 0);
  10266.                 } else {
  10267.                     if ((ck_krb4_tkt_isvalid(tgt) <= 0) &&
  10268.             (!krb4_autoget ||
  10269.              krb4_autoget && !ck_krb4_autoget_TGT(realm))) {
  10270.             printf(
  10271.                "?Kerberos 4: Ticket Getting Ticket not valid.\n");
  10272.             slrestor();
  10273.             return(success = 0);
  10274.                     }
  10275.                 }
  10276.             }
  10277. #endif /* KRB4 */
  10278. #ifdef KRB5
  10279.             if (ttnproto == NP_K5LOGIN || ttnproto == NP_EK5LOGIN ||
  10280.                 ttnproto == NP_K5U2U)
  10281.             {
  10282.                 extern int krb5_autoget;
  10283.                 char tgt[256];
  10284.                 char * realm;
  10285.  
  10286.                 /* this is fine except for one huge problem         */
  10287.                 /* we don't have the full hostname at this point    */
  10288.                 /* so we really need to perform a DNS lookup before */
  10289.                 /* calling ttopen().                                */
  10290.  
  10291.                 realm = ck_krb5_realmofhost(ckgetfqhostname(hostname));
  10292.         ckmakmsg(tgt,256,"krbtgt/",realm,"@",realm);
  10293.  
  10294.                 if (!ck_krb5_is_installed()) {
  10295.             printf(
  10296.         "?Required authentication method (Kerberos 5) is not installed\n"
  10297.                );
  10298.                     slrestor();
  10299.                     return(success = 0);
  10300.                 } else if (!((ck_krb5_tkt_isvalid(NULL,tgt) > 0) ||
  10301.                               ck_krb5_is_tgt_valid()) &&
  10302.                (!krb5_autoget ||
  10303.                 krb5_autoget && !ck_krb5_autoget_TGT(realm))) {
  10304.                     printf("?Kerberos 5: Ticket Getting Ticket not valid.\n");
  10305.                     slrestor();
  10306.                     return(success = 0);
  10307.                 }
  10308.             }
  10309. #endif /* KRB5 */
  10310. #endif /* CK_KERBEROS */
  10311. #endif /* RLOGCODE */
  10312.  
  10313. #ifdef NETCONN
  10314. #ifndef NOSPL
  10315.             if (tmpstring) {
  10316.                 if (tmpstring[0]) {
  10317.                     ckstrncpy(pwbuf,tmpstring,PWBUFL+1);
  10318.                     pwflg = 1;
  10319.                     pwcrypt = 0;
  10320.                 } else
  10321.                     pwflg = 0;
  10322.                 makestr(&tmpstring,NULL);
  10323.             }
  10324. #ifdef RLOGCODE
  10325.             if (tmpusrid) {
  10326.                 if (!sl_uid_saved) {
  10327.                     ckstrncpy(sl_uidbuf,uidbuf,UIDBUFLEN);
  10328.                     sl_uid_saved = 1;
  10329.                 }
  10330.         ckstrncpy(uidbuf,tmpusrid,UIDBUFLEN);
  10331.                 makestr(&tmpusrid,NULL);
  10332.                 uidflag = 1;
  10333.             }
  10334. #endif /* RLOGCODE */
  10335. #endif /* NOSPL */
  10336. #endif /* NETCONN */
  10337.  
  10338. #ifdef TNCODE
  10339.             if (!sl_tn_saved) {
  10340.                 sl_tn_wait = tn_wait_flg;
  10341.                 sl_tn_saved = 1;
  10342.             }
  10343.         tn_wait_flg = wait;
  10344. #endif /* TNCODE */
  10345.  
  10346.         /* Try to open */
  10347.             y = ttopen(line, &_local, mdmtyp, 0 );
  10348.  
  10349. #ifndef NOHTTP
  10350.             /*  If the connection failed and we are using an HTTP Proxy
  10351.              *  and the reason for the failure was an authentication
  10352.              *  error, then we need to give the user to ability to
  10353.              *  enter a username and password, just like a browser.
  10354.              *
  10355.              *  I tried to do all of this within the netopen() call
  10356.              *  but it is much too much work.
  10357.              */
  10358.             while (y < 0 && tcp_http_proxy != NULL ) {
  10359.  
  10360.                 if (tcp_http_proxy_errno == 401 ||
  10361.             tcp_http_proxy_errno == 407 ) {
  10362.                     char uid[UIDBUFLEN];
  10363.                     char pwd[256];
  10364.  
  10365.                     readtext("Proxy Userid: ",uid,UIDBUFLEN);
  10366.                     if (uid[0]) {
  10367.                         char * proxy_user, * proxy_pwd;
  10368.  
  10369.                         readpass("Proxy Password: ",pwd,256);
  10370.  
  10371.                         proxy_user = tcp_http_proxy_user;
  10372.                         proxy_pwd  = tcp_http_proxy_pwd;
  10373.  
  10374.                         tcp_http_proxy_user = uid;
  10375.                         tcp_http_proxy_pwd = pwd;
  10376.  
  10377.                         y = ttopen(line, &_local, mdmtyp, 0);
  10378.                         memset(pwd,0,sizeof(pwd));
  10379.                         tcp_http_proxy_user = proxy_user;
  10380.                         tcp_http_proxy_pwd = proxy_pwd;
  10381.                     } else
  10382.               break;
  10383.                 } else
  10384.           break;
  10385.             }
  10386. #endif /* NOHTTP */
  10387.         if (y < 0) {
  10388.                 slrestor();
  10389.         makestr(&slmsg,"Network connection failure");
  10390. #ifdef VMS
  10391.         if (hints && !xcmdsrc && ttnproto == NP_RLOGIN) {
  10392.             makestr(&slmsg,"RLOGIN failure");
  10393.             if  (socket_errno == EACCES) {
  10394.                         printf("*************************\n");
  10395.                 printf(
  10396.                "Hint: RLOGIN requires privileges to open an outbound port.\n");
  10397.                 printf(
  10398.                         "(Use SET HINTS OFF to suppress future hints.)\n");
  10399.                 printf("*************************\n");
  10400.                     }
  10401.         }
  10402. #else  /* Not VMS... */
  10403.         if (errno) {
  10404.             int x;
  10405.             debug(F111,"set host line, errno","",errno);
  10406.             makestr(&slmsg,ck_errstr());
  10407.             x = strlen(line) + 2;
  10408.             if (LINBUFSIZ - x > 100) {
  10409.             tp = line + x;
  10410. #ifdef OS2
  10411.             printf("Can't connect to %s\n",line);
  10412. #else /* OS2 */
  10413. #ifdef UNIX
  10414.             if (hints && !xcmdsrc && ttnproto == NP_RLOGIN) {
  10415.                 makestr(&slmsg,"RLOGIN failure");
  10416.                 printf("*************************\n");
  10417.                 printf(
  10418.              "Hint: RLOGIN requires privileges to open an outbound port.\n");
  10419.                 printf(
  10420.          "(Use SET HINTS OFF to suppress future hints.)\n");
  10421.                 printf("*************************\n");
  10422.             }
  10423. #endif /* UNIX */
  10424. #endif /* OS2 */
  10425.             } else printf("Can't connect to %s\n",line);
  10426.         } else
  10427. #endif /* VMS */
  10428.           printf("Can't open connection to %s\n",line);
  10429.         continue;
  10430.         } else {
  10431.         success = 1;
  10432. #ifndef NODIAL
  10433.         dialsta = DIA_UNK;
  10434. #endif /* NODIAL */
  10435.         switch (mynet) {
  10436.           case NET_TCPA:
  10437.           case NET_TCPB:
  10438.             cxtype = CXT_TCPIP;
  10439.             break;
  10440.           case NET_SLAT:
  10441.             cxtype = CXT_LAT;
  10442.             break;
  10443.           case NET_SX25:
  10444.           case NET_IX25:
  10445.           case NET_HX25:
  10446.           case NET_VX25:
  10447.             cxtype = CXT_X25;
  10448.             break;
  10449.           case NET_BIOS:
  10450.             cxtype = CXT_NETBIOS;
  10451.             break;
  10452.           case NET_FILE:
  10453.           case NET_PIPE:
  10454.           case NET_CMD:
  10455.           case NET_DLL:
  10456.           case NET_PTY:
  10457.             cxtype = CXT_PIPE;
  10458.             break;
  10459.           default:
  10460.             cxtype = CXT_PIPE;
  10461.             break;
  10462.         }
  10463.         break;
  10464.         }
  10465.     } /* for-loop */
  10466.     s = line;
  10467.     } /* network connection */
  10468. #endif /* NETCONN */
  10469. /*
  10470.   NOTE:
  10471.   The following will fail if Kermit is running as a daemon with no
  10472.   controlling tty.  Needs research.
  10473. */
  10474.     if (!success) {
  10475.     local = dfloc;            /* Go back to normal */
  10476. #ifndef MAC
  10477.     ckstrncpy(ttname,dftty,TTNAMLEN); /* Restore default tty name */
  10478. #endif /* MAC */
  10479.     speed = ttgspd();
  10480.     network = 0;            /* No network connection active */
  10481.     haveline = 0;
  10482.     if (mdmtyp < 0) {        /* Switching from net to async? */
  10483.         if (mdmsav > -1)        /* Restore modem type from last */
  10484.           mdmtyp = mdmsav;        /* SET MODEM command, if any. */
  10485.         else
  10486.           mdmtyp = 0;
  10487.         mdmsav = -1;
  10488.     }
  10489.     return(0);            /* Return failure */
  10490.     }
  10491.     if (_local > -1) local = _local;    /* Opened ok, set local/remote. */
  10492.     makestr(&slmsg,NULL);
  10493.     network = (mdmtyp < 0);        /* Remember connection type. */
  10494.     ckstrncpy(ttname,s,TTNAMLEN);    /* Copy name into real place. */
  10495.     debug(F110,"setlin ok",ttname,0);
  10496.     debug(F101,"setlin network","",network);
  10497. #ifndef NOXFER
  10498.     if ((reliable != SET_OFF || !setreliable)) /* Assume not reliable. */
  10499.       reliable = SET_OFF;            
  10500. #endif /* NOXFER */
  10501.     if (!network)
  10502.       speed = ttgspd();            /* Get the current speed. */
  10503.     debug(F101,"setlin local","",local);
  10504. #ifdef NETCONN
  10505.     if (network) {
  10506.     debug(F101,"setlin mynet","",mynet);
  10507. #ifndef NOXFER
  10508.     /* Force prefixing of 255 on TCP/IP connections... */
  10509.     if (mynet == NET_TCPB) {
  10510.         debug(F101,"setlin reliable A","",reliable);
  10511. #ifdef CK_SPEED
  10512.         ctlp[(unsigned)255] = 1;
  10513. #endif /* CK_SPEED */
  10514.         if ((reliable != SET_OFF || !setreliable)) {
  10515. #ifdef TN_COMPORT
  10516.         if (istncomport()) {    /* Telnet communication port */
  10517.             reliable = SET_OFF;    /* Transport is not reliable */
  10518.             debug(F101,"setlin reliable istncomport()","",1);
  10519.         } else {
  10520.             reliable = SET_ON;    /* Transport is reliable end to end */
  10521.             debug(F101,"setlin reliable istncomport()","",0);
  10522.         }
  10523. #else
  10524.         reliable = SET_ON;    /* Transport is reliable end to end */
  10525. #endif /* ifdef TN_COMPORT */
  10526.         }
  10527.         debug(F101,"setlin reliable B","",reliable);
  10528.     } else if (mynet == NET_SX25 ||
  10529.            mynet == NET_VX25 ||
  10530.            mynet == NET_IX25 ||
  10531.            mynet == NET_HX25) {
  10532.         duplex = 1;            /* Local echo for X.25 */
  10533.         if (reliable != SET_OFF || !setreliable)
  10534.           reliable = SET_ON;    /* Transport is reliable end to end */
  10535.     }
  10536. #endif /* NOXFER */
  10537.     }
  10538. #endif /* NETCONN */
  10539. #ifndef NOXFER
  10540.     debug(F101,"setlin reliable","",reliable);
  10541. #endif /* NOXFER */
  10542. #ifdef OS2
  10543.     if (mdmtyp <= 0)            /* Network or Direct Connection */
  10544.       DialerSend(OPT_KERMIT_CONNECT, 0);
  10545. #endif /* OS2 */
  10546.  
  10547.   xsetlin:
  10548.  
  10549.     setflow();                /* Set appropriate flow control */
  10550.  
  10551.     haveline = 1;
  10552. #ifdef CKLOGDIAL
  10553. #ifdef NETCONN
  10554.     if (network)            /* Start connection log record */
  10555.       dolognet();
  10556.     else
  10557. #endif /* NETCONN */
  10558.       dologline();
  10559. #endif /* CKLOGDIAL */
  10560.  
  10561. #ifndef NOSPL
  10562.     if (local) {
  10563.     if (nmac) {            /* Any macros defined? */
  10564.         int k;            /* Yes */
  10565.         k = mlook(mactab,"on_open",nmac);    /* Look this up */
  10566.         if (k >= 0) {            /* If found, */
  10567.         if (dodo(k,ttname,0) > -1)    /* set it up, */
  10568.           parser(1);            /* and execute it */
  10569.         }
  10570.     }
  10571.     }
  10572. #endif /* NOSPL */
  10573.  
  10574.     if (local && (cx || sx)) {        /* /CONNECT or /SERVER switch given */
  10575.     extern int carrier;
  10576.     if (xx == XYLINE && carrier != CAR_OFF) { /* on serial connection... */
  10577.         /* Open() turns on DTR -- wait up to a second for CD to come up */
  10578.         int i, x;
  10579.         for (i = 0; i < 10; i++) {    /* WAIT 1 CD... */
  10580.         x = ttgmdm();
  10581.         if (x < 0 || x & BM_DCD)
  10582.           break;
  10583.         msleep(100);
  10584.         }
  10585.     }
  10586.     if (cx) {            /* /CONNECT */
  10587.             /* Command was confirmed so we can pre-pop command level. */
  10588.             /* This is so CONNECT module won't think we're executing a */
  10589.             /* script if CONNECT was the final command in the script. */
  10590.  
  10591.             if (cmdlvl > 0)
  10592.           prepop();
  10593. #ifndef NODIAL
  10594.         dialsta = DIA_UNK;
  10595. #endif /* NODIAL */
  10596.         success = doconect(0, cmdlvl == 0 ? 1 : 0);
  10597. #ifdef CKLOGDIAL
  10598.         if (ttchk() < 0)
  10599.           dologend();
  10600. #endif /* CKLOGDIAL */
  10601.         return(success);
  10602. #ifndef NOXFER
  10603.     } else if (sx) {        /* /SERVER */
  10604.         sstate = 'x';
  10605. #ifdef MAC
  10606.         what = W_RECV;
  10607.         scrcreate();
  10608. #endif /* MAC */
  10609.         if (local) displa = 1;
  10610. #ifdef AMIGA
  10611.         reqoff();            /* No DOS requestors while server */
  10612. #endif /* AMIGA */
  10613. #endif /* NOXFER */
  10614.     }
  10615.     }
  10616. #ifndef NODIAL
  10617.     dialsta = DIA_UNK;
  10618. #endif /* NODIAL */
  10619.     return(success = 1);
  10620. }
  10621. #endif /* NOLOCAL */
  10622.  
  10623. #ifdef CKCHANNELIO
  10624. /*
  10625.   C-Library based file-i/o package for scripts.  This should be portable to
  10626.   all C-Kermit versions since it uses the same APIs we have always used for
  10627.   processing command files.  The entire channel i/o package is contained
  10628.   herein, apart from some keyword table entries in the main keyword table
  10629.   and the help text in the HELP command module.
  10630.  
  10631.   On platforms like VMS and VOS, this package handles only UNIX-style
  10632.   stream files.  If desired, it can be replaced for those platforms by
  10633.   <#>ifdef'ing out this code and adding the equivalent replacement routines
  10634.   to the ck?fio.c module, e.g. for RMS-based file i/o in ckvfio.c.
  10635. */
  10636.  
  10637. /* Define NOSTAT if the <#>include causes trouble. */
  10638.  
  10639. #ifndef NOSTAT
  10640. #ifdef VMS
  10641. #ifdef VAXC                /* As it does in VAX C */
  10642. #define NOSTAT
  10643. #endif /* VAXC */
  10644. #endif /* VMS */
  10645. #endif /* NOSTAT */
  10646.  
  10647. #ifndef NOSTAT
  10648. #include <sys/stat.h>
  10649. #endif /* NOSTAT */
  10650.  
  10651. #ifdef NLCHAR
  10652. static int z_lt = 1;            /* Length of line terminator */
  10653. #else
  10654. static int z_lt = 2;
  10655. #endif /* NLCHAR */
  10656.  
  10657. struct ckz_file {            /* C-Kermit file struct */
  10658.     FILE * z_fp;            /* Includes the C-Lib file struct */
  10659.     unsigned int z_flags;        /* Plus C-Kermit mode flags, */
  10660.     long z_nline;            /* current line number if known, */
  10661.     char z_name[CKMAXPATH+2];        /* and the file's name. */
  10662. };
  10663. static struct ckz_file * z_file = NULL;    /* Array of C-Kermit file structs */
  10664. static int z_inited = 0;        /* Flag for array initialized */
  10665. int z_maxchan = Z_MAXCHAN;        /* Max number of C-Kermit channels */
  10666. int z_openmax = CKMAXOPEN;        /* Max number of open files overall */
  10667. int z_nopen = 0;            /* How many channels presently open */
  10668. int z_error = 0;            /* Most recent error */
  10669. int z_filcount = -1;            /* Most recent FILE COUNT result */
  10670.  
  10671. #define RD_LINE 0            /* FILE READ options */
  10672. #define RD_CHAR 1
  10673. #define RD_SIZE 2
  10674.  
  10675. #define WR_LINE RD_LINE            /* FILE WRITE options */
  10676. #define WR_CHAR RD_CHAR
  10677. #define WR_SIZE RD_SIZE
  10678. #define WR_STRI 3
  10679. #define WR_LPAD 4
  10680. #define WR_RPAD 5
  10681.  
  10682. #ifdef UNIX
  10683. extern int ckmaxfiles;            /* Filled in by sysinit(). */
  10684. #endif /* UNIX */
  10685.  
  10686. /* See ckcker.h for error numbers */
  10687. /* See ckcdeb.h for Z_MAXCHAN and CKMAXOPEN definitions */
  10688. /* NOTE: For VMS we might be able to fill in ckmaxfiles */
  10689. /* from FILLM and CHANNELCNT -- find out about these... */
  10690.  
  10691. static char * fopnargs[] = {        /* Mode combinations for fopen() */
  10692. #ifdef COMMENT
  10693.     /* All combinations of rwa */
  10694.     "",  "r",  "w",  "rw",  "a",  "ra",  "wa",  "rwa", /* Text mode */
  10695.     "b", "rb", "wb", "rwb", "ab", "rab", "wab", "rwab" /* Binary mode */
  10696. #else
  10697.     /* Combinations and syntax permitted by C libraries... */
  10698.     "",  "r",  "w",  "r+",  "a",  "",   "a",  "", /* Text mode */
  10699. #ifdef OS2
  10700.     "",  "rb", "wb", "r+b", "ab", "",   "ab", "" /* Binary modes for K95 */
  10701. #else
  10702. #ifdef VMS
  10703.     "",  "rb", "wb", "r+b", "ab", "",   "ab", "" /* Binary modes for VMS */
  10704. #else
  10705.     "",  "r",   "w", "r+",  "a",  "",   "a",  "" /* Binary modes for UNIX */
  10706. #endif /* VMS */
  10707. #endif /* OS2 */
  10708. #endif /* COMMENT */
  10709. };
  10710. static int nfopnargs = sizeof(fopnargs) / sizeof(char *);
  10711.  
  10712. char *                    /* Error messages */
  10713. ckferror(n) int n; {
  10714.     switch (n) {
  10715.       case FX_NER: return("No error");
  10716.       case FX_SYS: return(ck_errstr());
  10717.       case FX_EOF: return("End of file");
  10718.       case FX_NOP: return("File not open");
  10719.       case FX_CHN: return("Channel out of range");
  10720.       case FX_RNG: return("Parameter out of range");
  10721.       case FX_NMF: return("Too many files open");
  10722.       case FX_FOP: return("Operation conflicts with OPEN mode");
  10723.       case FX_NYI: return("OPEN mode not supported");
  10724.       case FX_BOM: return("Illegal combination of OPEN modes");
  10725.       case FX_ACC: return("Access denied");
  10726.       case FX_FNF: return("File not found");
  10727.       case FX_OFL: return("Buffer overflow");
  10728.       case FX_LNU: return("Current line number unknown");
  10729.       case FX_ROO: return("Off limits");
  10730.       case FX_UNK: return("Operation fails - reason unknown");
  10731.       default: return("Error number out of range");
  10732.     }
  10733. }
  10734.  
  10735. /*
  10736.   Z _ O P E N --  Open a file for the requested type of access.
  10737.  
  10738.   Call with:
  10739.     name:  Name of file to be opened.
  10740.     flags: Any combination of FM_xxx values except FM_EOF (ckcker.h).
  10741.   Returns:
  10742.     >= 0 on success: The assigned channel number
  10743.     <  0 on failure: A negative FX_xxx error code (ckcker.h).
  10744. */
  10745. int
  10746. z_open(name, flags) char * name; int flags; {
  10747.     int i, n;
  10748.     FILE * t;
  10749.     char * mode;
  10750.     debug(F111,"z_open",name,flags);
  10751.     if (!name) name = "";        /* Check name argument */
  10752.     if (!name[0])
  10753.       return(z_error = FX_BFN);
  10754.     if (flags & FM_CMD)            /* Opening pipes not implemented yet */
  10755.       return(z_error = FX_NYI);        /* (and not portable either) */
  10756.     debug(F101,"z_open nfopnargs","",nfopnargs);
  10757.     if (flags < 0 || flags >= nfopnargs) /* Range check flags */
  10758.       return(z_error = FX_RNG);
  10759.     mode = fopnargs[flags];        /* Get fopen() arg */
  10760.     debug(F111,"z_open fopen args",mode,flags);
  10761.     if (!mode[0])            /* Check for illegal combinations */
  10762.       return(z_error = FX_BOM);
  10763.     if (!z_inited) {            /* If file structs not inited */
  10764.     debug(F101,"z_open z_maxchan 1","",z_maxchan);
  10765. #ifdef UNIX
  10766.     debug(F101,"z_open ckmaxfiles","",ckmaxfiles);
  10767.     if (ckmaxfiles > 0) {        /* Set in ck?tio.c: sysinit() */
  10768.         int x;
  10769.         x = ckmaxfiles - ZNFILS - 5;
  10770.         if (x > z_maxchan)        /* sysconf() value greater than */
  10771.           z_maxchan = x;        /* value from header files. */
  10772.         debug(F101,"z_open z_maxchan 2","",z_maxchan);
  10773.     }
  10774. #endif /* UNIX */
  10775.     if (z_maxchan < Z_MINCHAN)    /* Allocate at least this many. */
  10776.       z_maxchan = Z_MINCHAN;
  10777.     debug(F101,"z_open z_maxchan 3","",z_maxchan);
  10778.     /* Note: This could be a pretty big chunk of memory */
  10779.     /* if z_maxchan is a big number.  If this becomes a problem */
  10780.     /* we'll need to malloc and free each element at open/close time */
  10781.     if (!(z_file = (struct ckz_file *)
  10782.           malloc(sizeof(struct ckz_file) * (z_maxchan + 1))))
  10783.       return(z_error = FX_NMF);
  10784.     for (i = 0; i < z_maxchan; i++) {
  10785.         z_file[i].z_fp = NULL;
  10786.         z_file[i].z_flags = 0;
  10787.         z_file[i].z_nline = 0;
  10788.         *(z_file[i].z_name) = '\0';
  10789.     }
  10790.     z_inited = 1;            /* Remember we did */
  10791.     }
  10792.     for (n = -1, i = 0; i < z_maxchan; i++) {
  10793.     if (!z_file[i].z_fp) {
  10794.         n = i;
  10795.         break;
  10796.     }
  10797.     }
  10798.     if (n < 0 || n >= z_maxchan)    /* Any free channels? */
  10799.       return(z_error = FX_NMF);        /* No, fail. */
  10800.     errno = 0;
  10801.  
  10802.     z_file[n].z_flags = 0;        /* In case of failure... */
  10803.  
  10804.     t = fopen(name, mode);        /* Try to open the file. */
  10805.     if (!t) {                /* Failed... */
  10806.     debug(F111,"z_open error",name,errno);
  10807. #ifdef EMFILE
  10808.     if (errno == EMFILE)
  10809.       return(z_error = FX_NMF);
  10810. #endif /* EMFILE */
  10811.     return(z_error = (errno ?  FX_SYS : FX_UNK)); /* Return error code */
  10812.     }
  10813. #ifdef NT
  10814. #ifdef O_SEQUENTIAL
  10815.     if (t)                /* Caching hint for NT */
  10816.       _setmode(_fileno(t),O_SEQUENTIAL);
  10817. #endif /* O_SEQUENTIAL */
  10818. #endif /* NT */
  10819.     z_nopen++;                /* Open, count it. */
  10820.     z_file[n].z_fp = t;            /* Stash the file pointer */
  10821.     z_file[n].z_flags = flags;        /* and the flags */
  10822.     z_error = 0;
  10823.     zfnqfp(name,CKMAXPATH,z_file[n].z_name); /* and the file's full name */
  10824.     return(n);                /* Return the channel number */
  10825. }
  10826.  
  10827. int
  10828. z_close(channel) int channel; {        /* Close file on given channel */
  10829.     int x;
  10830.     FILE * t;
  10831.     if (!z_inited)            /* Called before any files are open? */
  10832.       return(z_error = FX_NOP);
  10833.     if (channel >= z_maxchan)        /* Channel out of range? */
  10834.       return(z_error = FX_CHN);
  10835.     if (!(t = z_file[channel].z_fp))    /* Channel wasn't open? */
  10836.       return(z_error = FX_NOP);
  10837.     errno = 0;                /* Set errno 0 to get a good reading */
  10838.     x = fclose(t);            /* Try to close */
  10839.     if (x == EOF)            /* On failure */
  10840.       return(z_error = FX_SYS);        /* indicate system error. */
  10841.     z_nopen--;                /* Closed OK, decrement open count */
  10842.     z_file[channel].z_fp = NULL;    /* Set file pointer to NULL */
  10843.     z_file[channel].z_nline = 0;    /* Current line number is 0 */
  10844.     z_file[channel].z_flags = 0;    /* Set flags to 0 */
  10845.     *(z_file[channel].z_name) = '\0';    /* Clear name */
  10846.     return(z_error = 0);
  10847. }
  10848.  
  10849. /*
  10850.   Z _ O U T  --  Output string to channel.
  10851.  
  10852.   Call with:
  10853.     channel:     Channel number to write to.
  10854.     s:           String to write.
  10855.     length > -1: How many characters of s to write.
  10856.     length < 0:  Write entire NUL-terminated string.
  10857.     flags == 0:  Supply line termination.
  10858.     flags >  0:  Don't supply line termination.
  10859.     flags <  0:  Write 'length' NUL characters.
  10860.   Special case:
  10861.     If flags > -1 and s is empty or NULL and length == 1, write 1 NUL.
  10862.   Returns:
  10863.     Number of characters written to channel on success, or
  10864.     negative FX_xxx error code on failure.
  10865. */
  10866. int
  10867. z_out(channel,s,length,flags) int channel, flags, length; char * s; {
  10868.     FILE * t;
  10869.     int x, n;
  10870.     char c = '\0';
  10871.  
  10872.     if (!s) s = "";            /* Guard against null pointer */
  10873. #ifdef DEBUG
  10874.     if (deblog) {
  10875.     debug(F111,"z_out",s,channel);
  10876.     debug(F101,"z_out length","",length);
  10877.     debug(F101,"z_out flags","",flags);
  10878.     }
  10879. #endif /* DEBUG */
  10880.     if (!z_inited)            /* File i/o inited? */
  10881.       return(z_error = FX_NOP);
  10882.     if (channel >= z_maxchan)        /* Channel in range? */
  10883.       return(z_error = FX_CHN);
  10884.     if (!(t = z_file[channel].z_fp))    /* File open? */
  10885.       return(z_error = FX_NOP);
  10886.     if (!((z_file[channel].z_flags) & (FM_WRI|FM_APP)))    /* In write mode? */
  10887.       return(z_error = FX_FOP);
  10888.     n = length;                /* Length of string to write */
  10889.     if (n < 0) {            /* Negative means get it ourselves */
  10890.     if (flags < 0)            /* Except when told to write NULs in */
  10891.       return(z_error = FX_RNG);    /* which case args are inconsistent */
  10892.     n = strlen(s);            /* Get length of string arg */
  10893.     }
  10894.     errno = 0;                /* Reset errno */
  10895.     debug(F101,"z_out n","",n);
  10896.     if (flags < 0) {            /* Writing NULs... */
  10897.     int i;
  10898.     for (i = 0; i < n; i++) {
  10899.         x = fwrite(&c,1,1,t);
  10900.         if (x < 1)
  10901.           return(z_error = (errno ? FX_SYS : FX_UNK));
  10902.     }
  10903.     z_file[channel].z_nline = -1;    /* Current line no longer known */
  10904.     z_error = 0;
  10905.     return(i);
  10906.     } else {                /* Writing string arg */
  10907.     if (n == 1 && !s[0])        /* Writing one char but it's NUL */
  10908.       x = fwrite(&c,1,1,t);
  10909.     else                /* Writing non-NUL char or string */
  10910.       x = fwrite(s,1,n,t);
  10911.     debug(F101,"z_out fwrite",ckitoa(x),errno);
  10912.     if (x < n)            /* Failure to write requested amount */
  10913.       return(z_error = (errno ? FX_SYS : FX_UNK)); /* Return error */
  10914.     if (flags == 0) {        /* If supplying line termination */
  10915.         if (fwrite("\n",1,1,t))    /* do that  */
  10916.           x += z_lt;        /* count the terminator */
  10917.         if (z_file[channel].z_nline > -1) /* count this line */
  10918.           z_file[channel].z_nline++;
  10919.     } else {
  10920.         z_file[channel].z_nline = -1; /* Current line no longer known */
  10921.     }
  10922.     }
  10923.     z_error = 0;
  10924.     return(x);
  10925. }
  10926.  
  10927. #define Z_INBUFLEN 64
  10928.  
  10929. /*
  10930.   Z _ I N  --  Multichannel i/o file input function.
  10931.  
  10932.   Call with:
  10933.     channel number to read from.
  10934.     s = address of destination buffer.
  10935.     buflen = destination buffer length.
  10936.     length = Number of bytes to read, must be < buflen.
  10937.     flags: 0 = read a line; nonzero = read the given number of bytes.
  10938.   Returns:
  10939.     Number of bytes read into buffer or a negative error code.
  10940.     A terminating NUL is deposited after the last byte that was read.
  10941. */
  10942. int
  10943. z_in(channel,s,buflen,length,flags)
  10944.  int channel, buflen, length, flags; char * s;
  10945. /* z_in */ {
  10946.     int i, j, x;
  10947.     FILE * t;
  10948.     char * p;
  10949.  
  10950.     if (!z_inited)            /* Check everything... */
  10951.       return(z_error = FX_NOP);
  10952.     if (channel >= z_maxchan)
  10953.       return(z_error = FX_CHN);
  10954.     if (!(t = z_file[channel].z_fp))
  10955.       return(z_error = FX_NOP);
  10956.     if (!((z_file[channel].z_flags) & FM_REA))
  10957.       return(z_error = FX_FOP);
  10958.     if (!s)                /* Check destination */
  10959.      return(z_error = FX_RNG);
  10960.     s[0] = NUL;
  10961.     if (length == 0)            /* Read 0 bytes - easy. */
  10962.       return(z_error = 0);
  10963.     debug(F101,"z_in channel","",channel);
  10964.     debug(F101,"z_in buflen","",buflen);
  10965.     debug(F101,"z_in length","",length);
  10966.     debug(F101,"z_in flags","",flags);
  10967.     if (length < 0 || buflen < 0)    /* Check length args */
  10968.       return(z_error = FX_RNG);
  10969.     if (buflen <= length)
  10970.       return(z_error = FX_RNG);
  10971.     errno = 0;                /* Reset errno */
  10972.     if (flags) {            /* Read block or byte */
  10973.     i = fread(s,1,length,t);
  10974. #ifdef DEBUG
  10975.     if (deblog) {
  10976.         debug(F111,"z_in block",s,i);
  10977.         debug(F101,"z_in block errno","",errno);
  10978.         debug(F101,"z_in block ferror","",ferror(t));
  10979.         debug(F101,"z_in block feof","",feof(t));
  10980.     }
  10981. #endif /* DEBUG */
  10982.     z_file[channel].z_nline = -1;    /* Current line no longer known */
  10983.     } else {                /* Read line */
  10984. #ifndef COMMENT
  10985.     /* This method is used because it's simpler than the others */
  10986.         /* and also marginally faster. */
  10987.     debug(F101,"z_in getc loop","",ftell(t));
  10988.     for (i = 0; i < length; i++) {
  10989.         if ((x = getc(t)) == EOF) {
  10990.         debug(F101,"z_in getc error","",ftell(t));
  10991.         s[i] = '\0';
  10992.         break;
  10993.         }
  10994.         s[i] = x;
  10995.         if (s[i] == '\n') {
  10996.         s[i] = '\0';
  10997.         break;
  10998.         }
  10999.     }
  11000.     debug(F111,"z_in line byte loop",ckitoa(errno),i);
  11001.     debug(F111,"z_in line got",s,z_file[channel].z_nline);
  11002.     if (z_file[channel].z_nline > -1)
  11003.       z_file[channel].z_nline++;
  11004. #else
  11005. #ifdef COMMENT2
  11006.     /* Straightforward but strlen() slows it down. */
  11007.     s[0] = '\0';
  11008.     i = 0;
  11009.     if (fgets(s,length,t)) {
  11010.         i = strlen(s);
  11011.         if (i > 0 && s[i-1] == '\n') i--;
  11012.     }
  11013.     debug(F111,"z_in line fgets",ckitoa(errno),i);
  11014.     if (z_file[channel].z_nline > -1)
  11015.       z_file[channel].z_nline++;
  11016. #else
  11017.     /* This is a do-it-yourself fgets() with its own readahead and */
  11018.     /* putback.  It's a bit faster than real fgets() but not enough */
  11019.     /* to justify the added complexity or the risk of the ftell() and */
  11020.     /* fseek() calls failing. */
  11021.     int k, flag = 0;
  11022.     long pos;
  11023.     for (i = 0; !flag && i <= (length - Z_INBUFLEN); i += Z_INBUFLEN) {
  11024.         k = ((length - i) < Z_INBUFLEN) ? length - i : Z_INBUFLEN;
  11025.         if ((x = fread(s+i,1,k,t)) < 1)
  11026.           break;
  11027.         s[i+x] = '\0';
  11028.         for (j = 0; j < x; j++) {
  11029.         if (s[i+j] == '\n') {
  11030.             s[i+j] = '\0';
  11031.             flag ++;
  11032.             pos = ftell(t);
  11033.             if (pos > -1) {
  11034.             pos -= (x - j - 1);
  11035.             x = fseek(t, pos, 0);
  11036.             i += j;
  11037.             break;
  11038.             } else
  11039.               return(z_error = FX_SYS);
  11040.         }
  11041.         }
  11042.     }
  11043.     if (z_file[channel].z_nline > -1)
  11044.       z_file[channel].z_nline++;
  11045.     debug(F111,"z_in line chunk loop",ckitoa(errno),i);
  11046. #endif /* COMMENT2 */
  11047. #endif /* COMMENT */
  11048.     }
  11049.     debug(F111,"z_in i",ckitoa(errno),i);
  11050.     if (i < 0) i = 0;            /* NUL-terminate result */
  11051.     s[i] = '\0';
  11052.     if (i > 0) {
  11053.     z_error = 0;
  11054.     return(i);
  11055.     }
  11056.     if (i == 0 && feof(t))        /* EOF on reading? */
  11057.       return(z_error = FX_EOF);        /* Return EOF code */
  11058.     return(errno ? (z_error = -1) : i);    /* Return length or system error */
  11059. }
  11060.  
  11061. int
  11062. z_flush(channel) int channel; {        /* Flush output channel */
  11063.     FILE * t;
  11064.     int x;
  11065.     if (!z_inited)            /* Regular checks */
  11066.       return(z_error = FX_NOP);
  11067.     if (channel >= z_maxchan)
  11068.       return(z_error = FX_CHN);
  11069.     if (!(t = z_file[channel].z_fp))
  11070.       return(z_error = FX_NOP);
  11071.     if (!((z_file[channel].z_flags) & (FM_WRI|FM_APP)))    /* Write access? */
  11072.       return(z_error = FX_FOP);
  11073.     errno = 0;                /* Reset errno */
  11074.     x = fflush(t);            /* Try to flush */
  11075.     return(x ? (z_error = FX_SYS) : 0);    /* Return system error or 0 if OK */
  11076. }
  11077.  
  11078. int
  11079. #ifdef CK_ANSIC
  11080. z_seek(int channel, long pos)        /* Move file pointer to byte */
  11081. #else
  11082. z_seek(channel,pos) int channel; long pos; /* (seek to given position) */
  11083. #endif /* CK_ANSIC */
  11084. {
  11085.     int i, x = 0, rc;
  11086.     FILE * t;
  11087.     if (!z_inited)            /* Check... */
  11088.       return(z_error = FX_NOP);
  11089.     if (channel >= z_maxchan)
  11090.       return(z_error = FX_CHN);
  11091.     if (!(t = z_file[channel].z_fp))
  11092.       return(z_error = FX_NOP);
  11093.     if (pos < 0L) {
  11094.     x = 2;
  11095.     pos = (pos == -2) ? -1L : 0L;
  11096.     }
  11097.     errno = 0;
  11098.     rc = fseek(t,pos,x);        /* Try to seek */
  11099.     debug(F111,"z_seek",ckitoa(errno),rc);
  11100.     if (rc < 0)                /* OK? */
  11101.       return(z_error = FX_SYS);    /* No. */
  11102.     z_file[channel].z_nline = ((pos || x) ? -1 : 0);
  11103.     return(z_error = 0);
  11104. }
  11105.  
  11106. int
  11107. #ifdef CK_ANSIC
  11108. z_line(int channel, long pos)        /* Move file pointer to line */
  11109. #else
  11110. z_line(channel,pos) int channel; long pos; /* (seek to given position) */
  11111. #endif /* CK_ANSIC */
  11112. {
  11113.     int i, len, x = 0;
  11114.     long current = 0L, prev = -1L, old = -1L;
  11115.     FILE * t;
  11116.     char tmpbuf[256];
  11117.     if (!z_inited)            /* Check... */
  11118.       return(z_error = FX_NOP);
  11119.     if (channel >= z_maxchan)
  11120.       return(z_error = FX_CHN);
  11121.     if (!(t = z_file[channel].z_fp))
  11122.       return(z_error = FX_NOP);
  11123.     debug(F101,"z_line pos","",pos);
  11124.     if (pos < 0L) {            /* EOF wanted */
  11125.         long n;
  11126.     n = z_file[channel].z_nline;
  11127.     debug(F101,"z_line n","",n);
  11128.     if (n < 0 || pos < 0) {
  11129.         rewind(t);
  11130.         n = 0;
  11131.     }
  11132.     while (1) {            /* This could take a while... */
  11133.         if ((x = getc(t)) == EOF)
  11134.           break;
  11135.         if (x == '\n') {
  11136.         n++;
  11137.         if (pos == -2) {
  11138.             old = prev;
  11139.             prev = ftell(t);
  11140.         }
  11141.         }
  11142.     }
  11143.     debug(F101,"z_line old","",old);
  11144.     debug(F101,"z_line prev","",prev);
  11145.     if (pos == -2) {
  11146.         if ((x = z_seek(channel,old)) < 0)
  11147.           return(z_error = x);
  11148.         else
  11149.           n--;
  11150.     }
  11151.     z_file[channel].z_nline = n;
  11152.     return(z_error = 0);
  11153.     }
  11154.     if (pos == 0L) {            /* Rewind wanted */
  11155.     z_file[channel].z_nline = 0L;
  11156.     rewind(t);
  11157.     debug(F100,"z_line rewind","",0);
  11158.     return(0L);
  11159.     }
  11160.     tmpbuf[255] = NUL;            /* Make sure buf is NUL terminated */
  11161.     current = z_file[channel].z_nline;    /* Current line */
  11162.     /*
  11163.       If necessary the following could be optimized, e.g. for positioning
  11164.       to a previous line in a large file without starting over.
  11165.     */
  11166.     if (current < 0 || pos < current) {    /* Not known or behind us... */
  11167.     debug(F101,"z_line rewinding","",pos);
  11168.     if ((x = z_seek(channel, 0L)) < 0) /* Rewind */
  11169.       return(z_error = x);
  11170.     if (pos == 0)            /* If 0th line wanted we're done */
  11171.       return(z_error = 0);
  11172.     current = 0;
  11173.     }
  11174.     while (current < pos) {        /* Search for specified line */
  11175.     if (fgets(tmpbuf,255,t)) {
  11176.         len = strlen(tmpbuf);
  11177.         if (len > 0 && tmpbuf[len-1] == '\n') {
  11178.         current++;
  11179.         debug(F111,"z_line read",ckitoa(len),current);
  11180.         } else if (len == 0) {
  11181.         return(z_error = FX_UNK);
  11182.         }
  11183.     } else {
  11184.         z_file[channel].z_nline = -1L;
  11185.         debug(F101,"z_line premature EOF","",current);
  11186.         return(z_error = FX_EOF);
  11187.     }
  11188.     }
  11189.     z_file[channel].z_nline = current;
  11190.     debug(F101,"z_line result","",current);
  11191.     z_error = 0;
  11192.     return(current);
  11193. }
  11194.  
  11195. char *
  11196. z_getname(channel) int channel; {    /* Return name of file on channel */
  11197.     FILE * t;
  11198.     if (!z_inited) {
  11199.     z_error = FX_NOP;
  11200.     return(NULL);
  11201.     }
  11202.     if (channel >= z_maxchan) {
  11203.     z_error = FX_CHN;
  11204.     return(NULL);
  11205.     }
  11206.     if (!(t = z_file[channel].z_fp)) {
  11207.     z_error = FX_NOP;
  11208.     return(NULL);
  11209.     }
  11210.     return((char *)(z_file[channel].z_name));
  11211. }
  11212.  
  11213. int
  11214. z_getmode(channel) int channel; {    /* Return OPEN modes of channel */
  11215.     FILE * t;                /* 0 if file not open */
  11216. #ifndef NOSTAT
  11217. #ifdef NT
  11218.     struct _stat statbuf;
  11219. #else /* NT */
  11220.     struct stat statbuf;
  11221. #endif /* NT */
  11222. #endif /* NOSTAT */
  11223.     int x;
  11224.     if (!z_inited)
  11225.       return(0);
  11226.     if (channel >= z_maxchan)
  11227.       return(z_error = FX_CHN);
  11228.     if (!(t = z_file[channel].z_fp))
  11229.       return(0);
  11230.     x = z_file[channel].z_flags;
  11231.     if (feof(t)) {            /* This might not work for */
  11232.     x |= FM_EOF;            /* output files */
  11233. #ifndef NOSTAT
  11234.     /* But this does if we can use it. */
  11235.     } else if (stat(z_file[channel].z_name,&statbuf) > -1) {
  11236.     if (ftell(t) == statbuf.st_size)
  11237.       x |= FM_EOF;
  11238. #endif /* NOSTAT */
  11239.     }
  11240.     return(x);
  11241. }
  11242.  
  11243. long
  11244. z_getpos(channel) int channel; {    /* Get file pointer position */
  11245.     FILE * t;                /* on this channel */
  11246.     long x;
  11247.     if (!z_inited)
  11248.       return(z_error = FX_NOP);
  11249.     if (channel >= z_maxchan)
  11250.       return(z_error = FX_CHN);
  11251.     if (!(t = z_file[channel].z_fp))
  11252.       return(z_error = FX_NOP);
  11253.     x = ftell(t);
  11254.     return((x < 0L) ? (z_error = FX_SYS) : x);
  11255. }
  11256.  
  11257. long
  11258. z_getline(channel) int channel; {    /* Get current line number */
  11259.     FILE * t;                /* in file on this channel */
  11260.     long rc;
  11261.     if (!z_inited)
  11262.       return(z_error = FX_NOP);
  11263.     if (channel >= z_maxchan)
  11264.       return(z_error = FX_CHN);
  11265.     if (!(t = z_file[channel].z_fp))
  11266.       return(z_error = FX_NOP);
  11267.     debug(F101,"z_getline","",z_file[channel].z_nline);
  11268.     rc = z_file[channel].z_nline;
  11269.     return((rc < 0) ? (z_error = FX_LNU) : rc);
  11270. }
  11271.  
  11272. int
  11273. z_getfnum(channel) int channel; {    /* Get file number / handle */
  11274.     FILE * t;                /* for file on this channel */
  11275.     if (!z_inited)
  11276.       return(z_error = FX_NOP);
  11277.     if (channel >= z_maxchan)
  11278.       return(z_error = FX_CHN);
  11279.     if (!(t = z_file[channel].z_fp))
  11280.       return(z_error = FX_NOP);
  11281.     z_error = 0;
  11282.     return(fileno(t));
  11283. }
  11284.  
  11285. /*
  11286.   Line-oriented counts and seeks are as dumb as they can be at the moment.
  11287.   Later we can speed them up by building little indexes.
  11288. */
  11289. long
  11290. z_count(channel, what) int channel, what; { /* Count bytes or lines in file */
  11291.     FILE * t;
  11292.     int i, x;
  11293.     long pos, count = 0L;
  11294.     if (!z_inited)            /* Check stuff... */
  11295.       return(z_error = FX_NOP);
  11296.     if (channel >= z_maxchan)
  11297.       return(z_error = FX_CHN);
  11298.     if (!(t = z_file[channel].z_fp))
  11299.       return(z_error = FX_NOP);
  11300.     pos = ftell(t);            /* Save current file pointer */
  11301.     errno = 0;
  11302.     z_error = 0;
  11303.     if (what == RD_CHAR) {        /* Size in bytes requested */
  11304.     if (!fseek(t,0L,2)) {        /* Seek to end */
  11305.         count = ftell(t);        /* Get file pointer */
  11306.         fseek(t,pos,0);        /* Restore file file pointer */
  11307.         return(count);
  11308.     } else                /* Fallback in case seek fails */
  11309.       return(zgetfs(z_file[channel].z_name));
  11310.     }
  11311.     rewind(t);                /* Line count requested - rewind. */
  11312.     while (1) {                /* Count lines. */
  11313.     if ((x = getc(t)) == EOF)    /* Stupid byte loop */
  11314.       break;            /* but it works as well as anything */
  11315.     if (x == '\n')            /* else... */
  11316.       count++;
  11317.     }
  11318.     x = fseek(t,pos,0);            /* Restore file pointer */
  11319.     return(count);
  11320. }
  11321.  
  11322. /* User interface for generalized channel-oriented file i/o */
  11323.  
  11324. struct keytab fctab[] = {        /* FILE subcommands */
  11325.     { "close",      FIL_CLS, 0 },
  11326.     { "count",      FIL_COU, 0 },
  11327.     { "flush",      FIL_FLU, 0 },
  11328.     { "list",       FIL_LIS, 0 },
  11329.     { "open",       FIL_OPN, 0 },
  11330.     { "read",       FIL_REA, 0 },
  11331.     { "rewind",     FIL_REW, 0 },
  11332.     { "seek",       FIL_SEE, 0 },
  11333.     { "status",     FIL_STA, 0 },
  11334.     { "write",      FIL_WRI, 0 }
  11335. };
  11336. int nfctab = (sizeof (fctab) / sizeof (struct keytab));
  11337.  
  11338. static struct keytab fcswtab[] = {    /* OPEN modes */
  11339.     { "/append",    FM_APP,  0 },
  11340.     { "/binary",    FM_BIN,  0 },
  11341. #ifdef COMMENT
  11342.     { "/command",   FM_CMD,  0 },    /* Not implemented */
  11343. #endif /* COMMENT */
  11344.     { "/read",      FM_REA,  0 },
  11345.     { "/write",     FM_WRI,  0 }
  11346. };
  11347. static int nfcswtab = (sizeof (fcswtab) / sizeof (struct keytab));
  11348.  
  11349. static struct keytab fclkwtab[] = {    /* CLOSE options */
  11350.     { "all",        1,       0 }
  11351. };
  11352.  
  11353. static struct keytab fsekwtab[] = {    /* SEEK symbols */
  11354.     { "eof",        1,       0 },
  11355.     { "last",       2,       0 }
  11356. };
  11357. static int nfsekwtab = (sizeof (fsekwtab) / sizeof (struct keytab));
  11358.  
  11359. #define SEE_LINE  RD_LINE        /* SEEK options */
  11360. #define SEE_CHAR  RD_CHAR
  11361. #define SEE_REL   3
  11362. #define SEE_ABS   4
  11363.  
  11364. static struct keytab fskswtab[] = {
  11365.     { "/absolute",  SEE_ABS,  0 },
  11366.     { "/byte",      SEE_CHAR, 0 },
  11367.     { "/character", SEE_CHAR, CM_INV },
  11368.     { "/line",      SEE_LINE, 0 },
  11369.     { "/relative",  SEE_REL,  0 }
  11370. };
  11371. static int nfskswtab = (sizeof (fskswtab) / sizeof (struct keytab));
  11372.  
  11373. #define COU_LINE  RD_LINE        /* COUNT options */
  11374. #define COU_CHAR  RD_CHAR
  11375. #define COU_LIS   3
  11376. #define COU_NOL   4
  11377.  
  11378. static struct keytab fcoswtab[] = {
  11379.     { "/bytes",     COU_CHAR, 0      },
  11380.     { "/characters",COU_CHAR, CM_INV },
  11381.     { "/lines",     COU_LINE, 0      },
  11382.     { "/list",      COU_LIS,  0      },
  11383.     { "/nolist",    COU_NOL,  0      },
  11384.     { "/quiet",     COU_NOL,  CM_INV }
  11385. };
  11386. static int nfcoswtab = (sizeof (fcoswtab) / sizeof (struct keytab));
  11387.  
  11388. static struct keytab frdtab[] = {    /* READ types */
  11389.     { "/block",     RD_SIZE, CM_INV|CM_ARG },
  11390.     { "/byte",      RD_CHAR, CM_INV },
  11391.     { "/character", RD_CHAR, 0      },
  11392.     { "/line",      RD_LINE, 0      },
  11393.     { "/size",      RD_SIZE, CM_ARG }
  11394. };
  11395. static int nfrdtab = (sizeof (frdtab) / sizeof (struct keytab));
  11396.  
  11397. static struct keytab fwrtab[] = {    /* WRITE types */
  11398.     { "/block",     WR_SIZE, CM_INV|CM_ARG },
  11399.     { "/byte",      WR_CHAR, CM_INV },
  11400.     { "/character", WR_CHAR, 0      },
  11401.     { "/line",      WR_LINE, 0      },
  11402.     { "/lpad",      WR_LPAD, CM_ARG },
  11403.     { "/rpad",      WR_RPAD, CM_ARG },
  11404.     { "/size",      WR_SIZE, CM_ARG },
  11405.     { "/string",    WR_STRI, 0      }
  11406. };
  11407. static int nfwrtab = (sizeof (fwrtab) / sizeof (struct keytab));
  11408.  
  11409. static char blanks[] = "\040\040\040\040"; /* Some blanks for formatting */
  11410.  
  11411. int
  11412. dofile(op) int op; {            /* Do the FILE command */
  11413.     char vnambuf[VNAML];        /* Buffer for variable names */
  11414.     char *vnp = NULL;            /* Pointer to same */
  11415.     char zfilnam[CKMAXPATH+2];
  11416.     char * p;
  11417.     struct FDB fl, sw, nu;
  11418.     long z;
  11419.     int rsize, filmode = 0, relative = -1, eofflg = 0;
  11420.     int rc, x, y, cx, n, getval, dummy, confirmed, listing = -1;
  11421.     int charflag = 0, sizeflag = 0;
  11422.     int pad = 32, wr_lpad = 0, wr_rpad = 0;
  11423.  
  11424.     if (op == XXFILE) {            /* FILE command was given */
  11425.     /* Get subcommand */
  11426.     if ((cx = cmkey(fctab,nfctab,"Operation","",xxstring)) < 0) {
  11427.         if (cx == -3) {
  11428.         printf("?File operation required\n");
  11429.         x = -9;
  11430.         }
  11431.         return(cx);
  11432.     }
  11433.     } else {                /* Shorthand command was given */
  11434.     switch (op) {
  11435.       case XXF_CL: cx = FIL_CLS; break; /* FCLOSE */
  11436.       case XXF_FL: cx = FIL_FLU; break; /* FFLUSH */
  11437.       case XXF_LI: cx = FIL_LIS; break; /* FLIST */
  11438.       case XXF_OP: cx = FIL_OPN; break; /* etc... */
  11439.       case XXF_RE: cx = FIL_REA; break;
  11440.       case XXF_RW: cx = FIL_REW; break;
  11441.       case XXF_SE: cx = FIL_SEE; break;
  11442.       case XXF_ST: cx = FIL_STA; break;
  11443.       case XXF_WR: cx = FIL_WRI; break;
  11444.       case XXF_CO: cx = FIL_COU; break;
  11445.       default: return(-2);
  11446.     }
  11447.     }
  11448.     switch (cx) {            /* Do requested subcommand */
  11449.       case FIL_OPN:            /* OPEN */
  11450.     cmfdbi(&sw,            /* Switches */
  11451.            _CMKEY,            /* fcode */
  11452.            "Variable or switch",    /* hlpmsg */
  11453.            "",            /* default */
  11454.            "",            /* addtl string data */
  11455.            nfcswtab,        /* addtl numeric data 1: tbl size */
  11456.            4,            /* addtl numeric data 2: 4 = cmswi */
  11457.            xxstring,        /* Processing function */
  11458.            fcswtab,            /* Keyword table */
  11459.            &fl            /* Pointer to next FDB */
  11460.            );
  11461.     cmfdbi(&fl,            /* Anything that doesn't match */
  11462.            _CMFLD,            /* fcode */
  11463.            "Variable",        /* hlpmsg */
  11464.            "",
  11465.            "",
  11466.            0,
  11467.            0,
  11468.            NULL,
  11469.            NULL,
  11470.            NULL
  11471.            );
  11472.     while (1) {
  11473.         x = cmfdb(&sw);        /* Parse something */
  11474.         if (x < 0) {
  11475.         if (x == -3) {
  11476.             printf("?Variable name and file name required\n");
  11477.             x = -9;
  11478.         }
  11479.         return(x);
  11480.         }
  11481.         if (cmresult.fcode == _CMFLD)
  11482.           break;
  11483.         else if (cmresult.fcode == _CMKEY) {
  11484.         char c;
  11485.         c = cmgbrk();
  11486.         if ((getval =
  11487.              (c == ':' || c == '=')) && !(cmgkwflgs() & CM_ARG)) {
  11488.             printf("?This switch does not take an argument\n");
  11489.             return(-9);
  11490.         }
  11491. #ifdef COMMENT
  11492.         /* Uncomment if we add any switches ere that take args */
  11493.         if (!getval && (cmgkwflgs() & CM_ARG)) {
  11494.             printf("?This switch requires an argument\n");
  11495.             return(-9);        /* (none do...) */
  11496.         }
  11497. #endif /* COMMENT */
  11498.         filmode |= cmresult.nresult; /* OR in the file mode */
  11499.         } else
  11500.           return(-2);
  11501.     }
  11502.     /* Not a switch - get the string */
  11503.     ckstrncpy(vnambuf,cmresult.sresult,VNAML);
  11504.     if (!vnambuf[0] || chknum(vnambuf)) { /* (if there is one...) */
  11505.         printf("?Variable name required\n");
  11506.         return(-9);
  11507.     }
  11508.     vnp = vnambuf;            /* Check variable-name syntax */
  11509.     if (vnambuf[0] == CMDQ &&
  11510.         (vnambuf[1] == '%' || vnambuf[1] == '&'))
  11511.       vnp++;
  11512.     y = 0;
  11513.     if (*vnp == '%' || *vnp == '&') {
  11514.         if ((y = parsevar(vnp,&x,&dummy)) < 0) {
  11515.         printf("?Syntax error in variable name\n");
  11516.         return(-9);
  11517.         }
  11518.     }
  11519.     if (!(filmode & FM_RWA))    /* If no access mode specified */
  11520.       filmode |= FM_REA;        /* default to /READ. */
  11521.  
  11522.     y = 0;                /* Now parse the filename */
  11523.     if ((filmode & FM_RWA) == FM_WRI)
  11524.       x = cmofi("Name of new file","",&s,xxstring);
  11525.     else if ((filmode & FM_RWA) == FM_REA)
  11526.       x = cmifi("Name of existing file","",&s,&y,xxstring);
  11527.     else {
  11528.         x = cmiofi("Filename","",&s,&y,xxstring);
  11529.         debug(F101,"fopen /append x","",x);
  11530.     }
  11531.     if (x == -9) {
  11532.         if (zchko(s) < 0) {
  11533.         printf("Can't create \"%s\"\n",s);
  11534.         return(x);
  11535.         }
  11536.     } else if (x < 0) {
  11537.         if (x == -3) {
  11538.         printf("?Filename required\n");
  11539.         x = -9;
  11540.         }
  11541.         return(x);
  11542.     }
  11543.     if (y) {            /* No wildcards */
  11544.         printf("?Wildcards not allowed here\n");
  11545.         return(-9);
  11546.     }
  11547.     if (filmode & (FM_APP|FM_WRI)) { /* Check output access */
  11548.         if (zchko(s) < 0) {         /* and set error code if denied */
  11549.         z_error = FX_ACC;
  11550.         printf("?Write access denied - \"%s\"\n",s);
  11551.         return(-9);
  11552.         }
  11553.     }
  11554.     ckstrncpy(zfilnam,s,CKMAXPATH);    /* Is OK - make safe copy */
  11555.     if ((x = cmcfm()) < 0)        /* Get confirmation of command */
  11556.       return(x);
  11557.     if ((n = z_open(zfilnam,filmode)) < 0) {
  11558.         printf("?OPEN failed - %s: %s\n",zfilnam,ckferror(n));
  11559.         return(-9);
  11560.     }
  11561.     addmac(vnambuf,ckitoa(n));    /* Assign channel number to variable */
  11562.     return(success = 1);
  11563.  
  11564.       case FIL_REW:            /* REWIND */
  11565.     if ((x = cmnum("Channel number","",10,&n, xxstring)) < 0) {
  11566.         if (x == -3) {
  11567.         printf("?Channel number required\n");
  11568.         x = -9;
  11569.         }
  11570.         return(x);
  11571.     }
  11572.     if ((x = cmcfm()) < 0)
  11573.       return(x);
  11574.     if ((rc = z_seek(n,0L)) < 0) {
  11575.         printf("?REWIND failed - Channel %d: %s\n",n,ckferror(rc));
  11576.         return(-9);
  11577.     }
  11578.     return(success = 1);
  11579.  
  11580.       case FIL_CLS:            /* CLOSE */
  11581.       cmfdbi(&sw,            /* Second FDB - switches */
  11582.          _CMKEY,        /* fcode */
  11583.          "Channel number; or keyword",
  11584.          "",
  11585.          "",            /* addtl string data */
  11586.          1,            /* addtl numeric data 1: tbl size */
  11587.          0,            /* addtl numeric data 2: 4 = cmswi */
  11588.          xxstring,        /* Processing function */
  11589.          fclkwtab,        /* Keyword table */
  11590.          &nu            /* Pointer to next FDB */
  11591.          );
  11592.       cmfdbi(&nu,            /* First FDB - command switches */
  11593.          _CMNUM,        /* fcode */
  11594.          "",
  11595.          "",            /* default */
  11596.          "",            /* addtl string data */
  11597.          10,            /* addtl numeric data 1: radix */
  11598.          0,            /* addtl numeric data 2: 0 */
  11599.          xxstring,        /* Processing function */
  11600.          NULL,            /* Keyword table */
  11601.          NULL            /* Pointer to next FDB */
  11602.          );            /*  */
  11603.     x = cmfdb(&sw);            /* Parse something */
  11604.     if (x < 0) {
  11605.         if (x == -3) {
  11606.         printf("?Channel number or ALL required\n");
  11607.         x = -9;
  11608.         }
  11609.         return(x);
  11610.     }
  11611.     if (cmresult.fcode == _CMNUM)
  11612.       n = cmresult.nresult;
  11613.     else if (cmresult.fcode == _CMKEY)
  11614.       n = -1;
  11615.     if ((x = cmcfm()) < 0)
  11616.       return(x);
  11617.     rc = 1;
  11618.     if (n < 0) {
  11619.         int count = 0;
  11620.         int i;
  11621.         for (i = 0; i < z_maxchan; i++) {
  11622.         x = z_close(i);
  11623.         if (x == FX_SYS) {
  11624.             printf("?CLOSE failed - Channel %d: %s\n",n,ckferror(x));
  11625.             rc = 0;
  11626.         } else if (x > -1)
  11627.           count++;
  11628.         }
  11629.         debug(F101,"FILE CLOSE ALL","",count);
  11630.     } else if ((x = z_close(n)) < 0) {
  11631.         printf("?CLOSE failed - Channel %d: %s\n",n,ckferror(x));
  11632.         return(-9);
  11633.     }
  11634.     return(success = rc);
  11635.  
  11636.       case FIL_REA:            /* READ */
  11637.       case FIL_WRI:            /* WRITE */
  11638.     rsize = 0;
  11639.     cmfdbi(&sw,            /* Switches */
  11640.            _CMKEY,            /* fcode */
  11641.            "Channel or switch",    /* hlpmsg */
  11642.            "",            /* default */
  11643.            "",            /* addtl string data */
  11644.            (cx == FIL_REA) ? nfrdtab : nfwrtab,
  11645.            4,            /* addtl numeric data 2: 4 = cmswi */
  11646.            xxstring,        /* Processing function */
  11647.            (cx == FIL_REA) ? frdtab : fwrtab, /* Keyword table */
  11648.            &nu            /* Pointer to next FDB */
  11649.            );
  11650.     cmfdbi(&nu,            /* Channel number */
  11651.            _CMNUM,            /* fcode */
  11652.            "Channel",
  11653.            "",            /* default */
  11654.            "",            /* addtl string data */
  11655.            10,            /* addtl numeric data 1: radix */
  11656.            0,            /* addtl numeric data 2: 0 */
  11657.            xxstring,        /* Processing function */
  11658.            NULL,            /* Keyword table */
  11659.            NULL            /* Pointer to next FDB */
  11660.            );
  11661.     do {
  11662.         x = cmfdb(&sw);        /* Parse something */
  11663.         if (x < 0) {
  11664.         if (x == -3) {
  11665.             printf("?Channel number required\n");
  11666.             x = -9;
  11667.         }
  11668.         return(x);
  11669.         }
  11670.         if (cmresult.fcode == _CMNUM) /* Channel number */
  11671.           break;
  11672.         else if (cmresult.fcode == _CMKEY) { /* Switch */
  11673.         char c;
  11674.         c = cmgbrk();
  11675.         if ((getval =
  11676.              (c == ':' || c == '=')) && !(cmgkwflgs() & CM_ARG)) {
  11677.             printf("?This switch does not take an argument\n");
  11678.             return(-9);
  11679.         }
  11680.         if (!getval && (cmgkwflgs() & CM_ARG)) {
  11681.             printf("?This switch requires an argument\n");
  11682.             return(-9);
  11683.         }
  11684.         switch (cmresult.nresult) {
  11685.           case WR_LINE:
  11686.             charflag = 0;
  11687.             sizeflag = 0;
  11688.             rsize = 0;
  11689.             break;
  11690.           case WR_CHAR:
  11691.             rsize = 1;
  11692.             charflag = 1;
  11693.             sizeflag = 1;
  11694.             break;
  11695.           case WR_SIZE:
  11696.             if ((x = cmnum("Bytes","",10,&rsize, xxstring)) < 0) {
  11697.             if (x == -3) {
  11698.                 printf("?Number required\n");
  11699.                 x = -9;
  11700.             }
  11701.             return(x);
  11702.             }
  11703.             charflag = 0;
  11704.             sizeflag = 1;
  11705.             break;
  11706.           case WR_STRI:
  11707.             rsize = 1;
  11708.             charflag = 0;
  11709.             sizeflag = 0;
  11710.             break;
  11711.           case WR_LPAD:
  11712.           case WR_RPAD:
  11713.             if ((x = cmnum("Numeric ASCII character value",
  11714.                    "32",10,&pad, xxstring)) < 0)
  11715.               return(x);
  11716.             if (cmresult.nresult == WR_LPAD)
  11717.               wr_lpad = 1;
  11718.             else
  11719.               wr_rpad = 1;
  11720.             break;
  11721.         }
  11722.         debug(F101,"FILE READ rsize 2","",rsize);
  11723.         } else
  11724.           return(-2);
  11725.     } while
  11726.       (cmresult.fcode == _CMKEY);
  11727.  
  11728.     n = cmresult.nresult;        /* Channel */
  11729.     debug(F101,"FILE READ/WRITE channel","",n);
  11730.  
  11731.     if (cx == FIL_WRI) {        /* WRITE */
  11732.         int len = 0;
  11733.         if ((x = cmtxt("Text","",&s,xxstring)) < 0)
  11734.           return(x);
  11735.         ckstrncpy(line,s,LINBUFSIZ); /* Make a safe copy */
  11736.         s = line;
  11737.         s = brstrip(s);        /* Strip braces */
  11738.         if (charflag) {        /* Write one char */
  11739.         len = 1;        /* So length = 1 */
  11740.         rsize = 1;        /* Don't supply terminator */
  11741.         } else if (!sizeflag) {    /* Write a string */
  11742.         len = -1;        /* So length is unspecified */
  11743.         } else {            /* Write a block of given size */
  11744.         int i, k, xx;
  11745.         if (rsize > TMPBUFSIZ) {
  11746.             z_error = FX_OFL;
  11747.             printf("?Buffer overflow\n");
  11748.             return(-9);
  11749.         }
  11750.         len = rsize;        /* rsize is really length */
  11751.         rsize = 1;        /* Don't supply a terminator */
  11752.         xx = strlen(s);        /* Size of given string */
  11753.         if (xx >= len) {    /* Bigger or equal */
  11754.             s[len] = NUL;
  11755.         } else if (wr_lpad) {    /* Smaller, left-padding requested */
  11756.             for (i = 0; i < len - xx; i++) /* Must make a copy */
  11757.               tmpbuf[i] = pad;
  11758.             ckstrncpy(tmpbuf+i,s,TMPBUFSIZ-i);
  11759.             tmpbuf[len] = NUL;
  11760.             s = tmpbuf;        /* Redirect write source */
  11761.         } else if (wr_rpad) {    /* Smaller with right-padding */
  11762.             for (i = xx; i < len; i++)
  11763.               s[i] = pad;
  11764.             s[len] = NUL;
  11765.         }
  11766.         }
  11767.         if ((rc = z_out(n,s,len,rsize)) < 0) { /* Try to write */
  11768.         printf("?Channel %d WRITE error: %s\n",n,ckferror(rc));
  11769.         return(-9);
  11770.         }
  11771.     } else {            /* FIL_REA READ */
  11772.         confirmed = 0;
  11773.         vnambuf[0] = NUL;
  11774.         x = cmfld("Variable name","",&s,NULL);
  11775.         debug(F111,"FILE READ cmfld",s,x);
  11776.         if (x < 0) {
  11777.         if (x == -3 || !*s) {
  11778.             if ((x = cmcfm()) < 0)
  11779.               return(x);
  11780.             else
  11781.               confirmed++;
  11782.         } else
  11783.           return(x);
  11784.         }
  11785.         ckstrncpy(vnambuf,s,VNAML);
  11786.         debug(F111,"FILE READ vnambuf",vnambuf,confirmed);
  11787.         if (vnambuf[0]) {        /* Variable name given, check it */
  11788.         if (!confirmed) {
  11789.             x = cmcfm();
  11790.             if (x < 0)
  11791.               return(x);
  11792.             else
  11793.               confirmed++;
  11794.         }
  11795.         vnp = vnambuf;
  11796.         if (vnambuf[0] == CMDQ &&
  11797.             (vnambuf[1] == '%' || vnambuf[1] == '&'))
  11798.           vnp++;
  11799.         y = 0;
  11800.         if (*vnp == '%' || *vnp == '&') {
  11801.             if ((y = parsevar(vnp,&x,&dummy)) < 0) {
  11802.             printf("?Syntax error in variable name\n");
  11803.             return(-9);
  11804.             }
  11805.         }
  11806.         }
  11807.         debug(F111,"FILE READ variable",vnambuf,confirmed);
  11808.  
  11809.         if (!confirmed)
  11810.           if ((x = cmcfm()) < 0)
  11811.         return(x);
  11812.  
  11813.         line[0] = NUL;        /* Clear destination buffer */
  11814.         if (rsize >= LINBUFSIZ)    /* Don't overrun it */
  11815.           rsize = LINBUFSIZ - 1;
  11816.  
  11817.         if (rsize == 0)        /* Read a line */
  11818.           rc = z_in(n,line,LINBUFSIZ,LINBUFSIZ-1,0);
  11819.         else
  11820.           rc = z_in(n,line,LINBUFSIZ,rsize,1); /* Read a block */
  11821.         if (rc < 0) {        /* Error... */
  11822.         debug(F101,"FILE READ error","",rc);
  11823.         debug(F101,"FILE READ errno","",errno);
  11824.         if (rc == FX_EOF) {    /* EOF - fail but no error message */
  11825.             return(success = 0);
  11826.         } else {        /* Other error - fail and print msg */
  11827.             printf("?READ error: %s\n",ckferror(rc));
  11828.             return(-9);
  11829.         }
  11830.         }
  11831.         debug(F110,"FILE READ data",line,0);
  11832.         if (vnambuf[0])        /* Read OK - If variable name given */
  11833.           addmac(vnambuf,line);    /* Assign result to variable */
  11834.         else            /* otherwise */
  11835.           printf("%s\n",line);    /* just print it */
  11836.     }
  11837.     return(success = 1);
  11838.  
  11839.       case FIL_SEE:            /* SEEK */
  11840.       case FIL_COU:            /* COUNT */
  11841.     rsize = RD_CHAR;        /* Defaults to /BYTE */
  11842.     cmfdbi(&sw,            /* Switches */
  11843.            _CMKEY,            /* fcode */
  11844.            "Channel or switch",    /* hlpmsg */
  11845.            "",            /* default */
  11846.            "",            /* addtl string data */
  11847.            ((cx == FIL_SEE) ? nfskswtab : nfcoswtab),
  11848.            4,            /* addtl numeric data 2: 4 = cmswi */
  11849.            xxstring,        /* Processing function */
  11850.            ((cx == FIL_SEE) ? fskswtab : fcoswtab),
  11851.            &nu            /* Pointer to next FDB */
  11852.            );
  11853.     cmfdbi(&nu,            /* Channel number */
  11854.            _CMNUM,            /* fcode */
  11855.            "Channel",
  11856.            "",            /* default */
  11857.            "",            /* addtl string data */
  11858.            10,            /* addtl numeric data 1: radix */
  11859.            0,            /* addtl numeric data 2: 0 */
  11860.            xxstring,        /* Processing function */
  11861.            NULL,            /* Keyword table */
  11862.            NULL            /* Pointer to next FDB */
  11863.            );
  11864.     do {
  11865.         x = cmfdb(&sw);        /* Parse something */
  11866.         if (x < 0) {
  11867.         if (x == -3) {
  11868.             printf("?Channel number required\n");
  11869.             x = -9;
  11870.         }
  11871.         return(x);
  11872.         }
  11873.         if (cmresult.fcode == _CMNUM) /* Channel number */
  11874.           break;
  11875.         else if (cmresult.fcode == _CMKEY) { /* Switch */
  11876.         char c;
  11877.         c = cmgbrk();
  11878.         if ((getval =
  11879.              (c == ':' || c == '=')) && !(cmgkwflgs() & CM_ARG)) {
  11880.             printf("?This switch does not take an argument\n");
  11881.             return(-9);
  11882.         }
  11883.         if (cx == FIL_SEE) {
  11884.             switch (cmresult.nresult) {
  11885.               case SEE_REL: relative = 1; break;
  11886.               case SEE_ABS: relative = 0; break;
  11887.               default: rsize = cmresult.nresult;
  11888.             }
  11889.         } else if (cx == FIL_COU) {
  11890.             switch (cmresult.nresult) {
  11891.               case COU_LIS: listing = 1; break;
  11892.               case COU_NOL: listing = 0; break;
  11893.               default: rsize = cmresult.nresult;
  11894.             }
  11895.         }
  11896.         }
  11897.     } while
  11898.       (cmresult.fcode == _CMKEY);
  11899.  
  11900.     n = cmresult.nresult;        /* Channel */
  11901.     debug(F101,"FILE SEEK/COUNT channel","",n);
  11902.     if (cx == FIL_COU) {
  11903.         if ((x = cmcfm()) < 0)
  11904.           return(x);
  11905.         z_filcount = z_count(n,rsize);
  11906.         if (z_filcount < 0) {
  11907.         rc = z_filcount;
  11908.         printf("?COUNT error: %s\n",ckferror(rc));
  11909.         return(-9);
  11910.         }
  11911.         if (listing < 0)
  11912.           listing = !xcmdsrc;
  11913.         if (listing)
  11914.           printf(" %ld %s%s\n",
  11915.              z_filcount,
  11916.              ((rsize == RD_CHAR) ? "byte" : "line"),
  11917.              ((z_filcount == 1L) ? "" : "s")
  11918.              );
  11919.         return(success = (z_filcount > -1) ? 1 : 0);
  11920.     }
  11921.     cmfdbi(&sw,            /* SEEK symbolic targets (EOF) */
  11922.            _CMKEY,            /* fcode */
  11923.            "Channel number;\n or keyword",
  11924.            "",
  11925.            "",            /* addtl string data */
  11926.            nfsekwtab,        /* addtl numeric data 1: table size */
  11927.            0,            /* addtl numeric data 2: 4 = cmswi */
  11928.            xxstring,        /* Processing function */
  11929.            fsekwtab,        /* Keyword table */
  11930.            &nu            /* Pointer to next FDB */
  11931.            );
  11932.     cmfdbi(&nu,            /* Channel number */
  11933.            _CMNUM,            /* fcode */
  11934.            "",
  11935.            "",            /* default */
  11936.            "",            /* addtl string data */
  11937.            10,            /* addtl numeric data 1: radix */
  11938.            0,            /* addtl numeric data 2: 0 */
  11939.            xxstring,        /* Processing function */
  11940.            NULL,            /* Keyword table */
  11941.            NULL            /* Pointer to next FDB */
  11942.            );
  11943.     x = cmfdb(&sw);            /* Parse something */
  11944.     if (x < 0) {
  11945.         if (x == -3) {
  11946.         printf("?Channel number or EOF required\n");
  11947.         x = -9;
  11948.         }
  11949.         return(x);
  11950.     }
  11951.     if (cmresult.fcode == _CMNUM) {
  11952.         y = cmresult.nresult;
  11953.         debug(F110,"FILE SEEK atmbuf",atmbuf,0);
  11954.         if (relative < 0) {
  11955.         if (cx == FIL_SEE && (atmbuf[0] == '+' || atmbuf[0] == '-'))
  11956.           relative = 1;
  11957.         else
  11958.           relative = 0;
  11959.         }
  11960.     } else if (cmresult.fcode == _CMKEY) {
  11961.         eofflg = cmresult.nresult;
  11962.         relative = 0;
  11963.         y = 0 - eofflg;
  11964.     }
  11965.     if ((x = cmcfm()) < 0)
  11966.       return(x);
  11967.     z = y;                /* Convert to long */
  11968.     y = 1;                /* Recycle this */
  11969.     z_flush(n);
  11970.     debug(F101,"FILE SEEK relative","",relative);
  11971.     debug(F101,"FILE SEEK rsize","",rsize);
  11972.  
  11973.     if (rsize == RD_CHAR) {        /* Seek to byte position */
  11974.         if (relative > 0) {
  11975.         long pos;
  11976.         pos = z_getpos(n);
  11977.         if (pos < 0L) {
  11978.             rc = pos;
  11979.             printf("?Relative SEEK failed: %s\n",ckferror(rc));
  11980.             return(-9);
  11981.         }
  11982.         z += pos;
  11983.         } else {
  11984.         if (z < 0 && !eofflg) {    /* Negative arg but not relative */
  11985.             y = 0;        /* Remember this was bad */
  11986.             z = 0;        /* but substitute 0 */
  11987.         }
  11988.         }
  11989.         debug(F101,"FILE SEEK /CHAR z","",z);
  11990.         if (z < 0 && !eofflg) {
  11991.         z_error = FX_RNG;
  11992.         return(success = 0);
  11993.         }
  11994.         if ((rc = z_seek(n,z)) < 0) {
  11995.         if (rc == FX_EOF) return(success = 0);
  11996.         printf("?SEEK /BYTE failed - Channel %d: %s\n",n,ckferror(rc));
  11997.         return(-9);
  11998.         }
  11999.     } else {            /* Seek to line */
  12000.         if (relative > 0) {
  12001.         long pos;
  12002.         pos = z_getline(n);
  12003.         debug(F101,"FILE SEEK /LINE pos","",pos);
  12004.         if (pos < 0L) {
  12005.             rc = pos;
  12006.             printf("?Relative SEEK failed: %s\n",ckferror(rc));
  12007.             return(-9);
  12008.         }
  12009.         z += pos;
  12010.         }
  12011.         debug(F101,"FILE SEEK /LINE z","",z);
  12012.         debug(F101,"FILE SEEK /LINE eofflg","",eofflg);
  12013.         if (z < 0 && !eofflg) {
  12014.         z_error = FX_RNG;
  12015.         return(success = 0);
  12016.         }
  12017.         if ((rc = z_line(n,z)) < 0) {
  12018.         if (rc == FX_EOF) return(success = 0);
  12019.         printf("?SEEK /LINE failed - Channel %d: %s\n",n,ckferror(rc));
  12020.         return(-9);
  12021.         }
  12022.     }
  12023.     return(success = y);
  12024.  
  12025.       case FIL_LIS: {            /* LIST open files */
  12026. #ifdef CK_TTGWSIZ
  12027.       extern int cmd_rows, cmd_cols;
  12028. #endif /* CK_TTGWSIZ */
  12029.           extern int xaskmore;
  12030.       int i, x, n = 0, paging = 0;
  12031.       char * s;
  12032.  
  12033.       if ((x = cmcfm()) < 0)
  12034.         return(x);
  12035.  
  12036. #ifdef CK_TTGWSIZ
  12037.       if (cmd_rows > 0 && cmd_cols > 0)
  12038. #endif /* CK_TTGWSIZ */
  12039.         paging = xaskmore;
  12040.  
  12041.       printf("System open file limit: %4d\n", z_openmax);
  12042.       printf("Maximum for FILE OPEN:  %4d\n", z_maxchan);
  12043.       printf("Files currently open:   %4d\n\n", z_nopen);
  12044.       n = 4;
  12045.       for (i = 0; i < z_maxchan; i++) {
  12046.           s = z_getname(i);        /* Got one? */
  12047.           if (s) {            /* Yes */
  12048.           char m[8];
  12049.           m[0] = NUL;
  12050.           printf("%2d. %s",i,s); /* Print name */
  12051.           n++;             /* Count it */
  12052.           x = z_getmode(i);     /* Get modes & print them */
  12053.           if (x > -1) {
  12054.               if (x & FM_REA) ckstrncat(m,"R",8);
  12055.               if (x & FM_WRI) ckstrncat(m,"W",8);
  12056.               if (x & FM_APP) ckstrncat(m,"A",8);
  12057.               if (x & FM_BIN) ckstrncat(m,"B",8);
  12058.               if (m[0])
  12059.             printf(" (%s)",m);
  12060.               if (x & FM_EOF)
  12061.             printf(" [EOF]");
  12062.               else
  12063.             printf(" %ld",z_getpos(i)); /* And file position too */
  12064.           }
  12065.           printf("\n");
  12066. #ifdef CK_TTGWSIZ
  12067.           if (paging > 0) {    /* Pause at end of screen */
  12068.               if (n > cmd_rows - 3) {
  12069.               if (!askmore())
  12070.                 break;
  12071.               else
  12072.                 n = 0;
  12073.               }
  12074.           }
  12075. #endif /* CK_TTGWSIZ */
  12076.           }
  12077.       }
  12078.       return(success = 1);
  12079.       }
  12080.  
  12081.       case FIL_FLU:            /* FLUSH */
  12082.     if ((x = cmnum("Channel number","",10,&n, xxstring)) < 0) {
  12083.         if (x == -3) {
  12084.         printf("?Channel number required\n");
  12085.         x = -9;
  12086.         }
  12087.         return(x);
  12088.     }
  12089.     if ((x = cmcfm()) < 0)
  12090.       return(x);
  12091.     if ((rc = z_flush(n)) < 0) {
  12092.         printf("?FLUSH failed - Channel %d: %s\n",n,ckferror(rc));
  12093.         return(-9);
  12094.     }
  12095.     return(success = 1);
  12096.  
  12097.       case FIL_STA:            /* STATUS */
  12098.     if ((x = cmnum("Channel number","",10,&n, xxstring)) < 0) {
  12099.         if (x == -3) {
  12100.         printf("?Channel number required\n");
  12101.         x = -9;
  12102.         }
  12103.         return(x);
  12104.     }
  12105.     if ((x = cmcfm()) < 0)
  12106.       return(x);
  12107.     p = blanks + 3;            /* Tricky formatting... */
  12108.     if (n < 1000) p--;
  12109.     if (n < 100) p--;
  12110.     if (n < 10) p--;
  12111.     if ((rc = z_getmode(n)) < 0) {
  12112.         printf("Channel %d:%s%s\n",n,p,ckferror(rc));
  12113.         return(success = 0);
  12114.     } else if (!rc) {
  12115.         printf("Channel %d:%sNot open\n",n,p);
  12116.         return(success = 0);
  12117.     } else {
  12118.         long xx;
  12119.         s = z_getname(n);
  12120.         if (!s) s = "(name unknown)";
  12121.         printf("Channel %d:%sOpen\n",n,p);
  12122.         printf(" File:        %s\n Modes:      ",s);
  12123.         if (rc & FM_REA) printf(" /READ");
  12124.         if (rc & FM_WRI) printf(" /WRITE");
  12125.         if (rc & FM_APP) printf(" /APPEND");
  12126.         if (rc & FM_BIN) printf(" /BINARY");
  12127.         if (rc & FM_CMD) printf(" /COMMAND");
  12128.         if (rc & FM_EOF) printf(" [EOF]");
  12129.         printf("\n Size:        %ld\n",z_count(n,RD_CHAR));
  12130.         printf(" At byte:     %ld\n",z_getpos(n));
  12131.         xx = z_getline(n);
  12132.         if (xx > -1)
  12133.           printf(" At line:     %ld\n",xx);
  12134.         return(success = 1);
  12135.     }
  12136.       default:
  12137.     return(-2);
  12138.     }
  12139. }
  12140. #endif /* CKCHANNELIO */
  12141.  
  12142. #ifndef NOSETKEY
  12143. /* Save Key maps and in OS/2 Mouse maps */
  12144. int
  12145. savkeys(name,disp) char * name; int disp; {
  12146.     char *tp;
  12147.     static struct filinfo xx;
  12148.     int savfil, i, j, k;
  12149.     char buf[1024];
  12150.  
  12151.     zclose(ZMFILE);
  12152.  
  12153.     if (disp) {
  12154.     xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  12155.     xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = "";
  12156.     xx.lblopts = 0;
  12157.     savfil = zopeno(ZMFILE,name,NULL,&xx);
  12158.     } else savfil = zopeno(ZMFILE,name,NULL,NULL);
  12159.  
  12160.     if (savfil) {
  12161. #ifdef OS2
  12162.     ztime(&tp);
  12163.     zsout(ZMFILE, "; Kermit 95 SAVE KEYMAP file: ");
  12164.     zsoutl(ZMFILE,tp);
  12165.     if (mskkeys) {
  12166.         zsoutl(ZMFILE,
  12167.      "if eq \"\\v(program)\" \"C-Kermit\" set mskermit keycodes on");
  12168.     } else {
  12169.         zsoutl(ZMFILE,
  12170.          "if NOT eq \"\\v(program)\" \"C-Kermit\" stop 1 C-Kermit required.");
  12171.         zsoutl(ZMFILE,"set mskermit keycodes off");
  12172.     }
  12173.     zsoutl(ZMFILE,"");
  12174. #else /* OS2 */
  12175.     ztime(&tp);
  12176.     zsout(ZMFILE, "; C-Kermit SAVE KEYMAP file: ");
  12177.     zsoutl(ZMFILE,tp);
  12178. #endif /* OS2 */
  12179.  
  12180.     zsoutl(ZMFILE,"; Clear previous keyboard mappings ");
  12181.     zsoutl(ZMFILE,"set key clear");
  12182. #ifdef OS2
  12183.     for (k = 0; k < nttkey; k++) {
  12184.         if (!ttkeytab[k].flgs) {
  12185.         ckmakmsg(buf,1024,
  12186.              "set terminal key ",
  12187.              ttkeytab[k].kwd,
  12188.              " clear",
  12189.              NULL
  12190.              );
  12191.         zsoutl(ZMFILE,buf);
  12192.         }
  12193.     }
  12194. #endif /* OS2 */
  12195.     zsoutl(ZMFILE,"");
  12196.  
  12197.     for (i = 0; i < KMSIZE; i++) {
  12198.         if (macrotab[i]) {
  12199.         int len = strlen((char *)macrotab[i]);
  12200. #ifdef OS2
  12201.         ckmakmsg(buf,
  12202.              1024,
  12203.              "set key \\",
  12204.              ckitoa(mskkeys ? cktomsk(i) : i),
  12205.              " ",
  12206.              NULL
  12207.              );
  12208. #else /* OS2 */
  12209.         ckmakmsg(buf,
  12210.              1024,
  12211.              "set key \\",
  12212.              ckitoa(i),
  12213.              NULL,NULL
  12214.              );
  12215. #endif /* OS2 */
  12216.         zsout(ZMFILE,buf);
  12217.  
  12218.         for (j = 0; j < len; j++) {
  12219.             char ch = macrotab[i][j];
  12220.             if (ch <= SP || ch >= DEL ||
  12221.              ch == '-' || ch == ',' ||
  12222.                          ch == '{' || ch == '}' ||
  12223.                          ch == ';' || ch == '?' ||
  12224.                          ch == '.' || ch == '\'' ||
  12225.                          ch == '\\' || ch == '/' ||
  12226.                          ch == '#') {
  12227.             ckmakmsg(buf,1024,"\\{",ckitoa((int)ch),"}",NULL);
  12228.             zsout(ZMFILE,buf);
  12229.             } else {
  12230.             ckmakmsg(buf,1024,ckctoa((char)ch),NULL,NULL,NULL);
  12231.             zsout(ZMFILE,buf);
  12232.             }
  12233.         }
  12234. #ifdef OS2
  12235.         ckmakmsg(buf,1024,"\t; ",keyname(i),NULL,NULL);
  12236.         zsoutl(ZMFILE,buf);
  12237. #else
  12238.         zsoutl(ZMFILE,"");
  12239. #endif /* OS2 */
  12240.         } else if ( keymap[i] != i ) {
  12241. #ifndef NOKVERBS
  12242.         if (IS_KVERB(keymap[i])) {
  12243.             for (j = 0; j < nkverbs; j++)
  12244.               if (kverbs[j].kwval == (keymap[i] & ~F_KVERB))
  12245.             break;
  12246.             if (j != nkverbs) {
  12247. #ifdef OS2
  12248. #ifdef COMMENT
  12249.             sprintf(buf, "set key \\%d \\K%s\t; %s",
  12250.                 mskkeys ? cktomsk(i) : i,
  12251.                 kverbs[j].kwd, keyname(i)
  12252.                 );
  12253. #else
  12254.             ckmakxmsg(buf,    /* 12 string args */
  12255.                   1024,
  12256.                   "set key \\",
  12257.                   ckitoa(mskkeys ? cktomsk(i) : i),
  12258.                   " \\K",
  12259.                   kverbs[j].kwd,
  12260.                   "\t; ",
  12261.                   keyname(i),
  12262.                   NULL, NULL, NULL, NULL, NULL, NULL);
  12263. #endif /* COMMENT */
  12264.             zsoutl(ZMFILE,buf);
  12265. #else
  12266. #ifdef COMMENT
  12267.             sprintf(buf, "set key \\%d \\K%s", i, kverbs[j].kwd);
  12268. #else
  12269.             ckmakmsg(buf,1024,
  12270.                  "set key \\",
  12271.                  ckitoa(i),
  12272.                  " \\K",
  12273.                  kverbs[j].kwd
  12274.                  );
  12275. #endif /* COMMENT */
  12276.             zsoutl(ZMFILE,buf);
  12277. #endif
  12278.             }
  12279.         } else
  12280. #endif /* NOKVERBS */
  12281.           {
  12282. #ifdef OS2
  12283. #ifdef COMMENT
  12284.               sprintf(buf, "set key \\%d \\{%d}\t; %s",
  12285.                   mskkeys ? cktomsk(i) : i,
  12286.                   keymap[i],
  12287.                   keyname(i)
  12288.                   );
  12289. #else
  12290.               ckmakxmsg(buf,    /* 8 string args */
  12291.                 1024,
  12292.                 "set key \\",
  12293.                 ckitoa(mskkeys ? cktomsk(i) : i),
  12294.                 " \\{",
  12295.                 ckitoa(keymap[i]),
  12296.                 "}\t; ",
  12297.                 keyname(i),
  12298.                 NULL,NULL,NULL,NULL,NULL,NULL);
  12299. #endif /* COMMENT */
  12300.               zsoutl(ZMFILE,buf);
  12301. #else
  12302. #ifdef COMMENT
  12303.               sprintf(buf, "set key \\%d \\{%d}", i, keymap[i]);
  12304. #else
  12305.               ckmakxmsg(buf,1024,
  12306.                    "set key \\",
  12307.                    ckitoa(i),
  12308.                    " \\{",
  12309.                    ckitoa(keymap[i]),
  12310.                    "}",
  12311.                    NULL,NULL,NULL,NULL,NULL,NULL,NULL);
  12312. #endif /* COMMENT */
  12313.               zsoutl(ZMFILE,buf);
  12314. #endif /* OS2 */
  12315.           }
  12316.         }
  12317.     }
  12318. #ifdef OS2
  12319.     /* OS/2 also has the SET TERMINAL KEY <termtype> defines */
  12320.     for (k = 0; k < nttkey; k++) {
  12321.         extern struct keynode * ttkeymap[];
  12322.         struct keynode * pnode = NULL;
  12323.  
  12324.         if (ttkeytab[k].flgs)    /* Don't process CM_INV or CM_ABR */
  12325.           continue;
  12326.  
  12327.         zsoutl(ZMFILE,"");
  12328.         ckmakmsg(buf,1024,"; SET TERMINAL KEY ",ttkeytab[k].kwd,NULL,NULL);
  12329.         zsoutl(ZMFILE,buf);
  12330.  
  12331.         for (pnode = ttkeymap[ttkeytab[k].kwval];
  12332.          pnode;
  12333.          pnode = pnode->next
  12334.          ) {
  12335.         switch (pnode->def.type) {
  12336.           case key:
  12337. #ifdef COMMENT
  12338.             sprintf(buf, "set terminal key %s \\%d \\{%d}\t; %s",
  12339.                      ttkeytab[k].kwd,
  12340.                 mskkeys ? cktomsk(pnode->key) : pnode->key,
  12341.                 pnode->def.key.scancode,
  12342.                 keyname(pnode->key)
  12343.                 );
  12344. #else
  12345.             ckmakxmsg(buf,
  12346.                   1024,
  12347.                   "set terminal key ",
  12348.                   ttkeytab[k].kwd,
  12349.                   " \\",
  12350.                   ckitoa(mskkeys ?
  12351.                      cktomsk(pnode->key) :
  12352.                      pnode->key),
  12353.                   " \\{",
  12354.                   ckitoa(pnode->def.key.scancode),
  12355.                   "}\t; ",
  12356.                   keyname(pnode->key),
  12357.                   NULL,NULL,NULL,NULL
  12358.                   );
  12359. #endif /* COMMENT */
  12360.             zsoutl(ZMFILE,buf);
  12361.             break;
  12362.           case kverb:
  12363.             for (j = 0; j < nkverbs; j++)
  12364.               if (kverbs[j].kwval == (pnode->def.kverb.id & ~F_KVERB))
  12365.             break;
  12366.             if (j != nkverbs) {
  12367. #ifdef COMMENT
  12368.             sprintf(buf, "set terminal key %s \\%d \\K%s\t; %s",
  12369.                 ttkeytab[k].kwd,
  12370.                 mskkeys ? cktomsk(pnode->key) : pnode->key,
  12371.                 kverbs[j].kwd, keyname(pnode->key)
  12372.                 );
  12373. #else
  12374.             ckmakxmsg(buf,
  12375.                   1024,
  12376.                   "set terminal key ",
  12377.                   ttkeytab[k].kwd,
  12378.                   " \\",
  12379.                   ckitoa(mskkeys ?
  12380.                      cktomsk(pnode->key) :
  12381.                      pnode->key),
  12382.                   " \\K",
  12383.                   kverbs[j].kwd,
  12384.                   "\t; ",
  12385.                   keyname(pnode->key),
  12386.                   NULL,NULL,NULL,NULL
  12387.                   );
  12388. #endif /* COMMENT */
  12389.             zsoutl(ZMFILE,buf);
  12390.             }
  12391.             break;
  12392.           case macro: {
  12393.               int len = strlen((char *)pnode->def.macro.string);
  12394. #ifdef COMMENT
  12395.               sprintf(buf,"set terminal key %s \\%d ",
  12396.                   ttkeytab[k].kwd,
  12397.                   mskkeys ? cktomsk(pnode->key) : pnode->key);
  12398. #else
  12399.               ckmakxmsg(buf,
  12400.                    1024,
  12401.                    "set terminal key ",
  12402.                    ttkeytab[k].kwd,
  12403.                    " \\",
  12404.                    ckitoa(mskkeys ?
  12405.                       cktomsk(pnode->key) :
  12406.                       pnode->key),
  12407.                    " ",
  12408.                    NULL,NULL,NULL,NULL,NULL,NULL,NULL
  12409.                   );
  12410. #endif /* COMMENT */
  12411.               zsout(ZMFILE,buf);
  12412.  
  12413.               for (j = 0; j < len; j++) {
  12414.               char ch = pnode->def.macro.string[j];
  12415.               if (ch <= SP || ch >= DEL ||
  12416.                                ch == '-' || ch == ',' ||
  12417.                                ch == '{' || ch == '}' ||
  12418.                                ch == ';' || ch == '?' ||
  12419.                                ch == '.' || ch == '\'' ||
  12420.                                ch == '\\' || ch == '/' ||
  12421.                                ch == '#') {
  12422.                   ckmakmsg(buf,1024,
  12423.                        "\\{",ckitoa((int)ch),"}",NULL);
  12424.                   zsout(ZMFILE,buf);
  12425.               } else {
  12426.                   ckmakmsg(buf,1024,
  12427.                        ckctoa((char)ch),NULL,NULL,NULL);
  12428.                   zsout(ZMFILE,buf);
  12429.               }
  12430.               }
  12431.               ckmakmsg(buf,1024,"\t; ",keyname(pnode->key),NULL,NULL);
  12432.               zsoutl(ZMFILE,buf);
  12433.               break;
  12434.           }
  12435.           case literal: {
  12436.               int len = strlen((char *)pnode->def.literal.string);
  12437. #ifdef COMMENT
  12438.               sprintf(buf,"set terminal key %s /literal \\%d ",
  12439.                   ttkeytab[k].kwd,
  12440.                   mskkeys ? cktomsk(pnode->key) : pnode->key);
  12441. #else
  12442.               ckmakxmsg(buf,
  12443.                    1024,
  12444.                    "set terminal key ",
  12445.                    ttkeytab[k].kwd,
  12446.                    " /literal \\",
  12447.                    ckitoa(mskkeys ?
  12448.                       cktomsk(pnode->key) :
  12449.                       pnode->key),
  12450.                    " ",
  12451.                    NULL,NULL,NULL,NULL,NULL,NULL,NULL);
  12452. #endif /* COMMENT */
  12453.               zsout(ZMFILE,buf);
  12454.  
  12455.               for (j = 0; j < len; j++) {
  12456.               char ch = pnode->def.literal.string[j];
  12457.               if (ch <= SP || ch >= DEL ||
  12458.                                ch == '-' || ch == ',' ||
  12459.                                ch == '{' || ch == '}' ||
  12460.                                ch == ';' || ch == '?' ||
  12461.                                ch == '.' || ch == '\'' ||
  12462.                                ch == '\\' || ch == '/' ||
  12463.                                ch == '#') {
  12464.                   ckmakmsg(buf,1024,
  12465.                        "\\{",ckitoa((int)ch),"}",NULL);
  12466.                   zsout(ZMFILE,buf);
  12467.               } else {
  12468.                   ckmakmsg(buf,1024,
  12469.                        ckctoa((char)ch),NULL,NULL,NULL);
  12470.                   zsout(ZMFILE,buf);
  12471.               }
  12472.               }
  12473.               ckmakmsg(buf,1024,"\t; ",keyname(pnode->key),NULL,NULL);
  12474.               zsoutl(ZMFILE,buf);
  12475.               break;
  12476.           }
  12477.           case esc:
  12478. #ifdef COMMENT
  12479.             sprintf(buf,
  12480.                "set terminal key %s /literal \\%d \\{%d}\\{%d}\t; %s",
  12481.                 ttkeytab[k].kwd,
  12482.                 mskkeys ? cktomsk(pnode->key) : pnode->key,
  12483.                 ISDG200(ttkeytab[k].kwval) ? 30 : 27,
  12484.                 pnode->def.esc.key & ~F_ESC,
  12485.                 keyname(pnode->key)
  12486.                 );
  12487. #else
  12488.             ckmakxmsg(buf,
  12489.                   1024,
  12490.                   "set terminal key ",
  12491.                   ttkeytab[k].kwd,
  12492.                   " /literal \\",
  12493.                   ckitoa(mskkeys ?
  12494.                      cktomsk(pnode->key) :
  12495.                      pnode->key),
  12496.                   " \\{",
  12497.                   ckitoa(ISDG200(ttkeytab[k].kwval) ? 30 : 27),
  12498.                   "}\\{",
  12499.                   ckitoa(pnode->def.esc.key & ~F_ESC),
  12500.                   "}\t; ",
  12501.                   keyname(pnode->key),
  12502.                   NULL,NULL
  12503.                   );
  12504. #endif /* COMMENT */
  12505.             zsoutl(ZMFILE,buf);
  12506.             break;
  12507.           case csi:
  12508. #ifdef COMMENT
  12509.             sprintf(buf,
  12510.                "set terminal key %s /literal \\%d \\{27}[\\{%d}\t; %s",
  12511.                 ttkeytab[k].kwd,
  12512.                 mskkeys ? cktomsk(pnode->key) : pnode->key,
  12513.                 pnode->def.csi.key & ~F_CSI,
  12514.                 keyname(pnode->key)
  12515.                 );
  12516. #else
  12517.             ckmakxmsg(buf,
  12518.                   1024,
  12519.                   "set terminal key ",
  12520.                   ttkeytab[k].kwd,
  12521.                   " /literal \\",
  12522.                   ckitoa(mskkeys ?
  12523.                      cktomsk(pnode->key) :
  12524.                      pnode->key),
  12525.                   " \\{27}[\\{",
  12526.                   ckitoa(pnode->def.csi.key & ~F_CSI),
  12527.                   "}\t; ",
  12528.                   keyname(pnode->key),
  12529.                   NULL,NULL,NULL,NULL
  12530.                   );
  12531. #endif /* COMMENT */
  12532.             zsoutl(ZMFILE,buf);
  12533.             break;
  12534.           default:
  12535.             continue;
  12536.         }
  12537.         }
  12538.     }
  12539. #endif /* OS2 */
  12540.  
  12541.     zsoutl(ZMFILE,"");
  12542.     zsoutl(ZMFILE,"; End");
  12543.     zclose(ZMFILE);
  12544.     return(success = 1);
  12545.     } else {
  12546.     return(success = 0);
  12547.     }
  12548. }
  12549. #endif /* NOSETKEY */
  12550.  
  12551. #define SV_SCRL 0
  12552. #define SV_HIST 1
  12553.  
  12554. #ifdef OS2
  12555. #ifndef NOLOCAL
  12556. static struct keytab trmtrmopt[] = {
  12557.     { "scrollback", SV_SCRL, 0 }
  12558. };
  12559. #endif /* NOLOCAL */
  12560. #endif /* OS2 */
  12561.  
  12562. static struct keytab cmdtrmopt[] = {
  12563. #ifdef CK_RECALL
  12564.     { "history",    SV_HIST, 0 },
  12565. #endif /* CK_RECALL */
  12566. #ifdef OS2
  12567. #ifndef NOLOCAL
  12568.     { "scrollback", SV_SCRL, 0 },
  12569. #endif /* NOLOCAL */
  12570. #endif /* OS2 */
  12571.     { "", 0, 0 }
  12572. };
  12573. static int ncmdtrmopt = (sizeof (cmdtrmopt) / sizeof (struct keytab)) - 1;
  12574.  
  12575. #ifdef OS2
  12576. #ifndef NOLOCAL
  12577. _PROTOTYP(int savscrbk, (int, char *, int));
  12578. #endif /* NOLOCAL */
  12579. #endif /* OS2 */
  12580.  
  12581. #ifdef CK_RECALL
  12582. _PROTOTYP(int savhistory, (char *, int));
  12583. #endif /* CK_RECALL */
  12584.  
  12585. int
  12586. dosave(xx) int xx; {
  12587.     int x, y = 0, disp;
  12588.     char * s = NULL;
  12589.     extern struct keytab disptb[];
  12590. #ifdef ZFNQFP
  12591.     struct zfnfp * fnp;
  12592. #endif /* ZFNQFP */
  12593.  
  12594. #ifndef NOSETKEY
  12595.     if (xx == XSKEY) {            /* SAVE KEYMAP.. */
  12596.     z = cmofi("Name of Kermit command file","keymap.ksc",&s,xxstring);
  12597.     } else {
  12598. #endif /* NOSETKEY */
  12599.     switch (xx) {
  12600.       case XSCMD:            /* SAVE COMMAND.. */
  12601.         if ((y = cmkey(cmdtrmopt, ncmdtrmopt, "What to save",
  12602. #ifdef OS2
  12603.                "scrollback",
  12604. #else
  12605.                "history",
  12606. #endif /* OS2 */
  12607.                xxstring)) < 0)
  12608.           return(y);
  12609.         break;
  12610. #ifdef OS2
  12611. #ifndef NOLOCAL
  12612.       case XSTERM:            /* SAVE TERMINAL.. */
  12613.         if ((y = cmkey(trmtrmopt,1,
  12614.                "What to save","scrollback",xxstring)) < 0)
  12615.           return(y);
  12616.         break;
  12617. #endif /* NOLOCAL */
  12618. #endif /* OS2 */
  12619.     }
  12620.     z = cmofi("Filename",
  12621.           ((y == SV_SCRL) ? "scrollbk.txt" : "history.txt"),
  12622.           &s,
  12623.           xxstring
  12624.           );
  12625. #ifndef NOSETKEY
  12626.     }
  12627. #endif /* NOSETKEY */
  12628.     if (z < 0)                /* Check output-file parse results */
  12629.       return(z);
  12630.     if (z == 2) {
  12631.     printf("?Sorry, %s is a directory name\n",s);
  12632.     return(-9);
  12633.     }
  12634. #ifdef ZFNQFP
  12635.     if ((fnp = zfnqfp(s,TMPBUFSIZ - 1,tmpbuf))) {/* Convert to full pathname */
  12636.     if (fnp->fpath)
  12637.       if ((int) strlen(fnp->fpath) > 0)
  12638.         s = fnp->fpath;
  12639.     }
  12640. #endif /* ZFNQFP */
  12641.  
  12642.     ckstrncpy(line,s,LINBUFSIZ);    /* Make safe copy of pathname */
  12643.     s = line;
  12644. #ifdef MAC
  12645.     z = 0;
  12646. #else
  12647.     /* Get NEW/APPEND disposition */
  12648.     if ((z = cmkey(disptb,2,"Disposition","new",xxstring)) < 0)
  12649.       return(z);
  12650. #endif /* MAC */
  12651.     disp = z;
  12652.     if ((x = cmcfm()) < 0)        /* Get confirmation */
  12653.       return(x);
  12654.  
  12655.     switch (xx) {            /* Do action.. */
  12656. #ifndef NOSETKEY
  12657.       case XSKEY:            /* SAVE KEYMAP */
  12658.     return (savkeys(s,disp));
  12659. #endif /* NOSETKEY */
  12660.  
  12661.       case XSCMD:            /* SAVE COMMAND.. */
  12662. #ifdef OS2
  12663. #ifndef NOLOCAL
  12664.     if (y == SV_SCRL)        /* .. SCROLLBACK */
  12665.       return(success = savscrbk(VCMD,s,disp));
  12666. #endif /* NOLOCAL */
  12667. #endif /* OS2 */
  12668. #ifndef NORECALL
  12669.     if (y == SV_HIST)        /* .. HISTORY */
  12670.       return(success = savhistory(s,disp));
  12671.     break;
  12672. #endif /* NORECALL */
  12673.  
  12674. #ifdef OS2
  12675. #ifndef NOLOCAL
  12676.       case XSTERM:            /* SAVE TERMINAL SCROLLBACK */
  12677.     return(success = savscrbk(VTERM,s,disp));
  12678. #endif /* NOLOCAL */
  12679. #endif /* OS2 */
  12680.     }
  12681.     success = 0;
  12682.     return(-2);
  12683. }
  12684.  
  12685. /*
  12686.   R E A D T E X T
  12687.  
  12688.   Read text with a custom prompt into given buffer using command parser but
  12689.   with no echoing or entry into recall buffer.
  12690. */
  12691. int
  12692. readtext(prmpt, buffer, bufsiz) char * prmpt; char * buffer; int bufsiz; {
  12693. #ifdef CK_RECALL
  12694.     extern int on_recall;        /* Around Password prompting */
  12695. #endif /* CK_RECALL */
  12696.     int rc;
  12697. #ifndef NOLOCAL
  12698. #ifdef OS2
  12699.     extern int vmode;
  12700.     extern int startflags;
  12701.     int vmode_sav = vmode;
  12702.  
  12703.     if (win95_popup && !(startflags & 96)
  12704. #ifdef IKSD
  12705.          && !inserver
  12706. #endif /* IKSD */
  12707.          )
  12708.       return(popup_readtext(vmode,prmpt,buffer,bufsiz,0));
  12709.  
  12710.     if (vmode == VTERM) {
  12711.         vmode = VCMD;
  12712.         VscrnIsDirty(VTERM);
  12713.         VscrnIsDirty(VCMD);
  12714.     }
  12715. #endif /* OS2 */
  12716. #endif /* NOLOCAL */
  12717.  
  12718. #ifdef CK_RECALL
  12719.     on_recall = 0;
  12720. #endif /* CK_RECALL */
  12721.     cmsavp(psave,PROMPTL);        /* Save old prompt */
  12722.     cmsetp(prmpt);            /* Make new prompt */
  12723.     concb((char)escape);        /* Put console in cbreak mode */
  12724.     cmini(1);                /* and echo mode */
  12725.     if (pflag) prompt(xxstring);    /* Issue prompt if at top level */
  12726.     cmres();                /* Reset the parser */
  12727.     for (rc = -1; rc < 0; ) {        /* Prompt till they answer */
  12728.         rc = cmtxt("","",&s,NULL);    /* Get a literal line of text */
  12729.         cmres();            /* Reset the parser again */
  12730.     }
  12731.     ckstrncpy(buffer,s,bufsiz);
  12732.     cmsetp(psave);            /* Restore original prompt */
  12733.  
  12734. #ifndef NOLOCAL
  12735. #ifdef OS2
  12736.     if (vmode != vmode_sav) {
  12737.         vmode = VTERM;
  12738.         VscrnIsDirty(VCMD);
  12739.         VscrnIsDirty(VTERM);
  12740.     }
  12741. #endif /* OS2 */
  12742. #endif /* NOLOCAL */
  12743.     return(0);
  12744. }
  12745. #endif /* NOICP */
  12746.  
  12747. /* A general function to allow a Password or other information  */
  12748. /* to be read from the command prompt without it going into     */
  12749. /* the recall buffer or being echo'd.                           */
  12750.  
  12751. int
  12752. readpass(prmpt, buffer, bufsiz) char * prmpt; char * buffer; int bufsiz; {
  12753.     int x;
  12754. #ifdef NOICP
  12755.     printf("%s", prmpt);
  12756. #ifdef COMMENT
  12757.     /* Some linkers won't allow this because it's unsafe */
  12758.     gets(buffer);
  12759. #else
  12760.     {
  12761.     int c, i; char * p;
  12762.     p = buffer;
  12763.     for (i = 0; i < bufsiz-1; i++) {
  12764.         if ((c = getchar()) == EOF)
  12765.           break;
  12766.         if (c < SP)
  12767.           break;
  12768.         buffer[i] = c;
  12769.     }
  12770.     buffer[i] = NUL;
  12771.     }
  12772. #endif /* COMMENT */
  12773.     return(1);
  12774. #else  /* NOICP */
  12775. #ifdef CK_RECALL
  12776.     extern int on_recall;        /* around Password prompting */
  12777. #endif /* CK_RECALL */
  12778.     int rc;
  12779. #ifndef NOLOCAL
  12780. #ifdef OS2
  12781.     extern int vmode;
  12782.     extern int startflags;
  12783.     int vmode_sav = vmode;
  12784. #endif /* OS2 */
  12785. #endif /* NOLOCAL */
  12786. #ifdef CKSYSLOG
  12787.     int savlog;
  12788. #endif /* CKSYSLOG */
  12789. #ifndef NOLOCAL
  12790.     debok = 0;                /* Don't log */
  12791. #ifdef OS2
  12792.     if (win95_popup && !(startflags & 96)
  12793. #ifdef IKSD
  12794.          && !inserver
  12795. #endif /* IKSD */
  12796.          ) {
  12797.     x = popup_readpass(vmode,prmpt,buffer,bufsiz,0);
  12798.     debok = 1;
  12799.     return(x);
  12800.     }
  12801. #endif /* OS2 */
  12802. #endif /* NOLOCAL */
  12803.  
  12804. #ifdef CKSYSLOG
  12805.     savlog = ckxsyslog;            /* Save and turn off syslogging */
  12806.     ckxsyslog = 0;
  12807. #endif /* CKSYSLOG */
  12808. #ifndef NOLOCAL
  12809. #ifdef OS2
  12810.     if (vmode == VTERM) {
  12811.         vmode = VCMD;
  12812.         VscrnIsDirty(VTERM);
  12813.         VscrnIsDirty(VCMD);
  12814.     }
  12815. #endif /* OS2 */
  12816. #endif /* NOLOCAL */
  12817. #ifdef CK_RECALL
  12818.     on_recall = 0;
  12819. #endif /* CK_RECALL */
  12820.     cmsavp(psave,PROMPTL);        /* Save old prompt */
  12821.     cmsetp(prmpt);            /* Make new prompt */
  12822.     concb((char)escape);        /* Put console in cbreak mode */
  12823.     cmini(0);                /* and no-echo mode */
  12824.     if (pflag) prompt(xxstring);    /* Issue prompt if at top level */
  12825.     cmres();                /* Reset the parser */
  12826.     for (rc = -1; rc < 0; ) {        /* Prompt till they answer */
  12827.         rc = cmtxt("","",&s,NULL);    /* Get a literal line of text */
  12828.         cmres();            /* Reset the parser again */
  12829.     }
  12830.     ckstrncpy(buffer,s,bufsiz);
  12831.     printf("\r\n");            /* Echo a CRLF */
  12832.     cmsetp(psave);            /* Restore original prompt */
  12833.     cmini(1);                /* Restore echo mode */
  12834. #ifndef NOLOCAL
  12835. #ifdef OS2
  12836.     if (vmode != vmode_sav) {
  12837.         vmode = VTERM;
  12838.         VscrnIsDirty(VCMD);
  12839.         VscrnIsDirty(VTERM);
  12840.     }
  12841. #endif /* OS2 */
  12842. #endif /* NOLOCAL */
  12843. #ifdef CKSYSLOG
  12844.     ckxsyslog = savlog;            /* Restore syslogging */
  12845. #endif /* CKSYSLOG */
  12846.     debok = 1;
  12847.     return(0);
  12848. #endif /* NOICP */
  12849. }
  12850.  
  12851. #ifndef NOICP
  12852. struct keytab authtab[] = {        /* Available authentication types */
  12853. #ifdef CK_KERBEROS
  12854.     { "k4",        AUTH_KRB4, CM_INV },
  12855.     { "k5",        AUTH_KRB5, CM_INV },
  12856.     { "kerberos4", AUTH_KRB4, 0      },
  12857.     { "kerberos5", AUTH_KRB5, 0      },
  12858.     { "krb4",      AUTH_KRB4, CM_INV },
  12859.     { "krb5",      AUTH_KRB5, CM_INV },
  12860. #endif /* CK_KERBEROS */
  12861. #ifdef NT
  12862.     { "ntlm",      AUTH_NTLM, 0 },
  12863. #endif /* NT */
  12864. #ifdef CK_SRP
  12865.     { "srp",       AUTH_SRP,  0 },
  12866. #endif /* CK_SRP */
  12867. #ifdef CK_SSL
  12868.     { "ssl",       AUTH_SSL,  0 },
  12869. #endif /* CK_SSL */
  12870.     { "",          0,         0 }
  12871. };
  12872. int authtabn = sizeof(authtab)/sizeof(struct keytab)-1;
  12873.  
  12874. #ifdef CK_KERBEROS
  12875. struct keytab kerbtab[] = {        /* Kerberos authentication types */
  12876.     { "k4",        AUTH_KRB4, CM_INV },
  12877.     { "k5",        AUTH_KRB5, CM_INV },
  12878.     { "kerberos4", AUTH_KRB4, 0      },
  12879.     { "kerberos5", AUTH_KRB5, 0      },
  12880.     { "krb4",      AUTH_KRB4, CM_INV },
  12881.     { "krb5",      AUTH_KRB5, CM_INV }
  12882. };
  12883. int kerbtabn = sizeof(kerbtab)/sizeof(struct keytab);
  12884.  
  12885. static struct keytab krb_s_tbl[] = {    /* AUTHENTICATE command switches: */
  12886.     { "/cache",   KRB_S_CA, CM_ARG }
  12887. };
  12888. static int krb_s_n = sizeof(krb_s_tbl)/sizeof(struct keytab);
  12889.  
  12890. static struct keytab krb_v_tbl[] = {    /* KERBEROS version values: */
  12891.     { "4",    4, 0 },
  12892.     { "5",    5, 0 },            /* (add others as needed...) */
  12893.     { "auto", 0, 0 }            /* Note: 0 = auto */
  12894. };
  12895. static int krb_v_n = sizeof(krb_v_tbl)/sizeof(struct keytab);
  12896.  
  12897. static struct keytab krb_a_tbl[] = {    /* KERBEROS actions: */
  12898.     { "destroy",           KRB_A_DE, 0 },
  12899.     { "initialize",        KRB_A_IN, 0 },
  12900.     { "list-credentials",  KRB_A_LC, 0 }
  12901. };
  12902. static int krb_a_n = sizeof(krb_a_tbl)/sizeof(struct keytab);
  12903.  
  12904. static struct keytab krb4_i_tbl[] = {    /* KERBEROS 4 INITIALIZE switches: */
  12905.     { "/brief",            KRB_I_BR, 0 },      /* /BRIEF       */
  12906.     { "/instance",         KRB_I_IN, CM_ARG }, /* /INSTANCE:   */
  12907.     { "/lifetime",         KRB_I_LF, CM_ARG }, /* /LIFETIME:   */
  12908.     { "/not-preauth",      KRB_I_NPA, 0 },     /* /NOT-PREAUTH */
  12909.     { "/password",         KRB_I_PW, CM_ARG }, /* /PASSWORD:   */
  12910. #ifdef OS2
  12911.     { "/popup",            KRB_I_POP, 0 },     /* /POPUP       */
  12912. #endif /* OS2 */
  12913.     { "/preauth",          KRB_I_PA, 0 },      /* /PREAUTH     */
  12914.     { "/realm",            KRB_I_RL, CM_ARG }, /* /REALM:      */
  12915.     { "/verbose",          KRB_I_VB, 0 },      /* /VERBOSE     */
  12916.     { "", 0, 0 }
  12917. };
  12918. static int krb4_i_n = sizeof(krb4_i_tbl)/sizeof(struct keytab) - 1;
  12919.  
  12920. static struct keytab krb5_i_tbl[] = {    /* KERBEROS 5 INITIALIZE switches: */
  12921.     { "/addresses",        KRB_I_ADR, CM_ARG },
  12922.     { "/forwardable",      KRB_I_FW,  0 },       /* /FORWARDABLE */
  12923.     { "/instance",         KRB_I_IN, CM_ARG }, /* /INSTANCE:   */
  12924.     { "/k4",               KRB_I_K4,  CM_INV }, /* /KERBEROS4   */
  12925.     { "/kerberos4",        KRB_I_K4,  0 },      /* /KERBEROS4   */
  12926.     { "/krb4",             KRB_I_K4,  CM_INV }, /* /KERBEROS4   */
  12927.     { "/lifetime",         KRB_I_LF,  CM_ARG }, /* /LIFETIME:   */
  12928.     { "/no-addresses",     KRB_I_NAD, 0 },      /* /NO-ADDRESSES */
  12929.     { "/no-k4",            KRB_I_NK4, CM_INV },/* /NO-KERBEROS4 */
  12930.     { "/no-kerberos4",     KRB_I_NK4, 0 },     /* /NO-KERBEROS4 */
  12931.     { "/no-krb4",          KRB_I_NK4, CM_INV },/* /NO-KERBEROS4 */
  12932.     { "/not-forwardable",  KRB_I_NFW, 0 },       /* /NOT-FORWARDABLE */
  12933.     { "/not-proxiable",    KRB_I_NPR, 0 },     /* /NOT-PROXIABLE   */
  12934.     { "/password",         KRB_I_PW,  CM_ARG }, /* /PASSWORD:   */
  12935. #ifdef OS2
  12936.     { "/popup",            KRB_I_POP, 0 },     /* /POPUP       */
  12937. #endif /* OS2 */
  12938.     { "/postdate",         KRB_I_PD, CM_ARG }, /* /POSTDATE:   */
  12939.     { "/pr",               KRB_I_PR, CM_INV|CM_ABR }, /* to allow for */
  12940.     { "/pro",              KRB_I_PR, CM_INV|CM_ABR }, /* different spellings */
  12941.     { "/prox",             KRB_I_PR, CM_INV|CM_ABR },
  12942.     { "/proxiable",        KRB_I_PR, 0 },      /* /PROXIABLE   */
  12943.     { "/proxyable",        KRB_I_PR, CM_INV }, /* /PROXYABLE   */
  12944.     { "/realm",            KRB_I_RL, CM_ARG }, /* /REALM:      */
  12945.     { "/renew",            KRB_I_RN, 0 },       /* /RENEW       */
  12946.     { "/renewable",        KRB_I_RB, CM_ARG }, /* /RENEWABLE:  */
  12947.     { "/service",          KRB_I_SR, CM_ARG }, /* /SERVICE:    */
  12948.     { "/validate",         KRB_I_VA, 0 },        /* /VALIDATE    */
  12949.     { "", 0, 0 }
  12950. };
  12951. static int krb5_i_n = sizeof(krb5_i_tbl)/sizeof(struct keytab) - 1;
  12952.  
  12953. static struct keytab klctab[] = {    /* List Credentials switches*/
  12954.     { "/addresses",  XYKLCAD, 0 },
  12955.     { "/encryption", XYKLCEN, 0 },
  12956.     { "/flags",      XYKLCFL, 0 }
  12957. };
  12958. static int nklctab = sizeof(klctab)/sizeof(struct keytab);
  12959.  
  12960. extern int krb_action;
  12961. extern struct krb_op_data krb_op;
  12962.  
  12963. extern struct krb5_list_cred_data krb5_lc;
  12964. extern struct krb5_init_data krb5_init;
  12965. extern char * krb5_d_principal;        /* Default principal */
  12966. extern char * krb5_d_instance;
  12967. extern char * krb5_d_realm;        /* Default realm */
  12968. extern char * krb5_d_cc;        /* Default credentials cache */
  12969. extern char * krb5_d_srv;               /* Default service name */
  12970. extern int    krb5_d_lifetime;          /* Default lifetime */
  12971. extern int    krb5_d_forwardable;
  12972. extern int    krb5_d_proxiable;
  12973. extern int    krb5_d_renewable;
  12974. extern int    krb5_autoget;
  12975. extern int    krb5_autodel;
  12976. extern int    krb5_d_getk4;
  12977. extern int    krb5_d_no_addresses;
  12978. extern int    krb5_checkaddrs;
  12979. extern char * krb5_d_addrs[];
  12980. extern char * k5_keytab;                /* Keytab file */
  12981.  
  12982. extern struct krb4_init_data krb4_init;
  12983. extern char * krb4_d_principal;        /* Default principal */
  12984. extern char * krb4_d_realm;        /* Default realm */
  12985. extern char * krb4_d_srv;               /* Default service name */
  12986. extern int    krb4_d_lifetime;          /* Default lifetime */
  12987. extern int    krb4_d_preauth;
  12988. extern char * krb4_d_instance;
  12989. extern int    krb4_autoget;
  12990. extern int    krb4_autodel;
  12991. extern int    krb4_checkaddrs;
  12992. extern char * k4_keytab;                /* Keytab file */
  12993. #endif /* CK_KERBEROS */
  12994.  
  12995. #ifndef NOSHOW
  12996. int 
  12997. sho_iks() {
  12998. #ifdef IKSDCONF
  12999. #ifdef CK_LOGIN
  13000.     extern int ckxsyslog, ckxwtmp, ckxanon;
  13001. #ifdef UNIX
  13002.     extern int ckxpriv;
  13003. #endif /* UNIX */
  13004. #ifdef CK_PERMS
  13005.     extern int ckxperms;
  13006. #endif /* CK_PERMS */
  13007.     extern char * anonfile, * userfile, * anonroot;
  13008. #ifdef OS2
  13009.     extern char * anonacct;
  13010. #endif /* OS2 */
  13011. #ifdef NT
  13012.     extern char * iks_domain;
  13013. #endif /* NT */
  13014. #endif /* CK_LOGIN */
  13015. #ifdef CKWTMP
  13016.     extern char * wtmpfile;
  13017. #endif /* CKWTMP */
  13018. #ifdef IKSDB
  13019.     extern char * dbfile;
  13020.     extern int dbenabled;
  13021. #endif /* IKSDB */
  13022. #ifdef CK_LOGIN
  13023.     extern int logintimo;
  13024. #endif /* CK_LOGIN */
  13025.     extern int srvcdmsg, success, iksdcf, noinit, arg_x;
  13026.     extern char * cdmsgfile[], * cdmsgstr, *kermrc;
  13027.     char * bannerfile = NULL;
  13028.     char * helpfile = NULL;
  13029.     extern int xferlog;
  13030.     extern char * xferfile;
  13031.     int i;
  13032.  
  13033.     if (isguest) {
  13034.         printf("?Command disabled\r\n");
  13035.     return(success = 0);
  13036.     }
  13037.  
  13038.     printf("IKS Settings\r\n");
  13039. #ifdef CK_LOGIN
  13040. #ifdef OS2
  13041.     printf("  Anonymous Account:   %s\r\n",anonacct?anonacct:"<none>");
  13042. #endif /* OS2 */
  13043.     printf("  Anonymous Initfile:  %s\r\n",anonfile?anonfile:"<none>");
  13044.     printf("  Anonymous Login:     %d\r\n",ckxanon);
  13045.     printf("  Anonymous Root:      %s\r\n",anonroot?anonroot:"<none>");
  13046. #endif /* CK_LOGIN */
  13047.     printf("  Bannerfile:          %s\r\n",bannerfile?bannerfile:"<none>");
  13048.     printf("  CDfile:              %s\r\n",cdmsgfile[0]?cdmsgfile[0]:"<none>");
  13049.     for ( i=1;i<16 && cdmsgfile[i];i++ )
  13050.     printf("  CDfile:              %s\r\n",cdmsgfile[i]);
  13051.     printf("  CDMessage:           %d\r\n",srvcdmsg);
  13052. #ifdef IKSDB
  13053.     printf("  DBfile:              %s\r\n",dbfile?dbfile:"<none>");
  13054.     printf("  DBenabled:           %d\r\n",dbenabled);
  13055. #endif /* IKSDB */
  13056. #ifdef CK_LOGIN
  13057. #ifdef NT
  13058.     printf("  Default-domain:      %s\r\n",iks_domain?iks_domain:".");
  13059. #endif /* NT */
  13060. #endif /* CK_LOGIN */
  13061.     printf("  Helpfile:            %s\r\n",helpfile?helpfile:"<none>");
  13062.     printf("  Initfile:            %s\r\n",kermrc?kermrc:"<none>");
  13063.     printf("  No-Initfile:         %d\r\n",noinit);
  13064. #ifdef CK_LOGIN
  13065. #ifdef CK_PERM
  13066.     printf("  Permission code:     %0d\r\n",ckxperms);
  13067. #endif /* CK_PERM */
  13068. #ifdef UNIX
  13069.     printf("  Privileged Login:    %d\r\n",ckxpriv);
  13070. #endif /* UNIX */
  13071. #endif /* CK_LOGIN */
  13072.     printf("  Server-only:         %d\r\n",arg_x);
  13073.     printf("  Syslog:              %d\r\n",ckxsyslog);
  13074.     printf("  Timeout (seconds):   %d\r\n",logintimo);
  13075.     printf("  Userfile:            %s\r\n",userfile?userfile:"<none>");
  13076. #ifdef CK_LOGIN
  13077. #ifdef CKWTMP
  13078.     printf("  Wtmplog:             %d\r\n",ckxwtmp);
  13079.     printf("  Wtmpfile:            %s\r\n",wtmpfile?wtmpfile:"<none>");
  13080. #endif /* CKWTMP */
  13081. #endif /* CK_LOGIN */
  13082.     printf("  Xferfile:            %s\r\n",xferfile?xferfile:"<none>");
  13083.     printf("  Xferlog:             %d\r\n",xferlog);
  13084. #else /* IKSDCONF */
  13085.     printf("?Nothing to show.\r\n");
  13086. #endif /* IKSDCONF */
  13087.     return(success = 1);
  13088. }
  13089.  
  13090. #ifdef CK_AUTHENTICATION
  13091. int
  13092. sho_auth(cx) int cx; {
  13093.     extern int auth_type_user[], cmd_rows;
  13094.     int i;
  13095.     char * p;
  13096.     int kv = 0, all = 0, n = 0;
  13097.  
  13098. #ifdef IKSD
  13099.     if (inserver && isguest) {
  13100.         printf("?Sorry, command disabled.\r\n");
  13101.         return(success = 0);
  13102.     }
  13103. #endif /* IKSD */
  13104.     if (cx) {
  13105.         kv = cx;
  13106.     } else if (auth_type_user[0] != AUTHTYPE_AUTO) {
  13107.         kv = auth_type_user[0];
  13108.     } else {
  13109.         all = 1;
  13110.         kv = AUTHTYPE_KERBEROS_V4;
  13111.     }
  13112.     while (kv) {
  13113.         switch (kv) {
  13114.       case AUTHTYPE_KERBEROS_V4:
  13115.             kv = all ? AUTHTYPE_KERBEROS_V5 : 0;
  13116.             if (ck_krb4_is_installed()) {
  13117.                 printf(" Authentication:      Kerberos 4\n");
  13118.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13119.             } else {
  13120.                 printf(" Authentication:      Kerberos 4 (not installed)\n");
  13121.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13122.                 continue;
  13123.             }
  13124. #ifdef CK_KERBEROS
  13125.             printf(" Keytab file:         %s\n",
  13126.                       k4_keytab ? k4_keytab : "(none)");
  13127.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13128.             if (krb_action < 0) {
  13129.                 p = "(none)";
  13130.             } else {
  13131.                 for (p = "", i = 0; i < krb_a_n; i++) {
  13132.                     if (krb_action == krb_a_tbl[i].kwval) {
  13133.                         p = krb_a_tbl[i].kwd;
  13134.                         break;
  13135.                     }
  13136.                 }
  13137.             }
  13138.             printf(" Action:              %s\n", p);
  13139.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13140.             printf(" Default lifetime     %d\n",krb4_d_lifetime);
  13141.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13142.             printf(" Lifetime:            %d (minutes)\n",krb4_init.lifetime);
  13143.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13144.             printf(" Default preauth:     %d\n",krb4_d_preauth);
  13145.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13146.             printf(" Preauth:             %d\n",krb4_init.preauth);
  13147.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13148.             printf(" Default principal:   \"%s\"\n",
  13149.                     krb4_d_principal ? krb4_d_principal : "");
  13150.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13151.             printf(" Principal:           \"%s\"\n",
  13152.                     krb4_init.principal ? krb4_init.principal : "");
  13153.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13154.             printf(" Default realm:       \"%s\"\n",
  13155.                     krb4_d_realm ? krb4_d_realm : "");
  13156.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13157.             printf(" Realm:               \"%s\"\n",
  13158.                     krb4_init.realm ? krb4_init.realm : "");
  13159.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13160.             printf(" Default instance:    \"%s\"\n",
  13161.                     krb4_d_instance ? krb4_d_instance : "");
  13162.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13163.             printf(" Instance:            \"%s\"\n",
  13164.                     krb4_init.instance ? krb4_init.instance : "");
  13165.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13166.             printf(" Auto-Get TGTs:       %d\n",krb4_autoget);
  13167.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13168.             printf(" Auto-Destroy TGTs:   %s\n",
  13169.                     krb4_autodel==KRB_DEL_NO?"never":
  13170.                     krb4_autodel==KRB_DEL_CL?"on-close":"on-exit");
  13171.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13172.             printf(" Check IP Addresses:  %d\n",krb4_checkaddrs);
  13173.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13174. #ifdef COMMENT
  13175.             printf(" Password:    \"%s\"\n",
  13176.                     krb4_init.password  ? krb4_init.password  : "");
  13177.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13178. #endif /* COMMENT */
  13179. #endif /* CK_KERBEROS */
  13180.             printf("\n");
  13181.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13182.             break;
  13183.         case AUTHTYPE_KERBEROS_V5:
  13184.             kv = all ? AUTHTYPE_SSL : 0;
  13185.             if (ck_krb5_is_installed()) {
  13186.                 if (ck_gssapi_is_installed())
  13187.                     printf(" Authentication:      Kerberos 5 plus GSSAPI\n");
  13188.                 else
  13189.                     printf(" Authentication:      Kerberos 5\n");
  13190.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13191.             } else {
  13192.                 printf(" Authentication:      Kerberos 5 (not installed)\n");
  13193.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13194.                 continue;
  13195.             }
  13196.  
  13197. #ifdef CK_KERBEROS
  13198.             printf(" Cache file:          %s\n",
  13199.                     krb_op.cache ? krb_op.cache : "(none)");
  13200.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13201.             printf(" Default cache:       %s\n",
  13202.                     krb5_d_cc ? krb5_d_cc : "(none)");
  13203.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13204.             printf(" Keytab file:         %s\n",
  13205.                       k5_keytab ? k5_keytab : "(none)");
  13206.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13207.             if (krb_action < 0) {
  13208.                 p = "(none)";
  13209.             } else  {
  13210.                 for (p = "", i = 0; i < krb_a_n; i++) {
  13211.                     if (krb_action == krb_a_tbl[i].kwval) {
  13212.                         p = krb_a_tbl[i].kwd;
  13213.                         break;
  13214.                     }
  13215.                 }
  13216.             }
  13217.             printf(" Action:              %s\n", p);
  13218.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13219.  
  13220.             printf(" Default forwardable  %d\n",krb5_d_forwardable);
  13221.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13222.             printf(" Forwardable:         %d\n",krb5_init.forwardable);
  13223.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13224.             printf(" Default lifetime     %d\n",krb5_d_lifetime);
  13225.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13226.             printf(" Lifetime:            %d (minutes)\n",krb5_init.lifetime);
  13227.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13228.             printf(" Postdate:            \"%s\"\n",
  13229.                     krb5_init.postdate ? krb5_init.postdate: "");
  13230.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13231.             printf(" Default proxiable:   %d\n",krb5_d_proxiable);
  13232.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13233.             printf(" Proxiable:           %d\n",krb5_init.proxiable);
  13234.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13235.             printf(" Renew:               %d\n",krb5_init.renew);
  13236.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13237.             printf(" Default renewable:   %d (minutes)\n",krb5_d_renewable);
  13238.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13239.             printf(" Renewable:           %d (minutes)\n",krb5_init.renewable);
  13240.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13241.             printf(" Service:             \"%s\"\n",
  13242.                     krb5_init.service ? krb5_init.service : "");
  13243.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13244.             printf(" Validate:            %d\n",krb5_init.validate);
  13245.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13246.             printf(" Default principal:   \"%s\"\n",
  13247.                     krb5_d_principal ? krb5_d_principal : "");
  13248.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13249.             printf(" Principal:           \"%s\"\n",
  13250.                     krb5_init.principal ? krb5_init.principal : "");
  13251.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13252.             printf(" Default instance:    \"%s\"\n",
  13253.                     krb5_d_instance ? krb5_d_instance : "");
  13254.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13255.             printf(" Default realm:       \"%s\"\n",
  13256.                     krb5_d_realm ? krb5_d_realm : "");
  13257.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13258.             printf(" Realm:               \"%s\"\n",
  13259.                     krb5_init.realm ? krb5_init.realm : "");
  13260.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13261.             printf(" Auto-Get TGTs:       %d\n",krb5_autoget);
  13262.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13263.             printf(" Auto-Destroy TGTs:   %s\n",
  13264.                     krb5_autodel==KRB_DEL_NO?"never":
  13265.                     krb5_autodel==KRB_DEL_CL?"on-close":"on-exit");
  13266.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13267.             printf(" Default get K4 TGTs: %d\n",krb5_d_getk4);
  13268.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13269.             printf(" Get K4 TGTs: %d\n",krb5_init.getk4);
  13270.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13271.             printf(" Check IP Addresses:  %d\n",krb5_checkaddrs);
  13272.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13273.             printf(" No IP Addresses:  %d\n",krb5_d_no_addresses);
  13274.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13275.             printf(" IP-Addresses:        ");
  13276.             if (krb5_init.addrs && krb5_init.addrs[0]) {
  13277.                 for (i = 0; krb5_init.addrs[i]; i++) {
  13278.                     if (i)
  13279.               printf(",");
  13280.                     printf("%s",krb5_init.addrs[i]);
  13281.                 }
  13282.             } else if (krb5_d_addrs[0]) {
  13283.                 for (i = 0;i < KRB5_NUM_OF_ADDRS && krb5_d_addrs[i];i++) {
  13284.                     if (i)
  13285.               printf(",");
  13286.                     printf("%s",krb5_d_addrs[i]);
  13287.                 }
  13288.             } else {
  13289.                 printf("(use default)");
  13290.             }
  13291.             printf("\n");
  13292.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13293. #ifdef COMMENT
  13294.             printf(" Password:            \"%s\"\n",
  13295.                     krb5_init.password  ? krb5_init.password  : "");
  13296.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13297. #endif /* COMMENT */
  13298. #endif /* CK_KERBEROS */
  13299.             printf("\n");
  13300.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13301.             break;
  13302.       case AUTHTYPE_SSL:
  13303.             kv = all ? AUTHTYPE_SRP : 0;
  13304.             if (ck_ssleay_is_installed()) {
  13305.                 printf(" Authentication:      SSL/TLS\n");
  13306.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13307.             } else {
  13308.                 printf(" Authentication:      SSL/TLS (not installed)\n");
  13309.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13310.                 continue;
  13311.             }
  13312.  
  13313. #ifdef CK_SSL
  13314.             printf(" RSA Certs file: %s\n",ssl_rsa_cert_file?
  13315.                   ssl_rsa_cert_file:"(none)");
  13316.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13317.             printf(" RSA Certs Chain file: %s\n",ssl_rsa_cert_chain_file?
  13318.                   ssl_rsa_cert_chain_file:"(none)");
  13319.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13320.             printf(" RSA Key file: %s\n",ssl_rsa_key_file?
  13321.                   ssl_rsa_key_file:"(none)");
  13322.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13323.             printf(" DSA Certs file: %s\n",ssl_dsa_cert_file?
  13324.                   ssl_dsa_cert_file:"(none)");
  13325.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13326.             printf(" DSA Certs Chain file: %s\n",ssl_dsa_cert_chain_file?
  13327.                   ssl_dsa_cert_chain_file:"(none)");
  13328.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13329.             printf(" DH Key file: %s\n",ssl_dh_key_file?
  13330.                   ssl_dh_key_file:"(none)");
  13331.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13332.             printf(" DH Param file: %s\n",ssl_dh_param_file?
  13333.                   ssl_dh_param_file:"(none)");
  13334.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13335.             printf(" CRL file: %s\n",ssl_crl_file?
  13336.                   ssl_crl_file:"(none)");
  13337.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13338.             printf(" CRL dir: %s\n",ssl_crl_dir?
  13339.                     ssl_crl_dir:"(none)");
  13340.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13341.             printf(" Random file: %s\n",ssl_rnd_file?
  13342.                   ssl_rnd_file:"(none)");
  13343.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13344.             printf(" Verify file: %s\n",ssl_verify_file?
  13345.                   ssl_verify_file:"(none)");
  13346.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13347.             printf(" Verify dir: %s\n",ssl_verify_dir?
  13348.                   ssl_verify_dir:"(none)");
  13349.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13350.             printf(" Cipher list:\n");
  13351.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13352.         if (ssl_con == NULL) {
  13353.         SSL_library_init();
  13354.         ssl_ctx = (SSL_CTX *)
  13355.           SSL_CTX_new((SSL_METHOD *)TLSv1_method());
  13356.         if (ssl_ctx != NULL)
  13357.           ssl_con= (SSL *) SSL_new(ssl_ctx);
  13358.         }
  13359.         if (ssl_con != NULL) {
  13360.         CHAR * p = NULL;
  13361.         int i;
  13362.  
  13363.         for (i = 0; ; i++) {
  13364.             p = (CHAR *) SSL_get_cipher_list(ssl_con,i);
  13365.             if (p == NULL)
  13366.               break;
  13367.             printf("    %s\n",p);
  13368.                     if (++n > cmd_rows - 3)
  13369.                         if (!askmore()) return(0); else n = 0;
  13370.         }
  13371.         }
  13372.             printf(" Certs OK? %s\n",ssl_certsok_flag? "yes" : "no");
  13373.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13374.             printf(" Debug mode: %s\n", ssl_debug_flag ? "on" : "off");
  13375.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13376.             printf(" Verbose mode: %s\n", ssl_verbose_flag ? "on" : "off");
  13377.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13378.             printf(" Verify mode: %s\n",
  13379.                     ssl_verify_flag == SSL_VERIFY_NONE ? "none" :
  13380.                     ssl_verify_flag == SSL_VERIFY_PEER ? "peer-cert" :
  13381.                     "fail-if-no-peer-cert");
  13382.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13383.             printf(" SSL only? %s\n", ssl_only_flag ? "yes" : "no");
  13384.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13385.             printf(" TLS only? %s\n", tls_only_flag ? "yes" : "no");
  13386.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13387. #endif /* CK_SSL */
  13388.             break;
  13389.       case AUTHTYPE_NTLM:
  13390.             kv = 0;
  13391.             if (ck_ntlm_is_installed()) {
  13392.                 printf(" Authentication:      NTLM\n");
  13393.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13394.                 printf(" No options\n");
  13395.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13396.             } else {
  13397.                 printf(" Authentication:      NTLM (not installed)\n");
  13398.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13399.                 continue;
  13400.             }
  13401.             printf("\n");
  13402.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13403.             break;
  13404.       case AUTHTYPE_SRP:
  13405.             kv = all ? AUTHTYPE_NTLM : 0;
  13406.             if (ck_srp_is_installed()) {
  13407.                 if (ck_krypto_is_installed())
  13408.                     printf(" Authentication:      SRP plus Krypto API\n");
  13409.                 else
  13410.                     printf(" Authentication:      SRP\n");
  13411.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13412.                 printf(" No options\n");
  13413.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13414.             } else {
  13415.                 printf(" Authentication:      SRP (not installed)\n");
  13416.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13417.                 continue;
  13418.             }
  13419.             printf("\n");
  13420.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  13421.             break;
  13422.         }
  13423.     }
  13424.     return(success = 1);
  13425. }
  13426. #endif /* CK_AUTHENTICATION */
  13427. #endif /* NOSHOW */
  13428.  
  13429. #ifdef CK_KERBEROS
  13430.  
  13431. /*  C P _ A U T H  --  AUTHENTICATE command parsing  */
  13432.  
  13433. int
  13434. cp_auth() {                /* Command_Parse AUTHENTICATE */
  13435.     int c, i, n;            /* Workers */
  13436.     int rc = 0;                /* Return code */
  13437.     int getval;                /* Parsing helpers */
  13438.     int tmpauth = 0;            /* Temporary authentication type */
  13439.     int kv = 0;                /* Temporary Kerberos version */
  13440.     int tmp_action = -1;        /* Temporary Kerberos action */
  13441.     int tmp_klc = 0;            /* Temporary list-credentials */
  13442.     char tmphlp[256];            /* For building help message */
  13443.     char * p;
  13444.     char * tmppswd  = NULL;        /* Password */
  13445.     char * tmpprinz = NULL;        /* Principal */
  13446.     char * tmprealm = NULL;             /* Realm */
  13447.     char * tmpcache = NULL;        /* Cache file */
  13448.     char * tmpinst  = NULL;             /* K4 Instance */
  13449.     char * tmpaddrs[KRB5_NUM_OF_ADDRS];
  13450. #ifdef CK_RECALL
  13451.     extern int on_recall;        /* around Password prompting */
  13452. #endif /* CK_RECALL */
  13453.     struct stringint {            /* Temporary array for switch values */
  13454.     char * sval;            /* String value */
  13455.     int ival;            /* Integer value */
  13456.     } pv[KRB_I_MAX+1];            /* This many */
  13457.     struct FDB kw, sw, fl;        /* FDBs for each parse function */
  13458.  
  13459.     krb_action = -1;            /* Initialize Kerberos action. */
  13460.     tmp_action = -1;            /* And our local copy. */
  13461.     for (i = 0; i < KRB5_NUM_OF_ADDRS; i++)
  13462.       tmpaddrs[i] = NULL;
  13463.  
  13464.     if ((y = cmkey(kerbtab,kerbtabn,"authentication type","",xxstring)) < 0)
  13465.       {
  13466.       if (y == -3)
  13467.         printf("?Authentication type not specified - nothing happens\n");
  13468.       return(y);
  13469.       }
  13470.     tmpauth = y;
  13471.     debug(F101,"kerberos authentication","",tmpauth);
  13472.     switch (tmpauth) {
  13473.       case AUTH_KRB4: kv = 4; break;    /* Don't assume values are the same */
  13474.       case AUTH_KRB5: kv = 5; break;
  13475.       default:
  13476.     printf("?Authentication type not supported: \"%s\"\n",atmbuf);
  13477.     return(-9);
  13478.     }
  13479.  
  13480.     /* From here down is Kerberos */
  13481.     ini_kerb();                /* Reset Init data to defaults */
  13482.  
  13483.     if (kv == 4) {            /* Set K4 defaults */
  13484.         if (krb4_d_realm)
  13485.       makestr(&tmprealm,krb4_d_realm);
  13486.         if (krb4_d_principal)
  13487.       makestr(&tmpprinz,krb4_d_principal);
  13488.         if (krb4_d_instance)
  13489.       makestr(&tmpinst,krb4_d_instance);
  13490.     } else if (kv == 5) {        /* Set K5 defaults */
  13491.         if (krb5_d_cc)
  13492.       makestr(&tmpcache,krb5_d_cc);
  13493.         if (krb5_d_realm)
  13494.       makestr(&tmprealm,krb5_d_realm);
  13495.         if (krb5_d_principal)
  13496.       makestr(&tmpprinz,krb5_d_principal);
  13497.         if (krb5_d_instance)
  13498.       makestr(&tmpinst,krb5_d_instance);
  13499.     }
  13500.  
  13501.     for (i = 0; i <= KRB_I_MAX; i++) {    /* Initialize switch values */
  13502.     pv[i].sval = NULL;        /* to null pointers */
  13503.     pv[i].ival = 0;            /* and 0 int values */
  13504.     }
  13505.  
  13506.     if (kv == 4) {            /* Kerberos 4 */
  13507.         pv[KRB_I_LF].ival = krb4_d_lifetime;
  13508.         pv[KRB_I_PA].ival = krb4_d_preauth;
  13509.  
  13510.     if ((n = cmkey(krb_a_tbl,krb_a_n,"Kerberos 4 action","",xxstring)) < 0)
  13511.       {
  13512.           if (n == -3)
  13513.         printf("?Action not specified - nothing happens.\n");
  13514.           return(n);
  13515.       }
  13516.     } else if (kv == 5) {        /* Kerberos 5 */
  13517.         pv[KRB_I_FW].ival = krb5_d_forwardable;
  13518.         pv[KRB_I_PR].ival = krb5_d_proxiable;
  13519.         pv[KRB_I_LF].ival = krb5_d_lifetime;
  13520.         pv[KRB_I_RB].ival = krb5_d_renewable;
  13521.         pv[KRB_I_K4].ival = krb5_d_getk4;
  13522.         pv[KRB_I_NAD].ival = krb5_d_no_addresses;
  13523.  
  13524.     /* Make help message that shows switches and action keywords */
  13525.     ckstrncpy(tmphlp,"Kerberos 5 action, one of the following:\n ",256);
  13526.     for (i = 0; i < krb_a_n; i++) {
  13527.         ckstrncat(tmphlp,krb_a_tbl[i].kwd,sizeof(tmphlp));
  13528.         if (i == krb_a_n - 1)
  13529.           ckstrncat(tmphlp,"\nor switch",sizeof(tmphlp));
  13530.         else
  13531.           ckstrncat(tmphlp,"   ",sizeof(tmphlp));
  13532.     }
  13533.     /* Set up first set of chained FDB's */
  13534.  
  13535.     cmfdbi(&sw,            /* First FDB - command switches */
  13536.            _CMKEY,            /* fcode */
  13537.            tmphlp,            /* hlpmsg */
  13538.            "",            /* default (none) */
  13539.            "",            /* addtl string data */
  13540.            krb_s_n,            /* Switch table size */
  13541.            4,            /* addtl numeric data 2: 4 = cmswi */
  13542.            xxstring,        /* Processing function */
  13543.            krb_s_tbl,        /* Switch table */
  13544.            &kw            /* Pointer to next FDB */
  13545.            );
  13546.     cmfdbi(&kw,            /* Second FDB - action keywords */
  13547.            _CMKEY,            /* fcode */
  13548.            "Kerberos action",    /* hlpmsg */
  13549.            "",            /* default (none) */
  13550.            "",            /* addtl string data */
  13551.            krb_a_n,            /* Switch table size */
  13552.            0,            /* addtl num data (0 = NOT switch) */
  13553.            xxstring,        /* Processing function */
  13554.            krb_a_tbl,        /* Keyword table */
  13555.            NULL            /* Pointer to next FDB (none) */
  13556.            );
  13557.  
  13558.     /* Parse */
  13559.  
  13560.     while (1) {            /* Parse 0 or more switches */
  13561.         rc = cmfdb(&sw);        /* Parse something */
  13562.         debug(F101,"kerberos cmfdb 1 rc","",rc);
  13563.         if (rc < 0) {            /* Error */
  13564.         if (rc == -3)
  13565.           printf("?Action not specified - nothing happens.\n");
  13566.         return(rc);        /* or reparse needed */
  13567.         }
  13568.         if (cmresult.fdbaddr != &sw) /* Break out if not a switch */
  13569.           break;
  13570.         c = cmgbrk();        /* Have switch - get break character */
  13571.         getval = (c == ':' || c == '='); /* Must parse an agument? */
  13572.         if (getval && !(cmresult.kflags & CM_ARG)) {
  13573.         printf("?This switch does not take arguments\n");
  13574.         return(-9);        /* OK because nothing malloc'd yet */
  13575.         }
  13576.         if (!getval && (cmgkwflgs() & CM_ARG)) {
  13577.         printf("?This switch requires an argument\n");
  13578.         return(-9);
  13579.         }
  13580.         n = cmresult.nresult;    /* Numeric result = switch value */
  13581.         debug(F101,"kerberos command switch","",n);
  13582.  
  13583.         switch (n) {        /* Handle the switch */
  13584.           case KRB_S_CA:        /* /CACHE:<filename> */
  13585.         p = krb5_d_cc ? krb5_d_cc : "";
  13586.         if ((y = cmofi("Name of cache file",p,&s,xxstring)) < 0) {
  13587.             if (y == -3)
  13588.               s = NULL;
  13589.             else
  13590.               return(y);
  13591.         }
  13592.         makestr(&tmpcache,s);
  13593.         break;
  13594.           default:
  13595.         printf("?Unexpected switch value - internal error\n");
  13596.         return(-9);        /* (if) nothing malloc'd yet. */
  13597.         }
  13598.     }
  13599.     if (cmresult.fdbaddr != &kw) {    /* Checking... */
  13600.         printf("?Unexpected result - internal error\n");
  13601.         return(-9);            /* Nothing malloc'd yet. */
  13602.     }
  13603.     n = cmresult.nresult;        /* Get keyword value */
  13604.     } else {
  13605.     printf("?Unexpected Kerberos version - Internal error\n");
  13606.     return(-9);
  13607.     }
  13608.     debug(F101,"kerberos action","",n);
  13609.     switch (n) {
  13610.       case KRB_A_IN:            /* INITIALIZE */
  13611.       case KRB_A_DE:            /* DESTROY */
  13612.       case KRB_A_LC:            /* LIST-CREDENTIALS */
  13613.     tmp_action = n;            /* OK, set */
  13614.     break;
  13615.       default:                /* Not OK, punt. */
  13616.     printf("?Unexpected action - internal error\n");
  13617.     return(-9);
  13618.     }
  13619.     if (tmp_action == KRB_A_IN) {    /* Action is INITIALIZE */
  13620.     int x;
  13621.     cmfdbi(&sw,            /* INITIALIZE switches */
  13622.            _CMKEY,            /* fcode */
  13623.            "Principal,\n or optional INITIALIZE switch(es)", /* hlpmsg */
  13624.            "",            /* default (none) */
  13625.            "",            /* addtl string data */
  13626.            kv == 4 ?  krb4_i_n : krb5_i_n, /* Switch table size */
  13627.            4,            /* addtl numeric data 2: 4 = cmswi */
  13628.            xxstring,        /* Processing function */
  13629.            kv == 4 ?  krb4_i_tbl : krb5_i_tbl,    /* Switch table */
  13630.            &fl            /* Pointer to next FDB */
  13631.            );
  13632.     cmfdbi(&fl,            /* 3rd FDB - command to send from */
  13633.            _CMFLD,            /* fcode */
  13634.            "Principal",        /* hlpmsg */
  13635.            kv == 4 ? krb4_d_principal : krb5_d_principal, /* principal */
  13636.            "",            /* addtl string data */
  13637.            0,            /* addtl numeric data 1 */
  13638.            0,            /* addtl numeric data 2 */
  13639.            xxstring,
  13640.            NULL,
  13641.            NULL
  13642.            );
  13643.     while (1) {            /* Parse INIT switches or principal */
  13644.         rc = cmfdb(&sw);
  13645.         debug(F101,"kerberos cmfdb 2 rc","",rc);
  13646.         if (rc < 0) {
  13647.         if (rc == -3)
  13648.           printf("?Principal name required\n");
  13649.         goto kerbx;
  13650.         }
  13651.         debug(F101,"kerberos cmfdb 2 fcode","",cmresult.fcode);
  13652.         if (cmresult.fcode != _CMKEY) /* Not a switch, quit switch loop */
  13653.           break;
  13654.         c = cmgbrk();        /* Switch - get break character */
  13655.         debug(F101,"kerberos cmfdb 2 cmgbrk","",c);
  13656.         getval = (c == ':' || c == '=');
  13657.         if (getval && !(cmresult.kflags & CM_ARG)) {
  13658.         printf("?This switch does not take arguments\n");
  13659.         return(-9);        /* OK because nothing malloc'd yet */
  13660.         }
  13661.         if (!getval && (cmgkwflgs() & CM_ARG)) {
  13662.         printf("?This switch requires an argument\n");
  13663.         return(-9);
  13664.         }
  13665.         n = cmresult.nresult;    /* Numeric result = switch value */
  13666.         switch (n) {
  13667.           /* These don't take args... */
  13668.               case KRB_I_PA:            /* /PREAUTH */
  13669.           case KRB_I_FW:        /* /FORWARDABLE */
  13670.           case KRB_I_PR:        /* /PROXIABLE */
  13671.               case KRB_I_RN:        /* /RENEW */
  13672.           case KRB_I_VA:        /* /VALIDATE */
  13673.               case KRB_I_NPA:           /* /NOT-PREAUTH */
  13674.               case KRB_I_NFW:        /* /NOT-FORWARDABLE */
  13675.               case KRB_I_NPR:        /* /NOT-PROXIABLE */
  13676.               case KRB_I_VB:            /* /VERBOSE */
  13677.               case KRB_I_BR:            /* /BRIEF */
  13678.               case KRB_I_K4:            /* /KERBEROS4 */
  13679.               case KRB_I_NK4:           /* /NO-KERBEROS4 */
  13680.               case KRB_I_POP:           /* /POPUP */
  13681.               case KRB_I_NAD:           /* /NO-ADDRESSES */
  13682.         if (getval) {
  13683.             printf("?This switch does not take a value\n");
  13684.             rc = -9;
  13685.             goto kerbx;
  13686.         }
  13687.                 switch (n) {
  13688.           case KRB_I_NPA:
  13689.                     pv[KRB_I_PA].ival = 0;
  13690.                     break;
  13691.           case KRB_I_NFW:
  13692.                     pv[KRB_I_FW].ival = 0;
  13693.                     break;
  13694.           case KRB_I_NPR:
  13695.                     pv[KRB_I_PR].ival = 0;
  13696.                     break;
  13697.           case KRB_I_VB:
  13698.                     pv[KRB_I_BR].ival = 0;
  13699.                     break;
  13700.                   case KRB_I_NK4:
  13701.                     pv[KRB_I_K4].ival = 0;
  13702.                     break;
  13703.           default:
  13704.                     pv[n].ival = 1;
  13705.                 }
  13706.         break;
  13707.  
  13708.         /* These do take arguments */
  13709.  
  13710.           case KRB_I_RB:        /* /RENEWABLE:<minutes> */
  13711.         pv[n].ival = 0;
  13712.         if (!getval) break;
  13713.         if ((rc = cmnum("Minutes",ckitoa(krb5_init.renewable),
  13714.                 10,&y, xxstring)) < 0)
  13715.           goto kerbx;
  13716.         pv[n].ival = y;
  13717.         break;
  13718.  
  13719.           case KRB_I_LF:        /* /LIFETIME:<minutes> */
  13720.         pv[n].ival = 0;
  13721.         /* Default is previous value */
  13722.         sprintf(tmpbuf,"%d",    /* SAFE */
  13723.             kv == 4 ?
  13724.             krb4_init.lifetime :
  13725.             krb5_init.lifetime
  13726.             );
  13727.         if (!getval) break;
  13728.         if ((rc = cmnum("Minutes",tmpbuf,10,&y, xxstring)) < 0)
  13729.           goto kerbx;
  13730.         pv[n].ival = y;
  13731.         break;
  13732.  
  13733.           case KRB_I_PD:        /* /POSTDATE:<timestamp> */
  13734.         if (pv[n].sval) {
  13735.             free(pv[n].sval);
  13736.             pv[n].sval = NULL;
  13737.         }
  13738.         if (!getval) break;
  13739.         if ((rc = cmdate("date-time","",&s,0,xxstring)) < 0)
  13740.           goto kerbx;
  13741.         makestr(&(pv[n].sval),s);
  13742.         break;
  13743.  
  13744.           case KRB_I_SR:        /* /SERVICE:<name> */
  13745.         if (pv[n].sval) {
  13746.             free(pv[n].sval);
  13747.             pv[n].sval = NULL;
  13748.         }
  13749.         if (!getval) break;
  13750.         if ((rc = cmfld("Service-name","",&s,xxstring)) < 0)
  13751.           goto kerbx;
  13752.         makestr(&(pv[n].sval),s);
  13753.         break;
  13754.  
  13755.               case KRB_I_RL:        /* /REALM:<name> */
  13756.         if (pv[n].sval) {
  13757.             free(pv[n].sval);
  13758.             pv[n].sval = NULL;
  13759.         }
  13760.         if (!getval) break;
  13761.         if (kv == 4)
  13762.           p = krb4_d_realm ? krb4_d_realm : "";
  13763.         else
  13764.           p = krb5_d_realm ? krb5_d_realm : "";
  13765.         if ((rc = cmfld("Realm",p,&s,xxstring)) < 0)
  13766.           goto kerbx;
  13767.         makestr(&(pv[n].sval),s);
  13768.         break;
  13769.  
  13770.           case KRB_I_IN:        /* /INSTANCE:<name> */
  13771.         if (pv[n].sval) {
  13772.             free(pv[n].sval);
  13773.             pv[n].sval = NULL;
  13774.         }
  13775.         if (!getval) break;
  13776.                 if (kv == 4)
  13777.                     p = krb4_d_instance ? krb4_d_instance : "";
  13778.                 else
  13779.                     p = krb5_d_instance ? krb5_d_instance : "";
  13780.         if ((rc = cmfld("Instance",p,&s,xxstring)) < 0)
  13781.           goto kerbx;
  13782.         makestr(&(pv[n].sval),s);
  13783.         break;
  13784.  
  13785.           case KRB_I_PW:        /* /PASSWORD:<password> */
  13786.         debok = 0;
  13787.         if (pv[n].sval) {
  13788.             free(pv[n].sval);
  13789.             pv[n].sval = NULL;
  13790.         }
  13791.         if (!getval) break;
  13792.         if ((rc = cmfld("Password","",&s,xxstring)) < 0)
  13793.           if (rc != -3)
  13794.             goto kerbx;
  13795.         makestr(&(pv[n].sval),s);
  13796.         break;
  13797.  
  13798.               case KRB_I_ADR:        /* /ADDRESSES:{<address-list>} */
  13799.         if (pv[n].sval) {
  13800.             free(pv[n].sval);
  13801.             pv[n].sval = NULL;
  13802.         }
  13803.         if (!getval) break;
  13804.         if ((rc = cmfld("List of IP addresses","",&s,xxstring)) < 0)
  13805.           goto kerbx;
  13806.         makelist(s,tmpaddrs,KRB5_NUM_OF_ADDRS);
  13807.         for (i = 0; i < KRB5_NUM_OF_ADDRS && tmpaddrs[i]; i++) {
  13808.             if (inet_addr(tmpaddrs[i]) == 0xffffffff) {
  13809.             printf("invalid ip address: %s\n",tmpaddrs[i]);
  13810.             rc = -9;
  13811.             goto kerbx;
  13812.             }
  13813.         }
  13814.                 pv[KRB_I_NAD].ival = 0;
  13815.         break;
  13816.  
  13817.           default:
  13818.         printf("?Unexpected switch value - internal error\n");
  13819.         rc = -9;
  13820.         goto kerbx;
  13821.         }
  13822.     }
  13823.     if (cmresult.fcode != _CMFLD) {
  13824.         printf("?Unexected result - internal error\n");
  13825.         rc = -9;
  13826.         goto kerbx;
  13827.     }
  13828.         /* cmresult.sresult may be of the form PRINCIPAL@REALM */
  13829.         i = ckindex("@",cmresult.sresult,0,0,0);
  13830.         if (i != 0) {
  13831.             makestr(&tmprealm,&cmresult.sresult[i]);
  13832.             cmresult.sresult[i-1] = '\0';
  13833.         }
  13834.     makestr(&tmpprinz,cmresult.sresult); /* Principal (user) */
  13835.  
  13836.     if ((rc = cmcfm()) < 0)    {    /* Now get confirmation */
  13837.             if (rc == -3) {
  13838.         printf("?Principal name required\n");
  13839.             }
  13840.             goto kerbx;
  13841.         }
  13842.         if (!tmpprinz || !tmpprinz[0]) {
  13843.             printf("?Principal name required\n");
  13844.             goto kerbx;
  13845.         }
  13846.         if (!pv[KRB_I_RN].ival && !pv[KRB_I_VA].ival) {
  13847.             /* Don't use a password if Validating or Renewing */
  13848.         if (pv[KRB_I_PW].sval) {    /* If they gave a /PASSWORD switch */
  13849.         makestr(&tmppswd,pv[KRB_I_PW].sval); /* use this value */
  13850.         }
  13851. #ifdef COMMENT
  13852.             /* Password prompting has been moved to ck_krb[45]_initTGT() */
  13853.             else {            /* Otherwise must prompt for it */
  13854.         char prmpt[80];
  13855.                 if (pv[KRB_I_RL].sval)
  13856.           sprintf(prmpt,"%s@%s's Password: ",
  13857.               tmpprinz,pv[KRB_I_RL].sval);
  13858.                 else if (tmprealm)
  13859.           sprintf(prmpt,"%s@%s's Password: ",
  13860.               tmpprinz,tmprealm);
  13861.                 else
  13862.           sprintf(prmpt,"%s's Password: ",tmpprinz);
  13863. #ifdef OS2
  13864.                 if (pv[KRB_I_POP].ival) {
  13865.                     char passwd[80]="";
  13866.                     readpass(prmpt,passwd,80);
  13867.                     makestr(&tmppswd,passwd);
  13868.                     memset(passwd,0,80);
  13869.                 } else
  13870. #endif /* OS2 */
  13871.         {
  13872. #ifdef CK_RECALL
  13873.             on_recall = 0;
  13874. #endif /* CK_RECALL */
  13875.             cmsavp(psave,PROMPTL); /* Save old prompt */
  13876.             cmsetp(prmpt);    /* Make new prompt */
  13877.             concb((char)escape); /* Put console in cbreak mode */
  13878.             cmini(0);        /* and no-echo mode */
  13879.             /* Issue prompt if at top level */
  13880.             if (pflag) prompt(xxstring);
  13881.             cmres();        /* Reset the parser */
  13882.             for (rc = -1; rc < 0; ) { /* Prompt till they answer */
  13883.             /* Get a literal line of text */
  13884.             rc = cmtxt("","",&s,NULL);
  13885.             cmres();    /* Reset the parser again */
  13886.             }
  13887.             makestr(&tmppswd,s);
  13888.             printf("\n");    /* Echo a CRLF */
  13889.             cmsetp(psave);    /* Restore original prompt */
  13890.                 }
  13891.         }
  13892.         x = 0;            /* Check for password */
  13893.         if (tmppswd)
  13894.           if (*tmppswd)
  13895.         x = 1;
  13896.         if (!x) {
  13897.         printf("?Password required\n");
  13898.         goto kerbx;
  13899.         }
  13900. #endif /* COMMENT */
  13901.         }
  13902.     } else if (kv == 5 && tmp_action == KRB_A_LC) { /* LIST-CREDENTIALS */
  13903.     tmp_klc = 0;
  13904.     while (1) {
  13905.         if ((x = cmkey(klctab,nklctab,"Switch","",xxstring)) < 0) {
  13906.         if (x == -3) {
  13907.             if ((rc = cmcfm()) < 0)
  13908.               goto kerbx;
  13909.             else
  13910.               break;
  13911.         } else {
  13912.             rc = x;
  13913.             goto kerbx;
  13914.         }
  13915.         }
  13916.         tmp_klc |= x;
  13917.     }
  13918.     } else if ((rc = cmcfm()) < 0)    /* DESTROY, just confirm */
  13919.     goto kerbx;
  13920.  
  13921. /* Done - Move confirmed data to final locations */
  13922.  
  13923.     krb_action = tmp_action;        /* Action requested */
  13924.     krb_op.version = kv;        /* Kerberos version */
  13925.     krb_op.cache = tmpcache;        /* Cache file */
  13926.     tmpcache = NULL;            /* So we don't free it */
  13927.  
  13928.     switch (krb_action) {
  13929.       case KRB_A_IN:            /* INITIALIZE */
  13930.         if (kv == 5) {
  13931.             krb5_init.forwardable = pv[KRB_I_FW].ival;
  13932.             krb5_init.proxiable   = pv[KRB_I_PR].ival;
  13933.             krb5_init.lifetime    = pv[KRB_I_LF].ival;
  13934.             krb5_init.renew       = pv[KRB_I_RN].ival;
  13935.             krb5_init.renewable   = pv[KRB_I_RB].ival;
  13936.             krb5_init.validate    = pv[KRB_I_VA].ival;
  13937.  
  13938.             /* Here we just reassign the pointers and then set them to NULL */
  13939.             /* so they won't be freed below. */
  13940.  
  13941.             krb5_init.postdate = pv[KRB_I_PD].sval; pv[KRB_I_PD].sval = NULL;
  13942.             krb5_init.service  = pv[KRB_I_SR].sval; pv[KRB_I_SR].sval = NULL;
  13943.         if (pv[KRB_I_RL].sval) {
  13944.         krb5_init.realm  = pv[KRB_I_RL].sval; pv[KRB_I_RL].sval = NULL;
  13945.             } else if (tmprealm) {
  13946.                 krb5_init.realm = tmprealm; tmprealm = NULL;
  13947.             }
  13948.             if (pv[KRB_I_IN].sval) {
  13949.                 krb5_init.instance = pv[KRB_I_IN].sval;
  13950.         pv[KRB_I_IN].sval = NULL;
  13951.             } else if ( tmpinst ) {
  13952.                 krb5_init.instance = tmpinst;
  13953.         tmpinst = NULL;
  13954.             }
  13955.             if (tmpprinz) {
  13956.                 krb5_init.principal = tmpprinz;
  13957.                 tmpprinz = NULL;
  13958.             }
  13959.             krb5_init.password = tmppswd;
  13960.             tmppswd = NULL;
  13961.  
  13962.             krb5_init.getk4 = pv[KRB_I_K4].ival;
  13963.             if (krb5_init.getk4) {
  13964.                 krb4_init.lifetime = pv[KRB_I_LF].ival;
  13965.                 if (krb5_init.realm)
  13966.                     makestr(&krb4_init.realm,krb5_init.realm);
  13967.                 krb4_init.preauth  = krb4_d_preauth;
  13968.                 krb4_init.verbose  = pv[KRB_I_BR].ival ? 0 : 1;
  13969.                 if (krb5_init.principal)
  13970.                     makestr(&krb4_init.principal,krb5_init.principal);
  13971.                 if (krb5_init.principal)
  13972.                     makestr(&krb4_init.password,krb5_init.password);
  13973.             }
  13974.             krb5_init.no_addresses = pv[KRB_I_NAD].ival;
  13975.             if (tmpaddrs[0]) {
  13976.                 for (i = 0; i < KRB5_NUM_OF_ADDRS; i++) {
  13977.                     if (krb5_init.addrs[i]) {
  13978.                         free(krb5_init.addrs[i]);
  13979.                         krb5_init.addrs[i] = NULL;
  13980.                     }
  13981.                     krb5_init.addrs[i] = tmpaddrs[i];
  13982.                     tmpaddrs[i] = NULL;
  13983.                 }
  13984.             }
  13985.     } else if (kv == 4) {        /* Same deal for Kerberos 4 */
  13986.             krb4_init.lifetime = pv[KRB_I_LF].ival;
  13987.         if (pv[KRB_I_RL].sval) {
  13988.         krb4_init.realm  = pv[KRB_I_RL].sval;
  13989.         pv[KRB_I_RL].sval = NULL;
  13990.             } else if ( tmprealm ) {
  13991.                 krb4_init.realm  = tmprealm;
  13992.         tmprealm = NULL;
  13993.             }
  13994.             if (pv[KRB_I_IN].sval) {
  13995.                 krb4_init.instance = pv[KRB_I_IN].sval;
  13996.         pv[KRB_I_IN].sval = NULL;
  13997.             } else if ( tmpinst ) {
  13998.                 krb4_init.instance = tmpinst;
  13999.         tmpinst = NULL;
  14000.             }
  14001.             krb4_init.preauth  = pv[KRB_I_PA].ival;
  14002.             krb4_init.verbose  = pv[KRB_I_BR].ival ? 0 : 1;
  14003.  
  14004.             if (tmpprinz) {
  14005.                 krb4_init.principal = tmpprinz;
  14006.                 tmpprinz = NULL;
  14007.             }
  14008.             krb4_init.password = tmppswd;
  14009.             tmppswd = NULL;
  14010.         }
  14011.     break;
  14012.       case KRB_A_LC:            /* List Credentials */
  14013.     krb5_lc.encryption = tmp_klc & XYKLCEN;
  14014.     krb5_lc.flags = tmp_klc & XYKLCFL;
  14015.     krb5_lc.addr  = tmp_klc & XYKLCAD;
  14016.     break;
  14017.     }
  14018.  
  14019. /* Common exit - Free temporary storage */
  14020.  
  14021.   kerbx:
  14022.     for (i = 0; i <= KRB_I_MAX; i++) {    /* Free malloc'd switch data */
  14023.     if (pv[i].sval)
  14024.       free(pv[i].sval);
  14025.     }
  14026.     for (i = 0; i < KRB5_NUM_OF_ADDRS; i++) {
  14027.         if (tmpaddrs[i])
  14028.       free(tmpaddrs[i]);
  14029.     }
  14030.     if (tmpprinz) free(tmpprinz);    /* And these too. */
  14031.     if (tmppswd)  free(tmppswd);
  14032.     if (tmpcache) free(tmpcache);
  14033.     if (tmprealm) free(tmprealm);
  14034.     if (tmpinst)  free(tmpinst);
  14035.  
  14036.     return(rc);                /* Return the return code */
  14037. }
  14038. #endif /* CK_KERBEROS */
  14039.  
  14040. #ifdef CK_LOGIN
  14041. int
  14042. #ifdef CK_ANSIC
  14043. ckxlogin(CHAR * userid, CHAR * passwd, CHAR * acct, int promptok)
  14044. #else /* CK_ANSIC */
  14045. ckxlogin(userid, passwd, acct, promptok)
  14046.   CHAR * userid; CHAR * passwd; CHAR * acct; int promptok;
  14047. #endif /* CK_ANSIC */
  14048. /* ckxlogin */ {
  14049. #ifdef CK_RECALL
  14050.     extern int on_recall;        /* around Password prompting */
  14051. #endif /* CK_RECALL */
  14052. #ifdef CK_PAM
  14053.     extern int guest;
  14054. #endif /* CK_PAM */
  14055.     int rprompt = 0;            /* Restore prompt */
  14056. #ifdef CKSYSLOG
  14057.     int savlog;
  14058. #endif /* CKSYSLOG */
  14059.  
  14060.     extern int what, srvcdmsg;
  14061.  
  14062.     int x = 0, ok = 0, rc = 0;
  14063.     CHAR * _u = NULL, * _p = NULL, * _a = NULL;
  14064.  
  14065.     debug(F111,"ckxlogin userid",userid,promptok);
  14066.     debug(F110,"ckxlogin passwd",passwd,0);
  14067.  
  14068.     isguest = 0;            /* Global "anonymous" flag */
  14069.  
  14070.     if (!userid) userid = (CHAR *)"";
  14071.     if (!passwd) passwd = (CHAR *)"";
  14072.  
  14073.     debug(F111,"ckxlogin userid",userid,what);
  14074.  
  14075. #ifdef CK_RECALL
  14076.     on_recall = 0;
  14077. #endif /* CK_RECALL */
  14078.  
  14079. #ifdef CKSYSLOG
  14080.     savlog = ckxsyslog;            /* Save and turn off syslogging */
  14081. #endif /* CKSYSLOG */
  14082.  
  14083.     if ((!*userid || !*passwd) &&    /* Need to prompt for missing info */
  14084.     promptok) {
  14085.         cmsavp(psave,PROMPTL);        /* Save old prompt */
  14086.     debug(F110,"ckxlogin saved",psave,0);
  14087.     rprompt = 1;
  14088.     }
  14089.     if (!*userid) {
  14090.     if (!promptok)
  14091.       return(0);
  14092.         cmsetp("Username: ");            /* Make new prompt */
  14093.         concb((char)escape);        /* Put console in cbreak mode */
  14094.         cmini(1);
  14095.  
  14096. /* Flush typeahead */
  14097.  
  14098. #ifdef IKS_OPTION
  14099.     debug(F101,
  14100.           "ckxlogin TELOPT_SB(TELOPT_KERMIT).kermit.me_start",
  14101.           "",
  14102.           TELOPT_SB(TELOPT_KERMIT).kermit.me_start
  14103.           );
  14104. #endif /* IKS_OPTION */
  14105.  
  14106.     while (ttchk() > 0) {
  14107.         x = ttinc(0);
  14108.         debug(F101,"ckxlogin flush user x","",x);
  14109.             if (x < 0)
  14110.           doexit(GOOD_EXIT,0);    /* Connection lost */
  14111. #ifdef TNCODE
  14112.         if (sstelnet) {
  14113.         if (x == IAC) {
  14114.             x = tn_doop((CHAR)(x & 0xff),ckxech,ttinc);
  14115.             debug(F101,"ckxlogin user tn_doop","",x);
  14116. #ifdef IKS_OPTION
  14117.             debug(F101,
  14118.               "ckxlogin user TELOPT_SB(TELOPT_KERMIT).kermit.me_start",
  14119.               "",
  14120.               TELOPT_SB(TELOPT_KERMIT).kermit.me_start
  14121.               );
  14122. #endif /* IKS_OPTION */
  14123.  
  14124.             if (x < 0)
  14125.               goto XCKXLOG;
  14126.             switch (x) {
  14127.               case 1: ckxech = 1; break; /* Turn on echoing */
  14128.               case 2: ckxech = 0; break; /* Turn off echoing */
  14129. #ifdef IKS_OPTION
  14130.               case 4:             /* IKS event */
  14131.             if (!TELOPT_SB(TELOPT_KERMIT).kermit.me_start)
  14132.               break;         /* else fall thru... */
  14133. #endif /* IKS_OPTION */
  14134.               case 6:             /* Logout */
  14135.             goto XCKXLOG;
  14136.             }
  14137.         }
  14138.         }
  14139. #endif /* TNCODE */
  14140.     }
  14141.         if (pflag) prompt(xxstring);    /* Issue prompt if at top level */
  14142.         cmres();            /* Reset the parser */
  14143.         for (x = -1; x < 0;) {        /* Prompt till they answer */
  14144.         /* Get a literal line of text */
  14145.             x=cmtxt("Your username, or \"ftp\", or \"anonymous\"","",&s,NULL);
  14146.             if (x == -4 || x == -10) {
  14147.                 printf("\r\nLogin cancelled\n");
  14148. #ifdef CKSYSLOG
  14149.         ckxsyslog = savlog;
  14150. #endif /* CKSYSLOG */
  14151.                 doexit(GOOD_EXIT,0);
  14152.             }
  14153.         if (sstate)            /* Did a packet come instead? */
  14154.           goto XCKXLOG;
  14155.             cmres();            /* Reset the parser again */
  14156.         }
  14157.         if ((_u = (CHAR *)malloc((int)strlen(s) + 1)) == NULL) {
  14158.             printf("?Internal error: malloc\n");
  14159.         goto XCKXLOG;
  14160.         } else {
  14161.             strcpy((char *)_u,s);    /* safe */
  14162.             userid = _u;
  14163.         }
  14164.     }
  14165.     ok = zvuser((char *)userid);    /* Verify username */
  14166.     debug(F111,"ckxlogin zvuser",userid,ok);
  14167.  
  14168.     if (!*passwd && promptok
  14169. #ifdef CK_PAM
  14170.     && guest
  14171. #endif /* CK_PAM */
  14172.     ) {
  14173.         char prmpt[80];
  14174.  
  14175. #ifdef CKSYSLOG
  14176.         savlog = ckxsyslog;        /* Save and turn off syslogging */
  14177.         ckxsyslog = 0;
  14178. #endif /* CKSYSLOG */
  14179.  
  14180. /* Flush typeahead again */
  14181.  
  14182.     while (ttchk() > 0) {
  14183.         x = ttinc(0);
  14184.         debug(F101,"ckxlogin flush user x","",x);
  14185. #ifdef TNCODE
  14186.         if (sstelnet) {
  14187.         if (x == IAC) {
  14188.             x = tn_doop((CHAR)(x & 0xff),ckxech,ttinc);
  14189.             debug(F101,"ckxlogin pass tn_doop","",x);
  14190. #ifdef IKS_OPTION
  14191.             debug(F101,
  14192.               "ckxlogin pass TELOPT_SB(TELOPT_KERMIT).kermit.me_start",
  14193.               "",
  14194.               TELOPT_SB(TELOPT_KERMIT).kermit.me_start
  14195.               );
  14196. #endif /* IKS_OPTION */
  14197.             if (x < 0)
  14198.               goto XCKXLOG;
  14199.             switch (x) {
  14200.               case 1: ckxech = 1; break; /* Turn on echoing */
  14201.               case 2: ckxech = 0; break; /* Turn off echoing */
  14202.               case 4:             /* IKS event */
  14203.             if (!TELOPT_SB(TELOPT_KERMIT).kermit.me_start)
  14204.               break;         /* else fall thru... */
  14205.               case 6:             /* Logout */
  14206.             goto XCKXLOG;
  14207.             }
  14208.         }
  14209.         }
  14210. #endif /* TNCODE */
  14211.     }
  14212.         if (!strcmp((char *)userid,"anonymous") ||
  14213.         !strcmp((char *)userid,"ftp")) {
  14214.         if (!ok)
  14215.           goto XCKXLOG;
  14216.         ckstrncpy(prmpt,"Enter e-mail address as Password: ",80);
  14217.     } else if (*userid && strlen((char *)userid) < 60) {
  14218. #ifdef NT
  14219.             extern CHAR * pReferenceDomainName;
  14220.             if (pReferenceDomainName)
  14221.           ckmakxmsg(prmpt,
  14222.                80,
  14223.                "Enter ",
  14224.                pReferenceDomainName,
  14225.                "\\\\",
  14226.                userid,
  14227.                "'s Password: ",
  14228.                NULL,NULL,NULL,NULL,NULL,NULL,NULL
  14229.                );
  14230.             else
  14231. #endif /* NT */
  14232.           ckmakmsg(prmpt,80,"Enter ",(char *)userid,"'s Password: ",NULL);
  14233.         } else
  14234.       ckstrncpy(prmpt,"Enter Password: ",80);
  14235.     cmsetp(prmpt);            /* Make new prompt */
  14236.     concb((char)escape);        /* Put console in cbreak mode */
  14237.         if (strcmp((char *)userid,"anonymous") &&
  14238.         strcmp((char *)userid,"ftp")) { /* and if not anonymous */
  14239.         debok = 0;
  14240.         cmini(0);            /* and no-echo mode */
  14241.     } else {
  14242.         cmini(1);
  14243.     }
  14244.     if (pflag) prompt(xxstring);    /* Issue prompt if at top level */
  14245.     cmres();            /* Reset the parser */
  14246.     for (x = -1; x < 0;) {        /* Prompt till they answer */
  14247.         x = cmtxt("","",&s,NULL);    /* Get a literal line of text */
  14248.             if (x == -4 || x == -10) {
  14249.                 printf("\r\nLogin cancelled\r\n");
  14250. #ifdef CKSYSLOG
  14251.         ckxsyslog = savlog;
  14252. #endif /* CKSYSLOG */
  14253.                 doexit(GOOD_EXIT,0);
  14254.             }
  14255.         if (sstate)            /* In case of a Kermit packet */
  14256.           goto XCKXLOG;
  14257.         cmres();            /* Reset the parser again */
  14258.     }
  14259.     printf("\r\n");            /* Echo a CRLF */
  14260.     if ((_p = (CHAR *)malloc((int)strlen(s) + 1)) == NULL) {
  14261.         printf("?Internal error: malloc\n");
  14262.         goto XCKXLOG;
  14263.     } else {
  14264.         strcpy((char *)_p,s);    /* safe */
  14265.         passwd = _p;
  14266.     }
  14267.     }
  14268. #ifdef CK_PAM
  14269.     else {
  14270.     cmres();            /* Reset the parser */
  14271.  
  14272.     /* We restore the prompt now because the PAM engine will call  */
  14273.     /* readpass() which will overwrite psave. */
  14274.     if (rprompt) {
  14275.         cmsetp(psave);        /* Restore original prompt */
  14276.         debug(F110,"ckxlogin restored",psave,0);
  14277.         rprompt = 0;
  14278.     }
  14279.     }
  14280. #endif /* CK_PAM */
  14281.  
  14282. #ifdef CKSYSLOG
  14283.     ckxsyslog = savlog;
  14284. #endif /* CKSYSLOG */
  14285.  
  14286.     if (ok) {
  14287.     ok = zvpass((char *)passwd);    /* Check password */
  14288.     debug(F101,"ckxlogin zvpass","",ok);
  14289.     }
  14290.  
  14291.     if (ok > 0 && isguest) {
  14292. #ifndef NOPUSH
  14293.     nopush = 1;
  14294. #endif /* NOPUSH */
  14295.     srvcdmsg = 1;
  14296.     }
  14297.     rc = ok;                /* Set the return code */
  14298.     if ((char *)uidbuf != (char *)userid)
  14299.       ckstrncpy(uidbuf,(char *)userid,UIDBUFLEN); /* Remember username */
  14300.  
  14301.   XCKXLOG:                /* Common exit */
  14302. #ifdef CKSYSLOG
  14303.     ckxsyslog = savlog;            /* In case of GOTO above */
  14304. #endif /* CKSYSLOG */
  14305.     if (rprompt) {
  14306.     cmsetp(psave);            /* Restore original prompt */
  14307.     debug(F110,"ckxlogin restored",psave,0);
  14308.     }
  14309.     if (_u || _p || _a) {
  14310.         if (_u) free(_u);
  14311.         if (_p) free(_p);
  14312.         if (_a) free(_a);
  14313.     }
  14314.     return(rc);
  14315. }
  14316.  
  14317. int
  14318. ckxlogout() {
  14319.     doexit(GOOD_EXIT,0);        /* doexit calls zvlogout */
  14320.     return(0);                /* not reached */
  14321. }
  14322. #endif /* CK_LOGIN */
  14323. #endif /* NOICP */
  14324.