home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / cku201.zip / ckuus3.c < prev    next >
C/C++ Source or Header  |  2002-02-03  |  431KB  |  12,520 lines

  1. #ifdef SSHTEST
  2. #define SSHBUILTIN
  3. #endif /* SSHTEST */
  4.  
  5. #include "ckcsym.h"                     /* Symbol definitions */
  6.  
  7. /*  C K U U S 3 --  "User Interface" for C-Kermit, part 3  */
  8.  
  9. /*
  10.   Author: Frank da Cruz <fdc@columbia.edu>,
  11.   Columbia University Academic Information Systems, New York City.
  12.  
  13.   Copyright (C) 1985, 2002,
  14.     Trustees of Columbia University in the City of New York.
  15.     All rights reserved.  See the C-Kermit COPYING.TXT file or the
  16.     copyright text in the ckcmai.c module for disclaimer and permissions.
  17. */
  18.  
  19. /*  SET command (but much material has been split off into ckuus7.c). */
  20.  
  21. /*
  22.   Kermit-specific includes.
  23.   Definitions here supersede those from system include files.
  24. */
  25. #include "ckcdeb.h"                     /* Debugging & compiler things */
  26. #include "ckcasc.h"                     /* ASCII character symbols */
  27. #include "ckcker.h"                     /* Kermit application definitions */
  28. #include "ckcxla.h"                     /* Character set translation */
  29. #include "ckcnet.h"                     /* Network symbols */
  30.  
  31. char pwbuf[PWBUFL+1]  = { NUL, NUL };
  32. int pwflg = 0;
  33. int pwcrypt = 0;
  34.  
  35. #ifndef NOICP
  36.  
  37. #ifdef CK_AUTHENTICATION
  38. #include "ckuath.h"
  39. #endif /* CK_AUTHENTICATION */
  40. #ifdef CK_SSL
  41. #include "ck_ssl.h"
  42. #endif /* CK_SSL */
  43. #include "ckuusr.h"                     /* User interface symbols */
  44. #ifdef OS2
  45. #ifdef SSHBUILTIN
  46. #include "ckossh.h"
  47. #endif /* SSHBUILTIN */
  48. #ifdef CK_NETBIOS
  49. #include <os2.h>
  50. #ifdef COMMENT                          /* Would you believe */
  51. #undef COMMENT                          /* <os2.h> defines this ? */
  52. #endif /* COMMENT */
  53. #include "ckonbi.h"
  54. extern UCHAR NetBiosAdapter;
  55. #endif /* CK_NETBIOS */
  56. #include "ckocon.h"
  57. #include "ckokey.h"
  58. #ifndef NOTERM
  59. extern unsigned char colorcmd;  /* Command-screen colors */
  60. extern struct keytab ttyclrtab[];
  61. extern int nclrs;
  62. extern int tt_cols[], tt_rows[], tt_szchng[], tt_status[];
  63. #endif /* NOTERM */
  64. _PROTOTYP(int setprty, (void));
  65. extern char startupdir[], exedir[];
  66. extern int tt_modechg;
  67. #ifdef NT
  68. #include <windows.h>
  69. #include <tapi.h>
  70. #include "ckntap.h"                     /* Microsoft TAPI */
  71. #endif /* NT */
  72. #endif /* OS2 */
  73.  
  74. #ifndef OS2
  75. extern char * exedir;
  76. #endif /* OS2 */
  77.  
  78. #ifdef CK_RECALL
  79. extern int cm_retry;
  80. #endif /* CK_RECALL */
  81.  
  82. extern int cmdint;
  83. extern int srvidl;
  84.  
  85. #ifndef NOPUSH
  86. #ifndef NOFRILLS
  87. #ifdef VMS
  88. char editor[CKMAXPATH + 1] = "edit";
  89. #else
  90. char editor[CKMAXPATH + 1] = { NUL, NUL };
  91. #endif /* VMS */
  92. char editopts[128] = { NUL, NUL };
  93. char editfile[CKMAXPATH + 1] = { NUL, NUL };
  94. #ifdef BROWSER
  95. char browser[CKMAXPATH + 1] = { NUL, NUL };
  96. char browsopts[128] = { NUL, NUL };
  97. char browsurl[4096] = { NUL, NUL };
  98. #endif /* BROWSER */
  99. #endif /*  NOFRILLS */
  100. #endif /* NOPUSH */
  101.  
  102. /* Variables */
  103.  
  104. int cmd_quoting = 1;
  105. extern int hints, xcmdsrc;
  106.  
  107. #ifdef CK_KERBEROS
  108. char * k4pwprompt = NULL;               /* Kerberos 4 password prompt */
  109. char * k4prprompt = NULL;               /* Kerberos 4 principal prompt */
  110. char * k5pwprompt = NULL;               /* Kerberos 5 password prompt */
  111. char * k5prprompt = NULL;               /* Kerberos 5 principal prompt */
  112. #endif /* CK_KERBEROS */
  113. #ifdef CK_SRP
  114. char * srppwprompt = NULL;
  115. #endif /* CK_SRP */
  116.  
  117. extern char * ckprompt, * ikprompt;     /* Default prompt */
  118. extern xx_strp xxstring;
  119.  
  120. extern char * cdmsgfile[], * cdmsgstr;
  121.  
  122. extern int
  123.   local, server, success, dest, sleepcan, inserver, flow, autoflow, binary,
  124.   parity, escape, what, turn, duplex, backgrd, hwparity, stopbits, turnch,
  125.   mdmtyp, network, quiet, nettype, carrier, debses, debtim, cdtimo, nlangs,
  126.   bgset, pflag, msgflg, cmdmsk, suspend, techo, pacing, xitwarn, xitsta,
  127.   outesc, cmd_cols, cmd_rows, ckxech, xaskmore, haveline, didsetlin, isguest,
  128.   mdmsav, clearrq, saveask;
  129.  
  130. extern int reliable, setreliable;
  131.  
  132. #ifndef NOSERVER
  133.   extern int en_pri;
  134. #endif /* NOSERVER */
  135.  
  136. #ifdef IKSDCONF
  137. extern int iksdcf;
  138. #endif /* IKSDCONF */
  139. #ifdef TCPSOCKET
  140.   extern int tn_exit;
  141. #endif /* TCPSOCKET */
  142. #ifdef TNCODE
  143.   char * tn_pr_uid = NULL;
  144. #endif /* TNCODE */
  145.   extern int exitonclose;
  146.  
  147. #ifndef NOKVERBS
  148. extern int nkverbs;
  149. extern struct keytab kverbs[];
  150. #endif /* NOKVERBS */
  151.  
  152. extern int ttnproto;                    /* Network protocol */
  153.  
  154. extern char *ccntab[];                  /* Names of control chars */
  155.  
  156. #ifdef CK_APC
  157. extern int apcactive, apcstatus;
  158. #endif /* CK_APC */
  159.  
  160. #ifndef NOSCRIPT
  161. extern int secho;                       /* Whether SCRIPT cmd should echo */
  162. #endif /* NOSCRIPT */
  163.  
  164. #ifdef DCMDBUF
  165. extern char *atmbuf, *atxbuf;
  166. #else
  167. extern char atmbuf[], atxbuf[];
  168. #endif /* DCMDBUF */
  169. extern int cmflgs;
  170.  
  171. extern char psave[];
  172. extern char uidbuf[];
  173. extern int  sl_uid_saved;
  174. int DeleteStartupFile = 0;
  175.  
  176. extern int cmdlvl;                      /* Overall command level */
  177.  
  178. #ifndef NOSPL
  179. _PROTOTYP( static int parsdir, (int) );
  180. char prmbuf[PWBUFL+1] = { NUL, NUL };
  181. int fndiags = 1;                        /* Function diagnostics on/off */
  182. int fnerror = 1;                        /* Function error treatment */
  183.  
  184. #ifdef DCMDBUF
  185. extern int *count, *takerr, *merror, *inpcas;
  186. #else
  187. extern int count[], takerr[], merror[], inpcas[];
  188. #endif /* DCMDBUF */
  189. extern int mecho;                       /* Macro echo */
  190. extern long ck_alarm;
  191. extern char alrm_date[], alrm_time[];
  192. #else
  193. extern int takerr[];
  194. #endif /* NOSPL */
  195.  
  196. extern int x_ifnum;
  197. extern int bigsbsiz, bigrbsiz;          /* Packet buffers */
  198.  
  199. extern long speed;                      /* Terminal speed */
  200.  
  201. extern char ttname[];                   /* Communication device name */
  202. extern char myhost[] ;
  203. extern char inidir[];                   /* Ini File directory */
  204.  
  205. #ifndef NOSETKEY
  206. extern KEY *keymap;                     /* Character map for SET KEY (1:1)  */
  207. extern MACRO *macrotab;                 /* Macro map for SET KEY (1:string) */
  208. #endif /* NOSETKEY */
  209. #ifdef OS2
  210. int wideresult;                         /* For wide OS/2 scan codes/cmnum() */
  211. #endif /* OS2 */
  212.  
  213. #ifndef NOLOCAL
  214. #ifdef OS2
  215. extern int tt_scrsize[];                /* Scrollback buffer Sizes */
  216. #endif /* OS2 */
  217. #endif /* NOLOCAL */
  218.  
  219. /* Printer settings */
  220.  
  221. extern char * printername;              /* NULL if printer not redirected */
  222. extern int printpipe;
  223. extern int noprinter;
  224. #ifdef PRINTSWI
  225. int printtimo = 0;
  226. char * printterm = NULL;
  227. char * printsep = NULL;
  228. int printertype = 0;
  229. #ifdef BPRINT
  230. int printbidi = 0;                      /* SET BPRINTER (bidirectional) */
  231. long pportspeed = 0L;                   /* Bidirection printer port speed, */
  232. int pportparity = 0;                    /*  parity, */
  233. int pportflow = FLO_KEEP;               /*  and flow control */
  234. #endif /* BPRINT */
  235. #ifdef OS2
  236. extern int txt2ps;                      /* Text2PS conversion? */
  237. extern int ps_width, ps_length;         /* Text2PS dimensions */
  238. #endif /* OS2 */
  239. #endif /* PRINTSWI */
  240.  
  241. #ifdef OS2
  242. extern int tcp_avail;                   /* Nonzero if TCP/IP is available */
  243. #ifdef DECNET
  244. extern int dnet_avail;                  /* Ditto for DECnet */
  245. #endif /* DECNET */
  246. #ifdef SUPERLAT
  247. extern int slat_avail;
  248. #endif /* SUPERLAT */
  249. #endif /* OS2 */
  250.  
  251. static struct keytab logintab[] = {
  252.     { "password", LOGI_PSW, CM_INV },
  253.     { "prompt",   LOGI_PRM, CM_INV },
  254.     { "userid",   LOGI_UID, 0 }
  255. };
  256.  
  257. #ifndef NOCSETS
  258. /* system-independent character sets, defined in ckcxla.[ch] */
  259. extern struct csinfo tcsinfo[];
  260. extern struct langinfo langs[];
  261.  
  262. /* Other character-set related variables */
  263. extern int tcharset, tslevel, language;
  264. #endif /* NOCSETS */
  265.  
  266. /* File-transfer variable declarations */
  267.  
  268. #ifndef NOXFER
  269. #ifdef CK_AUTODL
  270. extern int cmdadl;
  271. #endif /* CK_AUTODL */
  272.  
  273. #ifndef NOSERVER
  274. extern int ngetpath;
  275. extern char * getpath[];
  276. #endif /* NOSERVER */
  277.  
  278. extern struct ck_p ptab[];
  279.  
  280. extern CHAR sstate;                     /* Protocol start state */
  281. extern CHAR myctlq;                     /* Control-character prefix */
  282. extern CHAR myrptq;                     /* Repeat-count prefix */
  283.  
  284. extern int protocol, size, spsiz, spmax, urpsiz, srvtim, srvcdmsg, slostart,
  285.   srvdis, xfermode, ckdelay, keep, maxtry, unkcs, bctr, ebqflg, swcapr,
  286.   wslotr, lscapr, lscapu, spsizr, rptena, rptmin, docrc, xfrcan, xfrchr,
  287.   xfrnum, xfrbel, xfrint, srvping, g_xfermode, xfrxla;
  288.  
  289. #ifdef PIPESEND
  290. extern int usepipes;
  291. #endif /* PIPESEND */
  292.  
  293. #ifdef CKXXCHAR                         /* DOUBLE / IGNORE char table */
  294. extern int dblflag, ignflag, dblchar;
  295. extern short dblt[];
  296. #endif /* CKXXCHAR */
  297.  
  298. #ifdef CK_SPEED
  299. extern short ctlp[];                    /* Control-prefix table */
  300. extern int prefixing;
  301. static struct keytab pfxtab[] = {
  302.     "all",         PX_ALL, 0,
  303.     "cautious",    PX_CAU, 0,
  304.     "minimal",     PX_WIL, 0,
  305.     "none",        PX_NON, CM_INV
  306. };
  307. #endif /* CK_SPEED */
  308. #endif /* NOXFER */
  309.  
  310. /* Declarations from cmd package */
  311.  
  312. #ifdef DCMDBUF
  313. extern char *cmdbuf;                    /* Command buffer */
  314. extern char *line;
  315. extern char *tmpbuf;
  316. #else
  317. extern char cmdbuf[];                   /* Command buffer */
  318. extern char line[];                     /* Character buffer for anything */
  319. extern char tmpbuf[];
  320. #endif /* DCMDBUF */
  321.  
  322. /* From main ckuser module... */
  323.  
  324. extern char *tp, *lp;                   /* Temporary buffer */
  325.  
  326. extern int tlevel;                      /* Take Command file level */
  327.  
  328. #ifndef NOLOCAL
  329. extern int sessft;                      /* Session-log file type */
  330. extern int slogts;                      /* Session-log timestamps on/off */
  331. #endif /* NOLOCAL */
  332.  
  333. char * tempdir = NULL;
  334.  
  335. #ifdef VMS
  336. int vms_msgs = 1;                       /* SET MESSAGES */
  337. extern int batch;
  338. #endif /* VMS */
  339.  
  340. /* Keyword tables for SET commands */
  341.  
  342. #ifdef CK_SPEED
  343. struct keytab ctltab[] = {
  344.     "prefixed",   1, 0,                 /* Note, the values are important. */
  345.     "unprefixed", 0, 0
  346. };
  347. #endif /* CK_SPEED */
  348.  
  349. static struct keytab oldnew[] = {
  350.     "new", 0, 0,
  351.     "old", 1, 0
  352. };
  353.  
  354. #ifndef NOSPL
  355. static struct keytab functab[] = {
  356.     "diagnostics", FUNC_DI, 0,
  357.     "error",       FUNC_ER, 0
  358. };
  359. static int nfunctab = (sizeof(functab) / sizeof(struct keytab));
  360.  
  361. struct keytab outptab[] = {             /* SET OUTPUT parameters */
  362.     "pacing", 0, 0,                     /* only one so far... */
  363.     "special-escapes", 1, 0
  364. };
  365. int noutptab = (sizeof(outptab) / sizeof(struct keytab)); /* How many */
  366. #endif /* NOSPL */
  367.  
  368. struct keytab chktab[] = {              /* Block check types */
  369.     "1", 1, 0,                          /* 1 =  6-bit checksum */
  370.     "2", 2, 0,                          /* 2 = 12-bit checksum */
  371.     "3", 3, 0,                          /* 3 = 16-bit CRC */
  372.     "4", 4, CM_INV,                     /* Same as B */
  373.     "blank-free-2", 4, 0                /* B = 12-bit checksum, no blanks */
  374. };
  375.  
  376. struct keytab rpttab[] = {              /* SET REPEAT */
  377.     "counts",    0, 0,                  /* On or Off */
  378. #ifdef COMMENT
  379.     "minimum",   1, 0,                  /* Threshhold */
  380. #endif /* COMMENT */
  381.     "prefix",    2, 0                   /* Repeat-prefix character value */
  382. };
  383.  
  384. #ifndef NOLOCAL
  385. /* For SET [ MODEM ] CARRIER, and also for SET DIAL CONNECT */
  386.  
  387. struct keytab crrtab[] = {
  388.     "automatic", CAR_AUT, 0,            /* 2 */
  389.     "off",       CAR_OFF, 0,            /* 0 */
  390.     "on",        CAR_ON,  0             /* 1 */
  391. };
  392. int ncrr = 3;
  393. #endif /* NOLOCAL */
  394.  
  395. struct keytab ooatab[] = {              /* On/Off/Auto table */
  396.     "automatic", SET_AUTO, 0,           /* 2 */
  397.     "off",       SET_OFF,  0,           /* 0 */
  398.     "on",        SET_ON,   0            /* 1 */
  399. };
  400.  
  401. struct keytab ooktab[] = {              /* On/Off/Ask table */
  402.     "ask",       3,        0,           /* 3 */
  403.     "off",       SET_OFF,  0,           /* 0 */
  404.     "on",        SET_ON,   0            /* 1 */
  405. };
  406.  
  407. struct keytab qvtab[] = {               /* Quiet/Verbose table */
  408.     "quiet", 1, 0,
  409.     "verbose", 0, 0
  410. };
  411. int nqvt = 2;
  412.  
  413. /* For SET DEBUG */
  414.  
  415. #define DEB_OFF  0
  416. #define DEB_ON   1
  417. #define DEB_SES  2
  418. #define DEB_TIM  3
  419. #define DEB_LEN  4
  420.  
  421. struct keytab dbgtab[] = {
  422.     "linelength", DEB_LEN, CM_INV,
  423.     "off",        DEB_OFF, 0,
  424.     "on",         DEB_ON,  0,
  425.     "session",    DEB_SES, 0,
  426.     "timestamps", DEB_TIM, 0
  427. };
  428. int ndbg = (sizeof(dbgtab) / sizeof(struct keytab));
  429.  
  430. #ifndef NOLOCAL
  431. /* Transmission speeds */
  432.  
  433. #ifdef TTSPDLIST /* Speed table constructed at runtime . . . */
  434.  
  435. struct keytab * spdtab = NULL;
  436. int nspd = 0;
  437.  
  438. #else
  439. /*
  440.   Note, the values are encoded in cps rather than bps because 19200 and higher
  441.   are too big for some ints.  All but 75bps are multiples of ten.  Result of
  442.   lookup in this table must be multiplied by 10 to get actual speed in bps.
  443.   If this number is 70, it must be changed to 75.  If it is 888, this means
  444.   75/1200 split speed.
  445.  
  446.   The values are generic, rather than specific to UNIX.  We can't use B75,
  447.   B1200, B9600, etc, because non-UNIX versions of C-Kermit will not
  448.   necessarily have these symbols defined.  The BPS_xxx symbols are
  449.   Kermit-specific, and are defined in ckcdeb.h or on the CC command line.
  450.  
  451.   Like all other keytabs, this one must be in "alphabetical" order,
  452.   rather than numeric order.
  453. */
  454. struct keytab spdtab[] = {
  455.     "0",      0,  CM_INV,
  456.     "110",   11,  0,
  457. #ifdef BPS_115K
  458.  "115200",11520,  0,
  459. #endif /* BPS_115K */
  460.   "1200",   120,  0,
  461. #ifdef BPS_134
  462.   "134.5",  134,  0,
  463. #endif /* BPS_134 */
  464. #ifdef BPS_14K
  465.   "14400", 1440,  0,
  466. #endif /* BPS_14K */
  467. #ifdef BPS_150
  468.   "150",     15,  0,
  469. #endif /* BPS_150 */
  470. #ifdef BPS_1800
  471.   "1800",     180,  0,
  472. #endif /* BPS_150 */
  473. #ifdef BPS_19K
  474.   "19200", 1920,  0,
  475. #endif /* BPS_19K */
  476. #ifdef BPS_200
  477.   "200",     20,  0,
  478. #endif /* BPS_200 */
  479. #ifdef BPS_230K
  480.   "230400", 23040, 0,
  481. #endif /* BPS_230K */
  482.   "2400",   240,  0,
  483. #ifdef BPS_28K
  484.   "28800", 2880,  0,
  485. #endif /* BPS_28K */
  486.   "300",     30,  0,
  487. #ifdef BPS_3600
  488.   "3600",   360,  0,
  489. #endif /* BPS_3600 */
  490. #ifdef BPS_38K
  491.   "38400", 3840,  0,
  492. #endif /* BPS_38K */
  493. #ifdef BPS_460K
  494.   "460800", 46080,  0,                  /* Need 32 bits for this... */
  495. #endif /* BPS_460K */
  496.   "4800",   480,  0,
  497. #ifdef BPS_50
  498.   "50",       5,  0,
  499. #endif /* BPS_50 */
  500. #ifdef BPS_57K
  501.   "57600", 5760,  0,
  502. #endif /* BPS_57K */
  503.   "600",     60,  0,
  504. #ifdef BPS_7200
  505.   "7200",   720,  0,
  506. #endif /* BPS_7200 */
  507. #ifdef BPS_75
  508.   "75",       7,  0,
  509. #endif /* BPS_75 */
  510. #ifdef BPS_7512
  511.   "75/1200",888,  0,                    /* Code "888" for split speed */
  512. #endif /* BPS_7512 */
  513. #ifdef BPS_76K
  514.   "76800", 7680,  0,
  515. #endif /* BPS_76K */
  516. #ifdef BPS_921K
  517.   "921600", 92160,0,                    /* Need 32 bits for this... */
  518. #endif /* BPS_921K */
  519.   "9600",   960,  0
  520. };
  521. int nspd = (sizeof(spdtab) / sizeof(struct keytab)); /* How many speeds */
  522. #endif /* TTSPDLIST */
  523.  
  524. #ifdef TN_COMPORT
  525. struct keytab tnspdtab[] = {            /* RFC 2217 TELNET COMPORT Option */
  526.     "115200", 11520,  0,                /* (add any other defined speeds) */
  527.     "1200",     120,  0,
  528.     "14400",   1440,  0,
  529.     "19200",   1920,  0,
  530.     "230400", 23040,  0,
  531.     "2400",     240,  0,
  532.     "28800",   2880,  0,
  533.     "300",       30,  0,
  534.     "38400",   3840,  0,
  535.     "460800", 46080,  0,
  536.     "4800",     480,  0,
  537.     "57600",   5760,  0,
  538.     "600",       60,  0,
  539.     "9600",     960,  0
  540. };
  541. int ntnspd = (sizeof(tnspdtab) / sizeof(struct keytab)); /* How many speeds */
  542. #endif /* TN_COMPORT */
  543. #endif /* NOLOCAL */
  544.  
  545. #ifndef NOCSETS
  546. extern struct keytab lngtab[];          /* Languages for SET LANGUAGE */
  547. extern int nlng;
  548. #endif /* NOCSETS */
  549.  
  550. #ifndef NOLOCAL
  551. /* Duplex keyword table */
  552.  
  553. struct keytab dpxtab[] = {
  554.     "full",      0, 0,
  555.     "half",      1, 0
  556. };
  557. #endif /* NOLOCAL */
  558.  
  559. /* Flow Control */
  560.  
  561. struct keytab cxtypesw[] = {
  562. #ifdef DECNET
  563.     "/decnet",         CXT_DECNET,  0,
  564. #endif /* DECNET */
  565.     "/direct-serial",  CXT_DIRECT,  0,
  566. #ifdef DECNET
  567.     "/lat",            CXT_LAT,     0,
  568. #else
  569. #ifdef SUPERLAT
  570.     "/lat",            CXT_LAT,     0,
  571. #endif /* SUPERLAT */
  572. #endif /* DECNET */
  573.     "/modem",          CXT_MODEM,   0,
  574. #ifdef NPIPE
  575.     "/named-pipe",     CXT_NPIPE,   0,
  576. #endif /* NPIPE */
  577. #ifdef NETBIOS
  578.     "/netbios",        CXT_NETBIOS, 0,
  579. #endif /* NETBIOS */
  580.     "/remote",         CXT_REMOTE,  0,
  581. #ifdef TCPSOCKET
  582.     "/tcpip",          CXT_TCPIP,   0,
  583. #endif /* TCPSOCKET */
  584. #ifdef ANYX25
  585.     "/x.25",           CXT_X25,     0,
  586. #endif /* ANYX25 */
  587.     "", 0, 0
  588. };
  589. int ncxtypesw = (sizeof(cxtypesw) / sizeof(struct keytab));
  590.  
  591. #ifdef TN_COMPORT
  592. struct keytab tnflotab[] = {            /* SET FLOW-CONTROL keyword table */
  593.     "dtr/cd",    FLO_DTRC, 0,           /* for RFC 2217 Telnet COMPORT */
  594.     "dtr/cts",   FLO_DTRT, 0,
  595.     "keep",      FLO_KEEP, 0,
  596.     "none",      FLO_NONE, 0,
  597.     "rts/cts",   FLO_RTSC, 0,
  598.     "xon/xoff",  FLO_XONX, 0
  599. };
  600. int ntnflo = (sizeof(tnflotab) / sizeof(struct keytab));
  601. #endif /* TN_COMPORT */
  602.  
  603. struct keytab flotab[] = {              /* SET FLOW-CONTROL keyword table */
  604.     "automatic", FLO_AUTO, CM_INV,      /* Not needed any more */
  605. #ifdef CK_DTRCD
  606.     "dtr/cd",    FLO_DTRC, 0,
  607. #endif /* CK_DTRCD */
  608. #ifdef CK_DTRCTS
  609.     "dtr/cts",   FLO_DTRT, 0,
  610. #endif /* CK_DTRCTS */
  611.     "keep",      FLO_KEEP, 0,
  612.     "none",      FLO_NONE, 0,
  613. #ifdef CK_RTSCTS
  614.     "rts/cts",   FLO_RTSC, 0,
  615. #endif /* CK_RTSCTS */
  616. #ifndef Plan9
  617.     "xon/xoff",  FLO_XONX, 0,
  618. #endif /* Plan9 */
  619.     "", 0, 0
  620. };
  621. int nflo = (sizeof(flotab) / sizeof(struct keytab)) - 1;
  622.  
  623. /*  Handshake characters  */
  624.  
  625. struct keytab hshtab[] = {
  626.     "bell", 007, 0,
  627.     "code", 998, 0,
  628.     "cr",   015, 0,
  629.     "esc",  033, 0,
  630.     "lf",   012, 0,
  631.     "none", 999, 0,                     /* (can't use negative numbers) */
  632.     "xoff", 023, 0,
  633.     "xon",  021, 0
  634. };
  635. int nhsh = (sizeof(hshtab) / sizeof(struct keytab));
  636.  
  637. #ifndef NOLOCAL
  638. static struct keytab sfttab[] = {       /* File types for SET SESSION-LOG */
  639.     "ascii",     XYFT_T, CM_INV,
  640.     "binary",    XYFT_B, 0,
  641.     "debug",     XYFT_D, 0,
  642.     "text",      XYFT_T, 0,
  643.     "timestamped-text", 999, 0
  644. };
  645. static int nsfttab = (sizeof(sfttab) / sizeof(struct keytab));
  646. #endif /* NOLOCAL */
  647.  
  648. #ifndef NODIAL
  649.  
  650. #ifdef NETCONN                          /* Networks directory depends */
  651. int nnetdir = 0;                        /* on DIAL code -- fix later... */
  652. char *netdir[MAXDDIR+2];
  653. #endif /* NETCONN */
  654.  
  655. _PROTOTYP( static int setdial, (int) );
  656. _PROTOTYP( static int setdcd, (void) );
  657. _PROTOTYP( static int cklogin, (void) );
  658.  
  659. #ifndef MINIDIAL
  660. #ifdef OLDTBCODE
  661. extern int tbmodel;                     /* Telebit model ID */
  662. #endif /* OLDTBCODE */
  663. #endif /* MINIDIAL */
  664.  
  665. extern MDMINF *modemp[];                /* Pointers to modem info structs */
  666. extern struct keytab mdmtab[];          /* Modem types (in module ckudia.c) */
  667. extern int nmdm;                        /* Number of them */
  668.  
  669. _PROTOTYP(static int dialstr,(char **, char *));
  670.  
  671. extern int dialhng, dialtmo, dialksp, dialdpy, dialmhu, dialec, dialdc;
  672. extern int dialrtr, dialint, dialudt, dialsrt, dialrstr, mdmwaitd;
  673. extern int mdmspd, dialfc, dialmth, dialesc, dialfld, dialidt, dialpace;
  674. extern int mdmspk, mdmvol, dialtest;
  675.  
  676. int dialcvt = 2;                        /* DIAL CONVERT-DIRECTORY */
  677. int dialcnf = 0;                        /* DIAL CONFIRMATION */
  678. int dialcon = 2;                        /* DIAL CONNECT */
  679. int dialcq  = 0;                        /* DIAL CONNECT AUTO quiet/verbose */
  680. extern long dialmax, dialcapas;
  681. int usermdm = 0;
  682. extern int ndialdir;
  683. extern char *dialini,   *dialmstr, *dialmprmt, *dialdir[], *dialcmd,  *dialnpr,
  684.  *dialdcon, *dialdcoff, *dialecon, *dialecoff, *dialhcmd,  *dialx3,
  685.  *dialhwfc, *dialswfc,  *dialnofc, *dialtone,  *dialpulse, *dialname, *diallac;
  686. extern char *diallcc,   *dialixp,  *dialixs,   *dialldp,   *diallds,  *dialtfp,
  687.  *dialpxi,  *dialpxo,   *dialsfx,  *dialaaon,  *dialaaoff;
  688. extern char *diallcp,   *diallcs,  *dialini2,  *dialmac;
  689. extern char *dialspoff, *dialspon, *dialvol1,  *dialvol2,  *dialvol3;
  690.  
  691. char *dialtocc[MAXTPCC] = { NULL, NULL };
  692. int ndialtocc = 0;
  693. char *dialpucc[MAXTPCC] = { NULL, NULL };
  694. int ndialpucc = 0;
  695.  
  696. char *dialtfc[MAXTOLLFREE] = {
  697.     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
  698. };
  699. int ntollfree = 0;
  700.  
  701. char *dialpxx[MAXPBXEXCH] = {
  702.     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
  703. };
  704. int ndialpxx = 0;
  705.  
  706. char *diallcac[MAXLOCALAC] = {
  707.     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  708.     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  709.     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  710.     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
  711. };
  712. int nlocalac = 0;
  713.  
  714. static struct keytab drstrtab[] = {
  715.     "international", 5, 0,
  716.     "local",         2, 0,
  717.     "long-distance", 4, 0,
  718.     "none",          6, 0
  719. };
  720.  
  721. static struct keytab dcnvtab[] = {
  722.     "ask",  2, 0,
  723.     "off",  0, 0,
  724.     "on",   1, 0
  725. };
  726.  
  727. struct keytab setmdm[] = {
  728.     "capabilities",     XYDCAP,  0,
  729.     "carrier-watch",    XYDMCD,  0,
  730.     "command",          XYDSTR,  0,
  731.     "compression",      XYDDC,   CM_INV,
  732.     "data-compression", XYDDC,   0,
  733.     "dial-command",     XYDDIA,  0,
  734.     "error-correction", XYDEC,   0,
  735.     "escape-character", XYDESC,  0,
  736.     "flow-control",     XYDFC,   0,
  737.     "hangup-method",    XYDMHU,  0,
  738. #ifndef NOXFER
  739.     "kermit-spoof",     XYDKSP,  0,
  740. #endif /* NOXFER */
  741.     "maximum-speed",    XYDMAX,  0,
  742.     "name",             XYDNAM,  0,
  743.     "speaker",          XYDSPK,  0,
  744.     "speed-matching",   XYDSPD,  0,
  745.     "type",             XYDTYP,  0,
  746.     "volume",           XYDVOL,  0
  747. };
  748. int nsetmdm = (sizeof(setmdm) / sizeof(struct keytab));
  749.  
  750. struct keytab voltab[] = {
  751.     "high",   3,  0,
  752.     "low",    1,  0,
  753.     "medium", 2,  0
  754. };
  755.  
  756. struct keytab mdmcap[] = {
  757.     "at-commands",      CKD_AT,  0,
  758.     "compression",      CKD_DC,  0,
  759.     "dc",               CKD_DC,  CM_INV,
  760.     "ec",               CKD_EC,  CM_INV,
  761.     "error-correction", CKD_EC,  0,
  762.     "hardware-flow",    CKD_HW,  0,
  763.     "hwfc",             CKD_HW,  CM_INV,
  764.     "itu",              CKD_V25, CM_INV,
  765.     "kermit-spoof",     CKD_KS,  0,
  766.     "ks",               CKD_KS,  CM_INV,
  767.     "sb",               CKD_SB,  CM_INV,
  768.     "software-flow",    CKD_SW,  0,
  769.     "speed-buffering",  CKD_SB,  0,
  770.     "swfc",             CKD_SW,  CM_INV,
  771.     "tb",               CKD_TB,  CM_INV,
  772.     "telebit",          CKD_TB,  0,
  773.     "v25bis-commands",  CKD_V25, 0
  774. };
  775. int nmdmcap = (sizeof(mdmcap) / sizeof(struct keytab));
  776.  
  777. #ifdef COMMENT                          /* SET ANSWER not implemented yet */
  778. static struct keytab answertab[] = {
  779.     { "caller-id",  XYA_CID,  0 };
  780.     { "rings",      XYA_RNG,  0 };
  781.     { "", 0, 0 }
  782. };
  783. static int nanswertab =  (sizeof(answertab) / sizeof(struct keytab)) - 1;
  784. #endif /* COMMENT */
  785.  
  786. struct keytab dialtab[] = {             /* SET DIAL table */
  787.     "area-code",        XYDLAC, 0,      /* Also still includes items     */
  788.     "compression",      XYDDC,  CM_INV, /* that were moved to SET MODEM, */
  789.     "confirmation",     XYDCNF, 0,      /* but they are CM_INVisible...  */
  790.     "connect",          XYDCON, 0,
  791.     "convert-directory",XYDCVT, 0,
  792.     "country-code",     XYDLCC, 0,
  793.     "dial-command",     XYDDIA, CM_INV,
  794.     "directory",        XYDDIR, 0,
  795.     "display",          XYDDPY, 0,
  796.     "escape-character", XYDESC, CM_INV,
  797.     "error-correction", XYDEC,  CM_INV,
  798.     "flow-control",     XYDFC,  CM_INV,
  799.     "force-long-distance", XYDFLD, 0,
  800.     "hangup",           XYDHUP, 0,
  801.     "ignore-dialtone",  XYDIDT, 0,
  802.     "interval",         XYDINT, 0,
  803.     "in",               XYDINI, CM_INV|CM_ABR,
  804.     "init-string",      XYDINI, CM_INV,
  805.     "intl-prefix",      XYDIXP, 0,
  806.     "intl-suffix",      XYDIXS, 0,
  807. #ifndef NOXFER
  808.     "kermit-spoof",     XYDKSP, CM_INV,
  809. #endif /* NOXFER */
  810.     "lc-area-codes",    XYDLLAC, 0,
  811.     "lc-prefix",        XYDLCP, 0,
  812.     "lc-suffix",        XYDLCS, 0,
  813.     "ld-prefix",        XYDLDP, 0,
  814.     "ld-suffix",        XYDLDS, 0,
  815.     "local-area-code",  XYDLAC, CM_INV,
  816.     "local-prefix",     XYDLCP, CM_INV,
  817.     "local-suffix",     XYDLCS, CM_INV,
  818.     "m",                XYDMTH, CM_INV|CM_ABR,
  819. #ifndef NOSPL
  820.     "macro",            XYDMAC, 0,      /* 195 */
  821. #endif /* NOSPL */
  822. #ifdef MDMHUP
  823.     "me",               XYDMTH, CM_INV|CM_ABR,
  824. #endif /* MDMHUP */
  825.     "method",           XYDMTH, 0,
  826.     "mnp-enable",       XYDMNP, CM_INV, /* obsolete but still accepted */
  827. #ifdef MDMHUP
  828.     "modem-hangup",     XYDMHU, CM_INV,
  829. #endif /* MDMHUP */
  830.     "pacing",           XYDPAC,  0,
  831.     "pbx-exchange",     XYDPXX,  0,
  832.     "pbx-inside-prefix",XYDPXI,  0,
  833.     "pbx-outside-prefix",XYDPXO, 0,
  834.     "prefix",           XYDNPR,  0,
  835.     "pulse-countries",  XYDPUCC, 0,
  836.     "restrict",         XYDRSTR, 0,
  837.     "retries",          XYDRTM,  0,
  838.     "sort",             XYDSRT,  0,
  839.     "speed-matching",   XYDSPD,  CM_INV,
  840.     "string",           XYDSTR,  CM_INV,
  841.     "suffix",           XYDSFX,  0,
  842.     "test",             XYDTEST, 0,
  843.     "timeout",          XYDTMO,  0,
  844.     "tf-area-code",     XYDTFC,  CM_INV,
  845.     "tf-prefix",        XYDTFP,  CM_INV,
  846.     "toll-free-area-code",XYDTFC,0,
  847.     "toll-free-prefix", XYDTFP,  0,
  848.     "tone-countries",   XYDTOCC, 0
  849. };
  850. int ndial = (sizeof(dialtab) / sizeof(struct keytab));
  851.  
  852. #ifdef MDMHUP
  853. struct keytab mdmhang[] = {
  854.     "dtr",           0, 0,
  855.     "modem-command", 1, 0,
  856.     "rs232-signal",  0, 0,
  857.     "v24-signal",    0, CM_INV
  858. };
  859. #endif /* MDMHUP */
  860.  
  861. static struct keytab mdmcmd[] = {
  862.     "autoanswer",       XYDS_AN, 0,     /* autoanswer */
  863.     "compression",      XYDS_DC, 0,     /* data compression */
  864.     "dial-mode-prompt", XYDS_MP, 0,     /* dial mode prompt */
  865.     "dial-mode-string", XYDS_MS, 0,     /* dial mode string */
  866.     "error-correction", XYDS_EC, 0,     /* error correction */
  867.     "hangup-command",   XYDS_HU, 0,     /* hangup command */
  868.     "hardware-flow",    XYDS_HW, 0,     /* hwfc */
  869.     "ignore-dialtone",  XYDS_ID, 0,     /* ignore dialtone */
  870.     "init-string",      XYDS_IN, 0,     /* init string */
  871.     "no-flow-control",  XYDS_NF, 0,     /* no flow control */
  872.     "predial-init",     XYDS_I2, 0,     /* last-minute setup commands */
  873.     "pulse",            XYDS_DP, 0,     /* pulse */
  874.     "software-flow",    XYDS_SW, 0,     /* swfc */
  875.     "speaker",          XYDS_SP, 0,     /* Speaker */
  876.     "tone",             XYDS_DT, 0,     /* tone */
  877.     "volume",           XYDS_VO, 0      /* Volume */
  878. };
  879. static int nmdmcmd = (sizeof(mdmcmd) / sizeof(struct keytab));
  880.  
  881. struct keytab dial_fc[] = {
  882.     "auto",     FLO_AUTO, 0,
  883.     "none",     FLO_NONE, 0,
  884.     "rts/cts",  FLO_RTSC, 0,
  885.     "xon/xoff", FLO_XONX, 0
  886. };
  887.  
  888. struct keytab dial_m[] = {              /* DIAL METHOD */
  889.     "auto",    XYDM_A, 0,
  890.     "default", XYDM_D, 0,
  891.     "pulse",   XYDM_P, 0,
  892.     "tone",    XYDM_T, 0
  893. };
  894. int ndial_m = (sizeof(dial_m)/sizeof(struct keytab));
  895.  
  896. #ifdef CK_TAPI
  897. struct keytab tapitab[] = {             /* Top-Level Microsoft TAPI */
  898.     "configure-line",     XYTAPI_CFG,  0,
  899.     "dialing-properties", XYTAPI_DIAL, 0
  900. };
  901. int ntapitab = (sizeof(tapitab)/sizeof(struct keytab));
  902.  
  903. struct keytab settapitab[] = {          /* SET Microsoft TAPI */
  904.     "inactivity-timeout", XYTAPI_INA,  0,
  905.     "line",               XYTAPI_LIN,  0,
  906.     "location",           XYTAPI_LOC,  0,
  907.     "manual-dialing",     XYTAPI_MAN,  0,
  908.     "modem-dialing",      XYTAPI_PASS, 0,
  909.     "modem-lights",       XYTAPI_LGHT, 0,
  910.     "phone-number-conversions",   XYTAPI_CON,  0,
  911.     "port",               XYTAPI_LIN,  CM_INV,
  912.     "post-dial-terminal", XYTAPI_PST,  0,
  913.     "pre-dial-terminal",  XYTAPI_PRE,  0,
  914.     "use-windows-configuration", XYTAPI_USE, 0,
  915.     "wait-for-credit-card-tone", XYTAPI_BNG, 0
  916. };
  917. int nsettapitab = (sizeof(settapitab)/sizeof(struct keytab));
  918.  
  919. struct keytab * tapiloctab = NULL;      /* Microsoft TAPI Locations */
  920. int ntapiloc = 0;
  921. extern struct keytab * tapilinetab;     /* Microsoft TAPI Line Devices */
  922. extern int ntapiline;
  923. extern int tttapi;                      /* TAPI in use */
  924. extern int tapipass;                    /* TAPI Passthrough mode */
  925. extern int tapiconv;                    /* TAPI Conversion mode */
  926. extern int tapilights;
  927. extern int tapipreterm;
  928. extern int tapipostterm;
  929. extern int tapimanual;
  930. extern int tapiinactivity;
  931. extern int tapibong;
  932. extern int tapiusecfg;
  933. #endif /* CK_TAPI */
  934. #endif /* NODIAL */
  935.  
  936. #ifndef NOPUSH
  937. extern int nopush;
  938. #ifdef UNIX
  939. struct keytab wildtab[] = {             /* SET WILDCARD-EXPANSION */
  940.     "kermit",  0, 0,
  941.     "shell",   1, 0
  942. };
  943. struct keytab wdottab[] = {             /* cont'd */
  944.     "/match-dot-files",    1, 0,
  945.     "/no-match-dot-files", 0, 0
  946. };
  947. extern int wildxpand;
  948. #endif /* UNIX */
  949. #endif /* NOPUSH */
  950.  
  951. #ifdef NETCONN
  952. extern struct keytab netcmd[], netkey[];
  953. extern int nnets, nnetkey;
  954. #ifdef TCPSOCKET
  955. extern struct keytab tcpopt[];
  956. extern int ntcpopt;
  957. #endif /* TCPSOCKET */
  958. #ifdef NPIPE
  959. char pipename[PIPENAML+1] = { NUL, NUL };
  960. #endif /* NPIPE */
  961. #ifdef CK_NETBIOS
  962. extern unsigned char NetBiosName[];
  963. #endif /* CK_NETBIOS */
  964. #endif /* NETCONN */
  965.  
  966. #ifdef ANYX25
  967. struct keytab x25tab[] = {
  968.     "call-user-data",    XYUDAT, 0,
  969.     "closed-user-group", XYCLOS, 0,
  970.     "reverse-charge",    XYREVC, 0
  971. };
  972. int nx25 = (sizeof(x25tab) / sizeof(struct keytab));
  973.  
  974. #ifndef IBMX25
  975. struct keytab padx3tab[] = {
  976.     "break-action",         PAD_BREAK_ACTION,           0,
  977.     "break-character",      PAD_BREAK_CHARACTER,        0,
  978.     "character-delete",     PAD_CHAR_DELETE_CHAR,       0,
  979.     "cr-padding",           PAD_PADDING_AFTER_CR,       0,
  980.     "discard-output",       PAD_SUPPRESSION_OF_DATA,    0,
  981.     "echo",                 PAD_ECHO,                   0,
  982.     "editing",              PAD_EDITING,                0,
  983.     "escape",               PAD_ESCAPE,                 0,
  984.     "forward",              PAD_DATA_FORWARD_CHAR,      0,
  985.     "lf-padding",           PAD_PADDING_AFTER_LF,       0,
  986.     "lf-insert",            PAD_LF_AFTER_CR,            0,
  987.     "line-delete",          PAD_BUFFER_DELETE_CHAR,     0,
  988.     "line-display",         PAD_BUFFER_DISPLAY_CHAR,    0,
  989.     "line-fold",            PAD_LINE_FOLDING,           0,
  990.     "pad-flow-control",     PAD_FLOW_CONTROL_BY_PAD,    0,
  991.     "service-signals",      PAD_SUPPRESSION_OF_SIGNALS, 0,
  992.     "timeout",              PAD_DATA_FORWARD_TIMEOUT,   0,
  993. /* Speed is read-only */
  994.     "transmission-rate",    PAD_LINE_SPEED,             0,
  995.     "user-flow-control",    PAD_FLOW_CONTROL_BY_USER,   0
  996. };
  997. int npadx3 = (sizeof(padx3tab) / sizeof(struct keytab));
  998. #endif /* IBMX25 */
  999. #endif /* ANYX25 */
  1000.  
  1001. #ifdef TLOG
  1002. static struct keytab vbtab[] = {
  1003.     "brief",   0, 0,
  1004. #ifdef OS2ORUNIX
  1005.     "ftp",     2, 0,
  1006. #endif /* OS2ORUNIX */
  1007.     "verbose", 1, 0
  1008. };
  1009. int nvb = (sizeof(vbtab) / sizeof(struct keytab));
  1010. #endif /* TLOG */
  1011.  
  1012. #ifdef CKSYSLOG
  1013. static struct keytab syslogtab[] = {
  1014.     "all",         SYSLG_CX, 0,
  1015.     "commands",    SYSLG_CM, 0,
  1016.     "connection",  SYSLG_AC, 0,
  1017.     "debug",       SYSLG_DB, 0,
  1018.     "dial",        SYSLG_DI, 0,
  1019.     "file-access", SYSLG_FA, 0,
  1020.     "file-create", SYSLG_FC, 0,
  1021.     "login",       SYSLG_LI, 0,
  1022.     "none",        SYSLG_NO, 0,
  1023.     "protocol",    SYSLG_PR, 0
  1024. };
  1025. int nsyslog = (sizeof(syslogtab) / sizeof(struct keytab));
  1026. #endif /* CKSYSLOG */
  1027.  
  1028. /* Parity keyword table */
  1029.  
  1030. struct keytab partbl[] = {
  1031.     "even",    'e', 0,
  1032. #ifdef HWPARITY
  1033.     "hardware",'H', 0,
  1034. #endif /* HWPARITY */
  1035.     "mark",    'm', 0,
  1036.     "none",     0 , 0,
  1037.     "odd",     'o', 0,
  1038.     "space",   's', 0
  1039. };
  1040. int npar = (sizeof(partbl) / sizeof(struct keytab));
  1041.  
  1042. #ifdef HWPARITY
  1043. struct keytab hwpartbl[] = {
  1044. /* Add mark and space if needed and possible */
  1045.     "even",    'e', 0,
  1046. #ifdef OS2
  1047.     "mark",    'm', 0,
  1048. #endif /* OS2 */
  1049.     "odd",     'o', 0,
  1050. #ifdef OS2
  1051.     "space",   's', 0,
  1052. #endif /* OS2 */
  1053.     "", 0, 0
  1054. };
  1055. int nhwpar = (sizeof(hwpartbl) / sizeof(struct keytab)) - 1;
  1056. #endif /* HWPARITY */
  1057.  
  1058. /* On/Off table */
  1059.  
  1060. struct keytab onoff[] = {
  1061.     "off",       0, 0,
  1062.     "on",        1, 0
  1063. };
  1064.  
  1065. struct keytab cdtab[] = {
  1066.     "message",   XYCD_M, 0,
  1067.     "path",      XYCD_P, 0
  1068. };
  1069. int ncdtab = (sizeof(cdtab) / sizeof(struct keytab));
  1070.  
  1071. struct keytab cdmsg[] = {
  1072.     "file",      2, 0,
  1073.     "off",       0, 0,
  1074.     "on",        1, 0
  1075. };
  1076. int ncdmsg = (sizeof(cdmsg) / sizeof(struct keytab));
  1077.  
  1078. static
  1079. struct keytab xittab[] = {              /* SET EXIT */
  1080.     "hangup",        3, 0,              /* ...HANGUP */
  1081.     "on-disconnect", 2, 0,              /* ...ON-DISCONNECT */
  1082.     "status",        0, 0,              /* ...STATUS */
  1083.     "warning",       1, 0               /* ...WARNING */
  1084. };
  1085. int nexit = (sizeof(xittab) / sizeof(struct keytab));
  1086.  
  1087. struct keytab xitwtab[] = {             /* SET EXIT WARNING */
  1088.     "always", 2, 0,                     /* even when not connected */
  1089.     "off",    0, 0,                     /* no warning     */
  1090.     "on",     1, 0                      /* when connected */
  1091. };
  1092. int nexitw = (sizeof(xitwtab) / sizeof(struct keytab));
  1093.  
  1094. struct keytab rltab[] = {
  1095.     "local",     1, 0,                  /* ECHO values */
  1096.     "off",       0, CM_INV,
  1097.     "on",        1, CM_INV,
  1098.     "remote",    0, 0
  1099. };
  1100. int nrlt = (sizeof(rltab) / sizeof(struct keytab));
  1101.  
  1102. /* Incomplete File Disposition table */
  1103.  
  1104. struct keytab ifdtab[] = {
  1105.     "discard", SET_OFF, 0,
  1106.     "keep",    SET_ON,  0
  1107. };
  1108.  
  1109. struct keytab ifdatab[] = {
  1110.     "auto",    SET_AUTO, 0,
  1111.     "discard", SET_OFF,  0,
  1112.     "keep",    SET_ON,   0
  1113. };
  1114.  
  1115. char * ifdnam[] = { "discard", "keep", "auto" };
  1116.  
  1117. /* SET TAKE parameters table */
  1118. static
  1119. struct keytab taktab[] = {
  1120.     "echo",  0, 0,
  1121.     "error", 1, 0,
  1122.     "off",   2, CM_INV,                 /* For compatibility */
  1123.     "on",    3, CM_INV                  /* with MS-DOS Kermit... */
  1124. };
  1125.  
  1126. #ifndef NOSPL
  1127. #ifdef COMMENT
  1128. /* not used */
  1129. static
  1130. struct keytab suftab[] = {              /* (what to do with) STARTUP-FILE */
  1131.     "delete", 1, 0,
  1132.     "keep",   0, 0
  1133. };
  1134. #endif /* COMMENT */
  1135.  
  1136. /* SET MACRO parameters table */
  1137. static
  1138. struct keytab smactab[] = {
  1139.     "echo",  0, 0,
  1140.     "error", 1, 0
  1141. };
  1142. #endif /* NOSPL */
  1143.  
  1144. #ifndef NOSCRIPT
  1145. static
  1146. struct keytab scrtab[] = {
  1147.     "echo",  0, 0
  1148. };
  1149. #endif /* NOSCRIPT */
  1150.  
  1151. /* SET COMMAND table */
  1152.  
  1153. /* SET COMMAND items... */
  1154.  
  1155. #define SCMD_BSZ 0    /* BYTESIZE */
  1156. #define SCMD_RCL 1    /* RECALL */
  1157. #define SCMD_RTR 2    /* RETRY */
  1158. #define SCMD_QUO 3    /* QUOTING */
  1159. #define SCMD_COL 4    /* COLOR */
  1160. #define SCMD_HIG 5    /* HEIGHT */
  1161. #define SCMD_WID 6    /* WIDTH */
  1162. #define SCMD_CUR 7    /* CURSOR-POSITION */
  1163. #define SCMD_SCR 8    /* SCROLLBACK */
  1164. #define SCMD_MOR 9    /* MORE-PROMPTING */
  1165. #define SCMD_INT 10     /* INTERRUPTION */
  1166. #define SCMD_ADL 11     /* AUTODOWNLOAD */
  1167. #define SCMD_STA 12     /* STATUSLINE */
  1168. #define SCMD_DBQ 13    /* DOUBLEQUOTING */
  1169. #define SCMD_CBR 14    /* CBREAK */
  1170. #define SCMD_BFL 15    /* BUFFER-SIZE (not used) */
  1171.  
  1172. static struct keytab scmdtab[] = {
  1173. #ifdef CK_AUTODL
  1174.     "autodownload",       SCMD_ADL, 0,
  1175. #endif /* CK_AUTODL */
  1176. #ifdef COMMENT
  1177. /*
  1178.   To implement this requires that we change CMDBL and ATMBL
  1179.   from compile-time symbols to runtime variables.  Not a big deal,
  1180.   but not trivial either.
  1181.  */
  1182.     "buffer-size",        SCMD_BFL, 0,
  1183. #endif /* COMMENT */
  1184.     "bytesize",           SCMD_BSZ, 0,
  1185.     "cbreak",             SCMD_CBR, CM_INV,
  1186. #ifdef OS2
  1187.     "color",              SCMD_COL, 0,
  1188.     "cursor-position",    SCMD_CUR, 0,
  1189. #endif /* OS2 */
  1190. #ifdef DOUBLEQUOTING
  1191.     "doublequoting",      SCMD_DBQ, 0,
  1192. #endif /* DOUBLEQUOTING */
  1193.     "height",             SCMD_HIG, 0,
  1194.     "interruption",       SCMD_INT, 0,
  1195.     "more-prompting",     SCMD_MOR, 0,
  1196.     "quoting",            SCMD_QUO, 0,
  1197. #ifdef CK_RECALL
  1198.     "recall-buffer-size", SCMD_RCL, 0,
  1199. #endif /* CK_RECALL */
  1200. #ifdef CK_RECALL
  1201.     "retry",              SCMD_RTR, 0,
  1202. #endif /* CK_RECALL */
  1203. #ifdef OS2
  1204. #ifdef ONETERMUPD
  1205.     "scrollback",         SCMD_SCR, 0,
  1206.     "statusline",         SCMD_STA, 0,
  1207. #endif /* ONETERMUPD */
  1208. #endif /* OS2 */
  1209.     "width",              SCMD_WID, 0
  1210. };
  1211. static int nbytt = (sizeof(scmdtab) / sizeof(struct keytab));
  1212.  
  1213. #ifndef NOSERVER
  1214. /* Server parameters table */
  1215. static struct keytab srvtab[] = {
  1216.     "cd-message",   XYSERC, 0,
  1217.     "display",      XYSERD, 0,
  1218.     "get-path",     XYSERP, 0,
  1219.     "idle-timeout", XYSERI, 0,
  1220.     "keepalive",    XYSERK, 0,
  1221.     "login",        XYSERL, 0,
  1222.     "timeout",      XYSERT, 0
  1223. };
  1224. static int nsrvt = (sizeof(srvtab) / sizeof(struct keytab));
  1225. #endif /* NOSERVER */
  1226.  
  1227. static struct keytab sleeptab[] = {     /* SET SLEEP table */
  1228.     "cancellation",  0,   0
  1229. };
  1230.  
  1231. static struct keytab tstab[] = {        /* SET TRANSFER/XFER table */
  1232.     "bell",            XYX_BEL, 0,
  1233. #ifdef XFRCAN
  1234.     "cancellation",    XYX_CAN, 0,
  1235. #endif /* XFRCAN */
  1236. #ifndef NOCSETS
  1237.     "character-set",   XYX_CSE, 0,
  1238. #endif /* NOCSETS */
  1239. #ifndef NOSPL
  1240.     "crc-calculation", XYX_CRC, 0,
  1241. #endif /* NOSPL */
  1242.     "display",         XYX_DIS, 0,
  1243.     "interruption",    XYX_INT, 0,
  1244.     "locking-shift",   XYX_LSH, 0,
  1245.     "message",         XYX_MSG, 0,
  1246.     "mode",            XYX_MOD, 0,
  1247.     "msg",             XYX_MSG, CM_INV,
  1248. #ifdef PIPESEND
  1249.     "pipes",           XYX_PIP, 0,
  1250. #endif /* PIPESEND */
  1251. #ifdef CK_XYZ
  1252.     "protocol",        XYX_PRO, 0,
  1253. #endif /* CK_XYZ */
  1254.     "slow-start",      XYX_SLO, 0,
  1255. #ifndef NOCSETS
  1256.     "translation",     XYX_XLA, 0,
  1257. #else
  1258.     "translation",     XYX_XLA, CM_INV,
  1259. #endif /* NOCSETS */
  1260.     "xlation",         XYX_XLA, CM_INV,
  1261.     "", 0, 0
  1262. };
  1263. static int nts = (sizeof(tstab) / sizeof(struct keytab)) - 1;
  1264.  
  1265. static struct keytab rtstab[] = {       /* REMOTE SET TRANSFER/XFER table */
  1266. #ifndef NOCSETS
  1267.     "character-set",   XYX_CSE, 0,
  1268. #endif /* NOCSETS */
  1269.     "mode",            XYX_MOD, 0
  1270. };
  1271. static int nrts = (sizeof(rtstab) / sizeof(struct keytab));
  1272.  
  1273. struct keytab xfrmtab[] = {             /* TRANSFER MODE table */
  1274.     "automatic", XMODE_A, 0,
  1275.     "manual",    XMODE_M, 0
  1276. };
  1277.  
  1278. #ifdef LOCUS
  1279. extern int locus, autolocus;
  1280.  
  1281. static struct keytab locustab[] = {
  1282.     { "auto",    2, 0 },
  1283.     { "local",   1, 0 },
  1284.     { "remote",  0, 0 }
  1285. };
  1286. static int nlocustab = 3;
  1287. #endif /* LOCUS */
  1288.  
  1289. #ifndef NOCSETS
  1290. /* SET TRANSFER CHARACTER-SET table */
  1291.  
  1292. extern struct keytab tcstab[];
  1293. extern int ntcs;
  1294. #endif /* NOCSETS */
  1295.  
  1296. /* SET TRANSFER LOCKING-SHIFT table */
  1297. struct keytab lstab[] = {
  1298.     "forced", 2,   0,
  1299.     "off",    0,   0,
  1300.     "on",     1,   0
  1301. };
  1302. int nls = (sizeof(lstab) / sizeof(struct keytab));
  1303.  
  1304. /* SET TELNET tables */
  1305. #ifdef TNCODE
  1306. extern int tn_nlm, tn_b_nlm, tn_b_meu, tn_b_ume, tn_b_xfer, tn_sb_bug;
  1307. extern int tn_no_encrypt_xfer;
  1308. extern int tn_wait_flg, tn_duplex, tn_delay_sb, tn_sfu;
  1309. extern int sl_tn_saved;
  1310. extern int tn_infinite;
  1311. extern int tn_rem_echo;
  1312. extern int tn_deb;
  1313. extern int tn_auth_how;
  1314. extern int tn_auth_enc;
  1315. #ifdef CK_FORWARD_X
  1316. extern char * tn_fwdx_xauthority;
  1317. #endif /* CK_FORWARD_X */
  1318. #ifdef CK_AUTHENTICATION
  1319. static struct keytab setauth[] = {
  1320. #ifdef CK_KERBEROS
  1321.     "k4",        AUTH_KRB4, CM_INV,
  1322.     "k5",        AUTH_KRB5, CM_INV,
  1323.     "kerberos4", AUTH_KRB4, 0,
  1324.     "kerberos5", AUTH_KRB5, 0,
  1325.     "kerberos_iv",AUTH_KRB4, CM_INV,
  1326.     "kerberos_v", AUTH_KRB5, CM_INV,
  1327.     "krb4",      AUTH_KRB4, CM_INV,
  1328.     "krb5",      AUTH_KRB5, CM_INV,
  1329. #endif /* CK_KERBEROS */
  1330. #ifdef CK_SRP
  1331.     "srp",       AUTH_SRP,  0,
  1332. #endif /* CK_SRP */
  1333. #ifdef CK_SSL
  1334.     "ssl",      AUTH_SSL,   0,
  1335.     "tls",      AUTH_TLS,   0,
  1336. #endif /* CK_SSL */
  1337.     "",         0,      0
  1338. };
  1339. static int nsetauth = sizeof(setauth)/sizeof(struct keytab) - 1;
  1340. #ifdef CK_KERBEROS
  1341. extern char * krb5_d_principal;         /* Default principal */
  1342. extern char * krb5_d_instance;
  1343. extern char * krb5_d_realm;             /* Default realm */
  1344. extern char * krb5_d_cc;                /* Default credentials cache */
  1345. extern char * krb5_d_srv;               /* Default service name */
  1346. extern int    krb5_d_lifetime;          /* Default lifetime */
  1347. extern int    krb5_d_forwardable;
  1348. extern int    krb5_d_proxiable;
  1349. extern int    krb5_d_renewable;
  1350. extern int    krb5_autoget;
  1351. extern int    krb5_autodel;
  1352. extern int    krb5_d_getk4;
  1353. extern int    krb5_checkaddrs;          /* Check TGT Addrs */
  1354. extern int    krb5_d_no_addresses;
  1355. extern char * krb5_d_addrs[];
  1356. extern char * k5_keytab;                /* Keytab file */
  1357.  
  1358. extern struct krb4_init_data krb4_init;
  1359. extern char * krb4_d_principal;         /* Default principal */
  1360. extern char * krb4_d_realm;             /* Default realm */
  1361. extern char * krb4_d_srv;               /* Default service name */
  1362. extern int    krb4_d_lifetime;          /* Default lifetime */
  1363. extern int    krb4_d_preauth;
  1364. extern char * krb4_d_instance;
  1365. extern int    krb4_autoget;
  1366. extern int    krb4_autodel;
  1367. extern int    krb4_checkaddrs;          /* Check TGT Addrs */
  1368. extern char * k4_keytab;                /* Keytab file */
  1369. #ifdef KRB4
  1370. extern int    k4debug;
  1371. #endif /* KRB4 */
  1372. static struct keytab krbver[] = {
  1373.     "4",                 4, 0,
  1374.     "5",                 5, 0,
  1375.     "iv",                4, CM_INV,
  1376.     "v",                 5, CM_INV
  1377. };
  1378. static int nkrbver = sizeof(krbver)/sizeof(struct keytab);
  1379.  
  1380. static struct keytab kdestab[] = {
  1381.     "never",            KRB_DEL_NO, 0,
  1382.     "no",               KRB_DEL_NO, CM_INV,
  1383.     "on-close",         KRB_DEL_CL, 0,
  1384.     "on-exit",          KRB_DEL_EX, 0
  1385. };
  1386. static int nkdestab = sizeof(kdestab)/sizeof(struct keytab);
  1387.  
  1388. static struct keytab k4tab[] = {
  1389.     "autodel",           XYKRBDEL, CM_INV,
  1390.     "autodestroy",       XYKRBDEL, 0,
  1391.     "autoget",           XYKRBGET, 0,
  1392.     "check-address",     XYKRBADR, 0,
  1393.     "debug",             XYKRBDBG, CM_INV,
  1394.     "instance",          XYKRBINS, 0,
  1395.     "keytab",            XYKRBKTB, 0,
  1396.     "lifetime",          XYKRBLIF, 0,
  1397.     "preauth",           XYKRBPRE, 0,
  1398.     "principal",         XYKRBPR,  0,
  1399.     "prompt",            XYKRBPRM, 0,
  1400.     "realm",             XYKRBRL,  0,
  1401.     "service-name",      XYKRBSRV, 0
  1402. };
  1403. static int nk4tab = sizeof(k4tab)/sizeof(struct keytab);
  1404.  
  1405. static struct keytab k5tab[] = {
  1406.     "addresses",         XYKRBADD, 0,
  1407.     "autodelete",        XYKRBDEL, CM_INV,
  1408.     "autodestroy",       XYKRBDEL, 0,
  1409.     "autoget",           XYKRBGET, 0,
  1410.     "cc",                XYKRBCC,  CM_INV,
  1411.     "check-address",     XYKRBADR, 0,
  1412.     "credentials-cache", XYKRBCC,  0,
  1413.     "forwardable",       XYKRBFWD, 0,
  1414.     "get-k4-tgt",        XYKRBK5K4,0,
  1415.     "instance",          XYKRBINS, 0,
  1416.     "keytab",            XYKRBKTB, 0,
  1417.     "lifetime",          XYKRBLIF, 0,
  1418.     "no-addresses",      XYKRBNAD, 0,
  1419.     "principal",         XYKRBPR,  0,
  1420.     "prompt",            XYKRBPRM, 0,
  1421.     "proxiable",         XYKRBPRX, 0,
  1422.     "realm",             XYKRBRL,  0,
  1423.     "renewable",         XYKRBRNW, 0,
  1424.     "service-name",      XYKRBSRV, 0
  1425. };
  1426. static int nk5tab = sizeof(k5tab)/sizeof(struct keytab);
  1427.  
  1428. #define KRB_PW_PRM 1
  1429. #define KRB_PR_PRM 2
  1430.  
  1431. static struct keytab krbprmtab[] = {
  1432.     "password",  KRB_PW_PRM, 0,
  1433.     "principal", KRB_PR_PRM, 0
  1434. };
  1435.  
  1436. #endif /* CK_KERBEROS */
  1437. #ifdef CK_SRP
  1438. static struct keytab srptab[] = {
  1439.     "prompt",            XYSRPPRM, 0
  1440. };
  1441. static int nsrptab = sizeof(srptab)/sizeof(struct keytab);
  1442. #define SRP_PW_PRM 1
  1443.  
  1444. static struct keytab srpprmtab[] = {
  1445.     "password",  SRP_PW_PRM, 0
  1446. };
  1447. #endif /* CK_SRP */
  1448. #ifdef CK_SSL
  1449. static struct keytab ssltab[] = {
  1450.     "certs-ok",          XYSSLCOK,  CM_INV,
  1451.     "cipher-list",       XYSSLCL,   0,
  1452.     "crl-dir",           XYSSLCRLD, 0,
  1453.     "crl-file",          XYSSLCRL,  0,
  1454.     "debug",             XYSSLDBG,  0,
  1455.     "dh-key-file",       XYSSLDKFL, CM_INV,
  1456.     "dh-param-file",     XYSSLDPFL, 0,
  1457.     "dsa-cert-chain-file", XYSSLDCCF, 0,
  1458.     "dsa-cert-file",     XYSSLDCFL, 0,
  1459.     "dsa-key-file",      XYSSLDKFL, 0,
  1460.     "dummy",             XYSSLDUM,  CM_INV,
  1461.     "only",              XYSSLON,   CM_INV,
  1462.     "random-file",       XYSSLRND,  0,
  1463.     "rsa-cert-chain-file", XYSSLRCCF, 0,
  1464.     "rsa-cert-file",     XYSSLRCFL, 0,
  1465.     "rsa-key-file",      XYSSLRKFL, 0,
  1466.     "verbose",           XYSSLVRB,  0,
  1467.     "verify",            XYSSLVRF,  0,
  1468.     "verify-dir",        XYSSLVRFD, 0,
  1469.     "verify-file",       XYSSLVRFF, 0
  1470. };
  1471. static int nssltab = sizeof(ssltab)/sizeof(struct keytab);
  1472. static struct keytab sslvertab[] = {
  1473.     "fail-if-no-peer-cert", SSL_VERIFY_PEER |
  1474.                             SSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0,
  1475.     "no",               SSL_VERIFY_NONE, 0,
  1476.     "none",             SSL_VERIFY_NONE, CM_INV,
  1477.     "off",              SSL_VERIFY_NONE, CM_INV,
  1478.     "on",               SSL_VERIFY_PEER, CM_INV,
  1479.     "peer-cert",        SSL_VERIFY_PEER, 0
  1480. };
  1481. static int nsslvertab = sizeof(sslvertab)/sizeof(struct keytab);
  1482. #endif /* CK_SSL */
  1483. #endif /* CK_AUTHENTICATION */
  1484. #ifdef CK_ENCRYPTION
  1485. int cx_type = CX_AUTO;
  1486. extern int sl_cx_type;
  1487. #endif /* CK_ENCRYPTION */
  1488. extern char *tcp_address;
  1489. #ifndef NOHTTP
  1490. extern char *tcp_http_proxy;
  1491. #endif /* NOHTTP */
  1492. #ifdef NT
  1493. #ifdef CK_SOCKS
  1494. extern char *tcp_socks_svr;
  1495. #ifdef CK_SOCKS_NS
  1496. extern char *tcp_socks_ns;
  1497. #endif /* CK_SOCKS_NS */
  1498. #endif /* CK_SOCKS */
  1499. #endif /* NT */
  1500.  
  1501. static struct keytab tnnegtab[] = {     /* TELNET NEGOTIATION table */
  1502.     "accepted",  TN_NG_AC, 0,
  1503.     "refused",   TN_NG_RF, 0,
  1504.     "req",       TN_NG_RQ, CM_INV|CM_ABR,
  1505.     "requ",      TN_NG_RQ, CM_INV|CM_ABR,
  1506.     "reque",     TN_NG_RQ, CM_INV|CM_ABR,
  1507.     "reques",    TN_NG_RQ, CM_INV|CM_ABR,
  1508.     "request",   TN_NG_RQ, CM_INV|CM_ABR,
  1509.     "requeste",  TN_NG_RQ, CM_INV|CM_ABR,
  1510.     "requested", TN_NG_RQ, 0,
  1511.     "required",  TN_NG_MU, 0
  1512. };
  1513. static int ntnnegtab = sizeof(tnnegtab)/sizeof(struct keytab);
  1514.  
  1515. #ifdef CK_ENCRYPTION
  1516. static struct keytab typkwd[] = {
  1517.     "/type", 0, CM_ARG
  1518. };
  1519.  
  1520. static struct keytab tnenctab[] = {     /* TELNET ENCRYPTION table */
  1521.     "accepted",   TN_NG_AC,    CM_INV,
  1522.     "refused",    TN_NG_RF,    CM_INV,
  1523.     "req",        TN_NG_RQ,    CM_INV|CM_ABR,
  1524.     "requ",       TN_NG_RQ,    CM_INV|CM_ABR,
  1525.     "reque",      TN_NG_RQ,    CM_INV|CM_ABR,
  1526.     "reques",     TN_NG_RQ,    CM_INV|CM_ABR,
  1527.     "request",    TN_NG_RQ,    CM_INV|CM_ABR,
  1528.     "requeste",   TN_NG_RQ,    CM_INV|CM_ABR,
  1529.     "requested",  TN_NG_RQ,    CM_INV,
  1530.     "required",   TN_NG_MU,    CM_INV,
  1531.     "start",      TN_EN_START, CM_INV,
  1532.     "stop",       TN_EN_STOP,  CM_INV,
  1533.     "type",       TN_EN_TYP,   0
  1534. };
  1535. static int ntnenc = sizeof(tnenctab)/sizeof(struct keytab) ;
  1536. #endif /* CK_ENCRYPTION */
  1537.  
  1538. #ifdef CK_FORWARD_X
  1539. static struct keytab tnfwdxtab[] = {    /* TELNET FORWARD-X table */
  1540.     "no-encryption",    1,  CM_INV,
  1541.     "xauthority-file",  0,  0
  1542. };
  1543. static int ntnfwdx = sizeof(tnfwdxtab)/sizeof(struct keytab) ;
  1544. #endif /* CK_FORWARD_X */
  1545.  
  1546. static struct keytab tnbugtab[] = {     /* TELNET BUG table */
  1547.     "binary-me-means-u-too", 0, 0,
  1548.     "binary-u-means-me-too", 1, 0,
  1549.     "infinite-loop-check",   2, 0,
  1550.     "sb-implies-will-do",    3, 0
  1551. };
  1552.  
  1553. #ifdef CK_ENVIRONMENT
  1554. static struct keytab tnenvtab[] = {     /* TELNET ENVIRONMENT table */
  1555.     "acct",     TN_ENV_ACCT,    0,
  1556.     "display",  TN_ENV_DISP,    0,
  1557.     "job",      TN_ENV_JOB,     0,
  1558.     "location", TN_ENV_LOC,     0,
  1559.     "off",      TN_ENV_OFF,     CM_INV,
  1560.     "on",       TN_ENV_ON,      CM_INV,
  1561.     "printer",  TN_ENV_PRNT,    0,
  1562.     "systemtype",TN_ENV_SYS,    0,
  1563.     "user",     TN_ENV_USR,     0,
  1564.     "uservar",  TN_ENV_UVAR,    0,
  1565.     "", 0, 0
  1566. };
  1567. static int ntnenv = sizeof(tnenvtab)/sizeof(struct keytab) - 1;
  1568. #endif /* CK_ENVIRONMENT */
  1569.  
  1570. #ifdef CK_AUTHENTICATION
  1571. static struct keytab tnauthtab[] = {    /* TELNET AUTHENTICATION table */
  1572.     "accepted",   TN_NG_AC,  CM_INV,
  1573.     "encrypt-flag", TN_AU_ENC, 0,
  1574.     "forwarding", TN_AU_FWD,   0,
  1575.     "how-flag",   TN_AU_HOW,   0,
  1576.     "refused",    TN_NG_RF,  CM_INV,
  1577.     "req",        TN_NG_RQ,  CM_INV|CM_ABR,
  1578.     "requ",       TN_NG_RQ,  CM_INV|CM_ABR,
  1579.     "reque",      TN_NG_RQ,  CM_INV|CM_ABR,
  1580.     "reques",     TN_NG_RQ,  CM_INV|CM_ABR,
  1581.     "request",    TN_NG_RQ,  CM_INV|CM_ABR,
  1582.     "requeste",   TN_NG_RQ,  CM_INV|CM_ABR,
  1583.     "requested",  TN_NG_RQ,  CM_INV,
  1584.     "required",   TN_NG_MU,  CM_INV,
  1585.     "type",       TN_AU_TYP, 0
  1586. };
  1587. static int ntnauth = sizeof(tnauthtab)/sizeof(struct keytab) ;
  1588.  
  1589. struct keytab autyptab[] = {    /* TELNET AUTHENTICATION TYPE table */
  1590.     "automatic",  AUTH_AUTO, 0,
  1591. #ifdef CK_KERBEROS
  1592.     "k4",         AUTH_KRB4, CM_INV,
  1593.     "k5",         AUTH_KRB5, CM_INV,
  1594.     "kerberos4",  AUTH_KRB4, 0,
  1595.     "kerberos5",  AUTH_KRB5, 0,
  1596.     "kerberos_iv",AUTH_KRB4, CM_INV,
  1597.     "kerberos_v", AUTH_KRB5, CM_INV,
  1598.     "krb4",       AUTH_KRB4, CM_INV,
  1599.     "krb5",       AUTH_KRB5, CM_INV,
  1600. #endif /* CK_KERBEROS */
  1601.     "none",       AUTH_NONE, 0,
  1602. #ifdef NT
  1603.     "ntlm",       AUTH_NTLM, 0,
  1604. #endif /* NT */
  1605. #ifdef CK_SRP
  1606.     "srp",        AUTH_SRP,  0,
  1607. #endif /* CK_SRP */
  1608. #ifdef CK_SSL
  1609.     "ssl",        AUTH_SSL,  0,
  1610. #endif /* CK_SSL */
  1611.     "", 0, 0
  1612. };
  1613. int nautyp = sizeof(autyptab)/sizeof(struct keytab) - 1;
  1614.  
  1615. struct keytab auhowtab[] = {    /* TELNET AUTHENTICATION HOW table */
  1616.     "any",     TN_AUTH_HOW_ANY,     0,
  1617.     "mutual",  TN_AUTH_HOW_MUTUAL,  0,
  1618.     "one-way", TN_AUTH_HOW_ONE_WAY, 0,
  1619.     "", 0, 0
  1620. };
  1621. int nauhow = sizeof(auhowtab)/sizeof(struct keytab) - 1;
  1622.  
  1623. struct keytab auenctab[] = {    /* TELNET AUTHENTICATION ENCRYPT table */
  1624.     "any",     TN_AUTH_ENC_ANY,     0,
  1625.     "none",    TN_AUTH_ENC_NONE,    0,
  1626.     "telopt",  TN_AUTH_ENC_TELOPT,  0,
  1627. #ifdef CK_SSL
  1628.     "tls",     TN_AUTH_ENC_TLS,     0,
  1629. #endif /* CK_SSL */
  1630.     "", 0, 0
  1631. };
  1632. int nauenc = sizeof(auenctab)/sizeof(struct keytab) - 1;
  1633. #endif /* CK_AUTHENTICATION */
  1634.  
  1635. #define TN_NL_BIN 3
  1636. #define TN_NL_NVT 4
  1637. static struct keytab tn_nlmtab[] = {    /* TELNET NEWLINE-MODE table */
  1638.     "binary-mode", TN_NL_BIN, 0,        /* Binary mode */
  1639.     "nvt",    TN_NL_NVT, 0,             /* NVT mode */
  1640.     "off",    TNL_CRNUL, CM_INV,        /* CR-NUL (TELNET spec) */
  1641.     "on",     TNL_CRLF,  CM_INV,        /* CR-LF (TELNET spec) */
  1642.     "raw",    TNL_CR,    CM_INV         /* CR only (out of spec) */
  1643. };
  1644. static int ntn_nlm = (sizeof(tn_nlmtab) / sizeof(struct keytab));
  1645.  
  1646. static struct keytab tnlmtab[] = {      /* TELNET NEWLINE-MODE table */
  1647.     "cr",     TNL_CR,    CM_INV,        /* CR only (out of spec) */
  1648.     "cr-lf",  TNL_CRLF,  CM_INV,        /* CR-LF (TELNET spec) */
  1649.     "cr-nul", TNL_CRNUL, CM_INV,        /* CR-NUL (TELNET spec) */
  1650.     "lf",     TNL_LF,    CM_INV,        /* LF instead of CR-LF */
  1651.     "off",    TNL_CRNUL, 0,             /* CR-NUL (TELNET spec) */
  1652.     "on",     TNL_CRLF,  0,             /* CR-LF (TELNET spec) */
  1653.     "raw",    TNL_CR,    0              /* CR only (out of spec) */
  1654. };
  1655. static int ntnlm = (sizeof(tnlmtab) / sizeof(struct keytab));
  1656.  
  1657. struct keytab tntab[] = {
  1658. #ifdef CK_AUTHENTICATION
  1659.     "authentication",       CK_TN_AU,  0,
  1660. #endif /* CK_AUTHENTICATION */
  1661.     "b",                    CK_TN_BM,  CM_INV|CM_ABR,
  1662.     "bi",                   CK_TN_BM,  CM_INV|CM_ABR,
  1663.     "bin",                  CK_TN_BM,  CM_INV|CM_ABR,
  1664.     "bina",                 CK_TN_BM,  CM_INV|CM_ABR,
  1665.     "binar",                CK_TN_BM,  CM_INV|CM_ABR,
  1666.     "binary",               CK_TN_BM,  CM_INV|CM_ABR,
  1667.     "binary-",              CK_TN_BM,  CM_INV|CM_ABR,
  1668.     "binary-mode",          CK_TN_BM,  CM_INV,
  1669.     "binary-transfer-mode", CK_TN_XF,  0,
  1670.     "binary-xfer-mode",     CK_TN_XF,  CM_INV,
  1671.     "bug",                  CK_TN_BUG, 0,
  1672.     "debug",                CK_TN_DB,  0,
  1673.     "delay-sb",             CK_TN_DL,  0,
  1674.     "echo",                 CK_TN_EC,  0,
  1675. #ifdef CK_ENCRYPTION
  1676.     "encryption",      CK_TN_ENC,  0,
  1677. #endif /* CK_ENCRYPTION */
  1678. #ifdef CK_ENVIRONMENT
  1679.     "environment",     CK_TN_ENV,  0,
  1680. #endif /* CK_ENVIRONMENT */
  1681. #ifdef CK_FORWARD_X
  1682.     "forward-x",       CK_TN_FX,   0,
  1683. #endif /* CK_FORWARD_X */
  1684. #ifdef IKS_OPTION
  1685.     "kermit",          CK_TN_IKS,  CM_INV,
  1686. #endif /* IKS_OPTION */
  1687. #ifdef CK_SNDLOC
  1688.     "location",        CK_TN_LOC,  0,
  1689. #endif /* CK_SNDLOC */
  1690. #ifdef CK_NAWS
  1691.     "naws",            CK_TN_NAWS, CM_INV,
  1692. #endif /* CK_NAWS */
  1693.     "newline-mode",    CK_TN_NL,   0,
  1694.     "no-encrypt-during-xfer", CK_TN_NE, CM_INV,
  1695.     "prompt-for-userid",CK_TN_PUID,0,
  1696.     "remote-echo",     CK_TN_RE,   0,
  1697. #ifdef CK_SSL
  1698.     "start-tls",       CK_TN_TLS,  CM_INV,
  1699. #endif /* CK_SSL */
  1700. #ifdef NT
  1701.     "sfu-compatibility", CK_TN_SFU, 0,
  1702. #else
  1703.     "sfu-compatibility", CK_TN_SFU, CM_INV,
  1704. #endif /* NT */
  1705.     "terminal-type",   CK_TN_TT,   0,
  1706.     "wait-for-negotiations", CK_TN_WAIT, 0,
  1707. #ifdef CK_ENVIRONMENT
  1708.     "xdisplay-location",CK_TN_XD, CM_INV,
  1709. #endif /* CK_ENVIRONMENT */
  1710.     "", 0, 0
  1711. };
  1712. int ntn = (sizeof(tntab) / sizeof(struct keytab)) - 1;
  1713.  
  1714. struct keytab tnopttab[] = {
  1715. #ifdef CK_AUTHENTICATION
  1716.     "authentication",  CK_TN_AU,   0,
  1717. #else
  1718.     "authentication",  CK_TN_AU,   CM_INV,
  1719. #endif /* CK_AUTHENTICATION */
  1720.     "binary-mode",     CK_TN_BM,   0,
  1721. #ifdef TN_COMPORT
  1722.     "c",               CK_TN_CPC,   CM_INV|CM_ABR,
  1723.     "co",              CK_TN_CPC,   CM_INV|CM_ABR,
  1724.     "com",             CK_TN_CPC,   CM_INV|CM_ABR,
  1725.     "com-port-control",CK_TN_CPC,   0,
  1726.     "comport-control", CK_TN_CPC,   CM_INV,
  1727. #else /* TN_COMPORT */
  1728.     "com-port-control",CK_TN_CPC,  CM_INV,
  1729.     "comport-control", CK_TN_CPC,   CM_INV,
  1730. #endif /* TN_COMPORT */
  1731.     "echo",            CK_TN_EC,   0,
  1732. #ifdef CK_ENCRYPTION
  1733.     "encryption",      CK_TN_ENC,  0,
  1734. #else
  1735.     "encryption",      CK_TN_ENC,  CM_INV,
  1736. #endif /* CK_ENCRYPTION */
  1737. #ifdef CK_FORWARD_X
  1738.     "forward-x",       CK_TN_FX,   0,
  1739. #else /* CK_FORWARD_X */
  1740.     "forward-x",       CK_TN_FX,   CM_INV,
  1741. #endif /* CK_FORWARD_X */
  1742.     "ibm-sak",         CK_TN_SAK,  CM_INV,
  1743. #ifdef IKS_OPTION
  1744.     "kermit",          CK_TN_IKS,  0,
  1745. #else
  1746.     "kermit",          CK_TN_IKS,  CM_INV,
  1747. #endif /* IKS_OPTION */
  1748.     "lflow",           CK_TN_FLW,  CM_INV,
  1749.     "logout",          CK_TN_LOG,  0,
  1750. #ifdef CK_NAWS
  1751.     "naws",            CK_TN_NAWS, 0,
  1752. #else
  1753.     "naws",            CK_TN_NAWS, CM_INV,
  1754. #endif /* CK_NAWS */
  1755. #ifdef CK_ENVIRONMENT
  1756.     "new-environment", CK_TN_ENV,  0,
  1757. #else
  1758.     "new-environment", CK_TN_ENV,  CM_INV,
  1759. #endif /* CK_ENVIRONMENT */
  1760.     "pragma-heartbeat",CK_TN_PHR,  CM_INV,
  1761.     "pragma-logon",    CK_TN_PLG,  CM_INV,
  1762.     "pragma-sspi",     CK_TN_PSP,  CM_INV,
  1763.     "sak",             CK_TN_SAK,  CM_INV,
  1764. #ifdef CK_SNDLOC
  1765.     "send-location",   CK_TN_LOC,  0,
  1766. #else
  1767.     "send-location",   CK_TN_LOC,  CM_INV,
  1768. #endif /* CK_SNDLOC */
  1769.     "sga",             CK_TN_SGA, CM_INV|CM_ABR,
  1770. #ifdef CK_SSL
  1771.     "start-tls",       CK_TN_TLS,  0,
  1772. #else
  1773.     "start-tls",       CK_TN_TLS,  CM_INV,
  1774. #endif /* CK_SSL */
  1775.     "suppress-go-aheads", CK_TN_SGA, 0,
  1776.     "terminal-type",   CK_TN_TT,   0,
  1777.     "ttype",           CK_TN_TT,   CM_INV|CM_ABR,
  1778. #ifdef CK_ENVIRONMENT
  1779.     "xdisplay-location", CK_TN_XD, 0,
  1780. #else
  1781.     "xdisplay-location", CK_TN_XD, CM_INV,
  1782. #endif /* CK_ENVIRONMENT */
  1783.     "", 0, 0
  1784. };
  1785. int ntnopt = (sizeof(tnopttab) / sizeof(struct keytab)) - 1;
  1786.  
  1787. struct keytab tnoptsw[] = {
  1788.     "/client",  CK_TN_CLIENT,   0,
  1789.     "/server",  CK_TN_SERVER,   0
  1790. };
  1791. int ntnoptsw = (sizeof(tnoptsw) / sizeof(struct keytab));
  1792. #endif /* TNCODE */
  1793.  
  1794. struct keytab ftrtab[] = {              /* Feature table */
  1795. #ifndef NOCSETS                         /* 0 = we have it, 1 = we don't */
  1796. "character-sets",       0, 0,
  1797. #else
  1798. "character-sets",       1, 0,
  1799. #endif /* NOCSETS */
  1800. #ifndef NOCYRIL
  1801. "cyrillic",             0, 0,
  1802. #else
  1803. "cyrillic",             1, 0,
  1804. #endif /* NOCYRIL */
  1805.  
  1806. #ifndef NOLOGDIAL
  1807. "cx-log",               0, 0,
  1808. #else
  1809. "cx-log",               1, 0,
  1810. #endif /* NOLOGDIAL */
  1811.  
  1812. #ifndef NODEBUG
  1813. "debug",                0, 0,
  1814. #else
  1815. "debug",                1, 0,
  1816. #endif /* NODEBUG */
  1817.  
  1818. #ifndef NODIAL
  1819. "dial",                 0, 0,
  1820. #else
  1821. "dial",                 1, 0,
  1822. #endif /* NODIAL */
  1823.  
  1824. #ifdef DYNAMIC
  1825. "dynamic-memory",       0, 0,
  1826. #else
  1827. "dynamic-memory",       1, 0,
  1828. #endif /* DYNAMIC */
  1829.  
  1830. #ifndef NOXFER
  1831. "file-transfer",        0, 0,
  1832. #else
  1833. "file-transfer",        1, 0,
  1834. #endif /* NOXFER */
  1835.  
  1836. #ifdef XXFWD
  1837. "forward",              0, 0,
  1838. #else
  1839. "forward",              1, 0,
  1840. #endif /* XXFWD */
  1841.  
  1842. #ifdef NEWFTP
  1843. "ftp",                  0, 0,
  1844. #else
  1845. "ftp",                  1, 0,
  1846. #endif /* NEWFTP */
  1847.  
  1848. #ifdef CK_CURSES
  1849. "fullscreen-display",   0, 0,
  1850. #else
  1851. "fullscreen-display",   1, 0,
  1852. #endif /* CK_CURSES */
  1853. #ifdef GREEK
  1854. "greek",                0, 0,
  1855. #else
  1856. "greek",                1, 0,
  1857. #endif /* GREEK */
  1858. #ifdef HEBREW
  1859. "hebrew",               0, 0,
  1860. #else
  1861. "hebrew",               1, 0,
  1862. #endif /* HEBREW */
  1863. #ifndef NOHELP
  1864. "help",                 0, 0,
  1865. #else
  1866. "help",                 1, 0,
  1867. #endif /* NOHELP */
  1868.  
  1869. #ifndef NOIKSD
  1870. "iksd",                 0, 0,
  1871. #else
  1872. "iksd",                 1, 0,
  1873. #endif /* NOIKSD */
  1874.  
  1875. #ifndef NOSPL
  1876. "if-command",           0, 0,
  1877. #else
  1878. "if-command",           1, 0,
  1879. #endif /* NOSPL */
  1880. #ifndef NOJC
  1881. #ifdef UNIX
  1882. "job-control",          0, 0,
  1883. #else
  1884. "job-control",          1, 0,
  1885. #endif /* UNIX */
  1886. #else
  1887. "job-control",          1, 0,
  1888. #endif /* NOJC */
  1889. #ifdef KANJI
  1890. "kanji",                0, 0,
  1891. #else
  1892. "kanji",                1, 0,
  1893. #endif /* KANJI */
  1894.  
  1895. #ifndef NOXFER
  1896. "kermit",               0, 0,
  1897. #else
  1898. "kermit",               1, 0,
  1899. #endif /* NOXFER */
  1900.  
  1901. #ifdef CK_KERBEROS
  1902. "kerberos",             0, 0,
  1903. #else
  1904. "kerberos",             1, 0,
  1905. #endif /* CK_KERBEROS */
  1906.  
  1907. #ifndef NOCSETS
  1908. "latin1",               0, 0,
  1909. #else
  1910. "latin1",               1, 0,
  1911. #endif /* NOCSETS */
  1912. #ifdef LATIN2
  1913. "latin2",               0, 0,
  1914. #else
  1915. "latin2",               1, 0,
  1916. #endif /* LATIN2 */
  1917.  
  1918. #ifdef CKLEARN
  1919. "learned-scripts",       0, 0,
  1920. #else
  1921. "learned-scripts",       1, 0,
  1922. #endif /* CKLEARN */
  1923.  
  1924. #ifndef NOLOCAL
  1925. "making-connections",   0, 0,
  1926. #else
  1927. "making-connections",   1, 0,
  1928. #endif /* NOLOCAL */
  1929.  
  1930. #ifdef NETCONN
  1931. "network",              0, 0,
  1932. #else
  1933. "network",              1, 0,
  1934. #endif /* NETCONN */
  1935.  
  1936. #ifdef NT
  1937. #ifdef CK_AUTHENTICATION
  1938. "ntlm",                 1, 0,
  1939. #else /* CK_AUTHENTICATION */
  1940. "ntlm",                 0, 0,
  1941. #endif /* CK_AUTHENTICATION */
  1942. #else /* NT */
  1943. "ntlm",                 0, 0,
  1944. #endif /* NT */
  1945.  
  1946. #ifdef PIPESEND
  1947. "pipes",                0, 0,
  1948. #else
  1949. #ifdef NETCMD
  1950. "pipes",                0, 0,
  1951. #endif /* NETCMD */
  1952. #endif /* PIPESEND */
  1953. #ifndef PIPESEND
  1954. #ifndef NETCMD
  1955. "pipes",                1, 0,
  1956. #endif /* PIPESEND */
  1957. #endif /* NETCMD */
  1958.  
  1959. #ifdef NETPTY
  1960. "pty",                  0, 0,
  1961. #else
  1962. "pty",                  1, 0,
  1963. #endif /* NETPTY */
  1964.  
  1965. #ifndef NOPUSH
  1966. "push",                 0, 0,
  1967. #else
  1968. "push",                 1, 0,
  1969. #endif /* PUSH */
  1970.  
  1971. #ifdef CK_REDIR
  1972. "redirect",             0, 0,
  1973. #else
  1974. "redirect",             1, 0,
  1975. #endif /* CK_REDIR */
  1976.  
  1977. #ifdef CK_RTSCTS
  1978. "rts/cts",              0, 0,
  1979. #else
  1980. "rts/cts",              1, 0,
  1981. #endif /* RTS/CTS */
  1982.  
  1983. #ifndef NOSCRIPT
  1984. "script-command",       0, 0,
  1985. #else
  1986. "script-command",       1, 0,
  1987. #endif /* NOSCRIPT */
  1988. #ifndef NOSERVER
  1989. "server-mode",          0, 0,
  1990. #else
  1991. "server-mode",          1, 0,
  1992. #endif /* NOSERVER */
  1993.  
  1994. #ifndef NOSEXP
  1995. "sexpression",          0, 0,
  1996. #else
  1997. "sexpression",          1, 0,
  1998. #endif /* NOSEXP */
  1999.  
  2000. #ifndef NOSHOW
  2001. "show-command",         0, 0,
  2002. #else
  2003. "show-command",         1, 0,
  2004. #endif /* NOSHOW */
  2005.  
  2006. #ifdef CK_SRP
  2007. "srp",                  0, 0,
  2008. #else
  2009. "srp",                  1, 0,
  2010. #endif /* CK_SRP */
  2011.  
  2012. #ifdef SSHBUILTIN
  2013. "ssh",                  0, 0,
  2014. #else /* SSHBUILTIN */
  2015. "ssh",                  1, 0,
  2016. #endif /* SSHBUILTIN */
  2017.  
  2018. #ifdef CK_SSL
  2019. "ssl/tls",              0, 0,
  2020. #else
  2021. "ssl/tls",              1, 0,
  2022. #endif /* CK_SSL */
  2023.  
  2024. #ifndef NOXMIT
  2025. "transmit",             0, 0,
  2026. #else
  2027. "transmit",             1, 0,
  2028. #endif /* NOXMIT */
  2029.  
  2030. #ifdef UNICODE
  2031. "unicode",              0, 0,
  2032. #else
  2033. "unicode",              1, 0,
  2034. #endif /* UNICODE */
  2035.  
  2036. #ifdef CK_XYZ
  2037. "xyzmodem",             0, 0,
  2038. #else
  2039. "xyzmodem",             1, 0,
  2040. #endif /* NOXMIT */
  2041.  
  2042. "", 0, 0
  2043. };
  2044. int nftr = (sizeof(ftrtab) / sizeof(struct keytab)) - 1;
  2045.  
  2046. struct keytab desttab[] = {             /* SET DESTINATION */
  2047. #ifdef CALIBRATE
  2048.     "calibrate", DEST_N, CM_INV,
  2049. #endif /* CALIBRATE */
  2050.     "disk",    DEST_D, 0,
  2051. #ifdef CALIBRATE
  2052.     "nowhere", DEST_N, 0,
  2053. #endif /* CALIBRATE */
  2054.     "printer", DEST_P, 0,
  2055.     "screen",  DEST_S, 0
  2056. };
  2057. int ndests =  (sizeof(desttab) / sizeof(struct keytab));
  2058.  
  2059. #ifndef NOSPL           /* Used only with script programming items... */
  2060.  
  2061. #ifndef NOSERVER                        /* This is just to avoid some */
  2062. #define CK_PARSDIR                      /* "statement not reached" */
  2063. #else                                   /* complaints... */
  2064. #ifndef NODIAL
  2065. #define CK_PARSDIR
  2066. #endif /* NODIAL */
  2067. #endif /* NOSERVER */
  2068.  
  2069. /*
  2070.   cx == 0 means dial directory
  2071.   cx == 1 means network directory
  2072.   cx == 2 means a directory path list
  2073. */
  2074. static int
  2075. parsdir(cx) int cx; {
  2076.     int i, x, y, dd;                    /* Workers */
  2077.     int nxdir;
  2078.     char *s;
  2079.     char ** xdir;
  2080.     char *pp[MAXGETPATH];               /* Temporary name pointers */
  2081. #ifdef ZFNQFP
  2082.     struct zfnfp * fnp;
  2083. #ifdef OS2
  2084.     char * env;
  2085.     char dirpath[4096];
  2086. #else /* OS2 */
  2087.     char dirpath[1024];                 /* For fully qualified filenames */
  2088. #endif /* OS2 */
  2089. #endif /* ZFNQFP */
  2090.  
  2091.     int max = 0;                        /* Maximum number of things to parse */
  2092.     char c;
  2093.  
  2094. #ifndef NODIAL
  2095.     if (cx == 0) {                      /* Dialing */
  2096.         nxdir = ndialdir;
  2097.         xdir = dialdir;
  2098.         max = MAXDDIR;
  2099.     } else
  2100. #ifdef NETCONN
  2101.     if (cx == 1) {                      /* Network */
  2102.         nxdir = nnetdir;
  2103.         xdir = netdir;
  2104.         max = MAXDDIR;
  2105.     } else
  2106. #endif /* NETCONN */
  2107. #endif /* NODIAL */
  2108. #ifndef NOSERVER
  2109.     if (cx == 2) {                      /* GET path */
  2110.         nxdir = ngetpath;
  2111.         xdir = getpath;
  2112.         max = MAXGETPATH;
  2113.     } else                              /* Called with invalid function code */
  2114. #endif /* NOSERVER */
  2115.       return(-2);
  2116.  
  2117.     for (i = 0; i < MAXGETPATH; i++)    /* Init these. */
  2118.       pp[i] = NULL;
  2119.  
  2120. #ifdef CK_PARSDIR
  2121.     dd = 0;                             /* Temporary name counter */
  2122.     while (1) {
  2123.         if (cx != 2) {                  /* Dialing or Network Directory */
  2124. #ifdef OS2
  2125.             int len;
  2126.             char * appdata0 = NULL, * appdata1 = NULL;
  2127. #ifdef NT
  2128.             env = getenv("K95PHONES");
  2129.             makestr(&appdata0,(char *)GetAppData(0));
  2130.             makestr(&appdata1,(char *)GetAppData(1));
  2131. #else /* NT */
  2132.             env = getenv("K2PHONES");
  2133. #endif /* NT */
  2134.             if (!env)
  2135.               env = getenv("K95PHONES");
  2136.             if (!env)
  2137.               env = "";
  2138.  
  2139.             dirpath[0] = '\0';
  2140.             len = strlen(env) + 2*strlen(startupdir) + 2*strlen(inidir)
  2141.                 + (appdata0?2*strlen(appdata0):0) 
  2142.                 + (appdata1?2*strlen(appdata1):0)
  2143.                 + 2*strlen(zhome()) + 2*strlen(exedir) + 8*strlen("PHONES/")
  2144.                 + 12;
  2145.             if (len < 4096)             /* SAFE */
  2146.               sprintf(dirpath,
  2147.                     "%s%s%s;%s%s;%s%s%s%s%s%s%s%s%s;%s%s;%s;%s%s",
  2148.                     /* Semicolon-separated path list */
  2149.                     env,
  2150.                     (env[0] && env[strlen(env)-1] == ';') ? "" : ";",
  2151.                     startupdir,
  2152.                     startupdir, "PHONES/",
  2153.                     appdata1 ? appdata1 : "", 
  2154.                     appdata1 ? "Kermit 95;" : "",
  2155.                     appdata1 ? appdata1 : "", 
  2156.                     appdata1 ? "Kermit 95/PHONES/;" : "",
  2157.                     appdata0 ? appdata0 : "", 
  2158.                     appdata0 ? "Kermit 95;" : "",
  2159.                     appdata0 ? appdata0 : "", 
  2160.                     appdata0 ? "Kermit 95/PHONES/;" : "",
  2161.                     inidir,
  2162.                     inidir, "PHONES/",
  2163.                     zhome(),
  2164.                     zhome(), "PHONES/",
  2165.                     exedir,
  2166.                     exedir, "PHONES/"
  2167.                     );
  2168. #ifdef NT
  2169.             makestr(&appdata0,NULL);
  2170.             makestr(&appdata1,NULL);
  2171. #endif /* NT */
  2172. #else
  2173. #ifdef UNIX
  2174.             y = 1024;
  2175.             s = dirpath;
  2176.             zzstring("\\v(home)",&s,&y);
  2177. #endif /* UNIX */
  2178. #endif /* OS2 */
  2179.             y = cmifip(
  2180.                   "Names of one or more directory files, separated by spaces",
  2181.                        "",&s,&x,0,
  2182. #ifdef OS2ORUNIX
  2183.                        dirpath,
  2184. #else
  2185.                        NULL,
  2186. #endif /* OS2ORUNIX */
  2187.                        xxstring
  2188.                        );
  2189.         } else {                        /* List of directory names */
  2190.             x = 0;
  2191.             y = cmdir("Directory name","",&s,xxstring);
  2192.         }
  2193.         if (y < 0) {
  2194.             if (y == -3) {              /* EOL or user typed <CR> */
  2195.                 if ((y = cmcfm()) < 0) return(y);
  2196.                 for (i = 0; i < max; i++) { /* Clear these */
  2197.                     if (i < nxdir && xdir[i]) {
  2198.                         free(xdir[i]);
  2199.                     }
  2200.                     xdir[i] = (i < dd) ? pp[i] : NULL;
  2201.                 }
  2202. #ifndef NODIAL
  2203.                 if (cx == 0)
  2204.                   ndialdir = dd;
  2205. #ifdef NETCONN
  2206.                 if (cx == 1)
  2207.                   nnetdir = dd;
  2208. #endif /* NETCONN */
  2209. #endif /* NODIAL */
  2210. #ifndef NOSERVER
  2211.                 if (cx == 2)
  2212.                   ngetpath = dd;
  2213. #endif /* NOSERVER */
  2214.                 return(success = 1);
  2215.  
  2216.             } else {                    /* Parse error */
  2217.                 for (i = 0; i < dd; i++) {  /* Free temp storage */
  2218.                     if (pp[i]) free(pp[i]); /* but don't change */
  2219.                     pp[i] = NULL;           /* anything else */
  2220.                 }
  2221.                 return(y);
  2222.             }
  2223.         }
  2224.         if (x) {
  2225.             printf("?Wildcards not allowed\n");
  2226.             return(-9);
  2227.         }
  2228. #ifdef CK_TMPDIR
  2229.         if (cx == 2 && !isdir(s)) {
  2230.             printf("?Not a directory - %s\n", s);
  2231.             return(-9);
  2232.         }
  2233. #endif /* CK_TMPDIR */
  2234.  
  2235. #ifdef ZFNQFP
  2236.         if (cx < 2) {
  2237.             if (!isabsolute(s)) {       /* If not relative get full path */
  2238.                 if ((fnp = zfnqfp(s,TMPBUFSIZ - 1,tmpbuf))) {
  2239.                     if (fnp->fpath)
  2240.                       if ((int) strlen(fnp->fpath) > 0)
  2241.                         s = fnp->fpath;
  2242.                 }
  2243.             }
  2244.         }
  2245. #endif /* ZFNQFP */
  2246.         c = NUL;
  2247.         x = strlen(s);
  2248.         if (x > 0)                      /* Get last char */
  2249.           c = s[x-1];
  2250.         debug(F000,"parsdir s",s,c);
  2251.         if ((pp[dd] = malloc(strlen(s)+2)) == NULL) {
  2252.             printf("?Internal error - malloc\n");
  2253.             for (i = 0; i < dd; i++) {  /* Free temp storage */
  2254.                 if (pp[i]) free(pp[i]);
  2255.                 pp[i] = NULL;
  2256.             }
  2257.             return(-9);
  2258.         } else {                        /* Have storage for name */
  2259.             strcpy(pp[dd],s);           /* Copy string into new storage */
  2260.             debug(F111,"parsdir pp[dd] 1",pp[dd],dd);
  2261. #ifndef NOXFER
  2262.             if (cx == 2) {              /* If we are parsing directories */
  2263.                 char dirsep[2];
  2264.                 extern int myindex;     /* Append directory separator if */
  2265.                 extern struct sysdata sysidlist[]; /* it is missing...   */
  2266.                 debug(F101,"parsdir myindex","",myindex);
  2267.                 if (myindex > -1)
  2268.                   if (sysidlist[myindex].sid_unixlike)
  2269.                     if (c != sysidlist[myindex].sid_dirsep) {
  2270.                         dirsep[0] = sysidlist[myindex].sid_dirsep;
  2271.                         dirsep[1] = NUL;
  2272.                         strcat(pp[dd], (char *) dirsep); /* safe */
  2273.                     }
  2274.             }
  2275. #endif /* NOXFER */
  2276.             debug(F111,"parsdir pp[dd] 2",pp[dd],dd);
  2277.             if (++dd > max) {
  2278.                 printf("?Too many directories - %d max\n", max);
  2279.                 for (i = 0; i < dd; i++) {  /* Free temp storage */
  2280.                     if (pp[i]) free(pp[i]);
  2281.                     pp[i] = NULL;
  2282.                 }
  2283.             }
  2284.         }
  2285.     }
  2286. #endif /* CK_PARSDIR */
  2287. }
  2288. #endif /* NOSPL */
  2289.  
  2290. #ifndef NOSERVER
  2291. static int
  2292. cklogin() {
  2293.     int x;
  2294.     char * s;
  2295.     char username[LOGINLEN+1];
  2296.     char password[LOGINLEN+1];
  2297.     char account[LOGINLEN+1];
  2298.     extern char * x_user, * x_passwd, * x_acct;
  2299.     extern int x_login, x_logged;
  2300.  
  2301.     username[0] = NUL;
  2302.     password[0] = NUL;
  2303.     account[0]  = NUL;
  2304.  
  2305.     x = cmfld("username", "", &s, xxstring);
  2306.     if (x != -3) {
  2307.         if (x < 0)
  2308.           return(x);
  2309.         if ((int)strlen(s) > LOGINLEN) {
  2310.             printf("\"%s\" - too long, %d max\n", s, LOGINLEN);
  2311.             return(-9);
  2312.         }
  2313.         ckstrncpy(username,s,LOGINLEN+1);
  2314.         x = cmfld("password", "", &s, xxstring);
  2315.         if (x != -3) {
  2316.             if (x < 0)
  2317.               return(x);
  2318.             if ((int)strlen(s) > LOGINLEN) {
  2319.                 printf("\"%s\" - too long, %d max\n", s, LOGINLEN);
  2320.                 return(-9);
  2321.             }
  2322.             ckstrncpy(password,s,LOGINLEN+1);
  2323.             x = cmfld("account", "", &s, xxstring);
  2324.             if (x != -3) {
  2325.                 if (x < 0)
  2326.                   return(x);
  2327.                 if ((int)strlen(s) > LOGINLEN) {
  2328.                     printf("\"%s\" - too long, %d max\n", s, LOGINLEN);
  2329.                     return(-9);
  2330.                 }
  2331.                 ckstrncpy(account,s,LOGINLEN+1);
  2332.                 if ((x = cmcfm()) < 0)
  2333.                   return(x);
  2334.             }
  2335.         }
  2336.     }
  2337.     makestr(&x_user,username);
  2338.     makestr(&x_passwd,password);
  2339.     makestr(&x_acct,account);
  2340.     x_login = (x_user) ? 1 : 0;
  2341.     x_logged = 0;
  2342.     return(1);
  2343. }
  2344. #endif /* NOSERVER */
  2345.  
  2346. #ifndef NOLOCAL
  2347. static int
  2348. setdcd() {
  2349.     int x, y, z = 0;
  2350.     if ((y = cmkey(crrtab,ncrr,"","auto",xxstring)) < 0) return(y);
  2351.     if (y == CAR_ON) {
  2352.         x = cmnum("Carrier wait timeout, seconds","0",10,&z,xxstring);
  2353.         if (x < 0) return(x);
  2354.     }
  2355.     if ((x = cmcfm()) < 0) return(x);
  2356.     carrier = ttscarr(y);
  2357.     cdtimo = z;
  2358.     return(1);
  2359. }
  2360. #endif /* NOLOCAL */
  2361.  
  2362. extern struct keytab yesno[];
  2363. extern int nyesno;
  2364.  
  2365. /* g e t y e s n o  */
  2366.  
  2367. static struct keytab q0yesno[] = {      /* Yes/No/Quit keyword table */
  2368.     "no",    0, 0,
  2369.     "ok",    1, 0,
  2370.     "yes",   1, 0
  2371. };
  2372. static int nq0yesno = (sizeof(q0yesno) / sizeof(struct keytab));
  2373.  
  2374. static struct keytab q1yesno[] = {      /* Yes/No/Quit keyword table */
  2375.     "no",    0, 0,
  2376.     "ok",    1, 0,
  2377.     "quit",  2, 0,
  2378.     "yes",   1, 0
  2379. };
  2380. static int nq1yesno = (sizeof(q1yesno) / sizeof(struct keytab));
  2381.  
  2382. static struct keytab q2yesno[] = {      /* Yes/No/Quit keyword table */
  2383.     "go",    3, 0,
  2384.     "no",    0, 0,
  2385.     "ok",    1, 0,
  2386.     "yes",   1, 0
  2387. };
  2388. static int nq2yesno = (sizeof(q2yesno) / sizeof(struct keytab));
  2389.  
  2390. static struct keytab q3yesno[] = {      /* Yes/No/Quit keyword table */
  2391.     "go",    3, 0,
  2392.     "no",    0, 0,
  2393.     "ok",    1, 0,
  2394.     "quit",  2, 0,
  2395.     "yes",   1, 0
  2396. };
  2397. static int nq3yesno = (sizeof(q3yesno) / sizeof(struct keytab));
  2398.  
  2399.  
  2400. /* Ask question, get yes/no answer */
  2401.  
  2402. int
  2403. getyesno(msg, flags) char * msg; int flags; {
  2404. #ifdef CK_RECALL
  2405.     extern int on_recall;               /* around Password prompting */
  2406. #endif /* CK_RECALL */
  2407.     int y, z;
  2408.  
  2409. #ifndef NOLOCAL
  2410. #ifdef OS2
  2411.     extern int vmode, win95_popup;
  2412.     int vmode_sav = vmode;
  2413. #endif /* OS2 */
  2414. #endif /* NOLOCAL */
  2415.  
  2416. #ifdef CK_APC
  2417.     if ( apcactive != APC_INACTIVE && (apcstatus & APC_NOINP) ) {
  2418.         return(success = 0);
  2419.     }
  2420. #endif /* CK_APC */
  2421.  
  2422. #ifndef NOLOCAL
  2423. #ifdef COMMENT
  2424. #ifdef OS2
  2425.     if (win95_popup
  2426. #ifdef IKSD
  2427.         && !inserver
  2428. #endif /* IKSD */
  2429.         )
  2430.       return(popup_readyesno(vmode,msg,flags));
  2431. #endif /* COMMENT */
  2432.     if (vmode == VTERM) {
  2433.         vmode = VCMD;
  2434.         VscrnIsDirty(VTERM);
  2435.         VscrnIsDirty(VCMD);
  2436.     }
  2437. #endif /* OS2 */
  2438. #endif /* NOLOCAL */
  2439. #ifdef VMS
  2440. /*
  2441.   In VMS, whenever a TAKE file or macro is active, we restore the
  2442.   original console modes so Ctrl-C/Ctrl-Y can work.  But here we
  2443.   go interactive again, so we have to temporarily put them back.
  2444. */
  2445.     if (!xcmdsrc)
  2446.       concb((char)escape);
  2447. #endif /* VMS */
  2448.  
  2449. #ifdef CK_RECALL
  2450.     on_recall = 0;
  2451. #endif /* CK_RECALL */
  2452.     cmsavp(psave,PROMPTL);              /* Save old prompt */
  2453.     cmsetp(msg);                        /* Make new prompt */
  2454.     z = 0;                              /* Initialize answer to No. */
  2455.     cmini(ckxech);                      /* Initialize parser. */
  2456.     do {
  2457.         prompt(NULL);                   /* Issue prompt. */
  2458.         switch (flags) {
  2459.           case 0:  y = cmkey(q0yesno,nq0yesno,"","",NULL); break;
  2460.           case 1:  y = cmkey(q1yesno,nq1yesno,"","",NULL); break;
  2461.           case 2:  y = cmkey(q2yesno,nq2yesno,"","",NULL); break;
  2462.           default: y = cmkey(q3yesno,nq3yesno,"","",NULL);
  2463.         }
  2464.         if (y < 0) {
  2465.             if (y == -4) {              /* EOF */
  2466.                 z = y;
  2467.                 break;
  2468.             } else if (y == -3)         /* No answer? */
  2469.               printf(" Please respond; type '?' to see valid answers.\n");
  2470.             cmini(ckxech);
  2471.         } else {
  2472.             z = y;                      /* Save answer */
  2473.             y = cmcfm();                /* Get confirmation */
  2474.         }
  2475.     } while (y < 0);                    /* Continue till done */
  2476.     cmsetp(psave);                      /* Restore real prompt */
  2477. #ifdef VMS
  2478.     if (cmdlvl > 0)                     /* In VMS and not at top level, */
  2479.       conres();                         /*  restore console again. */
  2480. #endif /* VMS */
  2481. #ifndef NOLOCAL
  2482. #ifdef OS2
  2483.     if (vmode != vmode_sav) {
  2484.         vmode = VTERM;
  2485.         VscrnIsDirty(VCMD);
  2486.         VscrnIsDirty(VTERM);
  2487.     }
  2488. #endif /* OS2 */
  2489. #endif /* NOLOCAL */
  2490.     return(z);
  2491. }
  2492.  
  2493. #ifdef CK_PERMS
  2494. #ifdef UNIX
  2495.  
  2496. _PROTOTYP( int zsetperm, (char *, int));
  2497.  
  2498. /* CHMOD command for UNIX only */
  2499.  
  2500. #define CHM_DIR 0
  2501. #define CHM_DOT 1
  2502. #define CHM_FIL 2
  2503. #define CHM_LIS 3
  2504. #define CHM_NOL 4
  2505. #define CHM_QUI 5
  2506. #define CHM_REC 6
  2507. #define CHM_VRB 7
  2508. #define CHM_PAG 8
  2509. #define CHM_NOP 9
  2510. #define CHM_TYP 10
  2511. #define CHM_SIM 11
  2512.  
  2513. static struct keytab uchmodsw[] = {
  2514.     "/directories", CHM_DIR, 0,
  2515.     "/dotfiles",    CHM_DOT, 0,
  2516.     "/files",       CHM_FIL, 0,
  2517.     "/list",        CHM_LIS, 0,
  2518.     "/nolist",      CHM_NOL, 0,
  2519.     "/nopage",      CHM_NOP, 0,
  2520.     "/page",        CHM_PAG, 0,
  2521.     "/quiet",       CHM_QUI, CM_INV,
  2522.     "/recursive",   CHM_REC, 0,
  2523.     "/simulate",    CHM_SIM, 0,
  2524.     "/type",        CHM_TYP, CM_ARG,
  2525.     "/verbose",     CHM_VRB, CM_INV,
  2526. };
  2527. static int nchmodsw = (sizeof(uchmodsw) / sizeof(struct keytab));
  2528.  
  2529. int
  2530. douchmod() {
  2531.     extern int matchdot, recursive, nscanfile, diractive;
  2532. #ifdef CK_TTGWSIZ
  2533.     extern int tt_rows, tt_cols;
  2534.     int n = 0;
  2535. #endif /* CK_TTGWSIZ */
  2536.     int i, files = 1, t1 = 1, t2 = 0, x, y, z, verbose = 0, rc = 1, paging;
  2537.     int xmode = -1, fs = 0, getval = 0, simulate = 0, wild = 0;
  2538.     char c, * s;
  2539.     struct FDB sw, nu;
  2540.  
  2541.     if (xaskmore < 0) {
  2542. #ifdef CK_TTGWSIZ
  2543.         xaskmore = 1;
  2544. #else
  2545.         xaskmore = 0;
  2546. #endif /* CK_TTGWSIZ */
  2547.     }
  2548.     paging = xaskmore;
  2549.  
  2550.     cmfdbi(&sw,                         /* First FDB - command switches */
  2551.            _CMKEY,                      /* fcode */
  2552.            "Octal file permission code, or switch",
  2553.            "",                          /* default */
  2554.            "",                          /* addtl string data */
  2555.            nchmodsw,                    /* addtl numeric data 1: tbl size */
  2556.            4,                           /* addtl numeric data 2: 4 = cmswi */
  2557.            xxstring,                    /* Processing function */
  2558.            uchmodsw,                    /* Keyword table */
  2559.            &nu                          /* Pointer to next FDB */
  2560.            );
  2561.     cmfdbi(&nu,
  2562.            _CMNUM,                      /* Number */
  2563.            "",                          /* Help message */
  2564.            "",                          /* Default */
  2565.            "",                          /* N/A */
  2566.            8,                           /* Radix = 8 */
  2567.            0,                           /* N/A */
  2568.            xxstring,                    /* Processing function */
  2569.            NULL,                        /* N/A */
  2570.            NULL                         /* Next */
  2571.            );
  2572.  
  2573.     while (1) {
  2574.         if ((x = cmfdb(&sw)) < 0) {
  2575.             if (x == -3) {
  2576.                 x = -9;
  2577.                 printf("?Filename required\n");
  2578.             }
  2579.             return(x);
  2580.         }
  2581.         if (cmresult.fcode != _CMKEY)
  2582.           break;
  2583.         c = cmgbrk();
  2584.         getval = (c == ':' || c == '=');
  2585.         if (getval && !(cmgkwflgs() & CM_ARG)) {
  2586.             printf("?This switch does not take an argument\n");
  2587.             return(-9);
  2588.         }
  2589.         if (!getval && (cmgkwflgs() & CM_ARG)) {
  2590.             printf("?This switch requires an argument\n");
  2591.             return(-9);
  2592.         }
  2593.         switch (cmresult.nresult) {
  2594.           case CHM_DIR:
  2595.             t1 = 1;
  2596.             t2 = 1;
  2597.             break;
  2598.           case CHM_DOT:
  2599.             matchdot = 1;
  2600.             break;
  2601.           case CHM_FIL:
  2602.             t1 = 0;
  2603.             t2 = 0;
  2604.             break;
  2605.           case CHM_LIS:
  2606.           case CHM_VRB:
  2607.             verbose = 1;
  2608.             break;
  2609.           case CHM_NOL:
  2610.           case CHM_QUI:
  2611.             verbose = 0;
  2612.             break;
  2613.           case CHM_REC:
  2614.             recursive = 1;
  2615.             break;
  2616.           case CHM_PAG:
  2617.             verbose = 1;
  2618.             paging = 1;
  2619.             break;
  2620.           case CHM_NOP:
  2621.             paging = 0;
  2622.             break;
  2623.           case CHM_SIM:
  2624.             simulate = 1;
  2625.             break;
  2626.           case CHM_TYP: {
  2627.               extern struct keytab txtbin[];
  2628.               if ((x = cmkey(txtbin,3,"","",xxstring)) < 0)
  2629.                 return(x);
  2630.               if (x == 2) {             /* ALL */
  2631.                   xmode = -1;
  2632.               } else {                  /* TEXT or BINARY only */
  2633.                   xmode = x;
  2634.                   fs = 1;
  2635.               }
  2636.               break;
  2637.           }
  2638.         }
  2639.     }
  2640.     z = cmresult.nresult;
  2641.     x = cmifi2("File specification","",&s,&wild,t1,NULL,xxstring,t2);
  2642.     if (x < 0) {
  2643.         if (x == -3) {
  2644.             printf("?A file specification is required\n");
  2645.             return(-9);
  2646.         } else
  2647.           return(x);
  2648.     }
  2649.     ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  2650.     s = tmpbuf;
  2651.     if ((x = cmcfm()) < 0)
  2652.       return(x);
  2653. #ifdef ZXREWIND
  2654.     if (wild) files = zxrewind();
  2655. #else
  2656.     if (wild) files = nzxpand(s,0);
  2657. #endif /* ZXREWIND */
  2658.  
  2659.     if (paging > -1)
  2660.       xaskmore = paging;
  2661.  
  2662. #ifdef CK_TTGWSIZ
  2663.     if (verbose && paging) {
  2664. #ifdef OS2
  2665.         ttgcwsz();
  2666. #else /* OS2 */
  2667.         if (ttgwsiz() > 0) {
  2668.             if (tt_rows > 0 && tt_cols > 0) {
  2669.                 cmd_rows = tt_rows;
  2670.                 cmd_cols = tt_cols;
  2671.             }
  2672.         }
  2673. #endif /* OS2 */
  2674.     }
  2675. #endif /* CK_TTGWSIZ */
  2676.  
  2677.     for (i = 0; i < files; i++) {
  2678.         if (files == 1 && wild == 0) {  /* For "chmod 777 ." */
  2679.             ckstrncpy(line,s,LINBUFSIZ);
  2680.         } else {
  2681.             x = znext(line);
  2682.             if (x < 1) {
  2683.                 if (i == 0) {
  2684.                     printf("?No files match - \"%s\"\n",line);
  2685.                     return(-9);
  2686.                 }
  2687.                 return(1);
  2688.             }
  2689.         }
  2690.         if (fs) {
  2691. #ifdef VMSORUNIX
  2692.             /* If /TYPE:TEXT or BINARY given, skip directories and links */
  2693.             /* since they are neither text nor binary. */
  2694.             extern int zgfs_dir, zgfs_link;
  2695.             zgetfs(line);
  2696.             if (zgfs_dir || zgfs_link)
  2697.               continue;
  2698. #else
  2699.             if (zchki(line) < 0)
  2700.               continue;
  2701. #endif /* VMSORUNIX */
  2702.             /* Regular file, scan it */
  2703.             switch (scanfile(line,&y,nscanfile)) {
  2704.               case FT_BIN:
  2705.                 if (xmode != 1)
  2706.                   continue;
  2707.                 break;
  2708.               case FT_TEXT:
  2709.               case FT_7BIT:
  2710.               case FT_8BIT:
  2711. #ifdef UNICODE
  2712.               case FT_UTF8:
  2713.               case FT_UCS2:
  2714. #endif /* UNICODE */
  2715.                 if (xmode != 0)
  2716.                   continue;
  2717.             }
  2718.         }
  2719.         if (simulate) {
  2720. #ifdef UNIX
  2721.             extern int zchkod;          /* Unidentified Flying */
  2722.             int xx = zchkod;            /* API Extension... */
  2723.             zchkod = 1;
  2724. #endif /* UNIX */
  2725.             if (zchko(line) < 0)
  2726.               printf("%s - Access denied\n",line);
  2727.             else
  2728.               printf("%s - OK\n",line);
  2729. #ifdef UNIX
  2730.             zchkod = xx;
  2731. #endif /* UNIX */
  2732.         } else {
  2733.             if (zsetperm(line,z) < 1) {
  2734.                 if (verbose || files < 2) {
  2735.                     printf("%s: %s\n",line,ck_errstr());
  2736.                 }
  2737.                 rc = 0;
  2738.             } else if (verbose) {
  2739.                 printf("%s  %s\n",ziperm(line),line);
  2740.             }
  2741.         }
  2742. #ifdef CK_TTGWSIZ
  2743.         if (verbose && paging) {        /* Pause at end of screen */
  2744.             if (cmd_rows > 0 && cmd_cols > 0) {
  2745.                 if (++n > cmd_rows - 3) {
  2746.                     if (!askmore())
  2747.                       break;
  2748.                     else
  2749.                       n = 0;
  2750.                 }
  2751.             }
  2752.         }
  2753. #endif /* CK_TTGWSIZ */
  2754.  
  2755.     }
  2756.     return(success = rc);
  2757. }
  2758. #endif /* UNIX */
  2759. #endif /* CK_PERMS */
  2760.  
  2761. #ifndef NOSPL                           /* S-Expressions */
  2762. #ifndef NOSEXP
  2763.  
  2764. struct keytab sexptab[] = {
  2765.     "depth-limit", 1, 0,
  2766.     "echo-result", 0, 0
  2767. };
  2768.  
  2769. static int sexpmaxdep = 1000;           /* Maximum depth */
  2770.  
  2771. #define xxfloat(s,x) \
  2772. ((isdigit(*s)||(*s=='-')||(*s=='+')||(*s=='.')||(*s=='\040'))?isfloat(s,x):0)
  2773.  
  2774. #define SX_ADD  1                       /* Symbols for built-in operators */
  2775. #define SX_SUB  2
  2776. #define SX_MUL  3
  2777. #define SX_DIV  4
  2778. #define SX_POW  5
  2779. #define SX_SET  6
  2780. #define SX_MOD  7
  2781. #define SX_EVA  8
  2782. #define SX_EXP  9
  2783. #define SX_AEQ 10
  2784. #define SX_ALT 11
  2785. #define SX_AGT 12
  2786. #define SX_ALE 13
  2787. #define SX_AGE 14
  2788. #define SX_MIN 15
  2789. #define SX_MAX 16
  2790. #define SX_SQR 17
  2791. #define SX_FLR 18
  2792. #define SX_CEI 19
  2793. #define SX_TRU 20
  2794. #define SX_ABS 21
  2795. #define SX_ROU 22
  2796. #define SX_LET 23
  2797. #define SX_LGN 24
  2798. #define SX_LGX 25
  2799. #define SX_FLO 26
  2800. #define SX_IFC 27
  2801. #define SX_NOT 28
  2802. #define SX_NEQ 29
  2803. #define SX_AND 30
  2804. #define SX_LOR 31
  2805. #define SX_SIN 32
  2806. #define SX_COS 33
  2807. #define SX_TAN 34
  2808. #define SX_BWA 35
  2809. #define SX_BWO 36
  2810. #define SX_BWX 37
  2811. #define SX_BWN 38
  2812. #define SX_XOR 39
  2813. #define SX_INC 40
  2814. #define SX_DEC 41
  2815. #define SX_QUO 42
  2816. #define SX_STR 43
  2817.  
  2818. /* Operator flags */
  2819.  
  2820. #define SXF_PRE 256                     /* Predicate */
  2821. #define SXF_ONE 512                     /* Requires one arg */
  2822. #define SXF_TWO 1024                    /* Requires two args or more */
  2823. #define SXF_FLO 2048                    /* Coerce to floating-point */
  2824.  
  2825. /* Built-in constants */
  2826.  
  2827. #define SXC_NIL 1                       /* NIL */
  2828. #define SXC_PI  2                       /* PI */
  2829. #define SXC_T   3                       /* T */
  2830.  
  2831. /*
  2832.   This is an xlookup() table and so need not be in "alhabetical" order.
  2833.   Therefore entries are arranged to minimize search for most common
  2834.   operators.
  2835. */
  2836. static struct keytab sexpops[] = {      /* Built-in operators */
  2837.     "setq",    SX_SET, 0,               /* Global assignment */
  2838.     "+",       SX_ADD, 0,               /* Simple arithmetic */
  2839.     "-",       SX_SUB, 0,
  2840.     "*",       SX_MUL, 0,
  2841.     "/",       SX_DIV, SXF_TWO,
  2842.     "^",       SX_POW, SXF_TWO,
  2843.  
  2844.     "if",      SX_IFC, SXF_TWO,         /* IF */
  2845.     "let",     SX_LET, 0,               /* Local assignment */
  2846.     "not",     SX_NOT, SXF_ONE,         /* NOT */
  2847.     "mod",     SX_MOD, SXF_TWO,         /* Modulus */
  2848.  
  2849.     "<",       SX_ALT, SXF_PRE|SXF_TWO, /* Comparisons */
  2850.     ">",       SX_AGT, SXF_PRE|SXF_TWO,
  2851.     "<=",      SX_ALE, SXF_PRE|SXF_TWO,
  2852.     "=",       SX_AEQ, SXF_PRE|SXF_TWO,
  2853.     ">=",      SX_AGE, SXF_PRE|SXF_TWO,
  2854.     "!=",      SX_NEQ, SXF_PRE|SXF_TWO,
  2855.  
  2856.     "++",      SX_INC, SXF_ONE|SXF_TWO, /* Increment */
  2857.     "--",      SX_DEC, SXF_ONE|SXF_TWO, /* Decrement */
  2858.  
  2859.     "**",      SX_POW, SXF_TWO,         /* Common synonyms */
  2860.     "==",      SX_AEQ, SXF_PRE|SXF_TWO,
  2861.     "!",       SX_NOT, SXF_ONE,
  2862.     ".",       SX_EVA, 0,
  2863.  
  2864.     "and",     SX_AND, 0,               /* Logical operators */
  2865.     "or",      SX_LOR, 0,
  2866.     "xor",     SX_XOR, SXF_TWO,
  2867.  
  2868.     "max",     SX_MAX, SXF_ONE|SXF_TWO, /* Max and min */
  2869.     "min",     SX_MIN, SXF_ONE|SXF_TWO,
  2870.  
  2871.     "%",       SX_MOD, SXF_TWO,         /* More synonyms */
  2872.     "||",      SX_LOR, 0,
  2873.     "&&",      SX_AND, 0,
  2874.  
  2875.     "quote",   SX_QUO, SXF_ONE,
  2876.     "string",  SX_STR, SXF_ONE,
  2877.  
  2878.     "eval",    SX_EVA, 0,               /* Assorted commands */
  2879.     "abs",     SX_ABS, SXF_ONE,
  2880.     "truncate",SX_TRU, SXF_ONE|SXF_FLO,
  2881.     "round",   SX_ROU, SXF_ONE|SXF_FLO,
  2882.     "ceiling", SX_CEI, SXF_ONE|SXF_FLO,
  2883.     "floor",   SX_FLR, SXF_ONE|SXF_FLO,
  2884.     "float",   SX_FLO, SXF_ONE|SXF_FLO,
  2885.  
  2886. #ifdef FNFLOAT
  2887.     "sqrt",    SX_SQR, SXF_ONE|SXF_FLO, /* Floating point functions */
  2888.     "exp",     SX_EXP, SXF_ONE|SXF_FLO,
  2889.     "sin",     SX_SIN, SXF_ONE|SXF_FLO,
  2890.     "cos",     SX_COS, SXF_ONE|SXF_FLO,
  2891.     "tan",     SX_TAN, SXF_ONE|SXF_FLO,
  2892.     "log",     SX_LGN, SXF_ONE|SXF_FLO,
  2893.     "log10",   SX_LGX, SXF_ONE|SXF_FLO,
  2894. #endif /* FNFLOAT */
  2895.  
  2896.     "#",       SX_BWX, SXF_TWO,         /* Bitwise operators */
  2897.     "&",       SX_BWA, 0,
  2898.     "|",       SX_BWO, 0,
  2899.     "~",       SX_BWN, SXF_ONE,
  2900.     "", 0, 0                            /* (end) */
  2901. };
  2902. static int nsexpops = (sizeof(sexpops) / sizeof(struct keytab)) - 1;
  2903.  
  2904. static struct keytab sexpconsts[] = {   /* Built-in constants */
  2905.     "nil", SXC_NIL, 0,                  /* NIL (false) */
  2906.     "pi",  SXC_PI,  0,                  /* Pi (3.1415926...) */
  2907.     "t",   SXC_T,   0,                  /* T (true) */
  2908.     "", 0, 0
  2909. };
  2910. static int nsexpconsts = (sizeof(sexpconsts) / sizeof(struct keytab)) - 1;
  2911.  
  2912. int sexprc = 0;                         /* S-Expression error flag */
  2913. int sexppv = -1;                        /* Predicate value */
  2914.  
  2915. #define SXMLEN 64                       /* Macro arg list initial length */
  2916. #include <math.h>                       /* Floating-point functions */
  2917.  
  2918. _PROTOTYP( char * fpformat, (CKFLOAT, int, int) );
  2919.  
  2920. extern char math_pi[];                  /* Value of Pi */
  2921. extern int sexpecho;                    /* SET SEXPRESSION ECHO value */
  2922. extern char * sexpval;                  /* Last top-level S-Expression value */
  2923. extern char * lastsexp;                 /* Last S-Expression */
  2924. int sexprmax = 0;                       /* Longest result (for stats) */
  2925. int sexpdmax = 0;                       /* Max depth reached (for stats) */
  2926. int sexpdep  = 0;                       /* dosexp() recursion depth */
  2927. static int * sxrlen = NULL;             /* Result stack string sizes */
  2928. static char ** sxresult = NULL;         /* Result stack */
  2929.  
  2930. /*  s h o s e x p  --  Show S-Expression info  */
  2931.  
  2932. VOID
  2933. shosexp() {
  2934.     printf("\n");
  2935.     printf(" sexpression echo-result: %s\n",showooa(sexpecho));
  2936.     printf(" sexpression depth-limit: %d\n",sexpmaxdep);
  2937.     printf("\n");
  2938.     printf(" maximum depth reached:   %d\n",sexpdmax);
  2939.     printf(" longest result returned: %d\n",sexprmax);
  2940.     printf("\n");
  2941.     printf(" last sexpression:        %s\n",lastsexp ? lastsexp : "(none)");
  2942.     printf(" last value:              %s\n",sexpval ? sexpval : "(none)");
  2943.     printf("\n");
  2944. }
  2945.  
  2946.  
  2947. static char *
  2948. sexpdebug(s) char * s; {
  2949.     /* For debugging -- includes recursion depth in each debug entry */
  2950.     static char buf[64];
  2951.     ckmakmsg(buf,64,"dosexp[",ckitoa(sexpdep),"] ",s);
  2952.     return((char *)buf);
  2953. }
  2954.  
  2955. /*  d o s e x p  --  S-Expression Reader  */
  2956.  
  2957. /*  Returns value as string (empty, numeric, or non-numeric) */
  2958.  
  2959. char *
  2960. dosexp(s) char *s; {                    /* s = S-Expression */
  2961.     extern struct mtab *mactab;         /* Macro table */
  2962.     extern int maclvl, nmac;
  2963.     extern char *mrval[];
  2964.     extern int makestrlen;              /* (see makestr()) */
  2965.     struct stringarray * q = NULL;      /* cksplit() return type */
  2966.     char * p[SEXPMAX+1], ** p2;         /* List items (must be on stack) */
  2967.     char * line = NULL;                 /* For building macro argument list */
  2968.     int linelen = 0;
  2969.     int linepos = 0;
  2970.     int quote = 0;                      /* LISP quote flag */
  2971.     char * s2;                          /* Workers */
  2972.     int i, j, k, n = 0, x = 0, kw, kwflags, mx = 0;
  2973.     int result = 0, not = 0, truncate = 0, builtin = 0;
  2974.     int fpflag = 0, quit = 0, macro = 0;
  2975.     extern CKFLOAT floatval;            /* (see isfloat()) */
  2976.     CKFLOAT fpj, fpresult = 0.0;        /* Floating-point results */
  2977.     int pflag = 0;                      /* Have predicate */
  2978.     int presult = 0;                    /* Predicate result */
  2979.     int mustfree = 0;                   /* If we malloc'd we must free */
  2980.  
  2981.     sexppv = -1;                        /* Predicate value */
  2982.     s2 = "";                            /* Default return value */
  2983.  
  2984.     if (++sexpdep > sexpmaxdep) {       /* Keep track of depth */
  2985.         printf("?S-Expression depth limit exceeded: %d\n",sexpmaxdep);
  2986.         sexprc++;
  2987.         debug(F111,sexpdebug("max depth exceeded"),s,sexprc);
  2988.     }
  2989.     if (sexpdep > sexpdmax)             /* For stats */
  2990.       sexpdmax = sexpdep;
  2991.  
  2992.     if (sexprc)                         /* Error, quit all levels */
  2993.       goto xdosexp;                     /* Always goto common exit point */
  2994.  
  2995.     debug(F111,sexpdebug("entry"),s,sexprc);
  2996.  
  2997.     if (!s) s = "";                     /* Null or empty arg */
  2998.  
  2999.     while (*s == SP) s++;               /* Strip leading spaces */
  3000.     if (!*s)                            /* so empty result */
  3001.       goto xdosexp;
  3002.  
  3003. /*
  3004.   Allocate result stack upon first use, or after it has been resized with
  3005.   SET SEXP DEPTH-LIMIT.
  3006. */
  3007.     if (!sxresult) {
  3008.         sxresult = (char **)malloc(sexpmaxdep * sizeof(char *));
  3009.         if (!sxresult) {
  3010.             printf("?Memory allocation failure - \"%s\"\n", s);
  3011.             sexprc++;
  3012.             goto xdosexp;
  3013.         }
  3014.         sxrlen = (int *)malloc(sexpmaxdep * sizeof(int));
  3015.         if (!sxrlen) {
  3016.             printf("?Memory allocation failure - \"%s\"\n", s);
  3017.             sexprc++;
  3018.             goto xdosexp;
  3019.         }
  3020.         for (i = 0; i < sexpmaxdep; i++) {
  3021.             sxresult[i] = NULL;         /* Result pointers */
  3022.             sxrlen[i] = 0;              /* Buffer sizes */
  3023.         }
  3024.     }
  3025.     s2 = s;                             /* s2 is the result pointer */
  3026.     k = 0;                              /* Length accumulator */
  3027.     if (s[0] == '(') {                  /* Starts with open paren? */
  3028.         while (*s2++) k++;              /* Get length */
  3029.         if (s[k-1] == ')') {            /* Strip outer parens if any */
  3030.             s[k-1] = NUL;
  3031.             s++;
  3032.             k -= 2;
  3033.             while (*s == SP) {          /* Strip leading spaces from result */
  3034.                 s++;
  3035.                 k--;
  3036.             }
  3037.             while (k > 0 && s[k-1] == SP) { /* And trailing spaces. */
  3038.                 s[k-1] = NUL;
  3039.                 k--;
  3040.             }
  3041.         }
  3042.         if (!*s) {                      /* If nothing remains */
  3043.             s2 = "";                    /* return empty result. */
  3044.             goto xdosexp;
  3045.         }
  3046.     }
  3047.     /* Break result up into "words" (an SEXP counts as a word) */
  3048.  
  3049.     p[0] = NULL;                        /* (We don't use element 0) */
  3050.     if (!*(s+1) || !*(s+2)) {           /* No need to call cksplit() */
  3051.         n = 1;                          /* if it's one or two chars. */
  3052.         p[1] = s;                       /* No need to malloc this either. */
  3053.         debug(F101,sexpdebug("nosplit"),"",n);
  3054.         if (s[0] == '(') {              /* () empty */
  3055.             s2 = "";
  3056.             goto xdosexp;
  3057.         }
  3058.     } else {
  3059.         q = cksplit(1,SEXPMAX,s,NULL,"\\%[]&$+-/=*^_@!{}/<>|.#~'`:;?",8,39,0);
  3060.         if (!q)
  3061.           goto xdosexp;
  3062.         n = q->a_size;                  /* Number of items */
  3063.         debug(F101,sexpdebug("split"),"",n);
  3064.         if (n < 0 || n > SEXPMAX) {     /* Check for too many */
  3065.             printf("?Too many operands: max = %d\n",SEXPMAX);
  3066.             sexprc++;
  3067.             goto xdosexp;
  3068.         }
  3069.         if (n == 0)                     /* None, result is NULL, done. */
  3070.           goto xdosexp;
  3071.         if (n == 1 && s[0] == '(') {    /* One but it's another SEXP */
  3072.             s2 = dosexp(s);
  3073.             goto xdosexp;
  3074.         }
  3075.         p2 = q->a_head;                 /* Point to result array. */
  3076.         for (i = 1; i <= n; i++) {      /* We must copy it because */
  3077.             p[i] = NULL;                /* recursive calls to dosexp() */
  3078.             if (p2[i])                  /* write over the same array */
  3079.               makestr(&(p[i]),p2[i]);
  3080.         }
  3081.         if (s[0] == '(') {              /* Operator is an S-Expression */
  3082.             s2 = dosexp(p[1]);          /* Replace it by its value */
  3083.             makestr(&(p[1]),s2);
  3084.         }
  3085.         mustfree++;                     /* Remember to free it */
  3086.     }
  3087.     debug(F110,sexpdebug("head"),p[1],0);
  3088.  
  3089.     if (n == 1 && p[1]) {
  3090.         if (*(p[1]) == '\047') {
  3091.             s2 = p[1];
  3092.             goto xdosexp;
  3093.         }
  3094.     }
  3095. /*
  3096.   This section sidesteps xlookup() of the most common operators.
  3097.   It's not necessary but it speeds up SEXP-heavy loops by about 10%.
  3098. */
  3099.     kwflags = 0;
  3100.     if (n > 0) {                        /* Look up the operator */
  3101.         s2 = p[1];                      /* Prelookup optimization... */
  3102.         if (!s2)
  3103.           s2 = "";
  3104.         if (!*s2)
  3105.           goto xdosexp;
  3106.         kw = 0;
  3107.         x = 0;
  3108.         if (isdigit(*s2)) {             /* Digit */
  3109.             x = -2;
  3110.  
  3111.         } else if (isalpha(*s2) && !*(s2+1)) { /* Single letter */
  3112.             x = -1;
  3113.  
  3114.         } else if (*s2 == 's' || *s2 == 'S') { /* SETQ */
  3115.             s2++;
  3116.             if (*s2 == 'e' || *s2 == 'E') {
  3117.                 s2++;
  3118.                 if (*s2 == 't' || *s2 == 'T') {
  3119.                     s2++;
  3120.                     if (*s2 == 'q' || *s2 == 'Q') {
  3121.                         if (!*(s2+1)) {
  3122.                             x = SX_SET;
  3123.                             kwflags = 0;
  3124.                             builtin = 1;
  3125.                         }
  3126.                     }
  3127.                 }
  3128.             }
  3129.         }
  3130.         if (!x) {
  3131.             if (!*(s2+1)) {             /* Common single-character ops */
  3132.                 if (*s2 == '+') {
  3133.                     x = SX_ADD;
  3134.                     kwflags = 0;
  3135.                     builtin = 1;
  3136.                 } else if (*s2 == '-') {
  3137.                     x = SX_SUB;
  3138.                     kwflags = 0;
  3139.                     builtin = 1;
  3140.                 } else if (*s2 == '*') {
  3141.                     x = SX_MUL;
  3142.                     kwflags = 0;
  3143.                     builtin = 1;
  3144.                 } else if (*s2 == '/') {
  3145.                     x = SX_DIV;
  3146.                     kwflags = SXF_TWO;
  3147.                     builtin = 1;
  3148.                 }
  3149.             }
  3150.             if (!x) {                   /* None of the above, look it up */
  3151.                 x = xlookup(sexpops,p[1],nsexpops,&kw);
  3152.                 if (x > 0) {
  3153.                     kwflags = sexpops[kw].flgs;
  3154.                     builtin = 1;
  3155.                 }
  3156.             }
  3157.         }
  3158.     }
  3159.     /* If none of the above, check built-in constants */
  3160.  
  3161.     if (x == -1) {
  3162.         x = xlookup(sexpconsts,p[1],nsexpconsts,&kw);
  3163.         if (x > 0) {
  3164.             switch (x) {
  3165.               case SXC_NIL:
  3166.                 s2 = "";
  3167.                 goto xdosexp;
  3168.               case SXC_PI:
  3169.                 s2 = math_pi;
  3170.                 goto xdosexp;
  3171.               case SXC_T:
  3172.                 s2 = "1";
  3173.                 goto xdosexp;
  3174.             }
  3175.         }
  3176.     }
  3177.     if (n == 1) {                       /* Not an expression */
  3178.         if (builtin) {                  /* Built-in operand? */
  3179.             switch (x) {                /* Operators with default values */
  3180.               case SX_EVA:
  3181.                 s2 = "";
  3182.                 goto xdosexp;
  3183.               case SX_MUL:              /* (*) */
  3184.                 s2 = sexpval ? sexpval : "1";
  3185.                 goto xdosexp;
  3186.               case SX_AND:              /* (AND) */
  3187.               case SX_BWA:              /* Bitwise (&) */
  3188.                 result++;
  3189.               case SX_LOR:              /* (OR) */
  3190.               case SX_BWO:              /* Bitwise (|) */
  3191.               case SX_ADD:              /* (+) */
  3192.               case SX_SUB:              /* (-) */
  3193.                 s2 = result ? "1" : "0";
  3194.                 goto xdosexp;
  3195.             }
  3196.  
  3197.         } else {                        /* Not a built-in operand */
  3198.             char * p1;
  3199.             p1 = p[1];
  3200.             while (*p1 == SP) p1++;
  3201.             if (!isalpha(*p1)) {
  3202.                 if (xxfloat(p1,0) > 0) { /* Is it a number? */
  3203.                     s2 = p1;
  3204.                     while (*s2 == '+') s2++;
  3205.                 } else if (*p1 == '(') { /* An S-Expression? */
  3206.  
  3207. #ifdef COMMENT
  3208.                     s2 = dosexp(s2);
  3209. #else
  3210.                     s2 = dosexp(p1);
  3211. #endif /* COMMENT */
  3212.                 }
  3213.                 goto xdosexp;
  3214.             } else if (x < 1) {         /* Is it a variable? */
  3215.                 j = mxlook(mactab,p[1],nmac); /* Look it up */
  3216.                 debug(F111,sexpdebug("n==1 mxlook"),p[1],j);
  3217.                 s2 = (j > -1) ? mactab[j].mval : "";
  3218.                 if (!s2) s2 = "";
  3219.                 if (xxfloat(s2,0) > 0)  /* Macro value is a number */
  3220.                   goto xdosexp;
  3221.  
  3222.                 if (j > -1) {           /* It's a macro */
  3223.                     mx = j;
  3224.                     x = j;              /* whose definition is not numeric */
  3225.                     if (*s2 == '(') {   /* Is it an S-Expression? */
  3226.                         /* We have to allocate memory on the stack */
  3227.                         /* to call ourselves recursively on it */
  3228.                         /* otherwise we'll wipe out the macro definition */
  3229.                         char * s3 = NULL;
  3230.                         /* int k = 0; */
  3231.                         s3 = s2;
  3232.                         while (*s3++) k++;
  3233.                         s3 = (char *)malloc(k + 4);
  3234.                         if (s3) {
  3235.                             strcpy(s3,s2);   /* SAFE */
  3236.                             s2 = dosexp(s3); /* Evaluate it */
  3237.                             free(s3);
  3238.                         } else {
  3239.                             printf("?Memory allocation failure - \"%s\"\n",s2);
  3240.                             sexprc++;
  3241.                         }
  3242.                         goto xdosexp;
  3243.                     }
  3244.                     if (*s2 == '\047') {
  3245.                         s2++;
  3246.                         makestr(&p[1],s2);
  3247.                         s2 = p[1];
  3248.                         if (*s2 == '(') {
  3249.                             if (s2[makestrlen-1] == ')') {
  3250.                                 s2[makestrlen-1] = NUL;
  3251.                                 s2++;
  3252.                             }
  3253.                         }
  3254.                         debug(F110,sexpdebug("'A"),s2,0);
  3255.                         goto xdosexp;
  3256.                     }
  3257.                     macro++;            /* Not an S-Expression */
  3258.                 } else {                /* Not found in macro table */
  3259.                     printf("?Not defined - \"%s\"\n", p[1]);
  3260.                     sexprc++;
  3261.                     goto xdosexp;
  3262.                 }
  3263.             }
  3264.         }
  3265.     } else if (x < 1 && !macro) {       /* n > 1 and not a built-in operator */
  3266.         x = mxlook(mactab,p[1],nmac);   /* See if it's a macro */
  3267.         debug(F111,sexpdebug("n!=1 mxlook"),p[1],x);
  3268.         if (x < 0) {
  3269.             printf("?Invalid operand - \"%s\"\n",p[1]);
  3270.             sexprc++;
  3271.             goto xdosexp;
  3272.         }
  3273.         mx = x;
  3274.         macro++;
  3275.     }
  3276.     if (builtin) {                      /* Built-in operator... */
  3277.         if (kwflags) {
  3278.             int flgs;
  3279.             if ((flgs = (kwflags & (SXF_ONE|SXF_TWO)))) {
  3280.                 switch (flgs) {
  3281.                   case (SXF_ONE|SXF_TWO):
  3282.                     if (n < 2) {
  3283.                         printf("?Too few operands - \"%s\"\n",s);
  3284.                         sexprc++;
  3285.                         goto xdosexp;
  3286.                     }
  3287.                     break;
  3288.                   case SXF_TWO:
  3289.                     if (n < 3) {
  3290.                         printf("?Too few operands - \"%s\"\n",s);
  3291.                         sexprc++;
  3292.                         goto xdosexp;
  3293.                     }
  3294.                     break;
  3295.                   case SXF_ONE:
  3296.                     if (n != 2) {
  3297.                         printf("?Too %s operands - \"%s\"\n",
  3298.                                (n > 2) ? "many" : "few", s);
  3299.                         sexprc++;
  3300.                         goto xdosexp;
  3301.                     }
  3302.                 }
  3303.             }
  3304.             if (kwflags & SXF_PRE) {    /* Predicate? */
  3305.                 pflag = 1;
  3306.                 presult = 1;
  3307.             }
  3308.             if (kwflags & SXF_FLO)      /* Operator requires floating point */
  3309.               fpflag++;                 /* Force it */
  3310.         }
  3311.         if (x == SX_SET || x == SX_LET || /* Assignment is special */
  3312.             x == SX_INC || x == SX_DEC) {
  3313.             int rc;
  3314.             char c, * m, * s3;
  3315.             if (n == 1) {
  3316.                 s2 = "";
  3317.                 goto xdosexp;
  3318.             }
  3319.             s2 = NULL;
  3320.             for (i = 1; i < n; i += 2) { /* Loop thru operand pairs */
  3321.                 rc = 0;
  3322.                 s3 = p[i+1];
  3323.                 c = *s3;
  3324.                 debug(F110,sexpdebug("target p"),s3,0);
  3325.  
  3326.                 /* Make sure target doesn't have multiple words */
  3327.                 while (*s3) { if (*s3 < '!') { rc = 1; break; }; s3++; }
  3328.                 s3 = p[i+1];
  3329.                 if (rc) {               /* If it does it must have been */
  3330.                     char * s4;          /* an SEXP so evaluate it */
  3331.                     s3 = dosexp(s3);
  3332.                     s4 = s3;
  3333.                     rc = 0;
  3334.                     while (*s4) { if (*s4 < '!') { rc = 1; break; }; s4++; }
  3335.                     if (rc == 0) makestr(&(p[i+1]),s3);
  3336.                 }
  3337.  
  3338.                 /* And that it's not a number, etc. */
  3339.                 if (rc > 0 || isdigit(c) || c == '(') {
  3340.                     printf("?Invalid assignment - \"%s\"\n",s);
  3341.                     sexprc++;
  3342.                     goto xdosexp;
  3343.                 } else if (isalpha(c)) {
  3344.                     rc = xlookup(sexpconsts,s3,nsexpconsts,NULL);
  3345.                     if (rc > 0) {
  3346.                         printf("?Assignment to constant - \"%s\"\n",s);
  3347.                         sexprc++;
  3348.                         goto xdosexp;
  3349.                     }
  3350.                 }
  3351.  
  3352.                 /* If ++ or --, get current value of variable */
  3353.                 if (x == SX_INC || x == SX_DEC) {
  3354.                     int ok = 1;
  3355.                     char buf[32];
  3356.                     if (c == CMDQ) {    /* A backslash variable */
  3357.                         int n = 32;
  3358.                         char * s = buf;
  3359.                         buf[0] = NUL;
  3360.                         if (zzstring(s3,&s,&n) < 0 || !buf[0])
  3361.                           ok = 0;
  3362.                         s2 = buf;
  3363.                     } else {            /* A macro */
  3364.                         if ((k = mxlook(mactab,s3,nmac)) < 0)
  3365.                           ok = 0;
  3366.                         else
  3367.                           s2 = mactab[k].mval;
  3368.                     }
  3369.                     if (!ok) {
  3370.                         printf("?Not defined - \"%s\"\n",p[i+1]);
  3371.                         sexprc++;
  3372.                         goto xdosexp;
  3373.                     }
  3374.                     if (!s2) s2 = "";
  3375.                     k = xxfloat(s2,0);
  3376.                     if (k < 1) {
  3377.                         printf("?Not numeric - \"%s\"\n",p[i+1]);
  3378.                         sexprc++;
  3379.                         goto xdosexp;
  3380.                     }
  3381.                     while (*s2 == '+') s2++;
  3382.                     result = atoi(s2);
  3383.                     fpresult = floatval;
  3384.                     if (k > 1 || fpresult != result)
  3385.                       fpflag++;
  3386.                 }
  3387.                 if (n < i+2) {          /* Variable with no value */
  3388.                     s2 = "";
  3389.                     if (x == SX_SET || x == SX_LET) {
  3390.                         delmac(p[i+1],1); /* Delete the variable */
  3391.                         break;
  3392.                     } else {
  3393.                         s2 = "1";
  3394.                     }
  3395.                 } else {                /* Variable with value */
  3396.                     k = xxfloat(p[i+2],0); /* Is it a number? */
  3397.                     if (k > 0) {
  3398.                         s2 = p[i+2];
  3399.                         while (*s2 == '+') s2++;
  3400.                     } else {
  3401.                         s2 = dosexp(p[i+2]); /* Have value, evaluate it */
  3402.                         if (sexprc) goto xdosexp;
  3403.                         if (!s2) s2 = "";
  3404.                         if (!*s2 && (x == SX_INC || x == SX_DEC))
  3405.                           continue;
  3406.                     }
  3407.                 }
  3408.                 if (x == SX_INC || x == SX_DEC) {
  3409.                     k = xxfloat(s2,0);
  3410.                     if (k < 1) {
  3411.                         printf("?Not numeric - \"%s\"\n",s2);
  3412.                         sexprc++;
  3413.                         goto xdosexp;
  3414.                     }
  3415.                     while (*s2 == '+') s2++;
  3416.                     j = atoi(s2);
  3417.                     if (k > 1) {
  3418.                         fpj = floatval;
  3419.                         fpflag++;
  3420.                     } else {
  3421.                         fpj = (CKFLOAT)j;
  3422.                     }
  3423.                     if (x == SX_INC) {
  3424.                         result += j;
  3425.                         fpresult += fpj;
  3426.                     } else if (x == SX_DEC) {
  3427.                         result -= j;
  3428.                         fpresult -= fpj;
  3429.                     }
  3430.                     if (result != fpresult) fpflag++;
  3431.                     s2 = fpflag ? fpformat(fpresult,0,0) : ckitoa(result);
  3432.                 }
  3433.                 if (x == SX_LET && cmdlvl > 0) /* LET makes var local */
  3434.                   addlocal(p[i+1]);
  3435.                 if ((rc = addmac(p[i+1],s2)) < 0) { /* Add the value */
  3436.                     switch (rc) {
  3437.                       case -3: m = "Array not declared"; break;
  3438.                       case -2: m = "Subscript out of range"; break;
  3439.                       case -4: m = "Out of memory"; break;
  3440.                       default: m = "Error creating variable";
  3441.                     }
  3442.                     printf("?%s - \"%s\"\n",m,s);
  3443.                     sexprc++;
  3444.                     goto xdosexp;
  3445.                 }
  3446.                 if (s2) result = atoi(s2);
  3447.             }
  3448.             goto xdosexp;
  3449.         } else if (x == SX_IFC) {               /* Conditional expression */
  3450.             int true = 0;
  3451.             if (n > 4) {
  3452.                 printf("?Too many operands: IF - \"%s\"\n",s);
  3453.                 sexprc++;
  3454.                 goto xdosexp;
  3455.             }
  3456.             s2 = dosexp(p[2]);
  3457.             if (sexprc) goto xdosexp;
  3458.             if (s2) {
  3459.                 j = atoi(s2);
  3460.                 if (xxfloat(s2,0) == 2) {
  3461.                     fpflag++;
  3462.                     fpresult = (CKFLOAT)result;
  3463.                     fpj = floatval;
  3464.                 } else {
  3465.                     fpj = atof(s2);
  3466.                 }
  3467.                 true = ((fpj != 0.0) ? 1 : 0);
  3468.             }
  3469.             if (!true && n < 4) {
  3470.                 s2 = NULL;
  3471.             } else {
  3472.                 s2 = dosexp(true ? p[3] : p[4]);
  3473.                 if (sexprc) goto xdosexp;
  3474.                 j = s2 ? atoi(s2) : 0;
  3475.                 if (xxfloat(s2,0) == 2) {
  3476.                     fpflag++;
  3477.                     fpresult = (CKFLOAT)result;
  3478.                     fpj = floatval;
  3479.                 } else {
  3480.                     fpj = s2 ? atof(s2) : 0.0;
  3481.                 }
  3482.                 fpresult = fpj;
  3483.                 result = j;
  3484.             }
  3485.             goto xdosexp;
  3486.         } else if (x == SX_QUO) {
  3487. #ifndef COMMENT
  3488.             int xx;
  3489.             xx = strlen(p[2]);
  3490.             p[3] = (char *)malloc(xx+4);
  3491.             s2 = p[3];
  3492.             ckmakmsg(p[3],xx+4,"'(",p[2],")",NULL);
  3493.             n++;
  3494. #else
  3495.             s2 = p[2];
  3496. #endif /* COMMENT */
  3497.             goto xdosexp;
  3498.         } else if (x == SX_STR) {
  3499.             int xx;
  3500.             s2 = dosexp(p[2]);
  3501.             if (sexprc) goto xdosexp;
  3502.             xx = strlen(s2);
  3503.             p[3] = (char *)malloc(xx+4);
  3504.             ckmakmsg(p[3],xx+4,"'(",s2,")",NULL);
  3505.             s2 = p[3];
  3506.             n++;
  3507.             goto xdosexp;
  3508.         }
  3509.     }
  3510.     /* Arithmetic operator or macro - Loop thru operands */
  3511.  
  3512.     quit = 0;                           /* Short-circuit flag. */
  3513.     if (macro && n > 1) {               /* If operator is a macro */
  3514.         if (!line) {                    /* allocate local buffer for */
  3515.             line = (char *)malloc(SXMLEN); /* the evaluated argument list. */
  3516.             if (!line) {
  3517.                 printf("?Memory allocation failure - \"%s\"\n",p[1]);
  3518.                 sexprc++;
  3519.                 goto xdosexp;
  3520.             }
  3521.             linelen = SXMLEN;
  3522.             /* debug(F101,"dosexp macro arg buffer","",linelen); */
  3523.         }
  3524.         linepos = 0;
  3525.         line[linepos] = NUL;
  3526.     }
  3527.     for (i = 1; ((i < n) && !sexprc && !quit); i++) { /* Loop thru operands */
  3528.         quote = 0;
  3529.         s2 = p[i+1];                    /* Get operand */
  3530.         if (!s2) s2 = "";
  3531. #ifdef COMMENT
  3532.         if (*s2 == '\047') {            /* Is it quoted? */
  3533.             debug(F110,sexpdebug("'B"),s2,0);
  3534.             s2++;                       /* Space past the quote */
  3535.             quote++;
  3536.             if (*s2 == '(') {           /* Quoted S-Expression? */
  3537.                 char c4, * s4 = s2+1;   /* Strip outer parens */
  3538.                 while ((c4 = *s4++)) {
  3539.                     if (c4 == ')' && !*s4) {
  3540.                         s2++;
  3541.                         *(s4-1) = NUL;
  3542.                         break;
  3543.                     }
  3544.                 }
  3545.             }
  3546.             debug(F110,sexpdebug("'C"),s2,0);
  3547.  
  3548.         } else {                        /* Not quoted */
  3549.             s2 = dosexp(p[i+1]);        /* evaluate it */
  3550.             if (sexprc) goto xdosexp;
  3551.             if (!s2) s2 = "";
  3552.             if (!macro && x == SX_EVA)
  3553.               continue;
  3554.         }
  3555. #else
  3556.         if (*s2 != '\047') {            /* Is it quoted? */
  3557.             s2 = dosexp(p[i+1]);        /* No, evaluate it */
  3558.             if (sexprc) goto xdosexp;
  3559.             if (!s2) s2 = "";
  3560.             if (!macro && x == SX_EVA)
  3561.               continue;
  3562.         }
  3563.         if (*s2 == '\047') {            /* Is result quoted? */
  3564.             debug(F110,sexpdebug("'B"),s2,0);
  3565.             s2++;                       /* Space past the quote */
  3566.             quote++;
  3567.             if (*s2 == '(') {           /* Quoted S-Expression? */
  3568.                 char c4, * s4 = s2+1;   /* Strip outer parens */
  3569.                 while ((c4 = *s4++)) {
  3570.                     if (c4 == ')' && !*s4) {
  3571.                         s2++;
  3572.                         *(s4-1) = NUL;
  3573.                         break;
  3574.                     }
  3575.                 }
  3576.             }
  3577.             debug(F110,sexpdebug("'C"),s2,0);
  3578.         }
  3579. #endif /* COMMENT */
  3580.         if (macro) {
  3581.             debug(F111,sexpdebug("macro arg"),s2,i);
  3582.             if (!*s2) quote++;
  3583.             if (!quote) {
  3584.                 register char c4, * s4 = s2;
  3585.                 while ((c4 = *s4++)) if (c4 == SP) { quote++; break; }
  3586.             }
  3587.             if (quote) line[linepos++] = '{';
  3588.             while ((line[linepos++] = *s2++)) {
  3589.                 if (linepos > linelen - 3) {
  3590.                     char * tmp = NULL;
  3591.                     line[linepos] = NUL;
  3592.                     linelen += SXMLEN;
  3593.                     tmp = (char *) malloc(linelen);
  3594.                     if (!tmp) {
  3595.                         printf("?Memory re-allocation failure - \"%s...\"\n",
  3596.                                line);
  3597.                         sexprc++;
  3598.                         goto xdosexp;
  3599.                     }
  3600.                     strcpy(tmp,line);
  3601.                     free(line);
  3602.                     line = tmp;
  3603.                 }
  3604.             }
  3605.             linepos--;                  /* Back up over NUL */
  3606.             if (quote)
  3607.               line[linepos++] = '}';    /* End quote group */
  3608.             line[linepos++] = SP;       /* add a space */
  3609.             line[linepos] = NUL;        /* and a NUL */
  3610.             continue;
  3611.         }
  3612.         if (!quote) {                   /* Built-in operator... */
  3613.             s2 = dosexp(s2);
  3614.             if (sexprc) goto xdosexp;
  3615.             if (!s2) s2 = "";
  3616.         }
  3617.         if (x == SX_EVA)
  3618.           continue;
  3619.  
  3620.         if (!*s2) {
  3621.             /* An empty value is not a legal number */
  3622.             /* but it is a legal truth value */
  3623.             if (x != SX_AND && x != SX_LOR && x != SX_NOT) {
  3624.                 printf("?Not Numeric - \"%s\"\n",p[i+1]);
  3625.                 sexprc++;
  3626.                 goto xdosexp;
  3627.             }
  3628.             j = 0;
  3629.             fpj = 0.0;
  3630.         } else {
  3631.             j = atoi(s2);
  3632.             /* Switch to floating-point upon encountering any f.p. arg */
  3633.             /* OR... if integer is too big */
  3634.             if (!fpflag) if (xxfloat(s2,0) == 2)
  3635.               fpflag++;
  3636.             fpj = atof(s2);
  3637.         }
  3638.         if (i == 1) {                   /* Initial result is first operand */
  3639.             result = (n == 2 && x == SX_SUB) ? 0-j : j;
  3640.             fpresult = (n == 2 && x == SX_SUB) ? -fpj : fpj;
  3641.             if (!(kwflags & SXF_ONE))   /* Command with single arg */
  3642.               continue;
  3643.         }
  3644.         if (x == SX_MOD || x == SX_DIV) {
  3645.             if (!result)
  3646.               fpflag++;
  3647.             if (!fpj) {
  3648.                 printf("?Divide by zero - \"%s\"\n",cmdbuf);
  3649.                 sexprc++;
  3650.                 goto xdosexp;
  3651.             }
  3652.         }
  3653.         switch (x) {                    /* Accumulate result */
  3654.  
  3655.           case SX_EVA:                  /* EVAL */
  3656.             result = j;
  3657.             fpresult = fpj;
  3658.             break;
  3659.  
  3660.           case SX_ADD:                  /* + */
  3661.             result += j;
  3662.             fpresult += fpj;
  3663.             if (result != fpresult)
  3664.               fpflag++;
  3665.             break;
  3666.  
  3667.           case SX_SUB:                  /* - */
  3668.             result -= j;
  3669.             fpresult -= fpj;
  3670.             if (result != fpresult)
  3671.               fpflag++;
  3672.             break;
  3673.  
  3674.           case SX_MUL:                  /* * */
  3675.             result *= j;
  3676.             fpresult *= fpj;
  3677.             if (result != fpresult)
  3678.               fpflag++;
  3679.             break;
  3680.  
  3681.           case SX_AND:                  /* AND */
  3682.             result = result && j;
  3683.             if (!result) quit++;
  3684.             fpresult = fpresult && fpj;
  3685.             break;
  3686.  
  3687.           case SX_LOR:                  /* OR */
  3688.             result = result || j;
  3689.             if (!result) quit++;
  3690.             fpresult = fpresult || fpj;
  3691.             break;
  3692.  
  3693.           case SX_MOD:                  /* Modulus */
  3694.             result = result % j;
  3695. #ifdef FNFLOAT
  3696.             fpresult = (CKFLOAT)fmod(fpresult,fpj);
  3697.             if (result != fpresult)
  3698.               fpflag++;
  3699. #else
  3700.             fpresult = result;
  3701. #endif /* FNFLOAT */
  3702.             break;
  3703.  
  3704.           case SX_DIV:                  /* / */
  3705.             result /= j;
  3706.             fpresult /= fpj;
  3707.             if (result != fpresult)
  3708.               fpflag++;
  3709.             break;
  3710.  
  3711.           case SX_AEQ:                  /* Test for equality */
  3712.             if (fpflag) {
  3713.                 if (fpresult != fpj)
  3714.                   presult = 0;
  3715.             } else {
  3716.                 if (result != j)
  3717.                   presult = 0;
  3718.             }
  3719.             break;
  3720.  
  3721.           case SX_NEQ:                  /* Test for ineqality */
  3722.             if (fpflag) {
  3723.                 if (fpresult == fpj)
  3724.                   presult = 0;
  3725.             } else {
  3726.                 if (result == j)
  3727.                   presult = 0;
  3728.             }
  3729.             break;
  3730.  
  3731.           case SX_ALE:                  /* Arithmetic less-equal */
  3732.             if (fpflag) {
  3733.                 if (fpj < fpresult)
  3734.                   presult = 0;
  3735.                 fpresult = fpj;
  3736.             } else {
  3737.                 if (j < result)
  3738.                   presult = 0;
  3739.                 result = j;
  3740.             }
  3741.             break;
  3742.  
  3743.           case SX_ALT:                  /* Arithmetic less-than */
  3744.             if (fpflag) {
  3745.                 if (fpj <= fpresult)
  3746.                   presult = 0;
  3747.                 fpresult = fpj;
  3748.             } else {
  3749.                 if (j <= result)
  3750.                   presult = 0;
  3751.                 result = j;
  3752.             }
  3753.             break;
  3754.  
  3755.           case SX_AGT:                  /* Arithmetic greater-than */
  3756.             if (fpflag) {
  3757.                 if (fpj >= fpresult)
  3758.                   presult = 0;
  3759.                 fpresult = fpj;
  3760.             } else {
  3761.                 if (j >= result)
  3762.                   presult = 0;
  3763.                 result = j;
  3764.             }
  3765.             break;
  3766.  
  3767.           case SX_AGE:                  /* Arithmetic greater-equal */
  3768.             if (fpflag) {
  3769.                 if (fpj > fpresult)
  3770.                   presult = 0;
  3771.                 fpresult = fpj;
  3772.             } else {
  3773.                 if (j > result)
  3774.                   presult = 0;
  3775.                 result = j;
  3776.             }
  3777.             break;
  3778.  
  3779.           case SX_POW:                  /* Raise to power */
  3780. #ifdef FNFLOAT
  3781.             {
  3782.                 double dummy;
  3783.                 if (!fpj) {
  3784.                     fpresult = 1.0;
  3785.                 } else if ((!fpresult && fpj <= 0.0)) {
  3786.                     printf("?Divide by zero - \"%s\"\n",cmdbuf);
  3787.                     sexprc++;
  3788.                     goto xdosexp;
  3789.                 } else if (fpresult < 0.0 && modf(fpj,&dummy)) {
  3790.                     printf("?Domain error - \"%s\"\n",cmdbuf);
  3791.                     sexprc++;
  3792.                     goto xdosexp;
  3793.                 } else {
  3794.                     fpresult = (CKFLOAT)pow(fpresult,fpj);
  3795.                 }
  3796.             }
  3797. #endif /* FNFLOAT */
  3798.             if (j == 0) {
  3799.                 result = 1;
  3800.             } else {
  3801.                 int z, sign = 0;
  3802.                 if (j < 0) {
  3803.                     if (result == 0) {
  3804.                         printf("?Divide by zero - \"%s\"\n",cmdbuf);
  3805.                         sexprc++;
  3806.                         goto xdosexp;
  3807.                     }
  3808.                     j = 0 - j;
  3809.                     sign++;
  3810.                 }
  3811.                 z = result;
  3812.                 while (--j > 0)
  3813.                   result *= z;
  3814.                 if (sign)
  3815.                   result = 1 / result;
  3816.             }
  3817.             if (result != fpresult)
  3818.               fpflag++;
  3819.             break;
  3820.  
  3821. #ifdef FNFLOAT
  3822.           case SX_EXP:                  /* e to the given power */
  3823.             fpresult = (CKFLOAT) exp(fpj);
  3824.             break;
  3825.  
  3826.           case SX_LGN:                  /* Natural log */
  3827.           case SX_LGX:                  /* Log base 10 */
  3828.           case SX_SQR:                  /* Square root */
  3829.             if (fpj < 0.0) {
  3830.                 printf("?Argument out of range - \"%s\"\n",cmdbuf);
  3831.                 sexprc++;
  3832.                 goto xdosexp;
  3833.             }
  3834.             if (x == SX_SQR)
  3835.               fpresult = (CKFLOAT) sqrt(fpj);
  3836.             else if (x == SX_LGN)
  3837.               fpresult = (CKFLOAT) log(fpj);
  3838.             else
  3839.               fpresult = (CKFLOAT) log10(fpj);
  3840.             break;
  3841.  
  3842.           case SX_SIN:                  /* sine */
  3843.             fpresult = (CKFLOAT) sin(fpj);
  3844.             break;
  3845.  
  3846.           case SX_COS:                  /* cosine */
  3847.             fpresult = (CKFLOAT) cos(fpj);
  3848.             break;
  3849.  
  3850.           case SX_TAN:                  /* tangent */
  3851.             fpresult = (CKFLOAT) tan(fpj);
  3852.             break;
  3853. #endif /* FNFLOAT */
  3854.  
  3855.           case SX_CEI:                  /* Ceiling */
  3856.             if (j != fpj)
  3857.               if (fpj > 0.0)
  3858.                 fpj += 1.0;
  3859.             fpresult = fpj;
  3860.             fpflag = 1;
  3861.             truncate = 1;
  3862.             break;
  3863.  
  3864.           case SX_FLR:                  /* Floor */
  3865.             if (j != fpj)
  3866.               if (fpj < 0.0)
  3867.                 fpj -= 1.0;
  3868.             fpresult = fpj;
  3869.             fpflag = 1;
  3870.             truncate = 1;
  3871.             break;
  3872.  
  3873.           case SX_TRU:                  /* Truncate */
  3874.             fpresult = fpj;
  3875.             fpflag = 1;
  3876.             truncate = 1;
  3877.             break;
  3878.  
  3879.           case SX_ROU:                  /* Round */
  3880.             if (fpj > 0.0)
  3881.               fpj += 0.5;
  3882.             else if (fpj < 0.0)
  3883.               fpj -= 0.5;
  3884.             fpresult = fpj;
  3885.             fpflag = 1;
  3886.             truncate = 1;
  3887.             break;
  3888.  
  3889.           case SX_ABS:                  /* Absolute value */
  3890.             result = (j < 0) ? 0 - j : j;
  3891.             fpresult = (fpj < 0.0) ? 0.0 - fpj : fpj;
  3892.             if (result != fpresult)
  3893.               fpflag++;
  3894.             break;
  3895.  
  3896.           case SX_MAX:                  /* Max */
  3897.             if (j != fpj)
  3898.               fpflag++;
  3899.             if (fpflag) {
  3900.                 if (fpj > fpresult)
  3901.                   fpresult = fpj;
  3902.             } else
  3903.               if (j > result)
  3904.                 result = j;
  3905.             break;
  3906.  
  3907.           case SX_MIN:                  /* Min */
  3908.             if (j != fpj)
  3909.               fpflag++;
  3910.             if (fpflag) {
  3911.                 if (fpj < fpresult)
  3912.                   fpresult = fpj;
  3913.             } else
  3914.               if (j < result)
  3915.                 result = j;
  3916.             break;
  3917.  
  3918.           case SX_FLO:                  /* Float */
  3919.             fpflag++;
  3920.             fpresult = result;
  3921.             fpj = j;
  3922.             break;
  3923.  
  3924.           case SX_NOT:                  /* NOT (reverse truth value) */
  3925.             fpflag = 0;
  3926.             not++;
  3927.             break;
  3928.  
  3929.           case SX_BWA:                  /* Bitwise AND */
  3930.             fpflag = 0;
  3931.             result &= j;
  3932.             break;
  3933.  
  3934.           case SX_BWO:                  /* Bitwise OR */
  3935.             fpflag = 0;
  3936.             result |= j;
  3937.             break;
  3938.  
  3939.           case SX_BWX:                  /* Bitwise XOR */
  3940.           case SX_XOR:                  /* Logical XOR */
  3941.             if (n > 3) {
  3942.                 printf("?Too many operands - \"%s\"\n",s);
  3943.                 sexprc++;
  3944.                 goto xdosexp;
  3945.             }
  3946.             fpflag = 0;
  3947.             if (x == SX_BWX) {
  3948.                 result ^= j;
  3949.             } else {
  3950.                 result = (result && !j) || (!result && j);
  3951.                 if (result) result = 1;
  3952.             }
  3953.             break;
  3954.  
  3955.           case SX_BWN:                  /* Bitwise Not */
  3956.             fpflag = 0;
  3957.             result = ~result;
  3958.             break;
  3959.  
  3960.           default:
  3961.             printf("BAD OP [%s]\n",p[1]);
  3962.             sexprc++;
  3963.         }
  3964.     }
  3965.     if (!pflag)                         /* Not a predicate */
  3966.       sexppv = -1;                      /* So unset this */
  3967.  
  3968.   /* domacro: */
  3969.  
  3970.     if (macro) {                        /* User-defined macro */
  3971.         extern int fsexpflag;           /* (see fneval():ckuus4.c) */
  3972.         int lookagain = 0;              /* Maybe the macro table changed */
  3973.         if (mactab[mx].kwd) {           /* Check and see */
  3974.             if (ckstrcmp(mactab[mx].kwd,p[1],-1,0))
  3975.               lookagain++;
  3976.         } else
  3977.           lookagain++;
  3978.         if (lookagain) {                /* The table changed */
  3979.             mx = mxlook(mactab,p[1],nmac); /* Get the macro's new index */
  3980.             debug(F111,sexpdebug("macro moved"),p[1],mx);
  3981.             if (mx < 0) {                  /* Yikes! */
  3982.                 printf("?Macro disappeared! - \"%s\"\n",p[1]);
  3983.                 sexprc++;
  3984.                 goto xdosexp;
  3985.             }
  3986.         }
  3987.         debug(F111,sexpdebug("macro mx"),mactab[mx].kwd,mx);
  3988.         if (fsexpflag) {                /* If embedded in a function call */
  3989.             if (cmpush() > -1) {        /* get a new copy of the parsing */
  3990.                 extern int ifc;         /* environment, */
  3991.                 int k, ifcsav = ifc;    /* save the IF state */
  3992.                 dodo(mx,line,0);        /* Set up the macro */
  3993.                 k = parser(1);          /* Call the parser to execute it */
  3994.                 cmpop();                /* Pop back to previous level */
  3995.                 ifc = ifcsav;           /* restore IF state */
  3996.                 if (k == 0)             /* If no error */
  3997.                   s2 = mrval[maclvl+1]; /* get return value, if any */
  3998.                 if (!s2) s2 = "";
  3999.                 debug(F110,sexpdebug("macro return"),s2,0);
  4000.             } else {
  4001.                 printf("?Resources exhausted - \"%s\"\n",s);
  4002.                 sexprc++;
  4003.             }
  4004.         } else {                        /* Not embedded in a function call */
  4005.             dodo(mx,line,0);            /* As above but without cmpush/pop() */
  4006.             k = parser(1);
  4007.             if (k == 0)
  4008.               s2 = mrval[maclvl+1];
  4009.             if (!s2) s2 = "";
  4010.         }
  4011.     } else if (pflag) {                 /* Predicate */
  4012.         if (not) presult = presult ? 0 : 1;
  4013.         sexppv = presult;               /* So set predicate value (0 or 1) */
  4014.         s2 = presult ? "1" : "0";
  4015.     } else if (fpflag) {                /* Result is floating-point */
  4016.         if (not) fpresult = fpresult ? 0.0 : 1.0;
  4017.         s2 = fpformat(fpresult,0,0);
  4018.     } else if (x != SX_EVA) {
  4019.         if (not) result = result ? 0 : 1;
  4020.         s2 = ckitoa(result);
  4021.     }
  4022.  
  4023. /* Common exit point.  Always come here to exit. */
  4024.  
  4025.   xdosexp:
  4026.  
  4027.     if (!s2) s2 = "";
  4028.     if (!sexprc && s2) {                /* Have a result */
  4029.         char * sx;
  4030.         char * q2 = s2; int xx = 0;
  4031.         if (*s2) {
  4032.             while (*q2++) xx++;         /* Get length */
  4033.             if (xx > sexprmax)          /* (stats) */
  4034.               sexprmax = xx;
  4035.         } else
  4036.           xx = 0;
  4037.         if (xx > sxrlen[sexpdep] || !sxresult[sexpdep]) {
  4038.             int k;
  4039.             k = xx + xx / 4;
  4040.             if (k < 32) k = 32;
  4041.             if (sxresult[sexpdep])
  4042.               free(sxresult[sexpdep]);
  4043.             if ((sxresult[sexpdep] = (char *)malloc(k))) {
  4044.                 sxrlen[sexpdep] = k;
  4045.             } else {
  4046.                 printf("?Memory allocation failure - \"%s\"\n",s2);
  4047.                 sexprc++;
  4048.             }
  4049.         }
  4050.         sx = sxresult[sexpdep];         /* Point to result buffer */
  4051.         while ((*sx++ = *s2++)) ;       /* copy result. */
  4052.         if (fpflag && truncate) {       /* Floating point + truncate */
  4053.             sx = sxresult[sexpdep];     /* at decimal point */
  4054.             for (i = xx - 1; i >= 0; i--) {
  4055.                 if (sx[i] == '.') {
  4056.                     sx[i] = NUL;
  4057.                     if (i == 0) {       /* If nothing left */
  4058.                         sx[0] = '0';    /* put a zero. */
  4059.                         sx[1] = NUL;
  4060.                     }
  4061.                 }
  4062.             }
  4063.         }
  4064.     }
  4065.     if (line)                           /* If macro arg buffer allocated */
  4066.       free(line);                       /* free it. */
  4067.     if (mustfree) {                     /* And free local copy of split list */
  4068.         for (i = 1; i <= n; i++) {
  4069.             if (p[i]) free(p[i]);
  4070.         }
  4071.     }
  4072.     debug(F111,sexpdebug("exit"),sxresult[sexpdep],sexprc);
  4073.     return(sxresult[sexpdep--]);
  4074. }
  4075. #endif /* NOSEXP */
  4076. #endif /* NOSPL */
  4077.  
  4078. int                                     /* CHECK command */
  4079. dochk() {
  4080.     int x, y;
  4081.     if ((y = cmkey(ftrtab,nftr,"","",xxstring)) < 0)
  4082.       return(y);
  4083.     ckstrncpy(line,atmbuf,LINBUFSIZ);
  4084.     if ((y = cmcfm()) < 0)
  4085.       return(y);
  4086. #ifndef NOPUSH
  4087.     if (!ckstrcmp(line,"push",(int)strlen(line),0)) {
  4088.         if (msgflg)                     /* If at top level... */
  4089.           printf(" push%s available\n", nopush ? " not" : "");
  4090.         else if (nopush && !backgrd)
  4091.           printf(" CHECK: push not available\n");
  4092.         return(success = 1 - nopush);
  4093.     }
  4094. #endif /* NOPUSH */
  4095. #ifdef PIPESEND
  4096.     if (!ckstrcmp(line,"pipes",(int)strlen(line),0)) {
  4097.         if (msgflg)                     /* If at top level... */
  4098.           printf(" pipes%s available\n",
  4099.                  (nopush || protocol != PROTO_K) ? " not" : "");
  4100.         else if ((nopush || protocol != PROTO_K) && !backgrd)
  4101.           printf(" CHECK: pipes not available\n");
  4102.         return(success = 1 - nopush);
  4103.     }
  4104. #endif /* PIPESEND */
  4105.     y = lookup(ftrtab,line,nftr,&x);    /* Look it up */
  4106.     debug(F111,"dochk",ftrtab[x].kwd,y);
  4107.     if (msgflg)                         /* If at top level... */
  4108.       printf(" %s%s available\n", ftrtab[x].kwd, y ? " not" : "");
  4109.     else if (y && !backgrd)
  4110.       printf(" CHECK: %s not available\n", ftrtab[x].kwd);
  4111.     return(success = 1 - y);
  4112. }
  4113.  
  4114. #ifndef NOLOCAL
  4115. #ifdef CKLOGDIAL
  4116.  
  4117. /* Connection log and elapsed-time reporting */
  4118.  
  4119. extern char cxlogbuf[];                 /* Log record buffer */
  4120. extern char diafil[];                   /* Log file name */
  4121. extern int dialog, cx_active;           /* Flags */
  4122. static long cx_prev = 0L;               /* Elapsed time of previous session */
  4123.  
  4124. #endif /* CKLOGDIAL */
  4125. #endif /* NOLOCAL */
  4126.  
  4127. VOID
  4128. dologend() {                            /* Write record to connection log */
  4129. #ifdef LOCUS
  4130.     extern int locus, autolocus;
  4131. #endif /* LOCUS */
  4132.  
  4133. #ifndef NOLOCAL
  4134. #ifdef CKLOGDIAL
  4135.     long d1, d2, t1, t2;
  4136.     char buf[32], * p;
  4137. #endif /* CKLOGDIAL */
  4138. #endif /* NOLOCAL */
  4139.  
  4140. #ifdef LOCUS
  4141.     if (autolocus) {
  4142.         int x = locus;
  4143. #ifdef NEWFTP
  4144.         extern int ftpisconnected();
  4145.         locus = ftpisconnected() ? 0 : 1;
  4146. #else
  4147.         locus = 1;
  4148. #endif /* NEWFTP */
  4149.         if (msgflg && (x != locus)) {
  4150.             printf("Switching LOCUS for file-management commands to %s.\n",
  4151.                    locus ? "LOCAL" : "REMOTE"
  4152.                    );
  4153.         }
  4154.     }
  4155. #endif /* LOCUS */
  4156.  
  4157. #ifndef NOLOCAL
  4158. #ifdef CKLOGDIAL
  4159.     debug(F101,"dologend dialog","",dialog);
  4160.     debug(F101,"dologend cxlogbuf[0]","",cxlogbuf[0]);
  4161. #ifdef CKSYSLOG
  4162.     debug(F101,"dologend ckxlogging","",ckxlogging);
  4163. #endif /* CKSYSLOG */
  4164.  
  4165.     if (!cx_active || !cxlogbuf[0])     /* No active record */
  4166.       return;
  4167.  
  4168.     cx_active = 0;                      /* Record is not active */
  4169.     debug(F111,"dologend cxlogbuf 1",cxlogbuf,cx_active);
  4170.  
  4171.     d1 = mjd((char *)cxlogbuf);         /* Get start date of this session */
  4172.     ckstrncpy(buf,ckdate(),31);         /* Get current date */
  4173.     d2 = mjd(buf);                      /* Convert them to mjds */
  4174.     p = cxlogbuf;                       /* Get start time */
  4175.     p[11] = NUL;
  4176.     p[14] = NUL;                        /* Convert to seconds */
  4177.     t1 = atol(p+9) * 3600L + atol(p+12) * 60L + atol(p+15);
  4178.     p[11] = ':';
  4179.     p[14] = ':';
  4180.     p = buf;                            /* Get end time */
  4181.     p[11] = NUL;
  4182.     p[14] = NUL;
  4183.     t2 = atol(p+9) * 3600L + atol(p+12) * 60L + atol(p+15);
  4184.     t2 = ((d2 - d1) * 86400L) + (t2 - t1); /* Compute elapsed time */
  4185.     debug(F101,"dologend t2","",t2);
  4186.     if (t2 > -1L) {
  4187.         cx_prev = t2;
  4188.         p = hhmmss(t2);
  4189.         debug(F110,"dologend hhmmss",p,0);
  4190.         strncat(cxlogbuf,"E=",CXLOGBUFL); /* Append to log record */
  4191.         strncat(cxlogbuf,p,CXLOGBUFL);
  4192.         debug(F110,"dologend cxlogbuf 2",cxlogbuf,0);
  4193.     } else
  4194.       cx_prev = 0L;
  4195.     debug(F101,"dologend cx_prev","",cx_prev);
  4196.     if (dialog) {                       /* If logging */
  4197.         int x;
  4198.         x = diaopn(diafil,1,1);         /* Open log in append mode */
  4199.         debug(F101,"dologend diaopn","",x);
  4200.         x = zsoutl(ZDIFIL,cxlogbuf);    /* Write the record */
  4201.         debug(F101,"dologend zsoutl","",x);
  4202.         x = zclose(ZDIFIL);             /* Close the log */
  4203.         debug(F101,"dologend zclose","",x);
  4204.     }
  4205. #ifdef CKSYSLOG
  4206.     debug(F101,"dologend ckxlogging","",ckxlogging);
  4207.     if (ckxlogging) {
  4208.         int x;
  4209.         x = ckindex("T=DIAL",cxlogbuf,0,0,1);
  4210.         debug(F111,"dologend ckxsyslog",cxlogbuf,ckxsyslog);
  4211.         debug(F111,"dologend ckindex","T=DIAL",x);
  4212.         if (x > 0) {
  4213.             if (ckxsyslog >= SYSLG_DI) {
  4214.                 debug(F110,"dologend syslog",cxlogbuf+18,0);
  4215.                 cksyslog(SYSLG_DI,1,"CONNECTION",(char *)(cxlogbuf+18),"");
  4216.             } else if (ckxsyslog >= SYSLG_AC) {
  4217.                 debug(F110,"dologend syslog",cxlogbuf+18,0);
  4218.                 cksyslog(SYSLG_AC,1,"CONNECTION",(char *)(cxlogbuf+18),"");
  4219.             }
  4220.         }
  4221.     }
  4222. #endif /* CKSYSLOG */
  4223. #endif /* CKLOGDIAL */
  4224. #endif /* NOLOCAL */
  4225. }
  4226.  
  4227. #ifndef NOLOCAL
  4228. #ifdef CKLOGDIAL
  4229.  
  4230. /*  D O L O G S H O W  --  Show session/connection info  */
  4231.  
  4232. /* Call with fc == 1 to show, fc == 0 to only calculate. */
  4233. /* Returns session elapsed time in seconds. */
  4234. /* If no session active, returns elapsed time of previous session, if any, */
  4235. /* otherwise 0 */
  4236.  
  4237. long
  4238. dologshow(fc) int fc; {                 /* SHOW (current) CONNECTION */
  4239.     long d1, d2, t1, t2 = 0, prev;
  4240.     char c, buf1[32], buf2[32], * info[32], * p, * s;
  4241.     char * xlogbuf, xbuf[CXLOGBUFL+1];
  4242.     int i, x = 0, z, ftp = 0, active = 0;
  4243.  
  4244. #ifdef NEWFTP
  4245.     extern char ftplogbuf[];
  4246.     extern long ftplogprev;
  4247.     extern int ftplogactive;
  4248.     if (fc & W_FTP) {
  4249.         fc &= 63;
  4250.         ftp = 1;
  4251.         xlogbuf = ftplogbuf;
  4252.         prev = ftplogprev;
  4253.         active = ftplogactive;
  4254.     } else {
  4255. #endif /* NEWFTP */
  4256.         ftp = 0;
  4257.         xlogbuf = cxlogbuf;
  4258.         prev = cx_prev;
  4259.         active = cx_active;
  4260. #ifdef NEWFTP
  4261.     }
  4262. #endif /* NEWFTP */
  4263.  
  4264.     debug(F101,"dologshow local","",local);
  4265.     debug(F101,"dologshow ftp","",ftp);
  4266.     debug(F111,"dologshow active",xlogbuf,active);
  4267.  
  4268.     if (!xlogbuf[0]) {
  4269.         if (fc) {
  4270.             if (didsetlin || ftp)
  4271.               printf(" %s: No record.\n", ftp ? "FTP" : "Kermit");
  4272.             else
  4273.               printf(" %s: No connection.\n", ftp ? "FTP" : "Kermit");
  4274.         }
  4275.         return(prev);
  4276.     }
  4277.  
  4278. #ifdef NEWFTP
  4279.     if (ftp) {
  4280.         z = ftpisconnected() ? 1 : -1;
  4281.     } else {
  4282. #endif /* NEWFTP */
  4283.         if (local) {                    /* See if we have an open connection */
  4284.             z = ttchk();
  4285.             debug(F101,"dologshow ttchk","",z);
  4286.             z = (z > -1) ? 1 : -2;
  4287.         } else {
  4288.             z = active ? 1 : -2;
  4289.         }
  4290. #ifdef NEWFTP
  4291.     }
  4292. #endif /* NEWFTP */
  4293.     if (z < 0L) {
  4294.         if (!fc)
  4295.           return(prev);
  4296.         else
  4297.           t2 = prev;
  4298.     }
  4299.     /* Note: NOT ckstrncpy! */
  4300.     strncpy(buf1,xlogbuf,17);           /* Copy of just the timestamp */
  4301.     buf1[17] = NUL;                     /* Terminate it */
  4302.     ckstrncpy(xbuf,xlogbuf+18,CXLOGBUFL); /* Copy that can be poked */
  4303.     debug(F111,"dologshow prev",xbuf,prev);
  4304.  
  4305.     xwords(xbuf,31,info,1);             /* Break up into fields */
  4306.     d1 = mjd(buf1);                     /* Convert start time to MJD */
  4307.     ckstrncpy(buf2,ckdate(),31);        /* Current date */
  4308.     d2 = mjd(buf2);                     /* Convert to MJD */
  4309.     p = buf1;                           /* Point to start time */
  4310.     p[11] = NUL;
  4311.     p[14] = NUL;                        /* Convert to seconds */
  4312.     t1 = atol(p+9) * 3600L + atol(p+12) * 60L + atol(p+15);
  4313.     p[11] = ':';
  4314.     p[14] = ':';
  4315.     p = buf2;                           /* Ditto for current time */
  4316.     p[11] = NUL;
  4317.     p[14] = NUL;
  4318.     if (z > -1L) {
  4319.         t2 = atol(p+9) * 3600L + atol(p+12) * 60L + atol(p+15);
  4320.         t2 = ((d2 - d1) * 86400L) + (t2 - t1); /* Elapsed time so far */
  4321.     }
  4322.     if (fc) {
  4323.         p = NULL;
  4324.         if (t2 > -1L)                   /* Convert seconds to hh:mm:ss */
  4325.           p = hhmmss(t2);
  4326.         if (z > -1)
  4327.           s = "Active";
  4328.         else if (z == -2)
  4329.           s = "Closed";
  4330.         else
  4331.           s = "Unknown";
  4332.         printf("\n");                   /* Show results */
  4333.         printf(" Status:       %s\n",s);
  4334.         printf(" Opened:       %s\n",buf1);
  4335.         printf(" User:         %s\n",info[1] ? info[1] : "");
  4336.         printf(" PID:          %s\n",info[2] ? info[2] : "");
  4337.         for (i = 3; info[i]; i++) {
  4338.             c = info[i][0];
  4339.             s = (info[i]) ? info[i]+2 : "";
  4340.             switch (c) {
  4341.               case 'T': printf(" Type:         %s\n", s); break;
  4342.               case 'N': printf(" To:           %s\n", s); break;
  4343.               case 'H': printf(" From:         %s\n", s); break;
  4344.               case 'D': printf(" Device:       %s\n", s); break;
  4345.               case 'O': printf(" Origin:       %s\n", s); break;
  4346.               case 'E': break;
  4347.               default:  printf(" %s\n",info[i] ? info[i] : "");
  4348.             }
  4349.         }
  4350.         if (z < 0L)
  4351.           printf(" Elapsed time: %s\n", hhmmss(t2));
  4352.         else
  4353.           printf(" Elapsed time: %s\n", p ? p : "(unknown)");
  4354.         x = 0;
  4355. #ifdef NETCONN
  4356. #ifdef SSHBUILTIN
  4357.         if ( IS_SSH() ) x++;
  4358. #endif /* SSHBUILTIN */
  4359. #ifdef CK_ENCRYPTION
  4360.         if (ck_tn_encrypting() && ck_tn_decrypting()) x++;
  4361. #endif /* CK_ENCRYPTION */
  4362. #ifdef CK_SSL
  4363.         if (tls_active_flag || ssl_active_flag) x++;
  4364. #endif /* CK_SSL */
  4365. #ifdef RLOGCODE
  4366. #ifdef CK_KERBEROS
  4367. #ifdef CK_ENCRYPTION
  4368.         if (ttnproto == NP_EK4LOGIN || ttnproto == NP_EK5LOGIN) x++;
  4369. #endif /* CK_ENCRYPTION */
  4370. #endif /* CK_KERBEROS */
  4371. #endif /* RLOGCODE */
  4372. #endif /* NETCONN */
  4373.         if (z > 0)
  4374.           printf(" Encrypted:    %s\n", x ? "Yes" : "No");
  4375.         printf(" Log:          %s\n", dialog ? diafil : "(none)");
  4376.         printf("\n");
  4377.     }
  4378.     return(t2 > -1L ? t2 : 0L);
  4379. }
  4380.  
  4381. VOID
  4382. dologline() {
  4383.     char * p;
  4384.     int n, m = 0;
  4385.  
  4386.     dologend();                         /* Previous session not closed out? */
  4387.     cx_active = 1;                      /* Record is active */
  4388.     cx_prev = 0L;
  4389.     p = ckdate();                       /* Get timestamp */
  4390.     n = ckstrncpy(cxlogbuf,p,CXLOGBUFL-1); /* Start record off with it */
  4391.     if (!uidbuf[0]) {
  4392.         debug(F100,"dologline uidbuf empty","",0);
  4393. #ifdef UNIX                             /* Who has whoami()... */
  4394.         ckstrncpy(uidbuf,(char *)whoami(),UIDBUFLEN);
  4395. #else
  4396. #ifdef STRATUS
  4397.         ckstrncpy(uidbuf,(char *)whoami(),UIDBUFLEN);
  4398. #else
  4399.         ckstrncpy(uidbuf,"UNKNOWN",UIDBUFLEN);
  4400. #endif /* STRATUS */
  4401. #endif /* UNIX */
  4402.     }
  4403.     m = strlen(uidbuf) + strlen(myhost) + strlen(ttname) + 32;
  4404.     if (n+m < CXLOGBUFL-1) {            /* Add serial device info */
  4405.         p = cxlogbuf+n;
  4406.         sprintf(p," %s %s T=SERIAL H=%s D=%s ", /* SAFE */
  4407.                 uidbuf,
  4408.                 ckgetpid(),
  4409.                 myhost,
  4410.                 ttname
  4411.                 );
  4412.     } else
  4413.       ckstrncpy(cxlogbuf,"LOGLINE BUFFER OVERFLOW",CXLOGBUFL);
  4414.     debug(F110,"dologline",cxlogbuf,0);
  4415. }
  4416.  
  4417. #ifdef NETCONN
  4418. VOID
  4419. dolognet() {
  4420.     char * p, * s = "NET", * uu = uidbuf;
  4421.     int n, m;
  4422.  
  4423.     dologend();                         /* Previous session not closed out? */
  4424.     cx_prev = 0L;
  4425.     cx_active = 1;                      /* Record is active */
  4426.     p = ckdate();
  4427.     n = ckstrncpy(cxlogbuf,p,CXLOGBUFL);
  4428. #ifdef TCPSOCKET
  4429.     if (nettype == NET_TCPB || nettype == NET_TCPA)
  4430.       s = "TCP";
  4431. #endif /* TCPSOCKET */
  4432. #ifdef ANYX25
  4433.     if (nettype == NET_SX25 || nettype == NET_VX25 || nettype == NET_IX25)
  4434.       s = "X25";
  4435. #endif /* ANYX25 */
  4436. #ifdef DECNET
  4437.     if (nettype == NET_DEC)
  4438.       s = "DECNET";
  4439. #endif /* DECNET */
  4440. #ifdef SUPERLAT
  4441.     if (nettype == NET_SLAT)
  4442.       s = "SUPERLAT";
  4443. #endif /* SUPERLAT */
  4444. #ifdef CK_NETBIOS
  4445.     if (nettype == NET_BIOS)
  4446.       s = "NETBIOS";
  4447. #endif /* CK_NETBIOS */
  4448.  
  4449.     if (!uu[0]) {
  4450.         debug(F100,"dolognet uidbuf empty","",0);
  4451. #ifdef OS2ORUNIX                        /* Who has whoami()... */
  4452.         uu = (char *)whoami();
  4453. #else
  4454. #ifdef STRATUS
  4455.         uu = (char *)whoami();
  4456. #else
  4457.         uu = "UNKNOWN";
  4458. #endif /* STRATUS */
  4459. #endif /* UNIX */
  4460.     }
  4461.     m = strlen(uu) + strlen(myhost) + strlen(ttname) + strlen(s) + 32;
  4462.     if (n+m < CXLOGBUFL-1) {            /* SAFE */
  4463.         p = cxlogbuf+n;
  4464.         sprintf(p," %s %s T=%s N=%s H=%s ",
  4465.                 uu,
  4466.                 ckgetpid(),
  4467.                 s,
  4468.                 ttname,
  4469.                 myhost
  4470.                 );
  4471.     } else
  4472.       ckstrncpy(cxlogbuf,"LOGNET BUFFER OVERFLOW",CXLOGBUFL);
  4473.     debug(F110,"dolognet cxlogbuf",cxlogbuf,0);
  4474. }
  4475. #endif /* NETCONN */
  4476. #endif /* CKLOGDIAL */
  4477.  
  4478. #ifndef NODIAL
  4479. /*
  4480.   Parse a DIAL-related string, stripping enclosing braces, if any.
  4481. */
  4482. static int
  4483. dialstr(p,msg) char **p; char *msg; {
  4484.     int x;
  4485.     char *s;
  4486.  
  4487.     if ((x = cmtxt(msg, "", &s, xxstring)) < 0)
  4488.       return(x);
  4489.     s = brstrip(s);                     /* Strip braces around. */
  4490.     debug(F110,"dialstr",s,0);
  4491.     makestr(p,*s?s:NULL);
  4492.     return(success = 1);
  4493. }
  4494.  
  4495. VOID
  4496. initmdm(x) int x; {
  4497.     MDMINF * p;
  4498.     int m;
  4499.  
  4500.     mdmtyp = x;                         /* Set global modem type */
  4501.     debug(F101,"initmdm mdmtyp","",mdmtyp);
  4502.     debug(F101,"initmdm usermdm","",usermdm);
  4503.     if (x < 1) return;
  4504.  
  4505.     m = usermdm ? usermdm : mdmtyp;
  4506.  
  4507.     p = modemp[m];                      /* Point to modem info struct, and */
  4508.     debug(F101,"initmdm p","",p);
  4509.     if (p) {
  4510.         dialec = p->capas & CKD_EC;     /* set DIAL ERROR-CORRECTION, */
  4511.         dialdc = p->capas & CKD_DC;     /* DIAL DATA-COMPRESSION, and */
  4512.         mdmspd = p->capas & CKD_SB ? 0 : 1; /* DIAL SPEED-MATCHING from it. */
  4513.         dialfc = FLO_AUTO;                  /* Modem's local flow control.. */
  4514.         dialmax   = p->max_speed;
  4515.         dialcapas = p->capas;
  4516.         dialesc   = p->esc_char;
  4517.     } else if (mdmtyp > 0) {
  4518.         printf("WARNING: modem info for \"%s\" not filled in yet\n",
  4519.                gmdmtyp()
  4520.                );
  4521.     }
  4522.  
  4523. /* Reset or set the SET DIAL STRING items ... */
  4524.  
  4525. #ifdef DEBUG
  4526.     if (deblog) {
  4527.         debug(F110,"initmdm dialini",dialini,0);
  4528.         debug(F110,"initmdm dialmstr ",dialmstr,0);
  4529.         debug(F110,"initmdm dialmprmt",dialmprmt,0);
  4530.         debug(F110,"initmdm dialcmd",dialcmd,0);
  4531.         debug(F110,"initmdm dialdcon",dialdcon,0);
  4532.         debug(F110,"initmdm dialdcoff",dialdcoff,0);
  4533.         debug(F110,"initmdm dialecon",dialecon,0);
  4534.         debug(F110,"initmdm dialecoff",dialecoff,0);
  4535.         debug(F110,"initmdm dialhcmd",dialhcmd,0);
  4536.         debug(F110,"initmdm dialhwfc",dialhwfc,0);
  4537.         debug(F110,"initmdm dialswfc",dialswfc,0);
  4538.         debug(F110,"initmdm dialnofc",dialnofc,0);
  4539.         debug(F110,"initmdm dialtone",dialtone,0);
  4540.         debug(F110,"initmdm dialpulse",dialpulse,0);
  4541.         debug(F110,"initmdm dialname",dialname,0);
  4542.         debug(F110,"initmdm dialaaon",dialaaon,0);
  4543.         debug(F110,"initmdm dialaaoff",dialaaoff,0);
  4544.         debug(F110,"initmdm dialx3",dialx3,0);
  4545.         debug(F110,"initmdm dialspon",dialspon,0);
  4546.         debug(F110,"initmdm dialspoff",dialspoff,0);
  4547.         debug(F110,"initmdm dialvol1",dialvol1,0);
  4548.         debug(F110,"initmdm dialvol2",dialvol2,0);
  4549.         debug(F110,"initmdm dialvol3",dialvol3,0);
  4550.         debug(F110,"initmdm dialini2",dialini2,0);
  4551.     }
  4552. #endif /* DEBUG */
  4553.  
  4554.     if (usermdm && p) { /* USER-DEFINED: copy info from specified template */
  4555.  
  4556.         makestr(&dialini  ,p->wake_str);
  4557.         makestr(&dialmstr ,p->dmode_str);
  4558.         makestr(&dialmprmt,p->dmode_prompt);
  4559.         makestr(&dialcmd  ,p->dial_str);
  4560.         makestr(&dialdcon ,p->dc_on_str);
  4561.         makestr(&dialdcoff,p->dc_off_str);
  4562.         makestr(&dialecon ,p->ec_on_str);
  4563.         makestr(&dialecoff,p->ec_off_str);
  4564.         makestr(&dialhcmd ,p->hup_str);
  4565.         makestr(&dialhwfc ,p->hwfc_str);
  4566.         makestr(&dialswfc ,p->swfc_str);
  4567.         makestr(&dialnofc ,p->nofc_str);
  4568.         makestr(&dialtone ,p->tone);
  4569.         makestr(&dialpulse,p->pulse);
  4570.         makestr(&dialname ,"This space available (use SET MODEM NAME)");
  4571.         makestr(&dialaaon ,p->aa_on_str);
  4572.         makestr(&dialaaoff,p->aa_off_str);
  4573.         makestr(&dialx3   ,p->ignoredt);
  4574.         makestr(&dialspon ,p->sp_on_str);
  4575.         makestr(&dialspoff,p->sp_off_str);
  4576.         makestr(&dialvol1 ,p->vol1_str);
  4577.         makestr(&dialvol2 ,p->vol2_str);
  4578.         makestr(&dialvol3 ,p->vol3_str);
  4579.         makestr(&dialini2 ,p->ini2);
  4580.  
  4581.     } else {                    /* Not user-defined, so wipe out overrides */
  4582.  
  4583.         if (dialini)   makestr(&dialini,NULL);   /* Init-string */
  4584.         if (dialmstr)  makestr(&dialmstr,NULL);  /* Dial-mode-str */
  4585.         if (dialmprmt) makestr(&dialmprmt,NULL); /* Dial-mode-pro */
  4586.         if (dialcmd)   makestr(&dialcmd,NULL);   /* Dial-command  */
  4587.         if (dialdcon)  makestr(&dialdcon,NULL);  /* DC ON command */
  4588.         if (dialdcoff) makestr(&dialdcoff,NULL); /* DC OFF command */
  4589.         if (dialecon)  makestr(&dialecon,NULL);  /* EC ON command */
  4590.         if (dialecoff) makestr(&dialecoff,NULL); /* EC OFF command */
  4591.         if (dialhcmd)  makestr(&dialhcmd,NULL);  /* Hangup command */
  4592.         if (dialhwfc)  makestr(&dialhwfc,NULL);  /* Flow control... */
  4593.         if (dialswfc)  makestr(&dialswfc,NULL);  /*  */
  4594.         if (dialnofc)  makestr(&dialnofc,NULL);  /*  */
  4595.         if (dialtone)  makestr(&dialtone,NULL);  /* Dialing method */
  4596.         if (dialpulse) makestr(&dialpulse,NULL); /*  */
  4597.         if (dialname)  makestr(&dialname,NULL);  /* Modem name */
  4598.         if (dialaaon)  makestr(&dialaaon,NULL);  /* Autoanswer On */
  4599.         if (dialaaoff) makestr(&dialaaoff,NULL); /* Autoanswer Off */
  4600.         if (dialx3)    makestr(&dialx3,NULL);    /* Ignore dialtone */
  4601.         if (dialspon)  makestr(&dialspon,NULL);  /* Speaker On */
  4602.         if (dialspoff) makestr(&dialspoff,NULL); /* Speaker Off */
  4603.         if (dialvol1)  makestr(&dialvol1,NULL);  /* Low volume */
  4604.         if (dialvol2)  makestr(&dialvol2,NULL);  /* Medium volume */
  4605.         if (dialvol3)  makestr(&dialvol3,NULL);  /* High volume */
  4606.         if (dialini2)  makestr(&dialini2,NULL);  /* Init string 2 */
  4607.     }
  4608.     if (autoflow)                       /* Maybe change flow control */
  4609.       setflow();
  4610.  
  4611. #ifndef MINIDIAL
  4612. #ifdef OLDTBCODE
  4613.     tbmodel = 0;           /* If it's a Telebit, we don't know the model yet */
  4614. #endif /* OLDTBCODE */
  4615. #endif /* MINIDIAL */
  4616. }
  4617.  
  4618. #ifdef COMMENT
  4619. /* Not implemented yet */
  4620. int
  4621. setanswer() {
  4622.     int x, y;
  4623.     extern int ans_cid, ans_ring;
  4624.     if ((x = cmkey(answertab,nanswertab,"","",xxstring)) < 0)
  4625.       return(x);
  4626.     switch (x) {
  4627.       case XYA_CID:
  4628.         return(seton(&ans_cid));
  4629.       case XYA_RNG:
  4630.         y = cmnum("How many rings before answering","1",10,&x,xxstring);
  4631.         y = setnum(&ans_rings,x,y,254);
  4632.         return(y);
  4633.     }
  4634. }
  4635. #endif /* COMMENT */
  4636.  
  4637. int
  4638. setmodem() {                            /* SET MODEM */
  4639.  
  4640.     int x, y, z;
  4641.     long zz;
  4642.     struct FDB k1, k2;
  4643.     extern int mdmset;
  4644.  
  4645.     cmfdbi(&k1,_CMKEY,
  4646.            "Modem parameter","","",nsetmdm, 0, xxstring, setmdm, &k2);
  4647.     cmfdbi(&k2,_CMKEY,"","","",nmdm,0,xxstring,mdmtab,NULL);
  4648.     x = cmfdb(&k1);
  4649.     if (x < 0) {                        /* Error */
  4650.         if (x == -2 || x == -9)
  4651.           printf("?No keywords match: \"%s\"\n",atmbuf);
  4652.         return(x);
  4653.     }
  4654.     y = cmresult.nresult;               /* Keyword value */
  4655.     if (cmresult.fdbaddr == &k2) {      /* Modem-type keyword table */
  4656.         if ((x = cmcfm()) < 0)
  4657.           return(x);
  4658.         usermdm = 0;
  4659.         initmdm(cmresult.nresult);      /* Set the modem type. */
  4660.         return(success = 1);            /* Done */
  4661.     }
  4662.     switch (cmresult.nresult) {         /* SET MODEM keyword table. */
  4663. #ifdef MDMHUP
  4664.       case XYDMHU:                      /* DIAL MODEM-HANGUP */
  4665.         if ((y = cmkey(mdmhang,4,"how to hang up modem",
  4666.                        "modem-command", xxstring)) < 0)
  4667.           return(y);
  4668.         if ((x = cmcfm()) < 0)
  4669.           return(x);
  4670.         dialmhu = y;
  4671. #ifdef COMMENT
  4672. /* Nope, I fixed it (2001 11 08) */
  4673. #ifdef CK_SCOV5
  4674.         if (dialmhu == 0 && !quiet) {
  4675.             printf(
  4676. "\n WARNING: RS-232 signal sampling and manipulation do not work\n"
  4677.                     );
  4678.             printf(
  4679. " in the standard SCO OSR5 serial i/o drivers.  SET MODEM HANGUP-METHOD\n"
  4680.                    );
  4681.             printf(
  4682. " MODEM-COMMAND is recommended for OSR5.\n\n"
  4683.                     );
  4684.         }
  4685. #endif /* CK_SCOV5 */
  4686. #endif /* COMMENT */
  4687.         return(success = 1);
  4688. #endif /* MDMHUP */
  4689.  
  4690.       case XYDCAP:
  4691.         zz = 0L;
  4692.         y = 0;
  4693.         while (y != -3) {
  4694.             if ((y = cmkey(mdmcap,nmdmcap,
  4695.                            "capability of modem", "", xxstring)) < 0) {
  4696.                 if (y == -3)
  4697.                   break;
  4698.                 else
  4699.                   return(y);
  4700.             }
  4701.             zz |= y;
  4702.         }
  4703.         if ((x = cmcfm()) < 0)
  4704.           return(x);
  4705.         dialcapas = zz;
  4706.         debug(F101,"setmodem autoflow","",autoflow);
  4707.         debug(F101,"setmodem flow 1","",flow);
  4708.         if (autoflow)                   /* Maybe change flow control */
  4709.           setflow();
  4710.         debug(F101,"setmodem flow 2","",flow);
  4711.         mdmspd = zz & CKD_SB ? 0 : 1;   /* Set MODEM SPEED-MATCHING from it. */
  4712.         return(success = 1);
  4713.  
  4714.       case XYDMAX:
  4715. #ifdef TN_COMPORT
  4716.         if (network && istncomport())
  4717.           x = cmkey(tnspdtab,ntnspd,line,"",xxstring);
  4718.         else
  4719. #endif /* TN_COMPORT */
  4720.           x = cmkey(spdtab,nspd,line,"",xxstring);
  4721.         if (x < 0) {
  4722.             if (x == -3) printf("?value required\n");
  4723.             return(x);
  4724.         }
  4725.         if ((y = cmcfm()) < 0) return(y);
  4726.         dialmax = (long) x * 10L;
  4727.         if (dialmax == 70) dialmax = 75;
  4728.         return(success = 1);
  4729.  
  4730.       case XYDSTR:                      /* These moved from SET DIAL */
  4731.       case XYDDC:
  4732.       case XYDEC:
  4733.       case XYDESC:
  4734.       case XYDFC:
  4735.       case XYDKSP:
  4736.       case XYDSPD:
  4737.       case XYDDIA:
  4738.         return(setdial(x));
  4739.  
  4740.       case XYDTYP:
  4741.         if ((y = cmkey(mdmtab,nmdm,"modem type","none", xxstring)) < 0)
  4742.           return(y);
  4743.         if (y == dialudt) {             /* User-defined modem type */
  4744.             if ((x = cmkey(mdmtab,nmdm,"based on existing modem type",
  4745.                            "unknown", xxstring)) < 0)
  4746.               return(x);
  4747.         }
  4748.         if ((z = cmcfm()) < 0)
  4749.           return(z);
  4750.         usermdm = 0;
  4751.         usermdm = (y == dialudt) ? x : 0;
  4752.         initmdm(y);
  4753.         mdmset = (mdmtyp > 0);
  4754.         return(success = 1);
  4755.  
  4756.       case XYDNAM:
  4757.         return(dialstr(&dialname,"Descriptive name for modem"));
  4758.  
  4759.       case XYDMCD:                      /* SET MODEM CARRIER-WATCH */
  4760.         return(setdcd());
  4761.  
  4762.       case XYDSPK:                      /* SET MODEM SPEAKER */
  4763.         return(seton(&mdmspk));
  4764.  
  4765.       case XYDVOL:                      /* SET MODEM VOLUME */
  4766.         if ((x = cmkey(voltab,3,"","medium",xxstring)) < 0)
  4767.           return(x);
  4768.         if ((y = cmcfm()) < 0)
  4769.           return(y);
  4770.         mdmvol = x;
  4771.         return(success = 1);
  4772.  
  4773.       default:
  4774.         printf("Unexpected SET MODEM parameter\n");
  4775.         return(-9);
  4776.     }
  4777. }
  4778.  
  4779. static int                              /* Set DIAL command options */
  4780. setdial(y) int y; {
  4781.     int x = 0, z = 0;
  4782.     char *s = NULL;
  4783.  
  4784.     if (y < 0)
  4785.       if ((y = cmkey(dialtab,ndial,"","",xxstring)) < 0)
  4786.         return(y);
  4787.     switch (y) {
  4788.       case XYDHUP:                      /* DIAL HANGUP */
  4789.         return(seton(&dialhng));
  4790.       case XYDINI:                      /* DIAL INIT-STRING */
  4791.         return(dialstr(&dialini,"Modem initialization string"));
  4792.       case XYDNPR:                      /* DIAL PREFIX */
  4793.         return(dialstr(&dialnpr,"Telephone number prefix"));
  4794.       case XYDDIA:                      /* DIAL DIAL-COMMAND */
  4795.         x = cmtxt("Dialing command for modem,\n\
  4796.  include \"%s\" to stand for phone number,\n\
  4797.  for example, \"set dial dial-command ATDT%s\\13\"",
  4798.                   "",
  4799.                   &s,
  4800.                   xxstring);
  4801.         if (x < 0 && x != -3)           /* Handle parse errors */
  4802.           return(x);
  4803.         s = brstrip(s);                 /* Strip braces or quotes */
  4804.         y = x = strlen(s);              /* Get length of text */
  4805.         if (y > 0) {                    /* If there is any text (left), */
  4806.             for (x = 0; x < y; x++) {   /* make sure they included "%s" */
  4807.                 if (s[x] != '%') continue;
  4808.                 if (s[x+1] == 's') break;
  4809.             }
  4810.             if (x == y) {
  4811.                 printf(
  4812. "?Dial-command must contain \"%cs\" for phone number.\n",'%');
  4813.                 return(-9);
  4814.             }
  4815.         }
  4816.         if (dialcmd) {                  /* Free any previous string. */
  4817.             free(dialcmd);
  4818.             dialcmd = (char *) 0;
  4819.         }
  4820.         if (y > 0) {
  4821.             dialcmd = malloc(y + 1);    /* Allocate space for it */
  4822.             if (dialcmd)
  4823.               strcpy(dialcmd,s);        /* and make a safe copy. */
  4824.         }
  4825.         return(success = 1);
  4826. #ifndef NOXFER
  4827.       case XYDKSP:                      /* DIAL KERMIT-SPOOF */
  4828.         return(seton(&dialksp));
  4829. #endif /* NOXFER */
  4830.       case XYDTMO:                      /* DIAL TIMEOUT */
  4831.         y = cmnum("Seconds to wait for call completion","0",10,&x,xxstring);
  4832.         if (y < 0) return(y);
  4833.         y = cmnum("Kermit/modem timeout differential","10",10,&z,xxstring);
  4834.         if (y < 0) return(y);
  4835.         if ((y = cmcfm()) < 0)
  4836.           return(y);
  4837.         dialtmo = x;
  4838.         mdmwaitd = z;
  4839.       case XYDESC:                      /* DIAL ESCAPE-CHARACTER */
  4840.         y = cmnum("ASCII value of character to escape back to modem",
  4841.                   "43",10,&x,xxstring);
  4842.         y = setnum(&dialesc,x,y,128);
  4843.         if (y > -1 && dialesc < 0)      /* No escape character */
  4844.           dialmhu = 0;                  /* So no hangup by modem command */
  4845.         return(y);
  4846.       case XYDDPY:                      /* DIAL DISPLAY */
  4847.         return(seton(&dialdpy));
  4848.       case XYDSPD:                      /* DIAL SPEED-MATCHING */
  4849.                                         /* used to be speed-changing */
  4850.         if ((y = seton(&mdmspd)) < 0) return(y);
  4851. #ifdef COMMENT
  4852.         mdmspd = 1 - mdmspd;            /* so here we reverse the meaning */
  4853. #endif /* COMMENT */
  4854.         return(success = 1);
  4855.       case XYDMNP:                      /* DIAL MNP-ENABLE */
  4856.       case XYDEC:                       /* DIAL ERROR-CORRECTION */
  4857.         x = seton(&dialec);
  4858.         if (x > 0)
  4859.           if (!dialec) dialdc = 0;      /* OFF also turns off compression */
  4860.         return(x);
  4861.  
  4862.       case XYDDC:                       /* DIAL COMPRESSION */
  4863.         x = seton(&dialdc);
  4864.         if (x > 0)
  4865.           if (dialdc) dialec = 1;       /* ON also turns on error correction */
  4866.         return(x);
  4867.  
  4868. #ifdef MDMHUP
  4869.       case XYDMHU:                      /* DIAL MODEM-HANGUP */
  4870.         return(seton(&dialmhu));
  4871. #endif /* MDMHUP */
  4872.  
  4873. #ifndef NOSPL
  4874.       case XYDDIR:                      /* DIAL DIRECTORY (zero or more) */
  4875.         return(parsdir(0));             /* 0 means DIAL */
  4876. #endif /* NOSPL */
  4877.  
  4878.       case XYDSTR:                      /* DIAL STRING */
  4879.         if ((y = cmkey(mdmcmd,nmdmcmd,"","",xxstring)) < 0) return(y);
  4880.         switch (y) {
  4881.           case XYDS_AN:                 /* Autoanswer ON/OFF */
  4882.           case XYDS_DC:                 /* Data compression ON/OFF */
  4883.           case XYDS_EC:                 /* Error correction ON/OFF */
  4884.             if ((x = cmkey(onoff,2,"","on",xxstring)) < 0)
  4885.               return(x);
  4886.             sprintf(tmpbuf,"Modem's command to %sable %s", /* SAFE */
  4887.                     x ? "en" : "dis",
  4888.                     (y == XYDS_DC) ? "compression" :
  4889.                     ((y == XYDS_EC) ? "error-correction" :
  4890.                     "autoanswer")
  4891.                     );
  4892.             if (x) {
  4893.                 if (y == XYDS_DC)
  4894.                   return(dialstr(&dialdcon,tmpbuf));
  4895.                 else if (y == XYDS_EC)
  4896.                   return(dialstr(&dialecon,tmpbuf));
  4897.                 else
  4898.                   return(dialstr(&dialaaon,tmpbuf));
  4899.             } else {
  4900.                 if (y == XYDS_DC)
  4901.                   return(dialstr(&dialdcoff,tmpbuf));
  4902.                 else if (y == XYDS_EC)
  4903.                   return(dialstr(&dialecoff,tmpbuf));
  4904.                 else
  4905.                   return(dialstr(&dialaaoff,tmpbuf));
  4906.             }
  4907.           case XYDS_HU:                 /*    hangup command */
  4908.             return(dialstr(&dialhcmd,"Modem's hangup command"));
  4909.           case XYDS_HW:                 /*    hwfc */
  4910.             return(dialstr(&dialhwfc,
  4911.                            "Modem's command to enable hardware flow control"));
  4912.           case XYDS_IN:                 /*    init */
  4913.             return(dialstr(&dialini,"Modem's initialization string"));
  4914.           case XYDS_NF:                 /*    no flow control */
  4915.             return(dialstr(&dialnofc,
  4916.                            "Modem's command to disable local flow control"));
  4917.           case XYDS_PX:                 /*    prefix */
  4918.             return(dialstr(&dialnpr,"Telephone number prefix for dialing"));
  4919.           case XYDS_SW:                 /*    swfc */
  4920.             return(dialstr(&dialswfc,
  4921.                    "Modem's command to enable local software flow control"));
  4922.           case XYDS_DT:                 /*    tone dialing */
  4923.             return(dialstr(&dialtone,
  4924.                    "Command to configure modem for tone dialing"));
  4925.           case XYDS_DP:                 /*    pulse dialing */
  4926.             return(dialstr(&dialpulse,
  4927.                            "Command to configure modem for pulse dialing"));
  4928.           case XYDS_MS:                 /*    dial mode string */
  4929.             return(dialstr(&dialmstr,
  4930.                          "Command to enter dial mode"));
  4931.           case XYDS_MP:                 /*    dial mode prompt */
  4932.             return(dialstr(&dialmprmt,
  4933.                            "Modem response upon entering dial mode"));
  4934.           case XYDS_SP:                 /* SPEAKER OFF */
  4935.             if ((x = cmkey(onoff,2,"","on",xxstring)) < 0) return(x);
  4936.             if (x)
  4937.               return(dialstr(&dialspon,"Command to turn modem speaker on"));
  4938.             else
  4939.               return(dialstr(&dialspoff,"Command to turn modem speaker off"));
  4940.  
  4941.           case XYDS_VO:                 /* VOLUME LOW */
  4942.             if ((x = cmkey(voltab,3,"","medium",xxstring)) < 0) return(x);
  4943.             switch (x) {
  4944.               case 0:
  4945.               case 1:
  4946.                 return(dialstr(&dialvol1,
  4947.                                "Command for low modem speaker volume"));
  4948.               case 2:
  4949.                 return(dialstr(&dialvol2,
  4950.                            "Command for medium modem speaker volume"));
  4951.  
  4952.               case 3:
  4953.                 return(dialstr(&dialvol3,
  4954.                                "Command for high modem speaker volume"));
  4955.               default:
  4956.                 return(-2);
  4957.             }
  4958.  
  4959.           case XYDS_ID:                 /* IGNORE-DIALTONE */
  4960.             return(dialstr(&dialx3,
  4961.                            "Command to tell modem to ignore dialtone"));
  4962.  
  4963.           case XYDS_I2:                 /* PREDIAL-INIT */
  4964.             return(dialstr(&dialini2,
  4965.                            "Command to send to modem just prior to dialing"));
  4966.  
  4967.           default:
  4968.             printf("?Unexpected SET DIAL STRING parameter\n");
  4969.         }
  4970.  
  4971.       case XYDFC:                       /* DIAL FLOW-CONTROL */
  4972.         if ((y = cmkey(dial_fc,4,"","auto",xxstring)) < 0) return(y);
  4973.         if ((x = cmcfm()) < 0) return(x);
  4974.         dialfc = y;
  4975.         return(success = 1);
  4976.  
  4977.       case XYDMTH: {                    /* DIAL METHOD */
  4978.         extern int dialmauto;
  4979.         if ((y = cmkey(dial_m,ndial_m,"","default",xxstring)) < 0)
  4980.           return(y);
  4981.         if ((x = cmcfm()) < 0)
  4982.           return(x);
  4983.         if (y == XYDM_A) {              /* AUTO */
  4984.             dialmauto = 1;              /* local country code, if known. */
  4985.             dialmth = XYDM_D;
  4986.         } else {
  4987.           dialmauto = 0;                /* use the method specified */
  4988.           dialmth = y;
  4989.         }
  4990.         return(success = 1);
  4991.       }
  4992.       case XYDRTM:
  4993.         y = cmnum("Number of times to try dialing a number",
  4994.                   "1",10,&x,xxstring);
  4995.         return(setnum(&dialrtr,x,y,16383));
  4996.  
  4997.       case XYDINT:
  4998.         y = cmnum("Seconds to wait between redial attempts",
  4999.                   "30",10,&x,xxstring);
  5000.         return(setnum(&dialint,x,y,128));
  5001.  
  5002.       case XYDLAC:                      /* DIAL AREA-CODE */
  5003.         if ((x = dialstr(&diallac,"Area code you are calling from")) < 0)
  5004.           return(x);
  5005.         if (diallac) {
  5006.             if (!rdigits(diallac)) {
  5007.                 printf("?Sorry, area code must be numeric\n");
  5008.                 if (*diallac == '(')
  5009.                   printf("(please omit the parentheses)\n");
  5010.                 if (*diallac == '/')
  5011.                   printf("(no slashes, please)\n");
  5012.                 if (diallac) free(diallac);
  5013.                 diallac = NULL;
  5014.                 return(-9);
  5015.             }
  5016.         }
  5017.         return(x);
  5018.  
  5019.       case XYDCNF:                      /* CONFIRMATION */
  5020.         return(success = seton(&dialcnf));
  5021.  
  5022.       case XYDCVT:                      /* CONVERT-DIRECTORY */
  5023.         if ((y = cmkey(dcnvtab,3,"","ask",xxstring)) < 0)
  5024.           return(y);
  5025.         if ((x = cmcfm()) < 0)
  5026.           return(x);
  5027.         dialcvt = y;
  5028.         return(success = 1);
  5029.  
  5030.       case XYDLCC:                      /* DIAL COUNTRY-CODE */
  5031.         x = dialstr(&diallcc,"Country code you are calling from");
  5032.         if (x < 1) return(x);
  5033.         if (diallcc) {
  5034.             if (!rdigits(diallcc)) {
  5035.                 printf("?Sorry, country code must be numeric\n");
  5036.                 if (*diallcc == '+')
  5037.                   printf("(please omit the plus sign)\n");
  5038.                 if (diallcc) free(diallcc);
  5039.                 diallcc = NULL;
  5040.                 return(-9);
  5041.             }
  5042.             if (!strcmp(diallcc,"1")) { /* Set defaults for USA and Canada */
  5043.                 if (!dialldp)           /* Long-distance prefix */
  5044.                   makestr(&dialldp,"1");
  5045.                 if (!dialixp)           /* International dialing prefix */
  5046.                   makestr(&dialixp,"011");
  5047.                 if (ntollfree == 0) {   /* Toll-free area codes */
  5048.                     if ((dialtfc[0] = malloc(4))) {
  5049.                         strcpy(dialtfc[0],"800"); /* 1970-something */
  5050.                         ntollfree++;
  5051.                         if ((dialtfc[1] = malloc(4))) {
  5052.                             strcpy(dialtfc[1],"888"); /* 1996 */
  5053.                             ntollfree++;
  5054.                             if ((dialtfc[2] = malloc(4))) {
  5055.                                 strcpy(dialtfc[2],"877"); /* 5 April 1998 */
  5056.                                 ntollfree++;
  5057.                                 if ((dialtfc[3] = malloc(4))) {
  5058.                                     strcpy(dialtfc[3],"866"); /* 2000? */
  5059.                                     ntollfree++;
  5060.                                 }
  5061.                             }
  5062.                         }
  5063.                     }
  5064.                 }
  5065.                 if (!dialtfp)           /* Toll-free dialing prefix */
  5066.                   makestr(&dialtfp,"1");
  5067. #ifdef COMMENT
  5068. /* The time for this is past */
  5069.             } else if (!strcmp(diallcc,"358") &&
  5070.                        ((int) strcmp(zzndate(),"19961011") > 0)
  5071.                        ) {              /* Finland */
  5072.                 if (!dialldp)           /* Long-distance prefix */
  5073.                   makestr(&dialldp,"9");
  5074.                 if (!dialixp)           /* International dialing prefix */
  5075.                   makestr(&dialixp,"990");
  5076. #endif /* COMMENT */
  5077.             } else {                    /* Everywhere else ... */
  5078.                 if (!dialldp) {
  5079.                     if ((dialldp = malloc(4)))
  5080.                       strcpy(dialldp,"0");
  5081.                 }
  5082.                 if (!dialixp) {
  5083.                     if ((dialixp = malloc(4)))
  5084.                       strcpy(dialixp,"00");
  5085.                 }
  5086.             }
  5087.             if (!strcmp(diallcc,"33"))  /* France */
  5088.               dialfld = 1;              /* Long-distance dialing is forced */
  5089.         }
  5090.         return(success = 1);
  5091.  
  5092.       case XYDIXP:                      /* DIAL INTL-PREFIX */
  5093.         return(dialstr(&dialixp,"International dialing prefix"));
  5094.  
  5095.       case XYDIXS:                      /* DIAL INTL-SUFFIX */
  5096.         return(dialstr(&dialixs,"International dialing suffix"));
  5097.  
  5098.       case XYDLDP:                      /* DIAL LD-PREFIX */
  5099.         return(dialstr(&dialldp,"Long-distance dialing prefix"));
  5100.  
  5101.       case XYDLDS:                      /* DIAL LD-SUFFIX */
  5102.         return(dialstr(&diallds,"Long-distance dialing suffix"));
  5103.  
  5104.       case XYDLCP:                      /* DIAL LC-PREFIX */
  5105.         return(dialstr(&diallcp,"Local dialing prefix"));
  5106.  
  5107.       case XYDLCS:                      /* DIAL LC-SUFFIX */
  5108.         return(dialstr(&diallcs,"Local dialing suffix"));
  5109.  
  5110. #ifdef COMMENT
  5111.       case XYDPXX:                      /* DIAL PBX-EXCHANGE */
  5112.         return(dialstr(&dialpxx,"Exchange of PBX you are calling from"));
  5113. #endif /* COMMENT */
  5114.  
  5115.       case XYDPXI: {                    /* DIAL PBX-INTERNAL-PREFIX */
  5116. #ifdef COMMENT
  5117.           return(dialstr(&dialpxi,
  5118.                        "Internal-call prefix of PBX you are calling from"));
  5119. #else
  5120.           int x;
  5121.           if ((x = cmtxt("Internal-call prefix of PBX you are calling from",
  5122.                          "",&s,NULL)) < 0) /* Don't evaluate */
  5123.             return(x);
  5124. #ifndef NOSPL
  5125.           if (*s) {
  5126.               char c, * p = tmpbuf;
  5127.               if (*s == '\\') {
  5128.                   c = *(s+1);
  5129.                   if (isupper(c)) c = tolower(c);
  5130.                   if (c != 'f' &&
  5131.                       ckstrcmp(s,"\\v(d$px)",8,0) &&
  5132.                       ckstrcmp(s,"\\v(d$pxx)",9,0) &&
  5133.                       ckstrcmp(s,"\\v(d$p)",7,0)) {
  5134.                       x = TMPBUFSIZ;
  5135.                       zzstring(s,&p,&x);
  5136.                       s = tmpbuf;
  5137.                   }
  5138.               }
  5139.           }
  5140. #endif /* NOSPL */
  5141.           makestr(&dialpxi,s);
  5142.           return(1);
  5143.       }
  5144. #endif /* COMMENT */
  5145.  
  5146.       case XYDPXO:                      /* DIAL PBX-OUTSIDE-PREFIX */
  5147.         return(dialstr(&dialpxo,
  5148.                        "Outside-line prefix of PBX you are calling from"));
  5149.  
  5150.       case XYDSFX:                      /* DIAL INTL-SUFFIX */
  5151.         return(dialstr(&dialsfx," Telephone number suffix for dialing"));
  5152.  
  5153.       case XYDSRT:                      /* DIAL SORT */
  5154.         return(success = seton(&dialsrt));
  5155.  
  5156.       case XYDPXX:                      /* DIAL PBX-EXCHANGE */
  5157.       case XYDTFC: {                    /* DIAL TOLL-FREE-AREA-CODE  */
  5158.           int n, i;                     /* (zero or more of them...) */
  5159.           char * p[MAXTOLLFREE];        /* Temporary pointers */
  5160.           char * m;
  5161.           for (n = 0; n < MAXTOLLFREE; n++) {
  5162.               if (n == 0) {
  5163.                   m = (y == XYDTFC) ?
  5164.                   "Toll-free area code(s) in the country you are calling from"
  5165.                     : "Exchange(s) of PBX you are calling from";
  5166.               } else {
  5167.                   m = (y == XYDTFC) ?
  5168.                     "Another toll-free area code"
  5169.                       : "Another PBX exchange";
  5170.               }
  5171.               if ((x = cmfld(m,"",&s,xxstring)) < 0)
  5172.                 break;
  5173.               if (s) {
  5174.                   int k;
  5175.                   k = (int) strlen(s);
  5176.                   if (k > 0) {
  5177.                       if ((p[n] = malloc(k + 1)))
  5178.                         strcpy(p[n], s); /* safe */
  5179.                   } else break;
  5180.               } else break;
  5181.           }
  5182.           if (x == -3) {                /* Command was successful */
  5183.               int m;
  5184.               m = (y == XYDTFC) ? ntollfree : ndialpxx;
  5185.               if ((x = cmcfm()) < 0)
  5186.                 return(x);
  5187.               x = 1;
  5188.               for (i = 0; i < m; i++) { /* Remove old list, if any */
  5189.                   if  (y == XYDTFC)
  5190.                     makestr(&(dialtfc[i]),NULL);
  5191.                   else
  5192.                     makestr(&(dialpxx[i]),NULL);
  5193.               }
  5194.               if  (y == XYDTFC)
  5195.                 ntollfree = n;          /* New count */
  5196.               else
  5197.                 ndialpxx = n;
  5198.               for (i = 0; i < n; i++) { /* New list */
  5199.                   if  (y == XYDTFC)
  5200.                     makestr(&(dialtfc[i]),p[i]);
  5201.                   else
  5202.                     makestr(&(dialpxx[i]),p[i]);
  5203.               }
  5204.               x = 1;
  5205.           }
  5206.           for (i = 0; i < n; i++)
  5207.             if (p[i]) free(p[i]);
  5208.           return(x);
  5209.       }
  5210.  
  5211.       case XYDTFP:                      /* TOLL-FREE-PREFIX */
  5212.         return(dialstr(&dialtfp,
  5213.                        " Long-distance prefix for toll-free dialing"));
  5214.  
  5215.       case XYDCON:                      /* CONNECT */
  5216.         z = -1;
  5217.         if ((y = cmkey(crrtab,ncrr,"","auto",xxstring)) < 0) return(y);
  5218.         if (y != CAR_OFF)               /* AUTO or ON? */
  5219.           if ((z = cmkey(qvtab,nqvt,"","verbose",xxstring)) < 0) return(z);
  5220.         if ((x = cmcfm()) < 0) return(x);
  5221.         if (z > -1)
  5222.           dialcq = z;
  5223.         dialcon = y;
  5224.         return(success = 1);
  5225.  
  5226.       case XYDRSTR:                     /* RESTRICT */
  5227.         if ((y = cmkey(drstrtab,4,"","none",xxstring)) < 0) return(y);
  5228.         if ((x = cmcfm()) < 0) return(x);
  5229.         dialrstr = y;
  5230.         return(success = 1);
  5231.  
  5232.       case XYDLLAC: {                   /* Local area-code list  */
  5233.           int n, i;                     /* (zero or more of them...) */
  5234.           char * p[MAXLOCALAC]; /* Temporary pointers */
  5235.           for (n = 0; n < MAXLOCALAC; n++) {
  5236.               if ((x = cmfld(
  5237.                     "Area code to which calls from your area are local",
  5238.                        "",&s,xxstring)) < 0)
  5239.                 break;
  5240.               if (s) {
  5241.                   int k;
  5242.                   k = (int) strlen(s);
  5243.                   if (k > 0) {
  5244.                       if ((p[n] = malloc(k + 1)))
  5245.                         strcpy(p[n], s); /* safe */
  5246.                   } else break;
  5247.               } else break;
  5248.           }
  5249.           if (x == -3) {                /* Command was successful */
  5250.               if ((x = cmcfm()) < 0)
  5251.                 return(x);
  5252.               for (i = 0; i < nlocalac; i++) /* Remove old list, if any */
  5253.                 if (diallcac[i]) {
  5254.                     free(diallcac[i]);
  5255.                     diallcac[i] = NULL;
  5256.                 }
  5257.               nlocalac = n;             /* New count */
  5258.               for (i = 0; i < nlocalac; i++) /* New list */
  5259.                 diallcac[i] = p[i];
  5260.               return(success = 1);
  5261.           } else {                      /* Parse error, undo everything */
  5262.               for (i = 0; i < n; i++)
  5263.                 if (p[i]) free(p[i]);
  5264.               return(x);
  5265.           }
  5266.       }
  5267.  
  5268.       case XYDFLD:
  5269.         return(success = seton(&dialfld));
  5270.  
  5271.       case XYDIDT:                      /* DIAL IGNORE-DIALTONE */
  5272.         return(seton(&dialidt));
  5273.  
  5274.       case XYDPAC:
  5275.         y = cmnum(
  5276.               "Milliseconds to pause between each character sent to dialer",
  5277.                   "",10,&x,xxstring);
  5278.         return(setnum(&dialpace,x,y,9999));
  5279.  
  5280. #ifndef NOSPL
  5281.       case XYDMAC:
  5282.         if ((x = cmfld("Name of macro to execute just prior to dialing",
  5283.                        "",&s,xxstring)) < 0) {
  5284.             if (x == -3)
  5285.               s = NULL;
  5286.             else
  5287.               return(x);
  5288.         }
  5289.         if (s) {
  5290.             if (!*s) {
  5291.                 s = NULL;
  5292.             } else {
  5293.                 ckstrncpy(line,s,LINBUFSIZ);
  5294.                 s = line;
  5295.             }
  5296.         }
  5297.         if ((x = cmcfm()) < 0)
  5298.           return(x);
  5299.         makestr(&dialmac,s);
  5300.         return(success = 1);
  5301. #endif /* NOSPL */
  5302.  
  5303.       case XYDPUCC:                     /* Pulse country codes */
  5304.       case XYDTOCC: {                   /* Tone country codes */
  5305.           int n, i;
  5306.           char * p[MAXTPCC];
  5307.           char * m;
  5308.           for (n = 0; n < MAXTPCC; n++) {
  5309.               if (n == 0) {
  5310.                   m = (y == XYDPUCC) ?
  5311.                   "Country code where Pulse dialing is required"
  5312.                     : "Country code where Tone dialing is available";
  5313.               } else
  5314.                 m = "Another country code";
  5315.               if ((x = cmfld(m,"",&s,xxstring)) < 0)
  5316.                 break;
  5317.               if (s) {
  5318.                   int k;
  5319.                   k = (int) strlen(s);
  5320.                   if (k > 0) {
  5321.                       if ((p[n] = malloc(k + 1)))
  5322.                         strcpy(p[n], s); /* safe */
  5323.                   } else break;
  5324.               } else break;
  5325.           }
  5326.           if (x == -3) {                /* Command was successful */
  5327.               int m;
  5328.               m = (y == XYDPUCC) ? ndialpucc : ndialtocc;
  5329.               if ((x = cmcfm()) < 0)
  5330.                 return(x);
  5331.               x = 1;
  5332.               for (i = 0; i < m; i++) { /* Remove old list, if any */
  5333.                   if (y == XYDPUCC)
  5334.                     makestr(&(dialpucc[i]),NULL);
  5335.                   else
  5336.                     makestr(&(dialtocc[i]),NULL);
  5337.               }
  5338.               if (y == XYDPUCC) {
  5339.                   ndialpucc = n;                /* New count */
  5340.               } else {
  5341.                   ndialtocc = n;
  5342.               }
  5343.               for (i = 0; i < n; i++) { /* New list */
  5344.                   if (y == XYDPUCC) {
  5345.                       makestr(&(dialpucc[i]),p[i]);
  5346.                   } else {
  5347.                       makestr(&(dialtocc[i]),p[i]);
  5348.                   }
  5349.               }
  5350.               x = 1;
  5351.           }
  5352.           for (i = 0; i < n; i++)
  5353.             if (p[i]) free(p[i]);
  5354.           return(x);
  5355.       }
  5356.       case XYDTEST:
  5357.         return(seton(&dialtest));
  5358.  
  5359.       default:
  5360.         printf("?Unexpected SET DIAL parameter\n");
  5361.         return(-9);
  5362.     }
  5363. }
  5364.  
  5365. #ifdef CK_TAPI
  5366. int                                             /* TAPI action commands */
  5367. dotapi() {
  5368.     int x,y;
  5369.     char *s;
  5370.  
  5371.     if (!TAPIAvail) {
  5372.         printf("\nTAPI is unavailable on this system.\n");
  5373.         return(-9);
  5374.     }
  5375.     if ((y = cmkey(tapitab,ntapitab,"MS TAPI command","",xxstring)) < 0)
  5376.       return(y);
  5377.     switch (y) {
  5378.       case XYTAPI_CFG: {                        /* TAPI CONFIGURE-LINE */
  5379.           extern struct keytab * tapilinetab;
  5380.           extern struct keytab * _tapilinetab;
  5381.           extern int ntapiline;
  5382.           extern int LineDeviceId;
  5383.           int lineID=LineDeviceId;
  5384.           if (TAPIAvail)
  5385.             cktapiBuildLineTable(&tapilinetab, &_tapilinetab, &ntapiline);
  5386.           if (tapilinetab && _tapilinetab && ntapiline > 0) {
  5387.               int i=0, j = 9999, k = -1;
  5388.  
  5389.               if ( LineDeviceId == -1 ) {
  5390.                   /* Find out what the lowest numbered TAPI device is */
  5391.                   /* and use it as the default.                       */
  5392.                   for (i = 0; i < ntapiline; i++ ) {
  5393.                       if (tapilinetab[i].kwval < j) {
  5394.                           k = i;
  5395.                       }
  5396.                   }
  5397.               } else {
  5398.                   /* Find the LineDeviceId in the table and use that entry */
  5399.                   for (i = 0; i < ntapiline; i++ ) {
  5400.                       if (tapilinetab[i].kwval == LineDeviceId) {
  5401.                           k = i;
  5402.                           break;
  5403.                       }
  5404.                   }
  5405.               }
  5406.               if (k >= 0)
  5407.                 s = _tapilinetab[k].kwd;
  5408.               else
  5409.                 s = "";
  5410.  
  5411.               if ((y = cmkey(_tapilinetab,ntapiline,
  5412.                               "TAPI device name",s,xxstring)) < 0)
  5413.                 return(y);
  5414.               lineID = y;
  5415.           }
  5416.           if ((x = cmcfm()) < 0) return(x);
  5417. #ifdef IKSD
  5418.           if (inserver) {
  5419.               printf("Sorry, command disabled\r\n");
  5420.               return(success = 0);
  5421.           }
  5422. #endif /* ISKD */
  5423.           cktapiConfigureLine(lineID);
  5424.           break;
  5425.       }
  5426.       case XYTAPI_DIAL:                 /* TAPI DIALING-PROPERTIES */
  5427.         if ((x = cmcfm()) < 0)
  5428.           return(x);
  5429. #ifdef IKSD
  5430.         if (inserver) {
  5431.             printf("Sorry, command disabled\r\n");
  5432.             return(success = 0);
  5433.         }
  5434. #endif /* ISKD */
  5435.         cktapiDialingProp();
  5436.         break;
  5437.     }
  5438.     return(success = 1);
  5439. }
  5440.  
  5441. static int                              /* SET TAPI command options */
  5442. settapi() {
  5443.     int x, y;
  5444.     char *s;
  5445.  
  5446.     if (!TAPIAvail) {
  5447.         printf("\nTAPI is unavailable on this system.\n");
  5448.         return(-9);
  5449.     }
  5450.     if ((y = cmkey(settapitab,nsettapitab,"MS TAPI option","",xxstring)) < 0)
  5451.       return(y);
  5452.     switch (y) {
  5453.       case XYTAPI_USE:
  5454.         return (success = seton(&tapiusecfg));
  5455.       case XYTAPI_LGHT:
  5456.         return (success = seton(&tapilights));
  5457.       case XYTAPI_PRE:
  5458.         return (success = seton(&tapipreterm));
  5459.       case XYTAPI_PST:
  5460.         return (success = seton(&tapipostterm));
  5461.       case XYTAPI_INA:
  5462.         y = cmnum("seconds of inactivity before auto-disconnect",
  5463.                   "0",10,&x,xxstring);
  5464.         return(setnum(&tapiinactivity,x,y,65535));
  5465.       case XYTAPI_BNG:
  5466.         y = cmnum("seconds to wait for credit card tone",
  5467.                   "8",10,&x,xxstring);
  5468.         return(setnum(&tapibong,x,y,90));
  5469.       case XYTAPI_MAN:
  5470.         return (success = seton(&tapimanual));
  5471.       case XYTAPI_CON:                  /* TAPI CONVERSIONS */
  5472.         return (success = setonaut(&tapiconv));
  5473.       case XYTAPI_LIN:                  /* TAPI LINE */
  5474.         x = setlin(XYTAPI_LIN,1,0);
  5475.         if (x > -1) didsetlin++;
  5476.         return(x);
  5477.       case XYTAPI_PASS: {               /* TAPI PASSTHROUGH */
  5478.         /* Passthrough became Modem-dialing which is an antonym */
  5479.         success = seton(&tapipass);
  5480.         tapipass = !tapipass;
  5481.         return (success);
  5482.       }
  5483.       case XYTAPI_LOC: {                /* TAPI LOCATION */
  5484.           extern char tapiloc[];
  5485.           extern int tapilocid;
  5486.           int i = 0, j = 9999, k = -1;
  5487.  
  5488.           cktapiBuildLocationTable(&tapiloctab, &ntapiloc);
  5489.           if (!tapiloctab || !ntapiloc) {
  5490.               printf("\nNo TAPI Locations are configured for this system\n");
  5491.               return(-9);
  5492.           }
  5493.           if (tapilocid == -1)
  5494.             tapilocid = cktapiGetCurrentLocationID();
  5495.  
  5496.           /* Find the current tapiloc entry */
  5497.           /* and use it as the default. */
  5498.           for (k = 0; k < ntapiloc; k++) {
  5499.               if (tapiloctab[k].kwval == tapilocid)
  5500.                 break;
  5501.           }
  5502.           if (k >= 0 && k < ntapiloc)
  5503.             s = tapiloctab[k].kwd;
  5504.           else
  5505.             s = "";
  5506.  
  5507.           if ((y = cmkey(tapiloctab,ntapiloc, "TAPI location",s,xxstring)) < 0)
  5508.             return(y);
  5509.  
  5510.           if ((x = cmcfm()) < 0)
  5511.             return(x);
  5512. #ifdef IKSD
  5513.           if (inserver) {
  5514.               printf("Sorry, command disabled\r\n");
  5515.               return(success = 0);
  5516.           }
  5517. #endif /* ISKD */
  5518.           cktapiFetchLocationInfoByID( y );
  5519.           CopyTapiLocationInfoToKermitDialCmd();
  5520.         }
  5521.         break;
  5522.     }
  5523.     return(success=1);
  5524. }
  5525. #endif /* CK_TAPI */
  5526.  
  5527. #ifndef NOSHOW
  5528. int                                     /* SHOW MODEM */
  5529. shomodem() {
  5530.     MDMINF * p;
  5531.     int x, n, mdm;
  5532.     char c;
  5533.     long zz;
  5534.  
  5535. #ifdef IKSD
  5536.     if (inserver) {
  5537.         printf("Sorry, command disabled\r\n");
  5538.         return(success = 0);
  5539.     }
  5540. #endif /* IKSD */
  5541.  
  5542.     shmdmlin();
  5543.     printf("\n");
  5544.  
  5545.     mdm = (mdmtyp > 0) ? mdmtyp : mdmsav;
  5546.     p = (mdm > 0) ? modemp[mdm] : NULL;
  5547.  
  5548.     if (p) {
  5549.         printf(" %s\n\n", dialname ? dialname : p->name);
  5550.  
  5551.         printf(" Modem capabilities:    ");
  5552.         zz = dialcapas ? dialcapas : p->capas;
  5553.         if (!zz) {
  5554.             printf(" (none)");
  5555.         } else {
  5556.             if (zz & CKD_AT) printf(" AT");
  5557.             if (zz & CKD_V25) printf(" ITU");
  5558.             if (zz & CKD_SB) printf(" SB");
  5559.             if (zz & CKD_EC) printf(" EC");
  5560.             if (zz & CKD_DC) printf(" DC");
  5561.             if (zz & CKD_HW) printf(" HWFC");
  5562.             if (zz & CKD_SW) printf(" SWFC");
  5563.             if (zz & CKD_KS) printf(" KS");
  5564.             if (zz & CKD_TB) printf(" TB");
  5565.         }
  5566.         printf("\n Modem carrier-watch:    ");
  5567.         if (carrier == CAR_OFF) printf("off\n");
  5568.         else if (carrier == CAR_ON) printf("on\n");
  5569.         else if (carrier == CAR_AUT) printf("auto\n");
  5570.         else printf("unknown\n");
  5571.  
  5572.         printf(" Modem maximum-speed:    ");
  5573.         zz = (dialmax > 0L) ? dialmax : p->max_speed;
  5574.         if (zz > 0)
  5575.           printf("%ld bps\n", zz);
  5576.         else
  5577.           printf("(unknown)\n");
  5578.         printf(" Modem error-correction: %s\n", dialec ? "on" : "off");
  5579.         printf(" Modem compression:      %s\n", dialdc ? "on" : "off");
  5580.         printf(" Modem speed-matching:   %s",   mdmspd ? "on" : "off");
  5581.         printf(" (interface speed %s)\n", mdmspd ? "changes" : "is locked");
  5582.         printf(" Modem flow-control:     ");
  5583.         if (dialfc == FLO_NONE) printf("none\n");
  5584.         else if (dialfc == FLO_XONX) printf("xon/xoff\n");
  5585.         else if (dialfc == FLO_RTSC) printf("rts/cts\n");
  5586.         else if (dialfc == FLO_AUTO) printf("auto\n");
  5587.         printf(" Modem hangup-method:    %s\n",
  5588.                dialmhu ?
  5589.                "modem-command" :
  5590.                "rs232-signal"
  5591.                );
  5592.         printf(" Modem speaker:          %s\n", showoff(mdmspk));
  5593.         printf(" Modem volume:           %s\n",
  5594.                (mdmvol == 2) ? "medium" : ((mdmvol <= 1) ? "low" : "high"));
  5595.         printf(" Modem kermit-spoof:     %s\n", dialksp ? "on" : "off");
  5596.         c = (char) (x = (dialesc ? dialesc : p->esc_char));
  5597.         printf(" Modem escape-character: %d", x);
  5598.         if (isprint(c))
  5599.           printf(" (= \"%c\")",c);
  5600.         printf(
  5601. "\n\nMODEM COMMANDs (* = set automatically by SET MODEM TYPE):\n\n");
  5602.         debug(F110,"show dialini",dialini,0);
  5603.         printf(" %c Init-string:          ", dialini ? ' ' : '*' );
  5604.         shods(dialini ? dialini : p->wake_str);
  5605.         printf(" %c Dial-mode-string:     ", dialmstr ? ' ' : '*' );
  5606.         shods(dialmstr ? dialmstr : p->dmode_str);
  5607.         n = local ? 19 : 20;
  5608.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5609.         printf(" %c Dial-mode-prompt:     ", dialmprmt ? ' ' : '*' );
  5610.         shods(dialmprmt ? dialmprmt : p->dmode_prompt);
  5611.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5612.         printf(" %c Dial-command:         ", dialcmd ? ' ' : '*' );
  5613.         shods(dialcmd ? dialcmd : p->dial_str);
  5614.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5615.         printf(" %c Compression on:       ", dialdcon ? ' ' : '*' );
  5616.         if (!dialdcon)
  5617.           debug(F110,"dialdcon","(null)",0);
  5618.         else
  5619.           debug(F110,"dialdcon",dialdcon,0);
  5620.         shods(dialdcon ? dialdcon : p->dc_on_str);
  5621.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5622.         printf(" %c Compression off:      ", dialdcoff ? ' ' : '*' );
  5623.         shods(dialdcoff ? dialdcoff : p->dc_off_str);
  5624.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5625.         printf(" %c Error-correction on:  ", dialecon ? ' ' : '*' );
  5626.         shods(dialecon ? dialecon : p->ec_on_str);
  5627.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5628.         printf(" %c Error-correction off: ", dialecoff ? ' ' : '*' );
  5629.         shods(dialecoff ? dialecoff : p->ec_off_str);
  5630.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5631.         printf(" %c Autoanswer on:        ", dialaaon ? ' ' : '*' );
  5632.         shods(dialaaon ? dialaaon : p->aa_on_str);
  5633.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5634.         printf(" %c Autoanswer off:       ", dialaaoff ? ' ' : '*' );
  5635.         shods(dialaaoff ? dialaaoff : p->aa_off_str);
  5636.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5637.  
  5638.         printf(" %c Speaker on:           ", dialspon ? ' ' : '*' );
  5639.         shods(dialspon ? dialspon : p->sp_on_str);
  5640.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5641.         printf(" %c Speaker off:          ", dialspoff ? ' ' : '*' );
  5642.         shods(dialspoff ? dialspoff : p->sp_off_str);
  5643.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5644.         printf(" %c Volume low:           ", dialvol1 ? ' ' : '*' );
  5645.         shods(dialvol1 ? dialvol1 : p->vol1_str);
  5646.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5647.         printf(" %c Volume medium:        ", dialvol2 ? ' ' : '*' );
  5648.         shods(dialvol2 ? dialvol2 : p->vol2_str);
  5649.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5650.         printf(" %c Volume high:          ", dialvol3 ? ' ' : '*' );
  5651.         shods(dialvol3 ? dialvol3 : p->vol3_str);
  5652.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5653.  
  5654.         printf(" %c Hangup-command:       ", dialhcmd ? ' ' : '*' );
  5655.         shods(dialhcmd ? dialhcmd : p->hup_str);
  5656.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5657.         printf(" %c Hardware-flow:        ", dialhwfc ? ' ' : '*' );
  5658.         shods(dialhwfc ? dialhwfc : p->hwfc_str);
  5659.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5660.         printf(" %c Software-flow:        ", dialswfc ? ' ' : '*' );
  5661.         shods(dialswfc ? dialswfc : p->swfc_str);
  5662.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5663.         printf(" %c No-flow-control:      ", dialnofc ? ' ' : '*' );
  5664.         shods(dialnofc ? dialnofc : p->nofc_str);
  5665.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5666.         printf(" %c Pulse:                ", dialpulse ? ' ' : '*');
  5667.         shods(dialpulse ? dialpulse : p->pulse);
  5668.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5669.         printf(" %c Tone:                 ", dialtone ? ' ' : '*');
  5670.         shods(dialtone ? dialtone : p->tone);
  5671.  
  5672.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5673.         printf(" %c Ignore-dialtone:      ", dialx3 ? ' ' : '*');
  5674.         shods(dialx3 ? dialx3 : p->ignoredt);
  5675.  
  5676.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5677.         printf(" %c Predial-init:         ", dialini2 ? ' ' : '*');
  5678.         shods(dialini2 ? dialini2 : p->ini2);
  5679.  
  5680.         if (++n > cmd_rows - 4) if (!askmore()) return(0); else n = 0;
  5681.         printf("\n For more info: SHOW DIAL and SHOW COMMUNICATIONS\n");
  5682.  
  5683.     } else if (mdm > 0) {
  5684.         printf("Modem info for \"%s\" not filled in yet\n", gmdmtyp());
  5685.     } else printf(
  5686. " No modem selected, so DIAL and most SET MODEM commands have no effect.\n\
  5687.  Use SET MODEM TYPE to select a modem.\n");
  5688.     return(success = 1);
  5689. }
  5690. #endif /* NOSHOW */
  5691. #endif /* NODIAL */
  5692. #endif /* NOLOCAL */
  5693.  
  5694. #ifndef NOSPL
  5695. #ifdef CK_ANSIC                         /* SET ALARM */
  5696. int
  5697. setalarm(long xx)
  5698. #else
  5699. int
  5700. setalarm(xx) long xx;
  5701. #endif /* CK_ANSIC */
  5702. /* setalarm */ {
  5703. #ifdef COMMENT
  5704.     int yyyy, mm, dd, x;
  5705.     char *s;
  5706.     long zz;
  5707.     char buf[6];
  5708. #endif /* COMMENT */
  5709.     long sec, jd;
  5710.     char xbuf[20], * p;
  5711.  
  5712.     debug(F101,"setalarm xx","",xx);
  5713.     ck_alarm = 0L;                      /* 0 = no alarm (in case of error) */
  5714.     if (xx < 0L) {
  5715.         printf("%ld - illegal value, must be 0 or positive\n", xx);
  5716.         return(-9);
  5717.     }
  5718.     if (xx == 0L) {                     /* CLEAR ALARM */
  5719.         alrm_date[0] = NUL;
  5720.         alrm_time[0] = NUL;
  5721.         return(1);
  5722.     }
  5723. #ifdef COMMENT
  5724.     x = 8;                              /* Get current date */
  5725.     s = alrm_date;
  5726.     if (zzstring("\\v(ndate)",&s,&x) < 0) {
  5727.         printf("Internal date error, sorry.\n");
  5728.         alrm_date[0] = SP;
  5729.         return(-9);
  5730.     }
  5731.     x = 5;                              /* Get current time */
  5732.     s = alrm_time;
  5733.     if (zzstring("\\v(ntime)",&s,&x) < 0) {
  5734.         printf("Internal time error, sorry.\n");
  5735.         alrm_time[0] = SP;
  5736.         return(-9);
  5737.     }
  5738.     sprintf(buf,"%05ld",atol(alrm_time)); /* SAFE (20) */
  5739.     ckstrncpy(alrm_time,buf,8);
  5740.     debug(F110,"SET ALARM date (1)",alrm_date,0);
  5741.     debug(F110,"SET ALARM time (1)",alrm_time,0);
  5742.  
  5743.     if ((zz = atol(alrm_time) + xx) < 0L) {
  5744.         printf("Internal time conversion error, sorry.\n");
  5745.         return(-9);
  5746.     }
  5747.     if (zz >= 86400L) {                 /* Alarm crosses midnight */
  5748.         char d[10];                     /* Local date buffer */
  5749.         int lastday;                    /* Last day of this month */
  5750.  
  5751.         ckstrncpy(d,alrm_date,8);       /* We'll have to change the date */
  5752.  
  5753.         x = (zz / 86400L);              /* How many days after today */
  5754.  
  5755.         dd = atoi((char *)(d+6));       /* Parse yyyymmdd */
  5756.         d[6] = NUL;                     /* into yyyy, mm, dd ... */
  5757.         mm = atoi((char *)(d+4));
  5758.         d[4] = NUL;
  5759.         yyyy = atoi((char *)d);
  5760.  
  5761.         /* How many days in this month */
  5762.  
  5763.         lastday = mdays[mm];
  5764.         if (mm == 2 && yyyy % 4 == 0)   /* Works thru 2099 AD... */
  5765.           lastday++;
  5766.  
  5767.         if (dd + x > lastday) {         /* Dumb loop */
  5768.             int y;
  5769.  
  5770.             x -= (mdays[mm] - dd);      /* Deduct rest of this month's days */
  5771.  
  5772.             /* There's a more elegant way to do this... */
  5773.  
  5774.             while (1) {
  5775.                 mm++;                   /* Next month */
  5776.                 if (mm > 12) {          /* Wrap around */
  5777.                     mm = 1;             /* Jan, next year */
  5778.                     yyyy++;
  5779.                 }
  5780.                 y = mdays[mm];          /* Days in new month */
  5781.                 if (mm == 2 && yyyy % 4 == 0) /* Feb in leap year */
  5782.                   y++;                  /* Works until 2100 AD */
  5783.                 if (x - y < 1)
  5784.                   break;
  5785.                 x -= y;
  5786.             }
  5787.             dd = x;                     /* Day of alarm month */
  5788.         } else dd += x;
  5789.  
  5790.         sprintf(alrm_date,"%04d%02d%02d",yyyy,mm,dd); /* SAFE (24) */
  5791.         zz = zz % 86400L;
  5792.     }
  5793.     sprintf(alrm_time,"%ld",zz);        /* SAFE (24) */
  5794.     debug(F110,"SET ALARM date (2)",alrm_date,0);
  5795.     debug(F110,"SET ALARM time (2)",alrm_time,0);
  5796.     ck_alarm = xx;
  5797. #else
  5798.     /* Jul 1998 */
  5799.     ckstrncpy(xbuf,ckcvtdate("",1),20); /* Get current date and time */
  5800.     p = xbuf;
  5801.     ckstrncpy(alrm_date,xbuf,10);
  5802.     alrm_date[8] = NUL;
  5803.     sec = atol(p+9) * 3600L + atol(p+12) * 60L + atol(p+15);
  5804.     debug(F110,"SET ALARM date (1)",alrm_date,0);
  5805.     debug(F101,"SET ALARM time (1)","",sec);
  5806.     if ((sec += xx) < 0L) {
  5807.         printf("Internal time conversion error, sorry.\n");
  5808.         return(-9);
  5809.     }
  5810.     if (sec >= 86400L) {                /* Alarm crosses midnight */
  5811.         long days;
  5812.         days = sec / 86400L;
  5813.         jd = mjd(p) + days;             /* Get modified Julian date */
  5814.         ckstrncpy(alrm_date,mjd2date(jd),10);
  5815.         sec %= 86400L;
  5816.     }
  5817.     sprintf(alrm_time,"%05ld",sec);     /* SAFE (24) */
  5818.     debug(F110,"SET ALARM date (2)",alrm_date,0);
  5819.     debug(F110,"SET ALARM time (2)",alrm_time,0);
  5820.     ck_alarm = 1;                       /* Alarm is set */
  5821.  
  5822. #endif /* COMMENT */
  5823.     return(success = 1);
  5824. }
  5825. #endif /* NOSPL */
  5826.  
  5827. #ifndef NOSETKEY
  5828. int
  5829. dosetkey() {                            /* SET KEY */
  5830.     int x, y;
  5831.     int flag = 0;
  5832.     int kc;                             /* Key code */
  5833.     char *s;                            /* Key binding */
  5834. #ifndef NOKVERBS
  5835.     char *p;                            /* Worker */
  5836. #endif /* NOKVERBS */
  5837. #ifdef OS2
  5838.     extern int os2gks;
  5839.     extern int mskkeys;
  5840.     extern int initvik;
  5841. #endif /* OS2 */
  5842.  
  5843.     x_ifnum = 1;
  5844.     y = cmnum("numeric key code, or the word CLEAR,","",10,&kc,xxstring);
  5845.     x_ifnum = 0;
  5846.     if (y < 0) {
  5847.         debug(F111,"SET KEY",atmbuf,y);
  5848.         if (y == -2) {                  /* Not a valid number */
  5849.             if ((y = strlen(atmbuf)) < 0) /* Check for SET KEY CLEAR */
  5850.               return(-2);
  5851.             if (ckstrcmp(atmbuf,"clear",y,0))
  5852.               return(-2);
  5853.             if ((x = cmcfm()) < 0)
  5854.               return(x);
  5855.             for (y = 0; y < KMSIZE; y++) {
  5856.                 keymap[y] = (KEY) y;
  5857.                 macrotab[y] = NULL;
  5858.             }
  5859. #ifdef OS2
  5860.             keymapinit();               /* Special OS/2 initializations */
  5861.             initvik = 1;                /* Update the VIK table */
  5862. #endif /* OS2 */
  5863.             return(1);
  5864.         } else if (y == -3) {           /* SET KEY <Return> */
  5865.             printf(" Press key to be defined: "); /* Prompt for a keystroke */
  5866. #ifdef UNIX
  5867. #ifdef NOSETBUF
  5868.             fflush(stdout);
  5869. #endif /* NOSETBUF */
  5870. #endif /* UNIX */
  5871.             conbin((char)escape);       /* Put terminal in binary mode */
  5872. #ifdef OS2
  5873.             os2gks = 0;                 /* Turn off Kverb preprocessing */
  5874. #endif /* OS2 */
  5875.             kc = congks(0);             /* Get character or scan code */
  5876. #ifdef OS2
  5877.             os2gks = 1;                 /* Turn on Kverb preprocessing */
  5878. #endif /* OS2 */
  5879.             concb((char)escape);        /* Restore terminal to cbreak mode */
  5880.             if (kc < 0) {               /* Check for error */
  5881.                 printf("?Error reading key\n");
  5882.                 return(0);
  5883.             }
  5884. #ifdef OS2
  5885.             shokeycode(kc,-1);          /* Show current definition */
  5886. #else
  5887.             shokeycode(kc);             /* Show current definition */
  5888. #endif /* OS2 */
  5889.             flag = 1;                   /* Remember it's a multiline command */
  5890.         } else                          /* Error */
  5891.           return(y);
  5892.     }
  5893.  
  5894.     /* Normal SET KEY <scancode> <value> command... */
  5895.  
  5896. #ifdef OS2
  5897.     if (mskkeys)
  5898.       kc = msktock(kc);
  5899. #endif /* OS2 */
  5900.  
  5901.     if (kc < 0 || kc >= KMSIZE) {
  5902.         printf("?key code must be between 0 and %d\n", KMSIZE - 1);
  5903.         return(-9);
  5904.     }
  5905.     if (kc == escape) {
  5906.         printf("Sorry, %d is the CONNECT-mode escape character\n",kc);
  5907.         return(-9);
  5908.     }
  5909. #ifdef OS2
  5910.     wideresult = -1;
  5911. #endif /* OS2 */
  5912.     if (flag) {
  5913.         cmsavp(psave,PROMPTL);
  5914.         cmsetp(" Enter new definition: ");
  5915.         cmini(ckxech);
  5916.         cmflgs = 0;
  5917.         prompt(NULL);
  5918.     }
  5919.   def_again:
  5920.     if (flag)
  5921.       cmres();
  5922.     if ((y = cmtxt("key definition,\n\
  5923. or Ctrl-C to cancel this command,\n\
  5924. or Enter to restore default definition",
  5925.                    "",&s,NULL)) < 0) {
  5926.         if (flag)                       /* Handle parse errors */
  5927.           goto def_again;
  5928.         else
  5929.           return(y);
  5930.     }
  5931.     s = brstrip(s);
  5932. #ifndef NOKVERBS
  5933.     p = s;                              /* Save this place */
  5934. #endif /* NOKVERBS */
  5935. /*
  5936.   If the definition included any \Kverbs, quote the backslash so the \Kverb
  5937.   will still be in the definition when the key is pressed.  We don't do this
  5938.   in zzstring(), because \Kverbs are valid only in this context and nowhere
  5939.   else.
  5940.  
  5941.   We use this code active for all versions that support SET KEY, even if they
  5942.   don't support \Kverbs, because otherwise \K would behave differently for
  5943.   different versions.
  5944. */
  5945.     for (x = 0, y = 0; s[x]; x++, y++) { /* Convert \K to \\K */
  5946.         if ((x > 0) &&
  5947.             (s[x] == 'K' || s[x] == 'k')
  5948.             ) {                         /* Have K */
  5949.  
  5950.             if ((x == 1 && s[x-1] == CMDQ) ||
  5951.                 (x > 1 && s[x-1] == CMDQ && s[x-2] != CMDQ)) {
  5952.                 line[y++] = CMDQ;       /* Make it \\K */
  5953.             }
  5954.             if (x > 1 && s[x-1] == '{' && s[x-2] == CMDQ) {
  5955.                 line[y-1] = CMDQ;       /* Have \{K */
  5956.                 line[y++] = '{';        /* Make it \\{K */
  5957.             }
  5958.         }
  5959.         line[y] = s[x];
  5960.     }
  5961.     line[y++] = NUL;                    /* Terminate */
  5962.     s = line + y + 1;                   /* Point to after it */
  5963.     x = LINBUFSIZ - (int) strlen(line) - 1; /* Calculate remaining space */
  5964.     if ((x < (LINBUFSIZ / 2)) ||
  5965.         (zzstring(line, &s, &x) < 0)) { /* Expand variables, etc. */
  5966.         printf("?Key definition too long\n");
  5967.         if (flag) cmsetp(psave);
  5968.         return(-9);
  5969.     }
  5970.     s = line + y + 1;                   /* Point to result. */
  5971.  
  5972. #ifndef NOKVERBS
  5973. /*
  5974.   Special case: see if the definition starts with a \Kverb.
  5975.   If it does, point to it with p, otherwise set p to NULL.
  5976. */
  5977.     p = s;
  5978.     if (*p++ == CMDQ) {
  5979.         if (*p == '{') p++;
  5980.         p = (*p == 'k' || *p == 'K') ? p + 1 : NULL;
  5981.     }
  5982. #endif /* NOKVERBS */
  5983.  
  5984.     if (macrotab[kc]) {                 /* Possibly free old macro from key. */
  5985.         free((char *)macrotab[kc]);
  5986.         macrotab[kc] = NULL;
  5987.     }
  5988.     switch (strlen(s)) {                /* Action depends on length */
  5989.       case 0:                           /* Reset to default binding */
  5990.         keymap[kc] = (KEY) kc;
  5991.         break;
  5992.       case 1:                           /* Single character */
  5993.         keymap[kc] = (CHAR) *s;
  5994.         break;
  5995.       default:                          /* Character string */
  5996. #ifndef NOKVERBS
  5997.         if (p) {
  5998.             y = xlookup(kverbs,p,nkverbs,&x); /* Look it up */
  5999.             debug(F101,"set key kverb lookup",0,y); /* exact match required */
  6000.             if (y > -1) {
  6001.                 keymap[kc] = F_KVERB | y;
  6002.                 break;
  6003.             }
  6004.         }
  6005. #endif /* NOKVERBS */
  6006.         keymap[kc] = (KEY) kc;
  6007.         macrotab[kc] = (MACRO) malloc(strlen(s)+1);
  6008.         if (macrotab[kc])
  6009.           strcpy((char *) macrotab[kc], s); /* safe */
  6010.         break;
  6011.     }
  6012.     if (flag) cmsetp(psave);
  6013. #ifdef OS2
  6014.     initvik = 1;                        /* Update VIK table */
  6015. #endif /* OS2 */
  6016.     return(1);
  6017. }
  6018. #endif /* NOSETKEY */
  6019.  
  6020. #ifdef STOPBITS
  6021. struct keytab stoptbl[] = {
  6022.     { "1", 1, 0 },
  6023.     { "2", 2, 0 }
  6024. };
  6025. #endif /* STOPBITS */
  6026.  
  6027. static struct keytab sertbl[] = {
  6028.     { "7E1", 0, 0 },
  6029.     { "7E2", 1, 0 },
  6030.     { "7M1", 2, 0 },
  6031.     { "7M2", 3, 0 },
  6032.     { "7O1", 4, 0 },
  6033.     { "7O2", 5, 0 },
  6034.     { "7S1", 6, 0 },
  6035.     { "7S2", 7, 0 },
  6036. #ifdef HWPARITY
  6037.     { "8E1", 9, 0 },
  6038.     { "8E2", 10, 0 },
  6039. #endif /* HWPARITY */
  6040.     { "8N1", 8, 0 },
  6041. #ifdef HWPARITY
  6042.     { "8N2", 11, 0 },
  6043.     { "8O1", 12, 0 },
  6044.     { "8O2", 13, 0 },
  6045. #endif /* HWPARITY */
  6046.     { "", 0, 0 }
  6047. };
  6048. static int nsertbl = (sizeof(sertbl) / sizeof(struct keytab)) - 1;
  6049.  
  6050. static char * sernam[] = {              /* Keep this in sync with sertbl[] */
  6051.   "7E1", "7E2", "7M1", "7M2", "7O1", "7O2", "7S1", "7S2",
  6052.   "8N1", "8E1", "8E2", "8N2", "8O1", "8O2"
  6053. };
  6054.  
  6055. static struct keytab optstab[] = {      /* SET OPTIONS table */
  6056. #ifndef NOFRILLS
  6057.     { "delete",    XXDEL,   0},            /* DELETE */
  6058. #endif /* NOFRILLS */
  6059.     { "directory", XXDIR,   0},         /* DIRECTORY */
  6060. #ifdef CKPURGE
  6061.     { "purge",     XXPURGE, 0},         /* PURGE */
  6062. #endif /* CKPURGE */
  6063.     { "type",      XXTYP,   0},         /* TYPE */
  6064.     { "", 0, 0}
  6065. };
  6066. static int noptstab =  (sizeof(optstab) / sizeof(struct keytab)) - 1;
  6067.  
  6068. #ifndef NOXFER
  6069. /*
  6070.   PROTOCOL SELECTION.  Kermit is always available.  If CK_XYZ is defined at
  6071.   compile time, then the others become selections also.  In OS/2 and
  6072.   Windows, they are integrated and the various SET commands (e.g. "set file
  6073.   type") affect them as they would Kermit.  In other OS's (UNIX, VMS, etc),
  6074.   they are external protocols which are run via Kermit's REDIRECT mechanism.
  6075.   All we do is collect and verify the filenames and pass them along to the
  6076.   external protocol.
  6077. */
  6078. struct keytab protos[] = {
  6079. #ifdef CK_XYZ
  6080.     "g",          PROTO_G,  CM_INV,
  6081. #endif /* CK_XYZ */
  6082.     "kermit",     PROTO_K,  0,
  6083. #ifdef CK_XYZ
  6084.     "other",      PROTO_O,  0,
  6085.     "x",          PROTO_X,  CM_INV|CM_ABR,
  6086.     "xmodem",     PROTO_X,  0,
  6087.     "xmodem-crc", PROTO_XC, 0,
  6088.     "y",          PROTO_Y,  CM_INV|CM_ABR,
  6089.     "ymodem",     PROTO_Y,  0,
  6090.     "ymodem-g",   PROTO_G,  0,
  6091.     "zmodem",     PROTO_Z,  0
  6092. #endif /* CK_XYZ */
  6093. };
  6094. int nprotos =  (sizeof(protos) / sizeof(struct keytab));
  6095.  
  6096. #define XPCMDLEN 71
  6097.  
  6098. _PROTOTYP(static int protofield, (char *, char *, char *));
  6099. _PROTOTYP(static int setproto, (void));
  6100.  
  6101. static int
  6102. protofield(current, help, px) char * current, * help, * px; {
  6103.  
  6104.     char *s, tmpbuf[XPCMDLEN+1];
  6105.     int x;
  6106.  
  6107.     if (current)                        /* Put braces around default */
  6108.       ckmakmsg(tmpbuf,TMPBUFSIZ,"{",current,"}",NULL);
  6109.     else
  6110.       tmpbuf[0] = NUL;
  6111.  
  6112.     if ((x = cmfld(help, (char *)tmpbuf, &s, xxstring)) < 0)
  6113.       return(x);
  6114.     if ((int)strlen(s) > XPCMDLEN) {
  6115.         printf("?Sorry - maximum length is %d\n", XPCMDLEN);
  6116.         return(-9);
  6117.     } else if (*s) {
  6118.         strcpy(px,s);                   /* safe */
  6119.     } else {
  6120.         px = NULL;
  6121.     }
  6122.     return(x);
  6123. }
  6124.  
  6125. static int
  6126. setproto() {                            /* Select a file transfer protocol */
  6127.     /* char * s = NULL; */
  6128.     int x = 0, y;
  6129.     char s1[XPCMDLEN+1], s2[XPCMDLEN+1], s3[XPCMDLEN+1];
  6130.     char s4[XPCMDLEN+1], s5[XPCMDLEN+1], s6[XPCMDLEN+1], s7[XPCMDLEN+1];
  6131.     char * p1 = s1, * p2 = s2, *p3 = s3;
  6132.     char * p4 = s4, * p5 = s5, *p6 = s6, *p7 = s7;
  6133.  
  6134. #ifdef XYZ_INTERNAL
  6135.     extern int p_avail;
  6136. #else
  6137. #ifndef CK_REDIR
  6138.     x = 1;
  6139. #endif /* CK_REDIR */
  6140. #endif /* XYZ_INTERNAL */
  6141.     s1[0] = NUL;
  6142.     s2[0] = NUL;
  6143.     s3[0] = NUL;
  6144.     s4[0] = NUL;
  6145.     s5[0] = NUL;
  6146.     s6[0] = NUL;
  6147.  
  6148.     if ((y = cmkey(protos,nprotos,"","kermit",xxstring)) < 0)
  6149.       return(y);
  6150.  
  6151.     if (x && y != PROTO_K) {
  6152.         printf(
  6153.            "?Sorry, REDIRECT capability required for external protocols.\n");
  6154.         return(-9);
  6155.     }
  6156.     if ((x = protofield(ptab[y].h_b_init,
  6157.      "Optional command to send to host prior to uploading in binary mode",
  6158.                p1)) < 0) {
  6159.         if (x == -3) {
  6160.             protocol = y;               /* Set protocol but don't change */
  6161.             return(1);                  /* anything else */
  6162.         } else
  6163.           return(x);
  6164.     }
  6165.     if ((x = protofield(ptab[y].h_t_init,
  6166.      "Optional command to send to host prior to uploading in text mode",
  6167.                p2)) < 0) {
  6168.         if (x == -3)
  6169.           goto protoexit;
  6170.         else
  6171.           return(x);
  6172.     }
  6173.  
  6174.     if (y == PROTO_K) {
  6175.         if ((x = protofield(ptab[y].h_x_init,
  6176.                     "Optional command to send to host to start Kermit server",
  6177.                             p3)) < 0) {
  6178.             if (x == -3)
  6179.               goto protoexit;
  6180.             else
  6181.               return(x);
  6182.         }
  6183.     }
  6184.  
  6185.  
  6186. #ifndef XYZ_INTERNAL                    /* If XYZMODEM are external... */
  6187.  
  6188.     if (y != PROTO_K) {
  6189.         if ((x = protofield(ptab[y].p_b_scmd,
  6190.                  "External command to SEND in BINARY mode with this protocol",
  6191.                             p4)) < 0) {
  6192.             if (x == -3)
  6193.               goto protoexit;
  6194.             else
  6195.               return(x);
  6196.         }
  6197.         if ((x = protofield(ptab[y].p_t_scmd,
  6198.                  "External command to SEND in TEXT mode with this protocol",
  6199.                             p5)) < 0) {
  6200.             if (x == -3)
  6201.               goto protoexit;
  6202.             else
  6203.               return(x);
  6204.         }
  6205.         if ((x = protofield(ptab[y].p_b_rcmd,
  6206.                "External command to RECEIVE in BINARY mode with this protocol",
  6207.                             p6)) < 0) {
  6208.             if (x == -3)
  6209.               goto protoexit;
  6210.             else
  6211.               return(x);
  6212.         }
  6213.         if ((x = protofield(ptab[y].p_t_rcmd,
  6214.                  "External command to RECEIVE in TEXT mode with this protocol",
  6215.                             p7)) < 0) {
  6216.             if (x == -3)
  6217.               goto protoexit;
  6218.             else
  6219.               return(x);
  6220.         }
  6221.     }
  6222. #endif /* XYZ_INTERNAL */
  6223.  
  6224.     if ((x = cmcfm()) < 0)              /* Confirm the command */
  6225.       return(x);
  6226.  
  6227. protoexit:                              /* Common exit from this routine */
  6228.  
  6229. #ifdef XYZ_INTERNAL
  6230.     if (!p_avail) {
  6231.         bleep(BP_WARN);
  6232.         printf("\n?X,Y, and Zmodem are unavailable\n");
  6233.         return(success = 0);
  6234.     }
  6235. #endif /* XYZ_INTERNAL */
  6236.  
  6237.     p1 = brstrip(p1);
  6238.     p2 = brstrip(p2);
  6239.     p3 = brstrip(p3);
  6240.     p4 = brstrip(p4);
  6241.     p5 = brstrip(p5);
  6242.     p6 = brstrip(p6);
  6243.     p7 = brstrip(p7);
  6244.     initproto(y,p1,p2,p3,p4,p5,p6,p7);
  6245.     return(success = 1);
  6246. }
  6247.  
  6248. int
  6249. setdest() {
  6250.     int x, y;
  6251.     if ((y = cmkey(desttab,ndests,"","disk",xxstring)) < 0) return(y);
  6252.     if ((x = cmcfm()) < 0) return(x);
  6253.     dest = y;
  6254.     return(1);
  6255. }
  6256. #endif /* NOXFER */
  6257.  
  6258. #ifdef DECNET
  6259. struct keytab dnettab[] = {
  6260. #ifndef OS2ONLY
  6261.     "cterm", NP_CTERM, 0,
  6262. #endif /* OS2ONLY */
  6263.     "lat",   NP_LAT,   0
  6264. };
  6265. int ndnet =  (sizeof(dnettab) / sizeof(struct keytab));
  6266. #endif /* DECNET */
  6267.  
  6268. /*  S E T P R I N T E R  --  SET PRINTER command  */
  6269.  
  6270. #ifdef PRINTSWI
  6271. static struct keytab prntab[] = {       /* SET PRINTER switches */
  6272.     "/bidirectional",    PRN_BID, 0,
  6273.     "/command",          PRN_PIP, CM_ARG,
  6274.     "/dos-device",       PRN_DOS, CM_ARG,
  6275.     "/end-of-job-string",PRN_TRM, CM_ARG,
  6276.     "/file",             PRN_FIL, CM_ARG,
  6277. #ifdef BPRINT
  6278.     "/flow-control",     PRN_FLO, CM_ARG,
  6279. #endif /* BPRINT */
  6280.     "/job-header-file",  PRN_SEP, CM_ARG,
  6281. #ifdef OS2
  6282.     "/length",           PRN_LEN, CM_ARG,
  6283. #endif /* OS2 */
  6284.     "/none",             PRN_NON, 0,
  6285. #ifdef OS2
  6286.     "/nopostscript",     PRN_RAW, 0,
  6287.     "/nops",             PRN_RAW, CM_INV,
  6288. #endif /* OS2 */
  6289.     "/output-only",      PRN_OUT, 0,
  6290. #ifdef BPRINT
  6291.     "/parity",           PRN_PAR, CM_ARG,
  6292. #endif /* BPRINT */
  6293.     "/pipe",             PRN_PIP, CM_ARG|CM_INV,
  6294. #ifdef OS2
  6295.     "/postscript",       PRN_PS,  0,
  6296.     "/ps",               PRN_PS,  CM_INV,
  6297. #endif /* OS2 */
  6298.     "/separator",        PRN_SEP, CM_ARG|CM_INV,
  6299. #ifdef BPRINT
  6300.     "/speed",            PRN_SPD, CM_ARG,
  6301. #endif /* BPRINT */
  6302.     "/timeout",          PRN_TMO, CM_ARG,
  6303.     "/terminator",       PRN_TRM, CM_ARG|CM_INV,
  6304. #ifdef OS2
  6305. #ifdef NT
  6306.     "/w",                PRN_WIN, CM_ARG|CM_ABR|CM_INV,
  6307.     "/wi",               PRN_WIN, CM_ARG|CM_ABR|CM_INV,
  6308. #endif /* NT */
  6309.     "/width",            PRN_WID, CM_ARG,
  6310. #endif /* OS2 */
  6311. #ifdef NT
  6312.     "/windows-queue",    PRN_WIN, CM_ARG,
  6313. #endif /* NT */
  6314.     "",                 0,      0
  6315. };
  6316. int nprnswi =  (sizeof(prntab) / sizeof(struct keytab)) - 1;
  6317. #endif /* PRINTSWI */
  6318.  
  6319. static int
  6320. setprinter(xx) int xx; {
  6321.     int x, y;
  6322.     char * s;
  6323.     char * defname = NULL;
  6324.  
  6325. #ifdef BPRINT
  6326.     char portbuf[64];
  6327.     long portspeed = 0L;
  6328.     int portparity = 0;
  6329.     int portflow = 0;
  6330. #endif /* BPRINT */
  6331.  
  6332. #ifdef PRINTSWI
  6333.     int c, i, n, wild, confirmed = 0;   /* Workers */
  6334.     int getval = 0;                     /* Whether to get switch value */
  6335.     struct stringint {                  /* Temporary array for switch values */
  6336.         char * sval;
  6337.         int ival;
  6338.     } pv[PRN_MAX+1];
  6339.     struct FDB sw, of, cm;              /* FDBs for each parse function */
  6340.     int haveque = 0;
  6341.     int typeset = 0;
  6342. #endif /* PRINTSWI */
  6343.  
  6344. #ifdef NT
  6345.     struct keytab * printtab = NULL, * _printtab = NULL;
  6346.     int nprint = 0, printdef=0;
  6347. #endif /* NT */
  6348.  
  6349. #ifdef OS2
  6350.     defname = "PRN";                    /* default */
  6351. #else
  6352. #ifdef VMS
  6353.     defname = "LPT:";
  6354. #else
  6355. #ifdef UNIX
  6356.     defname = "|lpr";
  6357. #endif /* UNIX */
  6358. #endif /* VMS */
  6359. #endif /* OS2 */
  6360.  
  6361. #ifdef PRINTSWI
  6362. #ifdef NT
  6363.     haveque = Win32EnumPrt(&printtab,&_printtab,&nprint,&printdef);
  6364.     haveque = haveque && nprint;
  6365. #endif /* NT */
  6366.  
  6367.     for (i = 0; i <= PRN_MAX; i++) {    /* Initialize switch values */
  6368.         pv[i].sval = NULL;              /* to null pointers */
  6369.         pv[i].ival = -1;                /* and -1 int values */
  6370.     }
  6371.     if (xx == XYBDCP) {                 /* SET BPRINTER == /BIDIRECTIONAL */
  6372.         pv[PRN_BID].ival = 1;
  6373.         pv[PRN_OUT].ival = 0;
  6374.     }
  6375.  
  6376.     /* Initialize defaults based upon current printer settings */
  6377.     if (printername) {
  6378.         defname = printername;
  6379.         switch (printertype) {
  6380.           case PRT_WIN: pv[PRN_WIN].ival = 1; break;
  6381.           case PRT_DOS: pv[PRN_DOS].ival = 1; break;
  6382.           case PRT_PIP: pv[PRN_PIP].ival = 1; break;
  6383.           case PRT_FIL: pv[PRN_FIL].ival = 1; break;
  6384.           case PRT_NON: pv[PRN_NON].ival = 1; break;
  6385.         }
  6386.     }
  6387. #ifdef BPRINT
  6388.     /* only set the BIDI flag if we are bidi */
  6389.     if (printbidi)
  6390.         pv[PRN_BID].ival = 1;
  6391.  
  6392.     /* serial port parameters may be set for non-bidi devices */
  6393.     pv[PRN_SPD].ival = pportspeed / 10L;
  6394.     pv[PRN_PAR].ival = pportparity;
  6395.     pv[PRN_FLO].ival = pportflow;
  6396. #endif /* BPRINT */
  6397.     if (printtimo)
  6398.         pv[PRN_TMO].ival = printtimo;
  6399.     if (printterm) {
  6400.         pv[PRN_TRM].ival = 1;
  6401.         makestr(&pv[PRN_TRM].sval,printterm);
  6402.     }
  6403.     if (printsep) {
  6404.         pv[PRN_SEP].ival = 1;
  6405.         makestr(&pv[PRN_SEP].sval,printsep);
  6406.     }
  6407.     if (txt2ps) {
  6408.         pv[PRN_PS].ival = 1;
  6409.         pv[PRN_WID].ival = ps_width;
  6410.         pv[PRN_LEN].ival = ps_length;
  6411.     } else {
  6412.         pv[PRN_RAW].ival = 1;
  6413.     }
  6414.  
  6415.     /* Set up chained parse functions... */
  6416.  
  6417.     cmfdbi(&sw,                         /* First FDB - command switches */
  6418.            _CMKEY,                      /* fcode */
  6419.            "Switch",                    /* hlpmsg */
  6420.            "",                          /* default */
  6421.            "",                          /* addtl string data */
  6422.            nprnswi,                     /* addtl numeric data 1: tbl size */
  6423.            4,                           /* addtl numeric data 2: 4 = cmswi */
  6424.            xxstring,                    /* Processing function */
  6425.            prntab,                      /* Keyword table */
  6426.            &cm                          /* Pointer to next FDB */
  6427.            );
  6428.     cmfdbi(&cm,                         /* Second fdb for confirmation */
  6429.            _CMCFM,                      /* fcode */
  6430.            "",                          /* hlpmsg */
  6431.            "",                          /* default */
  6432.            "",                          /* addtl string data */
  6433.            0,                           /* addtl numeric data 1 */
  6434.            0,                           /* addtl numeric data 2 */
  6435.            NULL,
  6436.            NULL,
  6437.            &of
  6438.            );
  6439.     cmfdbi(&of,                         /* Third FDB for printer name */
  6440.            _CMOFI,                      /* fcode */
  6441.            "Printer or file name",      /* hlpmsg */
  6442.            defname,                     /* default */
  6443.            "",                          /* addtl string data */
  6444.            0,                           /* addtl numeric data 1: tbl size */
  6445.            0,                           /* addtl numeric data 2: 4 = cmswi */
  6446.            xxstring,                    /* Processing function */
  6447.            NULL,                        /* Nothing */
  6448.            NULL
  6449.            );
  6450.  
  6451.     while (1) {                         /* Parse 0 or more switches */
  6452.         x = cmfdb(&sw);                 /* Parse switch or other thing */
  6453.         debug(F101,"setprinter cmfdb","",x);
  6454.         if (x < 0)                      /* Error */
  6455.           goto xsetprn;                 /* or reparse needed */
  6456.         if (cmresult.fcode != _CMKEY)   /* Break out if not a switch */
  6457.           break;
  6458.         if (cmresult.fdbaddr != &sw)    /* Advanced usage :-) */
  6459.           break;
  6460.         c = cmgbrk();                   /* Get break character */
  6461.         getval = (c == ':' || c == '='); /* to see how they ended the switch */
  6462.         n = cmresult.nresult;           /* Numeric result = switch value */
  6463.         debug(F101,"setprinter switch","",n);
  6464.  
  6465.         switch (n) {                    /* Process the switch */
  6466.           case PRN_PS:                  /* Text to Postscript */
  6467.             pv[PRN_PS].ival = 1;
  6468.             pv[PRN_BID].ival = 0;
  6469.             pv[PRN_OUT].ival = 1;
  6470.             pv[PRN_RAW].ival = 0;
  6471.             break;
  6472.  
  6473.           case PRN_RAW:                 /* Non-Postscript */
  6474.             pv[PRN_PS].ival = 0;
  6475.             pv[PRN_RAW].ival = 1;
  6476.             break;
  6477.  
  6478.           case PRN_BID:                 /* Bidirectional */
  6479.             pv[PRN_BID].ival = 1;
  6480.             pv[PRN_OUT].ival = 0;
  6481.             pv[PRN_PS].ival = 0;
  6482.             pv[PRN_RAW].ival = 1;
  6483.             break;
  6484.  
  6485.           case PRN_OUT:                 /* Output-only */
  6486.             pv[PRN_OUT].ival = 1;
  6487.             pv[PRN_BID].ival = 0;
  6488.             pv[PRN_PS].ival = 0;
  6489.             pv[PRN_RAW].ival = 1;
  6490.             break;
  6491.  
  6492.           case PRN_NON:                 /* NONE */
  6493.             typeset++;
  6494.             pv[n].ival = 1;
  6495.             pv[PRN_SPD].ival = 0;
  6496.             pv[PRN_PAR].ival = 0;
  6497.             pv[PRN_FLO].ival = FLO_KEEP;
  6498.             break;
  6499.  
  6500. #ifdef UNIX
  6501.           case PRN_WIN:
  6502. #endif /* UNIX */
  6503.           case PRN_DOS:                 /* DOS printer name */
  6504.           case PRN_FIL:                 /* Or filename */
  6505.           case PRN_PIP:
  6506.             typeset++;
  6507.             if (pv[n].sval) free(pv[n].sval);
  6508.             pv[n].sval = NULL;
  6509.             pv[PRN_NON].ival = 0;       /* Zero any previous selections */
  6510.             pv[PRN_WIN].ival = 0;
  6511.             pv[PRN_DOS].ival = 0;
  6512.             pv[PRN_FIL].ival = 0;
  6513.             pv[PRN_PIP].ival = 0;
  6514.             pv[n].ival = 1;             /* Flag this one */
  6515.             if (!getval) break;         /* No value wanted */
  6516.  
  6517.             if (n == PRN_FIL) {         /* File, check accessibility */
  6518.                 int wild = 0;
  6519.                 if ((x = cmiofi("Filename","kermit.prn",&s,&wild,xxstring))< 0)
  6520.                   if (x == -9) {
  6521.                       if (zchko(s) < 0) {
  6522.                           printf("Can't create \"%s\"\n",s);
  6523.                           return(x);
  6524.                       }
  6525.                   } else goto xsetprn;
  6526.                 if (iswild(s)) {
  6527.                     printf("?A single file please\n");
  6528.                     return(-9);
  6529.                 }
  6530.                 pv[PRN_SPD].ival = 0;
  6531.                 pv[PRN_PAR].ival = 0;
  6532.                 pv[PRN_FLO].ival = FLO_KEEP;
  6533.             } else if ((x = cmfld(n == PRN_DOS ? /* Value wanted - parse it */
  6534.                            "DOS printer device name" : /* Help message */
  6535.                            (n == PRN_PIP ?
  6536.                            "Program name" :
  6537.                            "Filename"),
  6538.                            n == PRN_DOS ?
  6539.                            "PRN" :      /* Default */
  6540.                            "",
  6541.                            &s,
  6542.                            xxstring
  6543.                            )) < 0)
  6544.               goto xsetprn;
  6545.             s = brstrip(s);             /* Strip enclosing braces */
  6546.             while (*s == SP)            /* Strip leading blanks */
  6547.               s++;
  6548.             if (n == PRN_PIP) {         /* If /PIPE: */
  6549.                 if (*s == '|') {        /* strip any extraneous pipe sign */
  6550.                     s++;
  6551.                     while (*s == SP)
  6552.                       s++;
  6553.                 }
  6554.                 pv[PRN_SPD].ival = 0;
  6555.                 pv[PRN_PAR].ival = 0;
  6556.                 pv[PRN_FLO].ival = FLO_KEEP;
  6557.             }
  6558.             if ((y = strlen(s)) > 0)    /* Anything left? */
  6559.               if (pv[n].sval = (char *) malloc(y+1)) /* Yes, keep it */
  6560.                 strcpy(pv[n].sval,s);   /* safe */
  6561.             break;
  6562. #ifdef NT
  6563.           case PRN_WIN:                 /* Windows queue name */
  6564.             typeset++;
  6565.             if (pv[n].sval) free(pv[n].sval);
  6566.             pv[n].sval = NULL;
  6567.             pv[PRN_NON].ival = 0;
  6568.             pv[PRN_DOS].ival = 0;
  6569.             pv[PRN_FIL].ival = 0;
  6570.             pv[n].ival = 1;
  6571.             pv[PRN_SPD].ival = 0;
  6572.             pv[PRN_PAR].ival = 0;
  6573.             pv[PRN_FLO].ival = FLO_KEEP;
  6574.  
  6575.             if (!getval || !haveque)
  6576.               break;
  6577.             if ((x = cmkey(_printtab,nprint,"Print queue name",
  6578.                            _printtab[printdef].kwd,xxstring)) < 0) {
  6579.                 if (x != -2)
  6580.                   goto xsetprn;
  6581.  
  6582.                 if (pv[PRN_WIN].sval) free(pv[PRN_WIN].sval);
  6583.                 s = atmbuf;
  6584.                 if ((y = strlen(s)) > 0)
  6585.                   if (pv[n].sval = (char *)malloc(y+1))
  6586.                     strcpy(pv[n].sval,s); /* safe */
  6587.             } else {
  6588.                 if (pv[PRN_WIN].sval) free(pv[PRN_WIN].sval);
  6589.                 for (i = 0; i < nprint; i++) {
  6590.                     if (x == printtab[i].kwval) {
  6591.                         s = printtab[i].kwd;
  6592.                         break;
  6593.                     }
  6594.                 }
  6595.                 if ((y = strlen(s)) > 0)
  6596.                   if (pv[n].sval = (char *)malloc(y+1))
  6597.                     strcpy(pv[n].sval,s); /* safe */
  6598.             }
  6599.             break;
  6600. #endif /* NT */
  6601.  
  6602.           case PRN_SEP:                 /* /JOB-HEADER (separator) */
  6603.             if (pv[n].sval) free(pv[n].sval);
  6604.             pv[n].sval = NULL;
  6605.             pv[n].ival = 1;
  6606.             if (!getval) break;
  6607.             if ((x = cmifi("Filename","",&s,&y,xxstring)) < 0)
  6608.               goto xsetprn;
  6609.             if (y) {
  6610.                 printf("?Wildcards not allowed\n");
  6611.                 x = -9;
  6612.                 goto xsetprn;
  6613.             }
  6614.             if ((y = strlen(s)) > 0)
  6615.               if (pv[n].sval = (char *) malloc(y+1))
  6616.                 strcpy(pv[n].sval,s);   /* safe */
  6617.             break;
  6618.  
  6619.           case PRN_TMO:                 /* /TIMEOUT:number */
  6620.             pv[n].ival = 0;
  6621.             if (!getval) break;
  6622.             if ((x = cmnum("Seconds","0",10,&y,xxstring)) < 0)
  6623.               goto xsetprn;
  6624.             if (y > 999) {
  6625.                 printf("?Sorry - 999 is the maximum\n");
  6626.                 x = -9;
  6627.                 goto xsetprn;
  6628.             } else
  6629.               pv[n].ival = y;
  6630.             break;
  6631.  
  6632.           case PRN_TRM:                 /* /END-OF-JOB:string */
  6633.             if (pv[n].sval) free(pv[n].sval);
  6634.             pv[n].sval = NULL;
  6635.             pv[n].ival = 1;
  6636.             if (!getval) break;
  6637.             if ((x = cmfld("String (enclose in braces if it contains spaces)",
  6638.                            "",&s,xxstring)) < 0)
  6639.               goto xsetprn;
  6640.             s = brstrip(s);
  6641.             if ((y = strlen(s)) > 0)
  6642.               if (pv[n].sval = (char *) malloc(y+1))
  6643.                 strcpy(pv[n].sval,s);   /* safe */
  6644.             break;
  6645.  
  6646. #ifdef BPRINT
  6647.           case PRN_FLO:
  6648.             if (!getval) break;
  6649.             if ((x = cmkey(flotab,nflo,
  6650.                               "Serial printer-port flow control",
  6651.                               "rts/cts",xxstring)) < 0)
  6652.               goto xsetprn;
  6653.             pv[n].ival = x;
  6654.             break;
  6655.  
  6656. #ifndef NOLOCAL
  6657.           case PRN_SPD:
  6658.             if (!getval) break;
  6659.  
  6660.             /* TN_COMPORT here too? */
  6661.  
  6662.             if ((x = cmkey(spdtab,      /* Speed (no default) */
  6663.                            nspd,
  6664.                            "Serial printer-port interface speed",
  6665.                            "9600",
  6666.                            xxstring)
  6667.                  ) < 0)
  6668.               goto xsetprn;
  6669.             pv[n].ival = x;
  6670.             break;
  6671. #endif /* NOLOCAL */
  6672.  
  6673.           case PRN_PAR:
  6674.             pv[n].ival = 0;
  6675.             if (!getval) break;
  6676.             if ((x = cmkey(partbl,npar,"Serial printer-port parity",
  6677.                            "none",xxstring)) < 0)
  6678.               goto xsetprn;
  6679.             pv[n].ival = x;
  6680.             break;
  6681. #endif /* BPRINT */
  6682.  
  6683. #ifdef OS2
  6684.           case PRN_LEN:
  6685.             if (!getval) break;
  6686.             if ((x = cmnum("PS page length", "66",10,&y,xxstring)) < 0)
  6687.               goto xsetprn;
  6688.             pv[n].ival = y;
  6689.             break;
  6690.  
  6691.           case PRN_WID:
  6692.             if (!getval) break;
  6693.             if ((x = cmnum("PS page width", "80",10,&y,xxstring)) < 0)
  6694.               goto xsetprn;
  6695.             pv[n].ival = y;
  6696.             break;
  6697. #endif /* OS2 */
  6698.  
  6699.           default:
  6700.             printf("?Unexpected switch value - %d\n",cmresult.nresult);
  6701.             x = -9;
  6702.             goto xsetprn;
  6703.         }
  6704.     }
  6705.     line[0] = NUL;                      /* Initialize printer name value */
  6706.     switch (cmresult.fcode) {           /* How did we get here? */
  6707.       case _CMOFI:                      /* They typed a filename */
  6708.         ckstrncpy(line,cmresult.sresult,LINBUFSIZ); /* Name */
  6709.         wild = cmresult.nresult;        /* Wild flag */
  6710.         if (!typeset) {                 /* A printer name without a type */
  6711.             pv[PRN_NON].ival = 0;       /* is supposed to be treated as  */
  6712.             pv[PRN_WIN].ival = 0;       /* a DOS or Pipe printer.  We    */
  6713.             pv[PRN_FIL].ival = 0;       /* clear all the flags and let   */
  6714.             pv[PRN_PIP].ival = 0;       /* the code below dope out the   */
  6715.             pv[PRN_DOS].ival = 0;       /* type.                         */
  6716.         }
  6717. #ifdef NT
  6718.         else if (pv[PRN_WIN].ival && lookup(_printtab,line,nprint,&y)) {
  6719.             /* invalid Window Queue name */
  6720.             printf("?invalid Windows Printer Queue name: \"%s\"\r\n",line);
  6721.             x = -9;
  6722.             goto xsetprn;
  6723.         }
  6724. #endif /* NT */
  6725.         if ((x = cmcfm()) < 0)          /* Confirm the command */
  6726.           goto xsetprn;
  6727.         break;
  6728.       case _CMCFM:                      /* They entered the command */
  6729.         if (pv[PRN_DOS].ival > 0)
  6730.           ckstrncpy(line,pv[PRN_DOS].sval ? pv[PRN_DOS].sval : "",LINBUFSIZ);
  6731.         else if (pv[PRN_WIN].ival > 0)
  6732.           ckstrncpy(line,pv[PRN_WIN].sval ? pv[PRN_WIN].sval : "",LINBUFSIZ);
  6733.         else if (pv[PRN_FIL].ival > 0)
  6734.           ckstrncpy(line,pv[PRN_FIL].sval ? pv[PRN_FIL].sval : "",LINBUFSIZ);
  6735.         else if (pv[PRN_PIP].ival > 0)
  6736.           ckstrncpy(line,pv[PRN_PIP].sval ? pv[PRN_PIP].sval : "",LINBUFSIZ);
  6737.         break;
  6738.       default:                          /* By mistake */
  6739.         printf("?Unexpected function code: %d\n",cmresult.fcode);
  6740.         x = -9;
  6741.         goto xsetprn;
  6742.     }
  6743.  
  6744. #else  /* No PRINTSWI */
  6745.  
  6746.     if ((x = cmofi("Printer or file name",defname,&s,xxstring)) < 0)
  6747.       return(x);
  6748.     if (x > 1) {
  6749.         printf("?Directory names not allowed\n");
  6750.         return(-9);
  6751.     }
  6752.     while (*s == SP || *s == HT) s++;   /* Trim leading whitespace */
  6753.     ckstrncpy(line,s,LINBUFSIZ);        /* Make a temporary safe copy */
  6754.     if ((x = cmcfm()) < 0) return(x);   /* Confirm the command */
  6755. #endif /* PRINTSWI */
  6756.  
  6757. #ifdef IKSD
  6758.     if (inserver && (isguest
  6759. #ifndef NOSERVER
  6760.                      || !ENABLED(en_pri)
  6761. #endif /* NOSERVER */
  6762.                      )) {
  6763.         printf("Sorry, printing disabled\r\n");
  6764.         return(success = 0);
  6765.     }
  6766. #endif /* ISKD */
  6767.  
  6768. #ifdef PRINTSWI
  6769. #ifdef BPRINT
  6770.     if (printbidi) {                    /* If bidi printing active */
  6771. #ifndef UNIX
  6772.         bprtstop();                     /* Stop it before proceeding */
  6773. #endif /* UNIX */
  6774.         printbidi = 0;
  6775.     }
  6776.     if (pv[PRN_SPD].ival > 0) {
  6777.         portspeed = (long) pv[PRN_SPD].ival * 10L;
  6778.         if (portspeed == 70L) portspeed = 75L;
  6779.     }
  6780.     if (pv[PRN_PAR].ival > 0)
  6781.         portparity = pv[PRN_PAR].ival;
  6782.     if (pv[PRN_FLO].ival > 0)
  6783.         portflow = pv[PRN_FLO].ival;
  6784. #endif /* BPRINT */
  6785. #endif /* PRINTSWI */
  6786.  
  6787.     s = line;                           /* Printer name, if given */
  6788.  
  6789. #ifdef OS2ORUNIX
  6790. #ifdef PRINTSWI
  6791.     if (pv[PRN_PIP].ival > 0) {         /* /PIPE was given? */
  6792.         printpipe = 1;
  6793.         noprinter = 0;
  6794.         if (*s ==  '|') {               /* It might still have a pipe sign */
  6795.             s++;                        /* if name give later */
  6796.             while (*s == SP)            /* so remove it and spaces */
  6797.               s++;
  6798.         }
  6799.     } else
  6800. #endif /* PRINTSWI */
  6801.       if (*s == '|') {                  /* Or pipe implied by name? */
  6802.           s++;                          /* Point past pipe sign */
  6803.           while (*s == SP)              /* Gobble whitespace */
  6804.             s++;
  6805.           if (*s) {
  6806.               printpipe = 1;
  6807.               noprinter = 0;
  6808.           }
  6809.       } else {
  6810.           printpipe = 0;
  6811.       }
  6812.  
  6813. #ifdef PRINTSWI
  6814. #ifdef BPRINT
  6815.     if (printpipe && pv[PRN_BID].ival > 0) {
  6816.         printf("?Sorry, pipes not allowed for bidirectional printer\n");
  6817.         return(-9);
  6818.     }
  6819. #endif /* BPRINT */
  6820. #endif /* PRINTSWI */
  6821. #endif /* OS2ORUNIX */
  6822.  
  6823. #ifdef OS2
  6824.     if ( pv[PRN_PS].ival > 0 ) {
  6825.         txt2ps = 1;
  6826.         ps_width = pv[PRN_WID].ival <= 0 ? 80 : pv[PRN_WID].ival;
  6827.         ps_length = pv[PRN_LEN].ival <= 0 ? 66 : pv[PRN_LEN].ival;
  6828.     }
  6829. #endif /* OS2 */
  6830.  
  6831.     y = strlen(s);                      /* Length of name of new print file */
  6832.     if (y > 0
  6833. #ifdef OS2
  6834.         && ((y != 3) || (ckstrcmp(s,"PRN",3,0) != 0))
  6835. #endif /* OS2 */
  6836.         ) {
  6837.         if (printername) {              /* Had a print file before? */
  6838.             free(printername);          /* Remove its name */
  6839.             printername = NULL;
  6840.         }
  6841.         printername = (char *) malloc(y + 1); /* Allocate space for it */
  6842.         if (!printername) {
  6843.             printf("?Memory allocation failure\n");
  6844.             return(-9);
  6845.         }
  6846.         strcpy(printername,s);          /* (safe) Copy new name to new space */
  6847.         debug(F110,"printername",printername,0);
  6848.     }
  6849.  
  6850. #ifdef PRINTSWI
  6851.     /* Set printer type from switches that were given explicitly */
  6852.  
  6853.     if (pv[PRN_NON].ival > 0) {         /* No printer */
  6854.         printertype = PRT_NON;
  6855.         noprinter = 1;
  6856.         printpipe = 0;
  6857.     } else if (pv[PRN_FIL].ival > 0) {  /* File */
  6858.         printertype = PRT_FIL;
  6859.         noprinter = 0;
  6860.         printpipe = 0;
  6861.     } else if (pv[PRN_PIP].ival > 0) {  /* Pipe */
  6862.         printertype = PRT_PIP;
  6863.         noprinter = 0;
  6864.         printpipe = 1;
  6865.     } else if (pv[PRN_WIN].ival > 0) {  /* Windows print queue */
  6866.         printertype = PRT_WIN;
  6867.         noprinter = 0;
  6868.         printpipe = 0;
  6869.     } else if (pv[PRN_DOS].ival > 0) {  /* DOS device */
  6870.         printertype = PRT_DOS;
  6871.         noprinter = 0;
  6872.         printpipe = 0;
  6873.     } else if (line[0]) {               /* Name given without switches */
  6874.         noprinter = 0;
  6875.         printertype = printpipe ? PRT_PIP : PRT_DOS;
  6876. #ifdef NT
  6877.         /* was the command SET PRINTER windows-queue ? */
  6878.         if (lookup(_printtab,line,nprint,&x) >= 0) {
  6879.             printertype = PRT_WIN;
  6880.             if (pv[PRN_WIN].sval) free(pv[PRN_WIN].sval);
  6881.             if (printername) {          /* Had a print file before? */
  6882.                 free(printername);      /* Remove its name */
  6883.                 printername = NULL;
  6884.             }
  6885.             pv[PRN_WIN].sval = NULL;
  6886.             pv[PRN_WIN].ival = 1;
  6887.             s = printtab[x].kwd;        /* Get full new name */
  6888.             if ((y = strlen(s)) > 0) {
  6889.                 makestr(&pv[PRN_WIN].sval,s);
  6890.                 makestr(&printername,s);
  6891.                 if (!printername) {
  6892.                     printf("?Memory allocation failure\n");
  6893.                     return(-9);
  6894.                 }
  6895.                 debug(F110,"printername",printername,0);
  6896.             }
  6897.         }
  6898. #endif /* NT */
  6899.     }
  6900.  
  6901. #ifdef BPRINT
  6902.     /* Port parameters may be set for non-bidi mode */
  6903.  
  6904.     pportspeed = portspeed;             /* Set parameters */
  6905.     pportparity = portparity;
  6906.     pportflow = portflow;
  6907.  
  6908.     if (pv[PRN_BID].ival > 0) {         /* Bidirectional */
  6909. #ifdef UNIX
  6910.         printbidi = 1;                  /* (just to test parsing...) */
  6911. #else
  6912.         printbidi = bprtstart();        /* Start bidirectional printer */
  6913. #endif /* UNIX */
  6914.         return(success = printbidi);
  6915.     } else
  6916.       printbidi = 0;                    /* Not BPRINTER, unset flag */
  6917. #endif /* BPRINT */
  6918.  
  6919.     if (pv[PRN_TMO].ival > -1) {        /* Take care of timeout */
  6920.         printtimo = pv[PRN_TMO].ival;
  6921.     }
  6922.     if (pv[PRN_TRM].ival > 0) {         /* Termination string */
  6923.         if (printterm) {
  6924.             free(printterm);
  6925.             printterm = NULL;
  6926.         }
  6927.         if (pv[PRN_TRM].sval)
  6928.           makestr(&printterm,pv[PRN_TRM].sval);
  6929.     }
  6930.     if (pv[PRN_SEP].ival > 0) {         /* and separator file */
  6931.         if (printsep) {
  6932.             free(printsep);
  6933.             printsep = NULL;
  6934.         }
  6935.         if (pv[PRN_SEP].sval)
  6936.           makestr(&printsep,pv[PRN_SEP].sval);
  6937.     }
  6938. #endif /* PRINTSWI */
  6939.  
  6940. #ifdef UNIXOROSK
  6941.     if (!printpipe
  6942. #ifdef PRINTSWI
  6943.         && !noprinter
  6944. #endif /* PRINTSWI */
  6945.         ) {                             /* File - check access */
  6946.         if (zchko(s) < 0) {
  6947.             printf("?Access denied - %s\n",s);
  6948.             x = -9;
  6949.             goto xsetprn;
  6950.         }
  6951.     }
  6952. #endif /* UNIXOROSK */
  6953.  
  6954.     x = 1;                              /* Return code */
  6955.  
  6956.   xsetprn:                              /* Common exit */
  6957. #ifdef PRINTSWI
  6958.     for (i = 0; i <= PRN_MAX; i++) {    /* Free malloc'd memory */
  6959.         if (pv[i].sval)
  6960.           free(pv[i].sval);
  6961.     }
  6962. #endif /* PRINTSWI */
  6963.     success = (x > 0) ? 1 : 0;
  6964.     return(x);
  6965. }
  6966.  
  6967. #ifdef ANYSSH
  6968. /* The SET SSH command */
  6969.  
  6970. #define SSH_CMD  1                      /* SET SSH COMMAND */
  6971.  
  6972. #ifdef SSHBUILTIN                       /* Built-in SET SSH options */
  6973. #define SSH_ADD  2                      /* Add */
  6974. #define SSH_AFW  3                      /* Agent-forwarding */
  6975. #define SSH_CHI  4                      /* Check Host IP */
  6976. #define SSH_XFW  5                      /* X11-forwarding */
  6977. #define SSH_DYF  6                      /* Dynamic forwarding */
  6978. #define SSH_GWP  7                      /* Gatewa portgs */
  6979. #define SSH_GSS  8                      /* GSSAPI */
  6980. #define SSH_KBD  9                      /* KBD Interactive Devices */
  6981. #define SSH_K4  10                      /* Kerberos 4 */
  6982. #define SSH_K5  11                      /* Kerberos 5 */
  6983. #define SSH_SHK 12                      /* Strict Host Key Check */
  6984. #define SSH_V1  13                      /* SSH V1 */
  6985. #define SSH_V2  14                      /* SSH V2 */
  6986. #define SSH_PRP 15                      /* Privd port */
  6987. #define SSH_CMP 16                      /* Compression */
  6988. #define SSH_XAL 17                      /* X Auth Location */
  6989. #define SSH_SHH 18                      /* Quiet */
  6990. #define SSH_VER 19                      /* Version */
  6991. #define SSH_VRB 20                      /* Verbosity level */
  6992. #define SSH_IDF 21                      /* Identity File */
  6993. #define SSH_CFG 22                      /* Use OpenSSH Config */
  6994. #endif /* SSHBUILTIN */
  6995.  
  6996. static struct keytab sshtab[] = {       /* SET SSH command table */
  6997. #ifdef SSHBUILTIN
  6998.     { "agent-forwarding",        SSH_AFW,  0 },
  6999.     { "check-host-ip",           SSH_CHI,  0 },
  7000.     { "compression",             SSH_CMP,  0 },
  7001.     { "dynamic-forwarding",      SSH_DYF,  0 },
  7002.     { "gateway-ports",           SSH_GWP,  0 },
  7003.     { "gssapi",                  SSH_GSS,  0 },
  7004.     { "identity-file",           SSH_IDF,  0 },
  7005. #ifdef COMMENT
  7006.     { "kbd-interactive-devices", SSH_KBD,  0 },
  7007. #endif /* COMMENT */
  7008.     { "k4",                      SSH_K4, CM_INV },
  7009.     { "k5",                      SSH_K5, CM_INV },
  7010.     { "kerberos4",               SSH_K4,   0 },
  7011.     { "kerberos5",               SSH_K5,   0 },
  7012.     { "krb4",                    SSH_K4, CM_INV },
  7013.     { "krb5",                    SSH_K5, CM_INV },
  7014.     { "privileged-port",         SSH_PRP,  0 },
  7015.     { "quiet",                   SSH_SHH,  0 },
  7016.     { "strict-host-key-check",   SSH_SHK,  0 },
  7017.     { "use-openssh-config",      SSH_CFG,  0 },
  7018.     { "v1",                      SSH_V1,   0 },
  7019.     { "v2",                      SSH_V2,   0 },
  7020.     { "verbose",                 SSH_VRB,  0 },
  7021.     { "version",                 SSH_VER,  0 },
  7022.     { "x11-forwarding",          SSH_XFW,  0 },
  7023.     { "xauth-location",          SSH_XAL,  0 },
  7024. #else
  7025. #ifdef SSHCMD
  7026.     { "command",                 SSH_CMD,  0 },
  7027. #endif /* SSHCMD */
  7028. #endif /* SSHBUILTIN */
  7029.     { "", 0, 0 }
  7030. };
  7031. static int nsshtab = (sizeof(sshtab) / sizeof(struct keytab)) - 1;
  7032.  
  7033. #ifdef SSHBUILTIN
  7034. static struct keytab sshver[] = {       /* SET SSH VERSION command table */
  7035.     { "1",          1,  0 },
  7036.     { "2",          2,  0 },
  7037.     { "automatic",  0,  0 }
  7038. };
  7039.  
  7040. #define SSHA_CRS   1
  7041. #define SSHA_DSA   2
  7042. #define SSHA_GSS   3
  7043. #define SSHA_HOS   4
  7044. #define SSHA_KBD   5
  7045. #define SSHA_K4    6
  7046. #define SSHA_K5    7
  7047. #define SSHA_PSW   8
  7048. #define SSHA_PK    9
  7049. #define SSHA_SKE  10
  7050. #define SSHA_TIS  11
  7051. #define SSHA_EXT  12
  7052. #define SSHA_SRP  13
  7053.  
  7054. static struct keytab ssh2aut[] = {      /* SET SSH V2 AUTH command table */
  7055.     { "external-keyx",      SSHA_EXT, 0 },
  7056.     { "gssapi",             SSHA_GSS, 0 },
  7057.     { "hostbased",          SSHA_HOS, 0 },
  7058.     { "keyboard-interactive",  SSHA_KBD, 0 },
  7059.     { "password",           SSHA_PSW, 0 },
  7060.     { "publickey",          SSHA_PK,  0 },
  7061.     { "srp-gex-sha1",       SSHA_SRP, 0 },
  7062.     { "", 0, 0 }
  7063. };
  7064. static int nssh2aut = (sizeof(ssh2aut) / sizeof(struct keytab)) - 1;
  7065.  
  7066. #define SSHF_LCL   1
  7067. #define SSHF_RMT   2
  7068.  
  7069. static struct keytab addfwd[] = {       /* SET SSH ADD command table */
  7070.     { "local-port-forward",  SSHF_LCL, 0 },
  7071.     { "remote-port-forward", SSHF_RMT, 0 },
  7072.     { "", 0, 0 }
  7073. };
  7074. static int naddfwd = (sizeof(addfwd) / sizeof(struct keytab)) - 1;
  7075.  
  7076. #define SSH1_CIF   1
  7077. #define SSH1_GNH   2
  7078. #define SSH1_UNH   3
  7079. #define SSH1_K54   4
  7080.  
  7081. #define SSH2_CIF   1
  7082. #define SSH2_GNH   2
  7083. #define SSH2_UNH   3
  7084. #define SSH2_ARK   4
  7085. #define SSH2_HKA   5
  7086. #define SSH2_MAC   6
  7087. #define SSH2_AUT   7
  7088.  
  7089. static struct keytab sshv1tab[] = {     /* SET SSH V1 command table */
  7090.     { "cipher",                  SSH1_CIF, 0 },
  7091.     { "global-known-hosts-file", SSH1_GNH, 0 },
  7092.     { "k5-reuse-k4-messages",    SSH1_K54, CM_INV },
  7093.     { "user-known-hosts-file",   SSH1_UNH, 0 },
  7094.     { "", 0, 0 }
  7095. };
  7096. static int nsshv1tab = (sizeof(sshv1tab) / sizeof(struct keytab)) - 1;
  7097.  
  7098. static struct keytab sshv2tab[] = {     /* SET SSH V2 command table */
  7099.     { "authentication",          SSH2_AUT, 0 },
  7100.     { "auto-rekey",              SSH2_ARK, CM_INV },
  7101.     { "ciphers",                 SSH2_CIF, 0 },
  7102.     { "global-known-hosts-file", SSH2_GNH, 0 },
  7103.     { "hostkey-algorithms",      SSH2_HKA, 0 },
  7104.     { "macs",                    SSH2_MAC, 0 },
  7105.     { "user-known-hosts-file",   SSH2_UNH, 0 },
  7106.     { "", 0, 0 }
  7107. };
  7108. static int nsshv2tab = (sizeof(sshv2tab) / sizeof(struct keytab)) - 1;
  7109.  
  7110. #define SSHC_3DES 1                     /* 3DES */
  7111. #define SSHC_3CBC 2                     /* 3DES-CBC */
  7112. #define SSHC_A128 3                     /* AES128-CBC */
  7113. #define SSHC_A192 4                     /* AES192-CBC */
  7114. #define SSHC_A256 5                     /* AES256-CBC */
  7115. #define SSHC_ARC4 6                     /* ARCFOUR */
  7116. #define SSHC_FISH 7                     /* BLOWFISH */
  7117. #define SSHC_BCBC 9                     /* BLOWFISH-CBC */
  7118. #define SSHC_C128 8                     /* CAST128-CBC */
  7119. #define SSHC_1DES 10                    /* DES */
  7120.  
  7121. static struct keytab ssh1ciphers[] = {
  7122.     { "3des",         SSHC_3DES, 0 },
  7123.     { "blowfish",     SSHC_FISH, 0 },
  7124.     { "des",          SSHC_1DES, 0 },
  7125.     { "", 0, 0 }
  7126. };
  7127. static int nssh1ciphers = (sizeof(ssh1ciphers) / sizeof(struct keytab)) - 1;
  7128.  
  7129. static struct keytab ssh2ciphers[] = {  /* SET SSH V2 CIPHERS command table */
  7130.     { "3des-cbc",        SSHC_3DES, 0 },
  7131.     { "aes128-cbc",      SSHC_A128, 0 },
  7132.     { "aes192-cbc",      SSHC_A192, 0 },
  7133.     { "aes256-cbc",      SSHC_A256, 0 },
  7134.     { "arcfour",         SSHC_ARC4, 0 },
  7135.     { "blowfish-cbc",    SSHC_FISH, 0 },
  7136.     { "cast128-cbc",     SSHC_C128, 0 },
  7137.     { "rijndael128-cbc", SSHC_A128, 0 },
  7138.     { "rijndael192-cbc", SSHC_A192, 0 },
  7139.     { "rijndael256-cbc", SSHC_A256, 0 },
  7140.     { "", 0, 0 }
  7141. };
  7142. static int nssh2ciphers = (sizeof(ssh2ciphers) / sizeof(struct keytab)) - 1;
  7143.  
  7144. #define SSHM_SHA        1               /* HMAC-SHA1 */
  7145. #define SSHM_SHA_96     2               /* HMAC-SHA1-96 */
  7146. #define SSHM_MD5        3               /* HMAC-MD5 */
  7147. #define SSHM_MD5_96     4               /* HMAC-MD5-96 */
  7148. #define SSHM_RIPE       5               /* HMAC-RIPEMD160 */
  7149.  
  7150. static struct keytab ssh2macs[] = {     /* SET SSH V2 MACS command table */
  7151.     { "hmac-md5",       SSHM_MD5,    0 },
  7152.     { "hmac-md5-96",    SSHM_MD5_96, 0 },
  7153.     { "hmac-ripemd160", SSHM_RIPE,   0 },
  7154.     { "hmac-sha1",      SSHM_SHA,    0 },
  7155.     { "hmac-sha1-96",   SSHM_SHA_96, 0 },
  7156.     { "", 0, 0 }
  7157. };
  7158. static int nssh2macs = (sizeof(ssh2macs) / sizeof(struct keytab)) - 1;
  7159.  
  7160. static struct keytab tgtpass[] = {
  7161.     { "tgt-passing", 1, 0, },
  7162.     { "", 0, 0 }
  7163. };
  7164. static int ntgtpass = (sizeof(tgtpass) / sizeof(struct keytab)) - 1;
  7165.  
  7166. static struct keytab gssapitab[] = {
  7167.     { "delegate-credentials", 1, 0, },
  7168.     { "key-exchange",         2, CM_INV, },
  7169.     { "", 0, 0 }
  7170. };
  7171. static int ngssapitab = (sizeof(gssapitab) / sizeof(struct keytab)) - 1;
  7172.  
  7173. #define HKA_RSA 1
  7174. #define HKA_DSS 2
  7175.  
  7176. static struct keytab hkatab[] = {
  7177.     { "ssh-dss", HKA_DSS, 0, },
  7178.     { "ssh-rsa", HKA_RSA, 0, },
  7179.     { "", 0, 0 }
  7180. };
  7181. static int nhkatab = (sizeof(hkatab) / sizeof(struct keytab)) - 1;
  7182.  
  7183. int                                     /* SET SSH variables */
  7184.   ssh_afw = 0,                          /* agent forwarding */
  7185.   ssh_xfw = 0,                          /* x11 forwarding   */
  7186.   ssh_prp = SET_OFF,                    /* privileged ports */
  7187.   ssh_cmp = 1,                          /* compression */
  7188.   ssh_shh = 0,                          /* quiet       */
  7189.   ssh_ver = 0,                          /* protocol version (auto,1,2) */
  7190.   ssh_vrb = 2,                          /* Report errors */
  7191.   ssh_chkip = 0,                        /* SSH Check Host IP flag */
  7192.   ssh_gwp = 0,                          /* gateway ports */
  7193.   ssh_dyf = 0,                          /* dynamic forwarding */
  7194.   ssh_gsd = 0,                          /* gssapi delegate credentials */
  7195.   ssh_k4tgt = 0,                        /* k4 tgt passing */
  7196.   ssh_k5tgt = 0,                        /* k5 tgt passing */
  7197.   ssh_shk = 2,                          /* Strict host key (no, yes, ask) */
  7198.   ssh2_ark = 0,                         /* Auto re-key */
  7199.   ssh_cas = 0,                          /* command as subsys */
  7200.   ssh_cfg = 0,                          /* use OpenSSH config? */
  7201.   ssh_gkx = 1,                          /* gssapi key exchange */
  7202.   ssh_k5_is_k4 = 1,                     /* some SSH v1 use same codes */
  7203.   ssh_dummy = 0;                        /* bottom of list */
  7204.  
  7205. char                                    /* The following are to be malloc'd */
  7206.   * ssh1_cif = NULL,                    /* v1 cipher */
  7207.   * ssh2_cif = NULL,                    /* v2 cipher list */
  7208.   * ssh2_mac = NULL,                    /* v2 mac list */
  7209.   * ssh2_auth = NULL,                   /* v2 authentication list */
  7210.   * ssh_hst = NULL,                     /* hostname */
  7211.   * ssh_prt = NULL,                     /* port/service */
  7212.   * ssh_cmd = NULL,                     /* command to execute */
  7213.   * ssh_xal = NULL,                     /* xauth-location */
  7214.   * ssh1_gnh = NULL,                    /* v1 global known hosts file */
  7215.   * ssh1_unh = NULL,                    /* v1 user known hosts file */
  7216.   * ssh2_gnh = NULL,                    /* v2 global known hosts file */
  7217.   * ssh2_unh = NULL,                    /* v2 user known hosts file */
  7218.   * ssh2_hka = NULL,                    /* Host Key Algorithms */
  7219.   * xxx_dummy = NULL;
  7220.  
  7221. char * ssh_idf[32] = {                  /* Identity file list */
  7222.   NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
  7223.   NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
  7224.   NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
  7225.   NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
  7226. };
  7227. char * ssh_tmp[32] = {                  /* Temp identity file list */
  7228.   NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
  7229.   NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
  7230.   NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
  7231.   NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
  7232. };
  7233. int ssh_idf_n = 0;
  7234.  
  7235. extern int    ssh_pf_lcl_n,
  7236.               ssh_pf_rmt_n;
  7237. extern struct ssh_pf ssh_pf_lcl[32];    /* Port forwarding structs */
  7238. extern struct ssh_pf ssh_pf_rmt[32];    /* (declared in ckuusr.c) */
  7239. #endif /* SSHBUILTIN */
  7240.  
  7241. VOID
  7242. shossh() {
  7243. #ifdef SSHBUILTIN
  7244.     int i, n = 0;                       /* ADD askmore()! */
  7245.  
  7246.     printf("\nSSH is built in:\n\n");
  7247.  
  7248.     printf(" ssh host:                        %s\n",showstring(ssh_hst));
  7249.     printf(" ssh port:                        %s\n",showstring(ssh_prt));
  7250.     printf(" ssh command:                     %s\n",showstring(ssh_cmd));
  7251.     printf(" ssh agent-forwarding:            %s\n",showoff(ssh_afw));
  7252.     printf(" ssh check-host-ip:               %s\n",showoff(ssh_chkip));
  7253.     printf(" ssh compression:                 %s\n",showoff(ssh_cmp));
  7254.     printf(" ssh dynamic-forwarding:          %s\n",showoff(ssh_dyf));
  7255.     if (ssh_pf_lcl[0].p1 && ssh_pf_lcl[0].host && ssh_pf_lcl[0].p2)
  7256.       printf(" ssh forward-local-port:          %d %s %d\n",
  7257.              ssh_pf_lcl[0].p1, ssh_pf_lcl[0].host, ssh_pf_lcl[0].p2);
  7258.     else
  7259.       printf(" ssh forward-local-port:         (none)\n");
  7260.     if (ssh_pf_rmt[0].p1 && ssh_pf_rmt[0].host && ssh_pf_rmt[0].p2)
  7261.       printf(" ssh forward-remote-port:         %d %s %d\n",
  7262.              ssh_pf_rmt[0].p1, ssh_pf_rmt[0].host, ssh_pf_rmt[0].p2);
  7263.     else
  7264.       printf(" ssh forward-remote-port:        (none)\n");
  7265.     printf(" ssh gateway-ports:               %s\n",showoff(ssh_gwp));
  7266.     printf(" ssh gssapi delegate-credentials: %s\n",showoff(ssh_gsd));
  7267.     printf(" ssh gssapi key-exchange        : %s\n",showoff(ssh_gkx));
  7268.     printf(" ssh identity-file:               %d\n",ssh_idf_n);
  7269.     for (i = 0; i < ssh_idf_n; i++)
  7270.       printf("  %2d. %s\n",i+1,showstring(ssh_idf[i]));
  7271.     printf(" ssh k4 tgt-passing:              %s\n",showoff(ssh_k4tgt));
  7272.     printf(" ssh k5 tgt-passing:              %s\n",showoff(ssh_k5tgt));
  7273.  
  7274.     printf(" ssh privileged-port:             %s\n",showooa(ssh_prp));
  7275.     printf(" ssh quiet:                       %s\n",showoff(ssh_shh));
  7276.     printf(" ssh strict-host-key-check:       %d\n",ssh_shk);
  7277.     printf(" ssh use-openssh-config:          %s\n",showoff(ssh_cfg));
  7278.     printf(" ssh verbose:                     %d\n",ssh_vrb);
  7279.     printf(" ssh version:                     %s\n",
  7280.            ssh_ver ? ckitoa(ssh_ver) : "automatic"
  7281.            );
  7282.     printf(" ssh x11-forwarding:              %s\n",showooa(ssh_xfw));
  7283.     printf(" ssh xauth-location:              %s\n",showstring(ssh_xal));
  7284.     printf("\n");
  7285.     printf(" ssh v1 cipher:                   %s\n",showstring(ssh1_cif));
  7286.     printf(" ssh v1 global-known-hosts-file:  %s\n",showstring(ssh1_gnh));
  7287.     printf(" ssh v1 user-known-hosts-file:    %s\n",showstring(ssh1_unh));
  7288.     printf("\n");
  7289.     printf(" ssh v2 authentication:           %s\n",showstring(ssh2_auth));
  7290.     printf(" ssh v2 auto-rekey:               %s\n",showoff(ssh2_ark));
  7291.     printf(" ssh v2 ciphers:                  %s\n",showstring(ssh2_cif));
  7292.     printf(" ssh v2 command-as-subsystem:     %s\n",showoff(ssh_cas));
  7293.     printf(" ssh v2 global-known-hosts-file:  %s\n",showstring(ssh2_gnh));
  7294.     printf(" ssh v2 hostkey-algorithms:       %s\n",showstring(ssh2_hka));
  7295.     printf(" ssh v2 mac:                      %s\n",showstring(ssh2_mac));
  7296.     printf(" ssh v2 user-known-hosts-file:    %s\n",showstring(ssh2_unh));
  7297. #else
  7298. #ifdef SSHCMD
  7299.     extern char * sshcmd, * defsshcmd;
  7300.     char * s;
  7301.     s = sshcmd ? sshcmd : defsshcmd;
  7302.     printf("\n SSH is external.\n\n");
  7303.     printf(" ssh command: %s\n",showstring(s));
  7304. #endif /* SSHCMD */
  7305. #endif /* SSHBUILTIN */
  7306.     printf("\n");
  7307. }
  7308.  
  7309. static int
  7310. dosetssh() {
  7311. #ifdef SSHCMD
  7312.     extern char * sshcmd;
  7313. #endif /* SSHCMD */
  7314. #ifdef SSHBUILTIN
  7315. #ifndef SSHTEST
  7316.     extern int sl_ssh_xfw_saved, sl_ssh_ver_saved;
  7317. #endif /* SSHTEST */
  7318. #endif /* SSHBUILTIN */
  7319.     int cx, x, y, z;
  7320.     char * s;
  7321.  
  7322.     if ((cx = cmkey(sshtab,nsshtab,"","command", xxstring)) < 0)
  7323.       return(cx);
  7324.     switch (cx) {
  7325. #ifdef SSHCMD
  7326.       case SSH_CMD:                     /* Command */
  7327.         if ((x = cmtxt("Command to start ssh","ssh -e none",
  7328.                        &s,xxstring)) < 0)
  7329.           return(x);
  7330.         makestr(&sshcmd,s);
  7331.         return(success = 1);
  7332. #endif /* SSHCMD */
  7333.  
  7334. #ifdef SSHBUILTIN
  7335.       case SSH_AFW:                     /* Agent-forwarding */
  7336.         return(success = seton(&ssh_afw));
  7337.  
  7338.       case SSH_CHI:                     /* Check Host IP */
  7339.         return(success = seton(&ssh_chkip));
  7340.         break;
  7341.  
  7342.       case SSH_CMP:                     /* Compression */
  7343.         return(success = seton(&ssh_cmp));
  7344.  
  7345.       case SSH_DYF:                     /* Dynamic Forwarding */
  7346.         return(success = seton(&ssh_dyf));
  7347.  
  7348.       case SSH_GWP:                     /* Gateway ports */
  7349.         return(success = seton(&ssh_gwp));
  7350.  
  7351.       case SSH_GSS:                     /* GSSAPI */
  7352.         if ((y = cmkey(gssapitab,ngssapitab,"","", xxstring)) < 0)
  7353.           return(y);
  7354.         switch (y) {
  7355.           case 1:                       /* Delegate credentials */
  7356.             return(success = seton(&ssh_gsd));
  7357.           case 2:                       /* key-exchange */
  7358.             return(success = seton(&ssh_gkx));
  7359.         }
  7360.         if ((x = cmcfm()) < 0)
  7361.           return(x);
  7362.         return(success = 0);
  7363.  
  7364. #ifdef COMMENT
  7365.       case SSH_KBD:                     /* Kbd Interactive Devices */
  7366.         if ((x = cmcfm()) < 0)
  7367.           return(x);
  7368.         /* TO BE FILLED IN */
  7369.         return(-2);
  7370. #endif /* COMMENT */
  7371.  
  7372.       case SSH_K4:                      /* Kerberos IV */
  7373.       case SSH_K5:                      /* Kerberos V */
  7374.         if ((y = cmkey(tgtpass,1,"","tgt-passing", xxstring)) < 0)
  7375.           return(y);
  7376.         switch (y) {
  7377.           case 1:
  7378.             return(success = (cx == SSH_K4) ?
  7379.                    seton(&ssh_k4tgt) : seton(&ssh_k5tgt));
  7380.         }
  7381.         if ((x = cmcfm()) < 0)
  7382.           return(x);
  7383.         return(success = 0);
  7384.  
  7385.       case SSH_PRP:                     /* Privd port */
  7386.         return(success = seton(&ssh_prp));
  7387.  
  7388.       case SSH_SHH:                     /* Quiet */
  7389.         return(success = seton(&ssh_shh));
  7390.  
  7391.       case SSH_SHK:                     /* Strict Host Key Check */
  7392.         if ((y = cmkey(ooktab,3,"","", xxstring)) < 0)
  7393.           return(y);
  7394.         if ((x = cmcfm()) < 0)
  7395.           return(x);
  7396.         ssh_shk = y;
  7397.         return(success = 1);
  7398.  
  7399.       case SSH_V1:                      /* SSH V1 */
  7400.         if ((y = cmkey(sshv1tab,nsshv1tab,"","", xxstring)) < 0)
  7401.           return(y);
  7402.         switch (y) {
  7403.           case SSH1_K54:
  7404.             return(success = seton(&ssh_k5_is_k4));
  7405.           case SSH1_CIF:                /* Not a list */
  7406.             if ((y = cmkey(ssh1ciphers,nssh1ciphers,"","", xxstring)) < 0)
  7407.               if (y != -3)
  7408.                 return(y);
  7409.             if ((x = cmcfm()) < 0) return(x);
  7410.             if (y == -3) {
  7411.                 makestr(&ssh1_cif,NULL);
  7412.             } else {
  7413.                 for (x = 0; x < nssh1ciphers; x++)
  7414.                   if (ssh1ciphers[x].kwval == y)
  7415.                     break;
  7416.                 makestr(&ssh1_cif,ssh1ciphers[x].kwd);
  7417.             }
  7418.             return(1);
  7419.           case SSH1_GNH:
  7420.           case SSH1_UNH:
  7421.             if ((x = cmifi("Filename","",&s,&z,xxstring)) < 0) {
  7422.                 if (x != -3)
  7423.                   return(x);
  7424.             } else {
  7425.                 ckstrncpy(line,s,LINBUFSIZ);
  7426.                 if (zfnqfp(line,TMPBUFSIZ,tmpbuf))
  7427.                   ckstrncpy(line,tmpbuf,LINBUFSIZ);
  7428.             }
  7429.             s = (x == -3) ? NULL : line;
  7430.             if ((x = cmcfm()) < 0)
  7431.               return(x);
  7432.             switch (y) {
  7433.               case SSH1_GNH: makestr(&ssh1_gnh,s); break;
  7434.               case SSH1_UNH: makestr(&ssh1_unh,s); break;
  7435.             }
  7436.             return(1);
  7437.         }
  7438.  
  7439.       case SSH_V2:                      /* SSH V2 */
  7440.         if ((y = cmkey(sshv2tab,nsshv2tab,"","", xxstring)) < 0)
  7441.           return(y);
  7442.         switch (y) {
  7443.           case SSH2_ARK:
  7444.             return(success = seton(&ssh2_ark));
  7445.         case SSH2_AUT: {                        /* Authentication */
  7446. #define TMPCNT 12
  7447.             int i, j, tmp[TMPCNT];
  7448.             for (i = 0; i < TMPCNT; i++)
  7449.               tmp[i] = 0;
  7450.             for (i = 0; i < TMPCNT; i++) {
  7451.                 if ((y = cmkey(ssh2aut,nssh2aut,
  7452.                                "Authentication method","",xxstring)) < 0) {
  7453.                     if (y == -3)
  7454.                       break;
  7455.                     return(y);
  7456.                 }
  7457.                 for (j = 0; j < i; j++) {
  7458.                     if (tmp[j] == y) {
  7459.                         printf("\r\n?Choice has already been used.\r\n");
  7460.                         return(-9);
  7461.                     }
  7462.                 }
  7463.                 tmp[i] = y;
  7464.             }
  7465.             if ((z = cmcfm()) < 0)
  7466.               return(z);
  7467.  
  7468.             if (ssh2_auth) {
  7469.                 free(ssh2_auth);
  7470.                 ssh2_auth = NULL;
  7471.             }
  7472.             if (i > 0) {
  7473.                 int len = 0;
  7474.                 for (j = 0; j < i; j++) {
  7475.                     for (x = 0; x < nssh2aut; x++)
  7476.                       if (ssh2aut[x].kwval == tmp[j] && !ssh2aut[x].flgs)
  7477.                         break;
  7478.                     len += strlen(ssh2aut[x].kwd) + 1;
  7479.                 }
  7480.                 ssh2_auth = malloc(len);
  7481.                 ssh2_auth[0] = '\0';
  7482.                 for (j = 0; j < i; j++) {
  7483.                     for (x = 0; x < nssh2aut; x++)
  7484.                       if (ssh2aut[x].kwval == tmp[j] && !ssh2aut[x].flgs)
  7485.                         break;
  7486.                     ckstrncat(ssh2_auth,ssh2aut[x].kwd,len);
  7487.                     if (j < i - 1)
  7488.                       ckstrncat(ssh2_auth,",",len);
  7489.                 }
  7490.             }
  7491.             return(success = 1);
  7492. #undef TMPCNT
  7493.           }
  7494.         case SSH2_CIF: {
  7495. #define TMPCNT 12
  7496.             int i, j, tmp[TMPCNT];
  7497.             for (i = 0; i < TMPCNT; i++)
  7498.               tmp[i] = 0;
  7499.  
  7500.             for (i = 0; i < TMPCNT; i++) {
  7501.                 if ((y = cmkey(ssh2ciphers,nssh2ciphers,
  7502.                                "","", xxstring)) < 0) {
  7503.                     if (y == -3)
  7504.                       break;
  7505.                     return(y);
  7506.                 }
  7507.                 for (j = 0; j < i; j++) {
  7508.                     if (tmp[j] == y) {
  7509.                         printf("\r\n?Choice has already been used.\r\n");
  7510.                         return(-9);
  7511.                     }
  7512.                 }
  7513.                 tmp[i] = y;
  7514.             }
  7515.             if ((z = cmcfm()) < 0)
  7516.               return(z);
  7517.  
  7518.             if (ssh2_cif) {
  7519.                 free(ssh2_cif);
  7520.                 ssh2_cif = NULL;
  7521.             }
  7522.             if (i > 0) {
  7523.                 int len = 0;
  7524.                 for (j=0; j < i; j++) {
  7525.                     for (x = 0; x < nssh2ciphers; x++)
  7526.                       if (ssh2ciphers[x].kwval == tmp[j] &&
  7527.                           !ssh2ciphers[x].flgs)
  7528.                         break;
  7529.                     len += strlen(ssh2ciphers[x].kwd) + 1;
  7530.                 }
  7531.                 ssh2_cif = malloc(len);
  7532.                 ssh2_cif[0] = '\0';
  7533.                 for (j = 0; j < i; j++) {
  7534.                   for (x = 0; x < nssh2ciphers; x++)
  7535.                     if (ssh2ciphers[x].kwval == tmp[j] && !ssh2ciphers[x].flgs)
  7536.                       break;
  7537.                     ckstrncat(ssh2_cif,ssh2ciphers[x].kwd,len);
  7538.                     if (j < i - 1)
  7539.                       ckstrncat(ssh2_cif,",",len);
  7540.                 }
  7541.             }
  7542.             return(success = 1);
  7543. #undef TMPCNT
  7544.         }
  7545.         case SSH2_MAC: {
  7546. #define TMPCNT 12
  7547.             int i, j, tmp[TMPCNT];
  7548.             for (i = 0; i < TMPCNT; i++)
  7549.               tmp[i] = 0;
  7550.  
  7551.             for (i = 0; i < TMPCNT; i++) {
  7552.                 if ((y = cmkey(ssh2macs,nssh2macs,"","", xxstring)) < 0) {
  7553.                     if (y == -3)
  7554.                       break;
  7555.                     return(y);
  7556.                 }
  7557.                 for (j = 0; j < i; j++) {
  7558.                     if (tmp[j] == y) {
  7559.                         printf("\r\n?Choice has already been used.\r\n");
  7560.                         return(-9);
  7561.                     }
  7562.                 }
  7563.                 tmp[i] = y;
  7564.             }
  7565.             if ((z = cmcfm()) < 0)
  7566.                 return(z);
  7567.  
  7568.             if (ssh2_mac) {
  7569.                 free(ssh2_mac);
  7570.                 ssh2_mac = NULL;
  7571.             }
  7572.             if (i > 0) {
  7573.                 int len = 0;
  7574.                 for (j = 0; j < i; j++) {
  7575.                     for (x = 0; x < nssh2macs; x++)
  7576.                       if (ssh2macs[x].kwval == tmp[j] && !ssh2macs[x].flgs)
  7577.                         break;
  7578.                     len += strlen(ssh2macs[x].kwd) + 1;
  7579.                 }
  7580.                 ssh2_mac = malloc(len);
  7581.                 ssh2_mac[0] = '\0';
  7582.                 for (j=0; j < i; j++) {
  7583.                     for (x = 0; x < nssh2macs; x++)
  7584.                       if (ssh2macs[x].kwval == tmp[j] && !ssh2macs[x].flgs)
  7585.                         break;
  7586.                     ckstrncat(ssh2_mac,ssh2macs[x].kwd,len);
  7587.                     if (j < i - 1)
  7588.                       ckstrncat(ssh2_mac,",",len);
  7589.                 }
  7590.             }
  7591.             return(success = 1);
  7592. #undef TMPCNT
  7593.           }
  7594.           case SSH2_HKA: {
  7595. #define TMPCNT 12
  7596.             int i, j, tmp[TMPCNT];
  7597.             for (i = 0; i < TMPCNT; i++)
  7598.               tmp[i] = 0;
  7599.  
  7600.             for (i = 0; i < TMPCNT; i++) {
  7601.                 if ((y = cmkey(hkatab,nhkatab,
  7602.                                "","", xxstring)) < 0) {
  7603.                     if (y == -3)
  7604.                       break;
  7605.                     return(y);
  7606.                 }
  7607.                 for (j = 0; j < i; j++) {
  7608.                     if (tmp[j] == y) {
  7609.                         printf("\r\n?Choice has already been used.\r\n");
  7610.                         return(-9);
  7611.                     }
  7612.                 }
  7613.                 tmp[i] = y;
  7614.             }
  7615.             if ((z = cmcfm()) < 0)
  7616.               return(z);
  7617.  
  7618.             if (ssh2_hka) {
  7619.                 free(ssh2_hka);
  7620.                 ssh2_hka = NULL;
  7621.             }
  7622.             if (i > 0) {
  7623.                 int len = 0;
  7624.                 for (j=0; j < i; j++) {
  7625.                     for (x = 0; x < nhkatab; x++)
  7626.                       if (hkatab[x].kwval == tmp[j] &&
  7627.                           !hkatab[x].flgs)
  7628.                         break;
  7629.                     len += strlen(hkatab[x].kwd) + 1;
  7630.                 }
  7631.                 ssh2_hka = malloc(len);
  7632.                 ssh2_hka[0] = '\0';
  7633.                 for (j = 0; j < i; j++) {
  7634.                   for (x = 0; x < nhkatab; x++)
  7635.                     if (hkatab[x].kwval == tmp[j] && !hkatab[x].flgs)
  7636.                       break;
  7637.                     ckstrncat(ssh2_hka,hkatab[x].kwd,len);
  7638.                     if (j < i - 1)
  7639.                       ckstrncat(ssh2_hka,",",len);
  7640.                 }
  7641.             }
  7642.             return(success = 1);
  7643. #undef TMPCNT
  7644.           }
  7645.           case SSH2_GNH:
  7646.           case SSH2_UNH:
  7647.             if ((x = cmifi("Filename","",&s,&z,xxstring)) < 0) {
  7648.                 if (x != -3)
  7649.                   return(y);
  7650.             } else {
  7651.                 ckstrncpy(line,s,LINBUFSIZ);
  7652.                 if (zfnqfp(line,TMPBUFSIZ,tmpbuf))
  7653.                   ckstrncpy(line,tmpbuf,LINBUFSIZ);
  7654.             }
  7655.             s = (x == -3) ? NULL : line;
  7656.             if ((x = cmcfm()) < 0)
  7657.               return(x);
  7658.             switch (y) {
  7659.               case SSH2_GNH: makestr(&ssh2_gnh,s); break;
  7660.               case SSH2_UNH: makestr(&ssh2_unh,s); break;
  7661.               default: return(success = 0);
  7662.             }
  7663.             return(success = 1);
  7664.         }
  7665.  
  7666.       case SSH_VRB:                     /* Verbosity level */
  7667.         y = cmnum("SSH verbosity level, 0-7","2",10,&x,xxstring);
  7668.         return(setnum(&ssh_vrb,x,y,7));
  7669.  
  7670.       case SSH_VER:                     /* Version */
  7671.         if ((y = cmkey(sshver,3,"","auto", xxstring)) < 0)
  7672.           return(y);
  7673.         if ((x = cmcfm()) < 0)
  7674.           return(x);
  7675.         ssh_ver = y;                    /* 0 == AUTO */
  7676. #ifndef SSHTEST
  7677.         sl_ssh_ver_saved = 0;
  7678. #endif /* SSHTEST */
  7679.         return(success = 1);
  7680.  
  7681.       case SSH_IDF: {                   /* Identity file */
  7682.         int i, n;
  7683.         for (i = 0; i < 32; i++) {
  7684.             if ((x = cmifi("Filename","",&s,&y,xxstring)) < 0) {
  7685.                 if (x == -3)
  7686.                   break;
  7687.                 return(x);
  7688.             }
  7689.             if (!zfnqfp(s,LINBUFSIZ,line))
  7690.               ckstrncpy(line,s,LINBUFSIZ);
  7691.             makestr(&ssh_tmp[i],line);
  7692.         }
  7693.         n = i;
  7694.         if ((x = cmcfm()) < 0) {
  7695.             for (i = 0; i < n; i++)
  7696.               makestr(&(ssh_tmp[i]),NULL);
  7697.             return(x);
  7698.         }
  7699.         for (i = 0; i < 32; i++) {
  7700.             makestr(&(ssh_idf[i]),NULL);
  7701.             if (i < n) {
  7702.                 ssh_idf[i] = ssh_tmp[i];
  7703.                 ssh_tmp[i] = NULL;
  7704.             } else {
  7705.                 makestr(&(ssh_tmp[i]),NULL);
  7706.             }
  7707.         }
  7708.         ssh_idf_n = n;
  7709.         return(success = 1);
  7710.       }
  7711.       case SSH_XFW:                     /* X11-forwarding */
  7712.         success = seton(&ssh_xfw);
  7713. #ifndef SSHTEST
  7714.         if (success)
  7715.           sl_ssh_xfw_saved = 0;
  7716. #endif /* SSHTEST */
  7717.         return(success);
  7718.  
  7719.       case SSH_XAL:                     /* SSH Xauth Location */
  7720.         if ((x = cmifi("Path to executable", "",&s,&y,xxstring)) < 0) {
  7721.             if (x != -3)
  7722.               return(x);
  7723.         } else {
  7724.             ckstrncpy(line,s,LINBUFSIZ);
  7725.             if (zfnqfp(line,TMPBUFSIZ,tmpbuf))
  7726.               ckstrncpy(line,tmpbuf,LINBUFSIZ);
  7727.         }
  7728.         s = (x == -3) ? NULL : line;
  7729.         if ((x = cmcfm()) < 0) return(x);
  7730.         makestr(&ssh_xal,s);
  7731.         return(success = 1);
  7732.  
  7733.       case SSH_CFG:                     /* Use OpenSSH Config */
  7734.         return(success = seton(&ssh_cfg));
  7735. #endif /* SSHBUILTIN */
  7736.  
  7737.       default:
  7738.         return(-2);
  7739.     }
  7740. }
  7741. #endif /* ANYSSH */
  7742.  
  7743.  
  7744. #ifdef KUI
  7745. #include "ikui.h"
  7746. extern ULONG RGBTable[16];
  7747.  
  7748. #define GUI_RGB  1
  7749. #define GUI_WIN  2
  7750. #define GUI_FON  3
  7751. #define GUIW_POS 1
  7752.  
  7753. static struct keytab guitab[] = {
  7754.     { "rgbcolor",    GUI_RGB,  0 },
  7755.     { "window",      GUI_WIN,  0 },
  7756.     { "font",        GUI_FON,  0 },
  7757.     { "", 0, 0}
  7758. };
  7759. static int nguitab = (sizeof(guitab) / sizeof(struct keytab));
  7760.  
  7761. static struct keytab guiwtab[] = {
  7762.     { "position",    GUIW_POS, 0 },
  7763.     { "", 0, 0}
  7764. };
  7765. static int nguiwtab = (sizeof(guiwtab) / sizeof(struct keytab));
  7766.  
  7767. static struct keytab rgbtab[] = {
  7768.     { "black",         0, 0 },
  7769.     { "blue",          1, 0 },
  7770.     { "brown",         6, 0 },
  7771.     { "cyan",          3, 0 },
  7772.     { "dgray",         8, 0 },
  7773.     { "green",         2, 0 },
  7774.     { "lblue",         9, CM_INV },
  7775.     { "lcyan",        11, CM_INV },
  7776.     { "lgreen",       10, CM_INV },
  7777.     { "lgray",         7, CM_INV },
  7778.     { "lightblue",     9, 0 },
  7779.     { "lightcyan",    11, 0 },
  7780.     { "lightgreen",   10, 0 },
  7781.     { "lightgray",     7, 0 },
  7782.     { "lightmagenta", 13, 0 },
  7783.     { "lightred",     12, 0 },
  7784.     { "lmagenta",     13, CM_INV },
  7785.     { "lred",         12, CM_INV },
  7786.     { "magenta",       5, 0 },
  7787.     { "red",           4, 0 },
  7788.     { "white",        15, 0 },
  7789.     { "yellow",       14, 0 },
  7790.  
  7791. };
  7792. int nrgb = (sizeof(rgbtab) / sizeof(struct keytab));
  7793.  
  7794. VOID
  7795. shogui() {
  7796.     int i, red, green, blue;
  7797.     char * s;
  7798.  
  7799.     printf("RGB Color Table\n\n");
  7800.     printf("  Color              Red Green Blue\n");
  7801.     printf("  ------------------------------------\n");
  7802.     for (i = 0; i < nrgb; i++) {
  7803.         if (!rgbtab[i].flgs) {
  7804.             blue = (RGBTable[rgbtab[i].kwval] & 0x00FF0000)>>16;
  7805.             green = (RGBTable[rgbtab[i].kwval] & 0x0000FF00)>>8;
  7806.             red = (RGBTable[rgbtab[i].kwval] & 0x000000FF);
  7807.             printf("  %-18s %3d  %3d  %3d\n",rgbtab[i].kwd,red,green,blue);
  7808.         }
  7809.     }
  7810.     printf("\n");
  7811. }
  7812.  
  7813. int
  7814. setrgb() {
  7815.     int cx, red = 0, blue = 0, green = 0, z, x;
  7816.  
  7817.     if ((cx = cmkey(rgbtab,nrgb,"","",xxstring)) < 0)
  7818.       return(cx);
  7819.     if ((z = cmnum("Red value, 0-255","",10,&red,xxstring)) < 0)
  7820.       return(z);
  7821.     if ((z = cmnum("Blue value, 0-255","",10,&green,xxstring)) < 0)
  7822.       return(z);
  7823.     if ((z = cmnum("Green value, 0-255","",10,&blue,xxstring)) < 0)
  7824.       return(z);
  7825.     if ((x = cmcfm()) < 0) return(x);
  7826.     if (cx > 15 || red > 255 || blue > 255 || green > 255)
  7827.       return(-2);
  7828.     RGBTable[cx] = (unsigned)(((unsigned)blue << 16) |
  7829.         (unsigned)((unsigned)green << 8) |
  7830.         (unsigned)red);
  7831.     return(success = 1);
  7832. }
  7833.  
  7834. /*
  7835.   Set GUI window position: XY coordinates of upper left corner,
  7836.   expressed as pixel numbers in the current screen resolution.
  7837.   (0,0) means put ourselves in the upper left corner.
  7838.   Can we check for out of bounds?
  7839. */
  7840.  
  7841. int
  7842. setguiwin() {
  7843.     int cx, x, y, z;
  7844.     if ((cx = cmkey(guiwtab,nguiwtab,"","",xxstring)) < 0)
  7845.       return(cx);
  7846.     switch (cx) {
  7847.       case GUIW_POS:
  7848.         if ((z = cmnum("X coordinate (pixel number)","",10,&x,xxstring)) < 0)
  7849.           return(z);
  7850.         if ((z = cmnum("Y coordinate (pixel number)","",10,&y,xxstring)) < 0)
  7851.           return(z);
  7852.         if ((z = cmcfm()) < 0)
  7853.           return(z);
  7854.         if (x < 0 || y < 0) {
  7855.             printf("?Coordinates must be 0 or greater\n");
  7856.             return(-9);
  7857.         }
  7858. #ifdef COMMENT
  7859.         gui_xpos = x;
  7860.         gui_ypos = y;
  7861.         /* ACTION HERE */
  7862. #endif /* COMMENT */
  7863.         return(success = 1);
  7864.  
  7865.       default:
  7866.         return(-2);
  7867.     }
  7868. }
  7869.  
  7870. int
  7871. setguifont() {
  7872.     extern struct keytab * term_font;
  7873.     extern struct keytab * _term_font;
  7874.     extern int tt_font, tt_font_size, ntermfont;
  7875.     int x, y, z;
  7876.     if (ntermfont == 0)
  7877.       BuildFontTable(&term_font, &_term_font, &ntermfont);
  7878.     if (!(term_font && _term_font && ntermfont > 0)) {
  7879.         printf("\nUnable to enumerate fonts.\n");
  7880.         return(-9);
  7881.     }
  7882.     if ((x = cmkey(_term_font,ntermfont,"","",xxstring)) < 0) {
  7883.         return(x);
  7884.     }
  7885.     if ((z = cmnum("Height of Font","12",10,&y,xxstring)) < 0)
  7886.       return(z);
  7887.     if ((z = cmcfm()) < 0) return(z);
  7888.     tt_font = x;
  7889.     tt_font_size = y;
  7890.     KuiSetProperty(KUI_TERM_FONT, (long)tt_font, (long)tt_font_size);
  7891.     return(success = 1);
  7892. }
  7893.  
  7894. int
  7895. setgui() {
  7896.     int cx;
  7897.     if ((cx = cmkey(guitab,nguitab,"","",xxstring)) < 0)
  7898.       return(cx);
  7899.     switch (cx) {
  7900.       case GUI_RGB:
  7901.         return(setrgb());
  7902.       case GUI_WIN:
  7903.         return(setguiwin());
  7904.       default:
  7905.         return(-2);
  7906.     }
  7907. }
  7908. #endif /* KUI */
  7909.  
  7910. /*  D O P R M  --  Set a parameter.  */
  7911. /*
  7912.  Returns:
  7913.   -2: illegal input
  7914.   -1: reparse needed
  7915.    0: success
  7916. */
  7917. int
  7918. doprm(xx,rmsflg) int xx, rmsflg; {
  7919.     int i = 0, x = 0, y = 0, z = 0;
  7920.     long zz = 0L;
  7921.     char *s = NULL, *p = NULL;
  7922. #ifdef OS2
  7923.     char portbuf[64];
  7924.     long portspeed = 0L;
  7925.     int portparity = 0;
  7926.     int portflow = 0;
  7927. #endif /* OS2 */
  7928.  
  7929. #ifndef NOSETKEY
  7930. #ifdef OS2
  7931.     if (xx == XYMSK)
  7932.       return(setmsk());
  7933. #endif /* OS2 */
  7934. #endif /* NOSETKEY */
  7935.  
  7936.     if (xx == XYFLAG) {                 /* SET FLAG */
  7937.         extern int ooflag;
  7938.         return(success = seton(&ooflag));
  7939.     }
  7940.     if (xx == XYPRTR                    /* SET PRINTER (or BPRINTER) */
  7941. #ifdef BPRINT
  7942.         || xx == XYBDCP
  7943. #endif /* BPRINT */
  7944.         )
  7945.       return(setprinter(xx));
  7946.  
  7947.     switch (xx) {
  7948.  
  7949. #ifdef ANYX25                           /* SET X25 ... */
  7950. case XYX25:
  7951.         return(setx25());
  7952.  
  7953. #ifndef IBMX25
  7954. case XYPAD:                             /* SET PAD ... */
  7955.         return(setpadp());
  7956. #endif /* IBMX25 */
  7957. #endif /* ANYX25 */
  7958.  
  7959. #ifndef NOXFER
  7960.       case XYEOL:       /* These have all been moved to set send/receive... */
  7961.       case XYLEN:       /* Let the user know what to do. */
  7962.       case XYMARK:
  7963.       case XYNPAD:
  7964.       case XYPADC:
  7965.       case XYTIMO:
  7966.         printf("...Use SET SEND or SET RECEIVE instead.\n");
  7967.         printf("Type HELP SET SEND or HELP SET RECEIVE for more info.\n");
  7968.         return(success = 0);
  7969.  
  7970.       case XYATTR:                      /* File Attribute packets */
  7971.         return(setat(rmsflg));
  7972.  
  7973.       case XYIFD:                       /* Incomplete file disposition */
  7974.         if ((y = cmkey(ifdatab,3,"","auto",xxstring)) < 0) return(y);
  7975.         if ((x = cmcfm()) < 0) return(x);
  7976.         if (rmsflg) {
  7977.             sstate = setgen('S',
  7978.                             "310",
  7979.                             y == 0 ? "0" : (y == 1 ? "1" : "2"),
  7980.                             ""
  7981.                             );
  7982.             return((int) sstate);
  7983.         } else {
  7984.             keep = y;
  7985.             return(success = 1);
  7986.         }
  7987. #endif /* NOXFER */
  7988.  
  7989. #ifndef NOSPL
  7990.       case XYINPU:                      /* SET INPUT */
  7991.         return(setinp());
  7992. #endif /* NOSPL */
  7993.  
  7994. #ifdef NETCONN
  7995.       case XYNET: {                     /* SET NETWORK */
  7996.  
  7997.           struct FDB k1, k2;
  7998.  
  7999.           cmfdbi(&k1,_CMKEY,"","","",nnetkey, 0, xxstring, netkey, &k2);
  8000.           cmfdbi(&k2,_CMKEY,"","","",nnets,   0, xxstring, netcmd, NULL);
  8001.  
  8002. #ifdef OS2     /* Hide network-type keywords for networks not installed */
  8003.           for (z = 0; z < nnets; z++) {
  8004.               if (netcmd[z].kwval == NET_TCPB && tcp_avail == 0)
  8005.                 netcmd[z].flgs =  CM_INV;
  8006. #ifdef SSHBUILTIN
  8007.               if (netcmd[z].kwval == NET_SSH &&
  8008.                    !ck_ssleay_is_installed())
  8009.                 netcmd[z].flgs =  CM_INV;
  8010. #endif /* SSHBUILTIN */
  8011. #ifdef DECNET
  8012.               else if (netcmd[z].kwval == NET_DEC  && dnet_avail == 0)
  8013.                 netcmd[z].flgs =  CM_INV;
  8014. #endif /* DECNET */
  8015. #ifdef CK_NETBIOS
  8016.               else if (netcmd[z].kwval == NET_BIOS && netbiosAvail == 0)
  8017.                 netcmd[z].flgs =  CM_INV;
  8018. #endif /* CK_NETBIOS */
  8019. #ifdef SUPERLAT
  8020.               else if (netcmd[z].kwval == NET_SLAT  && slat_avail == 0)
  8021.                 netcmd[z].flgs =  CM_INV;
  8022. #endif /* SUPERLAT */
  8023.           }
  8024.           if (tcp_avail)                /* Default network type */
  8025.             ckstrncpy(tmpbuf,"tcp/ip",TMPBUFSIZ);
  8026. #ifdef SSHBUILTIN
  8027.           else if ( ck_ssleay_is_installed() )
  8028.             ckstrncpy(tmpbuf,"ssh",TMPBUFSIZ);
  8029. #endif /* SSHBUILTIN */
  8030. #ifdef DECNET
  8031.           else if (dnet_avail)
  8032.             ckstrncpy(tmpbuf,"decnet",TMPBUFSIZ);
  8033. #endif /* DECNET */
  8034. #ifdef SUPERLAT
  8035.           else if (slat_avail)
  8036.             ckstrncpy(tmpbuf,"superlat",TMPBUFSIZ);
  8037. #endif /* SUPERLAT */
  8038. #ifdef CK_NETBIOS
  8039.           else if (netbiosAvail)
  8040.             ckstrncpy(tmpbuf,"netbios",TMPBUFSIZ);
  8041. #endif /* CK_NETBIOS */
  8042.           else ckstrncpy(tmpbuf,"named-pipe",TMPBUFSIZ);
  8043. #else  /* OS2 */
  8044. #ifdef TCPSOCKET
  8045.           ckstrncpy(tmpbuf,"tcp/ip",TMPBUFSIZ);
  8046. #else
  8047. #ifdef ANYX25
  8048.           ckstrncpy(tmpbuf,"x.25",TMPBUFSIZ);
  8049. #else
  8050.           ckstrncpy(tmpbuf,"",TMPBUFSIZ);
  8051. #endif /* ANYX25 */
  8052. #endif /* TCPSOCKET */
  8053. #endif /* OS2 */
  8054.  
  8055.           x = cmfdb(&k1);
  8056.           if (x < 0) {                  /* Error */
  8057.               if (x == -2 || x == -9)
  8058.                 printf("?No keywords match: \"%s\"\n",atmbuf);
  8059.               return(x);
  8060.           }
  8061.           z = cmresult.nresult;         /* Keyword value */
  8062.           if (cmresult.fdbaddr == &k1) { /* Which table? */
  8063. #ifndef NOSPL
  8064. #ifndef NODIAL
  8065.               if (z == XYNET_D)
  8066.                 return(parsdir(1));
  8067. #endif /* NODIAL */
  8068. #endif /* NOSPL */
  8069.               if ((z = cmkey(netcmd,nnets,"",tmpbuf,xxstring)) < 0)
  8070.                 return(z);
  8071.           }
  8072.  
  8073. #ifdef NETCMD
  8074.           if (z == NET_CMD && nopush) {
  8075.               printf("\n?Sorry, access to external commands is disabled\n");
  8076.               return(-9);
  8077.           }
  8078. #endif /* NETCMD */
  8079.  
  8080. #ifndef NOPUSH
  8081. #ifdef NETPTY
  8082.           if (z == NET_PTY && nopush) {
  8083.               printf("\n?Sorry, access to external commands is disabled\n");
  8084.               return(-9);
  8085.           }
  8086. #endif /* NETPTY */
  8087. #endif /* NOPUSH */
  8088.  
  8089. #ifdef OS2
  8090.           if (z == NET_TCPB && tcp_avail == 0) {
  8091.               printf(
  8092. "\n?Sorry, either TCP/IP is not available on this system or\n\
  8093. necessary DLLs did not load.  Use SHOW NETWORK to check network status.\n");
  8094.               return(-9);
  8095. #ifdef SSHBUILTIN
  8096.           } else if (z == NET_SSH && !ck_ssleay_is_installed()) {
  8097.             printf("\n?Sorry, SSH is not available on this system.\n") ;
  8098.             return(-9);
  8099. #endif /* SSHBUILTIN */
  8100. #ifdef CK_NETBIOS
  8101.           } else if (z == NET_BIOS && netbiosAvail == 0) {
  8102.               printf("\n?Sorry, NETBIOS is not available on this system.\n") ;
  8103.               return(-9);
  8104. #endif /* CK_NETBIOS */
  8105. #ifdef DECNET
  8106.           } else if (z == NET_DEC && dnet_avail == 0) {
  8107.               printf("\n?Sorry, DECnet is not available on this system.\n") ;
  8108.               return(-9);
  8109. #endif /* DECNET */
  8110. #ifdef SUPERLAT
  8111.           } else if (z == NET_SLAT && slat_avail == 0) {
  8112.               printf("\n?Sorry, SuperLAT is not available on this system.\n") ;
  8113.               return(-9);
  8114. #endif /* SUPERLAT */
  8115.           }
  8116. #endif /* OS2 */
  8117.  
  8118. #ifdef NPIPEORBIOS
  8119.           if (z == NET_PIPE ||          /* Named pipe -- also get pipename */
  8120.               z == NET_BIOS) {          /* NETBIOS -- also get local name */
  8121.               char *defnam;
  8122. #ifdef CK_NETBIOS
  8123.               char tmpnbnam[NETBIOS_NAME_LEN+1];
  8124. #endif /* CK_NETBIOS */
  8125.               /* Construct default name  */
  8126.               if (z == NET_PIPE) {      /* Named pipe */
  8127.                   defnam = "kermit";    /* Default name is always "kermit" */
  8128.               } else {                  /* NetBIOS */
  8129.                   if (NetBiosName[0] != SP) { /* If there is already a name, */
  8130.                       char *p = NULL;
  8131.                       int n;            /* use it as the default. */
  8132.                       ckstrncpy(tmpnbnam,NetBiosName,NETBIOS_NAME_LEN+1);
  8133.                       /* convert trailing spaces to NULs */
  8134.                       p = &tmpnbnam[NETBIOS_NAME_LEN-1];
  8135.                       while (*p == SP) {
  8136.                           *p = NUL;
  8137.                           p--;
  8138.                       }
  8139.                       defnam = tmpnbnam;
  8140.                   } else if (*myhost)   /* Otherwise use this PC's host name */
  8141.                     defnam = (char *) myhost;
  8142.                   else                  /* Otherwise use "kermit" */
  8143.                     defnam = "kermit";
  8144.               }
  8145.               if ((y = cmtxt((z == NET_PIPE) ? "pipe name" :
  8146.                              "local NETBIOS name",
  8147.                              defnam, &s, xxstring)) < 0)
  8148.                 return(y);
  8149. #ifdef NPIPE
  8150.               pipename[0] = NUL;
  8151. #endif /* NPIPE */
  8152.               if ((y = (int) strlen(s)) < 1) {
  8153.                   printf("?You must also specify a %s name\n",
  8154.                          (z == NET_PIPE) ? "pipe" : "local NETBIOS" );
  8155.                   return(-9);
  8156.               }
  8157. #ifdef CK_NETBIOS
  8158.               if (z == NET_BIOS) {
  8159.                   if (!netbiosAvail) {
  8160.                       printf("?NETBIOS is not available on this system.\n") ;
  8161.                       return(-9);
  8162.                   }
  8163.                   if (y - NETBIOS_NAME_LEN > 0) {
  8164.                       printf("?NETBIOS name too long, %ld maximum\n",
  8165.                              NETBIOS_NAME_LEN);
  8166.                       return(-9);
  8167.                   } else if ( !strcmp(s,tmpnbnam) ) {
  8168.                       nettype = z;      /* Returning to old connection... */
  8169.                       return(success = 1); /* Done */
  8170.                   } else if (strcmp("                ",NetBiosName)) {
  8171.                       printf("?NETBIOS name already assigned to \"%s\"\n",
  8172.                              NetBiosName);
  8173.                       return(-9);
  8174.                   } else {
  8175.                       NCB ncb;
  8176.                       APIRET rc;
  8177.                       ckstrncpy(NetBiosName,s,16);
  8178.                       for (x = y; x < NETBIOS_NAME_LEN; x++)
  8179.                         NetBiosName[x] = SP;
  8180.                       NetBiosName[NETBIOS_NAME_LEN] = NUL;
  8181.                       printf("Checking \"%s\" as a unique NetBIOS name...\n",
  8182.                              NetBiosName);
  8183.                       rc = NCBAddName( NetbeuiAPI,
  8184.                                       &ncb, NetBiosAdapter, NetBiosName );
  8185.                       if (rc) {
  8186.                           printf(
  8187.                 "?Sorry, \"%s\" is already in use by another NetBIOS node.\n",
  8188.                                  NetBiosName);
  8189.                           for (x = 0; x < NETBIOS_NAME_LEN; x++)
  8190.                             NetBiosName[x] = SP;
  8191.                           return(-9);
  8192.                       }
  8193.                   }
  8194.               }
  8195. #endif /* CK_NETBIOS */
  8196. #ifdef NPIPE
  8197.               if (z == NET_PIPE)
  8198.                 ckstrncpy(pipename,s,PIPENAML);
  8199. #endif /* NPIPE */
  8200.           } else
  8201. #endif /* NPIPEORBIOS */
  8202. #ifdef DECNET
  8203.             if (z == NET_DEC) {
  8204.                 /* Determine if we are using LAT or CTERM */
  8205.                 if ((y = cmkey(dnettab,
  8206.                                ndnet,"DECNET protocol","lat",xxstring)) < 0)
  8207.                   return(y);
  8208.                 if ((x = cmcfm()) < 0) return(x);
  8209.                 ttnproto = y;
  8210.             } else
  8211. #endif /* DECNET */
  8212. #ifdef NETDLL
  8213.               if (z == NET_DLL) {
  8214.                   /* Find out which DLL they are using */
  8215.                   char dllname[256]="";
  8216.                   char * p=NULL;
  8217.                   if ((x = cmifi("Dynamic load library",
  8218.                                  "",&p,&y,xxstring)) < 0) {
  8219.                       if (x == -3) {
  8220.                           printf("?Name of DLL required\n");
  8221.                           return(-9);
  8222.                       }
  8223.                       return(x);
  8224.                   }
  8225.                   ckstrncpy(dllname,p,256);
  8226.                   if ((x = cmcfm()) < 0) return(x);
  8227.  
  8228.                   if (netdll_load(dllname) < 0) /* Try to load the dll */
  8229.                     return(success = 0);
  8230.                   else {
  8231.                       nettype = z;
  8232.                       return(success = 1);
  8233.                   }
  8234.               } else
  8235. #endif /* NETDLL */
  8236.                 if ((x = cmcfm()) < 0) return(x);
  8237.           nettype = z;
  8238.           if (
  8239. #ifdef DECNET
  8240.               (nettype != NET_DEC)  &&
  8241. #endif /* DECNET */
  8242. #ifdef NPIPE
  8243.               (nettype != NET_PIPE) &&
  8244. #endif /* NPIPE */
  8245. #ifdef CK_NETBIOS
  8246.               (nettype != NET_BIOS) &&
  8247. #endif /* CK_NETBIOS */
  8248. #ifdef NETFILE
  8249.               (nettype != NET_FILE) &&
  8250. #endif /* NETFILE */
  8251. #ifdef NETCMD
  8252.               (nettype != NET_CMD) &&
  8253. #endif /* NETCMD */
  8254. #ifdef NETPTY
  8255.               (nettype != NET_PTY) &&
  8256. #endif /* NETPTY */
  8257. #ifdef NETDLL
  8258.               (nettype != NET_DLL) &&
  8259. #endif /* NETDLL */
  8260. #ifdef SUPERLAT
  8261.               (nettype != NET_SLAT) &&
  8262. #endif /* SUPERLAT */
  8263.               (nettype != NET_SX25) &&
  8264.               (nettype != NET_VX25) &&
  8265. #ifdef IBMX25
  8266.               (nettype != NET_IX25) &&
  8267. #endif /* IBMX25 */
  8268. #ifdef SSHBUILTIN
  8269.               (nettype != NET_SSH) &&
  8270. #endif /* SSHBUILTIN */
  8271.               (nettype != NET_TCPB)) {
  8272.               printf("?Network type not supported\n");
  8273.               return(success = 0);
  8274.           } else {
  8275.               return(success = 1);
  8276.           }
  8277.       }
  8278.  
  8279. #ifndef NOTCPOPTS
  8280. #ifdef TCPSOCKET
  8281.       case XYTCP: {
  8282.         extern int ttyfd;
  8283.  
  8284.         if ((z = cmkey(tcpopt,ntcpopt,"TCP option","nodelay",xxstring)) < 0)
  8285.           return(z);
  8286.  
  8287.         switch (z) {
  8288. #ifndef NOHTTP
  8289.           case XYTCP_HTTP_PROXY:
  8290.             if ((y = cmtxt("hostname[:port] of HTTP proxy server",p,
  8291.                            &s,xxstring)) < 0)
  8292.               return(y);
  8293. #ifdef IKSDCONF
  8294.             if (iksdcf)
  8295.               return(success = 0);
  8296. #endif /* IKSDCONF */
  8297.             if (tcp_http_proxy) {
  8298.                 free(tcp_http_proxy);   /* Free any previous storage */
  8299.                 tcp_http_proxy = NULL;
  8300.             }
  8301.             if (s == NULL || *s == NUL) { /* If none given */
  8302.                 tcp_http_proxy = NULL;  /* remove the override string */
  8303.                 return(success = 1);
  8304.             } else if ((tcp_http_proxy = malloc(strlen(s)+1))) {
  8305.                 strcpy(tcp_http_proxy,s); /* (safe) Copy to new storage */
  8306.                 return(success = 1);
  8307.             } else
  8308.               return(success = 0);
  8309. #endif /* NOHTTP */
  8310. #ifdef NT
  8311. #ifdef CK_SOCKS
  8312.           case XYTCP_SOCKS_SVR: {
  8313.               char * p = getenv("SOCKS_SERVER");
  8314.               if (!p) p = "";
  8315.               if ((y = cmtxt("hostname or IP of SOCKS server",p,
  8316.                              &s,xxstring)) < 0)
  8317.                 return(y);
  8318. #ifdef IKSDCONF
  8319.               if (iksdcf) return(success = 0);
  8320. #endif /* IKSDCONF */
  8321.               if (tcp_socks_svr) {
  8322.                   free(tcp_socks_svr);  /* Free any previous storage */
  8323.                   tcp_socks_svr = NULL;
  8324.               }
  8325.               if (s == NULL || *s == NUL) { /* If none given */
  8326.                   tcp_socks_svr = NULL; /* remove the override string */
  8327.                   return(success = 1);
  8328.               } else if ((tcp_socks_svr = malloc(strlen(s)+1))) {
  8329.                   strcpy(tcp_socks_svr,s);
  8330.                   return(success = 1);
  8331.               } else
  8332.                 return(success = 0);
  8333.           }
  8334. #ifdef CK_SOCKS_NS
  8335.           case XYTCP_SOCKS_NS: {
  8336.             char * p = getenv("SOCKS_NS");
  8337.             if (!p) p = "";
  8338.             if ((y = cmtxt("hostname or IP of SOCKS Name Server",p,
  8339.                             &s,xxstring)) < 0)
  8340.                 return(y);
  8341. #ifdef IKSDCONF
  8342.               if (iksdcf) return(success = 0);
  8343. #endif /* IKSDCONF */
  8344.               if (tcp_socks_ns) {
  8345.                   free(tcp_socks_ns);   /* Free any previous storage */
  8346.                   tcp_socks_ns = NULL;
  8347.               }
  8348.               if (s == NULL || *s == NUL) { /* If none given */
  8349.                   tcp_socks_ns = NULL;  /* remove the override string */
  8350.                   return(success = 1);
  8351.               } else if ((tcp_socks_ns = malloc(strlen(s)+1))) {
  8352.                   strcpy(tcp_socks_ns,s);
  8353.                   return(success = 1);
  8354.               } else
  8355.                 return(success = 0);
  8356.           }
  8357. #endif /* CK_SOCKS_NS */
  8358. #endif /* CK_SOCKS */
  8359. #endif /* NT */
  8360.           case XYTCP_ADDRESS:
  8361.             if ((y = cmtxt("preferred IP Address for TCP connections","",
  8362.                            &s,xxstring)) < 0)
  8363.               return(y);
  8364. #ifdef IKSDCONF
  8365.             if (iksdcf) return(success = 0);
  8366. #endif /* IKSDCONF */
  8367.             if (tcp_address) {
  8368.                 free(tcp_address);      /* Free any previous storage */
  8369.                 tcp_address = NULL;
  8370.             }
  8371.             if (s == NULL || *s == NUL) { /* If none given */
  8372.                 tcp_address = NULL;     /* remove the override string */
  8373.                 return(success = 1);
  8374.             } else if ((tcp_address = malloc(strlen(s)+1))) {
  8375.                 strcpy(tcp_address,s);
  8376.                 return(success = 1);
  8377.             } else
  8378.               return(success = 0);
  8379. #ifdef SO_KEEPALIVE
  8380.           case XYTCP_KEEPALIVE:
  8381.             if ((z = cmkey(onoff,2,"","on",xxstring)) < 0) return(z);
  8382.             if ((y = cmcfm()) < 0) return(y);
  8383. #ifdef IKSDCONF
  8384.             if (iksdcf) return(success = 0);
  8385. #endif /* IKSDCONF */
  8386.             success = keepalive(ttyfd,z);
  8387.             return(success);
  8388. #endif /* SO_KEEPALIVE */
  8389. #ifdef SO_DONTROUTE
  8390.           case XYTCP_DONTROUTE:
  8391.             if ((z = cmkey(onoff,2,"","off",xxstring)) < 0) return(z);
  8392.             if ((y = cmcfm()) < 0) return(y);
  8393. #ifdef IKSDCONF
  8394.             if (iksdcf) return(success = 0);
  8395. #endif /* IKSDCONF */
  8396.             success = dontroute(ttyfd,z);
  8397.             return(success);
  8398. #endif /* SO_DONTROUTE */
  8399. #ifdef TCP_NODELAY
  8400.           case XYTCP_NODELAY:
  8401.             if ((z = cmkey(onoff,2,"","off",xxstring)) < 0) return(z);
  8402.             if ((y = cmcfm()) < 0) return(y);
  8403. #ifdef IKSDCONF
  8404.             if (iksdcf) return(success = 0);
  8405. #endif /* IKSDCONF */
  8406.             success = no_delay(ttyfd,z);
  8407.             return(success);
  8408.           case XYTCP_NAGLE:             /* The inverse of NODELAY */
  8409.             if ((z = cmkey(onoff,2,"","on",xxstring)) < 0) return(z);
  8410.             if ((y = cmcfm()) < 0) return(y);
  8411. #ifdef IKSDCONF
  8412.             if (iksdcf) return(success = 0);
  8413. #endif /* IKSDCONF */
  8414.             success = no_delay(ttyfd,!z);
  8415.             return(success);
  8416. #endif /* TCP_NODELAY */
  8417. #ifdef SO_LINGER
  8418.           case XYTCP_LINGER:
  8419.             if ((z = cmkey(onoff,2,"","on",xxstring)) < 0)
  8420.               return(z);
  8421.             if (z) {                    /* if on, we need a timeout value */
  8422.                 if ((x = cmnum("Linger timeout in 10th of a millisecond",
  8423.                                "0",10,&y,xxstring)) < 0)
  8424.                   return(x);
  8425.             } else
  8426.               y = 0;
  8427.             if ((x = cmcfm()) < 0)
  8428.               return(x);
  8429. #ifdef IKSDCONF
  8430.             if (iksdcf) return(success = 0);
  8431. #endif /* IKSDCONF */
  8432.             success = ck_linger(ttyfd,z,y);
  8433.             return(success);
  8434. #endif /* SO_LINGER */
  8435. #ifdef SO_SNDBUF
  8436.           case XYTCP_SENDBUF:
  8437.             x = cmnum("Send buffer size, bytes","8192",10,&z,xxstring);
  8438.             if (x < 0) return(x);
  8439.             if ((x = cmcfm()) < 0) return(x);
  8440. #ifdef IKSDCONF
  8441.             if (iksdcf) return(success = 0);
  8442. #endif /* IKSDCONF */
  8443.             success = sendbuf(ttyfd,z);
  8444.             return(success);
  8445. #endif /* SO_SNDBUF */
  8446. #ifdef SO_RCVBUF
  8447.           case XYTCP_RECVBUF:
  8448.             x = cmnum("Receive buffer size, bytes","8192",10,&z,xxstring);
  8449.             if (x < 0) return(x);
  8450.             if ((x = cmcfm()) < 0) return(x);
  8451. #ifdef IKSDCONF
  8452.             if (iksdcf) return(success = 0);
  8453. #endif /* IKSDCONF */
  8454.  
  8455. /* Note: The following is not 16-bit safe */
  8456.  
  8457. #ifndef QNX16
  8458.             if (x > 52248) {
  8459.                 printf("?Warning: receive buffers larger than 52248 bytes\n");
  8460.                 printf(" may not be understood by all hosts.  Performance\n");
  8461.                 printf(" may suffer.\n");
  8462.                 return(-9);
  8463.             }
  8464. #endif /* QNX16 */
  8465.             success = recvbuf(ttyfd,z);
  8466.             return(success);
  8467. #endif /* SO_RCVBUF */
  8468.  
  8469. #ifdef VMS
  8470. #ifdef DEC_TCPIP
  8471.           case XYTCP_UCX: {             /* UCX 2.0 port swabbing bug */
  8472.               extern int ucx_port_bug;
  8473.               return(success = seton(&ucx_port_bug));
  8474.           }
  8475. #endif /* DEC_TCPIP */
  8476. #endif /* VMS */
  8477.  
  8478.           case XYTCP_RDNS: {
  8479.               extern int tcp_rdns;
  8480.               return(success = setonaut(&tcp_rdns));
  8481.           }
  8482.  
  8483. #ifdef CK_DNS_SRV
  8484.           case XYTCP_DNS_SRV: {
  8485.               extern int tcp_dns_srv;
  8486.               return(success = seton(&tcp_dns_srv));
  8487.           }
  8488. #endif /* CK_DNS_SRV */
  8489.  
  8490.           default:
  8491.             return(0);
  8492.         }
  8493.       }
  8494. #endif /* TCPSOCKET */
  8495. #endif /* NOTCPOPTS */
  8496. #endif /* NETCONN */
  8497.     }
  8498.  
  8499.     switch (xx) {
  8500.  
  8501. #ifndef NOLOCAL
  8502. #ifdef NETCONN
  8503.       case XYHOST: {                    /* SET HOST */
  8504.           z = ttnproto;                 /* Save protocol in case of failure */
  8505. #ifdef DECNET
  8506.           if (nettype != NET_DEC)
  8507. #endif /* DECNET */
  8508.             ttnproto = NP_NONE;
  8509.           if ((y = setlin(XYHOST,1,0)) < 0) {
  8510.               debug(F101,"SET HOST fail mdmtyp","",mdmtyp);
  8511.               ttnproto = z;             /* Failed, restore protocol */
  8512.               success = 0;
  8513.           }
  8514.           didsetlin++;
  8515.           debug(F101,"SET HOST OK mdmtyp","",mdmtyp);
  8516.           debug(F101,"SET HOST reliable","",reliable);
  8517.           return(y);
  8518.       }
  8519. #endif /* NETCONN */
  8520.  
  8521.       case XYLINE:                      /* SET LINE (= SET PORT) */
  8522.         debug(F101,"setlin flow 1","",flow);
  8523.         x = setlin(xx,1,0);
  8524.         if (x > -1) didsetlin++;
  8525.         debug(F101,"SET LINE setlin","",x);
  8526.         debug(F101,"SET LINE flow","",flow);
  8527.         debug(F101,"SET LINE local","",local);
  8528.         debug(F101,"SET LINE reliable","",reliable);
  8529.         return(x);
  8530. #endif /* NOLOCAL */
  8531.  
  8532. #ifndef NOSETKEY
  8533.       case XYKEY:                       /* SET KEY */
  8534.         return(dosetkey());
  8535. #endif /* NOSETKEY */
  8536.  
  8537. #ifndef NOCSETS
  8538.       case XYLANG:                      /* Language */
  8539.         if ((y = cmkey(lngtab,nlng,"","none",xxstring)) < 0)
  8540.           return(y);
  8541.         if ((x = cmcfm()) < 0) return(x);
  8542.  
  8543.         /* Look up language and get associated character sets */
  8544.         for (i = 0; (i < nlangs) && (langs[i].id != y); i++) ;
  8545.         if (i >= nlangs) {
  8546.             printf("?internal error, sorry\n");
  8547.             return(success = 0);
  8548.         } /*  */
  8549.         language = i;                   /* All good, set the language, */
  8550.         return(success = 1);
  8551. #endif /* NOCSETS */
  8552.  
  8553. #ifndef MAC
  8554.       case XYBACK:                      /* BACKGROUND */
  8555.         if ((z = cmkey(onoff,2,"","",xxstring)) < 0) return(z);
  8556.         if ((y = cmcfm()) < 0) return(y);
  8557. #ifdef COMMENT
  8558.         bgset = z;                      /* 0 = off (foreground) */
  8559. #ifdef VMS                              /* 1 = on (background) */
  8560.         if (batch && bgset == 0)        /* To enable echoing of commands */
  8561.           ckxech = 1;                   /* in VMS batch logs */
  8562. #endif /* VMS */
  8563. #else  /* COMMENT */
  8564.         if (z) {                        /* 1 = Background */
  8565.             bgset = 1;
  8566.             backgrd = 1;
  8567. #ifdef VMS
  8568.             batch = 1;
  8569. #endif /* VMS */
  8570.         } else {                        /* 0 = Foreground */
  8571.             bgset = 0;
  8572.             backgrd = 0;
  8573. #ifdef VMS
  8574.             batch = 0;
  8575. #endif /* VMS */
  8576.         }
  8577. #endif /* COMMENT */
  8578.         success = 1;
  8579.         bgchk();
  8580.         return(success);
  8581. #endif /* MAC */
  8582.  
  8583.       case XYQUIE: {                    /* QUIET */
  8584. #ifdef DCMDBUF
  8585.           extern int * xquiet;
  8586. #else
  8587.           extern int xquiet[];
  8588. #endif /* DCMDBUF */
  8589.           x = seton(&quiet);
  8590.           if (x < 0) return(x);
  8591.           xquiet[cmdlvl] = quiet;
  8592.           return(success = x);
  8593.       }
  8594.  
  8595. #ifndef NOXFER
  8596.       case XYBUF: {                     /* BUFFERS */
  8597. #ifdef DYNAMIC
  8598.           int sb, rb;
  8599.           if ((y = cmnum("Send buffer size","",10,&sb,xxstring)) < 0) {
  8600.               if (y == -3) printf("?Buffer size required\n");
  8601.               return(y);
  8602.           }
  8603.           if (sb < 0) {
  8604.               if (*atmbuf == '-')
  8605.                 printf("?Negative numbers can't be used here\n");
  8606.               else printf("?Integer overflow, use a smaller number please\n");
  8607.               return(-9);
  8608.           } else if (sb < 80) {
  8609.               printf("?Too small\n");
  8610.               return(-9);
  8611.           }
  8612.           if ((y=cmnum("Receive buffer size",ckitoa(sb),10,&rb,xxstring)) < 0)
  8613.             return(y);
  8614.           if (rb < 0) {
  8615.               if (*atmbuf == '-')
  8616.                 printf("?Negative numbers can't be used here\n");
  8617.               else printf("?Integer overflow, use a smaller number please\n");
  8618.               return(-9);
  8619.           } else if (rb < 80) {
  8620.               printf("?Too small\n");
  8621.               return(-9);
  8622.           }
  8623.           if ((y = cmcfm()) < 0) return(y);
  8624.           if ((y = inibufs(sb,rb)) < 0) return(y);
  8625.           y = adjpkl(urpsiz,wslotr,bigrbsiz); /* Maybe adjust packet sizes */
  8626.           if (y != urpsiz) urpsiz = y;
  8627.           y = adjpkl(spsiz,wslotr,bigsbsiz);
  8628.           if (y != spsiz) spsiz = spmax = spsizr = y;
  8629.           return(success = 1);
  8630. #else
  8631.           printf("?Sorry, not available\n");
  8632.           return(success = 0);
  8633. #endif /* DYNAMIC */
  8634.       }
  8635.  
  8636.       case XYCHKT:                      /* BLOCK-CHECK */
  8637.         if ((x = cmkey(chktab,4,"","3",xxstring)) < 0) return(x);
  8638.         if ((y = cmcfm()) < 0) return(y);
  8639.         bctr = x;                       /* Set local too even if REMOTE SET */
  8640.         if (rmsflg) {
  8641.             if (x == 4) {
  8642.                 tmpbuf[0] = 'B';
  8643.                 tmpbuf[1] = '\0';
  8644.             } else
  8645.               ckstrncpy(tmpbuf,ckitoa(x),TMPBUFSIZ);
  8646.             sstate = setgen('S', "400", tmpbuf, "");
  8647.             return((int) sstate);
  8648.         } else {
  8649.             return(success = 1);
  8650.         }
  8651. #endif /* NOXFER */
  8652.  
  8653. #ifndef NOLOCAL
  8654. #ifndef MAC                             /* The Mac has no RS-232 */
  8655. case XYCARR:                            /* CARRIER-WATCH */
  8656.         return(setdcd());
  8657. #endif /* MAC */
  8658. #endif /* NOLOCAL */
  8659.     }
  8660.  
  8661. #ifdef TNCODE
  8662.     switch (xx) {                       /* Avoid long switch statements... */
  8663.       case XYTELOP: {
  8664.           int c, n;                     /* Workers */
  8665.           int getval = 0;               /* Whether to get switch value */
  8666.           int tnserver = 0;             /* Client by default */
  8667.           int opt = -1;                 /* Telnet Option */
  8668.           struct FDB sw, op;            /* FDBs for each parse function */
  8669. #ifdef CK_AUTHENTICATION
  8670.           extern int sl_topt_a_s_saved;
  8671.           extern int sl_topt_a_c_saved;
  8672.           extern int sl_topt_e_s_saved;
  8673.           extern int sl_topt_e_c_saved;
  8674. #endif /* CK_AUTHENTICATION */
  8675. #ifdef IKSD
  8676.           if (inserver)                 /* Server by default when IKSD */
  8677.             tnserver = 1;
  8678. #endif /* IKSD */
  8679.  
  8680.           /* Set up chained parse functions... */
  8681.  
  8682.           cmfdbi(&op,                   /* First fdb - telopts*/
  8683.                  _CMKEY,                /* fcode */
  8684.                  "/client, /server or", /* hlpmsg */
  8685.                  "",                    /* default */
  8686.                  "",                    /* addtl string data */
  8687.                  ntnopt,                /* addtl numeric data 1 */
  8688.                  0,                     /* addtl numeric data 2 */
  8689.                  xxstring,
  8690.                  tnopttab,
  8691.                  &sw
  8692.                  );
  8693.           cmfdbi(&sw,                   /* Second FDB - command switches */
  8694.                  _CMKEY,                /* fcode */
  8695.                  "",                    /* hlpmsg */
  8696.                  "",                    /* default */
  8697.                  "",                    /* addtl string data */
  8698.                  ntnoptsw,              /* addtl numeric data 1: tbl size */
  8699.                  4,                     /* addtl numeric data 2: 4 = cmswi */
  8700.                  xxstring,              /* Processing function */
  8701.                  tnoptsw,               /* Keyword table */
  8702.                  NULL                   /* Pointer to next FDB */
  8703.                  );
  8704.  
  8705.           while (opt < 0) {             /* Parse 0 or more switches */
  8706.               x = cmfdb(&op);           /* Parse switch or other thing */
  8707.               debug(F101,"XYTELOP cmfdb","",x);
  8708.               if (x < 0)                /* Error */
  8709.                 return(x);              /* or reparse needed */
  8710.               if (cmresult.fcode != _CMKEY) /* Break out if not a switch */
  8711.                 break;
  8712.               c = cmgbrk();             /* Get break character */
  8713.               getval = (c == ':' || c == '='); /* see how switch ended */
  8714.               if (getval && !(cmresult.kflags & CM_ARG)) {
  8715.                   printf("?This switch does not take arguments\n");
  8716.                   return(-9);
  8717.               }
  8718.               z = cmresult.nresult;     /* Numeric result = switch value */
  8719.               debug(F101,"XYTELOP switch","",z);
  8720.  
  8721.               switch (z) {              /* Process the switch */
  8722.                 case CK_TN_CLIENT:
  8723.                   tnserver = 0;
  8724.                   break;
  8725.                 case CK_TN_SERVER:
  8726.                   tnserver = 1;
  8727.                     break;
  8728.                 case CK_TN_EC:
  8729.                   opt = TELOPT_ECHO;
  8730.                   break;
  8731.                 case CK_TN_TT:
  8732.                   opt = TELOPT_TTYPE;
  8733.                   break;
  8734.                 case CK_TN_BM:
  8735.                   opt = TELOPT_BINARY;
  8736.                   break;
  8737.                 case CK_TN_ENV:
  8738.                   opt = TELOPT_NEWENVIRON;
  8739.                   break;
  8740.                 case CK_TN_LOC:
  8741.                   opt = TELOPT_SNDLOC;
  8742.                   break;
  8743.                 case CK_TN_AU:
  8744.                   opt = TELOPT_AUTHENTICATION;
  8745.                   break;
  8746.                 case CK_TN_FX:
  8747.                   opt = TELOPT_FORWARD_X;
  8748.                   break;
  8749.                 case CK_TN_ENC:
  8750.                   opt = TELOPT_ENCRYPTION;
  8751.                   break;
  8752.                 case CK_TN_IKS:
  8753.                   opt = TELOPT_KERMIT;
  8754.                   break;
  8755.                 case CK_TN_TLS:
  8756.                   opt = TELOPT_START_TLS;
  8757.                   break;
  8758.                 case CK_TN_XD:
  8759.                   opt = TELOPT_XDISPLOC;
  8760.                   break;
  8761.                 case CK_TN_NAWS:
  8762.                   opt = TELOPT_NAWS;
  8763.                   break;
  8764.                 case CK_TN_SGA:
  8765.                   opt = TELOPT_SGA;
  8766.                   break;
  8767.                 case CK_TN_PHR:
  8768.                   opt = TELOPT_PRAGMA_HEARTBEAT;
  8769.                   break;
  8770.                 case CK_TN_PSP:
  8771.                   opt = TELOPT_SSPI_LOGON;
  8772.                   break;
  8773.                 case CK_TN_PLG:
  8774.                   opt = TELOPT_PRAGMA_LOGON;
  8775.                   break;
  8776.                 case CK_TN_SAK:
  8777.                   opt = TELOPT_IBM_SAK;
  8778.                   break;
  8779.                 case CK_TN_CPC:
  8780.                   opt = TELOPT_COMPORT;
  8781.                   break;
  8782.                 case CK_TN_LOG:
  8783.                   opt = TELOPT_LOGOUT;
  8784.                   break;
  8785.                 case CK_TN_FLW:
  8786.                   opt = TELOPT_LFLOW;
  8787.                   break;
  8788.                 default:
  8789.                   printf("?Unexpected value - %d\n",z);
  8790.                   return(-9);
  8791.               }
  8792. #ifdef COMMENT
  8793.               if (cmresult.fdbaddr == &op)
  8794.                 break;
  8795. #endif /* COMMENT */
  8796.           }
  8797.           switch (opt) {
  8798.             case TELOPT_ECHO:           /* Options only the Server WILL */
  8799.             case TELOPT_FORWARD_X:
  8800.             case TELOPT_SEND_URL:
  8801.             case TELOPT_IBM_SAK:
  8802.             case TELOPT_LOGOUT:
  8803.               if ((x = cmkey(tnnegtab,
  8804.                              ntnnegtab,
  8805.                              "desired server state",
  8806.    TELOPT_MODE(tnserver?TELOPT_DEF_S_ME_MODE(opt):TELOPT_DEF_C_U_MODE(opt)),
  8807.                              xxstring)
  8808.                    ) < 0)
  8809.                 return(x);
  8810.               if ((z = cmcfm()) < 0)
  8811.                   return(z);
  8812.               if (tnserver) {
  8813.                   TELOPT_DEF_S_ME_MODE(opt) = x;
  8814.                   TELOPT_ME_MODE(opt) = x;
  8815.               } else {
  8816.                   TELOPT_DEF_C_U_MODE(opt) = x;
  8817.                   TELOPT_U_MODE(opt) = x;
  8818.               }
  8819.               break;
  8820.  
  8821.             case TELOPT_TTYPE:          /* Options only the Client WILL */
  8822.             case TELOPT_NEWENVIRON:
  8823.             case TELOPT_SNDLOC:
  8824.             case TELOPT_AUTHENTICATION:
  8825.             case TELOPT_START_TLS:
  8826.             case TELOPT_XDISPLOC:
  8827.             case TELOPT_NAWS:
  8828.             case TELOPT_LFLOW:
  8829.             case TELOPT_COMPORT:
  8830.               if ((x = cmkey(tnnegtab,
  8831.                              ntnnegtab,
  8832.                              "desired client state",
  8833.     TELOPT_MODE(!tnserver?TELOPT_DEF_S_U_MODE(opt):TELOPT_DEF_C_ME_MODE(opt)),
  8834.                              xxstring)
  8835.                    ) < 0)
  8836.                 return(x);
  8837.               if ((z = cmcfm()) < 0)
  8838.                 return(z);
  8839.               if (tnserver) {
  8840.                   TELOPT_DEF_S_U_MODE(opt) = x;
  8841.                   TELOPT_U_MODE(opt) = x;
  8842. #ifdef CK_AUTHENTICATION
  8843.                   if (opt == TELOPT_AUTHENTICATION)
  8844.                     sl_topt_a_s_saved = 0;
  8845. #endif /* CK_AUTHENTICATION */
  8846.               } else {
  8847.                   TELOPT_DEF_C_ME_MODE(opt) = x;
  8848.                   TELOPT_ME_MODE(opt) = x;
  8849. #ifdef CK_AUTHENTICATION
  8850.                   if (opt == TELOPT_AUTHENTICATION)
  8851.                     sl_topt_a_c_saved = 0;
  8852. #endif /* CK_AUTHENTICATION */
  8853.               }
  8854.               break;
  8855.  
  8856.             default:
  8857.               if ((x = cmkey(tnnegtab,
  8858.                              ntnnegtab,
  8859.                              tnserver ?
  8860.                              "desired server state" :
  8861.                              "desired client state",
  8862.     TELOPT_MODE(tnserver?TELOPT_DEF_S_ME_MODE(opt):TELOPT_DEF_C_ME_MODE(opt)),
  8863.                              xxstring
  8864.                              )
  8865.                    ) < 0)
  8866.                 return(x);
  8867.               if ((y = cmkey(tnnegtab,
  8868.                              ntnnegtab,
  8869.                              !tnserver ? "desired server state" :
  8870.                              "desired client state",
  8871.     TELOPT_MODE(!tnserver?TELOPT_DEF_S_U_MODE(opt):TELOPT_DEF_C_U_MODE(opt)),
  8872.                              xxstring
  8873.                              )
  8874.                    ) < 0)
  8875.                 return(y);
  8876.               if ((z = cmcfm()) < 0)
  8877.                 return(z);
  8878.               if (tnserver) {
  8879.                   TELOPT_DEF_S_ME_MODE(opt) = x;
  8880.                   TELOPT_ME_MODE(opt) = x;
  8881.                   TELOPT_DEF_S_U_MODE(opt) = y;
  8882.                   TELOPT_U_MODE(opt) = y;
  8883. #ifdef CK_ENCRYPTION
  8884.                   if (opt == TELOPT_ENCRYPTION)
  8885.                     sl_topt_e_s_saved = 0;
  8886. #endif /* CK_ENCRYPTION */
  8887.               } else {
  8888.                   TELOPT_DEF_C_ME_MODE(opt) = x;
  8889.                   TELOPT_ME_MODE(opt) = x;
  8890.                   TELOPT_DEF_C_U_MODE(opt) = y;
  8891.                   TELOPT_U_MODE(opt) = y;
  8892. #ifdef CK_ENCRYPTION
  8893.                   if (opt == TELOPT_ENCRYPTION)
  8894.                     sl_topt_e_c_saved = 0;
  8895. #endif /* CK_ENCRYPTION */
  8896.               }
  8897.           }
  8898.           return(success = 1);
  8899.       }
  8900.  
  8901.       case XYTEL:                       /* TELNET */
  8902.         if ((z = cmkey(tntab,ntn,"parameter for TELNET negotiations", "",
  8903.                        xxstring)) < 0)
  8904.           return(z);
  8905.         switch (z) {
  8906.           case CK_TN_EC:                /* ECHO */
  8907.             if ((x = cmkey(rltab,nrlt,
  8908.                            "initial TELNET echoing state",
  8909.                            "local",xxstring)) < 0)
  8910.               return(x);
  8911.             if ((y = cmcfm()) < 0) return(y);
  8912.             tn_duplex = x;
  8913.             return(success = 1);
  8914.  
  8915.           case CK_TN_RE:                /* REMOTE-ECHO */
  8916.             return(success = seton(&tn_rem_echo));
  8917.  
  8918.           case CK_TN_DB:                /* DEBUG */
  8919.             return(success = seton(&tn_deb));
  8920.  
  8921.           case CK_TN_TT:                /* TERMINAL TYPE */
  8922.             if ((y = cmtxt("terminal type for TELNET connections","",
  8923.                            &s,xxstring)) < 0)
  8924.               return(y);
  8925.             if (tn_term) {
  8926.                 free(tn_term);          /* Free any previous storage */
  8927.                 tn_term = NULL;
  8928.             }
  8929.             if (s == NULL || *s == NUL) { /* If none given */
  8930.                 tn_term = NULL;         /* remove the override string */
  8931.                 return(success = 1);
  8932.             } else if ((tn_term = malloc(strlen(s)+1))) {
  8933.                 strcpy(tn_term,s);
  8934.                 return(success = 1);
  8935.             } else return(success = 0);
  8936.  
  8937. #ifdef CK_FORWARD_X
  8938.           case CK_TN_FX:                /* FORWARD-X */
  8939.             if ((x=cmkey(tnfwdxtab,ntnfwdx,"","xauthority-file",xxstring)) < 0)
  8940.               return(x);
  8941.             switch (x) {
  8942.               case 0: {                 /* Xauthority-File */
  8943.                   x = cmifi("Full path of .Xauthority file","",&s,&y,xxstring);
  8944.                   if (x < 0 && x != -3)
  8945.                     return(x);
  8946.                   makestr(&tn_fwdx_xauthority,s);
  8947.                   return(success = 1);
  8948.               }
  8949.               case 1: {                 /* No-Encryption */
  8950.                   extern int fwdx_no_encrypt;
  8951.                   return(success = seton(&fwdx_no_encrypt));
  8952.               }
  8953.             }
  8954.             return(success = 0);
  8955. #endif /* CK_FORWARD_X */
  8956.  
  8957.           case CK_TN_NL:                /* TELNET NEWLINE-MODE */
  8958.             if ((x = cmkey(tn_nlmtab,ntn_nlm,"","nvt",xxstring)) < 0)
  8959.               return(x);
  8960.             if (x == TN_NL_BIN) {
  8961.               if ((x = cmkey(tnlmtab,ntnlm,"","raw",xxstring)) < 0)
  8962.                 return(x);
  8963.               if ((y = cmcfm()) < 0)
  8964.                 return(y);
  8965.               tn_b_nlm = x;
  8966.               return(success = 1);
  8967.           } else if (x == TN_NL_NVT) {
  8968.               if ((x = cmkey(tnlmtab,ntnlm,"","on",xxstring)) < 0)
  8969.                 return(x);
  8970.               if ((y = cmcfm()) < 0)
  8971.                 return(y);
  8972.               tn_nlm = x;
  8973.               return(success = 1);
  8974.           } else {
  8975.               if ((y = cmcfm()) < 0)
  8976.                 return(y);
  8977.               tn_nlm = x;
  8978.               return(success = 1);
  8979.           }
  8980.  
  8981.         case CK_TN_XF:                  /* BINARY-TRANSFER-MODE */
  8982.             if ((z = cmkey(onoff,2,"","on",xxstring)) < 0) return(z);
  8983.             if ((y = cmcfm()) < 0) return(y);
  8984.             tn_b_xfer = z;
  8985.             return(success = 1);
  8986.  
  8987.         case CK_TN_NE:                  /* NO-ENCRYPT-DURING-XFER */
  8988.             if ((z = cmkey(onoff,2,"","on",xxstring)) < 0) return(z);
  8989.             if ((y = cmcfm()) < 0) return(y);
  8990. #ifdef CK_APC
  8991.             /* Don't let this be set remotely */
  8992.             if (apcactive == APC_LOCAL ||
  8993.                 (apcactive == APC_REMOTE && !(apcstatus & APC_UNCH)))
  8994.               return(success = 0);
  8995. #endif /* CK_APC */
  8996.             tn_no_encrypt_xfer = z;
  8997.             return(success = 1);
  8998.  
  8999.           case CK_TN_BM:                /* BINARY-MODE */
  9000.             if ((x = cmkey(tnnegtab,ntnnegtab,"","refused",xxstring)) < 0)
  9001.               return(x);
  9002.             if ((y = cmcfm()) < 0)
  9003.               return(y);
  9004.             TELOPT_DEF_S_ME_MODE(TELOPT_BINARY) = x;
  9005.             TELOPT_DEF_S_U_MODE(TELOPT_BINARY) = x;
  9006.             TELOPT_DEF_C_ME_MODE(TELOPT_BINARY) = x;
  9007.             TELOPT_DEF_C_U_MODE(TELOPT_BINARY) = x;
  9008.             return(success = 1);
  9009.  
  9010. #ifdef IKS_OPTION
  9011.           case CK_TN_IKS:               /* KERMIT */
  9012.             if ((x = cmkey(tnnegtab,ntnnegtab,"DO","accept",xxstring)) < 0)
  9013.               return(x);
  9014.             if ((y = cmkey(tnnegtab,ntnnegtab,"WILL","accept",xxstring)) < 0)
  9015.               return(y);
  9016.             if ((z = cmcfm()) < 0)
  9017.               return(z);
  9018.             TELOPT_DEF_S_ME_MODE(TELOPT_KERMIT) = y;
  9019.             TELOPT_DEF_S_U_MODE(TELOPT_KERMIT) = x;
  9020.             TELOPT_DEF_C_ME_MODE(TELOPT_KERMIT) = y;
  9021.             TELOPT_DEF_C_U_MODE(TELOPT_KERMIT) = x;
  9022.             return(success = 1);
  9023. #endif /* IKS_OPTION */
  9024.  
  9025. #ifdef CK_SSL
  9026.           case CK_TN_TLS:               /* START_TLS */
  9027.             if ((x = cmkey(tnnegtab,ntnnegtab,"me","accept",xxstring)) < 0)
  9028.               return(x);
  9029.             if ((y = cmkey(tnnegtab,ntnnegtab,"u","accept",xxstring)) < 0)
  9030.               return(y);
  9031.             if ((z = cmcfm()) < 0)
  9032.               return(z);
  9033.             TELOPT_DEF_S_ME_MODE(TELOPT_START_TLS) = x;
  9034.             TELOPT_DEF_S_U_MODE(TELOPT_START_TLS) = y;
  9035.             TELOPT_DEF_C_ME_MODE(TELOPT_START_TLS) = x;
  9036.             TELOPT_DEF_C_U_MODE(TELOPT_START_TLS) = y;
  9037.             return(success = 1);
  9038. #endif /* CK_SSL */
  9039.  
  9040. #ifdef CK_NAWS
  9041.           case CK_TN_NAWS:              /* NAWS */
  9042.             if ((x = cmkey(tnnegtab,ntnnegtab,"me","accept",xxstring)) < 0)
  9043.               return(x);
  9044.             if ((y = cmkey(tnnegtab,ntnnegtab,"u","accept",xxstring)) < 0)
  9045.               return(y);
  9046.             if ((z = cmcfm()) < 0)
  9047.               return(z);
  9048.             TELOPT_DEF_S_ME_MODE(TELOPT_NAWS) = x;
  9049.             TELOPT_DEF_S_U_MODE(TELOPT_NAWS) = y;
  9050.             TELOPT_DEF_C_ME_MODE(TELOPT_NAWS) = x;
  9051.             TELOPT_DEF_C_U_MODE(TELOPT_NAWS) = y;
  9052.             return(success = 1);
  9053. #endif /* CK_NAWS */
  9054.  
  9055. #ifdef CK_AUTHENTICATION
  9056.           case CK_TN_AU:                /* AUTHENTICATION */
  9057.             if ((x = cmkey(tnauthtab,ntnauth,"","",xxstring)) < 0)
  9058.               return(x);
  9059.             if (x == TN_AU_FWD) {
  9060.                 extern int forward_flag;
  9061.                 return(success = seton(&forward_flag));
  9062.             } else if (x == TN_AU_TYP) {
  9063.                 extern int auth_type_user[];
  9064.                 extern int sl_auth_type_user[];
  9065.                 extern int sl_auth_saved;
  9066.                 int i, j, atypes[AUTHTYPLSTSZ];
  9067.  
  9068.                 for (i = 0; i < AUTHTYPLSTSZ; i++) {
  9069.                     if ((y = cmkey(autyptab,nautyp,"",
  9070.                                    i == 0 ? "automatic" : "" ,
  9071.                                    xxstring)) < 0) {
  9072.                         if (y == -3)
  9073.                           break;
  9074.                         return(y);
  9075.                     }
  9076.                     if (i > 0 && (y == AUTHTYPE_AUTO || y == AUTHTYPE_NULL)) {
  9077.                         printf(
  9078.                         "\r\n?Choice may only be used in first position.\r\n");
  9079.                         return(-9);
  9080.                     }
  9081.                     for (j = 0; j < i; j++) {
  9082.                         if (atypes[j] == y) {
  9083.                             printf("\r\n?Choice has already been used.\r\n");
  9084.                             return(-9);
  9085.                         }
  9086.                     }
  9087.                     atypes[i] = y;
  9088.                     if (y == AUTHTYPE_NULL || y == AUTHTYPE_AUTO) {
  9089.                         i++;
  9090.                         break;
  9091.                     }
  9092.                 }
  9093.                 if (i < AUTHTYPLSTSZ)
  9094.                   atypes[i] = AUTHTYPE_NULL;
  9095.                 if ((z = cmcfm()) < 0)
  9096.                   return(z);
  9097.                 sl_auth_saved = 0;
  9098.                 for (i = 0; i < AUTHTYPLSTSZ; i++) {
  9099.                     auth_type_user[i] = atypes[i];
  9100.                     sl_auth_type_user[i] = 0;
  9101.                 }
  9102.             } else if (x == TN_AU_HOW) {
  9103.                 if ((y = cmkey(auhowtab,nauhow,"","any",xxstring)) < 0)
  9104.                   return(y);
  9105.                 if ((z = cmcfm()) < 0)
  9106.                   return(z);
  9107.                 tn_auth_how = y;
  9108.             } else if (x == TN_AU_ENC) {
  9109.                 if ((y = cmkey(auenctab,nauenc,"","encrypt",xxstring)) < 0)
  9110.                   return(y);
  9111.                 if ((z = cmcfm()) < 0)
  9112.                   return(z);
  9113.                 tn_auth_enc = y;
  9114.             } else {
  9115.                 if ((y = cmcfm()) < 0)
  9116.                   return(y);
  9117.                 TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = x;
  9118.                 TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = x;
  9119.             }
  9120.             return(success = 1);
  9121. #endif /* CK_AUTHENTICATION */
  9122.  
  9123. #ifdef CK_ENCRYPTION
  9124.           case CK_TN_ENC: {             /* ENCRYPTION */
  9125.               int c, tmp = -1;
  9126.               int getval = 0;
  9127.               static struct keytab * tnetbl = NULL;
  9128.               static int ntnetbl = 0;
  9129.  
  9130.               if ((y = cmkey(tnenctab,ntnenc,"","",xxstring)) < 0)
  9131.                 return(y);
  9132.               switch (y) {
  9133.                 case TN_EN_TYP:
  9134.                   x = ck_get_crypt_table(&tnetbl,&ntnetbl);
  9135.                   debug(F101,"ck_get_crypt_table x","",x);
  9136.                   debug(F101,"ck_get_crypt_table n","",ntnetbl);
  9137.                   if (x < 1 || !tnetbl || ntnetbl < 1) /* Didn't get it */
  9138.                     x = 0;
  9139.                   if (!x) {
  9140.                       printf("?Oops, types not loaded\n");
  9141.                       return(-9);
  9142.                   }
  9143.                   if ((x = cmkey(tnetbl,ntnetbl,"type of encryption",
  9144.                                  "automatic",xxstring)) < 0)
  9145.                     return(x);
  9146.                   if ((z = cmcfm()) < 0)
  9147.                     return(z);
  9148.                   cx_type = x;
  9149.                   sl_cx_type = 0;
  9150.                   break;
  9151.                 case TN_EN_START:
  9152.                   if ((z = cmcfm()) < 0)
  9153.                     return(z);
  9154. #ifdef CK_APC
  9155.                   /* Don't let this be set remotely */
  9156.                   if (apcactive == APC_LOCAL ||
  9157.                       apcactive == APC_REMOTE && !(apcstatus & APC_UNCH))
  9158.                     return(success = 0);
  9159. #endif /* CK_APC */
  9160.                   ck_tn_enc_start();
  9161.                   break;
  9162.                 case TN_EN_STOP:
  9163.                   if ((z = cmcfm()) < 0)
  9164.                     return(z);
  9165. #ifdef CK_APC
  9166.                   /* Don't let this be set remotely */
  9167.                   if (apcactive == APC_LOCAL ||
  9168.                       apcactive == APC_REMOTE && !(apcstatus & APC_UNCH))
  9169.                     return(success = 0);
  9170. #endif /* CK_APC */
  9171.                   ck_tn_enc_stop();
  9172.                   break;
  9173.                 default:
  9174.                   if ((z = cmcfm()) < 0)
  9175.                     return(z);
  9176.                   TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION) = y;
  9177.                   TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION) = y;
  9178.                   TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION) = y;
  9179.                   TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION) = y;
  9180.               }
  9181.               return(success = 1);
  9182.           }
  9183. #endif /* CK_ENCRYPTION */
  9184.  
  9185.           case CK_TN_BUG:               /* BUG */
  9186.             if ((x = cmkey(tnbugtab,4,"",
  9187.                            "binary-me-means-u-too",xxstring)) < 0)
  9188.               return(x);
  9189.             if ((z = cmkey(onoff,2,"","off",xxstring)) < 0) return(z);
  9190.             if ((y = cmcfm()) < 0) return(y);
  9191.             switch (x) {
  9192.               case 0:
  9193.                 tn_b_meu = z;
  9194.                 break;
  9195.               case 1:
  9196.                 tn_b_ume = z;
  9197.                 break;
  9198.               case 2:
  9199.                 tn_infinite = z;
  9200.                 break;
  9201.               case 3:
  9202.                 tn_sb_bug = z;
  9203.                 break;
  9204.             }
  9205.             return(success = 1);
  9206.  
  9207. #ifdef CK_ENVIRONMENT
  9208.           case CK_TN_XD:                /* XDISPLOC */
  9209.             if ((x = cmkey(tnnegtab,ntnnegtab,"me","accept",xxstring)) < 0)
  9210.               return(x);
  9211.             if ((y = cmkey(tnnegtab,ntnnegtab,"u","accept",xxstring)) < 0)
  9212.               return(y);
  9213.             if ((z = cmcfm()) < 0)
  9214.               return(z);
  9215.             TELOPT_DEF_S_ME_MODE(TELOPT_XDISPLOC) = x;
  9216.             TELOPT_DEF_S_U_MODE(TELOPT_XDISPLOC) = y;
  9217.             TELOPT_DEF_C_ME_MODE(TELOPT_XDISPLOC) = x;
  9218.             TELOPT_DEF_C_U_MODE(TELOPT_XDISPLOC) = y;
  9219.             return(success = 1);
  9220.  
  9221.           case CK_TN_ENV: {
  9222.               char * msg = "value of telnet environment variable";
  9223.               extern int tn_env_flg;
  9224.               extern char tn_env_acct[], tn_env_disp[], tn_env_job[],
  9225.               tn_env_prnt[], tn_env_sys[];
  9226.               extern char * tn_loc;
  9227.               if ((x = cmkey(tnenvtab,ntnenv,"","",xxstring)) < 0)
  9228.                 return(x);
  9229.               if (x == TN_ENV_UVAR) {   /* User variables */
  9230.                   char * uvar=NULL;
  9231.                   char * uval=NULL;
  9232.                   char * env;
  9233.                   extern char * tn_env_uservar[8][2];
  9234.  
  9235.                   /* Get the user variable name */
  9236.                   if ((x = cmfld("Name of Environment Variable","",&s,
  9237.                                  xxstring)) < 0)
  9238.                     return(x);
  9239.                   makestr(&uvar,s);
  9240.  
  9241.                   env = getenv(uvar);
  9242.                   if (!env) env = "";
  9243.  
  9244.                   if ((x = cmtxt("Value of Environment Variable",env,
  9245.                                  &s,xxstring)) < 0)
  9246.                     return(x);
  9247.                   if (*s)
  9248.                     makestr(&uval,s);
  9249.  
  9250.                   /* Now that we have the variable and perhaps a value */
  9251.                   /* there are three possibilities: (1) new variable   */
  9252.                   /* and associated value; (2) variable already exists */
  9253.                   /* but we have a new value; (3) variable already     */
  9254.                   /* exists but no new value therefore the user wants  */
  9255.                   /* to clear variable.                                */
  9256.  
  9257.                   /* Try to find an existing variable */
  9258.                   for (x = 0; x < 8; x++) {
  9259.                       if (!ckstrcmp(tn_env_uservar[x][0],uvar,-1,0)) {
  9260.                           if (uval) {
  9261.                               free(tn_env_uservar[x][1]);
  9262.                               tn_env_uservar[x][1] = uval;
  9263.                               free(uvar);
  9264.                               return(success = 1);
  9265.                           } else {
  9266.                               free(tn_env_uservar[x][0]);
  9267.                               tn_env_uservar[x][0] = NULL;
  9268.                               free(tn_env_uservar[x][1]);
  9269.                               tn_env_uservar[x][1] = NULL;
  9270.                               free(uvar);
  9271.                               return(success = 1);
  9272.                           }
  9273.                       }
  9274.                   }
  9275.  
  9276.                   /* Couldn't find one; look for empty location to insert */
  9277.                   for (x = 0; x < 8; x++) {
  9278.                       if (!tn_env_uservar[x][0]) {
  9279.                           tn_env_uservar[x][0] = uvar;
  9280.                           tn_env_uservar[x][1] = uval;
  9281.                           return(success = 1);
  9282.                       }
  9283.                   }
  9284.                   printf("?Sorry, no space for variable.\n");
  9285.                   return(success = 0);
  9286.               }
  9287.               if (x == TN_ENV_OFF || x == TN_ENV_ON) {
  9288.                   if ((y = cmcfm()) < 0) return(y);
  9289. #ifdef IKSD
  9290.                   if (inserver) {
  9291.                       printf("?Sorry, command disabled.\r\n");
  9292.                       return(success = 0);
  9293.                   }
  9294. #endif /* IKSD */
  9295.                   tn_env_flg = x == TN_ENV_OFF ? 0 : 1;
  9296.                   return(success = 1);
  9297.               }
  9298.  
  9299.               /* Not ON/OFF - Get the value */
  9300.               z = cmdgquo();
  9301.               cmdsquo(0);
  9302.               if ((y = cmtxt(msg, "", &s, xxstring)) < 0) {
  9303.                   cmdsquo(z);
  9304.                   return(y);
  9305.               }
  9306.               cmdsquo(z);
  9307. #ifdef IKSD
  9308.               if (inserver)
  9309.                 return(success = 0);
  9310. #endif /* IKSD */
  9311.               if ((int)strlen(s) > 63) {
  9312.                   printf("Sorry, too long\n");
  9313.                   return(-9);
  9314.               }
  9315.               switch (x) {
  9316.                 case TN_ENV_USR:
  9317.                   ckstrncpy(uidbuf,s,UIDBUFLEN);
  9318.                   sl_uid_saved = 0;
  9319.                   break;
  9320.                 case TN_ENV_ACCT:
  9321.                   ckstrncpy(tn_env_acct,s,64);
  9322.                   break;
  9323.                 case TN_ENV_DISP:
  9324.                   ckstrncpy(tn_env_disp,s,64);
  9325.                   break;
  9326.                 case TN_ENV_JOB:
  9327.                   ckstrncpy(tn_env_job,s,64);
  9328.                   break;
  9329.                 case TN_ENV_PRNT:
  9330.                   ckstrncpy(tn_env_prnt,s,64);
  9331.                   break;
  9332.                 case TN_ENV_SYS:
  9333.                   ckstrncpy(tn_env_sys,s,64);
  9334.                   break;
  9335.                 case TN_ENV_LOC:
  9336.                   if (!*s) s = NULL;
  9337.                   makestr(&tn_loc,s);
  9338.                   break;
  9339.                 case TN_ENV_UVAR:
  9340.                   printf("\n?Not yet implemented\n");
  9341.                   break;
  9342.               }
  9343.               return(success = 1);
  9344.           }
  9345. #endif /* CK_ENVIRONMENT */
  9346.  
  9347. #ifdef CK_SNDLOC
  9348.           case CK_TN_LOC: {             /* LOCATION */
  9349.               extern char * tn_loc;
  9350.               if ((y = cmtxt("Location string","",&s,xxstring)) < 0)
  9351.                 return(y);
  9352.               if (!*s) s = NULL;
  9353.               makestr(&tn_loc,s);
  9354.               return(success = 1);
  9355.           }
  9356. #endif /* CK_SNDLOC */
  9357.           case CK_TN_SFU:               /* Microsoft SFU compatibility */
  9358.             if ((z = cmkey(onoff,2,"","on",xxstring)) < 0) return(z);
  9359.             if ((y = cmcfm()) < 0) return(y);
  9360.             tn_sfu = z;
  9361.             return(success = 1);
  9362.             break;
  9363.  
  9364.           case CK_TN_WAIT:              /* WAIT-FOR-NEGOTIATIONS */
  9365.             if ((z = cmkey(onoff,2,"","on",xxstring)) < 0) return(z);
  9366.             if ((y = cmcfm()) < 0) return(y);
  9367. #ifdef IKSD
  9368.             if (inserver &&
  9369. #ifdef IKSDCONF
  9370.                 iksdcf
  9371. #else
  9372.                 1
  9373. #endif /* IKSDCONF */
  9374.                 ) {
  9375.                 printf("?Sorry, command disabled.\r\n");
  9376.                 return(success = 0);
  9377.             }
  9378. #endif /* IKSD */
  9379.             tn_wait_flg = z;
  9380.             sl_tn_saved = 0;
  9381.             return(success = 1);
  9382.  
  9383.           case CK_TN_DL:                /* DELAY SUBNEGOTIATIONS */
  9384.             if ((z = cmkey(onoff,2,"","on",xxstring)) < 0) return(z);
  9385.             if ((y = cmcfm()) < 0) return(y);
  9386. #ifdef IKSD
  9387.             if (inserver &&
  9388. #ifdef IKSDCONF
  9389.                 iksdcf
  9390. #else
  9391.                 1
  9392. #endif /* IKSDCONF */
  9393.                 ) {
  9394.                 printf("?Sorry, command disabled.\r\n");
  9395.                 return(success = 0);
  9396.             }
  9397. #endif /* IKSD */
  9398.             tn_delay_sb = z;
  9399.             return(success = 1);
  9400.  
  9401.           case CK_TN_PUID: {            /* PROMPT-FOR-USERID */
  9402.               int i,len;
  9403.               if ((y = cmtxt("Prompt string","",&s,xxstring)) < 0)
  9404.                 return(y);
  9405.               if (s == "") s = NULL;
  9406.               if (s) {
  9407.                   s = brstrip(s);
  9408.                   if (s == "") s = NULL;
  9409.               }
  9410.               /* we must check to make sure there are no % fields */
  9411.               len = strlen(s);
  9412.               for (i = 0; i < len; i++) {
  9413.                   if (s[i] == '%') {
  9414.                       if (s[i+1] != '%') {
  9415.                           printf("%% fields are not used in this command.\n");
  9416.                           return(-9);
  9417.                       }
  9418.                       i++;
  9419.                   }
  9420.               }
  9421.               makestr(&tn_pr_uid,s);
  9422.               return(success = 1);
  9423.           }
  9424.           default:
  9425.             return(-2);
  9426.         }
  9427.     }
  9428. #endif /* TNCODE */
  9429.  
  9430.     switch (xx) {
  9431. #ifndef NOSPL
  9432.       case XYCOUN:                      /* SET COUNT */
  9433.         x = cmnum("Positive number","0",10,&z,xxstring);
  9434.         if (x < 0) return(x);
  9435.         if ((x = cmcfm()) < 0) return(x);
  9436.         if (z < 0) {
  9437.             printf("?A positive number, please\n");
  9438.             return(0);
  9439.         }
  9440.         debug(F101,"XYCOUN: z","",z);
  9441.         return(success = setnum(&count[cmdlvl],z,0,10000));
  9442. #endif /* NOSPL */
  9443.  
  9444. #ifndef NOSPL
  9445.       case XYCASE:
  9446.         return(success = seton(&inpcas[cmdlvl]));
  9447. #endif /* NOSPL */
  9448.  
  9449.       case XYCMD:                       /* COMMAND ... */
  9450.         if ((y = cmkey(scmdtab,nbytt,"","",xxstring)) < 0)
  9451.           return(y);
  9452.         switch (y) {
  9453.           case SCMD_CBR:
  9454.             if ((y = cmcfm()) < 0)
  9455.               return(y);
  9456.             concb((char)escape);
  9457.             return(success = 1);
  9458.  
  9459.           case SCMD_BSZ:
  9460.             if ((y = cmnum("bytesize for command characters, 7 or 8","7",10,&x,
  9461.                            xxstring)) < 0)
  9462.               return(y);
  9463.             if (x != 7 && x != 8) {
  9464.                 printf("\n?The choices are 7 and 8\n");
  9465.                 return(success = 0);
  9466.             }
  9467.             if ((y = cmcfm()) < 0) return(y);
  9468.             if (x == 7) cmdmsk = 0177;
  9469.             else if (x == 8) cmdmsk = 0377;
  9470.             return(success = 1);
  9471. #ifdef CK_RECALL
  9472.           case SCMD_RCL:
  9473.             if ((y = cmnum("maximum number of commands in recall buffer","10",
  9474.                            10,&x,xxstring)) < 0)
  9475.               return(y);
  9476.             if ((y = cmcfm()) < 0) return(y);
  9477.             return(success = cmrini(x));
  9478. #endif /* CK_RECALL */
  9479. #ifdef CK_RECALL
  9480.           case SCMD_RTR:
  9481.             return(success = seton(&cm_retry));
  9482. #endif /* CK_RECALL */
  9483.           case SCMD_MOR:                /* More-prompting */
  9484.             success = seton(&xaskmore);
  9485.             if (success)
  9486.               saveask = xaskmore;
  9487.             return(success);
  9488.           case SCMD_QUO:
  9489.             if ((x = seton(&y)) < 0) return(x);
  9490.             cmdsquo(y);                 /* Do it the right way */
  9491.             cmd_quoting = y;            /* Also keep a global copy */
  9492.             /* Set string-processing function */
  9493. #ifdef datageneral
  9494.             xxstring = y ? zzstring : (xx_strp) NULL;
  9495. #else
  9496. #ifdef CK_ANSIC
  9497.             xxstring = y ? zzstring : (xx_strp) NULL;
  9498. #else
  9499.             xxstring = y ? zzstring : (xx_strp) NULL;
  9500. #endif /* CK_ANSIC */
  9501. #endif /* datageneral */
  9502.             return(success = 1);
  9503.  
  9504. #ifdef OS2
  9505. #ifndef NOLOCAL
  9506.           case SCMD_COL: {              /* Command-screen colors */
  9507.               int fg, bg;
  9508.               fg = cmkey(ttyclrtab, nclrs,
  9509.                          "foreground color and then background color",
  9510.                          "white",
  9511.                          xxstring);
  9512.               if (fg < 0)
  9513.                 return(fg);
  9514.               if ((bg = cmkey(ttyclrtab,nclrs,
  9515.                               "background color","black",xxstring)) < 0)
  9516.                 return(bg);
  9517.               if ((y = cmcfm()) < 0)
  9518.                 return(y);
  9519.               colorcmd = fg | bg << 4;
  9520.               return(success = 1);
  9521.           }
  9522.           case SCMD_SCR:                /* Command Scrollback size */
  9523.             if ((y = cmnum("COMMAND scrollback buffer size, lines","512",10,&x,
  9524.                            xxstring)) < 0)
  9525.               return(y);
  9526.             /* The max number of lines is the RAM  */
  9527.             /* we can actually dedicate to a       */
  9528.             /* scrollback buffer given the maximum */
  9529.             /* process memory space of 512MB       */
  9530.             if (x < 256 || x > 2000000L) {
  9531.                 printf("\n?The size must be between 256 and 2,000,000.\n");
  9532.                 return(success = 0);
  9533.             }
  9534.             if ((y = cmcfm()) < 0) return(y);
  9535.             tt_scrsize[VCMD] = x;
  9536.             VscrnInit( VCMD );
  9537.             return(success = 1);
  9538.  
  9539.           case SCMD_WID: {
  9540.               if ((y = cmnum(
  9541.                          "Number of columns in display window during CONNECT",
  9542.                          "80",10,&x,xxstring)) < 0)
  9543.                 return(y);
  9544.               if ((y = cmcfm()) < 0) return(y);
  9545.  
  9546.               if (IsOS2FullScreen()) {
  9547.                   if (x != 40 && x != 80 && x != 132) {
  9548.                       printf("\n?The width must be 40, 80,");
  9549. #ifdef NT
  9550.                       printf(" or 132 under Windows 95.\n.");
  9551. #else /* NT */
  9552.                       printf(" or 132 in a Full Screen session.\n.");
  9553. #endif /* NT */
  9554.                       return(success = 0);
  9555.                   }
  9556.               } else {
  9557.                   if (!IsWARPed() && x != 80) {
  9558.                       printf("\n?OS/2 version is pre-WARP: the width must");
  9559.                       printf("equal 80 in a Windowed Session\n.");
  9560.                       return(success = 0);
  9561.                   }
  9562.                   if (x < 20 || x > MAXTERMCOL) {
  9563.                       printf(
  9564.                       "\n?The width must be between 20 and %d\n.",MAXTERMCOL);
  9565.                       return(success = 0);
  9566.                   }
  9567.               }
  9568.               if (x > 8192/(tt_rows[VCMD]+1)) {
  9569.                   printf(
  9570. "\n?The max screen area is 8192 cells: %d(rows) x %d(cols) = %d cells.\n",
  9571.                          tt_rows[VCMD]+1,x,x*(tt_rows[VCMD]+1));
  9572.                   return(success = 0);
  9573.               }
  9574.               os2_setcmdwidth(x);
  9575.               return(success = 1);
  9576.           }
  9577.           case SCMD_HIG:
  9578.             if ((y = cmnum("Number of rows in display window during CONNECT",
  9579.                            "25",10,&x,xxstring)) < 0)
  9580.               return(y);
  9581.             if ((y = cmcfm()) < 0) return(y);
  9582.  
  9583.             if (tt_modechg == TVC_DIS) {
  9584.                 printf("\n?SET TERMINAL VIDEO-CHANGE DISABLED\n");
  9585.                 return(success = 0);
  9586.             }
  9587.             if (IsOS2FullScreen()) {
  9588.                 if ( tt_status[VCMD] ) {
  9589.                     if (x != 24 && x != 42 && x != 49 && x != 59) {
  9590.                         printf("\n?The height must be 24, 42, 49");
  9591. #ifdef NT
  9592.                         printf(" or 59 under Windows 95.\n.");
  9593. #else /* NT */
  9594.                         printf(" or 59 in a Full Screen session.\n.");
  9595. #endif /* NT */
  9596.                         return(success = 0);
  9597.                     }
  9598.                 } else {
  9599.                     if (x != 25 && x != 43 && x != 50 && x != 60) {
  9600.                         printf("\n?The height must be 25, 43, 50");
  9601. #ifdef NT
  9602.                         printf(" or 60 under Windows 95.\n.");
  9603. #else /* NT */
  9604.                         printf(" or 60 in a Full Screen session.\n.");
  9605. #endif /* NT */
  9606.                         return(success = 0);
  9607.                     }
  9608.                 }
  9609.             } else if (tt_modechg == TVC_W95) {
  9610.                 if (tt_status[VCMD]) {
  9611.                     if (x != 24 && x != 42 && x != 59) {
  9612.                         printf("\n?The height must be 24, 42, 49");
  9613. #ifdef NT
  9614.                         printf(" under Windows 95.\n.");
  9615. #else /* NT */
  9616.                         printf(" in a Full Screen session.\n.");
  9617. #endif /* NT */
  9618.                         return(success = 0);
  9619.                     }
  9620.                 } else {
  9621.                     if (x != 25 && x != 43 && x != 50) {
  9622.                         printf("\n?The height must be 25, 43, 50");
  9623. #ifdef NT
  9624.                         printf(" under Windows 95.\n.");
  9625. #else /* NT */
  9626.                         printf(" in a Full Screen session.\n.");
  9627. #endif /* NT */
  9628.                         return(success = 0);
  9629.                     }
  9630.                 }
  9631.             } else {
  9632.                 if (x < 8 || x > MAXTERMROW ) {
  9633.                     printf("\n?The height must be between 8 and %d\n.",
  9634.                            MAXTERMROW);
  9635.                     return(success = 0);
  9636.                 }
  9637.             }
  9638.             if (x > 8192/tt_cols[VCMD]) {
  9639.                 printf(
  9640. "\n?The max screen area is 8192 cells: %d(rows) x %d(cols) = %d cells.\n",
  9641.                        x,tt_cols[VCMD],x*tt_cols[VCMD]);
  9642.                 return(success = 0);
  9643.             }
  9644.             os2_setcmdheight(x);
  9645.             return(success = 1);
  9646.  
  9647.           case SCMD_STA: {
  9648.               extern int marginbot;
  9649.               if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  9650.               if ((x = cmcfm()) < 0) return(x);
  9651.               if (y != tt_status[VCMD]) {
  9652.                   /* Might need to fixup the margins */
  9653.                   tt_status[VCMD] = y;
  9654.                   if (y) {
  9655.                       tt_szchng[VCMD] = 2;
  9656.                       tt_rows[VCMD]--;
  9657.                       cmd_rows--;
  9658.                       VscrnInit(VCMD);  /* Height set here */
  9659.                       printf("\n");
  9660.                   } else {
  9661.                       tt_szchng[VCMD] = 1;
  9662.                       tt_rows[VCMD]++;
  9663.                       cmd_rows++;
  9664.                       VscrnInit(VCMD);  /* Height set here */
  9665.                   }
  9666.               }
  9667.               return(success = 1);
  9668.           }
  9669.  
  9670.           case SCMD_CUR: {
  9671.               int row, col;
  9672.               position * ppos;
  9673.  
  9674.               ppos = VscrnGetCurPos(VCMD);
  9675. #ifdef NT
  9676. #define itoa _itoa
  9677. #endif /* NT */
  9678.               itoa(ppos->y+1, tmpbuf, 10);
  9679.               if ((y = cmnum("row (1-based)",tmpbuf,10,&row,xxstring)) < 0)
  9680.                 return(y);
  9681.  
  9682.               itoa(ppos->x+1, tmpbuf, 10);
  9683.               if ((y = cmnum("col (1-based)",tmpbuf,10,&col,xxstring)) < 0)
  9684.                 return(y);
  9685.               if ((x = cmcfm()) < 0) return(x);
  9686.  
  9687.               VscrnSetCurPos( VCMD, (short) (col-1), (short) (row-1) ) ;
  9688.               VscrnIsDirty( VCMD );
  9689.               return(success=1);
  9690.           }
  9691. #endif /* NOLOCAL */
  9692. #else
  9693.           case SCMD_WID:
  9694.             y = cmnum("Command screen width, characters","80",10,&x,xxstring);
  9695.             return(setnum(&cmd_cols,x,y,1024));
  9696.  
  9697.           case SCMD_HIG:
  9698.             y = cmnum("Command screen height, rows","24",10,&x,xxstring);
  9699.             return(setnum(&cmd_rows,x,y,1024));
  9700. #endif /* OS2 */
  9701.  
  9702.           case SCMD_INT:
  9703.             return(seton(&cmdint));
  9704.  
  9705. #ifdef CK_AUTODL
  9706.           case SCMD_ADL:
  9707.             return(seton(&cmdadl));
  9708. #endif /* CK_AUTODL */
  9709.  
  9710. #ifdef DOUBLEQUOTING
  9711.           case SCMD_DBQ: {
  9712.               extern int dblquo;
  9713.               return(seton(&dblquo));
  9714.           }
  9715. #endif /* DOUBLEQUOTING */
  9716.  
  9717.           default:
  9718.             return(-2);
  9719.         }
  9720.     }
  9721.  
  9722.     switch (xx) {
  9723.  
  9724.       case XYDFLT:                      /* SET DEFAULT = CD */
  9725.         return(success = docd(XXCWD));
  9726.  
  9727. case XYDEBU:                            /* SET DEBUG { on, off, session } */
  9728.         if ((y = cmkey(dbgtab,ndbg,"","",xxstring)) < 0)
  9729.           return(y);
  9730.         if (y == DEB_TIM)
  9731. #ifdef COMMENT
  9732.           return(seton(&debtim) < 0 ? x : (success = 1));
  9733. #else
  9734.           /* why this change? */
  9735.           return(success = seton(&debtim));
  9736. #endif /* COMMENT */
  9737.  
  9738. #ifdef IKSD
  9739.         if (inserver && isguest) {
  9740.             printf("?Sorry, command disabled.\r\n");
  9741.             return(success = 0);
  9742.     }
  9743. #endif /* IKSD */
  9744.  
  9745.         switch (y) {
  9746.           case DEB_LEN:
  9747.             y = cmnum("Max length for debug log strings","",10,&x,xxstring);
  9748.             if ((z = setnum(&debxlen,x,y,-1)) < 0)
  9749.               return(z);
  9750.             if ((x = cmcfm()) < 0)
  9751.               return(x);
  9752.             return(success = 1);
  9753.  
  9754.           case DEB_OFF:
  9755.             if ((x = cmcfm()) < 0)
  9756.               return(x);
  9757.             debses = 0;
  9758. #ifdef DEBUG
  9759.             if (deblog) doclslog(LOGD);
  9760. #endif /* DEBUG */
  9761.             return(success = 1);
  9762.  
  9763.           case DEB_ON:
  9764.             if ((x = cmcfm()) < 0)
  9765.               return(x);
  9766. #ifdef DEBUG
  9767.             deblog = debopn("debug.log", 0);
  9768.             return(success = deblog ? 1 : 0);
  9769. #else
  9770.             printf("?Sorry, debug log feature not enabled\n");
  9771.             return(success = 0);
  9772. #endif /* DEBUG */
  9773.           case DEB_SES:
  9774.             if ((x = cmcfm()) < 0)
  9775.               return(x);
  9776.             return(success = debses = 1);
  9777.         }
  9778.         break;
  9779.  
  9780. #ifndef NOXFER
  9781.       case XYDELA:                      /* SET DELAY */
  9782.         y = cmnum("Number of seconds before starting to send",
  9783.                   "5",10,&x,xxstring);
  9784.         if (x < 0) x = 0;
  9785.         return(success = setnum(&ckdelay,x,y,999));
  9786. #endif /* NOXFER */
  9787.  
  9788.       default:
  9789.         break;
  9790.     }
  9791.  
  9792.     switch (xx) {
  9793. #ifndef NODIAL
  9794. #ifdef CK_TAPI
  9795.       case XYTAPI:
  9796.         return(settapi());
  9797. #endif /* CK_TAPI */
  9798.       case XYDIAL:                      /* SET MODEM or SET DIAL */
  9799.         return(setdial(-1));
  9800.       case XYMODM:
  9801.         return(setmodem());
  9802. #ifdef COMMENT
  9803.       /* not implemented yet */
  9804.       case XYANSWER:                    /* SET ANSWER */
  9805.         return(setanswer());
  9806. #endif /* COMMENT */
  9807. #endif /* NODIAL */
  9808.  
  9809. #ifndef NOLOCAL
  9810.       case XYDUPL:                      /* SET DUPLEX */
  9811.         if ((y = cmkey(dpxtab,2,"","full",xxstring)) < 0) return(y);
  9812.         if ((x = cmcfm()) < 0) return(x);
  9813.         duplex = y;
  9814.         return(success = 1);
  9815.  
  9816.       case XYLCLE:                      /* LOCAL-ECHO (= DUPLEX) */
  9817.         return(success = seton(&duplex));
  9818.  
  9819.       case XYESC:                       /* SET ESCAPE */
  9820.         return(success = setcc(ckitoa(DFESC),&escape));
  9821. #endif /* NOLOCAL */
  9822.  
  9823.       case XYEXIT:                      /* SET EXIT */
  9824.         if ((z = cmkey(xittab,nexit,"","",xxstring)) < 0)
  9825.           return(z);
  9826.         switch (z) {
  9827.           case 0:                       /* STATUS */
  9828.             y = cmnum("EXIT status code","",10,&x,xxstring);
  9829.             return(success = setnum(&xitsta,x,y,-1));
  9830.           case 1:                       /* WARNING */
  9831.             if ((z = cmkey(xitwtab,nexitw,"","",xxstring)) < 0)
  9832.               return(z);
  9833.             if ((y = cmcfm()) < 0) return(y);
  9834.             xitwarn = z;
  9835.             return(success = 1);
  9836.           case 2:
  9837.             success = seton(&exitonclose);
  9838. #ifdef TCPSOCKET
  9839.             if (success) tn_exit = exitonclose;
  9840. #endif /* TCPSOCKET */
  9841.             return(success);
  9842.           case 3: {
  9843.               extern int exithangup;
  9844.               return((success = seton(&exithangup)));
  9845.           }
  9846.           default:
  9847.             return(-2);
  9848.         } /* End of SET EXIT switch() */
  9849.       default:
  9850.         break;
  9851.     }
  9852.  
  9853.     switch (xx) {
  9854.  
  9855.       case XYFILE:                      /* SET FILE */
  9856.         return(setfil(rmsflg));
  9857.  
  9858.       case XYFLOW: {                    /* FLOW-CONTROL */
  9859.           extern int cxflow[];
  9860.           struct FDB k1, k2;
  9861.           int tncomport = 0;
  9862.           char * m;
  9863.  
  9864. #ifdef TN_COMPORT
  9865.           if (network && istncomport())
  9866.             tncomport = 1;
  9867. #endif /* TN_COMPORT */
  9868.  
  9869.           if (tncomport) {
  9870.               m = "Flow control type, one of the following:\n\
  9871.    dtr/cd    dtr/cts   keep    none    rts/cts   xon/xoff\n\
  9872.  or connection type";
  9873.           } else {
  9874.           /* All this is because chained FDB's don't give chained help yet */
  9875.               m =
  9876. #ifdef Plan9
  9877. #ifdef CK_RTSCTS
  9878.            "Flow control type, one of the following:\n\
  9879.    keep   none    rts/cts\n\
  9880.  or connection type",
  9881. #else
  9882.            "Flow control type, one of the following:\n\
  9883.    keep   none\n\
  9884.  or connection type";
  9885. #endif /* CK_RTSCTS */
  9886. #else
  9887. #ifdef CK_RTSCTS
  9888. #ifdef CK_DTRCD
  9889. #ifdef CK_DTRCTS
  9890.            "Flow control type, one of the following:\n\
  9891.    dtr/cd    dtr/cts   keep    none    rts/cts   xon/xoff\n\
  9892.  or connection type";
  9893. #else /* CK_DTRCTS */
  9894.            "Flow control type, one of the following:\n\
  9895.    dtr/cd    keep    none    rts/cts   xon/xoff\n\
  9896.             or connection type";
  9897. #endif /* CK_DTRCTS */
  9898. #else /* CK_DTRCD */
  9899. #ifdef CK_DTRCTS
  9900.            "Flow control type, one of the following:\n\
  9901.    dtr/cts   keep   none    rts/cts   xon/xoff\n\
  9902.  or connection type";
  9903. #else /* CK_DTRCTS */
  9904.            "Flow control type, one of the following:\n\
  9905.    keep   none    rts/cts   xon/xoff\n\
  9906.  or connection type";
  9907. #endif /* CK_DTRCTS */
  9908. #endif /* CK_DTRCD */
  9909. #else
  9910.            "Flow control type, one of the following:\n\
  9911.    keep   none    xon/xoff\n\
  9912.  or connection type";
  9913. #endif /* CK_RTSCTS */
  9914. #endif /* Plan9 */
  9915.           }
  9916.           cmfdbi(&k1,_CMKEY,m,"","",ncxtypesw, 4, xxstring, cxtypesw, &k2);
  9917.           cmfdbi(&k2,
  9918.                  _CMKEY,
  9919.                  "",
  9920.                  "",
  9921.                  "",
  9922. #ifdef TN_COMPORT
  9923.                  (tncomport ? ntnflo : nflo),
  9924. #else
  9925.                  nflo,
  9926. #endif /* TN_COMPORT */
  9927.                  0,
  9928.                  xxstring,
  9929. #ifdef TN_COMPORT
  9930.                  (tncomport ? tnflotab : flotab),
  9931. #else
  9932.                  flotab,
  9933. #endif /* TN_COMPORT */
  9934.                  NULL
  9935.                  );
  9936.           x = cmfdb(&k1);
  9937.           if (x < 0) {                  /* Error */
  9938.               if (x == -2 || x == -9)
  9939.                 printf("?No keywords or switches match: \"%s\"\n",atmbuf);
  9940.               return(x);
  9941.           }
  9942.           z = cmresult.nresult;         /* Keyword value */
  9943.           if (cmresult.fdbaddr == &k2) { /* Flow-control type keyword table */
  9944.               if ((x = cmcfm()) < 0)    /* Set it immediately */
  9945.                 return(x);
  9946.               flow = z;
  9947.               debug(F101,"set flow","",flow);
  9948. #ifdef CK_SPEED
  9949.               if (flow == FLO_XONX)     /* Xon/Xoff forces prefixing */
  9950.                 ctlp[XON] = ctlp[XOFF] = ctlp[XON+128] = ctlp[XOFF+128] = 1;
  9951. #endif /* CK_SPEED */
  9952.               autoflow = (flow == FLO_AUTO);
  9953.               return(success = 1);      /* Done */
  9954.           }
  9955.           debug(F101,"set flow /blah 1","",z); /* SET FLOW /for-what */
  9956.           if ((y = cmkey(flotab,nflo,"Flow control type","none",xxstring)) < 0)
  9957.             return(y);
  9958.           if ((x = cmcfm()) < 0)
  9959.             return(x);
  9960.           debug(F101,"set flow /blah 2","",y);
  9961.           if (y == FLO_AUTO) {
  9962.               printf(
  9963.   "?Sorry, \"automatic\" can not be assigned to a connection type.\n");
  9964.               return(-9);
  9965.           } else if (z >= 0 && z <= CXT_MAX)
  9966.             cxflow[z] = y;
  9967.           debug(F101,"set flow","",flow);
  9968.           debug(F101,"set flow autoflow","",autoflow);
  9969.           return(success = 1);
  9970.       }
  9971.  
  9972.       case XYHAND:                      /* HANDSHAKE */
  9973.         if ((y = cmkey(hshtab,nhsh,"","none",xxstring)) < 0) return(y);
  9974.         if (y == 998) {
  9975.             if ((x = cmnum("ASCII value","",10,&y,xxstring)) < 0)
  9976.               return(x);
  9977.             if ((y < 1) || ((y > 31) && (y != 127))) {
  9978.                 printf("?Character must be in ASCII control range\n");
  9979.                 return(-9);
  9980.             }
  9981.         }
  9982.         if ((x = cmcfm()) < 0) return(x);
  9983.         turn = (y > 0127) ? 0 : 1;
  9984.         turnch = y;
  9985.         return(success = 1);
  9986.  
  9987. #ifndef NOSPL
  9988.       case XYMACR:                      /* SET MACRO */
  9989.         if ((y = cmkey(smactab,2,"","",xxstring)) < 0) return(y);
  9990.         switch (y) {
  9991.           case 0: return(success = seton(&mecho));
  9992.           case 1: return(success = seton(&merror[cmdlvl]));
  9993.           default: return(-2);
  9994.         }
  9995. #endif /* NOSPL */
  9996.  
  9997.       case XYMSGS:
  9998. #ifdef VMS
  9999.         if ((z = cmkey(onoff,2,"","",xxstring)) < 0) return(z);
  10000.         if ((y = cmcfm()) < 0) return(y);
  10001.         vms_msgs = z;
  10002.         printf("Sorry, SET MESSAGES not implemented yet\n");
  10003.         return(success = 0);
  10004. #endif /* VMS */
  10005.       default:
  10006.         break;
  10007.     }
  10008.  
  10009.     switch (xx) {
  10010.  
  10011.       case XYPARI:                      /* PARITY */
  10012.         if ((y = cmkey(partbl,npar,"","none",xxstring)) < 0)
  10013.           return(y);
  10014.  
  10015.         /* If parity not none, then we also want 8th-bit prefixing */
  10016.  
  10017. #ifdef HWPARITY
  10018.         if (y == 'H') {                 /* Hardware */
  10019.             if ((x = cmkey(hwpartbl,nhwpar,"","even",xxstring)) < 0)
  10020.               return(x);
  10021.         }
  10022. #endif /* HWPARITY */
  10023.  
  10024.         if ((z = cmcfm()) < 0)
  10025.           return(z);
  10026.  
  10027. #ifdef HWPARITY
  10028.         if (y == 'H') {                 /* 8 data bits plus hardware parity */
  10029.             parity = 0;
  10030. #ifndef NOXFER
  10031.             ebqflg = 0;
  10032. #endif /* NOXFER */
  10033.             hwparity = x;
  10034.         } else {                        /* 7 data bits + software parity */
  10035.             hwparity = 0;
  10036. #endif /* HWPARITY */
  10037.             parity = y;
  10038. #ifndef NOXFER
  10039.             ebqflg = (parity) ? 1 : 0;
  10040. #endif /* NOXFER */
  10041. #ifdef HWPARITY
  10042.         }
  10043. #endif /* HWPARITY */
  10044.  
  10045. #ifdef TN_COMPORT
  10046.         if (network && istncomport())
  10047.           tnsettings(parity, 0);
  10048. #endif /* TN_COMPORT */
  10049.  
  10050.         return(success = 1);
  10051.  
  10052. #ifndef NOFRILLS
  10053.       case XYPROM:                      /* SET PROMPT */
  10054. /*
  10055.   Note: xxstring not invoked here.  Instead, it is invoked every time the
  10056.   prompt is issued.  This allows the prompt string to contain variables
  10057.   that can change, like \v(dir), \v(time), etc.
  10058. */
  10059.         ckmakmsg(line,                  /* Default might have trailing space */
  10060.                  LINBUFSIZ,
  10061.                  "{",
  10062.                  inserver ? ikprompt : ckprompt,
  10063.                  "}",
  10064.                  NULL
  10065.                  );
  10066.         if ((x = cmtxt("Program's command prompt",line,&s,NULL)) < 0)
  10067.           return(x);
  10068.         s = brstrip(s);                 /* Remove enclosing braces, if any */
  10069.         cmsetp(s);                      /* Set the prompt */
  10070.         return(success = 1);
  10071. #endif /* NOFRILLS */
  10072.  
  10073. #ifndef NOXFER
  10074.       case XYRETR:                      /* RETRY: per-packet retry limit */
  10075.         y = cmnum("Maximum retries per packet","10",10,&x,xxstring);
  10076.         if (x < 0) x = 0;
  10077.         if ((x = setnum(&maxtry,x,y,999)) < 0) return(x);
  10078. #ifdef COMMENT
  10079.         if (maxtry <= wslotr) {
  10080.             printf("?Retry limit must be greater than window size\n");
  10081.             return(success = 0);
  10082.         }
  10083. #endif /* COMMENT */
  10084.         if (rmsflg) {
  10085.             sstate = setgen('S', "403", ckitoa(maxtry), "");
  10086.             return((int) sstate);
  10087.         } else return(success = x);
  10088. #endif /* NOXFER */
  10089.  
  10090. #ifndef NOSERVER
  10091.       case XYSERV:                      /* SET SERVER items */
  10092.         if ((y = cmkey(srvtab,nsrvt,"","",xxstring)) < 0) return(y);
  10093.         switch (y) {
  10094.           case XYSERI:
  10095.             if ((y = cmnum("Number of seconds, or 0 for no idle timeout",
  10096.                            "0",10,&x,xxstring)) < 0)
  10097.               return(y);
  10098.             if (x < 0)
  10099.               x = 0;
  10100.             if ((y = cmcfm()) < 0)
  10101.               return(y);
  10102. #ifndef OS2
  10103.             srvtim = 0;
  10104. #endif /* OS2 */
  10105.             srvidl = x;
  10106.             return(success = 1);
  10107.           case XYSERT:
  10108.             if ((y = cmnum("Interval for server NAKs, 0 = none",
  10109.                            ckitoa(DSRVTIM),
  10110.                            10,&x, xxstring)) < 0)
  10111.               return(y);
  10112.             if (x < 0) {
  10113.                 printf(
  10114.                    "\n?Specify a positive number, or 0 for no server NAKs\n");
  10115.                 return(0);
  10116.             }
  10117.             if ((y = cmcfm()) < 0) return(y);
  10118.             if (rmsflg) {
  10119.                 sstate = setgen('S', "404", ckitoa(x), "");
  10120.                 return((int) sstate);
  10121.             } else {
  10122. #ifndef OS2
  10123.                 srvidl = 0;
  10124. #endif /* OS2 */
  10125.                 srvtim = x;             /* Set the server timeout variable */
  10126.                 return(success = 1);
  10127.             }
  10128.           case XYSERD:                  /* SERVER DISPLAY */
  10129.             return(success = seton(&srvdis)); /* ON or OFF... */
  10130.  
  10131. #ifndef NOSPL
  10132.           case XYSERP:                  /* SERVER GET-PATH */
  10133.             return(parsdir(2));
  10134. #endif /* NOSPL */
  10135.  
  10136.           case XYSERL:                  /* SERVER LOGIN */
  10137.             return(cklogin());
  10138.  
  10139.           case XYSERC:                  /* SERVER CD-MESSAGE */
  10140.             x = rmsflg ?
  10141.               cmkey(onoff,2,"","",xxstring) :
  10142.                 cmkey(cdmsg,3,"","",xxstring);
  10143.             if (x < 0)
  10144.               return(x);
  10145.             if (x == 2) {               /* CD-MESSAGE FILE */
  10146.                 if ((x = cmtxt("Name of file","",&s,NULL)) < 0)
  10147.                   return(x);
  10148.                 if (!*s) {
  10149.                     s = NULL;
  10150.                     srvcdmsg = 0;
  10151.                 }
  10152.                 makestr(&cdmsgstr,s);
  10153.                 makelist(cdmsgstr,cdmsgfile,8);
  10154.                 return(success = 1);
  10155.             }
  10156.             if ((y = cmcfm()) < 0)      /* CD-MESSAGE ON/OFF */
  10157.               return(y);
  10158.             if (rmsflg) {
  10159.                 sstate = setgen('S', "420", x ? "1" : "0", "");
  10160.                 return((int) sstate);
  10161.             } else {
  10162.                 if (x > 0)
  10163.                   srvcdmsg |= 1;
  10164.                 else
  10165.                   srvcdmsg &= 2;
  10166.                 return(success = 1);
  10167.             }
  10168.           case XYSERK:                  /* SERVER KEEPALIVE */
  10169.             return(success = seton(&srvping)); /* ON or OFF... */
  10170.  
  10171.           default:
  10172.             return(-2);
  10173.         }
  10174. #endif /* NOSERVER */
  10175.     }
  10176.  
  10177.     switch (xx) {
  10178. #ifdef UNIX
  10179. #ifndef NOJC
  10180.       case XYSUSP:                      /* SET SUSPEND */
  10181.         seton(&suspend);                /* on or off... */
  10182.         return(success = 1);
  10183. #endif /* NOJC */
  10184. #endif /* UNIX */
  10185.  
  10186.       case XYTAKE:                      /* SET TAKE */
  10187.         if ((y = cmkey(taktab,4,"","",xxstring)) < 0) return(y);
  10188.         switch (y) {
  10189.           case 0: return(success = seton(&techo));
  10190. #ifndef NOSPL
  10191.           case 1: return(success = seton(&takerr[cmdlvl]));
  10192. #else
  10193.           case 1: return(success = seton(&takerr[tlevel]));
  10194. #endif /* NOSPL */
  10195.           case 2: techo = 0; return(success = 1); /* For compatibility with */
  10196.           case 3: techo = 1; return(success = 1); /* MS-DOS Kermit */
  10197.           default: return(-2);
  10198.         }
  10199.  
  10200. #ifndef NOSCRIPT
  10201.       case XYSCRI:                      /* SET SCRIPT */
  10202.         if ((y = cmkey(scrtab,1,"","echo",xxstring)) < 0) return(y);
  10203.         switch (y) {
  10204.           case 0: return(success = seton(&secho));
  10205.           default: return(-2);
  10206.         }
  10207. #endif /* NOSCRIPT */
  10208.  
  10209.       default:
  10210.         break;
  10211.     }
  10212.  
  10213. #ifndef NOLOCAL
  10214.     switch (xx) {
  10215.       case XYTERM:                      /* SET TERMINAL */
  10216.         x = settrm();
  10217.         success = (x > 0) ? 1 : 0;
  10218.         return(x);
  10219.  
  10220. #ifdef NT
  10221.       case XYWIN95:                     /* SET WIN95 workarounds */
  10222.         x = setwin95();
  10223.         success = (x > 0 ? 1 : 0);
  10224.         return(x);
  10225. #endif /* NT */
  10226.  
  10227. #ifdef OS2
  10228.       case XYDLR:                       /* SET DIALER workarounds */
  10229.         x = setdialer();
  10230.         success = (x > 0 ? 1 : 0);
  10231.         return(x);
  10232.  
  10233.       case XYTITLE:                     /* SET TITLE of window */
  10234.         x = settitle();
  10235.         success = (x > 0 ? 1 : 0);
  10236.         return(x);
  10237. #endif /* OS2 */
  10238.  
  10239. #ifdef OS2MOUSE
  10240.       case XYMOUSE:                     /* SET MOUSE */
  10241.         return(success = setmou());
  10242. #endif /* OS2MOUSE */
  10243.  
  10244.       case XYBELL:                      /* SET BELL */
  10245.         return(success = setbell());
  10246.  
  10247. #ifdef OS2
  10248.       case XYPRTY:
  10249.         return(success = setprty() );
  10250. #endif /* OS2 */
  10251.  
  10252.       default:
  10253.         break;
  10254.     }
  10255. #endif /* NOLOCAL */
  10256.  
  10257.     switch (xx) {
  10258.  
  10259. /* SET SEND/RECEIVE protocol parameters. */
  10260.  
  10261. #ifndef NOXFER
  10262.       case XYRECV:
  10263.       case XYSEND:
  10264.         return(setsr(xx,rmsflg));
  10265. #endif /* NOXFER */
  10266.  
  10267. #ifndef NOLOCAL
  10268.       case XYSESS:                      /* SESSION-LOG */
  10269.         if ((x = cmkey(sfttab,nsfttab,"type of file",
  10270. #ifdef OS2
  10271.                        "binary",
  10272. #else /* OS2 */
  10273.                        "text",
  10274. #endif /* OS2 */
  10275.                        xxstring
  10276.                        )
  10277.              ) < 0)
  10278.           return(x);
  10279.         if ((y = cmcfm()) < 0)
  10280.           return(y);
  10281.         if (x == 999) {                 /* TIMESTAMPED-TEXT */
  10282.             sessft = XYFT_T;            /* Implies text */
  10283.             slogts = 1;                 /* and timestamps */
  10284.         } else {                        /* A regular type */
  10285.             sessft = x;                 /* The type */
  10286.             slogts = 0;                 /* No timestampes */
  10287.         }
  10288.         return(success = 1);
  10289.  
  10290.       case XYSPEE:                      /* SET SPEED */
  10291.         lp = line;
  10292.         if (local && !network) {
  10293.           ckmakmsg(lp,
  10294.                    LINBUFSIZ,
  10295.                    "Transmission rate for ",
  10296.                    ttname,
  10297.                    " (bits per second)",
  10298.                    NULL
  10299.                    );
  10300.         } else {
  10301.           ckstrncpy(lp,
  10302.                     "Serial-port speed (bits per second)",
  10303.                     LINBUFSIZ
  10304.                     );
  10305.         }
  10306.         zz = -1L;
  10307.  
  10308. #ifdef TN_COMPORT
  10309.         if (network && istncomport())
  10310.           x = cmkey(tnspdtab,ntnspd,line,"",xxstring);
  10311.         else
  10312. #endif /* TN_COMPORT */
  10313.           x = cmkey(spdtab,nspd,line,"",xxstring);
  10314.         if (x < 0) {
  10315.             if (x == -3) printf("?value required\n");
  10316. #ifdef USETCSETSPEED
  10317.             /* In this case, any number can be tried */
  10318.             /* There's a parse error message but the request still goes thru */
  10319.             if (rdigits(atmbuf))
  10320.               zz = atol(atmbuf);
  10321.             else
  10322. #endif /* USETCSETSPEED */
  10323.               return(x);
  10324.         }
  10325.         if ((y = cmcfm()) < 0) return(y);
  10326. #ifdef IKSD
  10327.         if (inserver) {
  10328.             printf("?Sorry, command disabled.\r\n");
  10329.             return(success = 0);
  10330.         }
  10331. #endif /* IKSD */
  10332.         if (!local) {
  10333.             printf("?SET SPEED has no effect without prior SET LINE\n");
  10334.             return(success = 0);
  10335.         } else if (network
  10336. #ifdef TN_COMPORT
  10337.                    && !istncomport()
  10338. #endif /* TN_COMPORT */
  10339.                    ) {
  10340.             printf("\n?Speed cannot be set for network connections\n");
  10341.             return(success = 0);
  10342.         }
  10343.  
  10344. /*
  10345.   Note: This way of handling speeds is not 16-bit safe for speeds greater
  10346.   than 230400.  The argument to ttsspd() should have been a long.
  10347. */
  10348. #ifdef USETCSETSPEED
  10349.         if (zz > -1L)
  10350.           x = zz / 10L;
  10351. #endif /* USETCSETSPEED */
  10352.         zz = (long) x * 10L;
  10353.         if (zz == 130L) zz = 134L;
  10354.         if (zz == 70L) zz = 75L;        /* (see spdtab[] definition) */
  10355.         if (ttsspd(x) < 0)  {           /* Call ttsspd with cps, not bps! */
  10356.             printf("?Unsupported line speed - %ld\n",zz);
  10357.             return(success = 0);
  10358.         } else {
  10359. #ifdef CK_TAPI
  10360.             if (!tttapi || tapipass)
  10361.               speed = ttgspd();         /* Read it back */
  10362.             else
  10363.               speed = zz;
  10364. #else /* CK_TAPI */
  10365.             speed = ttgspd();           /* Read it back */
  10366. #endif /* CK_TAPI */
  10367.             if (speed != zz)  {         /* Call ttsspd with cps, not bps! */
  10368.                 printf("?SET SPEED fails, speed is %ld\n",speed);
  10369.                 return(success = 0);
  10370.             }
  10371.             if (pflag && !xcmdsrc) {
  10372.                 if (speed == 8880)
  10373.                   printf("%s, 75/1200 bps\n",ttname);
  10374.                 else if (speed == 134)
  10375.                   printf("%s, 134.5 bps\n",ttname);
  10376.                 else
  10377.                   printf("%s, %ld bps\n",ttname,speed);
  10378.             }
  10379.             return(success = 1);
  10380.         }
  10381. #endif /* NOLOCAL */
  10382.  
  10383. #ifndef NOXFER
  10384.       case XYXFER:                      /* SET TRANSFER */
  10385.         if ((y = cmkey(rmsflg ? rtstab : tstab, /* (or REMOTE SET TRANSFER) */
  10386.                        rmsflg ? nrts : nts,
  10387.                        "","character-set",xxstring)) < 0) return(y);
  10388.         switch (y) {
  10389. #ifdef XFRCAN
  10390.           case XYX_CAN:                 /* CANCELLATION */
  10391.             if ((z = cmkey(onoff,2,"","",xxstring)) < 0) return(z);
  10392.             if (z == 0) {               /* OFF */
  10393.                 if ((y = cmcfm()) < 0) return(y);
  10394.                 xfrcan = 0;
  10395.             } else {
  10396.                 if ((y = cmnum("ASCII code for cancellation character",
  10397.                                "3",10,&x,
  10398.                                xxstring)) < 0)
  10399.                   return(y);
  10400.                 if (x > 31 && x != 127) {
  10401.                     printf("Cancel character must be 0-31 or 127\n");
  10402.                     return(-9);
  10403.                 }
  10404.                 if ((y = cmnum("How many required to cause cancellation",
  10405.                                "2",10,&z, xxstring)) < 0)
  10406.                   return(y);
  10407.                 if (z < 2) {
  10408.                     printf("Number must be 2 or greater\n");
  10409.                     return(-9);
  10410.                 }
  10411.                 if ((y = cmcfm()) < 0) return(y);
  10412.                 xfrcan = 1;             /* CANCELLATION ON */
  10413.                 xfrchr = x;             /* Using this character */
  10414.                 xfrnum = z;             /* Needing this many of them */
  10415.             }
  10416.             return(success = 1);
  10417. #endif /* XFRCAN */
  10418.  
  10419. #ifndef NOCSETS
  10420.           case XYX_CSE:                 /* CHARACTER-SET */
  10421.             if ((y = cmkey(tcstab,ntcs,"","transparent",xxstring)) < 0)
  10422.               return(y);
  10423.             if ((x = cmcfm()) < 0) return(x);
  10424.             if (rmsflg) {
  10425.                 sstate = setgen('S', "405", tcsinfo[y].designator, "");
  10426.                 return((int) sstate);
  10427.             } else {
  10428.                 extern int s_cset, fcharset, axcset[];
  10429.                 tslevel = (y == TC_TRANSP) ? 0 : 1; /* transfer syntax level */
  10430.                 tcharset = y;           /* transfer character set */
  10431.                 /* SEND CHARACTER-SET AUTO */
  10432.                 if (tslevel > 0 && s_cset == XMODE_A)
  10433.                   if (y > -1 && y <= MAXTCSETS)
  10434.                     if (axcset[y] > -1 && axcset[y] > MAXFCSETS)
  10435.                       fcharset = axcset[y]; /* Auto-pick file charset */
  10436.                 setxlatype(tcharset,fcharset); /* Translation type */
  10437.                 return(success = 1);
  10438.             }
  10439. #endif /* NOCSETS */
  10440.  
  10441.           case XYX_LSH:                 /* LOCKING-SHIFT */
  10442.             if ((y = cmkey(lstab,nls,"","on",xxstring)) < 0)
  10443.               return(y);
  10444.             if ((x = cmcfm()) < 0) return(x);
  10445.             lscapr = (y == 1) ? 1 : 0;  /* ON: requested = 1 */
  10446.             lscapu = (y == 2) ? 2 : 0;  /* FORCED:  used = 1 */
  10447.             return(success = 1);
  10448.  
  10449. #ifdef CK_XYZ
  10450.           case XYX_PRO:                 /* Protocol */
  10451. #ifndef OS2
  10452.             if (inserver) {
  10453.                 printf("?Sorry, only Kermit protocol is available\n");
  10454.                 return(-9);
  10455.             }
  10456. #endif /* OS2 */
  10457.             return(setproto());
  10458. #endif /* CK_XYZ */
  10459.  
  10460.           case XYX_MOD:                 /* Mode */
  10461.             if ((y = cmkey(xfrmtab,2,"","automatic",xxstring)) < 0)
  10462.               return(y);
  10463.             if ((x = cmcfm()) < 0) return(x);
  10464.             if (rmsflg) {
  10465.                 sstate = setgen('S', "410", y == XMODE_A ? "0" : "1", "");
  10466.                 return((int)sstate);
  10467.             }
  10468.             g_xfermode = y;
  10469.             xfermode = y;
  10470.             return(success = 1);
  10471.  
  10472. #ifndef NOLOCAL
  10473.           case XYX_DIS:                 /* Display */
  10474.             return(doxdis());
  10475. #endif /* NOLOCAL */
  10476.  
  10477.           case XYX_SLO:                 /* Slow-start */
  10478.             return(seton(&slostart));
  10479.  
  10480. #ifndef NOSPL
  10481.           case XYX_CRC:                 /* CRC */
  10482.             return(seton(&docrc));
  10483. #endif /* NOSPL */
  10484.  
  10485.           case XYX_BEL:                 /* Bell */
  10486.             return(seton(&xfrbel));
  10487.  
  10488. #ifdef PIPESEND
  10489.           case XYX_PIP:                 /* Pipes */
  10490. #ifndef NOPUSH
  10491.             if (nopush) {
  10492. #endif /* NOPUSH */
  10493.                 printf("Sorry, access to pipes is disabled\n");
  10494.                 return(-9);
  10495. #ifndef NOPUSH
  10496.             } else
  10497. #endif /* NOPUSH */
  10498.               return(seton(&usepipes));
  10499. #endif /* PIPESEND */
  10500.  
  10501.           case XYX_INT:                 /* Interruption */
  10502.             return(seton(&xfrint));
  10503.  
  10504.           case XYX_XLA:
  10505.             return(seton(&xfrxla));     /* Translation */
  10506.  
  10507.           case XYX_MSG: {
  10508.               extern char * xfrmsg;
  10509.               if ((x = cmtxt("Prompt string","",&s,xxstring)) < 0)
  10510.                 return(x);
  10511.               if (!*s) s = NULL;
  10512.               makestr(&xfrmsg,s);
  10513.               return(success = 1);
  10514.           }
  10515.           default:
  10516.             return(-2);
  10517.         }
  10518. #endif /* NOXFER */
  10519.     }
  10520.  
  10521.     switch (xx) {
  10522.  
  10523. #ifndef NOXMIT
  10524.       case XYXMIT:                      /* SET TRANSMIT */
  10525.         return(setxmit());
  10526. #endif /* NOXMIT */
  10527.  
  10528. #ifndef NOXFER
  10529. #ifndef NOCSETS
  10530.       case XYUNCS:                      /* UNKNOWN-CHARACTER-SET */
  10531.         if ((y = cmkey(ifdtab,2,"","discard",xxstring)) < 0) return(y);
  10532.         if ((x = cmcfm()) < 0) return(x);
  10533.         unkcs = y;
  10534.         return(success = 1);
  10535. #endif /* NOCSETS */
  10536. #endif /* NOXFER */
  10537.  
  10538. #ifndef NOPUSH
  10539. #ifdef UNIX
  10540.       case XYWILD:                      /* WILDCARD-EXPANSION */
  10541.         if ((y = cmkey(wildtab,2,
  10542.                        "Who expands wildcards","kermit",xxstring)) < 0)
  10543.           return(y);
  10544.         if ((z = cmkey(wdottab,
  10545.                        2,
  10546.                        "whether to match filenames that start with \".\"",
  10547.                        "/no-match-dot-files",
  10548.                        xxstring)
  10549.              ) < 0)
  10550.           return(z);
  10551.         if ((x = cmcfm()) < 0) return(x);
  10552.         if (nopush) {
  10553.             if (y > 0) {
  10554.                 printf("Shell expansion is disabled\n");
  10555.                 return(success = 0);
  10556.             }
  10557.         }
  10558.         wildxpand = y;
  10559.         matchdot = z;
  10560.         return(success = 1);
  10561. #endif /* UNIX */
  10562. #endif /* NOPUSH */
  10563.  
  10564. #ifndef NOXFER
  10565.       case XYWIND:                      /* WINDOW-SLOTS */
  10566.         if (protocol == PROTO_K) {
  10567.             y = cmnum("Window size for Kermit protocol, 1 to 32",
  10568.                       "1", 10, &x, xxstring);
  10569.             y = setnum(&z,x,y,MAXWS);   /* == 32 */
  10570.         }
  10571. #ifdef CK_XYZ
  10572.         else if (protocol == PROTO_Z) {
  10573.             y = cmnum("Window size for ZMODEM protocol, 0 to 65535",
  10574.                       "0", 10, &x, xxstring);
  10575.             y = setnum(&z,x,y,65535);
  10576.         }
  10577. #endif /* CK_XYZ */
  10578.         else {
  10579.             y = cmnum("Window size for current protocol",
  10580.                       "", 10, &x, xxstring);
  10581.             y = setnum(&z,x,y,65472);   /* Doesn't matter - we won't use it */
  10582.         }
  10583.         if (y < 0) return(y);
  10584.         if (protocol == PROTO_K) {
  10585.             if (z < 1)
  10586.               z = 1;
  10587.         }
  10588. #ifdef CK_XYZ
  10589.         else if (protocol == PROTO_Z) {
  10590.             /* Zmodem windowing is closer to Kermit packet length */
  10591.             /* than Kermit window size.  If Window size is zero   */
  10592.             /* an end of frame and CRC is sent only at the end of */
  10593.             /* the file (default).  Otherwise, an End of Frame    */
  10594.             /* and CRC are sent after Window Size number of bytes */
  10595.             if (z < 0)                  /* Disable windowing  */
  10596.               z = 0;
  10597.         } else {
  10598.             printf("?SET WINDOW does not apply to %s protocol\n",
  10599.                    ptab[protocol].p_name
  10600.                    );
  10601.         }
  10602. #endif /* CK_XYZ */
  10603.  
  10604. #ifdef COMMENT
  10605.         /* This is taken care of automatically now in protocol negotiation */
  10606.         if (maxtry < z) {
  10607.             printf("?Window slots must be less than retry limit\n");
  10608.             return(success = 0);
  10609.         }
  10610. #endif /* COMMENT */
  10611.         if (protocol == PROTO_K && rmsflg) { /* Set remote window size */
  10612.             wslotr = z;                 /* Set local window size too */
  10613.             ptab[protocol].winsize = wslotr;
  10614.             sstate = setgen('S', "406", ckitoa(z), "");
  10615.             return((int) sstate);
  10616.         }
  10617.         wslotr = z;                     /* Set requested window size here */
  10618.         ptab[protocol].winsize = wslotr; /* and in protocol-specific table */
  10619.         if (protocol == PROTO_K) {      /* And for Kermit only... */
  10620.             swcapr = (wslotr > 1) ? 1 : 0; /* set window bit in capas word */
  10621.             if (wslotr > 1) {           /* Window size > 1? */
  10622.                 /* Maybe adjust packet size */
  10623.                 y = adjpkl(urpsiz,wslotr,bigrbsiz);
  10624.                 if (y != urpsiz) {      /* Did it change? */
  10625.                     urpsiz = y;
  10626.                     if (msgflg)
  10627.                       printf(
  10628. " Adjusting receive packet-length to %d for %d window slots\n",
  10629.                              urpsiz,
  10630.                              wslotr
  10631.                              );
  10632.                 }
  10633.             }
  10634.         }
  10635.         return(success = 1);
  10636. #endif /* NOXFER */
  10637.     }
  10638.  
  10639.     switch (xx) {
  10640.  
  10641. #ifndef NOSPL
  10642.       case XYOUTP:                      /* OUTPUT command parameters */
  10643.         if ((y = cmkey(outptab,noutptab,"OUTPUT command parameter","pacing",
  10644.                        xxstring)) < 0)
  10645.           return(y);
  10646.         switch(y) {                     /* Which parameter */
  10647.           case OUT_PAC:                 /* PACING */
  10648.             y = cmnum("Milliseconds to pause between each OUTPUT character",
  10649.                       "100", 10,&x,xxstring);
  10650.             y = setnum(&z,x,y,16383);   /* Verify and get confirmation */
  10651.             if (y < 0) return(y);
  10652.             if (z < 0) z = 0;           /* (save some space) */
  10653.             pacing = z;
  10654.             return(success = 1);
  10655.           case OUT_ESC:                 /* Special-escapes */
  10656.             return(seton(&outesc));
  10657.           default:                      /* (shouldn't happen) */
  10658.             return(-2);
  10659.         }
  10660. #endif /* NOSPL */
  10661.  
  10662. #ifdef CK_SPEED
  10663.       case XYQCTL: {
  10664.           short *p;
  10665.           int zz;
  10666.           if ((z = cmkey(ctltab,2, "control-character prefixing option",""
  10667.                          ,xxstring)) < 0)
  10668.             return(z);
  10669.           /* Make space for a temporary copy of the prefixing table */
  10670.  
  10671.           p = (short *)malloc(256 * sizeof(short));
  10672.           if (!p) {
  10673.               printf("?Internal error - malloc failure\n");
  10674.               return(-9);
  10675.           }
  10676.           for (i = 0; i < 256; i++) p[i] = ctlp[i]; /* Copy current table */
  10677.  
  10678.           switch (z) {
  10679.             case 0:                     /* UNPREFIXED control character */
  10680.             case 1:                     /* PREFIXED control character */
  10681.               while (1) {               /* Collect a list of numbers */
  10682. #ifndef NOSPL
  10683.                   x_ifnum = 1;          /* Turn off complaints from eval() */
  10684. #endif /* NOSPL */
  10685.                   if ((x = cmnum((z == 0) ?
  10686. "\n Numeric ASCII value of control character that needs NO prefix,\n\
  10687.  or the word \"all\", or carriage return to complete the list" :
  10688. "\n Numeric ASCII value of control character that MUST BE prefixed,\n\
  10689.  or the word \"all\", or carriage return to complete the list",
  10690.                                  "",10,&y,xxstring
  10691.                                  )) < 0) {
  10692. #ifndef NOSPL
  10693.                       x_ifnum = 0;
  10694. #endif /* NOSPL */
  10695.                       if (x == -3) {
  10696.                           if ((x = cmcfm()) < 0) return(x);
  10697.                           break;
  10698.                       }
  10699.                       if (x == -2) {
  10700.                           if (p) { free((char *)p); p = NULL; }
  10701.                           debug(F110,"SET CONTROL atmbuf",atmbuf,0);
  10702.                           if (!ckstrcmp(atmbuf,"all",3,0) ||
  10703.                               !ckstrcmp(atmbuf,"al",2,0) ||
  10704.                               !ckstrcmp(atmbuf,"a",1,0)) {
  10705.                               if ((x = cmcfm()) < 0) /* Get confirmation */
  10706.                                 return(x);
  10707.                               if (z)
  10708.                                 prefixing = PX_ALL;
  10709. #ifndef UNPREFIXZERO
  10710.                               /* Set all values, but don't touch 0 */
  10711.                               for (y = 1; y < 32; y++) ctlp[y] = (short) z;
  10712. #else
  10713.                               /* Zero too */
  10714.                               for (y = 0; y < 32; y++) ctlp[y] = (short) z;
  10715. #endif /* UNPREFIXZERO */
  10716.                               for (y = 127; y < 160; y++) ctlp[y] = (short) z;
  10717.                               ctlp[255] = (short) z;
  10718.                               /* Watch out for XON and XOFF */
  10719.                               if (flow == FLO_XONX && z == 0) {
  10720.                                   if (msgflg) {
  10721.                                       printf(
  10722. " XON/XOFF characters 17, 19, 145, 147 not affected.\n");
  10723.                                       printf(
  10724. #ifdef CK_RTSCTS
  10725. " SET FLOW NONE or RTS/CTS to transmit these characters unprefixed.\n"
  10726. #else
  10727. " SET FLOW NONE to transmit these characters unprefixed.\n"
  10728. #endif /* CK_RTSCTS */
  10729.                                              );
  10730.                                   }
  10731.                                   ctlp[XON] =
  10732.                                     ctlp[XOFF] =
  10733.                                       ctlp[XON+128] =
  10734.                                         ctlp[XOFF+128] = 1;
  10735.                               }
  10736. #ifdef TNCODE
  10737.                               /* Watch out for TELNET IAC */
  10738.                               if (network &&
  10739.                                   (IS_TELNET()) && z == 0) {
  10740.                                   ctlp[255] = 1;
  10741.                                   if (parity == 'e' || parity == 'm')
  10742.                                     ctlp[127] = 1;
  10743.                                   ctlp[13] = 1;
  10744.                                   if (msgflg)
  10745.                                     printf(
  10746.                                " TELNET IAC = 255, CR = 13, not affected.\n");
  10747.                               }
  10748. #endif /* TNCODE */
  10749. #ifndef UNPREFIXZERO
  10750. #ifdef OS2
  10751.                               if (z == 0 && protocol != PROTO_K)
  10752.                                 ctlp[0] = 0;
  10753. #endif /* OS2 */
  10754. #endif /* UNPREFIXZERO */
  10755.                               return(success = 1);
  10756.                           } else {
  10757.                               printf(
  10758.                                  "?Please specify a number or the word ALL\n");
  10759.                               return(-9);
  10760.                           }
  10761.                       } else {
  10762.                           if (p) free((char *)p);
  10763.                           return(x);
  10764.                       }
  10765.                   }
  10766. #ifndef NOSPL
  10767.                   x_ifnum = 0;
  10768. #endif /* NOSPL */
  10769. #ifdef UNPREFIXZERO
  10770.                   zz = 0;
  10771. #else
  10772. #ifndef OS2
  10773.                   zz = 1 - z;
  10774. #else
  10775.                   zz = 0;               /* Allow 0 (but only for Zmodem) */
  10776. #endif /* OS2 */
  10777. #endif /* UNPREFIXZERO */
  10778.  
  10779.             /* printf("x = %d, y = %d, z = %d, zz = %d\n", x,y,z,zz); */
  10780.  
  10781.                   if ((y >  31 && y < 127) || /* A specific numeric value */
  10782.                       (y > 159 && y < 255) || /* Check that it is a valid */
  10783.                       (y < zz) ||       /* control code. */
  10784.                       (y > 255)) {
  10785.                       printf("?Values allowed are: %d-31, 127-159, 255\n",zz);
  10786.                       if (p) free((char *)p);
  10787.                       return(-9);
  10788.                   }
  10789.                   x = y & 127;          /* Get 7-bit value */
  10790.                   if (z == 0) {         /* If they are saying it is safe... */
  10791.                       /* If flow control is Xon/Xoff */
  10792.                       if (((flow == FLO_XONX) &&
  10793.                            /* XON & XOFF chars not safe. */
  10794.                            (x == XON || x == XOFF))
  10795.                           ) {
  10796.                           if (msgflg)
  10797.                             printf(
  10798.                               "Sorry, not while Xon/Xoff is in effect.\n");
  10799.                           if (p) free((char *)p);
  10800.                           return(-9);
  10801.                       }
  10802. #ifdef TNCODE
  10803.                       else if (network && IS_TELNET()
  10804.                                && (y == CR ||
  10805.                                    (unsigned) y == (unsigned) 255)) {
  10806.                           if (msgflg)
  10807.                             printf("Sorry, not on a TELNET connection.\n");
  10808.                           if (p) free((char *)p);
  10809.                           return(-9);
  10810.                       }
  10811. #endif /* TNCODE */
  10812.                   }
  10813.                   p[y] = (char) z;      /* All OK, set flag */
  10814.               } /* End of while loop */
  10815. /*
  10816.   Get here only if they have made no mistakes.  Copy temporary table back to
  10817.   permanent one, then free temporary table and return successfully.
  10818. */
  10819.               for (i = 0; i < 256; i++) ctlp[i] = p[i];
  10820.               if (p) free((char *)p);
  10821.               if (z > 0) clearrq = 0;   /* 199 (see SET PREFIXING) */
  10822.               return(success = 1);
  10823.             default:
  10824.               return(-2);
  10825.           }
  10826.       }
  10827. #endif /* CK_SPEED */
  10828.     }
  10829.  
  10830.     switch (xx) {
  10831.  
  10832. #ifndef NOXFER
  10833.       case XYREPT:
  10834.         if ((y = cmkey(rpttab,2,
  10835.                        "repeat-count compression parameter","",xxstring)) < 0)
  10836.           return(y);
  10837.         switch(y) {
  10838.           case 0:
  10839.             return(success = seton(&rptena)); /* REPEAT COUNTS = ON, OFF */
  10840.           case 1:                       /* REPEAT MININUM number */
  10841.             printf("(not implemented yet, nothing happens)\n");
  10842.             return(-9);
  10843.           case 2:                       /* REPEAT PREFIX char */
  10844.             if ((x = cmnum("ASCII value","",10,&z,xxstring)) < 0)
  10845.               return(x);
  10846.             if ((x = cmcfm()) < 0) return(x);
  10847.             if ((z > 32 && z < 63) || (z > 95 && z < 127)) {
  10848.                 if (y == 1) rptmin = (CHAR) z; else myrptq = (CHAR) z;
  10849.                 return(success = 1);
  10850.             } else {
  10851.                 printf("?Illegal value for prefix character\n");
  10852.                 return(-9);
  10853.             }
  10854.         }
  10855. #endif /* NOXFER */
  10856.  
  10857. #ifndef NOSPL
  10858.       case XYALRM: {
  10859. #ifndef COMMENT
  10860.           int yy;
  10861.           long zz;
  10862.           zz = -1L;
  10863.           yy = x_ifnum;
  10864.           x_ifnum = 1;                  /* Turn off internal complaints */
  10865.           y = cmnum("Seconds from now, or time of day as hh:mm:ss",
  10866.                     "0" ,10, &x, xxstring);
  10867.           x_ifnum = yy;
  10868.           if (y < 0) {
  10869.               if (y == -2) {            /* Invalid number or expression */
  10870.                   zz = tod2sec(atmbuf); /* Convert to secs since midnight */
  10871.                   if (zz < 0L) {
  10872.                       printf("?Number, expression, or time of day required\n");
  10873.                       return(-9);
  10874.                   } else {
  10875.                       char now[32];     /* Current time */
  10876.                       char *p;
  10877.                       long tnow;
  10878.                       p = now;
  10879.                       ztime(&p);
  10880.                       tnow = atol(p+11) * 3600L +
  10881.                         atol(p+14) * 60L + atol(p+17);
  10882.                       if (zz < tnow)    /* User's time before now */
  10883.                         zz += 86400L;   /* So make it tomorrow */
  10884.                       zz -= tnow;       /* Seconds from now. */
  10885.                   }
  10886.               } else
  10887.                 return(y);
  10888.           }
  10889.           if (x < 0) {
  10890.               printf("?Alarm time is in the past.\n");
  10891.               return(-9);
  10892.           }
  10893.           if ((y = cmcfm()) < 0) return(y);
  10894.           if (zz > -1L) {               /* Time of day given? */
  10895.               x = zz;
  10896.               if (zz != (long) x) {
  10897.                   printf(
  10898. "Sorry, arithmetic overflow - hh:mm:ss not usable on this platform.\n"
  10899.                          );
  10900.                   return(-9);
  10901.               }
  10902.           }
  10903.           return(setalarm((long)x));
  10904.       }
  10905. #else
  10906. /*
  10907.   This is to allow long values where int and long are not the same, e.g.
  10908.   on 16-bit systems.  But something is wrong with it.
  10909. */
  10910.         if ((y = cmtxt("seconds from now", "0", &s, xxstring)) < 0)
  10911.           return(y);
  10912.         if (rdigits(s)) {
  10913.             return(setalarm(atol(s)));
  10914.         } else {
  10915.             printf("%s - not a number\n",s);
  10916.             return(-9);
  10917.         }
  10918. #endif /* COMMENT */
  10919. #endif /* NOSPL */
  10920.  
  10921. #ifndef NOXFER
  10922.       case XYPROTO:
  10923.         return(setproto());
  10924. #endif /* NOXFER */
  10925.  
  10926. /*
  10927.   C-Kermit unprefixes control characters automatically on network connections
  10928.   if CLEAR-CHANNEL is ON, which it is by default.  But not all network
  10929.   connections are transparent to all control characters.  For example, the
  10930.   DEC-20, even when you TELNET to it, is sensitive to Ctrl-O and Ctrl-T.
  10931.   If you tell C-Kermit to SET CONTROL PREFIX 15 and/or 20, it doesn't help
  10932.   because CLEAR-CHANNEL is still in effect.  If the user goes to the trouble
  10933.   to set up some prefixing, then Kermit do what the user said.  In C-Kermit
  10934.   7.1 Alpha.03 we change the code to set clearrq to 0 if the user gives a
  10935.   SET PREFIXING or SET CONTROL PREFIX command.
  10936. */
  10937.  
  10938. #ifdef CK_SPEED
  10939.       case XYPREFIX: {
  10940. #ifdef COMMENT
  10941.           extern int clearrq;
  10942. #endif /* COMMENT */
  10943.           if ((z = cmkey(pfxtab, 4, "control-character prefixing option",
  10944.                          "", xxstring)) < 0)
  10945.             return(z);
  10946.           if ((x = cmcfm()) < 0) return(x);
  10947.           clearrq = 0;                  /* 199 */
  10948.           setprefix(z);
  10949. #ifdef COMMENT
  10950.           if (hints && (z == PX_ALL || z == PX_CAU) && clearrq) {
  10951.         printf("Hint: Use SET CLEAR-CHANNEL OFF to disable negotiation of\n");
  10952.         printf("      SET PREFIXING NONE during file transfers on reliable\n");
  10953.         printf("      connections.\n");
  10954.           }
  10955. #endif /* COMMENT */
  10956.           return(success = 1);
  10957.       }
  10958. #endif /* CK_SPEED */
  10959.  
  10960. #ifndef NOSPL
  10961.       case XYLOGIN:
  10962.         if ((z = cmkey(logintab, 3, "value for login script","userid",
  10963.                        xxstring)) < 0)
  10964.           return(z);
  10965.         x = cmdgquo();
  10966.         if (z == LOGI_PSW)
  10967.           cmdsquo(0);
  10968.         if ((y = cmtxt("text","", &s, NULL)) < 0) {
  10969.             cmdsquo(x);
  10970.             return(y);
  10971.         }
  10972.         cmdsquo(x);
  10973. #ifdef IKSD
  10974.         if (inserver)
  10975.           return(success = 0);
  10976. #endif /* IKSD */
  10977.         s = brstrip(s);
  10978.         if ((int)strlen(s) > 63) {
  10979.             printf("Sorry, too long\n");
  10980.             return(-9);
  10981.         }
  10982.         switch(z) {
  10983.           case LOGI_UID:
  10984.             ckstrncpy(uidbuf,s,UIDBUFLEN);
  10985.             sl_uid_saved = 0;
  10986.             break;
  10987.           case LOGI_PSW:
  10988.             ckstrncpy(pwbuf,s,PWBUFL);
  10989.             if (pwbuf[0]) {
  10990.                 pwflg = 1;
  10991. #ifdef OS2
  10992.                 pwcrypt = 1;
  10993. #else /* OS2 */
  10994.                 pwcrypt = 0;
  10995. #endif /* OS2 */
  10996.             }
  10997.             break;
  10998.           case LOGI_PRM:
  10999.             ckstrncpy(prmbuf,s,PWBUFL);
  11000.         }
  11001.         return(success = 1);
  11002. #endif /* NOSPL */
  11003.     }
  11004.  
  11005.     switch (xx) {
  11006.  
  11007.       case XYSTARTUP:
  11008.         if ((y = cmkey(ifdtab,2,"","discard",xxstring)) < 0) return(y);
  11009.         if ((x = cmcfm()) < 0) return(x);
  11010.         DeleteStartupFile = (y != 0) ? 0 : 1;
  11011.         return(success = 1);
  11012.  
  11013.       case XYTMPDIR:
  11014.         x = cmdir("Name of temporary directory","",&s,xxstring);
  11015.         if (x == -3)
  11016.           s = "";
  11017.         else if (x < 0)
  11018.           return(x);
  11019.         if ((x = cmcfm()) < 0) return(x);
  11020.         makestr(&tempdir,s);
  11021.         return(tempdir ? 1 : 0);
  11022.  
  11023. #ifndef NOXFER
  11024.       case XYDEST:                      /* DESTINATION */
  11025.         return(setdest());
  11026. #endif /* NOXFER */
  11027.  
  11028. #ifndef NOPUSH
  11029. #ifndef NOFRILLS
  11030.  
  11031. /* Editor, Browser, and FTP Client */
  11032.  
  11033.       case XYEDIT:                      /* EDITOR */
  11034. #ifdef IKSD
  11035.         if (inserver) {
  11036.             printf("?Sorry, command disabled.\r\n");
  11037.             return(success = 0);
  11038.         }
  11039. #endif /* IKSD */
  11040. #ifdef CK_APC
  11041.         /* Don't let this be set remotely */
  11042.         if (apcactive == APC_LOCAL ||
  11043.             (apcactive == APC_REMOTE && !(apcstatus & APC_UNCH)))
  11044.           return(success = 0);
  11045. #endif /* CK_APC */
  11046.  
  11047. #ifdef OS2ORUNIX
  11048.         {
  11049.             char *p = getenv("PATH");
  11050.             char *e;
  11051.             e = editor[0] ? (char *) editor : getenv("EDITOR");
  11052.             if (!e) e = "";
  11053.             if (p)
  11054.               x = cmifip("Name of preferred editor",e,&s,&y,0,p,xxstring);
  11055.             else
  11056.               x = cmifi("Full path of preferred editor",e,&s,&y,xxstring);
  11057.             if (x < 0 && x != -3)
  11058.               return(x);
  11059.         }
  11060. #else
  11061. #ifdef VMS
  11062.         if ((y = cmtxt("DCL command for editing", "edit", &s, NULL)) < 0) {
  11063.             if (x != -3)
  11064.               return(x);
  11065.         }
  11066. #else
  11067.         if ((x = cmifi("Full path of preferred editor","",&s,&y,xxstring))<0) {
  11068.             if (x != -3)
  11069.               return(x);
  11070.         }
  11071. #endif /* VMS */
  11072. #endif /* OS2ORUNIX */
  11073. #ifdef VMS
  11074.         ckstrncpy(editor,s,CKMAXPATH);
  11075.         editopts[0] = NUL;
  11076. #else
  11077.         if (y != 0) {
  11078.             printf("?A single file please\n");
  11079.             return(-2);
  11080.         }
  11081.         ckstrncpy(line,s,LINBUFSIZ);
  11082.         if ((x = cmtxt("editor command-line options","",&s,NULL)) < 0)
  11083.           return(x);
  11084.         ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  11085.         if ((z = cmcfm()) < 0) return(z);
  11086.         if (line[0]) {
  11087.             zfnqfp(line,CKMAXPATH,editor);
  11088.             ckstrncpy(editopts,tmpbuf,128);
  11089.         } else {
  11090.             editor[0] = NUL;
  11091.             editopts[0] = NUL;
  11092.         }
  11093. #endif /* VMS */
  11094.         return(success = 1);
  11095.  
  11096. #ifndef NOFTP
  11097. #ifndef SYSFTP
  11098. #ifdef TCPSOCKET
  11099.       case XYFTPX:
  11100.         return(dosetftp());             /* SET FTP */
  11101. #endif /* TCPSOCKET */
  11102. #endif /* SYSFTP */
  11103. #endif /* NOFTP */
  11104.  
  11105. #ifdef BROWSER
  11106. #ifndef NOFTP
  11107. #ifdef SYSFTP
  11108.       case XYFTP:                       /* SET FTP-CLIENT */
  11109. #endif /* SYSFTP */
  11110. #endif /* NOFTP */
  11111.       case XYBROWSE:                    /* SET BROWSER */
  11112.         {
  11113.             char *p = getenv("PATH");
  11114.             char *app = (char *) browser, *opts = (char *) browsopts;
  11115. #ifndef NOFTP
  11116. #ifdef SYSFTP
  11117.             extern char ftpapp[], ftpopts[];
  11118.             if (xx == XYFTP) {
  11119.                 app = (char *)ftpapp;
  11120.                 opts = (char *)ftpopts;
  11121.             }
  11122. #endif /* SYSFTP */
  11123. #endif /* NOFTP */
  11124. #ifdef IKSD
  11125.             if (inserver) {
  11126.                 printf("?Sorry, command disabled.\r\n");
  11127.                 return(success = 0);
  11128.             }
  11129. #endif /* IKSD */
  11130. #ifdef CK_APC
  11131.             /* Don't let this be set remotely */
  11132.             if (apcactive == APC_LOCAL ||
  11133.                 (apcactive == APC_REMOTE && !(apcstatus & APC_UNCH)))
  11134.               return(success = 0);
  11135. #endif /* CK_APC */
  11136. #ifdef OS2ORUNIX
  11137.             if (p)
  11138.               x = cmifip(xx == XYBROWSE ?
  11139.                          "Name of preferred browser" :
  11140.                          "Name of preferred ftp client",
  11141. #ifdef OS2
  11142.                          xx == XYFTP ? "ftp.exe" : ""
  11143. #else
  11144.                          xx == XYFTP ? "ftp" : ""
  11145. #endif /* OS2 */
  11146.                          ,&s,&y,0,p,xxstring
  11147.                          );
  11148.             else
  11149.               x = cmifi(xx == XYBROWSE ?
  11150.                         "Full path of preferred browser" :
  11151.                         "Full path of preferred ftp client",
  11152.                         "",&s,&y,xxstring
  11153.                         );
  11154.             if (x < 0 && x != -3)
  11155.               return(x);
  11156. #else
  11157. #ifdef VMS
  11158.             if ((x = cmtxt("DCL command to start your preferred Web browser",
  11159.                            "", &s, NULL)) < 0) {
  11160.                 if (x != -3)
  11161.                   return(x);
  11162.             }
  11163. #else
  11164.             if ((x = cmifi("Full path of preferred browser","",&s,&y,xxstring)
  11165.                  ) < 0) {
  11166.                 if (x != -3)
  11167.                   return(x);
  11168.             }
  11169. #endif /* VMS */
  11170. #endif /* OS2ORUNIX */
  11171. #ifdef VMS
  11172.             ckstrncpy(app,s,CKMAXPATH);
  11173.             *opts = NUL;
  11174. #else
  11175.             if (y != 0) {
  11176.                 printf("?A single file please\n");
  11177.                 return(-2);
  11178.             }
  11179.             ckstrncpy(line,s,LINBUFSIZ);
  11180.             if ((x = cmtxt(xx == XYBROWSE ?
  11181.                            "browser command-line options" :
  11182.                            "ftp client command-line options",
  11183.                            "",&s,NULL)
  11184.                  ) < 0)
  11185.               return(x);
  11186.             ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  11187.             if ((z = cmcfm()) < 0) return(z);
  11188.             if (line[0]) {
  11189.                 zfnqfp(line,CKMAXPATH,app);
  11190.                 ckstrncpy(opts, tmpbuf, 128);
  11191.             } else {
  11192.                 *app = NUL;
  11193.                 *opts = NUL;
  11194.             }
  11195. #endif /* VMS */
  11196.             return(success = 1);
  11197.         }
  11198. #endif /* BROWSER */
  11199. #endif /* NOFRILLS */
  11200. #endif /* NOPUSH */
  11201.  
  11202. #ifdef CK_CTRLZ
  11203.       case XYEOF: {                     /* SET EOF */
  11204.           extern int eofmethod; extern struct keytab eoftab[];
  11205.           if ((x = cmkey(eoftab,3,"end-of-file detection method","",
  11206.                          xxstring)) < 0)
  11207.             return(x);
  11208.           if ((y = cmcfm()) < 0)
  11209.             return(y);
  11210.           eofmethod = x;
  11211.           return(success = 1);
  11212.       }
  11213. #endif /* CK_CTRLZ */
  11214.  
  11215. #ifdef SESLIMIT
  11216.       case XYLIMIT: {  /* Session-Limit (length of session in seconds) */
  11217.           extern int seslimit;
  11218.           y = cmnum("Maximum length of session, seconds","0",10,&x,xxstring);
  11219. #ifdef IKSD
  11220.           if (inserver &&
  11221. #ifdef IKSDCONF
  11222.               iksdcf
  11223. #else
  11224.               1
  11225. #endif /* IKSDCONF */
  11226.               ) {
  11227.               if ((z = cmcfm()) < 0)
  11228.                 return(z);
  11229.               printf("?Sorry, command disabled.\r\n");
  11230.               return(success = 0);
  11231.           }
  11232. #endif /* IKSD */
  11233.  
  11234.           return(setnum(&seslimit,x,y,86400));
  11235.       }
  11236. #endif /* SESLIMIT */
  11237.  
  11238.       case XYRELY: {                    /* SET RELIABLE */
  11239.           if ((x = cmkey(ooatab,3,"","automatic",xxstring)) < 0)
  11240.             return(x);
  11241.           if ((y = cmcfm()) < 0) return(y);
  11242.           reliable = x;
  11243.           setreliable = (x != SET_AUTO);
  11244.           debug(F101,"SET RELIABLE reliable","",reliable);
  11245.           return(success = 1);
  11246.       }
  11247.  
  11248. #ifdef STREAMING
  11249.       case XYSTREAM: {                  /* SET STREAMING */
  11250.           extern int streamrq;
  11251.           if ((x = cmkey(ooatab,3,"","automatic",xxstring)) < 0)
  11252.             return(x);
  11253.           if ((y = cmcfm()) < 0) return(y);
  11254.           streamrq = x;
  11255.           return(success = 1);
  11256.       }
  11257. #endif /* STREAMING */
  11258.  
  11259. #ifdef CKSYSLOG
  11260.       case XYSYSL: {
  11261.           if ((x = cmkey(syslogtab,nsyslog,"","",xxstring)) < 0)
  11262.             return(x);
  11263.           if ((y = cmcfm()) < 0) return(y);
  11264. #ifdef IKSD
  11265.           if (inserver &&
  11266. #ifdef IKSDCONF
  11267.               iksdcf
  11268. #else
  11269.               1
  11270. #endif /* IKSDCONF */
  11271.               ) {
  11272.               printf("?Sorry, command disabled.\n");
  11273.               return(success = 0);
  11274.           }
  11275. #endif /* IKSD */
  11276. #ifdef CK_APC
  11277.           /* Don't let this be set remotely */
  11278.           if (apcactive == APC_LOCAL ||
  11279.               (apcactive == APC_REMOTE && !(apcstatus & APC_UNCH)))
  11280.             return(success = 0);
  11281. #endif /* CK_APC */
  11282.           ckxsyslog = x;
  11283.           return(success = 1);
  11284.       }
  11285. #endif /* CKSYSLOG */
  11286.  
  11287. #ifdef TLOG
  11288.       case XYTLOG: {                    /* SET TRANSACTION-LOG */
  11289.           extern int tlogsep;
  11290.           if ((x = cmkey(vbtab,nvb,"","verbose",xxstring)) < 0)
  11291.             return(x);
  11292.           if (x == 0) {
  11293.               if ((y = cmtxt("field separator",",",&s,NULL)) < 0) return(y);
  11294.               s = brstrip(s);
  11295.               if (*s) {
  11296.                   if (s[1]) {
  11297.                       printf("?A single character, please.\n");
  11298.                       return(-9);
  11299.                   } else if ((*s >= '0' && *s <= '9') ||
  11300.                              (*s >= 'A' && *s <= 'Z') ||
  11301.                              (*s >= 'a' && *s <= 'z')) {
  11302.                       printf("?A non-alphanumeric character, please.\n");
  11303.                       return(-9);
  11304.                   } else
  11305.                     tlogsep = *s;
  11306.               }
  11307.           } else {
  11308.               if ((y = cmcfm()) < 0) return(y);
  11309.           }
  11310. #ifdef IKSD
  11311.           if (inserver && isguest) {
  11312.               printf("?Sorry, command disabled.\n");
  11313.               return(success = 0);
  11314.           }
  11315. #endif /* IKSD */
  11316. #ifdef CK_APC
  11317.           /* Don't let this be set remotely */
  11318.           if (apcactive == APC_LOCAL ||
  11319.               (apcactive == APC_REMOTE && !(apcstatus & APC_UNCH)))
  11320.             return(success = 0);
  11321. #endif /* CK_APC */
  11322.           tlogfmt = x;
  11323.           return(success = 1);
  11324.       }
  11325. #endif /* TLOG */
  11326.  
  11327.       case XYCLEAR: {                   /* SET CLEARCHANNEL */
  11328.           if ((x = cmkey(ooatab,3,"","automatic",xxstring)) < 0)
  11329.             return(x);
  11330.           if ((y = cmcfm()) < 0) return(y);
  11331.           clearrq = x;
  11332.           return(success = 1);
  11333.       }
  11334.  
  11335. #ifdef CK_AUTHENTICATION
  11336.       case XYAUTH: {                    /* SET AUTHENTICATION */
  11337. #ifdef CK_KERBEROS
  11338.           int kv = 0;
  11339.           extern struct krb_op_data krb_op;
  11340. #endif /* CK_KERBEROS */
  11341.           char * p = NULL;
  11342.           if ((x =
  11343.                cmkey(setauth,nsetauth,"authentication type","",xxstring)) < 0)
  11344.             return(x);
  11345.           switch (x) {
  11346. #ifdef CK_KERBEROS
  11347.             case AUTH_KRB4: kv = 4; break; /* Don't assume values are same */
  11348.             case AUTH_KRB5: kv = 5; break;
  11349. #endif /* CK_KERBEROS */
  11350. #ifdef CK_SRP
  11351.             case AUTH_SRP: break;
  11352. #endif /* CK_SRP */
  11353. #ifdef CK_SSL
  11354.             case AUTH_SSL:
  11355.             case AUTH_TLS:
  11356.               break;
  11357. #endif /* CK_SSL */
  11358.             default:
  11359.               printf("?Authorization type not supported yet - \"%s\"\n",
  11360.                      atmbuf);
  11361.               return(-9);
  11362.           }
  11363. #ifdef IKSD
  11364.           if (inserver &&
  11365. #ifdef IKSDCONF
  11366.               iksdcf
  11367. #else
  11368.               1
  11369. #endif /* IKSDCONF */
  11370.               ) {
  11371.               if ((y = cmcfm()) < 0) return(y);
  11372.               printf("?Sorry, command disabled.\n");
  11373.               return(success = 0);
  11374.           }
  11375. #endif /* IKSD */
  11376. #ifdef CK_APC
  11377.           /* Don't let this be set remotely */
  11378.           if (apcactive == APC_LOCAL ||
  11379.               apcactive == APC_REMOTE && !(apcstatus & APC_UNCH)) {
  11380.               if ((y = cmcfm()) < 0) return(y);
  11381.               return(success = 0);
  11382.           }
  11383. #endif /* CK_APC */
  11384.  
  11385.           switch(x) {
  11386. #ifdef CK_KERBEROS
  11387.             case AUTH_KRB4:
  11388.             case AUTH_KRB5: {
  11389.                 if ((x = cmkey(kv == 4 ? k4tab : k5tab,
  11390.                                kv == 4 ? nk4tab : nk5tab,
  11391.                                "Kerberos parameter","",xxstring)) < 0) {
  11392.                     return(x);
  11393.                 }
  11394.                 s = "";
  11395.                 switch (x) {
  11396. #ifdef KRB4
  11397.                   case XYKRBDBG:
  11398.                     if (kv == 4) {
  11399.                         if ((y = seton(&k4debug)) < 0)
  11400.                           return(y);
  11401. #ifdef NT
  11402.                         ck_krb4_debug(k4debug);
  11403. #endif /* NT */
  11404.                     } else {
  11405.                         return(-9);
  11406.                     }
  11407.                     break;
  11408. #endif /* KRB4 */
  11409.                   case XYKRBLIF:
  11410.                     if ((y = cmnum("TGT lifetime","600",10,&z,xxstring)) < 0)
  11411.                       return(y);
  11412.                     break;
  11413.                   case XYKRBPRE:
  11414.                     if (kv == 4) {
  11415.                         if ((y = seton(&krb4_d_preauth)) < 0)
  11416.                           return(y);
  11417.                     } else {
  11418.                         return(-9);
  11419.                     }
  11420.                     break;
  11421.                   case XYKRBINS:
  11422.                     if ((y = cmtxt("Instance name","",&s,xxstring)) < 0)
  11423.                       return(y);
  11424.                     break;
  11425.                   case XYKRBFWD:
  11426.                     if (kv == 5) {
  11427.                         if ((y = seton(&krb5_d_forwardable)) < 0)
  11428.                           return(y);
  11429.                     } else {
  11430.                         return(-9);
  11431.                     }
  11432.                     break;
  11433.                   case XYKRBPRX:
  11434.                     if (kv == 5) {
  11435.                         if ((y = seton(&krb5_d_proxiable)) < 0)
  11436.                           return(y);
  11437.                     } else {
  11438.                         return(-9);
  11439.                     }
  11440.                     break;
  11441.                   case XYKRBRNW:
  11442.                     if ((y = cmnum("TGT renewable lifetime",
  11443.                                    "0",10,&z,xxstring)) < 0)
  11444.                       return(y);
  11445.                     break;
  11446.                   case XYKRBADR:
  11447.                     if (kv == 5) {
  11448.                         if ((y = seton(&krb5_checkaddrs)) < 0)
  11449.                           return(y);
  11450.                     } else {
  11451.                         if ((y = seton(&krb4_checkaddrs)) < 0)
  11452.                           return(y);
  11453.                     }
  11454.                     break;
  11455.                   case XYKRBNAD:
  11456.                     if (kv == 5) {
  11457.                         if ((y = seton(&krb5_d_no_addresses)) < 0)
  11458.                           return(y);
  11459.                     }
  11460.                     break;
  11461.                   case XYKRBADD:
  11462.                     if (kv == 5) {
  11463.                         char * tmpaddrs[KRB5_NUM_OF_ADDRS];
  11464.                         for (i = 0; i < KRB5_NUM_OF_ADDRS; i++)
  11465.                           tmpaddrs[i] = NULL;
  11466.  
  11467.                         if ((y =
  11468.                              cmfld("List of IP addresses","",&s,xxstring)) < 0)
  11469.                           return(y);
  11470.                         makelist(s,tmpaddrs,KRB5_NUM_OF_ADDRS);
  11471.                         if ((y = cmcfm()) < 0) {
  11472.                             for (i = 0; i < KRB5_NUM_OF_ADDRS; i++) {
  11473.                                 if (tmpaddrs[i] != NULL)
  11474.                                   free(tmpaddrs[i]);
  11475.                             }
  11476.                             return(y);
  11477.                         }
  11478.                         for (i = 0;
  11479.                              i < KRB5_NUM_OF_ADDRS && tmpaddrs[i];
  11480.                              i++) {
  11481.                             if (inet_addr(tmpaddrs[i]) == 0xffffffff) {
  11482.                                 printf("invalid ip address: %s\n",
  11483.                                        tmpaddrs[i]);
  11484.                                 for (i = 0; i < KRB5_NUM_OF_ADDRS; i++) {
  11485.                                     if (tmpaddrs[i] != NULL)
  11486.                                       free(tmpaddrs[i]);
  11487.                                 }
  11488.                                 return(-9);
  11489.                             }
  11490.                         }
  11491.                         for (i = 0;
  11492.                              i < KRB5_NUM_OF_ADDRS && krb5_d_addrs[i];
  11493.                              i++) {
  11494.                             if (krb5_d_addrs[i])
  11495.                               free(krb5_d_addrs[i]);
  11496.                             krb5_d_addrs[i] = NULL;
  11497.                         }
  11498.                         for (i = 0;
  11499.                              i < KRB5_NUM_OF_ADDRS && tmpaddrs[i];
  11500.                              i++) {
  11501.                             krb5_d_addrs[i] = tmpaddrs[i];
  11502.                             tmpaddrs[i] = NULL;
  11503.                         }
  11504.                         krb5_d_addrs[i] = NULL;
  11505.                         return(success = 1);
  11506.                     }
  11507.                     break;
  11508.  
  11509.                   case XYKRBGET:
  11510.                     if (kv == 5) {
  11511.                         if ((y = seton(&krb5_autoget)) < 0)
  11512.                           return(y);
  11513.                     } else {
  11514.                         if ((y = seton(&krb4_autoget)) < 0)
  11515.                           return(y);
  11516.                     }
  11517.                     break;
  11518.                   case XYKRBDEL:
  11519.                     if ((z = cmkey(kdestab,nkdestab,
  11520.                                    "Auto Destroy Tickets",
  11521.                                    "never",xxstring)) < 0)
  11522.                       return(z);
  11523.                     break;
  11524.                   case XYKRBPR:
  11525.                     if ((y = cmtxt("User ID",uidbuf,&s,xxstring)) < 0)
  11526.                       return(y);
  11527.                     break;
  11528.                   case XYKRBRL:
  11529.                     if ((y = cmtxt("Name of realm","",&s,xxstring)) < 0)
  11530.                       return(y);
  11531.                     break;
  11532.                   case XYKRBKTB:
  11533.                     y = cmifi("Filename","",&s,&z,xxstring);
  11534.                     if (y != -3) {
  11535.                        if (y < 0)
  11536.                          return(y);
  11537.                        if (z) {
  11538.                          printf("?Wildcards not allowed\n");
  11539.                          return(-9);
  11540.                        }
  11541.                     }
  11542.                     break;
  11543.                   case XYKRBCC:
  11544.                     if ((y = cmofi("Filename","",&s,xxstring)) < 0)
  11545.                       return(y);
  11546.                     break;
  11547.                   case XYKRBSRV:
  11548.                     if ((y = cmtxt("Name of service to use in ticket",
  11549.                                    (kv == 4 ? "rcmd" : "host"),
  11550.                                    &s,
  11551.                                    xxstring
  11552.                                    )) < 0)
  11553.                       return(y);
  11554.                     break;
  11555.                   case XYKRBK5K4:
  11556.                     if (kv == 5) {
  11557.                         if ((y = seton(&krb5_d_getk4)) < 0)
  11558.                           return(y);
  11559.                     } else {
  11560.                         return(-9);
  11561.                     }
  11562.                     break;
  11563.                   case XYKRBPRM:        /* Prompt */
  11564.                     if ((z = cmkey(krbprmtab,2,"","",xxstring)) < 0)
  11565.                       return(z);
  11566.                     if ((y = cmtxt((z == KRB_PW_PRM) ?
  11567.   "Text of prompt;\nmay contain \"%s\" to be replaced by principal name" :
  11568.   "Text of prompt",
  11569.                                    "",
  11570.                                    &s,
  11571.                                    xxstring
  11572.                                    )
  11573.                          ) < 0)
  11574.                       return(y);
  11575.                     break;
  11576.                 }
  11577.                 ckstrncpy(line,s,LINBUFSIZ);
  11578.                 s = line;
  11579.                 if ((y = cmcfm()) < 0)
  11580.                   return(y);
  11581. #ifdef IKSD
  11582.                 if (inserver &&
  11583. #ifdef IKSDCONF
  11584.                     iksdcf
  11585. #else /* IKSDCONF */
  11586.                     1
  11587. #endif /* IKSDCONF */
  11588.                     )
  11589.                   return(success = 0);
  11590. #endif /* IKSD */
  11591.  
  11592.                 switch (x) {            /* Copy value to right place */
  11593.                   case XYKRBLIF:        /* Lifetime */
  11594.                     if (kv == 4)
  11595.                       krb4_d_lifetime = z;
  11596.                     else
  11597.                       krb5_d_lifetime = z;
  11598.                     break;
  11599.                   case XYKRBRNW:
  11600.                     if (kv == 5)
  11601.                       krb5_d_renewable = z;
  11602.                     break;
  11603.                   case XYKRBPR:         /* Principal */
  11604.                     s = brstrip(s);             /* Strip braces around. */
  11605.                     if (kv == 4)
  11606.                       makestr(&krb4_d_principal,s);
  11607.                     else
  11608.                       makestr(&krb5_d_principal,s);
  11609.                     break;
  11610.                   case XYKRBINS:        /* Instance */
  11611.                     if (kv == 4)
  11612.                       makestr(&krb4_d_instance,s);
  11613.                     else
  11614.                       makestr(&krb5_d_instance,s);
  11615.                     break;
  11616.                   case XYKRBRL:         /* Realm */
  11617.                     if (kv == 4)
  11618.                       makestr(&krb4_d_realm,s);
  11619.                     else
  11620.                       makestr(&krb5_d_realm,s);
  11621.                     break;
  11622.                   case XYKRBKTB:        /* Key Table */
  11623.                     if (kv == 4)
  11624.                       makestr(&k4_keytab,s);
  11625.                     else
  11626.                       makestr(&k5_keytab,s);
  11627.                     break;
  11628.                   case XYKRBCC:         /* Credentials cache */
  11629.                     makestr(&krb5_d_cc,s);
  11630.                     break;
  11631.                   case XYKRBSRV:        /* Service Name */
  11632.                     if (kv == 4)
  11633.                       makestr(&krb4_d_srv,s);
  11634.                     else
  11635.                       makestr(&krb5_d_srv,s);
  11636.                     break;
  11637.                   case XYKRBDEL:
  11638.                     if (kv == 5)
  11639.                       krb5_autodel = z;
  11640.                     else
  11641.                       krb4_autodel = z;
  11642.                     break;
  11643.                   case XYKRBPRM:        /* Prompt */
  11644.                     if (s == "") s = NULL;
  11645.                     if (s) {
  11646.                         s = brstrip(s);
  11647.                         if (s == "") s = NULL;
  11648.                     }
  11649.                     switch (z) {
  11650.                       case KRB_PW_PRM: { /* Password */
  11651.                           /* Check that there are no more than */
  11652.                           /* two % fields and % must followed by 's'. */
  11653.                           int i,n,len;
  11654.                           len = strlen(s);
  11655.                           for (i = 0, n = 0; i < len; i++) {
  11656.                               if (s[i] == '%') {
  11657.                                   if (s[i+1] != '%') {
  11658.                                       if (s[i+1] != 's') {
  11659.                                           printf(
  11660.                                            "Only %%s fields are permitted.\n"
  11661.                                                  );
  11662.                                           return(-9);
  11663.                                       }
  11664.                                       if (++n > 2) {
  11665.                                           printf(
  11666.                                       "Only two %%s fields are permitted.\n");
  11667.                                           return(-9);
  11668.                                       }
  11669.                                   }
  11670.                                   i++;
  11671.                               }
  11672.                           }
  11673.                           if (kv == 5)
  11674.                             makestr(&k5pwprompt,s);
  11675.                           else
  11676.                             makestr(&k4pwprompt,s);
  11677.                           break;
  11678.                       }
  11679.                       case KRB_PR_PRM: { /* Principal */
  11680.                           /* Check to make sure there are no % fields */
  11681.                           int i,len;
  11682.                           len = strlen(s);
  11683.                           for (i = 0; i < len; i++) {
  11684.                               if (s[i] == '%') {
  11685.                                   if (s[i+1] != '%') {
  11686.                                       printf(
  11687.                                   "%% fields are not used in this command.\n");
  11688.                                       return(-9);
  11689.                                   }
  11690.                                   i++;
  11691.                               }
  11692.                           }
  11693.                           if (kv == 5)
  11694.                             makestr(&k5prprompt,s);
  11695.                           else
  11696.                             makestr(&k4prprompt,s);
  11697.                           break;
  11698.                       }
  11699.                     }
  11700.                 }
  11701.                 break;
  11702.             }
  11703. #endif /* CK_KERBEROS */
  11704. #ifdef CK_SRP
  11705.             case AUTH_SRP: {
  11706.                 if ((x = cmkey(srptab, nsrptab,
  11707.                                "SRP parameter","",xxstring)) < 0) {
  11708.                     return(x);
  11709.                 }
  11710.                 s = "";
  11711.                 switch (x) {
  11712.                   case XYSRPPRM:        /* Prompt */
  11713.                     if ((z = cmkey(srpprmtab,1,"","",xxstring)) < 0)
  11714.                       return(z);
  11715.                     if ((y = cmtxt(
  11716.   "Text of prompt;\nmay contain one \"%s\" to be replaced by the username",
  11717.                                    "",
  11718.                                    &s,
  11719.                                    xxstring
  11720.                                    )
  11721.                          ) < 0)
  11722.                       return(y);
  11723.                     break;
  11724.                 }
  11725.                 ckstrncpy(line,s,LINBUFSIZ);
  11726.                 s = line;
  11727.                 if ((y = cmcfm()) < 0)
  11728.                   return(y);
  11729.                 switch (x) {            /* Copy value to right place */
  11730.                   case XYSRPPRM:        /* Prompt */
  11731.                     if (s == "") s = NULL;
  11732.                     if (s) {
  11733.                         s = brstrip(s);
  11734.                         if (s == "") s = NULL;
  11735.                     }
  11736.                     switch (z) {
  11737.                       case SRP_PW_PRM: { /* Password */
  11738.                           /* Check %s fields */
  11739.                           int i,n,len;
  11740.                           len = strlen(s);
  11741.                           for (i = 0, n = 0; i < len; i++) {
  11742.                               if (s[i] == '%') {
  11743.                                   if (s[i+1] != '%') {
  11744.                                       if (s[i+1] != 's') {
  11745.                                           printf(
  11746.                                           "Only %%s fields are permitted.\n");
  11747.                                           return(-9);
  11748.                                       }
  11749.                                       if (++n > 1) {
  11750.                                           printf(
  11751.                                        "Only one %%s field is permitted.\n");
  11752.                                           return(-9);
  11753.                                       }
  11754.                                   }
  11755.                                   i++;
  11756.                               }
  11757.                           }
  11758.                           makestr(&srppwprompt,s);
  11759.                           break;
  11760.                       }
  11761.                     }
  11762.                 }
  11763.                 break;
  11764.             }
  11765. #endif /* CK_SRP */
  11766. #ifdef CK_SSL
  11767.             case AUTH_SSL:
  11768.             case AUTH_TLS: {
  11769.                 if ((z = cmkey(ssltab, nssltab,
  11770.                            (x == AUTH_SSL ? "SSL parameter" : "TLS parameter"),
  11771.                            "",xxstring)) < 0)
  11772.                   return(z);
  11773.                 s = "";
  11774.                 switch (z) {
  11775.                   case XYSSLRCFL:       /* SSL/TLS RSA Certs file */
  11776.                   case XYSSLRCCF:       /* SSL/TLS RSA Certs Chain file */
  11777.                   case XYSSLRKFL:       /* SSL/TLS RSA Key File */
  11778.                   case XYSSLDCFL:       /* SSL/TLS DSA Certs file */
  11779.                   case XYSSLDCCF:       /* SSL/TLS DSA Certs Chain file */
  11780.                   case XYSSLDKFL:       /* SSL/TLS DH Key File */
  11781.                   case XYSSLDPFL:       /* SSL/TLS DH Param File */
  11782.                   case XYSSLCRL:        /* SSL/TLS CRL File */
  11783.                   case XYSSLVRFF:       /* SSL/TLS Verify File */
  11784.                   case XYSSLRND:        /* SSL/TLS Random File */
  11785.                     y = cmifi("Filename","",&s,&x,xxstring);
  11786.                     if (y != -3) {
  11787.                         if (y < 0)
  11788.                           return(y);
  11789.                         if (x) {
  11790.                             printf("?Wildcards not allowed\n");
  11791.                             return(-9);
  11792.                         }
  11793.                     }
  11794.                     ckstrncpy(line,s,LINBUFSIZ);
  11795.                     s = line;
  11796.                     s = brstrip(s);
  11797.                     if ((y = cmcfm()) < 0)
  11798.                       return(y);
  11799.                     switch (z) {
  11800.                       case XYSSLRCFL:   /* SSL/TLS RSA Certs file */
  11801.                         if (!s[0] && ssl_rsa_cert_file) {
  11802.                             free(ssl_rsa_cert_file);
  11803.                             ssl_rsa_cert_file = NULL;
  11804.                         } else if (s[0]) {
  11805.                             makestr(&ssl_rsa_cert_file,s);
  11806.                             if (!ssl_rsa_key_file)
  11807.                               makestr(&ssl_rsa_key_file,s);
  11808.                         }
  11809.                         break;
  11810.                       case XYSSLRCCF:   /* SSL/TLS RSA Certs Chain file */
  11811.                           if (!s[0] && ssl_rsa_cert_chain_file) {
  11812.                               free(ssl_rsa_cert_chain_file);
  11813.                               ssl_rsa_cert_chain_file = NULL;
  11814.                           } else if (s[0]) {
  11815.                               makestr(&ssl_rsa_cert_chain_file,s);
  11816.                           }
  11817.                           break;
  11818.                       case XYSSLRKFL:   /* SSL/TLS RSA Key File */
  11819.                         if (!s[0] && ssl_rsa_key_file) {
  11820.                             free(ssl_rsa_key_file);
  11821.                             ssl_rsa_key_file = NULL;
  11822.                         } else if (s[0]) {
  11823.                             makestr(&ssl_rsa_key_file,s);
  11824.                         }
  11825.                         break;
  11826.                       case XYSSLDCFL:   /* SSL/TLS DSA Certs file */
  11827.                         if (!s[0] && ssl_dsa_cert_file) {
  11828.                             free(ssl_dsa_cert_file);
  11829.                             ssl_dsa_cert_file = NULL;
  11830.                         } else if (s[0]) {
  11831.                             makestr(&ssl_dsa_cert_file,s);
  11832.                             if (!ssl_dh_key_file)
  11833.                               makestr(&ssl_dh_key_file,s);
  11834.                         }
  11835.                         break;
  11836.                       case XYSSLDCCF:   /* SSL/TLS DSA Certs Chain file */
  11837.                           if (!s[0] && ssl_dsa_cert_chain_file) {
  11838.                               free(ssl_dsa_cert_chain_file);
  11839.                               ssl_dsa_cert_chain_file = NULL;
  11840.                           } else if (s[0]) {
  11841.                               makestr(&ssl_dsa_cert_chain_file,s);
  11842.                           }
  11843.                           break;
  11844.                       case XYSSLDKFL:   /* SSL/TLS DH Key File */
  11845.                         if (!s[0] && ssl_dh_key_file) {
  11846.                             free(ssl_dh_key_file);
  11847.                             ssl_dh_key_file = NULL;
  11848.                         } else if (s[0]) {
  11849.                             makestr(&ssl_dh_key_file,s);
  11850.                         }
  11851.                         break;
  11852.                       case XYSSLDPFL:   /* SSL/TLS DH Param File */
  11853.                         if (!s[0] && ssl_dh_param_file) {
  11854.                             free(ssl_dh_param_file);
  11855.                             ssl_dh_param_file = NULL;
  11856.                         } else if (s[0]) {
  11857.                             makestr(&ssl_dh_param_file,s);
  11858.                         }
  11859.                         break;
  11860.                       case XYSSLCRL:    /* SSL/TLS CRL File */
  11861.                         if (!s[0] && ssl_crl_file) {
  11862.                             free(ssl_crl_file);
  11863.                             ssl_crl_file = NULL;
  11864.                         } else if (s[0]) {
  11865.                             makestr(&ssl_crl_file,s);
  11866.                         }
  11867.                         break;
  11868.                       case XYSSLVRFF:   /* SSL/TLS Verify File */
  11869.                         if (!s[0] && ssl_verify_file) {
  11870.                             free(ssl_verify_file);
  11871.                             ssl_verify_file = NULL;
  11872.                         } else if (s[0]) {
  11873.                             makestr(&ssl_verify_file,s);
  11874.                         }
  11875.                         break;
  11876.                       case XYSSLRND:    /* SSL/TLS Random File */
  11877.                         if (!s[0] && ssl_rnd_file) {
  11878.                             free(ssl_rnd_file);
  11879.                             ssl_rnd_file = NULL;
  11880.                         } else if (s[0]) {
  11881.                             makestr(&ssl_rnd_file,s);
  11882.                         }
  11883.                         break;
  11884.                     }
  11885.                     break;
  11886.  
  11887.                   case XYSSLCRLD:
  11888.                   case XYSSLVRFD: {
  11889.                     char * d = NULL;
  11890.                     if (z == XYSSLVRFD)
  11891.                       d= getenv("SSL_CERT_DIR");
  11892.                     if (d == NULL)
  11893.                         d = "";
  11894.                     if ((y = cmdir("Directory",d,&s,xxstring)) < 0)
  11895.                       return(y);
  11896.                     if (y != -3) {
  11897.                         if (y < 0)
  11898.                           return(y);
  11899.                     }
  11900.                     ckstrncpy(line,s,LINBUFSIZ);
  11901.                     s = line;
  11902.                     s = brstrip(s);
  11903.                     if ((y = cmcfm()) < 0)
  11904.                       return(y);
  11905.                     switch(z) {
  11906.                       case XYSSLCRLD:
  11907.                         if (!s[0] && ssl_crl_dir) {
  11908.                             free(ssl_crl_dir);
  11909.                             ssl_crl_dir = NULL;
  11910.                         } else if (s[0]) {
  11911.                             makestr(&ssl_crl_dir,s);
  11912.                         }
  11913.                         break;
  11914.                       case XYSSLVRFD:
  11915.                         if (!s[0] && ssl_verify_dir) {
  11916.                             free(ssl_verify_dir);
  11917.                             ssl_verify_dir = NULL;
  11918.                         } else if (s[0]) {
  11919.                             makestr(&ssl_verify_dir,s);
  11920.                         }
  11921.                         break;
  11922.                     }
  11923.                     break;
  11924.                   }
  11925.                   case XYSSLCOK:        /* SSL/TLS Certs-Ok flag */
  11926.                     if ((y = seton(&ssl_certsok_flag)) < 0)
  11927.                       return(y);
  11928.                     break;
  11929.                   case XYSSLDBG:                /* SSL/TLS Debug flag */
  11930.                     if ((y = seton(&ssl_debug_flag)) < 0)
  11931.                       return(y);
  11932.                     break;
  11933.                   case XYSSLON:         /* SSL/TLS Only flag */
  11934.                     switch (x) {
  11935.                       case AUTH_SSL:
  11936.                         if ((y = seton(&ssl_only_flag)) < 0)
  11937.                           return(y);
  11938.                         break;
  11939.                       case AUTH_TLS:
  11940.                         if ((y = seton(&tls_only_flag)) < 0)
  11941.                           return(y);
  11942.                         break;
  11943.                     }
  11944.                     break;
  11945.                   case XYSSLVRB:        /* SSL/TLS Verbose flag */
  11946.                     if ((y = seton(&ssl_verbose_flag)) < 0)
  11947.                       return(y);
  11948.                     break;
  11949.                   case XYSSLVRF:        /* SSL/TLS Verify flag */
  11950.                     if ((x = cmkey(sslvertab, nsslvertab,
  11951.                                    "SSL/TLS verify mode",
  11952.                                    "peer-cert",xxstring)) < 0)
  11953.                       return(x);
  11954.                     if ((y = cmcfm()) < 0)
  11955.                       return(y);
  11956.                     ssl_verify_flag = x;
  11957.                     break;
  11958.                   case XYSSLDUM:
  11959.                     if ((y = seton(&ssl_dummy_flag)) < 0)
  11960.                       return(y);
  11961.                     break;
  11962.                   case XYSSLCL: {               /* SSL/TLS Cipher List */
  11963. #ifdef COMMENT
  11964.                       /* This code is used to generate a colon delimited */
  11965.                       /* list of the ciphers currently in use to be used */
  11966.                       /* as the default for cmtxt().  However, a better  */
  11967.                       /* default is simply the magic keyword "ALL".      */
  11968.                       CHAR def[1024] = "";
  11969.                       if (ssl_con != NULL) {
  11970.                           CHAR * p = NULL, *q = def;
  11971.                           int i, len;
  11972.  
  11973.                           for (i = 0; ; i++) {
  11974.                               p = (CHAR *) SSL_get_cipher_list(ssl_con,i);
  11975.                               if (p == NULL)
  11976.                                 break;
  11977.                               len = strlen(p);
  11978.                               if (q+len+1 >= def+1024)
  11979.                                 break;
  11980.                               if (i != 0)
  11981.                                 *q++ = ':';
  11982.                               strcpy(q,p);
  11983.                               q += len;
  11984.                           }
  11985.                       }
  11986. #endif /* COMMENT */
  11987.                       char * p = getenv("SSL_CIPHER");
  11988.                       if (!p)
  11989.                         p = "ALL";
  11990.                       if ((y = cmtxt(
  11991.                     "Colon-delimited list of ciphers or ALL (case sensitive)",
  11992.                                      p,
  11993.                                      &s,
  11994.                                      xxstring
  11995.                                      )
  11996.                            ) < 0)
  11997.                         return(y);
  11998.                       makestr(&ssl_cipher_list,s);
  11999.                       if (ssl_con == NULL) {
  12000.                           SSL_library_init();
  12001.                           ssl_ctx = (SSL_CTX *)
  12002.                             SSL_CTX_new((SSL_METHOD *)TLSv1_method());
  12003.                           if (ssl_ctx != NULL)
  12004.                             ssl_con= (SSL *) SSL_new(ssl_ctx);
  12005.                       }
  12006.                       if (ssl_con) {
  12007.                           SSL_set_cipher_list(ssl_con,ssl_cipher_list);
  12008.                       }
  12009.                       break;
  12010.                   }
  12011.                 }
  12012.                 break;
  12013.             }
  12014. #endif /* CK_SSL */
  12015.             default:
  12016.               break;
  12017.           }
  12018.           return(success = 1);
  12019.       }
  12020. #endif /* CK_AUTHENTICATION */
  12021.  
  12022. #ifndef NOSPL
  12023.       case XYFUNC:
  12024.         if ((x = cmkey(functab,nfunctab,"","diagnostics",xxstring)) < 0)
  12025.           return(x);
  12026.         switch (x) {
  12027.           case FUNC_DI: return(seton(&fndiags));
  12028.           case FUNC_ER: return(seton(&fnerror));
  12029.           default:      return(-2);
  12030.         }
  12031. #endif /* NOSPL */
  12032.  
  12033.       case XYSLEEP:                     /* SET SLEEP / PAUSE */
  12034.         if ((x = cmkey(sleeptab,1,"","cancellation",xxstring)) < 0)
  12035.           return(x);
  12036.         return(seton(&sleepcan));
  12037.  
  12038.       case XYCD:                        /* SET CD */
  12039.         if ((x = cmkey(cdtab,ncdtab,"","",xxstring)) < 0)
  12040.           return(x);
  12041.         switch (x) {
  12042.           case XYCD_M:                  /* SET CD MESSAGE */
  12043.             if ((x = cmkey(cdmsg,ncdmsg,"","",xxstring)) < 0)
  12044.               return(x);
  12045.             if (x == 2) {               /* CD MESSAGE FILE */
  12046.                 if ((x = cmtxt("Name of file","",&s,NULL)) < 0)
  12047.                   return(x);
  12048.                 if (!*s) {
  12049.                     s = NULL;
  12050. #ifndef NOXFER
  12051.                     srvcdmsg = 0;
  12052. #endif /* NOXFER */
  12053.                 }
  12054.                 makestr(&cdmsgstr,s);
  12055.                 makelist(cdmsgstr,cdmsgfile,8);
  12056.                 return(success = 1);
  12057.             }
  12058.  
  12059.             if ((y = cmcfm()) < 0) return(y); /* CD-MESSAGE ON/OFF */
  12060. #ifndef NOXFER
  12061.             if (x > 0)
  12062.               srvcdmsg |= 2;
  12063.             else
  12064.               srvcdmsg &= 1;
  12065. #endif /* NOXFER */
  12066.             return(success = 1);
  12067.  
  12068.           case XYCD_P: {                /* SET CD PATH */
  12069.               extern char * ckcdpath;
  12070.               if ((x = cmtxt("CD PATH string","",&s,xxstring)) < 0)
  12071.                 return(x);
  12072.               makestr(&ckcdpath,s);
  12073.               return(success = 1);
  12074.           }
  12075.         }
  12076.  
  12077. #ifndef NOLOCAL
  12078. #ifdef STOPBITS
  12079.       case XYSTOP:                      /* STOP-BITS */
  12080.         if ((x = cmkey(stoptbl,2,"Stop bits for serial device","",
  12081.                        xxstring)) < 0)
  12082.           return(x);
  12083.         if ((y = cmcfm()) < 0)
  12084.           return(y);
  12085.         if (x > 0 && x < 3) {
  12086.             stopbits = x;
  12087. #ifdef TN_COMPORT
  12088.             if (network && istncomport()) {
  12089.                 tnsettings(-1, x);
  12090.                 return(success = 1);
  12091.             }
  12092. #endif /* TN_COMPORT */
  12093. #ifdef HWPARITY
  12094.             return(success = 1);
  12095. #else /* HWPARITY */
  12096.             return(-2);
  12097. #endif /* HWPARITY */
  12098.         } else
  12099.           return(-2);
  12100. #endif /* STOPBITS */
  12101.  
  12102.       case XYDISC: {
  12103.           extern int clsondisc;
  12104.           return(seton(&clsondisc));
  12105.       }
  12106.  
  12107.       case XYSERIAL: {
  12108.           /* char c; */
  12109.           extern int cmask;
  12110.           if ((x = cmkey(sertbl,nsertbl,
  12111.                          "Serial device character size, parity, and stop bits",
  12112.                          "8N1", xxstring)) < 0)
  12113.             return(x);
  12114.           ckstrncpy(line,atmbuf,LINBUFSIZ); /* Associated keyword string */
  12115.           s = line;
  12116.           if ((y = cmcfm()) < 0)
  12117.             return(y);
  12118.           ckstrncpy(line,sernam[x],LINBUFSIZ);
  12119.           s = line;
  12120.           if (s[0] != '8' && s[0] != '7') /* Char size */
  12121.             return(-2);
  12122.           else
  12123.             z = s[0] - '0';
  12124.           if (isupper(s[1]))            /* Parity */
  12125.             s[1] = tolower(s[1]);
  12126.           if (s[2] != '1' && s[2] != '2') /* Stop bits */
  12127.             return(-2);
  12128.           else
  12129.             stopbits = s[2] - '0';
  12130.           if (z == 8) {                 /* 8 bits + parity (or not) */
  12131.               parity = 0;               /* Set parity */
  12132.               hwparity = (s[1] == 'n') ? 0 : s[1];
  12133.               cmask = 0xff;             /* Also set TERM BYTESIZE to 8 */
  12134.           } else {                      /* 7 bits plus parity */
  12135.               parity = (s[1] == 'n') ? 0 : s[1];
  12136.               hwparity = 0;
  12137.               cmask = 0x7f;             /* Also set TERM BYTESIZE to 7 */
  12138.           }
  12139. #ifdef TN_COMPORT
  12140.           if (network && !istncomport())
  12141.             tnsettings(parity, stopbits);
  12142. #endif /* TN_COMPORT */
  12143.  
  12144.           return(success = 1);          /* from SET SERIAL */
  12145.       }
  12146.  
  12147.       case XYOPTS: {                    /* SET OPTIONS */
  12148.           extern int setdiropts();
  12149.           extern int settypopts();
  12150. #ifdef CKPURGE
  12151.           extern int setpurgopts();
  12152. #endif /* CKPURGE */
  12153.           if ((x = cmkey(optstab,noptstab,"for command","", xxstring)) < 0)
  12154.             return(x);
  12155.           switch (x) {
  12156. #ifndef NOFRILLS
  12157.             case XXDEL:
  12158.               return(setdelopts());
  12159. #endif /* NOFRILLS */
  12160.             case XXDIR:
  12161.               return(setdiropts());
  12162.             case XXTYP:
  12163.               return(settypopts());
  12164. #ifdef CKPURGE
  12165.             case XXPURGE:
  12166.               return(setpurgopts());
  12167. #endif /* CKPURGE */
  12168.             default:
  12169.               return(-2);
  12170.           }
  12171.       }
  12172. #endif /* NOLOCAL */
  12173. #ifndef NOXFER
  12174.       case XYQ8FLG: {
  12175.           extern int q8flag;
  12176.           return(seton(&q8flag));
  12177.       }
  12178.       case XYTIMER: {
  12179.           extern int asktimer;
  12180.           y = cmnum("Time limit for ASK command, seconds","0",10,&x,xxstring);
  12181. #ifdef QNX16
  12182.           return(setnum(&asktimer,x,y,32767));
  12183. #else
  12184.           return(setnum(&asktimer,x,y,86400));
  12185. #endif /* QNX16 */
  12186.       }
  12187.       case XYFACKB: {
  12188.           extern int fackbug;
  12189.           return(seton(&fackbug));
  12190.       }
  12191. #endif /* NOXFER */
  12192.  
  12193.       case XYHINTS:
  12194.         return(seton(&hints));
  12195.  
  12196. #ifndef NOSPL
  12197.       case XYEVAL: {
  12198.           extern int oldeval;
  12199.           if ((x = cmkey(oldnew,2,"","", xxstring)) < 0)
  12200.             return(x);
  12201.           if ((y = cmcfm()) < 0)
  12202.             return(y);
  12203.           oldeval = x;
  12204.           return(success = 1);
  12205.       }
  12206. #endif /* NOSPL */
  12207.  
  12208. #ifndef NOXFER
  12209.       case XYFACKP: {
  12210.           extern int fackpath;
  12211.           return(seton(&fackpath));
  12212.       }
  12213. #endif /* NOXFER */
  12214.  
  12215.       case XYQNXPL: {
  12216.           extern int qnxportlock;
  12217.           return(seton(&qnxportlock));
  12218.       }
  12219.  
  12220. #ifndef NOCMDL
  12221. #ifdef IKSD
  12222.       case XYIKS: {
  12223.           int setiks();
  12224.           return(setiks());
  12225.       }
  12226. #endif /* IKSD */
  12227. #endif /* NOCMDL */
  12228.  
  12229. #ifdef CKROOT
  12230.       case XYROOT:
  12231.         return(dochroot());
  12232. #endif /* CKROOT */
  12233.  
  12234. #ifndef NOSPL
  12235. #ifndef NOSEXP
  12236.       case XYSEXP: {
  12237.           if ((x = cmkey(sexptab,2,"","", xxstring)) < 0)
  12238.             return(x);
  12239.           switch (x) {
  12240.             case 0:
  12241.               if ((x = cmkey(ooatab,3,"","automatic", xxstring)) < 0)
  12242.                 return(x);
  12243.               if ((y = cmcfm()) < 0)
  12244.                 return(y);
  12245.               sexpecho = x;
  12246.               break;
  12247.             case 1: {
  12248.                 int i, xx;
  12249.                 xx = sexpmaxdep;
  12250.                 if ((y = cmnum("Maximum recursion depth",
  12251.                                "1000",10,&x,xxstring)) < 0)
  12252.                   return(y);
  12253.                 z = setnum(&sexpmaxdep,x,y,-1);
  12254.                 if (z < 0)
  12255.                   return(z);
  12256.                 if (sxresult) {         /* Free old stack if allocated */
  12257.                     for (i = 0; i < xx; i++)
  12258.                       if (sxresult[i]) free(sxresult[i]);
  12259.                     free((char *)sxresult);
  12260.                     if (sxrlen) free((char *)sxrlen);
  12261.                     sxresult = NULL;
  12262.                     sxrlen = NULL;
  12263.                 }
  12264.                 break;
  12265.             }
  12266.           }
  12267.           return(success = 1);
  12268.       }
  12269. #endif /* NOSEXPL */
  12270. #endif /* NOSPL */
  12271.  
  12272. #ifdef NEWFTP
  12273.       case XYGPR: {
  12274.           extern struct keytab gprtab[];
  12275.           extern int ftpget;
  12276.           if ((x = cmkey(gprtab,3,"","kermit", xxstring)) < 0)
  12277.             return(x);
  12278.           if ((y = cmcfm()) < 0)
  12279.             return(y);
  12280.           ftpget = x;
  12281.           return(success = 1);
  12282.       }
  12283. #endif /* NEWFTP */
  12284.  
  12285. #ifdef ANYSSH
  12286.       case XYSSH:
  12287.         return(dosetssh());
  12288. #endif /* ANYSHH */
  12289.  
  12290. #ifdef LOCUS
  12291.       case XYLOCUS:
  12292.           if ((x = cmkey(locustab,nlocustab,"","auto", xxstring)) < 0)
  12293.             return(x);
  12294.           if ((y = cmcfm()) < 0)
  12295.             return(y);
  12296.           if (x == 2) {
  12297.               autolocus = 1;
  12298.               locus = 1;
  12299.           } else {
  12300.               autolocus = 0;
  12301.               locus = x;
  12302.           }
  12303.           return(success = 1);
  12304. #endif /* LOCUS */
  12305.  
  12306. #ifdef KUI
  12307.       case XYGUI:
  12308.         return(setgui());
  12309. #endif /* KUI */
  12310.  
  12311.       default:
  12312.          if ((x = cmcfm()) < 0) return(x);
  12313.          printf("Not implemented - %s\n",cmdbuf);
  12314.          return(success = 0);
  12315.     }
  12316. }
  12317.  
  12318. /*
  12319.   H U P O K  --  Is Hangup OK?
  12320.  
  12321.   Issues a warning and gets OK from user depending on whether a connection
  12322.   seems to be open and what the SET EXIT WARNING setting is.  Returns:
  12323.     0 if not OK to hang up or exit (i.e. user said No);
  12324.     nonzero if OK.
  12325.   Argument x is used to differentiate the EXIT command from SET LINE / HOST.
  12326. */
  12327. int
  12328. hupok(x) int x; {                       /* Returns 1 if OK, 0 if not OK */
  12329.     int y, z = 1;
  12330.     extern int exithangup;
  12331. #ifdef VMS
  12332.     extern int batch;
  12333.  
  12334.     if (batch)                          /* No warnings in batch */
  12335.       return(1);
  12336. #else
  12337. #ifdef UNIX
  12338.     if (backgrd)                        /* No warnings in background */
  12339.       return(1);
  12340. #endif /* UNIX */
  12341. #endif /* VMS */
  12342.  
  12343.     debug(F101,"hupok local","",local);
  12344.  
  12345.     if (!local)                         /* No warnings in remote mode */
  12346.       return(1);
  12347.  
  12348.     if (x == 0 && exithangup == 0)      /* EXIT and EXIT HANGUP is OFF */
  12349.       return(1);
  12350.  
  12351.     debug(F101,"hupok x","",x);
  12352.     debug(F101,"hupok xitwarn","",xitwarn);
  12353.     debug(F101,"hupok network","",network);
  12354.     debug(F101,"hupok haveline","",haveline);
  12355.  
  12356.     if ((local && xitwarn) ||           /* Is a connection open? */
  12357.         (!x && xitwarn == 2)) {         /* Or Always give warning on EXIT */
  12358.         int needwarn = 0;
  12359.  
  12360.         if (network) {
  12361.             if (ttchk() >= 0)
  12362.               needwarn = 1;
  12363.             /* A connection seems to be open but it can't possibly be */
  12364.             if (!haveline)
  12365.               needwarn = 0;
  12366.             if (needwarn) {
  12367.                 if (strcmp(ttname,"*"))
  12368.                   printf(
  12369. " A network connection to %s might still be active.\n",
  12370.                          ttname
  12371.                          );
  12372.                 else
  12373.                   printf(
  12374.                    " An incoming network connection might still be active.\n"
  12375.                          );
  12376.             }
  12377.         } else {                        /* Serial connection */
  12378.             if (carrier == CAR_OFF)     /* SET CARRIER OFF */
  12379.               needwarn = 0;             /* so we don't care about carrier. */
  12380.             else if ((y = ttgmdm()) >= 0) /* else, get modem signals */
  12381.               needwarn = (y & BM_DCD);  /* Check for carrier */
  12382.             else                        /* If we can't get modem signals... */
  12383.               needwarn = (ttchk() >= 0);
  12384.             /* A connection seems to be open but it can't possibly be */
  12385.             if (!haveline || !exithangup)
  12386.               needwarn = 0;
  12387.             if (needwarn)
  12388.               printf(
  12389.                      " A serial connection might still be active on %s.\n",
  12390.                      ttname
  12391.                      );
  12392.         }
  12393.  
  12394. /* If a warning was issued, get user's permission to EXIT. */
  12395.  
  12396.         if (needwarn || (!x && xitwarn == 2 && local)) {
  12397.             z = getyesno(x ? "OK to close? " : "OK to exit? ",0);
  12398.             debug(F101,"hupok getyesno","",z);
  12399.             if (z < -3) z = 0;
  12400.         }
  12401.     }
  12402.     return(z);
  12403. }
  12404.  
  12405. #ifndef NOSHOW
  12406. VOID
  12407. shoctl() {                              /* SHOW CONTROL-PREFIXING */
  12408. #ifdef CK_SPEED
  12409.     int i;
  12410. #ifdef OS2
  12411.     int zero;
  12412. #endif /* OS2 */
  12413.     printf(
  12414. "\ncontrol quote = %d, applied to (0 = unprefixed, 1 = prefixed):\n\n",
  12415.            myctlq);
  12416. #ifdef OS2
  12417. #ifndef UNPREFIXZERO
  12418.     zero = ctlp[0];
  12419.     if (protocol == PROTO_K)            /* Zero can't be unprefixed */
  12420.       ctlp[0] = 1;                      /* for Kermit */
  12421. #endif /* UNPREFIXZERO */
  12422. #endif /* OS2 */
  12423.     for (i = 0; i < 16; i++) {
  12424.         printf("  %3d: %d   %3d: %d ",i,ctlp[i], i+16, ctlp[i+16]);
  12425.         if (i == 15)
  12426.           printf("  127: %d",ctlp[127]);
  12427.         else
  12428.           printf("        ");
  12429.         printf("  %3d: %d   %3d: %d ",i+128,ctlp[i+128], i+144, ctlp[i+144]);
  12430.         if (i == 15)  printf("  255: %d",ctlp[255]);
  12431.         printf("\n");
  12432.     }
  12433.     printf("\n");
  12434. #ifndef UNPREFIXZERO
  12435. #ifdef OS2
  12436.     ctlp[0] = zero;
  12437. #endif /* OS2 */
  12438. #endif /* UNPREFIXZERO */
  12439.  
  12440. #endif /* CK_SPEED */
  12441. }
  12442.  
  12443. #ifndef NOXFER
  12444. VOID
  12445. shodbl() {                              /* SHOW DOUBLE/IGNORE */
  12446. #ifdef CKXXCHAR
  12447.     int i, n = 0;
  12448.     printf("\nSET SEND DOUBLE characters:\n");
  12449.     for (i = 0; i < 255; i++) {
  12450.         if (dblt[i] & 2) {
  12451.             n++;
  12452.             printf(" %d", i);
  12453.         }
  12454.     }
  12455.     if (n == 0)
  12456.       printf(" (none)");
  12457.     n = 0;
  12458.     printf("\nSET RECEIVE IGNORE characters:\n");
  12459.     for (i = 0; i < 255; i++) {
  12460.         if (dblt[i] & 1) {
  12461.             n++;
  12462.             printf(" %d", i);
  12463.         }
  12464.     }
  12465.     if (n == 0)
  12466.       printf(" (none)");
  12467.     printf("\n\n");
  12468. #endif /* CKXXCHAR */
  12469. }
  12470. #endif /* NOXFER */
  12471. #endif /* NOSHOW */
  12472.  
  12473. #ifndef NOPUSH
  12474. #ifdef CK_REXX
  12475. /*
  12476.   Rexx command.  Note, this is not OS/2-specific, because Rexx also runs
  12477.   on other systems where C-Kermit also runs, like the Amiga.
  12478. */
  12479. #define REXBUFL 100                     /* Change this if neccessary */
  12480. char rexxbuf[REXBUFL] = { '\0' };       /* Rexx's return value (string) */
  12481.  
  12482. int
  12483. dorexx() {
  12484.     int x, y;
  12485.     char *rexxcmd;
  12486.  
  12487.         if ((x = cmtxt("Rexx command","",&rexxcmd,xxstring)) < 0)
  12488.           return(x);
  12489.  
  12490. #ifdef IKSD
  12491.     if (inserver) {
  12492.         printf("?Sorry, command disabled.\r\n");
  12493.         return(success = 0);
  12494.     }
  12495. #endif /* IKSD */
  12496. #ifdef CK_APC
  12497.     /* Don't let this be set remotely */
  12498.     if (apcactive == APC_LOCAL ||
  12499.         apcactive == APC_REMOTE && !(apcstatus & APC_UNCH))
  12500.       return(success = 0);
  12501. #endif /* CK_APC */
  12502.  
  12503.         ckstrncpy(line,rexxcmd,LINBUFSIZ);
  12504.         rexxcmd = line;
  12505. #ifdef OS2
  12506.         return(os2rexx(rexxcmd,rexxbuf,REXBUFL));
  12507. #else /* !OS2 */
  12508.         printf("Sorry, nothing happens.\n");
  12509.         return(success = 0);
  12510. #endif /* OS2 */
  12511. }
  12512. #endif /* CK_REXX */
  12513. #endif /* NOPUSH */
  12514. #else  /* NOICP */
  12515. VOID
  12516. dologend() {
  12517.     /* Dummy write record to connection log */
  12518. }
  12519. #endif /* NOICP */
  12520.