home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / ckv200.zip / ckuus3.c < prev    next >
C/C++ Source or Header  |  2001-12-08  |  317KB  |  11,573 lines

  1. #include "ckcsym.h"            /* Symbol definitions */
  2.  
  3. /*  C K U U S 3 --  "User Interface" for C-Kermit, part 3  */
  4.  
  5. /*
  6.   Author: Frank da Cruz <fdc@columbia.edu>,
  7.   Columbia University Academic Information Systems, New York City.
  8.  
  9.   Copyright (C) 1985, 2001,
  10.     Trustees of Columbia University in the City of New York.
  11.     All rights reserved.  See the C-Kermit COPYING.TXT file or the
  12.     copyright text in the ckcmai.c module for disclaimer and permissions.
  13. */
  14.  
  15. /*  SET command (but much material has been split off into ckuus7.c). */
  16.  
  17. /*
  18.   Kermit-specific includes.
  19.   Definitions here supersede those from system include files.
  20. */
  21. #include "ckcdeb.h"            /* Debugging & compiler things */
  22. #include "ckcasc.h"            /* ASCII character symbols */
  23. #include "ckcker.h"            /* Kermit application definitions */
  24. #include "ckcxla.h"            /* Character set translation */
  25. #include "ckcnet.h"            /* Network symbols */
  26.  
  27. char pwbuf[PWBUFL+1]  = { NUL, NUL };
  28. int pwflg = 0;
  29. int pwcrypt = 0;
  30.  
  31. #ifndef NOICP
  32.  
  33. #ifdef CK_AUTHENTICATION
  34. #include "ckuath.h"
  35. #endif /* CK_AUTHENTICATION */
  36. #ifdef CK_SSL
  37. #include "ck_ssl.h"
  38. #endif /* CK_SSL */
  39. #include "ckuusr.h"            /* User interface symbols */
  40. #ifdef OS2
  41. #ifdef CK_NETBIOS
  42. #include <os2.h>
  43. #ifdef COMMENT                /* Would you believe */
  44. #undef COMMENT                /* <os2.h> defines this ? */
  45. #endif /* COMMENT */
  46. #include "ckonbi.h"
  47. extern UCHAR NetBiosAdapter;
  48. #endif /* CK_NETBIOS */
  49. #include "ckocon.h"
  50. #include "ckokey.h"
  51. #ifndef NOTERM
  52. extern unsigned char colorcmd;    /* Command-screen colors */
  53. extern struct keytab ttyclrtab[];
  54. extern int nclrs;
  55. extern int tt_cols[], tt_rows[], tt_szchng[], tt_status[];
  56. #endif /* NOTERM */
  57. _PROTOTYP(int setprty, (void));
  58. extern char startupdir[], exedir[];
  59. extern int tt_modechg;
  60. #ifdef NT
  61. #include <windows.h>
  62. #include <tapi.h>
  63. #include "ckntap.h"            /* Microsoft TAPI */
  64. #endif /* NT */
  65. #endif /* OS2 */
  66.  
  67. #ifndef OS2
  68. extern char * exedir;
  69. #endif /* OS2 */
  70.  
  71. #ifdef CK_RECALL
  72. extern int cm_retry;
  73. #endif /* CK_RECALL */
  74.  
  75. extern int cmdint;
  76. extern int srvidl;
  77.  
  78. #ifndef NOPUSH
  79. #ifndef NOFRILLS
  80. #ifdef VMS
  81. char editor[CKMAXPATH + 1] = "edit";
  82. #else
  83. char editor[CKMAXPATH + 1] = { NUL, NUL };
  84. #endif /* VMS */
  85. char editopts[128] = { NUL, NUL };
  86. char editfile[CKMAXPATH + 1] = { NUL, NUL };
  87. #ifdef BROWSER
  88. char browser[CKMAXPATH + 1] = { NUL, NUL };
  89. char browsopts[128] = { NUL, NUL };
  90. char browsurl[4096] = { NUL, NUL };
  91. #endif /* BROWSER */
  92. #endif /*  NOFRILLS */
  93. #endif /* NOPUSH */
  94.  
  95. /* Variables */
  96.  
  97. int cmd_quoting = 1;
  98. extern int hints, xcmdsrc;
  99.  
  100. #ifdef CK_KERBEROS
  101. char * k4pwprompt = NULL;        /* Kerberos 4 password prompt */
  102. char * k4prprompt = NULL;        /* Kerberos 4 principal prompt */
  103. char * k5pwprompt = NULL;        /* Kerberos 5 password prompt */
  104. char * k5prprompt = NULL;        /* Kerberos 5 principal prompt */
  105. #endif /* CK_KERBEROS */
  106. #ifdef CK_SRP
  107. char * srppwprompt = NULL;
  108. #endif /* CK_SRP */
  109.  
  110. extern char * ckprompt, * ikprompt;    /* Default prompt */
  111. extern xx_strp xxstring;
  112.  
  113. extern char * cdmsgfile[], * cdmsgstr;
  114.  
  115. extern int
  116.   local, server, success, dest, sleepcan, inserver, flow, autoflow, binary,
  117.   parity, escape, what, turn, duplex, backgrd, hwparity, stopbits, turnch,
  118.   mdmtyp, network, quiet, nettype, carrier, debses, debtim, cdtimo, nlangs,
  119.   bgset, pflag, msgflg, cmdmsk, suspend, techo, pacing, xitwarn, xitsta,
  120.   outesc, cmd_cols, cmd_rows, ckxech, xaskmore, haveline, didsetlin, isguest,
  121.   mdmsav, clearrq, saveask;
  122.  
  123. extern int reliable, setreliable;
  124.  
  125. #ifndef NOSERVER
  126.   extern int en_pri;
  127. #endif /* NOSERVER */
  128.  
  129. #ifdef IKSDCONF
  130. extern int iksdcf;
  131. #endif /* IKSDCONF */
  132. #ifdef TCPSOCKET
  133.   extern int tn_exit;
  134. #endif /* TCPSOCKET */
  135. #ifdef TNCODE
  136.   char * tn_pr_uid = NULL;
  137. #endif /* TNCODE */
  138.   extern int exitonclose;
  139.  
  140. #ifndef NOKVERBS
  141. extern int nkverbs;
  142. extern struct keytab kverbs[];
  143. #endif /* NOKVERBS */
  144.  
  145. extern int ttnproto;            /* Network protocol */
  146.  
  147. extern char *ccntab[];            /* Names of control chars */
  148.  
  149. #ifdef CK_APC
  150. extern int apcactive, apcstatus;
  151. #endif /* CK_APC */
  152.  
  153. #ifndef NOSCRIPT
  154. extern int secho;            /* Whether SCRIPT cmd should echo */
  155. #endif /* NOSCRIPT */
  156.  
  157. #ifdef DCMDBUF
  158. extern char *atmbuf, *atxbuf;
  159. #else
  160. extern char atmbuf[], atxbuf[];
  161. #endif /* DCMDBUF */
  162. extern int cmflgs;
  163.  
  164. extern char psave[];
  165. extern char uidbuf[];
  166. extern int  sl_uid_saved;
  167. int DeleteStartupFile = 0;
  168.  
  169. extern int cmdlvl;            /* Overall command level */
  170.  
  171. #ifndef NOSPL
  172. _PROTOTYP( static int parsdir, (int) );
  173. char prmbuf[PWBUFL+1] = { NUL, NUL };
  174. int fndiags = 1;            /* Function diagnostics on/off */
  175. int fnerror = 1;            /* Function error treatment */
  176.  
  177. #ifdef DCMDBUF
  178. extern int *count, *takerr, *merror, *inpcas;
  179. #else
  180. extern int count[], takerr[], merror[], inpcas[];
  181. #endif /* DCMDBUF */
  182. extern int mecho;            /* Macro echo */
  183. extern long ck_alarm;
  184. extern char alrm_date[], alrm_time[];
  185. #else
  186. extern int takerr[];
  187. #endif /* NOSPL */
  188.  
  189. extern int x_ifnum;
  190. extern int bigsbsiz, bigrbsiz;        /* Packet buffers */
  191.  
  192. extern long speed;            /* Terminal speed */
  193.  
  194. extern char ttname[];            /* Communication device name */
  195. extern char myhost[] ;
  196. extern char inidir[];            /* Ini File directory */
  197.  
  198. #ifndef NOSETKEY
  199. extern KEY *keymap;            /* Character map for SET KEY (1:1)  */
  200. extern MACRO *macrotab;            /* Macro map for SET KEY (1:string) */
  201. #endif /* NOSETKEY */
  202. #ifdef OS2
  203. int wideresult;                /* For wide OS/2 scan codes/cmnum() */
  204. #endif /* OS2 */
  205.  
  206. #ifndef NOLOCAL
  207. #ifdef OS2
  208. extern int tt_scrsize[];        /* Scrollback buffer Sizes */
  209. #endif /* OS2 */
  210. #endif /* NOLOCAL */
  211.  
  212. /* Printer settings */
  213.  
  214. extern char * printername;        /* NULL if printer not redirected */
  215. extern int printpipe;
  216. extern int noprinter;
  217. #ifdef PRINTSWI
  218. int printtimo = 0;
  219. char * printterm = NULL;
  220. char * printsep = NULL;
  221. int printertype = 0;
  222. #ifdef BPRINT
  223. int printbidi = 0;            /* SET BPRINTER (bidirectional) */
  224. long pportspeed = 0L;            /* Bidirection printer port speed, */
  225. int pportparity = 0;            /*  parity, */
  226. int pportflow = FLO_KEEP;        /*  and flow control */
  227. #endif /* BPRINT */
  228. #ifdef OS2
  229. extern int txt2ps;                      /* Text2PS conversion? */
  230. extern int ps_width, ps_length;         /* Text2PS dimensions */
  231. #endif /* OS2 */
  232. #endif /* PRINTSWI */
  233.  
  234. #ifdef OS2
  235. extern int tcp_avail;            /* Nonzero if TCP/IP is available */
  236. #ifdef DECNET
  237. extern int dnet_avail;            /* Ditto for DECnet */
  238. #endif /* DECNET */
  239. #ifdef SUPERLAT
  240. extern int slat_avail;
  241. #endif /* SUPERLAT */
  242. #endif /* OS2 */
  243.  
  244. static struct keytab logintab[] = {
  245.     { "password", LOGI_PSW, CM_INV },
  246.     { "prompt",   LOGI_PRM, CM_INV },
  247.     { "userid",   LOGI_UID, 0 }
  248. };
  249.  
  250. #ifndef NOCSETS
  251. /* system-independent character sets, defined in ckcxla.[ch] */
  252. extern struct csinfo tcsinfo[];
  253. extern struct langinfo langs[];
  254.  
  255. /* Other character-set related variables */
  256. extern int tcharset, tslevel, language;
  257. #endif /* NOCSETS */
  258.  
  259. /* File-transfer variable declarations */
  260.  
  261. #ifndef NOXFER
  262. #ifdef CK_AUTODL
  263. extern int cmdadl;
  264. #endif /* CK_AUTODL */
  265.  
  266. #ifndef NOSERVER
  267. extern int ngetpath;
  268. extern char * getpath[];
  269. #endif /* NOSERVER */
  270.  
  271. extern struct ck_p ptab[];
  272.  
  273. extern CHAR sstate;            /* Protocol start state */
  274. extern CHAR myctlq;            /* Control-character prefix */
  275. extern CHAR myrptq;            /* Repeat-count prefix */
  276.  
  277. extern int protocol, size, spsiz, spmax, urpsiz, srvtim, srvcdmsg, slostart,
  278.   srvdis, xfermode, ckdelay, keep, maxtry, unkcs, bctr, ebqflg, swcapr,
  279.   wslotr, lscapr, lscapu, spsizr, rptena, rptmin, docrc, xfrcan, xfrchr,
  280.   xfrnum, xfrbel, xfrint, srvping, g_xfermode, xfrxla;
  281.  
  282. #ifdef PIPESEND
  283. extern int usepipes;
  284. #endif /* PIPESEND */
  285.  
  286. #ifdef CKXXCHAR                /* DOUBLE / IGNORE char table */
  287. extern int dblflag, ignflag, dblchar;
  288. extern short dblt[];
  289. #endif /* CKXXCHAR */
  290.  
  291. #ifdef CK_SPEED
  292. extern short ctlp[];            /* Control-prefix table */
  293. extern int prefixing;
  294. static struct keytab pfxtab[] = {
  295.     "all",         PX_ALL, 0,
  296.     "cautious",    PX_CAU, 0,
  297.     "minimal",     PX_WIL, 0,
  298.     "none",        PX_NON, CM_INV
  299. };
  300. #endif /* CK_SPEED */
  301. #endif /* NOXFER */
  302.  
  303. /* Declarations from cmd package */
  304.  
  305. #ifdef DCMDBUF
  306. extern char *cmdbuf;            /* Command buffer */
  307. extern char *line;
  308. extern char *tmpbuf;
  309. #else
  310. extern char cmdbuf[];            /* Command buffer */
  311. extern char line[];            /* Character buffer for anything */
  312. extern char tmpbuf[];
  313. #endif /* DCMDBUF */
  314.  
  315. /* From main ckuser module... */
  316.  
  317. extern char *tp, *lp;            /* Temporary buffer */
  318.  
  319. extern int tlevel;            /* Take Command file level */
  320.  
  321. #ifndef NOLOCAL
  322. extern int sessft;            /* Session-log file type */
  323. extern int slogts;            /* Session-log timestamps on/off */
  324. #endif /* NOLOCAL */
  325.  
  326. char * tempdir = NULL;
  327.  
  328. #ifdef VMS
  329. int vms_msgs = 1;            /* SET MESSAGES */
  330. extern int batch;
  331. #endif /* VMS */
  332.  
  333. /* Keyword tables for SET commands */
  334.  
  335. #ifdef CK_SPEED
  336. struct keytab ctltab[] = {
  337.     "prefixed",   1, 0,            /* Note, the values are important. */
  338.     "unprefixed", 0, 0
  339. };
  340. #endif /* CK_SPEED */
  341.  
  342. static struct keytab oldnew[] = {
  343.     "new", 0, 0,
  344.     "old", 1, 0
  345. };
  346.  
  347. #ifndef NOSPL
  348. static struct keytab functab[] = {
  349.     "diagnostics", FUNC_DI, 0,
  350.     "error",       FUNC_ER, 0
  351. };
  352. static int nfunctab = (sizeof(functab) / sizeof(struct keytab));
  353.  
  354. struct keytab outptab[] = {        /* SET OUTPUT parameters */
  355.     "pacing", 0, 0,            /* only one so far... */
  356.     "special-escapes", 1, 0
  357. };
  358. int noutptab = (sizeof(outptab) / sizeof(struct keytab)); /* How many */
  359. #endif /* NOSPL */
  360.  
  361. struct keytab chktab[] = {        /* Block check types */
  362.     "1", 1, 0,                /* 1 =  6-bit checksum */
  363.     "2", 2, 0,                /* 2 = 12-bit checksum */
  364.     "3", 3, 0,                /* 3 = 16-bit CRC */
  365.     "4", 4, CM_INV,            /* Same as B */
  366.     "blank-free-2", 4, 0        /* B = 12-bit checksum, no blanks */
  367. };
  368.  
  369. struct keytab rpttab[] = {        /* SET REPEAT */
  370.     "counts",    0, 0,            /* On or Off */
  371. #ifdef COMMENT
  372.     "minimum",   1, 0,            /* Threshhold */
  373. #endif /* COMMENT */
  374.     "prefix",    2, 0            /* Repeat-prefix character value */
  375. };
  376.  
  377. #ifndef NOLOCAL
  378. /* For SET [ MODEM ] CARRIER, and also for SET DIAL CONNECT */
  379.  
  380. struct keytab crrtab[] = {
  381.     "automatic", CAR_AUT, 0,        /* 2 */
  382.     "off",       CAR_OFF, 0,        /* 0 */
  383.     "on",        CAR_ON,  0        /* 1 */
  384. };
  385. int ncrr = 3;
  386. #endif /* NOLOCAL */
  387.  
  388. struct keytab ooatab[] = {        /* On/Off/Auto table */
  389.     "automatic", SET_AUTO, 0,        /* 2 */
  390.     "off",       SET_OFF,  0,        /* 0 */
  391.     "on",        SET_ON,   0        /* 1 */
  392. };
  393.  
  394. struct keytab qvtab[] = {        /* Quiet/Verbose table */
  395.     "quiet", 1, 0,
  396.     "verbose", 0, 0
  397. };
  398. int nqvt = 2;
  399.  
  400. /* For SET DEBUG */
  401.  
  402. #define DEB_OFF  0
  403. #define DEB_ON   1
  404. #define DEB_SES  2
  405. #define DEB_TIM  3
  406. #define DEB_LEN  4
  407.  
  408. struct keytab dbgtab[] = {
  409.     "linelength", DEB_LEN, CM_INV,
  410.     "off",        DEB_OFF, 0,
  411.     "on",         DEB_ON,  0,
  412.     "session",    DEB_SES, 0,
  413.     "timestamps", DEB_TIM, 0
  414. };
  415. int ndbg = (sizeof(dbgtab) / sizeof(struct keytab));
  416.  
  417. #ifndef NOLOCAL
  418. /* Transmission speeds */
  419.  
  420. #ifdef TTSPDLIST /* Speed table constructed at runtime . . . */
  421.  
  422. struct keytab * spdtab = NULL;
  423. int nspd = 0;
  424.  
  425. #else
  426. /*
  427.   Note, the values are encoded in cps rather than bps because 19200 and higher
  428.   are too big for some ints.  All but 75bps are multiples of ten.  Result of
  429.   lookup in this table must be multiplied by 10 to get actual speed in bps.
  430.   If this number is 70, it must be changed to 75.  If it is 888, this means
  431.   75/1200 split speed.
  432.  
  433.   The values are generic, rather than specific to UNIX.  We can't use B75,
  434.   B1200, B9600, etc, because non-UNIX versions of C-Kermit will not
  435.   necessarily have these symbols defined.  The BPS_xxx symbols are
  436.   Kermit-specific, and are defined in ckcdeb.h or on the CC command line.
  437.  
  438.   Like all other keytabs, this one must be in "alphabetical" order,
  439.   rather than numeric order.
  440. */
  441. struct keytab spdtab[] = {
  442.     "0",      0,  CM_INV,
  443.     "110",   11,  0,
  444. #ifdef BPS_115K
  445.  "115200",11520,  0,
  446. #endif /* BPS_115K */
  447.   "1200",   120,  0,
  448. #ifdef BPS_134
  449.   "134.5",  134,  0,
  450. #endif /* BPS_134 */
  451. #ifdef BPS_14K
  452.   "14400", 1440,  0,
  453. #endif /* BPS_14K */
  454. #ifdef BPS_150
  455.   "150",     15,  0,
  456. #endif /* BPS_150 */
  457. #ifdef BPS_1800
  458.   "1800",     180,  0,
  459. #endif /* BPS_150 */
  460. #ifdef BPS_19K
  461.   "19200", 1920,  0,
  462. #endif /* BPS_19K */
  463. #ifdef BPS_200
  464.   "200",     20,  0,
  465. #endif /* BPS_200 */
  466. #ifdef BPS_230K
  467.   "230400", 23040, 0,
  468. #endif /* BPS_230K */
  469.   "2400",   240,  0,
  470. #ifdef BPS_28K
  471.   "28800", 2880,  0,
  472. #endif /* BPS_28K */
  473.   "300",     30,  0,
  474. #ifdef BPS_3600
  475.   "3600",   360,  0,
  476. #endif /* BPS_3600 */
  477. #ifdef BPS_38K
  478.   "38400", 3840,  0,
  479. #endif /* BPS_38K */
  480. #ifdef BPS_460K
  481.   "460800", 46080,  0,            /* Need 32 bits for this... */
  482. #endif /* BPS_460K */
  483.   "4800",   480,  0,
  484. #ifdef BPS_50
  485.   "50",       5,  0,
  486. #endif /* BPS_50 */
  487. #ifdef BPS_57K
  488.   "57600", 5760,  0,
  489. #endif /* BPS_57K */
  490.   "600",     60,  0,
  491. #ifdef BPS_7200
  492.   "7200",   720,  0,
  493. #endif /* BPS_7200 */
  494. #ifdef BPS_75
  495.   "75",       7,  0,
  496. #endif /* BPS_75 */
  497. #ifdef BPS_7512
  498.   "75/1200",888,  0,            /* Code "888" for split speed */
  499. #endif /* BPS_7512 */
  500. #ifdef BPS_76K
  501.   "76800", 7680,  0,
  502. #endif /* BPS_76K */
  503. #ifdef BPS_921K
  504.   "921600", 92160,0,            /* Need 32 bits for this... */
  505. #endif /* BPS_921K */
  506.   "9600",   960,  0
  507. };
  508. int nspd = (sizeof(spdtab) / sizeof(struct keytab)); /* How many speeds */
  509. #endif /* TTSPDLIST */
  510.  
  511. #ifdef TN_COMPORT
  512. struct keytab tnspdtab[] = {        /* RFC 2217 TELNET COMPORT Option */
  513.     "115200", 11520,  0,        /* (add any other defined speeds) */
  514.     "1200",     120,  0,
  515.     "14400",   1440,  0,
  516.     "19200",   1920,  0,
  517.     "230400", 23040,  0,
  518.     "2400",     240,  0,
  519.     "28800",   2880,  0,
  520.     "300",       30,  0,
  521.     "38400",   3840,  0,
  522.     "460800", 46080,  0,
  523.     "4800",     480,  0,
  524.     "57600",   5760,  0,
  525.     "600",       60,  0,
  526.     "9600",     960,  0
  527. };
  528. int ntnspd = (sizeof(tnspdtab) / sizeof(struct keytab)); /* How many speeds */
  529. #endif /* TN_COMPORT */
  530. #endif /* NOLOCAL */
  531.  
  532. #ifndef NOCSETS
  533. extern struct keytab lngtab[];        /* Languages for SET LANGUAGE */
  534. extern int nlng;
  535. #endif /* NOCSETS */
  536.  
  537. #ifndef NOLOCAL
  538. /* Duplex keyword table */
  539.  
  540. struct keytab dpxtab[] = {
  541.     "full",      0, 0,
  542.     "half",      1, 0
  543. };
  544. #endif /* NOLOCAL */
  545.  
  546. /* Flow Control */
  547.  
  548. struct keytab cxtypesw[] = {
  549. #ifdef DECNET
  550.     "/decnet",         CXT_DECNET,  0,
  551. #endif /* DECNET */
  552.     "/direct-serial",  CXT_DIRECT,  0,
  553. #ifdef DECNET
  554.     "/lat",            CXT_LAT,     0,
  555. #else
  556. #ifdef SUPERLAT
  557.     "/lat",            CXT_LAT,     0,
  558. #endif /* SUPERLAT */
  559. #endif /* DECNET */
  560.     "/modem",          CXT_MODEM,   0,
  561. #ifdef NPIPE
  562.     "/named-pipe",     CXT_NPIPE,   0,
  563. #endif /* NPIPE */
  564. #ifdef NETBIOS
  565.     "/netbios",        CXT_NETBIOS, 0,
  566. #endif /* NETBIOS */
  567.     "/remote",         CXT_REMOTE,  0,
  568. #ifdef TCPSOCKET
  569.     "/tcpip",          CXT_TCPIP,   0,
  570. #endif /* TCPSOCKET */
  571. #ifdef ANYX25
  572.     "/x.25",           CXT_X25,     0,
  573. #endif /* ANYX25 */
  574.     "", 0, 0
  575. };
  576. int ncxtypesw = (sizeof(cxtypesw) / sizeof(struct keytab));
  577.  
  578. #ifdef TN_COMPORT
  579. struct keytab tnflotab[] = {        /* SET FLOW-CONTROL keyword table */
  580.     "dtr/cd",    FLO_DTRC, 0,        /* for RFC 2217 Telnet COMPORT */
  581.     "dtr/cts",   FLO_DTRT, 0,
  582.     "keep",      FLO_KEEP, 0,
  583.     "none",      FLO_NONE, 0,
  584.     "rts/cts",   FLO_RTSC, 0,
  585.     "xon/xoff",  FLO_XONX, 0
  586. };
  587. int ntnflo = (sizeof(tnflotab) / sizeof(struct keytab));
  588. #endif /* TN_COMPORT */
  589.  
  590. struct keytab flotab[] = {        /* SET FLOW-CONTROL keyword table */
  591.     "automatic", FLO_AUTO, CM_INV,    /* Not needed any more */
  592. #ifdef CK_DTRCD
  593.     "dtr/cd",    FLO_DTRC, 0,
  594. #endif /* CK_DTRCD */
  595. #ifdef CK_DTRCTS
  596.     "dtr/cts",   FLO_DTRT, 0,
  597. #endif /* CK_DTRCTS */
  598.     "keep",      FLO_KEEP, 0,
  599.     "none",      FLO_NONE, 0,
  600. #ifdef CK_RTSCTS
  601.     "rts/cts",   FLO_RTSC, 0,
  602. #endif /* CK_RTSCTS */
  603. #ifndef Plan9
  604.     "xon/xoff",  FLO_XONX, 0,
  605. #endif /* Plan9 */
  606.     "", 0, 0
  607. };
  608. int nflo = (sizeof(flotab) / sizeof(struct keytab)) - 1;
  609.  
  610. /*  Handshake characters  */
  611.  
  612. struct keytab hshtab[] = {
  613.     "bell", 007, 0,
  614.     "code", 998, 0,
  615.     "cr",   015, 0,
  616.     "esc",  033, 0,
  617.     "lf",   012, 0,
  618.     "none", 999, 0,            /* (can't use negative numbers) */
  619.     "xoff", 023, 0,
  620.     "xon",  021, 0
  621. };
  622. int nhsh = (sizeof(hshtab) / sizeof(struct keytab));
  623.  
  624. #ifndef NOLOCAL
  625. static struct keytab sfttab[] = {    /* File types for SET SESSION-LOG */
  626.     "ascii",     XYFT_T, CM_INV,
  627.     "binary",    XYFT_B, 0,
  628.     "debug",     XYFT_D, 0,
  629.     "text",      XYFT_T, 0,
  630.     "timestamped-text", 999, 0
  631. };
  632. static int nsfttab = (sizeof(sfttab) / sizeof(struct keytab));
  633. #endif /* NOLOCAL */
  634.  
  635. #ifndef NODIAL
  636.  
  637. #ifdef NETCONN                /* Networks directory depends */
  638. int nnetdir = 0;            /* on DIAL code -- fix later... */
  639. char *netdir[MAXDDIR+2];
  640. #endif /* NETCONN */
  641.  
  642. _PROTOTYP( static int setdial, (int) );
  643. _PROTOTYP( static int setdcd, (void) );
  644. _PROTOTYP( static int cklogin, (void) );
  645.  
  646. #ifndef MINIDIAL
  647. #ifdef OLDTBCODE
  648. extern int tbmodel;            /* Telebit model ID */
  649. #endif /* OLDTBCODE */
  650. #endif /* MINIDIAL */
  651.  
  652. extern MDMINF *modemp[];        /* Pointers to modem info structs */
  653. extern struct keytab mdmtab[];        /* Modem types (in module ckudia.c) */
  654. extern int nmdm;            /* Number of them */
  655.  
  656. _PROTOTYP(static int dialstr,(char **, char *));
  657.  
  658. extern int dialhng, dialtmo, dialksp, dialdpy, dialmhu, dialec, dialdc;
  659. extern int dialrtr, dialint, dialudt, dialsrt, dialrstr, mdmwaitd;
  660. extern int mdmspd, dialfc, dialmth, dialesc, dialfld, dialidt, dialpace;
  661. extern int mdmspk, mdmvol, dialtest;
  662.  
  663. int dialcvt = 2;            /* DIAL CONVERT-DIRECTORY */
  664. int dialcnf = 0;            /* DIAL CONFIRMATION */
  665. int dialcon = 2;            /* DIAL CONNECT */
  666. int dialcq  = 0;            /* DIAL CONNECT AUTO quiet/verbose */
  667. extern long dialmax, dialcapas;
  668. int usermdm = 0;
  669. extern int ndialdir;
  670. extern char *dialini,   *dialmstr, *dialmprmt, *dialdir[], *dialcmd,  *dialnpr,
  671.  *dialdcon, *dialdcoff, *dialecon, *dialecoff, *dialhcmd,  *dialx3,
  672.  *dialhwfc, *dialswfc,  *dialnofc, *dialtone,  *dialpulse, *dialname, *diallac;
  673. extern char *diallcc,   *dialixp,  *dialixs,   *dialldp,   *diallds,  *dialtfp,
  674.  *dialpxi,  *dialpxo,   *dialsfx,  *dialaaon,  *dialaaoff;
  675. extern char *diallcp,   *diallcs,  *dialini2,  *dialmac;
  676. extern char *dialspoff, *dialspon, *dialvol1,  *dialvol2,  *dialvol3;
  677.  
  678. char *dialtocc[MAXTPCC] = { NULL, NULL };
  679. int ndialtocc = 0;
  680. char *dialpucc[MAXTPCC] = { NULL, NULL };
  681. int ndialpucc = 0;
  682.  
  683. char *dialtfc[MAXTOLLFREE] = {
  684.     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
  685. };
  686. int ntollfree = 0;
  687.  
  688. char *dialpxx[MAXPBXEXCH] = {
  689.     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
  690. };
  691. int ndialpxx = 0;
  692.  
  693. char *diallcac[MAXLOCALAC] = {
  694.     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  695.     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  696.     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  697.     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
  698. };
  699. int nlocalac = 0;
  700.  
  701. static struct keytab drstrtab[] = {
  702.     "international", 5, 0,
  703.     "local",         2, 0,
  704.     "long-distance", 4, 0,
  705.     "none",          6, 0
  706. };
  707.  
  708. static struct keytab dcnvtab[] = {
  709.     "ask",  2, 0,
  710.     "off",  0, 0,
  711.     "on",   1, 0
  712. };
  713.  
  714. struct keytab setmdm[] = {
  715.     "capabilities",    XYDCAP,  0,
  716.     "carrier-watch",    XYDMCD,  0,
  717.     "command",        XYDSTR,  0,
  718.     "compression",    XYDDC,   CM_INV,
  719.     "data-compression", XYDDC,   0,
  720.     "dial-command",     XYDDIA,  0,
  721.     "error-correction",    XYDEC,   0,
  722.     "escape-character",    XYDESC,  0,
  723.     "flow-control",    XYDFC,   0,
  724.     "hangup-method",    XYDMHU,  0,
  725. #ifndef NOXFER
  726.     "kermit-spoof",    XYDKSP,  0,
  727. #endif /* NOXFER */
  728.     "maximum-speed",    XYDMAX,  0,
  729.     "name",        XYDNAM,  0,
  730.     "speaker",          XYDSPK,  0,
  731.     "speed-matching",    XYDSPD,  0,
  732.     "type",        XYDTYP,  0,
  733.     "volume",           XYDVOL,  0
  734. };
  735. int nsetmdm = (sizeof(setmdm) / sizeof(struct keytab));
  736.  
  737. struct keytab voltab[] = {
  738.     "high",   3,  0,
  739.     "low",    1,  0,
  740.     "medium", 2,  0
  741. };
  742.  
  743. struct keytab mdmcap[] = {
  744.     "at-commands",    CKD_AT,  0,
  745.     "compression",      CKD_DC,  0,
  746.     "dc",               CKD_DC,  CM_INV,
  747.     "ec",               CKD_EC,  CM_INV,
  748.     "error-correction", CKD_EC,  0,
  749.     "hardware-flow",    CKD_HW,  0,
  750.     "hwfc",             CKD_HW,  CM_INV,
  751.     "itu",              CKD_V25, CM_INV,
  752.     "kermit-spoof",    CKD_KS,  0,
  753.     "ks",               CKD_KS,  CM_INV,
  754.     "sb",               CKD_SB,  CM_INV,
  755.     "software-flow",    CKD_SW,  0,
  756.     "speed-buffering",  CKD_SB,  0,
  757.     "swfc",             CKD_SW,  CM_INV,
  758.     "tb",               CKD_TB,  CM_INV,
  759.     "telebit",          CKD_TB,  0,
  760.     "v25bis-commands",    CKD_V25, 0
  761. };
  762. int nmdmcap = (sizeof(mdmcap) / sizeof(struct keytab));
  763.  
  764. struct keytab dialtab[] = {        /* SET DIAL table */
  765.     "area-code",        XYDLAC, 0,    /* Also still includes items     */
  766.     "compression",    XYDDC,  CM_INV,    /* that were moved to SET MODEM, */
  767.     "confirmation",    XYDCNF, 0,    /* but they are CM_INVisible...  */
  768.     "connect",          XYDCON, 0,
  769.     "convert-directory",XYDCVT, 0,
  770.     "country-code",     XYDLCC, 0,
  771.     "dial-command",    XYDDIA, CM_INV,
  772.     "directory",    XYDDIR, 0,
  773.     "display",        XYDDPY, 0,
  774.     "escape-character", XYDESC, CM_INV,
  775.     "error-correction",    XYDEC,  CM_INV,
  776.     "flow-control",    XYDFC,  CM_INV,
  777.     "force-long-distance", XYDFLD, 0,
  778.     "hangup",        XYDHUP, 0,
  779.     "ignore-dialtone",  XYDIDT, 0,
  780.     "interval",        XYDINT, 0,
  781.     "in",        XYDINI, CM_INV|CM_ABR,
  782.     "init-string",    XYDINI, CM_INV,
  783.     "intl-prefix",    XYDIXP, 0,
  784.     "intl-suffix",    XYDIXS, 0,
  785. #ifndef NOXFER
  786.     "kermit-spoof",    XYDKSP, CM_INV,
  787. #endif /* NOXFER */
  788.     "lc-area-codes",    XYDLLAC, 0,
  789.     "lc-prefix",        XYDLCP, 0,
  790.     "lc-suffix",        XYDLCS, 0,
  791.     "ld-prefix",    XYDLDP, 0,
  792.     "ld-suffix",    XYDLDS, 0,
  793.     "local-area-code",  XYDLAC, CM_INV,
  794.     "local-prefix",     XYDLCP, CM_INV,
  795.     "local-suffix",     XYDLCS, CM_INV,
  796.     "m",                XYDMTH, CM_INV|CM_ABR,
  797. #ifndef NOSPL
  798.     "macro",            XYDMAC, 0,    /* 195 */
  799. #endif /* NOSPL */
  800. #ifdef MDMHUP
  801.     "me",               XYDMTH, CM_INV|CM_ABR,
  802. #endif /* MDMHUP */
  803.     "method",        XYDMTH, 0,
  804.     "mnp-enable",    XYDMNP, CM_INV,    /* obsolete but still accepted */
  805. #ifdef MDMHUP
  806.     "modem-hangup",    XYDMHU, CM_INV,
  807. #endif /* MDMHUP */
  808.     "pacing",           XYDPAC,  0,
  809.     "pbx-exchange",     XYDPXX,  0,
  810.     "pbx-inside-prefix",XYDPXI,  0,
  811.     "pbx-outside-prefix",XYDPXO, 0,
  812.     "prefix",        XYDNPR,  0,
  813.     "pulse-countries",  XYDPUCC, 0,
  814.     "restrict",         XYDRSTR, 0,
  815.     "retries",        XYDRTM,  0,
  816.     "sort",             XYDSRT,  0,
  817.     "speed-matching",    XYDSPD,  CM_INV,
  818.     "string",        XYDSTR,  CM_INV,
  819.     "suffix",        XYDSFX,  0,
  820.     "test",             XYDTEST, 0,
  821.     "timeout",        XYDTMO,  0,
  822.     "tf-area-code",     XYDTFC,  CM_INV,
  823.     "tf-prefix",        XYDTFP,  CM_INV,
  824.     "toll-free-area-code",XYDTFC,0,
  825.     "toll-free-prefix", XYDTFP,  0,
  826.     "tone-countries",   XYDTOCC, 0
  827. };
  828. int ndial = (sizeof(dialtab) / sizeof(struct keytab));
  829.  
  830. #ifdef MDMHUP
  831. struct keytab mdmhang[] = {
  832.     "dtr",           0, 0,
  833.     "modem-command", 1, 0,
  834.     "rs232-signal",  0, 0,
  835.     "v24-signal",    0, CM_INV
  836. };
  837. #endif /* MDMHUP */
  838.  
  839. static struct keytab mdmcmd[] = {
  840.     "autoanswer",       XYDS_AN, 0,    /* autoanswer */
  841.     "compression",    XYDS_DC, 0,    /* data compression */
  842.     "dial-mode-prompt", XYDS_MP, 0,    /* dial mode prompt */
  843.     "dial-mode-string", XYDS_MS, 0,    /* dial mode string */
  844.     "error-correction",    XYDS_EC, 0,    /* error correction */
  845.     "hangup-command",    XYDS_HU, 0,    /* hangup command */
  846.     "hardware-flow",    XYDS_HW, 0,    /* hwfc */
  847.     "ignore-dialtone",    XYDS_ID, 0,    /* ignore dialtone */
  848.     "init-string",    XYDS_IN, 0,    /* init string */
  849.     "no-flow-control",    XYDS_NF, 0,    /* no flow control */
  850.     "predial-init",     XYDS_I2, 0,     /* last-minute setup commands */
  851.     "pulse",            XYDS_DP, 0,    /* pulse */
  852.     "software-flow",    XYDS_SW, 0,    /* swfc */
  853.     "speaker",          XYDS_SP, 0,     /* Speaker */
  854.     "tone",             XYDS_DT, 0,    /* tone */
  855.     "volume",           XYDS_VO, 0      /* Volume */
  856. };
  857. static int nmdmcmd = (sizeof(mdmcmd) / sizeof(struct keytab));
  858.  
  859. struct keytab dial_fc[] = {
  860.     "auto",     FLO_AUTO, 0,
  861.     "none",     FLO_NONE, 0,
  862.     "rts/cts",  FLO_RTSC, 0,
  863.     "xon/xoff", FLO_XONX, 0
  864. };
  865.  
  866. struct keytab dial_m[] = {        /* DIAL METHOD */
  867.     "auto",    XYDM_A, 0,
  868.     "default", XYDM_D, 0,
  869.     "pulse",   XYDM_P, 0,
  870.     "tone",    XYDM_T, 0
  871. };
  872. int ndial_m = (sizeof(dial_m)/sizeof(struct keytab));
  873.  
  874. #ifdef CK_TAPI
  875. struct keytab tapitab[] = {        /* Top-Level Microsoft TAPI */
  876.     "configure-line",     XYTAPI_CFG,  0,
  877.     "dialing-properties", XYTAPI_DIAL, 0
  878. };
  879. int ntapitab = (sizeof(tapitab)/sizeof(struct keytab));
  880.  
  881. struct keytab settapitab[] = {        /* SET Microsoft TAPI */
  882.     "inactivity-timeout", XYTAPI_INA,  0,
  883.     "line",               XYTAPI_LIN,  0,
  884.     "location",           XYTAPI_LOC,  0,
  885.     "manual-dialing",     XYTAPI_MAN,  0,
  886.     "modem-dialing",      XYTAPI_PASS, 0,
  887.     "modem-lights",       XYTAPI_LGHT, 0,
  888.     "phone-number-conversions",      XYTAPI_CON,  0,
  889.     "port",               XYTAPI_LIN,  CM_INV,
  890.     "post-dial-terminal", XYTAPI_PST,  0,
  891.     "pre-dial-terminal",  XYTAPI_PRE,  0,
  892.     "use-windows-configuration", XYTAPI_USE, 0,
  893.     "wait-for-credit-card-tone", XYTAPI_BNG, 0
  894. };
  895. int nsettapitab = (sizeof(settapitab)/sizeof(struct keytab));
  896.  
  897. struct keytab * tapiloctab = NULL;    /* Microsoft TAPI Locations */
  898. int ntapiloc = 0;
  899. extern struct keytab * tapilinetab;    /* Microsoft TAPI Line Devices */
  900. extern int ntapiline;
  901. extern int tttapi;            /* TAPI in use */
  902. extern int tapipass;            /* TAPI Passthrough mode */
  903. extern int tapiconv;            /* TAPI Conversion mode */
  904. extern int tapilights;
  905. extern int tapipreterm;
  906. extern int tapipostterm;
  907. extern int tapimanual;
  908. extern int tapiinactivity;
  909. extern int tapibong;
  910. extern int tapiusecfg;
  911. #endif /* CK_TAPI */
  912. #endif /* NODIAL */
  913.  
  914. #ifndef NOPUSH
  915. extern int nopush;
  916. #ifdef UNIX
  917. struct keytab wildtab[] = {        /* SET WILDCARD-EXPANSION */
  918.     "kermit",  0, 0,
  919.     "shell",   1, 0
  920. };
  921. struct keytab wdottab[] = {        /* cont'd */
  922.     "/match-dot-files",    1, 0,
  923.     "/no-match-dot-files", 0, 0
  924. };
  925. extern int wildxpand;
  926. #endif /* UNIX */
  927. #endif /* NOPUSH */
  928.  
  929. #ifdef NETCONN
  930. extern struct keytab netcmd[], netkey[];
  931. extern int nnets, nnetkey;
  932. #ifdef TCPSOCKET
  933. extern struct keytab tcpopt[];
  934. extern int ntcpopt;
  935. #ifndef NOTCPOPTS
  936. #ifdef SO_LINGER
  937. _PROTOTYP( int linger, (int,int) );
  938. #endif /* SO_LINGER */
  939. #ifdef TCP_NODELAY
  940. _PROTOTYP( int no_delay, (int) );
  941. #endif /* TCP_NODELAY */
  942. #endif /* NOTCPOPTS */
  943. #endif /* TCPSOCKET */
  944. #ifdef NPIPE
  945. char pipename[PIPENAML+1] = { NUL, NUL };
  946. #endif /* NPIPE */
  947. #ifdef CK_NETBIOS
  948. extern unsigned char NetBiosName[];
  949. #endif /* CK_NETBIOS */
  950. #endif /* NETCONN */
  951.  
  952. #ifdef ANYX25
  953. struct keytab x25tab[] = {
  954.     "call-user-data",    XYUDAT, 0,
  955.     "closed-user-group", XYCLOS, 0,
  956.     "reverse-charge",    XYREVC, 0
  957. };
  958. int nx25 = (sizeof(x25tab) / sizeof(struct keytab));
  959.  
  960. #ifndef IBMX25
  961. struct keytab padx3tab[] = {
  962.     "break-action",         PAD_BREAK_ACTION,           0,
  963.     "break-character",      PAD_BREAK_CHARACTER,        0,
  964.     "character-delete",     PAD_CHAR_DELETE_CHAR,       0,
  965.     "cr-padding",           PAD_PADDING_AFTER_CR,       0,
  966.     "discard-output",       PAD_SUPPRESSION_OF_DATA,    0,
  967.     "echo",                 PAD_ECHO,                   0,
  968.     "editing",              PAD_EDITING,                0,
  969.     "escape",               PAD_ESCAPE,                 0,
  970.     "forward",              PAD_DATA_FORWARD_CHAR,      0,
  971.     "lf-padding",           PAD_PADDING_AFTER_LF,       0,
  972.     "lf-insert",            PAD_LF_AFTER_CR,            0,
  973.     "line-delete",          PAD_BUFFER_DELETE_CHAR,     0,
  974.     "line-display",         PAD_BUFFER_DISPLAY_CHAR,    0,
  975.     "line-fold",            PAD_LINE_FOLDING,           0,
  976.     "pad-flow-control",     PAD_FLOW_CONTROL_BY_PAD,    0,
  977.     "service-signals",      PAD_SUPPRESSION_OF_SIGNALS, 0,
  978.     "timeout",              PAD_DATA_FORWARD_TIMEOUT,   0,
  979. /* Speed is read-only */
  980.     "transmission-rate",    PAD_LINE_SPEED,             0,
  981.     "user-flow-control",    PAD_FLOW_CONTROL_BY_USER,   0
  982. };
  983. int npadx3 = (sizeof(padx3tab) / sizeof(struct keytab));
  984. #endif /* IBMX25 */
  985. #endif /* ANYX25 */
  986.  
  987. #ifdef TLOG
  988. static struct keytab vbtab[] = {
  989.     "brief",   0, 0,
  990. #ifdef OS2ORUNIX
  991.     "ftp",     2, 0,
  992. #endif /* OS2ORUNIX */
  993.     "verbose", 1, 0
  994. };
  995. int nvb = (sizeof(vbtab) / sizeof(struct keytab));
  996. #endif /* TLOG */
  997.  
  998. #ifdef CKSYSLOG
  999. static struct keytab syslogtab[] = {
  1000.     "all",         SYSLG_CX, 0,
  1001.     "commands",    SYSLG_CM, 0,
  1002.     "connection",  SYSLG_AC, 0,
  1003.     "debug",       SYSLG_DB, 0,
  1004.     "dial",        SYSLG_DI, 0,
  1005.     "file-access", SYSLG_FA, 0,
  1006.     "file-create", SYSLG_FC, 0,
  1007.     "login",       SYSLG_LI, 0,
  1008.     "none",        SYSLG_NO, 0,
  1009.     "protocol",    SYSLG_PR, 0
  1010. };
  1011. int nsyslog = (sizeof(syslogtab) / sizeof(struct keytab));
  1012. #endif /* CKSYSLOG */
  1013.  
  1014. /* Parity keyword table */
  1015.  
  1016. struct keytab partbl[] = {
  1017.     "even",    'e', 0,
  1018. #ifdef HWPARITY
  1019.     "hardware",'H', 0,
  1020. #endif /* HWPARITY */
  1021.     "mark",    'm', 0,
  1022.     "none",     0 , 0,
  1023.     "odd",     'o', 0,
  1024.     "space",   's', 0
  1025. };
  1026. int npar = (sizeof(partbl) / sizeof(struct keytab));
  1027.  
  1028. #ifdef HWPARITY
  1029. struct keytab hwpartbl[] = {
  1030. /* Add mark and space if needed and possible */
  1031.     "even",    'e', 0,
  1032. #ifdef OS2
  1033.     "mark",    'm', 0,
  1034. #endif /* OS2 */
  1035.     "odd",     'o', 0,
  1036. #ifdef OS2
  1037.     "space",   's', 0,
  1038. #endif /* OS2 */
  1039.     "", 0, 0
  1040. };
  1041. int nhwpar = (sizeof(hwpartbl) / sizeof(struct keytab)) - 1;
  1042. #endif /* HWPARITY */
  1043.  
  1044. /* On/Off table */
  1045.  
  1046. struct keytab onoff[] = {
  1047.     "off",       0, 0,
  1048.     "on",        1, 0
  1049. };
  1050.  
  1051. struct keytab cdtab[] = {
  1052.     "message",   XYCD_M, 0,
  1053.     "path",      XYCD_P, 0
  1054. };
  1055. int ncdtab = (sizeof(cdtab) / sizeof(struct keytab));
  1056.  
  1057. struct keytab cdmsg[] = {
  1058.     "file",      2, 0,
  1059.     "off",       0, 0,
  1060.     "on",        1, 0
  1061. };
  1062. int ncdmsg = (sizeof(cdmsg) / sizeof(struct keytab));
  1063.  
  1064. static
  1065. struct keytab xittab[] = {        /* SET EXIT */
  1066.     "hangup",        3, 0,        /* ...HANGUP */
  1067.     "on-disconnect", 2, 0,        /* ...ON-DISCONNECT */
  1068.     "status",        0, 0,        /* ...STATUS */
  1069.     "warning",       1, 0        /* ...WARNING */
  1070. };
  1071. int nexit = (sizeof(xittab) / sizeof(struct keytab));
  1072.  
  1073. struct keytab xitwtab[] = {        /* SET EXIT WARNING */
  1074.     "always", 2, 0,                     /* even when not connected */
  1075.     "off",    0, 0,            /* no warning     */
  1076.     "on",     1, 0            /* when connected */
  1077. };
  1078. int nexitw = (sizeof(xitwtab) / sizeof(struct keytab));
  1079.  
  1080. struct keytab rltab[] = {
  1081.     "local",     1, 0,            /* ECHO values */
  1082.     "off",       0, CM_INV,
  1083.     "on",        1, CM_INV,
  1084.     "remote",    0, 0
  1085. };
  1086. int nrlt = (sizeof(rltab) / sizeof(struct keytab));
  1087.  
  1088. /* Incomplete File Disposition table */
  1089.  
  1090. struct keytab ifdtab[] = {
  1091.     "discard", SET_OFF, 0,
  1092.     "keep",    SET_ON,  0
  1093. };
  1094.  
  1095. struct keytab ifdatab[] = {
  1096.     "auto",    SET_AUTO, 0,
  1097.     "discard", SET_OFF,  0,
  1098.     "keep",    SET_ON,   0
  1099. };
  1100.  
  1101. char * ifdnam[] = { "discard", "keep", "auto" };
  1102.  
  1103. /* SET TAKE parameters table */
  1104. static
  1105. struct keytab taktab[] = {
  1106.     "echo",  0, 0,
  1107.     "error", 1, 0,
  1108.     "off",   2, CM_INV,            /* For compatibility */
  1109.     "on",    3, CM_INV            /* with MS-DOS Kermit... */
  1110. };
  1111.  
  1112. #ifndef NOSPL
  1113. #ifdef COMMENT
  1114. /* not used */
  1115. static
  1116. struct keytab suftab[] = {        /* (what to do with) STARTUP-FILE */
  1117.     "delete", 1, 0,
  1118.     "keep",   0, 0
  1119. };
  1120. #endif /* COMMENT */
  1121.  
  1122. /* SET MACRO parameters table */
  1123. static
  1124. struct keytab smactab[] = {
  1125.     "echo",  0, 0,
  1126.     "error", 1, 0
  1127. };
  1128. #endif /* NOSPL */
  1129.  
  1130. #ifndef NOSCRIPT
  1131. static
  1132. struct keytab scrtab[] = {
  1133.     "echo",  0, 0
  1134. };
  1135. #endif /* NOSCRIPT */
  1136.  
  1137. /* SET COMMAND table */
  1138. static struct keytab scmdtab[] = {
  1139. #ifdef CK_AUTODL
  1140.     "autodownload",       SCMD_ADL, 0,
  1141. #endif /* CK_AUTODL */
  1142.     "bytesize",           SCMD_BSZ, 0,
  1143.     "cbreak",             876,      CM_INV,
  1144. #ifdef OS2
  1145.     "color",              SCMD_COL, 0,
  1146.     "cursor-position",    SCMD_CUR, 0,
  1147. #endif /* OS2 */
  1148. #ifdef DOUBLEQUOTING
  1149.     "doublequoting",      SCMD_DBQ, 0,
  1150. #endif /* DOUBLEQUOTING */
  1151.     "height",             SCMD_HIG, 0,
  1152.     "interruption",       SCMD_INT, 0,
  1153.     "more-prompting",     SCMD_MOR, 0,
  1154.     "quoting",            SCMD_QUO, 0,
  1155. #ifdef CK_RECALL
  1156.     "recall-buffer-size", SCMD_RCL, 0,
  1157. #endif /* CK_RECALL */
  1158. #ifdef CK_RECALL
  1159.     "retry",              SCMD_RTR, 0,
  1160. #endif /* CK_RECALL */
  1161. #ifdef OS2
  1162. #ifdef ONETERMUPD
  1163.     "scrollback",         SCMD_SCR, 0,
  1164.     "statusline",         SCMD_STA, 0,
  1165. #endif /* ONETERMUPD */
  1166. #endif /* OS2 */
  1167.     "width",              SCMD_WID, 0
  1168. };
  1169. static int nbytt = (sizeof(scmdtab) / sizeof(struct keytab));
  1170.  
  1171. #ifndef NOSERVER
  1172. /* Server parameters table */
  1173. static struct keytab srvtab[] = {
  1174.     "cd-message",   XYSERC, 0,
  1175.     "display",      XYSERD, 0,
  1176.     "get-path",     XYSERP, 0,
  1177.     "idle-timeout", XYSERI, 0,
  1178.     "keepalive",    XYSERK, 0,
  1179.     "login",        XYSERL, 0,
  1180.     "timeout",      XYSERT, 0
  1181. };
  1182. static int nsrvt = (sizeof(srvtab) / sizeof(struct keytab));
  1183. #endif /* NOSERVER */
  1184.  
  1185. static struct keytab sleeptab[] = {    /* SET SLEEP table */
  1186.     "cancellation",  0,   0
  1187. };
  1188.  
  1189. static struct keytab tstab[] = {    /* SET TRANSFER/XFER table */
  1190.     "bell",            XYX_BEL, 0,
  1191. #ifdef XFRCAN
  1192.     "cancellation",    XYX_CAN, 0,
  1193. #endif /* XFRCAN */
  1194. #ifndef NOCSETS
  1195.     "character-set",   XYX_CSE, 0,
  1196. #endif /* NOCSETS */
  1197. #ifndef NOSPL
  1198.     "crc-calculation", XYX_CRC, 0,
  1199. #endif /* NOSPL */
  1200.     "display",         XYX_DIS, 0,
  1201.     "interruption",    XYX_INT, 0,
  1202.     "locking-shift",   XYX_LSH, 0,
  1203.     "message",         XYX_MSG, 0,
  1204.     "mode",            XYX_MOD, 0,
  1205.     "msg",             XYX_MSG, CM_INV,
  1206. #ifdef PIPESEND
  1207.     "pipes",           XYX_PIP, 0,
  1208. #endif /* PIPESEND */
  1209. #ifdef CK_XYZ
  1210.     "protocol",        XYX_PRO, 0,
  1211. #endif /* CK_XYZ */
  1212.     "slow-start",      XYX_SLO, 0,
  1213. #ifndef NOCSETS
  1214.     "translation",     XYX_XLA, 0,
  1215. #else
  1216.     "translation",     XYX_XLA, CM_INV,
  1217. #endif /* NOCSETS */
  1218.     "xlation",         XYX_XLA, CM_INV,
  1219.     "", 0, 0
  1220. };
  1221. static int nts = (sizeof(tstab) / sizeof(struct keytab)) - 1;
  1222.  
  1223. static struct keytab rtstab[] = {    /* REMOTE SET TRANSFER/XFER table */
  1224. #ifndef NOCSETS
  1225.     "character-set",   XYX_CSE, 0,
  1226. #endif /* NOCSETS */
  1227.     "mode",            XYX_MOD, 0
  1228. };
  1229. static int nrts = (sizeof(rtstab) / sizeof(struct keytab));
  1230.  
  1231. struct keytab xfrmtab[] = {        /* TRANSFER MODE table */
  1232.     "automatic", XMODE_A, 0,
  1233.     "manual",    XMODE_M, 0
  1234. };
  1235.  
  1236. #ifndef NOCSETS
  1237. /* SET TRANSFER CHARACTER-SET table */
  1238.  
  1239. extern struct keytab tcstab[];
  1240. extern int ntcs;
  1241. #endif /* NOCSETS */
  1242.  
  1243. /* SET TRANSFER LOCKING-SHIFT table */
  1244. struct keytab lstab[] = {
  1245.     "forced", 2,   0,
  1246.     "off",    0,   0,
  1247.     "on",     1,   0
  1248. };
  1249. int nls = (sizeof(lstab) / sizeof(struct keytab));
  1250.  
  1251. /* SET TELNET tables */
  1252. #ifdef TNCODE
  1253. extern int tn_nlm, tn_b_nlm, tn_b_meu, tn_b_ume, tn_b_xfer, tn_sb_bug;
  1254. extern int tn_no_encrypt_xfer;
  1255. extern int tn_wait_flg, tn_duplex, tn_delay_sb, tn_sfu;
  1256. extern int sl_tn_saved;
  1257. extern int tn_infinite;
  1258. extern int tn_rem_echo;
  1259. extern int tn_deb;
  1260. extern int tn_auth_how;
  1261. extern int tn_auth_enc;
  1262. #ifdef CK_FORWARD_X
  1263. extern char * tn_fwdx_xauthority;
  1264. #endif /* CK_FORWARD_X */
  1265. #ifdef CK_AUTHENTICATION
  1266. static struct keytab setauth[] = {
  1267. #ifdef CK_KERBEROS
  1268.     "k4",        AUTH_KRB4, CM_INV,
  1269.     "k5",        AUTH_KRB5, CM_INV,
  1270.     "kerberos4", AUTH_KRB4, 0,
  1271.     "kerberos5", AUTH_KRB5, 0,
  1272.     "kerberos_iv",AUTH_KRB4, CM_INV,
  1273.     "kerberos_v", AUTH_KRB5, CM_INV,
  1274.     "krb4",      AUTH_KRB4, CM_INV,
  1275.     "krb5",      AUTH_KRB5, CM_INV,
  1276. #endif /* CK_KERBEROS */
  1277. #ifdef CK_SRP
  1278.     "srp",       AUTH_SRP,  0,
  1279. #endif /* CK_SRP */
  1280. #ifdef CK_SSL
  1281.     "ssl",      AUTH_SSL,   0,
  1282.     "tls",      AUTH_TLS,   0,
  1283. #endif /* CK_SSL */
  1284.     "",         0,      0
  1285. };
  1286. static int nsetauth = sizeof(setauth)/sizeof(struct keytab) - 1;
  1287. #ifdef CK_KERBEROS
  1288. extern char * krb5_d_principal;        /* Default principal */
  1289. extern char * krb5_d_instance;
  1290. extern char * krb5_d_realm;        /* Default realm */
  1291. extern char * krb5_d_cc;        /* Default credentials cache */
  1292. extern char * krb5_d_srv;               /* Default service name */
  1293. extern int    krb5_d_lifetime;          /* Default lifetime */
  1294. extern int    krb5_d_forwardable;
  1295. extern int    krb5_d_proxiable;
  1296. extern int    krb5_d_renewable;
  1297. extern int    krb5_autoget;
  1298. extern int    krb5_autodel;
  1299. extern int    krb5_d_getk4;
  1300. extern int    krb5_checkaddrs;        /* Check TGT Addrs */
  1301. extern int    krb5_d_no_addresses;
  1302. extern char * krb5_d_addrs[];
  1303. extern char * k5_keytab;                /* Keytab file */
  1304.  
  1305. extern struct krb4_init_data krb4_init;
  1306. extern char * krb4_d_principal;        /* Default principal */
  1307. extern char * krb4_d_realm;        /* Default realm */
  1308. extern char * krb4_d_srv;               /* Default service name */
  1309. extern int    krb4_d_lifetime;          /* Default lifetime */
  1310. extern int    krb4_d_preauth;
  1311. extern char * krb4_d_instance;
  1312. extern int    krb4_autoget;
  1313. extern int    krb4_autodel;
  1314. extern int    krb4_checkaddrs;        /* Check TGT Addrs */
  1315. extern char * k4_keytab;                /* Keytab file */
  1316. #ifdef KRB4
  1317. extern int    k4debug;
  1318. #endif /* KRB4 */
  1319. static struct keytab krbver[] = {
  1320.     "4",                 4, 0,
  1321.     "5",                 5, 0,
  1322.     "iv",                4, CM_INV,
  1323.     "v",                 5, CM_INV
  1324. };
  1325. static int nkrbver = sizeof(krbver)/sizeof(struct keytab);
  1326.  
  1327. static struct keytab kdestab[] = {
  1328.     "never",            KRB_DEL_NO, 0,
  1329.     "no",               KRB_DEL_NO, CM_INV,
  1330.     "on-close",         KRB_DEL_CL, 0,
  1331.     "on-exit",          KRB_DEL_EX, 0
  1332. };
  1333. static int nkdestab = sizeof(kdestab)/sizeof(struct keytab);
  1334.  
  1335. static struct keytab k4tab[] = {
  1336.     "autodel",           XYKRBDEL, CM_INV,
  1337.     "autodestroy",       XYKRBDEL, 0,
  1338.     "autoget",           XYKRBGET, 0,
  1339.     "check-address",     XYKRBADR, 0,
  1340.     "debug",             XYKRBDBG, CM_INV,
  1341.     "instance",          XYKRBINS, 0,
  1342.     "keytab",            XYKRBKTB, 0,
  1343.     "lifetime",          XYKRBLIF, 0,
  1344.     "preauth",           XYKRBPRE, 0,
  1345.     "principal",         XYKRBPR,  0,
  1346.     "prompt",            XYKRBPRM, 0,
  1347.     "realm",             XYKRBRL,  0,
  1348.     "service-name",      XYKRBSRV, 0
  1349. };
  1350. static int nk4tab = sizeof(k4tab)/sizeof(struct keytab);
  1351.  
  1352. static struct keytab k5tab[] = {
  1353.     "addresses",         XYKRBADD, 0,
  1354.     "autodelete",        XYKRBDEL, CM_INV,
  1355.     "autodestroy",       XYKRBDEL, 0,
  1356.     "autoget",           XYKRBGET, 0,
  1357.     "cc",                XYKRBCC,  CM_INV,
  1358.     "check-address",     XYKRBADR, 0,
  1359.     "credentials-cache", XYKRBCC,  0,
  1360.     "forwardable",       XYKRBFWD, 0,
  1361.     "get-k4-tgt",        XYKRBK5K4,0,
  1362.     "instance",          XYKRBINS, 0,
  1363.     "keytab",            XYKRBKTB, 0,
  1364.     "lifetime",          XYKRBLIF, 0,
  1365.     "no-addresses",      XYKRBNAD, 0,
  1366.     "principal",         XYKRBPR,  0,
  1367.     "prompt",            XYKRBPRM, 0,
  1368.     "proxiable",         XYKRBPRX, 0,
  1369.     "realm",             XYKRBRL,  0,
  1370.     "renewable",         XYKRBRNW, 0,
  1371.     "service-name",      XYKRBSRV, 0
  1372. };
  1373. static int nk5tab = sizeof(k5tab)/sizeof(struct keytab);
  1374.  
  1375. #define KRB_PW_PRM 1
  1376. #define KRB_PR_PRM 2
  1377.  
  1378. static struct keytab krbprmtab[] = {
  1379.     "password",  KRB_PW_PRM, 0,
  1380.     "principal", KRB_PR_PRM, 0
  1381. };
  1382.  
  1383. #endif /* CK_KERBEROS */
  1384. #ifdef CK_SRP
  1385. static struct keytab srptab[] = {
  1386.     "prompt",            XYSRPPRM, 0
  1387. };
  1388. static int nsrptab = sizeof(srptab)/sizeof(struct keytab);
  1389. #define SRP_PW_PRM 1
  1390.  
  1391. static struct keytab srpprmtab[] = {
  1392.     "password",  SRP_PW_PRM, 0
  1393. };
  1394. #endif /* CK_SRP */
  1395. #ifdef CK_SSL
  1396. static struct keytab ssltab[] = {
  1397.     "certs-ok",          XYSSLCOK,  CM_INV,
  1398.     "cipher-list",       XYSSLCL,   0,
  1399.     "crl-dir",           XYSSLCRLD, 0,
  1400.     "crl-file",          XYSSLCRL,  0,
  1401.     "debug",             XYSSLDBG,  0,
  1402.     "dh-key-file",       XYSSLDKFL, CM_INV,
  1403.     "dh-param-file",     XYSSLDPFL, 0,
  1404.     "dsa-cert-chain-file", XYSSLDCCF, 0,
  1405.     "dsa-cert-file",     XYSSLDCFL, 0,
  1406.     "dsa-key-file",      XYSSLDKFL, 0,
  1407.     "dummy",             XYSSLDUM,  CM_INV,
  1408.     "only",              XYSSLON,   CM_INV,
  1409.     "random-file",       XYSSLRND,  0,
  1410.     "rsa-cert-chain-file", XYSSLRCCF, 0,
  1411.     "rsa-cert-file",     XYSSLRCFL, 0,
  1412.     "rsa-key-file",      XYSSLRKFL, 0,
  1413.     "verbose",           XYSSLVRB,  0,
  1414.     "verify",            XYSSLVRF,  0,
  1415.     "verify-dir",        XYSSLVRFD, 0,
  1416.     "verify-file",       XYSSLVRFF, 0
  1417. };
  1418. static int nssltab = sizeof(ssltab)/sizeof(struct keytab);
  1419. static struct keytab sslvertab[] = {
  1420.     "fail-if-no-peer-cert", SSL_VERIFY_PEER |
  1421.                             SSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0,
  1422.     "no",               SSL_VERIFY_NONE, 0,
  1423.     "none",             SSL_VERIFY_NONE, CM_INV,
  1424.     "off",              SSL_VERIFY_NONE, CM_INV,
  1425.     "on",               SSL_VERIFY_PEER, CM_INV,
  1426.     "peer-cert",        SSL_VERIFY_PEER, 0
  1427. };
  1428. static int nsslvertab = sizeof(sslvertab)/sizeof(struct keytab);
  1429. #endif /* CK_SSL */
  1430. #endif /* CK_AUTHENTICATION */
  1431. #ifdef CK_ENCRYPTION
  1432. int cx_type = CX_AUTO;
  1433. extern int sl_cx_type;
  1434. #endif /* CK_ENCRYPTION */
  1435. extern char *tcp_address;
  1436. #ifndef NOHTTP
  1437. extern char *tcp_http_proxy;
  1438. #endif /* NOHTTP */
  1439. #ifdef NT
  1440. #ifdef CK_SOCKS
  1441. extern char *tcp_socks_svr;
  1442. #ifdef CK_SOCKS_NS
  1443. extern char *tcp_socks_ns;
  1444. #endif /* CK_SOCKS_NS */
  1445. #endif /* CK_SOCKS */
  1446. #endif /* NT */
  1447.  
  1448. static struct keytab tnnegtab[] = {    /* TELNET NEGOTIATION table */
  1449.     "accepted",  TN_NG_AC, 0,
  1450.     "refused",   TN_NG_RF, 0,
  1451.     "req",       TN_NG_RQ, CM_INV|CM_ABR,
  1452.     "requ",      TN_NG_RQ, CM_INV|CM_ABR,
  1453.     "reque",     TN_NG_RQ, CM_INV|CM_ABR,
  1454.     "reques",    TN_NG_RQ, CM_INV|CM_ABR,
  1455.     "request",   TN_NG_RQ, CM_INV|CM_ABR,
  1456.     "requeste",  TN_NG_RQ, CM_INV|CM_ABR,
  1457.     "requested", TN_NG_RQ, 0,
  1458.     "required",  TN_NG_MU, 0
  1459. };
  1460. static int ntnnegtab = sizeof(tnnegtab)/sizeof(struct keytab);
  1461.  
  1462. #ifdef CK_ENCRYPTION
  1463. static struct keytab typkwd[] = {
  1464.     "/type", 0, CM_ARG
  1465. };
  1466.  
  1467. static struct keytab tnenctab[] = {    /* TELNET ENCRYPTION table */
  1468.     "accepted",   TN_NG_AC,    CM_INV,
  1469.     "refused",    TN_NG_RF,    CM_INV,
  1470.     "req",        TN_NG_RQ,    CM_INV|CM_ABR,
  1471.     "requ",       TN_NG_RQ,    CM_INV|CM_ABR,
  1472.     "reque",      TN_NG_RQ,    CM_INV|CM_ABR,
  1473.     "reques",     TN_NG_RQ,    CM_INV|CM_ABR,
  1474.     "request",    TN_NG_RQ,    CM_INV|CM_ABR,
  1475.     "requeste",   TN_NG_RQ,    CM_INV|CM_ABR,
  1476.     "requested",  TN_NG_RQ,    CM_INV,
  1477.     "required",   TN_NG_MU,    CM_INV,
  1478.     "start",      TN_EN_START, CM_INV,
  1479.     "stop",       TN_EN_STOP,  CM_INV,
  1480.     "type",       TN_EN_TYP,   0
  1481. };
  1482. static int ntnenc = sizeof(tnenctab)/sizeof(struct keytab) ;
  1483. #endif /* CK_ENCRYPTION */
  1484.  
  1485. #ifdef CK_FORWARD_X
  1486. static struct keytab tnfwdxtab[] = {    /* TELNET FORWARD-X table */
  1487.     "xauthority-file",  0,  0
  1488. };
  1489. static int ntnfwdx = sizeof(tnfwdxtab)/sizeof(struct keytab) ;
  1490. #endif /* CK_FORWARD_X */
  1491.  
  1492. static struct keytab tnbugtab[] = {    /* TELNET BUG table */
  1493.     "binary-me-means-u-too", 0, 0,
  1494.     "binary-u-means-me-too", 1, 0,
  1495.     "infinite-loop-check",   2, 0,
  1496.     "sb-implies-will-do",    3, 0
  1497. };
  1498.  
  1499. #ifdef CK_ENVIRONMENT
  1500. static struct keytab tnenvtab[] = {    /* TELNET ENVIRONMENT table */
  1501.     "acct",    TN_ENV_ACCT,    0,
  1502.     "display",    TN_ENV_DISP,    0,
  1503.     "job",    TN_ENV_JOB,    0,
  1504.     "location", TN_ENV_LOC,     0,
  1505.     "off",      TN_ENV_OFF,     CM_INV,
  1506.     "on",       TN_ENV_ON,      CM_INV,
  1507.     "printer",    TN_ENV_PRNT,    0,
  1508.     "systemtype",TN_ENV_SYS,    0,
  1509.     "user",     TN_ENV_USR,     0,
  1510.     "uservar",    TN_ENV_UVAR,    0,
  1511.     "", 0, 0
  1512. };
  1513. static int ntnenv = sizeof(tnenvtab)/sizeof(struct keytab) - 1;
  1514. #endif /* CK_ENVIRONMENT */
  1515.  
  1516. #ifdef CK_AUTHENTICATION
  1517. static struct keytab tnauthtab[] = {    /* TELNET AUTHENTICATION table */
  1518.     "accepted",   TN_NG_AC,  CM_INV,
  1519.     "encrypt-flag", TN_AU_ENC, 0,
  1520.     "forwarding", TN_AU_FWD,   0,
  1521.     "how-flag",   TN_AU_HOW,   0,
  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.     "type",       TN_AU_TYP, 0
  1532. };
  1533. static int ntnauth = sizeof(tnauthtab)/sizeof(struct keytab) ;
  1534.  
  1535. struct keytab autyptab[] = {    /* TELNET AUTHENTICATION TYPE table */
  1536.     "automatic",  AUTH_AUTO, 0,
  1537. #ifdef CK_KERBEROS
  1538.     "k4",         AUTH_KRB4, CM_INV,
  1539.     "k5",         AUTH_KRB5, CM_INV,
  1540.     "kerberos4",  AUTH_KRB4, 0,
  1541.     "kerberos5",  AUTH_KRB5, 0,
  1542.     "kerberos_iv",AUTH_KRB4, CM_INV,
  1543.     "kerberos_v", AUTH_KRB5, CM_INV,
  1544.     "krb4",       AUTH_KRB4, CM_INV,
  1545.     "krb5",       AUTH_KRB5, CM_INV,
  1546. #endif /* CK_KERBEROS */
  1547.     "none",       AUTH_NONE, 0,
  1548. #ifdef NT
  1549.     "ntlm",       AUTH_NTLM, 0,
  1550. #endif /* NT */
  1551. #ifdef CK_SRP
  1552.     "srp",        AUTH_SRP,  0,
  1553. #endif /* CK_SRP */
  1554. #ifdef CK_SSL
  1555.     "ssl",        AUTH_SSL,  0,
  1556. #endif /* CK_SSL */
  1557.     "", 0, 0
  1558. };
  1559. int nautyp = sizeof(autyptab)/sizeof(struct keytab) - 1;
  1560.  
  1561. struct keytab auhowtab[] = {    /* TELNET AUTHENTICATION HOW table */
  1562.     "any",     TN_AUTH_HOW_ANY,     0,
  1563.     "mutual",  TN_AUTH_HOW_MUTUAL,  0,
  1564.     "one-way", TN_AUTH_HOW_ONE_WAY, 0,
  1565.     "", 0, 0
  1566. };
  1567. int nauhow = sizeof(auhowtab)/sizeof(struct keytab) - 1;
  1568.  
  1569. struct keytab auenctab[] = {    /* TELNET AUTHENTICATION ENCRYPT table */
  1570.     "any",     TN_AUTH_ENC_ANY,     0,
  1571.     "none",    TN_AUTH_ENC_NONE,    0,
  1572.     "telopt",  TN_AUTH_ENC_TELOPT,  0,
  1573. #ifdef CK_SSL
  1574.     "tls",     TN_AUTH_ENC_TLS,     0,
  1575. #endif /* CK_SSL */
  1576.     "", 0, 0
  1577. };
  1578. int nauenc = sizeof(auenctab)/sizeof(struct keytab) - 1;
  1579. #endif /* CK_AUTHENTICATION */
  1580.  
  1581. #define TN_NL_BIN 3
  1582. #define TN_NL_NVT 4
  1583. static struct keytab tn_nlmtab[] = {    /* TELNET NEWLINE-MODE table */
  1584.     "binary-mode", TN_NL_BIN, 0,    /* Binary mode */
  1585.     "nvt",    TN_NL_NVT, 0,        /* NVT mode */
  1586.     "off",    TNL_CRNUL, CM_INV,    /* CR-NUL (TELNET spec) */
  1587.     "on",     TNL_CRLF,  CM_INV,    /* CR-LF (TELNET spec) */
  1588.     "raw",    TNL_CR,    CM_INV        /* CR only (out of spec) */
  1589. };
  1590. static int ntn_nlm = (sizeof(tn_nlmtab) / sizeof(struct keytab));
  1591.  
  1592. static struct keytab tnlmtab[] = {    /* TELNET NEWLINE-MODE table */
  1593.     "cr",     TNL_CR,    CM_INV,    /* CR only (out of spec) */
  1594.     "cr-lf",  TNL_CRLF,  CM_INV,    /* CR-LF (TELNET spec) */
  1595.     "cr-nul", TNL_CRNUL, CM_INV,    /* CR-NUL (TELNET spec) */
  1596.     "lf",     TNL_LF,    CM_INV,    /* LF instead of CR-LF */
  1597.     "off",    TNL_CRNUL, 0,        /* CR-NUL (TELNET spec) */
  1598.     "on",     TNL_CRLF,  0,        /* CR-LF (TELNET spec) */
  1599.     "raw",    TNL_CR,    0        /* CR only (out of spec) */
  1600. };
  1601. static int ntnlm = (sizeof(tnlmtab) / sizeof(struct keytab));
  1602.  
  1603. struct keytab tntab[] = {
  1604. #ifdef CK_AUTHENTICATION
  1605.     "authentication",       CK_TN_AU,  0,
  1606. #endif /* CK_AUTHENTICATION */
  1607.     "b",                    CK_TN_BM,  CM_INV|CM_ABR,
  1608.     "bi",                   CK_TN_BM,  CM_INV|CM_ABR,
  1609.     "bin",                  CK_TN_BM,  CM_INV|CM_ABR,
  1610.     "bina",                 CK_TN_BM,  CM_INV|CM_ABR,
  1611.     "binar",                CK_TN_BM,  CM_INV|CM_ABR,
  1612.     "binary",               CK_TN_BM,  CM_INV|CM_ABR,
  1613.     "binary-",              CK_TN_BM,  CM_INV|CM_ABR,
  1614.     "binary-mode",          CK_TN_BM,  CM_INV,
  1615.     "binary-transfer-mode", CK_TN_XF,  0,
  1616.     "binary-xfer-mode",     CK_TN_XF,  CM_INV,
  1617.     "bug",                  CK_TN_BUG, 0,
  1618.     "debug",                CK_TN_DB,  0,
  1619.     "delay-sb",             CK_TN_DL,  0,
  1620.     "echo",                 CK_TN_EC,  0,
  1621. #ifdef CK_ENCRYPTION
  1622.     "encryption",      CK_TN_ENC,  0,
  1623. #endif /* CK_ENCRYPTION */
  1624. #ifdef CK_ENVIRONMENT
  1625.     "environment",     CK_TN_ENV,  0,
  1626. #endif /* CK_ENVIRONMENT */
  1627. #ifdef CK_FORWARD_X
  1628.     "forward-x",       CK_TN_FX,   0,
  1629. #endif /* CK_FORWARD_X */
  1630. #ifdef IKS_OPTION
  1631.     "kermit",          CK_TN_IKS,  CM_INV,
  1632. #endif /* IKS_OPTION */
  1633. #ifdef CK_SNDLOC
  1634.     "location",        CK_TN_LOC,  0,
  1635. #endif /* CK_SNDLOC */
  1636. #ifdef CK_NAWS
  1637.     "naws",            CK_TN_NAWS, CM_INV,
  1638. #endif /* CK_NAWS */
  1639.     "newline-mode",    CK_TN_NL,   0,
  1640.     "no-encrypt-during-xfer", CK_TN_NE, CM_INV,
  1641.     "prompt-for-userid",CK_TN_PUID,0,
  1642.     "remote-echo",     CK_TN_RE,   0,
  1643. #ifdef CK_SSL
  1644.     "start-tls",       CK_TN_TLS,  CM_INV,
  1645. #endif /* CK_SSL */
  1646. #ifdef NT
  1647.     "sfu-compatibility", CK_TN_SFU, 0,
  1648. #else
  1649.     "sfu-compatibility", CK_TN_SFU, CM_INV,
  1650. #endif /* NT */
  1651.     "terminal-type",   CK_TN_TT,   0,
  1652.     "wait-for-negotiations", CK_TN_WAIT, 0,
  1653. #ifdef CK_ENVIRONMENT
  1654.     "xdisplay-location",CK_TN_XD, CM_INV,
  1655. #endif /* CK_ENVIRONMENT */
  1656.     "", 0, 0
  1657. };
  1658. int ntn = (sizeof(tntab) / sizeof(struct keytab)) - 1;
  1659.  
  1660. struct keytab tnopttab[] = {
  1661. #ifdef CK_AUTHENTICATION
  1662.     "authentication",  CK_TN_AU,   0,
  1663. #else
  1664.     "authentication",  CK_TN_AU,   CM_INV,
  1665. #endif /* CK_AUTHENTICATION */
  1666.     "binary-mode",     CK_TN_BM,   0,
  1667. #ifdef TN_COMPORT
  1668.     "c",               CK_TN_CPC,   CM_INV|CM_ABR,
  1669.     "co",              CK_TN_CPC,   CM_INV|CM_ABR,
  1670.     "com",             CK_TN_CPC,   CM_INV|CM_ABR,
  1671.     "com-port-control",CK_TN_CPC,   0,
  1672.     "comport-control", CK_TN_CPC,   CM_INV,
  1673. #else /* TN_COMPORT */
  1674.     "com-port-control",CK_TN_CPC,  CM_INV,
  1675.     "comport-control", CK_TN_CPC,   CM_INV,
  1676. #endif /* TN_COMPORT */
  1677.     "echo",            CK_TN_EC,   0,
  1678. #ifdef CK_ENCRYPTION
  1679.     "encryption",      CK_TN_ENC,  0,
  1680. #else
  1681.     "encryption",      CK_TN_ENC,  CM_INV,
  1682. #endif /* CK_ENCRYPTION */
  1683. #ifdef CK_FORWARD_X
  1684.     "forward-x",       CK_TN_FX,   0,
  1685. #else /* CK_FORWARD_X */
  1686.     "forward-x",       CK_TN_FX,   CM_INV,
  1687. #endif /* CK_FORWARD_X */
  1688.     "ibm-sak",         CK_TN_SAK,  CM_INV,
  1689. #ifdef IKS_OPTION
  1690.     "kermit",          CK_TN_IKS,  0,
  1691. #else
  1692.     "kermit",          CK_TN_IKS,  CM_INV,
  1693. #endif /* IKS_OPTION */
  1694.     "lflow",           CK_TN_FLW,  CM_INV,
  1695.     "logout",          CK_TN_LOG,  0,
  1696. #ifdef CK_NAWS
  1697.     "naws",            CK_TN_NAWS, 0,
  1698. #else
  1699.     "naws",            CK_TN_NAWS, CM_INV,
  1700. #endif /* CK_NAWS */
  1701. #ifdef CK_ENVIRONMENT
  1702.     "new-environment", CK_TN_ENV,  0,
  1703. #else
  1704.     "new-environment", CK_TN_ENV,  CM_INV,
  1705. #endif /* CK_ENVIRONMENT */
  1706.     "pragma-heartbeat",CK_TN_PHR,  CM_INV,
  1707.     "pragma-logon",    CK_TN_PLG,  CM_INV,
  1708.     "pragma-sspi",     CK_TN_PSP,  CM_INV,
  1709.     "sak",             CK_TN_SAK,  CM_INV,
  1710. #ifdef CK_SNDLOC
  1711.     "send-location",   CK_TN_LOC,  0,
  1712. #else
  1713.     "send-location",   CK_TN_LOC,  CM_INV,
  1714. #endif /* CK_SNDLOC */
  1715.     "sga",             CK_TN_SGA, CM_INV|CM_ABR,
  1716. #ifdef CK_SSL
  1717.     "start-tls",       CK_TN_TLS,  0,
  1718. #else
  1719.     "start-tls",       CK_TN_TLS,  CM_INV,
  1720. #endif /* CK_SSL */
  1721.     "suppress-go-aheads", CK_TN_SGA, 0,
  1722.     "terminal-type",   CK_TN_TT,   0,
  1723.     "ttype",           CK_TN_TT,   CM_INV|CM_ABR,
  1724. #ifdef CK_ENVIRONMENT
  1725.     "xdisplay-location", CK_TN_XD, 0,
  1726. #else
  1727.     "xdisplay-location", CK_TN_XD, CM_INV,
  1728. #endif /* CK_ENVIRONMENT */
  1729.     "", 0, 0
  1730. };
  1731. int ntnopt = (sizeof(tnopttab) / sizeof(struct keytab)) - 1;
  1732.  
  1733. struct keytab tnoptsw[] = {
  1734.     "/client",  CK_TN_CLIENT,   0,
  1735.     "/server",  CK_TN_SERVER,   0
  1736. };
  1737. int ntnoptsw = (sizeof(tnoptsw) / sizeof(struct keytab));
  1738. #endif /* TNCODE */
  1739.  
  1740. struct keytab ftrtab[] = {        /* Feature table */
  1741. #ifndef NOCSETS                /* 0 = we have it, 1 = we don't */
  1742. "character-sets",    0, 0,
  1743. #else
  1744. "character-sets",    1, 0,
  1745. #endif /* NOCSETS */
  1746. #ifndef NOCYRIL
  1747. "cyrillic",        0, 0,
  1748. #else
  1749. "cyrillic",        1, 0,
  1750. #endif /* NOCYRIL */
  1751.  
  1752. #ifndef NOLOGDIAL
  1753. "cx-log",               0, 0,
  1754. #else
  1755. "cx-log",               1, 0,
  1756. #endif /* NOLOGDIAL */
  1757.  
  1758. #ifndef NODEBUG
  1759. "debug",        0, 0,
  1760. #else
  1761. "debug",        1, 0,
  1762. #endif /* NODEBUG */
  1763.  
  1764. #ifndef NODIAL
  1765. "dial",            0, 0,
  1766. #else
  1767. "dial",            1, 0,
  1768. #endif /* NODIAL */
  1769.  
  1770. #ifdef DYNAMIC
  1771. "dynamic-memory",       0, 0,
  1772. #else
  1773. "dynamic-memory",       1, 0,
  1774. #endif /* DYNAMIC */
  1775.  
  1776. #ifndef NOXFER
  1777. "file-transfer",        0, 0,
  1778. #else
  1779. "file-transfer",        1, 0,
  1780. #endif /* NOXFER */
  1781.  
  1782. #ifdef XXFWD
  1783. "forward",              0, 0,
  1784. #else
  1785. "forward",              1, 0,
  1786. #endif /* XXFWD */
  1787.  
  1788. #ifdef NEWFTP
  1789. "ftp",                  0, 0,
  1790. #else
  1791. "ftp",                  1, 0,
  1792. #endif /* NEWFTP */
  1793.  
  1794. #ifdef CK_CURSES
  1795. "fullscreen-display",    0, 0,
  1796. #else
  1797. "fullscreen-display",    1, 0,
  1798. #endif /* CK_CURSES */
  1799. #ifdef GREEK
  1800. "greek",                0, 0,
  1801. #else
  1802. "greek",                1, 0,
  1803. #endif /* GREEK */
  1804. #ifdef HEBREW
  1805. "hebrew",               0, 0,
  1806. #else
  1807. "hebrew",               1, 0,
  1808. #endif /* HEBREW */
  1809. #ifndef NOHELP
  1810. "help",            0, 0,
  1811. #else
  1812. "help",            1, 0,
  1813. #endif /* NOHELP */
  1814.  
  1815. #ifndef NOIKSD
  1816. "iksd",                 0, 0,
  1817. #else
  1818. "iksd",                 1, 0,
  1819. #endif /* NOIKSD */
  1820.  
  1821. #ifndef NOSPL
  1822. "if-command",        0, 0,
  1823. #else
  1824. "if-command",        1, 0,
  1825. #endif /* NOSPL */
  1826. #ifndef NOJC
  1827. #ifdef UNIX
  1828. "job-control",        0, 0,
  1829. #else
  1830. "job-control",        1, 0,
  1831. #endif /* UNIX */
  1832. #else
  1833. "job-control",        1, 0,
  1834. #endif /* NOJC */
  1835. #ifdef KANJI
  1836. "kanji",        0, 0,
  1837. #else
  1838. "kanji",        1, 0,
  1839. #endif /* KANJI */
  1840.  
  1841. #ifndef NOXFER
  1842. "kermit",               0, 0,
  1843. #else
  1844. "kermit",               1, 0,
  1845. #endif /* NOXFER */
  1846.  
  1847. #ifdef CK_KERBEROS
  1848. "kerberos",        0, 0,
  1849. #else
  1850. "kerberos",        1, 0,
  1851. #endif /* CK_KERBEROS */
  1852.  
  1853. #ifndef NOCSETS
  1854. "latin1",        0, 0,
  1855. #else
  1856. "latin1",        1, 0,
  1857. #endif /* NOCSETS */
  1858. #ifdef LATIN2
  1859. "latin2",        0, 0,
  1860. #else
  1861. "latin2",        1, 0,
  1862. #endif /* LATIN2 */
  1863.  
  1864. #ifdef CKLEARN
  1865. "learned-scripts",       0, 0,
  1866. #else
  1867. "learned-scripts",       1, 0,
  1868. #endif /* CKLEARN */
  1869.  
  1870. #ifndef NOLOCAL
  1871. "making-connections",   0, 0,
  1872. #else
  1873. "making-connections",   1, 0,
  1874. #endif /* NOLOCAL */
  1875.  
  1876. #ifdef NETCONN
  1877. "network",        0, 0,
  1878. #else
  1879. "network",        1, 0,
  1880. #endif /* NETCONN */
  1881.  
  1882. #ifdef NT
  1883. #ifdef CK_AUTHENTICATION
  1884. "ntlm",                 1, 0,
  1885. #else /* CK_AUTHENTICATION */
  1886. "ntlm",                 0, 0,
  1887. #endif /* CK_AUTHENTICATION */
  1888. #else /* NT */
  1889. "ntlm",                 0, 0,
  1890. #endif /* NT */
  1891.  
  1892. #ifdef PIPESEND
  1893. "pipes",                0, 0,
  1894. #else
  1895. #ifdef NETCMD
  1896. "pipes",                0, 0,
  1897. #endif /* NETCMD */
  1898. #endif /* PIPESEND */
  1899. #ifndef PIPESEND
  1900. #ifndef NETCMD
  1901. "pipes",                1, 0,
  1902. #endif /* PIPESEND */
  1903. #endif /* NETCMD */
  1904.  
  1905. #ifdef NETPTY
  1906. "pty",                  0, 0,
  1907. #else
  1908. "pty",                  1, 0,
  1909. #endif /* NETPTY */
  1910.  
  1911. #ifndef NOPUSH
  1912. "push",            0, 0,
  1913. #else
  1914. "push",            1, 0,
  1915. #endif /* PUSH */
  1916.  
  1917. #ifdef CK_REDIR
  1918. "redirect",             0, 0,
  1919. #else
  1920. "redirect",             1, 0,
  1921. #endif /* CK_REDIR */
  1922.  
  1923. #ifdef CK_RTSCTS
  1924. "rts/cts",        0, 0,
  1925. #else
  1926. "rts/cts",        1, 0,
  1927. #endif /* RTS/CTS */
  1928.  
  1929. #ifndef NOSCRIPT
  1930. "script-command",    0, 0,
  1931. #else
  1932. "script-command",    1, 0,
  1933. #endif /* NOSCRIPT */
  1934. #ifndef NOSERVER
  1935. "server-mode",        0, 0,
  1936. #else
  1937. "server-mode",        1, 0,
  1938. #endif /* NOSERVER */
  1939.  
  1940. #ifndef NOSEXP
  1941. "sexpression",        0, 0,
  1942. #else
  1943. "sexpression",        1, 0,
  1944. #endif /* NOSEXP */
  1945.  
  1946. #ifndef NOSHOW
  1947. "show-command",        0, 0,
  1948. #else
  1949. "show-command",        1, 0,
  1950. #endif /* NOSHOW */
  1951.  
  1952. #ifdef CK_SRP
  1953. "srp",                0, 0,
  1954. #else
  1955. "srp",                1, 0,
  1956. #endif /* CK_SRP */
  1957.  
  1958. #ifdef CK_SSL
  1959. "ssl/tls",        0, 0,
  1960. #else
  1961. "ssl/tls",        1, 0,
  1962. #endif /* CK_SSL */
  1963.  
  1964. #ifndef NOXMIT
  1965. "transmit",        0, 0,
  1966. #else
  1967. "transmit",        1, 0,
  1968. #endif /* NOXMIT */
  1969.  
  1970. #ifdef UNICODE
  1971. "unicode",              0, 0,
  1972. #else
  1973. "unicode",              1, 0,
  1974. #endif /* UNICODE */
  1975.  
  1976. #ifdef CK_XYZ
  1977. "xyzmodem",        0, 0,
  1978. #else
  1979. "xyzmodem",        1, 0,
  1980. #endif /* NOXMIT */
  1981.  
  1982. "", 0, 0
  1983. };
  1984. int nftr = (sizeof(ftrtab) / sizeof(struct keytab)) - 1;
  1985.  
  1986. struct keytab desttab[] = {        /* SET DESTINATION */
  1987. #ifdef CALIBRATE
  1988.     "calibrate", DEST_N, CM_INV,
  1989. #endif /* CALIBRATE */
  1990.     "disk",    DEST_D, 0,
  1991. #ifdef CALIBRATE
  1992.     "nowhere", DEST_N, 0,
  1993. #endif /* CALIBRATE */
  1994.     "printer", DEST_P, 0,
  1995.     "screen",  DEST_S, 0
  1996. };
  1997. int ndests =  (sizeof(desttab) / sizeof(struct keytab));
  1998.  
  1999. #ifndef NOSPL        /* Used only with script programming items... */
  2000.  
  2001. #ifndef NOSERVER            /* This is just to avoid some */
  2002. #define CK_PARSDIR            /* "statement not reached" */
  2003. #else                    /* complaints... */
  2004. #ifndef NODIAL
  2005. #define CK_PARSDIR
  2006. #endif /* NODIAL */
  2007. #endif /* NOSERVER */
  2008.  
  2009. /*
  2010.   cx == 0 means dial directory
  2011.   cx == 1 means network directory
  2012.   cx == 2 means a directory path list
  2013. */
  2014. static int
  2015. parsdir(cx) int cx; {
  2016.     int i, x, y, dd;            /* Workers */
  2017.     int nxdir;
  2018.     char *s;
  2019.     char ** xdir;
  2020.     char *pp[MAXGETPATH];        /* Temporary name pointers */
  2021. #ifdef ZFNQFP
  2022.     struct zfnfp * fnp;
  2023. #ifdef OS2
  2024.     char * env;
  2025.     char dirpath[4096];
  2026. #else /* OS2 */
  2027.     char dirpath[1024];            /* For fully qualified filenames */
  2028. #endif /* OS2 */
  2029. #endif /* ZFNQFP */
  2030.  
  2031.     int max = 0;            /* Maximum number of things to parse */
  2032.     char c;
  2033.  
  2034. #ifndef NODIAL
  2035.     if (cx == 0) {            /* Dialing */
  2036.     nxdir = ndialdir;
  2037.     xdir = dialdir;
  2038.     max = MAXDDIR;
  2039.     } else
  2040. #ifdef NETCONN
  2041.     if (cx == 1) {            /* Network */
  2042.     nxdir = nnetdir;
  2043.     xdir = netdir;
  2044.     max = MAXDDIR;
  2045.     } else
  2046. #endif /* NETCONN */
  2047. #endif /* NODIAL */
  2048. #ifndef NOSERVER
  2049.     if (cx == 2) {            /* GET path */
  2050.     nxdir = ngetpath;
  2051.     xdir = getpath;
  2052.     max = MAXGETPATH;
  2053.     } else                /* Called with invalid function code */
  2054. #endif /* NOSERVER */
  2055.       return(-2);
  2056.  
  2057.     for (i = 0; i < MAXGETPATH; i++)    /* Init these. */
  2058.       pp[i] = NULL;
  2059.  
  2060. #ifdef CK_PARSDIR
  2061.     dd = 0;                /* Temporary name counter */
  2062.     while (1) {
  2063.     if (cx != 2) {            /* Dialing or Network Directory */
  2064. #ifdef OS2
  2065.         int len;
  2066. #ifdef NT
  2067.         env = getenv("K95PHONES");
  2068. #else /* NT */
  2069.         env = getenv("K2PHONES");
  2070. #endif /* NT */
  2071.         if (!env)
  2072.           env = getenv("K95PHONES");
  2073.             if (!env)
  2074.           env = "";
  2075.  
  2076.             dirpath[0] = '\0';
  2077.             len = strlen(env) + 2*strlen(startupdir) + 2*strlen(inidir)
  2078.                 + 2*strlen(zhome()) + 2*strlen(exedir) + 4*strlen("PHONES/")
  2079.                 + 12;
  2080.             if (len < 4096)        /* SAFE */
  2081.           sprintf(dirpath,"%s%s%s;%s%s;%s;%s%s;%s;%s%s",
  2082.             /* Semicolon-separated path list */
  2083.             env,
  2084.             (env[0] && env[strlen(env)-1] == ';') ? "" : ";",
  2085.             startupdir,
  2086.             startupdir, "PHONES/",
  2087.             inidir,
  2088.             inidir, "PHONES/",
  2089.                     zhome(),
  2090.                     zhome(), "PHONES/",
  2091.             exedir,
  2092.             exedir, "PHONES/"
  2093.             );
  2094. #else
  2095. #ifdef UNIX
  2096.         y = 1024;
  2097.         s = dirpath;
  2098.         zzstring("\\v(home)",&s,&y);
  2099. #endif /* UNIX */
  2100. #endif /* OS2 */
  2101.         y = cmifip(
  2102.           "Names of one or more directory files, separated by spaces",
  2103.                "",&s,&x,0,
  2104. #ifdef OS2ORUNIX
  2105.                dirpath,
  2106. #else
  2107.                NULL,
  2108. #endif /* OS2ORUNIX */
  2109.                xxstring
  2110.                );
  2111.     } else {            /* List of directory names */
  2112.         x = 0;
  2113.         y = cmdir("Directory name","",&s,xxstring);
  2114.     }
  2115.     if (y < 0) {
  2116.         if (y == -3) {        /* EOL or user typed <CR> */
  2117.         if ((y = cmcfm()) < 0) return(y);
  2118.         for (i = 0; i < max; i++) { /* Clear these */
  2119.             if (i < nxdir && xdir[i]) {
  2120.             free(xdir[i]);
  2121.             }
  2122.             xdir[i] = (i < dd) ? pp[i] : NULL;
  2123.         }
  2124. #ifndef NODIAL
  2125.         if (cx == 0)
  2126.           ndialdir = dd;
  2127. #ifdef NETCONN
  2128.         if (cx == 1)
  2129.           nnetdir = dd;
  2130. #endif /* NETCONN */
  2131. #endif /* NODIAL */
  2132. #ifndef NOSERVER
  2133.         if (cx == 2)
  2134.           ngetpath = dd;
  2135. #endif /* NOSERVER */
  2136.         return(success = 1);
  2137.  
  2138.         } else {            /* Parse error */
  2139.         for (i = 0; i < dd; i++) {  /* Free temp storage */
  2140.             if (pp[i]) free(pp[i]); /* but don't change */
  2141.             pp[i] = NULL;           /* anything else */
  2142.         }
  2143.         return(y);
  2144.         }
  2145.     }
  2146.     if (x) {
  2147.         printf("?Wildcards not allowed\n");
  2148.         return(-9);
  2149.     }
  2150. #ifdef CK_TMPDIR
  2151.     if (cx == 2 && !isdir(s)) {
  2152.         printf("?Not a directory - %s\n", s);
  2153.         return(-9);
  2154.     }
  2155. #endif /* CK_TMPDIR */
  2156.  
  2157. #ifdef ZFNQFP
  2158.         if (cx < 2) {
  2159.         if (!isabsolute(s)) {    /* If not relative get full path */
  2160.         if ((fnp = zfnqfp(s,TMPBUFSIZ - 1,tmpbuf))) {
  2161.             if (fnp->fpath)
  2162.               if ((int) strlen(fnp->fpath) > 0)
  2163.             s = fnp->fpath;
  2164.         }
  2165.         }
  2166.     }
  2167. #endif /* ZFNQFP */
  2168.     c = NUL;
  2169.     x = strlen(s);
  2170.     if (x > 0)            /* Get last char */
  2171.       c = s[x-1];
  2172.     debug(F000,"parsdir s",s,c);
  2173.     if ((pp[dd] = malloc(strlen(s)+2)) == NULL) {
  2174.         printf("?Internal error - malloc\n");
  2175.         for (i = 0; i < dd; i++) {  /* Free temp storage */
  2176.         if (pp[i]) free(pp[i]);
  2177.         pp[i] = NULL;
  2178.         }
  2179.         return(-9);
  2180.     } else {            /* Have storage for name */
  2181.         strcpy(pp[dd],s);        /* Copy string into new storage */
  2182.         debug(F111,"parsdir pp[dd] 1",pp[dd],dd);
  2183. #ifndef NOXFER
  2184.         if (cx == 2) {        /* If we are parsing directories */
  2185.         char dirsep[2];
  2186.         extern int myindex;    /* Append directory separator if */
  2187.         extern struct sysdata sysidlist[]; /* it is missing...   */
  2188.         debug(F101,"parsdir myindex","",myindex);
  2189.         if (myindex > -1)
  2190.           if (sysidlist[myindex].sid_unixlike)
  2191.             if (c != sysidlist[myindex].sid_dirsep) {
  2192.             dirsep[0] = sysidlist[myindex].sid_dirsep;
  2193.             dirsep[1] = NUL;
  2194.             strcat(pp[dd], (char *) dirsep); /* safe */
  2195.             }
  2196.         }
  2197. #endif /* NOXFER */
  2198.         debug(F111,"parsdir pp[dd] 2",pp[dd],dd);
  2199.         if (++dd > max) {
  2200.         printf("?Too many directories - %d max\n", max);
  2201.         for (i = 0; i < dd; i++) {  /* Free temp storage */
  2202.             if (pp[i]) free(pp[i]);
  2203.             pp[i] = NULL;
  2204.         }
  2205.         }
  2206.     }
  2207.     }
  2208. #endif /* CK_PARSDIR */
  2209. }
  2210. #endif /* NOSPL */
  2211.  
  2212. #ifndef NOSERVER
  2213. static int
  2214. cklogin() {
  2215.     int x;
  2216.     char * s;
  2217.     char username[LOGINLEN+1];
  2218.     char password[LOGINLEN+1];
  2219.     char account[LOGINLEN+1];
  2220.     extern char * x_user, * x_passwd, * x_acct;
  2221.     extern int x_login, x_logged;
  2222.  
  2223.     username[0] = NUL;
  2224.     password[0] = NUL;
  2225.     account[0]  = NUL;
  2226.  
  2227.     x = cmfld("username", "", &s, xxstring);
  2228.     if (x != -3) {
  2229.     if (x < 0)
  2230.       return(x);
  2231.     if ((int)strlen(s) > LOGINLEN) {
  2232.         printf("\"%s\" - too long, %d max\n", s, LOGINLEN);
  2233.         return(-9);
  2234.     }
  2235.     ckstrncpy(username,s,LOGINLEN+1);
  2236.     x = cmfld("password", "", &s, xxstring);
  2237.     if (x != -3) {
  2238.         if (x < 0)
  2239.           return(x);
  2240.         if ((int)strlen(s) > LOGINLEN) {
  2241.         printf("\"%s\" - too long, %d max\n", s, LOGINLEN);
  2242.         return(-9);
  2243.         }
  2244.         ckstrncpy(password,s,LOGINLEN+1);
  2245.         x = cmfld("account", "", &s, xxstring);
  2246.         if (x != -3) {
  2247.         if (x < 0)
  2248.           return(x);
  2249.         if ((int)strlen(s) > LOGINLEN) {
  2250.             printf("\"%s\" - too long, %d max\n", s, LOGINLEN);
  2251.             return(-9);
  2252.         }
  2253.         ckstrncpy(account,s,LOGINLEN+1);
  2254.         if ((x = cmcfm()) < 0)
  2255.           return(x);
  2256.         }
  2257.     }
  2258.     }
  2259.     makestr(&x_user,username);
  2260.     makestr(&x_passwd,password);
  2261.     makestr(&x_acct,account);
  2262.     x_login = (x_user) ? 1 : 0;
  2263.     x_logged = 0;
  2264.     return(1);
  2265. }
  2266. #endif /* NOSERVER */
  2267.  
  2268. #ifndef NOLOCAL
  2269. static int
  2270. setdcd() {
  2271.     int x, y, z = 0;
  2272.     if ((y = cmkey(crrtab,ncrr,"","auto",xxstring)) < 0) return(y);
  2273.     if (y == CAR_ON) {
  2274.     x = cmnum("Carrier wait timeout, seconds","0",10,&z,xxstring);
  2275.     if (x < 0) return(x);
  2276.     }
  2277.     if ((x = cmcfm()) < 0) return(x);
  2278.     carrier = ttscarr(y);
  2279.     cdtimo = z;
  2280.     return(1);
  2281. }
  2282. #endif /* NOLOCAL */
  2283.  
  2284. extern struct keytab yesno[];
  2285. extern int nyesno;
  2286.  
  2287. /* g e t y e s n o  */
  2288.  
  2289. static struct keytab q0yesno[] = {    /* Yes/No/Quit keyword table */
  2290.     "no",    0, 0,
  2291.     "ok",    1, 0,
  2292.     "yes",   1, 0
  2293. };
  2294. static int nq0yesno = (sizeof(q0yesno) / sizeof(struct keytab));
  2295.  
  2296. static struct keytab q1yesno[] = {    /* Yes/No/Quit keyword table */
  2297.     "no",    0, 0,
  2298.     "ok",    1, 0,
  2299.     "quit",  2, 0,
  2300.     "yes",   1, 0
  2301. };
  2302. static int nq1yesno = (sizeof(q1yesno) / sizeof(struct keytab));
  2303.  
  2304. static struct keytab q2yesno[] = {    /* Yes/No/Quit keyword table */
  2305.     "go",    3, 0,
  2306.     "no",    0, 0,
  2307.     "ok",    1, 0,
  2308.     "yes",   1, 0
  2309. };
  2310. static int nq2yesno = (sizeof(q2yesno) / sizeof(struct keytab));
  2311.  
  2312. static struct keytab q3yesno[] = {    /* Yes/No/Quit keyword table */
  2313.     "go",    3, 0,
  2314.     "no",    0, 0,
  2315.     "ok",    1, 0,
  2316.     "quit",  2, 0,
  2317.     "yes",   1, 0
  2318. };
  2319. static int nq3yesno = (sizeof(q3yesno) / sizeof(struct keytab));
  2320.  
  2321.  
  2322. /* Ask question, get yes/no answer */
  2323.  
  2324. int
  2325. getyesno(msg, flags) char * msg; int flags; {
  2326. #ifdef CK_RECALL
  2327.     extern int on_recall;        /* around Password prompting */
  2328. #endif /* CK_RECALL */
  2329.     int y, z;
  2330.  
  2331. #ifndef NOLOCAL
  2332. #ifdef OS2
  2333.     extern int vmode;
  2334.     int vmode_sav = vmode;
  2335. #endif /* OS2 */
  2336. #endif /* NOLOCAL */
  2337.  
  2338. #ifdef CK_APC
  2339.     if ( apcactive != APC_INACTIVE && (apcstatus & APC_NOINP) ) {
  2340.         return(success = 0);
  2341.     }
  2342. #endif /* CK_APC */
  2343.  
  2344. #ifndef NOLOCAL
  2345. #ifdef OS2
  2346. #ifdef COMMENT
  2347.     if (win95_popup
  2348. #ifdef IKSD
  2349.     && !inserver
  2350. #endif /* IKSD */
  2351.     )
  2352.       return(popup_readyesno(vmode,prmpt,flags));
  2353. #endif /* COMMENT */
  2354.     if (vmode == VTERM) {
  2355.         vmode = VCMD;
  2356.         VscrnIsDirty(VTERM);
  2357.         VscrnIsDirty(VCMD);
  2358.     }
  2359. #endif /* OS2 */
  2360. #endif /* NOLOCAL */
  2361. #ifdef VMS
  2362. /*
  2363.   In VMS, whenever a TAKE file or macro is active, we restore the
  2364.   original console modes so Ctrl-C/Ctrl-Y can work.  But here we
  2365.   go interactive again, so we have to temporarily put them back.
  2366. */
  2367.     if (!xcmdsrc)
  2368.       concb((char)escape);
  2369. #endif /* VMS */
  2370.  
  2371. #ifdef CK_RECALL
  2372.     on_recall = 0;
  2373. #endif /* CK_RECALL */
  2374.     cmsavp(psave,PROMPTL);        /* Save old prompt */
  2375.     cmsetp(msg);            /* Make new prompt */
  2376.     z = 0;                /* Initialize answer to No. */
  2377.     cmini(ckxech);            /* Initialize parser. */
  2378.     do {
  2379.     prompt(NULL);            /* Issue prompt. */
  2380.     switch (flags) {
  2381.       case 0:  y = cmkey(q0yesno,nq0yesno,"","",NULL); break;
  2382.       case 1:  y = cmkey(q1yesno,nq1yesno,"","",NULL); break;
  2383.       case 2:  y = cmkey(q2yesno,nq2yesno,"","",NULL); break;
  2384.       default: y = cmkey(q3yesno,nq3yesno,"","",NULL);
  2385.     }
  2386.     if (y < 0) {
  2387.         if (y == -4) {        /* EOF */
  2388.         z = y;
  2389.         break;
  2390.         } else if (y == -3)        /* No answer? */
  2391.           printf(" Please respond; type '?' to see valid answers.\n");
  2392.         cmini(ckxech);
  2393.     } else {
  2394.         z = y;            /* Save answer */
  2395.         y = cmcfm();        /* Get confirmation */
  2396.     }
  2397.     } while (y < 0);            /* Continue till done */
  2398.     cmsetp(psave);            /* Restore real prompt */
  2399. #ifdef VMS
  2400.     if (cmdlvl > 0)            /* In VMS and not at top level, */
  2401.       conres();                /*  restore console again. */
  2402. #endif /* VMS */
  2403. #ifndef NOLOCAL
  2404. #ifdef OS2
  2405.     if (vmode != vmode_sav) {
  2406.         vmode = VTERM;
  2407.         VscrnIsDirty(VCMD);
  2408.         VscrnIsDirty(VTERM);
  2409.     }
  2410. #endif /* OS2 */
  2411. #endif /* NOLOCAL */
  2412.     return(z);
  2413. }
  2414.  
  2415. #ifdef CK_PERMS
  2416. #ifdef UNIX
  2417.  
  2418. _PROTOTYP( int zsetperm, (char *, int));
  2419.  
  2420. /* CHMOD command for UNIX only */
  2421.  
  2422. #define CHM_DIR 0
  2423. #define CHM_DOT 1
  2424. #define CHM_FIL 2
  2425. #define CHM_LIS 3
  2426. #define CHM_NOL 4
  2427. #define CHM_QUI 5
  2428. #define CHM_REC 6
  2429. #define CHM_VRB 7
  2430. #define CHM_PAG 8
  2431. #define CHM_NOP 9
  2432. #define CHM_TYP 10
  2433. #define CHM_SIM 11
  2434.  
  2435. static struct keytab uchmodsw[] = {
  2436.     "/directories", CHM_DIR, 0,
  2437.     "/dotfiles",    CHM_DOT, 0,
  2438.     "/files",       CHM_FIL, 0,
  2439.     "/list",        CHM_LIS, 0,
  2440.     "/nolist",      CHM_NOL, 0,
  2441.     "/nopage",      CHM_NOP, 0,
  2442.     "/page",        CHM_PAG, 0,
  2443.     "/quiet",       CHM_QUI, CM_INV,
  2444.     "/recursive",   CHM_REC, 0,
  2445.     "/simulate",    CHM_SIM, 0,
  2446.     "/type",        CHM_TYP, CM_ARG,
  2447.     "/verbose",     CHM_VRB, CM_INV,
  2448. };
  2449. static int nchmodsw = (sizeof(uchmodsw) / sizeof(struct keytab));
  2450.  
  2451. int
  2452. douchmod() {
  2453.     extern int matchdot, recursive, nscanfile, diractive;
  2454. #ifdef CK_TTGWSIZ
  2455.     extern int tt_rows, tt_cols;
  2456.     int n = 0;
  2457. #endif /* CK_TTGWSIZ */
  2458.     int i, files = 1, t1 = 1, t2 = 0, x, y, z, verbose = 0, rc = 1, paging;
  2459.     int xmode = -1, fs = 0, getval = 0, simulate = 0, wild = 0;
  2460.     char c, * s;
  2461.     struct FDB sw, nu;
  2462.  
  2463.     if (xaskmore < 0) {
  2464. #ifdef CK_TTGWSIZ
  2465.     xaskmore = 1;
  2466. #else
  2467.     xaskmore = 0;
  2468. #endif /* CK_TTGWSIZ */
  2469.     }
  2470.     paging = xaskmore;
  2471.  
  2472.     cmfdbi(&sw,                /* First FDB - command switches */
  2473.        _CMKEY,            /* fcode */
  2474.        "Octal file permission code, or switch",
  2475.        "",                /* default */
  2476.        "",                /* addtl string data */
  2477.        nchmodsw,            /* addtl numeric data 1: tbl size */
  2478.        4,                /* addtl numeric data 2: 4 = cmswi */
  2479.        xxstring,            /* Processing function */
  2480.        uchmodsw,            /* Keyword table */
  2481.        &nu                /* Pointer to next FDB */
  2482.        );
  2483.     cmfdbi(&nu,
  2484.        _CMNUM,            /* Number */
  2485.        "",                /* Help message */
  2486.        "",                /* Default */
  2487.        "",                /* N/A */
  2488.        8,                /* Radix = 8 */
  2489.        0,                /* N/A */
  2490.        xxstring,            /* Processing function */
  2491.        NULL,            /* N/A */
  2492.        NULL                /* Next */
  2493.        );
  2494.  
  2495.     while (1) {
  2496.     if ((x = cmfdb(&sw)) < 0) {
  2497.         if (x == -3) {
  2498.         x = -9;
  2499.         printf("?Filename required\n");
  2500.         }
  2501.         return(x);
  2502.     }
  2503.     if (cmresult.fcode != _CMKEY)
  2504.       break;
  2505.     c = cmgbrk();
  2506.     getval = (c == ':' || c == '=');
  2507.     if (getval && !(cmgkwflgs() & CM_ARG)) {
  2508.         printf("?This switch does not take an argument\n");
  2509.         return(-9);
  2510.     }
  2511.     if (!getval && (cmgkwflgs() & CM_ARG)) {
  2512.         printf("?This switch requires an argument\n");
  2513.         return(-9);
  2514.     }
  2515.     switch (cmresult.nresult) {
  2516.       case CHM_DIR:
  2517.         t1 = 1;
  2518.         t2 = 1;
  2519.         break;
  2520.       case CHM_DOT:
  2521.         matchdot = 1;
  2522.         break;
  2523.       case CHM_FIL:
  2524.         t1 = 0;
  2525.         t2 = 0;
  2526.         break;
  2527.       case CHM_LIS:
  2528.       case CHM_VRB:
  2529.         verbose = 1;
  2530.         break;
  2531.       case CHM_NOL:
  2532.       case CHM_QUI:
  2533.         verbose = 0;
  2534.         break;
  2535.       case CHM_REC:
  2536.         recursive = 1;
  2537.         break;
  2538.       case CHM_PAG:
  2539.         verbose = 1;
  2540.         paging = 1;
  2541.         break;
  2542.       case CHM_NOP:
  2543.         paging = 0;
  2544.         break;
  2545.       case CHM_SIM:
  2546.         simulate = 1;
  2547.         break;
  2548.       case CHM_TYP: {
  2549.           extern struct keytab txtbin[];
  2550.           if ((x = cmkey(txtbin,3,"","",xxstring)) < 0)
  2551.         return(x);
  2552.           if (x == 2) {        /* ALL */
  2553.           xmode = -1;
  2554.           } else {            /* TEXT or BINARY only */
  2555.           xmode = x;
  2556.           fs = 1;
  2557.           }
  2558.           break;
  2559.       }
  2560.     }
  2561.     }
  2562.     z = cmresult.nresult;
  2563.     x = cmifi2("File specification","",&s,&wild,t1,NULL,xxstring,t2);
  2564.     if (x < 0) {
  2565.     if (x == -3) {
  2566.         printf("?A file specification is required\n");
  2567.         return(-9);
  2568.     } else
  2569.       return(x);
  2570.     }
  2571.     ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  2572.     s = tmpbuf;
  2573.     if ((x = cmcfm()) < 0)
  2574.       return(x);
  2575. #ifdef ZXREWIND
  2576.     if (wild) files = zxrewind();
  2577. #else
  2578.     if (wild) files = nzxpand(s,0);
  2579. #endif /* ZXREWIND */
  2580.  
  2581.     if (paging > -1)
  2582.       xaskmore = paging;
  2583.  
  2584. #ifdef CK_TTGWSIZ
  2585.     if (verbose && paging) {
  2586. #ifdef OS2
  2587.     ttgcwsz();
  2588. #else /* OS2 */
  2589.     if (ttgwsiz() > 0) {
  2590.         if (tt_rows > 0 && tt_cols > 0) {
  2591.         cmd_rows = tt_rows;
  2592.         cmd_cols = tt_cols;
  2593.         }
  2594.     }
  2595. #endif /* OS2 */
  2596.     }
  2597. #endif /* CK_TTGWSIZ */
  2598.  
  2599.     for (i = 0; i < files; i++) {
  2600.     if (files == 1 && wild == 0) {    /* For "chmod 777 ." */
  2601.         ckstrncpy(line,s,LINBUFSIZ);
  2602.     } else {
  2603.         x = znext(line);
  2604.         if (x < 1) {
  2605.         if (i == 0) {
  2606.             printf("?No files match - \"%s\"\n",line);
  2607.             return(-9);
  2608.         }
  2609.         return(1);
  2610.         }
  2611.     }
  2612.     if (fs) {
  2613. #ifdef VMSORUNIX
  2614.         /* If /TYPE:TEXT or BINARY given, skip directories and links */
  2615.         /* since they are neither text nor binary. */
  2616.         extern int zgfs_dir, zgfs_link;
  2617.         zgetfs(line);
  2618.         if (zgfs_dir || zgfs_link)
  2619.           continue;
  2620. #else
  2621.         if (zchki(line) < 0)
  2622.           continue;
  2623. #endif /* VMSORUNIX */
  2624.         /* Regular file, scan it */
  2625.         switch (scanfile(line,&y,nscanfile)) {
  2626.           case FT_BIN:
  2627.         if (xmode != 1)
  2628.           continue;
  2629.         break;
  2630.           case FT_TEXT:
  2631.           case FT_7BIT:
  2632.           case FT_8BIT:
  2633. #ifdef UNICODE
  2634.           case FT_UTF8:
  2635.           case FT_UCS2:
  2636. #endif /* UNICODE */
  2637.         if (xmode != 0)
  2638.           continue;
  2639.         }
  2640.     }
  2641.     if (simulate) {
  2642. #ifdef UNIX
  2643.         extern int zchkod;        /* Unidentified Flying */
  2644.         int xx = zchkod;        /* API Extension... */
  2645.         zchkod = 1;
  2646. #endif /* UNIX */
  2647.         if (zchko(line) < 0)
  2648.           printf("%s - Access denied\n",line);
  2649.         else
  2650.           printf("%s - OK\n",line);
  2651. #ifdef UNIX
  2652.         zchkod = xx;
  2653. #endif /* UNIX */
  2654.     } else {
  2655.         if (zsetperm(line,z) < 1) {
  2656.         if (verbose || files < 2) {
  2657.             printf("%s: %s\n",line,ck_errstr());
  2658.         }
  2659.         rc = 0;
  2660.         } else if (verbose) {
  2661.         printf("%s  %s\n",ziperm(line),line);
  2662.         }
  2663.     }
  2664. #ifdef CK_TTGWSIZ
  2665.     if (verbose && paging) {    /* Pause at end of screen */
  2666.         if (cmd_rows > 0 && cmd_cols > 0) {
  2667.         if (++n > cmd_rows - 3) {
  2668.             if (!askmore())
  2669.               break;
  2670.             else
  2671.               n = 0;
  2672.         }
  2673.         }
  2674.     }
  2675. #endif /* CK_TTGWSIZ */
  2676.  
  2677.     }
  2678.     return(success = rc);
  2679. }
  2680. #endif /* UNIX */
  2681. #endif /* CK_PERMS */
  2682.  
  2683. #ifndef NOSPL                /* S-Expressions */
  2684. #ifndef NOSEXP
  2685.  
  2686. struct keytab sexptab[] = {
  2687.     "depth-limit", 1, 0,
  2688.     "echo-result", 0, 0
  2689. };
  2690.  
  2691. static int sexpmaxdep = 1000;        /* Maximum depth */
  2692.  
  2693. #define xxfloat(s,x) \
  2694. ((isdigit(*s)||(*s=='-')||(*s=='+')||(*s=='.')||(*s=='\040'))?isfloat(s,x):0)
  2695.  
  2696. #define SX_ADD  1            /* Symbols for built-in operators */
  2697. #define SX_SUB  2
  2698. #define SX_MUL  3
  2699. #define SX_DIV  4
  2700. #define SX_POW  5
  2701. #define SX_SET  6
  2702. #define SX_MOD  7
  2703. #define SX_EVA  8
  2704. #define SX_EXP  9
  2705. #define SX_AEQ 10
  2706. #define SX_ALT 11
  2707. #define SX_AGT 12
  2708. #define SX_ALE 13
  2709. #define SX_AGE 14
  2710. #define SX_MIN 15
  2711. #define SX_MAX 16
  2712. #define SX_SQR 17
  2713. #define SX_FLR 18
  2714. #define SX_CEI 19
  2715. #define SX_TRU 20
  2716. #define SX_ABS 21
  2717. #define SX_ROU 22
  2718. #define SX_LET 23
  2719. #define SX_LGN 24
  2720. #define SX_LGX 25
  2721. #define SX_FLO 26
  2722. #define SX_IFC 27
  2723. #define SX_NOT 28
  2724. #define SX_NEQ 29
  2725. #define SX_AND 30
  2726. #define SX_LOR 31
  2727. #define SX_SIN 32
  2728. #define SX_COS 33
  2729. #define SX_TAN 34
  2730. #define SX_BWA 35
  2731. #define SX_BWO 36
  2732. #define SX_BWX 37
  2733. #define SX_BWN 38
  2734. #define SX_XOR 39
  2735. #define SX_INC 40
  2736. #define SX_DEC 41
  2737. #define SX_QUO 42
  2738. #define SX_STR 43
  2739.  
  2740. /* Operator flags */
  2741.  
  2742. #define SXF_PRE 256            /* Predicate */
  2743. #define SXF_ONE 512            /* Requires one arg */
  2744. #define SXF_TWO 1024            /* Requires two args or more */
  2745. #define SXF_FLO 2048            /* Coerce to floating-point */
  2746.  
  2747. /* Built-in constants */
  2748.  
  2749. #define SXC_NIL 1            /* NIL */
  2750. #define SXC_PI  2            /* PI */
  2751. #define SXC_T   3            /* T */
  2752.  
  2753. /*
  2754.   This is an xlookup() table and so need not be in "alhabetical" order.
  2755.   Therefore entries are arranged to minimize search for most common
  2756.   operators.
  2757. */
  2758. static struct keytab sexpops[] = {    /* Built-in operators */
  2759.     "setq",    SX_SET, 0,        /* Global assignment */
  2760.     "+",       SX_ADD, 0,        /* Simple arithmetic */
  2761.     "-",       SX_SUB, 0,
  2762.     "*",       SX_MUL, 0,
  2763.     "/",       SX_DIV, SXF_TWO,
  2764.     "^",       SX_POW, SXF_TWO,
  2765.  
  2766.     "if",      SX_IFC, SXF_TWO,        /* IF */
  2767.     "let",     SX_LET, 0,        /* Local assignment */
  2768.     "not",     SX_NOT, SXF_ONE,        /* NOT */
  2769.     "mod",     SX_MOD, SXF_TWO,        /* Modulus */
  2770.  
  2771.     "<",       SX_ALT, SXF_PRE|SXF_TWO,    /* Comparisons */
  2772.     ">",       SX_AGT, SXF_PRE|SXF_TWO,
  2773.     "<=",      SX_ALE, SXF_PRE|SXF_TWO,
  2774.     "=",       SX_AEQ, SXF_PRE|SXF_TWO,
  2775.     ">=",      SX_AGE, SXF_PRE|SXF_TWO,
  2776.     "!=",      SX_NEQ, SXF_PRE|SXF_TWO,
  2777.  
  2778.     "++",      SX_INC, SXF_ONE|SXF_TWO,    /* Increment */
  2779.     "--",      SX_DEC, SXF_ONE|SXF_TWO,    /* Decrement */
  2780.  
  2781.     "**",      SX_POW, SXF_TWO,        /* Common synonyms */
  2782.     "==",      SX_AEQ, SXF_PRE|SXF_TWO,
  2783.     "!",       SX_NOT, SXF_ONE,
  2784.     ".",       SX_EVA, 0,
  2785.  
  2786.     "and",     SX_AND, 0,        /* Logical operators */
  2787.     "or",      SX_LOR, 0,
  2788.     "xor",     SX_XOR, SXF_TWO,
  2789.  
  2790.     "max",     SX_MAX, SXF_ONE|SXF_TWO,    /* Max and min */
  2791.     "min",     SX_MIN, SXF_ONE|SXF_TWO,
  2792.  
  2793.     "%",       SX_MOD, SXF_TWO,        /* More synonyms */
  2794.     "||",      SX_LOR, 0,
  2795.     "&&",      SX_AND, 0,
  2796.  
  2797.     "quote",   SX_QUO, SXF_ONE,
  2798.     "string",  SX_STR, SXF_ONE,
  2799.  
  2800.     "eval",    SX_EVA, 0,        /* Assorted commands */
  2801.     "abs",     SX_ABS, SXF_ONE,
  2802.     "truncate",SX_TRU, SXF_ONE|SXF_FLO,
  2803.     "round",   SX_ROU, SXF_ONE|SXF_FLO,
  2804.     "ceiling", SX_CEI, SXF_ONE|SXF_FLO,
  2805.     "floor",   SX_FLR, SXF_ONE|SXF_FLO,
  2806.     "float",   SX_FLO, SXF_ONE|SXF_FLO,
  2807.  
  2808. #ifdef FNFLOAT
  2809.     "sqrt",    SX_SQR, SXF_ONE|SXF_FLO,    /* Floating point functions */
  2810.     "exp",     SX_EXP, SXF_ONE|SXF_FLO,
  2811.     "sin",     SX_SIN, SXF_ONE|SXF_FLO,
  2812.     "cos",     SX_COS, SXF_ONE|SXF_FLO,
  2813.     "tan",     SX_TAN, SXF_ONE|SXF_FLO,
  2814.     "log",     SX_LGN, SXF_ONE|SXF_FLO,
  2815.     "log10",   SX_LGX, SXF_ONE|SXF_FLO,
  2816. #endif /* FNFLOAT */
  2817.  
  2818.     "#",       SX_BWX, SXF_TWO,        /* Bitwise operators */
  2819.     "&",       SX_BWA, 0,
  2820.     "|",       SX_BWO, 0,
  2821.     "~",       SX_BWN, SXF_ONE,
  2822.     "", 0, 0                /* (end) */
  2823. };
  2824. static int nsexpops = (sizeof(sexpops) / sizeof(struct keytab)) - 1;
  2825.  
  2826. static struct keytab sexpconsts[] = {    /* Built-in constants */
  2827.     "nil", SXC_NIL, 0,            /* NIL (false) */
  2828.     "pi",  SXC_PI,  0,            /* Pi (3.1415926...) */
  2829.     "t",   SXC_T,   0,            /* T (true) */
  2830.     "", 0, 0
  2831. };
  2832. static int nsexpconsts = (sizeof(sexpconsts) / sizeof(struct keytab)) - 1;
  2833.  
  2834. int sexprc = 0;                /* S-Expression error flag */
  2835. int sexppv = -1;            /* Predicate value */
  2836.  
  2837. #define SXMLEN 64            /* Macro arg list initial length */
  2838. #include <math.h>                       /* Floating-point functions */
  2839.  
  2840. _PROTOTYP( char * fpformat, (CKFLOAT, int, int) );
  2841.  
  2842. extern char math_pi[];            /* Value of Pi */
  2843. extern int sexpecho;            /* SET SEXPRESSION ECHO value */
  2844. extern char * sexpval;            /* Last top-level S-Expression value */
  2845. extern char * lastsexp;            /* Last S-Expression */
  2846. int sexprmax = 0;            /* Longest result (for stats) */
  2847. int sexpdmax = 0;            /* Max depth reached (for stats) */
  2848. int sexpdep  = 0;            /* dosexp() recursion depth */
  2849. static int * sxrlen = NULL;        /* Result stack string sizes */
  2850. static char ** sxresult = NULL;        /* Result stack */
  2851.  
  2852. /*  s h o s e x p  --  Show S-Expression info  */
  2853.  
  2854. VOID
  2855. shosexp() {
  2856.     printf("\n");
  2857.     printf(" sexpression echo-result: %s\n",showooa(sexpecho));
  2858.     printf(" sexpression depth-limit: %d\n",sexpmaxdep);
  2859.     printf("\n");
  2860.     printf(" maximum depth reached:   %d\n",sexpdmax);
  2861.     printf(" longest result returned: %d\n",sexprmax);
  2862.     printf("\n");
  2863.     printf(" last sexpression:        %s\n",lastsexp ? lastsexp : "(none)");
  2864.     printf(" last value:              %s\n",sexpval ? sexpval : "(none)");
  2865.     printf("\n");
  2866. }
  2867.  
  2868.  
  2869. static char *
  2870. sexpdebug(s) char * s; {
  2871.     /* For debugging -- includes recursion depth in each debug entry */
  2872.     static char buf[64];
  2873.     ckmakmsg(buf,64,"dosexp[",ckitoa(sexpdep),"] ",s);
  2874.     return((char *)buf);
  2875. }
  2876.  
  2877. /*  d o s e x p  --  S-Expression Reader  */
  2878.  
  2879. /*  Returns value as string (empty, numeric, or non-numeric) */
  2880.  
  2881. char *
  2882. dosexp(s) char *s; {            /* s = S-Expression */
  2883.     extern struct mtab *mactab;        /* Macro table */
  2884.     extern int maclvl, nmac;
  2885.     extern char *mrval[];
  2886.     extern int makestrlen;        /* (see makestr()) */
  2887.     struct stringarray * q = NULL;    /* cksplit() return type */
  2888.     char * p[SEXPMAX+1], ** p2;        /* List items (must be on stack) */
  2889.     char * line = NULL;            /* For building macro argument list */
  2890.     int linelen = 0;
  2891.     int linepos = 0;
  2892.     int quote = 0;            /* LISP quote flag */
  2893.     char * s2;                /* Workers */
  2894.     int i, j, k, n = 0, x = 0, kw, kwflags, mx = 0;
  2895.     int result = 0, not = 0, truncate = 0, builtin = 0;
  2896.     int fpflag = 0, quit = 0, macro = 0;
  2897.     extern CKFLOAT floatval;        /* (see isfloat()) */
  2898.     CKFLOAT fpj, fpresult = 0.0;    /* Floating-point results */
  2899.     int pflag = 0;            /* Have predicate */
  2900.     int presult = 0;            /* Predicate result */
  2901.     int mustfree = 0;            /* If we malloc'd we must free */
  2902.  
  2903.     sexppv = -1;            /* Predicate value */
  2904.     s2 = "";                /* Default return value */
  2905.  
  2906.     if (++sexpdep > sexpmaxdep) {    /* Keep track of depth */
  2907.         printf("?S-Expression depth limit exceeded: %d\n",sexpmaxdep);
  2908.         sexprc++;
  2909.     debug(F111,sexpdebug("max depth exceeded"),s,sexprc);
  2910.     }
  2911.     if (sexpdep > sexpdmax)        /* For stats */
  2912.       sexpdmax = sexpdep;
  2913.  
  2914.     if (sexprc)                /* Error, quit all levels */
  2915.       goto xdosexp;            /* Always goto common exit point */
  2916.  
  2917.     debug(F111,sexpdebug("entry"),s,sexprc);
  2918.  
  2919.     if (!s) s = "";            /* Null or empty arg */
  2920.  
  2921.     while (*s == SP) s++;        /* Strip leading spaces */
  2922.     if (!*s)                /* so empty result */
  2923.       goto xdosexp;
  2924.  
  2925. /*
  2926.   Allocate result stack upon first use, or after it has been resized with
  2927.   SET SEXP DEPTH-LIMIT.
  2928. */
  2929.     if (!sxresult) {
  2930.     sxresult = (char **)malloc(sexpmaxdep * sizeof(char *));
  2931.     if (!sxresult) {
  2932.         printf("?Memory allocation failure - \"%s\"\n", s);
  2933.         sexprc++;
  2934.         goto xdosexp;
  2935.     }
  2936.     sxrlen = (int *)malloc(sexpmaxdep * sizeof(int));
  2937.     if (!sxrlen) {
  2938.         printf("?Memory allocation failure - \"%s\"\n", s);
  2939.         sexprc++;
  2940.         goto xdosexp;
  2941.     }
  2942.     for (i = 0; i < sexpmaxdep; i++) {
  2943.         sxresult[i] = NULL;        /* Result pointers */
  2944.         sxrlen[i] = 0;        /* Buffer sizes */
  2945.     }
  2946.     }
  2947.     s2 = s;                /* s2 is the result pointer */
  2948.     k = 0;                /* Length accumulator */
  2949.     if (s[0] == '(') {            /* Starts with open paren? */
  2950.     while (*s2++) k++;        /* Get length */
  2951.     if (s[k-1] == ')') {        /* Strip outer parens if any */
  2952.         s[k-1] = NUL;
  2953.         s++;
  2954.         k -= 2;
  2955.         while (*s == SP) {        /* Strip leading spaces from result */
  2956.         s++;
  2957.         k--;
  2958.         }
  2959.         while (k > 0 && s[k-1] == SP) { /* And trailing spaces. */
  2960.         s[k-1] = NUL;
  2961.         k--;
  2962.         }
  2963.     }
  2964.     if (!*s) {            /* If nothing remains */
  2965.         s2 = "";            /* return empty result. */
  2966.         goto xdosexp;
  2967.     }
  2968.     }
  2969.     /* Break result up into "words" (an SEXP counts as a word) */
  2970.  
  2971.     p[0] = NULL;            /* (We don't use element 0) */
  2972.     if (!*(s+1) || !*(s+2)) {        /* No need to call cksplit() */
  2973.     n = 1;                /* if it's one or two chars. */
  2974.     p[1] = s;            /* No need to malloc this either. */
  2975.     debug(F101,sexpdebug("nosplit"),"",n);
  2976.     if (s[0] == '(') {        /* () empty */
  2977.         s2 = "";
  2978.         goto xdosexp;
  2979.     }
  2980.     } else {
  2981.     q = cksplit(1,SEXPMAX,s,NULL,"\\%[]&$+-/=*^_@!{}/<>|.#~'`:;?",8,39,0);
  2982.     if (!q)
  2983.       goto xdosexp;
  2984.     n = q->a_size;            /* Number of items */
  2985.     debug(F101,sexpdebug("split"),"",n);
  2986.     if (n < 0 || n > SEXPMAX) {    /* Check for too many */
  2987.         printf("?Too many operands: max = %d\n",SEXPMAX);
  2988.         sexprc++;
  2989.         goto xdosexp;
  2990.     }
  2991.     if (n == 0)            /* None, result is NULL, done. */
  2992.       goto xdosexp;
  2993.     if (n == 1 && s[0] == '(') {    /* One but it's another SEXP */
  2994.         s2 = dosexp(s);
  2995.         goto xdosexp;
  2996.     }
  2997.     p2 = q->a_head;            /* Point to result array. */
  2998.     for (i = 1; i <= n; i++) {    /* We must copy it because */
  2999.         p[i] = NULL;        /* recursive calls to dosexp() */
  3000.         if (p2[i])            /* write over the same array */
  3001.           makestr(&(p[i]),p2[i]);
  3002.     }
  3003.     if (s[0] == '(') {        /* Operator is an S-Expression */
  3004.         s2 = dosexp(p[1]);        /* Replace it by its value */
  3005.         makestr(&(p[1]),s2);
  3006.     }
  3007.     mustfree++;            /* Remember to free it */
  3008.     }
  3009.     debug(F110,sexpdebug("head"),p[1],0);
  3010.  
  3011.     if (n == 1 && p[1]) {
  3012.     if (*(p[1]) == '\047') {
  3013.         s2 = p[1];
  3014.         goto xdosexp;
  3015.     }
  3016.     }
  3017. /*
  3018.   This section sidesteps xlookup() of the most common operators.
  3019.   It's not necessary but it speeds up SEXP-heavy loops by about 10%.
  3020. */
  3021.     kwflags = 0;
  3022.     if (n > 0) {            /* Look up the operator */
  3023.     s2 = p[1];            /* Prelookup optimization... */
  3024.     if (!s2)
  3025.       s2 = "";
  3026.     if (!*s2)
  3027.       goto xdosexp;
  3028.     kw = 0;
  3029.     x = 0;
  3030.     if (isdigit(*s2)) {        /* Digit */
  3031.         x = -2;
  3032.  
  3033.     } else if (isalpha(*s2) && !*(s2+1)) { /* Single letter */
  3034.         x = -1;
  3035.  
  3036.     } else if (*s2 == 's' || *s2 == 'S') { /* SETQ */
  3037.         s2++;
  3038.         if (*s2 == 'e' || *s2 == 'E') {
  3039.         s2++;
  3040.         if (*s2 == 't' || *s2 == 'T') {
  3041.             s2++;
  3042.             if (*s2 == 'q' || *s2 == 'Q') {
  3043.             if (!*(s2+1)) {
  3044.                 x = SX_SET;
  3045.                 kwflags = 0;
  3046.                 builtin = 1;
  3047.             }
  3048.             }
  3049.         }
  3050.         }
  3051.     }
  3052.     if (!x) {
  3053.         if (!*(s2+1)) {        /* Common single-character ops */
  3054.         if (*s2 == '+') {
  3055.             x = SX_ADD;
  3056.             kwflags = 0;
  3057.             builtin = 1;
  3058.         } else if (*s2 == '-') {
  3059.             x = SX_SUB;
  3060.             kwflags = 0;
  3061.             builtin = 1;
  3062.         } else if (*s2 == '*') {
  3063.             x = SX_MUL;
  3064.             kwflags = 0;
  3065.             builtin = 1;
  3066.         } else if (*s2 == '/') {
  3067.             x = SX_DIV;
  3068.             kwflags = SXF_TWO;
  3069.             builtin = 1;
  3070.         }
  3071.         }
  3072.         if (!x) {            /* None of the above, look it up */
  3073.         x = xlookup(sexpops,p[1],nsexpops,&kw);
  3074.         if (x > 0) {
  3075.             kwflags = sexpops[kw].flgs;
  3076.             builtin = 1;
  3077.         }
  3078.         }
  3079.     }
  3080.     }
  3081.     /* If none of the above, check built-in constants */
  3082.  
  3083.     if (x == -1) {
  3084.     x = xlookup(sexpconsts,p[1],nsexpconsts,&kw);
  3085.     if (x > 0) {
  3086.         switch (x) {
  3087.           case SXC_NIL:
  3088.         s2 = "";
  3089.         goto xdosexp;
  3090.           case SXC_PI:
  3091.         s2 = math_pi;
  3092.         goto xdosexp;
  3093.           case SXC_T:
  3094.         s2 = "1";
  3095.         goto xdosexp;
  3096.         }
  3097.     }
  3098.     }
  3099.     if (n == 1) {            /* Not an expression */
  3100.     if (builtin) {            /* Built-in operand? */
  3101.         switch (x) {        /* Operators with default values */
  3102.           case SX_EVA:
  3103.         s2 = "";
  3104.         goto xdosexp;
  3105.           case SX_MUL:        /* (*) */
  3106.         s2 = sexpval ? sexpval : "1";
  3107.         goto xdosexp;
  3108.           case SX_AND:        /* (AND) */
  3109.           case SX_BWA:        /* Bitwise (&) */
  3110.         result++;
  3111.           case SX_LOR:        /* (OR) */
  3112.           case SX_BWO:        /* Bitwise (|) */
  3113.           case SX_ADD:        /* (+) */
  3114.           case SX_SUB:        /* (-) */
  3115.         s2 = result ? "1" : "0";
  3116.         goto xdosexp;
  3117.         }
  3118.  
  3119.     } else {            /* Not a built-in operand */
  3120.         char * p1;
  3121.         p1 = p[1];
  3122.         while (*p1 == SP) p1++;
  3123.         if (!isalpha(*p1)) {
  3124.         if (xxfloat(p1,0) > 0) { /* Is it a number? */
  3125.             s2 = p1;
  3126.             while (*s2 == '+') s2++;
  3127.         } else if (*p1 == '(') { /* An S-Expression? */
  3128.  
  3129. #ifdef COMMENT
  3130.             s2 = dosexp(s2);
  3131. #else
  3132.             s2 = dosexp(p1);
  3133. #endif /* COMMENT */
  3134.         }
  3135.         goto xdosexp;
  3136.         } else if (x < 1) {        /* Is it a variable? */
  3137.         j = mxlook(mactab,p[1],nmac); /* Look it up */
  3138.         debug(F111,sexpdebug("n==1 mxlook"),p[1],j);
  3139.         s2 = (j > -1) ? mactab[j].mval : "";
  3140.         if (!s2) s2 = "";
  3141.         if (xxfloat(s2,0) > 0)    /* Macro value is a number */
  3142.           goto xdosexp;
  3143.  
  3144.         if (j > -1) {        /* It's a macro */
  3145.             mx = j;
  3146.             x = j;        /* whose definition is not numeric */
  3147.             if (*s2 == '(') {    /* Is it an S-Expression? */
  3148.             /* We have to allocate memory on the stack */
  3149.             /* to call ourselves recursively on it */
  3150.             /* otherwise we'll wipe out the macro definition */
  3151.             char * s3 = NULL;
  3152.             /* int k = 0; */
  3153.             s3 = s2;
  3154.             while (*s3++) k++;
  3155.             s3 = (char *)malloc(k + 4);
  3156.             if (s3) {
  3157.                 strcpy(s3,s2);   /* SAFE */
  3158.                 s2 = dosexp(s3); /* Evaluate it */
  3159.                 free(s3);
  3160.             } else {
  3161.                 printf("?Memory allocation failure - \"%s\"\n",s2);
  3162.                 sexprc++;
  3163.             }
  3164.             goto xdosexp;
  3165.             }
  3166.             if (*s2 == '\047') {
  3167.             s2++;
  3168.             makestr(&p[1],s2);
  3169.             s2 = p[1];
  3170.             if (*s2 == '(') {
  3171.                 if (s2[makestrlen-1] == ')') {
  3172.                 s2[makestrlen-1] = NUL;
  3173.                 s2++;
  3174.                 }
  3175.             }
  3176.             debug(F110,sexpdebug("'A"),s2,0);
  3177.             goto xdosexp;
  3178.             }
  3179.             macro++;        /* Not an S-Expression */
  3180.         } else {        /* Not found in macro table */
  3181.             printf("?Not defined - \"%s\"\n", p[1]);
  3182.             sexprc++;
  3183.             goto xdosexp;
  3184.         }
  3185.         }
  3186.     }
  3187.     } else if (x < 1 && !macro) {    /* n > 1 and not a built-in operator */
  3188.     x = mxlook(mactab,p[1],nmac);    /* See if it's a macro */
  3189.     debug(F111,sexpdebug("n!=1 mxlook"),p[1],x);
  3190.     if (x < 0) {
  3191.         printf("?Invalid operand - \"%s\"\n",p[1]);
  3192.         sexprc++;
  3193.         goto xdosexp;
  3194.     }
  3195.     mx = x;
  3196.     macro++;
  3197.     }
  3198.     if (builtin) {            /* Built-in operator... */
  3199.     if (kwflags) {
  3200.         int flgs;
  3201.         if ((flgs = (kwflags & (SXF_ONE|SXF_TWO)))) {
  3202.         switch (flgs) {
  3203.           case (SXF_ONE|SXF_TWO):
  3204.             if (n < 2) {
  3205.             printf("?Too few operands - \"%s\"\n",s);
  3206.             sexprc++;
  3207.             goto xdosexp;
  3208.             }
  3209.             break;
  3210.           case SXF_TWO:
  3211.             if (n < 3) {
  3212.             printf("?Too few operands - \"%s\"\n",s);
  3213.             sexprc++;
  3214.             goto xdosexp;
  3215.             }
  3216.             break;
  3217.           case SXF_ONE:
  3218.             if (n != 2) {
  3219.             printf("?Too %s operands - \"%s\"\n",
  3220.                    (n > 2) ? "many" : "few", s);
  3221.             sexprc++;
  3222.             goto xdosexp;
  3223.             }
  3224.         }
  3225.         }
  3226.         if (kwflags & SXF_PRE) {    /* Predicate? */
  3227.         pflag = 1;
  3228.         presult = 1;
  3229.         }
  3230.         if (kwflags & SXF_FLO)    /* Operator requires floating point */
  3231.           fpflag++;            /* Force it */
  3232.     }
  3233.     if (x == SX_SET || x == SX_LET || /* Assignment is special */
  3234.         x == SX_INC || x == SX_DEC) {
  3235.         int rc;
  3236.         char c, * m, * s3;
  3237.         if (n == 1) {
  3238.             s2 = "";
  3239.         goto xdosexp;
  3240.         }
  3241.         s2 = NULL;
  3242.         for (i = 1; i < n; i += 2) { /* Loop thru operand pairs */
  3243.         rc = 0;
  3244.         s3 = p[i+1];
  3245.         c = *s3;
  3246.         debug(F110,sexpdebug("target p"),s3,0);
  3247.  
  3248.         /* Make sure target doesn't have multiple words */
  3249.         while (*s3) { if (*s3 < '!') { rc = 1; break; }; s3++; }
  3250.         s3 = p[i+1];
  3251.         if (rc) {        /* If it does it must have been */
  3252.             char * s4;        /* an SEXP so evaluate it */
  3253.             s3 = dosexp(s3);
  3254.             s4 = s3;
  3255.             rc = 0;
  3256.             while (*s4) { if (*s4 < '!') { rc = 1; break; }; s4++; }
  3257.             if (rc == 0) makestr(&(p[i+1]),s3);
  3258.         }
  3259.  
  3260.         /* And that it's not a number, etc. */
  3261.         if (rc > 0 || isdigit(c) || c == '(') {
  3262.             printf("?Invalid assignment - \"%s\"\n",s);
  3263.             sexprc++;
  3264.             goto xdosexp;
  3265.         } else if (isalpha(c)) {
  3266.             rc = xlookup(sexpconsts,s3,nsexpconsts,NULL);
  3267.             if (rc > 0) {
  3268.             printf("?Assignment to constant - \"%s\"\n",s);
  3269.             sexprc++;
  3270.             goto xdosexp;
  3271.             }
  3272.         }
  3273.  
  3274.         /* If ++ or --, get current value of variable */
  3275.         if (x == SX_INC || x == SX_DEC) {
  3276.             int ok = 1;
  3277.             char buf[32];
  3278.             if (c == CMDQ) {    /* A backslash variable */
  3279.             int n = 32;
  3280.             char * s = buf;
  3281.             buf[0] = NUL;
  3282.             if (zzstring(s3,&s,&n) < 0 || !buf[0])
  3283.               ok = 0;
  3284.             s2 = buf;
  3285.             } else {        /* A macro */
  3286.             if ((k = mxlook(mactab,s3,nmac)) < 0)
  3287.               ok = 0;
  3288.             else
  3289.               s2 = mactab[k].mval;
  3290.             }
  3291.             if (!ok) {
  3292.             printf("?Not defined - \"%s\"\n",p[i+1]);
  3293.             sexprc++;
  3294.             goto xdosexp;
  3295.             }
  3296.             if (!s2) s2 = "";
  3297.             k = xxfloat(s2,0);
  3298.             if (k < 1) {
  3299.             printf("?Not numeric - \"%s\"\n",p[i+1]);
  3300.             sexprc++;
  3301.             goto xdosexp;
  3302.             }
  3303.             while (*s2 == '+') s2++;
  3304.             result = atoi(s2);
  3305.             fpresult = floatval;
  3306.             if (k > 1 || fpresult != result)
  3307.               fpflag++;
  3308.         }
  3309.         if (n < i+2) {        /* Variable with no value */
  3310.             s2 = "";
  3311.             if (x == SX_SET || x == SX_LET) {
  3312.             delmac(p[i+1],1); /* Delete the variable */
  3313.             break;
  3314.             } else {
  3315.             s2 = "1";
  3316.             }
  3317.         } else {        /* Variable with value */
  3318.             k = xxfloat(p[i+2],0); /* Is it a number? */
  3319.             if (k > 0) {
  3320.             s2 = p[i+2];
  3321.             while (*s2 == '+') s2++;
  3322.             } else {
  3323.             s2 = dosexp(p[i+2]); /* Have value, evaluate it */
  3324.             if (sexprc) goto xdosexp;
  3325.             if (!s2) s2 = "";
  3326.             if (!*s2 && (x == SX_INC || x == SX_DEC))
  3327.               continue;
  3328.             }
  3329.         }
  3330.         if (x == SX_INC || x == SX_DEC) {
  3331.             k = xxfloat(s2,0);
  3332.             if (k < 1) {
  3333.             printf("?Not numeric - \"%s\"\n",s2);
  3334.             sexprc++;
  3335.             goto xdosexp;
  3336.             }
  3337.             while (*s2 == '+') s2++;
  3338.             j = atoi(s2);
  3339.             if (k > 1) {
  3340.             fpj = floatval;
  3341.             fpflag++;
  3342.             } else {
  3343.             fpj = (CKFLOAT)j;
  3344.             }
  3345.             if (x == SX_INC) {
  3346.             result += j;
  3347.             fpresult += fpj;
  3348.             } else if (x == SX_DEC) {
  3349.             result -= j;
  3350.             fpresult -= fpj;
  3351.             }
  3352.             if (result != fpresult) fpflag++;
  3353.             s2 = fpflag ? fpformat(fpresult,0,0) : ckitoa(result);
  3354.         }
  3355.         if (x == SX_LET && cmdlvl > 0) /* LET makes var local */
  3356.           addlocal(p[i+1]);
  3357.         if ((rc = addmac(p[i+1],s2)) < 0) { /* Add the value */
  3358.             switch (rc) {
  3359.               case -3: m = "Array not declared"; break;
  3360.               case -2: m = "Subscript out of range"; break;
  3361.               case -4: m = "Out of memory"; break;
  3362.               default: m = "Error creating variable";
  3363.             }
  3364.             printf("?%s - \"%s\"\n",m,s);
  3365.             sexprc++;
  3366.             goto xdosexp;
  3367.         }
  3368.         if (s2) result = atoi(s2);
  3369.         }
  3370.         goto xdosexp;
  3371.     } else if (x == SX_IFC) {        /* Conditional expression */
  3372.         int true = 0;
  3373.         if (n > 4) {
  3374.         printf("?Too many operands: IF - \"%s\"\n",s);
  3375.         sexprc++;
  3376.         goto xdosexp;
  3377.         }
  3378.         s2 = dosexp(p[2]);
  3379.         if (sexprc) goto xdosexp;
  3380.         if (s2) {
  3381.         j = atoi(s2);
  3382.         if (xxfloat(s2,0) == 2) {
  3383.             fpflag++;
  3384.             fpresult = (CKFLOAT)result;
  3385.             fpj = floatval;
  3386.         } else {
  3387.             fpj = atof(s2);
  3388.         }
  3389.         true = ((fpj != 0.0) ? 1 : 0);
  3390.         }
  3391.         if (!true && n < 4) {
  3392.         s2 = NULL;
  3393.         } else {
  3394.         s2 = dosexp(true ? p[3] : p[4]);
  3395.         if (sexprc) goto xdosexp;
  3396.         j = s2 ? atoi(s2) : 0;
  3397.         if (xxfloat(s2,0) == 2) {
  3398.             fpflag++;
  3399.             fpresult = (CKFLOAT)result;
  3400.             fpj = floatval;
  3401.         } else {
  3402.             fpj = s2 ? atof(s2) : 0.0;
  3403.         }
  3404.         fpresult = fpj;
  3405.         result = j;
  3406.         }
  3407.         goto xdosexp;
  3408.     } else if (x == SX_QUO) {
  3409. #ifndef COMMENT
  3410.         int xx;
  3411.         xx = strlen(p[2]);
  3412.         p[3] = (char *)malloc(xx+4);
  3413.         s2 = p[3];
  3414.         ckmakmsg(p[3],xx+4,"'(",p[2],")",NULL);
  3415.         n++;
  3416. #else
  3417.         s2 = p[2];
  3418. #endif /* COMMENT */
  3419.         goto xdosexp;
  3420.     } else if (x == SX_STR) {
  3421.         int xx;
  3422.         s2 = dosexp(p[2]);
  3423.         if (sexprc) goto xdosexp;
  3424.         xx = strlen(s2);
  3425.         p[3] = (char *)malloc(xx+4);
  3426.         ckmakmsg(p[3],xx+4,"'(",s2,")",NULL);
  3427.         s2 = p[3];
  3428.         n++;
  3429.         goto xdosexp;
  3430.     }
  3431.     }
  3432.     /* Arithmetic operator or macro - Loop thru operands */
  3433.  
  3434.     quit = 0;                /* Short-circuit flag. */
  3435.     if (macro && n > 1) {        /* If operator is a macro */
  3436.     if (!line) {            /* allocate local buffer for */
  3437.         line = (char *)malloc(SXMLEN); /* the evaluated argument list. */
  3438.         if (!line) {
  3439.         printf("?Memory allocation failure - \"%s\"\n",p[1]);
  3440.         sexprc++;
  3441.         goto xdosexp;
  3442.         }
  3443.         linelen = SXMLEN;
  3444.         /* debug(F101,"dosexp macro arg buffer","",linelen); */
  3445.     }
  3446.     linepos = 0;
  3447.     line[linepos] = NUL;
  3448.     }
  3449.     for (i = 1; ((i < n) && !sexprc && !quit); i++) { /* Loop thru operands */
  3450.     quote = 0;
  3451.     s2 = p[i+1];            /* Get operand */
  3452.     if (!s2) s2 = "";
  3453. #ifdef COMMENT
  3454.     if (*s2 == '\047') {        /* Is it quoted? */
  3455.         debug(F110,sexpdebug("'B"),s2,0);
  3456.         s2++;            /* Space past the quote */
  3457.         quote++;
  3458.         if (*s2 == '(') {        /* Quoted S-Expression? */
  3459.         char c4, * s4 = s2+1;    /* Strip outer parens */
  3460.         while ((c4 = *s4++)) {
  3461.             if (c4 == ')' && !*s4) {
  3462.             s2++;
  3463.             *(s4-1) = NUL;
  3464.             break;
  3465.             }
  3466.         }
  3467.         }
  3468.         debug(F110,sexpdebug("'C"),s2,0);
  3469.  
  3470.     } else {            /* Not quoted */
  3471.         s2 = dosexp(p[i+1]);    /* evaluate it */
  3472.         if (sexprc) goto xdosexp;
  3473.         if (!s2) s2 = "";
  3474.         if (!macro && x == SX_EVA)
  3475.           continue;
  3476.     }
  3477. #else
  3478.     if (*s2 != '\047') {        /* Is it quoted? */
  3479.         s2 = dosexp(p[i+1]);    /* No, evaluate it */
  3480.         if (sexprc) goto xdosexp;
  3481.         if (!s2) s2 = "";
  3482.         if (!macro && x == SX_EVA)
  3483.           continue;
  3484.     }
  3485.     if (*s2 == '\047') {        /* Is result quoted? */
  3486.         debug(F110,sexpdebug("'B"),s2,0);
  3487.         s2++;            /* Space past the quote */
  3488.         quote++;
  3489.         if (*s2 == '(') {        /* Quoted S-Expression? */
  3490.         char c4, * s4 = s2+1;    /* Strip outer parens */
  3491.         while ((c4 = *s4++)) {
  3492.             if (c4 == ')' && !*s4) {
  3493.             s2++;
  3494.             *(s4-1) = NUL;
  3495.             break;
  3496.             }
  3497.         }
  3498.         }
  3499.         debug(F110,sexpdebug("'C"),s2,0);
  3500.     }
  3501. #endif /* COMMENT */
  3502.     if (macro) {
  3503.         debug(F111,sexpdebug("macro arg"),s2,i);
  3504.         if (!*s2) quote++;
  3505.         if (!quote) {
  3506.         register char c4, * s4 = s2;
  3507.         while ((c4 = *s4++)) if (c4 == SP) { quote++; break; }
  3508.         }
  3509.         if (quote) line[linepos++] = '{';
  3510.         while ((line[linepos++] = *s2++)) {
  3511.         if (linepos > linelen - 3) {
  3512.             char * tmp = NULL;
  3513.             line[linepos] = NUL;
  3514.             linelen += SXMLEN;
  3515.             tmp = (char *) malloc(linelen);
  3516.             if (!tmp) {
  3517.             printf("?Memory re-allocation failure - \"%s...\"\n",
  3518.                    line);
  3519.             sexprc++;
  3520.             goto xdosexp;
  3521.             }
  3522.             strcpy(tmp,line);
  3523.             free(line);
  3524.             line = tmp;
  3525.         }
  3526.         }
  3527.         linepos--;            /* Back up over NUL */
  3528.         if (quote)
  3529.           line[linepos++] = '}';    /* End quote group */
  3530.         line[linepos++] = SP;    /* add a space */
  3531.         line[linepos] = NUL;    /* and a NUL */
  3532.         continue;
  3533.     }
  3534.     if (!quote) {            /* Built-in operator... */
  3535.         s2 = dosexp(s2);
  3536.         if (sexprc) goto xdosexp;
  3537.         if (!s2) s2 = "";
  3538.     }
  3539.     if (x == SX_EVA)
  3540.       continue;
  3541.  
  3542.     if (!*s2) {
  3543.         /* An empty value is not a legal number */
  3544.         /* but it is a legal truth value */
  3545.         if (x != SX_AND && x != SX_LOR && x != SX_NOT) {
  3546.         printf("?Not Numeric - \"%s\"\n",p[i+1]);
  3547.         sexprc++;
  3548.         goto xdosexp;
  3549.         }
  3550.         j = 0;
  3551.         fpj = 0.0;
  3552.     } else {
  3553.         j = atoi(s2);
  3554.         /* Switch to floating-point upon encountering any f.p. arg */
  3555.         /* OR... if integer is too big */
  3556.         if (!fpflag) if (xxfloat(s2,0) == 2)
  3557.           fpflag++;
  3558.         fpj = atof(s2);
  3559.     }
  3560.     if (i == 1) {            /* Initial result is first operand */
  3561.         result = (n == 2 && x == SX_SUB) ? 0-j : j;
  3562.         fpresult = (n == 2 && x == SX_SUB) ? -fpj : fpj;
  3563.         if (!(kwflags & SXF_ONE))    /* Command with single arg */
  3564.           continue;
  3565.     }
  3566.     if (x == SX_MOD || x == SX_DIV) {
  3567.         if (!result)
  3568.           fpflag++;
  3569.         if (!fpj) {
  3570.         printf("?Divide by zero - \"%s\"\n",cmdbuf);
  3571.         sexprc++;
  3572.         goto xdosexp;
  3573.         }
  3574.     }
  3575.     switch (x) {            /* Accumulate result */
  3576.  
  3577.       case SX_EVA:            /* EVAL */
  3578.         result = j;
  3579.         fpresult = fpj;
  3580.         break;
  3581.  
  3582.       case SX_ADD:            /* + */
  3583.         result += j;
  3584.         fpresult += fpj;
  3585.         if (result != fpresult)
  3586.           fpflag++;
  3587.         break;
  3588.  
  3589.       case SX_SUB:            /* - */
  3590.         result -= j;
  3591.         fpresult -= fpj;
  3592.         if (result != fpresult)
  3593.           fpflag++;
  3594.         break;
  3595.  
  3596.       case SX_MUL:            /* * */
  3597.         result *= j;
  3598.         fpresult *= fpj;
  3599.         if (result != fpresult)
  3600.           fpflag++;
  3601.         break;
  3602.  
  3603.       case SX_AND:            /* AND */
  3604.         result = result && j;
  3605.         if (!result) quit++;
  3606.         fpresult = fpresult && fpj;
  3607.         break;
  3608.  
  3609.       case SX_LOR:            /* OR */
  3610.         result = result || j;
  3611.         if (!result) quit++;
  3612.         fpresult = fpresult || fpj;
  3613.         break;
  3614.  
  3615.       case SX_MOD:            /* Modulus */
  3616.         result = result % j;
  3617. #ifdef FNFLOAT
  3618.         fpresult = (CKFLOAT)fmod(fpresult,fpj);
  3619.         if (result != fpresult)
  3620.           fpflag++;
  3621. #else
  3622.         fpresult = result;
  3623. #endif /* FNFLOAT */
  3624.         break;
  3625.  
  3626.       case SX_DIV:            /* / */
  3627.         result /= j;
  3628.         fpresult /= fpj;
  3629.         if (result != fpresult)
  3630.           fpflag++;
  3631.         break;
  3632.  
  3633.       case SX_AEQ:            /* Test for equality */
  3634.         if (fpflag) {
  3635.         if (fpresult != fpj)
  3636.           presult = 0;
  3637.         } else {
  3638.         if (result != j)
  3639.           presult = 0;
  3640.         }
  3641.         break;
  3642.  
  3643.       case SX_NEQ:            /* Test for ineqality */
  3644.         if (fpflag) {
  3645.         if (fpresult == fpj)
  3646.           presult = 0;
  3647.         } else {
  3648.         if (result == j)
  3649.           presult = 0;
  3650.         }
  3651.         break;
  3652.  
  3653.       case SX_ALE:            /* Arithmetic less-equal */
  3654.         if (fpflag) {
  3655.         if (fpj < fpresult)
  3656.           presult = 0;
  3657.         fpresult = fpj;
  3658.         } else {
  3659.         if (j < result)
  3660.           presult = 0;
  3661.         result = j;
  3662.         }
  3663.         break;
  3664.  
  3665.       case SX_ALT:            /* Arithmetic less-than */
  3666.         if (fpflag) {
  3667.         if (fpj <= fpresult)
  3668.           presult = 0;
  3669.         fpresult = fpj;
  3670.         } else {
  3671.         if (j <= result)
  3672.           presult = 0;
  3673.         result = j;
  3674.         }
  3675.         break;
  3676.  
  3677.       case SX_AGT:            /* Arithmetic greater-than */
  3678.         if (fpflag) {
  3679.         if (fpj >= fpresult)
  3680.           presult = 0;
  3681.         fpresult = fpj;
  3682.         } else {
  3683.         if (j >= result)
  3684.           presult = 0;
  3685.         result = j;
  3686.         }
  3687.         break;
  3688.  
  3689.       case SX_AGE:            /* Arithmetic greater-equal */
  3690.         if (fpflag) {
  3691.         if (fpj > fpresult)
  3692.           presult = 0;
  3693.         fpresult = fpj;
  3694.         } else {
  3695.         if (j > result)
  3696.           presult = 0;
  3697.         result = j;
  3698.         }
  3699.         break;
  3700.  
  3701.       case SX_POW:            /* Raise to power */
  3702. #ifdef FNFLOAT
  3703.         {
  3704.         double dummy;
  3705.         if (!fpj) {
  3706.             fpresult = 1.0;
  3707.         } else if ((!fpresult && fpj <= 0.0)) {
  3708.             printf("?Divide by zero - \"%s\"\n",cmdbuf);
  3709.             sexprc++;
  3710.             goto xdosexp;
  3711.         } else if (fpresult < 0.0 && modf(fpj,&dummy)) {
  3712.             printf("?Domain error - \"%s\"\n",cmdbuf);
  3713.             sexprc++;
  3714.             goto xdosexp;
  3715.         } else {
  3716.             fpresult = (CKFLOAT)pow(fpresult,fpj);
  3717.         }
  3718.         }
  3719. #endif /* FNFLOAT */
  3720.         if (j == 0) {
  3721.         result = 1;
  3722.         } else {
  3723.         int z, sign = 0;
  3724.         if (j < 0) {
  3725.             if (result == 0) {
  3726.             printf("?Divide by zero - \"%s\"\n",cmdbuf);
  3727.             sexprc++;
  3728.             goto xdosexp;
  3729.             }
  3730.             j = 0 - j;
  3731.             sign++;
  3732.         }
  3733.         z = result;
  3734.         while (--j > 0)
  3735.           result *= z;
  3736.         if (sign)
  3737.           result = 1 / result;
  3738.         }
  3739.         if (result != fpresult)
  3740.           fpflag++;
  3741.         break;
  3742.  
  3743. #ifdef FNFLOAT
  3744.       case SX_EXP:            /* e to the given power */
  3745.         fpresult = (CKFLOAT) exp(fpj);
  3746.         break;
  3747.  
  3748.       case SX_LGN:            /* Natural log */
  3749.       case SX_LGX:            /* Log base 10 */
  3750.       case SX_SQR:            /* Square root */
  3751.         if (fpj < 0.0) {
  3752.         printf("?Argument out of range - \"%s\"\n",cmdbuf);
  3753.         sexprc++;
  3754.         goto xdosexp;
  3755.         }
  3756.         if (x == SX_SQR)
  3757.           fpresult = (CKFLOAT) sqrt(fpj);
  3758.         else if (x == SX_LGN)
  3759.           fpresult = (CKFLOAT) log(fpj);
  3760.         else
  3761.           fpresult = (CKFLOAT) log10(fpj);
  3762.         break;
  3763.  
  3764.       case SX_SIN:            /* sine */
  3765.         fpresult = (CKFLOAT) sin(fpj);
  3766.         break;
  3767.  
  3768.       case SX_COS:            /* cosine */
  3769.         fpresult = (CKFLOAT) cos(fpj);
  3770.         break;
  3771.  
  3772.       case SX_TAN:            /* tangent */
  3773.         fpresult = (CKFLOAT) tan(fpj);
  3774.         break;
  3775. #endif /* FNFLOAT */
  3776.  
  3777.       case SX_CEI:            /* Ceiling */
  3778.         if (j != fpj)
  3779.           if (fpj > 0.0)
  3780.         fpj += 1.0;
  3781.         fpresult = fpj;
  3782.         fpflag = 1;
  3783.         truncate = 1;
  3784.         break;
  3785.  
  3786.       case SX_FLR:            /* Floor */
  3787.         if (j != fpj)
  3788.           if (fpj < 0.0)
  3789.         fpj -= 1.0;
  3790.         fpresult = fpj;
  3791.         fpflag = 1;
  3792.         truncate = 1;
  3793.         break;
  3794.  
  3795.       case SX_TRU:            /* Truncate */
  3796.         fpresult = fpj;
  3797.         fpflag = 1;
  3798.         truncate = 1;
  3799.         break;
  3800.  
  3801.       case SX_ROU:            /* Round */
  3802.         if (fpj > 0.0)
  3803.           fpj += 0.5;
  3804.         else if (fpj < 0.0)
  3805.           fpj -= 0.5;
  3806.         fpresult = fpj;
  3807.         fpflag = 1;
  3808.         truncate = 1;
  3809.         break;
  3810.  
  3811.       case SX_ABS:            /* Absolute value */
  3812.         result = (j < 0) ? 0 - j : j;
  3813.         fpresult = (fpj < 0.0) ? 0.0 - fpj : fpj;
  3814.         if (result != fpresult)
  3815.           fpflag++;
  3816.         break;
  3817.  
  3818.       case SX_MAX:            /* Max */
  3819.         if (j != fpj)
  3820.           fpflag++;
  3821.         if (fpflag) {
  3822.         if (fpj > fpresult)
  3823.           fpresult = fpj;
  3824.         } else
  3825.           if (j > result)
  3826.         result = j;
  3827.         break;
  3828.  
  3829.       case SX_MIN:            /* Min */
  3830.         if (j != fpj)
  3831.           fpflag++;
  3832.         if (fpflag) {
  3833.         if (fpj < fpresult)
  3834.           fpresult = fpj;
  3835.         } else
  3836.           if (j < result)
  3837.         result = j;
  3838.         break;
  3839.  
  3840.       case SX_FLO:            /* Float */
  3841.         fpflag++;
  3842.         fpresult = result;
  3843.         fpj = j;
  3844.         break;
  3845.  
  3846.       case SX_NOT:            /* NOT (reverse truth value) */
  3847.         fpflag = 0;
  3848.         not++;
  3849.         break;
  3850.  
  3851.       case SX_BWA:            /* Bitwise AND */
  3852.         fpflag = 0;
  3853.         result &= j;
  3854.         break;
  3855.  
  3856.       case SX_BWO:            /* Bitwise OR */
  3857.         fpflag = 0;
  3858.         result |= j;
  3859.         break;
  3860.  
  3861.       case SX_BWX:            /* Bitwise XOR */
  3862.       case SX_XOR:            /* Logical XOR */
  3863.         if (n > 3) {
  3864.         printf("?Too many operands - \"%s\"\n",s);
  3865.         sexprc++;
  3866.         goto xdosexp;
  3867.         }
  3868.         fpflag = 0;
  3869.         if (x == SX_BWX) {
  3870.         result ^= j;
  3871.         } else {
  3872.         result = (result && !j) || (!result && j);
  3873.         if (result) result = 1;
  3874.         }
  3875.         break;
  3876.  
  3877.       case SX_BWN:            /* Bitwise Not */
  3878.         fpflag = 0;
  3879.         result = ~result;
  3880.         break;
  3881.  
  3882.       default:
  3883.         printf("BAD OP [%s]\n",p[1]);
  3884.         sexprc++;
  3885.     }
  3886.     }
  3887.     if (!pflag)                /* Not a predicate */
  3888.       sexppv = -1;            /* So unset this */
  3889.  
  3890.   /* domacro: */
  3891.  
  3892.     if (macro) {            /* User-defined macro */
  3893.     extern int fsexpflag;        /* (see fneval():ckuus4.c) */
  3894.     int lookagain = 0;        /* Maybe the macro table changed */
  3895.     if (mactab[mx].kwd) {        /* Check and see */
  3896.         if (ckstrcmp(mactab[mx].kwd,p[1],-1,0))
  3897.           lookagain++;
  3898.     } else
  3899.       lookagain++;
  3900.     if (lookagain) {        /* The table changed */
  3901.         mx = mxlook(mactab,p[1],nmac); /* Get the macro's new index */
  3902.         debug(F111,sexpdebug("macro moved"),p[1],mx);
  3903.         if (mx < 0) {           /* Yikes! */
  3904.         printf("?Macro disappeared! - \"%s\"\n",p[1]);
  3905.         sexprc++;
  3906.         goto xdosexp;
  3907.         }
  3908.     }
  3909.     debug(F111,sexpdebug("macro mx"),mactab[mx].kwd,mx);
  3910.     if (fsexpflag) {        /* If embedded in a function call */
  3911.         if (cmpush() > -1) {    /* get a new copy of the parsing */
  3912.         extern int ifc;        /* environment, */
  3913.         int k, ifcsav = ifc;    /* save the IF state */
  3914.         dodo(mx,line,0);    /* Set up the macro */
  3915.         k = parser(1);        /* Call the parser to execute it */
  3916.         cmpop();        /* Pop back to previous level */
  3917.         ifc = ifcsav;        /* restore IF state */
  3918.         if (k == 0)        /* If no error */
  3919.           s2 = mrval[maclvl+1];    /* get return value, if any */
  3920.         if (!s2) s2 = "";
  3921.         debug(F110,sexpdebug("macro return"),s2,0);
  3922.         } else {
  3923.         printf("?Resources exhausted - \"%s\"\n",s);
  3924.         sexprc++;
  3925.         }
  3926.     } else {            /* Not embedded in a function call */
  3927.         dodo(mx,line,0);        /* As above but without cmpush/pop() */
  3928.         k = parser(1);
  3929.         if (k == 0)
  3930.           s2 = mrval[maclvl+1];
  3931.         if (!s2) s2 = "";
  3932.     }
  3933.     } else if (pflag) {            /* Predicate */
  3934.     if (not) presult = presult ? 0 : 1;
  3935.     sexppv = presult;        /* So set predicate value (0 or 1) */
  3936.     s2 = presult ? "1" : "0";
  3937.     } else if (fpflag) {        /* Result is floating-point */
  3938.     if (not) fpresult = fpresult ? 0.0 : 1.0;
  3939.     s2 = fpformat(fpresult,0,0);
  3940.     } else if (x != SX_EVA) {
  3941.     if (not) result = result ? 0 : 1;
  3942.     s2 = ckitoa(result);
  3943.     }
  3944.  
  3945. /* Common exit point.  Always come here to exit. */
  3946.  
  3947.   xdosexp:
  3948.  
  3949.     if (!s2) s2 = "";
  3950.     if (!sexprc && s2) {        /* Have a result */
  3951.     char * sx;
  3952.     char * q2 = s2; int xx = 0;
  3953.     if (*s2) {
  3954.         while (*q2++) xx++;        /* Get length */
  3955.         if (xx > sexprmax)        /* (stats) */
  3956.           sexprmax = xx;
  3957.     } else
  3958.       xx = 0;
  3959.     if (xx > sxrlen[sexpdep] || !sxresult[sexpdep]) {
  3960.         int k;
  3961.         k = xx + xx / 4;
  3962.         if (k < 32) k = 32;
  3963.         if (sxresult[sexpdep])
  3964.           free(sxresult[sexpdep]);
  3965.         if ((sxresult[sexpdep] = (char *)malloc(k))) {
  3966.         sxrlen[sexpdep] = k;
  3967.         } else {
  3968.         printf("?Memory allocation failure - \"%s\"\n",s2);
  3969.         sexprc++;
  3970.         }
  3971.     }
  3972.     sx = sxresult[sexpdep];        /* Point to result buffer */
  3973.     while ((*sx++ = *s2++)) ;    /* copy result. */
  3974.     if (fpflag && truncate) {    /* Floating point + truncate */
  3975.         sx = sxresult[sexpdep];    /* at decimal point */
  3976.         for (i = xx - 1; i >= 0; i--) {
  3977.         if (sx[i] == '.') {
  3978.             sx[i] = NUL;
  3979.             if (i == 0) {    /* If nothing left */
  3980.             sx[0] = '0';    /* put a zero. */
  3981.             sx[1] = NUL;
  3982.             }
  3983.         }
  3984.         }
  3985.     }
  3986.     }
  3987.     if (line)                /* If macro arg buffer allocated */
  3988.       free(line);            /* free it. */
  3989.     if (mustfree) {            /* And free local copy of split list */
  3990.     for (i = 1; i <= n; i++) {
  3991.         if (p[i]) free(p[i]);
  3992.     }
  3993.     }
  3994.     debug(F111,sexpdebug("exit"),sxresult[sexpdep],sexprc);
  3995.     return(sxresult[sexpdep--]);
  3996. }
  3997. #endif /* NOSEXP */
  3998. #endif /* NOSPL */
  3999.  
  4000. int                    /* CHECK command */
  4001. dochk() {
  4002.     int x, y;
  4003.     if ((y = cmkey(ftrtab,nftr,"","",xxstring)) < 0)
  4004.       return(y);
  4005.     ckstrncpy(line,atmbuf,LINBUFSIZ);
  4006.     if ((y = cmcfm()) < 0)
  4007.       return(y);
  4008. #ifndef NOPUSH
  4009.     if (!ckstrcmp(line,"push",(int)strlen(line),0)) {
  4010.     if (msgflg)            /* If at top level... */
  4011.       printf(" push%s available\n", nopush ? " not" : "");
  4012.     else if (nopush && !backgrd)
  4013.       printf(" CHECK: push not available\n");
  4014.     return(success = 1 - nopush);
  4015.     }
  4016. #endif /* NOPUSH */
  4017. #ifdef PIPESEND
  4018.     if (!ckstrcmp(line,"pipes",(int)strlen(line),0)) {
  4019.     if (msgflg)            /* If at top level... */
  4020.       printf(" pipes%s available\n",
  4021.          (nopush || protocol != PROTO_K) ? " not" : "");
  4022.     else if ((nopush || protocol != PROTO_K) && !backgrd)
  4023.       printf(" CHECK: pipes not available\n");
  4024.     return(success = 1 - nopush);
  4025.     }
  4026. #endif /* PIPESEND */
  4027.     y = lookup(ftrtab,line,nftr,&x);    /* Look it up */
  4028.     debug(F111,"dochk",ftrtab[x].kwd,y);
  4029.     if (msgflg)                /* If at top level... */
  4030.       printf(" %s%s available\n", ftrtab[x].kwd, y ? " not" : "");
  4031.     else if (y && !backgrd)
  4032.       printf(" CHECK: %s not available\n", ftrtab[x].kwd);
  4033.     return(success = 1 - y);
  4034. }
  4035.  
  4036. #ifndef NOLOCAL
  4037. #ifdef CKLOGDIAL
  4038.  
  4039. /* Connection log and elapsed-time reporting */
  4040.  
  4041. extern char cxlogbuf[];            /* Log record buffer */
  4042. extern char diafil[];            /* Log file name */
  4043. extern int dialog, cx_active;        /* Flags */
  4044. static long cx_prev = 0L;        /* Elapsed time of previous session */
  4045.  
  4046. VOID
  4047. dologend() {                /* Write record to connection log */
  4048.     long d1, d2, t1, t2;
  4049.     char buf[32], * p;
  4050.  
  4051.     debug(F101,"dologend dialog","",dialog);
  4052.     debug(F101,"dologend cxlogbuf[0]","",cxlogbuf[0]);
  4053. #ifdef CKSYSLOG
  4054.     debug(F101,"dologend ckxlogging","",ckxlogging);
  4055. #endif /* CKSYSLOG */
  4056.  
  4057.     if (!cx_active || !cxlogbuf[0])    /* No active record */
  4058.       return;
  4059.  
  4060.     cx_active = 0;            /* Record is not active */
  4061.     debug(F111,"dologend cxlogbuf 1",cxlogbuf,cx_active);
  4062.  
  4063.     d1 = mjd((char *)cxlogbuf);        /* Get start date of this session */
  4064.     ckstrncpy(buf,ckdate(),31);        /* Get current date */
  4065.     d2 = mjd(buf);            /* Convert them to mjds */
  4066.     p = cxlogbuf;            /* Get start time */
  4067.     p[11] = NUL;
  4068.     p[14] = NUL;            /* Convert to seconds */
  4069.     t1 = atol(p+9) * 3600L + atol(p+12) * 60L + atol(p+15);
  4070.     p[11] = ':';
  4071.     p[14] = ':';
  4072.     p = buf;                /* Get end time */
  4073.     p[11] = NUL;
  4074.     p[14] = NUL;
  4075.     t2 = atol(p+9) * 3600L + atol(p+12) * 60L + atol(p+15);
  4076.     t2 = ((d2 - d1) * 86400L) + (t2 - t1); /* Compute elapsed time */
  4077.     debug(F101,"dologend t2","",t2);
  4078.     if (t2 > -1L) {
  4079.     cx_prev = t2;
  4080.     p = hhmmss(t2);
  4081.     debug(F110,"dologend hhmmss",p,0);
  4082.     strncat(cxlogbuf,"E=",CXLOGBUFL); /* Append to log record */
  4083.     strncat(cxlogbuf,p,CXLOGBUFL);
  4084.     debug(F110,"dologend cxlogbuf 2",cxlogbuf,0);
  4085.     } else
  4086.       cx_prev = 0L;
  4087.     debug(F101,"dologend cx_prev","",cx_prev);
  4088.     if (dialog) {            /* If logging */
  4089.     int x;
  4090.     x = diaopn(diafil,1,1);        /* Open log in append mode */
  4091.     debug(F101,"dologend diaopn","",x);
  4092.     x = zsoutl(ZDIFIL,cxlogbuf);    /* Write the record */
  4093.     debug(F101,"dologend zsoutl","",x);
  4094.     x = zclose(ZDIFIL);        /* Close the log */
  4095.     debug(F101,"dologend zclose","",x);
  4096.     }
  4097. #ifdef CKSYSLOG
  4098.     debug(F101,"dologend ckxlogging","",ckxlogging);
  4099.     if (ckxlogging) {
  4100.     int x;
  4101.     x = ckindex("T=DIAL",cxlogbuf,0,0,1);
  4102.     debug(F111,"dologend ckxsyslog",cxlogbuf,ckxsyslog);
  4103.     debug(F111,"dologend ckindex","T=DIAL",x);
  4104.         if (x > 0) {
  4105.         if (ckxsyslog >= SYSLG_DI) {
  4106.         debug(F110,"dologend syslog",cxlogbuf+18,0);
  4107.         cksyslog(SYSLG_DI,1,"CONNECTION",(char *)(cxlogbuf+18),"");
  4108.         } else if (ckxsyslog >= SYSLG_AC) {
  4109.         debug(F110,"dologend syslog",cxlogbuf+18,0);
  4110.         cksyslog(SYSLG_AC,1,"CONNECTION",(char *)(cxlogbuf+18),"");
  4111.         }
  4112.         }
  4113.     }
  4114. #endif /* CKSYSLOG */
  4115. }
  4116.  
  4117. /*  D O L O G S H O W  --  Show session/connection info  */
  4118.  
  4119. /* Call with fc == 1 to show, fc == 0 to only calculate. */
  4120. /* Returns session elapsed time in seconds. */
  4121. /* If no session active, returns elapsed time of previous session, if any, */
  4122. /* otherwise 0 */
  4123.  
  4124. long
  4125. dologshow(fc) int fc; {            /* SHOW (current) CONNECTION */
  4126.     long d1, d2, t1, t2 = 0, prev;
  4127.     char c, buf1[32], buf2[32], * info[32], * p, * s;
  4128.     char * xlogbuf, xbuf[CXLOGBUFL+1];
  4129.     int i, x = 0, z, ftp = 0, active = 0;
  4130.  
  4131. #ifdef NEWFTP
  4132.     extern char ftplogbuf[];
  4133.     extern long ftplogprev;
  4134.     extern int ftplogactive;
  4135.     if (fc & W_FTP) {
  4136.     fc &= 63;
  4137.     ftp = 1;
  4138.     xlogbuf = ftplogbuf;
  4139.     prev = ftplogprev;
  4140.     active = ftplogactive;
  4141.     } else {
  4142. #endif /* NEWFTP */
  4143.     ftp = 0;
  4144.     xlogbuf = cxlogbuf;
  4145.     prev = cx_prev;
  4146.     active = cx_active;
  4147. #ifdef NEWFTP
  4148.     }
  4149. #endif /* NEWFTP */
  4150.  
  4151.     debug(F101,"dologshow local","",local);
  4152.     debug(F101,"dologshow ftp","",ftp);
  4153.     debug(F111,"dologshow active",xlogbuf,active);
  4154.  
  4155.     if (!xlogbuf[0]) {
  4156.     if (fc) {
  4157.         if (didsetlin || ftp)
  4158.           printf(" %s: No record.\n", ftp ? "FTP" : "Kermit");
  4159.         else
  4160.           printf(" %s: No connection.\n", ftp ? "FTP" : "Kermit");
  4161.     }
  4162.     return(prev);
  4163.     }
  4164.  
  4165. #ifdef NEWFTP
  4166.     if (ftp) {
  4167.     z = ftpisconnected() ? 1 : -1;
  4168.     } else {
  4169. #endif /* NEWFTP */
  4170.     if (local) {            /* See if we have an open connection */
  4171.         z = ttchk();
  4172.         debug(F101,"dologshow ttchk","",z);
  4173.         z = (z > -1) ? 1 : -2;
  4174.     } else {
  4175.         z = active ? 1 : -2;
  4176.     }
  4177. #ifdef NEWFTP
  4178.     }
  4179. #endif /* NEWFTP */
  4180.     if (z < 0L) {
  4181.     if (!fc)
  4182.       return(prev);
  4183.     else
  4184.       t2 = prev;
  4185.     }
  4186.     /* Note: NOT ckstrncpy! */
  4187.     strncpy(buf1,xlogbuf,17);        /* Copy of just the timestamp */
  4188.     buf1[17] = NUL;            /* Terminate it */
  4189.     ckstrncpy(xbuf,xlogbuf+18,CXLOGBUFL); /* Copy that can be poked */
  4190.     debug(F111,"dologshow prev",xbuf,prev);
  4191.  
  4192.     xwords(xbuf,31,info,1);        /* Break up into fields */
  4193.     d1 = mjd(buf1);            /* Convert start time to MJD */
  4194.     ckstrncpy(buf2,ckdate(),31);    /* Current date */
  4195.     d2 = mjd(buf2);            /* Convert to MJD */
  4196.     p = buf1;                /* Point to start time */
  4197.     p[11] = NUL;
  4198.     p[14] = NUL;            /* Convert to seconds */
  4199.     t1 = atol(p+9) * 3600L + atol(p+12) * 60L + atol(p+15);
  4200.     p[11] = ':';
  4201.     p[14] = ':';
  4202.     p = buf2;                /* Ditto for current time */
  4203.     p[11] = NUL;
  4204.     p[14] = NUL;
  4205.     if (z > -1L) {
  4206.     t2 = atol(p+9) * 3600L + atol(p+12) * 60L + atol(p+15);
  4207.     t2 = ((d2 - d1) * 86400L) + (t2 - t1); /* Elapsed time so far */
  4208.     }
  4209.     if (fc) {
  4210.     p = NULL;
  4211.     if (t2 > -1L)            /* Convert seconds to hh:mm:ss */
  4212.       p = hhmmss(t2);
  4213.     if (z > -1)
  4214.       s = "Active";
  4215.     else if (z == -2)
  4216.       s = "Closed";
  4217.     else
  4218.       s = "Unknown";
  4219.     printf("\n");            /* Show results */
  4220.     printf(" Status:       %s\n",s);
  4221.     printf(" Opened:       %s\n",buf1);
  4222.     printf(" User:         %s\n",info[1] ? info[1] : "");
  4223.     printf(" PID:          %s\n",info[2] ? info[2] : "");
  4224.     for (i = 3; info[i]; i++) {
  4225.         c = info[i][0];
  4226.         s = (info[i]) ? info[i]+2 : "";
  4227.         switch (c) {
  4228.           case 'T': printf(" Type:         %s\n", s); break;
  4229.           case 'N': printf(" To:           %s\n", s); break;
  4230.           case 'H': printf(" From:         %s\n", s); break;
  4231.           case 'D': printf(" Device:       %s\n", s); break;
  4232.           case 'O': printf(" Origin:       %s\n", s); break;
  4233.           case 'E': break;
  4234.           default:  printf(" %s\n",info[i] ? info[i] : "");
  4235.         }
  4236.     }
  4237.     if (z < 0L)
  4238.       printf(" Elapsed time: %s\n", hhmmss(t2));
  4239.     else
  4240.       printf(" Elapsed time: %s\n", p ? p : "(unknown)");
  4241.     x = 0;
  4242. #ifdef NETCONN
  4243. #ifdef CK_ENCRYPTION
  4244.     if (ck_tn_encrypting() && ck_tn_decrypting()) x++;
  4245. #endif /* CK_ENCRYPTION */
  4246. #ifdef CK_SSL
  4247.     if (tls_active_flag || ssl_active_flag) x++;
  4248. #endif /* CK_SSL */
  4249. #ifdef RLOGCODE
  4250. #ifdef CK_KERBEROS
  4251. #ifdef CK_ENCRYPTION
  4252.     if (ttnproto == NP_EK4LOGIN || ttnproto == NP_EK5LOGIN) x++;
  4253. #endif /* CK_ENCRYPTION */
  4254. #endif /* CK_KERBEROS */
  4255. #endif /* RLOGCODE */
  4256. #endif /* NETCONN */
  4257.         if (z > 0)
  4258.       printf(" Encrypted:    %s\n", x ? "Yes" : "No");
  4259.     printf(" Log:          %s\n", dialog ? diafil : "(none)");
  4260.     printf("\n");
  4261.     }
  4262.     return(t2 > -1L ? t2 : 0L);
  4263. }
  4264.  
  4265. VOID
  4266. dologline() {
  4267.     char * p;
  4268.     int n, m = 0;
  4269.  
  4270.     dologend();                /* Previous session not closed out? */
  4271.     cx_active = 1;            /* Record is active */
  4272.     cx_prev = 0L;
  4273.     p = ckdate();            /* Get timestamp */
  4274.     n = ckstrncpy(cxlogbuf,p,CXLOGBUFL-1); /* Start record off with it */
  4275.     if (!uidbuf[0]) {
  4276.     debug(F100,"dologline uidbuf empty","",0);
  4277. #ifdef UNIX                /* Who has whoami()... */
  4278.     ckstrncpy(uidbuf,(char *)whoami(),UIDBUFLEN);
  4279. #else
  4280. #ifdef STRATUS
  4281.     ckstrncpy(uidbuf,(char *)whoami(),UIDBUFLEN);
  4282. #else
  4283.     ckstrncpy(uidbuf,"UNKNOWN",UIDBUFLEN);
  4284. #endif /* STRATUS */
  4285. #endif /* UNIX */
  4286.     }
  4287.     m = strlen(uidbuf) + strlen(myhost) + strlen(ttname) + 32;
  4288.     if (n+m < CXLOGBUFL-1) {        /* Add serial device info */
  4289.     p = cxlogbuf+n;
  4290.     sprintf(p," %s %s T=SERIAL H=%s D=%s ",    /* SAFE */
  4291.         uidbuf,
  4292.         ckgetpid(),
  4293.         myhost,
  4294.         ttname
  4295.         );
  4296.     } else
  4297.       ckstrncpy(cxlogbuf,"LOGLINE BUFFER OVERFLOW",CXLOGBUFL);
  4298.     debug(F110,"dologline",cxlogbuf,0);
  4299. }
  4300.  
  4301. #ifdef NETCONN
  4302. VOID
  4303. dolognet() {
  4304.     char * p, * s = "NET", * uu = uidbuf;
  4305.     int n, m;
  4306.  
  4307.     dologend();                /* Previous session not closed out? */
  4308.     cx_prev = 0L;
  4309.     cx_active = 1;            /* Record is active */
  4310.     p = ckdate();
  4311.     n = ckstrncpy(cxlogbuf,p,CXLOGBUFL);
  4312. #ifdef TCPSOCKET
  4313.     if (nettype == NET_TCPB || nettype == NET_TCPA)
  4314.       s = "TCP";
  4315. #endif /* TCPSOCKET */
  4316. #ifdef ANYX25
  4317.     if (nettype == NET_SX25 || nettype == NET_VX25 || nettype == NET_IX25)
  4318.       s = "X25";
  4319. #endif /* ANYX25 */
  4320. #ifdef DECNET
  4321.     if (nettype == NET_DEC)
  4322.       s = "DECNET";
  4323. #endif /* DECNET */
  4324. #ifdef SUPERLAT
  4325.     if (nettype == NET_SLAT)
  4326.       s = "SUPERLAT";
  4327. #endif /* SUPERLAT */
  4328. #ifdef CK_NETBIOS
  4329.     if (nettype == NET_BIOS)
  4330.       s = "NETBIOS";
  4331. #endif /* CK_NETBIOS */
  4332.  
  4333.     if (!uu[0]) {
  4334.     debug(F100,"dolognet uidbuf empty","",0);
  4335. #ifdef OS2ORUNIX            /* Who has whoami()... */
  4336.         uu = (char *)whoami();
  4337. #else
  4338. #ifdef STRATUS
  4339.         uu = (char *)whoami();
  4340. #else
  4341.         uu = "UNKNOWN";
  4342. #endif /* STRATUS */
  4343. #endif /* UNIX */
  4344.     }
  4345.     m = strlen(uu) + strlen(myhost) + strlen(ttname) + strlen(s) + 32;
  4346.     if (n+m < CXLOGBUFL-1) {        /* SAFE */
  4347.     p = cxlogbuf+n;
  4348.     sprintf(p," %s %s T=%s N=%s H=%s ",
  4349.         uu,
  4350.         ckgetpid(),
  4351.         s,
  4352.         ttname,
  4353.         myhost
  4354.         );
  4355.     } else
  4356.       ckstrncpy(cxlogbuf,"LOGNET BUFFER OVERFLOW",CXLOGBUFL);
  4357.     debug(F110,"dolognet cxlogbuf",cxlogbuf,0);
  4358. }
  4359. #endif /* NETCONN */
  4360. #endif /* CKLOGDIAL */
  4361.  
  4362. #ifndef NODIAL
  4363. /*
  4364.   Parse a DIAL-related string, stripping enclosing braces, if any.
  4365. */
  4366. static int
  4367. dialstr(p,msg) char **p; char *msg; {
  4368.     int x;
  4369.     char *s;
  4370.  
  4371.     if ((x = cmtxt(msg, "", &s, xxstring)) < 0)
  4372.       return(x);
  4373.     s = brstrip(s);            /* Strip braces around. */
  4374.     debug(F110,"dialstr",s,0);
  4375.     makestr(p,*s?s:NULL);
  4376.     return(success = 1);
  4377. }
  4378.  
  4379. VOID
  4380. initmdm(x) int x; {
  4381.     MDMINF * p;
  4382.     int m;
  4383.  
  4384.     mdmtyp = x;                /* Set global modem type */
  4385.     debug(F101,"initmdm mdmtyp","",mdmtyp);
  4386.     debug(F101,"initmdm usermdm","",usermdm);
  4387.     if (x < 1) return;
  4388.  
  4389.     m = usermdm ? usermdm : mdmtyp;
  4390.  
  4391.     p = modemp[m];            /* Point to modem info struct, and */
  4392.     debug(F101,"initmdm p","",p);
  4393.     if (p) {
  4394.     dialec = p->capas & CKD_EC;    /* set DIAL ERROR-CORRECTION, */
  4395.     dialdc = p->capas & CKD_DC;    /* DIAL DATA-COMPRESSION, and */
  4396.     mdmspd = p->capas & CKD_SB ? 0 : 1; /* DIAL SPEED-MATCHING from it. */
  4397.     dialfc = FLO_AUTO;            /* Modem's local flow control.. */
  4398.     dialmax   = p->max_speed;
  4399.     dialcapas = p->capas;
  4400.     dialesc   = p->esc_char;
  4401.     } else if (mdmtyp > 0) {
  4402.     printf("WARNING: modem info for \"%s\" not filled in yet\n",
  4403.            gmdmtyp()
  4404.            );
  4405.     }
  4406.  
  4407. /* Reset or set the SET DIAL STRING items ... */
  4408.  
  4409. #ifdef DEBUG
  4410.     if (deblog) {
  4411.         debug(F110,"initmdm dialini",dialini,0);
  4412.         debug(F110,"initmdm dialmstr ",dialmstr,0);
  4413.         debug(F110,"initmdm dialmprmt",dialmprmt,0);
  4414.         debug(F110,"initmdm dialcmd",dialcmd,0);
  4415.         debug(F110,"initmdm dialdcon",dialdcon,0);
  4416.         debug(F110,"initmdm dialdcoff",dialdcoff,0);
  4417.         debug(F110,"initmdm dialecon",dialecon,0);
  4418.         debug(F110,"initmdm dialecoff",dialecoff,0);
  4419.         debug(F110,"initmdm dialhcmd",dialhcmd,0);
  4420.         debug(F110,"initmdm dialhwfc",dialhwfc,0);
  4421.         debug(F110,"initmdm dialswfc",dialswfc,0);
  4422.         debug(F110,"initmdm dialnofc",dialnofc,0);
  4423.         debug(F110,"initmdm dialtone",dialtone,0);
  4424.         debug(F110,"initmdm dialpulse",dialpulse,0);
  4425.         debug(F110,"initmdm dialname",dialname,0);
  4426.         debug(F110,"initmdm dialaaon",dialaaon,0);
  4427.         debug(F110,"initmdm dialaaoff",dialaaoff,0);
  4428.         debug(F110,"initmdm dialx3",dialx3,0);
  4429.         debug(F110,"initmdm dialspon",dialspon,0);
  4430.         debug(F110,"initmdm dialspoff",dialspoff,0);
  4431.         debug(F110,"initmdm dialvol1",dialvol1,0);
  4432.         debug(F110,"initmdm dialvol2",dialvol2,0);
  4433.         debug(F110,"initmdm dialvol3",dialvol3,0);
  4434.         debug(F110,"initmdm dialini2",dialini2,0);
  4435.     }
  4436. #endif /* DEBUG */
  4437.  
  4438.     if (usermdm && p) {    /* USER-DEFINED: copy info from specified template */
  4439.  
  4440.     makestr(&dialini  ,p->wake_str);
  4441.     makestr(&dialmstr ,p->dmode_str);
  4442.     makestr(&dialmprmt,p->dmode_prompt);
  4443.     makestr(&dialcmd  ,p->dial_str);
  4444.     makestr(&dialdcon ,p->dc_on_str);
  4445.     makestr(&dialdcoff,p->dc_off_str);
  4446.     makestr(&dialecon ,p->ec_on_str);
  4447.     makestr(&dialecoff,p->ec_off_str);
  4448.     makestr(&dialhcmd ,p->hup_str);
  4449.     makestr(&dialhwfc ,p->hwfc_str);
  4450.     makestr(&dialswfc ,p->swfc_str);
  4451.     makestr(&dialnofc ,p->nofc_str);
  4452.     makestr(&dialtone ,p->tone);
  4453.     makestr(&dialpulse,p->pulse);
  4454.     makestr(&dialname ,"This space available (use SET MODEM NAME)");
  4455.     makestr(&dialaaon ,p->aa_on_str);
  4456.     makestr(&dialaaoff,p->aa_off_str);
  4457.     makestr(&dialx3   ,p->ignoredt);
  4458.     makestr(&dialspon ,p->sp_on_str);
  4459.     makestr(&dialspoff,p->sp_off_str);
  4460.     makestr(&dialvol1 ,p->vol1_str);
  4461.     makestr(&dialvol2 ,p->vol2_str);
  4462.     makestr(&dialvol3 ,p->vol3_str);
  4463.     makestr(&dialini2 ,p->ini2);
  4464.  
  4465.     } else {            /* Not user-defined, so wipe out overrides */
  4466.  
  4467.     if (dialini)   makestr(&dialini,NULL);   /* Init-string */
  4468.     if (dialmstr)  makestr(&dialmstr,NULL);  /* Dial-mode-str */
  4469.     if (dialmprmt) makestr(&dialmprmt,NULL); /* Dial-mode-pro */
  4470.     if (dialcmd)   makestr(&dialcmd,NULL);   /* Dial-command  */
  4471.     if (dialdcon)  makestr(&dialdcon,NULL);  /* DC ON command */
  4472.     if (dialdcoff) makestr(&dialdcoff,NULL); /* DC OFF command */
  4473.     if (dialecon)  makestr(&dialecon,NULL);  /* EC ON command */
  4474.     if (dialecoff) makestr(&dialecoff,NULL); /* EC OFF command */
  4475.     if (dialhcmd)  makestr(&dialhcmd,NULL);  /* Hangup command */
  4476.     if (dialhwfc)  makestr(&dialhwfc,NULL);  /* Flow control... */
  4477.     if (dialswfc)  makestr(&dialswfc,NULL);  /*  */
  4478.     if (dialnofc)  makestr(&dialnofc,NULL);  /*  */
  4479.     if (dialtone)  makestr(&dialtone,NULL);  /* Dialing method */
  4480.     if (dialpulse) makestr(&dialpulse,NULL); /*  */
  4481.     if (dialname)  makestr(&dialname,NULL);  /* Modem name */
  4482.     if (dialaaon)  makestr(&dialaaon,NULL);  /* Autoanswer On */
  4483.     if (dialaaoff) makestr(&dialaaoff,NULL); /* Autoanswer Off */
  4484.     if (dialx3)    makestr(&dialx3,NULL);    /* Ignore dialtone */
  4485.     if (dialspon)  makestr(&dialspon,NULL);  /* Speaker On */
  4486.     if (dialspoff) makestr(&dialspoff,NULL); /* Speaker Off */
  4487.     if (dialvol1)  makestr(&dialvol1,NULL);  /* Low volume */
  4488.     if (dialvol2)  makestr(&dialvol2,NULL);  /* Medium volume */
  4489.     if (dialvol3)  makestr(&dialvol3,NULL);  /* High volume */
  4490.     if (dialini2)  makestr(&dialini2,NULL);  /* Init string 2 */
  4491.     }
  4492.     if (autoflow)            /* Maybe change flow control */
  4493.       setflow();
  4494.  
  4495. #ifndef MINIDIAL
  4496. #ifdef OLDTBCODE
  4497.     tbmodel = 0;           /* If it's a Telebit, we don't know the model yet */
  4498. #endif /* OLDTBCODE */
  4499. #endif /* MINIDIAL */
  4500. }
  4501.  
  4502. int
  4503. setmodem() {                /* SET MODEM */
  4504.  
  4505.     int x, y, z;
  4506.     long zz;
  4507.     struct FDB k1, k2;
  4508.     extern int mdmset;
  4509.  
  4510.     cmfdbi(&k1,_CMKEY,
  4511.        "Modem parameter","","",nsetmdm, 0, xxstring, setmdm, &k2);
  4512.     cmfdbi(&k2,_CMKEY,"","","",nmdm,0,xxstring,mdmtab,NULL);
  4513.     x = cmfdb(&k1);
  4514.     if (x < 0) {            /* Error */
  4515.     if (x == -2 || x == -9)
  4516.       printf("?No keywords match: \"%s\"\n",atmbuf);
  4517.     return(x);
  4518.     }
  4519.     y = cmresult.nresult;        /* Keyword value */
  4520.     if (cmresult.fdbaddr == &k2) {    /* Modem-type keyword table */
  4521.     if ((x = cmcfm()) < 0)
  4522.       return(x);
  4523.     usermdm = 0;
  4524.     initmdm(cmresult.nresult);    /* Set the modem type. */
  4525.     return(success = 1);        /* Done */
  4526.     }
  4527.     switch (cmresult.nresult) {        /* SET MODEM keyword table. */
  4528. #ifdef MDMHUP
  4529.       case XYDMHU:            /* DIAL MODEM-HANGUP */
  4530.     if ((y = cmkey(mdmhang,4,"how to hang up modem",
  4531.                "modem-command", xxstring)) < 0)
  4532.       return(y);
  4533.     if ((x = cmcfm()) < 0)
  4534.       return(x);
  4535.     dialmhu = y;
  4536. #ifdef COMMENT
  4537. /* Nope, I fixed it (2001 11 08) */
  4538. #ifdef CK_SCOV5
  4539.     if (dialmhu == 0 && !quiet) {
  4540.         printf(
  4541. "\n WARNING: RS-232 signal sampling and manipulation do not work\n"
  4542.             );
  4543.         printf(
  4544. " in the standard SCO OSR5 serial i/o drivers.  SET MODEM HANGUP-METHOD\n"
  4545.            );
  4546.         printf(
  4547. " MODEM-COMMAND is recommended for OSR5.\n\n"
  4548.             );
  4549.     }
  4550. #endif /* CK_SCOV5 */
  4551. #endif /* COMMENT */
  4552.     return(success = 1);
  4553. #endif /* MDMHUP */
  4554.  
  4555.       case XYDCAP:
  4556.     zz = 0L;
  4557.     y = 0;
  4558.     while (y != -3) {
  4559.         if ((y = cmkey(mdmcap,nmdmcap,
  4560.                "capability of modem", "", xxstring)) < 0) {
  4561.         if (y == -3)
  4562.           break;
  4563.         else
  4564.           return(y);
  4565.         }
  4566.         zz |= y;
  4567.     }
  4568.     if ((x = cmcfm()) < 0)
  4569.       return(x);
  4570.     dialcapas = zz;
  4571.     debug(F101,"setmodem autoflow","",autoflow);
  4572.     debug(F101,"setmodem flow 1","",flow);
  4573.     if (autoflow)            /* Maybe change flow control */
  4574.       setflow();
  4575.     debug(F101,"setmodem flow 2","",flow);
  4576.     mdmspd = zz & CKD_SB ? 0 : 1;    /* Set MODEM SPEED-MATCHING from it. */
  4577.     return(success = 1);
  4578.  
  4579.       case XYDMAX:
  4580. #ifdef TN_COMPORT
  4581.     if (network && istncomport())
  4582.       x = cmkey(tnspdtab,ntnspd,line,"",xxstring);
  4583.     else
  4584. #endif /* TN_COMPORT */
  4585.       x = cmkey(spdtab,nspd,line,"",xxstring);
  4586.     if (x < 0) {
  4587.         if (x == -3) printf("?value required\n");
  4588.         return(x);
  4589.     }
  4590.     if ((y = cmcfm()) < 0) return(y);
  4591.     dialmax = (long) x * 10L;
  4592.     if (dialmax == 70) dialmax = 75;
  4593.     return(success = 1);
  4594.  
  4595.       case XYDSTR:            /* These moved from SET DIAL */
  4596.       case XYDDC:
  4597.       case XYDEC:
  4598.       case XYDESC:
  4599.       case XYDFC:
  4600.       case XYDKSP:
  4601.       case XYDSPD:
  4602.       case XYDDIA:
  4603.     return(setdial(x));
  4604.  
  4605.       case XYDTYP:
  4606.     if ((y = cmkey(mdmtab,nmdm,"modem type","none", xxstring)) < 0)
  4607.       return(y);
  4608.     if (y == dialudt) {        /* User-defined modem type */
  4609.         if ((x = cmkey(mdmtab,nmdm,"based on existing modem type",
  4610.                "unknown", xxstring)) < 0)
  4611.           return(x);
  4612.     }
  4613.     if ((z = cmcfm()) < 0)
  4614.       return(z);
  4615.     usermdm = 0;
  4616.     usermdm = (y == dialudt) ? x : 0;
  4617.     initmdm(y);
  4618.     mdmset = (mdmtyp > 0);
  4619.     return(success = 1);
  4620.  
  4621.       case XYDNAM:
  4622.     return(dialstr(&dialname,"Descriptive name for modem"));
  4623.  
  4624.       case XYDMCD:            /* SET MODEM CARRIER-WATCH */
  4625.     return(setdcd());
  4626.  
  4627.       case XYDSPK:            /* SET MODEM SPEAKER */
  4628.     return(seton(&mdmspk));
  4629.  
  4630.       case XYDVOL:            /* SET MODEM VOLUME */
  4631.     if ((x = cmkey(voltab,3,"","medium",xxstring)) < 0)
  4632.       return(x);
  4633.     if ((y = cmcfm()) < 0)
  4634.       return(y);
  4635.     mdmvol = x;
  4636.     return(success = 1);
  4637.  
  4638.       default:
  4639.     printf("Unexpected SET MODEM parameter\n");
  4640.     return(-9);
  4641.     }
  4642. }
  4643.  
  4644. static int                /* Set DIAL command options */
  4645. setdial(y) int y; {
  4646.     int x = 0, z = 0;
  4647.     char *s = NULL;
  4648.  
  4649.     if (y < 0)
  4650.       if ((y = cmkey(dialtab,ndial,"","",xxstring)) < 0)
  4651.     return(y);
  4652.     switch (y) {
  4653.       case XYDHUP:            /* DIAL HANGUP */
  4654.     return(seton(&dialhng));
  4655.       case XYDINI:            /* DIAL INIT-STRING */
  4656.     return(dialstr(&dialini,"Modem initialization string"));
  4657.       case XYDNPR:            /* DIAL PREFIX */
  4658.     return(dialstr(&dialnpr,"Telephone number prefix"));
  4659.       case XYDDIA:            /* DIAL DIAL-COMMAND */
  4660.     x = cmtxt("Dialing command for modem,\n\
  4661.  include \"%s\" to stand for phone number,\n\
  4662.  for example, \"set dial dial-command ATDT%s\\13\"",
  4663.           "",
  4664.           &s,
  4665.           xxstring);
  4666.     if (x < 0 && x != -3)        /* Handle parse errors */
  4667.       return(x);
  4668.     s = brstrip(s);            /* Strip braces or quotes */
  4669.     y = x = strlen(s);        /* Get length of text */
  4670.     if (y > 0) {            /* If there is any text (left), */
  4671.         for (x = 0; x < y; x++) {    /* make sure they included "%s" */
  4672.         if (s[x] != '%') continue;
  4673.         if (s[x+1] == 's') break;
  4674.         }
  4675.         if (x == y) {
  4676.         printf(
  4677. "?Dial-command must contain \"%cs\" for phone number.\n",'%');
  4678.         return(-9);
  4679.         }
  4680.     }
  4681.     if (dialcmd) {            /* Free any previous string. */
  4682.         free(dialcmd);
  4683.         dialcmd = (char *) 0;
  4684.     }
  4685.     if (y > 0) {
  4686.         dialcmd = malloc(y + 1);    /* Allocate space for it */
  4687.         if (dialcmd)
  4688.           strcpy(dialcmd,s);    /* and make a safe copy. */
  4689.     }
  4690.     return(success = 1);
  4691. #ifndef NOXFER
  4692.       case XYDKSP:            /* DIAL KERMIT-SPOOF */
  4693.     return(seton(&dialksp));
  4694. #endif /* NOXFER */
  4695.       case XYDTMO:            /* DIAL TIMEOUT */
  4696.     y = cmnum("Seconds to wait for call completion","0",10,&x,xxstring);
  4697.     if (y < 0) return(y);
  4698.     y = cmnum("Kermit/modem timeout differential","10",10,&z,xxstring);
  4699.     if (y < 0) return(y);
  4700.     if ((y = cmcfm()) < 0)
  4701.       return(y);
  4702.     dialtmo = x;
  4703.     mdmwaitd = z;
  4704.       case XYDESC:            /* DIAL ESCAPE-CHARACTER */
  4705.     y = cmnum("ASCII value of character to escape back to modem",
  4706.           "43",10,&x,xxstring);
  4707.     y = setnum(&dialesc,x,y,128);
  4708.     if (y > -1 && dialesc < 0)    /* No escape character */
  4709.       dialmhu = 0;            /* So no hangup by modem command */
  4710.     return(y);
  4711.       case XYDDPY:            /* DIAL DISPLAY */
  4712.     return(seton(&dialdpy));
  4713.       case XYDSPD:            /* DIAL SPEED-MATCHING */
  4714.                     /* used to be speed-changing */
  4715.     if ((y = seton(&mdmspd)) < 0) return(y);
  4716. #ifdef COMMENT
  4717.     mdmspd = 1 - mdmspd;        /* so here we reverse the meaning */
  4718. #endif /* COMMENT */
  4719.     return(success = 1);
  4720.       case XYDMNP:            /* DIAL MNP-ENABLE */
  4721.       case XYDEC:            /* DIAL ERROR-CORRECTION */
  4722.     x = seton(&dialec);
  4723.     if (x > 0)
  4724.       if (!dialec) dialdc = 0;    /* OFF also turns off compression */
  4725.     return(x);
  4726.  
  4727.       case XYDDC:            /* DIAL COMPRESSION */
  4728.     x = seton(&dialdc);
  4729.     if (x > 0)
  4730.       if (dialdc) dialec = 1;    /* ON also turns on error correction */
  4731.     return(x);
  4732.  
  4733. #ifdef MDMHUP
  4734.       case XYDMHU:            /* DIAL MODEM-HANGUP */
  4735.     return(seton(&dialmhu));
  4736. #endif /* MDMHUP */
  4737.  
  4738. #ifndef NOSPL
  4739.       case XYDDIR:            /* DIAL DIRECTORY (zero or more) */
  4740.     return(parsdir(0));        /* 0 means DIAL */
  4741. #endif /* NOSPL */
  4742.  
  4743.       case XYDSTR:            /* DIAL STRING */
  4744.     if ((y = cmkey(mdmcmd,nmdmcmd,"","",xxstring)) < 0) return(y);
  4745.     switch (y) {
  4746.       case XYDS_AN:            /* Autoanswer ON/OFF */
  4747.       case XYDS_DC:            /* Data compression ON/OFF */
  4748.       case XYDS_EC:            /* Error correction ON/OFF */
  4749.         if ((x = cmkey(onoff,2,"","on",xxstring)) < 0)
  4750.           return(x);
  4751.         sprintf(tmpbuf,"Modem's command to %sable %s", /* SAFE */
  4752.             x ? "en" : "dis",
  4753.             (y == XYDS_DC) ? "compression" :
  4754.             ((y == XYDS_EC) ? "error-correction" :
  4755.             "autoanswer")
  4756.             );
  4757.         if (x) {
  4758.         if (y == XYDS_DC)
  4759.           return(dialstr(&dialdcon,tmpbuf));
  4760.         else if (y == XYDS_EC)
  4761.           return(dialstr(&dialecon,tmpbuf));
  4762.         else
  4763.           return(dialstr(&dialaaon,tmpbuf));
  4764.         } else {
  4765.         if (y == XYDS_DC)
  4766.           return(dialstr(&dialdcoff,tmpbuf));
  4767.         else if (y == XYDS_EC)
  4768.           return(dialstr(&dialecoff,tmpbuf));
  4769.         else
  4770.           return(dialstr(&dialaaoff,tmpbuf));
  4771.         }
  4772.       case XYDS_HU:            /*    hangup command */
  4773.         return(dialstr(&dialhcmd,"Modem's hangup command"));
  4774.       case XYDS_HW:            /*    hwfc */
  4775.         return(dialstr(&dialhwfc,
  4776.                "Modem's command to enable hardware flow control"));
  4777.       case XYDS_IN:            /*    init */
  4778.         return(dialstr(&dialini,"Modem's initialization string"));
  4779.       case XYDS_NF:            /*    no flow control */
  4780.         return(dialstr(&dialnofc,
  4781.                "Modem's command to disable local flow control"));
  4782.       case XYDS_PX:            /*    prefix */
  4783.         return(dialstr(&dialnpr,"Telephone number prefix for dialing"));
  4784.       case XYDS_SW:            /*    swfc */
  4785.         return(dialstr(&dialswfc,
  4786.            "Modem's command to enable local software flow control"));
  4787.       case XYDS_DT:            /*    tone dialing */
  4788.         return(dialstr(&dialtone,
  4789.            "Command to configure modem for tone dialing"));
  4790.       case XYDS_DP:            /*    pulse dialing */
  4791.         return(dialstr(&dialpulse,
  4792.                "Command to configure modem for pulse dialing"));
  4793.       case XYDS_MS:            /*    dial mode string */
  4794.         return(dialstr(&dialmstr,
  4795.                          "Command to enter dial mode"));
  4796.       case XYDS_MP:            /*    dial mode prompt */
  4797.         return(dialstr(&dialmprmt,
  4798.                "Modem response upon entering dial mode"));
  4799.       case XYDS_SP:            /* SPEAKER OFF */
  4800.         if ((x = cmkey(onoff,2,"","on",xxstring)) < 0) return(x);
  4801.         if (x)
  4802.           return(dialstr(&dialspon,"Command to turn modem speaker on"));
  4803.         else
  4804.           return(dialstr(&dialspoff,"Command to turn modem speaker off"));
  4805.  
  4806.       case XYDS_VO:            /* VOLUME LOW */
  4807.         if ((x = cmkey(voltab,3,"","medium",xxstring)) < 0) return(x);
  4808.         switch (x) {
  4809.           case 0:
  4810.           case 1:
  4811.         return(dialstr(&dialvol1,
  4812.                    "Command for low modem speaker volume"));
  4813.           case 2:
  4814.         return(dialstr(&dialvol2,
  4815.                "Command for medium modem speaker volume"));
  4816.  
  4817.           case 3:
  4818.         return(dialstr(&dialvol3,
  4819.                    "Command for high modem speaker volume"));
  4820.           default:
  4821.         return(-2);
  4822.         }
  4823.  
  4824.       case XYDS_ID:            /* IGNORE-DIALTONE */
  4825.         return(dialstr(&dialx3,
  4826.                "Command to tell modem to ignore dialtone"));
  4827.  
  4828.       case XYDS_I2:            /* PREDIAL-INIT */
  4829.         return(dialstr(&dialini2,
  4830.                "Command to send to modem just prior to dialing"));
  4831.  
  4832.       default:
  4833.         printf("?Unexpected SET DIAL STRING parameter\n");
  4834.     }
  4835.  
  4836.       case XYDFC:            /* DIAL FLOW-CONTROL */
  4837.     if ((y = cmkey(dial_fc,4,"","auto",xxstring)) < 0) return(y);
  4838.     if ((x = cmcfm()) < 0) return(x);
  4839.     dialfc = y;
  4840.     return(success = 1);
  4841.  
  4842.       case XYDMTH: {            /* DIAL METHOD */
  4843.         extern int dialmauto;
  4844.     if ((y = cmkey(dial_m,ndial_m,"","default",xxstring)) < 0)
  4845.       return(y);
  4846.     if ((x = cmcfm()) < 0)
  4847.       return(x);
  4848.     if (y == XYDM_A) {        /* AUTO */
  4849.         dialmauto = 1;        /* local country code, if known. */
  4850.         dialmth = XYDM_D;
  4851.     } else {
  4852.           dialmauto = 0;        /* use the method specified */
  4853.       dialmth = y;
  4854.         }
  4855.     return(success = 1);
  4856.       }
  4857.       case XYDRTM:
  4858.     y = cmnum("Number of times to try dialing a number",
  4859.           "1",10,&x,xxstring);
  4860.     return(setnum(&dialrtr,x,y,16383));
  4861.  
  4862.       case XYDINT:
  4863.     y = cmnum("Seconds to wait between redial attempts",
  4864.           "30",10,&x,xxstring);
  4865.     return(setnum(&dialint,x,y,128));
  4866.  
  4867.       case XYDLAC:            /* DIAL AREA-CODE */
  4868.     if ((x = dialstr(&diallac,"Area code you are calling from")) < 0)
  4869.       return(x);
  4870.     if (diallac) {
  4871.         if (!rdigits(diallac)) {
  4872.         printf("?Sorry, area code must be numeric\n");
  4873.         if (*diallac == '(')
  4874.           printf("(please omit the parentheses)\n");
  4875.         if (*diallac == '/')
  4876.           printf("(no slashes, please)\n");
  4877.         if (diallac) free(diallac);
  4878.         diallac = NULL;
  4879.         return(-9);
  4880.         }
  4881.     }
  4882.     return(x);
  4883.  
  4884.       case XYDCNF:            /* CONFIRMATION */
  4885.     return(success = seton(&dialcnf));
  4886.  
  4887.       case XYDCVT:            /* CONVERT-DIRECTORY */
  4888.     if ((y = cmkey(dcnvtab,3,"","ask",xxstring)) < 0)
  4889.       return(y);
  4890.     if ((x = cmcfm()) < 0)
  4891.       return(x);
  4892.     dialcvt = y;
  4893.     return(success = 1);
  4894.  
  4895.       case XYDLCC:            /* DIAL COUNTRY-CODE */
  4896.     x = dialstr(&diallcc,"Country code you are calling from");
  4897.     if (x < 1) return(x);
  4898.     if (diallcc) {
  4899.         if (!rdigits(diallcc)) {
  4900.         printf("?Sorry, country code must be numeric\n");
  4901.         if (*diallcc == '+')
  4902.           printf("(please omit the plus sign)\n");
  4903.         if (diallcc) free(diallcc);
  4904.         diallcc = NULL;
  4905.         return(-9);
  4906.         }
  4907.         if (!strcmp(diallcc,"1")) {    /* Set defaults for USA and Canada */
  4908.         if (!dialldp)        /* Long-distance prefix */
  4909.           makestr(&dialldp,"1");
  4910.         if (!dialixp)         /* International dialing prefix */
  4911.           makestr(&dialixp,"011");
  4912.         if (ntollfree == 0) {    /* Toll-free area codes */
  4913.             if ((dialtfc[0] = malloc(4))) {
  4914.             strcpy(dialtfc[0],"800"); /* 1970-something */
  4915.             ntollfree++;
  4916.             if ((dialtfc[1] = malloc(4))) {
  4917.                 strcpy(dialtfc[1],"888"); /* 1996 */
  4918.                 ntollfree++;
  4919.                 if ((dialtfc[2] = malloc(4))) {
  4920.                 strcpy(dialtfc[2],"877"); /* 5 April 1998 */
  4921.                 ntollfree++;
  4922.                 if ((dialtfc[3] = malloc(4))) {
  4923.                     strcpy(dialtfc[3],"866"); /* 2000? */
  4924.                     ntollfree++;
  4925.                 }
  4926.                 }
  4927.             }
  4928.             }
  4929.         }
  4930.         if (!dialtfp)         /* Toll-free dialing prefix */
  4931.           makestr(&dialtfp,"1");
  4932. #ifdef COMMENT
  4933. /* The time for this is past */
  4934.         } else if (!strcmp(diallcc,"358") &&
  4935.                ((int) strcmp(zzndate(),"19961011") > 0)
  4936.                ) {        /* Finland */
  4937.         if (!dialldp)        /* Long-distance prefix */
  4938.           makestr(&dialldp,"9");
  4939.         if (!dialixp)         /* International dialing prefix */
  4940.           makestr(&dialixp,"990");
  4941. #endif /* COMMENT */
  4942.         } else {            /* Everywhere else ... */
  4943.         if (!dialldp) {
  4944.             if ((dialldp = malloc(4)))
  4945.               strcpy(dialldp,"0");
  4946.         }
  4947.         if (!dialixp) {
  4948.             if ((dialixp = malloc(4)))
  4949.               strcpy(dialixp,"00");
  4950.         }
  4951.         }
  4952.         if (!strcmp(diallcc,"33"))    /* France */
  4953.           dialfld = 1;        /* Long-distance dialing is forced */
  4954.     }
  4955.     return(success = 1);
  4956.  
  4957.       case XYDIXP:            /* DIAL INTL-PREFIX */
  4958.     return(dialstr(&dialixp,"International dialing prefix"));
  4959.  
  4960.       case XYDIXS:            /* DIAL INTL-SUFFIX */
  4961.     return(dialstr(&dialixs,"International dialing suffix"));
  4962.  
  4963.       case XYDLDP:            /* DIAL LD-PREFIX */
  4964.     return(dialstr(&dialldp,"Long-distance dialing prefix"));
  4965.  
  4966.       case XYDLDS:            /* DIAL LD-SUFFIX */
  4967.     return(dialstr(&diallds,"Long-distance dialing suffix"));
  4968.  
  4969.       case XYDLCP:            /* DIAL LC-PREFIX */
  4970.     return(dialstr(&diallcp,"Local dialing prefix"));
  4971.  
  4972.       case XYDLCS:            /* DIAL LC-SUFFIX */
  4973.     return(dialstr(&diallcs,"Local dialing suffix"));
  4974.  
  4975. #ifdef COMMENT
  4976.       case XYDPXX:            /* DIAL PBX-EXCHANGE */
  4977.     return(dialstr(&dialpxx,"Exchange of PBX you are calling from"));
  4978. #endif /* COMMENT */
  4979.  
  4980.       case XYDPXI: {            /* DIAL PBX-INTERNAL-PREFIX */
  4981. #ifdef COMMENT
  4982.       return(dialstr(&dialpxi,
  4983.                "Internal-call prefix of PBX you are calling from"));
  4984. #else
  4985.       int x;
  4986.       if ((x = cmtxt("Internal-call prefix of PBX you are calling from",
  4987.              "",&s,NULL)) < 0) /* Don't evaluate */
  4988.         return(x);
  4989. #ifndef NOSPL
  4990.       if (*s) {
  4991.           char c, * p = tmpbuf;
  4992.           if (*s == '\\') {
  4993.           c = *(s+1);
  4994.           if (isupper(c)) c = tolower(c);
  4995.           if (c != 'f' &&
  4996.               ckstrcmp(s,"\\v(d$px)",8,0) &&
  4997.               ckstrcmp(s,"\\v(d$pxx)",9,0) &&
  4998.               ckstrcmp(s,"\\v(d$p)",7,0)) {
  4999.               x = TMPBUFSIZ;
  5000.               zzstring(s,&p,&x);
  5001.               s = tmpbuf;
  5002.           }
  5003.           }
  5004.       }
  5005. #endif /* NOSPL */
  5006.       makestr(&dialpxi,s);
  5007.       return(1);
  5008.       }
  5009. #endif /* COMMENT */
  5010.  
  5011.       case XYDPXO:            /* DIAL PBX-OUTSIDE-PREFIX */
  5012.     return(dialstr(&dialpxo,
  5013.                "Outside-line prefix of PBX you are calling from"));
  5014.  
  5015.       case XYDSFX:            /* DIAL INTL-SUFFIX */
  5016.     return(dialstr(&dialsfx," Telephone number suffix for dialing"));
  5017.  
  5018.       case XYDSRT:            /* DIAL SORT */
  5019.     return(success = seton(&dialsrt));
  5020.  
  5021.       case XYDPXX:            /* DIAL PBX-EXCHANGE */
  5022.       case XYDTFC: {            /* DIAL TOLL-FREE-AREA-CODE  */
  5023.       int n, i;            /* (zero or more of them...) */
  5024.       char * p[MAXTOLLFREE];    /* Temporary pointers */
  5025.       char * m;
  5026.       for (n = 0; n < MAXTOLLFREE; n++) {
  5027.           if (n == 0) {
  5028.           m = (y == XYDTFC) ?
  5029.           "Toll-free area code(s) in the country you are calling from"
  5030.             : "Exchange(s) of PBX you are calling from";
  5031.           } else {
  5032.           m = (y == XYDTFC) ?
  5033.             "Another toll-free area code"
  5034.               : "Another PBX exchange";
  5035.           }
  5036.           if ((x = cmfld(m,"",&s,xxstring)) < 0)
  5037.         break;
  5038.           if (s) {
  5039.           int k;
  5040.           k = (int) strlen(s);
  5041.           if (k > 0) {
  5042.               if ((p[n] = malloc(k + 1)))
  5043.             strcpy(p[n], s); /* safe */
  5044.           } else break;
  5045.           } else break;
  5046.       }
  5047.       if (x == -3) {        /* Command was successful */
  5048.           int m;
  5049.           m = (y == XYDTFC) ? ntollfree : ndialpxx;
  5050.           if ((x = cmcfm()) < 0)
  5051.         return(x);
  5052.           x = 1;
  5053.           for (i = 0; i < m; i++) { /* Remove old list, if any */
  5054.           if  (y == XYDTFC)
  5055.             makestr(&(dialtfc[i]),NULL);
  5056.           else
  5057.             makestr(&(dialpxx[i]),NULL);
  5058.           }
  5059.           if  (y == XYDTFC)
  5060.         ntollfree = n;        /* New count */
  5061.           else
  5062.         ndialpxx = n;
  5063.           for (i = 0; i < n; i++) { /* New list */
  5064.           if  (y == XYDTFC)
  5065.             makestr(&(dialtfc[i]),p[i]);
  5066.           else
  5067.             makestr(&(dialpxx[i]),p[i]);
  5068.           }
  5069.           x = 1;
  5070.       }
  5071.       for (i = 0; i < n; i++)
  5072.         if (p[i]) free(p[i]);
  5073.       return(x);
  5074.       }
  5075.  
  5076.       case XYDTFP:            /* TOLL-FREE-PREFIX */
  5077.     return(dialstr(&dialtfp,
  5078.                " Long-distance prefix for toll-free dialing"));
  5079.  
  5080.       case XYDCON:            /* CONNECT */
  5081.     z = -1;
  5082.     if ((y = cmkey(crrtab,ncrr,"","auto",xxstring)) < 0) return(y);
  5083.     if (y != CAR_OFF)        /* AUTO or ON? */
  5084.       if ((z = cmkey(qvtab,nqvt,"","verbose",xxstring)) < 0) return(z);
  5085.     if ((x = cmcfm()) < 0) return(x);
  5086.     if (z > -1)
  5087.       dialcq = z;
  5088.     dialcon = y;
  5089.     return(success = 1);
  5090.  
  5091.       case XYDRSTR:            /* RESTRICT */
  5092.     if ((y = cmkey(drstrtab,4,"","none",xxstring)) < 0) return(y);
  5093.     if ((x = cmcfm()) < 0) return(x);
  5094.     dialrstr = y;
  5095.     return(success = 1);
  5096.  
  5097.       case XYDLLAC: {            /* Local area-code list  */
  5098.       int n, i;            /* (zero or more of them...) */
  5099.       char * p[MAXLOCALAC];    /* Temporary pointers */
  5100.       for (n = 0; n < MAXLOCALAC; n++) {
  5101.           if ((x = cmfld(
  5102.             "Area code to which calls from your area are local",
  5103.                "",&s,xxstring)) < 0)
  5104.         break;
  5105.           if (s) {
  5106.           int k;
  5107.           k = (int) strlen(s);
  5108.           if (k > 0) {
  5109.               if ((p[n] = malloc(k + 1)))
  5110.             strcpy(p[n], s); /* safe */
  5111.           } else break;
  5112.           } else break;
  5113.       }
  5114.       if (x == -3) {        /* Command was successful */
  5115.           if ((x = cmcfm()) < 0)
  5116.         return(x);
  5117.           for (i = 0; i < nlocalac; i++) /* Remove old list, if any */
  5118.         if (diallcac[i]) {
  5119.             free(diallcac[i]);
  5120.             diallcac[i] = NULL;
  5121.         }
  5122.           nlocalac = n;        /* New count */
  5123.           for (i = 0; i < nlocalac; i++) /* New list */
  5124.         diallcac[i] = p[i];
  5125.           return(success = 1);
  5126.       } else {            /* Parse error, undo everything */
  5127.           for (i = 0; i < n; i++)
  5128.         if (p[i]) free(p[i]);
  5129.           return(x);
  5130.       }
  5131.       }
  5132.  
  5133.       case XYDFLD:
  5134.     return(success = seton(&dialfld));
  5135.  
  5136.       case XYDIDT:            /* DIAL IGNORE-DIALTONE */
  5137.     return(seton(&dialidt));
  5138.  
  5139.       case XYDPAC:
  5140.     y = cmnum(
  5141.           "Milliseconds to pause between each character sent to dialer",
  5142.           "",10,&x,xxstring);
  5143.     return(setnum(&dialpace,x,y,9999));
  5144.  
  5145. #ifndef NOSPL
  5146.       case XYDMAC:
  5147.     if ((x = cmfld("Name of macro to execute just prior to dialing",
  5148.                "",&s,xxstring)) < 0) {
  5149.         if (x == -3)
  5150.           s = NULL;
  5151.         else
  5152.           return(x);
  5153.     }
  5154.     if (s) {
  5155.         if (!*s) {
  5156.         s = NULL;
  5157.         } else {
  5158.         ckstrncpy(line,s,LINBUFSIZ);
  5159.         s = line;
  5160.         }
  5161.     }
  5162.     if ((x = cmcfm()) < 0)
  5163.       return(x);
  5164.     makestr(&dialmac,s);
  5165.     return(success = 1);
  5166. #endif /* NOSPL */
  5167.  
  5168.       case XYDPUCC:            /* Pulse country codes */
  5169.       case XYDTOCC: {            /* Tone country codes */
  5170.       int n, i;
  5171.       char * p[MAXTPCC];
  5172.       char * m;
  5173.       for (n = 0; n < MAXTPCC; n++) {
  5174.           if (n == 0) {
  5175.           m = (y == XYDPUCC) ?
  5176.           "Country code where Pulse dialing is required"
  5177.             : "Country code where Tone dialing is available";
  5178.           } else
  5179.         m = "Another country code";
  5180.           if ((x = cmfld(m,"",&s,xxstring)) < 0)
  5181.         break;
  5182.           if (s) {
  5183.           int k;
  5184.           k = (int) strlen(s);
  5185.           if (k > 0) {
  5186.               if ((p[n] = malloc(k + 1)))
  5187.             strcpy(p[n], s); /* safe */
  5188.           } else break;
  5189.           } else break;
  5190.       }
  5191.       if (x == -3) {        /* Command was successful */
  5192.           int m;
  5193.           m = (y == XYDPUCC) ? ndialpucc : ndialtocc;
  5194.           if ((x = cmcfm()) < 0)
  5195.         return(x);
  5196.           x = 1;
  5197.           for (i = 0; i < m; i++) { /* Remove old list, if any */
  5198.           if (y == XYDPUCC)
  5199.             makestr(&(dialpucc[i]),NULL);
  5200.           else
  5201.             makestr(&(dialtocc[i]),NULL);
  5202.           }
  5203.           if (y == XYDPUCC) {
  5204.           ndialpucc = n;        /* New count */
  5205.           } else {
  5206.           ndialtocc = n;
  5207.           }
  5208.           for (i = 0; i < n; i++) { /* New list */
  5209.           if (y == XYDPUCC) {
  5210.               makestr(&(dialpucc[i]),p[i]);
  5211.           } else {
  5212.               makestr(&(dialtocc[i]),p[i]);
  5213.           }
  5214.           }
  5215.           x = 1;
  5216.       }
  5217.       for (i = 0; i < n; i++)
  5218.         if (p[i]) free(p[i]);
  5219.       return(x);
  5220.       }
  5221.       case XYDTEST:
  5222.     return(seton(&dialtest));
  5223.  
  5224.       default:
  5225.     printf("?Unexpected SET DIAL parameter\n");
  5226.     return(-9);
  5227.     }
  5228. }
  5229.  
  5230. #ifdef CK_TAPI
  5231. int                        /* TAPI action commands */
  5232. dotapi() {
  5233.     int x,y;
  5234.     char *s;
  5235.  
  5236.     if (!TAPIAvail) {
  5237.     printf("\nTAPI is unavailable on this system.\n");
  5238.     return(-9);
  5239.     }
  5240.     if ((y = cmkey(tapitab,ntapitab,"MS TAPI command","",xxstring)) < 0)
  5241.       return(y);
  5242.     switch (y) {
  5243.       case XYTAPI_CFG: {            /* TAPI CONFIGURE-LINE */
  5244.       extern struct keytab * tapilinetab;
  5245.       extern struct keytab * _tapilinetab;
  5246.       extern int ntapiline;
  5247.       extern int LineDeviceId;
  5248.       int lineID=LineDeviceId;
  5249.       if (TAPIAvail)
  5250.         cktapiBuildLineTable(&tapilinetab, &_tapilinetab, &ntapiline);
  5251.       if (tapilinetab && _tapilinetab && ntapiline > 0) {
  5252.           int i=0, j = 9999, k = -1;
  5253.  
  5254.           if ( LineDeviceId == -1 ) {
  5255.           /* Find out what the lowest numbered TAPI device is */
  5256.           /* and use it as the default.                       */
  5257.           for (i = 0; i < ntapiline; i++ ) {
  5258.               if (tapilinetab[i].kwval < j) {
  5259.               k = i;
  5260.               }
  5261.           }
  5262.           } else {
  5263.           /* Find the LineDeviceId in the table and use that entry */
  5264.           for (i = 0; i < ntapiline; i++ ) {
  5265.               if (tapilinetab[i].kwval == LineDeviceId) {
  5266.               k = i;
  5267.               break;
  5268.               }
  5269.           }
  5270.           }
  5271.           if (k >= 0)
  5272.         s = _tapilinetab[k].kwd;
  5273.           else
  5274.         s = "";
  5275.  
  5276.           if ((y = cmkey(_tapilinetab,ntapiline,
  5277.                   "TAPI device name",s,xxstring)) < 0)
  5278.         return(y);
  5279.           lineID = y;
  5280.       }
  5281.       if ((x = cmcfm()) < 0) return(x);
  5282. #ifdef IKSD
  5283.           if (inserver) {
  5284.               printf("Sorry, command disabled\r\n");
  5285.               return(success = 0);
  5286.           }
  5287. #endif /* ISKD */
  5288.       cktapiConfigureLine(lineID);
  5289.       break;
  5290.       }
  5291.       case XYTAPI_DIAL:            /* TAPI DIALING-PROPERTIES */
  5292.     if ((x = cmcfm()) < 0)
  5293.       return(x);
  5294. #ifdef IKSD
  5295.     if (inserver) {
  5296.         printf("Sorry, command disabled\r\n");
  5297.         return(success = 0);
  5298.     }
  5299. #endif /* ISKD */
  5300.     cktapiDialingProp();
  5301.     break;
  5302.     }
  5303.     return(success = 1);
  5304. }
  5305.  
  5306. static int                /* SET TAPI command options */
  5307. settapi() {
  5308.     int x, y;
  5309.     char *s;
  5310.  
  5311.     if (!TAPIAvail) {
  5312.     printf("\nTAPI is unavailable on this system.\n");
  5313.     return(-9);
  5314.     }
  5315.     if ((y = cmkey(settapitab,nsettapitab,"MS TAPI option","",xxstring)) < 0)
  5316.       return(y);
  5317.     switch (y) {
  5318.       case XYTAPI_USE:
  5319.     return (success = seton(&tapiusecfg));
  5320.       case XYTAPI_LGHT:
  5321.     return (success = seton(&tapilights));
  5322.       case XYTAPI_PRE:
  5323.     return (success = seton(&tapipreterm));
  5324.       case XYTAPI_PST:
  5325.     return (success = seton(&tapipostterm));
  5326.       case XYTAPI_INA:
  5327.     y = cmnum("seconds of inactivity before auto-disconnect",
  5328.           "0",10,&x,xxstring);
  5329.     return(setnum(&tapiinactivity,x,y,65535));
  5330.       case XYTAPI_BNG:
  5331.     y = cmnum("seconds to wait for credit card tone",
  5332.           "8",10,&x,xxstring);
  5333.     return(setnum(&tapibong,x,y,90));
  5334.       case XYTAPI_MAN:
  5335.     return (success = seton(&tapimanual));
  5336.       case XYTAPI_CON:            /* TAPI CONVERSIONS */
  5337.     return (success = setonaut(&tapiconv));
  5338.       case XYTAPI_LIN:            /* TAPI LINE */
  5339.     x = setlin(XYTAPI_LIN,1,0);
  5340.     if (x > -1) didsetlin++;
  5341.     return(x);
  5342.       case XYTAPI_PASS:    {        /* TAPI PASSTHROUGH */
  5343.         /* Passthrough became Modem-dialing which is an antonym */
  5344.         success = seton(&tapipass);
  5345.         tapipass = !tapipass;
  5346.     return (success);
  5347.       }
  5348.       case XYTAPI_LOC: {        /* TAPI LOCATION */
  5349.       extern char tapiloc[];
  5350.       extern int tapilocid;
  5351.       int i = 0, j = 9999, k = -1;
  5352.  
  5353.       cktapiBuildLocationTable(&tapiloctab, &ntapiloc);
  5354.       if (!tapiloctab || !ntapiloc) {
  5355.           printf("\nNo TAPI Locations are configured for this system\n");
  5356.           return(-9);
  5357.       }
  5358.       if (tapilocid == -1)
  5359.         tapilocid = cktapiGetCurrentLocationID();
  5360.  
  5361.       /* Find the current tapiloc entry */
  5362.       /* and use it as the default. */
  5363.       for (k = 0; k < ntapiloc; k++) {
  5364.           if (tapiloctab[k].kwval == tapilocid)
  5365.         break;
  5366.       }
  5367.           if (k >= 0 && k < ntapiloc)
  5368.         s = tapiloctab[k].kwd;
  5369.       else
  5370.         s = "";
  5371.  
  5372.       if ((y = cmkey(tapiloctab,ntapiloc, "TAPI location",s,xxstring)) < 0)
  5373.         return(y);
  5374.  
  5375.       if ((x = cmcfm()) < 0)
  5376.         return(x);
  5377. #ifdef IKSD
  5378.           if (inserver) {
  5379.               printf("Sorry, command disabled\r\n");
  5380.               return(success = 0);
  5381.           }
  5382. #endif /* ISKD */
  5383.       cktapiFetchLocationInfoByID( y );
  5384.       CopyTapiLocationInfoToKermitDialCmd();
  5385.         }
  5386.     break;
  5387.     }
  5388.     return(success=1);
  5389. }
  5390. #endif /* CK_TAPI */
  5391.  
  5392. #ifndef NOSHOW
  5393. int                    /* SHOW MODEM */
  5394. shomodem() {
  5395.     MDMINF * p;
  5396.     int x, n, mdm;
  5397.     char c;
  5398.     long zz;
  5399.  
  5400. #ifdef IKSD
  5401.     if (inserver) {
  5402.         printf("Sorry, command disabled\r\n");
  5403.         return(success = 0);
  5404.     }
  5405. #endif /* IKSD */
  5406.  
  5407.     shmdmlin();
  5408.     printf("\n");
  5409.  
  5410.     mdm = (mdmtyp > 0) ? mdmtyp : mdmsav;
  5411.     p = (mdm > 0) ? modemp[mdm] : NULL;
  5412.  
  5413.     if (p) {
  5414.     printf(" %s\n\n", dialname ? dialname : p->name);
  5415.  
  5416.     printf(" Modem capabilities:    ");
  5417.     zz = dialcapas ? dialcapas : p->capas;
  5418.     if (!zz) {
  5419.         printf(" (none)");
  5420.     } else {
  5421.         if (zz & CKD_AT) printf(" AT");
  5422.         if (zz & CKD_V25) printf(" ITU");
  5423.         if (zz & CKD_SB) printf(" SB");
  5424.         if (zz & CKD_EC) printf(" EC");
  5425.         if (zz & CKD_DC) printf(" DC");
  5426.         if (zz & CKD_HW) printf(" HWFC");
  5427.         if (zz & CKD_SW) printf(" SWFC");
  5428.         if (zz & CKD_KS) printf(" KS");
  5429.         if (zz & CKD_TB) printf(" TB");
  5430.     }
  5431.     printf("\n Modem carrier-watch:    ");
  5432.     if (carrier == CAR_OFF) printf("off\n");
  5433.     else if (carrier == CAR_ON) printf("on\n");
  5434.     else if (carrier == CAR_AUT) printf("auto\n");
  5435.     else printf("unknown\n");
  5436.  
  5437.     printf(" Modem maximum-speed:    ");
  5438.     zz = (dialmax > 0L) ? dialmax : p->max_speed;
  5439.     if (zz > 0)
  5440.       printf("%ld bps\n", zz);
  5441.     else
  5442.       printf("(unknown)\n");
  5443.     printf(" Modem error-correction: %s\n", dialec ? "on" : "off");
  5444.     printf(" Modem compression:      %s\n", dialdc ? "on" : "off");
  5445.     printf(" Modem speed-matching:   %s",   mdmspd ? "on" : "off");
  5446.     printf(" (interface speed %s)\n", mdmspd ? "changes" : "is locked");
  5447.     printf(" Modem flow-control:     ");
  5448.     if (dialfc == FLO_NONE) printf("none\n");
  5449.         else if (dialfc == FLO_XONX) printf("xon/xoff\n");
  5450.     else if (dialfc == FLO_RTSC) printf("rts/cts\n");
  5451.     else if (dialfc == FLO_AUTO) printf("auto\n");
  5452.     printf(" Modem hangup-method:    %s\n",
  5453.            dialmhu ?
  5454.            "modem-command" :
  5455.            "rs232-signal"
  5456.            );
  5457.     printf(" Modem speaker:          %s\n", showoff(mdmspk));
  5458.     printf(" Modem volume:           %s\n",
  5459.            (mdmvol == 2) ? "medium" : ((mdmvol <= 1) ? "low" : "high"));
  5460.     printf(" Modem kermit-spoof:     %s\n", dialksp ? "on" : "off");
  5461.     c = (char) (x = (dialesc ? dialesc : p->esc_char));
  5462.     printf(" Modem escape-character: %d", x);
  5463.     if (isprint(c))
  5464.       printf(" (= \"%c\")",c);
  5465.     printf(
  5466. "\n\nMODEM COMMANDs (* = set automatically by SET MODEM TYPE):\n\n");
  5467.     debug(F110,"show dialini",dialini,0);
  5468.     printf(" %c Init-string:          ", dialini ? ' ' : '*' );
  5469.     shods(dialini ? dialini : p->wake_str);
  5470.     printf(" %c Dial-mode-string:     ", dialmstr ? ' ' : '*' );
  5471.     shods(dialmstr ? dialmstr : p->dmode_str);
  5472.     n = local ? 19 : 20;
  5473.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5474.     printf(" %c Dial-mode-prompt:     ", dialmprmt ? ' ' : '*' );
  5475.     shods(dialmprmt ? dialmprmt : p->dmode_prompt);
  5476.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5477.     printf(" %c Dial-command:         ", dialcmd ? ' ' : '*' );
  5478.     shods(dialcmd ? dialcmd : p->dial_str);
  5479.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5480.     printf(" %c Compression on:       ", dialdcon ? ' ' : '*' );
  5481.     if (!dialdcon)
  5482.       debug(F110,"dialdcon","(null)",0);
  5483.     else
  5484.       debug(F110,"dialdcon",dialdcon,0);
  5485.     shods(dialdcon ? dialdcon : p->dc_on_str);
  5486.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5487.     printf(" %c Compression off:      ", dialdcoff ? ' ' : '*' );
  5488.     shods(dialdcoff ? dialdcoff : p->dc_off_str);
  5489.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5490.     printf(" %c Error-correction on:  ", dialecon ? ' ' : '*' );
  5491.     shods(dialecon ? dialecon : p->ec_on_str);
  5492.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5493.     printf(" %c Error-correction off: ", dialecoff ? ' ' : '*' );
  5494.     shods(dialecoff ? dialecoff : p->ec_off_str);
  5495.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5496.     printf(" %c Autoanswer on:        ", dialaaon ? ' ' : '*' );
  5497.     shods(dialaaon ? dialaaon : p->aa_on_str);
  5498.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5499.     printf(" %c Autoanswer off:       ", dialaaoff ? ' ' : '*' );
  5500.     shods(dialaaoff ? dialaaoff : p->aa_off_str);
  5501.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5502.  
  5503.     printf(" %c Speaker on:           ", dialspon ? ' ' : '*' );
  5504.     shods(dialspon ? dialspon : p->sp_on_str);
  5505.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5506.     printf(" %c Speaker off:          ", dialspoff ? ' ' : '*' );
  5507.     shods(dialspoff ? dialspoff : p->sp_off_str);
  5508.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5509.     printf(" %c Volume low:           ", dialvol1 ? ' ' : '*' );
  5510.     shods(dialvol1 ? dialvol1 : p->vol1_str);
  5511.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5512.     printf(" %c Volume medium:        ", dialvol2 ? ' ' : '*' );
  5513.     shods(dialvol2 ? dialvol2 : p->vol2_str);
  5514.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5515.     printf(" %c Volume high:          ", dialvol3 ? ' ' : '*' );
  5516.     shods(dialvol3 ? dialvol3 : p->vol3_str);
  5517.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5518.  
  5519.     printf(" %c Hangup-command:       ", dialhcmd ? ' ' : '*' );
  5520.     shods(dialhcmd ? dialhcmd : p->hup_str);
  5521.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5522.     printf(" %c Hardware-flow:        ", dialhwfc ? ' ' : '*' );
  5523.     shods(dialhwfc ? dialhwfc : p->hwfc_str);
  5524.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5525.     printf(" %c Software-flow:        ", dialswfc ? ' ' : '*' );
  5526.     shods(dialswfc ? dialswfc : p->swfc_str);
  5527.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5528.     printf(" %c No-flow-control:      ", dialnofc ? ' ' : '*' );
  5529.     shods(dialnofc ? dialnofc : p->nofc_str);
  5530.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5531.     printf(" %c Pulse:                ", dialpulse ? ' ' : '*');
  5532.     shods(dialpulse ? dialpulse : p->pulse);
  5533.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5534.     printf(" %c Tone:                 ", dialtone ? ' ' : '*');
  5535.     shods(dialtone ? dialtone : p->tone);
  5536.  
  5537.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5538.     printf(" %c Ignore-dialtone:      ", dialx3 ? ' ' : '*');
  5539.     shods(dialx3 ? dialx3 : p->ignoredt);
  5540.  
  5541.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5542.     printf(" %c Predial-init:         ", dialini2 ? ' ' : '*');
  5543.     shods(dialini2 ? dialini2 : p->ini2);
  5544.  
  5545.     if (++n > cmd_rows - 4) if (!askmore()) return(0); else n = 0;
  5546.     printf("\n For more info: SHOW DIAL and SHOW COMMUNICATIONS\n");
  5547.  
  5548.     } else if (mdm > 0) {
  5549.     printf("Modem info for \"%s\" not filled in yet\n", gmdmtyp());
  5550.     } else printf(
  5551. " No modem selected, so DIAL and most SET MODEM commands have no effect.\n\
  5552.  Use SET MODEM TYPE to select a modem.\n");
  5553.     return(success = 1);
  5554. }
  5555. #endif /* NOSHOW */
  5556. #endif /* NODIAL */
  5557. #endif /* NOLOCAL */
  5558.  
  5559. #ifndef NOSPL
  5560. #ifdef CK_ANSIC                /* SET ALARM */
  5561. int
  5562. setalarm(long xx)
  5563. #else
  5564. int
  5565. setalarm(xx) long xx;
  5566. #endif /* CK_ANSIC */
  5567. /* setalarm */ {
  5568. #ifdef COMMENT
  5569.     int yyyy, mm, dd, x;
  5570.     char *s;
  5571.     long zz;
  5572.     char buf[6];
  5573. #endif /* COMMENT */
  5574.     long sec, jd;
  5575.     char xbuf[20], * p;
  5576.  
  5577.     debug(F101,"setalarm xx","",xx);
  5578.     ck_alarm = 0L;            /* 0 = no alarm (in case of error) */
  5579.     if (xx < 0L) {
  5580.     printf("%ld - illegal value, must be 0 or positive\n", xx);
  5581.     return(-9);
  5582.     }
  5583.     if (xx == 0L) {            /* CLEAR ALARM */
  5584.     alrm_date[0] = NUL;
  5585.     alrm_time[0] = NUL;
  5586.     return(1);
  5587.     }
  5588. #ifdef COMMENT
  5589.     x = 8;                /* Get current date */
  5590.     s = alrm_date;
  5591.     if (zzstring("\\v(ndate)",&s,&x) < 0) {
  5592.     printf("Internal date error, sorry.\n");
  5593.     alrm_date[0] = SP;
  5594.     return(-9);
  5595.     }
  5596.     x = 5;                /* Get current time */
  5597.     s = alrm_time;
  5598.     if (zzstring("\\v(ntime)",&s,&x) < 0) {
  5599.     printf("Internal time error, sorry.\n");
  5600.     alrm_time[0] = SP;
  5601.     return(-9);
  5602.     }
  5603.     sprintf(buf,"%05ld",atol(alrm_time)); /* SAFE (20) */
  5604.     ckstrncpy(alrm_time,buf,8);
  5605.     debug(F110,"SET ALARM date (1)",alrm_date,0);
  5606.     debug(F110,"SET ALARM time (1)",alrm_time,0);
  5607.  
  5608.     if ((zz = atol(alrm_time) + xx) < 0L) {
  5609.     printf("Internal time conversion error, sorry.\n");
  5610.     return(-9);
  5611.     }
  5612.     if (zz >= 86400L) {            /* Alarm crosses midnight */
  5613.     char d[10];            /* Local date buffer */
  5614.     int lastday;            /* Last day of this month */
  5615.  
  5616.     ckstrncpy(d,alrm_date,8);    /* We'll have to change the date */
  5617.  
  5618.     x = (zz / 86400L);        /* How many days after today */
  5619.  
  5620.     dd = atoi((char *)(d+6));    /* Parse yyyymmdd */
  5621.     d[6] = NUL;            /* into yyyy, mm, dd ... */
  5622.     mm = atoi((char *)(d+4));
  5623.     d[4] = NUL;
  5624.     yyyy = atoi((char *)d);
  5625.  
  5626.     /* How many days in this month */
  5627.  
  5628.     lastday = mdays[mm];
  5629.     if (mm == 2 && yyyy % 4 == 0)    /* Works thru 2099 AD... */
  5630.       lastday++;
  5631.  
  5632.     if (dd + x > lastday) {        /* Dumb loop */
  5633.         int y;
  5634.  
  5635.         x -= (mdays[mm] - dd);    /* Deduct rest of this month's days */
  5636.  
  5637.         /* There's a more elegant way to do this... */
  5638.  
  5639.         while (1) {
  5640.         mm++;            /* Next month */
  5641.         if (mm > 12) {        /* Wrap around */
  5642.             mm = 1;        /* Jan, next year */
  5643.             yyyy++;
  5644.         }
  5645.         y = mdays[mm];        /* Days in new month */
  5646.         if (mm == 2 && yyyy % 4 == 0) /* Feb in leap year */
  5647.           y++;            /* Works until 2100 AD */
  5648.         if (x - y < 1)
  5649.           break;
  5650.         x -= y;
  5651.         }
  5652.         dd = x;            /* Day of alarm month */
  5653.     } else dd += x;
  5654.  
  5655.     sprintf(alrm_date,"%04d%02d%02d",yyyy,mm,dd); /* SAFE (24) */
  5656.     zz = zz % 86400L;
  5657.     }
  5658.     sprintf(alrm_time,"%ld",zz);    /* SAFE (24) */
  5659.     debug(F110,"SET ALARM date (2)",alrm_date,0);
  5660.     debug(F110,"SET ALARM time (2)",alrm_time,0);
  5661.     ck_alarm = xx;
  5662. #else
  5663.     /* Jul 1998 */
  5664.     ckstrncpy(xbuf,ckcvtdate("",1),20);    /* Get current date and time */
  5665.     p = xbuf;
  5666.     ckstrncpy(alrm_date,xbuf,10);
  5667.     alrm_date[8] = NUL;
  5668.     sec = atol(p+9) * 3600L + atol(p+12) * 60L + atol(p+15);
  5669.     debug(F110,"SET ALARM date (1)",alrm_date,0);
  5670.     debug(F101,"SET ALARM time (1)","",sec);
  5671.     if ((sec += xx) < 0L) {
  5672.     printf("Internal time conversion error, sorry.\n");
  5673.     return(-9);
  5674.     }
  5675.     if (sec >= 86400L) {        /* Alarm crosses midnight */
  5676.     long days;
  5677.     days = sec / 86400L;
  5678.     jd = mjd(p) + days;        /* Get modified Julian date */
  5679.     ckstrncpy(alrm_date,mjd2date(jd),10);
  5680.     sec %= 86400L;
  5681.     }
  5682.     sprintf(alrm_time,"%05ld",sec);    /* SAFE (24) */
  5683.     debug(F110,"SET ALARM date (2)",alrm_date,0);
  5684.     debug(F110,"SET ALARM time (2)",alrm_time,0);
  5685.     ck_alarm = 1;            /* Alarm is set */
  5686.  
  5687. #endif /* COMMENT */
  5688.     return(success = 1);
  5689. }
  5690. #endif /* NOSPL */
  5691.  
  5692. #ifndef NOSETKEY
  5693. int
  5694. dosetkey() {                /* SET KEY */
  5695.     int x, y;
  5696.     int flag = 0;
  5697.     int kc;                /* Key code */
  5698.     char *s;                /* Key binding */
  5699. #ifndef NOKVERBS
  5700.     char *p;                /* Worker */
  5701. #endif /* NOKVERBS */
  5702. #ifdef OS2
  5703.     extern int os2gks;
  5704.     extern int mskkeys;
  5705.     extern int initvik;
  5706. #endif /* OS2 */
  5707.  
  5708.     x_ifnum = 1;
  5709.     y = cmnum("numeric key code, or the word CLEAR,","",10,&kc,xxstring);
  5710.     x_ifnum = 0;
  5711.     if (y < 0) {
  5712.     debug(F111,"SET KEY",atmbuf,y);
  5713.     if (y == -2) {            /* Not a valid number */
  5714.         if ((y = strlen(atmbuf)) < 0) /* Check for SET KEY CLEAR */
  5715.           return(-2);
  5716.         if (ckstrcmp(atmbuf,"clear",y,0))
  5717.           return(-2);
  5718.         if ((x = cmcfm()) < 0)
  5719.           return(x);
  5720.         for (y = 0; y < KMSIZE; y++) {
  5721.         keymap[y] = (KEY) y;
  5722.         macrotab[y] = NULL;
  5723.         }
  5724. #ifdef OS2
  5725.         keymapinit();        /* Special OS/2 initializations */
  5726.         initvik = 1;        /* Update the VIK table */
  5727. #endif /* OS2 */
  5728.         return(1);
  5729.     } else if (y == -3) {        /* SET KEY <Return> */
  5730.         printf(" Press key to be defined: "); /* Prompt for a keystroke */
  5731. #ifdef UNIX
  5732. #ifdef NOSETBUF
  5733.         fflush(stdout);
  5734. #endif /* NOSETBUF */
  5735. #endif /* UNIX */
  5736.         conbin((char)escape);    /* Put terminal in binary mode */
  5737. #ifdef OS2
  5738.         os2gks = 0;            /* Turn off Kverb preprocessing */
  5739. #endif /* OS2 */
  5740.         kc = congks(0);        /* Get character or scan code */
  5741. #ifdef OS2
  5742.         os2gks = 1;            /* Turn on Kverb preprocessing */
  5743. #endif /* OS2 */
  5744.         concb((char)escape);    /* Restore terminal to cbreak mode */
  5745.         if (kc < 0) {        /* Check for error */
  5746.         printf("?Error reading key\n");
  5747.         return(0);
  5748.         }
  5749. #ifdef OS2
  5750.         shokeycode(kc,-1);        /* Show current definition */
  5751. #else
  5752.         shokeycode(kc);        /* Show current definition */
  5753. #endif /* OS2 */
  5754.         flag = 1;            /* Remember it's a multiline command */
  5755.     } else                /* Error */
  5756.       return(y);
  5757.     }
  5758.  
  5759.     /* Normal SET KEY <scancode> <value> command... */
  5760.  
  5761. #ifdef OS2
  5762.     if (mskkeys)
  5763.       kc = msktock(kc);
  5764. #endif /* OS2 */
  5765.  
  5766.     if (kc < 0 || kc >= KMSIZE) {
  5767.     printf("?key code must be between 0 and %d\n", KMSIZE - 1);
  5768.     return(-9);
  5769.     }
  5770.     if (kc == escape) {
  5771.     printf("Sorry, %d is the CONNECT-mode escape character\n",kc);
  5772.     return(-9);
  5773.     }
  5774. #ifdef OS2
  5775.     wideresult = -1;
  5776. #endif /* OS2 */
  5777.     if (flag) {
  5778.     cmsavp(psave,PROMPTL);
  5779.     cmsetp(" Enter new definition: ");
  5780.     cmini(ckxech);
  5781.     cmflgs = 0;
  5782.     prompt(NULL);
  5783.     }
  5784.   def_again:
  5785.     if (flag)
  5786.       cmres();
  5787.     if ((y = cmtxt("key definition,\n\
  5788. or Ctrl-C to cancel this command,\n\
  5789. or Enter to restore default definition",
  5790.            "",&s,NULL)) < 0) {
  5791.     if (flag)            /* Handle parse errors */
  5792.       goto def_again;
  5793.     else
  5794.       return(y);
  5795.     }
  5796.     s = brstrip(s);
  5797. #ifndef NOKVERBS
  5798.     p = s;                /* Save this place */
  5799. #endif /* NOKVERBS */
  5800. /*
  5801.   If the definition included any \Kverbs, quote the backslash so the \Kverb
  5802.   will still be in the definition when the key is pressed.  We don't do this
  5803.   in zzstring(), because \Kverbs are valid only in this context and nowhere
  5804.   else.
  5805.  
  5806.   We use this code active for all versions that support SET KEY, even if they
  5807.   don't support \Kverbs, because otherwise \K would behave differently for
  5808.   different versions.
  5809. */
  5810.     for (x = 0, y = 0; s[x]; x++, y++) { /* Convert \K to \\K */
  5811.     if ((x > 0) &&
  5812.         (s[x] == 'K' || s[x] == 'k')
  5813.         ) {                /* Have K */
  5814.  
  5815.         if ((x == 1 && s[x-1] == CMDQ) ||
  5816.         (x > 1 && s[x-1] == CMDQ && s[x-2] != CMDQ)) {
  5817.         line[y++] = CMDQ;    /* Make it \\K */
  5818.         }
  5819.         if (x > 1 && s[x-1] == '{' && s[x-2] == CMDQ) {
  5820.           line[y-1] = CMDQ;    /* Have \{K */
  5821.           line[y++] = '{';    /* Make it \\{K */
  5822.         }
  5823.     }
  5824.     line[y] = s[x];
  5825.     }
  5826.     line[y++] = NUL;            /* Terminate */
  5827.     s = line + y + 1;            /* Point to after it */
  5828.     x = LINBUFSIZ - (int) strlen(line) - 1; /* Calculate remaining space */
  5829.     if ((x < (LINBUFSIZ / 2)) ||
  5830.     (zzstring(line, &s, &x) < 0)) { /* Expand variables, etc. */
  5831.     printf("?Key definition too long\n");
  5832.     if (flag) cmsetp(psave);
  5833.     return(-9);
  5834.     }
  5835.     s = line + y + 1;            /* Point to result. */
  5836.  
  5837. #ifndef NOKVERBS
  5838. /*
  5839.   Special case: see if the definition starts with a \Kverb.
  5840.   If it does, point to it with p, otherwise set p to NULL.
  5841. */
  5842.     p = s;
  5843.     if (*p++ == CMDQ) {
  5844.     if (*p == '{') p++;
  5845.     p = (*p == 'k' || *p == 'K') ? p + 1 : NULL;
  5846.     }
  5847. #endif /* NOKVERBS */
  5848.  
  5849.     if (macrotab[kc]) {            /* Possibly free old macro from key. */
  5850.     free((char *)macrotab[kc]);
  5851.     macrotab[kc] = NULL;
  5852.     }
  5853.     switch (strlen(s)) {        /* Action depends on length */
  5854.       case 0:                /* Reset to default binding */
  5855.     keymap[kc] = (KEY) kc;
  5856.     break;
  5857.       case 1:                /* Single character */
  5858.       keymap[kc] = (CHAR) *s;
  5859.       break;
  5860.       default:                /* Character string */
  5861. #ifndef NOKVERBS
  5862.     if (p) {
  5863.         y = xlookup(kverbs,p,nkverbs,&x); /* Look it up */
  5864.         debug(F101,"set key kverb lookup",0,y); /* exact match required */
  5865.         if (y > -1) {
  5866.         keymap[kc] = F_KVERB | y;
  5867.         break;
  5868.         }
  5869.     }
  5870. #endif /* NOKVERBS */
  5871.     keymap[kc] = (KEY) kc;
  5872.     macrotab[kc] = (MACRO) malloc(strlen(s)+1);
  5873.     if (macrotab[kc])
  5874.       strcpy((char *) macrotab[kc], s); /* safe */
  5875.     break;
  5876.     }
  5877.     if (flag) cmsetp(psave);
  5878. #ifdef OS2
  5879.     initvik = 1;            /* Update VIK table */
  5880. #endif /* OS2 */
  5881.     return(1);
  5882. }
  5883. #endif /* NOSETKEY */
  5884.  
  5885. #ifdef STOPBITS
  5886. struct keytab stoptbl[] = {
  5887.     { "1", 1, 0 },
  5888.     { "2", 2, 0 }
  5889. };
  5890. #endif /* STOPBITS */
  5891.  
  5892. static struct keytab sertbl[] = {
  5893.     { "7E1", 0, 0 },
  5894.     { "7E2", 1, 0 },
  5895.     { "7M1", 2, 0 },
  5896.     { "7M2", 3, 0 },
  5897.     { "7O1", 4, 0 },
  5898.     { "7O2", 5, 0 },
  5899.     { "7S1", 6, 0 },
  5900.     { "7S2", 7, 0 },
  5901. #ifdef HWPARITY
  5902.     { "8E1", 9, 0 },
  5903.     { "8E2", 10, 0 },
  5904. #endif /* HWPARITY */
  5905.     { "8N1", 8, 0 },
  5906. #ifdef HWPARITY
  5907.     { "8N2", 11, 0 },
  5908.     { "8O1", 12, 0 },
  5909.     { "8O2", 13, 0 },
  5910. #endif /* HWPARITY */
  5911.     { "", 0, 0 }
  5912. };
  5913. static int nsertbl = (sizeof(sertbl) / sizeof(struct keytab)) - 1;
  5914.  
  5915. static char * sernam[] = {        /* Keep this in sync with sertbl[] */
  5916.   "7E1", "7E2", "7M1", "7M2", "7O1", "7O2", "7S1", "7S2",
  5917.   "8N1", "8E1", "8E2", "8N2", "8O1", "8O2"
  5918. };
  5919.  
  5920. static struct keytab optstab[] = {    /* SET OPTIONS table */
  5921. #ifndef NOFRILLS
  5922.     { "delete",    XXDEL,   0},            /* DELETE */
  5923. #endif /* NOFRILLS */
  5924.     { "directory", XXDIR,   0},        /* DIRECTORY */
  5925. #ifdef CKPURGE
  5926.     { "purge",     XXPURGE, 0},        /* PURGE */
  5927. #endif /* CKPURGE */
  5928.     { "type",      XXTYP,   0},        /* TYPE */
  5929.     { "", 0, 0}
  5930. };
  5931. static int noptstab =  (sizeof(optstab) / sizeof(struct keytab)) - 1;
  5932.  
  5933. #ifndef NOXFER
  5934. /*
  5935.   PROTOCOL SELECTION.  Kermit is always available.  If CK_XYZ is defined at
  5936.   compile time, then the others become selections also.  In OS/2 and
  5937.   Windows, they are integrated and the various SET commands (e.g. "set file
  5938.   type") affect them as they would Kermit.  In other OS's (UNIX, VMS, etc),
  5939.   they are external protocols which are run via Kermit's REDIRECT mechanism.
  5940.   All we do is collect and verify the filenames and pass them along to the
  5941.   external protocol.
  5942. */
  5943. struct keytab protos[] = {
  5944. #ifdef CK_XYZ
  5945.     "g",          PROTO_G,  CM_INV,
  5946. #endif /* CK_XYZ */
  5947.     "kermit",     PROTO_K,  0,
  5948. #ifdef CK_XYZ
  5949.     "other",      PROTO_O,  0,
  5950.     "x",          PROTO_X,  CM_INV|CM_ABR,
  5951.     "xmodem",     PROTO_X,  0,
  5952.     "xmodem-crc", PROTO_XC, 0,
  5953.     "y",          PROTO_Y,  CM_INV|CM_ABR,
  5954.     "ymodem",     PROTO_Y,  0,
  5955.     "ymodem-g",   PROTO_G,  0,
  5956.     "zmodem",     PROTO_Z,  0
  5957. #endif /* CK_XYZ */
  5958. };
  5959. int nprotos =  (sizeof(protos) / sizeof(struct keytab));
  5960.  
  5961. #define XPCMDLEN 71
  5962.  
  5963. _PROTOTYP(static int protofield, (char *, char *, char *));
  5964. _PROTOTYP(static int setproto, (void));
  5965.  
  5966. static int
  5967. protofield(current, help, px) char * current, * help, * px; {
  5968.  
  5969.     char *s, tmpbuf[XPCMDLEN+1];
  5970.     int x;
  5971.  
  5972.     if (current)            /* Put braces around default */
  5973.       ckmakmsg(tmpbuf,TMPBUFSIZ,"{",current,"}",NULL);
  5974.     else
  5975.       tmpbuf[0] = NUL;
  5976.  
  5977.     if ((x = cmfld(help, (char *)tmpbuf, &s, xxstring)) < 0)
  5978.       return(x);
  5979.     if ((int)strlen(s) > XPCMDLEN) {
  5980.     printf("?Sorry - maximum length is %d\n", XPCMDLEN);
  5981.     return(-9);
  5982.     } else if (*s) {
  5983.     strcpy(px,s);            /* safe */
  5984.     } else {
  5985.     px = NULL;
  5986.     }
  5987.     return(x);
  5988. }
  5989.  
  5990. static int
  5991. setproto() {                /* Select a file transfer protocol */
  5992.     /* char * s = NULL; */
  5993.     int x = 0, y;
  5994.     char s1[XPCMDLEN+1], s2[XPCMDLEN+1], s3[XPCMDLEN+1];
  5995.     char s4[XPCMDLEN+1], s5[XPCMDLEN+1], s6[XPCMDLEN+1], s7[XPCMDLEN+1];
  5996.     char * p1 = s1, * p2 = s2, *p3 = s3;
  5997.     char * p4 = s4, * p5 = s5, *p6 = s6, *p7 = s7;
  5998.  
  5999. #ifdef XYZ_INTERNAL
  6000.     extern int p_avail;
  6001. #else
  6002. #ifndef CK_REDIR
  6003.     x = 1;
  6004. #endif /* CK_REDIR */
  6005. #endif /* XYZ_INTERNAL */
  6006.     s1[0] = NUL;
  6007.     s2[0] = NUL;
  6008.     s3[0] = NUL;
  6009.     s4[0] = NUL;
  6010.     s5[0] = NUL;
  6011.     s6[0] = NUL;
  6012.  
  6013.     if ((y = cmkey(protos,nprotos,"","kermit",xxstring)) < 0)
  6014.       return(y);
  6015.  
  6016.     if (x && y != PROTO_K) {
  6017.     printf(
  6018.        "?Sorry, REDIRECT capability required for external protocols.\n");
  6019.     return(-9);
  6020.     }
  6021.     if ((x = protofield(ptab[y].h_b_init,
  6022.      "Optional command to send to host prior to uploading in binary mode",
  6023.            p1)) < 0) {
  6024.     if (x == -3) {
  6025.         protocol = y;        /* Set protocol but don't change */
  6026.         return(1);            /* anything else */
  6027.     } else
  6028.       return(x);
  6029.     }
  6030.     if ((x = protofield(ptab[y].h_t_init,
  6031.      "Optional command to send to host prior to uploading in text mode",
  6032.            p2)) < 0) {
  6033.     if (x == -3)
  6034.       goto protoexit;
  6035.     else
  6036.       return(x);
  6037.     }
  6038.  
  6039.     if (y == PROTO_K) {
  6040.     if ((x = protofield(ptab[y].h_x_init,
  6041.             "Optional command to send to host to start Kermit server",
  6042.                 p3)) < 0) {
  6043.         if (x == -3)
  6044.           goto protoexit;
  6045.         else
  6046.           return(x);
  6047.     }
  6048.     }
  6049.  
  6050.  
  6051. #ifndef XYZ_INTERNAL            /* If XYZMODEM are external... */
  6052.  
  6053.     if (y != PROTO_K) {
  6054.     if ((x = protofield(ptab[y].p_b_scmd,
  6055.                "External command to SEND in BINARY mode with this protocol",
  6056.                 p4)) < 0) {
  6057.         if (x == -3)
  6058.           goto protoexit;
  6059.         else
  6060.           return(x);
  6061.     }
  6062.     if ((x = protofield(ptab[y].p_t_scmd,
  6063.          "External command to SEND in TEXT mode with this protocol",
  6064.                 p5)) < 0) {
  6065.         if (x == -3)
  6066.           goto protoexit;
  6067.         else
  6068.           return(x);
  6069.     }
  6070.     if ((x = protofield(ptab[y].p_b_rcmd,
  6071.            "External command to RECEIVE in BINARY mode with this protocol",
  6072.                 p6)) < 0) {
  6073.         if (x == -3)
  6074.           goto protoexit;
  6075.         else
  6076.           return(x);
  6077.     }
  6078.     if ((x = protofield(ptab[y].p_t_rcmd,
  6079.          "External command to RECEIVE in TEXT mode with this protocol",
  6080.                 p7)) < 0) {
  6081.         if (x == -3)
  6082.           goto protoexit;
  6083.         else
  6084.           return(x);
  6085.     }
  6086.     }
  6087. #endif /* XYZ_INTERNAL */
  6088.  
  6089.     if ((x = cmcfm()) < 0)        /* Confirm the command */
  6090.       return(x);
  6091.  
  6092. protoexit:                /* Common exit from this routine */
  6093.  
  6094. #ifdef XYZ_INTERNAL
  6095.     if (!p_avail) {
  6096.     bleep(BP_WARN);
  6097.     printf("\n?X,Y, and Zmodem are unavailable\n");
  6098.     return(success = 0);
  6099.     }
  6100. #endif /* XYZ_INTERNAL */
  6101.  
  6102.     p1 = brstrip(p1);
  6103.     p2 = brstrip(p2);
  6104.     p3 = brstrip(p3);
  6105.     p4 = brstrip(p4);
  6106.     p5 = brstrip(p5);
  6107.     p6 = brstrip(p6);
  6108.     p7 = brstrip(p7);
  6109.     initproto(y,p1,p2,p3,p4,p5,p6,p7);
  6110.     return(success = 1);
  6111. }
  6112.  
  6113. int
  6114. setdest() {
  6115.     int x, y;
  6116.     if ((y = cmkey(desttab,ndests,"","disk",xxstring)) < 0) return(y);
  6117.     if ((x = cmcfm()) < 0) return(x);
  6118.     dest = y;
  6119.     return(1);
  6120. }
  6121. #endif /* NOXFER */
  6122.  
  6123. #ifdef DECNET
  6124. struct keytab dnettab[] = {
  6125. #ifndef OS2ONLY
  6126.     "cterm", NP_CTERM, 0,
  6127. #endif /* OS2ONLY */
  6128.     "lat",   NP_LAT,   0
  6129. };
  6130. int ndnet =  (sizeof(dnettab) / sizeof(struct keytab));
  6131. #endif /* DECNET */
  6132.  
  6133. /*  S E T P R I N T E R  --  SET PRINTER command  */
  6134.  
  6135. #ifdef PRINTSWI
  6136. static struct keytab prntab[] = {    /* SET PRINTER switches */
  6137.     "/bidirectional",    PRN_BID, 0,
  6138.     "/command",          PRN_PIP, CM_ARG,
  6139.     "/dos-device",       PRN_DOS, CM_ARG,
  6140.     "/end-of-job-string",PRN_TRM, CM_ARG,
  6141.     "/file",             PRN_FIL, CM_ARG,
  6142. #ifdef BPRINT
  6143.     "/flow-control",     PRN_FLO, CM_ARG,
  6144. #endif /* BPRINT */
  6145.     "/job-header-file",  PRN_SEP, CM_ARG,
  6146. #ifdef OS2
  6147.     "/length",           PRN_LEN, CM_ARG,
  6148. #endif /* OS2 */
  6149.     "/none",             PRN_NON, 0,
  6150. #ifdef OS2
  6151.     "/nopostscript",     PRN_RAW, 0,
  6152.     "/nops",             PRN_RAW, CM_INV,
  6153. #endif /* OS2 */
  6154.     "/output-only",      PRN_OUT, 0,
  6155. #ifdef BPRINT
  6156.     "/parity",           PRN_PAR, CM_ARG,
  6157. #endif /* BPRINT */
  6158.     "/pipe",             PRN_PIP, CM_ARG|CM_INV,
  6159. #ifdef OS2
  6160.     "/postscript",       PRN_PS,  0,
  6161.     "/ps",               PRN_PS,  CM_INV,
  6162. #endif /* OS2 */
  6163.     "/separator",        PRN_SEP, CM_ARG|CM_INV,
  6164. #ifdef BPRINT
  6165.     "/speed",            PRN_SPD, CM_ARG,
  6166. #endif /* BPRINT */
  6167.     "/timeout",          PRN_TMO, CM_ARG,
  6168.     "/terminator",       PRN_TRM, CM_ARG|CM_INV,
  6169. #ifdef OS2
  6170. #ifdef NT
  6171.     "/w",                PRN_WIN, CM_ARG|CM_ABR|CM_INV,
  6172.     "/wi",               PRN_WIN, CM_ARG|CM_ABR|CM_INV,
  6173. #endif /* NT */
  6174.     "/width",            PRN_WID, CM_ARG,
  6175. #endif /* OS2 */
  6176. #ifdef NT
  6177.     "/windows-queue",    PRN_WIN, CM_ARG,
  6178. #endif /* NT */
  6179.     "",                 0,      0
  6180. };
  6181. int nprnswi =  (sizeof(prntab) / sizeof(struct keytab)) - 1;
  6182. #endif /* PRINTSWI */
  6183.  
  6184. static int
  6185. setprinter(xx) int xx; {
  6186.     int x, y;
  6187.     char * s;
  6188.     char * defname = NULL;
  6189.  
  6190. #ifdef BPRINT
  6191.     char portbuf[64];
  6192.     long portspeed = 0L;
  6193.     int portparity = 0;
  6194.     int portflow = 0;
  6195. #endif /* BPRINT */
  6196.  
  6197. #ifdef PRINTSWI
  6198.     int c, i, n, wild, confirmed = 0;    /* Workers */
  6199.     int getval = 0;            /* Whether to get switch value */
  6200.     struct stringint {            /* Temporary array for switch values */
  6201.     char * sval;
  6202.     int ival;
  6203.     } pv[PRN_MAX+1];
  6204.     struct FDB sw, of, cm;        /* FDBs for each parse function */
  6205.     int haveque = 0;
  6206.     int typeset = 0;
  6207. #endif /* PRINTSWI */
  6208.  
  6209. #ifdef NT
  6210.     struct keytab * printtab = NULL, * _printtab = NULL;
  6211.     int nprint = 0, printdef=0;
  6212. #endif /* NT */
  6213.  
  6214. #ifdef OS2
  6215.     defname = "PRN";            /* default */
  6216. #else
  6217. #ifdef VMS
  6218.     defname = "LPT:";
  6219. #else
  6220. #ifdef UNIX
  6221.     defname = "|lpr";
  6222. #endif /* UNIX */
  6223. #endif /* VMS */
  6224. #endif /* OS2 */
  6225.  
  6226. #ifdef PRINTSWI
  6227. #ifdef NT
  6228.     haveque = Win32EnumPrt(&printtab,&_printtab,&nprint,&printdef);
  6229.     haveque = haveque && nprint;
  6230. #endif /* NT */
  6231.  
  6232.     for (i = 0; i <= PRN_MAX; i++) {    /* Initialize switch values */
  6233.     pv[i].sval = NULL;        /* to null pointers */
  6234.     pv[i].ival = -1;        /* and -1 int values */
  6235.     }
  6236.     if (xx == XYBDCP) {            /* SET BPRINTER == /BIDIRECTIONAL */
  6237.     pv[PRN_BID].ival = 1;
  6238.     pv[PRN_OUT].ival = 0;
  6239.     }
  6240.  
  6241.     /* Initialize defaults based upon current printer settings */
  6242.     if (printername) {
  6243.         defname = printername;
  6244.         switch (printertype) {
  6245.       case PRT_WIN: pv[PRN_WIN].ival = 1; break;
  6246.       case PRT_DOS: pv[PRN_DOS].ival = 1; break;
  6247.       case PRT_PIP: pv[PRN_PIP].ival = 1; break;
  6248.       case PRT_FIL: pv[PRN_FIL].ival = 1; break;
  6249.       case PRT_NON: pv[PRN_NON].ival = 1; break;
  6250.         }
  6251.     }
  6252. #ifdef BPRINT
  6253.     /* only set the BIDI flag if we are bidi */
  6254.     if (printbidi)
  6255.         pv[PRN_BID].ival = 1;
  6256.  
  6257.     /* serial port parameters may be set for non-bidi devices */
  6258.     pv[PRN_SPD].ival = pportspeed / 10L;
  6259.     pv[PRN_PAR].ival = pportparity;
  6260.     pv[PRN_FLO].ival = pportflow;
  6261. #endif /* BPRINT */
  6262.     if (printtimo)
  6263.         pv[PRN_TMO].ival = printtimo;
  6264.     if (printterm) {
  6265.         pv[PRN_TRM].ival = 1;
  6266.         makestr(&pv[PRN_TRM].sval,printterm);
  6267.     }
  6268.     if (printsep) {
  6269.         pv[PRN_SEP].ival = 1;
  6270.         makestr(&pv[PRN_SEP].sval,printsep);
  6271.     }
  6272.     if (txt2ps) {
  6273.         pv[PRN_PS].ival = 1;
  6274.         pv[PRN_WID].ival = ps_width;
  6275.         pv[PRN_LEN].ival = ps_length;
  6276.     } else {
  6277.         pv[PRN_RAW].ival = 1;
  6278.     }
  6279.  
  6280.     /* Set up chained parse functions... */
  6281.  
  6282.     cmfdbi(&sw,                /* First FDB - command switches */
  6283.        _CMKEY,            /* fcode */
  6284.        "Switch",            /* hlpmsg */
  6285.        "",                /* default */
  6286.        "",                /* addtl string data */
  6287.        nprnswi,            /* addtl numeric data 1: tbl size */
  6288.        4,                /* addtl numeric data 2: 4 = cmswi */
  6289.        xxstring,            /* Processing function */
  6290.        prntab,            /* Keyword table */
  6291.        &cm                /* Pointer to next FDB */
  6292.        );
  6293.     cmfdbi(&cm,                /* Second fdb for confirmation */
  6294.        _CMCFM,            /* fcode */
  6295.        "",                /* hlpmsg */
  6296.        "",                /* default */
  6297.        "",                /* addtl string data */
  6298.        0,                /* addtl numeric data 1 */
  6299.        0,                /* addtl numeric data 2 */
  6300.        NULL,
  6301.        NULL,
  6302.        &of
  6303.        );
  6304.     cmfdbi(&of,                /* Third FDB for printer name */
  6305.        _CMOFI,            /* fcode */
  6306.        "Printer or file name",    /* hlpmsg */
  6307.        defname,            /* default */
  6308.        "",                /* addtl string data */
  6309.        0,                /* addtl numeric data 1: tbl size */
  6310.        0,                /* addtl numeric data 2: 4 = cmswi */
  6311.        xxstring,            /* Processing function */
  6312.        NULL,            /* Nothing */
  6313.        NULL
  6314.        );
  6315.  
  6316.     while (1) {                /* Parse 0 or more switches */
  6317.     x = cmfdb(&sw);            /* Parse switch or other thing */
  6318.     debug(F101,"setprinter cmfdb","",x);
  6319.     if (x < 0)            /* Error */
  6320.       goto xsetprn;            /* or reparse needed */
  6321.     if (cmresult.fcode != _CMKEY)    /* Break out if not a switch */
  6322.       break;
  6323.     if (cmresult.fdbaddr != &sw)    /* Advanced usage :-) */
  6324.       break;
  6325.     c = cmgbrk();            /* Get break character */
  6326.     getval = (c == ':' || c == '='); /* to see how they ended the switch */
  6327.     n = cmresult.nresult;        /* Numeric result = switch value */
  6328.     debug(F101,"setprinter switch","",n);
  6329.  
  6330.     switch (n) {            /* Process the switch */
  6331.       case PRN_PS:                  /* Text to Postscript */
  6332.             pv[PRN_PS].ival = 1;
  6333.         pv[PRN_BID].ival = 0;
  6334.         pv[PRN_OUT].ival = 1;
  6335.             pv[PRN_RAW].ival = 0;
  6336.             break;
  6337.  
  6338.       case PRN_RAW:            /* Non-Postscript */
  6339.             pv[PRN_PS].ival = 0;
  6340.             pv[PRN_RAW].ival = 1;
  6341.             break;
  6342.  
  6343.       case PRN_BID:            /* Bidirectional */
  6344.         pv[PRN_BID].ival = 1;
  6345.         pv[PRN_OUT].ival = 0;
  6346.             pv[PRN_PS].ival = 0;
  6347.             pv[PRN_RAW].ival = 1;
  6348.         break;
  6349.  
  6350.       case PRN_OUT:            /* Output-only */
  6351.         pv[PRN_OUT].ival = 1;
  6352.         pv[PRN_BID].ival = 0;
  6353.             pv[PRN_PS].ival = 0;
  6354.             pv[PRN_RAW].ival = 1;
  6355.         break;
  6356.  
  6357.       case PRN_NON:            /* NONE */
  6358.             typeset++;
  6359.         pv[n].ival = 1;
  6360.         pv[PRN_SPD].ival = 0;
  6361.         pv[PRN_PAR].ival = 0;
  6362.         pv[PRN_FLO].ival = FLO_KEEP;
  6363.         break;
  6364.  
  6365. #ifdef UNIX
  6366.       case PRN_WIN:
  6367. #endif /* UNIX */
  6368.       case PRN_DOS:            /* DOS printer name */
  6369.       case PRN_FIL:            /* Or filename */
  6370.       case PRN_PIP:
  6371.             typeset++;
  6372.         if (pv[n].sval) free(pv[n].sval);
  6373.         pv[n].sval = NULL;
  6374.         pv[PRN_NON].ival = 0;    /* Zero any previous selections */
  6375.         pv[PRN_WIN].ival = 0;
  6376.         pv[PRN_DOS].ival = 0;
  6377.         pv[PRN_FIL].ival = 0;
  6378.         pv[PRN_PIP].ival = 0;
  6379.         pv[n].ival = 1;        /* Flag this one */
  6380.         if (!getval) break;        /* No value wanted */
  6381.  
  6382.         if (n == PRN_FIL) {        /* File, check accessibility */
  6383.         int wild = 0;
  6384.         if ((x = cmiofi("Filename","kermit.prn",&s,&wild,xxstring))< 0)
  6385.           if (x == -9) {
  6386.               if (zchko(s) < 0) {
  6387.               printf("Can't create \"%s\"\n",s);
  6388.               return(x);
  6389.               }
  6390.           } else goto xsetprn;
  6391.         if (iswild(s)) {
  6392.             printf("?A single file please\n");
  6393.             return(-9);
  6394.         }
  6395.                 pv[PRN_SPD].ival = 0;
  6396.                 pv[PRN_PAR].ival = 0;
  6397.                 pv[PRN_FLO].ival = FLO_KEEP;
  6398.         } else if ((x = cmfld(n == PRN_DOS ? /* Value wanted - parse it */
  6399.                "DOS printer device name" : /* Help message */
  6400.                (n == PRN_PIP ?
  6401.                "Program name" :
  6402.                "Filename"),
  6403.                n == PRN_DOS ?
  6404.                "PRN" :    /* Default */
  6405.                "",
  6406.                &s,
  6407.                xxstring
  6408.                )) < 0)
  6409.           goto xsetprn;
  6410.         s = brstrip(s);        /* Strip enclosing braces */
  6411.         while (*s == SP)        /* Strip leading blanks */
  6412.           s++;
  6413.         if (n == PRN_PIP) {        /* If /PIPE: */
  6414.         if (*s == '|') {    /* strip any extraneous pipe sign */
  6415.             s++;
  6416.             while (*s == SP)
  6417.               s++;
  6418.         }
  6419.                 pv[PRN_SPD].ival = 0;
  6420.                 pv[PRN_PAR].ival = 0;
  6421.                 pv[PRN_FLO].ival = FLO_KEEP;
  6422.         }
  6423.         if ((y = strlen(s)) > 0)    /* Anything left? */
  6424.           if (pv[n].sval = (char *) malloc(y+1)) /* Yes, keep it */
  6425.         strcpy(pv[n].sval,s);    /* safe */
  6426.         break;
  6427. #ifdef NT
  6428.       case PRN_WIN:            /* Windows queue name */
  6429.             typeset++;
  6430.         if (pv[n].sval) free(pv[n].sval);
  6431.         pv[n].sval = NULL;
  6432.         pv[PRN_NON].ival = 0;
  6433.         pv[PRN_DOS].ival = 0;
  6434.         pv[PRN_FIL].ival = 0;
  6435.         pv[n].ival = 1;
  6436.             pv[PRN_SPD].ival = 0;
  6437.             pv[PRN_PAR].ival = 0;
  6438.             pv[PRN_FLO].ival = FLO_KEEP;
  6439.  
  6440.         if (!getval || !haveque)
  6441.           break;
  6442.         if ((x = cmkey(_printtab,nprint,"Print queue name",
  6443.                _printtab[printdef].kwd,xxstring)) < 0) {
  6444.         if (x != -2)
  6445.           goto xsetprn;
  6446.  
  6447.         if (pv[PRN_WIN].sval) free(pv[PRN_WIN].sval);
  6448.         s = atmbuf;
  6449.         if ((y = strlen(s)) > 0)
  6450.           if (pv[n].sval = (char *)malloc(y+1))
  6451.             strcpy(pv[n].sval,s); /* safe */
  6452.         } else {
  6453.         if (pv[PRN_WIN].sval) free(pv[PRN_WIN].sval);
  6454.         for (i = 0; i < nprint; i++) {
  6455.             if (x == printtab[i].kwval) {
  6456.             s = printtab[i].kwd;
  6457.             break;
  6458.             }
  6459.         }
  6460.         if ((y = strlen(s)) > 0)
  6461.           if (pv[n].sval = (char *)malloc(y+1))
  6462.             strcpy(pv[n].sval,s); /* safe */
  6463.         }
  6464.         break;
  6465. #endif /* NT */
  6466.  
  6467.       case PRN_SEP:            /* /JOB-HEADER (separator) */
  6468.         if (pv[n].sval) free(pv[n].sval);
  6469.         pv[n].sval = NULL;
  6470.         pv[n].ival = 1;
  6471.         if (!getval) break;
  6472.         if ((x = cmifi("Filename","",&s,&y,xxstring)) < 0)
  6473.           goto xsetprn;
  6474.         if (y) {
  6475.         printf("?Wildcards not allowed\n");
  6476.         x = -9;
  6477.         goto xsetprn;
  6478.         }
  6479.         if ((y = strlen(s)) > 0)
  6480.           if (pv[n].sval = (char *) malloc(y+1))
  6481.         strcpy(pv[n].sval,s);    /* safe */
  6482.         break;
  6483.  
  6484.       case PRN_TMO:            /* /TIMEOUT:number */
  6485.         pv[n].ival = 0;
  6486.         if (!getval) break;
  6487.         if ((x = cmnum("Seconds","0",10,&y,xxstring)) < 0)
  6488.           goto xsetprn;
  6489.         if (y > 999) {
  6490.         printf("?Sorry - 999 is the maximum\n");
  6491.         x = -9;
  6492.         goto xsetprn;
  6493.         } else
  6494.           pv[n].ival = y;
  6495.         break;
  6496.  
  6497.       case PRN_TRM:            /* /END-OF-JOB:string */
  6498.         if (pv[n].sval) free(pv[n].sval);
  6499.         pv[n].sval = NULL;
  6500.         pv[n].ival = 1;
  6501.         if (!getval) break;
  6502.         if ((x = cmfld("String (enclose in braces if it contains spaces)",
  6503.                "",&s,xxstring)) < 0)
  6504.           goto xsetprn;
  6505.         s = brstrip(s);
  6506.         if ((y = strlen(s)) > 0)
  6507.           if (pv[n].sval = (char *) malloc(y+1))
  6508.         strcpy(pv[n].sval,s);    /* safe */
  6509.         break;
  6510.  
  6511. #ifdef BPRINT
  6512.       case PRN_FLO:
  6513.         if (!getval) break;
  6514.         if ((x = cmkey(flotab,nflo,
  6515.                   "Serial printer-port flow control",
  6516.                   "rts/cts",xxstring)) < 0)
  6517.           goto xsetprn;
  6518.         pv[n].ival = x;
  6519.         break;
  6520.  
  6521. #ifndef NOLOCAL
  6522.       case PRN_SPD:
  6523.         if (!getval) break;
  6524.  
  6525.         /* TN_COMPORT here too? */
  6526.  
  6527.         if ((x = cmkey(spdtab,    /* Speed (no default) */
  6528.                nspd,
  6529.                "Serial printer-port interface speed",
  6530.                "9600",
  6531.                xxstring)
  6532.          ) < 0)
  6533.           goto xsetprn;
  6534.         pv[n].ival = x;
  6535.         break;
  6536. #endif /* NOLOCAL */
  6537.  
  6538.       case PRN_PAR:
  6539.         pv[n].ival = 0;
  6540.         if (!getval) break;
  6541.         if ((x = cmkey(partbl,npar,"Serial printer-port parity",
  6542.                "none",xxstring)) < 0)
  6543.           goto xsetprn;
  6544.         pv[n].ival = x;
  6545.         break;
  6546. #endif /* BPRINT */
  6547.  
  6548. #ifdef OS2
  6549.       case PRN_LEN:
  6550.         if (!getval) break;
  6551.             if ((x = cmnum("PS page length", "66",10,&y,xxstring)) < 0)
  6552.           goto xsetprn;
  6553.         pv[n].ival = y;
  6554.         break;
  6555.  
  6556.       case PRN_WID:
  6557.         if (!getval) break;
  6558.             if ((x = cmnum("PS page width", "80",10,&y,xxstring)) < 0)
  6559.           goto xsetprn;
  6560.         pv[n].ival = y;
  6561.             break;
  6562. #endif /* OS2 */
  6563.  
  6564.       default:
  6565.         printf("?Unexpected switch value - %d\n",cmresult.nresult);
  6566.         x = -9;
  6567.         goto xsetprn;
  6568.     }
  6569.     }
  6570.     line[0] = NUL;            /* Initialize printer name value */
  6571.     switch (cmresult.fcode) {        /* How did we get here? */
  6572.       case _CMOFI:            /* They typed a filename */
  6573.     ckstrncpy(line,cmresult.sresult,LINBUFSIZ); /* Name */
  6574.     wild = cmresult.nresult;    /* Wild flag */
  6575.         if (!typeset) {                 /* A printer name without a type */
  6576.             pv[PRN_NON].ival = 0;       /* is supposed to be treated as  */
  6577.         pv[PRN_WIN].ival = 0;       /* a DOS or Pipe printer.  We    */
  6578.         pv[PRN_FIL].ival = 0;       /* clear all the flags and let   */
  6579.         pv[PRN_PIP].ival = 0;       /* the code below dope out the   */
  6580.         pv[PRN_DOS].ival = 0;       /* type.                         */
  6581.         }
  6582. #ifdef NT
  6583.         else if (pv[PRN_WIN].ival && lookup(_printtab,line,nprint,&y)) {
  6584.             /* invalid Window Queue name */
  6585.             printf("?invalid Windows Printer Queue name: \"%s\"\r\n",line);
  6586.             x = -9;
  6587.             goto xsetprn;
  6588.         }
  6589. #endif /* NT */
  6590.     if ((x = cmcfm()) < 0)        /* Confirm the command */
  6591.       goto xsetprn;
  6592.     break;
  6593.       case _CMCFM:            /* They entered the command */
  6594.     if (pv[PRN_DOS].ival > 0)
  6595.       ckstrncpy(line,pv[PRN_DOS].sval ? pv[PRN_DOS].sval : "",LINBUFSIZ);
  6596.     else if (pv[PRN_WIN].ival > 0)
  6597.       ckstrncpy(line,pv[PRN_WIN].sval ? pv[PRN_WIN].sval : "",LINBUFSIZ);
  6598.     else if (pv[PRN_FIL].ival > 0)
  6599.       ckstrncpy(line,pv[PRN_FIL].sval ? pv[PRN_FIL].sval : "",LINBUFSIZ);
  6600.     else if (pv[PRN_PIP].ival > 0)
  6601.       ckstrncpy(line,pv[PRN_PIP].sval ? pv[PRN_PIP].sval : "",LINBUFSIZ);
  6602.     break;
  6603.       default:                /* By mistake */
  6604.     printf("?Unexpected function code: %d\n",cmresult.fcode);
  6605.     x = -9;
  6606.     goto xsetprn;
  6607.     }
  6608.  
  6609. #else  /* No PRINTSWI */
  6610.  
  6611.     if ((x = cmofi("Printer or file name",defname,&s,xxstring)) < 0)
  6612.       return(x);
  6613.     if (x > 1) {
  6614.     printf("?Directory names not allowed\n");
  6615.     return(-9);
  6616.     }
  6617.     while (*s == SP || *s == HT) s++;    /* Trim leading whitespace */
  6618.     ckstrncpy(line,s,LINBUFSIZ);    /* Make a temporary safe copy */
  6619.     if ((x = cmcfm()) < 0) return(x);    /* Confirm the command */
  6620. #endif /* PRINTSWI */
  6621.  
  6622. #ifdef IKSD
  6623.     if (inserver && (isguest
  6624. #ifndef NOSERVER
  6625.              || !ENABLED(en_pri)
  6626. #endif /* NOSERVER */
  6627.              )) {
  6628.         printf("Sorry, printing disabled\r\n");
  6629.         return(success = 0);
  6630.     }
  6631. #endif /* ISKD */
  6632.  
  6633. #ifdef PRINTSWI
  6634. #ifdef BPRINT
  6635.     if (printbidi) {            /* If bidi printing active */
  6636. #ifndef UNIX
  6637.     bprtstop();            /* Stop it before proceeding */
  6638. #endif /* UNIX */
  6639.     printbidi = 0;
  6640.     }
  6641.     if (pv[PRN_SPD].ival > 0) {
  6642.         portspeed = (long) pv[PRN_SPD].ival * 10L;
  6643.         if (portspeed == 70L) portspeed = 75L;
  6644.     }
  6645.     if (pv[PRN_PAR].ival > 0)
  6646.         portparity = pv[PRN_PAR].ival;
  6647.     if (pv[PRN_FLO].ival > 0)
  6648.         portflow = pv[PRN_FLO].ival;
  6649. #endif /* BPRINT */
  6650. #endif /* PRINTSWI */
  6651.  
  6652.     s = line;                /* Printer name, if given */
  6653.  
  6654. #ifdef OS2ORUNIX
  6655. #ifdef PRINTSWI
  6656.     if (pv[PRN_PIP].ival > 0) {        /* /PIPE was given? */
  6657.     printpipe = 1;
  6658.     noprinter = 0;
  6659.     if (*s ==  '|') {        /* It might still have a pipe sign */
  6660.         s++;            /* if name give later */
  6661.         while (*s == SP)        /* so remove it and spaces */
  6662.           s++;
  6663.     }
  6664.     } else
  6665. #endif /* PRINTSWI */
  6666.       if (*s == '|') {            /* Or pipe implied by name? */
  6667.       s++;                /* Point past pipe sign */
  6668.       while (*s == SP)        /* Gobble whitespace */
  6669.         s++;
  6670.       if (*s) {
  6671.           printpipe = 1;
  6672.           noprinter = 0;
  6673.       }
  6674.       } else {
  6675.           printpipe = 0;
  6676.       }
  6677.  
  6678. #ifdef PRINTSWI
  6679. #ifdef BPRINT
  6680.     if (printpipe && pv[PRN_BID].ival > 0) {
  6681.     printf("?Sorry, pipes not allowed for bidirectional printer\n");
  6682.     return(-9);
  6683.     }
  6684. #endif /* BPRINT */
  6685. #endif /* PRINTSWI */
  6686. #endif /* OS2ORUNIX */
  6687.  
  6688. #ifdef OS2
  6689.     if ( pv[PRN_PS].ival > 0 ) {
  6690.         txt2ps = 1;
  6691.         ps_width = pv[PRN_WID].ival <= 0 ? 80 : pv[PRN_WID].ival;
  6692.         ps_length = pv[PRN_LEN].ival <= 0 ? 66 : pv[PRN_LEN].ival;
  6693.     }
  6694. #endif /* OS2 */
  6695.  
  6696.     y = strlen(s);            /* Length of name of new print file */
  6697.     if (y > 0
  6698. #ifdef OS2
  6699.     && ((y != 3) || (ckstrcmp(s,"PRN",3,0) != 0))
  6700. #endif /* OS2 */
  6701.     ) {
  6702.     if (printername) {        /* Had a print file before? */
  6703.         free(printername);        /* Remove its name */
  6704.         printername = NULL;
  6705.     }
  6706.     printername = (char *) malloc(y + 1); /* Allocate space for it */
  6707.     if (!printername) {
  6708.         printf("?Memory allocation failure\n");
  6709.         return(-9);
  6710.     }
  6711.     strcpy(printername,s);        /* (safe) Copy new name to new space */
  6712.     debug(F110,"printername",printername,0);
  6713.     }
  6714.  
  6715. #ifdef PRINTSWI
  6716.     /* Set printer type from switches that were given explicitly */
  6717.  
  6718.     if (pv[PRN_NON].ival > 0) {        /* No printer */
  6719.     printertype = PRT_NON;
  6720.     noprinter = 1;
  6721.     printpipe = 0;
  6722.     } else if (pv[PRN_FIL].ival > 0) {    /* File */
  6723.     printertype = PRT_FIL;
  6724.     noprinter = 0;
  6725.     printpipe = 0;
  6726.     } else if (pv[PRN_PIP].ival > 0) {    /* Pipe */
  6727.     printertype = PRT_PIP;
  6728.     noprinter = 0;
  6729.     printpipe = 1;
  6730.     } else if (pv[PRN_WIN].ival > 0) {    /* Windows print queue */
  6731.     printertype = PRT_WIN;
  6732.     noprinter = 0;
  6733.     printpipe = 0;
  6734.     } else if (pv[PRN_DOS].ival > 0) {    /* DOS device */
  6735.     printertype = PRT_DOS;
  6736.     noprinter = 0;
  6737.     printpipe = 0;
  6738.     } else if (line[0]) {        /* Name given without switches */
  6739.     noprinter = 0;
  6740.     printertype = printpipe ? PRT_PIP : PRT_DOS;
  6741. #ifdef NT
  6742.     /* was the command SET PRINTER windows-queue ? */
  6743.         if (lookup(_printtab,line,nprint,&x) >= 0) {
  6744.             printertype = PRT_WIN;
  6745.             if (pv[PRN_WIN].sval) free(pv[PRN_WIN].sval);
  6746.             if (printername) {        /* Had a print file before? */
  6747.                 free(printername);    /* Remove its name */
  6748.                 printername = NULL;
  6749.             }
  6750.             pv[PRN_WIN].sval = NULL;
  6751.             pv[PRN_WIN].ival = 1;
  6752.             s = printtab[x].kwd;    /* Get full new name */
  6753.             if ((y = strlen(s)) > 0) {
  6754.                 makestr(&pv[PRN_WIN].sval,s);
  6755.                 makestr(&printername,s);
  6756.                 if (!printername) {
  6757.                     printf("?Memory allocation failure\n");
  6758.                     return(-9);
  6759.                 }
  6760.                 debug(F110,"printername",printername,0);
  6761.             }
  6762.         }
  6763. #endif /* NT */
  6764.     }
  6765.  
  6766. #ifdef BPRINT
  6767.     /* Port parameters may be set for non-bidi mode */
  6768.  
  6769.     pportspeed = portspeed;        /* Set parameters */
  6770.     pportparity = portparity;
  6771.     pportflow = portflow;
  6772.  
  6773.     if (pv[PRN_BID].ival > 0) {        /* Bidirectional */
  6774. #ifdef UNIX
  6775.     printbidi = 1;            /* (just to test parsing...) */
  6776. #else
  6777.     printbidi = bprtstart();    /* Start bidirectional printer */
  6778. #endif /* UNIX */
  6779.     return(success = printbidi);
  6780.     } else
  6781.       printbidi = 0;            /* Not BPRINTER, unset flag */
  6782. #endif /* BPRINT */
  6783.  
  6784.     if (pv[PRN_TMO].ival > -1) {    /* Take care of timeout */
  6785.     printtimo = pv[PRN_TMO].ival;
  6786.     }
  6787.     if (pv[PRN_TRM].ival > 0) {        /* Termination string */
  6788.     if (printterm) {
  6789.         free(printterm);
  6790.         printterm = NULL;
  6791.     }
  6792.     if (pv[PRN_TRM].sval)
  6793.       makestr(&printterm,pv[PRN_TRM].sval);
  6794.     }
  6795.     if (pv[PRN_SEP].ival > 0) {        /* and separator file */
  6796.     if (printsep) {
  6797.         free(printsep);
  6798.         printsep = NULL;
  6799.     }
  6800.     if (pv[PRN_SEP].sval)
  6801.       makestr(&printsep,pv[PRN_SEP].sval);
  6802.     }
  6803. #endif /* PRINTSWI */
  6804.  
  6805. #ifdef UNIXOROSK
  6806.     if (!printpipe
  6807. #ifdef PRINTSWI
  6808.     && !noprinter
  6809. #endif /* PRINTSWI */
  6810.     ) {                /* File - check access */
  6811.     if (zchko(s) < 0) {
  6812.         printf("?Access denied - %s\n",s);
  6813.         x = -9;
  6814.         goto xsetprn;
  6815.     }
  6816.     }
  6817. #endif /* UNIXOROSK */
  6818.  
  6819.     x = 1;                /* Return code */
  6820.  
  6821.   xsetprn:                /* Common exit */
  6822. #ifdef PRINTSWI
  6823.     for (i = 0; i <= PRN_MAX; i++) {    /* Free malloc'd memory */
  6824.     if (pv[i].sval)
  6825.       free(pv[i].sval);
  6826.     }
  6827. #endif /* PRINTSWI */
  6828.     success = (x > 0) ? 1 : 0;
  6829.     return(x);
  6830. }
  6831.  
  6832. #ifdef ANYSSH
  6833.  
  6834. #ifdef SSHBUILTIN
  6835. #ifdef SSHCMD
  6836. #undef SSHCMD
  6837. #endif /* SSHCMD */
  6838. #endif /* SSHBUILTIN */
  6839.  
  6840. /* The SET SSH command */
  6841.  
  6842. #define SSH_CMD  1            /* SET SSH COMMAND */
  6843.  
  6844. #ifdef SSHBUILTIN            /* Built-in SET SSH options */
  6845. #define SSH_AFW  2            /* Agent-forwarding */
  6846. #define SSH_XFW  3            /* X11-forwarding */
  6847. #define SSH_VER  4            /* Version */
  6848. #define SSH_IDF  5            /* ID file */
  6849. #define SSH_PRP  6            /* Privd port */
  6850. #define SSH_CIF  7            /* Cipher */
  6851. #define SSH_MAC  8            /* MAC */
  6852. #define SSH_CMP  9            /* Compression */
  6853. #define SSH_CAS 10            /* command-as-subsys */
  6854. #define SSH_SHH 11            /* Quiet */
  6855. #define SSH_VRB 12            /* Verbosity level */
  6856. #define SSH_AV2 13            /* Auto-V2-Rekey */
  6857. #endif /* SSHBUILTIN */
  6858.  
  6859. static struct keytab sshtab[] = {    /* SET SSH command table */
  6860. #ifdef SSHBUILTIN
  6861.     { "agent-forwarding",     SSH_AFW,  0 },
  6862.     { "auto-v2-rekey",        SSH_AV2,  0 },
  6863.     { "cipher",               SSH_CIF,  0 },
  6864.     { "command-as-subsystem", SSH_CAS,  0 },
  6865.     { "compression",          SSH_CMP,  0 },
  6866.     { "identify-file",        SSH_IDF,  0 },
  6867.     { "mac",                  SSH_MAC,  0 },
  6868.     { "privileged-port",      SSH_PRP,  0 },
  6869.     { "quiet",                SSH_SHH,  0 },
  6870.     { "verbose",              SSH_VRB,  0 },
  6871.     { "version",              SSH_VER,  0 },
  6872.     { "x11-forwarding",       SSH_XFW,  0 },
  6873. #else
  6874. #ifdef SSHCMD
  6875.     { "command",              SSH_CMD,  0 },
  6876. #endif /* SSHCMD */
  6877. #endif /* SSHBUILTIN */
  6878.     { "", 0, 0 }
  6879. };
  6880. static int nsshtab = (sizeof(sshtab) / sizeof(struct keytab)) - 1;
  6881.  
  6882. #ifdef SSHBUILTIN
  6883. static struct keytab sshver[] = {    /* SET SSH VERSION command table */
  6884.     { "1",          1,  0 },
  6885.     { "2",          2,  0 },
  6886.     { "automatic",  0,  0 }
  6887. };
  6888. #endif /* SSHBUILTIN */
  6889.  
  6890. #ifdef SSHBUILTIN
  6891. /*
  6892.   I just made these up; maybe you have other ones or maybe these should
  6893.   be external.  You also might want to initialize them differently.
  6894. */
  6895. int                    /* SET SSH variables */
  6896.   ssh_afw = 0,
  6897.   ssh_xfw = 0,
  6898.   ssh_prp = SET_AUTO,
  6899.   ssh_cmp = 0,
  6900.   ssh_cas = 0,
  6901.   ssh_shh = 0,
  6902.   ssh_ver = 0,
  6903.   ssh_vrb = 2,                /* Report errors */
  6904.   ssh_av2 = 0,
  6905.   ssh_prt = 0;
  6906. char                    /* The following are to be malloc'd */
  6907.   * ssh_idf = NULL,
  6908.   * ssh_cif = NULL,            /* <-- Should these be some kind */
  6909.   * ssh_mac = NULL,            /* <-- of list or array? */
  6910.   * ssh_hst = NULL,
  6911.   * ssh_cmd = NULL;
  6912. #endif /* SSHBUILTIN */
  6913.  
  6914. VOID
  6915. shossh() {
  6916. #ifdef SSHBUILTIN    
  6917.     printf("\nSSH is built in:\n\n");
  6918.  
  6919.     printf(" ssh host:                 %s\n",ssh_hst);
  6920.     printf(" ssh port:                 %d\n",ssh_prt);
  6921.     printf(" ssh command:              %s\n",ssh_cmd);
  6922.     printf(" ssh agent-forwarding:     %s\n",showoff(ssh_afw));
  6923.     printf(" ssh auto-v2-rekey:        %d (sec)\n",ssh_av2);
  6924.     printf(" ssh cipher:               %s\n",showstring(ssh_cif));
  6925.     printf(" ssh command-as-subsystem: %s\n",showoff(ssh_cas));
  6926.     printf(" ssh compression:          %s\n",showoff(ssh_cmp));
  6927.     printf(" ssh identify-file:        %s\n",showstring(ssh_idf));
  6928.     printf(" ssh mac:                  %s\n",showstring(ssh_mac));
  6929.     printf(" ssh privileged-port:      %s\n",showooa(ssh_prp));
  6930.     printf(" ssh quiet:                %s\n",showoff(ssh_shh));
  6931.     printf(" ssh verbose:              %d\n",ssh_vrb);
  6932.     printf(" ssh version:              %s\n",
  6933.        ssh_ver ? ckitoa(ssh_ver) : "automatic"
  6934.        );
  6935.     printf(" ssh x11-forwarding:       %s\n",showooa(ssh_xfw));
  6936. #else
  6937. #ifdef SSHCMD
  6938.     extern char * sshcmd, * defsshcmd;
  6939.     char * s;
  6940.     s = sshcmd ? sshcmd : defsshcmd;
  6941.     printf("\n SSH is external.\n\n");
  6942.     printf(" ssh command: %s\n",showstring(s));
  6943. #endif /* SSHCMD */
  6944. #endif /* SSHBUILTIN */
  6945.     printf("\n");
  6946. }
  6947.  
  6948. static int
  6949. dosetssh() {
  6950. #ifdef SSHCMD
  6951.     extern char * sshcmd;
  6952. #endif /* SSHCMD */
  6953.     int x, y;
  6954.     char * s;
  6955.  
  6956.     if ((x = cmkey(sshtab,nsshtab,"","command", xxstring)) < 0)
  6957.       return(x);
  6958.     switch (x) {
  6959. #ifdef SSHCMD
  6960.       case SSH_CMD:            /* Command */
  6961.     if ((x = cmtxt("Command to start ssh","ssh -e none",
  6962.                &s,xxstring)) < 0)
  6963.       return(x);
  6964.     makestr(&sshcmd,s);
  6965.     return(success = 1);
  6966. #endif /* SSHCMD */
  6967.  
  6968. #ifdef SSHBUILTIN
  6969.       case SSH_AFW:            /* Agent-forwarding */
  6970.     return(success = seton(&ssh_afw));
  6971.  
  6972.       case SSH_XFW:            /* X11-forwarding */
  6973.     return(success = seton(&ssh_xfw));
  6974.  
  6975.       case SSH_VER:            /* Version */
  6976.     if ((x = cmkey(sshver,3,"","auto", xxstring)) < 0)
  6977.       return(x);
  6978.     if ((x = cmcfm()) < 0)
  6979.       return(x);
  6980.     ssh_ver = x;            /* 0 == AUTO */
  6981.     return(success = 1);
  6982.  
  6983.       case SSH_IDF:            /* ID file */
  6984.     if ((x = cmifi("Filename","",&s,&y,xxstring)) < 0)
  6985.       return(x);
  6986.     ckstrncpy(line,s,LINBUFSIZ);
  6987.     s = line;
  6988.     if ((x = cmcfm()) < 0)
  6989.       return(x);
  6990.     makestr(&ssh_idf,s);
  6991.     return(success = 1);
  6992.  
  6993.       case SSH_PRP:            /* Privd port */
  6994.     return(success = setonaut(&ssh_prp));
  6995.  
  6996.       case SSH_CIF:            /* Cipher */
  6997.         /* to be replaced by a runtime constructed keyword list */
  6998.     if ((x = cmtxt("SSH cipher list","",&s,xxstring)) < 0)
  6999.       return(x);
  7000.     makestr(&ssh_cif,s);
  7001.     return(success = 1);
  7002.  
  7003.       case SSH_MAC:            /* MAC */
  7004.         /* to be replaced by a runtime constructed keyword list */
  7005.     if ((x = cmtxt("SSH mac list","",&s,xxstring)) < 0)
  7006.       return(x);
  7007.     makestr(&ssh_mac,s);
  7008.     return(success = 1);
  7009.  
  7010.       case SSH_CMP:            /* Compression */
  7011.     return(success = seton(&ssh_cmp));
  7012.  
  7013.       case SSH_CAS:            /* command-as-subsys */
  7014.     return(success = seton(&ssh_cas));
  7015.  
  7016.       case SSH_SHH:            /* Quiet */
  7017.     return(success = seton(&ssh_shh));
  7018.  
  7019.       case SSH_VRB:            /* Verbosity level */
  7020.     y = cmnum("SSH verbosity level, 0-7","2",10,&x,xxstring);
  7021.     return(setnum(&ssh_vrb,x,y,7));
  7022.  
  7023.       case SSH_AV2:            /* Auto-V2-Rekey */
  7024.     if ((y = cmnum("Seconds","2",10,&x,xxstring)) < 0)
  7025.       return(y);
  7026.     ssh_av2 = x;
  7027.     return(success = 1);
  7028. #endif /* SSHBUILTIN */
  7029.       default:
  7030.     return(-2);
  7031.     }
  7032. }
  7033. #endif /* ANYSSH */
  7034.  
  7035.  
  7036. /*  D O P R M  --  Set a parameter.  */
  7037. /*
  7038.  Returns:
  7039.   -2: illegal input
  7040.   -1: reparse needed
  7041.    0: success
  7042. */
  7043. int
  7044. doprm(xx,rmsflg) int xx, rmsflg; {
  7045.     int i = 0, x = 0, y = 0, z = 0;
  7046.     long zz = 0L;
  7047.     char *s = NULL, *p = NULL;
  7048. #ifdef OS2
  7049.     char portbuf[64];
  7050.     long portspeed = 0L;
  7051.     int portparity = 0;
  7052.     int portflow = 0;
  7053. #endif /* OS2 */
  7054.  
  7055. #ifndef NOSETKEY
  7056. #ifdef OS2
  7057.     if (xx == XYMSK)
  7058.       return(setmsk());
  7059. #endif /* OS2 */
  7060. #endif /* NOSETKEY */
  7061.  
  7062.     if (xx == XYFLAG) {            /* SET FLAG */
  7063.     extern int ooflag;
  7064.     return(success = seton(&ooflag));
  7065.     }
  7066.     if (xx == XYPRTR            /* SET PRINTER (or BPRINTER) */
  7067. #ifdef BPRINT
  7068.     || xx == XYBDCP
  7069. #endif /* BPRINT */
  7070.     )
  7071.       return(setprinter(xx));
  7072.  
  7073.     switch (xx) {
  7074.  
  7075. #ifdef ANYX25                /* SET X25 ... */
  7076. case XYX25:
  7077.     return(setx25());
  7078.  
  7079. #ifndef IBMX25
  7080. case XYPAD:                /* SET PAD ... */
  7081.     return(setpadp());
  7082. #endif /* IBMX25 */
  7083. #endif /* ANYX25 */
  7084.  
  7085. #ifndef NOXFER
  7086.       case XYEOL:       /* These have all been moved to set send/receive... */
  7087.       case XYLEN:     /* Let the user know what to do. */
  7088.       case XYMARK:
  7089.       case XYNPAD:
  7090.       case XYPADC:
  7091.       case XYTIMO:
  7092.     printf("...Use SET SEND or SET RECEIVE instead.\n");
  7093.     printf("Type HELP SET SEND or HELP SET RECEIVE for more info.\n");
  7094.     return(success = 0);
  7095.  
  7096.       case XYATTR:            /* File Attribute packets */
  7097.     return(setat(rmsflg));
  7098.  
  7099.       case XYIFD:            /* Incomplete file disposition */
  7100.     if ((y = cmkey(ifdatab,3,"","auto",xxstring)) < 0) return(y);
  7101.     if ((x = cmcfm()) < 0) return(x);
  7102.     if (rmsflg) {
  7103.         sstate = setgen('S',
  7104.                 "310",
  7105.                 y == 0 ? "0" : (y == 1 ? "1" : "2"),
  7106.                 ""
  7107.                 );
  7108.         return((int) sstate);
  7109.     } else {
  7110.         keep = y;
  7111.         return(success = 1);
  7112.     }
  7113. #endif /* NOXFER */
  7114.  
  7115. #ifndef NOSPL
  7116.       case XYINPU:            /* SET INPUT */
  7117.     return(setinp());
  7118. #endif /* NOSPL */
  7119.  
  7120. #ifdef NETCONN
  7121.       case XYNET: {            /* SET NETWORK */
  7122.  
  7123.       struct FDB k1, k2;
  7124.  
  7125.       cmfdbi(&k1,_CMKEY,"","","",nnetkey, 0, xxstring, netkey, &k2);
  7126.       cmfdbi(&k2,_CMKEY,"","","",nnets,   0, xxstring, netcmd, NULL);
  7127.  
  7128. #ifdef OS2     /* Hide network-type keywords for networks not installed */
  7129.       for (z = 0; z < nnets; z++) {
  7130.           if (netcmd[z].kwval == NET_TCPB && tcp_avail == 0)
  7131.         netcmd[z].flgs =  CM_INV;
  7132. #ifdef DECNET
  7133.           else if (netcmd[z].kwval == NET_DEC  && dnet_avail == 0)
  7134.         netcmd[z].flgs =  CM_INV;
  7135. #endif /* DECNET */
  7136. #ifdef CK_NETBIOS
  7137.           else if (netcmd[z].kwval == NET_BIOS && netbiosAvail == 0)
  7138.         netcmd[z].flgs =  CM_INV;
  7139. #endif /* CK_NETBIOS */
  7140. #ifdef SUPERLAT
  7141.           else if (netcmd[z].kwval == NET_SLAT  && slat_avail == 0)
  7142.         netcmd[z].flgs =  CM_INV;
  7143. #endif /* SUPERLAT */
  7144.       }
  7145.       if (tcp_avail)        /* Default network type */
  7146.         ckstrncpy(tmpbuf,"tcp/ip",TMPBUFSIZ);
  7147. #ifdef DECNET
  7148.       else if (dnet_avail)
  7149.         ckstrncpy(tmpbuf,"decnet",TMPBUFSIZ);
  7150. #endif /* DECNET */
  7151. #ifdef SUPERLAT
  7152.       else if (slat_avail)
  7153.         ckstrncpy(tmpbuf,"superlat",TMPBUFSIZ);
  7154. #endif /* SUPERLAT */
  7155. #ifdef CK_NETBIOS
  7156.       else if (netbiosAvail)
  7157.         ckstrncpy(tmpbuf,"netbios",TMPBUFSIZ);
  7158. #endif /* CK_NETBIOS */
  7159.       else ckstrncpy(tmpbuf,"named-pipe",TMPBUFSIZ);
  7160. #else
  7161. #ifdef TCPSOCKET
  7162.       ckstrncpy(tmpbuf,"tcp/ip",TMPBUFSIZ);
  7163. #else
  7164. #ifdef ANYX25
  7165.       ckstrncpy(tmpbuf,"x.25",TMPBUFSIZ);
  7166. #else
  7167.       ckstrncpy(tmpbuf,"",TMPBUFSIZ);
  7168. #endif /* ANYX25 */
  7169. #endif /* TCPSOCKET */
  7170. #endif /* OS2 */
  7171.  
  7172.       x = cmfdb(&k1);
  7173.       if (x < 0) {            /* Error */
  7174.           if (x == -2 || x == -9)
  7175.         printf("?No keywords match: \"%s\"\n",atmbuf);
  7176.           return(x);
  7177.       }
  7178.       z = cmresult.nresult;        /* Keyword value */
  7179.       if (cmresult.fdbaddr == &k1) { /* Which table? */
  7180. #ifndef NOSPL
  7181. #ifndef NODIAL
  7182.           if (z == XYNET_D)
  7183.         return(parsdir(1));
  7184. #endif /* NODIAL */
  7185. #endif /* NOSPL */
  7186.           if ((z = cmkey(netcmd,nnets,"",tmpbuf,xxstring)) < 0)
  7187.         return(z);
  7188.       }
  7189.  
  7190. #ifdef NETCMD
  7191.       if (z == NET_CMD && nopush) {
  7192.           printf("\n?Sorry, access to external commands is disabled\n");
  7193.           return(-9);
  7194.       }
  7195. #endif /* NETCMD */
  7196.  
  7197. #ifndef NOPUSH
  7198. #ifdef NETPTY
  7199.       if (z == NET_PTY && nopush) {
  7200.           printf("\n?Sorry, access to external commands is disabled\n");
  7201.           return(-9);
  7202.       }
  7203. #endif /* NETPTY */
  7204. #endif /* NOPUSH */
  7205.  
  7206. #ifdef OS2
  7207.       if (z == NET_TCPB && tcp_avail == 0) {
  7208.           printf(
  7209. "\n?Sorry, either TCP/IP is not available on this system or\n\
  7210. necessary DLLs did not load.  Use SHOW NETWORK to check network status.\n");
  7211.           return(-9);
  7212. #ifdef CK_NETBIOS
  7213.       } else if (z == NET_BIOS && netbiosAvail == 0) {
  7214.           printf("\n?Sorry, NETBIOS is not available on this system.\n") ;
  7215.           return(-9);
  7216. #endif /* CK_NETBIOS */
  7217. #ifdef DECNET
  7218.       } else if (z == NET_DEC && dnet_avail == 0) {
  7219.           printf("\n?Sorry, DECnet is not available on this system.\n") ;
  7220.           return(-9);
  7221. #endif /* DECNET */
  7222. #ifdef SUPERLAT
  7223.       } else if (z == NET_SLAT && slat_avail == 0) {
  7224.           printf("\n?Sorry, SuperLAT is not available on this system.\n") ;
  7225.           return(-9);
  7226. #endif /* SUPERLAT */
  7227.       }
  7228. #endif /* OS2 */
  7229.  
  7230. #ifdef NPIPEORBIOS
  7231.       if (z == NET_PIPE ||         /* Named pipe -- also get pipename */
  7232.           z == NET_BIOS) {        /* NETBIOS -- also get local name */
  7233.           char *defnam;
  7234. #ifdef CK_NETBIOS
  7235.           char tmpnbnam[NETBIOS_NAME_LEN+1];
  7236. #endif /* CK_NETBIOS */
  7237.           /* Construct default name  */
  7238.           if (z == NET_PIPE) {    /* Named pipe */
  7239.           defnam = "kermit";    /* Default name is always "kermit" */
  7240.           } else {            /* NetBIOS */
  7241.           if (NetBiosName[0] != SP) { /* If there is already a name, */
  7242.               char *p = NULL;
  7243.               int n;        /* use it as the default. */
  7244.               ckstrncpy(tmpnbnam,NetBiosName,NETBIOS_NAME_LEN+1);
  7245.               /* convert trailing spaces to NULs */
  7246.               p = &tmpnbnam[NETBIOS_NAME_LEN-1];
  7247.               while (*p == SP) {
  7248.               *p = NUL;
  7249.               p--;
  7250.               }
  7251.               defnam = tmpnbnam;
  7252.           } else if (*myhost)    /* Otherwise use this PC's host name */
  7253.             defnam = (char *) myhost;
  7254.           else            /* Otherwise use "kermit" */
  7255.             defnam = "kermit";
  7256.           }
  7257.           if ((y = cmtxt((z == NET_PIPE) ? "pipe name" :
  7258.                  "local NETBIOS name",
  7259.                  defnam, &s, xxstring)) < 0)
  7260.         return(y);
  7261. #ifdef NPIPE
  7262.           pipename[0] = NUL;
  7263. #endif /* NPIPE */
  7264.           if ((y = (int) strlen(s)) < 1) {
  7265.           printf("?You must also specify a %s name\n",
  7266.              (z == NET_PIPE) ? "pipe" : "local NETBIOS" );
  7267.           return(-9);
  7268.           }
  7269. #ifdef CK_NETBIOS
  7270.           if (z == NET_BIOS) {
  7271.           if (!netbiosAvail) {
  7272.               printf("?NETBIOS is not available on this system.\n") ;
  7273.               return(-9);
  7274.           }
  7275.           if (y - NETBIOS_NAME_LEN > 0) {
  7276.               printf("?NETBIOS name too long, %ld maximum\n",
  7277.                  NETBIOS_NAME_LEN);
  7278.               return(-9);
  7279.           } else if ( !strcmp(s,tmpnbnam) ) {
  7280.               nettype = z;    /* Returning to old connection... */
  7281.               return(success = 1); /* Done */
  7282.           } else if (strcmp("                ",NetBiosName)) {
  7283.               printf("?NETBIOS name already assigned to \"%s\"\n",
  7284.                  NetBiosName);
  7285.               return(-9);
  7286.           } else {
  7287.               NCB ncb;
  7288.               APIRET rc;
  7289.               ckstrncpy(NetBiosName,s,16);
  7290.               for (x = y; x < NETBIOS_NAME_LEN; x++)
  7291.             NetBiosName[x] = SP;
  7292.               NetBiosName[NETBIOS_NAME_LEN] = NUL;
  7293.               printf("Checking \"%s\" as a unique NetBIOS name...\n",
  7294.                  NetBiosName);
  7295.               rc = NCBAddName( NetbeuiAPI,
  7296.                       &ncb, NetBiosAdapter, NetBiosName );
  7297.               if (rc) {
  7298.               printf(
  7299.         "?Sorry, \"%s\" is already in use by another NetBIOS node.\n",
  7300.                  NetBiosName);
  7301.               for (x = 0; x < NETBIOS_NAME_LEN; x++)
  7302.                 NetBiosName[x] = SP;
  7303.               return(-9);
  7304.               }
  7305.           }
  7306.           }
  7307. #endif /* CK_NETBIOS */
  7308. #ifdef NPIPE
  7309.           if (z == NET_PIPE)
  7310.         ckstrncpy(pipename,s,PIPENAML);
  7311. #endif /* NPIPE */
  7312.       } else
  7313. #endif /* NPIPEORBIOS */
  7314. #ifdef DECNET
  7315.         if (z == NET_DEC) {
  7316.         /* Determine if we are using LAT or CTERM */
  7317.         if ((y = cmkey(dnettab,
  7318.                    ndnet,"DECNET protocol","lat",xxstring)) < 0)
  7319.           return(y);
  7320.         if ((x = cmcfm()) < 0) return(x);
  7321.         ttnproto = y;
  7322.         } else
  7323. #endif /* DECNET */
  7324. #ifdef NETDLL
  7325.           if (z == NET_DLL) {
  7326.           /* Find out which DLL they are using */
  7327.           char dllname[256]="";
  7328.           char * p=NULL;
  7329.           if ((x = cmifi("Dynamic load library",
  7330.                  "",&p,&y,xxstring)) < 0) {
  7331.               if (x == -3) {
  7332.               printf("?Name of DLL required\n");
  7333.               return(-9);
  7334.               }
  7335.               return(x);
  7336.           }
  7337.           ckstrncpy(dllname,p,256);
  7338.           if ((x = cmcfm()) < 0) return(x);
  7339.  
  7340.           if (netdll_load(dllname) < 0) /* Try to load the dll */
  7341.             return(success = 0);
  7342.           else {
  7343.               nettype = z;
  7344.               return(success = 1);
  7345.           }
  7346.           } else
  7347. #endif /* NETDLL */
  7348.         if ((x = cmcfm()) < 0) return(x);
  7349.       nettype = z;
  7350.       if (
  7351. #ifdef DECNET
  7352.           (nettype != NET_DEC)  &&
  7353. #endif /* DECNET */
  7354. #ifdef NPIPE
  7355.           (nettype != NET_PIPE) &&
  7356. #endif /* NPIPE */
  7357. #ifdef CK_NETBIOS
  7358.           (nettype != NET_BIOS) &&
  7359. #endif /* CK_NETBIOS */
  7360. #ifdef NETFILE
  7361.           (nettype != NET_FILE) &&
  7362. #endif /* NETFILE */
  7363. #ifdef NETCMD
  7364.           (nettype != NET_CMD) &&
  7365. #endif /* NETCMD */
  7366. #ifdef NETPTY
  7367.           (nettype != NET_PTY) &&
  7368. #endif /* NETPTY */
  7369. #ifdef NETDLL
  7370.           (nettype != NET_DLL) &&
  7371. #endif /* NETDLL */
  7372. #ifdef SUPERLAT
  7373.           (nettype != NET_SLAT) &&
  7374. #endif /* SUPERLAT */
  7375.           (nettype != NET_SX25) &&
  7376.           (nettype != NET_VX25) &&
  7377. #ifdef IBMX25
  7378.           (nettype != NET_IX25) &&
  7379. #endif /* IBMX25 */
  7380.           (nettype != NET_TCPB)) {
  7381.           printf("?Network type not supported\n");
  7382.           return(success = 0);
  7383.       } else {
  7384.           return(success = 1);
  7385.       }
  7386.       }
  7387.  
  7388. #ifndef NOTCPOPTS
  7389. #ifdef TCPSOCKET
  7390.       case XYTCP:
  7391.     if ((z = cmkey(tcpopt,ntcpopt,"TCP option","nodelay",xxstring)) < 0)
  7392.       return(z);
  7393.  
  7394.     switch (z) {
  7395. #ifndef NOHTTP
  7396.       case XYTCP_HTTP_PROXY:
  7397.         if ((y = cmtxt("hostname[:port] of HTTP proxy server",p,
  7398.                &s,xxstring)) < 0)
  7399.           return(y);
  7400. #ifdef IKSDCONF
  7401.         if (iksdcf)
  7402.           return(success = 0);
  7403. #endif /* IKSDCONF */
  7404.         if (tcp_http_proxy) {
  7405.         free(tcp_http_proxy);    /* Free any previous storage */
  7406.         tcp_http_proxy = NULL;
  7407.         }
  7408.         if (s == NULL || *s == NUL) { /* If none given */
  7409.         tcp_http_proxy = NULL;    /* remove the override string */
  7410.         return(success = 1);
  7411.         } else if ((tcp_http_proxy = malloc(strlen(s)+1))) {
  7412.         strcpy(tcp_http_proxy,s); /* (safe) Copy to new storage */
  7413.         return(success = 1);
  7414.         } else
  7415.           return(success = 0);
  7416. #endif /* NOHTTP */
  7417. #ifdef NT
  7418. #ifdef CK_SOCKS
  7419.       case XYTCP_SOCKS_SVR: {
  7420.           char * p = getenv("SOCKS_SERVER");
  7421.           if (!p) p = "";
  7422.           if ((y = cmtxt("hostname or IP of SOCKS server",p,
  7423.                  &s,xxstring)) < 0)
  7424.         return(y);
  7425. #ifdef IKSDCONF
  7426.           if (iksdcf) return(success = 0);
  7427. #endif /* IKSDCONF */
  7428.           if (tcp_socks_svr) {
  7429.           free(tcp_socks_svr);    /* Free any previous storage */
  7430.           tcp_socks_svr = NULL;
  7431.           }
  7432.           if (s == NULL || *s == NUL) { /* If none given */
  7433.           tcp_socks_svr = NULL;    /* remove the override string */
  7434.           return(success = 1);
  7435.           } else if ((tcp_socks_svr = malloc(strlen(s)+1))) {
  7436.           strcpy(tcp_socks_svr,s);
  7437.           return(success = 1);
  7438.           } else
  7439.         return(success = 0);
  7440.       }
  7441. #ifdef CK_SOCKS_NS
  7442.           case XYTCP_SOCKS_NS: {
  7443.             char * p = getenv("SOCKS_NS");
  7444.             if (!p) p = "";
  7445.             if ((y = cmtxt("hostname or IP of SOCKS Name Server",p,
  7446.                             &s,xxstring)) < 0)
  7447.         return(y);
  7448. #ifdef IKSDCONF
  7449.           if (iksdcf) return(success = 0);
  7450. #endif /* IKSDCONF */
  7451.           if (tcp_socks_ns) {
  7452.           free(tcp_socks_ns);    /* Free any previous storage */
  7453.           tcp_socks_ns = NULL;
  7454.           }
  7455.           if (s == NULL || *s == NUL) { /* If none given */
  7456.           tcp_socks_ns = NULL;    /* remove the override string */
  7457.           return(success = 1);
  7458.           } else if ((tcp_socks_ns = malloc(strlen(s)+1))) {
  7459.           strcpy(tcp_socks_ns,s);
  7460.           return(success = 1);
  7461.           } else
  7462.         return(success = 0);
  7463.       }
  7464. #endif /* CK_SOCKS_NS */
  7465. #endif /* CK_SOCKS */
  7466. #endif /* NT */
  7467.       case XYTCP_ADDRESS:
  7468.         if ((y = cmtxt("preferred IP Address for TCP connections","",
  7469.                &s,xxstring)) < 0)
  7470.           return(y);
  7471. #ifdef IKSDCONF
  7472.         if (iksdcf) return(success = 0);
  7473. #endif /* IKSDCONF */
  7474.         if (tcp_address) {
  7475.         free(tcp_address);    /* Free any previous storage */
  7476.         tcp_address = NULL;
  7477.         }
  7478.         if (s == NULL || *s == NUL) { /* If none given */
  7479.         tcp_address = NULL;    /* remove the override string */
  7480.         return(success = 1);
  7481.         } else if ((tcp_address = malloc(strlen(s)+1))) {
  7482.         strcpy(tcp_address,s);
  7483.         return(success = 1);
  7484.         } else
  7485.           return(success = 0);
  7486. #ifdef SO_KEEPALIVE
  7487.       case XYTCP_KEEPALIVE:
  7488.         if ((z = cmkey(onoff,2,"","on",xxstring)) < 0) return(z);
  7489.         if ((y = cmcfm()) < 0) return(y);
  7490. #ifdef IKSDCONF
  7491.         if (iksdcf) return(success = 0);
  7492. #endif /* IKSDCONF */
  7493.         success = keepalive(z);
  7494.         return(success);
  7495. #endif /* SO_KEEPALIVE */
  7496. #ifdef SO_DONTROUTE
  7497.       case XYTCP_DONTROUTE:
  7498.         if ((z = cmkey(onoff,2,"","off",xxstring)) < 0) return(z);
  7499.         if ((y = cmcfm()) < 0) return(y);
  7500. #ifdef IKSDCONF
  7501.         if (iksdcf) return(success = 0);
  7502. #endif /* IKSDCONF */
  7503.         success = dontroute(z);
  7504.         return(success);
  7505. #endif /* SO_DONTROUTE */
  7506. #ifdef TCP_NODELAY
  7507.       case XYTCP_NODELAY:
  7508.         if ((z = cmkey(onoff,2,"","off",xxstring)) < 0) return(z);
  7509.         if ((y = cmcfm()) < 0) return(y);
  7510. #ifdef IKSDCONF
  7511.         if (iksdcf) return(success = 0);
  7512. #endif /* IKSDCONF */
  7513.         success = no_delay(z);
  7514.         return(success);
  7515.       case XYTCP_NAGLE:        /* The inverse of NODELAY */
  7516.         if ((z = cmkey(onoff,2,"","on",xxstring)) < 0) return(z);
  7517.         if ((y = cmcfm()) < 0) return(y);
  7518. #ifdef IKSDCONF
  7519.         if (iksdcf) return(success = 0);
  7520. #endif /* IKSDCONF */
  7521.         success = no_delay(!z);
  7522.         return(success);
  7523. #endif /* TCP_NODELAY */
  7524. #ifdef SO_LINGER
  7525.       case XYTCP_LINGER:
  7526.         if ((z = cmkey(onoff,2,"","on",xxstring)) < 0)
  7527.           return(z);
  7528.         if (z) {            /* if on, we need a timeout value */
  7529.         if ((x = cmnum("Linger timeout in 10th of a millisecond",
  7530.                    "0",10,&y,xxstring)) < 0)
  7531.           return(x);
  7532.         } else
  7533.           y = 0;
  7534.         if ((x = cmcfm()) < 0)
  7535.           return(x);
  7536. #ifdef IKSDCONF
  7537.         if (iksdcf) return(success = 0);
  7538. #endif /* IKSDCONF */
  7539.         success = ck_linger(z,y);
  7540.         return(success);
  7541. #endif /* SO_LINGER */
  7542. #ifdef SO_SNDBUF
  7543.       case XYTCP_SENDBUF:
  7544.         x = cmnum("Send buffer size, bytes","8192",10,&z,xxstring);
  7545.         if (x < 0) return(x);
  7546.         if ((x = cmcfm()) < 0) return(x);
  7547. #ifdef IKSDCONF
  7548.         if (iksdcf) return(success = 0);
  7549. #endif /* IKSDCONF */
  7550.         success = sendbuf(z);
  7551.         return(success);
  7552. #endif /* SO_SNDBUF */
  7553. #ifdef SO_RCVBUF
  7554.       case XYTCP_RECVBUF:
  7555.         x = cmnum("Receive buffer size, bytes","8192",10,&z,xxstring);
  7556.         if (x < 0) return(x);
  7557.         if ((x = cmcfm()) < 0) return(x);
  7558. #ifdef IKSDCONF
  7559.         if (iksdcf) return(success = 0);
  7560. #endif /* IKSDCONF */
  7561.  
  7562. /* Note: The following is not 16-bit safe */
  7563.  
  7564. #ifndef QNX16
  7565.         if (x > 52248) {
  7566.         printf("?Warning: receive buffers larger than 52248 bytes\n");
  7567.         printf(" may not be understood by all hosts.  Performance\n");
  7568.         printf(" may suffer.\n");
  7569.         return(-9);
  7570.         }
  7571. #endif /* QNX16 */
  7572.         success = recvbuf(z);
  7573.         return(success);
  7574. #endif /* SO_RCVBUF */
  7575.  
  7576. #ifdef VMS
  7577. #ifdef DEC_TCPIP
  7578.       case XYTCP_UCX: {        /* UCX 2.0 port swabbing bug */
  7579.           extern int ucx_port_bug;
  7580.           return(success = seton(&ucx_port_bug));
  7581.       }
  7582. #endif /* DEC_TCPIP */
  7583. #endif /* VMS */
  7584.  
  7585.       case XYTCP_RDNS: {
  7586.           extern int tcp_rdns;
  7587.           return(success = setonaut(&tcp_rdns));
  7588.       }
  7589.  
  7590. #ifdef CK_DNS_SRV
  7591.       case XYTCP_DNS_SRV: {
  7592.           extern int tcp_dns_srv;
  7593.           return(success = setonaut(&tcp_dns_srv));
  7594.       }
  7595. #endif /* CK_DNS_SRV */
  7596.  
  7597.       default:
  7598.         return(0);
  7599.     }
  7600. #endif /* TCPSOCKET */
  7601. #endif /* NOTCPOPTS */
  7602. #endif /* NETCONN */
  7603.     }
  7604.  
  7605.     switch (xx) {
  7606.  
  7607. #ifndef NOLOCAL
  7608. #ifdef NETCONN
  7609.       case XYHOST: {            /* SET HOST */
  7610.       z = ttnproto;            /* Save protocol in case of failure */
  7611. #ifdef DECNET
  7612.       if (nettype != NET_DEC)
  7613. #endif /* DECNET */
  7614.         ttnproto = NP_NONE;
  7615.       if ((y = setlin(XYHOST,1,0)) < 0) {
  7616.           debug(F101,"SET HOST fail mdmtyp","",mdmtyp);
  7617.           ttnproto = z;        /* Failed, restore protocol */
  7618.           success = 0;
  7619.       }
  7620.       didsetlin++;
  7621.       debug(F101,"SET HOST OK mdmtyp","",mdmtyp);
  7622.       debug(F101,"SET HOST reliable","",reliable);
  7623.       return(y);
  7624.       }
  7625. #endif /* NETCONN */
  7626.  
  7627.       case XYLINE:            /* SET LINE (= SET PORT) */
  7628.     debug(F101,"setlin flow 1","",flow);
  7629.     x = setlin(xx,1,0);
  7630.     if (x > -1) didsetlin++;
  7631.     debug(F101,"SET LINE setlin","",x);
  7632.     debug(F101,"SET LINE flow","",flow);
  7633.     debug(F101,"SET LINE local","",local);
  7634.     debug(F101,"SET LINE reliable","",reliable);
  7635.     return(x);
  7636. #endif /* NOLOCAL */
  7637.  
  7638. #ifndef NOSETKEY
  7639.       case XYKEY:            /* SET KEY */
  7640.     return(dosetkey());
  7641. #endif /* NOSETKEY */
  7642.  
  7643. #ifndef NOCSETS
  7644.       case XYLANG:            /* Language */
  7645.     if ((y = cmkey(lngtab,nlng,"","none",xxstring)) < 0)
  7646.       return(y);
  7647.     if ((x = cmcfm()) < 0) return(x);
  7648.  
  7649.     /* Look up language and get associated character sets */
  7650.     for (i = 0; (i < nlangs) && (langs[i].id != y); i++) ;
  7651.     if (i >= nlangs) {
  7652.         printf("?internal error, sorry\n");
  7653.         return(success = 0);
  7654.     } /*  */
  7655.     language = i;            /* All good, set the language, */
  7656.     return(success = 1);
  7657. #endif /* NOCSETS */
  7658.  
  7659. #ifndef MAC
  7660.       case XYBACK:            /* BACKGROUND */
  7661.     if ((z = cmkey(onoff,2,"","",xxstring)) < 0) return(z);
  7662.     if ((y = cmcfm()) < 0) return(y);
  7663.     bgset = z;
  7664. #ifdef VMS
  7665.     if (batch && bgset == 0)    /* To enable echoing of commands */
  7666.       ckxech = 1;            /* in VMS batch logs */
  7667. #endif /* VMS */
  7668.     success = 1;
  7669.     bgchk();
  7670.     return(success);
  7671. #endif /* MAC */
  7672.  
  7673.       case XYQUIE: {            /* QUIET */
  7674. #ifdef DCMDBUF
  7675.       extern int * xquiet;
  7676. #else
  7677.       extern int xquiet[];
  7678. #endif /* DCMDBUF */
  7679.       x = seton(&quiet);
  7680.       if (x < 0) return(x);
  7681.       xquiet[cmdlvl] = quiet;
  7682.       return(success = x);
  7683.       }
  7684.  
  7685. #ifndef NOXFER
  7686.       case XYBUF: {            /* BUFFERS */
  7687. #ifdef DYNAMIC
  7688.       int sb, rb;
  7689.       if ((y = cmnum("Send buffer size","",10,&sb,xxstring)) < 0) {
  7690.           if (y == -3) printf("?Buffer size required\n");
  7691.           return(y);
  7692.       }
  7693.       if (sb < 0) {
  7694.           if (*atmbuf == '-')
  7695.         printf("?Negative numbers can't be used here\n");
  7696.           else printf("?Integer overflow, use a smaller number please\n");
  7697.           return(-9);
  7698.       } else if (sb < 80) {
  7699.           printf("?Too small\n");
  7700.           return(-9);
  7701.       }
  7702.       if ((y=cmnum("Receive buffer size",ckitoa(sb),10,&rb,xxstring)) < 0)
  7703.         return(y);
  7704.       if (rb < 0) {
  7705.           if (*atmbuf == '-')
  7706.         printf("?Negative numbers can't be used here\n");
  7707.           else printf("?Integer overflow, use a smaller number please\n");
  7708.           return(-9);
  7709.       } else if (rb < 80) {
  7710.           printf("?Too small\n");
  7711.           return(-9);
  7712.       }
  7713.       if ((y = cmcfm()) < 0) return(y);
  7714.       if ((y = inibufs(sb,rb)) < 0) return(y);
  7715.       y = adjpkl(urpsiz,wslotr,bigrbsiz); /* Maybe adjust packet sizes */
  7716.       if (y != urpsiz) urpsiz = y;
  7717.       y = adjpkl(spsiz,wslotr,bigsbsiz);
  7718.       if (y != spsiz) spsiz = spmax = spsizr = y;
  7719.       return(success = 1);
  7720. #else
  7721.       printf("?Sorry, not available\n");
  7722.       return(success = 0);
  7723. #endif /* DYNAMIC */
  7724.       }
  7725.  
  7726.       case XYCHKT:            /* BLOCK-CHECK */
  7727.     if ((x = cmkey(chktab,4,"","3",xxstring)) < 0) return(x);
  7728.     if ((y = cmcfm()) < 0) return(y);
  7729.     bctr = x;            /* Set local too even if REMOTE SET */
  7730.     if (rmsflg) {
  7731.         if (x == 4) {
  7732.         tmpbuf[0] = 'B';
  7733.         tmpbuf[1] = '\0';
  7734.         } else
  7735.           ckstrncpy(tmpbuf,ckitoa(x),TMPBUFSIZ);
  7736.         sstate = setgen('S', "400", tmpbuf, "");
  7737.         return((int) sstate);
  7738.     } else {
  7739.         return(success = 1);
  7740.     }
  7741. #endif /* NOXFER */
  7742.  
  7743. #ifndef NOLOCAL
  7744. #ifndef MAC                /* The Mac has no RS-232 */
  7745. case XYCARR:                /* CARRIER-WATCH */
  7746.     return(setdcd());
  7747. #endif /* MAC */
  7748. #endif /* NOLOCAL */
  7749.     }
  7750.  
  7751. #ifdef TNCODE
  7752.     switch (xx) {            /* Avoid long switch statements... */
  7753.       case XYTELOP: {
  7754.       int c, n;            /* Workers */
  7755.       int getval = 0;        /* Whether to get switch value */
  7756.       int tnserver = 0;        /* Client by default */
  7757.       int opt = -1;            /* Telnet Option */
  7758.       struct FDB sw, op;        /* FDBs for each parse function */
  7759. #ifdef CK_AUTHENTICATION
  7760.       extern int sl_topt_a_s_saved;
  7761.       extern int sl_topt_a_c_saved;
  7762.       extern int sl_topt_e_s_saved;
  7763.       extern int sl_topt_e_c_saved;
  7764. #endif /* CK_AUTHENTICATION */
  7765. #ifdef IKSD
  7766.       if (inserver)            /* Server by default when IKSD */
  7767.         tnserver = 1;
  7768. #endif /* IKSD */
  7769.  
  7770.       /* Set up chained parse functions... */
  7771.  
  7772.       cmfdbi(&op,            /* First fdb - telopts*/
  7773.          _CMKEY,        /* fcode */
  7774.          "/client, /server or",    /* hlpmsg */
  7775.          "",            /* default */
  7776.          "",            /* addtl string data */
  7777.          ntnopt,        /* addtl numeric data 1 */
  7778.          0,            /* addtl numeric data 2 */
  7779.          xxstring,
  7780.          tnopttab,
  7781.          &sw
  7782.          );
  7783.       cmfdbi(&sw,            /* Second FDB - command switches */
  7784.          _CMKEY,        /* fcode */
  7785.          "",            /* hlpmsg */
  7786.          "",            /* default */
  7787.          "",            /* addtl string data */
  7788.          ntnoptsw,        /* addtl numeric data 1: tbl size */
  7789.          4,            /* addtl numeric data 2: 4 = cmswi */
  7790.          xxstring,        /* Processing function */
  7791.          tnoptsw,        /* Keyword table */
  7792.          NULL            /* Pointer to next FDB */
  7793.          );
  7794.  
  7795.       while (opt < 0) {        /* Parse 0 or more switches */
  7796.           x = cmfdb(&op);        /* Parse switch or other thing */
  7797.           debug(F101,"XYTELOP cmfdb","",x);
  7798.           if (x < 0)        /* Error */
  7799.         return(x);        /* or reparse needed */
  7800.           if (cmresult.fcode != _CMKEY) /* Break out if not a switch */
  7801.         break;
  7802.           c = cmgbrk();        /* Get break character */
  7803.           getval = (c == ':' || c == '='); /* see how switch ended */
  7804.           if (getval && !(cmresult.kflags & CM_ARG)) {
  7805.           printf("?This switch does not take arguments\n");
  7806.           return(-9);
  7807.           }
  7808.           z = cmresult.nresult;    /* Numeric result = switch value */
  7809.           debug(F101,"XYTELOP switch","",z);
  7810.  
  7811.           switch (z) {        /* Process the switch */
  7812.         case CK_TN_CLIENT:
  7813.           tnserver = 0;
  7814.           break;
  7815.         case CK_TN_SERVER:
  7816.           tnserver = 1;
  7817.             break;
  7818.         case CK_TN_EC:
  7819.           opt = TELOPT_ECHO;
  7820.           break;
  7821.         case CK_TN_TT:
  7822.           opt = TELOPT_TTYPE;
  7823.           break;
  7824.         case CK_TN_BM:
  7825.           opt = TELOPT_BINARY;
  7826.           break;
  7827.         case CK_TN_ENV:
  7828.           opt = TELOPT_NEWENVIRON;
  7829.           break;
  7830.         case CK_TN_LOC:
  7831.           opt = TELOPT_SNDLOC;
  7832.           break;
  7833.         case CK_TN_AU:
  7834.           opt = TELOPT_AUTHENTICATION;
  7835.           break;
  7836.         case CK_TN_FX:
  7837.           opt = TELOPT_FORWARD_X;
  7838.           break;
  7839.         case CK_TN_ENC:
  7840.           opt = TELOPT_ENCRYPTION;
  7841.           break;
  7842.         case CK_TN_IKS:
  7843.           opt = TELOPT_KERMIT;
  7844.           break;
  7845.         case CK_TN_TLS:
  7846.           opt = TELOPT_START_TLS;
  7847.           break;
  7848.         case CK_TN_XD:
  7849.           opt = TELOPT_XDISPLOC;
  7850.           break;
  7851.         case CK_TN_NAWS:
  7852.           opt = TELOPT_NAWS;
  7853.           break;
  7854.         case CK_TN_SGA:
  7855.           opt = TELOPT_SGA;
  7856.           break;
  7857.         case CK_TN_PHR:
  7858.           opt = TELOPT_PRAGMA_HEARTBEAT;
  7859.           break;
  7860.         case CK_TN_PSP:
  7861.           opt = TELOPT_SSPI_LOGON;
  7862.           break;
  7863.         case CK_TN_PLG:
  7864.           opt = TELOPT_PRAGMA_LOGON;
  7865.           break;
  7866.         case CK_TN_SAK:
  7867.           opt = TELOPT_IBM_SAK;
  7868.           break;
  7869.         case CK_TN_CPC:
  7870.           opt = TELOPT_COMPORT;
  7871.           break;
  7872.         case CK_TN_LOG:
  7873.           opt = TELOPT_LOGOUT;
  7874.           break;
  7875.         case CK_TN_FLW:
  7876.           opt = TELOPT_LFLOW;
  7877.           break;
  7878.         default:
  7879.           printf("?Unexpected value - %d\n",z);
  7880.           return(-9);
  7881.           }
  7882. #ifdef COMMENT
  7883.           if (cmresult.fdbaddr == &op)
  7884.         break;
  7885. #endif /* COMMENT */
  7886.       }
  7887.       switch (opt) {
  7888.         case TELOPT_ECHO:        /* Options only the Server WILL */
  7889.         case TELOPT_FORWARD_X:
  7890.         case TELOPT_SEND_URL:
  7891.         case TELOPT_IBM_SAK:
  7892.         case TELOPT_LOGOUT:
  7893.           if ((x = cmkey(tnnegtab,
  7894.                  ntnnegtab,
  7895.                  "desired server state",
  7896.    TELOPT_MODE(tnserver?TELOPT_DEF_S_ME_MODE(opt):TELOPT_DEF_C_U_MODE(opt)),
  7897.                  xxstring)
  7898.            ) < 0)
  7899.         return(x);
  7900.           if ((z = cmcfm()) < 0)
  7901.           return(z);
  7902.           if (tnserver) {
  7903.           TELOPT_DEF_S_ME_MODE(opt) = x;
  7904.           TELOPT_ME_MODE(opt) = x;
  7905.           } else {
  7906.           TELOPT_DEF_C_U_MODE(opt) = x;
  7907.           TELOPT_U_MODE(opt) = x;
  7908.           }
  7909.           break;
  7910.  
  7911.         case TELOPT_TTYPE:        /* Options only the Client WILL */
  7912.         case TELOPT_NEWENVIRON:
  7913.         case TELOPT_SNDLOC:
  7914.         case TELOPT_AUTHENTICATION:
  7915.         case TELOPT_START_TLS:
  7916.         case TELOPT_XDISPLOC:
  7917.         case TELOPT_NAWS:
  7918.         case TELOPT_LFLOW:
  7919.         case TELOPT_COMPORT:
  7920.           if ((x = cmkey(tnnegtab,
  7921.                  ntnnegtab,
  7922.                  "desired client state",
  7923.     TELOPT_MODE(!tnserver?TELOPT_DEF_S_U_MODE(opt):TELOPT_DEF_C_ME_MODE(opt)),
  7924.                  xxstring)
  7925.            ) < 0)
  7926.         return(x);
  7927.           if ((z = cmcfm()) < 0)
  7928.         return(z);
  7929.           if (tnserver) {
  7930.           TELOPT_DEF_S_U_MODE(opt) = x;
  7931.           TELOPT_U_MODE(opt) = x;
  7932. #ifdef CK_AUTHENTICATION
  7933.           if (opt == TELOPT_AUTHENTICATION)
  7934.             sl_topt_a_s_saved = 0;
  7935. #endif /* CK_AUTHENTICATION */
  7936.           } else {
  7937.           TELOPT_DEF_C_ME_MODE(opt) = x;
  7938.           TELOPT_ME_MODE(opt) = x;
  7939. #ifdef CK_AUTHENTICATION
  7940.           if (opt == TELOPT_AUTHENTICATION)
  7941.             sl_topt_a_c_saved = 0;
  7942. #endif /* CK_AUTHENTICATION */
  7943.           }
  7944.           break;
  7945.  
  7946.         default:
  7947.           if ((x = cmkey(tnnegtab,
  7948.                  ntnnegtab,
  7949.                  tnserver ?
  7950.                  "desired server state" :
  7951.                  "desired client state",
  7952.     TELOPT_MODE(tnserver?TELOPT_DEF_S_ME_MODE(opt):TELOPT_DEF_C_ME_MODE(opt)),
  7953.                  xxstring
  7954.                  )
  7955.            ) < 0)
  7956.         return(x);
  7957.           if ((y = cmkey(tnnegtab,
  7958.                  ntnnegtab,
  7959.                  !tnserver ? "desired server state" :
  7960.                  "desired client state",
  7961.     TELOPT_MODE(!tnserver?TELOPT_DEF_S_U_MODE(opt):TELOPT_DEF_C_U_MODE(opt)),
  7962.                  xxstring
  7963.                  )
  7964.            ) < 0)
  7965.         return(y);
  7966.           if ((z = cmcfm()) < 0)
  7967.         return(z);
  7968.           if (tnserver) {
  7969.           TELOPT_DEF_S_ME_MODE(opt) = x;
  7970.           TELOPT_ME_MODE(opt) = x;
  7971.           TELOPT_DEF_S_U_MODE(opt) = y;
  7972.           TELOPT_U_MODE(opt) = y;
  7973. #ifdef CK_ENCRYPTION
  7974.           if (opt == TELOPT_ENCRYPTION)
  7975.             sl_topt_e_s_saved = 0;
  7976. #endif /* CK_ENCRYPTION */
  7977.           } else {
  7978.           TELOPT_DEF_C_ME_MODE(opt) = x;
  7979.           TELOPT_ME_MODE(opt) = x;
  7980.           TELOPT_DEF_C_U_MODE(opt) = y;
  7981.           TELOPT_U_MODE(opt) = y;
  7982. #ifdef CK_ENCRYPTION
  7983.           if (opt == TELOPT_ENCRYPTION)
  7984.             sl_topt_e_c_saved = 0;
  7985. #endif /* CK_ENCRYPTION */
  7986.           }
  7987.       }
  7988.       return(success = 1);
  7989.       }
  7990.  
  7991.       case XYTEL:            /* TELNET */
  7992.     if ((z = cmkey(tntab,ntn,"parameter for TELNET negotiations", "",
  7993.                xxstring)) < 0)
  7994.       return(z);
  7995.     switch (z) {
  7996.       case CK_TN_EC:        /* ECHO */
  7997.         if ((x = cmkey(rltab,nrlt,
  7998.                "initial TELNET echoing state",
  7999.                "local",xxstring)) < 0)
  8000.           return(x);
  8001.         if ((y = cmcfm()) < 0) return(y);
  8002.         tn_duplex = x;
  8003.         return(success = 1);
  8004.  
  8005.       case CK_TN_RE:        /* REMOTE-ECHO */
  8006.         return(success = seton(&tn_rem_echo));
  8007.  
  8008.       case CK_TN_DB:        /* DEBUG */
  8009.         return(success = seton(&tn_deb));
  8010.  
  8011.       case CK_TN_TT:        /* TERMINAL TYPE */
  8012.         if ((y = cmtxt("terminal type for TELNET connections","",
  8013.                &s,xxstring)) < 0)
  8014.           return(y);
  8015.         if (tn_term) {
  8016.         free(tn_term);        /* Free any previous storage */
  8017.         tn_term = NULL;
  8018.         }
  8019.         if (s == NULL || *s == NUL) { /* If none given */
  8020.         tn_term = NULL;        /* remove the override string */
  8021.         return(success = 1);
  8022.         } else if ((tn_term = malloc(strlen(s)+1))) {
  8023.         strcpy(tn_term,s);
  8024.         return(success = 1);
  8025.         } else return(success = 0);
  8026.  
  8027. #ifdef CK_FORWARD_X
  8028.       case CK_TN_FX:        /* FORWARD-X */
  8029.         if ((x=cmkey(tnfwdxtab,ntnfwdx,"","xauthority-file",xxstring)) < 0)
  8030.               return(x);
  8031.         if (x == 0) {        /* Xauthority-File */
  8032.         x = cmifi("Full path of .Xauthority file","",&s,&y,xxstring);
  8033.         if (x < 0 && x != -3)
  8034.                   return(x);
  8035.         makestr(&tn_fwdx_xauthority,s);
  8036.         return(success = 1);
  8037.         }
  8038.         return(success = 0);
  8039. #endif /* CK_FORWARD_X */
  8040.  
  8041.       case CK_TN_NL:        /* TELNET NEWLINE-MODE */
  8042.         if ((x = cmkey(tn_nlmtab,ntn_nlm,"","nvt",xxstring)) < 0)
  8043.           return(x);
  8044.         if (x == TN_NL_BIN) {
  8045.           if ((x = cmkey(tnlmtab,ntnlm,"","raw",xxstring)) < 0)
  8046.         return(x);
  8047.           if ((y = cmcfm()) < 0)
  8048.         return(y);
  8049.           tn_b_nlm = x;
  8050.           return(success = 1);
  8051.       } else if (x == TN_NL_NVT) {
  8052.           if ((x = cmkey(tnlmtab,ntnlm,"","on",xxstring)) < 0)
  8053.         return(x);
  8054.           if ((y = cmcfm()) < 0)
  8055.         return(y);
  8056.           tn_nlm = x;
  8057.           return(success = 1);
  8058.       } else {
  8059.           if ((y = cmcfm()) < 0)
  8060.         return(y);
  8061.           tn_nlm = x;
  8062.           return(success = 1);
  8063.       }
  8064.  
  8065.     case CK_TN_XF:            /* BINARY-TRANSFER-MODE */
  8066.         if ((z = cmkey(onoff,2,"","on",xxstring)) < 0) return(z);
  8067.         if ((y = cmcfm()) < 0) return(y);
  8068.         tn_b_xfer = z;
  8069.         return(success = 1);
  8070.  
  8071.     case CK_TN_NE:            /* NO-ENCRYPT-DURING-XFER */
  8072.         if ((z = cmkey(onoff,2,"","on",xxstring)) < 0) return(z);
  8073.         if ((y = cmcfm()) < 0) return(y);
  8074. #ifdef CK_APC
  8075.         /* Don't let this be set remotely */
  8076.         if (apcactive == APC_LOCAL ||
  8077.         (apcactive == APC_REMOTE && !(apcstatus & APC_UNCH)))
  8078.               return(success = 0);
  8079. #endif /* CK_APC */
  8080.         tn_no_encrypt_xfer = z;
  8081.         return(success = 1);
  8082.  
  8083.       case CK_TN_BM:        /* BINARY-MODE */
  8084.         if ((x = cmkey(tnnegtab,ntnnegtab,"","refused",xxstring)) < 0)
  8085.           return(x);
  8086.         if ((y = cmcfm()) < 0)
  8087.           return(y);
  8088.         TELOPT_DEF_S_ME_MODE(TELOPT_BINARY) = x;
  8089.         TELOPT_DEF_S_U_MODE(TELOPT_BINARY) = x;
  8090.         TELOPT_DEF_C_ME_MODE(TELOPT_BINARY) = x;
  8091.         TELOPT_DEF_C_U_MODE(TELOPT_BINARY) = x;
  8092.         return(success = 1);
  8093.  
  8094. #ifdef IKS_OPTION
  8095.       case CK_TN_IKS:        /* KERMIT */
  8096.         if ((x = cmkey(tnnegtab,ntnnegtab,"DO","accept",xxstring)) < 0)
  8097.           return(x);
  8098.         if ((y = cmkey(tnnegtab,ntnnegtab,"WILL","accept",xxstring)) < 0)
  8099.           return(y);
  8100.         if ((z = cmcfm()) < 0)
  8101.           return(z);
  8102.         TELOPT_DEF_S_ME_MODE(TELOPT_KERMIT) = y;
  8103.         TELOPT_DEF_S_U_MODE(TELOPT_KERMIT) = x;
  8104.         TELOPT_DEF_C_ME_MODE(TELOPT_KERMIT) = y;
  8105.         TELOPT_DEF_C_U_MODE(TELOPT_KERMIT) = x;
  8106.         return(success = 1);
  8107. #endif /* IKS_OPTION */
  8108.  
  8109. #ifdef CK_SSL
  8110.       case CK_TN_TLS:        /* START_TLS */
  8111.         if ((x = cmkey(tnnegtab,ntnnegtab,"me","accept",xxstring)) < 0)
  8112.           return(x);
  8113.         if ((y = cmkey(tnnegtab,ntnnegtab,"u","accept",xxstring)) < 0)
  8114.           return(y);
  8115.         if ((z = cmcfm()) < 0)
  8116.           return(z);
  8117.         TELOPT_DEF_S_ME_MODE(TELOPT_START_TLS) = x;
  8118.         TELOPT_DEF_S_U_MODE(TELOPT_START_TLS) = y;
  8119.         TELOPT_DEF_C_ME_MODE(TELOPT_START_TLS) = x;
  8120.         TELOPT_DEF_C_U_MODE(TELOPT_START_TLS) = y;
  8121.         return(success = 1);
  8122. #endif /* CK_SSL */
  8123.  
  8124. #ifdef CK_NAWS
  8125.       case CK_TN_NAWS:        /* NAWS */
  8126.         if ((x = cmkey(tnnegtab,ntnnegtab,"me","accept",xxstring)) < 0)
  8127.           return(x);
  8128.         if ((y = cmkey(tnnegtab,ntnnegtab,"u","accept",xxstring)) < 0)
  8129.           return(y);
  8130.         if ((z = cmcfm()) < 0)
  8131.           return(z);
  8132.         TELOPT_DEF_S_ME_MODE(TELOPT_NAWS) = x;
  8133.         TELOPT_DEF_S_U_MODE(TELOPT_NAWS) = y;
  8134.         TELOPT_DEF_C_ME_MODE(TELOPT_NAWS) = x;
  8135.         TELOPT_DEF_C_U_MODE(TELOPT_NAWS) = y;
  8136.         return(success = 1);
  8137. #endif /* CK_NAWS */
  8138.  
  8139. #ifdef CK_AUTHENTICATION
  8140.       case CK_TN_AU:        /* AUTHENTICATION */
  8141.         if ((x = cmkey(tnauthtab,ntnauth,"","",xxstring)) < 0)
  8142.           return(x);
  8143.         if (x == TN_AU_FWD) {
  8144.         extern int forward_flag;
  8145.         return(success = seton(&forward_flag));
  8146.         } else if (x == TN_AU_TYP) {
  8147.         extern int auth_type_user[];
  8148.         extern int sl_auth_type_user[];
  8149.         extern int sl_auth_saved;
  8150.         int i, j, atypes[AUTHTYPLSTSZ];
  8151.  
  8152.         for (i = 0; i < AUTHTYPLSTSZ; i++) {
  8153.             if ((y = cmkey(autyptab,nautyp,"",
  8154.                    i == 0 ? "automatic" : "" ,
  8155.                    xxstring)) < 0) {
  8156.             if (y == -3)
  8157.               break;
  8158.             return(y);
  8159.             }
  8160.             if (i > 0 && (y == AUTHTYPE_AUTO || y == AUTHTYPE_NULL)) {
  8161.             printf(
  8162.                 "\r\n?Choice may only be used in first position.\r\n");
  8163.             return(-9);
  8164.             }
  8165.             for (j = 0; j < i; j++) {
  8166.             if (atypes[j] == y) {
  8167.                 printf("\r\n?Choice has already been used.\r\n");
  8168.                 return(-9);
  8169.             }
  8170.             }
  8171.             atypes[i] = y;
  8172.             if (y == AUTHTYPE_NULL || y == AUTHTYPE_AUTO) {
  8173.             i++;
  8174.             break;
  8175.             }
  8176.         }
  8177.         if (i < AUTHTYPLSTSZ)
  8178.           atypes[i] = AUTHTYPE_NULL;
  8179.         if ((z = cmcfm()) < 0)
  8180.           return(z);
  8181.         sl_auth_saved = 0;
  8182.         for (i = 0; i < AUTHTYPLSTSZ; i++) {
  8183.             auth_type_user[i] = atypes[i];
  8184.             sl_auth_type_user[i] = 0;
  8185.         }
  8186.         } else if (x == TN_AU_HOW) {
  8187.         if ((y = cmkey(auhowtab,nauhow,"","any",xxstring)) < 0)
  8188.           return(y);
  8189.         if ((z = cmcfm()) < 0)
  8190.           return(z);
  8191.         tn_auth_how = y;
  8192.         } else if (x == TN_AU_ENC) {
  8193.         if ((y = cmkey(auenctab,nauenc,"","encrypt",xxstring)) < 0)
  8194.           return(y);
  8195.         if ((z = cmcfm()) < 0)
  8196.           return(z);
  8197.         tn_auth_enc = y;
  8198.         } else {
  8199.         if ((y = cmcfm()) < 0)
  8200.           return(y);
  8201.         TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = x;
  8202.         TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = x;
  8203.         }
  8204.         return(success = 1);
  8205. #endif /* CK_AUTHENTICATION */
  8206.  
  8207. #ifdef CK_ENCRYPTION
  8208.       case CK_TN_ENC: {        /* ENCRYPTION */
  8209.           int c, tmp = -1;
  8210.           int getval = 0;
  8211.           static struct keytab * tnetbl = NULL;
  8212.           static int ntnetbl = 0;
  8213.  
  8214.           if ((y = cmkey(tnenctab,ntnenc,"","",xxstring)) < 0)
  8215.         return(y);
  8216.           switch (y) {
  8217.         case TN_EN_TYP:
  8218.           x = ck_get_crypt_table(&tnetbl,&ntnetbl);
  8219.           debug(F101,"ck_get_crypt_table x","",x);
  8220.           debug(F101,"ck_get_crypt_table n","",ntnetbl);
  8221.           if (x < 1 || !tnetbl || ntnetbl < 1) /* Didn't get it */
  8222.             x = 0;
  8223.           if (!x) {
  8224.               printf("?Oops, types not loaded\n");
  8225.               return(-9);
  8226.           }
  8227.           if ((x = cmkey(tnetbl,ntnetbl,"type of encryption",
  8228.                  "automatic",xxstring)) < 0)
  8229.             return(x);
  8230.           if ((z = cmcfm()) < 0)
  8231.             return(z);
  8232.           cx_type = x;
  8233.           sl_cx_type = 0;
  8234.           break;
  8235.         case TN_EN_START:
  8236.           if ((z = cmcfm()) < 0)
  8237.             return(z);
  8238. #ifdef CK_APC
  8239.           /* Don't let this be set remotely */
  8240.           if (apcactive == APC_LOCAL ||
  8241.               apcactive == APC_REMOTE && !(apcstatus & APC_UNCH))
  8242.             return(success = 0);
  8243. #endif /* CK_APC */
  8244.           ck_tn_enc_start();
  8245.           break;
  8246.         case TN_EN_STOP:
  8247.           if ((z = cmcfm()) < 0)
  8248.             return(z);
  8249. #ifdef CK_APC
  8250.           /* Don't let this be set remotely */
  8251.           if (apcactive == APC_LOCAL ||
  8252.               apcactive == APC_REMOTE && !(apcstatus & APC_UNCH))
  8253.             return(success = 0);
  8254. #endif /* CK_APC */
  8255.           ck_tn_enc_stop();
  8256.           break;
  8257.         default:
  8258.           if ((z = cmcfm()) < 0)
  8259.             return(z);
  8260.           TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION) = y;
  8261.           TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION) = y;
  8262.           TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION) = y;
  8263.           TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION) = y;
  8264.           }
  8265.           return(success = 1);
  8266.       }
  8267. #endif /* CK_ENCRYPTION */
  8268.  
  8269.       case CK_TN_BUG:        /* BUG */
  8270.         if ((x = cmkey(tnbugtab,4,"",
  8271.                "binary-me-means-u-too",xxstring)) < 0)
  8272.           return(x);
  8273.         if ((z = cmkey(onoff,2,"","off",xxstring)) < 0) return(z);
  8274.         if ((y = cmcfm()) < 0) return(y);
  8275.         switch (x) {
  8276.           case 0:
  8277.         tn_b_meu = z;
  8278.         break;
  8279.           case 1:
  8280.         tn_b_ume = z;
  8281.         break;
  8282.           case 2:
  8283.         tn_infinite = z;
  8284.         break;
  8285.           case 3:
  8286.         tn_sb_bug = z;
  8287.         break;
  8288.         }
  8289.         return(success = 1);
  8290.  
  8291. #ifdef CK_ENVIRONMENT
  8292.       case CK_TN_XD:        /* XDISPLOC */
  8293.         if ((x = cmkey(tnnegtab,ntnnegtab,"me","accept",xxstring)) < 0)
  8294.           return(x);
  8295.         if ((y = cmkey(tnnegtab,ntnnegtab,"u","accept",xxstring)) < 0)
  8296.           return(y);
  8297.         if ((z = cmcfm()) < 0)
  8298.           return(z);
  8299.         TELOPT_DEF_S_ME_MODE(TELOPT_XDISPLOC) = x;
  8300.         TELOPT_DEF_S_U_MODE(TELOPT_XDISPLOC) = y;
  8301.         TELOPT_DEF_C_ME_MODE(TELOPT_XDISPLOC) = x;
  8302.         TELOPT_DEF_C_U_MODE(TELOPT_XDISPLOC) = y;
  8303.         return(success = 1);
  8304.  
  8305.       case CK_TN_ENV: {
  8306.           char * msg = "value of telnet environment variable";
  8307.           extern int tn_env_flg;
  8308.           extern char tn_env_acct[], tn_env_disp[], tn_env_job[],
  8309.           tn_env_prnt[], tn_env_sys[];
  8310.           extern char * tn_loc;
  8311.           if ((x = cmkey(tnenvtab,ntnenv,"","",xxstring)) < 0)
  8312.         return(x);
  8313.           if (x == TN_ENV_UVAR) {    /* User variables */
  8314.           char * uvar=NULL;
  8315.           char * uval=NULL;
  8316.           char * env;
  8317.           extern char * tn_env_uservar[8][2];
  8318.  
  8319.           /* Get the user variable name */
  8320.           if ((x = cmfld("Name of Environment Variable","",&s,
  8321.                  xxstring)) < 0)
  8322.             return(x);
  8323.           makestr(&uvar,s);
  8324.  
  8325.           env = getenv(uvar);
  8326.           if (!env) env = "";
  8327.  
  8328.           if ((x = cmtxt("Value of Environment Variable",env,
  8329.                  &s,xxstring)) < 0)
  8330.             return(x);
  8331.           if (*s)
  8332.             makestr(&uval,s);
  8333.  
  8334.           /* Now that we have the variable and perhaps a value */
  8335.           /* there are three possibilities: (1) new variable   */
  8336.           /* and associated value; (2) variable already exists */
  8337.           /* but we have a new value; (3) variable already     */
  8338.           /* exists but no new value therefore the user wants  */
  8339.           /* to clear variable.                                */
  8340.  
  8341.           /* Try to find an existing variable */
  8342.           for (x = 0; x < 8; x++) {
  8343.               if (!ckstrcmp(tn_env_uservar[x][0],uvar,-1,0)) {
  8344.               if (uval) {
  8345.                   free(tn_env_uservar[x][1]);
  8346.                   tn_env_uservar[x][1] = uval;
  8347.                   free(uvar);
  8348.                   return(success = 1);
  8349.               } else {
  8350.                   free(tn_env_uservar[x][0]);
  8351.                   tn_env_uservar[x][0] = NULL;
  8352.                   free(tn_env_uservar[x][1]);
  8353.                   tn_env_uservar[x][1] = NULL;
  8354.                   free(uvar);
  8355.                   return(success = 1);
  8356.               }
  8357.               }
  8358.           }
  8359.  
  8360.           /* Couldn't find one; look for empty location to insert */
  8361.           for (x = 0; x < 8; x++) {
  8362.               if (!tn_env_uservar[x][0]) {
  8363.               tn_env_uservar[x][0] = uvar;
  8364.               tn_env_uservar[x][1] = uval;
  8365.               return(success = 1);
  8366.               }
  8367.           }
  8368.           printf("?Sorry, no space for variable.\n");
  8369.           return(success = 0);
  8370.           }
  8371.           if (x == TN_ENV_OFF || x == TN_ENV_ON) {
  8372.           if ((y = cmcfm()) < 0) return(y);
  8373. #ifdef IKSD
  8374.           if (inserver) {
  8375.               printf("?Sorry, command disabled.\r\n");
  8376.               return(success = 0);
  8377.           }
  8378. #endif /* IKSD */
  8379.           tn_env_flg = x == TN_ENV_OFF ? 0 : 1;
  8380.           return(success = 1);
  8381.           }
  8382.  
  8383.           /* Not ON/OFF - Get the value */
  8384.           z = cmdgquo();
  8385.           cmdsquo(0);
  8386.           if ((y = cmtxt(msg, "", &s, xxstring)) < 0) {
  8387.           cmdsquo(z);
  8388.           return(y);
  8389.           }
  8390.           cmdsquo(z);
  8391. #ifdef IKSD
  8392.           if (inserver)
  8393.         return(success = 0);
  8394. #endif /* IKSD */
  8395.           if ((int)strlen(s) > 63) {
  8396.           printf("Sorry, too long\n");
  8397.           return(-9);
  8398.           }
  8399.           switch (x) {
  8400.         case TN_ENV_USR:
  8401.           ckstrncpy(uidbuf,s,UIDBUFLEN);
  8402.           sl_uid_saved = 0;
  8403.           break;
  8404.         case TN_ENV_ACCT:
  8405.           ckstrncpy(tn_env_acct,s,64);
  8406.           break;
  8407.         case TN_ENV_DISP:
  8408.           ckstrncpy(tn_env_disp,s,64);
  8409.           break;
  8410.         case TN_ENV_JOB:
  8411.           ckstrncpy(tn_env_job,s,64);
  8412.           break;
  8413.         case TN_ENV_PRNT:
  8414.           ckstrncpy(tn_env_prnt,s,64);
  8415.           break;
  8416.         case TN_ENV_SYS:
  8417.           ckstrncpy(tn_env_sys,s,64);
  8418.           break;
  8419.         case TN_ENV_LOC:
  8420.           if (!*s) s = NULL;
  8421.           makestr(&tn_loc,s);
  8422.           break;
  8423.         case TN_ENV_UVAR:
  8424.           printf("\n?Not yet implemented\n");
  8425.           break;
  8426.           }
  8427.           return(success = 1);
  8428.       }
  8429. #endif /* CK_ENVIRONMENT */
  8430.  
  8431. #ifdef CK_SNDLOC
  8432.       case CK_TN_LOC: {        /* LOCATION */
  8433.           extern char * tn_loc;
  8434.           if ((y = cmtxt("Location string","",&s,xxstring)) < 0)
  8435.         return(y);
  8436.           if (!*s) s = NULL;
  8437.           makestr(&tn_loc,s);
  8438.           return(success = 1);
  8439.       }
  8440. #endif /* CK_SNDLOC */
  8441.       case CK_TN_SFU:        /* Microsoft SFU compatibility */
  8442.         if ((z = cmkey(onoff,2,"","on",xxstring)) < 0) return(z);
  8443.         if ((y = cmcfm()) < 0) return(y);
  8444.         tn_sfu = z;
  8445.         return(success = 1);
  8446.         break;
  8447.  
  8448.       case CK_TN_WAIT:        /* WAIT-FOR-NEGOTIATIONS */
  8449.         if ((z = cmkey(onoff,2,"","on",xxstring)) < 0) return(z);
  8450.         if ((y = cmcfm()) < 0) return(y);
  8451. #ifdef IKSD
  8452.         if (inserver &&
  8453. #ifdef IKSDCONF
  8454.         iksdcf
  8455. #else
  8456.         1
  8457. #endif /* IKSDCONF */
  8458.         ) {
  8459.         printf("?Sorry, command disabled.\r\n");
  8460.         return(success = 0);
  8461.         }
  8462. #endif /* IKSD */
  8463.         tn_wait_flg = z;
  8464.         sl_tn_saved = 0;
  8465.         return(success = 1);
  8466.  
  8467.       case CK_TN_DL:        /* DELAY SUBNEGOTIATIONS */
  8468.         if ((z = cmkey(onoff,2,"","on",xxstring)) < 0) return(z);
  8469.         if ((y = cmcfm()) < 0) return(y);
  8470. #ifdef IKSD
  8471.         if (inserver &&
  8472. #ifdef IKSDCONF
  8473.         iksdcf
  8474. #else
  8475.         1
  8476. #endif /* IKSDCONF */
  8477.         ) {
  8478.         printf("?Sorry, command disabled.\r\n");
  8479.         return(success = 0);
  8480.         }
  8481. #endif /* IKSD */
  8482.         tn_delay_sb = z;
  8483.         return(success = 1);
  8484.  
  8485.       case CK_TN_PUID: {        /* PROMPT-FOR-USERID */
  8486.           int i,len;
  8487.           if ((y = cmtxt("Prompt string","",&s,xxstring)) < 0)
  8488.         return(y);
  8489.           if (s == "") s = NULL;
  8490.           if (s) {
  8491.           s = brstrip(s);
  8492.           if (s == "") s = NULL;
  8493.           }
  8494.           /* we must check to make sure there are no % fields */
  8495.           len = strlen(s);
  8496.           for (i = 0; i < len; i++) {
  8497.           if (s[i] == '%') {
  8498.               if (s[i+1] != '%') {
  8499.               printf("%% fields are not used in this command.\n");
  8500.               return(-9);
  8501.               }
  8502.               i++;
  8503.           }
  8504.           }
  8505.           makestr(&tn_pr_uid,s);
  8506.           return(success = 1);
  8507.       }
  8508.       default:
  8509.         return(-2);
  8510.     }
  8511.     }
  8512. #endif /* TNCODE */
  8513.  
  8514.     switch (xx) {
  8515. #ifndef NOSPL
  8516.       case XYCOUN:            /* SET COUNT */
  8517.     x = cmnum("Positive number","0",10,&z,xxstring);
  8518.     if (x < 0) return(x);
  8519.     if ((x = cmcfm()) < 0) return(x);
  8520.     if (z < 0) {
  8521.         printf("?A positive number, please\n");
  8522.         return(0);
  8523.     }
  8524.     debug(F101,"XYCOUN: z","",z);
  8525.     return(success = setnum(&count[cmdlvl],z,0,10000));
  8526. #endif /* NOSPL */
  8527.  
  8528. #ifndef NOSPL
  8529.       case XYCASE:
  8530.     return(success = seton(&inpcas[cmdlvl]));
  8531. #endif /* NOSPL */
  8532.  
  8533.       case XYCMD:            /* COMMAND ... */
  8534.     if ((y = cmkey(scmdtab,nbytt,"","",xxstring)) < 0)
  8535.       return(y);
  8536.     switch (y) {
  8537.       case 876:
  8538.         if ((y = cmcfm()) < 0)
  8539.           return(y);
  8540.         concb((char)escape);
  8541.         return(success = 1);
  8542.  
  8543.       case SCMD_BSZ:
  8544.         if ((y = cmnum("bytesize for command characters, 7 or 8","7",10,&x,
  8545.                xxstring)) < 0)
  8546.           return(y);
  8547.         if (x != 7 && x != 8) {
  8548.         printf("\n?The choices are 7 and 8\n");
  8549.         return(success = 0);
  8550.         }
  8551.         if ((y = cmcfm()) < 0) return(y);
  8552.         if (x == 7) cmdmsk = 0177;
  8553.         else if (x == 8) cmdmsk = 0377;
  8554.         return(success = 1);
  8555. #ifdef CK_RECALL
  8556.       case SCMD_RCL:
  8557.         if ((y = cmnum("maximum number of commands in recall buffer","10",
  8558.                10,&x,xxstring)) < 0)
  8559.           return(y);
  8560.         if ((y = cmcfm()) < 0) return(y);
  8561.         return(success = cmrini(x));
  8562. #endif /* CK_RECALL */
  8563. #ifdef CK_RECALL
  8564.       case SCMD_RTR:
  8565.         return(success = seton(&cm_retry));
  8566. #endif /* CK_RECALL */
  8567.       case SCMD_MOR:        /* More-prompting */
  8568.         success = seton(&xaskmore);
  8569.         if (success)
  8570.           saveask = xaskmore;
  8571.         return(success);
  8572.       case SCMD_QUO:
  8573.         if ((x = seton(&y)) < 0) return(x);
  8574.         cmdsquo(y);            /* Do it the right way */
  8575.         cmd_quoting = y;        /* Also keep a global copy */
  8576.         /* Set string-processing function */
  8577. #ifdef datageneral
  8578.         xxstring = y ? zzstring : (xx_strp) NULL;
  8579. #else
  8580. #ifdef CK_ANSIC
  8581.         xxstring = y ? zzstring : (xx_strp) NULL;
  8582. #else
  8583.         xxstring = y ? zzstring : (xx_strp) NULL;
  8584. #endif /* CK_ANSIC */
  8585. #endif /* datageneral */
  8586.         return(success = 1);
  8587.  
  8588. #ifdef OS2
  8589. #ifndef NOLOCAL
  8590.       case SCMD_COL: {        /* Command-screen colors */
  8591.           int fg, bg;
  8592.           fg = cmkey(ttyclrtab, nclrs,
  8593.              "foreground color and then background color",
  8594.              "white",
  8595.              xxstring);
  8596.           if (fg < 0)
  8597.         return(fg);
  8598.           if ((bg = cmkey(ttyclrtab,nclrs,
  8599.                   "background color","black",xxstring)) < 0)
  8600.         return(bg);
  8601.           if ((y = cmcfm()) < 0)
  8602.         return(y);
  8603.           colorcmd = fg | bg << 4;
  8604.           return(success = 1);
  8605.       }
  8606.       case SCMD_SCR:        /* Command Scrollback size */
  8607.         if ((y = cmnum("COMMAND scrollback buffer size, lines","512",10,&x,
  8608.                xxstring)) < 0)
  8609.           return(y);
  8610.         /* The max number of lines is the RAM  */
  8611.         /* we can actually dedicate to a       */
  8612.         /* scrollback buffer given the maximum */
  8613.         /* process memory space of 512MB       */
  8614.         if (x < 256 || x > 2000000L) {
  8615.         printf("\n?The size must be between 256 and 2,000,000.\n");
  8616.         return(success = 0);
  8617.         }
  8618.         if ((y = cmcfm()) < 0) return(y);
  8619.         tt_scrsize[VCMD] = x;
  8620.         VscrnInit( VCMD );
  8621.         return(success = 1);
  8622.  
  8623.       case SCMD_WID: {
  8624.           if ((y = cmnum(
  8625.              "Number of columns in display window during CONNECT",
  8626.              "80",10,&x,xxstring)) < 0)
  8627.         return(y);
  8628.           if ((y = cmcfm()) < 0) return(y);
  8629.  
  8630.           if (IsOS2FullScreen()) {
  8631.           if (x != 40 && x != 80 && x != 132) {
  8632.               printf("\n?The width must be 40, 80,");
  8633. #ifdef NT
  8634.               printf(" or 132 under Windows 95.\n.");
  8635. #else /* NT */
  8636.               printf(" or 132 in a Full Screen session.\n.");
  8637. #endif /* NT */
  8638.               return(success = 0);
  8639.           }
  8640.           } else {
  8641.           if (!IsWARPed() && x != 80) {
  8642.               printf("\n?OS/2 version is pre-WARP: the width must");
  8643.               printf("equal 80 in a Windowed Session\n.");
  8644.               return(success = 0);
  8645.           }
  8646.           if (x < 20 || x > MAXTERMCOL) {
  8647.               printf(
  8648.               "\n?The width must be between 20 and %d\n.",MAXTERMCOL);
  8649.               return(success = 0);
  8650.           }
  8651.           }
  8652.           if (x > 8192/(tt_rows[VCMD]+1)) {
  8653.           printf(
  8654. "\n?The max screen area is 8192 cells: %d(rows) x %d(cols) = %d cells.\n",
  8655.              tt_rows[VCMD]+1,x,x*(tt_rows[VCMD]+1));
  8656.           return(success = 0);
  8657.           }
  8658.               os2_setcmdwidth(x);
  8659.           return(success = 1);
  8660.       }
  8661.       case SCMD_HIG:
  8662.         if ((y = cmnum("Number of rows in display window during CONNECT",
  8663.                "25",10,&x,xxstring)) < 0)
  8664.           return(y);
  8665.         if ((y = cmcfm()) < 0) return(y);
  8666.  
  8667.         if (tt_modechg == TVC_DIS) {
  8668.         printf("\n?SET TERMINAL VIDEO-CHANGE DISABLED\n");
  8669.         return(success = 0);
  8670.         }
  8671.         if (IsOS2FullScreen()) {
  8672.         if ( tt_status[VCMD] ) {
  8673.             if (x != 24 && x != 42 && x != 49 && x != 59) {
  8674.             printf("\n?The height must be 24, 42, 49");
  8675. #ifdef NT
  8676.             printf(" or 59 under Windows 95.\n.");
  8677. #else /* NT */
  8678.             printf(" or 59 in a Full Screen session.\n.");
  8679. #endif /* NT */
  8680.             return(success = 0);
  8681.             }
  8682.         } else {
  8683.             if (x != 25 && x != 43 && x != 50 && x != 60) {
  8684.             printf("\n?The height must be 25, 43, 50");
  8685. #ifdef NT
  8686.             printf(" or 60 under Windows 95.\n.");
  8687. #else /* NT */
  8688.             printf(" or 60 in a Full Screen session.\n.");
  8689. #endif /* NT */
  8690.             return(success = 0);
  8691.             }
  8692.         }
  8693.         } else if (tt_modechg == TVC_W95) {
  8694.         if (tt_status[VCMD]) {
  8695.             if (x != 24 && x != 42 && x != 59) {
  8696.             printf("\n?The height must be 24, 42, 49");
  8697. #ifdef NT
  8698.             printf(" under Windows 95.\n.");
  8699. #else /* NT */
  8700.             printf(" in a Full Screen session.\n.");
  8701. #endif /* NT */
  8702.             return(success = 0);
  8703.             }
  8704.         } else {
  8705.             if (x != 25 && x != 43 && x != 50) {
  8706.             printf("\n?The height must be 25, 43, 50");
  8707. #ifdef NT
  8708.             printf(" under Windows 95.\n.");
  8709. #else /* NT */
  8710.             printf(" in a Full Screen session.\n.");
  8711. #endif /* NT */
  8712.             return(success = 0);
  8713.             }
  8714.         }
  8715.         } else {
  8716.         if (x < 8 || x > MAXTERMROW ) {
  8717.             printf("\n?The height must be between 8 and %d\n.",
  8718.                MAXTERMROW);
  8719.             return(success = 0);
  8720.         }
  8721.         }
  8722.         if (x > 8192/tt_cols[VCMD]) {
  8723.         printf(
  8724. "\n?The max screen area is 8192 cells: %d(rows) x %d(cols) = %d cells.\n",
  8725.                x,tt_cols[VCMD],x*tt_cols[VCMD]);
  8726.         return(success = 0);
  8727.         }
  8728.             os2_setcmdheight(x);
  8729.         return(success = 1);
  8730.  
  8731.       case SCMD_STA: {
  8732.           extern int marginbot;
  8733.           if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  8734.           if ((x = cmcfm()) < 0) return(x);
  8735.           if (y != tt_status[VCMD]) {
  8736.           /* Might need to fixup the margins */
  8737.           tt_status[VCMD] = y;
  8738.           if (y) {
  8739.               tt_szchng[VCMD] = 2;
  8740.               tt_rows[VCMD]--;
  8741.               cmd_rows--;
  8742.               VscrnInit(VCMD);    /* Height set here */
  8743.               printf("\n");
  8744.           } else {
  8745.               tt_szchng[VCMD] = 1;
  8746.               tt_rows[VCMD]++;
  8747.               cmd_rows++;
  8748.               VscrnInit(VCMD);    /* Height set here */
  8749.           }
  8750.           }
  8751.           return(success = 1);
  8752.       }
  8753.  
  8754.       case SCMD_CUR: {
  8755.           int row, col;
  8756.           position * ppos;
  8757.  
  8758.           ppos = VscrnGetCurPos(VCMD);
  8759. #ifdef NT
  8760. #define itoa _itoa
  8761. #endif /* NT */
  8762.           itoa(ppos->y+1, tmpbuf, 10);
  8763.           if ((y = cmnum("row (1-based)",tmpbuf,10,&row,xxstring)) < 0)
  8764.         return(y);
  8765.  
  8766.           itoa(ppos->x+1, tmpbuf, 10);
  8767.           if ((y = cmnum("col (1-based)",tmpbuf,10,&col,xxstring)) < 0)
  8768.         return(y);
  8769.           if ((x = cmcfm()) < 0) return(x);
  8770.  
  8771.           VscrnSetCurPos( VCMD, (short) (col-1), (short) (row-1) ) ;
  8772.           VscrnIsDirty( VCMD );
  8773.           return(success=1);
  8774.       }
  8775. #endif /* NOLOCAL */
  8776. #else
  8777.       case SCMD_WID:
  8778.         y = cmnum("Command screen width, characters","80",10,&x,xxstring);
  8779.         return(setnum(&cmd_cols,x,y,1024));
  8780.  
  8781.       case SCMD_HIG:
  8782.         y = cmnum("Command screen height, rows","24",10,&x,xxstring);
  8783.         return(setnum(&cmd_rows,x,y,1024));
  8784. #endif /* OS2 */
  8785.  
  8786.       case SCMD_INT:
  8787.         return(seton(&cmdint));
  8788.  
  8789. #ifdef CK_AUTODL
  8790.       case SCMD_ADL:
  8791.         return(seton(&cmdadl));
  8792. #endif /* CK_AUTODL */
  8793.  
  8794. #ifdef DOUBLEQUOTING
  8795.       case SCMD_DBQ: {
  8796.           extern int dblquo;
  8797.           return(seton(&dblquo));
  8798.       }
  8799. #endif /* DOUBLEQUOTING */
  8800.  
  8801.       default:
  8802.         return(-2);
  8803.     }
  8804.     }
  8805.  
  8806.     switch (xx) {
  8807.  
  8808.       case XYDFLT:            /* SET DEFAULT = CD */
  8809.     return(success = docd(XXCWD));
  8810.  
  8811. case XYDEBU:                /* SET DEBUG { on, off, session } */
  8812.     if ((y = cmkey(dbgtab,ndbg,"","",xxstring)) < 0)
  8813.       return(y);
  8814.     if (y == DEB_TIM)
  8815. #ifdef COMMENT
  8816.       return(seton(&debtim) < 0 ? x : (success = 1));
  8817. #else
  8818.       /* why this change? */
  8819.       return(success = seton(&debtim));
  8820. #endif /* COMMENT */
  8821.  
  8822. #ifdef IKSD
  8823.     if (inserver && isguest) {
  8824.         printf("?Sorry, command disabled.\r\n");
  8825.         return(success = 0);
  8826.     }
  8827. #endif /* IKSD */
  8828.  
  8829.     switch (y) {
  8830.       case DEB_LEN:
  8831.         y = cmnum("Max length for debug log strings","",10,&x,xxstring);
  8832.         if ((z = setnum(&debxlen,x,y,-1)) < 0)
  8833.           return(z);
  8834.         if ((x = cmcfm()) < 0)
  8835.           return(x);
  8836.         return(success = 1);
  8837.  
  8838.       case DEB_OFF:
  8839.         if ((x = cmcfm()) < 0)
  8840.           return(x);
  8841.         debses = 0;
  8842. #ifdef DEBUG
  8843.         if (deblog) doclslog(LOGD);
  8844. #endif /* DEBUG */
  8845.         return(success = 1);
  8846.  
  8847.       case DEB_ON:
  8848.         if ((x = cmcfm()) < 0)
  8849.           return(x);
  8850. #ifdef DEBUG
  8851.         deblog = debopn("debug.log", 0);
  8852.         return(success = deblog ? 1 : 0);
  8853. #else
  8854.         printf("?Sorry, debug log feature not enabled\n");
  8855.         return(success = 0);
  8856. #endif /* DEBUG */
  8857.       case DEB_SES:
  8858.         if ((x = cmcfm()) < 0)
  8859.           return(x);
  8860.         return(success = debses = 1);
  8861.     }
  8862.     break;
  8863.  
  8864. #ifndef NOXFER
  8865.       case XYDELA:            /* SET DELAY */
  8866.     y = cmnum("Number of seconds before starting to send",
  8867.           "5",10,&x,xxstring);
  8868.     if (x < 0) x = 0;
  8869.     return(success = setnum(&ckdelay,x,y,999));
  8870. #endif /* NOXFER */
  8871.  
  8872.       default:
  8873.     break;
  8874.     }
  8875.  
  8876.     switch (xx) {
  8877. #ifndef NODIAL
  8878. #ifdef CK_TAPI
  8879.       case XYTAPI:
  8880.     return(settapi());
  8881. #endif /* CK_TAPI */
  8882.       case XYDIAL:            /* SET MODEM or SET DIAL */
  8883.     return(setdial(-1));
  8884. case XYMODM:
  8885.     return(setmodem());
  8886. #endif /* NODIAL */
  8887.  
  8888. #ifndef NOLOCAL
  8889.       case XYDUPL:            /* SET DUPLEX */
  8890.     if ((y = cmkey(dpxtab,2,"","full",xxstring)) < 0) return(y);
  8891.     if ((x = cmcfm()) < 0) return(x);
  8892.     duplex = y;
  8893.     return(success = 1);
  8894.  
  8895.       case XYLCLE:            /* LOCAL-ECHO (= DUPLEX) */
  8896.     return(success = seton(&duplex));
  8897.  
  8898.       case XYESC:            /* SET ESCAPE */
  8899.     return(success = setcc(ckitoa(DFESC),&escape));
  8900. #endif /* NOLOCAL */
  8901.  
  8902.       case XYEXIT:            /* SET EXIT */
  8903.     if ((z = cmkey(xittab,nexit,"","",xxstring)) < 0)
  8904.       return(z);
  8905.     switch (z) {
  8906.       case 0:            /* STATUS */
  8907.         y = cmnum("EXIT status code","",10,&x,xxstring);
  8908.         return(success = setnum(&xitsta,x,y,-1));
  8909.       case 1:            /* WARNING */
  8910.         if ((z = cmkey(xitwtab,nexitw,"","",xxstring)) < 0)
  8911.           return(z);
  8912.         if ((y = cmcfm()) < 0) return(y);
  8913.         xitwarn = z;
  8914.         return(success = 1);
  8915.       case 2:
  8916.         success = seton(&exitonclose);
  8917. #ifdef TCPSOCKET
  8918.         if (success) tn_exit = exitonclose;
  8919. #endif /* TCPSOCKET */
  8920.         return(success);
  8921.       case 3: {
  8922.           extern int exithangup;
  8923.           return((success = seton(&exithangup)));
  8924.       }
  8925.       default:
  8926.         return(-2);
  8927.     } /* End of SET EXIT switch() */
  8928.       default:
  8929.     break;
  8930.     }
  8931.  
  8932.     switch (xx) {
  8933.  
  8934.       case XYFILE:            /* SET FILE */
  8935.     return(setfil(rmsflg));
  8936.  
  8937.       case XYFLOW: {            /* FLOW-CONTROL */
  8938.       extern int cxflow[];
  8939.       struct FDB k1, k2;
  8940.       int tncomport = 0;
  8941.       char * m;
  8942.  
  8943. #ifdef TN_COMPORT
  8944.       if (network && istncomport())
  8945.         tncomport = 1;
  8946. #endif /* TN_COMPORT */
  8947.  
  8948.       if (tncomport) {
  8949.           m = "Flow control type, one of the following:\n\
  8950.    dtr/cd    dtr/cts   keep    none    rts/cts   xon/xoff\n\
  8951.  or connection type";
  8952.       } else {
  8953.       /* All this is because chained FDB's don't give chained help yet */
  8954.           m =
  8955. #ifdef Plan9
  8956. #ifdef CK_RTSCTS
  8957.        "Flow control type, one of the following:\n\
  8958.    keep   none    rts/cts\n\
  8959.  or connection type",
  8960. #else
  8961.        "Flow control type, one of the following:\n\
  8962.    keep   none\n\
  8963.  or connection type";
  8964. #endif /* CK_RTSCTS */
  8965. #else
  8966. #ifdef CK_RTSCTS
  8967. #ifdef CK_DTRCD
  8968. #ifdef CK_DTRCTS
  8969.        "Flow control type, one of the following:\n\
  8970.    dtr/cd    dtr/cts   keep    none    rts/cts   xon/xoff\n\
  8971.  or connection type";
  8972. #else /* CK_DTRCTS */
  8973.            "Flow control type, one of the following:\n\
  8974.    dtr/cd    keep    none    rts/cts   xon/xoff\n\
  8975.             or connection type";
  8976. #endif /* CK_DTRCTS */
  8977. #else /* CK_DTRCD */
  8978. #ifdef CK_DTRCTS
  8979.            "Flow control type, one of the following:\n\
  8980.    dtr/cts   keep   none    rts/cts   xon/xoff\n\
  8981.  or connection type";
  8982. #else /* CK_DTRCTS */
  8983.        "Flow control type, one of the following:\n\
  8984.    keep   none    rts/cts   xon/xoff\n\
  8985.  or connection type";
  8986. #endif /* CK_DTRCTS */
  8987. #endif /* CK_DTRCD */
  8988. #else
  8989.        "Flow control type, one of the following:\n\
  8990.    keep   none    xon/xoff\n\
  8991.  or connection type";
  8992. #endif /* CK_RTSCTS */
  8993. #endif /* Plan9 */
  8994.       }
  8995.       cmfdbi(&k1,_CMKEY,m,"","",ncxtypesw, 4, xxstring, cxtypesw, &k2);
  8996.       cmfdbi(&k2,
  8997.          _CMKEY,
  8998.          "",
  8999.          "",
  9000.          "",
  9001. #ifdef TN_COMPORT
  9002.          (tncomport ? ntnflo : nflo),
  9003. #else
  9004.          nflo,
  9005. #endif /* TN_COMPORT */
  9006.          0,
  9007.          xxstring,
  9008. #ifdef TN_COMPORT
  9009.          (tncomport ? tnflotab : flotab),
  9010. #else
  9011.          flotab,
  9012. #endif /* TN_COMPORT */
  9013.          NULL
  9014.          );
  9015.       x = cmfdb(&k1);
  9016.       if (x < 0) {            /* Error */
  9017.           if (x == -2 || x == -9)
  9018.         printf("?No keywords or switches match: \"%s\"\n",atmbuf);
  9019.           return(x);
  9020.       }
  9021.       z = cmresult.nresult;        /* Keyword value */
  9022.       if (cmresult.fdbaddr == &k2) { /* Flow-control type keyword table */
  9023.           if ((x = cmcfm()) < 0)    /* Set it immediately */
  9024.         return(x);
  9025.           flow = z;
  9026.           debug(F101,"set flow","",flow);
  9027. #ifdef CK_SPEED
  9028.           if (flow == FLO_XONX)    /* Xon/Xoff forces prefixing */
  9029.         ctlp[XON] = ctlp[XOFF] = ctlp[XON+128] = ctlp[XOFF+128] = 1;
  9030. #endif /* CK_SPEED */
  9031.           autoflow = (flow == FLO_AUTO);
  9032.           return(success = 1);    /* Done */
  9033.       }
  9034.       debug(F101,"set flow /blah 1","",z); /* SET FLOW /for-what */
  9035.       if ((y = cmkey(flotab,nflo,"Flow control type","none",xxstring)) < 0)
  9036.         return(y);
  9037.       if ((x = cmcfm()) < 0)
  9038.         return(x);
  9039.       debug(F101,"set flow /blah 2","",y);
  9040.       if (y == FLO_AUTO) {
  9041.           printf(
  9042.   "?Sorry, \"automatic\" can not be assigned to a connection type.\n");
  9043.           return(-9);
  9044.       } else if (z >= 0 && z <= CXT_MAX)
  9045.         cxflow[z] = y;
  9046.       debug(F101,"set flow","",flow);
  9047.       debug(F101,"set flow autoflow","",autoflow);
  9048.       return(success = 1);
  9049.       }
  9050.  
  9051.       case XYHAND:            /* HANDSHAKE */
  9052.     if ((y = cmkey(hshtab,nhsh,"","none",xxstring)) < 0) return(y);
  9053.     if (y == 998) {
  9054.         if ((x = cmnum("ASCII value","",10,&y,xxstring)) < 0)
  9055.           return(x);
  9056.         if ((y < 1) || ((y > 31) && (y != 127))) {
  9057.         printf("?Character must be in ASCII control range\n");
  9058.         return(-9);
  9059.         }
  9060.     }
  9061.     if ((x = cmcfm()) < 0) return(x);
  9062.     turn = (y > 0127) ? 0 : 1;
  9063.     turnch = y;
  9064.     return(success = 1);
  9065.  
  9066. #ifndef NOSPL
  9067.       case XYMACR:            /* SET MACRO */
  9068.     if ((y = cmkey(smactab,2,"","",xxstring)) < 0) return(y);
  9069.     switch (y) {
  9070.       case 0: return(success = seton(&mecho));
  9071.       case 1: return(success = seton(&merror[cmdlvl]));
  9072.       default: return(-2);
  9073.     }
  9074. #endif /* NOSPL */
  9075.  
  9076.       case XYMSGS:
  9077. #ifdef VMS
  9078.     if ((z = cmkey(onoff,2,"","",xxstring)) < 0) return(z);
  9079.     if ((y = cmcfm()) < 0) return(y);
  9080.     vms_msgs = z;
  9081.     printf("Sorry, SET MESSAGES not implemented yet\n");
  9082.     return(success = 0);
  9083. #endif /* VMS */
  9084.       default:
  9085.     break;
  9086.     }
  9087.  
  9088.     switch (xx) {
  9089.  
  9090.       case XYPARI:            /* PARITY */
  9091.     if ((y = cmkey(partbl,npar,"","none",xxstring)) < 0)
  9092.       return(y);
  9093.  
  9094.     /* If parity not none, then we also want 8th-bit prefixing */
  9095.  
  9096. #ifdef HWPARITY
  9097.     if (y == 'H') {            /* Hardware */
  9098.         if ((x = cmkey(hwpartbl,nhwpar,"","even",xxstring)) < 0)
  9099.           return(x);
  9100.     }
  9101. #endif /* HWPARITY */
  9102.  
  9103.     if ((z = cmcfm()) < 0)
  9104.       return(z);
  9105.  
  9106. #ifdef HWPARITY
  9107.     if (y == 'H') {            /* 8 data bits plus hardware parity */
  9108.         parity = 0;
  9109. #ifndef NOXFER
  9110.         ebqflg = 0;
  9111. #endif /* NOXFER */
  9112.         hwparity = x;
  9113.     } else {            /* 7 data bits + software parity */
  9114.         hwparity = 0;
  9115. #endif /* HWPARITY */
  9116.         parity = y;
  9117. #ifndef NOXFER
  9118.         ebqflg = (parity) ? 1 : 0;
  9119. #endif /* NOXFER */
  9120. #ifdef HWPARITY
  9121.     }
  9122. #endif /* HWPARITY */
  9123.  
  9124. #ifdef TN_COMPORT
  9125.     if (network && istncomport())
  9126.       tnsettings(parity, 0);
  9127. #endif /* TN_COMPORT */
  9128.  
  9129.     return(success = 1);
  9130.  
  9131. #ifndef NOFRILLS
  9132.       case XYPROM:            /* SET PROMPT */
  9133. /*
  9134.   Note: xxstring not invoked here.  Instead, it is invoked every time the
  9135.   prompt is issued.  This allows the prompt string to contain variables
  9136.   that can change, like \v(dir), \v(time), etc.
  9137. */
  9138.     ckmakmsg(line,            /* Default might have trailing space */
  9139.          LINBUFSIZ,
  9140.          "{",
  9141.          inserver ? ikprompt : ckprompt,
  9142.          "}",
  9143.          NULL
  9144.          );
  9145.     if ((x = cmtxt("Program's command prompt",line,&s,NULL)) < 0)
  9146.       return(x);
  9147.     s = brstrip(s);            /* Remove enclosing braces, if any */
  9148.     cmsetp(s);            /* Set the prompt */
  9149.     return(success = 1);
  9150. #endif /* NOFRILLS */
  9151.  
  9152. #ifndef NOXFER
  9153.       case XYRETR:            /* RETRY: per-packet retry limit */
  9154.     y = cmnum("Maximum retries per packet","10",10,&x,xxstring);
  9155.     if (x < 0) x = 0;
  9156.     if ((x = setnum(&maxtry,x,y,999)) < 0) return(x);
  9157. #ifdef COMMENT
  9158.     if (maxtry <= wslotr) {
  9159.         printf("?Retry limit must be greater than window size\n");
  9160.         return(success = 0);
  9161.     }
  9162. #endif /* COMMENT */
  9163.     if (rmsflg) {
  9164.         sstate = setgen('S', "403", ckitoa(maxtry), "");
  9165.         return((int) sstate);
  9166.     } else return(success = x);
  9167. #endif /* NOXFER */
  9168.  
  9169. #ifndef NOSERVER
  9170.       case XYSERV:            /* SET SERVER items */
  9171.     if ((y = cmkey(srvtab,nsrvt,"","",xxstring)) < 0) return(y);
  9172.     switch (y) {
  9173.       case XYSERI:
  9174.         if ((y = cmnum("Number of seconds, or 0 for no idle timeout",
  9175.                "0",10,&x,xxstring)) < 0)
  9176.           return(y);
  9177.         if (x < 0)
  9178.           x = 0;
  9179.         if ((y = cmcfm()) < 0)
  9180.           return(y);
  9181. #ifndef OS2
  9182.         srvtim = 0;
  9183. #endif /* OS2 */
  9184.         srvidl = x;
  9185.         return(success = 1);
  9186.       case XYSERT:
  9187.         if ((y = cmnum("Interval for server NAKs, 0 = none",
  9188.                ckitoa(DSRVTIM),
  9189.                10,&x, xxstring)) < 0)
  9190.           return(y);
  9191.         if (x < 0) {
  9192.         printf(
  9193.            "\n?Specify a positive number, or 0 for no server NAKs\n");
  9194.         return(0);
  9195.         }
  9196.         if ((y = cmcfm()) < 0) return(y);
  9197.         if (rmsflg) {
  9198.         sstate = setgen('S', "404", ckitoa(x), "");
  9199.         return((int) sstate);
  9200.         } else {
  9201. #ifndef OS2
  9202.         srvidl = 0;
  9203. #endif /* OS2 */
  9204.         srvtim = x;        /* Set the server timeout variable */
  9205.         return(success = 1);
  9206.         }
  9207.       case XYSERD:            /* SERVER DISPLAY */
  9208.         return(success = seton(&srvdis)); /* ON or OFF... */
  9209.  
  9210. #ifndef NOSPL
  9211.       case XYSERP:            /* SERVER GET-PATH */
  9212.         return(parsdir(2));
  9213. #endif /* NOSPL */
  9214.  
  9215.       case XYSERL:            /* SERVER LOGIN */
  9216.         return(cklogin());
  9217.  
  9218.       case XYSERC:            /* SERVER CD-MESSAGE */
  9219.         x = rmsflg ?
  9220.           cmkey(onoff,2,"","",xxstring) :
  9221.         cmkey(cdmsg,3,"","",xxstring);
  9222.         if (x < 0)
  9223.           return(x);
  9224.         if (x == 2) {        /* CD-MESSAGE FILE */
  9225.         if ((x = cmtxt("Name of file","",&s,NULL)) < 0)
  9226.           return(x);
  9227.         if (!*s) {
  9228.             s = NULL;
  9229.             srvcdmsg = 0;
  9230.         }
  9231.         makestr(&cdmsgstr,s);
  9232.         makelist(cdmsgstr,cdmsgfile,8);
  9233.         return(success = 1);
  9234.         }
  9235.         if ((y = cmcfm()) < 0)    /* CD-MESSAGE ON/OFF */
  9236.           return(y);
  9237.         if (rmsflg) {
  9238.         sstate = setgen('S', "420", x ? "1" : "0", "");
  9239.         return((int) sstate);
  9240.         } else {
  9241.         if (x > 0)
  9242.           srvcdmsg |= 1;
  9243.         else
  9244.           srvcdmsg &= 2;
  9245.         return(success = 1);
  9246.         }
  9247.       case XYSERK:            /* SERVER KEEPALIVE */
  9248.         return(success = seton(&srvping)); /* ON or OFF... */
  9249.  
  9250.       default:
  9251.         return(-2);
  9252.     }
  9253. #endif /* NOSERVER */
  9254.     }
  9255.  
  9256.     switch (xx) {
  9257. #ifdef UNIX
  9258. #ifndef NOJC
  9259.       case XYSUSP:            /* SET SUSPEND */
  9260.     seton(&suspend);        /* on or off... */
  9261.     return(success = 1);
  9262. #endif /* NOJC */
  9263. #endif /* UNIX */
  9264.  
  9265.       case XYTAKE:            /* SET TAKE */
  9266.     if ((y = cmkey(taktab,4,"","",xxstring)) < 0) return(y);
  9267.     switch (y) {
  9268.       case 0: return(success = seton(&techo));
  9269. #ifndef NOSPL
  9270.       case 1: return(success = seton(&takerr[cmdlvl]));
  9271. #else
  9272.       case 1: return(success = seton(&takerr[tlevel]));
  9273. #endif /* NOSPL */
  9274.       case 2: techo = 0; return(success = 1); /* For compatibility with */
  9275.       case 3: techo = 1; return(success = 1); /* MS-DOS Kermit */
  9276.       default: return(-2);
  9277.     }
  9278.  
  9279. #ifndef NOSCRIPT
  9280.       case XYSCRI:            /* SET SCRIPT */
  9281.     if ((y = cmkey(scrtab,1,"","echo",xxstring)) < 0) return(y);
  9282.     switch (y) {
  9283.       case 0: return(success = seton(&secho));
  9284.       default: return(-2);
  9285.     }
  9286. #endif /* NOSCRIPT */
  9287.  
  9288.       default:
  9289.     break;
  9290.     }
  9291.  
  9292. #ifndef NOLOCAL
  9293.     switch (xx) {
  9294.       case XYTERM:            /* SET TERMINAL */
  9295.     x = settrm();
  9296.     success = (x > 0) ? 1 : 0;
  9297.     return(x);
  9298.  
  9299. #ifdef NT
  9300.       case XYWIN95:            /* SET WIN95 workarounds */
  9301.     x = setwin95();
  9302.     success = (x > 0 ? 1 : 0);
  9303.     return(x);
  9304. #endif /* NT */
  9305.  
  9306. #ifdef OS2
  9307.       case XYDLR:            /* SET DIALER workarounds */
  9308.     x = setdialer();
  9309.     success = (x > 0 ? 1 : 0);
  9310.     return(x);
  9311.  
  9312.       case XYTITLE:            /* SET TITLE of window */
  9313.     x = settitle();
  9314.     success = (x > 0 ? 1 : 0);
  9315.     return(x);
  9316. #endif /* OS2 */
  9317.  
  9318. #ifdef OS2MOUSE
  9319.       case XYMOUSE:            /* SET MOUSE */
  9320.     return(success = setmou());
  9321. #endif /* OS2MOUSE */
  9322.  
  9323.       case XYBELL:            /* SET BELL */
  9324.     return(success = setbell());
  9325.  
  9326. #ifdef OS2
  9327.       case XYPRTY:
  9328.     return(success = setprty() );
  9329. #endif /* OS2 */
  9330.  
  9331.       default:
  9332.     break;
  9333.     }
  9334. #endif /* NOLOCAL */
  9335.  
  9336.     switch (xx) {
  9337.  
  9338. /* SET SEND/RECEIVE protocol parameters. */
  9339.  
  9340. #ifndef NOXFER
  9341.       case XYRECV:
  9342.       case XYSEND:
  9343.     return(setsr(xx,rmsflg));
  9344. #endif /* NOXFER */
  9345.  
  9346. #ifndef NOLOCAL
  9347.       case XYSESS:            /* SESSION-LOG */
  9348.     if ((x = cmkey(sfttab,nsfttab,"type of file",
  9349. #ifdef OS2
  9350.                "binary",
  9351. #else /* OS2 */
  9352.                "text",
  9353. #endif /* OS2 */
  9354.                xxstring
  9355.                )
  9356.          ) < 0)
  9357.       return(x);
  9358.     if ((y = cmcfm()) < 0)
  9359.       return(y);
  9360.     if (x == 999) {            /* TIMESTAMPED-TEXT */
  9361.         sessft = XYFT_T;        /* Implies text */
  9362.         slogts = 1;            /* and timestamps */
  9363.     } else {            /* A regular type */
  9364.         sessft = x;            /* The type */
  9365.         slogts = 0;            /* No timestampes */
  9366.     }
  9367.     return(success = 1);
  9368.  
  9369.       case XYSPEE:            /* SET SPEED */
  9370.     lp = line;
  9371.     if (local && !network) {
  9372.       ckmakmsg(lp,
  9373.            LINBUFSIZ,
  9374.            "Transmission rate for ",
  9375.            ttname,
  9376.            " (bits per second)",
  9377.            NULL
  9378.            );
  9379.     } else {
  9380.       ckstrncpy(lp,
  9381.             "Serial-port speed (bits per second)",
  9382.             LINBUFSIZ
  9383.             );
  9384.     }
  9385.     zz = -1L;
  9386.  
  9387. #ifdef TN_COMPORT
  9388.     if (network && istncomport())
  9389.       x = cmkey(tnspdtab,ntnspd,line,"",xxstring);
  9390.     else
  9391. #endif /* TN_COMPORT */
  9392.       x = cmkey(spdtab,nspd,line,"",xxstring);
  9393.     if (x < 0) {
  9394.         if (x == -3) printf("?value required\n");
  9395. #ifdef USETCSETSPEED
  9396.         /* In this case, any number can be tried */
  9397.         /* There's a parse error message but the request still goes thru */
  9398.         if (rdigits(atmbuf))
  9399.           zz = atol(atmbuf);
  9400.         else
  9401. #endif /* USETCSETSPEED */
  9402.           return(x);
  9403.     }
  9404.     if ((y = cmcfm()) < 0) return(y);
  9405. #ifdef IKSD
  9406.     if (inserver) {
  9407.         printf("?Sorry, command disabled.\r\n");
  9408.         return(success = 0);
  9409.     }
  9410. #endif /* IKSD */
  9411.     if (!local) {
  9412.         printf("?SET SPEED has no effect without prior SET LINE\n");
  9413.         return(success = 0);
  9414.     } else if (network
  9415. #ifdef TN_COMPORT
  9416.            && !istncomport()
  9417. #endif /* TN_COMPORT */
  9418.            ) {
  9419.         printf("\n?Speed cannot be set for network connections\n");
  9420.         return(success = 0);
  9421.     }
  9422.  
  9423. /*
  9424.   Note: This way of handling speeds is not 16-bit safe for speeds greater
  9425.   than 230400.  The argument to ttsspd() should have been a long.
  9426. */
  9427. #ifdef USETCSETSPEED
  9428.     if (zz > -1L)
  9429.       x = zz / 10L;
  9430. #endif /* USETCSETSPEED */
  9431.     zz = (long) x * 10L;
  9432.     if (zz == 130L) zz = 134L;
  9433.     if (zz == 70L) zz = 75L;    /* (see spdtab[] definition) */
  9434.     if (ttsspd(x) < 0)  {        /* Call ttsspd with cps, not bps! */
  9435.         printf("?Unsupported line speed - %ld\n",zz);
  9436.         return(success = 0);
  9437.     } else {
  9438. #ifdef CK_TAPI
  9439.         if (!tttapi || tapipass)
  9440.           speed = ttgspd();        /* Read it back */
  9441.         else
  9442.           speed = zz;
  9443. #else /* CK_TAPI */
  9444.         speed = ttgspd();        /* Read it back */
  9445. #endif /* CK_TAPI */
  9446.         if (speed != zz)  {        /* Call ttsspd with cps, not bps! */
  9447.         printf("?SET SPEED fails, speed is %ld\n",speed);
  9448.         return(success = 0);
  9449.         }
  9450.         if (pflag && !xcmdsrc) {
  9451.         if (speed == 8880)
  9452.           printf("%s, 75/1200 bps\n",ttname);
  9453.         else if (speed == 134)
  9454.           printf("%s, 134.5 bps\n",ttname);
  9455.         else
  9456.           printf("%s, %ld bps\n",ttname,speed);
  9457.         }
  9458.         return(success = 1);
  9459.     }
  9460. #endif /* NOLOCAL */
  9461.  
  9462. #ifndef NOXFER
  9463.       case XYXFER:            /* SET TRANSFER */
  9464.     if ((y = cmkey(rmsflg ? rtstab : tstab, /* (or REMOTE SET TRANSFER) */
  9465.                rmsflg ? nrts : nts,
  9466.                "","character-set",xxstring)) < 0) return(y);
  9467.     switch (y) {
  9468. #ifdef XFRCAN
  9469.       case XYX_CAN:            /* CANCELLATION */
  9470.         if ((z = cmkey(onoff,2,"","",xxstring)) < 0) return(z);
  9471.         if (z == 0) {        /* OFF */
  9472.         if ((y = cmcfm()) < 0) return(y);
  9473.         xfrcan = 0;
  9474.         } else {
  9475.         if ((y = cmnum("ASCII code for cancellation character",
  9476.                    "3",10,&x,
  9477.                    xxstring)) < 0)
  9478.           return(y);
  9479.         if (x > 31 && x != 127) {
  9480.             printf("Cancel character must be 0-31 or 127\n");
  9481.             return(-9);
  9482.         }
  9483.         if ((y = cmnum("How many required to cause cancellation",
  9484.                    "2",10,&z, xxstring)) < 0)
  9485.           return(y);
  9486.         if (z < 2) {
  9487.             printf("Number must be 2 or greater\n");
  9488.             return(-9);
  9489.         }
  9490.         if ((y = cmcfm()) < 0) return(y);
  9491.         xfrcan = 1;        /* CANCELLATION ON */
  9492.         xfrchr = x;        /* Using this character */
  9493.         xfrnum = z;        /* Needing this many of them */
  9494.         }
  9495.         return(success = 1);
  9496. #endif /* XFRCAN */
  9497.  
  9498. #ifndef NOCSETS
  9499.       case XYX_CSE:            /* CHARACTER-SET */
  9500.         if ((y = cmkey(tcstab,ntcs,"","transparent",xxstring)) < 0)
  9501.           return(y);
  9502.         if ((x = cmcfm()) < 0) return(x);
  9503.         if (rmsflg) {
  9504.         sstate = setgen('S', "405", tcsinfo[y].designator, "");
  9505.         return((int) sstate);
  9506.         } else {
  9507.         extern int s_cset, fcharset, axcset[];
  9508.         tslevel = (y == TC_TRANSP) ? 0 : 1; /* transfer syntax level */
  9509.         tcharset = y;        /* transfer character set */
  9510.         /* SEND CHARACTER-SET AUTO */
  9511.         if (tslevel > 0 && s_cset == XMODE_A)
  9512.           if (y > -1 && y <= MAXTCSETS)
  9513.             if (axcset[y] > -1 && axcset[y] > MAXFCSETS)
  9514.               fcharset = axcset[y]; /* Auto-pick file charset */
  9515.         setxlatype(tcharset,fcharset); /* Translation type */
  9516.         return(success = 1);
  9517.         }
  9518. #endif /* NOCSETS */
  9519.  
  9520.       case XYX_LSH:            /* LOCKING-SHIFT */
  9521.         if ((y = cmkey(lstab,nls,"","on",xxstring)) < 0)
  9522.           return(y);
  9523.         if ((x = cmcfm()) < 0) return(x);
  9524.         lscapr = (y == 1) ? 1 : 0;    /* ON: requested = 1 */
  9525.         lscapu = (y == 2) ? 2 : 0;    /* FORCED:  used = 1 */
  9526.         return(success = 1);
  9527.  
  9528. #ifdef CK_XYZ
  9529.       case XYX_PRO:            /* Protocol */
  9530. #ifndef OS2
  9531.         if (inserver) {
  9532.         printf("?Sorry, only Kermit protocol is available\n");
  9533.         return(-9);
  9534.         }
  9535. #endif /* OS2 */
  9536.         return(setproto());
  9537. #endif /* CK_XYZ */
  9538.  
  9539.       case XYX_MOD:            /* Mode */
  9540.         if ((y = cmkey(xfrmtab,2,"","automatic",xxstring)) < 0)
  9541.           return(y);
  9542.         if ((x = cmcfm()) < 0) return(x);
  9543.         if (rmsflg) {
  9544.         sstate = setgen('S', "410", y == XMODE_A ? "0" : "1", "");
  9545.         return((int)sstate);
  9546.         }
  9547.         g_xfermode = y;
  9548.         xfermode = y;
  9549.         return(success = 1);
  9550.  
  9551. #ifndef NOLOCAL
  9552.       case XYX_DIS:            /* Display */
  9553.         return(doxdis());
  9554. #endif /* NOLOCAL */
  9555.  
  9556.       case XYX_SLO:            /* Slow-start */
  9557.         return(seton(&slostart));
  9558.  
  9559. #ifndef NOSPL
  9560.       case XYX_CRC:            /* CRC */
  9561.         return(seton(&docrc));
  9562. #endif /* NOSPL */
  9563.  
  9564.       case XYX_BEL:            /* Bell */
  9565.         return(seton(&xfrbel));
  9566.  
  9567. #ifdef PIPESEND
  9568.       case XYX_PIP:            /* Pipes */
  9569. #ifndef NOPUSH
  9570.         if (nopush) {
  9571. #endif /* NOPUSH */
  9572.         printf("Sorry, access to pipes is disabled\n");
  9573.         return(-9);
  9574. #ifndef NOPUSH
  9575.         } else
  9576. #endif /* NOPUSH */
  9577.           return(seton(&usepipes));
  9578. #endif /* PIPESEND */
  9579.  
  9580.       case XYX_INT:            /* Interruption */
  9581.         return(seton(&xfrint));
  9582.  
  9583.       case XYX_XLA:
  9584.         return(seton(&xfrxla));    /* Translation */
  9585.  
  9586.       case XYX_MSG: {
  9587.           extern char * xfrmsg;
  9588.           if ((x = cmtxt("Prompt string","",&s,xxstring)) < 0)
  9589.         return(x);
  9590.           if (!*s) s = NULL;
  9591.           makestr(&xfrmsg,s);
  9592.           return(success = 1);
  9593.       }
  9594.       default:
  9595.         return(-2);
  9596.     }
  9597. #endif /* NOXFER */
  9598.     }
  9599.  
  9600.     switch (xx) {
  9601.  
  9602. #ifndef NOXMIT
  9603.       case XYXMIT:            /* SET TRANSMIT */
  9604.     return(setxmit());
  9605. #endif /* NOXMIT */
  9606.  
  9607. #ifndef NOXFER
  9608. #ifndef NOCSETS
  9609.       case XYUNCS:            /* UNKNOWN-CHARACTER-SET */
  9610.     if ((y = cmkey(ifdtab,2,"","discard",xxstring)) < 0) return(y);
  9611.     if ((x = cmcfm()) < 0) return(x);
  9612.     unkcs = y;
  9613.     return(success = 1);
  9614. #endif /* NOCSETS */
  9615. #endif /* NOXFER */
  9616.  
  9617. #ifndef NOPUSH
  9618. #ifdef UNIX
  9619.       case XYWILD:            /* WILDCARD-EXPANSION */
  9620.     if ((y = cmkey(wildtab,2,
  9621.                "Who expands wildcards","kermit",xxstring)) < 0)
  9622.       return(y);
  9623.     if ((z = cmkey(wdottab,
  9624.                2,
  9625.                "whether to match filenames that start with \".\"",
  9626.                "/no-match-dot-files",
  9627.                xxstring)
  9628.          ) < 0)
  9629.       return(z);
  9630.     if ((x = cmcfm()) < 0) return(x);
  9631.     if (nopush) {
  9632.         if (y > 0) {
  9633.         printf("Shell expansion is disabled\n");
  9634.         return(success = 0);
  9635.         }
  9636.     }
  9637.     wildxpand = y;
  9638.     matchdot = z;
  9639.     return(success = 1);
  9640. #endif /* UNIX */
  9641. #endif /* NOPUSH */
  9642.  
  9643. #ifndef NOXFER
  9644.       case XYWIND:            /* WINDOW-SLOTS */
  9645.     if (protocol == PROTO_K) {
  9646.         y = cmnum("Window size for Kermit protocol, 1 to 32",
  9647.               "1", 10, &x, xxstring);
  9648.         y = setnum(&z,x,y,MAXWS);    /* == 32 */
  9649.     }
  9650. #ifdef CK_XYZ
  9651.     else if (protocol == PROTO_Z) {
  9652.         y = cmnum("Window size for ZMODEM protocol, 0 to 65535",
  9653.               "0", 10, &x, xxstring);
  9654.         y = setnum(&z,x,y,65535);
  9655.     }
  9656. #endif /* CK_XYZ */
  9657.     else {
  9658.         y = cmnum("Window size for current protocol",
  9659.               "", 10, &x, xxstring);
  9660.         y = setnum(&z,x,y,65472);    /* Doesn't matter - we won't use it */
  9661.     }
  9662.     if (y < 0) return(y);
  9663.     if (protocol == PROTO_K) {
  9664.         if (z < 1)
  9665.           z = 1;
  9666.     }
  9667. #ifdef CK_XYZ
  9668.     else if (protocol == PROTO_Z) {
  9669.         /* Zmodem windowing is closer to Kermit packet length */
  9670.         /* than Kermit window size.  If Window size is zero   */
  9671.         /* an end of frame and CRC is sent only at the end of */
  9672.         /* the file (default).  Otherwise, an End of Frame    */
  9673.         /* and CRC are sent after Window Size number of bytes */
  9674.         if (z < 0)            /* Disable windowing  */
  9675.           z = 0;
  9676.     } else {
  9677.         printf("?SET WINDOW does not apply to %s protocol\n",
  9678.            ptab[protocol].p_name
  9679.            );
  9680.     }
  9681. #endif /* CK_XYZ */
  9682.  
  9683. #ifdef COMMENT
  9684.     /* This is taken care of automatically now in protocol negotiation */
  9685.     if (maxtry < z) {
  9686.         printf("?Window slots must be less than retry limit\n");
  9687.         return(success = 0);
  9688.     }
  9689. #endif /* COMMENT */
  9690.     if (protocol == PROTO_K && rmsflg) { /* Set remote window size */
  9691.         wslotr = z;            /* Set local window size too */
  9692.         ptab[protocol].winsize = wslotr;
  9693.         sstate = setgen('S', "406", ckitoa(z), "");
  9694.         return((int) sstate);
  9695.     }
  9696.     wslotr = z;            /* Set requested window size here */
  9697.     ptab[protocol].winsize = wslotr; /* and in protocol-specific table */
  9698.     if (protocol == PROTO_K) {    /* And for Kermit only... */
  9699.         swcapr = (wslotr > 1) ? 1 : 0; /* set window bit in capas word */
  9700.         if (wslotr > 1) {        /* Window size > 1? */
  9701.         /* Maybe adjust packet size */
  9702.         y = adjpkl(urpsiz,wslotr,bigrbsiz);
  9703.         if (y != urpsiz) {    /* Did it change? */
  9704.             urpsiz = y;
  9705.             if (msgflg)
  9706.               printf(
  9707. " Adjusting receive packet-length to %d for %d window slots\n",
  9708.                  urpsiz,
  9709.                  wslotr
  9710.                  );
  9711.         }
  9712.         }
  9713.     }
  9714.     return(success = 1);
  9715. #endif /* NOXFER */
  9716.     }
  9717.  
  9718.     switch (xx) {
  9719.  
  9720. #ifndef NOSPL
  9721.       case XYOUTP:            /* OUTPUT command parameters */
  9722.     if ((y = cmkey(outptab,noutptab,"OUTPUT command parameter","pacing",
  9723.                xxstring)) < 0)
  9724.       return(y);
  9725.     switch(y) {            /* Which parameter */
  9726.       case OUT_PAC:            /* PACING */
  9727.         y = cmnum("Milliseconds to pause between each OUTPUT character",
  9728.               "100", 10,&x,xxstring);
  9729.         y = setnum(&z,x,y,16383);    /* Verify and get confirmation */
  9730.         if (y < 0) return(y);
  9731.         if (z < 0) z = 0;        /* (save some space) */
  9732.         pacing = z;
  9733.         return(success = 1);
  9734.       case OUT_ESC:            /* Special-escapes */
  9735.         return(seton(&outesc));
  9736.       default:            /* (shouldn't happen) */
  9737.         return(-2);
  9738.     }
  9739. #endif /* NOSPL */
  9740.  
  9741. #ifdef CK_SPEED
  9742.       case XYQCTL: {
  9743.       short *p;
  9744.       int zz;
  9745.       if ((z = cmkey(ctltab,2, "control-character prefixing option",""
  9746.              ,xxstring)) < 0)
  9747.         return(z);
  9748.       /* Make space for a temporary copy of the prefixing table */
  9749.  
  9750.       p = (short *)malloc(256 * sizeof(short));
  9751.       if (!p) {
  9752.           printf("?Internal error - malloc failure\n");
  9753.           return(-9);
  9754.       }
  9755.       for (i = 0; i < 256; i++) p[i] = ctlp[i]; /* Copy current table */
  9756.  
  9757.       switch (z) {
  9758.         case 0:            /* UNPREFIXED control character */
  9759.         case 1:            /* PREFIXED control character */
  9760.           while (1) {        /* Collect a list of numbers */
  9761. #ifndef NOSPL
  9762.           x_ifnum = 1;        /* Turn off complaints from eval() */
  9763. #endif /* NOSPL */
  9764.           if ((x = cmnum((z == 0) ?
  9765. "\n Numeric ASCII value of control character that needs NO prefix,\n\
  9766.  or the word \"all\", or carriage return to complete the list" :
  9767. "\n Numeric ASCII value of control character that MUST BE prefixed,\n\
  9768.  or the word \"all\", or carriage return to complete the list",
  9769.                  "",10,&y,xxstring
  9770.                  )) < 0) {
  9771. #ifndef NOSPL
  9772.               x_ifnum = 0;
  9773. #endif /* NOSPL */
  9774.               if (x == -3) {
  9775.               if ((x = cmcfm()) < 0) return(x);
  9776.               break;
  9777.               }
  9778.               if (x == -2) {
  9779.               if (p) { free((char *)p); p = NULL; }
  9780.               debug(F110,"SET CONTROL atmbuf",atmbuf,0);
  9781.               if (!ckstrcmp(atmbuf,"all",3,0) ||
  9782.                   !ckstrcmp(atmbuf,"al",2,0) ||
  9783.                   !ckstrcmp(atmbuf,"a",1,0)) {
  9784.                   if ((x = cmcfm()) < 0) /* Get confirmation */
  9785.                 return(x);
  9786.                   if (z)
  9787.                 prefixing = PX_ALL;
  9788. #ifndef UNPREFIXZERO
  9789.                   /* Set all values, but don't touch 0 */
  9790.                   for (y = 1; y < 32; y++) ctlp[y] = (short) z;
  9791. #else
  9792.                   /* Zero too */
  9793.                   for (y = 0; y < 32; y++) ctlp[y] = (short) z;
  9794. #endif /* UNPREFIXZERO */
  9795.                   for (y = 127; y < 160; y++) ctlp[y] = (short) z;
  9796.                   ctlp[255] = (short) z;
  9797.                   /* Watch out for XON and XOFF */
  9798.                   if (flow == FLO_XONX && z == 0) {
  9799.                   if (msgflg) {
  9800.                       printf(
  9801. " XON/XOFF characters 17, 19, 145, 147 not affected.\n");
  9802.                       printf(
  9803. #ifdef CK_RTSCTS
  9804. " SET FLOW NONE or RTS/CTS to transmit these characters unprefixed.\n"
  9805. #else
  9806. " SET FLOW NONE to transmit these characters unprefixed.\n"
  9807. #endif /* CK_RTSCTS */
  9808.                          );
  9809.                   }
  9810.                   ctlp[XON] =
  9811.                     ctlp[XOFF] =
  9812.                       ctlp[XON+128] =
  9813.                     ctlp[XOFF+128] = 1;
  9814.                   }
  9815. #ifdef TNCODE
  9816.                   /* Watch out for TELNET IAC */
  9817.                   if (network &&
  9818.                   (ttnproto == NP_TELNET) && z == 0) {
  9819.                   ctlp[255] = 1;
  9820.                   if (parity == 'e' || parity == 'm')
  9821.                     ctlp[127] = 1;
  9822.                   ctlp[13] = 1;
  9823.                   if (msgflg)
  9824.                     printf(
  9825.                    " TELNET IAC = 255, CR = 13, not affected.\n");
  9826.                   }
  9827. #endif /* TNCODE */
  9828. #ifndef UNPREFIXZERO
  9829. #ifdef OS2
  9830.                   if (z == 0 && protocol != PROTO_K)
  9831.                 ctlp[0] = 0;
  9832. #endif /* OS2 */
  9833. #endif /* UNPREFIXZERO */
  9834.                   return(success = 1);
  9835.               } else {
  9836.                   printf(
  9837.                  "?Please specify a number or the word ALL\n");
  9838.                   return(-9);
  9839.               }
  9840.               } else {
  9841.               if (p) free((char *)p);
  9842.               return(x);
  9843.               }
  9844.           }
  9845. #ifndef NOSPL
  9846.           x_ifnum = 0;
  9847. #endif /* NOSPL */
  9848. #ifdef UNPREFIXZERO
  9849.           zz = 0;
  9850. #else
  9851. #ifndef OS2
  9852.           zz = 1 - z;
  9853. #else
  9854.           zz = 0;        /* Allow 0 (but only for Zmodem) */
  9855. #endif /* OS2 */
  9856. #endif /* UNPREFIXZERO */
  9857.  
  9858.         /* printf("x = %d, y = %d, z = %d, zz = %d\n", x,y,z,zz); */
  9859.  
  9860.           if ((y >  31 && y < 127) || /* A specific numeric value */
  9861.               (y > 159 && y < 255) || /* Check that it is a valid */
  9862.               (y < zz) ||    /* control code. */
  9863.               (y > 255)) {
  9864.               printf("?Values allowed are: %d-31, 127-159, 255\n",zz);
  9865.               if (p) free((char *)p);
  9866.               return(-9);
  9867.           }
  9868.           x = y & 127;        /* Get 7-bit value */
  9869.           if (z == 0) {        /* If they are saying it is safe... */
  9870.               /* If flow control is Xon/Xoff */
  9871.               if (((flow == FLO_XONX) &&
  9872.                /* XON & XOFF chars not safe. */
  9873.                (x == XON || x == XOFF))
  9874.               ) {
  9875.               if (msgflg)
  9876.                 printf(
  9877.                   "Sorry, not while Xon/Xoff is in effect.\n");
  9878.               if (p) free((char *)p);
  9879.               return(-9);
  9880.               }
  9881. #ifdef TNCODE
  9882.               else if (network && (ttnproto == NP_TELNET)
  9883.                    && (y == CR ||
  9884.                    (unsigned) y == (unsigned) 255)) {
  9885.               if (msgflg)
  9886.                 printf("Sorry, not on a TELNET connection.\n");
  9887.               if (p) free((char *)p);
  9888.               return(-9);
  9889.               }
  9890. #endif /* TNCODE */
  9891.           }
  9892.           p[y] = (char) z;    /* All OK, set flag */
  9893.           }    /* End of while loop */
  9894. /*
  9895.   Get here only if they have made no mistakes.  Copy temporary table back to
  9896.   permanent one, then free temporary table and return successfully.
  9897. */
  9898.           for (i = 0; i < 256; i++) ctlp[i] = p[i];
  9899.           if (p) free((char *)p);
  9900.           if (z > 0) clearrq = 0;    /* 199 (see SET PREFIXING) */
  9901.           return(success = 1);
  9902.         default:
  9903.           return(-2);
  9904.       }
  9905.       }
  9906. #endif /* CK_SPEED */
  9907.     }
  9908.  
  9909.     switch (xx) {
  9910.  
  9911. #ifndef NOXFER
  9912.       case XYREPT:
  9913.     if ((y = cmkey(rpttab,2,
  9914.                "repeat-count compression parameter","",xxstring)) < 0)
  9915.       return(y);
  9916.     switch(y) {
  9917.       case 0:
  9918.         return(success = seton(&rptena)); /* REPEAT COUNTS = ON, OFF */
  9919.       case 1:            /* REPEAT MININUM number */
  9920.         printf("(not implemented yet, nothing happens)\n");
  9921.         return(-9);
  9922.       case 2:            /* REPEAT PREFIX char */
  9923.         if ((x = cmnum("ASCII value","",10,&z,xxstring)) < 0)
  9924.           return(x);
  9925.         if ((x = cmcfm()) < 0) return(x);
  9926.         if ((z > 32 && z < 63) || (z > 95 && z < 127)) {
  9927.         if (y == 1) rptmin = (CHAR) z; else myrptq = (CHAR) z;
  9928.         return(success = 1);
  9929.         } else {
  9930.         printf("?Illegal value for prefix character\n");
  9931.         return(-9);
  9932.         }
  9933.     }
  9934. #endif /* NOXFER */
  9935.  
  9936. #ifndef NOSPL
  9937.       case XYALRM: {
  9938. #ifndef COMMENT
  9939.       int yy;
  9940.       long zz;
  9941.       zz = -1L;
  9942.       yy = x_ifnum;
  9943.       x_ifnum = 1;            /* Turn off internal complaints */
  9944.       y = cmnum("Seconds from now, or time of day as hh:mm:ss",
  9945.             "0" ,10, &x, xxstring);
  9946.       x_ifnum = yy;
  9947.       if (y < 0) {
  9948.           if (y == -2) {        /* Invalid number or expression */
  9949.           zz = tod2sec(atmbuf);    /* Convert to secs since midnight */
  9950.           if (zz < 0L) {
  9951.               printf("?Number, expression, or time of day required\n");
  9952.               return(-9);
  9953.           } else {
  9954.               char now[32];    /* Current time */
  9955.               char *p;
  9956.               long tnow;
  9957.               p = now;
  9958.               ztime(&p);
  9959.               tnow = atol(p+11) * 3600L +
  9960.             atol(p+14) * 60L + atol(p+17);
  9961.               if (zz < tnow)    /* User's time before now */
  9962.             zz += 86400L;    /* So make it tomorrow */
  9963.               zz -= tnow;    /* Seconds from now. */
  9964.           }
  9965.           } else
  9966.         return(y);
  9967.       }
  9968.       if (x < 0) {
  9969.           printf("?Alarm time is in the past.\n");
  9970.           return(-9);
  9971.       }
  9972.       if ((y = cmcfm()) < 0) return(y);
  9973.       if (zz > -1L) {        /* Time of day given? */
  9974.           x = zz;
  9975.           if (zz != (long) x) {
  9976.           printf(
  9977. "Sorry, arithmetic overflow - hh:mm:ss not usable on this platform.\n"
  9978.              );
  9979.           return(-9);
  9980.           }
  9981.       }
  9982.       return(setalarm((long)x));
  9983.       }
  9984. #else
  9985. /*
  9986.   This is to allow long values where int and long are not the same, e.g.
  9987.   on 16-bit systems.  But something is wrong with it.
  9988. */
  9989.     if ((y = cmtxt("seconds from now", "0", &s, xxstring)) < 0)
  9990.       return(y);
  9991.     if (rdigits(s)) {
  9992.         return(setalarm(atol(s)));
  9993.     } else {
  9994.         printf("%s - not a number\n",s);
  9995.         return(-9);
  9996.     }
  9997. #endif /* COMMENT */
  9998. #endif /* NOSPL */
  9999.  
  10000. #ifndef NOXFER
  10001.       case XYPROTO:
  10002.     return(setproto());
  10003. #endif /* NOXFER */
  10004.  
  10005. /*
  10006.   C-Kermit unprefixes control characters automatically on network connections
  10007.   if CLEAR-CHANNEL is ON, which it is by default.  But not all network
  10008.   connections are transparent to all control characters.  For example, the
  10009.   DEC-20, even when you TELNET to it, is sensitive to Ctrl-O and Ctrl-T.
  10010.   If you tell C-Kermit to SET CONTROL PREFIX 15 and/or 20, it doesn't help
  10011.   because CLEAR-CHANNEL is still in effect.  If the user goes to the trouble
  10012.   to set up some prefixing, then Kermit do what the user said.  In C-Kermit
  10013.   7.1 Alpha.03 we change the code to set clearrq to 0 if the user gives a
  10014.   SET PREFIXING or SET CONTROL PREFIX command.
  10015. */
  10016.  
  10017. #ifdef CK_SPEED
  10018.       case XYPREFIX: {
  10019. #ifdef COMMENT
  10020.       extern int clearrq;
  10021. #endif /* COMMENT */
  10022.       if ((z = cmkey(pfxtab, 4, "control-character prefixing option",
  10023.              "", xxstring)) < 0)
  10024.         return(z);
  10025.       if ((x = cmcfm()) < 0) return(x);
  10026.       clearrq = 0;            /* 199 */
  10027.       setprefix(z);
  10028. #ifdef COMMENT
  10029.       if (hints && (z == PX_ALL || z == PX_CAU) && clearrq) {
  10030.         printf("Hint: Use SET CLEAR-CHANNEL OFF to disable negotiation of\n");
  10031.         printf("      SET PREFIXING NONE during file transfers on reliable\n");
  10032.         printf("      connections.\n");
  10033.       }
  10034. #endif /* COMMENT */
  10035.       return(success = 1);
  10036.       }
  10037. #endif /* CK_SPEED */
  10038.  
  10039. #ifndef NOSPL
  10040.       case XYLOGIN:
  10041.     if ((z = cmkey(logintab, 3, "value for login script","userid",
  10042.                xxstring)) < 0)
  10043.       return(z);
  10044.     x = cmdgquo();
  10045.     if (z == LOGI_PSW)
  10046.       cmdsquo(0);
  10047.     if ((y = cmtxt("text","", &s, NULL)) < 0) {
  10048.         cmdsquo(x);
  10049.         return(y);
  10050.     }
  10051.     cmdsquo(x);
  10052. #ifdef IKSD
  10053.     if (inserver)
  10054.       return(success = 0);
  10055. #endif /* IKSD */
  10056.         s = brstrip(s);
  10057.     if ((int)strlen(s) > 63) {
  10058.         printf("Sorry, too long\n");
  10059.         return(-9);
  10060.     }
  10061.     switch(z) {
  10062.       case LOGI_UID:
  10063.         ckstrncpy(uidbuf,s,UIDBUFLEN);
  10064.         sl_uid_saved = 0;
  10065.         break;
  10066.       case LOGI_PSW:
  10067.         ckstrncpy(pwbuf,s,PWBUFL);
  10068.             if (pwbuf[0]) {
  10069.         pwflg = 1;
  10070. #ifdef OS2
  10071.         pwcrypt = 1;
  10072. #else /* OS2 */
  10073.         pwcrypt = 0;
  10074. #endif /* OS2 */
  10075.         }
  10076.         break;
  10077.       case LOGI_PRM:
  10078.         ckstrncpy(prmbuf,s,PWBUFL);
  10079.     }
  10080.     return(success = 1);
  10081. #endif /* NOSPL */
  10082.     }
  10083.  
  10084.     switch (xx) {
  10085.  
  10086.       case XYSTARTUP:
  10087.     if ((y = cmkey(ifdtab,2,"","discard",xxstring)) < 0) return(y);
  10088.     if ((x = cmcfm()) < 0) return(x);
  10089.     DeleteStartupFile = (y != 0) ? 0 : 1;
  10090.     return(success = 1);
  10091.  
  10092.       case XYTMPDIR:
  10093.     x = cmdir("Name of temporary directory","",&s,xxstring);
  10094.     if (x == -3)
  10095.       s = "";
  10096.     else if (x < 0)
  10097.       return(x);
  10098.     if ((x = cmcfm()) < 0) return(x);
  10099.     makestr(&tempdir,s);
  10100.     return(tempdir ? 1 : 0);
  10101.  
  10102. #ifndef NOXFER
  10103.       case XYDEST:            /* DESTINATION */
  10104.     return(setdest());
  10105. #endif /* NOXFER */
  10106.  
  10107. #ifndef NOPUSH
  10108. #ifndef NOFRILLS
  10109.  
  10110. /* Editor, Browser, and FTP Client */
  10111.  
  10112.       case XYEDIT:            /* EDITOR */
  10113. #ifdef IKSD
  10114.     if (inserver) {
  10115.         printf("?Sorry, command disabled.\r\n");
  10116.         return(success = 0);
  10117.     }
  10118. #endif /* IKSD */
  10119. #ifdef CK_APC
  10120.     /* Don't let this be set remotely */
  10121.     if (apcactive == APC_LOCAL ||
  10122.         (apcactive == APC_REMOTE && !(apcstatus & APC_UNCH)))
  10123.       return(success = 0);
  10124. #endif /* CK_APC */
  10125.  
  10126. #ifdef OS2ORUNIX
  10127.     {
  10128.         char *p = getenv("PATH");
  10129.         char *e;
  10130.         e = editor[0] ? (char *) editor : getenv("EDITOR");
  10131.         if (!e) e = "";
  10132.         if (p)
  10133.           x = cmifip("Name of preferred editor",e,&s,&y,0,p,xxstring);
  10134.         else
  10135.           x = cmifi("Full path of preferred editor",e,&s,&y,xxstring);
  10136.         if (x < 0 && x != -3)
  10137.           return(x);
  10138.     }
  10139. #else
  10140. #ifdef VMS
  10141.     if ((y = cmtxt("DCL command for editing", "edit", &s, NULL)) < 0) {
  10142.         if (x != -3)
  10143.           return(x);
  10144.     }
  10145. #else
  10146.     if ((x = cmifi("Full path of preferred editor","",&s,&y,xxstring))<0) {
  10147.         if (x != -3)
  10148.           return(x);
  10149.     }
  10150. #endif /* VMS */
  10151. #endif /* OS2ORUNIX */
  10152. #ifdef VMS
  10153.     ckstrncpy(editor,s,CKMAXPATH);
  10154.     editopts[0] = NUL;
  10155. #else
  10156.     if (y != 0) {
  10157.         printf("?A single file please\n");
  10158.         return(-2);
  10159.     }
  10160.     ckstrncpy(line,s,LINBUFSIZ);
  10161.     if ((x = cmtxt("editor command-line options","",&s,NULL)) < 0)
  10162.       return(x);
  10163.     ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  10164.     if ((z = cmcfm()) < 0) return(z);
  10165.     if (line[0]) {
  10166.         zfnqfp(line,CKMAXPATH,editor);
  10167.         ckstrncpy(editopts,tmpbuf,128);
  10168.     } else {
  10169.         editor[0] = NUL;
  10170.         editopts[0] = NUL;
  10171.     }
  10172. #endif /* VMS */
  10173.     return(success = 1);
  10174.  
  10175. #ifndef NOFTP
  10176. #ifndef SYSFTP
  10177. #ifdef TCPSOCKET
  10178.       case XYFTPX:
  10179.     return(dosetftp());        /* SET FTP */
  10180. #endif /* TCPSOCKET */
  10181. #endif /* SYSFTP */
  10182. #endif /* NOFTP */
  10183.  
  10184. #ifdef BROWSER
  10185. #ifndef NOFTP
  10186. #ifdef SYSFTP
  10187.       case XYFTP:            /* SET FTP-CLIENT */
  10188. #endif /* SYSFTP */
  10189. #endif /* NOFTP */
  10190.       case XYBROWSE:            /* SET BROWSER */
  10191.     {
  10192.         char *p = getenv("PATH");
  10193.         char *app = (char *) browser, *opts = (char *) browsopts;
  10194. #ifndef NOFTP
  10195. #ifdef SYSFTP
  10196.         extern char ftpapp[], ftpopts[];
  10197.         if (xx == XYFTP) {
  10198.         app = (char *)ftpapp;
  10199.         opts = (char *)ftpopts;
  10200.         }
  10201. #endif /* SYSFTP */
  10202. #endif /* NOFTP */
  10203. #ifdef IKSD
  10204.         if (inserver) {
  10205.         printf("?Sorry, command disabled.\r\n");
  10206.         return(success = 0);
  10207.         }
  10208. #endif /* IKSD */
  10209. #ifdef CK_APC
  10210.         /* Don't let this be set remotely */
  10211.         if (apcactive == APC_LOCAL ||
  10212.         (apcactive == APC_REMOTE && !(apcstatus & APC_UNCH)))
  10213.           return(success = 0);
  10214. #endif /* CK_APC */
  10215. #ifdef OS2ORUNIX
  10216.         if (p)
  10217.           x = cmifip(xx == XYBROWSE ?
  10218.              "Name of preferred browser" :
  10219.              "Name of preferred ftp client",
  10220. #ifdef OS2
  10221.              xx == XYFTP ? "ftp.exe" : ""
  10222. #else
  10223.              xx == XYFTP ? "ftp" : ""
  10224. #endif /* OS2 */
  10225.              ,&s,&y,0,p,xxstring
  10226.              );
  10227.         else
  10228.           x = cmifi(xx == XYBROWSE ?
  10229.             "Full path of preferred browser" :
  10230.             "Full path of preferred ftp client",
  10231.             "",&s,&y,xxstring
  10232.             );
  10233.         if (x < 0 && x != -3)
  10234.           return(x);
  10235. #else
  10236. #ifdef VMS
  10237.         if ((x = cmtxt("DCL command to start your preferred Web browser",
  10238.                "", &s, NULL)) < 0) {
  10239.         if (x != -3)
  10240.           return(x);
  10241.         }
  10242. #else
  10243.         if ((x = cmifi("Full path of preferred browser","",&s,&y,xxstring)
  10244.          ) < 0) {
  10245.         if (x != -3)
  10246.           return(x);
  10247.         }
  10248. #endif /* VMS */
  10249. #endif /* OS2ORUNIX */
  10250. #ifdef VMS
  10251.         ckstrncpy(app,s,CKMAXPATH);
  10252.         *opts = NUL;
  10253. #else
  10254.         if (y != 0) {
  10255.         printf("?A single file please\n");
  10256.         return(-2);
  10257.         }
  10258.         ckstrncpy(line,s,LINBUFSIZ);
  10259.         if ((x = cmtxt(xx == XYBROWSE ?
  10260.                "browser command-line options" :
  10261.                "ftp client command-line options",
  10262.                "",&s,NULL)
  10263.          ) < 0)
  10264.           return(x);
  10265.         ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  10266.         if ((z = cmcfm()) < 0) return(z);
  10267.         if (line[0]) {
  10268.         zfnqfp(line,CKMAXPATH,app);
  10269.         ckstrncpy(opts, tmpbuf, 128);
  10270.         } else {
  10271.         *app = NUL;
  10272.         *opts = NUL;
  10273.         }
  10274. #endif /* VMS */
  10275.         return(success = 1);
  10276.     }
  10277. #endif /* BROWSER */
  10278. #endif /* NOFRILLS */
  10279. #endif /* NOPUSH */
  10280.  
  10281. #ifdef CK_CTRLZ
  10282.       case XYEOF: {            /* SET EOF */
  10283.       extern int eofmethod; extern struct keytab eoftab[];
  10284.       if ((x = cmkey(eoftab,3,"end-of-file detection method","",
  10285.              xxstring)) < 0)
  10286.         return(x);
  10287.       if ((y = cmcfm()) < 0)
  10288.         return(y);
  10289.       eofmethod = x;
  10290.       return(success = 1);
  10291.       }
  10292. #endif /* CK_CTRLZ */
  10293.  
  10294. #ifdef SESLIMIT
  10295.       case XYLIMIT: {  /* Session-Limit (length of session in seconds) */
  10296.       extern int seslimit;
  10297.       y = cmnum("Maximum length of session, seconds","0",10,&x,xxstring);
  10298. #ifdef IKSD
  10299.       if (inserver &&
  10300. #ifdef IKSDCONF
  10301.           iksdcf
  10302. #else
  10303.           1
  10304. #endif /* IKSDCONF */
  10305.           ) {
  10306.           if ((z = cmcfm()) < 0)
  10307.         return(z);
  10308.           printf("?Sorry, command disabled.\r\n");
  10309.           return(success = 0);
  10310.       }
  10311. #endif /* IKSD */
  10312.  
  10313.       return(setnum(&seslimit,x,y,86400));
  10314.       }
  10315. #endif /* SESLIMIT */
  10316.  
  10317.       case XYRELY: {            /* SET RELIABLE */
  10318.       if ((x = cmkey(ooatab,3,"","automatic",xxstring)) < 0)
  10319.         return(x);
  10320.       if ((y = cmcfm()) < 0) return(y);
  10321.       reliable = x;
  10322.       setreliable = (x != SET_AUTO);
  10323.       debug(F101,"SET RELIABLE reliable","",reliable);
  10324.       return(success = 1);
  10325.       }
  10326.  
  10327. #ifdef STREAMING
  10328.       case XYSTREAM: {            /* SET STREAMING */
  10329.       extern int streamrq;
  10330.       if ((x = cmkey(ooatab,3,"","automatic",xxstring)) < 0)
  10331.         return(x);
  10332.       if ((y = cmcfm()) < 0) return(y);
  10333.       streamrq = x;
  10334.       return(success = 1);
  10335.       }
  10336. #endif /* STREAMING */
  10337.  
  10338. #ifdef CKSYSLOG
  10339.       case XYSYSL: {
  10340.       if ((x = cmkey(syslogtab,nsyslog,"","",xxstring)) < 0)
  10341.         return(x);
  10342.       if ((y = cmcfm()) < 0) return(y);
  10343. #ifdef IKSD
  10344.       if (inserver &&
  10345. #ifdef IKSDCONF
  10346.           iksdcf
  10347. #else
  10348.           1
  10349. #endif /* IKSDCONF */
  10350.           ) {
  10351.           printf("?Sorry, command disabled.\n");
  10352.           return(success = 0);
  10353.       }
  10354. #endif /* IKSD */
  10355. #ifdef CK_APC
  10356.       /* Don't let this be set remotely */
  10357.       if (apcactive == APC_LOCAL ||
  10358.           (apcactive == APC_REMOTE && !(apcstatus & APC_UNCH)))
  10359.         return(success = 0);
  10360. #endif /* CK_APC */
  10361.       ckxsyslog = x;
  10362.       return(success = 1);
  10363.       }
  10364. #endif /* CKSYSLOG */
  10365.  
  10366. #ifdef TLOG
  10367.       case XYTLOG: {            /* SET TRANSACTION-LOG */
  10368.       extern int tlogsep;
  10369.       if ((x = cmkey(vbtab,nvb,"","verbose",xxstring)) < 0)
  10370.         return(x);
  10371.       if (x == 0) {
  10372.           if ((y = cmtxt("field separator",",",&s,NULL)) < 0) return(y);
  10373.           s = brstrip(s);
  10374.           if (*s) {
  10375.           if (s[1]) {
  10376.               printf("?A single character, please.\n");
  10377.               return(-9);
  10378.           } else if ((*s >= '0' && *s <= '9') ||
  10379.                  (*s >= 'A' && *s <= 'Z') ||
  10380.                  (*s >= 'a' && *s <= 'z')) {
  10381.               printf("?A non-alphanumeric character, please.\n");
  10382.               return(-9);
  10383.           } else
  10384.             tlogsep = *s;
  10385.           }
  10386.       } else {
  10387.           if ((y = cmcfm()) < 0) return(y);
  10388.       }
  10389. #ifdef IKSD
  10390.       if (inserver && isguest) {
  10391.           printf("?Sorry, command disabled.\n");
  10392.           return(success = 0);
  10393.       }
  10394. #endif /* IKSD */
  10395. #ifdef CK_APC
  10396.       /* Don't let this be set remotely */
  10397.       if (apcactive == APC_LOCAL ||
  10398.           (apcactive == APC_REMOTE && !(apcstatus & APC_UNCH)))
  10399.         return(success = 0);
  10400. #endif /* CK_APC */
  10401.       tlogfmt = x;
  10402.       return(success = 1);
  10403.       }
  10404. #endif /* TLOG */
  10405.  
  10406.       case XYCLEAR: {            /* SET CLEARCHANNEL */
  10407.       if ((x = cmkey(ooatab,3,"","automatic",xxstring)) < 0)
  10408.         return(x);
  10409.       if ((y = cmcfm()) < 0) return(y);
  10410.       clearrq = x;
  10411.       return(success = 1);
  10412.       }
  10413.  
  10414. #ifdef CK_AUTHENTICATION
  10415.       case XYAUTH: {            /* SET AUTHENTICATION */
  10416. #ifdef CK_KERBEROS
  10417.       int kv = 0;
  10418.       extern struct krb_op_data krb_op;
  10419. #endif /* CK_KERBEROS */
  10420.       char * p = NULL;
  10421.       if ((x =
  10422.            cmkey(setauth,nsetauth,"authentication type","",xxstring)) < 0)
  10423.         return(x);
  10424.       switch (x) {
  10425. #ifdef CK_KERBEROS
  10426.         case AUTH_KRB4: kv = 4; break; /* Don't assume values are same */
  10427.         case AUTH_KRB5: kv = 5; break;
  10428. #endif /* CK_KERBEROS */
  10429. #ifdef CK_SRP
  10430.         case AUTH_SRP: break;
  10431. #endif /* CK_SRP */
  10432. #ifdef CK_SSL
  10433.         case AUTH_SSL:
  10434.         case AUTH_TLS:
  10435.           break;
  10436. #endif /* CK_SSL */
  10437.         default:
  10438.           printf("?Authorization type not supported yet - \"%s\"\n",
  10439.              atmbuf);
  10440.           return(-9);
  10441.       }
  10442. #ifdef IKSD
  10443.       if (inserver &&
  10444. #ifdef IKSDCONF
  10445.           iksdcf
  10446. #else
  10447.           1
  10448. #endif /* IKSDCONF */
  10449.           ) {
  10450.           if ((y = cmcfm()) < 0) return(y);
  10451.           printf("?Sorry, command disabled.\n");
  10452.           return(success = 0);
  10453.       }
  10454. #endif /* IKSD */
  10455. #ifdef CK_APC
  10456.       /* Don't let this be set remotely */
  10457.       if (apcactive == APC_LOCAL ||
  10458.           apcactive == APC_REMOTE && !(apcstatus & APC_UNCH)) {
  10459.           if ((y = cmcfm()) < 0) return(y);
  10460.           return(success = 0);
  10461.       }
  10462. #endif /* CK_APC */
  10463.  
  10464.       switch(x) {
  10465. #ifdef CK_KERBEROS
  10466.         case AUTH_KRB4:
  10467.         case AUTH_KRB5: {
  10468.         if ((x = cmkey(kv == 4 ? k4tab : k5tab,
  10469.                    kv == 4 ? nk4tab : nk5tab,
  10470.                    "Kerberos parameter","",xxstring)) < 0) {
  10471.             return(x);
  10472.         }
  10473.         s = "";
  10474.         switch (x) {
  10475. #ifdef KRB4
  10476.           case XYKRBDBG:
  10477.             if (kv == 4) {
  10478.             if ((y = seton(&k4debug)) < 0)
  10479.               return(y);
  10480. #ifdef NT
  10481.             ck_krb4_debug(k4debug);
  10482. #endif /* NT */
  10483.             } else {
  10484.             return(-9);
  10485.             }
  10486.             break;
  10487. #endif /* KRB4 */
  10488.           case XYKRBLIF:
  10489.             if ((y = cmnum("TGT lifetime","600",10,&z,xxstring)) < 0)
  10490.               return(y);
  10491.             break;
  10492.           case XYKRBPRE:
  10493.             if (kv == 4) {
  10494.             if ((y = seton(&krb4_d_preauth)) < 0)
  10495.               return(y);
  10496.             } else {
  10497.             return(-9);
  10498.             }
  10499.             break;
  10500.           case XYKRBINS:
  10501.             if ((y = cmtxt("Instance name","",&s,xxstring)) < 0)
  10502.               return(y);
  10503.             break;
  10504.           case XYKRBFWD:
  10505.             if (kv == 5) {
  10506.             if ((y = seton(&krb5_d_forwardable)) < 0)
  10507.               return(y);
  10508.             } else {
  10509.             return(-9);
  10510.             }
  10511.             break;
  10512.           case XYKRBPRX:
  10513.             if (kv == 5) {
  10514.             if ((y = seton(&krb5_d_proxiable)) < 0)
  10515.               return(y);
  10516.             } else {
  10517.             return(-9);
  10518.             }
  10519.             break;
  10520.           case XYKRBRNW:
  10521.             if ((y = cmnum("TGT renewable lifetime",
  10522.                    "0",10,&z,xxstring)) < 0)
  10523.               return(y);
  10524.             break;
  10525.           case XYKRBADR:
  10526.             if (kv == 5) {
  10527.             if ((y = seton(&krb5_checkaddrs)) < 0)
  10528.               return(y);
  10529.             } else {
  10530.             if ((y = seton(&krb4_checkaddrs)) < 0)
  10531.               return(y);
  10532.             }
  10533.             break;
  10534.           case XYKRBNAD:
  10535.             if (kv == 5) {
  10536.             if ((y = seton(&krb5_d_no_addresses)) < 0)
  10537.                           return(y);
  10538.             }
  10539.             break;
  10540.           case XYKRBADD:
  10541.             if (kv == 5) {
  10542.             char * tmpaddrs[KRB5_NUM_OF_ADDRS];
  10543.             for (i = 0; i < KRB5_NUM_OF_ADDRS; i++)
  10544.               tmpaddrs[i] = NULL;
  10545.  
  10546.             if ((y =
  10547.                  cmfld("List of IP addresses","",&s,xxstring)) < 0)
  10548.               return(y);
  10549.             makelist(s,tmpaddrs,KRB5_NUM_OF_ADDRS);
  10550.             if ((y = cmcfm()) < 0) {
  10551.                 for (i = 0; i < KRB5_NUM_OF_ADDRS; i++) {
  10552.                 if (tmpaddrs[i] != NULL)
  10553.                   free(tmpaddrs[i]);
  10554.                 }
  10555.                 return(y);
  10556.             }
  10557.             for (i = 0;
  10558.                  i < KRB5_NUM_OF_ADDRS && tmpaddrs[i];
  10559.                  i++) {
  10560.                 if (inet_addr(tmpaddrs[i]) == 0xffffffff) {
  10561.                 printf("invalid ip address: %s\n",
  10562.                        tmpaddrs[i]);
  10563.                 for (i = 0; i < KRB5_NUM_OF_ADDRS; i++) {
  10564.                     if (tmpaddrs[i] != NULL)
  10565.                       free(tmpaddrs[i]);
  10566.                 }
  10567.                 return(-9);
  10568.                 }
  10569.             }
  10570.             for (i = 0;
  10571.                  i < KRB5_NUM_OF_ADDRS && krb5_d_addrs[i];
  10572.                  i++) {
  10573.                 if (krb5_d_addrs[i])
  10574.                   free(krb5_d_addrs[i]);
  10575.                 krb5_d_addrs[i] = NULL;
  10576.             }
  10577.             for (i = 0;
  10578.                  i < KRB5_NUM_OF_ADDRS && tmpaddrs[i];
  10579.                  i++) {
  10580.                 krb5_d_addrs[i] = tmpaddrs[i];
  10581.                 tmpaddrs[i] = NULL;
  10582.             }
  10583.             krb5_d_addrs[i] = NULL;
  10584.             return(success = 1);
  10585.             }
  10586.             break;
  10587.  
  10588.           case XYKRBGET:
  10589.             if (kv == 5) {
  10590.             if ((y = seton(&krb5_autoget)) < 0)
  10591.               return(y);
  10592.             } else {
  10593.             if ((y = seton(&krb4_autoget)) < 0)
  10594.               return(y);
  10595.             }
  10596.             break;
  10597.           case XYKRBDEL:
  10598.             if ((z = cmkey(kdestab,nkdestab,
  10599.                    "Auto Destroy Tickets",
  10600.                    "never",xxstring)) < 0)
  10601.               return(z);
  10602.             break;
  10603.           case XYKRBPR:
  10604.             if ((y = cmtxt("User ID",uidbuf,&s,xxstring)) < 0)
  10605.               return(y);
  10606.             break;
  10607.           case XYKRBRL:
  10608.             if ((y = cmtxt("Name of realm","",&s,xxstring)) < 0)
  10609.               return(y);
  10610.             break;
  10611.                   case XYKRBKTB:
  10612.                     y = cmifi("Filename","",&s,&z,xxstring);
  10613.                     if (y != -3) {
  10614.                        if (y < 0)
  10615.                          return(y);
  10616.                        if (z) {
  10617.                          printf("?Wildcards not allowed\n");
  10618.                          return(-9);
  10619.                        }
  10620.                     }
  10621.                     break;
  10622.           case XYKRBCC:
  10623.             if ((y = cmofi("Filename","",&s,xxstring)) < 0)
  10624.               return(y);
  10625.             break;
  10626.           case XYKRBSRV:
  10627.             if ((y = cmtxt("Name of service to use in ticket",
  10628.                    (kv == 4 ? "rcmd" : "host"),
  10629.                    &s,
  10630.                    xxstring
  10631.                    )) < 0)
  10632.               return(y);
  10633.             break;
  10634.           case XYKRBK5K4:
  10635.             if (kv == 5) {
  10636.             if ((y = seton(&krb5_d_getk4)) < 0)
  10637.               return(y);
  10638.             } else {
  10639.             return(-9);
  10640.             }
  10641.             break;
  10642.           case XYKRBPRM:    /* Prompt */
  10643.             if ((z = cmkey(krbprmtab,2,"","",xxstring)) < 0)
  10644.               return(z);
  10645.             if ((y = cmtxt((z == KRB_PW_PRM) ?
  10646.   "Text of prompt;\nmay contain \"%s\" to be replaced by principal name" :
  10647.   "Text of prompt",
  10648.                    "",
  10649.                    &s,
  10650.                    xxstring
  10651.                    )
  10652.              ) < 0)
  10653.               return(y);
  10654.             break;
  10655.         }
  10656.         ckstrncpy(line,s,LINBUFSIZ);
  10657.         s = line;
  10658.         if ((y = cmcfm()) < 0)
  10659.           return(y);
  10660. #ifdef IKSD
  10661.         if (inserver &&
  10662. #ifdef IKSDCONF
  10663.             iksdcf
  10664. #else /* IKSDCONF */
  10665.             1
  10666. #endif /* IKSDCONF */
  10667.             )
  10668.           return(success = 0);
  10669. #endif /* IKSD */
  10670.  
  10671.         switch (x) {        /* Copy value to right place */
  10672.           case XYKRBLIF:    /* Lifetime */
  10673.             if (kv == 4)
  10674.               krb4_d_lifetime = z;
  10675.             else
  10676.               krb5_d_lifetime = z;
  10677.             break;
  10678.           case XYKRBRNW:
  10679.             if (kv == 5)
  10680.               krb5_d_renewable = z;
  10681.             break;
  10682.           case XYKRBPR:        /* Principal */
  10683.             s = brstrip(s);            /* Strip braces around. */
  10684.             if (kv == 4)
  10685.               makestr(&krb4_d_principal,s);
  10686.             else
  10687.               makestr(&krb5_d_principal,s);
  10688.             break;
  10689.           case XYKRBINS:    /* Instance */
  10690.             if (kv == 4)
  10691.               makestr(&krb4_d_instance,s);
  10692.             else
  10693.               makestr(&krb5_d_instance,s);
  10694.             break;
  10695.           case XYKRBRL:        /* Realm */
  10696.             if (kv == 4)
  10697.               makestr(&krb4_d_realm,s);
  10698.             else
  10699.               makestr(&krb5_d_realm,s);
  10700.             break;
  10701.                   case XYKRBKTB:    /* Key Table */
  10702.                     if (kv == 4)
  10703.                       makestr(&k4_keytab,s);
  10704.                     else
  10705.                       makestr(&k5_keytab,s);
  10706.                     break;
  10707.           case XYKRBCC:        /* Credentials cache */
  10708.             makestr(&krb5_d_cc,s);
  10709.             break;
  10710.           case XYKRBSRV:    /* Service Name */
  10711.             if (kv == 4)
  10712.               makestr(&krb4_d_srv,s);
  10713.             else
  10714.               makestr(&krb5_d_srv,s);
  10715.             break;
  10716.           case XYKRBDEL:
  10717.             if (kv == 5)
  10718.               krb5_autodel = z;
  10719.             else
  10720.               krb4_autodel = z;
  10721.             break;
  10722.           case XYKRBPRM:    /* Prompt */
  10723.             if (s == "") s = NULL;
  10724.             if (s) {
  10725.             s = brstrip(s);
  10726.             if (s == "") s = NULL;
  10727.             }
  10728.             switch (z) {
  10729.               case KRB_PW_PRM: { /* Password */
  10730.               /* Check that there are no more than */
  10731.               /* two % fields and % must followed by 's'. */
  10732.               int i,n,len;
  10733.               len = strlen(s);
  10734.               for (i = 0, n = 0; i < len; i++) {
  10735.                   if (s[i] == '%') {
  10736.                   if (s[i+1] != '%') {
  10737.                       if (s[i+1] != 's') {
  10738.                       printf(
  10739.                        "Only %%s fields are permitted.\n"
  10740.                          );
  10741.                       return(-9);
  10742.                       }
  10743.                       if (++n > 2) {
  10744.                       printf(
  10745.                       "Only two %%s fields are permitted.\n");
  10746.                       return(-9);
  10747.                       }
  10748.                   }
  10749.                   i++;
  10750.                   }
  10751.               }
  10752.               if (kv == 5)
  10753.                 makestr(&k5pwprompt,s);
  10754.               else
  10755.                 makestr(&k4pwprompt,s);
  10756.               break;
  10757.               }
  10758.               case KRB_PR_PRM: { /* Principal */
  10759.               /* Check to make sure there are no % fields */
  10760.               int i,len;
  10761.               len = strlen(s);
  10762.               for (i = 0; i < len; i++) {
  10763.                   if (s[i] == '%') {
  10764.                   if (s[i+1] != '%') {
  10765.                       printf(
  10766.                   "%% fields are not used in this command.\n");
  10767.                       return(-9);
  10768.                   }
  10769.                   i++;
  10770.                   }
  10771.               }
  10772.               if (kv == 5)
  10773.                 makestr(&k5prprompt,s);
  10774.               else
  10775.                 makestr(&k4prprompt,s);
  10776.               break;
  10777.               }
  10778.             }
  10779.         }
  10780.         break;
  10781.         }
  10782. #endif /* CK_KERBEROS */
  10783. #ifdef CK_SRP
  10784.         case AUTH_SRP: {
  10785.         if ((x = cmkey(srptab, nsrptab,
  10786.                    "SRP parameter","",xxstring)) < 0) {
  10787.             return(x);
  10788.         }
  10789.         s = "";
  10790.         switch (x) {
  10791.           case XYSRPPRM:    /* Prompt */
  10792.             if ((z = cmkey(srpprmtab,1,"","",xxstring)) < 0)
  10793.               return(z);
  10794.             if ((y = cmtxt(
  10795.   "Text of prompt;\nmay contain one \"%s\" to be replaced by the username",
  10796.                    "",
  10797.                    &s,
  10798.                    xxstring
  10799.                    )
  10800.              ) < 0)
  10801.               return(y);
  10802.             break;
  10803.         }
  10804.         ckstrncpy(line,s,LINBUFSIZ);
  10805.         s = line;
  10806.         if ((y = cmcfm()) < 0)
  10807.           return(y);
  10808.         switch (x) {        /* Copy value to right place */
  10809.           case XYSRPPRM:    /* Prompt */
  10810.             if (s == "") s = NULL;
  10811.             if (s) {
  10812.             s = brstrip(s);
  10813.             if (s == "") s = NULL;
  10814.             }
  10815.             switch (z) {
  10816.               case SRP_PW_PRM: { /* Password */
  10817.               /* Check %s fields */
  10818.               int i,n,len;
  10819.               len = strlen(s);
  10820.               for (i = 0, n = 0; i < len; i++) {
  10821.                   if (s[i] == '%') {
  10822.                   if (s[i+1] != '%') {
  10823.                       if (s[i+1] != 's') {
  10824.                       printf(
  10825.                       "Only %%s fields are permitted.\n");
  10826.                       return(-9);
  10827.                       }
  10828.                       if (++n > 1) {
  10829.                       printf(
  10830.                        "Only one %%s field is permitted.\n");
  10831.                       return(-9);
  10832.                       }
  10833.                   }
  10834.                   i++;
  10835.                   }
  10836.               }
  10837.               makestr(&srppwprompt,s);
  10838.               break;
  10839.               }
  10840.             }
  10841.         }
  10842.         break;
  10843.         }
  10844. #endif /* CK_SRP */
  10845. #ifdef CK_SSL
  10846.         case AUTH_SSL:
  10847.         case AUTH_TLS: {
  10848.         if ((z = cmkey(ssltab, nssltab,
  10849.                (x == AUTH_SSL ? "SSL parameter" : "TLS parameter"),
  10850.                "",xxstring)) < 0)
  10851.           return(z);
  10852.         s = "";
  10853.         switch (z) {
  10854.           case XYSSLRCFL:    /* SSL/TLS RSA Certs file */
  10855.                   case XYSSLRCCF:    /* SSL/TLS RSA Certs Chain file */
  10856.                   case XYSSLRKFL:    /* SSL/TLS RSA Key File */
  10857.           case XYSSLDCFL:    /* SSL/TLS DSA Certs file */
  10858.                   case XYSSLDCCF:    /* SSL/TLS DSA Certs Chain file */
  10859.                   case XYSSLDKFL:    /* SSL/TLS DH Key File */
  10860.           case XYSSLDPFL:    /* SSL/TLS DH Param File */
  10861.           case XYSSLCRL:    /* SSL/TLS CRL File */
  10862.           case XYSSLVRFF:    /* SSL/TLS Verify File */
  10863.           case XYSSLRND:    /* SSL/TLS Random File */
  10864.             y = cmifi("Filename","",&s,&x,xxstring);
  10865.             if (y != -3) {
  10866.             if (y < 0)
  10867.               return(y);
  10868.             if (x) {
  10869.                 printf("?Wildcards not allowed\n");
  10870.                 return(-9);
  10871.             }
  10872.             }
  10873.             ckstrncpy(line,s,LINBUFSIZ);
  10874.             s = line;
  10875.             s = brstrip(s);
  10876.             if ((y = cmcfm()) < 0)
  10877.               return(y);
  10878.             switch (z) {
  10879.               case XYSSLRCFL:    /* SSL/TLS RSA Certs file */
  10880.             if (!s[0] && ssl_rsa_cert_file) {
  10881.                 free(ssl_rsa_cert_file);
  10882.                 ssl_rsa_cert_file = NULL;
  10883.             } else if (s[0]) {
  10884.                 makestr(&ssl_rsa_cert_file,s);
  10885.                 if (!ssl_rsa_key_file)
  10886.                   makestr(&ssl_rsa_key_file,s);
  10887.             }
  10888.             break;
  10889.                       case XYSSLRCCF:    /* SSL/TLS RSA Certs Chain file */
  10890.                           if (!s[0] && ssl_rsa_cert_chain_file) {
  10891.                               free(ssl_rsa_cert_chain_file);
  10892.                               ssl_rsa_cert_chain_file = NULL;
  10893.                           } else if (s[0]) {
  10894.                               makestr(&ssl_rsa_cert_chain_file,s);
  10895.                           }
  10896.                           break;
  10897.               case XYSSLRKFL:    /* SSL/TLS RSA Key File */
  10898.             if (!s[0] && ssl_rsa_key_file) {
  10899.                 free(ssl_rsa_key_file);
  10900.                 ssl_rsa_key_file = NULL;
  10901.             } else if (s[0]) {
  10902.                 makestr(&ssl_rsa_key_file,s);
  10903.             }
  10904.             break;
  10905.               case XYSSLDCFL:    /* SSL/TLS DSA Certs file */
  10906.             if (!s[0] && ssl_dsa_cert_file) {
  10907.                 free(ssl_dsa_cert_file);
  10908.                 ssl_dsa_cert_file = NULL;
  10909.             } else if (s[0]) {
  10910.                 makestr(&ssl_dsa_cert_file,s);
  10911.                 if (!ssl_dh_key_file)
  10912.                   makestr(&ssl_dh_key_file,s);
  10913.             }
  10914.             break;
  10915.                       case XYSSLDCCF:    /* SSL/TLS DSA Certs Chain file */
  10916.                           if (!s[0] && ssl_dsa_cert_chain_file) {
  10917.                               free(ssl_dsa_cert_chain_file);
  10918.                               ssl_dsa_cert_chain_file = NULL;
  10919.                           } else if (s[0]) {
  10920.                               makestr(&ssl_dsa_cert_chain_file,s);
  10921.                           }
  10922.                           break;
  10923.               case XYSSLDKFL:    /* SSL/TLS DH Key File */
  10924.             if (!s[0] && ssl_dh_key_file) {
  10925.                 free(ssl_dh_key_file);
  10926.                 ssl_dh_key_file = NULL;
  10927.             } else if (s[0]) {
  10928.                 makestr(&ssl_dh_key_file,s);
  10929.             }
  10930.             break;
  10931.               case XYSSLDPFL:    /* SSL/TLS DH Param File */
  10932.             if (!s[0] && ssl_dh_param_file) {
  10933.                 free(ssl_dh_param_file);
  10934.                 ssl_dh_param_file = NULL;
  10935.             } else if (s[0]) {
  10936.                 makestr(&ssl_dh_param_file,s);
  10937.             }
  10938.             break;
  10939.               case XYSSLCRL:    /* SSL/TLS CRL File */
  10940.             if (!s[0] && ssl_crl_file) {
  10941.                 free(ssl_crl_file);
  10942.                 ssl_crl_file = NULL;
  10943.             } else if (s[0]) {
  10944.                 makestr(&ssl_crl_file,s);
  10945.             }
  10946.             break;
  10947.               case XYSSLVRFF:    /* SSL/TLS Verify File */
  10948.             if (!s[0] && ssl_verify_file) {
  10949.                 free(ssl_verify_file);
  10950.                 ssl_verify_file = NULL;
  10951.             } else if (s[0]) {
  10952.                 makestr(&ssl_verify_file,s);
  10953.             }
  10954.             break;
  10955.               case XYSSLRND:    /* SSL/TLS Random File */
  10956.             if (!s[0] && ssl_rnd_file) {
  10957.                 free(ssl_rnd_file);
  10958.                 ssl_rnd_file = NULL;
  10959.             } else if (s[0]) {
  10960.                 makestr(&ssl_rnd_file,s);
  10961.             }
  10962.             break;
  10963.             }
  10964.             break;
  10965.  
  10966.           case XYSSLCRLD:
  10967.                   case XYSSLVRFD: {
  10968.                     char * d = NULL;
  10969.                     if (z == XYSSLVRFD)
  10970.                       d= getenv("SSL_CERT_DIR");
  10971.                     if (d == NULL)
  10972.                         d = "";
  10973.             if ((y = cmdir("Directory",d,&s,xxstring)) < 0)
  10974.               return(y);
  10975.             if (y != -3) {
  10976.             if (y < 0)
  10977.               return(y);
  10978.             }
  10979.             ckstrncpy(line,s,LINBUFSIZ);
  10980.             s = line;
  10981.             s = brstrip(s);
  10982.             if ((y = cmcfm()) < 0)
  10983.               return(y);
  10984.             switch(z) {
  10985.               case XYSSLCRLD:
  10986.             if (!s[0] && ssl_crl_dir) {
  10987.                 free(ssl_crl_dir);
  10988.                 ssl_crl_dir = NULL;
  10989.             } else if (s[0]) {
  10990.                 makestr(&ssl_crl_dir,s);
  10991.             }
  10992.             break;
  10993.               case XYSSLVRFD:
  10994.             if (!s[0] && ssl_verify_dir) {
  10995.                 free(ssl_verify_dir);
  10996.                 ssl_verify_dir = NULL;
  10997.             } else if (s[0]) {
  10998.                 makestr(&ssl_verify_dir,s);
  10999.             }
  11000.             break;
  11001.             }
  11002.             break;
  11003.                   }
  11004.           case XYSSLCOK:    /* SSL/TLS Certs-Ok flag */
  11005.             if ((y = seton(&ssl_certsok_flag)) < 0)
  11006.               return(y);
  11007.             break;
  11008.           case XYSSLDBG:        /* SSL/TLS Debug flag */
  11009.             if ((y = seton(&ssl_debug_flag)) < 0)
  11010.               return(y);
  11011.             break;
  11012.           case XYSSLON:        /* SSL/TLS Only flag */
  11013.             switch (x) {
  11014.               case AUTH_SSL:
  11015.             if ((y = seton(&ssl_only_flag)) < 0)
  11016.               return(y);
  11017.             break;
  11018.               case AUTH_TLS:
  11019.             if ((y = seton(&tls_only_flag)) < 0)
  11020.               return(y);
  11021.             break;
  11022.             }
  11023.             break;
  11024.           case XYSSLVRB:    /* SSL/TLS Verbose flag */
  11025.             if ((y = seton(&ssl_verbose_flag)) < 0)
  11026.               return(y);
  11027.             break;
  11028.           case XYSSLVRF:    /* SSL/TLS Verify flag */
  11029.             if ((x = cmkey(sslvertab, nsslvertab,
  11030.                    "SSL/TLS verify mode",
  11031.                    "peer-cert",xxstring)) < 0)
  11032.               return(x);
  11033.             if ((y = cmcfm()) < 0)
  11034.               return(y);
  11035.             ssl_verify_flag = x;
  11036.             break;
  11037.           case XYSSLDUM:
  11038.             if ((y = seton(&ssl_dummy_flag)) < 0)
  11039.               return(y);
  11040.             break;
  11041.           case XYSSLCL: {        /* SSL/TLS Cipher List */
  11042. #ifdef COMMENT
  11043.               /* This code is used to generate a colon delimited */
  11044.               /* list of the ciphers currently in use to be used */
  11045.               /* as the default for cmtxt().  However, a better  */
  11046.               /* default is simply the magic keyword "ALL".      */
  11047.               CHAR def[1024] = "";
  11048.               if (ssl_con != NULL) {
  11049.               CHAR * p = NULL, *q = def;
  11050.               int i, len;
  11051.  
  11052.               for (i = 0; ; i++) {
  11053.                   p = (CHAR *) SSL_get_cipher_list(ssl_con,i);
  11054.                   if (p == NULL)
  11055.                 break;
  11056.                   len = strlen(p);
  11057.                   if (q+len+1 >= def+1024)
  11058.                 break;
  11059.                   if (i != 0)
  11060.                 *q++ = ':';
  11061.                   strcpy(q,p);
  11062.                   q += len;
  11063.               }
  11064.               }
  11065. #endif /* COMMENT */
  11066.               char * p = getenv("SSL_CIPHER");
  11067.               if (!p)
  11068.             p = "ALL";
  11069.               if ((y = cmtxt(
  11070.                     "Colon-delimited list of ciphers or ALL (case sensitive)",
  11071.                      p,
  11072.                      &s,
  11073.                      xxstring
  11074.                      )
  11075.                ) < 0)
  11076.             return(y);
  11077.               makestr(&ssl_cipher_list,s);
  11078.               if (ssl_con == NULL) {
  11079.               SSL_library_init();
  11080.               ssl_ctx = (SSL_CTX *)
  11081.                 SSL_CTX_new((SSL_METHOD *)TLSv1_method());
  11082.               if (ssl_ctx != NULL)
  11083.                 ssl_con= (SSL *) SSL_new(ssl_ctx);
  11084.               }
  11085.               if (ssl_con) {
  11086.               SSL_set_cipher_list(ssl_con,ssl_cipher_list);
  11087.               }
  11088.               break;
  11089.           }
  11090.         }
  11091.         break;
  11092.         }
  11093. #endif /* CK_SSL */
  11094.         default:
  11095.           break;
  11096.       }
  11097.       return(success = 1);
  11098.       }
  11099. #endif /* CK_AUTHENTICATION */
  11100.  
  11101. #ifndef NOSPL
  11102.       case XYFUNC:
  11103.     if ((x = cmkey(functab,nfunctab,"","diagnostics",xxstring)) < 0)
  11104.       return(x);
  11105.     switch (x) {
  11106.       case FUNC_DI: return(seton(&fndiags));
  11107.       case FUNC_ER: return(seton(&fnerror));
  11108.       default:      return(-2);
  11109.     }
  11110. #endif /* NOSPL */
  11111.  
  11112.       case XYSLEEP:            /* SET SLEEP / PAUSE */
  11113.     if ((x = cmkey(sleeptab,1,"","cancellation",xxstring)) < 0)
  11114.       return(x);
  11115.     return(seton(&sleepcan));
  11116.  
  11117.       case XYCD:            /* SET CD */
  11118.     if ((x = cmkey(cdtab,ncdtab,"","",xxstring)) < 0)
  11119.       return(x);
  11120.     switch (x) {
  11121.       case XYCD_M:            /* SET CD MESSAGE */
  11122.         if ((x = cmkey(cdmsg,ncdmsg,"","",xxstring)) < 0)
  11123.           return(x);
  11124.         if (x == 2) {        /* CD MESSAGE FILE */
  11125.         if ((x = cmtxt("Name of file","",&s,NULL)) < 0)
  11126.           return(x);
  11127.         if (!*s) {
  11128.             s = NULL;
  11129. #ifndef NOXFER
  11130.             srvcdmsg = 0;
  11131. #endif /* NOXFER */
  11132.         }
  11133.         makestr(&cdmsgstr,s);
  11134.         makelist(cdmsgstr,cdmsgfile,8);
  11135.         return(success = 1);
  11136.         }
  11137.  
  11138.         if ((y = cmcfm()) < 0) return(y); /* CD-MESSAGE ON/OFF */
  11139. #ifndef NOXFER
  11140.         if (x > 0)
  11141.           srvcdmsg |= 2;
  11142.         else
  11143.           srvcdmsg &= 1;
  11144. #endif /* NOXFER */
  11145.         return(success = 1);
  11146.  
  11147.       case XYCD_P: {        /* SET CD PATH */
  11148.           extern char * ckcdpath;
  11149.           if ((x = cmtxt("CD PATH string","",&s,xxstring)) < 0)
  11150.         return(x);
  11151.           makestr(&ckcdpath,s);
  11152.           return(success = 1);
  11153.       }
  11154.     }
  11155.  
  11156. #ifndef NOLOCAL
  11157. #ifdef STOPBITS
  11158.       case XYSTOP:            /* STOP-BITS */
  11159.         if ((x = cmkey(stoptbl,2,"Stop bits for serial device","",
  11160.                xxstring)) < 0)
  11161.       return(x);
  11162.     if ((y = cmcfm()) < 0)
  11163.       return(y);
  11164.     if (x > 0 && x < 3) {
  11165.         stopbits = x;
  11166. #ifdef TN_COMPORT
  11167.         if (network && istncomport()) {
  11168.         tnsettings(-1, x);
  11169.         return(success = 1);
  11170.             }
  11171. #endif /* TN_COMPORT */
  11172. #ifdef HWPARITY
  11173.         return(success = 1);
  11174. #else /* HWPARITY */
  11175.             return(-2);
  11176. #endif /* HWPARITY */
  11177.     } else
  11178.       return(-2);
  11179. #endif /* STOPBITS */
  11180.  
  11181.       case XYDISC: {
  11182.       extern int clsondisc;
  11183.       return(seton(&clsondisc));
  11184.       }
  11185.  
  11186.       case XYSERIAL: {
  11187.       /* char c; */
  11188.       extern int cmask;
  11189.       if ((x = cmkey(sertbl,nsertbl,
  11190.              "Serial device character size, parity, and stop bits",
  11191.              "8N1", xxstring)) < 0)
  11192.         return(x);
  11193.       ckstrncpy(line,atmbuf,LINBUFSIZ); /* Associated keyword string */
  11194.       s = line;
  11195.       if ((y = cmcfm()) < 0)
  11196.         return(y);
  11197.       ckstrncpy(line,sernam[x],LINBUFSIZ);
  11198.       s = line;
  11199.       if (s[0] != '8' && s[0] != '7') /* Char size */
  11200.         return(-2);
  11201.       else
  11202.         z = s[0] - '0';
  11203.       if (isupper(s[1]))        /* Parity */
  11204.         s[1] = tolower(s[1]);
  11205.       if (s[2] != '1' && s[2] != '2') /* Stop bits */
  11206.         return(-2);
  11207.       else
  11208.         stopbits = s[2] - '0';
  11209.       if (z == 8) {            /* 8 bits + parity (or not) */
  11210.           parity = 0;        /* Set parity */
  11211.           hwparity = (s[1] == 'n') ? 0 : s[1];
  11212.           cmask = 0xff;        /* Also set TERM BYTESIZE to 8 */
  11213.       } else {            /* 7 bits plus parity */
  11214.           parity = (s[1] == 'n') ? 0 : s[1];
  11215.           hwparity = 0;
  11216.           cmask = 0x7f;        /* Also set TERM BYTESIZE to 7 */
  11217.       }
  11218. #ifdef TN_COMPORT
  11219.       if (network && !istncomport())
  11220.         tnsettings(parity, stopbits);
  11221. #endif /* TN_COMPORT */
  11222.  
  11223.       return(success = 1);        /* from SET SERIAL */
  11224.       }
  11225.  
  11226.       case XYOPTS: {            /* SET OPTIONS */
  11227.       extern int setdiropts();
  11228.       extern int settypopts();
  11229. #ifdef CKPURGE
  11230.       extern int setpurgopts();
  11231. #endif /* CKPURGE */
  11232.       if ((x = cmkey(optstab,noptstab,"for command","", xxstring)) < 0)
  11233.         return(x);
  11234.       switch (x) {
  11235. #ifndef NOFRILLS
  11236.         case XXDEL:
  11237.           return(setdelopts());
  11238. #endif /* NOFRILLS */
  11239.         case XXDIR:
  11240.           return(setdiropts());
  11241.         case XXTYP:
  11242.           return(settypopts());
  11243. #ifdef CKPURGE
  11244.         case XXPURGE:
  11245.           return(setpurgopts());
  11246. #endif /* CKPURGE */
  11247.         default:
  11248.           return(-2);
  11249.       }
  11250.       }
  11251. #endif /* NOLOCAL */
  11252. #ifndef NOXFER
  11253.       case XYQ8FLG: {
  11254.       extern int q8flag;
  11255.       return(seton(&q8flag));
  11256.       }
  11257.       case XYTIMER: {
  11258.       extern int asktimer;
  11259.       y = cmnum("Time limit for ASK command, seconds","0",10,&x,xxstring);
  11260. #ifdef QNX16
  11261.       return(setnum(&asktimer,x,y,32767));
  11262. #else
  11263.       return(setnum(&asktimer,x,y,86400));
  11264. #endif /* QNX16 */
  11265.       }
  11266.       case XYFACKB: {
  11267.       extern int fackbug;
  11268.       return(seton(&fackbug));
  11269.       }
  11270. #endif /* NOXFER */
  11271.  
  11272.       case XYHINTS:
  11273.         return(seton(&hints));
  11274.  
  11275. #ifndef NOSPL
  11276.       case XYEVAL: {
  11277.       extern int oldeval;
  11278.       if ((x = cmkey(oldnew,2,"","", xxstring)) < 0)
  11279.         return(x);
  11280.       if ((y = cmcfm()) < 0)
  11281.         return(y);
  11282.       oldeval = x;
  11283.       return(success = 1);
  11284.       }
  11285. #endif /* NOSPL */
  11286.  
  11287. #ifndef NOXFER
  11288.       case XYFACKP: {
  11289.       extern int fackpath;
  11290.       return(seton(&fackpath));
  11291.       }
  11292. #endif /* NOXFER */
  11293.  
  11294.       case XYQNXPL: {
  11295.       extern int qnxportlock;
  11296.       return(seton(&qnxportlock));
  11297.       }
  11298.  
  11299. #ifndef NOCMDL
  11300. #ifdef IKSD
  11301.       case XYIKS: {
  11302.       int setiks();
  11303.       return(setiks());
  11304.       }
  11305. #endif /* IKSD */
  11306. #endif /* NOCMDL */
  11307.  
  11308. #ifdef CKROOT
  11309.       case XYROOT:
  11310.         return(dochroot());
  11311. #endif /* CKROOT */
  11312.  
  11313. #ifndef NOSPL
  11314. #ifndef NOSEXP
  11315.       case XYSEXP: {
  11316.       if ((x = cmkey(sexptab,2,"","", xxstring)) < 0)
  11317.         return(x);
  11318.       switch (x) {
  11319.         case 0:
  11320.           if ((x = cmkey(ooatab,3,"","automatic", xxstring)) < 0)
  11321.         return(x);
  11322.           if ((y = cmcfm()) < 0)
  11323.         return(y);
  11324.           sexpecho = x;
  11325.           break;
  11326.         case 1: {
  11327.         int i, xx;
  11328.         xx = sexpmaxdep;
  11329.         if ((y = cmnum("Maximum recursion depth",
  11330.                    "1000",10,&x,xxstring)) < 0)
  11331.           return(y);
  11332.         z = setnum(&sexpmaxdep,x,y,-1);
  11333.         if (z < 0)
  11334.           return(z);
  11335.         if (sxresult) {        /* Free old stack if allocated */
  11336.             for (i = 0; i < xx; i++)
  11337.               if (sxresult[i]) free(sxresult[i]);
  11338.             free((char *)sxresult);
  11339.             if (sxrlen) free((char *)sxrlen);
  11340.             sxresult = NULL;
  11341.             sxrlen = NULL;
  11342.         }
  11343.         break;
  11344.         }
  11345.       }
  11346.       return(success = 1);
  11347.       }
  11348. #endif /* NOSEXPL */
  11349. #endif /* NOSPL */
  11350.  
  11351. #ifdef NEWFTP
  11352.       case XYGPR: {
  11353.       extern struct keytab gprtab[];
  11354.       extern int ftpget;
  11355.       if ((x = cmkey(gprtab,3,"","kermit", xxstring)) < 0)
  11356.         return(x);
  11357.       if ((y = cmcfm()) < 0)
  11358.         return(y);
  11359.       ftpget = x;
  11360.       return(success = 1);
  11361.       }
  11362. #endif /* NEWFTP */
  11363.  
  11364. #ifdef ANYSSH
  11365.       case XYSSH:
  11366.     return(dosetssh());
  11367. #endif /* ANYSHH */
  11368.  
  11369.       default:
  11370.      if ((x = cmcfm()) < 0) return(x);
  11371.      printf("Not implemented - %s\n",cmdbuf);
  11372.      return(success = 0);
  11373.     }
  11374. }
  11375.  
  11376. /*
  11377.   H U P O K  --  Is Hangup OK?
  11378.  
  11379.   Issues a warning and gets OK from user depending on whether a connection
  11380.   seems to be open and what the SET EXIT WARNING setting is.  Returns:
  11381.     0 if not OK to hang up or exit (i.e. user said No);
  11382.     nonzero if OK.
  11383.   Argument x is used to differentiate the EXIT command from SET LINE / HOST.
  11384. */
  11385. int
  11386. hupok(x) int x; {            /* Returns 1 if OK, 0 if not OK */
  11387.     int y, z = 1;
  11388.     extern int exithangup;
  11389. #ifdef VMS
  11390.     extern int batch;
  11391.  
  11392.     if (batch)                /* No warnings in batch */
  11393.       return(1);
  11394. #else
  11395. #ifdef UNIX
  11396.     if (backgrd)            /* No warnings in background */
  11397.       return(1);
  11398. #endif /* UNIX */
  11399. #endif /* VMS */
  11400.  
  11401.     debug(F101,"hupok local","",local);
  11402.  
  11403.     if (!local)                /* No warnings in remote mode */
  11404.       return(1);
  11405.  
  11406.     if (x == 0 && exithangup == 0)    /* EXIT and EXIT HANGUP is OFF */
  11407.       return(1);
  11408.  
  11409.     debug(F101,"hupok x","",x);
  11410.     debug(F101,"hupok xitwarn","",xitwarn);
  11411.     debug(F101,"hupok network","",network);
  11412.     debug(F101,"hupok haveline","",haveline);
  11413.  
  11414.     if ((local && xitwarn) ||        /* Is a connection open? */
  11415.         (!x && xitwarn == 2)) {        /* Or Always give warning on EXIT */
  11416.     int needwarn = 0;
  11417.  
  11418.     if (network) {
  11419.         if (ttchk() >= 0)
  11420.           needwarn = 1;
  11421.         /* A connection seems to be open but it can't possibly be */
  11422.         if (!haveline)
  11423.           needwarn = 0;
  11424.         if (needwarn) {
  11425.         if (strcmp(ttname,"*"))
  11426.           printf(
  11427. " A network connection to %s might still be active.\n",
  11428.              ttname
  11429.              );
  11430.         else
  11431.           printf(
  11432.            " An incoming network connection might still be active.\n"
  11433.              );
  11434.         }
  11435.     } else {            /* Serial connection */
  11436.         if (carrier == CAR_OFF)    /* SET CARRIER OFF */
  11437.           needwarn = 0;        /* so we don't care about carrier. */
  11438.         else if ((y = ttgmdm()) >= 0) /* else, get modem signals */
  11439.           needwarn = (y & BM_DCD);    /* Check for carrier */
  11440.         else            /* If we can't get modem signals... */
  11441.           needwarn = (ttchk() >= 0);
  11442.         /* A connection seems to be open but it can't possibly be */
  11443.         if (!haveline || !exithangup)
  11444.           needwarn = 0;
  11445.         if (needwarn)
  11446.           printf(
  11447.              " A serial connection might still be active on %s.\n",
  11448.              ttname
  11449.              );
  11450.     }
  11451.  
  11452. /* If a warning was issued, get user's permission to EXIT. */
  11453.  
  11454.     if (needwarn || (!x && xitwarn == 2 && local)) {
  11455.         z = getyesno(x ? "OK to close? " : "OK to exit? ",0);
  11456.         debug(F101,"hupok getyesno","",z);
  11457.         if (z < -3) z = 0;
  11458.     }
  11459.     }
  11460.     return(z);
  11461. }
  11462.  
  11463. #ifndef NOSHOW
  11464. VOID
  11465. shoctl() {                /* SHOW CONTROL-PREFIXING */
  11466. #ifdef CK_SPEED
  11467.     int i;
  11468. #ifdef OS2
  11469.     int zero;
  11470. #endif /* OS2 */
  11471.     printf(
  11472. "\ncontrol quote = %d, applied to (0 = unprefixed, 1 = prefixed):\n\n",
  11473.        myctlq);
  11474. #ifdef OS2
  11475. #ifndef UNPREFIXZERO
  11476.     zero = ctlp[0];
  11477.     if (protocol == PROTO_K)        /* Zero can't be unprefixed */
  11478.       ctlp[0] = 1;            /* for Kermit */
  11479. #endif /* UNPREFIXZERO */
  11480. #endif /* OS2 */
  11481.     for (i = 0; i < 16; i++) {
  11482.     printf("  %3d: %d   %3d: %d ",i,ctlp[i], i+16, ctlp[i+16]);
  11483.     if (i == 15)
  11484.       printf("  127: %d",ctlp[127]);
  11485.     else
  11486.       printf("        ");
  11487.     printf("  %3d: %d   %3d: %d ",i+128,ctlp[i+128], i+144, ctlp[i+144]);
  11488.     if (i == 15)  printf("  255: %d",ctlp[255]);
  11489.     printf("\n");
  11490.     }
  11491.     printf("\n");
  11492. #ifndef UNPREFIXZERO
  11493. #ifdef OS2
  11494.     ctlp[0] = zero;
  11495. #endif /* OS2 */
  11496. #endif /* UNPREFIXZERO */
  11497.  
  11498. #endif /* CK_SPEED */
  11499. }
  11500.  
  11501. #ifndef NOXFER
  11502. VOID
  11503. shodbl() {                /* SHOW DOUBLE/IGNORE */
  11504. #ifdef CKXXCHAR
  11505.     int i, n = 0;
  11506.     printf("\nSET SEND DOUBLE characters:\n");
  11507.     for (i = 0; i < 255; i++) {
  11508.     if (dblt[i] & 2) {
  11509.         n++;
  11510.         printf(" %d", i);
  11511.     }
  11512.     }
  11513.     if (n == 0)
  11514.       printf(" (none)");
  11515.     n = 0;
  11516.     printf("\nSET RECEIVE IGNORE characters:\n");
  11517.     for (i = 0; i < 255; i++) {
  11518.     if (dblt[i] & 1) {
  11519.         n++;
  11520.         printf(" %d", i);
  11521.     }
  11522.     }
  11523.     if (n == 0)
  11524.       printf(" (none)");
  11525.     printf("\n\n");
  11526. #endif /* CKXXCHAR */
  11527. }
  11528. #endif /* NOXFER */
  11529. #endif /* NOSHOW */
  11530.  
  11531. #ifndef NOPUSH
  11532. #ifdef CK_REXX
  11533. /*
  11534.   Rexx command.  Note, this is not OS/2-specific, because Rexx also runs
  11535.   on other systems where C-Kermit also runs, like the Amiga.
  11536. */
  11537. #define REXBUFL 100            /* Change this if neccessary */
  11538. char rexxbuf[REXBUFL] = { '\0' };    /* Rexx's return value (string) */
  11539.  
  11540. int
  11541. dorexx() {
  11542.     int x, y;
  11543.     char *rexxcmd;
  11544.  
  11545.     if ((x = cmtxt("Rexx command","",&rexxcmd,xxstring)) < 0)
  11546.       return(x);
  11547.  
  11548. #ifdef IKSD
  11549.     if (inserver) {
  11550.         printf("?Sorry, command disabled.\r\n");
  11551.         return(success = 0);
  11552.     }
  11553. #endif /* IKSD */
  11554. #ifdef CK_APC
  11555.     /* Don't let this be set remotely */
  11556.     if (apcactive == APC_LOCAL ||
  11557.         apcactive == APC_REMOTE && !(apcstatus & APC_UNCH))
  11558.       return(success = 0);
  11559. #endif /* CK_APC */
  11560.  
  11561.     ckstrncpy(line,rexxcmd,LINBUFSIZ);
  11562.     rexxcmd = line;
  11563. #ifdef OS2
  11564.     return(os2rexx(rexxcmd,rexxbuf,REXBUFL));
  11565. #else /* !OS2 */
  11566.     printf("Sorry, nothing happens.\n");
  11567.     return(success = 0);
  11568. #endif /* OS2 */
  11569. }
  11570. #endif /* CK_REXX */
  11571. #endif /* NOPUSH */
  11572. #endif /* NOICP */
  11573.