home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / k95source / ckuus3.c < prev    next >
C/C++ Source or Header  |  2020-01-01  |  440KB  |  13,369 lines

  1. #ifdef SSHTEST
  2. #define SSHBUILTIN
  3. #endif /* SSHTEST */
  4.  
  5. #include "ckcsym.h"                     /* Symbol definitions */
  6.  
  7. /*  C K U U S 3 --  "User Interface" for C-Kermit, part 3  */
  8.  
  9. /*
  10.   Authors:
  11.     Frank da Cruz <fdc@columbia.edu>,
  12.       The Kermit Project, Columbia University, New York City
  13.     Jeffrey E Altman <jaltman@secure-endpoints.com>
  14.       Secure Endpoints Inc., New York City
  15.  
  16.   Copyright (C) 1985, 2005,
  17.     Trustees of Columbia University in the City of New York.
  18.     All rights reserved.  See the C-Kermit COPYING.TXT file or the
  19.     copyright text in the ckcmai.c module for disclaimer and permissions.
  20. */
  21.  
  22. /*  SET command (but much material has been split off into ckuus7.c). */
  23.  
  24. /*
  25.   Kermit-specific includes.
  26.   Definitions here supersede those from system include files.
  27. */
  28. #include "ckcdeb.h"                     /* Debugging & compiler things */
  29. #include "ckcasc.h"                     /* ASCII character symbols */
  30. #include "ckcker.h"                     /* Kermit application definitions */
  31. #include "ckcxla.h"                     /* Character set translation */
  32. #include "ckcnet.h"                     /* Network symbols */
  33.  
  34. char pwbuf[PWBUFL+1]  = { NUL, NUL };
  35. int pwflg = 0;
  36. int pwcrypt = 0;
  37.  
  38. #ifndef NOICP
  39.  
  40. #ifdef CK_AUTHENTICATION
  41. #include "ckuath.h"
  42. #endif /* CK_AUTHENTICATION */
  43. #ifdef CK_SSL
  44. #include "ck_ssl.h"
  45. #endif /* CK_SSL */
  46. #include "ckuusr.h"                     /* User interface symbols */
  47. #ifdef OS2
  48. #include "ckcuni.h"
  49. #ifdef SSHBUILTIN
  50. #include "ckossh.h"
  51. #endif /* SSHBUILTIN */
  52. #ifdef CK_NETBIOS
  53. #include <os2.h>
  54. #ifdef COMMENT                          /* Would you believe */
  55. #undef COMMENT                          /* <os2.h> defines this ? */
  56. #endif /* COMMENT */
  57. #include "ckonbi.h"
  58. extern UCHAR NetBiosAdapter;
  59. #endif /* CK_NETBIOS */
  60. #include "ckocon.h"
  61. #include "ckokey.h"
  62. #ifndef NOTERM
  63. extern unsigned char colorcmd;  /* Command-screen colors */
  64. extern struct keytab ttyclrtab[];
  65. extern int nclrs;
  66. extern int tt_cols[], tt_rows[], tt_szchng[], tt_status[];
  67. #endif /* NOTERM */
  68. _PROTOTYP(int setprty, (void));
  69. extern char startupdir[], exedir[];
  70. extern int tt_modechg;
  71. #ifdef NT
  72. #include <windows.h>
  73. #include <tapi.h>
  74. #include "ckntap.h"                     /* Microsoft TAPI */
  75. #endif /* NT */
  76. #endif /* OS2 */
  77.  
  78. #ifndef OS2
  79. extern char * exedir;
  80. #endif /* OS2 */
  81.  
  82. #ifdef CK_RECALL
  83. extern int cm_retry;
  84. #endif /* CK_RECALL */
  85.  
  86. extern int cmdint;
  87. extern int srvidl;
  88.  
  89. #ifdef CKFLOAT
  90. extern CKFLOAT floatval;        /* (see isfloat()) */
  91. #endif /* CKFLOAT */
  92.  
  93. #ifndef NOPUSH
  94. #ifndef NOFRILLS
  95. #ifdef VMS
  96. char editor[CKMAXPATH + 1] = "edit";
  97. #else
  98. char editor[CKMAXPATH + 1] = { NUL, NUL };
  99. #endif /* VMS */
  100. char editopts[128] = { NUL, NUL };
  101. char editfile[CKMAXPATH + 1] = { NUL, NUL };
  102. #ifdef BROWSER
  103. char browser[CKMAXPATH + 1] = { NUL, NUL };
  104. char browsopts[128] = { NUL, NUL };
  105. char browsurl[4096] = { NUL, NUL };
  106. #endif /* BROWSER */
  107. #endif /*  NOFRILLS */
  108. #endif /* NOPUSH */
  109.  
  110. /* Variables */
  111.  
  112. int cmd_quoting = 1;
  113. extern int hints, xcmdsrc;
  114.  
  115. #ifdef CK_KERBEROS
  116. char * k4pwprompt = NULL;               /* Kerberos 4 password prompt */
  117. char * k4prprompt = NULL;               /* Kerberos 4 principal prompt */
  118. char * k5pwprompt = NULL;               /* Kerberos 5 password prompt */
  119. char * k5prprompt = NULL;               /* Kerberos 5 principal prompt */
  120. #endif /* CK_KERBEROS */
  121. #ifdef CK_SRP
  122. char * srppwprompt = NULL;
  123. #endif /* CK_SRP */
  124.  
  125. extern char * ckprompt, * ikprompt;     /* Default prompt */
  126. extern xx_strp xxstring;
  127.  
  128. extern char * cdmsgfile[], * cdmsgstr;
  129.  
  130. extern int
  131.   local, server, success, dest, sleepcan, inserver, flow, autoflow, binary,
  132.   parity, escape, what, turn, duplex, backgrd, hwparity, stopbits, turnch,
  133.   mdmtyp, network, quiet, nettype, carrier, debses, debtim, cdtimo, nlangs,
  134.   bgset, pflag, msgflg, cmdmsk, xsuspend, techo, pacing, xitwarn, xitsta,
  135.   outesc, cmd_cols, cmd_rows, ckxech, xaskmore, haveline, didsetlin, isguest,
  136.   mdmsav, clearrq, saveask;
  137.  
  138. extern int reliable, setreliable, matchdot, matchfifo, dir_dots;
  139.  
  140. #ifndef NOSERVER
  141.   extern int en_pri;
  142. #endif /* NOSERVER */
  143.  
  144. #ifdef IKSDCONF
  145. extern int iksdcf;
  146. #endif /* IKSDCONF */
  147. #ifdef TCPSOCKET
  148.   extern int tn_exit;
  149. #endif /* TCPSOCKET */
  150. #ifdef TNCODE
  151.   char * tn_pr_uid = NULL;
  152. #endif /* TNCODE */
  153.   extern int exitonclose;
  154.  
  155. #ifndef NOKVERBS
  156. extern int nkverbs;
  157. extern struct keytab kverbs[];
  158. #endif /* NOKVERBS */
  159.  
  160. extern int ttnproto;                    /* Network protocol */
  161.  
  162. extern char *ccntab[];                  /* Names of control chars */
  163.  
  164. #ifdef CK_APC
  165. extern int apcactive, apcstatus;
  166. #endif /* CK_APC */
  167.  
  168. #ifndef NOSCRIPT
  169. extern int secho;                       /* Whether SCRIPT cmd should echo */
  170. #endif /* NOSCRIPT */
  171.  
  172. #ifdef DCMDBUF
  173. extern char *atmbuf, *atxbuf;
  174. #else
  175. extern char atmbuf[], atxbuf[];
  176. #endif /* DCMDBUF */
  177. extern int cmflgs;
  178.  
  179. extern char psave[];
  180. extern char uidbuf[];
  181. extern int  sl_uid_saved;
  182. int DeleteStartupFile = 0;
  183.  
  184. extern int cmdlvl;                      /* Overall command level */
  185.  
  186. #ifndef NOSPL
  187. _PROTOTYP( static int parsdir, (int) );
  188. char prmbuf[PWBUFL+1] = { NUL, NUL };
  189. int fndiags = 1;                        /* Function diagnostics on/off */
  190. int fnerror = 1;                        /* Function error treatment */
  191.  
  192. #ifdef DCMDBUF
  193. extern int *count, *takerr, *merror, *inpcas;
  194. #else
  195. extern int count[], takerr[], merror[], inpcas[];
  196. #endif /* DCMDBUF */
  197. extern int mecho;                       /* Macro echo */
  198. extern long ck_alarm;
  199. extern char alrm_date[], alrm_time[];
  200. #else
  201. extern int takerr[];
  202. #endif /* NOSPL */
  203.  
  204. extern int x_ifnum;
  205. extern int bigsbsiz, bigrbsiz;          /* Packet buffers */
  206.  
  207. extern long speed;                      /* Terminal speed */
  208.  
  209. extern char ttname[];                   /* Communication device name */
  210. extern char myhost[] ;
  211. extern char inidir[];                   /* Ini File directory */
  212.  
  213. #ifndef NOSETKEY
  214. extern KEY *keymap;                     /* Character map for SET KEY (1:1)  */
  215. extern MACRO *macrotab;                 /* Macro map for SET KEY (1:string) */
  216. #endif /* NOSETKEY */
  217. #ifdef OS2
  218. int wideresult;                         /* For wide OS/2 scan codes/cmnum() */
  219. #endif /* OS2 */
  220.  
  221. #ifndef NOLOCAL
  222. #ifdef OS2
  223. extern int tt_scrsize[];                /* Scrollback buffer Sizes */
  224. #endif /* OS2 */
  225. #endif /* NOLOCAL */
  226.  
  227. /* Printer settings */
  228.  
  229. extern char * printername;              /* NULL if printer not redirected */
  230. extern int printpipe;
  231. extern int noprinter;
  232. #ifdef PRINTSWI
  233. int printtimo = 0;
  234. char * printterm = NULL;
  235. char * printsep = NULL;
  236. int printertype = 0;
  237. #ifdef BPRINT
  238. int printbidi = 0;                      /* SET BPRINTER (bidirectional) */
  239. long pportspeed = 0L;                   /* Bidirection printer port speed, */
  240. int pportparity = 0;                    /*  parity, */
  241. int pportflow = FLO_KEEP;               /*  and flow control */
  242. #endif /* BPRINT */
  243. #ifdef OS2
  244. extern int txt2ps;                      /* Text2PS conversion? */
  245. extern int ps_width, ps_length;         /* Text2PS dimensions */
  246. #endif /* OS2 */
  247. #endif /* PRINTSWI */
  248.  
  249. #ifdef OS2
  250. extern int tcp_avail;                   /* Nonzero if TCP/IP is available */
  251. #ifdef DECNET
  252. extern int dnet_avail;                  /* Ditto for DECnet */
  253. #endif /* DECNET */
  254. #ifdef SUPERLAT
  255. extern int slat_avail;
  256. #endif /* SUPERLAT */
  257. #endif /* OS2 */
  258.  
  259. static struct keytab logintab[] = {
  260.     { "password", LOGI_PSW, CM_INV },
  261.     { "prompt",   LOGI_PRM, CM_INV },
  262.     { "userid",   LOGI_UID, 0 }
  263. };
  264.  
  265. #ifndef NOCSETS
  266. /* system-independent character sets, defined in ckcxla.[ch] */
  267. extern struct csinfo tcsinfo[];
  268. extern struct langinfo langs[];
  269.  
  270. /* Other character-set related variables */
  271. extern int tcharset, tslevel, language;
  272. #endif /* NOCSETS */
  273.  
  274. /* File-transfer variable declarations */
  275.  
  276. #ifndef NOXFER
  277. #ifdef CK_AUTODL
  278. extern int cmdadl;
  279. #endif /* CK_AUTODL */
  280.  
  281. #ifndef NOSERVER
  282. extern int ngetpath;
  283. extern char * getpath[];
  284. #endif /* NOSERVER */
  285.  
  286. extern struct ck_p ptab[];
  287.  
  288. extern CHAR sstate;                     /* Protocol start state */
  289. extern CHAR myctlq;                     /* Control-character prefix */
  290. extern CHAR myrptq;                     /* Repeat-count prefix */
  291.  
  292. extern int protocol, size, spsiz, spmax, urpsiz, srvtim, srvcdmsg, slostart,
  293.   srvdis, xfermode, ckdelay, keep, maxtry, unkcs, bctr, ebqflg, swcapr,
  294.   wslotr, lscapr, lscapu, spsizr, rptena, rptmin, docrc, xfrcan, xfrchr,
  295.   xfrnum, xfrbel, xfrint, srvping, g_xfermode, xfrxla;
  296.  
  297. #ifdef PIPESEND
  298. extern int usepipes;
  299. #endif /* PIPESEND */
  300.  
  301. #ifdef CKXXCHAR                         /* DOUBLE / IGNORE char table */
  302. extern int dblflag, ignflag, dblchar;
  303. extern short dblt[];
  304. #endif /* CKXXCHAR */
  305.  
  306. #ifdef CK_SPEED
  307. extern short ctlp[];                    /* Control-prefix table */
  308. extern int prefixing;
  309. static struct keytab pfxtab[] = {
  310.     "all",         PX_ALL, 0,
  311.     "cautious",    PX_CAU, 0,
  312.     "minimal",     PX_WIL, 0,
  313.     "none",        PX_NON, 0
  314. };
  315. #endif /* CK_SPEED */
  316. #endif /* NOXFER */
  317.  
  318. /* Declarations from cmd package */
  319.  
  320. #ifdef DCMDBUF
  321. extern char *cmdbuf;                    /* Command buffer */
  322. extern char *line;
  323. extern char *tmpbuf;
  324. #else
  325. extern char cmdbuf[];                   /* Command buffer */
  326. extern char line[];                     /* Character buffer for anything */
  327. extern char tmpbuf[];
  328. #endif /* DCMDBUF */
  329.  
  330. /* From main ckuser module... */
  331.  
  332. extern char *tp, *lp;                   /* Temporary buffer */
  333.  
  334. extern int tlevel;                      /* Take Command file level */
  335.  
  336. #ifndef NOLOCAL
  337. extern int sessft;                      /* Session-log file type */
  338. extern int slogts;                      /* Session-log timestamps on/off */
  339. #endif /* NOLOCAL */
  340.  
  341. char * tempdir = NULL;
  342.  
  343. #ifdef VMS
  344. int vms_msgs = 1;                       /* SET MESSAGES */
  345. extern int batch;
  346. #endif /* VMS */
  347.  
  348. /* Keyword tables for SET commands */
  349.  
  350. #ifdef CK_SPEED
  351. struct keytab ctltab[] = {
  352.     "prefixed",   1, 0,                 /* Note, the values are important. */
  353.     "unprefixed", 0, 0
  354. };
  355. #endif /* CK_SPEED */
  356.  
  357. static struct keytab oldnew[] = {
  358.     "new", 0, 0,
  359.     "old", 1, 0
  360. };
  361.  
  362. #define MCH_FIFO 1
  363. #define MCH_DOTF 2
  364. struct keytab matchtab[] = {
  365.     { "dotfile", MCH_DOTF, 0 },
  366.     { "fifo",    MCH_FIFO, 0 }
  367. };
  368. int nmatchtab = (sizeof(matchtab) / sizeof(struct keytab));
  369.  
  370. #ifndef NOSPL
  371. static struct keytab functab[] = {
  372.     "diagnostics", FUNC_DI, 0,
  373.     "error",       FUNC_ER, 0
  374. };
  375. static int nfunctab = (sizeof(functab) / sizeof(struct keytab));
  376.  
  377. struct keytab outptab[] = {             /* SET OUTPUT parameters */
  378.     "pacing", 0, 0,                     /* only one so far... */
  379.     "special-escapes", 1, 0
  380. };
  381. int noutptab = (sizeof(outptab) / sizeof(struct keytab)); /* How many */
  382. #endif /* NOSPL */
  383.  
  384. struct keytab chktab[] = {              /* Block check types */
  385.     "1", 1, 0,                          /* 1 =  6-bit checksum */
  386.     "2", 2, 0,                          /* 2 = 12-bit checksum */
  387.     "3", 3, 0,                          /* 3 = 16-bit CRC */
  388.     "4", 4, CM_INV,                     /* Same as B */
  389.     "blank-free-2", 4, 0                /* B = 12-bit checksum, no blanks */
  390. };
  391.  
  392. struct keytab rpttab[] = {              /* SET REPEAT */
  393.     "counts",    0, 0,                  /* On or Off */
  394. #ifdef COMMENT
  395.     "minimum",   1, 0,                  /* Threshhold */
  396. #endif /* COMMENT */
  397.     "prefix",    2, 0                   /* Repeat-prefix character value */
  398. };
  399.  
  400. #ifndef NOLOCAL
  401. /* For SET [ MODEM ] CARRIER, and also for SET DIAL CONNECT */
  402.  
  403. struct keytab crrtab[] = {
  404.     "automatic", CAR_AUT, 0,            /* 2 */
  405.     "off",       CAR_OFF, 0,            /* 0 */
  406.     "on",        CAR_ON,  0             /* 1 */
  407. };
  408. int ncrr = 3;
  409. #endif /* NOLOCAL */
  410.  
  411. struct keytab ooatab[] = {              /* On/Off/Auto table */
  412.     "automatic", SET_AUTO, 0,           /* 2 */
  413.     "off",       SET_OFF,  0,           /* 0 */
  414.     "on",        SET_ON,   0            /* 1 */
  415. };
  416.  
  417. struct keytab ooktab[] = {              /* On/Off/Ask table */
  418.     "ask",       2,        0,           /* 2 */
  419.     "off",       SET_OFF,  0,           /* 0 */
  420.     "on",        SET_ON,   0            /* 1 */
  421. };
  422.  
  423. struct keytab qvtab[] = {               /* Quiet/Verbose table */
  424.     "quiet", 1, 0,
  425.     "verbose", 0, 0
  426. };
  427. int nqvt = 2;
  428.  
  429. /* For SET DEBUG */
  430.  
  431. #define DEB_OFF  0
  432. #define DEB_ON   1
  433. #define DEB_SES  2
  434. #define DEB_TIM  3
  435. #define DEB_LEN  4
  436.  
  437. struct keytab dbgtab[] = {
  438.     "linelength", DEB_LEN, CM_INV,
  439.     "off",        DEB_OFF, 0,
  440.     "on",         DEB_ON,  0,
  441.     "session",    DEB_SES, 0,
  442.     "timestamps", DEB_TIM, 0
  443. };
  444. int ndbg = (sizeof(dbgtab) / sizeof(struct keytab));
  445.  
  446. #ifndef NOLOCAL
  447. /* Transmission speeds */
  448.  
  449. #ifdef TTSPDLIST /* Speed table constructed at runtime . . . */
  450.  
  451. struct keytab * spdtab = NULL;
  452. int nspd = 0;
  453.  
  454. #else
  455. /*
  456.   Note, the values are encoded in cps rather than bps because 19200 and higher
  457.   are too big for some ints.  All but 75bps are multiples of ten.  Result of
  458.   lookup in this table must be multiplied by 10 to get actual speed in bps.
  459.   If this number is 70, it must be changed to 75.  If it is 888, this means
  460.   75/1200 split speed.
  461.  
  462.   The values are generic, rather than specific to UNIX.  We can't use B75,
  463.   B1200, B9600, etc, because non-UNIX versions of C-Kermit will not
  464.   necessarily have these symbols defined.  The BPS_xxx symbols are
  465.   Kermit-specific, and are defined in ckcdeb.h or on the CC command line.
  466.  
  467.   Like all other keytabs, this one must be in "alphabetical" order,
  468.   rather than numeric order.
  469. */
  470. struct keytab spdtab[] = {
  471.     "0",      0,  CM_INV,
  472.     "110",   11,  0,
  473. #ifdef BPS_115K
  474.  "115200",11520,  0,
  475. #endif /* BPS_115K */
  476.   "1200",   120,  0,
  477. #ifdef BPS_134
  478.   "134.5",  134,  0,
  479. #endif /* BPS_134 */
  480. #ifdef BPS_14K
  481.   "14400", 1440,  0,
  482. #endif /* BPS_14K */
  483. #ifdef BPS_150
  484.   "150",     15,  0,
  485. #endif /* BPS_150 */
  486. #ifdef BPS_1800
  487.   "1800",     180,  0,
  488. #endif /* BPS_150 */
  489. #ifdef BPS_19K
  490.   "19200", 1920,  0,
  491. #endif /* BPS_19K */
  492. #ifdef BPS_200
  493.   "200",     20,  0,
  494. #endif /* BPS_200 */
  495. #ifdef BPS_230K
  496.   "230400", 23040, 0,
  497. #endif /* BPS_230K */
  498.   "2400",   240,  0,
  499. #ifdef BPS_28K
  500.   "28800", 2880,  0,
  501. #endif /* BPS_28K */
  502.   "300",     30,  0,
  503. #ifdef BPS_3600
  504.   "3600",   360,  0,
  505. #endif /* BPS_3600 */
  506. #ifdef BPS_38K
  507.   "38400", 3840,  0,
  508. #endif /* BPS_38K */
  509. #ifdef BPS_460K
  510.   "460800", 46080,  0,                  /* Need 32 bits for this... */
  511. #endif /* BPS_460K */
  512.   "4800",   480,  0,
  513. #ifdef BPS_50
  514.   "50",       5,  0,
  515. #endif /* BPS_50 */
  516. #ifdef BPS_57K
  517.   "57600", 5760,  0,
  518. #endif /* BPS_57K */
  519.   "600",     60,  0,
  520. #ifdef BPS_7200
  521.   "7200",   720,  0,
  522. #endif /* BPS_7200 */
  523. #ifdef BPS_75
  524.   "75",       7,  0,
  525. #endif /* BPS_75 */
  526. #ifdef BPS_7512
  527.   "75/1200",888,  0,                    /* Code "888" for split speed */
  528. #endif /* BPS_7512 */
  529. #ifdef BPS_76K
  530.   "76800", 7680,  0,
  531. #endif /* BPS_76K */
  532. #ifdef BPS_921K
  533.   "921600", 92160,0,                    /* Need 32 bits for this... */
  534. #endif /* BPS_921K */
  535.   "9600",   960,  0
  536. };
  537. int nspd = (sizeof(spdtab) / sizeof(struct keytab)); /* How many speeds */
  538. #endif /* TTSPDLIST */
  539.  
  540. #ifdef TN_COMPORT
  541. struct keytab tnspdtab[] = {            /* RFC 2217 TELNET COMPORT Option */
  542.     "115200", 11520,  0,                /* (add any other defined speeds) */
  543.     "1200",     120,  0,
  544.     "14400",   1440,  0,
  545.     "19200",   1920,  0,
  546.     "230400", 23040,  0,
  547.     "2400",     240,  0,
  548.     "28800",   2880,  0,
  549.     "300",       30,  0,
  550.     "38400",   3840,  0,
  551.     "460800", 46080,  0,
  552.     "4800",     480,  0,
  553.     "57600",   5760,  0,
  554.     "600",       60,  0,
  555.     "9600",     960,  0
  556. };
  557. int ntnspd = (sizeof(tnspdtab) / sizeof(struct keytab)); /* How many speeds */
  558. #endif /* TN_COMPORT */
  559. #endif /* NOLOCAL */
  560.  
  561. #ifndef NOCSETS
  562. extern struct keytab lngtab[];          /* Languages for SET LANGUAGE */
  563. extern int nlng;
  564. #endif /* NOCSETS */
  565.  
  566. #ifndef NOLOCAL
  567. /* Duplex keyword table */
  568.  
  569. struct keytab dpxtab[] = {
  570.     "full",      0, 0,
  571.     "half",      1, 0
  572. };
  573. #endif /* NOLOCAL */
  574.  
  575. /* Flow Control */
  576.  
  577. struct keytab cxtypesw[] = {
  578. #ifdef DECNET
  579.     "/decnet",         CXT_DECNET,  0,
  580. #endif /* DECNET */
  581.     "/direct-serial",  CXT_DIRECT,  0,
  582. #ifdef DECNET
  583.     "/lat",            CXT_LAT,     0,
  584. #else
  585. #ifdef SUPERLAT
  586.     "/lat",            CXT_LAT,     0,
  587. #endif /* SUPERLAT */
  588. #endif /* DECNET */
  589.     "/modem",          CXT_MODEM,   0,
  590. #ifdef NPIPE
  591.     "/named-pipe",     CXT_NPIPE,   0,
  592. #endif /* NPIPE */
  593. #ifdef NETBIOS
  594.     "/netbios",        CXT_NETBIOS, 0,
  595. #endif /* NETBIOS */
  596.     "/remote",         CXT_REMOTE,  0,
  597. #ifdef TCPSOCKET
  598.     "/tcpip",          CXT_TCPIP,   0,
  599. #endif /* TCPSOCKET */
  600. #ifdef ANYX25
  601.     "/x.25",           CXT_X25,     0,
  602. #endif /* ANYX25 */
  603.     "", 0, 0
  604. };
  605. int ncxtypesw = (sizeof(cxtypesw) / sizeof(struct keytab));
  606.  
  607. #ifdef TN_COMPORT
  608. struct keytab tnflotab[] = {            /* SET FLOW-CONTROL keyword table */
  609.     "dtr/cd",    FLO_DTRC, 0,           /* for RFC 2217 Telnet COMPORT */
  610.     "dtr/cts",   FLO_DTRT, 0,
  611.     "keep",      FLO_KEEP, 0,
  612.     "none",      FLO_NONE, 0,
  613.     "rts/cts",   FLO_RTSC, 0,
  614.     "xon/xoff",  FLO_XONX, 0
  615. };
  616. int ntnflo = (sizeof(tnflotab) / sizeof(struct keytab));
  617. #endif /* TN_COMPORT */
  618.  
  619. struct keytab flotab[] = {              /* SET FLOW-CONTROL keyword table */
  620.     "automatic", FLO_AUTO, CM_INV,      /* Not needed any more */
  621. #ifdef CK_DTRCD
  622.     "dtr/cd",    FLO_DTRC, 0,
  623. #endif /* CK_DTRCD */
  624. #ifdef CK_DTRCTS
  625.     "dtr/cts",   FLO_DTRT, 0,
  626. #endif /* CK_DTRCTS */
  627.     "keep",      FLO_KEEP, 0,
  628.     "none",      FLO_NONE, 0,
  629. #ifdef CK_RTSCTS
  630.     "rts/cts",   FLO_RTSC, 0,
  631. #endif /* CK_RTSCTS */
  632. #ifndef Plan9
  633.     "xon/xoff",  FLO_XONX, 0,
  634. #endif /* Plan9 */
  635.     "", 0, 0
  636. };
  637. int nflo = (sizeof(flotab) / sizeof(struct keytab)) - 1;
  638.  
  639. /*  Handshake characters  */
  640.  
  641. struct keytab hshtab[] = {
  642.     "bell", 007, 0,
  643.     "code", 998, 0,
  644.     "cr",   015, 0,
  645.     "esc",  033, 0,
  646.     "lf",   012, 0,
  647.     "none", 999, 0,                     /* (can't use negative numbers) */
  648.     "xoff", 023, 0,
  649.     "xon",  021, 0
  650. };
  651. int nhsh = (sizeof(hshtab) / sizeof(struct keytab));
  652.  
  653. #ifndef NOLOCAL
  654. static struct keytab sfttab[] = {       /* File types for SET SESSION-LOG */
  655.     "ascii",     XYFT_T, CM_INV,
  656.     "binary",    XYFT_B, 0,
  657.     "debug",     XYFT_D, 0,
  658.     "text",      XYFT_T, 0,
  659.     "timestamped-text", 999, 0
  660. };
  661. static int nsfttab = (sizeof(sfttab) / sizeof(struct keytab));
  662. #endif /* NOLOCAL */
  663.  
  664. #ifndef NODIAL
  665.  
  666. #ifdef NETCONN                          /* Networks directory depends */
  667. int nnetdir = 0;                        /* on DIAL code -- fix later... */
  668. char *netdir[MAXDDIR+2];
  669. #endif /* NETCONN */
  670.  
  671. _PROTOTYP( static int setdial, (int) );
  672. _PROTOTYP( static int setdcd, (void) );
  673. _PROTOTYP( static int cklogin, (void) );
  674.  
  675. #ifndef MINIDIAL
  676. #ifdef OLDTBCODE
  677. extern int tbmodel;                     /* Telebit model ID */
  678. #endif /* OLDTBCODE */
  679. #endif /* MINIDIAL */
  680.  
  681. extern MDMINF *modemp[];                /* Pointers to modem info structs */
  682. extern struct keytab mdmtab[];          /* Modem types (in module ckudia.c) */
  683. extern int nmdm;                        /* Number of them */
  684.  
  685. _PROTOTYP(static int dialstr,(char **, char *));
  686.  
  687. extern int dialhng, dialtmo, dialksp, dialdpy, dialmhu, dialec, dialdc;
  688. extern int dialrtr, dialint, dialudt, dialsrt, dialrstr, mdmwaitd;
  689. extern int mdmspd, dialfc, dialmth, dialesc, dialfld, dialidt, dialpace;
  690. extern int mdmspk, mdmvol, dialtest;
  691.  
  692. int dialcvt = 2;                        /* DIAL CONVERT-DIRECTORY */
  693. int dialcnf = 0;                        /* DIAL CONFIRMATION */
  694. int dialcon = 2;                        /* DIAL CONNECT */
  695. int dialcq  = 0;                        /* DIAL CONNECT AUTO quiet/verbose */
  696. extern long dialmax, dialcapas;
  697. int usermdm = 0;
  698. extern int ndialdir;
  699. extern char *dialini,   *dialmstr, *dialmprmt, *dialdir[], *dialcmd,  *dialnpr,
  700.  *dialdcon, *dialdcoff, *dialecon, *dialecoff, *dialhcmd,  *dialx3,
  701.  *dialhwfc, *dialswfc,  *dialnofc, *dialtone,  *dialpulse, *dialname, *diallac;
  702. extern char *diallcc,   *dialixp,  *dialixs,   *dialldp,   *diallds,  *dialtfp,
  703.  *dialpxi,  *dialpxo,   *dialsfx,  *dialaaon,  *dialaaoff;
  704. extern char *diallcp,   *diallcs,  *dialini2,  *dialmac;
  705. extern char *dialspoff, *dialspon, *dialvol1,  *dialvol2,  *dialvol3;
  706.  
  707. char *dialtocc[MAXTPCC] = { NULL, NULL };
  708. int ndialtocc = 0;
  709. char *dialpucc[MAXTPCC] = { NULL, NULL };
  710. int ndialpucc = 0;
  711.  
  712. char *dialtfc[MAXTOLLFREE] = {
  713.     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
  714. };
  715. int ntollfree = 0;
  716.  
  717. char *dialpxx[MAXPBXEXCH] = {
  718.     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
  719. };
  720. int ndialpxx = 0;
  721.  
  722. char *diallcac[MAXLOCALAC] = {
  723.     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  724.     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  725.     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  726.     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
  727. };
  728. int nlocalac = 0;
  729.  
  730. static struct keytab drstrtab[] = {
  731.     "international", 5, 0,
  732.     "local",         2, 0,
  733.     "long-distance", 4, 0,
  734.     "none",          6, 0
  735. };
  736.  
  737. static struct keytab dcnvtab[] = {
  738.     "ask",  2, 0,
  739.     "off",  0, 0,
  740.     "on",   1, 0
  741. };
  742.  
  743. struct keytab setmdm[] = {
  744.     "capabilities",     XYDCAP,  0,
  745.     "carrier-watch",    XYDMCD,  0,
  746.     "command",          XYDSTR,  0,
  747.     "compression",      XYDDC,   CM_INV,
  748.     "data-compression", XYDDC,   0,
  749.     "dial-command",     XYDDIA,  0,
  750.     "error-correction", XYDEC,   0,
  751.     "escape-character", XYDESC,  0,
  752.     "flow-control",     XYDFC,   0,
  753.     "hangup-method",    XYDMHU,  0,
  754. #ifndef NOXFER
  755.     "kermit-spoof",     XYDKSP,  0,
  756. #endif /* NOXFER */
  757.     "maximum-speed",    XYDMAX,  0,
  758.     "name",             XYDNAM,  0,
  759.     "speaker",          XYDSPK,  0,
  760.     "speed-matching",   XYDSPD,  0,
  761.     "type",             XYDTYP,  0,
  762.     "volume",           XYDVOL,  0
  763. };
  764. int nsetmdm = (sizeof(setmdm) / sizeof(struct keytab));
  765.  
  766. struct keytab voltab[] = {
  767.     "high",   3,  0,
  768.     "low",    1,  0,
  769.     "medium", 2,  0
  770. };
  771.  
  772. struct keytab mdmcap[] = {
  773.     "at-commands",      CKD_AT,  0,
  774.     "compression",      CKD_DC,  0,
  775.     "dc",               CKD_DC,  CM_INV,
  776.     "ec",               CKD_EC,  CM_INV,
  777.     "error-correction", CKD_EC,  0,
  778.     "hardware-flow",    CKD_HW,  0,
  779.     "hwfc",             CKD_HW,  CM_INV,
  780.     "itu",              CKD_V25, CM_INV,
  781.     "kermit-spoof",     CKD_KS,  0,
  782.     "ks",               CKD_KS,  CM_INV,
  783.     "sb",               CKD_SB,  CM_INV,
  784.     "software-flow",    CKD_SW,  0,
  785.     "speed-buffering",  CKD_SB,  0,
  786.     "swfc",             CKD_SW,  CM_INV,
  787.     "tb",               CKD_TB,  CM_INV,
  788.     "telebit",          CKD_TB,  0,
  789.     "v25bis-commands",  CKD_V25, 0
  790. };
  791. int nmdmcap = (sizeof(mdmcap) / sizeof(struct keytab));
  792.  
  793. #ifdef COMMENT                          /* SET ANSWER not implemented yet */
  794. static struct keytab answertab[] = {
  795.     { "caller-id",  XYA_CID,  0 };
  796.     { "rings",      XYA_RNG,  0 };
  797.     { "", 0, 0 }
  798. };
  799. static int nanswertab =  (sizeof(answertab) / sizeof(struct keytab)) - 1;
  800. #endif /* COMMENT */
  801.  
  802. struct keytab dialtab[] = {             /* SET DIAL table */
  803.     "area-code",        XYDLAC, 0,      /* Also still includes items     */
  804.     "compression",      XYDDC,  CM_INV, /* that were moved to SET MODEM, */
  805.     "confirmation",     XYDCNF, 0,      /* but they are CM_INVisible...  */
  806.     "connect",          XYDCON, 0,
  807.     "convert-directory",XYDCVT, 0,
  808.     "country-code",     XYDLCC, 0,
  809.     "dial-command",     XYDDIA, CM_INV,
  810.     "directory",        XYDDIR, 0,
  811.     "display",          XYDDPY, 0,
  812.     "escape-character", XYDESC, CM_INV,
  813.     "error-correction", XYDEC,  CM_INV,
  814.     "flow-control",     XYDFC,  CM_INV,
  815.     "force-long-distance", XYDFLD, 0,
  816.     "hangup",           XYDHUP, 0,
  817.     "ignore-dialtone",  XYDIDT, 0,
  818.     "interval",         XYDINT, 0,
  819.     "in",               XYDINI, CM_INV|CM_ABR,
  820.     "init-string",      XYDINI, CM_INV,
  821.     "intl-prefix",      XYDIXP, 0,
  822.     "intl-suffix",      XYDIXS, 0,
  823. #ifndef NOXFER
  824.     "kermit-spoof",     XYDKSP, CM_INV,
  825. #endif /* NOXFER */
  826.     "lc-area-codes",    XYDLLAC, 0,
  827.     "lc-prefix",        XYDLCP, 0,
  828.     "lc-suffix",        XYDLCS, 0,
  829.     "ld-prefix",        XYDLDP, 0,
  830.     "ld-suffix",        XYDLDS, 0,
  831.     "local-area-code",  XYDLAC, CM_INV,
  832.     "local-prefix",     XYDLCP, CM_INV,
  833.     "local-suffix",     XYDLCS, CM_INV,
  834.     "m",                XYDMTH, CM_INV|CM_ABR,
  835. #ifndef NOSPL
  836.     "macro",            XYDMAC, 0,      /* 195 */
  837. #endif /* NOSPL */
  838. #ifdef MDMHUP
  839.     "me",               XYDMTH, CM_INV|CM_ABR,
  840. #endif /* MDMHUP */
  841.     "method",           XYDMTH, 0,
  842.     "mnp-enable",       XYDMNP, CM_INV, /* obsolete but still accepted */
  843. #ifdef MDMHUP
  844.     "modem-hangup",     XYDMHU, CM_INV,
  845. #endif /* MDMHUP */
  846.     "pacing",           XYDPAC,  0,
  847.     "pbx-exchange",     XYDPXX,  0,
  848.     "pbx-inside-prefix",XYDPXI,  0,
  849.     "pbx-outside-prefix",XYDPXO, 0,
  850.     "prefix",           XYDNPR,  0,
  851.     "pulse-countries",  XYDPUCC, 0,
  852.     "restrict",         XYDRSTR, 0,
  853.     "retries",          XYDRTM,  0,
  854.     "sort",             XYDSRT,  0,
  855.     "speed-matching",   XYDSPD,  CM_INV,
  856.     "string",           XYDSTR,  CM_INV,
  857.     "suffix",           XYDSFX,  0,
  858.     "test",             XYDTEST, 0,
  859.     "timeout",          XYDTMO,  0,
  860.     "tf-area-code",     XYDTFC,  CM_INV,
  861.     "tf-prefix",        XYDTFP,  CM_INV,
  862.     "toll-free-area-code",XYDTFC,0,
  863.     "toll-free-prefix", XYDTFP,  0,
  864.     "tone-countries",   XYDTOCC, 0
  865. };
  866. int ndial = (sizeof(dialtab) / sizeof(struct keytab));
  867.  
  868. #ifdef MDMHUP
  869. struct keytab mdmhang[] = {
  870.     "dtr",           0, 0,
  871.     "modem-command", 1, 0,
  872.     "rs232-signal",  0, 0,
  873.     "v24-signal",    0, CM_INV
  874. };
  875. #endif /* MDMHUP */
  876.  
  877. static struct keytab mdmcmd[] = {
  878.     "autoanswer",       XYDS_AN, 0,     /* autoanswer */
  879.     "compression",      XYDS_DC, 0,     /* data compression */
  880.     "dial-mode-prompt", XYDS_MP, 0,     /* dial mode prompt */
  881.     "dial-mode-string", XYDS_MS, 0,     /* dial mode string */
  882.     "error-correction", XYDS_EC, 0,     /* error correction */
  883.     "hangup-command",   XYDS_HU, 0,     /* hangup command */
  884.     "hardware-flow",    XYDS_HW, 0,     /* hwfc */
  885.     "ignore-dialtone",  XYDS_ID, 0,     /* ignore dialtone */
  886.     "init-string",      XYDS_IN, 0,     /* init string */
  887.     "no-flow-control",  XYDS_NF, 0,     /* no flow control */
  888.     "predial-init",     XYDS_I2, 0,     /* last-minute setup commands */
  889.     "pulse",            XYDS_DP, 0,     /* pulse */
  890.     "software-flow",    XYDS_SW, 0,     /* swfc */
  891.     "speaker",          XYDS_SP, 0,     /* Speaker */
  892.     "tone",             XYDS_DT, 0,     /* tone */
  893.     "volume",           XYDS_VO, 0      /* Volume */
  894. };
  895. static int nmdmcmd = (sizeof(mdmcmd) / sizeof(struct keytab));
  896.  
  897. struct keytab dial_fc[] = {
  898.     "auto",     FLO_AUTO, 0,
  899.     "none",     FLO_NONE, 0,
  900.     "rts/cts",  FLO_RTSC, 0,
  901.     "xon/xoff", FLO_XONX, 0
  902. };
  903.  
  904. struct keytab dial_m[] = {              /* DIAL METHOD */
  905.     "auto",    XYDM_A, 0,
  906.     "default", XYDM_D, 0,
  907.     "pulse",   XYDM_P, 0,
  908.     "tone",    XYDM_T, 0
  909. };
  910. int ndial_m = (sizeof(dial_m)/sizeof(struct keytab));
  911. #endif /* NODIAL */
  912.  
  913. #ifdef CK_TAPI
  914. struct keytab tapitab[] = {             /* Top-Level Microsoft TAPI */
  915.     "configure-line",     XYTAPI_CFG,  0,
  916.     "dialing-properties", XYTAPI_DIAL, 0
  917. };
  918. int ntapitab = (sizeof(tapitab)/sizeof(struct keytab));
  919.  
  920. struct keytab settapitab[] = {          /* SET Microsoft TAPI */
  921.     "inactivity-timeout", XYTAPI_INA,  0,
  922.     "line",               XYTAPI_LIN,  0,
  923.     "location",           XYTAPI_LOC,  0,
  924.     "manual-dialing",     XYTAPI_MAN,  0,
  925.     "modem-dialing",      XYTAPI_PASS, 0,
  926.     "modem-lights",       XYTAPI_LGHT, 0,
  927.     "phone-number-conversions",   XYTAPI_CON,  0,
  928.     "port",               XYTAPI_LIN,  CM_INV,
  929.     "post-dial-terminal", XYTAPI_PST,  0,
  930.     "pre-dial-terminal",  XYTAPI_PRE,  0,
  931.     "use-windows-configuration", XYTAPI_USE, 0,
  932.     "wait-for-credit-card-tone", XYTAPI_BNG, 0
  933. };
  934. int nsettapitab = (sizeof(settapitab)/sizeof(struct keytab));
  935.  
  936. struct keytab * tapiloctab = NULL;      /* Microsoft TAPI Locations */
  937. int ntapiloc = 0;
  938. extern struct keytab * tapilinetab;     /* Microsoft TAPI Line Devices */
  939. extern int ntapiline;
  940. extern int tttapi;                      /* TAPI in use */
  941. extern int tapipass;                    /* TAPI Passthrough mode */
  942. extern int tapiconv;                    /* TAPI Conversion mode */
  943. extern int tapilights;
  944. extern int tapipreterm;
  945. extern int tapipostterm;
  946. extern int tapimanual;
  947. extern int tapiinactivity;
  948. extern int tapibong;
  949. extern int tapiusecfg;
  950. #endif /* CK_TAPI */
  951.  
  952. #ifndef NOPUSH
  953. extern int nopush;
  954. extern int wildena;
  955. #ifdef UNIX
  956. struct keytab wildtab[] = {             /* SET WILDCARD-EXPANSION */
  957. #ifdef UNIX
  958.     "kermit",  WILD_KER, 0,        /* By Kermit */
  959. #endif    /* UNIX */
  960.     "off",     WILD_OFF, 0,        /* Disabled */
  961.     "on",      WILD_ON,  0,        /* Enabled */
  962. #ifdef UNIX
  963.     "shell",   WILD_SHE, 0,        /* By Shell */
  964. #endif    /* UNIX */
  965.     "", 0, 0
  966. };
  967. int nwild = (sizeof(wildtab) / sizeof(struct keytab)) - 1;
  968.  
  969. struct keytab wdottab[] = {             /* cont'd */
  970.     "/match-dot-files",    1, 0,
  971.     "/no-match-dot-files", 0, 0
  972. };
  973. extern int wildxpand;
  974. #endif /* UNIX */
  975. #endif /* NOPUSH */
  976.  
  977. #ifdef NETCONN
  978. extern struct keytab netcmd[], netkey[];
  979. extern int nnets, nnetkey;
  980. #ifdef TCPSOCKET
  981. extern struct keytab tcpopt[];
  982. extern int ntcpopt;
  983. #endif /* TCPSOCKET */
  984. #ifdef NPIPE
  985. char pipename[PIPENAML+1] = { NUL, NUL };
  986. #endif /* NPIPE */
  987. #ifdef CK_NETBIOS
  988. extern unsigned char NetBiosName[];
  989. #endif /* CK_NETBIOS */
  990. #endif /* NETCONN */
  991.  
  992. #ifdef ANYX25
  993. struct keytab x25tab[] = {
  994.     "call-user-data",    XYUDAT, 0,
  995.     "closed-user-group", XYCLOS, 0,
  996.     "reverse-charge",    XYREVC, 0
  997. };
  998. int nx25 = (sizeof(x25tab) / sizeof(struct keytab));
  999.  
  1000. #ifndef IBMX25
  1001. struct keytab padx3tab[] = {
  1002.     "break-action",         PAD_BREAK_ACTION,           0,
  1003.     "break-character",      PAD_BREAK_CHARACTER,        0,
  1004.     "character-delete",     PAD_CHAR_DELETE_CHAR,       0,
  1005.     "cr-padding",           PAD_PADDING_AFTER_CR,       0,
  1006.     "discard-output",       PAD_SUPPRESSION_OF_DATA,    0,
  1007.     "echo",                 PAD_ECHO,                   0,
  1008.     "editing",              PAD_EDITING,                0,
  1009.     "escape",               PAD_ESCAPE,                 0,
  1010.     "forward",              PAD_DATA_FORWARD_CHAR,      0,
  1011.     "lf-padding",           PAD_PADDING_AFTER_LF,       0,
  1012.     "lf-insert",            PAD_LF_AFTER_CR,            0,
  1013.     "line-delete",          PAD_BUFFER_DELETE_CHAR,     0,
  1014.     "line-display",         PAD_BUFFER_DISPLAY_CHAR,    0,
  1015.     "line-fold",            PAD_LINE_FOLDING,           0,
  1016.     "pad-flow-control",     PAD_FLOW_CONTROL_BY_PAD,    0,
  1017.     "service-signals",      PAD_SUPPRESSION_OF_SIGNALS, 0,
  1018.     "timeout",              PAD_DATA_FORWARD_TIMEOUT,   0,
  1019. /* Speed is read-only */
  1020.     "transmission-rate",    PAD_LINE_SPEED,             0,
  1021.     "user-flow-control",    PAD_FLOW_CONTROL_BY_USER,   0
  1022. };
  1023. int npadx3 = (sizeof(padx3tab) / sizeof(struct keytab));
  1024. #endif /* IBMX25 */
  1025. #endif /* ANYX25 */
  1026.  
  1027. #ifdef TLOG
  1028. static struct keytab vbtab[] = {
  1029.     "brief",   0, 0,
  1030. #ifdef OS2ORUNIX
  1031.     "ftp",     2, 0,
  1032. #endif /* OS2ORUNIX */
  1033.     "verbose", 1, 0
  1034. };
  1035. int nvb = (sizeof(vbtab) / sizeof(struct keytab));
  1036. #endif /* TLOG */
  1037.  
  1038. #ifdef CKSYSLOG
  1039. static struct keytab syslogtab[] = {
  1040.     "all",         SYSLG_CX, 0,
  1041.     "commands",    SYSLG_CM, 0,
  1042.     "connection",  SYSLG_AC, 0,
  1043.     "debug",       SYSLG_DB, 0,
  1044.     "dial",        SYSLG_DI, 0,
  1045.     "file-access", SYSLG_FA, 0,
  1046.     "file-create", SYSLG_FC, 0,
  1047.     "login",       SYSLG_LI, 0,
  1048.     "none",        SYSLG_NO, 0,
  1049.     "protocol",    SYSLG_PR, 0
  1050. };
  1051. int nsyslog = (sizeof(syslogtab) / sizeof(struct keytab));
  1052. #endif /* CKSYSLOG */
  1053.  
  1054. /* Parity keyword table */
  1055.  
  1056. struct keytab partbl[] = {
  1057.     "even",    'e', 0,
  1058. #ifdef HWPARITY
  1059.     "hardware",'H', 0,
  1060. #endif /* HWPARITY */
  1061.     "mark",    'm', 0,
  1062.     "none",     0 , 0,
  1063.     "odd",     'o', 0,
  1064.     "space",   's', 0
  1065. };
  1066. int npar = (sizeof(partbl) / sizeof(struct keytab));
  1067.  
  1068. #ifdef HWPARITY
  1069. struct keytab hwpartbl[] = {
  1070. /* Add mark and space if needed and possible */
  1071.     "even",    'e', 0,
  1072. #ifdef OS2
  1073.     "mark",    'm', 0,
  1074. #endif /* OS2 */
  1075.     "odd",     'o', 0,
  1076. #ifdef OS2
  1077.     "space",   's', 0,
  1078. #endif /* OS2 */
  1079.     "", 0, 0
  1080. };
  1081. int nhwpar = (sizeof(hwpartbl) / sizeof(struct keytab)) - 1;
  1082. #endif /* HWPARITY */
  1083.  
  1084. /* On/Off table */
  1085.  
  1086. struct keytab onoff[] = {
  1087.     "off",       0, 0,
  1088.     "on",        1, 0
  1089. };
  1090.  
  1091. #define XYCD_M    0            /* CD MESSAGE */
  1092. #define XYCD_P    1            /* CD PATH */
  1093. #define XYCD_H    2            /* CD HOME */
  1094.  
  1095. struct keytab cdtab[] = {
  1096.     "home",      XYCD_H, 0,
  1097.     "message",   XYCD_M, 0,
  1098.     "path",      XYCD_P, 0
  1099. };
  1100. int ncdtab = (sizeof(cdtab) / sizeof(struct keytab));
  1101.  
  1102. struct keytab cdmsg[] = {
  1103.     "file",      2, 0,
  1104.     "off",       0, 0,
  1105.     "on",        1, 0
  1106. };
  1107. int ncdmsg = (sizeof(cdmsg) / sizeof(struct keytab));
  1108.  
  1109. static
  1110. struct keytab xittab[] = {              /* SET EXIT */
  1111.     "hangup",        3, 0,              /* ...HANGUP */
  1112.     "on-disconnect", 2, 0,              /* ...ON-DISCONNECT */
  1113.     "status",        0, 0,              /* ...STATUS */
  1114.     "warning",       1, 0               /* ...WARNING */
  1115. };
  1116. int nexit = (sizeof(xittab) / sizeof(struct keytab));
  1117.  
  1118. struct keytab xitwtab[] = {             /* SET EXIT WARNING */
  1119.     "always", 2, 0,                     /* even when not connected */
  1120.     "off",    0, 0,                     /* no warning     */
  1121.     "on",     1, 0                      /* when connected */
  1122. };
  1123. int nexitw = (sizeof(xitwtab) / sizeof(struct keytab));
  1124.  
  1125. struct keytab rltab[] = {
  1126.     "local",     1, 0,                  /* ECHO values */
  1127.     "off",       0, CM_INV,
  1128.     "on",        1, CM_INV,
  1129.     "remote",    0, 0
  1130. };
  1131. int nrlt = (sizeof(rltab) / sizeof(struct keytab));
  1132.  
  1133. /* Incomplete File Disposition table */
  1134.  
  1135. struct keytab ifdtab[] = {
  1136.     "discard", SET_OFF, 0,
  1137.     "keep",    SET_ON,  0
  1138. };
  1139.  
  1140. struct keytab ifdatab[] = {
  1141.     "auto",    SET_AUTO, 0,
  1142.     "discard", SET_OFF,  0,
  1143.     "keep",    SET_ON,   0
  1144. };
  1145.  
  1146. char * ifdnam[] = { "discard", "keep", "auto" };
  1147.  
  1148. /* SET TAKE parameters table */
  1149. static
  1150. struct keytab taktab[] = {
  1151.     "echo",  0, 0,
  1152.     "error", 1, 0,
  1153.     "off",   2, CM_INV,                 /* For compatibility */
  1154.     "on",    3, CM_INV                  /* with MS-DOS Kermit... */
  1155. };
  1156.  
  1157. #ifndef NOSPL
  1158. #ifdef COMMENT
  1159. /* not used */
  1160. static
  1161. struct keytab suftab[] = {              /* (what to do with) STARTUP-FILE */
  1162.     "delete", 1, 0,
  1163.     "keep",   0, 0
  1164. };
  1165. #endif /* COMMENT */
  1166.  
  1167. /* SET MACRO parameters table */
  1168. static
  1169. struct keytab smactab[] = {
  1170.     "echo",  0, 0,
  1171.     "error", 1, 0
  1172. };
  1173. #endif /* NOSPL */
  1174.  
  1175. #ifndef NOSCRIPT
  1176. static
  1177. struct keytab scrtab[] = {
  1178.     "echo",  0, 0
  1179. };
  1180. #endif /* NOSCRIPT */
  1181.  
  1182. /* SET COMMAND table */
  1183.  
  1184. /* SET COMMAND items... */
  1185.  
  1186. #define SCMD_BSZ 0    /* BYTESIZE */
  1187. #define SCMD_RCL 1    /* RECALL */
  1188. #define SCMD_RTR 2    /* RETRY */
  1189. #define SCMD_QUO 3    /* QUOTING */
  1190. #define SCMD_COL 4    /* COLOR */
  1191. #define SCMD_HIG 5    /* HEIGHT */
  1192. #define SCMD_WID 6    /* WIDTH */
  1193. #define SCMD_CUR 7    /* CURSOR-POSITION */
  1194. #define SCMD_SCR 8    /* SCROLLBACK */
  1195. #define SCMD_MOR 9    /* MORE-PROMPTING */
  1196. #define SCMD_INT 10     /* INTERRUPTION */
  1197. #define SCMD_ADL 11     /* AUTODOWNLOAD */
  1198. #define SCMD_STA 12     /* STATUSLINE */
  1199. #define SCMD_DBQ 13    /* DOUBLEQUOTING */
  1200. #define SCMD_CBR 14    /* CBREAK */
  1201. #define SCMD_BFL 15    /* BUFFER-SIZE (not used) */
  1202.  
  1203. static struct keytab scmdtab[] = {
  1204. #ifdef CK_AUTODL
  1205.     "autodownload",       SCMD_ADL, 0,
  1206. #endif /* CK_AUTODL */
  1207. #ifdef COMMENT
  1208. /*
  1209.   To implement this requires that we change CMDBL and ATMBL
  1210.   from compile-time symbols to runtime variables.  Not a big deal,
  1211.   but not trivial either.
  1212.  */
  1213.     "buffer-size",        SCMD_BFL, 0,
  1214. #endif /* COMMENT */
  1215.     "bytesize",           SCMD_BSZ, 0,
  1216.     "cbreak",             SCMD_CBR, CM_INV,
  1217. #ifdef OS2
  1218.     "color",              SCMD_COL, 0,
  1219.     "cursor-position",    SCMD_CUR, 0,
  1220. #endif /* OS2 */
  1221. #ifdef DOUBLEQUOTING
  1222.     "doublequoting",      SCMD_DBQ, 0,
  1223. #endif /* DOUBLEQUOTING */
  1224.     "height",             SCMD_HIG, 0,
  1225.     "interruption",       SCMD_INT, 0,
  1226.     "more-prompting",     SCMD_MOR, 0,
  1227.     "quoting",            SCMD_QUO, 0,
  1228. #ifdef CK_RECALL
  1229.     "recall-buffer-size", SCMD_RCL, 0,
  1230. #endif /* CK_RECALL */
  1231. #ifdef CK_RECALL
  1232.     "retry",              SCMD_RTR, 0,
  1233. #endif /* CK_RECALL */
  1234. #ifdef OS2
  1235. #ifdef ONETERMUPD
  1236.     "scrollback",         SCMD_SCR, 0,
  1237.     "statusline",         SCMD_STA, 0,
  1238. #endif /* ONETERMUPD */
  1239. #endif /* OS2 */
  1240.     "width",              SCMD_WID, 0
  1241. };
  1242. static int nbytt = (sizeof(scmdtab) / sizeof(struct keytab));
  1243.  
  1244. #ifndef NOSERVER
  1245. /* Server parameters table */
  1246. static struct keytab srvtab[] = {
  1247.     "cd-message",   XYSERC, 0,
  1248.     "display",      XYSERD, 0,
  1249.     "get-path",     XYSERP, 0,
  1250.     "idle-timeout", XYSERI, 0,
  1251.     "keepalive",    XYSERK, 0,
  1252.     "login",        XYSERL, 0,
  1253.     "timeout",      XYSERT, 0
  1254. };
  1255. static int nsrvt = (sizeof(srvtab) / sizeof(struct keytab));
  1256. #endif /* NOSERVER */
  1257.  
  1258. static struct keytab sleeptab[] = {     /* SET SLEEP table */
  1259.     "cancellation",  0,   0
  1260. };
  1261.  
  1262. static struct keytab tstab[] = {        /* SET TRANSFER/XFER table */
  1263.     "bell",            XYX_BEL, 0,
  1264. #ifdef XFRCAN
  1265.     "cancellation",    XYX_CAN, 0,
  1266. #endif /* XFRCAN */
  1267. #ifndef NOCSETS
  1268.     "character-set",   XYX_CSE, 0,
  1269. #endif /* NOCSETS */
  1270. #ifndef NOSPL
  1271.     "crc-calculation", XYX_CRC, 0,
  1272. #endif /* NOSPL */
  1273.     "display",         XYX_DIS, 0,
  1274.     "interruption",    XYX_INT, 0,
  1275.     "locking-shift",   XYX_LSH, 0,
  1276.     "message",         XYX_MSG, 0,
  1277.     "mode",            XYX_MOD, 0,
  1278.     "msg",             XYX_MSG, CM_INV,
  1279. #ifdef PIPESEND
  1280.     "pipes",           XYX_PIP, 0,
  1281. #endif /* PIPESEND */
  1282. #ifdef CK_XYZ
  1283.     "protocol",        XYX_PRO, 0,
  1284. #endif /* CK_XYZ */
  1285.     "report",          XYX_RPT, 0,
  1286.     "slow-start",      XYX_SLO, 0,
  1287. #ifndef NOCSETS
  1288.     "translation",     XYX_XLA, 0,
  1289. #else
  1290.     "translation",     XYX_XLA, CM_INV,
  1291. #endif /* NOCSETS */
  1292.     "xlation",         XYX_XLA, CM_INV,
  1293.     "", 0, 0
  1294. };
  1295. static int nts = (sizeof(tstab) / sizeof(struct keytab)) - 1;
  1296.  
  1297. static struct keytab rtstab[] = {       /* REMOTE SET TRANSFER/XFER table */
  1298. #ifndef NOCSETS
  1299.     "character-set",   XYX_CSE, 0,
  1300. #endif /* NOCSETS */
  1301.     "mode",            XYX_MOD, 0
  1302. };
  1303. static int nrts = (sizeof(rtstab) / sizeof(struct keytab));
  1304.  
  1305. struct keytab xfrmtab[] = {             /* TRANSFER MODE table */
  1306.     "automatic", XMODE_A, 0,
  1307.     "manual",    XMODE_M, 0
  1308. };
  1309.  
  1310. #ifdef LOCUS
  1311. extern int locus, autolocus;
  1312.  
  1313. static struct keytab locustab[] = {
  1314. #ifdef KUI
  1315.     { "ask",     3, 0 },        /* Presently implemented in GUI only */
  1316. #endif /* KUI */
  1317.     { "auto",    2, 0 },
  1318.     { "local",   1, 0 },
  1319.     { "remote",  0, 0 }
  1320. };
  1321. static int nlocustab = (sizeof(locustab) / sizeof(struct keytab));
  1322.  
  1323. #endif /* LOCUS */
  1324.  
  1325. #ifndef NOCSETS
  1326. /* SET TRANSFER CHARACTER-SET table */
  1327.  
  1328. extern struct keytab tcstab[];
  1329. extern int ntcs;
  1330. #endif /* NOCSETS */
  1331.  
  1332. /* SET TRANSFER LOCKING-SHIFT table */
  1333. struct keytab lstab[] = {
  1334.     "forced", 2,   0,
  1335.     "off",    0,   0,
  1336.     "on",     1,   0
  1337. };
  1338. int nls = (sizeof(lstab) / sizeof(struct keytab));
  1339.  
  1340. /* SET TELNET tables */
  1341. #ifdef TNCODE
  1342. extern int tn_nlm, tn_b_nlm, tn_b_meu, tn_b_ume, tn_b_xfer, tn_sb_bug;
  1343. extern int tn_no_encrypt_xfer, tn_auth_krb5_des_bug;
  1344. extern int tn_wait_flg, tn_duplex, tn_delay_sb, tn_sfu;
  1345. extern int sl_tn_saved;
  1346. extern int tn_infinite;
  1347. extern int tn_rem_echo;
  1348. extern int tn_deb;
  1349. extern int tn_auth_how;
  1350. extern int tn_auth_enc;
  1351. #ifdef CK_FORWARD_X
  1352. extern char * tn_fwdx_xauthority;
  1353. #endif /* CK_FORWARD_X */
  1354. #ifdef CK_AUTHENTICATION
  1355. static struct keytab setauth[] = {
  1356. #ifdef CK_KERBEROS
  1357.     "k4",        AUTH_KRB4, CM_INV,
  1358.     "k5",        AUTH_KRB5, CM_INV,
  1359.     "kerberos4", AUTH_KRB4, 0,
  1360.     "kerberos5", AUTH_KRB5, 0,
  1361.     "kerberos_iv",AUTH_KRB4, CM_INV,
  1362.     "kerberos_v", AUTH_KRB5, CM_INV,
  1363.     "krb4",      AUTH_KRB4, CM_INV,
  1364.     "krb5",      AUTH_KRB5, CM_INV,
  1365. #endif /* CK_KERBEROS */
  1366. #ifdef CK_SRP
  1367.     "srp",       AUTH_SRP,  0,
  1368. #endif /* CK_SRP */
  1369. #ifdef CK_SSL
  1370.     "ssl",      AUTH_SSL,   0,
  1371.     "tls",      AUTH_TLS,   0,
  1372. #endif /* CK_SSL */
  1373.     "",         0,      0
  1374. };
  1375. static int nsetauth = sizeof(setauth)/sizeof(struct keytab) - 1;
  1376. #ifdef CK_KERBEROS
  1377. extern char * krb5_d_principal;         /* Default principal */
  1378. extern char * krb5_d_instance;
  1379. extern char * krb5_d_realm;             /* Default realm */
  1380. extern char * krb5_d_cc;                /* Default credentials cache */
  1381. extern char * krb5_d_srv;               /* Default service name */
  1382. extern int    krb5_d_lifetime;          /* Default lifetime */
  1383. extern int    krb5_d_forwardable;
  1384. extern int    krb5_d_proxiable;
  1385. extern int    krb5_d_renewable;
  1386. extern int    krb5_autoget;
  1387. extern int    krb5_autodel;
  1388. extern int    krb5_d_getk4;
  1389. extern int    krb5_checkaddrs;          /* Check TGT Addrs */
  1390. extern int    krb5_d_no_addresses;
  1391. extern char * krb5_d_addrs[];
  1392. extern char * k5_keytab;                /* Keytab file */
  1393.  
  1394. extern struct krb4_init_data krb4_init;
  1395. extern char * krb4_d_principal;         /* Default principal */
  1396. extern char * krb4_d_realm;             /* Default realm */
  1397. extern char * krb4_d_srv;               /* Default service name */
  1398. extern int    krb4_d_lifetime;          /* Default lifetime */
  1399. extern int    krb4_d_preauth;
  1400. extern char * krb4_d_instance;
  1401. extern int    krb4_autoget;
  1402. extern int    krb4_autodel;
  1403. extern int    krb4_checkaddrs;          /* Check TGT Addrs */
  1404. extern char * k4_keytab;                /* Keytab file */
  1405. #ifdef KRB4
  1406. extern int    k4debug;
  1407. #endif /* KRB4 */
  1408. static struct keytab krbver[] = {
  1409.     "4",                 4, 0,
  1410.     "5",                 5, 0,
  1411.     "iv",                4, CM_INV,
  1412.     "v",                 5, CM_INV
  1413. };
  1414. static int nkrbver = sizeof(krbver)/sizeof(struct keytab);
  1415.  
  1416. static struct keytab kdestab[] = {
  1417.     "never",            KRB_DEL_NO, 0,
  1418.     "no",               KRB_DEL_NO, CM_INV,
  1419.     "on-close",         KRB_DEL_CL, 0,
  1420.     "on-exit",          KRB_DEL_EX, 0
  1421. };
  1422. static int nkdestab = sizeof(kdestab)/sizeof(struct keytab);
  1423.  
  1424. static struct keytab k4tab[] = {
  1425.     "autodel",           XYKRBDEL, CM_INV,
  1426.     "autodestroy",       XYKRBDEL, 0,
  1427.     "autoget",           XYKRBGET, 0,
  1428.     "check-address",     XYKRBADR, 0,
  1429.     "debug",             XYKRBDBG, CM_INV,
  1430.     "instance",          XYKRBINS, 0,
  1431.     "keytab",            XYKRBKTB, 0,
  1432.     "lifetime",          XYKRBLIF, 0,
  1433.     "preauth",           XYKRBPRE, 0,
  1434.     "principal",         XYKRBPR,  0,
  1435.     "prompt",            XYKRBPRM, 0,
  1436.     "realm",             XYKRBRL,  0,
  1437.     "service-name",      XYKRBSRV, 0
  1438. };
  1439. static int nk4tab = sizeof(k4tab)/sizeof(struct keytab);
  1440.  
  1441. static struct keytab k5tab[] = {
  1442.     "addresses",         XYKRBADD, 0,
  1443.     "autodelete",        XYKRBDEL, CM_INV,
  1444.     "autodestroy",       XYKRBDEL, 0,
  1445.     "autoget",           XYKRBGET, 0,
  1446.     "cc",                XYKRBCC,  CM_INV,
  1447.     "check-address",     XYKRBADR, 0,
  1448.     "credentials-cache", XYKRBCC,  0,
  1449.     "forwardable",       XYKRBFWD, 0,
  1450.     "get-k4-tgt",        XYKRBK5K4,0,
  1451.     "instance",          XYKRBINS, 0,
  1452.     "keytab",            XYKRBKTB, 0,
  1453.     "lifetime",          XYKRBLIF, 0,
  1454.     "no-addresses",      XYKRBNAD, 0,
  1455.     "principal",         XYKRBPR,  0,
  1456.     "prompt",            XYKRBPRM, 0,
  1457.     "proxiable",         XYKRBPRX, 0,
  1458.     "realm",             XYKRBRL,  0,
  1459.     "renewable",         XYKRBRNW, 0,
  1460.     "service-name",      XYKRBSRV, 0
  1461. };
  1462. static int nk5tab = sizeof(k5tab)/sizeof(struct keytab);
  1463.  
  1464. #define KRB_PW_PRM 1
  1465. #define KRB_PR_PRM 2
  1466.  
  1467. static struct keytab krbprmtab[] = {
  1468.     "password",  KRB_PW_PRM, 0,
  1469.     "principal", KRB_PR_PRM, 0
  1470. };
  1471.  
  1472. #endif /* CK_KERBEROS */
  1473. #ifdef CK_SRP
  1474. static struct keytab srptab[] = {
  1475.     "prompt",            XYSRPPRM, 0
  1476. };
  1477. static int nsrptab = sizeof(srptab)/sizeof(struct keytab);
  1478. #define SRP_PW_PRM 1
  1479.  
  1480. static struct keytab srpprmtab[] = {
  1481.     "password",  SRP_PW_PRM, 0
  1482. };
  1483. #endif /* CK_SRP */
  1484. #ifdef CK_SSL
  1485. static struct keytab ssltab[] = {
  1486.     "certs-ok",          XYSSLCOK,  CM_INV,
  1487.     "cipher-list",       XYSSLCL,   0,
  1488.     "crl-dir",           XYSSLCRLD, 0,
  1489.     "crl-file",          XYSSLCRL,  0,
  1490.     "debug",             XYSSLDBG,  0,
  1491.     "dh-key-file",       XYSSLDKFL, CM_INV,
  1492.     "dh-param-file",     XYSSLDPFL, 0,
  1493.     "dsa-cert-chain-file", XYSSLDCCF, 0,
  1494.     "dsa-cert-file",     XYSSLDCFL, 0,
  1495.     "dsa-key-file",      XYSSLDKFL, 0,
  1496.     "dummy",             XYSSLDUM,  CM_INV,
  1497.     "only",              XYSSLON,   CM_INV,
  1498.     "random-file",       XYSSLRND,  0,
  1499.     "rsa-cert-chain-file", XYSSLRCCF, 0,
  1500.     "rsa-cert-file",     XYSSLRCFL, 0,
  1501.     "rsa-key-file",      XYSSLRKFL, 0,
  1502.     "verbose",           XYSSLVRB,  0,
  1503.     "verify",            XYSSLVRF,  0,
  1504.     "verify-dir",        XYSSLVRFD, 0,
  1505.     "verify-file",       XYSSLVRFF, 0
  1506. };
  1507. static int nssltab = sizeof(ssltab)/sizeof(struct keytab);
  1508. static struct keytab sslvertab[] = {
  1509.     "fail-if-no-peer-cert", SSL_VERIFY_PEER |
  1510.                             SSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0,
  1511.     "no",               SSL_VERIFY_NONE, 0,
  1512.     "none",             SSL_VERIFY_NONE, CM_INV,
  1513.     "off",              SSL_VERIFY_NONE, CM_INV,
  1514.     "on",               SSL_VERIFY_PEER, CM_INV,
  1515.     "peer-cert",        SSL_VERIFY_PEER, 0
  1516. };
  1517. static int nsslvertab = sizeof(sslvertab)/sizeof(struct keytab);
  1518. #endif /* CK_SSL */
  1519. #endif /* CK_AUTHENTICATION */
  1520. #ifdef CK_ENCRYPTION
  1521. int cx_type = CX_AUTO;
  1522. extern int sl_cx_type;
  1523. #endif /* CK_ENCRYPTION */
  1524. extern char *tcp_address;
  1525. #ifndef NOHTTP
  1526. extern char * tcp_http_proxy;
  1527. extern char * tcp_http_proxy_user;
  1528. extern char * tcp_http_proxy_pwd;
  1529. extern char * tcp_http_proxy_agent;
  1530. #endif /* NOHTTP */
  1531. #ifdef NT
  1532. #ifdef CK_SOCKS
  1533. extern char *tcp_socks_svr;
  1534. extern char *tcp_socks_user;
  1535. #ifdef CK_SOCKS_NS
  1536. extern char *tcp_socks_ns;
  1537. #endif /* CK_SOCKS_NS */
  1538. #endif /* CK_SOCKS */
  1539. #endif /* NT */
  1540.  
  1541. #define UPW_USER  1
  1542. #define UPW_PASS  2
  1543. #define UPW_AGENT 3
  1544.  
  1545. static struct keytab userpass[] = {
  1546.     { "/agent",   UPW_AGENT, CM_ARG },
  1547.     { "/password", UPW_PASS, CM_ARG },
  1548.     { "/user",     UPW_USER, CM_ARG },
  1549. };
  1550. static int nuserpass = sizeof(userpass)/sizeof(struct keytab);
  1551.  
  1552. static struct keytab tnnegtab[] = {     /* TELNET NEGOTIATION table */
  1553.     "accepted",  TN_NG_AC, 0,
  1554.     "refused",   TN_NG_RF, 0,
  1555.     "req",       TN_NG_RQ, CM_INV|CM_ABR,
  1556.     "requ",      TN_NG_RQ, CM_INV|CM_ABR,
  1557.     "reque",     TN_NG_RQ, CM_INV|CM_ABR,
  1558.     "reques",    TN_NG_RQ, CM_INV|CM_ABR,
  1559.     "request",   TN_NG_RQ, CM_INV|CM_ABR,
  1560.     "requeste",  TN_NG_RQ, CM_INV|CM_ABR,
  1561.     "requested", TN_NG_RQ, 0,
  1562.     "required",  TN_NG_MU, 0
  1563. };
  1564. static int ntnnegtab = sizeof(tnnegtab)/sizeof(struct keytab);
  1565.  
  1566. #ifdef CK_ENCRYPTION
  1567. static struct keytab typkwd[] = {
  1568.     "/type", 0, CM_ARG
  1569. };
  1570.  
  1571. static struct keytab tnenctab[] = {     /* TELNET ENCRYPTION table */
  1572.     "accepted",   TN_NG_AC,    CM_INV,
  1573.     "refused",    TN_NG_RF,    CM_INV,
  1574.     "req",        TN_NG_RQ,    CM_INV|CM_ABR,
  1575.     "requ",       TN_NG_RQ,    CM_INV|CM_ABR,
  1576.     "reque",      TN_NG_RQ,    CM_INV|CM_ABR,
  1577.     "reques",     TN_NG_RQ,    CM_INV|CM_ABR,
  1578.     "request",    TN_NG_RQ,    CM_INV|CM_ABR,
  1579.     "requeste",   TN_NG_RQ,    CM_INV|CM_ABR,
  1580.     "requested",  TN_NG_RQ,    CM_INV,
  1581.     "required",   TN_NG_MU,    CM_INV,
  1582.     "start",      TN_EN_START, CM_INV,
  1583.     "stop",       TN_EN_STOP,  CM_INV,
  1584.     "type",       TN_EN_TYP,   0
  1585. };
  1586. static int ntnenc = sizeof(tnenctab)/sizeof(struct keytab) ;
  1587. #endif /* CK_ENCRYPTION */
  1588.  
  1589. #ifdef CK_FORWARD_X
  1590. static struct keytab tnfwdxtab[] = {    /* TELNET FORWARD-X table */
  1591.     "no-encryption",    1,  CM_INV,
  1592.     "xauthority-file",  0,  0
  1593. };
  1594. static int ntnfwdx = sizeof(tnfwdxtab)/sizeof(struct keytab) ;
  1595. #endif /* CK_FORWARD_X */
  1596.  
  1597. static struct keytab tnbugtab[] = {     /* TELNET BUG table */
  1598.     "auth-krb5-des",         4, 0,
  1599.     "binary-me-means-u-too", 0, 0,
  1600.     "binary-u-means-me-too", 1, 0,
  1601.     "infinite-loop-check",   2, 0,
  1602.     "sb-implies-will-do",    3, 0
  1603. };
  1604.  
  1605. #ifdef CK_ENVIRONMENT
  1606. static struct keytab tnenvtab[] = {     /* TELNET ENVIRONMENT table */
  1607.     "acct",     TN_ENV_ACCT,    0,
  1608.     "display",  TN_ENV_DISP,    0,
  1609.     "job",      TN_ENV_JOB,     0,
  1610.     "location", TN_ENV_LOC,     0,
  1611.     "off",      TN_ENV_OFF,     CM_INV,
  1612.     "on",       TN_ENV_ON,      CM_INV,
  1613.     "printer",  TN_ENV_PRNT,    0,
  1614.     "systemtype",TN_ENV_SYS,    0,
  1615.     "user",     TN_ENV_USR,     0,
  1616.     "uservar",  TN_ENV_UVAR,    0,
  1617.     "", 0, 0
  1618. };
  1619. static int ntnenv = sizeof(tnenvtab)/sizeof(struct keytab) - 1;
  1620. #endif /* CK_ENVIRONMENT */
  1621.  
  1622. #ifdef CK_AUTHENTICATION
  1623. static struct keytab tnauthtab[] = {    /* TELNET AUTHENTICATION table */
  1624.     "accepted",   TN_NG_AC,  CM_INV,
  1625.     "encrypt-flag", TN_AU_ENC, 0,
  1626.     "forwarding", TN_AU_FWD,   0,
  1627.     "how-flag",   TN_AU_HOW,   0,
  1628.     "refused",    TN_NG_RF,  CM_INV,
  1629.     "req",        TN_NG_RQ,  CM_INV|CM_ABR,
  1630.     "requ",       TN_NG_RQ,  CM_INV|CM_ABR,
  1631.     "reque",      TN_NG_RQ,  CM_INV|CM_ABR,
  1632.     "reques",     TN_NG_RQ,  CM_INV|CM_ABR,
  1633.     "request",    TN_NG_RQ,  CM_INV|CM_ABR,
  1634.     "requeste",   TN_NG_RQ,  CM_INV|CM_ABR,
  1635.     "requested",  TN_NG_RQ,  CM_INV,
  1636.     "required",   TN_NG_MU,  CM_INV,
  1637.     "type",       TN_AU_TYP, 0
  1638. };
  1639. static int ntnauth = sizeof(tnauthtab)/sizeof(struct keytab) ;
  1640.  
  1641. struct keytab autyptab[] = {    /* TELNET AUTHENTICATION TYPE table */
  1642.     "automatic",  AUTH_AUTO, 0,
  1643. #ifdef CK_KERBEROS
  1644.     "k4",         AUTH_KRB4, CM_INV,
  1645.     "k5",         AUTH_KRB5, CM_INV,
  1646.     "kerberos4",  AUTH_KRB4, 0,
  1647.     "kerberos5",  AUTH_KRB5, 0,
  1648.     "kerberos_iv",AUTH_KRB4, CM_INV,
  1649.     "kerberos_v", AUTH_KRB5, CM_INV,
  1650.     "krb4",       AUTH_KRB4, CM_INV,
  1651.     "krb5",       AUTH_KRB5, CM_INV,
  1652. #endif /* CK_KERBEROS */
  1653.     "none",       AUTH_NONE, 0,
  1654. #ifdef NT
  1655.     "ntlm",       AUTH_NTLM, 0,
  1656. #endif /* NT */
  1657. #ifdef CK_SRP
  1658.     "srp",        AUTH_SRP,  0,
  1659. #endif /* CK_SRP */
  1660. #ifdef CK_SSL
  1661.     "ssl",        AUTH_SSL,  0,
  1662. #endif /* CK_SSL */
  1663.     "", 0, 0
  1664. };
  1665. int nautyp = sizeof(autyptab)/sizeof(struct keytab) - 1;
  1666.  
  1667. struct keytab auhowtab[] = {    /* TELNET AUTHENTICATION HOW table */
  1668.     "any",     TN_AUTH_HOW_ANY,     0,
  1669.     "mutual",  TN_AUTH_HOW_MUTUAL,  0,
  1670.     "one-way", TN_AUTH_HOW_ONE_WAY, 0,
  1671.     "", 0, 0
  1672. };
  1673. int nauhow = sizeof(auhowtab)/sizeof(struct keytab) - 1;
  1674.  
  1675. struct keytab auenctab[] = {    /* TELNET AUTHENTICATION ENCRYPT table */
  1676.     "any",     TN_AUTH_ENC_ANY,     0,
  1677.     "none",    TN_AUTH_ENC_NONE,    0,
  1678.     "telopt",  TN_AUTH_ENC_TELOPT,  0,
  1679. #ifdef CK_SSL
  1680.     "tls",     TN_AUTH_ENC_TLS,     0,
  1681. #endif /* CK_SSL */
  1682.     "", 0, 0
  1683. };
  1684. int nauenc = sizeof(auenctab)/sizeof(struct keytab) - 1;
  1685. #endif /* CK_AUTHENTICATION */
  1686.  
  1687. #define TN_NL_BIN 3
  1688. #define TN_NL_NVT 4
  1689. static struct keytab tn_nlmtab[] = {    /* TELNET NEWLINE-MODE table */
  1690.     "binary-mode", TN_NL_BIN, 0,        /* Binary mode */
  1691.     "nvt",    TN_NL_NVT, 0,             /* NVT mode */
  1692.     "off",    TNL_CRNUL, CM_INV,        /* CR-NUL (TELNET spec) */
  1693.     "on",     TNL_CRLF,  CM_INV,        /* CR-LF (TELNET spec) */
  1694.     "raw",    TNL_CR,    CM_INV         /* CR only (out of spec) */
  1695. };
  1696. static int ntn_nlm = (sizeof(tn_nlmtab) / sizeof(struct keytab));
  1697.  
  1698. static struct keytab tnlmtab[] = {      /* TELNET NEWLINE-MODE table */
  1699.     "cr",     TNL_CR,    CM_INV,        /* CR only (out of spec) */
  1700.     "cr-lf",  TNL_CRLF,  CM_INV,        /* CR-LF (TELNET spec) */
  1701.     "cr-nul", TNL_CRNUL, CM_INV,        /* CR-NUL (TELNET spec) */
  1702.     "lf",     TNL_LF,    CM_INV,        /* LF instead of CR-LF */
  1703.     "off",    TNL_CRNUL, 0,             /* CR-NUL (TELNET spec) */
  1704.     "on",     TNL_CRLF,  0,             /* CR-LF (TELNET spec) */
  1705.     "raw",    TNL_CR,    0              /* CR only (out of spec) */
  1706. };
  1707. static int ntnlm = (sizeof(tnlmtab) / sizeof(struct keytab));
  1708.  
  1709. struct keytab tntab[] = {
  1710. #ifdef CK_AUTHENTICATION
  1711.     "authentication",       CK_TN_AU,  0,
  1712. #endif /* CK_AUTHENTICATION */
  1713.     "b",                    CK_TN_BM,  CM_INV|CM_ABR,
  1714.     "bi",                   CK_TN_BM,  CM_INV|CM_ABR,
  1715.     "bin",                  CK_TN_BM,  CM_INV|CM_ABR,
  1716.     "bina",                 CK_TN_BM,  CM_INV|CM_ABR,
  1717.     "binar",                CK_TN_BM,  CM_INV|CM_ABR,
  1718.     "binary",               CK_TN_BM,  CM_INV|CM_ABR,
  1719.     "binary-",              CK_TN_BM,  CM_INV|CM_ABR,
  1720.     "binary-mode",          CK_TN_BM,  CM_INV,
  1721.     "binary-transfer-mode", CK_TN_XF,  0,
  1722.     "binary-xfer-mode",     CK_TN_XF,  CM_INV,
  1723.     "bug",                  CK_TN_BUG, 0,
  1724.     "debug",                CK_TN_DB,  0,
  1725.     "delay-sb",             CK_TN_DL,  0,
  1726.     "echo",                 CK_TN_EC,  0,
  1727. #ifdef CK_ENCRYPTION
  1728.     "encryption",      CK_TN_ENC,  0,
  1729. #endif /* CK_ENCRYPTION */
  1730. #ifdef CK_ENVIRONMENT
  1731.     "environment",     CK_TN_ENV,  0,
  1732. #endif /* CK_ENVIRONMENT */
  1733. #ifdef CK_FORWARD_X
  1734.     "forward-x",       CK_TN_FX,   0,
  1735. #endif /* CK_FORWARD_X */
  1736. #ifdef IKS_OPTION
  1737.     "kermit",          CK_TN_IKS,  CM_INV,
  1738. #endif /* IKS_OPTION */
  1739. #ifdef CK_SNDLOC
  1740.     "location",        CK_TN_LOC,  0,
  1741. #endif /* CK_SNDLOC */
  1742. #ifdef CK_NAWS
  1743.     "naws",            CK_TN_NAWS, CM_INV,
  1744. #endif /* CK_NAWS */
  1745.     "newline-mode",    CK_TN_NL,   0,
  1746.     "no-encrypt-during-xfer", CK_TN_NE, CM_INV,
  1747.     "prompt-for-userid",CK_TN_PUID,0,
  1748.     "remote-echo",     CK_TN_RE,   0,
  1749. #ifdef CK_SSL
  1750.     "start-tls",       CK_TN_TLS,  CM_INV,
  1751. #endif /* CK_SSL */
  1752. #ifdef NT
  1753.     "sfu-compatibility", CK_TN_SFU, 0,
  1754. #else
  1755.     "sfu-compatibility", CK_TN_SFU, CM_INV,
  1756. #endif /* NT */
  1757.     "terminal-type",   CK_TN_TT,   0,
  1758.     "wait-for-negotiations", CK_TN_WAIT, 0,
  1759. #ifdef CK_ENVIRONMENT
  1760.     "xdisplay-location",CK_TN_XD, CM_INV,
  1761. #endif /* CK_ENVIRONMENT */
  1762.     "", 0, 0
  1763. };
  1764. int ntn = (sizeof(tntab) / sizeof(struct keytab)) - 1;
  1765.  
  1766. struct keytab tnopttab[] = {
  1767. #ifdef CK_AUTHENTICATION
  1768.     "authentication",  CK_TN_AU,   0,
  1769. #else
  1770.     "authentication",  CK_TN_AU,   CM_INV,
  1771. #endif /* CK_AUTHENTICATION */
  1772.     "binary-mode",     CK_TN_BM,   0,
  1773. #ifdef TN_COMPORT
  1774.     "c",               CK_TN_CPC,   CM_INV|CM_ABR,
  1775.     "co",              CK_TN_CPC,   CM_INV|CM_ABR,
  1776.     "com",             CK_TN_CPC,   CM_INV|CM_ABR,
  1777.     "com-port-control",CK_TN_CPC,   0,
  1778.     "comport-control", CK_TN_CPC,   CM_INV,
  1779. #else /* TN_COMPORT */
  1780.     "com-port-control",CK_TN_CPC,  CM_INV,
  1781.     "comport-control", CK_TN_CPC,   CM_INV,
  1782. #endif /* TN_COMPORT */
  1783.     "echo",            CK_TN_EC,   0,
  1784. #ifdef CK_ENCRYPTION
  1785.     "encryption",      CK_TN_ENC,  0,
  1786. #else
  1787.     "encryption",      CK_TN_ENC,  CM_INV,
  1788. #endif /* CK_ENCRYPTION */
  1789. #ifdef CK_FORWARD_X
  1790.     "forward-x",       CK_TN_FX,   0,
  1791. #else /* CK_FORWARD_X */
  1792.     "forward-x",       CK_TN_FX,   CM_INV,
  1793. #endif /* CK_FORWARD_X */
  1794.     "ibm-sak",         CK_TN_SAK,  CM_INV,
  1795. #ifdef IKS_OPTION
  1796.     "kermit",          CK_TN_IKS,  0,
  1797. #else
  1798.     "kermit",          CK_TN_IKS,  CM_INV,
  1799. #endif /* IKS_OPTION */
  1800.     "lflow",           CK_TN_FLW,  CM_INV,
  1801.     "logout",          CK_TN_LOG,  0,
  1802. #ifdef CK_NAWS
  1803.     "naws",            CK_TN_NAWS, 0,
  1804. #else
  1805.     "naws",            CK_TN_NAWS, CM_INV,
  1806. #endif /* CK_NAWS */
  1807. #ifdef CK_ENVIRONMENT
  1808.     "new-environment", CK_TN_ENV,  0,
  1809. #else
  1810.     "new-environment", CK_TN_ENV,  CM_INV,
  1811. #endif /* CK_ENVIRONMENT */
  1812.     "pragma-heartbeat",CK_TN_PHR,  CM_INV,
  1813.     "pragma-logon",    CK_TN_PLG,  CM_INV,
  1814.     "pragma-sspi",     CK_TN_PSP,  CM_INV,
  1815.     "sak",             CK_TN_SAK,  CM_INV,
  1816. #ifdef CK_SNDLOC
  1817.     "send-location",   CK_TN_LOC,  0,
  1818. #else
  1819.     "send-location",   CK_TN_LOC,  CM_INV,
  1820. #endif /* CK_SNDLOC */
  1821.     "sga",             CK_TN_SGA, CM_INV|CM_ABR,
  1822. #ifdef CK_SSL
  1823.     "start-tls",       CK_TN_TLS,  0,
  1824. #else
  1825.     "start-tls",       CK_TN_TLS,  CM_INV,
  1826. #endif /* CK_SSL */
  1827.     "suppress-go-aheads", CK_TN_SGA, 0,
  1828.     "terminal-type",   CK_TN_TT,   0,
  1829.     "ttype",           CK_TN_TT,   CM_INV|CM_ABR,
  1830. #ifdef CK_ENVIRONMENT
  1831.     "xdisplay-location", CK_TN_XD, 0,
  1832. #else
  1833.     "xdisplay-location", CK_TN_XD, CM_INV,
  1834. #endif /* CK_ENVIRONMENT */
  1835.     "", 0, 0
  1836. };
  1837. int ntnopt = (sizeof(tnopttab) / sizeof(struct keytab)) - 1;
  1838.  
  1839. struct keytab tnoptsw[] = {
  1840.     "/client",  CK_TN_CLIENT,   0,
  1841.     "/server",  CK_TN_SERVER,   0
  1842. };
  1843. int ntnoptsw = (sizeof(tnoptsw) / sizeof(struct keytab));
  1844. #endif /* TNCODE */
  1845.  
  1846. struct keytab ftrtab[] = {              /* Feature table */
  1847. #ifndef NOCSETS                         /* 0 = we have it, 1 = we don't */
  1848. "character-sets",       0, 0,
  1849. #else
  1850. "character-sets",       1, 0,
  1851. #endif /* NOCSETS */
  1852. #ifndef NOCYRIL
  1853. "cyrillic",             0, 0,
  1854. #else
  1855. "cyrillic",             1, 0,
  1856. #endif /* NOCYRIL */
  1857.  
  1858. #ifndef NOLOGDIAL
  1859. "cx-log",               0, 0,
  1860. #else
  1861. "cx-log",               1, 0,
  1862. #endif /* NOLOGDIAL */
  1863.  
  1864. #ifndef NODEBUG
  1865. "debug",                0, 0,
  1866. #else
  1867. "debug",                1, 0,
  1868. #endif /* NODEBUG */
  1869.  
  1870. #ifndef NODIAL
  1871. "dial",                 0, 0,
  1872. #else
  1873. "dial",                 1, 0,
  1874. #endif /* NODIAL */
  1875.  
  1876. #ifdef DYNAMIC
  1877. "dynamic-memory",       0, 0,
  1878. #else
  1879. "dynamic-memory",       1, 0,
  1880. #endif /* DYNAMIC */
  1881.  
  1882. #ifndef NOXFER
  1883. "file-transfer",        0, 0,
  1884. #else
  1885. "file-transfer",        1, 0,
  1886. #endif /* NOXFER */
  1887.  
  1888. #ifdef XXFWD
  1889. "forward",              0, 0,
  1890. #else
  1891. "forward",              1, 0,
  1892. #endif /* XXFWD */
  1893.  
  1894. #ifdef NEWFTP
  1895. "ftp",                  0, 0,
  1896. #else
  1897. "ftp",                  1, 0,
  1898. #endif /* NEWFTP */
  1899.  
  1900. #ifdef CK_CURSES
  1901. "fullscreen-display",   0, 0,
  1902. #else
  1903. "fullscreen-display",   1, 0,
  1904. #endif /* CK_CURSES */
  1905. #ifdef GREEK
  1906. "greek",                0, 0,
  1907. #else
  1908. "greek",                1, 0,
  1909. #endif /* GREEK */
  1910. #ifdef HEBREW
  1911. "hebrew",               0, 0,
  1912. #else
  1913. "hebrew",               1, 0,
  1914. #endif /* HEBREW */
  1915. #ifndef NOHELP
  1916. "help",                 0, 0,
  1917. #else
  1918. "help",                 1, 0,
  1919. #endif /* NOHELP */
  1920.  
  1921. #ifndef NOIKSD
  1922. "iksd",                 0, 0,
  1923. #else
  1924. "iksd",                 1, 0,
  1925. #endif /* NOIKSD */
  1926.  
  1927. #ifndef NOSPL
  1928. "if-command",           0, 0,
  1929. #else
  1930. "if-command",           1, 0,
  1931. #endif /* NOSPL */
  1932. #ifndef NOJC
  1933. #ifdef UNIX
  1934. "job-control",          0, 0,
  1935. #else
  1936. "job-control",          1, 0,
  1937. #endif /* UNIX */
  1938. #else
  1939. "job-control",          1, 0,
  1940. #endif /* NOJC */
  1941. #ifdef KANJI
  1942. "kanji",                0, 0,
  1943. #else
  1944. "kanji",                1, 0,
  1945. #endif /* KANJI */
  1946.  
  1947. #ifndef NOXFER
  1948. "kermit",               0, 0,
  1949. #else
  1950. "kermit",               1, 0,
  1951. #endif /* NOXFER */
  1952.  
  1953. #ifdef CK_KERBEROS
  1954. "kerberos",             0, 0,
  1955. #else
  1956. "kerberos",             1, 0,
  1957. #endif /* CK_KERBEROS */
  1958.  
  1959. #ifndef NOCSETS
  1960. "latin1",               0, 0,
  1961. #else
  1962. "latin1",               1, 0,
  1963. #endif /* NOCSETS */
  1964. #ifdef LATIN2
  1965. "latin2",               0, 0,
  1966. #else
  1967. "latin2",               1, 0,
  1968. #endif /* LATIN2 */
  1969.  
  1970. #ifdef CKLEARN
  1971. "learned-scripts",       0, 0,
  1972. #else
  1973. "learned-scripts",       1, 0,
  1974. #endif /* CKLEARN */
  1975.  
  1976. #ifndef NOLOCAL
  1977. "making-connections",   0, 0,
  1978. #else
  1979. "making-connections",   1, 0,
  1980. #endif /* NOLOCAL */
  1981.  
  1982. #ifdef NETCONN
  1983. "network",              0, 0,
  1984. #else
  1985. "network",              1, 0,
  1986. #endif /* NETCONN */
  1987.  
  1988. #ifdef NT
  1989. #ifdef CK_AUTHENTICATION
  1990. "ntlm",                 1, 0,
  1991. #else /* CK_AUTHENTICATION */
  1992. "ntlm",                 0, 0,
  1993. #endif /* CK_AUTHENTICATION */
  1994. #else /* NT */
  1995. "ntlm",                 0, 0,
  1996. #endif /* NT */
  1997.  
  1998. #ifdef PIPESEND
  1999. "pipes",                0, 0,
  2000. #else
  2001. #ifdef NETCMD
  2002. "pipes",                0, 0,
  2003. #endif /* NETCMD */
  2004. #endif /* PIPESEND */
  2005. #ifndef PIPESEND
  2006. #ifndef NETCMD
  2007. "pipes",                1, 0,
  2008. #endif /* PIPESEND */
  2009. #endif /* NETCMD */
  2010.  
  2011. #ifdef NETPTY
  2012. "pty",                  0, 0,
  2013. #else
  2014. "pty",                  1, 0,
  2015. #endif /* NETPTY */
  2016.  
  2017. #ifndef NOPUSH
  2018. "push",                 0, 0,
  2019. #else
  2020. "push",                 1, 0,
  2021. #endif /* PUSH */
  2022.  
  2023. #ifdef CK_REDIR
  2024. "redirect",             0, 0,
  2025. #else
  2026. "redirect",             1, 0,
  2027. #endif /* CK_REDIR */
  2028.  
  2029. #ifdef CK_RTSCTS
  2030. "rts/cts",              0, 0,
  2031. #else
  2032. "rts/cts",              1, 0,
  2033. #endif /* RTS/CTS */
  2034.  
  2035. #ifndef NOSCRIPT
  2036. "script-command",       0, 0,
  2037. #else
  2038. "script-command",       1, 0,
  2039. #endif /* NOSCRIPT */
  2040. #ifndef NOSERVER
  2041. "server-mode",          0, 0,
  2042. #else
  2043. "server-mode",          1, 0,
  2044. #endif /* NOSERVER */
  2045.  
  2046. #ifndef NOSEXP
  2047. "sexpression",          0, 0,
  2048. #else
  2049. "sexpression",          1, 0,
  2050. #endif /* NOSEXP */
  2051.  
  2052. #ifdef SFTP_BUILTIN
  2053. "sftp",                 1, 0,
  2054. #else
  2055. "sftp",                 0, 0,
  2056. #endif /* SFTP_BUILTIN */
  2057.  
  2058. #ifndef NOSHOW
  2059. "show-command",         0, 0,
  2060. #else
  2061. "show-command",         1, 0,
  2062. #endif /* NOSHOW */
  2063.  
  2064. #ifdef CK_SRP
  2065. "srp",                  0, 0,
  2066. #else
  2067. "srp",                  1, 0,
  2068. #endif /* CK_SRP */
  2069.  
  2070. #ifdef SSHBUILTIN
  2071. "ssh",                  0, 0,
  2072. #else /* SSHBUILTIN */
  2073. "ssh",                  1, 0,
  2074. #endif /* SSHBUILTIN */
  2075.  
  2076. #ifdef CK_SSL
  2077. "ssl/tls",              0, 0,
  2078. #else
  2079. "ssl/tls",              1, 0,
  2080. #endif /* CK_SSL */
  2081.  
  2082. #ifndef NOXMIT
  2083. "transmit",             0, 0,
  2084. #else
  2085. "transmit",             1, 0,
  2086. #endif /* NOXMIT */
  2087.  
  2088. #ifdef UNICODE
  2089. "unicode",              0, 0,
  2090. #else
  2091. "unicode",              1, 0,
  2092. #endif /* UNICODE */
  2093.  
  2094. #ifdef CK_XYZ
  2095. "xyzmodem",             0, 0,
  2096. #else
  2097. "xyzmodem",             1, 0,
  2098. #endif /* NOXMIT */
  2099.  
  2100. "", 0, 0
  2101. };
  2102. int nftr = (sizeof(ftrtab) / sizeof(struct keytab)) - 1;
  2103.  
  2104. struct keytab desttab[] = {             /* SET DESTINATION */
  2105. #ifdef CALIBRATE
  2106.     "calibrate", DEST_N, CM_INV,
  2107. #endif /* CALIBRATE */
  2108.     "disk",    DEST_D, 0,
  2109. #ifdef CALIBRATE
  2110.     "nowhere", DEST_N, 0,
  2111. #endif /* CALIBRATE */
  2112.     "printer", DEST_P, 0,
  2113.     "screen",  DEST_S, 0
  2114. };
  2115. int ndests =  (sizeof(desttab) / sizeof(struct keytab));
  2116.  
  2117. #ifndef NOSPL           /* Used only with script programming items... */
  2118.  
  2119. #ifndef NOSERVER                        /* This is just to avoid some */
  2120. #define CK_PARSDIR                      /* "statement not reached" */
  2121. #else                                   /* complaints... */
  2122. #ifndef NODIAL
  2123. #define CK_PARSDIR
  2124. #endif /* NODIAL */
  2125. #endif /* NOSERVER */
  2126.  
  2127. /*
  2128.   cx == 0 means dial directory
  2129.   cx == 1 means network directory
  2130.   cx == 2 means a directory path list
  2131. */
  2132. static int
  2133. parsdir(cx) int cx; {
  2134.     int i, x, y, dd;                    /* Workers */
  2135.     int nxdir;
  2136.     char *s;
  2137.     char ** xdir;
  2138.     char *pp[MAXGETPATH];               /* Temporary name pointers */
  2139. #ifdef ZFNQFP
  2140.     struct zfnfp * fnp;
  2141. #ifdef OS2
  2142.     char * env;
  2143.     char dirpath[4096];
  2144. #else /* OS2 */
  2145.     char dirpath[1024];                 /* For fully qualified filenames */
  2146. #endif /* OS2 */
  2147. #endif /* ZFNQFP */
  2148.  
  2149.     int max = 0;                        /* Maximum number of things to parse */
  2150.     char c;
  2151.  
  2152. #ifndef NODIAL
  2153.     if (cx == 0) {                      /* Dialing */
  2154.         nxdir = ndialdir;
  2155.         xdir = dialdir;
  2156.         max = MAXDDIR;
  2157.     } else
  2158. #ifdef NETCONN
  2159.     if (cx == 1) {                      /* Network */
  2160.         nxdir = nnetdir;
  2161.         xdir = netdir;
  2162.         max = MAXDDIR;
  2163.     } else
  2164. #endif /* NETCONN */
  2165. #endif /* NODIAL */
  2166. #ifndef NOSERVER
  2167.     if (cx == 2) {                      /* GET path */
  2168.         nxdir = ngetpath;
  2169.         xdir = getpath;
  2170.         max = MAXGETPATH;
  2171.     } else                              /* Called with invalid function code */
  2172. #endif /* NOSERVER */
  2173.       return(-2);
  2174.  
  2175.     for (i = 0; i < MAXGETPATH; i++)    /* Init these. */
  2176.       pp[i] = NULL;
  2177.  
  2178. #ifdef CK_PARSDIR
  2179.     dd = 0;                             /* Temporary name counter */
  2180.     while (1) {
  2181.         if (cx != 2) {                  /* Dialing or Network Directory */
  2182. #ifdef OS2
  2183.             int len;
  2184.             char * appdata0 = NULL, * appdata1 = NULL;
  2185. #ifdef NT
  2186.             env = getenv("K95PHONES");
  2187.             makestr(&appdata0,(char *)GetAppData(0));
  2188.             makestr(&appdata1,(char *)GetAppData(1));
  2189. #else /* NT */
  2190.             env = getenv("K2PHONES");
  2191. #endif /* NT */
  2192.             if (!env)
  2193.               env = getenv("K95PHONES");
  2194.             if (!env)
  2195.               env = "";
  2196.  
  2197.             dirpath[0] = '\0';
  2198.             len = strlen(env) + 2*strlen(startupdir) + 2*strlen(inidir)
  2199.                 + (appdata0?2*strlen(appdata0):0) 
  2200.                 + (appdata1?2*strlen(appdata1):0)
  2201.                 + 2*strlen(zhome()) + 2*strlen(exedir) + 8*strlen("PHONES/")
  2202.                 + 12;
  2203.             if (len < 4096)             /* SAFE */
  2204.               sprintf(dirpath,
  2205.                     "%s%s%s;%s%s;%s%s%s%s%s%s%s%s%s;%s%s;%s;%s%s",
  2206.                     /* Semicolon-separated path list */
  2207.                     env,
  2208.                     (env[0] && env[strlen(env)-1] == ';') ? "" : ";",
  2209.                     startupdir,
  2210.                     startupdir, "PHONES/",
  2211.                     appdata1 ? appdata1 : "", 
  2212.                     appdata1 ? "Kermit 95;" : "",
  2213.                     appdata1 ? appdata1 : "", 
  2214.                     appdata1 ? "Kermit 95/PHONES/;" : "",
  2215.                     appdata0 ? appdata0 : "", 
  2216.                     appdata0 ? "Kermit 95;" : "",
  2217.                     appdata0 ? appdata0 : "", 
  2218.                     appdata0 ? "Kermit 95/PHONES/;" : "",
  2219.                     inidir,
  2220.                     inidir, "PHONES/",
  2221.                     zhome(),
  2222.                     zhome(), "PHONES/",
  2223.                     exedir,
  2224.                     exedir, "PHONES/"
  2225.                     );
  2226. #ifdef NT
  2227.             makestr(&appdata0,NULL);
  2228.             makestr(&appdata1,NULL);
  2229. #endif /* NT */
  2230. #else
  2231. #ifdef UNIX
  2232.             y = 1024;
  2233.             s = dirpath;
  2234.             zzstring("\\v(home)",&s,&y);
  2235. #endif /* UNIX */
  2236. #endif /* OS2 */
  2237.             y = cmifip(
  2238.                   "Names of one or more directory files, separated by spaces",
  2239.                        "",&s,&x,0,
  2240. #ifdef OS2ORUNIX
  2241.                        dirpath,
  2242. #else
  2243.                        NULL,
  2244. #endif /* OS2ORUNIX */
  2245.                        xxstring
  2246.                        );
  2247.         } else {                        /* List of directory names */
  2248.             x = 0;
  2249.             y = cmdir("Directory name","",&s,xxstring);
  2250.         }
  2251.         if (y < 0) {
  2252.             if (y == -3) {              /* EOL or user typed <CR> */
  2253.                 if ((y = cmcfm()) < 0) return(y);
  2254.                 for (i = 0; i < max; i++) { /* Clear these */
  2255.                     if (i < nxdir && xdir[i]) {
  2256.                         free(xdir[i]);
  2257.                     }
  2258.                     xdir[i] = (i < dd) ? pp[i] : NULL;
  2259.                 }
  2260. #ifndef NODIAL
  2261.                 if (cx == 0)
  2262.                   ndialdir = dd;
  2263. #ifdef NETCONN
  2264.                 if (cx == 1)
  2265.                   nnetdir = dd;
  2266. #endif /* NETCONN */
  2267. #endif /* NODIAL */
  2268. #ifndef NOSERVER
  2269.                 if (cx == 2)
  2270.                   ngetpath = dd;
  2271. #endif /* NOSERVER */
  2272.                 return(success = 1);
  2273.  
  2274.             } else {                    /* Parse error */
  2275.                 for (i = 0; i < dd; i++) {  /* Free temp storage */
  2276.                     if (pp[i]) free(pp[i]); /* but don't change */
  2277.                     pp[i] = NULL;           /* anything else */
  2278.                 }
  2279.                 return(y);
  2280.             }
  2281.         }
  2282.         if (x) {
  2283.             printf("?Wildcards not allowed\n");
  2284.             return(-9);
  2285.         }
  2286. #ifdef CK_TMPDIR
  2287.         if (cx == 2 && !isdir(s)) {
  2288.             printf("?Not a directory - %s\n", s);
  2289.             return(-9);
  2290.         }
  2291. #endif /* CK_TMPDIR */
  2292.  
  2293. #ifdef ZFNQFP
  2294.         if (cx < 2) {
  2295.             if (!isabsolute(s)) {       /* If not relative get full path */
  2296.                 if ((fnp = zfnqfp(s,TMPBUFSIZ - 1,tmpbuf))) {
  2297.                     if (fnp->fpath)
  2298.                       if ((int) strlen(fnp->fpath) > 0)
  2299.                         s = fnp->fpath;
  2300.                 }
  2301.             }
  2302.         }
  2303. #endif /* ZFNQFP */
  2304.         c = NUL;
  2305.         x = strlen(s);
  2306.         if (x > 0)                      /* Get last char */
  2307.           c = s[x-1];
  2308.         debug(F000,"parsdir s",s,c);
  2309.         if ((pp[dd] = malloc(strlen(s)+2)) == NULL) {
  2310.             printf("?Internal error - malloc\n");
  2311.             for (i = 0; i < dd; i++) {  /* Free temp storage */
  2312.                 if (pp[i]) free(pp[i]);
  2313.                 pp[i] = NULL;
  2314.             }
  2315.             return(-9);
  2316.         } else {                        /* Have storage for name */
  2317.             strcpy(pp[dd],s);           /* Copy string into new storage */
  2318.             debug(F111,"parsdir pp[dd] 1",pp[dd],dd);
  2319. #ifndef NOXFER
  2320.             if (cx == 2) {              /* If we are parsing directories */
  2321.                 char dirsep[2];
  2322.                 extern int myindex;     /* Append directory separator if */
  2323.                 extern struct sysdata sysidlist[]; /* it is missing...   */
  2324.                 debug(F101,"parsdir myindex","",myindex);
  2325.                 if (myindex > -1)
  2326.                   if (sysidlist[myindex].sid_unixlike)
  2327.                     if (c != sysidlist[myindex].sid_dirsep) {
  2328.                         dirsep[0] = sysidlist[myindex].sid_dirsep;
  2329.                         dirsep[1] = NUL;
  2330.                         strcat(pp[dd], (char *) dirsep); /* safe */
  2331.                     }
  2332.             }
  2333. #endif /* NOXFER */
  2334.             debug(F111,"parsdir pp[dd] 2",pp[dd],dd);
  2335.             if (++dd > max) {
  2336.                 printf("?Too many directories - %d max\n", max);
  2337.                 for (i = 0; i < dd; i++) {  /* Free temp storage */
  2338.                     if (pp[i]) free(pp[i]);
  2339.                     pp[i] = NULL;
  2340.                 }
  2341.             }
  2342.         }
  2343.     }
  2344. #endif /* CK_PARSDIR */
  2345. }
  2346. #endif /* NOSPL */
  2347.  
  2348. #ifndef NOSERVER
  2349. static int
  2350. cklogin() {
  2351.     int x;
  2352.     char * s;
  2353.     char username[LOGINLEN+1];
  2354.     char password[LOGINLEN+1];
  2355.     char account[LOGINLEN+1];
  2356.     extern char * x_user, * x_passwd, * x_acct;
  2357.     extern int x_login, x_logged;
  2358.  
  2359.     username[0] = NUL;
  2360.     password[0] = NUL;
  2361.     account[0]  = NUL;
  2362.  
  2363.     x = cmfld("username", "", &s, xxstring);
  2364.     if (x != -3) {
  2365.         if (x < 0)
  2366.           return(x);
  2367.         if ((int)strlen(s) > LOGINLEN) {
  2368.             printf("\"%s\" - too long, %d max\n", s, LOGINLEN);
  2369.             return(-9);
  2370.         }
  2371.         ckstrncpy(username,s,LOGINLEN+1);
  2372.         x = cmfld("password", "", &s, xxstring);
  2373.         if (x != -3) {
  2374.             if (x < 0)
  2375.               return(x);
  2376.             if ((int)strlen(s) > LOGINLEN) {
  2377.                 printf("\"%s\" - too long, %d max\n", s, LOGINLEN);
  2378.                 return(-9);
  2379.             }
  2380.             ckstrncpy(password,s,LOGINLEN+1);
  2381.             x = cmfld("account", "", &s, xxstring);
  2382.             if (x != -3) {
  2383.                 if (x < 0)
  2384.                   return(x);
  2385.                 if ((int)strlen(s) > LOGINLEN) {
  2386.                     printf("\"%s\" - too long, %d max\n", s, LOGINLEN);
  2387.                     return(-9);
  2388.                 }
  2389.                 ckstrncpy(account,s,LOGINLEN+1);
  2390.                 if ((x = cmcfm()) < 0)
  2391.                   return(x);
  2392.             }
  2393.         }
  2394.     }
  2395.     makestr(&x_user,username);
  2396.     makestr(&x_passwd,password);
  2397.     makestr(&x_acct,account);
  2398.     x_login = (x_user) ? 1 : 0;
  2399.     x_logged = 0;
  2400.     return(1);
  2401. }
  2402. #endif /* NOSERVER */
  2403.  
  2404. #ifndef NOLOCAL
  2405. static int
  2406. setdcd() {
  2407.     int x, y, z = 0;
  2408.     if ((y = cmkey(crrtab,ncrr,"","automatic",xxstring)) < 0) return(y);
  2409.     if (y == CAR_ON) {
  2410.         x = cmnum("Carrier wait timeout, seconds","0",10,&z,xxstring);
  2411.         if (x < 0) return(x);
  2412.     }
  2413.     if ((x = cmcfm()) < 0) return(x);
  2414.     carrier = ttscarr(y);
  2415.     cdtimo = z;
  2416.     return(1);
  2417. }
  2418. #endif /* NOLOCAL */
  2419.  
  2420. extern struct keytab yesno[];
  2421. extern int nyesno;
  2422.  
  2423. /* g e t y e s n o  */
  2424.  
  2425. static struct keytab q0yesno[] = {      /* Yes/No/Quit keyword table */
  2426.     "no",    0, 0,
  2427.     "ok",    1, 0,
  2428.     "yes",   1, 0
  2429. };
  2430. static int nq0yesno = (sizeof(q0yesno) / sizeof(struct keytab));
  2431.  
  2432. static struct keytab q1yesno[] = {      /* Yes/No/Quit keyword table */
  2433.     "no",    0, 0,
  2434.     "ok",    1, 0,
  2435.     "quit",  2, 0,
  2436.     "yes",   1, 0
  2437. };
  2438. static int nq1yesno = (sizeof(q1yesno) / sizeof(struct keytab));
  2439.  
  2440. static struct keytab q2yesno[] = {      /* Yes/No/Quit keyword table */
  2441.     "go",    3, 0,
  2442.     "no",    0, 0,
  2443.     "ok",    1, 0,
  2444.     "yes",   1, 0
  2445. };
  2446. static int nq2yesno = (sizeof(q2yesno) / sizeof(struct keytab));
  2447.  
  2448. static struct keytab q3yesno[] = {      /* Yes/No/Quit keyword table */
  2449.     "go",    3, 0,
  2450.     "no",    0, 0,
  2451.     "ok",    1, 0,
  2452.     "quit",  2, 0,
  2453.     "yes",   1, 0
  2454. };
  2455. static int nq3yesno = (sizeof(q3yesno) / sizeof(struct keytab));
  2456.  
  2457.  
  2458. /* Ask question, get yes/no answer */
  2459.  
  2460. int
  2461. getyesno(msg, flags) char * msg; int flags; {
  2462. #ifdef CK_RECALL
  2463.     extern int on_recall;               /* around Password prompting */
  2464. #endif /* CK_RECALL */
  2465.     int y, z;
  2466.  
  2467. #ifndef NOLOCAL
  2468. #ifdef OS2
  2469.     extern int vmode, win95_popup, startflags;
  2470.     int vmode_sav = vmode;
  2471. #endif /* OS2 */
  2472. #endif /* NOLOCAL */
  2473.  
  2474. #ifdef CK_APC
  2475.     if ( apcactive != APC_INACTIVE && (apcstatus & APC_NOINP) ) {
  2476.         return(success = 0);
  2477.     }
  2478. #endif /* CK_APC */
  2479.  
  2480. #ifndef NOLOCAL
  2481. #ifdef OS2
  2482. #ifdef COMMENT
  2483.     if (win95_popup && !(startflags & 96)
  2484. #ifdef IKSD
  2485.         && !inserver
  2486. #endif /* IKSD */
  2487.         )
  2488.       return(popup_readyesno(vmode,NULL,msg,flags));
  2489. #endif /* COMMENT */
  2490.     if (vmode == VTERM) {
  2491.         vmode = VCMD;
  2492.         VscrnIsDirty(VTERM);
  2493.         VscrnIsDirty(VCMD);
  2494.     }
  2495. #endif /* OS2 */
  2496. #endif /* NOLOCAL */
  2497. #ifdef VMS
  2498. /*
  2499.   In VMS, whenever a TAKE file or macro is active, we restore the
  2500.   original console modes so Ctrl-C/Ctrl-Y can work.  But here we
  2501.   go interactive again, so we have to temporarily put them back.
  2502. */
  2503.     if (!xcmdsrc)
  2504.       concb((char)escape);
  2505. #endif /* VMS */
  2506.  
  2507. #ifdef CK_RECALL
  2508.     on_recall = 0;
  2509. #endif /* CK_RECALL */
  2510.     cmsavp(psave,PROMPTL);              /* Save old prompt */
  2511.     cmsetp(msg);                        /* Make new prompt */
  2512.     z = 0;                              /* Initialize answer to No. */
  2513.     cmini(ckxech);                      /* Initialize parser. */
  2514.     do {
  2515.         prompt(NULL);                   /* Issue prompt. */
  2516.         switch (flags) {
  2517.           case 0:  y = cmkey(q0yesno,nq0yesno,"","",NULL); break;
  2518.           case 1:  y = cmkey(q1yesno,nq1yesno,"","",NULL); break;
  2519.           case 2:  y = cmkey(q2yesno,nq2yesno,"","",NULL); break;
  2520.           default: y = cmkey(q3yesno,nq3yesno,"","",NULL);
  2521.         }
  2522.         if (y < 0) {
  2523.             if (y == -4) {              /* EOF */
  2524.                 z = y;
  2525.                 break;
  2526.             } else if (y == -3)         /* No answer? */
  2527.               printf(" Please respond; type '?' to see valid answers.\n");
  2528.             cmini(ckxech);
  2529.         } else {
  2530.             z = y;                      /* Save answer */
  2531.             y = cmcfm();                /* Get confirmation */
  2532.         }
  2533.     } while (y < 0);                    /* Continue till done */
  2534.     cmsetp(psave);                      /* Restore real prompt */
  2535. #ifdef VMS
  2536.     if (cmdlvl > 0)                     /* In VMS and not at top level, */
  2537.       conres();                         /*  restore console again. */
  2538. #endif /* VMS */
  2539. #ifndef NOLOCAL
  2540. #ifdef OS2
  2541.     if (vmode != vmode_sav) {
  2542.         vmode = VTERM;
  2543.         VscrnIsDirty(VCMD);
  2544.         VscrnIsDirty(VTERM);
  2545.     }
  2546. #endif /* OS2 */
  2547. #endif /* NOLOCAL */
  2548.     return(z);
  2549. }
  2550.  
  2551. #ifdef KUI
  2552. extern HWND hwndConsole;
  2553. _PROTOTYP(int gui_txt_dialog,(char *,char *,int,char *,int,char *,int));
  2554. _PROTOTYP(int gui_mtxt_dialog,(char *,int,struct txtbox []));
  2555. _PROTOTYP(int gui_position,(int, int));
  2556. _PROTOTYP(int gui_resize_mode,(int));
  2557. _PROTOTYP(int gui_win_run_mode,(int));
  2558. _PROTOTYP(int gui_saveas_dialog,(char *,char *, int, char *, char *, int));
  2559. extern int gui_dialog;
  2560. #endif /* KUI */
  2561.  
  2562. /* u q _ o k  --  User Query, get Yes/No or OK Cancel  */
  2563. /*
  2564.   Call with:  
  2565.     preface: Explanatory text to print, or NULL.
  2566.     prompt:  Prompt.
  2567.     mask:    Bitmask for legal responses: 1 = OK or Yes; 2 = No or Cancel.
  2568.     help:    Help text (array of strings or NULL) [not used by parser].
  2569.     dflt:    Default response (1 or 2) [not used by parser].
  2570.   Returns:
  2571.    -1:       Invalid argument(s).
  2572.     0:       User said No or Cancel.
  2573.     1        User said Yes or OK.    
  2574.   Notes:
  2575.     preface and prompt should not include final line terminator but may
  2576.     include embedded ones.  Help text is in case GUI dialog needs a Help
  2577.     button; final element of help-string array is "".  dflt is used by GUI
  2578.     to highlight the default response button.
  2579. */
  2580. int
  2581. #ifdef CK_ANSIC
  2582. uq_ok(char * preface, char * prompt, int mask,char ** help, int dflt)
  2583. #else /* CK_ANSIC */
  2584. uq_ok(preface,prompt,mask,help,dflt)
  2585.     char * preface, * prompt, ** help;
  2586.     int mask, dflt;
  2587. #endif /* CK_ANSIC */
  2588. /* uq_ok */ {
  2589.     int rc, len;
  2590.     char * text=NULL;
  2591.  
  2592.     if (!prompt)
  2593.       return(-1);
  2594.  
  2595.     if ((mask & 3) == 1) {        /* OK (GUI only) */
  2596. #ifdef KUI
  2597.       if ( gui_dialog ) {
  2598.     /* This one is for popup help, alerts, etc */
  2599.         if (preface) {
  2600.             len = strlen(preface) + strlen(prompt) + 4;
  2601.             text = (char *)malloc(len);
  2602.             ckmakmsg(text,len,preface,"\n",prompt,NULL);
  2603.         }
  2604.         rc = MessageBox(hwndConsole,
  2605.                          text ? text : prompt,
  2606.                          prompt,
  2607.                          MB_OK | MB_ICONINFORMATION | MB_TASKMODAL);
  2608.         ShowWindowAsync(hwndConsole,SW_SHOWNORMAL);
  2609.         SetForegroundWindow(hwndConsole);
  2610.         if (text)
  2611.       free(text);
  2612.         if (!rc)
  2613.       return(-1);
  2614.         else 
  2615.       return(1);
  2616.       } else
  2617. #endif  /* KUI */
  2618.       {
  2619.     if (preface)            /* Just display the text, if any */
  2620.       printf("%s\n",preface);
  2621.     if (prompt)
  2622.       printf("%s\n",prompt);
  2623.         return(1);
  2624.       }
  2625.     } else if ((mask & 3) == 3) {    /* Yes/No or OK/Cancel */
  2626. #ifdef KUI
  2627.       if ( gui_dialog ) {
  2628.         if (preface) {
  2629.             len = strlen(preface) + strlen(prompt) + 4;
  2630.             text = (char *)malloc(len);
  2631.             ckmakmsg(text,len,preface,"\n",prompt,NULL);
  2632.         }
  2633.         rc = MessageBox(hwndConsole,
  2634.                          text ? text : prompt,
  2635.                          prompt,
  2636.                          MB_YESNO | MB_ICONINFORMATION | MB_TASKMODAL | 
  2637.                          (dflt == 2 ? MB_DEFBUTTON2 : MB_DEFBUTTON1));
  2638.         ShowWindowAsync(hwndConsole,SW_SHOWNORMAL);
  2639.         SetForegroundWindow(hwndConsole);
  2640.         if (text)
  2641.       free(text);
  2642.         if (!rc)
  2643.       return(-1);
  2644.         else if (rc == IDNO || rc == IDCANCEL)
  2645.       return(0);
  2646.         else
  2647.       return(1);
  2648.       } else
  2649. #endif  /* KUI */
  2650.       {
  2651.     if (preface)
  2652.       printf("%s\n",preface);
  2653.     return(getyesno(prompt,0));
  2654.       }
  2655.     } else {
  2656.     printf("?Internal error: uq_ok()\n");
  2657.     return(-1);
  2658.     }
  2659. }
  2660.  
  2661. /* u q _ t x t  --  User Query, get single text response  */
  2662. /*
  2663.   Call with:  
  2664.     preface: Explanatory text to print, or NULL.
  2665.     prompt:  Prompt. 
  2666.     echo:    0 = don't echo; 1 = echo; 2 = echo with asterisks.
  2667.     help:    Help text (array of strings or NULL) [not used by parser].
  2668.     buf:     Pointer to result buffer.
  2669.     buflen:  Length of result buffer.
  2670.     dflt:    Default response text or NULL [not used by parser].
  2671.     timer:   Optional Timeout
  2672.   Returns:
  2673.     0:       User said No or Cancel.
  2674.     1        User said Yes or OK.    
  2675.   Notes:
  2676.     preface, prompt, and help as for uq_ok().
  2677. */
  2678. int
  2679. #ifdef CK_ANSIC
  2680. uq_txt(char * preface, char * prompt, int echo, char ** help, char * buf, 
  2681.        int buflen, char *dflt, int timer)
  2682. #else /* CK_ANSIC */
  2683. uq_txt(preface,prompt,echo,help,buf,buflen,dflt,timer)
  2684.     char * preface, * prompt, ** help, * buf, * dflt; 
  2685.     int buflen, echo, timer;
  2686. #endif /* CK_ANSIC */
  2687. {
  2688. #ifndef NOLOCAL
  2689. #ifdef OS2
  2690.     extern int vmode;
  2691.     extern int startflags;
  2692.     extern int win95_popup;
  2693. #endif /* OS2 */
  2694. #endif /* NOLOCAL */
  2695.     int rc; 
  2696.  
  2697.     if (buflen < 1 || !buf)
  2698.       return(0);
  2699. #ifdef KUI
  2700.     if ( gui_dialog ) {
  2701.         rc = gui_txt_dialog(preface,prompt,echo,buf,buflen,dflt,timer);
  2702.         if ( rc > -1 )
  2703.             return(rc);
  2704.     /* Otherwise, the dialog could not be created.  Fallback to text mode */
  2705.     } 
  2706. #endif /* KUI */
  2707. #ifndef NOLOCAL
  2708. #ifdef OS2
  2709.     if (win95_popup && !(startflags & 96)
  2710. #ifdef IKSD
  2711.          && !inserver
  2712. #endif /* IKSD */
  2713.          ) {
  2714.         debok = 0;                          /* Don't log */
  2715.         if (echo == 1)
  2716.                 popup_readtext(vmode,preface,prompt,buf,buflen,0);
  2717.             else
  2718.                 popup_readpass(vmode,preface,prompt,buf,buflen,0);
  2719.         debok = 1;
  2720.         return(1);
  2721.     }
  2722. #endif /* OS2 */
  2723. #endif /* NOLOCAL */
  2724.  
  2725.     if (preface)
  2726.       printf("%s\n",preface);
  2727.     if (echo == 1)
  2728.       readtext(prompt,buf,buflen);
  2729.     else
  2730.       readpass(prompt,buf,buflen);
  2731.     return(1);                /* (no buttons in parser) */
  2732. }
  2733.  
  2734. /* u q _ m t x t  --  User Query, get multiple text responses */
  2735. /*
  2736.   Call with:  
  2737.     preface: Explanatory text to print, or NULL.
  2738.     help:    Help text (array of strings or NULL) [not used by parser].
  2739.     n:       Number of responses wanted.
  2740.     field:   Array of struct txtbox, one element per field, see ckuusr.h.
  2741.   Returns:
  2742.     0:       User said No or Cancel.
  2743.     1        User said Yes or OK.    
  2744.   Notes:
  2745.     preface and help as for uq_ok().
  2746. */
  2747. int
  2748. #ifdef CK_ANSIC
  2749. uq_mtxt(char * preface,char **help, int n, struct txtbox field[])
  2750. #else /* CK_ANSIC */
  2751. uq_mtxt(preface,help,n,field)
  2752.     char * preface; char ** help; int n; struct txtbox field[]; 
  2753. #endif /* CK_ANSIC */
  2754. {
  2755. #ifndef NOLOCAL
  2756. #ifdef OS2
  2757.     extern int vmode;
  2758.     extern int startflags;
  2759.     extern int win95_popup;
  2760. #endif /* OS2 */
  2761. #endif /* NOLOCAL */
  2762.     int i, rc;
  2763.  
  2764.     if (n < 1 || !field)
  2765.       return(0);
  2766. #ifdef KUI
  2767.     if ( gui_dialog ) {
  2768.         rc = gui_mtxt_dialog(preface, n, field);
  2769.         if ( rc > -1 )
  2770.             return(rc);
  2771.     /* Otherwise, the dialog could not be created.  Fallback to text mode */
  2772.     }
  2773. #endif /* KUI */
  2774. #ifndef NOLOCAL
  2775. #ifdef OS2
  2776.     if (win95_popup && !(startflags & 96)
  2777. #ifdef IKSD
  2778.          && !inserver
  2779. #endif /* IKSD */
  2780.          ) {
  2781.         debok = 0;                          /* Don't log */
  2782.         for (i = 0; i < n; i++) {
  2783.             if (field[i].t_echo == 1)
  2784.                 popup_readtext(vmode,preface,field[i].t_lbl,field[i].t_buf,field[i].t_len,0);
  2785.             else
  2786.                 popup_readpass(vmode,preface,field[i].t_lbl,field[i].t_buf,field[i].t_len,0);
  2787.         }
  2788.         debok = 1;
  2789.         return(1);
  2790.     }
  2791. #endif /* OS2 */
  2792. #endif /* NOLOCAL */
  2793.  
  2794.     if (preface)
  2795.       printf("%s\n",preface);
  2796.     for (i = 0; i < n; i++) {
  2797.     if (field[i].t_echo == 1)
  2798.       readtext(field[i].t_lbl,field[i].t_buf,field[i].t_len);
  2799.     else
  2800.       readpass(field[i].t_lbl,field[i].t_buf,field[i].t_len);
  2801.     }
  2802.     return(1);
  2803. }
  2804.  
  2805. /* u q _ f i l e  --  User Query, get file or directory name  */
  2806. /*
  2807.   Call with:  
  2808.     preface: Explanatory text to print, or NULL.
  2809.     prompt:  Prompt string.
  2810.     fc:      Function code:
  2811.            1 = input (existing) file
  2812.            2 = existing directory 
  2813.            3 = create new output file
  2814.            4 = output file allowing append access
  2815.     help:    Help text (array of strings or NULL) [not used by parser].
  2816.     dflt:    Default response.
  2817.     result:  Pointer to result buffer.
  2818.     rlength: Length of result buffer.
  2819.  
  2820.   Returns:
  2821.    -1:       Invalid argument, result too long, or other error.
  2822.     0:       User Canceled.
  2823.     1:       OK, with file/pathname copied to result buffer.
  2824.     2:       Like 1, but for output file that is to be appended to.
  2825.  
  2826.   Notes:
  2827.     1. preface and prompt should not include final line terminator but may
  2828.        include embedded ones.  Help text is in case GUI dialog needs a Help
  2829.        button; final element of help-string array is "".
  2830.  
  2831.     2. The default might be a filename, a directory name, a relative
  2832.        pathname, or an absolute pathname.  This routine must convert it into
  2833.        into a fully qualified (absolute) pathname so the user knows exactly
  2834.        where the file is to be found or stored.  In addition, the Windows
  2835.        version of this routine must separate the directory part from the
  2836.        name part, so it can display the given directory in the file dialog,
  2837.        and put name in the filename box to be edited, replaced, or
  2838.        accepted.
  2839.  
  2840.     3. When called with FC 4, the Windows version should include "New" and
  2841.        "Append" buttons in the dialog. so the user can say whether the file
  2842.        should overwrite any file of the same name, or be appended to it.
  2843. */
  2844.  
  2845. int
  2846. #ifdef CK_ANSIC
  2847. uq_file(char * preface, char * fprompt, int fc, char ** help,
  2848.     char * dflt, char * result, int rlength)
  2849. #else /* CK_ANSIC */
  2850. uq_file(preface,fprompt,fc,help,dflt,result,rlength)
  2851.     char * preface, * fprompt, ** help, * dflt, * result;
  2852.     int fc, rlength;
  2853. #endif /* CK_ANSIC */
  2854. /* uq_file */ {
  2855.  
  2856.     int rc = -1, x, y, z;
  2857.     char * s, * p, * fullpath;
  2858.     char filebuf[CKMAXPATH+1];
  2859.  
  2860. #ifdef CK_RECALL
  2861.     extern int on_recall;
  2862. #endif /* CK_RECALL */
  2863.  
  2864. #ifdef KUI
  2865.     if ( gui_dialog ) {
  2866.         rc = gui_saveas_dialog(preface,fprompt,fc,dflt,result,rlength);
  2867.         return rc;
  2868.     }
  2869. #endif /* KUI */
  2870.  
  2871. #ifdef CK_RECALL
  2872.     on_recall = 0;
  2873. #endif /* CK_RECALL */
  2874.  
  2875.     if (preface)            /* If prefatory text given... */
  2876.       printf("%s\n",preface);        /* display it. */
  2877.  
  2878.     cmsavp(psave,PROMPTL);              /* Save old prompt */
  2879.  
  2880.     /* We get the full pathname of the proposed output file just so */
  2881.     /* we can show it to the user but we don't use it ourselves. */
  2882.  
  2883.     p = NULL;                /* Build new prompt */
  2884.     if (!dflt) dflt = "";
  2885.     if (*dflt)                /* Have default filename */
  2886.       zfnqfp(dflt,CKMAXPATH+1,filebuf);    /* Get full path */
  2887.     else
  2888.       ckmakmsg(filebuf,CKMAXPATH+1,zgtdir(),"newfile",NULL,NULL);
  2889.     fullpath = filebuf;
  2890.     x = strlen(fullpath);
  2891.  
  2892.     /* If no prompt given, build one that shows the proposed full pathname. */
  2893.  
  2894.     if (!fprompt) fprompt = "";
  2895.     if (!*fprompt) fprompt = x ? " Filename" : " Filename: ";
  2896.     y = strlen(fprompt);
  2897.     if (x > 0) {            /* Have default pathname? */
  2898.     p = (char *)malloc(x + y + 7);    /* Get temp storage */
  2899.     if (p) {            /* Build prompt */
  2900.         ckmakmsg(p,x+y+7,fprompt," [",fullpath,"]: ");
  2901.         fprompt = p;
  2902.     }
  2903.     }
  2904.     cmsetp(fprompt);            /* Make new prompt */
  2905.     if (p) free(p);            /* Free temp storage */
  2906.     cmini(ckxech);                      /* Initialize parser. */
  2907.     x = -1;
  2908.     do {
  2909.         prompt(NULL);                   /* Issue prompt. */
  2910.         switch (fc) {            /* Parse depends on function code */
  2911.           case 1:            /* Input file */
  2912.         x = cmifi("Name of existing file",dflt,&s,&y,xxstring);
  2913.         rc = 1;
  2914.         break;
  2915.       case 2:            /* Directory */
  2916.         x = cmdir("Directory name",dflt,&s,xxstring);
  2917.         rc = 1;
  2918.         break;
  2919.           case 3:            /* New output file */
  2920.         /* Fall thru... */
  2921.       case 4:            /* Output file - Append allowed */
  2922.         x = cmofi("Output file specification",dflt,&s,xxstring);
  2923.         rc = (fc == 4) ? 1 : 2;
  2924.         break;
  2925.           default:            /* Bad function code */
  2926.         goto x_uq_file;
  2927.         }
  2928.         if (x < 0) {            /* Parse error */
  2929.         filebuf[0] = NUL;
  2930.             if (x == -4) {              /* EOF */
  2931.                 break;
  2932.             } else if (x == -3)         /* No answer? */
  2933.               printf(fc == 2 ?
  2934.              " Please enter a directory name.\n" :
  2935.              " Please enter a filename.\n"
  2936.              );
  2937.             cmini(ckxech);
  2938.         } else {
  2939.         z = strlen(s);
  2940.         if (z > rlength || ckstrncpy(filebuf,brstrip(s),CKMAXPATH+1) < z) {
  2941.         printf("?Name too long\n");
  2942.         x = -9;
  2943.         } else
  2944.           x = cmcfm();        /* Get confirmation */
  2945.         }
  2946.     if (fc == 1 && x > -1 && y > 0) {
  2947.         printf("?Wildcards not allowed\n");
  2948.         x = -9;
  2949.     }
  2950.     } while (x < 0);                    /* Continue till done */
  2951.  
  2952.   x_uq_file:
  2953.     if (x < 0)
  2954.       rc = -1;
  2955.  
  2956.     cmsetp(psave);                      /* Restore real prompt */
  2957.  
  2958.     if (rc > 0)
  2959.       ckstrncpy(result,filebuf,rlength);
  2960.     return(rc);
  2961. }
  2962.  
  2963.  
  2964. #ifdef CK_PERMS
  2965. #ifdef UNIX
  2966.  
  2967. _PROTOTYP( int zsetperm, (char *, int));
  2968.  
  2969. /* CHMOD command for UNIX only */
  2970.  
  2971. #define CHM_DIR 0
  2972. #define CHM_DOT 1
  2973. #define CHM_FIL 2
  2974. #define CHM_LIS 3
  2975. #define CHM_NOL 4
  2976. #define CHM_QUI 5
  2977. #define CHM_REC 6
  2978. #define CHM_VRB 7
  2979. #define CHM_PAG 8
  2980. #define CHM_NOP 9
  2981. #define CHM_TYP 10
  2982. #define CHM_SIM 11
  2983.  
  2984. static struct keytab uchmodsw[] = {
  2985.     "/directories", CHM_DIR, 0,
  2986.     "/dotfiles",    CHM_DOT, 0,
  2987.     "/files",       CHM_FIL, 0,
  2988.     "/list",        CHM_LIS, 0,
  2989.     "/nolist",      CHM_NOL, 0,
  2990.     "/nopage",      CHM_NOP, 0,
  2991.     "/page",        CHM_PAG, 0,
  2992.     "/quiet",       CHM_QUI, CM_INV,
  2993.     "/recursive",   CHM_REC, 0,
  2994.     "/simulate",    CHM_SIM, 0,
  2995.     "/type",        CHM_TYP, CM_ARG,
  2996.     "/verbose",     CHM_VRB, CM_INV,
  2997. };
  2998. static int nchmodsw = (sizeof(uchmodsw) / sizeof(struct keytab));
  2999.  
  3000. int
  3001. douchmod() {
  3002.     extern int recursive, nscanfile, diractive;
  3003. #ifdef CK_TTGWSIZ
  3004.     extern int tt_rows, tt_cols;
  3005.     int n = 0;
  3006. #endif /* CK_TTGWSIZ */
  3007.     int i, files = 1, t1 = 1, t2 = 0, x, y, z, verbose = 0, rc = 1, paging;
  3008.     int xmode = -1, fs = 0, getval = 0, simulate = 0, wild = 0;
  3009.     char c, * s;
  3010.     struct FDB sw, nu;
  3011.  
  3012.     if (xaskmore < 0) {
  3013. #ifdef CK_TTGWSIZ
  3014.         xaskmore = 1;
  3015. #else
  3016.         xaskmore = 0;
  3017. #endif /* CK_TTGWSIZ */
  3018.     }
  3019.     paging = xaskmore;
  3020.  
  3021.     cmfdbi(&sw,                         /* First FDB - command switches */
  3022.            _CMKEY,                      /* fcode */
  3023.            "Octal file permission code, or switch",
  3024.            "",                          /* default */
  3025.            "",                          /* addtl string data */
  3026.            nchmodsw,                    /* addtl numeric data 1: tbl size */
  3027.            4,                           /* addtl numeric data 2: 4 = cmswi */
  3028.            xxstring,                    /* Processing function */
  3029.            uchmodsw,                    /* Keyword table */
  3030.            &nu                          /* Pointer to next FDB */
  3031.            );
  3032.     cmfdbi(&nu,
  3033.            _CMNUM,                      /* Number */
  3034.            "",                          /* Help message */
  3035.            "",                          /* Default */
  3036.            "",                          /* N/A */
  3037.            8,                           /* Radix = 8 */
  3038.            0,                           /* N/A */
  3039.            xxstring,                    /* Processing function */
  3040.            NULL,                        /* N/A */
  3041.            NULL                         /* Next */
  3042.            );
  3043.  
  3044.     while (1) {
  3045.         if ((x = cmfdb(&sw)) < 0) {
  3046.             if (x == -3) {
  3047.                 x = -9;
  3048.                 printf("?Filename required\n");
  3049.             }
  3050.             return(x);
  3051.         }
  3052.         if (cmresult.fcode != _CMKEY)
  3053.           break;
  3054.         c = cmgbrk();
  3055.         getval = (c == ':' || c == '=');
  3056.         if (getval && !(cmgkwflgs() & CM_ARG)) {
  3057.             printf("?This switch does not take an argument\n");
  3058.             return(-9);
  3059.         }
  3060.         if (!getval && (cmgkwflgs() & CM_ARG)) {
  3061.             printf("?This switch requires an argument\n");
  3062.             return(-9);
  3063.         }
  3064.         switch (cmresult.nresult) {
  3065.           case CHM_DIR:
  3066.             t1 = 1;
  3067.             t2 = 1;
  3068.             break;
  3069.           case CHM_DOT:
  3070.             matchdot = 1;
  3071.             break;
  3072.           case CHM_FIL:
  3073.             t1 = 0;
  3074.             t2 = 0;
  3075.             break;
  3076.           case CHM_LIS:
  3077.           case CHM_VRB:
  3078.             verbose = 1;
  3079.             break;
  3080.           case CHM_NOL:
  3081.           case CHM_QUI:
  3082.             verbose = 0;
  3083.             break;
  3084.           case CHM_REC:
  3085.             recursive = 1;
  3086.             break;
  3087.           case CHM_PAG:
  3088.             verbose = 1;
  3089.             paging = 1;
  3090.             break;
  3091.           case CHM_NOP:
  3092.             paging = 0;
  3093.             break;
  3094.           case CHM_SIM:
  3095.             simulate = 1;
  3096.             break;
  3097.           case CHM_TYP: {
  3098.               extern struct keytab txtbin[];
  3099.               if ((x = cmkey(txtbin,3,"","",xxstring)) < 0)
  3100.                 return(x);
  3101.               if (x == 2) {             /* ALL */
  3102.                   xmode = -1;
  3103.               } else {                  /* TEXT or BINARY only */
  3104.                   xmode = x;
  3105.                   fs = 1;
  3106.               }
  3107.               break;
  3108.           }
  3109.         }
  3110.     }
  3111.     z = cmresult.nresult;
  3112.     x = cmifi2("File specification","",&s,&wild,t1,NULL,xxstring,t2);
  3113.     if (x < 0) {
  3114.         if (x == -3) {
  3115.             printf("?A file specification is required\n");
  3116.             return(-9);
  3117.         } else
  3118.           return(x);
  3119.     }
  3120.     ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  3121.     s = tmpbuf;
  3122.     if ((x = cmcfm()) < 0)
  3123.       return(x);
  3124. #ifdef ZXREWIND
  3125.     if (wild) files = zxrewind();
  3126. #else
  3127.     if (wild) files = nzxpand(s,0);
  3128. #endif /* ZXREWIND */
  3129.  
  3130.     if (paging > -1)
  3131.       xaskmore = paging;
  3132.  
  3133. #ifdef CK_TTGWSIZ
  3134.     if (verbose && paging) {
  3135. #ifdef OS2
  3136.         ttgcwsz();
  3137. #else /* OS2 */
  3138.         if (ttgwsiz() > 0) {
  3139.             if (tt_rows > 0 && tt_cols > 0) {
  3140.                 cmd_rows = tt_rows;
  3141.                 cmd_cols = tt_cols;
  3142.             }
  3143.         }
  3144. #endif /* OS2 */
  3145.     }
  3146. #endif /* CK_TTGWSIZ */
  3147.  
  3148.     for (i = 0; i < files; i++) {
  3149.         if (files == 1 && wild == 0) {  /* For "chmod 777 ." */
  3150.             ckstrncpy(line,s,LINBUFSIZ);
  3151.         } else {
  3152.             x = znext(line);
  3153.             if (x < 1) {
  3154.                 if (i == 0) {
  3155.                     printf("?No files match - \"%s\"\n",line);
  3156.                     return(-9);
  3157.                 }
  3158.                 return(1);
  3159.             }
  3160.         }
  3161.         if (fs) {
  3162. #ifdef VMSORUNIX
  3163.             /* If /TYPE:TEXT or BINARY given, skip directories and links */
  3164.             /* since they are neither text nor binary. */
  3165.             extern int zgfs_dir, zgfs_link;
  3166.             zgetfs(line);
  3167.             if (zgfs_dir || zgfs_link)
  3168.               continue;
  3169. #else
  3170.             if (zchki(line) < 0)
  3171.               continue;
  3172. #endif /* VMSORUNIX */
  3173.             /* Regular file, scan it */
  3174.             switch (scanfile(line,&y,nscanfile)) {
  3175.               case FT_BIN:
  3176.                 if (xmode != 1)
  3177.                   continue;
  3178.                 break;
  3179.               case FT_TEXT:
  3180.               case FT_7BIT:
  3181.               case FT_8BIT:
  3182. #ifdef UNICODE
  3183.               case FT_UTF8:
  3184.               case FT_UCS2:
  3185. #endif /* UNICODE */
  3186.                 if (xmode != 0)
  3187.                   continue;
  3188.             }
  3189.         }
  3190.         if (simulate) {
  3191. #ifdef UNIX
  3192.             extern int zchkod;          /* Unidentified Flying */
  3193.             int xx = zchkod;            /* API Extension... */
  3194.             zchkod = 1;
  3195. #endif /* UNIX */
  3196.             if (zchko(line) < 0)
  3197.               printf("%s - Access denied\n",line);
  3198.             else
  3199.               printf("%s - OK\n",line);
  3200. #ifdef UNIX
  3201.             zchkod = xx;
  3202. #endif /* UNIX */
  3203.         } else {
  3204.             if (zsetperm(line,z) < 1) {
  3205.                 if (verbose || files < 2) {
  3206.                     printf("%s: %s\n",line,ck_errstr());
  3207.                 }
  3208.                 rc = 0;
  3209.             } else if (verbose) {
  3210.                 printf("%s  %s\n",ziperm(line),line);
  3211.             }
  3212.         }
  3213. #ifdef CK_TTGWSIZ
  3214.         if (verbose && paging) {        /* Pause at end of screen */
  3215.             if (cmd_rows > 0 && cmd_cols > 0) {
  3216.                 if (++n > cmd_rows - 3) {
  3217.                     if (!askmore())
  3218.                       break;
  3219.                     else
  3220.                       n = 0;
  3221.                 }
  3222.             }
  3223.         }
  3224. #endif /* CK_TTGWSIZ */
  3225.  
  3226.     }
  3227.     return(success = rc);
  3228. }
  3229. #endif /* UNIX */
  3230. #endif /* CK_PERMS */
  3231.  
  3232. #ifndef NOSPL                           /* S-Expressions */
  3233. #ifndef NOSEXP
  3234.  
  3235. struct keytab sexptab[] = {
  3236.     "depth-limit", 1, 0,
  3237.     "echo-result", 0, 0
  3238. };
  3239.  
  3240. static int sexpmaxdep = 1000;           /* Maximum depth */
  3241.  
  3242. #define xxfloat(s,x) \
  3243. ((isdigit(*s)||(*s=='-')||(*s=='+')||(*s=='.')||(*s=='\040'))?isfloat(s,x):0)
  3244.  
  3245. #define SX_ADD  1                       /* Symbols for built-in operators */
  3246. #define SX_SUB  2
  3247. #define SX_MUL  3
  3248. #define SX_DIV  4
  3249. #define SX_POW  5
  3250. #define SX_SET  6
  3251. #define SX_MOD  7
  3252. #define SX_EVA  8
  3253. #define SX_EXP  9
  3254. #define SX_AEQ 10
  3255. #define SX_ALT 11
  3256. #define SX_AGT 12
  3257. #define SX_ALE 13
  3258. #define SX_AGE 14
  3259. #define SX_MIN 15
  3260. #define SX_MAX 16
  3261. #define SX_SQR 17
  3262. #define SX_FLR 18
  3263. #define SX_CEI 19
  3264. #define SX_TRU 20
  3265. #define SX_ABS 21
  3266. #define SX_ROU 22
  3267. #define SX_LET 23
  3268. #define SX_LGN 24
  3269. #define SX_LGX 25
  3270. #define SX_FLO 26
  3271. #define SX_IFC 27
  3272. #define SX_NOT 28
  3273. #define SX_NEQ 29
  3274. #define SX_AND 30
  3275. #define SX_LOR 31
  3276. #define SX_SIN 32
  3277. #define SX_COS 33
  3278. #define SX_TAN 34
  3279. #define SX_BWA 35
  3280. #define SX_BWO 36
  3281. #define SX_BWX 37
  3282. #define SX_BWN 38
  3283. #define SX_XOR 39
  3284. #define SX_INC 40
  3285. #define SX_DEC 41
  3286. #define SX_QUO 42
  3287. #define SX_STR 43
  3288.  
  3289. /* Operator flags */
  3290.  
  3291. #define SXF_PRE 256                     /* Predicate */
  3292. #define SXF_ONE 512                     /* Requires one arg */
  3293. #define SXF_TWO 1024                    /* Requires two args or more */
  3294. #define SXF_FLO 2048                    /* Coerce to floating-point */
  3295.  
  3296. /* Built-in constants */
  3297.  
  3298. #define SXC_NIL 1                       /* NIL */
  3299. #define SXC_PI  2                       /* PI */
  3300. #define SXC_T   3                       /* T */
  3301.  
  3302. /*
  3303.   This is an xlookup() table and so need not be in "alhabetical" order.
  3304.   Therefore entries are arranged to minimize search for most common
  3305.   operators.
  3306. */
  3307. static struct keytab sexpops[] = {      /* Built-in operators */
  3308.     "setq",    SX_SET, 0,               /* Global assignment */
  3309.     "+",       SX_ADD, 0,               /* Simple arithmetic */
  3310.     "-",       SX_SUB, 0,
  3311.     "*",       SX_MUL, 0,
  3312.     "/",       SX_DIV, SXF_TWO,
  3313.     "^",       SX_POW, SXF_TWO,
  3314.  
  3315.     "if",      SX_IFC, SXF_TWO,         /* IF */
  3316.     "let",     SX_LET, 0,               /* Local assignment */
  3317.     "not",     SX_NOT, SXF_ONE,         /* NOT */
  3318.     "mod",     SX_MOD, SXF_TWO,         /* Modulus */
  3319.  
  3320.     "<",       SX_ALT, SXF_PRE|SXF_TWO, /* Comparisons */
  3321.     ">",       SX_AGT, SXF_PRE|SXF_TWO,
  3322.     "<=",      SX_ALE, SXF_PRE|SXF_TWO,
  3323.     "=",       SX_AEQ, SXF_PRE|SXF_TWO,
  3324.     ">=",      SX_AGE, SXF_PRE|SXF_TWO,
  3325.     "!=",      SX_NEQ, SXF_PRE|SXF_TWO,
  3326.  
  3327.     "++",      SX_INC, SXF_ONE|SXF_TWO, /* Increment */
  3328.     "--",      SX_DEC, SXF_ONE|SXF_TWO, /* Decrement */
  3329.  
  3330.     "**",      SX_POW, SXF_TWO,         /* Common synonyms */
  3331.     "==",      SX_AEQ, SXF_PRE|SXF_TWO,
  3332.     "!",       SX_NOT, SXF_ONE,
  3333.     ".",       SX_EVA, 0,
  3334.  
  3335.     "and",     SX_AND, 0,               /* Logical operators */
  3336.     "or",      SX_LOR, 0,
  3337.     "xor",     SX_XOR, SXF_TWO,
  3338.  
  3339.     "max",     SX_MAX, SXF_ONE|SXF_TWO, /* Max and min */
  3340.     "min",     SX_MIN, SXF_ONE|SXF_TWO,
  3341.  
  3342.     "%",       SX_MOD, SXF_TWO,         /* More synonyms */
  3343.     "||",      SX_LOR, 0,
  3344.     "&&",      SX_AND, 0,
  3345.  
  3346.     "quote",   SX_QUO, SXF_ONE,
  3347.     "string",  SX_STR, SXF_ONE,
  3348.  
  3349.     "eval",    SX_EVA, 0,               /* Assorted commands */
  3350.     "abs",     SX_ABS, SXF_ONE,
  3351.     "truncate",SX_TRU, SXF_ONE|SXF_FLO,
  3352.     "round",   SX_ROU, SXF_ONE|SXF_FLO,
  3353.     "ceiling", SX_CEI, SXF_ONE|SXF_FLO,
  3354.     "floor",   SX_FLR, SXF_ONE|SXF_FLO,
  3355.     "float",   SX_FLO, SXF_ONE|SXF_FLO,
  3356.  
  3357. #ifdef FNFLOAT
  3358.     "sqrt",    SX_SQR, SXF_ONE|SXF_FLO, /* Floating point functions */
  3359.     "exp",     SX_EXP, SXF_ONE|SXF_FLO,
  3360.     "sin",     SX_SIN, SXF_ONE|SXF_FLO,
  3361.     "cos",     SX_COS, SXF_ONE|SXF_FLO,
  3362.     "tan",     SX_TAN, SXF_ONE|SXF_FLO,
  3363.     "log",     SX_LGN, SXF_ONE|SXF_FLO,
  3364.     "log10",   SX_LGX, SXF_ONE|SXF_FLO,
  3365. #endif /* FNFLOAT */
  3366.  
  3367.     "#",       SX_BWX, SXF_TWO,         /* Bitwise operators */
  3368.     "&",       SX_BWA, 0,
  3369.     "|",       SX_BWO, 0,
  3370.     "~",       SX_BWN, SXF_ONE,
  3371.     "", 0, 0                            /* (end) */
  3372. };
  3373. static int nsexpops = (sizeof(sexpops) / sizeof(struct keytab)) - 1;
  3374.  
  3375. static struct keytab sexpconsts[] = {   /* Built-in constants */
  3376.     "nil", SXC_NIL, 0,                  /* NIL (false) */
  3377.     "pi",  SXC_PI,  0,                  /* Pi (3.1415926...) */
  3378.     "t",   SXC_T,   0,                  /* T (true) */
  3379.     "", 0, 0
  3380. };
  3381. static int nsexpconsts = (sizeof(sexpconsts) / sizeof(struct keytab)) - 1;
  3382.  
  3383. int sexprc = 0;                         /* S-Expression error flag */
  3384. int sexppv = -1;                        /* Predicate value */
  3385.  
  3386. #define SXMLEN 64                       /* Macro arg list initial length */
  3387. #include <math.h>                       /* Floating-point functions */
  3388.  
  3389. _PROTOTYP( char * fpformat, (CKFLOAT, int, int) );
  3390.  
  3391. extern char math_pi[];                  /* Value of Pi */
  3392. extern int sexpecho;                    /* SET SEXPRESSION ECHO value */
  3393. extern char * sexpval;                  /* Last top-level S-Expression value */
  3394. extern char * lastsexp;                 /* Last S-Expression */
  3395. int sexprmax = 0;                       /* Longest result (for stats) */
  3396. int sexpdmax = 0;                       /* Max depth reached (for stats) */
  3397. int sexpdep  = 0;                       /* dosexp() recursion depth */
  3398. static int * sxrlen = NULL;             /* Result stack string sizes */
  3399. static char ** sxresult = NULL;         /* Result stack */
  3400.  
  3401. /*  s h o s e x p  --  Show S-Expression info  */
  3402.  
  3403. VOID
  3404. shosexp() {
  3405.     printf("\n");
  3406.     printf(" sexpression echo-result: %s\n",showooa(sexpecho));
  3407.     printf(" sexpression depth-limit: %d\n",sexpmaxdep);
  3408.     printf("\n");
  3409.     printf(" maximum depth reached:   %d\n",sexpdmax);
  3410.     printf(" longest result returned: %d\n",sexprmax);
  3411.     printf("\n");
  3412.     printf(" last sexpression:        %s\n",lastsexp ? lastsexp : "(none)");
  3413.     printf(" last value:              %s\n",sexpval ? sexpval : "(none)");
  3414.     printf("\n");
  3415. }
  3416.  
  3417.  
  3418. static char *
  3419. sexpdebug(s) char * s; {
  3420.     /* For debugging -- includes recursion depth in each debug entry */
  3421.     static char buf[64];
  3422.     ckmakmsg(buf,64,"dosexp[",ckitoa(sexpdep),"] ",s);
  3423.     return((char *)buf);
  3424. }
  3425.  
  3426. /*  d o s e x p  --  S-Expression Reader  */
  3427.  
  3428. /*  Returns value as string (empty, numeric, or non-numeric) */
  3429.  
  3430. char *
  3431. dosexp(s) char *s; {                    /* s = S-Expression */
  3432.     extern struct mtab *mactab;         /* Macro table */
  3433.     extern int maclvl, nmac;
  3434.     extern char *mrval[];
  3435.     extern int makestrlen;              /* (see makestr()) */
  3436.     struct stringarray * q = NULL;      /* cksplit() return type */
  3437.     char * p[SEXPMAX+1], ** p2;         /* List items (must be on stack) */
  3438.     char * line = NULL;                 /* For building macro argument list */
  3439.     int nosplit = 0;
  3440.     int linelen = 0;
  3441.     int linepos = 0;
  3442.     int quote = 0;                      /* LISP quote flag */
  3443.     char * s2;                          /* Workers */
  3444.     int kw, kwflags, mx = 0;
  3445.     int not = 0, truncate = 0, builtin = 0;
  3446.     int fpflag = 0, quit = 0, macro = 0;
  3447.     CK_OFF_T result = 0, i, j, k, x, n = 0;
  3448.     CKFLOAT fpj, fpresult = 0.0;        /* Floating-point results */
  3449.     int pflag = 0;                      /* Have predicate */
  3450.     int presult = 0;                    /* Predicate result */
  3451.     int mustfree = 0;                   /* If we malloc'd we must free */
  3452.  
  3453.     sexppv = -1;                        /* Predicate value */
  3454.     s2 = "";                            /* Default return value */
  3455.  
  3456.     if (++sexpdep > sexpmaxdep) {       /* Keep track of depth */
  3457.         printf("?S-Expression depth limit exceeded: %d\n",sexpmaxdep);
  3458.         sexprc++;
  3459.         debug(F111,sexpdebug("max depth exceeded"),s,sexprc);
  3460.     }
  3461.     if (sexpdep > sexpdmax)             /* For stats */
  3462.       sexpdmax = sexpdep;
  3463.  
  3464.     if (sexprc)                         /* Error, quit all levels */
  3465.       goto xdosexp;                     /* Always goto common exit point */
  3466.  
  3467.     debug(F111,sexpdebug("entry"),s,sexprc);
  3468.  
  3469.     if (!s) s = "";                     /* Null or empty arg */
  3470.  
  3471.     while (*s == SP) s++;               /* Strip leading spaces */
  3472.     if (!*s)                            /* so empty result */
  3473.       goto xdosexp;
  3474.  
  3475. /*
  3476.   Allocate result stack upon first use, or after it has been resized with
  3477.   SET SEXP DEPTH-LIMIT.
  3478. */
  3479.     if (!sxresult) {
  3480.         sxresult = (char **)malloc(sexpmaxdep * sizeof(char *));
  3481.         if (!sxresult) {
  3482.             printf("?Memory allocation failure - \"%s\"\n", s);
  3483.             sexprc++;
  3484.             goto xdosexp;
  3485.         }
  3486.         sxrlen = (int *)malloc(sexpmaxdep * sizeof(int));
  3487.         if (!sxrlen) {
  3488.             printf("?Memory allocation failure - \"%s\"\n", s);
  3489.             sexprc++;
  3490.             goto xdosexp;
  3491.         }
  3492.         for (i = 0; i < sexpmaxdep; i++) {
  3493.             sxresult[i] = NULL;         /* Result pointers */
  3494.             sxrlen[i] = 0;              /* Buffer sizes */
  3495.         }
  3496.     }
  3497.     s2 = s;                             /* s2 is the result pointer */
  3498.     k = 0;                              /* Length accumulator */
  3499.     if (s[0] == '(') {                  /* Starts with open paren? */
  3500.         while (*s2++) k++;              /* Get length */
  3501.         if (s[k-1] == ')') {            /* Strip outer parens if any */
  3502.             s[k-1] = NUL;
  3503.             s++;
  3504.             k -= 2;
  3505.             while (*s == SP) {          /* Strip leading spaces from result */
  3506.                 s++;
  3507.                 k--;
  3508.             }
  3509.             while (k > 0 && s[k-1] == SP) { /* And trailing spaces. */
  3510.                 s[k-1] = NUL;
  3511.                 k--;
  3512.             }
  3513.         }
  3514.         if (!*s) {                      /* If nothing remains */
  3515.             s2 = "";                    /* return empty result. */
  3516.             goto xdosexp;
  3517.         }
  3518.     }
  3519.     /* Break result up into "words" (an SEXP counts as a word) */
  3520.  
  3521.     p[0] = NULL;                        /* (We don't use element 0) */
  3522.     if (!*(s+1) || !*(s+2)) {           /* No need to call cksplit() */
  3523.         n = 1;                          /* if it's one or two chars. */
  3524.         p[1] = s;                       /* No need to malloc this either. */
  3525.     nosplit = 1;
  3526.         debug(F101,sexpdebug("nosplit"),"",n);
  3527.         if (s[0] == '(') {              /* () empty */
  3528.             s2 = "";
  3529.             goto xdosexp;
  3530.         }
  3531.     } else {
  3532.     nosplit = 0;
  3533.         q = cksplit(1,SEXPMAX,s,NULL,"\\%[]&$+-/=*^_@!{}/<>|.#~'`:;?",8,39,0);
  3534.         if (!q)
  3535.           goto xdosexp;
  3536.         n = q->a_size;                  /* Number of items */
  3537.         debug(F101,sexpdebug("split"),"",n);
  3538.         if (n < 0 || n > SEXPMAX) {     /* Check for too many */
  3539.             printf("?Too many operands: max = %d\n",SEXPMAX);
  3540.             sexprc++;
  3541.             goto xdosexp;
  3542.         }
  3543.         if (n == 0)                     /* None, result is NULL, done. */
  3544.           goto xdosexp;
  3545.         if (n == 1 && s[0] == '(') {    /* One but it's another SEXP */
  3546.             s2 = dosexp(s);
  3547.             goto xdosexp;
  3548.         }
  3549.         p2 = q->a_head;                 /* Point to result array. */
  3550.         for (i = 1; i <= n; i++) {      /* We must copy it because */
  3551.             p[i] = NULL;                /* recursive calls to dosexp() */
  3552.             if (p2[i])                  /* write over the same array */
  3553.               makestr(&(p[i]),p2[i]);
  3554.         }
  3555.         if (s[0] == '(') {              /* Operator is an S-Expression */
  3556.             s2 = dosexp(p[1]);          /* Replace it by its value */
  3557.             makestr(&(p[1]),s2);
  3558.         }
  3559.         mustfree++;                     /* Remember to free it */
  3560.     }
  3561.     debug(F110,sexpdebug("head"),p[1],0);
  3562.  
  3563.     if (n == 1 && p[1]) {
  3564.         if (*(p[1]) == '\047') {
  3565.             s2 = p[1];
  3566.             goto xdosexp;
  3567.         }
  3568.     }
  3569. /*
  3570.   This section sidesteps xlookup() of the most common operators.
  3571.   It's not necessary but it speeds up SEXP-heavy loops by about 10%.
  3572. */
  3573.     kwflags = 0;
  3574.     if (n > 0) {                        /* Look up the operator */
  3575.         s2 = p[1];                      /* Prelookup optimization... */
  3576.         if (!s2)
  3577.           s2 = "";
  3578.         if (!*s2)
  3579.           goto xdosexp;
  3580.         kw = 0;
  3581.         x = 0;
  3582.         if (isdigit(*s2)) {             /* Digit */
  3583.             x = -2;
  3584.  
  3585.         } else if (isalpha(*s2) && !*(s2+1)) { /* Single letter */
  3586.             x = -1;
  3587.  
  3588.         } else if (*s2 == 's' || *s2 == 'S') { /* SETQ */
  3589.             s2++;
  3590.             if (*s2 == 'e' || *s2 == 'E') {
  3591.                 s2++;
  3592.                 if (*s2 == 't' || *s2 == 'T') {
  3593.                     s2++;
  3594.                     if (*s2 == 'q' || *s2 == 'Q') {
  3595.                         if (!*(s2+1)) {
  3596.                             x = SX_SET;
  3597.                             kwflags = 0;
  3598.                             builtin = 1;
  3599.                         }
  3600.                     }
  3601.                 }
  3602.             }
  3603.         }
  3604.         if (!x) {
  3605.             if (!*(s2+1)) {             /* Common single-character ops */
  3606.                 if (*s2 == '+') {
  3607.                     x = SX_ADD;
  3608.                     kwflags = 0;
  3609.                     builtin = 1;
  3610.                 } else if (*s2 == '-') {
  3611.                     x = SX_SUB;
  3612.                     kwflags = 0;
  3613.                     builtin = 1;
  3614.                 } else if (*s2 == '*') {
  3615.                     x = SX_MUL;
  3616.                     kwflags = 0;
  3617.                     builtin = 1;
  3618.                 } else if (*s2 == '/') {
  3619.                     x = SX_DIV;
  3620.                     kwflags = SXF_TWO;
  3621.                     builtin = 1;
  3622.                 }
  3623.             }
  3624.             if (!x) {                   /* None of the above, look it up */
  3625.                 x = xlookup(sexpops,p[1],nsexpops,&kw);
  3626.         debug(F111,"XXX",p[1],x);
  3627.                 if (x > 0) {
  3628.                     kwflags = sexpops[kw].flgs;
  3629.                     builtin = 1;
  3630.                 }
  3631.             }
  3632.         }
  3633.     }
  3634.     /* If none of the above, check built-in constants */
  3635.  
  3636.     if (x == -1) {
  3637.         x = xlookup(sexpconsts,p[1],nsexpconsts,&kw);
  3638.         if (x > 0) {
  3639.             switch (x) {
  3640.               case SXC_NIL:
  3641.                 s2 = "";
  3642.                 goto xdosexp;
  3643.               case SXC_PI:
  3644.                 s2 = math_pi;
  3645.                 goto xdosexp;
  3646.               case SXC_T:
  3647.                 s2 = "1";
  3648.                 goto xdosexp;
  3649.             }
  3650.         }
  3651.     }
  3652.     if (n == 1) {                       /* Not an expression */
  3653.         if (builtin) {                  /* Built-in operand? */
  3654.             switch (x) {                /* Operators with default values */
  3655.               case SX_EVA:
  3656.                 s2 = "";
  3657.                 goto xdosexp;
  3658.               case SX_MUL:              /* (*) */
  3659.                 s2 = sexpval ? sexpval : "1";
  3660.                 goto xdosexp;
  3661.               case SX_AND:              /* (AND) */
  3662.               case SX_BWA:              /* Bitwise (&) */
  3663.                 result++;
  3664.               case SX_LOR:              /* (OR) */
  3665.               case SX_BWO:              /* Bitwise (|) */
  3666.               case SX_ADD:              /* (+) */
  3667.               case SX_SUB:              /* (-) */
  3668.                 s2 = result ? "1" : "0";
  3669.                 goto xdosexp;
  3670.             }
  3671.  
  3672.         } else {                        /* Not a built-in operand */
  3673.             char * p1;
  3674.             p1 = p[1];
  3675.             while (*p1 == SP) p1++;
  3676.             if (!isalpha(*p1)) {
  3677.                 if (xxfloat(p1,0) > 0) { /* Is it a number? */
  3678.                     s2 = p1;
  3679.                     while (*s2 == '+') s2++;
  3680.                 } else if (*p1 == '(') { /* An S-Expression? */
  3681.  
  3682. #ifdef COMMENT
  3683.                     s2 = dosexp(s2);
  3684. #else
  3685.                     s2 = dosexp(p1);
  3686. #endif /* COMMENT */
  3687.                 }
  3688.                 goto xdosexp;
  3689.             } else if (x < 1) {         /* Is it a variable? */
  3690.                 j = mxlook(mactab,p[1],nmac); /* Look it up */
  3691.                 debug(F111,sexpdebug("n==1 mxlook"),p[1],j);
  3692.                 s2 = (j > -1) ? mactab[j].mval : "";
  3693.                 if (!s2) s2 = "";
  3694.                 if (xxfloat(s2,0) > 0)  /* Macro value is a number */
  3695.                   goto xdosexp;
  3696.                 if (j > -1) {           /* It's a macro */
  3697.                     mx = j;
  3698.                     x = j;              /* whose definition is not numeric */
  3699.                     if (*s2 == '(') {   /* Is it an S-Expression? */
  3700.                         /* We have to allocate memory on the stack */
  3701.                         /* to call ourselves recursively on it */
  3702.                         /* otherwise we'll wipe out the macro definition */
  3703.                         char * s3 = NULL;
  3704.                         /* int k = 0; */
  3705.                         s3 = s2;
  3706.                         while (*s3++) k++;
  3707.                         s3 = (char *)malloc(k + 4);
  3708.                         if (s3) {
  3709.                             strcpy(s3,s2);   /* SAFE */
  3710.                             s2 = dosexp(s3); /* Evaluate it */
  3711.                             free(s3);
  3712.                         } else {
  3713.                             printf("?Memory allocation failure - \"%s\"\n",s2);
  3714.                             sexprc++;
  3715.                         }
  3716.                         goto xdosexp;
  3717.                     }
  3718.                     if (*s2 == '\047') {
  3719.                         s2++;
  3720. #ifdef COMMENT
  3721.             /* Dumps core if petty optimization was taken */
  3722.                         makestr(&(p[1]),s2);
  3723. #else
  3724.             if (!nosplit && p[1]) free(p[1]);
  3725.             p[1] = (char *)malloc((int)strlen(s2) + 1);
  3726. #endif /* COMMENT */
  3727.                         s2 = p[1];
  3728.             if (!s2) s2 = "";
  3729.                         if (*s2 == '(') {
  3730.                             if (s2[makestrlen-1] == ')') {
  3731.                                 s2[makestrlen-1] = NUL;
  3732.                                 s2++;
  3733.                             }
  3734.                         }
  3735.                         debug(F110,sexpdebug("'A"),s2,0);
  3736.                         goto xdosexp;
  3737.                     }
  3738.                     macro++;            /* Not an S-Expression */
  3739.                 } else {                /* Not found in macro table */
  3740.                     printf("?Not defined - \"%s\"\n", p[1]);
  3741.                     sexprc++;
  3742.                     goto xdosexp;
  3743.                 }
  3744.             }
  3745.         }
  3746.     } else if (x < 1 && !macro) {       /* n > 1 and not a built-in operator */
  3747.         x = mxlook(mactab,p[1],nmac);   /* See if it's a macro */
  3748.         debug(F111,sexpdebug("n!=1 mxlook"),p[1],x);
  3749.         if (x < 0) {
  3750.             printf("?Invalid operand - \"%s\"\n",p[1]);
  3751.             sexprc++;
  3752.             goto xdosexp;
  3753.         }
  3754.         mx = x;
  3755.         macro++;
  3756.     }
  3757.     if (builtin) {                      /* Built-in operator... */
  3758.         if (kwflags) {
  3759.             int flgs;
  3760.             if ((flgs = (kwflags & (SXF_ONE|SXF_TWO)))) {
  3761.                 switch (flgs) {
  3762.                   case (SXF_ONE|SXF_TWO):
  3763.                     if (n < 2) {
  3764.                         printf("?Too few operands - \"%s\"\n",s);
  3765.                         sexprc++;
  3766.                         goto xdosexp;
  3767.                     }
  3768.                     break;
  3769.                   case SXF_TWO:
  3770.                     if (n < 3) {
  3771.                         printf("?Too few operands - \"%s\"\n",s);
  3772.                         sexprc++;
  3773.                         goto xdosexp;
  3774.                     }
  3775.                     break;
  3776.                   case SXF_ONE:
  3777.                     if (n != 2) {
  3778.                         printf("?Too %s operands - \"%s\"\n",
  3779.                                (n > 2) ? "many" : "few", s);
  3780.                         sexprc++;
  3781.                         goto xdosexp;
  3782.                     }
  3783.                 }
  3784.             }
  3785.             if (kwflags & SXF_PRE) {    /* Predicate? */
  3786.                 pflag = 1;
  3787.                 presult = 1;
  3788.             }
  3789.             if (kwflags & SXF_FLO)      /* Operator requires floating point */
  3790.               fpflag++;                 /* Force it */
  3791.         }
  3792.         if (x == SX_SET || x == SX_LET || /* Assignment is special */
  3793.             x == SX_INC || x == SX_DEC) {
  3794.             int rc;
  3795.             char c, * m, * s3;
  3796.             if (n == 1) {
  3797.                 s2 = "";
  3798.                 goto xdosexp;
  3799.             }
  3800.             s2 = NULL;
  3801.             for (i = 1; i < n; i += 2) { /* Loop thru operand pairs */
  3802.                 rc = 0;
  3803.                 s3 = p[i+1];
  3804.                 c = *s3;
  3805.                 debug(F110,sexpdebug("target p"),s3,0);
  3806.  
  3807.                 /* Make sure target doesn't have multiple words */
  3808.                 while (*s3) { if (*s3 < '!') { rc = 1; break; }; s3++; }
  3809.                 s3 = p[i+1];
  3810.                 if (rc) {               /* If it does it must have been */
  3811.                     char * s4;          /* an SEXP so evaluate it */
  3812.                     s3 = dosexp(s3);
  3813.                     s4 = s3;
  3814.                     rc = 0;
  3815.                     while (*s4) { if (*s4 < '!') { rc = 1; break; }; s4++; }
  3816.                     if (rc == 0) makestr(&(p[i+1]),s3);
  3817.                 }
  3818.  
  3819.                 /* And that it's not a number, etc. */
  3820.                 if (rc > 0 || isdigit(c) || c == '(') {
  3821.                     printf("?Invalid assignment - \"%s\"\n",s);
  3822.                     sexprc++;
  3823.                     goto xdosexp;
  3824.                 } else if (isalpha(c)) {
  3825.                     rc = xlookup(sexpconsts,s3,nsexpconsts,NULL);
  3826.                     if (rc > 0) {
  3827.                         printf("?Assignment to constant - \"%s\"\n",s);
  3828.                         sexprc++;
  3829.                         goto xdosexp;
  3830.                     }
  3831.                 }
  3832.  
  3833.                 /* If ++ or --, get current value of variable */
  3834.                 if (x == SX_INC || x == SX_DEC) {
  3835.                     int ok = 1;
  3836.                     char buf[32];
  3837.                     if (c == CMDQ) {    /* A backslash variable */
  3838.                         int n = 32;
  3839.                         char * s = buf;
  3840.                         buf[0] = NUL;
  3841.                         if (zzstring(s3,&s,&n) < 0 || !buf[0])
  3842.                           ok = 0;
  3843.                         s2 = buf;
  3844.                     } else {            /* A macro */
  3845.                         if ((k = mxlook(mactab,s3,nmac)) < 0)
  3846.                           ok = 0;
  3847.                         else
  3848.                           s2 = mactab[k].mval;
  3849.                     }
  3850.                     if (!ok) {
  3851.                         printf("?Not defined - \"%s\"\n",p[i+1]);
  3852.                         sexprc++;
  3853.                         goto xdosexp;
  3854.                     }
  3855.                     if (!s2) s2 = "";
  3856.                     k = xxfloat(s2,0);
  3857.                     if (k < 1) {
  3858.                         printf("?Not numeric - \"%s\"\n",p[i+1]);
  3859.                         sexprc++;
  3860.                         goto xdosexp;
  3861.                     }
  3862.                     while (*s2 == '+') s2++;
  3863.                     result = ckatofs(s2);
  3864.                     fpresult = floatval;
  3865.                     if (k > 1 || fpresult != result)
  3866.                       fpflag++;
  3867.                 }
  3868.                 if (n < i+2) {          /* Variable with no value */
  3869.                     s2 = "";
  3870.                     if (x == SX_SET || x == SX_LET) {
  3871.                         delmac(p[i+1],1); /* Delete the variable */
  3872.                         break;
  3873.                     } else {
  3874.                         s2 = "1";
  3875.                     }
  3876.                 } else {                /* Variable with value */
  3877.                     k = xxfloat(p[i+2],0); /* Is it a number? */
  3878.                     if (k > 0) {
  3879.                         s2 = p[i+2];
  3880.                         while (*s2 == '+') s2++;
  3881.                     } else {
  3882.                         s2 = dosexp(p[i+2]); /* Have value, evaluate it */
  3883.                         if (sexprc) goto xdosexp;
  3884.                         if (!s2) s2 = "";
  3885.                         if (!*s2 && (x == SX_INC || x == SX_DEC))
  3886.                           continue;
  3887.                     }
  3888.                 }
  3889.                 if (x == SX_INC || x == SX_DEC) {
  3890.                     k = xxfloat(s2,0);
  3891.                     if (k < 1) {
  3892.                         printf("?Not numeric - \"%s\"\n",s2);
  3893.                         sexprc++;
  3894.                         goto xdosexp;
  3895.                     }
  3896.                     while (*s2 == '+') s2++;
  3897.                     j = ckatofs(s2);
  3898.                     if (k > 1) {
  3899.                         fpj = floatval;
  3900.                         fpflag++;
  3901.                     } else {
  3902.                         fpj = (CKFLOAT)j;
  3903.                     }
  3904.                     if (x == SX_INC) {
  3905.                         result += j;
  3906.                         fpresult += fpj;
  3907.                     } else if (x == SX_DEC) {
  3908.                         result -= j;
  3909.                         fpresult -= fpj;
  3910.                     }
  3911. #ifdef FNFLOAT
  3912.                     if (result != fpresult) fpflag++;
  3913. #endif    /* FNFLOAT */
  3914.                     s2 = fpflag ? fpformat(fpresult,0,0) : ckfstoa(result);
  3915.                 }
  3916.                 if (x == SX_LET && cmdlvl > 0) /* LET makes var local */
  3917.                   addlocal(p[i+1]);
  3918.                 if ((rc = addmac(p[i+1],s2)) < 0) { /* Add the value */
  3919.                     switch (rc) {
  3920.                       case -3: m = "Array not declared"; break;
  3921.                       case -2: m = "Subscript out of range"; break;
  3922.                       case -4: m = "Out of memory"; break;
  3923.                       default: m = "Error creating variable";
  3924.                     }
  3925.                     printf("?%s - \"%s\"\n",m,s);
  3926.                     sexprc++;
  3927.                     goto xdosexp;
  3928.                 }
  3929.                 if (s2) result = ckatofs(s2);
  3930.             }
  3931.             goto xdosexp;
  3932.         } else if (x == SX_IFC) {               /* Conditional expression */
  3933.             int true = 0;
  3934.             if (n > 4) {
  3935.                 printf("?Too many operands: IF - \"%s\"\n",s);
  3936.                 sexprc++;
  3937.                 goto xdosexp;
  3938.             }
  3939.             s2 = dosexp(p[2]);
  3940.             if (sexprc) goto xdosexp;
  3941.             if (s2) {
  3942.                 j = ckatofs(s2);
  3943.                 if (xxfloat(s2,0) == 2) {
  3944.                     fpflag++;
  3945.                     fpresult = (CKFLOAT)result;
  3946.                     fpj = floatval;
  3947.                 } else {
  3948.                     fpj = atof(s2);
  3949.                 }
  3950.                 true = ((fpj != 0.0) ? 1 : 0);
  3951.             }
  3952.             if (!true && n < 4) {
  3953.                 s2 = NULL;
  3954.             } else {
  3955.                 s2 = dosexp(true ? p[3] : p[4]);
  3956.                 if (sexprc) goto xdosexp;
  3957.                 j = s2 ? ckatofs(s2) : 0;
  3958.                 if (xxfloat(s2,0) == 2) {
  3959.                     fpflag++;
  3960.                     fpresult = (CKFLOAT)result;
  3961.                     fpj = floatval;
  3962.                 } else {
  3963.                     fpj = s2 ? atof(s2) : 0.0;
  3964.                 }
  3965.                 fpresult = fpj;
  3966.                 result = j;
  3967.             }
  3968.             goto xdosexp;
  3969.         } else if (x == SX_QUO) {
  3970. #ifndef COMMENT
  3971.             int xx;
  3972.             xx = strlen(p[2]);
  3973.             p[3] = (char *)malloc(xx+4);
  3974.             s2 = p[3];
  3975.             ckmakmsg(p[3],xx+4,"'(",p[2],")",NULL);
  3976.             n++;
  3977. #else
  3978.             s2 = p[2];
  3979. #endif /* COMMENT */
  3980.             goto xdosexp;
  3981.         } else if (x == SX_STR) {
  3982.             int xx;
  3983.             s2 = dosexp(p[2]);
  3984.             if (sexprc) goto xdosexp;
  3985.             xx = strlen(s2);
  3986.             p[3] = (char *)malloc(xx+4);
  3987.             ckmakmsg(p[3],xx+4,"'(",s2,")",NULL);
  3988.             s2 = p[3];
  3989.             n++;
  3990.             goto xdosexp;
  3991.         }
  3992.     }
  3993.     /* Arithmetic operator or macro - Loop thru operands */
  3994.  
  3995.     quit = 0;                           /* Short-circuit flag. */
  3996.     if (macro && n > 1) {               /* If operator is a macro */
  3997.         if (!line) {                    /* allocate local buffer for */
  3998.             line = (char *)malloc(SXMLEN); /* the evaluated argument list. */
  3999.             if (!line) {
  4000.                 printf("?Memory allocation failure - \"%s\"\n",p[1]);
  4001.                 sexprc++;
  4002.                 goto xdosexp;
  4003.             }
  4004.             linelen = SXMLEN;
  4005.             /* debug(F101,"dosexp macro arg buffer","",linelen); */
  4006.         }
  4007.         linepos = 0;
  4008.         line[linepos] = NUL;
  4009.     }
  4010.     for (i = 1; ((i < n) && !sexprc && !quit); i++) { /* Loop thru operands */
  4011.         quote = 0;
  4012.         s2 = p[i+1];                    /* Get operand */
  4013.         if (!s2) s2 = "";
  4014. #ifdef COMMENT
  4015.         if (*s2 == '\047') {            /* Is it quoted? */
  4016.             debug(F110,sexpdebug("'B"),s2,0);
  4017.             s2++;                       /* Space past the quote */
  4018.             quote++;
  4019.             if (*s2 == '(') {           /* Quoted S-Expression? */
  4020.                 char c4, * s4 = s2+1;   /* Strip outer parens */
  4021.                 while ((c4 = *s4++)) {
  4022.                     if (c4 == ')' && !*s4) {
  4023.                         s2++;
  4024.                         *(s4-1) = NUL;
  4025.                         break;
  4026.                     }
  4027.                 }
  4028.             }
  4029.             debug(F110,sexpdebug("'C"),s2,0);
  4030.  
  4031.         } else {                        /* Not quoted */
  4032.             s2 = dosexp(p[i+1]);        /* evaluate it */
  4033.             if (sexprc) goto xdosexp;
  4034.             if (!s2) s2 = "";
  4035.             if (!macro && x == SX_EVA)
  4036.               continue;
  4037.         }
  4038. #else
  4039.         if (*s2 != '\047') {            /* Is it quoted? */
  4040.             s2 = dosexp(p[i+1]);        /* No, evaluate it */
  4041.             if (sexprc) goto xdosexp;
  4042.             if (!s2) s2 = "";
  4043.             if (!macro && x == SX_EVA)
  4044.               continue;
  4045.         }
  4046.         if (*s2 == '\047') {            /* Is result quoted? */
  4047.             debug(F110,sexpdebug("'B"),s2,0);
  4048.             s2++;                       /* Space past the quote */
  4049.             quote++;
  4050.             if (*s2 == '(') {           /* Quoted S-Expression? */
  4051.                 char c4, * s4 = s2+1;   /* Strip outer parens */
  4052.                 while ((c4 = *s4++)) {
  4053.                     if (c4 == ')' && !*s4) {
  4054.                         s2++;
  4055.                         *(s4-1) = NUL;
  4056.                         break;
  4057.                     }
  4058.                 }
  4059.             }
  4060.             debug(F110,sexpdebug("'C"),s2,0);
  4061.         }
  4062. #endif /* COMMENT */
  4063.         if (macro) {
  4064.             debug(F111,sexpdebug("macro arg"),s2,i);
  4065.             if (!*s2) quote++;
  4066.             if (!quote) {
  4067.                 register char c4, * s4 = s2;
  4068.                 while ((c4 = *s4++)) if (c4 == SP) { quote++; break; }
  4069.             }
  4070.             if (quote) line[linepos++] = '{';
  4071.             while ((line[linepos++] = *s2++)) {
  4072.                 if (linepos > linelen - 3) {
  4073.                     char * tmp = NULL;
  4074.                     line[linepos] = NUL;
  4075.                     linelen += SXMLEN;
  4076.                     tmp = (char *) malloc(linelen);
  4077.                     if (!tmp) {
  4078.                         printf("?Memory re-allocation failure - \"%s...\"\n",
  4079.                                line);
  4080.                         sexprc++;
  4081.                         goto xdosexp;
  4082.                     }
  4083.                     strcpy(tmp,line);
  4084.                     free(line);
  4085.                     line = tmp;
  4086.                 }
  4087.             }
  4088.             linepos--;                  /* Back up over NUL */
  4089.             if (quote)
  4090.               line[linepos++] = '}';    /* End quote group */
  4091.             line[linepos++] = SP;       /* add a space */
  4092.             line[linepos] = NUL;        /* and a NUL */
  4093.             continue;
  4094.         }
  4095.         if (!quote) {                   /* Built-in operator... */
  4096.             s2 = dosexp(s2);
  4097.             if (sexprc) goto xdosexp;
  4098.             if (!s2) s2 = "";
  4099.         }
  4100.         if (x == SX_EVA)
  4101.           continue;
  4102.  
  4103.         if (!*s2) {
  4104.             /* An empty value is not a legal number */
  4105.             /* but it is a legal truth value */
  4106.             if (x != SX_AND && x != SX_LOR && x != SX_NOT) {
  4107.                 printf("?Not Numeric - \"%s\"\n",p[i+1]);
  4108.                 sexprc++;
  4109.                 goto xdosexp;
  4110.             }
  4111.             j = 0;
  4112.             fpj = 0.0;
  4113.         } else {
  4114.             j = ckatofs(s2);
  4115.             /* Switch to floating-point upon encountering any f.p. arg */
  4116.             /* OR... if integer is too big */
  4117.             if (!fpflag) if (xxfloat(s2,0) == 2)
  4118.               fpflag++;
  4119.             fpj = atof(s2);
  4120.         }
  4121.         if (i == 1) {                   /* Initial result is first operand */
  4122.             result = (n == 2 && x == SX_SUB) ? 0-j : j;
  4123.             fpresult = (n == 2 && x == SX_SUB) ? -fpj : fpj;
  4124.         if ((x == SX_AND && result == 0) ||    /* Short circuit */
  4125.         (x == SX_LOR && result != 0))
  4126.           quit++;
  4127.             if (!(kwflags & SXF_ONE))   /* Command with single arg */
  4128.               continue;
  4129.         }
  4130.         if (x == SX_MOD || x == SX_DIV) {
  4131.             if (!result)
  4132.               fpflag++;
  4133.             if (!fpj) {
  4134.                 printf("?Divide by zero - \"%s\"\n",cmdbuf);
  4135.                 sexprc++;
  4136.                 goto xdosexp;
  4137.             }
  4138.         }
  4139.         switch (x) {                    /* Accumulate result */
  4140.  
  4141.           case SX_EVA:                  /* EVAL */
  4142.             result = j;
  4143.             fpresult = fpj;
  4144.             break;
  4145.  
  4146.           case SX_ADD:                  /* + */
  4147.             result += j;
  4148.             fpresult += fpj;
  4149. #ifdef FNFLOAT
  4150.             if (result != fpresult)
  4151.               fpflag++;
  4152. #endif    /* FNFLOAT */
  4153.             break;
  4154.  
  4155.           case SX_SUB:                  /* - */
  4156.             result -= j;
  4157.             fpresult -= fpj;
  4158. #ifdef FNFLOAT
  4159.             if (result != fpresult)
  4160.               fpflag++;
  4161. #endif    /* FNFLOAT */
  4162.             break;
  4163.  
  4164.           case SX_MUL:                  /* * */
  4165.             result *= j;
  4166.             fpresult *= fpj;
  4167. #ifdef FNFLOAT
  4168.             if (result != fpresult)
  4169.               fpflag++;
  4170. #endif    /* FNFLOAT */
  4171.             break;
  4172.  
  4173.           case SX_AND:                  /* AND */
  4174.             result = result && j;
  4175.             if (!result) quit++;
  4176.             fpresult = fpresult && fpj;
  4177.             break;
  4178.  
  4179.           case SX_LOR:                  /* OR */
  4180.             result = result || j;
  4181.             if (!result) quit++;
  4182.             fpresult = fpresult || fpj;
  4183.             break;
  4184.  
  4185.           case SX_MOD:                  /* Modulus */
  4186.             result = result % j;
  4187. #ifdef FNFLOAT
  4188.             fpresult = (CKFLOAT)fmod(fpresult,fpj);
  4189.             if (result != fpresult)
  4190.               fpflag++;
  4191. #else
  4192.             fpresult = result;
  4193. #endif /* FNFLOAT */
  4194.             break;
  4195.  
  4196.           case SX_DIV:                  /* / */
  4197.             result /= j;
  4198.             fpresult /= fpj;
  4199. #ifdef FNFLOAT
  4200.             if (result != fpresult)
  4201.               fpflag++;
  4202. #endif    /* FNFLOAT */
  4203.             break;
  4204.  
  4205.           case SX_AEQ:                  /* Test for equality */
  4206.             if (fpflag) {
  4207.                 if (fpresult != fpj)
  4208.                   presult = 0;
  4209.             } else {
  4210.                 if (result != j)
  4211.                   presult = 0;
  4212.             }
  4213.             break;
  4214.  
  4215.           case SX_NEQ:                  /* Test for ineqality */
  4216.             if (fpflag) {
  4217.                 if (fpresult == fpj)
  4218.                   presult = 0;
  4219.             } else {
  4220.                 if (result == j)
  4221.                   presult = 0;
  4222.             }
  4223.             break;
  4224.  
  4225.           case SX_ALE:                  /* Arithmetic less-equal */
  4226.             if (fpflag) {
  4227.                 if (fpj < fpresult)
  4228.                   presult = 0;
  4229.                 fpresult = fpj;
  4230.             } else {
  4231.                 if (j < result)
  4232.                   presult = 0;
  4233.                 result = j;
  4234.             }
  4235.             break;
  4236.  
  4237.           case SX_ALT:                  /* Arithmetic less-than */
  4238.             if (fpflag) {
  4239.                 if (fpj <= fpresult)
  4240.                   presult = 0;
  4241.                 fpresult = fpj;
  4242.             } else {
  4243.                 if (j <= result)
  4244.                   presult = 0;
  4245.                 result = j;
  4246.             }
  4247.             break;
  4248.  
  4249.           case SX_AGT:                  /* Arithmetic greater-than */
  4250.             if (fpflag) {
  4251.                 if (fpj >= fpresult)
  4252.                   presult = 0;
  4253.                 fpresult = fpj;
  4254.             } else {
  4255.                 if (j >= result)
  4256.                   presult = 0;
  4257.                 result = j;
  4258.             }
  4259.             break;
  4260.  
  4261.           case SX_AGE:                  /* Arithmetic greater-equal */
  4262.             if (fpflag) {
  4263.                 if (fpj > fpresult)
  4264.                   presult = 0;
  4265.                 fpresult = fpj;
  4266.             } else {
  4267.                 if (j > result)
  4268.                   presult = 0;
  4269.                 result = j;
  4270.             }
  4271.             break;
  4272.  
  4273.           case SX_POW:                  /* Raise to power */
  4274. #ifdef FNFLOAT
  4275.             {
  4276.                 double dummy;
  4277.                 if (!fpj) {
  4278.                     fpresult = 1.0;
  4279.                 } else if ((!fpresult && fpj <= 0.0)) {
  4280.                     printf("?Divide by zero - \"%s\"\n",cmdbuf);
  4281.                     sexprc++;
  4282.                     goto xdosexp;
  4283.                 } else if (fpresult < 0.0 && modf(fpj,&dummy)) {
  4284.                     printf("?Domain error - \"%s\"\n",cmdbuf);
  4285.                     sexprc++;
  4286.                     goto xdosexp;
  4287.                 } else {
  4288.                     fpresult = (CKFLOAT)pow(fpresult,fpj);
  4289.                 }
  4290.             }
  4291. #endif /* FNFLOAT */
  4292.             if (j == 0) {
  4293.                 result = 1;
  4294.             } else {
  4295.                 CK_OFF_T z, sign = 0;
  4296.                 if (j < 0) {
  4297.                     if (result == 0) {
  4298.                         printf("?Divide by zero - \"%s\"\n",cmdbuf);
  4299.                         sexprc++;
  4300.                         goto xdosexp;
  4301.                     }
  4302.                     j = 0 - j;
  4303.                     sign++;
  4304.                 }
  4305.                 z = result;
  4306.                 while (--j > 0)
  4307.                   result *= z;
  4308.                 if (sign)
  4309.                   result = 1 / result;
  4310.             }
  4311. #ifdef FNFLOAT
  4312.             if (result != fpresult)
  4313.               fpflag++;
  4314. #endif    /* FNFLOAT */
  4315.             break;
  4316.  
  4317. #ifdef FNFLOAT
  4318.           case SX_EXP:                  /* e to the given power */
  4319.             fpresult = (CKFLOAT) exp(fpj);
  4320.             break;
  4321.  
  4322.           case SX_LGN:                  /* Natural log */
  4323.           case SX_LGX:                  /* Log base 10 */
  4324.           case SX_SQR:                  /* Square root */
  4325.             if (fpj < 0.0) {
  4326.                 printf("?Argument out of range - \"%s\"\n",cmdbuf);
  4327.                 sexprc++;
  4328.                 goto xdosexp;
  4329.             }
  4330.             if (x == SX_SQR)
  4331.               fpresult = (CKFLOAT) sqrt(fpj);
  4332.             else if (x == SX_LGN)
  4333.               fpresult = (CKFLOAT) log(fpj);
  4334.             else
  4335.               fpresult = (CKFLOAT) log10(fpj);
  4336.             break;
  4337.  
  4338.           case SX_SIN:                  /* sine */
  4339.             fpresult = (CKFLOAT) sin(fpj);
  4340.             break;
  4341.  
  4342.           case SX_COS:                  /* cosine */
  4343.             fpresult = (CKFLOAT) cos(fpj);
  4344.             break;
  4345.  
  4346.           case SX_TAN:                  /* tangent */
  4347.             fpresult = (CKFLOAT) tan(fpj);
  4348.             break;
  4349. #endif /* FNFLOAT */
  4350.  
  4351.           case SX_CEI:                  /* Ceiling */
  4352.             if (j != fpj)
  4353.               if (fpj > 0.0)
  4354.                 fpj += 1.0;
  4355.             fpresult = fpj;
  4356.             fpflag = 1;
  4357.             truncate = 1;
  4358.             break;
  4359.  
  4360.           case SX_FLR:                  /* Floor */
  4361.             if (j != fpj)
  4362.               if (fpj < 0.0)
  4363.                 fpj -= 1.0;
  4364.             fpresult = fpj;
  4365.             fpflag = 1;
  4366.             truncate = 1;
  4367.             break;
  4368.  
  4369.           case SX_TRU:                  /* Truncate */
  4370.             fpresult = fpj;
  4371.             fpflag = 1;
  4372.             truncate = 1;
  4373.             break;
  4374.  
  4375.           case SX_ROU:                  /* Round */
  4376.             if (fpj > 0.0)
  4377.               fpj += 0.5;
  4378.             else if (fpj < 0.0)
  4379.               fpj -= 0.5;
  4380.             fpresult = fpj;
  4381.             fpflag = 1;
  4382.             truncate = 1;
  4383.             break;
  4384.  
  4385.           case SX_ABS:                  /* Absolute value */
  4386.             result = (j < 0) ? 0 - j : j;
  4387. #ifdef FNFLOAT
  4388.             fpresult = (fpj < 0.0) ? 0.0 - fpj : fpj;
  4389.             if (result != fpresult)
  4390.               fpflag++;
  4391. #endif    /* FNFLOAT */
  4392.             break;
  4393.  
  4394.           case SX_MAX:                  /* Max */
  4395.             if (j != fpj)
  4396.               fpflag++;
  4397.             if (fpflag) {
  4398.                 if (fpj > fpresult)
  4399.                   fpresult = fpj;
  4400.             } else
  4401.               if (j > result)
  4402.                 result = j;
  4403.             break;
  4404.  
  4405.           case SX_MIN:                  /* Min */
  4406.             if (j != fpj)
  4407.               fpflag++;
  4408.             if (fpflag) {
  4409.                 if (fpj < fpresult)
  4410.                   fpresult = fpj;
  4411.             } else
  4412.               if (j < result)
  4413.                 result = j;
  4414.             break;
  4415.  
  4416.           case SX_FLO:                  /* Float */
  4417.             fpflag++;
  4418.             fpresult = result;
  4419.             fpj = j;
  4420.             break;
  4421.  
  4422.           case SX_NOT:                  /* NOT (reverse truth value) */
  4423.             fpflag = 0;
  4424.             not++;
  4425.             break;
  4426.  
  4427.           case SX_BWA:                  /* Bitwise AND */
  4428.             fpflag = 0;
  4429.             result &= j;
  4430.             break;
  4431.  
  4432.           case SX_BWO:                  /* Bitwise OR */
  4433.             fpflag = 0;
  4434.             result |= j;
  4435.             break;
  4436.  
  4437.           case SX_BWX:                  /* Bitwise XOR */
  4438.           case SX_XOR:                  /* Logical XOR */
  4439.             if (n > 3) {
  4440.                 printf("?Too many operands - \"%s\"\n",s);
  4441.                 sexprc++;
  4442.                 goto xdosexp;
  4443.             }
  4444.             fpflag = 0;
  4445.             if (x == SX_BWX) {
  4446.                 result ^= j;
  4447.             } else {
  4448.                 result = (result && !j) || (!result && j);
  4449.                 if (result) result = 1;
  4450.             }
  4451.             break;
  4452.  
  4453.           case SX_BWN:                  /* Bitwise Not */
  4454.             fpflag = 0;
  4455.             result = ~result;
  4456.             break;
  4457.  
  4458.           default:
  4459.             printf("BAD OP [%s]\n",p[1]);
  4460.             sexprc++;
  4461.         }
  4462.     }
  4463.     if (!pflag)                         /* Not a predicate */
  4464.       sexppv = -1;                      /* So unset this */
  4465.  
  4466.   /* domacro: */
  4467.  
  4468.     if (macro) {                        /* User-defined macro */
  4469.         extern int fsexpflag;           /* (see fneval():ckuus4.c) */
  4470.         int lookagain = 0;              /* Maybe the macro table changed */
  4471.         if (mactab[mx].kwd) {           /* Check and see */
  4472.             if (ckstrcmp(mactab[mx].kwd,p[1],-1,0))
  4473.               lookagain++;
  4474.         } else
  4475.           lookagain++;
  4476.         if (lookagain) {                /* The table changed */
  4477.             mx = mxlook(mactab,p[1],nmac); /* Get the macro's new index */
  4478.             debug(F111,sexpdebug("macro moved"),p[1],mx);
  4479.             if (mx < 0) {                  /* Yikes! */
  4480.                 printf("?Macro disappeared! - \"%s\"\n",p[1]);
  4481.                 sexprc++;
  4482.                 goto xdosexp;
  4483.             }
  4484.         }
  4485.         debug(F111,sexpdebug("macro mx"),mactab[mx].kwd,mx);
  4486.         if (fsexpflag) {                /* If embedded in a function call */
  4487.             if (cmpush() > -1) {        /* get a new copy of the parsing */
  4488.                 extern int ifc;         /* environment, */
  4489.                 int k, ifcsav = ifc;    /* save the IF state */
  4490.                 dodo(mx,line,0);        /* Set up the macro */
  4491.                 k = parser(1);          /* Call the parser to execute it */
  4492.                 cmpop();                /* Pop back to previous level */
  4493.                 ifc = ifcsav;           /* restore IF state */
  4494.                 if (k == 0)             /* If no error */
  4495.                   s2 = mrval[maclvl+1]; /* get return value, if any */
  4496.                 if (!s2) s2 = "";
  4497.                 debug(F110,sexpdebug("macro return"),s2,0);
  4498.             } else {
  4499.                 printf("?Resources exhausted - \"%s\"\n",s);
  4500.                 sexprc++;
  4501.             }
  4502.         } else {                        /* Not embedded in a function call */
  4503.             dodo(mx,line,0);            /* As above but without cmpush/pop() */
  4504.             k = parser(1);
  4505.             if (k == 0)
  4506.               s2 = mrval[maclvl+1];
  4507.             if (!s2) s2 = "";
  4508.         }
  4509.     } else if (pflag) {                 /* Predicate */
  4510.         if (not) presult = presult ? 0 : 1;
  4511.         sexppv = presult;               /* So set predicate value (0 or 1) */
  4512.         s2 = presult ? "1" : "0";
  4513.     } else if (fpflag) {                /* Result is floating-point */
  4514.         if (not) fpresult = fpresult ? 0.0 : 1.0;
  4515.         s2 = fpformat(fpresult,0,0);
  4516.     } else if (x != SX_EVA) {
  4517.         if (not) result = result ? 0 : 1;
  4518.         s2 = ckfstoa(result);
  4519.     }
  4520.  
  4521. /* Common exit point.  Always come here to exit. */
  4522.  
  4523.   xdosexp:
  4524.  
  4525.     if (!s2) s2 = "";
  4526.     if (!sexprc && s2) {                /* Have a result */
  4527.         char * sx;
  4528.         char * q2 = s2; int xx = 0;
  4529.         if (*s2) {
  4530.             while (*q2++) xx++;         /* Get length */
  4531.             if (xx > sexprmax)          /* (stats) */
  4532.               sexprmax = xx;
  4533.         } else
  4534.           xx = 0;
  4535.         if (xx > sxrlen[sexpdep] || !sxresult[sexpdep]) {
  4536.             int k;
  4537.             k = xx + xx / 4;
  4538.             if (k < 32) k = 32;
  4539.             if (sxresult[sexpdep])
  4540.               free(sxresult[sexpdep]);
  4541.             if ((sxresult[sexpdep] = (char *)malloc(k))) {
  4542.                 sxrlen[sexpdep] = k;
  4543.             } else {
  4544.                 printf("?Memory allocation failure - \"%s\"\n",s2);
  4545.                 sexprc++;
  4546.             }
  4547.         }
  4548.         sx = sxresult[sexpdep];         /* Point to result buffer */
  4549.         while ((*sx++ = *s2++)) ;       /* copy result. */
  4550.         if (fpflag && truncate) {       /* Floating point + truncate */
  4551.             sx = sxresult[sexpdep];     /* at decimal point */
  4552.             for (i = xx - 1; i >= 0; i--) {
  4553.                 if (sx[i] == '.') {
  4554.                     sx[i] = NUL;
  4555.                     if (i == 0) {       /* If nothing left */
  4556.                         sx[0] = '0';    /* put a zero. */
  4557.                         sx[1] = NUL;
  4558.                     }
  4559.                 }
  4560.             }
  4561.         }
  4562.     }
  4563.     if (line)                           /* If macro arg buffer allocated */
  4564.       free(line);                       /* free it. */
  4565.     if (mustfree) {                     /* And free local copy of split list */
  4566.         for (i = 1; i <= n; i++) {
  4567.             if (p[i]) free(p[i]);
  4568.         }
  4569.     }
  4570.     debug(F111,sexpdebug("exit"),sxresult[sexpdep],sexprc);
  4571.     return(sxresult[sexpdep--]);
  4572. }
  4573. #endif /* NOSEXP */
  4574. #endif /* NOSPL */
  4575.  
  4576. int                                     /* CHECK command */
  4577. dochk() {
  4578.     int x, y;
  4579.     if ((y = cmkey(ftrtab,nftr,"","",xxstring)) < 0)
  4580.       return(y);
  4581.     ckstrncpy(line,atmbuf,LINBUFSIZ);
  4582.     if ((y = cmcfm()) < 0)
  4583.       return(y);
  4584. #ifndef NOPUSH
  4585.     if (!ckstrcmp(line,"push",(int)strlen(line),0)) {
  4586.         if (msgflg)                     /* If at top level... */
  4587.           printf(" push%s available\n", nopush ? " not" : "");
  4588.         else if (nopush && !backgrd)
  4589.           printf(" CHECK: push not available\n");
  4590.         return(success = 1 - nopush);
  4591.     }
  4592. #endif /* NOPUSH */
  4593. #ifdef PIPESEND
  4594.     if (!ckstrcmp(line,"pipes",(int)strlen(line),0)) {
  4595.         if (msgflg)                     /* If at top level... */
  4596.           printf(" pipes%s available\n",
  4597.                  (nopush || protocol != PROTO_K) ? " not" : "");
  4598.         else if ((nopush || protocol != PROTO_K) && !backgrd)
  4599.           printf(" CHECK: pipes not available\n");
  4600.         return(success = 1 - nopush);
  4601.     }
  4602. #endif /* PIPESEND */
  4603.     y = lookup(ftrtab,line,nftr,&x);    /* Look it up */
  4604.     debug(F111,"dochk",ftrtab[x].kwd,y);
  4605.     if (msgflg)                         /* If at top level... */
  4606.       printf(" %s%s available\n", ftrtab[x].kwd, y ? " not" : "");
  4607.     else if (y && !backgrd)
  4608.       printf(" CHECK: %s not available\n", ftrtab[x].kwd);
  4609.     return(success = 1 - y);
  4610. }
  4611.  
  4612. #ifndef NOLOCAL
  4613. #ifdef CKLOGDIAL
  4614.  
  4615. /* Connection log and elapsed-time reporting */
  4616.  
  4617. extern char cxlogbuf[];                 /* Log record buffer */
  4618. extern char diafil[];                   /* Log file name */
  4619. extern int dialog, cx_active;           /* Flags */
  4620. static long cx_prev = 0L;               /* Elapsed time of previous session */
  4621.  
  4622. #endif /* CKLOGDIAL */
  4623. #endif /* NOLOCAL */
  4624.  
  4625. VOID
  4626. dologend() {                            /* Write record to connection log */
  4627. #ifdef LOCUS
  4628.     extern int locus, autolocus;
  4629. #endif /* LOCUS */
  4630.  
  4631. #ifndef NOLOCAL
  4632. #ifdef CKLOGDIAL
  4633.     long d1, d2, t1, t2;
  4634.     char buf[32], * p;
  4635. #endif /* CKLOGDIAL */
  4636. #endif /* NOLOCAL */
  4637.  
  4638. #ifdef LOCUS
  4639.     if (autolocus) {
  4640.         int x = locus;
  4641. #ifdef NEWFTP
  4642.         extern int ftpisconnected();
  4643.     debug(F101,"dologend ftpisconnected","",ftpisconnected());
  4644.         setlocus(ftpisconnected() ? 0 : 1, 1);
  4645. #else
  4646.         setlocus(1,1);
  4647. #endif /* NEWFTP */
  4648.     }
  4649. #endif /* LOCUS */
  4650.  
  4651. #ifndef NOLOCAL
  4652. #ifdef CKLOGDIAL
  4653.     debug(F101,"dologend dialog","",dialog);
  4654.     debug(F101,"dologend cxlogbuf[0]","",cxlogbuf[0]);
  4655. #ifdef CKSYSLOG
  4656.     debug(F101,"dologend ckxlogging","",ckxlogging);
  4657. #endif /* CKSYSLOG */
  4658.  
  4659.     if (!cx_active || !cxlogbuf[0])     /* No active record */
  4660.       return;
  4661.  
  4662.     cx_active = 0;                      /* Record is not active */
  4663.     debug(F111,"dologend cxlogbuf 1",cxlogbuf,cx_active);
  4664.  
  4665.     d1 = mjd((char *)cxlogbuf);         /* Get start date of this session */
  4666.     ckstrncpy(buf,ckdate(),31);         /* Get current date */
  4667.     d2 = mjd(buf);                      /* Convert them to mjds */
  4668.     p = cxlogbuf;                       /* Get start time */
  4669.     p[11] = NUL;
  4670.     p[14] = NUL;                        /* Convert to seconds */
  4671.     t1 = atol(p+9) * 3600L + atol(p+12) * 60L + atol(p+15);
  4672.     p[11] = ':';
  4673.     p[14] = ':';
  4674.     p = buf;                            /* Get end time */
  4675.     p[11] = NUL;
  4676.     p[14] = NUL;
  4677.     t2 = atol(p+9) * 3600L + atol(p+12) * 60L + atol(p+15);
  4678.     t2 = ((d2 - d1) * 86400L) + (t2 - t1); /* Compute elapsed time */
  4679.     debug(F101,"dologend t2","",t2);
  4680.     if (t2 > -1L) {
  4681.         cx_prev = t2;
  4682.         p = hhmmss(t2);
  4683.         debug(F110,"dologend hhmmss",p,0);
  4684.         ckstrncat(cxlogbuf,"E=",CXLOGBUFL); /* Append to log record */
  4685.         ckstrncat(cxlogbuf,p,CXLOGBUFL);
  4686.         debug(F110,"dologend cxlogbuf 2",cxlogbuf,0);
  4687.     } else
  4688.       cx_prev = 0L;
  4689.     debug(F101,"dologend cx_prev","",cx_prev);
  4690.     if (dialog) {                       /* If logging */
  4691.         int x;
  4692.         x = diaopn(diafil,1,1);         /* Open log in append mode */
  4693.         debug(F101,"dologend diaopn","",x);
  4694.         x = zsoutl(ZDIFIL,cxlogbuf);    /* Write the record */
  4695.         debug(F101,"dologend zsoutl","",x);
  4696.         x = zclose(ZDIFIL);             /* Close the log */
  4697.         debug(F101,"dologend zclose","",x);
  4698.     }
  4699. #ifdef CKSYSLOG
  4700.     debug(F101,"dologend ckxlogging","",ckxlogging);
  4701.     if (ckxlogging) {
  4702.         int x;
  4703.         x = ckindex("T=DIAL",cxlogbuf,0,0,1);
  4704.         debug(F111,"dologend ckxsyslog",cxlogbuf,ckxsyslog);
  4705.         debug(F111,"dologend ckindex","T=DIAL",x);
  4706.         if (x > 0) {
  4707.             if (ckxsyslog >= SYSLG_DI) {
  4708.                 debug(F110,"dologend syslog",cxlogbuf+18,0);
  4709.                 cksyslog(SYSLG_DI,1,"CONNECTION",(char *)(cxlogbuf+18),"");
  4710.             } else if (ckxsyslog >= SYSLG_AC) {
  4711.                 debug(F110,"dologend syslog",cxlogbuf+18,0);
  4712.                 cksyslog(SYSLG_AC,1,"CONNECTION",(char *)(cxlogbuf+18),"");
  4713.             }
  4714.         }
  4715.     }
  4716. #endif /* CKSYSLOG */
  4717. #endif /* CKLOGDIAL */
  4718. #endif /* NOLOCAL */
  4719. }
  4720.  
  4721. #ifndef NOLOCAL
  4722. #ifdef CKLOGDIAL
  4723.  
  4724. /*  D O L O G S H O W  --  Show session/connection info  */
  4725.  
  4726. /* Call with fc == 1 to show, fc == 0 to only calculate. */
  4727. /* Returns session elapsed time in seconds. */
  4728. /* If no session active, returns elapsed time of previous session, if any, */
  4729. /* otherwise 0 */
  4730.  
  4731. long
  4732. dologshow(fc) int fc; {                 /* SHOW (current) CONNECTION */
  4733.     long d1, d2, t1, t2 = 0, prev;
  4734.     char c, buf1[32], buf2[32], * info[32], * p, * s;
  4735.     char * xlogbuf, xbuf[CXLOGBUFL+1];
  4736.     int i, x = 0, z, ftp = 0, active = 0;
  4737.  
  4738. #ifdef NEWFTP
  4739.     extern char ftplogbuf[];
  4740.     extern long ftplogprev;
  4741.     extern int ftplogactive;
  4742.     if (fc & W_FTP) {
  4743.         fc &= 63;
  4744.         ftp = 1;
  4745.         xlogbuf = ftplogbuf;
  4746.         prev = ftplogprev;
  4747.         active = ftplogactive;
  4748.     } else {
  4749. #endif /* NEWFTP */
  4750.         ftp = 0;
  4751.         xlogbuf = cxlogbuf;
  4752.         prev = cx_prev;
  4753.         active = cx_active;
  4754. #ifdef NEWFTP
  4755.     }
  4756. #endif /* NEWFTP */
  4757.  
  4758.     debug(F101,"dologshow local","",local);
  4759.     debug(F101,"dologshow ftp","",ftp);
  4760.     debug(F111,"dologshow active",xlogbuf,active);
  4761.  
  4762.     if (!xlogbuf[0]) {
  4763.         if (fc) {
  4764.             if (didsetlin || ftp)
  4765.               printf(" %s: No record.\n", ftp ? "FTP" : "Kermit");
  4766.             else
  4767.               printf(" %s: No connection.\n", ftp ? "FTP" : "Kermit");
  4768.         }
  4769.         return(prev);
  4770.     }
  4771.  
  4772. #ifdef NEWFTP
  4773.     if (ftp) {
  4774.         z = ftpisconnected() ? 1 : -1;
  4775.     } else {
  4776. #endif /* NEWFTP */
  4777.         if (local) {                    /* See if we have an open connection */
  4778.             z = ttchk();
  4779.             debug(F101,"dologshow ttchk","",z);
  4780.             z = (z > -1) ? 1 : -2;
  4781.         } else {
  4782.             z = active ? 1 : -2;
  4783.         }
  4784. #ifdef NEWFTP
  4785.     }
  4786. #endif /* NEWFTP */
  4787.     if (z < 0L) {
  4788.         if (!fc)
  4789.           return(prev);
  4790.         else
  4791.           t2 = prev;
  4792.     }
  4793.     /* Note: NOT ckstrncpy! */
  4794.     strncpy(buf1,xlogbuf,17);           /* Copy of just the timestamp */
  4795.     buf1[17] = NUL;                     /* Terminate it */
  4796.     ckstrncpy(xbuf,xlogbuf+18,CXLOGBUFL); /* Copy that can be poked */
  4797.     debug(F111,"dologshow prev",xbuf,prev);
  4798.  
  4799.     xwords(xbuf,31,info,1);             /* Break up into fields */
  4800.     d1 = mjd(buf1);                     /* Convert start time to MJD */
  4801.     ckstrncpy(buf2,ckdate(),31);        /* Current date */
  4802.     d2 = mjd(buf2);                     /* Convert to MJD */
  4803.     p = buf1;                           /* Point to start time */
  4804.     p[11] = NUL;
  4805.     p[14] = NUL;                        /* Convert to seconds */
  4806.     t1 = atol(p+9) * 3600L + atol(p+12) * 60L + atol(p+15);
  4807.     p[11] = ':';
  4808.     p[14] = ':';
  4809.     p = buf2;                           /* Ditto for current time */
  4810.     p[11] = NUL;
  4811.     p[14] = NUL;
  4812.     if (z > -1L) {
  4813.         t2 = atol(p+9) * 3600L + atol(p+12) * 60L + atol(p+15);
  4814.         t2 = ((d2 - d1) * 86400L) + (t2 - t1); /* Elapsed time so far */
  4815.     }
  4816.     if (fc) {
  4817.         p = NULL;
  4818.         if (t2 > -1L)                   /* Convert seconds to hh:mm:ss */
  4819.           p = hhmmss(t2);
  4820.         if (z > -1)
  4821.           s = "Active";
  4822.         else if (z == -2)
  4823.           s = "Closed";
  4824.         else
  4825.           s = "Unknown";
  4826.         printf("\n");                   /* Show results */
  4827.         printf(" Status:       %s\n",s);
  4828.         printf(" Opened:       %s\n",buf1);
  4829.         printf(" User:         %s\n",info[1] ? info[1] : "");
  4830.         printf(" PID:          %s\n",info[2] ? info[2] : "");
  4831.         for (i = 3; info[i]; i++) {
  4832.             c = info[i][0];
  4833.             s = (info[i]) ? info[i]+2 : "";
  4834.             switch (c) {
  4835.               case 'T': printf(" Type:         %s\n", s); break;
  4836.               case 'N': printf(" To:           %s\n", s); break;
  4837.               case 'H': printf(" From:         %s\n", s); break;
  4838.               case 'D': printf(" Device:       %s\n", s); break;
  4839.               case 'O': printf(" Origin:       %s\n", s); break;
  4840.               case 'E': break;
  4841.               default:  printf(" %s\n",info[i] ? info[i] : "");
  4842.             }
  4843.         }
  4844.         if (z < 0L)
  4845.           printf(" Elapsed time: %s\n", hhmmss(t2));
  4846.         else
  4847.           printf(" Elapsed time: %s\n", p ? p : "(unknown)");
  4848.         x = 0;
  4849. #ifdef NETCONN
  4850. #ifdef SSHBUILTIN
  4851.         if ( IS_SSH() ) x++;
  4852. #endif /* SSHBUILTIN */
  4853. #ifdef CK_ENCRYPTION
  4854.         if (ck_tn_encrypting() && ck_tn_decrypting()) x++;
  4855. #endif /* CK_ENCRYPTION */
  4856. #ifdef CK_SSL
  4857.         if (tls_active_flag || ssl_active_flag) x++;
  4858. #endif /* CK_SSL */
  4859. #ifdef RLOGCODE
  4860. #ifdef CK_KERBEROS
  4861. #ifdef CK_ENCRYPTION
  4862.         if (ttnproto == NP_EK4LOGIN || ttnproto == NP_EK5LOGIN) x++;
  4863. #endif /* CK_ENCRYPTION */
  4864. #endif /* CK_KERBEROS */
  4865. #endif /* RLOGCODE */
  4866. #endif /* NETCONN */
  4867.         if (z > 0)
  4868.           printf(" Encrypted:    %s\n", x ? "Yes" : "No");
  4869.         printf(" Log:          %s\n", dialog ? diafil : "(none)");
  4870.         printf("\n");
  4871.     }
  4872.     return(t2 > -1L ? t2 : 0L);
  4873. }
  4874.  
  4875. VOID
  4876. dologline() {
  4877.     char * p;
  4878.     int n, m = 0;
  4879.  
  4880.     dologend();                         /* Previous session not closed out? */
  4881.     cx_active = 1;                      /* Record is active */
  4882.     cx_prev = 0L;
  4883.     p = ckdate();                       /* Get timestamp */
  4884.     n = ckstrncpy(cxlogbuf,p,CXLOGBUFL-1); /* Start record off with it */
  4885.     if (!uidbuf[0]) {
  4886.         debug(F100,"dologline uidbuf empty","",0);
  4887. #ifdef UNIX                             /* Who has whoami()... */
  4888.         ckstrncpy(uidbuf,(char *)whoami(),UIDBUFLEN);
  4889. #else
  4890. #ifdef STRATUS
  4891.         ckstrncpy(uidbuf,(char *)whoami(),UIDBUFLEN);
  4892. #else
  4893.         ckstrncpy(uidbuf,"UNKNOWN",UIDBUFLEN);
  4894. #endif /* STRATUS */
  4895. #endif /* UNIX */
  4896.     }
  4897.     m = strlen(uidbuf) + strlen(myhost) + strlen(ttname) + 32;
  4898.     if (n+m < CXLOGBUFL-1) {            /* Add serial device info */
  4899.         p = cxlogbuf+n;
  4900.         sprintf(p," %s %s T=SERIAL H=%s D=%s ", /* SAFE */
  4901.                 uidbuf,
  4902.                 ckgetpid(),
  4903.                 myhost,
  4904.                 ttname
  4905.                 );
  4906.     } else
  4907.       ckstrncpy(cxlogbuf,"LOGLINE BUFFER OVERFLOW",CXLOGBUFL);
  4908.     debug(F110,"dologline",cxlogbuf,0);
  4909. }
  4910.  
  4911. #ifdef NETCONN
  4912. VOID
  4913. dolognet() {
  4914.     char * p, * s = "NET", * uu = uidbuf;
  4915.     int n, m;
  4916.  
  4917.     dologend();                         /* Previous session not closed out? */
  4918.     cx_prev = 0L;
  4919.     cx_active = 1;                      /* Record is active */
  4920.     p = ckdate();
  4921.     n = ckstrncpy(cxlogbuf,p,CXLOGBUFL);
  4922. #ifdef TCPSOCKET
  4923.     if (nettype == NET_TCPB || nettype == NET_TCPA)
  4924.       s = "TCP";
  4925. #endif /* TCPSOCKET */
  4926. #ifdef ANYX25
  4927.     if (nettype == NET_SX25 || nettype == NET_VX25 || nettype == NET_IX25)
  4928.       s = "X25";
  4929. #endif /* ANYX25 */
  4930. #ifdef DECNET
  4931.     if (nettype == NET_DEC)
  4932.       s = "DECNET";
  4933. #endif /* DECNET */
  4934. #ifdef SUPERLAT
  4935.     if (nettype == NET_SLAT)
  4936.       s = "SUPERLAT";
  4937. #endif /* SUPERLAT */
  4938. #ifdef CK_NETBIOS
  4939.     if (nettype == NET_BIOS)
  4940.       s = "NETBIOS";
  4941. #endif /* CK_NETBIOS */
  4942.  
  4943.     if (!uu[0]) {
  4944.         debug(F100,"dolognet uidbuf empty","",0);
  4945. #ifdef OS2ORUNIX                        /* Who has whoami()... */
  4946.         uu = (char *)whoami();
  4947. #else
  4948. #ifdef STRATUS
  4949.         uu = (char *)whoami();
  4950. #else
  4951.         uu = "UNKNOWN";
  4952. #endif /* STRATUS */
  4953. #endif /* UNIX */
  4954.     }
  4955.     m = strlen(uu) + strlen(myhost) + strlen(ttname) + strlen(s) + 32;
  4956.     if (n+m < CXLOGBUFL-1) {            /* SAFE */
  4957.         p = cxlogbuf+n;
  4958.         sprintf(p," %s %s T=%s N=%s H=%s ",
  4959.                 uu,
  4960.                 ckgetpid(),
  4961.                 s,
  4962.                 ttname,
  4963.                 myhost
  4964.                 );
  4965.     } else
  4966.       ckstrncpy(cxlogbuf,"LOGNET BUFFER OVERFLOW",CXLOGBUFL);
  4967.     debug(F110,"dolognet cxlogbuf",cxlogbuf,0);
  4968. }
  4969. #endif /* NETCONN */
  4970. #endif /* CKLOGDIAL */
  4971.  
  4972. #ifndef NODIAL
  4973. /*
  4974.   Parse a DIAL-related string, stripping enclosing braces, if any.
  4975. */
  4976. static int
  4977. dialstr(p,msg) char **p; char *msg; {
  4978.     int x;
  4979.     char *s;
  4980.  
  4981.     if ((x = cmtxt(msg, "", &s, xxstring)) < 0)
  4982.       return(x);
  4983.     s = brstrip(s);                     /* Strip braces around. */
  4984.     debug(F110,"dialstr",s,0);
  4985.     makestr(p,*s?s:NULL);
  4986.     return(success = 1);
  4987. }
  4988.  
  4989. VOID
  4990. initmdm(x) int x; {
  4991.     MDMINF * p;
  4992.     int m;
  4993.  
  4994.     mdmtyp = x;                         /* Set global modem type */
  4995.     debug(F101,"initmdm mdmtyp","",mdmtyp);
  4996.     debug(F101,"initmdm usermdm","",usermdm);
  4997.     if (x < 1) return;
  4998.  
  4999.     m = usermdm ? usermdm : mdmtyp;
  5000.  
  5001.     p = modemp[m];                      /* Point to modem info struct, and */
  5002.     /* debug(F101,"initmdm p","",p); */
  5003.     if (p) {
  5004.         dialec = p->capas & CKD_EC;     /* set DIAL ERROR-CORRECTION, */
  5005.         dialdc = p->capas & CKD_DC;     /* DIAL DATA-COMPRESSION, and */
  5006.         mdmspd = p->capas & CKD_SB ? 0 : 1; /* DIAL SPEED-MATCHING from it. */
  5007.         dialfc = FLO_AUTO;                  /* Modem's local flow control.. */
  5008.         dialmax   = p->max_speed;
  5009.         dialcapas = p->capas;
  5010.         dialesc   = p->esc_char;
  5011.     } else if (mdmtyp > 0) {
  5012.         printf("WARNING: modem info for \"%s\" not filled in yet\n",
  5013.                gmdmtyp()
  5014.                );
  5015.     }
  5016.  
  5017. /* Reset or set the SET DIAL STRING items ... */
  5018.  
  5019. #ifdef DEBUG
  5020.     if (deblog) {
  5021.         debug(F110,"initmdm dialini",dialini,0);
  5022.         debug(F110,"initmdm dialmstr ",dialmstr,0);
  5023.         debug(F110,"initmdm dialmprmt",dialmprmt,0);
  5024.         debug(F110,"initmdm dialcmd",dialcmd,0);
  5025.         debug(F110,"initmdm dialdcon",dialdcon,0);
  5026.         debug(F110,"initmdm dialdcoff",dialdcoff,0);
  5027.         debug(F110,"initmdm dialecon",dialecon,0);
  5028.         debug(F110,"initmdm dialecoff",dialecoff,0);
  5029.         debug(F110,"initmdm dialhcmd",dialhcmd,0);
  5030.         debug(F110,"initmdm dialhwfc",dialhwfc,0);
  5031.         debug(F110,"initmdm dialswfc",dialswfc,0);
  5032.         debug(F110,"initmdm dialnofc",dialnofc,0);
  5033.         debug(F110,"initmdm dialtone",dialtone,0);
  5034.         debug(F110,"initmdm dialpulse",dialpulse,0);
  5035.         debug(F110,"initmdm dialname",dialname,0);
  5036.         debug(F110,"initmdm dialaaon",dialaaon,0);
  5037.         debug(F110,"initmdm dialaaoff",dialaaoff,0);
  5038.         debug(F110,"initmdm dialx3",dialx3,0);
  5039.         debug(F110,"initmdm dialspon",dialspon,0);
  5040.         debug(F110,"initmdm dialspoff",dialspoff,0);
  5041.         debug(F110,"initmdm dialvol1",dialvol1,0);
  5042.         debug(F110,"initmdm dialvol2",dialvol2,0);
  5043.         debug(F110,"initmdm dialvol3",dialvol3,0);
  5044.         debug(F110,"initmdm dialini2",dialini2,0);
  5045.     }
  5046. #endif /* DEBUG */
  5047.  
  5048.     if (usermdm && p) { /* USER-DEFINED: copy info from specified template */
  5049.  
  5050.         makestr(&dialini  ,p->wake_str);
  5051.         makestr(&dialmstr ,p->dmode_str);
  5052.         makestr(&dialmprmt,p->dmode_prompt);
  5053.         makestr(&dialcmd  ,p->dial_str);
  5054.         makestr(&dialdcon ,p->dc_on_str);
  5055.         makestr(&dialdcoff,p->dc_off_str);
  5056.         makestr(&dialecon ,p->ec_on_str);
  5057.         makestr(&dialecoff,p->ec_off_str);
  5058.         makestr(&dialhcmd ,p->hup_str);
  5059.         makestr(&dialhwfc ,p->hwfc_str);
  5060.         makestr(&dialswfc ,p->swfc_str);
  5061.         makestr(&dialnofc ,p->nofc_str);
  5062.         makestr(&dialtone ,p->tone);
  5063.         makestr(&dialpulse,p->pulse);
  5064.         makestr(&dialname ,"This space available (use SET MODEM NAME)");
  5065.         makestr(&dialaaon ,p->aa_on_str);
  5066.         makestr(&dialaaoff,p->aa_off_str);
  5067.         makestr(&dialx3   ,p->ignoredt);
  5068.         makestr(&dialspon ,p->sp_on_str);
  5069.         makestr(&dialspoff,p->sp_off_str);
  5070.         makestr(&dialvol1 ,p->vol1_str);
  5071.         makestr(&dialvol2 ,p->vol2_str);
  5072.         makestr(&dialvol3 ,p->vol3_str);
  5073.         makestr(&dialini2 ,p->ini2);
  5074.  
  5075.     } else {                    /* Not user-defined, so wipe out overrides */
  5076.  
  5077.         if (dialini)   makestr(&dialini,NULL);   /* Init-string */
  5078.         if (dialmstr)  makestr(&dialmstr,NULL);  /* Dial-mode-str */
  5079.         if (dialmprmt) makestr(&dialmprmt,NULL); /* Dial-mode-pro */
  5080.         if (dialcmd)   makestr(&dialcmd,NULL);   /* Dial-command  */
  5081.         if (dialdcon)  makestr(&dialdcon,NULL);  /* DC ON command */
  5082.         if (dialdcoff) makestr(&dialdcoff,NULL); /* DC OFF command */
  5083.         if (dialecon)  makestr(&dialecon,NULL);  /* EC ON command */
  5084.         if (dialecoff) makestr(&dialecoff,NULL); /* EC OFF command */
  5085.         if (dialhcmd)  makestr(&dialhcmd,NULL);  /* Hangup command */
  5086.         if (dialhwfc)  makestr(&dialhwfc,NULL);  /* Flow control... */
  5087.         if (dialswfc)  makestr(&dialswfc,NULL);  /*  */
  5088.         if (dialnofc)  makestr(&dialnofc,NULL);  /*  */
  5089.         if (dialtone)  makestr(&dialtone,NULL);  /* Dialing method */
  5090.         if (dialpulse) makestr(&dialpulse,NULL); /*  */
  5091.         if (dialname)  makestr(&dialname,NULL);  /* Modem name */
  5092.         if (dialaaon)  makestr(&dialaaon,NULL);  /* Autoanswer On */
  5093.         if (dialaaoff) makestr(&dialaaoff,NULL); /* Autoanswer Off */
  5094.         if (dialx3)    makestr(&dialx3,NULL);    /* Ignore dialtone */
  5095.         if (dialspon)  makestr(&dialspon,NULL);  /* Speaker On */
  5096.         if (dialspoff) makestr(&dialspoff,NULL); /* Speaker Off */
  5097.         if (dialvol1)  makestr(&dialvol1,NULL);  /* Low volume */
  5098.         if (dialvol2)  makestr(&dialvol2,NULL);  /* Medium volume */
  5099.         if (dialvol3)  makestr(&dialvol3,NULL);  /* High volume */
  5100.         if (dialini2)  makestr(&dialini2,NULL);  /* Init string 2 */
  5101.     }
  5102.     if (autoflow)                       /* Maybe change flow control */
  5103.       setflow();
  5104.  
  5105. #ifndef MINIDIAL
  5106. #ifdef OLDTBCODE
  5107.     tbmodel = 0;           /* If it's a Telebit, we don't know the model yet */
  5108. #endif /* OLDTBCODE */
  5109. #endif /* MINIDIAL */
  5110. }
  5111.  
  5112. #ifdef COMMENT
  5113. /* Not implemented yet */
  5114. int
  5115. setanswer() {
  5116.     int x, y;
  5117.     extern int ans_cid, ans_ring;
  5118.     if ((x = cmkey(answertab,nanswertab,"","",xxstring)) < 0)
  5119.       return(x);
  5120.     switch (x) {
  5121.       case XYA_CID:
  5122.         return(seton(&ans_cid));
  5123.       case XYA_RNG:
  5124.         y = cmnum("How many rings before answering","1",10,&x,xxstring);
  5125.         y = setnum(&ans_rings,x,y,254);
  5126.         return(y);
  5127.     }
  5128. }
  5129. #endif /* COMMENT */
  5130.  
  5131. int
  5132. setmodem() {                            /* SET MODEM */
  5133.  
  5134.     int x, y, z;
  5135.     long zz;
  5136.     struct FDB k1, k2;
  5137.     extern int mdmset;
  5138.  
  5139.     cmfdbi(&k1,_CMKEY,
  5140.            "Modem parameter","","",nsetmdm, 0, xxstring, setmdm, &k2);
  5141.     cmfdbi(&k2,_CMKEY,"","","",nmdm,0,xxstring,mdmtab,NULL);
  5142.     x = cmfdb(&k1);
  5143.     if (x < 0) {                        /* Error */
  5144.         if (x == -2 || x == -9)
  5145.           printf("?No keywords match: \"%s\"\n",atmbuf);
  5146.         return(x);
  5147.     }
  5148.     y = cmresult.nresult;               /* Keyword value */
  5149.     if (cmresult.fdbaddr == &k2) {      /* Modem-type keyword table */
  5150.         if ((x = cmcfm()) < 0)
  5151.           return(x);
  5152.         usermdm = 0;
  5153.         initmdm(cmresult.nresult);      /* Set the modem type. */
  5154.         return(success = 1);            /* Done */
  5155.     }
  5156.     switch (cmresult.nresult) {         /* SET MODEM keyword table. */
  5157. #ifdef MDMHUP
  5158.       case XYDMHU:                      /* DIAL MODEM-HANGUP */
  5159.         if ((y = cmkey(mdmhang,4,"how to hang up modem",
  5160.                        "modem-command", xxstring)) < 0)
  5161.           return(y);
  5162.         if ((x = cmcfm()) < 0)
  5163.           return(x);
  5164.         dialmhu = y;
  5165. #ifdef COMMENT
  5166. /* Nope, I fixed it (2001 11 08) */
  5167. #ifdef CK_SCOV5
  5168.         if (dialmhu == 0 && !quiet) {
  5169.             printf(
  5170. "\n WARNING: RS-232 signal sampling and manipulation do not work\n"
  5171.                     );
  5172.             printf(
  5173. " in the standard SCO OSR5 serial i/o drivers.  SET MODEM HANGUP-METHOD\n"
  5174.                    );
  5175.             printf(
  5176. " MODEM-COMMAND is recommended for OSR5.\n\n"
  5177.                     );
  5178.         }
  5179. #endif /* CK_SCOV5 */
  5180. #endif /* COMMENT */
  5181.         return(success = 1);
  5182. #endif /* MDMHUP */
  5183.  
  5184.       case XYDCAP:
  5185.         zz = 0L;
  5186.         y = 0;
  5187.         while (y != -3) {
  5188.             if ((y = cmkey(mdmcap,nmdmcap,
  5189.                            "capability of modem", "", xxstring)) < 0) {
  5190.                 if (y == -3)
  5191.                   break;
  5192.                 else
  5193.                   return(y);
  5194.             }
  5195.             zz |= y;
  5196.         }
  5197.         if ((x = cmcfm()) < 0)
  5198.           return(x);
  5199.         dialcapas = zz;
  5200.         debug(F101,"setmodem autoflow","",autoflow);
  5201.         debug(F101,"setmodem flow 1","",flow);
  5202.         if (autoflow)                   /* Maybe change flow control */
  5203.           setflow();
  5204.         debug(F101,"setmodem flow 2","",flow);
  5205.         mdmspd = zz & CKD_SB ? 0 : 1;   /* Set MODEM SPEED-MATCHING from it. */
  5206.         return(success = 1);
  5207.  
  5208.       case XYDMAX:
  5209. #ifdef TN_COMPORT
  5210.         if (network && istncomport())
  5211.           x = cmkey(tnspdtab,ntnspd,line,"",xxstring);
  5212.         else
  5213. #endif /* TN_COMPORT */
  5214.           x = cmkey(spdtab,nspd,line,"",xxstring);
  5215.         if (x < 0) {
  5216.             if (x == -3) printf("?value required\n");
  5217.             return(x);
  5218.         }
  5219.         if ((y = cmcfm()) < 0) return(y);
  5220.         dialmax = (long) x * 10L;
  5221.         if (dialmax == 70) dialmax = 75;
  5222.         return(success = 1);
  5223.  
  5224.       case XYDSTR:                      /* These moved from SET DIAL */
  5225.       case XYDDC:
  5226.       case XYDEC:
  5227.       case XYDESC:
  5228.       case XYDFC:
  5229.       case XYDKSP:
  5230.       case XYDSPD:
  5231.       case XYDDIA:
  5232.         return(setdial(x));
  5233.  
  5234.       case XYDTYP:
  5235.         if ((y = cmkey(mdmtab,nmdm,"modem type","none", xxstring)) < 0)
  5236.           return(y);
  5237.         if (y == dialudt) {             /* User-defined modem type */
  5238.             if ((x = cmkey(mdmtab,nmdm,"based on existing modem type",
  5239.                            "unknown", xxstring)) < 0)
  5240.               return(x);
  5241.         }
  5242.         if ((z = cmcfm()) < 0)
  5243.           return(z);
  5244.         usermdm = 0;
  5245.         usermdm = (y == dialudt) ? x : 0;
  5246.         initmdm(y);
  5247.         mdmset = (mdmtyp > 0);
  5248.         return(success = 1);
  5249.  
  5250.       case XYDNAM:
  5251.         return(dialstr(&dialname,"Descriptive name for modem"));
  5252.  
  5253.       case XYDMCD:                      /* SET MODEM CARRIER-WATCH */
  5254.         return(setdcd());
  5255.  
  5256.       case XYDSPK:                      /* SET MODEM SPEAKER */
  5257.         return(seton(&mdmspk));
  5258.  
  5259.       case XYDVOL:                      /* SET MODEM VOLUME */
  5260.         if ((x = cmkey(voltab,3,"","medium",xxstring)) < 0)
  5261.           return(x);
  5262.         if ((y = cmcfm()) < 0)
  5263.           return(y);
  5264.         mdmvol = x;
  5265.         return(success = 1);
  5266.  
  5267.       default:
  5268.         printf("Unexpected SET MODEM parameter\n");
  5269.         return(-9);
  5270.     }
  5271. }
  5272.  
  5273. static int                              /* Set DIAL command options */
  5274. setdial(y) int y; {
  5275.     int x = 0, z = 0;
  5276.     char *s = NULL;
  5277.  
  5278.     if (y < 0)
  5279.       if ((y = cmkey(dialtab,ndial,"","",xxstring)) < 0)
  5280.         return(y);
  5281.     switch (y) {
  5282.       case XYDHUP:                      /* DIAL HANGUP */
  5283.         return(seton(&dialhng));
  5284.       case XYDINI:                      /* DIAL INIT-STRING */
  5285.         return(dialstr(&dialini,"Modem initialization string"));
  5286.       case XYDNPR:                      /* DIAL PREFIX */
  5287.         return(dialstr(&dialnpr,"Telephone number prefix"));
  5288.       case XYDDIA:                      /* DIAL DIAL-COMMAND */
  5289.         x = cmtxt("Dialing command for modem,\n\
  5290.  include \"%s\" to stand for phone number,\n\
  5291.  for example, \"set dial dial-command ATDT%s\\13\"",
  5292.                   "",
  5293.                   &s,
  5294.                   xxstring);
  5295.         if (x < 0 && x != -3)           /* Handle parse errors */
  5296.           return(x);
  5297.         s = brstrip(s);                 /* Strip braces or quotes */
  5298.         y = x = strlen(s);              /* Get length of text */
  5299.         if (y > 0) {                    /* If there is any text (left), */
  5300.             for (x = 0; x < y; x++) {   /* make sure they included "%s" */
  5301.                 if (s[x] != '%') continue;
  5302.                 if (s[x+1] == 's') break;
  5303.             }
  5304.             if (x == y) {
  5305.                 printf(
  5306. "?Dial-command must contain \"%cs\" for phone number.\n",'%');
  5307.                 return(-9);
  5308.             }
  5309.         }
  5310.         if (dialcmd) {                  /* Free any previous string. */
  5311.             free(dialcmd);
  5312.             dialcmd = (char *) 0;
  5313.         }
  5314.         if (y > 0) {
  5315.             dialcmd = malloc(y + 1);    /* Allocate space for it */
  5316.             if (dialcmd)
  5317.               strcpy(dialcmd,s);        /* and make a safe copy. */
  5318.         }
  5319.         return(success = 1);
  5320. #ifndef NOXFER
  5321.       case XYDKSP:                      /* DIAL KERMIT-SPOOF */
  5322.         return(seton(&dialksp));
  5323. #endif /* NOXFER */
  5324.       case XYDTMO:                      /* DIAL TIMEOUT */
  5325.         y = cmnum("Seconds to wait for call completion","0",10,&x,xxstring);
  5326.         if (y < 0) return(y);
  5327.         y = cmnum("Kermit/modem timeout differential","10",10,&z,xxstring);
  5328.         if (y < 0) return(y);
  5329.         if ((y = cmcfm()) < 0)
  5330.           return(y);
  5331.         dialtmo = x;
  5332.         mdmwaitd = z;
  5333.       case XYDESC:                      /* DIAL ESCAPE-CHARACTER */
  5334.         y = cmnum("ASCII value of character to escape back to modem",
  5335.                   "43",10,&x,xxstring);
  5336.         y = setnum(&dialesc,x,y,128);
  5337.         if (y > -1 && dialesc < 0)      /* No escape character */
  5338.           dialmhu = 0;                  /* So no hangup by modem command */
  5339.         return(y);
  5340.       case XYDDPY:                      /* DIAL DISPLAY */
  5341.         return(seton(&dialdpy));
  5342.       case XYDSPD:                      /* DIAL SPEED-MATCHING */
  5343.                                         /* used to be speed-changing */
  5344.         if ((y = seton(&mdmspd)) < 0) return(y);
  5345. #ifdef COMMENT
  5346.         mdmspd = 1 - mdmspd;            /* so here we reverse the meaning */
  5347. #endif /* COMMENT */
  5348.         return(success = 1);
  5349.       case XYDMNP:                      /* DIAL MNP-ENABLE */
  5350.       case XYDEC:                       /* DIAL ERROR-CORRECTION */
  5351.         x = seton(&dialec);
  5352.         if (x > 0)
  5353.           if (!dialec) dialdc = 0;      /* OFF also turns off compression */
  5354.         return(x);
  5355.  
  5356.       case XYDDC:                       /* DIAL COMPRESSION */
  5357.         x = seton(&dialdc);
  5358.         if (x > 0)
  5359.           if (dialdc) dialec = 1;       /* ON also turns on error correction */
  5360.         return(x);
  5361.  
  5362. #ifdef MDMHUP
  5363.       case XYDMHU:                      /* DIAL MODEM-HANGUP */
  5364.         return(seton(&dialmhu));
  5365. #endif /* MDMHUP */
  5366.  
  5367. #ifndef NOSPL
  5368.       case XYDDIR:                      /* DIAL DIRECTORY (zero or more) */
  5369.         return(parsdir(0));             /* 0 means DIAL */
  5370. #endif /* NOSPL */
  5371.  
  5372.       case XYDSTR:                      /* DIAL STRING */
  5373.         if ((y = cmkey(mdmcmd,nmdmcmd,"","",xxstring)) < 0) return(y);
  5374.         switch (y) {
  5375.           case XYDS_AN:                 /* Autoanswer ON/OFF */
  5376.           case XYDS_DC:                 /* Data compression ON/OFF */
  5377.           case XYDS_EC:                 /* Error correction ON/OFF */
  5378.             if ((x = cmkey(onoff,2,"","on",xxstring)) < 0)
  5379.               return(x);
  5380.             sprintf(tmpbuf,"Modem's command to %sable %s", /* SAFE */
  5381.                     x ? "en" : "dis",
  5382.                     (y == XYDS_DC) ? "compression" :
  5383.                     ((y == XYDS_EC) ? "error-correction" :
  5384.                     "autoanswer")
  5385.                     );
  5386.             if (x) {
  5387.                 if (y == XYDS_DC)
  5388.                   return(dialstr(&dialdcon,tmpbuf));
  5389.                 else if (y == XYDS_EC)
  5390.                   return(dialstr(&dialecon,tmpbuf));
  5391.                 else
  5392.                   return(dialstr(&dialaaon,tmpbuf));
  5393.             } else {
  5394.                 if (y == XYDS_DC)
  5395.                   return(dialstr(&dialdcoff,tmpbuf));
  5396.                 else if (y == XYDS_EC)
  5397.                   return(dialstr(&dialecoff,tmpbuf));
  5398.                 else
  5399.                   return(dialstr(&dialaaoff,tmpbuf));
  5400.             }
  5401.           case XYDS_HU:                 /*    hangup command */
  5402.             return(dialstr(&dialhcmd,"Modem's hangup command"));
  5403.           case XYDS_HW:                 /*    hwfc */
  5404.             return(dialstr(&dialhwfc,
  5405.                            "Modem's command to enable hardware flow control"));
  5406.           case XYDS_IN:                 /*    init */
  5407.             return(dialstr(&dialini,"Modem's initialization string"));
  5408.           case XYDS_NF:                 /*    no flow control */
  5409.             return(dialstr(&dialnofc,
  5410.                            "Modem's command to disable local flow control"));
  5411.           case XYDS_PX:                 /*    prefix */
  5412.             return(dialstr(&dialnpr,"Telephone number prefix for dialing"));
  5413.           case XYDS_SW:                 /*    swfc */
  5414.             return(dialstr(&dialswfc,
  5415.                    "Modem's command to enable local software flow control"));
  5416.           case XYDS_DT:                 /*    tone dialing */
  5417.             return(dialstr(&dialtone,
  5418.                    "Command to configure modem for tone dialing"));
  5419.           case XYDS_DP:                 /*    pulse dialing */
  5420.             return(dialstr(&dialpulse,
  5421.                            "Command to configure modem for pulse dialing"));
  5422.           case XYDS_MS:                 /*    dial mode string */
  5423.             return(dialstr(&dialmstr,
  5424.                          "Command to enter dial mode"));
  5425.           case XYDS_MP:                 /*    dial mode prompt */
  5426.             return(dialstr(&dialmprmt,
  5427.                            "Modem response upon entering dial mode"));
  5428.           case XYDS_SP:                 /* SPEAKER OFF */
  5429.             if ((x = cmkey(onoff,2,"","on",xxstring)) < 0) return(x);
  5430.             if (x)
  5431.               return(dialstr(&dialspon,"Command to turn modem speaker on"));
  5432.             else
  5433.               return(dialstr(&dialspoff,"Command to turn modem speaker off"));
  5434.  
  5435.           case XYDS_VO:                 /* VOLUME LOW */
  5436.             if ((x = cmkey(voltab,3,"","medium",xxstring)) < 0) return(x);
  5437.             switch (x) {
  5438.               case 0:
  5439.               case 1:
  5440.                 return(dialstr(&dialvol1,
  5441.                                "Command for low modem speaker volume"));
  5442.               case 2:
  5443.                 return(dialstr(&dialvol2,
  5444.                            "Command for medium modem speaker volume"));
  5445.  
  5446.               case 3:
  5447.                 return(dialstr(&dialvol3,
  5448.                                "Command for high modem speaker volume"));
  5449.               default:
  5450.                 return(-2);
  5451.             }
  5452.  
  5453.           case XYDS_ID:                 /* IGNORE-DIALTONE */
  5454.             return(dialstr(&dialx3,
  5455.                            "Command to tell modem to ignore dialtone"));
  5456.  
  5457.           case XYDS_I2:                 /* PREDIAL-INIT */
  5458.             return(dialstr(&dialini2,
  5459.                            "Command to send to modem just prior to dialing"));
  5460.  
  5461.           default:
  5462.             printf("?Unexpected SET DIAL STRING parameter\n");
  5463.         }
  5464.  
  5465.       case XYDFC:                       /* DIAL FLOW-CONTROL */
  5466.         if ((y = cmkey(dial_fc,4,"","auto",xxstring)) < 0) return(y);
  5467.         if ((x = cmcfm()) < 0) return(x);
  5468.         dialfc = y;
  5469.         return(success = 1);
  5470.  
  5471.       case XYDMTH: {                    /* DIAL METHOD */
  5472.         extern int dialmauto;
  5473.         if ((y = cmkey(dial_m,ndial_m,"","default",xxstring)) < 0)
  5474.           return(y);
  5475.         if ((x = cmcfm()) < 0)
  5476.           return(x);
  5477.         if (y == XYDM_A) {              /* AUTO */
  5478.             dialmauto = 1;              /* local country code, if known. */
  5479.             dialmth = XYDM_D;
  5480.         } else {
  5481.           dialmauto = 0;                /* use the method specified */
  5482.           dialmth = y;
  5483.         }
  5484.         return(success = 1);
  5485.       }
  5486.       case XYDRTM:
  5487.         y = cmnum("Number of times to try dialing a number",
  5488.                   "1",10,&x,xxstring);
  5489.     z = setnum(&dialrtr,x,y,-1);
  5490.     if (z > -1 && dialrtr < 0) {
  5491.         printf("?Sorry, negative dial retries not valid: %d\n",dialrtr);
  5492.         return(-9);
  5493.     }
  5494.         return(z);
  5495.  
  5496.       case XYDINT:
  5497.         y = cmnum("Seconds to wait between redial attempts",
  5498.                   "30",10,&x,xxstring);
  5499.         z = setnum(&dialint,x,y,-1);
  5500.     if (z > -1 && dialint < 0) {
  5501.         printf("?Sorry, negative dial interval not valid: %d\n",dialint);
  5502.         return(-9);
  5503.     }
  5504.         return(z);
  5505.  
  5506.       case XYDLAC:                      /* DIAL AREA-CODE */
  5507.         if ((x = dialstr(&diallac,"Area code you are calling from")) < 0)
  5508.           return(x);
  5509.         if (diallac) {
  5510.             if (!rdigits(diallac)) {
  5511.                 printf("?Sorry, area code must be numeric\n");
  5512.                 if (*diallac == '(')
  5513.                   printf("(please omit the parentheses)\n");
  5514.                 if (*diallac == '/')
  5515.                   printf("(no slashes, please)\n");
  5516.                 if (diallac) free(diallac);
  5517.                 diallac = NULL;
  5518.                 return(-9);
  5519.             }
  5520.         }
  5521.         return(x);
  5522.  
  5523.       case XYDCNF:                      /* CONFIRMATION */
  5524.         return(success = seton(&dialcnf));
  5525.  
  5526.       case XYDCVT:                      /* CONVERT-DIRECTORY */
  5527.         if ((y = cmkey(dcnvtab,3,"","ask",xxstring)) < 0)
  5528.           return(y);
  5529.         if ((x = cmcfm()) < 0)
  5530.           return(x);
  5531.         dialcvt = y;
  5532.         return(success = 1);
  5533.  
  5534.       case XYDLCC:                      /* DIAL COUNTRY-CODE */
  5535.         x = dialstr(&diallcc,"Country code you are calling from");
  5536.         if (x < 1) return(x);
  5537.         if (diallcc) {
  5538.             if (!rdigits(diallcc)) {
  5539.                 printf("?Sorry, country code must be numeric\n");
  5540.                 if (*diallcc == '+')
  5541.                   printf("(please omit the plus sign)\n");
  5542.                 if (diallcc) free(diallcc);
  5543.                 diallcc = NULL;
  5544.                 return(-9);
  5545.             }
  5546.             if (!strcmp(diallcc,"1")) { /* Set defaults for USA and Canada */
  5547.                 if (!dialldp)           /* Long-distance prefix */
  5548.                   makestr(&dialldp,"1");
  5549.                 if (!dialixp)           /* International dialing prefix */
  5550.                   makestr(&dialixp,"011");
  5551.                 if (ntollfree == 0) {   /* Toll-free area codes */
  5552.                     if ((dialtfc[0] = malloc(4))) {
  5553.                         strcpy(dialtfc[0],"800"); /* 1970-something */
  5554.                         ntollfree++;
  5555.                         if ((dialtfc[1] = malloc(4))) {
  5556.                             strcpy(dialtfc[1],"888"); /* 1996 */
  5557.                             ntollfree++;
  5558.                             if ((dialtfc[2] = malloc(4))) {
  5559.                                 strcpy(dialtfc[2],"877"); /* 5 April 1998 */
  5560.                                 ntollfree++;
  5561.                                 if ((dialtfc[3] = malloc(4))) {
  5562.                                     strcpy(dialtfc[3],"866"); /* 2000? */
  5563.                                     ntollfree++;
  5564.                                 }
  5565.                             }
  5566.                         }
  5567.                     }
  5568.                 }
  5569.                 if (!dialtfp)           /* Toll-free dialing prefix */
  5570.                   makestr(&dialtfp,"1");
  5571. #ifdef COMMENT
  5572. /* The time for this is past */
  5573.             } else if (!strcmp(diallcc,"358") &&
  5574.                        ((int) strcmp(zzndate(),"19961011") > 0)
  5575.                        ) {              /* Finland */
  5576.                 if (!dialldp)           /* Long-distance prefix */
  5577.                   makestr(&dialldp,"9");
  5578.                 if (!dialixp)           /* International dialing prefix */
  5579.                   makestr(&dialixp,"990");
  5580. #endif /* COMMENT */
  5581.             } else {                    /* Everywhere else ... */
  5582.                 if (!dialldp) {
  5583.                     if ((dialldp = malloc(4)))
  5584.                       strcpy(dialldp,"0");
  5585.                 }
  5586.                 if (!dialixp) {
  5587.                     if ((dialixp = malloc(4)))
  5588.                       strcpy(dialixp,"00");
  5589.                 }
  5590.             }
  5591.             if (!strcmp(diallcc,"33"))  /* France */
  5592.               dialfld = 1;              /* Long-distance dialing is forced */
  5593.         }
  5594.         return(success = 1);
  5595.  
  5596.       case XYDIXP:                      /* DIAL INTL-PREFIX */
  5597.         return(dialstr(&dialixp,"International dialing prefix"));
  5598.  
  5599.       case XYDIXS:                      /* DIAL INTL-SUFFIX */
  5600.         return(dialstr(&dialixs,"International dialing suffix"));
  5601.  
  5602.       case XYDLDP:                      /* DIAL LD-PREFIX */
  5603.         return(dialstr(&dialldp,"Long-distance dialing prefix"));
  5604.  
  5605.       case XYDLDS:                      /* DIAL LD-SUFFIX */
  5606.         return(dialstr(&diallds,"Long-distance dialing suffix"));
  5607.  
  5608.       case XYDLCP:                      /* DIAL LC-PREFIX */
  5609.         return(dialstr(&diallcp,"Local dialing prefix"));
  5610.  
  5611.       case XYDLCS:                      /* DIAL LC-SUFFIX */
  5612.         return(dialstr(&diallcs,"Local dialing suffix"));
  5613.  
  5614. #ifdef COMMENT
  5615.       case XYDPXX:                      /* DIAL PBX-EXCHANGE */
  5616.         return(dialstr(&dialpxx,"Exchange of PBX you are calling from"));
  5617. #endif /* COMMENT */
  5618.  
  5619.       case XYDPXI: {                    /* DIAL PBX-INTERNAL-PREFIX */
  5620. #ifdef COMMENT
  5621.           return(dialstr(&dialpxi,
  5622.                        "Internal-call prefix of PBX you are calling from"));
  5623. #else
  5624.           int x;
  5625.           if ((x = cmtxt("Internal-call prefix of PBX you are calling from",
  5626.                          "",&s,NULL)) < 0) /* Don't evaluate */
  5627.             return(x);
  5628. #ifndef NOSPL
  5629.           if (*s) {
  5630.               char c, * p = tmpbuf;
  5631.               if (*s == '\\') {
  5632.                   c = *(s+1);
  5633.                   if (isupper(c)) c = tolower(c);
  5634.                   if (c != 'f' &&
  5635.                       ckstrcmp(s,"\\v(d$px)",8,0) &&
  5636.                       ckstrcmp(s,"\\v(d$pxx)",9,0) &&
  5637.                       ckstrcmp(s,"\\v(d$p)",7,0)) {
  5638.                       x = TMPBUFSIZ;
  5639.                       zzstring(s,&p,&x);
  5640.                       s = tmpbuf;
  5641.                   }
  5642.               }
  5643.           }
  5644. #endif /* NOSPL */
  5645.           makestr(&dialpxi,s);
  5646.           return(1);
  5647.       }
  5648. #endif /* COMMENT */
  5649.  
  5650.       case XYDPXO:                      /* DIAL PBX-OUTSIDE-PREFIX */
  5651.         return(dialstr(&dialpxo,
  5652.                        "Outside-line prefix of PBX you are calling from"));
  5653.  
  5654.       case XYDSFX:                      /* DIAL INTL-SUFFIX */
  5655.         return(dialstr(&dialsfx," Telephone number suffix for dialing"));
  5656.  
  5657.       case XYDSRT:                      /* DIAL SORT */
  5658.         return(success = seton(&dialsrt));
  5659.  
  5660.       case XYDPXX:                      /* DIAL PBX-EXCHANGE */
  5661.       case XYDTFC: {                    /* DIAL TOLL-FREE-AREA-CODE  */
  5662.           int n, i;                     /* (zero or more of them...) */
  5663.           char * p[MAXTOLLFREE];        /* Temporary pointers */
  5664.           char * m;
  5665.           for (n = 0; n < MAXTOLLFREE; n++) {
  5666.               if (n == 0) {
  5667.                   m = (y == XYDTFC) ?
  5668.                   "Toll-free area code(s) in the country you are calling from"
  5669.                     : "Exchange(s) of PBX you are calling from";
  5670.               } else {
  5671.                   m = (y == XYDTFC) ?
  5672.                     "Another toll-free area code"
  5673.                       : "Another PBX exchange";
  5674.               }
  5675.               if ((x = cmfld(m,"",&s,xxstring)) < 0)
  5676.                 break;
  5677.               if (s) {
  5678.                   int k;
  5679.                   k = (int) strlen(s);
  5680.                   if (k > 0) {
  5681.                       if ((p[n] = malloc(k + 1)))
  5682.                         strcpy(p[n], s); /* safe */
  5683.                   } else break;
  5684.               } else break;
  5685.           }
  5686.           if (x == -3) {                /* Command was successful */
  5687.               int m;
  5688.               m = (y == XYDTFC) ? ntollfree : ndialpxx;
  5689.               if ((x = cmcfm()) < 0)
  5690.                 return(x);
  5691.               x = 1;
  5692.               for (i = 0; i < m; i++) { /* Remove old list, if any */
  5693.                   if  (y == XYDTFC)
  5694.                     makestr(&(dialtfc[i]),NULL);
  5695.                   else
  5696.                     makestr(&(dialpxx[i]),NULL);
  5697.               }
  5698.               if  (y == XYDTFC)
  5699.                 ntollfree = n;          /* New count */
  5700.               else
  5701.                 ndialpxx = n;
  5702.               for (i = 0; i < n; i++) { /* New list */
  5703.                   if  (y == XYDTFC)
  5704.                     makestr(&(dialtfc[i]),p[i]);
  5705.                   else
  5706.                     makestr(&(dialpxx[i]),p[i]);
  5707.               }
  5708.               x = 1;
  5709.           }
  5710.           for (i = 0; i < n; i++)
  5711.             if (p[i]) free(p[i]);
  5712.           return(x);
  5713.       }
  5714.  
  5715.       case XYDTFP:                      /* TOLL-FREE-PREFIX */
  5716.         return(dialstr(&dialtfp,
  5717.                        " Long-distance prefix for toll-free dialing"));
  5718.  
  5719.       case XYDCON:                      /* CONNECT */
  5720.         z = -1;
  5721.         if ((y = cmkey(crrtab,ncrr,"","auto",xxstring)) < 0) return(y);
  5722.         if (y != CAR_OFF)               /* AUTO or ON? */
  5723.           if ((z = cmkey(qvtab,nqvt,"","verbose",xxstring)) < 0) return(z);
  5724.         if ((x = cmcfm()) < 0) return(x);
  5725.         if (z > -1)
  5726.           dialcq = z;
  5727.         dialcon = y;
  5728.         return(success = 1);
  5729.  
  5730.       case XYDRSTR:                     /* RESTRICT */
  5731.         if ((y = cmkey(drstrtab,4,"","none",xxstring)) < 0) return(y);
  5732.         if ((x = cmcfm()) < 0) return(x);
  5733.         dialrstr = y;
  5734.         return(success = 1);
  5735.  
  5736.       case XYDLLAC: {                   /* Local area-code list  */
  5737.           int n, i;                     /* (zero or more of them...) */
  5738.           char * p[MAXLOCALAC]; /* Temporary pointers */
  5739.           for (n = 0; n < MAXLOCALAC; n++) {
  5740.               if ((x = cmfld(
  5741.                     "Area code to which calls from your area are local",
  5742.                        "",&s,xxstring)) < 0)
  5743.                 break;
  5744.               if (s) {
  5745.                   int k;
  5746.                   k = (int) strlen(s);
  5747.                   if (k > 0) {
  5748.                       if ((p[n] = malloc(k + 1)))
  5749.                         strcpy(p[n], s); /* safe */
  5750.                   } else break;
  5751.               } else break;
  5752.           }
  5753.           if (x == -3) {                /* Command was successful */
  5754.               if ((x = cmcfm()) < 0)
  5755.                 return(x);
  5756.               for (i = 0; i < nlocalac; i++) /* Remove old list, if any */
  5757.                 if (diallcac[i]) {
  5758.                     free(diallcac[i]);
  5759.                     diallcac[i] = NULL;
  5760.                 }
  5761.               nlocalac = n;             /* New count */
  5762.               for (i = 0; i < nlocalac; i++) /* New list */
  5763.                 diallcac[i] = p[i];
  5764.               return(success = 1);
  5765.           } else {                      /* Parse error, undo everything */
  5766.               for (i = 0; i < n; i++)
  5767.                 if (p[i]) free(p[i]);
  5768.               return(x);
  5769.           }
  5770.       }
  5771.  
  5772.       case XYDFLD:
  5773.         return(success = seton(&dialfld));
  5774.  
  5775.       case XYDIDT:                      /* DIAL IGNORE-DIALTONE */
  5776.         return(seton(&dialidt));
  5777.  
  5778.       case XYDPAC:
  5779.         y = cmnum(
  5780.               "Milliseconds to pause between each character sent to dialer",
  5781.                   "",10,&x,xxstring);
  5782.         return(setnum(&dialpace,x,y,9999));
  5783.  
  5784. #ifndef NOSPL
  5785.       case XYDMAC:
  5786.         if ((x = cmfld("Name of macro to execute just prior to dialing",
  5787.                        "",&s,xxstring)) < 0) {
  5788.             if (x == -3)
  5789.               s = NULL;
  5790.             else
  5791.               return(x);
  5792.         }
  5793.         if (s) {
  5794.             if (!*s) {
  5795.                 s = NULL;
  5796.             } else {
  5797.                 ckstrncpy(line,s,LINBUFSIZ);
  5798.                 s = line;
  5799.             }
  5800.         }
  5801.         if ((x = cmcfm()) < 0)
  5802.           return(x);
  5803.         makestr(&dialmac,s);
  5804.         return(success = 1);
  5805. #endif /* NOSPL */
  5806.  
  5807.       case XYDPUCC:                     /* Pulse country codes */
  5808.       case XYDTOCC: {                   /* Tone country codes */
  5809.           int n, i;
  5810.           char * p[MAXTPCC];
  5811.           char * m;
  5812.           for (n = 0; n < MAXTPCC; n++) {
  5813.               if (n == 0) {
  5814.                   m = (y == XYDPUCC) ?
  5815.                   "Country code where Pulse dialing is required"
  5816.                     : "Country code where Tone dialing is available";
  5817.               } else
  5818.                 m = "Another country code";
  5819.               if ((x = cmfld(m,"",&s,xxstring)) < 0)
  5820.                 break;
  5821.               if (s) {
  5822.                   int k;
  5823.                   k = (int) strlen(s);
  5824.                   if (k > 0) {
  5825.                       if ((p[n] = malloc(k + 1)))
  5826.                         strcpy(p[n], s); /* safe */
  5827.                   } else break;
  5828.               } else break;
  5829.           }
  5830.           if (x == -3) {                /* Command was successful */
  5831.               int m;
  5832.               m = (y == XYDPUCC) ? ndialpucc : ndialtocc;
  5833.               if ((x = cmcfm()) < 0)
  5834.                 return(x);
  5835.               x = 1;
  5836.               for (i = 0; i < m; i++) { /* Remove old list, if any */
  5837.                   if (y == XYDPUCC)
  5838.                     makestr(&(dialpucc[i]),NULL);
  5839.                   else
  5840.                     makestr(&(dialtocc[i]),NULL);
  5841.               }
  5842.               if (y == XYDPUCC) {
  5843.                   ndialpucc = n;                /* New count */
  5844.               } else {
  5845.                   ndialtocc = n;
  5846.               }
  5847.               for (i = 0; i < n; i++) { /* New list */
  5848.                   if (y == XYDPUCC) {
  5849.                       makestr(&(dialpucc[i]),p[i]);
  5850.                   } else {
  5851.                       makestr(&(dialtocc[i]),p[i]);
  5852.                   }
  5853.               }
  5854.               x = 1;
  5855.           }
  5856.           for (i = 0; i < n; i++)
  5857.             if (p[i]) free(p[i]);
  5858.           return(x);
  5859.       }
  5860.       case XYDTEST:
  5861.         return(seton(&dialtest));
  5862.  
  5863.       default:
  5864.         printf("?Unexpected SET DIAL parameter\n");
  5865.         return(-9);
  5866.     }
  5867. }
  5868.  
  5869. #ifndef NOSHOW
  5870. int                                     /* SHOW MODEM */
  5871. shomodem() {
  5872.     MDMINF * p;
  5873.     int x, n, mdm;
  5874.     char c;
  5875.     long zz;
  5876.  
  5877. #ifdef IKSD
  5878.     if (inserver) {
  5879.         printf("Sorry, command disabled\r\n");
  5880.         return(success = 0);
  5881.     }
  5882. #endif /* IKSD */
  5883.  
  5884.     shmdmlin();
  5885.     printf("\n");
  5886.  
  5887.     mdm = (mdmtyp > 0) ? mdmtyp : mdmsav;
  5888.     p = (mdm > 0) ? modemp[mdm] : NULL;
  5889.  
  5890.     if (p) {
  5891.         printf(" %s\n\n", dialname ? dialname : p->name);
  5892.  
  5893.         printf(" Modem capabilities:    ");
  5894.         zz = dialcapas ? dialcapas : p->capas;
  5895.         if (!zz) {
  5896.             printf(" (none)");
  5897.         } else {
  5898.             if (zz & CKD_AT) printf(" AT");
  5899.             if (zz & CKD_V25) printf(" ITU");
  5900.             if (zz & CKD_SB) printf(" SB");
  5901.             if (zz & CKD_EC) printf(" EC");
  5902.             if (zz & CKD_DC) printf(" DC");
  5903.             if (zz & CKD_HW) printf(" HWFC");
  5904.             if (zz & CKD_SW) printf(" SWFC");
  5905.             if (zz & CKD_KS) printf(" KS");
  5906.             if (zz & CKD_TB) printf(" TB");
  5907.         }
  5908.         printf("\n Modem carrier-watch:    ");
  5909.         if (carrier == CAR_OFF) printf("off\n");
  5910.         else if (carrier == CAR_ON) printf("on\n");
  5911.         else if (carrier == CAR_AUT) printf("auto\n");
  5912.         else printf("unknown\n");
  5913.  
  5914.         printf(" Modem maximum-speed:    ");
  5915.         zz = (dialmax > 0L) ? dialmax : p->max_speed;
  5916.         if (zz > 0)
  5917.           printf("%ld bps\n", zz);
  5918.         else
  5919.           printf("(unknown)\n");
  5920.         printf(" Modem error-correction: %s\n", dialec ? "on" : "off");
  5921.         printf(" Modem compression:      %s\n", dialdc ? "on" : "off");
  5922.         printf(" Modem speed-matching:   %s",   mdmspd ? "on" : "off");
  5923.         printf(" (interface speed %s)\n", mdmspd ? "changes" : "is locked");
  5924.         printf(" Modem flow-control:     ");
  5925.         if (dialfc == FLO_NONE) printf("none\n");
  5926.         else if (dialfc == FLO_XONX) printf("xon/xoff\n");
  5927.         else if (dialfc == FLO_RTSC) printf("rts/cts\n");
  5928.         else if (dialfc == FLO_AUTO) printf("auto\n");
  5929.         printf(" Modem hangup-method:    %s\n",
  5930.                dialmhu ?
  5931.                "modem-command" :
  5932.                "rs232-signal"
  5933.                );
  5934.         printf(" Modem speaker:          %s\n", showoff(mdmspk));
  5935.         printf(" Modem volume:           %s\n",
  5936.                (mdmvol == 2) ? "medium" : ((mdmvol <= 1) ? "low" : "high"));
  5937.         printf(" Modem kermit-spoof:     %s\n", dialksp ? "on" : "off");
  5938.         c = (char) (x = (dialesc ? dialesc : p->esc_char));
  5939.         printf(" Modem escape-character: %d", x);
  5940.         if (isprint(c))
  5941.           printf(" (= \"%c\")",c);
  5942.         printf(
  5943. "\n\nMODEM COMMANDs (* = set automatically by SET MODEM TYPE):\n\n");
  5944.         debug(F110,"show dialini",dialini,0);
  5945.         printf(" %c Init-string:          ", dialini ? ' ' : '*' );
  5946.         shods(dialini ? dialini : p->wake_str);
  5947.         printf(" %c Dial-mode-string:     ", dialmstr ? ' ' : '*' );
  5948.         shods(dialmstr ? dialmstr : p->dmode_str);
  5949.         n = local ? 19 : 20;
  5950.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5951.         printf(" %c Dial-mode-prompt:     ", dialmprmt ? ' ' : '*' );
  5952.         shods(dialmprmt ? dialmprmt : p->dmode_prompt);
  5953.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5954.         printf(" %c Dial-command:         ", dialcmd ? ' ' : '*' );
  5955.         shods(dialcmd ? dialcmd : p->dial_str);
  5956.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5957.         printf(" %c Compression on:       ", dialdcon ? ' ' : '*' );
  5958.         if (!dialdcon)
  5959.           debug(F110,"dialdcon","(null)",0);
  5960.         else
  5961.           debug(F110,"dialdcon",dialdcon,0);
  5962.         shods(dialdcon ? dialdcon : p->dc_on_str);
  5963.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5964.         printf(" %c Compression off:      ", dialdcoff ? ' ' : '*' );
  5965.         shods(dialdcoff ? dialdcoff : p->dc_off_str);
  5966.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5967.         printf(" %c Error-correction on:  ", dialecon ? ' ' : '*' );
  5968.         shods(dialecon ? dialecon : p->ec_on_str);
  5969.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5970.         printf(" %c Error-correction off: ", dialecoff ? ' ' : '*' );
  5971.         shods(dialecoff ? dialecoff : p->ec_off_str);
  5972.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5973.         printf(" %c Autoanswer on:        ", dialaaon ? ' ' : '*' );
  5974.         shods(dialaaon ? dialaaon : p->aa_on_str);
  5975.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5976.         printf(" %c Autoanswer off:       ", dialaaoff ? ' ' : '*' );
  5977.         shods(dialaaoff ? dialaaoff : p->aa_off_str);
  5978.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5979.  
  5980.         printf(" %c Speaker on:           ", dialspon ? ' ' : '*' );
  5981.         shods(dialspon ? dialspon : p->sp_on_str);
  5982.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5983.         printf(" %c Speaker off:          ", dialspoff ? ' ' : '*' );
  5984.         shods(dialspoff ? dialspoff : p->sp_off_str);
  5985.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5986.         printf(" %c Volume low:           ", dialvol1 ? ' ' : '*' );
  5987.         shods(dialvol1 ? dialvol1 : p->vol1_str);
  5988.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5989.         printf(" %c Volume medium:        ", dialvol2 ? ' ' : '*' );
  5990.         shods(dialvol2 ? dialvol2 : p->vol2_str);
  5991.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5992.         printf(" %c Volume high:          ", dialvol3 ? ' ' : '*' );
  5993.         shods(dialvol3 ? dialvol3 : p->vol3_str);
  5994.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5995.  
  5996.         printf(" %c Hangup-command:       ", dialhcmd ? ' ' : '*' );
  5997.         shods(dialhcmd ? dialhcmd : p->hup_str);
  5998.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5999.         printf(" %c Hardware-flow:        ", dialhwfc ? ' ' : '*' );
  6000.         shods(dialhwfc ? dialhwfc : p->hwfc_str);
  6001.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  6002.         printf(" %c Software-flow:        ", dialswfc ? ' ' : '*' );
  6003.         shods(dialswfc ? dialswfc : p->swfc_str);
  6004.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  6005.         printf(" %c No-flow-control:      ", dialnofc ? ' ' : '*' );
  6006.         shods(dialnofc ? dialnofc : p->nofc_str);
  6007.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  6008.         printf(" %c Pulse:                ", dialpulse ? ' ' : '*');
  6009.         shods(dialpulse ? dialpulse : p->pulse);
  6010.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  6011.         printf(" %c Tone:                 ", dialtone ? ' ' : '*');
  6012.         shods(dialtone ? dialtone : p->tone);
  6013.  
  6014.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  6015.         printf(" %c Ignore-dialtone:      ", dialx3 ? ' ' : '*');
  6016.         shods(dialx3 ? dialx3 : p->ignoredt);
  6017.  
  6018.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  6019.         printf(" %c Predial-init:         ", dialini2 ? ' ' : '*');
  6020.         shods(dialini2 ? dialini2 : p->ini2);
  6021.  
  6022.         if (++n > cmd_rows - 4) if (!askmore()) return(0); else n = 0;
  6023.         printf("\n For more info: SHOW DIAL and SHOW COMMUNICATIONS\n");
  6024.  
  6025.     } else if (mdm > 0) {
  6026.         printf("Modem info for \"%s\" not filled in yet\n", gmdmtyp());
  6027.     } else printf(
  6028. " No modem selected, so DIAL and most SET MODEM commands have no effect.\n\
  6029.  Use SET MODEM TYPE to select a modem.\n");
  6030.     return(success = 1);
  6031. }
  6032. #endif /* NOSHOW */
  6033. #endif /* NODIAL */
  6034.  
  6035. #ifdef CK_TAPI
  6036. int                                             /* TAPI action commands */
  6037. dotapi() {
  6038.     int x,y;
  6039.     char *s;
  6040.  
  6041.     if (!TAPIAvail) {
  6042.         printf("\nTAPI is unavailable on this system.\n");
  6043.         return(-9);
  6044.     }
  6045.     if ((y = cmkey(tapitab,ntapitab,"MS TAPI command","",xxstring)) < 0)
  6046.       return(y);
  6047.     switch (y) {
  6048.       case XYTAPI_CFG: {                        /* TAPI CONFIGURE-LINE */
  6049.           extern struct keytab * tapilinetab;
  6050.           extern struct keytab * _tapilinetab;
  6051.           extern int ntapiline;
  6052.           extern int LineDeviceId;
  6053.           int lineID=LineDeviceId;
  6054.           if (TAPIAvail)
  6055.             cktapiBuildLineTable(&tapilinetab, &_tapilinetab, &ntapiline);
  6056.           if (tapilinetab && _tapilinetab && ntapiline > 0) {
  6057.               int i=0, j = 9999, k = -1;
  6058.  
  6059.               if ( LineDeviceId == -1 ) {
  6060.                   /* Find out what the lowest numbered TAPI device is */
  6061.                   /* and use it as the default.                       */
  6062.                   for (i = 0; i < ntapiline; i++ ) {
  6063.                       if (tapilinetab[i].kwval < j) {
  6064.                           k = i;
  6065.                       }
  6066.                   }
  6067.               } else {
  6068.                   /* Find the LineDeviceId in the table and use that entry */
  6069.                   for (i = 0; i < ntapiline; i++ ) {
  6070.                       if (tapilinetab[i].kwval == LineDeviceId) {
  6071.                           k = i;
  6072.                           break;
  6073.                       }
  6074.                   }
  6075.               }
  6076.               if (k >= 0)
  6077.                 s = _tapilinetab[k].kwd;
  6078.               else
  6079.                 s = "";
  6080.  
  6081.               if ((y = cmkey(_tapilinetab,ntapiline,
  6082.                               "TAPI device name",s,xxstring)) < 0)
  6083.                 return(y);
  6084.               lineID = y;
  6085.           }
  6086.           if ((x = cmcfm()) < 0) return(x);
  6087. #ifdef IKSD
  6088.           if (inserver) {
  6089.               printf("Sorry, command disabled\r\n");
  6090.               return(success = 0);
  6091.           }
  6092. #endif /* ISKD */
  6093.           cktapiConfigureLine(lineID);
  6094.           break;
  6095.       }
  6096.       case XYTAPI_DIAL:                 /* TAPI DIALING-PROPERTIES */
  6097.         if ((x = cmcfm()) < 0)
  6098.           return(x);
  6099. #ifdef IKSD
  6100.         if (inserver) {
  6101.             printf("Sorry, command disabled\r\n");
  6102.             return(success = 0);
  6103.         }
  6104. #endif /* ISKD */
  6105.         cktapiDialingProp();
  6106.         break;
  6107.     }
  6108.     return(success = 1);
  6109. }
  6110.  
  6111. static int                              /* SET TAPI command options */
  6112. settapi() {
  6113.     int x, y;
  6114.     char *s;
  6115.  
  6116.     if (!TAPIAvail) {
  6117.         printf("\nTAPI is unavailable on this system.\n");
  6118.         return(-9);
  6119.     }
  6120.     if ((y = cmkey(settapitab,nsettapitab,"MS TAPI option","",xxstring)) < 0)
  6121.       return(y);
  6122.     switch (y) {
  6123.       case XYTAPI_USE:
  6124.         return (success = seton(&tapiusecfg));
  6125.       case XYTAPI_LGHT:
  6126.         return (success = seton(&tapilights));
  6127.       case XYTAPI_PRE:
  6128.         return (success = seton(&tapipreterm));
  6129.       case XYTAPI_PST:
  6130.         return (success = seton(&tapipostterm));
  6131.       case XYTAPI_INA:
  6132.         y = cmnum("seconds of inactivity before auto-disconnect",
  6133.                   "0",10,&x,xxstring);
  6134.         return(setnum(&tapiinactivity,x,y,65535));
  6135.       case XYTAPI_BNG:
  6136.         y = cmnum("seconds to wait for credit card tone",
  6137.                   "8",10,&x,xxstring);
  6138.         return(setnum(&tapibong,x,y,90));
  6139.       case XYTAPI_MAN:
  6140.         return (success = seton(&tapimanual));
  6141.       case XYTAPI_CON:                  /* TAPI CONVERSIONS */
  6142.         return (success = setonaut(&tapiconv));
  6143.       case XYTAPI_LIN:                  /* TAPI LINE */
  6144.         x = setlin(XYTAPI_LIN,1,0);
  6145.         if (x > -1) didsetlin++;
  6146.         return(x);
  6147.       case XYTAPI_PASS: {               /* TAPI PASSTHROUGH */
  6148. #ifdef NODIAL
  6149.           printf("\n?Modem-dialing not supported\n");
  6150.           return(-9);
  6151. #else /* NODIAL */
  6152.           /* Passthrough became Modem-dialing which is an antonym */
  6153.           success = seton(&tapipass);
  6154.           tapipass = !tapipass;
  6155.           return (success);
  6156. #endif /* NODIAL */        
  6157.       }
  6158.       case XYTAPI_LOC: {                /* TAPI LOCATION */
  6159.           extern char tapiloc[];
  6160.           extern int tapilocid;
  6161.           int i = 0, j = 9999, k = -1;
  6162.  
  6163.           cktapiBuildLocationTable(&tapiloctab, &ntapiloc);
  6164.           if (!tapiloctab || !ntapiloc) {
  6165.               printf("\nNo TAPI Locations are configured for this system\n");
  6166.               return(-9);
  6167.           }
  6168.           if (tapilocid == -1)
  6169.             tapilocid = cktapiGetCurrentLocationID();
  6170.  
  6171.           /* Find the current tapiloc entry */
  6172.           /* and use it as the default. */
  6173.           for (k = 0; k < ntapiloc; k++) {
  6174.               if (tapiloctab[k].kwval == tapilocid)
  6175.                 break;
  6176.           }
  6177.           if (k >= 0 && k < ntapiloc)
  6178.             s = tapiloctab[k].kwd;
  6179.           else
  6180.             s = "";
  6181.  
  6182.           if ((y = cmkey(tapiloctab,ntapiloc, "TAPI location",s,xxstring)) < 0)
  6183.             return(y);
  6184.  
  6185.           if ((x = cmcfm()) < 0)
  6186.             return(x);
  6187. #ifdef IKSD
  6188.           if (inserver) {
  6189.               printf("Sorry, command disabled\r\n");
  6190.               return(success = 0);
  6191.           }
  6192. #endif /* IKSD */
  6193.           cktapiFetchLocationInfoByID( y );
  6194. #ifndef NODIAL
  6195.           CopyTapiLocationInfoToKermitDialCmd();
  6196. #endif /* NODIAL */
  6197.         }
  6198.         break;
  6199.     }
  6200.     return(success=1);
  6201. }
  6202. #endif /* CK_TAPI */
  6203. #endif /* NOLOCAL */
  6204.  
  6205. #ifndef NOSPL
  6206. #ifdef CK_ANSIC                         /* SET ALARM */
  6207. int
  6208. setalarm(long xx)
  6209. #else
  6210. int
  6211. setalarm(xx) long xx;
  6212. #endif /* CK_ANSIC */
  6213. /* setalarm */ {
  6214. #ifdef COMMENT
  6215.     int yyyy, mm, dd, x;
  6216.     char *s;
  6217.     long zz;
  6218.     char buf[6];
  6219. #endif /* COMMENT */
  6220.     long sec, jd;
  6221.     char xbuf[20], * p;
  6222.  
  6223.     debug(F101,"setalarm xx","",xx);
  6224.     ck_alarm = 0L;                      /* 0 = no alarm (in case of error) */
  6225.     if (xx < 0L) {
  6226.         printf("%ld - illegal value, must be 0 or positive\n", xx);
  6227.         return(-9);
  6228.     }
  6229.     if (xx == 0L) {                     /* CLEAR ALARM */
  6230.         alrm_date[0] = NUL;
  6231.         alrm_time[0] = NUL;
  6232.         return(1);
  6233.     }
  6234. #ifdef COMMENT
  6235.     x = 8;                              /* Get current date */
  6236.     s = alrm_date;
  6237.     if (zzstring("\\v(ndate)",&s,&x) < 0) {
  6238.         printf("Internal date error, sorry.\n");
  6239.         alrm_date[0] = SP;
  6240.         return(-9);
  6241.     }
  6242.     x = 5;                              /* Get current time */
  6243.     s = alrm_time;
  6244.     if (zzstring("\\v(ntime)",&s,&x) < 0) {
  6245.         printf("Internal time error, sorry.\n");
  6246.         alrm_time[0] = SP;
  6247.         return(-9);
  6248.     }
  6249.     sprintf(buf,"%05ld",atol(alrm_time)); /* SAFE (20) */
  6250.     ckstrncpy(alrm_time,buf,8);
  6251.     debug(F110,"SET ALARM date (1)",alrm_date,0);
  6252.     debug(F110,"SET ALARM time (1)",alrm_time,0);
  6253.  
  6254.     if ((zz = atol(alrm_time) + xx) < 0L) {
  6255.         printf("Internal time conversion error, sorry.\n");
  6256.         return(-9);
  6257.     }
  6258.     if (zz >= 86400L) {                 /* Alarm crosses midnight */
  6259.         char d[10];                     /* Local date buffer */
  6260.         int lastday;                    /* Last day of this month */
  6261.  
  6262.         ckstrncpy(d,alrm_date,8);       /* We'll have to change the date */
  6263.  
  6264.         x = (zz / 86400L);              /* How many days after today */
  6265.  
  6266.         dd = atoi((char *)(d+6));       /* Parse yyyymmdd */
  6267.         d[6] = NUL;                     /* into yyyy, mm, dd ... */
  6268.         mm = atoi((char *)(d+4));
  6269.         d[4] = NUL;
  6270.         yyyy = atoi((char *)d);
  6271.  
  6272.         /* How many days in this month */
  6273.  
  6274.         lastday = mdays[mm];
  6275.         if (mm == 2 && yyyy % 4 == 0)   /* Works thru 2099 AD... */
  6276.           lastday++;
  6277.  
  6278.         if (dd + x > lastday) {         /* Dumb loop */
  6279.             int y;
  6280.  
  6281.             x -= (mdays[mm] - dd);      /* Deduct rest of this month's days */
  6282.  
  6283.             /* There's a more elegant way to do this... */
  6284.  
  6285.             while (1) {
  6286.                 mm++;                   /* Next month */
  6287.                 if (mm > 12) {          /* Wrap around */
  6288.                     mm = 1;             /* Jan, next year */
  6289.                     yyyy++;
  6290.                 }
  6291.                 y = mdays[mm];          /* Days in new month */
  6292.                 if (mm == 2 && yyyy % 4 == 0) /* Feb in leap year */
  6293.                   y++;                  /* Works until 2100 AD */
  6294.                 if (x - y < 1)
  6295.                   break;
  6296.                 x -= y;
  6297.             }
  6298.             dd = x;                     /* Day of alarm month */
  6299.         } else dd += x;
  6300.  
  6301.         sprintf(alrm_date,"%04d%02d%02d",yyyy,mm,dd); /* SAFE (24) */
  6302.         zz = zz % 86400L;
  6303.     }
  6304.     sprintf(alrm_time,"%ld",zz);        /* SAFE (24) */
  6305.     debug(F110,"SET ALARM date (2)",alrm_date,0);
  6306.     debug(F110,"SET ALARM time (2)",alrm_time,0);
  6307.     ck_alarm = xx;
  6308. #else
  6309.     /* Jul 1998 */
  6310.     ckstrncpy(xbuf,ckcvtdate("",1),20); /* Get current date and time */
  6311.     p = xbuf;
  6312.     ckstrncpy(alrm_date,xbuf,10);
  6313.     alrm_date[8] = NUL;
  6314.     sec = atol(p+9) * 3600L + atol(p+12) * 60L + atol(p+15);
  6315.     debug(F110,"SET ALARM date (1)",alrm_date,0);
  6316.     debug(F101,"SET ALARM time (1)","",sec);
  6317.     if ((sec += xx) < 0L) {
  6318.         printf("Internal time conversion error, sorry.\n");
  6319.         return(-9);
  6320.     }
  6321.     if (sec >= 86400L) {                /* Alarm crosses midnight */
  6322.         long days;
  6323.         days = sec / 86400L;
  6324.         jd = mjd(p) + days;             /* Get modified Julian date */
  6325.         ckstrncpy(alrm_date,mjd2date(jd),10);
  6326.         sec %= 86400L;
  6327.     }
  6328.     sprintf(alrm_time,"%05ld",sec);     /* SAFE (24) */
  6329.     debug(F110,"SET ALARM date (2)",alrm_date,0);
  6330.     debug(F110,"SET ALARM time (2)",alrm_time,0);
  6331.     ck_alarm = 1;                       /* Alarm is set */
  6332.  
  6333. #endif /* COMMENT */
  6334.     return(success = 1);
  6335. }
  6336. #endif /* NOSPL */
  6337.  
  6338. #ifndef NOSETKEY
  6339. int
  6340. dosetkey() {                            /* SET KEY */
  6341.     int x, y;
  6342.     int flag = 0;
  6343.     int kc;                             /* Key code */
  6344.     char *s;                            /* Key binding */
  6345. #ifndef NOKVERBS
  6346.     char *p;                            /* Worker */
  6347. #endif /* NOKVERBS */
  6348. #ifdef OS2
  6349.     extern int os2gks;
  6350.     extern int mskkeys;
  6351.     extern int initvik;
  6352. #endif /* OS2 */
  6353.  
  6354.     x_ifnum = 1;
  6355.     y = cmnum("numeric key code, or the word CLEAR,","",10,&kc,xxstring);
  6356.     x_ifnum = 0;
  6357.     if (y < 0) {
  6358.         debug(F111,"SET KEY",atmbuf,y);
  6359.         if (y == -2) {                  /* Not a valid number */
  6360.             if ((y = strlen(atmbuf)) < 0) /* Check for SET KEY CLEAR */
  6361.               return(-2);
  6362.             if (ckstrcmp(atmbuf,"clear",y,0))
  6363.               return(-2);
  6364.             if ((x = cmcfm()) < 0)
  6365.               return(x);
  6366.             for (y = 0; y < KMSIZE; y++) {
  6367.                 keymap[y] = (KEY) y;
  6368.                 macrotab[y] = NULL;
  6369.             }
  6370. #ifdef OS2
  6371.             keymapinit();               /* Special OS/2 initializations */
  6372.             initvik = 1;                /* Update the VIK table */
  6373. #endif /* OS2 */
  6374.             return(1);
  6375.         } else if (y == -3) {           /* SET KEY <Return> */
  6376.             printf(" Press key to be defined: "); /* Prompt for a keystroke */
  6377. #ifdef UNIX
  6378. #ifdef NOSETBUF
  6379.             fflush(stdout);
  6380. #endif /* NOSETBUF */
  6381. #endif /* UNIX */
  6382.             conbin((char)escape);       /* Put terminal in binary mode */
  6383. #ifdef OS2
  6384.             os2gks = 0;                 /* Turn off Kverb preprocessing */
  6385. #endif /* OS2 */
  6386.             kc = congks(0);             /* Get character or scan code */
  6387. #ifdef OS2
  6388.             os2gks = 1;                 /* Turn on Kverb preprocessing */
  6389. #endif /* OS2 */
  6390.             concb((char)escape);        /* Restore terminal to cbreak mode */
  6391.             if (kc < 0) {               /* Check for error */
  6392.                 printf("?Error reading key\n");
  6393.                 return(0);
  6394.             }
  6395. #ifdef OS2
  6396.             shokeycode(kc,-1);          /* Show current definition */
  6397. #else
  6398.             shokeycode(kc);             /* Show current definition */
  6399. #endif /* OS2 */
  6400.             flag = 1;                   /* Remember it's a multiline command */
  6401.         } else                          /* Error */
  6402.           return(y);
  6403.     }
  6404.  
  6405.     /* Normal SET KEY <scancode> <value> command... */
  6406.  
  6407. #ifdef OS2
  6408.     if (mskkeys)
  6409.       kc = msktock(kc);
  6410. #endif /* OS2 */
  6411.  
  6412.     if (kc < 0 || kc >= KMSIZE) {
  6413.         printf("?key code must be between 0 and %d\n", KMSIZE - 1);
  6414.         return(-9);
  6415.     }
  6416.     if (kc == escape) {
  6417.         printf("Sorry, %d is the CONNECT-mode escape character\n",kc);
  6418.         return(-9);
  6419.     }
  6420. #ifdef OS2
  6421.     wideresult = -1;
  6422. #endif /* OS2 */
  6423.     if (flag) {
  6424.         cmsavp(psave,PROMPTL);
  6425.         cmsetp(" Enter new definition: ");
  6426.         cmini(ckxech);
  6427.         cmflgs = 0;
  6428.         prompt(NULL);
  6429.     }
  6430.   def_again:
  6431.     if (flag)
  6432.       cmres();
  6433.     if ((y = cmtxt("key definition,\n\
  6434. or Ctrl-C to cancel this command,\n\
  6435. or Enter to restore default definition",
  6436.                    "",&s,NULL)) < 0) {
  6437.         if (flag)                       /* Handle parse errors */
  6438.           goto def_again;
  6439.         else
  6440.           return(y);
  6441.     }
  6442.     s = brstrip(s);
  6443. #ifndef NOKVERBS
  6444.     p = s;                              /* Save this place */
  6445. #endif /* NOKVERBS */
  6446. /*
  6447.   If the definition included any \Kverbs, quote the backslash so the \Kverb
  6448.   will still be in the definition when the key is pressed.  We don't do this
  6449.   in zzstring(), because \Kverbs are valid only in this context and nowhere
  6450.   else.
  6451.  
  6452.   We use this code active for all versions that support SET KEY, even if they
  6453.   don't support \Kverbs, because otherwise \K would behave differently for
  6454.   different versions.
  6455. */
  6456.     for (x = 0, y = 0; s[x]; x++, y++) { /* Convert \K to \\K */
  6457.         if ((x > 0) &&
  6458.             (s[x] == 'K' || s[x] == 'k')
  6459.             ) {                         /* Have K */
  6460.  
  6461.             if ((x == 1 && s[x-1] == CMDQ) ||
  6462.                 (x > 1 && s[x-1] == CMDQ && s[x-2] != CMDQ)) {
  6463.                 line[y++] = CMDQ;       /* Make it \\K */
  6464.             }
  6465.             if (x > 1 && s[x-1] == '{' && s[x-2] == CMDQ) {
  6466.                 line[y-1] = CMDQ;       /* Have \{K */
  6467.                 line[y++] = '{';        /* Make it \\{K */
  6468.             }
  6469.         }
  6470.         line[y] = s[x];
  6471.     }
  6472.     line[y++] = NUL;                    /* Terminate */
  6473.     s = line + y + 1;                   /* Point to after it */
  6474.     x = LINBUFSIZ - (int) strlen(line) - 1; /* Calculate remaining space */
  6475.     if ((x < (LINBUFSIZ / 2)) ||
  6476.         (zzstring(line, &s, &x) < 0)) { /* Expand variables, etc. */
  6477.         printf("?Key definition too long\n");
  6478.         if (flag) cmsetp(psave);
  6479.         return(-9);
  6480.     }
  6481.     s = line + y + 1;                   /* Point to result. */
  6482.  
  6483. #ifndef NOKVERBS
  6484. /*
  6485.   Special case: see if the definition starts with a \Kverb.
  6486.   If it does, point to it with p, otherwise set p to NULL.
  6487. */
  6488.     p = s;
  6489.     if (*p++ == CMDQ) {
  6490.         if (*p == '{') p++;
  6491.         p = (*p == 'k' || *p == 'K') ? p + 1 : NULL;
  6492.     }
  6493. #endif /* NOKVERBS */
  6494.  
  6495.     if (macrotab[kc]) {                 /* Possibly free old macro from key. */
  6496.         free((char *)macrotab[kc]);
  6497.         macrotab[kc] = NULL;
  6498.     }
  6499.     switch (strlen(s)) {                /* Action depends on length */
  6500.       case 0:                           /* Reset to default binding */
  6501.         keymap[kc] = (KEY) kc;
  6502.         break;
  6503.       case 1:                           /* Single character */
  6504.         keymap[kc] = (CHAR) *s;
  6505.         break;
  6506.       default:                          /* Character string */
  6507. #ifndef NOKVERBS
  6508.         if (p) {
  6509.             y = xlookup(kverbs,p,nkverbs,&x); /* Look it up */
  6510.             debug(F101,"set key kverb lookup",0,y); /* exact match required */
  6511.             if (y > -1) {
  6512.                 keymap[kc] = F_KVERB | y;
  6513.                 break;
  6514.             }
  6515.         }
  6516. #endif /* NOKVERBS */
  6517.         keymap[kc] = (KEY) kc;
  6518.         macrotab[kc] = (MACRO) malloc(strlen(s)+1);
  6519.         if (macrotab[kc])
  6520.           strcpy((char *) macrotab[kc], s); /* safe */
  6521.         break;
  6522.     }
  6523.     if (flag) cmsetp(psave);
  6524. #ifdef OS2
  6525.     initvik = 1;                        /* Update VIK table */
  6526. #endif /* OS2 */
  6527.     return(1);
  6528. }
  6529. #endif /* NOSETKEY */
  6530.  
  6531. #ifdef STOPBITS
  6532. struct keytab stoptbl[] = {
  6533.     { "1", 1, 0 },
  6534.     { "2", 2, 0 }
  6535. };
  6536. #endif /* STOPBITS */
  6537.  
  6538. static struct keytab sertbl[] = {
  6539.     { "7E1", 0, 0 },
  6540.     { "7E2", 1, 0 },
  6541.     { "7M1", 2, 0 },
  6542.     { "7M2", 3, 0 },
  6543.     { "7O1", 4, 0 },
  6544.     { "7O2", 5, 0 },
  6545.     { "7S1", 6, 0 },
  6546.     { "7S2", 7, 0 },
  6547. #ifdef HWPARITY
  6548.     { "8E1", 9, 0 },
  6549.     { "8E2", 10, 0 },
  6550. #endif /* HWPARITY */
  6551.     { "8N1", 8, 0 },
  6552. #ifdef HWPARITY
  6553.     { "8N2", 11, 0 },
  6554.     { "8O1", 12, 0 },
  6555.     { "8O2", 13, 0 },
  6556. #endif /* HWPARITY */
  6557.     { "", 0, 0 }
  6558. };
  6559. static int nsertbl = (sizeof(sertbl) / sizeof(struct keytab)) - 1;
  6560.  
  6561. static char * sernam[] = {              /* Keep this in sync with sertbl[] */
  6562.   "7E1", "7E2", "7M1", "7M2", "7O1", "7O2", "7S1", "7S2",
  6563.   "8N1", "8E1", "8E2", "8N2", "8O1", "8O2"
  6564. };
  6565.  
  6566. static struct keytab optstab[] = {      /* SET OPTIONS table */
  6567. #ifndef NOFRILLS
  6568.     { "delete",    XXDEL,   0},            /* DELETE */
  6569. #endif /* NOFRILLS */
  6570.     { "directory", XXDIR,   0},         /* DIRECTORY */
  6571. #ifdef CKPURGE
  6572.     { "purge",     XXPURGE, 0},         /* PURGE */
  6573. #endif /* CKPURGE */
  6574.     { "type",      XXTYP,   0},         /* TYPE */
  6575.     { "", 0, 0}
  6576. };
  6577. static int noptstab =  (sizeof(optstab) / sizeof(struct keytab)) - 1;
  6578.  
  6579. #ifndef NOXFER
  6580. /*
  6581.   PROTOCOL SELECTION.  Kermit is always available.  If CK_XYZ is defined at
  6582.   compile time, then the others become selections also.  In OS/2 and
  6583.   Windows, they are integrated and the various SET commands (e.g. "set file
  6584.   type") affect them as they would Kermit.  In other OS's (UNIX, VMS, etc),
  6585.   they are external protocols which are run via Kermit's REDIRECT mechanism.
  6586.   All we do is collect and verify the filenames and pass them along to the
  6587.   external protocol.
  6588. */
  6589. struct keytab protos[] = {
  6590. #ifdef CK_XYZ
  6591.     "g",          PROTO_G,  CM_INV,
  6592. #endif /* CK_XYZ */
  6593.     "kermit",     PROTO_K,  0,
  6594. #ifdef CK_XYZ
  6595.     "other",      PROTO_O,  0,
  6596.     "x",          PROTO_X,  CM_INV|CM_ABR,
  6597.     "xmodem",     PROTO_X,  0,
  6598.     "xmodem-crc", PROTO_XC, 0,
  6599.     "y",          PROTO_Y,  CM_INV|CM_ABR,
  6600.     "ymodem",     PROTO_Y,  0,
  6601.     "ymodem-g",   PROTO_G,  0,
  6602.     "zmodem",     PROTO_Z,  0
  6603. #endif /* CK_XYZ */
  6604. };
  6605. int nprotos =  (sizeof(protos) / sizeof(struct keytab));
  6606.  
  6607. #define XPCMDLEN 71
  6608.  
  6609. _PROTOTYP(static int protofield, (char *, char *, char *));
  6610. _PROTOTYP(static int setproto, (void));
  6611.  
  6612. static int
  6613. protofield(current, help, px) char * current, * help, * px; {
  6614.  
  6615.     char *s, tmpbuf[XPCMDLEN+1];
  6616.     int x;
  6617.  
  6618.     if (current)                        /* Put braces around default */
  6619.       ckmakmsg(tmpbuf,TMPBUFSIZ,"{",current,"}",NULL);
  6620.     else
  6621.       tmpbuf[0] = NUL;
  6622.  
  6623.     if ((x = cmfld(help, (char *)tmpbuf, &s, xxstring)) < 0)
  6624.       return(x);
  6625.     if ((int)strlen(s) > XPCMDLEN) {
  6626.         printf("?Sorry - maximum length is %d\n", XPCMDLEN);
  6627.         return(-9);
  6628.     } else if (*s) {
  6629.         strcpy(px,s);                   /* safe */
  6630.     } else {
  6631.         px = NULL;
  6632.     }
  6633.     return(x);
  6634. }
  6635.  
  6636. static int
  6637. setproto() {                            /* Select a file transfer protocol */
  6638.     /* char * s = NULL; */
  6639.     int x = 0, y;
  6640.     char s1[XPCMDLEN+1], s2[XPCMDLEN+1], s3[XPCMDLEN+1];
  6641.     char s4[XPCMDLEN+1], s5[XPCMDLEN+1], s6[XPCMDLEN+1], s7[XPCMDLEN+1];
  6642.     char * p1 = s1, * p2 = s2, *p3 = s3;
  6643.     char * p4 = s4, * p5 = s5, *p6 = s6, *p7 = s7;
  6644.  
  6645. #ifdef XYZ_INTERNAL
  6646.     extern int p_avail;
  6647. #else
  6648. #ifndef CK_REDIR
  6649.     x = 1;
  6650. #endif /* CK_REDIR */
  6651. #endif /* XYZ_INTERNAL */
  6652.     s1[0] = NUL;
  6653.     s2[0] = NUL;
  6654.     s3[0] = NUL;
  6655.     s4[0] = NUL;
  6656.     s5[0] = NUL;
  6657.     s6[0] = NUL;
  6658.  
  6659.     if ((y = cmkey(protos,nprotos,"","kermit",xxstring)) < 0)
  6660.       return(y);
  6661.  
  6662.     if (x && y != PROTO_K) {
  6663.         printf(
  6664.            "?Sorry, REDIRECT capability required for external protocols.\n");
  6665.         return(-9);
  6666.     }
  6667.     if ((x = protofield(ptab[y].h_b_init,
  6668.      "Optional command to send to host prior to uploading in binary mode",
  6669.                p1)) < 0) {
  6670.         if (x == -3) {
  6671.             protocol = y;               /* Set protocol but don't change */
  6672.             return(1);                  /* anything else */
  6673.         } else
  6674.           return(x);
  6675.     }
  6676.     if ((x = protofield(ptab[y].h_t_init,
  6677.      "Optional command to send to host prior to uploading in text mode",
  6678.                p2)) < 0) {
  6679.         if (x == -3)
  6680.           goto protoexit;
  6681.         else
  6682.           return(x);
  6683.     }
  6684.  
  6685.     if (y == PROTO_K) {
  6686.         if ((x = protofield(ptab[y].h_x_init,
  6687.                     "Optional command to send to host to start Kermit server",
  6688.                             p3)) < 0) {
  6689.             if (x == -3)
  6690.               goto protoexit;
  6691.             else
  6692.               return(x);
  6693.         }
  6694.     }
  6695.  
  6696.  
  6697. #ifndef XYZ_INTERNAL                    /* If XYZMODEM are external... */
  6698.  
  6699.     if (y != PROTO_K) {
  6700.         if ((x = protofield(ptab[y].p_b_scmd,
  6701.                  "External command to SEND in BINARY mode with this protocol",
  6702.                             p4)) < 0) {
  6703.             if (x == -3)
  6704.               goto protoexit;
  6705.             else
  6706.               return(x);
  6707.         }
  6708.         if ((x = protofield(ptab[y].p_t_scmd,
  6709.                  "External command to SEND in TEXT mode with this protocol",
  6710.                             p5)) < 0) {
  6711.             if (x == -3)
  6712.               goto protoexit;
  6713.             else
  6714.               return(x);
  6715.         }
  6716.         if ((x = protofield(ptab[y].p_b_rcmd,
  6717.                "External command to RECEIVE in BINARY mode with this protocol",
  6718.                             p6)) < 0) {
  6719.             if (x == -3)
  6720.               goto protoexit;
  6721.             else
  6722.               return(x);
  6723.         }
  6724.         if ((x = protofield(ptab[y].p_t_rcmd,
  6725.                  "External command to RECEIVE in TEXT mode with this protocol",
  6726.                             p7)) < 0) {
  6727.             if (x == -3)
  6728.               goto protoexit;
  6729.             else
  6730.               return(x);
  6731.         }
  6732.     }
  6733. #endif /* XYZ_INTERNAL */
  6734.  
  6735.     if ((x = cmcfm()) < 0)              /* Confirm the command */
  6736.       return(x);
  6737.  
  6738. protoexit:                              /* Common exit from this routine */
  6739.  
  6740. #ifdef XYZ_INTERNAL
  6741.     if (!p_avail) {
  6742.         bleep(BP_WARN);
  6743.         printf("\n?X,Y, and Zmodem are unavailable\n");
  6744.         return(success = 0);
  6745.     }
  6746. #endif /* XYZ_INTERNAL */
  6747.  
  6748.     p1 = brstrip(p1);
  6749.     p2 = brstrip(p2);
  6750.     p3 = brstrip(p3);
  6751.     p4 = brstrip(p4);
  6752.     p5 = brstrip(p5);
  6753.     p6 = brstrip(p6);
  6754.     p7 = brstrip(p7);
  6755.     initproto(y,p1,p2,p3,p4,p5,p6,p7);
  6756.     return(success = 1);
  6757. }
  6758.  
  6759. int
  6760. setdest() {
  6761.     int x, y;
  6762.     if ((y = cmkey(desttab,ndests,"","disk",xxstring)) < 0) return(y);
  6763.     if ((x = cmcfm()) < 0) return(x);
  6764.     dest = y;
  6765.     return(1);
  6766. }
  6767. #endif /* NOXFER */
  6768.  
  6769. #ifdef DECNET
  6770. struct keytab dnettab[] = {
  6771. #ifndef OS2ONLY
  6772.     "cterm", NP_CTERM, 0,
  6773. #endif /* OS2ONLY */
  6774.     "lat",   NP_LAT,   0
  6775. };
  6776. int ndnet =  (sizeof(dnettab) / sizeof(struct keytab));
  6777. #endif /* DECNET */
  6778.  
  6779. /*  S E T P R I N T E R  --  SET PRINTER command  */
  6780.  
  6781. #ifdef PRINTSWI
  6782. static struct keytab prntab[] = {       /* SET PRINTER switches */
  6783.     "/bidirectional",    PRN_BID, 0,
  6784. #ifdef OS2
  6785.     "/character-set",    PRN_CS,  CM_ARG,
  6786. #endif /* OS2 */
  6787.     "/command",          PRN_PIP, CM_ARG,
  6788.     "/dos-device",       PRN_DOS, CM_ARG,
  6789.     "/end-of-job-string",PRN_TRM, CM_ARG,
  6790.     "/file",             PRN_FIL, CM_ARG,
  6791. #ifdef BPRINT
  6792.     "/flow-control",     PRN_FLO, CM_ARG,
  6793. #endif /* BPRINT */
  6794.     "/job-header-file",  PRN_SEP, CM_ARG,
  6795. #ifdef OS2
  6796.     "/length",           PRN_LEN, CM_ARG,
  6797. #endif /* OS2 */
  6798.     "/none",             PRN_NON, 0,
  6799. #ifdef OS2
  6800.     "/nopostscript",     PRN_RAW, 0,
  6801.     "/nops",             PRN_RAW, CM_INV,
  6802. #endif /* OS2 */
  6803.     "/output-only",      PRN_OUT, 0,
  6804. #ifdef BPRINT
  6805.     "/parity",           PRN_PAR, CM_ARG,
  6806. #endif /* BPRINT */
  6807.     "/pipe",             PRN_PIP, CM_ARG|CM_INV,
  6808. #ifdef OS2
  6809.     "/postscript",       PRN_PS,  0,
  6810.     "/ps",               PRN_PS,  CM_INV,
  6811. #endif /* OS2 */
  6812.     "/separator",        PRN_SEP, CM_ARG|CM_INV,
  6813. #ifdef BPRINT
  6814.     "/speed",            PRN_SPD, CM_ARG,
  6815. #endif /* BPRINT */
  6816.     "/timeout",          PRN_TMO, CM_ARG,
  6817.     "/terminator",       PRN_TRM, CM_ARG|CM_INV,
  6818. #ifdef OS2
  6819. #ifdef NT
  6820.     "/w",                PRN_WIN, CM_ARG|CM_ABR|CM_INV,
  6821.     "/wi",               PRN_WIN, CM_ARG|CM_ABR|CM_INV,
  6822. #endif /* NT */
  6823.     "/width",            PRN_WID, CM_ARG,
  6824. #endif /* OS2 */
  6825. #ifdef NT
  6826.     "/windows-queue",    PRN_WIN, CM_ARG,
  6827. #endif /* NT */
  6828.     "",                 0,      0
  6829. };
  6830. int nprnswi =  (sizeof(prntab) / sizeof(struct keytab)) - 1;
  6831. #endif /* PRINTSWI */
  6832.  
  6833. static int
  6834. setprinter(xx) int xx; {
  6835.     int x, y;
  6836.     char * s;
  6837.     char * defname = NULL;
  6838. #ifdef OS2
  6839.     extern int prncs;
  6840. #endif /* OS2 */
  6841.  
  6842. #ifdef BPRINT
  6843.     char portbuf[64];
  6844.     long portspeed = 0L;
  6845.     int portparity = 0;
  6846.     int portflow = 0;
  6847. #endif /* BPRINT */
  6848.  
  6849. #ifdef PRINTSWI
  6850.     int c, i, n, wild, confirmed = 0;   /* Workers */
  6851.     int getval = 0;                     /* Whether to get switch value */
  6852.     struct stringint pv[PRN_MAX+1];    /* Temporary array for switch values */
  6853.     struct FDB sw, of, cm;              /* FDBs for each parse function */
  6854.     int haveque = 0;
  6855.     int typeset = 0;
  6856. #endif /* PRINTSWI */
  6857.  
  6858. #ifdef NT
  6859.     struct keytab * printtab = NULL, * _printtab = NULL;
  6860.     int nprint = 0, printdef=0;
  6861. #endif /* NT */
  6862.  
  6863. #ifdef OS2
  6864.     defname = "PRN";                    /* default */
  6865. #else
  6866. #ifdef VMS
  6867.     defname = "LPT:";
  6868. #else
  6869. #ifdef UNIX
  6870.     defname = "|lpr";
  6871. #endif /* UNIX */
  6872. #endif /* VMS */
  6873. #endif /* OS2 */
  6874.  
  6875. #ifdef PRINTSWI
  6876. #ifdef NT
  6877.     haveque = Win32EnumPrt(&printtab,&_printtab,&nprint,&printdef);
  6878.     haveque = haveque && nprint;
  6879. #endif /* NT */
  6880.  
  6881.     for (i = 0; i <= PRN_MAX; i++) {    /* Initialize switch values */
  6882.         pv[i].sval = NULL;              /* to null pointers */
  6883.         pv[i].ival = -1;                /* and -1 int values */
  6884.         pv[i].wval = (CK_OFF_T)-1;    /* and -1 wide values */
  6885.     }
  6886.     if (xx == XYBDCP) {                 /* SET BPRINTER == /BIDIRECTIONAL */
  6887.         pv[PRN_BID].ival = 1;
  6888.         pv[PRN_OUT].ival = 0;
  6889.     }
  6890.  
  6891.     /* Initialize defaults based upon current printer settings */
  6892.     if (printername) {
  6893.         defname = printername;
  6894.         switch (printertype) {
  6895.           case PRT_WIN: pv[PRN_WIN].ival = 1; break;
  6896.           case PRT_DOS: pv[PRN_DOS].ival = 1; break;
  6897.           case PRT_PIP: pv[PRN_PIP].ival = 1; break;
  6898.           case PRT_FIL: pv[PRN_FIL].ival = 1; break;
  6899.           case PRT_NON: pv[PRN_NON].ival = 1; break;
  6900.         }
  6901.     }
  6902. #ifdef BPRINT
  6903.     /* only set the BIDI flag if we are bidi */
  6904.     if (printbidi)
  6905.         pv[PRN_BID].ival = 1;
  6906.  
  6907.     /* serial port parameters may be set for non-bidi devices */
  6908.     pv[PRN_SPD].ival = pportspeed / 10L;
  6909.     pv[PRN_PAR].ival = pportparity;
  6910.     pv[PRN_FLO].ival = pportflow;
  6911. #endif /* BPRINT */
  6912.     if (printtimo)
  6913.         pv[PRN_TMO].ival = printtimo;
  6914.     if (printterm) {
  6915.         pv[PRN_TRM].ival = 1;
  6916.         makestr(&pv[PRN_TRM].sval,printterm);
  6917.     }
  6918.     if (printsep) {
  6919.         pv[PRN_SEP].ival = 1;
  6920.         makestr(&pv[PRN_SEP].sval,printsep);
  6921.     }
  6922.     if (txt2ps) {
  6923.         pv[PRN_PS].ival = 1;
  6924.         pv[PRN_WID].ival = ps_width;
  6925.         pv[PRN_LEN].ival = ps_length;
  6926.     } else {
  6927.         pv[PRN_RAW].ival = 1;
  6928.     }
  6929.  
  6930.     /* Set up chained parse functions... */
  6931.  
  6932.     cmfdbi(&sw,                         /* First FDB - command switches */
  6933.            _CMKEY,                      /* fcode */
  6934.            "Switch",                    /* hlpmsg */
  6935.            "",                          /* default */
  6936.            "",                          /* addtl string data */
  6937.            nprnswi,                     /* addtl numeric data 1: tbl size */
  6938.            4,                           /* addtl numeric data 2: 4 = cmswi */
  6939.            xxstring,                    /* Processing function */
  6940.            prntab,                      /* Keyword table */
  6941.            &cm                          /* Pointer to next FDB */
  6942.            );
  6943.     cmfdbi(&cm,                         /* Second fdb for confirmation */
  6944.            _CMCFM,                      /* fcode */
  6945.            "",                          /* hlpmsg */
  6946.            "",                          /* default */
  6947.            "",                          /* addtl string data */
  6948.            0,                           /* addtl numeric data 1 */
  6949.            0,                           /* addtl numeric data 2 */
  6950.            NULL,
  6951.            NULL,
  6952.            &of
  6953.            );
  6954.     cmfdbi(&of,                         /* Third FDB for printer name */
  6955.            _CMOFI,                      /* fcode */
  6956.            "Printer or file name",      /* hlpmsg */
  6957.            defname,                     /* default */
  6958.            "",                          /* addtl string data */
  6959.            0,                           /* addtl numeric data 1: tbl size */
  6960.            0,                           /* addtl numeric data 2: 4 = cmswi */
  6961.            xxstring,                    /* Processing function */
  6962.            NULL,                        /* Nothing */
  6963.            NULL
  6964.            );
  6965.  
  6966.     while (1) {                         /* Parse 0 or more switches */
  6967.         x = cmfdb(&sw);                 /* Parse switch or other thing */
  6968.         debug(F101,"setprinter cmfdb","",x);
  6969.         if (x < 0)                      /* Error */
  6970.           goto xsetprn;                 /* or reparse needed */
  6971.         if (cmresult.fcode != _CMKEY)   /* Break out if not a switch */
  6972.           break;
  6973.         if (cmresult.fdbaddr != &sw)    /* Advanced usage :-) */
  6974.           break;
  6975.         c = cmgbrk();                   /* Get break character */
  6976.         getval = (c == ':' || c == '='); /* to see how they ended the switch */
  6977.         n = cmresult.nresult;           /* Numeric result = switch value */
  6978.         debug(F101,"setprinter switch","",n);
  6979.  
  6980.         switch (n) {                    /* Process the switch */
  6981.           case PRN_PS:                  /* Text to Postscript */
  6982.             pv[PRN_PS].ival = 1;
  6983.             pv[PRN_BID].ival = 0;
  6984.             pv[PRN_OUT].ival = 1;
  6985.             pv[PRN_RAW].ival = 0;
  6986.             break;
  6987.  
  6988.           case PRN_RAW:                 /* Non-Postscript */
  6989.             pv[PRN_PS].ival = 0;
  6990.             pv[PRN_RAW].ival = 1;
  6991.             break;
  6992.  
  6993.           case PRN_BID:                 /* Bidirectional */
  6994.             pv[PRN_BID].ival = 1;
  6995.             pv[PRN_OUT].ival = 0;
  6996.             pv[PRN_PS].ival = 0;
  6997.             pv[PRN_RAW].ival = 1;
  6998.             break;
  6999.  
  7000.           case PRN_OUT:                 /* Output-only */
  7001.             pv[PRN_OUT].ival = 1;
  7002.             pv[PRN_BID].ival = 0;
  7003.             pv[PRN_PS].ival = 0;
  7004.             pv[PRN_RAW].ival = 1;
  7005.             break;
  7006.  
  7007.           case PRN_NON:                 /* NONE */
  7008.             typeset++;
  7009.             pv[n].ival = 1;
  7010.             pv[PRN_SPD].ival = 0;
  7011.             pv[PRN_PAR].ival = 0;
  7012.             pv[PRN_FLO].ival = FLO_KEEP;
  7013.             break;
  7014.  
  7015. #ifdef UNIX
  7016.           case PRN_WIN:
  7017. #endif /* UNIX */
  7018.           case PRN_DOS:                 /* DOS printer name */
  7019.           case PRN_FIL:                 /* Or filename */
  7020.           case PRN_PIP:
  7021.             typeset++;
  7022.             if (pv[n].sval) free(pv[n].sval);
  7023.             pv[n].sval = NULL;
  7024.             pv[PRN_NON].ival = 0;       /* Zero any previous selections */
  7025.             pv[PRN_WIN].ival = 0;
  7026.             pv[PRN_DOS].ival = 0;
  7027.             pv[PRN_FIL].ival = 0;
  7028.             pv[PRN_PIP].ival = 0;
  7029.             pv[n].ival = 1;             /* Flag this one */
  7030.             if (!getval) break;         /* No value wanted */
  7031.  
  7032.             if (n == PRN_FIL) {         /* File, check accessibility */
  7033.                 int wild = 0;
  7034.                 if ((x = cmiofi("Filename","kermit.prn",&s,&wild,xxstring))< 0)
  7035.                   if (x == -9) {
  7036.                       if (zchko(s) < 0) {
  7037.                           printf("Can't create \"%s\"\n",s);
  7038.                           return(x);
  7039.                       }
  7040.                   } else goto xsetprn;
  7041.                 if (iswild(s)) {
  7042.                     printf("?A single file please\n");
  7043.                     return(-9);
  7044.                 }
  7045.                 pv[PRN_SPD].ival = 0;
  7046.                 pv[PRN_PAR].ival = 0;
  7047.                 pv[PRN_FLO].ival = FLO_KEEP;
  7048.             } else if ((x = cmfld(n == PRN_DOS ? /* Value wanted - parse it */
  7049.                            "DOS printer device name" : /* Help message */
  7050.                            (n == PRN_PIP ?
  7051.                            "Program name" :
  7052.                            "Filename"),
  7053.                            n == PRN_DOS ?
  7054.                            "PRN" :      /* Default */
  7055.                            "",
  7056.                            &s,
  7057.                            xxstring
  7058.                            )) < 0)
  7059.               goto xsetprn;
  7060.             s = brstrip(s);             /* Strip enclosing braces */
  7061.             while (*s == SP)            /* Strip leading blanks */
  7062.               s++;
  7063.             if (n == PRN_PIP) {         /* If /PIPE: */
  7064.                 if (*s == '|') {        /* strip any extraneous pipe sign */
  7065.                     s++;
  7066.                     while (*s == SP)
  7067.                       s++;
  7068.                 }
  7069.                 pv[PRN_SPD].ival = 0;
  7070.                 pv[PRN_PAR].ival = 0;
  7071.                 pv[PRN_FLO].ival = FLO_KEEP;
  7072.             }
  7073.             if ((y = strlen(s)) > 0)    /* Anything left? */
  7074.               if (pv[n].sval = (char *) malloc(y+1)) /* Yes, keep it */
  7075.                 strcpy(pv[n].sval,s);   /* safe */
  7076.             break;
  7077. #ifdef NT
  7078.           case PRN_WIN:                 /* Windows queue name */
  7079.             typeset++;
  7080.             if (pv[n].sval) free(pv[n].sval);
  7081.             pv[n].sval = NULL;
  7082.             pv[PRN_NON].ival = 0;
  7083.             pv[PRN_DOS].ival = 0;
  7084.             pv[PRN_FIL].ival = 0;
  7085.             pv[n].ival = 1;
  7086.             pv[PRN_SPD].ival = 0;
  7087.             pv[PRN_PAR].ival = 0;
  7088.             pv[PRN_FLO].ival = FLO_KEEP;
  7089.  
  7090.             if (!getval || !haveque)
  7091.               break;
  7092.             if ((x = cmkey(_printtab,nprint,"Print queue name",
  7093.                            _printtab[printdef].kwd,xxstring)) < 0) {
  7094.                 if (x != -2)
  7095.                   goto xsetprn;
  7096.  
  7097.                 if (pv[PRN_WIN].sval) free(pv[PRN_WIN].sval);
  7098.                 s = atmbuf;
  7099.                 if ((y = strlen(s)) > 0)
  7100.                   if (pv[n].sval = (char *)malloc(y+1))
  7101.                     strcpy(pv[n].sval,s); /* safe */
  7102.             } else {
  7103.                 if (pv[PRN_WIN].sval) free(pv[PRN_WIN].sval);
  7104.                 for (i = 0; i < nprint; i++) {
  7105.                     if (x == printtab[i].kwval) {
  7106.                         s = printtab[i].kwd;
  7107.                         break;
  7108.                     }
  7109.                 }
  7110.                 if ((y = strlen(s)) > 0)
  7111.                   if (pv[n].sval = (char *)malloc(y+1))
  7112.                     strcpy(pv[n].sval,s); /* safe */
  7113.             }
  7114.             break;
  7115. #endif /* NT */
  7116.  
  7117.           case PRN_SEP:                 /* /JOB-HEADER (separator) */
  7118.             if (pv[n].sval) free(pv[n].sval);
  7119.             pv[n].sval = NULL;
  7120.             pv[n].ival = 1;
  7121.             if (!getval) break;
  7122.             if ((x = cmifi("Filename","",&s,&y,xxstring)) < 0)
  7123.               goto xsetprn;
  7124.             if (y) {
  7125.                 printf("?Wildcards not allowed\n");
  7126.                 x = -9;
  7127.                 goto xsetprn;
  7128.             }
  7129.             if ((y = strlen(s)) > 0)
  7130.               if (pv[n].sval = (char *) malloc(y+1))
  7131.                 strcpy(pv[n].sval,s);   /* safe */
  7132.             break;
  7133.  
  7134.           case PRN_TMO:                 /* /TIMEOUT:number */
  7135.             pv[n].ival = 0;
  7136.             if (!getval) break;
  7137.             if ((x = cmnum("Seconds","0",10,&y,xxstring)) < 0)
  7138.               goto xsetprn;
  7139.             if (y > 999) {
  7140.                 printf("?Sorry - 999 is the maximum\n");
  7141.                 x = -9;
  7142.                 goto xsetprn;
  7143.             } else
  7144.               pv[n].ival = y;
  7145.             break;
  7146.  
  7147.           case PRN_TRM:                 /* /END-OF-JOB:string */
  7148.             if (pv[n].sval) free(pv[n].sval);
  7149.             pv[n].sval = NULL;
  7150.             pv[n].ival = 1;
  7151.             if (!getval) break;
  7152.             if ((x = cmfld("String (enclose in braces if it contains spaces)",
  7153.                            "",&s,xxstring)) < 0)
  7154.               goto xsetprn;
  7155.             s = brstrip(s);
  7156.             if ((y = strlen(s)) > 0)
  7157.               if (pv[n].sval = (char *) malloc(y+1))
  7158.                 strcpy(pv[n].sval,s);   /* safe */
  7159.             break;
  7160.  
  7161. #ifdef BPRINT
  7162.           case PRN_FLO:
  7163.             if (!getval) break;
  7164.             if ((x = cmkey(flotab,nflo,
  7165.                               "Serial printer-port flow control",
  7166.                               "rts/cts",xxstring)) < 0)
  7167.               goto xsetprn;
  7168.             pv[n].ival = x;
  7169.             break;
  7170.  
  7171. #ifndef NOLOCAL
  7172.           case PRN_SPD:
  7173.             if (!getval) break;
  7174.  
  7175.             /* TN_COMPORT here too? */
  7176.  
  7177.             if ((x = cmkey(spdtab,      /* Speed (no default) */
  7178.                            nspd,
  7179.                            "Serial printer-port interface speed",
  7180.                            "9600",
  7181.                            xxstring)
  7182.                  ) < 0)
  7183.               goto xsetprn;
  7184.             pv[n].ival = x;
  7185.             break;
  7186. #endif /* NOLOCAL */
  7187.  
  7188.           case PRN_PAR:
  7189.             pv[n].ival = 0;
  7190.             if (!getval) break;
  7191.             if ((x = cmkey(partbl,npar,"Serial printer-port parity",
  7192.                            "none",xxstring)) < 0)
  7193.               goto xsetprn;
  7194.             pv[n].ival = x;
  7195.             break;
  7196. #endif /* BPRINT */
  7197.  
  7198. #ifdef OS2
  7199.           case PRN_LEN:
  7200.             if (!getval) break;
  7201.             if ((x = cmnum("PS page length", "66",10,&y,xxstring)) < 0)
  7202.               goto xsetprn;
  7203.             pv[n].ival = y;
  7204.             break;
  7205.  
  7206.           case PRN_WID:
  7207.             if (!getval) break;
  7208.             if ((x = cmnum("PS page width", "80",10,&y,xxstring)) < 0)
  7209.               goto xsetprn;
  7210.             pv[n].ival = y;
  7211.             break;
  7212.  
  7213.           case PRN_CS:
  7214.               pv[n].ival = 0;
  7215.               if (!getval) break;
  7216.               if ((y = cmkey(
  7217. #ifdef CKOUNI
  7218.                        txrtab,ntxrtab,
  7219. #else /* CKOUNI */
  7220.                        ttcstab,ntermc,
  7221. #endif /* CKOUNI */
  7222.                        "auto-print/printscreen character-set",
  7223.                        "cp437",xxstring)) < 0)
  7224.                   goto xsetprn;
  7225.               pv[n].ival = y;
  7226.               break;
  7227. #endif /* OS2 */
  7228.  
  7229.           default:
  7230.             printf("?Unexpected switch value - %d\n",cmresult.nresult);
  7231.             x = -9;
  7232.             goto xsetprn;
  7233.         }
  7234.     }
  7235.     line[0] = NUL;                      /* Initialize printer name value */
  7236.     switch (cmresult.fcode) {           /* How did we get here? */
  7237.       case _CMOFI:                      /* They typed a filename */
  7238.         ckstrncpy(line,cmresult.sresult,LINBUFSIZ); /* Name */
  7239.         wild = cmresult.nresult;        /* Wild flag */
  7240.         if (!typeset) {                 /* A printer name without a type */
  7241.             pv[PRN_NON].ival = 0;       /* is supposed to be treated as  */
  7242.             pv[PRN_WIN].ival = 0;       /* a DOS or Pipe printer.  We    */
  7243.             pv[PRN_FIL].ival = 0;       /* clear all the flags and let   */
  7244.             pv[PRN_PIP].ival = 0;       /* the code below dope out the   */
  7245.             pv[PRN_DOS].ival = 0;       /* type.                         */
  7246.         }
  7247. #ifdef NT
  7248.         else if (pv[PRN_WIN].ival && lookup(_printtab,line,nprint,&y)) {
  7249.             /* invalid Window Queue name */
  7250.             printf("?invalid Windows Printer Queue name: \"%s\"\r\n",line);
  7251.             x = -9;
  7252.             goto xsetprn;
  7253.         }
  7254. #endif /* NT */
  7255.         if ((x = cmcfm()) < 0)          /* Confirm the command */
  7256.           goto xsetprn;
  7257.         break;
  7258.       case _CMCFM:                      /* They entered the command */
  7259.         if (pv[PRN_DOS].ival > 0)
  7260.           ckstrncpy(line,pv[PRN_DOS].sval ? pv[PRN_DOS].sval : "",LINBUFSIZ);
  7261.         else if (pv[PRN_WIN].ival > 0)
  7262.           ckstrncpy(line,pv[PRN_WIN].sval ? pv[PRN_WIN].sval : "",LINBUFSIZ);
  7263.         else if (pv[PRN_FIL].ival > 0)
  7264.           ckstrncpy(line,pv[PRN_FIL].sval ? pv[PRN_FIL].sval : "",LINBUFSIZ);
  7265.         else if (pv[PRN_PIP].ival > 0)
  7266.           ckstrncpy(line,pv[PRN_PIP].sval ? pv[PRN_PIP].sval : "",LINBUFSIZ);
  7267.         break;
  7268.       default:                          /* By mistake */
  7269.         printf("?Unexpected function code: %d\n",cmresult.fcode);
  7270.         x = -9;
  7271.         goto xsetprn;
  7272.     }
  7273.  
  7274. #else  /* No PRINTSWI */
  7275.  
  7276.     if ((x = cmofi("Printer or file name",defname,&s,xxstring)) < 0)
  7277.       return(x);
  7278.     if (x > 1) {
  7279.         printf("?Directory names not allowed\n");
  7280.         return(-9);
  7281.     }
  7282.     while (*s == SP || *s == HT) s++;   /* Trim leading whitespace */
  7283.     ckstrncpy(line,s,LINBUFSIZ);        /* Make a temporary safe copy */
  7284.     if ((x = cmcfm()) < 0) return(x);   /* Confirm the command */
  7285. #endif /* PRINTSWI */
  7286.  
  7287. #ifdef IKSD
  7288.     if (inserver && (isguest
  7289. #ifndef NOSERVER
  7290.                      || !ENABLED(en_pri)
  7291. #endif /* NOSERVER */
  7292.                      )) {
  7293.         printf("Sorry, printing disabled\r\n");
  7294.         return(success = 0);
  7295.     }
  7296. #endif /* ISKD */
  7297.  
  7298. #ifdef PRINTSWI
  7299. #ifdef BPRINT
  7300.     if (printbidi) {                    /* If bidi printing active */
  7301. #ifndef UNIX
  7302.         bprtstop();                     /* Stop it before proceeding */
  7303. #endif /* UNIX */
  7304.         printbidi = 0;
  7305.     }
  7306.     if (pv[PRN_SPD].ival > 0) {
  7307.         portspeed = (long) pv[PRN_SPD].ival * 10L;
  7308.         if (portspeed == 70L) portspeed = 75L;
  7309.     }
  7310.     if (pv[PRN_PAR].ival > 0)
  7311.         portparity = pv[PRN_PAR].ival;
  7312.     if (pv[PRN_FLO].ival > 0)
  7313.         portflow = pv[PRN_FLO].ival;
  7314. #endif /* BPRINT */
  7315. #endif /* PRINTSWI */
  7316.  
  7317.     s = line;                           /* Printer name, if given */
  7318.  
  7319. #ifdef OS2ORUNIX
  7320. #ifdef PRINTSWI
  7321.     if (pv[PRN_PIP].ival > 0) {         /* /PIPE was given? */
  7322.         printpipe = 1;
  7323.         noprinter = 0;
  7324.         if (*s ==  '|') {               /* It might still have a pipe sign */
  7325.             s++;                        /* if name give later */
  7326.             while (*s == SP)            /* so remove it and spaces */
  7327.               s++;
  7328.         }
  7329.     } else
  7330. #endif /* PRINTSWI */
  7331.       if (*s == '|') {                  /* Or pipe implied by name? */
  7332.           s++;                          /* Point past pipe sign */
  7333.           while (*s == SP)              /* Gobble whitespace */
  7334.             s++;
  7335.           if (*s) {
  7336.               printpipe = 1;
  7337.               noprinter = 0;
  7338.           }
  7339.       } else {
  7340.           printpipe = 0;
  7341.       }
  7342.  
  7343. #ifdef PRINTSWI
  7344. #ifdef BPRINT
  7345.     if (printpipe && pv[PRN_BID].ival > 0) {
  7346.         printf("?Sorry, pipes not allowed for bidirectional printer\n");
  7347.         return(-9);
  7348.     }
  7349. #endif /* BPRINT */
  7350. #endif /* PRINTSWI */
  7351. #endif /* OS2ORUNIX */
  7352.  
  7353. #ifdef OS2
  7354.     if ( pv[PRN_CS].ival > 0 ) 
  7355.         prncs = pv[PRN_CS].ival;
  7356.  
  7357.     if ( pv[PRN_PS].ival > 0 ) {
  7358.         txt2ps = 1;
  7359.         ps_width = pv[PRN_WID].ival <= 0 ? 80 : pv[PRN_WID].ival;
  7360.         ps_length = pv[PRN_LEN].ival <= 0 ? 66 : pv[PRN_LEN].ival;
  7361.     }
  7362. #endif /* OS2 */
  7363.  
  7364.     y = strlen(s);                      /* Length of name of new print file */
  7365.     if (y > 0
  7366. #ifdef OS2
  7367.         && ((y != 3) || (ckstrcmp(s,"PRN",3,0) != 0))
  7368. #endif /* OS2 */
  7369.         ) {
  7370.         if (printername) {              /* Had a print file before? */
  7371.             free(printername);          /* Remove its name */
  7372.             printername = NULL;
  7373.         }
  7374.         printername = (char *) malloc(y + 1); /* Allocate space for it */
  7375.         if (!printername) {
  7376.             printf("?Memory allocation failure\n");
  7377.             return(-9);
  7378.         }
  7379.         strcpy(printername,s);          /* (safe) Copy new name to new space */
  7380.         debug(F110,"printername",printername,0);
  7381.     }
  7382.  
  7383. #ifdef PRINTSWI
  7384.     /* Set printer type from switches that were given explicitly */
  7385.  
  7386.     if (pv[PRN_NON].ival > 0) {         /* No printer */
  7387.         printertype = PRT_NON;
  7388.         noprinter = 1;
  7389.         printpipe = 0;
  7390.     } else if (pv[PRN_FIL].ival > 0) {  /* File */
  7391.         printertype = PRT_FIL;
  7392.         noprinter = 0;
  7393.         printpipe = 0;
  7394.     } else if (pv[PRN_PIP].ival > 0) {  /* Pipe */
  7395.         printertype = PRT_PIP;
  7396.         noprinter = 0;
  7397.         printpipe = 1;
  7398.     } else if (pv[PRN_WIN].ival > 0) {  /* Windows print queue */
  7399.         printertype = PRT_WIN;
  7400.         noprinter = 0;
  7401.         printpipe = 0;
  7402.     } else if (pv[PRN_DOS].ival > 0) {  /* DOS device */
  7403.         printertype = PRT_DOS;
  7404.         noprinter = 0;
  7405.         printpipe = 0;
  7406.     } else if (line[0]) {               /* Name given without switches */
  7407.         noprinter = 0;
  7408.         printertype = printpipe ? PRT_PIP : PRT_DOS;
  7409. #ifdef NT
  7410.         /* was the command SET PRINTER windows-queue ? */
  7411.         y = lookup(_printtab,line,nprint,&x);
  7412.         if (y >= 0) {
  7413.             printertype = PRT_WIN;
  7414.             if (pv[PRN_WIN].sval) free(pv[PRN_WIN].sval);
  7415.             if (printername) {          /* Had a print file before? */
  7416.                 free(printername);      /* Remove its name */
  7417.                 printername = NULL;
  7418.             }
  7419.             pv[PRN_WIN].sval = NULL;
  7420.             pv[PRN_WIN].ival = 1;
  7421.             s = printtab[x].kwd;        /* Get full new name */
  7422.             if ((y = strlen(s)) > 0) {
  7423.                 makestr(&pv[PRN_WIN].sval,s);
  7424.                 makestr(&printername,s);
  7425.                 if (!printername) {
  7426.                     printf("?Memory allocation failure\n");
  7427.                     return(-9);
  7428.                 }
  7429.                 debug(F110,"printername",printername,0);
  7430.             }
  7431.         } else if ( y == -2 ) {
  7432.             /* Ambiguous Print Queue Name */
  7433.             printf("?Ambiguous printer name provided.\n");
  7434.             return(-9);
  7435.         }
  7436. #endif /* NT */
  7437.     }
  7438.  
  7439. #ifdef BPRINT
  7440.     /* Port parameters may be set for non-bidi mode */
  7441.  
  7442.     pportspeed = portspeed;             /* Set parameters */
  7443.     pportparity = portparity;
  7444.     pportflow = portflow;
  7445.  
  7446.     if (pv[PRN_BID].ival > 0) {         /* Bidirectional */
  7447. #ifdef UNIX
  7448.         printbidi = 1;                  /* (just to test parsing...) */
  7449. #else
  7450.         printbidi = bprtstart();        /* Start bidirectional printer */
  7451. #endif /* UNIX */
  7452.         return(success = printbidi);
  7453.     } else
  7454.       printbidi = 0;                    /* Not BPRINTER, unset flag */
  7455. #endif /* BPRINT */
  7456.  
  7457.     if (pv[PRN_TMO].ival > -1) {        /* Take care of timeout */
  7458.         printtimo = pv[PRN_TMO].ival;
  7459.     }
  7460.     if (pv[PRN_TRM].ival > 0) {         /* Termination string */
  7461.         if (printterm) {
  7462.             free(printterm);
  7463.             printterm = NULL;
  7464.         }
  7465.         if (pv[PRN_TRM].sval)
  7466.           makestr(&printterm,pv[PRN_TRM].sval);
  7467.     }
  7468.     if (pv[PRN_SEP].ival > 0) {         /* and separator file */
  7469.         if (printsep) {
  7470.             free(printsep);
  7471.             printsep = NULL;
  7472.         }
  7473.         if (pv[PRN_SEP].sval)
  7474.           makestr(&printsep,pv[PRN_SEP].sval);
  7475.     }
  7476. #endif /* PRINTSWI */
  7477.  
  7478. #ifdef UNIXOROSK
  7479.     if (!printpipe
  7480. #ifdef PRINTSWI
  7481.         && !noprinter
  7482. #endif /* PRINTSWI */
  7483.         ) {                             /* File - check access */
  7484.         if (zchko(s) < 0) {
  7485.             printf("?Access denied - %s\n",s);
  7486.             x = -9;
  7487.             goto xsetprn;
  7488.         }
  7489.     }
  7490. #endif /* UNIXOROSK */
  7491.  
  7492.     x = 1;                              /* Return code */
  7493.  
  7494.   xsetprn:                              /* Common exit */
  7495. #ifdef PRINTSWI
  7496.     for (i = 0; i <= PRN_MAX; i++) {    /* Free malloc'd memory */
  7497.         if (pv[i].sval)
  7498.           free(pv[i].sval);
  7499.     }
  7500. #endif /* PRINTSWI */
  7501.     success = (x > 0) ? 1 : 0;
  7502.     return(x);
  7503. }
  7504.  
  7505. #ifdef ANYSSH
  7506. /* The SET SSH command */
  7507.  
  7508. #define SSH_CMD  1                      /* SET SSH COMMAND */
  7509.  
  7510. #ifdef SSHBUILTIN                       /* Built-in SET SSH options */
  7511. #define SSH_ADD  2                      /* Add */
  7512. #define SSH_AFW  3                      /* Agent-forwarding */
  7513. #define SSH_CHI  4                      /* Check Host IP */
  7514. #define SSH_XFW  5                      /* X11-forwarding */
  7515. #define SSH_DYF  6                      /* Dynamic forwarding */
  7516. #define SSH_GWP  7                      /* Gatewa portgs */
  7517. #define SSH_GSS  8                      /* GSSAPI */
  7518. #define SSH_KBD  9                      /* KBD Interactive Devices */
  7519. #define SSH_K4  10                      /* Kerberos 4 */
  7520. #define SSH_K5  11                      /* Kerberos 5 */
  7521. #define SSH_SHK 12                      /* Strict Host Key Check */
  7522. #define SSH_V1  13                      /* SSH V1 */
  7523. #define SSH_V2  14                      /* SSH V2 */
  7524. #define SSH_PRP 15                      /* Privd port */
  7525. #define SSH_CMP 16                      /* Compression */
  7526. #define SSH_XAL 17                      /* X Auth Location */
  7527. #define SSH_SHH 18                      /* Quiet */
  7528. #define SSH_VER 19                      /* Version */
  7529. #define SSH_VRB 20                      /* Verbosity level */
  7530. #define SSH_IDF 21                      /* Identity File */
  7531. #define SSH_CFG 22                      /* Use OpenSSH Config */
  7532. #define SSH_HBT 23                      /* Heartbeat Interval */
  7533. #endif /* SSHBUILTIN */
  7534.  
  7535. static struct keytab sshtab[] = {       /* SET SSH command table */
  7536. #ifdef SSHBUILTIN
  7537.     { "agent-forwarding",        SSH_AFW,  0 },
  7538.     { "check-host-ip",           SSH_CHI,  0 },
  7539.     { "compression",             SSH_CMP,  0 },
  7540.     { "dynamic-forwarding",      SSH_DYF,  0 },
  7541.     { "gateway-ports",           SSH_GWP,  0 },
  7542.     { "gssapi",                  SSH_GSS,  0 },
  7543.     { "heartbeat-interval",      SSH_HBT,  0 },
  7544.     { "identity-file",           SSH_IDF,  0 },
  7545. #ifdef COMMENT
  7546.     { "kbd-interactive-devices", SSH_KBD,  0 },
  7547. #endif /* COMMENT */
  7548.     { "k4",                      SSH_K4, CM_INV },
  7549.     { "k5",                      SSH_K5, CM_INV },
  7550.     { "kerberos4",               SSH_K4,   0 },
  7551.     { "kerberos5",               SSH_K5,   0 },
  7552.     { "krb4",                    SSH_K4, CM_INV },
  7553.     { "krb5",                    SSH_K5, CM_INV },
  7554.     { "privileged-port",         SSH_PRP,  0 },
  7555.     { "quiet",                   SSH_SHH,  0 },
  7556.     { "strict-host-key-check",   SSH_SHK,  0 },
  7557.     { "use-openssh-config",      SSH_CFG,  0 },
  7558.     { "v1",                      SSH_V1,   0 },
  7559.     { "v2",                      SSH_V2,   0 },
  7560.     { "verbose",                 SSH_VRB,  0 },
  7561.     { "version",                 SSH_VER,  0 },
  7562.     { "x11-forwarding",          SSH_XFW,  0 },
  7563.     { "xauth-location",          SSH_XAL,  0 },
  7564. #else
  7565. #ifdef SSHCMD
  7566.     { "command",                 SSH_CMD,  0 },
  7567. #endif /* SSHCMD */
  7568. #endif /* SSHBUILTIN */
  7569.     { "", 0, 0 }
  7570. };
  7571. static int nsshtab = (sizeof(sshtab) / sizeof(struct keytab)) - 1;
  7572.  
  7573. #ifdef SSHBUILTIN
  7574. static struct keytab sshver[] = {       /* SET SSH VERSION command table */
  7575.     { "1",          1,  0 },
  7576.     { "2",          2,  0 },
  7577.     { "automatic",  0,  0 }
  7578. };
  7579.  
  7580. #define SSHA_CRS   1
  7581. #define SSHA_DSA   2
  7582. #define SSHA_GSS   3
  7583. #define SSHA_HOS   4
  7584. #define SSHA_KBD   5
  7585. #define SSHA_K4    6
  7586. #define SSHA_K5    7
  7587. #define SSHA_PSW   8
  7588. #define SSHA_PK    9
  7589. #define SSHA_SKE  10
  7590. #define SSHA_TIS  11
  7591. #define SSHA_EXT  12
  7592. #define SSHA_SRP  13
  7593.  
  7594. static struct keytab ssh2aut[] = {      /* SET SSH V2 AUTH command table */
  7595.     { "external-keyx",      SSHA_EXT, 0 },
  7596.     { "gssapi",             SSHA_GSS, 0 },
  7597.     { "hostbased",          SSHA_HOS, 0 },
  7598.     { "keyboard-interactive",  SSHA_KBD, 0 },
  7599.     { "password",           SSHA_PSW, 0 },
  7600.     { "publickey",          SSHA_PK,  0 },
  7601.     { "srp-gex-sha1",       SSHA_SRP, 0 },
  7602.     { "", 0, 0 }
  7603. };
  7604. static int nssh2aut = (sizeof(ssh2aut) / sizeof(struct keytab)) - 1;
  7605.  
  7606. #define SSHF_LCL   1
  7607. #define SSHF_RMT   2
  7608.  
  7609. static struct keytab addfwd[] = {       /* SET SSH ADD command table */
  7610.     { "local-port-forward",  SSHF_LCL, 0 },
  7611.     { "remote-port-forward", SSHF_RMT, 0 },
  7612.     { "", 0, 0 }
  7613. };
  7614. static int naddfwd = (sizeof(addfwd) / sizeof(struct keytab)) - 1;
  7615.  
  7616. #define SSH1_CIF   1
  7617. #define SSH1_GNH   2
  7618. #define SSH1_UNH   3
  7619. #define SSH1_K54   4
  7620.  
  7621. #define SSH2_CIF   1
  7622. #define SSH2_GNH   2
  7623. #define SSH2_UNH   3
  7624. #define SSH2_ARK   4
  7625. #define SSH2_HKA   5
  7626. #define SSH2_MAC   6
  7627. #define SSH2_AUT   7
  7628.  
  7629. static struct keytab sshv1tab[] = {     /* SET SSH V1 command table */
  7630.     { "cipher",                  SSH1_CIF, 0 },
  7631.     { "global-known-hosts-file", SSH1_GNH, 0 },
  7632.     { "k5-reuse-k4-messages",    SSH1_K54, CM_INV },
  7633.     { "user-known-hosts-file",   SSH1_UNH, 0 },
  7634.     { "", 0, 0 }
  7635. };
  7636. static int nsshv1tab = (sizeof(sshv1tab) / sizeof(struct keytab)) - 1;
  7637.  
  7638. static struct keytab sshv2tab[] = {     /* SET SSH V2 command table */
  7639.     { "authentication",          SSH2_AUT, 0 },
  7640.     { "auto-rekey",              SSH2_ARK, 0 },
  7641.     { "ciphers",                 SSH2_CIF, 0 },
  7642.     { "global-known-hosts-file", SSH2_GNH, 0 },
  7643.     { "hostkey-algorithms",      SSH2_HKA, 0 },
  7644.     { "macs",                    SSH2_MAC, 0 },
  7645.     { "user-known-hosts-file",   SSH2_UNH, 0 },
  7646.     { "", 0, 0 }
  7647. };
  7648. static int nsshv2tab = (sizeof(sshv2tab) / sizeof(struct keytab)) - 1;
  7649.  
  7650. #define SSHC_3DES 1                     /* 3DES */
  7651. #define SSHC_3CBC 2                     /* 3DES-CBC */
  7652. #define SSHC_A128 3                     /* AES128-CBC */
  7653. #define SSHC_A192 4                     /* AES192-CBC */
  7654. #define SSHC_A256 5                     /* AES256-CBC */
  7655. #define SSHC_ARC4 6                     /* ARCFOUR */
  7656. #define SSHC_FISH 7                     /* BLOWFISH */
  7657. #define SSHC_BCBC 9                     /* BLOWFISH-CBC */
  7658. #define SSHC_C128 8                     /* CAST128-CBC */
  7659. #define SSHC_1DES 10                    /* DES */
  7660.  
  7661. static struct keytab ssh1ciphers[] = {
  7662.     { "3des",         SSHC_3DES, 0 },
  7663.     { "blowfish",     SSHC_FISH, 0 },
  7664.     { "des",          SSHC_1DES, 0 },
  7665.     { "", 0, 0 }
  7666. };
  7667. static int nssh1ciphers = (sizeof(ssh1ciphers) / sizeof(struct keytab)) - 1;
  7668.  
  7669. static struct keytab ssh2ciphers[] = {  /* SET SSH V2 CIPHERS command table */
  7670.     { "3des-cbc",        SSHC_3DES, 0 },
  7671.     { "aes128-cbc",      SSHC_A128, 0 },
  7672.     { "aes192-cbc",      SSHC_A192, 0 },
  7673.     { "aes256-cbc",      SSHC_A256, 0 },
  7674.     { "arcfour",         SSHC_ARC4, 0 },
  7675.     { "blowfish-cbc",    SSHC_FISH, 0 },
  7676.     { "cast128-cbc",     SSHC_C128, 0 },
  7677.     { "rijndael128-cbc", SSHC_A128, 0 },
  7678.     { "rijndael192-cbc", SSHC_A192, 0 },
  7679.     { "rijndael256-cbc", SSHC_A256, 0 },
  7680.     { "", 0, 0 }
  7681. };
  7682. static int nssh2ciphers = (sizeof(ssh2ciphers) / sizeof(struct keytab)) - 1;
  7683.  
  7684. #define SSHM_SHA        1               /* HMAC-SHA1 */
  7685. #define SSHM_SHA_96     2               /* HMAC-SHA1-96 */
  7686. #define SSHM_MD5        3               /* HMAC-MD5 */
  7687. #define SSHM_MD5_96     4               /* HMAC-MD5-96 */
  7688. #define SSHM_RIPE       5               /* HMAC-RIPEMD160 */
  7689.  
  7690. static struct keytab ssh2macs[] = {     /* SET SSH V2 MACS command table */
  7691.     { "hmac-md5",       SSHM_MD5,    0 },
  7692.     { "hmac-md5-96",    SSHM_MD5_96, 0 },
  7693.     { "hmac-ripemd160", SSHM_RIPE,   0 },
  7694.     { "hmac-sha1",      SSHM_SHA,    0 },
  7695.     { "hmac-sha1-96",   SSHM_SHA_96, 0 },
  7696.     { "", 0, 0 }
  7697. };
  7698. static int nssh2macs = (sizeof(ssh2macs) / sizeof(struct keytab)) - 1;
  7699.  
  7700. static struct keytab tgtpass[] = {
  7701.     { "tgt-passing", 1, 0, },
  7702.     { "", 0, 0 }
  7703. };
  7704. static int ntgtpass = (sizeof(tgtpass) / sizeof(struct keytab)) - 1;
  7705.  
  7706. static struct keytab gssapitab[] = {
  7707.     { "delegate-credentials", 1, 0, },
  7708.     { "key-exchange",         2, CM_INV, },
  7709.     { "", 0, 0 }
  7710. };
  7711. static int ngssapitab = (sizeof(gssapitab) / sizeof(struct keytab)) - 1;
  7712.  
  7713. #define HKA_RSA 1
  7714. #define HKA_DSS 2
  7715.  
  7716. static struct keytab hkatab[] = {
  7717.     { "ssh-dss", HKA_DSS, 0, },
  7718.     { "ssh-rsa", HKA_RSA, 0, },
  7719.     { "", 0, 0 }
  7720. };
  7721. static int nhkatab = (sizeof(hkatab) / sizeof(struct keytab)) - 1;
  7722.  
  7723. int                                     /* SET SSH variables */
  7724.   ssh_afw = 0,                          /* agent forwarding */
  7725.   ssh_xfw = 0,                          /* x11 forwarding   */
  7726.   ssh_prp = SET_OFF,                    /* privileged ports */
  7727.   ssh_cmp = 1,                          /* compression */
  7728.   ssh_shh = 0,                          /* quiet       */
  7729.   ssh_ver = 0,                          /* protocol version (auto,1,2) */
  7730.   ssh_vrb = 2,                          /* Report errors */
  7731.   ssh_chkip = 0,                        /* SSH Check Host IP flag */
  7732.   ssh_gwp = 0,                          /* gateway ports */
  7733.   ssh_dyf = 0,                          /* dynamic forwarding */
  7734.   ssh_gsd = 0,                          /* gssapi delegate credentials */
  7735.   ssh_k4tgt = 0,                        /* k4 tgt passing */
  7736.   ssh_k5tgt = 0,                        /* k5 tgt passing */
  7737.   ssh_shk = 2,                          /* Strict host key (no, yes, ask) */
  7738.   ssh2_ark = 1,                         /* Auto re-key */
  7739.   ssh_cas = 0,                          /* command as subsys */
  7740.   ssh_cfg = 0,                          /* use OpenSSH config? */
  7741.   ssh_gkx = 1,                          /* gssapi key exchange */
  7742.   ssh_k5_is_k4 = 1,                     /* some SSH v1 use same codes */
  7743.   ssh_hbt = 0,                          /* heartbeat (seconds) */
  7744.   ssh_dummy = 0;                        /* bottom of list */
  7745.  
  7746. char                                    /* The following are to be malloc'd */
  7747.   * ssh1_cif = NULL,                    /* v1 cipher */
  7748.   * ssh2_cif = NULL,                    /* v2 cipher list */
  7749.   * ssh2_mac = NULL,                    /* v2 mac list */
  7750.   * ssh2_auth = NULL,                   /* v2 authentication list */
  7751.   * ssh_hst = NULL,                     /* hostname */
  7752.   * ssh_prt = NULL,                     /* port/service */
  7753.   * ssh_cmd = NULL,                     /* command to execute */
  7754.   * ssh_xal = NULL,                     /* xauth-location */
  7755.   * ssh1_gnh = NULL,                    /* v1 global known hosts file */
  7756.   * ssh1_unh = NULL,                    /* v1 user known hosts file */
  7757.   * ssh2_gnh = NULL,                    /* v2 global known hosts file */
  7758.   * ssh2_unh = NULL,                    /* v2 user known hosts file */
  7759.   * ssh2_hka = NULL,                    /* Host Key Algorithms */
  7760.   * xxx_dummy = NULL;
  7761.  
  7762. char * ssh_idf[32] = {                  /* Identity file list */
  7763.   NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
  7764.   NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
  7765.   NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
  7766.   NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
  7767. };
  7768. char * ssh_tmp[32] = {                  /* Temp identity file list */
  7769.   NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
  7770.   NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
  7771.   NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
  7772.   NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
  7773. };
  7774. int ssh_idf_n = 0;
  7775.  
  7776. extern int    ssh_pf_lcl_n,
  7777.               ssh_pf_rmt_n;
  7778. extern struct ssh_pf ssh_pf_lcl[32];    /* Port forwarding structs */
  7779. extern struct ssh_pf ssh_pf_rmt[32];    /* (declared in ckuusr.c) */
  7780. #endif /* SSHBUILTIN */
  7781.  
  7782. #ifdef SFTP_BUILTIN
  7783. static struct keytab sftptab[] = {
  7784.     { "end-of-line",            XY_SFTP_EOL, 0, },
  7785.     { "remote-character-set",   XY_SFTP_RCS, 0, },
  7786.     { "", 0, 0 }
  7787. };
  7788. static int nsftptab = (sizeof(sftptab) / sizeof(struct keytab)) - 1;
  7789. #endif /* SFTP_BUILTIN */
  7790.  
  7791. VOID
  7792. shossh() {
  7793. #ifdef SSHBUILTIN
  7794.     int i, n = 0;                       /* ADD askmore()! */
  7795.  
  7796.     printf("\nSSH is built in:\n\n");
  7797.  
  7798.     printf(" ssh host:                        %s\n",showstring(ssh_hst));
  7799.     printf(" ssh port:                        %s\n",showstring(ssh_prt));
  7800.     printf(" ssh command:                     %s\n",showstring(ssh_cmd));
  7801.     printf(" ssh agent-forwarding:            %s\n",showoff(ssh_afw));
  7802.     printf(" ssh check-host-ip:               %s\n",showoff(ssh_chkip));
  7803.     printf(" ssh compression:                 %s\n",showoff(ssh_cmp));
  7804.     printf(" ssh dynamic-forwarding:          %s\n",showoff(ssh_dyf));
  7805.     if (ssh_pf_lcl[0].p1 && ssh_pf_lcl[0].host && ssh_pf_lcl[0].p2) {
  7806.       printf(" ssh forward-local-port:          %d %s %d\n",
  7807.              ssh_pf_lcl[0].p1, ssh_pf_lcl[0].host, ssh_pf_lcl[0].p2);
  7808.       for ( n=1;n<ssh_pf_lcl_n;n++ )
  7809.         printf("                       :          %d %s %d\n",
  7810.                ssh_pf_lcl[n].p1, ssh_pf_lcl[n].host, ssh_pf_lcl[n].p2);
  7811.     } else
  7812.       printf(" ssh forward-local-port:         (none)\n");
  7813.     if (ssh_pf_rmt[0].p1 && ssh_pf_rmt[0].host && ssh_pf_rmt[0].p2) {
  7814.       printf(" ssh forward-remote-port:         %d %s %d\n",
  7815.              ssh_pf_rmt[0].p1, ssh_pf_rmt[0].host, ssh_pf_rmt[0].p2);
  7816.       for ( n=1;n<ssh_pf_rmt_n;n++ )
  7817.         printf("                        :         %d %s %d\n",
  7818.                ssh_pf_rmt[n].p1, ssh_pf_rmt[n].host, ssh_pf_rmt[n].p2);
  7819.     } else
  7820.       printf(" ssh forward-remote-port:        (none)\n");
  7821.     printf(" ssh gateway-ports:               %s\n",showoff(ssh_gwp));
  7822.     printf(" ssh gssapi delegate-credentials: %s\n",showoff(ssh_gsd));
  7823.     printf(" ssh gssapi key-exchange        : %s\n",showoff(ssh_gkx));
  7824.     printf(" ssh identity-file:               %d\n",ssh_idf_n);
  7825.     for (i = 0; i < ssh_idf_n; i++)
  7826.       printf("  %2d. %s\n",i+1,showstring(ssh_idf[i]));
  7827.     printf(" ssh heartbeat interval:          %d\n", ssh_hbt);
  7828.     printf(" ssh k4 tgt-passing:              %s\n",showoff(ssh_k4tgt));
  7829.     printf(" ssh k5 tgt-passing:              %s\n",showoff(ssh_k5tgt));
  7830.  
  7831.     printf(" ssh privileged-port:             %s\n",showooa(ssh_prp));
  7832.     printf(" ssh quiet:                       %s\n",showoff(ssh_shh));
  7833.     printf(" ssh strict-host-key-check:       %d\n",ssh_shk);
  7834.     printf(" ssh use-openssh-config:          %s\n",showoff(ssh_cfg));
  7835.     printf(" ssh verbose:                     %d\n",ssh_vrb);
  7836.     printf(" ssh version:                     %s\n",
  7837.            ssh_ver ? ckitoa(ssh_ver) : "automatic"
  7838.            );
  7839.     printf(" ssh x11-forwarding:              %s\n",showooa(ssh_xfw));
  7840.     printf(" ssh xauth-location:              %s\n",showstring(ssh_xal));
  7841.     printf("\n");
  7842.     printf(" ssh v1 cipher:                   %s\n",showstring(ssh1_cif));
  7843.     printf(" ssh v1 global-known-hosts-file:  %s\n",showstring(ssh1_gnh));
  7844.     printf(" ssh v1 user-known-hosts-file:    %s\n",showstring(ssh1_unh));
  7845.     printf("\n");
  7846.     printf(" ssh v2 authentication:           %s\n",showstring(ssh2_auth));
  7847.     printf(" ssh v2 auto-rekey:               %s\n",showoff(ssh2_ark));
  7848.     printf(" ssh v2 ciphers:                  %s\n",showstring(ssh2_cif));
  7849.     printf(" ssh v2 command-as-subsystem:     %s\n",showoff(ssh_cas));
  7850.     printf(" ssh v2 global-known-hosts-file:  %s\n",showstring(ssh2_gnh));
  7851.     printf(" ssh v2 hostkey-algorithms:       %s\n",showstring(ssh2_hka));
  7852.     printf(" ssh v2 mac:                      %s\n",showstring(ssh2_mac));
  7853.     printf(" ssh v2 user-known-hosts-file:    %s\n",showstring(ssh2_unh));
  7854. #else
  7855. #ifdef SSHCMD
  7856.     extern char * sshcmd, * defsshcmd;
  7857.     char * s;
  7858.     s = sshcmd ? sshcmd : defsshcmd;
  7859.     printf("\n SSH is external.\n\n");
  7860.     printf(" ssh command: %s\n",showstring(s));
  7861. #endif /* SSHCMD */
  7862. #endif /* SSHBUILTIN */
  7863.     printf("\n");
  7864. }
  7865.  
  7866. static int
  7867. dosetssh() {
  7868. #ifdef SSHCMD
  7869.     extern char * sshcmd;
  7870. #endif /* SSHCMD */
  7871. #ifdef SSHBUILTIN
  7872. #ifndef SSHTEST
  7873.     extern int sl_ssh_xfw_saved, sl_ssh_ver_saved;
  7874. #endif /* SSHTEST */
  7875. #endif /* SSHBUILTIN */
  7876.     int cx, x, y, z;
  7877.     char * s;
  7878.  
  7879.     if ((cx = cmkey(sshtab,nsshtab,"","command", xxstring)) < 0)
  7880.       return(cx);
  7881.     switch (cx) {
  7882. #ifdef SSHCMD
  7883.       case SSH_CMD:                     /* Command */
  7884.         if ((x = cmtxt("Command to start ssh","ssh -e none",
  7885.                        &s,xxstring)) < 0)
  7886.           return(x);
  7887.         makestr(&sshcmd,s);
  7888.         return(success = 1);
  7889. #endif /* SSHCMD */
  7890.  
  7891. #ifdef SSHBUILTIN
  7892.       case SSH_AFW:                     /* Agent-forwarding */
  7893.         return(success = seton(&ssh_afw));
  7894.  
  7895.       case SSH_CHI:                     /* Check Host IP */
  7896.         return(success = seton(&ssh_chkip));
  7897.         break;
  7898.  
  7899.       case SSH_CMP:                     /* Compression */
  7900.         return(success = seton(&ssh_cmp));
  7901.  
  7902.       case SSH_DYF:                     /* Dynamic Forwarding */
  7903.         return(success = seton(&ssh_dyf));
  7904.  
  7905.       case SSH_GWP:                     /* Gateway ports */
  7906.         return(success = seton(&ssh_gwp));
  7907.  
  7908.       case SSH_GSS:                     /* GSSAPI */
  7909.         if ((y = cmkey(gssapitab,ngssapitab,"","", xxstring)) < 0)
  7910.           return(y);
  7911.         switch (y) {
  7912.           case 1:                       /* Delegate credentials */
  7913.             return(success = seton(&ssh_gsd));
  7914.           case 2:                       /* key-exchange */
  7915.             return(success = seton(&ssh_gkx));
  7916.         }
  7917.         if ((x = cmcfm()) < 0)
  7918.           return(x);
  7919.         return(success = 0);
  7920.  
  7921. #ifdef COMMENT
  7922.       case SSH_KBD:                     /* Kbd Interactive Devices */
  7923.         if ((x = cmcfm()) < 0)
  7924.           return(x);
  7925.         /* TO BE FILLED IN */
  7926.         return(-2);
  7927. #endif /* COMMENT */
  7928.  
  7929.       case SSH_K4:                      /* Kerberos IV */
  7930.       case SSH_K5:                      /* Kerberos V */
  7931.         if ((y = cmkey(tgtpass,1,"","tgt-passing", xxstring)) < 0)
  7932.           return(y);
  7933.         switch (y) {
  7934.           case 1:
  7935.             return(success = (cx == SSH_K4) ?
  7936.                    seton(&ssh_k4tgt) : seton(&ssh_k5tgt));
  7937.         }
  7938.         if ((x = cmcfm()) < 0)
  7939.           return(x);
  7940.         return(success = 0);
  7941.  
  7942.       case SSH_PRP:                     /* Privd port */
  7943.         return(success = seton(&ssh_prp));
  7944.  
  7945.       case SSH_SHH:                     /* Quiet */
  7946.         return(success = seton(&ssh_shh));
  7947.  
  7948.       case SSH_SHK:                     /* Strict Host Key Check */
  7949.         if ((y = cmkey(ooktab,3,"","", xxstring)) < 0)
  7950.           return(y);
  7951.         if ((x = cmcfm()) < 0)
  7952.           return(x);
  7953.         ssh_shk = y;
  7954.         return(success = 1);
  7955.  
  7956.       case SSH_HBT:
  7957.     x = cmnum("Heartbeat interval, seconds","0",10,&z,xxstring);
  7958.     if (x < 0) return(x);
  7959.     if ((x = cmcfm()) < 0) return(x);
  7960.     ssh_hbt = z;
  7961.     return(success = 1);
  7962.  
  7963.       case SSH_V1:                      /* SSH V1 */
  7964.         if ((y = cmkey(sshv1tab,nsshv1tab,"","", xxstring)) < 0)
  7965.           return(y);
  7966.         switch (y) {
  7967.           case SSH1_K54:
  7968.             return(success = seton(&ssh_k5_is_k4));
  7969.           case SSH1_CIF:                /* Not a list */
  7970.             if ((y = cmkey(ssh1ciphers,nssh1ciphers,"","", xxstring)) < 0)
  7971.               if (y != -3)
  7972.                 return(y);
  7973.             if ((x = cmcfm()) < 0) return(x);
  7974.             if (y == -3) {
  7975.                 makestr(&ssh1_cif,NULL);
  7976.             } else {
  7977.                 for (x = 0; x < nssh1ciphers; x++)
  7978.                   if (ssh1ciphers[x].kwval == y)
  7979.                     break;
  7980.                 makestr(&ssh1_cif,ssh1ciphers[x].kwd);
  7981.             }
  7982.             return(1);
  7983.           case SSH1_GNH:
  7984.           case SSH1_UNH:
  7985.             if ((x = cmifi("Filename","",&s,&z,xxstring)) < 0) {
  7986.                 if (x != -3)
  7987.                   return(x);
  7988.             } else {
  7989.                 ckstrncpy(line,s,LINBUFSIZ);
  7990.                 if (zfnqfp(line,TMPBUFSIZ,tmpbuf))
  7991.                   ckstrncpy(line,tmpbuf,LINBUFSIZ);
  7992.             }
  7993.             s = (x == -3) ? NULL : line;
  7994.             if ((x = cmcfm()) < 0)
  7995.               return(x);
  7996.             switch (y) {
  7997.               case SSH1_GNH: makestr(&ssh1_gnh,s); break;
  7998.               case SSH1_UNH: makestr(&ssh1_unh,s); break;
  7999.             }
  8000.             return(1);
  8001.         }
  8002.  
  8003.       case SSH_V2:                      /* SSH V2 */
  8004.         if ((y = cmkey(sshv2tab,nsshv2tab,"","", xxstring)) < 0)
  8005.           return(y);
  8006.         switch (y) {
  8007.           case SSH2_ARK:
  8008.             return(success = seton(&ssh2_ark));
  8009.         case SSH2_AUT: {                        /* Authentication */
  8010. #define TMPCNT 12
  8011.             int i, j, tmp[TMPCNT];
  8012.             for (i = 0; i < TMPCNT; i++)
  8013.               tmp[i] = 0;
  8014.             for (i = 0; i < TMPCNT; i++) {
  8015.                 if ((y = cmkey(ssh2aut,nssh2aut,
  8016.                                "Authentication method","",xxstring)) < 0) {
  8017.                     if (y == -3)
  8018.                       break;
  8019.                     return(y);
  8020.                 }
  8021.                 for (j = 0; j < i; j++) {
  8022.                     if (tmp[j] == y) {
  8023.                         printf("\r\n?Choice has already been used.\r\n");
  8024.                         return(-9);
  8025.                     }
  8026.                 }
  8027.                 tmp[i] = y;
  8028.             }
  8029.             if ((z = cmcfm()) < 0)
  8030.               return(z);
  8031.  
  8032.             if (ssh2_auth) {
  8033.                 free(ssh2_auth);
  8034.                 ssh2_auth = NULL;
  8035.             }
  8036.             if (i > 0) {
  8037.                 int len = 0;
  8038.                 for (j = 0; j < i; j++) {
  8039.                     for (x = 0; x < nssh2aut; x++)
  8040.                       if (ssh2aut[x].kwval == tmp[j] && !ssh2aut[x].flgs)
  8041.                         break;
  8042.                     len += strlen(ssh2aut[x].kwd) + 1;
  8043.                 }
  8044.                 ssh2_auth = malloc(len);
  8045.                 ssh2_auth[0] = '\0';
  8046.                 for (j = 0; j < i; j++) {
  8047.                     for (x = 0; x < nssh2aut; x++)
  8048.                       if (ssh2aut[x].kwval == tmp[j] && !ssh2aut[x].flgs)
  8049.                         break;
  8050.                     ckstrncat(ssh2_auth,ssh2aut[x].kwd,len);
  8051.                     if (j < i - 1)
  8052.                       ckstrncat(ssh2_auth,",",len);
  8053.                 }
  8054.             }
  8055.             return(success = 1);
  8056. #undef TMPCNT
  8057.           }
  8058.         case SSH2_CIF: {
  8059. #define TMPCNT 12
  8060.             int i, j, tmp[TMPCNT];
  8061.             for (i = 0; i < TMPCNT; i++)
  8062.               tmp[i] = 0;
  8063.  
  8064.             for (i = 0; i < TMPCNT; i++) {
  8065.                 if ((y = cmkey(ssh2ciphers,nssh2ciphers,
  8066.                                "","", xxstring)) < 0) {
  8067.                     if (y == -3)
  8068.                       break;
  8069.                     return(y);
  8070.                 }
  8071.                 for (j = 0; j < i; j++) {
  8072.                     if (tmp[j] == y) {
  8073.                         printf("\r\n?Choice has already been used.\r\n");
  8074.                         return(-9);
  8075.                     }
  8076.                 }
  8077.                 tmp[i] = y;
  8078.             }
  8079.             if ((z = cmcfm()) < 0)
  8080.               return(z);
  8081.  
  8082.             if (ssh2_cif) {
  8083.                 free(ssh2_cif);
  8084.                 ssh2_cif = NULL;
  8085.             }
  8086.             if (i > 0) {
  8087.                 int len = 0;
  8088.                 for (j=0; j < i; j++) {
  8089.                     for (x = 0; x < nssh2ciphers; x++)
  8090.                       if (ssh2ciphers[x].kwval == tmp[j] &&
  8091.                           !ssh2ciphers[x].flgs)
  8092.                         break;
  8093.                     len += strlen(ssh2ciphers[x].kwd) + 1;
  8094.                 }
  8095.                 ssh2_cif = malloc(len);
  8096.                 ssh2_cif[0] = '\0';
  8097.                 for (j = 0; j < i; j++) {
  8098.                   for (x = 0; x < nssh2ciphers; x++)
  8099.                     if (ssh2ciphers[x].kwval == tmp[j] && !ssh2ciphers[x].flgs)
  8100.                       break;
  8101.                     ckstrncat(ssh2_cif,ssh2ciphers[x].kwd,len);
  8102.                     if (j < i - 1)
  8103.                       ckstrncat(ssh2_cif,",",len);
  8104.                 }
  8105.             }
  8106.             return(success = 1);
  8107. #undef TMPCNT
  8108.         }
  8109.         case SSH2_MAC: {
  8110. #define TMPCNT 12
  8111.             int i, j, tmp[TMPCNT];
  8112.             for (i = 0; i < TMPCNT; i++)
  8113.               tmp[i] = 0;
  8114.  
  8115.             for (i = 0; i < TMPCNT; i++) {
  8116.                 if ((y = cmkey(ssh2macs,nssh2macs,"","", xxstring)) < 0) {
  8117.                     if (y == -3)
  8118.                       break;
  8119.                     return(y);
  8120.                 }
  8121.                 for (j = 0; j < i; j++) {
  8122.                     if (tmp[j] == y) {
  8123.                         printf("\r\n?Choice has already been used.\r\n");
  8124.                         return(-9);
  8125.                     }
  8126.                 }
  8127.                 tmp[i] = y;
  8128.             }
  8129.             if ((z = cmcfm()) < 0)
  8130.                 return(z);
  8131.  
  8132.             if (ssh2_mac) {
  8133.                 free(ssh2_mac);
  8134.                 ssh2_mac = NULL;
  8135.             }
  8136.             if (i > 0) {
  8137.                 int len = 0;
  8138.                 for (j = 0; j < i; j++) {
  8139.                     for (x = 0; x < nssh2macs; x++)
  8140.                       if (ssh2macs[x].kwval == tmp[j] && !ssh2macs[x].flgs)
  8141.                         break;
  8142.                     len += strlen(ssh2macs[x].kwd) + 1;
  8143.                 }
  8144.                 ssh2_mac = malloc(len);
  8145.                 ssh2_mac[0] = '\0';
  8146.                 for (j=0; j < i; j++) {
  8147.                     for (x = 0; x < nssh2macs; x++)
  8148.                       if (ssh2macs[x].kwval == tmp[j] && !ssh2macs[x].flgs)
  8149.                         break;
  8150.                     ckstrncat(ssh2_mac,ssh2macs[x].kwd,len);
  8151.                     if (j < i - 1)
  8152.                       ckstrncat(ssh2_mac,",",len);
  8153.                 }
  8154.             }
  8155.             return(success = 1);
  8156. #undef TMPCNT
  8157.           }
  8158.           case SSH2_HKA: {
  8159. #define TMPCNT 12
  8160.             int i, j, tmp[TMPCNT];
  8161.             for (i = 0; i < TMPCNT; i++)
  8162.               tmp[i] = 0;
  8163.  
  8164.             for (i = 0; i < TMPCNT; i++) {
  8165.                 if ((y = cmkey(hkatab,nhkatab,
  8166.                                "","", xxstring)) < 0) {
  8167.                     if (y == -3)
  8168.                       break;
  8169.                     return(y);
  8170.                 }
  8171.                 for (j = 0; j < i; j++) {
  8172.                     if (tmp[j] == y) {
  8173.                         printf("\r\n?Choice has already been used.\r\n");
  8174.                         return(-9);
  8175.                     }
  8176.                 }
  8177.                 tmp[i] = y;
  8178.             }
  8179.             if ((z = cmcfm()) < 0)
  8180.               return(z);
  8181.  
  8182.             if (ssh2_hka) {
  8183.                 free(ssh2_hka);
  8184.                 ssh2_hka = NULL;
  8185.             }
  8186.             if (i > 0) {
  8187.                 int len = 0;
  8188.                 for (j=0; j < i; j++) {
  8189.                     for (x = 0; x < nhkatab; x++)
  8190.                       if (hkatab[x].kwval == tmp[j] &&
  8191.                           !hkatab[x].flgs)
  8192.                         break;
  8193.                     len += strlen(hkatab[x].kwd) + 1;
  8194.                 }
  8195.                 ssh2_hka = malloc(len);
  8196.                 ssh2_hka[0] = '\0';
  8197.                 for (j = 0; j < i; j++) {
  8198.                   for (x = 0; x < nhkatab; x++)
  8199.                     if (hkatab[x].kwval == tmp[j] && !hkatab[x].flgs)
  8200.                       break;
  8201.                     ckstrncat(ssh2_hka,hkatab[x].kwd,len);
  8202.                     if (j < i - 1)
  8203.                       ckstrncat(ssh2_hka,",",len);
  8204.                 }
  8205.             }
  8206.             return(success = 1);
  8207. #undef TMPCNT
  8208.           }
  8209.           case SSH2_GNH:
  8210.           case SSH2_UNH:
  8211.             if ((x = cmifi("Filename","",&s,&z,xxstring)) < 0) {
  8212.                 if (x != -3)
  8213.                   return(x);
  8214.             } else {
  8215.                 ckstrncpy(line,s,LINBUFSIZ);
  8216.                 if (zfnqfp(line,TMPBUFSIZ,tmpbuf))
  8217.                   ckstrncpy(line,tmpbuf,LINBUFSIZ);
  8218.             }
  8219.             s = (x == -3) ? NULL : line;
  8220.             if ((x = cmcfm()) < 0)
  8221.               return(x);
  8222.             switch (y) {
  8223.               case SSH2_GNH: makestr(&ssh2_gnh,s); break;
  8224.               case SSH2_UNH: makestr(&ssh2_unh,s); break;
  8225.               default: return(success = 0);
  8226.             }
  8227.             return(success = 1);
  8228.         }
  8229.  
  8230.       case SSH_VRB:                     /* Verbosity level */
  8231.         y = cmnum("SSH verbosity level, 0-7","2",10,&x,xxstring);
  8232.         return(setnum(&ssh_vrb,x,y,7));
  8233.  
  8234.       case SSH_VER:                     /* Version */
  8235.         if ((y = cmkey(sshver,3,"","auto", xxstring)) < 0)
  8236.           return(y);
  8237.         if ((x = cmcfm()) < 0)
  8238.           return(x);
  8239.         ssh_ver = y;                    /* 0 == AUTO */
  8240. #ifndef SSHTEST
  8241.         sl_ssh_ver_saved = 0;
  8242. #endif /* SSHTEST */
  8243.         return(success = 1);
  8244.  
  8245.       case SSH_IDF: {                   /* Identity file */
  8246.         int i, n;
  8247.         for (i = 0; i < 32; i++) {
  8248.             if ((x = cmifi("Filename","",&s,&y,xxstring)) < 0) {
  8249.                 if (x == -3)
  8250.                   break;
  8251.                 return(x);
  8252.             }
  8253.             if (!zfnqfp(s,LINBUFSIZ,line))
  8254.               ckstrncpy(line,s,LINBUFSIZ);
  8255.             makestr(&ssh_tmp[i],line);
  8256.         }
  8257.         n = i;
  8258.         if ((x = cmcfm()) < 0) {
  8259.             for (i = 0; i < n; i++)
  8260.               makestr(&(ssh_tmp[i]),NULL);
  8261.             return(x);
  8262.         }
  8263.         for (i = 0; i < 32; i++) {
  8264.             makestr(&(ssh_idf[i]),NULL);
  8265.             if (i < n) {
  8266.                 ssh_idf[i] = ssh_tmp[i];
  8267.                 ssh_tmp[i] = NULL;
  8268.             } else {
  8269.                 makestr(&(ssh_tmp[i]),NULL);
  8270.             }
  8271.         }
  8272.         ssh_idf_n = n;
  8273.         return(success = 1);
  8274.       }
  8275.       case SSH_XFW:                     /* X11-forwarding */
  8276.         success = seton(&ssh_xfw);
  8277. #ifndef SSHTEST
  8278.         if (success)
  8279.           sl_ssh_xfw_saved = 0;
  8280. #endif /* SSHTEST */
  8281.         return(success);
  8282.  
  8283.       case SSH_XAL:                     /* SSH Xauth Location */
  8284.         if ((x = cmifi("Path to executable", "",&s,&y,xxstring)) < 0) {
  8285.             if (x != -3)
  8286.               return(x);
  8287.         } else {
  8288.             ckstrncpy(line,s,LINBUFSIZ);
  8289.             if (zfnqfp(line,TMPBUFSIZ,tmpbuf))
  8290.               ckstrncpy(line,tmpbuf,LINBUFSIZ);
  8291.         }
  8292.         s = (x == -3) ? NULL : line;
  8293.         if ((x = cmcfm()) < 0) return(x);
  8294.         makestr(&ssh_xal,s);
  8295.         return(success = 1);
  8296.  
  8297.       case SSH_CFG:                     /* Use OpenSSH Config */
  8298.         return(success = seton(&ssh_cfg));
  8299. #endif /* SSHBUILTIN */
  8300.  
  8301.       default:
  8302.         return(-2);
  8303.     }
  8304. }
  8305. #endif /* ANYSSH */
  8306.  
  8307. #ifdef SFTP_BUILTIN
  8308. static int
  8309. dosetsftp() {
  8310.     int cx, x, y, z;
  8311.     char * s;
  8312.  
  8313.     if ((cx = cmkey(sftptab,nsftptab,"","", xxstring)) < 0)
  8314.       return(cx);
  8315.     switch (cx) {
  8316.     case XY_SFTP_EOL:
  8317.     case XY_SFTP_RCS:
  8318.     default:
  8319.         return(-2);
  8320.     }
  8321. }
  8322. #endif /* SFTP_BUILTIN */
  8323.  
  8324. #ifdef KUI
  8325. #include "ikui.h"
  8326. extern ULONG RGBTable[16];
  8327.  
  8328. #define GUI_RGB  1
  8329. #define GUI_WIN  2
  8330. #define GUI_FON  3
  8331. #define GUI_DIA  4
  8332. #define GUI_TLB  5
  8333. #define GUI_MNB  6
  8334. #define GUI_CLS  7
  8335.  
  8336. #define GUIW_POS 1
  8337. #define GUIW_RES 2
  8338. #define GUIW_RUN 3
  8339. #define GUIWR_NON 0
  8340. #define GUIWR_FON 1
  8341. #define GUIWR_DIM 2
  8342. #define GUIWN_RES 1
  8343. #define GUIWN_MIN 2
  8344. #define GUIWN_MAX 3
  8345.  
  8346. static struct keytab guitab[] = {
  8347.     { "close",       GUI_CLS,  0 },
  8348.     { "dialogs",     GUI_DIA,  0 },
  8349.     { "font",        GUI_FON,  0 },
  8350.     { "menubar",     GUI_MNB,  0 },
  8351.     { "rgbcolor",    GUI_RGB,  0 },
  8352.     { "toolbar",     GUI_TLB,  0 },
  8353.     { "window",      GUI_WIN,  0 },
  8354.     { "", 0, 0}
  8355. };
  8356. static int nguitab = (sizeof(guitab) / sizeof(struct keytab));
  8357.  
  8358. static struct keytab guiwtab[] = {
  8359.     { "position",    GUIW_POS, 0 },
  8360.     { "resize-mode", GUIW_RES, 0 },
  8361.     { "run-mode",    GUIW_RUN, 0 },
  8362.     { "", 0, 0}
  8363. };
  8364. static int nguiwtab = (sizeof(guiwtab) / sizeof(struct keytab));
  8365.  
  8366. static struct keytab guiwrtab[] = {
  8367.     { "change-dimensions",  GUIWR_DIM, 0 },
  8368.     { "none",               GUIWR_NON, 0 },
  8369.     { "scale-font",         GUIWR_FON, 0 },
  8370.     { "", 0, 0}
  8371. };
  8372. static int nguiwrtab = (sizeof(guiwrtab) / sizeof(struct keytab));
  8373.  
  8374. static struct keytab guiwntab[] = {
  8375.     { "maximize",  GUIWN_MAX, 0 },
  8376.     { "minimize",  GUIWN_MIN, 0 },
  8377.     { "restore",   GUIWN_RES, 0 },
  8378.     { "", 0, 0}
  8379. };
  8380. static int nguiwntab = (sizeof(guiwntab) / sizeof(struct keytab));
  8381.  
  8382. static struct keytab rgbtab[] = {
  8383.     { "black",         0, 0 },
  8384.     { "blue",          1, 0 },
  8385.     { "brown",         6, 0 },
  8386.     { "cyan",          3, 0 },
  8387.     { "darkgray",      8, 0 },
  8388.     { "dgray",         8, CM_INV },
  8389.     { "green",         2, 0 },
  8390.     { "lblue",         9, CM_INV },
  8391.     { "lcyan",        11, CM_INV },
  8392.     { "lgreen",       10, CM_INV },
  8393.     { "lgray",         7, CM_INV },
  8394.     { "lightblue",     9, 0 },
  8395.     { "lightcyan",    11, 0 },
  8396.     { "lightgreen",   10, 0 },
  8397.     { "lightgray",     7, 0 },
  8398.     { "lightmagenta", 13, 0 },
  8399.     { "lightred",     12, 0 },
  8400.     { "lmagenta",     13, CM_INV },
  8401.     { "lred",         12, CM_INV },
  8402.     { "magenta",       5, 0 },
  8403.     { "red",           4, 0 },
  8404.     { "white",        15, 0 },
  8405.     { "yellow",       14, 0 },
  8406.  
  8407. };
  8408. int nrgb = (sizeof(rgbtab) / sizeof(struct keytab));
  8409.  
  8410. VOID
  8411. shogui() {
  8412.     extern gui_dialog;
  8413.     extern HWND getHwndKUI();
  8414.     unsigned char cmdsav = colorcmd;
  8415.     int i, red, green, blue, lines=0;
  8416.     char * s;
  8417.  
  8418.  
  8419.     printf("GUI paramters:\n");
  8420.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  8421.     printf("  Dialogs:     %s\n",showoff(gui_dialog));
  8422.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  8423.     printf("  Position:    %d,%d\n",get_gui_window_pos_x(),
  8424.             get_gui_window_pos_y());
  8425.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  8426.     printf("  Resolution:  %d x %d\n",GetSystemMetrics(SM_CXSCREEN),
  8427.             GetSystemMetrics(SM_CYSCREEN));
  8428.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  8429.     printf("  Run-mode:    %s\n",IsIconic(getHwndKUI()) ? "minimized" :
  8430.             IsZoomed(getHwndKUI()) ? "maximized" : "restored");
  8431.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  8432.     switch ( get_gui_resize_mode() ) {
  8433.       case GUIWR_NON:
  8434.         s = "none";
  8435.         break;
  8436.       case GUIWR_FON:
  8437.         s = "scales font";
  8438.         break;
  8439.       case GUIWR_DIM:
  8440.         s= "changes dimensions";
  8441.         break;
  8442.     }
  8443.     printf("  Resize-mode: %s\n",s);
  8444.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  8445.     printf("\n");
  8446.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  8447.  
  8448.     printf("RGB Color Table:\n");
  8449.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  8450.     printf("  Color              Red Green Blue\n");
  8451.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  8452.     printf("  ------------------------------------------\n");
  8453.     if (++lines > cmd_rows - 3) { if (!askmore()) return; else lines = 0; }
  8454.     for (i = 0; i < nrgb; i++) {
  8455.         if (!rgbtab[i].flgs) {
  8456.             blue = (RGBTable[rgbtab[i].kwval] & 0x00FF0000)>>16;
  8457.             green = (RGBTable[rgbtab[i].kwval] & 0x0000FF00)>>8;
  8458.             red = (RGBTable[rgbtab[i].kwval] & 0x000000FF);
  8459.             printf("  %-18s %3d  %3d  %3d  ",rgbtab[i].kwd,red,green,blue);
  8460.             colorcmd = rgbtab[i].kwval << 4;
  8461.             printf("********");
  8462.             colorcmd = cmdsav;
  8463.             printf("\n");
  8464.             if (++lines > cmd_rows - 3) {
  8465.         if (!askmore())
  8466.           return;
  8467.         else
  8468.           lines = 0;
  8469.         }
  8470.         }
  8471.     }
  8472.     printf("\n");
  8473. }
  8474.  
  8475. int
  8476. setrgb() {
  8477.     int cx, red = 0, blue = 0, green = 0, z, x;
  8478.  
  8479.     if ((cx = cmkey(rgbtab,nrgb,"","",xxstring)) < 0)
  8480.       return(cx);
  8481.     if ((z = cmnum("Red value, 0-255","",10,&red,xxstring)) < 0)
  8482.       return(z);
  8483.     if ((z = cmnum("Green value, 0-255","",10,&green,xxstring)) < 0)
  8484.       return(z);
  8485.     if ((z = cmnum("Blue value, 0-255","",10,&blue,xxstring)) < 0)
  8486.       return(z);
  8487.     if ((x = cmcfm()) < 0) return(x);
  8488.     if (cx > 15 || red > 255 || blue > 255 || green > 255)
  8489.       return(-2);
  8490.     RGBTable[cx] = (unsigned)(((unsigned)blue << 16) |
  8491.         (unsigned)((unsigned)green << 8) |
  8492.         (unsigned)red);
  8493.     return(success = 1);
  8494. }
  8495.  
  8496. /*
  8497.   Set GUI window position: XY coordinates of upper left corner,
  8498.   expressed as pixel numbers in the current screen resolution.
  8499.   (0,0) means put ourselves in the upper left corner.
  8500.   Can we check for out of bounds?
  8501. */
  8502.  
  8503. int
  8504. setguiwin() {
  8505.     int cx, x, y, z;
  8506.     if ((cx = cmkey(guiwtab,nguiwtab,"","",xxstring)) < 0)
  8507.       return(cx);
  8508.     switch (cx) {
  8509.       case GUIW_POS:
  8510.         if ((z = cmnum("X coordinate (pixel number)","",10,&x,xxstring)) < 0)
  8511.           return(z);
  8512.         if ((z = cmnum("Y coordinate (pixel number)","",10,&y,xxstring)) < 0)
  8513.           return(z);
  8514.         if ((z = cmcfm()) < 0)
  8515.           return(z);
  8516.         if (x < 0 || y < 0) {
  8517.             printf("?Coordinates must be 0 or greater\n");
  8518.             return(-9);
  8519.         }
  8520.         gui_position(x,y);
  8521.         return(success = 1);
  8522.       case GUIW_RES:
  8523.         if ((x = cmkey(guiwrtab,nguiwrtab,"","",xxstring)) < 0)
  8524.           return(x);
  8525.         if ((z = cmcfm()) < 0)
  8526.           return(z);
  8527.         gui_resize_mode(x);
  8528.         return(success = 1);
  8529.       case GUIW_RUN:
  8530.     if ((x = cmkey(guiwntab,nguiwntab,"","",xxstring)) < 0)
  8531.       return(x);
  8532.     if ((z = cmcfm()) < 0)
  8533.       return(z);
  8534.     gui_win_run_mode(x);
  8535.     return(success = 1);
  8536.       default:
  8537.         return(-2);
  8538.     }
  8539. }
  8540.  
  8541. int
  8542. setguifont() {                /* Assumes that CKFLOAT is defined! */
  8543.  
  8544.     extern struct keytab * term_font;
  8545.     extern struct keytab * _term_font;
  8546.     extern int tt_font, tt_font_size, ntermfont;
  8547.     int x, y, z;
  8548.     char *s;
  8549.  
  8550.     if (ntermfont == 0)
  8551.       BuildFontTable(&term_font, &_term_font, &ntermfont);
  8552.     if (!(term_font && _term_font && ntermfont > 0)) {
  8553.         printf("?Internal error: Failure to enumerate fonts\n");
  8554.         return(-9);
  8555.     }
  8556.     if ((x = cmkey(_term_font,ntermfont,"","",xxstring)) < 0)
  8557.       return(x);
  8558.     if ((z = cmfld("Height of font in points","12",&s,xxstring)) < 0)
  8559.       return(z);
  8560.     if (isfloat(s,0) < 1) {        /* (sets floatval) */
  8561.     printf("?Integer or floating-point number required\n");
  8562.     return(-9);
  8563.     }
  8564.     if (floatval < 0.5) {
  8565.     printf("?Positive number required\n");
  8566.     return(-9);
  8567.     }
  8568.     if ((z = cmcfm()) < 0)
  8569.       return(z);
  8570.     tt_font = x;            /* Font index */
  8571.     tt_font_size = (int)(floatval * 2);    /* Font size in half points */
  8572.     KuiSetProperty(KUI_TERM_FONT, (long)tt_font, (long)tt_font_size);
  8573.     return(success = 1);
  8574. }
  8575.  
  8576. VOID
  8577. setguidialog(x) int x;
  8578. {
  8579.     extern int gui_dialog;
  8580.     gui_dialog = x;
  8581.     KuiSetProperty(KUI_GUI_DIALOGS, (long)x, 0L);
  8582. }
  8583.  
  8584. VOID
  8585. setguimenubar(x) int x;
  8586. {
  8587.     KuiSetProperty(KUI_GUI_MENUBAR, (long)x, 0L);
  8588. }
  8589.  
  8590. VOID
  8591. setguitoolbar(x) int x;
  8592. {
  8593.     KuiSetProperty(KUI_GUI_TOOLBAR, (long)x, 0L);
  8594. }
  8595.  
  8596. VOID
  8597. setguiclose(x) int x;
  8598. {
  8599.     KuiSetProperty(KUI_GUI_CLOSE, (long)x, 0L);
  8600. }
  8601.  
  8602. int
  8603. setgui() {
  8604.     int cx, x, rc;
  8605.     if ((cx = cmkey(guitab,nguitab,"","",xxstring)) < 0)
  8606.       return(cx);
  8607.     switch (cx) {
  8608.       case GUI_DIA:
  8609.         rc = seton(&x);
  8610.         if (rc >= 0)
  8611.           setguidialog(x);
  8612.         return(rc);
  8613.       case GUI_FON:
  8614.         return(setguifont());
  8615.       case GUI_RGB:
  8616.         return(setrgb());
  8617.       case GUI_WIN:
  8618.         return(setguiwin());
  8619.       case GUI_TLB:
  8620.         rc = seton(&x);
  8621.         if (rc >= 0)
  8622.           setguitoolbar(x);
  8623.         return(rc);
  8624.       case GUI_MNB:
  8625.         rc = seton(&x);
  8626.         if (rc >= 0)
  8627.           setguimenubar(x);
  8628.         return(rc);
  8629.       case GUI_CLS:
  8630.         rc = seton(&x);
  8631.         if (rc >= 0)
  8632.           setguiclose(x);
  8633.         return(rc);
  8634.       default:
  8635.         return(-2);
  8636.     }
  8637. }
  8638. #endif /* KUI */
  8639.  
  8640. VOID
  8641. setexitwarn(x) int x; 
  8642. {
  8643.     xitwarn = x;
  8644. #ifdef KUI
  8645.     KuiSetProperty(KUI_EXIT_WARNING, (long)x, 0L);
  8646. #endif /* KUI */
  8647. }
  8648.  
  8649. #ifndef NOLOCAL
  8650. VOID
  8651. setdebses(x) int x; {
  8652. #ifdef OS2
  8653.     if ((debses != 0) && (x == 0))    /* It was on and we turned it off? */
  8654.       os2debugoff();            /* Fix OS/2 coloration */
  8655. #endif /* OS2 */
  8656.     debses = x;
  8657. #ifdef KUI
  8658.     KuiSetProperty(KUI_TERM_DEBUG,x,0);
  8659. #endif /* KUI */
  8660. }
  8661. #endif /* NOLOCAL */
  8662.  
  8663. /*  D O P R M  --  Set a parameter.  */
  8664. /*
  8665.  Returns:
  8666.   -2: illegal input
  8667.   -1: reparse needed
  8668.    0: success
  8669. */
  8670. int
  8671. doprm(xx,rmsflg) int xx, rmsflg; {
  8672.     int i = 0, x = 0, y = 0, z = 0;
  8673.     long zz = 0L;
  8674.     char *s = NULL, *p = NULL;
  8675. #ifdef OS2
  8676.     char portbuf[64];
  8677.     long portspeed = 0L;
  8678.     int portparity = 0;
  8679.     int portflow = 0;
  8680. #endif /* OS2 */
  8681.  
  8682. #ifndef NOSETKEY
  8683. #ifdef OS2
  8684.     if (xx == XYMSK)
  8685.       return(setmsk());
  8686. #endif /* OS2 */
  8687. #endif /* NOSETKEY */
  8688.  
  8689.     if (xx == XYFLAG) {                 /* SET FLAG */
  8690.         extern int ooflag;
  8691.         return(success = seton(&ooflag));
  8692.     }
  8693.     if (xx == XYPRTR                    /* SET PRINTER (or BPRINTER) */
  8694. #ifdef BPRINT
  8695.         || xx == XYBDCP
  8696. #endif /* BPRINT */
  8697.         )
  8698.       return(setprinter(xx));
  8699.  
  8700.     switch (xx) {
  8701.  
  8702. #ifdef ANYX25                           /* SET X25 ... */
  8703. case XYX25:
  8704.         return(setx25());
  8705.  
  8706. #ifndef IBMX25
  8707. case XYPAD:                             /* SET PAD ... */
  8708.         return(setpadp());
  8709. #endif /* IBMX25 */
  8710. #endif /* ANYX25 */
  8711.  
  8712. #ifndef NOXFER
  8713.       case XYEOL:       /* These have all been moved to set send/receive... */
  8714.       case XYLEN:       /* Let the user know what to do. */
  8715.       case XYMARK:
  8716.       case XYNPAD:
  8717.       case XYPADC:
  8718.       case XYTIMO:
  8719.         printf("...Use SET SEND or SET RECEIVE instead.\n");
  8720.         printf("Type HELP SET SEND or HELP SET RECEIVE for more info.\n");
  8721.         return(success = 0);
  8722.  
  8723.       case XYATTR:                      /* File Attribute packets */
  8724.         return(setat(rmsflg));
  8725.  
  8726.       case XYIFD:                       /* Incomplete file disposition */
  8727.         if ((y = cmkey(ifdatab,3,"","auto",xxstring)) < 0) return(y);
  8728.         if ((x = cmcfm()) < 0) return(x);
  8729.         if (rmsflg) {
  8730.             sstate = setgen('S',
  8731.                             "310",
  8732.                             y == 0 ? "0" : (y == 1 ? "1" : "2"),
  8733.                             ""
  8734.                             );
  8735.             return((int) sstate);
  8736.         } else {
  8737.             keep = y;
  8738.             return(success = 1);
  8739.         }
  8740. #endif /* NOXFER */
  8741.  
  8742.       case XYMATCH:            /* [ REMOTE ] SET MATCH...  */
  8743. #ifndef NOXFER
  8744.     if ((z = cmkey(matchtab,nmatchtab,"","",xxstring)) < 0)
  8745.       return(z);
  8746.     if (rmsflg) {
  8747.             if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  8748.         if ((x = cmcfm()) < 0) return(x);
  8749.         switch (z) {
  8750.           case MCH_DOTF:
  8751.         return(sstate = setgen('S',"330", y == 0 ? "0" : "1", ""));
  8752.           case MCH_FIFO:
  8753.         return(sstate = setgen('S',"331", y == 0 ? "0" : "1", ""));
  8754.           default:
  8755.         return(-2);
  8756.           }
  8757.       }
  8758. #endif /* NOXFER */
  8759.       switch (z) {
  8760.         case MCH_FIFO:
  8761.           return(success = seton(&matchfifo));
  8762.         case MCH_DOTF:
  8763.           x = seton(&matchdot); 
  8764.           if (x < 0) return(x);
  8765.           dir_dots = -1;
  8766.           return(success = x);
  8767.         default:
  8768.           return(-2);
  8769.       }
  8770.  
  8771. #ifndef NOSPL
  8772.       case XYINPU:                      /* SET INPUT */
  8773.         return(setinp());
  8774. #endif /* NOSPL */
  8775.  
  8776. #ifdef NETCONN
  8777.       case XYNET: {                     /* SET NETWORK */
  8778.  
  8779.           struct FDB k1, k2;
  8780.  
  8781.           cmfdbi(&k1,_CMKEY,"","","",nnetkey, 0, xxstring, netkey, &k2);
  8782.           cmfdbi(&k2,_CMKEY,"","","",nnets,   0, xxstring, netcmd, NULL);
  8783.  
  8784. #ifdef OS2     /* Hide network-type keywords for networks not installed */
  8785.           for (z = 0; z < nnets; z++) {
  8786.               if (netcmd[z].kwval == NET_TCPB && tcp_avail == 0)
  8787.                 netcmd[z].flgs =  CM_INV;
  8788. #ifdef SSHBUILTIN
  8789.               if (netcmd[z].kwval == NET_SSH &&
  8790.                    !ck_ssleay_is_installed())
  8791.                 netcmd[z].flgs =  CM_INV;
  8792. #endif /* SSHBUILTIN */
  8793. #ifdef DECNET
  8794.               else if (netcmd[z].kwval == NET_DEC  && dnet_avail == 0)
  8795.                 netcmd[z].flgs =  CM_INV;
  8796. #endif /* DECNET */
  8797. #ifdef CK_NETBIOS
  8798.               else if (netcmd[z].kwval == NET_BIOS && netbiosAvail == 0)
  8799.                 netcmd[z].flgs =  CM_INV;
  8800. #endif /* CK_NETBIOS */
  8801. #ifdef SUPERLAT
  8802.               else if (netcmd[z].kwval == NET_SLAT  && slat_avail == 0)
  8803.                 netcmd[z].flgs =  CM_INV;
  8804. #endif /* SUPERLAT */
  8805.           }
  8806.           if (tcp_avail)                /* Default network type */
  8807.             ckstrncpy(tmpbuf,"tcp/ip",TMPBUFSIZ);
  8808. #ifdef SSHBUILTIN
  8809.           else if ( ck_ssleay_is_installed() )
  8810.             ckstrncpy(tmpbuf,"ssh",TMPBUFSIZ);
  8811. #endif /* SSHBUILTIN */
  8812. #ifdef DECNET
  8813.           else if (dnet_avail)
  8814.             ckstrncpy(tmpbuf,"decnet",TMPBUFSIZ);
  8815. #endif /* DECNET */
  8816. #ifdef SUPERLAT
  8817.           else if (slat_avail)
  8818.             ckstrncpy(tmpbuf,"superlat",TMPBUFSIZ);
  8819. #endif /* SUPERLAT */
  8820. #ifdef CK_NETBIOS
  8821.           else if (netbiosAvail)
  8822.             ckstrncpy(tmpbuf,"netbios",TMPBUFSIZ);
  8823. #endif /* CK_NETBIOS */
  8824.           else ckstrncpy(tmpbuf,"named-pipe",TMPBUFSIZ);
  8825. #else  /* OS2 */
  8826. #ifdef TCPSOCKET
  8827.           ckstrncpy(tmpbuf,"tcp/ip",TMPBUFSIZ);
  8828. #else
  8829. #ifdef ANYX25
  8830.           ckstrncpy(tmpbuf,"x.25",TMPBUFSIZ);
  8831. #else
  8832.           ckstrncpy(tmpbuf,"",TMPBUFSIZ);
  8833. #endif /* ANYX25 */
  8834. #endif /* TCPSOCKET */
  8835. #endif /* OS2 */
  8836.  
  8837.           x = cmfdb(&k1);
  8838.           if (x < 0) {                  /* Error */
  8839.               if (x == -2 || x == -9)
  8840.                 printf("?No keywords match: \"%s\"\n",atmbuf);
  8841.               return(x);
  8842.           }
  8843.           z = cmresult.nresult;         /* Keyword value */
  8844.           if (cmresult.fdbaddr == &k1) { /* Which table? */
  8845. #ifndef NOSPL
  8846. #ifndef NODIAL
  8847.               if (z == XYNET_D)
  8848.                 return(parsdir(1));
  8849. #endif /* NODIAL */
  8850. #endif /* NOSPL */
  8851.               if ((z = cmkey(netcmd,nnets,"",tmpbuf,xxstring)) < 0)
  8852.                 return(z);
  8853.           }
  8854.  
  8855. #ifdef NETCMD
  8856.           if (z == NET_CMD && nopush) {
  8857.               printf("\n?Sorry, access to external commands is disabled\n");
  8858.               return(-9);
  8859.           }
  8860. #endif /* NETCMD */
  8861.  
  8862. #ifndef NOPUSH
  8863. #ifdef NETPTY
  8864.           if (z == NET_PTY && nopush) {
  8865.               printf("\n?Sorry, access to external commands is disabled\n");
  8866.               return(-9);
  8867.           }
  8868. #endif /* NETPTY */
  8869. #endif /* NOPUSH */
  8870.  
  8871. #ifdef OS2
  8872.           if (z == NET_TCPB && tcp_avail == 0) {
  8873.               printf(
  8874. "\n?Sorry, either TCP/IP is not available on this system or\n\
  8875. necessary DLLs did not load.  Use SHOW NETWORK to check network status.\n");
  8876.               return(-9);
  8877. #ifdef SSHBUILTIN
  8878.           } else if (z == NET_SSH && !ck_ssleay_is_installed()) {
  8879.             printf("\n?Sorry, SSH is not available on this system.\n") ;
  8880.             return(-9);
  8881. #endif /* SSHBUILTIN */
  8882. #ifdef CK_NETBIOS
  8883.           } else if (z == NET_BIOS && netbiosAvail == 0) {
  8884.               printf("\n?Sorry, NETBIOS is not available on this system.\n") ;
  8885.               return(-9);
  8886. #endif /* CK_NETBIOS */
  8887. #ifdef DECNET
  8888.           } else if (z == NET_DEC && dnet_avail == 0) {
  8889.               printf("\n?Sorry, DECnet is not available on this system.\n") ;
  8890.               return(-9);
  8891. #endif /* DECNET */
  8892. #ifdef SUPERLAT
  8893.           } else if (z == NET_SLAT && slat_avail == 0) {
  8894.               printf("\n?Sorry, SuperLAT is not available on this system.\n") ;
  8895.               return(-9);
  8896. #endif /* SUPERLAT */
  8897.           }
  8898. #endif /* OS2 */
  8899.  
  8900. #ifdef NPIPEORBIOS
  8901.           if (z == NET_PIPE ||          /* Named pipe -- also get pipename */
  8902.               z == NET_BIOS) {          /* NETBIOS -- also get local name */
  8903.               char *defnam;
  8904. #ifdef CK_NETBIOS
  8905.               char tmpnbnam[NETBIOS_NAME_LEN+1];
  8906. #endif /* CK_NETBIOS */
  8907.               /* Construct default name  */
  8908.               if (z == NET_PIPE) {      /* Named pipe */
  8909.                   defnam = "kermit";    /* Default name is always "kermit" */
  8910.               } 
  8911. #ifdef CK_NETBIOS
  8912.           else {            /* NetBIOS */
  8913.                   if (NetBiosName[0] != SP) { /* If there is already a name, */
  8914.                       char *p = NULL;
  8915.                       int n;            /* use it as the default. */
  8916.                       ckstrncpy(tmpnbnam,NetBiosName,NETBIOS_NAME_LEN+1);
  8917.                       /* convert trailing spaces to NULs */
  8918.                       p = &tmpnbnam[NETBIOS_NAME_LEN-1];
  8919.                       while (*p == SP) {
  8920.                           *p = NUL;
  8921.                           p--;
  8922.                       }
  8923.                       defnam = tmpnbnam;
  8924.                   } else if (*myhost)   /* Otherwise use this PC's host name */
  8925.                     defnam = (char *) myhost;
  8926.                   else                  /* Otherwise use "kermit" */
  8927.                     defnam = "kermit";
  8928.               }
  8929. #endif /* CK_NETBIOS */
  8930.               if ((y = cmtxt((z == NET_PIPE) ? "name of named-pipe" :
  8931.                              "local NETBIOS name",
  8932.                              defnam, &s, xxstring)) < 0)
  8933.                 return(y);
  8934. #ifdef NPIPE
  8935.               pipename[0] = NUL;
  8936. #endif /* NPIPE */
  8937.               if ((y = (int) strlen(s)) < 1) {
  8938.                   printf("?You must also specify a %s name\n",
  8939.                          (z == NET_PIPE) ? "pipe" : "local NETBIOS" );
  8940.                   return(-9);
  8941.               }
  8942. #ifdef CK_NETBIOS
  8943.               if (z == NET_BIOS) {
  8944.                   if (!netbiosAvail) {
  8945.                       printf("?NETBIOS is not available on this system.\n") ;
  8946.                       return(-9);
  8947.                   }
  8948.                   if (y - NETBIOS_NAME_LEN > 0) {
  8949.                       printf("?NETBIOS name too long, %ld maximum\n",
  8950.                              NETBIOS_NAME_LEN);
  8951.                       return(-9);
  8952.                   } else if ( !strcmp(s,tmpnbnam) ) {
  8953.                       nettype = z;      /* Returning to old connection... */
  8954.                       return(success = 1); /* Done */
  8955.                   } else if (strcmp("                ",NetBiosName)) {
  8956.                       printf("?NETBIOS name already assigned to \"%s\"\n",
  8957.                              NetBiosName);
  8958.                       return(-9);
  8959.                   } else {
  8960.                       NCB ncb;
  8961.                       APIRET rc;
  8962.                       ckstrncpy(NetBiosName,s,16);
  8963.                       for (x = y; x < NETBIOS_NAME_LEN; x++)
  8964.                         NetBiosName[x] = SP;
  8965.                       NetBiosName[NETBIOS_NAME_LEN] = NUL;
  8966.                       printf("Checking \"%s\" as a unique NetBIOS name...\n",
  8967.                              NetBiosName);
  8968.                       rc = NCBAddName( NetbeuiAPI,
  8969.                                       &ncb, NetBiosAdapter, NetBiosName );
  8970.                       if (rc) {
  8971.                           printf(
  8972.                 "?Sorry, \"%s\" is already in use by another NetBIOS node.\n",
  8973.                                  NetBiosName);
  8974.                           for (x = 0; x < NETBIOS_NAME_LEN; x++)
  8975.                             NetBiosName[x] = SP;
  8976.                           return(-9);
  8977.                       }
  8978.                   }
  8979.               }
  8980. #endif /* CK_NETBIOS */
  8981. #ifdef NPIPE
  8982.               if (z == NET_PIPE)
  8983.                 ckstrncpy(pipename,s,PIPENAML);
  8984. #endif /* NPIPE */
  8985.           } else
  8986. #endif /* NPIPEORBIOS */
  8987. #ifdef DECNET
  8988.             if (z == NET_DEC) {
  8989.                 /* Determine if we are using LAT or CTERM */
  8990.                 if ((y = cmkey(dnettab,
  8991.                                ndnet,"DECNET protocol","lat",xxstring)) < 0)
  8992.                   return(y);
  8993.                 if ((x = cmcfm()) < 0) return(x);
  8994.                 ttnproto = y;
  8995.             } else
  8996. #endif /* DECNET */
  8997. #ifdef NETDLL
  8998.               if (z == NET_DLL) {
  8999.                   /* Find out which DLL they are using */
  9000.                   char dllname[256]="";
  9001.                   char * p=NULL;
  9002.                   if ((x = cmifi("Dynamic load library",
  9003.                                  "",&p,&y,xxstring)) < 0) {
  9004.                       if (x == -3) {
  9005.                           printf("?Name of DLL required\n");
  9006.                           return(-9);
  9007.                       }
  9008.                       return(x);
  9009.                   }
  9010.                   ckstrncpy(dllname,p,256);
  9011.                   if ((x = cmcfm()) < 0) return(x);
  9012.  
  9013.                   if (netdll_load(dllname) < 0) /* Try to load the dll */
  9014.                     return(success = 0);
  9015.                   else {
  9016.                       nettype = z;
  9017.                       return(success = 1);
  9018.                   }
  9019.               } else
  9020. #endif /* NETDLL */
  9021.                 if ((x = cmcfm()) < 0) return(x);
  9022.           nettype = z;
  9023.           if (
  9024. #ifdef DECNET
  9025.               (nettype != NET_DEC)  &&
  9026. #endif /* DECNET */
  9027. #ifdef NPIPE
  9028.               (nettype != NET_PIPE) &&
  9029. #endif /* NPIPE */
  9030. #ifdef CK_NETBIOS
  9031.               (nettype != NET_BIOS) &&
  9032. #endif /* CK_NETBIOS */
  9033. #ifdef NETFILE
  9034.               (nettype != NET_FILE) &&
  9035. #endif /* NETFILE */
  9036. #ifdef NETCMD
  9037.               (nettype != NET_CMD) &&
  9038. #endif /* NETCMD */
  9039. #ifdef NETPTY
  9040.               (nettype != NET_PTY) &&
  9041. #endif /* NETPTY */
  9042. #ifdef NETDLL
  9043.               (nettype != NET_DLL) &&
  9044. #endif /* NETDLL */
  9045. #ifdef SUPERLAT
  9046.               (nettype != NET_SLAT) &&
  9047. #endif /* SUPERLAT */
  9048.               (nettype != NET_SX25) &&
  9049.               (nettype != NET_VX25) &&
  9050. #ifdef IBMX25
  9051.               (nettype != NET_IX25) &&
  9052. #endif /* IBMX25 */
  9053. #ifdef SSHBUILTIN
  9054.               (nettype != NET_SSH) &&
  9055. #endif /* SSHBUILTIN */
  9056.               (nettype != NET_TCPB)) {
  9057.               printf("?Network type not supported\n");
  9058.               return(success = 0);
  9059.           } else {
  9060.               return(success = 1);
  9061.           }
  9062.       }
  9063.  
  9064. #ifndef NOTCPOPTS
  9065. #ifdef TCPSOCKET
  9066.       case XYTCP: {
  9067.         extern int ttyfd;
  9068.  
  9069.         if ((z = cmkey(tcpopt,ntcpopt,"TCP option","nodelay",xxstring)) < 0)
  9070.           return(z);
  9071.  
  9072.         switch (z) {
  9073. #ifndef NOHTTP
  9074.           case XYTCP_HTTP_PROXY: {
  9075.           struct FDB sw, tx;
  9076.           int n, x;
  9077.           char ubuf[LOGINLEN+1], pbuf[LOGINLEN+1], abuf[256];
  9078.           ubuf[0] = pbuf[0] = abuf[0] = 0;
  9079.  
  9080.           cmfdbi(&sw,        /* First FDB - switches */
  9081.              _CMKEY,        /* fcode */
  9082.              "HTTP proxy server host[:port] or switch",
  9083.              "",        /* default */
  9084.              "",        /* addtl string data */
  9085.              nuserpass,        /* addtl numeric data 1: tbl size */
  9086.              4,            /* addtl numeric data 2: 4 = cmswi */
  9087.              xxstring,        /* Processing function */
  9088.              userpass,        /* Keyword table */
  9089.              &tx        /* Pointer to next FDB */
  9090.              );
  9091.           cmfdbi(&tx,
  9092.              _CMTXT,        /* fcode */
  9093.              "HTTP proxy server host[:port]",
  9094.              "",        /* default */
  9095.              "",        /* addtl string data */
  9096.              0,            /* addtl numeric data 1 */
  9097.              0,            /* addtl numeric data 2 */
  9098.              xxstring,
  9099.              NULL,
  9100.              NULL
  9101.              );
  9102.           while (1) {
  9103.           if ((x = cmfdb(&sw)) < 0) {
  9104.               if (x == -3) {
  9105.               x = -9;
  9106.               printf("?Hostname required\n");
  9107.               }
  9108.               return(x);
  9109.           }
  9110.           if (cmresult.fcode != _CMKEY)
  9111.             break;
  9112.           n = cmresult.nresult;
  9113.           switch (n) {
  9114.             case UPW_USER:
  9115.             case UPW_PASS:
  9116.             case UPW_AGENT:
  9117.               if ((x = cmfld((n == UPW_USER) ?
  9118.                      "Username" :
  9119.                      ((n == UPW_PASS) ? "Password" : "Agent"),
  9120.                      "", &s, xxstring)) < 0) {
  9121.               if (x != -3)
  9122.                 return(x);
  9123.               }
  9124.               ckstrncpy((n == UPW_USER) ? ubuf :
  9125.                         ((n == UPW_PASS) ? pbuf : abuf), s, 
  9126.                         (n == UPW_AGENT) ? 256 : (LOGINLEN+1));
  9127.           }
  9128.           }
  9129.           if (cmresult.fcode != _CMTXT)
  9130.         return(-2);
  9131.           s = cmresult.sresult;
  9132.           if (s) if (!*s) s = NULL;
  9133.  
  9134. #ifdef IKSDCONF
  9135.           if (iksdcf)
  9136.         return(success = 0);
  9137. #endif /* IKSDCONF */
  9138.           makestr(&tcp_http_proxy_user,ubuf[0]?ubuf:NULL);
  9139.           makestr(&tcp_http_proxy_pwd,pbuf[0]?pbuf:NULL);
  9140.           makestr(&tcp_http_proxy_agent,abuf[0]?abuf:NULL);
  9141.           makestr(&tcp_http_proxy,s);
  9142.           memset(pbuf,0,sizeof(pbuf));
  9143.           return(success = 1);
  9144.       }
  9145. #endif /* NOHTTP */
  9146. /*
  9147.   It would have been easy to combine XYTCP_SOCKS_SVR with the previous
  9148.   one except for the #ifdefs...
  9149. */
  9150. #ifdef NT
  9151. #ifdef CK_SOCKS
  9152.           case XYTCP_SOCKS_SVR: {
  9153.           char ubuf[LOGINLEN+1], pbuf[LOGINLEN+1];
  9154.           char * p = getenv("SOCKS_SERVER");
  9155.           struct FDB sw, tx;
  9156.           int n, x;
  9157.  
  9158.           if (!p) p = "";
  9159.  
  9160.           cmfdbi(&sw,        /* First FDB - switches */
  9161.              _CMKEY,        /* fcode */
  9162.              "SOCKS server host[:port] or switch",
  9163.              "",        /* default */
  9164.              "",        /* addtl string data */
  9165.              nuserpass,        /* addtl numeric data 1: tbl size */
  9166.              4,            /* addtl numeric data 2: 4 = cmswi */
  9167.              xxstring,        /* Processing function */
  9168.              userpass,        /* Keyword table */
  9169.              &tx        /* Pointer to next FDB */
  9170.              );
  9171.           cmfdbi(&tx,
  9172.              _CMTXT,        /* fcode */
  9173.              "SOCKS server host[:port]",
  9174.              p,            /* default */
  9175.              "",        /* addtl string data */
  9176.              0,            /* addtl numeric data 1 */
  9177.              0,            /* addtl numeric data 2 */
  9178.              xxstring,
  9179.              NULL,
  9180.              NULL
  9181.              );
  9182.           while (1) {
  9183.           if ((x = cmfdb(&sw)) < 0) {
  9184.               if (x == -3) {
  9185.               x = -9;
  9186.               printf("?Hostname required\n");
  9187.               }
  9188.               return(x);
  9189.           }
  9190.           if (cmresult.fcode != _CMKEY)
  9191.             break;
  9192.           n = cmresult.nresult;
  9193.           switch (n) {
  9194.             case UPW_USER:
  9195.             case UPW_PASS:
  9196.               if ((x = cmfld((n == UPW_USER) ? "Username" : "Password",
  9197.                      "", &s, xxstring)) < 0) {
  9198.               if (x != -3)
  9199.                 return(x);
  9200.               }
  9201.               ckstrncpy((n == UPW_USER) ? ubuf : pbuf, s, LOGINLEN+1);
  9202.           }
  9203.           }
  9204.           if (cmresult.fcode != _CMTXT)
  9205.         return(-2);
  9206.           s = cmresult.sresult;
  9207.           if (s) if (!*s) s = NULL;
  9208.  
  9209. #ifdef IKSDCONF
  9210.           if (iksdcf)
  9211.         return(success = 0);
  9212. #endif /* IKSDCONF */
  9213.           makestr(&tcp_socks_user,ubuf);
  9214.               memset(pbuf,0,sizeof(pbuf));
  9215.           makestr(&tcp_socks_svr,s);
  9216.           return(success = 1);
  9217.       }
  9218.  
  9219. #ifdef CK_SOCKS_NS
  9220.           case XYTCP_SOCKS_NS: {
  9221.             char * p = getenv("SOCKS_NS");
  9222.             if (!p) p = "";
  9223.             if ((y = cmtxt("hostname or IP of SOCKS Name Server",p,
  9224.                             &s,xxstring)) < 0)
  9225.                 return(y);
  9226. #ifdef IKSDCONF
  9227.               if (iksdcf) return(success = 0);
  9228. #endif /* IKSDCONF */
  9229.               if (tcp_socks_ns) {
  9230.                   free(tcp_socks_ns);   /* Free any previous storage */
  9231.                   tcp_socks_ns = NULL;
  9232.               }
  9233.               if (s == NULL || *s == NUL) { /* If none given */
  9234.                   tcp_socks_ns = NULL;  /* remove the override string */
  9235.                   return(success = 1);
  9236.               } else if ((tcp_socks_ns = malloc(strlen(s)+1))) {
  9237.                   strcpy(tcp_socks_ns,s);
  9238.                   return(success = 1);
  9239.               } else
  9240.                 return(success = 0);
  9241.           }
  9242. #endif /* CK_SOCKS_NS */
  9243. #endif /* CK_SOCKS */
  9244. #endif /* NT */
  9245.           case XYTCP_ADDRESS:
  9246.             if ((y = cmtxt("preferred IP Address for TCP connections","",
  9247.                            &s,xxstring)) < 0)
  9248.               return(y);
  9249. #ifdef IKSDCONF
  9250.             if (iksdcf) return(success = 0);
  9251. #endif /* IKSDCONF */
  9252.             if (tcp_address) {
  9253.                 free(tcp_address);      /* Free any previous storage */
  9254.                 tcp_address = NULL;
  9255.             }
  9256.             if (s == NULL || *s == NUL) { /* If none given */
  9257.                 tcp_address = NULL;     /* remove the override string */
  9258.                 return(success = 1);
  9259.             } else if ((tcp_address = malloc(strlen(s)+1))) {
  9260.                 strcpy(tcp_address,s);
  9261.                 return(success = 1);
  9262.             } else
  9263.               return(success = 0);
  9264. #ifdef SO_KEEPALIVE
  9265.           case XYTCP_KEEPALIVE:
  9266.             if ((z = cmkey(onoff,2,"","on",xxstring)) < 0) return(z);
  9267.             if ((y = cmcfm()) < 0) return(y);
  9268. #ifdef IKSDCONF
  9269.             if (iksdcf) return(success = 0);
  9270. #endif /* IKSDCONF */
  9271. #ifdef SSHBUILTIN
  9272.             if (network && nettype == NET_SSH && ssh_sock != -1)
  9273.               success = keepalive(ssh_sock,z);
  9274.             else
  9275. #endif /* SSHBUILTIN */
  9276.           success = keepalive(ttyfd,z);
  9277.             return(success);
  9278. #endif /* SO_KEEPALIVE */
  9279. #ifdef SO_DONTROUTE
  9280.           case XYTCP_DONTROUTE:
  9281.             if ((z = cmkey(onoff,2,"","off",xxstring)) < 0) return(z);
  9282.             if ((y = cmcfm()) < 0) return(y);
  9283. #ifdef IKSDCONF
  9284.             if (iksdcf) return(success = 0);
  9285. #endif /* IKSDCONF */
  9286. #ifdef SSHBUILTIN
  9287.             if (network && nettype == NET_SSH && ssh_sock != -1)
  9288.               success = dontroute(ssh_sock,z);
  9289.             else
  9290. #endif /* SSHBUILTIN */
  9291.           success = dontroute(ttyfd,z);
  9292.             return(success);
  9293. #endif /* SO_DONTROUTE */
  9294. #ifdef TCP_NODELAY
  9295.           case XYTCP_NODELAY:
  9296.             if ((z = cmkey(onoff,2,"","off",xxstring)) < 0) return(z);
  9297.             if ((y = cmcfm()) < 0) return(y);
  9298. #ifdef IKSDCONF
  9299.             if (iksdcf) return(success = 0);
  9300. #endif /* IKSDCONF */
  9301. #ifdef SSHBUILTIN
  9302.             if (network && nettype == NET_SSH && ssh_sock != -1)
  9303.               success = no_delay(ssh_sock,z);
  9304.             else
  9305. #endif /* SSHBUILTIN */
  9306.           success = no_delay(ttyfd,z);
  9307.             return(success);
  9308.           case XYTCP_NAGLE:             /* The inverse of NODELAY */
  9309.             if ((z = cmkey(onoff,2,"","on",xxstring)) < 0) return(z);
  9310.             if ((y = cmcfm()) < 0) return(y);
  9311. #ifdef IKSDCONF
  9312.             if (iksdcf) return(success = 0);
  9313. #endif /* IKSDCONF */
  9314. #ifdef SSHBUILTIN
  9315.             if (network && nettype == NET_SSH && ssh_sock != -1)
  9316.               success = no_delay(ssh_sock,z);
  9317.             else
  9318. #endif /* SSHBUILTIN */
  9319.           success = no_delay(ttyfd,!z);
  9320.             return(success);
  9321. #endif /* TCP_NODELAY */
  9322. #ifdef SO_LINGER
  9323.           case XYTCP_LINGER:
  9324.             if ((z = cmkey(onoff,2,"","on",xxstring)) < 0)
  9325.               return(z);
  9326.             if (z) {                    /* if on, we need a timeout value */
  9327.                 if ((x = cmnum("Linger timeout in 10th of a millisecond",
  9328.                                "0",10,&y,xxstring)) < 0)
  9329.                   return(x);
  9330.             } else
  9331.               y = 0;
  9332.             if ((x = cmcfm()) < 0)
  9333.               return(x);
  9334. #ifdef IKSDCONF
  9335.             if (iksdcf) return(success = 0);
  9336. #endif /* IKSDCONF */
  9337. #ifdef SSHBUILTIN
  9338.             if (network && nettype == NET_SSH && ssh_sock != -1)
  9339.               success = ck_linger(ssh_sock,z,y);
  9340.             else
  9341. #endif /* SSHBUILTIN */
  9342.           success = ck_linger(ttyfd,z,y);
  9343.             return(success);
  9344. #endif /* SO_LINGER */
  9345. #ifdef SO_SNDBUF
  9346.           case XYTCP_SENDBUF:
  9347.             x = cmnum("Send buffer size, bytes","8192",10,&z,xxstring);
  9348.             if (x < 0) return(x);
  9349.             if ((x = cmcfm()) < 0) return(x);
  9350. #ifdef IKSDCONF
  9351.             if (iksdcf) return(success = 0);
  9352. #endif /* IKSDCONF */
  9353. #ifdef SSHBUILTIN
  9354.             if (network && nettype == NET_SSH && ssh_sock != -1)
  9355.               success = sendbuf(ssh_sock,z);
  9356.             else
  9357. #endif /* SSHBUILTIN */
  9358.           success = sendbuf(ttyfd,z);
  9359.             return(success);
  9360. #endif /* SO_SNDBUF */
  9361. #ifdef SO_RCVBUF
  9362.           case XYTCP_RECVBUF:
  9363.             x = cmnum("Receive buffer size, bytes","8192",10,&z,xxstring);
  9364.             if (x < 0) return(x);
  9365.             if ((x = cmcfm()) < 0) return(x);
  9366. #ifdef IKSDCONF
  9367.             if (iksdcf) return(success = 0);
  9368. #endif /* IKSDCONF */
  9369.  
  9370. /* Note: The following is not 16-bit safe */
  9371.  
  9372. #ifndef QNX16
  9373.             if (x > 52248) {
  9374.                 printf("?Warning: receive buffers larger than 52248 bytes\n");
  9375.                 printf(" may not be understood by all hosts.  Performance\n");
  9376.                 printf(" may suffer.\n");
  9377.                 return(-9);
  9378.             }
  9379. #endif /* QNX16 */
  9380. #ifdef SSHBUILTIN
  9381.             if (network && nettype == NET_SSH && ssh_sock != -1)
  9382.               success = recvbuf(ssh_sock,z);
  9383.             else
  9384. #endif /* SSHBUILTIN */
  9385.           success = recvbuf(ttyfd,z);
  9386.             return(success);
  9387. #endif /* SO_RCVBUF */
  9388.  
  9389. #ifdef VMS
  9390. #ifdef DEC_TCPIP
  9391.           case XYTCP_UCX: {             /* UCX 2.0 port swabbing bug */
  9392.               extern int ucx_port_bug;
  9393.               return(success = seton(&ucx_port_bug));
  9394.           }
  9395. #endif /* DEC_TCPIP */
  9396. #endif /* VMS */
  9397.  
  9398.           case XYTCP_RDNS: {
  9399.               extern int tcp_rdns;
  9400.               return(success = setonaut(&tcp_rdns));
  9401.           }
  9402.  
  9403. #ifdef CK_DNS_SRV
  9404.           case XYTCP_DNS_SRV: {
  9405.               extern int tcp_dns_srv;
  9406.               return(success = seton(&tcp_dns_srv));
  9407.           }
  9408. #endif /* CK_DNS_SRV */
  9409.  
  9410.           default:
  9411.             return(0);
  9412.         }
  9413.       }
  9414. #endif /* TCPSOCKET */
  9415. #endif /* NOTCPOPTS */
  9416. #endif /* NETCONN */
  9417.     }
  9418.  
  9419.     switch (xx) {
  9420.  
  9421. #ifndef NOLOCAL
  9422. #ifdef NETCONN
  9423.       case XYHOST: {                    /* SET HOST */
  9424.           z = ttnproto;                 /* Save protocol in case of failure */
  9425. #ifdef DECNET
  9426.           if (nettype != NET_DEC)
  9427. #endif /* DECNET */
  9428.             ttnproto = NP_NONE;
  9429.           if ((y = setlin(XYHOST,1,0)) <= 0) { /* Sets success to 1 */
  9430.               debug(F101,"SET HOST fail mdmtyp","",mdmtyp);
  9431.               ttnproto = z;             /* Failed, restore protocol */
  9432.               success = 0;
  9433.           }
  9434.           didsetlin++;
  9435.           debug(F101,"SET HOST OK mdmtyp","",mdmtyp);
  9436.           debug(F101,"SET HOST reliable","",reliable);
  9437.           return(y);
  9438.       }
  9439. #endif /* NETCONN */
  9440.  
  9441.       case XYLINE:                      /* SET LINE (= SET PORT) */
  9442.         debug(F101,"setlin flow 1","",flow);
  9443.         x = setlin(xx,1,0);
  9444.         if (x > -1) didsetlin++;
  9445.         debug(F101,"SET LINE setlin","",x);
  9446.         debug(F101,"SET LINE flow","",flow);
  9447.         debug(F101,"SET LINE local","",local);
  9448.         debug(F101,"SET LINE reliable","",reliable);
  9449.         return(x);
  9450. #endif /* NOLOCAL */
  9451.  
  9452. #ifndef NOSETKEY
  9453.       case XYKEY:                       /* SET KEY */
  9454.         return(dosetkey());
  9455. #endif /* NOSETKEY */
  9456.  
  9457. #ifndef NOCSETS
  9458.       case XYLANG:                      /* Language */
  9459.         if ((y = cmkey(lngtab,nlng,"","none",xxstring)) < 0)
  9460.           return(y);
  9461.         if ((x = cmcfm()) < 0) return(x);
  9462.  
  9463.         /* Look up language and get associated character sets */
  9464.         for (i = 0; (i < nlangs) && (langs[i].id != y); i++) ;
  9465.         if (i >= nlangs) {
  9466.             printf("?internal error, sorry\n");
  9467.             return(success = 0);
  9468.         } /*  */
  9469.         language = i;                   /* All good, set the language, */
  9470.         return(success = 1);
  9471. #endif /* NOCSETS */
  9472.  
  9473. #ifndef MAC
  9474.       case XYBACK:                      /* BACKGROUND */
  9475.         if ((z = cmkey(onoff,2,"","",xxstring)) < 0) return(z);
  9476.         if ((y = cmcfm()) < 0) return(y);
  9477. #ifdef COMMENT
  9478.         bgset = z;                      /* 0 = off (foreground) */
  9479. #ifdef VMS                              /* 1 = on (background) */
  9480.         if (batch && bgset == 0)        /* To enable echoing of commands */
  9481.           ckxech = 1;                   /* in VMS batch logs */
  9482. #endif /* VMS */
  9483. #else  /* COMMENT */
  9484.         if (z) {                        /* 1 = Background */
  9485.             bgset = 1;
  9486.             backgrd = 1;
  9487. #ifdef VMS
  9488.             batch = 1;
  9489. #endif /* VMS */
  9490.         } else {                        /* 0 = Foreground */
  9491.             bgset = 0;
  9492.             backgrd = 0;
  9493. #ifdef VMS
  9494.             batch = 0;
  9495. #endif /* VMS */
  9496.         }
  9497. #endif /* COMMENT */
  9498.         success = 1;
  9499.         bgchk();
  9500.         return(success);
  9501. #endif /* MAC */
  9502.  
  9503.       case XYQUIE: {                    /* QUIET */
  9504. #ifdef DCMDBUF
  9505.           extern int * xquiet;
  9506. #else
  9507.           extern int xquiet[];
  9508. #endif /* DCMDBUF */
  9509.           x = seton(&quiet);
  9510.           if (x < 0) return(x);
  9511.           xquiet[cmdlvl] = quiet;
  9512.           return(success = x);
  9513.       }
  9514.  
  9515. #ifndef NOXFER
  9516.       case XYBUF: {                     /* BUFFERS */
  9517. #ifdef DYNAMIC
  9518.           int sb, rb;
  9519.           if ((y = cmnum("Send buffer size","",10,&sb,xxstring)) < 0) {
  9520.               if (y == -3) printf("?Buffer size required\n");
  9521.               return(y);
  9522.           }
  9523.           if (sb < 0) {
  9524.               if (*atmbuf == '-')
  9525.                 printf("?Negative numbers can't be used here\n");
  9526.               else printf("?Integer overflow, use a smaller number please\n");
  9527.               return(-9);
  9528.           } else if (sb < 80) {
  9529.               printf("?Too small\n");
  9530.               return(-9);
  9531.           }
  9532.           if ((y=cmnum("Receive buffer size",ckitoa(sb),10,&rb,xxstring)) < 0)
  9533.             return(y);
  9534.           if (rb < 0) {
  9535.               if (*atmbuf == '-')
  9536.                 printf("?Negative numbers can't be used here\n");
  9537.               else printf("?Integer overflow, use a smaller number please\n");
  9538.               return(-9);
  9539.           } else if (rb < 80) {
  9540.               printf("?Too small\n");
  9541.               return(-9);
  9542.           }
  9543.           if ((y = cmcfm()) < 0) return(y);
  9544.           if ((y = inibufs(sb,rb)) < 0) return(y);
  9545.           y = adjpkl(urpsiz,wslotr,bigrbsiz); /* Maybe adjust packet sizes */
  9546.           if (y != urpsiz) urpsiz = y;
  9547.           y = adjpkl(spsiz,wslotr,bigsbsiz);
  9548.           if (y != spsiz) spsiz = spmax = spsizr = y;
  9549.           return(success = 1);
  9550. #else
  9551.           printf("?Sorry, not available\n");
  9552.           return(success = 0);
  9553. #endif /* DYNAMIC */
  9554.       }
  9555.  
  9556.       case XYCHKT:                      /* BLOCK-CHECK */
  9557.         if ((x = cmkey(chktab,4,"","3",xxstring)) < 0) return(x);
  9558.         if ((y = cmcfm()) < 0) return(y);
  9559.         bctr = x;                       /* Set local too even if REMOTE SET */
  9560.         if (rmsflg) {
  9561.             if (x == 4) {
  9562.                 tmpbuf[0] = 'B';
  9563.                 tmpbuf[1] = '\0';
  9564.             } else
  9565.               ckstrncpy(tmpbuf,ckitoa(x),TMPBUFSIZ);
  9566.             sstate = setgen('S', "400", tmpbuf, "");
  9567.             return((int) sstate);
  9568.         } else {
  9569.             return(success = 1);
  9570.         }
  9571. #endif /* NOXFER */
  9572.  
  9573. #ifndef NOLOCAL
  9574. #ifndef MAC                             /* The Mac has no RS-232 */
  9575. case XYCARR:                            /* CARRIER-WATCH */
  9576.         return(setdcd());
  9577. #endif /* MAC */
  9578. #endif /* NOLOCAL */
  9579.     }
  9580.  
  9581. #ifdef TNCODE
  9582.     switch (xx) {                       /* Avoid long switch statements... */
  9583.       case XYTELOP: {
  9584.           int c, n;                     /* Workers */
  9585.           int getval = 0;               /* Whether to get switch value */
  9586.           int tnserver = 0;             /* Client by default */
  9587.           int opt = -1;                 /* Telnet Option */
  9588.           struct FDB sw, op;            /* FDBs for each parse function */
  9589. #ifdef CK_AUTHENTICATION
  9590.           extern int sl_topt_a_s_saved;
  9591.           extern int sl_topt_a_c_saved;
  9592.           extern int sl_topt_e_s_saved;
  9593.           extern int sl_topt_e_c_saved;
  9594. #endif /* CK_AUTHENTICATION */
  9595. #ifdef IKSD
  9596.           if (inserver)                 /* Server by default when IKSD */
  9597.             tnserver = 1;
  9598. #endif /* IKSD */
  9599.  
  9600.           /* Set up chained parse functions... */
  9601.  
  9602.           cmfdbi(&op,                   /* First fdb - telopts*/
  9603.                  _CMKEY,                /* fcode */
  9604.                  "/client, /server or", /* hlpmsg */
  9605.                  "",                    /* default */
  9606.                  "",                    /* addtl string data */
  9607.                  ntnopt,                /* addtl numeric data 1 */
  9608.                  0,                     /* addtl numeric data 2 */
  9609.                  xxstring,
  9610.                  tnopttab,
  9611.                  &sw
  9612.                  );
  9613.           cmfdbi(&sw,                   /* Second FDB - command switches */
  9614.                  _CMKEY,                /* fcode */
  9615.                  "",                    /* hlpmsg */
  9616.                  "",                    /* default */
  9617.                  "",                    /* addtl string data */
  9618.                  ntnoptsw,              /* addtl numeric data 1: tbl size */
  9619.                  4,                     /* addtl numeric data 2: 4 = cmswi */
  9620.                  xxstring,              /* Processing function */
  9621.                  tnoptsw,               /* Keyword table */
  9622.                  NULL                   /* Pointer to next FDB */
  9623.                  );
  9624.  
  9625.           while (opt < 0) {             /* Parse 0 or more switches */
  9626.               x = cmfdb(&op);           /* Parse switch or other thing */
  9627.               debug(F101,"XYTELOP cmfdb","",x);
  9628.               if (x < 0)                /* Error */
  9629.                 return(x);              /* or reparse needed */
  9630.               if (cmresult.fcode != _CMKEY) /* Break out if not a switch */
  9631.                 break;
  9632.               c = cmgbrk();             /* Get break character */
  9633.               getval = (c == ':' || c == '='); /* see how switch ended */
  9634.               if (getval && !(cmresult.kflags & CM_ARG)) {
  9635.                   printf("?This switch does not take arguments\n");
  9636.                   return(-9);
  9637.               }
  9638.               z = cmresult.nresult;     /* Numeric result = switch value */
  9639.               debug(F101,"XYTELOP switch","",z);
  9640.  
  9641.               switch (z) {              /* Process the switch */
  9642.                 case CK_TN_CLIENT:
  9643.                   tnserver = 0;
  9644.                   break;
  9645.                 case CK_TN_SERVER:
  9646.                   tnserver = 1;
  9647.                     break;
  9648.                 case CK_TN_EC:
  9649.                   opt = TELOPT_ECHO;
  9650.                   break;
  9651.                 case CK_TN_TT:
  9652.                   opt = TELOPT_TTYPE;
  9653.                   break;
  9654.                 case CK_TN_BM:
  9655.                   opt = TELOPT_BINARY;
  9656.                   break;
  9657.                 case CK_TN_ENV:
  9658.                   opt = TELOPT_NEWENVIRON;
  9659.                   break;
  9660.                 case CK_TN_LOC:
  9661.                   opt = TELOPT_SNDLOC;
  9662.                   break;
  9663.                 case CK_TN_AU:
  9664.                   opt = TELOPT_AUTHENTICATION;
  9665.                   break;
  9666.                 case CK_TN_FX:
  9667.                   opt = TELOPT_FORWARD_X;
  9668.                   break;
  9669.                 case CK_TN_ENC:
  9670.                   opt = TELOPT_ENCRYPTION;
  9671.                   break;
  9672.                 case CK_TN_IKS:
  9673.                   opt = TELOPT_KERMIT;
  9674.                   break;
  9675.                 case CK_TN_TLS:
  9676.                   opt = TELOPT_START_TLS;
  9677.                   break;
  9678.                 case CK_TN_XD:
  9679.                   opt = TELOPT_XDISPLOC;
  9680.                   break;
  9681.                 case CK_TN_NAWS:
  9682.                   opt = TELOPT_NAWS;
  9683.                   break;
  9684.                 case CK_TN_SGA:
  9685.                   opt = TELOPT_SGA;
  9686.                   break;
  9687.                 case CK_TN_PHR:
  9688.                   opt = TELOPT_PRAGMA_HEARTBEAT;
  9689.                   break;
  9690.                 case CK_TN_PSP:
  9691.                   opt = TELOPT_SSPI_LOGON;
  9692.                   break;
  9693.                 case CK_TN_PLG:
  9694.                   opt = TELOPT_PRAGMA_LOGON;
  9695.                   break;
  9696.                 case CK_TN_SAK:
  9697.                   opt = TELOPT_IBM_SAK;
  9698.                   break;
  9699.                 case CK_TN_CPC:
  9700.                   opt = TELOPT_COMPORT;
  9701.                   break;
  9702.                 case CK_TN_LOG:
  9703.                   opt = TELOPT_LOGOUT;
  9704.                   break;
  9705.                 case CK_TN_FLW:
  9706.                   opt = TELOPT_LFLOW;
  9707.                   break;
  9708.                 default:
  9709.                   printf("?Unexpected value - %d\n",z);
  9710.                   return(-9);
  9711.               }
  9712. #ifdef COMMENT
  9713.               if (cmresult.fdbaddr == &op)
  9714.                 break;
  9715. #endif /* COMMENT */
  9716.           }
  9717.           switch (opt) {
  9718.             case TELOPT_ECHO:           /* Options only the Server WILL */
  9719.             case TELOPT_FORWARD_X:
  9720.             case TELOPT_SEND_URL:
  9721.             case TELOPT_IBM_SAK:
  9722.             case TELOPT_LOGOUT:
  9723.               if ((x = cmkey(tnnegtab,
  9724.                              ntnnegtab,
  9725.                              "desired server state",
  9726.    TELOPT_MODE(tnserver?TELOPT_DEF_S_ME_MODE(opt):TELOPT_DEF_C_U_MODE(opt)),
  9727.                              xxstring)
  9728.                    ) < 0)
  9729.                 return(x);
  9730.               if ((z = cmcfm()) < 0)
  9731.                   return(z);
  9732.               if (tnserver) {
  9733.                   TELOPT_DEF_S_ME_MODE(opt) = x;
  9734.                   TELOPT_ME_MODE(opt) = x;
  9735.               } else {
  9736.                   TELOPT_DEF_C_U_MODE(opt) = x;
  9737.                   TELOPT_U_MODE(opt) = x;
  9738.               }
  9739.               break;
  9740.  
  9741.             case TELOPT_TTYPE:          /* Options only the Client WILL */
  9742.             case TELOPT_NEWENVIRON:
  9743.             case TELOPT_SNDLOC:
  9744.             case TELOPT_AUTHENTICATION:
  9745.             case TELOPT_START_TLS:
  9746.             case TELOPT_XDISPLOC:
  9747.             case TELOPT_NAWS:
  9748.             case TELOPT_LFLOW:
  9749.             case TELOPT_COMPORT:
  9750.               if ((x = cmkey(tnnegtab,
  9751.                              ntnnegtab,
  9752.                              "desired client state",
  9753.     TELOPT_MODE(!tnserver?TELOPT_DEF_S_U_MODE(opt):TELOPT_DEF_C_ME_MODE(opt)),
  9754.                              xxstring)
  9755.                    ) < 0)
  9756.                 return(x);
  9757.               if ((z = cmcfm()) < 0)
  9758.                 return(z);
  9759.               if (tnserver) {
  9760.                   TELOPT_DEF_S_U_MODE(opt) = x;
  9761.                   TELOPT_U_MODE(opt) = x;
  9762. #ifdef CK_AUTHENTICATION
  9763.                   if (opt == TELOPT_AUTHENTICATION)
  9764.                     sl_topt_a_s_saved = 0;
  9765. #endif /* CK_AUTHENTICATION */
  9766.               } else {
  9767.                   TELOPT_DEF_C_ME_MODE(opt) = x;
  9768.                   TELOPT_ME_MODE(opt) = x;
  9769. #ifdef CK_AUTHENTICATION
  9770.                   if (opt == TELOPT_AUTHENTICATION)
  9771.                     sl_topt_a_c_saved = 0;
  9772. #endif /* CK_AUTHENTICATION */
  9773.               }
  9774.               break;
  9775.  
  9776.             default:
  9777.               if ((x = cmkey(tnnegtab,
  9778.                              ntnnegtab,
  9779.                              tnserver ?
  9780.                              "desired server state" :
  9781.                              "desired client state",
  9782.     TELOPT_MODE(tnserver?TELOPT_DEF_S_ME_MODE(opt):TELOPT_DEF_C_ME_MODE(opt)),
  9783.                              xxstring
  9784.                              )
  9785.                    ) < 0)
  9786.                 return(x);
  9787.               if ((y = cmkey(tnnegtab,
  9788.                              ntnnegtab,
  9789.                              !tnserver ? "desired server state" :
  9790.                              "desired client state",
  9791.     TELOPT_MODE(!tnserver?TELOPT_DEF_S_U_MODE(opt):TELOPT_DEF_C_U_MODE(opt)),
  9792.                              xxstring
  9793.                              )
  9794.                    ) < 0)
  9795.                 return(y);
  9796.               if ((z = cmcfm()) < 0)
  9797.                 return(z);
  9798.               if (tnserver) {
  9799.                   TELOPT_DEF_S_ME_MODE(opt) = x;
  9800.                   TELOPT_ME_MODE(opt) = x;
  9801.                   TELOPT_DEF_S_U_MODE(opt) = y;
  9802.                   TELOPT_U_MODE(opt) = y;
  9803. #ifdef CK_ENCRYPTION
  9804.                   if (opt == TELOPT_ENCRYPTION)
  9805.                     sl_topt_e_s_saved = 0;
  9806. #endif /* CK_ENCRYPTION */
  9807.               } else {
  9808.                   TELOPT_DEF_C_ME_MODE(opt) = x;
  9809.                   TELOPT_ME_MODE(opt) = x;
  9810.                   TELOPT_DEF_C_U_MODE(opt) = y;
  9811.                   TELOPT_U_MODE(opt) = y;
  9812. #ifdef CK_ENCRYPTION
  9813.                   if (opt == TELOPT_ENCRYPTION)
  9814.                     sl_topt_e_c_saved = 0;
  9815. #endif /* CK_ENCRYPTION */
  9816.               }
  9817.           }
  9818.           return(success = 1);
  9819.       }
  9820.  
  9821.       case XYTEL:                       /* TELNET */
  9822.         if ((z = cmkey(tntab,ntn,"parameter for TELNET negotiations", "",
  9823.                        xxstring)) < 0)
  9824.           return(z);
  9825.         switch (z) {
  9826.           case CK_TN_EC:                /* ECHO */
  9827.             if ((x = cmkey(rltab,nrlt,
  9828.                            "initial TELNET echoing state",
  9829.                            "local",xxstring)) < 0)
  9830.               return(x);
  9831.             if ((y = cmcfm()) < 0) return(y);
  9832.             tn_duplex = x;
  9833.             return(success = 1);
  9834.  
  9835.           case CK_TN_RE:                /* REMOTE-ECHO */
  9836.             return(success = seton(&tn_rem_echo));
  9837.  
  9838.           case CK_TN_DB:                /* DEBUG */
  9839.             return(success = seton(&tn_deb));
  9840.  
  9841.           case CK_TN_TT:                /* TERMINAL TYPE */
  9842.             if ((y = cmtxt("terminal type for TELNET connections","",
  9843.                            &s,xxstring)) < 0)
  9844.               return(y);
  9845.             if (tn_term) {
  9846.                 free(tn_term);          /* Free any previous storage */
  9847.                 tn_term = NULL;
  9848.             }
  9849.             if (s == NULL || *s == NUL) { /* If none given */
  9850.                 tn_term = NULL;         /* remove the override string */
  9851.                 return(success = 1);
  9852.             } else if ((tn_term = malloc(strlen(s)+1))) {
  9853.                 strcpy(tn_term,s);
  9854.                 return(success = 1);
  9855.             } else return(success = 0);
  9856.  
  9857. #ifdef CK_FORWARD_X
  9858.           case CK_TN_FX:                /* FORWARD-X */
  9859.             if ((x=cmkey(tnfwdxtab,ntnfwdx,"","xauthority-file",xxstring)) < 0)
  9860.               return(x);
  9861.             switch (x) {
  9862.               case 0: {                 /* Xauthority-File */
  9863.                   x = cmifi("Full path of .Xauthority file","",&s,&y,xxstring);
  9864.                   if (x < 0 && x != -3)
  9865.                     return(x);
  9866.                   makestr(&tn_fwdx_xauthority,s);
  9867.                   return(success = 1);
  9868.               }
  9869.               case 1: {                 /* No-Encryption */
  9870.                   extern int fwdx_no_encrypt;
  9871.                   return(success = seton(&fwdx_no_encrypt));
  9872.               }
  9873.             }
  9874.             return(success = 0);
  9875. #endif /* CK_FORWARD_X */
  9876.  
  9877.           case CK_TN_NL:                /* TELNET NEWLINE-MODE */
  9878.             if ((x = cmkey(tn_nlmtab,ntn_nlm,"","nvt",xxstring)) < 0)
  9879.               return(x);
  9880.             if (x == TN_NL_BIN) {
  9881.               if ((x = cmkey(tnlmtab,ntnlm,"","raw",xxstring)) < 0)
  9882.                 return(x);
  9883.               if ((y = cmcfm()) < 0)
  9884.                 return(y);
  9885.               tn_b_nlm = x;
  9886.               return(success = 1);
  9887.           } else if (x == TN_NL_NVT) {
  9888.               if ((x = cmkey(tnlmtab,ntnlm,"","on",xxstring)) < 0)
  9889.                 return(x);
  9890.               if ((y = cmcfm()) < 0)
  9891.                 return(y);
  9892.               tn_nlm = x;
  9893.               return(success = 1);
  9894.           } else {
  9895.               if ((y = cmcfm()) < 0)
  9896.                 return(y);
  9897.               tn_nlm = x;
  9898.               return(success = 1);
  9899.           }
  9900.  
  9901.         case CK_TN_XF:                  /* BINARY-TRANSFER-MODE */
  9902.             if ((z = cmkey(onoff,2,"","on",xxstring)) < 0) return(z);
  9903.             if ((y = cmcfm()) < 0) return(y);
  9904.             tn_b_xfer = z;
  9905.             return(success = 1);
  9906.  
  9907.         case CK_TN_NE:                  /* NO-ENCRYPT-DURING-XFER */
  9908.             if ((z = cmkey(onoff,2,"","on",xxstring)) < 0) return(z);
  9909.             if ((y = cmcfm()) < 0) return(y);
  9910. #ifdef CK_APC
  9911.             /* Don't let this be set remotely */
  9912.             if (apcactive == APC_LOCAL ||
  9913.                 (apcactive == APC_REMOTE && !(apcstatus & APC_UNCH)))
  9914.               return(success = 0);
  9915. #endif /* CK_APC */
  9916.             tn_no_encrypt_xfer = z;
  9917.             return(success = 1);
  9918.  
  9919.           case CK_TN_BM:                /* BINARY-MODE */
  9920.             if ((x = cmkey(tnnegtab,ntnnegtab,"","refused",xxstring)) < 0)
  9921.               return(x);
  9922.             if ((y = cmcfm()) < 0)
  9923.               return(y);
  9924.             TELOPT_DEF_S_ME_MODE(TELOPT_BINARY) = x;
  9925.             TELOPT_DEF_S_U_MODE(TELOPT_BINARY) = x;
  9926.             TELOPT_DEF_C_ME_MODE(TELOPT_BINARY) = x;
  9927.             TELOPT_DEF_C_U_MODE(TELOPT_BINARY) = x;
  9928.             return(success = 1);
  9929.  
  9930. #ifdef IKS_OPTION
  9931.           case CK_TN_IKS:               /* KERMIT */
  9932.             if ((x = cmkey(tnnegtab,ntnnegtab,"DO","accept",xxstring)) < 0)
  9933.               return(x);
  9934.             if ((y = cmkey(tnnegtab,ntnnegtab,"WILL","accept",xxstring)) < 0)
  9935.               return(y);
  9936.             if ((z = cmcfm()) < 0)
  9937.               return(z);
  9938.             TELOPT_DEF_S_ME_MODE(TELOPT_KERMIT) = y;
  9939.             TELOPT_DEF_S_U_MODE(TELOPT_KERMIT) = x;
  9940.             TELOPT_DEF_C_ME_MODE(TELOPT_KERMIT) = y;
  9941.             TELOPT_DEF_C_U_MODE(TELOPT_KERMIT) = x;
  9942.             return(success = 1);
  9943. #endif /* IKS_OPTION */
  9944.  
  9945. #ifdef CK_SSL
  9946.           case CK_TN_TLS:               /* START_TLS */
  9947.             if ((x = cmkey(tnnegtab,ntnnegtab,"me","accept",xxstring)) < 0)
  9948.               return(x);
  9949.             if ((y = cmkey(tnnegtab,ntnnegtab,"u","accept",xxstring)) < 0)
  9950.               return(y);
  9951.             if ((z = cmcfm()) < 0)
  9952.               return(z);
  9953.             TELOPT_DEF_S_ME_MODE(TELOPT_START_TLS) = x;
  9954.             TELOPT_DEF_S_U_MODE(TELOPT_START_TLS) = y;
  9955.             TELOPT_DEF_C_ME_MODE(TELOPT_START_TLS) = x;
  9956.             TELOPT_DEF_C_U_MODE(TELOPT_START_TLS) = y;
  9957.             return(success = 1);
  9958. #endif /* CK_SSL */
  9959.  
  9960. #ifdef CK_NAWS
  9961.           case CK_TN_NAWS:              /* NAWS */
  9962.             if ((x = cmkey(tnnegtab,ntnnegtab,"me","accept",xxstring)) < 0)
  9963.               return(x);
  9964.             if ((y = cmkey(tnnegtab,ntnnegtab,"u","accept",xxstring)) < 0)
  9965.               return(y);
  9966.             if ((z = cmcfm()) < 0)
  9967.               return(z);
  9968.             TELOPT_DEF_S_ME_MODE(TELOPT_NAWS) = x;
  9969.             TELOPT_DEF_S_U_MODE(TELOPT_NAWS) = y;
  9970.             TELOPT_DEF_C_ME_MODE(TELOPT_NAWS) = x;
  9971.             TELOPT_DEF_C_U_MODE(TELOPT_NAWS) = y;
  9972.             return(success = 1);
  9973. #endif /* CK_NAWS */
  9974.  
  9975. #ifdef CK_AUTHENTICATION
  9976.           case CK_TN_AU:                /* AUTHENTICATION */
  9977.             if ((x = cmkey(tnauthtab,ntnauth,"","",xxstring)) < 0)
  9978.               return(x);
  9979.             if (x == TN_AU_FWD) {
  9980.                 extern int forward_flag;
  9981.                 return(success = seton(&forward_flag));
  9982.             } else if (x == TN_AU_TYP) {
  9983.                 extern int auth_type_user[];
  9984.                 extern int sl_auth_type_user[];
  9985.                 extern int sl_auth_saved;
  9986.                 int i, j, atypes[AUTHTYPLSTSZ];
  9987.  
  9988.                 for (i = 0; i < AUTHTYPLSTSZ; i++) {
  9989.                     if ((y = cmkey(autyptab,nautyp,"",
  9990.                                    i == 0 ? "automatic" : "" ,
  9991.                                    xxstring)) < 0) {
  9992.                         if (y == -3)
  9993.                           break;
  9994.                         return(y);
  9995.                     }
  9996.                     if (i > 0 && (y == AUTHTYPE_AUTO || y == AUTHTYPE_NULL)) {
  9997.                         printf(
  9998.                         "\r\n?Choice may only be used in first position.\r\n");
  9999.                         return(-9);
  10000.                     }
  10001.                     for (j = 0; j < i; j++) {
  10002.                         if (atypes[j] == y) {
  10003.                             printf("\r\n?Choice has already been used.\r\n");
  10004.                             return(-9);
  10005.                         }
  10006.                     }
  10007.                     atypes[i] = y;
  10008.                     if (y == AUTHTYPE_NULL || y == AUTHTYPE_AUTO) {
  10009.                         i++;
  10010.                         break;
  10011.                     }
  10012.                 }
  10013.                 if (i < AUTHTYPLSTSZ)
  10014.                   atypes[i] = AUTHTYPE_NULL;
  10015.                 if ((z = cmcfm()) < 0)
  10016.                   return(z);
  10017.                 sl_auth_saved = 0;
  10018.                 for (i = 0; i < AUTHTYPLSTSZ; i++) {
  10019.                     auth_type_user[i] = atypes[i];
  10020.                     sl_auth_type_user[i] = 0;
  10021.                 }
  10022.             } else if (x == TN_AU_HOW) {
  10023.                 if ((y = cmkey(auhowtab,nauhow,"","any",xxstring)) < 0)
  10024.                   return(y);
  10025.                 if ((z = cmcfm()) < 0)
  10026.                   return(z);
  10027.                 tn_auth_how = y;
  10028.             } else if (x == TN_AU_ENC) {
  10029.                 if ((y = cmkey(auenctab,nauenc,"","encrypt",xxstring)) < 0)
  10030.                   return(y);
  10031.                 if ((z = cmcfm()) < 0)
  10032.                   return(z);
  10033.                 tn_auth_enc = y;
  10034.             } else {
  10035.                 if ((y = cmcfm()) < 0)
  10036.                   return(y);
  10037.                 TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = x;
  10038.                 TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = x;
  10039.             }
  10040.             return(success = 1);
  10041. #endif /* CK_AUTHENTICATION */
  10042.  
  10043. #ifdef CK_ENCRYPTION
  10044.           case CK_TN_ENC: {             /* ENCRYPTION */
  10045.               int c, tmp = -1;
  10046.               int getval = 0;
  10047.               static struct keytab * tnetbl = NULL;
  10048.               static int ntnetbl = 0;
  10049.  
  10050.               if ((y = cmkey(tnenctab,ntnenc,"","",xxstring)) < 0)
  10051.                 return(y);
  10052.               switch (y) {
  10053.                 case TN_EN_TYP:
  10054.                   x = ck_get_crypt_table(&tnetbl,&ntnetbl);
  10055.                   debug(F101,"ck_get_crypt_table x","",x);
  10056.                   debug(F101,"ck_get_crypt_table n","",ntnetbl);
  10057.                   if (x < 1 || !tnetbl || ntnetbl < 1) /* Didn't get it */
  10058.                     x = 0;
  10059.                   if (!x) {
  10060.                       printf("?Oops, types not loaded\n");
  10061.                       return(-9);
  10062.                   }
  10063.                   if ((x = cmkey(tnetbl,ntnetbl,"type of encryption",
  10064.                                  "automatic",xxstring)) < 0)
  10065.                     return(x);
  10066.                   if ((z = cmcfm()) < 0)
  10067.                     return(z);
  10068.                   cx_type = x;
  10069.                   sl_cx_type = 0;
  10070.                   break;
  10071.                 case TN_EN_START:
  10072.                   if ((z = cmcfm()) < 0)
  10073.                     return(z);
  10074. #ifdef CK_APC
  10075.                   /* Don't let this be set remotely */
  10076.                   if (apcactive == APC_LOCAL ||
  10077.                       apcactive == APC_REMOTE && !(apcstatus & APC_UNCH))
  10078.                     return(success = 0);
  10079. #endif /* CK_APC */
  10080.                   ck_tn_enc_start();
  10081.                   break;
  10082.                 case TN_EN_STOP:
  10083.                   if ((z = cmcfm()) < 0)
  10084.                     return(z);
  10085. #ifdef CK_APC
  10086.                   /* Don't let this be set remotely */
  10087.                   if (apcactive == APC_LOCAL ||
  10088.                       apcactive == APC_REMOTE && !(apcstatus & APC_UNCH))
  10089.                     return(success = 0);
  10090. #endif /* CK_APC */
  10091.                   ck_tn_enc_stop();
  10092.                   break;
  10093.                 default:
  10094.                   if ((z = cmcfm()) < 0)
  10095.                     return(z);
  10096.                   TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION) = y;
  10097.                   TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION) = y;
  10098.                   TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION) = y;
  10099.                   TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION) = y;
  10100.               }
  10101.               return(success = 1);
  10102.           }
  10103. #endif /* CK_ENCRYPTION */
  10104.  
  10105.           case CK_TN_BUG:               /* BUG */
  10106.             if ((x = cmkey(tnbugtab,4,"",
  10107.                            "binary-me-means-u-too",xxstring)) < 0)
  10108.               return(x);
  10109.             if ((z = cmkey(onoff,2,"","off",xxstring)) < 0) return(z);
  10110.             if ((y = cmcfm()) < 0) return(y);
  10111.             switch (x) {
  10112.               case 0:
  10113.                 tn_b_meu = z;
  10114.                 break;
  10115.               case 1:
  10116.                 tn_b_ume = z;
  10117.                 break;
  10118.               case 2:
  10119.                 tn_infinite = z;
  10120.                 break;
  10121.               case 3:
  10122.                 tn_sb_bug = z;
  10123.                 break;
  10124.               case 4:
  10125.                 tn_auth_krb5_des_bug = z;
  10126.                 break;
  10127.             }
  10128.             return(success = 1);
  10129.  
  10130. #ifdef CK_ENVIRONMENT
  10131.           case CK_TN_XD:                /* XDISPLOC */
  10132.             if ((x = cmkey(tnnegtab,ntnnegtab,"me","accept",xxstring)) < 0)
  10133.               return(x);
  10134.             if ((y = cmkey(tnnegtab,ntnnegtab,"u","accept",xxstring)) < 0)
  10135.               return(y);
  10136.             if ((z = cmcfm()) < 0)
  10137.               return(z);
  10138.             TELOPT_DEF_S_ME_MODE(TELOPT_XDISPLOC) = x;
  10139.             TELOPT_DEF_S_U_MODE(TELOPT_XDISPLOC) = y;
  10140.             TELOPT_DEF_C_ME_MODE(TELOPT_XDISPLOC) = x;
  10141.             TELOPT_DEF_C_U_MODE(TELOPT_XDISPLOC) = y;
  10142.             return(success = 1);
  10143.  
  10144.           case CK_TN_ENV: {
  10145.               char * msg = "value of telnet environment variable";
  10146.               extern int tn_env_flg;
  10147.               extern char tn_env_acct[], tn_env_disp[], tn_env_job[],
  10148.               tn_env_prnt[], tn_env_sys[];
  10149.               extern char * tn_loc;
  10150.               if ((x = cmkey(tnenvtab,ntnenv,"","",xxstring)) < 0)
  10151.                 return(x);
  10152.               if (x == TN_ENV_UVAR) {   /* User variables */
  10153.                   char * uvar=NULL;
  10154.                   char * uval=NULL;
  10155.                   char * env;
  10156.                   extern char * tn_env_uservar[8][2];
  10157.  
  10158.                   /* Get the user variable name */
  10159.                   if ((x = cmfld("Name of Environment Variable","",&s,
  10160.                                  xxstring)) < 0)
  10161.                     return(x);
  10162.                   makestr(&uvar,s);
  10163.  
  10164.                   env = getenv(uvar);
  10165.                   if (!env) env = "";
  10166.  
  10167.                   if ((x = cmtxt("Value of Environment Variable",env,
  10168.                                  &s,xxstring)) < 0)
  10169.                     return(x);
  10170.                   if (*s)
  10171.                     makestr(&uval,s);
  10172.  
  10173.                   /* Now that we have the variable and perhaps a value */
  10174.                   /* there are three possibilities: (1) new variable   */
  10175.                   /* and associated value; (2) variable already exists */
  10176.                   /* but we have a new value; (3) variable already     */
  10177.                   /* exists but no new value therefore the user wants  */
  10178.                   /* to clear variable.                                */
  10179.  
  10180.                   /* Try to find an existing variable */
  10181.                   for (x = 0; x < 8; x++) {
  10182.                       if (!ckstrcmp(tn_env_uservar[x][0],uvar,-1,0)) {
  10183.                           if (uval) {
  10184.                               free(tn_env_uservar[x][1]);
  10185.                               tn_env_uservar[x][1] = uval;
  10186.                               free(uvar);
  10187.                               return(success = 1);
  10188.                           } else {
  10189.                               free(tn_env_uservar[x][0]);
  10190.                               tn_env_uservar[x][0] = NULL;
  10191.                               free(tn_env_uservar[x][1]);
  10192.                               tn_env_uservar[x][1] = NULL;
  10193.                               free(uvar);
  10194.                               return(success = 1);
  10195.                           }
  10196.                       }
  10197.                   }
  10198.  
  10199.                   /* Couldn't find one; look for empty location to insert */
  10200.                   for (x = 0; x < 8; x++) {
  10201.                       if (!tn_env_uservar[x][0]) {
  10202.                           tn_env_uservar[x][0] = uvar;
  10203.                           tn_env_uservar[x][1] = uval;
  10204.                           return(success = 1);
  10205.                       }
  10206.                   }
  10207.                   printf("?Sorry, no space for variable.\n");
  10208.                   return(success = 0);
  10209.               }
  10210.               if (x == TN_ENV_OFF || x == TN_ENV_ON) {
  10211.                   if ((y = cmcfm()) < 0) return(y);
  10212. #ifdef IKSD
  10213.                   if (inserver) {
  10214.                       printf("?Sorry, command disabled.\r\n");
  10215.                       return(success = 0);
  10216.                   }
  10217. #endif /* IKSD */
  10218.                   tn_env_flg = x == TN_ENV_OFF ? 0 : 1;
  10219.                   return(success = 1);
  10220.               }
  10221.  
  10222.               /* Not ON/OFF - Get the value */
  10223.               z = cmdgquo();
  10224.               cmdsquo(0);
  10225.               if ((y = cmtxt(msg, "", &s, xxstring)) < 0) {
  10226.                   cmdsquo(z);
  10227.                   return(y);
  10228.               }
  10229.               cmdsquo(z);
  10230. #ifdef IKSD
  10231.               if (inserver)
  10232.                 return(success = 0);
  10233. #endif /* IKSD */
  10234.               if ((int)strlen(s) > 63) {
  10235.                   printf("Sorry, too long\n");
  10236.                   return(-9);
  10237.               }
  10238.               switch (x) {
  10239.                 case TN_ENV_USR:
  10240.                   ckstrncpy(uidbuf,s,UIDBUFLEN);
  10241.                   sl_uid_saved = 0;
  10242.                   break;
  10243.                 case TN_ENV_ACCT:
  10244.                   ckstrncpy(tn_env_acct,s,64);
  10245.                   break;
  10246.                 case TN_ENV_DISP:
  10247.                   ckstrncpy(tn_env_disp,s,64);
  10248.                   break;
  10249.                 case TN_ENV_JOB:
  10250.                   ckstrncpy(tn_env_job,s,64);
  10251.                   break;
  10252.                 case TN_ENV_PRNT:
  10253.                   ckstrncpy(tn_env_prnt,s,64);
  10254.                   break;
  10255.                 case TN_ENV_SYS:
  10256.                   ckstrncpy(tn_env_sys,s,64);
  10257.                   break;
  10258.                 case TN_ENV_LOC:
  10259.                   if (!*s) s = NULL;
  10260.                   makestr(&tn_loc,s);
  10261.                   break;
  10262.                 case TN_ENV_UVAR:
  10263.                   printf("\n?Not yet implemented\n");
  10264.                   break;
  10265.               }
  10266.               return(success = 1);
  10267.           }
  10268. #endif /* CK_ENVIRONMENT */
  10269.  
  10270. #ifdef CK_SNDLOC
  10271.           case CK_TN_LOC: {             /* LOCATION */
  10272.               extern char * tn_loc;
  10273.               if ((y = cmtxt("Location string","",&s,xxstring)) < 0)
  10274.                 return(y);
  10275.               if (!*s) s = NULL;
  10276.               makestr(&tn_loc,s);
  10277.               return(success = 1);
  10278.           }
  10279. #endif /* CK_SNDLOC */
  10280.           case CK_TN_SFU:               /* Microsoft SFU compatibility */
  10281.             if ((z = cmkey(onoff,2,"","on",xxstring)) < 0) return(z);
  10282.             if ((y = cmcfm()) < 0) return(y);
  10283.             tn_sfu = z;
  10284.             return(success = 1);
  10285.             break;
  10286.  
  10287.           case CK_TN_WAIT:              /* WAIT-FOR-NEGOTIATIONS */
  10288.             if ((z = cmkey(onoff,2,"","on",xxstring)) < 0) return(z);
  10289.             if ((y = cmcfm()) < 0) return(y);
  10290. #ifdef IKSD
  10291.             if (inserver &&
  10292. #ifdef IKSDCONF
  10293.                 iksdcf
  10294. #else
  10295.                 1
  10296. #endif /* IKSDCONF */
  10297.                 ) {
  10298.                 printf("?Sorry, command disabled.\r\n");
  10299.                 return(success = 0);
  10300.             }
  10301. #endif /* IKSD */
  10302.             tn_wait_flg = z;
  10303.             sl_tn_saved = 0;
  10304.             return(success = 1);
  10305.  
  10306.           case CK_TN_DL:                /* DELAY SUBNEGOTIATIONS */
  10307.             if ((z = cmkey(onoff,2,"","on",xxstring)) < 0) return(z);
  10308.             if ((y = cmcfm()) < 0) return(y);
  10309. #ifdef IKSD
  10310.             if (inserver &&
  10311. #ifdef IKSDCONF
  10312.                 iksdcf
  10313. #else
  10314.                 1
  10315. #endif /* IKSDCONF */
  10316.                 ) {
  10317.                 printf("?Sorry, command disabled.\r\n");
  10318.                 return(success = 0);
  10319.             }
  10320. #endif /* IKSD */
  10321.             tn_delay_sb = z;
  10322.             return(success = 1);
  10323.  
  10324.           case CK_TN_PUID: {            /* PROMPT-FOR-USERID */
  10325.               int i,len;
  10326.               if ((y = cmtxt("Prompt string","",&s,xxstring)) < 0)
  10327.                 return(y);
  10328.               if (s == "") s = NULL;
  10329.               if (s) {
  10330.                   s = brstrip(s);
  10331.                   if (s == "") s = NULL;
  10332.               }
  10333.               /* we must check to make sure there are no % fields */
  10334.               len = strlen(s);
  10335.               for (i = 0; i < len; i++) {
  10336.                   if (s[i] == '%') {
  10337.                       if (s[i+1] != '%') {
  10338.                           printf("%% fields are not used in this command.\n");
  10339.                           return(-9);
  10340.                       }
  10341.                       i++;
  10342.                   }
  10343.               }
  10344.               makestr(&tn_pr_uid,s);
  10345.               return(success = 1);
  10346.           }
  10347.           default:
  10348.             return(-2);
  10349.         }
  10350.     }
  10351. #endif /* TNCODE */
  10352.  
  10353.     switch (xx) {
  10354. #ifndef NOSPL
  10355.       case XYCOUN:                      /* SET COUNT */
  10356.         x = cmnum("Positive number","0",10,&z,xxstring);
  10357.         if (x < 0) return(x);
  10358.         if ((x = cmcfm()) < 0) return(x);
  10359.         if (z < 0) {
  10360.             printf("?A positive number, please\n");
  10361.             return(0);
  10362.         }
  10363.         debug(F101,"XYCOUN: z","",z);
  10364.         return(success = setnum(&count[cmdlvl],z,0,10000));
  10365. #endif /* NOSPL */
  10366.  
  10367. #ifndef NOSPL
  10368.       case XYCASE:
  10369.         return(success = seton(&inpcas[cmdlvl]));
  10370. #endif /* NOSPL */
  10371.  
  10372.       case XYCMD:                       /* COMMAND ... */
  10373.         if ((y = cmkey(scmdtab,nbytt,"","",xxstring)) < 0)
  10374.           return(y);
  10375.         switch (y) {
  10376.           case SCMD_CBR:
  10377.             if ((y = cmcfm()) < 0)
  10378.               return(y);
  10379.             concb((char)escape);
  10380.             return(success = 1);
  10381.  
  10382.           case SCMD_BSZ:
  10383.             if ((y = cmnum("bytesize for command characters, 7 or 8","7",10,&x,
  10384.                            xxstring)) < 0)
  10385.               return(y);
  10386.             if (x != 7 && x != 8) {
  10387.                 printf("\n?The choices are 7 and 8\n");
  10388.                 return(success = 0);
  10389.             }
  10390.             if ((y = cmcfm()) < 0) return(y);
  10391.             if (x == 7) cmdmsk = 0177;
  10392.             else if (x == 8) cmdmsk = 0377;
  10393.             return(success = 1);
  10394. #ifdef CK_RECALL
  10395.           case SCMD_RCL:
  10396.             if ((y = cmnum("maximum number of commands in recall buffer","10",
  10397.                            10,&x,xxstring)) < 0)
  10398.               return(y);
  10399.             if ((y = cmcfm()) < 0) return(y);
  10400.             return(success = cmrini(x));
  10401. #endif /* CK_RECALL */
  10402. #ifdef CK_RECALL
  10403.           case SCMD_RTR:
  10404.             return(success = seton(&cm_retry));
  10405. #endif /* CK_RECALL */
  10406.           case SCMD_MOR:                /* More-prompting */
  10407.             success = seton(&xaskmore);
  10408.             if (success)
  10409.               saveask = xaskmore;
  10410.             return(success);
  10411.           case SCMD_QUO:
  10412.             if ((x = seton(&y)) < 0) return(x);
  10413.             cmdsquo(y);                 /* Do it the right way */
  10414.             cmd_quoting = y;            /* Also keep a global copy */
  10415.             /* Set string-processing function */
  10416. #ifdef datageneral
  10417.             xxstring = y ? zzstring : (xx_strp) NULL;
  10418. #else
  10419. #ifdef CK_ANSIC
  10420.             xxstring = y ? zzstring : (xx_strp) NULL;
  10421. #else
  10422.             xxstring = y ? zzstring : (xx_strp) NULL;
  10423. #endif /* CK_ANSIC */
  10424. #endif /* datageneral */
  10425.             return(success = 1);
  10426.  
  10427. #ifdef OS2
  10428. #ifndef NOLOCAL
  10429.           case SCMD_COL: {              /* Command-screen colors */
  10430.               int fg, bg;
  10431.               fg = cmkey(ttyclrtab, nclrs,
  10432.                          "foreground color and then background color",
  10433.                          "white",
  10434.                          xxstring);
  10435.               if (fg < 0)
  10436.                 return(fg);
  10437.               if ((bg = cmkey(ttyclrtab,nclrs,
  10438.                               "background color","black",xxstring)) < 0)
  10439.                 return(bg);
  10440.               if ((y = cmcfm()) < 0)
  10441.                 return(y);
  10442.               colorcmd = fg | bg << 4;
  10443.               return(success = 1);
  10444.           }
  10445.           case SCMD_SCR:                /* Command Scrollback size */
  10446.             if ((y = cmnum("COMMAND scrollback buffer size, lines","512",10,&x,
  10447.                            xxstring)) < 0)
  10448.               return(y);
  10449.             /* The max number of lines is the RAM  */
  10450.             /* we can actually dedicate to a       */
  10451.             /* scrollback buffer given the maximum */
  10452.             /* process memory space of 512MB       */
  10453.             if (x < 256 || x > 2000000L) {
  10454.                 printf("\n?The size must be between 256 and 2,000,000.\n");
  10455.                 return(success = 0);
  10456.             }
  10457.             if ((y = cmcfm()) < 0) return(y);
  10458.             tt_scrsize[VCMD] = x;
  10459.             VscrnInit( VCMD );
  10460.             return(success = 1);
  10461.  
  10462.           case SCMD_WID: {
  10463.               if ((y = cmnum("Number of columns in display window",
  10464.                          "80",10,&x,xxstring)) < 0)
  10465.                 return(y);
  10466.               if ((y = cmcfm()) < 0) return(y);
  10467.  
  10468.               os2_setcmdwidth(x);
  10469.               return(success = 1);
  10470.           }
  10471.           case SCMD_HIG:
  10472.             if ((y = cmnum("Number of rows in display window",
  10473.                            "24",10,&x,xxstring)) < 0)
  10474.               return(y);
  10475.             if ((y = cmcfm()) < 0) return(y);
  10476.             os2_setcmdheight(x);
  10477.             return(success = 1);
  10478.  
  10479.           case SCMD_STA: {
  10480.               extern int marginbot;
  10481.               if ((y = cmkey(onoff,2,"","on",xxstring)) < 0) return(y);
  10482.               if ((x = cmcfm()) < 0) return(x);
  10483.               if (y != tt_status[VCMD]) {
  10484.                   /* Might need to fixup the margins */
  10485.                   tt_status[VCMD] = y;
  10486.                   if (y) {
  10487.                       tt_szchng[VCMD] = 2;
  10488.                       tt_rows[VCMD]--;
  10489.                       cmd_rows--;
  10490.                       VscrnInit(VCMD);  /* Height set here */
  10491.                       printf("\n");
  10492.                   } else {
  10493.                       tt_szchng[VCMD] = 1;
  10494.                       tt_rows[VCMD]++;
  10495.                       cmd_rows++;
  10496.                       VscrnInit(VCMD);  /* Height set here */
  10497.                   }
  10498.               }
  10499.               return(success = 1);
  10500.           }
  10501.  
  10502.           case SCMD_CUR: {
  10503.               int row, col;
  10504.               position * ppos;
  10505.  
  10506.               ppos = VscrnGetCurPos(VCMD);
  10507. #ifdef NT
  10508. #define itoa _itoa
  10509. #endif /* NT */
  10510.               itoa(ppos->y+1, tmpbuf, 10);
  10511.               if ((y = cmnum("row (1-based)",tmpbuf,10,&row,xxstring)) < 0)
  10512.                 return(y);
  10513.  
  10514.               itoa(ppos->x+1, tmpbuf, 10);
  10515.               if ((y = cmnum("col (1-based)",tmpbuf,10,&col,xxstring)) < 0)
  10516.                 return(y);
  10517.               if ((x = cmcfm()) < 0) return(x);
  10518.  
  10519.               lgotoxy( VCMD, col, row ) ;
  10520.               VscrnIsDirty( VCMD );
  10521.               return(success=1);
  10522.           }
  10523. #endif /* NOLOCAL */
  10524. #else
  10525.           case SCMD_WID:
  10526.             y = cmnum("Command screen width, characters","80",10,&x,xxstring);
  10527.             return(setnum(&cmd_cols,x,y,1024));
  10528.  
  10529.           case SCMD_HIG:
  10530.             y = cmnum("Command screen height, rows","24",10,&x,xxstring);
  10531.             return(setnum(&cmd_rows,x,y,1024));
  10532. #endif /* OS2 */
  10533.  
  10534.           case SCMD_INT:
  10535.             return(seton(&cmdint));
  10536.  
  10537. #ifdef CK_AUTODL
  10538.           case SCMD_ADL:
  10539.             return(seton(&cmdadl));
  10540. #endif /* CK_AUTODL */
  10541.  
  10542. #ifdef DOUBLEQUOTING
  10543.           case SCMD_DBQ: {
  10544.               extern int dblquo;
  10545.               return(seton(&dblquo));
  10546.           }
  10547. #endif /* DOUBLEQUOTING */
  10548.  
  10549.           default:
  10550.             return(-2);
  10551.         }
  10552.     }
  10553.  
  10554.     switch (xx) {
  10555.  
  10556.       case XYDFLT:                      /* SET DEFAULT = CD */
  10557.         return(success = docd(XXCWD));
  10558.  
  10559. case XYDEBU:                            /* SET DEBUG { on, off, session } */
  10560.         if ((y = cmkey(dbgtab,ndbg,"","",xxstring)) < 0)
  10561.           return(y);
  10562.         if (y == DEB_TIM)
  10563. #ifdef COMMENT
  10564.           return(seton(&debtim) < 0 ? x : (success = 1));
  10565. #else
  10566.           /* why this change? */
  10567.           return(success = seton(&debtim));
  10568. #endif /* COMMENT */
  10569.  
  10570. #ifdef IKSD
  10571.         if (inserver && isguest) {
  10572.             printf("?Sorry, command disabled.\r\n");
  10573.             return(success = 0);
  10574.     }
  10575. #endif /* IKSD */
  10576.  
  10577.         switch (y) {
  10578.           case DEB_LEN:
  10579.             y = cmnum("Max length for debug log strings","",10,&x,xxstring);
  10580.             if ((z = setnum(&debxlen,x,y,-1)) < 0)
  10581.               return(z);
  10582.             if ((x = cmcfm()) < 0)
  10583.               return(x);
  10584.             return(success = 1);
  10585.  
  10586.           case DEB_OFF:
  10587.             if ((x = cmcfm()) < 0)
  10588.               return(x);
  10589. #ifndef NOLOCAL
  10590.             setdebses(0);
  10591. #endif /* NOLOCAL */
  10592. #ifdef DEBUG
  10593.             if (deblog) doclslog(LOGD);
  10594. #endif /* DEBUG */
  10595.             return(success = 1);
  10596.  
  10597.           case DEB_ON:
  10598.             if ((x = cmcfm()) < 0)
  10599.               return(x);
  10600. #ifdef DEBUG
  10601.             deblog = debopn("debug.log", 0);
  10602.             return(success = deblog ? 1 : 0);
  10603. #else
  10604.             printf("?Sorry, debug log feature not enabled\n");
  10605.             return(success = 0);
  10606. #endif /* DEBUG */
  10607.           case DEB_SES:
  10608.             if ((x = cmcfm()) < 0)
  10609.               return(x);
  10610. #ifndef NOLOCAL
  10611.             setdebses(1);
  10612. #endif /* NOLOCAL */
  10613.             return(success = 1);
  10614.         }
  10615.         break;
  10616.  
  10617. #ifndef NOXFER
  10618.       case XYDELA:                      /* SET DELAY */
  10619.         y = cmnum("Number of seconds before starting to send",
  10620.                   "5",10,&x,xxstring);
  10621.         if (x < 0) x = 0;
  10622.         return(success = setnum(&ckdelay,x,y,999));
  10623. #endif /* NOXFER */
  10624.  
  10625.       default:
  10626.         break;
  10627.     }
  10628.  
  10629.     switch (xx) {
  10630. #ifdef CK_TAPI
  10631.       case XYTAPI:
  10632.         return(settapi());
  10633. #endif /* CK_TAPI */
  10634. #ifndef NODIAL
  10635.       case XYDIAL:                      /* SET MODEM or SET DIAL */
  10636.         return(setdial(-1));
  10637.       case XYMODM:
  10638.         return(setmodem());
  10639. #ifdef COMMENT
  10640.       /* not implemented yet */
  10641.       case XYANSWER:                    /* SET ANSWER */
  10642.         return(setanswer());
  10643. #endif /* COMMENT */
  10644. #endif /* NODIAL */
  10645.  
  10646. #ifndef NOLOCAL
  10647.       case XYDUPL:                      /* SET DUPLEX */
  10648.         if ((y = cmkey(dpxtab,2,"","full",xxstring)) < 0) return(y);
  10649.         if ((x = cmcfm()) < 0) return(x);
  10650.         duplex = y;
  10651.         return(success = 1);
  10652.  
  10653.       case XYLCLE:                      /* LOCAL-ECHO (= DUPLEX) */
  10654.         return(success = seton(&duplex));
  10655.  
  10656.       case XYESC:                       /* SET ESCAPE */
  10657.         return(success = setcc(ckitoa(DFESC),&escape));
  10658. #endif /* NOLOCAL */
  10659.  
  10660.       case XYEXIT:                      /* SET EXIT */
  10661.         if ((z = cmkey(xittab,nexit,"","",xxstring)) < 0)
  10662.           return(z);
  10663.         switch (z) {
  10664.           case 0:                       /* STATUS */
  10665.             y = cmnum("EXIT status code","",10,&x,xxstring);
  10666.             return(success = setnum(&xitsta,x,y,-1));
  10667.           case 1:                       /* WARNING */
  10668.             if ((z = cmkey(xitwtab,nexitw,"","",xxstring)) < 0)
  10669.               return(z);
  10670.             if ((y = cmcfm()) < 0) return(y);
  10671.             setexitwarn(z);
  10672.             return(success = 1);
  10673.           case 2:
  10674.             success = seton(&exitonclose);
  10675. #ifdef TCPSOCKET
  10676.             if (success) tn_exit = exitonclose;
  10677. #endif /* TCPSOCKET */
  10678.             return(success);
  10679.           case 3: {
  10680.               extern int exithangup;
  10681.               return((success = seton(&exithangup)));
  10682.           }
  10683.           default:
  10684.             return(-2);
  10685.         } /* End of SET EXIT switch() */
  10686.       default:
  10687.         break;
  10688.     }
  10689.  
  10690.     switch (xx) {
  10691.  
  10692.       case XYFILE:                      /* SET FILE */
  10693.         return(setfil(rmsflg));
  10694.  
  10695.       case XYFLOW: {                    /* FLOW-CONTROL */
  10696.           extern int cxflow[];
  10697.           struct FDB k1, k2;
  10698.           int tncomport = 0;
  10699.           char * m;
  10700.  
  10701. #ifdef TN_COMPORT
  10702.           if (network && istncomport())
  10703.             tncomport = 1;
  10704. #endif /* TN_COMPORT */
  10705.  
  10706.           if (tncomport) {
  10707.               m = "Flow control type, one of the following:\n\
  10708.    dtr/cd    dtr/cts   keep    none    rts/cts   xon/xoff\n\
  10709.  or connection type";
  10710.           } else {
  10711.           /* All this is because chained FDB's don't give chained help yet */
  10712.               m =
  10713. #ifdef Plan9
  10714. #ifdef CK_RTSCTS
  10715.            "Flow control type, one of the following:\n\
  10716.    keep   none    rts/cts\n\
  10717.  or connection type",
  10718. #else
  10719.            "Flow control type, one of the following:\n\
  10720.    keep   none\n\
  10721.  or connection type";
  10722. #endif /* CK_RTSCTS */
  10723. #else
  10724. #ifdef CK_RTSCTS
  10725. #ifdef CK_DTRCD
  10726. #ifdef CK_DTRCTS
  10727.            "Flow control type, one of the following:\n\
  10728.    dtr/cd    dtr/cts   keep    none    rts/cts   xon/xoff\n\
  10729.  or connection type";
  10730. #else /* CK_DTRCTS */
  10731.            "Flow control type, one of the following:\n\
  10732.    dtr/cd    keep    none    rts/cts   xon/xoff\n\
  10733.             or connection type";
  10734. #endif /* CK_DTRCTS */
  10735. #else /* CK_DTRCD */
  10736. #ifdef CK_DTRCTS
  10737.            "Flow control type, one of the following:\n\
  10738.    dtr/cts   keep   none    rts/cts   xon/xoff\n\
  10739.  or connection type";
  10740. #else /* CK_DTRCTS */
  10741.            "Flow control type, one of the following:\n\
  10742.    keep   none    rts/cts   xon/xoff\n\
  10743.  or connection type";
  10744. #endif /* CK_DTRCTS */
  10745. #endif /* CK_DTRCD */
  10746. #else
  10747.            "Flow control type, one of the following:\n\
  10748.    keep   none    xon/xoff\n\
  10749.  or connection type";
  10750. #endif /* CK_RTSCTS */
  10751. #endif /* Plan9 */
  10752.           }
  10753.           cmfdbi(&k1,_CMKEY,m,"","",ncxtypesw, 4, xxstring, cxtypesw, &k2);
  10754.           cmfdbi(&k2,
  10755.                  _CMKEY,
  10756.                  "",
  10757.                  "",
  10758.                  "",
  10759. #ifdef TN_COMPORT
  10760.                  (tncomport ? ntnflo : nflo),
  10761. #else
  10762.                  nflo,
  10763. #endif /* TN_COMPORT */
  10764.                  0,
  10765.                  xxstring,
  10766. #ifdef TN_COMPORT
  10767.                  (tncomport ? tnflotab : flotab),
  10768. #else
  10769.                  flotab,
  10770. #endif /* TN_COMPORT */
  10771.                  NULL
  10772.                  );
  10773.           x = cmfdb(&k1);
  10774.           if (x < 0) {                  /* Error */
  10775.               if (x == -2 || x == -9)
  10776.                 printf("?No keywords or switches match: \"%s\"\n",atmbuf);
  10777.               return(x);
  10778.           }
  10779.           z = cmresult.nresult;         /* Keyword value */
  10780.           if (cmresult.fdbaddr == &k2) { /* Flow-control type keyword table */
  10781.               if ((x = cmcfm()) < 0)    /* Set it immediately */
  10782.                 return(x);
  10783.               flow = z;
  10784.               debug(F101,"set flow","",flow);
  10785. #ifdef CK_SPEED
  10786.               if (flow == FLO_XONX)     /* Xon/Xoff forces prefixing */
  10787.                 ctlp[XON] = ctlp[XOFF] = ctlp[XON+128] = ctlp[XOFF+128] = 1;
  10788. #endif /* CK_SPEED */
  10789.               autoflow = (flow == FLO_AUTO);
  10790.               return(success = 1);      /* Done */
  10791.           }
  10792.           debug(F101,"set flow /blah 1","",z); /* SET FLOW /for-what */
  10793.           if ((y = cmkey(flotab,nflo,"Flow control type","none",xxstring)) < 0)
  10794.             return(y);
  10795.           if ((x = cmcfm()) < 0)
  10796.             return(x);
  10797.           debug(F101,"set flow /blah 2","",y);
  10798.           if (y == FLO_AUTO) {
  10799.               printf(
  10800.   "?Sorry, \"automatic\" can not be assigned to a connection type.\n");
  10801.               return(-9);
  10802.           } else if (z >= 0 && z <= CXT_MAX)
  10803.             cxflow[z] = y;
  10804.           debug(F101,"set flow","",flow);
  10805.           debug(F101,"set flow autoflow","",autoflow);
  10806.           return(success = 1);
  10807.       }
  10808.  
  10809.       case XYHAND:                      /* HANDSHAKE */
  10810.         if ((y = cmkey(hshtab,nhsh,"","none",xxstring)) < 0) return(y);
  10811.         if (y == 998) {
  10812.             if ((x = cmnum("ASCII value","",10,&y,xxstring)) < 0)
  10813.               return(x);
  10814.             if ((y < 1) || ((y > 31) && (y != 127))) {
  10815.                 printf("?Character must be in ASCII control range\n");
  10816.                 return(-9);
  10817.             }
  10818.         }
  10819.         if ((x = cmcfm()) < 0) return(x);
  10820.         turn = (y > 0127) ? 0 : 1;
  10821.         turnch = y;
  10822.         return(success = 1);
  10823.  
  10824. #ifndef NOSPL
  10825.       case XYMACR:                      /* SET MACRO */
  10826.         if ((y = cmkey(smactab,2,"","",xxstring)) < 0) return(y);
  10827.         switch (y) {
  10828.           case 0: return(success = seton(&mecho));
  10829.           case 1: return(success = seton(&merror[cmdlvl]));
  10830.           default: return(-2);
  10831.         }
  10832. #endif /* NOSPL */
  10833.  
  10834.       case XYMSGS:
  10835. #ifdef VMS
  10836.         if ((z = cmkey(onoff,2,"","",xxstring)) < 0) return(z);
  10837.         if ((y = cmcfm()) < 0) return(y);
  10838.         vms_msgs = z;
  10839.         printf("Sorry, SET MESSAGES not implemented yet\n");
  10840.         return(success = 0);
  10841. #endif /* VMS */
  10842.       default:
  10843.         break;
  10844.     }
  10845.  
  10846.     switch (xx) {
  10847.  
  10848.       case XYPARI:                      /* PARITY */
  10849.         if ((y = cmkey(partbl,npar,"","none",xxstring)) < 0)
  10850.           return(y);
  10851.  
  10852.         /* If parity not none, then we also want 8th-bit prefixing */
  10853.  
  10854. #ifdef HWPARITY
  10855.         if (y == 'H') {                 /* Hardware */
  10856.             if ((x = cmkey(hwpartbl,nhwpar,"","even",xxstring)) < 0)
  10857.               return(x);
  10858.         }
  10859. #endif /* HWPARITY */
  10860.  
  10861.         if ((z = cmcfm()) < 0)
  10862.           return(z);
  10863.  
  10864. #ifdef HWPARITY
  10865.         if (y == 'H') {                 /* 8 data bits plus hardware parity */
  10866.             parity = 0;
  10867. #ifndef NOXFER
  10868.             ebqflg = 0;
  10869. #endif /* NOXFER */
  10870.             hwparity = x;
  10871.         } else {                        /* 7 data bits + software parity */
  10872.             hwparity = 0;
  10873. #endif /* HWPARITY */
  10874.             parity = y;
  10875. #ifndef NOXFER
  10876.             ebqflg = (parity) ? 1 : 0;
  10877. #endif /* NOXFER */
  10878. #ifdef HWPARITY
  10879.         }
  10880. #endif /* HWPARITY */
  10881.  
  10882. #ifdef TN_COMPORT
  10883.         if (network && istncomport())
  10884.           tnsettings(parity, 0);
  10885. #endif /* TN_COMPORT */
  10886.  
  10887.         return(success = 1);
  10888.  
  10889. #ifndef NOFRILLS
  10890.       case XYPROM:                      /* SET PROMPT */
  10891. /*
  10892.   Note: xxstring not invoked here.  Instead, it is invoked every time the
  10893.   prompt is issued.  This allows the prompt string to contain variables
  10894.   that can change, like \v(dir), \v(time), etc.
  10895. */
  10896.         ckmakmsg(line,                  /* Default might have trailing space */
  10897.                  LINBUFSIZ,
  10898.                  "{",
  10899.                  inserver ? ikprompt : ckprompt,
  10900.                  "}",
  10901.                  NULL
  10902.                  );
  10903.         if ((x = cmtxt("Program's command prompt",line,&s,NULL)) < 0)
  10904.           return(x);
  10905.         s = brstrip(s);                 /* Remove enclosing braces, if any */
  10906.         cmsetp(s);                      /* Set the prompt */
  10907.         return(success = 1);
  10908. #endif /* NOFRILLS */
  10909.  
  10910. #ifndef NOXFER
  10911.       case XYRETR:                      /* RETRY: per-packet retry limit */
  10912.         y = cmnum("Maximum retries per packet","10",10,&x,xxstring);
  10913.         if (x < 0) x = 0;
  10914.         if ((x = setnum(&maxtry,x,y,999)) < 0) return(x);
  10915. #ifdef COMMENT
  10916.         if (maxtry <= wslotr) {
  10917.             printf("?Retry limit must be greater than window size\n");
  10918.             return(success = 0);
  10919.         }
  10920. #endif /* COMMENT */
  10921.         if (rmsflg) {
  10922.             sstate = setgen('S', "403", ckitoa(maxtry), "");
  10923.             return((int) sstate);
  10924.         } else return(success = x);
  10925. #endif /* NOXFER */
  10926.  
  10927. #ifndef NOSERVER
  10928.       case XYSERV:                      /* SET SERVER items */
  10929.         if ((y = cmkey(srvtab,nsrvt,"","",xxstring)) < 0) return(y);
  10930.         switch (y) {
  10931.           case XYSERI:
  10932.             if ((y = cmnum("Number of seconds, or 0 for no idle timeout",
  10933.                            "0",10,&x,xxstring)) < 0)
  10934.               return(y);
  10935.             if (x < 0)
  10936.               x = 0;
  10937.             if ((y = cmcfm()) < 0)
  10938.               return(y);
  10939. #ifndef OS2
  10940.             srvtim = 0;
  10941. #endif /* OS2 */
  10942.             srvidl = x;
  10943.             return(success = 1);
  10944.           case XYSERT:
  10945.             if ((y = cmnum("Interval for server NAKs, 0 = none",
  10946.                            ckitoa(DSRVTIM),
  10947.                            10,&x, xxstring)) < 0)
  10948.               return(y);
  10949.             if (x < 0) {
  10950.                 printf(
  10951.                    "\n?Specify a positive number, or 0 for no server NAKs\n");
  10952.                 return(0);
  10953.             }
  10954.             if ((y = cmcfm()) < 0) return(y);
  10955.             if (rmsflg) {
  10956.                 sstate = setgen('S', "404", ckitoa(x), "");
  10957.                 return((int) sstate);
  10958.             } else {
  10959. #ifndef OS2
  10960.                 srvidl = 0;
  10961. #endif /* OS2 */
  10962.                 srvtim = x;             /* Set the server timeout variable */
  10963.                 return(success = 1);
  10964.             }
  10965.           case XYSERD:                  /* SERVER DISPLAY */
  10966.             return(success = seton(&srvdis)); /* ON or OFF... */
  10967.  
  10968. #ifndef NOSPL
  10969.           case XYSERP:                  /* SERVER GET-PATH */
  10970.             return(parsdir(2));
  10971. #endif /* NOSPL */
  10972.  
  10973.           case XYSERL:                  /* SERVER LOGIN */
  10974.             return(cklogin());
  10975.  
  10976.           case XYSERC:                  /* SERVER CD-MESSAGE */
  10977.             x = rmsflg ?
  10978.               cmkey(onoff,2,"","",xxstring) :
  10979.                 cmkey(cdmsg,3,"","",xxstring);
  10980.             if (x < 0)
  10981.               return(x);
  10982.             if (x == 2) {               /* CD-MESSAGE FILE */
  10983.                 if ((x = cmtxt("Name of file","",&s,NULL)) < 0)
  10984.                   return(x);
  10985.                 if (!*s) {
  10986.                     s = NULL;
  10987.                     srvcdmsg = 0;
  10988.                 }
  10989.                 makestr(&cdmsgstr,s);
  10990.                 makelist(cdmsgstr,cdmsgfile,8);
  10991.                 return(success = 1);
  10992.             }
  10993.             if ((y = cmcfm()) < 0)      /* CD-MESSAGE ON/OFF */
  10994.               return(y);
  10995.             if (rmsflg) {
  10996.                 sstate = setgen('S', "420", x ? "1" : "0", "");
  10997.                 return((int) sstate);
  10998.             } else {
  10999.                 if (x > 0)
  11000.                   srvcdmsg |= 1;
  11001.                 else
  11002.                   srvcdmsg &= 2;
  11003.                 return(success = 1);
  11004.             }
  11005.           case XYSERK:                  /* SERVER KEEPALIVE */
  11006.             return(success = seton(&srvping)); /* ON or OFF... */
  11007.  
  11008.           default:
  11009.             return(-2);
  11010.         }
  11011. #endif /* NOSERVER */
  11012.     }
  11013.  
  11014.     switch (xx) {
  11015. #ifdef UNIX
  11016. #ifndef NOJC
  11017.       case XYSUSP:                      /* SET SUSPEND */
  11018.         seton(&xsuspend);        /* on or off... */
  11019.         return(success = 1);
  11020. #endif /* NOJC */
  11021. #endif /* UNIX */
  11022.  
  11023.       case XYTAKE:                      /* SET TAKE */
  11024.         if ((y = cmkey(taktab,4,"","",xxstring)) < 0) return(y);
  11025.         switch (y) {
  11026.           case 0: return(success = seton(&techo));
  11027. #ifndef NOSPL
  11028.           case 1: return(success = seton(&takerr[cmdlvl]));
  11029. #else
  11030.           case 1: return(success = seton(&takerr[tlevel]));
  11031. #endif /* NOSPL */
  11032.           case 2: techo = 0; return(success = 1); /* For compatibility with */
  11033.           case 3: techo = 1; return(success = 1); /* MS-DOS Kermit */
  11034.           default: return(-2);
  11035.         }
  11036.  
  11037. #ifndef NOSCRIPT
  11038.       case XYSCRI:                      /* SET SCRIPT */
  11039.         if ((y = cmkey(scrtab,1,"","echo",xxstring)) < 0) return(y);
  11040.         switch (y) {
  11041.           case 0: return(success = seton(&secho));
  11042.           default: return(-2);
  11043.         }
  11044. #endif /* NOSCRIPT */
  11045.  
  11046.       default:
  11047.         break;
  11048.     }
  11049.  
  11050. #ifndef NOLOCAL
  11051.     switch (xx) {
  11052.       case XYTERM:                      /* SET TERMINAL */
  11053.         x = settrm();
  11054.         success = (x > 0) ? 1 : 0;
  11055.         return(x);
  11056.  
  11057. #ifdef NT
  11058.       case XYWIN95:                     /* SET WIN95 workarounds */
  11059.         x = setwin95();
  11060.         success = (x > 0 ? 1 : 0);
  11061.         return(x);
  11062. #endif /* NT */
  11063.  
  11064. #ifdef OS2
  11065.       case XYDLR:                       /* SET DIALER workarounds */
  11066.         x = setdialer();
  11067.         success = (x > 0 ? 1 : 0);
  11068.         return(x);
  11069.  
  11070.       case XYTITLE:                     /* SET TITLE of window */
  11071.         x = settitle();
  11072.         success = (x > 0 ? 1 : 0);
  11073.         return(x);
  11074. #endif /* OS2 */
  11075.  
  11076. #ifdef OS2MOUSE
  11077.       case XYMOUSE:                     /* SET MOUSE */
  11078.         return(success = setmou());
  11079. #endif /* OS2MOUSE */
  11080.  
  11081.       case XYBELL:                      /* SET BELL */
  11082.         return(success = setbell());
  11083.  
  11084. #ifdef OS2
  11085.       case XYPRTY:
  11086.         return(success = setprty() );
  11087. #endif /* OS2 */
  11088.  
  11089.       default:
  11090.         break;
  11091.     }
  11092. #endif /* NOLOCAL */
  11093.  
  11094.     switch (xx) {
  11095.  
  11096. /* SET SEND/RECEIVE protocol parameters. */
  11097.  
  11098. #ifndef NOXFER
  11099.       case XYRECV:
  11100.       case XYSEND:
  11101.         return(setsr(xx,rmsflg));
  11102. #endif /* NOXFER */
  11103.  
  11104. #ifndef NOLOCAL
  11105.       case XYSESS:                      /* SESSION-LOG */
  11106.         if ((x = cmkey(sfttab,nsfttab,"type of file",
  11107. #ifdef OS2
  11108.                        "binary",
  11109. #else /* OS2 */
  11110.                        "text",
  11111. #endif /* OS2 */
  11112.                        xxstring
  11113.                        )
  11114.              ) < 0)
  11115.           return(x);
  11116.         if ((y = cmcfm()) < 0)
  11117.           return(y);
  11118.         if (x == 999) {                 /* TIMESTAMPED-TEXT */
  11119.             sessft = XYFT_T;            /* Implies text */
  11120.             slogts = 1;                 /* and timestamps */
  11121.         } else {                        /* A regular type */
  11122.             sessft = x;                 /* The type */
  11123.             slogts = 0;                 /* No timestampes */
  11124.         }
  11125.         return(success = 1);
  11126.  
  11127.       case XYSPEE:                      /* SET SPEED */
  11128.         lp = line;
  11129.         if (local && !network) {
  11130.           ckmakmsg(lp,
  11131.                    LINBUFSIZ,
  11132.                    "Transmission rate for ",
  11133.                    ttname,
  11134.                    " (bits per second)",
  11135.                    NULL
  11136.                    );
  11137.         } else {
  11138.           ckstrncpy(lp,
  11139.                     "Serial-port speed (bits per second)",
  11140.                     LINBUFSIZ
  11141.                     );
  11142.         }
  11143.         zz = -1L;
  11144.  
  11145. #ifdef TN_COMPORT
  11146.         if (network && istncomport())
  11147.           x = cmkey(tnspdtab,ntnspd,line,"",xxstring);
  11148.         else
  11149. #endif /* TN_COMPORT */
  11150.           x = cmkey(spdtab,nspd,line,"",xxstring);
  11151.         if (x < 0) {
  11152.             if (x == -3) printf("?value required\n");
  11153. #ifdef USETCSETSPEED
  11154.             /* In this case, any number can be tried */
  11155.             /* There's a parse error message but the request still goes thru */
  11156.             if (rdigits(atmbuf))
  11157.               zz = atol(atmbuf);
  11158.             else
  11159. #endif /* USETCSETSPEED */
  11160.               return(x);
  11161.         }
  11162.         if ((y = cmcfm()) < 0) return(y);
  11163. #ifdef IKSD
  11164.         if (inserver) {
  11165.             printf("?Sorry, command disabled.\r\n");
  11166.             return(success = 0);
  11167.         }
  11168. #endif /* IKSD */
  11169.         if (!local) {
  11170.             printf("?SET SPEED has no effect without prior SET LINE\n");
  11171.             return(success = 0);
  11172.         } else if (network
  11173. #ifdef TN_COMPORT
  11174.                    && !istncomport()
  11175. #endif /* TN_COMPORT */
  11176.                    ) {
  11177.             printf("\n?Speed cannot be set for network connections\n");
  11178.             return(success = 0);
  11179.         }
  11180.  
  11181. /*
  11182.   Note: This way of handling speeds is not 16-bit safe for speeds greater
  11183.   than 230400.  The argument to ttsspd() should have been a long.
  11184. */
  11185. #ifdef USETCSETSPEED
  11186.         if (zz > -1L)
  11187.           x = zz / 10L;
  11188. #endif /* USETCSETSPEED */
  11189.         zz = (long) x * 10L;
  11190.         if (zz == 130L) zz = 134L;
  11191.         if (zz == 70L) zz = 75L;        /* (see spdtab[] definition) */
  11192.         if (ttsspd(x) < 0)  {           /* Call ttsspd with cps, not bps! */
  11193.             printf("?Unsupported line speed - %ld\n",zz);
  11194.             return(success = 0);
  11195.         } else {
  11196. #ifdef CK_TAPI
  11197.             if (!tttapi || tapipass)
  11198.               speed = ttgspd();         /* Read it back */
  11199.             else
  11200.               speed = zz;
  11201. #else /* CK_TAPI */
  11202.             speed = ttgspd();           /* Read it back */
  11203. #endif /* CK_TAPI */
  11204.             if (speed != zz)  {         /* Call ttsspd with cps, not bps! */
  11205.                 printf("?SET SPEED fails, speed is %ld\n",speed);
  11206.                 return(success = 0);
  11207.             }
  11208.             if (pflag && !xcmdsrc) {
  11209.                 if (speed == 8880)
  11210.                   printf("%s, 75/1200 bps\n",ttname);
  11211.                 else if (speed == 134)
  11212.                   printf("%s, 134.5 bps\n",ttname);
  11213.                 else
  11214.                   printf("%s, %ld bps\n",ttname,speed);
  11215.             }
  11216.             return(success = 1);
  11217.         }
  11218. #endif /* NOLOCAL */
  11219.  
  11220. #ifndef NOXFER
  11221.       case XYXFER:                      /* SET TRANSFER */
  11222.         if ((y = cmkey(rmsflg ? rtstab : tstab, /* (or REMOTE SET TRANSFER) */
  11223.                        rmsflg ? nrts : nts,
  11224.                        "","character-set",xxstring)) < 0) return(y);
  11225.         switch (y) {
  11226. #ifdef XFRCAN
  11227.           case XYX_CAN:                 /* CANCELLATION */
  11228.             if ((z = cmkey(onoff,2,"","",xxstring)) < 0) return(z);
  11229.             if (z == 0) {               /* OFF */
  11230.                 if ((y = cmcfm()) < 0) return(y);
  11231.                 xfrcan = 0;
  11232.             } else {
  11233.                 if ((y = cmnum("ASCII code for cancellation character",
  11234.                                "3",10,&x,
  11235.                                xxstring)) < 0)
  11236.                   return(y);
  11237.                 if (x > 31 && x != 127) {
  11238.                     printf("Cancel character must be 0-31 or 127\n");
  11239.                     return(-9);
  11240.                 }
  11241.                 if ((y = cmnum("How many required to cause cancellation",
  11242.                                "2",10,&z, xxstring)) < 0)
  11243.                   return(y);
  11244.                 if (z < 2) {
  11245.                     printf("Number must be 2 or greater\n");
  11246.                     return(-9);
  11247.                 }
  11248.                 if ((y = cmcfm()) < 0) return(y);
  11249.                 xfrcan = 1;             /* CANCELLATION ON */
  11250.                 xfrchr = x;             /* Using this character */
  11251.                 xfrnum = z;             /* Needing this many of them */
  11252.             }
  11253.             return(success = 1);
  11254. #endif /* XFRCAN */
  11255.  
  11256. #ifndef NOCSETS
  11257.           case XYX_CSE:                 /* CHARACTER-SET */
  11258.             if ((y = cmkey(tcstab,ntcs,"","transparent",xxstring)) < 0)
  11259.               return(y);
  11260.             if ((x = cmcfm()) < 0) return(x);
  11261.             if (rmsflg) {
  11262.                 sstate = setgen('S', "405", tcsinfo[y].designator, "");
  11263.                 return((int) sstate);
  11264.             } else {
  11265.                 extern int s_cset, fcharset, axcset[], tcs_save;
  11266.                 tslevel = (y == TC_TRANSP) ? 0 : 1; /* transfer syntax level */
  11267.         xfrxla = tslevel;
  11268.                 tcharset = y;           /* transfer character set */
  11269.                 /* SEND CHARACTER-SET AUTO */
  11270.                 if (tslevel > 0 && s_cset == XMODE_A)
  11271.                   if (y > -1 && y <= MAXTCSETS)
  11272.                     if (axcset[y] > -1 && axcset[y] > MAXFCSETS)
  11273.                       fcharset = axcset[y]; /* Auto-pick file charset */
  11274.                 setxlatype(tcharset,fcharset); /* Translation type */
  11275.         tcs_save = -1;
  11276.                 return(success = 1);
  11277.             }
  11278. #endif /* NOCSETS */
  11279.  
  11280.           case XYX_LSH:                 /* LOCKING-SHIFT */
  11281.             if ((y = cmkey(lstab,nls,"","on",xxstring)) < 0)
  11282.               return(y);
  11283.             if ((x = cmcfm()) < 0) return(x);
  11284.             lscapr = (y == 1) ? 1 : 0;  /* ON: requested = 1 */
  11285.             lscapu = (y == 2) ? 2 : 0;  /* FORCED:  used = 1 */
  11286.             return(success = 1);
  11287.  
  11288. #ifdef CK_XYZ
  11289.           case XYX_PRO:                 /* Protocol */
  11290. #ifndef OS2
  11291.             if (inserver) {
  11292.                 printf("?Sorry, only Kermit protocol is available\n");
  11293.                 return(-9);
  11294.             }
  11295. #endif /* OS2 */
  11296.             return(setproto());
  11297. #endif /* CK_XYZ */
  11298.  
  11299.           case XYX_MOD:                 /* Mode */
  11300.             if ((y = cmkey(xfrmtab,2,"","automatic",xxstring)) < 0)
  11301.               return(y);
  11302.             if ((x = cmcfm()) < 0) return(x);
  11303.             if (rmsflg) {
  11304.                 sstate = setgen('S', "410", y == XMODE_A ? "0" : "1", "");
  11305.                 return((int)sstate);
  11306.             }
  11307.             g_xfermode = y;
  11308.             xfermode = y;
  11309.             return(success = 1);
  11310.  
  11311. #ifndef NOLOCAL
  11312.           case XYX_DIS:                 /* Display */
  11313.             return(doxdis(1));        /* 1 == Kermit */
  11314. #endif /* NOLOCAL */
  11315.  
  11316.           case XYX_SLO:                 /* Slow-start */
  11317.             return(seton(&slostart));
  11318.  
  11319. #ifndef NOSPL
  11320.           case XYX_CRC:                 /* CRC */
  11321.             return(seton(&docrc));
  11322. #endif /* NOSPL */
  11323.  
  11324.           case XYX_BEL:                 /* Bell */
  11325.             return(seton(&xfrbel));
  11326.  
  11327. #ifdef PIPESEND
  11328.           case XYX_PIP:                 /* Pipes */
  11329. #ifndef NOPUSH
  11330.             if (nopush) {
  11331. #endif /* NOPUSH */
  11332.                 printf("Sorry, access to pipes is disabled\n");
  11333.                 return(-9);
  11334. #ifndef NOPUSH
  11335.             } else
  11336. #endif /* NOPUSH */
  11337.               return(seton(&usepipes));
  11338. #endif /* PIPESEND */
  11339.  
  11340.           case XYX_INT:                 /* Interruption */
  11341.             return(seton(&xfrint));
  11342.  
  11343.           case XYX_XLA:
  11344.             return(seton(&xfrxla));     /* Translation */
  11345.  
  11346.           case XYX_MSG: {
  11347.               extern char * xfrmsg;
  11348.               if ((x = cmtxt("Prompt string","",&s,xxstring)) < 0)
  11349.                 return(x);
  11350.               if (!*s) s = NULL;
  11351.               makestr(&xfrmsg,s);
  11352.               return(success = 1);
  11353.  
  11354.       }
  11355.       case XYX_RPT: {
  11356.           extern int whereflg;
  11357.           return(seton(&whereflg));
  11358.           }
  11359.           default:
  11360.             return(-2);
  11361.         }
  11362. #endif /* NOXFER */
  11363.     }
  11364.  
  11365.     switch (xx) {
  11366.  
  11367. #ifndef NOXMIT
  11368.       case XYXMIT:                      /* SET TRANSMIT */
  11369.         return(setxmit());
  11370. #endif /* NOXMIT */
  11371.  
  11372. #ifndef NOXFER
  11373. #ifndef NOCSETS
  11374.       case XYUNCS:                      /* UNKNOWN-CHARACTER-SET */
  11375.         if ((y = cmkey(ifdtab,2,"","discard",xxstring)) < 0) return(y);
  11376.         if ((x = cmcfm()) < 0) return(x);
  11377.         unkcs = y;
  11378.         return(success = 1);
  11379. #endif /* NOCSETS */
  11380. #endif /* NOXFER */
  11381.  
  11382. #ifndef NOPUSH
  11383. #ifdef UNIX
  11384.       case XYWILD:                      /* WILDCARD-EXPANSION */
  11385.         if ((y = cmkey(wildtab,nwild,
  11386.                        "Wildcard expansion option","on",xxstring)) < 0)
  11387.           return(y);
  11388.         if ((z = cmkey(wdottab,
  11389.                        2,
  11390.                        "whether to match filenames that start with \".\"",
  11391.                        "/no-match-dot-files",
  11392.                        xxstring)
  11393.              ) < 0)
  11394.           return(z);
  11395.         if ((x = cmcfm()) < 0) return(x);
  11396.         if (nopush) {
  11397.             if (y > 0) {
  11398.                 printf("Shell expansion is disabled\n");
  11399.                 return(success = 0);
  11400.             }
  11401.         }
  11402.     switch (y) {
  11403.       case WILD_ON:
  11404.         wildena = 1; 
  11405.         break;
  11406.       case WILD_OFF:
  11407.         wildena = 0; 
  11408.         break;
  11409.       case WILD_KER:
  11410.         wildxpand = 0;         /* These are the previous */
  11411.         break;            /* hardwired values */
  11412.       case WILD_SHE:
  11413.         wildxpand = 1; 
  11414.         break;
  11415.     }
  11416.         matchdot = z;
  11417.         return(success = 1);
  11418. #endif /* UNIX */
  11419. #endif /* NOPUSH */
  11420.  
  11421. #ifndef NOXFER
  11422.       case XYWIND:                      /* WINDOW-SLOTS */
  11423.         if (protocol == PROTO_K) {
  11424.             y = cmnum("Window size for Kermit protocol, 1 to 32",
  11425.                       "1", 10, &x, xxstring);
  11426.             y = setnum(&z,x,y,MAXWS);   /* == 32 */
  11427.         }
  11428. #ifdef CK_XYZ
  11429.         else if (protocol == PROTO_Z) {
  11430.             y = cmnum("Window size for ZMODEM protocol, 0 to 65535",
  11431.                       "0", 10, &x, xxstring);
  11432.             y = setnum(&z,x,y,65535);
  11433.         }
  11434. #endif /* CK_XYZ */
  11435.         else {
  11436.             y = cmnum("Window size for current protocol",
  11437.                       "", 10, &x, xxstring);
  11438.             y = setnum(&z,x,y,65472);   /* Doesn't matter - we won't use it */
  11439.         }
  11440.         if (y < 0) return(y);
  11441.         if (protocol == PROTO_K) {
  11442.             if (z < 1)
  11443.               z = 1;
  11444.         }
  11445. #ifdef CK_XYZ
  11446.         else if (protocol == PROTO_Z) {
  11447.             /* Zmodem windowing is closer to Kermit packet length */
  11448.             /* than Kermit window size.  If Window size is zero   */
  11449.             /* an end of frame and CRC is sent only at the end of */
  11450.             /* the file (default).  Otherwise, an End of Frame    */
  11451.             /* and CRC are sent after Window Size number of bytes */
  11452.             if (z < 0)                  /* Disable windowing  */
  11453.               z = 0;
  11454.         } else {
  11455.             printf("?SET WINDOW does not apply to %s protocol\n",
  11456.                    ptab[protocol].p_name
  11457.                    );
  11458.         }
  11459. #endif /* CK_XYZ */
  11460.  
  11461. #ifdef COMMENT
  11462.         /* This is taken care of automatically now in protocol negotiation */
  11463.         if (maxtry < z) {
  11464.             printf("?Window slots must be less than retry limit\n");
  11465.             return(success = 0);
  11466.         }
  11467. #endif /* COMMENT */
  11468.         if (protocol == PROTO_K && rmsflg) { /* Set remote window size */
  11469.             wslotr = z;                 /* Set local window size too */
  11470.             ptab[protocol].winsize = wslotr;
  11471.             sstate = setgen('S', "406", ckitoa(z), "");
  11472.             return((int) sstate);
  11473.         }
  11474.         wslotr = z;                     /* Set requested window size here */
  11475.         ptab[protocol].winsize = wslotr; /* and in protocol-specific table */
  11476.         if (protocol == PROTO_K) {      /* And for Kermit only... */
  11477.             swcapr = (wslotr > 1) ? 1 : 0; /* set window bit in capas word */
  11478.             if (wslotr > 1) {           /* Window size > 1? */
  11479.                 /* Maybe adjust packet size */
  11480.                 y = adjpkl(urpsiz,wslotr,bigrbsiz);
  11481.                 if (y != urpsiz) {      /* Did it change? */
  11482.                     urpsiz = y;
  11483.                     if (msgflg)
  11484.                       printf(
  11485. " Adjusting receive packet-length to %d for %d window slots\n",
  11486.                              urpsiz,
  11487.                              wslotr
  11488.                              );
  11489.                 }
  11490.             }
  11491.         }
  11492.         return(success = 1);
  11493. #endif /* NOXFER */
  11494.     }
  11495.  
  11496.     switch (xx) {
  11497.  
  11498. #ifndef NOSPL
  11499.       case XYOUTP:                      /* OUTPUT command parameters */
  11500.         if ((y = cmkey(outptab,noutptab,"OUTPUT command parameter","pacing",
  11501.                        xxstring)) < 0)
  11502.           return(y);
  11503.         switch(y) {                     /* Which parameter */
  11504.           case OUT_PAC:                 /* PACING */
  11505.             y = cmnum("Milliseconds to pause between each OUTPUT character",
  11506.                       "100", 10,&x,xxstring);
  11507.             y = setnum(&z,x,y,16383);   /* Verify and get confirmation */
  11508.             if (y < 0) return(y);
  11509.             if (z < 0) z = 0;           /* (save some space) */
  11510.             pacing = z;
  11511.             return(success = 1);
  11512.           case OUT_ESC:                 /* Special-escapes */
  11513.             return(seton(&outesc));
  11514.           default:                      /* (shouldn't happen) */
  11515.             return(-2);
  11516.         }
  11517. #endif /* NOSPL */
  11518.  
  11519. #ifdef CK_SPEED
  11520.       case XYQCTL: {
  11521.           short *p;
  11522.           int zz;
  11523.           if ((z = cmkey(ctltab,2, "control-character prefixing option",""
  11524.                          ,xxstring)) < 0)
  11525.             return(z);
  11526.           /* Make space for a temporary copy of the prefixing table */
  11527.  
  11528.           p = (short *)malloc(256 * sizeof(short));
  11529.           if (!p) {
  11530.               printf("?Internal error - malloc failure\n");
  11531.               return(-9);
  11532.           }
  11533.           for (i = 0; i < 256; i++) p[i] = ctlp[i]; /* Copy current table */
  11534.  
  11535.           switch (z) {
  11536.             case 0:                     /* UNPREFIXED control character */
  11537.             case 1:                     /* PREFIXED control character */
  11538.               while (1) {               /* Collect a list of numbers */
  11539. #ifndef NOSPL
  11540.                   x_ifnum = 1;          /* Turn off complaints from eval() */
  11541. #endif /* NOSPL */
  11542.                   if ((x = cmnum((z == 0) ?
  11543. "\n Numeric ASCII value of control character that needs NO prefix,\n\
  11544.  or the word \"all\", or carriage return to complete the list" :
  11545. "\n Numeric ASCII value of control character that MUST BE prefixed,\n\
  11546.  or the word \"all\", or carriage return to complete the list",
  11547.                                  "",10,&y,xxstring
  11548.                                  )) < 0) {
  11549. #ifndef NOSPL
  11550.                       x_ifnum = 0;
  11551. #endif /* NOSPL */
  11552.                       if (x == -3) {
  11553.                           if ((x = cmcfm()) < 0) return(x);
  11554.                           break;
  11555.                       }
  11556.                       if (x == -2) {
  11557.                           if (p) { free((char *)p); p = NULL; }
  11558.                           debug(F110,"SET CONTROL atmbuf",atmbuf,0);
  11559.                           if (!ckstrcmp(atmbuf,"all",3,0) || /* "ALL" */
  11560.                               !ckstrcmp(atmbuf,"al",2,0) ||
  11561.                               !ckstrcmp(atmbuf,"a",1,0)) {
  11562.                               if ((x = cmcfm()) < 0) /* Get confirmation */
  11563.                                 return(x);
  11564.                   prefixing = z ? PX_ALL : PX_NON;
  11565.                   setprefix(prefixing);
  11566.                   return(success = 1);
  11567.                           } else {    /* Not number, not ALL */
  11568.                               printf(
  11569.                                  "?Please specify a number or the word ALL\n");
  11570.                               return(-9);
  11571.                           }
  11572.                       } else {
  11573.                           if (p) free((char *)p);
  11574.                           return(x);
  11575.                       }
  11576.                   }
  11577. #ifndef NOSPL
  11578.                   x_ifnum = 0;
  11579. #endif /* NOSPL */
  11580. #ifdef UNPREFIXZERO
  11581.                   zz = 0;
  11582. #else
  11583. #ifndef OS2
  11584.                   zz = 1 - z;
  11585. #else
  11586.                   zz = 0;               /* Allow 0 (but only for Zmodem) */
  11587. #endif /* OS2 */
  11588. #endif /* UNPREFIXZERO */
  11589.  
  11590.             /* printf("x = %d, y = %d, z = %d, zz = %d\n", x,y,z,zz); */
  11591.  
  11592.                   if ((y >  31 && y < 127) || /* A specific numeric value */
  11593.                       (y > 159 && y < 255) || /* Check that it is a valid */
  11594.                       (y < zz) ||       /* control code. */
  11595.                       (y > 255)) {
  11596.                       printf("?Values allowed are: %d-31, 127-159, 255\n",zz);
  11597.                       if (p) free((char *)p);
  11598.                       return(-9);
  11599.                   }
  11600.                   x = y & 127;          /* Get 7-bit value */
  11601.                   if (z == 0) {         /* If they are saying it is safe... */
  11602.                       /* If flow control is Xon/Xoff */
  11603.                       if (((flow == FLO_XONX) &&
  11604.                            /* XON & XOFF chars not safe. */
  11605.                            (x == XON || x == XOFF))
  11606.                           ) {
  11607.                           if (msgflg)
  11608.                             printf(
  11609.                               "Sorry, not while Xon/Xoff is in effect.\n");
  11610.                           if (p) free((char *)p);
  11611.                           return(-9);
  11612.                       }
  11613. #ifdef TNCODE
  11614.                       else if (network && IS_TELNET()
  11615.                                && (y == CR ||
  11616.                                    (unsigned) y == (unsigned) 255)) {
  11617.                           if (msgflg)
  11618.                             printf("Sorry, not on a TELNET connection.\n");
  11619.                           if (p) free((char *)p);
  11620.                           return(-9);
  11621.                       }
  11622. #endif /* TNCODE */
  11623.                   }
  11624.                   p[y] = (char) z;      /* All OK, set flag */
  11625.               } /* End of while loop */
  11626. /*
  11627.   Get here only if they have made no mistakes.  Copy temporary table back to
  11628.   permanent one, then free temporary table and return successfully.
  11629. */
  11630.               for (i = 0; i < 256; i++) ctlp[i] = p[i];
  11631.               if (p) free((char *)p);
  11632.               if (z > 0) clearrq = 0;   /* 199 (see SET PREFIXING) */
  11633.               return(success = 1);
  11634.             default:
  11635.               return(-2);
  11636.           }
  11637.       }
  11638. #endif /* CK_SPEED */
  11639.     }
  11640.  
  11641.     switch (xx) {
  11642.  
  11643. #ifndef NOXFER
  11644.       case XYREPT:
  11645.         if ((y = cmkey(rpttab,2,
  11646.                        "repeat-count compression parameter","",xxstring)) < 0)
  11647.           return(y);
  11648.         switch(y) {
  11649.           case 0:
  11650.             return(success = seton(&rptena)); /* REPEAT COUNTS = ON, OFF */
  11651.           case 1:                       /* REPEAT MININUM number */
  11652.             printf("(not implemented yet, nothing happens)\n");
  11653.             return(-9);
  11654.           case 2:                       /* REPEAT PREFIX char */
  11655.             if ((x = cmnum("ASCII value","",10,&z,xxstring)) < 0)
  11656.               return(x);
  11657.             if ((x = cmcfm()) < 0) return(x);
  11658.             if ((z > 32 && z < 63) || (z > 95 && z < 127)) {
  11659.                 if (y == 1) rptmin = (CHAR) z; else myrptq = (CHAR) z;
  11660.                 return(success = 1);
  11661.             } else {
  11662.                 printf("?Illegal value for prefix character\n");
  11663.                 return(-9);
  11664.             }
  11665.         }
  11666. #endif /* NOXFER */
  11667.  
  11668. #ifndef NOSPL
  11669.       case XYALRM: {
  11670. #ifndef COMMENT
  11671.           int yy;
  11672.           long zz;
  11673.           zz = -1L;
  11674.           yy = x_ifnum;
  11675.           x_ifnum = 1;                  /* Turn off internal complaints */
  11676.           y = cmnum("Seconds from now, or time of day as hh:mm:ss",
  11677.                     "0" ,10, &x, xxstring);
  11678.           x_ifnum = yy;
  11679.           if (y < 0) {
  11680.               if (y == -2) {            /* Invalid number or expression */
  11681.                   zz = tod2sec(atmbuf); /* Convert to secs since midnight */
  11682.                   if (zz < 0L) {
  11683.                       printf("?Number, expression, or time of day required\n");
  11684.                       return(-9);
  11685.                   } else {
  11686.                       char now[32];     /* Current time */
  11687.                       char *p;
  11688.                       long tnow;
  11689.                       p = now;
  11690.                       ztime(&p);
  11691.                       tnow = atol(p+11) * 3600L +
  11692.                         atol(p+14) * 60L + atol(p+17);
  11693.                       if (zz < tnow)    /* User's time before now */
  11694.                         zz += 86400L;   /* So make it tomorrow */
  11695.                       zz -= tnow;       /* Seconds from now. */
  11696.                   }
  11697.               } else
  11698.                 return(y);
  11699.           }
  11700.           if (x < 0) {
  11701.               printf("?Alarm time is in the past.\n");
  11702.               return(-9);
  11703.           }
  11704.           if ((y = cmcfm()) < 0) return(y);
  11705.           if (zz > -1L) {               /* Time of day given? */
  11706.               x = zz;
  11707.               if (zz != (long) x) {
  11708.                   printf(
  11709. "Sorry, arithmetic overflow - hh:mm:ss not usable on this platform.\n"
  11710.                          );
  11711.                   return(-9);
  11712.               }
  11713.           }
  11714.           return(setalarm((long)x));
  11715.       }
  11716. #else
  11717. /*
  11718.   This is to allow long values where int and long are not the same, e.g.
  11719.   on 16-bit systems.  But something is wrong with it.
  11720. */
  11721.         if ((y = cmtxt("seconds from now", "0", &s, xxstring)) < 0)
  11722.           return(y);
  11723.         if (rdigits(s)) {
  11724.             return(setalarm(atol(s)));
  11725.         } else {
  11726.             printf("%s - not a number\n",s);
  11727.             return(-9);
  11728.         }
  11729. #endif /* COMMENT */
  11730. #endif /* NOSPL */
  11731.  
  11732. #ifndef NOXFER
  11733.       case XYPROTO:
  11734.         return(setproto());
  11735. #endif /* NOXFER */
  11736.  
  11737. /*
  11738.   C-Kermit unprefixes control characters automatically on network connections
  11739.   if CLEAR-CHANNEL is ON, which it is by default.  But not all network
  11740.   connections are transparent to all control characters.  For example, the
  11741.   DEC-20, even when you TELNET to it, is sensitive to Ctrl-O and Ctrl-T.
  11742.   If you tell C-Kermit to SET CONTROL PREFIX 15 and/or 20, it doesn't help
  11743.   because CLEAR-CHANNEL is still in effect.  If the user goes to the trouble
  11744.   to set up some prefixing, then Kermit should do what the user said.  In
  11745.   C-Kermit 7.1 Alpha.03 we change the code to set clearrq to 0 if the user
  11746.   gives a SET PREFIXING or SET CONTROL PREFIX command.
  11747. */
  11748.  
  11749. #ifdef CK_SPEED
  11750.       case XYPREFIX: {
  11751. #ifdef COMMENT
  11752.           extern int clearrq;
  11753. #endif /* COMMENT */
  11754.           if ((z = cmkey(pfxtab, 4, "control-character prefixing option",
  11755.                          "", xxstring)) < 0)
  11756.             return(z);
  11757.           if ((x = cmcfm()) < 0) return(x);
  11758.           clearrq = 0;                  /* 199 */
  11759.           setprefix(z);
  11760. #ifdef COMMENT
  11761.           if (hints && (z == PX_ALL || z == PX_CAU) && clearrq) {
  11762.         printf("Hint: Use SET CLEAR-CHANNEL OFF to disable negotiation of\n");
  11763.         printf("      SET PREFIXING NONE during file transfers on reliable\n");
  11764.         printf("      connections.\n");
  11765.           }
  11766. #endif /* COMMENT */
  11767.           return(success = 1);
  11768.       }
  11769. #endif /* CK_SPEED */
  11770.  
  11771. #ifndef NOSPL
  11772.       case XYLOGIN:
  11773.         if ((z = cmkey(logintab, 3, "value for login script","userid",
  11774.                        xxstring)) < 0)
  11775.           return(z);
  11776.         x = cmdgquo();
  11777.         if (z == LOGI_PSW)
  11778.           cmdsquo(0);
  11779.         if ((y = cmtxt("text","", &s, NULL)) < 0) {
  11780.             cmdsquo(x);
  11781.             return(y);
  11782.         }
  11783.         cmdsquo(x);
  11784. #ifdef IKSD
  11785.         if (inserver)
  11786.           return(success = 0);
  11787. #endif /* IKSD */
  11788.         s = brstrip(s);
  11789.         if ((int)strlen(s) > 63) {
  11790.             printf("Sorry, too long\n");
  11791.             return(-9);
  11792.         }
  11793.         switch(z) {
  11794.           case LOGI_UID:
  11795.             ckstrncpy(uidbuf,s,UIDBUFLEN);
  11796.             sl_uid_saved = 0;
  11797.             break;
  11798.           case LOGI_PSW:
  11799.             ckstrncpy(pwbuf,s,PWBUFL);
  11800.             if (pwbuf[0]) {
  11801.                 pwflg = 1;
  11802. #ifdef OS2
  11803.                 pwcrypt = 1;
  11804. #else /* OS2 */
  11805.                 pwcrypt = 0;
  11806. #endif /* OS2 */
  11807.             }
  11808.             break;
  11809.           case LOGI_PRM:
  11810.             ckstrncpy(prmbuf,s,PWBUFL);
  11811.         }
  11812.         return(success = 1);
  11813. #endif /* NOSPL */
  11814.     }
  11815.  
  11816.     switch (xx) {
  11817.  
  11818.       case XYSTARTUP:
  11819.         if ((y = cmkey(ifdtab,2,"","discard",xxstring)) < 0) return(y);
  11820.         if ((x = cmcfm()) < 0) return(x);
  11821.         DeleteStartupFile = (y != 0) ? 0 : 1;
  11822.         return(success = 1);
  11823.  
  11824.       case XYTMPDIR:
  11825.         x = cmdir("Name of temporary directory","",&s,xxstring);
  11826.         if (x == -3)
  11827.           s = "";
  11828.         else if (x < 0)
  11829.           return(x);
  11830.         if ((x = cmcfm()) < 0) return(x);
  11831.         makestr(&tempdir,s);
  11832.         return(tempdir ? 1 : 0);
  11833.  
  11834. #ifndef NOXFER
  11835.       case XYDEST:                      /* DESTINATION */
  11836.         return(setdest());
  11837. #endif /* NOXFER */
  11838.  
  11839. #ifndef NOPUSH
  11840. #ifndef NOFRILLS
  11841.  
  11842. /* Editor, Browser, and FTP Client */
  11843.  
  11844.       case XYEDIT:                      /* EDITOR */
  11845. #ifdef IKSD
  11846.         if (inserver) {
  11847.             printf("?Sorry, command disabled.\r\n");
  11848.             return(success = 0);
  11849.         }
  11850. #endif /* IKSD */
  11851. #ifdef CK_APC
  11852.         /* Don't let this be set remotely */
  11853.         if (apcactive == APC_LOCAL ||
  11854.             (apcactive == APC_REMOTE && !(apcstatus & APC_UNCH)))
  11855.           return(success = 0);
  11856. #endif /* CK_APC */
  11857.  
  11858. #ifdef OS2ORUNIX
  11859.         {
  11860.             char *p = getenv("PATH");
  11861.             char *e;
  11862.             e = editor[0] ? (char *) editor : getenv("EDITOR");
  11863.             if (!e) e = "";
  11864.             if (p)
  11865.               x = cmifip("Name of preferred editor",e,&s,&y,0,p,xxstring);
  11866.             else
  11867.               x = cmifi("Full path of preferred editor",e,&s,&y,xxstring);
  11868.             if (x < 0 && x != -3)
  11869.               return(x);
  11870.         }
  11871. #else
  11872. #ifdef VMS
  11873.         if ((y = cmtxt("DCL command for editing", "edit", &s, NULL)) < 0) {
  11874.             if (x != -3)
  11875.               return(x);
  11876.         }
  11877. #else
  11878.         if ((x = cmifi("Full path of preferred editor","",&s,&y,xxstring))<0) {
  11879.             if (x != -3)
  11880.               return(x);
  11881.         }
  11882. #endif /* VMS */
  11883. #endif /* OS2ORUNIX */
  11884. #ifdef VMS
  11885.         ckstrncpy(editor,s,CKMAXPATH);
  11886.         editopts[0] = NUL;
  11887. #else
  11888.         if (y != 0) {
  11889.             printf("?A single file please\n");
  11890.             return(-2);
  11891.         }
  11892.         ckstrncpy(line,s,LINBUFSIZ);
  11893.         if ((x = cmtxt("editor command-line options","",&s,NULL)) < 0)
  11894.           return(x);
  11895.         ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  11896.         if ((z = cmcfm()) < 0) return(z);
  11897.         if (line[0]) {
  11898.             zfnqfp(line,CKMAXPATH,editor);
  11899.             ckstrncpy(editopts,tmpbuf,128);
  11900.         } else {
  11901.             editor[0] = NUL;
  11902.             editopts[0] = NUL;
  11903.         }
  11904. #endif /* VMS */
  11905.         return(success = 1);
  11906.  
  11907. #ifndef NOFTP
  11908. #ifndef SYSFTP
  11909. #ifdef TCPSOCKET
  11910.       case XYFTPX:
  11911.         return(dosetftp());             /* SET FTP */
  11912. #endif /* TCPSOCKET */
  11913. #endif /* SYSFTP */
  11914. #endif /* NOFTP */
  11915.  
  11916. #ifdef BROWSER
  11917. #ifndef NOFTP
  11918. #ifdef SYSFTP
  11919.       case XYFTP:                       /* SET FTP-CLIENT */
  11920. #endif /* SYSFTP */
  11921. #endif /* NOFTP */
  11922.       case XYBROWSE:                    /* SET BROWSER */
  11923.         {
  11924.             char *p = getenv("PATH");
  11925.             char *app = (char *) browser, *opts = (char *) browsopts;
  11926. #ifndef NOFTP
  11927. #ifdef SYSFTP
  11928.             extern char ftpapp[], ftpopts[];
  11929.             if (xx == XYFTP) {
  11930.                 app = (char *)ftpapp;
  11931.                 opts = (char *)ftpopts;
  11932.             }
  11933. #endif /* SYSFTP */
  11934. #endif /* NOFTP */
  11935. #ifdef IKSD
  11936.             if (inserver) {
  11937.                 printf("?Sorry, command disabled.\r\n");
  11938.                 return(success = 0);
  11939.             }
  11940. #endif /* IKSD */
  11941. #ifdef CK_APC
  11942.             /* Don't let this be set remotely */
  11943.             if (apcactive == APC_LOCAL ||
  11944.                 (apcactive == APC_REMOTE && !(apcstatus & APC_UNCH)))
  11945.               return(success = 0);
  11946. #endif /* CK_APC */
  11947. #ifdef OS2ORUNIX
  11948.             if (p)
  11949.               x = cmifip(xx == XYBROWSE ?
  11950.                          "Name of preferred browser" :
  11951.                          "Name of preferred ftp client",
  11952. #ifdef OS2
  11953.                          xx == XYFTP ? "ftp.exe" : ""
  11954. #else
  11955.                          xx == XYFTP ? "ftp" : ""
  11956. #endif /* OS2 */
  11957.                          ,&s,&y,0,p,xxstring
  11958.                          );
  11959.             else
  11960.               x = cmifi(xx == XYBROWSE ?
  11961.                         "Full path of preferred browser" :
  11962.                         "Full path of preferred ftp client",
  11963.                         "",&s,&y,xxstring
  11964.                         );
  11965.             if (x < 0 && x != -3)
  11966.               return(x);
  11967. #else
  11968. #ifdef VMS
  11969.             if ((x = cmtxt("DCL command to start your preferred Web browser",
  11970.                            "", &s, NULL)) < 0) {
  11971.                 if (x != -3)
  11972.                   return(x);
  11973.             }
  11974. #else
  11975.             if ((x = cmifi("Full path of preferred browser","",&s,&y,xxstring)
  11976.                  ) < 0) {
  11977.                 if (x != -3)
  11978.                   return(x);
  11979.             }
  11980. #endif /* VMS */
  11981. #endif /* OS2ORUNIX */
  11982. #ifdef VMS
  11983.             ckstrncpy(app,s,CKMAXPATH);
  11984.             *opts = NUL;
  11985. #else
  11986.             if (y != 0) {
  11987.                 printf("?A single file please\n");
  11988.                 return(-2);
  11989.             }
  11990.             ckstrncpy(line,s,LINBUFSIZ);
  11991.             if ((x = cmtxt(xx == XYBROWSE ?
  11992.                            "browser command-line options" :
  11993.                            "ftp client command-line options",
  11994.                            "",&s,NULL)
  11995.                  ) < 0)
  11996.               return(x);
  11997.             ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  11998.             if ((z = cmcfm()) < 0) return(z);
  11999.             if (line[0]) {
  12000.                 zfnqfp(line,CKMAXPATH,app);
  12001.                 ckstrncpy(opts, tmpbuf, 128);
  12002.             } else {
  12003.                 *app = NUL;
  12004.                 *opts = NUL;
  12005.             }
  12006. #endif /* VMS */
  12007.             return(success = 1);
  12008.         }
  12009. #endif /* BROWSER */
  12010. #endif /* NOFRILLS */
  12011. #endif /* NOPUSH */
  12012.  
  12013. #ifdef CK_CTRLZ
  12014.       case XYEOF: {                     /* SET EOF */
  12015.           extern int eofmethod; extern struct keytab eoftab[];
  12016.           if ((x = cmkey(eoftab,3,"end-of-file detection method","",
  12017.                          xxstring)) < 0)
  12018.             return(x);
  12019.           if ((y = cmcfm()) < 0)
  12020.             return(y);
  12021.           eofmethod = x;
  12022.           return(success = 1);
  12023.       }
  12024. #endif /* CK_CTRLZ */
  12025.  
  12026. #ifdef SESLIMIT
  12027.       case XYLIMIT: {  /* Session-Limit (length of session in seconds) */
  12028.           extern int seslimit;
  12029. #ifdef OS2
  12030.           extern int downloaded;
  12031. #endif /* OS2 */
  12032.           y = cmnum("Maximum length of session, seconds","0",10,&x,xxstring);
  12033.           if (inserver &&
  12034. #ifdef IKSDCONF
  12035.               iksdcf
  12036. #else
  12037.               1
  12038. #endif /* IKSDCONF */
  12039. #ifdef OS2
  12040.                || downloaded
  12041. #endif /* OS2 */
  12042.               ) {
  12043.               if ((z = cmcfm()) < 0)
  12044.                 return(z);
  12045.               printf("?Sorry, command disabled.\r\n");
  12046.               return(success = 0);
  12047.           }
  12048.           return(setnum(&seslimit,x,y,86400));
  12049.       }
  12050. #endif /* SESLIMIT */
  12051.  
  12052.       case XYRELY: {                    /* SET RELIABLE */
  12053.           if ((x = cmkey(ooatab,3,"","automatic",xxstring)) < 0)
  12054.             return(x);
  12055.           if ((y = cmcfm()) < 0) return(y);
  12056.           reliable = x;
  12057.           setreliable = (x != SET_AUTO);
  12058.           debug(F101,"SET RELIABLE reliable","",reliable);
  12059.           return(success = 1);
  12060.       }
  12061.  
  12062. #ifdef STREAMING
  12063.       case XYSTREAM: {                  /* SET STREAMING */
  12064.           extern int streamrq;
  12065.           if ((x = cmkey(ooatab,3,"","automatic",xxstring)) < 0)
  12066.             return(x);
  12067.           if ((y = cmcfm()) < 0) return(y);
  12068.           streamrq = x;
  12069.           return(success = 1);
  12070.       }
  12071. #endif /* STREAMING */
  12072.  
  12073. #ifdef CKSYSLOG
  12074.       case XYSYSL: {
  12075.           if ((x = cmkey(syslogtab,nsyslog,"","",xxstring)) < 0)
  12076.             return(x);
  12077.           if ((y = cmcfm()) < 0) return(y);
  12078. #ifdef IKSD
  12079.           if (inserver &&
  12080. #ifdef IKSDCONF
  12081.               iksdcf
  12082. #else
  12083.               1
  12084. #endif /* IKSDCONF */
  12085.               ) {
  12086.               printf("?Sorry, command disabled.\n");
  12087.               return(success = 0);
  12088.           }
  12089. #endif /* IKSD */
  12090. #ifdef CK_APC
  12091.           /* Don't let this be set remotely */
  12092.           if (apcactive == APC_LOCAL ||
  12093.               (apcactive == APC_REMOTE && !(apcstatus & APC_UNCH)))
  12094.             return(success = 0);
  12095. #endif /* CK_APC */
  12096.           ckxsyslog = x;
  12097.           return(success = 1);
  12098.       }
  12099. #endif /* CKSYSLOG */
  12100.  
  12101. #ifdef TLOG
  12102.       case XYTLOG: {                    /* SET TRANSACTION-LOG */
  12103.           extern int tlogsep;
  12104.           if ((x = cmkey(vbtab,nvb,"","verbose",xxstring)) < 0)
  12105.             return(x);
  12106.           if (x == 0) {
  12107.               if ((y = cmtxt("field separator",",",&s,NULL)) < 0) return(y);
  12108.               s = brstrip(s);
  12109.               if (*s) {
  12110.                   if (s[1]) {
  12111.                       printf("?A single character, please.\n");
  12112.                       return(-9);
  12113.                   } else if ((*s >= '0' && *s <= '9') ||
  12114.                              (*s >= 'A' && *s <= 'Z') ||
  12115.                              (*s >= 'a' && *s <= 'z')) {
  12116.                       printf("?A non-alphanumeric character, please.\n");
  12117.                       return(-9);
  12118.                   } else
  12119.                     tlogsep = *s;
  12120.               }
  12121.           } else {
  12122.               if ((y = cmcfm()) < 0) return(y);
  12123.           }
  12124. #ifdef IKSD
  12125.           if (inserver && isguest) {
  12126.               printf("?Sorry, command disabled.\n");
  12127.               return(success = 0);
  12128.           }
  12129. #endif /* IKSD */
  12130. #ifdef CK_APC
  12131.           /* Don't let this be set remotely */
  12132.           if (apcactive == APC_LOCAL ||
  12133.               (apcactive == APC_REMOTE && !(apcstatus & APC_UNCH)))
  12134.             return(success = 0);
  12135. #endif /* CK_APC */
  12136.           tlogfmt = x;
  12137.           return(success = 1);
  12138.       }
  12139. #endif /* TLOG */
  12140.  
  12141.       case XYCLEAR: {                   /* SET CLEARCHANNEL */
  12142.           if ((x = cmkey(ooatab,3,"","automatic",xxstring)) < 0)
  12143.             return(x);
  12144.           if ((y = cmcfm()) < 0) return(y);
  12145.           clearrq = x;
  12146.           return(success = 1);
  12147.       }
  12148.  
  12149. #ifdef CK_AUTHENTICATION
  12150.       case XYAUTH: {                    /* SET AUTHENTICATION */
  12151. #ifdef CK_KERBEROS
  12152.           int kv = 0;
  12153.           extern struct krb_op_data krb_op;
  12154. #endif /* CK_KERBEROS */
  12155.           char * p = NULL;
  12156.           if ((x =
  12157.                cmkey(setauth,nsetauth,"authentication type","",xxstring)) < 0)
  12158.             return(x);
  12159.           switch (x) {
  12160. #ifdef CK_KERBEROS
  12161.             case AUTH_KRB4: kv = 4; break; /* Don't assume values are same */
  12162.             case AUTH_KRB5: kv = 5; break;
  12163. #endif /* CK_KERBEROS */
  12164. #ifdef CK_SRP
  12165.             case AUTH_SRP: break;
  12166. #endif /* CK_SRP */
  12167. #ifdef CK_SSL
  12168.             case AUTH_SSL:
  12169.             case AUTH_TLS:
  12170.               break;
  12171. #endif /* CK_SSL */
  12172.             default:
  12173.               printf("?Authorization type not supported yet - \"%s\"\n",
  12174.                      atmbuf);
  12175.               return(-9);
  12176.           }
  12177. #ifdef IKSD
  12178.           if (inserver &&
  12179. #ifdef IKSDCONF
  12180.               iksdcf
  12181. #else
  12182.               1
  12183. #endif /* IKSDCONF */
  12184.               ) {
  12185.               if ((y = cmcfm()) < 0) return(y);
  12186.               printf("?Sorry, command disabled.\n");
  12187.               return(success = 0);
  12188.           }
  12189. #endif /* IKSD */
  12190. #ifdef CK_APC
  12191.           /* Don't let this be set remotely */
  12192.           if (apcactive == APC_LOCAL ||
  12193.               apcactive == APC_REMOTE && !(apcstatus & APC_UNCH)) {
  12194.               if ((y = cmcfm()) < 0) return(y);
  12195.               return(success = 0);
  12196.           }
  12197. #endif /* CK_APC */
  12198.  
  12199.           switch(x) {
  12200. #ifdef CK_KERBEROS
  12201.             case AUTH_KRB4:
  12202.             case AUTH_KRB5: {
  12203.                 if ((x = cmkey(kv == 4 ? k4tab : k5tab,
  12204.                                kv == 4 ? nk4tab : nk5tab,
  12205.                                "Kerberos parameter","",xxstring)) < 0) {
  12206.                     return(x);
  12207.                 }
  12208.                 s = "";
  12209.                 switch (x) {
  12210. #ifdef KRB4
  12211.                   case XYKRBDBG:
  12212.                     if (kv == 4) {
  12213.                         if ((y = seton(&k4debug)) < 0)
  12214.                           return(y);
  12215. #ifdef NT
  12216.                         ck_krb4_debug(k4debug);
  12217. #endif /* NT */
  12218.                     } else {
  12219.                         return(-9);
  12220.                     }
  12221.                     break;
  12222. #endif /* KRB4 */
  12223.                   case XYKRBLIF:
  12224.                     if ((y = cmnum("TGT lifetime","600",10,&z,xxstring)) < 0)
  12225.                       return(y);
  12226.                     break;
  12227.                   case XYKRBPRE:
  12228.                     if (kv == 4) {
  12229.                         if ((y = seton(&krb4_d_preauth)) < 0)
  12230.                           return(y);
  12231.                     } else {
  12232.                         return(-9);
  12233.                     }
  12234.                     break;
  12235.                   case XYKRBINS:
  12236.                     if ((y = cmtxt("Instance name","",&s,xxstring)) < 0)
  12237.                       return(y);
  12238.                     break;
  12239.                   case XYKRBFWD:
  12240.                     if (kv == 5) {
  12241.                         if ((y = seton(&krb5_d_forwardable)) < 0)
  12242.                           return(y);
  12243.                     } else {
  12244.                         return(-9);
  12245.                     }
  12246.                     break;
  12247.                   case XYKRBPRX:
  12248.                     if (kv == 5) {
  12249.                         if ((y = seton(&krb5_d_proxiable)) < 0)
  12250.                           return(y);
  12251.                     } else {
  12252.                         return(-9);
  12253.                     }
  12254.                     break;
  12255.                   case XYKRBRNW:
  12256.                     if ((y = cmnum("TGT renewable lifetime",
  12257.                                    "0",10,&z,xxstring)) < 0)
  12258.                       return(y);
  12259.                     break;
  12260.                   case XYKRBADR:
  12261.                     if (kv == 5) {
  12262.                         if ((y = seton(&krb5_checkaddrs)) < 0)
  12263.                           return(y);
  12264.                     } else {
  12265.                         if ((y = seton(&krb4_checkaddrs)) < 0)
  12266.                           return(y);
  12267.                     }
  12268.                     break;
  12269.                   case XYKRBNAD:
  12270.                     if (kv == 5) {
  12271.                         if ((y = seton(&krb5_d_no_addresses)) < 0)
  12272.                           return(y);
  12273.                     }
  12274.                     break;
  12275.                   case XYKRBADD:
  12276.                     if (kv == 5) {
  12277.                         char * tmpaddrs[KRB5_NUM_OF_ADDRS];
  12278.                         for (i = 0; i < KRB5_NUM_OF_ADDRS; i++)
  12279.                           tmpaddrs[i] = NULL;
  12280.  
  12281.                         if ((y =
  12282.                              cmfld("List of IP addresses","",&s,xxstring)) < 0)
  12283.                           return(y);
  12284.                         makelist(s,tmpaddrs,KRB5_NUM_OF_ADDRS);
  12285.                         if ((y = cmcfm()) < 0) {
  12286.                             for (i = 0; i < KRB5_NUM_OF_ADDRS; i++) {
  12287.                                 if (tmpaddrs[i] != NULL)
  12288.                                   free(tmpaddrs[i]);
  12289.                             }
  12290.                             return(y);
  12291.                         }
  12292.                         for (i = 0;
  12293.                              i < KRB5_NUM_OF_ADDRS && tmpaddrs[i];
  12294.                              i++) {
  12295.                             if (inet_addr(tmpaddrs[i]) == 0xffffffff) {
  12296.                                 printf("invalid ip address: %s\n",
  12297.                                        tmpaddrs[i]);
  12298.                                 for (i = 0; i < KRB5_NUM_OF_ADDRS; i++) {
  12299.                                     if (tmpaddrs[i] != NULL)
  12300.                                       free(tmpaddrs[i]);
  12301.                                 }
  12302.                                 return(-9);
  12303.                             }
  12304.                         }
  12305.                         for (i = 0;
  12306.                              i < KRB5_NUM_OF_ADDRS && krb5_d_addrs[i];
  12307.                              i++) {
  12308.                             if (krb5_d_addrs[i])
  12309.                               free(krb5_d_addrs[i]);
  12310.                             krb5_d_addrs[i] = NULL;
  12311.                         }
  12312.                         for (i = 0;
  12313.                              i < KRB5_NUM_OF_ADDRS && tmpaddrs[i];
  12314.                              i++) {
  12315.                             krb5_d_addrs[i] = tmpaddrs[i];
  12316.                             tmpaddrs[i] = NULL;
  12317.                         }
  12318.                         krb5_d_addrs[i] = NULL;
  12319.                         return(success = 1);
  12320.                     }
  12321.                     break;
  12322.  
  12323.                   case XYKRBGET:
  12324.                     if (kv == 5) {
  12325.                         if ((y = seton(&krb5_autoget)) < 0)
  12326.                           return(y);
  12327.                     } else {
  12328.                         if ((y = seton(&krb4_autoget)) < 0)
  12329.                           return(y);
  12330.                     }
  12331.                     break;
  12332.                   case XYKRBDEL:
  12333.                     if ((z = cmkey(kdestab,nkdestab,
  12334.                                    "Auto Destroy Tickets",
  12335.                                    "never",xxstring)) < 0)
  12336.                       return(z);
  12337.                     break;
  12338.                   case XYKRBPR:
  12339.                     if ((y = cmtxt("User ID",uidbuf,&s,xxstring)) < 0)
  12340.                       return(y);
  12341.                     break;
  12342.                   case XYKRBRL:
  12343.                     if ((y = cmtxt("Name of realm","",&s,xxstring)) < 0)
  12344.                       return(y);
  12345.                     break;
  12346.                   case XYKRBKTB:
  12347.                     y = cmifi("Filename","",&s,&z,xxstring);
  12348.                     if (y != -3) {
  12349.                        if (y < 0)
  12350.                          return(y);
  12351.                        if (z) {
  12352.                          printf("?Wildcards not allowed\n");
  12353.                          return(-9);
  12354.                        }
  12355.                     }
  12356.                     break;
  12357.                   case XYKRBCC:
  12358.                     if ((y = cmofi("Filename","",&s,xxstring)) < 0)
  12359.                       return(y);
  12360.                     break;
  12361.                   case XYKRBSRV:
  12362.                     if ((y = cmtxt("Name of service to use in ticket",
  12363.                                    (kv == 4 ? "rcmd" : "host"),
  12364.                                    &s,
  12365.                                    xxstring
  12366.                                    )) < 0)
  12367.                       return(y);
  12368.                     break;
  12369.                   case XYKRBK5K4:
  12370.                     if (kv == 5) {
  12371.                         if ((y = seton(&krb5_d_getk4)) < 0)
  12372.                           return(y);
  12373.                     } else {
  12374.                         return(-9);
  12375.                     }
  12376.                     break;
  12377.                   case XYKRBPRM:        /* Prompt */
  12378.                     if ((z = cmkey(krbprmtab,2,"","",xxstring)) < 0)
  12379.                       return(z);
  12380.                     if ((y = cmtxt((z == KRB_PW_PRM) ?
  12381.   "Text of prompt;\nmay contain \"%s\" to be replaced by principal name" :
  12382.   "Text of prompt",
  12383.                                    "",
  12384.                                    &s,
  12385.                                    xxstring
  12386.                                    )
  12387.                          ) < 0)
  12388.                       return(y);
  12389.                     break;
  12390.                 }
  12391.                 ckstrncpy(line,s,LINBUFSIZ);
  12392.                 s = line;
  12393.                 if ((y = cmcfm()) < 0)
  12394.                   return(y);
  12395. #ifdef IKSD
  12396.                 if (inserver &&
  12397. #ifdef IKSDCONF
  12398.                     iksdcf
  12399. #else /* IKSDCONF */
  12400.                     1
  12401. #endif /* IKSDCONF */
  12402.                     )
  12403.                   return(success = 0);
  12404. #endif /* IKSD */
  12405.  
  12406.                 switch (x) {            /* Copy value to right place */
  12407.                   case XYKRBLIF:        /* Lifetime */
  12408.                     if (kv == 4)
  12409.                       krb4_d_lifetime = z;
  12410.                     else
  12411.                       krb5_d_lifetime = z;
  12412.                     break;
  12413.                   case XYKRBRNW:
  12414.                     if (kv == 5)
  12415.                       krb5_d_renewable = z;
  12416.                     break;
  12417.                   case XYKRBPR:         /* Principal */
  12418.                     s = brstrip(s);    /* Strip braces around. */
  12419.                     if (kv == 4)
  12420.                       makestr(&krb4_d_principal,s);
  12421.                     else
  12422.                       makestr(&krb5_d_principal,s);
  12423.                     break;
  12424.                   case XYKRBINS:        /* Instance */
  12425.                     if (kv == 4)
  12426.                       makestr(&krb4_d_instance,s);
  12427.                     else
  12428.                       makestr(&krb5_d_instance,s);
  12429.                     break;
  12430.                   case XYKRBRL:         /* Realm */
  12431.                     if (kv == 4)
  12432.                       makestr(&krb4_d_realm,s);
  12433.                     else
  12434.                       makestr(&krb5_d_realm,s);
  12435.                     break;
  12436.                   case XYKRBKTB:        /* Key Table */
  12437.                     if (kv == 4)
  12438.                       makestr(&k4_keytab,s);
  12439.                     else
  12440.                       makestr(&k5_keytab,s);
  12441.                     break;
  12442.                   case XYKRBCC:         /* Credentials cache */
  12443.                     makestr(&krb5_d_cc,s);
  12444.                     break;
  12445.                   case XYKRBSRV:        /* Service Name */
  12446.                     if (kv == 4)
  12447.                       makestr(&krb4_d_srv,s);
  12448.                     else
  12449.                       makestr(&krb5_d_srv,s);
  12450.                     break;
  12451.                   case XYKRBDEL:
  12452.                     if (kv == 5)
  12453.                       krb5_autodel = z;
  12454.                     else
  12455.                       krb4_autodel = z;
  12456.                     break;
  12457.                   case XYKRBPRM:        /* Prompt */
  12458.                     if (s == "") s = NULL;
  12459.                     if (s) {
  12460.                         s = brstrip(s);
  12461.                         if (s == "") s = NULL;
  12462.                     }
  12463.                     switch (z) {
  12464.                       case KRB_PW_PRM: { /* Password */
  12465.                           /* Check that there are no more than */
  12466.                           /* two % fields and % must followed by 's'. */
  12467.                           int i,n,len;
  12468.                           len = strlen(s);
  12469.                           for (i = 0, n = 0; i < len; i++) {
  12470.                               if (s[i] == '%') {
  12471.                                   if (s[i+1] != '%') {
  12472.                                       if (s[i+1] != 's') {
  12473.                                           printf(
  12474.                                            "Only %%s fields are permitted.\n"
  12475.                                                  );
  12476.                                           return(-9);
  12477.                                       }
  12478.                                       if (++n > 2) {
  12479.                                           printf(
  12480.                                       "Only two %%s fields are permitted.\n");
  12481.                                           return(-9);
  12482.                                       }
  12483.                                   }
  12484.                                   i++;
  12485.                               }
  12486.                           }
  12487.                           if (kv == 5)
  12488.                             makestr(&k5pwprompt,s);
  12489.                           else
  12490.                             makestr(&k4pwprompt,s);
  12491.                           break;
  12492.                       }
  12493.                       case KRB_PR_PRM: { /* Principal */
  12494.                           /* Check to make sure there are no % fields */
  12495.                           int i,len;
  12496.                           len = strlen(s);
  12497.                           for (i = 0; i < len; i++) {
  12498.                               if (s[i] == '%') {
  12499.                                   if (s[i+1] != '%') {
  12500.                                       printf(
  12501.                                   "%% fields are not used in this command.\n");
  12502.                                       return(-9);
  12503.                                   }
  12504.                                   i++;
  12505.                               }
  12506.                           }
  12507.                           if (kv == 5)
  12508.                             makestr(&k5prprompt,s);
  12509.                           else
  12510.                             makestr(&k4prprompt,s);
  12511.                           break;
  12512.                       }
  12513.                     }
  12514.                 }
  12515.                 break;
  12516.             }
  12517. #endif /* CK_KERBEROS */
  12518. #ifdef CK_SRP
  12519.             case AUTH_SRP: {
  12520.                 if ((x = cmkey(srptab, nsrptab,
  12521.                                "SRP parameter","",xxstring)) < 0) {
  12522.                     return(x);
  12523.                 }
  12524.                 s = "";
  12525.                 switch (x) {
  12526.                   case XYSRPPRM:        /* Prompt */
  12527.                     if ((z = cmkey(srpprmtab,1,"","",xxstring)) < 0)
  12528.                       return(z);
  12529.                     if ((y = cmtxt(
  12530.   "Text of prompt;\nmay contain one \"%s\" to be replaced by the username",
  12531.                                    "",
  12532.                                    &s,
  12533.                                    xxstring
  12534.                                    )
  12535.                          ) < 0)
  12536.                       return(y);
  12537.                     break;
  12538.                 }
  12539.                 ckstrncpy(line,s,LINBUFSIZ);
  12540.                 s = line;
  12541.                 if ((y = cmcfm()) < 0)
  12542.                   return(y);
  12543.                 switch (x) {            /* Copy value to right place */
  12544.                   case XYSRPPRM:        /* Prompt */
  12545.                     if (s == "") s = NULL;
  12546.                     if (s) {
  12547.                         s = brstrip(s);
  12548.                         if (s == "") s = NULL;
  12549.                     }
  12550.                     switch (z) {
  12551.                       case SRP_PW_PRM: { /* Password */
  12552.                           /* Check %s fields */
  12553.                           int i,n,len;
  12554.                           len = strlen(s);
  12555.                           for (i = 0, n = 0; i < len; i++) {
  12556.                               if (s[i] == '%') {
  12557.                                   if (s[i+1] != '%') {
  12558.                                       if (s[i+1] != 's') {
  12559.                                           printf(
  12560.                                           "Only %%s fields are permitted.\n");
  12561.                                           return(-9);
  12562.                                       }
  12563.                                       if (++n > 1) {
  12564.                                           printf(
  12565.                                        "Only one %%s field is permitted.\n");
  12566.                                           return(-9);
  12567.                                       }
  12568.                                   }
  12569.                                   i++;
  12570.                               }
  12571.                           }
  12572.                           makestr(&srppwprompt,s);
  12573.                           break;
  12574.                       }
  12575.                     }
  12576.                 }
  12577.                 break;
  12578.             }
  12579. #endif /* CK_SRP */
  12580. #ifdef CK_SSL
  12581.             case AUTH_SSL:
  12582.             case AUTH_TLS: {
  12583.                 if ((z = cmkey(ssltab, nssltab,
  12584.                            (x == AUTH_SSL ? "SSL parameter" : "TLS parameter"),
  12585.                            "",xxstring)) < 0)
  12586.                   return(z);
  12587.                 s = "";
  12588.                 switch (z) {
  12589.                   case XYSSLRCFL:       /* SSL/TLS RSA Certs file */
  12590.                   case XYSSLRCCF:       /* SSL/TLS RSA Certs Chain file */
  12591.                   case XYSSLRKFL:       /* SSL/TLS RSA Key File */
  12592.                   case XYSSLDCFL:       /* SSL/TLS DSA Certs file */
  12593.                   case XYSSLDCCF:       /* SSL/TLS DSA Certs Chain file */
  12594.                   case XYSSLDKFL:       /* SSL/TLS DH Key File */
  12595.                   case XYSSLDPFL:       /* SSL/TLS DH Param File */
  12596.                   case XYSSLCRL:        /* SSL/TLS CRL File */
  12597.                   case XYSSLVRFF:       /* SSL/TLS Verify File */
  12598.                   case XYSSLRND:        /* SSL/TLS Random File */
  12599.                     y = cmifi("Filename","",&s,&x,xxstring);
  12600.                     if (y != -3) {
  12601.                         if (y < 0)
  12602.                           return(y);
  12603.                         if (x) {
  12604.                             printf("?Wildcards not allowed\n");
  12605.                             return(-9);
  12606.                         }
  12607.                     }
  12608.                     ckstrncpy(line,s,LINBUFSIZ);
  12609.                     s = line;
  12610.                     s = brstrip(s);
  12611.                     if ((y = cmcfm()) < 0)
  12612.                       return(y);
  12613.                     switch (z) {
  12614.                       case XYSSLRCFL:   /* SSL/TLS RSA Certs file */
  12615.                         if (!s[0] && ssl_rsa_cert_file) {
  12616.                             free(ssl_rsa_cert_file);
  12617.                             ssl_rsa_cert_file = NULL;
  12618.                         } else if (s[0]) {
  12619.                             makestr(&ssl_rsa_cert_file,s);
  12620.                             if (!ssl_rsa_key_file)
  12621.                               makestr(&ssl_rsa_key_file,s);
  12622.                         }
  12623.                         break;
  12624.                       case XYSSLRCCF:   /* SSL/TLS RSA Certs Chain file */
  12625.                           if (!s[0] && ssl_rsa_cert_chain_file) {
  12626.                               free(ssl_rsa_cert_chain_file);
  12627.                               ssl_rsa_cert_chain_file = NULL;
  12628.                           } else if (s[0]) {
  12629.                               makestr(&ssl_rsa_cert_chain_file,s);
  12630.                           }
  12631.                           break;
  12632.                       case XYSSLRKFL:   /* SSL/TLS RSA Key File */
  12633.                         if (!s[0] && ssl_rsa_key_file) {
  12634.                             free(ssl_rsa_key_file);
  12635.                             ssl_rsa_key_file = NULL;
  12636.                         } else if (s[0]) {
  12637.                             makestr(&ssl_rsa_key_file,s);
  12638.                         }
  12639.                         break;
  12640.                       case XYSSLDCFL:   /* SSL/TLS DSA Certs file */
  12641.                         if (!s[0] && ssl_dsa_cert_file) {
  12642.                             free(ssl_dsa_cert_file);
  12643.                             ssl_dsa_cert_file = NULL;
  12644.                         } else if (s[0]) {
  12645.                             makestr(&ssl_dsa_cert_file,s);
  12646.                             if (!ssl_dh_key_file)
  12647.                               makestr(&ssl_dh_key_file,s);
  12648.                         }
  12649.                         break;
  12650.                       case XYSSLDCCF:   /* SSL/TLS DSA Certs Chain file */
  12651.                           if (!s[0] && ssl_dsa_cert_chain_file) {
  12652.                               free(ssl_dsa_cert_chain_file);
  12653.                               ssl_dsa_cert_chain_file = NULL;
  12654.                           } else if (s[0]) {
  12655.                               makestr(&ssl_dsa_cert_chain_file,s);
  12656.                           }
  12657.                           break;
  12658.                       case XYSSLDKFL:   /* SSL/TLS DH Key File */
  12659.                         if (!s[0] && ssl_dh_key_file) {
  12660.                             free(ssl_dh_key_file);
  12661.                             ssl_dh_key_file = NULL;
  12662.                         } else if (s[0]) {
  12663.                             makestr(&ssl_dh_key_file,s);
  12664.                         }
  12665.                         break;
  12666.                       case XYSSLDPFL:   /* SSL/TLS DH Param File */
  12667.                         if (!s[0] && ssl_dh_param_file) {
  12668.                             free(ssl_dh_param_file);
  12669.                             ssl_dh_param_file = NULL;
  12670.                         } else if (s[0]) {
  12671.                             makestr(&ssl_dh_param_file,s);
  12672.                         }
  12673.                         break;
  12674.                       case XYSSLCRL:    /* SSL/TLS CRL File */
  12675.                         if (!s[0] && ssl_crl_file) {
  12676.                             free(ssl_crl_file);
  12677.                             ssl_crl_file = NULL;
  12678.                         } else if (s[0]) {
  12679.                             makestr(&ssl_crl_file,s);
  12680.                         }
  12681.                         break;
  12682.                       case XYSSLVRFF:   /* SSL/TLS Verify File */
  12683.                         if (!s[0] && ssl_verify_file) {
  12684.                             free(ssl_verify_file);
  12685.                             ssl_verify_file = NULL;
  12686.                         } else if (s[0]) {
  12687.                             makestr(&ssl_verify_file,s);
  12688.                         }
  12689.                         break;
  12690.                       case XYSSLRND:    /* SSL/TLS Random File */
  12691.                         if (!s[0] && ssl_rnd_file) {
  12692.                             free(ssl_rnd_file);
  12693.                             ssl_rnd_file = NULL;
  12694.                         } else if (s[0]) {
  12695.                             makestr(&ssl_rnd_file,s);
  12696.                         }
  12697.                         break;
  12698.                     }
  12699.                     break;
  12700.  
  12701.                   case XYSSLCRLD:
  12702.                   case XYSSLVRFD: {
  12703.                     char * d = NULL;
  12704.                     if (z == XYSSLVRFD)
  12705.                       d= getenv("SSL_CERT_DIR");
  12706.                     if (d == NULL)
  12707.                         d = "";
  12708.                     if ((y = cmdir("Directory",d,&s,xxstring)) < 0)
  12709.               if (y != -3)
  12710.             return(y);
  12711.                     ckstrncpy(line,s,LINBUFSIZ);
  12712.                     s = line;
  12713.                     s = brstrip(s);
  12714.                     if ((y = cmcfm()) < 0)
  12715.                       return(y);
  12716.                     switch(z) {
  12717.                       case XYSSLCRLD:
  12718.                         if (!s[0] && ssl_crl_dir) {
  12719.                             free(ssl_crl_dir);
  12720.                             ssl_crl_dir = NULL;
  12721.                         } else if (s[0]) {
  12722.                             makestr(&ssl_crl_dir,s);
  12723.                         }
  12724.                         break;
  12725.                       case XYSSLVRFD:
  12726.                         if (!s[0] && ssl_verify_dir) {
  12727.                             free(ssl_verify_dir);
  12728.                             ssl_verify_dir = NULL;
  12729.                         } else if (s[0]) {
  12730.                             makestr(&ssl_verify_dir,s);
  12731.                         }
  12732.                         break;
  12733.                     }
  12734.                     break;
  12735.                   }
  12736.                   case XYSSLCOK:        /* SSL/TLS Certs-Ok flag */
  12737.                     if ((y = seton(&ssl_certsok_flag)) < 0)
  12738.                       return(y);
  12739.                     break;
  12740.                   case XYSSLDBG:                /* SSL/TLS Debug flag */
  12741.                     if ((y = seton(&ssl_debug_flag)) < 0)
  12742.                       return(y);
  12743.                     break;
  12744.                   case XYSSLON:         /* SSL/TLS Only flag */
  12745.                     switch (x) {
  12746.                       case AUTH_SSL:
  12747.                         if ((y = seton(&ssl_only_flag)) < 0)
  12748.                           return(y);
  12749.                         break;
  12750.                       case AUTH_TLS:
  12751.                         if ((y = seton(&tls_only_flag)) < 0)
  12752.                           return(y);
  12753.                         break;
  12754.                     }
  12755.                     break;
  12756.                   case XYSSLVRB:        /* SSL/TLS Verbose flag */
  12757.                     if ((y = seton(&ssl_verbose_flag)) < 0)
  12758.                       return(y);
  12759.                     break;
  12760.                   case XYSSLVRF:        /* SSL/TLS Verify flag */
  12761.                     if ((x = cmkey(sslvertab, nsslvertab,
  12762.                                    "SSL/TLS verify mode",
  12763.                                    "peer-cert",xxstring)) < 0)
  12764.                       return(x);
  12765.                     if ((y = cmcfm()) < 0)
  12766.                       return(y);
  12767.                     ssl_verify_flag = x;
  12768.                     break;
  12769.                   case XYSSLDUM:
  12770.                     if ((y = seton(&ssl_dummy_flag)) < 0)
  12771.                       return(y);
  12772.                     break;
  12773.                   case XYSSLCL: {               /* SSL/TLS Cipher List */
  12774. #ifdef COMMENT
  12775.                       /* This code is used to generate a colon delimited */
  12776.                       /* list of the ciphers currently in use to be used */
  12777.                       /* as the default for cmtxt().  However, a better  */
  12778.                       /* default is simply the magic keyword "ALL".      */
  12779.                       CHAR def[1024] = "";
  12780.                       if (ssl_con != NULL) {
  12781.                           CHAR * p = NULL, *q = def;
  12782.                           int i, len;
  12783.  
  12784.                           for (i = 0; ; i++) {
  12785.                               p = (CHAR *) SSL_get_cipher_list(ssl_con,i);
  12786.                               if (p == NULL)
  12787.                                 break;
  12788.                               len = strlen(p);
  12789.                               if (q+len+1 >= def+1024)
  12790.                                 break;
  12791.                               if (i != 0)
  12792.                                 *q++ = ':';
  12793.                               strcpy(q,p);
  12794.                               q += len;
  12795.                           }
  12796.                       }
  12797. #endif /* COMMENT */
  12798.                       char * p = getenv("SSL_CIPHER");
  12799.                       if (!p)
  12800.                         p = "ALL";
  12801.                       if ((y = cmtxt(
  12802.                     "Colon-delimited list of ciphers or ALL (case-sensitive)",
  12803.                                      p,
  12804.                                      &s,
  12805.                                      xxstring
  12806.                                      )
  12807.                            ) < 0)
  12808.                         return(y);
  12809.                       makestr(&ssl_cipher_list,s);
  12810.                       if (ssl_con == NULL) {
  12811.                           SSL_library_init();
  12812.                           ssl_ctx = (SSL_CTX *)
  12813.                             SSL_CTX_new((SSL_METHOD *)TLSv1_method());
  12814.                           if (ssl_ctx != NULL)
  12815.                             ssl_con= (SSL *) SSL_new(ssl_ctx);
  12816.                       }
  12817.                       if (ssl_con) {
  12818.                           SSL_set_cipher_list(ssl_con,ssl_cipher_list);
  12819.                       }
  12820.                       break;
  12821.                   }
  12822.                 }
  12823.                 break;
  12824.             }
  12825. #endif /* CK_SSL */
  12826.             default:
  12827.               break;
  12828.           }
  12829.           return(success = 1);
  12830.       }
  12831. #endif /* CK_AUTHENTICATION */
  12832.  
  12833. #ifndef NOSPL
  12834.       case XYFUNC:
  12835.         if ((x = cmkey(functab,nfunctab,"","diagnostics",xxstring)) < 0)
  12836.           return(x);
  12837.         switch (x) {
  12838.           case FUNC_DI: return(seton(&fndiags));
  12839.           case FUNC_ER: return(seton(&fnerror));
  12840.           default:      return(-2);
  12841.         }
  12842. #endif /* NOSPL */
  12843.  
  12844.       case XYSLEEP:                     /* SET SLEEP / PAUSE */
  12845.         if ((x = cmkey(sleeptab,1,"","cancellation",xxstring)) < 0)
  12846.           return(x);
  12847.         return(seton(&sleepcan));
  12848.  
  12849.       case XYCD:                        /* SET CD */
  12850.         if ((x = cmkey(cdtab,ncdtab,"","",xxstring)) < 0)
  12851.           return(x);
  12852.         switch (x) {
  12853.       case XYCD_H: {        /* SET CD HOME */
  12854.           extern char * myhome;
  12855.           if ((y = cmdir("Directory name",zhome(),&s,xxstring)) < 0)
  12856.         return(y);
  12857.           makestr(&myhome,s);
  12858.           return(success = 1);
  12859.       }
  12860.           case XYCD_M:                  /* SET CD MESSAGE */
  12861.             if ((x = cmkey(cdmsg,ncdmsg,"","",xxstring)) < 0)
  12862.               return(x);
  12863.             if (x == 2) {               /* CD MESSAGE FILE */
  12864.                 if ((x = cmtxt("Name of file","",&s,NULL)) < 0)
  12865.                   return(x);
  12866.                 if (!*s) {
  12867.                     s = NULL;
  12868. #ifndef NOXFER
  12869.                     srvcdmsg = 0;
  12870. #endif /* NOXFER */
  12871.                 }
  12872.                 makestr(&cdmsgstr,s);
  12873.                 makelist(cdmsgstr,cdmsgfile,8);
  12874.                 return(success = 1);
  12875.             }
  12876.  
  12877.             if ((y = cmcfm()) < 0) return(y); /* CD-MESSAGE ON/OFF */
  12878. #ifndef NOXFER
  12879.             if (x > 0)
  12880.               srvcdmsg |= 2;
  12881.             else
  12882.               srvcdmsg &= 1;
  12883. #endif /* NOXFER */
  12884.             return(success = 1);
  12885.  
  12886.           case XYCD_P: {                /* SET CD PATH */
  12887.               extern char * ckcdpath;
  12888.               if ((x = cmtxt("CD PATH string","",&s,xxstring)) < 0)
  12889.                 return(x);
  12890.               makestr(&ckcdpath,s);
  12891.               return(success = 1);
  12892.           }
  12893.         }
  12894.  
  12895. #ifndef NOLOCAL
  12896. #ifdef STOPBITS
  12897.       case XYSTOP:                      /* STOP-BITS */
  12898.         if ((x = cmkey(stoptbl,2,"Stop bits for serial device","",
  12899.                        xxstring)) < 0)
  12900.           return(x);
  12901.         if ((y = cmcfm()) < 0)
  12902.           return(y);
  12903.         if (x > 0 && x < 3) {
  12904.             stopbits = x;
  12905. #ifdef TN_COMPORT
  12906.             if (network && istncomport()) {
  12907.                 tnsettings(-1, x);
  12908.                 return(success = 1);
  12909.             }
  12910. #endif /* TN_COMPORT */
  12911. #ifdef HWPARITY
  12912.             return(success = 1);
  12913. #else /* HWPARITY */
  12914.             return(-2);
  12915. #endif /* HWPARITY */
  12916.         } else
  12917.           return(-2);
  12918. #endif /* STOPBITS */
  12919.  
  12920.       case XYDISC: {
  12921.           extern int clsondisc;
  12922.           return(seton(&clsondisc));
  12923.       }
  12924.  
  12925.       case XYSERIAL: {
  12926.           /* char c; */
  12927.           extern int cmask;
  12928.           if ((x = cmkey(sertbl,nsertbl,
  12929.                          "Serial device character size, parity, and stop bits",
  12930.                          "8N1", xxstring)) < 0)
  12931.             return(x);
  12932.           ckstrncpy(line,atmbuf,LINBUFSIZ); /* Associated keyword string */
  12933.           s = line;
  12934.           if ((y = cmcfm()) < 0)
  12935.             return(y);
  12936.           ckstrncpy(line,sernam[x],LINBUFSIZ);
  12937.           s = line;
  12938.           if (s[0] != '8' && s[0] != '7') /* Char size */
  12939.             return(-2);
  12940.           else
  12941.             z = s[0] - '0';
  12942.           if (isupper(s[1]))            /* Parity */
  12943.             s[1] = tolower(s[1]);
  12944.           if (s[2] != '1' && s[2] != '2') /* Stop bits */
  12945.             return(-2);
  12946.           else
  12947.             stopbits = s[2] - '0';
  12948.           if (z == 8) {                 /* 8 bits + parity (or not) */
  12949.               parity = 0;               /* Set parity */
  12950.               hwparity = (s[1] == 'n') ? 0 : s[1];
  12951.               setcmask(8);              /* Also set TERM BYTESIZE to 8 */
  12952.           } else {                      /* 7 bits plus parity */
  12953.               parity = (s[1] == 'n') ? 0 : s[1];
  12954.               hwparity = 0;
  12955.               setcmask(7);              /* Also set TERM BYTESIZE to 7 */
  12956.           }
  12957. #ifdef TN_COMPORT
  12958.           if (network && !istncomport())
  12959.             tnsettings(parity, stopbits);
  12960. #endif /* TN_COMPORT */
  12961.  
  12962.           return(success = 1);          /* from SET SERIAL */
  12963.       }
  12964.  
  12965.       case XYOPTS: {                    /* SET OPTIONS */
  12966.           extern int setdiropts();
  12967.           extern int settypopts();
  12968. #ifdef CKPURGE
  12969.           extern int setpurgopts();
  12970. #endif /* CKPURGE */
  12971.           if ((x = cmkey(optstab,noptstab,"for command","", xxstring)) < 0)
  12972.             return(x);
  12973.           switch (x) {
  12974. #ifndef NOFRILLS
  12975.             case XXDEL:
  12976.               return(setdelopts());
  12977. #endif /* NOFRILLS */
  12978.             case XXDIR:
  12979.               return(setdiropts());
  12980.             case XXTYP:
  12981.               return(settypopts());
  12982. #ifdef CKPURGE
  12983.             case XXPURGE:
  12984.               return(setpurgopts());
  12985. #endif /* CKPURGE */
  12986.             default:
  12987.               return(-2);
  12988.           }
  12989.       }
  12990. #endif /* NOLOCAL */
  12991. #ifndef NOXFER
  12992.       case XYQ8FLG: {
  12993.           extern int q8flag;
  12994.           return(seton(&q8flag));
  12995.       }
  12996.       case XYTIMER: {
  12997.           extern int asktimer;
  12998.           y = cmnum("Time limit for ASK command, seconds","0",10,&x,xxstring);
  12999. #ifdef QNX16
  13000.           return(setnum(&asktimer,x,y,32767));
  13001. #else
  13002.           return(setnum(&asktimer,x,y,86400));
  13003. #endif /* QNX16 */
  13004.       }
  13005.       case XYFACKB: {
  13006.           extern int fackbug;
  13007.           return(seton(&fackbug));
  13008.       }
  13009. #endif /* NOXFER */
  13010.  
  13011.       case XYHINTS:
  13012.         return(seton(&hints));
  13013.  
  13014. #ifndef NOSPL
  13015.       case XYEVAL: {
  13016.           extern int oldeval;
  13017.           if ((x = cmkey(oldnew,2,"","", xxstring)) < 0)
  13018.             return(x);
  13019.           if ((y = cmcfm()) < 0)
  13020.             return(y);
  13021.           oldeval = x;
  13022.           return(success = 1);
  13023.       }
  13024. #endif /* NOSPL */
  13025.  
  13026. #ifndef NOXFER
  13027.       case XYFACKP: {
  13028.           extern int fackpath;
  13029.           return(seton(&fackpath));
  13030.       }
  13031. #endif /* NOXFER */
  13032.  
  13033.       case XYQNXPL: {
  13034.           extern int qnxportlock;
  13035.           return(seton(&qnxportlock));
  13036.       }
  13037.  
  13038. #ifndef NOCMDL
  13039. #ifdef IKSD
  13040.       case XYIKS: {
  13041.           int setiks();
  13042.           return(setiks());
  13043.       }
  13044. #endif /* IKSD */
  13045. #endif /* NOCMDL */
  13046.  
  13047. #ifdef CKROOT
  13048.       case XYROOT:
  13049.         return(dochroot());
  13050. #endif /* CKROOT */
  13051.  
  13052. #ifndef NOSPL
  13053. #ifndef NOSEXP
  13054.       case XYSEXP: {
  13055.           if ((x = cmkey(sexptab,2,"","", xxstring)) < 0)
  13056.             return(x);
  13057.           switch (x) {
  13058.             case 0:
  13059.               if ((x = cmkey(ooatab,3,"","automatic", xxstring)) < 0)
  13060.                 return(x);
  13061.               if ((y = cmcfm()) < 0)
  13062.                 return(y);
  13063.               sexpecho = x;
  13064.               break;
  13065.             case 1: {
  13066.                 int i, xx;
  13067.                 xx = sexpmaxdep;
  13068.                 if ((y = cmnum("Maximum recursion depth",
  13069.                                "1000",10,&x,xxstring)) < 0)
  13070.                   return(y);
  13071.                 z = setnum(&sexpmaxdep,x,y,-1);
  13072.                 if (z < 0)
  13073.                   return(z);
  13074.                 if (sxresult) {         /* Free old stack if allocated */
  13075.                     for (i = 0; i < xx; i++)
  13076.                       if (sxresult[i]) free(sxresult[i]);
  13077.                     free((char *)sxresult);
  13078.                     if (sxrlen) free((char *)sxrlen);
  13079.                     sxresult = NULL;
  13080.                     sxrlen = NULL;
  13081.                 }
  13082.                 break;
  13083.             }
  13084.           }
  13085.           return(success = 1);
  13086.       }
  13087. #endif /* NOSEXPL */
  13088. #endif /* NOSPL */
  13089.  
  13090. #ifdef NEWFTP
  13091.       case XYGPR: {
  13092.           extern struct keytab gprtab[];
  13093.           extern int ftpget;
  13094.           if ((x = cmkey(gprtab,3,"","kermit", xxstring)) < 0)
  13095.             return(x);
  13096.           if ((y = cmcfm()) < 0)
  13097.             return(y);
  13098.           ftpget = x;
  13099.           return(success = 1);
  13100.       }
  13101. #endif /* NEWFTP */
  13102.  
  13103. #ifdef ANYSSH
  13104.       case XYSSH:
  13105.         return(dosetssh());
  13106. #endif /* ANYSHH */
  13107.  
  13108. #ifdef SFTP_BUILTIN
  13109.       case XYSFTP:
  13110.         return(dosetsftp());
  13111. #endif /* SFTP_BUILTIN */
  13112.  
  13113. #ifdef LOCUS
  13114.       case XYLOCUS:
  13115.           if ((x = cmkey(locustab,nlocustab,"",
  13116. #ifdef KUI
  13117.              "ask"
  13118. #else
  13119.              "auto"
  13120. #endif /* KUI */
  13121.              ,xxstring)) < 0)
  13122.             return(x);
  13123.           if ((y = cmcfm()) < 0)
  13124.             return(y);
  13125.           if (x == 2 || x == 3) {    /* AUTO or ASK */
  13126.               setautolocus(x - 1);    /* Two forms of automatic locusing */
  13127.           /* setlocus(1,0); */      /* we're not changing the locus here */
  13128.           } else {            /* LOCAL or REMOTE */
  13129.               setautolocus(0);        /* No automatic Locus changing */
  13130.               setlocus(x,0);        /* Set Locus as requested */
  13131.           }
  13132.           return(success = 1);
  13133. #endif /* LOCUS */
  13134.  
  13135. #ifdef KUI
  13136.       case XYGUI:
  13137.         return(setgui());
  13138. #endif /* KUI */
  13139.  
  13140.       default:
  13141.          if ((x = cmcfm()) < 0) return(x);
  13142.          printf("Not implemented - %s\n",cmdbuf);
  13143.          return(success = 0);
  13144.     }
  13145. }
  13146.  
  13147. /*
  13148.   H U P O K  --  Is Hangup OK?
  13149.  
  13150.   Issues a warning and gets OK from user depending on whether a connection
  13151.   seems to be open and what the SET EXIT WARNING setting is.  Returns:
  13152.     0 if not OK to hang up or exit (i.e. user said No);
  13153.     nonzero if OK.
  13154.   Argument x is used to differentiate the EXIT command from SET LINE / HOST.
  13155. */
  13156. int
  13157. hupok(x) int x; {                       /* Returns 1 if OK, 0 if not OK */
  13158.     int y, z = 1;
  13159.     extern int exithangup;
  13160. #ifdef VMS
  13161.     extern int batch;
  13162.  
  13163.     if (batch)                          /* No warnings in batch */
  13164.       return(1);
  13165. #else
  13166. #ifdef UNIX
  13167.     if (backgrd)                        /* No warnings in background */
  13168.       return(1);
  13169. #endif /* UNIX */
  13170. #endif /* VMS */
  13171.  
  13172. #ifndef K95G
  13173.     debug(F101,"hupok local","",local);
  13174.  
  13175.     if (!local)                         /* No warnings in remote mode */
  13176.       return(1);
  13177. #endif /* K95G */
  13178.  
  13179.     if (x == 0 && exithangup == 0)      /* EXIT and EXIT HANGUP is OFF */
  13180.       return(1);
  13181.  
  13182.     debug(F101,"hupok x","",x);
  13183.     debug(F101,"hupok xitwarn","",xitwarn);
  13184.     debug(F101,"hupok network","",network);
  13185.     debug(F101,"hupok haveline","",haveline);
  13186.  
  13187.     if ((local && xitwarn) ||           /* Is a connection open? */
  13188.         (!x && xitwarn == 2)) {         /* Or Always give warning on EXIT */
  13189.         int needwarn = 0;
  13190.         char warning[256];
  13191.  
  13192.         if (network) {
  13193.             if (ttchk() >= 0)
  13194.               needwarn = 1;
  13195.             /* A connection seems to be open but it can't possibly be */
  13196.             if (!haveline)
  13197.               needwarn = 0;
  13198.             if (needwarn) {
  13199.                 if (strcmp(ttname,"*"))
  13200.                     ckmakmsg(warning,256,
  13201.                               " A network connection to ",ttname,
  13202.                               " might still be active.\n",NULL);
  13203.                 else
  13204.                   ckstrncpy(warning,
  13205.                    " An incoming network connection might still be active.\n",
  13206.                              256);
  13207.             }
  13208.         } else {                        /* Serial connection */
  13209.             if (carrier == CAR_OFF)     /* SET CARRIER OFF */
  13210.               needwarn = 0;             /* so we don't care about carrier. */
  13211.             else if ((y = ttgmdm()) >= 0) /* else, get modem signals */
  13212.               needwarn = (y & BM_DCD);  /* Check for carrier */
  13213.             else                        /* If we can't get modem signals... */
  13214.               needwarn = (ttchk() >= 0);
  13215.             /* A connection seems to be open but it can't possibly be */
  13216.             if (!haveline || !exithangup)
  13217.               needwarn = 0;
  13218.             if (needwarn)
  13219.                 ckmakmsg(warning,256,
  13220.                      " A serial connection might still be active on ",
  13221.                      ttname,".\n",NULL);
  13222.         }
  13223.  
  13224. /* If a warning was issued, get user's permission to EXIT. */
  13225.  
  13226.         if (needwarn || (!x && xitwarn == 2
  13227. #ifndef K95G
  13228.             && local
  13229. #endif /* K95G */
  13230.              )) {
  13231.             if ( !needwarn )
  13232.                 ckstrncpy(warning, "No active connections", 256);
  13233.  
  13234. #ifdef COMMENT
  13235.         printf("%s",warning);
  13236.             z = getyesno(x ? "OK to close? " : "OK to exit? ",0);
  13237.             debug(F101,"hupok getyesno","",z);
  13238.             if (z < -3) z = 0;
  13239. #else
  13240.         z = uq_ok(warning,
  13241.               x ? "OK to close? " : "OK to exit? ",
  13242.               3,
  13243.               NULL,
  13244.               0
  13245.               );
  13246.             debug(F101,"hupok uq_ok","",z);
  13247.         if (z < 0) z = 0;
  13248. #endif /* COMMENT */
  13249.         }
  13250.     }
  13251.     return(z);
  13252. }
  13253.  
  13254. #ifndef NOSHOW
  13255. VOID
  13256. shoctl() {                              /* SHOW CONTROL-PREFIXING */
  13257. #ifdef CK_SPEED
  13258.     int i;
  13259. #ifdef OS2
  13260.     int zero;
  13261. #endif /* OS2 */
  13262.     printf(
  13263. "\ncontrol quote = %d, applied to (0 = unprefixed, 1 = prefixed):\n\n",
  13264.            myctlq);
  13265. #ifdef OS2
  13266. #ifndef UNPREFIXZERO
  13267.     zero = ctlp[0];
  13268.     if (protocol == PROTO_K)            /* Zero can't be unprefixed */
  13269.       ctlp[0] = 1;                      /* for Kermit */
  13270. #endif /* UNPREFIXZERO */
  13271. #endif /* OS2 */
  13272.     for (i = 0; i < 16; i++) {
  13273.         printf("  %3d: %d   %3d: %d ",i,ctlp[i], i+16, ctlp[i+16]);
  13274.         if (i == 15)
  13275.           printf("  127: %d",ctlp[127]);
  13276.         else
  13277.           printf("        ");
  13278.         printf("  %3d: %d   %3d: %d ",i+128,ctlp[i+128], i+144, ctlp[i+144]);
  13279.         if (i == 15)  printf("  255: %d",ctlp[255]);
  13280.         printf("\n");
  13281.     }
  13282.     printf("\n");
  13283. #ifndef UNPREFIXZERO
  13284. #ifdef OS2
  13285.     ctlp[0] = zero;
  13286. #endif /* OS2 */
  13287. #endif /* UNPREFIXZERO */
  13288.  
  13289. #endif /* CK_SPEED */
  13290. }
  13291.  
  13292. #ifndef NOXFER
  13293. VOID
  13294. shodbl() {                              /* SHOW DOUBLE/IGNORE */
  13295. #ifdef CKXXCHAR
  13296.     int i, n = 0;
  13297.     printf("\nSET SEND DOUBLE characters:\n");
  13298.     for (i = 0; i < 255; i++) {
  13299.         if (dblt[i] & 2) {
  13300.             n++;
  13301.             printf(" %d", i);
  13302.         }
  13303.     }
  13304.     if (n == 0)
  13305.       printf(" (none)");
  13306.     n = 0;
  13307.     printf("\nSET RECEIVE IGNORE characters:\n");
  13308.     for (i = 0; i < 255; i++) {
  13309.         if (dblt[i] & 1) {
  13310.             n++;
  13311.             printf(" %d", i);
  13312.         }
  13313.     }
  13314.     if (n == 0)
  13315.       printf(" (none)");
  13316.     printf("\n\n");
  13317. #endif /* CKXXCHAR */
  13318. }
  13319. #endif /* NOXFER */
  13320. #endif /* NOSHOW */
  13321.  
  13322. #ifndef NOPUSH
  13323. #ifdef CK_REXX
  13324. /*
  13325.   Rexx command.  Note, this is not OS/2-specific, because Rexx also runs
  13326.   on other systems where C-Kermit also runs, like the Amiga.
  13327. */
  13328. #define REXBUFL 100                     /* Change this if neccessary */
  13329. char rexxbuf[REXBUFL] = { '\0' };       /* Rexx's return value (string) */
  13330.  
  13331. int
  13332. dorexx() {
  13333.     int x, y;
  13334.     char *rexxcmd;
  13335.  
  13336.         if ((x = cmtxt("Rexx command","",&rexxcmd,xxstring)) < 0)
  13337.           return(x);
  13338.  
  13339. #ifdef IKSD
  13340.     if (inserver) {
  13341.         printf("?Sorry, command disabled.\r\n");
  13342.         return(success = 0);
  13343.     }
  13344. #endif /* IKSD */
  13345. #ifdef CK_APC
  13346.     /* Don't let this be set remotely */
  13347.     if (apcactive == APC_LOCAL ||
  13348.         apcactive == APC_REMOTE && !(apcstatus & APC_UNCH))
  13349.       return(success = 0);
  13350. #endif /* CK_APC */
  13351.  
  13352.         ckstrncpy(line,rexxcmd,LINBUFSIZ);
  13353.         rexxcmd = line;
  13354. #ifdef OS2
  13355.         return(os2rexx(rexxcmd,rexxbuf,REXBUFL));
  13356. #else /* !OS2 */
  13357.         printf("Sorry, nothing happens.\n");
  13358.         return(success = 0);
  13359. #endif /* OS2 */
  13360. }
  13361. #endif /* CK_REXX */
  13362. #endif /* NOPUSH */
  13363. #else  /* NOICP */
  13364. VOID
  13365. dologend() {
  13366.     /* Dummy write record to connection log */
  13367. }
  13368. #endif /* NOICP */
  13369.