home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / ck208 / cku208.tar.gz / cku208.tar / ckuus4.c < prev    next >
C/C++ Source or Header  |  2003-02-11  |  470KB  |  14,004 lines

  1. #include "ckcsym.h"
  2.  
  3. /*  C K U U S 4 --  "User Interface" for C-Kermit, part 4  */
  4.  
  5. /*
  6.   Author: Frank da Cruz <fdc@columbia.edu>,
  7.   Columbia University Academic Information Systems, New York City.
  8.  
  9.   Copyright (C) 1985, 2003,
  10.     Trustees of Columbia University in the City of New York.
  11.     All rights reserved.  See the C-Kermit COPYING.TXT file or the
  12.     copyright text in the ckcmai.c module for disclaimer and permissions.
  13. */
  14.  
  15. /*
  16.   File ckuus4.c -- Functions moved from other ckuus*.c modules to even
  17.   out their sizes.
  18. */
  19. #include "ckcdeb.h"
  20. #include "ckcasc.h"
  21. #include "ckcker.h"
  22. #include "ckuusr.h"
  23. #include "ckuver.h"
  24. #include "ckcnet.h"                     /* Network symbols */
  25. #include "ckcxla.h"                     /* Character sets */
  26.  
  27. #ifdef CK_AUTHENTICATION
  28. #include "ckuath.h"
  29. #endif /* CK_AUTHENTICATION */
  30. #ifdef CK_SSL
  31. #include "ck_ssl.h"
  32. #endif /* CK_SSL */
  33.  
  34. #ifdef VMS
  35. #include <errno.h>                      /* For \v(errno) */
  36. extern char * ckvmserrstr(unsigned long);
  37. #ifndef OLD_VMS
  38. #include <lib$routines.h>               /* Not for VAX C 2.4 */
  39. #else
  40. #include <libdef.h>
  41. #endif /* OLD_VMS */
  42. _PROTOTYP(int vmsttyfd, (void) );
  43. #endif /* VMS */
  44.  
  45. #ifdef OS2
  46. #ifndef NT
  47. #define INCL_NOPM
  48. #define INCL_VIO                        /* Needed for ckocon.h */
  49. #include <os2.h>
  50. #undef COMMENT
  51. #else
  52. #include <windows.h>
  53. #include <tapi.h>
  54. #include "ckntap.h"
  55. #define APIRET ULONG
  56. #endif /* NT */
  57. #include "ckocon.h"
  58. #include "ckoetc.h"
  59. int StartedFromDialer = 0;
  60. HWND hwndDialer = 0;
  61. LONG KermitDialerID = 0;
  62. #ifdef putchar
  63. #undef putchar
  64. #endif /* putchar */
  65. #define putchar(x) conoc(x)
  66. #ifdef CK_PID
  67. #include <process.h>
  68. #endif /* CK_PID */
  69. #endif /* OS2 */
  70.  
  71. #ifdef KUI
  72. extern struct keytab * term_font;
  73. extern int ntermfont, tt_font, tt_font_size;
  74. #endif /* KUI */
  75.  
  76. extern xx_strp xxstring;
  77.  
  78. #ifdef DEC_TCPIP
  79. #include <descrip>
  80. #include <dvidef>
  81. #include <dcdef>
  82. #endif /* DEC_TCPIP */
  83.  
  84. #ifdef FNFLOAT
  85. #include <math.h>                       /* Floating-point functions */
  86. #endif /* FNFLOAT */
  87.  
  88. extern int quiet, network, xitsta, escape, nopush, xferstat,
  89.   exitonclose, tn_exit, ttnproto, autodl, flow, byteorder, what, lastxfer;
  90.  
  91. extern int filepeek, nscanfile, makestrlen;
  92. extern char * k_info_dir;
  93.  
  94. #ifndef MAC
  95. #ifndef AMIGA
  96. extern int ttyfd;
  97. #endif /* MAC */
  98. #endif /* AMIGA */
  99.  
  100. #ifdef TNCODE
  101. extern int tn_nlm, tn_b_nlm, tn_b_xfer, tn_sb_bug;
  102. extern int tn_rem_echo;
  103. extern int tn_b_meu, tn_b_ume;
  104. #endif /* TNCODE */
  105.  
  106. char * xferfile = NULL;
  107. int xferlog = 0;
  108.  
  109. extern int local, xargc, stayflg, rcflag, bgset, backgrd, cfilef,
  110.   inserver, srvcdmsg, success;
  111.  
  112. #ifdef VMS
  113. extern int batch;
  114. #endif /* VMS */
  115.  
  116. extern char cmdfil[], *versio, *ckxsys, **xargv;
  117. #ifdef DEBUG
  118. extern char debfil[];                   /* Debug log file name */
  119. extern int debtim;
  120. #endif /* DEBUG */
  121.  
  122. extern int noinit;
  123.  
  124. static char ndatbuf[10];
  125.  
  126. char *months[] = {
  127.     "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  128.     "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
  129. };
  130.  
  131. char *
  132. zzndate() {                             /* Returns today's date as yyyymmdd */
  133.     char * p = NULL;
  134.     int x;
  135.  
  136. /* WARNING - This will fail if asctime() returns non-English month names */
  137.  
  138.     ztime(&p);                          /* Get "asctime" string */
  139.     if (p == NULL || *p == NUL) return("");
  140.     for (x = 20; x < 24; x++)           /* yyyy */
  141.       ndatbuf[x - 20] = p[x];
  142.     ndatbuf[6] = (char) ((p[8] == ' ') ? '0' : p[8]);
  143.     ndatbuf[7] = p[9];                  /* dd */
  144.     for (x = 0; x < 12; x++)            /* mm */
  145.       if (!strncmp(p+4,months[x],3)) break;
  146.     if (x == 12) {
  147.         ndatbuf[4] = ndatbuf[5] = '?';
  148.     } else {
  149.         x++;
  150.         ndatbuf[4] = (char) ((x < 10) ? '0' : '1');
  151.         ndatbuf[5] = (char) ((x % 10) + 48);
  152.     }
  153.     ndatbuf[8] = NUL;
  154.     debug(F110,"zzndate return",ndatbuf,0);
  155.     return((char *)ndatbuf);
  156. }
  157.  
  158. #ifdef DCMDBUF
  159. extern struct cmdptr *cmdstk;
  160. extern char *line, *tmpbuf;
  161. #else
  162. extern struct cmdptr cmdstk[];
  163. extern char line[], tmpbuf[];
  164. #endif /* DCMDBUF */
  165.  
  166. #ifdef OS2
  167. extern char exedir[];
  168. #else
  169. extern char * exedir;
  170. #endif /* OS2 */
  171.  
  172. extern int nettype;
  173.  
  174. #ifndef NOICP                           /* Most of this file... */
  175. #ifdef CKLOGDIAL
  176. extern char diafil[];
  177. #endif /* CKLOGDIAL */
  178.  
  179. #ifndef AMIGA
  180. #ifndef MAC
  181. #include <signal.h>
  182. #endif /* MAC */
  183. #endif /* AMIGA */
  184.  
  185. #ifdef STRATUS                          /* Stratus Computer, Inc.  VOS */
  186. #ifdef putchar
  187. #undef putchar
  188. #endif /* putchar */
  189. #define putchar(x) conoc(x)
  190. #ifdef getchar
  191. #undef getchar
  192. #endif /* getchar */
  193. #define getchar(x) coninc(0)
  194. #endif /* STRATUS */
  195.  
  196.  
  197. #ifdef ANYX25
  198. extern int revcall, closgr, cudata;
  199. int x25ver;
  200. extern char udata[];
  201. #ifndef IBMX25
  202. extern int npadx3;
  203. extern CHAR padparms[];
  204. extern struct keytab padx3tab[];
  205. #endif /* !IBMX25 */
  206. #ifdef IBMX25
  207. /* global variables only available for IBM X.25 - possibly interesting for
  208.  * other implementations
  209.  */
  210. extern x25addr_t local_nua;
  211. extern x25addr_t remote_nua;
  212. #endif /* IBMX25 */
  213. #endif /* ANYX25 */
  214.  
  215. #ifdef NETCONN
  216. #ifndef NODIAL
  217. extern int nnetdir;
  218. extern char *netdir[];
  219. #endif /* NODIAL */
  220. extern char ipaddr[];
  221.  
  222. #ifdef CK_NETBIOS
  223. extern unsigned short netbiosAvail;
  224. extern unsigned long NetbeuiAPI;
  225. extern unsigned char NetBiosName[];
  226. extern unsigned char NetBiosAdapter;
  227. extern unsigned char NetBiosLSN;
  228. #endif /* CK_NETBIOS */
  229.  
  230. #ifdef TCPSOCKET
  231. extern char myipaddr[];
  232. extern int tcp_rdns;
  233. #ifdef CK_DNS_SRV
  234. extern int tcp_dns_srv;
  235. #endif /* CK_DNS_SRV */
  236. extern char * tcp_address;
  237. #ifndef NOHTTP
  238. extern char * tcp_http_proxy;
  239. #endif /* NOHTTP */
  240. #ifdef NT
  241. #ifdef CK_SOCKS
  242. extern char * tcp_socks_svr;
  243. #ifdef CK_SOCKS_NS
  244. extern char * tcp_socks_ns;
  245. #endif /* CK_SOCKS_NS */
  246. #endif /* CK_SOCKS */
  247. #endif /* NT */
  248.  
  249. #ifndef NOTCPOPTS
  250. #ifdef SOL_SOCKET
  251. #ifdef SO_LINGER
  252. extern int tcp_linger;
  253. extern int tcp_linger_tmo;
  254. #endif /* SO_LINGER */
  255. #ifdef SO_DONTROUTE
  256. extern int tcp_dontroute;
  257. #endif /* SO_DONTROUTE */
  258. #ifdef TCP_NODELAY
  259. extern int tcp_nodelay;
  260. #endif /* TCP_NODELAY */
  261. #ifdef SO_SNDBUF
  262. extern int tcp_sendbuf;
  263. #endif /* SO_SNDBUF */
  264. #ifdef SO_RCVBUF
  265. extern int tcp_recvbuf;
  266. #endif /* SO_RCVBUF */
  267. #ifdef SO_KEEPALIVE
  268. extern int tcp_keepalive;
  269. #endif /* SO_KEEPALIVE */
  270. #endif /* SOL_SOCKET */
  271. #endif /* NOTCPOPTS */
  272. #endif /* TCPSOCKET */
  273. #endif /* NETCONN */
  274.  
  275. extern char * floname[];
  276.  
  277. #ifndef NOSPL
  278. extern int fndiags;                     /* Function diagnostics on/off */
  279. extern int divbyzero;
  280. int ispattern = 0;
  281. int isjoin = 0;
  282. #ifdef CK_APC
  283. extern int apcactive;                   /* Nonzero = APC command was rec'd */
  284. extern int apcstatus;                   /* Are APC commands being processed? */
  285. #ifdef DCMDBUF
  286. extern char *apcbuf;                    /* APC command buffer */
  287. #else
  288. extern char apcbuf[];
  289. #endif /* DCMDBUF */
  290. #endif /* CK_APC */
  291.  
  292. extern char evalbuf[];                  /* EVALUATE result */
  293. extern char uidbuf[], pwbuf[], prmbuf[];
  294. _PROTOTYP( static char * fneval, (char *, char * [], int, char * ) );
  295. _PROTOTYP( static VOID myflsh, (void) );
  296. _PROTOTYP( static char * getip, (char *) );
  297. _PROTOTYP( int delta2sec, (char *, long *) );
  298.  
  299. #ifdef NEWFTP
  300. _PROTOTYP( char * ftp_cpl_mode, (void) );
  301. _PROTOTYP( char * ftp_dpl_mode, (void) );
  302. _PROTOTYP( char * ftp_authtype, (void) );
  303. #endif /* NEWFTP */
  304.  
  305. #ifndef NOHTTP
  306. _PROTOTYP( char * http_host, (void) );
  307. _PROTOTYP( int http_isconnected, (void) );
  308. _PROTOTYP( char * http_security, (void) );
  309. #endif /* NOHTTP */
  310.  
  311. #ifndef NOSEXP
  312. _PROTOTYP( char * dosexp, (char *) );
  313. int fsexpflag = 0;
  314. #endif /* NOSEXP */
  315.  
  316. static char hexdigits[16] = {
  317.     '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
  318. };
  319. extern char * tempdir;
  320.  
  321. #ifdef CK_REXX
  322. extern char rexxbuf[];
  323. #endif /* CK_REXX */
  324.  
  325. extern int tfline[];
  326.  
  327. /* These need to be internationalized... */
  328.  
  329. static
  330. char *wkdays[] = {
  331.     "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
  332. };
  333. #endif /* NOSPL */
  334.  
  335. #ifdef OS2
  336. extern char startupdir[], inidir[];
  337. #else
  338. #ifdef VMSORUNIX
  339. extern char startupdir[];
  340. #endif /* VMSORUNIX */
  341. #endif /* OS2 */
  342.  
  343. #ifdef OS2
  344. _PROTOTYP (int os2getcp, (void) );
  345. #ifdef TCPSOCKET
  346. extern char tcpname[];
  347. #endif /* TCPSOCKET */
  348. extern int tcp_avail;
  349. #ifdef DECNET
  350. extern int dnet_avail;
  351. #endif /* DECNET */
  352. #ifdef SUPERLAT
  353. extern int slat_avail;
  354. #endif /* SUPERLAT */
  355.  
  356. #ifndef NOTERM
  357. extern int tt_type, max_tt;
  358. extern struct tt_info_rec tt_info[];
  359. #endif /* NOTERM */
  360. extern int tt_rows[], tt_cols[];
  361. #else /* OS2 */
  362. extern int tt_rows, tt_cols;
  363. #endif /* OS2 */
  364.  
  365. #ifdef CK_TAPI
  366. extern int tttapi;
  367. extern int tapipass;
  368. extern struct keytab * tapilinetab;
  369. extern struct keytab * _tapilinetab;
  370. extern int ntapiline;
  371. #endif /* CK_TAPI */
  372.  
  373. extern struct keytab colxtab[];
  374. extern int ncolx;
  375.  
  376. extern char ttname[], *zinptr, *kermrc;
  377. extern char inidir[];
  378.  
  379. extern int activecmd, remonly, cmd_rows, cmd_cols, parity, seslog,
  380.   sessft, sosi, hwparity, tsecs, xargs, zincnt, tlevel, insilence, cmdmsk,
  381.   timint, timef, inbufsize, dialog, binary, carrier, cdtimo, cmask, duplex,
  382.   fmask, inecho, nmac, turnch, turn, kbchar;
  383.  
  384. #ifndef NOXFER
  385. extern CHAR eol,  mypadc, mystch, padch, seol, stchr, * epktmsg, feol;
  386. extern char *cksysid;
  387. extern struct ck_p ptab[];
  388. extern int
  389.   protocol, prefixing, xfrbel, xfrcan, xfrint, xfrchr, xfrnum, pktpaus,
  390.   lscapr, lscapu, xfermode, dest, slostart, maxrps, maxsps, maxtry, mypadn,
  391.   npad, pkttim, bigrbsiz, bigsbsiz, keep, atcapr, autopar, bctr, bctu,
  392.   crunched, ckdelay, ebq, ebqflg, pktlog, retrans, rpackets, rptflg, rptq,
  393.   rtimo, spackets, spsiz, spsizf, spsizr, timeouts, fncact, fncnv, urpsiz,
  394.   wmax, wslotn, wslotr, fdispla, spmax, fnrpath, fnspath, crc16;
  395. #endif /* NOXFER */
  396.  
  397. #ifdef OS2
  398. extern int zxpn;
  399. extern int viewonly;
  400. #endif /* OS2 */
  401.  
  402. #ifndef NOXFER
  403. #ifdef GFTIMER
  404. extern CKFLOAT fptsecs, fpxfsecs;
  405. #endif /* GFTIMER */
  406. extern long xfsecs, tfcps;
  407.  
  408. #ifdef CK_TMPDIR
  409. extern char *dldir;
  410. #endif /* CK_TMPDIR */
  411. #endif /* NOXFER */
  412.  
  413. #ifdef RECURSIVE
  414. extern int recursive;
  415. #endif /* RECURSIVE */
  416.  
  417. #ifdef VMS
  418.   extern int frecl;
  419. #endif /* VMS */
  420.  
  421. extern long
  422.   ffc, filcnt, rptn, speed, tfc, tlci, tlco, ccu, ccp, vernum, xvernum;
  423.  
  424. #ifndef NOSPL
  425. extern char fspec[], myhost[];
  426. #endif /* NOSPL */
  427.  
  428. extern char *tfnam[];                   /* Command file names */
  429.  
  430. extern char pktfil[],                   /* Packet log file name */
  431. #ifdef TLOG
  432.   trafil[],                             /* Transaction log file name */
  433. #endif /* TLOG */
  434.   sesfil[];                             /* Session log file name */
  435.  
  436. #ifndef NOXMIT                          /* TRANSMIT command variables */
  437. extern char xmitbuf[];
  438. extern int xmitf, xmitl, xmitx, xmits, xmitw, xmitt;
  439. #endif /* NOXMIT */
  440.  
  441. extern int cmdlvl;
  442.  
  443. #ifndef NOSPL
  444. /* Script programming language items */
  445. extern char **a_ptr[];                  /* Arrays */
  446. extern int a_dim[];
  447. static char * inpmatch = NULL;
  448. extern char * inpbuf, inchar[];         /* Buffers for INPUT and REINPUT */
  449. extern char *inpbp;                     /* And pointer to same */
  450. static char *r3 = (char *)0;
  451. extern int incount;                     /* INPUT character count */
  452. extern int m_found;                     /* MINPUT result */
  453. extern int maclvl;                      /* Macro invocation level */
  454. extern struct mtab *mactab;             /* Macro table */
  455. extern char *mrval[];
  456. extern int macargc[], topargc;
  457.  
  458. #ifdef COMMENT
  459. extern char *m_line[];
  460. extern char *topline;
  461. #endif /* COMMENT */
  462.  
  463. extern char *m_arg[MACLEVEL][10]; /* You have to put in the dimensions */
  464. extern char *g_var[GVARS];        /* for external 2-dimensional arrays. */
  465. #ifdef DCMDBUF
  466. extern int *count, *inpcas;
  467. #else
  468. extern int count[], inpcas[];
  469. #endif /* DCMDBUF */
  470. #endif /* NOSPL */
  471.  
  472. #ifdef UNIX
  473. extern int haslock;                     /* For UUCP locks */
  474. extern char flfnam[];
  475. #ifndef USETTYLOCK
  476. extern char lock2[];
  477. #endif /* USETTYLOCK */
  478. #endif /* UNIX */
  479.  
  480. #ifdef OS2ORUNIX
  481. extern int maxnam, maxpath;             /* Longest name, path length */
  482. #endif /* OS2ORUNIX */
  483.  
  484. extern int mdmtyp, mdmsav;
  485.  
  486. #ifndef NODIAL
  487. /* DIAL-related variables */
  488. extern char modemmsg[];
  489. extern MDMINF *modemp[];                /* Pointers to modem info structs */
  490. extern int nmdm, dialhng, dialtmo, dialksp, dialdpy, dialsrt, dialsta;
  491. extern int dialrtr, dialint, dialrstr, dialcon, dialcq, dialfld;
  492. extern int mdmspd, dialec, dialdc, dialmth, dialmauto, dialesc;
  493. extern char *dialnum,   *dialini,  *dialdir[], *dialcmd,  *dialnpr,
  494.  *dialdcon, *dialdcoff, *dialecon, *dialecoff, *dialhcmd, *diallac,
  495.  *dialhwfc, *dialswfc,  *dialnofc, *dialpulse, *dialtone, *dialname,
  496.  *dialaaon, *dialaaoff, *dialmac;
  497. extern char *diallcc,   *dialixp,  *dialixs,   *dialldp,  *diallds,
  498.  *dialpxi,  *dialpxo,   *dialsfx,  *dialtfp;
  499. extern char *diallcp,   *diallcs;
  500. extern int ntollfree, ndialpxx, nlocalac;
  501. extern char *dialtfc[], *diallcac[], *dialpxx[], *matchpxx;
  502. extern int ndialpucc, ndialtocc;
  503. extern char *dialtocc[], *dialpucc[];
  504. extern int ndialdir, dialcnf, dialcvt, dialidt, dialpace;
  505. extern long dialmax, dialcapas;
  506.  
  507. extern struct keytab mdmtab[];
  508.  
  509. #ifdef BIGBUFOK
  510. #define ARGBUFSIZ 8191
  511. #else
  512. #define ARGBUFSIZ 1023
  513. #endif /* BIGBUFOK */
  514.  
  515. #ifdef BIGBUFOK
  516. extern char * dialmsg[];
  517. #endif /* BIGBUFOK */
  518.  
  519. #endif /* NODIAL */
  520.  
  521. #ifndef NOCSETS
  522. /* Translation stuff */
  523. extern int fcharset, tcharset, tslevel, language, nlng, tcsr, tcsl;
  524. extern int dcset7, dcset8;
  525. extern struct keytab lngtab[];
  526. extern struct csinfo fcsinfo[], tcsinfo[];
  527. extern struct langinfo langs[];
  528. #ifdef CK_ANSIC
  529. extern CHAR (*xls[MAXTCSETS+1][MAXFCSETS+1])(CHAR); /* Character set */
  530. extern CHAR (*xlr[MAXTCSETS+1][MAXFCSETS+1])(CHAR); /* translation functions */
  531. #else
  532. extern CHAR (*xls[MAXTCSETS+1][MAXFCSETS+1])(); /* Character set */
  533. extern CHAR (*xlr[MAXTCSETS+1][MAXFCSETS+1])(); /* translation functions. */
  534. #endif /* CK_ANSIC */
  535. #ifdef UNICODE
  536.     extern int ucsbom, ucsorder;
  537. #endif /* UNICODE */
  538. #endif /* NOCSETS */
  539.  
  540. #ifndef NOSPL
  541. /* Built-in variable names, maximum length VNAML (20 characters) */
  542.  
  543. struct keytab vartab[] = {
  544.     { "_line",     VN_TFLN,  CM_INV},   /* 192 */
  545. #ifdef OS2
  546.     { "_regname",  VN_REGN,  CM_INV},   /* 1.1.12 */
  547.     { "_regorg",   VN_REGO,  CM_INV},   /* 1.1.12 */
  548.     { "_regnum",   VN_REGS,  CM_INV},   /* 1.1.12 */
  549. #endif /* OS2 */
  550.     { "apcactive", VN_APC,   CM_INV},   /* 192 */
  551. #ifdef NT
  552.     { "appdata",   VN_APPDATA, 0},      /* 201 */
  553. #endif /* NT */
  554.     { "argc",      VN_ARGC,  0},
  555.     { "args",      VN_ARGS,  0},
  556.     { "authname",  VN_AUTHN, 0},        /* 196 */
  557.     { "authstate", VN_AUTHS, 0},        /* 195 */
  558.     { "authtype",  VN_AUTHT, 0},        /* 195 */
  559.     { "blockcheck",VN_BLK,   0},        /* 195 */
  560. #ifdef BROWSER
  561.     { "browser",   VN_BROWSR,0},        /* 193 */
  562.     { "browsopts", VN_BROPT, 0},        /* 193 */
  563.     { "browsurl",  VN_URL,   0},        /* 193 */
  564.     { "buildid",   VN_BUILD, 0},        /* 199 */
  565. #endif /* BROWSER */
  566.     { "byteorder", VN_BYTE,  0},        /* 195 */
  567. #ifndef NOCSETS
  568.     { "charset",   VN_CSET,  0},        /* 192 */
  569. #endif /* NOCSETS */
  570.     { "cmdbufsize",VN_CMDBL, 0},        /* 195 */
  571.     { "cmdfile",   VN_CMDF,  0},
  572.     { "cmdlevel",  VN_CMDL,  0},
  573.     { "cmdsource", VN_CMDS,  0},
  574.     { "cols",      VN_COLS,  0},        /* 190 */
  575. #ifdef NT
  576.     { "common",    VN_COMMON, 0},       /* 201 */
  577. #endif /* NT */
  578.     { "connection",VN_CONN,  0},        /* 190 */
  579.     { "count",     VN_COUN,  0},
  580. #ifndef NOXFER
  581.     { "cps",       VN_CPS,   0},        /* 190 */
  582. #endif /* NOXFER */
  583.     { "cpu",       VN_CPU,   0},
  584. #ifndef NOXFER
  585.     { "crc16",     VN_CRC16, 0},        /* 192 */
  586.     { "ctty",      VN_TTYNAM,0},        /* 196 */
  587. #endif /* NOXFER */
  588. #ifndef NOLOGDIAL
  589. #ifndef NOLOCAL
  590.     { "cx_time",   VN_CXTIME,0},        /* 195 */
  591.     { "cx_status", VN_CX_STA,0},        /* 199 */
  592. #endif /* NOLOCAL */
  593. #endif /* NOLOGDIAL */
  594. #ifndef NODIAL
  595.     { "d$ac",      VN_D_AC,  0},        /* 192 */
  596.     { "d$cc",      VN_D_CC,  0},        /* 192 */
  597.     { "d$ip",      VN_D_IP,  0},        /* 192 */
  598.     { "d$lc",      VN_D_LCP, 0},        /* 193 */
  599.     { "d$lcp",     VN_D_LCP, CM_INV},   /* 193 */
  600.     { "d$lp",      VN_D_LP,  0},        /* 192 */
  601.     { "d$px",      VN_D_PXX, 0},        /* 195 */
  602.     { "d$pxx",     VN_D_PXX, CM_INV},   /* 195 */
  603. #endif /* NODIAL */
  604.     { "date",      VN_DATE,  0},
  605.     { "day",       VN_DAY,   0},
  606. #ifdef NT
  607.     { "desktop",   VN_DESKTOP, 0},     /* 201 */
  608. #endif /* NT */
  609. #ifndef NODIAL
  610.     { "dialcount", VN_DRTR,  0},        /* 195 */
  611.     { "dialnumber",VN_DNUM,  0},        /* 192 */
  612.     { "dialresult",VN_MDMSG, 0},        /* 192 */
  613.     { "dialstatus",VN_DIAL,  0},        /* 190 */
  614.     { "dialsuffix",VN_PDSFX, 0},        /* 193 */
  615.     { "dialtype",  VN_DTYPE, 0},        /* 193 */
  616. #endif /* NODIAL */
  617.     { "directory", VN_DIRE,  0},
  618. #ifndef NODIAL
  619.     { "dm_hf",     VN_DM_HF, 0},        /* 199 */
  620.     { "dm_lp",     VN_DM_LP, 0},        /* 195 */
  621.     { "dm_sp",     VN_DM_SP, 0},        /* 195 */
  622.     { "dm_pd",     VN_DM_PD, 0},        /* 195 */
  623.     { "dm_td",     VN_DM_TD, 0},        /* 195 */
  624.     { "dm_wa",     VN_DM_WA, 0},        /* 195 */
  625.     { "dm_wb",     VN_DM_WB, 0},        /* 199 */
  626.     { "dm_wd",     VN_DM_WD, 0},        /* 195 */
  627.     { "dm_rc",     VN_DM_RC, 0},        /* 195 */
  628. #endif /* NODIAL */
  629. #ifndef NOXFER
  630.     { "download",  VN_DLDIR, 0},        /* 192 */
  631. #endif /* NOXFER */
  632.     { "editor",    VN_EDITOR,0},
  633.     { "editfile",  VN_EDFILE,0},
  634.     { "editopts",  VN_EDOPT, 0},
  635.     { "errno",     VN_ERRNO, 0},        /* 192 */
  636.     { "errstring", VN_ERSTR, 0},        /* 192 */
  637.     { "escape",    VN_ESC,   0},        /* 193 */
  638.     { "evaluate",  VN_EVAL,  0},        /* 190 */
  639. #ifdef OS2ORUNIX
  640.     { "exedir",    VN_EXEDIR,0},        /* 192 */
  641. #endif /* OS2ORUNIX */
  642.     { "exitstatus",VN_EXIT,  0},
  643. #ifdef CKCHANNELIO
  644.     { "f_count",   VN_FCOU,  0},        /* 195 */
  645.     { "f_error",   VN_FERR,  0},        /* 195 */
  646.     { "f_max",     VN_FMAX,  0},        /* 195 */
  647.     { "fileerror", VN_FERR,  CM_INV},   /* 195 */
  648.     { "filemax",   VN_FERR,  CM_INV},   /* 195 */
  649. #endif /* CKCHANNELIO */
  650.     { "filename",  VN_FNAM,  0},        /* 193 */
  651.     { "filenumber",VN_FNUM,  0},        /* 193 */
  652.     { "filespec",  VN_FILE,  0},
  653.     { "fsize",     VN_FFC,   0},        /* 190 */
  654. #ifdef GFTIMER
  655.     { "ftime",     VN_FTIME, 0},        /* 199 */
  656. #else
  657.     { "ftime",     VN_NTIM,  CM_INV},
  658. #endif /* GFTIMER */
  659. #ifndef NOFTP
  660. #ifndef SYSFTP
  661.     { "ftp_code",         VN_FTP_C, 0}, /* 199 */
  662.     { "ftp_cpl",          VN_FTP_B, 0}, /* 199 */
  663.     { "ftp_connected",    VN_FTP_X, 0}, /* 199 */
  664.     { "ftp_dpl",          VN_FTP_D, 0}, /* 199 */
  665.     { "ftp_getputremote", VN_FTP_G, 0}, /* 199 */
  666.     { "ftp_host",         VN_FTP_H, 0}, /* 199 */
  667.     { "ftp_loggedin",     VN_FTP_L, 0}, /* 199 */
  668.     { "ftp_message",      VN_FTP_M, 0}, /* 199 */
  669.     { "ftp_msg",          VN_FTP_M, CM_INV}, /* 199 */
  670.     { "ftp_security",     VN_FTP_Z, 0}, /* 199 */
  671.     { "ftp_server",       VN_FTP_S, 0}, /* 199 */
  672. #endif /* SYSFTP */
  673. #endif /* NOFTP */
  674.     { "ftype",     VN_MODE,  0},        /* 190 */
  675. #ifdef KUI
  676.     { "gui_fontname", VN_GUI_FNM, 0},    /* 205 */
  677.     { "gui_fontsize", VN_GUI_FSZ, 0},    /* 205 */
  678.     { "gui_runmode", VN_GUI_RUN, 0},    /* 205 */
  679.     { "gui_xpos",    VN_GUI_XP,  0},    /* 205 */
  680.     { "gui_xres",    VN_GUI_XR,  0},    /* 205 */
  681.     { "gui_ypos",    VN_GUI_YP,  0},    /* 205 */
  682.     { "gui_yres",    VN_GUI_YR,  0},    /* 205 */
  683. #endif /* KUI */
  684.     { "herald",    VN_HERALD, 0},
  685.     { "home",      VN_HOME,   0},
  686.     { "host",      VN_HOST,   0},
  687.     { "hour",      VN_HOUR,   0},       /* 200 */
  688. #ifndef NOHTTP
  689.     { "http_code",      VN_HTTP_C, 0},  /* 199 */
  690.     { "http_connected", VN_HTTP_N, 0},  /* 199 */
  691.     { "http_host",      VN_HTTP_H, 0},  /* 199 */
  692.     { "http_message",   VN_HTTP_M, 0},  /* 199 */
  693.     { "http_security",  VN_HTTP_S, 0},  /* 199 */
  694. #endif /* NOHTTP */
  695.     { "hwparity",  VN_HWPAR, 0},        /* 195 */
  696.     { "input",     VN_IBUF,  0},
  697.     { "inchar",    VN_ICHR,  0},
  698.     { "incount",   VN_ICNT,  0},
  699.     { "inidir",    VN_INI,   0},        /* 192 */
  700.     { "inmatch",   VN_MATCH, 0},        /* 196 */
  701.     { "instatus",  VN_ISTAT, 0},        /* 192 */
  702.     { "intime",    VN_INTIME,0},        /* 193 */
  703.     { "inwait",    VN_INTMO, 0},        /* 195 */
  704.     { "ip",        VN_IPADDR, CM_ABR|CM_INV},
  705.     { "ipaddress", VN_IPADDR,0},        /* 192 */
  706.     { "iprompt",   VN_PROMPT,0},        /* 199 */
  707.     { "kbchar",    VN_KBCHAR,0},        /* 196 */
  708. #ifndef NOLOCAL
  709. #ifdef OS2
  710.     { "keyboard",  VN_KEYB,  0},
  711. #endif /* OS2 */
  712. #endif /* NOLOCAL */
  713. #ifdef CK_KERBEROS
  714.     { "krb4errmsg",    VN_K4EMSG,0},
  715.     { "krb4errno",     VN_K4ENO, 0},
  716.     { "krb4principal", VN_K4PRN, 0},
  717.     { "krb4realm",     VN_K4RLM, 0},
  718.     { "krb4service",   VN_K4SRV, 0},
  719.     { "krb5cc",        VN_K5CC,  0},
  720.     { "krb5errmsg",    VN_K5EMSG,0},
  721.     { "krb5errno",     VN_K5ENO, 0},
  722.     { "krb5principal", VN_K5PRN, 0},
  723.     { "krb5realm",     VN_K5RLM, 0},
  724.     { "krb5service",   VN_K5SRV, 0},
  725. #endif /* CK_KERBEROS */
  726.     { "line",      VN_LINE,  0},
  727.     { "local",     VN_LCL,   0},
  728. #ifdef UNIX
  729.     { "lockdir",   VN_LCKDIR,0},        /* 195 */
  730.     { "lockpid",   VN_LCKPID,0},        /* 195 */
  731. #endif /* UNIX */
  732.     { "log_connection", VN_LOG_CON, 0}, /* 206 */
  733.     { "log_debug", VN_LOG_DEB, 0},      /* 206 */
  734.     { "log_packet", VN_LOG_PKT, 0},     /* 206 */
  735.     { "log_session", VN_LOG_SES, 0},    /* 206 */
  736.     { "log_transaction", VN_LOG_TRA, 0},/* 206 */
  737.     { "maclevel",  VN_MACLVL,0},        /* 195 */
  738.     { "macro",     VN_MAC,   0},
  739. #ifdef FNFLOAT
  740.     { "math_e",    VN_MA_E,  0},        /* 195 */
  741.     { "math_pi",   VN_MA_PI, 0},        /* 195 */
  742.     { "math_precision", VN_MA_PR, 0},   /* 195 */
  743. #endif /* FNFLOAT */
  744.     { "minput",    VN_MINP,  0},        /* 192 */
  745.     { "model",     VN_MODL,  0},        /* 193 */
  746.     { "modem",     VN_MDM,   0},
  747. #ifndef NOLOCAL
  748. #ifdef OS2
  749.     { "mousecurx", VN_MOU_X, 0},        /* K95 1.1.14 */
  750.     { "mousecury", VN_MOU_Y, 0},        /* K95 1.1.14 */
  751. #endif /* OS2 */
  752. #endif /* NOLOCAL */
  753. #ifndef NODIAL
  754.     { "m_aa_off",  VN_M_AAX, 0},        /* all 192... */
  755.     { "m_aa_on",   VN_M_AAO, 0},
  756.     { "m_dc_off",  VN_M_DCX, 0},
  757.     { "m_dc_on",   VN_M_DCO, 0},
  758.     { "m_dial",    VN_M_DCM, 0},
  759.     { "m_ec_off",  VN_M_ECX, 0},
  760.     { "m_ec_on",   VN_M_ECO, 0},
  761.     { "m_fc_hw",   VN_M_HWF, 0},
  762.     { "m_fc_no",   VN_M_NFC, 0},
  763.     { "m_fc_sw",   VN_M_SWF, 0},
  764.     { "m_hup",     VN_M_HUP, 0},
  765.     { "m_init",    VN_M_INI, 0},
  766.     { "m_name",    VN_M_NAM, 0},        /* 195 */
  767.     { "m_pulse",   VN_M_PDM, 0},
  768.     { "m_sig_cd",  VN_MS_CD, 0},        /* 195 */
  769.     { "m_sig_cts", VN_MS_CTS,0},        /* 195 */
  770.     { "m_sig_dsr", VN_MS_DSR,0},        /* 195 */
  771.     { "m_sig_dtr", VN_MS_DTR,0},        /* 195 */
  772.     { "m_sig_ri",  VN_MS_RI, 0},        /* 195 */
  773.     { "m_sig_rts", VN_MS_RTS,0},        /* 195 */
  774.     { "m_tone",    VN_M_TDM, 0},
  775. #endif /* NODIAL */
  776.     { "name",      VN_NAME,  0},
  777.     { "ndate",     VN_NDAT,  0},
  778.     { "nday",      VN_NDAY,  0},
  779.     { "newline",   VN_NEWL,  0},
  780.     { "ntime",     VN_NTIM,  0},
  781.     { "osname",    VN_OSNAM, 0},        /* 193 */
  782.     { "osrelease", VN_OSREL, 0},        /* 193 */
  783.     { "osversion", VN_OSVER, 0},        /* 193 */
  784. #ifndef NOXFER
  785.     { "packetlen", VN_RPSIZ, 0},        /* 192 */
  786. #endif /* NOXFER */
  787.     { "parity",    VN_PRTY,  0},        /* 190 */
  788.     { "password",  VN_PWD,   CM_INV},   /* 192 */
  789. #ifdef NT
  790.     { "personal",  VN_PERSONAL, 0},     /* 201 */
  791. #endif /* NT */
  792. #ifdef PEXITSTAT
  793.     { "pexitstat", VN_PEXIT, 0},        /* 193 */
  794. #endif /* PEXITSTAT */
  795. #ifdef CK_PID
  796.     { "pid",       VN_PID,   0},        /* 193 */
  797. #endif /* CK_PID */
  798.     { "platform",  VN_SYSV,  0},
  799.     { "printer",   VN_PRINT, 0},        /* 193 */
  800.     { "program",   VN_PROG,  0},
  801.     { "prompt",    VN_PRM,   CM_INV},   /* 192 */
  802. #ifndef NOXFER
  803.     { "protocol",  VN_PROTO, 0},        /* 192 */
  804.     { "p_8bit",    VN_P_8BIT,0},        /* 193 */
  805.     { "p_ctl",     VN_P_CTL, 0},        /* 193 */
  806.     { "p_rpt",     VN_P_RPT, 0},        /* 193 */
  807.     { "query",     VN_QUE,   0},        /* 190 */
  808. #endif /* NOXFER */
  809.     { "return",    VN_RET,   0},
  810. #ifdef CK_REXX
  811.     { "rexx",      VN_REXX,  0},        /* 190 */
  812. #endif /* CK_REXX */
  813. #ifdef TN_COMPORT
  814.     { "rfc2217_signature", VN_TNC_SIG, 0}, /* 201 */
  815.     { "rfc2717_signature", VN_TNC_SIG, CM_INV}, /* 202 */
  816. #endif /* TN_COMPORT */
  817.     { "rows",      VN_ROWS,  0},        /* 190 */
  818. #ifndef NOSEXP
  819.     { "sdepth",    VN_LSEXP,0},         /* 199 */
  820. #endif /* NOSEXP */
  821.     { "secure",    VN_SECURE, 0},       /* 199 */
  822. #ifndef NOLOCAL
  823. #ifdef OS2
  824.     { "select",    VN_SELCT, 0},        /* 192 */
  825. #endif /* OS2 */
  826. #endif /* NOLOCAL */
  827.     { "sendlist",  VN_SNDL,  0},
  828.     { "serial",    VN_SERIAL,0},        /* 195 */
  829.     { "setlinemsg",VN_SLMSG, 0},        /* 195 */
  830. #ifndef NOSEXP
  831.     { "sexpression",VN_SEXP, 0},        /* 199 */
  832. #endif /* NOSEXP */
  833.     { "speed",     VN_SPEE,  0},
  834. #ifdef OS2
  835.     { "space",     VN_SPA,   0},
  836.     { "startup",   VN_STAR,  0},        /* 190 */
  837. #else
  838. #ifdef UNIX
  839.     { "startup",   VN_STAR,  0},        /* 193 */
  840. #else
  841. #ifdef VMS
  842.     { "startup",   VN_STAR,  0},        /* 193 */
  843. #endif /* VMS */
  844. #endif /* UNIX */
  845. #endif /* OS2 */
  846.     { "status",    VN_SUCC,  0},
  847. #ifndef NOSEXP
  848.     { "svalue",    VN_VSEXP, 0},        /* 199 */
  849. #endif /* NOSEXP */
  850. #ifndef NOXFER
  851.     { "sysid",     VN_SYSI,  0},
  852. #endif /* NOXFER */
  853.     { "system",    VN_SYST,  0},
  854.     { "terminal",  VN_TTYP,  0},
  855. #ifdef OS2
  856. #ifndef NOKVERBS
  857.     { "termkey",   VN_TRMK,  CM_INV},   /* 192 */
  858. #endif /* NOKVERBS */
  859. #endif /* OS2 */
  860.     { "test",      VN_TEST,  0},        /* 193 */
  861.     { "textdir",   VN_TXTDIR,0},        /* 195 */
  862. #ifndef NOXFER
  863.     { "tfsize",    VN_TFC,   0},
  864.     { "tftime",    VN_TFTIM, 0},        /* 195 */
  865. #endif /* NOXFER */
  866.     { "time",      VN_TIME,  0},
  867.     { "timestamp", VN_NOW,   0},        /* 200 */
  868.     { "tmpdir",    VN_TEMP,  0},        /* 192 */
  869. #ifdef CK_TRIGGER
  870.     { "trigger",   VN_TRIG,  0},        /* 193 */
  871. #endif /* CK_TRIGGER */
  872. #ifdef CK_TTYFD
  873.     { "ttyfd",     VN_TTYF,  0},
  874. #endif /* CK_TTYFD */
  875.     { "ty_ln",     VN_TY_LN, 0},        /* 195 */
  876.     { "ty_lc",     VN_TY_LC, 0},        /* 195 */
  877.     { "ty_lm",     VN_TY_LM, 0},        /* 195 */
  878. #ifdef BROWSER
  879.     { "url",       VN_URL,   CM_INV},   /* 193 */
  880. #endif /* BROWSER */
  881.     { "userid",    VN_UID,   0},        /* 192 */
  882.     { "version",   VN_VERS,  0},
  883. #ifndef NOXFER
  884.     { "window",    VN_WINDO, 0},        /* 192 */
  885. #endif /* NOXFER */
  886. #ifdef IBMX25
  887.     { "x25local_nua", VN_X25LA, 0},     /* 193 */
  888.     { "x25remote_nua", VN_X25RA, 0},    /* 193 */
  889. #endif /* IBMX25 */
  890. #ifdef CK_SSL
  891.     { "x509_issuer",  VN_X509_I, 0},
  892.     { "x509_subject", VN_X509_S, 0},
  893. #endif /* CK_SSL */
  894. #ifndef NOXFER
  895.     { "xferstatus",VN_XFSTAT,0},        /* 193 */
  896.     { "xfermsg",   VN_XFMSG, 0},        /* 193 */
  897.     { "xfer_badpackets", VN_XF_BC, 0},  /* 195 */
  898.     { "xfer_timeouts",   VN_XF_TM, 0},  /* 195 */
  899.     { "xfer_retransmits",VN_XF_RX, 0},  /* 195 */
  900. #endif /* NOXFER */
  901.     { "xprogram",  VN_XPROG, 0},        /* 193 */
  902.     { "xversion",  VN_XVNUM, 0}         /* 192 */
  903. };
  904. int nvars = (sizeof(vartab) / sizeof(struct keytab));
  905. #endif /* NOSPL */
  906.  
  907. #ifndef NOSPL
  908. struct keytab fnctab[] = {              /* Function names */
  909. #ifdef OS2
  910.     { ".oox",       FN_OOX, CM_INV},    /* ... */
  911. #endif /* OS2 */
  912.  
  913. #ifdef CKCHANNELIO
  914.     { "_eof",       FN_FEOF,   0},
  915.     { "_errmsg",    FN_FERMSG, 0},
  916.     { "_getblock",  FN_FGBLK,  0},
  917.     { "_getchar",   FN_FGCHAR, 0},
  918.     { "_getline",   FN_FGLINE, 0},
  919.     { "_handle",    FN_FILNO,  0},
  920.     { "_line",      FN_NLINE,  0},
  921.     { "_pos",       FN_FPOS,   0},
  922.     { "_putblock",  FN_FPBLK,  0},
  923.     { "_putchar",   FN_FPCHAR, 0},
  924.     { "_putline",   FN_FPLINE, 0},
  925.     { "_status",    FN_FSTAT,  0},
  926. #endif /* CKCHANNELIO */
  927.  
  928.     { "aaconvert",  FN_AADUMP, 0},      /* Associative Array conversion */
  929.     { "absolute",   FN_ABS,  0},        /* Absolute value */
  930. #ifdef TCPSOCKET
  931.     { "addr2name",  FN_HSTADD,CM_INV},  /* IP Address to Hostname */
  932.     { "addrtoname", FN_HSTADD,CM_INV},  /* IP Address to Hostname */
  933. #endif /* TCPSOCKET */
  934.     { "arraylook",  FN_ALOOK,0},        /* Array lookup */
  935.     { "b64decode",  FN_FMB64,0},        /* Base-64 conversion */
  936.     { "b64encode",  FN_TOB64,0},        /* ... */
  937.     { "basename",   FN_BSN,  0},        /* Basename */
  938.     { "break",      FN_BRK,  0},        /* Break (as in Snobol) */
  939.     { "ca",         FN_CAP,  CM_INV|CM_ABR}, /* Abbreviation for capitablize */
  940.     { "cap",        FN_CAP,  CM_INV|CM_ABR}, /* Abbreviation for capitablize */
  941.     { "capitalize", FN_CAP,  0},        /* First Letter -> uppercase */
  942.     { "caps",       FN_CAP,  CM_INV},   /* ditto */
  943.     { "character",  FN_CHR,  0},        /* Character from code */
  944.     { "checksum",   FN_CHK,  0},        /* Checksum */
  945.     { "cmdstack",   FN_CMDSTK,0},       /* Command stack */
  946.     { "cmpdates",   FN_CMPDATE,0},      /* Compare dates */
  947.     { "code",       FN_COD,  0},        /* Code from character */
  948. #ifndef NOPUSH
  949.     { "command",    FN_CMD,  0},        /* Output from a command */
  950. #endif /* NOPUSH */
  951.     { "contents",   FN_CON,  0},        /* Definition (contents) of variable */
  952.     { "crc16",      FN_CRC,  0},        /* CRC-16 */
  953. #ifdef OS2
  954.     { "crypt",      FN_CRY, CM_INV},
  955. #endif /* OS2 */
  956.     { "cvtdate",    FN_DTIM, 0},        /* Convert free date/time to std */
  957. #ifdef ZFCDAT
  958.     { "date",       FN_FD,   0},        /* File modification/creation date */
  959. #endif /* ZFCDAT */
  960.     { "day",        FN_DAY,  0},        /* Day of week */
  961.     { "dayofyear",  FN_JDATE,0},        /* Date to Day of Year */
  962.     { "definition", FN_DEF,  0},        /* Return definition of given macro */
  963.     { "delta2secs", FN_DELSEC, 0},      /* Delta time to seconds */
  964.     { "deltatosecs", FN_DELSEC, CM_INV}, /* Delta time to seconds */
  965. #ifndef NODIAL
  966.     { "dialconvert",FN_PNCVT,0},        /* Convert portable phone number */
  967. #endif /* NODIAL */
  968.     { "diffdates",  FN_DIFDATE,0},      /* Difference of two date-times */
  969.     { "dimension",  FN_DIM,  0},        /* Dimension of array */
  970.     { "directories",FN_DIR,  0},        /* List of directories */
  971.     { "dirname",    FN_DNAM, 0},        /* Directory part of filename */
  972.     { "dos2unixpath",FN_PC_DU, },       /* DOS to UNIX path */
  973.     { "dostounixpath",FN_PC_DU, CM_INV}, /* DOS to UNIX path */
  974.     { "doy",        FN_JDATE,CM_INV},   /* Date to Day of Year */
  975.     { "doy2date",   FN_DATEJ,0},        /* Day of Year to date */
  976.     { "doytodate",  FN_DATEJ,CM_INV},   /* Day of Year to date */
  977. #ifdef FN_ERRMSG
  978.     { "errstring",  FN_ERRMSG,0},       /* Error code to message */
  979. #endif /* FN_ERRMSG */
  980.     { "evaluate",   FN_EVA,  0},        /* Evaluate given arith expression */
  981.     { "execute",    FN_EXE,  0},        /* Execute given macro */
  982.     { "files",      FN_FC,   0},        /* File count */
  983. #ifdef FNFLOAT
  984.     { "fpabsolute", FN_FPABS, 0},       /* Floating-point absolute value */
  985.     { "fpadd",      FN_FPADD, 0},       /* FP add */
  986.     { "fpcosine",   FN_FPCOS, 0},       /* FP cosine */
  987.     { "fpdivide",   FN_FPDIV, 0},       /* FP divide */
  988.     { "fpexp",      FN_FPEXP, 0},       /* FP e to the x */
  989.     { "fpint",      FN_FPINT, 0},       /* FP to integer */
  990.     { "fplog10",    FN_FPLOG, 0},       /* FP base-10 logarithm */
  991.     { "fplogn",     FN_FPLN,  0},       /* FP natural logarithm */
  992.     { "fpmaximum",  FN_FPMAX, 0},       /* FP maxinum */
  993.     { "fpminimum",  FN_FPMIN, 0},       /* FP mininum */
  994.     { "fpmodulus",  FN_FPMOD, 0},       /* FP modulus */
  995.     { "fpmultiply", FN_FPMUL, 0},       /* FP multiply */
  996.     { "fpraise",    FN_FPPOW, 0},       /* FP raise to a power */
  997.     { "fpround",    FN_FPROU, 0},       /* FP round */
  998.     { "fpsine",     FN_FPSIN, 0},       /* FP sine */
  999.     { "fpsqrt",     FN_FPSQR, 0},       /* FP square root */
  1000.     { "fpsubtract", FN_FPSUB, 0},       /* FP subtract */
  1001.     { "fptangent",  FN_FPTAN, 0},       /* FP tangent */
  1002. #endif /* FNFLOAT */
  1003.     { "hex2ip",     FN_HEX2IP,0},       /* Hex to IP address */
  1004.     { "hextoip",    FN_HEX2IP,CM_INV},  /* Hex to IP address */
  1005.     { "hex2n",      FN_HEX2N, CM_INV},  /* Hex to decimal number */
  1006.     { "hexify",     FN_HEX,   0},       /* Hexify (string) */
  1007.     { "index",      FN_IND,   0},       /* Index (string search) */
  1008.     { "ip2hex",     FN_IP2HEX,0},       /* IP address to hex */
  1009.     { "iptohex",    FN_IP2HEX,CM_INV},  /* IP address to hex */
  1010.     { "ipaddress",  FN_IPA,   0},       /* Find and return IP address */
  1011.     { "jdate",      FN_JDATE, CM_INV},  /* Date to Day of Year */
  1012.     { "join",       FN_JOIN,  0},       /* Join array elements */
  1013.     { "keywordvalue",  FN_KWVAL, 0},    /* Keyword=Value */
  1014. #ifdef CK_KERBEROS
  1015.     { "krbflags",      FN_KRB_FG, 0},   /* Kerberos functions */
  1016.     { "krbisvalid",    FN_KRB_IV, 0},
  1017.     { "krbnextticket", FN_KRB_NX, 0},
  1018.     { "krbtickets",    FN_KRB_TK, 0},
  1019.     { "krbtimeleft",   FN_KRB_TT, 0},
  1020. #endif /* CK_KERBEROS */
  1021.     { "left",       FN_LEF,  0},        /* Leftmost n characters of string */
  1022.     { "length",     FN_LEN,  0},        /* Return length of argument */
  1023.     { "literal",    FN_LIT,  0},        /* Return argument literally */
  1024. #ifdef NT
  1025.     { "longpathname",FN_LNAME,0},    /* GetLongPathName() */
  1026. #else
  1027.     { "longpathname",FN_FFN,CM_INV},
  1028. #endif /* NT */
  1029.     { "lop",        FN_STL,  0},        /* Lop */
  1030.     { "lower",      FN_LOW,  0},        /* Return lowercased argument */
  1031.     { "lpad",       FN_LPA,  0},        /* Return left-padded argument */
  1032.     { "ltrim",      FN_LTR,  0},        /* Left-Trim */
  1033.     { "maximum",    FN_MAX,  0},        /* Return maximum of two arguments */
  1034.     { "minimum",    FN_MIN,  0},        /* Return minimum of two arguments */
  1035.     { "mjd",        FN_MJD,  0},        /* Date to Modified Julian Date */
  1036.     { "mjd2date",   FN_MJD2, 0},        /* MJD to Date */
  1037.     { "mjdtodate",  FN_MJD2, CM_INV},   /* MJD to Date */
  1038.     { "modulus",    FN_MOD,  0},        /* Return modulus of two arguments */
  1039. #ifdef COMMENT
  1040.     { "msleep",     FN_MSLEEP,0},       /* Sleep for n milliseconds */
  1041. #endif /* COMMENT */
  1042.     { "n2hex",      FN_2HEX, CM_INV},   /* Number to hex */
  1043.     { "n2octal",    FN_2OCT, CM_INV},   /* Number to octal */
  1044.     { "n2time",     FN_N2TIM,0},        /* Number to hh:mm:ss */
  1045. #ifdef TCPSOCKET
  1046.     { "name2addr",  FN_HSTNAM,CM_INV},  /* Hostname to IP Address */
  1047. #endif /* TCPSOCKET */
  1048.     { "nday",       FN_NDAY, 0},        /* Numeric day of week */
  1049.     { "nextfile",   FN_FIL,  0},        /* Next file in list */
  1050.     { "ntime",      FN_NTIM, 0},        /* Time to seconds since midnight */
  1051.     { "ntohex",     FN_2HEX, CM_INV},   /* Number to hex */
  1052.     { "ntooctal",   FN_2OCT, CM_INV},   /* Number to octal */
  1053.     { "ntotime",    FN_N2TIM,CM_INV},   /* Number to hh:mm:ss */
  1054.     { "oct2n",      FN_OCT2N,CM_INV},   /* Octal to decimal number */
  1055.     { "octton",     FN_OCT2N,CM_INV},   /* Octal to decimal number */
  1056.     { "pathname",   FN_FFN,  0},        /* Full file name */
  1057.     { "pattern",    FN_PATTERN, 0},     /* Pattern (for INPUT) */
  1058. #ifdef CK_PERMS
  1059.     { "permissions",FN_PERM, 0},        /* Permissions of file */
  1060. #else
  1061.     { "permissions",FN_PERM, CM_INV},   /* Permissions of file */
  1062. #endif /* CK_PERMS */
  1063.     { "radix",      FN_RADIX,0},        /* Radix conversion */
  1064. #ifndef NORANDOM
  1065.     { "random",     FN_RAND, 0},        /* Random number */
  1066. #endif /* NORANDOM */
  1067. #ifndef NOPUSH
  1068.     { "rawcommand", FN_RAW,  0},        /* Output from a command (raw) */
  1069. #endif /* NOPUSH */
  1070. #ifdef RECURSIVE
  1071.     { "rdirectories", FN_RDIR, 0},      /* Recursive directory list */
  1072.     { "rfiles",       FN_RFIL, 0},      /* Recursive file list */
  1073. #endif /* RECURSIVE */
  1074.     { "rep",        FN_REP, CM_INV|CM_ABR},
  1075.     { "repeat",     FN_REP,  0},        /* Repeat argument given # of times */
  1076.     { "replace",    FN_RPL,  0},        /* Replace characters in string */
  1077.     { "reverse",    FN_REV,  0},        /* Reverse the argument string */
  1078.     { "right",      FN_RIG,  0},        /* Rightmost n characters of string */
  1079.     { "rindex",     FN_RIX,  0},        /* Right index */
  1080.     { "rpad",       FN_RPA,  0},        /* Right-pad the argument */
  1081.     { "rsearch",    FN_RSEARCH, 0},     /* R-L Search for pattern in string */
  1082. #ifdef OS2
  1083.     { "scrncurx",   FN_SCRN_CX,  0},    /* Screen Cursor X Pos */
  1084.     { "scrncury",   FN_SCRN_CY,  0},    /* Screen Cursor Y Pos */
  1085.     { "scrnstr",    FN_SCRN_STR, 0},    /* Screen String */
  1086. #endif /* OS2 */
  1087.     { "search",     FN_SEARCH, 0},      /* L-R Search for pattern in string */
  1088. #ifndef NOSEXP
  1089.     { "sexpression",FN_SEXP, 0},        /* S-Expression */
  1090. #endif /* NOSEXP */
  1091. #ifdef NT
  1092.     { "shortpathname",FN_SNAME,0},    /* GetShortPathName() */
  1093. #else
  1094.     { "shortpathname",FN_FFN,CM_INV},
  1095. #endif /* NT */
  1096.     { "size",       FN_FS,   0},        /* File size */
  1097. #ifdef COMMENT
  1098.     { "sleep",      FN_SLEEP,0},        /* Sleep for n seconds */
  1099. #endif /* COMMENT */
  1100.     { "span",       FN_SPN,  0},        /* Span - like Snobol */
  1101.     { "split",      FN_SPLIT,0},        /* Split string into words */
  1102.     { "stripb",     FN_STB,  0},        /* Strip enclosing braces/brackets */
  1103.     { "stripn",     FN_STN,  0},        /* Strip n chars */
  1104.     { "stripx",     FN_STX,  0},        /* Strip suffix */
  1105.     { "su",         FN_SUB,  CM_INV|CM_ABR},
  1106.     { "sub",        FN_SUB,  CM_INV|CM_ABR},
  1107.     { "subs",       FN_SUB,  CM_INV|CM_ABR},
  1108.     { "subst",      FN_SUB,  CM_INV|CM_ABR},
  1109.     { "substitute", FN_SUBST,0},        /* Substitute chars */
  1110.     { "substring",  FN_SUB,  0},        /* Extract substring from argument */
  1111.     { "tablelook",  FN_TLOOK,0},        /* Table lookup */
  1112.     { "time",       FN_TIME, 0},        /* Free-format time to hh:mm:ss */
  1113.     { "tod2secs",   FN_NTIM, CM_INV},   /* Time-of-day-to-secs-since-midnite */
  1114.     { "todtosecs",  FN_NTIM, CM_INV},   /* Time-of-day-to-secs-since-midnite */
  1115.     { "trim",       FN_TRM,  0},        /* Trim */
  1116.     { "unhexify",   FN_UNH,  0},        /* Unhexify */
  1117.     { "unix2dospath",FN_PC_UD, 0},      /* UNIX to DOS path */
  1118.     { "unixtodospath",FN_PC_UD, CM_INV}, /* UNIX to DOS path */
  1119.     { "upper",      FN_UPP,  0},        /* Return uppercased argument */
  1120.     { "utcdate",    FN_TOGMT,0},        /* Date-time to UTC (GMT) */
  1121.     { "verify",     FN_VER,  0},        /* Verify */
  1122.     { "word",       FN_WORD, 0},        /* Extract a word */
  1123.     { "", 0, 0}
  1124. };
  1125. int nfuncs = (sizeof(fnctab) / sizeof(struct keytab)) - 1;
  1126. #endif /* NOSPL */
  1127.  
  1128. #ifndef NOSPL                           /* Buffer for expansion of */
  1129. #ifdef BIGBUFOK                         /* built-in variables. */
  1130. #define VVBUFL 1024
  1131. #else
  1132. #define VVBUFL 256
  1133. #endif /* BIGBUFOK */
  1134. char vvbuf[VVBUFL+1];
  1135. #endif /* NOSPL */
  1136.  
  1137. struct keytab disptb[] = {              /* Log file disposition */
  1138.     { "append",    1,  0},
  1139.     { "new",       0,  0}
  1140. };
  1141.  
  1142. #ifdef CKFLOAT
  1143.  
  1144. /* I N I T F L O A T  --  Deduce floating-point precision by inspection */
  1145.  
  1146. int fp_rounding = 0;                /* Nonzero if printf("%f") rounds */
  1147. int fp_digits = 0;                  /* Digits of floating point precision */
  1148.  
  1149. #ifdef COMMENT
  1150. /* For looking at internal floating-point representations */
  1151. static char fp_xbuf[128];
  1152. static char *
  1153. tohex(s, n) CHAR * s; int n; {
  1154.     int x;
  1155.     char * p = fp_xbuf;
  1156.     while (n-- > 0) {
  1157.         x = (*s >> 4) & 0x0f;
  1158.         *p++ = hexdigits[x];
  1159.         x = *s++ & 0x0f;
  1160.         *p++ = hexdigits[x];
  1161.     }
  1162.     *p = NUL;
  1163.     return((char *)fp_xbuf);
  1164. }
  1165. #endif /* COMMENT */
  1166.  
  1167. char math_pi[] = "3.1415926535897932384626433832795";
  1168. char math_e[] =  "2.7182818284590452353602874713527";
  1169.  
  1170. VOID
  1171. initfloat() {
  1172.     char * buf = NULL;
  1173.     int i, x, y;
  1174. /*
  1175.   We malloc a big temporary buffer for sprintf() to minimize likelihood of
  1176.   (and damage from) sprintf buffer overflows.  In any case, the only way this
  1177.   could happen would be if sprintf() itself had bugs, since the format
  1178.   descriptor says to cut it off at 250 decimal places.
  1179. */
  1180.     if ((buf = (char *)malloc(4096))) {
  1181.         sprintf(buf,"%0.250f",(10.0 / 3.0));
  1182.         for (i = 2; i < 250 && buf[i] == '3'; i++) ;
  1183.         x = i - 1;
  1184.         debug(F111,"initfloat 10.0/3.0",buf,x);
  1185.         sprintf(buf,"%0.250f",(4.0 / 9.0));
  1186.         for (i = 2; i < 250 && buf[i] == '4'; i++) ;
  1187.         y = i - 1;
  1188.         debug(F111,"initfloat 4.0/9.0",buf,y);
  1189.         fp_digits = (x < y) ? x : y;
  1190.         if (fp_digits < sizeof(math_pi) - 1) {
  1191.             math_pi[fp_digits+1] = NUL;
  1192.             math_e[fp_digits+1] = NUL;
  1193.         }
  1194.         sprintf(buf,"%0.6f",(7.0 / 9.0));
  1195.         if (buf[7] == '8') fp_rounding = 1;
  1196.         debug(F111,"initfloat 7.0/9.0",buf,fp_rounding);
  1197.         debug(F101,"initfloat precision","",fp_digits);
  1198.         free(buf);
  1199.     }
  1200. }
  1201. #endif /* CKFLOAT */
  1202.  
  1203. /*
  1204.   P R E S C A N -- A quick look through the command-line options for
  1205.   items that must be handled before the initialization file is executed.
  1206. */
  1207. #ifdef NT
  1208. extern int StartedFromDialer;
  1209. #endif /* NT */
  1210. #ifdef OS2
  1211. extern int k95stdio;
  1212. unsigned long startflags = 0L;
  1213. #endif /* OS2 */
  1214.  
  1215. static char *
  1216. findinpath(arg) char * arg; {
  1217. #ifdef OS2
  1218.     char * scriptenv, * keymapenv;
  1219.     int len;
  1220. #endif /* OS2 */
  1221. #ifdef DCMDBUF
  1222.     extern char * cmdbuf;
  1223. #else
  1224.     extern char cmdbuf[];
  1225. #endif /* DCMDBUF */
  1226.     char takepath[4096];
  1227.     char * s;
  1228.     int x, z;
  1229.  
  1230.     /* Set up search path... */
  1231. #ifdef OS2
  1232.     char * appdata0 = NULL, *appdata1 = NULL;
  1233. #ifdef NT
  1234.     scriptenv = getenv("K95SCRIPTS");
  1235.     keymapenv = getenv("K95KEYMAPS");
  1236.     makestr(&appdata0,(char *)GetAppData(0));
  1237.     makestr(&appdata1,(char *)GetAppData(1));
  1238. #else /* NT */
  1239.     scriptenv = getenv("K2SCRIPTS");
  1240.     keymapenv = getenv("K2KEYMAPS");
  1241. #endif /* NT */
  1242.     if (!scriptenv)
  1243.       scriptenv = getenv("CK_SCRIPTS");
  1244.     if (!scriptenv)
  1245.       scriptenv = "";
  1246.     if (!keymapenv)
  1247.       keymapenv = getenv("CK_KEYMAPS");
  1248.     if (!keymapenv)
  1249.       keymapenv = "";
  1250.  
  1251.     debug(F110,"startupdir",startupdir,0);
  1252.     debug(F110,"common appdata directory",appdata1,0);
  1253.     debug(F110,"appdata directory",appdata0,0);
  1254.     debug(F110,"inidir",inidir,0);
  1255.     debug(F110,"home",zhome(),0);
  1256.     debug(F110,"exedir",exedir,0);
  1257.  
  1258.     len = strlen(scriptenv) + strlen(keymapenv) + 3*strlen(startupdir)
  1259.         + 3*strlen(inidir) + 3*strlen(zhome()) + 3*strlen(exedir)
  1260.         + (appdata0 ? 3*strlen(appdata0) : 0) 
  1261.         + (appdata1 ? 3*strlen(appdata1) : 0)
  1262.         + 6*strlen("SCRIPTS/") + 6*strlen("KEYMAPS/") + 16;
  1263.  
  1264.     if (len >= 4096) {                  /* SAFE (length is checked) */
  1265.         takepath[0] = '\0';
  1266.         debug(F111,"findinpath error - path length too long","len",len);
  1267.     } else
  1268.       sprintf(takepath,
  1269.               /* semicolon-separated path list */
  1270.     "%s%s%s%s%s;%s%s;%s%s;%s%s%s%s%s%s%s%s%s%s%s%s%s;%s%s;%s%s;%s;%s%s;%s%s",
  1271.               scriptenv,
  1272.               (scriptenv[0] && scriptenv[strlen(scriptenv)-1]==';')?"":";",
  1273.               keymapenv,
  1274.               (keymapenv[0] && keymapenv[strlen(keymapenv)-1]==';')?"":";",
  1275.               startupdir,
  1276.               startupdir, "SCRIPTS/",
  1277.               startupdir, "KEYMAPS/",
  1278.               appdata1 ? appdata1 : "", 
  1279.               appdata1 ? "Kermit 95;" : "",
  1280.               appdata1 ? appdata1 : "",
  1281.               appdata1 ? "Kermit 95/SCRIPTS/;" : "",
  1282.               appdata1 ? appdata1 : "",
  1283.               appdata1 ? "Kermit 95/KEYMAPS/;" : "",
  1284.               appdata0 ? appdata0 : "",
  1285.               appdata0 ? "Kermit 95;" : "",
  1286.               appdata0 ? appdata0 : "",
  1287.               appdata0 ? "Kermit 95/SCRIPTS/;" : "",
  1288.               appdata0 ? appdata0 : "",
  1289.               appdata0 ? "Kermit 95/KEYMAPS/;" : "",
  1290.               inidir,
  1291.               inidir, "SCRIPTS/",
  1292.               inidir, "KEYMAPS/",
  1293.               zhome(),
  1294.               zhome(), "SCRIPTS/",
  1295.               zhome(), "KEYMAPS/",
  1296.               exedir,
  1297.               exedir, "SCRIPTS/",
  1298.               exedir, "KEYMAPS/"
  1299.               );
  1300.     debug(F110,"findinpath takepath",takepath,0);
  1301. #ifdef NT
  1302.     makestr(&appdata0,NULL);
  1303.     makestr(&appdata1,NULL);
  1304. #endif /* NT */
  1305. #else /* not OS2 */
  1306. #ifndef NOSPL
  1307.     z = 1024;                           /* Look in home directory */
  1308.     s = takepath;
  1309.     zzstring("\\v(home)",&s,&z);
  1310. #else
  1311.     takepath[0] = '\0';
  1312. #endif /* NOSPL */
  1313. #endif /* OS2 */
  1314. /*
  1315.   All the logic for searching the take path is in the command parser.
  1316.   So even though we aren't parsing commands, we initialize and call the
  1317.   parser from here, with the purported filename stuffed into the command
  1318.   buffer, followed by some carriage returns to make the parser return.
  1319.   If the file is not found, or otherwise not accessible, the parser prints
  1320.   an appropriate message, and then we just exit.
  1321. */
  1322.     cmdini();                           /* Allocate command buffers etc */
  1323.     cmini(0);                           /* Initialize them */
  1324.     /* Stuff filename into command buf with braces in case of spaces */
  1325.     ckmakmsg(cmdbuf,CMDBL,"{",arg,"}",NULL);
  1326.     debug(F110,"findinpath cmdbuf",cmdbuf,0);
  1327.     ckstrncat(cmdbuf,"\r\r",CMDBL);     /* And some carriage returns */
  1328.     if (cmifip("","",&s,&x,0,takepath,xxstring) < 0)
  1329.       return(NULL);
  1330.     cmres();
  1331.     return(s);
  1332. }
  1333.  
  1334. static int tr_int;                      /* Flag if TRANSMIT interrupted */
  1335.  
  1336. #ifndef MAC
  1337. SIGTYP
  1338. #ifdef CK_ANSIC
  1339. trtrap(int foo)                         /* TRANSMIT interrupt trap */
  1340. #else
  1341. trtrap(foo) int foo;                    /* TRANSMIT interrupt trap */
  1342. #endif /* CK_ANSIC */
  1343. /* trtrap */ {
  1344. #ifdef __EMX__
  1345.     signal(SIGINT, SIG_ACK);
  1346. #endif
  1347.     tr_int = 1;                         /* (Need arg for ANSI C) */
  1348.     SIGRETURN;
  1349. }
  1350. #endif /* MAC */
  1351. #endif /* NOICP */
  1352.  
  1353. #ifdef UNIX
  1354. VOID
  1355. getexedir() {
  1356.     extern char * xarg0;
  1357.   /*
  1358.     Unix provides no standard service for this.  We look in argv[0], and if
  1359.     we're lucky there's a full pathname.  If not we do a PATH search.
  1360.   */
  1361.     if (ckstrchr(xarg0,'/')) {          /* Global copy of argv[0] */
  1362.         int i, k;
  1363.         char * p = NULL;
  1364.         if ((k = ckstrncpy(tmpbuf,xarg0,TMPBUFSIZ-2)) > 0) {
  1365.             p = tmpbuf;
  1366.             /* Convert to fully qualified pathname */
  1367.             if (tmpbuf[0]) if (tmpbuf[0] != '/') {
  1368.                 line[0] = NUL;
  1369.                 zfnqfp(tmpbuf,LINBUFSIZ-2,(char *)line);
  1370.                 if (line[0])
  1371.                   p = line;
  1372.             }
  1373.             if (zchki(p) > -1) {        /* Is the result an existing file? */
  1374.                 k = strlen(p);
  1375.                 for (i = k-1; i > 0; i--) { /* Yes, strip name part */
  1376.                     if (tmpbuf[i] == '/') {
  1377.                         if (i < k-1)
  1378.                           tmpbuf[i+1] = NUL;
  1379.                         break;
  1380.                     }
  1381.                 }
  1382.                 makestr(&exedir,p);     /* Save the result */
  1383.             }
  1384.         }
  1385.     }
  1386.     if (!exedir && xarg0) {             /* Not found? */
  1387.         char * p;
  1388.         p = getenv("PATH");             /* Search the PATH */
  1389.         if (p) {                        /* If there is one... */
  1390.             char * q, * PATH = NULL;
  1391.             int k;
  1392.             makestr(&PATH,p);           /* Pokeable copy of PATH string */
  1393.             if (PATH) {                 /* If malloc succeeded... */
  1394.                 p = PATH;
  1395.                 while (p && *p) {        /* Loop through segments */
  1396.                     q = ckstrchr(p,':'); /* End of this segment */
  1397.                     if (q == p) {       /* Null PATH segment */
  1398.                         p++;            /* Skip over colon */
  1399.                         continue;
  1400.                     }
  1401.                     if (q)              /* If not at end of PATH string */
  1402.                       *q++ = NUL;       /* zero out the colon */
  1403.                     if ((k = ckstrncpy(tmpbuf,p,TMPBUFSIZ)) > 0) {
  1404.                         if (tmpbuf[k-1] != '/') { /* Copy this PATH segment */
  1405.                             tmpbuf[k++] = '/';    /* Append '/' if needed */
  1406.                             tmpbuf[k] = NUL;
  1407.                         }
  1408.                         /* Append the argv[0] value */
  1409.                         if (ckstrncpy(&tmpbuf[k],xarg0,TMPBUFSIZ) > 0) {
  1410.                             if (zchki(tmpbuf) > -1) { /* File exists? */
  1411.                                 tmpbuf[k] = NUL;      /* Yes, we're done */
  1412.                                 zfnqfp(tmpbuf,LINBUFSIZ,(char *)line);
  1413.                                 makestr(&exedir,line);
  1414.                                 break;
  1415.                             }
  1416.                         } else break;
  1417.                     } else break;
  1418.                     p = q;              /* Not found, go to next segment  */
  1419.                 } /* while */
  1420.                 free(PATH);             /* Free PATH copy */
  1421.             }
  1422.         }
  1423.         if (!exedir) {                  /* Still nothing? */
  1424.             if (zchki(xarg0) > -1) {    /* Maybe it's in the current dir */
  1425.                 zfnqfp(zgtdir(),LINBUFSIZ,(char *)line);
  1426.                 makestr(&exedir,line);
  1427.             }
  1428.         }
  1429.     }
  1430.     if (!exedir) {                      /* Still nothing? */
  1431.         makestr(&exedir,"/");           /* Fake it with with root. */
  1432.     }
  1433. }
  1434. #endif /* UNIX */
  1435.  
  1436. int arg_x = 0;
  1437. static int x_prescan = 0;
  1438.  
  1439. /*
  1440.   The argument y once meant something but I can't imagine what so now
  1441.   it's ignored.  (Prior to 22 Aug 98, prescan() was called twice by main(),
  1442.   and the arg differentiated the two calls.  But this caused all sorts of
  1443.   problems & confusion, so I commented out the second call.  This issue might
  1444.   need to be revisited.)
  1445. */
  1446. VOID
  1447. prescan(dummy) int dummy; {             /* Arg is ignored. */
  1448.     extern int howcalled;
  1449.     int yargc; char **yargv;
  1450.     char x;
  1451.     char *yp, *yy;
  1452. #ifdef DEBUG
  1453.     int debcount = 0;
  1454. #endif /* DEBUG */
  1455.     int z;
  1456.  
  1457.     if (x_prescan)                      /* Only run once */
  1458.       return;
  1459.     x_prescan = 1;
  1460.  
  1461.     yargc = xargc;                      /* Make copy of arg vector */
  1462.     yargv = xargv;
  1463.  
  1464. #ifndef NOICP
  1465. #ifdef DCMDBUF
  1466.     if (!kermrc)
  1467.       if (!(kermrc = (char *) malloc(KERMRCL+1)))
  1468.         fatal("prescan: no memory for kermrc");
  1469. #endif /* DCMDBUF */
  1470.     ckstrncpy(kermrc,KERMRC,KERMRCL);   /* Default init file name */
  1471. #endif /* NOICP */
  1472.  
  1473.  
  1474. #ifdef IKSD
  1475.     if (howcalled == I_AM_IKSD)         /* Internet Kermit Service daemon */
  1476.       inserver = 1;                     /* (See inserver section of ckcmai) */
  1477. #endif /* IKSD */
  1478.  
  1479. /* Command line options for Kermit */
  1480.  
  1481. #ifndef NOCMDL
  1482.     if (yargc > 1
  1483.         && *yargv[1] != '-'
  1484.         && (yargv[1][0] != '=')
  1485. #ifdef KERBANG
  1486.         && (yargv[1][0] != '+')
  1487. #endif /* KERBANG */
  1488. #ifdef IKSD
  1489.         && (howcalled != I_AM_IKSD)
  1490. #endif /* IKSD */
  1491.         ) {                             /* Filename as 1st argument */
  1492. #ifndef NOICP
  1493.         char *s;
  1494. #endif /* NOICP */
  1495. #ifndef NOURL
  1496.         extern int haveurl;
  1497.         extern struct urldata g_url;
  1498.         if (urlparse(yargv[1],&g_url)) {
  1499.             if (!ckstrcmp(g_url.svc,"ftp",-1,0) ||
  1500.                 !ckstrcmp(g_url.svc,"ftps",-1,0)) {
  1501.                 haveurl = 1;
  1502.                 howcalled = I_AM_FTP;
  1503.             } else if (!ckstrcmp(g_url.svc,"telnet",-1,0) ||
  1504.                        !ckstrcmp(g_url.svc,"telnets",-1,0)) {
  1505.                 haveurl = 1;
  1506.                 howcalled = I_AM_TELNET;
  1507.             } else if (!ckstrcmp(g_url.svc,"ssh",-1,0)) {
  1508.                 haveurl = 1;
  1509.                 howcalled = I_AM_SSH;
  1510.             } else if (!ckstrcmp(g_url.svc,"iksd",-1,0) ||
  1511.                        !ckstrcmp(g_url.svc,"kermit",-1,0)) {
  1512.                 haveurl = 1;
  1513.                 howcalled = I_AM_KERMIT;
  1514.             } else if (!ckstrcmp(g_url.svc,"http",-1,0) ||
  1515.                        !ckstrcmp(g_url.svc,"https",-1,0)) {
  1516.                 haveurl = 1;
  1517.                 howcalled = I_AM_HTTP;
  1518.             }
  1519.             if (haveurl) {
  1520.                 while (--yargc > 0) {   /* Go through command-line args */
  1521.                     yargv++;            /* looking for -Y and -d */
  1522.                     yp = *yargv+1;
  1523.                     if (**yargv == '-') {
  1524.                         x = *(*yargv+1);
  1525.                         while (x) {
  1526.                             switch (x) {
  1527.                               case 'Y':
  1528.                                 noinit++;
  1529.                                 break;
  1530.                               case 'h':
  1531.                                   noinit = 1;
  1532. #ifdef OS2
  1533.                                   startflags |= 2;    /* No network DLLs */
  1534.                                   startflags |= 4;    /* No TAPI DLLs */
  1535.                                   startflags |= 8;    /* No Security DLLs */
  1536.                                   startflags |= 16;   /* No Zmodem DLLs */
  1537.                                   startflags |= 32;   /* Stdin */
  1538.                                   startflags |= 64;   /* Stdout */
  1539. #endif /* OS2 */
  1540.                                   break;
  1541.                               case 'd': /* = SET DEBUG ON */
  1542. #ifdef DEBUG
  1543.                                 if (debcount++ > 0)
  1544.                                   debtim = 1;
  1545.                                 if (!deblog)
  1546.                                   deblog = debopn("debug.log",0);
  1547. #endif /* DEBUG */
  1548.                                 break;
  1549. #ifdef OS2
  1550.                               case 'W':
  1551.                                 if (*(yp+1))
  1552.                                   fatal("invalid argument bundling after -W");
  1553.                                 yargv++, yargc--;
  1554.                                 if (yargc < 1)
  1555.                                   fatal("Window handle missing");
  1556.                                 hwndDialer = (HWND) atol(*yargv);
  1557.                                 StartedFromDialer = 1;
  1558.                                 yargv++, yargc--;
  1559.                                 KermitDialerID = atol(*yargv) ;
  1560.                                 break;
  1561.                               case '#': /* K95 initialization options */
  1562.                                 if (*(yp+1)) {
  1563.                                     fatal("invalid argument bundling");
  1564.                                 }
  1565.                                 yargv++, yargc--;
  1566.                                 if (yargc < 1)
  1567.                                   fatal("-# argument missing");
  1568.                                 startflags |= atol(*yargv);
  1569.                                 break;
  1570. #endif /* OS2 */
  1571.                             }
  1572.                             if (!yp)
  1573.                               break;
  1574.                             x = *++yp;
  1575.                         }
  1576.                     }
  1577.                 }
  1578.                 return;
  1579.             }
  1580.         }
  1581.         /* after this point non-Kermit personalities must return */
  1582.         switch (howcalled) {
  1583.       case I_AM_KERMIT:
  1584.       case I_AM_IKSD:
  1585.       case I_AM_SSHSUB:
  1586.             break;
  1587.       default:
  1588.             return;
  1589.         }
  1590. #endif /* NOURL */
  1591.  
  1592. #ifndef NOICP
  1593.         /* If it is not a URL that we recognize, try to treat it as a file */
  1594.  
  1595.         if (!isabsolute(yargv[1]))      /* If not absolute */
  1596.           s = findinpath(yargv[1]);     /* Look in PATH */
  1597.         else
  1598.           s = yargv[1];
  1599.         if (!s)
  1600.           doexit(BAD_EXIT,xitsta);
  1601.         zfnqfp(s,CKMAXPATH,cmdfil);     /* In case of CD in file */
  1602.         yargc -= 1;                     /* Skip past the filename */
  1603.         yargv += 1;                     /* Otherwise we'll get an error */
  1604. #endif /* NOICP */
  1605.     }
  1606.  
  1607. #ifndef NOCMDL
  1608. #ifdef NEWFTP
  1609.     if (howcalled == I_AM_FTP) {        /* Kermit's FTP client personality */
  1610.         while (--yargc > 0) {           /* Go through command-line args */
  1611.             yargv++;                    /* looking for -Y and -d */
  1612.             yp = *yargv+1;
  1613.             if (**yargv == '-') {
  1614.                 x = *(*yargv+1);
  1615.                 while (x) {
  1616.                     switch (x) {
  1617.                       case 'Y':
  1618.                         noinit++;
  1619.                         break;
  1620.                       case 'h':
  1621.                         noinit = 1;
  1622. #ifdef OS2
  1623.                         startflags |= 2;    /* No network DLLs */
  1624.                         startflags |= 4;    /* No TAPI DLLs */
  1625.                         startflags |= 8;    /* No Security DLLs */
  1626.                         startflags |= 16;   /* No Zmodem DLLs */
  1627.                         startflags |= 32;   /* Stdin */
  1628.                         startflags |= 64;   /* Stdout */
  1629. #endif /* OS2 */
  1630.                         break;
  1631.                       case 'd':             /* = SET DEBUG ON */
  1632. #ifdef DEBUG
  1633.                         if (debcount++ > 0)
  1634.                           debtim = 1;
  1635.                         if (!deblog)
  1636.                           deblog = debopn("debug.log",0);
  1637. #endif /* DEBUG */
  1638.                         break;
  1639. #ifdef OS2
  1640.                       case 'W':
  1641.                         if (*(yp+1))
  1642.                           fatal("invalid argument bundling after -W");
  1643.                         yargv++, yargc--;
  1644.                         if (yargc < 1)
  1645.                           fatal("Window handle missing");
  1646.                         hwndDialer = (HWND) atol(*yargv);
  1647.                         StartedFromDialer = 1;
  1648.                         yargv++, yargc--;
  1649.                         KermitDialerID = atol(*yargv) ;
  1650.                         break;
  1651.                       case '#':         /* K95 initialization options */
  1652.                         if (*(yp+1)) {
  1653.                             fatal("invalid argument bundling");
  1654.                         }
  1655.                         yargv++, yargc--;
  1656.                         if (yargc < 1)
  1657.                           fatal("-# argument missing");
  1658.                         startflags |= atol(*yargv);
  1659.                         break;
  1660. #endif /* OS2 */
  1661.                     }
  1662.                     if (!yp)
  1663.                       break;
  1664.                     x = *++yp;
  1665.                 }
  1666.             }
  1667.         }
  1668.         return;
  1669.     }
  1670. #endif /* NEWFTP */
  1671. #endif /* NOCMDL */
  1672.  
  1673.     while (--yargc > 0) {               /* Go through command-line args */
  1674.         yargv++;
  1675.         yp = *yargv+1;                  /* Pointer for bundled args */
  1676.         if (**yargv == '=')             /* Same rules as cmdlin()... */
  1677.           return;
  1678.         debug(F110,"prescan *yargv",*yargv,0);
  1679.  
  1680. #ifndef NOICP
  1681. #ifdef KERBANG
  1682.         yy = *yargv;
  1683.         if (!strcmp(yy,"+") || (*yy == '+' && *(yy+1) < (char)33)) {
  1684.             char * s;
  1685.             yargv++;
  1686.             noinit = 1;
  1687.             if (!*yargv)
  1688.               return;
  1689.             cfilef = 1;
  1690.             s = findinpath(*yargv);
  1691.             if (s) {
  1692.                 zfnqfp(s,CKMAXPATH,cmdfil);
  1693.                 return;
  1694.             } else
  1695.               doexit(BAD_EXIT,xitsta);
  1696.         }
  1697. #endif /* KERBANG */
  1698. #endif /* NOICP */
  1699.         if (!strcmp(*yargv,"--"))       /* getopt() conformance */
  1700.           return;
  1701. #ifdef VMS
  1702.         else if (**yargv == '/')
  1703.           continue;
  1704. #endif /* VMS */
  1705.         else if (**yargv == '-') {      /* Got an option (begins with dash) */
  1706.             x = *(*yargv+1);            /* Get option letter */
  1707.             while (x) {                 /* Allow for bundled options */
  1708.                 debug(F000,"prescan arg","",x);
  1709.                 switch (x) {
  1710. #ifndef NOICP
  1711.                   case '+':
  1712.                   case '-':
  1713.                     if (doxarg(yargv,1) < 0) {
  1714.                         fatal("Extended argument error");
  1715.                     }
  1716.                     yargv++, yargc--;
  1717.                     yp = *yargv;
  1718.                     break;
  1719. #endif /* NOICP */
  1720.  
  1721.                   case '7':             /* Undocumented... */
  1722.                     sstelnet = 1;       /* (because it doesn't work) */
  1723.                     break;
  1724. #ifdef IKSD
  1725.                   case 'A': {
  1726.                       char * p;
  1727.                       inserver = 1;     /* Flag that we are doing this */
  1728.                       srvcdmsg = 2;     /* Preset this */
  1729.                       /* See inserver section of ckcmai.c for more settings */
  1730. #ifdef OS2
  1731.                       if (*(yp+1)) {
  1732.                           fatal("invalid argument bundling after -A");
  1733.                       }
  1734. #ifdef NT
  1735.                       /* Support for Pragma Systems Telnet/Terminal Servers */
  1736.                       p = getenv("PRAGMASYS_INETD_SOCK");
  1737.                       if (p && atoi(p) != 0) {
  1738.                           ttname[0] = '$';
  1739.                           ckstrncpy(&ttname[1],p,TTNAMLEN-1);
  1740.                           break;
  1741.                       }
  1742. #endif /* NT */
  1743.                       yargv++, yargc--;
  1744.                       if (yargc < 1 || **yargv == '-') {
  1745.                           fatal("-A argument missing");
  1746.                       } else {
  1747.                           ttname[0] = '$';
  1748.                           ckstrncpy(&ttname[1],*yargv,TTNAMLEN-1);
  1749.                       }
  1750. #endif /* OS2 */
  1751.                       break;
  1752.                   }
  1753. #endif /* IKSD */
  1754.  
  1755. #ifdef OS2
  1756.                   case 'W':
  1757.                     if (*(yp+1))
  1758.                       fatal("invalid argument bundling after -W");
  1759.                     yargv++, yargc--;
  1760.                     if (yargc < 1)
  1761.                       fatal("Window handle missing");
  1762. #ifdef COMMENT
  1763.                     if (dummy) {
  1764.                         yargv++, yargc--;
  1765.                         break;
  1766.                     } else {
  1767. #endif /* COMMENT */
  1768.                         hwndDialer = (HWND) atol(*yargv);
  1769.                         StartedFromDialer = 1;
  1770.                         yargv++, yargc--;
  1771.                         KermitDialerID = atol(*yargv) ;
  1772. #ifdef COMMENT
  1773.                     }
  1774. #endif /* COMMENT */
  1775.                     break;
  1776.  
  1777.                   case '#':             /* K95 initialization options */
  1778.                     if (*(yp+1)) {
  1779.                         fatal("invalid argument bundling");
  1780.                     }
  1781.                     yargv++, yargc--;
  1782.                     if (yargc < 1)
  1783.                       fatal("-# argument missing");
  1784.                     startflags |= atol(*yargv);
  1785.                     break;
  1786. #endif /* OS2 */
  1787.  
  1788. #ifndef NOSPL
  1789.                   case 'M':                             /* My User Name */
  1790.                     if (*(yp+1)) {
  1791.                         fatal("invalid argument bundling");
  1792.                     }
  1793.                     yargv++, yargc--;
  1794.                     if ((yargc < 1) || (**yargv == '-')) {
  1795.                         fatal("missing username");
  1796.                     }
  1797.                     if ((int)strlen(*yargv) > UIDBUFLEN) {
  1798.                         fatal("username too long");
  1799.                     }
  1800. #ifdef COMMENT
  1801. /*
  1802.   This can't work.  uidbuf is overwritten in sysinit() which has yet to be
  1803.   called.  This cannot be set in prescan().
  1804. */
  1805. #ifdef IKSD
  1806.                     if (!inserver)
  1807. #endif /* IKSD */
  1808.                       ckstrncpy(uidbuf,*yargv,UIDBUFLEN);
  1809. #endif /* COMMENT */
  1810.                     break;
  1811. #endif /* NOSPL */
  1812.                   case 'R':             /* Remote-only advisory */
  1813. #ifdef CK_IFRO
  1814.                     remonly = 1;
  1815. #endif /* CK_IFRO */
  1816.                     break;
  1817.                   case 'S':             /* STAY */
  1818.                     stayflg = 1;
  1819.                     break;
  1820.                   case 'h':
  1821.                     noinit = 1;
  1822. #ifdef OS2
  1823.                     startflags |= 2;    /* No network DLLs */
  1824.                     startflags |= 4;    /* No TAPI DLLs */
  1825.                     startflags |= 8;    /* No Security DLLs */
  1826.                     startflags |= 16;   /* No Zmodem DLLs */
  1827.                     startflags |= 32;   /* Stdin */
  1828.                     startflags |= 64;   /* Stdout */
  1829. #endif /* OS2 */
  1830.                     break;
  1831. #ifndef NOICP
  1832.                   case 'Y':             /* No init file */
  1833.                     noinit = 1;
  1834.                     break;
  1835. #endif /* NOICP */
  1836.                   case 'd':             /* = SET DEBUG ON */
  1837. #ifdef DEBUG
  1838.                     if (debcount++ > 0)
  1839.                       debtim = 1;
  1840.                     if (!deblog)
  1841.                       deblog = debopn("debug.log",0);
  1842. #endif /* DEBUG */
  1843.                     break;
  1844.  
  1845.                   case 'x':             /* Server */
  1846.                     arg_x = 1;          /* Note in advance */
  1847.                     break;
  1848. #ifndef NOICP
  1849.                   case 'y':             /* Alternative init file */
  1850.                     noinit = 0;
  1851.                     yargv++, yargc--;
  1852.                     if (yargc < 1) fatal("missing name in -y");
  1853.                     /* Replace init file name */
  1854.                     ckstrncpy(kermrc,*yargv,KERMRCL);
  1855.                     rcflag = 1;         /* Flag that this has been done */
  1856.                     debug(F111,"prescan kermrc",kermrc,rcflag);
  1857.                     break;
  1858. #endif /* NOICP */
  1859.                   case 'z':             /* = SET BACKGROUND OFF */
  1860.                     bgset = 0;
  1861.                     backgrd = 0;
  1862. #ifdef VMS
  1863.                     batch = 0;
  1864. #endif /* VMS */
  1865.                     break;
  1866.  
  1867.                   case 'B':             /* Force background (batch) */
  1868.                     bgset = 1;
  1869.                     backgrd = 1;
  1870. #ifdef VMS
  1871.                     batch = 1;
  1872. #endif /* VMS */
  1873.                     break;
  1874.  
  1875. #ifdef CK_NETBIOS
  1876.                   case 'N':
  1877.                     {
  1878.                         int n ;
  1879.                         yargv++, yargc--;
  1880. #ifdef COMMENT
  1881.                         if (y)
  1882.                           break;
  1883. #endif /* COMMENT */
  1884.                         if (strlen(*yargv) != 1 || (*yargv)[0] == 'X') {
  1885.                             NetBiosAdapter = -1;
  1886.                         } else {
  1887.                             n = atoi(*yargv);
  1888.                             if (n >= 0 && n <= 9)
  1889.                               NetBiosAdapter = n;
  1890.                             else
  1891.                               NetBiosAdapter = -1;
  1892.                         }
  1893.                     }
  1894.                     break;
  1895. #endif /* CK_NETBIOS */
  1896.                   default:
  1897.                     break;
  1898.                 }
  1899.                 if (!yp)
  1900.                   break;
  1901.                 x = *++yp;              /* See if options are bundled */
  1902.             }
  1903.         }
  1904.     }
  1905. #endif /* NOCMDL */
  1906. }
  1907.  
  1908. /*  G E T T C S  --  Get Transfer (Intermediate) Character Set  */
  1909.  
  1910. /*
  1911.   Given two file character sets, this routine picks out the appropriate
  1912.   "transfer" character set to use for translating between them.
  1913.   The transfer character set number is returned.
  1914.  
  1915.   Translation between two file character sets is done, for example,
  1916.   by the CONNECT, TRANSMIT, and TRANSLATE commands.
  1917.  
  1918.   Translation between Kanji character sets is not yet supported.
  1919. */
  1920. int
  1921. gettcs(cs1,cs2) int cs1, cs2; {
  1922. #ifdef NOCSETS                          /* No character-set support */
  1923.     return(0);                          /* so no translation */
  1924. #else
  1925.     int tcs = TC_TRANSP;
  1926. #ifdef KANJI
  1927. /* Kanji not supported yet */
  1928.     if (fcsinfo[cs1].alphabet == AL_JAPAN ||
  1929.         fcsinfo[cs2].alphabet == AL_JAPAN )
  1930.       tcs = TC_TRANSP;
  1931.     else
  1932. #endif /* KANJI */
  1933. #ifdef CYRILLIC
  1934. /*
  1935.   I can't remember why we don't test both sets here, but I think there
  1936.   must have been a reason...
  1937. */
  1938.       if (fcsinfo[cs2].alphabet == AL_CYRIL)
  1939.         tcs = TC_CYRILL;
  1940.       else
  1941. #endif /* CYRILLIC */
  1942. #ifdef HEBREW
  1943.           if (fcsinfo[cs1].alphabet == AL_HEBREW ||
  1944.               fcsinfo[cs2].alphabet == AL_HEBREW )
  1945.             tcs = TC_HEBREW;
  1946.           else
  1947. #endif /* HEBREW */
  1948. #ifdef GREEK
  1949.           if (fcsinfo[cs1].alphabet == AL_GREEK ||
  1950.               fcsinfo[cs2].alphabet == AL_GREEK )
  1951.             tcs = TC_GREEK;
  1952.           else
  1953. #endif /* GREEK */
  1954.  
  1955.             /* Roman sets ... */
  1956.  
  1957. #ifdef LATIN2                           /* East European */
  1958.         if (cs1 == FC_2LATIN  || cs2 == FC_2LATIN || /* Latin-2 */
  1959.             cs1 == FC_CP852   || cs2 == FC_CP852  || /* CP852 */
  1960.             cs1 == FC_CP1250  || cs2 == FC_CP1250 || /* Windows Latin-2 */
  1961.             cs1 == FC_MAZOVIA || cs2 == FC_MAZOVIA)  /* Polish Mazovia */
  1962.           tcs = TC_2LATIN;
  1963.         else
  1964. #endif /* LATIN2 */
  1965.                                         /* West European Euro-aware */
  1966.           if (cs1 == FC_CP858 || cs1 == FC_9LATIN ||
  1967.               cs2 == FC_CP858 || cs2 == FC_9LATIN)
  1968.             tcs = TC_9LATIN;
  1969.           else                          /* Traditional West European */
  1970.             tcs = TC_1LATIN;
  1971.     return(tcs);
  1972. #endif /* NOCSETS */
  1973. }
  1974.  
  1975. #ifndef NOLOCAL
  1976. /*  D O C O N E C T  --  Do the connect command  */
  1977. /*
  1978.   q = 0 means issue normal informational message about how to get back, etc.
  1979.   q != 0 means to skip the message.
  1980. */
  1981.  
  1982. int
  1983. doconect(q,async) int q, async; {
  1984.     int x;                              /* Return code */
  1985. #ifdef CK_AUTODL
  1986.     extern CHAR ksbuf[];
  1987. #endif /* CK_AUTODL */
  1988. #ifndef NOKVERBS                        /* Keyboard macro material */
  1989.     extern int keymac, keymacx;
  1990. #endif /* NOKVERBS */
  1991.     extern int justone, adl_err;
  1992.     int qsave;                          /* For remembering "quiet" value */
  1993. #ifdef OS2
  1994.     extern int term_io;
  1995.     extern int display_demo;
  1996.     int term_io_save;
  1997. #ifdef KUI
  1998.     extern int kui_async;
  1999. #endif /* KUI */
  2000. #endif /* OS2 */
  2001.     int is_tn = 0;
  2002.  
  2003. #ifdef IKSD
  2004.     if (inserver) {
  2005.         if (!quiet)
  2006.           printf("?Sorry, IKSD cannot CONNECT.\r\n");
  2007.         return(success = 0);
  2008.     }
  2009. #endif /* IKSD */
  2010.  
  2011.     is_tn =
  2012. #ifdef TNCODE
  2013.       (local && network && IS_TELNET()) || (!local && sstelnet)
  2014. #else
  2015.         0
  2016. #endif /* TNCODE */
  2017.           ;
  2018. /*
  2019.   Saving, changing, and restoring the global "quiet" variable around calls
  2020.   to conect() to control whether the verbose CONNECT message is printed is
  2021.   obviously less elegant than passing a parameter to conect(), but we do it
  2022.   this way to avoid the need to change all of the ck?con.c modules.  NOTE:
  2023.   it is important to restore the value immediately upon return in case there
  2024.   is an autodownload or APC.
  2025. */
  2026.     qsave = quiet;                      /* Save it */
  2027.     if (!quiet && q > -1)
  2028.       quiet = q;                        /* Use argument temporarily */
  2029.     conres();                           /* Put console back to normal */
  2030.     debug(F101,"doconect justone 1","",justone);
  2031. #ifdef CK_AUTODL
  2032.     ksbuf[0] = NUL;                     /* Autodownload packet buffer */
  2033. #endif /* CK_AUTODL */
  2034. #ifdef OS2
  2035.     display_demo = 1;                   /* Remember to display demo */
  2036. #endif /* OS2 */
  2037.  
  2038. #ifdef IKS_OPTION
  2039.     if (is_tn && TELOPT_U(TELOPT_KERMIT) && ttchk() >= 0
  2040. #ifdef OS2
  2041.        && !viewonly
  2042. #endif /* OS2 */
  2043.         ) {
  2044.         /* If the remote side is in a state of IKS START-SERVER    */
  2045.         /* we request that the state be changed.  We will detect   */
  2046.         /* a failure to adhere to the request when we call ttinc() */
  2047.         if (!iks_wait(KERMIT_REQ_STOP,0) && !tcp_incoming) {
  2048.             if (!quiet) {
  2049.                 printf("\r\nEnter Client/Server Mode...  Use:\r\n\r\n");
  2050.                 printf(
  2051. " REMOTE LOGIN <user> <password> to log in to the server if necessary.\r\n");
  2052.                 printf(" SEND and GET for file transfer.\r\n");
  2053.                 printf(" REMOTE commands for file management.\r\n");
  2054.                 printf(" FINISH to terminate Client/Server mode.\r\n");
  2055.                 printf(" BYE to terminate and close connection.\r\n");
  2056.                 printf(" REMOTE HELP for additional information.\r\n\r\n");
  2057.             }
  2058.             quiet = qsave;
  2059.             return(0);      /* Failure */
  2060.         }
  2061.     }
  2062.  
  2063.     /* Let our peer know our state. */
  2064. #ifdef CK_AUTODL
  2065.     if (is_tn && TELOPT_ME(TELOPT_KERMIT)
  2066. #ifdef OS2
  2067.         && !viewonly
  2068. #endif /* OS2 */
  2069.          ) {
  2070.         if (autodl && !TELOPT_SB(TELOPT_KERMIT).kermit.me_start) {
  2071.             tn_siks(KERMIT_START);      /* Send Kermit-Server Start */
  2072.         } else if (!autodl && TELOPT_SB(TELOPT_KERMIT).kermit.me_start) {
  2073.             tn_siks(KERMIT_STOP);
  2074.         }
  2075.     }
  2076. #else /* CK_AUTODL */
  2077.     if (is_tn && TELOPT_ME(TELOPT_KERMIT) &&
  2078.     TELOPT_SB(TELOPT_KERMIT).kermit.me_start)
  2079.         tn_siks(KERMIT_STOP);
  2080. #endif /* CK_AUTODL */
  2081. #endif /* IKS_OPTION */
  2082.  
  2083.     debug(F101,"doconect flow","",flow);
  2084. #ifdef OS2
  2085.     debug(F101,"doconect async","",async);
  2086. #ifdef KUI
  2087.     if (kui_async)
  2088.       async = 1;;
  2089. #endif /* KUI */
  2090.     x = conect(async);                  /* Connect the first time */
  2091. #else /* OS2 */
  2092.     x = conect();
  2093. #endif /* OS2 */
  2094.     debok = 1;
  2095.  
  2096. #ifdef IKS_OPTION
  2097.     if (TELOPT_U(TELOPT_KERMIT) &&
  2098.         TELOPT_SB(TELOPT_KERMIT).kermit.u_start &&
  2099.         !tcp_incoming && !quiet && ttchk() >= 0
  2100.         ) {
  2101.         printf("\r\nEnter Client/Server Mode...  Use:\r\n\r\n");
  2102.         printf(
  2103. " REMOTE LOGIN <user> <password> to log in to the server if necessary.\r\n");
  2104.         printf(" SEND and GET for file transfer.\r\n");
  2105.         printf(" REMOTE commands for file management.\r\n");
  2106.         printf(" FINISH to terminate Client/Server mode.\r\n");
  2107.         printf(" BYE to terminate and close connection.\r\n");
  2108.         printf(" REMOTE HELP for additional information.\r\n\r\n");
  2109.     }
  2110. #endif /* IKS_OPTION */
  2111.  
  2112.     quiet = qsave;                      /* Restore "quiet" value */
  2113.     debug(F101,"doconect justone 2","",justone);
  2114.  
  2115. #ifdef NETCONN
  2116.     if (network && tn_exit && ttchk() < 0)
  2117.       doexit(GOOD_EXIT,xitsta);         /* Exit with good status */
  2118. #endif /* NETCONN */
  2119.  
  2120. #ifdef OS2ORUNIX
  2121.     /* Exit on disconnect if the port is not open or carrier detect */
  2122.     if (exitonclose && (ttchk() < 0))
  2123.       doexit(GOOD_EXIT,xitsta);
  2124. #endif /* OS2ORUNIX */
  2125.  
  2126. #ifdef CKCONINTB4CB
  2127.     /* The order makes a difference in HP-UX 8.00. */
  2128.     /* The other order makes it think it's in the background when it */
  2129.     /* returns from CONNECT (Apr 1999). */
  2130.     setint();
  2131.     concb((char)escape);                /* Restore console for commands */
  2132. #else
  2133.     /* This is how it has always been so better leave it */
  2134.     /* this way for all non-HP-UX-8.00 builds. */
  2135.     concb((char)escape);                /* Restore console for commands */
  2136.     setint();
  2137. #endif /* CKCONINTB4CB */
  2138.  
  2139. #ifdef OS2
  2140.     if (!async) {
  2141.         term_io_save = term_io;         /* Disable I/O by emulator */
  2142.         term_io = 0;
  2143. #endif /* OS2 */
  2144.  
  2145. #ifdef CK_APC
  2146. /*
  2147.   If an APC command was received during CONNECT mode, we define it now
  2148.   as a macro, execute the macro, and then return to CONNECT mode.
  2149.   We do this in a WHILE loop in case additional APCs come during subsequent
  2150.   CONNECT sessions.
  2151. */
  2152.         debug(F101,"doconect apcactive","",apcactive);
  2153.         debug(F101,"doconect success","",success);
  2154.  
  2155.         while (x > 0 && (apcactive == APC_LOCAL ||
  2156.                          (apcactive == APC_REMOTE && apcstatus != APC_OFF))) {
  2157.             debug(F101,"doconect justone 3","",justone);
  2158.             if (mlook(mactab,"_apc_commands",nmac) == -1) {
  2159.                 debug(F110,"doconect about to execute APC",apcbuf,0);
  2160.                 domac("_apc_commands",apcbuf,cmdstk[cmdlvl].ccflgs|CF_APC);
  2161.                 delmac("_apc_commands",1);
  2162. #ifdef DEBUG
  2163.             } else {
  2164.                 debug(F100,"doconect APC in progress","",0);
  2165. #endif /* DEBUG */
  2166.             }
  2167.             debug(F101,"doconect apcactive after domac","",apcactive);
  2168.             if (!apcactive) {               /* In case CLEAR APC was in APC */
  2169.                 debug(F101,"doconect quit APC loop: apcactive","",apcactive);
  2170.                 break;
  2171.             }
  2172.             /* Also don't reconnect if autodownload failed - very confusing! */
  2173.             /* Let them view the local screen to see what happened. - fdc */
  2174.  
  2175.             /* This should be conditional.  If someone is relying on the */
  2176.             /* connect mode autodownload for the kermit server to use with */
  2177.             /* a remotely executed script we should be able to return to */
  2178.             /* connect mode on the failure.  What we really need to do is */
  2179.             /* report the status of the transfer and then return to CONNECT. */
  2180.             /* In unix this would simply be a printf(), but in K95 it could */
  2181.             /* use a popup dialog to report the status. - Jeff */
  2182.  
  2183. #ifndef NOXFER
  2184.             debug(F101,"doconect xferstat","",xferstat);
  2185.             if (apcactive == APC_LOCAL && !xferstat && adl_err != 0) {
  2186.                 debug(F101,"doconect quit APC loop: xferstat","",xferstat);
  2187.                 apcactive = APC_INACTIVE;
  2188.                 break;
  2189.             }
  2190. #endif /* NOXFER */
  2191. #ifdef OS2
  2192.             msleep(250);
  2193. #endif /* OS2 */
  2194.             debug(F101,"doconect justone 4","",justone);
  2195.             qsave = quiet;              /* Do this again... */
  2196.             if (!quiet && q > -1)
  2197.               quiet = q;
  2198. #ifdef CK_AUTODL
  2199.             ksbuf[0] = NUL;
  2200. #endif /* CK_AUTODL */
  2201. #ifdef IKS_OPTION
  2202. #ifdef CK_AUTODL
  2203.             if (is_tn &&
  2204.                 TELOPT_ME(TELOPT_KERMIT) &&
  2205.                 !TELOPT_SB(TELOPT_KERMIT).kermit.me_start &&
  2206.                 autodl
  2207. #ifdef CK_APC
  2208.                 && !apcactive
  2209. #endif /* CK_APC */
  2210. #ifdef OS2
  2211.                 && !viewonly
  2212. #endif /* OS2 */
  2213.                 ) {
  2214.                 tn_siks(KERMIT_START);  /* Send Kermit-Server Start */
  2215.             }
  2216. #endif /* CK_AUTODL */
  2217. #endif /* IKS_OPTION */
  2218. #ifndef OS2
  2219.             x = conect();               /* Re-CONNECT. */
  2220. #else /* OS2 */
  2221.             x = conect(0);
  2222.             term_io = term_io_save;
  2223. #endif /* OS2 */
  2224.             debok = 1;
  2225.             quiet = qsave;
  2226.             debug(F101,"doconect justone 5","",justone);
  2227. #ifdef NETCONN
  2228.             if (network && ttchk() < 0) {
  2229.                 if (tn_exit || exitonclose)
  2230.                   doexit(GOOD_EXIT,xitsta);
  2231.                 else
  2232.                   break;
  2233.             }
  2234. #endif /* NETCONN */
  2235.  
  2236. #ifdef OS2ORUNIX
  2237.             /* If connection dropped */
  2238.             if (ttchk() < 0) {
  2239.                 concb((char)escape);    /* Restore console. */
  2240.                 if (exitonclose)
  2241.                   doexit(GOOD_EXIT,xitsta);
  2242.                 else
  2243.                   break;
  2244.             }
  2245. #endif /* OS2ORUNIX */
  2246.         } /* Loop back for more. */
  2247. #endif /* CK_APC */
  2248.  
  2249. #ifndef NOKVERBS
  2250.         if ((keymac > 0) && (keymacx > -1)) { /* Executing a keyboard macro? */
  2251.             /* Set up the macro and return */
  2252.             /* Do not clear the keymac flag */
  2253.             return(dodo(keymacx,NULL,CF_KMAC|cmdstk[cmdlvl].ccflgs));
  2254.         }
  2255. #endif /* NOKVERBS */
  2256. #ifdef OS2
  2257.         term_io = term_io_save;
  2258.     } /* if (!async) */
  2259. #endif /* OS2 */
  2260.  
  2261. #ifdef CKCONINTB4CB
  2262.     /* The order makes a difference in HP-UX 8.00. */
  2263.     /* The other order makes it think it's in the background when it */
  2264.     /* returns from CONNECT (Apr 1999). */
  2265.     setint();
  2266.     concb((char)escape);                /* Restore console for commands */
  2267. #else
  2268.     /* This is how it has always been so better leave it */
  2269.     /* this way for all non-HP-UX-8.00 builds. */
  2270.     concb((char)escape);                /* Restore console for commands */
  2271.     setint();
  2272. #endif /* CKCONINTB4CB */
  2273. #ifdef OS2
  2274.     if (!async)
  2275. #endif /* OS2 */
  2276.       what = W_COMMAND;                 /* Back in command mode. */
  2277.     return(x);                          /* Done. */
  2278. }
  2279. #endif /* NOLOCAL */
  2280.  
  2281. #ifndef NOICP
  2282. #ifdef COMMENT
  2283. /*
  2284.   It seemed that this was needed for OS/2, in which \v(cmdfile) and other
  2285.   file-oriented variables or functions can return filenames containing
  2286.   backslashes, which are subsequently interpreted as quotes rather than
  2287.   directory separators (e.g. see commented section for VN_CMDF below).
  2288.   But the problem can't be cured at this level.  Example:
  2289.  
  2290.     type \v(cmdfile)
  2291.  
  2292.   Without doubling, the filename is parsed correctly, but then when passed
  2293.   to UNIX 'cat' through the shell, the backslash is removed, and then cat
  2294.   can't open the file.  With doubling, the filename is not parsed correctly
  2295.   and the TYPE command fails immediately with a "file not found" error.
  2296. */
  2297. /*
  2298.   Utility routine to double all backslashes in a string.
  2299.   s1 is pointer to source string, s2 is pointer to destination string,
  2300.   n is length of destination string, both NUL-terminated.
  2301.   Returns 0 if OK, -1 if not OK (destination string too short).
  2302. */
  2303. int
  2304. dblbs(s1,s2,n) char *s1, *s2; int n; {
  2305.     int i = 0;
  2306.     while (*s1) {
  2307.         if (*s1 == '\\') {
  2308.             if (++i > n) return(-1);
  2309.             *s2++ = '\\';
  2310.         }
  2311.         if (++i > n) return(-1);
  2312.         *s2++ = *s1++;
  2313.     }
  2314.     *s2 = NUL;
  2315.     return(0);
  2316. }
  2317. #endif /* COMMENT */
  2318.  
  2319. char *
  2320. gmdmtyp() {                             /* Get modem type */
  2321. #ifndef NODIAL
  2322.     int i, x;
  2323.  
  2324.     debug(F111,"gmdmtyp","mdmtyp",mdmtyp);
  2325.     debug(F111,"gmdmtyp","mdmsav",mdmsav);
  2326.  
  2327.     x = mdmtyp;
  2328.     if (x < 0)                          /* In case of network dialing */
  2329.       x = mdmsav;
  2330.     if (x < 1)
  2331.       return("none");
  2332.     else
  2333.       for (i = 0; i < nmdm; i++)
  2334.         if ((mdmtab[i].kwval == x) && (mdmtab[i].flgs == 0))
  2335.           return(mdmtab[i].kwd);
  2336. #endif /* NODIAL */
  2337.     return("none");
  2338. }
  2339.  
  2340. #ifndef NOXMIT
  2341. #ifndef NOLOCAL
  2342. /*  T R A N S M I T  --  Raw upload  */
  2343.  
  2344. /*  Obey current line, duplex, parity, flow, text/binary settings. */
  2345. /*  Returns 0 upon apparent success, 1 on obvious failure.  */
  2346.  
  2347. /***
  2348.  Things to add:
  2349.  . Make both text and binary mode obey set file bytesize.
  2350.  . Maybe allow user to specify terminators other than CR?
  2351.  . Maybe allow user to specify prompts other than single characters?
  2352.  . Make STATISTICS also work for TRANSMIT.
  2353.  . If TRANSMIT is done without echo, make some kind of (optional) display.
  2354.  . Make the same optimization for binary-mode transmit that was done for
  2355.    text-mode (in the no-echo / no-prompt / no-pause case).
  2356. ***/
  2357.  
  2358. /*  T R A N S M I T  --  Raw upload  */
  2359.  
  2360. /*  s is the filename, t is the turnaround (prompt) character  */
  2361.  
  2362. /*
  2363.   Maximum number of characters to buffer.
  2364.   Must be less than LINBUFSIZ
  2365. */
  2366. #ifdef OS2
  2367. #define XMBUFS 4096                     /* For compatibility with XYZmodem */
  2368. #else /* OS2 */
  2369. #define XMBUFS 1024
  2370. #endif /* OS2 */
  2371.  
  2372. #ifdef TNCODE
  2373. #ifndef IAC
  2374. #define IAC 255
  2375. #endif /* IAC */
  2376. #endif /* TNCODE */
  2377.  
  2378. #define OUTXBUFSIZ 15
  2379. static CHAR inxbuf[OUTXBUFSIZ+1];       /* Host-to-screen expansion buffer */
  2380. static int inxcount = 0;                /* and count */
  2381. static CHAR outxbuf[OUTXBUFSIZ+1];      /* Keyboard-to-host expansion buf */
  2382. static int outxcount = 0;               /* and count */
  2383.  
  2384. /*  T R A N S M I T  --  Unguarded non-protocol file transmission  */
  2385. /*
  2386.   Call with:
  2387.     char * s:   Name of file to transmit.
  2388.     char t:     Turnaround char for text-mode transmission (normally LF).
  2389.     int xlate:  nonzero = charset translation for text-mode xfer, 0 = skip.
  2390.     int binary: nonzero = transmit in binary mode, 0 = in text mode.
  2391. */
  2392. #define XBBUFSIZ 252                    /* For binary blasting */
  2393. static CHAR xbbuf[XBBUFSIZ+4];
  2394.  
  2395. int
  2396. #ifdef CK_ANSIC
  2397. transmit(char * s, char t, int xlate, int binary, int xxecho)
  2398. #else
  2399. transmit(s,t,xlate,binary,xxecho) char *s; char t; int xlate, binary, xxecho;
  2400. #endif /* CK_ANSIC */
  2401. /* transmit */ {
  2402. #ifdef MAC
  2403.     extern char sstate;
  2404.     int count = 100;
  2405. #else
  2406.     int count = 0;
  2407. #ifdef OS2
  2408. #ifdef NT
  2409.     SIGTYP (* oldsig)(int);             /* For saving old interrupt trap. */
  2410. #else /* NT */
  2411.     SIGTYP (* volatile oldsig)(int);
  2412. #endif /* NT */
  2413.  
  2414. #else /* OS2 */
  2415.     SIGTYP (* oldsig)();
  2416. #endif /* OS2 */
  2417. #endif /* MAC */
  2418.     int eof = 0;                        /* End of File flag */
  2419.     int eol = 0;                        /* End of Line flag */
  2420.     int rc = 1;                         /* Return code. 0=fail, 1=succeed. */
  2421.     int myflow;                         /* Local copy of global flow... */
  2422.     int is_tn = 0;                      /* Do Telnet negotiations */
  2423.     int xbufsiz = XMBUFS;               /* Size of TRANSMIT buffer */
  2424.     int x, y, c, i;                     /* Int workers... */
  2425.     int control = 0;                    /* Echo loop control */
  2426.     long nbytes = 0;                    /* File byte count */
  2427.     long zz;                            /* Long worker */
  2428.     char *p;                            /* Char * worker */
  2429.  
  2430. #ifdef PIPESEND
  2431.     extern int pipesend;
  2432. #endif /* PIPESEND */
  2433.  
  2434. #ifndef NOCSETS
  2435.     int tcs = TC_TRANSP;                /* Intermediate (xfer) char set */
  2436.     int langsv = L_USASCII;             /* Save current language */
  2437.     int unicode = 0;
  2438.     int tcssize = 0;
  2439.  
  2440. #ifdef CK_ANSIC /* ANSI C prototypes... */
  2441.     CHAR (*sxo)(CHAR);
  2442.     CHAR (*rxo)(CHAR);
  2443.     CHAR (*sxi)(CHAR);
  2444.     CHAR (*rxi)(CHAR);
  2445. #else /* Not ANSI C... */
  2446.     CHAR (*sxo)();
  2447.     CHAR (*rxo)();
  2448.     CHAR (*sxi)();
  2449.     CHAR (*rxi)();
  2450. #endif /* CK_ANSIC */
  2451. #ifdef UNICODE
  2452.     union ck_short uc;
  2453.     int bomorder = 0;
  2454. #ifdef CK_ANSIC
  2455.     extern int (*xl_ufc[MAXFCSETS+1])(USHORT);  /* Unicode to FCS */
  2456.     extern USHORT (*xl_fcu[MAXFCSETS+1])(CHAR); /* FCS to Unicode */
  2457.     extern int (*xuf)(USHORT);
  2458.     extern USHORT (*xfu)(CHAR);
  2459. #else
  2460.     extern int (*xl_ufc[MAXFCSETS+1])();
  2461.     extern USHORT (*xl_fcu[MAXFCSETS+1])();
  2462.     extern int (*xuf)();
  2463.     extern USHORT (*xfu)();
  2464. #endif /* CK_ANSIC */
  2465. #endif /* UNICODE */
  2466. #endif /* NOCSETS */
  2467.  
  2468.     debug(F101,"xmit t","",t);
  2469.     debug(F101,"xmit xlate","",xlate);
  2470.     debug(F101,"xmit binary","",binary);
  2471.  
  2472. #ifdef PIPESEND
  2473.     if (pipesend) {
  2474.         if (nopush) return(-2);
  2475.         if (zxcmd(ZIFILE,s) < 1) {
  2476.             printf("?Can't start command: %s\n",s);
  2477.             return(0);
  2478.         }
  2479.     } else
  2480. #endif /* PIPESEND */
  2481.     if (zopeni(ZIFILE,s) == 0) {        /* Open the file to be transmitted */
  2482.         printf("?Can't open file %s\n",s);
  2483.         return(0);
  2484.     }
  2485.     x = -1;                             /* Open the communication channel */
  2486.     if (ttopen(ttname,&x,mdmtyp,cdtimo) < 0) {  /* (no harm if already open) */
  2487.         printf("Can't open device %s\n",ttname);
  2488.         return(0);
  2489.     }
  2490.     zz = x ? speed : -1L;
  2491.     if (binary) {                       /* Binary file transmission */
  2492.         myflow = (flow == FLO_XONX) ? FLO_NONE : flow;
  2493.  
  2494.         if (ttvt(zz,myflow) < 0) {      /* So no Xon/Xoff! */
  2495.             printf("Can't condition line\n");
  2496.             return(0);
  2497.         }
  2498.     } else {
  2499.         if (ttpkt(zz,flow,parity) < 0) { /* Put the line in "packet mode" */
  2500.             printf("Can't condition line\n"); /* so Xon/Xoff will work, etc. */
  2501.             return(0);
  2502.         }
  2503.     }
  2504.     is_tn =
  2505. #ifdef TNCODE
  2506.       (local && network && IS_TELNET()) || (!local && sstelnet)
  2507. #else
  2508.         0
  2509. #endif /* TNCODE */
  2510.           ;
  2511.  
  2512. #ifndef NOCSETS
  2513. /* Set up character set translations */
  2514.  
  2515.     tcs = 0;                            /* "Transfer" or "Other" charset */
  2516.     sxo = rxo = NULL;                   /* Initialize byte-to-byte functions */
  2517.     sxi = rxi = NULL;
  2518.     unicode = 0;                        /* Assume Unicode won't be involved */
  2519.     if (!binary && xlate) {             /* Set up charset translations */
  2520. /*
  2521.   In the SENDING direction, we are converting from the local file's
  2522.   character-set (fcharset) to the remote terminal charset (tcsr).  In the
  2523.   RECEIVING direction (echoing) we are converting from the remote end of the
  2524.   terminal charset (tcsr) to its local end (tcsl), which is not necessarily
  2525.   the same as the file character-set.  Especially when the file character
  2526.   set is UCS-2, which is not a valid terminal character set.  The various
  2527.   combinations are represented in this table:
  2528.  
  2529.   FCS = File Character Set
  2530.   RCS = Remote Terminal Character Set
  2531.   CCS = Console (Local Terminal) Character Set
  2532.  
  2533.    8   4   2   1
  2534.   FCS FCS RCS CCS
  2535.   UCS UTF UTF UTF
  2536.    0   0   0   0   =   0   =   No translation
  2537.    0   0   0   1   =   1   =   FCS -> RCS, Echo RCS -> UTF
  2538.    0   0   1   0   =   2   =   FCS -> UTF, Echo UTF -> CCS
  2539.    0   0   1   1   =   3   =   FCS -> UTF, Echo no translation
  2540.  
  2541.    0   1   0   0   =   4   =   UTF -> RCS, Echo RCS -> CCS
  2542.    0   1   0   1   =   5   =   UTF -> RCS, Echo RCS -> UTF
  2543.    0   1   1   0   =   6   =   UTF -> UTF, Echo UTF -> CCS
  2544.    0   1   1   1   =   7   =   No translation
  2545.  
  2546.    1   0   0   0   =   8   =   UCS -> RCS, Echo RCS -> CCS
  2547.    1   0   0   1   =   9   =   UCS -> RCS, Echo RCS -> UTF
  2548.    1   0   1   0   =  10   =   UCS -> UTF, Echo UTF -> CCS
  2549.    1   0   1   1   =  11   =   UCS -> UTF, Echo no translation
  2550. */
  2551. #ifdef UNICODE
  2552.         xfu = NULL;                     /* Unicode translation functions */
  2553.         xuf = NULL;
  2554.         bomorder = ucsorder;            /* UCS-2 byte order */
  2555.  
  2556.         if (fcharset == FC_UCS2)        /* File charset is UCS-2 */
  2557.           unicode |= 8;
  2558.         else if (fcharset == FC_UTF8)   /* File charset is UTF-8 */
  2559.           unicode |= 4;
  2560.         if (tcsr == FC_UTF8)            /* Remote term charset is UTF-8 */
  2561.           unicode |= 2;
  2562.         if (tcsl == FC_UTF8)            /* Local term charset is UTF-8 */
  2563.           unicode |= 1;
  2564. #endif /* UNICODE */
  2565. /*
  2566.   When Unicode not involved -- TCS is the intermediate (xfer) set, and:
  2567.   sxo = File-to-Intermediate charset function
  2568.   rxo = Intermediate-to-Remote-Terminal charset function
  2569.   sxi = Remote-Terminal-to-Intermediate
  2570.   rxi = Intermediate-to-Local-Terminal
  2571. */
  2572.         tcs = gettcs(tcsr,fcharset);    /* Get intermediate set. */
  2573.         sxo = xls[tcs][fcharset];       /* translation function */
  2574.         rxo = xlr[tcs][tcsr];           /* pointers for output functions */
  2575.         sxi = xls[tcs][tcsr];           /* and for input functions. */
  2576.         rxi = xlr[tcs][tcsl];
  2577. /*
  2578.   At this point we have unicode nonzero if Unicode is involved in the
  2579.   conversion, and to 0 if it is not.
  2580.   The following is to prevent use of zmstuff() and zdstuff() by translation
  2581.   functions (stuffing works with file i/o, not with communication i/o).
  2582. */
  2583.         langsv = language;              /* Save current SET LANGUAGE */
  2584.         language = L_USASCII;           /* No language-specific translations */
  2585.     }
  2586. #endif /* NOCSETS */
  2587.  
  2588.     i = 0;                              /* Beginning of buffer. */
  2589. #ifndef MAC
  2590. #ifndef AMIGA
  2591.     oldsig = signal(SIGINT, trtrap);    /* Save current interrupt trap. */
  2592. #endif /* AMIGA */
  2593. #endif /* MAC */
  2594.     tr_int = 0;                         /* Have not been interrupted (yet). */
  2595.     rc = 1;                             /* Return code presumed good. */
  2596. #ifdef VMS
  2597.     conres();
  2598. #endif /* VMS */
  2599.  
  2600. #ifndef NOCSETS
  2601.     debug(F101,"XMIT unicode","",unicode);
  2602. #ifdef UNICODE
  2603.     debug(F101,"XMIT bomorder","",bomorder);
  2604. #endif /* UNICODE */
  2605. #endif /* NOCSETS */
  2606.  
  2607.     c = 0;                              /* Initial condition */
  2608.     while (c > -1 && !eof) {            /* Loop for all characters in file */
  2609.         eol = 0;
  2610. #ifdef MAC
  2611.         /*
  2612.          * It is expensive to run the miniparser so don't do it for
  2613.          * every character.
  2614.          */
  2615.         if (--count < 0) {
  2616.             count = 100;
  2617.             miniparser(1);
  2618.             if (sstate == 'a') {
  2619.                 sstate = '\0';
  2620.                 goto xmitfail;
  2621.             }
  2622.         }
  2623. #else /* Not MAC */
  2624.         if (tr_int) {                   /* Interrupted? */
  2625.             printf("^C...\n");          /* Print message */
  2626.             goto xmitfail;
  2627.         }
  2628. #endif /* MAC */
  2629.         c = zminchar();                 /* Get a file character */
  2630. #ifdef COMMENT
  2631. /* too much */
  2632. #ifdef DEBUG
  2633.         if (deblog) {
  2634.             if (c < 0)
  2635.               debug(F101,"XMIT zminchar","",c);
  2636.             else
  2637.               debug(F000,"XMIT zminchar","",c);
  2638.         }
  2639. #endif /* DEBUG */
  2640. #endif /* COMMENT */
  2641.         if (c < -1) {                   /* Other error */
  2642.             printf("?TRANSMIT file read error: %s\n",ck_errstr());
  2643.             goto xmitfail;
  2644.         } else if (c > -1) {
  2645.             nbytes++;
  2646.             c &= fmask;                 /* Apply SET FILE BYTESIZE mask */
  2647.         } else if (c == -1) {
  2648.             eof = 1;
  2649.             debug(F101,"XMIT eof","",eof);
  2650.         }
  2651.         if (binary) {                   /* Binary... */
  2652.             if (c == -1) {              /* If EOF */
  2653.                 rc = 1;                 /* Success */
  2654.                 eof = 1;
  2655.                 goto xmitexit;          /* Done */
  2656.             }
  2657.             if (!xmitw && !xxecho) {    /* Special "blast" mode */
  2658.                 if (count == XBBUFSIZ) { /* File input buffer full... */
  2659.                     while (count > 0) {
  2660.                         errno = 0;
  2661.                         y = ttol(xbbuf,count);
  2662.                         if (y < 0) {    /* try to send it. */
  2663.                             printf("?TRANSMIT output error: %s\n",
  2664.                                    ck_errstr());
  2665.                             debug(F111,"XMIT binary ttol error",
  2666.                                   ck_errstr(),errno);
  2667.                             rc = 0;
  2668.                             break;
  2669.                         }
  2670.                         if (y < 0) break;
  2671.                         count -= y;
  2672.                     }
  2673.                     count = 0;
  2674.                 }
  2675.                 xbbuf[count++] = c;
  2676. #ifdef TNCODE
  2677.                 if (c == IAC && is_tn)  /* Telnet IAC */
  2678.                   xbbuf[count++] = IAC; /* must be doubled */
  2679. #endif /* TNCODE */
  2680.                 continue;
  2681.             }
  2682.             if (ttoc(dopar((char) c)) < 0) { /* else just send the char */
  2683.                 printf("?Can't transmit character\n");
  2684.                 goto xmitfail;
  2685.             }
  2686. #ifdef TNCODE
  2687.             if (c == IAC && is_tn)      /* Quote Telnet IAC */
  2688.               ttoc((char)IAC);
  2689. #endif /* TNCODE */
  2690.  
  2691.             if (xmitw)                  /* Pause if requested */
  2692.               msleep(xmitw);
  2693.  
  2694.             if (xxecho) {               /* SET TRANSMIT ECHO ON? */
  2695.                 if (duplex) {           /* Yes, for half duplex */
  2696. #ifndef NOLOCAL
  2697. #ifdef OS2
  2698.                     /* Echo to emulator */
  2699.                     scriptwrtbuf((USHORT)(c & cmdmsk));
  2700. #endif /* OS2 */
  2701. #endif /* NOLOCAL */
  2702.                     if (conoc((char)(c & cmdmsk)) < 0) /* echo locally. */
  2703.                       goto xmitfail;
  2704.                 } else {                /* For full duplex, */
  2705.                     int i, n;           /* display whatever is there. */
  2706.                     n = ttchk();        /* See how many chars are waiting */
  2707.                     if (n < 0) {        /* Connection dropped? */
  2708.                         printf("?Connection lost\n");
  2709.                         goto xmitfail;
  2710.                     }
  2711.                     for (i = 0; i < n; i++) { /* Read and echo that many. */
  2712.                         x = ttinc(xmitt); /* Timed read just in case. */
  2713.                         if (x > -1) {   /* If no timeout */
  2714.                             if (parity) x &= 0x7f; /* display the char, */
  2715. #ifndef NOLOCAL
  2716. #ifdef OS2
  2717.                             /* Echo to emulator */
  2718.                             scriptwrtbuf((USHORT)x);
  2719. #endif /* OS2 */
  2720. #endif /* NOLOCAL */
  2721.                             if (conoc((char)(x & cmdmsk)) < 0) {
  2722.                                 printf("?Output error\n");
  2723.                                 goto xmitfail;
  2724.                             }
  2725.                         } else if (x == -2) {
  2726.                             printf("Connection closed.\n");
  2727.                             ttclos(1);
  2728.                             goto xmitfail;
  2729.                         } else if (x == -3) {
  2730.                             printf(
  2731.                             "Session Limit exceeded - closing connection.\n"
  2732.                                    );
  2733.                             ttclos(1);
  2734.                             goto xmitfail;
  2735.                         } else {
  2736.                             printf("?Communications error\n");
  2737.                             goto xmitfail;
  2738.                         }
  2739.                     }
  2740.                 }
  2741.             } else ttflui();            /* Not echoing, just flush input. */
  2742.  
  2743.         } else {                        /* Text mode, line at a time. */
  2744. #ifdef UNICODE
  2745.             if (fcharset == FC_UCS2 && xlate) { /* Special for UCS-2 */
  2746.                 char xbuf[8];
  2747.                 x = 1 - (nbytes & 1);   /* Odd or even byte */
  2748.                 if (x == 0)             /* Note: 1 = the 1st, 0 = 2nd, etc */
  2749.                   uc.x_short = 0;
  2750.                 if (bomorder)           /* Little Endian */
  2751.                   x = 1 - x;            /* Save byte in appropriate half */
  2752.                 debug(F101,"XMIT UCS2 x","",x);
  2753.                 uc.x_char[x] = (CHAR) (c & 0xff);
  2754.                 if (nbytes & 1)         /* First byte, go back for next */
  2755.                   continue;
  2756.                 if (nbytes == 2) {      /* UCS-2 Byte Order Mark */
  2757.                     if (uc.x_short == (USHORT) 0xfeff) {
  2758.                         debug(F100,"XMIT UCS2 BOM FEFF","",bomorder);
  2759.                         continue;
  2760.                     } else if (uc.x_short == (USHORT) 0xfffe) {
  2761.                         bomorder = 1 - bomorder;
  2762.                         debug(F100,"XMIT UCS2 BOM FFFE (swap)","",bomorder);
  2763.                         continue;
  2764.                     }
  2765.                 }
  2766.                 sprintf(xbuf,"%04X",uc.x_short); /* SAFE */
  2767.                 debug(F111,"XMIT UCS2",xbuf,uc.x_short);
  2768.                 if (nbytes & 1)         /* Special eol test for UCS-2 */
  2769.                   if (uc.x_short == '\n')
  2770.                     eol = 1;
  2771. #ifdef COMMENT
  2772.                 if (uc.x_short == 0x2028 || uc.x_short == 0x2029)
  2773.                     eol = 1;
  2774. #endif /* COMMENT */
  2775.             } else
  2776. #endif /* UNICODE */
  2777.               if (c == '\n') {          /* Normal eol test otherwise */
  2778.                   eol = 1;
  2779.             }
  2780.             if (eol) {                  /* End of line? */
  2781.                 int stuff = -1;
  2782.                 debug(F101,"XMIT eol length","",i);
  2783.                 if (i == 0) {           /* Blank line? */
  2784.                     if (xmitf)          /* Yes, insert fill if asked. */
  2785.                       line[i++] = dopar((char) xmitf);
  2786.                 }
  2787.                 if (i == 0 || ((char) line[i-1]) != ((char) dopar(CR)))
  2788.                   line[i++] = dopar(CR); /* Terminate it with CR */
  2789.                 if (xmitl) {
  2790.                     stuff = LF;
  2791. #ifdef TNCODE
  2792.                 } else if (is_tn && (tn_nlm != TNL_CR)) {
  2793.                     /* TELNET NEWLINE ON/OFF/RAW */
  2794.                     stuff = (tn_nlm == TNL_CRLF) ? LF : NUL;
  2795. #endif /* TNCODE */
  2796.                 }
  2797.                 if (stuff > -1)
  2798.                   line[i++] = dopar((char)stuff);
  2799.                 line[i] = NUL;
  2800.                 debug(F111,"XMIT eol line",line,i);
  2801.  
  2802.             } else if (c != -1) {       /* Not a newline, regular character */
  2803.                 int k, x;
  2804.                 outxbuf[0] = c;         /* In case of no translation */
  2805.                 outxcount = 1;          /* Assume result is one byte */
  2806. #ifndef NOCSETS
  2807.                 switch (unicode) {
  2808.                   case 0:               /* No Unicode involved */
  2809.                   case 1:
  2810.                     if (xlate) {        /* If not /TRANSPARENT */
  2811.                         /* Local-to-intermediate */
  2812.                         if (sxo) c = (*sxo)((char)c);
  2813.                         /* Intermediate-to-remote */
  2814.                         if (rxo) c = (*rxo)((char)c);
  2815.                         outxbuf[0] = c;
  2816.                     }
  2817.                     break;
  2818. #ifdef UNICODE
  2819.                   case 2:               /* Local byte to UTF-8 */
  2820.                   case 3:
  2821.                     xfu = xl_fcu[fcharset];
  2822.                     tcssize = fcsinfo[fcharset].size;
  2823.                     outxcount =
  2824.                       b_to_u((CHAR)c,outxbuf,OUTXBUFSIZ,tcssize);
  2825.                     break;
  2826.                   case 4:               /* Local UTF-8 to remote byte */
  2827.                   case 5:
  2828.                     xuf = xl_ufc[tcsr];
  2829.                     x = u_to_b((CHAR)c); /* Convert to byte */
  2830.                     if (x == -1) {      /* If more input bytes needed */
  2831.                         continue;       /* go back and get them */
  2832.                     } else if (x == -2) { /* LS or PS (shouldn't happen) */
  2833.                         outxbuf[0] = CR;
  2834.                     } else if (x == -9) { /* UTF-8 error */
  2835.                         outxbuf[0] = '?'; /* Insert error char */
  2836.                         outxbuf[1] = u_to_b2(); /* Insert next char */
  2837.                         outxcount = 2;
  2838.                     } else {
  2839.                         outxbuf[0] =    /* Otherwise store result */
  2840.                           (unsigned)(x & 0xff);
  2841.                     }
  2842.                     break;
  2843.                   case 6:               /* UTF-8 to UTF-8 */
  2844.                   case 7:
  2845.                     break;
  2846.                   case 8:               /* UCS-2 to byte */
  2847.                   case 9:
  2848.                     xuf = xl_ufc[tcsr];
  2849.                     outxbuf[0] = (*xuf)(uc.x_short);
  2850.                     break;
  2851.                   case 10:
  2852.                   case 11: {            /* UCS-2 to UTF-8 */
  2853.                       int j;
  2854.                       CHAR * buf = NULL;
  2855.                       x = ucs2_to_utf8(uc.x_short,&buf);
  2856.                       if (x < 0) {
  2857.                           outxbuf[0] = 0xff; /* (= U+FFFD) */
  2858.                           outxbuf[1] = 0xbd;
  2859.                           x = 2;
  2860.                       }
  2861.                       for (j = 0; j < x; j++)
  2862.                         outxbuf[j] = buf[j];
  2863.                       outxcount = x;
  2864.                       break;
  2865.                   }
  2866. #endif /* UNICODE */
  2867.                 }
  2868. #endif /* NOCSETS */
  2869.                 outxbuf[outxcount] = NUL;
  2870.                 debug(F111,"XMIT outxbuf",outxbuf,outxcount);
  2871. /*
  2872.   Now the input character (1 or more bytes) is translated into the output
  2873.   expansion buffer (1 or more bytes); outxcount = number of bytes to add to
  2874.   the TRANSMIT line buffer, which we do here, taking care of parity, SI/SO
  2875.   processing, and quoting Telnet IACs.
  2876. */
  2877.                 for (k = 0; k < outxcount; k++) {
  2878.                     c = outxbuf[k];
  2879.                     if (xmits && parity && (c & 0200)) { /* If shifting */
  2880.                         line[i++] = dopar(SO); /* needs to be done, */
  2881.                         line[i++] = dopar((char)c); /* do it here, */
  2882.                         line[i++] = dopar(SI); /* crudely. */
  2883.                     } else {
  2884.                         line[i++] = dopar((char)c);
  2885. #ifdef TNCODE
  2886.                         if (c == IAC && is_tn)
  2887.                           line[i++] = IAC;
  2888. #endif /* TNCODE */
  2889.                     }
  2890.                 }
  2891.             }
  2892. /*
  2893.   Send characters if buffer full, or at end of line, or at end of file.
  2894.   (End of line only if echoing, waiting for a prompt, or pausing.)
  2895. */
  2896.             debug(F000,"XMIT c",ckitoa(i),c);
  2897.             if (i >= xbufsiz || eof || (eol && (xxecho || xmitw || t))) {
  2898.                 p = line;
  2899.                 line[i] = '\0';
  2900.                 debug(F111,"transmit buf",p,i);
  2901.                 if (ttol((CHAR *)p,i) < 0) { /* try to send it. */
  2902.                     printf("?TRANSMIT output error: %s\n",ck_errstr());
  2903.                     rc = 0;
  2904.                     break;
  2905.                 }
  2906.                 i = 0;                  /* Reset buffer pointer. */
  2907. /*
  2908.   Now we handle the echo.  If the user wants to see it, or if we have to
  2909.   wait for the turnaround character, t.  If the echo is being displayed,
  2910.   and terminal character-set translation is required, we do it here.
  2911. */
  2912.                 if (duplex && xxecho) {  /* If local echo, echo it */
  2913.                     if (parity || cmdmsk == 0x7f) { /* Strip hi bits */
  2914.                         char *ss = line;             /* if necessary */
  2915.                         while (*ss) {
  2916.                             *ss &= 0x7f;
  2917.                             ss++;
  2918.                         }
  2919.                     }
  2920. #ifndef NOLOCAL
  2921. #ifdef OS2
  2922.                     {                   /* Echo to emulator */
  2923.                         char *ss = p;
  2924.                         while (*ss) {
  2925.                             scriptwrtbuf((USHORT)*ss);
  2926.                             ss++;
  2927.                         }
  2928.                     }
  2929. #endif /* OS2 */
  2930. #endif /* NOLOCAL */
  2931.                     if (conoll(p) < 0)
  2932.                       goto xmitfail;
  2933.                 }
  2934.                 if (xmitw)              /* Sleep TRANSMIT PAUSE interval */
  2935.                   msleep(xmitw);
  2936.  
  2937.                 control = 0;            /* Readback loop control */
  2938.                 if (t != 0 && eol)      /* TRANSMIT PROMPT given and at EOL */
  2939.                   control |= 1;
  2940.                 if (xxecho && !duplex)   /* Echo desired and is remote */
  2941.                   control |= 2;
  2942.  
  2943.                 if (control) {          /* Do this if reading back the echo */
  2944.                     int n;
  2945.                     x = 0;
  2946.                     while (1) {
  2947.                         if (control & 1) { /* Termination criterion */
  2948.                             if (x == t)    /* for turnaround */
  2949.                               break;
  2950.                         } else if (control & 2) { /* And for echoing */
  2951.                             if ((n = ttchk()) < 1)
  2952.                               break;
  2953.                         }
  2954.                         if ((x = ttinc(xmitt)) < 0) { /* Read with timeout */
  2955.                             switch (x) {
  2956.                               case -2:
  2957.                                 printf("Connection closed.\n");
  2958.                                 ttclos(1);
  2959.                                 goto xmitfail;
  2960.                               case -3:
  2961.                                 printf(
  2962.                               "Session Limit exceeded - closing connection.\n"
  2963.                                        );
  2964.                                 ttclos(1); /* full thru... */
  2965.                                 goto xmitfail;
  2966.                               default:
  2967.                                 printf("?Timeout\n");
  2968.                                 goto xmitfail;
  2969.                             }
  2970.                         }
  2971.                         if (x > -1 && (control & 2)) { /* Echo any echoes */
  2972.                             if (parity)
  2973.                               x &= 0x7f;
  2974.                             c = x;
  2975. #ifndef NOLOCAL
  2976. #ifdef OS2
  2977.                             scriptwrtbuf((USHORT)x);
  2978. #endif /* OS2 */
  2979. #endif /* NOLOCAL */
  2980.                             inxbuf[0] = c;
  2981.                             inxcount = 1;
  2982. #ifndef NOCSETS
  2983.                             switch (unicode & 3) { /* Remote bits */
  2984.                               case 0:
  2985.                                 if (xlate) {
  2986.                                     if (sxi) c = (*sxi)((CHAR)c);
  2987.                                     if (rxi) c = (*rxi)((CHAR)c);
  2988.                                     inxbuf[0] = c;
  2989.                                 }
  2990.                                 break;
  2991. #ifdef UNICODE
  2992.                               case 1:   /* Remote Byte to local UTF-8 */
  2993.                                 xfu = xl_fcu[tcsr];
  2994.                                 tcssize = fcsinfo[tcsr].size;
  2995.                                 inxcount =
  2996.                                   b_to_u((CHAR)c,
  2997.                                          inxbuf,
  2998.                                          OUTXBUFSIZ,
  2999.                                          tcssize
  3000.                                          );
  3001.                                 break;
  3002.                               case 2:   /* Remote UTF-8 to local Byte */
  3003.                                 xuf = xl_ufc[tcsl];
  3004.                                 x = u_to_b((CHAR)c);
  3005.                                 if (x < 0)
  3006.                                   continue;
  3007.                                 inxbuf[0] = (unsigned)(x & 0xff);
  3008.                                 break;
  3009.                               case 3:   /* UTF-8 to UTF-8 */
  3010.                                 break;
  3011. #endif /* UNICODE */
  3012.                             }
  3013. #endif /* NOCSETS */
  3014.                             inxbuf[inxcount] = NUL;
  3015.                             if (conxo(inxcount,(char *)inxbuf) < 0)
  3016.                               goto xmitfail;
  3017.                         }
  3018.                     }
  3019.                 } else                  /* Not echoing */
  3020.                   ttflui();             /* Just flush input buffer */
  3021.             } /* End of buffer-dumping block */
  3022.         } /* End of text mode */
  3023.         if (eof) {
  3024.             rc = 1;
  3025.             goto xmitexit;
  3026.         }
  3027.     } /* End of character-reading loop */
  3028.  
  3029.   xmitfail:                             /* Failure exit point */
  3030.     rc = 0;
  3031.  
  3032.   xmitexit:                             /* General exit point */
  3033.     if (rc > 0) {
  3034.         if (binary && !xmitw && !xxecho) { /* "blasting"? */
  3035.             while (count > 0) {            /* Partial buffer still to go? */
  3036.                 errno = 0;
  3037.                 y = ttol(xbbuf,count);
  3038.                 if (y < 0) {
  3039.                     printf("?TRANSMIT output error: %s\n",
  3040.                            ck_errstr());
  3041.                     debug(F111,"XMIT binary eof ttol error",
  3042.                           ck_errstr(),errno);
  3043.                     rc = 0;
  3044.                     break;
  3045.                 }
  3046.                 count -= y;
  3047.             }
  3048.         } else if (!binary && *xmitbuf) { /* Anything to send at EOF? */
  3049.             p = xmitbuf;                /* Yes, point to string. */
  3050.             while (*p)                  /* Send it. */
  3051.               ttoc(dopar(*p++));        /* Don't worry about echo here. */
  3052.         }
  3053.     }
  3054.  
  3055. #ifndef AMIGA
  3056. #ifndef MAC
  3057.     signal(SIGINT,oldsig);              /* Put old signal action back. */
  3058. #endif /* MAC */
  3059. #endif /* AMIGA */
  3060. #ifdef VMS
  3061.     concb(escape);                      /* Put terminal back, */
  3062. #endif /* VMS */
  3063.     zclose(ZIFILE);                     /* Close file, */
  3064. #ifndef NOCSETS
  3065.     language = langsv;                  /* restore language, */
  3066. #endif /* NOCSETS */
  3067.     ttres();                            /* and terminal modes, */
  3068.     return(rc);                         /* and return successfully. */
  3069. }
  3070. #endif /* NOLOCAL */
  3071. #endif /* NOXMIT */
  3072.  
  3073. #ifndef NOCSETS
  3074.  
  3075. _PROTOTYP( CHAR (*sxx), (CHAR) );       /* Local translation function */
  3076. _PROTOTYP( CHAR (*rxx), (CHAR) );       /* Local translation function */
  3077. _PROTOTYP( CHAR zl1as, (CHAR) );        /* Latin-1 to ascii */
  3078. _PROTOTYP( CHAR xl1as, (CHAR) );        /* ditto */
  3079.  
  3080. /*  X L A T E  --  Translate a local file from one character set to another */
  3081.  
  3082. /*
  3083.   Translates input file (fin) from character set csin to character set csout
  3084.   and puts the result in the output file (fout).  The two character sets are
  3085.   file character sets from fcstab.
  3086. */
  3087.  
  3088. int
  3089. xlate(fin, fout, csin, csout) char *fin, *fout; int csin, csout; {
  3090.  
  3091. #ifndef MAC
  3092. #ifdef OS2
  3093.     extern int k95stdout;
  3094.     extern int wherex[], wherey[];
  3095.     extern unsigned char colorcmd;
  3096. #ifdef NT
  3097.     SIGTYP (* oldsig)(int);             /* For saving old interrupt trap. */
  3098. #else /* NT */
  3099.     SIGTYP (* volatile oldsig)(int);    /* For saving old interrupt trap. */
  3100. #endif /* NT */
  3101. #else /* OS2 */
  3102.     SIGTYP (* oldsig)();
  3103. #endif /* OS2 */
  3104. #endif /* MAC */
  3105. #ifdef CK_ANSIC
  3106.     int (*fn)(char);                    /* Output function pointer */
  3107. #else
  3108.     int (*fn)();
  3109. #endif /* CK_ANSIC */
  3110.     extern int xlatype;
  3111.     int filecode;                       /* Code for output file */
  3112.     int scrnflg = 0;
  3113.  
  3114.     int z = 1;                          /* Return code. */
  3115.     int x, c, c2;                       /* Workers */
  3116. #ifndef UNICODE
  3117.     int tcs;
  3118. #endif /* UNICODE */
  3119.  
  3120.     ffc = 0L;
  3121.  
  3122.     if (zopeni(ZIFILE,fin) == 0) {      /* Open the file to be translated */
  3123. #ifdef COMMENT
  3124.         /* An error message was already printed by zopeni() */
  3125.         printf("?Can't open input file %s\n",fin);
  3126. #endif /* COMMENT */
  3127.         return(0);
  3128.     }
  3129. #ifdef MAC
  3130. /*
  3131.   If user specified no output file, it goes to the screen.  For the Mac,
  3132.   this must be done a special way (result goes to a new window); the Mac
  3133.   doesn't have a "controlling terminal" device name.
  3134. */
  3135.     filecode = !strcmp(fout,CTTNAM) ? ZCTERM : ZOFILE;
  3136. #else
  3137. #ifdef VMS
  3138.     filecode = !strcmp(fout,CTTNAM) ? ZCTERM : ZMFILE;
  3139. #else
  3140. #ifdef OS2
  3141.     filecode = (!stricmp(fout,"con") || !stricmp(fout,"con:")) ?
  3142.         ZCTERM : ZMFILE;
  3143.     if ((filecode == ZCTERM) && !k95stdout && !inserver)
  3144.         csout = FC_UCS2;
  3145. #else /* OS2 */
  3146.     filecode = ZOFILE;
  3147. #endif /* OS2 */
  3148. #endif /* VMS */
  3149. #endif /* MAC */
  3150.     if (zopeno(filecode,fout,NULL,NULL) == 0) { /* And the output file */
  3151.         printf("?Can't open output file %s\n",fout);
  3152.         return(0);
  3153.     }
  3154. #ifndef AMIGA
  3155. #ifndef MAC
  3156.     oldsig = signal(SIGINT, trtrap);    /* Save current interrupt trap. */
  3157. #endif /* MAC */
  3158. #endif /* AMIGA */
  3159.  
  3160.     scrnflg = (filecode == ZCTERM);     /* Set output function */
  3161.     if (scrnflg)
  3162.       fn = NULL;
  3163.     else if (filecode == ZMFILE)
  3164.       fn = putmfil;
  3165.     else
  3166.       fn = putfil;
  3167.  
  3168.     tr_int = 0;                         /* Have not been interrupted (yet). */
  3169.     z = 1;                              /* Return code presumed good. */
  3170.  
  3171.     if (!scrnflg && !quiet)
  3172.       printf(" %s (%s) => %s (%s)\n",   /* Say what we're doing. */
  3173.              fin, fcsinfo[csin].keyword,
  3174.              fout,fcsinfo[csout].keyword
  3175.              );
  3176.  
  3177. #ifndef UNICODE
  3178. /*
  3179.   Non-Unicode picks the "most appropriate" transfer character set as the
  3180.   intermediate set, which results in loss of any characters that the source
  3181.   and target sets have in common, but are lacking from the intermediate set.
  3182. */
  3183. #ifdef KANJI
  3184.     /* Special handling for Japanese... */
  3185.  
  3186.     if (fcsinfo[csin].alphabet == AL_JAPAN ||
  3187.          fcsinfo[csout].alphabet == AL_JAPAN) {
  3188.         USHORT eu;
  3189.         int c, x, y;
  3190.  
  3191.         xpnbyte(-1,0,0,NULL);           /* Reset output machine */
  3192.         xlatype = XLA_JAPAN;
  3193.  
  3194.         while ((c = xgnbyte(FC_JEUC,csin,NULL)) > -1) { /* Get an EUC byte */
  3195.             if (tr_int) {               /* Interrupted? */
  3196.                 printf("^C...\n");      /* Print message */
  3197.                 z = 0;
  3198.                 break;
  3199.             }
  3200.             /* Send EUC byte to output machine */
  3201.             if ((x = xpnbyte(c,TC_JEUC,csout,fn)) < 0) {
  3202.                 z = -1;
  3203.                 break;
  3204.             }
  3205.         }
  3206.         goto xxlate;
  3207.     }
  3208. #endif /* KANJI */
  3209.  
  3210.     /* Regular bytewise conversion... */
  3211.  
  3212.     tcs = gettcs(csin,csout);           /* Get intermediate set. */
  3213.     if (csin == csout) {                /* Input and output sets the same? */
  3214.         sxx = rxx = NULL;               /* If so, no translation. */
  3215.     } else {                            /* Otherwise, set up */
  3216.         if (tcs < 0 || tcs > MAXTCSETS ||
  3217.             csin < 0 || csin > MAXFCSETS ||
  3218.             csout < 0 || csout > MAXFCSETS) {
  3219.             debug(F100,"XLATE csets out of range","",0);
  3220.             sxx = rxx = NULL;
  3221.         } else {
  3222.             sxx = xls[tcs][csin];       /* translation function */
  3223.             rxx = xlr[tcs][csout];      /* pointers. */
  3224.             if (rxx == zl1as) rxx = xl1as;
  3225.         }
  3226.     }
  3227.     while ((c = zminchar()) != -1) { /* Loop for all characters in file */
  3228.         if (tr_int) {                   /* Interrupted? */
  3229.             printf("^C...\n");          /* Print message */
  3230.             z = 0;
  3231.             break;
  3232.         }
  3233.         if (sxx) c = (*sxx)((CHAR)c);   /* From fcs1 to tcs */
  3234.         if (rxx) c = (*rxx)((CHAR)c);   /* from tcs to fcs2 */
  3235.         if (zchout(filecode,(char)c) < 0) { /* Output xlated character */
  3236.             z = -1;
  3237.             break;
  3238.         }
  3239.     }
  3240.     goto xxlate;                        /* Done. */
  3241.  
  3242. #else  /* UNICODE */
  3243. /*
  3244.    Use Unicode as the intermediate character set.  It's simple and gives
  3245.    little or no loss, but the overhead is a bit higher.
  3246. */
  3247.     initxlate(csin,csout);              /* Set up translation functions */
  3248.  
  3249.     if (xlatype == XLA_NONE) {
  3250.         while ((c = zminchar()) != -1) { /* Loop for all characters in file */
  3251.             if (tr_int) {               /* Interrupted? */
  3252.                 printf("^C...\n");      /* Print message */
  3253.                 z = 0;
  3254.                 break;
  3255.             }
  3256.             if (zchout(filecode,(char)c) < 0) { /* Output xlated character */
  3257.                 z = -1;
  3258.                 break;
  3259.             }
  3260.         }
  3261.         goto xxlate;                    /* Done. */
  3262.     }
  3263.  
  3264.  
  3265. #ifndef NOLOCAL
  3266. #ifdef OS2
  3267.     if (csout == FC_UCS2 &&             /* we're translating to UCS-2 */
  3268.         filecode == ZCTERM &&           /* for the real screen... */
  3269.         !k95stdout && !inserver
  3270.         ) {
  3271.         union {
  3272.             USHORT ucs2;
  3273.             UCHAR  bytes[2];
  3274.         } output;
  3275.  
  3276.         while (1) {                     /* In this case we go two-by-two. */
  3277.             if ((c = xgnbyte(FC_UCS2,csin,NULL)) < 0)
  3278.               break;
  3279.             output.bytes[0] = c;
  3280.             if ((c = xgnbyte(FC_UCS2,csin,NULL)) < 0)
  3281.               break;
  3282.             output.bytes[1] = c;
  3283.  
  3284.             if (tr_int) {               /* Interrupted? */
  3285.                 printf("^C...\n");      /* Print message */
  3286.                 z = 0;
  3287.                 break;
  3288.             }
  3289.  
  3290.             VscrnWrtUCS2StrAtt(VCMD,
  3291.                                &output.ucs2,
  3292.                                1,
  3293.                                wherey[VCMD],
  3294.                                wherex[VCMD],
  3295.                                &colorcmd
  3296.                                );
  3297.         }
  3298.     } else
  3299. #endif /* OS2 */
  3300. #endif /* NOLOCAL */
  3301.  
  3302.       /* General case: Get next byte translated from fcs to UCS-2 */
  3303.  
  3304. #ifdef COMMENT
  3305.       while ((c = xgnbyte(FC_UCS2,csin,NULL)) > -1 &&
  3306.               (c2 = xgnbyte(FC_UCS2,csin,NULL)) > -1) {
  3307.           extern int fileorder;
  3308.  
  3309.           if (tr_int) {                 /* Interrupted? */
  3310.               printf("^C...\n");        /* Print message */
  3311.               z = 0;
  3312.               break;
  3313.           }
  3314.           debug(F001,"XLATE c","",c);
  3315.           debug(F001,"XLATE c2","",c2);
  3316.  
  3317.           /* And then send UCS-2 byte to translate-and-output machine */
  3318.  
  3319.           if ((x = xpnbyte(fileorder?c2:c,TC_UCS2,csout,fn)) < 0) {
  3320.               z = -1;
  3321.               break;
  3322.           }
  3323.           if ((x = xpnbyte(fileorder?c:c2,TC_UCS2,csout,fn)) < 0) {
  3324.               z = -1;
  3325.               break;
  3326.           }
  3327.       }
  3328. #else
  3329.     while ((c = xgnbyte(FC_UCS2,csin,NULL)) > -1) {
  3330.           if (tr_int) {                 /* Interrupted? */
  3331.               printf("^C...\n");        /* Print message */
  3332.               z = 0;
  3333.               break;
  3334.           }
  3335.           if ((x = xpnbyte(c,TC_UCS2,csout,fn)) < 0) {
  3336.               z = -1;
  3337.               break;
  3338.           }
  3339.       }
  3340. #endif /* COMMENT */
  3341.  
  3342. #endif /* UNICODE */
  3343.  
  3344.   xxlate:                               /* Common exit point */
  3345.  
  3346. #ifndef AMIGA
  3347. #ifndef MAC
  3348.     signal(SIGINT,oldsig);              /* Put old signal action back. */
  3349. #endif /* MAC */
  3350. #endif /* AMIGA */
  3351.     tr_int = 0;
  3352.     if (z < 0) {
  3353.         if (z == -1)
  3354.           printf("?File output error: %s\n",ck_errstr());
  3355.         z = 0;
  3356.     }
  3357.     zclose(ZIFILE);                     /* Close files */
  3358.     zclose(filecode);                   /* ... */
  3359.     return(success = z);                /* and return status. */
  3360. }
  3361.  
  3362. int
  3363. doxlate() {
  3364. #ifdef OS2ONLY
  3365.     extern int tt_font;
  3366. #endif /* OS2ONLY */
  3367. #ifdef UNIX
  3368.     extern char ** mtchs;               /* zxpand() file list */
  3369. #endif /* UNIX */
  3370.     extern int nfilc;
  3371.     extern struct keytab fcstab[];
  3372.     int x, y, incs, outcs, multiple = 0, wild = 0, fc = 0, len = 0;
  3373.     int ofisdir = 0;
  3374.     char * s, * tocs = "";
  3375.  
  3376.     if ((x = cmifi("File(s) to translate","",&s,&wild,xxstring)) < 0) {
  3377.         if (x == -3) {
  3378.             printf("?Name of an existing file\n");
  3379.             return(-9);
  3380.         } else
  3381.           return(x);
  3382.     }
  3383.     ckstrncpy(line,s,LINBUFSIZ);        /* Save copy of string just parsed. */
  3384.  
  3385.     if ((incs = cmkey(fcstab,nfilc,"from character-set","",xxstring)) < 0)
  3386.       return(incs);
  3387.  
  3388. #ifdef OS2
  3389.     if (isunicode())
  3390.       tocs = "ucs2";
  3391.     else
  3392. #endif /* OS2 */
  3393.       tocs = getdcset();
  3394.  
  3395.     if ((outcs = cmkey(fcstab,nfilc,"to character-set",tocs,xxstring)) < 0)
  3396.       return(outcs);
  3397.     if ((x = cmofi("output file",CTTNAM,&s,xxstring)) < 0) return(x);
  3398.     if (x > 1)
  3399.       ofisdir = 1;
  3400.  
  3401.     len = ckstrncpy(tmpbuf,s,TMPBUFSIZ);
  3402.     if ((y = cmcfm()) < 0) return(y);   /* Confirm the command */
  3403.  
  3404.     if (len < 1)
  3405.       return(-2);
  3406.  
  3407.     if (ofisdir)
  3408.       multiple = 2;
  3409.     else if (wild) {
  3410.         if (isdir(tmpbuf))
  3411.           multiple = 2;
  3412.         else if (!strcmp(tmpbuf,CTTNAM))
  3413.           multiple = 1;
  3414. #ifdef OS2
  3415.         else if (!stricmp(tmpbuf,"con") || !stricmp(tmpbuf,"con:"))
  3416.           multiple = 1;
  3417. #else
  3418. #ifdef UNIXOROSK
  3419.         else if (!strncmp(tmpbuf,"/dev/",4))
  3420.           multiple = 1;
  3421. #endif /* UNIXOROSK */
  3422. #endif /* OS2 */
  3423.         if (!multiple) {
  3424.             printf("?A single file please\n");
  3425.             return(-9);
  3426.         }
  3427.     }
  3428.     if (!multiple) {                    /* Just one file */
  3429.         return(success = xlate(line,tmpbuf,incs,outcs));
  3430.     } else {                            /* Translate multiple files */
  3431.         char dirbuf[CKMAXPATH+4];
  3432.         int k;
  3433. #ifndef ZXREWIND
  3434.         int flags = ZX_FILONLY;
  3435. #endif /* ZXREWIND */
  3436.  
  3437.         if (multiple == 2) {            /* Target is a directory */
  3438.             k = ckstrncpy(dirbuf,tmpbuf,CKMAXPATH+1) - 1;
  3439.             if (k < 0)
  3440.               return(-2);
  3441. #ifdef OS2ORUNIX
  3442.             if (dirbuf[k] != '/') {
  3443.                 dirbuf[k+1] = '/';
  3444.                 dirbuf[k+2] = NUL;
  3445.             }
  3446. #else
  3447. #ifdef OSK
  3448.             if (dirbuf[k] != '/') {
  3449.                 dirbuf[k+1] = '/';
  3450.                 dirbuf[k+2] = NUL;
  3451.             }
  3452. #else
  3453. #ifdef VMS
  3454.             if (ckmatch("*.DIR;1",s,0,0))
  3455.               k = cvtdir(tmpbuf,dirbuf,TMPBUFSIZ);
  3456.             if (dirbuf[k] != ']' &&
  3457.                 dirbuf[k] != '>' &&
  3458.                 dirbuf[k] != ':')
  3459.               return(-2);
  3460. #else
  3461. #ifdef datageneral
  3462.             if (dirbuf[k] != ':') {
  3463.                 dirbuf[k+1] = ':';
  3464.                 dirbuf[k+2] = NUL;
  3465.             }
  3466. #else
  3467. #ifdef STRATUS
  3468.             if (dirbuf[k] != '>') {
  3469.                 dirbuf[k+1] = '>';
  3470.                 dirbuf[k+2] = NUL;
  3471.             }
  3472. #endif /* STRATUS */
  3473. #endif /* datageneral */
  3474. #endif /* VMS */
  3475. #endif /* OSK */
  3476. #endif /* OS2ORUNIX */
  3477.         }
  3478.  
  3479. #ifdef ZXREWIND
  3480.         fc = zxrewind();                /* Rewind the file list */
  3481. #else
  3482.         if (matchdot)  flags |= ZX_MATCHDOT;
  3483.         fc = nzxpand(line,flags);
  3484. #endif /* ZXREWIND */
  3485.  
  3486.         if (fc < 1) {
  3487.             printf("?Wildcard expansion error\n");
  3488.             return(-9);
  3489.         }
  3490. #ifdef UNIX
  3491.         sh_sort(mtchs,NULL,fc,0,0,filecase); /* Sort the file list */
  3492. #endif /* UNIX */
  3493.  
  3494.         while (1) {                     /* Loop through the files */
  3495.             znext(line);
  3496.             if (!line[0])
  3497.               break;
  3498.             if (multiple == 2)
  3499.               ckmakmsg(tmpbuf,TMPBUFSIZ,dirbuf,line,NULL,NULL);
  3500.             if (xlate(line,tmpbuf,incs,outcs) < 1)
  3501.               return(success = 0);
  3502.         }
  3503.     }
  3504.     return(success = 1);
  3505. }
  3506. #endif /* NOCSETS */
  3507.  
  3508. static char hompthbuf[CKMAXPATH+1];
  3509.  
  3510. char *
  3511. homepath() {
  3512.     int x;
  3513.     extern char * myhome;
  3514.     char * h;
  3515.  
  3516.     h = myhome ? myhome : zhome();
  3517.     hompthbuf[0] = NUL;
  3518. #ifdef UNIXOROSK
  3519.     x = ckstrncpy(hompthbuf,h,CKMAXPATH+1);
  3520.     if (x <= 0) {
  3521.         hompthbuf[0] = '/';
  3522.         hompthbuf[1] = NUL;
  3523.     } else if (x < CKMAXPATH - 2 && hompthbuf[x-1] != '/') {
  3524.         hompthbuf[x] = '/';
  3525.         hompthbuf[x+1] = NUL;
  3526.     }
  3527.     return(hompthbuf);
  3528. #else
  3529. #ifdef STRATUS
  3530.     if (strlen(h) < CKMAXPATH)
  3531.       sprintf(hompthbuf,"%s>",h);    /* SAFE */
  3532.     return(hompthbuf);
  3533. #else
  3534.     return(h);
  3535. #endif /* STRATUS */
  3536. #endif /* UNIXOROSK */
  3537. }
  3538.  
  3539. /*  D O L O G  --  Do the log command  */
  3540.  
  3541. int
  3542. dolog(x) int x; {
  3543.     int y, disp; char *s = NULL, * p = NULL, * q = NULL;
  3544.     extern int isguest;
  3545. #ifdef ZFNQFP
  3546.     struct zfnfp * fnp;
  3547. #endif /* ZFNQFP */
  3548.  
  3549.     if (isguest) {
  3550.         printf("?Anonymous log creation not allowed\n");
  3551.         return(-9);
  3552.     }
  3553.     switch (x) {                        /* Which log... */
  3554.  
  3555. #ifdef DEBUG
  3556.       case LOGD:
  3557.         q = "debug.log";
  3558.         y = cmofi("Name of debugging log file",q,&s,xxstring);
  3559.         break;
  3560. #endif /* DEBUG */
  3561.  
  3562.       case LOGP:
  3563.         q = "packet.log";
  3564.         y = cmofi("Name of packet log file",q,&s,xxstring);
  3565.         break;
  3566.  
  3567. #ifndef NOLOCAL
  3568.       case LOGS:
  3569.         q = "session.log";
  3570.         y = cmofi("Name of session log file",q,&s,xxstring);
  3571.         break;
  3572. #endif /* NOLOCAL */
  3573.  
  3574. #ifdef TLOG
  3575.       case LOGT:
  3576.         q = "transact.log";
  3577.         y = cmofi("Name of transaction log file",q,&s,xxstring);
  3578.         break;
  3579. #endif /* TLOG */
  3580.  
  3581. #ifdef CKLOGDIAL
  3582.       case LOGM: {
  3583.           int m, n;
  3584.           char mypath[CKMAXPATH+1];
  3585.           q = CXLOGFILE;
  3586.           m = ckstrncpy(mypath,homepath(),CKMAXPATH);
  3587.           n = strlen(CXLOGFILE);
  3588.           if (m + n < CKMAXPATH)
  3589.             ckstrncat(mypath,CXLOGFILE,CKMAXPATH);
  3590.           else
  3591.             ckstrncpy(mypath,CXLOGFILE,CKMAXPATH);
  3592.           y = cmofi("Name of connection log file",mypath,&s,xxstring);
  3593.           break;
  3594.       }
  3595. #endif /* CKLOGDIAL */
  3596.  
  3597.       default:
  3598.         printf("\n?Unknown log designator - %d\n",x);
  3599.         return(-2);
  3600.     }
  3601.     if (y < 0) return(y);
  3602.     if (y == 2) {                       /* If they gave a directory name */
  3603.         int k;
  3604.         char * ds = "/";
  3605.         k = strlen(s);
  3606.         if (k > 0 && s[k-1] == '/') ds = "";
  3607.         ckmakmsg(tmpbuf,TMPBUFSIZ,s,ds,q,NULL);
  3608.         s = tmpbuf;
  3609.     }
  3610. #ifdef ZFNQFP
  3611. #ifdef OS2ORUNIX
  3612.     if (*s != '|')                      /* Allow for pipes */
  3613. #else
  3614. #ifdef OSK
  3615.     if (*s != '|')
  3616. #endif /* OSK */
  3617. #endif /* OS2ORUNIX */
  3618.       if ((fnp = zfnqfp(s,TMPBUFSIZ - 1,tmpbuf))) {
  3619.           if (fnp->fpath)
  3620.             if ((int) strlen(fnp->fpath) > 0)
  3621.               s = fnp->fpath;
  3622.       } /* else if error keep original string */
  3623. #endif /* ZFNQFP */
  3624.  
  3625.     ckstrncpy(line,s,LINBUFSIZ);
  3626.     s = line;
  3627. #ifdef MAC
  3628.     y = 0;
  3629. #else
  3630.  
  3631.     p = "new";
  3632. #ifdef TLOG
  3633.     if ((x == LOGT && tlogfmt == 2) || x == LOGM)
  3634.       p = "append";
  3635. #endif /* TLOG */
  3636.  
  3637.     if ((y = cmkey(disptb,2,"Disposition",p,xxstring)) < 0)
  3638.       return(y);
  3639. #endif /* MAC */
  3640.     disp = y;
  3641.     if ((y = cmcfm()) < 0) return(y);
  3642.  
  3643.     switch (x) {
  3644.  
  3645. #ifdef DEBUG
  3646.       case LOGD:
  3647.         return(deblog = debopn(s,disp));
  3648. #endif /* DEBUG */
  3649.  
  3650. #ifndef NOXFER
  3651.       case LOGP:
  3652.         return(pktlog = pktopn(s,disp));
  3653. #endif /* NOXFER */
  3654.  
  3655. #ifndef NOLOCAL
  3656.       case LOGS:
  3657.         setseslog(sesopn(s,disp));
  3658.         return(seslog);
  3659. #endif /* NOLOCAL */
  3660.  
  3661. #ifdef TLOG
  3662.       case LOGT:
  3663.         return(tralog = traopn(s,disp));
  3664. #endif /* TLOG */
  3665.  
  3666. #ifdef CKLOGDIAL
  3667.       case LOGM:
  3668.         return(dialog = diaopn(s,disp,0));
  3669. #endif /* CKLOGDIAL */
  3670.  
  3671.       default:
  3672.         return(-2);
  3673.     }
  3674. }
  3675.  
  3676. #ifndef NOXFER
  3677. int
  3678. pktopn(s,disp) char *s; int disp; {
  3679.     static struct filinfo xx;
  3680.  
  3681.     if (!s)
  3682.       s = "";
  3683.     if (!*s)
  3684.       return(0);
  3685.  
  3686.     debug(F111,"pktopn",s,disp);
  3687.  
  3688.     zclose(ZPFILE);
  3689.  
  3690. #ifdef OS2ORUNIX
  3691.     if (s[0] == '|') {                  /* Pipe */
  3692.         char * p = s + 1;
  3693.         debug(F110,"pktopn p",p,0);
  3694.         while (*p) {
  3695.             if (*p != ' ')
  3696.               break;
  3697.             else
  3698.               p++;
  3699.         }
  3700.         debug(F110,"pktopn pipe",p,0);
  3701.         pktlog = zxcmd(ZPFILE,p);
  3702.         debug(F101,"pktopn seslog","",seslog);
  3703.     } else {                            /* File */
  3704. #endif /* OS2ORUNIX */
  3705.         if (disp) {
  3706.             xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  3707.             xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = "";
  3708.             xx.lblopts = 0;
  3709.             pktlog = zopeno(ZPFILE,s,NULL,&xx);
  3710.         } else pktlog = zopeno(ZPFILE,s,NULL,NULL);
  3711.         if (!pktlog)
  3712.           printf("?%s - %s\n",s,ck_errstr());
  3713. #ifdef OS2ORUNIX
  3714.     }
  3715. #endif /* OS2ORUNIX */
  3716.     if (pktlog > 0)
  3717.       ckstrncpy(pktfil,s,CKMAXPATH+1);
  3718.     else
  3719.       *pktfil = '\0';
  3720.     return(pktlog);
  3721. }
  3722. #endif /* NOXFER */
  3723.  
  3724. int
  3725. traopn(s,disp) char *s; int disp; {
  3726. #ifdef TLOG
  3727.     static struct filinfo xx;
  3728.  
  3729.     if (!s)
  3730.       s = "";
  3731.     if (!*s)
  3732.       return(0);
  3733.  
  3734.     debug(F111,"traopn",s,disp);
  3735.     debug(F101,"traopn tlogfmt","",tlogfmt);
  3736.  
  3737.     zclose(ZTFILE);
  3738.  
  3739. #ifdef OS2ORUNIX
  3740.     if (tlogfmt == 2) {                 /* FTP format is special... */
  3741.         VOID doiklog();
  3742.         if (!disp)                      /* Append? */
  3743.           if (zchki(s) > -1)            /* No - does file exist? */
  3744.             (VOID) zdelet(s);           /* Yes - delete it. */
  3745.         xferlog = 1;
  3746.         ckstrncpy(trafil,s,CKMAXPATH);
  3747.         makestr(&xferfile,s);
  3748.         doiklog();
  3749.         return(1);
  3750.     }
  3751.     if (s[0] == '|') {                  /* Pipe */
  3752.         char * p = s + 1;
  3753.         debug(F110,"traopn p",p,0);
  3754.         while (*p) {
  3755.             if (*p != ' ')
  3756.               break;
  3757.             else
  3758.               p++;
  3759.         }
  3760.         debug(F110,"traopn pipe",p,0);
  3761.         tralog = zxcmd(ZTFILE,p);
  3762.         debug(F101,"traopn tralog","",tralog);
  3763.     }
  3764. #endif /* OS2ORUNIX */
  3765.  
  3766.     if (s[0] != '|') {                  /* File */
  3767.         if (disp) {
  3768.             xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  3769.             xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = "";
  3770.             xx.lblopts = 0;
  3771.             tralog = zopeno(ZTFILE,s,NULL,&xx);
  3772.         } else tralog = zopeno(ZTFILE,s,NULL,NULL);
  3773.     }
  3774.     if (!tralog)
  3775.       printf("?%s - %s\n",s,ck_errstr());
  3776.     if (tralog > 0 && tlogfmt > 0) {
  3777.         ckstrncpy(trafil,s,CKMAXPATH);
  3778.         tlog(F110,"Transaction Log:",versio,0L);
  3779. #ifndef MAC
  3780.         tlog(F100,ckxsys,"",0L);
  3781. #endif /* MAC */
  3782.         ztime(&s);
  3783.         tlog(F100,s,"",0L);
  3784.     } else
  3785.       *trafil = '\0';
  3786.     return(tralog);
  3787. #else
  3788.     return(0);
  3789. #endif /* TLOG */
  3790. }
  3791.  
  3792. #ifndef NOLOCAL
  3793. int
  3794. sesopn(s,disp) char * s; int disp; {
  3795.     static struct filinfo xx;
  3796.     extern int tsstate;
  3797.  
  3798.     tsstate = 0;                        /* Session log timestamp state */
  3799.  
  3800.     if (!s)
  3801.       s = "";
  3802.     if (!*s)
  3803.       return(0);
  3804.  
  3805.     debug(F111,"sesopn",s,disp);
  3806.  
  3807.     zclose(ZSFILE);
  3808.  
  3809. #ifdef OS2ORUNIX
  3810.     if (s[0] == '|') {                  /* Pipe */
  3811.         char * p = s + 1;
  3812.         debug(F110,"sesopn p",p,0);
  3813.         while (*p) {
  3814.             if (*p != ' ')
  3815.               break;
  3816.             else
  3817.               p++;
  3818.         }
  3819.         debug(F110,"sesopn pipe",p,0);
  3820.         setseslog(zxcmd(ZSFILE,p));
  3821.         debug(F101,"sesopn seslog","",seslog);
  3822.     } else {                            /* File */
  3823. #endif /* OS2ORUNIX */
  3824.         if (disp) {
  3825.             xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  3826.             xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = "";
  3827.             xx.lblopts = 0;
  3828.             setseslog(zopeno(ZSFILE,s,NULL,&xx));
  3829.         } else
  3830.           setseslog(zopeno(ZSFILE,s,NULL,NULL));
  3831.         if (!seslog)
  3832.           printf("?%s - %s\n",s,ck_errstr());
  3833. #ifdef OS2ORUNIX
  3834.     }
  3835. #endif /* OS2ORUNIX */
  3836.     if (seslog > 0)
  3837.       ckstrncpy(sesfil,s,CKMAXPATH+1);
  3838.     else
  3839.       *sesfil = '\0';
  3840.     return(seslog);
  3841. }
  3842. #endif /* NOLOCAL */
  3843. #endif /* NOICP */
  3844.  
  3845. int
  3846. debopn(s,disp) char *s; int disp; {
  3847. #ifdef DEBUG
  3848. #ifdef CK_UTSNAME
  3849.     extern char unm_mch[], unm_nam[], unm_rel[], unm_ver[], unm_mod[];
  3850. #endif /* CK_UTSNAME */
  3851. #ifdef OS2
  3852.     extern char ckxsystem[];
  3853. #endif /* OS2 */
  3854.     char *tp;
  3855.     static struct filinfo xx;
  3856.  
  3857.     if (!s)
  3858.       s = "";
  3859.     if (!*s)
  3860.       return(0);
  3861.  
  3862.     zclose(ZDFILE);
  3863.  
  3864. #ifdef OS2ORUNIX
  3865.     if (s[0] == '|') {                  /* Pipe */
  3866.         char * p = s + 1;
  3867.         debug(F110,"debopn p",p,0);
  3868.         while (*p) {
  3869.             if (*p != ' ')
  3870.               break;
  3871.             else
  3872.               p++;
  3873.         }
  3874.         debug(F110,"debopn pipe",p,0);
  3875.         deblog = zxcmd(ZDFILE,p);
  3876.         debug(F101,"debopn deblog","",deblog);
  3877.     } else {                            /* File */
  3878. #endif /* OS2ORUNIX */
  3879.         if (disp) {
  3880.             xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  3881.             xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = "";
  3882.             xx.lblopts = 0;
  3883.             deblog = zopeno(ZDFILE,s,NULL,&xx);
  3884.         } else
  3885.           deblog = zopeno(ZDFILE,s,NULL,NULL);
  3886.         if (!deblog)
  3887.           printf("?%s - %s\n",s,ck_errstr());
  3888. #ifdef OS2ORUNIX
  3889.     }
  3890. #endif /* OS2ORUNIX */
  3891.     if (deblog > 0) {
  3892.         ckstrncpy(debfil,s,CKMAXPATH+1);
  3893.         debug(F110,"Debug Log ",versio,0);
  3894. #ifndef MAC
  3895. #ifdef OS2
  3896.         debug(F110,ckxsys,ckxsystem,0);
  3897. #else /* OS2 */
  3898.         debug(F100,ckxsys,"",0);
  3899. #endif /* OS2 */
  3900. #endif /* MAC */
  3901. #ifdef CK_UTSNAME
  3902.         if (unm_mch[0]) {
  3903.             debug(F110,"uname machine",unm_mch,0);
  3904.             if (unm_mod[0])
  3905.               debug(F110,"uname model  ",unm_mod,0);
  3906.             debug(F110,"uname sysname",unm_nam,0);
  3907.             debug(F110,"uname release",unm_rel,0);
  3908.             debug(F110,"uname version",unm_ver,0);
  3909.         }
  3910. #ifdef KTARGET
  3911.         {
  3912.             char * s;                   /* Makefile target */
  3913.             s = KTARGET;
  3914.             if (!s) s = "";
  3915.             if (!*s) s = "(unknown)";
  3916.             debug(F110,"build target",s,0);
  3917.         }
  3918. #endif /* KTARGET */
  3919.         deblog = 0;
  3920.         ztime(&tp);
  3921.         deblog = 1;
  3922.         debug(F100,tp,"",0);
  3923. #endif /* UTSNAME */
  3924.         debug(F101,"byteorder","",byteorder);
  3925. #ifndef NOICP
  3926. #ifndef NOLOCAL
  3927.         if (local) {
  3928.             debug(F110,"Active connection: ",ttname,0);
  3929.             if (!network) {
  3930.                 debug(F101,"Speed","",speed);
  3931.                 if (hwparity)
  3932.                   debug(F110,"Parity[hardware]",parnam((char)hwparity),0);
  3933.                 else
  3934.                   debug(F110,"Parity",parnam((char)parity),0);
  3935.                 deblog = 0;
  3936.                 debug(F110,"Modem",gmdmtyp(),0);
  3937.                 deblog = 1;
  3938.             }
  3939.         } else {
  3940.             debug(F110,"Active connection: ","none",0);
  3941.         }
  3942. #endif /* NOLOCAL */
  3943. #endif /* NOICP */
  3944.     } else *debfil = '\0';
  3945.     return(deblog);
  3946. #else
  3947.     return(0);
  3948. #endif /* MAC */
  3949. }
  3950.  
  3951.  
  3952. /*  C K D A T E  --  Returns current date/time in standard format  */
  3953.  
  3954. static char nowbuf[18];
  3955.  
  3956. char *
  3957. ckdate() {
  3958.     extern struct keytab cmonths[];
  3959.     int x;
  3960.     char * t;                   /* Substitute today's date */
  3961.     char dbuf[32];
  3962.     ztime(&t);
  3963.  
  3964. /*  012345678901234567890123 */
  3965. /*  Sat Jul  4 12:16:43 1998 */
  3966.  
  3967.     ckstrncpy(dbuf,t,32);
  3968.     t = dbuf;
  3969.     debug(F110,"ckdate dbuf",dbuf,0);
  3970.     nowbuf[0] = t[20];
  3971.     nowbuf[1] = t[21];
  3972.     nowbuf[2] = t[22];
  3973.     nowbuf[3] = t[23];
  3974.  
  3975.     nowbuf[4] = NUL;
  3976.     debug(F110,"ckdate nowbuf",nowbuf,0);
  3977.  
  3978.     t[7] = NUL;
  3979.     if ((x = lookup(cmonths,t+4,12,NULL)) < 0) {
  3980.         debug(F110,"ckdate bad month",t,0);
  3981.         return("<BAD_MONTH>");
  3982.     }
  3983.     sprintf(nowbuf+4,"%02d",x);         /* SAFE */
  3984.     nowbuf[6] = (t[8] == SP) ? '0' : t[8];
  3985.     nowbuf[7] = t[9];
  3986.     nowbuf[8] = ' ';
  3987.  
  3988.     nowbuf[9] = NUL;
  3989.     debug(F110,"ckdate nowbuf",nowbuf,0);
  3990.  
  3991.     for (x = 11; x < 19; x++) nowbuf[x-2] = t[x];
  3992.     nowbuf[17] = NUL;
  3993.     debug(F110,"ckdate nowbuf",nowbuf,0);
  3994.  
  3995.     return((char *)nowbuf);
  3996. }
  3997.  
  3998. #ifndef NOICP
  3999. #ifdef CKLOGDIAL
  4000.  
  4001. /*
  4002.   fc = 0 for initial open, meaning open, then close immediately.
  4003.   fc > 0 for subsequent opens, meaning open for use, leave open.
  4004. */
  4005. int
  4006. diaopn(s,disp,fc) char *s; int disp, fc; {
  4007.     static struct filinfo xx;
  4008.  
  4009.     if (!s)
  4010.       s = "";
  4011.     if (!*s)
  4012.       return(0);
  4013.  
  4014.     debug(F110,"diaopn log",s,0);
  4015.     debug(F101,"diaopn fc",s,fc);
  4016.     debug(F101,"diaopn disp 1",s,disp);
  4017.     if (fc) disp = 1;                   /* Force append if open for use */
  4018.     debug(F101,"diaopn disp 2",s,disp);
  4019.  
  4020.     zclose(ZDIFIL);                     /* In case a log was already open */
  4021.  
  4022. #ifdef OS2ORUNIX
  4023.     if (s[0] == '|') {                  /* Pipe */
  4024.         char * p = s + 1;
  4025.         debug(F110,"diaopn p",p,0);
  4026.         while (*p) {
  4027.             if (*p != ' ')
  4028.               break;
  4029.             else
  4030.               p++;
  4031.         }
  4032.         debug(F110,"diaopn pipe",p,0);
  4033.         dialog = zxcmd(ZDIFIL,p);
  4034.         debug(F101,"diaopn dialog","",dialog);
  4035.     } else {                            /* File */
  4036. #endif /* OS2ORUNIX */
  4037.         if (disp) {
  4038.             xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  4039.             xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = "";
  4040.             xx.lblopts = 0;
  4041.             dialog = zopeno(ZDIFIL,s,NULL,&xx);
  4042.         } else dialog = zopeno(ZDIFIL,s,NULL,NULL);
  4043.         if (!dialog)
  4044.           printf("?%s - %s\n",s,ck_errstr());
  4045. #ifdef OS2ORUNIX
  4046.     }
  4047. #endif /* OS2ORUNIX */
  4048.     if (dialog > 0)
  4049.       ckstrncpy(diafil,s,CKMAXPATH+1);
  4050.     else
  4051.       *diafil = '\0';
  4052.     if (fc == 0)                        /* Initial open */
  4053.       zclose(ZDIFIL);                   /* close it */
  4054.     return(dialog);
  4055. }
  4056. #endif /* CKLOGDIAL */
  4057.  
  4058. #ifndef NOSHOW
  4059.  
  4060. /*  SHOW command routines */
  4061.  
  4062. char *
  4063. shoxm() {
  4064.     char * s;
  4065.     switch (binary) {
  4066.       case XYFT_T: s = "text";         break;
  4067. #ifdef VMS
  4068.       case XYFT_B: s = "binary fixed"; break;
  4069.       case XYFT_I: s = "image";        break;
  4070.       case XYFT_L: s = "labeled";      break;
  4071.       case XYFT_U: s = "binary undef"; break;
  4072. #else
  4073. #ifdef MAC
  4074.       case XYFT_B: s = "binary";       break;
  4075.       case XYFT_M: s = "macbinary";    break;
  4076. #else
  4077.       case XYFT_B: s = "binary";       break;
  4078. #ifdef CK_LABELED
  4079.       case XYFT_L: s = "labeled";      break;
  4080. #endif /* CK_LABELED */
  4081. #endif /* MAC */
  4082. #endif /* VMS */
  4083.       default: s = "unknown"; break;
  4084.     }
  4085.     return(s);
  4086. }
  4087.  
  4088. #ifndef NOXFER
  4089. VOID                                    /* SHOW TRANSFER */
  4090. shoxfer() {
  4091.     extern int docrc, usepipes, xfrxla, whereflg;
  4092.     extern char * xfrmsg;
  4093.     printf("\n");
  4094.     printf(" Transfer Bell: %s\n",showoff(xfrbel));
  4095.     printf(" Transfer Interruption: %s\n",showoff(xfrint));
  4096.     printf(" Transfer Cancellation: %s\n",showoff(xfrcan));
  4097. #ifndef NOCSETS
  4098.     printf(" Transfer Translation:  %s\n",showoff(xfrxla));
  4099.     printf(" Transfer Character-set: ");
  4100.     if (tcharset == TC_TRANSP)
  4101.       printf("Transparent\n");
  4102.     else
  4103.       printf("%s\n",tcsinfo[tcharset].keyword);
  4104. #endif /* NOCSETS */
  4105.     printf(" Transfer CRC-calculation: %s\n",showoff(docrc));
  4106.     printf(" Transfer Display: ");
  4107.     switch (fdispla) {
  4108.       case XYFD_N: printf("%s\n","none"); break;
  4109.       case XYFD_R: printf("%s\n","serial"); break;
  4110.       case XYFD_C: printf("%s\n","fullscreen"); break;
  4111.       case XYFD_S: printf("%s\n","crt"); break;
  4112.       case XYFD_B: printf("%s\n","brief"); break;
  4113.       case XYFD_G: printf("%s\n","gui"); break;
  4114.     }
  4115.     printf(" Transfer Message: %s\n", xfrmsg ? xfrmsg : "(none)");
  4116.     printf(" Transfer Locking-shift: ");
  4117.     if (lscapu == 2) {
  4118.         printf("forced");
  4119.     } else {
  4120.         printf("%s", (lscapr ? "enabled" : "disabled"));
  4121.         if (lscapr) printf(",%s%s", (lscapu ? " " : " not "), "used");
  4122.     }
  4123.     printf("\n Transfer Mode: %s\n",
  4124.            xfermode == XMODE_A ?
  4125.            "automatic" :
  4126.            "manual"
  4127.            );
  4128.     printf(" Transfer Pipes: %s\n", showoff(usepipes));
  4129.     printf(" Transfer Protocol: %s\n",ptab[protocol].p_name);
  4130.     printf(" Transfer Report: %s\n",showoff(whereflg));
  4131.     printf(" Transfer Slow-start: %s\n",showoff(slostart));
  4132.     printf("\n");
  4133. }
  4134. #endif /* NOXFER */
  4135.  
  4136. VOID
  4137. shoflow() {
  4138.     int i, x;
  4139.     extern int cxflow[], cxtype, ncxname, nfloname, autoflow;
  4140.     extern char * cxname[];
  4141.     printf("\nConnection type:        %s\n",cxname[cxtype]);
  4142.     if (autoflow) {
  4143.         printf("Current flow-control:   %s\n", floname[cxflow[cxtype]]);
  4144.         printf("Switches automatically: yes\n");
  4145.     } else {
  4146.         printf("Current flow-control:   %s\n", floname[flow]);
  4147.         printf("Switches automatically: no\n");
  4148.     }
  4149.     printf("\nDefaults by connection type:\n");
  4150.     debug(F111,"shoflow cxtype",cxname[cxtype],cxtype);
  4151.     debug(F101,"shoflow flow","",flow);
  4152.     for (i = 0; i < ncxname; i++) {
  4153. #ifdef NOLOCAL
  4154.         if (i > 0) break;
  4155. #endif /* NOLOCAL */
  4156. #ifndef NETCONN
  4157.         if (i > 2) break;
  4158. #endif /* NETCONN */
  4159. #ifndef DECNET
  4160.         if (i == CXT_DECNET) continue;
  4161. #endif /* DECNET */
  4162. #ifndef DECNET
  4163. #ifndef SUPERLAT
  4164.         if (i == CXT_LAT) continue;
  4165. #endif /* SUPERLAT */
  4166. #endif /* DECNET */
  4167. #ifndef CK_NETBIOS
  4168.         if (i == CXT_NETBIOS) continue;
  4169. #endif /* CK_NETBIOS */
  4170. #ifndef NPIPE
  4171.         if (i == CXT_NPIPE) continue;
  4172. #endif /* NPIPE */
  4173. #ifndef NETCMD
  4174.         if (i == CXT_PIPE) continue;
  4175. #endif /* NETCMD */
  4176. #ifndef ANYX25
  4177.         if (i == CXT_X25) continue;
  4178. #endif /* ANYX25 */
  4179.         x = cxflow[i];
  4180.         debug(F101,"shoflow x","",x);
  4181.         if (x < nfloname)
  4182.           printf("  %-14s: %s\n",cxname[i],floname[x]);
  4183.         else
  4184.           printf("  %-14s: (%d)\n",cxname[i],x);
  4185.     }
  4186.     printf("\n");
  4187. }
  4188.  
  4189. #ifndef NOLOCAL
  4190. #ifdef ANYX25
  4191. int
  4192. shox25(n) int n; {
  4193.     if (nettype == NET_SX25) {
  4194.         printf("SunLink X.25 V%d.%d",x25ver / 10,x25ver % 10);
  4195.         if (ttnproto == NP_X3) printf(", PAD X.3, X.28, X.29 protocol,");
  4196.         printf("\n");
  4197.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4198.         printf(" Reverse charge call %s",
  4199.                revcall ? "selected" : "not selected");
  4200.         printf (", Closed user group ");
  4201.         if (closgr > -1)
  4202.           printf ("%d",closgr);
  4203.         else
  4204.           printf ("not selected");
  4205.         printf("\n");
  4206.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4207.         printf(" Call user data %s.\n", cudata ? udata : "not selected");
  4208.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4209.     } else if (nettype == NET_VX25) {
  4210.         if (ttnproto == NP_X3) printf(", PAD X.3, X.28, X.29 protocol,");
  4211.         printf("\n");
  4212.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4213.         printf(" Reverse charge call %s",
  4214.                revcall ? "selected" : "not selected");
  4215.         printf (", Closed user group [unsupported]");
  4216.         if (closgr > -1)
  4217.           printf ("%d",closgr);
  4218.         else
  4219.           printf ("not selected");
  4220.         printf (",");
  4221.         printf("\n");
  4222.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4223.         printf(" Call user data %s.\n", cudata ? udata : "not selected");
  4224.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4225.     } else if (nettype == NET_IX25) {
  4226.         printf("AIX NPI X.25\n");
  4227.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4228.         printf("\n Reverse charge call %s",
  4229.                revcall ? "selected" : "not selected");
  4230.         printf (", Closed user group [unsupported]");
  4231.         if (closgr > -1)
  4232.           printf ("%d",closgr);
  4233.         else
  4234.           printf ("not selected");
  4235.         printf (",");
  4236.         printf("\n Call user data %s.\n", cudata ? udata : "not selected");
  4237.     }
  4238.     return(n);
  4239. }
  4240.  
  4241. #ifndef IBMX25
  4242. int
  4243. shopad(n) int n; {
  4244.     int i;
  4245.     printf("\nX.3 PAD Parameters:\n");
  4246.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4247.     for (i = 0; i < npadx3; i++) {
  4248.         printf(" [%d] %s %d\n",padx3tab[i].kwval,padx3tab[i].kwd,
  4249.                padparms[padx3tab[i].kwval]);
  4250.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4251.     }
  4252.     return(n);
  4253. }
  4254. #endif /* IBMX25 */
  4255. #endif /* ANYX25 */
  4256.  
  4257. VOID
  4258. shoparc() {
  4259.     extern int reliable, stopbits, clsondisc;
  4260.     int i; char *s;
  4261.     long zz;
  4262.  
  4263. #ifdef NEWFTP
  4264.     if (ftpisconnected()) {
  4265.         shoftp(1);
  4266.         printf("\n");
  4267.     }
  4268. #endif /* NEWFTP */
  4269.  
  4270.     printf("Communications Parameters:\n");
  4271.  
  4272.     if (network
  4273. #ifdef IKSD
  4274.          || inserver
  4275. #endif /* IKSD */
  4276.          ) {
  4277.         printf(" Network Host: %s%s",ttname,
  4278.                (reliable == SET_ON || (reliable == SET_AUTO && !local)
  4279. #ifdef TN_COMPORT
  4280.                && !istncomport()
  4281. #endif /* TN_COMPORT */
  4282. #ifdef IKSD
  4283.                || inserver
  4284. #endif /* IKSD */
  4285.                ) ? " (reliable)" : "");
  4286. #ifdef TN_COMPORT
  4287.         if (istncomport()) {
  4288.             int modemstate;
  4289.             char * oflow, * iflow = "", * parity, * stopsize, * signature;
  4290.             int baud = tnc_get_baud();
  4291.  
  4292.             switch (tnc_get_oflow()) {
  4293.               case TNC_CTL_OFLOW_NONE:
  4294.                 oflow = "none";
  4295.                 break;
  4296.               case TNC_CTL_OFLOW_XON_XOFF:
  4297.                 oflow = "xon/xoff";
  4298.                 break;
  4299.               case TNC_CTL_OFLOW_RTS_CTS:
  4300.                 oflow = "rts/cts";
  4301.                 break;
  4302.               case TNC_CTL_OFLOW_DCD:
  4303.                 oflow = "dcd";
  4304.                 break;
  4305.               case TNC_CTL_OFLOW_DSR:
  4306.                 oflow = "dsr";
  4307.                 break;
  4308.               default:
  4309.                 oflow = "(unknown)";
  4310.             }
  4311.             switch (tnc_get_iflow()) {
  4312.               case TNC_CTL_IFLOW_NONE:
  4313.                 iflow = "none";
  4314.                 break;
  4315.               case TNC_CTL_IFLOW_XON_XOFF:
  4316.                 iflow = "xon/xoff";
  4317.                 break;
  4318.               case TNC_CTL_IFLOW_RTS_CTS:
  4319.                 iflow = "rts/cts";
  4320.                 break;
  4321.               case TNC_CTL_IFLOW_DTR:
  4322.                 break;
  4323.               default:
  4324.                 iflow = oflow;
  4325.             }
  4326.             switch (tnc_get_parity()) {
  4327.               case TNC_PAR_NONE:
  4328.                 parity = "none";
  4329.                 break;
  4330.               case TNC_PAR_ODD:
  4331.                 parity = "odd";
  4332.                 break;
  4333.               case TNC_PAR_EVEN:
  4334.                 parity = "even";
  4335.                 break;
  4336.               case TNC_PAR_MARK:
  4337.                 parity = "mark";
  4338.                 break;
  4339.               case TNC_PAR_SPACE:
  4340.                 parity = "space";
  4341.                 break;
  4342.               default:
  4343.                 parity = "(unknown)";
  4344.             }
  4345.             switch (tnc_get_stopsize()) {
  4346.               case TNC_SB_1:
  4347.                 stopsize = "1";
  4348.                 break;
  4349.               case TNC_SB_1_5:
  4350.                 stopsize = "1.5";
  4351.                 break;
  4352.               case TNC_SB_2:
  4353.                 stopsize = "2";
  4354.                 break;
  4355.               default:
  4356.                 stopsize = "(unknown)";
  4357.             }
  4358.         signature = (char *)tnc_get_signature();
  4359.             printf("\n  Signature            : %s\n",signature?signature:"");
  4360.             if (baud <= 0)
  4361.               printf("  Speed                : (unknown)\n");
  4362.             else
  4363.               printf("  Speed                : %d\n", baud);
  4364.             printf("  Outbound Flow Control: %s\n", oflow);
  4365.             printf("  Inbound Flow Control : %s\n", iflow);
  4366.             printf("  Parity               : %s\n", parity);
  4367.             printf("  Data Size            : %d\n", tnc_get_datasize());
  4368.             printf("  Stop Bits            : %s\n", stopsize);
  4369.             printf("  DTR Signal           : %d\n", tnc_get_dtr_state());
  4370.             printf("  RTS Signal           : %d\n", tnc_get_rts_state());
  4371.             printf("  Modem State:\n");
  4372.             modemstate = tnc_get_ms();
  4373.             if (modemstate & TNC_MS_EDGE_RING)
  4374.               printf("    Trailing Edge Ring Detector On\n");
  4375.             else
  4376.               printf("    Trailing Edge Ring Detector Off\n");
  4377.             if (modemstate & TNC_MS_CTS_SIG)
  4378.               printf("    CTS Signal On\n");
  4379.             else
  4380.               printf("    CTS Signal Off\n");
  4381.             if (modemstate & TNC_MS_DSR_SIG)
  4382.               printf("    DSR Signal On\n");
  4383.             else
  4384.               printf("    DSR Signal Off\n");
  4385.             if (modemstate & TNC_MS_RI_SIG)
  4386.               printf("    Ring Indicator On\n");
  4387.             else
  4388.               printf("    Ring Indicator Off\n");
  4389.             if (modemstate & TNC_MS_RLSD_SIG)
  4390.               printf("    RLSD (CD) Signal On\n");
  4391.             else
  4392.               printf("    RLSD (CD) Signal Off\n");
  4393.             printf("\n");
  4394.         }
  4395. #endif /* TN_COMPORT */
  4396.     } else {
  4397.  
  4398.         printf(" %s: %s%s, speed: ",
  4399. #ifdef OS2
  4400.                "Port",
  4401. #else
  4402.                "Line",
  4403. #endif /* OS2 */
  4404.                ttname,
  4405. #ifdef CK_TTYFD
  4406.                (local &&
  4407. #ifdef VMS
  4408.                 vmsttyfd() < 0
  4409. #else
  4410.                 ttyfd == -1
  4411. #endif /* VMS */
  4412.                 ) ?
  4413.                  " (closed)" :
  4414.                    (reliable == SET_ON ? " (reliable)" : "")
  4415. #else
  4416.                ""
  4417. #endif /* CK_TTYFD */
  4418.                );
  4419.         if (
  4420. #ifdef CK_TTYFD
  4421. #ifdef VMS
  4422.             vmsttyfd() < 0
  4423. #else
  4424.             ttyfd == -1
  4425. #endif /* VMS */
  4426.             ||
  4427. #endif /* CK_TTYFD */
  4428.             (zz = ttgspd()) < 0) {
  4429.             printf("unknown");
  4430.         } else {
  4431.             if (speed == 8880) printf("75/1200");
  4432.             else if (speed == 134) printf("134.5");
  4433.             else printf("%ld",zz);
  4434.         }
  4435.     }
  4436.     if (network
  4437. #ifdef IKSD
  4438.          || inserver
  4439. #endif /* IKSD */
  4440.          )
  4441.       printf("\n Mode: ");
  4442.     else
  4443.       printf(", mode: ");
  4444.     if (local) printf("local"); else printf("remote");
  4445.     if (network == 0
  4446. #ifdef IKSD
  4447.          && !inserver
  4448. #endif/* IKSD */
  4449.          ) {
  4450. #ifdef CK_TAPI
  4451.         if (tttapi && !tapipass )
  4452.           printf(", modem: %s","TAPI");
  4453.         else
  4454. #endif /* CK_TAPI */
  4455.         printf(", modem: %s",gmdmtyp());
  4456.     } else {
  4457. #ifdef NETCONN
  4458.        if (nettype == NET_TCPA) printf(", TCP/IP");
  4459.        if (nettype == NET_TCPB) printf(", TCP/IP");
  4460.        if (nettype == NET_DEC) {
  4461.            if (ttnproto == NP_LAT) printf(", DECnet LAT");
  4462.            else if ( ttnproto == NP_CTERM ) printf(", DECnet CTERM");
  4463.            else printf(", DECnet");
  4464.        }
  4465.        if (nettype == NET_SLAT) printf(", Meridian Technologies' SuperLAT");
  4466. #ifdef NETFILE
  4467.        if (nettype == NET_FILE) printf(", local file");
  4468. #endif /* NETFILE */
  4469. #ifdef NETCMD
  4470.        if (nettype == NET_CMD) printf(", pipe");
  4471. #endif /* NETCMD */
  4472. #ifdef NETPTY
  4473.        if (nettype == NET_PTY) printf(", pseudoterminal");
  4474. #endif /* NETPTY */
  4475. #ifdef NETDLL
  4476.        if (nettype == NET_DLL) printf(", dynamic load library");
  4477. #endif /* NETDLL */
  4478.        if (nettype == NET_PIPE) printf(", Named Pipes");
  4479. #ifdef SSHBUILTIN
  4480.        if (nettype == NET_SSH)
  4481.          printf(", Secure Shell protocol (SECURE)");
  4482. #endif /* SSHBUILTIN */
  4483. #ifdef ANYX25
  4484.        if (shox25(0) < 0) return;
  4485. #endif /* ANYX25 */
  4486.        if (IS_TELNET()) {
  4487.            printf(", telnet protocol");
  4488.            if (0
  4489. #ifdef CK_ENCRYPTION
  4490.                || ck_tn_encrypting() && ck_tn_decrypting()
  4491. #endif /* CK_ENCRYPTION */
  4492. #ifdef CK_SSL
  4493.                || tls_active_flag || ssl_active_flag
  4494. #endif /* CK_SSL */
  4495.                )
  4496.              printf(" (SECURE)");
  4497.        }
  4498. #ifdef RLOGCODE
  4499.        else if (ttnproto == NP_RLOGIN || ttnproto == NP_K4LOGIN ||
  4500.                 ttnproto == NP_K5LOGIN)
  4501.          printf(", rlogin protocol");
  4502.        else if (ttnproto == NP_EK4LOGIN || ttnproto == NP_EK5LOGIN)
  4503.          printf(", rlogin protocol (SECURE)");
  4504. #endif /* RLOGCODE */
  4505. #ifdef CK_KERBEROS
  4506. #ifdef KRB5
  4507.        else if (ttnproto == NP_K5U2U)
  4508.          printf(", Kerberos 5 User to User protocol (SECURE)");
  4509. #endif /* KRB5 */
  4510. #endif /* CK_KERBEROS */
  4511. #endif /* NETCONN */
  4512.     }
  4513.     printf("\n");
  4514.     if (hwparity && local && !network)
  4515.       s = parnam((char)hwparity);
  4516.     else
  4517.       s = parnam((char)parity);
  4518.     printf(" Parity: %s%s",hwparity ? "hardware " : "", s);
  4519. #ifndef NOLOCAL
  4520.     if (local && !network) {
  4521.         int sb;
  4522.         char c;
  4523.         c = s[0];
  4524.         if (islower(c)) c = toupper(c);
  4525.         sb = stopbits;
  4526.         if (sb < 1) {
  4527.             sb = (speed > 0 && speed <= 110L) ? 2 : 1;
  4528.             printf(", stop-bits: (default)");
  4529.         } else {
  4530.             printf(", stop-bits: %d",sb);
  4531.         }
  4532.         if (hwparity)
  4533.           printf(" (8%c%d)",c,sb);
  4534.         else if (parity)
  4535.           printf(" (7%c%d)",c,sb);
  4536.         else
  4537.           printf(" (8N%d)",sb);
  4538.         printf("\n D");
  4539.     } else
  4540.       printf(", d");
  4541. #endif /* NOLOCAL */
  4542.  
  4543.     printf("uplex: %s, ", duplex ? "half" : "full");
  4544.     debug(F101,"shoparp flow","",flow);
  4545.     printf("flow: %s", floname[flow]);
  4546.     printf(", handshake: ");
  4547.     if (turn) printf("%d\n",turnch); else printf("none\n");
  4548. #ifdef COMMENT
  4549.     if (local && !network) {            /* SET CARRIER-WATCH */
  4550. #endif /* COMMENT */
  4551.         if (carrier == CAR_OFF) s = "off";
  4552.         else if (carrier == CAR_ON) s = "on";
  4553.         else if (carrier == CAR_AUT) s = "auto";
  4554.         else s = "unknown";
  4555.         printf(" Carrier-watch: %s", s);
  4556.         if (carrier == CAR_ON) {
  4557.             if (cdtimo) printf(", timeout: %d sec", cdtimo);
  4558.             else printf(", timeout: none");
  4559.         }
  4560. #ifdef COMMENT
  4561.     }
  4562. #endif /* COMMENT */
  4563.     printf(", close-on-disconnect: %s\n",showoff(clsondisc));
  4564.  
  4565. #ifdef UNIX                             /* UUCP lockfile, UNIX only */
  4566.     if (local) {
  4567. #ifndef NOUUCP
  4568.         if (!network && haslock && *flfnam)
  4569.           printf(" Lockfile: %s",flfnam);
  4570. #ifndef USETTYLOCK
  4571.         if (!network && haslock && lock2[0])
  4572.           printf("\n Secondary lockfile: %s",lock2);
  4573. #endif /* USETTYLOCK */
  4574. #else
  4575. #ifdef QNX
  4576.         {
  4577.             extern int qnxportlock, qnxopencount();
  4578.             if (local)
  4579.               printf(" Qnx-port-lock: %s, Open count: %d",
  4580.                      showoff(qnxportlock),
  4581.                      qnxopencount()
  4582.                      );
  4583.             else
  4584.               printf(" Qnx-port-lock: %s", showoff(qnxportlock));
  4585.         }
  4586. #endif /* QNX */
  4587. #endif /* NOUUCP */
  4588.         printf("\n");
  4589.     } else {
  4590.         char * s, * ttglckdir();
  4591.         s = ttglckdir();
  4592.         if (!s) s = "";
  4593.         printf(" Lockfile directory: %s\n", *s ? s : "(none)");
  4594.     }
  4595. #endif /* UNIX */
  4596.     if (!local) {
  4597.         printf(" Typical port device name: %s\n",ttgtpn());
  4598.     }
  4599.     if (local) {
  4600.         int i;
  4601.         i = parity ? 7 : 8;
  4602.         if (i == 8) i = (cmask == 0177) ? 7 : 8;
  4603.         printf(" Terminal bytesize: %d,",i);
  4604.         printf(" escape character: %d (^%c)\n",escape,ctl(escape));
  4605.     }
  4606. }
  4607.  
  4608. int
  4609. shotcp(n) int n; {
  4610. #ifdef TCPSOCKET
  4611.     if (nettype == NET_TCPA || nettype == NET_TCPB) {
  4612.         printf("SET TCP parameters:\n");
  4613.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4614.         printf(" Reverse DNS lookup: %s\n", showooa(tcp_rdns));
  4615.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4616.  
  4617. #ifdef CK_DNS_SRV
  4618.         printf(" DNS Service Records lookup: %s\n", showooa(tcp_dns_srv));
  4619.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4620. #endif /* CK_DNS_SRV */
  4621.  
  4622. #ifndef NOTCPOPTS
  4623. #ifdef SOL_SOCKET
  4624. #ifdef SO_KEEPALIVE
  4625.         printf(" Keepalive: %s\n", showoff(tcp_keepalive));
  4626.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4627. #endif /* SO_KEEPALIVE */
  4628.  
  4629. #ifdef SO_LINGER
  4630.         printf(" Linger: %s", tcp_linger ? "on, " : "off\n" );
  4631.         if (tcp_linger) {
  4632.             if (tcp_linger_tmo)
  4633.               printf("%d x 10 milliseconds\n",tcp_linger_tmo);
  4634.             else
  4635.               printf("no timeout\n");
  4636.         }
  4637.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4638. #endif /* SO_LINGER */
  4639.  
  4640. #ifdef SO_DONTROUTE
  4641.         printf(" DontRoute: %s\n", tcp_dontroute ? "on" : "off" );
  4642.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4643. #endif /* SO_DONTROUTE */
  4644.  
  4645. #ifdef TCP_NODELAY
  4646.         printf(" Nodelay: %s\n", showoff(tcp_nodelay));
  4647.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4648. #endif /* TCP_NODELAY */
  4649.  
  4650. #ifdef SO_SNDBUF
  4651.         if (tcp_sendbuf <= 0)
  4652.           printf(" Send buffer: (default size)\n");
  4653.         else
  4654.           printf(" Send buffer: %d bytes\n", tcp_sendbuf);
  4655.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4656. #endif /* SO_SNDBUF */
  4657. #ifdef SO_RCVBUF
  4658.         if (tcp_recvbuf <= 0)
  4659.           printf(" Receive buffer: (default size)\n");
  4660.         else
  4661.           printf(" Receive buffer: %d bytes\n", tcp_recvbuf);
  4662.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  4663. #endif /* SO_RCVBUF */
  4664. #endif /* SOL_SOCKET */
  4665. #endif /* NOTCPOPTS */
  4666.         printf(" address: %s\n",tcp_address ? tcp_address : "(none)");
  4667.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4668. #ifndef NOHTTP
  4669.         printf(" http-proxy: %s\n",tcp_http_proxy ? tcp_http_proxy : "(none)");
  4670.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4671. #endif /* NOHTTP */
  4672. #ifdef NT
  4673. #ifdef CK_SOCKS
  4674.         printf(" socks-server: %s\n",tcp_socks_svr ? tcp_socks_svr : "(none)");
  4675.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4676. #ifdef CK_SOCKS_NS
  4677.         printf(" socks-name-server: %s\n",
  4678.                tcp_socks_ns ? tcp_socks_ns : "(none)");
  4679.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4680. #endif /* CK_SOCKS_NS */
  4681. #endif /* CK_SOCKS */
  4682. #endif /* NT */
  4683.     }
  4684. #endif /* TCPSOCKET */
  4685.     return(n);
  4686. }
  4687.  
  4688. #ifdef TNCODE
  4689. int
  4690. shotopt(n) int n; {
  4691.     int opt;
  4692.  
  4693.     printf("%-21s %12s %12s %12s %12s\n\n",
  4694.            "Telnet Option","Me (client)","U (client)",
  4695.            "Me (server)","U (server)");
  4696.     n += 2;
  4697.     if (n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4698.  
  4699.     for ( opt = TELOPT_FIRST; opt <= TELOPT_LAST; opt++) {
  4700.         switch (opt) {
  4701.           case TELOPT_AUTHENTICATION:
  4702.           case TELOPT_ENCRYPTION:
  4703.           case TELOPT_TTYPE:
  4704.           case TELOPT_NAWS:
  4705.           case TELOPT_BINARY:
  4706.           case TELOPT_NEWENVIRON:
  4707.           case TELOPT_SNDLOC:
  4708.           case TELOPT_XDISPLOC:
  4709.           case TELOPT_SGA:
  4710.           case TELOPT_ECHO:
  4711.           case TELOPT_KERMIT:
  4712.           case TELOPT_START_TLS:
  4713.           case TELOPT_FORWARD_X:
  4714.           case TELOPT_COMPORT:
  4715.             break;
  4716.           default:
  4717.             continue;
  4718.         }
  4719.         printf("%03d %-17s ",
  4720.                opt, TELOPT(opt)
  4721.                );
  4722.         printf("%12s %12s ",
  4723.                TELOPT_MODE(TELOPT_DEF_C_ME_MODE(opt)),
  4724.                TELOPT_MODE(TELOPT_DEF_C_U_MODE(opt))
  4725.                );
  4726.         printf("%12s %12s\n",
  4727.                TELOPT_MODE(TELOPT_DEF_S_ME_MODE(opt)),
  4728.                TELOPT_MODE(TELOPT_DEF_S_U_MODE(opt))
  4729.                );
  4730.  
  4731.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4732.         if (sstelnet)
  4733.           printf("%21s %12s %12s %12s %12s\n",
  4734.                  "",
  4735.                  "",
  4736.                  "",
  4737.                  (TELOPT_ME(opt)?"WILL":"WONT"),
  4738.                  (TELOPT_U(opt)?"DO":"DONT")
  4739.                  );
  4740.         else
  4741.           printf("%21s %12s %12s %12s %12s\n",
  4742.                  "",
  4743.                  (TELOPT_ME(opt)?"WILL":"WONT"),
  4744.                  (TELOPT_U(opt)?"DO":"DONT"),
  4745.                  "",
  4746.                  ""
  4747.                  );
  4748.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4749.     }
  4750.     return(n);
  4751. }
  4752.  
  4753. int
  4754. shotel(n) int n; {
  4755.     extern int tn_duplex;
  4756. #ifdef CK_ENVIRONMENT
  4757.     extern int tn_env_flg;
  4758.     extern char tn_env_acct[];
  4759.     extern char tn_env_job[];
  4760.     extern char tn_env_prnt[];
  4761.     extern char tn_env_sys[];
  4762.     extern char * tn_env_uservar[8][2];
  4763.     int x;
  4764. #endif /* CK_ENVIRONMENT */
  4765. #ifdef CK_SNDLOC
  4766.     extern char * tn_loc;
  4767. #endif /* CK_SNDLOC */
  4768.     printf("SET TELNET parameters:\n echo: %s\n NVT newline-mode: ",
  4769.            tn_duplex ? "local" : "remote");
  4770.     switch (tn_nlm) {
  4771.       case TNL_CRNUL: printf("%s\n","off (cr-nul)"); break;
  4772.       case TNL_CRLF:  printf("%s\n","on (cr-lf)"); break;
  4773.       case TNL_CR:    printf("%s\n","raw (cr)"); break;
  4774.       case TNL_LF:    printf("%s\n","(lf)"); break;
  4775.     }
  4776.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4777. #ifdef CK_AUTHENTICATION
  4778.     {
  4779.         int type = ck_tn_authenticated();
  4780.         printf(" authentication: ");
  4781.         switch (sstelnet ?
  4782.                 TELOPT_U_MODE(TELOPT_AUTHENTICATION) :
  4783.                  TELOPT_ME_MODE(TELOPT_AUTHENTICATION)
  4784.                 ) {
  4785.           case TN_NG_AC: printf( "accepted " ); break;
  4786.           case TN_NG_RF: printf( "refused  " ); break;
  4787.           case TN_NG_RQ: printf( "requested"); break;
  4788.           case TN_NG_MU: printf( "required "); break;
  4789.         }
  4790.  
  4791. #ifdef CK_SSL
  4792.         if ((ssl_active_flag || tls_active_flag) &&
  4793.              ck_tn_auth_valid() == AUTH_VALID &&
  4794.              (!TELOPT_U(TELOPT_AUTHENTICATION) ||
  4795.                type == AUTHTYPE_NULL ||
  4796.                type == AUTHTYPE_AUTO))
  4797.             printf("   in use: X.509 certificate\n");
  4798.         else
  4799. #endif /* CK_SSL */
  4800.           printf("   in use: %s\n",AUTHTYPE_NAME(type));
  4801.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4802.         if (forward_flag)
  4803.           printf("  credentials forwarding requested %s\n",
  4804.                  forwarded_tickets ? "and completed" :
  4805.                  "but not completed");
  4806.         else
  4807.           printf("  credentials forwarding disabled\n");
  4808.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4809.     }
  4810. #endif /* CK_AUTHENTICATION */
  4811. #ifdef CK_ENCRYPTION
  4812.     {
  4813.         int i,x;
  4814.         int e_type = ck_tn_encrypting();
  4815.         int d_type = ck_tn_decrypting();
  4816.         char * e_str = NULL, * d_str = NULL;
  4817.         static struct keytab * tnetbl = NULL;
  4818.         static int ntnetbl = 0;
  4819.  
  4820.         x = ck_get_crypt_table(&tnetbl,&ntnetbl);
  4821.  
  4822.         for (i = 0; i < ntnetbl; i++) {
  4823.             if (e_type == tnetbl[i].kwval)
  4824.               e_str = tnetbl[i].kwd;
  4825.             if (d_type == tnetbl[i].kwval)
  4826.               d_str = tnetbl[i].kwd;
  4827.         }
  4828.         printf(" encryption: ");
  4829.         switch (TELOPT_ME_MODE(TELOPT_ENCRYPTION)) {
  4830.           /* This should be changed to report both ME and U modes */
  4831.           case TN_NG_AC: printf( "accepted " ); break;
  4832.           case TN_NG_RF: printf( "refused  " ); break;
  4833.           case TN_NG_RQ: printf( "requested"); break;
  4834.           case TN_NG_MU: printf( "required "); break;
  4835.         }
  4836.         printf("       in use: ");
  4837.         switch ((e_type ? 1 : 0) | (d_type ? 2 : 0)) {
  4838.           case 0:
  4839.             printf("plain text in both directions");
  4840.             break;
  4841.           case 1:
  4842.             printf("%s output, plain text input",e_str);
  4843.             break;
  4844.           case 2:
  4845.             printf("plain text output, %s input",d_str);
  4846.             break;
  4847.           case 3:
  4848.             printf("%s output, %s input",e_str,d_str);
  4849.             break;
  4850.         }
  4851.         printf("\n");
  4852.         if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4853.     }
  4854. #endif /* CK_ENCRYPTION */
  4855. #ifdef IKS_OPTION
  4856.     printf(" kermit: ");
  4857.     switch (TELOPT_U_MODE(TELOPT_KERMIT)) {
  4858.       case TN_NG_AC: printf( "u, accepted;  " ); break;
  4859.       case TN_NG_RF: printf( "u, refused;   " ); break;
  4860.       case TN_NG_RQ: printf( "u, requested; "); break;
  4861.       case TN_NG_MU: printf( "u, required;  "); break;
  4862.     }
  4863.     switch (TELOPT_ME_MODE(TELOPT_KERMIT)) {
  4864.       case TN_NG_AC: printf( "me, accepted;  " ); break;
  4865.       case TN_NG_RF: printf( "me, refused;   " ); break;
  4866.       case TN_NG_RQ: printf( "me, requested; "); break;
  4867.       case TN_NG_MU: printf( "me, required;  "); break;
  4868.     }
  4869.     if (TELOPT_U(TELOPT_KERMIT))
  4870.       printf(" u, %s",
  4871.              TELOPT_SB(TELOPT_KERMIT).kermit.u_start ?
  4872.              "started" :
  4873.              "stopped"
  4874.              );
  4875.     else
  4876.       printf(" u, n/a");
  4877.     if (TELOPT_ME(TELOPT_KERMIT))
  4878.       printf(" me, %s;",
  4879.              TELOPT_SB(TELOPT_KERMIT).kermit.me_start ?
  4880.              "started" :
  4881.              "stopped"
  4882.              );
  4883.     else
  4884.       printf(" me, n/a;");
  4885.     printf("\n");
  4886.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4887. #endif /* IKS_OPTION */
  4888.     printf(" BINARY newline-mode: ");
  4889.     switch (tn_b_nlm) {
  4890.       case TNL_CRNUL: printf("%s\n","off (cr-nul)"); break;
  4891.       case TNL_CRLF:  printf("%s\n","on (cr-lf)"); break;
  4892.       case TNL_CR:    printf("%s\n","raw (cr)"); break;
  4893.       case TNL_LF:    printf("%s\n","(lf)"); break;
  4894.     }
  4895.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4896.     printf(" binary-mode: ");
  4897.     switch (TELOPT_U_MODE(TELOPT_BINARY)) {
  4898.       case TN_NG_AC: printf( "u, accepted;  " ); break;
  4899.       case TN_NG_RF: printf( "u, refused;   " ); break;
  4900.       case TN_NG_RQ: printf( "u, requested; "); break;
  4901.       case TN_NG_MU: printf( "u, required;  "); break;
  4902.     }
  4903.     switch (TELOPT_ME_MODE(TELOPT_BINARY)) {
  4904.       case TN_NG_AC: printf( "me, accepted; " ); break ;
  4905.       case TN_NG_RF: printf( "me, refused; " ); break;
  4906.       case TN_NG_RQ: printf( "me, requested; "); break;
  4907.       case TN_NG_MU: printf( "me, required;  "); break;
  4908.     }
  4909.     printf("u, %s; me, %s\n",
  4910.            TELOPT_U(TELOPT_BINARY) ? "BINARY" : "NVT",
  4911.            TELOPT_ME(TELOPT_BINARY) ? "BINARY" : "NVT"
  4912.            );
  4913.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4914.     printf(" binary-transfer-mode: %s\n",showoff(tn_b_xfer));
  4915.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4916.     printf(" bug binary-me-means-u-too: %s\n",showoff(tn_b_meu));
  4917.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4918.     printf(" bug binary-u-means-me-too: %s\n",showoff(tn_b_ume));
  4919.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4920.     printf(" bug sb-implies-will-do: %s\n",showoff(tn_sb_bug));
  4921.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4922.     printf(" terminal-type: ");
  4923.     if (tn_term) {
  4924.         printf("%s\n",tn_term);
  4925.     } else {
  4926.         char *p;
  4927. #ifdef OS2
  4928.         p = (tt_type >= 0 && tt_type <= max_tt) ?
  4929.           tt_info[tt_type].x_name :
  4930.             "UNKNOWN";
  4931. #else
  4932.         p = getenv("TERM");
  4933. #endif /* OS2 */
  4934.         if (p)
  4935.           printf("none (%s will be used)\n",p);
  4936.         else printf("none\n");
  4937.     }
  4938.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4939. #ifdef CK_ENVIRONMENT
  4940.     printf(" environment: %s\n", showoff(tn_env_flg));
  4941.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4942.     printf("   ACCOUNT: %s\n",tn_env_acct);
  4943.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4944.     printf("   DISPLAY: %s\n",(char *)tn_get_display() ?
  4945.             (char *)tn_get_display() : "");
  4946.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4947.     printf("   JOB    : %s\n",tn_env_job);
  4948.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4949.     printf("   PRINTER: %s\n",tn_env_prnt);
  4950.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4951. #ifndef NOSPL
  4952.     printf("   USER   : %s\n",uidbuf);
  4953.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4954. #endif /* NOSPL */
  4955.     printf("   SYSTEM : %s\n",tn_env_sys);
  4956.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4957.     for (x = 0; x < 8; x++) {
  4958.         if (tn_env_uservar[x][0] && tn_env_uservar[x][1]) {
  4959.             printf("   %-7s: %s\n",tn_env_uservar[x][0],
  4960.                    tn_env_uservar[x][1]);
  4961.             if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4962.         }
  4963.     }
  4964. #endif /* CK_ENVIRONMENT */
  4965. #ifdef CK_SNDLOC
  4966.     printf("  LOCATION: %s\n", tn_loc ? tn_loc : "");
  4967.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4968. #endif /* CK_SNDLOC */
  4969. #ifdef CK_FORWARD_X
  4970.     printf(" .Xauthority-file: %s\n", (char *)XauFileName() ?
  4971.             (char *)XauFileName() : "(none)");
  4972.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4973. #endif /* CK_FORWARD_X */
  4974.     return(n);
  4975. }
  4976. #endif /* TNCODE */
  4977.  
  4978. #ifdef CK_NETBIOS
  4979. static int
  4980. shonb(n) int n; {
  4981.     printf("NETBIOS parameters:\n");
  4982.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4983.     printf(" API       : %s\n",
  4984.            NetbeuiAPI ?
  4985.            "NETAPI.DLL - IBM Extended Services or Novell Netware Requester"
  4986.            : "ACSNETB.DLL - IBM Network Transport Services/2" ) ;
  4987.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4988.     printf(" Local Name: [%s]\n", NetBiosName);
  4989.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4990.     printf(" Adapter   : %d\n", NetBiosAdapter);
  4991.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4992.     if (NetBiosLSN > 0xFF) {
  4993.         printf(" Session   : %d\n", NetBiosLSN);
  4994.     } else {
  4995.         printf(" Session   : none active\n");
  4996.     }
  4997.     if (++n > cmd_rows - 3) if (!askmore()) return(-1); else n = 0;
  4998.     return(n);
  4999. }
  5000. #endif /* CK_NETBIOS */
  5001.  
  5002. #ifndef NONET
  5003. int
  5004. shonet() {
  5005.  
  5006. #ifndef NETCONN
  5007.     printf("\nNo networks are supported in this version of C-Kermit\n");
  5008.  
  5009. #else
  5010. #ifdef NOLOCAL
  5011.     printf("\nNo networks are supported in this version of C-Kermit\n");
  5012.  
  5013. #else /* rest of this routine */
  5014.  
  5015.     int i, n = 4;
  5016.  
  5017. #ifndef NODIAL
  5018.     if (nnetdir <= 1) {
  5019.         printf("\nNetwork directory: %s\n",netdir[0] ? netdir[0] : "(none)");
  5020.         n++;
  5021.     } else {
  5022.         int i;
  5023.         printf("\nNetwork directories:\n");
  5024.         for (i = 0; i < nnetdir; i++) {
  5025.             printf("%2d. %s\n",i,netdir[i]);
  5026.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5027.         }
  5028.     }
  5029. #endif /* NODIAL */
  5030.  
  5031. #ifdef SSHCMD
  5032.     {
  5033.         extern char * sshcmd;
  5034.         printf("SSH COMMAND: %s\n",sshcmd ? sshcmd : "ssh -e none");
  5035.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5036.     }
  5037. #endif /* SSHCMD */
  5038.  
  5039. #ifdef OS2
  5040.     printf("\nNetwork availability:\n");
  5041. #else
  5042.     printf("\nSupported networks:\n");
  5043. #endif /* OS2 */
  5044.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5045.  
  5046. #ifdef VMS
  5047.  
  5048. #ifdef TCPWARE
  5049.     printf(" Process Software Corporation TCPware for OpenVMS");
  5050. #else
  5051. #ifdef MULTINET
  5052.     printf(" TGV MultiNet TCP/IP");
  5053. #else
  5054. #ifdef WINTCP
  5055.     printf(" WOLLONGONG WIN/TCP");
  5056. #else
  5057. #ifdef DEC_TCPIP
  5058.     {
  5059.         static $DESCRIPTOR(tcp_desc,"_TCP0:");
  5060.         int status;
  5061.         long devclass;
  5062.         static int itmcod = DVI$_DEVCLASS;
  5063.  
  5064. #ifdef COMMENT
  5065.         status = LIB$GETDVI(&itmcod, 0, &tcp_desc, &devclass);
  5066. #else
  5067.         /* Martin Zinser 9/96 */
  5068.         status = lib$getdvi(&itmcod, 0, &tcp_desc, &devclass);
  5069. #endif /* COMMENT */
  5070.         if ((status & 1) && (devclass == DC$_SCOM))
  5071.           printf(" Process Software Corporation TCPware for OpenVMS");
  5072.         else
  5073. #ifdef UCX50
  5074.           printf(" DEC TCP/IP Services for (Open)VMS 5.0");
  5075. #else
  5076.           printf(" DEC TCP/IP Services for (Open)VMS");
  5077. #endif /* UCX50 */
  5078.     }
  5079. #else
  5080. #ifdef CMU_TCPIP
  5081.     printf(" CMU-OpenVMS/IP");
  5082. #else
  5083.     printf(" None");
  5084. #endif /* CMU_TCPIP */
  5085. #endif /* DEC_TCPIP */
  5086. #endif /* WINTCP */
  5087. #endif /* MULTINET */
  5088. #endif /* TCPWARE */
  5089.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5090. #ifdef TNCODE
  5091.     printf(", TELNET protocol\n\n");
  5092.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5093.     n = shotel(n);
  5094.     if (n < 0) return(0);
  5095.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5096. #endif /* TNCODE */
  5097.     printf("\n");
  5098.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5099.     printf("\n");
  5100.     n = shotcp(++n);
  5101.     if (n < 0) return(0);
  5102. #else /* Not VMS */
  5103.  
  5104. #ifdef SUNX25
  5105.     printf(" SunLink X.25\n");
  5106.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5107. #endif /* SUNX25 */
  5108.  
  5109. #ifdef STRATUSX25
  5110.     printf(" Stratus VOS X.25\n");
  5111.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5112. #endif /* STRATUSX25 */
  5113.  
  5114. #ifdef IBMX25
  5115.     printf(" IBM AIX X.25\n");
  5116.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5117. #endif /* IBMX25 */
  5118.  
  5119. #ifdef HPX25
  5120.     printf(" HP-UX X.25\n");
  5121.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5122. #endif /* HPX25 */
  5123.  
  5124. #ifdef SSHBUILTIN
  5125.     if (ck_ssleay_is_installed())
  5126.         printf(" SSH V1 and V2 protocols\n");
  5127.     else
  5128.         printf(" SSH V1 and V2 protocols - not available\n");
  5129. #endif /* SSHBUILTIN */
  5130.  
  5131. #ifdef DECNET
  5132. #ifdef OS2
  5133. #ifdef NT
  5134.     if (dnet_avail)
  5135.       printf(" DECnet, LAT and CTERM protocols\n");
  5136.     else
  5137.       printf(" DECnet, LAT and CTERM protocols - not available\n");
  5138.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5139. #else /* NT */
  5140.     if (dnet_avail)
  5141.       printf(" DECnet, LAT protocol\n");
  5142.     else
  5143.       printf(" DECnet, LAT protocol - not available\n");
  5144.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5145. #endif /* NT */
  5146. #else
  5147.     printf(" DECnet\n");
  5148.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5149. #endif /* OS2 */
  5150. #endif /* DECNET */
  5151.  
  5152. #ifdef NPIPE
  5153.     printf(" Named Pipes\n");
  5154.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5155. #endif /* NPIPE */
  5156.  
  5157. #ifdef CK_NETBIOS
  5158.     if (netbiosAvail)
  5159.       printf(" NETBIOS\n");
  5160.     else
  5161.       printf(" NETBIOS - not available\n");
  5162.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5163. #endif /* CK_NETBIOS */
  5164.  
  5165. #ifdef SUPERLAT
  5166.     if (slat_avail)
  5167.       printf(" SuperLAT\n");
  5168.     else
  5169.       printf(" SuperLAT - not available\n") ;
  5170.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5171. #endif /* SUPERLAT */
  5172.  
  5173. #ifdef TCPSOCKET
  5174.     if (
  5175. #ifdef OS2
  5176.         tcp_avail
  5177. #else
  5178.         1
  5179. #endif /* OS2 */
  5180.         ) {
  5181.         char ipaddr[16];
  5182.  
  5183.         if (getlocalipaddrs(ipaddr,16,0) < 0) {
  5184. #ifdef OS2ONLY
  5185.             printf(" TCP/IP via %s\n", tcpname);
  5186. #else
  5187.             printf(" TCP/IP\n");
  5188. #endif /* OS2ONLY */
  5189.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5190.         } else {
  5191.             int i = 1;
  5192. #ifdef OS2ONLY
  5193.           printf(" TCP/IP [%16s] via %s\n", ipaddr, tcpname);
  5194. #else
  5195.           printf(" TCP/IP [%16s]\n",ipaddr);
  5196. #endif /* OS2ONLY */
  5197.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5198.  
  5199.             while (getlocalipaddrs(ipaddr,16,i++) >= 0) {
  5200.                 printf("        [%16s]\n",ipaddr);
  5201.                 if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5202.             }
  5203.         }
  5204.         if (nettype == NET_TCPB) {
  5205.             printf("\n");
  5206.             n = shotcp(++n);
  5207.             if (n < 0) return(0);
  5208. #ifdef TNCODE
  5209.             printf("\n");
  5210.             n = shotel(++n);
  5211.             if (n < 0) return(0);
  5212. #endif /* TNCODE */
  5213.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5214.         }
  5215. #ifdef OS2
  5216.     } else {
  5217.         printf(" TCP/IP - not available%s\n",tcpname[0] ? tcpname : "" );
  5218.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5219. #endif /* OS2 */
  5220.     }
  5221. #endif /* TCPSOCKET */
  5222.  
  5223. #ifdef CK_NETBIOS
  5224.     if (netbiosAvail && nettype == NET_BIOS) {
  5225.        printf("\n") ;
  5226.        if ((n = shonb(++n)) < 0) return(0);
  5227.        if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5228.     }
  5229. #endif /* CK_NETBIOS */
  5230.  
  5231. #endif /* VMS */
  5232.  
  5233.     printf("\nActive network connection:\n");
  5234.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5235.  
  5236.     if (network) {
  5237.         printf(" Host: %s",ttname);
  5238.         if ((nettype == NET_TCPA || nettype == NET_TCPB) && *ipaddr)
  5239.           printf(" [%s]",ipaddr);
  5240.     } else
  5241.       printf(" Host: none");
  5242.     printf(", via: ");
  5243.     if (nettype == NET_TCPA || nettype == NET_TCPB)
  5244.       printf("tcp/ip\n");
  5245.     else if (nettype == NET_SX25)
  5246.       printf("SunLink X.25\n");
  5247.     else if (nettype == NET_VX25)
  5248.       printf("Stratus VOS X.25\n");
  5249.     else if (nettype == NET_IX25)
  5250.       printf("IBM AIX X.25\n");
  5251.     else if (nettype == NET_HX25)
  5252.       printf("HP-UX X.25\n");
  5253.     else if (nettype == NET_DEC) {
  5254.         if ( ttnproto == NP_LAT )
  5255.           printf("DECnet LAT\n");
  5256.         else if ( ttnproto == NP_CTERM )
  5257.           printf("DECnet CTERM\n");
  5258.         else
  5259.           printf("DECnet\n");
  5260.     } else if (nettype == NET_PIPE)
  5261.       printf("Named Pipes\n");
  5262.     else if (nettype == NET_BIOS)
  5263.       printf("NetBIOS\n");
  5264.     else if (nettype == NET_SLAT)
  5265.       printf("SuperLAT\n");
  5266.  
  5267. #ifdef NETFILE
  5268.     else if ( nettype == NET_FILE )
  5269.       printf("local file\n");
  5270. #endif /* NETFILE */
  5271. #ifdef NETCMD
  5272.     else if ( nettype == NET_CMD )
  5273.       printf("pipe\n");
  5274. #endif /* NETCMD */
  5275. #ifdef NETPTY
  5276.     else if ( nettype == NET_PTY )
  5277.         printf("pseudoterminal\n");
  5278. #endif /* NETPTY */
  5279. #ifdef NETDLL
  5280.     else if ( nettype == NET_DLL )
  5281.       printf("dynamic link library\n");
  5282. #endif /* NETDLL */
  5283.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5284.  
  5285. #ifdef ANYX25
  5286.     if ((nettype == NET_SX25) ||
  5287.         (nettype == NET_VX25) ||
  5288.         (nettype == NET_IX25))
  5289.       if ((n = shox25(n)) < 0) return(0);
  5290. #endif /* ANYX25 */
  5291.  
  5292. #ifdef SSHBUILTIN
  5293.     if (nettype == NET_SSH) {
  5294.         printf("Secure Shell protocol\n");
  5295.         if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5296.     }
  5297. #endif /* SSHBUILTIN */
  5298.  
  5299.     if (nettype == NET_TCPA || nettype == NET_TCPB) {
  5300. #ifdef RLOGCODE
  5301.         if (ttnproto == NP_RLOGIN) {
  5302.             printf(" LOGIN (rlogin) protocol\n");
  5303.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5304.         }
  5305. #ifdef CK_KERBEROS
  5306.         else if (ttnproto == NP_K4LOGIN) {
  5307.             printf(" Kerberos 4 LOGIN (klogin) protocol\n");
  5308.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5309.         }
  5310.         else if (ttnproto == NP_EK4LOGIN) {
  5311.             printf(" Encrypted Kerberos 4 LOGIN (eklogin) protocol\n");
  5312.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5313.         }
  5314.         else if (ttnproto == NP_K5LOGIN) {
  5315.             printf(" Kerberos 5 LOGIN (klogin) protocol\n");
  5316.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5317.         }
  5318.         else if (ttnproto == NP_EK5LOGIN) {
  5319.             printf(" Encrypted Kerberos 5 LOGIN (eklogin) protocol\n");
  5320.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5321.         }
  5322. #endif /* CK_KERBEROS */
  5323. #endif /* RLOGCODE */
  5324. #ifdef CK_KERBEROS
  5325.         if (ttnproto == NP_K5U2U) {
  5326.             printf(" Kerberos 5 User to User protocol\n");
  5327.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5328.         }
  5329. #endif /* CK_KERBEROS */
  5330.  
  5331. #ifdef TNCODE
  5332.         if (IS_TELNET()) {
  5333.             printf(" TELNET protocol\n");
  5334.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5335.             printf(" Echoing is currently %s\n",duplex ? "local" : "remote");
  5336.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5337.         }
  5338. #endif /* TNCODE */
  5339.         if (ttnproto == NP_TCPRAW) {
  5340.             printf(" Raw TCP socket\n");
  5341.             if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5342.         }
  5343.     }
  5344.     printf("\n");
  5345. #endif /* NOLOCAL */
  5346. #endif /* NETCONN */
  5347.     return(0);
  5348. }
  5349. #endif /* NONET */
  5350.  
  5351. #ifndef NODIAL
  5352. VOID
  5353. shodial() {
  5354.     if (mdmtyp >= 0 || local != 0) doshodial();
  5355. }
  5356.  
  5357. VOID
  5358. shods(s) char *s; {                     /* Show a dial-related string */
  5359.     char c;
  5360.     if (s == NULL || !(*s)) {           /* Empty? */
  5361.         printf("(none)\n");
  5362.     } else {                            /* Not empty. */
  5363.         while ((c = *s++))              /* Can contain controls */
  5364.           if (c == '\\')                /* a backslash */
  5365.             printf("\\\\");
  5366.           else if (c > 31 && c < 127) {
  5367.               putchar(c);
  5368.           } else
  5369.             printf("\\{%d}",c);
  5370.         printf("\n");
  5371.     }
  5372. }
  5373.  
  5374. int
  5375. doshodial() {
  5376.  
  5377.     int i, n = 2;
  5378.  
  5379.     printf(" Dial status:  %d", dialsta);
  5380.  
  5381. #ifdef BIGBUFOK
  5382.     if (dialsta > 90)
  5383.       printf(" = Unknown error");
  5384.     else if (dialsta < 0)
  5385.       printf(" = (none)");
  5386.     else if (dialsta < 35 && dialmsg[dialsta])
  5387.       printf(" = %s", dialmsg[dialsta]);
  5388. #endif /* BIGBUFOK */
  5389.     n++;
  5390.     if (ndialdir <= 1) {
  5391.         printf("\n Dial directory: %s\n",dialdir[0] ? dialdir[0] : "(none)");
  5392.     } else {
  5393.         int i;
  5394.         printf("\n Dial directories:\n");
  5395.         for (i = 0; i < ndialdir; i++)
  5396.           printf("%2d. %s\n",i+1,dialdir[i]);
  5397.         n += ndialdir;
  5398.     }
  5399.     printf(" Dial method:  ");
  5400.     if      (dialmauto)         printf("auto   ");
  5401.     else if (dialmth == XYDM_D) printf("default");
  5402.     else if (dialmth == XYDM_P) printf("pulse  ");
  5403.     else if (dialmth == XYDM_T) printf("tone   ");
  5404.     printf("         Dial sort: %s\n",dialsrt ? "on" : "off");
  5405.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5406.     printf(" Dial hangup:  %s             Dial display: %s\n",
  5407.            dialhng ? "on " : "off", dialdpy ? "on" : "off");
  5408.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5409.     if (dialrtr > 0) {
  5410.         printf(" Dial retries: %-6d          Dial interval: %d\n",
  5411.                dialrtr, dialint);
  5412.     } else {
  5413.         printf(" Dial retries: (auto)          Dial interval: %d\n", dialint);
  5414.     }
  5415.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5416.     printf(" Dial timeout: ");
  5417. #ifdef CK_TAPI
  5418.     if (tttapi && !tapipass)
  5419.         printf("(tapi)");
  5420.     else
  5421. #endif /* CK_TAPI */
  5422.     if (dialtmo > 0)
  5423.       printf("%4d sec", dialtmo);
  5424.     else
  5425.       printf("0 (auto)");
  5426.     printf("        Redial number: %s\n",dialnum ? dialnum : "(none)");
  5427.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5428.     printf(" Dial confirmation: %s        Dial convert-directory: %s\n",
  5429.            dialcnf ? "on " : "off",
  5430.            dialcvt ? ((dialcvt == 1) ? "on" : "ask") : "off");
  5431.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5432.     printf(" Dial ignore-dialtone: %s", dialidt ? "on " : "off");
  5433.     printf("     Dial pacing: %d\n",dialpace);
  5434.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5435.     printf(
  5436. " Dial prefix:                  %s\n", dialnpr ? dialnpr : "(none)");
  5437.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5438.     printf(
  5439. " Dial suffix:                  %s\n", dialsfx ? dialsfx : "(none)");
  5440.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5441.     printf(
  5442. " Dial country-code:            %-12s", diallcc ? diallcc : "(none)");
  5443.     printf("Dial connect:  %s", dialcon ? ((dialcon == 1) ? "on" : "auto")
  5444.            : "off");
  5445.     if (dialcon != CAR_OFF)
  5446.       printf(" %s", dialcq ? "quiet" : "verbose");
  5447.     printf(
  5448. "\n Dial area-code:               %-12s", diallac ? diallac : "(none)");
  5449.     n++;
  5450.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5451.     printf("Dial restrict: ");
  5452.     if (dialrstr == 5) printf("international\n");
  5453.     else if (dialrstr == 4) printf("long-distance\n");
  5454.     else if (dialrstr == 2) printf("local\n");
  5455.     else if (dialrstr == 6) printf("none\n");
  5456.     else printf("?\n");
  5457.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5458.     printf(" Dial lc-area-codes:           ");
  5459.     if (nlocalac == 0)
  5460.       printf("(none)");
  5461.     else
  5462.       for (i = 0; i < nlocalac; i++)
  5463.         printf("%s ", diallcac[i]);
  5464.     printf(
  5465. "\n Dial lc-prefix:               %s\n", diallcp ? diallcp : "(none)");
  5466.     n++;
  5467.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5468.     printf(
  5469. " Dial lc-suffix:               %s\n", diallcs ? diallcs : "(none)");
  5470.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5471.     printf(
  5472. " Dial ld-prefix:               %s\n", dialldp ? dialldp : "(none)");
  5473.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5474.     printf(
  5475. " Dial ld-suffix:               %s\n", diallds ? diallds : "(none)");
  5476.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5477.     printf(
  5478. " Dial force-long-distance      %s\n", showoff(dialfld));
  5479.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5480.     printf(
  5481. " Dial intl-prefix:             %s\n", dialixp ? dialixp : "(none)");
  5482.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5483.     printf(
  5484. " Dial intl-suffix:             %s\n", dialixs ? dialixs : "(none)");
  5485.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5486.     printf(
  5487. " Dial toll-free-area-code:     ");
  5488.     if (ntollfree == 0)
  5489.       printf("(none)");
  5490.     else
  5491.       for (i = 0; i < ntollfree; i++)
  5492.         printf("%s ", dialtfc[i]);
  5493.     printf("\n");
  5494.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5495.  
  5496.     printf(
  5497. " Dial pulse-countries:         ");
  5498.     if (ndialpucc == 0)
  5499.       printf("(none)");
  5500.     else
  5501.       for (i = 0; i < ndialpucc; i++)
  5502.         printf("%s ", dialpucc[i]);
  5503.     printf("\n");
  5504.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5505.  
  5506.     printf(
  5507. " Dial tone-countries:          ");
  5508.     if (ndialtocc == 0)
  5509.       printf("(none)");
  5510.     else
  5511.       for (i = 0; i < ndialtocc; i++)
  5512.         printf("%s ", dialtocc[i]);
  5513.     printf("\n");
  5514.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5515.  
  5516.     printf(
  5517.     " Dial toll-free-prefix:        %s\n",
  5518.     dialtfp ? dialtfp :
  5519.     (dialldp ? dialldp : "(none)")
  5520.     );
  5521.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5522.     printf(" Dial pbx-exchange:            ");
  5523.     if (ndialpxx == 0)
  5524.       printf("(none)");
  5525.     else
  5526.       for (i = 0; i < ndialpxx; i++)
  5527.         printf("%s ", dialpxx[i]);
  5528.     printf("\n");
  5529.  
  5530.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5531.     printf(
  5532. " Dial pbx-inside-prefix:       %s\n", dialpxi ? dialpxi : "(none)");
  5533.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5534.     printf(
  5535. " Dial pbx-outside-prefix:      %s\n", dialpxo ? dialpxo : "(none)");
  5536.     if (++n > cmd_rows - 3) if (!askmore()) return(0); else n = 0;
  5537.     printf(
  5538. " Dial macro:                   %s\n", dialmac ? dialmac : "(none)");
  5539.     return(0);
  5540. }
  5541. #endif /* NODIAL */
  5542. #endif /* NOLOCAL */
  5543.  
  5544. /*  Show File Parameters */
  5545.  
  5546. static char *
  5547. pathval(x) int x; {
  5548.     switch (x) {
  5549.       case PATH_OFF:  return("off");
  5550.       case PATH_ABS:  return("absolute");
  5551.       case PATH_REL:  return("relative");
  5552.       case PATH_AUTO: return("auto");
  5553.       default: return("unknown");
  5554.     }
  5555. }
  5556.  
  5557. VOID
  5558. shofil() {
  5559.     char *s; int i = 0, n = 1;
  5560.     extern char * ifdnam[];
  5561. #ifdef UNIX
  5562.     extern int wildxpand;
  5563. #endif /* UNIX */
  5564.     extern char * snd_move, * snd_rename, * rcv_move, * rcv_rename;
  5565. #ifdef PATTERNS
  5566.     extern int patterns;
  5567. #endif /* PATTERNS */
  5568.     extern char * rfspec, * sfspec;
  5569. #ifdef UNIX
  5570.     extern int zobufsize, zofbuffer, zofblock;
  5571. #endif /* UNIX */
  5572. #ifdef CK_CTRLZ
  5573.     extern int eofmethod;
  5574. #endif /* CK_CTRLZ */
  5575.  
  5576.     printf("\n");
  5577.  
  5578. #ifdef VMS
  5579.     printf(" File record-Length:      %5d\n",frecl);
  5580.     n++;
  5581. #endif /* VMS */
  5582.  
  5583. #ifndef NOXFER
  5584.     printf(" Transfer mode:           %s\n",
  5585.            xfermode == XMODE_A ?
  5586.            "automatic" :
  5587.            "manual"
  5588.            );
  5589.     n++;
  5590. #ifdef PATTERNS
  5591.     printf(" File patterns:           %s", showooa(patterns));
  5592.     if (xfermode == XMODE_M && patterns)
  5593.       printf(" (but disabled by TRANSFER-MODE MANUAL)");
  5594.     else if (patterns)
  5595.       printf(" (SHOW PATTERNS for list)");
  5596.     printf("\n");
  5597.     n++;
  5598. #endif /* PATTERNS */
  5599.     if (filepeek)
  5600.       printf(" File scan:               on %d\n", nscanfile);
  5601.     else
  5602.       printf(" File scan:               off\n");
  5603.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5604.     if (xfermode == XMODE_A)
  5605.       printf(" Default file type:       %s\n",shoxm());
  5606.     else
  5607.       printf(" File type:               %s\n",shoxm());
  5608.     n++;
  5609.     if (fncnv == XYFN_L)
  5610.       s = "literal";
  5611.     else if (fncnv == XYFN_C)
  5612.       s = "converted";
  5613.     else
  5614.       s = "(unknown)";
  5615.     printf(" File names:              %s\n",s);
  5616.     n++;
  5617.     printf(" Send pathnames:          %s\n", pathval(fnspath));
  5618.     n++;
  5619.     printf(" Receive pathnames:       %s\n", pathval(fnrpath));
  5620.     n++;
  5621. #ifdef UNIXOROSK
  5622.     printf(" Match dot files:         %s\n", matchdot ? "yes" : "no");
  5623.     n++;
  5624. #ifdef UNIX
  5625.     printf(" Wildcard-expansion:      %s\n", wildxpand ? "shell" : "kermit");
  5626.     n++;
  5627. #endif /* UNIX */
  5628. #endif /* UNIXOROSK */
  5629.     printf(" File collision:          ");
  5630.     for (i = 0; i < ncolx; i++)
  5631.       if (colxtab[i].kwval == fncact) break;
  5632.     printf("%s\n", (i == ncolx) ? "unknown" : colxtab[i].kwd);
  5633.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5634.     printf(" File destination:        %s\n",
  5635.            (dest == DEST_D) ? "disk" :
  5636.            ((dest == DEST_S) ? "screen" :
  5637.             ((dest == DEST_N) ? "nowhere" :
  5638.             "printer"))
  5639.            );
  5640.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5641.     s = (keep >= 0 && keep <= 2) ? ifdnam[keep] : "keep";
  5642.     printf(" File incomplete:         %s\n",s);
  5643.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5644.     printf(" File bytesize:           %d\n",(fmask == 0177) ? 7 : 8);
  5645.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5646. #ifndef NOCSETS
  5647.     printf(" File character-set:      %s\n",fcsinfo[fcharset].keyword);
  5648.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5649.     printf(" File default 7-bit:      %s\n",fcsinfo[dcset7].keyword);
  5650.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5651.     printf(" File default 8-bit:      %s\n",fcsinfo[dcset8].keyword);
  5652.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5653. #ifdef UNICODE
  5654.     printf(" File UCS bom:            %s\n",showoff(ucsbom));
  5655.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5656.     printf(" File UCS byte-order:     %s-endian\n",
  5657.            ucsorder ? "little" : "big");
  5658.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5659.     printf(" Computer byteorder:      %s-endian\n",
  5660.            byteorder ? "little" : "big");
  5661.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5662. #endif /* UNICODE */
  5663. #endif /* NOCSETS */
  5664.  
  5665.     printf(" File end-of-line:        ");
  5666.     i = feol;
  5667.     switch (feol) {
  5668.       case XYFA_C: printf("%s\n","cr"); break;
  5669.       case XYFA_L: printf("%s\n","lf"); break;
  5670.       case XYFA_2: printf("%s\n","crlf"); break;
  5671.       default: printf("%d\n",i);
  5672.     }
  5673.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5674. #endif /* NOXFER */
  5675.  
  5676. #ifdef CK_CTRLZ
  5677.     printf(" File eof:                %s\n", eofmethod ? "ctrl-z" : "length");
  5678.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5679. #endif /* CK_CTRLZ */
  5680. #ifndef NOXFER
  5681. #ifdef CK_TMPDIR
  5682.     printf(" File download-directory: %s\n", dldir ? dldir : "(none)");
  5683.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5684. #ifdef COMMENT
  5685.     i = 256;
  5686.     s = line;
  5687.     zzstring("\\v(tmpdir)",&s,&i);
  5688.     printf(" Temporary directory:     %s\n", line);
  5689.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5690. #endif /* COMMENT */
  5691. #endif /* CK_TMPDIR */
  5692. #ifdef VMS
  5693.     {
  5694.         extern int vmssversions, vmsrversions;
  5695.         printf(" Send version-numbers:    %s\n",showoff(vmssversions));
  5696.         if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5697.         printf(" Receive version-numbers: %s\n",showoff(vmsrversions));
  5698.         if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5699.     }
  5700. #endif /* VMS */
  5701.     printf(" Send move-to:            %s\n",
  5702.            snd_move ? snd_move : "(none)");
  5703.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5704.     printf(" Send rename-to:          %s\n",
  5705.            snd_rename ? snd_rename : "(none)");
  5706.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5707.     printf(" Receive move-to:         %s\n",
  5708.            rcv_move ? rcv_move : "(none)");
  5709.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5710.     printf(" Receive rename-to:       %s\n",
  5711.            rcv_rename ? rcv_rename : "(none)");
  5712.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5713. #endif /* NOXFER */
  5714. #ifdef KERMRC
  5715.     printf(" Initialization file:     %s\n", noinit ? "(none)" :
  5716. #ifdef CK_SYSINI
  5717.            CK_SYSINI
  5718. #else
  5719.            kermrc
  5720. #endif /* CK_SYSINI */
  5721.            );
  5722. #endif /* KERMRC */
  5723.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5724.  
  5725.     if (k_info_dir) {
  5726.         printf(" Kermit doc files:        %s\n", k_info_dir);
  5727.         if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5728.     }
  5729.  
  5730. #ifdef CKROOT
  5731.     s = zgetroot();
  5732.     printf(" Root set:                %s\n", s ? s : "(none)");
  5733. #endif /* CKROOT */
  5734.  
  5735. #ifdef UNIX
  5736.     printf(" Disk output buffer:      %d (writes are %s, %s)\n",
  5737.            zobufsize,
  5738.            zofbuffer ? "buffered" : "unbuffered",
  5739.            zofblock ? "blocking" : "nonblocking"
  5740.            );
  5741.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5742. #ifdef DYNAMIC
  5743.     printf(" Stringspace:             %d\n", zsetfil(0,2));
  5744.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5745.     printf(" Listsize:                %d\n", zsetfil(0,4));
  5746.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5747. #endif /* DYNAMIC */
  5748. #endif /* UNIX */
  5749. #ifdef OS2ORUNIX
  5750.     printf(" Longest filename:        %d\n", maxnam);
  5751.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5752.     printf(" Longest pathname:        %d\n", maxpath);
  5753.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5754. #endif /* OS2ORUNIX */
  5755.  
  5756.     printf(" Last file sent:          %s\n", sfspec ? sfspec : "(none)");
  5757.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5758.     printf(" Last file received:      %s\n", rfspec ? rfspec : "(none)");
  5759.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5760.     printf("\n Also see:\n");
  5761.     n++;
  5762.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  5763.     printf(" SHOW PROTOCOL, SHOW XFER");
  5764. #ifdef CK_LABELED
  5765.     printf(", SHOW LABELED");
  5766. #endif /* CK_LABELED */
  5767. #ifdef PATTERNS
  5768.     printf(", SHOW PATTERNS");
  5769. #endif /* PATTERNS */
  5770. #ifdef STREAMING
  5771.     printf(", SHOW STREAMING");
  5772. #endif /* STREAMING */
  5773. #ifndef NOCSETS
  5774.     printf(", SHOW CHARACTER-SETS");
  5775. #endif /* NOCSETS */
  5776.     printf("\n\n");
  5777. }
  5778.  
  5779. #ifndef NOXFER
  5780. VOID
  5781. shoparp() {                             /* Protocol */
  5782.     extern int docrc, skipbup;
  5783.     char *s;
  5784.  
  5785. #ifdef CK_TIMERS
  5786.     extern int rttflg;
  5787. #endif /* CK_TIMERS */
  5788.  
  5789.     printf("Protocol: %s\n",ptab[protocol].p_name);
  5790.  
  5791.     if (protocol == PROTO_K) {
  5792.         printf("\nProtocol Parameters:   Send    Receive");
  5793.         if (timef)
  5794.           printf("\n Timeout (used=%2d):%7d*%8d ", timint, rtimo, pkttim);
  5795.         else
  5796.           printf("\n Timeout (used=%2d):%7d%9d ",  timint, rtimo, pkttim);
  5797. #ifdef XFRCAN
  5798.         printf("       Cancellation:    %s",showoff(xfrcan));
  5799.         if (xfrcan)
  5800.           printf(" %d %d", xfrchr, xfrnum);
  5801. #endif /* XFRCAN */
  5802.         printf("\n Padding:      %11d%9d", npad,   mypadn);
  5803.         if (bctr == 4)
  5804.           printf("        Block Check: blank-free-2\n");
  5805.         else
  5806.           printf("        Block Check: %6d\n",bctr);
  5807.         printf(  " Pad Character:%11d%9d", padch,  mypadc);
  5808.         printf("        Delay:       %6d\n",ckdelay);
  5809.         printf(  " Pause:        %11d%9d", pktpaus, pktpaus);
  5810.         printf("        Attributes:      %s\n",showoff(atcapr));
  5811.         printf(  " Packet Start: %11d%9d", mystch, stchr);
  5812.         printf("        Max Retries: %6d%s\n",
  5813.                maxtry,
  5814.                (maxtry == 0) ? " (unlimited)" : ""
  5815.                );
  5816.         printf(  " Packet End:   %11d%9d", seol,   eol);
  5817.         if (ebqflg)
  5818.           printf("        8th-Bit Prefix: '%c'",ebq);
  5819.         else
  5820.           printf("        8th-Bit Prefix: ('%c' but not used)",ebq);
  5821.         printf(  "\n Packet Length:%11d ", spmax);
  5822.         printf("%8d     ",  urpsiz);
  5823.         if (rptflg)
  5824.           printf("   Repeat Prefix:  '%c'",rptq);
  5825.         else
  5826.           printf("   Repeat Prefix:  ('%c' but not used)",rptq);
  5827.         printf(  "\n Maximum Length: %9d%9d", maxsps, maxrps);
  5828.         printf("        Window Size:%7d set, %d used\n",wslotr,wmax);
  5829.         printf(    " Buffer Size:  %11d%9d", bigsbsiz, bigrbsiz);
  5830.         printf("        Locking-Shift:    ");
  5831.         if (lscapu == 2) {
  5832.             printf("forced");
  5833.         } else {
  5834.             printf("%s", (lscapr ? "enabled" : "disabled"));
  5835.             if (lscapr) printf(",%s%s", (lscapu ? " " : " not "), "used");
  5836.         }
  5837.         printf("\n\n");
  5838.  
  5839.         if (!(s = ptab[protocol].h_b_init)) s = "";
  5840.         printf(" Auto-upload command (binary): ");
  5841.         if (*s) {
  5842.             shostrdef((CHAR *)s);
  5843.             printf("\n");
  5844.         } else {
  5845.             printf("(none)\n");
  5846.         }
  5847.         if (!(s = ptab[protocol].h_t_init)) s = "";
  5848.         printf(" Auto-upload command (text):   ");
  5849.         if (*s) {
  5850.             shostrdef((CHAR *)s);
  5851.             printf("\n");
  5852.         } else {
  5853.             printf("(none)\n");
  5854.         }
  5855.         if (!(s = ptab[protocol].h_x_init)) s = "";
  5856.         printf(" Auto-server command:          ");
  5857.         if (*s) {
  5858.             shostrdef((CHAR *)s);
  5859.             printf("\n");
  5860.         } else {
  5861.             printf("(none)\n");
  5862.         }
  5863.         tmpbuf[0] = NUL;
  5864. #ifdef CK_TIMERS
  5865.         if (rttflg) {
  5866.             extern int mintime, maxtime;
  5867.             sprintf(tmpbuf," Packet timeouts: dynamic %d:%d", /* SAFE */
  5868.                     mintime,
  5869.                     maxtime);
  5870.         } else {
  5871.             sprintf(tmpbuf," Packet timeouts: fixed"); /* SAFE */
  5872.         }
  5873. #endif /* CK_TIMERS */
  5874.         if (tmpbuf[0])
  5875.           printf("%-31s",tmpbuf);
  5876.         printf("Send backup: %s\n",showoff(!skipbup));
  5877.  
  5878.         printf(" Transfer mode:   %s", xfermode == XMODE_A ?
  5879.                "automatic   " :
  5880.                "manual      "
  5881.                );
  5882.         printf(" Transfer slow-start: %s, crc: %s\n",
  5883.                showoff(slostart),
  5884.                showoff(docrc)
  5885.                );
  5886. #ifdef PIPESEND
  5887.         {
  5888.             extern int usepipes;
  5889.             printf(" Transfer pipes:  %s         ",usepipes ? "on " : "off");
  5890.         }
  5891. #endif /* PIPESEND */
  5892. #ifndef NOCSETS
  5893.         printf(" Transfer character-set: ");
  5894.         if (tcharset == TC_TRANSP)
  5895.           printf("transparent\n");
  5896.         else
  5897.           printf("%s\n", tcsinfo[tcharset].keyword );
  5898. #endif /* NOCSETS */
  5899. #ifdef PIPESEND
  5900.         {
  5901.             extern char * sndfilter, * rcvfilter;
  5902.             printf(" Send filter:     %s\n", sndfilter ? sndfilter : "(none)");
  5903.             printf(" Receive filter:  %s\n", rcvfilter ? rcvfilter : "(none)");
  5904.         }
  5905. #endif /* PIPESEND */
  5906.         printf("\nAlso see:\n");
  5907.         printf(" SHOW FILE, SHOW XFER");
  5908.  
  5909. #ifdef CK_LABELED
  5910.         printf(", SHOW LABELED");
  5911. #endif /* CK_LABELED */
  5912. #ifdef PATTERNS
  5913.         printf(", SHOW PATTERNS");
  5914. #endif /* PATTERNS */
  5915. #ifdef STREAMING
  5916.         printf(", SHOW STREAMING");
  5917. #endif /* STREAMING */
  5918. #ifndef NOCSETS
  5919.         printf(", SHOW CHARACTER-SETS");
  5920. #endif /* NOCSETS */
  5921.     }
  5922.  
  5923. #ifdef CK_XYZ
  5924. #ifdef XYZ_INTERNAL
  5925.     if (protocol != PROTO_K) {
  5926.         int i;
  5927.         int x;
  5928.         printf(" File type: %s\n", binary ? "binary" : "text");
  5929.         if (protocol == PROTO_Z) {              /* Zmodem */
  5930.             printf(" Window size:   ");
  5931.             if (ptab[protocol].winsize < 1)
  5932.               printf("none\n");
  5933.             else
  5934.               printf("%d\n",wslotr);
  5935. #ifdef COMMENT
  5936.             printf(" Packet (frame) length: ");
  5937.             if (ptab[protocol].spktlen < 0)
  5938.               printf("none\n");
  5939.             else
  5940.               printf("%d\n",spmax);
  5941. #endif /* COMMENT */
  5942.         } else {
  5943.             if (ptab[protocol].spktlen >= 1000)
  5944.               printf(" 1K packets\n");
  5945.             else
  5946.               printf(" 128-byte packets\n");
  5947.         }
  5948.         printf(" Pathname stripping when sending:   %s\n",
  5949.                showoff(ptab[protocol].fnsp)
  5950.                );
  5951.         printf(" Pathname stripping when receiving: %s\n",
  5952.                showoff(ptab[protocol].fnrp)
  5953.                );
  5954.         printf(" Filename collision action:         ");
  5955.         for (i = 0; i < ncolx; i++)
  5956.           if (colxtab[i].kwval == fncact) break;
  5957.         printf("%-12s", (i == ncolx) ? "unknown" : colxtab[i].kwd);
  5958.  
  5959.         printf("\n Escape control characters:          ");
  5960.         x = ptab[protocol].prefix;
  5961.         if (x == PX_ALL)
  5962.           printf("all\n");
  5963.         else if (x == PX_CAU || x==PX_WIL)
  5964.           printf("minimal\n");
  5965.         else
  5966.           printf("none\n");
  5967.         if (!(s = ptab[protocol].h_b_init))
  5968.           s = "";
  5969.         printf(" Autoreceive command (binary): %s\n", *s ? s : "(none)");
  5970.         if (!(s = ptab[protocol].h_t_init))
  5971.           s = "";
  5972.         printf(" Autoreceive command (text):   %s\n", *s ? s : "(none)");
  5973.     }
  5974. #else
  5975.     if (protocol != PROTO_K) {
  5976.         printf("\nExecuted by external commands:\n\n");
  5977.         s = ptab[protocol].p_b_scmd;
  5978.         if (!s) s = "";
  5979.         printf(" SEND command (binary):        %s\n", *s ? s : "(none)");
  5980.         s = ptab[protocol].p_t_scmd;
  5981.         if (!s) s = "";
  5982.         printf(" SEND command (text):          %s\n", *s ? s : "(none)");
  5983.         s = ptab[protocol].p_b_rcmd;
  5984.         if (!s) s = "";
  5985.         printf(" RECEIVE command (binary):     %s\n", *s ? s : "(none)");
  5986.         s = ptab[protocol].p_t_rcmd;
  5987.         if (!s) s = "";
  5988.         printf(" RECEIVE command (text):       %s\n", *s ? s : "(none)");
  5989.         s = ptab[protocol].h_b_init;
  5990.         if (!s) s = "";
  5991.         printf(" Autoreceive command (binary): %s\n", *s ? s : "(none)");
  5992.         s = ptab[protocol].h_t_init;
  5993.         if (!s) s = "";
  5994.         printf(" Autoreceive command (text):   %s\n", *s ? s : "(none)");
  5995.     }
  5996. #endif /* XYZ_INTERNAL */
  5997. #endif /* CK_XYZ */
  5998. }
  5999. #endif /* NOXFER */
  6000.  
  6001. #ifndef NOCSETS
  6002. /* Character-set items */
  6003.  
  6004. extern int s_cset, r_cset, axcset[], afcset[];
  6005. extern struct keytab xfrmtab[];
  6006.  
  6007. VOID
  6008. shoparl() {
  6009. #ifdef COMMENT
  6010.     int i;
  6011. /* Misleading... */
  6012.     printf("\nAvailable Languages:\n");
  6013.     for (i = 0; i < MAXLANG; i++) {
  6014.         printf(" %s\n",langs[i].description);
  6015.     }
  6016. #else
  6017.     printf("\nLanguage-specific translation rules: %s\n",
  6018.            language == L_USASCII ? "none" : langs[language].description);
  6019.     shocharset();
  6020.     printf("\n\n");
  6021. #endif /* COMMENT */
  6022. }
  6023.  
  6024. VOID
  6025. shocharset() {
  6026.     int x;
  6027. #ifdef COMMENT
  6028.     char * s = "Unknown";
  6029.     extern int xlatype;
  6030. #endif /* COMMENT */
  6031.  
  6032. #ifndef NOXFER
  6033.     extern int xfrxla;
  6034. #endif /* NOXFER */
  6035.  
  6036.     debug(F101,"SHOW FILE CHAR","",fcharset);
  6037.     printf("\n");
  6038. #ifndef NOXFER
  6039.     printf(" Transfer Translation: %s\n", showoff(xfrxla));
  6040.     if (!xfrxla) {
  6041.         printf(
  6042.       " Because transfer translation is off, the following are ignored:\n\n");
  6043.     }
  6044. #endif /* NOXFER */
  6045.     printf(" File Character-Set: %s (%s), ",
  6046.            fcsinfo[fcharset].keyword,
  6047.            fcsinfo[fcharset].name
  6048.            );
  6049.     if ((x = fcsinfo[fcharset].size) == 128)
  6050.       printf("7-bit");
  6051.     else if (x == 256)
  6052.       printf("8-bit");
  6053.     else
  6054.       printf("multibyte");
  6055.     printf("\n");
  6056.     printf(" File Scan: %s\n",showoff(filepeek));
  6057.     printf("   Default 7bit-Character-Set: %s\n",fcsinfo[dcset7].keyword);
  6058.     printf("   Default 8bit-Character-Set: %s\n",fcsinfo[dcset8].keyword);
  6059.     printf(" Transfer Character-Set");
  6060. #ifdef COMMENT
  6061.     if (tslevel == TS_L2)
  6062.       printf(": (international)");
  6063.     else
  6064. #endif /* COMMENT */
  6065.     if (tcharset == TC_TRANSP)
  6066.       printf(": Transparent");
  6067.     else
  6068.       printf(": %s (%s)",tcsinfo[tcharset].keyword, tcsinfo[tcharset].name);
  6069.     printf("\n");
  6070. #ifdef COMMENT
  6071.     switch (xlatype) {
  6072.       case XLA_NONE: s = "None"; break;
  6073.       case XLA_BYTE: s = "Byte"; break;
  6074.       case XLA_JAPAN: s = "Japanese"; break;
  6075.       case XLA_UNICODE: s = "Unicode"; break;
  6076.     }
  6077.     printf("\n Translation type: %s\n",s);
  6078. #endif /* COMMENT */
  6079.     printf(" SEND character-set-selection: %s\n",xfrmtab[s_cset].kwd);
  6080.     printf(" RECEIVE character-set-selection: %s\n",xfrmtab[r_cset].kwd);
  6081.     if (s_cset == XMODE_A || r_cset == XMODE_A)
  6082.       printf(
  6083.       " (Use SHOW ASSOCIATIONS to list automatic character-set selections.)\n"
  6084.              );
  6085. }
  6086.  
  6087. VOID
  6088. showassoc() {
  6089.     int i, k, n = 4;
  6090.     char * s;
  6091.     printf("\nFor incoming files:\n\n");
  6092.     printf("Transfer Character-Set   File Character-Set\n");
  6093.     for (i = 1; i <= MAXTCSETS; i++) {
  6094.         k = axcset[i];
  6095.         if (k < 0 || k > MAXFCSETS)
  6096.           s = "(none)";
  6097.         else
  6098.           s = fcsinfo[k].keyword;
  6099.         if (!s) s = "";
  6100.         if (!*s) s = "(none)";
  6101.         printf(" %-25s%s\n",tcsinfo[i].keyword,s);
  6102.         if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  6103.     }
  6104.     printf("\nFor outbound files:\n\n");
  6105.     n += 2;
  6106.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  6107.     printf("File Character-Set       Transfer Character-Set\n");
  6108.     if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  6109.     for (i = 0; i <= MAXFCSETS; i++) {
  6110.         k = afcset[i];
  6111.         if (k < 0 || k > MAXTCSETS)
  6112.           s = "(none)";
  6113.         else
  6114.           s = tcsinfo[k].keyword;
  6115.         if (!s) s = "";
  6116.         if (!*s) s = "(none)";
  6117.         printf(" %-25s%s\n",fcsinfo[i].keyword,s);
  6118.         if (++n > cmd_rows - 3) if (!askmore()) return; else n = 0;
  6119.     }
  6120. }
  6121. #endif /* NOCSETS */
  6122.  
  6123. VOID
  6124. shopar() {
  6125.     printf("Show what?  (Type \"show ?\" for a list of possiblities.)\n");
  6126. }
  6127. #endif /* NOSHOW */
  6128.  
  6129. #ifndef NOXFER
  6130. /*  D O S T A T  --  Display file transfer statistics.  */
  6131.  
  6132. int
  6133. dostat(brief) int brief; {
  6134.     extern long filrej, peakcps;
  6135.     extern int lastspmax, streamed, cleared, streamok;
  6136.     extern char whoareu[];
  6137.     int n = 0, ftp = 0;
  6138.     extern int docrc, interrupted, fatalio;
  6139.  
  6140.     ftp = lastxfer & W_FTP;
  6141.  
  6142. #ifdef CK_TTGWSIZ
  6143. #ifdef OS2
  6144.     if (tt_cols[VTERM] < 0 || tt_rows[VTERM] < 0)
  6145.       ttgwsiz();
  6146. #else /* OS2 */
  6147.     if (ttgwsiz() > 0) {
  6148.         if (tt_rows > 0 && tt_cols > 0) {
  6149.             cmd_rows = tt_rows;
  6150.             cmd_cols = tt_cols;
  6151.         }
  6152.     }
  6153. #endif /* OS2 */
  6154. #endif /* CK_TTGWSIZ */
  6155.  
  6156.     debug(F101,"dostat xferstat","",xferstat);
  6157.     if (xferstat < 0) {
  6158.         printf(" No file transfers yet.\n");
  6159.         return(1);
  6160.     }
  6161.     n = 0;
  6162.     if (brief) { printf("\n"); n++; };
  6163.     printf(" protocol               : %s\n",
  6164.            ftp ? "ftp" : ptab[protocol].p_name);
  6165.     n++;
  6166.     printf(" status                 : ");
  6167.     if (xferstat) printf("SUCCESS\n");
  6168.     else if (interrupted) printf("FAILURE (interrupted)\n");
  6169.     else if (fatalio) printf("FAILURE (i/o error)\n");
  6170.     else printf("FAILURE\n");
  6171. #ifndef XYZ_INTERNAL
  6172.     if (!ftp && protocol != PROTO_K) {
  6173.         printf("\n external protocol statistics not available\n");
  6174.         return(1);
  6175.     }
  6176. #endif /* XYZ_INTERNAL */
  6177.     n++;
  6178.     if (!ftp) {
  6179.         if (!xferstat > 0) {
  6180.             if (docrc)
  6181.               printf(" crc-16 of file(s)      : %ld\n", crc16);
  6182.             else
  6183.               printf(" crc-16 of file(s)      : (disabled)\n");
  6184.             n++;
  6185.         }
  6186.         if (!xferstat && *epktmsg) {
  6187.             printf(" reason                 : %s\n", epktmsg);
  6188.             n++;
  6189.         }
  6190.     }
  6191.     if (!brief) {
  6192. #ifdef NEWFTP
  6193.         if (ftp) {
  6194.             extern char ftp_srvtyp[];
  6195.             printf(" remote system type     : %s\n",ftp_srvtyp);
  6196.         } else
  6197. #endif /* NEWFTP */
  6198.           if (whoareu[0]) {
  6199.             printf(" remote system type     : %s\n",
  6200.                    getsysid((char *)whoareu));
  6201.             n++;
  6202.         }
  6203.         printf(" files transferred      : %ld\n",filcnt - filrej);
  6204.         if (!ftp)
  6205.           printf(" files not transferred  : %ld\n",filrej);
  6206.         printf(" characters last file   : %ld\n",ffc);
  6207.         printf(" total file characters  : %ld\n",tfc);
  6208.         n += ftp ? 3 : 4;
  6209.         if (!ftp) {
  6210.             printf(" communication line in  : %ld\n",tlci);
  6211.             printf(" communication line out : %ld\n",tlco);
  6212.             printf(" packets sent           : %d\n", spackets);
  6213.             printf(" packets received       : %d\n", rpackets);
  6214.             n += 4;
  6215.         }
  6216.     }
  6217.     if (ftp) goto dotimes;
  6218.  
  6219.     printf(" damaged packets rec'd  : %d\n", crunched);
  6220.     printf(" timeouts               : %d\n", timeouts);
  6221.     printf(" retransmissions        : %d\n", retrans);
  6222.     n += 3;
  6223.  
  6224.     if (!brief) {
  6225.         if (filcnt > 0) {
  6226.             printf(" parity                 : %s",parnam((char)parity));
  6227.             n++;
  6228.             if (autopar) { printf(" (detected automatically)"); n++; }
  6229.             printf(
  6230.                  "\n control characters     : %ld prefixed, %ld unprefixed\n",
  6231.                    ccp, ccu);
  6232.             n++;
  6233.             printf(" 8th bit prefixing      : ");
  6234.             n++;
  6235.             if (ebqflg) printf("yes [%c]\n",ebq); else printf("no\n");
  6236.             n++;
  6237.             printf(" locking shifts         : %s\n", lscapu ? "yes" : "no");
  6238.             n++;
  6239.         }
  6240.     }
  6241.     if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6242.     if (streamed > 0)
  6243.       printf(" window slots used      : (streaming)\n");
  6244.     else
  6245.       printf(" window slots used      : %d of %d\n", wmax, wslotr);
  6246.     if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6247.     printf(" reliable:              : %s%s\n",
  6248.            streamok ? "" : "not ", "negotiated");
  6249.     if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6250.     printf(" clearchannel:          : %s%s\n",
  6251.            cleared  ? "" : "not ", "negotiated");
  6252.     if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6253.  
  6254.     if (!brief) {
  6255.         printf(" packet length          : %d (send), %d (receive)\n",
  6256.                lastspmax, urpsiz);
  6257.         if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6258.         printf(" compression            : ");
  6259.         if (rptflg)
  6260.           printf("yes [%c] (%ld)\n",(char) rptq,rptn);
  6261.         else
  6262.           printf("no\n");
  6263.         if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6264.         if (bctu == 4)
  6265.           printf(" block check type used  : blank-free-2\n");
  6266.         else
  6267.           printf(" block check type used  : %d\n",bctu);
  6268.         if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6269.     }
  6270.  
  6271.   dotimes:
  6272.  
  6273. #ifdef GFTIMER
  6274. #ifdef COMMENT
  6275.     printf(" elapsed time           : %0.3f sec, %s\n", fptsecs,hhmmss(tsecs));
  6276. #endif /* COMMENT */
  6277.     printf(" elapsed time           : %s (%0.3f sec)\n",
  6278.            hhmmss((long)(fptsecs + 0.5)),fptsecs);
  6279. #else
  6280. #ifdef COMMENT
  6281.     printf(" elapsed time           : %s (%d sec)\n",hhmmss(tsecs),tsecs);
  6282. #endif /* COMMENT */
  6283.     printf(" elapsed time           : %d sec, %s\n",tsecs,hhmmss(tsecs));
  6284. #endif /* GFTIMER */
  6285.     if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6286.     if (!ftp && local && !network && !brief) {
  6287.         if (speed <= 0L) speed = ttgspd();
  6288.         if (speed > 0L) {
  6289.             if (speed == 8880)
  6290.               printf(" transmission rate      : 75/1200 bps\n");
  6291.             else
  6292.               printf(" transmission rate      : %ld bps\n",speed);
  6293.             if (++n > cmd_rows - 3) { if (!askmore()) return(1); else n = 0; }
  6294.         }
  6295.     }
  6296.     if (!ftp && local && !network &&    /* Only makes sense for */
  6297.         mdmtyp == 0 &&                  /* direct serial connections */
  6298.         speed > 99L &&                  /* when we really know the speed */
  6299.         speed != 8880L
  6300.         ) {
  6301.         int eff;
  6302.         eff = (((tfcps * 100L) / (speed / 100L)) + 5L) / 10L;
  6303.         printf(" effective data rate    : %ld cps (%d%%)\n",tfcps,eff);
  6304.     } else
  6305.       printf(" effective data rate    : %ld cps\n", tfcps);
  6306.     if (!ftp && peakcps > 0L && peakcps > tfcps)
  6307.       printf(" peak data rate         : %ld cps\n", peakcps);
  6308.     if (brief)
  6309.       printf("\nUse STATISTICS /VERBOSE for greater detail.\n\n");
  6310.     return(1);
  6311. }
  6312. #endif /* NOXFER */
  6313.  
  6314. #ifndef NOSPL
  6315.  
  6316. /* The INPUT command */
  6317.  
  6318. /*
  6319.   NOTE: An INPUT timeout of 0 means to perform a nonblocking read of the
  6320.   material that has already arrived and is waiting to be read, and perform
  6321.   matches against it, without doing any further reads.  It should succeed
  6322.   or fail instantaneously.
  6323. */
  6324.  
  6325. /* Output buffering for "doinput" */
  6326.  
  6327. #ifdef pdp11
  6328. #define MAXBURST 16             /* Maximum size of input burst */
  6329. #else
  6330. #define MAXBURST 1024
  6331. #endif /* pdp11 */
  6332. #ifdef OSK
  6333. static CHAR *conbuf;            /* Buffer to hold output for console */
  6334. #else
  6335. static CHAR conbuf[MAXBURST];   /* Buffer to hold output for console */
  6336. #endif /* OSK */
  6337. static int concnt = 0;          /* Number of characters buffered */
  6338. #ifdef OSK
  6339. static CHAR *sesbuf;            /* Buffer to hold output for session log */
  6340. #else
  6341. static CHAR sesbuf[MAXBURST];   /* Buffer to hold output for session log */
  6342. #endif /* OSK */
  6343. static int sescnt = 0;          /* Number of characters buffered */
  6344.  
  6345. extern int debses;                      /* TERMINAL DEBUG ON/OFF */
  6346.  
  6347. static VOID                             /* Flush INPUT echoing */
  6348. myflsh() {                              /* and session log output. */
  6349.     if (concnt > 0) {
  6350.         if (debses) {                   /* Terminal debugging? */
  6351.             int i;
  6352.             for (i = 0; i < concnt; i++)
  6353.               conol(dbchr(conbuf[i]));
  6354.         } else
  6355.           conxo(concnt, (char *) conbuf);
  6356.         concnt = 0;
  6357.     }
  6358.     if (sescnt > 0) {
  6359.         logstr((char *) sesbuf, sescnt);
  6360.         sescnt = 0;
  6361.     }
  6362. }
  6363.  
  6364. /* Execute the INPUT and MINPUT commands */
  6365.  
  6366. int instatus = -1;
  6367. long inetime = -1L;
  6368. int inwait = 0;
  6369.  
  6370. /* For returning the input sequence that matched */
  6371.  
  6372. #ifdef BIGBUFOK
  6373. #define MATCHBUFSIZ 8191
  6374. #else
  6375. #define MATCHBUFSIZ 1023
  6376. #endif /* BIGBUFOK */
  6377. static char * matchbuf = NULL;
  6378. static int matchindex = 0;
  6379. /*
  6380.   timo = How long to wait:
  6381.          < 0 = Wait forever
  6382.            0 = Don't wait
  6383.          > 0 = Wait this many seconds
  6384.   ms   = Array of strings to wait for.
  6385.   mp   = Array of flags.
  6386.          If mp[i] == 0, ms[i] is literal, else it's a pattern.
  6387. */
  6388. int
  6389. doinput(timo,ms,mp) int timo; char *ms[]; int mp[]; {
  6390.     extern int inintr;
  6391. #ifdef CK_AUTODL
  6392.     extern int inautodl;
  6393. #endif /* CK_AUTODL */
  6394.     int x, y, i, t, rt, icn, anychar, mi[MINPMAX];
  6395. #ifdef GFTIMER
  6396.     CKFLOAT fpt = 0.0;
  6397. #endif /* GFTIMER */
  6398.     int lastchar = 0;
  6399.     int waiting = 0;
  6400.     int imask = 0;
  6401.     char ch, *xp, *s;
  6402.     CHAR c;
  6403. #ifndef NOLOCAL
  6404. #ifdef OS2
  6405.     extern int term_io;
  6406.     int term_io_save;
  6407. #endif /* OS2 */
  6408. #endif /* NOLOCAL */
  6409. #ifdef TNCODE
  6410.     static int cr = 0;
  6411. #endif /* TNCODE */
  6412.     int is_tn = 0;
  6413.     int wrapped = 0;
  6414.  
  6415. #define CK_BURST
  6416. /*
  6417.   This enables the INPUT speedup code, which depends on ttchk() returning
  6418.   accurate information.  If INPUT fails with this code enabled, change the
  6419.   above "#define" to "#undef".
  6420. */
  6421. #ifdef CK_BURST
  6422.     int burst = 0;                      /* Chars remaining in input burst */
  6423. #endif /* CK_BURST */
  6424.  
  6425.     imask = cmask;
  6426.     if (parity) imask = 0x7f;
  6427.     inwait = timo;                      /* For \v(inwait) */
  6428.     makestr(&inpmatch,NULL);
  6429.  
  6430.     if (!matchbuf) {
  6431.         matchbuf = malloc(MATCHBUFSIZ+1);
  6432.         matchbuf[0] = NUL;
  6433.     }
  6434.     matchindex = 0;
  6435.  
  6436.     is_tn =
  6437. #ifdef TNCODE
  6438.         (local && network && IS_TELNET()) || (!local && sstelnet)
  6439. #else
  6440.          0
  6441. #endif /* TNCODE */
  6442.           ;
  6443.  
  6444.     instatus = INP_IE;                  /* 3 = internal error */
  6445.     kbchar = 0;
  6446.  
  6447. #ifdef OSK
  6448.     if (conbuf == NULL) {
  6449.         if ((conbuf = (CHAR *)malloc(MAXBURST*2)) == NULL) {
  6450.             return(0);
  6451.         }
  6452.         sesbuf = conbuf + MAXBURST;
  6453.     }
  6454. #endif /* OSK */
  6455.  
  6456. #ifndef NOLOCAL
  6457.     if (local) {                        /* In local mode... */
  6458.         if ((waiting = ttchk()) < 0) {  /* check that connection is open */
  6459.         if (!quiet) {
  6460.         if ((!network 
  6461. #ifdef TN_COMPORT
  6462.               || istncomport()
  6463. #endif /* TN_COMPORT */
  6464.               ) && carrier != CAR_OFF)
  6465.             printf("?Carrier detect failure on %s.\n", ttname);
  6466.         else
  6467.             printf("?Connection %s %s is not open.\n",
  6468.                network ? "to" : "on",
  6469.                ttname
  6470.                );
  6471.         }
  6472.             instatus = INP_IO;
  6473.             return(0);
  6474.         }
  6475.         debug(F101,"doinput waiting","",waiting);
  6476.         y = ttvt(speed,flow);           /* Put line in "ttvt" mode */
  6477.         if (y < 0) {
  6478.             printf("?INPUT initialization error\n");
  6479.             instatus = INP_IO;
  6480.             return(0);                  /* Watch out for failure. */
  6481.         }
  6482.     }
  6483. #endif /* NOLOCAL */
  6484.  
  6485.     debug(F111,"doinput ms[0]",ms[0],waiting);
  6486.  
  6487.     if (!ms[0]) {                       /* If we were passed a NULL pointer */
  6488.         anychar = 1;                    /*  ... */
  6489.     } else {
  6490.         y = (int)strlen(ms[0]);         /* Or if search string is empty */
  6491.         anychar = (y < 1);              /* any input character will do. */
  6492.     }
  6493.     if (!anychar && waiting == 0 && timo == 0)
  6494.       return(0);
  6495.  
  6496. #ifndef NODEBUG
  6497.     if (deblog) {
  6498.         char xbuf[24];
  6499.         debug(F101,"doinput anychar","",anychar);
  6500.         debug(F101,"doinput timo","",timo);
  6501.         debug(F101,"doinput echo","",inecho);
  6502.         debug(F101,"doinput burst","",burst);
  6503.         y = -1;
  6504.         while (ms[++y]) {
  6505.             sprintf(xbuf,"doinput string %2d",y); /* SAFE (24) */
  6506.             debug(F111,xbuf,ms[y],mp[y]);
  6507.         }
  6508.     }
  6509. #endif /* NODEBUG */
  6510.  
  6511. #ifdef IKS_OPTION
  6512.     if (is_tn) {
  6513.         /* If the remote side is in a state of IKS START-SERVER    */
  6514.         /* we request that the state be changed.  We will detect   */
  6515.         /* a failure to adhere to the request when we call ttinc() */
  6516.         if (TELOPT_U(TELOPT_KERMIT) &&
  6517.             TELOPT_SB(TELOPT_KERMIT).kermit.u_start)
  6518.           iks_wait(KERMIT_REQ_STOP,0);  /* Send Request-Stop */
  6519. #ifdef CK_AUTODL
  6520.         /* If we are processing packets during INPUT and we have not */
  6521.         /* sent a START message, do so now.                          */
  6522.         if (inautodl && TELOPT_ME(TELOPT_KERMIT) &&
  6523.             !TELOPT_SB(TELOPT_KERMIT).kermit.me_start) {
  6524.             tn_siks(KERMIT_START);      /* Send Kermit-Server Start */
  6525.         }
  6526. #endif /* CK_AUTODL */
  6527.     }
  6528. #endif /* IKS_OPTION */
  6529.     x = 0;                              /* Return code, assume failure */
  6530.     instatus = INP_TO;                  /* Status, assume timeout */
  6531.  
  6532.     for (y = 0; y < MINPMAX; y++)
  6533.       mi[y] = 0;                        /* String pattern match position */
  6534.  
  6535.     if (!inpcas[cmdlvl]) {              /* INPUT CASE = IGNORE?  */
  6536.         y = -1;
  6537.  
  6538.         while ((xp = ms[++y])) {
  6539.             while (*xp) {               /* Convert to lowercase */
  6540.                 if (isupper(*xp)) *xp = (char) tolower(*xp);
  6541.                 xp++;
  6542.             }
  6543.         }
  6544.     }
  6545.     rtimer();                           /* Reset timer. */
  6546. #ifdef GFTIMER
  6547.     rftimer();                          /* Floating-point timer too. */
  6548. #endif /* GFTIMER */
  6549.     inetime = -1L;                      /* Initialize elapsed time. */
  6550.     t = 0;                              /* Time now is 0. */
  6551.     m_found = 0;                        /* Default to timed-out */
  6552.     incount = 0;                        /* Character counter */
  6553.     rt = (timo == 0) ? 0 : 1;           /* Character-read timeout interval */
  6554.  
  6555. #ifndef NOLOCAL
  6556. #ifdef OS2
  6557.     term_io_save = term_io;             /* Disable I/O by emulator */
  6558.     term_io = 0;
  6559. #endif /* OS2 */
  6560. #endif /* NOLOCAL */
  6561.  
  6562.     while (1) {                         /* Character-getting loop */
  6563. #ifdef CK_APC
  6564.         /* Check to see if there is an Autodown or other APC command */
  6565.         if (apcactive == APC_LOCAL ||
  6566.             (apcactive == APC_REMOTE && apcstatus != APC_OFF)) {
  6567.             if (mlook(mactab,"_apc_commands",nmac) == -1) {
  6568.                 debug(F110,"doinput about to execute APC",apcbuf,0);
  6569.                 domac("_apc_commands",apcbuf,cmdstk[cmdlvl].ccflgs|CF_APC);
  6570.                 delmac("_apc_commands",1);
  6571.                 apcactive = APC_INACTIVE;
  6572. #ifdef DEBUG
  6573.             } else {
  6574.                 debug(F100,"doinput APC in progress","",0);
  6575. #endif /* DEBUG */
  6576.             }
  6577.         }
  6578. #endif /* CK_APC */
  6579.  
  6580.         if (timo == 0 && waiting < 1) { /* Special exit criterion */
  6581.             instatus = INP_TO;          /* for timeout == 0 */
  6582.             break;
  6583.         }
  6584.         if (local) {                    /* One case for local */
  6585.             y = ttinc(rt);              /* Get character from comm device */
  6586.             debug(F101,"doinput ttinc(rt) returns","",y);
  6587.             if (y < -1) {               /* Connection failed. */
  6588.                 instatus = INP_IO;      /* Status = i/o error */
  6589. #ifndef NOLOCAL
  6590. #ifdef OS2
  6591.                 term_io = term_io_save;
  6592. #endif /* OS2 */
  6593. #endif /* NOLOCAL */
  6594.                 switch (y) {
  6595.                   case -2:              /* Connection lost */
  6596.                     if (local && !network && carrier != CAR_OFF) {
  6597.                         dologend();
  6598.                         printf("Connection closed.\n");
  6599.                         ttclos(1);
  6600.                     }
  6601.                     break;
  6602.                   case -3:
  6603.                     dologend();
  6604.                     printf("Session Limit exceeded - closing connection.\n");
  6605.                     ttclos(1);
  6606.                   default:
  6607.                     break;
  6608.                 }
  6609.                 debug(F111,"doinput Connection failed","returning 0",y);
  6610.                 return(0);
  6611.             }
  6612.             if (inintr) {
  6613.                 debug(F111,"doinput","inintr",inintr);
  6614.                 if ((icn = conchk()) > 0) { /* Interrupted from keyboard? */
  6615.                     debug(F101,"input interrupted from keyboard","",icn);
  6616.                     kbchar = coninc(0);
  6617.                     if (kbchar >= 0) {
  6618.                         while (--icn > 0) {
  6619.                             debug(F110,"doinput","absorbing",0);
  6620.                             coninc(0);      /* Yes, absorb what was typed. */
  6621.                         }
  6622.                         instatus = INP_UI;  /* Fail and remember why. */
  6623.                         break;
  6624.                     }
  6625.                 }
  6626.             }
  6627.         } else {                        /* Another for remote */
  6628.             y = coninc(rt);
  6629.             debug(F101,"doinput coninc(rt) returns","",y);
  6630.         }
  6631.         if (y > -1) {                   /* A character arrived */
  6632.             debug(F111,"doinput","a character arrived",y);
  6633.             if (timo == 0)
  6634.               waiting--;
  6635. #ifndef OS2
  6636. #define TN_NOLO
  6637. #endif /* OS2 */
  6638. #ifdef NOLOCAL
  6639. #define TN_NOLO
  6640. #endif /* NOLOCAL */
  6641.  
  6642. #ifdef TN_NOLO
  6643.             debug(F100,"doinput TN_NOLO","",0);
  6644. #ifdef TNCODE
  6645.             /* Check for telnet protocol negotiation */
  6646.             if (is_tn) {
  6647.                 switch (y & 0xff) {
  6648.                   case IAC:
  6649.                     cr = 0;
  6650.                     myflsh();   /* Break from input burst for tn_doop() */
  6651. #ifdef CK_BURST
  6652.                     burst = 0;
  6653. #endif /* CK_BURST */
  6654.                     waiting -= 2;       /* (not necessarily...) */
  6655.                     switch (tn_doop((CHAR)(y & 0xff),duplex,ttinc)) {
  6656.                       case 2: duplex = 0; continue;
  6657.                       case 1: duplex = 1; continue;
  6658. #ifdef IKS_OPTION
  6659.                       case 4:
  6660.                         if (TELOPT_SB(TELOPT_KERMIT).kermit.u_start &&
  6661.                              !tcp_incoming) {
  6662.                             instatus = INP_IKS;
  6663.                             printf(
  6664.  " Internet Kermit Service in SERVER mode.\n Please use REMOTE commands.\n"
  6665.                                    );
  6666.                             break;
  6667.                         }
  6668.                         continue;
  6669. #endif /* IKS_OPTION */
  6670.                       case 6:           /* TELNET DO LOGOUT received */
  6671.                       default: continue;
  6672.                     }
  6673.                   case CR:
  6674.                     cr = 1;
  6675.                     break;
  6676.                   case NUL:
  6677.                     if (!TELOPT_U(TELOPT_BINARY) && cr) {
  6678.                         cr = 0;
  6679.                         continue;
  6680.                     }
  6681.                     cr = 0;
  6682.                     break;
  6683.                   default:
  6684.                     cr = 0;
  6685.                 }
  6686.                 /* I'm echoing remote chars */
  6687.                 if (TELOPT_ME(TELOPT_ECHO) && tn_rem_echo)
  6688.                   ttoc((char)y);
  6689.             }
  6690. #endif /* TNCODE */
  6691. #ifdef CK_AUTODL
  6692.             /* Check for file transfer packets */
  6693.             if (inautodl) autodown(y);
  6694. #endif /* CK_AUTODL */
  6695. #else  /* TN_NOLO */
  6696.             debug(F100,"doinput !TN_NOLO","",0);
  6697. #ifdef TNCODE
  6698.             /* Check for telnet protocol negotiation */
  6699.             if (is_tn) {
  6700.                 int tx;
  6701.                 switch (y & 0xff) {
  6702.                   case IAC:
  6703.                     myflsh();   /* Break from input burst for tn_doop() */
  6704. #ifdef CK_BURST
  6705.                     burst = 0;
  6706. #endif /* CK_BURST */
  6707. #ifdef IKS_OPTION
  6708.                     tx = scriptwrtbuf((USHORT)y);
  6709.                     if (tx == 4) {
  6710.                         if (TELOPT_U(TELOPT_KERMIT) && 
  6711.                 TELOPT_SB(TELOPT_KERMIT).kermit.u_start &&
  6712.                             !tcp_incoming
  6713.                             ) {
  6714.                             instatus = INP_IKS;
  6715.                             printf(
  6716.   " Internet Kermit Service in SERVER mode.\n Please use REMOTE commands.\n"
  6717.                                    );
  6718.                             break;
  6719.                         }
  6720.                     } else if (tx == 6) {
  6721.                         /* TELNET DO LOGOUT received */
  6722.  
  6723.                     }
  6724. #else /* IKS_OPTION */
  6725.                     /* Handles Telnet negotiations */
  6726.                     tx = scriptwrtbuf((USHORT)y);
  6727.                     if (tx == 6) {
  6728.                         /* TELNET DO LOGOUT received */
  6729.                     }
  6730. #endif /* IKS_OPTION */
  6731.                     waiting -= 2;       /* (not necessarily...) */
  6732.                     cr = 0;
  6733.                     continue;           /* and autodownload check */
  6734.                   case CR:
  6735.                     cr = 1;
  6736.                     tx = scriptwrtbuf((USHORT)y);
  6737.                     if (tx == 6) {
  6738.                         /* TELNET DO LOGOUT received */
  6739.                     }
  6740.                     break;
  6741.                   case NUL:
  6742.                     cr = 0;
  6743.                     if (!TELOPT_U(TELOPT_BINARY) && cr)
  6744.                       continue;
  6745.                     tx = scriptwrtbuf((USHORT)y);
  6746.                     if (tx == 6) {
  6747.                         /* TELNET DO LOGOUT received */
  6748.                     }
  6749.                     break;
  6750.                   default:
  6751.                     cr = 0;
  6752.                     tx = scriptwrtbuf((USHORT)y);
  6753.                     if (tx == 6) {
  6754.                         /* TELNET DO LOGOUT received */
  6755.                     }
  6756.                 }
  6757.                 /* I'm echoing remote chars */
  6758.                 if (TELOPT_ME(TELOPT_ECHO) && tn_rem_echo)
  6759.                   ttoc((CHAR)y);
  6760.             } else
  6761. #endif /* TNCODE */
  6762.               /* Handles terminal emulation responses */
  6763.               scriptwrtbuf((USHORT)y);
  6764. #endif /* TN_NOLO */
  6765.  
  6766.             /* Real input character to be checked */
  6767.  
  6768. #ifdef CK_BURST
  6769.             burst--;                    /* One less character waiting */
  6770.             debug(F101,"doinput burst","",burst);
  6771. #endif /* CK_BURST */
  6772.             c = (CHAR) (imask & (CHAR) y); /* Mask off any parity */
  6773.             inchar[0] = c;              /* Remember character for \v(inchar) */
  6774. #ifdef COMMENT
  6775. #ifdef CK_BURST
  6776.             /* Update "lastchar" time only once during input burst */
  6777.             if (burst <= 0)
  6778. #endif /* CK_BURST */
  6779. #endif /* COMMENT */
  6780.               lastchar = gtimer();      /* Remember when it came */
  6781.  
  6782.             if (c == '\0') {            /* NUL, we can't use it */
  6783.                 if (anychar) {          /* Except if any character will do? */
  6784.                     x = 1;              /* Yes, done. */
  6785.                     incount = 1;        /* This must be the first and only. */
  6786.                     break;
  6787.                 } else goto refill;     /* Otherwise continue INPUTting */
  6788.             }
  6789.             *inpbp++ = c;               /* Store char in circular buffer */
  6790.             incount++;                  /* Count it for \v(incount) */
  6791.  
  6792.             /* Don't NUL-terminate here - it's a circular buffer. */
  6793.  
  6794.             if (inpbp >= inpbuf + inbufsize) { /* Time to wrap around? */
  6795.                 wrapped++;
  6796.                 *inpbp = NUL ;          /* Make it null-terminated */
  6797.                 inpbp = inpbuf;         /* Yes. */
  6798.             }
  6799.             if (matchbuf) {
  6800.                 if (matchindex < MATCHBUFSIZ) {
  6801.                     matchbuf[matchindex++] = c;
  6802.                     matchbuf[matchindex] = NUL;
  6803.                 }
  6804.             }
  6805. #ifdef MAC
  6806.             {
  6807.                 extern char *ttermw;    /* fake pointer cast */
  6808.                 if (inecho) {
  6809.                     outchar(ttermw, c); /* echo to terminal window */
  6810.                     /* this might be too much overhead to do here ? */
  6811.                     updatecommand(ttermw);
  6812.                 }
  6813.             }
  6814. #else /* Not MAC */
  6815.             if (inecho) {               /* Buffer console output */
  6816.                 conbuf[concnt++] = c;
  6817.             }
  6818. #endif /* MAC */
  6819. #ifndef OS2
  6820.             if (seslog) {
  6821. #ifdef UNIX
  6822.                 if (sessft != 0 || c != '\r')
  6823. #else
  6824. #ifdef OSK
  6825.                 if (sessft != 0 || c != '\012')
  6826. #endif /* OSK */
  6827. #endif /* UNIX */
  6828.                   sesbuf[sescnt++] = c; /* Buffer session log output */
  6829.             }
  6830. #endif /* OS2 */
  6831.             if (anychar) {              /* Any character will do? */
  6832.                 x = 1;
  6833.                 break;
  6834.             }
  6835.             if (!inpcas[cmdlvl]) {      /* Ignore alphabetic case? */
  6836.                 if (isupper(c))         /* Yes, convert input char to lower */
  6837.                   c = (CHAR) tolower(c);
  6838.             }
  6839.             debug(F000,"doinput char","",c);
  6840.  
  6841.             /* Here is the matching section */
  6842.  
  6843.             y = -1;                     /* Loop thru search strings */
  6844.             while ((s = ms[++y])) {     /* ...as many as we have. */
  6845.                 if (mp[y]) {            /* Pattern match? */
  6846. #ifdef COMMENT
  6847.                     int j;
  6848.                     /* This is gross but it works... */
  6849.                     /* We could just as easily have prepended '*' to the  */
  6850.                     /* pattern and skipped the loop, except then we would */
  6851.                     /* not have any way to identify the matching string.  */
  6852.                     for (j = 0; j < matchindex; j++) {
  6853.                         if (ckmatch(s,&matchbuf[j],1,1)) {
  6854.                             matchindex = j;
  6855.                             x = 1;
  6856.                             break;
  6857.                         }
  6858.                     }
  6859.                     if (x > 0)
  6860.                       break;
  6861. #else
  6862.                     /* July 2001 - ckmatch() returns match position. */
  6863.                     /* It works and it's not gross. */
  6864.             /* (4 = floating pattern) */
  6865.                     x = ckmatch(s,matchbuf,inpcas[cmdlvl],1+4);
  6866.                     if (x > 0) {
  6867.                         matchindex = x - 1;
  6868.                         x = 1;
  6869.                         break;
  6870.                     }
  6871. #endif /* COMMENT */
  6872.                     continue;
  6873.                 }                       /* Literal match. */
  6874.                 i = mi[y];              /* Match-position in search string. */
  6875.                 debug(F000,"compare char","",(CHAR)s[i]);
  6876.                 if (c == (CHAR) s[i]) { /* Check for match */
  6877.                     i++;                /* Got one, go to next character */
  6878.                 } else {                /* Don't have a match */
  6879.                     int j;
  6880.                     for (j = i; i > 0; ) { /* Back up in search string */
  6881.                         i--; /* (Do this here to prevent compiler foulup) */
  6882.                         /* j is the length of the substring that matched */
  6883.                         if (c == (CHAR) s[i]) {
  6884.                             if (!strncmp(s,&s[j-i],i)) {
  6885.                                 i++;          /* c actually matches -- cfk */
  6886.                                 break;
  6887.                             }
  6888.                         }
  6889.                     }
  6890.                 }
  6891.                 if ((CHAR) s[i] == (CHAR) '\0') { /* Matched to end? */
  6892.                     ckstrncpy(matchbuf,ms[y],MATCHBUFSIZ);
  6893.                     matchindex = 0;
  6894.                     x = 1;              /* Yes, */
  6895.                     break;              /* done. */
  6896.                 }
  6897.                 mi[y] = i;              /* No, remember match-position */
  6898.             }
  6899.             if (x == 1) {               /* Set \v(minput) result */
  6900.                 m_found = y + 1;
  6901.                 break;
  6902.             }
  6903.         }
  6904. #ifdef CK_BURST
  6905.         else if (y <= -1 && burst > 0) {
  6906.             debug(F111,"doinput (y<=-1&&burst>0)","burst",burst);
  6907.                                         /* a timo occurred so there can't   */
  6908.             burst = 0;                  /* be data waiting; must check timo */
  6909.         }
  6910.       refill:
  6911.         if (burst <= 0) {               /* No buffered chars remaining... */
  6912.             myflsh();                   /* Flush buffered output */
  6913.             if (local) {                /* Get size of next input burst */
  6914.                 burst = ttchk();
  6915.                 if (burst < 0) {        /* ttchk() says connection is closed */
  6916.                     instatus = INP_IO;  /* Status = i/o error */
  6917. #ifndef NOLOCAL
  6918. #ifdef OS2
  6919.                     term_io = term_io_save;
  6920. #endif /* OS2 */
  6921. #endif /* NOLOCAL */
  6922.  
  6923.             if ((!network 
  6924. #ifdef TN_COMPORT
  6925.                  || istncomport()
  6926. #endif /* TN_COMPORT */
  6927.              ) && carrier != CAR_OFF) {
  6928.     /* The test is written this way because the Microsoft compiler
  6929.      * is producing bad code if written:
  6930.      *
  6931.      *  if (network && (!istncomport() || carrier == CAR_OFF) )
  6932.      */
  6933.             break;
  6934.                      } else {
  6935.              printf("Fatal error - disconnected.\n");
  6936.              ttclos(1);
  6937.              break;
  6938.              }
  6939.                 }
  6940.                 if (inintr) {
  6941.                     if ((icn = conchk()) > 0) { /* Interrupt from keyboard? */
  6942.                         kbchar = coninc(0);
  6943.                         debug(F101,"input interrupted from keyboard","",icn);
  6944.                         while (--icn > 0) coninc(0); /* Yes, absorb chars. */
  6945.                         break;          /* And fail. */
  6946.                     }
  6947.                 }
  6948.             } else {
  6949.                 burst = conchk();
  6950.             }
  6951.             debug(F101,"doinput burst","",burst);
  6952.             /* Prevent overflow of "conbuf" and "sesbuf" */
  6953.             if (burst > MAXBURST)
  6954.               burst = MAXBURST;
  6955.  
  6956.             /* Did not match, timer exceeded? */
  6957.             t = gtimer();
  6958.             debug(F111,"doinput gtimer","burst",t);
  6959.             debug(F101,"doinput timo","",timo);
  6960.             if ((t >= timo) && (timo > 0))
  6961.               break;
  6962.             else if (insilence > 0 && (t - lastchar) > insilence)
  6963.               break;
  6964.         } else {
  6965.             debug(F111,"doinput (burst > 0)","burst",burst);
  6966.         }
  6967. #else
  6968.         myflsh();                       /* Flush buffered output */
  6969.         /* Did not match, timer exceeded? */
  6970.         t = gtimer();
  6971.         debug(F111,"doinput gtimer","no burst",t);
  6972.         debug(F101,"doinput timo","",timo);
  6973.         if ((t >= timo) && (timo > -1))
  6974.           break;
  6975.         else if (insilence > 0 && (t - lastchar) > insilence)
  6976.           break;
  6977. #endif /* CK_BURST */
  6978.     }                                   /* Still have time left, continue. */
  6979.     myflsh();                           /* Flush buffered output. */
  6980.     if (x > 0)
  6981.       instatus = 0;
  6982. #ifndef NOLOCAL
  6983. #ifdef OS2
  6984.     term_io = term_io_save;
  6985. #endif /* OS2 */
  6986. #endif /* NOLOCAL */
  6987. #ifdef COMMENT
  6988. #ifdef IKS_OPTION
  6989. #ifdef CK_AUTODL
  6990.     if (is_tn && TELOPT_ME(TELOPT_KERMIT) && inautodl) {
  6991.         tn_siks(KERMIT_STOP);           /* Send Kermit-Server Stop */
  6992.     }
  6993. #endif /* CK_AUTODL */
  6994. #endif /* IKS_OPTION */
  6995. #endif /* COMMENT */
  6996.  
  6997. #ifdef GFTIMER
  6998.     fpt = gftimer();                    /* Get elapsed time */
  6999.  
  7000. /* If a long is 32 bits, it would take about 50 days for this to overflow. */
  7001.  
  7002.     inetime = (int)(fpt * (CKFLOAT)1000.0);
  7003. #else
  7004.     inetime = (int)(gtimer() * 1000);
  7005. #endif /* GFTIMER */
  7006.  
  7007.     makestr(&inpmatch,&matchbuf[matchindex]); /* \v(inmatch) */
  7008.     return(x);                          /* Return the return code. */
  7009. }
  7010. #endif /* NOSPL */
  7011.  
  7012. #ifndef NOSPL
  7013. /* REINPUT Command */
  7014.  
  7015. /*
  7016.   Note, the timeout parameter is required, but ignored.  Syntax is compatible
  7017.   with MS-DOS Kermit except timeout can't be omitted.  This function only
  7018.   looks at the characters already received and does not read any new
  7019.   characters from the connection.
  7020. */
  7021. int
  7022. doreinp(timo,s,pat) int timo; char *s; int pat; {
  7023.     int x, y, i;
  7024.     char *xx, *xp, *xq = (char *)0;
  7025.     CHAR c;
  7026.  
  7027.     if (!s) s = "";
  7028.     debug(F101,"doreinput pat","",pat);
  7029.  
  7030.     y = (int)strlen(s);
  7031.     debug(F111,"doreinput search",s,y);
  7032.  
  7033.     if (y > inbufsize) {                /* If search string longer than */
  7034.         debug(F101,"doreinput inbufsize","",inbufsize);
  7035.         return(0);                      /* input buffer, fail. */
  7036.     }
  7037.     makestr(&inpmatch,NULL);
  7038.     if (!matchbuf)
  7039.       matchbuf = malloc(MATCHBUFSIZ+1);
  7040.     matchindex = 0;
  7041.  
  7042.     x = 0;                              /* Return code, assume failure */
  7043.     i = 0;                              /* String pattern match position */
  7044.  
  7045.     if (!inpcas[cmdlvl]) {              /* INPUT CASE = IGNORE?  */
  7046.         xp = malloc(y+2);               /* Make a separate copy of the */
  7047.         if (!xp) {                      /* search string. */
  7048.             printf("?malloc error 6\n");
  7049.             return(x);
  7050.         } else xq = xp;                 /* Keep pointer to beginning. */
  7051.         while (*s) {                    /* Yes, convert to lowercase */
  7052.             *xp = *s;
  7053.             if (isupper(*xp)) *xp = (char) tolower(*xp);
  7054.             xp++; s++;
  7055.         }
  7056.         *xp = NUL;                      /* Terminate it! */
  7057.         s = xq;                         /* Move search pointer to it. */
  7058.     }
  7059.     xx = *inpbp ? inpbp : inpbuf;       /* Current INPUT buffer pointer */
  7060.     do {
  7061.         c = *xx++;                      /* Get next character */
  7062.         if (!c) break;
  7063.         if (xx >= inpbuf + inbufsize)   /* Wrap around if necessary */
  7064.           xx = inpbuf;
  7065.         if (!inpcas[cmdlvl]) {          /* Ignore alphabetic case? */
  7066.             if (isupper(c)) c = (CHAR) tolower(c); /* Yes */
  7067.         }
  7068.         if (pat) {
  7069.             int j;
  7070.             if (matchbuf) {
  7071.                 if (matchindex < MATCHBUFSIZ) {
  7072.                     matchbuf[matchindex++] = c;
  7073.                     matchbuf[matchindex] = NUL;
  7074.                 }
  7075.                 for (j = 0; j < matchindex; j++) { /* Gross but effective */
  7076.                     if (ckmatch(s,&matchbuf[j],1,1)) {
  7077.                         debug(F101,"GOT IT","",j);
  7078.                         matchindex = j;
  7079.                         x = 1;
  7080.                         break;
  7081.                     }
  7082.                 }
  7083.             }
  7084.             if (x > 0)
  7085.               break;
  7086.             continue;
  7087.         }
  7088.         debug(F000,"doreinp char","",c);
  7089.         debug(F000,"compare char","",(CHAR) s[i]);
  7090.         if (((char) c) == ((char) s[i])) { /* Check for match */
  7091.             i++;                        /* Got one, go to next character */
  7092.         } else {                        /* Don't have a match */
  7093.             int j;
  7094.             for (j = i; i > 0; ) {      /* [jrs] search backwards for it  */
  7095.                 i--;
  7096.                 if (((char) c) == ((char) s[i])) {
  7097.                     if (!strncmp(s,&s[j-i],i)) {
  7098.                         i++;
  7099.                         break;
  7100.                     }
  7101.                 }
  7102.             }
  7103.         }                               /* [jrs] or return to zero from -1 */
  7104.         if (s[i] == '\0') {             /* Matched all the way to end? */
  7105.             ckstrncpy(matchbuf,s,MATCHBUFSIZ);
  7106.             matchindex = 0;
  7107.             x = 1;                      /* Yes, */
  7108.             break;                      /* done. */
  7109.         }
  7110.     } while (xx != inpbp && x < 1);     /* Until back where we started. */
  7111.  
  7112.     if (!inpcas[cmdlvl]) if (xq) free(xq); /* Free this if it was malloc'd. */
  7113.     makestr(&inpmatch,&matchbuf[matchindex]); /* \v(inmatch) */
  7114.     return(x);                          /* Return search result. */
  7115. }
  7116.  
  7117. /*  X X S T R I N G  --  Interpret strings containing backslash escapes  */
  7118. /*  Z Z S T R I N G  --  (new name...)  */
  7119. /*
  7120.  Copies result to new string.
  7121.   strips enclosing braces or doublequotes.
  7122.   interprets backslash escapes.
  7123.   returns 0 on success, nonzero on failure.
  7124.   tries to be compatible with MS-DOS Kermit.
  7125.  
  7126.  Syntax of input string:
  7127.   string = chars | "chars" | {chars}
  7128.   chars = (c*e*)*
  7129.   where c = any printable character, ascii 32-126
  7130.   and e = a backslash escape
  7131.   and * means 0 or more repetitions of preceding quantity
  7132.   backslash escape = \operand
  7133.   operand = {number} | number | fname(operand) | v(name) | $(name) | m(name)
  7134.   number = [r]n[n[n]]], i.e. an optional radix code followed by 1-3 digits
  7135.   radix code is oO (octal), xX (hex), dD or none (decimal) (see xxesc()).
  7136. */
  7137.  
  7138. #ifndef NOFRILLS
  7139. int
  7140. yystring(s,s2) char *s; char **s2; {    /* Reverse a string */
  7141.     int x;
  7142.     static char *new;
  7143.     new = *s2;
  7144.     if (!s || !new) return(-1);         /* Watch out for null pointers. */
  7145.     if ((x = (int)strlen(s)) == 0) {    /* Recursion done. */
  7146.         *new = '\0';
  7147.         return(0);
  7148.     }
  7149.     x--;                                /* Otherwise, call self */
  7150.     *new++ = s[x];                      /* to reverse rest of string. */
  7151.     s[x] = 0;
  7152.     return(yystring(s,&new));
  7153. }
  7154. #endif /* NOFRILLS */
  7155.  
  7156. static char ipabuf[16] = { NUL };       /* IP address buffer */
  7157.  
  7158. static char *
  7159. getip(s) char *s; {
  7160.     char c=NUL;                         /* Workers... */
  7161.     int i=0, p=0, d=0;
  7162.     int state = 0;                      /* State of 2-state FSA */
  7163.  
  7164.     while ((c = *s++)) {
  7165.         switch(state) {
  7166.           case 0:                       /* Find first digit */
  7167.             i = 0;                      /* Output buffer index */
  7168.             ipabuf[i] = NUL;            /* Initialize output buffer */
  7169.             p = 0;                      /* Period counter */
  7170.             d = 0;                      /* Digit counter */
  7171.             if (isdigit(c)) {           /* Have first digit */
  7172.                 d = 1;                  /* Count it */
  7173.                 ipabuf[i++] = c;        /* Copy it */
  7174.                 state = 1;              /* Change state */
  7175.             }
  7176.             break;
  7177.  
  7178.           case 1:                       /* In numeric field */
  7179.             if (isdigit(c)) {           /* Have digit */
  7180.                 if (++d > 3)            /* Too many */
  7181.                   state = 0;            /* Start over */
  7182.                 else                    /* Not too many */
  7183.                   ipabuf[i++] = c;      /* Keep it */
  7184.             } else if (c == '.' && p < 3) { /* Have a period */
  7185.                 p++;                    /* Count it */
  7186.                 if (d == 0)             /* Not preceded by a digit */
  7187.                   state = 0;            /* Start over */
  7188.                 else                    /* OK */
  7189.                   ipabuf[i++] = c;      /* Keep it */
  7190.                 d = 0;                  /* Reset digit counter */
  7191.             } else if (p == 3 && d > 0) { /* Not part of address */
  7192.                 ipabuf[i] = NUL;        /* If we have full IP address */
  7193.                 return((char *)ipabuf); /* Return it */
  7194.             } else {                    /* Otherwise */
  7195.                 state = 0;              /* Start over */
  7196.                 ipabuf[0] = NUL;        /* (in case no more chars left) */
  7197.             }
  7198.         }
  7199.     }                                   /* Fall thru at end of string */
  7200.     ipabuf[i] = NUL;                    /* Maybe we have one */
  7201.     return((p == 3 && d > 0) ? (char *)ipabuf : "");
  7202. }
  7203. #endif /* NOSPL */
  7204.  
  7205. /* Date Routines */
  7206.  
  7207. /* Z J D A T E  --  Convert yyyymmdd date to Day of Year */
  7208.  
  7209. static int jdays[12] = {  0,31,59,90,120,151,181,212,243,273,304,334 };
  7210. static int ldays[12] = {  0,31,60,91,121,152,182,213,244,274,305,335 };
  7211. static char zjdbuf[12] = { NUL, NUL };
  7212. /*
  7213.   Deinde, ne in posterum a XII kalendas aprilis aequinoctium recedat,
  7214.   statuimus bissextum quarto quoque anno (uti mos est) continuari debere,
  7215.   praeterquam in centesimis annis; qui, quamvis bissextiles antea semper
  7216.   fuerint, qualem etiam esse volumus annum MDC, post eum tamen qui deinceps
  7217.   consequentur centesimi non omnes bissextiles sint, sed in quadringentis
  7218.   quibusque annis primi quique tres centesimi sine bissexto transigantur,
  7219.   quartus vero quisque centesimus bissextilis sit, ita ut annus MDCC, MDCCC,
  7220.   MDCCCC bissextiles non sint. Anno vero MM, more consueto dies bissextus
  7221.   intercaletur, februario dies XXIX continente, idemque ordo intermittendi
  7222.   intercalandique bissextum diem in quadringentis quibusque annis perpetuo
  7223.   conservetur.  - Gregorius XIII, Anno Domini MDLXXXII.
  7224. */
  7225. char *
  7226. zjdate(date) char * date; {             /* date = yyyymmdd */
  7227.     char year[5];
  7228.     char month[3];
  7229.     char day[3];
  7230.     int d, m, x, y;
  7231.     int leapday, j;
  7232.     char * time = NULL;
  7233.  
  7234.     if (!date) date = "";               /* Validate arg */
  7235.     x = strlen(date);
  7236.     if (x < 1) return("0");
  7237.     if (x < 8) return("-1");
  7238.     for (x = 0; x < 8; x++)
  7239.       if (!isdigit(date[x]))
  7240.         return("-1");
  7241.  
  7242.     if (date[8]) if (date[9])
  7243.       time = date + 9;
  7244.  
  7245.     year[0] = date[0];                  /* Isolate year */
  7246.     year[1] = date[1];
  7247.     year[2] = date[2];
  7248.     year[3] = date[3];
  7249.     year[4] = '\0';
  7250.  
  7251.     month[0] = date[4];                 /* Month */
  7252.     month[1] = date[5];
  7253.     month[2] = '\0';;
  7254.  
  7255.     day[0] = date[6];                   /* And day */
  7256.     day[1] = date[7];
  7257.     day[2] = '\0';
  7258.  
  7259.     leapday = 0;                        /* Assume no leap day */
  7260.     y = atoi(year);
  7261.     m = atoi(month);
  7262.     d = atoi(day);
  7263.     if (m > 2) {                        /* No Leap day before March */
  7264.         if (y % 4 == 0) {               /* If year is divisible by 4 */
  7265.             leapday = 1;                /* It's a Leap year */
  7266.             if (y % 100 == 0) {         /* Except if divisible by 100 */
  7267.                 if (y % 400 != 0)       /* but not by 400 */
  7268.                   leapday = 0;
  7269.             }
  7270.         }
  7271.     }
  7272.     j = jdays[m - 1] + d + leapday;     /* Day of year */
  7273.     if (time)
  7274.       sprintf(zjdbuf,"%04d%03d %s",y,j,time); /* SAFE */
  7275.     else
  7276.       sprintf(zjdbuf,"%04d%03d",y,j);   /* SAFE */
  7277.     return((char *)zjdbuf);
  7278. }
  7279.  
  7280. static char jzdbuf[32];
  7281.  
  7282. /* J Z D A T E  --  Convert Day of Year to yyyyddmm date */
  7283.  
  7284. char *
  7285. jzdate(date) char * date; {             /* date = yyyyddd */
  7286.     char year[5];                       /* with optional time */
  7287.     char day[4];
  7288.     char * time = NULL, * p;
  7289.     int d, m, x, y;
  7290.     int leapday, j;
  7291.     int * zz;
  7292.  
  7293.     if (!date) date = "";               /* Validate arg */
  7294.     x = strlen(date);
  7295.  
  7296.     debug(F111,"jzdate len",date,x);
  7297.  
  7298.     if (x < 1) return("0");
  7299.     if (x < 7) return("-1");
  7300.     if (x > 8) time = date + 8;
  7301.  
  7302.     for (x = 0; x < 7; x++)
  7303.       if (!isdigit(date[x]))
  7304.         return("-1");
  7305.  
  7306.     year[0] = date[0];                  /* Isolate year */
  7307.     year[1] = date[1];
  7308.     year[2] = date[2];
  7309.     year[3] = date[3];
  7310.     year[4] = '\0';
  7311.  
  7312.     debug(F110,"jzdate year",year,0);
  7313.  
  7314.     day[0] = date[4];                   /* And day */
  7315.     day[1] = date[5];
  7316.     day[2] = date[6];
  7317.     day[3] = '\0';
  7318.  
  7319.     debug(F110,"jzdate day",day,0);
  7320.  
  7321.     j = atoi(day);
  7322.     if (j > 366)
  7323.       return("-1");
  7324.  
  7325.     leapday = 0;                        /* Assume no leap day */
  7326.     y = atoi(year);
  7327.     if (y % 4 == 0) {                   /* If year is divisible by 4 */
  7328.         leapday = 1;                    /* It's a Leap year */
  7329.         if (y % 100 == 0) {             /* Except if divisible by 100 */
  7330.             if (y % 400 != 0)           /* but not by 400 */
  7331.               leapday = 0;
  7332.         }
  7333.     }
  7334.     debug(F101,"jzdate leapday","",leapday);
  7335.     zz = leapday ? ldays : jdays;
  7336.  
  7337.     for (x = 0; x < 11; x++)
  7338.       if (j > zz[x] && j <= zz[x+1])
  7339.         break;
  7340.     m = x + 1;
  7341.  
  7342.     debug(F101,"jzdate m","",m);
  7343.  
  7344.     d = j - zz[x];
  7345.  
  7346.     debug(F101,"jzdate d","",d);
  7347.  
  7348.     if (time)
  7349.       sprintf(jzdbuf,"%04d%02d%02d %s",y,m,d,time); /* SAFE */
  7350.     else
  7351.       sprintf(jzdbuf,"%04d%02d%02d",y,m,d); /* SAFE */
  7352.  
  7353.     debug(F101,"jzdate jzdbuf",jzdbuf,0);
  7354.  
  7355.     p = ckcvtdate((char *)jzdbuf, 0);   /* Convert to standard form */
  7356.     ckstrncpy(jzdbuf,p,32);
  7357.     if (!time) jzdbuf[8] = NUL;         /* Remove time if not wanted */
  7358.     return((char *)jzdbuf);
  7359. }
  7360.  
  7361. /* M J D  --  Modified Julian Date */
  7362. /*
  7363.   Call with:
  7364.     Standard-format date-time string: yyyymmdd[ hh:mm:ss].
  7365.     The time, if any, is ignored.
  7366.  
  7367.   Returns:
  7368.     -1L on error, otherwise:
  7369.     The number of days since 17 Nov 1858 as a whole number:
  7370.     16 Nov 1858 = -1, 17 Nov 1858 = 0, 18 Nov 1858 = 1, 19 Nov 1858 = 2, ...
  7371.  
  7372.   The Modified Julian Date is defined by the International Astronomical
  7373.   Union as the true Julian date minus 2400000.5 days.  The true Julian
  7374.   date is the number days since since noon of 1 January 4713 BCE of the
  7375.   Julian proleptic calendar.  Conversions between calendar dates and
  7376.   Julian dates, however, assume Gregorian dating.
  7377. */
  7378. long
  7379. mjd(date) char * date; {
  7380.     char year[5];
  7381.     char month[3];
  7382.     char day[3];
  7383.     int x, a, d, m, y;
  7384.     long z;
  7385.  
  7386.     if (!date) date = "";               /* Validate arg */
  7387.     x = strlen(date);
  7388.     if (x < 1) return(0L);
  7389.     if (x < 8) return(-1L);
  7390.     for (x = 0; x < 8; x++)
  7391.       if (!isdigit(date[x]))
  7392.         return(-1L);
  7393.  
  7394.     year[0] = date[0];                  /* Isolate year */
  7395.     year[1] = date[1];
  7396.     year[2] = date[2];
  7397.     year[3] = date[3];
  7398.     year[4] = '\0';
  7399.  
  7400.     month[0] = date[4];                 /* Month */
  7401.     month[1] = date[5];
  7402.     month[2] = '\0';;
  7403.     m = atoi(month);
  7404.  
  7405.     day[0] = date[6];                   /* And day */
  7406.     day[1] = date[7];
  7407.     day[2] = '\0';
  7408.     d = atoi(day);
  7409.  
  7410.     a = (14-m)/12;                      /* Calculate true Julian date */
  7411.     y = atoi(year) + 4800 - a;
  7412.     m = m + 12 * a - 3;
  7413.     z = d + (long)(306*m+5)/10 + (long)(y*365) + y/4 - y/100 + y/400 - 32045L;
  7414.  
  7415.     z -= 2400001L;                      /* Convert JD to MJD */
  7416.  
  7417.     return(z);
  7418. }
  7419.  
  7420. static char mjd2dbuf[32];
  7421.  
  7422. /*  M J D 2 D A T E  --  Converts MJD to yyyymmdd  */
  7423.  
  7424. char *
  7425. #ifdef CK_ANSIC
  7426. mjd2date(long mjd)
  7427. #else
  7428. mjd2date(mjd) long mjd;
  7429. #endif /* CK_ANSIC */
  7430. /* mjd2date */ {
  7431.     long jd, l, n;
  7432.     int d, m, y;
  7433.     jd = (long)(mjd + 2400001L);
  7434.     l = jd + 68569;
  7435.     n = 4 * l / 146097L;
  7436.     l = l - (146097 * n + 3) / 4;
  7437.     y = 4000 * (l + 1) / 1461001L;
  7438.     l = l - 1461 * y / 4 + 31;
  7439.     m = 80 * l / 2447;
  7440.     d = l - 2447 * m / 80;
  7441.     l = m / 11;
  7442.     m = m + 2 - 12 * l;
  7443.     y = 100 * (n - 49) + y + l;
  7444.     sprintf(mjd2dbuf,"%04d%02d%02d",y,m,d); /* SAFE */
  7445.     return((char *)mjd2dbuf);
  7446. }
  7447.  
  7448. #ifndef NOSPL
  7449. static char ** flist = (char **) NULL;  /* File list for \fnextfile() */
  7450. static int flistn = 0;                  /* Number of items in file list */
  7451.  
  7452. /*
  7453.   The function return-value buffer must be global, since fneval() returns a
  7454.   pointer to it.  fneval() is called only by zzstring(), which always copies
  7455.   the result out of this buffer to somewhere else, so it's OK to have only
  7456.   one buffer for this in most cases.  However, since function calls can be
  7457.   nested -- e.g. functions whose arguments are functions, or recursive
  7458.   functions, at some point we should convert this to an array of buffers,
  7459.   indexed by function depth (which might or might not be the same as the
  7460.   "depth" variable).  Also, since function results are potentially quite big,
  7461.   we'd need to allocate and deallocate dynamically as we descend and ascend
  7462.   function depth.  Left for a future release...
  7463. */
  7464. char fnval[FNVALL+2];                   /* Function return value  */
  7465. static int fndepth = 0;                 /* (we don't actually use this yet) */
  7466. int fnsuccess = 1;
  7467. extern int fnerror;
  7468.  
  7469. /* f p f o r m a t  --  Floating-point number nicely formatted.  */
  7470. /*
  7471.    Returns results from a circular 1K buffer.
  7472.    Don't count on too many results remaining available at once; it could
  7473.    be anywhere from 5 to maybe 100, depending on the sizes of the results.
  7474. */
  7475. #ifdef CKFLOAT
  7476. #define FPFMTSIZ 1024
  7477. static char fpfmtbuf[FPFMTSIZ] = { NUL, NUL };
  7478. static int fpfbufpos = 0;               /* (why was this char before?) */
  7479.  
  7480. char *
  7481. fpformat(fpresult,places,round) CKFLOAT fpresult; int places, round; {
  7482.     char fbuf[16];                      /* For creating printf format */
  7483.     int nines = 0, sign = 0, x, y, i, j, size = 0;
  7484.     char * buf;
  7485.     CKFLOAT ftmp;
  7486.  
  7487.     x = places ? places : (fp_digits ? fp_digits : 6);
  7488.  
  7489.     debug(F101,"fpformat fpresult","",fpresult);
  7490.     debug(F101,"fpformat places","",places);
  7491.     debug(F101,"fpformat fpfbufpos 1","",fpfbufpos);
  7492.  
  7493.     ftmp = fpresult;
  7494.     if (ftmp < 0.0) ftmp = 0.0 - fpresult;
  7495.  
  7496. #ifdef FNFLOAT
  7497.     if (!fp_rounding &&                 /* If printf doesn't round, */
  7498.         (places > 0 ||                  /* round result to decimal places. */
  7499.          (places == 0 && round)))
  7500.       fpresult += (0.5 / pow(10.0,(CKFLOAT)places));
  7501.     y = (ftmp == 0.0) ? 1 : (int)log10(ftmp);
  7502.     size = y + x + 3;                   /* Estimated length of result */
  7503.     if (fpresult < 0.0) size++;
  7504. #else
  7505.     size = 200;                         /* No way to estimate, be generous */
  7506. #endif /* FNFLOAT */
  7507.  
  7508.     debug(F101,"fpformat size","",size);
  7509.  
  7510.     if (fpfbufpos > (FPFMTSIZ - size))  /* Wrap around if necessary */
  7511.       fpfbufpos = 0;
  7512.     debug(F101,"fpformat fpfbufpos 1","",fpfbufpos);
  7513.  
  7514.     buf = &fpfmtbuf[fpfbufpos];
  7515.  
  7516.     if (places > 0) {                   /* If places specified */
  7517.         /* use specified places to write given number of digits */
  7518.         sprintf(fbuf,"%%0.%df",places); /* SAFE */
  7519.         sprintf(buf,fbuf,fpresult);     /* SAFE */
  7520.     } else {                            /* Otherwise... */
  7521.         /* Go for max precision */
  7522.         sprintf(fbuf,"%%0.%df",fp_digits); /* SAFE */
  7523.         sprintf(buf,fbuf,fpresult);     /* SAFE */
  7524.     }
  7525.     if (buf[0] == '-') sign = 1;
  7526.     debug(F111,"fpresult 1 errno",buf,errno); /* Check for over/underflow */
  7527.     debug(F111,"fpresult 1 fpfbufpos",buf,fpfbufpos);
  7528.     /* Give requested decimal places */
  7529.     for (i = sign; i < FPFMTSIZ && buf[i]; i++) {
  7530.         if (buf[i] == '.')              /* First find the decimal point */
  7531.           break;
  7532.         else if (i > fp_digits + sign - 1) /* replacing garbage */
  7533.           buf[i] = '0';                 /* digits with 0... */
  7534.     }
  7535.     if (buf[i] == '.') {                /* Have decimal point */
  7536.         int gotend = 0;
  7537.         /* places < 0 so truncate fraction */
  7538.         if (places < 0 || (places == 0 && round)) {
  7539.             buf[i] = NUL;
  7540.         } else if (places > 0) {        /* d > 0 so this many decimal places */
  7541.             i++;                           /* First digit after decimal */
  7542.             for (j = 0; j < places; j++) { /* Truncate after d decimal */
  7543.                 if (!buf[j+i])        /* places or extend to d  */
  7544.                   gotend = 1;              /* decimal places. */
  7545.                 if (gotend || j+i+sign > fp_digits)
  7546.                   buf[j+i] = '0';
  7547.             }
  7548.             buf[j+i] = NUL;
  7549.         } else {                        /* places == 0 so Do The Right Thing */
  7550.             for (j = (int)strlen(buf) - 1; j > i+1; j--) {
  7551.                 if ((j - sign) > fp_digits)
  7552.                   buf[j] = '0';
  7553.                 if (buf[j] == '0')
  7554.                   buf[j] = NUL; /* Strip useless trailing 0's. */
  7555.                 else
  7556.                   break;
  7557.             }
  7558.         }
  7559.     }
  7560.     fpfmtbuf[FPFMTSIZ-1] = NUL;
  7561.     j = strlen(buf);
  7562.     sign = 0;
  7563.     for (i = j-1; i >= 0; i--) {
  7564.         if (buf[i] == '9')
  7565.           nines++;
  7566.         else
  7567.           break;
  7568.     }
  7569.     /* Do something about xx.xx99999999... */
  7570.     if (nines > 5) {
  7571.         if (isdigit(buf[i]) && i < FPFMTSIZ - 2) {
  7572.             buf[i] = buf[i] + 1;
  7573.             buf[i+1] = '0';
  7574.             buf[i+2] = '\0';
  7575.         }
  7576.     }
  7577.     if (!strncmp(buf,"-0.0",FPFMTSIZ))
  7578.       ckstrncpy(buf,"0.0",FPFMTSIZ);
  7579.     fpfbufpos += (int)strlen(buf) + 1;
  7580.     return((char *)buf);
  7581. }
  7582. #endif /* CKFLOAT */
  7583.  
  7584. static VOID
  7585. evalerr(fn) char * fn; {
  7586.     if (fndiags) {
  7587.         if (divbyzero)
  7588.           ckmakmsg(fnval,FNVALL,"<ERROR:DIVIDE_BY_ZERO:\\f",fn,"()>",NULL);
  7589.         else
  7590.           ckmakmsg(fnval,FNVALL,"<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  7591.     }
  7592. }
  7593.  
  7594. char *
  7595. dokwval(s,sep) char * s, sep; {
  7596.     char c = '\0', * p, * kw = NULL, * vp = NULL;
  7597.     int x;
  7598.     if (!s) return("0");
  7599.     if (!*s) return("0");
  7600.     debug(F110,"kwval arg",s,0);
  7601.     debug(F110,"kwval sep",ckctoa(sep),0);
  7602.     p = (char *)malloc((int)strlen(s)+1);
  7603.     if (!p) return("0");
  7604.     strcpy(p,s);                        /* SAFE */
  7605.     s = p;
  7606.     while (*s < '!' && *s > '\0')       /* Get first nonblank */
  7607.       s++;
  7608.     if (!*s) return("0");
  7609.     if (*s == sep) return("0");
  7610.     kw = s;                             /* Keyword */
  7611.     while (*s > ' ') {
  7612.         if (*s == sep) {                /* keyword=... */
  7613.             c = *s;
  7614.             break;
  7615.         }
  7616.         s++;
  7617.     }
  7618.     *s++ = NUL;                         /* Terminate keyword */
  7619.     while (*s < '!' && *s > '\0')       /* Skip blanks */
  7620.       s++;
  7621.     if (!c && *s == sep) {
  7622.         c = *s++;                       /* Have separator */
  7623.         while (*s < '!' && *s > '\0')   /* Skip blanks */
  7624.           s++;
  7625.     }
  7626.     if (c) {
  7627.         vp = s;
  7628.         while (*s > ' ')                /* Skip to end */
  7629.           s++;
  7630.         *s = NUL;                       /* Terminate value */
  7631.     }
  7632.     debug(F110,"kwval c",ckctoa(c),0);
  7633.     debug(F110,"kwval keyword",kw,0);
  7634.     debug(F110,"kwval value",vp,0);
  7635.     x = c ? addmac(kw,vp) : -1;
  7636.     free(p);
  7637.     return((x < 0) ? "0" : "1");
  7638. }
  7639.  
  7640. static int
  7641. isaarray(s) char * s; {            /* Is s an associative array element */
  7642.     int state = 0;
  7643.     CHAR c;
  7644.     if (!s) return(0);
  7645.     while ((c = *s++)) {
  7646.     if (!isprint(c)) {
  7647.         return(0);
  7648.     } else if (c == '<') {
  7649.         if (state != 0)
  7650.           return(0);
  7651.         state = 1;
  7652.     } else if (c == '>') {
  7653.         return((state != 1 || *s) ? 0 : 1);
  7654.     }
  7655.     }
  7656.     return(0);
  7657. }
  7658.  
  7659. static char *                           /* Evaluate builtin functions */
  7660. fneval(fn,argp,argn,xp) char *fn, *argp[]; int argn; char * xp; {
  7661.     int i=0, j=0, k=0, len1=0, len2=0, len3=0, n=0, t=0, x=0, y=0;
  7662.     int cx, failed = 0;                 /* Return code, 0 = ok */
  7663.     long z = 0L;
  7664.     char *bp[FNARGS + 1];               /* Pointers to malloc'd strings */
  7665.     char c = NUL;
  7666.     char *p = NULL, *s = NULL;
  7667.     char *val1 = NULL, *val2 = NULL;    /* Pointers to numeric string values */
  7668.  
  7669. #ifdef RECURSIVE
  7670.     int rsave = recursive;
  7671. #endif /* RECURSIVE */
  7672. #ifdef OS2
  7673.     int zsave = zxpn;
  7674. #endif /* OS2 */
  7675.  
  7676.     if (!fn) fn = "";                   /* Protect against null pointers */
  7677.     if (!*fn) return("");
  7678.  
  7679.     for (i = 0; i < FNARGS; i++)        /* Initialize argument pointers */
  7680.       bp[i] = NULL;
  7681. /*
  7682.   IMPORTANT: Note that argn is not an accurate count of the number of
  7683.   arguments.  We can't really tell if an argument is null until after we
  7684.   execute the code below.  So argn is really the maximum number of arguments
  7685.   we might have.  Argn should always be at least 1, even if the function is
  7686.   called with empty parentheses (but don't count on it).
  7687. */
  7688.     debug(F111,"fneval",fn,argn);
  7689.     debug(F110,"fneval",argp[0],0);
  7690.     if (argn > FNARGS)                  /* Discard excess arguments */
  7691.       argn = FNARGS;
  7692.  
  7693.     fndepth++;
  7694.     debug(F101,"fneval fndepth","",fndepth);
  7695.     p = fnval;
  7696.     fnval[0] = NUL;
  7697.     y = lookup(fnctab,fn,nfuncs,&x);    /* Look up the function name */
  7698.     cx = y;                             /* Because y is too generic... */
  7699.     if (cx < 0) {                        /* Not found */
  7700.         failed = 1;
  7701.         if (fndiags) {                  /* FUNCTION DIAGNOSTIC ON */
  7702.             int x;
  7703.             x = strlen(fn);
  7704.             /* The following sprintf's are safe */
  7705.             switch (cx) {
  7706.               case -1:
  7707.                 if (x + 32 < FNVALL)
  7708.                   sprintf(fnval,"<ERROR:NO_SUCH_FUNCTION:\\f%s()>",fn);
  7709.                 else
  7710.                   sprintf(fnval,"<ERROR:NO_SUCH_FUNCTION>");
  7711.                 break;
  7712.               case -2:
  7713.                 if (x + 26 < FNVALL)
  7714.                   sprintf(fnval,"<ERROR:NAME_AMBIGUOUS:\\f%s()>",fn);
  7715.                 else
  7716.                   sprintf(fnval,"<ERROR:NAME_AMBIGUOUS>");
  7717.                 break;
  7718.               case -3:
  7719.                 sprintf(fnval,"<ERROR:FUNCTION_NAME_MISSING:\\f()>");
  7720.                 break;
  7721.               default:
  7722.                 if (x + 26 < FNVALL)
  7723.                   sprintf(fnval,"<ERROR:LOOKUP_FAILURE:\\f%s()>",fn);
  7724.                 else
  7725.                   sprintf(fnval,"<ERROR:LOOKUP_FAILURE>");
  7726.                 break;
  7727.             }
  7728.         }
  7729.         goto fnend;                     /* Always leave via common exit */
  7730.     }
  7731.     fn = fnctab[x].kwd;                 /* Full name of function */
  7732.  
  7733.     if (argn < 0) {
  7734.         failed = 1;
  7735.         p = fnval;
  7736.         if (fndiags)
  7737.           sprintf(fnval,"<ERROR:MISSING_ARG:\\f%s()>",fn);
  7738.         goto fnend;
  7739.     }
  7740.     if (cx == FN_LIT) {                 /* literal(arg1) */
  7741.         debug(F010,"flit",xp,0);
  7742.         p = xp ? xp : "";               /* Return a pointer to arg itself */
  7743.         goto fnend;
  7744.     }
  7745.  
  7746. #ifdef DEBUG
  7747.     if (deblog) {
  7748.         int j;
  7749.         for (j = 0; j < argn; j++)
  7750.           debug(F111,"fneval arg",argp[j],j);
  7751.     }
  7752. #endif /* DEBUG */
  7753.     for (j = argn-1; j >= 0; j--) {     /* Uncount empty trailing args */
  7754.         if (!argp[j])
  7755.           argn--;
  7756.         else if (!*(argp[j]))
  7757.           argn--;
  7758.         else break;
  7759.     }
  7760.     debug(F111,"fneval argn",fn,argn);
  7761. /*
  7762.   \fliteral() and \fcontents() are special functions that do not evaluate
  7763.   their arguments, and are treated specially here.  After these come the
  7764.   functions whose arguments are evaluated in the normal way.
  7765. */
  7766. #ifdef COMMENT
  7767.     /* (moved up) */
  7768.     if (cx == FN_LIT) {                 /* literal(arg1) */
  7769.         debug(F110,"flit",xp,0);
  7770.         p = xp ? xp : "";               /* Return a pointer to arg itself */
  7771.         goto fnend;
  7772.     }
  7773. #endif /* COMMENT */
  7774.     if (cx == FN_CON) {                 /* Contents of variable, unexpanded. */
  7775.         char c;
  7776.         if (!(p = argp[0]) || !*p) {
  7777.             failed = 1;
  7778.             p = fnval;
  7779.             if (fndiags)
  7780.               sprintf(fnval,"<ERROR:MISSING_ARG:\\fcontents()>");
  7781.             goto fnend;
  7782.         }
  7783.         p = brstrip(p);
  7784.         if (*p == CMDQ) p++;
  7785.         if ((c = *p) == '%') {          /* Scalar variable. */
  7786.             c = *++p;                   /* Get ID character. */
  7787.             p = "";                     /* Assume definition is empty */
  7788.             if (!c) {                   /* Double paranoia */
  7789.                 failed = 1;
  7790.                 p = fnval;
  7791.                 if (fndiags)
  7792.                   sprintf(fnval,"<ERROR:ARG_BAD_VARIABLE:\\fcontents()>");
  7793.                 goto fnend;
  7794.             }
  7795.             if (c >= '0' && c <= '9') { /* Digit for macro arg */
  7796.                 if (maclvl < 0)         /* Digit variables are global */
  7797.                   p = g_var[c];         /* if no macro is active */
  7798.                 else                    /* otherwise */
  7799.                   p = m_arg[maclvl][c - '0']; /* they're on the stack */
  7800.             } else if (c == '*') {
  7801. #ifdef COMMENT
  7802.                 p = (maclvl > -1) ? m_line[maclvl] : topline;
  7803.                 if (!p) p = "";
  7804. #else
  7805.                 int nx = FNVALL;
  7806.                 char * sx = fnval;
  7807.                 p = fnval;
  7808. #ifdef COMMENT
  7809.                 if (cmdsrc() == 0 && topline)
  7810.                   p = topline;
  7811.                 else
  7812. #endif /* COMMENT */
  7813.                   if (zzstring("\\fjoin(&_[],{ },1)",&sx,&nx) < 0) {
  7814.                     failed = 1;
  7815.                     p = fnval;
  7816.                     if (fndiags)
  7817.                       sprintf(fnval,"<ERROR:OVERFLOW:\\fcontents()>");
  7818.             debug(F110,"zzstring fcontents(\\%*)",p,0);
  7819.                 }
  7820. #endif /* COMMENT */
  7821.             } else {
  7822.                 if (isupper(c)) c -= ('a'-'A');
  7823.                 p = g_var[c];           /* Letter for global variable */
  7824.             }
  7825.             if (!p) p = "";
  7826.             goto fnend;
  7827.         } else if (c == '&') {          /* Array reference. */
  7828.             int vbi, d;
  7829.             if (arraynam(p,&vbi,&d) < 0) { /* Get name and subscript */
  7830.                 failed = 1;
  7831.                 p = fnval;
  7832.                 if (fndiags)
  7833.                   sprintf(fnval,"<ERROR:ARG_BAD_ARRAY:\\fcontents()>");
  7834.                 goto fnend;
  7835.             }
  7836.             if (chkarray(vbi,d) > 0) {  /* Array is declared? */
  7837.                 vbi -= ARRAYBASE;       /* Convert name to index */
  7838.                 if (a_dim[vbi] >= d) {  /* If subscript in range */
  7839.                     char **ap;
  7840.                     ap = a_ptr[vbi];    /* get data pointer */
  7841.                     if (ap) {           /* and if there is one */
  7842.                         p = ap[d];
  7843.                         goto fnend;
  7844.                     }
  7845.                 }
  7846.             } else {
  7847.                 failed = 1;
  7848.                 p = fnval;
  7849.                 if (fndiags)
  7850.                   sprintf(fnval,"<ERROR:ARG_NOT_ARRAY:\\fcontents()>");
  7851.                 goto fnend;
  7852.             }
  7853.         } else {
  7854.             failed = 1;
  7855.             p = fnval;
  7856.             if (fndiags)
  7857.               sprintf(fnval,"<ERROR:ARG_NOT_VARIABLE:\\fcontents()>");
  7858.             goto fnend;
  7859.         }
  7860.     }
  7861.     p = fnval;                          /* Default result pointer */
  7862.     fnval[0] = NUL;                     /* Default result = empty string */
  7863.  
  7864.  
  7865.     for (i = 0; i < argn; i++) {        /* Loop to expand each argument */
  7866.         n = MAXARGLEN;                  /* Allow plenty of space */
  7867.         bp[i] = s = malloc(n+1);        /* Allocate space for this argument */
  7868.         if (bp[i] == NULL) {            /* Handle failure to get space */
  7869.             failed = 1;
  7870.             if (fndiags)
  7871.               ckmakmsg(fnval,FNVALL,"<ERROR:MALLOC_FAILURE:\\f",fn,"()>",NULL);
  7872.             goto fnend;
  7873.         }
  7874.         p = argp[i] ? argp[i] : "";     /* Point to this argument */
  7875.  
  7876. /*
  7877.   Trim leading and trailing spaces from the original argument, before
  7878.   evaluation.  This code new to edit 184.  Fixed in edit 199 to trim
  7879.   blanks BEFORE stripping braces.
  7880.  
  7881. */
  7882.         {
  7883.             int x, j;
  7884.             x = strlen(p);
  7885.             j = x - 1;                  /* Trim trailing whitespace */
  7886.             while (j > 0 && (*(p + j) == SP || *(p + j) == HT))
  7887.               *(p + j--) = NUL;
  7888.             while (*p == SP || *p == HT) /* Strip leading whitespace */
  7889.               p++;
  7890.             x = strlen(p);
  7891.             if (*p == '{' && *(p+x-1) == '}') { /* NOW strip braces */
  7892.                 p[x-1] = NUL;
  7893.                 p++;
  7894.                 x -= 2;
  7895.             }
  7896.         }
  7897.  
  7898. /* Now evaluate the argument */
  7899.  
  7900.         debug(F111,"fneval calling zzstring",p,n);
  7901.         t = zzstring(p,&s,&n);          /* Expand arg into new space */
  7902.         debug(F101,"fneval zzstring","",t);
  7903.         debug(F101,"fneval zzstring","",n);
  7904.         if (t < 0) {
  7905.             debug(F101,"fneval zzstring fails, arg","",i);
  7906.             failed = 1;
  7907.             if (fndiags) {
  7908.                 if (n == 0)
  7909.                   ckmakmsg(fnval,FNVALL,
  7910.                            "<ERROR:ARG_TOO_LONG:\\f",fn,"()>",NULL);
  7911.                 else
  7912.                   ckmakmsg(fnval,FNVALL,
  7913.                            "<ERROR:ARG_EVAL_FAILURE:\\f",fn,"()>",NULL);
  7914.             }
  7915.             goto fnend;
  7916.         }
  7917.         debug(F111,"fneval arg",bp[i],i);
  7918.     }
  7919.  
  7920. #ifdef DEBUG
  7921.     if (deblog) {
  7922.         int j;
  7923.         for (j = 0; j < argn; j++) {
  7924.             debug(F111,"fneval arg post eval",argp[j],j);
  7925.             debug(F111,"fneval evaluated arg",bp[j],j);
  7926.         }
  7927.     }
  7928. #endif /* DEBUG */
  7929. /*
  7930.   From this point on, bp[0..argn-1] are not NULL and all must be freed
  7931.   before returning.
  7932. */
  7933.     if (argn < 1) {                     /* Catch required args missing */
  7934.         switch (cx) {
  7935.           case FN_DEF:
  7936.           case FN_EVA:
  7937.           case FN_EXE:
  7938.           case FN_CHR:
  7939.           case FN_COD:
  7940.           case FN_MAX:
  7941.           case FN_MIN:
  7942.           case FN_MOD:
  7943.           case FN_FD:
  7944.           case FN_FS:
  7945.           case FN_TOD:
  7946.           case FN_FFN:
  7947.           case FN_BSN:
  7948.           case FN_RAW:
  7949.           case FN_CMD:
  7950.           case FN_2HEX:
  7951.           case FN_2OCT:
  7952.           case FN_DNAM:
  7953. #ifdef FN_ERRMSG
  7954.           case FN_ERRMSG:
  7955. #endif /* FN_ERRMSG */
  7956. #ifdef CK_KERBEROS
  7957.           case FN_KRB_TK:
  7958.           case FN_KRB_NX:
  7959.           case FN_KRB_IV:
  7960.           case FN_KRB_TT:
  7961.           case FN_KRB_FG:
  7962. #endif /* CK_KERBEROS */
  7963.           case FN_MJD2:
  7964.           case FN_N2TIM:
  7965.           case FN_DIM:
  7966.           case FN_DATEJ:
  7967.           case FN_PNCVT:
  7968.           case FN_PERM:
  7969.           case FN_ALOOK:
  7970.           case FN_TLOOK:
  7971.           case FN_ABS:
  7972.           case FN_AADUMP:
  7973.           case FN_JOIN:
  7974. #ifdef CKFLOAT
  7975.           case FN_FPABS:
  7976.           case FN_FPEXP:
  7977.           case FN_FPLOG:
  7978.           case FN_FPLN:
  7979.           case FN_FPMOD:
  7980.           case FN_FPSQR:
  7981.           case FN_FPADD:
  7982.           case FN_FPDIV:
  7983.           case FN_FPMUL:
  7984.           case FN_FPPOW:
  7985.           case FN_FPSUB:
  7986.           case FN_FPINT:
  7987.           case FN_FPROU:
  7988.           case FN_FPSIN:
  7989.           case FN_FPCOS:
  7990.           case FN_FPTAN:
  7991. #endif /* CKFLOAT */
  7992. #ifdef TCPSOCKET
  7993.           case FN_HSTADD:
  7994.           case FN_HSTNAM:
  7995. #endif /* TCPSOCKET */
  7996.           case FN_DELSEC:
  7997.           case FN_KWVAL:
  7998. #ifdef COMMENT
  7999.           case FN_SLEEP:
  8000.           case FN_MSLEEP:
  8001. #endif /* COMMENT */
  8002. #ifdef NT
  8003.           case FN_SNAME:
  8004.           case FN_LNAME:
  8005. #endif /* NT */
  8006.             failed = 1;
  8007.             p = fnval;
  8008.             if (fndiags)
  8009.               ckmakmsg(fnval,FNVALL,"<ERROR:MISSING_ARG:\\f",fn,"()>",NULL);
  8010.             goto fnend;
  8011.         }
  8012.     }
  8013.     p = fnval;                          /* Reset these again. */
  8014.     fnval[0] = NUL;
  8015.  
  8016.     switch (cx) {                       /* Do function on expanded args. */
  8017. #ifdef TCPSOCKET
  8018.       case FN_HSTADD:
  8019.         p = ckaddr2name(bp[0]);
  8020.         goto fnend;
  8021.       case FN_HSTNAM:
  8022.         p = ckname2addr(bp[0]);
  8023.         goto fnend;
  8024. #endif /* TCPSOCKET */
  8025.  
  8026.       case FN_DEF:                      /* \fdefinition(arg1) */
  8027.         k = isaarray(bp[0]) ?
  8028.         mxxlook(mactab,bp[0],nmac) :
  8029.         mxlook(mactab,bp[0],nmac);
  8030.         p = (k > -1) ? mactab[k].mval : "";
  8031.         goto fnend;
  8032.  
  8033.       case FN_EVA:                      /* \fevaluate(arg1) */
  8034.         p = *(bp[0]) ? evalx(bp[0]) : "";
  8035.         if (!*p && fndiags) {
  8036.             failed = 1;
  8037.             p = fnval;
  8038.             evalerr(fn);
  8039.         }
  8040.         goto fnend;
  8041.  
  8042.       case FN_EXE:                      /* \fexecute(arg1) */
  8043.         j = (int)strlen(s = bp[0]);     /* Length of macro invocation */
  8044.         p = "";                         /* Initialize return value to null */
  8045.         if (j) {                        /* If there is a macro to execute */
  8046.             while (*s == SP) s++,j--;   /* strip leading spaces */
  8047.             p = s;                      /* remember beginning of macro name */
  8048.             for (i = 0; i < j; i++) {   /* find end of macro name */
  8049.                 if (*s == SP)
  8050.                   break;
  8051.                 s++;
  8052.             }
  8053.             if (*s == SP)       {       /* if there was a space after */
  8054.                 *s++ = NUL;             /* terminate the macro name */
  8055.                 while (*s == SP) s++;   /* skip past any extra spaces */
  8056.             } else
  8057.               s = "";                   /* maybe there are no arguments */
  8058.             if (p && *p) {
  8059.                 k = mlook(mactab,p,nmac); /* Look up the macro name */
  8060.                 debug(F111,"fexec mlook",p,k);
  8061.             } else
  8062.               k = -1;
  8063.             if (k < 0) {
  8064.                 char * p2 = p;
  8065.                 failed = 1;
  8066.                 p = fnval;
  8067.                 if (fndiags)
  8068.                   ckmakxmsg(fnval,FNVALL,
  8069.                             "<ERROR:NO_SUCH_MACRO:\\f",fn,"(",p2,")>",
  8070.                             NULL,NULL,NULL,NULL,NULL,NULL,NULL);
  8071.                 goto fnend;
  8072.             }
  8073. /*
  8074.   This is just a WEE bit dangerous because we are copying up to 9 arguments
  8075.   into the space reserved for one.  It won't overrun the buffer, but if there
  8076.   are lots of long arguments we might lose some.  The other problem is that if
  8077.   the macro has more than 3 arguments, the 4th through last are all
  8078.   concatenated onto the third.  (The workaround is to use spaces rather than
  8079.   commas to separate them.)  Leaving it like this to avoid having to allocate
  8080.   tons more buffers.
  8081. */
  8082.             if (argn > 1) {             /* Commas used instead of spaces */
  8083.                 int i;
  8084.                 char *p = bp[0];        /* Reuse this space */
  8085.                 *p = NUL;               /* Make into dodo() arg list */
  8086.                 for (i = 1; i < argn; i++) {
  8087.                     strncat(p,bp[i],MAXARGLEN);
  8088.                     strncat(p," ",MAXARGLEN);
  8089.                 }
  8090.                 s = bp[0];              /* Point to new list */
  8091.             }
  8092.             p = "";                     /* Initialize return value */
  8093.             if (k >= 0) {               /* If macro found in table */
  8094.                 /* Go set it up (like DO cmd) */
  8095.                 if ((j = dodo(k,s,cmdstk[cmdlvl].ccflgs)) > 0) {
  8096.                     if (cmpush() > -1) { /* Push command parser state */
  8097.                         extern int ifc;
  8098.                         int ifcsav = ifc; /* Push IF condition on stack */
  8099.                         k = parser(1);  /* Call parser to execute the macro */
  8100.                         cmpop();        /* Pop command parser */
  8101.                         ifc = ifcsav;   /* Restore IF condition */
  8102.                         if (k == 0) {   /* No errors, ignore action cmds. */
  8103.                             p = mrval[maclvl+1]; /* If OK, set return value. */
  8104.                             if (p == NULL) p = "";
  8105.                         }
  8106.                     } else {            /* Can't push any more */
  8107.                         debug(F100,"zzstring fneval fexec failure","",0);
  8108.                         printf("\n?\\fexec() too deeply nested\n");
  8109.                         while (cmpop() > -1) ;
  8110.                         p = "";
  8111.                     }
  8112.                 }
  8113.             }
  8114.         }
  8115.         debug(F110,"zzstring fneval fexecute final p",p,0);
  8116.         goto fnend;
  8117.  
  8118. #ifdef RECURSIVE
  8119.       case FN_RDIR:                     /* \frdir..() - Recursive dir count */
  8120.       case FN_RFIL:                     /* \frfiles() - Recursive file count */
  8121.         /* recursive = 2; */            /* fall thru... */
  8122. #endif /* RECURSIVE */
  8123.       case FN_FC:                       /* \ffiles() - File count. */
  8124.       case FN_DIR: {                    /* \ffdir.() - Directory count. */
  8125.           char abuf[16], *s;
  8126.           char ** ap = NULL;
  8127.           int x, xflags = 0;
  8128.           if (matchdot)
  8129.             xflags |= ZX_MATCHDOT;
  8130.           if (cx == FN_RDIR || cx == FN_RFIL) {
  8131.               xflags |= ZX_RECURSE;
  8132. #ifdef CKSYMLINK
  8133.               /* Recursive - don't follow symlinks */
  8134.               xflags |= ZX_NOLINKS;
  8135. #endif /* CKSYMLINK */
  8136.           }
  8137.           failed = 0;
  8138.           if (argn < 1) {
  8139.               p = "0";
  8140.               goto fnend;
  8141.           }
  8142.           if (cx == FN_DIR || cx == FN_RDIR) { /* Only list directories */
  8143.               xflags |= ZX_DIRONLY;
  8144. #ifdef OS2
  8145.               zxpn = 1;                 /* Use the alternate list */
  8146. #endif /* OS2 */
  8147.           } else {                      /* List only files */
  8148.               xflags |= ZX_FILONLY;
  8149. #ifdef OS2
  8150.               zxpn = 1;                 /* Use the alternate list */
  8151. #endif /* OS2 */
  8152.           }
  8153.           if (*(bp[0])) {
  8154.               k = nzxpand(bp[0],xflags);
  8155.               if (k < 0) k = 0;
  8156.               sprintf(fnval,"%d",k);    /* SAFE */
  8157.               p = fnval;
  8158.           } else
  8159.             p = "0";
  8160.  
  8161.           if (argn > 1) {               /* Assign list to array */
  8162.               fnval[0] = NUL;           /* Initial return value */
  8163.               ckstrncpy(abuf,bp[1],16); /* Get array reference */
  8164.               s = abuf;
  8165.               if (*s == CMDQ) s++;
  8166.               failed = 1;               /* Assume it's bad */
  8167.               p = fnval;                /* Point to result */
  8168.               if (fndiags)              /* Default is this error message */
  8169.                 ckmakmsg(fnval,FNVALL,
  8170.                          "<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  8171.               if (s[0] != '&')          /* "Address" of array */
  8172.                 goto fnend;
  8173.               if (s[2])
  8174.                 if (s[2] != '[' || s[3] != ']')
  8175.                   goto fnend;
  8176.               if (s[1] >= 64 && s[1] < 91) /* Convert upper to lower */
  8177.                 s[1] += 32;
  8178.               if ((x = dclarray(s[1],k)) < 0) /* File list plus count */
  8179.                 goto fnend;
  8180.               failed = 0;               /* Unset failure flag */
  8181.               ap = a_ptr[x];            /* Point to array we just declared */
  8182.               sprintf(fnval,"%d",k);    /* SAFE */
  8183.           }
  8184. #ifdef OS2
  8185.           if (ap) {                     /* We are making an array */
  8186.               int i;
  8187.               char tmp[16];
  8188.               ap[0] = NULL;             /* Containing number of files    */
  8189.               makestr(&(ap[0]),ckitoa(k));
  8190.  
  8191.               ckstrncpy(tmp,fnval,16);  /* Save return value */
  8192.  
  8193.               for (i = 1; i <= k; i++) { /* Fill it */
  8194.                   ap[i] = NULL;
  8195.                   znext(fnval);         /* Next filename */
  8196.                   if (!*fnval)          /* No more, done */
  8197.                     break;              /* In case a premature end */
  8198.                   makestr(&(ap[i]),fnval);
  8199.               }
  8200. #ifdef ZXREWIND
  8201.               k = zxrewind();           /* Reset the file expansion */
  8202. #else
  8203.               k = nzxpand(bp[0],xflags);
  8204. #endif /* ZXREWIND */
  8205.               ckstrncpy(fnval,tmp,FNVALL); /* Restore return value */
  8206.           }
  8207. #else /* OS2 */
  8208.           {                             /* Make copies of the list */
  8209.               int i; char tmp[16];
  8210.               if (flist) {              /* Free old file list, if any */
  8211.                   for (i = 0; flist[i]; i++) { /* and each string */
  8212.                       free(flist[i]);
  8213.                       flist[i] = NULL;
  8214.                   }
  8215.                   free((char *)flist);
  8216.               }
  8217.               ckstrncpy(tmp,fnval,16);  /* Save our return value */
  8218.               flist = (char **) malloc((k+1) * sizeof(char *)); /* New array */
  8219.               if (flist) {
  8220.                   for (i = 0; i <= k; i++) { /* Fill it */
  8221.                       flist[i] = NULL;
  8222.                       znext(fnval);     /* Next filename */
  8223.                       if (!*fnval)      /* No more, done */
  8224.                         break;
  8225.                       makestr(&(flist[i]),fnval);
  8226.                   }
  8227.                   if (ap) {             /* If array pointer given */
  8228.                       ap[0] = NULL;
  8229.                       makestr(&(ap[0]),ckitoa(k));
  8230.                       for (i = 0; i < k; i++) { /* Copy file list to array */
  8231.                           ap[i+1] = NULL;
  8232.                           makestr(&(ap[i+1]),flist[i]);
  8233.                       }
  8234.                   }
  8235.               }
  8236.               ckstrncpy(fnval,tmp,FNVALL); /* Restore return value */
  8237.               flistn = 0;               /* Reset global list pointer */
  8238.           }
  8239. #endif /* OS2 */
  8240. #ifdef RECURSIVE
  8241.           recursive = rsave;
  8242. #endif /* RECURSIVE */
  8243. #ifdef OS2
  8244.           zxpn = zsave;
  8245. #endif /* OS2 */
  8246.       }
  8247.       goto fnend;
  8248.  
  8249.       case FN_FIL:                      /* \fnextfile() - Next file in list. */
  8250.         p = fnval;                      /* (no args) */
  8251.         *p = NUL;
  8252. #ifdef OS2
  8253.         zxpn = 1;                       /* OS/2 - use the alternate list */
  8254.         znext(p);                       /* Call system-dependent function */
  8255.         zxpn = zsave;                   /* Restore original list */
  8256. #else
  8257.         if (flist)                      /* Others, use our own list. */
  8258.           if (flist[flistn])
  8259.             p = flist[flistn++];
  8260. #endif /* OS2 */
  8261.         goto fnend;
  8262.  
  8263.     } /* Break up big switch... */
  8264.  
  8265.     switch (cx) {
  8266.       case FN_IND:                      /* \findex(s1,s2,start) */
  8267.       case FN_RIX:                      /* \frindex(s1,s2,start) */
  8268.       case FN_SEARCH:                   /* \fsearch(pat,string,start) */
  8269.       case FN_RSEARCH: {                /* \frsearch(pat,string,start) */
  8270.         int i = 0, right = 0, search = 0;
  8271.         right = (cx == FN_RIX || cx == FN_RSEARCH);
  8272.         search = (cx == FN_SEARCH || cx == FN_RSEARCH);
  8273.         p = "0";
  8274.         if (argn > 1) {                 /* Only works if we have 2 or 3 args */
  8275.             int start = 0;
  8276.             char * pat = NULL;
  8277.             len1 = (int)strlen(pat = bp[0]); /* length of string to look for */
  8278.             len2 = (int)strlen(s = bp[1]); /* length of string to look in */
  8279.             if (len1 < 1 || len2 < 1)   /* Watch out for empty strings */
  8280.               goto fnend;
  8281.             start = right ? -1 : 0;     /* Default starting position */
  8282.             if (argn > 2) {
  8283.                 val1 = *(bp[2]) ? evalx(bp[2]) : "1";
  8284.                 if (chknum(val1)) {
  8285.                     int t;
  8286.                     t = atoi(val1);
  8287.                     if (!search) {      /* Index or Rindex */
  8288.                         j = len2 - len1; /* Length difference */
  8289.                         t--;             /* Convert position to 0-based */
  8290.                         if (t < 0) t = 0;
  8291.                         start = t;
  8292.                         if (!right && start < 0) start = 0;
  8293.                     } else {            /* Search or Rsearch */
  8294.                         int x;
  8295.                         if (t < 0) t = 0;
  8296.                         if (right) {    /* Right to left */
  8297.                             if (t > len2) t = len2;
  8298.                             start = len2 - t - 1;
  8299.                             if (start < 0)
  8300.                               goto fnend;
  8301.                             x = len2 - t;
  8302.                             s[x] = NUL;
  8303.                         } else {        /* Left to right */
  8304.                             start = t - 1;
  8305.                             if (start < 0) start = 0;
  8306.                             if (start >= len2)
  8307.                               goto fnend;
  8308.                         }
  8309.                     }
  8310.                 } else {
  8311.                     failed = 1;
  8312.                     evalerr(fn);
  8313.                     p = fnval;
  8314.                     goto fnend;
  8315.                 }
  8316.             }
  8317.             if (search) {               /* \fsearch() or \frsearch() */
  8318.                 if (right && pat[0] == '^') {
  8319.                     right = 0;
  8320.                     start = 0;
  8321.                 }
  8322.                 if (right) {
  8323.                     if (start < 0) start = len2 - 1;
  8324.                     for (i = start;
  8325.                          i >= 0 && !ckmatch(pat,s+i,inpcas[cmdlvl],1+4);
  8326.                          i--) ;
  8327.                     if (i < 0) i = 0; else i++;
  8328.                 } else {
  8329.                     i = ckmatch(pat,&s[start],inpcas[cmdlvl],1+4);
  8330.                     if (start > 0) i += start;
  8331.                 }
  8332.             } else {
  8333.                 i = ckindex(pat,bp[1],start,right,inpcas[cmdlvl]);
  8334.             }
  8335.             sprintf(fnval,"%d",i);      /* SAFE */
  8336.             p = fnval;
  8337.         }
  8338.         goto fnend;
  8339.       }
  8340.  
  8341.       case FN_RPL:                      /* \freplace(s1,s2,s3) */
  8342.       /*
  8343.         s = bp[0] = source string
  8344.             bp[1] = match string
  8345.             bp[2] = replacement string
  8346.             bp[3] = which occurrence (default = all);
  8347.         p = fnval = destination (result) string
  8348.       */
  8349.         if (argn < 1)                   /* Nothing */
  8350.           goto fnend;
  8351.         if (argn < 2) {                 /* Only works if we have 2 or 3 args */
  8352.             ckstrncpy(p,bp[0],FNVALL);
  8353.         } else {
  8354.             int occur = 0, xx = 0, j2;
  8355.             len1 = (int)strlen(bp[0]);  /* length of string to look in */
  8356.             len2 = (int)strlen(bp[1]);  /* length of string to look for */
  8357.             len3 = (argn < 3) ? 0 : (int)strlen(bp[2]); /* Len of replacemnt */
  8358.             j = len1 - len2 + 1;
  8359.             j2 = j;
  8360.             if (argn > 3) {
  8361.                 if (chknum(bp[3])) {
  8362.                     occur = atoi(bp[3]);
  8363.                 } else {
  8364.                     failed = 1;
  8365.                     if (fndiags)
  8366.                       ckmakmsg(fnval,FNVALL,
  8367.                                "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  8368.                     goto fnend;
  8369.                 }
  8370.             }
  8371.             /* If args out of whack... */
  8372.             if (j < 1 || len1 == 0 || len2 == 0) {
  8373.                 ckstrncpy(p,bp[0],FNVALL); /* just return original string */
  8374.                 p[FNVALL] = NUL;
  8375.             } else {
  8376.               ragain:
  8377.                 s = bp[0];              /* Point to beginning of string */
  8378.                 while (j-- > 0) {       /* For each character */
  8379.                     if (!ckstrcmp(bp[1],s,len2,inpcas[cmdlvl]) &&
  8380.                         (occur == 0 || occur == ++xx)) {
  8381.                         if (len3) {
  8382.                             ckstrncpy(p,bp[2],FNVALL);
  8383.                             p += len3;
  8384.                         }
  8385.                         s += len2;      /* and skip past it. */
  8386.                     } else {            /* No, */
  8387.                         *p++ = *s++;    /* just copy this character */
  8388.                     }
  8389.                 }
  8390.                 *p = NUL;
  8391.                 while ((*p++ = *s++));
  8392.                 if (occur < 0) {        /* cheap... */
  8393.                     occur = xx + occur + 1;
  8394.                     xx = 0;
  8395.                     p = fnval;
  8396.                     j = j2;
  8397.                     if (occur > 0)
  8398.                       goto ragain;
  8399.                 }
  8400.             }
  8401.         }
  8402.         p = fnval;
  8403.         goto fnend;
  8404.  
  8405.       case FN_CHR:                      /* \fcharacter(arg1) */
  8406.         val1 = *(bp[0]) ? evalx(bp[0]) : "";
  8407.         if (chknum(val1)) {             /* Must be numeric */
  8408.             i = atoi(val1);
  8409.             if (i >= 0 && i < 256) {    /* Must be an 8-bit value */
  8410.                 p = fnval;
  8411.                 *p++ = (char) i;
  8412.                 *p = NUL;
  8413.                 p = fnval;
  8414.             } else {
  8415.                 failed = 1;
  8416.                 if (fndiags)
  8417.                   ckmakmsg(fnval,FNVALL,
  8418.                            "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  8419.             }
  8420.         } else {
  8421.             failed = 1;
  8422.             evalerr(fn);
  8423.         }
  8424.         goto fnend;
  8425.  
  8426.       case FN_COD:                      /* \fcode(char) */
  8427.         if ((int)strlen(bp[0]) > 0) {
  8428.             p = fnval;
  8429.             i = *bp[0];
  8430.             sprintf(p,"%d",(i & 0xff)); /* SAFE */
  8431.         } else p = "";                  /* Can't happen */
  8432.         goto fnend;
  8433.  
  8434.       case FN_LEN:                      /* \flength(arg1) */
  8435.         if (argn > 0) {
  8436.             p = fnval;
  8437.             sprintf(p,"%d",(int)strlen(bp[0])); /* SAFE */
  8438.         } else p = "0";
  8439.         goto fnend;
  8440.  
  8441.       case FN_LOW:                      /* \flower(arg1) */
  8442.         s = bp[0] ? bp[0] : "";
  8443.         p = fnval;
  8444.         while (*s) {
  8445.             if (isupper(*s))
  8446.               *p = (char) tolower(*s);
  8447.             else
  8448.               *p = *s;
  8449.             p++; s++;
  8450.         }
  8451.         *p = NUL;
  8452.         p = fnval;
  8453.         goto fnend;
  8454.  
  8455.       case FN_MAX:                      /* \fmax(arg1,arg2) */
  8456.       case FN_MIN:                      /* \fmin(arg1,arg2) */
  8457.       case FN_MOD:                      /* \fmod(arg1,arg2) */
  8458.         val1 = *(bp[0]) ? evalx(bp[0]) : "";
  8459. #ifdef COMMENT
  8460.         /* No longer necessary because evalx() no longer overwrites its */
  8461.         /* result every time it's called (2000/09/23). */
  8462.         free(bp[0]);
  8463.         bp[0] = NULL;
  8464. #endif /* COMMENT */
  8465.         if (argn > 1) {
  8466. #ifdef COMMENT
  8467.             /* Ditto... */
  8468.             bp[0] = malloc((int)strlen(val1)+1);
  8469.             if (bp[0])
  8470.               strcpy(bp[0],val1);       /* safe */
  8471.             val1 = bp[0];
  8472. #endif /* COMMENT */
  8473.             val2 = *(bp[1]) ? evalx(bp[1]) : "";
  8474.             if (chknum(val1) && chknum(val2)) {
  8475.                 i = atoi(val1);
  8476.                 j = atoi(val2);
  8477.                 switch (y) {
  8478.                   case FN_MAX:
  8479.                     if (j < i) j = i;
  8480.                     break;
  8481.                   case FN_MIN:
  8482.                     if (j > i) j = i;
  8483.                     break;
  8484.                   case FN_MOD:
  8485.                     if (j == 0) {
  8486.                         failed = 1;
  8487.                         if (fndiags)
  8488.                           ckmakmsg(fnval,FNVALL,
  8489.                                    "<ERROR:DIVIDE_BY_ZERO:\\f",fn,"()>",NULL);
  8490.                         else
  8491.                           fnval[0] = NUL;
  8492.                         goto fnend;
  8493.                     } else
  8494.                       j = i % j;
  8495.                 }
  8496.                 p = fnval;
  8497.                 sprintf(p,"%d",j);      /* SAFE */
  8498.             } else {
  8499.                 failed = 1;
  8500.                 evalerr(fn);
  8501.             }
  8502.         } else p = val1;
  8503.         goto fnend;
  8504.     } /* Break up big switch... */
  8505.  
  8506.     switch (y) {
  8507.       case FN_SUB:                      /* \fsubstr(arg1,arg2,arg3) */
  8508.       case FN_RIG:                      /* \fright(arg1,arg2) */
  8509.       case FN_LEF:                      /* \fleft(arg1,arg2) */
  8510.         if (argn < 1)
  8511.           goto fnend;
  8512.         val1 = "";
  8513.         if (argn > 1)
  8514.           if (*(bp[1]))
  8515.             val1 =  evalx(bp[1]);
  8516. #ifdef COMMENT
  8517.         if (bp[1]) free(bp[1]);         /* Have to copy this */
  8518.         bp[1] = malloc((int)strlen(val1)+1);
  8519.         if (!bp[1]) {
  8520.             failed = 1;
  8521.             if (fndiags) {
  8522.                 p = fnval;
  8523.                 ckmakmsg(fnval,FNVALL,
  8524.                          "<ERROR:MALLOC_FAILURE:\\f",fn,"()>",NULL);
  8525.             }
  8526.             goto fnend;
  8527.         }
  8528.         strcpy(bp[1],val1);             /* safe */
  8529.         val1 = bp[1];
  8530. #endif /* COMMENT */
  8531.         val2 = "";
  8532.         if (argn > 2)
  8533.           if (*(bp[2]))
  8534.             val2 = evalx(bp[2]);
  8535.         if (
  8536.             ((argn > 1) && (int)strlen(val1) && !rdigits(val1)) ||
  8537.             ((cx == FN_SUB) &&
  8538.               ((argn > 2) && (int)strlen(val2) && !rdigits(val2)))
  8539.             ) {
  8540.             failed = 1;
  8541.             evalerr(fn);
  8542.         } else {
  8543.             int lx;
  8544.             p = fnval;                  /* pointer to result */
  8545.             lx = strlen(bp[0]);         /* length of arg1 */
  8546.             if (cx == FN_SUB) {         /* substring */
  8547.                 k = (argn > 2) ? atoi(val2) : MAXARGLEN; /* length */
  8548.                 j = (argn > 1) ? atoi(val1) : 1; /* start pos for substr */
  8549.             } else if (cx == FN_LEF) {  /* left */
  8550.                 k = (argn > 1) ? atoi(val1) : lx;
  8551.                 j = 1;
  8552.             } else {                             /* right */
  8553.                 k = (argn > 1) ? atoi(val1) : lx; /* length */
  8554.                 j = lx - k + 1;                  /* start pos for right */
  8555.                 if (j < 1) j = 1;
  8556.             }
  8557.             if (k > 0 && j <= lx) {              /* if start pos in range */
  8558.                 s = bp[0]+j-1;                   /* point to source string */
  8559.                 for (i = 0; (i < k) && (*p++ = *s++); i++) ;  /* copy */
  8560.             }
  8561.             *p = NUL;                   /* terminate the result */
  8562.             p = fnval;                  /* and point to it. */
  8563.         }
  8564.         goto fnend;
  8565.  
  8566.       case FN_UPP:                      /* \fupper(arg1) */
  8567.         s = bp[0] ? bp[0] : "";
  8568.         p = fnval;
  8569.         while (*s) {
  8570.             if (islower(*s))
  8571.               *p = (char) toupper(*s);
  8572.             else
  8573.               *p = *s;
  8574.             p++; s++;
  8575.         }
  8576.         *p = NUL;
  8577.         p = fnval;
  8578.         goto fnend;
  8579.  
  8580.       case FN_REP:                      /* \frepeat(text,number) */
  8581.         if (argn < 1)
  8582.           goto fnend;
  8583.         val1 = "1";
  8584.         if (argn > 1)
  8585.           if (*(bp[1]))
  8586.             val1 = evalx(bp[1]);
  8587.         if (chknum(val1)) {             /* Repeat count */
  8588.             n = atoi(val1);
  8589.             debug(F111,"SUNDAY frepeat n",val1,n);
  8590.             if (n > 0) {                /* Make n copies */
  8591.                 p = fnval;
  8592.                 *p = '\0';
  8593.                 k = (int)strlen(bp[0]); /* Make sure string has some length */
  8594.                 debug(F111,"SUNDAY frepeat k","",k);
  8595.                 debug(F111,"SUNDAY frepeat FNVALL","",FNVALL);
  8596.                 if (k * n >= FNVALL) {  /* But not too much... */
  8597.                     failed = 1;
  8598.                     if (fndiags)
  8599.                       ckmakmsg(fnval,FNVALL,
  8600.                                "<ERROR:RESULT_TOO_LONG:\\f",fn,"()>",NULL);
  8601.                     else
  8602.                       fnval[0] = NUL;
  8603.                     p = fnval;
  8604.                     goto fnend;
  8605.                 }
  8606.                 if (k > 0) {            /* If there is something to copy */
  8607.                     for (i = 0; i < n; i++) { /* Copy loop */
  8608.                         s = bp[0];
  8609.                         for (j = 0; j < k; j++) {
  8610.                             if ((p - fnval) >= FNVALL)
  8611.                               break;    /* shouldn't happen... */
  8612.                             else
  8613.                               *p++ = *s++;
  8614.                         }
  8615.                     }
  8616.                     *p = NUL;
  8617.                 }
  8618.             }
  8619.         } else {
  8620.             failed = 1;
  8621.             evalerr(fn);
  8622.         }
  8623.         p = fnval;
  8624.         goto fnend;
  8625.  
  8626. #ifndef NOFRILLS
  8627.       case FN_REV:                      /* \freverse() */
  8628.         if (argn < 1)
  8629.           goto fnend;
  8630.         yystring(bp[0],&p);
  8631.         goto fnend;
  8632. #endif /* NOFRILLS */
  8633.  
  8634.       case FN_RPA:                      /* \frpad() and \flpad() */
  8635.       case FN_LPA:
  8636.         if (argn < 1)
  8637.           goto fnend;
  8638.         val1 = "";
  8639.         if (argn > 1)
  8640.           if (*(bp[1]))
  8641.             val1 = evalx(bp[1]);
  8642.         if (argn == 1) {                /* If a number wasn't given */
  8643.             p = fnval;                  /* just return the original string */
  8644.             ckstrncpy(p,bp[0],FNVALL);
  8645.         } else if (argn > 1 &&  !*val1) {
  8646.             failed = 1;
  8647.             evalerr(fn);
  8648.         } else /* if (chknum(val1)) */ { /* Repeat count */
  8649.             char pc;
  8650.             n = atoi(val1);
  8651.             if (n >= 0) {
  8652.                 p = fnval;
  8653.                 k = (int)strlen(bp[0]); /* Length of string to be padded */
  8654.                 if (k >= n) {           /* It's already long enough */
  8655.                     ckstrncpy(p,bp[0],FNVALL);
  8656.                 } else {
  8657.                     if (n + k <= FNVALL) {
  8658.                         pc = (char) ((argn < 3) ? SP : *bp[2]);
  8659.                         if (!pc) pc = SP;
  8660.                         if (cx == FN_RPA) { /* RPAD */
  8661.                             strncpy(p,bp[0],k); /* (leave it like this) */
  8662.                             p[k] = NUL;
  8663.                             p += k;
  8664.                             for (i = k; i < n; i++)
  8665.                               *p++ = pc;
  8666.                         } else {        /* LPAD */
  8667.                             n -= k;
  8668.                             for (i = 0; i < n; i++)
  8669.                               *p++ = pc;
  8670.                             strncpy(p,bp[0],k); /* (leave it like this) */
  8671.                             p[k] = NUL;
  8672.                             p += k;
  8673.                         }
  8674.                     }
  8675.                     *p = NUL;
  8676.                 }
  8677.             }
  8678.         }
  8679.         p = fnval;
  8680.         goto fnend;
  8681.  
  8682. #ifdef ZFCDAT
  8683.       case FN_FD:                       /* \fdate(filename) */
  8684.         p = fnval;
  8685.         s = zfcdat(bp[0]);
  8686.         if (!s) s = "";
  8687.         if (!*s) {
  8688.             failed = 1;
  8689.             if (fndiags)
  8690.               ckmakmsg(fnval,FNVALL,"<ERROR:FILE_NOT_FOUND:\\f",fn,"()>",NULL);
  8691.             goto fnend;
  8692.         }
  8693.         ckstrncpy(fnval,s,FNVALL);
  8694. #endif /* ZFCDAT */
  8695.         goto fnend;
  8696.  
  8697.     } /* Break up big switch... */
  8698.  
  8699.     switch (y) {
  8700.       case FN_FS:                       /* \fsize(filename) */
  8701.         p = fnval;
  8702.         z = zchki(bp[0]);
  8703.         if (z < 0) {
  8704.             failed = 1;
  8705.             if (fndiags) {
  8706.                 if (z == -1)
  8707.                   ckmakmsg(fnval,FNVALL,
  8708.                            "<ERROR:FILE_NOT_FOUND:\\f",fn,"()>",NULL);
  8709.                 else if (z == -2)
  8710.                   ckmakmsg(fnval,FNVALL,
  8711.                            "<ERROR:FILE_NOT_READABLE:\\f",fn,"()>",NULL);
  8712.                 else if (z == -3)
  8713.                   ckmakmsg(fnval,FNVALL,
  8714.                            "<ERROR:FILE_NOT_ACCESSIBLE:\\f",fn,"()>",NULL);
  8715.                 else
  8716.                   ckmakmsg(fnval,FNVALL,
  8717.                            "<ERROR:FILE_ERROR:\\f",fn,"()>",NULL);
  8718.             }
  8719.             goto fnend;
  8720.         }
  8721.         sprintf(fnval,"%ld",z);         /* SAFE */
  8722.         goto fnend;
  8723.  
  8724.       case FN_VER:                      /* \fverify() */
  8725.         p = "0";
  8726.         if (argn > 1) {                 /* Only works if we have 2 or 3 args */
  8727.             int start;
  8728.             char *s2, ch1, ch2;
  8729.             start = 0;
  8730.             if (argn > 2) {             /* Starting position specified */
  8731.                 val1 = *(bp[2]) ? evalx(bp[2]) : "0";
  8732.                 if (chknum(val1)) {
  8733.                     start = atoi(val1) /* - 1 */;
  8734.                     if (start < 0) start = 0;
  8735.                     if (start > (int)strlen(bp[1]))
  8736.                       goto verfin;
  8737.                 } else {
  8738.                     failed = 1;
  8739.                     evalerr(fn);
  8740.                     goto fnend;
  8741.                 }
  8742.             }
  8743.             i = start;
  8744.             p = "0";
  8745.             for (s = bp[1] + start; *s; s++,i++) {
  8746.                 ch1 = *s;
  8747.                 if (!inpcas[cmdlvl]) if (islower(ch1)) ch1 = toupper(ch1);
  8748.                 j = 0;
  8749.                 for (s2 = bp[0]; *s2; s2++) {
  8750.                     ch2 = *s2;
  8751.                     if (!inpcas[cmdlvl]) if (islower(ch2)) ch2 = toupper(ch2);
  8752.                     if (ch1 == ch2) {
  8753.                         j = 1;
  8754.                         break;
  8755.                     }
  8756.                 }
  8757.                 if (j == 0) {
  8758.                     sprintf(fnval,"%d",i+1); /* SAFE */
  8759.                     p = fnval;
  8760.                     break;
  8761.                 }
  8762.             }
  8763.         }
  8764.       verfin:
  8765.         goto fnend;
  8766.  
  8767.       case FN_IPA:                      /* Find and return IP address */
  8768.         if (argn > 0) {                 /* in argument string. */
  8769.             int start = 0;
  8770.             if (argn > 1) {             /* Starting position specified */
  8771.                 if (chknum(bp[1])) {
  8772.                     start = atoi(bp[1]) - 1;
  8773.                     if (start < 0) start = 0;
  8774.                 } else {
  8775.                     failed = 1;
  8776.                     if (fndiags)
  8777.                       ckmakmsg(fnval,FNVALL,
  8778.                                "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  8779.                     goto fnend;
  8780.                 }
  8781.             }
  8782.             p = getip(bp[0]+start);
  8783.         } else p = "";
  8784.         goto fnend;
  8785.  
  8786. #ifdef OS2
  8787.       case FN_CRY:
  8788.         p = "";
  8789.         if (argn > 0) {
  8790.             p = fnval;
  8791.             ckstrncpy(p,bp[0],FNVALL);
  8792.             ck_encrypt(p);
  8793.         }
  8794.         goto fnend;
  8795.  
  8796.       case FN_OOX:
  8797.         p = "";
  8798.         if (argn > 0)
  8799.           p = (char *) ck_oox(bp[0], (argn > 1) ? bp[1] : "");
  8800.         goto fnend;
  8801. #endif /* OS2 */
  8802.  
  8803.       case FN_HEX:                      /* \fhexify(arg1) */
  8804.         if (argn < 1)
  8805.           goto fnend;
  8806.         if ((int)strlen(bp[0]) < (FNVALL / 2)) {
  8807.             s = bp[0];
  8808.             p = fnval;
  8809.             while (*s) {
  8810.                 x = (*s >> 4) & 0x0f;
  8811.                 *p++ = hexdigits[x];
  8812.                 x = *s++ & 0x0f;
  8813.                 *p++ = hexdigits[x];
  8814.             }
  8815.             *p = NUL;
  8816.             p = fnval;
  8817.         }
  8818.         goto fnend;
  8819.  
  8820.       case FN_UNH: {                    /* \funhex(arg1) */
  8821.           int c[2], i;
  8822.           if (argn < 1)
  8823.             goto fnend;
  8824.           if ((int)strlen(bp[0]) < (FNVALL * 2)) {
  8825.               s = bp[0];
  8826.               p = fnval;
  8827.               while (*s) {
  8828.                   for (i = 0; i < 2; i++) {
  8829.                       c[i] = *s++;
  8830.                       if (!c[i]) { p = ""; goto unhexfin; }
  8831.                       if (islower(c[i])) c[i] = toupper(c[i]);
  8832.                       if (c[i] >= '0' && c[i] <= '9') {
  8833.                           c[i] -= 0x30;
  8834.                       } else if (c[i] >= 'A' && c[i] <= 'F') {
  8835.                           c[i] -= 0x37;
  8836.                       } else {
  8837.                           failed = 1;
  8838.                           if (fndiags)
  8839.                             ckmakmsg(fnval,
  8840.                                      FNVALL,
  8841.                                      "<ERROR:ARG_OUT_OF_RANGE:\\f",
  8842.                                      fn,
  8843.                                      "()>",
  8844.                                      NULL
  8845.                                      );
  8846.                           goto fnend;
  8847.                       }
  8848.                   }
  8849.                   *p++ = ((c[0] << 4) & 0xf0) | (c[1] & 0x0f);
  8850.               }
  8851.               *p = NUL;
  8852.               p = fnval;
  8853.           }
  8854.         unhexfin:
  8855.           goto fnend;
  8856.       }
  8857.  
  8858.       case FN_BRK: {                    /* \fbreak() */
  8859.           char * c;                     /* Characters to break on */
  8860.           char c2, s2;
  8861.           int start = 0;
  8862.           int done = 0;
  8863.           if (argn < 1)
  8864.             goto fnend;
  8865.           if (argn > 2) {
  8866.               s = bp[2] ? bp[2] : "0";
  8867.               if (chknum(s)) {
  8868.                   start = atoi(s);
  8869.                   if (start < 0) start = 0;
  8870.                   if (start > (int)strlen(bp[0]))
  8871.                     goto brkfin;
  8872.               } else {
  8873.                   failed = 1;
  8874.                   if (fndiags)
  8875.                     ckmakmsg(fnval,FNVALL,
  8876.                              "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  8877.                   goto fnend;
  8878.               }
  8879.           }
  8880.           s = bp[0] + start;            /* Source pointer */
  8881.  
  8882.           while (*s && !done) {
  8883.               s2 = *s;
  8884.               if (!inpcas[cmdlvl] && islower(s2)) s2 = toupper(s2);
  8885.               c = bp[1] ? bp[1] : "";   /* Character to break on */
  8886.               while (*c) {
  8887.                   c2 = *c;
  8888.                   if (!inpcas[cmdlvl] && islower(c2)) c2 = toupper(c2);
  8889.                   if (c2 == s2) {
  8890.                       done = 1;
  8891.                       break;
  8892.                   }
  8893.                   c++;
  8894.               }
  8895.               if (done) break;
  8896.               *p++ = *s++;
  8897.           }
  8898.           *p = NUL;                     /* terminate the result */
  8899.           p = fnval;                    /* and point to it. */
  8900.         brkfin:
  8901.           goto fnend;
  8902.       }
  8903.  
  8904.       case FN_SPN: {                    /* \fspan() */
  8905.           char *q;
  8906.           char c1, c2;
  8907.           int start = 0;
  8908.           if (argn < 1)
  8909.             goto fnend;
  8910.           if (argn > 2) {               /* Starting position */
  8911.               s = bp[2] ? bp[2] : "0";
  8912.               if (chknum(s)) {
  8913.                   start = atoi(s);
  8914.                   if (start < 0) start = 0;
  8915.               } else {
  8916.                   failed = 1;
  8917.                   if (fndiags)
  8918.                     ckmakmsg(fnval,FNVALL,
  8919.                              "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  8920.                   goto fnend;
  8921.               }
  8922.           }
  8923.           s = bp[0] + start;            /* Source pointer */
  8924.           if (argn > 1 &&
  8925.               (int)strlen(bp[1]) > 0 &&
  8926.               start <= (int)strlen(bp[0])) {
  8927.               while (*s) {              /* Loop thru source string */
  8928.                   q = bp[1];            /* Span string */
  8929.                   c1 = *s;
  8930.                   if (!inpcas[cmdlvl])
  8931.                     if (islower(c1)) c1 = toupper(c1);
  8932.                   x = 0;
  8933.                   while ((c2 = *q++)) {
  8934.                       if (!inpcas[cmdlvl])
  8935.                         if (islower(c2)) c2 = toupper(c2);
  8936.                       if (c1 == c2) { x = 1; break; }
  8937.                   }
  8938.                   if (!x) break;
  8939.                   *p++ = *s++;
  8940.               }
  8941.               *p = NUL;                 /* Terminate and return the result */
  8942.               p = fnval;
  8943.           }
  8944.           goto fnend;
  8945.       }
  8946.     } /* Break up big switch... */
  8947.  
  8948.     switch (y) {
  8949.       case FN_TRM:                      /* \ftrim(s1[,s2]) */
  8950.       case FN_LTR:                      /* \fltrim(s1[,s2]) */
  8951.         if (argn < 1)
  8952.           goto fnend;
  8953.         if ((len1 = (int)strlen(bp[0])) > 0) {
  8954.             if (len1 > FNVALL)
  8955.               len1 = FNVALL;
  8956.             s = " \t\r\n";
  8957.             if (argn > 1)               /* Trim list given */
  8958.               s = bp[1];
  8959.             len2 = (int)strlen(s);
  8960.             if (len2 < 1) {             /* or not... */
  8961.                 s = " \t\r\n";          /* Default is to trim whitespace */
  8962.                 len2 = 2;
  8963.             }
  8964.             if (cx == FN_TRM) {         /* Trim from right */
  8965.                 char * q, p2, q2;
  8966.                 ckstrncpy(fnval,bp[0],FNVALL); /* Copy string to output */
  8967.                 p = fnval + len1 - 1;   /* Point to last character */
  8968.  
  8969.                 while (p >= (char *)fnval) { /* Go backwards */
  8970.                     q = s;              /* Point to trim list */
  8971.                     p2 = *p;
  8972.                     if (!inpcas[cmdlvl])
  8973.                       if (islower(p2)) p2 = toupper(p2);
  8974.                     while (*q) {        /* Is this char in trim list? */
  8975.                         q2 = *q;
  8976.                         if (!inpcas[cmdlvl])
  8977.                           if (islower(q2)) q2 = toupper(q2);
  8978.                         if (p2 == q2) { /* Yes, null it out */
  8979.                             *p = NUL;
  8980.                             break;
  8981.                         }
  8982.                         q++;
  8983.                     }
  8984.                     if (!*q)            /* Trim list exhausted */
  8985.                       break;            /* So we're done. */
  8986.                     p--;                /* Else keep trimming */
  8987.                 }
  8988.             } else {                    /* Trim from left */
  8989.                 char * q, p2, q2;
  8990.                 p = bp[0];              /* Source */
  8991.                 while (*p) {
  8992.                     p2 = *p;
  8993.                     if (!inpcas[cmdlvl])
  8994.                       if (islower(p2)) p2 = toupper(p2);
  8995.                     q = s;
  8996.                     while (*q) {        /* Is this char in trim list? */
  8997.                         q2 = *q;
  8998.                         if (!inpcas[cmdlvl])
  8999.                           if (islower(q2)) q2 = toupper(q2);
  9000.                         if (p2 == q2) { /* Yes, point past it */
  9001.                             p++;        /* and try next source character */
  9002.                             break;
  9003.                         }
  9004.                         q++;            /* No, try next trim character */
  9005.                     }
  9006.                     if (!*q)            /* Trim list exhausted */
  9007.                       break;            /* So we're done. */
  9008.                 }
  9009.                 ckstrncpy(fnval,p,FNVALL);
  9010.             }
  9011.             p = fnval;
  9012.         } else p = "";
  9013.         goto fnend;
  9014.  
  9015.       case FN_CAP:                      /* \fcapitalize(arg1) */
  9016.         if (argn < 1)
  9017.           goto fnend;
  9018.         s = bp[0];
  9019.         p = fnval;
  9020.         x = 0;
  9021.         while ((c = *s++)) {
  9022.             if (isalpha(c)) {
  9023.                 if (x == 0) {
  9024.                     x = 1;
  9025.                     if (islower(c))
  9026.                       c = toupper(c);
  9027.                 } else if (isupper(c))
  9028.                   c = tolower(c);
  9029.             }
  9030.             *p++ = c;
  9031.         }
  9032.         *p = NUL;
  9033.         p = fnval;
  9034.         goto fnend;
  9035.  
  9036. #ifdef COMMENT
  9037.       case FN_TOD:                      /* Time of day to secs since midnite */
  9038.         sprintf(fnval,"%ld",tod2sec(bp[0])); /* SAFE */
  9039.         goto fnend;
  9040. #endif /* COMMENT */
  9041.  
  9042.       case FN_FFN:                      /* Full pathname of file */
  9043.         zfnqfp(bp[0],FNVALL,p);
  9044.         if (!p) p = "";
  9045.         goto fnend;
  9046.  
  9047.       case FN_CHK: {                    /* \fchecksum() */
  9048.           long chk = 0;
  9049.           p = (argn > 0) ? bp[0] : "";
  9050.           while (*p) chk += *p++;
  9051.           sprintf(fnval,"%lu",chk);     /* SAFE */
  9052.           p = fnval;
  9053.           goto fnend;
  9054.       }
  9055.  
  9056. #ifndef NOXFER
  9057.       case FN_CRC:                      /* \fcrc16() */
  9058.         if (argn > 0)
  9059.           sprintf(fnval,"%u",           /* SAFE */
  9060.                   chk3((CHAR *)bp[0],(int)strlen(bp[0])));
  9061.         else
  9062.           p = "0";
  9063.         goto fnend;
  9064. #endif /* NOXFER */
  9065.  
  9066.       case FN_BSN:                      /* \fbasename() */
  9067.         zstrip(bp[0],&p);
  9068.         goto fnend;
  9069.  
  9070. #ifndef NOLOCAL
  9071. #ifdef OS2
  9072.       case FN_SCRN_CX:                  /* \fscrncurx() */
  9073.         p = fnval;
  9074.         sprintf(p,"%d",(int)VscrnGetCurPos(VTERM)->x); /* SAFE */
  9075.         goto fnend;
  9076.  
  9077.       case FN_SCRN_CY:                  /* \fscrncury() */
  9078.         p = fnval;
  9079.         sprintf(p,"%d",(int)VscrnGetCurPos(VTERM)->y); /* SAFE */
  9080.         goto fnend;
  9081.  
  9082.       case FN_SCRN_STR: {               /* \fscrnstr() */
  9083.           videoline * line = NULL;
  9084.           viocell * cells = NULL;
  9085.           int row = 0, col = 0, len = 0;
  9086.           /* NOTE: On Unicode systems, the screen contents are stored in */
  9087.           /* in Unicode.  Therefore, we should really be performing a    */
  9088.           /* conversion to the local character set.                      */
  9089.  
  9090.           /* 6/18/2000 - added the translation to lcs */
  9091.  
  9092.           if (bp[0] == NULL || bp[0][0] == '\0') {
  9093.               row = 0;
  9094.           } else {
  9095.               if (chknum(bp[0])) {
  9096.                   row = atoi(bp[0]);
  9097.                   if (row < 0)
  9098.                     row = 0;
  9099.               } else {
  9100.                   failed = 1;
  9101.                   if (fndiags)
  9102.                     ckmakmsg(fnval,FNVALL,
  9103.                              "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9104.                   goto fnend;
  9105.               }
  9106.           }
  9107.           line = VscrnGetLineFromTop( VTERM, (USHORT) row );
  9108.           if (line != NULL) {
  9109.               if (bp[1] == NULL || bp[1][0] == '\0')
  9110.                 col = 0;
  9111.               else {
  9112.                   if (chknum(bp[0])) {
  9113.                       col = atoi(bp[1]);
  9114.                       if (col < 0 || col >= line->width)
  9115.                         col = 0;
  9116.                   } else {
  9117.                       failed = 1;
  9118.                       if (fndiags)
  9119.                         ckmakmsg(fnval,FNVALL,
  9120.                                  "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9121.                       goto fnend;
  9122.                   }
  9123.               }
  9124.               if (bp[2] == NULL || bp[2][0] == '\0') {
  9125.                   len = line->width - (col+1);
  9126.               } else {
  9127.                   if (!chknum(bp[2])) {
  9128.                       failed = 1;
  9129.                       if (fndiags)
  9130.                         ckmakmsg(fnval,FNVALL,
  9131.                                  "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9132.                       goto fnend;
  9133.                   }
  9134.                   len = atoi(bp[2]);
  9135.                   if (len < 0 || len > line->width)
  9136.                     len = line->width;
  9137.               }
  9138.               cells = line->cells;
  9139.               for (i = 0; i < len; i++) {
  9140.                   int pos = i + col;
  9141.                   if (pos < line->width) {
  9142.                       if (isunicode())
  9143.                         fnval[i] = (CHAR) utolxlat(cells[pos].c);
  9144.                       else
  9145.                         fnval[i] = (CHAR) (cells[pos].c & 0xFF);
  9146.                       if (fnval[i] == 0)
  9147.                         fnval[i] = SP;
  9148.                   } else
  9149.                     fnval[i] = SP;
  9150.               }
  9151.               fnval[i] = '\0';
  9152.           } else {
  9153.               fnval[0] = '\0';
  9154.           }
  9155.           p = fnval;
  9156.           goto fnend;
  9157.       }
  9158. #endif /* OS2 */
  9159. #endif /* NOLOCAL */
  9160.  
  9161. #ifndef NOPUSH
  9162.       case FN_RAW:                      /* \frawcommand() */
  9163.       case FN_CMD: {                    /* \fcommand() */
  9164.           int x, c, n = FNVALL;
  9165.           x = 0;                        /* Completion flag */
  9166. /*
  9167.   ZIFILE can be safely used because we can't possibly be transferring a file
  9168.   while executing this function.
  9169. */
  9170.           if (!nopush && zxcmd(ZIFILE,bp[0]) > 0) { /* Open the command */
  9171.               while (n-- > -1) {        /* Read from it */
  9172.                   if ((c = zminchar()) < 0) {
  9173.                       x = 1;             /* EOF - set completion flag */
  9174.                       if (cx == FN_CMD) { /* If not "rawcommand" */
  9175.                           p--;           /* remove trailing newlines */
  9176.                           while (*p == CR || *p == LF)
  9177.                             p--;
  9178.                           p++;
  9179.                       }
  9180.                       *p = NUL;         /* Terminate the string */
  9181.                       break;
  9182.                   } else                /* Command still running */
  9183.                     *p++ = c;           /* Copy the bytes */
  9184.               }
  9185.               zclose(ZIFILE);           /* Close the command */
  9186.           }
  9187.           /* Return null string if command's output was too long. */
  9188.           p = fnval;
  9189.           if (!x) {
  9190.               failed = 1;
  9191.               if (fndiags)
  9192.                 ckmakmsg(fnval,FNVALL,
  9193.                          "<ERROR:RESULT_TOO_LONG:\\f",fn,"()>",NULL);
  9194.           }
  9195.           goto fnend;
  9196.       }
  9197. #endif /* NOPUSH */
  9198.     } /* Break up big switch... */
  9199.  
  9200.     switch (y) {
  9201.       case FN_STX:                      /* \fstripx(string,c) */
  9202.         if (!(s = bp[0]))               /* Make sure there is a string */
  9203.           goto fnend;
  9204.         c = '.';                        /* Character to strip from */
  9205.         if (argn > 1) if (*bp[1]) c = *bp[1];
  9206.         n = ckstrncpy(fnval,bp[0],FNVALL);
  9207.         while (--n >= 0) {
  9208.             if (fnval[n] == c) {
  9209.                 fnval[n] = NUL;
  9210.                 break;
  9211.             }
  9212.         }
  9213.         p = fnval;
  9214.         goto fnend;
  9215.  
  9216.       case FN_STL:                      /* \flop(string,c) */
  9217.         if (!(s = bp[0]))               /* Make sure there is a string */
  9218.           goto fnend;
  9219.         c = '.';                        /* Character to strip to */
  9220.         if (argn > 1) if (*bp[1]) c = *bp[1];
  9221.         x = 0;
  9222.         while (*s++) {
  9223.             if (*(s-1) == c) {
  9224.                 x = 1;
  9225.                 break;
  9226.             }
  9227.         }
  9228.         if (!x) s = bp[0];
  9229.         ckstrncpy(fnval,s,FNVALL);
  9230.         p = fnval;
  9231.         goto fnend;
  9232.  
  9233.       case FN_STN:                      /* \fstripn(string,n) */
  9234.         if (argn < 1)                   /* Remove n chars from right */
  9235.           goto fnend;
  9236.         val1 = "0";
  9237.         if (argn > 1)
  9238.           if (*(bp[1]))
  9239.             val1 = evalx(bp[1]);
  9240.         if (!chknum(val1)) {
  9241.             failed = 1;
  9242.             evalerr(fn);
  9243.             goto fnend;
  9244.         }
  9245.         n = atoi(val1);
  9246.         if (n < 0) n = 0;
  9247.         k = (int)strlen(s = bp[0]) - n;
  9248.         if (k < 0) k = 0;
  9249.         p = fnval;
  9250.         while (k-- > 0)
  9251.           *p++ = *s++;
  9252.         *p = NUL;
  9253.         p = fnval;
  9254.         goto fnend;
  9255.  
  9256.       case FN_STB: {                    /* \fstripb(string,c) */
  9257.           char c2 = NUL;
  9258.           int i, k = 0;
  9259.           char * gr_opn = "\"{'([<";    /* Group open brackets */
  9260.           char * gr_cls = "\"}')]>";    /* Group close brackets */
  9261.  
  9262.           p = fnval;
  9263.           *p = NUL;
  9264.           if (!(s = bp[0]))             /* Make sure there is a string */
  9265.             goto fnend;
  9266.           if ((x = strlen(s)) < 1)
  9267.             goto fnend;
  9268.           c = NUL;                      /* Brace/bracket kind */
  9269.           if (argn > 1) {
  9270.               if (*bp[1]) {
  9271.                   if (chknum(bp[1])) {
  9272.                       k = atoi(bp[1]);
  9273.                       if (k < 0) k = 63;
  9274.                       for (i = 0; i < 6; i++) {
  9275.                           if (k & (1<<i)) {
  9276.                               if (s[0] == gr_opn[i] && s[x-1] == gr_cls[i]) {
  9277.                                   ckstrncpy(fnval,s+1,FNVALL);
  9278.                                   fnval[x-2] = NUL;
  9279.                                   goto fnend;
  9280.                               }
  9281.                           }
  9282.                       }
  9283.                       ckstrncpy(fnval,s,FNVALL); /* No match */
  9284.                       goto fnend;
  9285.                   }
  9286.               }
  9287.           }
  9288.           c = *bp[1];
  9289.           if (!c) c = s[0];
  9290.           if (argn > 2) if (*bp[2]) c2 = *bp[2];
  9291.           if (*s == c) {
  9292.               if (!c2) {
  9293.                   switch (c) {
  9294.                     case '(': c2 = ')'; break;
  9295.                     case '[': c2 = ']'; break;
  9296.                     case '{': c2 = '}'; break;
  9297.                     case '<': c2 = '>'; break;
  9298.                     case '"': c2 = '"'; break;
  9299.                     case 39:  c2 = 39;  break;
  9300.                     case 96:  c2 = 39;  break;
  9301.                     default:
  9302.                       if (argn == 2) {
  9303.                           c2 = c;
  9304.                       } else {
  9305.                           strncpy(fnval,s,x); /* Leave it like this */
  9306.                           fnval[x] = NUL;
  9307.                           goto fnend;
  9308.                       }
  9309.                   }
  9310.               }
  9311.               if (s[x-1] == c2) {
  9312.                   strncpy(fnval,s+1,x-2); /* Leave it like this */
  9313.                   fnval[x-2] = NUL;
  9314.                   goto fnend;
  9315.               }
  9316.           }
  9317.           strncpy(fnval,s,x);
  9318.           fnval[x] = NUL;
  9319.           goto fnend;
  9320.       }
  9321.  
  9322.       case FN_2HEX:                     /* Number to hex */
  9323.       case FN_2OCT:                     /* Number to octal */
  9324.         val1 = evalx(bp[0]);
  9325.         if (!*val1) {
  9326.             failed = 1;
  9327.             evalerr(fn);
  9328.             goto fnend;
  9329.         }
  9330.         sprintf(fnval, cx == FN_2HEX ? "%lx" : "%lo", atol(val1)); /* SAFE */
  9331.         if (cx == FN_2HEX && (int)(strlen(fnval)&1))
  9332.           sprintf(fnval,"0%lx",atol(val1)); /* SAFE */
  9333.         p = fnval;
  9334.         goto fnend;
  9335.  
  9336.       case FN_DNAM: {                   /* Directory part of file name */
  9337.           char *s;
  9338.           zfnqfp(bp[0],FNVALL,p);       /* Get full name */
  9339.           if (!isdir(p)) {              /* Is it already a directory? */
  9340.               zstrip(p,&s);             /* No get basename */
  9341.               if (*s) {
  9342.                   x = ckindex(s,p,0,0,0); /* Pos of latter in former */
  9343.                   if (x > 0) p[x-1] = NUL;
  9344.               }
  9345.           }
  9346.           if (!p) p = "";
  9347.           goto fnend;
  9348.       }
  9349.  
  9350. #ifndef NORANDOM
  9351.       case FN_RAND:                     /* Random number */
  9352. #ifdef CK_SSL
  9353.         if (RAND_bytes((unsigned char *)&k,sizeof(k)) < 0)
  9354. #endif /* CK_SSL */
  9355.           k = rand();
  9356.         x = 0;
  9357.         if (argn > 0) {
  9358.             if (!chknum(bp[0])) {
  9359.                 failed = 1;
  9360.                 if (fndiags)
  9361.                   ckmakmsg(fnval,FNVALL,
  9362.                            "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9363.                 goto fnend;
  9364.             }
  9365.             x = atoi(bp[0]);
  9366.         }
  9367. #ifdef COMMENT
  9368.         sprintf(fnval,"%d", (x > 0 && k > 0) || (x < 0 && k < 0) ? k % x : 
  9369.                 (x == 0 ? 0 : (0 - (k % (-x)))));
  9370. #else
  9371.         debug(F111,"rand",ckitoa(x),k);
  9372. #ifdef SUNOS4
  9373. /* This is really strange but on SunOS, if we are requesting random numbers */
  9374. /* between 0 and 4 or less, they always come out in sequence: 0 1 2 3 0 1 2 */
  9375. /* Shifting the result of rand() in this case gives a more random result.   */
  9376.         if (x < 5)
  9377.           k = k >> 5;
  9378. #endif /* SUNOS4 */
  9379.         if ((x > 0 && k > 0) || (x < 0 && k < 0))
  9380.           x = k % x;
  9381.         else if (x == 0)
  9382.           x = 0;
  9383.         else
  9384.           x = 0 - (k % (-x));
  9385.         debug(F101,"rand x","",x);
  9386.         sprintf(fnval,"%d", x);         /* SAFE */
  9387. #endif /* COMMENT */
  9388.         p = fnval;
  9389.         goto fnend;
  9390. #endif /* NORANDOM */
  9391.     } /* Break up big switch... */
  9392.  
  9393.     switch (y) {
  9394.       case FN_SPLIT:                    /* \fsplit(s1,a,s2,s3,mask) */
  9395.       case FN_WORD: {                   /* \fword(s1,n,s2,s3,mask) */
  9396.           int wordnum = 0;
  9397.           int splitting = 0;
  9398.           int x;
  9399.           int array = 0;
  9400.           int grouping = 0;
  9401.           int nocollapse = 0;
  9402.           char * sep = "";
  9403.           char * notsep = "";
  9404.           char * bp0 = NULL;
  9405.           char * bp1 = NULL;
  9406.           char   abuf[16];
  9407.           struct stringarray * q = NULL;
  9408.  
  9409.           splitting = (cx == FN_SPLIT); /* Our job */
  9410.  
  9411.           fnval[0] = splitting ? '0' : NUL; /* Initial return value */
  9412.           fnval[1] = NUL;
  9413.           p = fnval;
  9414.           bp0 = bp[0];                  /* Source string */
  9415.           if (!bp0) bp0 = "";
  9416.           debug(F111,"fsplit bp[0]",bp0,argn);
  9417.           if (argn < 1 || !*bp0)        /* If none, return default value */
  9418.             goto fnend;
  9419.  
  9420.           bp1 = bp[1];                  /* Function-dependent arg */
  9421.           if (!bp1) bp1 = "";           /* (array or number) */
  9422.           debug(F110,"fsplit bp[1]",bp1,0);
  9423.           if (bp[5]) {
  9424.               if (!chknum(bp[5])) {
  9425.                   failed = 1;
  9426.                   ckmakmsg(fnval,FNVALL,
  9427.                            "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9428.                   goto fnend;
  9429.               }
  9430.               x = atoi(bp[5]);
  9431.               nocollapse = x;
  9432.           }
  9433.           if (!splitting) {             /* \fword(): n = desired word number */
  9434.               val1 = "1";               /* Default is first word */
  9435.               if (argn > 1)             /* Word number supplied */
  9436.                 if (*bp1)
  9437.                   val1 = evalx(bp1);
  9438.               if (!chknum(val1)) {
  9439.                   failed = 1;
  9440.                   ckmakmsg(fnval,FNVALL,
  9441.                            "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9442.                   goto fnend;
  9443.               }
  9444.               n = atoi(val1);
  9445.           } else if (argn > 1 && *bp1) { /* \fsplit(): n = word count */
  9446.               ckstrncpy(abuf,bp1,16);   /* Get array reference */
  9447.               debug(F110,"fsplit abuf 1",abuf,0);
  9448.               failed = 1;               /* Assume it's bad */
  9449.               if (fndiags)              /* Default is this error message */
  9450.                 ckmakmsg(fnval,FNVALL,
  9451.                          "<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  9452.               if (abuf[0] != '&')       /* "Address" of array */
  9453.                 goto fnend;             /* It's bad */
  9454.               if (abuf[2]) {            /* Check for brackets */
  9455.                   if (abuf[2] != '[' || abuf[3] != ']') {
  9456.                       goto fnend;       /* Bad */
  9457.                   }
  9458.               }
  9459.               debug(F110,"fsplit abuf 2",abuf,0);
  9460.               if (abuf[1] > 64 && abuf[1] < 91) /* Convert upper to lower */
  9461.                 abuf[1] += 32;
  9462.               if (abuf[1] < 97 || abuf[1] > 122) { /* Check for a-z */
  9463.                   goto fnend;
  9464.               }
  9465.               debug(F110,"fsplit abuf 3",abuf,0);
  9466.               array = 1;
  9467.               fnval[0] = NUL;           /* No error, erase message */
  9468.               failed = 0;               /* Unset failure flag */
  9469.               n = 0;                    /* Initialize word counter */
  9470.           }
  9471.           if (argn > 2)                 /* Have break set? */
  9472.             sep = bp[2];
  9473.           debug(F111,"fsplit sep",sep,argn);
  9474.           if (argn > 3)                 /* Have include set? */
  9475.             notsep = bp[3];
  9476.           debug(F111,"fsplit notsep",notsep,argn);
  9477.           if (argn > 4) {               /* Have grouping set? */
  9478.               char * bp4 = bp[4];
  9479.               debug(F111,"fsplit bp4",bp4,argn);
  9480.               if (!bp4) bp4 = "0";
  9481.               if (!*bp4) bp4 = "0";
  9482.               if (chknum(bp4)) {
  9483.                   grouping = atoi(bp4);
  9484.                   if (grouping == -1)
  9485.                     grouping = 127;
  9486.               } else {
  9487.                   failed = 1;
  9488.                   if (fndiags)
  9489.                     ckmakmsg(fnval,FNVALL,
  9490.                              "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9491.                   goto fnend;
  9492.               }
  9493.           }
  9494.           /* Args parsed, now do the work */
  9495.  
  9496.           debug(F111,"fsplit bp0",bp0,n);
  9497.           q = cksplit(splitting,n,bp0,sep,notsep,grouping,0,nocollapse);
  9498.  
  9499.           wordnum = q ? q->a_size : -1; /* Check result */
  9500.           if (wordnum < 0) {
  9501.               failed = 1;               /* Failure */
  9502.               if (fndiags)
  9503.                 ckmakmsg(fnval,FNVALL,
  9504.                          (wordnum == -1) ?
  9505.                          "<ERROR:MALLOC_FAILURE:\\f" :
  9506.                          "<ERROR:TOO_MANY_WORDS:\\f",
  9507.                          fn,
  9508.                          "()>",
  9509.                          NULL
  9510.                          );
  9511.               goto fnend;
  9512.           }
  9513.           if (splitting) {              /* \fsplit() result */
  9514.               ckstrncpy(fnval,ckitoa(wordnum),FNVALL);
  9515.               if (array) {              /* Array was not declared. */
  9516.                   int i;
  9517.                   if ((x = dclarray(abuf[1],wordnum)) < 0) { /* Declare it. */
  9518.                       failed = 1;
  9519.                       if (fndiags)
  9520.                         ckmakmsg(fnval,FNVALL,
  9521.                                  "<ERROR:MALLOC_FAILURE:\\f",fn,"()>",NULL);
  9522.                       goto fnend;
  9523.                   }
  9524.                   for (i = 1; i <= wordnum; i++) { /* Copy results */
  9525.                       makestr(&(a_ptr[x][i]),q->a_head[i]);
  9526.                   }
  9527.                   a_ptr[x][0] = NULL;   /* Array is 1-based */
  9528.                   makestr(&(a_ptr[x][0]),fnval); /* Element = size */
  9529.               }
  9530.           } else {                      /* \fword() result */
  9531.               char * s;
  9532.               s = q->a_head[1];
  9533.               if (!s) s = "";
  9534.               ckstrncpy(fnval,s,FNVALL);
  9535.           }
  9536.           goto fnend;                   /* Done */
  9537.       }
  9538.  
  9539.     } /* Break up big switch... */
  9540.  
  9541.     switch (y) {
  9542.  
  9543. #ifdef CK_KERBEROS
  9544.       case FN_KRB_TK:                   /* Kerberos tickets */
  9545.       case FN_KRB_NX:                   /* Kerberos next ticket */
  9546.       case FN_KRB_IV:                   /* Kerberos ticket is valid */
  9547.       case FN_KRB_FG:                   /* Kerberos Ticket flags */
  9548.       case FN_KRB_TT: {                 /* Kerberos ticket time */
  9549.           int kv = 0;                   /* Kerberos version */
  9550.           int n = 0;
  9551.           char * s = NULL;
  9552.           if (rdigits(bp[0])) {
  9553.               kv = atoi(bp[0]);
  9554.           } else {
  9555.               failed = 1;
  9556.               if (fndiags)
  9557.                 ckmakmsg(fnval,FNVALL,
  9558.                          "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9559.               goto fnend;
  9560.           }
  9561.           if (kv != 4 && kv != 5) {
  9562.               failed = 1;
  9563.               if (fndiags)
  9564.                 ckmakmsg(fnval,FNVALL,
  9565.                          "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  9566.               goto fnend;
  9567.           }
  9568.           if ((cx == FN_KRB_IV || cx == FN_KRB_TT || cx == FN_KRB_FG) &&
  9569.                argn < 2) {
  9570.               failed = 1;
  9571.               if (fndiags)
  9572.                 ckmakmsg(fnval,FNVALL,"<ERROR:MISSING_ARG:\\f",fn,"()>",NULL);
  9573.               goto fnend;
  9574.           }
  9575.           switch (y) {
  9576.             case FN_KRB_TK:             /* Number of Kerberos tickets */
  9577. #ifdef CK_AUTHENTICATION
  9578.               switch (kv) {
  9579.                 case 4:
  9580.                   n = ck_krb4_get_tkts();
  9581.                   sprintf(fnval, "%d", (n >= 0) ? n : 0); /* SAFE */
  9582.                   goto fnend;
  9583.                 case 5: {
  9584.                     extern char * krb5_d_cc;
  9585.                     n = ck_krb5_get_tkts(krb5_d_cc);
  9586.                     sprintf(fnval, "%d", (n >= 0) ? n : 0); /* SAFE */
  9587.                     goto fnend;
  9588.                 }
  9589.               }
  9590. #else
  9591.               sprintf(fnval,"%d",0);    /* SAFE */
  9592. #endif /* CK_AUTHENTICATION */
  9593.               goto fnend;
  9594.  
  9595.             case FN_KRB_NX:             /* Kerberos next ticket */
  9596. #ifdef CK_AUTHENTICATION
  9597.               switch (kv) {
  9598.                 case 4:
  9599.                   s = ck_krb4_get_next_tkt();
  9600.                   ckstrncpy(fnval, s ? s : "",FNVALL);
  9601.                   goto fnend;
  9602.                 case 5:
  9603.                   s = ck_krb5_get_next_tkt();
  9604.                   ckstrncpy(fnval, s ? s : "",FNVALL);
  9605.                   goto fnend;
  9606.               }
  9607. #else
  9608.               sprintf(fnval,"k%d next-ticket-string",kv); /* SAFE */
  9609. #endif /* CK_AUTHENTICATION */
  9610.               goto fnend;
  9611.  
  9612.             case FN_KRB_IV:             /* Kerberos ticket is valid */
  9613. #ifdef CK_AUTHENTICATION
  9614.               /* Return 1 if valid, 0 if not */
  9615.               switch (kv) {
  9616.                 case 4:
  9617.                   n = ck_krb4_tkt_isvalid(bp[1]);
  9618.                   sprintf(fnval, "%d", n > 0 ? 1 : 0); /* SAVE */
  9619.                   goto fnend;
  9620.                 case 5: {
  9621.                     extern char * krb5_d_cc;
  9622.                     n = ck_krb5_tkt_isvalid(krb5_d_cc,bp[1]);
  9623.                     sprintf(fnval,"%d", n > 0 ? 1 : 0); /* SAFE */
  9624.                     goto fnend;
  9625.                 }
  9626.               }
  9627. #else
  9628.               sprintf(fnval,"%d",0);    /* SAFE */
  9629. #endif /* CK_AUTHENTICATION */
  9630.               goto fnend;
  9631.  
  9632.             case FN_KRB_TT:             /* Kerberos ticket time */
  9633. #ifdef CK_AUTHENTICATION
  9634.               switch (kv) {
  9635.                 case 4:
  9636.                   n = ck_krb4_tkt_time(bp[1]);
  9637.                   sprintf(fnval,"%d", n >= 0 ? n : 0); /* SAFE */
  9638.                   goto fnend;
  9639.                 case 5: {
  9640.                     extern char * krb5_d_cc;
  9641.                     n = ck_krb5_tkt_time(krb5_d_cc,bp[1]);
  9642.                     sprintf(fnval,"%d", n >= 0 ? n : 0); /* SAFE */
  9643.                     goto fnend;
  9644.                 }
  9645.               }
  9646. #else
  9647.               ckstrncpy(fnval,"600",FNVALL); /* Some time */
  9648. #endif /* CK_AUTHENTICATION */
  9649.               goto fnend;
  9650.  
  9651.             case FN_KRB_FG:             /* Kerberos ticket flags */
  9652. #ifdef CK_AUTHENTICATION
  9653.               switch (kv) {
  9654.                 case 4:
  9655.                   fnval[0] = '\0';
  9656.                   goto fnend;
  9657.                 case 5: {
  9658.                     extern char * krb5_d_cc;
  9659.                     ckstrncpy(fnval,ck_krb5_tkt_flags(krb5_d_cc,bp[1]),FNVALL);
  9660.                     goto fnend;
  9661.                 }
  9662.               }
  9663. #else
  9664.               fnval[0] = '\0';
  9665. #endif /* CK_AUTHENTICATION */
  9666.               goto fnend;
  9667.           }
  9668.           p = fnval;
  9669.           goto fnend;
  9670.       }
  9671. #endif /* CK_KERBEROS */
  9672.  
  9673. #ifdef FN_ERRMSG
  9674.       case FN_ERRMSG:
  9675.         if (rdigits(bp[0])) {
  9676.             k = atoi(bp[0]);
  9677.         } else {
  9678.             failed = 1;
  9679.             if (fndiags)
  9680.              ckmakmsg(fnval,FNVALL,"<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9681.             goto fnend;
  9682.         }
  9683. #ifdef VMS
  9684.         ckstrncpy(fnval,ckvmserrstr(k),FNVALL);
  9685. #else
  9686.         x = errno;
  9687.         errno = k;
  9688.         ckstrncpy(fnval,ck_errstr(),FNVALL);
  9689.         errno = x;
  9690. #endif /* VMS */
  9691.         p = fnval;
  9692.         goto fnend;
  9693. #endif /* FN_ERRMSG */
  9694.  
  9695.       case FN_DIM: {
  9696.           int max;
  9697.           char abuf[16], *s;
  9698.           fnval[0] = NUL;               /* Initial return value */
  9699.           ckstrncpy(abuf,bp[0],16);     /* Get array reference */
  9700.           s = abuf;
  9701.           if (*s == CMDQ) s++;
  9702.           failed = 1;                   /* Assume it's bad */
  9703.           p = fnval;                    /* Point to result */
  9704.           if (fndiags)                  /* Default is this error message */
  9705.             ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  9706.           if (s[0] != '&') {            /* "Address" of array */
  9707.               goto fnend;
  9708.           }
  9709.           if (s[2]) {
  9710.               if (s[2] != '[' || s[3] != ']') {
  9711.                   goto fnend;
  9712.               }
  9713.           }
  9714.           if (s[1] >= 64 && s[1] < 91)  /* Convert upper to lower */
  9715.             s[1] += 32;
  9716.           if (s[1] < 95 || s[1] > 122) { /* Check for a-z */
  9717.               goto fnend;                       /* Bad */
  9718.           }
  9719.           if ((max = chkarray(s[1],1)) < 1)
  9720.             max = 0;
  9721.           failed = 0;                   /* Unset failure flag */
  9722.           sprintf(fnval,"%d",max);      /* SAFE */
  9723.           goto fnend;
  9724.       }
  9725.  
  9726.     } /* Break up big switch... */
  9727.  
  9728.     switch (y) {
  9729.       case FN_JDATE:
  9730.         if (argn < 1)                   /* Check number of args */
  9731.           p = ckdate();                 /* None, get today's date-time */
  9732.         else                            /* Some */
  9733.           p = bp[0];                    /* Use first */
  9734.         p = ckcvtdate(p,0);             /* Convert to standard form */
  9735.         ckstrncpy(fnval,zjdate(p),FNVALL); /* Convert to Julian */
  9736.         p = fnval;                      /* Point to result */
  9737.         failed = 0;
  9738.         if (*p == '-') {
  9739.             failed = 1;
  9740.             if (fndiags)                /* Default is this error message */
  9741.               ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_DATE:\\f",fn,"()>",NULL);
  9742.         }
  9743.         goto fnend;
  9744.  
  9745.       case FN_DATEJ:
  9746.         ckstrncpy(fnval,jzdate(bp[0]),FNVALL); /* Convert to yyyy<dayofyear> */
  9747.         p = fnval;                      /* Point to result */
  9748.         failed = 0;
  9749.         if (*p == '-') {
  9750.             failed = 1;
  9751.             if (fndiags)                /* Default is this error message */
  9752.               ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_DATE:\\f",fn,"()>",NULL);
  9753.         }
  9754.         goto fnend;
  9755.  
  9756.       case FN_DTIM:                     /* \fcvtdate() */
  9757.       case FN_TIME:                     /* Free-format time to hh:mm:ss */
  9758.       case FN_NTIM:                     /* Time to sec since midnight */
  9759.         s = (argn > 0) ? bp[0] : "";
  9760.         if (!s) s = "";
  9761.         if (!*s)
  9762.           p = ckdate();                 /* None, get today's date */
  9763.         else                            /* Some */
  9764.           p = bp[0];                    /* Use first */
  9765.         p = ckcvtdate(p,2);             /* Convert to standard form */
  9766.         if (*p == '<') {
  9767.             failed = 1;
  9768.             if (fndiags)                /* Default is this error message */
  9769.               ckmakmsg(fnval,FNVALL,
  9770.                        "<ERROR:ARG_BAD_DATE_OR_TIME:\\f",fn,"()>",NULL);
  9771.             p = fnval;
  9772.             goto fnend;
  9773.         }
  9774.         if (argn > 1) {
  9775.             s = bp[1];
  9776.             if (!s) s = "";
  9777.             if (!*s) s = "0";
  9778.             if (!chknum(s)) {
  9779.                 failed = 1;
  9780.                 if (fndiags)
  9781.                   ckmakmsg(fnval,FNVALL,
  9782.                            "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9783.                 p = fnval;
  9784.                 goto fnend;
  9785.             }
  9786.             x = atoi(s);
  9787.             if (x) p = shuffledate(p,x);
  9788.         }
  9789.         if (cx == FN_TIME) {
  9790.             p += 9;
  9791.         } else if (cx == FN_NTIM) {
  9792.             long sec = 0L;
  9793.             p[11] = NUL;
  9794.             p[14] = NUL;
  9795.             sec = atol(p+9) * 3600L + atol(p+12) * 60L + atol(p+15);
  9796.             sprintf(fnval,"%ld",sec);   /* SAFE */
  9797.             p = fnval;
  9798.         }
  9799.         goto fnend;
  9800.  
  9801.       case FN_MJD:                      /* Modified Julian Date */
  9802.         if (argn < 1)                   /* Check number of args */
  9803.           p = zzndate();                /* None, get today's date-time */
  9804.         else                            /* Some */
  9805.           p = bp[0];                    /* Use first */
  9806.         p = ckcvtdate(p,0);             /* Convert to standard form */
  9807.         if (*p == '-') {
  9808.             failed = 1;
  9809.             if (fndiags)                /* Default is this error message */
  9810.               ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_DATE:\\f",fn,"()>",NULL);
  9811.             goto fnend;
  9812.         }
  9813.         /* Convert to modified Julian date */
  9814.         sprintf(fnval,"%ld",mjd(p));    /* SAFE */
  9815.         p = fnval;                      /* Point to result */
  9816.         goto fnend;
  9817.  
  9818.       case FN_MJD2: {
  9819.           long k = 0L;
  9820.           int n = 0;
  9821.           p = evalx(bp[0]);
  9822.           if (*p == '-') {
  9823.               p++;
  9824.               n = 1;
  9825.           }
  9826.           if (!rdigits(p)) {
  9827.               failed = 1;
  9828.               evalerr(fn);
  9829.               p = fnval;
  9830.               goto fnend;
  9831.           } else {
  9832.               k = atol(p);
  9833.               if (n) k = -k;
  9834.           }
  9835.           ckstrncpy(fnval,mjd2date(k),FNVALL); /* Convert to Date */
  9836.           p = fnval;                    /* Point to result */
  9837.           failed = 0;
  9838.           goto fnend;
  9839.       }
  9840.  
  9841. #ifndef NODIAL
  9842.       case FN_PNCVT: {                  /* Convert phone number */
  9843.           extern char * pncvt();
  9844.           failed = 0;
  9845.           p = pncvt(bp[0]);
  9846.           if (!p) p = "";
  9847.           if (!*p) {
  9848.             failed = 1;
  9849.             if (fndiags)                /* Default is this error message */
  9850.               ckmakmsg(fnval,FNVALL,
  9851.                        "<ERROR:ARG_BAD_PHONENUM:\\f",fn,"()>",NULL);
  9852.         }
  9853.         goto fnend;
  9854.       }
  9855. #endif /* NODIAL */
  9856.  
  9857.       case FN_DAY:
  9858.       case FN_NDAY:
  9859.         if (argn < 1)                   /* Check number of args */
  9860.           p = zzndate();                /* None, get today's date-time */
  9861.         else                            /* Some */
  9862.           p = bp[0];                    /* Use first */
  9863.         p = ckcvtdate(p,0);             /* Convert to standard form */
  9864.         if (*p == '-') {
  9865.             failed = 1;
  9866.             if (fndiags)                /* Default is this error message */
  9867.               ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_DATE:\\f",fn,"()>",NULL);
  9868.             goto fnend;
  9869.         }
  9870.         failed = 0;
  9871.         z = mjd(p);                     /* Convert to modified Julian date */
  9872.         z = z % 7L;
  9873.         if (z < 0) {
  9874.             z = 0 - z;
  9875.             k = 6 - ((int)z + 3) % 7;
  9876.         } else {
  9877.             k = ((int)z + 3) % 7;    /* Day of week */
  9878.         }
  9879.         p = fnval;                      /* Point to result */
  9880.         if (cx == FN_NDAY)
  9881.           sprintf(fnval,"%d",k);        /* SAFE */
  9882.         else
  9883.           ckstrncpy(fnval,wkdays[k],FNVALL);
  9884.         goto fnend;
  9885.  
  9886.       case FN_N2TIM: {                  /* Sec since midnight to hh:mm:ss */
  9887.           long k = 0L;
  9888.           int n = 0, hh, mm, ss;
  9889.           char * s = bp[0];
  9890.           if (argn < 1)                 /* If no arg substitute 0 */
  9891.             s = "0";
  9892.           p = evalx(s);                 /* Evaluate expression silently */
  9893.           if (*p == '-') {              /* Check result for minus sign */
  9894.               p++;
  9895.               n = 1;
  9896.           }
  9897.           if (!rdigits(p)) { /* Check for numeric */
  9898.               failed = 1;
  9899.               ckmakmsg(fnval,FNVALL,
  9900.                        "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  9901.               p = fnval;
  9902.               goto fnend;
  9903.           } else {
  9904.               k = atol(p);
  9905.               if (n) k = -k;
  9906.           }
  9907.           if (k < 0) {                  /* Check for negative */
  9908.               failed = 1;
  9909.               if (fndiags)
  9910.                 ckmakmsg(fnval,FNVALL,
  9911.                          "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  9912.               p = fnval;
  9913.               goto fnend;
  9914.           }
  9915.           hh = k / 3600L;               /* Have positive number */
  9916.           mm = (k % 3600L) / 60L;       /* break it down... */
  9917.           ss = ((k % 3600L) % 60L);
  9918.  
  9919.           sprintf(fnval,"%02d:%02d:%02d",hh,mm,ss); /* SAFE */
  9920.           p = fnval;
  9921.           failed = 0;
  9922.           goto fnend;
  9923.       }
  9924.  
  9925.       case FN_PERM: {                   /* File permissions */
  9926.           p = fnval;
  9927.           z = zchki(bp[0]);
  9928.           if (z < 0) {
  9929.               failed = 1;
  9930.               if (fndiags) {
  9931.                   if (z == -1)
  9932.                     ckmakmsg(fnval,FNVALL,
  9933.                              "<ERROR:FILE_NOT_FOUND:\\f",fn,"()>",NULL);
  9934.                   else if (z == -2)
  9935.                     ckmakmsg(fnval,FNVALL,
  9936.                              "<ERROR:FILE_NOT_READABLE:\\f",fn,"()>",NULL);
  9937.                   else if (z == -3)
  9938.                     ckmakmsg(fnval,FNVALL,
  9939.                              "<ERROR:FILE_NOT_ACCESSIBLE:\\f",fn,"()>",NULL);
  9940.                   else
  9941.                     ckmakmsg(fnval,FNVALL,
  9942.                              "<ERROR:FILE_ERROR:\\f",fn,"()>",NULL);
  9943.               }
  9944.               goto fnend;
  9945.           }
  9946. #ifdef CK_PERMS
  9947.           ckstrncpy(fnval,ziperm(bp[0]),FNVALL);
  9948. #else
  9949.           ckstrncpy(fnval,"(unknown)",FNVALL);
  9950. #endif /* CK_PERMS */
  9951.           goto fnend;
  9952.       }
  9953.       case FN_TLOOK:                    /* tablelook() */
  9954.       case FN_ALOOK: {                  /* arraylook() */
  9955.           int i, x, hi, lo, max, cmdlen;
  9956.           char abuf[16], *s, *pat;
  9957.           char kwbuf[256];
  9958.           char delim = ':';
  9959.           failed = 1;                   /* Assume failure */
  9960.           ckstrncpy(fnval,"-1",FNVALL);
  9961.           pat = bp[0];                  /* Point to search pattern */
  9962.           if (!pat) pat = "";           /* Watch out for NULL pointer */
  9963.           cmdlen = strlen(pat);         /* Get pattern length */
  9964.           if (argn < 2 /* || cmdlen < 1 */ ) { /* Need two args */
  9965.               if (fndiags)
  9966.                 ckmakmsg(fnval,FNVALL,"<ERROR:MISSING_ARG:\\f",fn,"()>",NULL);
  9967.               goto fnend;
  9968.           }
  9969.           ckstrncpy(abuf,bp[1],16);     /* Get array reference */
  9970.           if (argn > 2)
  9971.             delim = *(bp[2]);
  9972.           s = abuf;
  9973.           if ((x = arraybounds(s,&lo,&hi)) < 0) { /* Get index and bounds */
  9974.               if (fndiags)
  9975.                ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  9976.               goto fnend;
  9977.           }
  9978.           p = fnval;                    /* Point to result */
  9979.           max = a_dim[x];               /* Size of array */
  9980.           if (lo < 0) lo = 0;           /* Use given range if any */
  9981.           if (lo > max) lo = max;
  9982.           if (hi < 0) hi = max;
  9983.           if (hi > max) hi = max;
  9984.           failed = 0;                   /* Unset failure flag */
  9985.           if (max < 1)
  9986.             goto fnend;
  9987.           kwbuf[255] = NUL;
  9988.           for (i = lo; i <= hi; i++) {
  9989.               if (!a_ptr[x][i])
  9990.                 continue;
  9991.               if (cx == FN_ALOOK) {
  9992.                   if (ckmatch(pat,a_ptr[x][i],inpcas[cmdlvl],1+4)) {
  9993.                       sprintf(fnval,"%d",i); /* SAFE */
  9994.                       goto fnend;
  9995.                   }
  9996.               } else if (cx == FN_TLOOK) {
  9997.                   char * aa;
  9998.                   int j = 0, v = 0, len;
  9999.                   if (i == hi)
  10000.                     break;
  10001.                   aa = a_ptr[x][i];     /* Point to this array element */
  10002.                   if (!aa) aa = "";
  10003.                   while (j < 254 && *aa) { /* Isolate keyword */
  10004.                       if (*aa == delim)
  10005.                         break;
  10006.                       kwbuf[j++] = *aa++;
  10007.                   }
  10008.                   kwbuf[j] = NUL;
  10009.                   len = j;
  10010.                   v = 0;
  10011.                   if ((len == cmdlen && !ckstrcmp(kwbuf,pat,len,0)) ||
  10012.                       ((v = !ckstrcmp(kwbuf,pat,cmdlen,0)) &&
  10013.                        ckstrcmp(a_ptr[x][i+1],pat,cmdlen,0))) {
  10014.                       sprintf(fnval,"%d",i); /* SAFE */
  10015.                       goto fnend;
  10016.                   }
  10017.                   if (v) {              /* Ambiguous */
  10018.                       ckstrncpy(fnval,"-2",FNVALL);
  10019.                       goto fnend;
  10020.                   }
  10021.               }
  10022.           }
  10023.           if (cx == FN_TLOOK) {         /* tablelook() last element */
  10024.               ckstrncpy(fnval,"-1",FNVALL);
  10025.               if (!ckstrcmp(a_ptr[x][hi],pat,cmdlen,0))
  10026.                 sprintf(fnval,"%d",hi); /* SAFE */
  10027.           }
  10028.           goto fnend;
  10029.       }
  10030.       case FN_TOB64:                    /* Base-64 conversion */
  10031.       case FN_FMB64:
  10032.         p = fnval;
  10033.         *p = NUL;
  10034.         if (argn < 1)
  10035.           goto fnend;
  10036.         if (cx == FN_TOB64) {
  10037.             x = b8tob64(bp[0],-1,fnval,FNVALL);
  10038.         } else {
  10039.             x = strlen(bp[0]);
  10040.             if (x % 4) {                /* length must be multiple of 4 */
  10041.                 failed = 1;
  10042.                 ckmakmsg(fnval,FNVALL,
  10043.                          "<ERROR:ARG_INCOMPLETE:\\f",fn,"()>",NULL);
  10044.                 goto fnend;
  10045.             }
  10046.             b64tob8(NULL,0,NULL,0);     /* Reset */
  10047.             x = b64tob8(bp[0],-1,fnval,FNVALL);
  10048.             b64tob8(NULL,0,NULL,0);     /* Reset again */
  10049.         }
  10050.         if (x < 0) {
  10051.             failed = 1;
  10052.             if (fndiags) {
  10053.                 char * m = "INTERNAL_ERROR";
  10054.                 switch (x) {
  10055.                   case -1: m = "ARG_TOO_LONG"; break;
  10056.                   case -2: m = "ARG_OUT_OF_RANGE"; break;
  10057.                 }
  10058.                 if (ckmakmsg(fnval,FNVALL,"<ERROR:",m,"\\f",fn) > 0)
  10059.                   ckstrncat(fnval,"()>",FNVALL);
  10060.             }
  10061.         }
  10062.         goto fnend;
  10063.  
  10064.       case FN_ABS: {
  10065.           char * s;
  10066.           s = bp[0];
  10067.           if (*s == '-' || *s == '+')
  10068.             s++;
  10069.           if (!rdigits(s)) {
  10070.               if (fndiags)
  10071.                 ckmakmsg(fnval,FNVALL,
  10072.                          "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10073.               goto fnend;
  10074.           }
  10075.           ckstrncpy(fnval,s,FNVALL);
  10076.           goto fnend;
  10077.       }
  10078.  
  10079.       case FN_AADUMP: {
  10080.           char abuf[16], *s = NULL, **ap = NULL, **vp = NULL;
  10081.           char pattern[VNAML];
  10082.           int slen, i, j, k, first = -1;
  10083.           extern int xdelmac();
  10084.           p = fnval;
  10085.           if (argn < 2) {
  10086.               if (fndiags)
  10087.                 ckmakmsg(fnval,FNVALL,"<ERROR:MISSING_ARG2:\\f",fn,"()>",NULL);
  10088.               goto fnend;
  10089.           }
  10090.           debug(F101,"aaconvert argn","",argn);
  10091.           s = bp[0];
  10092.           slen = strlen(s);
  10093.  
  10094.           /* Count elements so we can create the array */
  10095.  
  10096.           ckmakmsg(pattern,VNAML,s,"<*>",NULL,NULL);
  10097.           for (k = 0, i = 0; i < nmac; i++) {
  10098.               if (ckmatch(pattern,mactab[i].kwd,0,1)) {
  10099.                   if (first < 0)        /* Remember location of first match */
  10100.                     first = i;
  10101.                   k++;
  10102.               }
  10103.           }
  10104.           debug(F101,"aaconvert matches","",k);
  10105.           debug(F101,"aaconvert first","",first);
  10106.           fnval[0] = NUL;               /* Initial return value */
  10107.           ckstrncpy(abuf,bp[1],16);     /* Get array reference */
  10108.           s = abuf;
  10109.           if (*s == CMDQ) s++;
  10110.           p = fnval;                    /* Point to result */
  10111.           if (fndiags)                  /* Default is this error message */
  10112.             ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  10113.           if (s[0] != '&')              /* Address of array */
  10114.             goto fnend;
  10115.           if (s[2])
  10116.             if (s[2] != '[' || s[3] != ']')
  10117.               goto fnend;
  10118.           if (s[1] >= 64 && s[1] < 91)  /* Convert upper to lower */
  10119.             s[1] += 32;
  10120.           if ((x = dclarray(s[1],k)) < 0) /* Declare array to size */
  10121.             goto fnend;
  10122.           ap = a_ptr[x];                /* Point to array we just declared */
  10123.           debug(F111,"aaconvert array 1",abuf,ap);
  10124.           abuf[0] = NUL;
  10125.           if (argn > 2) {
  10126.               ckstrncpy(abuf,bp[2],16); /* Get value array reference */
  10127.               s = abuf;
  10128.               if (*s == CMDQ) s++;
  10129.               if (s[0] != '&')          /* Address of array */
  10130.                 goto fnend;
  10131.               if (s[2])
  10132.                 if (s[2] != '[' || s[3] != ']')
  10133.                   goto fnend;
  10134.               if (s[1] >= 64 && s[1] < 91) /* Convert upper to lower */
  10135.                 s[1] += 32;
  10136.               if ((x = dclarray(s[1],k)) < 0)
  10137.                 goto fnend;
  10138.               vp = a_ptr[x];            /* Point to array we just declared */
  10139.           }
  10140.           debug(F111,"aaconvert array 2",abuf,vp);
  10141.           makestr(&ap[0],ckitoa(k));
  10142.           if (vp) makestr(&vp[0],ckitoa(k));
  10143.           if (fndiags)
  10144.            ckmakmsg(fnval,FNVALL,"<ERROR:ASSOCIATIVE_ARRAY:\\f",fn,"()>",NULL);
  10145.  
  10146.           /* Copy macro index & value to the arrays and then remove the */
  10147.           /* macro, so the 'first' pointer keeps indicating the next one. */
  10148.           /* We could combine the initial counting loop with this one but */
  10149.           /* then it would be harder to create the array and anyway this */
  10150.           /* function is plenty fast as it is. */
  10151.  
  10152.           for (i = 1; i <= k; ) {
  10153.               if (!ckmatch(pattern,mactab[first].kwd,0,1)) {
  10154.                   debug(F111,"aaconvert oddball",mactab[first].kwd,first);
  10155.                   first++;
  10156.                   continue;
  10157.               }
  10158.               ckstrncpy(tmpbuf,mactab[first].kwd,TMPBUFSIZ); /* Macro name */
  10159.               s = tmpbuf;                       /* Make writeable copy */
  10160.               s += slen;                        /* Isolate "index" */
  10161.               j = strlen(s) - 1;
  10162.               if (*s != '<' || *(s+j) != '>') { /* Check syntax */
  10163.                   /* This shouldn't happen */
  10164.                   debug(F111,"aaconvert ERROR",mactab[first].kwd,first);
  10165.                   goto fnend;
  10166.               }
  10167.               *(s+j) = NUL;             /* Remove final '>' */
  10168.               debug(F111,"aaconvert",s+1,i);
  10169.               makestr(&(ap[i]),s+1);    /* Set first array to index */
  10170.               if (vp)
  10171.                 makestr(&(vp[i]),mactab[first].mval); /* 2nd to value */
  10172.               if (xdelmac(first) < 0)
  10173.                 goto fnend;
  10174.               i++;
  10175.           }
  10176.           sprintf(fnval,"%d",k);        /* SAFE */
  10177.           p = fnval;                    /* Return size of array */
  10178.           debug(F110,"aaconvert return",p,0);
  10179.           failed = 0;                   /* Unset failure flag */
  10180.           goto fnend;
  10181.       }
  10182.  
  10183.     } /* End of switch() */
  10184.  
  10185. #ifdef FNFLOAT
  10186. /*
  10187.   Floating-point functions.  To be included only if FNFLOAT is defined, which
  10188.   should happen only if CKFLOAT is also defined, and if the math library is
  10189.   linked in.  Even then, we might have float-vs-double confusion as well as
  10190.   confusion about what the final "%f" format effector is supposed to reference
  10191.   (32 bits, 64 bits, etc).  Expect trouble if CKFLOAT does not match the data
  10192.   type of math library functions or args.
  10193. */
  10194.     if (cx == FN_FPABS ||               /* Floating-point functions */
  10195.         cx == FN_FPADD ||
  10196.         cx == FN_FPDIV ||
  10197.         cx == FN_FPEXP ||
  10198.         cx == FN_FPLOG ||
  10199.         cx == FN_FPLN  ||
  10200.         cx == FN_FPMOD ||
  10201.         cx == FN_FPMAX ||
  10202.         cx == FN_FPMIN ||
  10203.         cx == FN_FPMUL ||
  10204.         cx == FN_FPPOW ||
  10205.         cx == FN_FPSQR ||
  10206.         cx == FN_FPINT ||
  10207.         cx == FN_FPSUB ||
  10208.         cx == FN_FPROU ||
  10209.         cx == FN_FPSIN ||
  10210.         cx == FN_FPCOS ||
  10211.         cx == FN_FPTAN) {
  10212.         CKFLOAT farg[2], fpresult = 0.0;
  10213.         char fpbuf[64], * bp0;
  10214.         double dummy;
  10215.         /* int sign = 0; */
  10216.         int i, j, places = 0;
  10217.         int argcount = 1;
  10218.  
  10219.         failed = 1;
  10220.         p = fnval;
  10221.         bp0 = bp[0];
  10222.         if (!bp0)
  10223.           bp0 = "0";
  10224.         else if (!*bp0)
  10225.           bp0 = "0";
  10226.         if (!isfloat(bp0,0)) {
  10227.             k = mxlook(mactab,bp0,nmac);
  10228.             bp0 = (k > -1) ? mactab[k].mval : NULL;
  10229.             if (bp0) {
  10230.                 if (!isfloat(bp0,0)) {
  10231.                     if (fndiags)
  10232.                       ckmakmsg(fnval,FNVALL,
  10233.                                "<ERROR:ARG_NOT_FLOAT:\\f",fn,"()>",NULL);
  10234.                     goto fnend;
  10235.                 }
  10236.             }
  10237.         }
  10238.         if (cx == FN_FPINT) {           /* Float to int */
  10239.             failed = 0;
  10240.             ckstrncpy(fnval,bp0,FNVALL);
  10241.             for (i = 0; fnval[i]; i++) {
  10242.                 if (fnval[i] == '.') {
  10243.                     fnval[i] = NUL;
  10244.                     break;
  10245.                 }
  10246.             }
  10247.             goto fnend;
  10248.         }
  10249.         switch (y) {                    /* These need 2 args */
  10250.           case FN_FPADD:
  10251.           case FN_FPDIV:
  10252.           case FN_FPMOD:
  10253.           case FN_FPMAX:
  10254.           case FN_FPMIN:
  10255.           case FN_FPMUL:
  10256.           case FN_FPPOW:
  10257.           case FN_FPSUB:
  10258.             argcount = 2;
  10259.         }
  10260.         /* Missing arguments are supplied as 0.0 */
  10261.  
  10262.         debug(F111,fn,"argcount",argcount);
  10263.         for (i = 0; i < argcount; i++) { /* Get floating-point args */
  10264. #ifdef DEBUG
  10265.             if (deblog) {
  10266.                 ckmakmsg(fpbuf,
  10267.                          64,
  10268.                          "bp[",
  10269.                          ckitoa(i),
  10270.                          bp[i] ? bp[i] : "(null)",
  10271.                          "]"
  10272.                          );
  10273.                 debug(F100,fpbuf,"",0);
  10274.             }
  10275. #endif /* DEBUG */
  10276.             if (!bp[i]) {
  10277.                 farg[i] = 0.0;
  10278.             } else if (!*(bp[i])) {
  10279.                 farg[i] = 0.0;
  10280.             } else if (!isfloat(bp[i],0)) {
  10281.                 char * tmp;
  10282.                 k = mxlook(mactab,bp[i],nmac);
  10283.                 tmp = (k > -1) ? mactab[k].mval : NULL;
  10284.                 if (tmp) {
  10285.                     if (!isfloat(tmp,0)) {
  10286.                         if (fndiags)
  10287.                           ckmakmsg(fnval,FNVALL,
  10288.                                    "<ERROR:ARG_NOT_FLOAT:\\f",fn,"()>",NULL);
  10289.                         goto fnend;
  10290.                     }
  10291.                 }
  10292.             }
  10293.             farg[i] = floatval;
  10294.  
  10295. #ifdef DEBUG
  10296.             if (deblog) {
  10297.                 sprintf(fpbuf,"farg[%d]=%f",i,farg[i]); /* SAFE */
  10298.                 debug(F100,fpbuf,"",0);
  10299.             }
  10300. #endif /* DEBUG */
  10301.         }
  10302.         if (bp[argcount]) {             /* Get decimal places */
  10303.             char * s;
  10304.             s = bp[argcount];
  10305.             if (!s) s = "";
  10306.             if (!*s) s = "0";
  10307.             s = evalx(s);
  10308.             if (!s) s = "";
  10309.             if (!*s) {
  10310.                 evalerr(fn);
  10311.                 goto fnend;
  10312.             }
  10313.             places = atoi(s);
  10314.         }
  10315.         errno = 0;
  10316.         failed = 0;
  10317.         switch (y) {                    /* Now do the requested function */
  10318.           case FN_FPABS:                /* Floating-point absolute value */
  10319. #ifndef COMMENT
  10320.             fpresult = fabs(farg[0]);
  10321. #else
  10322.             if (farg[0] < 0.0)
  10323.               fpresult = 0.0 - farg[0];
  10324. #endif /* COMMENT */
  10325.             break;
  10326.           case FN_FPADD:                /* FP add */
  10327.             fpresult = farg[0] + farg[1];
  10328.             break;
  10329.           case FN_FPDIV:                /* FP divide */
  10330.           case FN_FPMOD:                /* FP modulus */
  10331.             if (!farg[1]) {
  10332.                 failed = 1;
  10333.                 if (fndiags)
  10334.                   ckmakmsg(fnval,FNVALL,
  10335.                            "<ERROR:DIVIDE_BY_ZERO:\\f",fn,"()>",NULL);
  10336.             } else
  10337.               fpresult = (cx == FN_FPDIV) ?
  10338.                 (farg[0] / farg[1]) :
  10339.                   fmod(farg[0],farg[1]);
  10340.             break;
  10341.           case FN_FPEXP:                /* FP e to the x */
  10342.             fpresult = (CKFLOAT) exp(farg[0]);
  10343.             break;
  10344.           case FN_FPLOG:                /* FP base-10 logarithm */
  10345.           case FN_FPLN:                 /* FP natural logarithm */
  10346.             if (farg[0] < 0.0) {
  10347.                 failed = 1;
  10348.                 if (fndiags)
  10349.                   ckmakmsg(fnval,FNVALL,
  10350.                            "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10351.             } else
  10352.               fpresult = (cx == FN_FPLOG) ? log10(farg[0]) : log(farg[0]);
  10353.             break;
  10354.           case FN_FPMUL:                /* FP multiply */
  10355.             fpresult = farg[0] * farg[1];
  10356.             break;
  10357.           case FN_FPPOW:                /* FP raise to a power */
  10358.             fpresult = modf(farg[1],&dummy);
  10359.             if ((!farg[0] && farg[1] <= 0.0) ||
  10360.                 (farg[0] < 0.0 && fpresult)) {
  10361.                 failed = 1;
  10362.                 if (fndiags)
  10363.                   ckmakmsg(fnval,FNVALL,
  10364.                            "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10365.             } else
  10366.               fpresult = pow(farg[0],farg[1]);
  10367.             break;
  10368.           case FN_FPSQR:                /* FP square root */
  10369.             if (farg[0] < 0.0) {
  10370.                 failed = 1;
  10371.                 if (fndiags)
  10372.                   ckmakmsg(fnval,FNVALL,
  10373.                            "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10374.             } else
  10375.               fpresult = sqrt(farg[0]);
  10376.             break;
  10377.           case FN_FPSUB:                /* FP subtract */
  10378.             fpresult = farg[0] - farg[1];
  10379.             break;
  10380.           case FN_FPROU:                /* FP round */
  10381.             fpresult = farg[0];
  10382.             break;
  10383.           case FN_FPSIN:                /* FP sine */
  10384.             fpresult = (CKFLOAT) sin(farg[0]);
  10385.             break;
  10386.           case FN_FPCOS:                /* FP cosine */
  10387.             fpresult = (CKFLOAT) cos(farg[0]);
  10388.             break;
  10389.           case FN_FPTAN:                /* FP tangent */
  10390.             fpresult = (CKFLOAT) tan(farg[0]);
  10391.             break;
  10392.           case FN_FPMAX:
  10393.             fpresult = (farg[0] > farg[1]) ? farg[0] : farg[1];
  10394.             break;
  10395.           case FN_FPMIN:
  10396.             fpresult = (farg[0] < farg[1]) ? farg[0] : farg[1];
  10397.             break;
  10398.         }
  10399.  
  10400.         /* Get here with fpresult = function result */
  10401.  
  10402.         if (errno) {                    /* If range or domain error */
  10403.             failed = 1;
  10404.             if (fndiags)
  10405.               ckmakmsg(fnval,FNVALL,
  10406.                        "<ERROR:FLOATING-POINT-OP:\\f",fn,"()>",NULL);
  10407.         }
  10408.         if (failed)                     /* and/or any other kind of error, */
  10409.           goto fnend;                   /* fail. */
  10410. #ifndef COMMENT
  10411.         /* Call routine containing code that was formerly inline */
  10412.         ckstrncpy(fnval,fpformat(fpresult,places,cx == FN_FPROU),FNVALL);
  10413. #else
  10414.         {
  10415.             char fbuf[16];              /* For creating printf format */
  10416.             if (!fp_rounding &&         /* If printf doesn't round, */
  10417.                 (places > 0 ||          /* round result to decimal places. */
  10418.                  (places == 0 && cx == FN_FPROU)))
  10419.               fpresult += (0.5 / pow(10.0,(CKFLOAT)places));
  10420.             if (places > 0) {                   /* If places specified */
  10421.                 /* use specified places to write given number of digits */
  10422.                 sprintf(fbuf,"%%0.%df",places); /* SAFE */
  10423.                 sprintf(fnval,fbuf,fpresult);   /* SAFE */
  10424.             } else {                            /* Otherwise... */
  10425. #ifdef COMMENT
  10426. /*
  10427.   Here we want to print exactly fp_digits significant digits, no matter which
  10428.   side of the decimal point they are on.  That is, we want want the default
  10429.   format to show the maximum number of non-garbage digits, AND we want the last
  10430.   such digit to be rounded.  Of course there is no way to do that, since the
  10431.   digit after the last non-garbage digit is, well, garbage.  So the following
  10432.   clever ruse does no good.
  10433. */
  10434.                 int sign = 0, m = 0;
  10435.                 sprintf(fnval,"%f",fpresult);
  10436.                 if (fnval[0] == '-') sign = 1;
  10437.                 for (i = sign; i < FNVALL; i++) {
  10438.                     if (isdigit(fnval[i]))
  10439.                       m++;
  10440.                     else
  10441.                       break;
  10442.                 }
  10443.                 if (m > 1) {
  10444.                     int d = fp_digits - m;
  10445.                     if (d < 1) d = 1;
  10446.                     sprintf(fbuf,"%%%d.%df",fp_digits+sign+1,d);
  10447.                 } else {
  10448.                     sprintf(fbuf,"%%0.%df",fp_digits);
  10449.                 }
  10450.                 sprintf(fnval,fbuf,fpresult);
  10451. #else
  10452.                 /* Go for max precision */
  10453.                 sprintf(fbuf,"%%0.%df",fp_digits); /* SAFE */
  10454.                 sprintf(fnval,fbuf,fpresult); /* SAFE */
  10455.  
  10456. #endif /* COMMENT */
  10457.             }
  10458.             if (fnval[0] == '-') sign = 1;
  10459.         }
  10460.         debug(F111,"fpresult 1",fnval,errno); /* Check for over/underflow */
  10461.         for (i = sign; fnval[i]; i++) { /* Give requested decimal places */
  10462.             if (fnval[i] == '.')        /* First find the decimal point */
  10463.               break;
  10464.             else if (i > fp_digits + sign - 1) /* replacing garbage */
  10465.               fnval[i] = '0';           /* digits with 0... */
  10466.         }
  10467.         if (fnval[i] == '.') {          /* Have decimal point */
  10468.             int gotend = 0;
  10469.             /* d < 0 so truncate fraction */
  10470.             if (places < 0 || (places == 0 && cx == FN_FPROU)) {
  10471.                 fnval[i] = NUL;
  10472.             } else if (places > 0) {    /* d > 0 so this many decimal places */
  10473.                 i++;                           /* First digit after decimal */
  10474.                 for (j = 0; j < places; j++) { /* Truncate after d decimal */
  10475.                     if (!fnval[j+i])           /* places or extend to d  */
  10476.                       gotend = 1;              /* decimal places. */
  10477.                     if (gotend || j+i+sign > fp_digits)
  10478.                       fnval[j+i] = '0';
  10479.                 }
  10480.                 fnval[j+i] = NUL;
  10481.             } else {                    /* d == 0 so Do The Right Thing */
  10482.                 for (j = (int)strlen(fnval) - 1; j > i+1; j--) {
  10483.                     if ((j - sign) > fp_digits)
  10484.                       fnval[j] = '0';
  10485.                     if (fnval[j] == '0')
  10486.                       fnval[j] = NUL;   /* Strip useless trailing 0's. */
  10487.                     else
  10488.                       break;
  10489.                 }
  10490.             }
  10491.         }
  10492. #endif /* COMMENT */
  10493.         debug(F111,"fpresult 2",fnval,errno);
  10494.         goto fnend;
  10495.  
  10496.     }
  10497. #endif /* FNFLOAT */
  10498.  
  10499. #ifdef CKCHANNELIO
  10500.     if (cx == FN_FSTAT  ||              /* File functions */
  10501.         cx == FN_FPOS   ||
  10502.         cx == FN_FEOF   ||
  10503.         cx == FN_FGCHAR ||
  10504.         cx == FN_FGLINE ||
  10505.         cx == FN_FGBLK  ||
  10506.         cx == FN_FPCHAR ||
  10507.         cx == FN_FPLINE ||
  10508.         cx == FN_FPBLK  ||
  10509.         cx == FN_NLINE  ||
  10510.         cx == FN_FERMSG ||
  10511.         cx == FN_FILNO) {
  10512.         int x = 0, t = 0, channel;
  10513.         long z;
  10514.         extern int z_maxchan;
  10515.  
  10516.         failed = 1;                     /* Assume failure */
  10517.         p = fnval;                      /* until we validate args */
  10518.         if (cx == FN_FERMSG) {
  10519.             extern int z_error;
  10520.             if (argn < 1) {
  10521.                 x = z_error;
  10522.             } else if (chknum(bp[0])) {
  10523.                 x = atoi(bp[0]);
  10524.             } else if (fndiags)
  10525.               ckmakmsg(fnval,FNVALL,
  10526.                        "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10527.             failed = 0;
  10528.             ckstrncpy(fnval,ckferror(x),FNVALL);
  10529.             goto fnend;
  10530.         }
  10531.         if (argn < 1) {                 /* All file functions need channel */
  10532.             if (fndiags)
  10533.               ckmakmsg(fnval,FNVALL,"<ERROR:MISSING_ARG:\\f",fn,"()>",NULL);
  10534.             goto fnend;
  10535.         }
  10536.         if (rdigits(bp[0])) {           /* Channel must be numeric */
  10537.             channel = atoi(bp[0]);
  10538.         } else {                        /* Fail if it isn't */
  10539.             if (fndiags)
  10540.               ckmakmsg(fnval,FNVALL,
  10541.                        "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10542.             goto fnend;
  10543.         }
  10544.         if (channel < 0 || channel > z_maxchan) { /* Check channel range */
  10545.             if (fndiags)
  10546.               ckmakmsg(fnval,FNVALL,
  10547.                        "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10548.             goto fnend;
  10549.         }
  10550.         x = z_getmode(channel);         /* Find out about the channel */
  10551.  
  10552.         failed = 0;                     /* Assume success from here down */
  10553.         if (cx == FN_FSTAT) {           /* Status / modes of channel */
  10554.             if (x > -1)
  10555.               x &= FM_RWB;              /* Mask out irrelevant bits */
  10556.             else                        /* In this case not open is OK */
  10557.               x = 0;                    /* 0 if not open, 1-7 if open */
  10558.             sprintf(fnval,"%d",x);      /* SAFE */
  10559.             goto fnend;
  10560.         } else if (x < 1) {             /* Not \f_status() so must be open */
  10561.             failed = 1;
  10562.             if (fndiags)
  10563.               ckmakmsg(fnval,FNVALL,"<ERROR:FILE_NOT_OPEN:\\f",fn,"()>",NULL);
  10564.             goto fnend;
  10565.         }
  10566.         switch (y) {                    /* Do the requested function */
  10567.           case FN_FPOS:                 /* Get position */
  10568.             z = z_getpos(channel);
  10569.             sprintf(fnval,"%ld",z);     /* SAFE */
  10570.             goto fnend;
  10571.  
  10572.           case FN_NLINE:                /* Get line number */
  10573.             z = z_getline(channel);
  10574.             sprintf(fnval,"%ld",z);     /* SAFE */
  10575.             goto fnend;
  10576.  
  10577.           case FN_FEOF:                 /* Check EOF */
  10578.             t = 0;
  10579.             if (x & FM_EOF) t = 1;
  10580.             sprintf(fnval,"%d",t);      /* SAFE */
  10581.             goto fnend;
  10582.  
  10583.           case FN_FILNO:                /* Get file handle */
  10584.             x = z_getfnum(channel);
  10585.             sprintf(fnval,"%d",x);      /* SAFE */
  10586.             goto fnend;
  10587.  
  10588.           case FN_FPBLK:                /* Read or write block */
  10589.           case FN_FGBLK:
  10590.             if (argn < 2) {
  10591.                 if (fndiags)
  10592.                   ckmakmsg(fnval,FNVALL,
  10593.                            "<ERROR:MISSING_ARG:\\f",fn,"()>",NULL);
  10594.                 goto fnend;
  10595.             }
  10596.             if (rdigits(bp[1])) {
  10597.                 t = atoi(bp[1]);
  10598.             } else {
  10599.                 if (fndiags)
  10600.                   ckmakmsg(fnval,FNVALL,
  10601.                            "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10602.                 goto fnend;
  10603.             }
  10604.           case FN_FGCHAR:               /* Read or write character or line */
  10605.           case FN_FPCHAR:
  10606.           case FN_FGLINE:
  10607.           case FN_FPLINE:
  10608.             fnval[0] = NUL;
  10609.             switch (y) {
  10610.               case FN_FGCHAR: t = z_in(channel,fnval,FNVALL,1,1); break;
  10611.               case FN_FGLINE: t = z_in(channel,fnval,FNVALL,FNVALL-1,0); break;
  10612.               case FN_FGBLK:
  10613.                 if (t >= FNVALL) t = FNVALL - 1;
  10614.                 t = z_in(channel,fnval,FNVALL,t,1);
  10615.                 break;
  10616.               case FN_FPCHAR: t = z_out(channel,bp[1],1,1);  break;
  10617.               case FN_FPLINE: t = z_out(channel,bp[1],-1,0); break;
  10618.               case FN_FPBLK:  t = z_out(channel,bp[1],-1,1); break;
  10619.             }
  10620.             if (t < 0) {                /* Handle read/write error */
  10621.                 failed = 1;
  10622.                 if (fndiags && t != FX_EOF)
  10623.                   ckmakmsg(fnval,FNVALL,
  10624.                            "<ERROR:FILE_ERROR_%d:\\f",fn,"()>",NULL);
  10625.                 goto fnend;
  10626.             }
  10627.             if (cx == FN_FGCHAR)        /* Null terminate char */
  10628.               fnval[1] = NUL;
  10629.             /* Write (put) functions return numeric status code */
  10630.             if (cx == FN_FPCHAR || cx == FN_FPLINE || cx == FN_FPBLK)
  10631.               sprintf(fnval,"%d",t);    /* SAFE */
  10632.             goto fnend;
  10633.         }
  10634.     }
  10635. #endif /* CKCHANNELIO */
  10636.  
  10637.     if (cx == FN_PATTERN) {             /* \fpattern() */
  10638.         ispattern = 1;
  10639.         if (argn > 0) {
  10640.             p = fnval;
  10641.             ckstrncpy(fnval,bp[0],FNVALL);
  10642.         } else p = "";
  10643.         goto fnend;
  10644.     }
  10645.  
  10646.     if (cx == FN_HEX2N || cx == FN_OCT2N) { /* \fhex2n(), \foct2n() */
  10647.         p = "0";
  10648.         if (argn < 1)
  10649.           goto fnend;
  10650.         p = ckradix(bp[0], ((cx == FN_HEX2N) ? 16 : 8), 10);
  10651.         if (!p) {
  10652.             if (fndiags)
  10653.               ckmakmsg(fnval,FNVALL,
  10654.                        "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10655.             goto fnend;
  10656.         }
  10657.         failed = 0;
  10658.         ckstrncpy(fnval,p,FNVALL);
  10659.         p = fnval;
  10660.         goto fnend;
  10661.     }
  10662.  
  10663.     if (cx == FN_HEX2IP) {
  10664.         int c[2], ip[4], i, k;
  10665.         p = "0";
  10666.         if (argn < 1)
  10667.           goto fnend;
  10668.         s = bp[0];
  10669.         if ((int)strlen(s) != 8) {
  10670.             failed = 1;
  10671.             if (fndiags)
  10672.               ckmakmsg(fnval,FNVALL,
  10673.                        "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10674.             goto fnend;
  10675.         }
  10676.         p = fnval;
  10677.         for (k = 0; k < 8; k += 2) {
  10678.             for (i = 0; i < 2; i++) {
  10679.                 c[i] = *s++;
  10680.                 if (islower(c[i])) c[i] = toupper(c[i]);
  10681.                 if (c[i] >= '0' && c[i] <= '9') {
  10682.                     c[i] -= 0x30;
  10683.                 } else if (c[i] >= 'A' && c[i] <= 'F') {
  10684.                     c[i] -= 0x37;
  10685.                 } else {
  10686.                     failed = 1;
  10687.                     if (fndiags)
  10688.                       ckmakmsg(fnval,FNVALL,
  10689.                                "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10690.                     goto fnend;
  10691.                 }
  10692.                 ip[k/2] = c[0] << 4 | c[1];
  10693.             }
  10694.             sprintf(p,"%d.%d.%d.%d",ip[0],ip[1],ip[2],ip[3]); /* SAFE */
  10695.         }
  10696.         goto fnend;
  10697.     }
  10698.     if (cx == FN_IP2HEX) {
  10699.         int ip[4], i;
  10700.         char * q;
  10701.         p = "00000000";
  10702.         if (argn < 1)
  10703.           goto fnend;
  10704.         s = bp[0];
  10705.         p = fnval;
  10706.         for (i = 0; i < 3; i++) {
  10707.             q = ckstrchr(s,'.');
  10708.             if (q) {
  10709.                 *q++ = NUL;
  10710.                 ip[i] = atoi(s);
  10711.                 s = q;
  10712.             } else {
  10713.                 failed = 1;
  10714.                 if (fndiags)
  10715.                   ckmakmsg(fnval,FNVALL,
  10716.                            "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10717.                 goto fnend;
  10718.             }
  10719.         }
  10720.         ip[3] = atoi(s);
  10721.         sprintf(p,"%02x%02x%02x%02x",ip[0],ip[1],ip[2],ip[3]); /* SAFE */
  10722.         goto fnend;
  10723.     }
  10724.     if (cx == FN_RADIX) {
  10725.         failed = 1;
  10726.         p = fnval;
  10727.         if (argn < 3) {
  10728.             if (fndiags)
  10729.               ckmakmsg(fnval,FNVALL,"<ERROR:MISSING_ARG:\\f",fn,"()>",NULL);
  10730.             goto fnend;
  10731.         }
  10732.         if (!rdigits(bp[1]) || !rdigits(bp[2])) {
  10733.             if (fndiags)
  10734.               ckmakmsg(fnval,FNVALL,
  10735.                        "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10736.             goto fnend;
  10737.         }
  10738.         p = ckradix(bp[0],atoi(bp[1]),atoi(bp[2]));
  10739.         if (!p) {
  10740.             if (fndiags)
  10741.               ckmakmsg(fnval,FNVALL,
  10742.                        "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  10743.             goto fnend;
  10744.         }
  10745.         failed = 0;
  10746.         ckstrncpy(fnval,p,FNVALL);
  10747.         p = fnval;
  10748.         goto fnend;
  10749.     }
  10750.     if (cx == FN_JOIN) {
  10751.         int i, x, y, z, flag, hi, lo, max, seplen, grouping = 0;
  10752.         char abuf[16], c, *s, *q, *sep = NULL;
  10753.         char * gr_opn = "\"{'([<";      /* Group open brackets */
  10754.         char * gr_cls = "\"}')]>";      /* Group close brackets */
  10755.         char lb[2], rb[2];              /* Selected left and right brackets */
  10756.  
  10757.         failed = 1;                     /* Assume failure */
  10758.         fnval[0] = NUL;
  10759.         debug(F101,"FNJOIN ARGN","",argn);
  10760.  
  10761.         ckstrncpy(abuf,bp[0],16);       /* Get array reference */
  10762.         s = abuf;
  10763.         if ((x = arraybounds(s,&lo,&hi)) < 0) {  /* Get index and bounds */
  10764.             if (fndiags)
  10765.               ckmakmsg(fnval,FNVALL,"<ERROR:ARG_BAD_ARRAY:\\f",fn,"()>",NULL);
  10766.             goto fnend;
  10767.         }
  10768.         p = fnval;                      /* Point to result */
  10769.         max = a_dim[x];                 /* Size of array */
  10770.         if (lo < 0) lo = 1;             /* Use given range if any */
  10771.         if (lo > max) lo = max;
  10772. #ifdef COMMENT
  10773.     hi = max;
  10774. #else
  10775. /*
  10776.   This is a workaround for the problem in which the dimension of the \&_[]
  10777.   array (but not its contents) grows upon entry to a SWITCH block.  But this
  10778.   code prevents the dimension from growing.  Go figure.
  10779. */
  10780.         if (hi < 0) {            /* Bounds not given */
  10781.             if (x)            /* Regular array */
  10782.           hi = max;
  10783.         else            /* Argument vector array */
  10784.           for (hi = max; hi >= lo; hi--) { /* ignore any trailing */
  10785.           if (!a_ptr[x][hi]) continue; /* empty elements */
  10786.           if (!*(a_ptr[x][hi])) continue;
  10787.           break;
  10788.           }
  10789.     }
  10790. #endif /* COMMENT */
  10791.         if (hi > max) hi = max;
  10792.         failed = 0;                     /* Unset failure flag */
  10793.         if (max < 1)
  10794.           goto fnend;
  10795.         sep = " ";                      /* Separator */
  10796.         if (argn > 1)
  10797.           if (bp[1])
  10798.             if (*bp[1])
  10799.               sep = bp[1];
  10800.         lb[0] = NUL;
  10801.         rb[0] = NUL;
  10802.         lb[1] = NUL;
  10803.         rb[1] = NUL;
  10804.         if (argn > 2) {                 /* Grouping? */
  10805.             char * bp2 = bp[2];
  10806.             if (!bp2) bp2 = "0";
  10807.             if (!*bp2) bp2 = "0";
  10808.             if (chknum(bp2)) {
  10809.                 grouping = atoi(bp2);
  10810.                 if (grouping < 0 || grouping > 63)
  10811.                   grouping = 1;
  10812.             } else {
  10813.                 failed = 1;
  10814.                 if (fndiags)
  10815.                   ckmakmsg(fnval,FNVALL,
  10816.                            "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  10817.                 goto fnend;
  10818.             }
  10819.             if (grouping) {             /* Take lowest-order one */
  10820.                 int j, k;               /* and set the others to 0 */
  10821.                 for (k = 0; k < 6; k++) {
  10822.                     j = 1 << k;
  10823.                     if (grouping & j) {
  10824.                         lb[0] = gr_opn[k];
  10825.                         rb[0] = gr_cls[k];
  10826.                         break;
  10827.                     }
  10828.                 }
  10829.             }
  10830.         }
  10831.         if (argn > 3)                   /* Nonzero 4th arg for no separator */
  10832.           if (chknum(bp[3]))
  10833.             if (atoi(bp[3]) > 0)
  10834.               sep = NULL;
  10835.         if (!sep) {
  10836.             sep = "";
  10837.             seplen = 0;
  10838.         } else
  10839.           seplen = strlen(sep);
  10840.         for (i = lo; i <= hi; i++) {    /* Loop thru selected array elements */
  10841.             s = a_ptr[x][i];            /* Get next element */
  10842.             if (!s)
  10843.               s = "";
  10844.             flag = 0;                   /* Buffer overrun flag */
  10845.             if (grouping) {             /* Does this element need quoting? */
  10846.                 q = s;                  /* Look for spaces */
  10847.                 while ((c = *q++)) { if (c == SP) { flag++; break; } }
  10848.             }
  10849.             y = strlen(s);              /* Get length of this element */
  10850.             if (cx == 0 && grouping)    /* If empty it might need quoting */
  10851.               flag = 1;
  10852.             if (flag) {                 /* Add grouping if needed */
  10853.                 char * s2 = NULL;
  10854.                 y += 2;
  10855.                 if ((q = (char *)malloc(y+1))) {
  10856.                     ckmakmsg(q,y+1,(char *)lb,s,(char *)rb,NULL);
  10857.                     makestr(&s2,q);
  10858.                     free(q);
  10859.                     s = s2;
  10860.                 }
  10861.             }
  10862.             z = 0;                      /* Number of chars copied */
  10863.             flag = 0;                   /* flag is now buffer-overrun flag */
  10864.             if (y > 0)                  /* If this string is not empty */
  10865.               z = ckstrncat(fnval,s,FNVALL); /* copy it. */
  10866.             if (z < y)                  /* Check for buffer overrun. */
  10867.               flag++;
  10868.             if (!flag && *sep && i < hi) { /* If buffer still has room */
  10869.                 z = ckstrncat(fnval,sep,FNVALL); /* copy delimiter */
  10870.                 if (z < seplen)
  10871.                   flag++;
  10872.             }
  10873.             if (flag) {
  10874.                 failed = 1;
  10875.                 if (fndiags)
  10876.                   ckmakmsg(fnval,FNVALL,
  10877.                            "<ERROR:RESULT_TOO_LONG:\\f",fn,"()>",NULL);
  10878.                 goto fnend;
  10879.             }
  10880.         }
  10881.     isjoin = 1;
  10882.         goto fnend;
  10883.     }
  10884.     if (cx == FN_SUBST) {               /* \fsubstitute() */
  10885.         CHAR c, * s, * r, * tp[2], buf1[256], buf2[256], buf3[256];
  10886.         int len, i, j, state = 0, lo = 0, hi = 0;
  10887.  
  10888.         failed = 0;
  10889.         p = fnval;                      /* Result pointer */
  10890.         *p = NUL;
  10891.         if (!bp[0])                     /* No target, no result*/
  10892.           goto fnend;
  10893.  
  10894.         len = strlen(bp[0]);            /* Length of source */
  10895.         if (len == 0)
  10896.           goto fnend;
  10897.         if (len > FNVALL) {
  10898.             failed = 1;
  10899.             if (fndiags)
  10900.               ckmakmsg(fnval,FNVALL,
  10901.                        "<ERROR:RESULT_TOO_LONG:\\f",fn,"()>",NULL);
  10902.             goto fnend;
  10903.         }
  10904.         if (!bp[1]) {
  10905.             ckstrncpy(bp[0],fnval,FNVALL);
  10906.             goto fnend;
  10907.         }
  10908.         tp[0] = buf1;                   /* For s2-s3 interpretation loop */
  10909.         tp[1] = buf2;
  10910.  
  10911.         for (i = 0; i < 256; i++) {     /* Initialize working buffers */
  10912.             buf1[i] = 0;                /* s2 expansion buffer */
  10913.             buf2[i] = 0;                /* s3 expansion buffer */
  10914.             buf3[i] = i;                /* Translation table */
  10915.         }
  10916.         for (i = 0; i < 2; i++) {       /* Interpret s2 and s3 */
  10917.             s = (CHAR *)bp[i+1];        /* Arg pointer */
  10918.             if (!s) s = (CHAR *)"";
  10919.             r = tp[i];                  /* To construct interpreted arg */
  10920.             j = 0;                      /* Output buf pointer */
  10921.             state = 0;                  /* Initial state */
  10922.             while (c = *s++) {          /* Loop thru arg chars */
  10923.                 if (j > 255)            /* Output buf full */
  10924.                   break;
  10925.                 switch (state) {
  10926.                   case 0:               /* Normal state */
  10927.                     switch (c) {
  10928.                       case '\\':        /* Have quote */
  10929.                         state = 1;
  10930.                         break;
  10931.                       case '[':         /* Have range starter */
  10932.                         state = 2;
  10933.                         break;
  10934.                       default:          /* Anything else */
  10935.                         r[j++] = c;
  10936.                         break;
  10937.                     }
  10938.                     continue;
  10939.                   case 1:               /* Quoted char */
  10940.                     r[j++] = c;
  10941.                     state = 0;
  10942.                     continue;
  10943.                   case 2:               /* Range bottom */
  10944.                     lo = c;
  10945.                     state++;
  10946.                     continue;
  10947.                   case 3:               /* Range separater */
  10948.                     if (c != '-') {
  10949.                         failed = 1;
  10950.                         if (fndiags)
  10951.                           ckmakmsg(fnval,FNVALL,
  10952.                                    "<ERROR:BAD_RANGE:\\f",fn,"()>",NULL);
  10953.                         goto fnend;
  10954.                     }
  10955.                     state++;
  10956.                     continue;
  10957.                   case 4:               /* Range top */
  10958.                     hi = c;
  10959.                     state++;
  10960.                     continue;
  10961.                   case 5:               /* Range end */
  10962.                     if (c != ']') {
  10963.                         failed = 1;
  10964.                         if (fndiags)
  10965.                           ckmakmsg(fnval,FNVALL,
  10966.                                    "<ERROR:BAD_RANGE:\\f",fn,"()>",NULL);
  10967.                         goto fnend;
  10968.                     }
  10969.                     for (k = lo; k <= hi && j < 255; k++) /* Fill in */
  10970.                       r[j++] = k;
  10971.                     lo = 0; hi = 0;     /* Reset */
  10972.                     state = 0;
  10973.                     continue;
  10974.                 }
  10975.             }
  10976.         }
  10977.         for (i = 0; i < 256 && buf1[i]; i++) {  /* Create translation table */
  10978.             k = (unsigned)buf1[i];
  10979.             buf3[k] = buf2[i];
  10980.         }
  10981.         s = (CHAR *)bp[0];              /* Point to source string */
  10982.         for (i = 0; i < len; i++) {     /* Translation loop */
  10983.             k = (unsigned)s[i];         /* Get next char */
  10984.             if (!buf3[k])               /* Remove this char */
  10985.               continue;
  10986.             *p++ = buf3[k];             /* Substitute this char */
  10987.         }
  10988.         *p = NUL;
  10989.         p = fnval;
  10990.         goto fnend;
  10991.     }
  10992.  
  10993. #ifndef NOSEXP
  10994.     if (cx == FN_SEXP) {                /* \fsexpression(arg1) */
  10995.         char * p2;
  10996.         fsexpflag++;
  10997.         p = (argn > 0) ? dosexp(bp[0]) : "";
  10998.         fsexpflag--;
  10999.         p2 = fnval;
  11000.         while ((*p2++ = *p++)) ;
  11001.         p = fnval;
  11002.         goto fnend;
  11003.     }
  11004. #endif /* NOSEXP */
  11005.  
  11006.     if (cx == FN_CMDSTK) {              /* \fcmdstack(n1,n2) */
  11007.         int i, j, k;
  11008.         char * s;
  11009.  
  11010.         if (bp[0])
  11011.           val1 = *(bp[0]) ? evalx(bp[0]) : ckitoa(cmdlvl);
  11012.         else
  11013.           val1 = ckitoa(cmdlvl);
  11014. #ifdef COMMENT
  11015.         free(bp[0]);                    /* (evalx() always uses same buffer) */
  11016.         bp[0] = NULL;                   /* (not any more!) */
  11017. #endif /* COMMENT */
  11018.         failed = 1;
  11019.         if (argn > 1) {
  11020. #ifdef COMMENT
  11021.             makestr(&(bp[0]),val1);
  11022.             val1 = bp[0];
  11023. #endif /* COMMENT */
  11024.             val2 = *(bp[1]) ? evalx(bp[1]) : "0";
  11025.             if (!(chknum(val1) && chknum(val2))) {
  11026.                 if (fndiags)
  11027.                   ckmakmsg(fnval,FNVALL,
  11028.                            "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  11029.                 goto fnend;
  11030.             }
  11031.         } else {
  11032.             val1 = ckitoa(cmdlvl);
  11033.             val2 = "0";
  11034.         }
  11035.         i = atoi(val1);                 /* Level */
  11036.         j = atoi(val2);                 /* Flags */
  11037.         if (i < 0 || i > cmdlvl) {
  11038.             if (fndiags)
  11039.               ckmakmsg(fnval,FNVALL,
  11040.                        "<ERROR:ARG_OUT_OF_RANGE:\\f",fn,"()>",NULL);
  11041.             goto fnend;
  11042.         }
  11043.         failed = 0;
  11044.         p = fnval;
  11045.         k = cmdstk[i].src;              /* What (prompt, file, macro) */
  11046.         if (j) {
  11047.             ckstrncpy(fnval,ckitoa(k),FNVALL);
  11048.             goto fnend;
  11049.         }
  11050.         switch (k) {
  11051.           case CMD_KB:
  11052.             ckstrncpy(fnval,"(prompt)",FNVALL);
  11053.             break;
  11054.           case CMD_TF:
  11055.             s = tfnam[cmdstk[i].lvl];
  11056.             if (!zfnqfp(s,FNVALL,fnval))
  11057.               ckstrncpy(fnval,s,FNVALL);
  11058.             break;
  11059.           case CMD_MD:
  11060.             ckstrncpy(fnval,m_arg[cmdstk[i].lvl][0],FNVALL);
  11061.             break;
  11062.         }
  11063.         goto fnend;
  11064.     }
  11065. #ifdef CKFLOAT
  11066.     if (cx == FN_DIFDATE) {             /* \fdiffdates(d1,d2) */
  11067.         char * d1, * d2;
  11068.         d1 = bp[0] ? bp[0] : ckdate();
  11069.         d2 = bp[1] ? bp[1] : ckdate();
  11070.         p = (char *)cmdiffdate(d1,d2);
  11071.         if (!p) {
  11072.             failed = 1;
  11073.             if (fndiags) {
  11074.                 ckmakmsg(fnval,FNVALL,"<ERROR:BAD_DATE:\\f",fn,"()>",NULL);
  11075.                 p = fnval;
  11076.             }
  11077.         }
  11078.         goto fnend;
  11079.     }
  11080. #endif /* CKFLOAT */
  11081.     if (cx == FN_CMPDATE) {             /* \fcmddates(d1,d2) */
  11082.         int x = 0;
  11083.         char d1[18], d2[18], * dp;
  11084.         failed = 0;
  11085.         d1[0] = NUL;
  11086.         d2[0] = NUL;
  11087.         p = fnval;
  11088.         dp = cmcvtdate(bp[0],1);
  11089.         if (dp) {
  11090.             ckstrncpy(d1,dp,18);
  11091.             if ((dp = cmcvtdate(bp[1],1))) {
  11092.                 ckstrncpy(d2,dp,18);
  11093.                 x = 1;
  11094.             }
  11095.         }
  11096.         if (x == 0) {
  11097.             failed = 1;
  11098.             if (fndiags)
  11099.               ckmakmsg(fnval,FNVALL,"<ERROR:BAD_DATE:\\f",fn,"()>",NULL);
  11100.         } else {
  11101.             x = strcmp(d1,d2);
  11102.             if (x > 0)
  11103.               x = 1;
  11104.             else if (x < 0)
  11105.               x = -1;
  11106.             sprintf(fnval,"%d",x);
  11107.         }
  11108.         goto fnend;
  11109.     }
  11110.     if (cx == FN_TOGMT) {               /* \futcdate(d1) */
  11111.         char * d1, * dp;
  11112.         char datebuf[32];
  11113.         char d2[32];
  11114.         p = fnval;
  11115.         failed = 1;
  11116.         if ((dp = cmcvtdate(bp[0],1))) { /* The given date */
  11117.             ckstrncpy(datebuf,dp,18);
  11118.             ckstrncpy(d2,dp,18);        /* local time */
  11119.             ckstrncat(datebuf,"Z",19);  /* Same time GMT */
  11120.             if ((dp = cmcvtdate(datebuf,1))) /* converted to local time */
  11121.               ckstrncpy(datebuf,dp,18);
  11122.             if ((p = (char *)cmdiffdate(d2,datebuf))) { /* Get offset */
  11123.                 ckstrncat(d2,p,32);     /* Append offset to local time */
  11124.                 if ((dp = cmcvtdate(d2,1))) {
  11125.                     failed = 0;
  11126.                     ckstrncpy(fnval,dp,FNVALL);
  11127.                     p = fnval;
  11128.                 }
  11129.             }
  11130.         }
  11131.         if (failed && fndiags)
  11132.           ckmakmsg(fnval,FNVALL,"<ERROR:BAD_DATE:\\f",fn,"()>",NULL);
  11133.         goto fnend;
  11134.     }
  11135.     if (cx == FN_DELSEC) {              /* \fdelta2secs(delta-time) */
  11136.         long secs;
  11137.         p = fnval;
  11138.         if ((x = delta2sec(bp[0],&secs)) < 0) {
  11139.             failed = 1;
  11140.             if (fndiags)
  11141.               ckmakmsg(fnval,FNVALL,
  11142.                        (x == -1) ?
  11143.                          "<ERROR:BAD_DELTA_TIME:\\f" :
  11144.                          "<ERROR:OVERFLOW:\\f",
  11145.                        fn,
  11146.                        "()>",
  11147.                        NULL
  11148.                        );
  11149.             goto fnend;
  11150.         }
  11151.         sprintf(p,"%ld",secs);
  11152.         goto fnend;
  11153.     }
  11154.     if (cx == FN_PC_DU) {
  11155.         char c, * s = bp[0];
  11156.         if (!s) s = "";
  11157.         p = fnval;
  11158.         while ((c = *s++)) {
  11159.             if (c == ':') {
  11160.                 if (*s != '\\')
  11161.                   *p++ = '/';
  11162.             } else if (c == '\\') {
  11163.                 *p++ = '/';
  11164.             } else {
  11165.                 *p++ = c;
  11166.             }
  11167.         }
  11168.         *p = NUL;
  11169.         p = fnval;
  11170.         goto fnend;
  11171.     }
  11172.     if (cx == FN_PC_UD) {               /* Unix to DOS path */
  11173.         char c, * s = bp[0];
  11174.         if (!s) s = "";
  11175.         if (*s == '~') {                /* Skip leading tilde */
  11176.             s++;
  11177.             if (*s == '/')
  11178.               s++;
  11179.         }
  11180.         p = fnval;
  11181.         while ((c = *s++))
  11182.           *p ++ = (c == '/') ? '\\' : c;
  11183.         *p = NUL;
  11184.         p = fnval;
  11185.         goto fnend;
  11186.     }
  11187.     if (cx == FN_KWVAL) {               /* Keyword=Value */
  11188.         p = dokwval(bp[0],bp[1]?*(bp[1]):'=');
  11189.         goto fnend;
  11190.     }
  11191. #ifdef COMMENT
  11192. /* Cute idea but doesn't work */
  11193.     if (cx == FN_SLEEP || cx == FN_MSLEEP) {
  11194.         p = "";
  11195.         if (chknum(bp[0])) {
  11196.             x = atoi(bp[0]);
  11197.         } else {
  11198.             failed = 1;
  11199.             if (fndiags) {
  11200.                 ckmakmsg(fnval,FNVALL,
  11201.                          "<ERROR:ARG_NOT_NUMERIC:\\f",fn,"()>",NULL);
  11202.                 p = fnval;
  11203.             }
  11204.             goto fnend;
  11205.         }
  11206.         if (cx == FN_SLEEP)
  11207.           x *= 1000;
  11208.         msleep(x);
  11209.         goto fnend;
  11210.     }
  11211. #endif /* COMMENT */
  11212.  
  11213. #ifdef NT
  11214.     if (cx == FN_SNAME) {
  11215.         GetShortPathName(bp[0],fnval,FNVALL);
  11216.         goto fnend;
  11217.     }
  11218.     if (cx == FN_LNAME) {
  11219.         ckGetLongPathName(bp[0],fnval,FNVALL);
  11220.         goto fnend;
  11221.     }
  11222. #endif /* NT */
  11223.  
  11224. /* Note: when adding new functions remember to update dohfunc in ckuus2.c. */
  11225.  
  11226.     failed = 1;
  11227.     if (fndiags)
  11228.       ckmakmsg(fnval,FNVALL,"<ERROR:UNKNOWN_FUNCTION:\\f",fn,"()>",NULL);
  11229.  
  11230.   fnend:
  11231.     /* Free temporary storage for aguments */
  11232.     for (k = 0; k < argn; k++) if (bp[k]) free(bp[k]);
  11233.     fndepth--;
  11234.     if (failed) {                       /* Handle failure */
  11235.         debug(F111,"fnend",fnval,errno);
  11236.         if (!p) p = "";
  11237.         if (p[0]) {
  11238.             /* In case this wasn't caught above... */
  11239.             k = strlen(p);
  11240.             if (p[0] != '<' && p[k-1] != '>') {
  11241.                 ckmakmsg(fnval,FNVALL,"<ERROR:BAD_ARG:\\f",fn,"()>",NULL);
  11242.                 p = fnval;
  11243.             }
  11244.         } else {
  11245.             ckmakmsg(fnval,FNVALL,"<ERROR:UNKNOWN:\\f",fn,"()>",NULL);
  11246.             p = fnval;
  11247.         }
  11248.         if (fnerror)                    /* SET FUNCTION ERROR ON */
  11249.           fnsuccess = 0;                /* Make command fail (see ckuus5.c) */
  11250.         debug(F111,"fneval failed",p,fnsuccess);
  11251.         if (fndiags)                    /* SET FUNCTION DIAGNOSTICS ON */
  11252.           printf("?%s\n",p);            /* Print error message now. */
  11253.         else
  11254.           return("");                   /* Return nothing. */
  11255.     }
  11256.     return(p);
  11257. }
  11258. #endif /* NOSPL */
  11259.  
  11260. static char ckpidbuf[32] = "????";
  11261.  
  11262. #ifdef VMS
  11263. _PROTOTYP(long zgpid,(void));
  11264. #endif /* VMS */
  11265.  
  11266. char *
  11267. ckgetpid() {                            /* Return pid as string */
  11268. #ifdef CK_PID
  11269. #ifdef OS2
  11270. #define getpid _getpid
  11271.     unsigned long zz;
  11272. #else
  11273.     long zz;
  11274. #endif /* OS2 */
  11275. #ifdef VMS
  11276.     zz = zgpid();
  11277. #else
  11278.     zz = getpid();
  11279. #endif /* VMS */
  11280.     sprintf(ckpidbuf,"%ld",zz);         /* SAFE */
  11281. #endif /* CK_PID */
  11282.     return((char *)ckpidbuf);
  11283. }
  11284.  
  11285. #ifndef NOSPL
  11286. #define EMBUFLEN 128                    /* Error message buffer length */
  11287.  
  11288. static char embuf[EMBUFLEN+1];
  11289.  
  11290. char *                                  /* Evaluate builtin variable */
  11291. nvlook(s) char *s; {
  11292.     int x, y, cx;
  11293.     long z;
  11294.     char *p;
  11295. #ifndef NODIAL
  11296.     MDMINF * m;
  11297. #endif /* NODIAL */
  11298. #ifndef NOKVERBS                        /* Keyboard macro material */
  11299.     extern int keymac, keymacx;
  11300. #endif /* NOKVERBS */
  11301. #ifdef CK_LOGIN
  11302.     extern int isguest;
  11303. #endif /* CK_LOGIN */
  11304.     if (!s) s = "";
  11305.     x = strlen(s);
  11306.     if (fndiags) {                      /* FUNCTION DIAGNOSTIC ON */
  11307.         if (x + 32 < EMBUFLEN)
  11308.           sprintf(embuf,"<ERROR:NO_SUCH_VARIABLE:\\v(%s)>",s); /* SAFE */
  11309.         else
  11310.           sprintf(embuf,"<ERROR:NO_SUCH_VARIABLE>"); /* SAFE */
  11311.     } else                              /* FUNCTION DIAGNOSTIC OFF */
  11312.       embuf[0] = NUL;
  11313.     x = VVBUFL;
  11314.     p = vvbuf;
  11315.     if (zzstring(s,&p,&x) < 0) {        /* e.g. for \v(\%a) */
  11316.         y = -1;
  11317.     } else {
  11318.         s = vvbuf;
  11319.         y = lookup(vartab,s,nvars,&x);
  11320.     }
  11321.     cx = y;                             /* y is too generic */
  11322. #ifndef NODIAL
  11323.     m = (mdmtyp > 0) ? modemp[mdmtyp] : NULL; /* For \v(m_xxx) variables */
  11324. #endif /* NODIAL */
  11325.  
  11326.     debug(F101,"nvlook y","",y);
  11327.  
  11328.     switch (y) {
  11329.       case VN_ARGC:                     /* ARGC */
  11330.         sprintf(vvbuf,"%d",maclvl < 0 ? topargc : macargc[maclvl]); /* SAFE */
  11331.         return(vvbuf);
  11332.  
  11333.       case VN_ARGS:                     /* ARGS */
  11334.         sprintf(vvbuf,"%d",xargs);      /* SAFE */
  11335.         return(vvbuf);
  11336.  
  11337.       case VN_COUN:                     /* COUNT */
  11338.         sprintf(vvbuf,"%d",count[cmdlvl]); /* SAFE */
  11339.         return(vvbuf);
  11340.  
  11341.       case VN_DATE:                     /* DATE */
  11342.         ztime(&p);                      /* Get "asctime" string */
  11343.         if (p == NULL || *p == NUL) return(NULL);
  11344.         vvbuf[0] = p[8];                /* dd */
  11345.         vvbuf[1] = p[9];
  11346.         vvbuf[2] = SP;
  11347.         vvbuf[3] = p[4];                /* mmm */
  11348.         vvbuf[4] = p[5];
  11349.         vvbuf[5] = p[6];
  11350.         vvbuf[6] = SP;
  11351.         for (x = 20; x < 24; x++)       /* yyyy */
  11352.           vvbuf[x - 13] = p[x];
  11353.         vvbuf[11] = NUL;
  11354.         return(vvbuf);
  11355.  
  11356.       case VN_NDAT:                     /* Numeric date */
  11357.         ckstrncpy(vvbuf,zzndate(),VVBUFL);
  11358.         return(vvbuf);
  11359.  
  11360.       case VN_DIRE:                     /* DIRECTORY */
  11361.         s = zgtdir();                   /* Get current directory */
  11362.         if (!s)
  11363. #ifdef UNIXOROSK
  11364.           s = "./";
  11365. #else
  11366. #ifdef VMS
  11367.           s = "[]";
  11368. #else
  11369.           s = "";
  11370. #endif /* VMS */
  11371. #endif /* UNIXOROSK */
  11372.         ckstrncpy(vvbuf,s,VVBUFL);
  11373.         s = vvbuf;
  11374. #ifdef UNIXOROSK
  11375.         x = strlen(s);
  11376.         if (x < VVBUFL - 1) {
  11377.             if (s[x-1] != '/') {
  11378.                 s[x] = '/';
  11379.                 s[x+1] = NUL;
  11380.             }
  11381.         }
  11382. #endif /* UNIXOROSK */
  11383.         return(s);
  11384.  
  11385.       case VN_FILE:                     /* filespec */
  11386.         return(fspec);
  11387.  
  11388.       case VN_HOST:                     /* host name */
  11389.         if (*myhost) {                  /* If known */
  11390.             return(myhost);             /* return it. */
  11391.         } else {                        /* Otherwise */
  11392.             ckstrncpy(vvbuf,"unknown",VVBUFL); /* just say "unknown" */
  11393.             return(vvbuf);
  11394.         }
  11395.  
  11396.       case VN_SYST:                     /* System type */
  11397. #ifdef UNIX
  11398.         ckstrncpy(vvbuf,"UNIX",VVBUFL);
  11399. #else
  11400. #ifdef VMS
  11401.         ckstrncpy(vvbuf,"VMS",VVBUFL);
  11402. #else
  11403. #ifdef OSK
  11404.         ckstrncpy(vvbuf,"OS9/68K",VVBUFL);
  11405. #else
  11406. #ifdef AMIGA
  11407.         ckstrncpy(vvbuf,"Amiga",VVBUFL);
  11408. #else
  11409. #ifdef MAC
  11410.         ckstrncpy(vvbuf,"Macintosh",VVBUFL);
  11411. #else
  11412. #ifdef OS2
  11413. #ifdef NT
  11414.         ckstrncpy(vvbuf,"WIN32",VVBUFL) ;
  11415. #else /* NT */
  11416.         ckstrncpy(vvbuf,"OS/2",VVBUFL);
  11417. #endif /* NT */
  11418. #else
  11419. #ifdef datageneral
  11420.         ckstrncpy(vvbuf,"AOS/VS",VVBUFL);
  11421. #else
  11422. #ifdef GEMDOS
  11423.         ckstrncpy(vvbuf,"Atari_ST",VVBUFL);
  11424. #else
  11425. #ifdef STRATUS
  11426.         ckstrncpy(vvbuf,"Stratus_VOS",VVBUFL);
  11427. #else
  11428.         ckstrncpy(vvbuf,"unknown",VVBUFL);
  11429. #endif /* STRATUS */
  11430. #endif /* GEMDOS */
  11431. #endif /* datageneral */
  11432. #endif /* OS2 */
  11433. #endif /* MAC */
  11434. #endif /* AMIGA */
  11435. #endif /* OSK */
  11436. #endif /* VMS */
  11437. #endif /* UNIX */
  11438.         return(vvbuf);
  11439.  
  11440.       case VN_SYSV:                     /* System herald */
  11441. #ifdef IKSD
  11442. #ifdef CK_LOGIN
  11443.         if (inserver && isguest)
  11444.           return("");
  11445. #endif /* CK_LOGIN */
  11446. #endif /* IKSD */
  11447.         for (x = y = 0; x < VVBUFL; x++) {
  11448.             if (ckxsys[x] == SP && y == 0) continue;
  11449.             vvbuf[y++] = (char) ((ckxsys[x] == SP) ? '_' : ckxsys[x]);
  11450.         }
  11451.         vvbuf[y] = NUL;
  11452.         return(vvbuf);
  11453.     } /* Break up long switch statements... */
  11454.  
  11455.     switch(y) {
  11456.       case VN_TIME:                     /* TIME. Assumes that ztime returns */
  11457.         ztime(&p);                      /* "Thu Feb  8 12:00:00 1990" */
  11458.         if (p == NULL || *p == NUL)     /* like asctime()! */
  11459.           return("");
  11460.         for (x = 11; x < 19; x++)       /* copy hh:mm:ss */
  11461.           vvbuf[x - 11] = p[x];         /* to vvbuf */
  11462.         vvbuf[8] = NUL;                 /* terminate */
  11463.         return(vvbuf);                  /* and return it */
  11464.  
  11465.       case VN_NTIM:                     /* Numeric time */
  11466.         ztime(&p);                      /* "Thu Feb  8 12:00:00 1990" */
  11467.         if (p == NULL || *p == NUL)     /* like asctime()! */
  11468.           return(NULL);
  11469.         z = atol(p+11) * 3600L + atol(p+14) * 60L + atol(p+17);
  11470.         sprintf(vvbuf,"%ld",z);         /* SAFE */
  11471.         return(vvbuf);
  11472.  
  11473. #ifdef CK_TTYFD
  11474.       case VN_TTYF:                     /* TTY file descriptor */
  11475.         sprintf(vvbuf,"%d",             /* SAFE */
  11476. #ifdef VMS
  11477.                 vmsttyfd()
  11478. #else
  11479.                 ttyfd
  11480. #endif /* VMS */
  11481.                 );
  11482.         return(vvbuf);
  11483. #endif /* CK_TTYFD */
  11484.  
  11485.       case VN_VERS:                     /* Numeric Kermit version number */
  11486.         sprintf(vvbuf,"%ld",vernum);    /* SAFE */
  11487.         return(vvbuf);
  11488.  
  11489.       case VN_XVNUM:                    /* Product-specific version number */
  11490.         sprintf(vvbuf,"%ld",xvernum);   /* SAFE */
  11491.         return(vvbuf);
  11492.  
  11493.       case VN_HOME:                     /* Home directory */
  11494.         return(homepath());
  11495.  
  11496.       case VN_IBUF:                     /* INPUT buffer */
  11497.         return((char *)inpbuf);
  11498.  
  11499.       case VN_ICHR:                     /* INPUT character */
  11500.         inchar[1] = NUL;
  11501.         return((char *)inchar);
  11502.  
  11503.       case VN_ICNT:                     /* INPUT character count */
  11504.         sprintf(vvbuf,"%d",incount);    /* SAFE */
  11505.         return(vvbuf);
  11506.  
  11507.       case VN_SPEE: {                   /* Transmission SPEED */
  11508.           long t;
  11509.           t = ttgspd();
  11510.           if (t < 0L)
  11511.             sprintf(vvbuf,"unknown");   /* SAFE */
  11512.           else
  11513.             sprintf(vvbuf,"%ld",t);     /* SAFE */
  11514.           return(vvbuf);
  11515.       }
  11516.  
  11517.       case VN_SUCC:                     /* SUCCESS flag */
  11518.         /* Note inverted sense */
  11519.         sprintf(vvbuf,"%d",(success == 0) ? 1 : 0); /* SAFE */
  11520.         return(vvbuf);
  11521.  
  11522.       case VN_LINE: {                   /* LINE */
  11523. #ifdef DEBUG
  11524.           if (deblog) {
  11525.               debug(F111,"\\v(line) local",ttname,local);
  11526.               debug(F111,"\\v(line) inserver","",inserver);
  11527. #ifdef TNCODE
  11528.               debug(F111,"\\v(line) tcp_incoming","",tcp_incoming);
  11529. #endif /* TNCODE */
  11530. #ifdef CK_TAPI
  11531.               debug(F111,"\\v(line) tttapi","",tttapi);
  11532. #endif /* CK_TAPI */
  11533.           }
  11534. #endif /* DEBUG */
  11535.  
  11536. #ifdef CK_TAPI
  11537.           if (tttapi) {                 /* If I have made a TAPI connection */
  11538.               int i;                    /* return the TAPI device name */
  11539.               for (i = 0; i < ntapiline; i++) {
  11540.                   if (!strcmp(ttname,tapilinetab[i].kwd)) {
  11541.                       p = _tapilinetab[i].kwd;
  11542.                       return(p);
  11543.                   }
  11544.               }
  11545.           }
  11546. #endif /* CK_TAPI */
  11547. #ifndef NOXFER
  11548.           if (inserver                  /* If I am a TCP server */
  11549. #ifdef TNCODE
  11550.               || tcp_incoming
  11551. #endif /* TNCODE */
  11552.               )
  11553. #ifdef TCPSOCKET
  11554.             p = ckgetpeer();            /* return peer name */
  11555.           else
  11556. #endif /* TCPSOCKET */
  11557. #endif /* NOXFER */
  11558.           if (local)                    /* Otherwise if in local mode */
  11559.             p = (char *) ttname;        /* return SET LINE / SET HOST name */
  11560.           else                          /* Otherwise */
  11561.             p = "";                     /* return empty string */
  11562.           if (!p)                       /* In case ckgetpeer() returns */
  11563.             p = "";                     /* null pointer... */
  11564.           debug(F110,"\\v(line) p",p,0);
  11565.           if (!*p)
  11566.             p = (char *) ttname;
  11567.           return(p);
  11568.       }
  11569.       case VN_PROG:                     /* Program name */
  11570.         return("C-Kermit");
  11571.  
  11572.     } /* Break up long switch statements... */
  11573.  
  11574.     switch(y) {
  11575.       case VN_RET:                      /* Value of most recent RETURN */
  11576.         debug(F111,"\\v(return)",mrval[maclvl+1],maclvl+1);
  11577.         p = mrval[maclvl+1];
  11578.         if (p == NULL) p = "";
  11579.         return(p);
  11580.  
  11581.       case VN_FFC:                      /* Size of most recent file */
  11582.         sprintf(vvbuf, "%ld", ffc);     /* SAFE */
  11583.         return(vvbuf);
  11584.  
  11585.       case VN_TFC:                      /* Size of most recent file group */
  11586.         sprintf(vvbuf, "%ld", tfc);     /* SAFE */
  11587.         return(vvbuf);
  11588.  
  11589.       case VN_CPU:                      /* CPU type */
  11590. #ifdef IKSD
  11591. #ifdef CK_LOGIN
  11592.         if (inserver && isguest)
  11593.           return("");
  11594. #endif /* CK_LOGIN */
  11595. #endif /* IKSD */
  11596. #ifdef OS2
  11597.          {
  11598.             char * getcpu(void) ;
  11599.             return getcpu();
  11600.          }
  11601. #else /* OS2 */
  11602. #ifdef CKCPU
  11603.         return(CKCPU);                  /* Traditionally, compile-time value */
  11604. #else
  11605. #ifdef CK_UTSNAME
  11606.         {                               /* But if none, try runtime value */
  11607.             extern char unm_mch[];
  11608.             return((char *)unm_mch);
  11609.         }
  11610. #else
  11611.         return("unknown");
  11612. #endif /* CK_UTSNAME */
  11613. #endif /* CKCPU */
  11614. #endif /* OS2 */
  11615.  
  11616.       case VN_CMDL:                     /* Command level */
  11617.         sprintf(vvbuf, "%d", cmdlvl);   /* SAFE */
  11618.         return(vvbuf);
  11619.  
  11620.       case VN_DAY:                      /* Day of week */
  11621.         ztime(&p);
  11622.         if (p != NULL && *p != NUL)     /* ztime() succeeded. */
  11623.           ckstrncpy(vvbuf,p,4);
  11624.         else
  11625.           vvbuf[0] = NUL;               /* ztime() failed. */
  11626.         return(vvbuf);                  /* Return what we got. */
  11627.  
  11628.       case VN_NDAY: {                   /* Numeric day of week */
  11629.           long k;
  11630.           z = mjd(zzndate());           /* Get modified Julian date */
  11631.           k = (((int)(z % 7L)) + 3) % 7; /* Get day number */
  11632.           sprintf(vvbuf,"%ld",k);       /* SAFE */
  11633.           return(vvbuf);
  11634.       }
  11635.  
  11636.       case VN_LCL:                      /* Local (vs remote) mode */
  11637.         ckstrncpy(vvbuf, local ? "1" : "0",VVBUFL);
  11638.         return(vvbuf);
  11639.  
  11640.       case VN_CMDS:                     /* Command source */
  11641.         if (cmdstk[cmdlvl].src == CMD_KB)
  11642.           ckstrncpy(vvbuf,"prompt",VVBUFL);
  11643.         else if (cmdstk[cmdlvl].src == CMD_MD)
  11644.           ckstrncpy(vvbuf,"macro",VVBUFL);
  11645.         else if (cmdstk[cmdlvl].src == CMD_TF)
  11646.           ckstrncpy(vvbuf,"file",VVBUFL);
  11647.         else
  11648.           ckstrncpy(vvbuf,"unknown",VVBUFL);
  11649.         return(vvbuf);
  11650.  
  11651.       case VN_CMDF:                     /* Current command file name */
  11652. #ifdef COMMENT                          /* (see comments above) */
  11653.         if (tfnam[tlevel]) {            /* (near dblbs declaration) */
  11654.             dblbs(tfnam[tlevel],vvbuf,VVBUFL);
  11655.             return(vvbuf);
  11656.         } else return("");
  11657. #else
  11658.         if (tlevel < 0)
  11659.           return("");
  11660.         else
  11661.           return(tfnam[tlevel] ? tfnam[tlevel] : "");
  11662. #endif /* COMMENT */
  11663.  
  11664.       case VN_MAC:                      /* Current macro name */
  11665.         return((maclvl > -1) ? m_arg[maclvl][0] : "");
  11666.  
  11667.       case VN_EXIT:
  11668.         sprintf(vvbuf,"%d",xitsta);     /* SAFE */
  11669.         return(vvbuf);
  11670.  
  11671.     } /* Break up long switch statements... */
  11672.  
  11673.     switch(y) {
  11674.       case VN_PRTY: {                   /* Parity */
  11675.           char *ss;
  11676.           switch (parity) {
  11677.             case 0:   ss = "none";  break;
  11678.             case 'e': ss = "even";  break;
  11679.             case 'm': ss = "mark";  break;
  11680.             case 'o': ss = "odd";   break;
  11681.             case 's': ss = "space"; break;
  11682.             default:  ss = "unknown"; break;
  11683.           }
  11684.           ckstrncpy(vvbuf,ss,VVBUFL);
  11685.           return(vvbuf);
  11686.       }
  11687.  
  11688.       case VN_DIAL:
  11689.         sprintf(vvbuf,"%d",             /* SAFE */
  11690. #ifndef NODIAL
  11691.                 dialsta
  11692. #else
  11693.                 -1
  11694. #endif /* NODIAL */
  11695.                 );
  11696.         return(vvbuf);
  11697.  
  11698. #ifdef OS2
  11699.       case VN_KEYB:
  11700.         ckstrncpy(vvbuf,conkbg(),VVBUFL);
  11701.         return(vvbuf);
  11702.       case VN_SELCT: {
  11703. #ifndef NOLOCAL
  11704.           const char * selection = GetSelection();
  11705.           return( (char *) (selection ? selection : "" )) ;
  11706. #else
  11707.           return("");
  11708. #endif /* NOLOCAL */
  11709.       }
  11710. #endif /* OS2 */
  11711.  
  11712. #ifndef NOXFER
  11713.       case VN_CPS:
  11714.         sprintf(vvbuf,"%ld",tfcps);     /* SAFE */
  11715.         return(vvbuf);
  11716. #endif /* NOXFER */
  11717.  
  11718.       case VN_MODE:                     /* File transfer mode */
  11719.         switch (binary) {
  11720.           case XYFT_T: ckstrncpy(vvbuf,"text",VVBUFL); break;
  11721.           case XYFT_B:
  11722.           case XYFT_U: ckstrncpy(vvbuf,"binary",VVBUFL); break;
  11723.           case XYFT_I: ckstrncpy(vvbuf,"image",VVBUFL); break;
  11724.           case XYFT_L: ckstrncpy(vvbuf,"labeled",VVBUFL); break;
  11725.           case XYFT_M: ckstrncpy(vvbuf,"macbinary",VVBUFL); break;
  11726.           default:     ckstrncpy(vvbuf,"unknown",VVBUFL);
  11727.         }
  11728.         return(vvbuf);
  11729.  
  11730. #ifdef CK_REXX
  11731.       case VN_REXX:
  11732.         return(rexxbuf);
  11733. #endif /* CK_REXX */
  11734.  
  11735.       case VN_NEWL:                     /* System newline char or sequence */
  11736. #ifdef UNIX
  11737.         ckstrncpy(vvbuf,"\n",VVBUFL);
  11738. #else
  11739. #ifdef datageneral
  11740.         ckstrncpy(vvbuf,"\n",VVBUFL);
  11741. #else
  11742. #ifdef OSK
  11743.         ckstrncpy(vvbuf,"\15",VVBUFL);  /* Remember, these are octal... */
  11744. #else
  11745. #ifdef MAC
  11746.         ckstrncpy(vvbuf,"\15",VVBUFL);
  11747. #else
  11748. #ifdef OS2
  11749.         ckstrncpy(vvbuf,"\15\12",VVBUFL);
  11750. #else
  11751. #ifdef STRATUS
  11752.         ckstrncpy(vvbuf,"\n",VVBUFL);
  11753. #else
  11754. #ifdef VMS
  11755.         ckstrncpy(vvbuf,"\15\12",VVBUFL);
  11756. #else
  11757. #ifdef AMIGA
  11758.         ckstrncpy(vvbuf,"\n",VVBUFL);
  11759. #else
  11760. #ifdef GEMDOS
  11761.         ckstrncpy(vvbuf,"\n",VVBUFL);
  11762. #else
  11763.         ckstrncpy(vvbuf,"\n",VVBUFL);
  11764. #endif /* GEMDOS */
  11765. #endif /* AMIGA */
  11766. #endif /* VMS */
  11767. #endif /* STRATUS */
  11768. #endif /* OS2 */
  11769. #endif /* MAC */
  11770. #endif /* OSK */
  11771. #endif /* datageneral */
  11772. #endif /* UNIX */
  11773.         return(vvbuf);
  11774.  
  11775.       case VN_ROWS:                     /* ROWS */
  11776.       case VN_COLS:                     /* COLS */
  11777.         ckstrncpy(vvbuf,(cx == VN_ROWS) ? "24" : "80",VVBUFL); /* Default */
  11778. #ifdef CK_TTGWSIZ
  11779. #ifdef OS2
  11780.         if (tt_cols[VTERM] < 0 || tt_rows[VTERM] < 0)
  11781.           ttgwsiz();
  11782.         sprintf(vvbuf,"%d",             /* SAFE */
  11783.                 (cx == VN_ROWS) ? tt_rows[VTERM] : tt_cols[VTERM]);
  11784. #else /* OS2 */
  11785.         if (ttgwsiz() > 0)              /* Get window size */
  11786.           if (tt_cols > 0 && tt_rows > 0) /* sets tt_rows, tt_cols */
  11787.             sprintf(vvbuf,"%d",         /* SAFE */
  11788.                     (cx == VN_ROWS) ? tt_rows : tt_cols);
  11789. #endif /* OS2 */
  11790. #endif /* CK_TTGWSIZ */
  11791.         return(vvbuf);
  11792.  
  11793.       case VN_TTYP:
  11794. #ifdef NOTERM
  11795.         ckstrncpy(vvbuf,"unknown",VVBUFL);
  11796. #else
  11797. #ifdef OS2
  11798.         sprintf(vvbuf, "%s",            /* SAFE */
  11799.                 (tt_type >= 0 && tt_type <= max_tt) ?
  11800.                 tt_info[tt_type].x_name :
  11801.                 "unknown"
  11802.                 );
  11803. #else
  11804. #ifdef MAC
  11805.         ckstrncpy(vvbuf,"vt320",VVBUFL);
  11806. #else
  11807.         p = getenv("TERM");
  11808.         ckstrncpy(vvbuf,p ? p : "unknown",VVBUFL+1);
  11809. #endif /* MAC */
  11810. #endif /* OS2 */
  11811. #endif /* NOTERM */
  11812.         return(vvbuf);
  11813.  
  11814.       case VN_MINP:                     /* MINPUT */
  11815.         sprintf(vvbuf, "%d", m_found);  /* SAFE */
  11816.         return(vvbuf);
  11817.     } /* Break up long switch statements... */
  11818.  
  11819.     switch(y) {
  11820.       case VN_CONN:                     /* CONNECTION */
  11821.         if (!local) {
  11822.           ckstrncpy(vvbuf,"remote",VVBUFL);
  11823.         } else {
  11824.             if (!network)
  11825.               ckstrncpy(vvbuf,"serial",VVBUFL);
  11826. #ifdef TCPSOCKET
  11827.             else if (nettype == NET_TCPB || nettype == NET_TCPA) {
  11828.                 if (ttnproto == NP_TELNET)
  11829.                   ckstrncpy(vvbuf,"tcp/ip_telnet",VVBUFL);
  11830. #ifdef CK_SSL
  11831.                 else if (ttnproto == NP_SSL)
  11832.                   ckstrncpy(vvbuf,"tcp/ip_ssl",VVBUFL);
  11833.                 else if (ttnproto == NP_TLS)
  11834.                   ckstrncpy(vvbuf,"tcp/ip_tls",VVBUFL);
  11835. #endif /* CK_SSL */
  11836.                 else
  11837.                   ckstrncpy(vvbuf,"tcp/ip",VVBUFL);
  11838.             }
  11839. #endif /* TCPSOCKET */
  11840. #ifdef SSHBUILTIN
  11841.             else if (nettype == NET_SSH)
  11842.                   ckstrncpy(vvbuf,"tcp/ip_ssh",VVBUFL);
  11843. #endif /* SSHBUILTIN */
  11844. #ifdef ANYX25
  11845.             else if (nettype == NET_SX25 ||
  11846.                      nettype == NET_VX25 ||
  11847.                      nettype == NET_IX25
  11848.                      )
  11849.               ckstrncpy(vvbuf,"x.25",VVBUFL);
  11850. #endif /* ANYX25 */
  11851. #ifdef DECNET
  11852.             else if (nettype == NET_DEC) {
  11853.                 if (ttnproto == NP_LAT)
  11854.                   ckstrncpy(vvbuf,"decnet_lat",VVBUFL);
  11855.                 else if ( ttnproto == NP_CTERM )
  11856.                   ckstrncpy(vvbuf,"decnet_cterm",VVBUFL);
  11857.                 else
  11858.                   ckstrncpy(vvbuf,"decnet",VVBUFL);
  11859.             }
  11860. #endif /* DECNET */
  11861. #ifdef SUPERLAT
  11862.             else if (nettype == NET_SLAT)
  11863.               ckstrncpy(vvbuf,"superlat",VVBUFL);
  11864. #endif /* SUPERLAT */
  11865. #ifdef NETFILE
  11866.             else if (nettype == NET_FILE)
  11867.               ckstrncpy(vvbuf,"local_file",VVBUFL);
  11868. #endif /* NETFILE */
  11869. #ifdef NETCMD
  11870.             else if (nettype == NET_CMD)
  11871.               ckstrncpy(vvbuf,"pipe",VVBUFL);
  11872. #endif /* NETCMD */
  11873. #ifdef NETPTY
  11874.             else if (nettype == NET_PTY)
  11875.               ckstrncpy(vvbuf,"pseudoterminal",VVBUFL);
  11876. #endif /* NETPTY */
  11877. #ifdef NETDLL
  11878.             else if (nettype == NET_DLL)
  11879.               ckstrncpy(vvbuf,"dynamic_link_library",VVBUFL);
  11880. #endif /* NETDLL */
  11881.  
  11882. #ifdef NPIPE
  11883.             else if (nettype == NET_PIPE)
  11884.               ckstrncpy(vvbuf,"named_pipe",VVBUFL);
  11885. #endif /* NPIPE */
  11886. #ifdef CK_NETBIOS
  11887.             else if (nettype == NET_BIOS)
  11888.               ckstrncpy(vvbuf,"netbios",VVBUFL);
  11889. #endif /* CK_NETBIOS */
  11890.             else
  11891.               ckstrncpy(vvbuf,"unknown",VVBUFL);
  11892.         }
  11893.         return(vvbuf);
  11894.  
  11895. #ifndef NOXFER
  11896.       case VN_SYSI:                     /* System ID, Kermit code */
  11897.         return((char *)cksysid);
  11898. #endif /* NOXFER */
  11899.  
  11900. #ifdef OS2
  11901.       case VN_SPA: {
  11902.           unsigned long space = zdskspace(0);
  11903.           if (space > 0 && space < 1024)
  11904.             sprintf(vvbuf,"-1");
  11905.           else
  11906.             sprintf(vvbuf,"%lu",space); /* SAFE */
  11907.           return(vvbuf);
  11908.       }
  11909. #endif /* OS2 */
  11910.  
  11911. #ifndef NOXFER
  11912.       case VN_QUE: {
  11913.           extern char querybuf[];
  11914.           return(querybuf);
  11915.       }
  11916. #endif /* NOXFER */
  11917.  
  11918. #ifndef NOCSETS
  11919.       case VN_CSET:
  11920. #ifdef OS2
  11921.         sprintf(vvbuf,"cp%d",os2getcp()); /* SAFE */
  11922. #else
  11923.         ckstrncpy(vvbuf,fcsinfo[fcharset].keyword,VVBUFL+1);
  11924. #endif /* OS2 */
  11925.         return(vvbuf);
  11926. #endif /* NOCSETS */
  11927.  
  11928. #ifdef OS2
  11929.       case VN_EXEDIR:
  11930.         return(exedir);
  11931.       case VN_STAR:
  11932.         return(startupdir);
  11933. #else
  11934.       case VN_EXEDIR:
  11935.         return(exedir ? exedir : "");
  11936. #ifdef VMSORUNIX
  11937.       case VN_STAR:
  11938.         return(startupdir);
  11939. #endif /* VMSORUNIX */
  11940. #endif /* OS2 */
  11941.  
  11942.       case VN_INI:
  11943.         return(inidir);
  11944.  
  11945.       case VN_MDM:
  11946.         return(gmdmtyp());
  11947.  
  11948.       case VN_EVAL:
  11949.         return(evalbuf);
  11950.  
  11951. #ifndef NODIAL
  11952.       case VN_D_CC:                     /* DIAL COUNTRY-CODE */
  11953.         return(diallcc ? diallcc : "");
  11954.  
  11955.       case VN_D_AC:                     /* DIAL AREA-CODE */
  11956.         return(diallac ? diallac : "");
  11957.  
  11958.       case VN_D_IP:                     /* DIAL INTERNATIONAL-PREFIX */
  11959.         return(dialixp ? dialixp : "");
  11960.  
  11961.       case VN_D_LP:                     /* DIAL LD-PREFIX */
  11962.         return(dialldp ? dialldp : "");
  11963.  
  11964.       case VN_D_LCP:                    /* DIAL LOCAL-PREFIX */
  11965.         return(diallcp ? diallcp : "");
  11966.  
  11967.       case VN_D_PXX:                    /* DIAL PBX-EXCHANGE that matched */
  11968.         return(matchpxx ? matchpxx : "");
  11969. #else
  11970.       case VN_D_CC:                     /* DIAL COUNTRY-CODE */
  11971.       case VN_D_AC:                     /* DIAL AREA-CODE */
  11972.       case VN_D_IP:                     /* DIAL INTERNATIONAL-PREFIX */
  11973.       case VN_D_LP:                     /* DIAL LD-PREFIX */
  11974.       case VN_D_LCP:                    /* DIAL LOCAL-PREFIX */
  11975.       case VN_D_PXX:                    /* DIAL PBX-EXCHANGE */
  11976.         return("");
  11977. #endif /* NODIAL */
  11978.       case VN_UID:
  11979. #ifdef UNIX
  11980.         {
  11981.             extern char * whoami();     /* From ckufio.c... */
  11982. #ifdef IKSD
  11983.             if (inserver)
  11984.               return((char *)uidbuf);
  11985.             else
  11986. #endif /* IKSD */
  11987.               if (uidbuf[0])
  11988.                 return((char *)uidbuf);
  11989.               else
  11990.                 return(whoami());
  11991.         }
  11992. #else
  11993.         return((char *)uidbuf);
  11994. #endif /* UNIX */
  11995.     } /* Break up long switch statements... */
  11996.  
  11997.     switch(y) {
  11998.       case VN_PWD:
  11999. #ifdef OS2
  12000.         if (activecmd == XXOUT || activecmd == XXLNOUT) {
  12001.             ckstrncpy(vvbuf,pwbuf,VVBUFL);
  12002.             ck_encrypt((char *)vvbuf);
  12003.             return((char *)vvbuf);
  12004.         } else
  12005. #endif /* OS2 */
  12006.           return((char *)pwbuf);
  12007.  
  12008.       case VN_PRM:
  12009.         return((char *)prmbuf);
  12010.  
  12011.       case VN_PROTO:
  12012. #ifdef NOXFER
  12013.         return("none");
  12014. #else
  12015. #ifdef CK_XYZ
  12016.         return(ptab[protocol].p_name);
  12017. #else
  12018.         return("kermit");
  12019. #endif /* CK_XYZ */
  12020. #endif /* NOXFER */
  12021.  
  12022. #ifndef NOXFER
  12023. #ifdef CK_TMPDIR
  12024.       case VN_DLDIR:
  12025.         return(dldir ? dldir : "");
  12026. #endif /* CK_TMPDIR */
  12027. #endif /* NOXFER */
  12028.  
  12029. #ifndef NODIAL
  12030.       case VN_M_INI:                    /* Modem init string */
  12031.         return(dialini ? dialini : (m ? m->wake_str : ""));
  12032.  
  12033.       case VN_M_DCM:                    /* Modem dial command */
  12034.         return(dialcmd ? dialcmd : (m ? m->dial_str : ""));
  12035.  
  12036.       case VN_M_DCO:                    /* Modem data compression on */
  12037.         return(dialdcon ? dialdcon : (m ? m->dc_on_str : ""));
  12038.  
  12039.       case VN_M_DCX:                    /* Modem data compression off */
  12040.         return(dialdcoff ? dialdcoff : (m ? m->dc_off_str : ""));
  12041.  
  12042.       case VN_M_ECO:                    /* Modem error correction on */
  12043.         return(dialecon ? dialecon : (m ? m->ec_on_str : ""));
  12044.  
  12045.       case VN_M_ECX:                    /* Modem error correction off */
  12046.         return(dialecoff ? dialecoff : (m ? m->ec_off_str : ""));
  12047.  
  12048.       case VN_M_AAO:                    /* Modem autoanswer on */
  12049.         return(dialaaon ? dialaaon : (m ? m->aa_on_str : ""));
  12050.  
  12051.       case VN_M_AAX:                    /* Modem autoanswer off */
  12052.         return(dialaaoff ? dialaaoff : (m ? m->aa_off_str : ""));
  12053.  
  12054.       case VN_M_HUP:                    /* Modem hangup command */
  12055.         return(dialhcmd ? dialhcmd : (m ? m->hup_str : ""));
  12056.  
  12057.       case VN_M_HWF:                    /* Modem hardware flow command */
  12058.         return(dialhwfc ? dialhwfc : (m ? m->hwfc_str : ""));
  12059.  
  12060.       case VN_M_SWF:                    /* Modem software flow command */
  12061.         return(dialswfc ? dialswfc : (m ? m->swfc_str : ""));
  12062.  
  12063.       case VN_M_NFC:                    /* Modem no flow-control command */
  12064.         return(dialnofc ? dialnofc : (m ? m->nofc_str : ""));
  12065.  
  12066.       case VN_M_PDM:                    /* Modem pulse dialing mode */
  12067.         return(dialpulse ? dialpulse : (m ? m->pulse : ""));
  12068.  
  12069.       case VN_M_TDM:                    /* Modem tone dialing mode */
  12070.         return(dialtone ? dialtone : (m ? m->tone : ""));
  12071.  
  12072.       case VN_M_NAM:                    /* Modem full name */
  12073.         return(dialname ? dialname : (m ? m->name : ""));
  12074. #else
  12075.       case VN_M_INI:                    /* Modem init string */
  12076.       case VN_M_DCM:                    /* Modem dial command */
  12077.       case VN_M_DCO:                    /* Modem data compression on */
  12078.       case VN_M_DCX:                    /* Modem data compression off */
  12079.       case VN_M_ECO:                    /* Modem error correction on */
  12080.       case VN_M_ECX:                    /* Modem error correction off */
  12081.       case VN_M_AAO:                    /* Modem autoanswer on */
  12082.       case VN_M_AAX:                    /* Modem autoanswer off */
  12083.       case VN_M_HUP:                    /* Modem hangup command */
  12084.       case VN_M_HWF:                    /* Modem hardware flow command */
  12085.       case VN_M_SWF:                    /* Modem software flow command */
  12086.       case VN_M_NFC:                    /* Modem no flow-control command */
  12087.       case VN_M_PDM:                    /* Modem pulse dialing mode */
  12088.       case VN_M_TDM:                    /* Modem tone dialing mode */
  12089.       case VN_M_NAM:
  12090.         return("");
  12091. #endif /* NODIAL */
  12092.  
  12093.       case VN_ISTAT:                    /* INPUT status */
  12094.         sprintf(vvbuf, "%d", instatus); /* SAFE */
  12095.         return(vvbuf);
  12096.  
  12097.       case VN_TEMP:                     /* Temporary directory */
  12098.         if (tempdir) {
  12099.             p = tempdir;
  12100.         } else {
  12101. #ifdef OS2
  12102. #ifdef NT
  12103.             p = getenv("K95TMP");
  12104. #else
  12105.             p = getenv("K2TMP");
  12106. #endif /* NT */
  12107.             if ( !p )
  12108. #endif /* OS2 */
  12109.               p = getenv("CK_TMP");
  12110.             if (!p) p = getenv("TMPDIR");
  12111.             if (!p) p = getenv("TEMP");
  12112.             if (!p) p = getenv("TMP");
  12113.  
  12114. #ifdef OS2ORUNIX
  12115.             if (p) {
  12116.                 int len = strlen(p);
  12117.                 if (p[len-1] != '/'
  12118. #ifdef OS2
  12119.                     && p[len-1] != '\\'
  12120. #endif /* OS2 */
  12121.                      ) {
  12122.                     static char foo[CKMAXPATH];
  12123.                     ckstrncpy(foo,p,CKMAXPATH);
  12124.                     ckstrncat(foo,"/",CKMAXPATH);
  12125.                     p = foo;
  12126.                 }
  12127.             } else
  12128. #else /* OS2ORUNIX */
  12129.             if (!p)
  12130. #endif /* OS2ORUNIX */
  12131. #ifdef UNIX                             /* Systems that have a standard */
  12132.               p = "/tmp/";              /* temporary directory... */
  12133. #else
  12134. #ifdef datageneral
  12135.               p = ":TMP:";
  12136. #else
  12137.               p = "";
  12138. #endif /* datageneral */
  12139. #endif /* UNIX */
  12140.         }
  12141.         ckstrncpy(vvbuf,p,VVBUFL);
  12142.         p = vvbuf;
  12143.  
  12144. /* This needs generalizing for VOS, AOS/VS, etc... */
  12145.  
  12146.         while (*p) {
  12147. #ifdef OS2
  12148.             if (*p == '\\') *p = '/';
  12149. #endif /* OS2 */
  12150.             p++;
  12151.         }
  12152. #ifndef VMS
  12153.         if (p > vvbuf) {
  12154.             char c =                    /* Directory termination character */
  12155. #ifdef MAC
  12156.               ':'
  12157. #else
  12158. #ifdef datageneral
  12159.               ':'
  12160. #else
  12161. #ifdef STRATUS
  12162.               '>'
  12163. #else
  12164.               '/'
  12165. #endif /* STRATUS */
  12166. #endif /* datageneral */
  12167. #endif /* MAC */
  12168.                 ;
  12169.  
  12170.             if (*(p-1) != c) {
  12171.                 *p++ = c;
  12172.                 *p = NUL;
  12173.             }
  12174.         }
  12175. #endif /* VMS */
  12176.         return(vvbuf);
  12177.     } /* Break up long switch statements... */
  12178.  
  12179.     switch(y) {
  12180.       case VN_ERRNO:                    /* Error number */
  12181. #ifdef VMS
  12182.         {
  12183.             extern int vms_lasterr;
  12184.             sprintf(vvbuf, "%d", vms_lasterr); /* SAFE */
  12185.         }
  12186. #else
  12187.         sprintf(vvbuf, "%d", errno);    /* SAFE */
  12188. #endif /* VMS */
  12189.         return(vvbuf);
  12190.  
  12191.       case VN_ERSTR:                    /* Error string */
  12192.         ckstrncpy(vvbuf,ck_errstr(),VVBUFL);
  12193.         return(vvbuf);
  12194.  
  12195. #ifndef NOXFER
  12196.       case VN_RPSIZ:                    /* RECEIVE packet-length */
  12197.         sprintf(vvbuf,"%d",urpsiz);     /* SAFE */
  12198.         return(vvbuf);
  12199.  
  12200.       case VN_WINDO:                    /* WINDOW slots */
  12201.         sprintf(vvbuf,"%d",wslotr);     /* SAFE */
  12202.         return(vvbuf);
  12203. #endif /* NOXFER */
  12204.  
  12205.       case VN_TFLN:                     /* TAKE-file line number */
  12206.         if (tlevel > -1) {
  12207.             sprintf(vvbuf, "%d", tfline[tlevel]); /* SAFE */
  12208.             return(vvbuf);
  12209.         } else
  12210.           return("0");
  12211.  
  12212.       case VN_MDMSG:                    /* DIALRESULT */
  12213. #ifndef NODIAL
  12214.         return((char *)modemmsg);
  12215. #else
  12216.         return("");
  12217. #endif /* NODIAL */
  12218.  
  12219.       case VN_DNUM:                     /* DIALNUMBER */
  12220. #ifndef NODIAL
  12221.         return(dialnum ? (char *) dialnum : "");
  12222. #else
  12223.         return("");
  12224. #endif /* NODIAL */
  12225.  
  12226.       case VN_APC:
  12227.         sprintf(vvbuf, "%d",            /* SAFE */
  12228. #ifdef CK_APC
  12229.                 apcactive
  12230. #else
  12231.                 0
  12232. #endif /* CK_APC */
  12233.                 );
  12234.         return((char *)vvbuf);
  12235.  
  12236. #ifdef OS2
  12237. #ifndef NOKVERBS
  12238.       case VN_TRMK:
  12239.           sprintf(vvbuf, "%d", keymac); /* SAFE */
  12240.         return((char *)vvbuf);
  12241. #endif /* NOKVERBS */
  12242. #endif /* OS2 */
  12243.  
  12244.       case VN_IPADDR:
  12245. #ifdef TCPSOCKET
  12246. #ifndef OSK
  12247.       /* This dumps core on OS-9 for some reason, but only if executed */
  12248.       /* before we have made a TCP connection.  This is obviously not */
  12249.       /* the ideal fix. */
  12250.         if (!myipaddr[0])
  12251.           getlocalipaddr();
  12252. #endif /* OSK */
  12253. #endif /* TCPSOCKET */
  12254.         ckstrncpy(vvbuf,
  12255. #ifdef TCPSOCKET
  12256.                 (char *)myipaddr,
  12257. #else
  12258.                 "",
  12259. #endif /* TCPSOCKET */
  12260.                 VVBUFL);
  12261.         return((char *)vvbuf);
  12262.  
  12263. #ifndef NOXFER
  12264.       case VN_CRC16:                    /* CRC-16 of most recent transfer */
  12265.         sprintf(vvbuf,"%d",crc16);      /* SAFE */
  12266.         return(vvbuf);
  12267. #endif /* NOXFER */
  12268.  
  12269. #ifdef CK_PID
  12270.       case VN_PID:
  12271. #ifdef IKSD
  12272. #ifdef CK_LOGIN
  12273.         if (inserver && isguest)
  12274.           return("");
  12275. #endif /* CK_LOGIN */
  12276. #endif /* IKSD */
  12277.         return(ckgetpid());
  12278. #endif /* CK_PID */
  12279.  
  12280. #ifndef NOXFER
  12281.       case VN_FNAM: {                   /* \v(filename) */
  12282.           extern char filnam[], ofn1[], *sfspec, *rrfspec;
  12283.           char * tmp;
  12284.           switch (what) {               /* File transfer is in progress */
  12285. #ifdef NEWFTP
  12286.             case (W_FTP|W_RECV):
  12287.             case (W_FTP|W_SEND):
  12288.               return((char *)filnam);
  12289. #endif /* NEWFTP */
  12290.             case W_RECV:
  12291.             case W_REMO:
  12292.               return((char *)ofn1);
  12293.             default:                    /* Most recent file transferred */
  12294.               if (filnam[0]) {          /* (if any) */
  12295.                   return((char *)filnam);
  12296.               } else if (lastxfer & W_SEND && sfspec) {
  12297.                   if (fnspath == PATH_OFF)
  12298.                     zstrip(sfspec,&tmp);
  12299.                   else
  12300.                     tmp = sfspec;
  12301.                   return(tmp);
  12302.               } else if (lastxfer & W_RECV && rrfspec) {
  12303.                   if (fnrpath == PATH_OFF)
  12304.                     zstrip(rrfspec,&tmp);
  12305.                   else
  12306.                     tmp = rrfspec;
  12307.                   return(tmp);
  12308.               } else
  12309.                 return("");
  12310.           }
  12311.       }
  12312.       case VN_FNUM:                     /* \v(filenum) */
  12313.         sprintf(vvbuf,"%ld",filcnt);    /* SAFE */
  12314.         return((char *)vvbuf);
  12315. #endif /* NOXFER */
  12316.  
  12317. #ifdef PEXITSTAT
  12318.       case VN_PEXIT: {
  12319.           extern int pexitstat;
  12320.           sprintf(vvbuf,"%d",pexitstat); /* SAFE */
  12321.           return((char *)vvbuf);
  12322.       }
  12323. #endif /* PEXITSTAT */
  12324.  
  12325. #ifndef NOXFER
  12326.       case VN_P_8BIT:
  12327.         vvbuf[0] = parity ? ebq : NUL;
  12328.         vvbuf[1] = NUL;
  12329.         return((char *)vvbuf);
  12330.  
  12331.       case VN_P_CTL: {
  12332.           extern CHAR myctlq;
  12333.           vvbuf[0] = myctlq;
  12334.           vvbuf[1] = NUL;
  12335.           return((char *)vvbuf);
  12336.       }
  12337.       case VN_P_RPT: {
  12338.           extern int rptena;
  12339.           vvbuf[0] = rptena ? rptq : NUL;
  12340.           vvbuf[1] = NUL;
  12341.           return((char *)vvbuf);
  12342.       }
  12343. #endif /* NOXFER */
  12344.  
  12345. #ifdef OS2
  12346.       case VN_REGN:
  12347.         return(get_reg_name());
  12348.       case VN_REGO:
  12349.         return(get_reg_corp());
  12350.       case VN_REGS:
  12351.         return(get_reg_sn());
  12352. #endif /* OS2 */
  12353.     } /* Break up long switch statements... */
  12354.  
  12355.     switch(y) {
  12356.       case VN_XPROG:
  12357. #ifdef OS2
  12358. #ifdef NT
  12359. #ifdef KUI
  12360.         return("K-95G");
  12361. #else
  12362.         return("K-95");
  12363. #endif /* KUI */
  12364. #else
  12365.         return("K/2");
  12366. #endif /* NT */
  12367. #else
  12368.         return("C-Kermit");
  12369. #endif /* OS2 */
  12370.  
  12371.       case VN_EDITOR:
  12372. #ifdef NOFRILLS
  12373.         return("");
  12374. #else
  12375. #ifdef NOPUSH
  12376.         return("");
  12377. #else
  12378.         {
  12379.             extern char editor[];
  12380.             char *ss;
  12381.             if (!editor[0]) {
  12382.                 ss = getenv("EDITOR");
  12383.                 if (ss) {
  12384.                     ckstrncpy(editor,ss,CKMAXPATH);
  12385.                 }
  12386.             }
  12387.             debug(F110,"\\v(editor)",editor,0);
  12388.             return(editor[0] ? (char *)editor : "");
  12389.         }
  12390. #endif /* NOPUSH */
  12391. #endif /* NOFRILLS */
  12392.  
  12393.       case VN_EDOPT:
  12394. #ifdef NOFRILLS
  12395.         return("");
  12396. #else
  12397. #ifdef NOPUSH
  12398.         return("");
  12399. #else
  12400.         {
  12401.             extern char editopts[];
  12402.             return(editopts[0] ? (char *)editopts : "");
  12403.         }
  12404. #endif /* NOPUSH */
  12405. #endif /* NOFRILLS */
  12406.  
  12407.       case VN_EDFILE:
  12408. #ifdef NOFRILLS
  12409.         return("");
  12410. #else
  12411. #ifdef NOPUSH
  12412.         return("");
  12413. #else
  12414.         {
  12415.             extern char editfile[];
  12416.             return(editfile[0] ? (char *)editfile : "");
  12417.         }
  12418. #endif /* NOPUSH */
  12419. #endif /* NOFRILLS */
  12420.  
  12421. #ifdef BROWSER
  12422.       case VN_BROWSR: {
  12423.           extern char browser[];
  12424.           if (!browser[0]) {
  12425.               s = getenv("BROWSER");
  12426.               if (s) ckstrncpy(browser,s,CKMAXPATH);
  12427.           }
  12428.           return(browser[0] ? (char *)browser : "");
  12429.       }
  12430.       case VN_BROPT: {
  12431.           extern char browsopts[];
  12432.           return(browsopts[0] ? (char *)browsopts : "");
  12433.       }
  12434.       case VN_URL: {
  12435.           extern char browsurl[];
  12436.           return(browsurl[0] ? (char *)browsurl : "");
  12437.       }
  12438. #endif /* BROWSER */
  12439.       case VN_HERALD:
  12440.         return((char *)versio);
  12441.  
  12442.       case VN_TEST: {                   /* test */
  12443.           extern char * ck_s_test, * ck_s_tver;
  12444.           if (!ck_s_test) ck_s_test = "";
  12445.           if (!ck_s_tver) ck_s_tver = "";
  12446.           if (*ck_s_test) {
  12447.               ckstrncpy(vvbuf,ck_s_test,VVBUFL);
  12448.               if (*ck_s_tver) {
  12449.                   ckstrncat(vvbuf,".",VVBUFL);
  12450.                   ckstrncat(vvbuf,ck_s_tver,VVBUFL);
  12451.               }
  12452.           } else
  12453.             ckstrncpy(vvbuf,"0",VVBUFL);
  12454.           return((char *)vvbuf);
  12455.       }
  12456.  
  12457. #ifndef NOXFER
  12458.       case VN_XFSTAT:                   /* xferstatus */
  12459.         x = xferstat;                   /* Like success */
  12460.         if (x > -1) x = (x == 0) ? 1 : 0; /* External value is reversed */
  12461.         sprintf(vvbuf,"%d",x);          /* SAFE */
  12462.         return((char *)vvbuf);
  12463.  
  12464.       case VN_XFMSG:                    /* xfermsg */
  12465.         return((char *)epktmsg);
  12466.  
  12467. #ifndef NOMSEND
  12468.       case VN_SNDL: {                   /* sendlist */
  12469.           extern int filesinlist;
  12470.           sprintf(vvbuf,"%d",filesinlist); /* SAFE */
  12471.           return((char *)vvbuf);
  12472.       }
  12473. #endif /* NOMSEND */
  12474. #endif /* NOXFER */
  12475.  
  12476. #ifdef CK_TRIGGER
  12477.       case VN_TRIG: {
  12478.           extern char * triggerval;
  12479.           return(triggerval ? triggerval : "");
  12480.       }
  12481. #endif /* CK_TRIGGER */
  12482. #ifdef OS2MOUSE
  12483. #ifdef OS2
  12484.       case VN_MOU_X: {
  12485.           extern int MouseCurX;
  12486.           sprintf(vvbuf,"%d",MouseCurX); /* SAFE */
  12487.           return((char *)vvbuf);
  12488.       }
  12489.       case VN_MOU_Y: {
  12490.           extern int MouseCurY;
  12491.           sprintf(vvbuf,"%d",MouseCurY); /* SAFE */
  12492.           return((char *)vvbuf);
  12493.       }
  12494. #endif /* OS2 */
  12495. #endif /* OS2MOUSE */
  12496.       case VN_PRINT: {
  12497.           extern int printpipe;
  12498.           extern char * printername;
  12499. #ifdef PRINTSWI
  12500.           extern int noprinter;
  12501.           if (noprinter) return("");
  12502. #endif /* PRINTSWI */
  12503.           ckmakmsg(vvbuf,VVBUFL,
  12504.                    printpipe ? "|" : "",
  12505.                    printername ? printername :
  12506. #ifdef OS2
  12507.                    "PRN",
  12508. #else
  12509.                    "(default)",
  12510. #endif /* OS2 */
  12511.                    NULL,
  12512.                    NULL
  12513.                    );
  12514.           return((char *)vvbuf);
  12515.       }
  12516.     } /* Break up long switch statements... */
  12517.  
  12518.     switch(y) {
  12519.       case VN_ESC:                      /* Escape character */
  12520.         sprintf(vvbuf,"%d",escape);     /* SAFE */
  12521.         return((char *)vvbuf);
  12522.  
  12523.       case VN_INTIME:
  12524.         sprintf(vvbuf,"%ld",inetime);   /* SAFE */
  12525.         return((char *)vvbuf);
  12526.  
  12527.       case VN_INTMO:
  12528.         sprintf(vvbuf,"%d",inwait);     /* SAFE */
  12529.         return((char *)vvbuf);
  12530.  
  12531.       case VN_SECURE:
  12532.         if (0
  12533. #ifdef SSHBUILTIN
  12534.             || IS_SSH()
  12535. #endif /* SSHBUILTIN */
  12536. #ifdef CK_ENCRYPTION
  12537.             || ck_tn_encrypting() && ck_tn_decrypting()
  12538. #endif /* CK_ENCRYPTION */
  12539. #ifdef CK_SSL
  12540.             || tls_active_flag || ssl_active_flag
  12541. #endif /* CK_SSL */
  12542.             )
  12543.           return("1");
  12544.         else
  12545.           return("0");
  12546.  
  12547.       case VN_AUTHN:
  12548. #ifdef CK_AUTHENTICATION
  12549.         {
  12550.             extern char szUserNameAuthenticated[];
  12551.             return((char *)szUserNameAuthenticated);
  12552.         }
  12553. #else /* CK_AUTHENTICATION */
  12554.         return((char *)"");
  12555. #endif /* CK_AUTHENTICATION */
  12556.  
  12557.       case VN_AUTHS:
  12558. #ifdef CK_AUTHENTICATION
  12559.         switch (ck_tn_auth_valid()) {
  12560.           case AUTH_UNKNOWN:
  12561.             return((char *)"unknown");
  12562.           case AUTH_OTHER:
  12563.             return((char *)"other");
  12564.           case AUTH_USER:
  12565.             return((char *)"user");
  12566.           case AUTH_VALID:
  12567.             return((char *)"valid");
  12568.           case AUTH_REJECT:
  12569.           default:
  12570.             return((char *)"rejected");
  12571.         }
  12572. #else /* CK_AUTHENTICATION */
  12573.         return((char *)"rejected");
  12574. #endif /* CK_AUTHENTICATION */
  12575.  
  12576.       case VN_AUTHT:
  12577. #ifdef CK_AUTHENTICATION
  12578. #ifdef CK_SSL
  12579.         if ((ssl_active_flag || tls_active_flag) &&
  12580.             ck_tn_auth_valid() == AUTH_VALID &&
  12581.             (sstelnet ? (!TELOPT_U(TELOPT_AUTHENTICATION)) :
  12582.                         (!TELOPT_ME(TELOPT_AUTHENTICATION))) ||
  12583.              ck_tn_authenticated() == AUTHTYPE_NULL ||
  12584.              ck_tn_authenticated() == AUTHTYPE_AUTO)
  12585.           return("X_509_CERTIFICATE");
  12586.         else
  12587. #endif /* CK_SSL */
  12588.           return(AUTHTYPE_NAME(ck_tn_authenticated()));
  12589. #else /* CK_AUTHENTICATION */
  12590.         return((char *)"NULL");
  12591. #endif /* CK_AUTHENTICATION */
  12592.  
  12593. #ifdef CK_KERBEROS
  12594.       case VN_K4PRN: {
  12595.           extern char * krb4_d_principal;
  12596.           if (krb4_d_principal)
  12597.             ckstrncpy(vvbuf,krb4_d_principal,VVBUFL+1);
  12598.           else
  12599.             *vvbuf = NUL;
  12600.           return((char *)vvbuf);
  12601.       }
  12602.       case VN_K5PRN: {
  12603.           extern char * krb5_d_principal;
  12604.           if (krb5_d_principal)
  12605.             ckstrncpy(vvbuf,krb5_d_principal,VVBUFL+1);
  12606.           else
  12607.             *vvbuf = NUL;
  12608.           return((char *)vvbuf);
  12609.       }
  12610.       case VN_K4RLM: {
  12611.           extern char * krb4_d_realm;
  12612.           if (krb4_d_realm) {
  12613.               ckstrncpy(vvbuf,krb4_d_realm,VVBUFL+1);
  12614.           } else {
  12615.               char * s = ck_krb4_getrealm();
  12616.               ckstrncpy(vvbuf,s ? s : "",VVBUFL+1);
  12617.           }
  12618.           return((char *)vvbuf);
  12619.       }
  12620.       case VN_K4SRV: {
  12621.           extern char * krb4_d_srv;
  12622.           if (krb4_d_srv)
  12623.             ckstrncpy(vvbuf,krb4_d_srv,VVBUFL+1);
  12624.           else
  12625.             ckstrncpy(vvbuf,"rcmd",VVBUFL);
  12626.           return((char *)vvbuf);
  12627.       }
  12628.       case VN_K5RLM: {
  12629.           extern char * krb5_d_realm;
  12630.           extern char * krb5_d_cc;
  12631.           if (krb5_d_realm) {
  12632.               ckstrncpy(vvbuf,krb5_d_realm,VVBUFL+1);
  12633.           } else {
  12634.               char * s = ck_krb5_getrealm(krb5_d_cc);
  12635.               ckstrncpy(vvbuf,s,VVBUFL+1);
  12636.           }
  12637.           return((char *)vvbuf);
  12638.       }
  12639.       case VN_K5CC: {
  12640.           extern char * krb5_d_cc;
  12641.           if (krb5_d_cc)
  12642.             ckstrncpy(vvbuf,krb5_d_cc,VVBUFL+1);
  12643.           else
  12644.             ckstrncpy(vvbuf,ck_krb5_get_cc_name(),VVBUFL+1);
  12645.           return((char *)vvbuf);
  12646.       }
  12647.       case VN_K5SRV: {
  12648.           extern char * krb5_d_srv;
  12649.           if (krb5_d_srv)
  12650.             ckstrncpy(vvbuf,krb5_d_srv,VVBUFL+1);
  12651.           else
  12652.             ckstrncpy(vvbuf,"host",VVBUFL);
  12653.           return((char *)vvbuf);
  12654.       }
  12655.       case VN_K4ENO: {
  12656.         extern char * krb4_errno;
  12657.         sprintf(vvbuf,"%d",krb4_errno); /* SAFE */
  12658.         return((char *)vvbuf);
  12659.       }
  12660.       case VN_K5ENO: {
  12661.         extern char * krb5_errno;
  12662.         sprintf(vvbuf,"%d",krb5_errno); /* SAFE */
  12663.         return((char *)vvbuf);
  12664.       }
  12665.       case VN_K4EMSG: {
  12666.         extern char * krb4_errmsg;
  12667.         ckstrncpy(vvbuf,krb4_errmsg?krb4_errmsg:"",VVBUFL+1);
  12668.         return((char *)vvbuf);
  12669.       }
  12670.       case VN_K5EMSG: {
  12671.         extern char * krb5_errmsg;
  12672.         ckstrncpy(vvbuf,krb5_errmsg,VVBUFL+1);
  12673.         return((char *)vvbuf);
  12674.       }
  12675. #endif /* CK_KERBEROS */
  12676. #ifdef CK_SSL
  12677.       case VN_X509_S:
  12678.         if (ssl_active_flag)
  12679.           ckstrncpy(vvbuf,ssl_get_subject_name(ssl_con),VVBUFL+1);
  12680.         else if (tls_active_flag)
  12681.           ckstrncpy(vvbuf,ssl_get_subject_name(tls_con),VVBUFL+1);
  12682.         else
  12683.           ckstrncpy(vvbuf,"",VVBUFL+1);
  12684.         return((char *)vvbuf);
  12685.       case VN_X509_I:
  12686.         if (ssl_active_flag)
  12687.           ckstrncpy(vvbuf,ssl_get_issuer_name(ssl_con),VVBUFL+1);
  12688.         else if (tls_active_flag)
  12689.           ckstrncpy(vvbuf,ssl_get_issuer_name(tls_con),VVBUFL+1);
  12690.         else
  12691.           ckstrncpy(vvbuf,"",VVBUFL+1);
  12692.         return((char *)vvbuf);
  12693. #endif /* CK_SSL */
  12694.  
  12695.       case VN_OSNAM:
  12696. #ifdef IKSD
  12697. #ifdef CK_LOGIN
  12698.         if (inserver && isguest)
  12699.           return("");
  12700. #endif /* CK_LOGIN */
  12701. #endif /* IKSD */
  12702. #ifdef CK_UTSNAME
  12703.         {
  12704.             extern char unm_nam[];
  12705.             return((char *)unm_nam);
  12706.         }
  12707. #else
  12708.         for (x = y = 0; x < VVBUFL; x++) {
  12709.             if (ckxsys[x] == SP && cx == 0) continue;
  12710.             vvbuf[y++] = (char) ((ckxsys[x] == SP) ? '_' : ckxsys[x]);
  12711.         }
  12712.         vvbuf[y] = NUL;
  12713.         return(vvbuf);
  12714. #endif /* CK_UTSNAME */
  12715.  
  12716.       case VN_OSVER: {
  12717. #ifdef CK_UTSNAME
  12718.           extern char unm_ver[];
  12719. #ifdef IKSD
  12720. #ifdef CK_LOGIN
  12721.           if (inserver && isguest)
  12722.             return("");
  12723. #endif /* CK_LOGIN */
  12724. #endif /* IKSD */
  12725.           return((char *)unm_ver);
  12726. #else
  12727.           return("");
  12728. #endif /* CK_UTSNAME */
  12729.       }
  12730.  
  12731.       case VN_OSREL: {
  12732. #ifdef CK_UTSNAME
  12733.           extern char unm_rel[];
  12734. #ifdef IKSD
  12735. #ifdef CK_LOGIN
  12736.           if (inserver && isguest)
  12737.             return("");
  12738. #endif /* CK_LOGIN */
  12739. #endif /* IKSD */
  12740.           return((char *)unm_rel);
  12741. #else
  12742.           return("");
  12743. #endif /* CK_UTSNAME */
  12744.       }
  12745.     } /* Break up long switch statements... */
  12746.  
  12747.     switch(y) {
  12748.       case VN_NAME: {
  12749.           extern char * myname;
  12750.           return(myname);
  12751.       }
  12752.  
  12753.       case VN_MODL: {
  12754. #ifdef CK_UTSNAME
  12755.           extern char unm_mod[], unm_mch[];
  12756.           int y = VVBUFL - 1;
  12757.           char * s = unm_mod;
  12758. #endif /* CK_UTSNAME */
  12759. #ifdef IKSD
  12760. #ifdef CK_LOGIN
  12761.           if (inserver && isguest)
  12762.             return("");
  12763. #endif /* CK_LOGIN */
  12764. #endif /* IKSD */
  12765.  
  12766. #ifdef COMMENT                          /* was HPUX */
  12767.           if (!unm_mod[0] && !nopush)
  12768.             zzstring("\\fcommand(model)",&s,&y);
  12769. /*
  12770.    Another possibility would be:
  12771.      "\\fcommand(ksh -c 'whence model 1>&- && model || uname -m')"
  12772.    But that would depend on having ksh.
  12773. */
  12774. #else
  12775. #ifdef OSF32                            /* Digital UNIX 3.2 and higher... */
  12776. /* Note: Ultrix has /etc/sizer, but it is not publicly executable. */
  12777. /* sizer -c outputs 'cpu:<tab><tab>"DECxxxx"' */
  12778.           if (!unm_mod[0]) {
  12779.               char * p;
  12780.               int flag = 0;
  12781.               zzstring("\\fcommand(/usr/sbin/sizer -c)",&s,&y);
  12782.               debug(F110,"DU model",unm_mod,0);
  12783.               s = unm_mod;
  12784.               p = unm_mod;
  12785.               while (*p) {              /* Extract the part in quotes */
  12786.                   if (*p == '"') {
  12787.                       if (flag)
  12788.                         break;
  12789.                       flag = 1;
  12790.                       p++;
  12791.                       continue;
  12792.                   }
  12793.                   if (flag)
  12794.                     *s++ = *p;
  12795.                   p++;
  12796.               }
  12797.               *s = NUL;
  12798.           }
  12799. #endif /* OSF32 */
  12800. #endif /* COMMENT */
  12801.  
  12802. #ifdef CK_UTSNAME
  12803.           if (unm_mod[0])
  12804.             return((char *)unm_mod);
  12805.           else
  12806.             return((char *)unm_mch);
  12807. #else
  12808.           return("");
  12809. #endif /* CK_UTSNAME */
  12810.       }
  12811.  
  12812. #ifdef IBMX25
  12813.       /* X.25 variables (local and remote address) */
  12814.       case VN_X25LA:
  12815.         if (!local_nua[0] && !x25local_nua(local_nua))
  12816.           *vvbuf = NULL;
  12817.         else
  12818.           ckstrncpy(vvbuf,local_nua,VVBUFL+1);
  12819.         return((char *)vvbuf);
  12820.  
  12821.       case VN_X25RA:
  12822.         if (!remote_nua[0])
  12823.           *vvbuf = NULL;
  12824.         else
  12825.           ckstrncpy(vvbuf,remote_nua,VVBUFL+1);
  12826.         return((char *)vvbuf);
  12827. #endif /* IBMX25 */
  12828.  
  12829. #ifndef NODIAL
  12830.       case VN_PDSFX: {
  12831.           extern char pdsfx[];
  12832.           return((char *)pdsfx);
  12833.       }
  12834.       case VN_DTYPE: {
  12835.           extern int dialtype;
  12836.           sprintf(vvbuf,"%d",dialtype); /* SAFE */
  12837.           return((char *)vvbuf);
  12838.       }
  12839. #endif /* NODIAL */
  12840.  
  12841. #ifdef UNIX
  12842.       case VN_LCKPID: {
  12843.           extern char lockpid[];
  12844.           return((char *)lockpid);
  12845.       }
  12846. #endif /* UNIX */
  12847.  
  12848. #ifndef NOXFER
  12849.       case VN_BLK:
  12850.         sprintf(vvbuf,"%d",bctr);       /* SAFE */
  12851.         return((char *)vvbuf);
  12852.  
  12853.       case VN_TFTIM:
  12854.         sprintf(vvbuf,                  /* SAFE */
  12855. #ifdef GFTIMER
  12856.                 "%ld", (long)(fptsecs + 0.5)
  12857. #else
  12858.                 "%d", tsecs
  12859. #endif /* GFTIMER */
  12860.                 );
  12861.         return((char *)vvbuf);
  12862. #endif /* NOXFER */
  12863.  
  12864.       case VN_HWPAR:
  12865.       case VN_SERIAL: {
  12866.           int sb;
  12867.           char c, * ss;
  12868.           extern int stopbits;
  12869.           vvbuf[0] = NUL;
  12870.           if (hwparity && local && !network)
  12871.             ss = parnam((char)hwparity);
  12872.           else
  12873.             ss = parnam((char)parity);
  12874.           if (cx == VN_HWPAR) {
  12875.               ckstrncpy(vvbuf,ss,VVBUFL);
  12876.               return((char *)vvbuf);
  12877.           }
  12878.           c = ss[0];
  12879.           if (islower(c)) c = toupper(c);
  12880.           sb = stopbits;
  12881.           if (sb < 1)
  12882.             sb = (speed > 0 && speed <= 110L) ? 2 : 1;
  12883.           if (hwparity)
  12884.             sprintf(vvbuf," 8%c%d",c,sb); /* SAFE */
  12885.           else if (parity)
  12886.             sprintf(vvbuf," 7%c%d",c,sb); /* SAFE */
  12887.           else
  12888.             sprintf(vvbuf," 8N%d",sb);  /* SAFE */
  12889.           return((char *)vvbuf);
  12890.       }
  12891.  
  12892. #ifdef UNIX
  12893.       case VN_LCKDIR: {
  12894. #ifndef NOUUCP
  12895.           extern char * uucplockdir;
  12896.           ckstrncpy(vvbuf,uucplockdir,VVBUFL);
  12897.           x = strlen(vvbuf);
  12898.           if (x > 0) {
  12899.               if (vvbuf[x-1] != '/') {
  12900.                   vvbuf[x] = '/';
  12901.                   vvbuf[x+1] = NUL;
  12902.               }
  12903.           }
  12904. #else
  12905.           vvbuf[0] = NUL;
  12906. #endif /* NOUUCP */
  12907.           return((char *)vvbuf);
  12908.       }
  12909. #endif /* UNIX */
  12910.     } /* Break up long switch statements... */
  12911.  
  12912.     switch(y) {
  12913. #ifndef NODIAL
  12914.       case VN_DM_LP:
  12915.       case VN_DM_SP:
  12916.       case VN_DM_PD:
  12917.       case VN_DM_TD:
  12918.       case VN_DM_WA:
  12919.       case VN_DM_WD:
  12920.       case VN_DM_HF:
  12921.       case VN_DM_WB:
  12922.       case VN_DM_RC: {
  12923.           extern char * getdm();
  12924.           ckstrncpy(vvbuf,getdm(y),VVBUFL);
  12925.           return((char *)vvbuf);
  12926.       }
  12927. #endif /* NODIAL */
  12928.  
  12929.       case VN_TY_LN:
  12930.       case VN_TY_LC: {
  12931.           extern int typ_lines;
  12932.           sprintf(vvbuf,"%d",typ_lines); /* SAFE */
  12933.           return((char *)vvbuf);
  12934.       }
  12935.       case VN_TY_LM: {
  12936.           extern int typ_mtchs;
  12937.           sprintf(vvbuf,"%d",typ_mtchs); /* SAFE */
  12938.           return((char *)vvbuf);
  12939.       }
  12940.       case VN_MACLVL:
  12941.         sprintf(vvbuf,"%d",maclvl);     /* SAFE */
  12942.         return((char *)vvbuf);
  12943.     } /* Break up long switch statements... */
  12944.  
  12945.     switch(y) {
  12946. #ifndef NOXFER
  12947.       case VN_XF_BC:
  12948.         sprintf(vvbuf,"%d",crunched);   /* SAFE */
  12949.         return((char *)vvbuf);
  12950.  
  12951.       case VN_XF_TM:
  12952.         sprintf(vvbuf,"%d",timeouts);   /* SAFE */
  12953.         return((char *)vvbuf);
  12954.  
  12955.       case VN_XF_RX:
  12956.         sprintf(vvbuf,"%d",retrans);    /* SAFE */
  12957.         return((char *)vvbuf);
  12958. #endif /* NOXFER */
  12959.  
  12960.       case VN_MS_CD:                    /* Modem signals */
  12961.       case VN_MS_CTS:
  12962.       case VN_MS_DSR:
  12963.       case VN_MS_DTR:
  12964.       case VN_MS_RI:
  12965.       case VN_MS_RTS: {
  12966.           int x, z = -1;
  12967.           x = ttgmdm();                 /* Try to get them */
  12968.           if (x > -1) {
  12969.               switch (y) {
  12970.                 case VN_MS_CD:  z = (x & BM_DCD) ? 1 : 0; break;
  12971.                 case VN_MS_DSR: z = (x & BM_DSR) ? 1 : 0; break;
  12972.                 case VN_MS_CTS: z = (x & BM_CTS) ? 1 : 0; break;
  12973. #ifdef MAC
  12974.                 case VN_MS_DTR: z = (x & BM_DTR) ? 1 : 0; break;
  12975. #else
  12976. #ifndef STRATUS
  12977.                 case VN_MS_RI:  z = (x & BM_RNG) ? 1 : 0; break;
  12978. #ifndef NT
  12979.                 case VN_MS_DTR: z = (x & BM_DTR) ? 1 : 0; break;
  12980.                 case VN_MS_RTS: z = (x & BM_RTS) ? 1 : 0; break;
  12981. #endif /* NT */
  12982. #endif /* STRATUS */
  12983. #endif /* MAC */
  12984.               }
  12985.           }
  12986.           sprintf(vvbuf,"%d",z);        /* SAFE */
  12987.           return((char *)vvbuf);
  12988.       }
  12989.       case VN_MATCH:                    /* INPUT MATCH */
  12990.         return(inpmatch ? inpmatch : "");
  12991.  
  12992.       case VN_SLMSG: {                  /* SET LINE / HOST message */
  12993.           extern char * slmsg;
  12994.           vvbuf[0] = NUL;
  12995.           if (slmsg)
  12996.             ckstrncpy(vvbuf,slmsg,VVBUFL);
  12997.          return(vvbuf);
  12998.       }
  12999.  
  13000.       case VN_TXTDIR:                   /* TEXTDIR */
  13001.         return(k_info_dir ? k_info_dir : "");
  13002.  
  13003. #ifdef FNFLOAT
  13004.       case VN_MA_PI:
  13005.         return(math_pi);
  13006.  
  13007.       case VN_MA_E:
  13008.         return(math_e);
  13009.  
  13010.       case VN_MA_PR:
  13011.         sprintf(vvbuf,"%d",fp_digits);  /* SAFE */
  13012.         return(vvbuf);
  13013. #endif /* FNFLOAT */
  13014.  
  13015.       case VN_CMDBL:
  13016.         sprintf(vvbuf,"%d",CMDBL);      /* SAFE */
  13017.         return(vvbuf);
  13018.  
  13019. #ifdef CKCHANNELIO
  13020.       case VN_FERR: {
  13021.           extern int z_error;
  13022.           sprintf(vvbuf,"%d",z_error);  /* SAFE */
  13023.           return(vvbuf);
  13024.       }
  13025.       case VN_FMAX: {
  13026.           extern int z_maxchan;
  13027.           sprintf(vvbuf,"%d",z_maxchan); /* SAFE */
  13028.           return(vvbuf);
  13029.       }
  13030.       case VN_FCOU: {
  13031.           extern int z_filcount;
  13032.           sprintf(vvbuf,"%d",z_filcount); /* SAFE */
  13033.           return(vvbuf);
  13034.       }
  13035. #endif /* CKCHANNELIO */
  13036.  
  13037. #ifndef NODIAL
  13038.       case VN_DRTR: {
  13039.           extern int dialcount;
  13040.           sprintf(vvbuf,"%d",dialcount); /* SAFE */
  13041.           return(vvbuf);
  13042.       }
  13043. #endif /* NODIAL */
  13044.  
  13045. #ifndef NOLOGDIAL
  13046. #ifndef NOLOCAL
  13047.       case VN_CXTIME:
  13048.         sprintf(vvbuf,"%ld",dologshow(0)); /* SAFE */
  13049.         return(vvbuf);
  13050. #endif /* NOLOCAL */
  13051. #endif /* NOLOGDIAL */
  13052.  
  13053.       case VN_BYTE:
  13054.         sprintf(vvbuf,"%d",byteorder);  /* SAFE */
  13055.         return(vvbuf);
  13056.  
  13057.       case VN_KBCHAR:
  13058.         vvbuf[0] = NUL;
  13059.         vvbuf[1] = NUL;
  13060.         if (kbchar > 0)
  13061.           vvbuf[0] = (kbchar & 0xff);
  13062.         return(vvbuf);
  13063.  
  13064.       case VN_TTYNAM: {
  13065. #ifdef HAVECTTNAM
  13066.           extern char cttnam[];
  13067.           return((char *)cttnam);
  13068. #else
  13069.           return(CTTNAM);
  13070. #endif /* HAVECTTNAM */
  13071.       }
  13072.  
  13073.       case VN_PROMPT:
  13074.         return(cmgetp());
  13075.  
  13076.       case VN_BUILD: {
  13077.           extern char * buildid;
  13078.           return(buildid);
  13079.       }
  13080.  
  13081. #ifndef NOSEXP
  13082.       case VN_SEXP: {
  13083.           extern char * lastsexp;
  13084.           return(lastsexp ? lastsexp : "");
  13085.       }
  13086.       case VN_VSEXP: {
  13087.           extern char * sexpval;
  13088.           return(sexpval ? sexpval : "");
  13089.       }
  13090.       case VN_LSEXP: {
  13091.           extern int sexpdep;
  13092.           ckstrncpy(vvbuf,ckitoa(sexpdep),VVBUFL);
  13093.           return(vvbuf);
  13094.       }
  13095. #endif /* NOSEXP */
  13096.  
  13097. #ifdef GFTIMER
  13098.       case VN_FTIME: {
  13099.           CKFLOAT f;
  13100.           ztime(&p);
  13101.           if (p == NULL || *p == NUL)
  13102.             return(NULL);
  13103.           z = atol(p+11) * 3600L + atol(p+14) * 60L + atol(p+17);
  13104.           f = (CKFLOAT)z + ((CKFLOAT)ztusec) / 1000000.0;
  13105.           sprintf(vvbuf,"%f",f);        /* SAFE */
  13106.           return(vvbuf);
  13107.       }
  13108. #endif /* GFTIMER */
  13109.  
  13110. #ifndef NOHTTP
  13111.       case VN_HTTP_C: {                 /* HTTP Code */
  13112.           extern int http_code;
  13113.           return(ckitoa(http_code));
  13114.       }
  13115.       case VN_HTTP_N:                   /* HTTP Connected */
  13116.         return( http_isconnected() ? "1" : "0");
  13117.       case VN_HTTP_H:                   /* HTTP Host */
  13118.         return( (char *)http_host() );
  13119.       case VN_HTTP_M: {                 /* HTTP Message */
  13120.           extern char http_reply_str[];
  13121.           return((char *)http_reply_str);
  13122.       }
  13123.       case VN_HTTP_S:                   /* HTTP Security */
  13124.         return((char *)http_security());
  13125. #endif /* NOHTTP */
  13126.  
  13127. #ifdef NEWFTP
  13128.       case VN_FTP_B:
  13129.         return((char *)ftp_cpl_mode());
  13130.       case VN_FTP_D:
  13131.         return((char *)ftp_dpl_mode());
  13132.       case VN_FTP_Z:
  13133.         return((char *)ftp_authtype());
  13134.       case VN_FTP_C: {
  13135.           extern int ftpcode;
  13136.           return(ckitoa(ftpcode));
  13137.       }
  13138.       case VN_FTP_M: {
  13139.           extern char ftp_reply_str[];
  13140.           if (isdigit(ftp_reply_str[0]) &&
  13141.               isdigit(ftp_reply_str[1]) &&
  13142.               isdigit(ftp_reply_str[2]) &&
  13143.               ftp_reply_str[3] == ' ')
  13144.             return(&ftp_reply_str[4]);
  13145.           else
  13146.             return(ftp_reply_str);
  13147.       }
  13148.       case VN_FTP_S: {
  13149.           extern char ftp_srvtyp[];
  13150.           return((char *)ftp_srvtyp);
  13151.       }
  13152.       case VN_FTP_H: {
  13153.           extern char * ftp_host;
  13154.           return(ftp_host ? ftp_host : "");
  13155.       }
  13156.       case VN_FTP_X: {                  /* FTP Connected */
  13157.           extern int ftpisconnected();
  13158.           return(ftpisconnected() ? "1" : "0");
  13159.       }
  13160.       case VN_FTP_L: {                  /* FTP Logged in */
  13161.           extern int ftpisloggedin();
  13162.           return(ftpisloggedin() ? "1" : "0");
  13163.       }
  13164.       case VN_FTP_G: {                  /* FTP GET-PUT-REMOTE */
  13165.           extern int ftpget;
  13166.           char * s = "";
  13167.           switch (ftpget) {
  13168.             case 0: s = "kermit"; break;
  13169.             case 1: s = "ftp"; break;
  13170.             case 2: s = "auto"; break;
  13171.           }
  13172.           return(s);
  13173.       }
  13174. #endif /* NEWFTP */
  13175.  
  13176. #ifndef NOLOCAL
  13177.       case VN_CX_STA: {                 /* CONNECT status */
  13178.           extern int cx_status;
  13179.           return(ckitoa(cx_status));
  13180.       }
  13181. #endif /* NOLOCAL */
  13182.       case VN_NOW:                      /* Timestamp */
  13183.         return(ckcvtdate(p,0));
  13184.  
  13185.       case VN_HOUR:                     /* Hour of the day */
  13186.         ztime(&p);                      /* "Thu Feb  8 12:00:00 1990" */
  13187.         if (!p) p = "";
  13188.         if (!*p) return(p);
  13189.         vvbuf[0] = p[11];
  13190.         vvbuf[1] = p[12];
  13191.         vvbuf[2] = NUL;
  13192.         return(vvbuf);                  /* and return it */
  13193.  
  13194.       case VN_LOG_CON:            /* \v(...) for log files */
  13195. #ifdef CKLOGDIAL
  13196.         return(diafil);
  13197. #else 
  13198.         return("");
  13199. #endif
  13200.       case VN_LOG_PKT:
  13201. #ifndef NOXFER
  13202.         return(pktfil);
  13203. #else
  13204.         return("");
  13205. #endif
  13206.       case VN_LOG_SES:
  13207. #ifndef NOLOCAL
  13208.         return(sesfil);
  13209. #else
  13210.         return("");
  13211. #endif
  13212.       case VN_LOG_TRA:
  13213. #ifdef TLOG
  13214.         return(trafil);
  13215. #else
  13216.         return("");
  13217. #endif
  13218.       case VN_LOG_DEB:
  13219. #ifdef DEBUG
  13220.         return(debfil);
  13221. #else
  13222.         return("");
  13223. #endif
  13224.     }
  13225.  
  13226. #ifndef NODIAL
  13227.     switch (y) {                        /* Caller ID values */
  13228.       extern char
  13229.         * callid_date, * callid_time, * callid_name,
  13230.         * callid_nmbr, * callid_mesg;
  13231.  
  13232.       case VN_CI_DA:
  13233.         return(callid_date ? callid_date : "");
  13234.  
  13235.       case VN_CI_TI:
  13236.         return(callid_time ? callid_time : "");
  13237.  
  13238.       case VN_CI_NA:
  13239.         return(callid_name ? callid_name : "");
  13240.  
  13241.       case VN_CI_NU:
  13242.         return(callid_nmbr ? callid_nmbr : "");
  13243.  
  13244.       case VN_CI_ME:
  13245.         return(callid_mesg ? callid_mesg : "");
  13246.  
  13247.     } /* End of variable-name switches */
  13248. #endif /* NODIAL */
  13249.  
  13250. #ifdef NT
  13251.     switch (y) {
  13252.       case VN_PERSONAL:
  13253.         p = (char *)GetPersonal();
  13254.         if (p) {
  13255.             GetShortPathName(p,vvbuf,VVBUFL);
  13256.             return(vvbuf);
  13257.         }
  13258.         return("");
  13259.       case VN_DESKTOP:
  13260.           p = (char *)GetDesktop();
  13261.           if (p) {
  13262.               GetShortPathName(p,vvbuf,VVBUFL);
  13263.               return(vvbuf);
  13264.           }
  13265.           return("");
  13266.       case VN_COMMON:
  13267.         p = (char *)GetAppData(1);
  13268.         if (p) {
  13269.             ckmakmsg(vvbuf,VVBUFL,p,"Kermit 95/",NULL,NULL);
  13270.             GetShortPathName(vvbuf,vvbuf,VVBUFL);
  13271.             return(vvbuf);
  13272.         }
  13273.         return("");
  13274.       case VN_APPDATA:
  13275.         p = (char *)GetAppData(0);
  13276.         if (p) {
  13277.             ckmakmsg(vvbuf,VVBUFL,p,"Kermit 95/",NULL,NULL);
  13278.             GetShortPathName(vvbuf,vvbuf,VVBUFL);
  13279.             return(vvbuf);
  13280.         }
  13281.         return("");
  13282.     }
  13283. #endif /* NT */
  13284.  
  13285. #ifdef TN_COMPORT
  13286.     switch (y) {
  13287.       case VN_TNC_SIG: {
  13288.         p = (char *) tnc_get_signature();
  13289.         ckstrncpy(vvbuf,p ? p : "",VVBUFL);
  13290.         return(vvbuf);
  13291.       }
  13292.     }
  13293. #endif /* TN_COMPORT */
  13294.  
  13295. #ifdef KUI
  13296.     switch (y) {
  13297.       case VN_GUI_RUN: {
  13298.       extern HWND getHwndKUI();
  13299.       if ( IsIconic(getHwndKUI()) )
  13300.             return("minimized");
  13301.       if ( IsZoomed(getHwndKUI()) )
  13302.             return("maximized");
  13303.       return("restored");
  13304.       }
  13305.       case VN_GUI_XP:
  13306.         sprintf(vvbuf,"%d",get_gui_window_pos_x());  /* SAFE */
  13307.         return(vvbuf);
  13308.       case VN_GUI_YP:
  13309.         sprintf(vvbuf,"%d",get_gui_window_pos_y());  /* SAFE */
  13310.         return(vvbuf);
  13311.       case VN_GUI_XR:
  13312.         sprintf(vvbuf,"%d",GetSystemMetrics(SM_CXSCREEN));  /* SAFE */
  13313.         return(vvbuf);
  13314.       case VN_GUI_YR:
  13315.         sprintf(vvbuf,"%d",GetSystemMetrics(SM_CYSCREEN));  /* SAFE */
  13316.         return(vvbuf);
  13317.       case VN_GUI_FNM:
  13318.           if ( ntermfont > 0 ) {
  13319.               int i;
  13320.               for (i = 0; i < ntermfont; i++) {
  13321.                   if (tt_font == term_font[i].kwval) {
  13322.                       ckstrncpy(vvbuf,term_font[i].kwd,VVBUFL);
  13323.                       return(vvbuf);
  13324.                   }
  13325.               }
  13326.           }
  13327.           return("(unknown)");
  13328.       case VN_GUI_FSZ:
  13329.           ckstrncpy(vvbuf,ckitoa(tt_font_size/2),VVBUFL);
  13330.           if ( tt_font_size % 2 )
  13331.               ckstrncat(vvbuf,".5",VVBUFL);
  13332.           return(vvbuf);
  13333.     }
  13334. #endif /* KUI */
  13335.  
  13336.     fnsuccess = 0;
  13337.     if (fnerror) {
  13338.         fnsuccess = 0;
  13339.     }
  13340.     if (fndiags) {
  13341.         if (!embuf)
  13342.           ckstrncpy(embuf,"<ERROR:NO_SUCH_VARIABLE>",EMBUFLEN);
  13343.         printf("?%s\n",embuf);
  13344.         return((char *)embuf);
  13345.     } else
  13346.       return("");
  13347. }
  13348. #endif /* NOSPL */
  13349.  
  13350.  
  13351. /*
  13352.   X X S T R I N G  --  Expand variables and backslash codes.
  13353.  
  13354.     int xxtstring(s,&s2,&n);
  13355.  
  13356.   Expands \ escapes via recursive descent.
  13357.   Argument s is a pointer to string to expand (source).
  13358.   Argument s2 is the address of where to put result (destination).
  13359.   Argument n is the length of the destination string (to prevent overruns).
  13360.   Returns -1 on failure, 0 on success,
  13361.     with destination string null-terminated and s2 pointing to the
  13362.     terminating null, so that subsequent characters can be added.
  13363. */
  13364.  
  13365. #define XXDEPLIM 100                    /* Recursion depth limit */
  13366. /*
  13367.   In Windows the stack is limited to 256K so big character arrays like
  13368.   vnambuf can't be on the stack in recursive functions like zzstring().
  13369.   But that's no reason use malloc() in Unix or VMS, which don't have
  13370.   this kind of restriction.
  13371. */
  13372. #ifdef DVNAMBUF                /* Dynamic vnambuf[] */
  13373. #undef DVNAMBUF                /* Clean slate */
  13374. #endif /* DVNAMBUF */
  13375.  
  13376. #ifndef NOSPL                /* Only if SPL included */
  13377. #ifdef OS2                /* Only for K95 */
  13378. #define DVNAMBUF
  13379. #endif /* OS2 */
  13380. #endif /* NOSPL */
  13381.  
  13382. int
  13383. zzstring(s,s2,n) char *s; char **s2; int *n; {
  13384.     int x,                              /* Current character */
  13385.         y,                              /* Worker */
  13386.         pp,                             /* Paren level */
  13387.         kp,                             /* Brace level */
  13388.         argn,                           /* Function argument counter */
  13389.         n2,                             /* Local copy of n */
  13390.         d,                              /* Array dimension */
  13391.         vbi,                            /* Variable id (integer form) */
  13392.         argl,                           /* String argument length */
  13393.         nx;                             /* Save original length */
  13394.  
  13395.     char vb,                            /* Variable id (char form) */
  13396.         *vp,                            /* Pointer to variable definition */
  13397.         *new,                           /* Local pointer to target string */
  13398. #ifdef COMMENT
  13399.         *old,                           /* Save original target pointer */
  13400. #endif /* COMMENT */
  13401.         *p,                             /* Worker */
  13402.         *q,                             /* Worker */
  13403.         *s3;                            /* Worker */
  13404.     int  x3;                            /* Worker */
  13405.     char *r  = (char *)0;               /* For holding function args */
  13406.     char *r2 = (char *)0;
  13407.     char *r3p;
  13408.  
  13409. #ifndef NOSPL
  13410. #ifdef DVNAMBUF
  13411.     char * vnambuf = NULL;              /* Buffer for variable/function name */
  13412. #else /* DVNAMBUF */
  13413.     char vnambuf[VNAML];                /* Buffer for variable/function name */
  13414. #endif /* DVNAMBUF */
  13415.     char *argp[FNARGS];                 /* Pointers to function args */
  13416. #endif /* NOSPL */
  13417.  
  13418.     static int depth = 0;               /* Call depth, avoid overflow */
  13419.  
  13420.     n2 = *n;                            /* Make local copies of args */
  13421.     nx = n2;
  13422.  
  13423.     new = *s2;                          /* for one less level of indirection */
  13424. #ifdef COMMENT
  13425.     old = new;
  13426. #endif /* COMMENT */
  13427.  
  13428. #ifndef NOSPL
  13429.     ispattern = 0;                      /* For \fpattern() */
  13430.     isjoin = 0;                /* For \fjoin() */
  13431. #endif /* NOSPL */
  13432.     depth++;                            /* Sink to a new depth */
  13433.     if (depth > XXDEPLIM) {             /* Too deep? */
  13434.         printf("?definition is circular or too deep\n");
  13435.         debug(F101,"zzstring fail","",depth);
  13436.         depth = 0;
  13437.         *new = NUL;
  13438.         return(-1);
  13439.     }
  13440.     if (!s || !new) {                   /* Watch out for null pointers */
  13441.         debug(F101,"zzstring fail 2","",depth);
  13442.         if (new)
  13443.           *new = NUL;
  13444.         depth = 0;
  13445.         return(-1);
  13446.     }
  13447.     s3 = s;
  13448.     argl = 0;
  13449.     while (*s3++) argl++;              /* Get length of source string */
  13450.     debug(F010,"zzstring entry",s,0);
  13451.     if (argl == 0) {                    /* Empty string */
  13452.         debug(F111,"zzstring empty arg",s,argl);
  13453.         depth = 0;
  13454.         *new = NUL;
  13455.         return(0);
  13456.     }
  13457.     if (argl < 0) {                     /* Watch out for garbage */
  13458.         debug(F101,"zzstring fail 3","",depth);
  13459.         *new = NUL;
  13460.         depth = 0;
  13461.         return(-1);
  13462.     }
  13463. #ifdef DVNAMBUF
  13464.     debug(F100,"vnambuf malloc...","",0);
  13465.     vnambuf = malloc(VNAML);
  13466.     if (vnambuf == NULL) {
  13467.         printf("?Out of memory");
  13468.         return(-1);
  13469.     }
  13470.     debug(F100,"vnambuf malloc ok","",0);
  13471. #endif /* DVNAMBUF */
  13472.  
  13473.     while ((x = *s)) {                  /* Loop for all characters */
  13474.         if (x != CMDQ) {                /* Is it the command-quote char? */
  13475.             *new++ = *s++;              /* No, normal char, just copy */
  13476.             if (--n2 < 0) {             /* and count it, careful of overflow */
  13477.                 debug(F101,"zzstring overflow 1","",depth);
  13478.                 depth = 0;
  13479. #ifdef DVNAMBUF
  13480.                 if (vnambuf) free(vnambuf);
  13481. #endif /* DVNAMBUF */
  13482.                 return(-1);
  13483.             }
  13484.             continue;
  13485.         }
  13486.  
  13487. /* We have the command-quote character. */
  13488.  
  13489.         x = *(s+1);                     /* Get the following character. */
  13490.         if (isupper(x)) x = tolower(x);
  13491.         switch (x) {                    /* Act according to variable type */
  13492. #ifndef NOSPL
  13493.           case 0:                       /* It's a lone backslash */
  13494.             *new++ = *s++;
  13495.             if (--n2 < 0) {
  13496.                 debug(F101,"zzstring overflow 2","",0);
  13497. #ifdef DVNAMBUF
  13498.                 if (vnambuf) free(vnambuf);
  13499. #endif /* DVNAMBUF */
  13500.                 return(-1);
  13501.             }
  13502.             break;
  13503.           case '%':                     /* Variable */
  13504.             s += 2;                     /* Get the letter or digit */
  13505.             vb = *s++;                  /* and move source pointer past it */
  13506.             vp = NULL;                  /* Assume definition is empty */
  13507.             if (vb >= '0' && vb <= '9') { /* Digit for macro arg */
  13508.                 if (maclvl < 0)         /* Digit variables are global */
  13509.                   vp = g_var[vb];       /* if no macro is active */
  13510.                 else                    /* otherwise */
  13511.                   vp = m_arg[maclvl][vb - '0']; /* they're on the stack */
  13512.             } else if (vb == '*') {     /* Macro args string */
  13513. #ifdef COMMENT
  13514.                 /* This doesn't take changes into account */
  13515.                 vp = (maclvl >= 0) ? m_line[maclvl] : topline;
  13516.                 if (!vp) vp = "";
  13517. #else
  13518.         char * ss = new;
  13519.                 if (zzstring("\\fjoin(&_[],,1)",&new,&n2) < 0) {
  13520. #ifdef DVNAMBUF
  13521.             if (vnambuf) free(vnambuf);
  13522. #endif /* DVNAMBUF */
  13523.             return(-1);
  13524.         }
  13525.         debug(F110,"zzstring \\%*",ss,0);
  13526.                 break;
  13527. #endif /* COMMENT */
  13528.             } else {
  13529.                 if (isupper(vb)) vb += ('a'-'A');
  13530.                 vp = g_var[vb];         /* Letter for global variable */
  13531.             }
  13532.             if (!vp) vp = "";
  13533. #ifdef COMMENT
  13534.             if (vp) {                   /* If definition not empty */
  13535. #endif /* COMMENT */
  13536.                 debug(F010,"zzstring %n vp",vp,0);
  13537.                 if (zzstring(vp,&new,&n2) < 0) { /* call self to evaluate it */
  13538.                     debug(F101,"zzstring fail 6","",depth);
  13539. #ifdef DVNAMBUF
  13540.                     if (vnambuf) free(vnambuf);
  13541. #endif /* DVNAMBUF */
  13542.                     return(-1);         /* Pass along failure */
  13543.                 }
  13544. #ifdef COMMENT
  13545.             } else {
  13546.                 debug(F110,"zzstring %n vp","(NULL)",0);
  13547.                 n2 = nx;
  13548.                 new = old;
  13549.                 *new = NUL;
  13550.             }
  13551. #endif /* COMMENT */
  13552.             break;
  13553.           case '&':                     /* An array reference */
  13554.             x = arraynam(s,&vbi,&d);    /* Get name and subscript */
  13555.             debug(F111,"zzstring arraynam",s,x);
  13556.             if (x < 0) {
  13557.                 debug(F101,"zzstring fail 7","",depth);
  13558. #ifdef DVNAMBUF
  13559.                 if (vnambuf) free(vnambuf);
  13560. #endif /* DVNAMBUF */
  13561.                 return(-1);
  13562.             }
  13563.             pp = 0;                     /* Bracket counter */
  13564.             while (*s) {                /* Advance source pointer... */
  13565.                 if (*s == '[') pp++;
  13566.                 if (*s == ']' && --pp == 0) break;
  13567.                 s++;
  13568.             }
  13569.             if (*s == ']') s++;         /* ...past the closing bracket. */
  13570.  
  13571.             x = chkarray(vbi,d);        /* Array is declared? */
  13572.             debug(F101,"zzstring chkarray","",x);
  13573.             if (x > 0) {
  13574. #ifdef COMMENT
  13575.                 char * s1 = NULL;
  13576. #endif /* COMMENT */
  13577.                 vbi -= ARRAYBASE;       /* Convert name to index */
  13578.  
  13579. #ifdef COMMENT
  13580.                 if (vbi == 0) {         /* Argument vector array */
  13581.                     extern char ** toparg, ** m_xarg[];
  13582.                     extern int n_xarg[];
  13583.                     if (maclvl < 0) {
  13584.                         if (topargc >= d) {
  13585.                             s1 = toparg[d];
  13586.                         }
  13587.                     } else {
  13588.                         if (n_xarg[maclvl] >= d) {
  13589.                             s1 = m_xarg[maclvl][d];
  13590.                         }
  13591.                     }
  13592.                     if (s1) {
  13593.                         if (zzstring(s1,&new,&n2) < 0) { /* evaluate */
  13594.                             debug(F101,"zzstring fail 7.5","",depth);
  13595. #ifdef DVNAMBUF
  13596.                             if (vnambuf) free(vnambuf);
  13597. #endif /* DVNAMBUF */
  13598.                             return(-1); /* Pass along failure */
  13599.                         }
  13600.                     } else {
  13601.                         /* old = new; */
  13602.                         n2 = nx;
  13603.                     }
  13604.                 } else
  13605. #endif /* COMMENT */
  13606.                   if (a_dim[vbi] >= d) { /* If subscript in range */
  13607.                     char **ap;
  13608. #ifndef COMMENT
  13609.                     debug(F110,"zzstring a_ptr[vbi]",a_ptr[vbi],0);
  13610.                     debug(F110,"zzstring a_ptr[vbi][d]",a_ptr[vbi][d],0);
  13611. #endif /* COMMENT */
  13612.                     ap = a_ptr[vbi];    /* get data pointer */
  13613.                     if (ap) {           /* and if there is one */
  13614.                         if (ap[d]) {    /* If definition not empty */
  13615.                             debug(F111,"zzstring ap[d]",ap[d],d);
  13616.                             if (zzstring(ap[d],&new,&n2) < 0) { /* evaluate */
  13617.                                 debug(F101,"zzstring fail 8","",depth);
  13618. #ifdef DVNAMBUF
  13619.                                 if (vnambuf) free(vnambuf);
  13620. #endif /* DVNAMBUF */
  13621.                                 return(-1); /* Pass along failure */
  13622.                             }
  13623.                         }
  13624.                     } else {
  13625.                         /* old = new; */
  13626.                         n2 = nx;
  13627.                     }
  13628.                 }
  13629.         }
  13630.             break;
  13631.  
  13632.           case 'f':                     /* A builtin function */
  13633.             q = vnambuf;                /* Copy the name */
  13634.             y = 0;                      /* into a separate buffer */
  13635.             s += 2;                     /* point past 'F' */
  13636.             while (y++ < VNAML) {
  13637.                 if (*s == '(') { s++; break; } /* Look for open paren */
  13638.                 if ((*q = *s) == NUL) break;   /* or end of string */
  13639.                 s++; q++;
  13640.             }
  13641.             *q = NUL;                   /* Terminate function name */
  13642.             if (y >= VNAML) {           /* Handle pathological case */
  13643.                 while (*s && (*s != '(')) /* of very long string entered */
  13644.                   s++;                    /* as function name. */
  13645.                 if (*s == ')') s++;       /* Skip past it. */
  13646.             }
  13647.             r = r2 = malloc(argl+2);    /* And make a place to copy args */
  13648.             /* debug(F101,"zzstring r2","",r2); */
  13649.             if (!r2) {                  /* Watch out for malloc failure */
  13650.                 debug(F101,"zzstring fail 9","",depth);
  13651.                 *new = NUL;
  13652.                 depth = 0;
  13653. #ifdef DVNAMBUF
  13654.                 if (vnambuf) free(vnambuf);
  13655. #endif /* DVNAMBUF */
  13656.                 return(-1);
  13657.             }
  13658.             if (r3) free(r3); /* And another to copy literal arg string */
  13659.             r3 = malloc(argl+2);
  13660.             /* debug(F101,"zzstring r3","",r3); */
  13661.             if (!r3) {
  13662.                 debug(F101,"zzstring fail 10","",depth);
  13663.                 depth = 0;
  13664.                 *new = NUL;
  13665.                 if (r2) free(r2);
  13666. #ifdef DVNAMBUF
  13667.                 if (vnambuf) free(vnambuf);
  13668. #endif /* DVNAMBUF */
  13669.                 return(-1);
  13670.             } else
  13671.               r3p = r3;
  13672.             argn = 0;                   /* Argument counter */
  13673.             argp[argn++] = r;           /* Point to first argument */
  13674.             y = 0;                      /* Completion flag */
  13675.             pp = 1;                     /* Paren level (already have one). */
  13676.             kp = 0;
  13677.             while (1) {                 /* Copy each argument, char by char. */
  13678.                 *r3p++ = *s;            /* This is a literal copy for \flit */
  13679.                 if (!*s) break;
  13680.  
  13681.                 if (*s == '{') {        /* Left brace */
  13682.                     kp++;
  13683.                 }
  13684.                 if (*s == '}') {        /* Right brace */
  13685.                     kp--;
  13686.                 }
  13687.                 if (*s == '(' && kp <= 0) { /* Open paren not in brace */
  13688.                     pp++;               /* Count it */
  13689.                 }
  13690.                 *r = *s;                /* Now copy resulting byte */
  13691.                 if (!*r)                /* If NUL, done. */
  13692.                   break;
  13693.                 if (*r == ')' && kp <= 0) { /* Closing paren, count it. */
  13694.                     if (--pp == 0) {    /* Final one? */
  13695.                         *r = NUL;       /* Make it a terminating null */
  13696.                         *(r3p - 1) = NUL;
  13697.                         s++;            /* Point past it in source string */
  13698.                         y = 1;          /* Flag we've got all the args */
  13699.                         break;          /* Done with while loop */
  13700.                     }
  13701.                 }
  13702.                 if (*r == ',' && kp <= 0) { /* Comma */
  13703.                     if (pp == 1) {          /* If not within ()'s, */
  13704.                         if (argn >= FNARGS) { /* Too many args */
  13705.                             s++; r++;   /* Keep collecting flit() string */
  13706.                             continue;
  13707.                         }
  13708.                         *r = NUL;           /* New arg, skip past comma */
  13709.                         argp[argn++] = r+1; /* In range, point to new arg */
  13710.                     }                   /* Otherwise just skip past  */
  13711.                 }
  13712.                 s++; r++;               /* Advance pointers */
  13713.             }
  13714.             if (!y)                     /* If we didn't find closing paren */
  13715.               argn = -1;
  13716. #ifdef DEBUG
  13717.             if (deblog) {
  13718.                 char buf[24];
  13719.                 debug(F111,"zzstring function name",vnambuf,y);
  13720.                 debug(F010,"zzstring function r3",r3,0);
  13721.                 for (y = 0; y < argn; y++) {
  13722.                     sprintf(buf,"arg %2d ",y);
  13723.                     debug(F010,buf,argp[y],0);
  13724.                 }
  13725.             }
  13726. #endif /* DEBUG */
  13727.             vp = fneval(vnambuf,argp,argn,r3); /* Evaluate the function. */
  13728.             if (vp) {                      /* If definition not empty */
  13729.                 while ((*new++ = *vp++)) { /* copy it to output string */
  13730.                     if (--n2 < 0) {        /* watch out for overflow */
  13731.                         debug(F101,"zzstring fail 12","",depth);
  13732.                         if (r2) { free(r2); r2 = NULL; }
  13733.                         if (r3) { free(r3); r3 = NULL; }
  13734. #ifdef DVNAMBUF
  13735.                         if (vnambuf) free(vnambuf);
  13736. #endif /* DVNAMBUF */
  13737.                         return(-1);
  13738.                     }
  13739.                 }
  13740.                 new--;                  /* Back up over terminating null */
  13741.                 n2++;                   /* to allow for further deposits. */
  13742.             }
  13743.             if (r2) { free(r2); r2 = NULL; }
  13744.             if (r3) { free(r3); r3 = NULL; }
  13745.             break;
  13746.           case '$':                     /* An environment variable */
  13747.           case 'v':                     /* Or a named builtin variable. */
  13748.           case 'm':                     /* Or a macro /long variable */
  13749.           case 's':                     /* 196 Macro substring */
  13750.           case ':':                     /* 196 \-variable substring */
  13751.             pp = 0;
  13752.             p = s+2;                    /* $/V/M must be followed by (name) */
  13753.             if (*p != '(') {            /* as in \$(HOME) or \V(count) */
  13754.                 *new++ = *s++;          /* If not, just copy it */
  13755.                 if (--n2 < 0) {
  13756.                     debug(F101,"zzstring overflow 3","",depth);
  13757. #ifdef DVNAMBUF
  13758.                     if (vnambuf) free(vnambuf);
  13759. #endif /* DVNAMBUF */
  13760.                     return(-1);
  13761.                 }
  13762.                 break;
  13763.             }
  13764.             pp++;
  13765.             p++;                        /* Point to 1st char of name */
  13766.             q = vnambuf;                /* Copy the name */
  13767.             y = 0;                      /* into a separate buffer */
  13768.             while (y++ < VNAML) {       /* Watch out for name too long */
  13769.                 if (*p == '(') {        /* Parens can be nested... */
  13770.                     pp++;
  13771.                 } else if (*p == ')') { /* Name properly terminated with ')' */
  13772.                     pp--;
  13773.                     if (pp == 0) {
  13774.                         p++;            /* Move source pointer past ')' */
  13775.                         break;
  13776.                     }
  13777.                 }
  13778.                 if ((*q = *p) == NUL)   /* String ends before ')' */
  13779.                   break;
  13780.                 p++; q++;               /* Advance pointers */
  13781.             }
  13782.             *q = NUL;                   /* Terminate the variable name */
  13783.             if (y >= VNAML) {           /* Handle pathological case */
  13784.                 while (*p && (*p != ')')) /* of very long string entered */
  13785.                   p++;                    /* as variable name. */
  13786.                 if (*p == ')') p++;       /* Skip ahead to the end of it. */
  13787.             }
  13788.             s = p;                      /* Adjust global source pointer */
  13789.             s3 = vnambuf;
  13790.             x3 = 0;
  13791.             while (*s3++) x3++;
  13792.             p = malloc(x3 + 1);         /* Make temporary space */
  13793.             if (p) {                    /* If we got the space */
  13794.                 vp = vnambuf;           /* Point to original */
  13795.                 strcpy(p,vp);           /* (safe) Make a copy of it */
  13796.                 y = VNAML;              /* Length of name buffer */
  13797.                 zzstring(p,&vp,&y);     /* Evaluate the copy */
  13798.                 free(p);                /* Free the temporary space */
  13799.                 p = NULL;
  13800.             }
  13801.             debug(F110,"zzstring vname",vnambuf,0);
  13802.             q = NULL;
  13803.             if (x == '$') {             /* Look up its value */
  13804.                 vp = getenv(vnambuf);   /* This way for environment variable */
  13805.             } else if (x == 'm' || x == 's' || x == ':') { /* Macro / substr */
  13806.                 int k, x1 = -1, x2 = -1;
  13807.                 k = strlen(vnambuf);
  13808.                 /* \s(name[n:m]) -- Compact substring notation */
  13809.                 if ((x == 's' || x == ':') && (k > 1)) { /* Substring wanted */
  13810.                     if (vnambuf[k-1] == ']') {
  13811.                         int i;
  13812.                         for (i = k-1; i > 0; i--) {
  13813.                             if (vnambuf[i] == '[') {
  13814.                                 char * p = NULL;
  13815.                                 p = (char *)malloc(k - i + 8);
  13816.                                 if (p) {
  13817.                                     /* Now this is a dirty trick... */
  13818.                                     ckmakmsg(p,
  13819.                                              k-i+8,
  13820.                                              "\\&a",
  13821.                                              &vnambuf[i],
  13822.                                              NULL,
  13823.                                              NULL
  13824.                                              );
  13825.                                     arraybounds(p,&x1,&x2);
  13826.                                     if (x1 < 1) x1 = 1;
  13827.                                     x1--; /* Adjust to 0-base */
  13828.                                     free(p);
  13829.                                     vnambuf[i] = NUL;
  13830.                                 }
  13831.                             }
  13832.                         }
  13833.                     }
  13834.                 }
  13835.                 if (x == ':') {
  13836.                     vp = vnambuf;
  13837.                 } else {
  13838.             y = isaarray(vnambuf) ?
  13839.             mxxlook(mactab,vnambuf,nmac) :
  13840.             mxlook(mactab,vnambuf,nmac);
  13841.                     if (y > -1) {    /* Got definition */
  13842.                         vp = mactab[y].mval;
  13843.                     } else {
  13844.                         vp = NULL;
  13845.                     }
  13846.                 }
  13847.                 if (vp) {
  13848.                     if ((x == 's' || x == ':') && (k > 1)) {
  13849.                         /* Compact substring notation */
  13850.                         if (x2 == 0) {  /* Length */
  13851.                             vp = NULL;
  13852.                         } else if (x1 > -1) { /* Start */
  13853.                             k = strlen(vp);
  13854.                             if (x1 > k) {  /* If it's off the end, */
  13855.                                 vp = NULL; /* result is empty */
  13856.                             } else if (k > 0) {
  13857.                                 if ((q = malloc(k+1))) {
  13858.                                     strcpy(q,vp); /* safe */
  13859.                                     if ((x2 > -1) && ((x1 + x2) <= k)) {
  13860.                                         q[x1+x2] = NUL;
  13861.                                     }
  13862.                                     vp = q+x1;
  13863.                                 }  else vp = NULL;
  13864.                             } else vp = NULL;
  13865.                         }
  13866. #ifdef DEBUG
  13867.                         if (deblog) {
  13868.                             if (!vp) {
  13869.                             } else {
  13870.                                 k = strlen(vp);
  13871.                             }
  13872.                         }
  13873. #endif /* DEBUG */
  13874.                     }
  13875.                 }
  13876.             } else {                    /* or */
  13877.                 vp = nvlook(vnambuf);   /* this way for builtin variable */
  13878.             }
  13879.             if (vp) {                   /* If definition not empty */
  13880.                 while ((*new++ = *vp++)) /* copy it to output string. */
  13881.                   if (--n2 < 0) {
  13882.                       if (q) free(q);
  13883.                       debug(F101,"zzstring overflow 4","",depth);
  13884. #ifdef DVNAMBUF
  13885.                       if (vnambuf) free(vnambuf);
  13886. #endif /* DVNAMBUF */
  13887.                       return(-1);
  13888.                   }
  13889.                 new--;                  /* Back up over terminating null */
  13890.                 n2++;                   /* to allow for further deposits. */
  13891.             }
  13892.             if (q) {
  13893.                 free(q);
  13894.                 q = NULL;
  13895.             }
  13896.             break;
  13897. #endif /* NOSPL */                      /* Handle \nnn even if NOSPL. */
  13898.  
  13899. #ifndef NOKVERBS
  13900.         case 'K':
  13901.         case 'k': {
  13902.             extern struct keytab kverbs[];
  13903.             extern int nkverbs;
  13904. #define K_BUFLEN 30
  13905.             char kbuf[K_BUFLEN + 1];    /* Key verb name buffer */
  13906.             int x, y, z, brace = 0;
  13907.             s += 2;
  13908. /*
  13909.   We assume that the verb name is {braced}, or it extends to the end of the
  13910.   string, s, or it ends with a space, control character, or backslash.
  13911. */
  13912.             p = kbuf;                   /* Copy verb name into local buffer */
  13913.             x = 0;
  13914.             if (*s == '{')  {
  13915.                 s++;
  13916.                 brace++;
  13917.             }
  13918.             while ((x++ < K_BUFLEN) && (*s > SP) && (*s != CMDQ)) {
  13919.                 if (brace && *s == '}') {
  13920.                     s++;
  13921.                     break;
  13922.                 }
  13923.                 *p++ = *s++;
  13924.             }
  13925.             brace = 0;
  13926.             *p = NUL;                   /* Terminate. */
  13927.             p = kbuf;                   /* Point back to beginning */
  13928.             debug(F110,"zzstring kverb",p,0);
  13929.             y = xlookup(kverbs,p,nkverbs,&x); /* Look it up */
  13930.             debug(F101,"zzstring lookup",0,y);
  13931.             if (y > -1) {
  13932.                 dokverb(VCMD,y);
  13933. #ifndef NOSPL
  13934.             } else {                    /* Is it a macro? */
  13935.                 y = mxlook(mactab,p,nmac);
  13936.                 if (y > -1) {
  13937.                     debug(F111,"zzstring mxlook",p,y);
  13938.                     if ((z = dodo(y,NULL,cmdstk[cmdlvl].ccflgs)) > 0) {
  13939.                         if (cmpush() > -1) {  /* Push command parser state */
  13940.                             extern int ifc;
  13941.                             int ifcsav = ifc; /* Push IF condition on stack */
  13942.                             y = parser(1);    /* New parser to execute macro */
  13943.                             cmpop();          /* Pop command parser */
  13944.                             ifc = ifcsav;     /* Restore IF condition */
  13945.                             if (y == 0) {     /* No errors, ignore actions */
  13946.                                 p = mrval[maclvl+1]; /* If OK set return val */
  13947.                                 if (p == NULL) p = "";
  13948.                             }
  13949.                         } else {                /* Can't push any more */
  13950.                             debug(F101,"zzstring pushed too deep","",depth);
  13951.                             printf(
  13952.                                "\n?Internal error: zzstring stack overflow\n"
  13953.                                    );
  13954.                             while (cmpop() > -1);
  13955.                             p = "";
  13956.                         }
  13957.                     }
  13958.                 }
  13959. #endif /* NOSPL */
  13960.             }
  13961.             break;
  13962.         }
  13963. #endif /* NOKVERBS */
  13964.  
  13965.         default:                        /* Maybe it's a backslash code */
  13966.           y = xxesc(&s);                /* Go interpret it */
  13967.           if (y < 0) {                  /* Upon failure */
  13968.               *new++ = (char) x;        /* Just quote the next character */
  13969.               s += 2;                   /* Move past the pair */
  13970.               n2 -= 2;
  13971.               if (n2 < 0) {
  13972.                   debug(F101,"zzstring overflow 5","",depth);
  13973. #ifdef DVNAMBUF
  13974.                   if (vnambuf) free(vnambuf);
  13975. #endif /* DVNAMBUF */
  13976.                   return(-1);
  13977.               }
  13978.               continue;                 /* and go back for more */
  13979.           } else {
  13980.               *new++ = (char) y;        /* else deposit interpreted value */
  13981.               if (--n2 < 0) {
  13982.                   debug(F101,"zzstring overflow 6","",depth);
  13983. #ifdef DVNAMBUF
  13984.                   if (vnambuf) free(vnambuf);
  13985. #endif /* DVNAMBUF */
  13986.                   return(-1);
  13987.               }
  13988.           }
  13989.         }
  13990.     }
  13991.     *new = NUL;                         /* Terminate the new string */
  13992.     debug(F010,"zzstring while exit",*s2,0);
  13993.  
  13994.     depth--;                            /* Adjust stack depth gauge */
  13995.     *s2 = new;                          /* Copy results back into */
  13996.     *n = n2;                            /* the argument addresses */
  13997.     debug(F101,"zzstring ok","",depth);
  13998. #ifdef DVNAMBUF
  13999.     if (vnambuf) free(vnambuf);
  14000. #endif /* DVNAMBUF */
  14001.     return(0);                          /* and return. */
  14002. }
  14003. #endif /* NOICP */
  14004.